AMBuildScript
changeset 2784 8903397125e6
child 2785 9e3d5ec34f33
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/AMBuildScript	Sun Aug 30 00:46:56 2009 -0700
     1.3 @@ -0,0 +1,290 @@
     1.4 +# vim: set ts=2 sw=2 tw=99 noet ft=python:
     1.5 +import os
     1.6 +import sys
     1.7 +from ambuild.command import SymlinkCommand
     1.8 +
     1.9 +class SM:
    1.10 +	def __init__(self):
    1.11 +		self.compiler = Cpp.Compiler()
    1.12 +
    1.13 +		#Build SDK info
    1.14 +		self.sdkInfo = { }
    1.15 +		self.sdkInfo['ep1'] =   {'sdk': 'HL2SDK',        'ext': '1.ep1',   'def': '1',
    1.16 +		                         'name': 'EPISODEONE'}
    1.17 +		self.sdkInfo['ep2'] =   {'sdk': 'HL2SDKOB',      'ext': '2.ep2',   'def': '3',
    1.18 +		                         'name': 'ORANGEBOX'}
    1.19 +		self.sdkInfo['ep2v'] =  {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v',  'def': '4',
    1.20 +		                         'name': 'ORANGEBOXVALVE'}
    1.21 +		self.sdkInfo['l4d'] =   {'sdk': 'HL2SDKL4D',     'ext': '2.l4d',   'def': '5',
    1.22 +		                         'name': 'LEFT4DEAD'}
    1.23 +		if AMBuild.target['platform'] == 'windows':
    1.24 +			self.sdkInfo['darkm'] = {'sdk': 'HL2SDK-DARKM',  'ext': '2.darkm', 'def': '2',
    1.25 +		                           'name': 'DARKMESSIAH'}
    1.26 +
    1.27 +		if AMBuild.mode == 'config':
    1.28 +			#Detect compilers
    1.29 +			self.compiler.DetectAll(AMBuild)
    1.30 +
    1.31 +			#Detect variables
    1.32 +			envvars = { 'MMSOURCE17':    'mmsource-1.7',
    1.33 +									'HL2SDK':        'hl2sdk',
    1.34 +									'HL2SDKOB':      'hl2sdk-ob',
    1.35 +									'HL2SDKL4D':     'hl2sdk-l4d',
    1.36 +									'HL2SDKOBVALVE': 'hl2sdk-ob-valve',
    1.37 +									'MYSQL5':        'mysql-5.0'
    1.38 +			}
    1.39 +
    1.40 +			#Dark Messiah is Windows-only
    1.41 +			if AMBuild.target['platform'] == 'windows':
    1.42 +				envvars['HL2SDK-DARKM'] = 'hl2sdk-darkm'
    1.43 +
    1.44 +			#Must have a path for each envvar (file a bug if you don't like this)
    1.45 +			for i in envvars:
    1.46 +				if i in os.environ:
    1.47 +					path = os.environ[i]
    1.48 +					if not os.path.isdir(path):
    1.49 +						raise Exception('Path for {0} was not found: {1}'.format(i, path))
    1.50 +				else:
    1.51 +					head = os.getcwd()
    1.52 +					while head != None and head != '/':
    1.53 +						path = os.path.join(head, envvars[i])
    1.54 +						if os.path.isdir(path):
    1.55 +							break
    1.56 +						head, tail = os.path.split(head)
    1.57 +					if head == None or head == '/':
    1.58 +						raise Exception('Could not find a valid path for {0}'.format(i))
    1.59 +				AMBuild.cache.CacheVariable(i, path)
    1.60 +
    1.61 +			#Set up defines
    1.62 +			cxx = self.compiler.cxx
    1.63 +			if isinstance(cxx, Cpp.GCC):
    1.64 +				self.vendor = 'gcc'
    1.65 +				self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
    1.66 +				self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
    1.67 +				self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
    1.68 +				self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
    1.69 +				self.compiler.AddToListVar('CFLAGS', '-pipe')
    1.70 +				self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
    1.71 +				if cxx.majorVersion >= 4:
    1.72 +					self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
    1.73 +					self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
    1.74 +				self.compiler.AddToListVar('CFLAGS', '-Wall')
    1.75 +				self.compiler.AddToListVar('CFLAGS', '-Werror')
    1.76 +				self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
    1.77 +				self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
    1.78 +				self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
    1.79 +				self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
    1.80 +				self.compiler.AddToListVar('CFLAGS', '-msse')
    1.81 +				self.compiler.AddToListVar('CFLAGS', '-m32')
    1.82 +				self.compiler.AddToListVar('CFLAGS', '-static-libgcc')
    1.83 +				self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
    1.84 +				self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
    1.85 +				self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
    1.86 +				self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
    1.87 +				self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
    1.88 +			elif isinstance(cxx, Cpp.MSVC):
    1.89 +				self.vendor = 'msvc'
    1.90 +				if AMBuild.options.debug == '1':
    1.91 +					self.compiler.AddToListVar('CFLAGS', '/MTd')
    1.92 +				else:
    1.93 +					self.compiler.AddToListVar('CFLAGS', '/MT')
    1.94 +				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
    1.95 +				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
    1.96 +				self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
    1.97 +				self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
    1.98 +				self.compiler.AddToListVar('CXXFLAGS', '/GR-')
    1.99 +				self.compiler.AddToListVar('CFLAGS', '/W3')
   1.100 +				self.compiler.AddToListVar('CFLAGS', '/nologo')
   1.101 +				self.compiler.AddToListVar('CFLAGS', '/Zi')
   1.102 +				self.compiler.AddToListVar('CXXFLAGS', '/TP')
   1.103 +				self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
   1.104 +				self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
   1.105 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
   1.106 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
   1.107 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
   1.108 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
   1.109 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
   1.110 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
   1.111 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
   1.112 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
   1.113 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
   1.114 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
   1.115 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
   1.116 +				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
   1.117 +
   1.118 +			#Optimization
   1.119 +			if AMBuild.options.opt == '1':
   1.120 +				self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
   1.121 +				if self.vendor == 'gcc':
   1.122 +					self.compiler.AddToListVar('CFLAGS', '-O3')
   1.123 +				elif self.vendor == 'msvc':
   1.124 +					self.compiler.AddToListVar('CFLAGS', '/Ot')
   1.125 +					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
   1.126 +
   1.127 +			#Debugging
   1.128 +			if AMBuild.options.debug == '1':
   1.129 +				self.compiler.AddToListVar('CDEFINES', 'DEBUG')
   1.130 +				self.compiler.AddToListVar('CDEFINES', '_DEBUG')
   1.131 +				if self.vendor == 'gcc':
   1.132 +					self.compiler.AddToListVar('CFLAGS', '-g3')
   1.133 +				elif self.vendor == 'msvc':
   1.134 +					self.compiler.AddToListVar('CFLAGS', '/Od')
   1.135 +					self.compiler.AddToListVar('CFLAGS', '/RTC1')
   1.136 +
   1.137 +			#Platform-specifics
   1.138 +			if AMBuild.target['platform'] == 'linux':
   1.139 +				self.compiler.AddToListVar('CDEFINES', '_LINUX')
   1.140 +			elif AMBuild.target['platform'] == 'windows':
   1.141 +				self.compiler.AddToListVar('CDEFINES', 'WIN32')
   1.142 +				self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
   1.143 +
   1.144 +			#Finish up
   1.145 +			self.compiler.AddToListVar('CDEFINES', 'SOURCEMOD_BUILD')
   1.146 +			self.compiler.AddToListVar('CDEFINES', 'SM_GENERATED_BUILD')
   1.147 +			self.compiler.AddToListVar('CINCLUDES',
   1.148 +			                           os.path.join(AMBuild.outputFolder, 'includes'))
   1.149 +			self.compiler.ToConfig(AMBuild, 'compiler')
   1.150 +			AMBuild.cache.CacheVariable('vendor', self.vendor)
   1.151 +			self.targetMap = { }
   1.152 +			AMBuild.cache.CacheVariable('targetMap', self.targetMap)
   1.153 +		else:
   1.154 +			self.compiler.FromConfig(AMBuild, 'compiler')
   1.155 +			self.targetMap = AMBuild.cache['targetMap']
   1.156 +
   1.157 +		if AMBuild.target['platform'] == 'windows':
   1.158 +			self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
   1.159 +		self.mmsPath = AMBuild.cache['MMSOURCE17']
   1.160 +
   1.161 +	def DefaultCompiler(self):
   1.162 +		return self.compiler.Clone()
   1.163 +
   1.164 +	def JobMatters(self, jobname):
   1.165 +		file = sys._getframe().f_code.co_filename
   1.166 +		if AMBuild.mode == 'config':
   1.167 +			self.targetMap[jobname] = file
   1.168 +			return True
   1.169 +		if len(AMBuild.args) == 0:
   1.170 +			return True
   1.171 +		if not jobname in AMBuild.args:
   1.172 +			return False
   1.173 +
   1.174 +	def DefaultExtCompiler(self, path):
   1.175 +		compiler = self.DefaultCompiler()
   1.176 +		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path))
   1.177 +		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sdk'))
   1.178 +		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public'))
   1.179 +		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'extensions'))
   1.180 +		compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public', 'sourcepawn'))
   1.181 +		return compiler
   1.182 +
   1.183 +	def AutoVersion(self, folder, binary):
   1.184 +		if AMBuild.target['platform'] != 'windows':
   1.185 +			return
   1.186 +		env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"']}
   1.187 +		binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
   1.188 +
   1.189 +	def PreSetupHL2Job(self, job, builder, sdk):
   1.190 +		info = self.sdkInfo[sdk]
   1.191 +		sdkPath = AMBuild.cache[info['sdk']]
   1.192 +		if AMBuild.target['platform'] == 'linux':
   1.193 +			if sdk == 'ep1':
   1.194 +				staticLibs = os.path.join(sdkPath, 'linux_sdk')
   1.195 +			else:
   1.196 +				staticLibs = os.path.join(sdkPath, 'lib', 'linux')
   1.197 +			workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
   1.198 +			for i in ['tier1_i486.a', 'mathlib_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
   1.199 +				link = os.path.join(workFolder, i)
   1.200 +				target = os.path.join(staticLibs, i)
   1.201 +				try:
   1.202 +					os.lstat(link)
   1.203 +				except:
   1.204 +					job.AddCommand(SymlinkCommand(link, target))
   1.205 +		elif AMBuild.target['platform'] == 'windows':
   1.206 +			for lib in ['tier0', 'tier1', 'vstdlib', 'mathlib']:
   1.207 +				libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
   1.208 +				builder.RebuildIfNewer(libPath)
   1.209 +				builder['POSTLINKFLAGS'].append(libPath)
   1.210 +
   1.211 +	def PostSetupHL2Job(self, job, builder, sdk):
   1.212 +		if AMBuild.target['platform'] == 'linux':
   1.213 +			builder.AddObjectFiles(['tier1_i486.a', 'mathlib_i486.a'])
   1.214 +
   1.215 +	def DefaultHL2Compiler(self, path, sdk, noLink = False, oldMms = '-legacy'):
   1.216 +		compiler = self.DefaultExtCompiler(path)
   1.217 +
   1.218 +		mms = 'core'
   1.219 +		if sdk == 'ep1':
   1.220 +			mms += oldMms
   1.221 +
   1.222 +		compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms))
   1.223 +		compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms, 'sourcehook'))
   1.224 +
   1.225 +		info = self.sdkInfo
   1.226 +		compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
   1.227 +		compiler['CDEFINES'].append('SE_DARKMESSIAH=2')
   1.228 +
   1.229 +		paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
   1.230 +						 ['public', 'tier0'], ['public', 'tier1']]
   1.231 +		if sdk == 'ep1' or sdk == 'darkm':
   1.232 +			paths.append(['public', 'dlls'])
   1.233 +			paths.append(['game_shared'])
   1.234 +		else:
   1.235 +			paths.append(['public', 'game', 'server'])
   1.236 +			paths.append(['public', 'game', 'shared'])
   1.237 +			paths.append(['common'])
   1.238 +
   1.239 +		info = self.sdkInfo[sdk]
   1.240 +		sdkPath = AMBuild.cache[info['sdk']]
   1.241 +
   1.242 +		compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
   1.243 +
   1.244 +		if sdk == 'ep1':
   1.245 +			if AMBuild.target['platform'] == 'linux':
   1.246 +				staticLibs = os.path.join(sdkPath, 'linux_sdk')
   1.247 +		else:
   1.248 +			if AMBuild.target['platform'] == 'linux':
   1.249 +				staticLibs = os.path.join(sdkPath, 'lib', 'linux')
   1.250 +
   1.251 +		for i in paths:
   1.252 +			compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
   1.253 +
   1.254 +		if not noLink:
   1.255 +			if AMBuild.target['platform'] == 'linux':
   1.256 +				compiler['POSTLINKFLAGS'][0:0] = ['-lm']
   1.257 +				compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
   1.258 +				compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
   1.259 +
   1.260 +		return compiler
   1.261 +
   1.262 +sm = SM()
   1.263 +globals = {
   1.264 +	'SM': sm
   1.265 +}
   1.266 +
   1.267 +AMBuild.Include(os.path.join('tools', 'buildbot', 'Versioning'), globals)
   1.268 +
   1.269 +FileList = [
   1.270 +		['loader', 'AMBuilder'],
   1.271 +		['core', 'AMBuilder'],
   1.272 +		['core', 'logic', 'AMBuilder'],
   1.273 +		['extensions', 'bintools', 'AMBuilder'],
   1.274 +		['extensions', 'clientprefs', 'AMBuilder'],
   1.275 +		['extensions', 'cstrike', 'AMBuilder'],
   1.276 +		['extensions', 'curl', 'AMBuilder'],
   1.277 +		['extensions', 'geoip', 'AMBuilder'],
   1.278 +		['extensions', 'mysql', 'AMBuilder'],
   1.279 +		['extensions', 'sdktools', 'AMBuilder'],
   1.280 +		['extensions', 'topmenus', 'AMBuilder'],
   1.281 +		['extensions', 'updater', 'AMBuilder'],
   1.282 +		['extensions', 'sqlite', 'AMBuilder'],
   1.283 +		['extensions', 'regex', 'AMBuilder'],
   1.284 +		['extensions', 'tf2', 'AMBuilder'],
   1.285 +		['sourcepawn', 'jit', 'AMBuilder'],
   1.286 +		['sourcepawn', 'compiler', 'AMBuilder'],
   1.287 +		['plugins', 'AMBuilder'],
   1.288 +		['tools', 'buildbot', 'PackageScript']
   1.289 +	]
   1.290 +
   1.291 +for parts in FileList:
   1.292 +	AMBuild.Include(os.path.join(*parts), globals)
   1.293 +