tools/builder/LinuxBuilder.cs
author Scott Ehlert <ds@alliedmods.net>
Fri Nov 14 09:18:30 2008 -0600 (2008-11-14)
changeset 2400 76b7b4575e21
parent 2289 44045ead61cd
child 2479 44e8e76d4e53
permissions -rw-r--r--
Added preliminary support for Left 4 Dead; some things may not yet work.
     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 output_folder = (lib.release_mode == ReleaseMode.ReleaseMode_Release) ? "Release" : "Debug";
    43 
    44 			if (lib.build_mode == BuildMode.BuildMode_Episode2)
    45 			{
    46 				output_folder += ".orangebox";
    47 			}
    48 			else if (lib.build_mode == BuildMode.BuildMode_OldMetamod)
    49 			{
    50 				output_folder += ".original";
    51 			}
    52 			else if (lib.build_mode == BuildMode.BuildMode_Left4Dead)
    53 			{
    54 				output_folder += ".left4dead";
    55 			}
    56 
    57 			string binpath = Config.PathFormat("{0}/{1}/{2}",
    58 				path,
    59 				output_folder,
    60 				binName);
    61 			
    62 			if (File.Exists(binpath))
    63 			{
    64 				File.Delete(binpath);
    65 			}
    66 
    67 			string makefile_args = "";
    68 
    69 			if (lib.build_mode == BuildMode.BuildMode_Episode1)
    70 			{
    71 				makefile_args = null;
    72 			}
    73 			else if (lib.build_mode == BuildMode.BuildMode_Episode2)
    74 			{
    75 				makefile_args = "ENGINE=\"orangebox\"";
    76 			}
    77 			else if (lib.build_mode == BuildMode.BuildMode_OldMetamod)
    78 			{
    79 				makefile_args = "ENGINE=\"original\"";
    80 			}
    81 			else if (lib.build_mode == BuildMode.BuildMode_Left4Dead)
    82 			{
    83 				makefile_args = "ENGINE=\"left4dead\"";
    84 			}
    85 
    86 			/* Clean the project first */
    87 			info.WorkingDirectory = path;
    88 			info.FileName = cfg.builder_path;
    89 			info.Arguments = makefile_args + " clean";
    90 			info.UseShellExecute = false;
    91 
    92 			Process p = Process.Start(info);
    93 			p.WaitForExit();
    94 			p.Close();
    95 
    96 			/* Now build it */
    97 			info.WorkingDirectory = path;
    98 			info.FileName = cfg.builder_path;
    99 			info.Arguments = makefile_args;
   100 			info.UseShellExecute = false;
   101 
   102 			if (cfg.build_options != null)
   103 			{
   104 				info.Arguments += " " + cfg.build_options;
   105 			}
   106 
   107 			p = Process.Start(info);
   108 			p.WaitForExit();
   109 			p.Close();
   110 
   111 			if (!File.Exists(binpath))
   112 			{
   113 				return false;
   114 			}
   115 			
   116 			path = Config.PathFormat("{0}/{1}/{2}/{3}",
   117 				cfg.pkg_path,
   118 				pkg.GetBaseFolder(),
   119 				lib.package_path,
   120 				binName);
   121 			File.Copy(binpath, path, true);
   122 
   123 			return true;
   124 		}
   125 	}
   126 }