blob: 017bcad310b2dc5ff667501d49462848c40ac7ba [file] [log] [blame]
Steve Block6ded16b2010-05-10 14:33:55 +01001# Copyright 2010 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002# 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
28import platform
29import re
30import sys
31import os
32from os.path import join, dirname, abspath
33from types import DictType, StringTypes
34root_dir = dirname(File('SConstruct').rfile().abspath)
Steve Block1e0659c2011-05-24 12:43:12 +010035sys.path.insert(0, join(root_dir, 'tools'))
Steve Blocka7e24c12009-10-30 11:49:00 +000036import js2c, utils
37
Steve Blocka7e24c12009-10-30 11:49:00 +000038# 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.
41ANDROID_TOP = os.environ.get('TOP')
42if ANDROID_TOP is None:
43 ANDROID_TOP=""
44
Steve Block6ded16b2010-05-10 14:33:55 +010045# ARM_TARGET_LIB is the path to the dynamic library to use on the target
Kristian Monsen50ef84f2010-07-29 15:18:00 +010046# machine if cross-compiling to an arm machine. You will also need to set
Steve Block6ded16b2010-05-10 14:33:55 +010047# the additional cross-compiling environment variables to the cross compiler.
48ARM_TARGET_LIB = os.environ.get('ARM_TARGET_LIB')
49if 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']
54else:
55 ARM_LINK_FLAGS = []
56
Iain Merrick75681382010-08-19 15:07:18 +010057GCC_EXTRA_CCFLAGS = []
58GCC_DTOA_EXTRA_CCFLAGS = []
Steve Blocka7e24c12009-10-30 11:49:00 +000059
Steve Block6ded16b2010-05-10 14:33:55 +010060ANDROID_FLAGS = ['-march=armv7-a',
61 '-mtune=cortex-a8',
62 '-mfloat-abi=softfp',
63 '-mfpu=vfp',
Steve Blocka7e24c12009-10-30 11:49:00 +000064 '-fpic',
65 '-mthumb-interwork',
66 '-funwind-tables',
67 '-fstack-protector',
68 '-fno-short-enums',
69 '-fmessage-length=0',
70 '-finline-functions',
71 '-fno-inline-functions-called-once',
72 '-fgcse-after-reload',
73 '-frerun-cse-after-loop',
74 '-frename-registers',
75 '-fomit-frame-pointer',
Steve Blocka7e24c12009-10-30 11:49:00 +000076 '-finline-limit=64',
Steve Block6ded16b2010-05-10 14:33:55 +010077 '-DCAN_USE_VFP_INSTRUCTIONS=1',
78 '-DCAN_USE_ARMV7_INSTRUCTIONS=1',
Kristian Monsen25f61362010-05-21 11:50:48 +010079 '-DCAN_USE_UNALIGNED_ACCESSES=1',
Steve Blocka7e24c12009-10-30 11:49:00 +000080 '-MD']
81
82ANDROID_INCLUDES = [ANDROID_TOP + '/bionic/libc/arch-arm/include',
83 ANDROID_TOP + '/bionic/libc/include',
84 ANDROID_TOP + '/bionic/libstdc++/include',
85 ANDROID_TOP + '/bionic/libc/kernel/common',
86 ANDROID_TOP + '/bionic/libc/kernel/arch-arm',
87 ANDROID_TOP + '/bionic/libm/include',
88 ANDROID_TOP + '/bionic/libm/include/arch/arm',
89 ANDROID_TOP + '/bionic/libthread_db/include',
90 ANDROID_TOP + '/frameworks/base/include',
91 ANDROID_TOP + '/system/core/include']
92
93ANDROID_LINKFLAGS = ['-nostdlib',
94 '-Bdynamic',
95 '-Wl,-T,' + ANDROID_TOP + '/build/core/armelf.x',
96 '-Wl,-dynamic-linker,/system/bin/linker',
97 '-Wl,--gc-sections',
98 '-Wl,-z,nocopyreloc',
99 '-Wl,-rpath-link=' + ANDROID_TOP + '/out/target/product/generic/obj/lib',
100 ANDROID_TOP + '/out/target/product/generic/obj/lib/crtbegin_dynamic.o',
Steve Block6ded16b2010-05-10 14:33:55 +0100101 ANDROID_TOP + '/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/interwork/libgcc.a',
Steve Blocka7e24c12009-10-30 11:49:00 +0000102 ANDROID_TOP + '/out/target/product/generic/obj/lib/crtend_android.o'];
103
104LIBRARY_FLAGS = {
105 'all': {
106 'CPPPATH': [join(root_dir, 'src')],
Steve Block6ded16b2010-05-10 14:33:55 +0100107 'regexp:interpreted': {
108 'CPPDEFINES': ['V8_INTERPRETED_REGEXP']
Steve Blocka7e24c12009-10-30 11:49:00 +0000109 },
110 'mode:debug': {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100111 'CPPDEFINES': ['V8_ENABLE_CHECKS', 'OBJECT_PRINT']
Steve Blocka7e24c12009-10-30 11:49:00 +0000112 },
Steve Block6ded16b2010-05-10 14:33:55 +0100113 'vmstate:on': {
114 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING'],
115 },
Ben Murdochb0fe1622011-05-05 13:52:32 +0100116 'objectprint:on': {
117 'CPPDEFINES': ['OBJECT_PRINT'],
118 },
Steve Block6ded16b2010-05-10 14:33:55 +0100119 'protectheap:on': {
120 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING', 'ENABLE_HEAP_PROTECTION'],
121 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000122 'profilingsupport:on': {
Steve Block6ded16b2010-05-10 14:33:55 +0100123 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING', 'ENABLE_LOGGING_AND_PROFILING'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000124 },
125 'debuggersupport:on': {
126 'CPPDEFINES': ['ENABLE_DEBUGGER_SUPPORT'],
Ben Murdochb8e0da22011-05-16 14:20:40 +0100127 },
128 'inspector:on': {
129 'CPPDEFINES': ['INSPECTOR'],
Steve Block1e0659c2011-05-24 12:43:12 +0100130 },
131 'liveobjectlist:on': {
132 'CPPDEFINES': ['ENABLE_DEBUGGER_SUPPORT', 'INSPECTOR',
133 'LIVE_OBJECT_LIST', 'OBJECT_PRINT'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000134 }
135 },
136 'gcc': {
137 'all': {
138 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
139 'CXXFLAGS': ['$CCFLAGS', '-fno-rtti', '-fno-exceptions'],
140 },
141 'visibility:hidden': {
142 # Use visibility=default to disable this.
143 'CXXFLAGS': ['-fvisibility=hidden']
144 },
145 'mode:debug': {
146 'CCFLAGS': ['-g', '-O0'],
147 'CPPDEFINES': ['ENABLE_DISASSEMBLER', 'DEBUG'],
148 'os:android': {
149 'CCFLAGS': ['-mthumb']
150 }
151 },
152 'mode:release': {
153 'CCFLAGS': ['-O3', '-fomit-frame-pointer', '-fdata-sections',
154 '-ffunction-sections'],
155 'os:android': {
156 'CCFLAGS': ['-mthumb', '-Os'],
157 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
158 }
159 },
160 'os:linux': {
161 'CCFLAGS': ['-ansi'] + GCC_EXTRA_CCFLAGS,
162 'library:shared': {
163 'CPPDEFINES': ['V8_SHARED'],
164 'LIBS': ['pthread']
165 }
166 },
167 'os:macos': {
168 'CCFLAGS': ['-ansi', '-mmacosx-version-min=10.4'],
Leon Clarkee46be812010-01-19 14:06:41 +0000169 'library:shared': {
170 'CPPDEFINES': ['V8_SHARED']
171 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000172 },
173 'os:freebsd': {
174 'CPPPATH' : ['/usr/local/include'],
175 'LIBPATH' : ['/usr/local/lib'],
176 'CCFLAGS': ['-ansi'],
177 },
Steve Blockd0582a62009-12-15 09:54:21 +0000178 'os:openbsd': {
179 'CPPPATH' : ['/usr/local/include'],
180 'LIBPATH' : ['/usr/local/lib'],
181 'CCFLAGS': ['-ansi'],
182 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000183 'os:solaris': {
Kristian Monsen25f61362010-05-21 11:50:48 +0100184 # On Solaris, to get isinf, INFINITY, fpclassify and other macros one
185 # needs to define __C99FEATURES__.
186 'CPPDEFINES': ['__C99FEATURES__'],
Leon Clarked91b9f72010-01-27 17:25:45 +0000187 'CPPPATH' : ['/usr/local/include'],
188 'LIBPATH' : ['/usr/local/lib'],
189 'CCFLAGS': ['-ansi'],
190 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000191 'os:win32': {
192 'CCFLAGS': ['-DWIN32'],
193 'CXXFLAGS': ['-DWIN32'],
194 },
195 'os:android': {
196 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__',
197 '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'],
198 'CCFLAGS': ANDROID_FLAGS,
199 'WARNINGFLAGS': ['-Wall', '-Wno-unused', '-Werror=return-type',
200 '-Wstrict-aliasing=2'],
201 'CPPPATH': ANDROID_INCLUDES,
202 },
203 'arch:ia32': {
204 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'],
205 'CCFLAGS': ['-m32'],
206 'LINKFLAGS': ['-m32']
207 },
208 'arch:arm': {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100209 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
210 'unalignedaccesses:on' : {
211 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=1']
212 },
213 'unalignedaccesses:off' : {
214 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=0']
215 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000216 },
217 'simulator:arm': {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100218 'CCFLAGS': ['-m32'],
Ben Murdochf87a2032010-10-22 12:50:53 +0100219 'LINKFLAGS': ['-m32'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000220 },
Andrei Popescu31002712010-02-23 13:46:05 +0000221 'arch:mips': {
222 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
223 'simulator:none': {
224 'CCFLAGS': ['-EL', '-mips32r2', '-Wa,-mips32r2', '-fno-inline'],
225 'LDFLAGS': ['-EL']
226 }
227 },
228 'simulator:mips': {
229 'CCFLAGS': ['-m32'],
Ben Murdochf87a2032010-10-22 12:50:53 +0100230 'LINKFLAGS': ['-m32'],
Andrei Popescu31002712010-02-23 13:46:05 +0000231 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 'arch:x64': {
233 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
234 'CCFLAGS': ['-m64'],
235 'LINKFLAGS': ['-m64'],
236 },
Ben Murdochb8e0da22011-05-16 14:20:40 +0100237 'gdbjit:on': {
238 'CPPDEFINES': ['ENABLE_GDB_JIT_INTERFACE']
Steve Blocka7e24c12009-10-30 11:49:00 +0000239 }
240 },
241 'msvc': {
242 'all': {
243 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
244 'CXXFLAGS': ['$CCFLAGS', '/GR-', '/Gy'],
245 'CPPDEFINES': ['WIN32'],
246 'LINKFLAGS': ['/INCREMENTAL:NO', '/NXCOMPAT', '/IGNORE:4221'],
247 'CCPDBFLAGS': ['/Zi']
248 },
249 'verbose:off': {
250 'DIALECTFLAGS': ['/nologo'],
251 'ARFLAGS': ['/NOLOGO']
252 },
253 'arch:ia32': {
254 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', '_USE_32BIT_TIME_T'],
255 'LINKFLAGS': ['/MACHINE:X86'],
256 'ARFLAGS': ['/MACHINE:X86']
257 },
258 'arch:x64': {
259 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
260 'LINKFLAGS': ['/MACHINE:X64'],
261 'ARFLAGS': ['/MACHINE:X64']
262 },
263 'mode:debug': {
264 'CCFLAGS': ['/Od', '/Gm'],
265 'CPPDEFINES': ['_DEBUG', 'ENABLE_DISASSEMBLER', 'DEBUG'],
266 'LINKFLAGS': ['/DEBUG'],
267 'msvcrt:static': {
268 'CCFLAGS': ['/MTd']
269 },
270 'msvcrt:shared': {
271 'CCFLAGS': ['/MDd']
272 }
273 },
274 'mode:release': {
275 'CCFLAGS': ['/O2'],
276 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
277 'msvcrt:static': {
278 'CCFLAGS': ['/MT']
279 },
280 'msvcrt:shared': {
281 'CCFLAGS': ['/MD']
282 },
283 'msvcltcg:on': {
284 'CCFLAGS': ['/GL'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000285 'ARFLAGS': ['/LTCG'],
Steve Block6ded16b2010-05-10 14:33:55 +0100286 'pgo:off': {
287 'LINKFLAGS': ['/LTCG'],
288 },
289 'pgo:instrument': {
290 'LINKFLAGS': ['/LTCG:PGI']
291 },
292 'pgo:optimize': {
293 'LINKFLAGS': ['/LTCG:PGO']
294 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000295 }
296 }
297 }
298}
299
300
301V8_EXTRA_FLAGS = {
302 'gcc': {
303 'all': {
304 'WARNINGFLAGS': ['-Wall',
305 '-Werror',
306 '-W',
307 '-Wno-unused-parameter',
308 '-Wnon-virtual-dtor']
309 },
310 'os:win32': {
311 'WARNINGFLAGS': ['-pedantic', '-Wno-long-long']
312 },
313 'os:linux': {
314 'WARNINGFLAGS': ['-pedantic'],
315 'library:shared': {
316 'soname:on': {
317 'LINKFLAGS': ['-Wl,-soname,${SONAME}']
318 }
319 }
320 },
321 'os:macos': {
322 'WARNINGFLAGS': ['-pedantic']
323 },
324 'disassembler:on': {
325 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
326 }
327 },
328 'msvc': {
329 'all': {
Steve Block1e0659c2011-05-24 12:43:12 +0100330 'WARNINGFLAGS': ['/W3', '/WX', '/wd4351', '/wd4355', '/wd4800']
Steve Blocka7e24c12009-10-30 11:49:00 +0000331 },
332 'library:shared': {
333 'CPPDEFINES': ['BUILDING_V8_SHARED'],
334 'LIBS': ['winmm', 'ws2_32']
335 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000336 'arch:arm': {
337 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
338 # /wd4996 is to silence the warning about sscanf
339 # used by the arm simulator.
340 'WARNINGFLAGS': ['/wd4996']
341 },
Andrei Popescu31002712010-02-23 13:46:05 +0000342 'arch:mips': {
343 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
344 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000345 'disassembler:on': {
346 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
347 }
348 }
349}
350
351
352MKSNAPSHOT_EXTRA_FLAGS = {
353 'gcc': {
354 'os:linux': {
355 'LIBS': ['pthread'],
356 },
357 'os:macos': {
358 'LIBS': ['pthread'],
359 },
360 'os:freebsd': {
361 'LIBS': ['execinfo', 'pthread']
362 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000363 'os:solaris': {
364 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
365 'LINKFLAGS': ['-mt']
366 },
Steve Blockd0582a62009-12-15 09:54:21 +0000367 'os:openbsd': {
368 'LIBS': ['execinfo', 'pthread']
369 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000370 'os:win32': {
371 'LIBS': ['winmm', 'ws2_32'],
372 },
373 },
374 'msvc': {
375 'all': {
376 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
377 'LIBS': ['winmm', 'ws2_32']
378 }
379 }
380}
381
382
383DTOA_EXTRA_FLAGS = {
384 'gcc': {
385 'all': {
386 'WARNINGFLAGS': ['-Werror', '-Wno-uninitialized'],
387 'CCFLAGS': GCC_DTOA_EXTRA_CCFLAGS
388 }
389 },
390 'msvc': {
391 'all': {
392 'WARNINGFLAGS': ['/WX', '/wd4018', '/wd4244']
393 }
394 }
395}
396
397
398CCTEST_EXTRA_FLAGS = {
399 'all': {
400 'CPPPATH': [join(root_dir, 'src')],
Steve Blocka7e24c12009-10-30 11:49:00 +0000401 },
402 'gcc': {
403 'all': {
404 'LIBPATH': [abspath('.')]
405 },
406 'os:linux': {
407 'LIBS': ['pthread'],
408 },
409 'os:macos': {
410 'LIBS': ['pthread'],
411 },
412 'os:freebsd': {
413 'LIBS': ['execinfo', 'pthread']
414 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000415 'os:solaris': {
416 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
417 'LINKFLAGS': ['-mt']
418 },
Steve Blockd0582a62009-12-15 09:54:21 +0000419 'os:openbsd': {
420 'LIBS': ['execinfo', 'pthread']
421 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000422 'os:win32': {
423 'LIBS': ['winmm', 'ws2_32']
424 },
425 'os:android': {
426 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__',
427 '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'],
428 'CCFLAGS': ANDROID_FLAGS,
429 'CPPPATH': ANDROID_INCLUDES,
Steve Block6ded16b2010-05-10 14:33:55 +0100430 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib',
431 ANDROID_TOP + '/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/interwork'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000432 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100433 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000434 'mode:release': {
435 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
436 }
437 },
Steve Block6ded16b2010-05-10 14:33:55 +0100438 'arch:arm': {
439 'LINKFLAGS': ARM_LINK_FLAGS
440 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000441 },
442 'msvc': {
443 'all': {
444 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
445 'LIBS': ['winmm', 'ws2_32']
446 },
447 'library:shared': {
448 'CPPDEFINES': ['USING_V8_SHARED']
449 },
450 'arch:ia32': {
451 'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
452 },
453 'arch:x64': {
Steve Block3ce2e202009-11-05 08:53:23 +0000454 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
455 'LINKFLAGS': ['/STACK:2091752']
Steve Blocka7e24c12009-10-30 11:49:00 +0000456 },
457 }
458}
459
460
461SAMPLE_FLAGS = {
462 'all': {
463 'CPPPATH': [join(abspath('.'), 'include')],
Steve Blocka7e24c12009-10-30 11:49:00 +0000464 },
465 'gcc': {
466 'all': {
467 'LIBPATH': ['.'],
468 'CCFLAGS': ['-fno-rtti', '-fno-exceptions']
469 },
470 'os:linux': {
471 'LIBS': ['pthread'],
472 },
473 'os:macos': {
474 'LIBS': ['pthread'],
475 },
476 'os:freebsd': {
477 'LIBPATH' : ['/usr/local/lib'],
Steve Blockd0582a62009-12-15 09:54:21 +0000478 'LIBS': ['execinfo', 'pthread']
479 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000480 'os:solaris': {
481 'LIBPATH' : ['/usr/local/lib'],
482 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
483 'LINKFLAGS': ['-mt']
484 },
Steve Blockd0582a62009-12-15 09:54:21 +0000485 'os:openbsd': {
486 'LIBPATH' : ['/usr/local/lib'],
487 'LIBS': ['execinfo', 'pthread']
Steve Blocka7e24c12009-10-30 11:49:00 +0000488 },
489 'os:win32': {
490 'LIBS': ['winmm', 'ws2_32']
491 },
492 'os:android': {
493 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__',
494 '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'],
495 'CCFLAGS': ANDROID_FLAGS,
496 'CPPPATH': ANDROID_INCLUDES,
Steve Block6ded16b2010-05-10 14:33:55 +0100497 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib',
498 ANDROID_TOP + '/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/lib/gcc/arm-eabi/4.4.0/interwork'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000499 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100500 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000501 'mode:release': {
502 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
503 }
504 },
Steve Block6ded16b2010-05-10 14:33:55 +0100505 'arch:arm': {
506 'LINKFLAGS': ARM_LINK_FLAGS
507 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000508 'arch:ia32': {
509 'CCFLAGS': ['-m32'],
510 'LINKFLAGS': ['-m32']
511 },
512 'arch:x64': {
513 'CCFLAGS': ['-m64'],
514 'LINKFLAGS': ['-m64']
515 },
Andrei Popescu31002712010-02-23 13:46:05 +0000516 'arch:mips': {
517 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
518 'simulator:none': {
519 'CCFLAGS': ['-EL', '-mips32r2', '-Wa,-mips32r2', '-fno-inline'],
520 'LINKFLAGS': ['-EL'],
521 'LDFLAGS': ['-EL']
522 }
523 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000524 'simulator:arm': {
525 'CCFLAGS': ['-m32'],
526 'LINKFLAGS': ['-m32']
527 },
Andrei Popescu31002712010-02-23 13:46:05 +0000528 'simulator:mips': {
529 'CCFLAGS': ['-m32'],
530 'LINKFLAGS': ['-m32']
531 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000532 'mode:release': {
533 'CCFLAGS': ['-O2']
534 },
535 'mode:debug': {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100536 'CCFLAGS': ['-g', '-O0'],
537 'CPPDEFINES': ['DEBUG']
Steve Blocka7e24c12009-10-30 11:49:00 +0000538 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000539 },
540 'msvc': {
541 'all': {
542 'LIBS': ['winmm', 'ws2_32']
543 },
544 'verbose:off': {
545 'CCFLAGS': ['/nologo'],
546 'LINKFLAGS': ['/NOLOGO']
547 },
548 'verbose:on': {
549 'LINKFLAGS': ['/VERBOSE']
550 },
551 'library:shared': {
552 'CPPDEFINES': ['USING_V8_SHARED']
553 },
554 'prof:on': {
555 'LINKFLAGS': ['/MAP']
556 },
557 'mode:release': {
558 'CCFLAGS': ['/O2'],
559 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
560 'msvcrt:static': {
561 'CCFLAGS': ['/MT']
562 },
563 'msvcrt:shared': {
564 'CCFLAGS': ['/MD']
565 },
566 'msvcltcg:on': {
567 'CCFLAGS': ['/GL'],
Steve Block6ded16b2010-05-10 14:33:55 +0100568 'pgo:off': {
569 'LINKFLAGS': ['/LTCG'],
570 },
571 },
572 'pgo:instrument': {
573 'LINKFLAGS': ['/LTCG:PGI']
574 },
575 'pgo:optimize': {
576 'LINKFLAGS': ['/LTCG:PGO']
Steve Blocka7e24c12009-10-30 11:49:00 +0000577 }
578 },
579 'arch:ia32': {
580 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'],
581 'LINKFLAGS': ['/MACHINE:X86']
582 },
583 'arch:x64': {
584 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
Steve Block3ce2e202009-11-05 08:53:23 +0000585 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2091752']
Steve Blocka7e24c12009-10-30 11:49:00 +0000586 },
587 'mode:debug': {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100588 'CCFLAGS': ['/Od'],
589 'LINKFLAGS': ['/DEBUG'],
590 'CPPDEFINES': ['DEBUG'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000591 'msvcrt:static': {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100592 'CCFLAGS': ['/MTd']
Steve Blocka7e24c12009-10-30 11:49:00 +0000593 },
594 'msvcrt:shared': {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100595 'CCFLAGS': ['/MDd']
Steve Blocka7e24c12009-10-30 11:49:00 +0000596 }
597 }
598 }
599}
600
601
602D8_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 Clarked91b9f72010-01-27 17:25:45 +0000616 'os:solaris': {
617 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
618 'LINKFLAGS': ['-mt']
619 },
Steve Blockd0582a62009-12-15 09:54:21 +0000620 'os:openbsd': {
621 'LIBS': ['pthread'],
622 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000623 'os:android': {
Steve Block6ded16b2010-05-10 14:33:55 +0100624 '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 Blocka7e24c12009-10-30 11:49:00 +0000626 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100627 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000628 },
629 'os:win32': {
630 'LIBS': ['winmm', 'ws2_32'],
631 },
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100632 'arch:arm': {
633 'LINKFLAGS': ARM_LINK_FLAGS
634 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000635 },
636 'msvc': {
637 'all': {
638 'LIBS': ['winmm', 'ws2_32']
639 }
640 }
641}
642
643
644SUFFIXES = {
645 'release': '',
646 'debug': '_g'
647}
648
649
650def Abort(message):
651 print message
652 sys.exit(1)
653
654
655def GuessToolchain(os):
656 tools = Environment()['TOOLS']
657 if 'gcc' in tools:
658 return 'gcc'
659 elif 'msvc' in tools:
660 return 'msvc'
661 else:
662 return None
663
664
Ben Murdochb0fe1622011-05-05 13:52:32 +0100665def GuessVisibility(os, toolchain):
666 if os == 'win32' and toolchain == 'gcc':
667 # MinGW can't do it.
668 return 'default'
Ben Murdochb8e0da22011-05-16 14:20:40 +0100669 elif os == 'solaris':
670 return 'default'
Ben Murdochb0fe1622011-05-05 13:52:32 +0100671 else:
672 return 'hidden'
673
674
Steve Blocka7e24c12009-10-30 11:49:00 +0000675OS_GUESS = utils.GuessOS()
676TOOLCHAIN_GUESS = GuessToolchain(OS_GUESS)
677ARCH_GUESS = utils.GuessArchitecture()
Ben Murdochb0fe1622011-05-05 13:52:32 +0100678VISIBILITY_GUESS = GuessVisibility(OS_GUESS, TOOLCHAIN_GUESS)
Steve Blocka7e24c12009-10-30 11:49:00 +0000679
680
681SIMPLE_OPTIONS = {
682 'toolchain': {
683 'values': ['gcc', 'msvc'],
684 'default': TOOLCHAIN_GUESS,
Ben Murdochf87a2032010-10-22 12:50:53 +0100685 'help': 'the toolchain to use (%s)' % TOOLCHAIN_GUESS
Steve Blocka7e24c12009-10-30 11:49:00 +0000686 },
687 'os': {
Leon Clarked91b9f72010-01-27 17:25:45 +0000688 'values': ['freebsd', 'linux', 'macos', 'win32', 'android', 'openbsd', 'solaris'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000689 'default': OS_GUESS,
Ben Murdochf87a2032010-10-22 12:50:53 +0100690 'help': 'the os to build for (%s)' % OS_GUESS
Steve Blocka7e24c12009-10-30 11:49:00 +0000691 },
692 'arch': {
Andrei Popescu31002712010-02-23 13:46:05 +0000693 'values':['arm', 'ia32', 'x64', 'mips'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000694 'default': ARCH_GUESS,
Ben Murdochf87a2032010-10-22 12:50:53 +0100695 'help': 'the architecture to build for (%s)' % ARCH_GUESS
Steve Blocka7e24c12009-10-30 11:49:00 +0000696 },
697 'regexp': {
698 'values': ['native', 'interpreted'],
699 'default': 'native',
700 'help': 'Whether to use native or interpreted regexp implementation'
701 },
702 'snapshot': {
703 'values': ['on', 'off', 'nobuild'],
704 'default': 'off',
705 'help': 'build using snapshots for faster start-up'
706 },
707 'prof': {
Steve Block1e0659c2011-05-24 12:43:12 +0100708 'values': ['on', 'off'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000709 'default': 'off',
710 'help': 'enable profiling of build target'
711 },
Ben Murdochb8e0da22011-05-16 14:20:40 +0100712 'gdbjit': {
713 'values': ['on', 'off'],
714 'default': 'off',
715 'help': 'enable GDB JIT interface'
716 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000717 'library': {
718 'values': ['static', 'shared'],
719 'default': 'static',
720 'help': 'the type of library to produce'
721 },
Steve Block6ded16b2010-05-10 14:33:55 +0100722 'vmstate': {
723 'values': ['on', 'off'],
724 'default': 'off',
725 'help': 'enable VM state tracking'
726 },
Ben Murdochb0fe1622011-05-05 13:52:32 +0100727 'objectprint': {
728 'values': ['on', 'off'],
729 'default': 'off',
730 'help': 'enable object printing'
731 },
Steve Block6ded16b2010-05-10 14:33:55 +0100732 'protectheap': {
733 'values': ['on', 'off'],
734 'default': 'off',
735 'help': 'enable heap protection'
736 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000737 'profilingsupport': {
738 'values': ['on', 'off'],
739 'default': 'on',
740 'help': 'enable profiling of JavaScript code'
741 },
742 'debuggersupport': {
743 'values': ['on', 'off'],
744 'default': 'on',
745 'help': 'enable debugging of JavaScript code'
746 },
Ben Murdochb8e0da22011-05-16 14:20:40 +0100747 'inspector': {
748 'values': ['on', 'off'],
749 'default': 'off',
750 'help': 'enable inspector features'
751 },
Steve Block1e0659c2011-05-24 12:43:12 +0100752 'liveobjectlist': {
753 'values': ['on', 'off'],
754 'default': 'off',
755 'help': 'enable live object list features in the debugger'
756 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000757 'soname': {
758 'values': ['on', 'off'],
759 'default': 'off',
760 'help': 'turn on setting soname for Linux shared library'
761 },
762 'msvcrt': {
763 'values': ['static', 'shared'],
764 'default': 'static',
765 'help': 'the type of Microsoft Visual C++ runtime library to use'
766 },
767 'msvcltcg': {
768 'values': ['on', 'off'],
769 'default': 'on',
770 'help': 'use Microsoft Visual C++ link-time code generation'
771 },
772 'simulator': {
Andrei Popescu31002712010-02-23 13:46:05 +0000773 'values': ['arm', 'mips', 'none'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000774 'default': 'none',
775 'help': 'build with simulator'
776 },
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100777 'unalignedaccesses': {
778 'values': ['default', 'on', 'off'],
779 'default': 'default',
780 'help': 'set whether the ARM target supports unaligned accesses'
781 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000782 'disassembler': {
783 'values': ['on', 'off'],
784 'default': 'off',
785 'help': 'enable the disassembler to inspect generated code'
786 },
787 'sourcesignatures': {
788 'values': ['MD5', 'timestamp'],
789 'default': 'MD5',
790 'help': 'set how the build system detects file changes'
791 },
792 'console': {
793 'values': ['dumb', 'readline'],
794 'default': 'dumb',
795 'help': 'the console to use for the d8 shell'
796 },
797 'verbose': {
798 'values': ['on', 'off'],
799 'default': 'off',
800 'help': 'more output from compiler and linker'
801 },
802 'visibility': {
803 'values': ['default', 'hidden'],
Ben Murdochb0fe1622011-05-05 13:52:32 +0100804 'default': VISIBILITY_GUESS,
805 'help': 'shared library symbol visibility (%s)' % VISIBILITY_GUESS
Leon Clarkee46be812010-01-19 14:06:41 +0000806 },
Steve Block6ded16b2010-05-10 14:33:55 +0100807 'pgo': {
808 'values': ['off', 'instrument', 'optimize'],
809 'default': 'off',
810 'help': 'select profile guided optimization variant',
Steve Blocka7e24c12009-10-30 11:49:00 +0000811 }
812}
813
814
815def GetOptions():
816 result = Options()
817 result.Add('mode', 'compilation mode (debug, release)', 'release')
Leon Clarkee46be812010-01-19 14:06:41 +0000818 result.Add('sample', 'build sample (shell, process, lineprocessor)', '')
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100819 result.Add('cache', 'directory to use for scons build cache', '')
Steve Blocka7e24c12009-10-30 11:49:00 +0000820 result.Add('env', 'override environment settings (NAME0:value0,NAME1:value1,...)', '')
821 result.Add('importenv', 'import environment settings (NAME0,NAME1,...)', '')
822 for (name, option) in SIMPLE_OPTIONS.iteritems():
823 help = '%s (%s)' % (name, ", ".join(option['values']))
824 result.Add(name, help, option.get('default'))
825 return result
826
827
828def GetVersionComponents():
829 MAJOR_VERSION_PATTERN = re.compile(r"#define\s+MAJOR_VERSION\s+(.*)")
830 MINOR_VERSION_PATTERN = re.compile(r"#define\s+MINOR_VERSION\s+(.*)")
831 BUILD_NUMBER_PATTERN = re.compile(r"#define\s+BUILD_NUMBER\s+(.*)")
832 PATCH_LEVEL_PATTERN = re.compile(r"#define\s+PATCH_LEVEL\s+(.*)")
833
834 patterns = [MAJOR_VERSION_PATTERN,
835 MINOR_VERSION_PATTERN,
836 BUILD_NUMBER_PATTERN,
837 PATCH_LEVEL_PATTERN]
838
839 source = open(join(root_dir, 'src', 'version.cc')).read()
840 version_components = []
841 for pattern in patterns:
842 match = pattern.search(source)
843 if match:
844 version_components.append(match.group(1).strip())
845 else:
846 version_components.append('0')
847
848 return version_components
849
850
851def GetVersion():
852 version_components = GetVersionComponents()
853
854 if version_components[len(version_components) - 1] == '0':
855 version_components.pop()
856 return '.'.join(version_components)
857
858
859def GetSpecificSONAME():
860 SONAME_PATTERN = re.compile(r"#define\s+SONAME\s+\"(.*)\"")
861
862 source = open(join(root_dir, 'src', 'version.cc')).read()
863 match = SONAME_PATTERN.search(source)
864
865 if match:
866 return match.group(1).strip()
867 else:
868 return ''
869
870
871def SplitList(str):
872 return [ s for s in str.split(",") if len(s) > 0 ]
873
874
875def IsLegal(env, option, values):
876 str = env[option]
877 for s in SplitList(str):
878 if not s in values:
879 Abort("Illegal value for option %s '%s'." % (option, s))
880 return False
881 return True
882
883
884def VerifyOptions(env):
885 if not IsLegal(env, 'mode', ['debug', 'release']):
886 return False
Leon Clarkee46be812010-01-19 14:06:41 +0000887 if not IsLegal(env, 'sample', ["shell", "process", "lineprocessor"]):
Steve Blocka7e24c12009-10-30 11:49:00 +0000888 return False
889 if not IsLegal(env, 'regexp', ["native", "interpreted"]):
890 return False
891 if env['os'] == 'win32' and env['library'] == 'shared' and env['prof'] == 'on':
892 Abort("Profiling on windows only supported for static library.")
Ben Murdochb8e0da22011-05-16 14:20:40 +0100893 if env['gdbjit'] == 'on' and (env['os'] != 'linux' or (env['arch'] != 'ia32' and env['arch'] != 'x64')):
894 Abort("GDBJIT interface is supported only for Intel-compatible (ia32 or x64) Linux target.")
Steve Blocka7e24c12009-10-30 11:49:00 +0000895 if env['os'] == 'win32' and env['soname'] == 'on':
896 Abort("Shared Object soname not applicable for Windows.")
897 if env['soname'] == 'on' and env['library'] == 'static':
898 Abort("Shared Object soname not applicable for static library.")
Steve Block6ded16b2010-05-10 14:33:55 +0100899 if env['os'] != 'win32' and env['pgo'] != 'off':
900 Abort("Profile guided optimization only supported on Windows.")
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100901 if env['cache'] and not os.path.isdir(env['cache']):
902 Abort("The specified cache directory does not exist.")
903 if not (env['arch'] == 'arm' or env['simulator'] == 'arm') and ('unalignedaccesses' in ARGUMENTS):
904 print env['arch']
905 print env['simulator']
906 Abort("Option unalignedaccesses only supported for the ARM architecture.")
Steve Blocka7e24c12009-10-30 11:49:00 +0000907 for (name, option) in SIMPLE_OPTIONS.iteritems():
908 if (not option.get('default')) and (name not in ARGUMENTS):
909 message = ("A value for option %s must be specified (%s)." %
910 (name, ", ".join(option['values'])))
911 Abort(message)
912 if not env[name] in option['values']:
913 message = ("Unknown %s value '%s'. Possible values are (%s)." %
914 (name, env[name], ", ".join(option['values'])))
915 Abort(message)
916
917
918class BuildContext(object):
919
920 def __init__(self, options, env_overrides, samples):
921 self.library_targets = []
922 self.mksnapshot_targets = []
923 self.cctest_targets = []
924 self.sample_targets = []
925 self.d8_targets = []
926 self.options = options
927 self.env_overrides = env_overrides
928 self.samples = samples
929 self.use_snapshot = (options['snapshot'] != 'off')
930 self.build_snapshot = (options['snapshot'] == 'on')
931 self.flags = None
932
933 def AddRelevantFlags(self, initial, flags):
934 result = initial.copy()
935 toolchain = self.options['toolchain']
936 if toolchain in flags:
937 self.AppendFlags(result, flags[toolchain].get('all'))
938 for option in sorted(self.options.keys()):
939 value = self.options[option]
940 self.AppendFlags(result, flags[toolchain].get(option + ':' + value))
941 self.AppendFlags(result, flags.get('all'))
942 return result
943
944 def AddRelevantSubFlags(self, options, flags):
945 self.AppendFlags(options, flags.get('all'))
946 for option in sorted(self.options.keys()):
947 value = self.options[option]
948 self.AppendFlags(options, flags.get(option + ':' + value))
949
950 def GetRelevantSources(self, source):
951 result = []
952 result += source.get('all', [])
953 for (name, value) in self.options.iteritems():
954 source_value = source.get(name + ':' + value, [])
955 if type(source_value) == dict:
956 result += self.GetRelevantSources(source_value)
957 else:
958 result += source_value
959 return sorted(result)
960
961 def AppendFlags(self, options, added):
962 if not added:
963 return
964 for (key, value) in added.iteritems():
965 if key.find(':') != -1:
966 self.AddRelevantSubFlags(options, { key: value })
967 else:
968 if not key in options:
969 options[key] = value
970 else:
971 prefix = options[key]
972 if isinstance(prefix, StringTypes): prefix = prefix.split()
973 options[key] = prefix + value
974
975 def ConfigureObject(self, env, input, **kw):
976 if (kw.has_key('CPPPATH') and env.has_key('CPPPATH')):
977 kw['CPPPATH'] += env['CPPPATH']
978 if self.options['library'] == 'static':
979 return env.StaticObject(input, **kw)
980 else:
981 return env.SharedObject(input, **kw)
982
983 def ApplyEnvOverrides(self, env):
984 if not self.env_overrides:
985 return
986 if type(env['ENV']) == DictType:
987 env['ENV'].update(**self.env_overrides)
988 else:
989 env['ENV'] = self.env_overrides
990
991
Steve Block6ded16b2010-05-10 14:33:55 +0100992def PostprocessOptions(options, os):
Steve Blocka7e24c12009-10-30 11:49:00 +0000993 # Adjust architecture if the simulator option has been set
994 if (options['simulator'] != 'none') and (options['arch'] != options['simulator']):
995 if 'arch' in ARGUMENTS:
996 # Print a warning if arch has explicitly been set
997 print "Warning: forcing architecture to match simulator (%s)" % options['simulator']
998 options['arch'] = options['simulator']
999 if (options['prof'] != 'off') and (options['profilingsupport'] == 'off'):
1000 # Print a warning if profiling is enabled without profiling support
1001 print "Warning: forcing profilingsupport on when prof is on"
1002 options['profilingsupport'] = 'on'
Steve Block6ded16b2010-05-10 14:33:55 +01001003 if os == 'win32' and options['pgo'] != 'off' and options['msvcltcg'] == 'off':
1004 if 'msvcltcg' in ARGUMENTS:
1005 print "Warning: forcing msvcltcg on as it is required for pgo (%s)" % options['pgo']
1006 options['msvcltcg'] = 'on'
Andrei Popescu31002712010-02-23 13:46:05 +00001007 if options['arch'] == 'mips':
1008 if ('regexp' in ARGUMENTS) and options['regexp'] == 'native':
1009 # Print a warning if native regexp is specified for mips
1010 print "Warning: forcing regexp to interpreted for mips"
1011 options['regexp'] = 'interpreted'
Steve Block1e0659c2011-05-24 12:43:12 +01001012 if options['liveobjectlist'] == 'on':
1013 if (options['debuggersupport'] != 'on') or (options['mode'] == 'release'):
1014 # Print a warning that liveobjectlist will implicitly enable the debugger
1015 print "Warning: forcing debuggersupport on for liveobjectlist"
1016 options['debuggersupport'] = 'on'
1017 options['inspector'] = 'on'
1018 options['objectprint'] = 'on'
Steve Blocka7e24c12009-10-30 11:49:00 +00001019
1020
1021def ParseEnvOverrides(arg, imports):
1022 # The environment overrides are in the format NAME0:value0,NAME1:value1,...
1023 # The environment imports are in the format NAME0,NAME1,...
1024 overrides = {}
1025 for var in imports.split(','):
1026 if var in os.environ:
1027 overrides[var] = os.environ[var]
1028 for override in arg.split(','):
1029 pos = override.find(':')
1030 if pos == -1:
1031 continue
1032 overrides[override[:pos].strip()] = override[pos+1:].strip()
1033 return overrides
1034
1035
1036def BuildSpecific(env, mode, env_overrides):
1037 options = {'mode': mode}
1038 for option in SIMPLE_OPTIONS:
1039 options[option] = env[option]
Steve Block6ded16b2010-05-10 14:33:55 +01001040 PostprocessOptions(options, env['os'])
Steve Blocka7e24c12009-10-30 11:49:00 +00001041
1042 context = BuildContext(options, env_overrides, samples=SplitList(env['sample']))
1043
1044 # Remove variables which can't be imported from the user's external
1045 # environment into a construction environment.
1046 user_environ = os.environ.copy()
1047 try:
1048 del user_environ['ENV']
1049 except KeyError:
1050 pass
1051
1052 library_flags = context.AddRelevantFlags(user_environ, LIBRARY_FLAGS)
1053 v8_flags = context.AddRelevantFlags(library_flags, V8_EXTRA_FLAGS)
1054 mksnapshot_flags = context.AddRelevantFlags(library_flags, MKSNAPSHOT_EXTRA_FLAGS)
1055 dtoa_flags = context.AddRelevantFlags(library_flags, DTOA_EXTRA_FLAGS)
1056 cctest_flags = context.AddRelevantFlags(v8_flags, CCTEST_EXTRA_FLAGS)
1057 sample_flags = context.AddRelevantFlags(user_environ, SAMPLE_FLAGS)
1058 d8_flags = context.AddRelevantFlags(library_flags, D8_FLAGS)
1059
1060 context.flags = {
1061 'v8': v8_flags,
1062 'mksnapshot': mksnapshot_flags,
1063 'dtoa': dtoa_flags,
1064 'cctest': cctest_flags,
1065 'sample': sample_flags,
1066 'd8': d8_flags
1067 }
1068
1069 # Generate library base name.
1070 target_id = mode
1071 suffix = SUFFIXES[target_id]
1072 library_name = 'v8' + suffix
1073 version = GetVersion()
1074 if context.options['soname'] == 'on':
1075 # When building shared object with SONAME version the library name.
1076 library_name += '-' + version
Steve Blocka7e24c12009-10-30 11:49:00 +00001077
1078 # Generate library SONAME if required by the build.
1079 if context.options['soname'] == 'on':
1080 soname = GetSpecificSONAME()
1081 if soname == '':
1082 soname = 'lib' + library_name + '.so'
1083 env['SONAME'] = soname
1084
1085 # Build the object files by invoking SCons recursively.
1086 (object_files, shell_files, mksnapshot) = env.SConscript(
1087 join('src', 'SConscript'),
1088 build_dir=join('obj', target_id),
1089 exports='context',
1090 duplicate=False
1091 )
1092
1093 context.mksnapshot_targets.append(mksnapshot)
1094
1095 # Link the object files into a library.
1096 env.Replace(**context.flags['v8'])
Leon Clarked91b9f72010-01-27 17:25:45 +00001097
Steve Blocka7e24c12009-10-30 11:49:00 +00001098 context.ApplyEnvOverrides(env)
1099 if context.options['library'] == 'static':
1100 library = env.StaticLibrary(library_name, object_files)
1101 else:
1102 # There seems to be a glitch in the way scons decides where to put
1103 # PDB files when compiling using MSVC so we specify it manually.
1104 # This should not affect any other platforms.
1105 pdb_name = library_name + '.dll.pdb'
1106 library = env.SharedLibrary(library_name, object_files, PDB=pdb_name)
1107 context.library_targets.append(library)
1108
1109 d8_env = Environment()
1110 d8_env.Replace(**context.flags['d8'])
Leon Clarkee46be812010-01-19 14:06:41 +00001111 context.ApplyEnvOverrides(d8_env)
Steve Blocka7e24c12009-10-30 11:49:00 +00001112 shell = d8_env.Program('d8' + suffix, object_files + shell_files)
1113 context.d8_targets.append(shell)
1114
1115 for sample in context.samples:
Steve Block6ded16b2010-05-10 14:33:55 +01001116 sample_env = Environment()
Steve Blocka7e24c12009-10-30 11:49:00 +00001117 sample_env.Replace(**context.flags['sample'])
Steve Block6ded16b2010-05-10 14:33:55 +01001118 sample_env.Prepend(LIBS=[library_name])
Steve Blocka7e24c12009-10-30 11:49:00 +00001119 context.ApplyEnvOverrides(sample_env)
1120 sample_object = sample_env.SConscript(
1121 join('samples', 'SConscript'),
1122 build_dir=join('obj', 'sample', sample, target_id),
1123 exports='sample context',
1124 duplicate=False
1125 )
1126 sample_name = sample + suffix
1127 sample_program = sample_env.Program(sample_name, sample_object)
1128 sample_env.Depends(sample_program, library)
1129 context.sample_targets.append(sample_program)
1130
Steve Block6ded16b2010-05-10 14:33:55 +01001131 cctest_env = env.Copy()
1132 cctest_env.Prepend(LIBS=[library_name])
1133 cctest_program = cctest_env.SConscript(
Steve Blocka7e24c12009-10-30 11:49:00 +00001134 join('test', 'cctest', 'SConscript'),
1135 build_dir=join('obj', 'test', target_id),
1136 exports='context object_files',
1137 duplicate=False
1138 )
1139 context.cctest_targets.append(cctest_program)
1140
1141 return context
1142
1143
1144def Build():
1145 opts = GetOptions()
1146 env = Environment(options=opts)
1147 Help(opts.GenerateHelpText(env))
1148 VerifyOptions(env)
1149 env_overrides = ParseEnvOverrides(env['env'], env['importenv'])
1150
1151 SourceSignatures(env['sourcesignatures'])
1152
1153 libraries = []
1154 mksnapshots = []
1155 cctests = []
1156 samples = []
1157 d8s = []
1158 modes = SplitList(env['mode'])
1159 for mode in modes:
1160 context = BuildSpecific(env.Copy(), mode, env_overrides)
1161 libraries += context.library_targets
1162 mksnapshots += context.mksnapshot_targets
1163 cctests += context.cctest_targets
1164 samples += context.sample_targets
1165 d8s += context.d8_targets
1166
1167 env.Alias('library', libraries)
1168 env.Alias('mksnapshot', mksnapshots)
1169 env.Alias('cctests', cctests)
1170 env.Alias('sample', samples)
1171 env.Alias('d8', d8s)
1172
1173 if env['sample']:
1174 env.Default('sample')
1175 else:
1176 env.Default('library')
1177
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001178 if env['cache']:
1179 CacheDir(env['cache'])
Steve Blocka7e24c12009-10-30 11:49:00 +00001180
1181# We disable deprecation warnings because we need to be able to use
1182# env.Copy without getting warnings for compatibility with older
1183# version of scons. Also, there's a bug in some revisions that
1184# doesn't allow this flag to be set, so we swallow any exceptions.
1185# Lovely.
1186try:
1187 SetOption('warn', 'no-deprecated')
1188except:
1189 pass
1190
1191
1192Build()