AMBuildScript
author Nicholas Hastings <skamonkey@gmail.com>
Mon Sep 09 18:41:54 2013 -0400 (2013-09-09)
changeset 4119 4de47ca41c58
parent 4105 c523a3bcfa57
child 4141 8ff66ae5ffcc
permissions -rw-r--r--
Initialize DamageCustom var in SDKHooks CTakeDamageInfoHack (nobug, r=asherkin).
     1 # vim: set ts=2 sw=2 tw=99 noet ft=python:
     2 import os
     3 import sys
     4 from ambuild.command import Command
     5 from ambuild.command import ShellCommand
     6 from ambuild.command import SymlinkCommand
     7 
     8 class ExtractDebugInfoCommand(Command):
     9 	def __init__(self, binary, outfile):
    10 		Command.__init__(self)
    11 		self.binary = binary
    12 		self.outfile = outfile
    13 
    14 	def run(self, runner, job):
    15 		if AMBuild.cache['debug']:
    16 			return
    17 
    18 		if not self.binary.NeedsRelink(self.outfile):
    19 			return
    20 
    21 		if AMBuild.target['platform'] == 'linux':
    22 			job.AddCommand(ShellCommand('objcopy --only-keep-debug ' + self.outfile + ' ' + self.outfile + '.dbg'))
    23 			job.AddCommand(ShellCommand('objcopy --strip-debug ' + self.outfile))
    24 			job.AddCommand(ShellCommand('objcopy --add-gnu-debuglink=' + os.path.basename(self.outfile) + '.dbg ' + self.outfile))
    25 		elif AMBuild.target['platform'] == 'darwin':
    26 			job.AddCommand(ShellCommand('dsymutil ' + self.outfile))
    27 			job.AddCommand(ShellCommand('strip -S ' + self.outfile))
    28 
    29 class SM:
    30 	def __init__(self):
    31 		self.compiler = Cpp.Compiler()
    32 
    33 		#Build SDK info
    34 		self.possibleSdks = { }
    35 		self.possibleSdks['ep1'] =   {'sdk': 'HL2SDK',          'ext': '1.ep1',   'def': '1',
    36 		                         'name': 'EPISODEONE',     'platform': ['windows', 'linux'],
    37 		                         'dir': 'hl2sdk'}
    38 		self.possibleSdks['ep2'] =   {'sdk': 'HL2SDKOB',        'ext': '2.ep2',   'def': '3',
    39 		                         'name': 'ORANGEBOX',      'platform': ['windows', 'linux'],
    40 		                         'dir': 'hl2sdk-ob'}
    41 		self.possibleSdks['css'] =   {'sdk': 'HL2SDKCSS',       'ext': '2.css',   'def': '6',
    42 		                         'name': 'CSS',            'platform': ['windows', 'linux', 'darwin'],
    43 		                         'dir': 'hl2sdk-css'}
    44 		self.possibleSdks['hl2dm'] = {'sdk': 'HL2SDKHL2DM',     'ext': '2.hl2dm', 'def': '7',
    45 		                         'name': 'HL2DM',          'platform': ['windows', 'linux', 'darwin'],
    46 		                        'dir': 'hl2sdk-hl2dm'}
    47 		self.possibleSdks['dods'] =  {'sdk': 'HL2SDKDODS',      'ext': '2.dods',  'def': '8',
    48 		                         'name': 'DODS',           'platform': ['windows', 'linux', 'darwin'],
    49 		                        'dir': 'hl2sdk-dods'}
    50 		self.possibleSdks['tf2'] =   {'sdk': 'HL2SDKTF2',       'ext': '2.tf2',   'def': '9',
    51 		                         'name': 'TF2',            'platform': ['windows', 'linux', 'darwin'],
    52 		                        'dir': 'hl2sdk-tf2'}
    53 		self.possibleSdks['l4d'] =   {'sdk': 'HL2SDKL4D',       'ext': '2.l4d',   'def': '10',
    54 		                         'name': 'LEFT4DEAD',      'platform': ['windows', 'linux', 'darwin'],
    55 		                         'dir': 'hl2sdk-l4d'}
    56 		self.possibleSdks['nd'] =    {'sdk': 'HL2SDKND',        'ext': '2.nd',    'def': '11',
    57 		                         'name': 'NUCLEARDAWN',    'platform': ['windows', 'linux', 'darwin'],
    58 		                         'dir': 'hl2sdk-nd'}
    59 		self.possibleSdks['l4d2'] =  {'sdk': 'HL2SDKL4D2',      'ext': '2.l4d2',  'def': '12',
    60 		                         'name': 'LEFT4DEAD2',     'platform': ['windows', 'linux', 'darwin'],
    61 		                         'dir': 'hl2sdk-l4d2'}
    62 		self.possibleSdks['darkm'] = {'sdk': 'HL2SDK-DARKM',    'ext': '2.darkm', 'def': '2',
    63 		                         'name': 'DARKMESSIAH',    'platform': ['windows'],
    64 		                          'dir': 'hl2sdk-darkm'}
    65 		self.possibleSdks['swarm'] = {'sdk': 'HL2SDK-SWARM',    'ext': '2.swarm', 'def': '13',
    66 		                         'name': 'ALIENSWARM',     'platform': ['windows'],
    67 		                         'dir': 'hl2sdk-swarm'}
    68 		self.possibleSdks['bgt'] =   {'sdk': 'HL2SDK-BGT',      'ext': '2.bgt',   'def': '4',
    69 		                         'name': 'BLOODYGOODTIME', 'platform': ['windows'],
    70 		                         'dir': 'hl2sdk-bgt'}
    71 		self.possibleSdks['eye'] =   {'sdk': 'HL2SDK-EYE',      'ext': '2.eye',   'def': '5',
    72 		                         'name': 'EYE',            'platform': ['windows'],
    73 		                         'dir': 'hl2sdk-eye'}
    74 		self.possibleSdks['csgo'] =  {'sdk': 'HL2SDKCSGO',     'ext': '2.csgo',   'def': '15',
    75 		                         'name': 'CSGO',           'platform': ['windows', 'linux', 'darwin'],
    76 		                         'dir': 'hl2sdk-csgo'}
    77 		self.possibleSdks['dota'] =  {'sdk': 'HL2SDKDOTA',     'ext': '2.dota',   'def': '16',
    78 		                         'name': 'DOTA',           'platform': ['windows'],
    79 		                         'dir': 'hl2sdk-dota'}
    80 		# self.possibleSdks['portal2'] =  {'sdk': 'HL2SDK-PORTAL2',     'ext': '2.portal2',  'def': '14',
    81 		#                        'name': 'PORTAL2',           'platform': ['windows'],
    82 		#                        'dir': 'hl2sdk-portal2'}
    83 		
    84 		self.sdkInfo = { }
    85 
    86 		if AMBuild.mode == 'config':
    87 			#Detect compilers
    88 			self.compiler.DetectAll(AMBuild)
    89 			
    90 			self.hasMySql = AMBuild.options.hasMySql
    91 			AMBuild.cache.CacheVariable('hasMySql', self.hasMySql)
    92 
    93 			AMBuild.cache.CacheVariable('debug', AMBuild.options.debug)
    94 			
    95 			#Environment variable paths to external headers
    96 			envvars = { 'MMSOURCE110': 'mmsource-1.10', 'MYSQL5': 'mysql-5.0' }
    97 			
    98 			#Look for Metamod:Source and MySQL if not disabled
    99 			for env in envvars:
   100 				if not self.hasMySql and env == 'MYSQL5':
   101 					continue
   102 				path = self.ResolveEnvPath(env, envvars[env])
   103 				if path == None:
   104 					raise Exception('Could not find a valid path for {0}'.format(env))
   105 				AMBuild.cache.CacheVariable(env, path)
   106 			
   107 			#Look for SDK directories
   108 			for sdk in self.possibleSdks:
   109 				#Get list of SDKs to build against or 'all' or 'present'
   110 				sdkList = AMBuild.options.sdks.split(',')
   111 				#Build against all supported SDKs?
   112 				useAll = sdkList[0] == 'all'
   113 				#Build against supported SDKs that exist?
   114 				usePresent = sdkList[0] == 'present'
   115 
   116 				info = self.possibleSdks[sdk]
   117 				if AMBuild.target['platform'] in info['platform']:
   118 					env = info['sdk']
   119 					dir = info['dir']
   120 					sdkPath = self.ResolveEnvPath(env, dir)
   121 					if sdkPath == None:
   122 						if useAll or sdk in sdkList:
   123 							raise Exception('Could not find a valid path for {0}'.format(env))
   124 						else:
   125 							continue
   126 					if useAll or usePresent or sdk in sdkList:
   127 						self.sdkInfo[sdk] = info
   128 						AMBuild.cache.CacheVariable(env, sdkPath)
   129 
   130 			if len(self.sdkInfo) < 1:
   131 				raise Exception('At least one SDK must be available.')
   132 				
   133 			AMBuild.cache.CacheVariable('sdkInfo', self.sdkInfo)
   134 
   135 			#Set up defines
   136 			cxx = self.compiler.cxx
   137 			if isinstance(cxx, Cpp.CompatGCC):
   138 				if isinstance(cxx, Cpp.GCC):
   139 					self.vendor = 'gcc'
   140 				elif isinstance(cxx, Cpp.Clang):
   141 					self.vendor = 'clang'
   142 				self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
   143 				self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
   144 				self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
   145 				self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
   146 				self.compiler.AddToListVar('CFLAGS', '-pipe')
   147 				self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
   148 				if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
   149 					self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
   150 					self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
   151 				self.compiler.AddToListVar('CFLAGS', '-Wall')
   152 				self.compiler.AddToListVar('CFLAGS', '-Werror')
   153 				if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 6) or self.vendor == 'clang':
   154 					self.compiler.AddToListVar('CFLAGS', '-Wno-narrowing')
   155 				self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
   156 				self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
   157 				self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
   158 				self.compiler.AddToListVar('CFLAGS', '-msse')
   159 				self.compiler.AddToListVar('CFLAGS', '-g3')
   160 				self.compiler.AddToListVar('CFLAGS', '-m32')
   161 				self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
   162 				self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
   163 				self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
   164 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
   165 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
   166 				if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
   167 						(self.vendor == 'clang' and cxx.majorVersion >= 3):
   168 					self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
   169 				self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
   170 				self.compiler.AddToListVar('CDEFINES', 'GNUC')
   171 				if self.vendor == 'gcc':
   172 					self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
   173 			elif isinstance(cxx, Cpp.MSVC):
   174 				self.vendor = 'msvc'
   175 				if AMBuild.options.debug == '1':
   176 					self.compiler.AddToListVar('CFLAGS', '/MTd')
   177 					self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
   178 				else:
   179 					self.compiler.AddToListVar('CFLAGS', '/MT')
   180 				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
   181 				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
   182 				self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
   183 				self.compiler.AddToListVar('CDEFINES', '_ITERATOR_DEBUG_LEVEL=0')
   184 				self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
   185 				self.compiler.AddToListVar('CXXFLAGS', '/GR-')
   186 				self.compiler.AddToListVar('CFLAGS', '/W3')
   187 				self.compiler.AddToListVar('CFLAGS', '/nologo')
   188 				self.compiler.AddToListVar('CFLAGS', '/Zi')
   189 				self.compiler.AddToListVar('CXXFLAGS', '/TP')
   190 				self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
   191 				self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
   192 				self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
   193 				self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
   194 				self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
   195 				self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
   196 				self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
   197 				self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
   198 				self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
   199 				self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
   200 				self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
   201 				self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
   202 				self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
   203 				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
   204 				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
   205 
   206 			#Optimization
   207 			if AMBuild.options.opt == '1':
   208 				self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
   209 				if self.vendor == 'gcc' or self.vendor == 'clang':
   210 					self.compiler.AddToListVar('CFLAGS', '-O3')
   211 				elif self.vendor == 'msvc':
   212 					self.compiler.AddToListVar('CFLAGS', '/Ox')
   213 					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
   214 					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
   215 
   216 			#Debugging
   217 			if AMBuild.options.debug == '1':
   218 				self.compiler.AddToListVar('CDEFINES', 'DEBUG')
   219 				self.compiler.AddToListVar('CDEFINES', '_DEBUG')
   220 				if self.vendor == 'msvc':
   221 					self.compiler.AddToListVar('CFLAGS', '/Od')
   222 					self.compiler.AddToListVar('CFLAGS', '/RTC1')
   223 			
   224 			#This needs to be after our optimization flags which could otherwise disable it.
   225 			if self.vendor == 'msvc':
   226 				# Don't omit frame pointer
   227 				self.compiler.AddToListVar('CFLAGS', '/Oy-')
   228 
   229 			#Platform-specifics
   230 			if AMBuild.target['platform'] == 'linux':
   231 				self.compiler.AddToListVar('CDEFINES', '_LINUX')
   232 				self.compiler.AddToListVar('CDEFINES', 'POSIX')
   233 				if self.vendor == 'gcc':
   234 					self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
   235 				if self.vendor == 'clang':
   236 					self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
   237 			elif AMBuild.target['platform'] == 'darwin':
   238 				self.compiler.AddToListVar('CDEFINES', 'OSX')
   239 				self.compiler.AddToListVar('CDEFINES', '_OSX')
   240 				self.compiler.AddToListVar('CDEFINES', 'POSIX')
   241 				self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
   242 				self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
   243 				self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
   244 
   245 				# For OS X dylib versioning
   246 				import re
   247 				productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
   248 				productContents = productFile.read()
   249 				productFile.close()
   250 				m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
   251 				if m == None:
   252 					self.version = '1.0.0'
   253 				else:
   254 					major, minor, release = m.groups()
   255 					self.version = '{0}.{1}.{2}'.format(major, minor, release)
   256 				AMBuild.cache.CacheVariable('version', self.version)
   257 			elif AMBuild.target['platform'] == 'windows':
   258 				self.compiler.AddToListVar('CDEFINES', 'WIN32')
   259 				self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
   260 
   261 			#Finish up
   262 			self.compiler.AddToListVar('CDEFINES', 'SOURCEMOD_BUILD')
   263 			self.compiler.AddToListVar('CDEFINES', 'SM_GENERATED_BUILD')
   264 			self.compiler.AddToListVar('CINCLUDES',
   265 			                           os.path.join(AMBuild.outputFolder, 'includes'))
   266 			self.compiler.ToConfig(AMBuild, 'compiler')
   267 			AMBuild.cache.CacheVariable('vendor', self.vendor)
   268 			self.targetMap = { }
   269 			AMBuild.cache.CacheVariable('targetMap', self.targetMap)
   270 		else:
   271 			self.sdkInfo = AMBuild.cache['sdkInfo']
   272 			self.compiler.FromConfig(AMBuild, 'compiler')
   273 			self.targetMap = AMBuild.cache['targetMap']
   274 			self.hasMySql = AMBuild.cache['hasMySql']
   275 
   276 		if AMBuild.target['platform'] == 'windows':
   277 			self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
   278 			self.compiler.AddToListVar('RCINCLUDES',
   279 			                           os.path.join(AMBuild.outputFolder, 'includes'))
   280 		self.mmsPath = AMBuild.cache['MMSOURCE110']
   281 
   282 	def DefaultCompiler(self):
   283 		return self.compiler.Clone()
   284 
   285 	def JobMatters(self, jobname):
   286 		file = sys._getframe().f_code.co_filename
   287 		if AMBuild.mode == 'config':
   288 			self.targetMap[jobname] = file
   289 			return True
   290 		if len(AMBuild.args) == 0:
   291 			return True
   292 		if not jobname in AMBuild.args:
   293 			return False
   294 
   295 	def DefaultExtCompiler(self, path):
   296 		compiler = self.DefaultCompiler()
   297 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path))
   298 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sdk'))
   299 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public'))
   300 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'extensions'))
   301 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'sourcepawn'))
   302 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'amtl'))
   303 		return compiler
   304 
   305 	def AutoVersion(self, folder, binary):
   306 		if AMBuild.target['platform'] == 'windows':
   307 			env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'SM_GENERATED_BUILD']}
   308 			binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
   309 		elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
   310 			binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
   311 			binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
   312 		else:
   313 			return
   314 
   315 	def ExtractDebugInfo(self, job, binary):
   316 		src = os.path.join('..', AMBuild.outputFolder, job.workFolder, binary.binaryFile)
   317 		job.AddCommand(ExtractDebugInfoCommand(binary, src))
   318 
   319 	def PreSetupHL2Job(self, job, builder, sdk):
   320 		info = self.sdkInfo[sdk]
   321 		sdkPath = AMBuild.cache[info['sdk']]
   322 		if AMBuild.target['platform'] == 'linux':
   323 			if sdk == 'ep1':
   324 				staticLibs = os.path.join(sdkPath, 'linux_sdk')
   325 			else:
   326 				staticLibs = os.path.join(sdkPath, 'lib', 'linux')
   327 			workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
   328 			if sdk in ['css', 'hl2dm', 'dods', 'tf2', 'l4d2']:
   329 				libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib_srv.so', 'libtier0_srv.so']
   330 				for lib in libs:
   331 					link = os.path.join(workFolder, lib)
   332 					target = os.path.join(staticLibs, lib)
   333 					try:
   334 						os.lstat(link)
   335 					except:
   336 						job.AddCommand(SymlinkCommand(link, target))
   337 			elif sdk in ['l4d', 'nd', 'csgo']:
   338 				libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.so', 'libtier0.so']
   339 				if sdk == 'csgo':
   340 					libs.append('interfaces_i486.a')
   341 				for lib in libs:
   342 					link = os.path.join(workFolder, lib)
   343 					target = os.path.join(staticLibs, lib)
   344 					try:
   345 						os.lstat(link)
   346 					except:
   347 						job.AddCommand(SymlinkCommand(link, target))
   348 			else:
   349 				libs = ['tier1_i486.a', 'mathlib_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']
   350 				for lib in libs:
   351 					link = os.path.join(workFolder, lib)
   352 					target = os.path.join(staticLibs, lib)
   353 					try:
   354 						os.lstat(link)
   355 					except:
   356 						job.AddCommand(SymlinkCommand(link, target))
   357 		elif AMBuild.target['platform'] == 'darwin':
   358 			staticLibs = os.path.join(sdkPath, 'lib', 'mac')
   359 			workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
   360 			libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']
   361 			if sdk == 'csgo':
   362 				libs.append('interfaces_i486.a')
   363 			for lib in libs:
   364 				link = os.path.join(workFolder, lib)
   365 				target = os.path.join(staticLibs, lib)
   366 				try:
   367 					os.lstat(link)
   368 				except:
   369 					job.AddCommand(SymlinkCommand(link, target))
   370 		elif AMBuild.target['platform'] == 'windows':
   371 			libs = ['tier0', 'tier1', 'vstdlib', 'mathlib']
   372 			if sdk in ['swarm', 'csgo', 'dota']:
   373 				libs.append('interfaces')
   374 			for lib in libs:
   375 				libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
   376 				builder.RebuildIfNewer(libPath)
   377 				builder['POSTLINKFLAGS'].append(libPath)
   378 
   379 	def PostSetupHL2Job(self, job, builder, sdk):
   380 		if AMBuild.target['platform'] in ['linux', 'darwin']:
   381 			builder.AddObjectFiles(['tier1_i486.a', 'mathlib_i486.a'])
   382 			if sdk == 'csgo':
   383 				builder.AddObjectFiles(['interfaces_i486.a'])
   384 	
   385 	def DefaultHL2Compiler(self, path, sdk, noLink = False, oldMms = '-legacy'):
   386 		compiler = self.DefaultExtCompiler(path)
   387 
   388 		mms = 'core'
   389 		if sdk == 'ep1':
   390 			mms += oldMms
   391 
   392 		compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms))
   393 		compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms, 'sourcehook'))
   394 
   395 		info = self.possibleSdks
   396 		compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
   397 				
   398 		# We don't build for Portal 2 (yet?, ever?), but using this define in code as 
   399 		# it saves trouble if we ever need to
   400 		compiler['CDEFINES'].append('SE_PORTAL2=14')
   401 
   402 		paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
   403 						 ['public', 'tier0'], ['public', 'tier1']]
   404 		if sdk == 'ep1' or sdk == 'darkm':
   405 			paths.append(['public', 'dlls'])
   406 			paths.append(['game_shared'])
   407 		else:
   408 			paths.append(['public', 'game', 'server'])
   409 			paths.append(['public', 'toolframework'])
   410 			paths.append(['game', 'shared'])
   411 			paths.append(['common'])
   412 
   413 		info = self.sdkInfo[sdk]
   414 		sdkPath = AMBuild.cache[info['sdk']]
   415 
   416 		compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
   417 
   418 		if sdk in ['swarm','csgo','dota']:
   419 			if AMBuild.target['platform'] == 'windows':
   420 				compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
   421 			else:
   422 				compiler['CDEFINES'].extend(['COMPILER_GCC'])
   423 
   424 		if sdk == 'ep1':
   425 			if AMBuild.target['platform'] == 'linux':
   426 				staticLibs = os.path.join(sdkPath, 'linux_sdk')
   427 		else:
   428 			if AMBuild.target['platform'] == 'linux':
   429 				staticLibs = os.path.join(sdkPath, 'lib', 'linux')
   430 			elif AMBuild.target['platform'] == 'darwin':
   431 				staticLibs = os.path.join(sdkPath, 'lib', 'mac')
   432 
   433 		for i in paths:
   434 			compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
   435 
   436 		if not noLink:
   437 			if AMBuild.target['platform'] == 'linux':
   438 				compiler['POSTLINKFLAGS'][0:0] = ['-lm']
   439 				if sdk in ['css', 'hl2dm', 'dods', 'tf2', 'l4d2']:
   440 					compiler['POSTLINKFLAGS'][0:0] = ['libtier0_srv.so']
   441 					compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib_srv.so']
   442 				elif sdk in ['l4d', 'nd', 'csgo']:
   443 					compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
   444 					compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
   445 				else:
   446 					compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
   447 					compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
   448 			elif AMBuild.target['platform'] == 'darwin':
   449 				compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
   450 				compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
   451 
   452 		return compiler
   453 		
   454 	def ResolveEnvPath(self, env, defaultDir):
   455 		if env in os.environ:
   456 			path = os.environ[env]
   457 			if os.path.isdir(path):
   458 				return path
   459 		else:
   460 			head = os.getcwd()
   461 			oldhead = None
   462 			while head != None and head != oldhead:
   463 				path = os.path.join(head, defaultDir)
   464 				if os.path.isdir(path):
   465 					return path
   466 				oldhead = head
   467 				head, tail = os.path.split(head)
   468 		return None
   469 
   470 sm = SM()
   471 globals = {
   472 	'SM': sm
   473 }
   474 
   475 AMBuild.Include(os.path.join('tools', 'buildbot', 'Versioning'), globals)
   476 
   477 FileList = [
   478 		['loader', 'AMBuilder'],
   479 		['core', 'AMBuilder'],
   480 		['core', 'logic', 'AMBuilder'],
   481 		['extensions', 'bintools', 'AMBuilder'],
   482 		['extensions', 'clientprefs', 'AMBuilder'],
   483 		['extensions', 'cstrike', 'AMBuilder'],
   484 		['extensions', 'curl', 'AMBuilder'],
   485 		['extensions', 'geoip', 'AMBuilder'],
   486 		['extensions', 'mysql', 'AMBuilder'],
   487 		['extensions', 'sdkhooks', 'AMBuilder'],
   488 		['extensions', 'sdktools', 'AMBuilder'],
   489 		['extensions', 'topmenus', 'AMBuilder'],
   490 		['extensions', 'updater', 'AMBuilder'],
   491 		['extensions', 'sqlite', 'AMBuilder'],
   492 		['extensions', 'regex', 'AMBuilder'],
   493 		['extensions', 'tf2', 'AMBuilder'],
   494 		['sourcepawn', 'jit', 'AMBuilder'],
   495 		['sourcepawn', 'compiler', 'AMBuilder'],
   496 		['plugins', 'AMBuilder'],
   497 		['tools', 'buildbot', 'PackageScript'],
   498 		['tools', 'buildbot', 'BreakpadSymbols']
   499 	]
   500 
   501 if not sm.hasMySql:
   502 	FileList.remove(['extensions', 'mysql', 'AMBuilder'])
   503 
   504 for parts in FileList:
   505 	AMBuild.Include(os.path.join(*parts), globals)
   506