danderson@11: # vim: set ts=2 sw=2 tw=99 noet ft=python: danderson@11: import os danderson@11: import sys danderson@11: from ambuild.command import SymlinkCommand danderson@11: danderson@11: class KE: danderson@11: def __init__(self): danderson@11: self.compiler = Cpp.Compiler() danderson@11: danderson@11: if AMBuild.mode == 'config': danderson@11: #Detect compilers danderson@11: self.compiler.DetectAll(AMBuild) danderson@11: danderson@11: #Set up defines danderson@11: cxx = self.compiler.cxx danderson@11: if isinstance(cxx, Cpp.CompatGCC): danderson@11: if isinstance(cxx, Cpp.GCC): danderson@11: self.vendor = 'gcc' danderson@11: elif isinstance(cxx, Cpp.Clang): danderson@11: self.vendor = 'clang' danderson@11: self.compiler.AddToListVar('CFLAGS', '-pipe') danderson@11: self.compiler.AddToListVar('CFLAGS', '-Wall') danderson@11: self.compiler.AddToListVar('CFLAGS', '-Werror') danderson@11: danderson@11: if AMBuild.options.arch == 'x86': danderson@11: self.compiler.AddToListVar('CFLAGS', '-m32') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '-m32') danderson@11: elif AMBuild.options.arch == 'x64': danderson@11: self.compiler.AddToListVar('CFLAGS', '-m64') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '-m64') danderson@11: elif AMBuild.options.arch: danderson@11: raise Exception('Unknown architecture: {0}'.format(AMBuild.options.arch)) danderson@11: danderson@11: # Disable some stuff we don't use, that gives us better binary danderson@11: # compatibility on Linux. danderson@11: self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions') danderson@11: self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti') danderson@11: self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics') danderson@11: danderson@11: # We don't really care about these. danderson@11: self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor') danderson@11: self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual') danderson@11: danderson@11: # The compiler is too aggressive about what what should be a valid offsetof. danderson@11: self.compiler.AddToListVar('CXXFLAGS', '-Wno-invalid-offsetof') danderson@11: danderson@11: # This would otherwise forbid ((x = y) == NULL) in clang apparently. danderson@11: if self.vendor == 'clang' and cxx.majorVersion > 1: danderson@11: self.compiler.AddToListVar('CXXFLAGS', '-Wno-null-arithmetic') danderson@11: if self.vendor == 'clang' and \ danderson@11: cxx.majorVersion >= 3 and \ danderson@11: cxx.minorVersion >= 3: danderson@11: self.compiler.AddToListVar('CXXFLAGS', '-Wno-unused-private-field') danderson@11: danderson@11: if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \ danderson@11: (self.vendor == 'clang' and cxx.majorVersion >= 3): danderson@11: self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor') danderson@11: danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '-lpthread') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '-lrt') danderson@11: elif isinstance(cxx, Cpp.MSVC): danderson@11: self.vendor = 'msvc' danderson@11: if AMBuild.options.debug == '1': danderson@11: self.compiler.AddToListVar('CFLAGS', '/MTd') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt') danderson@11: else: danderson@11: self.compiler.AddToListVar('CFLAGS', '/MT') danderson@11: self.compiler.AddToListVar('CDEFINES', 'WIN32') danderson@11: self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE') danderson@11: self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS') danderson@11: self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE') danderson@11: self.compiler.AddToListVar('CXXFLAGS', '/EHsc') danderson@11: self.compiler.AddToListVar('CXXFLAGS', '/GR-') danderson@11: self.compiler.AddToListVar('CFLAGS', '/W3') danderson@11: self.compiler.AddToListVar('CFLAGS', '/nologo') danderson@11: self.compiler.AddToListVar('CFLAGS', '/Zi') danderson@11: self.compiler.AddToListVar('CXXFLAGS', '/TP') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG') danderson@11: danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib') danderson@11: danderson@11: #Optimization danderson@11: if AMBuild.options.opt == '1': danderson@11: self.compiler.AddToListVar('CDEFINES', 'NDEBUG') danderson@11: if self.vendor == 'gcc' or self.vendor == 'clang': danderson@11: self.compiler.AddToListVar('CFLAGS', '-O3') danderson@11: elif self.vendor == 'msvc': danderson@11: self.compiler.AddToListVar('CFLAGS', '/Ox') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF') danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF') danderson@11: danderson@11: #Debugging danderson@11: if AMBuild.options.debug == '1': danderson@11: if self.vendor == 'gcc' or self.vendor == 'clang': danderson@11: self.compiler.AddToListVar('CFLAGS', '-g3') danderson@11: self.compiler.AddToListVar('CFLAGS', '-O0') danderson@11: elif self.vendor == 'msvc': danderson@11: self.compiler.AddToListVar('CFLAGS', '/Od') danderson@11: self.compiler.AddToListVar('CFLAGS', '/RTC1') danderson@11: danderson@11: #Platform-specifics danderson@11: if AMBuild.target['platform'] == 'linux': danderson@11: if self.vendor == 'gcc': danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc') danderson@11: if self.vendor == 'clang': danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh') danderson@11: elif AMBuild.target['platform'] == 'darwin': danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5') danderson@11: if AMBuild.options.arch == 'x86': danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386']) danderson@11: elif AMBuild.options.arch == 'x64': danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'x86_64']) danderson@11: self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++') danderson@11: danderson@11: #Finish up danderson@11: self.compiler.ToConfig(AMBuild, 'compiler') danderson@11: AMBuild.cache.CacheVariable('vendor', self.vendor) danderson@11: self.targetMap = { } danderson@11: AMBuild.cache.CacheVariable('targetMap', self.targetMap) danderson@11: else: danderson@11: self.compiler.FromConfig(AMBuild, 'compiler') danderson@11: self.targetMap = AMBuild.cache['targetMap'] danderson@11: danderson@11: def DefaultCompiler(self): danderson@11: return self.compiler.Clone() danderson@11: danderson@11: def JobMatters(self, jobname): danderson@11: file = sys._getframe().f_code.co_filename danderson@11: if AMBuild.mode == 'config': danderson@11: self.targetMap[jobname] = file danderson@11: return True danderson@11: if len(AMBuild.args) == 0: danderson@11: return True danderson@11: if not jobname in AMBuild.args: danderson@11: return False danderson@11: danderson@11: ke = KE() danderson@11: globals = { danderson@11: 'KE': ke danderson@11: } danderson@11: danderson@11: FileList = [ danderson@11: ['tests', 'AMBuild.tests'], danderson@11: ] danderson@11: danderson@11: for parts in FileList: danderson@11: AMBuild.Include(os.path.join(*parts), globals) danderson@11: