blob: c7543d997b2d7990c5cb9db91602bbd659a31704 [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
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 },
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
665OS_GUESS = utils.GuessOS()
666TOOLCHAIN_GUESS = GuessToolchain(OS_GUESS)
667ARCH_GUESS = utils.GuessArchitecture()
668
669
670SIMPLE_OPTIONS = {
671 'toolchain': {
672 'values': ['gcc', 'msvc'],
673 'default': TOOLCHAIN_GUESS,
674 'help': 'the toolchain to use (' + TOOLCHAIN_GUESS + ')'
675 },
676 'os': {
Leon Clarked91b9f72010-01-27 17:25:45 +0000677 'values': ['freebsd', 'linux', 'macos', 'win32', 'android', 'openbsd', 'solaris'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000678 'default': OS_GUESS,
679 'help': 'the os to build for (' + OS_GUESS + ')'
680 },
681 'arch': {
Andrei Popescu31002712010-02-23 13:46:05 +0000682 'values':['arm', 'ia32', 'x64', 'mips'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000683 'default': ARCH_GUESS,
684 'help': 'the architecture to build for (' + ARCH_GUESS + ')'
685 },
686 'regexp': {
687 'values': ['native', 'interpreted'],
688 'default': 'native',
689 'help': 'Whether to use native or interpreted regexp implementation'
690 },
691 'snapshot': {
692 'values': ['on', 'off', 'nobuild'],
693 'default': 'off',
694 'help': 'build using snapshots for faster start-up'
695 },
696 'prof': {
697 'values': ['on', 'off', 'oprofile'],
698 'default': 'off',
699 'help': 'enable profiling of build target'
700 },
701 'library': {
702 'values': ['static', 'shared'],
703 'default': 'static',
704 'help': 'the type of library to produce'
705 },
Steve Block6ded16b2010-05-10 14:33:55 +0100706 'vmstate': {
707 'values': ['on', 'off'],
708 'default': 'off',
709 'help': 'enable VM state tracking'
710 },
711 'protectheap': {
712 'values': ['on', 'off'],
713 'default': 'off',
714 'help': 'enable heap protection'
715 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000716 'profilingsupport': {
717 'values': ['on', 'off'],
718 'default': 'on',
719 'help': 'enable profiling of JavaScript code'
720 },
721 'debuggersupport': {
722 'values': ['on', 'off'],
723 'default': 'on',
724 'help': 'enable debugging of JavaScript code'
725 },
726 'soname': {
727 'values': ['on', 'off'],
728 'default': 'off',
729 'help': 'turn on setting soname for Linux shared library'
730 },
731 'msvcrt': {
732 'values': ['static', 'shared'],
733 'default': 'static',
734 'help': 'the type of Microsoft Visual C++ runtime library to use'
735 },
736 'msvcltcg': {
737 'values': ['on', 'off'],
738 'default': 'on',
739 'help': 'use Microsoft Visual C++ link-time code generation'
740 },
741 'simulator': {
Andrei Popescu31002712010-02-23 13:46:05 +0000742 'values': ['arm', 'mips', 'none'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000743 'default': 'none',
744 'help': 'build with simulator'
745 },
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100746 'unalignedaccesses': {
747 'values': ['default', 'on', 'off'],
748 'default': 'default',
749 'help': 'set whether the ARM target supports unaligned accesses'
750 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000751 'disassembler': {
752 'values': ['on', 'off'],
753 'default': 'off',
754 'help': 'enable the disassembler to inspect generated code'
755 },
756 'sourcesignatures': {
757 'values': ['MD5', 'timestamp'],
758 'default': 'MD5',
759 'help': 'set how the build system detects file changes'
760 },
761 'console': {
762 'values': ['dumb', 'readline'],
763 'default': 'dumb',
764 'help': 'the console to use for the d8 shell'
765 },
766 'verbose': {
767 'values': ['on', 'off'],
768 'default': 'off',
769 'help': 'more output from compiler and linker'
770 },
771 'visibility': {
772 'values': ['default', 'hidden'],
773 'default': 'hidden',
774 'help': 'shared library symbol visibility'
Leon Clarkee46be812010-01-19 14:06:41 +0000775 },
Steve Block6ded16b2010-05-10 14:33:55 +0100776 'pgo': {
777 'values': ['off', 'instrument', 'optimize'],
778 'default': 'off',
779 'help': 'select profile guided optimization variant',
Steve Blocka7e24c12009-10-30 11:49:00 +0000780 }
781}
782
783
784def GetOptions():
785 result = Options()
786 result.Add('mode', 'compilation mode (debug, release)', 'release')
Leon Clarkee46be812010-01-19 14:06:41 +0000787 result.Add('sample', 'build sample (shell, process, lineprocessor)', '')
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100788 result.Add('cache', 'directory to use for scons build cache', '')
Steve Blocka7e24c12009-10-30 11:49:00 +0000789 result.Add('env', 'override environment settings (NAME0:value0,NAME1:value1,...)', '')
790 result.Add('importenv', 'import environment settings (NAME0,NAME1,...)', '')
791 for (name, option) in SIMPLE_OPTIONS.iteritems():
792 help = '%s (%s)' % (name, ", ".join(option['values']))
793 result.Add(name, help, option.get('default'))
794 return result
795
796
797def GetVersionComponents():
798 MAJOR_VERSION_PATTERN = re.compile(r"#define\s+MAJOR_VERSION\s+(.*)")
799 MINOR_VERSION_PATTERN = re.compile(r"#define\s+MINOR_VERSION\s+(.*)")
800 BUILD_NUMBER_PATTERN = re.compile(r"#define\s+BUILD_NUMBER\s+(.*)")
801 PATCH_LEVEL_PATTERN = re.compile(r"#define\s+PATCH_LEVEL\s+(.*)")
802
803 patterns = [MAJOR_VERSION_PATTERN,
804 MINOR_VERSION_PATTERN,
805 BUILD_NUMBER_PATTERN,
806 PATCH_LEVEL_PATTERN]
807
808 source = open(join(root_dir, 'src', 'version.cc')).read()
809 version_components = []
810 for pattern in patterns:
811 match = pattern.search(source)
812 if match:
813 version_components.append(match.group(1).strip())
814 else:
815 version_components.append('0')
816
817 return version_components
818
819
820def GetVersion():
821 version_components = GetVersionComponents()
822
823 if version_components[len(version_components) - 1] == '0':
824 version_components.pop()
825 return '.'.join(version_components)
826
827
828def GetSpecificSONAME():
829 SONAME_PATTERN = re.compile(r"#define\s+SONAME\s+\"(.*)\"")
830
831 source = open(join(root_dir, 'src', 'version.cc')).read()
832 match = SONAME_PATTERN.search(source)
833
834 if match:
835 return match.group(1).strip()
836 else:
837 return ''
838
839
840def SplitList(str):
841 return [ s for s in str.split(",") if len(s) > 0 ]
842
843
844def IsLegal(env, option, values):
845 str = env[option]
846 for s in SplitList(str):
847 if not s in values:
848 Abort("Illegal value for option %s '%s'." % (option, s))
849 return False
850 return True
851
852
853def VerifyOptions(env):
854 if not IsLegal(env, 'mode', ['debug', 'release']):
855 return False
Leon Clarkee46be812010-01-19 14:06:41 +0000856 if not IsLegal(env, 'sample', ["shell", "process", "lineprocessor"]):
Steve Blocka7e24c12009-10-30 11:49:00 +0000857 return False
858 if not IsLegal(env, 'regexp', ["native", "interpreted"]):
859 return False
860 if env['os'] == 'win32' and env['library'] == 'shared' and env['prof'] == 'on':
861 Abort("Profiling on windows only supported for static library.")
862 if env['prof'] == 'oprofile' and env['os'] != 'linux':
863 Abort("OProfile is only supported on Linux.")
864 if env['os'] == 'win32' and env['soname'] == 'on':
865 Abort("Shared Object soname not applicable for Windows.")
866 if env['soname'] == 'on' and env['library'] == 'static':
867 Abort("Shared Object soname not applicable for static library.")
Steve Block6ded16b2010-05-10 14:33:55 +0100868 if env['os'] != 'win32' and env['pgo'] != 'off':
869 Abort("Profile guided optimization only supported on Windows.")
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100870 if env['cache'] and not os.path.isdir(env['cache']):
871 Abort("The specified cache directory does not exist.")
872 if not (env['arch'] == 'arm' or env['simulator'] == 'arm') and ('unalignedaccesses' in ARGUMENTS):
873 print env['arch']
874 print env['simulator']
875 Abort("Option unalignedaccesses only supported for the ARM architecture.")
Steve Blocka7e24c12009-10-30 11:49:00 +0000876 for (name, option) in SIMPLE_OPTIONS.iteritems():
877 if (not option.get('default')) and (name not in ARGUMENTS):
878 message = ("A value for option %s must be specified (%s)." %
879 (name, ", ".join(option['values'])))
880 Abort(message)
881 if not env[name] in option['values']:
882 message = ("Unknown %s value '%s'. Possible values are (%s)." %
883 (name, env[name], ", ".join(option['values'])))
884 Abort(message)
885
886
887class BuildContext(object):
888
889 def __init__(self, options, env_overrides, samples):
890 self.library_targets = []
891 self.mksnapshot_targets = []
892 self.cctest_targets = []
893 self.sample_targets = []
894 self.d8_targets = []
895 self.options = options
896 self.env_overrides = env_overrides
897 self.samples = samples
898 self.use_snapshot = (options['snapshot'] != 'off')
899 self.build_snapshot = (options['snapshot'] == 'on')
900 self.flags = None
901
902 def AddRelevantFlags(self, initial, flags):
903 result = initial.copy()
904 toolchain = self.options['toolchain']
905 if toolchain in flags:
906 self.AppendFlags(result, flags[toolchain].get('all'))
907 for option in sorted(self.options.keys()):
908 value = self.options[option]
909 self.AppendFlags(result, flags[toolchain].get(option + ':' + value))
910 self.AppendFlags(result, flags.get('all'))
911 return result
912
913 def AddRelevantSubFlags(self, options, flags):
914 self.AppendFlags(options, flags.get('all'))
915 for option in sorted(self.options.keys()):
916 value = self.options[option]
917 self.AppendFlags(options, flags.get(option + ':' + value))
918
919 def GetRelevantSources(self, source):
920 result = []
921 result += source.get('all', [])
922 for (name, value) in self.options.iteritems():
923 source_value = source.get(name + ':' + value, [])
924 if type(source_value) == dict:
925 result += self.GetRelevantSources(source_value)
926 else:
927 result += source_value
928 return sorted(result)
929
930 def AppendFlags(self, options, added):
931 if not added:
932 return
933 for (key, value) in added.iteritems():
934 if key.find(':') != -1:
935 self.AddRelevantSubFlags(options, { key: value })
936 else:
937 if not key in options:
938 options[key] = value
939 else:
940 prefix = options[key]
941 if isinstance(prefix, StringTypes): prefix = prefix.split()
942 options[key] = prefix + value
943
944 def ConfigureObject(self, env, input, **kw):
945 if (kw.has_key('CPPPATH') and env.has_key('CPPPATH')):
946 kw['CPPPATH'] += env['CPPPATH']
947 if self.options['library'] == 'static':
948 return env.StaticObject(input, **kw)
949 else:
950 return env.SharedObject(input, **kw)
951
952 def ApplyEnvOverrides(self, env):
953 if not self.env_overrides:
954 return
955 if type(env['ENV']) == DictType:
956 env['ENV'].update(**self.env_overrides)
957 else:
958 env['ENV'] = self.env_overrides
959
960
Steve Block6ded16b2010-05-10 14:33:55 +0100961def PostprocessOptions(options, os):
Steve Blocka7e24c12009-10-30 11:49:00 +0000962 # Adjust architecture if the simulator option has been set
963 if (options['simulator'] != 'none') and (options['arch'] != options['simulator']):
964 if 'arch' in ARGUMENTS:
965 # Print a warning if arch has explicitly been set
966 print "Warning: forcing architecture to match simulator (%s)" % options['simulator']
967 options['arch'] = options['simulator']
968 if (options['prof'] != 'off') and (options['profilingsupport'] == 'off'):
969 # Print a warning if profiling is enabled without profiling support
970 print "Warning: forcing profilingsupport on when prof is on"
971 options['profilingsupport'] = 'on'
Steve Block6ded16b2010-05-10 14:33:55 +0100972 if os == 'win32' and options['pgo'] != 'off' and options['msvcltcg'] == 'off':
973 if 'msvcltcg' in ARGUMENTS:
974 print "Warning: forcing msvcltcg on as it is required for pgo (%s)" % options['pgo']
975 options['msvcltcg'] = 'on'
Andrei Popescu31002712010-02-23 13:46:05 +0000976 if options['arch'] == 'mips':
977 if ('regexp' in ARGUMENTS) and options['regexp'] == 'native':
978 # Print a warning if native regexp is specified for mips
979 print "Warning: forcing regexp to interpreted for mips"
980 options['regexp'] = 'interpreted'
Steve Blocka7e24c12009-10-30 11:49:00 +0000981
982
983def ParseEnvOverrides(arg, imports):
984 # The environment overrides are in the format NAME0:value0,NAME1:value1,...
985 # The environment imports are in the format NAME0,NAME1,...
986 overrides = {}
987 for var in imports.split(','):
988 if var in os.environ:
989 overrides[var] = os.environ[var]
990 for override in arg.split(','):
991 pos = override.find(':')
992 if pos == -1:
993 continue
994 overrides[override[:pos].strip()] = override[pos+1:].strip()
995 return overrides
996
997
998def BuildSpecific(env, mode, env_overrides):
999 options = {'mode': mode}
1000 for option in SIMPLE_OPTIONS:
1001 options[option] = env[option]
Steve Block6ded16b2010-05-10 14:33:55 +01001002 PostprocessOptions(options, env['os'])
Steve Blocka7e24c12009-10-30 11:49:00 +00001003
1004 context = BuildContext(options, env_overrides, samples=SplitList(env['sample']))
1005
1006 # Remove variables which can't be imported from the user's external
1007 # environment into a construction environment.
1008 user_environ = os.environ.copy()
1009 try:
1010 del user_environ['ENV']
1011 except KeyError:
1012 pass
1013
1014 library_flags = context.AddRelevantFlags(user_environ, LIBRARY_FLAGS)
1015 v8_flags = context.AddRelevantFlags(library_flags, V8_EXTRA_FLAGS)
1016 mksnapshot_flags = context.AddRelevantFlags(library_flags, MKSNAPSHOT_EXTRA_FLAGS)
1017 dtoa_flags = context.AddRelevantFlags(library_flags, DTOA_EXTRA_FLAGS)
1018 cctest_flags = context.AddRelevantFlags(v8_flags, CCTEST_EXTRA_FLAGS)
1019 sample_flags = context.AddRelevantFlags(user_environ, SAMPLE_FLAGS)
1020 d8_flags = context.AddRelevantFlags(library_flags, D8_FLAGS)
1021
1022 context.flags = {
1023 'v8': v8_flags,
1024 'mksnapshot': mksnapshot_flags,
1025 'dtoa': dtoa_flags,
1026 'cctest': cctest_flags,
1027 'sample': sample_flags,
1028 'd8': d8_flags
1029 }
1030
1031 # Generate library base name.
1032 target_id = mode
1033 suffix = SUFFIXES[target_id]
1034 library_name = 'v8' + suffix
1035 version = GetVersion()
1036 if context.options['soname'] == 'on':
1037 # When building shared object with SONAME version the library name.
1038 library_name += '-' + version
Steve Blocka7e24c12009-10-30 11:49:00 +00001039
1040 # Generate library SONAME if required by the build.
1041 if context.options['soname'] == 'on':
1042 soname = GetSpecificSONAME()
1043 if soname == '':
1044 soname = 'lib' + library_name + '.so'
1045 env['SONAME'] = soname
1046
1047 # Build the object files by invoking SCons recursively.
1048 (object_files, shell_files, mksnapshot) = env.SConscript(
1049 join('src', 'SConscript'),
1050 build_dir=join('obj', target_id),
1051 exports='context',
1052 duplicate=False
1053 )
1054
1055 context.mksnapshot_targets.append(mksnapshot)
1056
1057 # Link the object files into a library.
1058 env.Replace(**context.flags['v8'])
Leon Clarked91b9f72010-01-27 17:25:45 +00001059
Steve Blocka7e24c12009-10-30 11:49:00 +00001060 context.ApplyEnvOverrides(env)
1061 if context.options['library'] == 'static':
1062 library = env.StaticLibrary(library_name, object_files)
1063 else:
1064 # There seems to be a glitch in the way scons decides where to put
1065 # PDB files when compiling using MSVC so we specify it manually.
1066 # This should not affect any other platforms.
1067 pdb_name = library_name + '.dll.pdb'
1068 library = env.SharedLibrary(library_name, object_files, PDB=pdb_name)
1069 context.library_targets.append(library)
1070
1071 d8_env = Environment()
1072 d8_env.Replace(**context.flags['d8'])
Leon Clarkee46be812010-01-19 14:06:41 +00001073 context.ApplyEnvOverrides(d8_env)
Steve Blocka7e24c12009-10-30 11:49:00 +00001074 shell = d8_env.Program('d8' + suffix, object_files + shell_files)
1075 context.d8_targets.append(shell)
1076
1077 for sample in context.samples:
Steve Block6ded16b2010-05-10 14:33:55 +01001078 sample_env = Environment()
Steve Blocka7e24c12009-10-30 11:49:00 +00001079 sample_env.Replace(**context.flags['sample'])
Steve Block6ded16b2010-05-10 14:33:55 +01001080 sample_env.Prepend(LIBS=[library_name])
Steve Blocka7e24c12009-10-30 11:49:00 +00001081 context.ApplyEnvOverrides(sample_env)
1082 sample_object = sample_env.SConscript(
1083 join('samples', 'SConscript'),
1084 build_dir=join('obj', 'sample', sample, target_id),
1085 exports='sample context',
1086 duplicate=False
1087 )
1088 sample_name = sample + suffix
1089 sample_program = sample_env.Program(sample_name, sample_object)
1090 sample_env.Depends(sample_program, library)
1091 context.sample_targets.append(sample_program)
1092
Steve Block6ded16b2010-05-10 14:33:55 +01001093 cctest_env = env.Copy()
1094 cctest_env.Prepend(LIBS=[library_name])
1095 cctest_program = cctest_env.SConscript(
Steve Blocka7e24c12009-10-30 11:49:00 +00001096 join('test', 'cctest', 'SConscript'),
1097 build_dir=join('obj', 'test', target_id),
1098 exports='context object_files',
1099 duplicate=False
1100 )
1101 context.cctest_targets.append(cctest_program)
1102
1103 return context
1104
1105
1106def Build():
1107 opts = GetOptions()
1108 env = Environment(options=opts)
1109 Help(opts.GenerateHelpText(env))
1110 VerifyOptions(env)
1111 env_overrides = ParseEnvOverrides(env['env'], env['importenv'])
1112
1113 SourceSignatures(env['sourcesignatures'])
1114
1115 libraries = []
1116 mksnapshots = []
1117 cctests = []
1118 samples = []
1119 d8s = []
1120 modes = SplitList(env['mode'])
1121 for mode in modes:
1122 context = BuildSpecific(env.Copy(), mode, env_overrides)
1123 libraries += context.library_targets
1124 mksnapshots += context.mksnapshot_targets
1125 cctests += context.cctest_targets
1126 samples += context.sample_targets
1127 d8s += context.d8_targets
1128
1129 env.Alias('library', libraries)
1130 env.Alias('mksnapshot', mksnapshots)
1131 env.Alias('cctests', cctests)
1132 env.Alias('sample', samples)
1133 env.Alias('d8', d8s)
1134
1135 if env['sample']:
1136 env.Default('sample')
1137 else:
1138 env.Default('library')
1139
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001140 if env['cache']:
1141 CacheDir(env['cache'])
Steve Blocka7e24c12009-10-30 11:49:00 +00001142
1143# We disable deprecation warnings because we need to be able to use
1144# env.Copy without getting warnings for compatibility with older
1145# version of scons. Also, there's a bug in some revisions that
1146# doesn't allow this flag to be set, so we swallow any exceptions.
1147# Lovely.
1148try:
1149 SetOption('warn', 'no-deprecated')
1150except:
1151 pass
1152
1153
1154Build()