Bug 415080: Add Testcase (r=brbaker)
[tamarin-stm.git] / configure.py
blobe0243eb8749b3d9f350bd0600c2b3c6d5b9eca9e
1 #!/usr/bin/env python
2 # -*- Mode: Python; indent-tabs-mode: nil -*-
3 # vi: set ts=4 sw=4 expandtab:
4 # ***** BEGIN LICENSE BLOCK *****
5 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 # The contents of this file are subject to the Mozilla Public License Version
8 # 1.1 (the "License"); you may not use this file except in compliance with
9 # the License. You may obtain a copy of the License at
10 # http://www.mozilla.org/MPL/
12 # Software distributed under the License is distributed on an "AS IS" basis,
13 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 # for the specific language governing rights and limitations under the
15 # License.
17 # The Original Code is [Open Source Virtual Machine].
19 # The Initial Developer of the Original Code is
20 # Adobe System Incorporated.
21 # Portions created by the Initial Developer are Copyright (C) 2005-2006
22 # the Initial Developer. All Rights Reserved.
24 # Contributor(s):
26 # Alternatively, the contents of this file may be used under the terms of
27 # either the GNU General Public License Version 2 or later (the "GPL"), or
28 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 # in which case the provisions of the GPL or the LGPL are applicable instead
30 # of those above. If you wish to allow use of your version of this file only
31 # under the terms of either the GPL or the LGPL, and not to allow others to
32 # use your version of this file under the terms of the MPL, indicate your
33 # decision by deleting the provisions above and replace them with the notice
34 # and other provisions required by the GPL or the LGPL. If you do not delete
35 # the provisions above, a recipient may use your version of this file under
36 # the terms of any one of the MPL, the GPL or the LGPL.
38 # ***** END LICENSE BLOCK *****
41 # This script runs just like a traditional configure script, to do configuration
42 # testing and makefile generation.
44 import os
45 import os.path
46 import sys
47 import build.process
48 import re
50 thisdir = os.path.dirname(os.path.abspath(__file__))
52 # Look for additional modules in our build/ directory.
53 sys.path.append(thisdir)
55 from build.configuration import *
56 import build.getopt
57 import build.avmfeatures
59 o = build.getopt.Options()
61 config = Configuration(thisdir, options = o,
62 sourcefile = 'core/avmplus.h')
64 buildTamarin = o.getBoolArg('tamarin', True)
65 if buildTamarin:
66 config.subst("ENABLE_TAMARIN", 1)
68 buildShell = o.getBoolArg("shell", False)
69 if (buildShell):
70 config.subst("ENABLE_SHELL", 1)
73 APP_CPPFLAGS = "-DAVMSHELL_BUILD "
74 APP_CXXFLAGS = ""
75 APP_CFLAGS = ""
76 OPT_CXXFLAGS = "-O3 "
77 OPT_CPPFLAGS = ""
78 DEBUG_CPPFLAGS = "-DDEBUG -D_DEBUG "
79 DEBUG_CXXFLAGS = ""
80 DEBUG_CFLAGS = ""
81 DEBUG_LDFLAGS = ""
82 OS_LIBS = []
83 OS_LDFLAGS = ""
84 MMGC_CPPFLAGS = "-DAVMSHELL_BUILD "
85 AVMSHELL_CPPFLAGS = ""
86 AVMSHELL_LDFLAGS = ""
87 MMGC_DEFINES = {'SOFT_ASSERTS': None}
88 NSPR_INCLUDES = ""
89 NSPR_LDOPTS = ""
91 # See build/avmfeatures.py for the code that processes switches for
92 # standard feature names.
93 APP_CPPFLAGS += build.avmfeatures.featureSettings(o)
95 if not o.getBoolArg("methodenv-impl32", True):
96 APP_CPPFLAGS += "-DVMCFG_METHODENV_IMPL32=0 "
98 memoryProfiler = o.getBoolArg("memory-profiler", False)
99 if memoryProfiler:
100 APP_CPPFLAGS += "-DMMGC_MEMORY_PROFILER "
102 MMGC_INTERIOR_PTRS = o.getBoolArg('mmgc-interior-pointers', False)
103 if MMGC_INTERIOR_PTRS:
104 MMGC_DEFINES['MMGC_INTERIOR_PTRS'] = None
106 MMGC_DYNAMIC = o.getBoolArg('mmgc-shared', False)
107 if MMGC_DYNAMIC:
108 MMGC_DEFINES['MMGC_DLL'] = None
109 MMGC_CPPFLAGS += "-DMMGC_IMPL "
111 arm_fpu = o.getBoolArg("arm-fpu",False)
112 arm_neon = o.getBoolArg("arm-neon",False)
114 the_os, cpu = config.getTarget()
116 # For -Wreorder, see https://bugzilla.mozilla.org/show_bug.cgi?id=475750
117 if config.getCompiler() == 'GCC':
118 if 'CXX' in os.environ:
119 rawver = build.process.run_for_output(['$CXX', '--version'])
120 else:
121 rawver = build.process.run_for_output(['gcc', '--version'])
122 vre = re.compile(".* ([3-9]\.[0-9]+\.[0-9]+)[ \n]")
123 ver = vre.match(rawver).group(1)
124 ver_arr = ver.split('.')
125 GCC_MAJOR_VERSION = int(ver_arr[0])
126 GCC_MINOR_VERSION = int(ver_arr[1])
127 # can't enable -Werror for gcc prior to 4.3 due to unavoidable "clobbered" warnings in Interpreter.cpp
128 # warnings have been updated to try to include all those enabled by current Flash/AIR builds -- disable with caution, or risk integration pain
129 APP_CXXFLAGS = "-Wall -Wcast-align -Wdisabled-optimization -Wextra -Wformat=2 -Winit-self -Winvalid-pch -Wno-invalid-offsetof -Wno-switch -Wparentheses -Wpointer-arith -Wreorder -Wsign-compare -Wunused-parameter -Wwrite-strings -Wno-ctor-dtor-privacy -Woverloaded-virtual -Wsign-promo -Wno-char-subscripts -fmessage-length=0 -fno-exceptions -fno-rtti -fno-check-new -fstrict-aliasing -fsigned-char "
130 if GCC_MAJOR_VERSION >= 4:
131 APP_CXXFLAGS += "-Wstrict-null-sentinel "
132 if (GCC_MAJOR_VERSION == 4 and GCC_MINOR_VERSION <= 2) or cpu == 'mips': # 4.0 - 4.2
133 APP_CXXFLAGS += "-Wstrict-aliasing=0 "
134 else: # gcc 4.3 or later
135 APP_CXXFLAGS += "-Werror -Wempty-body -Wno-logical-op -Wmissing-field-initializers -Wstrict-aliasing=3 -Wno-array-bounds -Wno-clobbered -Wstrict-overflow=0 -funit-at-a-time "
136 if arm_fpu:
137 OPT_CXXFLAGS += "-mfloat-abi=softfp -mfpu=vfp -march=armv6 -Wno-cast-align " # compile to use hardware fpu and armv6
138 DEBUG_CXXFLAGS += OPT_CXXFLAGS
139 if arm_neon:
140 OPT_CXXFLAGS += "-mfloat-abi=softfp -mfpu=neon -march=armv7-a -Wno-cast-align " # compile to use neon vfp and armv7
141 DEBUG_CXXFLAGS += OPT_CXXFLAGS
142 if config.getDebug():
143 APP_CXXFLAGS += ""
144 else:
145 APP_CXXFLAGS += "-Wuninitialized "
146 DEBUG_CXXFLAGS += "-g "
147 elif config.getCompiler() == 'VS':
148 if cpu == "arm":
149 APP_CXXFLAGS = "-W4 -WX -wd4291 -wd4201 -wd4189 -wd4740 -wd4127 -fp:fast -GF -GS- -Zc:wchar_t- "
150 OS_LDFLAGS += "-MAP "
151 if config.getDebug():
152 DEBUG_CXXFLAGS = "-Od "
153 DEBUG_CFLAGS = "-Od "
154 APP_CXXFLAGS += "-GR- -fp:fast -GS- -Zc:wchar_t- -Zc:forScope "
155 else:
156 OPT_CXXFLAGS = "-O2 -GR- "
158 if arm_fpu:
159 OPT_CXXFLAGS += "-QRfpe- -QRarch6" # compile to use hardware fpu and armv6
160 else:
161 APP_CXXFLAGS = "-W4 -WX -wd4291 -GF -GS- -Zc:wchar_t- "
162 APP_CFLAGS = "-W4 -WX -wd4291 -GF -GS- -Zc:wchar_t- "
163 if cpu == 'x86_64':
164 pass # 64 bit VC does NaN comparisons incorrectly with fp:fast
165 else:
166 APP_CXXFLAGS += "-fp:fast "
167 APP_CFLAGS += "-fp:fast "
168 OS_LDFLAGS += "-SAFESEH:NO -MAP "
169 if config.getDebug():
170 DEBUG_CXXFLAGS = "-Od "
171 DEBUG_CFLAGS = "-Od "
172 else:
173 OPT_CXXFLAGS = "-O2 -Ob1 -GR- "
174 OPT_CFLAGS = "-O2 -Ob1 -GR- "
175 if memoryProfiler:
176 OPT_CXXFLAGS += "-Oy- -Zi "
177 DEBUG_CXXFLAGS += "-Zi "
178 DEBUG_CFLAGS += "-Zi "
179 DEBUG_LDFLAGS += "-DEBUG "
180 elif config.getCompiler() == 'SunStudio':
181 APP_CXXFLAGS = "-template=no%extdef -erroff=wvarhidemem"
182 OPT_CXXFLAGS = "-xO5 "
183 DEBUG_CXXFLAGS += "-g "
184 else:
185 raise Exception('Unrecognized compiler: ' + config.getCompiler())
187 zlib_include_dir = o.getStringArg('zlib-include-dir')
188 if zlib_include_dir is not None:
189 AVMSHELL_CPPFLAGS += "-I%s " % zlib_include_dir
191 zlib_lib = o.getStringArg('zlib-lib')
192 if zlib_lib is not None:
193 AVMSHELL_LDFLAGS = zlib_lib
194 else:
195 AVMSHELL_LDFLAGS = '$(call EXPAND_LIBNAME,zlib)'
197 sys_root_dir = o.getStringArg('sys-root-dir')
198 if sys_root_dir is not None:
199 OS_LDFLAGS += " --sysroot=%s " % sys_root_dir
200 OPT_CXXFLAGS += " --sysroot=%s " % sys_root_dir
202 if the_os == "darwin":
203 AVMSHELL_LDFLAGS += " -exported_symbols_list " + thisdir + "/platform/mac/avmshell/exports.exp"
204 MMGC_DEFINES.update({'TARGET_API_MAC_CARBON': 1,
205 'DARWIN': 1,
206 '_MAC': None,
207 'AVMPLUS_MAC': None,
208 'TARGET_RT_MAC_MACHO': 1})
209 APP_CXXFLAGS += "-fpascal-strings -faltivec -fasm-blocks "
210 if cpu == 'x86_64' or cpu == 'ppc64':
211 # 64-bit mac targets require the 10.5 sdk.
212 # Note that we don't override CC/CXX here; the calling script is expected to do that if desired
213 # (thus we can support 10.5sdk with either 4.0 or 4.2)
214 APP_CXXFLAGS += "-mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk "
215 config.subst("MACOSX_DEPLOYMENT_TARGET",10.5)
216 if cpu == 'x86_64':
217 APP_CXXFLAGS += "-arch x86_64 "
218 APP_CFLAGS += "-arch x86_64 "
219 OS_LDFLAGS += "-arch x86_64 "
220 else:
221 APP_CXXFLAGS += "-arch ppc64 "
222 APP_CFLAGS += "-arch ppc64 "
223 OS_LDFLAGS += "-arch ppc64 "
224 else:
225 APP_CXXFLAGS += "-mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk "
226 config.subst("MACOSX_DEPLOYMENT_TARGET",10.4)
227 elif the_os == "windows" or the_os == "cygwin":
228 MMGC_DEFINES.update({'WIN32': None,
229 '_CRT_SECURE_NO_DEPRECATE': None})
230 OS_LDFLAGS += "-MAP "
231 if cpu == "arm":
232 APP_CPPFLAGS += "-DARM -D_ARM_ -DUNICODE -DUNDER_CE=1 -DMMGC_ARM "
233 if arm_fpu:
234 APP_CPPFLAGS += "-DARMV6 -QRarch6 "
235 else:
236 APP_CPPFLAGS += "-DARMV5 -QRarch5t "
237 OS_LIBS.append('mmtimer corelibc coredll')
238 else:
239 APP_CPPFLAGS += "-DWIN32_LEAN_AND_MEAN -D_CONSOLE "
240 OS_LIBS.append('winmm')
241 OS_LIBS.append('shlwapi')
242 OS_LIBS.append('AdvAPI32')
243 elif the_os == "linux":
244 MMGC_DEFINES.update({'UNIX': None,
245 'AVMPLUS_UNIX': None})
246 OS_LIBS.append('pthread')
247 # if cpu == "x86_64":
248 # # workaround https://bugzilla.mozilla.org/show_bug.cgi?id=467776
249 # OPT_CXXFLAGS += '-fno-schedule-insns2 '
250 if config.getDebug():
251 OS_LIBS.append("dl")
252 elif the_os == "sunos":
253 if config.getCompiler() != 'GCC':
254 APP_CXXFLAGS = "-template=no%extdef -erroff=wvarhidemem"
255 OPT_CXXFLAGS = "-xO5 "
256 DEBUG_CXXFLAGS = "-g "
257 MMGC_DEFINES.update({'UNIX': None,
258 'AVMPLUS_UNIX': None,
259 'SOLARIS': None})
260 OS_LIBS.append('pthread')
261 APP_CPPFLAGS += '-DAVMPLUS_CDECL '
262 if config.getDebug():
263 OS_LIBS.append("dl")
264 else:
265 raise Exception("Unsupported OS")
267 if cpu == "i686":
268 if config.getCompiler() == 'GCC' and the_os == 'darwin':
269 #only mactel always has sse2
270 APP_CPPFLAGS += "-msse2 "
271 elif cpu == "powerpc":
272 # we detect this in core/avmbuild.h and MMgc/*build.h
273 None
274 elif cpu == "ppc64":
275 # we detect this in core/avmbuild.h and MMgc/*build.h
276 None
277 elif cpu == "sparc":
278 APP_CPPFLAGS += "-DAVMPLUS_SPARC "
279 elif cpu == "x86_64":
280 # we detect this in core/avmbuild.h and MMgc/*build.h
281 None
282 elif cpu == "arm":
283 # we detect this in core/avmbuild.h and MMgc/*build.h
284 None
285 elif cpu == "mips":
286 # we detect this in core/avmbuild.h and MMgc/*build.h
287 None
288 else:
289 raise Exception("Unsupported CPU")
291 if o.getBoolArg('perfm'):
292 APP_CPPFLAGS += "-DPERFM "
294 if o.help:
295 sys.stdout.write(o.getHelp())
296 sys.exit(1)
299 # We do two things with MMGC_DEFINES: we append it to APP_CPPFLAGS and we also write MMgc-config.h
300 APP_CPPFLAGS += ''.join(val is None and ('-D%s ' % var) or ('-D%s=%s ' % (var, val))
301 for (var, val) in MMGC_DEFINES.iteritems())
303 definePattern = \
304 """#ifndef %(var)s
305 #define %(var)s %(val)s
306 #endif
309 outpath = "%s/MMgc-config.h" % config.getObjDir()
310 contents = ''.join(definePattern % {'var': var,
311 'val': val is not None and val or ''}
312 for (var, val) in MMGC_DEFINES.iteritems())
313 writeFileIfChanged(outpath, contents)
315 config.subst("APP_CPPFLAGS", APP_CPPFLAGS)
316 config.subst("APP_CXXFLAGS", APP_CXXFLAGS)
317 config.subst("OPT_CPPFLAGS", OPT_CPPFLAGS)
318 config.subst("OPT_CXXFLAGS", OPT_CXXFLAGS)
319 config.subst("DEBUG_CPPFLAGS", DEBUG_CPPFLAGS)
320 config.subst("DEBUG_CXXFLAGS", DEBUG_CXXFLAGS)
321 config.subst("DEBUG_LDFLAGS", DEBUG_LDFLAGS)
322 config.subst("OS_LIBS", " ".join(OS_LIBS))
323 config.subst("OS_LDFLAGS", OS_LDFLAGS)
324 config.subst("MMGC_CPPFLAGS", MMGC_CPPFLAGS)
325 config.subst("AVMSHELL_CPPFLAGS", AVMSHELL_CPPFLAGS)
326 config.subst("AVMSHELL_LDFLAGS", AVMSHELL_LDFLAGS)
327 config.subst("MMGC_DYNAMIC", MMGC_DYNAMIC and 1 or '')
328 config.generate("Makefile")
330 o.finish()