Updated to work on Linux, redesigned core

This commit is contained in:
David Anderson 2005-08-24 02:53:38 +00:00
parent 5b208eb9f5
commit 82fed37247
18 changed files with 608 additions and 115 deletions

View File

@ -1,30 +0,0 @@
using System;
using System.Collections;
namespace AMXXRelease
{
/// <summary>
/// Summary description for ABuild.
/// </summary>
public abstract class ABuild
{
protected ArrayList m_Mods;
public ABuild()
{
m_Mods = new ArrayList();
}
public abstract string GetName();
public virtual int GetMods()
{
return m_Mods.Count;
}
public virtual AMod GetMod(int i)
{
return (AMod)m_Mods[i];
}
}
}

226
installer/AMXXRelease/ABuilder.cs Executable file
View File

@ -0,0 +1,226 @@
using System;
using System.Diagnostics;
using System.IO;
namespace AMXXRelease
{
//This class specifies the process that builds a release.
//It also implements the functions that are unlikely to change.
public abstract class ABuilder
{
protected Config m_Cfg;
public virtual void OnBuild()
{
}
public virtual bool Build(Config cfg, Build build)
{
m_Cfg = cfg;
OnBuild();
int num = build.GetMods();
AMod mod;
for (int i=0; i<num; i++)
{
mod = build.GetMod(i);
if (!BuildMod(mod))
{
System.Console.WriteLine("Mod failed to build: " + mod.GetName());
return false;
}
CompressDir(m_Cfg.GetReleaseName() + "-" + mod.GetName() + ".zip", mod.GetName() + "\\*.*");
}
return true;
}
public virtual bool BuildMod(AMod mod)
{
CopyConfigs(mod);
if (!BuildModModules(mod))
return false;
if (!BuildModPlugins(mod))
return false;
string basedir = PropSlashes(m_Cfg.OutputPath() + "\\" + mod.GetModPath());
string sourcetree = m_Cfg.GetSourceTree();
if (!mod.CopyExtraFiles(basedir, sourcetree))
return false;
return true;
}
public virtual void CopyConfigs(AMod mod)
{
string basedir = PropSlashes(m_Cfg.OutputPath() + "\\" + mod.GetModPath() + "\\configs");
if (!Directory.Exists(basedir))
Directory.CreateDirectory(basedir);
string srcdir = m_Cfg.GetSourceTree() + "\\configs";
if (!Directory.Exists(srcdir))
return;
if (mod.GetPluginDir() != null)
srcdir += "\\" + mod.GetBaseName();
srcdir = PropSlashes(srcdir);
CopyNormal(srcdir, basedir);
}
public static void CopyNormal(string src, string dest)
{
string[] files = Directory.GetFiles(src);
if (!Directory.Exists(dest))
Directory.CreateDirectory(dest);
for (int i=0; i<files.Length; i++)
{
File.Copy(files[i],
PropSlashes(dest + "\\" + GetFileName(files[i])),
true);
}
}
public virtual bool BuildModPlugins(AMod mod)
{
int num = mod.GetPlugins();
Plugin plugin;
string binary, basedir;
basedir = m_Cfg.OutputPath();
basedir += "\\" + mod.GetModPath();
basedir = PropSlashes(basedir);
string dir, file, target;
for (int i=0; i<num; i++)
{
plugin = mod.GetPlugin(i);
binary = BuildPlugin(mod, plugin);
file = PropSlashes(m_Cfg.GetSourceTree() + "\\plugins\\" + GetFileName(binary));
if (!File.Exists(file))
{
System.Console.WriteLine("Plugin failed to compile: " +
mod.GetName() + "::" + plugin.name);
return false;
}
dir = PropSlashes(basedir + "\\" + plugin.outdir);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
target = PropSlashes(dir + "\\" + plugin.name + ".amxx");
if (File.Exists(target))
File.Delete(target);
File.Move(file,
target);
}
//Copy all files from the plugins dir to scripting
string search_dir = m_Cfg.GetSourceTree() + "\\plugins";
if (mod.GetPluginDir() != null)
search_dir += "\\" + mod.GetPluginDir();
search_dir = PropSlashes(search_dir);
string dest;
if (Directory.Exists(search_dir))
{
string[] files = Directory.GetFiles(search_dir);
if (!Directory.Exists(PropSlashes(basedir + "\\scripting")))
Directory.CreateDirectory(PropSlashes(basedir + "\\scripting"));
for (int i=0; i<files.Length; i++)
{
dest = PropSlashes(basedir + "\\scripting\\" + GetFileName(files[i]));
File.Copy(files[i], dest, true);
}
}
return true;
}
private static string GetFileName(string input)
{
for (int i=input.Length-1; i>=0; i--)
{
if ((input[i] == '\\' || input[i] == '/') && i != input.Length-1)
{
return input.Substring(i+1, input.Length-i-1);
}
}
return input;
}
public virtual bool BuildModModules(AMod mod)
{
int num = mod.GetModules();
Module module;
string binary, basedir;
basedir = m_Cfg.OutputPath();
basedir += "\\" + mod.GetModPath();
basedir = PropSlashes(basedir);
string dir;
for (int i=0; i<num; i++)
{
module = mod.GetModule(i);
binary = BuildModule(module);
if (binary == null)
{
System.Console.WriteLine("Module failed to compile: " +
mod.GetName() + "::" + module.projname + GetLibExt());
return false;
}
dir = PropSlashes(basedir + "\\" + module.outdir);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
File.Copy(binary,
PropSlashes(dir + "\\" + module.projname + GetLibExt()),
true);
}
return true;
}
public virtual string BuildPlugin(AMod mod, Plugin pl)
{
string modoffs = mod.GetPluginDir();
string pldir;
if (modoffs != null)
pldir = modoffs + "\\";
else
pldir = "";
AmxxPc(PropSlashes(pldir + pl.source), pl.options);
string outfile = pldir + pl.name + ".amxx";
return outfile;
}
public abstract void AmxxPc(string inpath, string args);
public abstract string BuildModule(Module module);
public abstract string GetLibExt();
public abstract void CompressDir(string target, string dir);
public static string PropSlashes(string path)
{
return path.Replace(Path.AltDirectorySeparatorChar,Path.DirectorySeparatorChar);
}
}
}

