tools/builder/LinuxBuilder.cs
author David Anderson <dvander@alliedmods.net>
Sun Oct 28 08:24:47 2007 +0000 (2007-10-28)
changeset 1649 37373aea4dfe
parent 1558 95a3d8bf618d
child 1879 64edd58691ab
permissions -rw-r--r--
fixed macro bug in the sdk
     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 bool BuildLibrary(Package pkg, Library lib)
    20 		{
    21 			ProcessStartInfo info = new ProcessStartInfo();
    22 
    23 			string path = Config.PathFormat("{0}/{1}", 
    24 				cfg.source_path,
    25 				lib.source_path);
    26 
    27 			/* PlatformExt ignored for us */
    28 			string binName = lib.binary_name;
    29 			
    30 			if (!lib.is_executable)
    31 			{
    32 				if (lib.has_platform_ext)
    33 				{
    34 					binName += "_i486.so";
    35 				} 
    36 				else 
    37 				{
    38 					binName += ".so";
    39 				}
    40 			}
    41 
    42 			string binpath = Config.PathFormat("{0}/{1}/{2}",
    43 				path,
    44 				(lib.release_mode == ReleaseMode.ReleaseMode_Release) ? "Release" : "Debug",
    45 				binName);
    46 			
    47 			if (File.Exists(binpath))
    48 			{
    49 				File.Delete(binpath);
    50 			}
    51 
    52 			string makefile_name = "Makefile";
    53 
    54 			if (lib.build_mode == BuildMode.BuildMode_Episode1)
    55 			{
    56 				makefile_name = "Makefile.ep1";
    57 			}
    58 			else if (lib.build_mode == BuildMode.BuildMode_Episode2)
    59 			{
    60 				makefile_name = "Makefile.ep2";
    61 			}
    62 			else if (lib.build_mode == BuildMode.BuildMode_OldMetamod)
    63 			{
    64 				makefile_name = "Makefile.orig";
    65 			}
    66 
    67 			/* Clean the project first */
    68 			info.WorkingDirectory = path;
    69 			info.FileName = cfg.builder_path;
    70 			info.Arguments = "-f " + makefile_name + " clean";
    71 			info.UseShellExecute = false;
    72 
    73 			Process p = Process.Start(info);
    74 			p.WaitForExit();
    75 			p.Close();
    76 
    77 			/* Now build it */
    78 			info.WorkingDirectory = path;
    79 			info.FileName = cfg.builder_path;
    80 			info.Arguments = "-f " + makefile_name;
    81 			info.UseShellExecute = false;
    82 
    83 			if (cfg.build_options != null)
    84 			{
    85 				info.Arguments += " " + cfg.build_options;
    86 			}
    87 
    88 			p = Process.Start(info);
    89 			p.WaitForExit();
    90 			p.Close();
    91 
    92 			if (!File.Exists(binpath))
    93 			{
    94 				return false;
    95 			}
    96 			
    97 			path = Config.PathFormat("{0}/{1}/{2}/{3}",
    98 				cfg.pkg_path,
    99 				pkg.GetBaseFolder(),
   100 				lib.package_path,
   101 				binName);
   102 			File.Copy(binpath, path, true);
   103 
   104 			return true;
   105 		}
   106 	}
   107 }