Don't omit frame pointer on msvc builds.
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['ep2v'] = {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v', 'def': '7',
22 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin'],
23 'dir': 'hl2sdk-ob-valve'}
24 self.possibleSdks['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '8',
25 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux', 'darwin'],
27 self.possibleSdks['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '9',
28 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux', 'darwin'],
30 self.possibleSdks['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '2.darkm', 'def': '2',
31 'name': 'DARKMESSIAH', 'platform': ['windows'],
32 'dir': 'hl2sdk-darkm'}
33 self.possibleSdks['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '2.swarm', 'def': '10',
34 'name': 'ALIENSWARM', 'platform': ['windows'],
35 'dir': 'hl2sdk-swarm'}
36 self.possibleSdks['bgt'] = {'sdk': 'HL2SDK-BGT', 'ext': '2.bgt', 'def': '4',
37 'name': 'BLOODYGOODTIME', 'platform': ['windows'],
39 self.possibleSdks['eye'] = {'sdk': 'HL2SDK-EYE', 'ext': '2.eye', 'def': '5',
40 'name': 'EYE', 'platform': ['windows'],
42 self.possibleSdks['csgo'] = {'sdk': 'HL2SDKCSGO', 'ext': '2.csgo', 'def': '12',
43 'name': 'CSGO', 'platform': ['windows', 'linux', 'darwin'],
45 self.possibleSdks['dota'] = {'sdk': 'HL2SDKDOTA', 'ext': '2.dota', 'def': '13',
46 'name': 'DOTA', 'platform': ['windows'],
48 # self.possibleSdks['portal2'] = {'sdk': 'HL2SDK-PORTAL2', 'ext': '2.portal2', 'def': '11',
49 # 'name': 'PORTAL2', 'platform': ['windows'],
50 # 'dir': 'hl2sdk-portal2'}
54 if AMBuild.mode == 'config':
56 self.compiler.DetectAll(AMBuild)
58 #Look for SDK directories
59 for sdk in self.possibleSdks:
60 #Get list of SDKs to build against or 'all' or 'present'
61 sdkList = AMBuild.options.sdks.split(',')
62 #Build against all supported SDKs?
63 useAll = sdkList[0] == 'all'
64 #Build against supported SDKs that exist?
65 usePresent = sdkList[0] == 'present'
67 info = self.possibleSdks[sdk]
68 if AMBuild.target['platform'] in info['platform']:
71 sdkPath = self.ResolveEnvPath(env, dir)
73 if useAll or sdk in sdkList:
74 raise Exception('Could not find a valid path for {0}'.format(env))
77 if useAll or usePresent or sdk in sdkList:
78 self.sdkInfo[sdk] = info
79 AMBuild.cache.CacheVariable(env, sdkPath)
81 if len(self.sdkInfo) < 1:
82 raise Exception('At least one SDK must be available.')
84 AMBuild.cache.CacheVariable('sdkInfo', self.sdkInfo)
87 cxx = self.compiler.cxx
88 if isinstance(cxx, Cpp.CompatGCC):
89 if isinstance(cxx, Cpp.GCC):
91 elif isinstance(cxx, Cpp.Clang):
93 self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
94 self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
95 self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
96 self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
97 self.compiler.AddToListVar('CFLAGS', '-pipe')
98 self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
99 if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
100 self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
101 self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
102 self.compiler.AddToListVar('CFLAGS', '-Wall')
103 self.compiler.AddToListVar('CFLAGS', '-Werror')
104 self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
105 self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
106 self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
107 self.compiler.AddToListVar('CFLAGS', '-msse')
108 self.compiler.AddToListVar('CFLAGS', '-m32')
109 self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
110 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
111 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
112 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
113 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
114 self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
115 if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
116 (self.vendor == 'clang' and cxx.majorVersion >= 3):
117 self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
118 self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
119 if self.vendor == 'gcc':
120 self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
121 elif isinstance(cxx, Cpp.MSVC):
123 if AMBuild.options.debug == '1':
124 self.compiler.AddToListVar('CFLAGS', '/MTd')
125 self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
127 self.compiler.AddToListVar('CFLAGS', '/MT')
128 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
129 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
130 self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
131 self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
132 self.compiler.AddToListVar('CXXFLAGS', '/GR-')
133 self.compiler.AddToListVar('CFLAGS', '/W3')
134 self.compiler.AddToListVar('CFLAGS', '/nologo')
135 self.compiler.AddToListVar('CFLAGS', '/Zi')
136 self.compiler.AddToListVar('CXXFLAGS', '/TP')
137 self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
138 self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
139 self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
140 self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
141 self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
142 self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
143 self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
144 self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
145 self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
146 self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
147 self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
148 self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
149 self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
150 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
151 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
154 if AMBuild.options.opt == '1':
155 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
156 if self.vendor == 'gcc' or self.vendor == 'clang':
157 self.compiler.AddToListVar('CFLAGS', '-O3')
158 elif self.vendor == 'msvc':
159 self.compiler.AddToListVar('CFLAGS', '/Ox')
160 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
161 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
164 if AMBuild.options.debug == '1':
165 self.compiler.AddToListVar('CDEFINES', 'DEBUG')
166 self.compiler.AddToListVar('CDEFINES', '_DEBUG')
167 if self.vendor == 'gcc' or self.vendor == 'clang':
168 self.compiler.AddToListVar('CFLAGS', '-g3')
169 elif self.vendor == 'msvc':
170 self.compiler.AddToListVar('CFLAGS', '/Od')
171 self.compiler.AddToListVar('CFLAGS', '/RTC1')
173 #This needs to be after our optimization flags which could otherwise disable it.
174 if self.vendor == 'msvc':
175 # Don't omit frame pointer
176 self.compiler.AddToListVar('CFLAGS', '/Oy-')
179 if AMBuild.target['platform'] == 'linux':
180 self.compiler.AddToListVar('CDEFINES', '_LINUX')
181 if self.vendor == 'gcc':
182 self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
183 if self.vendor == 'clang':
184 self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
185 elif AMBuild.target['platform'] == 'darwin':
186 self.compiler.AddToListVar('CDEFINES', 'OSX')
187 self.compiler.AddToListVar('CDEFINES', '_OSX')
188 self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
189 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
190 self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
192 # For OS X dylib versioning
194 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
195 productContents = productFile.read()
197 m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
199 self.version = '1.0.0'
201 major, minor, release = m.groups()
202 self.version = '{0}.{1}.{2}'.format(major, minor, release)
203 AMBuild.cache.CacheVariable('version', self.version)
204 elif AMBuild.target['platform'] == 'windows':
205 self.compiler.AddToListVar('CDEFINES', 'WIN32')
206 self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
209 self.compiler.AddToListVar('CDEFINES', 'MMS_GENERATED_BUILD')
210 self.compiler.AddToListVar('CINCLUDES',
211 os.path.join(AMBuild.outputFolder, 'includes'))
212 self.compiler.ToConfig(AMBuild, 'compiler')
213 AMBuild.cache.CacheVariable('vendor', self.vendor)
215 AMBuild.cache.CacheVariable('targetMap', self.targetMap)
217 self.sdkInfo = AMBuild.cache['sdkInfo']
218 self.compiler.FromConfig(AMBuild, 'compiler')
219 self.targetMap = AMBuild.cache['targetMap']
221 if AMBuild.target['platform'] == 'windows':
222 self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
223 self.compiler.AddToListVar('RCINCLUDES',
224 os.path.join(AMBuild.outputFolder, 'includes'))
226 def DefaultCompiler(self):
227 compiler = self.compiler.Clone()
228 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public'))
231 def JobMatters(self, jobname):
232 file = sys._getframe().f_code.co_filename
233 if AMBuild.mode == 'config':
234 self.targetMap[jobname] = file
236 if len(AMBuild.args) == 0:
238 if not jobname in AMBuild.args:
241 def AutoVersion(self, folder, binary):
242 if AMBuild.target['platform'] == 'windows':
243 env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'MMS_GENERATED_BUILD']}
244 binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
245 elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
246 binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
247 binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
251 def PreSetupHL2Job(self, job, builder, sdk):
252 info = self.sdkInfo[sdk]
253 sdkPath = AMBuild.cache[info['sdk']]
254 if AMBuild.target['platform'] == 'linux':
256 staticLibs = os.path.join(sdkPath, 'linux_sdk')
258 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
259 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
260 if sdk in ['ep2v', 'css']:
261 libs = ['tier1_i486.a', 'libvstdlib_srv.so', 'libtier0_srv.so']
263 link = os.path.join(workFolder, lib)
264 target = os.path.join(staticLibs, lib)
268 job.AddCommand(SymlinkCommand(link, target))
269 elif sdk in ['l4d', 'l4d2', 'csgo']:
270 libs = ['tier1_i486.a', 'libvstdlib.so', 'libtier0.so']
272 libs.insert(0, 'interfaces_i486.a')
274 link = os.path.join(workFolder, lib)
275 target = os.path.join(staticLibs, lib)
279 job.AddCommand(SymlinkCommand(link, target))
281 for i in ['tier1_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
282 link = os.path.join(workFolder, i)
283 target = os.path.join(staticLibs, i)
287 job.AddCommand(SymlinkCommand(link, target))
288 elif AMBuild.target['platform'] == 'darwin':
289 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
290 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
291 libs = ['tier1_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']
293 libs.append('interfaces_i486.a')
295 link = os.path.join(workFolder, lib)
296 target = os.path.join(staticLibs, lib)
300 job.AddCommand(SymlinkCommand(link, target))
301 elif AMBuild.target['platform'] == 'windows':
302 libs = ['tier0', 'tier1', 'vstdlib']
303 if sdk in ['swarm', 'csgo', 'dota']:
304 libs.append('interfaces')
306 libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
307 builder.RebuildIfNewer(libPath)
308 builder['POSTLINKFLAGS'].append(libPath)
310 def PostSetupHL2Job(self, job, builder, sdk):
311 if AMBuild.target['platform'] in ['linux', 'darwin']:
312 builder.AddObjectFiles(['tier1_i486.a'])
313 if( sdk in ['csgo', 'dota'] ):
314 builder.AddObjectFiles(['interfaces_i486.a'])
316 def DefaultHL2Compiler(self, path, sdk, noLink = False):
317 compiler = self.DefaultCompiler()
319 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path))
320 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sourcehook'))
321 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'loader'))
323 info = self.possibleSdks
324 compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
326 # We don't build for Portal 2 (yet?, ever?), but using this define in code as
327 # it saves trouble if we ever need to
328 compiler['CDEFINES'].append('SE_PORTAL2=11')
330 paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
331 ['public', 'tier0'], ['public', 'tier1']]
332 if sdk == 'ep1' or sdk == 'darkm':
333 paths.append(['public', 'dlls'])
334 paths.append(['game_shared'])
336 paths.append(['public', 'game', 'server'])
337 paths.append(['game', 'shared'])
338 paths.append(['common'])
340 info = self.sdkInfo[sdk]
341 sdkPath = AMBuild.cache[info['sdk']]
343 compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
345 if sdk in ['swarm', 'csgo', 'dota']:
346 if AMBuild.target['platform'] == 'windows':
347 compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
349 compiler['CDEFINES'].extend(['COMPILER_GCC', 'POSIX'])
352 if AMBuild.target['platform'] == 'linux':
353 staticLibs = os.path.join(sdkPath, 'linux_sdk')
355 if AMBuild.target['platform'] == 'linux':
356 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
357 elif AMBuild.target['platform'] == 'darwin':
358 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
361 compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
364 if AMBuild.target['platform'] == 'linux':
365 compiler['POSTLINKFLAGS'][0:0] = ['-lm']
366 if sdk in ['ep2v', 'css']:
367 compiler['POSTLINKFLAGS'][0:0] = ['libtier0_srv.so']
368 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib_srv.so']
369 elif sdk in ['l4d', 'l4d2', 'csgo']:
370 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
371 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
373 compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
374 compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
375 elif AMBuild.target['platform'] == 'darwin':
376 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
377 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
381 def ResolveEnvPath(self, env, defaultDir):
382 if env in os.environ:
383 path = os.environ[env]
384 if os.path.isdir(path):
389 while head != None and head != oldhead:
390 path = os.path.join(head, defaultDir)
391 if os.path.isdir(path):
394 head, tail = os.path.split(head)
402 AMBuild.Include(os.path.join('support', 'buildbot', 'Versioning'), globals)
405 ['loader', 'AMBuilder'],
406 ['core', 'AMBuilder'],
407 ['core-legacy', 'AMBuilder'],
408 ['support', 'buildbot', 'PackageScript']
411 for parts in FileList:
412 AMBuild.Include(os.path.join(*parts), globals)