blob: a36a96f9b31fbc284b45444610e4f01288000341 [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)
35sys.path.append(join(root_dir, 'tools'))
36import 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': {
111 'CPPDEFINES': ['V8_ENABLE_CHECKS']
112 },
Steve Block6ded16b2010-05-10 14:33:55 +0100113 'vmstate:on': {
114 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING'],
115 },
116 'protectheap:on': {
117 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING', 'ENABLE_HEAP_PROTECTION'],
118 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000119 'profilingsupport:on': {
Steve Block6ded16b2010-05-10 14:33:55 +0100120 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING', 'ENABLE_LOGGING_AND_PROFILING'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000121 },
122 'debuggersupport:on': {
123 'CPPDEFINES': ['ENABLE_DEBUGGER_SUPPORT'],
124 }
125 },
126 'gcc': {
127 'all': {
128 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
129 'CXXFLAGS': ['$CCFLAGS', '-fno-rtti', '-fno-exceptions'],
130 },
131 'visibility:hidden': {
132 # Use visibility=default to disable this.
133 'CXXFLAGS': ['-fvisibility=hidden']
134 },
135 'mode:debug': {
136 'CCFLAGS': ['-g', '-O0'],
137 'CPPDEFINES': ['ENABLE_DISASSEMBLER', 'DEBUG'],
138 'os:android': {
139 'CCFLAGS': ['-mthumb']
140 }
141 },
142 'mode:release': {
143 'CCFLAGS': ['-O3', '-fomit-frame-pointer', '-fdata-sections',
144 '-ffunction-sections'],
145 'os:android': {
146 'CCFLAGS': ['-mthumb', '-Os'],
147 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
148 }
149 },
150 'os:linux': {
151 'CCFLAGS': ['-ansi'] + GCC_EXTRA_CCFLAGS,
152 'library:shared': {
153 'CPPDEFINES': ['V8_SHARED'],
154 'LIBS': ['pthread']
155 }
156 },
157 'os:macos': {
158 'CCFLAGS': ['-ansi', '-mmacosx-version-min=10.4'],
Leon Clarkee46be812010-01-19 14:06:41 +0000159 'library:shared': {
160 'CPPDEFINES': ['V8_SHARED']
161 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000162 },
163 'os:freebsd': {
164 'CPPPATH' : ['/usr/local/include'],
165 'LIBPATH' : ['/usr/local/lib'],
166 'CCFLAGS': ['-ansi'],
167 },
Steve Blockd0582a62009-12-15 09:54:21 +0000168 'os:openbsd': {
169 'CPPPATH' : ['/usr/local/include'],
170 'LIBPATH' : ['/usr/local/lib'],
171 'CCFLAGS': ['-ansi'],
172 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000173 'os:solaris': {
Kristian Monsen25f61362010-05-21 11:50:48 +0100174 # On Solaris, to get isinf, INFINITY, fpclassify and other macros one
175 # needs to define __C99FEATURES__.
176 'CPPDEFINES': ['__C99FEATURES__'],
Leon Clarked91b9f72010-01-27 17:25:45 +0000177 'CPPPATH' : ['/usr/local/include'],
178 'LIBPATH' : ['/usr/local/lib'],
179 'CCFLAGS': ['-ansi'],
180 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000181 'os:win32': {
182 'CCFLAGS': ['-DWIN32'],
183 'CXXFLAGS': ['-DWIN32'],
184 },
185 'os:android': {
186 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__',
187 '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'],
188 'CCFLAGS': ANDROID_FLAGS,
189 'WARNINGFLAGS': ['-Wall', '-Wno-unused', '-Werror=return-type',
190 '-Wstrict-aliasing=2'],
191 'CPPPATH': ANDROID_INCLUDES,
192 },
193 'arch:ia32': {
194 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'],
195 'CCFLAGS': ['-m32'],
196 'LINKFLAGS': ['-m32']
197 },
198 'arch:arm': {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100199 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
200 'unalignedaccesses:on' : {
201 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=1']
202 },
203 'unalignedaccesses:off' : {
204 'CPPDEFINES' : ['CAN_USE_UNALIGNED_ACCESSES=0']
205 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000206 },
207 'simulator:arm': {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100208 'CCFLAGS': ['-m32'],
Ben Murdochf87a2032010-10-22 12:50:53 +0100209 'LINKFLAGS': ['-m32'],
210 'CPPDEFINES': ['USE_SIMULATOR']
Steve Blocka7e24c12009-10-30 11:49:00 +0000211 },
Andrei Popescu31002712010-02-23 13:46:05 +0000212 'arch:mips': {
213 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
214 'simulator:none': {
215 'CCFLAGS': ['-EL', '-mips32r2', '-Wa,-mips32r2', '-fno-inline'],
216 'LDFLAGS': ['-EL']
217 }
218 },
219 'simulator:mips': {
220 'CCFLAGS': ['-m32'],
Ben Murdochf87a2032010-10-22 12:50:53 +0100221 'LINKFLAGS': ['-m32'],
222 'CPPDEFINES': ['USE_SIMULATOR']
Andrei Popescu31002712010-02-23 13:46:05 +0000223 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000224 'arch:x64': {
225 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
226 'CCFLAGS': ['-m64'],
227 'LINKFLAGS': ['-m64'],
228 },
229 'prof:oprofile': {
230 'CPPDEFINES': ['ENABLE_OPROFILE_AGENT']
231 }
232 },
233 'msvc': {
234 'all': {
235 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
236 'CXXFLAGS': ['$CCFLAGS', '/GR-', '/Gy'],
237 'CPPDEFINES': ['WIN32'],
238 'LINKFLAGS': ['/INCREMENTAL:NO', '/NXCOMPAT', '/IGNORE:4221'],
239 'CCPDBFLAGS': ['/Zi']
240 },
241 'verbose:off': {
242 'DIALECTFLAGS': ['/nologo'],
243 'ARFLAGS': ['/NOLOGO']
244 },
245 'arch:ia32': {
246 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', '_USE_32BIT_TIME_T'],
247 'LINKFLAGS': ['/MACHINE:X86'],
248 'ARFLAGS': ['/MACHINE:X86']
249 },
250 'arch:x64': {
251 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
252 'LINKFLAGS': ['/MACHINE:X64'],
253 'ARFLAGS': ['/MACHINE:X64']
254 },
255 'mode:debug': {
256 'CCFLAGS': ['/Od', '/Gm'],
257 'CPPDEFINES': ['_DEBUG', 'ENABLE_DISASSEMBLER', 'DEBUG'],
258 'LINKFLAGS': ['/DEBUG'],
259 'msvcrt:static': {
260 'CCFLAGS': ['/MTd']
261 },
262 'msvcrt:shared': {
263 'CCFLAGS': ['/MDd']
264 }
265 },
266 'mode:release': {
267 'CCFLAGS': ['/O2'],
268 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
269 'msvcrt:static': {
270 'CCFLAGS': ['/MT']
271 },
272 'msvcrt:shared': {
273 'CCFLAGS': ['/MD']
274 },
275 'msvcltcg:on': {
276 'CCFLAGS': ['/GL'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000277 'ARFLAGS': ['/LTCG'],
Steve Block6ded16b2010-05-10 14:33:55 +0100278 'pgo:off': {
279 'LINKFLAGS': ['/LTCG'],
280 },
281 'pgo:instrument': {
282 'LINKFLAGS': ['/LTCG:PGI']
283 },
284 'pgo:optimize': {
285 'LINKFLAGS': ['/LTCG:PGO']
286 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000287 }
288 }
289 }
290}
291
292
293V8_EXTRA_FLAGS = {
294 'gcc': {
295 'all': {
296 'WARNINGFLAGS': ['-Wall',
297 '-Werror',
298 '-W',
299 '-Wno-unused-parameter',
300 '-Wnon-virtual-dtor']
301 },
302 'os:win32': {
303 'WARNINGFLAGS': ['-pedantic', '-Wno-long-long']
304 },
305 'os:linux': {
306 'WARNINGFLAGS': ['-pedantic'],
307 'library:shared': {
308 'soname:on': {
309 'LINKFLAGS': ['-Wl,-soname,${SONAME}']
310 }
311 }
312 },
313 'os:macos': {
314 'WARNINGFLAGS': ['-pedantic']
315 },
316 'disassembler:on': {
317 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
318 }
319 },
320 'msvc': {
321 'all': {
Leon Clarked91b9f72010-01-27 17:25:45 +0000322 'WARNINGFLAGS': ['/W3', '/WX', '/wd4355', '/wd4800']
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 },
324 'library:shared': {
325 'CPPDEFINES': ['BUILDING_V8_SHARED'],
326 'LIBS': ['winmm', 'ws2_32']
327 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000328 'arch:arm': {
329 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
330 # /wd4996 is to silence the warning about sscanf
331 # used by the arm simulator.
332 'WARNINGFLAGS': ['/wd4996']
333 },
Andrei Popescu31002712010-02-23 13:46:05 +0000334 'arch:mips': {
335 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
336 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000337 'disassembler:on': {
338 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
339 }
340 }
341}
342
343
344MKSNAPSHOT_EXTRA_FLAGS = {
345 'gcc': {
346 'os:linux': {
347 'LIBS': ['pthread'],
348 },
349 'os:macos': {
350 'LIBS': ['pthread'],
351 },
352 'os:freebsd': {
353 'LIBS': ['execinfo', 'pthread']
354 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000355 'os:solaris': {
356 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
357 'LINKFLAGS': ['-mt']
358 },
Steve Blockd0582a62009-12-15 09:54:21 +0000359 'os:openbsd': {
360 'LIBS': ['execinfo', 'pthread']
361 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000362 'os:win32': {
363 'LIBS': ['winmm', 'ws2_32'],
364 },
365 },
366 'msvc': {
367 'all': {
368 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
369 'LIBS': ['winmm', 'ws2_32']
370 }
371 }
372}
373
374
375DTOA_EXTRA_FLAGS = {
376 'gcc': {
377 'all': {
378 'WARNINGFLAGS': ['-Werror', '-Wno-uninitialized'],
379 'CCFLAGS': GCC_DTOA_EXTRA_CCFLAGS
380 }
381 },
382 'msvc': {
383 'all': {
384 'WARNINGFLAGS': ['/WX', '/wd4018', '/wd4244']
385 }
386 }
387}
388
389
390CCTEST_EXTRA_FLAGS = {
391 'all': {
392 'CPPPATH': [join(root_dir, 'src')],
Steve Blocka7e24c12009-10-30 11:49:00 +0000393 },
394 'gcc': {
395 'all': {
396 'LIBPATH': [abspath('.')]
397 },
398 'os:linux': {
399 'LIBS': ['pthread'],
400 },
401 'os:macos': {
402 'LIBS': ['pthread'],
403 },
404 'os:freebsd': {
405 'LIBS': ['execinfo', 'pthread']
406 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000407 'os:solaris': {
408 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
409 'LINKFLAGS': ['-mt']
410 },
Steve Blockd0582a62009-12-15 09:54:21 +0000411 'os:openbsd': {
412 'LIBS': ['execinfo', 'pthread']
413 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000414 'os:win32': {
415 'LIBS': ['winmm', 'ws2_32']
416 },
417 'os:android': {
418 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__',
419 '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'],
420 'CCFLAGS': ANDROID_FLAGS,
421 'CPPPATH': ANDROID_INCLUDES,
Steve Block6ded16b2010-05-10 14:33:55 +0100422 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib',
423 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 +0000424 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100425 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000426 'mode:release': {
427 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
428 }
429 },
Steve Block6ded16b2010-05-10 14:33:55 +0100430 'arch:arm': {
431 'LINKFLAGS': ARM_LINK_FLAGS
432 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000433 },
434 'msvc': {
435 'all': {
436 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
437 'LIBS': ['winmm', 'ws2_32']
438 },
439 'library:shared': {
440 'CPPDEFINES': ['USING_V8_SHARED']
441 },
442 'arch:ia32': {
443 'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
444 },
445 'arch:x64': {
Steve Block3ce2e202009-11-05 08:53:23 +0000446 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
447 'LINKFLAGS': ['/STACK:2091752']
Steve Blocka7e24c12009-10-30 11:49:00 +0000448 },
449 }
450}
451
452
453SAMPLE_FLAGS = {
454 'all': {
455 'CPPPATH': [join(abspath('.'), 'include')],
Steve Blocka7e24c12009-10-30 11:49:00 +0000456 },
457 'gcc': {
458 'all': {
459 'LIBPATH': ['.'],
460 'CCFLAGS': ['-fno-rtti', '-fno-exceptions']
461 },
462 'os:linux': {
463 'LIBS': ['pthread'],
464 },
465 'os:macos': {
466 'LIBS': ['pthread'],
467 },
468 'os:freebsd': {
469 'LIBPATH' : ['/usr/local/lib'],
Steve Blockd0582a62009-12-15 09:54:21 +0000470 'LIBS': ['execinfo', 'pthread']
471 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000472 'os:solaris': {
473 'LIBPATH' : ['/usr/local/lib'],
474 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
475 'LINKFLAGS': ['-mt']
476 },
Steve Blockd0582a62009-12-15 09:54:21 +0000477 'os:openbsd': {
478 'LIBPATH' : ['/usr/local/lib'],
479 'LIBS': ['execinfo', 'pthread']
Steve Blocka7e24c12009-10-30 11:49:00 +0000480 },
481 'os:win32': {
482 'LIBS': ['winmm', 'ws2_32']
483 },
484 'os:android': {
485 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__',
486 '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'],
487 'CCFLAGS': ANDROID_FLAGS,
488 'CPPPATH': ANDROID_INCLUDES,
Steve Block6ded16b2010-05-10 14:33:55 +0100489 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib',
490 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 +0000491 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100492 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000493 'mode:release': {
494 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
495 }
496 },
Steve Block6ded16b2010-05-10 14:33:55 +0100497 'arch:arm': {
498 'LINKFLAGS': ARM_LINK_FLAGS
499 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000500 'arch:ia32': {
501 'CCFLAGS': ['-m32'],
502 'LINKFLAGS': ['-m32']
503 },
504 'arch:x64': {
505 'CCFLAGS': ['-m64'],
506 'LINKFLAGS': ['-m64']
507 },
Andrei Popescu31002712010-02-23 13:46:05 +0000508 'arch:mips': {
509 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
510 'simulator:none': {
511 'CCFLAGS': ['-EL', '-mips32r2', '-Wa,-mips32r2', '-fno-inline'],
512 'LINKFLAGS': ['-EL'],
513 'LDFLAGS': ['-EL']
514 }
515 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000516 'simulator:arm': {
517 'CCFLAGS': ['-m32'],
518 'LINKFLAGS': ['-m32']
519 },
Andrei Popescu31002712010-02-23 13:46:05 +0000520 'simulator:mips': {
521 'CCFLAGS': ['-m32'],
522 'LINKFLAGS': ['-m32']
523 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000524 'mode:release': {
525 'CCFLAGS': ['-O2']
526 },
527 'mode:debug': {
528 'CCFLAGS': ['-g', '-O0']
529 },
530 'prof:oprofile': {
531 'LIBPATH': ['/usr/lib32', '/usr/lib32/oprofile'],
532 'LIBS': ['opagent']
533 }
534 },
535 'msvc': {
536 'all': {
537 'LIBS': ['winmm', 'ws2_32']
538 },
539 'verbose:off': {
540 'CCFLAGS': ['/nologo'],
541 'LINKFLAGS': ['/NOLOGO']
542 },
543 'verbose:on': {
544 'LINKFLAGS': ['/VERBOSE']
545 },
546 'library:shared': {
547 'CPPDEFINES': ['USING_V8_SHARED']
548 },
549 'prof:on': {
550 'LINKFLAGS': ['/MAP']
551 },
552 'mode:release': {
553 'CCFLAGS': ['/O2'],
554 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
555 'msvcrt:static': {
556 'CCFLAGS': ['/MT']
557 },
558 'msvcrt:shared': {
559 'CCFLAGS': ['/MD']
560 },
561 'msvcltcg:on': {
562 'CCFLAGS': ['/GL'],
Steve Block6ded16b2010-05-10 14:33:55 +0100563 'pgo:off': {
564 'LINKFLAGS': ['/LTCG'],
565 },
566 },
567 'pgo:instrument': {
568 'LINKFLAGS': ['/LTCG:PGI']
569 },
570 'pgo:optimize': {
571 'LINKFLAGS': ['/LTCG:PGO']
Steve Blocka7e24c12009-10-30 11:49:00 +0000572 }
573 },
574 'arch:ia32': {
575 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'],
576 'LINKFLAGS': ['/MACHINE:X86']
577 },
578 'arch:x64': {
579 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
Steve Block3ce2e202009-11-05 08:53:23 +0000580 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2091752']
Steve Blocka7e24c12009-10-30 11:49:00 +0000581 },
582 'mode:debug': {
583 'CCFLAGS': ['/Od'],
584 'LINKFLAGS': ['/DEBUG'],
585 'msvcrt:static': {
586 'CCFLAGS': ['/MTd']
587 },
588 'msvcrt:shared': {
589 'CCFLAGS': ['/MDd']
590 }
591 }
592 }
593}
594
595
596D8_FLAGS = {
597 'gcc': {
598 'console:readline': {
599 'LIBS': ['readline']
600 },
601 'os:linux': {
602 'LIBS': ['pthread'],
603 },
604 'os:macos': {
605 'LIBS': ['pthread'],
606 },
607 'os:freebsd': {
608 'LIBS': ['pthread'],
609 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000610 'os:solaris': {
611 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
612 'LINKFLAGS': ['-mt']
613 },
Steve Blockd0582a62009-12-15 09:54:21 +0000614 'os:openbsd': {
615 'LIBS': ['pthread'],
616 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000617 'os:android': {
Steve Block6ded16b2010-05-10 14:33:55 +0100618 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib',
619 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 +0000620 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100621 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000622 },
623 'os:win32': {
624 'LIBS': ['winmm', 'ws2_32'],
625 },
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100626 'arch:arm': {
627 'LINKFLAGS': ARM_LINK_FLAGS
628 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000629 },
630 'msvc': {
631 'all': {
632 'LIBS': ['winmm', 'ws2_32']
633 }
634 }
635}
636
637
638SUFFIXES = {
639 'release': '',
640 'debug': '_g'
641}
642
643
644def Abort(message):
645 print message
646 sys.exit(1)
647
648
649def GuessToolchain(os):
650 tools = Environment()['TOOLS']
651 if 'gcc' in tools:
652 return 'gcc'
653 elif 'msvc' in tools:
654 return 'msvc'
655 else:
656 return None
657
658
659OS_GUESS = utils.GuessOS()
660TOOLCHAIN_GUESS = GuessToolchain(OS_GUESS)
661ARCH_GUESS = utils.GuessArchitecture()
662
663
664SIMPLE_OPTIONS = {
665 'toolchain': {
666 'values': ['gcc', 'msvc'],
667 'default': TOOLCHAIN_GUESS,
Ben Murdochf87a2032010-10-22 12:50:53 +0100668 'help': 'the toolchain to use (%s)' % TOOLCHAIN_GUESS
Steve Blocka7e24c12009-10-30 11:49:00 +0000669 },
670 'os': {
Leon Clarked91b9f72010-01-27 17:25:45 +0000671 'values': ['freebsd', 'linux', 'macos', 'win32', 'android', 'openbsd', 'solaris'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000672 'default': OS_GUESS,
Ben Murdochf87a2032010-10-22 12:50:53 +0100673 'help': 'the os to build for (%s)' % OS_GUESS
Steve Blocka7e24c12009-10-30 11:49:00 +0000674 },
675 'arch': {
Andrei Popescu31002712010-02-23 13:46:05 +0000676 'values':['arm', 'ia32', 'x64', 'mips'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000677 'default': ARCH_GUESS,
Ben Murdochf87a2032010-10-22 12:50:53 +0100678 'help': 'the architecture to build for (%s)' % ARCH_GUESS
Steve Blocka7e24c12009-10-30 11:49:00 +0000679 },
680 'regexp': {
681 'values': ['native', 'interpreted'],
682 'default': 'native',
683 'help': 'Whether to use native or interpreted regexp implementation'
684 },
685 'snapshot': {
686 'values': ['on', 'off', 'nobuild'],
687 'default': 'off',
688 'help': 'build using snapshots for faster start-up'
689 },
690 'prof': {
691 'values': ['on', 'off', 'oprofile'],
692 'default': 'off',
693 'help': 'enable profiling of build target'
694 },
695 'library': {
696 'values': ['static', 'shared'],
697 'default': 'static',
698 'help': 'the type of library to produce'
699 },
Steve Block6ded16b2010-05-10 14:33:55 +0100700 'vmstate': {
701 'values': ['on', 'off'],
702 'default': 'off',
703 'help': 'enable VM state tracking'
704 },
705 'protectheap': {
706 'values': ['on', 'off'],
707 'default': 'off',
708 'help': 'enable heap protection'
709 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000710 'profilingsupport': {
711 'values': ['on', 'off'],
712 'default': 'on',
713 'help': 'enable profiling of JavaScript code'
714 },
715 'debuggersupport': {
716 'values': ['on', 'off'],
717 'default': 'on',
718 'help': 'enable debugging of JavaScript code'
719 },
720 'soname': {
721 'values': ['on', 'off'],
722 'default': 'off',
723 'help': 'turn on setting soname for Linux shared library'
724 },
725 'msvcrt': {
726 'values': ['static', 'shared'],
727 'default': 'static',
728 'help': 'the type of Microsoft Visual C++ runtime library to use'
729 },
730 'msvcltcg': {
731 'values': ['on', 'off'],
732 'default': 'on',
733 'help': 'use Microsoft Visual C++ link-time code generation'
734 },
735 'simulator': {
Andrei Popescu31002712010-02-23 13:46:05 +0000736 'values': ['arm', 'mips', 'none'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000737 'default': 'none',
738 'help': 'build with simulator'
739 },
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100740 'unalignedaccesses': {
741 'values': ['default', 'on', 'off'],
742 'default': 'default',
743 'help': 'set whether the ARM target supports unaligned accesses'
744 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000745 'disassembler': {
746 'values': ['on', 'off'],
747 'default': 'off',
748 'help': 'enable the disassembler to inspect generated code'
749 },
750 'sourcesignatures': {
751 'values': ['MD5', 'timestamp'],
752 'default': 'MD5',
753 'help': 'set how the build system detects file changes'
754 },
755 'console': {
756 'values': ['dumb', 'readline'],
757 'default': 'dumb',
758 'help': 'the console to use for the d8 shell'
759 },
760 'verbose': {
761 'values': ['on', 'off'],
762 'default': 'off',
763 'help': 'more output from compiler and linker'
764 },
765 'visibility': {
766 'values': ['default', 'hidden'],
767 'default': 'hidden',
768 'help': 'shared library symbol visibility'
Leon Clarkee46be812010-01-19 14:06:41 +0000769 },
Steve Block6ded16b2010-05-10 14:33:55 +0100770 'pgo': {
771 'values': ['off', 'instrument', 'optimize'],
772 'default': 'off',
773 'help': 'select profile guided optimization variant',
Steve Blocka7e24c12009-10-30 11:49:00 +0000774 }
775}
776
777
778def GetOptions():
779 result = Options()
780 result.Add('mode', 'compilation mode (debug, release)', 'release')
Leon Clarkee46be812010-01-19 14:06:41 +0000781 result.Add('sample', 'build sample (shell, process, lineprocessor)', '')
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100782 result.Add('cache', 'directory to use for scons build cache', '')
Steve Blocka7e24c12009-10-30 11:49:00 +0000783 result.Add('env', 'override environment settings (NAME0:value0,NAME1:value1,...)', '')
784 result.Add('importenv', 'import environment settings (NAME0,NAME1,...)', '')
785 for (name, option) in SIMPLE_OPTIONS.iteritems():
786 help = '%s (%s)' % (name, ", ".join(option['values']))
787 result.Add(name, help, option.get('default'))
788 return result
789
790
791def GetVersionComponents():
792 MAJOR_VERSION_PATTERN = re.compile(r"#define\s+MAJOR_VERSION\s+(.*)")
793 MINOR_VERSION_PATTERN = re.compile(r"#define\s+MINOR_VERSION\s+(.*)")
794 BUILD_NUMBER_PATTERN = re.compile(r"#define\s+BUILD_NUMBER\s+(.*)")
795 PATCH_LEVEL_PATTERN = re.compile(r"#define\s+PATCH_LEVEL\s+(.*)")
796
797 patterns = [MAJOR_VERSION_PATTERN,
798 MINOR_VERSION_PATTERN,
799 BUILD_NUMBER_PATTERN,
800 PATCH_LEVEL_PATTERN]
801
802 source = open(join(root_dir, 'src', 'version.cc')).read()
803 version_components = []
804 for pattern in patterns:
805 match = pattern.search(source)
806 if match:
807 version_components.append(match.group(1).strip())
808 else:
809 version_components.append('0')
810
811 return version_components
812
813
814def GetVersion():
815 version_components = GetVersionComponents()
816
817 if version_components[len(version_components) - 1] == '0':
818 version_components.pop()
819 return '.'.join(version_components)
820
821
822def GetSpecificSONAME():
823 SONAME_PATTERN = re.compile(r"#define\s+SONAME\s+\"(.*)\"")
824
825 source = open(join(root_dir, 'src', 'version.cc')).read()
826 match = SONAME_PATTERN.search(source)
827
828 if match:
829 return match.group(1).strip()
830 else:
831 return ''
832
833
834def SplitList(str):
835 return [ s for s in str.split(",") if len(s) > 0 ]
836
837
838def IsLegal(env, option, values):
839 str = env[option]
840 for s in SplitList(str):
841 if not s in values:
842 Abort("Illegal value for option %s '%s'." % (option, s))
843 return False
844 return True
845
846
847def VerifyOptions(env):
848 if not IsLegal(env, 'mode', ['debug', 'release']):
849 return False
Leon Clarkee46be812010-01-19 14:06:41 +0000850 if not IsLegal(env, 'sample', ["shell", "process", "lineprocessor"]):
Steve Blocka7e24c12009-10-30 11:49:00 +0000851 return False
852 if not IsLegal(env, 'regexp', ["native", "interpreted"]):
853 return False
854 if env['os'] == 'win32' and env['library'] == 'shared' and env['prof'] == 'on':
855 Abort("Profiling on windows only supported for static library.")
856 if env['prof'] == 'oprofile' and env['os'] != 'linux':
857 Abort("OProfile is only supported on Linux.")
858 if env['os'] == 'win32' and env['soname'] == 'on':
859 Abort("Shared Object soname not applicable for Windows.")
860 if env['soname'] == 'on' and env['library'] == 'static':
861 Abort("Shared Object soname not applicable for static library.")
Steve Block6ded16b2010-05-10 14:33:55 +0100862 if env['os'] != 'win32' and env['pgo'] != 'off':
863 Abort("Profile guided optimization only supported on Windows.")
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100864 if env['cache'] and not os.path.isdir(env['cache']):
865 Abort("The specified cache directory does not exist.")
866 if not (env['arch'] == 'arm' or env['simulator'] == 'arm') and ('unalignedaccesses' in ARGUMENTS):
867 print env['arch']
868 print env['simulator']
869 Abort("Option unalignedaccesses only supported for the ARM architecture.")
Steve Blocka7e24c12009-10-30 11:49:00 +0000870 for (name, option) in SIMPLE_OPTIONS.iteritems():
871 if (not option.get('default')) and (name not in ARGUMENTS):
872 message = ("A value for option %s must be specified (%s)." %
873 (name, ", ".join(option['values'])))
874 Abort(message)
875 if not env[name] in option['values']:
876 message = ("Unknown %s value '%s'. Possible values are (%s)." %
877 (name, env[name], ", ".join(option['values'])))
878 Abort(message)
879
880
881class BuildContext(object):
882
883 def __init__(self, options, env_overrides, samples):
884 self.library_targets = []
885 self.mksnapshot_targets = []
886 self.cctest_targets = []
887 self.sample_targets = []
888 self.d8_targets = []
889 self.options = options
890 self.env_overrides = env_overrides
891 self.samples = samples
892 self.use_snapshot = (options['snapshot'] != 'off')
893 self.build_snapshot = (options['snapshot'] == 'on')
894 self.flags = None
895
896 def AddRelevantFlags(self, initial, flags):
897 result = initial.copy()
898 toolchain = self.options['toolchain']
899 if toolchain in flags:
900 self.AppendFlags(result, flags[toolchain].get('all'))
901 for option in sorted(self.options.keys()):
902 value = self.options[option]
903 self.AppendFlags(result, flags[toolchain].get(option + ':' + value))
904 self.AppendFlags(result, flags.get('all'))
905 return result
906
907 def AddRelevantSubFlags(self, options, flags):
908 self.AppendFlags(options, flags.get('all'))
909 for option in sorted(self.options.keys()):
910 value = self.options[option]
911 self.AppendFlags(options, flags.get(option + ':' + value))
912
913 def GetRelevantSources(self, source):
914 result = []
915 result += source.get('all', [])
916 for (name, value) in self.options.iteritems():
917 source_value = source.get(name + ':' + value, [])
918 if type(source_value) == dict:
919 result += self.GetRelevantSources(source_value)
920 else:
921 result += source_value
922 return sorted(result)
923
924 def AppendFlags(self, options, added):
925 if not added:
926 return
927 for (key, value) in added.iteritems():
928 if key.find(':') != -1:
929 self.AddRelevantSubFlags(options, { key: value })
930 else:
931 if not key in options:
932 options[key] = value
933 else:
934 prefix = options[key]
935 if isinstance(prefix, StringTypes): prefix = prefix.split()
936 options[key] = prefix + value
937
938 def ConfigureObject(self, env, input, **kw):
939 if (kw.has_key('CPPPATH') and env.has_key('CPPPATH')):
940 kw['CPPPATH'] += env['CPPPATH']
941 if self.options['library'] == 'static':
942 return env.StaticObject(input, **kw)
943 else:
944 return env.SharedObject(input, **kw)
945
946 def ApplyEnvOverrides(self, env):
947 if not self.env_overrides:
948 return
949 if type(env['ENV']) == DictType:
950 env['ENV'].update(**self.env_overrides)
951 else:
952 env['ENV'] = self.env_overrides
953
954
Steve Block6ded16b2010-05-10 14:33:55 +0100955def PostprocessOptions(options, os):
Steve Blocka7e24c12009-10-30 11:49:00 +0000956 # Adjust architecture if the simulator option has been set
957 if (options['simulator'] != 'none') and (options['arch'] != options['simulator']):
958 if 'arch' in ARGUMENTS:
959 # Print a warning if arch has explicitly been set
960 print "Warning: forcing architecture to match simulator (%s)" % options['simulator']
961 options['arch'] = options['simulator']
962 if (options['prof'] != 'off') and (options['profilingsupport'] == 'off'):
963 # Print a warning if profiling is enabled without profiling support
964 print "Warning: forcing profilingsupport on when prof is on"
965 options['profilingsupport'] = 'on'
Steve Block6ded16b2010-05-10 14:33:55 +0100966 if os == 'win32' and options['pgo'] != 'off' and options['msvcltcg'] == 'off':
967 if 'msvcltcg' in ARGUMENTS:
968 print "Warning: forcing msvcltcg on as it is required for pgo (%s)" % options['pgo']
969 options['msvcltcg'] = 'on'
Andrei Popescu31002712010-02-23 13:46:05 +0000970 if options['arch'] == 'mips':
971 if ('regexp' in ARGUMENTS) and options['regexp'] == 'native':
972 # Print a warning if native regexp is specified for mips
973 print "Warning: forcing regexp to interpreted for mips"
974 options['regexp'] = 'interpreted'
Steve Blocka7e24c12009-10-30 11:49:00 +0000975
976
977def ParseEnvOverrides(arg, imports):
978 # The environment overrides are in the format NAME0:value0,NAME1:value1,...
979 # The environment imports are in the format NAME0,NAME1,...
980 overrides = {}
981 for var in imports.split(','):
982 if var in os.environ:
983 overrides[var] = os.environ[var]
984 for override in arg.split(','):
985 pos = override.find(':')
986 if pos == -1:
987 continue
988 overrides[override[:pos].strip()] = override[pos+1:].strip()
989 return overrides
990
991
992def BuildSpecific(env, mode, env_overrides):
993 options = {'mode': mode}
994 for option in SIMPLE_OPTIONS:
995 options[option] = env[option]
Steve Block6ded16b2010-05-10 14:33:55 +0100996 PostprocessOptions(options, env['os'])
Steve Blocka7e24c12009-10-30 11:49:00 +0000997
998 context = BuildContext(options, env_overrides, samples=SplitList(env['sample']))
999
1000 # Remove variables which can't be imported from the user's external
1001 # environment into a construction environment.
1002 user_environ = os.environ.copy()
1003 try:
1004 del user_environ['ENV']
1005 except KeyError:
1006 pass
1007
1008 library_flags = context.AddRelevantFlags(user_environ, LIBRARY_FLAGS)
1009 v8_flags = context.AddRelevantFlags(library_flags, V8_EXTRA_FLAGS)
1010 mksnapshot_flags = context.AddRelevantFlags(library_flags, MKSNAPSHOT_EXTRA_FLAGS)
1011 dtoa_flags = context.AddRelevantFlags(library_flags, DTOA_EXTRA_FLAGS)
1012 cctest_flags = context.AddRelevantFlags(v8_flags, CCTEST_EXTRA_FLAGS)
1013 sample_flags = context.AddRelevantFlags(user_environ, SAMPLE_FLAGS)
1014 d8_flags = context.AddRelevantFlags(library_flags, D8_FLAGS)
1015
1016 context.flags = {
1017 'v8': v8_flags,
1018 'mksnapshot': mksnapshot_flags,
1019 'dtoa': dtoa_flags,
1020 'cctest': cctest_flags,
1021 'sample': sample_flags,
1022 'd8': d8_flags
1023 }
1024
1025 # Generate library base name.
1026 target_id = mode
1027 suffix = SUFFIXES[target_id]
1028 library_name = 'v8' + suffix
1029 version = GetVersion()
1030 if context.options['soname'] == 'on':
1031 # When building shared object with SONAME version the library name.
1032 library_name += '-' + version
Steve Blocka7e24c12009-10-30 11:49:00 +00001033
1034 # Generate library SONAME if required by the build.
1035 if context.options['soname'] == 'on':
1036 soname = GetSpecificSONAME()
1037 if soname == '':
1038 soname = 'lib' + library_name + '.so'
1039 env['SONAME'] = soname
1040
1041 # Build the object files by invoking SCons recursively.
1042 (object_files, shell_files, mksnapshot) = env.SConscript(
1043 join('src', 'SConscript'),
1044 build_dir=join('obj', target_id),
1045 exports='context',
1046 duplicate=False
1047 )
1048
1049 context.mksnapshot_targets.append(mksnapshot)
1050
1051 # Link the object files into a library.
1052 env.Replace(**context.flags['v8'])
Leon Clarked91b9f72010-01-27 17:25:45 +00001053
Steve Blocka7e24c12009-10-30 11:49:00 +00001054 context.ApplyEnvOverrides(env)
1055 if context.options['library'] == 'static':
1056 library = env.StaticLibrary(library_name, object_files)
1057 else:
1058 # There seems to be a glitch in the way scons decides where to put
1059 # PDB files when compiling using MSVC so we specify it manually.
1060 # This should not affect any other platforms.
1061 pdb_name = library_name + '.dll.pdb'
1062 library = env.SharedLibrary(library_name, object_files, PDB=pdb_name)
1063 context.library_targets.append(library)
1064
1065 d8_env = Environment()
1066 d8_env.Replace(**context.flags['d8'])
Leon Clarkee46be812010-01-19 14:06:41 +00001067 context.ApplyEnvOverrides(d8_env)
Steve Blocka7e24c12009-10-30 11:49:00 +00001068 shell = d8_env.Program('d8' + suffix, object_files + shell_files)
1069 context.d8_targets.append(shell)
1070
1071 for sample in context.samples:
Steve Block6ded16b2010-05-10 14:33:55 +01001072 sample_env = Environment()
Steve Blocka7e24c12009-10-30 11:49:00 +00001073 sample_env.Replace(**context.flags['sample'])
Steve Block6ded16b2010-05-10 14:33:55 +01001074 sample_env.Prepend(LIBS=[library_name])
Steve Blocka7e24c12009-10-30 11:49:00 +00001075 context.ApplyEnvOverrides(sample_env)
1076 sample_object = sample_env.SConscript(
1077 join('samples', 'SConscript'),
1078 build_dir=join('obj', 'sample', sample, target_id),
1079 exports='sample context',
1080 duplicate=False
1081 )
1082 sample_name = sample + suffix
1083 sample_program = sample_env.Program(sample_name, sample_object)
1084 sample_env.Depends(sample_program, library)
1085 context.sample_targets.append(sample_program)
1086
Steve Block6ded16b2010-05-10 14:33:55 +01001087 cctest_env = env.Copy()
1088 cctest_env.Prepend(LIBS=[library_name])
1089 cctest_program = cctest_env.SConscript(
Steve Blocka7e24c12009-10-30 11:49:00 +00001090 join('test', 'cctest', 'SConscript'),
1091 build_dir=join('obj', 'test', target_id),
1092 exports='context object_files',
1093 duplicate=False
1094 )
1095 context.cctest_targets.append(cctest_program)
1096
1097 return context
1098
1099
1100def Build():
1101 opts = GetOptions()
1102 env = Environment(options=opts)
1103 Help(opts.GenerateHelpText(env))
1104 VerifyOptions(env)
1105 env_overrides = ParseEnvOverrides(env['env'], env['importenv'])
1106
1107 SourceSignatures(env['sourcesignatures'])
1108
1109 libraries = []
1110 mksnapshots = []
1111 cctests = []
1112 samples = []
1113 d8s = []
1114 modes = SplitList(env['mode'])
1115 for mode in modes:
1116 context = BuildSpecific(env.Copy(), mode, env_overrides)
1117 libraries += context.library_targets
1118 mksnapshots += context.mksnapshot_targets
1119 cctests += context.cctest_targets
1120 samples += context.sample_targets
1121 d8s += context.d8_targets
1122
1123 env.Alias('library', libraries)
1124 env.Alias('mksnapshot', mksnapshots)
1125 env.Alias('cctests', cctests)
1126 env.Alias('sample', samples)
1127 env.Alias('d8', d8s)
1128
1129 if env['sample']:
1130 env.Default('sample')
1131 else:
1132 env.Default('library')
1133
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001134 if env['cache']:
1135 CacheDir(env['cache'])
Steve Blocka7e24c12009-10-30 11:49:00 +00001136
1137# We disable deprecation warnings because we need to be able to use
1138# env.Copy without getting warnings for compatibility with older
1139# version of scons. Also, there's a bug in some revisions that
1140# doesn't allow this flag to be set, so we swallow any exceptions.
1141# Lovely.
1142try:
1143 SetOption('warn', 'no-deprecated')
1144except:
1145 pass
1146
1147
1148Build()