1 # vim: set ts=2 sw=2 tw=99 noet ft=python:
4 from ambuild.command import SymlinkCommand
8 self.compiler = Cpp.Compiler()
11 self.possibleSdks = { }
12 self.possibleSdks['ep1'] = {'sdk': 'HL2SDK', 'ext': '1.ep1', 'def': '1',
13 'name': 'EPISODEONE', 'platform': ['windows', 'linux'],
15 self.possibleSdks['ep2'] = {'sdk': 'HL2SDKOB', 'ext': '2.ep2', 'def': '3',
16 'name': 'ORANGEBOX', 'platform': ['windows', 'linux'],
18 self.possibleSdks['css'] = {'sdk': 'HL2SDKCSS', 'ext': '2.css', 'def': '6',
19 'name': 'CSS', 'platform': ['windows', 'linux', 'darwin'],
21 self.possibleSdks['hl2dm'] = {'sdk': 'HL2SDKHL2DM', 'ext': '2.hl2dm', 'def': '7',
22 'name': 'HL2DM', 'platform': ['windows', 'linux', 'darwin'],
23 'dir': 'hl2sdk-hl2dm'}
24 self.possibleSdks['dods'] = {'sdk': 'HL2SDKDODS', 'ext': '2.dods', 'def': '8',
25 'name': 'DODS', 'platform': ['windows', 'linux', 'darwin'],
27 self.possibleSdks['tf2'] = {'sdk': 'HL2SDKTF2', 'ext': '2.tf2', 'def': '9',
28 'name': 'TF2', 'platform': ['windows', 'linux', 'darwin'],
30 self.possibleSdks['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '10',
31 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux', 'darwin'],
33 self.possibleSdks['nd'] = {'sdk': 'HL2SDKND', 'ext': '2.nd', 'def': '11',
34 'name': 'NUCLEARDAWN', 'platform': ['windows', 'linux', 'darwin'],
36 self.possibleSdks['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '12',
37 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux', 'darwin'],
39 self.possibleSdks['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '2.darkm', 'def': '2',
40 'name': 'DARKMESSIAH', 'platform': ['windows'],
41 'dir': 'hl2sdk-darkm'}
42 self.possibleSdks['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '2.swarm', 'def': '13',
43 'name': 'ALIENSWARM', 'platform': ['windows'],
44 'dir': 'hl2sdk-swarm'}
45 self.possibleSdks['bgt'] = {'sdk': 'HL2SDK-BGT', 'ext': '2.bgt', 'def': '4',
46 'name': 'BLOODYGOODTIME', 'platform': ['windows'],
48 self.possibleSdks['eye'] = {'sdk': 'HL2SDK-EYE', 'ext': '2.eye', 'def': '5',
49 'name': 'EYE', 'platform': ['windows'],
51 self.possibleSdks['csgo'] = {'sdk': 'HL2SDKCSGO', 'ext': '2.csgo', 'def': '15',
52 'name': 'CSGO', 'platform': ['windows', 'linux', 'darwin'],
54 self.possibleSdks['dota'] = {'sdk': 'HL2SDKDOTA', 'ext': '2.dota', 'def': '16',
55 'name': 'DOTA', 'platform': ['windows'],
57 # self.possibleSdks['portal2'] = {'sdk': 'HL2SDK-PORTAL2', 'ext': '2.portal2', 'def': '14',
58 # 'name': 'PORTAL2', 'platform': ['windows'],
59 # 'dir': 'hl2sdk-portal2'}
63 if AMBuild.mode == 'config':
65 self.compiler.DetectAll(AMBuild)
67 #Look for SDK directories
68 for sdk in self.possibleSdks:
69 #Get list of SDKs to build against or 'all' or 'present'
70 sdkList = AMBuild.options.sdks.split(',')
71 #Build against all supported SDKs?
72 useAll = sdkList[0] == 'all'
73 #Build against supported SDKs that exist?
74 usePresent = sdkList[0] == 'present'
76 info = self.possibleSdks[sdk]
77 if AMBuild.target['platform'] in info['platform']:
80 sdkPath = self.ResolveEnvPath(env, dir)
82 if useAll or sdk in sdkList:
83 raise Exception('Could not find a valid path for {0}'.format(env))
86 if useAll or usePresent or sdk in sdkList:
87 self.sdkInfo[sdk] = info
88 AMBuild.cache.CacheVariable(env, sdkPath)
90 if len(self.sdkInfo) < 1:
91 raise Exception('At least one SDK must be available.')
93 AMBuild.cache.CacheVariable('sdkInfo', self.sdkInfo)
96 cxx = self.compiler.cxx
97 if isinstance(cxx, Cpp.CompatGCC):
98 if isinstance(cxx, Cpp.GCC):
100 elif isinstance(cxx, Cpp.Clang):
101 self.vendor = 'clang'
102 self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
103 self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
104 self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
105 self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
106 self.compiler.AddToListVar('CFLAGS', '-pipe')
107 self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
108 if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
109 self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
110 self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
111 self.compiler.AddToListVar('CFLAGS', '-Wall')
112 self.compiler.AddToListVar('CFLAGS', '-Werror')
113 self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
114 self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
115 self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
116 self.compiler.AddToListVar('CFLAGS', '-msse')
117 self.compiler.AddToListVar('CFLAGS', '-m32')
118 self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
119 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
120 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
121 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
122 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
123 self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
124 if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
125 (self.vendor == 'clang' and cxx.majorVersion >= 3):
126 self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
127 self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
128 self.compiler.AddToListVar('CDEFINES', 'GNUC')
129 if self.vendor == 'gcc':
130 self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
131 elif isinstance(cxx, Cpp.MSVC):
133 if AMBuild.options.debug == '1':
134 self.compiler.AddToListVar('CFLAGS', '/MTd')
135 self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
137 self.compiler.AddToListVar('CFLAGS', '/MT')
138 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
139 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
140 self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
141 self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
142 self.compiler.AddToListVar('CXXFLAGS', '/GR-')
143 self.compiler.AddToListVar('CFLAGS', '/W3')
144 self.compiler.AddToListVar('CFLAGS', '/nologo')
145 self.compiler.AddToListVar('CFLAGS', '/Zi')
146 self.compiler.AddToListVar('CXXFLAGS', '/TP')
147 self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
148 self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
149 self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
150 self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
151 self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
152 self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
153 self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
154 self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
155 self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
156 self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
157 self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
158 self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
159 self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
160 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
161 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
164 if AMBuild.options.opt == '1':
165 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
166 if self.vendor == 'gcc' or self.vendor == 'clang':
167 self.compiler.AddToListVar('CFLAGS', '-O3')
168 elif self.vendor == 'msvc':
169 self.compiler.AddToListVar('CFLAGS', '/Ox')
170 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
171 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
174 if AMBuild.options.debug == '1':
175 self.compiler.AddToListVar('CDEFINES', 'DEBUG')
176 self.compiler.AddToListVar('CDEFINES', '_DEBUG')
177 if self.vendor == 'gcc' or self.vendor == 'clang':
178 self.compiler.AddToListVar('CFLAGS', '-g3')
179 elif self.vendor == 'msvc':
180 self.compiler.AddToListVar('CFLAGS', '/Od')
181 self.compiler.AddToListVar('CFLAGS', '/RTC1')
183 #This needs to be after our optimization flags which could otherwise disable it.
184 if self.vendor == 'msvc':
185 # Don't omit frame pointer
186 self.compiler.AddToListVar('CFLAGS', '/Oy-')
189 if AMBuild.target['platform'] == 'linux':
190 self.compiler.AddToListVar('CDEFINES', '_LINUX')
191 self.compiler.AddToListVar('CDEFINES', 'POSIX')
192 if self.vendor == 'gcc':
193 self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
194 if self.vendor == 'clang':
195 self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
196 elif AMBuild.target['platform'] == 'darwin':
197 self.compiler.AddToListVar('CDEFINES', 'OSX')
198 self.compiler.AddToListVar('CDEFINES', '_OSX')
199 self.compiler.AddToListVar('CDEFINES', 'POSIX')
200 self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
201 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
202 self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
204 # For OS X dylib versioning
206 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
207 productContents = productFile.read()
209 m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
211 self.version = '1.0.0'
213 major, minor, release = m.groups()
214 self.version = '{0}.{1}.{2}'.format(major, minor, release)
215 AMBuild.cache.CacheVariable('version', self.version)
216 elif AMBuild.target['platform'] == 'windows':
217 self.compiler.AddToListVar('CDEFINES', 'WIN32')
218 self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
221 self.compiler.AddToListVar('CDEFINES', 'MMS_GENERATED_BUILD')
222 self.compiler.AddToListVar('CINCLUDES',
223 os.path.join(AMBuild.outputFolder, 'includes'))
224 self.compiler.ToConfig(AMBuild, 'compiler')
225 AMBuild.cache.CacheVariable('vendor', self.vendor)
227 AMBuild.cache.CacheVariable('targetMap', self.targetMap)
229 self.sdkInfo = AMBuild.cache['sdkInfo']
230 self.compiler.FromConfig(AMBuild, 'compiler')
231 self.targetMap = AMBuild.cache['targetMap']
233 if AMBuild.target['platform'] == 'windows':
234 self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
235 self.compiler.AddToListVar('RCINCLUDES',
236 os.path.join(AMBuild.outputFolder, 'includes'))
238 def DefaultCompiler(self):
239 compiler = self.compiler.Clone()
240 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public'))
243 def JobMatters(self, jobname):
244 file = sys._getframe().f_code.co_filename
245 if AMBuild.mode == 'config':
246 self.targetMap[jobname] = file
248 if len(AMBuild.args) == 0:
250 if not jobname in AMBuild.args:
253 def AutoVersion(self, folder, binary):
254 if AMBuild.target['platform'] == 'windows':
255 env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'MMS_GENERATED_BUILD']}
256 binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
257 elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
258 binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
259 binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
263 def PreSetupHL2Job(self, job, builder, sdk):
264 info = self.sdkInfo[sdk]
265 sdkPath = AMBuild.cache[info['sdk']]
266 if AMBuild.target['platform'] == 'linux':
268 staticLibs = os.path.join(sdkPath, 'linux_sdk')
270 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
271 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
272 if sdk in ['css', 'hl2dm', 'dods', 'tf2', 'l4d2']:
273 libs = ['tier1_i486.a', 'libvstdlib_srv.so', 'libtier0_srv.so']
275 link = os.path.join(workFolder, lib)
276 target = os.path.join(staticLibs, lib)
280 job.AddCommand(SymlinkCommand(link, target))
281 elif sdk in ['l4d', 'nd', 'csgo']:
282 libs = ['tier1_i486.a', 'libvstdlib.so', 'libtier0.so']
284 libs.insert(0, 'interfaces_i486.a')
286 link = os.path.join(workFolder, lib)
287 target = os.path.join(staticLibs, lib)
291 job.AddCommand(SymlinkCommand(link, target))
293 for i in ['tier1_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
294 link = os.path.join(workFolder, i)
295 target = os.path.join(staticLibs, i)
299 job.AddCommand(SymlinkCommand(link, target))
300 elif AMBuild.target['platform'] == 'darwin':
301 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
302 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
303 libs = ['tier1_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']
305 libs.append('interfaces_i486.a')
307 link = os.path.join(workFolder, lib)
308 target = os.path.join(staticLibs, lib)
312 job.AddCommand(SymlinkCommand(link, target))
313 elif AMBuild.target['platform'] == 'windows':
314 libs = ['tier0', 'tier1', 'vstdlib']
315 if sdk in ['swarm', 'csgo', 'dota']:
316 libs.append('interfaces')
318 libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
319 builder.RebuildIfNewer(libPath)
320 builder['POSTLINKFLAGS'].append(libPath)
322 def PostSetupHL2Job(self, job, builder, sdk):
323 if AMBuild.target['platform'] in ['linux', 'darwin']:
324 builder.AddObjectFiles(['tier1_i486.a'])
325 if( sdk in ['csgo', 'dota'] ):
326 builder.AddObjectFiles(['interfaces_i486.a'])
328 def DefaultHL2Compiler(self, path, sdk, noLink = False):
329 compiler = self.DefaultCompiler()
331 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path))
332 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sourcehook'))
333 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'loader'))
335 info = self.possibleSdks
336 compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
338 # We don't build for Portal 2 (yet?, ever?), but using this define in code as
339 # it saves trouble if we ever need to
340 compiler['CDEFINES'].append('SE_PORTAL2=14')
342 paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
343 ['public', 'tier0'], ['public', 'tier1']]
344 if sdk == 'ep1' or sdk == 'darkm':
345 paths.append(['public', 'dlls'])
346 paths.append(['game_shared'])
348 paths.append(['public', 'game', 'server'])
349 paths.append(['game', 'shared'])
350 paths.append(['common'])
352 info = self.sdkInfo[sdk]
353 sdkPath = AMBuild.cache[info['sdk']]
355 compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
357 if sdk in ['swarm', 'csgo', 'dota']:
358 if AMBuild.target['platform'] == 'windows':
359 compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
361 compiler['CDEFINES'].extend(['COMPILER_GCC'])
364 if AMBuild.target['platform'] == 'linux':
365 staticLibs = os.path.join(sdkPath, 'linux_sdk')
367 if AMBuild.target['platform'] == 'linux':
368 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
369 elif AMBuild.target['platform'] == 'darwin':
370 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
373 compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
376 if AMBuild.target['platform'] == 'linux':
377 compiler['POSTLINKFLAGS'][0:0] = ['-lm']
378 if sdk in ['css', 'hl2dm', 'dods', 'tf2', 'l4d2']:
379 compiler['POSTLINKFLAGS'][0:0] = ['libtier0_srv.so']
380 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib_srv.so']
381 elif sdk in ['l4d', 'nd', 'csgo']:
382 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
383 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
385 compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
386 compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
387 elif AMBuild.target['platform'] == 'darwin':
388 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
389 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
393 def ResolveEnvPath(self, env, defaultDir):
394 if env in os.environ:
395 path = os.environ[env]
396 if os.path.isdir(path):
401 while head != None and head != oldhead:
402 path = os.path.join(head, defaultDir)
403 if os.path.isdir(path):
406 head, tail = os.path.split(head)
414 AMBuild.Include(os.path.join('support', 'buildbot', 'Versioning'), globals)
417 ['loader', 'AMBuilder'],
418 ['core', 'AMBuilder'],
419 ['core-legacy', 'AMBuilder'],
420 ['support', 'buildbot', 'PackageScript']
423 for parts in FileList:
424 AMBuild.Include(os.path.join(*parts), globals)