Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1 | # Copyright 2010 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | # Redistribution and use in source and binary forms, with or without |
| 3 | # modification, are permitted provided that the following conditions are |
| 4 | # met: |
| 5 | # |
| 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. |
| 15 | # |
| 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. |
| 27 | |
| 28 | import platform |
| 29 | import re |
| 30 | import sys |
| 31 | import os |
| 32 | from os.path import join, dirname, abspath |
| 33 | from types import DictType, StringTypes |
| 34 | root_dir = dirname(File('SConstruct').rfile().abspath) |
| 35 | sys.path.append(join(root_dir, 'tools')) |
| 36 | import js2c, utils |
| 37 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | # ANDROID_TOP is the top of the Android checkout, fetched from the environment |
| 39 | # variable 'TOP'. You will also need to set the CXX, CC, AR and RANLIB |
| 40 | # environment variables to the cross-compiling tools. |
| 41 | ANDROID_TOP = os.environ.get('TOP') |
| 42 | if ANDROID_TOP is None: |
| 43 | ANDROID_TOP="" |
| 44 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 45 | # ARM_TARGET_LIB is the path to the dynamic library to use on the target |
| 46 | # machine if cross-compiling to an arm machine. You will also need to set |
| 47 | # the additional cross-compiling environment variables to the cross compiler. |
| 48 | ARM_TARGET_LIB = os.environ.get('ARM_TARGET_LIB') |
| 49 | if ARM_TARGET_LIB: |
| 50 | ARM_LINK_FLAGS = ['-Wl,-rpath=' + ARM_TARGET_LIB + '/lib:' + |
| 51 | ARM_TARGET_LIB + '/usr/lib', |
| 52 | '-Wl,--dynamic-linker=' + ARM_TARGET_LIB + |
| 53 | '/lib/ld-linux.so.3'] |
| 54 | else: |
| 55 | ARM_LINK_FLAGS = [] |
| 56 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 57 | # TODO: Sort these issues out properly but as a temporary solution for gcc 4.4 |
| 58 | # on linux we need these compiler flags to avoid crashes in the v8 test suite |
| 59 | # and avoid dtoa.c strict aliasing issues |
| 60 | if os.environ.get('GCC_VERSION') == '44': |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 61 | GCC_EXTRA_CCFLAGS = ['-fno-tree-vrp', '-fno-strict-aliasing'] |
| 62 | GCC_DTOA_EXTRA_CCFLAGS = [] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 63 | else: |
| 64 | GCC_EXTRA_CCFLAGS = [] |
| 65 | GCC_DTOA_EXTRA_CCFLAGS = [] |
| 66 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 67 | ANDROID_FLAGS = ['-march=armv7-a', |
| 68 | '-mtune=cortex-a8', |
| 69 | '-mfloat-abi=softfp', |
| 70 | '-mfpu=vfp', |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 71 | '-fpic', |
| 72 | '-mthumb-interwork', |
| 73 | '-funwind-tables', |
| 74 | '-fstack-protector', |
| 75 | '-fno-short-enums', |
| 76 | '-fmessage-length=0', |
| 77 | '-finline-functions', |
| 78 | '-fno-inline-functions-called-once', |
| 79 | '-fgcse-after-reload', |
| 80 | '-frerun-cse-after-loop', |
| 81 | '-frename-registers', |
| 82 | '-fomit-frame-pointer', |
| 83 | '-fno-strict-aliasing', |
| 84 | '-finline-limit=64', |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 85 | '-DCAN_USE_VFP_INSTRUCTIONS=1', |
| 86 | '-DCAN_USE_ARMV7_INSTRUCTIONS=1', |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 87 | '-DCAN_USE_UNALIGNED_ACCESSES=1', |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 88 | '-MD'] |
| 89 | |
| 90 | ANDROID_INCLUDES = [ANDROID_TOP + '/bionic/libc/arch-arm/include', |
| 91 | ANDROID_TOP + '/bionic/libc/include', |
| 92 | ANDROID_TOP + '/bionic/libstdc++/include', |
| 93 | ANDROID_TOP + '/bionic/libc/kernel/common', |
| 94 | ANDROID_TOP + '/bionic/libc/kernel/arch-arm', |
| 95 | ANDROID_TOP + '/bionic/libm/include', |
| 96 | ANDROID_TOP + '/bionic/libm/include/arch/arm', |
| 97 | ANDROID_TOP + '/bionic/libthread_db/include', |
| 98 | ANDROID_TOP + '/frameworks/base/include', |
| 99 | ANDROID_TOP + '/system/core/include'] |
| 100 | |
| 101 | ANDROID_LINKFLAGS = ['-nostdlib', |
| 102 | '-Bdynamic', |
| 103 | '-Wl,-T,' + ANDROID_TOP + '/build/core/armelf.x', |
| 104 | '-Wl,-dynamic-linker,/system/bin/linker', |
| 105 | '-Wl,--gc-sections', |
| 106 | '-Wl,-z,nocopyreloc', |
| 107 | '-Wl,-rpath-link=' + ANDROID_TOP + '/out/target/product/generic/obj/lib', |
| 108 | ANDROID_TOP + '/out/target/product/generic/obj/lib/crtbegin_dynamic.o', |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 109 | ANDROID_TOP + '/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/interwork/libgcc.a', |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 110 | ANDROID_TOP + '/out/target/product/generic/obj/lib/crtend_android.o']; |
| 111 | |
| 112 | LIBRARY_FLAGS = { |
| 113 | 'all': { |
| 114 | 'CPPPATH': [join(root_dir, 'src')], |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 115 | 'regexp:interpreted': { |
| 116 | 'CPPDEFINES': ['V8_INTERPRETED_REGEXP'] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 117 | }, |
| 118 | 'mode:debug': { |
| 119 | 'CPPDEFINES': ['V8_ENABLE_CHECKS'] |
| 120 | }, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 121 | 'vmstate:on': { |
| 122 | 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING'], |
| 123 | }, |
| 124 | 'protectheap:on': { |
| 125 | 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING', 'ENABLE_HEAP_PROTECTION'], |
| 126 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 127 | 'profilingsupport:on': { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 128 | 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING', 'ENABLE_LOGGING_AND_PROFILING'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 129 | }, |
| 130 | 'debuggersupport:on': { |
| 131 | 'CPPDEFINES': ['ENABLE_DEBUGGER_SUPPORT'], |
| 132 | } |
| 133 | }, |
| 134 | 'gcc': { |
| 135 | 'all': { |
| 136 | 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'], |
| 137 | 'CXXFLAGS': ['$CCFLAGS', '-fno-rtti', '-fno-exceptions'], |
| 138 | }, |
| 139 | 'visibility:hidden': { |
| 140 | # Use visibility=default to disable this. |
| 141 | 'CXXFLAGS': ['-fvisibility=hidden'] |
| 142 | }, |
| 143 | 'mode:debug': { |
| 144 | 'CCFLAGS': ['-g', '-O0'], |
| 145 | 'CPPDEFINES': ['ENABLE_DISASSEMBLER', 'DEBUG'], |
| 146 | 'os:android': { |
| 147 | 'CCFLAGS': ['-mthumb'] |
| 148 | } |
| 149 | }, |
| 150 | 'mode:release': { |
| 151 | 'CCFLAGS': ['-O3', '-fomit-frame-pointer', '-fdata-sections', |
| 152 | '-ffunction-sections'], |
| 153 | 'os:android': { |
| 154 | 'CCFLAGS': ['-mthumb', '-Os'], |
| 155 | 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG'] |
| 156 | } |
| 157 | }, |
| 158 | 'os:linux': { |
| 159 | 'CCFLAGS': ['-ansi'] + GCC_EXTRA_CCFLAGS, |
| 160 | 'library:shared': { |
| 161 | 'CPPDEFINES': ['V8_SHARED'], |
| 162 | 'LIBS': ['pthread'] |
| 163 | } |
| 164 | }, |
| 165 | 'os:macos': { |
| 166 | 'CCFLAGS': ['-ansi', '-mmacosx-version-min=10.4'], |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 167 | 'library:shared': { |
| 168 | 'CPPDEFINES': ['V8_SHARED'] |
| 169 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 170 | }, |
| 171 | 'os:freebsd': { |
| 172 | 'CPPPATH' : ['/usr/local/include'], |
| 173 | 'LIBPATH' : ['/usr/local/lib'], |
| 174 | 'CCFLAGS': ['-ansi'], |
| 175 | }, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 176 | 'os:openbsd': { |
| 177 | 'CPPPATH' : ['/usr/local/include'], |
| 178 | 'LIBPATH' : ['/usr/local/lib'], |
| 179 | 'CCFLAGS': ['-ansi'], |
| 180 | }, |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 181 | 'os:solaris': { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 182 | # On Solaris, to get isinf, INFINITY, fpclassify and other macros one |
| 183 | # needs to define __C99FEATURES__. |
| 184 | 'CPPDEFINES': ['__C99FEATURES__'], |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 185 | 'CPPPATH' : ['/usr/local/include'], |
| 186 | 'LIBPATH' : ['/usr/local/lib'], |
| 187 | 'CCFLAGS': ['-ansi'], |
| 188 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 189 | 'os:win32': { |
| 190 | 'CCFLAGS': ['-DWIN32'], |
| 191 | 'CXXFLAGS': ['-DWIN32'], |
| 192 | }, |
| 193 | 'os:android': { |
| 194 | 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__', |
| 195 | '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'], |
| 196 | 'CCFLAGS': ANDROID_FLAGS, |
| 197 | 'WARNINGFLAGS': ['-Wall', '-Wno-unused', '-Werror=return-type', |
| 198 | '-Wstrict-aliasing=2'], |
| 199 | 'CPPPATH': ANDROID_INCLUDES, |
| 200 | }, |
| 201 | 'arch:ia32': { |
| 202 | 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'], |
| 203 | 'CCFLAGS': ['-m32'], |
| 204 | 'LINKFLAGS': ['-m32'] |
| 205 | }, |
| 206 | 'arch:arm': { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame^] | 207 | 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'], |
| 208 | 'unalignedaccesses:on' : { |
| 209 | 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=1'] |
| 210 | }, |
| 211 | 'unalignedaccesses:off' : { |
| 212 | 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=0'] |
| 213 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 214 | }, |
| 215 | 'simulator:arm': { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame^] | 216 | 'CCFLAGS': ['-m32'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 217 | 'LINKFLAGS': ['-m32'] |
| 218 | }, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 219 | 'arch:mips': { |
| 220 | 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'], |
| 221 | 'simulator:none': { |
| 222 | 'CCFLAGS': ['-EL', '-mips32r2', '-Wa,-mips32r2', '-fno-inline'], |
| 223 | 'LDFLAGS': ['-EL'] |
| 224 | } |
| 225 | }, |
| 226 | 'simulator:mips': { |
| 227 | 'CCFLAGS': ['-m32'], |
| 228 | 'LINKFLAGS': ['-m32'] |
| 229 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 230 | 'arch:x64': { |
| 231 | 'CPPDEFINES': ['V8_TARGET_ARCH_X64'], |
| 232 | 'CCFLAGS': ['-m64'], |
| 233 | 'LINKFLAGS': ['-m64'], |
| 234 | }, |
| 235 | 'prof:oprofile': { |
| 236 | 'CPPDEFINES': ['ENABLE_OPROFILE_AGENT'] |
| 237 | } |
| 238 | }, |
| 239 | 'msvc': { |
| 240 | 'all': { |
| 241 | 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'], |
| 242 | 'CXXFLAGS': ['$CCFLAGS', '/GR-', '/Gy'], |
| 243 | 'CPPDEFINES': ['WIN32'], |
| 244 | 'LINKFLAGS': ['/INCREMENTAL:NO', '/NXCOMPAT', '/IGNORE:4221'], |
| 245 | 'CCPDBFLAGS': ['/Zi'] |
| 246 | }, |
| 247 | 'verbose:off': { |
| 248 | 'DIALECTFLAGS': ['/nologo'], |
| 249 | 'ARFLAGS': ['/NOLOGO'] |
| 250 | }, |
| 251 | 'arch:ia32': { |
| 252 | 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', '_USE_32BIT_TIME_T'], |
| 253 | 'LINKFLAGS': ['/MACHINE:X86'], |
| 254 | 'ARFLAGS': ['/MACHINE:X86'] |
| 255 | }, |
| 256 | 'arch:x64': { |
| 257 | 'CPPDEFINES': ['V8_TARGET_ARCH_X64'], |
| 258 | 'LINKFLAGS': ['/MACHINE:X64'], |
| 259 | 'ARFLAGS': ['/MACHINE:X64'] |
| 260 | }, |
| 261 | 'mode:debug': { |
| 262 | 'CCFLAGS': ['/Od', '/Gm'], |
| 263 | 'CPPDEFINES': ['_DEBUG', 'ENABLE_DISASSEMBLER', 'DEBUG'], |
| 264 | 'LINKFLAGS': ['/DEBUG'], |
| 265 | 'msvcrt:static': { |
| 266 | 'CCFLAGS': ['/MTd'] |
| 267 | }, |
| 268 | 'msvcrt:shared': { |
| 269 | 'CCFLAGS': ['/MDd'] |
| 270 | } |
| 271 | }, |
| 272 | 'mode:release': { |
| 273 | 'CCFLAGS': ['/O2'], |
| 274 | 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'], |
| 275 | 'msvcrt:static': { |
| 276 | 'CCFLAGS': ['/MT'] |
| 277 | }, |
| 278 | 'msvcrt:shared': { |
| 279 | 'CCFLAGS': ['/MD'] |
| 280 | }, |
| 281 | 'msvcltcg:on': { |
| 282 | 'CCFLAGS': ['/GL'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 283 | 'ARFLAGS': ['/LTCG'], |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 284 | 'pgo:off': { |
| 285 | 'LINKFLAGS': ['/LTCG'], |
| 286 | }, |
| 287 | 'pgo:instrument': { |
| 288 | 'LINKFLAGS': ['/LTCG:PGI'] |
| 289 | }, |
| 290 | 'pgo:optimize': { |
| 291 | 'LINKFLAGS': ['/LTCG:PGO'] |
| 292 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | |
| 299 | V8_EXTRA_FLAGS = { |
| 300 | 'gcc': { |
| 301 | 'all': { |
| 302 | 'WARNINGFLAGS': ['-Wall', |
| 303 | '-Werror', |
| 304 | '-W', |
| 305 | '-Wno-unused-parameter', |
| 306 | '-Wnon-virtual-dtor'] |
| 307 | }, |
| 308 | 'os:win32': { |
| 309 | 'WARNINGFLAGS': ['-pedantic', '-Wno-long-long'] |
| 310 | }, |
| 311 | 'os:linux': { |
| 312 | 'WARNINGFLAGS': ['-pedantic'], |
| 313 | 'library:shared': { |
| 314 | 'soname:on': { |
| 315 | 'LINKFLAGS': ['-Wl,-soname,${SONAME}'] |
| 316 | } |
| 317 | } |
| 318 | }, |
| 319 | 'os:macos': { |
| 320 | 'WARNINGFLAGS': ['-pedantic'] |
| 321 | }, |
| 322 | 'disassembler:on': { |
| 323 | 'CPPDEFINES': ['ENABLE_DISASSEMBLER'] |
| 324 | } |
| 325 | }, |
| 326 | 'msvc': { |
| 327 | 'all': { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 328 | 'WARNINGFLAGS': ['/W3', '/WX', '/wd4355', '/wd4800'] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 329 | }, |
| 330 | 'library:shared': { |
| 331 | 'CPPDEFINES': ['BUILDING_V8_SHARED'], |
| 332 | 'LIBS': ['winmm', 'ws2_32'] |
| 333 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 334 | 'arch:arm': { |
| 335 | 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'], |
| 336 | # /wd4996 is to silence the warning about sscanf |
| 337 | # used by the arm simulator. |
| 338 | 'WARNINGFLAGS': ['/wd4996'] |
| 339 | }, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 340 | 'arch:mips': { |
| 341 | 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'], |
| 342 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 343 | 'disassembler:on': { |
| 344 | 'CPPDEFINES': ['ENABLE_DISASSEMBLER'] |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | |
| 350 | MKSNAPSHOT_EXTRA_FLAGS = { |
| 351 | 'gcc': { |
| 352 | 'os:linux': { |
| 353 | 'LIBS': ['pthread'], |
| 354 | }, |
| 355 | 'os:macos': { |
| 356 | 'LIBS': ['pthread'], |
| 357 | }, |
| 358 | 'os:freebsd': { |
| 359 | 'LIBS': ['execinfo', 'pthread'] |
| 360 | }, |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 361 | 'os:solaris': { |
| 362 | 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'], |
| 363 | 'LINKFLAGS': ['-mt'] |
| 364 | }, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 365 | 'os:openbsd': { |
| 366 | 'LIBS': ['execinfo', 'pthread'] |
| 367 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 368 | 'os:win32': { |
| 369 | 'LIBS': ['winmm', 'ws2_32'], |
| 370 | }, |
| 371 | }, |
| 372 | 'msvc': { |
| 373 | 'all': { |
| 374 | 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'], |
| 375 | 'LIBS': ['winmm', 'ws2_32'] |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | |
| 381 | DTOA_EXTRA_FLAGS = { |
| 382 | 'gcc': { |
| 383 | 'all': { |
| 384 | 'WARNINGFLAGS': ['-Werror', '-Wno-uninitialized'], |
| 385 | 'CCFLAGS': GCC_DTOA_EXTRA_CCFLAGS |
| 386 | } |
| 387 | }, |
| 388 | 'msvc': { |
| 389 | 'all': { |
| 390 | 'WARNINGFLAGS': ['/WX', '/wd4018', '/wd4244'] |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | |
| 396 | CCTEST_EXTRA_FLAGS = { |
| 397 | 'all': { |
| 398 | 'CPPPATH': [join(root_dir, 'src')], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 399 | }, |
| 400 | 'gcc': { |
| 401 | 'all': { |
| 402 | 'LIBPATH': [abspath('.')] |
| 403 | }, |
| 404 | 'os:linux': { |
| 405 | 'LIBS': ['pthread'], |
| 406 | }, |
| 407 | 'os:macos': { |
| 408 | 'LIBS': ['pthread'], |
| 409 | }, |
| 410 | 'os:freebsd': { |
| 411 | 'LIBS': ['execinfo', 'pthread'] |
| 412 | }, |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 413 | 'os:solaris': { |
| 414 | 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'], |
| 415 | 'LINKFLAGS': ['-mt'] |
| 416 | }, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 417 | 'os:openbsd': { |
| 418 | 'LIBS': ['execinfo', 'pthread'] |
| 419 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 420 | 'os:win32': { |
| 421 | 'LIBS': ['winmm', 'ws2_32'] |
| 422 | }, |
| 423 | 'os:android': { |
| 424 | 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__', |
| 425 | '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'], |
| 426 | 'CCFLAGS': ANDROID_FLAGS, |
| 427 | 'CPPPATH': ANDROID_INCLUDES, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 428 | 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib', |
| 429 | ANDROID_TOP + '/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/interwork'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 430 | 'LINKFLAGS': ANDROID_LINKFLAGS, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 431 | 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 432 | 'mode:release': { |
| 433 | 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG'] |
| 434 | } |
| 435 | }, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 436 | 'arch:arm': { |
| 437 | 'LINKFLAGS': ARM_LINK_FLAGS |
| 438 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 439 | }, |
| 440 | 'msvc': { |
| 441 | 'all': { |
| 442 | 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'], |
| 443 | 'LIBS': ['winmm', 'ws2_32'] |
| 444 | }, |
| 445 | 'library:shared': { |
| 446 | 'CPPDEFINES': ['USING_V8_SHARED'] |
| 447 | }, |
| 448 | 'arch:ia32': { |
| 449 | 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'] |
| 450 | }, |
| 451 | 'arch:x64': { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 452 | 'CPPDEFINES': ['V8_TARGET_ARCH_X64'], |
| 453 | 'LINKFLAGS': ['/STACK:2091752'] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 454 | }, |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | |
| 459 | SAMPLE_FLAGS = { |
| 460 | 'all': { |
| 461 | 'CPPPATH': [join(abspath('.'), 'include')], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 462 | }, |
| 463 | 'gcc': { |
| 464 | 'all': { |
| 465 | 'LIBPATH': ['.'], |
| 466 | 'CCFLAGS': ['-fno-rtti', '-fno-exceptions'] |
| 467 | }, |
| 468 | 'os:linux': { |
| 469 | 'LIBS': ['pthread'], |
| 470 | }, |
| 471 | 'os:macos': { |
| 472 | 'LIBS': ['pthread'], |
| 473 | }, |
| 474 | 'os:freebsd': { |
| 475 | 'LIBPATH' : ['/usr/local/lib'], |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 476 | 'LIBS': ['execinfo', 'pthread'] |
| 477 | }, |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 478 | 'os:solaris': { |
| 479 | 'LIBPATH' : ['/usr/local/lib'], |
| 480 | 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'], |
| 481 | 'LINKFLAGS': ['-mt'] |
| 482 | }, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 483 | 'os:openbsd': { |
| 484 | 'LIBPATH' : ['/usr/local/lib'], |
| 485 | 'LIBS': ['execinfo', 'pthread'] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 486 | }, |
| 487 | 'os:win32': { |
| 488 | 'LIBS': ['winmm', 'ws2_32'] |
| 489 | }, |
| 490 | 'os:android': { |
| 491 | 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__', |
| 492 | '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'], |
| 493 | 'CCFLAGS': ANDROID_FLAGS, |
| 494 | 'CPPPATH': ANDROID_INCLUDES, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 495 | 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib', |
| 496 | ANDROID_TOP + '/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/interwork'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | 'LINKFLAGS': ANDROID_LINKFLAGS, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 498 | 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | 'mode:release': { |
| 500 | 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG'] |
| 501 | } |
| 502 | }, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 503 | 'arch:arm': { |
| 504 | 'LINKFLAGS': ARM_LINK_FLAGS |
| 505 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 506 | 'arch:ia32': { |
| 507 | 'CCFLAGS': ['-m32'], |
| 508 | 'LINKFLAGS': ['-m32'] |
| 509 | }, |
| 510 | 'arch:x64': { |
| 511 | 'CCFLAGS': ['-m64'], |
| 512 | 'LINKFLAGS': ['-m64'] |
| 513 | }, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 514 | 'arch:mips': { |
| 515 | 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'], |
| 516 | 'simulator:none': { |
| 517 | 'CCFLAGS': ['-EL', '-mips32r2', '-Wa,-mips32r2', '-fno-inline'], |
| 518 | 'LINKFLAGS': ['-EL'], |
| 519 | 'LDFLAGS': ['-EL'] |
| 520 | } |
| 521 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 522 | 'simulator:arm': { |
| 523 | 'CCFLAGS': ['-m32'], |
| 524 | 'LINKFLAGS': ['-m32'] |
| 525 | }, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 526 | 'simulator:mips': { |
| 527 | 'CCFLAGS': ['-m32'], |
| 528 | 'LINKFLAGS': ['-m32'] |
| 529 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 530 | 'mode:release': { |
| 531 | 'CCFLAGS': ['-O2'] |
| 532 | }, |
| 533 | 'mode:debug': { |
| 534 | 'CCFLAGS': ['-g', '-O0'] |
| 535 | }, |
| 536 | 'prof:oprofile': { |
| 537 | 'LIBPATH': ['/usr/lib32', '/usr/lib32/oprofile'], |
| 538 | 'LIBS': ['opagent'] |
| 539 | } |
| 540 | }, |
| 541 | 'msvc': { |
| 542 | 'all': { |
| 543 | 'LIBS': ['winmm', 'ws2_32'] |
| 544 | }, |
| 545 | 'verbose:off': { |
| 546 | 'CCFLAGS': ['/nologo'], |
| 547 | 'LINKFLAGS': ['/NOLOGO'] |
| 548 | }, |
| 549 | 'verbose:on': { |
| 550 | 'LINKFLAGS': ['/VERBOSE'] |
| 551 | }, |
| 552 | 'library:shared': { |
| 553 | 'CPPDEFINES': ['USING_V8_SHARED'] |
| 554 | }, |
| 555 | 'prof:on': { |
| 556 | 'LINKFLAGS': ['/MAP'] |
| 557 | }, |
| 558 | 'mode:release': { |
| 559 | 'CCFLAGS': ['/O2'], |
| 560 | 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'], |
| 561 | 'msvcrt:static': { |
| 562 | 'CCFLAGS': ['/MT'] |
| 563 | }, |
| 564 | 'msvcrt:shared': { |
| 565 | 'CCFLAGS': ['/MD'] |
| 566 | }, |
| 567 | 'msvcltcg:on': { |
| 568 | 'CCFLAGS': ['/GL'], |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 569 | 'pgo:off': { |
| 570 | 'LINKFLAGS': ['/LTCG'], |
| 571 | }, |
| 572 | }, |
| 573 | 'pgo:instrument': { |
| 574 | 'LINKFLAGS': ['/LTCG:PGI'] |
| 575 | }, |
| 576 | 'pgo:optimize': { |
| 577 | 'LINKFLAGS': ['/LTCG:PGO'] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 578 | } |
| 579 | }, |
| 580 | 'arch:ia32': { |
| 581 | 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'], |
| 582 | 'LINKFLAGS': ['/MACHINE:X86'] |
| 583 | }, |
| 584 | 'arch:x64': { |
| 585 | 'CPPDEFINES': ['V8_TARGET_ARCH_X64'], |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 586 | 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2091752'] |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 587 | }, |
| 588 | 'mode:debug': { |
| 589 | 'CCFLAGS': ['/Od'], |
| 590 | 'LINKFLAGS': ['/DEBUG'], |
| 591 | 'msvcrt:static': { |
| 592 | 'CCFLAGS': ['/MTd'] |
| 593 | }, |
| 594 | 'msvcrt:shared': { |
| 595 | 'CCFLAGS': ['/MDd'] |
| 596 | } |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | |
| 602 | D8_FLAGS = { |
| 603 | 'gcc': { |
| 604 | 'console:readline': { |
| 605 | 'LIBS': ['readline'] |
| 606 | }, |
| 607 | 'os:linux': { |
| 608 | 'LIBS': ['pthread'], |
| 609 | }, |
| 610 | 'os:macos': { |
| 611 | 'LIBS': ['pthread'], |
| 612 | }, |
| 613 | 'os:freebsd': { |
| 614 | 'LIBS': ['pthread'], |
| 615 | }, |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 616 | 'os:solaris': { |
| 617 | 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'], |
| 618 | 'LINKFLAGS': ['-mt'] |
| 619 | }, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 620 | 'os:openbsd': { |
| 621 | 'LIBS': ['pthread'], |
| 622 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 623 | 'os:android': { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 624 | 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib', |
| 625 | ANDROID_TOP + '/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/interwork'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 626 | 'LINKFLAGS': ANDROID_LINKFLAGS, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 627 | 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 628 | }, |
| 629 | 'os:win32': { |
| 630 | 'LIBS': ['winmm', 'ws2_32'], |
| 631 | }, |
| 632 | }, |
| 633 | 'msvc': { |
| 634 | 'all': { |
| 635 | 'LIBS': ['winmm', 'ws2_32'] |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | |
| 641 | SUFFIXES = { |
| 642 | 'release': '', |
| 643 | 'debug': '_g' |
| 644 | } |
| 645 | |
| 646 | |
| 647 | def Abort(message): |
| 648 | print message |
| 649 | sys.exit(1) |
| 650 | |
| 651 | |
| 652 | def GuessToolchain(os): |
| 653 | tools = Environment()['TOOLS'] |
| 654 | if 'gcc' in tools: |
| 655 | return 'gcc' |
| 656 | elif 'msvc' in tools: |
| 657 | return 'msvc' |
| 658 | else: |
| 659 | return None |
| 660 | |
| 661 | |
| 662 | OS_GUESS = utils.GuessOS() |
| 663 | TOOLCHAIN_GUESS = GuessToolchain(OS_GUESS) |
| 664 | ARCH_GUESS = utils.GuessArchitecture() |
| 665 | |
| 666 | |
| 667 | SIMPLE_OPTIONS = { |
| 668 | 'toolchain': { |
| 669 | 'values': ['gcc', 'msvc'], |
| 670 | 'default': TOOLCHAIN_GUESS, |
| 671 | 'help': 'the toolchain to use (' + TOOLCHAIN_GUESS + ')' |
| 672 | }, |
| 673 | 'os': { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 674 | 'values': ['freebsd', 'linux', 'macos', 'win32', 'android', 'openbsd', 'solaris'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 675 | 'default': OS_GUESS, |
| 676 | 'help': 'the os to build for (' + OS_GUESS + ')' |
| 677 | }, |
| 678 | 'arch': { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 679 | 'values':['arm', 'ia32', 'x64', 'mips'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 680 | 'default': ARCH_GUESS, |
| 681 | 'help': 'the architecture to build for (' + ARCH_GUESS + ')' |
| 682 | }, |
| 683 | 'regexp': { |
| 684 | 'values': ['native', 'interpreted'], |
| 685 | 'default': 'native', |
| 686 | 'help': 'Whether to use native or interpreted regexp implementation' |
| 687 | }, |
| 688 | 'snapshot': { |
| 689 | 'values': ['on', 'off', 'nobuild'], |
| 690 | 'default': 'off', |
| 691 | 'help': 'build using snapshots for faster start-up' |
| 692 | }, |
| 693 | 'prof': { |
| 694 | 'values': ['on', 'off', 'oprofile'], |
| 695 | 'default': 'off', |
| 696 | 'help': 'enable profiling of build target' |
| 697 | }, |
| 698 | 'library': { |
| 699 | 'values': ['static', 'shared'], |
| 700 | 'default': 'static', |
| 701 | 'help': 'the type of library to produce' |
| 702 | }, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 703 | 'vmstate': { |
| 704 | 'values': ['on', 'off'], |
| 705 | 'default': 'off', |
| 706 | 'help': 'enable VM state tracking' |
| 707 | }, |
| 708 | 'protectheap': { |
| 709 | 'values': ['on', 'off'], |
| 710 | 'default': 'off', |
| 711 | 'help': 'enable heap protection' |
| 712 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 713 | 'profilingsupport': { |
| 714 | 'values': ['on', 'off'], |
| 715 | 'default': 'on', |
| 716 | 'help': 'enable profiling of JavaScript code' |
| 717 | }, |
| 718 | 'debuggersupport': { |
| 719 | 'values': ['on', 'off'], |
| 720 | 'default': 'on', |
| 721 | 'help': 'enable debugging of JavaScript code' |
| 722 | }, |
| 723 | 'soname': { |
| 724 | 'values': ['on', 'off'], |
| 725 | 'default': 'off', |
| 726 | 'help': 'turn on setting soname for Linux shared library' |
| 727 | }, |
| 728 | 'msvcrt': { |
| 729 | 'values': ['static', 'shared'], |
| 730 | 'default': 'static', |
| 731 | 'help': 'the type of Microsoft Visual C++ runtime library to use' |
| 732 | }, |
| 733 | 'msvcltcg': { |
| 734 | 'values': ['on', 'off'], |
| 735 | 'default': 'on', |
| 736 | 'help': 'use Microsoft Visual C++ link-time code generation' |
| 737 | }, |
| 738 | 'simulator': { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 739 | 'values': ['arm', 'mips', 'none'], |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 740 | 'default': 'none', |
| 741 | 'help': 'build with simulator' |
| 742 | }, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame^] | 743 | 'unalignedaccesses': { |
| 744 | 'values': ['default', 'on', 'off'], |
| 745 | 'default': 'default', |
| 746 | 'help': 'set whether the ARM target supports unaligned accesses' |
| 747 | }, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 748 | 'disassembler': { |
| 749 | 'values': ['on', 'off'], |
| 750 | 'default': 'off', |
| 751 | 'help': 'enable the disassembler to inspect generated code' |
| 752 | }, |
| 753 | 'sourcesignatures': { |
| 754 | 'values': ['MD5', 'timestamp'], |
| 755 | 'default': 'MD5', |
| 756 | 'help': 'set how the build system detects file changes' |
| 757 | }, |
| 758 | 'console': { |
| 759 | 'values': ['dumb', 'readline'], |
| 760 | 'default': 'dumb', |
| 761 | 'help': 'the console to use for the d8 shell' |
| 762 | }, |
| 763 | 'verbose': { |
| 764 | 'values': ['on', 'off'], |
| 765 | 'default': 'off', |
| 766 | 'help': 'more output from compiler and linker' |
| 767 | }, |
| 768 | 'visibility': { |
| 769 | 'values': ['default', 'hidden'], |
| 770 | 'default': 'hidden', |
| 771 | 'help': 'shared library symbol visibility' |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 772 | }, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 773 | 'pgo': { |
| 774 | 'values': ['off', 'instrument', 'optimize'], |
| 775 | 'default': 'off', |
| 776 | 'help': 'select profile guided optimization variant', |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
| 780 | |
| 781 | def GetOptions(): |
| 782 | result = Options() |
| 783 | result.Add('mode', 'compilation mode (debug, release)', 'release') |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 784 | result.Add('sample', 'build sample (shell, process, lineprocessor)', '') |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame^] | 785 | result.Add('cache', 'directory to use for scons build cache', '') |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 786 | result.Add('env', 'override environment settings (NAME0:value0,NAME1:value1,...)', '') |
| 787 | result.Add('importenv', 'import environment settings (NAME0,NAME1,...)', '') |
| 788 | for (name, option) in SIMPLE_OPTIONS.iteritems(): |
| 789 | help = '%s (%s)' % (name, ", ".join(option['values'])) |
| 790 | result.Add(name, help, option.get('default')) |
| 791 | return result |
| 792 | |
| 793 | |
| 794 | def GetVersionComponents(): |
| 795 | MAJOR_VERSION_PATTERN = re.compile(r"#define\s+MAJOR_VERSION\s+(.*)") |
| 796 | MINOR_VERSION_PATTERN = re.compile(r"#define\s+MINOR_VERSION\s+(.*)") |
| 797 | BUILD_NUMBER_PATTERN = re.compile(r"#define\s+BUILD_NUMBER\s+(.*)") |
| 798 | PATCH_LEVEL_PATTERN = re.compile(r"#define\s+PATCH_LEVEL\s+(.*)") |
| 799 | |
| 800 | patterns = [MAJOR_VERSION_PATTERN, |
| 801 | MINOR_VERSION_PATTERN, |
| 802 | BUILD_NUMBER_PATTERN, |
| 803 | PATCH_LEVEL_PATTERN] |
| 804 | |
| 805 | source = open(join(root_dir, 'src', 'version.cc')).read() |
| 806 | version_components = [] |
| 807 | for pattern in patterns: |
| 808 | match = pattern.search(source) |
| 809 | if match: |
| 810 | version_components.append(match.group(1).strip()) |
| 811 | else: |
| 812 | version_components.append('0') |
| 813 | |
| 814 | return version_components |
| 815 | |
| 816 | |
| 817 | def GetVersion(): |
| 818 | version_components = GetVersionComponents() |
| 819 | |
| 820 | if version_components[len(version_components) - 1] == '0': |
| 821 | version_components.pop() |
| 822 | return '.'.join(version_components) |
| 823 | |
| 824 | |
| 825 | def GetSpecificSONAME(): |
| 826 | SONAME_PATTERN = re.compile(r"#define\s+SONAME\s+\"(.*)\"") |
| 827 | |
| 828 | source = open(join(root_dir, 'src', 'version.cc')).read() |
| 829 | match = SONAME_PATTERN.search(source) |
| 830 | |
| 831 | if match: |
| 832 | return match.group(1).strip() |
| 833 | else: |
| 834 | return '' |
| 835 | |
| 836 | |
| 837 | def SplitList(str): |
| 838 | return [ s for s in str.split(",") if len(s) > 0 ] |
| 839 | |
| 840 | |
| 841 | def IsLegal(env, option, values): |
| 842 | str = env[option] |
| 843 | for s in SplitList(str): |
| 844 | if not s in values: |
| 845 | Abort("Illegal value for option %s '%s'." % (option, s)) |
| 846 | return False |
| 847 | return True |
| 848 | |
| 849 | |
| 850 | def VerifyOptions(env): |
| 851 | if not IsLegal(env, 'mode', ['debug', 'release']): |
| 852 | return False |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 853 | if not IsLegal(env, 'sample', ["shell", "process", "lineprocessor"]): |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 854 | return False |
| 855 | if not IsLegal(env, 'regexp', ["native", "interpreted"]): |
| 856 | return False |
| 857 | if env['os'] == 'win32' and env['library'] == 'shared' and env['prof'] == 'on': |
| 858 | Abort("Profiling on windows only supported for static library.") |
| 859 | if env['prof'] == 'oprofile' and env['os'] != 'linux': |
| 860 | Abort("OProfile is only supported on Linux.") |
| 861 | if env['os'] == 'win32' and env['soname'] == 'on': |
| 862 | Abort("Shared Object soname not applicable for Windows.") |
| 863 | if env['soname'] == 'on' and env['library'] == 'static': |
| 864 | Abort("Shared Object soname not applicable for static library.") |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 865 | if env['os'] != 'win32' and env['pgo'] != 'off': |
| 866 | Abort("Profile guided optimization only supported on Windows.") |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame^] | 867 | if env['cache'] and not os.path.isdir(env['cache']): |
| 868 | Abort("The specified cache directory does not exist.") |
| 869 | if not (env['arch'] == 'arm' or env['simulator'] == 'arm') and ('unalignedaccesses' in ARGUMENTS): |
| 870 | print env['arch'] |
| 871 | print env['simulator'] |
| 872 | Abort("Option unalignedaccesses only supported for the ARM architecture.") |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 873 | for (name, option) in SIMPLE_OPTIONS.iteritems(): |
| 874 | if (not option.get('default')) and (name not in ARGUMENTS): |
| 875 | message = ("A value for option %s must be specified (%s)." % |
| 876 | (name, ", ".join(option['values']))) |
| 877 | Abort(message) |
| 878 | if not env[name] in option['values']: |
| 879 | message = ("Unknown %s value '%s'. Possible values are (%s)." % |
| 880 | (name, env[name], ", ".join(option['values']))) |
| 881 | Abort(message) |
| 882 | |
| 883 | |
| 884 | class BuildContext(object): |
| 885 | |
| 886 | def __init__(self, options, env_overrides, samples): |
| 887 | self.library_targets = [] |
| 888 | self.mksnapshot_targets = [] |
| 889 | self.cctest_targets = [] |
| 890 | self.sample_targets = [] |
| 891 | self.d8_targets = [] |
| 892 | self.options = options |
| 893 | self.env_overrides = env_overrides |
| 894 | self.samples = samples |
| 895 | self.use_snapshot = (options['snapshot'] != 'off') |
| 896 | self.build_snapshot = (options['snapshot'] == 'on') |
| 897 | self.flags = None |
| 898 | |
| 899 | def AddRelevantFlags(self, initial, flags): |
| 900 | result = initial.copy() |
| 901 | toolchain = self.options['toolchain'] |
| 902 | if toolchain in flags: |
| 903 | self.AppendFlags(result, flags[toolchain].get('all')) |
| 904 | for option in sorted(self.options.keys()): |
| 905 | value = self.options[option] |
| 906 | self.AppendFlags(result, flags[toolchain].get(option + ':' + value)) |
| 907 | self.AppendFlags(result, flags.get('all')) |
| 908 | return result |
| 909 | |
| 910 | def AddRelevantSubFlags(self, options, flags): |
| 911 | self.AppendFlags(options, flags.get('all')) |
| 912 | for option in sorted(self.options.keys()): |
| 913 | value = self.options[option] |
| 914 | self.AppendFlags(options, flags.get(option + ':' + value)) |
| 915 | |
| 916 | def GetRelevantSources(self, source): |
| 917 | result = [] |
| 918 | result += source.get('all', []) |
| 919 | for (name, value) in self.options.iteritems(): |
| 920 | source_value = source.get(name + ':' + value, []) |
| 921 | if type(source_value) == dict: |
| 922 | result += self.GetRelevantSources(source_value) |
| 923 | else: |
| 924 | result += source_value |
| 925 | return sorted(result) |
| 926 | |
| 927 | def AppendFlags(self, options, added): |
| 928 | if not added: |
| 929 | return |
| 930 | for (key, value) in added.iteritems(): |
| 931 | if key.find(':') != -1: |
| 932 | self.AddRelevantSubFlags(options, { key: value }) |
| 933 | else: |
| 934 | if not key in options: |
| 935 | options[key] = value |
| 936 | else: |
| 937 | prefix = options[key] |
| 938 | if isinstance(prefix, StringTypes): prefix = prefix.split() |
| 939 | options[key] = prefix + value |
| 940 | |
| 941 | def ConfigureObject(self, env, input, **kw): |
| 942 | if (kw.has_key('CPPPATH') and env.has_key('CPPPATH')): |
| 943 | kw['CPPPATH'] += env['CPPPATH'] |
| 944 | if self.options['library'] == 'static': |
| 945 | return env.StaticObject(input, **kw) |
| 946 | else: |
| 947 | return env.SharedObject(input, **kw) |
| 948 | |
| 949 | def ApplyEnvOverrides(self, env): |
| 950 | if not self.env_overrides: |
| 951 | return |
| 952 | if type(env['ENV']) == DictType: |
| 953 | env['ENV'].update(**self.env_overrides) |
| 954 | else: |
| 955 | env['ENV'] = self.env_overrides |
| 956 | |
| 957 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 958 | def PostprocessOptions(options, os): |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 959 | # Adjust architecture if the simulator option has been set |
| 960 | if (options['simulator'] != 'none') and (options['arch'] != options['simulator']): |
| 961 | if 'arch' in ARGUMENTS: |
| 962 | # Print a warning if arch has explicitly been set |
| 963 | print "Warning: forcing architecture to match simulator (%s)" % options['simulator'] |
| 964 | options['arch'] = options['simulator'] |
| 965 | if (options['prof'] != 'off') and (options['profilingsupport'] == 'off'): |
| 966 | # Print a warning if profiling is enabled without profiling support |
| 967 | print "Warning: forcing profilingsupport on when prof is on" |
| 968 | options['profilingsupport'] = 'on' |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 969 | if os == 'win32' and options['pgo'] != 'off' and options['msvcltcg'] == 'off': |
| 970 | if 'msvcltcg' in ARGUMENTS: |
| 971 | print "Warning: forcing msvcltcg on as it is required for pgo (%s)" % options['pgo'] |
| 972 | options['msvcltcg'] = 'on' |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 973 | if options['arch'] == 'mips': |
| 974 | if ('regexp' in ARGUMENTS) and options['regexp'] == 'native': |
| 975 | # Print a warning if native regexp is specified for mips |
| 976 | print "Warning: forcing regexp to interpreted for mips" |
| 977 | options['regexp'] = 'interpreted' |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 978 | |
| 979 | |
| 980 | def ParseEnvOverrides(arg, imports): |
| 981 | # The environment overrides are in the format NAME0:value0,NAME1:value1,... |
| 982 | # The environment imports are in the format NAME0,NAME1,... |
| 983 | overrides = {} |
| 984 | for var in imports.split(','): |
| 985 | if var in os.environ: |
| 986 | overrides[var] = os.environ[var] |
| 987 | for override in arg.split(','): |
| 988 | pos = override.find(':') |
| 989 | if pos == -1: |
| 990 | continue |
| 991 | overrides[override[:pos].strip()] = override[pos+1:].strip() |
| 992 | return overrides |
| 993 | |
| 994 | |
| 995 | def BuildSpecific(env, mode, env_overrides): |
| 996 | options = {'mode': mode} |
| 997 | for option in SIMPLE_OPTIONS: |
| 998 | options[option] = env[option] |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 999 | PostprocessOptions(options, env['os']) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1000 | |
| 1001 | context = BuildContext(options, env_overrides, samples=SplitList(env['sample'])) |
| 1002 | |
| 1003 | # Remove variables which can't be imported from the user's external |
| 1004 | # environment into a construction environment. |
| 1005 | user_environ = os.environ.copy() |
| 1006 | try: |
| 1007 | del user_environ['ENV'] |
| 1008 | except KeyError: |
| 1009 | pass |
| 1010 | |
| 1011 | library_flags = context.AddRelevantFlags(user_environ, LIBRARY_FLAGS) |
| 1012 | v8_flags = context.AddRelevantFlags(library_flags, V8_EXTRA_FLAGS) |
| 1013 | mksnapshot_flags = context.AddRelevantFlags(library_flags, MKSNAPSHOT_EXTRA_FLAGS) |
| 1014 | dtoa_flags = context.AddRelevantFlags(library_flags, DTOA_EXTRA_FLAGS) |
| 1015 | cctest_flags = context.AddRelevantFlags(v8_flags, CCTEST_EXTRA_FLAGS) |
| 1016 | sample_flags = context.AddRelevantFlags(user_environ, SAMPLE_FLAGS) |
| 1017 | d8_flags = context.AddRelevantFlags(library_flags, D8_FLAGS) |
| 1018 | |
| 1019 | context.flags = { |
| 1020 | 'v8': v8_flags, |
| 1021 | 'mksnapshot': mksnapshot_flags, |
| 1022 | 'dtoa': dtoa_flags, |
| 1023 | 'cctest': cctest_flags, |
| 1024 | 'sample': sample_flags, |
| 1025 | 'd8': d8_flags |
| 1026 | } |
| 1027 | |
| 1028 | # Generate library base name. |
| 1029 | target_id = mode |
| 1030 | suffix = SUFFIXES[target_id] |
| 1031 | library_name = 'v8' + suffix |
| 1032 | version = GetVersion() |
| 1033 | if context.options['soname'] == 'on': |
| 1034 | # When building shared object with SONAME version the library name. |
| 1035 | library_name += '-' + version |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1036 | |
| 1037 | # Generate library SONAME if required by the build. |
| 1038 | if context.options['soname'] == 'on': |
| 1039 | soname = GetSpecificSONAME() |
| 1040 | if soname == '': |
| 1041 | soname = 'lib' + library_name + '.so' |
| 1042 | env['SONAME'] = soname |
| 1043 | |
| 1044 | # Build the object files by invoking SCons recursively. |
| 1045 | (object_files, shell_files, mksnapshot) = env.SConscript( |
| 1046 | join('src', 'SConscript'), |
| 1047 | build_dir=join('obj', target_id), |
| 1048 | exports='context', |
| 1049 | duplicate=False |
| 1050 | ) |
| 1051 | |
| 1052 | context.mksnapshot_targets.append(mksnapshot) |
| 1053 | |
| 1054 | # Link the object files into a library. |
| 1055 | env.Replace(**context.flags['v8']) |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1056 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1057 | context.ApplyEnvOverrides(env) |
| 1058 | if context.options['library'] == 'static': |
| 1059 | library = env.StaticLibrary(library_name, object_files) |
| 1060 | else: |
| 1061 | # There seems to be a glitch in the way scons decides where to put |
| 1062 | # PDB files when compiling using MSVC so we specify it manually. |
| 1063 | # This should not affect any other platforms. |
| 1064 | pdb_name = library_name + '.dll.pdb' |
| 1065 | library = env.SharedLibrary(library_name, object_files, PDB=pdb_name) |
| 1066 | context.library_targets.append(library) |
| 1067 | |
| 1068 | d8_env = Environment() |
| 1069 | d8_env.Replace(**context.flags['d8']) |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1070 | context.ApplyEnvOverrides(d8_env) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1071 | shell = d8_env.Program('d8' + suffix, object_files + shell_files) |
| 1072 | context.d8_targets.append(shell) |
| 1073 | |
| 1074 | for sample in context.samples: |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1075 | sample_env = Environment() |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1076 | sample_env.Replace(**context.flags['sample']) |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1077 | sample_env.Prepend(LIBS=[library_name]) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1078 | context.ApplyEnvOverrides(sample_env) |
| 1079 | sample_object = sample_env.SConscript( |
| 1080 | join('samples', 'SConscript'), |
| 1081 | build_dir=join('obj', 'sample', sample, target_id), |
| 1082 | exports='sample context', |
| 1083 | duplicate=False |
| 1084 | ) |
| 1085 | sample_name = sample + suffix |
| 1086 | sample_program = sample_env.Program(sample_name, sample_object) |
| 1087 | sample_env.Depends(sample_program, library) |
| 1088 | context.sample_targets.append(sample_program) |
| 1089 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1090 | cctest_env = env.Copy() |
| 1091 | cctest_env.Prepend(LIBS=[library_name]) |
| 1092 | cctest_program = cctest_env.SConscript( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1093 | join('test', 'cctest', 'SConscript'), |
| 1094 | build_dir=join('obj', 'test', target_id), |
| 1095 | exports='context object_files', |
| 1096 | duplicate=False |
| 1097 | ) |
| 1098 | context.cctest_targets.append(cctest_program) |
| 1099 | |
| 1100 | return context |
| 1101 | |
| 1102 | |
| 1103 | def Build(): |
| 1104 | opts = GetOptions() |
| 1105 | env = Environment(options=opts) |
| 1106 | Help(opts.GenerateHelpText(env)) |
| 1107 | VerifyOptions(env) |
| 1108 | env_overrides = ParseEnvOverrides(env['env'], env['importenv']) |
| 1109 | |
| 1110 | SourceSignatures(env['sourcesignatures']) |
| 1111 | |
| 1112 | libraries = [] |
| 1113 | mksnapshots = [] |
| 1114 | cctests = [] |
| 1115 | samples = [] |
| 1116 | d8s = [] |
| 1117 | modes = SplitList(env['mode']) |
| 1118 | for mode in modes: |
| 1119 | context = BuildSpecific(env.Copy(), mode, env_overrides) |
| 1120 | libraries += context.library_targets |
| 1121 | mksnapshots += context.mksnapshot_targets |
| 1122 | cctests += context.cctest_targets |
| 1123 | samples += context.sample_targets |
| 1124 | d8s += context.d8_targets |
| 1125 | |
| 1126 | env.Alias('library', libraries) |
| 1127 | env.Alias('mksnapshot', mksnapshots) |
| 1128 | env.Alias('cctests', cctests) |
| 1129 | env.Alias('sample', samples) |
| 1130 | env.Alias('d8', d8s) |
| 1131 | |
| 1132 | if env['sample']: |
| 1133 | env.Default('sample') |
| 1134 | else: |
| 1135 | env.Default('library') |
| 1136 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame^] | 1137 | if env['cache']: |
| 1138 | CacheDir(env['cache']) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1139 | |
| 1140 | # We disable deprecation warnings because we need to be able to use |
| 1141 | # env.Copy without getting warnings for compatibility with older |
| 1142 | # version of scons. Also, there's a bug in some revisions that |
| 1143 | # doesn't allow this flag to be set, so we swallow any exceptions. |
| 1144 | # Lovely. |
| 1145 | try: |
| 1146 | SetOption('warn', 'no-deprecated') |
| 1147 | except: |
| 1148 | pass |
| 1149 | |
| 1150 | |
| 1151 | Build() |