1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/AMBuildScript Mon Aug 26 23:18:03 2013 -0700
1.3 @@ -0,0 +1,159 @@
1.4 +# vim: set ts=2 sw=2 tw=99 noet ft=python:
1.5 +import os
1.6 +import sys
1.7 +from ambuild.command import SymlinkCommand
1.8 +
1.9 +class KE:
1.10 + def __init__(self):
1.11 + self.compiler = Cpp.Compiler()
1.12 +
1.13 + if AMBuild.mode == 'config':
1.14 + #Detect compilers
1.15 + self.compiler.DetectAll(AMBuild)
1.16 +
1.17 + #Set up defines
1.18 + cxx = self.compiler.cxx
1.19 + if isinstance(cxx, Cpp.CompatGCC):
1.20 + if isinstance(cxx, Cpp.GCC):
1.21 + self.vendor = 'gcc'
1.22 + elif isinstance(cxx, Cpp.Clang):
1.23 + self.vendor = 'clang'
1.24 + self.compiler.AddToListVar('CFLAGS', '-pipe')
1.25 + self.compiler.AddToListVar('CFLAGS', '-Wall')
1.26 + self.compiler.AddToListVar('CFLAGS', '-Werror')
1.27 +
1.28 + if AMBuild.options.arch == 'x86':
1.29 + self.compiler.AddToListVar('CFLAGS', '-m32')
1.30 + self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
1.31 + elif AMBuild.options.arch == 'x64':
1.32 + self.compiler.AddToListVar('CFLAGS', '-m64')
1.33 + self.compiler.AddToListVar('POSTLINKFLAGS', '-m64')
1.34 + elif AMBuild.options.arch:
1.35 + raise Exception('Unknown architecture: {0}'.format(AMBuild.options.arch))
1.36 +
1.37 + # Disable some stuff we don't use, that gives us better binary
1.38 + # compatibility on Linux.
1.39 + self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
1.40 + self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
1.41 + self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
1.42 +
1.43 + # We don't really care about these.
1.44 + self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
1.45 + self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
1.46 +
1.47 + # The compiler is too aggressive about what what should be a valid offsetof.
1.48 + self.compiler.AddToListVar('CXXFLAGS', '-Wno-invalid-offsetof')
1.49 +
1.50 + # This would otherwise forbid ((x = y) == NULL) in clang apparently.
1.51 + if self.vendor == 'clang' and cxx.majorVersion > 1:
1.52 + self.compiler.AddToListVar('CXXFLAGS', '-Wno-null-arithmetic')
1.53 + if self.vendor == 'clang' and \
1.54 + cxx.majorVersion >= 3 and \
1.55 + cxx.minorVersion >= 3:
1.56 + self.compiler.AddToListVar('CXXFLAGS', '-Wno-unused-private-field')
1.57 +
1.58 + if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
1.59 + (self.vendor == 'clang' and cxx.majorVersion >= 3):
1.60 + self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
1.61 +
1.62 + self.compiler.AddToListVar('POSTLINKFLAGS', '-lpthread')
1.63 + self.compiler.AddToListVar('POSTLINKFLAGS', '-lrt')
1.64 + elif isinstance(cxx, Cpp.MSVC):
1.65 + self.vendor = 'msvc'
1.66 + if AMBuild.options.debug == '1':
1.67 + self.compiler.AddToListVar('CFLAGS', '/MTd')
1.68 + self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
1.69 + else:
1.70 + self.compiler.AddToListVar('CFLAGS', '/MT')
1.71 + self.compiler.AddToListVar('CDEFINES', 'WIN32')
1.72 + self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
1.73 + self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
1.74 + self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
1.75 + self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
1.76 + self.compiler.AddToListVar('CXXFLAGS', '/GR-')
1.77 + self.compiler.AddToListVar('CFLAGS', '/W3')
1.78 + self.compiler.AddToListVar('CFLAGS', '/nologo')
1.79 + self.compiler.AddToListVar('CFLAGS', '/Zi')
1.80 + self.compiler.AddToListVar('CXXFLAGS', '/TP')
1.81 + self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
1.82 +
1.83 + self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
1.84 + self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
1.85 + self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
1.86 + self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
1.87 + self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
1.88 + self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
1.89 + self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
1.90 + self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
1.91 + self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
1.92 + self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
1.93 + self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
1.94 + self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
1.95 +
1.96 + #Optimization
1.97 + if AMBuild.options.opt == '1':
1.98 + self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
1.99 + if self.vendor == 'gcc' or self.vendor == 'clang':
1.100 + self.compiler.AddToListVar('CFLAGS', '-O3')
1.101 + elif self.vendor == 'msvc':
1.102 + self.compiler.AddToListVar('CFLAGS', '/Ox')
1.103 + self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
1.104 + self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
1.105 +
1.106 + #Debugging
1.107 + if AMBuild.options.debug == '1':
1.108 + if self.vendor == 'gcc' or self.vendor == 'clang':
1.109 + self.compiler.AddToListVar('CFLAGS', '-g3')
1.110 + self.compiler.AddToListVar('CFLAGS', '-O0')
1.111 + elif self.vendor == 'msvc':
1.112 + self.compiler.AddToListVar('CFLAGS', '/Od')
1.113 + self.compiler.AddToListVar('CFLAGS', '/RTC1')
1.114 +
1.115 + #Platform-specifics
1.116 + if AMBuild.target['platform'] == 'linux':
1.117 + if self.vendor == 'gcc':
1.118 + self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
1.119 + if self.vendor == 'clang':
1.120 + self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
1.121 + elif AMBuild.target['platform'] == 'darwin':
1.122 + self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
1.123 + if AMBuild.options.arch == 'x86':
1.124 + self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
1.125 + elif AMBuild.options.arch == 'x64':
1.126 + self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'x86_64'])
1.127 + self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
1.128 +
1.129 + #Finish up
1.130 + self.compiler.ToConfig(AMBuild, 'compiler')
1.131 + AMBuild.cache.CacheVariable('vendor', self.vendor)
1.132 + self.targetMap = { }
1.133 + AMBuild.cache.CacheVariable('targetMap', self.targetMap)
1.134 + else:
1.135 + self.compiler.FromConfig(AMBuild, 'compiler')
1.136 + self.targetMap = AMBuild.cache['targetMap']
1.137 +
1.138 + def DefaultCompiler(self):
1.139 + return self.compiler.Clone()
1.140 +
1.141 + def JobMatters(self, jobname):
1.142 + file = sys._getframe().f_code.co_filename
1.143 + if AMBuild.mode == 'config':
1.144 + self.targetMap[jobname] = file
1.145 + return True
1.146 + if len(AMBuild.args) == 0:
1.147 + return True
1.148 + if not jobname in AMBuild.args:
1.149 + return False
1.150 +
1.151 +ke = KE()
1.152 +globals = {
1.153 + 'KE': ke
1.154 +}
1.155 +
1.156 +FileList = [
1.157 + ['tests', 'AMBuild.tests'],
1.158 + ]
1.159 +
1.160 +for parts in FileList:
1.161 + AMBuild.Include(os.path.join(*parts), globals)
1.162 +