Remove ep2v engine and add css engine to fix linux builds.
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['css'] = {'sdk': 'HL2SDKCSS', 'ext': '2.css', 'def': '6',
13 'name': 'CSS', 'platform': ['windows', 'linux', 'darwin']}
15 self.sdkInfo['csgo'] = {'sdk': 'HL2SDKCSGO', 'ext': '2.csgo', 'def': '11',
16 'name': 'CSGO', 'platform': ['windows', 'linux']}
18 if AMBuild.mode == 'config':
20 self.compiler.DetectAll(AMBuild)
23 envvars = { 'MMSOURCE19': 'mmsource-1.9' }
24 envvars['SOURCEMOD14'] = 'sourcemod-1.4'
25 envvars['SOURCEMOD-BIN'] = 'sourcemod-bin'
26 #envvars['HL2SDKOBVALVE'] = 'hl2sdk-ob-valve'
27 envvars['HL2SDKCSS'] = 'hl2sdk-css'
28 if AMBuild.target['platform'] != 'darwin':
29 envvars['HL2SDKCSGO'] = 'hl2sdk-csgo'
31 #Must have a path for each envvar (file a bug if you don't like this)
35 if not os.path.isdir(path):
36 raise Exception('Path for {0} was not found: {1}'.format(i, path))
40 while head != None and head != oldhead:
41 path = os.path.join(head, envvars[i])
42 if os.path.isdir(path):
45 head, tail = os.path.split(head)
46 if head == None or head == oldhead:
47 raise Exception('Could not find a valid path for {0}'.format(i))
48 AMBuild.cache.CacheVariable(i, path)
51 cxx = self.compiler.cxx
52 if isinstance(cxx, Cpp.CompatGCC):
53 if isinstance(cxx, Cpp.GCC):
55 elif isinstance(cxx, Cpp.Clang):
57 self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp')
58 self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp')
59 self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf')
60 self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf')
61 self.compiler.AddToListVar('CFLAGS', '-pipe')
62 self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
63 if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
64 self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
65 self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
66 self.compiler.AddToListVar('CFLAGS', '-Wall')
67 self.compiler.AddToListVar('CFLAGS', '-Werror')
68 self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized')
69 self.compiler.AddToListVar('CFLAGS', '-Wno-invalid-offsetof')
70 self.compiler.AddToListVar('CFLAGS', '-Wno-unused')
71 self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
72 self.compiler.AddToListVar('CFLAGS', '-msse')
73 self.compiler.AddToListVar('CFLAGS', '-m32')
74 self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
75 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
76 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
77 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
78 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
79 self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
80 if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
81 (self.vendor == 'clang' and cxx.majorVersion >= 3):
82 self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
83 self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H')
84 if self.vendor == 'gcc':
85 self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse')
86 elif isinstance(cxx, Cpp.MSVC):
88 if AMBuild.options.debug == '1':
89 self.compiler.AddToListVar('CFLAGS', '/MTd')
90 self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
92 self.compiler.AddToListVar('CFLAGS', '/MT')
93 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
94 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
95 self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
96 self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
97 self.compiler.AddToListVar('CXXFLAGS', '/GR-')
98 self.compiler.AddToListVar('CFLAGS', '/W3')
99 self.compiler.AddToListVar('CFLAGS', '/nologo')
100 self.compiler.AddToListVar('CFLAGS', '/Zi')
101 self.compiler.AddToListVar('CXXFLAGS', '/TP')
102 self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
103 self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
104 self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS')
105 self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
106 self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
107 self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
108 self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
109 self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
110 self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
111 self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
112 self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
113 self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
114 self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
115 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
116 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
119 if AMBuild.options.opt == '1':
120 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
121 if self.vendor == 'gcc' or self.vendor == 'clang':
122 self.compiler.AddToListVar('CFLAGS', '-O3')
123 elif self.vendor == 'msvc':
124 self.compiler.AddToListVar('CFLAGS', '/Ox')
125 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
126 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
129 if AMBuild.options.debug == '1':
130 self.compiler.AddToListVar('CDEFINES', 'DEBUG')
131 self.compiler.AddToListVar('CDEFINES', '_DEBUG')
132 if self.vendor == 'gcc' or self.vendor == 'clang':
133 self.compiler.AddToListVar('CFLAGS', '-g3')
134 elif self.vendor == 'msvc':
135 self.compiler.AddToListVar('CFLAGS', '/Od')
136 self.compiler.AddToListVar('CFLAGS', '/RTC1')
139 if AMBuild.target['platform'] == 'linux':
140 self.compiler.AddToListVar('CDEFINES', '_LINUX')
141 if self.vendor == 'gcc':
142 self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
143 if self.vendor == 'clang':
144 self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
145 elif AMBuild.target['platform'] == 'darwin':
146 self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
147 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
148 self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
150 # For OS X dylib versioning
152 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
153 productContents = productFile.read()
155 m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
157 self.version = '1.0.0'
159 major, minor, release = m.groups()
160 self.version = '{0}.{1}.{2}'.format(major, minor, release)
161 AMBuild.cache.CacheVariable('version', self.version)
162 elif AMBuild.target['platform'] == 'windows':
163 self.compiler.AddToListVar('CDEFINES', 'WIN32')
164 self.compiler.AddToListVar('CDEFINES', '_WINDOWS')
167 self.compiler.AddToListVar('CDEFINES', 'CSSDM_GENERATED_BUILD')
168 self.compiler.AddToListVar('CINCLUDES',
169 os.path.join(AMBuild.outputFolder, 'includes'))
170 self.compiler.ToConfig(AMBuild, 'compiler')
171 AMBuild.cache.CacheVariable('vendor', self.vendor)
173 AMBuild.cache.CacheVariable('targetMap', self.targetMap)
175 self.compiler.FromConfig(AMBuild, 'compiler')
176 self.targetMap = AMBuild.cache['targetMap']
178 if AMBuild.target['platform'] == 'windows':
179 self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public'))
180 self.compiler.AddToListVar('RCINCLUDES',
181 os.path.join(AMBuild.outputFolder, 'includes'))
182 self.mmsPath = AMBuild.cache['MMSOURCE19']
183 self.smSourcePath = AMBuild.cache['SOURCEMOD14']
184 self.smBinPath = AMBuild.cache['SOURCEMOD-BIN']
186 def DefaultCompiler(self):
187 compiler = self.compiler.Clone()
188 compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, 'core', 'sourcehook'))
191 def JobMatters(self, jobname):
192 file = sys._getframe().f_code.co_filename
193 if AMBuild.mode == 'config':
194 self.targetMap[jobname] = file
196 if len(AMBuild.args) == 0:
198 if not jobname in AMBuild.args:
201 def AutoVersion(self, folder, binary):
202 if AMBuild.target['platform'] == 'windows':
203 env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'CSSDM_GENERATED_BUILD']}
204 binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env)
205 elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder):
206 binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0'])
207 binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']])
211 def PreSetupHL2Job(self, job, builder, sdk):
212 info = self.sdkInfo[sdk]
213 sdkPath = AMBuild.cache[info['sdk']]
214 if AMBuild.target['platform'] == 'linux':
216 staticLibs = os.path.join(sdkPath, 'linux_sdk')
218 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
219 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
220 if sdk in ['ep2v', 'l4d', 'l4d2', 'csgo', 'css']:
221 libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.so', 'libtier0.so']
223 libs.append('interfaces_i486.a')
225 link = os.path.join(workFolder, i)
226 target = os.path.join(staticLibs, i)
230 job.AddCommand(SymlinkCommand(link, target))
232 for i in ['tier1_i486.a', 'mathlib_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']:
233 link = os.path.join(workFolder, i)
234 target = os.path.join(staticLibs, i)
238 job.AddCommand(SymlinkCommand(link, target))
239 elif AMBuild.target['platform'] == 'darwin':
240 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
241 workFolder = os.path.join(AMBuild.outputFolder, job.workFolder)
242 libs = ['tier1_i486.a', 'mathlib_i486.a', 'libvstdlib.dylib', 'libtier0.dylib']
244 libs.append('interfaces_i486.a')
246 link = os.path.join(workFolder, i)
247 target = os.path.join(staticLibs, i)
251 job.AddCommand(SymlinkCommand(link, target))
252 elif AMBuild.target['platform'] == 'windows':
253 libs = ['tier0', 'tier1', 'vstdlib', 'mathlib']
254 if sdk == 'swarm' or sdk == 'csgo':
255 libs.append('interfaces')
257 libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib'
258 builder.RebuildIfNewer(libPath)
259 builder['POSTLINKFLAGS'].append(libPath)
261 def PostSetupHL2Job(self, job, builder, sdk):
262 if AMBuild.target['platform'] in ['linux', 'darwin']:
263 builder.AddObjectFiles(['tier1_i486.a', 'mathlib_i486.a'])
265 builder.AddObjectFiles(['interfaces_i486.a'])
267 def DefaultHL2Compiler(self, path, sdk, noLink = False, oldMms = '-legacy'):
268 compiler = self.DefaultCompiler()
274 compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms))
275 compiler['CXXINCLUDES'].append(os.path.join(self.mmsPath, mms, 'sourcehook'))
276 compiler['CXXINCLUDES'].append(os.path.join(self.smSourcePath, 'public'))
277 compiler['CXXINCLUDES'].append(os.path.join(self.smSourcePath, 'public/extensions'))
278 compiler['CXXINCLUDES'].append(os.path.join(self.smSourcePath, 'public/sourcepawn'))
281 compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info])
283 paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'],
284 ['public', 'tier0'], ['public', 'tier1']]
285 if sdk == 'ep1' or sdk == 'darkm':
286 paths.append(['public', 'dlls'])
287 paths.append(['game_shared'])
289 paths.append(['public', 'game', 'server'])
290 paths.append(['game', 'shared'])
291 paths.append(['game', 'server'])
292 paths.append(['common'])
294 info = self.sdkInfo[sdk]
295 sdkPath = AMBuild.cache[info['sdk']]
297 compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def'])
299 if sdk in ['swarm','csgo']:
300 if AMBuild.target['platform'] == 'windows':
301 compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32'])
303 compiler['CDEFINES'].extend(['COMPILER_GCC', 'POSIX'])
306 if AMBuild.target['platform'] == 'linux':
307 staticLibs = os.path.join(sdkPath, 'linux_sdk')
309 if AMBuild.target['platform'] == 'linux':
310 staticLibs = os.path.join(sdkPath, 'lib', 'linux')
311 elif AMBuild.target['platform'] == 'darwin':
312 staticLibs = os.path.join(sdkPath, 'lib', 'mac')
315 compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i))
318 if AMBuild.target['platform'] == 'linux':
319 compiler['POSTLINKFLAGS'][0:0] = ['-lm']
320 if sdk in ['ep2v', 'l4d', 'l4d2', 'csgo', 'css']:
321 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so']
322 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so']
324 compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so']
325 compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so']
326 elif AMBuild.target['platform'] == 'darwin':
327 compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib']
328 compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib']
337 AMBuild.Include(os.path.join('buildbot', 'Versioning'), globals)
340 ['ExtensionBuilder'],
345 for parts in FileList:
346 AMBuild.Include(os.path.join(*parts), globals)