AMBuildScript
author David Anderson <danderson@mozilla.com>
Tue Aug 27 00:49:33 2013 -0700 (2013-08-27)
changeset 12 cebfc7eeafa5
parent 11 cfe800908837
permissions -rw-r--r--
Added hash table tests.
     1 # vim: set ts=2 sw=2 tw=99 noet ft=python:
     2 import os
     3 import sys
     4 from ambuild.command import SymlinkCommand
     5 
     6 class KE:
     7 	def __init__(self):
     8 		self.compiler = Cpp.Compiler()
     9 
    10 		if AMBuild.mode == 'config':
    11 			#Detect compilers
    12 			self.compiler.DetectAll(AMBuild)
    13 
    14 			#Set up defines
    15 			cxx = self.compiler.cxx
    16 			if isinstance(cxx, Cpp.CompatGCC):
    17 				if isinstance(cxx, Cpp.GCC):
    18 					self.vendor = 'gcc'
    19 				elif isinstance(cxx, Cpp.Clang):
    20 					self.vendor = 'clang'
    21 				self.compiler.AddToListVar('CFLAGS', '-pipe')
    22 				self.compiler.AddToListVar('CFLAGS', '-Wall')
    23 				self.compiler.AddToListVar('CFLAGS', '-Werror')
    24 
    25 				if AMBuild.options.arch == 'x86':
    26 					self.compiler.AddToListVar('CFLAGS', '-m32')
    27 					self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
    28 				elif AMBuild.options.arch == 'x64':
    29 					self.compiler.AddToListVar('CFLAGS', '-m64')
    30 					self.compiler.AddToListVar('POSTLINKFLAGS', '-m64')
    31 				elif AMBuild.options.arch:
    32 					raise Exception('Unknown architecture: {0}'.format(AMBuild.options.arch))
    33 
    34 				# Disable some stuff we don't use, that gives us better binary
    35         # compatibility on Linux.
    36 				self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
    37 				self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
    38 				self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
    39 
    40 				# We don't really care about these.
    41 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
    42 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
    43 
    44 				# The compiler is too aggressive about what what should be a valid offsetof.
    45 				self.compiler.AddToListVar('CXXFLAGS', '-Wno-invalid-offsetof')
    46 
    47 				# This would otherwise forbid ((x = y) == NULL) in clang apparently.
    48 				if self.vendor == 'clang' and cxx.majorVersion > 1:
    49 					self.compiler.AddToListVar('CXXFLAGS', '-Wno-null-arithmetic')
    50 				if self.vendor == 'clang' and \
    51 				   cxx.majorVersion >= 3 and \
    52 				   cxx.minorVersion >= 3:
    53 					self.compiler.AddToListVar('CXXFLAGS', '-Wno-unused-private-field')
    54 
    55 				if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
    56 						(self.vendor == 'clang' and cxx.majorVersion >= 3):
    57 					self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
    58 
    59 				self.compiler.AddToListVar('POSTLINKFLAGS', '-lpthread')
    60 				self.compiler.AddToListVar('POSTLINKFLAGS', '-lrt')
    61 			elif isinstance(cxx, Cpp.MSVC):
    62 				self.vendor = 'msvc'
    63 				if AMBuild.options.debug == '1':
    64 					self.compiler.AddToListVar('CFLAGS', '/MTd')
    65 					self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
    66 				else:
    67 					self.compiler.AddToListVar('CFLAGS', '/MT')
    68 				self.compiler.AddToListVar('CDEFINES', 'WIN32')
    69 				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
    70 				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
    71 				self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
    72 				self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
    73 				self.compiler.AddToListVar('CXXFLAGS', '/GR-')
    74 				self.compiler.AddToListVar('CFLAGS', '/W3')
    75 				self.compiler.AddToListVar('CFLAGS', '/nologo')
    76 				self.compiler.AddToListVar('CFLAGS', '/Zi')
    77 				self.compiler.AddToListVar('CXXFLAGS', '/TP')
    78 				self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
    79 
    80 				self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
    81 				self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
    82 				self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
    83 				self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
    84 				self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
    85 				self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
    86 				self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
    87 				self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
    88 				self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
    89 				self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
    90 				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
    91 				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
    92 
    93 			#Optimization
    94 			if AMBuild.options.opt == '1':
    95 				self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
    96 				if self.vendor == 'gcc' or self.vendor == 'clang':
    97 					self.compiler.AddToListVar('CFLAGS', '-O3')
    98 				elif self.vendor == 'msvc':
    99 					self.compiler.AddToListVar('CFLAGS', '/Ox')
   100 					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
   101 					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
   102 
   103 			#Debugging
   104 			if AMBuild.options.debug == '1':
   105 				if self.vendor == 'gcc' or self.vendor == 'clang':
   106 					self.compiler.AddToListVar('CFLAGS', '-g3')
   107 					self.compiler.AddToListVar('CFLAGS', '-O0')
   108 				elif self.vendor == 'msvc':
   109 					self.compiler.AddToListVar('CFLAGS', '/Od')
   110 					self.compiler.AddToListVar('CFLAGS', '/RTC1')
   111 
   112 			#Platform-specifics
   113 			if AMBuild.target['platform'] == 'linux':
   114 				if self.vendor == 'gcc':
   115 					self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
   116 				if self.vendor == 'clang':
   117 					self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
   118 			elif AMBuild.target['platform'] == 'darwin':
   119 				self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
   120 				if AMBuild.options.arch == 'x86':
   121 					self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
   122 				elif AMBuild.options.arch == 'x64':
   123 					self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'x86_64'])
   124 				self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
   125 
   126 			#Finish up
   127 			self.compiler.ToConfig(AMBuild, 'compiler')
   128 			AMBuild.cache.CacheVariable('vendor', self.vendor)
   129 			self.targetMap = { }
   130 			AMBuild.cache.CacheVariable('targetMap', self.targetMap)
   131 		else:
   132 			self.compiler.FromConfig(AMBuild, 'compiler')
   133 			self.targetMap = AMBuild.cache['targetMap']
   134 
   135 	def DefaultCompiler(self):
   136 		return self.compiler.Clone()
   137 
   138 	def JobMatters(self, jobname):
   139 		file = sys._getframe().f_code.co_filename
   140 		if AMBuild.mode == 'config':
   141 			self.targetMap[jobname] = file
   142 			return True
   143 		if len(AMBuild.args) == 0:
   144 			return True
   145 		if not jobname in AMBuild.args:
   146 			return False
   147 
   148 ke = KE()
   149 globals = {
   150 	'KE': ke
   151 }
   152 
   153 FileList = [
   154 		['tests', 'AMBuild.tests'],
   155 	]
   156 
   157 for parts in FileList:
   158 	AMBuild.Include(os.path.join(*parts), globals)
   159