AMBuildScript
author David Anderson <dvander@alliedmods.net>
Sun Jan 27 17:34:30 2013 -0800 (2013-01-27)
changeset 261 219b49bf4a03
parent 251 ca99a81745fe
permissions -rw-r--r--
Add support for importing enum types and enum values (as constexprs).
[email protected]
     1
# vim: set ts=2 sw=2 tw=99 noet ft=python:
[email protected]
     2
# 
[email protected]
     3
# Copyright (C) 2004-2012 David Anderson
[email protected]
     4
# 
[email protected]
     5
# This file is part of SourcePawn.
[email protected]
     6
# 
[email protected]
     7
# SourcePawn is free software: you can redistribute it and/or modify it under
[email protected]
     8
# the terms of the GNU General Public License as published by the Free
[email protected]
     9
# Software Foundation, either version 3 of the License, or (at your option)
[email protected]
    10
# any later version.
[email protected]
    11
# 
[email protected]
    12
# SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
[email protected]
    13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
[email protected]
    14
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
[email protected]
    15
# 
[email protected]
    16
# You should have received a copy of the GNU General Public License along with
[email protected]
    17
# SourcePawn. If not, see http://www.gnu.org/licenses/.
[email protected]
    18
#
[email protected]
    19
[email protected]
    20
import os
[email protected]
    21
import sys
[email protected]
    22
from ambuild.command import SymlinkCommand
[email protected]
    23
[email protected]
    24
class KE:
[email protected]
    25
	def __init__(self):
[email protected]
    26
		self.compiler = Cpp.Compiler()
[email protected]
    27
[email protected]
    28
		if AMBuild.mode == 'config':
[email protected]
    29
			#Detect compilers
[email protected]
    30
			self.compiler.DetectAll(AMBuild)
[email protected]
    31
[email protected]
    32
			#Set up defines
[email protected]
    33
			cxx = self.compiler.cxx
[email protected]
    34
			if isinstance(cxx, Cpp.CompatGCC):
[email protected]
    35
				if isinstance(cxx, Cpp.GCC):
[email protected]
    36
					self.vendor = 'gcc'
[email protected]
    37
				elif isinstance(cxx, Cpp.Clang):
[email protected]
    38
					self.vendor = 'clang'
[email protected]
    39
				self.compiler.AddToListVar('CFLAGS', '-pipe')
[email protected]
    40
				self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
[email protected]
    41
				if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
[email protected]
    42
					self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
[email protected]
    43
					self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
[email protected]
    44
				self.compiler.AddToListVar('CFLAGS', '-Wall')
[email protected]
    45
				self.compiler.AddToListVar('CFLAGS', '-Werror')
[email protected]
    46
				self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
[email protected]
    47
[email protected]
    48
				if AMBuild.options.arch == 'x86':
[email protected]
    49
					self.compiler.AddToListVar('CFLAGS', '-m32')
[email protected]
    50
					self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
[email protected]
    51
				elif AMBuild.options.arch == 'x64':
[email protected]
    52
					self.compiler.AddToListVar('CFLAGS', '-m64')
[email protected]
    53
					self.compiler.AddToListVar('POSTLINKFLAGS', '-m64')
[email protected]
    54
				elif AMBuild.options.arch:
[email protected]
    55
					raise Exception('Unknown architecture: {0}'.format(AMBuild.options.arch))
[email protected]
    56
[email protected]
    57
				# Disable some stuff we don't use, that gives us better binary
[email protected]
    58
        # compatibility on Linux.
[email protected]
    59
				self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
[email protected]
    60
				self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
[email protected]
    61
				self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
[email protected]
    62
[email protected]
    63
				# We don't really care about these.
[email protected]
    64
				self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
[email protected]
    65
				self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
[email protected]
    66
[email protected]
    67
				# The compiler is too aggressive about what what should be a valid offsetof.
[email protected]
    68
				self.compiler.AddToListVar('CXXFLAGS', '-Wno-invalid-offsetof')
[email protected]
    69
[email protected]
    70
				# This would otherwise forbid ((x = y) == NULL) in clang apparently.
[email protected]
    71
				if self.vendor == 'clang' and cxx.majorVersion > 1:
[email protected]
    72
					self.compiler.AddToListVar('CXXFLAGS', '-Wno-null-arithmetic')
[email protected]
    73
				if self.vendor == 'clang' and \
[email protected]
    74
				   cxx.majorVersion >= 3 and \
[email protected]
    75
				   cxx.minorVersion >= 3:
[email protected]
    76
					self.compiler.AddToListVar('CXXFLAGS', '-Wno-unused-private-field')
[email protected]
    77
[email protected]
    78
				if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
[email protected]
    79
						(self.vendor == 'clang' and cxx.majorVersion >= 3):
[email protected]
    80
					self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
[email protected]
    81
[email protected]
    82
				self.compiler.AddToListVar('POSTLINKFLAGS', '-lm')
[email protected]
    83
			elif isinstance(cxx, Cpp.MSVC):
[email protected]
    84
				self.vendor = 'msvc'
[email protected]
    85
				if AMBuild.options.debug == '1':
[email protected]
    86
					self.compiler.AddToListVar('CFLAGS', '/MTd')
[email protected]
    87
					self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
[email protected]
    88
				else:
[email protected]
    89
					self.compiler.AddToListVar('CFLAGS', '/MT')
[email protected]
    90
				self.compiler.AddToListVar('CDEFINES', 'WIN32')
