ds@704: # vim: set ts=2 sw=2 tw=99 noet ft=python: ds@704: import os ds@704: import sys ds@704: from ambuild.command import SymlinkCommand ds@704: ds@704: class MMS: ds@704: def __init__(self): ds@704: self.compiler = Cpp.Compiler() ds@704: ds@704: #Build SDK info reuben@773: self.possibleSdks = { } reuben@773: self.possibleSdks['ep1'] = {'sdk': 'HL2SDK', 'ext': '1.ep1', 'def': '1', reuben@773: 'name': 'EPISODEONE', 'platform': ['windows', 'linux']} reuben@773: self.possibleSdks['ep2'] = {'sdk': 'HL2SDKOB', 'ext': '2.ep2', 'def': '3', reuben@773: 'name': 'ORANGEBOX', 'platform': ['windows', 'linux']} skamonkey@791: self.possibleSdks['css'] = {'sdk': 'HL2SDKCSS', 'ext': '2.css', 'def': '6', skamonkey@791: 'name': 'CSS', 'platform': ['windows', 'linux', 'darwin']} skamonkey@791: self.possibleSdks['ep2v'] = {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v', 'def': '7', reuben@773: 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin']} skamonkey@791: self.possibleSdks['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '8', reuben@773: 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux', 'darwin']} skamonkey@791: self.possibleSdks['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '9', reuben@773: 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux', 'darwin']} reuben@773: self.possibleSdks['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '2.darkm', 'def': '2', reuben@773: 'name': 'DARKMESSIAH', 'platform': ['windows']} skamonkey@791: self.possibleSdks['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '2.swarm', 'def': '10', reuben@773: 'name': 'ALIENSWARM', 'platform': ['windows']} reuben@773: self.possibleSdks['bgt'] = {'sdk': 'HL2SDK-BGT', 'ext': '2.bgt', 'def': '4', reuben@773: 'name': 'BLOODYGOODTIME', 'platform': ['windows']} reuben@773: self.possibleSdks['eye'] = {'sdk': 'HL2SDK-EYE', 'ext': '2.eye', 'def': '5', reuben@773: 'name': 'EYE', 'platform': ['windows']} skamonkey@791: self.possibleSdks['csgo'] = {'sdk': 'HL2SDKCSGO', 'ext': '2.csgo', 'def': '12', ds@798: 'name': 'CSGO', 'platform': ['windows', 'linux', 'darwin']} skamonkey@791: # self.possibleSdks['portal2'] = {'sdk': 'HL2SDK-PORTAL2', 'ext': '2.portal2', 'def': '11', skamonkey@780: # 'name': 'PORTAL2', 'platform': ['windows']} reuben@773: ds@704: self.sdkInfo = { } reuben@773: ds@704: if AMBuild.mode == 'config': ds@704: #Detect compilers ds@704: self.compiler.DetectAll(AMBuild) ds@704: ds@704: #Detect variables ds@704: envvars = {} ds@704: if AMBuild.target['platform'] != 'darwin': ds@704: envvars['HL2SDK'] = 'hl2sdk' ds@704: envvars['HL2SDKOB'] = 'hl2sdk-ob' ds@704: skamonkey@791: envvars['HL2SDKCSS'] = 'hl2sdk-css' ds@704: envvars['HL2SDKOBVALVE'] = 'hl2sdk-ob-valve' ds@737: envvars['HL2SDKL4D'] = 'hl2sdk-l4d' ds@732: envvars['HL2SDKL4D2'] = 'hl2sdk-l4d2' ds@798: envvars['HL2SDKCSGO'] = 'hl2sdk-csgo' ds@704: ds@704: #Dark Messiah is Windows-only ds@704: if AMBuild.target['platform'] == 'windows': ds@704: envvars['HL2SDK-DARKM'] = 'hl2sdk-darkm' ds@725: envvars['HL2SDK-SWARM'] = 'hl2sdk-swarm' skamonkey@740: envvars['HL2SDK-BGT'] = 'hl2sdk-bgt' skamonkey@763: envvars['HL2SDK-EYE'] = 'hl2sdk-eye' ds@704: reuben@773: # Finds if a dict with `key` set to `value` is present on the dict of dicts `dictionary` reuben@773: def findDictByKey(dictionary, key, value): reuben@773: for index in dictionary: reuben@773: elem = dictionary[index] reuben@773: if elem[key] == value: reuben@773: return (elem, index) reuben@773: return None reuben@773: ds@704: for i in envvars: ds@704: if i in os.environ: ds@704: path = os.environ[i] ds@704: if not os.path.isdir(path): ds@704: raise Exception('Path for {0} was not found: {1}'.format(i, path)) reuben@773: elif i.startswith('HL2SDK'): reuben@773: (info, sdk) = findDictByKey(self.possibleSdks, 'sdk', i) reuben@773: self.sdkInfo[sdk] = info ds@704: else: ds@704: head = os.getcwd() ds@704: oldhead = None ds@704: while head != None and head != oldhead: ds@704: path = os.path.join(head, envvars[i]) ds@704: if os.path.isdir(path): ds@704: break ds@704: oldhead = head ds@704: head, tail = os.path.split(head) reuben@773: if i.startswith('HL2SDK'): reuben@773: if head != None and head != oldhead: reuben@773: (info, sdk) = findDictByKey(self.possibleSdks, 'sdk', i) reuben@773: self.sdkInfo[sdk] = info reuben@773: elif head == None or head == oldhead: ds@704: raise Exception('Could not find a valid path for {0}'.format(i)) ds@704: AMBuild.cache.CacheVariable(i, path) reuben@773: reuben@773: if len(self.sdkInfo) < 1: reuben@773: raise Exception('At least one SDK must be available.') reuben@773: reuben@773: AMBuild.cache.CacheVariable('sdkInfo', self.sdkInfo) ds@704: ds@704: #Set up defines ds@704: cxx = self.compiler.cxx ds@747: if isinstance(cxx, Cpp.CompatGCC): ds@747: if isinstance(cxx, Cpp.GCC): ds@747: self.vendor = 'gcc' ds@747: elif isinstance(cxx, Cpp.Clang): ds@747: self.vendor = 'clang' ds@704: self.compiler.AddToListVar('CDEFINES', 'stricmp=strcasecmp') ds@704: self.compiler.AddToListVar('CDEFINES', '_stricmp=strcasecmp') ds@704: self.compiler.AddToListVar('CDEFINES', '_snprintf=snprintf') ds@704: self.compiler.AddToListVar('CDEFINES', '_vsnprintf=vsnprintf') ds@704: self.compiler.AddToListVar('CFLAGS', '-pipe') ds@704: self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing') ds@747: if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang': ds@704: self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden') ds@704: self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden') ds@704: self.compiler.AddToListVar('CFLAGS', '-Wall') ds@704: self.compiler.AddToListVar('CFLAGS', '-Werror') ds@704: self.compiler.AddToListVar('CFLAGS', '-Wno-uninitialized') ds@704: self.compiler.AddToListVar('CFLAGS', '-Wno-unused') ds@704: self.compiler.AddToListVar('CFLAGS', '-Wno-switch') ds@704: self.compiler.AddToListVar('CFLAGS', '-msse') ds@704: self.compiler.AddToListVar('CFLAGS', '-m32') ds@735: self.compiler.AddToListVar('POSTLINKFLAGS', '-m32') ds@704: self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions') ds@704: self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti') ds@704: self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics') ds@704: self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor') ds@747: self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual') skamonkey@779: if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \ ds@777: (self.vendor == 'clang' and cxx.majorVersion >= 3): ds@777: self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor') ds@704: self.compiler.AddToListVar('CDEFINES', 'HAVE_STDINT_H') ds@747: if self.vendor == 'gcc': ds@747: self.compiler.AddToListVar('CFLAGS', '-mfpmath=sse') ds@704: elif isinstance(cxx, Cpp.MSVC): ds@704: self.vendor = 'msvc' ds@704: if AMBuild.options.debug == '1': ds@704: self.compiler.AddToListVar('CFLAGS', '/MTd') ds@725: self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt') ds@704: else: ds@704: self.compiler.AddToListVar('CFLAGS', '/MT') ds@704: self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE') ds@704: self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS') ds@704: self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE') ds@704: self.compiler.AddToListVar('CXXFLAGS', '/EHsc') ds@704: self.compiler.AddToListVar('CXXFLAGS', '/GR-') ds@704: self.compiler.AddToListVar('CFLAGS', '/W3') ds@704: self.compiler.AddToListVar('CFLAGS', '/nologo') ds@704: self.compiler.AddToListVar('CFLAGS', '/Zi') ds@704: self.compiler.AddToListVar('CXXFLAGS', '/TP') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:WINDOWS') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib') ds@704: ds@704: #Optimization ds@704: if AMBuild.options.opt == '1': ds@704: self.compiler.AddToListVar('CDEFINES', 'NDEBUG') ds@747: if self.vendor == 'gcc' or self.vendor == 'clang': ds@704: self.compiler.AddToListVar('CFLAGS', '-O3') ds@704: elif self.vendor == 'msvc': ds@709: self.compiler.AddToListVar('CFLAGS', '/Ox') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF') ds@708: self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF') ds@704: ds@704: #Debugging ds@704: if AMBuild.options.debug == '1': ds@704: self.compiler.AddToListVar('CDEFINES', 'DEBUG') ds@704: self.compiler.AddToListVar('CDEFINES', '_DEBUG') ds@747: if self.vendor == 'gcc' or self.vendor == 'clang': ds@704: self.compiler.AddToListVar('CFLAGS', '-g3') ds@704: elif self.vendor == 'msvc': ds@704: self.compiler.AddToListVar('CFLAGS', '/Od') ds@704: self.compiler.AddToListVar('CFLAGS', '/RTC1') ds@704: ds@704: #Platform-specifics ds@704: if AMBuild.target['platform'] == 'linux': ds@704: self.compiler.AddToListVar('CDEFINES', '_LINUX') ds@753: if self.vendor == 'gcc': ds@753: self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc') ds@752: if self.vendor == 'clang': ds@752: self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh') ds@704: elif AMBuild.target['platform'] == 'darwin': ds@798: self.compiler.AddToListVar('CDEFINES', 'OSX') ds@798: self.compiler.AddToListVar('CDEFINES', '_OSX') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5') ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386']) ds@704: self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++') ds@718: ds@718: # For OS X dylib versioning ds@718: import re ds@718: productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r') ds@718: productContents = productFile.read() ds@718: productFile.close() ds@718: m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents) ds@718: if m == None: ds@718: self.version = '1.0.0' ds@718: else: ds@718: major, minor, release = m.groups() ds@718: self.version = '{0}.{1}.{2}'.format(major, minor, release) ds@718: AMBuild.cache.CacheVariable('version', self.version) ds@704: elif AMBuild.target['platform'] == 'windows': ds@704: self.compiler.AddToListVar('CDEFINES', 'WIN32') ds@704: self.compiler.AddToListVar('CDEFINES', '_WINDOWS') ds@704: ds@704: #Finish up ds@704: self.compiler.AddToListVar('CDEFINES', 'MMS_GENERATED_BUILD') ds@704: self.compiler.AddToListVar('CINCLUDES', ds@704: os.path.join(AMBuild.outputFolder, 'includes')) ds@704: self.compiler.ToConfig(AMBuild, 'compiler') ds@704: AMBuild.cache.CacheVariable('vendor', self.vendor) ds@704: self.targetMap = { } ds@704: AMBuild.cache.CacheVariable('targetMap', self.targetMap) ds@704: else: reuben@773: self.sdkInfo = AMBuild.cache['sdkInfo'] ds@704: self.compiler.FromConfig(AMBuild, 'compiler') ds@704: self.targetMap = AMBuild.cache['targetMap'] ds@704: ds@704: if AMBuild.target['platform'] == 'windows': ds@704: self.compiler.AddToListVar('RCINCLUDES', os.path.join(AMBuild.sourceFolder, 'public')) ds@704: self.compiler.AddToListVar('RCINCLUDES', ds@704: os.path.join(AMBuild.outputFolder, 'includes')) ds@704: ds@704: def DefaultCompiler(self): ds@704: compiler = self.compiler.Clone() ds@704: compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'public')) ds@704: return compiler ds@704: ds@704: def JobMatters(self, jobname): ds@704: file = sys._getframe().f_code.co_filename ds@704: if AMBuild.mode == 'config': ds@704: self.targetMap[jobname] = file ds@704: return True ds@704: if len(AMBuild.args) == 0: ds@704: return True ds@704: if not jobname in AMBuild.args: ds@704: return False ds@704: ds@704: def AutoVersion(self, folder, binary): ds@718: if AMBuild.target['platform'] == 'windows': ds@718: env = {'RCDEFINES': ['BINARY_NAME="' + binary.binaryFile + '"', 'MMS_GENERATED_BUILD']} ds@718: binary.AddResourceFile(os.path.join(folder, 'version.rc' ), env) ds@718: elif AMBuild.target['platform'] == 'darwin' and isinstance(binary, Cpp.LibraryBuilder): ds@718: binary.compiler['POSTLINKFLAGS'].extend(['-compatibility_version', '1.0.0']) ds@718: binary.compiler['POSTLINKFLAGS'].extend(['-current_version', AMBuild.cache['version']]) ds@718: else: ds@704: return ds@704: ds@704: def PreSetupHL2Job(self, job, builder, sdk): ds@704: info = self.sdkInfo[sdk] ds@704: sdkPath = AMBuild.cache[info['sdk']] ds@704: if AMBuild.target['platform'] == 'linux': ds@704: if sdk == 'ep1': ds@704: staticLibs = os.path.join(sdkPath, 'linux_sdk') ds@704: else: ds@704: staticLibs = os.path.join(sdkPath, 'lib', 'linux') ds@704: workFolder = os.path.join(AMBuild.outputFolder, job.workFolder) skamonkey@791: if sdk in ['css', 'ep2v', 'l4d', 'l4d2', 'csgo']: skamonkey@780: libs = ['tier1_i486.a', 'libvstdlib.so', 'libtier0.so'] skamonkey@780: if sdk == 'csgo': skamonkey@780: libs.insert(0, 'interfaces_i486.a') skamonkey@780: for lib in libs: skamonkey@780: link = os.path.join(workFolder, lib) skamonkey@780: target = os.path.join(staticLibs, lib) ds@704: try: ds@704: os.lstat(link) ds@704: except: ds@704: job.AddCommand(SymlinkCommand(link, target)) ds@704: else: ds@704: for i in ['tier1_i486.a', 'vstdlib_i486.so', 'tier0_i486.so']: ds@704: link = os.path.join(workFolder, i) ds@704: target = os.path.join(staticLibs, i) ds@704: try: ds@704: os.lstat(link) ds@704: except: ds@704: job.AddCommand(SymlinkCommand(link, target)) ds@704: elif AMBuild.target['platform'] == 'darwin': ds@704: staticLibs = os.path.join(sdkPath, 'lib', 'mac') ds@704: workFolder = os.path.join(AMBuild.outputFolder, job.workFolder) skamonkey@780: libs = ['tier1_i486.a', 'libvstdlib.dylib', 'libtier0.dylib'] skamonkey@780: if sdk == 'csgo': skamonkey@780: libs.append('interfaces_i486.a') skamonkey@780: for lib in libs: skamonkey@780: link = os.path.join(workFolder, lib) skamonkey@780: target = os.path.join(staticLibs, lib) ds@704: try: ds@704: os.lstat(link) ds@704: except: ds@704: job.AddCommand(SymlinkCommand(link, target)) ds@704: elif AMBuild.target['platform'] == 'windows': ds@725: libs = ['tier0', 'tier1', 'vstdlib'] skamonkey@780: if sdk in ['swarm', 'csgo']: ds@725: libs.append('interfaces') ds@725: for lib in libs: ds@704: libPath = os.path.join(sdkPath, 'lib', 'public', lib) + '.lib' ds@704: builder.RebuildIfNewer(libPath) ds@704: builder['POSTLINKFLAGS'].append(libPath) ds@704: ds@704: def PostSetupHL2Job(self, job, builder, sdk): ds@704: if AMBuild.target['platform'] in ['linux', 'darwin']: ds@704: builder.AddObjectFiles(['tier1_i486.a']) skamonkey@780: if( sdk == 'csgo' ): skamonkey@780: builder.AddObjectFiles(['interfaces_i486.a']) ds@704: ds@704: def DefaultHL2Compiler(self, path, sdk, noLink = False): ds@704: compiler = self.DefaultCompiler() ds@704: ds@704: compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path)) ds@704: compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sourcehook')) ds@704: compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'loader')) ds@704: reuben@773: info = self.possibleSdks ds@704: compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info]) skamonkey@780: skamonkey@780: # We don't build for Portal 2 (yet?, ever?), but using this define in code as skamonkey@780: # it saves trouble if we ever need to skamonkey@791: compiler['CDEFINES'].append('SE_PORTAL2=11') ds@704: ds@704: paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'], ds@704: ['public', 'tier0'], ['public', 'tier1']] ds@704: if sdk == 'ep1' or sdk == 'darkm': ds@704: paths.append(['public', 'dlls']) ds@704: paths.append(['game_shared']) ds@704: else: ds@704: paths.append(['public', 'game', 'server']) ds@704: paths.append(['game', 'shared']) ds@704: paths.append(['common']) ds@704: ds@704: info = self.sdkInfo[sdk] ds@704: sdkPath = AMBuild.cache[info['sdk']] ds@704: ds@704: compiler['CDEFINES'].append('SOURCE_ENGINE=' + info['def']) ds@704: skamonkey@780: if sdk in ['swarm', 'csgo']: skamonkey@780: if AMBuild.target['platform'] == 'windows': skamonkey@780: compiler['CDEFINES'].extend(['COMPILER_MSVC', 'COMPILER_MSVC32']) skamonkey@780: else: skamonkey@780: compiler['CDEFINES'].extend(['COMPILER_GCC', 'POSIX']) ds@725: ds@704: if sdk == 'ep1': ds@704: if AMBuild.target['platform'] == 'linux': ds@704: staticLibs = os.path.join(sdkPath, 'linux_sdk') ds@704: else: ds@704: if AMBuild.target['platform'] == 'linux': ds@704: staticLibs = os.path.join(sdkPath, 'lib', 'linux') ds@704: elif AMBuild.target['platform'] == 'darwin': ds@704: staticLibs = os.path.join(sdkPath, 'lib', 'mac') ds@704: ds@704: for i in paths: ds@704: compiler['CXXINCLUDES'].append(os.path.join(sdkPath, *i)) ds@704: ds@704: if not noLink: ds@704: if AMBuild.target['platform'] == 'linux': ds@704: compiler['POSTLINKFLAGS'][0:0] = ['-lm'] skamonkey@791: if sdk in ['css', 'ep2v', 'l4d', 'l4d2', 'csgo']: ds@704: compiler['POSTLINKFLAGS'][0:0] = ['libtier0.so'] ds@704: compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.so'] ds@704: else: ds@704: compiler['POSTLINKFLAGS'][0:0] = ['tier0_i486.so'] ds@704: compiler['POSTLINKFLAGS'][0:0] = ['vstdlib_i486.so'] ds@704: elif AMBuild.target['platform'] == 'darwin': ds@704: compiler['POSTLINKFLAGS'][0:0] = ['libtier0.dylib'] ds@704: compiler['POSTLINKFLAGS'][0:0] = ['libvstdlib.dylib'] ds@704: ds@704: return compiler ds@704: ds@704: mms = MMS() ds@704: globals = { ds@704: 'MMS': mms ds@704: } ds@704: ds@704: AMBuild.Include(os.path.join('support', 'buildbot', 'Versioning'), globals) ds@704: ds@704: FileList = [ ds@704: ['loader', 'AMBuilder'], ds@704: ['core', 'AMBuilder'], ds@704: ['core-legacy', 'AMBuilder'], ds@704: ['support', 'buildbot', 'PackageScript'] ds@704: ] ds@704: ds@704: for parts in FileList: ds@704: AMBuild.Include(os.path.join(*parts), globals) ds@704: