1 # vim: set ts=2 sw=2 tw=99 noet ft=python:
4 from ambuild.command import SymlinkCommand
8 self.compiler = Cpp.Compiler()
12 self.sdkInfo['ep1'] = {'sdk': 'HL2SDK', 'ext': '14.ep1', 'def': '1',
13 'name': 'EPISODEONE', 'platform': ['windows', 'linux']}
14 self.sdkInfo['ep2'] = {'sdk': 'HL2SDKOB', 'ext': '16.ep2', 'def': '3',
15 'name': 'ORANGEBOX', 'platform': ['windows', 'linux']}
16 self.sdkInfo['ep2v'] = {'sdk': 'HL2SDKOBVALVE', 'ext': '16.ep2v', 'def': '5',
17 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin']}
18 self.sdkInfo['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '16.l4d', 'def': '6',
19 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux', 'darwin']}
20 self.sdkInfo['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '16.l4d2', 'def': '7',
21 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux', 'darwin']}
22 self.sdkInfo['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '16.darkm', 'def': '2',
23 'name': 'DARKMESSIAH', 'platform': ['windows']}
24 self.sdkInfo['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '16.swarm', 'def': '8',
25 'name': 'ALIENSWARM', 'platform': ['windows']}
26 self.sdkInfo['bgt'] = {'sdk': 'HL2SDK-BGT', 'ext': '16.bgt', 'def': '4',
27 'name': 'BLOODYGOODTIME', 'platform': ['windows']}
28 self.sdkInfo['csgo'] = {'sdk': 'HL2SDKCSGO', 'ext': '16.csgo', 'def': '12',
29 'name': 'CSGO', 'platform': ['windows', 'linux']}
30 self.sdkInfo['css'] = {'sdk': 'HL2SDKCSS', 'ext': '16.css', 'def': '13',
31 'name': 'CSS', 'platform': ['windows', 'linux', 'darwin']}
33 if AMBuild.mode == 'config':
35 self.compiler.DetectAll(AMBuild)
38 envvars = { 'MMSOURCE19': 'mmsource-1.9' }
39 if AMBuild.target['platform'] != 'darwin':
40 envvars['HL2SDK'] = 'hl2sdk'
41 envvars['HL2SDKOB'] = 'hl2sdk-ob'
42 envvars['HL2SDKCSGO'] = 'hl2sdk-csgo'
44 envvars['HL2SDKOBVALVE'] = 'hl2sdk-ob-valve'
45 envvars['HL2SDKL4D'] = 'hl2sdk-l4d'
46 envvars['HL2SDKL4D2'] = 'hl2sdk-l4d2'
47 envvars['HL2SDKCSS'] = 'hl2sdk-css'
49 #Dark Messiah is Windows-only
50 if AMBuild.target['platform'] == 'windows':
51 envvars['HL2SDK-DARKM'] = 'hl2sdk-darkm'
52 envvars['HL2SDK-SWARM'] = 'hl2sdk-swarm'
53 envvars['HL2SDK-BGT'] = 'hl2sdk-bgt'
55 #Must have a path for each envvar (file a bug if you don't like this)
59 if not os.path.isdir(path):
60 raise Exception('Path for {0} was not found: {1}'.format(i, path))
64 while head != None and head != oldhead:
65 path = os.path.join(head, envvars[i])
66 if os.path.isdir(path):
69 head, tail = os.path.split(head)
70 if head == None or head == oldhead:
71 raise Exception('Could not find a valid path for {0}'.format(i))
72 AMBuild.cache.CacheVariable(i, path)
75 cxx = self.compiler.cxx
76 if isinstance(cxx, Cpp.CompatGCC):
77 if isinstance(cxx, Cpp.GCC):
79 elif isinstance(cxx, Cpp.Clang):
81 self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
82 self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
83 self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
84 self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
85 self.compiler.AddToListVar('CFLAGS', '-pipe')
86 self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
87 if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
88 self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
89 self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
90 self.compiler.AddToListVar('CFLAGS', '-Wall')
91 self.compiler.AddToListVar('CFLAGS', '-Werror')
92 self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
93 self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
94 self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
95 self.compiler.AddToListVar('CFLAGS', '-msse')
96 self.compiler.AddToListVar('CFLAGS', '-m32')
97 self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
98 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
99 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
100 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
101 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
102 self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
103 if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
104 (self.vendor == 'clang' and cxx.majorVersion >= 3):
105 self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
106 self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
107 if self.vendor == 'gcc':
108 self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
109 elif isinstance(cxx, Cpp.MSVC):
111 if AMBuild.options.debug == '1':
112 self.compiler.AddToListVar('CFLAGS', '/MTd')
113 self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
115 self.compiler.AddToListVar('CFLAGS', '/MT')
116 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
117 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
118 self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
119 self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
120 self.compiler.AddToListVar('CXXFLAGS', '/GR-')
121 self.compiler.AddToListVar('CFLAGS', '/W3')
122 self.compiler.AddToListVar('CFLAGS', '/nologo')
123 self.compiler.AddToListVar('CFLAGS', '/Zi')
124 self.compiler.AddToListVar('CXXFLAGS', '/TP')
125 self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
126 self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
127 self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
128 self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
129 self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
130 self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
131 self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
132 self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
133 self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
134 self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
135 self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
136 self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
137 self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
138 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
139 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
142 if AMBuild.options.opt == '1':
143 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
144 if self.vendor == 'gcc' or self.vendor == 'clang':
145 self.compiler.AddToListVar('CFLAGS', '-O3')
146 elif self.vendor == 'msvc':
147 self.compiler.AddToListVar('CFLAGS', '/Ox')
148 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
149 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
152 if AMBuild.options.debug == '1':
153 self.compiler.AddToListVar('CDEFINES', 'DEBUG')
154 self.compiler.AddToListVar('CDEFINES', '_DEBUG')
155 if self.vendor == 'gcc' or self.vendor == 'clang':
156 self.compiler.AddToListVar('CFLAGS', '-g3')
157 elif self.vendor == 'msvc':
158 self.compiler.AddToListVar('CFLAGS', '/Od')
159 self.compiler.AddToListVar('CFLAGS', '/RTC1')
162 if AMBuild.target['platform'] == 'linux':
163 self.compiler.AddToListVar('CDEFINES', '_LINUX')
164 if self.vendor == 'gcc':
165 self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
166 if self.vendor == 'clang':
167 self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
168 elif AMBuild.target['platform'] == 'darwin':
169 self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
170 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
171 self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
173 # For OS X dylib versioning
175 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
176 productContents = productFile.read()
178 m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
180 self.version = '1.0.0'
182 major, minor, release = m.groups()
183 self.version = '{0}.{1}.{2}'.format(major, minor, release)
184 AMBuild.cache.CacheVariable('version', self.version)
185 elif AMBuild.target['platform'] == 'windows':
186 self.compiler.AddToListVar('CDEFINES', 'WIN32')
187 self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
190 self.compiler.AddToListVar('CDEFINES', 'STRIPPER_GENERATED_BUILD')
191 self.compiler.AddToListVar('CINCLUDES',
192 os.path.join(AMBuild.outputFolder, 'includes'))
193 self.compiler.ToConfig(AMBuild, 'compiler')
194 AMBuild.cache.CacheVariable('vendor', self.vendor)
196 AMBuild.cache.CacheVariable('targetMap', self.targetMap)
198 self.compiler.FromConfig(AMBuild, 'compiler')
199 self.targetMap = AMBuild.cache['targetMap']
201 if AMBuild.target['platform'] == 'windows':
202 self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
203 self.compiler.AddToListVar('RCINCLUDES',
204 os.path.join(AMBuild.outputFolder, 'includes'))
205 self.mmsPath = AMBuild.cache['MMSOURCE19']
207 def DefaultCompiler(self):
208 compiler = self.compiler.Clone()
209 compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, 'core', 'sourcehook'))
212 def JobMatters(self, jobname):
213 file = sys._getframe().f_code.co_filename
214 if AMBuild.mode == 'config':
215 self.targetMap[jobname] = file
217 if len(AMBuild.args) == 0:
219 if not jobname in AMBuild.args:
222 def AutoVersion(self, folder, binary):
223 if AMBuild.target['platform'] == 'windows':
224 env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'STRIPPER_GENERATED_BUILD']}
225 binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
226 elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
227 binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
228 binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
232 def PreSetupHL2Job(self, job, builder, sdk):
233 info = self.sdkInfo[sdk]
234 sdkPath = AMBuild.cache[info['sdk']]
235 if AMBuild.target['platform'] == 'linux':
237 staticLibs = os.path.join(sdkPath, 'linux_sdk')
239 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
240 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
241 if sdk in ['ep2v', 'l4d', 'l4d2', 'csgo', 'css']:
242 libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.so', 'libtier0.so']
244 libs.append('interfaces_i486.a')
246 link = os.path.join(workFolder, lib)
247 target = os.path.join(staticLibs, lib)
251 job.AddCommand(SymlinkCommand(link, target))
253 libs = ['tier1_i486.a', 'mathlib_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']
255 link = os.path.join(workFolder, lib)
256 target = os.path.join(staticLibs, lib)
260 job.AddCommand(SymlinkCommand(link, target))
261 elif AMBuild.target['platform'] == 'darwin':
262 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
263 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
264 libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']
266 libs.append('interfaces_i486.a')
268 link = os.path.join(workFolder, lib)
269 target = os.path.join(staticLibs, lib)
273 job.AddCommand(SymlinkCommand(link, target))
274 elif AMBuild.target['platform'] == 'windows':
275 libs = ['tier0', 'tier1', 'vstdlib', 'mathlib']
276 if sdk in ['swarm', 'csgo']:
277 libs.append('interfaces')
279 libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
280 builder.RebuildIfNewer(libPath)
281 builder['POSTLINKFLAGS'].append(libPath)
283 def PostSetupHL2Job(self, job, builder, sdk):
284 if AMBuild.target['platform'] in ['linux', 'darwin']:
285 builder.AddObjectFiles(['tier1_i486.a', 'mathlib_i486.a'])
287 builder.AddObjectFiles(['interfaces_i486.a'])
289 def DefaultHL2Compiler(self, path, sdk, noLink = False, oldMms = '-legacy'):
290 compiler = self.DefaultCompiler()
296 compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms))
297 compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms, 'sourcehook'))
300 compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
302 paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
303 ['public', 'tier0'], ['public', 'tier1']]
304 if sdk == 'ep1' or sdk == 'darkm':
305 paths.append(['public', 'dlls'])
306 paths.append(['game_shared'])
308 paths.append(['public', 'game', 'server'])
309 paths.append(['game', 'shared'])
310 paths.append(['common'])
312 info = self.sdkInfo[sdk]
313 sdkPath = AMBuild.cache[info['sdk']]
315 compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
317 if sdk in ['swarm','csgo']:
318 if AMBuild.target['platform'] == 'windows':
319 compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
321 compiler['CDEFINES'].extend(['COMPILER_GCC', 'POSIX'])
324 if AMBuild.target['platform'] == 'linux':
325 staticLibs = os.path.join(sdkPath, 'linux_sdk')
327 if AMBuild.target['platform'] == 'linux':
328 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
329 elif AMBuild.target['platform'] == 'darwin':
330 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
333 compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
336 if AMBuild.target['platform'] == 'linux':
337 compiler['POSTLINKFLAGS'][0:0] = ['-lm']
338 if sdk in ['ep2v', 'l4d', 'l4d2', 'csgo']:
339 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
340 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
342 compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
343 compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
344 elif AMBuild.target['platform'] == 'darwin':
345 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
346 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
350 stripper = Stripper()
355 AMBuild.Include(os.path.join('buildbot', 'Versioning'), globals)
359 ['gameshim', 'AMBuilder'],
360 ['loader', 'AMBuilder'],
364 for parts in FileList:
365 AMBuild.Include(os.path.join(*parts), globals)