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']}
14 self.possibleSdks['ep2'] = {'sdk': 'HL2SDKOB', 'ext': '2.ep2', 'def': '3',
15 'name': 'ORANGEBOX', 'platform': ['windows', 'linux']}
16 self.possibleSdks['ep2v'] = {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v', 'def': '6',
17 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin']}
18 self.possibleSdks['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '7',
19 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux', 'darwin']}
20 self.possibleSdks['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '8',
21 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux', 'darwin']}
22 self.possibleSdks['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '2.darkm', 'def': '2',
23 'name': 'DARKMESSIAH', 'platform': ['windows']}
24 self.possibleSdks['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '2.swarm', 'def': '9',
25 'name': 'ALIENSWARM', 'platform': ['windows']}
26 self.possibleSdks['bgt'] = {'sdk': 'HL2SDK-BGT', 'ext': '2.bgt', 'def': '4',
27 'name': 'BLOODYGOODTIME', 'platform': ['windows']}
28 self.possibleSdks['eye'] = {'sdk': 'HL2SDK-EYE', 'ext': '2.eye', 'def': '5',
29 'name': 'EYE', 'platform': ['windows']}
33 if AMBuild.mode == 'config':
35 self.compiler.DetectAll(AMBuild)
39 if AMBuild.target['platform'] != 'darwin':
40 envvars['HL2SDK'] = 'hl2sdk'
41 envvars['HL2SDKOB'] = 'hl2sdk-ob'
43 envvars['HL2SDKOBVALVE'] = 'hl2sdk-ob-valve'
44 envvars['HL2SDKL4D'] = 'hl2sdk-l4d'
45 envvars['HL2SDKL4D2'] = 'hl2sdk-l4d2'
47 #Dark Messiah is Windows-only
48 if AMBuild.target['platform'] == 'windows':
49 envvars['HL2SDK-DARKM'] = 'hl2sdk-darkm'
50 envvars['HL2SDK-SWARM'] = 'hl2sdk-swarm'
51 envvars['HL2SDK-BGT'] = 'hl2sdk-bgt'
52 envvars['HL2SDK-EYE'] = 'hl2sdk-eye'
54 # Finds if a dict with `key` set to `value` is present on the dict of dicts `dictionary`
55 def findDictByKey(dictionary, key, value):
56 for index in dictionary:
57 elem = dictionary[index]
58 if elem[key] == value:
65 if not os.path.isdir(path):
66 raise Exception('Path for {0} was not found: {1}'.format(i, path))
67 elif i.startswith('HL2SDK'):
68 (info, sdk) = findDictByKey(self.possibleSdks, 'sdk', i)
69 self.sdkInfo[sdk] = info
73 while head != None and head != oldhead:
74 path = os.path.join(head, envvars[i])
75 if os.path.isdir(path):
78 head, tail = os.path.split(head)
79 if i.startswith('HL2SDK'):
80 if head != None and head != oldhead:
81 (info, sdk) = findDictByKey(self.possibleSdks, 'sdk', i)
82 self.sdkInfo[sdk] = info
83 elif head == None or head == oldhead:
84 raise Exception('Could not find a valid path for {0}'.format(i))
85 AMBuild.cache.CacheVariable(i, path)
87 if len(self.sdkInfo) < 1:
88 raise Exception('At least one SDK must be available.')
90 AMBuild.cache.CacheVariable('sdkInfo', self.sdkInfo)
93 cxx = self.compiler.cxx
94 if isinstance(cxx, Cpp.CompatGCC):
95 if isinstance(cxx, Cpp.GCC):
97 elif isinstance(cxx, Cpp.Clang):
99 self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
100 self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
101 self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
102 self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
103 self.compiler.AddToListVar('CFLAGS', '-pipe')
104 self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
105 if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
106 self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
107 self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
108 self.compiler.AddToListVar('CFLAGS', '-Wall')
109 self.compiler.AddToListVar('CFLAGS', '-Werror')
110 self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
111 self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
112 self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
113 self.compiler.AddToListVar('CFLAGS', '-msse')
114 self.compiler.AddToListVar('CFLAGS', '-m32')
115 self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
116 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
117 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
118 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
119 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
120 self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
121 if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
122 (self.vendor == 'clang' and cxx.majorVersion >= 3):
123 self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
124 self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
125 if self.vendor == 'gcc':
126 self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
127 elif isinstance(cxx, Cpp.MSVC):
129 if AMBuild.options.debug == '1':
130 self.compiler.AddToListVar('CFLAGS', '/MTd')
131 self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
133 self.compiler.AddToListVar('CFLAGS', '/MT')
134 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
135 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
136 self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
137 self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
138 self.compiler.AddToListVar('CXXFLAGS', '/GR-')
139 self.compiler.AddToListVar('CFLAGS', '/W3')
140 self.compiler.AddToListVar('CFLAGS', '/nologo')
141 self.compiler.AddToListVar('CFLAGS', '/Zi')
142 self.compiler.AddToListVar('CXXFLAGS', '/TP')
143 self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
144 self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
145 self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
146 self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
147 self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
148 self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
149 self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
150 self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
151 self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
152 self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
153 self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
154 self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
155 self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
156 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
157 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
160 if AMBuild.options.opt == '1':
161 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
162 if self.vendor == 'gcc' or self.vendor == 'clang':
163 self.compiler.AddToListVar('CFLAGS', '-O3')
164 elif self.vendor == 'msvc':
165 self.compiler.AddToListVar('CFLAGS', '/Ox')
166 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
167 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
170 if AMBuild.options.debug == '1':
171 self.compiler.AddToListVar('CDEFINES', 'DEBUG')
172 self.compiler.AddToListVar('CDEFINES', '_DEBUG')
173 if self.vendor == 'gcc' or self.vendor == 'clang':
174 self.compiler.AddToListVar('CFLAGS', '-g3')
175 elif self.vendor == 'msvc':
176 self.compiler.AddToListVar('CFLAGS', '/Od')
177 self.compiler.AddToListVar('CFLAGS', '/RTC1')
180 if AMBuild.target['platform'] == 'linux':
181 self.compiler.AddToListVar('CDEFINES', '_LINUX')
182 if self.vendor == 'gcc':
183 self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
184 if self.vendor == 'clang':
185 self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
186 elif AMBuild.target['platform'] == 'darwin':
187 self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
188 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
189 self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
191 # For OS X dylib versioning
193 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
194 productContents = productFile.read()
196 m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
198 self.version = '1.0.0'
200 major, minor, release = m.groups()
201 self.version = '{0}.{1}.{2}'.format(major, minor, release)
202 AMBuild.cache.CacheVariable('version', self.version)
203 elif AMBuild.target['platform'] == 'windows':
204 self.compiler.AddToListVar('CDEFINES', 'WIN32')
205 self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
208 self.compiler.AddToListVar('CDEFINES', 'MMS_GENERATED_BUILD')
209 self.compiler.AddToListVar('CINCLUDES',
210 os.path.join(AMBuild.outputFolder, 'includes'))
211 self.compiler.ToConfig(AMBuild, 'compiler')
212 AMBuild.cache.CacheVariable('vendor', self.vendor)
214 AMBuild.cache.CacheVariable('targetMap', self.targetMap)
216 self.sdkInfo = AMBuild.cache['sdkInfo']
217 self.compiler.FromConfig(AMBuild, 'compiler')
218 self.targetMap = AMBuild.cache['targetMap']
220 if AMBuild.target['platform'] == 'windows':
221 self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
222 self.compiler.AddToListVar('RCINCLUDES',
223 os.path.join(AMBuild.outputFolder, 'includes'))
225 def DefaultCompiler(self):
226 compiler = self.compiler.Clone()
227 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public'))
230 def JobMatters(self, jobname):
231 file = sys._getframe().f_code.co_filename
232 if AMBuild.mode == 'config':
233 self.targetMap[jobname] = file
235 if len(AMBuild.args) == 0:
237 if not jobname in AMBuild.args:
240 def AutoVersion(self, folder, binary):
241 if AMBuild.target['platform'] == 'windows':
242 env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'MMS_GENERATED_BUILD']}
243 binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
244 elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
245 binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
246 binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
250 def PreSetupHL2Job(self, job, builder, sdk):
251 info = self.sdkInfo[sdk]
252 sdkPath = AMBuild.cache[info['sdk']]
253 if AMBuild.target['platform'] == 'linux':
255 staticLibs = os.path.join(sdkPath, 'linux_sdk')
257 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
258 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
259 if sdk in ['ep2v', 'l4d', 'l4d2']:
260 for i in ['tier1_i486.a', 'libvstdlib.so', 'libtier0.so']:
261 link = os.path.join(workFolder, i)
262 target = os.path.join(staticLibs, i)
266 job.AddCommand(SymlinkCommand(link, target))
268 for i in ['tier1_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
269 link = os.path.join(workFolder, i)
270 target = os.path.join(staticLibs, i)
274 job.AddCommand(SymlinkCommand(link, target))
275 elif AMBuild.target['platform'] == 'darwin':
276 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
277 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
278 for i in ['tier1_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']:
279 link = os.path.join(workFolder, i)
280 target = os.path.join(staticLibs, i)
284 job.AddCommand(SymlinkCommand(link, target))
285 elif AMBuild.target['platform'] == 'windows':
286 libs = ['tier0', 'tier1', 'vstdlib']
288 libs.append('interfaces')
290 libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
291 builder.RebuildIfNewer(libPath)
292 builder['POSTLINKFLAGS'].append(libPath)
294 def PostSetupHL2Job(self, job, builder, sdk):
295 if AMBuild.target['platform'] in ['linux', 'darwin']:
296 builder.AddObjectFiles(['tier1_i486.a'])
298 def DefaultHL2Compiler(self, path, sdk, noLink = False):
299 compiler = self.DefaultCompiler()
301 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path))
302 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sourcehook'))
303 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'loader'))
305 info = self.possibleSdks
306 compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
308 paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
309 ['public', 'tier0'], ['public', 'tier1']]
310 if sdk == 'ep1' or sdk == 'darkm':
311 paths.append(['public', 'dlls'])
312 paths.append(['game_shared'])
314 paths.append(['public', 'game', 'server'])
315 paths.append(['game', 'shared'])
316 paths.append(['common'])
318 info = self.sdkInfo[sdk]
319 sdkPath = AMBuild.cache[info['sdk']]
321 compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
323 if sdk == 'swarm' and AMBuild.target['platform'] == 'windows':
324 compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
327 if AMBuild.target['platform'] == 'linux':
328 staticLibs = os.path.join(sdkPath, 'linux_sdk')
330 if AMBuild.target['platform'] == 'linux':
331 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
332 elif AMBuild.target['platform'] == 'darwin':
333 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
336 compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
339 if AMBuild.target['platform'] == 'linux':
340 compiler['POSTLINKFLAGS'][0:0] = ['-lm']
341 if sdk in ['ep2v', 'l4d', 'l4d2']:
342 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
343 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
345 compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
346 compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
347 elif AMBuild.target['platform'] == 'darwin':
348 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
349 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
358 AMBuild.Include(os.path.join('support', 'buildbot', 'Versioning'), globals)
361 ['loader', 'AMBuilder'],
362 ['core', 'AMBuilder'],
363 ['core-legacy', 'AMBuilder'],
364 ['support', 'buildbot', 'PackageScript']
367 for parts in FileList:
368 AMBuild.Include(os.path.join(*parts), globals)