1 # Copyright 2011 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are
6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided
11 # with the distribution.
12 # * Neither the name of Google Inc. nor the names of its
13 # contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 from os.path import join, dirname, abspath
34 from types import DictType, StringTypes
35 root_dir = dirname(File('SConstruct').rfile().abspath)
36 sys.path.insert(0, join(root_dir, 'tools'))
39 # ARM_TARGET_LIB is the path to the dynamic library to use on the target
40 # machine if cross-compiling to an arm machine. You will also need to set
41 # the additional cross-compiling environment variables to the cross compiler.
42 ARM_TARGET_LIB = os.environ.get('ARM_TARGET_LIB')
44 ARM_LINK_FLAGS = ['-Wl,-rpath=' + ARM_TARGET_LIB + '/lib:' +
45 ARM_TARGET_LIB + '/usr/lib',
46 '-Wl,--dynamic-linker=' + ARM_TARGET_LIB +
51 GCC_EXTRA_CCFLAGS = []
52 GCC_DTOA_EXTRA_CCFLAGS = []
56 'CPPPATH': [join(root_dir, 'src')],
57 'regexp:interpreted': {
58 'CPPDEFINES': ['V8_INTERPRETED_REGEXP']
61 'CPPDEFINES': ['V8_ENABLE_CHECKS', 'OBJECT_PRINT']
64 'CPPDEFINES': ['OBJECT_PRINT'],
66 'debuggersupport:on': {
67 'CPPDEFINES': ['ENABLE_DEBUGGER_SUPPORT'],
70 'CPPDEFINES': ['INSPECTOR'],
73 'CPPDEFINES': ['V8_NO_FAST_TLS'],
75 'liveobjectlist:on': {
76 'CPPDEFINES': ['ENABLE_DEBUGGER_SUPPORT', 'INSPECTOR',
77 'LIVE_OBJECT_LIST', 'OBJECT_PRINT'],
82 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
83 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
85 'visibility:hidden': {
86 # Use visibility=default to disable this.
87 'CXXFLAGS': ['-fvisibility=hidden']
89 'strictaliasing:off': {
90 'CCFLAGS': ['-fno-strict-aliasing']
93 'CCFLAGS': ['-g', '-O0'],
94 'CPPDEFINES': ['ENABLE_DISASSEMBLER', 'DEBUG'],
97 'CCFLAGS': ['-O3', '-fomit-frame-pointer', '-fdata-sections',
98 '-ffunction-sections'],
101 'CCFLAGS': ['-ansi'] + GCC_EXTRA_CCFLAGS,
103 'CPPDEFINES': ['V8_SHARED'],
108 'CCFLAGS': ['-ansi', '-mmacosx-version-min=10.4'],
110 'CPPDEFINES': ['V8_SHARED']
114 'CPPPATH' : ['/usr/local/include'],
115 'LIBPATH' : ['/usr/local/lib'],
116 'CCFLAGS': ['-ansi'],
120 'CPPPATH' : ['/usr/local/include'],
121 'LIBPATH' : ['/usr/local/lib'],
122 'CCFLAGS': ['-ansi'],
125 # On Solaris, to get isinf, INFINITY, fpclassify and other macros one
126 # needs to define __C99FEATURES__.
127 'CPPDEFINES': ['__C99FEATURES__'],
128 'CPPPATH' : ['/usr/local/include'],
129 'LIBPATH' : ['/usr/local/lib'],
130 'CCFLAGS': ['-ansi'],
133 'CCFLAGS': ['-DWIN32'],
134 'CXXFLAGS': ['-DWIN32'],
137 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'],
139 'LINKFLAGS': ['-m32']
142 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
143 'unalignedaccesses:on' : {
144 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=1']
146 'unalignedaccesses:off' : {
147 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=0']
150 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
152 'CCFLAGS': ['-mfloat-abi=soft'],
156 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
158 'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']
161 'CCFLAGS': ['-mfloat-abi=softfp'],
165 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=1'],
167 'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']
170 'CCFLAGS': ['-mfloat-abi=hard'],
176 'LINKFLAGS': ['-m32'],
179 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
180 'mips_arch_variant:mips32r2': {
181 'CPPDEFINES': ['_MIPS_ARCH_MIPS32R2']
185 'LINKFLAGS': ['-EL'],
186 'mips_arch_variant:mips32r2': {
187 'CCFLAGS': ['-mips32r2', '-Wa,-mips32r2']
189 'mips_arch_variant:mips32r1': {
190 'CCFLAGS': ['-mips32', '-Wa,-mips32']
193 'LINKFLAGS': ['-static', '-static-libgcc']
195 'mipsabi:softfloat': {
196 'CCFLAGS': ['-msoft-float'],
197 'LINKFLAGS': ['-msoft-float']
199 'mipsabi:hardfloat': {
200 'CCFLAGS': ['-mhard-float'],
201 'LINKFLAGS': ['-mhard-float']
207 'LINKFLAGS': ['-m32'],
208 'mipsabi:softfloat': {
209 'CPPDEFINES': ['__mips_soft_float=1'],
211 'mipsabi:hardfloat': {
212 'CPPDEFINES': ['__mips_hard_float=1'],
216 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
218 'LINKFLAGS': ['-m64'],
221 'CPPDEFINES': ['ENABLE_GDB_JIT_INTERFACE']
223 'compress_startup_data:bz2': {
224 'CPPDEFINES': ['COMPRESS_STARTUP_DATA_BZ2']
229 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
230 'CXXFLAGS': ['/GR-', '/Gy'],
231 'CPPDEFINES': ['WIN32'],
232 'LINKFLAGS': ['/INCREMENTAL:NO', '/NXCOMPAT', '/IGNORE:4221'],
233 'CCPDBFLAGS': ['/Zi']
236 'DIALECTFLAGS': ['/nologo'],
237 'ARFLAGS': ['/NOLOGO']
240 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', '_USE_32BIT_TIME_T'],
241 'LINKFLAGS': ['/MACHINE:X86'],
242 'ARFLAGS': ['/MACHINE:X86']
245 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
246 'LINKFLAGS': ['/MACHINE:X64'],
247 'ARFLAGS': ['/MACHINE:X64']
250 'CCFLAGS': ['/Od', '/Gm'],
251 'CPPDEFINES': ['_DEBUG', 'ENABLE_DISASSEMBLER', 'DEBUG'],
252 'LINKFLAGS': ['/DEBUG'],
262 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
271 'ARFLAGS': ['/LTCG'],
273 'LINKFLAGS': ['/LTCG'],
276 'LINKFLAGS': ['/LTCG:PGI']
279 'LINKFLAGS': ['/LTCG:PGO']
290 'WARNINGFLAGS': ['-Wall',
293 '-Wno-unused-parameter',
294 '-Wnon-virtual-dtor']
297 'WARNINGFLAGS': ['-pedantic',
299 '-Wno-pedantic-ms-format'],
301 'LIBS': ['winmm', 'ws2_32']
305 'WARNINGFLAGS': ['-pedantic'],
308 'LINKFLAGS': ['-Wl,-soname,${SONAME}']
313 'WARNINGFLAGS': ['-pedantic']
316 # This is to silence warnings about ABI changes that some versions of the
317 # CodeSourcery G++ tool chain produce for each occurrence of varargs.
318 'WARNINGFLAGS': ['-Wno-abi']
321 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
326 'WARNINGFLAGS': ['/W3', '/WX', '/wd4351', '/wd4355', '/wd4800']
329 'CPPDEFINES': ['BUILDING_V8_SHARED'],
330 'LIBS': ['winmm', 'ws2_32']
333 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
334 # /wd4996 is to silence the warning about sscanf
335 # used by the arm simulator.
336 'WARNINGFLAGS': ['/wd4996']
339 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
340 'mips_arch_variant:mips32r2': {
341 'CPPDEFINES': ['_MIPS_ARCH_MIPS32R2']
345 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
351 MKSNAPSHOT_EXTRA_FLAGS = {
360 'LIBS': ['execinfo', 'pthread']
363 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
367 'LIBS': ['execinfo', 'pthread']
370 'LIBS': ['winmm', 'ws2_32'],
372 'compress_startup_data:bz2': {
380 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
381 'LIBS': ['winmm', 'ws2_32']
390 'WARNINGFLAGS': ['-Werror', '-Wno-uninitialized'],
391 'CCFLAGS': GCC_DTOA_EXTRA_CCFLAGS
396 'WARNINGFLAGS': ['/WX', '/wd4018', '/wd4244']
402 CCTEST_EXTRA_FLAGS = {
404 'CPPPATH': [join(root_dir, 'src')],
406 'CPPDEFINES': ['USING_V8_SHARED']
411 'LIBPATH': [abspath('.')],
412 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
413 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
414 'LINKFLAGS': ['$CCFLAGS'],
418 'CCFLAGS': ['-Wno-unused-but-set-variable'],
424 'LIBS': ['execinfo', 'pthread']
427 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
431 'LIBS': ['execinfo', 'pthread']
434 'LIBS': ['winmm', 'ws2_32']
437 'LINKFLAGS': ARM_LINK_FLAGS
442 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
443 'LIBS': ['winmm', 'ws2_32']
446 'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
449 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
450 'LINKFLAGS': ['/STACK:2097152']
458 'CPPPATH': [join(abspath('.'), 'include')],
460 'CPPDEFINES': ['USING_V8_SHARED']
466 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
467 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
468 'LINKFLAGS': ['$CCFLAGS'],
477 'LIBPATH' : ['/usr/local/lib'],
478 'LIBS': ['execinfo', 'pthread']
481 # On Solaris, to get isinf, INFINITY, fpclassify and other macros one
482 # needs to define __C99FEATURES__.
483 'CPPDEFINES': ['__C99FEATURES__'],
484 'LIBPATH' : ['/usr/local/lib'],
485 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
489 'LIBPATH' : ['/usr/local/lib'],
490 'LIBS': ['execinfo', 'pthread']
493 'LIBS': ['winmm', 'ws2_32']
496 'LINKFLAGS': ARM_LINK_FLAGS,
498 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
500 'CCFLAGS': ['-mfloat-abi=soft'],
504 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
506 'CCFLAGS': ['-mfloat-abi=softfp'],
510 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=1'],
512 'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']
515 'CCFLAGS': ['-mfloat-abi=hard'],
521 'LINKFLAGS': ['-m32']
525 'LINKFLAGS': ['-m64']
528 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
529 'mips_arch_variant:mips32r2': {
530 'CPPDEFINES': ['_MIPS_ARCH_MIPS32R2']
534 'LINKFLAGS': ['-EL'],
535 'mips_arch_variant:mips32r2': {
536 'CCFLAGS': ['-mips32r2', '-Wa,-mips32r2']
538 'mips_arch_variant:mips32r1': {
539 'CCFLAGS': ['-mips32', '-Wa,-mips32']
542 'LINKFLAGS': ['-static', '-static-libgcc']
544 'mipsabi:softfloat': {
545 'CCFLAGS': ['-msoft-float'],
546 'LINKFLAGS': ['-msoft-float']
548 'mipsabi:hardfloat': {
549 'CCFLAGS': ['-mhard-float'],
550 'LINKFLAGS': ['-mhard-float']
556 'LINKFLAGS': ['-m32']
560 'LINKFLAGS': ['-m32']
566 'CCFLAGS': ['-g', '-O0'],
567 'CPPDEFINES': ['DEBUG']
569 'compress_startup_data:bz2': {
570 'CPPDEFINES': ['COMPRESS_STARTUP_DATA_BZ2'],
578 'LIBS': ['winmm', 'ws2_32']
581 'CCFLAGS': ['/nologo'],
582 'LINKFLAGS': ['/NOLOGO']
585 'LINKFLAGS': ['/VERBOSE']
588 'LINKFLAGS': ['/MAP']
592 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
602 'LINKFLAGS': ['/LTCG'],
606 'LINKFLAGS': ['/LTCG:PGI']
609 'LINKFLAGS': ['/LTCG:PGO']
613 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', 'WIN32'],
614 'LINKFLAGS': ['/MACHINE:X86']
617 'CPPDEFINES': ['V8_TARGET_ARCH_X64', 'WIN32'],
618 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2097152']
622 'LINKFLAGS': ['/DEBUG'],
623 'CPPDEFINES': ['DEBUG'],
637 'CPPPATH': [join(abspath('.'), 'include'), join(abspath('.'), 'src')],
639 'CPPDEFINES': ['USING_V8_SHARED']
645 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
646 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
647 'LINKFLAGS': ['$CCFLAGS'],
650 'LIBS': ['winmm', 'ws2_32']
653 'LINKFLAGS': ARM_LINK_FLAGS,
655 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
657 'CCFLAGS': ['-mfloat-abi=soft'],
662 'CCFLAGS': ['-mfloat-abi=softfp'],
667 'CCFLAGS': ['-mfloat-abi=hard'],
673 'LINKFLAGS': ['-m32']
677 'LINKFLAGS': ['-m64']
680 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
681 'mips_arch_variant:mips32r2': {
682 'CPPDEFINES': ['_MIPS_ARCH_MIPS32R2']
686 'LINKFLAGS': ['-EL'],
687 'mips_arch_variant:mips32r2': {
688 'CCFLAGS': ['-mips32r2', '-Wa,-mips32r2']
690 'mips_arch_variant:mips32r1': {
691 'CCFLAGS': ['-mips32', '-Wa,-mips32']
694 'LINKFLAGS': ['-static', '-static-libgcc']
696 'mipsabi:softfloat': {
697 'CCFLAGS': ['-msoft-float'],
698 'LINKFLAGS': ['-msoft-float']
700 'mipsabi:hardfloat': {
701 'CCFLAGS': ['-mhard-float'],
702 'LINKFLAGS': ['-mhard-float']
708 'LINKFLAGS': ['-m32']
712 'LINKFLAGS': ['-m32'],
713 'mipsabi:softfloat': {
714 'CPPDEFINES': ['__mips_soft_float=1'],
716 'mipsabi:hardfloat': {
717 'CPPDEFINES': ['__mips_hard_float=1'],
724 'CCFLAGS': ['-g', '-O0'],
725 'CPPDEFINES': ['DEBUG']
728 'LIBPATH' : ['/usr/local/lib'],
733 'LIBS': ['winmm', 'ws2_32']
736 'CCFLAGS': ['/nologo'],
737 'LINKFLAGS': ['/NOLOGO']
740 'LINKFLAGS': ['/VERBOSE']
743 'LINKFLAGS': ['/MAP']
747 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
757 'LINKFLAGS': ['/LTCG'],
761 'LINKFLAGS': ['/LTCG:PGI']
764 'LINKFLAGS': ['/LTCG:PGO']
768 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', 'WIN32'],
769 'LINKFLAGS': ['/MACHINE:X86']
772 'CPPDEFINES': ['V8_TARGET_ARCH_X64', 'WIN32'],
773 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2097152']
777 'LINKFLAGS': ['/DEBUG'],
778 'CPPDEFINES': ['DEBUG'],
793 'CPPDEFINES': ['V8_SHARED'],
800 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
801 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
802 'LINKFLAGS': ['$CCFLAGS'],
804 'console:readline': {
817 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
824 'LIBS': ['winmm', 'ws2_32'],
827 'LINKFLAGS': ARM_LINK_FLAGS
829 'compress_startup_data:bz2': {
830 'CPPDEFINES': ['COMPRESS_STARTUP_DATA_BZ2'],
838 'LIBS': ['winmm', 'ws2_32']
841 'CCFLAGS': ['/nologo'],
842 'LINKFLAGS': ['/NOLOGO']
845 'LINKFLAGS': ['/VERBOSE']
848 'LINKFLAGS': ['/MAP']
852 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
862 'LINKFLAGS': ['/LTCG'],
866 'LINKFLAGS': ['/LTCG:PGI']
869 'LINKFLAGS': ['/LTCG:PGO']
873 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', 'WIN32'],
874 'LINKFLAGS': ['/MACHINE:X86']
877 'CPPDEFINES': ['V8_TARGET_ARCH_X64', 'WIN32'],
878 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2097152']
882 'LINKFLAGS': ['/DEBUG'],
883 'CPPDEFINES': ['DEBUG'],
907 return utils.GuessOS()
911 return utils.GuessArchitecture()
914 def GuessToolchain(env):
918 elif 'msvc' in tools:
924 def GuessVisibility(env):
926 toolchain = env['toolchain'];
927 if (os == 'win32' or os == 'cygwin') and toolchain == 'gcc':
928 # MinGW / Cygwin can't do it.
930 elif os == 'solaris':
936 def GuessStrictAliasing(env):
937 # There seems to be a problem with gcc 4.5.x.
938 # See http://code.google.com/p/v8/issues/detail?id=884
939 # It can be worked around by disabling strict aliasing.
940 toolchain = env['toolchain'];
941 if toolchain == 'gcc':
942 env = Environment(tools=['gcc'])
943 # The gcc version should be available in env['CCVERSION'],
944 # but when scons detects msvc this value is not set.
945 version = subprocess.Popen([env['CC'], '-dumpversion'],
946 stdout=subprocess.PIPE).communicate()[0]
947 if version.find('4.5') == 0:
954 'values': ['arm', 'ia32', 'x64', 'mips'],
956 'help': 'the architecture to build for'
959 'values': ['freebsd', 'linux', 'macos', 'win32', 'openbsd', 'solaris', 'cygwin'],
961 'help': 'the os to build for'
964 'values': ['gcc', 'msvc'],
965 'guess': GuessToolchain,
966 'help': 'the toolchain to use'
972 'values': ['native', 'interpreted'],
974 'help': 'Whether to use native or interpreted regexp implementation'
977 'values': ['on', 'off', 'nobuild'],
979 'help': 'build using snapshots for faster start-up'
982 'values': ['on', 'off'],
984 'help': 'enable profiling of build target'
987 'values': ['on', 'off'],
989 'help': 'enable GDB JIT interface'
992 'values': ['static', 'shared'],
994 'help': 'the type of library to produce'
997 'values': ['on', 'off'],
999 'help': 'enable object printing'
1001 'profilingsupport': {
1002 'values': ['on', 'off'],
1004 'help': 'enable profiling of JavaScript code'
1006 'debuggersupport': {
1007 'values': ['on', 'off'],
1009 'help': 'enable debugging of JavaScript code'
1012 'values': ['on', 'off'],
1014 'help': 'enable inspector features'
1017 'values': ['on', 'off'],
1019 'help': 'enable live object list features in the debugger'
1022 'values': ['on', 'off'],
1024 'help': 'turn on setting soname for Linux shared library'
1027 'values': ['static', 'shared'],
1028 'default': 'static',
1029 'help': 'the type of Microsoft Visual C++ runtime library to use'
1032 'values': ['on', 'off'],
1034 'help': 'use Microsoft Visual C++ link-time code generation'
1037 'values': ['arm', 'mips', 'none'],
1039 'help': 'build with simulator'
1041 'unalignedaccesses': {
1042 'values': ['default', 'on', 'off'],
1043 'default': 'default',
1044 'help': 'set whether the ARM target supports unaligned accesses'
1047 'values': ['on', 'off'],
1049 'help': 'enable the disassembler to inspect generated code'
1052 'values': ['on', 'off'],
1054 'help': 'enable fast thread local storage support '
1055 '(if available on the current architecture/platform)'
1057 'sourcesignatures': {
1058 'values': ['MD5', 'timestamp'],
1060 'help': 'set how the build system detects file changes'
1063 'values': ['dumb', 'readline'],
1065 'help': 'the console to use for the d8 shell'
1068 'values': ['on', 'off'],
1070 'help': 'more output from compiler and linker'
1073 'values': ['default', 'hidden'],
1074 'guess': GuessVisibility,
1075 'help': 'shared library symbol visibility'
1078 'values': ['default', 'off'],
1079 'guess': GuessStrictAliasing,
1080 'help': 'assume strict aliasing while optimizing'
1083 'values': ['off', 'instrument', 'optimize'],
1085 'help': 'select profile guided optimization variant',
1088 'values': ['hard', 'softfp', 'soft'],
1089 'default': 'softfp',
1090 'help': 'generate calling conventiont according to selected ARM EABI variant'
1093 'values': ['hardfloat', 'softfloat', 'none'],
1094 'default': 'hardfloat',
1095 'help': 'generate calling conventiont according to selected mips ABI'
1097 'mips_arch_variant': {
1098 'values': ['mips32r2', 'mips32r1'],
1099 'default': 'mips32r2',
1100 'help': 'mips variant'
1102 'compress_startup_data': {
1103 'values': ['off', 'bz2'],
1105 'help': 'compress startup data (snapshot) [Linux only]'
1108 'values': ['on', 'off'],
1110 'help': 'use vfp3 instructions when building the snapshot [Arm only]'
1115 ALL_OPTIONS = dict(PLATFORM_OPTIONS, **SIMPLE_OPTIONS)
1118 def AddOptions(options, result):
1119 guess_env = Environment(options=result)
1120 for (name, option) in options.iteritems():
1121 if 'guess' in option:
1122 # Option has a guess function
1123 guess = option.get('guess')
1124 default = guess(guess_env)
1126 # Option has a fixed default
1127 default = option.get('default')
1128 help = '%s (%s)' % (option.get('help'), ", ".join(option['values']))
1129 result.Add(name, help, default)
1134 result.Add('mode', 'compilation mode (debug, release)', 'release')
1135 result.Add('sample', 'build sample (shell, process, lineprocessor)', '')
1136 result.Add('cache', 'directory to use for scons build cache', '')
1137 result.Add('env', 'override environment settings (NAME0:value0,NAME1:value1,...)', '')
1138 result.Add('importenv', 'import environment settings (NAME0,NAME1,...)', '')
1139 AddOptions(PLATFORM_OPTIONS, result)
1140 AddOptions(SIMPLE_OPTIONS, result)
1145 env = Environment(options=opts)
1147 toolchain = env['toolchain']
1148 if os == 'win32' and toolchain == 'gcc':
1150 elif os == 'win32' and toolchain == 'msvc':
1151 return ['msvc', 'mslink', 'mslib', 'msvs']
1156 def GetVersionComponents():
1157 MAJOR_VERSION_PATTERN = re.compile(r"#define\s+MAJOR_VERSION\s+(.*)")
1158 MINOR_VERSION_PATTERN = re.compile(r"#define\s+MINOR_VERSION\s+(.*)")
1159 BUILD_NUMBER_PATTERN = re.compile(r"#define\s+BUILD_NUMBER\s+(.*)")
1160 PATCH_LEVEL_PATTERN = re.compile(r"#define\s+PATCH_LEVEL\s+(.*)")
1162 patterns = [MAJOR_VERSION_PATTERN,
1163 MINOR_VERSION_PATTERN,
1164 BUILD_NUMBER_PATTERN,
1165 PATCH_LEVEL_PATTERN]
1167 source = open(join(root_dir, 'src', 'version.cc')).read()
1168 version_components = []
1169 for pattern in patterns:
1170 match = pattern.search(source)
1172 version_components.append(match.group(1).strip())
1174 version_components.append('0')
1176 return version_components
1180 version_components = GetVersionComponents()
1182 if version_components[len(version_components) - 1] == '0':
1183 version_components.pop()
1184 return '.'.join(version_components)
1187 def GetSpecificSONAME():
1188 SONAME_PATTERN = re.compile(r"#define\s+SONAME\s+\"(.*)\"")
1190 source = open(join(root_dir, 'src', 'version.cc')).read()
1191 match = SONAME_PATTERN.search(source)
1194 return match.group(1).strip()
1200 return [ s for s in str.split(",") if len(s) > 0 ]
1203 def IsLegal(env, option, values):
1205 for s in SplitList(str):
1207 Abort("Illegal value for option %s '%s'." % (option, s))
1212 def VerifyOptions(env):
1213 if not IsLegal(env, 'mode', ['debug', 'release']):
1215 if not IsLegal(env, 'sample', ["shell", "process", "lineprocessor"]):
1217 if not IsLegal(env, 'regexp', ["native", "interpreted"]):
1219 if env['os'] == 'win32' and env['library'] == 'shared' and env['prof'] == 'on':
1220 Abort("Profiling on windows only supported for static library.")
1221 if env['gdbjit'] == 'on' and ((env['os'] != 'linux' and env['os'] != 'macos') or (env['arch'] != 'ia32' and env['arch'] != 'x64' and env['arch'] != 'arm')):
1222 Abort("GDBJIT interface is supported only for Intel-compatible (ia32 or x64) Linux/OSX target.")
1223 if env['os'] == 'win32' and env['soname'] == 'on':
1224 Abort("Shared Object soname not applicable for Windows.")
1225 if env['soname'] == 'on' and env['library'] == 'static':
1226 Abort("Shared Object soname not applicable for static library.")
1227 if env['os'] != 'win32' and env['pgo'] != 'off':
1228 Abort("Profile guided optimization only supported on Windows.")
1229 if env['cache'] and not os.path.isdir(env['cache']):
1230 Abort("The specified cache directory does not exist.")
1231 if not (env['arch'] == 'arm' or env['simulator'] == 'arm') and ('unalignedaccesses' in ARGUMENTS):
1233 print env['simulator']
1234 Abort("Option unalignedaccesses only supported for the ARM architecture.")
1235 if env['os'] != 'linux' and env['compress_startup_data'] != 'off':
1236 Abort("Startup data compression is only available on Linux")
1237 for (name, option) in ALL_OPTIONS.iteritems():
1238 if (not name in env):
1239 message = ("A value for option %s must be specified (%s)." %
1240 (name, ", ".join(option['values'])))
1242 if not env[name] in option['values']:
1243 message = ("Unknown %s value '%s'. Possible values are (%s)." %
1244 (name, env[name], ", ".join(option['values'])))
1248 class BuildContext(object):
1250 def __init__(self, options, env_overrides, samples):
1251 self.library_targets = []
1252 self.mksnapshot_targets = []
1253 self.cctest_targets = []
1254 self.sample_targets = []
1255 self.d8_targets = []
1256 self.options = options
1257 self.env_overrides = env_overrides
1258 self.samples = samples
1259 self.preparser_targets = []
1260 self.use_snapshot = (options['snapshot'] != 'off')
1261 self.build_snapshot = (options['snapshot'] == 'on')
1264 def AddRelevantFlags(self, initial, flags):
1265 result = initial.copy()
1266 toolchain = self.options['toolchain']
1267 if toolchain in flags:
1268 self.AppendFlags(result, flags[toolchain].get('all'))
1269 for option in sorted(self.options.keys()):
1270 value = self.options[option]
1271 self.AppendFlags(result, flags[toolchain].get(option + ':' + value))
1272 self.AppendFlags(result, flags.get('all'))
1275 def AddRelevantSubFlags(self, options, flags):
1276 self.AppendFlags(options, flags.get('all'))
1277 for option in sorted(self.options.keys()):
1278 value = self.options[option]
1279 self.AppendFlags(options, flags.get(option + ':' + value))
1281 def GetRelevantSources(self, source):
1283 result += source.get('all', [])
1284 for (name, value) in self.options.iteritems():
1285 source_value = source.get(name + ':' + value, [])
1286 if type(source_value) == dict:
1287 result += self.GetRelevantSources(source_value)
1289 result += source_value
1290 return sorted(result)
1292 def AppendFlags(self, options, added):
1295 for (key, value) in added.iteritems():
1296 if key.find(':') != -1:
1297 self.AddRelevantSubFlags(options, { key: value })
1299 if not key in options:
1300 options[key] = value
1302 prefix = options[key]
1303 if isinstance(prefix, StringTypes): prefix = prefix.split()
1304 options[key] = prefix + value
1306 def ConfigureObject(self, env, input, **kw):
1307 if (kw.has_key('CPPPATH') and env.has_key('CPPPATH')):
1308 kw['CPPPATH'] += env['CPPPATH']
1309 if self.options['library'] == 'static':
1310 return env.StaticObject(input, **kw)
1312 return env.SharedObject(input, **kw)
1314 def ApplyEnvOverrides(self, env):
1315 if not self.env_overrides:
1317 if type(env['ENV']) == DictType:
1318 env['ENV'].update(**self.env_overrides)
1320 env['ENV'] = self.env_overrides
1323 def PostprocessOptions(options, os):
1324 # Adjust architecture if the simulator option has been set
1325 if (options['simulator'] != 'none') and (options['arch'] != options['simulator']):
1326 if 'arch' in ARGUMENTS:
1327 # Print a warning if arch has explicitly been set
1328 print "Warning: forcing architecture to match simulator (%s)" % options['simulator']
1329 options['arch'] = options['simulator']
1330 if (options['prof'] != 'off') and (options['profilingsupport'] == 'off'):
1331 # Print a warning if profiling is enabled without profiling support
1332 print "Warning: forcing profilingsupport on when prof is on"
1333 options['profilingsupport'] = 'on'
1334 if os == 'win32' and options['pgo'] != 'off' and options['msvcltcg'] == 'off':
1335 if 'msvcltcg' in ARGUMENTS:
1336 print "Warning: forcing msvcltcg on as it is required for pgo (%s)" % options['pgo']
1337 options['msvcltcg'] = 'on'
1338 if (options['mipsabi'] != 'none') and (options['arch'] != 'mips') and (options['simulator'] != 'mips'):
1339 options['mipsabi'] = 'none'
1340 if options['liveobjectlist'] == 'on':
1341 if (options['debuggersupport'] != 'on') or (options['mode'] == 'release'):
1342 # Print a warning that liveobjectlist will implicitly enable the debugger
1343 print "Warning: forcing debuggersupport on for liveobjectlist"
1344 options['debuggersupport'] = 'on'
1345 options['inspector'] = 'on'
1346 options['objectprint'] = 'on'
1349 def ParseEnvOverrides(arg, imports):
1350 # The environment overrides are in the format NAME0:value0,NAME1:value1,...
1351 # The environment imports are in the format NAME0,NAME1,...
1353 for var in imports.split(','):
1354 if var in os.environ:
1355 overrides[var] = os.environ[var]
1356 for override in arg.split(','):
1357 pos = override.find(':')
1360 overrides[override[:pos].strip()] = override[pos+1:].strip()
1364 def BuildSpecific(env, mode, env_overrides, tools):
1365 options = {'mode': mode}
1366 for option in ALL_OPTIONS:
1367 options[option] = env[option]
1368 PostprocessOptions(options, env['os'])
1370 context = BuildContext(options, env_overrides, samples=SplitList(env['sample']))
1372 # Remove variables which can't be imported from the user's external
1373 # environment into a construction environment.
1374 user_environ = os.environ.copy()
1376 del user_environ['ENV']
1380 library_flags = context.AddRelevantFlags(user_environ, LIBRARY_FLAGS)
1381 v8_flags = context.AddRelevantFlags(library_flags, V8_EXTRA_FLAGS)
1382 mksnapshot_flags = context.AddRelevantFlags(library_flags, MKSNAPSHOT_EXTRA_FLAGS)
1383 dtoa_flags = context.AddRelevantFlags(library_flags, DTOA_EXTRA_FLAGS)
1384 cctest_flags = context.AddRelevantFlags(v8_flags, CCTEST_EXTRA_FLAGS)
1385 sample_flags = context.AddRelevantFlags(user_environ, SAMPLE_FLAGS)
1386 preparser_flags = context.AddRelevantFlags(user_environ, PREPARSER_FLAGS)
1387 d8_flags = context.AddRelevantFlags(library_flags, D8_FLAGS)
1391 'mksnapshot': mksnapshot_flags,
1393 'cctest': cctest_flags,
1394 'sample': sample_flags,
1396 'preparser': preparser_flags
1399 # Generate library base name.
1401 suffix = SUFFIXES[target_id]
1402 library_name = 'v8' + suffix
1403 preparser_library_name = 'v8preparser' + suffix
1404 version = GetVersion()
1405 if context.options['soname'] == 'on':
1406 # When building shared object with SONAME version the library name.
1407 library_name += '-' + version
1409 # Generate library SONAME if required by the build.
1410 if context.options['soname'] == 'on':
1411 soname = GetSpecificSONAME()
1413 soname = 'lib' + library_name + '.so'
1414 env['SONAME'] = soname
1416 # Build the object files by invoking SCons recursively.
1417 d8_env = Environment(tools=tools)
1418 d8_env.Replace(**context.flags['d8'])
1419 (object_files, shell_files, mksnapshot, preparser_files) = env.SConscript(
1420 join('src', 'SConscript'),
1421 build_dir=join('obj', target_id),
1422 exports='context tools d8_env',
1426 context.mksnapshot_targets.append(mksnapshot)
1428 # Link the object files into a library.
1429 env.Replace(**context.flags['v8'])
1431 context.ApplyEnvOverrides(env)
1432 if context.options['library'] == 'static':
1433 library = env.StaticLibrary(library_name, object_files)
1434 preparser_library = env.StaticLibrary(preparser_library_name,
1437 # There seems to be a glitch in the way scons decides where to put
1438 # PDB files when compiling using MSVC so we specify it manually.
1439 # This should not affect any other platforms.
1440 pdb_name = library_name + '.dll.pdb'
1441 library = env.SharedLibrary(library_name, object_files, PDB=pdb_name)
1442 preparser_pdb_name = preparser_library_name + '.dll.pdb';
1443 preparser_soname = 'lib' + preparser_library_name + '.so';
1444 preparser_library = env.SharedLibrary(preparser_library_name,
1446 PDB=preparser_pdb_name,
1447 SONAME=preparser_soname)
1448 context.library_targets.append(library)
1449 context.library_targets.append(preparser_library)
1451 context.ApplyEnvOverrides(d8_env)
1452 if context.options['library'] == 'static':
1453 shell = d8_env.Program('d8' + suffix, object_files + shell_files)
1455 shell = d8_env.Program('d8' + suffix, shell_files)
1456 d8_env.Depends(shell, library)
1457 context.d8_targets.append(shell)
1459 for sample in context.samples:
1460 sample_env = Environment(tools=tools)
1461 sample_env.Replace(**context.flags['sample'])
1462 sample_env.Prepend(LIBS=[library_name])
1463 context.ApplyEnvOverrides(sample_env)
1464 sample_object = sample_env.SConscript(
1465 join('samples', 'SConscript'),
1466 build_dir=join('obj', 'sample', sample, target_id),
1467 exports='sample context tools',
1470 sample_name = sample + suffix
1471 sample_program = sample_env.Program(sample_name, sample_object)
1472 sample_env.Depends(sample_program, library)
1473 context.sample_targets.append(sample_program)
1475 cctest_env = env.Copy()
1476 cctest_env.Prepend(LIBS=[library_name])
1477 cctest_program = cctest_env.SConscript(
1478 join('test', 'cctest', 'SConscript'),
1479 build_dir=join('obj', 'test', target_id),
1480 exports='context object_files tools',
1483 context.cctest_targets.append(cctest_program)
1485 preparser_env = env.Copy()
1486 preparser_env.Replace(**context.flags['preparser'])
1487 preparser_env.Prepend(LIBS=[preparser_library_name])
1488 context.ApplyEnvOverrides(preparser_env)
1489 preparser_object = preparser_env.SConscript(
1490 join('preparser', 'SConscript'),
1491 build_dir=join('obj', 'preparser', target_id),
1492 exports='context tools',
1495 preparser_name = join('obj', 'preparser', target_id, 'preparser')
1496 preparser_program = preparser_env.Program(preparser_name, preparser_object);
1497 preparser_env.Depends(preparser_program, preparser_library)
1498 context.preparser_targets.append(preparser_program)
1505 tools = GetTools(opts)
1506 env = Environment(options=opts, tools=tools)
1508 Help(opts.GenerateHelpText(env))
1510 env_overrides = ParseEnvOverrides(env['env'], env['importenv'])
1512 SourceSignatures(env['sourcesignatures'])
1520 modes = SplitList(env['mode'])
1522 context = BuildSpecific(env.Copy(), mode, env_overrides, tools)
1523 libraries += context.library_targets
1524 mksnapshots += context.mksnapshot_targets
1525 cctests += context.cctest_targets
1526 samples += context.sample_targets
1527 preparsers += context.preparser_targets
1528 d8s += context.d8_targets
1530 env.Alias('library', libraries)
1531 env.Alias('mksnapshot', mksnapshots)
1532 env.Alias('cctests', cctests)
1533 env.Alias('sample', samples)
1534 env.Alias('d8', d8s)
1535 env.Alias('preparser', preparsers)
1538 env.Default('sample')
1540 env.Default('library')
1543 CacheDir(env['cache'])
1545 # We disable deprecation warnings because we need to be able to use
1546 # env.Copy without getting warnings for compatibility with older
1547 # version of scons. Also, there's a bug in some revisions that
1548 # doesn't allow this flag to be set, so we swallow any exceptions.
1551 SetOption('warn', 'no-deprecated')