[email protected]
    91
				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
[email protected]
    92
				self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
[email protected]
    93
				self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
[email protected]
    94
				self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
[email protected]
    95
				self.compiler.AddToListVar('CXXFLAGS', '/GR-')
[email protected]
    96
				self.compiler.AddToListVar('CFLAGS', '/W3')
[email protected]
    97
				self.compiler.AddToListVar('CFLAGS', '/nologo')
[email protected]
    98
				self.compiler.AddToListVar('CFLAGS', '/Zi')
[email protected]
    99
				self.compiler.AddToListVar('CXXFLAGS', '/TP')
[email protected]
   100
				self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
[email protected]
   101
[email protected]
   102
				self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
[email protected]
   103
				self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
[email protected]
   104
				self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
[email protected]
   105
				self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
[email protected]
   106
				self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
[email protected]
   107
				self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
[email protected]
   108
				self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
[email protected]
   109
				self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
[email protected]
   110
				self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
[email protected]
   111
				self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
[email protected]
   112
				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
[email protected]
   113
				self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
[email protected]
   114
[email protected]
   115
			#Optimization
[email protected]
   116
			if AMBuild.options.opt == '1':
[email protected]
   117
				self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
[email protected]
   118
				if self.vendor == 'gcc' or self.vendor == 'clang':
[email protected]
   119
					self.compiler.AddToListVar('CFLAGS', '-O3')
[email protected]
   120
				elif self.vendor == 'msvc':
[email protected]
   121
					self.compiler.AddToListVar('CFLAGS', '/Ox')
[email protected]
   122
					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
[email protected]
   123
					self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
[email protected]
   124
[email protected]
   125
			#Debugging
[email protected]
   126
			if AMBuild.options.debug == '1':
[email protected]
   127
				if self.vendor == 'gcc' or self.vendor == 'clang':
[email protected]
   128
					self.compiler.AddToListVar('CFLAGS', '-g3')
[email protected]
   129
				elif self.vendor == 'msvc':
[email protected]
   130
					self.compiler.AddToListVar('CFLAGS', '/Od')
[email protected]
   131
					self.compiler.AddToListVar('CFLAGS', '/RTC1')
[email protected]
   132
[email protected]
   133
			#Platform-specifics
[email protected]
   134
			if AMBuild.target['platform'] == 'linux':
[email protected]
   135
				self.compiler.AddToListVar('CDEFINES', '_LINUX')
[email protected]
   136
				if self.vendor == 'gcc':
[email protected]
   137
					self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
[email protected]
   138
				if self.vendor == 'clang':
[email protected]
   139
					self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
dvande[email protected]
   140
			elif AMBuild.target['platform'] == 'darwin':
[email protected]
   141
				self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
[email protected]
   142
				if AMBuild.options.arch == 'x86':
[email protected]
   143
					self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
[email protected]
   144
				elif AMBuild.options.arch == 'x64':
[email protected]
   145
					self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'x86_64'])
[email protected]
   146
				self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
[email protected]
   147
[email protected]
   148
				# For OS X dylib versioning
[email protected]
   149
				import re
[email protected]
   150
				productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
[email protected]
   151
				productContents = productFile.read()
[email protected]
   152
				productFile.close()
[email protected]
   153
				m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
[email protected]
   154
				if m == None:
[email protected]
   155
					self.version = '1.0.0'
[email protected]
   156
				else:
[email protected]
   157
					major, minor, release = m.groups()
[email protected]
   158
					self.version = '{0}.{1}.{2}'.format(major, minor, release)
[email protected]
   159
				AMBuild.cache.CacheVariable('version', self.version)
[email protected]
   160
[email protected]
   161
			#Finish up
[email protected]
   162
			self.compiler.ToConfig(AMBuild, 'compiler')
[email protected]
   163
			AMBuild.cache.CacheVariable('vendor', self.vendor)
[email protected]
   164
			self.targetMap = { }
[email protected]
   165
			AMBuild.cache.CacheVariable('targetMap', self.targetMap)
[email protected]
   166
		else:
[email protected]
   167
			self.compiler.FromConfig(AMBuild, 'compiler')
[email protected]
   168
			self.targetMap = AMBuild.cache['targetMap']
[email protected]
   169
[email protected]
   170
	def DefaultCompiler(self):
[email protected]
   171
		return self.compiler.Clone()
[email protected]
   172
[email protected]
   173
	def JobMatters(self, jobname):
[email protected]
   174
		file = sys._getframe().f_code.co_filename
[email protected]
   175
		if AMBuild.mode == 'config':
[email protected]
   176
			self.targetMap[jobname] = file
[email protected]
   177
			return True
[email protected]
   178
		if len(AMBuild.args) == 0:
[email protected]
   179
			return True
[email protected]
   180
		if not jobname in AMBuild.args:
[email protected]
   181
			return False
[email protected]
   182
[email protected]
   183
ke = KE()
[email protected]
   184
globals = {
[email protected]
   185
	'KE': ke
[email protected]
   186
}
[email protected]
   187
[email protected]
   188
FileList = [
[email protected]
   189
		['src', 'AMBuild.library'],
[email protected]
   190
		['src', 'AMBuild.shell'],
[email protected]
   191
		['AMBuild.dist']
[email protected]
   192
	]
[email protected]
   193
[email protected]
   194
for parts in FileList:
[email protected]
   195
	AMBuild.Include(os.path.join(*parts), globals)
[email protected]
   196