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': '4',
17 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin']}
18 self.sdkInfo['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '5',
19 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux']}
20 self.sdkInfo['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '6',
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': '7',
25 'name': 'ALIENSWARM', 'platform': ['windows']}
27 if AMBuild.mode == 'config':
29 self.compiler.DetectAll(AMBuild)
33 if AMBuild.target['platform'] != 'darwin':
34 envvars['HL2SDK'] = 'hl2sdk'
35 envvars['HL2SDKOB'] = 'hl2sdk-ob'
36 envvars['HL2SDKL4D'] = 'hl2sdk-l4d'
38 envvars['HL2SDKOBVALVE'] = 'hl2sdk-ob-valve'
39 envvars['HL2SDKL4D2'] = 'hl2sdk-l4d2'
41 #Dark Messiah is Windows-only
42 if AMBuild.target['platform'] == 'windows':
43 envvars['HL2SDK-DARKM'] = 'hl2sdk-darkm'
44 envvars['HL2SDK-SWARM'] = 'hl2sdk-swarm'
46 #Must have a path for each envvar (file a bug if you don't like this)
50 if not os.path.isdir(path):
51 raise Exception('Path for {0} was not found: {1}'.format(i, path))
55 while head != None and head != oldhead:
56 path = os.path.join(head, envvars[i])
57 if os.path.isdir(path):
60 head, tail = os.path.split(head)
61 if head == None or head == oldhead:
62 raise Exception('Could not find a valid path for {0}'.format(i))
63 AMBuild.cache.CacheVariable(i, path)
66 cxx = self.compiler.cxx
67 if isinstance(cxx, Cpp.GCC):
69 self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
70 self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
71 self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
72 self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
73 self.compiler.AddToListVar('CFLAGS', '-pipe')
74 self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
75 if cxx.majorVersion >= 4:
76 self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
77 self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
78 self.compiler.AddToListVar('CFLAGS', '-Wall')
79 self.compiler.AddToListVar('CFLAGS', '-Werror')
80 self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
81 self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
82 self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
83 self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
84 self.compiler.AddToListVar('CFLAGS', '-msse')
85 self.compiler.AddToListVar('CFLAGS', '-m32')
86 self.compiler.AddToListVar('CFLAGS', '-static-libgcc')
87 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
88 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
89 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
90 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
91 self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
92 elif isinstance(cxx, Cpp.MSVC):
94 if AMBuild.options.debug == '1':
95 self.compiler.AddToListVar('CFLAGS', '/MTd')
96 self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
98 self.compiler.AddToListVar('CFLAGS', '/MT')
99 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
100 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
101 self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
102 self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
103 self.compiler.AddToListVar('CXXFLAGS', '/GR-')
104 self.compiler.AddToListVar('CFLAGS', '/W3')
105 self.compiler.AddToListVar('CFLAGS', '/nologo')
106 self.compiler.AddToListVar('CFLAGS', '/Zi')
107 self.compiler.AddToListVar('CXXFLAGS', '/TP')
108 self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
109 self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
110 self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
111 self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
112 self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
113 self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
114 self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
115 self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
116 self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
117 self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
118 self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
119 self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
120 self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
121 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
122 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
125 if AMBuild.options.opt == '1':
126 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
127 if self.vendor == 'gcc':
128 self.compiler.AddToListVar('CFLAGS', '-O3')
129 elif self.vendor == 'msvc':
130 self.compiler.AddToListVar('CFLAGS', '/Ox')
131 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
132 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
135 if AMBuild.options.debug == '1':
136 self.compiler.AddToListVar('CDEFINES', 'DEBUG')
137 self.compiler.AddToListVar('CDEFINES', '_DEBUG')
138 if self.vendor == 'gcc':
139 self.compiler.AddToListVar('CFLAGS', '-g3')
140 elif self.vendor == 'msvc':
141 self.compiler.AddToListVar('CFLAGS', '/Od')
142 self.compiler.AddToListVar('CFLAGS', '/RTC1')
145 if AMBuild.target['platform'] == 'linux':
146 self.compiler.AddToListVar('CDEFINES', '_LINUX')
147 elif AMBuild.target['platform'] == 'darwin':
148 self.compiler.AddToListVar('CFLAGS', ['-isysroot',
149 '/Developer/SDKs/MacOSX10.5.sdk'])
150 self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
151 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
152 self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
154 # For OS X dylib versioning
156 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
157 productContents = productFile.read()
159 m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
161 self.version = '1.0.0'
163 major, minor, release = m.groups()
164 self.version = '{0}.{1}.{2}'.format(major, minor, release)
165 AMBuild.cache.CacheVariable('version', self.version)
166 elif AMBuild.target['platform'] == 'windows':
167 self.compiler.AddToListVar('CDEFINES', 'WIN32')
168 self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
171 self.compiler.AddToListVar('CDEFINES', 'MMS_GENERATED_BUILD')
172 self.compiler.AddToListVar('CINCLUDES',
173 os.path.join(AMBuild.outputFolder, 'includes'))
174 self.compiler.ToConfig(AMBuild, 'compiler')
175 AMBuild.cache.CacheVariable('vendor', self.vendor)
177 AMBuild.cache.CacheVariable('targetMap', self.targetMap)
179 self.compiler.FromConfig(AMBuild, 'compiler')
180 self.targetMap = AMBuild.cache['targetMap']
182 if AMBuild.target['platform'] == 'windows':
183 self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
184 self.compiler.AddToListVar('RCINCLUDES',
185 os.path.join(AMBuild.outputFolder, 'includes'))
187 def DefaultCompiler(self):
188 compiler = self.compiler.Clone()
189 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public'))
192 def JobMatters(self, jobname):
193 file = sys._getframe().f_code.co_filename
194 if AMBuild.mode == 'config':
195 self.targetMap[jobname] = file
197 if len(AMBuild.args) == 0:
199 if not jobname in AMBuild.args:
202 def AutoVersion(self, folder, binary):
203 if AMBuild.target['platform'] == 'windows':
204 env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'MMS_GENERATED_BUILD']}
205 binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
206 elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
207 binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
208 binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
212 def PreSetupHL2Job(self, job, builder, sdk):
213 info = self.sdkInfo[sdk]
214 sdkPath = AMBuild.cache[info['sdk']]
215 if AMBuild.target['platform'] == 'linux':
217 staticLibs = os.path.join(sdkPath, 'linux_sdk')
219 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
220 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
221 if sdk == 'ep2v' or sdk == 'l4d2':
222 for i in ['tier1_i486.a', 'libvstdlib.so', 'libtier0.so']:
223 link = os.path.join(workFolder, i)
224 target = os.path.join(staticLibs, i)
228 job.AddCommand(SymlinkCommand(link, target))
230 for i in ['tier1_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
231 link = os.path.join(workFolder, i)
232 target = os.path.join(staticLibs, i)
236 job.AddCommand(SymlinkCommand(link, target))
237 elif AMBuild.target['platform'] == 'darwin':
238 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
239 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
240 for i in ['tier1_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']:
241 link = os.path.join(workFolder, i)
242 target = os.path.join(staticLibs, i)
246 job.AddCommand(SymlinkCommand(link, target))
247 elif AMBuild.target['platform'] == 'windows':
248 libs = ['tier0', 'tier1', 'vstdlib']
250 libs.append('interfaces')
252 libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
253 builder.RebuildIfNewer(libPath)
254 builder['POSTLINKFLAGS'].append(libPath)
256 def PostSetupHL2Job(self, job, builder, sdk):
257 if AMBuild.target['platform'] in ['linux', 'darwin']:
258 builder.AddObjectFiles(['tier1_i486.a'])
260 def DefaultHL2Compiler(self, path, sdk, noLink = False):
261 compiler = self.DefaultCompiler()
263 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path))
264 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sourcehook'))
265 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'loader'))
268 compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
270 paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
271 ['public', 'tier0'], ['public', 'tier1']]
272 if sdk == 'ep1' or sdk == 'darkm':
273 paths.append(['public', 'dlls'])
274 paths.append(['game_shared'])
276 paths.append(['public', 'game', 'server'])
277 paths.append(['game', 'shared'])
278 paths.append(['common'])
280 info = self.sdkInfo[sdk]
281 sdkPath = AMBuild.cache[info['sdk']]
283 compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
285 if sdk == 'swarm' and AMBuild.target['platform'] == 'windows':
286 compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
289 if AMBuild.target['platform'] == 'linux':
290 staticLibs = os.path.join(sdkPath, 'linux_sdk')
292 if AMBuild.target['platform'] == 'linux':
293 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
294 elif AMBuild.target['platform'] == 'darwin':
295 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
298 compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
301 if AMBuild.target['platform'] == 'linux':
302 compiler['POSTLINKFLAGS'][0:0] = ['-lm']
303 if sdk == 'ep2v' or sdk == 'l4d2':
304 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
305 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
307 compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
308 compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
309 elif AMBuild.target['platform'] == 'darwin':
310 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
311 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
320 AMBuild.Include(os.path.join('support', 'buildbot', 'Versioning'), globals)
323 ['loader', 'AMBuilder'],
324 ['core', 'AMBuilder'],
325 ['core-legacy', 'AMBuilder'],
326 ['support', 'buildbot', 'PackageScript']
329 for parts in FileList:
330 AMBuild.Include(os.path.join(*parts), globals)