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