Stop using ccache on OS X.
1 # vim: set ts=2 sw=2 tw=99 noet ft=python:
3 # Copyright (C) 2004-2012 David Anderson
5 # This file is part of SourcePawn.
7 # SourcePawn is free software: you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation, either version 3 of the License, or (at your option)
12 # SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # SourcePawn. If not, see http://www.gnu.org/licenses/.
22 from ambuild.command import SymlinkCommand
26 self.compiler = Cpp.Compiler()
28 if AMBuild.mode == 'config':
30 self.compiler.DetectAll(AMBuild)
33 cxx = self.compiler.cxx
34 if isinstance(cxx, Cpp.CompatGCC):
35 if isinstance(cxx, Cpp.GCC):
37 elif isinstance(cxx, Cpp.Clang):
39 self.compiler.AddToListVar('CFLAGS', '-pipe')
40 self.compiler.AddToListVar('CFLAGS', '-fno-strict-aliasing')
41 if (self.vendor == 'gcc' and cxx.majorVersion >= 4) or self.vendor == 'clang':
42 self.compiler.AddToListVar('CFLAGS', '-fvisibility=hidden')
43 self.compiler.AddToListVar('CXXFLAGS', '-fvisibility-inlines-hidden')
44 self.compiler.AddToListVar('CFLAGS', '-Wall')
45 self.compiler.AddToListVar('CFLAGS', '-Werror')
46 self.compiler.AddToListVar('CFLAGS', '-Wno-switch')
48 if AMBuild.options.arch == 'x86':
49 self.compiler.AddToListVar('CFLAGS', '-m32')
50 self.compiler.AddToListVar('POSTLINKFLAGS', '-m32')
51 elif AMBuild.options.arch == 'x64':
52 self.compiler.AddToListVar('CFLAGS', '-m64')
53 self.compiler.AddToListVar('POSTLINKFLAGS', '-m64')
54 elif AMBuild.options.arch:
55 raise Exception('Unknown architecture: {0}'.format(AMBuild.options.arch))
57 # Disable some stuff we don't use, that gives us better binary
58 # compatibility on Linux.
59 self.compiler.AddToListVar('CXXFLAGS', '-fno-exceptions')
60 self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
61 self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
63 # We don't really care about these.
64 self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
65 self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
67 # The compiler is too aggressive about what what should be a valid offsetof.
68 self.compiler.AddToListVar('CXXFLAGS', '-Wno-invalid-offsetof')
70 # This would otherwise forbid ((x = y) == NULL) in clang apparently.
71 if self.vendor == 'clang':
72 self.compiler.AddToListVar('CXXFLAGS', '-Wno-null-arithmetic')
74 if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
75 (self.vendor == 'clang' and cxx.majorVersion >= 3):
76 self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
78 self.compiler.AddToListVar('POSTLINKFLAGS', '-lm')
79 elif isinstance(cxx, Cpp.MSVC):
81 if AMBuild.options.debug == '1':
82 self.compiler.AddToListVar('CFLAGS', '/MTd')
83 self.compiler.AddToListVar('POSTLINKFLAGS', '/NODEFAULTLIB:libcmt')
85 self.compiler.AddToListVar('CFLAGS', '/MT')
86 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_DEPRECATE')
87 self.compiler.AddToListVar('CDEFINES', '_CRT_SECURE_NO_WARNINGS')
88 self.compiler.AddToListVar('CDEFINES', '_CRT_NONSTDC_NO_DEPRECATE')
89 self.compiler.AddToListVar('CXXFLAGS', '/EHsc')
90 self.compiler.AddToListVar('CXXFLAGS', '/GR-')
91 self.compiler.AddToListVar('CFLAGS', '/W3')
92 self.compiler.AddToListVar('CFLAGS', '/nologo')
93 self.compiler.AddToListVar('CFLAGS', '/Zi')
94 self.compiler.AddToListVar('CXXFLAGS', '/TP')
95 self.compiler.AddToListVar('POSTLINKFLAGS', '/DEBUG')
97 # if AMBuild.options.arch == 'x86':
98 # self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X86')
99 # elif AMBuild.options.arch == 'x64':
100 # self.compiler.AddToListVar('POSTLINKFLAGS', '/MACHINE:X64')
101 # elif AMBuild.options.arch:
102 # raise Exception('Unknown architecture: {0}'.format(AMBuild.options.arch))
104 self.compiler.AddToListVar('POSTLINKFLAGS', 'kernel32.lib')
105 self.compiler.AddToListVar('POSTLINKFLAGS', 'user32.lib')
106 self.compiler.AddToListVar('POSTLINKFLAGS', 'gdi32.lib')
107 self.compiler.AddToListVar('POSTLINKFLAGS', 'winspool.lib')
108 self.compiler.AddToListVar('POSTLINKFLAGS', 'comdlg32.lib')
109 self.compiler.AddToListVar('POSTLINKFLAGS', 'advapi32.lib')
110 self.compiler.AddToListVar('POSTLINKFLAGS', 'shell32.lib')
111 self.compiler.AddToListVar('POSTLINKFLAGS', 'ole32.lib')
112 self.compiler.AddToListVar('POSTLINKFLAGS', 'oleaut32.lib')
113 self.compiler.AddToListVar('POSTLINKFLAGS', 'uuid.lib')
114 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbc32.lib')
115 self.compiler.AddToListVar('POSTLINKFLAGS', 'odbccp32.lib')
118 if AMBuild.options.opt == '1':
119 self.compiler.AddToListVar('CDEFINES', 'NDEBUG')
120 if self.vendor == 'gcc' or self.vendor == 'clang':
121 self.compiler.AddToListVar('CFLAGS', '-O3')
122 elif self.vendor == 'msvc':
123 self.compiler.AddToListVar('CFLAGS', '/Ox')
124 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:ICF')
125 self.compiler.AddToListVar('POSTLINKFLAGS', '/OPT:REF')
128 if AMBuild.options.debug == '1':
129 if self.vendor == 'gcc' or self.vendor == 'clang':
130 self.compiler.AddToListVar('CFLAGS', '-g3')
131 elif self.vendor == 'msvc':
132 self.compiler.AddToListVar('CFLAGS', '/Od')
133 self.compiler.AddToListVar('CFLAGS', '/RTC1')
136 if AMBuild.target['platform'] == 'linux':
137 self.compiler.AddToListVar('CDEFINES', '_LINUX')
138 if self.vendor == 'gcc':
139 self.compiler.AddToListVar('POSTLINKFLAGS', '-static-libgcc')
140 if self.vendor == 'clang':
141 self.compiler.AddToListVar('POSTLINKFLAGS', '-lgcc_eh')
142 elif AMBuild.target['platform'] == 'darwin':
143 self.compiler.AddToListVar('POSTLINKFLAGS', '-mmacosx-version-min=10.5')
144 if AMBuild.options.arch == 'x86':
145 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'i386'])
146 elif AMBuild.options.arch == 'x64':
147 self.compiler.AddToListVar('POSTLINKFLAGS', ['-arch', 'x86_64'])
148 self.compiler.AddToListVar('POSTLINKFLAGS', '-lstdc++')
150 # For OS X dylib versioning
152 productFile = open(os.path.join(AMBuild.sourceFolder, 'product.version'), 'r')
153 productContents = productFile.read()
155 m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
157 self.version = '1.0.0'
159 major, minor, release = m.groups()
160 self.version = '{0}.{1}.{2}'.format(major, minor, release)
161 AMBuild.cache.CacheVariable('version', self.version)
164 self.compiler.ToConfig(AMBuild, 'compiler')
165 AMBuild.cache.CacheVariable('vendor', self.vendor)
167 AMBuild.cache.CacheVariable('targetMap', self.targetMap)
169 self.compiler.FromConfig(AMBuild, 'compiler')
170 self.targetMap = AMBuild.cache['targetMap']
172 def DefaultCompiler(self):
173 return self.compiler.Clone()
175 def JobMatters(self, jobname):
176 file = sys._getframe().f_code.co_filename
177 if AMBuild.mode == 'config':
178 self.targetMap[jobname] = file
180 if len(AMBuild.args) == 0:
182 if not jobname in AMBuild.args:
191 ['src', 'AMBuild.library'],
192 ['src', 'AMBuild.shell'],
196 for parts in FileList:
197 AMBuild.Include(os.path.join(*parts), globals)