View File

@ -4,12 +4,13 @@
namespace AMXXRelease
{
//Holds information about a plugin
public class Plugin
{
public string name;
public string source;
public string options;
public string outdir;
public string name; //Plugin output file name
public string source; //Source code file
public string options; //Compile-time options
public string outdir; //Output folder
public Plugin(string Name)
{
@ -19,14 +20,15 @@ public Plugin(string Name)
}
}
//Holds information necessary to compile a module/C++ program
public class Module
{
public string sourcedir;
public string projname;
public string build;
public string bindir;
public string vcproj;
public string outdir;
public string sourcedir; //Source directory
public string projname; //Output binary name (such as amxmodx_mm)
public string build; //Build configuration
public string bindir; //Binary directory
public string vcproj; //VCProj file name
public string outdir; //Output directory
public Module()
{
@ -44,6 +46,10 @@ public Module(string name)
}
}
//Class that represents how a mod wants to be built.
//It exports a list of functions, mods, and a few
// tidbits of information. It can also hook an extra
// step for copying miscellanious files.
public abstract class AMod
{
protected ArrayList m_Modules;

View File

@ -6,12 +6,12 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("AMXXRelease")]
[assembly: AssemblyDescription("Build scripts for AMX Mod X")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyCompany("AMX Mod X")]
[assembly: AssemblyProduct("AMXXRelease")]
[assembly: AssemblyCopyright("(C)Copyright 2004-2005 AMX Mod X Development Team")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

View File

@ -1,34 +1,100 @@
using System;
using System.IO;
namespace AMXXRelease
{
/// <summary>
/// Summary description for Config.
/// </summary>
//Reads in config file info
public class Config
{
private string m_SourceTree;
private string m_OutputPath;
private string m_DevenvPath;
private string m_PathToCompress;
private string m_ReleaseName;
private string m_MakeOpts;
public Config()
{
}
public string GetSourceTree()
{
return "C:\\real\\code\\amxmodx";
return m_SourceTree;
}
public string OutputPath()
{
return "C:\\real\\done";
return m_OutputPath;
}
public string DevenvPath()
{
return "C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Common7\\IDE\\devenv.com";
return m_DevenvPath;
}
public string PathToZip()
public string CompressPath()
{
return "C:\\Windows\\zip.exe";
return m_PathToCompress;
}
public string GetReleaseName()
{
return m_ReleaseName;
}
public string MakeOpts()
{
return m_MakeOpts;
}
public bool ReadFromFile(string file)
{
try
{
StreamReader sr = new StreamReader(file);
string line;
string delim = "\t \n\r\v";
string splt = "=";
while ( (line = sr.ReadLine()) != null )
{
line = line.Trim(delim.ToCharArray());
if (line.Length < 1 || line[0] == ';')
continue;
string [] s = line.Split(splt.ToCharArray());
string key, val="";
if (s.GetLength(0) >= 1)
{
key = s[0];
if (s.GetLength(0) >= 2)
{
for(int i=1; i<s.GetLength(0); i++)
val += s[i];
}
key = key.Trim(delim.ToCharArray());
val = val.Trim(delim.ToCharArray());
if (key.CompareTo("compress")==0)
m_PathToCompress = val;
if (key.CompareTo("devenv")==0)
m_DevenvPath = val;
if (key.CompareTo("output")==0)
m_OutputPath = val;
if (key.CompareTo("source")==0)
m_SourceTree = val;
if (key.CompareTo("release")==0)
m_ReleaseName = val;
if (key.CompareTo("makeopts")==0)
m_MakeOpts = val;
}
}
return true;
} catch {
Console.WriteLine("Unable to read file: " + file);
}
return false;
}
}
}

View File

@ -3,6 +3,7 @@
namespace AMXXRelease
{
//AMX Mod X core distribution
public class CoreMod : AMod
{
public CoreMod()
@ -31,26 +32,32 @@ public override sealed bool CopyExtraFiles(string basedir, string source)
//Create directory structures
string datadir = basedir + "\\data";
if (!Directory.Exists(datadir))
Directory.CreateDirectory(datadir);
if (!Directory.Exists(ABuilder.PropSlashes(datadir)))
Directory.CreateDirectory(ABuilder.PropSlashes(datadir));
File.Copy(source + "\\dlls\\geoip\\GeoIP.dat",
datadir + "\\GeoIP.dat",
File.Copy(ABuilder.PropSlashes(source + "\\dlls\\geoip\\GeoIP.dat"),
ABuilder.PropSlashes(datadir + "\\GeoIP.dat"),
true);
Builder.CopyNormal(source + "\\plugins\\lang", datadir + "\\lang");
ABuilder.CopyNormal(
ABuilder.PropSlashes(source + "\\plugins\\lang"),
ABuilder.PropSlashes(datadir + "\\lang")
);
if (!Directory.Exists(basedir + "\\logs"))
Directory.CreateDirectory(basedir + "\\logs");
if (!Directory.Exists(ABuilder.PropSlashes(basedir + "\\logs")))
Directory.CreateDirectory(ABuilder.PropSlashes(basedir + "\\logs"));
if (!Directory.Exists(basedir + "\\doc"))
Directory.CreateDirectory(basedir + "\\doc");
if (!Directory.Exists(ABuilder.PropSlashes(basedir + "\\doc")))
Directory.CreateDirectory(ABuilder.PropSlashes(basedir + "\\doc"));
File.Copy(source + "\\doc\\amxmodx-doc.chm",
basedir + "\\doc\\amxmodx-doc.chm",
File.Copy(
ABuilder.PropSlashes(source + "\\doc\\amxmodx-doc.chm"),
ABuilder.PropSlashes(basedir + "\\doc\\amxmodx-doc.chm"),
true);
Builder.CopyNormal(source + "\\plugins\\include", basedir + "\\scripting\\include");
ABuilder.CopyNormal(
ABuilder.PropSlashes(source + "\\plugins\\include"),
ABuilder.PropSlashes(basedir + "\\scripting\\include"));
return true;
}

View File

@ -0,0 +1,109 @@
using System;
using System.Diagnostics;
using System.IO;
namespace AMXXRelease
{
//Build process for any Linux
public class LinuxBuilder : ABuilder
{
private string m_AmxxPc;
public override void OnBuild()
{
m_AmxxPc = PropSlashes(m_Cfg.GetSourceTree() + "/plugins/amxxpc");
}
public override void CompressDir(string target, string dir)
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = m_Cfg.CompressPath();
info.WorkingDirectory = m_Cfg.OutputPath();
info.Arguments = "zcvf " + target + " " + dir;
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
}
public override void AmxxPc(string inpath, string args)
{
ProcessStartInfo info = new ProcessStartInfo();
info.WorkingDirectory = PropSlashes(m_Cfg.GetSourceTree() + "\\plugins");
info.FileName = (string)m_AmxxPc.Clone();
info.Arguments = inpath + ".sma";
if (args != null)
info.Arguments += " " + args;
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
}
public override string GetLibExt()
{
if (m_Cfg.MakeOpts().IndexOf("amd64") != -1)
return "_amd64.so";
else
return "_i386.so";
}
public override string BuildModule(Module module)
{
ProcessStartInfo info = new ProcessStartInfo();
string dir = m_Cfg.GetSourceTree() + "\\" + module.sourcedir;
string file = dir;
file += "\\" + "Release" + "\\" + module.projname + GetLibExt();
file = PropSlashes(file);
if (File.Exists(file))
File.Delete(file);
Console.WriteLine(PropSlashes(dir));
info.WorkingDirectory = PropSlashes(dir);
info.FileName = m_Cfg.DevenvPath();
info.Arguments = "clean";
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
info.WorkingDirectory = PropSlashes(dir);
info.FileName = m_Cfg.DevenvPath();
info.Arguments =m_Cfg.MakeOpts();
info.UseShellExecute = false;
p = Process.Start(info);
p.WaitForExit();
if (!File.Exists(file))
return null;
//Now we need to see if the DL handle is valid!
string dlsym_dir = m_Cfg.GetSourceTree() + "\\plugins";
string dlsym = dlsym_dir + "\\dlsym";
if (m_Cfg.MakeOpts().IndexOf("amd64") != -1)
dlsym += "64";
dlsym = PropSlashes(dlsym);
dlsym_dir = PropSlashes(dlsym_dir);
info.WorkingDirectory = dlsym_dir;
info.FileName = dlsym;
info.Arguments = file;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
p = Process.Start(info);
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
if (output.IndexOf("Handle:") == -1)
return null;
return file;
}
}
}

55
installer/AMXXRelease/Main.cs Executable file
View File

@ -0,0 +1,55 @@
using System;
using System.Diagnostics;
using System.IO;
namespace AMXXRelease
{
//Entry point for application.
//1. Reads config file
//2. Instantiates correct build process (ABuilder)
//3. Instantiates the build (Build)
//4. Passes configuration and build to the Builder
public class Releaser
{
private Config m_Cfg;
[STAThread]
static void Main(string[] args)
{
string file;
if (args.GetLength(0) < 1)
file = "release.info";
else
file = args[0];
Releaser r = new Releaser();
r.Release(file);
}
public void Release(string file)
{
m_Cfg = new Config();
file = ABuilder.PropSlashes(file);
if (!m_Cfg.ReadFromFile(file))
{
Console.WriteLine("Failed to read config, aborting!");
return;
}
ABuilder builder = null;
if ((int)System.Environment.OSVersion.Platform == 128)
{
builder = new LinuxBuilder();
} else {
builder = new Win32Builder();
}
Build build = new Build();
builder.Build(m_Cfg, build);
}
}
}

View File

@ -33,9 +33,14 @@ private void AddPlugins()
public override sealed bool CopyExtraFiles(string basedir, string source)
{
if ((int)System.Environment.OSVersion.Platform == 128)
{
} else {
File.Copy(source + "\\dlls\\csx\\source\\WinCSX\\Release\\WinCSX.exe",
basedir + "\\data\\WinCSX.exe",
true);
}
return true;
}

View File

@ -2,9 +2,7 @@
namespace AMXXRelease
{
/// <summary>
/// Summary description for ModDoD.
/// </summary>
//Day of Defeat
public class ModDoD : AMod
{
public ModDoD()

View File

@ -2,9 +2,7 @@
namespace AMXXRelease
{
/// <summary>
/// Summary description for ModEsf.
/// </summary>
//Earth's Special Forces
public class ModEsf : AMod
{
public ModEsf()

View File

@ -2,9 +2,7 @@
namespace AMXXRelease
{
/// <summary>
/// Summary description for ModNs.
/// </summary>
//Natural Selection
public class ModNs : AMod
{
public ModNs()

View File

@ -2,9 +2,7 @@
namespace AMXXRelease
{
/// <summary>
/// Summary description for ModTFC.
/// </summary>
//Team Fortress Classic
public class ModTFC : AMod
{
public ModTFC()

View File

@ -2,9 +2,7 @@
namespace AMXXRelease
{
/// <summary>
/// Summary description for ModTs.
/// </summary>
//The Specialists
public class ModTs : AMod
{
public ModTs()

View File

@ -1,34 +0,0 @@
using System;
namespace AMXXRelease
{
/// <summary>
/// Summary description for Release15.
/// </summary>
public class Release15 : ABuild
{
public Release15()
{
CoreMod core = new CoreMod();
ModCstrike cstrike = new ModCstrike();
ModDoD dod = new ModDoD();
ModEsf esf = new ModEsf();
ModNs ns = new ModNs();
ModTFC tfc = new ModTFC();
ModTs ts = new ModTs();
m_Mods.Add(core);
m_Mods.Add(cstrike);
m_Mods.Add(dod);
m_Mods.Add(esf);
m_Mods.Add(ns);
m_Mods.Add(tfc);
m_Mods.Add(ts);
}
public override sealed string GetName()
{
return "amxmodx-1.5";
}
}
}

View File

@ -0,0 +1,81 @@
using System;
using System.Diagnostics;
using System.IO;
namespace AMXXRelease
{
//Build process for Windows (32bit)
public class Win32Builder : ABuilder
{
private string m_AmxxPc;
public override void OnBuild()
{
m_AmxxPc = PropSlashes(m_Cfg.GetSourceTree() + "\\plugins\\amxxpc.exe");
}
public override void CompressDir(string target, string dir)
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = m_Cfg.CompressPath();
info.WorkingDirectory = m_Cfg.OutputPath();
info.Arguments = "-r " + target + " " + dir;
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
}
public override void AmxxPc(string inpath, string args)
{
ProcessStartInfo info = new ProcessStartInfo();
info.WorkingDirectory = PropSlashes(m_Cfg.GetSourceTree() + "\\plugins");
info.FileName = (string)m_AmxxPc.Clone();
info.Arguments = inpath + ".sma";
if (args != null)
info.Arguments += " " + args;
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
}
public override string GetLibExt()
{
return ".dll";
}
public override string BuildModule(Module module)
{
ProcessStartInfo info = new ProcessStartInfo();
string dir = m_Cfg.GetSourceTree() + "\\" + module.sourcedir;
if (module.bindir != null)
dir += "\\" + module.bindir;
string file = dir;
if (module.bindir == null)
file += "\\" + module.bindir;
file += "\\" + module.build + "\\" + module.projname + ".dll";
file = PropSlashes(file);
if (File.Exists(file))
File.Delete(file);
info.WorkingDirectory = PropSlashes(dir);
info.FileName = m_Cfg.DevenvPath();
info.Arguments = "/build " + module.build + " " + module.vcproj + ".vcproj";
info.UseShellExecute = false;
Process p = Process.Start(info);
p.WaitForExit();
if (!File.Exists(file))
return null;
return file;
}
}
}

View File

@ -0,0 +1,6 @@
compress = /bin/tar
source = /home1/dvander/amxx
makeopts =
output = /home1/dvander/done
devenv = /usr/bin/make
release = amxmodx-1.55

View File

@ -0,0 +1,6 @@
compress = /bin/tar
source = /home1/dvander/amxx
makeopts = amd64
output = /home1/dvander/done
devenv = /usr/bin/make
release = amxmodx-1.55