AMBuildScript
author Ruben Gonzalez <drifter01620@gmail.com>
Wed Oct 01 11:50:24 2014 -0400 (2014-10-01)
changeset 193 277c856152b0
parent 186 072ae02a1bc6
permissions -rw-r--r--
Update linix CS:GO gamedata
     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 CSSDM:
     7 	def __init__(self):
     8 		self.compiler = Cpp.Compiler()
     9 
    10 		#Build SDK info
    11 		self.sdkInfo = { }
    12 		self.sdkInfo['css'] =  {'sdk': 'HL2SDKCSS',   'ext': '2.css',  'def': '6',
    13 		                         'name': 'CSS', 'platform': ['windows', 'linux', 'darwin']}
    14 		
    15 		self.sdkInfo['csgo'] =  {'sdk': 'HL2SDKCSGO',     'ext': '2.csgo',  'def': '11',
    16 		                         'name': 'CSGO',           'platform': ['windows', 'linux']}
    17 
    18 		if AMBuild.mode == 'config':
    19 			#Detect compilers
    20 			self.compiler.DetectAll(AMBuild)
    21 
    22 			#Detect variables
    23 			envvars = { 'MMSOURCE19': 'mmsource-1.9' }
    24 			envvars['SOURCEMOD14'] = 'sourcemod-1.4'
    25 			envvars['SOURCEMOD-BIN'] = 'sourcemod-bin'
    26 			#envvars['HL2SDKOBVALVE'] = 'hl2sdk-ob-valve'
    27 			envvars['HL2SDKCSS'] = 'hl2sdk-css'
    28 			if AMBuild.target['platform'] != 'darwin':
    29 				envvars['HL2SDKCSGO'] = 'hl2sdk-csgo'
    30 
    31 			#Must have a path for each envvar (file a bug if you don't like this)
    32 			for i in envvars:
    33 				if i in os.environ:
    34 					path = os.environ[i]
    35 					if not os.path.isdir(path):
    36 						raise Exception('Path for {0} was not found: {1}'.format(i, path))
    37 				else:
    38 					head = os.getcwd()
    39 					oldhead = None
    40 					while head != None and head != oldhead:
    41 						path = os.path.join(head, envvars[i])
    42 						if os.path.isdir(path):
    43 							break
    44 						oldhead = head
    45 						head, tail = os.path.split(head)
    46 					if head == None or head == oldhead:
    47 						raise Exception('Could not find a valid path for {0}'.format(i))
    48 				AMBuild.cache.CacheVariable(i, path)
    49 
    50 			#Set up defines
    51 			cxx = self.compiler.cxx
    52 			if isinstance(cxx, Cpp.CompatGCC):
    53 				if isinstance(cxx, Cpp.GCC):
    54 					self.vendor = 'gcc'
    55 				elif isinstance(cxx, Cpp.Clang):
    56 					self.vendor = 'clang'
    57 				self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
    58 				self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
    59 				self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
    60 				self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
    61 				self.compiler.AddToListVar('CFLAGS', '-pipe')
    62 				self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
    63 				if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
    64 					self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
    65 					self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
    66 				self.compiler.AddToListVar('CFLAGS', '-Wall')
    67 				self.compiler.AddToListVar('CFLAGS', '-Werror')
    68 				self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
    69 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-invalid-offsetof')
    70 				self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
    71 				self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
    72 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
    73 				self.compiler.AddToListVar('CFLAGS', '-msse')
    74 				self.compiler.AddToListVar('CFLAGS', '-m32')
    75 				self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
    76 				self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
    77 				self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
    78 				self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
    79 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
    80 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
    81 				if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
    82 						(self.vendor == 'clang' and cxx.majorVersion >= 3):
    83 					self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
    84 				self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
    85 				if self.vendor == 'gcc':
    86 					self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
    87 			elif isinstance(cxx, Cpp.MSVC):
    88 				self.vendor = 'msvc'
    89 				if AMBuild.options.debug == '1':
    90 					self.compiler.AddToListVar('CFLAGS', '/MTd')
    91 					self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
    92 				else:
    93 					self.compiler.AddToListVar('CFLAGS', '/MT')
    94 				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
    95 				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
    96 				self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
    97 				self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
    98 				self.compiler.AddToListVar('CXXFLAGS', '/GR-')
    99 				self.compiler.AddToListVar('CFLAGS', '/W3')
   100 				self.compiler.AddToListVar('CFLAGS', '/nologo')
   101 				self.compiler.AddToListVar('CFLAGS', '/Zi')
   102 				self.compiler.AddToListVar('CXXFLAGS', '/TP')
   103 				self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
   104 				self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
   105 				self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
   106 				self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
   107 				self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
   108 				self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
   109 				self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
   110 				self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
   111 				self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
   112 				self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
   113 				self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
   114 				self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
   115 				self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
   116 				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
   117 				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
   118 
   119 			#Optimization
   120 			if AMBuild.options.opt == '1':
   121 				self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
   122 				if self.vendor == 'gcc' or self.vendor == 'clang':
   123 					self.compiler.AddToListVar('CFLAGS', '-O3')
   124 				elif self.vendor == 'msvc':
   125 					self.compiler.AddToListVar('CFLAGS', '/Ox')
   126 					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
   127 					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
   128 
   129 			#Debugging
   130 			if AMBuild.options.debug == '1':
   131 				self.compiler.AddToListVar('CDEFINES', 'DEBUG')
   132 				self.compiler.AddToListVar('CDEFINES', '_DEBUG')
   133 				if self.vendor == 'gcc' or self.vendor == 'clang':
   134 					self.compiler.AddToListVar('CFLAGS', '-g3')
   135 				elif self.vendor == 'msvc':
   136 					self.compiler.AddToListVar('CFLAGS', '/Od')
   137 					self.compiler.AddToListVar('CFLAGS', '/RTC1')
   138 
   139 			#Platform-specifics
   140 			if AMBuild.target['platform'] == 'linux':
   141 				self.compiler.AddToListVar('CDEFINES', '_LINUX')
   142 				if self.vendor == 'gcc':
   143 					self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
   144 				if self.vendor == 'clang':
   145 					self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
   146 			elif AMBuild.target['platform'] == 'darwin':
   147 				self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
   148 				self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
   149 				self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
   150 
   151 				# For OS X dylib versioning
   152 				import re
   153 				productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
   154 				productContents = productFile.read()
   155 				productFile.close()
   156 				m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
   157 				if m == None:
   158 					self.version = '1.0.0'
   159 				else:
   160 					major, minor, release = m.groups()
   161 					self.version = '{0}.{1}.{2}'.format(major, minor, release)
   162 				AMBuild.cache.CacheVariable('version', self.version)
   163 			elif AMBuild.target['platform'] == 'windows':
   164 				self.compiler.AddToListVar('CDEFINES', 'WIN32')
   165 				self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
   166 
   167 			#Finish up
   168 			self.compiler.AddToListVar('CDEFINES', 'CSSDM_GENERATED_BUILD')
   169 			self.compiler.AddToListVar('CINCLUDES',
   170 			                           os.path.join(AMBuild.outputFolder, 'includes'))
   171 			self.compiler.ToConfig(AMBuild, 'compiler')
   172 			AMBuild.cache.CacheVariable('vendor', self.vendor)
   173 			self.targetMap = { }
   174 			AMBuild.cache.CacheVariable('targetMap', self.targetMap)
   175 		else:
   176 			self.compiler.FromConfig(AMBuild, 'compiler')
   177 			self.targetMap = AMBuild.cache['targetMap']
   178 
   179 		if AMBuild.target['platform'] == 'windows':
   180 			self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
   181 			self.compiler.AddToListVar('RCINCLUDES',
   182 			                           os.path.join(AMBuild.outputFolder, 'includes'))
   183 		self.mmsPath = AMBuild.cache['MMSOURCE19']
   184 		self.smSourcePath = AMBuild.cache['SOURCEMOD14']
   185 		self.smBinPath = AMBuild.cache['SOURCEMOD-BIN']
   186 
   187 	def DefaultCompiler(self):
   188 		compiler = self.compiler.Clone()
   189 		compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, 'core', 'sourcehook'))
   190 		return compiler
   191 
   192 	def JobMatters(self, jobname):
   193 		file = sys._getframe().f_code.co_filename
   194 		if AMBuild.mode == 'config':
   195 			self.targetMap[jobname] = file
   196 			return True
   197 		if len(AMBuild.args) == 0:
   198 			return True
   199 		if not jobname in AMBuild.args:
   200 			return False
   201 
   202 	def AutoVersion(self, folder, binary):
   203 		if AMBuild.target['platform'] == 'windows':
   204 			env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'CSSDM_GENERATED_BUILD']}
   205 			binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
   206 		elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
   207 			binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
   208 			binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
   209 		else:
   210 			return
   211 
   212 	def PreSetupHL2Job(self, job, builder, sdk):
   213 		info = self.sdkInfo[sdk]
   214 		sdkPath = AMBuild.cache[info['sdk']]
   215 		if AMBuild.target['platform'] == 'linux':
   216 			if sdk == 'ep1':
   217 				staticLibs = os.path.join(sdkPath, 'linux_sdk')
   218 			else:
   219 				staticLibs = os.path.join(sdkPath, 'lib', 'linux')
   220 			workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
   221 			if sdk in ['ep2v', 'l4d', 'l4d2', 'csgo', 'css']:
   222 				libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.so', 'libtier0.so']
   223 				
   224 				if sdk in ['ep2v', 'css']:
   225 					libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib_srv.so', 'libtier0_srv.so']
   226 					
   227 				if sdk == 'csgo':
   228 					libs.append('interfaces_i486.a')
   229 					builder['POSTLINKFLAGS'].append('-lstdc++')
   230 					
   231 				for i in libs:
   232 					link = os.path.join(workFolder, i)
   233 					target = os.path.join(staticLibs, i)
   234 					try:
   235 						os.lstat(link)
   236 					except:
   237 						job.AddCommand(SymlinkCommand(link, target))
   238 			else:
   239 				for i in ['tier1_i486.a', 'mathlib_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
   240 					link = os.path.join(workFolder, i)
   241 					target = os.path.join(staticLibs, i)
   242 					try:
   243 						os.lstat(link)
   244 					except:
   245 						job.AddCommand(SymlinkCommand(link, target))
   246 		elif AMBuild.target['platform'] == 'darwin':
   247 			staticLibs = os.path.join(sdkPath, 'lib', 'mac')
   248 			workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
   249 			libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']
   250 			if sdk == 'csgo':
   251 				libs.append('interfaces_i486.a')
   252 			for i in libs:
   253 				link = os.path.join(workFolder, i)
   254 				target = os.path.join(staticLibs, i)
   255 				try:
   256 					os.lstat(link)
   257 				except:
   258 					job.AddCommand(SymlinkCommand(link, target))
   259 		elif AMBuild.target['platform'] == 'windows':
   260 			libs = ['tier0', 'tier1', 'vstdlib', 'mathlib']
   261 			if sdk == 'swarm' or sdk == 'csgo':
   262 				libs.append('interfaces')
   263 			for lib in libs:
   264 				libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
   265 				builder.RebuildIfNewer(libPath)
   266 				builder['POSTLINKFLAGS'].append(libPath)
   267 
   268 	def PostSetupHL2Job(self, job, builder, sdk):
   269 		if AMBuild.target['platform'] in ['linux', 'darwin']:
   270 			builder.AddObjectFiles(['tier1_i486.a', 'mathlib_i486.a'])
   271 			if sdk == 'csgo':
   272 				builder.AddObjectFiles(['interfaces_i486.a'])
   273 
   274 	def DefaultHL2Compiler(self, path, sdk, noLink = False, oldMms = '-legacy'):
   275 		compiler = self.DefaultCompiler()
   276 
   277 		mms = 'core'
   278 		if sdk == 'ep1':
   279 			mms += oldMms
   280 
   281 		compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms))
   282 		compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms, 'sourcehook'))
   283 		compiler['CXXINCLUDES'].append(os.path.join(self.smSourcePath, 'public'))
   284 		compiler['CXXINCLUDES'].append(os.path.join(self.smSourcePath, 'public/extensions'))
   285 		compiler['CXXINCLUDES'].append(os.path.join(self.smSourcePath, 'public/sourcepawn'))
   286 
   287 		info = self.sdkInfo
   288 		compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
   289 
   290 		paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
   291 						 ['public', 'tier0'], ['public', 'tier1']]
   292 		if sdk == 'ep1' or sdk == 'darkm':
   293 			paths.append(['public', 'dlls'])
   294 			paths.append(['game_shared'])
   295 		else:
   296 			paths.append(['public', 'game', 'server'])
   297 			paths.append(['game', 'shared'])
   298 			paths.append(['game', 'server'])
   299 			paths.append(['common'])
   300 
   301 		info = self.sdkInfo[sdk]
   302 		sdkPath = AMBuild.cache[info['sdk']]
   303 
   304 		compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
   305 
   306 		if sdk in ['swarm','csgo']:
   307 			if AMBuild.target['platform'] == 'windows':
   308 				compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
   309 			else:
   310 				compiler['CDEFINES'].extend(['COMPILER_GCC', 'POSIX'])
   311 
   312 		if sdk == 'ep1':
   313 			if AMBuild.target['platform'] == 'linux':
   314 				staticLibs = os.path.join(sdkPath, 'linux_sdk')
   315 		else:
   316 			if AMBuild.target['platform'] == 'linux':
   317 				compiler['CDEFINES'].extend(['COMPILER_GCC', 'POSIX'])
   318 				staticLibs = os.path.join(sdkPath, 'lib', 'linux')
   319 			elif AMBuild.target['platform'] == 'darwin':
   320 				compiler['CDEFINES'].extend(['OSX', 'POSIX'])
   321 				staticLibs = os.path.join(sdkPath, 'lib', 'mac')
   322 
   323 		for i in paths:
   324 			compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
   325 
   326 		if not noLink:
   327 			if AMBuild.target['platform'] == 'linux':
   328 				compiler['POSTLINKFLAGS'][0:0] = ['-lm']
   329 				if sdk in ['ep2v', 'css']:
   330 					compiler['POSTLINKFLAGS'][0:0] = ['libtier0_srv.so']
   331 					compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib_srv.so']
   332 				elif sdk in ['l4d', 'l4d2', 'csgo']:
   333 					compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
   334 					compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
   335 				else:
   336 					compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
   337 					compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
   338 			elif AMBuild.target['platform'] == 'darwin':
   339 				compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
   340 				compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
   341 
   342 		return compiler
   343 
   344 cssdm = CSSDM()
   345 globals = {
   346 	'CSSDM': cssdm
   347 }
   348 
   349 AMBuild.Include(os.path.join('buildbot', 'Versioning'), globals)
   350 
   351 FileList = [
   352 		['ExtensionBuilder'],
   353 		['PluginBuilder'],
   354 		['PackageScript']
   355 	]
   356 
   357 for parts in FileList:
   358 	AMBuild.Include(os.path.join(*parts), globals)
   359