1 # Copyright 2012 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 src_dir = join(root_dir, 'src')
37 sys.path.insert(0, join(root_dir, 'tools'))
40 # ARM_TARGET_LIB is the path to the dynamic library to use on the target
41 # machine if cross-compiling to an arm machine. You will also need to set
42 # the additional cross-compiling environment variables to the cross compiler.
43 ARM_TARGET_LIB = os.environ.get('ARM_TARGET_LIB')
45 ARM_LINK_FLAGS = ['-Wl,-rpath=' + ARM_TARGET_LIB + '/lib:' +
46 ARM_TARGET_LIB + '/usr/lib',
47 '-Wl,--dynamic-linker=' + ARM_TARGET_LIB +
52 GCC_EXTRA_CCFLAGS = []
53 GCC_DTOA_EXTRA_CCFLAGS = []
58 'regexp:interpreted': {
59 'CPPDEFINES': ['V8_INTERPRETED_REGEXP']
62 'CPPDEFINES': ['V8_ENABLE_CHECKS', 'OBJECT_PRINT']
65 'CPPDEFINES': ['OBJECT_PRINT'],
67 'debuggersupport:on': {
68 'CPPDEFINES': ['ENABLE_DEBUGGER_SUPPORT'],
71 'CPPDEFINES': ['INSPECTOR'],
74 'CPPDEFINES': ['V8_NO_FAST_TLS'],
76 'liveobjectlist:on': {
77 'CPPDEFINES': ['ENABLE_DEBUGGER_SUPPORT', 'INSPECTOR',
78 'LIVE_OBJECT_LIST', 'OBJECT_PRINT'],
83 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
84 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
86 'visibility:hidden': {
87 # Use visibility=default to disable this.
88 'CXXFLAGS': ['-fvisibility=hidden']
90 'strictaliasing:off': {
91 'CCFLAGS': ['-fno-strict-aliasing']
94 'CCFLAGS': ['-g', '-O0'],
95 'CPPDEFINES': ['ENABLE_DISASSEMBLER', 'DEBUG'],
98 'CCFLAGS': ['-O3', '-fomit-frame-pointer', '-fdata-sections',
99 '-ffunction-sections'],
102 'CCFLAGS': ['-ansi'] + GCC_EXTRA_CCFLAGS,
104 'CPPDEFINES': ['V8_SHARED'],
109 'CCFLAGS': ['-ansi', '-mmacosx-version-min=10.4'],
111 'CPPDEFINES': ['V8_SHARED']
115 'CPPPATH' : [src_dir, '/usr/local/include'],
116 'LIBPATH' : ['/usr/local/lib'],
117 'CCFLAGS': ['-ansi'],
121 'CPPPATH' : [src_dir, '/usr/local/include'],
122 'LIBPATH' : ['/usr/local/lib'],
123 'CCFLAGS': ['-ansi'],
126 # On Solaris, to get isinf, INFINITY, fpclassify and other macros one
127 # needs to define __C99FEATURES__.
128 'CPPDEFINES': ['__C99FEATURES__'],
129 'CPPPATH' : [src_dir, '/usr/local/include'],
130 'LIBPATH' : ['/usr/local/lib'],
131 'CCFLAGS': ['-ansi'],
134 'CPPPATH' : [src_dir, '/usr/pkg/include'],
135 'LIBPATH' : ['/usr/pkg/lib'],
138 'CCFLAGS': ['-DWIN32'],
139 'CXXFLAGS': ['-DWIN32'],
142 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'],
144 'LINKFLAGS': ['-m32']
147 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
148 'unalignedaccesses:on' : {
149 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=1']
151 'unalignedaccesses:off' : {
152 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=0']
155 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
157 'CCFLAGS': ['-mfloat-abi=soft'],
161 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
163 'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']
166 'CCFLAGS': ['-mfloat-abi=softfp'],
170 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=1'],
172 'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']
175 'CCFLAGS': ['-mfloat-abi=hard'],
181 'LINKFLAGS': ['-m32'],
184 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
185 'mips_arch_variant:mips32r2': {
186 'CPPDEFINES': ['_MIPS_ARCH_MIPS32R2']
188 'mips_arch_variant:loongson': {
189 'CPPDEFINES': ['_MIPS_ARCH_LOONGSON']
193 'LINKFLAGS': ['-EL'],
194 'mips_arch_variant:mips32r2': {
195 'CCFLAGS': ['-mips32r2', '-Wa,-mips32r2']
197 'mips_arch_variant:mips32r1': {
198 'CCFLAGS': ['-mips32', '-Wa,-mips32']
200 'mips_arch_variant:loongson': {
201 'CCFLAGS': ['-march=mips3', '-Wa,-march=mips3']
204 'LINKFLAGS': ['-static', '-static-libgcc']
206 'mipsabi:softfloat': {
207 'CCFLAGS': ['-msoft-float'],
208 'LINKFLAGS': ['-msoft-float']
210 'mipsabi:hardfloat': {
211 'CCFLAGS': ['-mhard-float'],
212 'LINKFLAGS': ['-mhard-float']
218 'LINKFLAGS': ['-m32'],
219 'mipsabi:softfloat': {
220 'CPPDEFINES': ['__mips_soft_float=1'],
222 'CPPDEFINES' : ['CAN_USE_FPU_INSTRUCTIONS']
225 'mipsabi:hardfloat': {
226 'CPPDEFINES': ['__mips_hard_float=1', 'CAN_USE_FPU_INSTRUCTIONS'],
230 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
232 'LINKFLAGS': ['-m64'],
235 'CPPDEFINES': ['ENABLE_GDB_JIT_INTERFACE']
237 'compress_startup_data:bz2': {
238 'CPPDEFINES': ['COMPRESS_STARTUP_DATA_BZ2']
243 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
244 'CXXFLAGS': ['/GR-', '/Gy'],
245 'CPPDEFINES': ['WIN32'],
246 'LINKFLAGS': ['/INCREMENTAL:NO', '/NXCOMPAT', '/IGNORE:4221'],
247 'CCPDBFLAGS': ['/Zi']
250 'DIALECTFLAGS': ['/nologo'],
251 'ARFLAGS': ['/NOLOGO']
254 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', '_USE_32BIT_TIME_T'],
255 'LINKFLAGS': ['/MACHINE:X86'],
256 'ARFLAGS': ['/MACHINE:X86']
259 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
260 'LINKFLAGS': ['/MACHINE:X64'],
261 'ARFLAGS': ['/MACHINE:X64']
264 'CCFLAGS': ['/Od', '/Gm'],
265 'CPPDEFINES': ['_DEBUG', 'ENABLE_DISASSEMBLER', 'DEBUG'],
266 'LINKFLAGS': ['/DEBUG'],
276 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
285 'ARFLAGS': ['/LTCG'],
287 'LINKFLAGS': ['/LTCG'],
290 'LINKFLAGS': ['/LTCG:PGI']
293 'LINKFLAGS': ['/LTCG:PGO']
304 'WARNINGFLAGS': ['-Wall',
307 '-Wno-unused-parameter',
308 '-Woverloaded-virtual',
309 '-Wnon-virtual-dtor']
312 'WARNINGFLAGS': ['-pedantic',
314 '-Wno-pedantic-ms-format'],
316 'LIBS': ['winmm', 'ws2_32']
320 'WARNINGFLAGS': ['-pedantic'],
323 'LINKFLAGS': ['-Wl,-soname,${SONAME}']
328 'WARNINGFLAGS': ['-pedantic']
331 # This is to silence warnings about ABI changes that some versions of the
332 # CodeSourcery G++ tool chain produce for each occurrence of varargs.
333 'WARNINGFLAGS': ['-Wno-abi']
336 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
341 'WARNINGFLAGS': ['/W3', '/WX', '/wd4351', '/wd4355', '/wd4800']
344 'CPPDEFINES': ['BUILDING_V8_SHARED'],
345 'LIBS': ['winmm', 'ws2_32']
348 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
349 # /wd4996 is to silence the warning about sscanf
350 # used by the arm simulator.
351 'WARNINGFLAGS': ['/wd4996']
354 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
355 'mips_arch_variant:mips32r2': {
356 'CPPDEFINES': ['_MIPS_ARCH_MIPS32R2']
360 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
366 MKSNAPSHOT_EXTRA_FLAGS = {
375 'LIBS': ['execinfo', 'pthread']
378 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
382 'LIBS': ['execinfo', 'pthread']
385 'LIBS': ['winmm', 'ws2_32'],
388 'LIBS': ['execinfo', 'pthread']
390 'compress_startup_data:bz2': {
398 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
399 'LIBS': ['winmm', 'ws2_32']
408 'WARNINGFLAGS': ['-Werror', '-Wno-uninitialized'],
409 'CCFLAGS': GCC_DTOA_EXTRA_CCFLAGS
414 'WARNINGFLAGS': ['/WX', '/wd4018', '/wd4244']
420 CCTEST_EXTRA_FLAGS = {
422 'CPPPATH': [src_dir],
424 'CPPDEFINES': ['USING_V8_SHARED']
429 'LIBPATH': [abspath('.')],
430 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
431 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
432 'LINKFLAGS': ['$CCFLAGS'],
436 'CCFLAGS': ['-Wno-unused-but-set-variable'],
442 'LIBS': ['execinfo', 'pthread']
445 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
449 'LIBS': ['execinfo', 'pthread']
452 'LIBS': ['winmm', 'ws2_32']
455 'LIBS': ['execinfo', 'pthread']
458 'LINKFLAGS': ARM_LINK_FLAGS
463 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
464 'LIBS': ['winmm', 'ws2_32']
467 'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
470 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
471 'LINKFLAGS': ['/STACK:2097152']
479 'CPPPATH': [join(root_dir, 'include')],
481 'CPPDEFINES': ['USING_V8_SHARED']
487 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
488 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
489 'LINKFLAGS': ['$CCFLAGS'],
498 'LIBPATH' : ['/usr/local/lib'],
499 'LIBS': ['execinfo', 'pthread']
502 # On Solaris, to get isinf, INFINITY, fpclassify and other macros one
503 # needs to define __C99FEATURES__.
504 'CPPDEFINES': ['__C99FEATURES__'],
505 'LIBPATH' : ['/usr/local/lib'],
506 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
510 'LIBPATH' : ['/usr/local/lib'],
511 'LIBS': ['execinfo', 'pthread']
514 'LIBS': ['winmm', 'ws2_32']
517 'LIBPATH' : ['/usr/pkg/lib'],
518 'LIBS': ['execinfo', 'pthread']
521 'LINKFLAGS': ARM_LINK_FLAGS,
523 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
525 'CCFLAGS': ['-mfloat-abi=soft'],
529 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
531 'CCFLAGS': ['-mfloat-abi=softfp'],
535 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=1'],
537 'CPPDEFINES' : ['CAN_USE_VFP_INSTRUCTIONS']
540 'CCFLAGS': ['-mfloat-abi=hard'],
546 'LINKFLAGS': ['-m32']
550 'LINKFLAGS': ['-m64']
553 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
554 'mips_arch_variant:mips32r2': {
555 'CPPDEFINES': ['_MIPS_ARCH_MIPS32R2']
557 'mips_arch_variant:loongson': {
558 'CPPDEFINES': ['_MIPS_ARCH_LOONGSON']
562 'LINKFLAGS': ['-EL'],
563 'mips_arch_variant:mips32r2': {
564 'CCFLAGS': ['-mips32r2', '-Wa,-mips32r2']
566 'mips_arch_variant:mips32r1': {
567 'CCFLAGS': ['-mips32', '-Wa,-mips32']
569 'mips_arch_variant:loongson': {
570 'CCFLAGS': ['-march=mips3', '-Wa,-march=mips3']
573 'LINKFLAGS': ['-static', '-static-libgcc']
575 'mipsabi:softfloat': {
576 'CCFLAGS': ['-msoft-float'],
577 'LINKFLAGS': ['-msoft-float']
579 'mipsabi:hardfloat': {
580 'CCFLAGS': ['-mhard-float'],
581 'LINKFLAGS': ['-mhard-float'],
583 'CPPDEFINES' : ['CAN_USE_FPU_INSTRUCTIONS']
590 'LINKFLAGS': ['-m32']
594 'LINKFLAGS': ['-m32']
600 'CCFLAGS': ['-g', '-O0'],
601 'CPPDEFINES': ['DEBUG']
603 'compress_startup_data:bz2': {
604 'CPPDEFINES': ['COMPRESS_STARTUP_DATA_BZ2'],
612 'LIBS': ['winmm', 'ws2_32']
615 'CCFLAGS': ['/nologo'],
616 'LINKFLAGS': ['/NOLOGO']
619 'LINKFLAGS': ['/VERBOSE']
622 'LINKFLAGS': ['/MAP']
626 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
636 'LINKFLAGS': ['/LTCG'],
640 'LINKFLAGS': ['/LTCG:PGI']
643 'LINKFLAGS': ['/LTCG:PGO']
647 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', 'WIN32'],
648 'LINKFLAGS': ['/MACHINE:X86']
651 'CPPDEFINES': ['V8_TARGET_ARCH_X64', 'WIN32'],
652 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2097152']
656 'LINKFLAGS': ['/DEBUG'],
657 'CPPDEFINES': ['DEBUG'],
671 'CPPPATH': [join(root_dir, 'include'), src_dir],
673 'CPPDEFINES': ['USING_V8_SHARED']
679 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
680 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
681 'LINKFLAGS': ['$CCFLAGS'],
684 'LIBS': ['winmm', 'ws2_32']
687 'LINKFLAGS': ARM_LINK_FLAGS,
689 'CPPDEFINES' : ['USE_EABI_HARDFLOAT=0'],
691 'CCFLAGS': ['-mfloat-abi=soft'],
696 'CCFLAGS': ['-mfloat-abi=softfp'],
701 'CCFLAGS': ['-mfloat-abi=hard'],
707 'LINKFLAGS': ['-m32']
711 'LINKFLAGS': ['-m64']
714 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
715 'mips_arch_variant:mips32r2': {
716 'CPPDEFINES': ['_MIPS_ARCH_MIPS32R2']
718 'mips_arch_variant:loongson': {
719 'CPPDEFINES': ['_MIPS_ARCH_LOONGSON']
723 'LINKFLAGS': ['-EL'],
724 'mips_arch_variant:mips32r2': {
725 'CCFLAGS': ['-mips32r2', '-Wa,-mips32r2']
727 'mips_arch_variant:mips32r1': {
728 'CCFLAGS': ['-mips32', '-Wa,-mips32']
730 'mips_arch_variant:loongson': {
731 'CCFLAGS': ['-march=mips3', '-Wa,-march=mips3']
734 'LINKFLAGS': ['-static', '-static-libgcc']
736 'mipsabi:softfloat': {
737 'CCFLAGS': ['-msoft-float'],
738 'LINKFLAGS': ['-msoft-float']
740 'mipsabi:hardfloat': {
741 'CCFLAGS': ['-mhard-float'],
742 'LINKFLAGS': ['-mhard-float']
748 'LINKFLAGS': ['-m32']
752 'LINKFLAGS': ['-m32'],
753 'mipsabi:softfloat': {
754 'CPPDEFINES': ['__mips_soft_float=1'],
756 'mipsabi:hardfloat': {
757 'CPPDEFINES': ['__mips_hard_float=1'],
764 'CCFLAGS': ['-g', '-O0'],
765 'CPPDEFINES': ['DEBUG']
768 'LIBPATH' : ['/usr/local/lib'],
773 'LIBS': ['winmm', 'ws2_32']
776 'CCFLAGS': ['/nologo'],
777 'LINKFLAGS': ['/NOLOGO']
780 'LINKFLAGS': ['/VERBOSE']
783 'LINKFLAGS': ['/MAP']
787 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
797 'LINKFLAGS': ['/LTCG'],
801 'LINKFLAGS': ['/LTCG:PGI']
804 'LINKFLAGS': ['/LTCG:PGO']
808 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', 'WIN32'],
809 'LINKFLAGS': ['/MACHINE:X86']
812 'CPPDEFINES': ['V8_TARGET_ARCH_X64', 'WIN32'],
813 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2097152']
817 'LINKFLAGS': ['/DEBUG'],
818 'CPPDEFINES': ['DEBUG'],
833 'CPPDEFINES': ['V8_SHARED'],
840 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
841 'CXXFLAGS': ['-fno-rtti', '-fno-exceptions'],
842 'LINKFLAGS': ['$CCFLAGS'],
844 'console:readline': {
857 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
864 'LIBS': ['winmm', 'ws2_32'],
870 'LINKFLAGS': ARM_LINK_FLAGS
872 'compress_startup_data:bz2': {
873 'CPPDEFINES': ['COMPRESS_STARTUP_DATA_BZ2'],
881 'LIBS': ['winmm', 'ws2_32']
884 'CCFLAGS': ['/nologo'],
885 'LINKFLAGS': ['/NOLOGO']
888 'LINKFLAGS': ['/VERBOSE']
891 'LINKFLAGS': ['/MAP']
895 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
905 'LINKFLAGS': ['/LTCG'],
909 'LINKFLAGS': ['/LTCG:PGI']
912 'LINKFLAGS': ['/LTCG:PGO']
916 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', 'WIN32'],
917 'LINKFLAGS': ['/MACHINE:X86']
920 'CPPDEFINES': ['V8_TARGET_ARCH_X64', 'WIN32'],
921 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2097152']
925 'LINKFLAGS': ['/DEBUG'],
926 'CPPDEFINES': ['DEBUG'],
950 return utils.GuessOS()
954 return utils.GuessArchitecture()
957 def GuessToolchain(env):
961 elif 'msvc' in tools:
967 def GuessVisibility(env):
969 toolchain = env['toolchain'];
970 if (os == 'win32' or os == 'cygwin') and toolchain == 'gcc':
971 # MinGW / Cygwin can't do it.
973 elif os == 'solaris':
979 def GuessStrictAliasing(env):
980 # There seems to be a problem with gcc 4.5.x.
981 # See http://code.google.com/p/v8/issues/detail?id=884
982 # It can be worked around by disabling strict aliasing.
983 toolchain = env['toolchain'];
984 if toolchain == 'gcc':
985 env = Environment(tools=['gcc'])
986 # The gcc version should be available in env['CCVERSION'],
987 # but when scons detects msvc this value is not set.
988 version = subprocess.Popen([env['CC'], '-dumpversion'],
989 stdout=subprocess.PIPE).communicate()[0]
990 if version.find('4.5') == 0:
997 'values': ['arm', 'ia32', 'x64', 'mips'],
999 'help': 'the architecture to build for'
1002 'values': ['freebsd', 'linux', 'macos', 'win32', 'openbsd', 'solaris', 'cygwin', 'netbsd'],
1004 'help': 'the os to build for'
1007 'values': ['gcc', 'msvc'],
1008 'guess': GuessToolchain,
1009 'help': 'the toolchain to use'
1015 'values': ['native', 'interpreted'],
1016 'default': 'native',
1017 'help': 'Whether to use native or interpreted regexp implementation'
1020 'values': ['on', 'off', 'nobuild'],
1022 'help': 'build using snapshots for faster start-up'
1025 'values': ['on', 'off'],
1027 'help': 'enable profiling of build target'
1030 'values': ['on', 'off'],
1032 'help': 'enable GDB JIT interface'
1035 'values': ['static', 'shared'],
1036 'default': 'static',
1037 'help': 'the type of library to produce'
1040 'values': ['on', 'off'],
1042 'help': 'enable object printing'
1044 'profilingsupport': {
1045 'values': ['on', 'off'],
1047 'help': 'enable profiling of JavaScript code'
1049 'debuggersupport': {
1050 'values': ['on', 'off'],
1052 'help': 'enable debugging of JavaScript code'
1055 'values': ['on', 'off'],
1057 'help': 'enable inspector features'
1060 'values': ['on', 'off'],
1062 'help': 'enable live object list features in the debugger'
1065 'values': ['on', 'off'],
1067 'help': 'turn on setting soname for Linux shared library'
1070 'values': ['static', 'shared'],
1071 'default': 'static',
1072 'help': 'the type of Microsoft Visual C++ runtime library to use'
1075 'values': ['on', 'off'],
1077 'help': 'use Microsoft Visual C++ link-time code generation'
1080 'values': ['arm', 'mips', 'none'],
1082 'help': 'build with simulator'
1084 'unalignedaccesses': {
1085 'values': ['default', 'on', 'off'],
1086 'default': 'default',
1087 'help': 'set whether the ARM target supports unaligned accesses'
1090 'values': ['on', 'off'],
1092 'help': 'enable the disassembler to inspect generated code'
1095 'values': ['on', 'off'],
1097 'help': 'enable fast thread local storage support '
1098 '(if available on the current architecture/platform)'
1100 'sourcesignatures': {
1101 'values': ['MD5', 'timestamp'],
1103 'help': 'set how the build system detects file changes'
1106 'values': ['dumb', 'readline'],
1108 'help': 'the console to use for the d8 shell'
1111 'values': ['on', 'off'],
1113 'help': 'more output from compiler and linker'
1116 'values': ['default', 'hidden'],
1117 'guess': GuessVisibility,
1118 'help': 'shared library symbol visibility'
1121 'values': ['default', 'off'],
1122 'guess': GuessStrictAliasing,
1123 'help': 'assume strict aliasing while optimizing'
1126 'values': ['off', 'instrument', 'optimize'],
1128 'help': 'select profile guided optimization variant',
1131 'values': ['hard', 'softfp', 'soft'],
1132 'default': 'softfp',
1133 'help': 'generate calling conventiont according to selected ARM EABI variant'
1136 'values': ['hardfloat', 'softfloat', 'none'],
1137 'default': 'hardfloat',
1138 'help': 'generate calling conventiont according to selected mips ABI'
1140 'mips_arch_variant': {
1141 'values': ['mips32r2', 'mips32r1', 'loongson'],
1142 'default': 'mips32r2',
1143 'help': 'mips variant'
1145 'compress_startup_data': {
1146 'values': ['off', 'bz2'],
1148 'help': 'compress startup data (snapshot) [Linux only]'
1151 'values': ['on', 'off'],
1153 'help': 'use vfp3 instructions when building the snapshot [Arm only]'
1156 'values': ['on', 'off'],
1158 'help': 'use fpu instructions when building the snapshot [MIPS only]'
1163 ALL_OPTIONS = dict(PLATFORM_OPTIONS, **SIMPLE_OPTIONS)
1166 def AddOptions(options, result):
1167 guess_env = Environment(options=result)
1168 for (name, option) in options.iteritems():
1169 if 'guess' in option:
1170 # Option has a guess function
1171 guess = option.get('guess')
1172 default = guess(guess_env)
1174 # Option has a fixed default
1175 default = option.get('default')
1176 help = '%s (%s)' % (option.get('help'), ", ".join(option['values']))
1177 result.Add(name, help, default)
1182 result.Add('mode', 'compilation mode (debug, release)', 'release')
1183 result.Add('sample', 'build sample (shell, process, lineprocessor)', '')
1184 result.Add('cache', 'directory to use for scons build cache', '')
1185 result.Add('env', 'override environment settings (NAME0:value0,NAME1:value1,...)', '')
1186 result.Add('importenv', 'import environment settings (NAME0,NAME1,...)', '')
1187 AddOptions(PLATFORM_OPTIONS, result)
1188 AddOptions(SIMPLE_OPTIONS, result)
1193 env = Environment(options=opts)
1195 toolchain = env['toolchain']
1196 if os == 'win32' and toolchain == 'gcc':
1198 elif os == 'win32' and toolchain == 'msvc':
1199 return ['msvc', 'mslink', 'mslib', 'msvs']
1204 def GetVersionComponents():
1205 MAJOR_VERSION_PATTERN = re.compile(r"#define\s+MAJOR_VERSION\s+(.*)")
1206 MINOR_VERSION_PATTERN = re.compile(r"#define\s+MINOR_VERSION\s+(.*)")
1207 BUILD_NUMBER_PATTERN = re.compile(r"#define\s+BUILD_NUMBER\s+(.*)")
1208 PATCH_LEVEL_PATTERN = re.compile(r"#define\s+PATCH_LEVEL\s+(.*)")
1210 patterns = [MAJOR_VERSION_PATTERN,
1211 MINOR_VERSION_PATTERN,
1212 BUILD_NUMBER_PATTERN,
1213 PATCH_LEVEL_PATTERN]
1215 source = open(join(root_dir, 'src', 'version.cc')).read()
1216 version_components = []
1217 for pattern in patterns:
1218 match = pattern.search(source)
1220 version_components.append(match.group(1).strip())
1222 version_components.append('0')
1224 return version_components
1228 version_components = GetVersionComponents()
1230 if version_components[len(version_components) - 1] == '0':
1231 version_components.pop()
1232 return '.'.join(version_components)
1235 def GetSpecificSONAME():
1236 SONAME_PATTERN = re.compile(r"#define\s+SONAME\s+\"(.*)\"")
1238 source = open(join(root_dir, 'src', 'version.cc')).read()
1239 match = SONAME_PATTERN.search(source)
1242 return match.group(1).strip()
1248 return [ s for s in str.split(",") if len(s) > 0 ]
1251 def IsLegal(env, option, values):
1253 for s in SplitList(str):
1255 Abort("Illegal value for option %s '%s'." % (option, s))
1260 def VerifyOptions(env):
1261 if not IsLegal(env, 'mode', ['debug', 'release']):
1263 if not IsLegal(env, 'sample', ["shell", "process", "lineprocessor"]):
1265 if not IsLegal(env, 'regexp', ["native", "interpreted"]):
1267 if env['os'] == 'win32' and env['library'] == 'shared' and env['prof'] == 'on':
1268 Abort("Profiling on windows only supported for static library.")
1269 if env['gdbjit'] == 'on' and ((env['os'] != 'linux' and env['os'] != 'macos') or (env['arch'] != 'ia32' and env['arch'] != 'x64' and env['arch'] != 'arm')):
1270 Abort("GDBJIT interface is supported only for Intel-compatible (ia32 or x64) Linux/OSX target.")
1271 if env['os'] == 'win32' and env['soname'] == 'on':
1272 Abort("Shared Object soname not applicable for Windows.")
1273 if env['soname'] == 'on' and env['library'] == 'static':
1274 Abort("Shared Object soname not applicable for static library.")
1275 if env['os'] != 'win32' and env['pgo'] != 'off':
1276 Abort("Profile guided optimization only supported on Windows.")
1277 if env['cache'] and not os.path.isdir(env['cache']):
1278 Abort("The specified cache directory does not exist.")
1279 if not (env['arch'] == 'arm' or env['simulator'] == 'arm') and ('unalignedaccesses' in ARGUMENTS):
1281 print env['simulator']
1282 Abort("Option unalignedaccesses only supported for the ARM architecture.")
1283 if env['os'] != 'linux' and env['compress_startup_data'] != 'off':
1284 Abort("Startup data compression is only available on Linux")
1285 for (name, option) in ALL_OPTIONS.iteritems():
1286 if (not name in env):
1287 message = ("A value for option %s must be specified (%s)." %
1288 (name, ", ".join(option['values'])))
1290 if not env[name] in option['values']:
1291 message = ("Unknown %s value '%s'. Possible values are (%s)." %
1292 (name, env[name], ", ".join(option['values'])))
1296 class BuildContext(object):
1298 def __init__(self, options, env_overrides, samples):
1299 self.library_targets = []
1300 self.mksnapshot_targets = []
1301 self.cctest_targets = []
1302 self.sample_targets = []
1303 self.d8_targets = []
1304 self.options = options
1305 self.env_overrides = env_overrides
1306 self.samples = samples
1307 self.preparser_targets = []
1308 self.use_snapshot = (options['snapshot'] != 'off')
1309 self.build_snapshot = (options['snapshot'] == 'on')
1312 def AddRelevantFlags(self, initial, flags):
1313 result = initial.copy()
1314 toolchain = self.options['toolchain']
1315 if toolchain in flags:
1316 self.AppendFlags(result, flags[toolchain].get('all'))
1317 for option in sorted(self.options.keys()):
1318 value = self.options[option]
1319 self.AppendFlags(result, flags[toolchain].get(option + ':' + value))
1320 self.AppendFlags(result, flags.get('all'))
1323 def AddRelevantSubFlags(self, options, flags):
1324 self.AppendFlags(options, flags.get('all'))
1325 for option in sorted(self.options.keys()):
1326 value = self.options[option]
1327 self.AppendFlags(options, flags.get(option + ':' + value))
1329 def GetRelevantSources(self, source):
1331 result += source.get('all', [])
1332 for (name, value) in self.options.iteritems():
1333 source_value = source.get(name + ':' + value, [])
1334 if type(source_value) == dict:
1335 result += self.GetRelevantSources(source_value)
1337 result += source_value
1338 return sorted(result)
1340 def AppendFlags(self, options, added):
1343 for (key, value) in added.iteritems():
1344 if key.find(':') != -1:
1345 self.AddRelevantSubFlags(options, { key: value })
1347 if not key in options:
1348 options[key] = value
1350 prefix = options[key]
1351 if isinstance(prefix, StringTypes): prefix = prefix.split()
1352 options[key] = prefix + value
1354 def ConfigureObject(self, env, input, **kw):
1355 if (kw.has_key('CPPPATH') and env.has_key('CPPPATH')):
1356 kw['CPPPATH'] += env['CPPPATH']
1357 if self.options['library'] == 'static':
1358 return env.StaticObject(input, **kw)
1360 return env.SharedObject(input, **kw)
1362 def ApplyEnvOverrides(self, env):
1363 if not self.env_overrides:
1365 if type(env['ENV']) == DictType:
1366 env['ENV'].update(**self.env_overrides)
1368 env['ENV'] = self.env_overrides
1371 def PostprocessOptions(options, os):
1372 # Adjust architecture if the simulator option has been set
1373 if (options['simulator'] != 'none') and (options['arch'] != options['simulator']):
1374 if 'arch' in ARGUMENTS:
1375 # Print a warning if arch has explicitly been set
1376 print "Warning: forcing architecture to match simulator (%s)" % options['simulator']
1377 options['arch'] = options['simulator']
1378 if (options['prof'] != 'off') and (options['profilingsupport'] == 'off'):
1379 # Print a warning if profiling is enabled without profiling support
1380 print "Warning: forcing profilingsupport on when prof is on"
1381 options['profilingsupport'] = 'on'
1382 if os == 'win32' and options['pgo'] != 'off' and options['msvcltcg'] == 'off':
1383 if 'msvcltcg' in ARGUMENTS:
1384 print "Warning: forcing msvcltcg on as it is required for pgo (%s)" % options['pgo']
1385 options['msvcltcg'] = 'on'
1386 if (options['mipsabi'] != 'none') and (options['arch'] != 'mips') and (options['simulator'] != 'mips'):
1387 options['mipsabi'] = 'none'
1388 if options['liveobjectlist'] == 'on':
1389 if (options['debuggersupport'] != 'on') or (options['mode'] == 'release'):
1390 # Print a warning that liveobjectlist will implicitly enable the debugger
1391 print "Warning: forcing debuggersupport on for liveobjectlist"
1392 options['debuggersupport'] = 'on'
1393 options['inspector'] = 'on'
1394 options['objectprint'] = 'on'
1397 def ParseEnvOverrides(arg, imports):
1398 # The environment overrides are in the format NAME0:value0,NAME1:value1,...
1399 # The environment imports are in the format NAME0,NAME1,...
1401 for var in imports.split(','):
1402 if var in os.environ:
1403 overrides[var] = os.environ[var]
1404 for override in arg.split(','):
1405 pos = override.find(':')
1408 overrides[override[:pos].strip()] = override[pos+1:].strip()
1412 def BuildSpecific(env, mode, env_overrides, tools):
1413 options = {'mode': mode}
1414 for option in ALL_OPTIONS:
1415 options[option] = env[option]
1416 PostprocessOptions(options, env['os'])
1418 context = BuildContext(options, env_overrides, samples=SplitList(env['sample']))
1420 # Remove variables which can't be imported from the user's external
1421 # environment into a construction environment.
1422 user_environ = os.environ.copy()
1424 del user_environ['ENV']
1428 library_flags = context.AddRelevantFlags(user_environ, LIBRARY_FLAGS)
1429 v8_flags = context.AddRelevantFlags(library_flags, V8_EXTRA_FLAGS)
1430 mksnapshot_flags = context.AddRelevantFlags(library_flags, MKSNAPSHOT_EXTRA_FLAGS)
1431 dtoa_flags = context.AddRelevantFlags(library_flags, DTOA_EXTRA_FLAGS)
1432 cctest_flags = context.AddRelevantFlags(v8_flags, CCTEST_EXTRA_FLAGS)
1433 sample_flags = context.AddRelevantFlags(user_environ, SAMPLE_FLAGS)
1434 preparser_flags = context.AddRelevantFlags(user_environ, PREPARSER_FLAGS)
1435 d8_flags = context.AddRelevantFlags(library_flags, D8_FLAGS)
1439 'mksnapshot': mksnapshot_flags,
1441 'cctest': cctest_flags,
1442 'sample': sample_flags,
1444 'preparser': preparser_flags
1447 # Generate library base name.
1449 suffix = SUFFIXES[target_id]
1450 library_name = 'v8' + suffix
1451 preparser_library_name = 'v8preparser' + suffix
1452 version = GetVersion()
1453 if context.options['soname'] == 'on':
1454 # When building shared object with SONAME version the library name.
1455 library_name += '-' + version
1457 # Generate library SONAME if required by the build.
1458 if context.options['soname'] == 'on':
1459 soname = GetSpecificSONAME()
1461 soname = 'lib' + library_name + '.so'
1462 env['SONAME'] = soname
1464 # Build the object files by invoking SCons recursively.
1465 d8_env = Environment(tools=tools)
1466 d8_env.Replace(**context.flags['d8'])
1467 (object_files, shell_files, mksnapshot, preparser_files) = env.SConscript(
1468 join('src', 'SConscript'),
1469 build_dir=join('obj', target_id),
1470 exports='context tools d8_env',
1474 context.mksnapshot_targets.append(mksnapshot)
1476 # Link the object files into a library.
1477 env.Replace(**context.flags['v8'])
1479 context.ApplyEnvOverrides(env)
1480 if context.options['library'] == 'static':
1481 library = env.StaticLibrary(library_name, object_files)
1482 preparser_library = env.StaticLibrary(preparser_library_name,
1485 # There seems to be a glitch in the way scons decides where to put
1486 # PDB files when compiling using MSVC so we specify it manually.
1487 # This should not affect any other platforms.
1488 pdb_name = library_name + '.dll.pdb'
1489 library = env.SharedLibrary(library_name, object_files, PDB=pdb_name)
1490 preparser_pdb_name = preparser_library_name + '.dll.pdb';
1491 preparser_soname = 'lib' + preparser_library_name + '.so';
1492 preparser_library = env.SharedLibrary(preparser_library_name,
1494 PDB=preparser_pdb_name,
1495 SONAME=preparser_soname)
1496 context.library_targets.append(library)
1497 context.library_targets.append(preparser_library)
1499 context.ApplyEnvOverrides(d8_env)
1500 if context.options['library'] == 'static':
1501 shell = d8_env.Program('d8' + suffix, object_files + shell_files)
1503 shell = d8_env.Program('d8' + suffix, shell_files)
1504 d8_env.Depends(shell, library)
1505 context.d8_targets.append(shell)
1507 for sample in context.samples:
1508 sample_env = Environment(tools=tools)
1509 sample_env.Replace(**context.flags['sample'])
1510 sample_env.Prepend(LIBS=[library_name])
1511 context.ApplyEnvOverrides(sample_env)
1512 sample_object = sample_env.SConscript(
1513 join('samples', 'SConscript'),
1514 build_dir=join('obj', 'sample', sample, target_id),
1515 exports='sample context tools',
1518 sample_name = sample + suffix
1519 sample_program = sample_env.Program(sample_name, sample_object)
1520 sample_env.Depends(sample_program, library)
1521 context.sample_targets.append(sample_program)
1523 cctest_env = env.Copy()
1524 cctest_env.Prepend(LIBS=[library_name])
1525 cctest_program = cctest_env.SConscript(
1526 join('test', 'cctest', 'SConscript'),
1527 build_dir=join('obj', 'test', target_id),
1528 exports='context object_files tools',
1531 context.cctest_targets.append(cctest_program)
1533 preparser_env = env.Copy()
1534 preparser_env.Replace(**context.flags['preparser'])
1535 preparser_env.Prepend(LIBS=[preparser_library_name])
1536 context.ApplyEnvOverrides(preparser_env)
1537 preparser_object = preparser_env.SConscript(
1538 join('preparser', 'SConscript'),
1539 build_dir=join('obj', 'preparser', target_id),
1540 exports='context tools',
1543 preparser_name = join('obj', 'preparser', target_id, 'preparser')
1544 preparser_program = preparser_env.Program(preparser_name, preparser_object);
1545 preparser_env.Depends(preparser_program, preparser_library)
1546 context.preparser_targets.append(preparser_program)
1553 tools = GetTools(opts)
1554 env = Environment(options=opts, tools=tools)
1556 Help(opts.GenerateHelpText(env))
1558 env_overrides = ParseEnvOverrides(env['env'], env['importenv'])
1560 SourceSignatures(env['sourcesignatures'])
1568 modes = SplitList(env['mode'])
1570 context = BuildSpecific(env.Copy(), mode, env_overrides, tools)
1571 libraries += context.library_targets
1572 mksnapshots += context.mksnapshot_targets
1573 cctests += context.cctest_targets
1574 samples += context.sample_targets
1575 preparsers += context.preparser_targets
1576 d8s += context.d8_targets
1578 env.Alias('library', libraries)
1579 env.Alias('mksnapshot', mksnapshots)
1580 env.Alias('cctests', cctests)
1581 env.Alias('sample', samples)
1582 env.Alias('d8', d8s)
1583 env.Alias('preparser', preparsers)
1586 env.Default('sample')
1588 env.Default('library')
1591 CacheDir(env['cache'])
1593 # We disable deprecation warnings because we need to be able to use
1594 # env.Copy without getting warnings for compatibility with older
1595 # version of scons. Also, there's a bug in some revisions that
1596 # doesn't allow this flag to be set, so we swallow any exceptions.
1599 SetOption('warn', 'no-deprecated')