tools/builder/LinuxBuilder.cs
author David Anderson <dvander@alliedmods.net>
Wed May 23 22:08:05 2007 +0000 (2007-05-23)
changeset 852 9a7a93363979
parent 468 e88b65aad7e1
child 1548 e759eedf6c9b
permissions -rw-r--r--
added plugin compiling
     1 using System;
     2 using System.IO;
     3 using System.Diagnostics;
     4 
     5 namespace builder
     6 {
     7 	public class LinuxBuilder : ABuilder
     8 	{
     9 		public LinuxBuilder(Config _cfg)
    10 		{
    11 			cfg = _cfg;
    12 		}
    13 
    14 		public override string GetPawnCompilerName()
    15 		{
    16 			return "spcomp";
    17 		}
    18 
    19 		public override string CompressPackage(Package pkg)
    20 		{
    21 			string lpath = null, ltarget = null;
    22 			
    23 			pkg.GetCompressBases(ref lpath, ref ltarget);
    24 
    25 			string local_dir = Config.PathFormat("{0}/{1}", 
    26 				cfg.OutputBase,
    27 				lpath);
    28 
    29 			string name = PackageBuildName(pkg) + ".tar.gz";
    30 
    31 			ProcessStartInfo info = new ProcessStartInfo();
    32 			info.FileName = cfg.Compressor;
    33 			info.WorkingDirectory = local_dir;
    34 			info.Arguments = "zcvf \"" + name + "\" \"" + ltarget + "\"";
    35 			info.UseShellExecute = false;
    36 
    37 			Process p = Process.Start(info);
    38 			p.WaitForExit();
    39 
    40 			local_dir = Config.PathFormat("{0}/{1}", local_dir, name);
    41 
    42 			if (!File.Exists(local_dir))
    43 			{
    44 				return null;
    45 			}
    46 
    47 			return name;
    48 		}
    49 
    50 
    51 		public override bool BuildLibrary(Package pkg, Library lib, ref string _binName, ref string _binPath)
    52 		{
    53 			ProcessStartInfo info = new ProcessStartInfo();
    54 
    55 			string path = Config.PathFormat("{0}/{1}", 
    56 				cfg.SourceBase,
    57 				lib.LocalPath);
    58 
    59 			/* PlatformExt ignored for us */
    60 			string binName = lib.Name;
    61 			
    62 			if (!lib.IsExecutable)
    63 			{
    64 				if (lib.PlatformExt)
    65 				{
    66 					binName += "_i486.so";
    67 				} 
    68 				else 
    69 				{
    70 					binName += ".so";
    71 				}
    72 			}
    73 
    74 			string binpath = Config.PathFormat("{0}/{1}/{2}",
    75 				path,
    76 				lib.ReleaseBuild,
    77 				binName);
    78 			
    79 			if (File.Exists(binpath))
    80 			{
    81 				File.Delete(binpath);
    82 			}
    83 
    84 			/* Clean the project first */
    85 			info.WorkingDirectory = path;
    86 			info.FileName = cfg.BuilderPath;
    87 			info.Arguments = "clean";
    88 			info.UseShellExecute = false;
    89 
    90 			Process p = Process.Start(info);
    91 			p.WaitForExit();
    92 			p.Close();
    93 
    94 			/* Now build it */
    95 			info.WorkingDirectory = path;
    96 			info.FileName = cfg.BuilderPath;
    97 			info.Arguments = "";
    98 			info.UseShellExecute = false;
    99 
   100 			if (cfg.BuildOptions != null)
   101 			{
   102 				info.Arguments += " " + cfg.BuildOptions;
   103 			}
   104 
   105 			p = Process.Start(info);
   106 			p.WaitForExit();
   107 			p.Close();
   108 
   109 			if (!File.Exists(binpath))
   110 			{
   111 				return false;
   112 			}
   113 			
   114 			_binName = binName;
   115 			_binPath = binpath;
   116 
   117 			return true;
   118 		}
   119 	}
   120 }