blob: 53d845c21bf7811268932cffdb981064ad03918b [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
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.
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
Steve Blocka7e24c12009-10-30 11:49:00 +000057# 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
60if os.environ.get('GCC_VERSION') == '44':
Steve Block6ded16b2010-05-10 14:33:55 +010061 GCC_EXTRA_CCFLAGS = ['-fno-tree-vrp', '-fno-strict-aliasing']
62 GCC_DTOA_EXTRA_CCFLAGS = []
Steve Blocka7e24c12009-10-30 11:49:00 +000063else:
64 GCC_EXTRA_CCFLAGS = []
65 GCC_DTOA_EXTRA_CCFLAGS = []
66
Steve Block6ded16b2010-05-10 14:33:55 +010067ANDROID_FLAGS = ['-march=armv7-a',
68 '-mtune=cortex-a8',
69 '-mfloat-abi=softfp',
70 '-mfpu=vfp',
Steve Blocka7e24c12009-10-30 11:49:00 +000071 '-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 Block6ded16b2010-05-10 14:33:55 +010085 '-DCAN_USE_VFP_INSTRUCTIONS=1',
86 '-DCAN_USE_ARMV7_INSTRUCTIONS=1',
Kristian Monsen25f61362010-05-21 11:50:48 +010087 '-DCAN_USE_UNALIGNED_ACCESSES=1',
Steve Blocka7e24c12009-10-30 11:49:00 +000088 '-MD']
89
90ANDROID_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
101ANDROID_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 Block6ded16b2010-05-10 14:33:55 +0100109 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 +0000110 ANDROID_TOP + '/out/target/product/generic/obj/lib/crtend_android.o'];
111
112LIBRARY_FLAGS = {
113 'all': {
114 'CPPPATH': [join(root_dir, 'src')],
Steve Block6ded16b2010-05-10 14:33:55 +0100115 'regexp:interpreted': {
116 'CPPDEFINES': ['V8_INTERPRETED_REGEXP']
Steve Blocka7e24c12009-10-30 11:49:00 +0000117 },
118 'mode:debug': {
119 'CPPDEFINES': ['V8_ENABLE_CHECKS']
120 },
Steve Block6ded16b2010-05-10 14:33:55 +0100121 'vmstate:on': {
122 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING'],
123 },
124 'protectheap:on': {
125 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING', 'ENABLE_HEAP_PROTECTION'],
126 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000127 'profilingsupport:on': {
Steve Block6ded16b2010-05-10 14:33:55 +0100128 'CPPDEFINES': ['ENABLE_VMSTATE_TRACKING', 'ENABLE_LOGGING_AND_PROFILING'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000129 },
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 Clarkee46be812010-01-19 14:06:41 +0000167 'library:shared': {
168 'CPPDEFINES': ['V8_SHARED']
169 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000170 },
171 'os:freebsd': {
172 'CPPPATH' : ['/usr/local/include'],
173 'LIBPATH' : ['/usr/local/lib'],
174 'CCFLAGS': ['-ansi'],
175 },
Steve Blockd0582a62009-12-15 09:54:21 +0000176 'os:openbsd': {
177 'CPPPATH' : ['/usr/local/include'],
178 'LIBPATH' : ['/usr/local/lib'],
179 'CCFLAGS': ['-ansi'],
180 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000181 'os:solaris': {
Kristian Monsen25f61362010-05-21 11:50:48 +0100182 # On Solaris, to get isinf, INFINITY, fpclassify and other macros one
183 # needs to define __C99FEATURES__.
184 'CPPDEFINES': ['__C99FEATURES__'],
Leon Clarked91b9f72010-01-27 17:25:45 +0000185 'CPPPATH' : ['/usr/local/include'],
186 'LIBPATH' : ['/usr/local/lib'],
187 'CCFLAGS': ['-ansi'],
188 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000189 '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 Murdoch7f4d5bd2010-06-15 11:15:29 +0100207 '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 Blocka7e24c12009-10-30 11:49:00 +0000214 },
215 'simulator:arm': {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100216 'CCFLAGS': ['-m32'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000217 'LINKFLAGS': ['-m32']
218 },
Andrei Popescu31002712010-02-23 13:46:05 +0000219 '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 Blocka7e24c12009-10-30 11:49:00 +0000230 '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 Blocka7e24c12009-10-30 11:49:00 +0000283 'ARFLAGS': ['/LTCG'],
Steve Block6ded16b2010-05-10 14:33:55 +0100284 'pgo:off': {
285 'LINKFLAGS': ['/LTCG'],
286 },
287 'pgo:instrument': {
288 'LINKFLAGS': ['/LTCG:PGI']
289 },
290 'pgo:optimize': {
291 'LINKFLAGS': ['/LTCG:PGO']
292 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000293 }
294 }
295 }
296}
297
298
299V8_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 Clarked91b9f72010-01-27 17:25:45 +0000328 'WARNINGFLAGS': ['/W3', '/WX', '/wd4355', '/wd4800']
Steve Blocka7e24c12009-10-30 11:49:00 +0000329 },
330 'library:shared': {
331 'CPPDEFINES': ['BUILDING_V8_SHARED'],
332 'LIBS': ['winmm', 'ws2_32']
333 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000334 '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 Popescu31002712010-02-23 13:46:05 +0000340 'arch:mips': {
341 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
342 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000343 'disassembler:on': {
344 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
345 }
346 }
347}
348
349
350MKSNAPSHOT_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 Clarked91b9f72010-01-27 17:25:45 +0000361 'os:solaris': {
362 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
363 'LINKFLAGS': ['-mt']
364 },
Steve Blockd0582a62009-12-15 09:54:21 +0000365 'os:openbsd': {
366 'LIBS': ['execinfo', 'pthread']
367 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000368 '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
381DTOA_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
396CCTEST_EXTRA_FLAGS = {
397 'all': {
398 'CPPPATH': [join(root_dir, 'src')],
Steve Blocka7e24c12009-10-30 11:49:00 +0000399 },
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 Clarked91b9f72010-01-27 17:25:45 +0000413 'os:solaris': {
414 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
415 'LINKFLAGS': ['-mt']
416 },
Steve Blockd0582a62009-12-15 09:54:21 +0000417 'os:openbsd': {
418 'LIBS': ['execinfo', 'pthread']
419 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000420 '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 Block6ded16b2010-05-10 14:33:55 +0100428 '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 Blocka7e24c12009-10-30 11:49:00 +0000430 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100431 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000432 'mode:release': {
433 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
434 }
435 },
Steve Block6ded16b2010-05-10 14:33:55 +0100436 'arch:arm': {
437 'LINKFLAGS': ARM_LINK_FLAGS
438 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000439 },
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 Block3ce2e202009-11-05 08:53:23 +0000452 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
453 'LINKFLAGS': ['/STACK:2091752']
Steve Blocka7e24c12009-10-30 11:49:00 +0000454 },
455 }
456}
457
458
459SAMPLE_FLAGS = {
460 'all': {
461 'CPPPATH': [join(abspath('.'), 'include')],
Steve Blocka7e24c12009-10-30 11:49:00 +0000462 },
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 Blockd0582a62009-12-15 09:54:21 +0000476 'LIBS': ['execinfo', 'pthread']
477 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000478 'os:solaris': {
479 'LIBPATH' : ['/usr/local/lib'],
480 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
481 'LINKFLAGS': ['-mt']
482 },
Steve Blockd0582a62009-12-15 09:54:21 +0000483 'os:openbsd': {
484 'LIBPATH' : ['/usr/local/lib'],
485 'LIBS': ['execinfo', 'pthread']
Steve Blocka7e24c12009-10-30 11:49:00 +0000486 },
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 Block6ded16b2010-05-10 14:33:55 +0100495 '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 Blocka7e24c12009-10-30 11:49:00 +0000497 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100498 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000499 'mode:release': {
500 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
501 }
502 },
Steve Block6ded16b2010-05-10 14:33:55 +0100503 'arch:arm': {
504 'LINKFLAGS': ARM_LINK_FLAGS
505 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000506 'arch:ia32': {
507 'CCFLAGS': ['-m32'],
508 'LINKFLAGS': ['-m32']
509 },
510 'arch:x64': {
511 'CCFLAGS': ['-m64'],
512 'LINKFLAGS': ['-m64']
513 },
Andrei Popescu31002712010-02-23 13:46:05 +0000514 '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 Blocka7e24c12009-10-30 11:49:00 +0000522 'simulator:arm': {
523 'CCFLAGS': ['-m32'],
524 'LINKFLAGS': ['-m32']
525 },
Andrei Popescu31002712010-02-23 13:46:05 +0000526 'simulator:mips': {
527 'CCFLAGS': ['-m32'],
528 'LINKFLAGS': ['-m32']
529 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000530 '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 Block6ded16b2010-05-10 14:33:55 +0100569 'pgo:off': {
570 'LINKFLAGS': ['/LTCG'],
571 },
572 },
573 'pgo:instrument': {
574 'LINKFLAGS': ['/LTCG:PGI']
575 },
576 'pgo:optimize': {
577 'LINKFLAGS': ['/LTCG:PGO']
Steve Blocka7e24c12009-10-30 11:49:00 +0000578 }
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 Block3ce2e202009-11-05 08:53:23 +0000586 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2091752']
Steve Blocka7e24c12009-10-30 11:49:00 +0000587 },
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
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 },
632 },
633 'msvc': {
634 'all': {
635 'LIBS': ['winmm', 'ws2_32']
636 }
637 }
638}
639
640
641SUFFIXES = {
642 'release': '',
643 'debug': '_g'
644}
645
646
647def Abort(message):
648 print message
649 sys.exit(1)
650
651
652def 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
662OS_GUESS = utils.GuessOS()
663TOOLCHAIN_GUESS = GuessToolchain(OS_GUESS)
664ARCH_GUESS = utils.GuessArchitecture()
665
666
667SIMPLE_OPTIONS = {
668 'toolchain': {
669 'values': ['gcc', 'msvc'],
670 'default': TOOLCHAIN_GUESS,
671 'help': 'the toolchain to use (' + TOOLCHAIN_GUESS + ')'
672 },
673 'os': {
Leon Clarked91b9f72010-01-27 17:25:45 +0000674 'values': ['freebsd', 'linux', 'macos', 'win32', 'android', 'openbsd', 'solaris'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000675 'default': OS_GUESS,
676 'help': 'the os to build for (' + OS_GUESS + ')'
677 },
678 'arch': {
Andrei Popescu31002712010-02-23 13:46:05 +0000679 'values':['arm', 'ia32', 'x64', 'mips'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000680 '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 Block6ded16b2010-05-10 14:33:55 +0100703 '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 Blocka7e24c12009-10-30 11:49:00 +0000713 '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 Popescu31002712010-02-23 13:46:05 +0000739 'values': ['arm', 'mips', 'none'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000740 'default': 'none',
741 'help': 'build with simulator'
742 },
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100743 'unalignedaccesses': {
744 'values': ['default', 'on', 'off'],
745 'default': 'default',
746 'help': 'set whether the ARM target supports unaligned accesses'
747 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000748 '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 Clarkee46be812010-01-19 14:06:41 +0000772 },
Steve Block6ded16b2010-05-10 14:33:55 +0100773 'pgo': {
774 'values': ['off', 'instrument', 'optimize'],
775 'default': 'off',
776 'help': 'select profile guided optimization variant',
Steve Blocka7e24c12009-10-30 11:49:00 +0000777 }
778}
779
780
781def GetOptions():
782 result = Options()
783 result.Add('mode', 'compilation mode (debug, release)', 'release')
Leon Clarkee46be812010-01-19 14:06:41 +0000784 result.Add('sample', 'build sample (shell, process, lineprocessor)', '')
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100785 result.Add('cache', 'directory to use for scons build cache', '')
Steve Blocka7e24c12009-10-30 11:49:00 +0000786 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
794def 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
817def 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
825def 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
837def SplitList(str):
838 return [ s for s in str.split(",") if len(s) > 0 ]
839
840
841def 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
850def VerifyOptions(env):
851 if not IsLegal(env, 'mode', ['debug', 'release']):
852 return False
Leon Clarkee46be812010-01-19 14:06:41 +0000853 if not IsLegal(env, 'sample', ["shell", "process", "lineprocessor"]):
Steve Blocka7e24c12009-10-30 11:49:00 +0000854 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 Block6ded16b2010-05-10 14:33:55 +0100865 if env['os'] != 'win32' and env['pgo'] != 'off':
866 Abort("Profile guided optimization only supported on Windows.")
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100867 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 Blocka7e24c12009-10-30 11:49:00 +0000873 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
884class 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 Block6ded16b2010-05-10 14:33:55 +0100958def PostprocessOptions(options, os):
Steve Blocka7e24c12009-10-30 11:49:00 +0000959 # 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 Block6ded16b2010-05-10 14:33:55 +0100969 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 Popescu31002712010-02-23 13:46:05 +0000973 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 Blocka7e24c12009-10-30 11:49:00 +0000978
979
980def 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
995def BuildSpecific(env, mode, env_overrides):
996 options = {'mode': mode}
997 for option in SIMPLE_OPTIONS:
998 options[option] = env[option]
Steve Block6ded16b2010-05-10 14:33:55 +0100999 PostprocessOptions(options, env['os'])
Steve Blocka7e24c12009-10-30 11:49:00 +00001000
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 Blocka7e24c12009-10-30 11:49:00 +00001036
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 Clarked91b9f72010-01-27 17:25:45 +00001056
Steve Blocka7e24c12009-10-30 11:49:00 +00001057 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 Clarkee46be812010-01-19 14:06:41 +00001070 context.ApplyEnvOverrides(d8_env)
Steve Blocka7e24c12009-10-30 11:49:00 +00001071 shell = d8_env.Program('d8' + suffix, object_files + shell_files)
1072 context.d8_targets.append(shell)
1073
1074 for sample in context.samples:
Steve Block6ded16b2010-05-10 14:33:55 +01001075 sample_env = Environment()
Steve Blocka7e24c12009-10-30 11:49:00 +00001076 sample_env.Replace(**context.flags['sample'])
Steve Block6ded16b2010-05-10 14:33:55 +01001077 sample_env.Prepend(LIBS=[library_name])
Steve Blocka7e24c12009-10-30 11:49:00 +00001078 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 Block6ded16b2010-05-10 14:33:55 +01001090 cctest_env = env.Copy()
1091 cctest_env.Prepend(LIBS=[library_name])
1092 cctest_program = cctest_env.SConscript(
Steve Blocka7e24c12009-10-30 11:49:00 +00001093 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
1103def 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 Murdoch7f4d5bd2010-06-15 11:15:29 +01001137 if env['cache']:
1138 CacheDir(env['cache'])
Steve Blocka7e24c12009-10-30 11:49:00 +00001139
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.
1145try:
1146 SetOption('warn', 'no-deprecated')
1147except:
1148 pass
1149
1150
1151Build()