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
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.
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.
51 thisdir
= os
.path
.dirname(os
.path
.abspath(__file__
))
53 # Look for additional modules in our build/ directory.
54 sys
.path
.append(thisdir
)
56 from build
.configuration
import *
58 import build
.avmfeatures
61 def _setSDKParams(sdk_version
,os_ver
):
63 # On 10.5/6 systems, and only if "--mac-sdk=104u" is passed in, compile for the 10.4u SDK and override CC/CXX (set in configuration.py) to use gcc/gxx 4.0.x
64 if sdk_version
== '104u':
65 os_ver
,sdk_number
= '10.4','10.4u'
66 config
._acvars
['CXX'] = 'g++-4.0'
67 config
._acvars
['CC'] = 'gcc-4.0'
68 elif sdk_version
== '105':
69 os_ver
,sdk_number
= '10.5','10.5'
70 elif sdk_version
== '106':
71 os_ver
,sdk_number
= '10.6','10.6'
72 # For future expansion
73 #elif sdk_version == '107':
74 #os_ver,sdk_number = '10.7','10.7'
76 print'Unknown SDK version -> %s. Expected values are 104u, 105 or 106.' % sdk_version
79 if not os
.path
.exists("/Developer/SDKs/MacOSX%s.sdk" % sdk_number
):
80 print'Could not find /Developer/SDKs/MacOSX%s.sdk' % sdk_number
83 return os_ver
,sdk_number
85 o
= build
.getopt
.Options()
87 config
= Configuration(thisdir
, options
= o
,
88 sourcefile
= 'core/avmplus.h')
90 buildTamarin
= o
.getBoolArg('tamarin', True)
92 config
.subst("ENABLE_TAMARIN", 1)
94 buildShell
= o
.getBoolArg("shell", False)
96 config
.subst("ENABLE_SHELL", 1)
99 APP_CPPFLAGS
= "-DAVMSHELL_BUILD "
102 OPT_CXXFLAGS
= "-O3 "
104 DEBUG_CPPFLAGS
= "-DDEBUG -D_DEBUG "
110 MMGC_CPPFLAGS
= "-DAVMSHELL_BUILD "
111 AVMSHELL_CPPFLAGS
= ""
112 AVMSHELL_LDFLAGS
= ""
113 MMGC_DEFINES
= {'SOFT_ASSERTS': None}
117 if 'APP_CPPFLAGS' in os
.environ
:
118 APP_CPPFLAGS
+= os
.environ
['APP_CPPFLAGS'] + " "
119 if 'APP_CXXFLAGS' in os
.environ
:
120 APP_CXXFLAGS
+= os
.environ
['APP_CXXFLAGS'] + " "
121 if 'APP_CFLAGS' in os
.environ
:
122 APP_CFLAGS
+= os
.environ
['APP_CFLAGS'] + " "
123 if 'OPT_CXXFLAGS' in os
.environ
:
124 OPT_CXXFLAGS
+= os
.environ
['OPT_CXXFLAGS'] + " "
125 if 'OPT_CPPFLAGS' in os
.environ
:
126 OPT_CPPFLAGS
+= os
.environ
['OPT_CPPFLAGS'] + " "
127 if 'DEBUG_CPPFLAGS' in os
.environ
:
128 DEBUG_CPPFLAGS
+= os
.environ
['DEBUG_CPPFLAGS'] + " "
129 if 'DEBUG_CXXFLAGS' in os
.environ
:
130 DEBUG_CXXFLAGS
+= os
.environ
['DEBUG_CXXFLAGS'] + " "
131 if 'DEBUG_CFLAGS' in os
.environ
:
132 DEBUG_CFLAGS
+= os
.environ
['DEBUG_CFLAGS'] + " "
133 if 'DEBUG_LDFLAGS' in os
.environ
:
134 DEBUG_LDFLAGS
+= os
.environ
['DEBUG_LDFLAGS'] + " "
135 if 'OS_LDFLAGS' in os
.environ
:
136 OS_LDFLAGS
+= os
.environ
['OS_LDFLAGS'] + " "
137 if 'MMGC_CPPFLAGS' in os
.environ
:
138 MMGC_CPPFLAGS
+= os
.environ
['MMGC_CPPFLAGS'] + " "
139 if 'AVMSHELL_CPPFLAGS' in os
.environ
:
140 AVMSHELL_CPPFLAGS
+= os
.environ
['AVMSHELL_CPPFLAGS'] + " "
141 if 'AVMSHELL_LDFLAGS' in os
.environ
:
142 AVMSHELL_LDFLAGS
+= os
.environ
['AVMSHELL_LDFLAGS'] + " "
143 if 'NSPR_INCLUDES' in os
.environ
:
144 NSPR_INCLUDES
+= os
.environ
['NSPR_INCLUDES'] + " "
145 if 'NSPR_LDOPTS' in os
.environ
:
146 NSPR_LDOPTS
+= os
.environ
['NSPR_LDOPTS'] + " "
147 if o
.getBoolArg('valgrind', False, False):
148 OPT_CXXFLAGS
= "-O1 -g "
150 valinc
= '$(topsrcdir)/other-licenses'
151 if 'VALGRIND_HOME' in os
.environ
:
152 valinc
= os
.environ
['VALGRIND_HOME'] + '/include'
153 APP_CPPFLAGS
+= '-I' + valinc
+ ' '
155 # See build/avmfeatures.py for the code that processes switches for
156 # standard feature names.
157 APP_CPPFLAGS
+= build
.avmfeatures
.featureSettings(o
)
159 if not o
.getBoolArg("methodenv-impl32", True):
160 APP_CPPFLAGS
+= "-DVMCFG_METHODENV_IMPL32=0 "
162 memoryProfiler
= o
.getBoolArg("memory-profiler", False)
164 APP_CPPFLAGS
+= "-DMMGC_MEMORY_PROFILER "
166 MMGC_INTERIOR_PTRS
= o
.getBoolArg('mmgc-interior-pointers', False)
167 if MMGC_INTERIOR_PTRS
:
168 MMGC_DEFINES
['MMGC_INTERIOR_PTRS'] = None
170 MMGC_DYNAMIC
= o
.getBoolArg('mmgc-shared', False)
172 MMGC_DEFINES
['MMGC_DLL'] = None
173 MMGC_CPPFLAGS
+= "-DMMGC_IMPL "
175 arm_fpu
= o
.getBoolArg("arm-fpu",False)
176 arm_neon
= o
.getBoolArg("arm-neon",False)
177 arm_arch
= o
.arm_arch
179 the_os
, cpu
= config
.getTarget()
181 # For -Wreorder, see https://bugzilla.mozilla.org/show_bug.cgi?id=475750
182 if config
.getCompiler() == 'GCC':
183 if 'CXX' in os
.environ
:
184 rawver
= build
.process
.run_for_output(['$CXX', '--version'])
186 rawver
= build
.process
.run_for_output(['gcc', '--version'])
187 vre
= re
.compile(".* ([3-9]\.[0-9]+\.[0-9]+)[ \n]")
188 ver
= vre
.match(rawver
).group(1)
189 ver_arr
= ver
.split('.')
190 GCC_MAJOR_VERSION
= int(ver_arr
[0])
191 GCC_MINOR_VERSION
= int(ver_arr
[1])
192 # can't enable -Werror for gcc prior to 4.3 due to unavoidable "clobbered" warnings in Interpreter.cpp
193 # warnings have been updated to try to include all those enabled by current Flash/AIR builds -- disable with caution, or risk integration pain
194 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 "
195 if GCC_MAJOR_VERSION
>= 4:
196 APP_CXXFLAGS
+= "-Wstrict-null-sentinel "
197 if (GCC_MAJOR_VERSION
== 4 and GCC_MINOR_VERSION
<= 2) or cpu
== 'mips': # 4.0 - 4.2
198 APP_CXXFLAGS
+= "-Wstrict-aliasing=0 "
199 else: # gcc 4.3 or later
200 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 "
202 APP_CXXFLAGS
+= "-mieee -Wno-cast-align "
205 ARM_FPU_FLAGS
= "-mfloat-abi=softfp -mfpu=vfp -march=%s -Wno-cast-align " % arm_arch
# compile to use hardware fpu
206 OPT_CXXFLAGS
+= ARM_FPU_FLAGS
207 DEBUG_CXXFLAGS
+= ARM_FPU_FLAGS
209 ARM_NEON_FLAGS
= "-mfloat-abi=softfp -mfpu=neon -march=%s -Wno-cast-align " % arm_arch
# compile to use neon vfp
210 OPT_CXXFLAGS
+= ARM_NEON_FLAGS
211 DEBUG_CXXFLAGS
+= ARM_NEON_FLAGS
213 #OPT_CXXFLAGS += "-march=%s " % arm_arch
214 #DEBUG_CXXFLAGS += "-march=%s " % arm_arch
216 if config
.getDebug():
219 APP_CXXFLAGS
+= "-Wuninitialized "
220 DEBUG_CXXFLAGS
+= "-g "
221 elif config
.getCompiler() == 'VS':
223 APP_CXXFLAGS
= "-W4 -WX -wd4291 -wd4201 -wd4189 -wd4740 -wd4127 -fp:fast -GF -GS- -Zc:wchar_t- "
224 OS_LDFLAGS
+= "-MAP "
225 if config
.getDebug():
226 DEBUG_CXXFLAGS
= "-Od "
227 DEBUG_CFLAGS
= "-Od "
228 APP_CXXFLAGS
+= "-GR- -fp:fast -GS- -Zc:wchar_t- -Zc:forScope "
230 OPT_CXXFLAGS
= "-O2 -GR- "
232 OPT_CXXFLAGS
+= "-QR%s " % arm_arch
234 OPT_CXXFLAGS
+= "-QRfpe- " # compile to use hardware fpu
236 APP_CXXFLAGS
= "-W4 -WX -wd4291 -GF -GS- -Zc:wchar_t- "
237 APP_CFLAGS
= "-W4 -WX -wd4291 -GF -GS- -Zc:wchar_t- "
239 pass # 64 bit VC does NaN comparisons incorrectly with fp:fast
241 APP_CXXFLAGS
+= "-fp:fast "
242 APP_CFLAGS
+= "-fp:fast "
243 OS_LDFLAGS
+= "-MAP "
244 if config
.getDebug():
245 DEBUG_CXXFLAGS
= "-Od "
246 DEBUG_CFLAGS
= "-Od "
248 OPT_CXXFLAGS
= "-O2 -Ob1 -GR- "
249 OPT_CFLAGS
= "-O2 -Ob1 -GR- "
251 OPT_CXXFLAGS
+= "-Oy- -Zi "
252 DEBUG_CXXFLAGS
+= "-Zi "
253 DEBUG_CFLAGS
+= "-Zi "
254 DEBUG_LDFLAGS
+= "-DEBUG "
255 elif config
.getCompiler() == 'SunStudio':
256 APP_CXXFLAGS
= "-template=no%extdef -erroff"
257 OPT_CXXFLAGS
= "-xO2 "
258 DEBUG_CXXFLAGS
+= "-g "
260 raise Exception('Unrecognized compiler: ' + config
.getCompiler())
262 zlib_include_dir
= o
.getStringArg('zlib-include-dir')
263 if zlib_include_dir
is not None:
264 AVMSHELL_CPPFLAGS
+= "-I%s " % zlib_include_dir
266 zlib_lib
= o
.getStringArg('zlib-lib')
267 if zlib_lib
is not None:
268 AVMSHELL_LDFLAGS
= zlib_lib
270 AVMSHELL_LDFLAGS
= '$(call EXPAND_LIBNAME,zlib)'
272 sys_root_dir
= o
.getStringArg('sys-root-dir')
273 if sys_root_dir
is not None:
274 OS_LDFLAGS
+= " --sysroot=%s " % sys_root_dir
275 OPT_CXXFLAGS
+= " --sysroot=%s " % sys_root_dir
277 if the_os
== "darwin":
278 # Get machine's OS version number and trim off anything after '10.x'
279 p
= subprocess
.Popen('sw_vers -productVersion', shell
=True, stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
280 os_ver
= p
.stdout
.read()
281 parts
= os_ver
.split('.')
282 os_ver
= parts
[0] + '.' + parts
[1]
284 AVMSHELL_LDFLAGS
+= " -exported_symbols_list " + thisdir
+ "/platform/mac/avmshell/exports.exp"
285 MMGC_DEFINES
.update({'TARGET_API_MAC_CARBON': 1,
289 'TARGET_RT_MAC_MACHO': 1})
290 APP_CXXFLAGS
+= "-fpascal-strings -faltivec -fasm-blocks "
292 # If an sdk is selected align OS and gcc/g++ versions to it
293 if o
.mac_sdk_version
is not None:
294 os_ver
,sdk_number
= _setSDKParams(o
.mac_sdk_version
, os_ver
)
295 APP_CXXFLAGS
+= "-mmacosx-version-min=%s -isysroot /Developer/SDKs/MACOSX%s.sdk " % (os_ver
,sdk_number
)
297 APP_CXXFLAGS
+= "-mmacosx-version-min=%s " % os_ver
299 config
.subst("MACOSX_DEPLOYMENT_TARGET",os_ver
)
302 APP_CXXFLAGS
+= "-arch ppc64 "
303 APP_CFLAGS
+= "-arch ppc64 "
304 OS_LDFLAGS
+= "-arch ppc64 "
305 elif cpu
== 'x86_64':
306 APP_CXXFLAGS
+= "-arch x86_64 "
307 APP_CFLAGS
+= "-arch x86_64 "
308 OS_LDFLAGS
+= "-arch x86_64 "
310 elif the_os
== "windows" or the_os
== "cygwin":
311 MMGC_DEFINES
.update({'WIN32': None,
312 '_CRT_SECURE_NO_DEPRECATE': None})
313 OS_LDFLAGS
+= "-MAP "
315 APP_CPPFLAGS
+= "-DARM -D_ARM_ -DUNICODE -DUNDER_CE=1 -DMMGC_ARM "
317 APP_CPPFLAGS
+= "-DARMV6 -QRarch6 "
319 APP_CPPFLAGS
+= "-DARMV5 -QRarch5t "
320 OS_LIBS
.append('mmtimer corelibc coredll')
322 APP_CPPFLAGS
+= "-DWIN32_LEAN_AND_MEAN -D_CONSOLE "
323 OS_LIBS
.append('winmm')
324 OS_LIBS
.append('shlwapi')
325 OS_LIBS
.append('AdvAPI32')
326 elif the_os
== "linux":
327 MMGC_DEFINES
.update({'UNIX': None,
328 'AVMPLUS_UNIX': None})
329 OS_LIBS
.append('pthread')
330 # if cpu == "x86_64":
331 # # workaround https://bugzilla.mozilla.org/show_bug.cgi?id=467776
332 # OPT_CXXFLAGS += '-fno-schedule-insns2 '
333 if config
.getDebug():
335 elif the_os
== "sunos":
336 if config
.getCompiler() != 'GCC':
337 APP_CXXFLAGS
= "-template=no%extdef -erroff"
338 OPT_CXXFLAGS
= "-xO2 "
339 DEBUG_CXXFLAGS
= "-g "
340 MMGC_DEFINES
.update({'UNIX': None,
341 'AVMPLUS_UNIX': None,
343 OS_LIBS
.append('pthread')
344 APP_CPPFLAGS
+= '-DAVMPLUS_CDECL '
345 if config
.getDebug():
348 raise Exception("Unsupported OS")
351 if config
.getCompiler() == 'GCC' and the_os
== 'darwin':
352 #only mactel always has sse2
353 APP_CPPFLAGS
+= "-msse2 "
354 elif cpu
== "powerpc":
355 # we detect this in core/avmbuild.h and MMgc/*build.h
358 # we detect this in core/avmbuild.h and MMgc/*build.h
361 APP_CPPFLAGS
+= "-DAVMPLUS_SPARC "
362 elif cpu
== "x86_64":
363 # we detect this in core/avmbuild.h and MMgc/*build.h
366 # we detect this in core/avmbuild.h and MMgc/*build.h
369 # we detect this in core/avmbuild.h and MMgc/*build.h
372 # work around for a problem with tas.b instruction on some sh4 boards
373 APP_CPPFLAGS
+= "-DUSE_PTHREAD_MUTEX "
375 raise Exception("Unsupported CPU")
377 if o
.getBoolArg('perfm'):
378 APP_CPPFLAGS
+= "-DPERFM "
381 sys
.stdout
.write(o
.getHelp())
385 # We do two things with MMGC_DEFINES: we append it to APP_CPPFLAGS and we also write MMgc-config.h
386 APP_CPPFLAGS
+= ''.join(val
is None and ('-D%s ' % var
) or ('-D%s=%s ' % (var
, val
))
387 for (var
, val
) in MMGC_DEFINES
.iteritems())
391 #define %(var)s %(val)s
395 outpath
= "%s/MMgc-config.h" % config
.getObjDir()
396 contents
= ''.join(definePattern
% {'var': var
,
397 'val': val
is not None and val
or ''}
398 for (var
, val
) in MMGC_DEFINES
.iteritems())
399 writeFileIfChanged(outpath
, contents
)
401 config
.subst("APP_CPPFLAGS", APP_CPPFLAGS
)
402 config
.subst("APP_CXXFLAGS", APP_CXXFLAGS
)
403 config
.subst("OPT_CPPFLAGS", OPT_CPPFLAGS
)
404 config
.subst("OPT_CXXFLAGS", OPT_CXXFLAGS
)
405 config
.subst("DEBUG_CPPFLAGS", DEBUG_CPPFLAGS
)
406 config
.subst("DEBUG_CXXFLAGS", DEBUG_CXXFLAGS
)
407 config
.subst("DEBUG_LDFLAGS", DEBUG_LDFLAGS
)
408 config
.subst("OS_LIBS", " ".join(OS_LIBS
))
409 config
.subst("OS_LDFLAGS", OS_LDFLAGS
)
410 config
.subst("MMGC_CPPFLAGS", MMGC_CPPFLAGS
)
411 config
.subst("AVMSHELL_CPPFLAGS", AVMSHELL_CPPFLAGS
)
412 config
.subst("AVMSHELL_LDFLAGS", AVMSHELL_LDFLAGS
)
413 config
.subst("MMGC_DYNAMIC", MMGC_DYNAMIC
and 1 or '')
414 config
.generate("Makefile")