AMBuildScript
author Nicholas Hastings <skamonkey@gmail.com>
Wed Mar 31 08:51:25 2010 -0400 (2010-03-31)
changeset 2943 1bbdb33fee53
parent 2877 e668ed09fbb4
child 2953 8238f91c0dc7
permissions -rw-r--r--
Added TF2_StunPlayer native and TF2_GetPlayerConditionFlags stock to TF2 ext. (bug 4331, r=pred)
     1 # vim: set ts=2 sw=2 tw=99 noet ft=python:
     2 import os
     3 import sys
     4 from ambuild.command import SymlinkCommand
     5 
     6 class SM:
     7 	def __init__(self):
     8 		self.compiler = Cpp.Compiler()
     9 
    10 		#Build SDK info
    11 		self.sdkInfo = { }
    12 		self.sdkInfo['ep1'] =   {'sdk': 'HL2SDK',        'ext': '1.ep1',   'def': '1',
    13 		                         'name': 'EPISODEONE'}
    14 		self.sdkInfo['ep2'] =   {'sdk': 'HL2SDKOB',      'ext': '2.ep2',   'def': '3',
    15 		                         'name': 'ORANGEBOX'}
    16 		self.sdkInfo['ep2v'] =  {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v',  'def': '4',
    17 		                         'name': 'ORANGEBOXVALVE'}
    18 		self.sdkInfo['l4d'] =   {'sdk': 'HL2SDKL4D',     'ext': '2.l4d',   'def': '5',
    19 		                         'name': 'LEFT4DEAD'}
    20 		self.sdkInfo['l4d2'] =   {'sdk': 'HL2SDKL4D2',     'ext': '2.l4d2',   'def': '6',
    21 		                         'name': 'LEFT4DEAD2'}
    22 		if AMBuild.target['platform'] == 'windows':
    23 			self.sdkInfo['darkm'] = {'sdk': 'HL2SDK-DARKM',  'ext': '2.darkm', 'def': '2',
    24 		                           'name': 'DARKMESSIAH'}
    25 
    26 		if AMBuild.mode == 'config':
    27 			#Detect compilers
    28 			self.compiler.DetectAll(AMBuild)
    29 
    30 			#Detect variables
    31 			envvars = { 'MMSOURCE18':    'mmsource-1.8',
    32 									'HL2SDK':        'hl2sdk',
    33 									'HL2SDKOB':      'hl2sdk-ob',
    34 									'HL2SDKL4D':     'hl2sdk-l4d',
    35 									'HL2SDKOBVALVE': 'hl2sdk-ob-valve',
    36 									'HL2SDKL4D2': 	 'hl2sdk-l4d2',
    37 									'MYSQL5':        'mysql-5.0'
    38 			}
    39 
    40 			#Dark Messiah is Windows-only
    41 			if AMBuild.target['platform'] == 'windows':
    42 				envvars['HL2SDK-DARKM'] = 'hl2sdk-darkm'
    43 
    44 			#Must have a path for each envvar (file a bug if you don't like this)
    45 			for i in envvars:
    46 				if i in os.environ:
    47 					path = os.environ[i]
    48 					if not os.path.isdir(path):
    49 						raise Exception('Path for {0} was not found: {1}'.format(i, path))
    50 				else:
    51 					head = os.getcwd()
    52 					oldhead = None
    53 					while head != None and head != oldhead:
    54 						path = os.path.join(head, envvars[i])
    55 						if os.path.isdir(path):
    56 							break
    57 						oldhead = head
    58 						head, tail = os.path.split(head)
    59 					if head == None or head == oldhead:
    60 						raise Exception('Could not find a valid path for {0}'.format(i))
    61 				AMBuild.cache.CacheVariable(i, path)
    62 
    63 			#Set up defines
    64 			cxx = self.compiler.cxx
    65 			if isinstance(cxx, Cpp.GCC):
    66 				self.vendor = 'gcc'
    67 				self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
    68 				self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
    69 				self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
    70 				self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
    71 				self.compiler.AddToListVar('CFLAGS', '-pipe')
    72 				self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
    73 				if cxx.majorVersion >= 4:
    74 					self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
    75 					self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
    76 				self.compiler.AddToListVar('CFLAGS', '-Wall')
    77 				self.compiler.AddToListVar('CFLAGS', '-Werror')
    78 				self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
    79 				self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
    80 				self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
    81 				self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
    82 				self.compiler.AddToListVar('CFLAGS', '-msse')
    83 				self.compiler.AddToListVar('CFLAGS', '-m32')
    84 				self.compiler.AddToListVar('CFLAGS', '-static-libgcc')
    85 				self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
    86 				self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
    87 				self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
    88 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
    89 				self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
    90 			elif isinstance(cxx, Cpp.MSVC):
    91 				self.vendor = 'msvc'
    92 				if AMBuild.options.debug == '1':
    93 					self.compiler.AddToListVar('CFLAGS', '/MTd')
    94 				else:
    95 					self.compiler.AddToListVar('CFLAGS', '/MT')
    96 				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
    97 				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
    98 				self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
    99 				self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
   100 				self.compiler.AddToListVar('CXXFLAGS', '/GR-')
   101 				self.compiler.AddToListVar('CFLAGS', '/W3')
   102 				self.compiler.AddToListVar('CFLAGS', '/nologo')
   103 				self.compiler.AddToListVar('CFLAGS', '/Zi')
   104 				self.compiler.AddToListVar('CXXFLAGS', '/TP')
   105 				self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
   106 				self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
   107 				self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
   108 				self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
   109 				self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
   110 				self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
   111 				self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
   112 				self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
   113 				self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
   114 				self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
   115 				self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
   116 				self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
   117 				self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
   118 				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
   119 				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
   120 
   121 			#Optimization
   122 			if AMBuild.options.opt == '1':
   123 				self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
   124 				if self.vendor == 'gcc':
   125 					self.compiler.AddToListVar('CFLAGS', '-O3')
   126 				elif self.vendor == 'msvc':
   127 					self.compiler.AddToListVar('CFLAGS', '/Ot')
   128 					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
   129 
   130 			#Debugging
   131 			if AMBuild.options.debug == '1':
   132 				self.compiler.AddToListVar('CDEFINES', 'DEBUG')
   133 				self.compiler.AddToListVar('CDEFINES', '_DEBUG')
   134 				if self.vendor == 'gcc':
   135 					self.compiler.AddToListVar('CFLAGS', '-g3')
   136 				elif self.vendor == 'msvc':
   137 					self.compiler.AddToListVar('CFLAGS', '/Od')
   138 					self.compiler.AddToListVar('CFLAGS', '/RTC1')
   139 
   140 			#Platform-specifics
   141 			if AMBuild.target['platform'] == 'linux':
   142 				self.compiler.AddToListVar('CDEFINES', '_LINUX')
   143 			elif AMBuild.target['platform'] == 'windows':
   144 				self.compiler.AddToListVar('CDEFINES', 'WIN32')
   145 				self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
   146 
   147 			#Finish up
   148 			self.compiler.AddToListVar('CDEFINES', 'SOURCEMOD_BUILD')
   149 			self.compiler.AddToListVar('CDEFINES', 'SM_GENERATED_BUILD')
   150 			self.compiler.AddToListVar('CINCLUDES',
   151 			                           os.path.join(AMBuild.outputFolder, 'includes'))
   152 			self.compiler.ToConfig(AMBuild, 'compiler')
   153 			AMBuild.cache.CacheVariable('vendor', self.vendor)
   154 			self.targetMap = { }
   155 			AMBuild.cache.CacheVariable('targetMap', self.targetMap)
   156 		else:
   157 			self.compiler.FromConfig(AMBuild, 'compiler')
   158 			self.targetMap = AMBuild.cache['targetMap']
   159 
   160 		if AMBuild.target['platform'] == 'windows':
   161 			self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
   162 			self.compiler.AddToListVar('RCINCLUDES',
   163 			                           os.path.join(AMBuild.outputFolder, 'includes'))
   164 		self.mmsPath = AMBuild.cache['MMSOURCE18']
   165 
   166 	def DefaultCompiler(self):
   167 		return self.compiler.Clone()
   168 
   169 	def JobMatters(self, jobname):
   170 		file = sys._getframe().f_code.co_filename
   171 		if AMBuild.mode == 'config':
   172 			self.targetMap[jobname] = file
   173 			return True
   174 		if len(AMBuild.args) == 0:
   175 			return True
   176 		if not jobname in AMBuild.args:
   177 			return False
   178 
   179 	def DefaultExtCompiler(self, path):
   180 		compiler = self.DefaultCompiler()
   181 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path))
   182 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sdk'))
   183 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public'))
   184 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'extensions'))
   185 		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'sourcepawn'))
   186 		return compiler
   187 
   188 	def AutoVersion(self, folder, binary):
   189 		if AMBuild.target['platform'] != 'windows':
   190 			return
   191 		env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'SM_GENERATED_BUILD']}
   192 		binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
   193 
   194 	def PreSetupHL2Job(self, job, builder, sdk):
   195 		info = self.sdkInfo[sdk]
   196 		sdkPath = AMBuild.cache[info['sdk']]
   197 		if AMBuild.target['platform'] == 'linux':
   198 			if sdk == 'ep1':
   199 				staticLibs = os.path.join(sdkPath, 'linux_sdk')
   200 			else:
   201 				staticLibs = os.path.join(sdkPath, 'lib', 'linux')
   202 			workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
   203 			if sdk == 'l4d2':
   204 				for i in ['tier1_i486.a', 'mathlib_i486.a', 'vstdlib_linux.so', 'tier0_linux.so']:
   205 					link = os.path.join(workFolder, i)
   206 					target = os.path.join(staticLibs, i)
   207 					try:
   208 						os.lstat(link)
   209 					except:
   210 						job.AddCommand(SymlinkCommand(link, target))
   211 			else:
   212 				for i in ['tier1_i486.a', 'mathlib_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
   213 					link = os.path.join(workFolder, i)
   214 					target = os.path.join(staticLibs, i)
   215 					try:
   216 						os.lstat(link)
   217 					except:
   218 						job.AddCommand(SymlinkCommand(link, target))
   219 		elif AMBuild.target['platform'] == 'windows':
   220 			for lib in ['tier0', 'tier1', 'vstdlib', 'mathlib']:
   221 				libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
   222 				builder.RebuildIfNewer(libPath)
   223 				builder['POSTLINKFLAGS'].append(libPath)
   224 
   225 	def PostSetupHL2Job(self, job, builder, sdk):
   226 		if AMBuild.target['platform'] == 'linux':
   227 			builder.AddObjectFiles(['tier1_i486.a', 'mathlib_i486.a'])
   228 
   229 	def DefaultHL2Compiler(self, path, sdk, noLink = False, oldMms = '-legacy'):
   230 		compiler = self.DefaultExtCompiler(path)
   231 
   232 		mms = 'core'
   233 		if sdk == 'ep1':
   234 			mms += oldMms
   235 
   236 		compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms))
   237 		compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms, 'sourcehook'))
   238 
   239 		info = self.sdkInfo
   240 		compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
   241 		compiler['CDEFINES'].append('SE_DARKMESSIAH=2')
   242 
   243 		paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
   244 						 ['public', 'tier0'], ['public', 'tier1']]
   245 		if sdk == 'ep1' or sdk == 'darkm':
   246 			paths.append(['public', 'dlls'])
   247 			paths.append(['game_shared'])
   248 		else:
   249 			paths.append(['public', 'game', 'server'])
   250 			paths.append(['game', 'shared'])
   251 			paths.append(['common'])
   252 
   253 		info = self.sdkInfo[sdk]
   254 		sdkPath = AMBuild.cache[info['sdk']]
   255 
   256 		compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
   257 
   258 		if sdk == 'ep1':
   259 			if AMBuild.target['platform'] == 'linux':
   260 				staticLibs = os.path.join(sdkPath, 'linux_sdk')
   261 		else:
   262 			if AMBuild.target['platform'] == 'linux':
   263 				staticLibs = os.path.join(sdkPath, 'lib', 'linux')
   264 
   265 		for i in paths:
   266 			compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
   267 
   268 		if not noLink:
   269 			if AMBuild.target['platform'] == 'linux':
   270 				compiler['POSTLINKFLAGS'][0:0] = ['-lm']
   271 				if sdk == 'l4d2':
   272 					compiler['POSTLINKFLAGS'][0:0] = ['tier0_linux.so']
   273 					compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_linux.so']
   274 				else:
   275 					compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
   276 					compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']				
   277 
   278 		return compiler
   279 
   280 sm = SM()
   281 globals = {
   282 	'SM': sm
   283 }
   284 
   285 AMBuild.Include(os.path.join('tools', 'buildbot', 'Versioning'), globals)
   286 
   287 FileList = [
   288 		['loader', 'AMBuilder'],
   289 		['core', 'AMBuilder'],
   290 		['core', 'logic', 'AMBuilder'],
   291 		['extensions', 'bintools', 'AMBuilder'],
   292 		['extensions', 'clientprefs', 'AMBuilder'],
   293 		['extensions', 'cstrike', 'AMBuilder'],
   294 		['extensions', 'curl', 'AMBuilder'],
   295 		['extensions', 'geoip', 'AMBuilder'],
   296 		['extensions', 'mysql', 'AMBuilder'],
   297 		['extensions', 'sdktools', 'AMBuilder'],
   298 		['extensions', 'topmenus', 'AMBuilder'],
   299 		['extensions', 'updater', 'AMBuilder'],
   300 		['extensions', 'sqlite', 'AMBuilder'],
   301 		['extensions', 'regex', 'AMBuilder'],
   302 		['extensions', 'tf2', 'AMBuilder'],
   303 		['sourcepawn', 'jit', 'AMBuilder'],
   304 		['sourcepawn', 'compiler', 'AMBuilder'],
   305 		['plugins', 'AMBuilder'],
   306 		['tools', 'buildbot', 'PackageScript']
   307 	]
   308 
   309 for parts in FileList:
   310 	AMBuild.Include(os.path.join(*parts), globals)
   311