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': '1.ep1', 'def': '1',
13 'name': 'EPISODEONE', 'platform': ['windows', 'linux']}
14 self.sdkInfo['ep2'] = {'sdk': 'HL2SDKOB', 'ext': '2.ep2', 'def': '3',
15 'name': 'ORANGEBOX', 'platform': ['windows', 'linux']}
16 self.sdkInfo['ep2v'] = {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v', 'def': '5',
17 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin']}
18 self.sdkInfo['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '6',
19 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux', 'darwin']}
20 self.sdkInfo['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '7',
21 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux', 'darwin']}
22 self.sdkInfo['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '2.darkm', 'def': '2',
23 'name': 'DARKMESSIAH', 'platform': ['windows']}
24 self.sdkInfo['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '2.swarm', 'def': '8',
25 'name': 'ALIENSWARM', 'platform': ['windows']}
26 self.sdkInfo['bgt'] = {'sdk': 'HL2SDK-BGT', 'ext': '2.bgt', 'def': '4',
27 'name': 'BLOODYGOODTIME', 'platform': ['windows']}
29 if AMBuild.mode == 'config':
31 self.compiler.DetectAll(AMBuild)
35 if AMBuild.target['platform'] != 'darwin':
36 envvars['HL2SDK'] = 'hl2sdk'
37 envvars['HL2SDKOB'] = 'hl2sdk-ob'
39 envvars['HL2SDKOBVALVE'] = 'hl2sdk-ob-valve'
40 envvars['HL2SDKL4D'] = 'hl2sdk-l4d'
41 envvars['HL2SDKL4D2'] = 'hl2sdk-l4d2'
43 #Dark Messiah is Windows-only
44 if AMBuild.target['platform'] == 'windows':
45 envvars['HL2SDK-DARKM'] = 'hl2sdk-darkm'
46 envvars['HL2SDK-SWARM'] = 'hl2sdk-swarm'
47 envvars['HL2SDK-BGT'] = 'hl2sdk-bgt'
49 #Must have a path for each envvar (file a bug if you don't like this)
53 if not os.path.isdir(path):
54 raise Exception('Path for {0} was not found: {1}'.format(i, path))
58 while head != None and head != oldhead:
59 path = os.path.join(head, envvars[i])
60 if os.path.isdir(path):
63 head, tail = os.path.split(head)
64 if head == None or head == oldhead:
65 raise Exception('Could not find a valid path for {0}'.format(i))
66 AMBuild.cache.CacheVariable(i, path)
69 cxx = self.compiler.cxx
70 if isinstance(cxx, Cpp.GCC):
72 self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
73 self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
74 self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
75 self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
76 self.compiler.AddToListVar('CFLAGS', '-pipe')
77 self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
78 if cxx.majorVersion >= 4:
79 self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
80 self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
81 self.compiler.AddToListVar('CFLAGS', '-Wall')
82 self.compiler.AddToListVar('CFLAGS', '-Werror')
83 self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
84 self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
85 self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
86 self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
87 self.compiler.AddToListVar('CFLAGS', '-msse')
88 self.compiler.AddToListVar('CFLAGS', '-m32')
89 self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
90 self.compiler.AddToListVar('CFLAGS', '-static-libgcc')
91 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
92 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
93 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
94 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
95 self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
96 elif isinstance(cxx, Cpp.MSVC):
98 if AMBuild.options.debug == '1':
99 self.compiler.AddToListVar('CFLAGS', '/MTd')
100 self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
102 self.compiler.AddToListVar('CFLAGS', '/MT')
103 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
104 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
105 self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
106 self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
107 self.compiler.AddToListVar('CXXFLAGS', '/GR-')
108 self.compiler.AddToListVar('CFLAGS', '/W3')
109 self.compiler.AddToListVar('CFLAGS', '/nologo')
110 self.compiler.AddToListVar('CFLAGS', '/Zi')
111 self.compiler.AddToListVar('CXXFLAGS', '/TP')
112 self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
113 self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
114 self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
115 self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
116 self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
117 self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
118 self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
119 self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
120 self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
121 self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
122 self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
123 self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
124 self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
125 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
126 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
129 if AMBuild.options.opt == '1':
130 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
131 if self.vendor == 'gcc':
132 self.compiler.AddToListVar('CFLAGS', '-O3')
133 elif self.vendor == 'msvc':
134 self.compiler.AddToListVar('CFLAGS', '/Ox')
135 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
136 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
139 if AMBuild.options.debug == '1':
140 self.compiler.AddToListVar('CDEFINES', 'DEBUG')
141 self.compiler.AddToListVar('CDEFINES', '_DEBUG')
142 if self.vendor == 'gcc':
143 self.compiler.AddToListVar('CFLAGS', '-g3')
144 elif self.vendor == 'msvc':
145 self.compiler.AddToListVar('CFLAGS', '/Od')
146 self.compiler.AddToListVar('CFLAGS', '/RTC1')
149 if AMBuild.target['platform'] == 'linux':
150 self.compiler.AddToListVar('CDEFINES', '_LINUX')
151 elif AMBuild.target['platform'] == 'darwin':
152 self.compiler.AddToListVar('CFLAGS', ['-isysroot',
153 '/Developer/SDKs/MacOSX10.5.sdk'])
154 self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
155 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
156 self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
158 # For OS X dylib versioning
160 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
161 productContents = productFile.read()
163 m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
165 self.version = '1.0.0'
167 major, minor, release = m.groups()
168 self.version = '{0}.{1}.{2}'.format(major, minor, release)
169 AMBuild.cache.CacheVariable('version', self.version)
170 elif AMBuild.target['platform'] == 'windows':
171 self.compiler.AddToListVar('CDEFINES', 'WIN32')
172 self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
175 self.compiler.AddToListVar('CDEFINES', 'MMS_GENERATED_BUILD')
176 self.compiler.AddToListVar('CINCLUDES',
177 os.path.join(AMBuild.outputFolder, 'includes'))
178 self.compiler.ToConfig(AMBuild, 'compiler')
179 AMBuild.cache.CacheVariable('vendor', self.vendor)
181 AMBuild.cache.CacheVariable('targetMap', self.targetMap)
183 self.compiler.FromConfig(AMBuild, 'compiler')
184 self.targetMap = AMBuild.cache['targetMap']
186 if AMBuild.target['platform'] == 'windows':
187 self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
188 self.compiler.AddToListVar('RCINCLUDES',
189 os.path.join(AMBuild.outputFolder, 'includes'))
191 def DefaultCompiler(self):
192 compiler = self.compiler.Clone()
193 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public'))
196 def JobMatters(self, jobname):
197 file = sys._getframe().f_code.co_filename
198 if AMBuild.mode == 'config':
199 self.targetMap[jobname] = file
201 if len(AMBuild.args) == 0:
203 if not jobname in AMBuild.args:
206 def AutoVersion(self, folder, binary):
207 if AMBuild.target['platform'] == 'windows':
208 env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'MMS_GENERATED_BUILD']}
209 binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
210 elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
211 binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
212 binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
216 def PreSetupHL2Job(self, job, builder, sdk):
217 info = self.sdkInfo[sdk]
218 sdkPath = AMBuild.cache[info['sdk']]
219 if AMBuild.target['platform'] == 'linux':
221 staticLibs = os.path.join(sdkPath, 'linux_sdk')
223 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
224 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
225 if sdk in ['ep2v', 'l4d', 'l4d2']:
226 for i in ['tier1_i486.a', 'libvstdlib.so', 'libtier0.so']:
227 link = os.path.join(workFolder, i)
228 target = os.path.join(staticLibs, i)
232 job.AddCommand(SymlinkCommand(link, target))
234 for i in ['tier1_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
235 link = os.path.join(workFolder, i)
236 target = os.path.join(staticLibs, i)
240 job.AddCommand(SymlinkCommand(link, target))
241 elif AMBuild.target['platform'] == 'darwin':
242 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
243 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
244 for i in ['tier1_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']:
245 link = os.path.join(workFolder, i)
246 target = os.path.join(staticLibs, i)
250 job.AddCommand(SymlinkCommand(link, target))
251 elif AMBuild.target['platform'] == 'windows':
252 libs = ['tier0', 'tier1', 'vstdlib']
254 libs.append('interfaces')
256 libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
257 builder.RebuildIfNewer(libPath)
258 builder['POSTLINKFLAGS'].append(libPath)
260 def PostSetupHL2Job(self, job, builder, sdk):
261 if AMBuild.target['platform'] in ['linux', 'darwin']:
262 builder.AddObjectFiles(['tier1_i486.a'])
264 def DefaultHL2Compiler(self, path, sdk, noLink = False):
265 compiler = self.DefaultCompiler()
267 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path))
268 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sourcehook'))
269 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'loader'))
272 compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
274 paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
275 ['public', 'tier0'], ['public', 'tier1']]
276 if sdk == 'ep1' or sdk == 'darkm':
277 paths.append(['public', 'dlls'])
278 paths.append(['game_shared'])
280 paths.append(['public', 'game', 'server'])
281 paths.append(['game', 'shared'])
282 paths.append(['common'])
284 info = self.sdkInfo[sdk]
285 sdkPath = AMBuild.cache[info['sdk']]
287 compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
289 if sdk == 'swarm' and AMBuild.target['platform'] == 'windows':
290 compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
293 if AMBuild.target['platform'] == 'linux':
294 staticLibs = os.path.join(sdkPath, 'linux_sdk')
296 if AMBuild.target['platform'] == 'linux':
297 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
298 elif AMBuild.target['platform'] == 'darwin':
299 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
302 compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
305 if AMBuild.target['platform'] == 'linux':
306 compiler['POSTLINKFLAGS'][0:0] = ['-lm']
307 if sdk in ['ep2v', 'l4d', 'l4d2']:
308 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
309 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
311 compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
312 compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
313 elif AMBuild.target['platform'] == 'darwin':
314 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
315 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
324 AMBuild.Include(os.path.join('support', 'buildbot', 'Versioning'), globals)
327 ['loader', 'AMBuilder'],
328 ['core', 'AMBuilder'],
329 ['core-legacy', 'AMBuilder'],
330 ['support', 'buildbot', 'PackageScript']
333 for parts in FileList:
334 AMBuild.Include(os.path.join(*parts), globals)