tools/builder/LinuxBuilder.cs
author Scott Ehlert <ds@alliedmods.net>
Tue May 13 08:22:49 2008 +0000 (2008-05-13)
changeset 2051 568678a2e847
parent 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Trunk build fixes
Fixed up IGameHelpers.h such that it no longer requires HL2SDK headers if a function doesn't need them
     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 
    53 			string binpath = Config.PathFormat("{0}/{1}/{2}",
    54 				path,
    55 				output_folder,
    56 				binName);
    57 			
    58 			if (File.Exists(binpath))
    59 			{
    60 				File.Delete(binpath);
    61 			}
    62 
    63 			string makefile_args = "";
    64 
    65 			if (lib.build_mode == BuildMode.BuildMode_Episode1)
    66 			{
    67 				makefile_args = null;
    68 			}
    69 			else if (lib.build_mode == BuildMode.BuildMode_Episode2)
    70 			{
    71 				makefile_args = "ENGINE=\"orangebox\"";
    72 			}
    73 			else if (lib.build_mode == BuildMode.BuildMode_OldMetamod)
    74 			{
    75 				makefile_args = "ENGINE=\"original\"";
    76 			}
    77 
    78 			/* Clean the project first */
    79 			info.WorkingDirectory = path;
    80 			info.FileName = cfg.builder_path;
    81 			info.Arguments = makefile_args + " clean";
    82 			info.UseShellExecute = false;
    83 
    84 			Process p = Process.Start(info);
    85 			p.WaitForExit();
    86 			p.Close();
    87 
    88 			/* Now build it */
    89 			info.WorkingDirectory = path;
    90 			info.FileName = cfg.builder_path;
    91 			info.Arguments = makefile_args;
    92 			info.UseShellExecute = false;
    93 
    94 			if (cfg.build_options != null)
    95 			{
    96 				info.Arguments += " " + cfg.build_options;
    97 			}
    98 
    99 			p = Process.Start(info);
   100 			p.WaitForExit();
   101 			p.Close();
   102 
   103 			if (!File.Exists(binpath))
   104 			{
   105 				return false;
   106 			}
   107 			
   108 			path = Config.PathFormat("{0}/{1}/{2}/{3}",
   109 				cfg.pkg_path,
   110 				pkg.GetBaseFolder(),
   111 				lib.package_path,
   112 				binName);
   113 			File.Copy(binpath, path, true);
   114 
   115 			return true;
   116 		}
   117 	}
   118 }