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', 'darwin']}
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'
37 envvars['HL2SDKOBVALVE'] = 'hl2sdk-ob-valve'
38 envvars['HL2SDKL4D'] = 'hl2sdk-l4d'
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('POSTLINKFLAGS', '-m32')
87 self.compiler.AddToListVar('CFLAGS', '-static-libgcc')
88 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
89 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
90 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
91 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
92 self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
93 elif isinstance(cxx, Cpp.MSVC):
95 if AMBuild.options.debug == '1':
96 self.compiler.AddToListVar('CFLAGS', '/MTd')
97 self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
99 self.compiler.AddToListVar('CFLAGS', '/MT')
100 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
101 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
102 self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
103 self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
104 self.compiler.AddToListVar('CXXFLAGS', '/GR-')
105 self.compiler.AddToListVar('CFLAGS', '/W3')
106 self.compiler.AddToListVar('CFLAGS', '/nologo')
107 self.compiler.AddToListVar('CFLAGS', '/Zi')
108 self.compiler.AddToListVar('CXXFLAGS', '/TP')
109 self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
110 self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
111 self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
112 self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
113 self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
114 self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
115 self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
116 self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
117 self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
118 self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
119 self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
120 self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
121 self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
122 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
123 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
126 if AMBuild.options.opt == '1':
127 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
128 if self.vendor == 'gcc':
129 self.compiler.AddToListVar('CFLAGS', '-O3')
130 elif self.vendor == 'msvc':
131 self.compiler.AddToListVar('CFLAGS', '/Ox')
132 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
133 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
136 if AMBuild.options.debug == '1':
137 self.compiler.AddToListVar('CDEFINES', 'DEBUG')
138 self.compiler.AddToListVar('CDEFINES', '_DEBUG')
139 if self.vendor == 'gcc':
140 self.compiler.AddToListVar('CFLAGS', '-g3')
141 elif self.vendor == 'msvc':
142 self.compiler.AddToListVar('CFLAGS', '/Od')
143 self.compiler.AddToListVar('CFLAGS', '/RTC1')
146 if AMBuild.target['platform'] == 'linux':
147 self.compiler.AddToListVar('CDEFINES', '_LINUX')
148 elif AMBuild.target['platform'] == 'darwin':
149 self.compiler.AddToListVar('CFLAGS', ['-isysroot',
150 '/Developer/SDKs/MacOSX10.5.sdk'])
151 self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
152 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
153 self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
155 # For OS X dylib versioning
157 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
158 productContents = productFile.read()
160 m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
162 self.version = '1.0.0'
164 major, minor, release = m.groups()
165 self.version = '{0}.{1}.{2}'.format(major, minor, release)
166 AMBuild.cache.CacheVariable('version', self.version)
167 elif AMBuild.target['platform'] == 'windows':
168 self.compiler.AddToListVar('CDEFINES', 'WIN32')
169 self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
172 self.compiler.AddToListVar('CDEFINES', 'MMS_GENERATED_BUILD')
173 self.compiler.AddToListVar('CINCLUDES',
174 os.path.join(AMBuild.outputFolder, 'includes'))
175 self.compiler.ToConfig(AMBuild, 'compiler')
176 AMBuild.cache.CacheVariable('vendor', self.vendor)
178 AMBuild.cache.CacheVariable('targetMap', self.targetMap)
180 self.compiler.FromConfig(AMBuild, 'compiler')
181 self.targetMap = AMBuild.cache['targetMap']
183 if AMBuild.target['platform'] == 'windows':
184 self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
185 self.compiler.AddToListVar('RCINCLUDES',
186 os.path.join(AMBuild.outputFolder, 'includes'))
188 def DefaultCompiler(self):
189 compiler = self.compiler.Clone()
190 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public'))
193 def JobMatters(self, jobname):
194 file = sys._getframe().f_code.co_filename
195 if AMBuild.mode == 'config':
196 self.targetMap[jobname] = file
198 if len(AMBuild.args) == 0:
200 if not jobname in AMBuild.args:
203 def AutoVersion(self, folder, binary):
204 if AMBuild.target['platform'] == 'windows':
205 env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'MMS_GENERATED_BUILD']}
206 binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
207 elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
208 binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
209 binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
213 def PreSetupHL2Job(self, job, builder, sdk):
214 info = self.sdkInfo[sdk]
215 sdkPath = AMBuild.cache[info['sdk']]
216 if AMBuild.target['platform'] == 'linux':
218 staticLibs = os.path.join(sdkPath, 'linux_sdk')
220 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
221 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
222 if sdk in ['ep2v', 'l4d', 'l4d2']:
223 for i in ['tier1_i486.a', 'libvstdlib.so', 'libtier0.so']:
224 link = os.path.join(workFolder, i)
225 target = os.path.join(staticLibs, i)
229 job.AddCommand(SymlinkCommand(link, target))
231 for i in ['tier1_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
232 link = os.path.join(workFolder, i)
233 target = os.path.join(staticLibs, i)
237 job.AddCommand(SymlinkCommand(link, target))
238 elif AMBuild.target['platform'] == 'darwin':
239 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
240 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
241 for i in ['tier1_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']:
242 link = os.path.join(workFolder, i)
243 target = os.path.join(staticLibs, i)
247 job.AddCommand(SymlinkCommand(link, target))
248 elif AMBuild.target['platform'] == 'windows':
249 libs = ['tier0', 'tier1', 'vstdlib']
251 libs.append('interfaces')
253 libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
254 builder.RebuildIfNewer(libPath)
255 builder['POSTLINKFLAGS'].append(libPath)
257 def PostSetupHL2Job(self, job, builder, sdk):
258 if AMBuild.target['platform'] in ['linux', 'darwin']:
259 builder.AddObjectFiles(['tier1_i486.a'])
261 def DefaultHL2Compiler(self, path, sdk, noLink = False):
262 compiler = self.DefaultCompiler()
264 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path))
265 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sourcehook'))
266 compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'loader'))
269 compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
271 paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
272 ['public', 'tier0'], ['public', 'tier1']]
273 if sdk == 'ep1' or sdk == 'darkm':
274 paths.append(['public', 'dlls'])
275 paths.append(['game_shared'])
277 paths.append(['public', 'game', 'server'])
278 paths.append(['game', 'shared'])
279 paths.append(['common'])
281 info = self.sdkInfo[sdk]
282 sdkPath = AMBuild.cache[info['sdk']]
284 compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
286 if sdk == 'swarm' and AMBuild.target['platform'] == 'windows':
287 compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
290 if AMBuild.target['platform'] == 'linux':
291 staticLibs = os.path.join(sdkPath, 'linux_sdk')
293 if AMBuild.target['platform'] == 'linux':
294 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
295 elif AMBuild.target['platform'] == 'darwin':
296 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
299 compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
302 if AMBuild.target['platform'] == 'linux':
303 compiler['POSTLINKFLAGS'][0:0] = ['-lm']
304 if sdk in ['ep2v', 'l4d', 'l4d2']:
305 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
306 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
308 compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
309 compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
310 elif AMBuild.target['platform'] == 'darwin':
311 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
312 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
321 AMBuild.Include(os.path.join('support', 'buildbot', 'Versioning'), globals)
324 ['loader', 'AMBuilder'],
325 ['core', 'AMBuilder'],
326 ['core-legacy', 'AMBuilder'],
327 ['support', 'buildbot', 'PackageScript']
330 for parts in FileList:
331 AMBuild.Include(os.path.join(*parts), globals)