blob: 2a39583f1c3e27fffc4cbbe920ed68d2443fe49e [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'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000209 'LINKFLAGS': ['-m32']
210 },
Andrei Popescu31002712010-02-23 13:46:05 +0000211 'arch:mips': {
212 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
213 'simulator:none': {
214 'CCFLAGS': ['-EL', '-mips32r2', '-Wa,-mips32r2', '-fno-inline'],
215 'LDFLAGS': ['-EL']
216 }
217 },
218 'simulator:mips': {
219 'CCFLAGS': ['-m32'],
220 'LINKFLAGS': ['-m32']
221 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000222 'arch:x64': {
223 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
224 'CCFLAGS': ['-m64'],
225 'LINKFLAGS': ['-m64'],
226 },
227 'prof:oprofile': {
228 'CPPDEFINES': ['ENABLE_OPROFILE_AGENT']
229 }
230 },
231 'msvc': {
232 'all': {
233 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
234 'CXXFLAGS': ['$CCFLAGS', '/GR-', '/Gy'],
235 'CPPDEFINES': ['WIN32'],
236 'LINKFLAGS': ['/INCREMENTAL:NO', '/NXCOMPAT', '/IGNORE:4221'],
237 'CCPDBFLAGS': ['/Zi']
238 },
239 'verbose:off': {
240 'DIALECTFLAGS': ['/nologo'],
241 'ARFLAGS': ['/NOLOGO']
242 },
243 'arch:ia32': {
244 'CPPDEFINES': ['V8_TARGET_ARCH_IA32', '_USE_32BIT_TIME_T'],
245 'LINKFLAGS': ['/MACHINE:X86'],
246 'ARFLAGS': ['/MACHINE:X86']
247 },
248 'arch:x64': {
249 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
250 'LINKFLAGS': ['/MACHINE:X64'],
251 'ARFLAGS': ['/MACHINE:X64']
252 },
253 'mode:debug': {
254 'CCFLAGS': ['/Od', '/Gm'],
255 'CPPDEFINES': ['_DEBUG', 'ENABLE_DISASSEMBLER', 'DEBUG'],
256 'LINKFLAGS': ['/DEBUG'],
257 'msvcrt:static': {
258 'CCFLAGS': ['/MTd']
259 },
260 'msvcrt:shared': {
261 'CCFLAGS': ['/MDd']
262 }
263 },
264 'mode:release': {
265 'CCFLAGS': ['/O2'],
266 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
267 'msvcrt:static': {
268 'CCFLAGS': ['/MT']
269 },
270 'msvcrt:shared': {
271 'CCFLAGS': ['/MD']
272 },
273 'msvcltcg:on': {
274 'CCFLAGS': ['/GL'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000275 'ARFLAGS': ['/LTCG'],
Steve Block6ded16b2010-05-10 14:33:55 +0100276 'pgo:off': {
277 'LINKFLAGS': ['/LTCG'],
278 },
279 'pgo:instrument': {
280 'LINKFLAGS': ['/LTCG:PGI']
281 },
282 'pgo:optimize': {
283 'LINKFLAGS': ['/LTCG:PGO']
284 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000285 }
286 }
287 }
288}
289
290
291V8_EXTRA_FLAGS = {
292 'gcc': {
293 'all': {
294 'WARNINGFLAGS': ['-Wall',
295 '-Werror',
296 '-W',
297 '-Wno-unused-parameter',
298 '-Wnon-virtual-dtor']
299 },
300 'os:win32': {
301 'WARNINGFLAGS': ['-pedantic', '-Wno-long-long']
302 },
303 'os:linux': {
304 'WARNINGFLAGS': ['-pedantic'],
305 'library:shared': {
306 'soname:on': {
307 'LINKFLAGS': ['-Wl,-soname,${SONAME}']
308 }
309 }
310 },
311 'os:macos': {
312 'WARNINGFLAGS': ['-pedantic']
313 },
314 'disassembler:on': {
315 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
316 }
317 },
318 'msvc': {
319 'all': {
Leon Clarked91b9f72010-01-27 17:25:45 +0000320 'WARNINGFLAGS': ['/W3', '/WX', '/wd4355', '/wd4800']
Steve Blocka7e24c12009-10-30 11:49:00 +0000321 },
322 'library:shared': {
323 'CPPDEFINES': ['BUILDING_V8_SHARED'],
324 'LIBS': ['winmm', 'ws2_32']
325 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000326 'arch:arm': {
327 'CPPDEFINES': ['V8_TARGET_ARCH_ARM'],
328 # /wd4996 is to silence the warning about sscanf
329 # used by the arm simulator.
330 'WARNINGFLAGS': ['/wd4996']
331 },
Andrei Popescu31002712010-02-23 13:46:05 +0000332 'arch:mips': {
333 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
334 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000335 'disassembler:on': {
336 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
337 }
338 }
339}
340
341
342MKSNAPSHOT_EXTRA_FLAGS = {
343 'gcc': {
344 'os:linux': {
345 'LIBS': ['pthread'],
346 },
347 'os:macos': {
348 'LIBS': ['pthread'],
349 },
350 'os:freebsd': {
351 'LIBS': ['execinfo', 'pthread']
352 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000353 'os:solaris': {
354 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
355 'LINKFLAGS': ['-mt']
356 },
Steve Blockd0582a62009-12-15 09:54:21 +0000357 'os:openbsd': {
358 'LIBS': ['execinfo', 'pthread']
359 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000360 'os:win32': {
361 'LIBS': ['winmm', 'ws2_32'],
362 },
363 },
364 'msvc': {
365 'all': {
366 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
367 'LIBS': ['winmm', 'ws2_32']
368 }
369 }
370}
371
372
373DTOA_EXTRA_FLAGS = {
374 'gcc': {
375 'all': {
376 'WARNINGFLAGS': ['-Werror', '-Wno-uninitialized'],
377 'CCFLAGS': GCC_DTOA_EXTRA_CCFLAGS
378 }
379 },
380 'msvc': {
381 'all': {
382 'WARNINGFLAGS': ['/WX', '/wd4018', '/wd4244']
383 }
384 }
385}
386
387
388CCTEST_EXTRA_FLAGS = {
389 'all': {
390 'CPPPATH': [join(root_dir, 'src')],
Steve Blocka7e24c12009-10-30 11:49:00 +0000391 },
392 'gcc': {
393 'all': {
394 'LIBPATH': [abspath('.')]
395 },
396 'os:linux': {
397 'LIBS': ['pthread'],
398 },
399 'os:macos': {
400 'LIBS': ['pthread'],
401 },
402 'os:freebsd': {
403 'LIBS': ['execinfo', 'pthread']
404 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000405 'os:solaris': {
406 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
407 'LINKFLAGS': ['-mt']
408 },
Steve Blockd0582a62009-12-15 09:54:21 +0000409 'os:openbsd': {
410 'LIBS': ['execinfo', 'pthread']
411 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000412 'os:win32': {
413 'LIBS': ['winmm', 'ws2_32']
414 },
415 'os:android': {
416 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__',
417 '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'],
418 'CCFLAGS': ANDROID_FLAGS,
419 'CPPPATH': ANDROID_INCLUDES,
Steve Block6ded16b2010-05-10 14:33:55 +0100420 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib',
421 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 +0000422 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100423 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000424 'mode:release': {
425 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
426 }
427 },
Steve Block6ded16b2010-05-10 14:33:55 +0100428 'arch:arm': {
429 'LINKFLAGS': ARM_LINK_FLAGS
430 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000431 },
432 'msvc': {
433 'all': {
434 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
435 'LIBS': ['winmm', 'ws2_32']
436 },
437 'library:shared': {
438 'CPPDEFINES': ['USING_V8_SHARED']
439 },
440 'arch:ia32': {
441 'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
442 },
443 'arch:x64': {
Steve Block3ce2e202009-11-05 08:53:23 +0000444 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
445 'LINKFLAGS': ['/STACK:2091752']
Steve Blocka7e24c12009-10-30 11:49:00 +0000446 },
447 }
448}
449
450
451SAMPLE_FLAGS = {
452 'all': {
453 'CPPPATH': [join(abspath('.'), 'include')],
Steve Blocka7e24c12009-10-30 11:49:00 +0000454 },
455 'gcc': {
456 'all': {
457 'LIBPATH': ['.'],
458 'CCFLAGS': ['-fno-rtti', '-fno-exceptions']
459 },
460 'os:linux': {
461 'LIBS': ['pthread'],
462 },
463 'os:macos': {
464 'LIBS': ['pthread'],
465 },
466 'os:freebsd': {
467 'LIBPATH' : ['/usr/local/lib'],
Steve Blockd0582a62009-12-15 09:54:21 +0000468 'LIBS': ['execinfo', 'pthread']
469 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000470 'os:solaris': {
471 'LIBPATH' : ['/usr/local/lib'],
472 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
473 'LINKFLAGS': ['-mt']
474 },
Steve Blockd0582a62009-12-15 09:54:21 +0000475 'os:openbsd': {
476 'LIBPATH' : ['/usr/local/lib'],
477 'LIBS': ['execinfo', 'pthread']
Steve Blocka7e24c12009-10-30 11:49:00 +0000478 },
479 'os:win32': {
480 'LIBS': ['winmm', 'ws2_32']
481 },
482 'os:android': {
483 'CPPDEFINES': ['ANDROID', '__ARM_ARCH_5__', '__ARM_ARCH_5T__',
484 '__ARM_ARCH_5E__', '__ARM_ARCH_5TE__'],
485 'CCFLAGS': ANDROID_FLAGS,
486 'CPPPATH': ANDROID_INCLUDES,
Steve Block6ded16b2010-05-10 14:33:55 +0100487 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib',
488 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 +0000489 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100490 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000491 'mode:release': {
492 'CPPDEFINES': ['SK_RELEASE', 'NDEBUG']
493 }
494 },
Steve Block6ded16b2010-05-10 14:33:55 +0100495 'arch:arm': {
496 'LINKFLAGS': ARM_LINK_FLAGS
497 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000498 'arch:ia32': {
499 'CCFLAGS': ['-m32'],
500 'LINKFLAGS': ['-m32']
501 },
502 'arch:x64': {
503 'CCFLAGS': ['-m64'],
504 'LINKFLAGS': ['-m64']
505 },
Andrei Popescu31002712010-02-23 13:46:05 +0000506 'arch:mips': {
507 'CPPDEFINES': ['V8_TARGET_ARCH_MIPS'],
508 'simulator:none': {
509 'CCFLAGS': ['-EL', '-mips32r2', '-Wa,-mips32r2', '-fno-inline'],
510 'LINKFLAGS': ['-EL'],
511 'LDFLAGS': ['-EL']
512 }
513 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000514 'simulator:arm': {
515 'CCFLAGS': ['-m32'],
516 'LINKFLAGS': ['-m32']
517 },
Andrei Popescu31002712010-02-23 13:46:05 +0000518 'simulator:mips': {
519 'CCFLAGS': ['-m32'],
520 'LINKFLAGS': ['-m32']
521 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000522 'mode:release': {
523 'CCFLAGS': ['-O2']
524 },
525 'mode:debug': {
526 'CCFLAGS': ['-g', '-O0']
527 },
528 'prof:oprofile': {
529 'LIBPATH': ['/usr/lib32', '/usr/lib32/oprofile'],
530 'LIBS': ['opagent']
531 }
532 },
533 'msvc': {
534 'all': {
535 'LIBS': ['winmm', 'ws2_32']
536 },
537 'verbose:off': {
538 'CCFLAGS': ['/nologo'],
539 'LINKFLAGS': ['/NOLOGO']
540 },
541 'verbose:on': {
542 'LINKFLAGS': ['/VERBOSE']
543 },
544 'library:shared': {
545 'CPPDEFINES': ['USING_V8_SHARED']
546 },
547 'prof:on': {
548 'LINKFLAGS': ['/MAP']
549 },
550 'mode:release': {
551 'CCFLAGS': ['/O2'],
552 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'],
553 'msvcrt:static': {
554 'CCFLAGS': ['/MT']
555 },
556 'msvcrt:shared': {
557 'CCFLAGS': ['/MD']
558 },
559 'msvcltcg:on': {
560 'CCFLAGS': ['/GL'],
Steve Block6ded16b2010-05-10 14:33:55 +0100561 'pgo:off': {
562 'LINKFLAGS': ['/LTCG'],
563 },
564 },
565 'pgo:instrument': {
566 'LINKFLAGS': ['/LTCG:PGI']
567 },
568 'pgo:optimize': {
569 'LINKFLAGS': ['/LTCG:PGO']
Steve Blocka7e24c12009-10-30 11:49:00 +0000570 }
571 },
572 'arch:ia32': {
573 'CPPDEFINES': ['V8_TARGET_ARCH_IA32'],
574 'LINKFLAGS': ['/MACHINE:X86']
575 },
576 'arch:x64': {
577 'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
Steve Block3ce2e202009-11-05 08:53:23 +0000578 'LINKFLAGS': ['/MACHINE:X64', '/STACK:2091752']
Steve Blocka7e24c12009-10-30 11:49:00 +0000579 },
580 'mode:debug': {
581 'CCFLAGS': ['/Od'],
582 'LINKFLAGS': ['/DEBUG'],
583 'msvcrt:static': {
584 'CCFLAGS': ['/MTd']
585 },
586 'msvcrt:shared': {
587 'CCFLAGS': ['/MDd']
588 }
589 }
590 }
591}
592
593
594D8_FLAGS = {
595 'gcc': {
596 'console:readline': {
597 'LIBS': ['readline']
598 },
599 'os:linux': {
600 'LIBS': ['pthread'],
601 },
602 'os:macos': {
603 'LIBS': ['pthread'],
604 },
605 'os:freebsd': {
606 'LIBS': ['pthread'],
607 },
Leon Clarked91b9f72010-01-27 17:25:45 +0000608 'os:solaris': {
609 'LIBS': ['m', 'pthread', 'socket', 'nsl', 'rt'],
610 'LINKFLAGS': ['-mt']
611 },
Steve Blockd0582a62009-12-15 09:54:21 +0000612 'os:openbsd': {
613 'LIBS': ['pthread'],
614 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000615 'os:android': {
Steve Block6ded16b2010-05-10 14:33:55 +0100616 'LIBPATH': [ANDROID_TOP + '/out/target/product/generic/obj/lib',
617 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 +0000618 'LINKFLAGS': ANDROID_LINKFLAGS,
Steve Block6ded16b2010-05-10 14:33:55 +0100619 'LIBS': ['log', 'c', 'stdc++', 'm', 'gcc'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000620 },
621 'os:win32': {
622 'LIBS': ['winmm', 'ws2_32'],
623 },
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100624 'arch:arm': {
625 'LINKFLAGS': ARM_LINK_FLAGS
626 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000627 },
628 'msvc': {
629 'all': {
630 'LIBS': ['winmm', 'ws2_32']
631 }
632 }
633}
634
635
636SUFFIXES = {
637 'release': '',
638 'debug': '_g'
639}
640
641
642def Abort(message):
643 print message
644 sys.exit(1)
645
646
647def GuessToolchain(os):
648 tools = Environment()['TOOLS']
649 if 'gcc' in tools:
650 return 'gcc'
651 elif 'msvc' in tools:
652 return 'msvc'
653 else:
654 return None
655
656
657OS_GUESS = utils.GuessOS()
658TOOLCHAIN_GUESS = GuessToolchain(OS_GUESS)
659ARCH_GUESS = utils.GuessArchitecture()
660
661
662SIMPLE_OPTIONS = {
663 'toolchain': {
664 'values': ['gcc', 'msvc'],
665 'default': TOOLCHAIN_GUESS,
666 'help': 'the toolchain to use (' + TOOLCHAIN_GUESS + ')'
667 },
668 'os': {
Leon Clarked91b9f72010-01-27 17:25:45 +0000669 'values': ['freebsd', 'linux', 'macos', 'win32', 'android', 'openbsd', 'solaris'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000670 'default': OS_GUESS,
671 'help': 'the os to build for (' + OS_GUESS + ')'
672 },
673 'arch': {
Andrei Popescu31002712010-02-23 13:46:05 +0000674 'values':['arm', 'ia32', 'x64', 'mips'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000675 'default': ARCH_GUESS,
676 'help': 'the architecture to build for (' + ARCH_GUESS + ')'
677 },
678 'regexp': {
679 'values': ['native', 'interpreted'],
680 'default': 'native',
681 'help': 'Whether to use native or interpreted regexp implementation'
682 },
683 'snapshot': {
684 'values': ['on', 'off', 'nobuild'],
685 'default': 'off',
686 'help': 'build using snapshots for faster start-up'
687 },
688 'prof': {
689 'values': ['on', 'off', 'oprofile'],
690 'default': 'off',
691 'help': 'enable profiling of build target'
692 },
693 'library': {
694 'values': ['static', 'shared'],
695 'default': 'static',
696 'help': 'the type of library to produce'
697 },
Steve Block6ded16b2010-05-10 14:33:55 +0100698 'vmstate': {
699 'values': ['on', 'off'],
700 'default': 'off',
701 'help': 'enable VM state tracking'
702 },
703 'protectheap': {
704 'values': ['on', 'off'],
705 'default': 'off',
706 'help': 'enable heap protection'
707 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000708 'profilingsupport': {
709 'values': ['on', 'off'],
710 'default': 'on',
711 'help': 'enable profiling of JavaScript code'
712 },
713 'debuggersupport': {
714 'values': ['on', 'off'],
715 'default': 'on',
716 'help': 'enable debugging of JavaScript code'
717 },
718 'soname': {
719 'values': ['on', 'off'],
720 'default': 'off',
721 'help': 'turn on setting soname for Linux shared library'
722 },
723 'msvcrt': {
724 'values': ['static', 'shared'],
725 'default': 'static',
726 'help': 'the type of Microsoft Visual C++ runtime library to use'
727 },
728 'msvcltcg': {
729 'values': ['on', 'off'],
730 'default': 'on',
731 'help': 'use Microsoft Visual C++ link-time code generation'
732 },
733 'simulator': {
Andrei Popescu31002712010-02-23 13:46:05 +0000734 'values': ['arm', 'mips', 'none'],
Steve Blocka7e24c12009-10-30 11:49:00 +0000735 'default': 'none',
736 'help': 'build with simulator'
737 },
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100738 'unalignedaccesses': {
739 'values': ['default', 'on', 'off'],
740 'default': 'default',
741 'help': 'set whether the ARM target supports unaligned accesses'
742 },
Steve Blocka7e24c12009-10-30 11:49:00 +0000743 'disassembler': {
744 'values': ['on', 'off'],
745 'default': 'off',
746 'help': 'enable the disassembler to inspect generated code'
747 },
748 'sourcesignatures': {
749 'values': ['MD5', 'timestamp'],
750 'default': 'MD5',
751 'help': 'set how the build system detects file changes'
752 },
753 'console': {
754 'values': ['dumb', 'readline'],
755 'default': 'dumb',
756 'help': 'the console to use for the d8 shell'
757 },
758 'verbose': {
759 'values': ['on', 'off'],
760 'default': 'off',
761 'help': 'more output from compiler and linker'
762 },
763 'visibility': {
764 'values': ['default', 'hidden'],
765 'default': 'hidden',
766 'help': 'shared library symbol visibility'
Leon Clarkee46be812010-01-19 14:06:41 +0000767 },
Steve Block6ded16b2010-05-10 14:33:55 +0100768 'pgo': {
769 'values': ['off', 'instrument', 'optimize'],
770 'default': 'off',
771 'help': 'select profile guided optimization variant',
Steve Blocka7e24c12009-10-30 11:49:00 +0000772 }
773}
774
775
776def GetOptions():
777 result = Options()
778 result.Add('mode', 'compilation mode (debug, release)', 'release')
Leon Clarkee46be812010-01-19 14:06:41 +0000779 result.Add('sample', 'build sample (shell, process, lineprocessor)', '')
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100780 result.Add('cache', 'directory to use for scons build cache', '')
Steve Blocka7e24c12009-10-30 11:49:00 +0000781 result.Add('env', 'override environment settings (NAME0:value0,NAME1:value1,...)', '')
782 result.Add('importenv', 'import environment settings (NAME0,NAME1,...)', '')
783 for (name, option) in SIMPLE_OPTIONS.iteritems():
784 help = '%s (%s)' % (name, ", ".join(option['values']))
785 result.Add(name, help, option.get('default'))
786 return result
787
788
789def GetVersionComponents():
790 MAJOR_VERSION_PATTERN = re.compile(r"#define\s+MAJOR_VERSION\s+(.*)")
791 MINOR_VERSION_PATTERN = re.compile(r"#define\s+MINOR_VERSION\s+(.*)")
792 BUILD_NUMBER_PATTERN = re.compile(r"#define\s+BUILD_NUMBER\s+(.*)")
793 PATCH_LEVEL_PATTERN = re.compile(r"#define\s+PATCH_LEVEL\s+(.*)")
794
795 patterns = [MAJOR_VERSION_PATTERN,
796 MINOR_VERSION_PATTERN,
797 BUILD_NUMBER_PATTERN,
798 PATCH_LEVEL_PATTERN]
799
800 source = open(join(root_dir, 'src', 'version.cc')).read()
801 version_components = []
802 for pattern in patterns:
803 match = pattern.search(source)
804 if match:
805 version_components.append(match.group(1).strip())
806 else:
807 version_components.append('0')
808
809 return version_components
810
811
812def GetVersion():
813 version_components = GetVersionComponents()
814
815 if version_components[len(version_components) - 1] == '0':
816 version_components.pop()
817 return '.'.join(version_components)
818
819
820def GetSpecificSONAME():
821 SONAME_PATTERN = re.compile(r"#define\s+SONAME\s+\"(.*)\"")
822
823 source = open(join(root_dir, 'src', 'version.cc')).read()
824 match = SONAME_PATTERN.search(source)
825
826 if match:
827 return match.group(1).strip()
828 else:
829 return ''
830
831
832def SplitList(str):
833 return [ s for s in str.split(",") if len(s) > 0 ]
834
835
836def IsLegal(env, option, values):
837 str = env[option]
838 for s in SplitList(str):
839 if not s in values:
840 Abort("Illegal value for option %s '%s'." % (option, s))
841 return False
842 return True
843
844
845def VerifyOptions(env):
846 if not IsLegal(env, 'mode', ['debug', 'release']):
847 return False
Leon Clarkee46be812010-01-19 14:06:41 +0000848 if not IsLegal(env, 'sample', ["shell", "process", "lineprocessor"]):
Steve Blocka7e24c12009-10-30 11:49:00 +0000849 return False
850 if not IsLegal(env, 'regexp', ["native", "interpreted"]):
851 return False
852 if env['os'] == 'win32' and env['library'] == 'shared' and env['prof'] == 'on':
853 Abort("Profiling on windows only supported for static library.")
854 if env['prof'] == 'oprofile' and env['os'] != 'linux':
855 Abort("OProfile is only supported on Linux.")
856 if env['os'] == 'win32' and env['soname'] == 'on':
857 Abort("Shared Object soname not applicable for Windows.")
858 if env['soname'] == 'on' and env['library'] == 'static':
859 Abort("Shared Object soname not applicable for static library.")
Steve Block6ded16b2010-05-10 14:33:55 +0100860 if env['os'] != 'win32' and env['pgo'] != 'off':
861 Abort("Profile guided optimization only supported on Windows.")
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100862 if env['cache'] and not os.path.isdir(env['cache']):
863 Abort("The specified cache directory does not exist.")
864 if not (env['arch'] == 'arm' or env['simulator'] == 'arm') and ('unalignedaccesses' in ARGUMENTS):
865 print env['arch']
866 print env['simulator']
867 Abort("Option unalignedaccesses only supported for the ARM architecture.")
Steve Blocka7e24c12009-10-30 11:49:00 +0000868 for (name, option) in SIMPLE_OPTIONS.iteritems():
869 if (not option.get('default')) and (name not in ARGUMENTS):
870 message = ("A value for option %s must be specified (%s)." %
871 (name, ", ".join(option['values'])))
872 Abort(message)
873 if not env[name] in option['values']:
874 message = ("Unknown %s value '%s'. Possible values are (%s)." %
875 (name, env[name], ", ".join(option['values'])))
876 Abort(message)
877
878
879class BuildContext(object):
880
881 def __init__(self, options, env_overrides, samples):
882 self.library_targets = []
883 self.mksnapshot_targets = []
884 self.cctest_targets = []
885 self.sample_targets = []
886 self.d8_targets = []
887 self.options = options
888 self.env_overrides = env_overrides
889 self.samples = samples
890 self.use_snapshot = (options['snapshot'] != 'off')
891 self.build_snapshot = (options['snapshot'] == 'on')
892 self.flags = None
893
894 def AddRelevantFlags(self, initial, flags):
895 result = initial.copy()
896 toolchain = self.options['toolchain']
897 if toolchain in flags:
898 self.AppendFlags(result, flags[toolchain].get('all'))
899 for option in sorted(self.options.keys()):
900 value = self.options[option]
901 self.AppendFlags(result, flags[toolchain].get(option + ':' + value))
902 self.AppendFlags(result, flags.get('all'))
903 return result
904
905 def AddRelevantSubFlags(self, options, flags):
906 self.AppendFlags(options, flags.get('all'))
907 for option in sorted(self.options.keys()):
908 value = self.options[option]
909 self.AppendFlags(options, flags.get(option + ':' + value))
910
911 def GetRelevantSources(self, source):
912 result = []
913 result += source.get('all', [])
914 for (name, value) in self.options.iteritems():
915 source_value = source.get(name + ':' + value, [])
916 if type(source_value) == dict:
917 result += self.GetRelevantSources(source_value)
918 else:
919 result += source_value
920 return sorted(result)
921
922 def AppendFlags(self, options, added):
923 if not added:
924 return
925 for (key, value) in added.iteritems():
926 if key.find(':') != -1:
927 self.AddRelevantSubFlags(options, { key: value })
928 else:
929 if not key in options:
930 options[key] = value
931 else:
932 prefix = options[key]
933 if isinstance(prefix, StringTypes): prefix = prefix.split()
934 options[key] = prefix + value
935
936 def ConfigureObject(self, env, input, **kw):
937 if (kw.has_key('CPPPATH') and env.has_key('CPPPATH')):
938 kw['CPPPATH'] += env['CPPPATH']
939 if self.options['library'] == 'static':
940 return env.StaticObject(input, **kw)
941 else:
942 return env.SharedObject(input, **kw)
943
944 def ApplyEnvOverrides(self, env):
945 if not self.env_overrides:
946 return
947 if type(env['ENV']) == DictType:
948 env['ENV'].update(**self.env_overrides)
949 else:
950 env['ENV'] = self.env_overrides
951
952
Steve Block6ded16b2010-05-10 14:33:55 +0100953def PostprocessOptions(options, os):
Steve Blocka7e24c12009-10-30 11:49:00 +0000954 # Adjust architecture if the simulator option has been set
955 if (options['simulator'] != 'none') and (options['arch'] != options['simulator']):
956 if 'arch' in ARGUMENTS:
957 # Print a warning if arch has explicitly been set
958 print "Warning: forcing architecture to match simulator (%s)" % options['simulator']
959 options['arch'] = options['simulator']
960 if (options['prof'] != 'off') and (options['profilingsupport'] == 'off'):
961 # Print a warning if profiling is enabled without profiling support
962 print "Warning: forcing profilingsupport on when prof is on"
963 options['profilingsupport'] = 'on'
Steve Block6ded16b2010-05-10 14:33:55 +0100964 if os == 'win32' and options['pgo'] != 'off' and options['msvcltcg'] == 'off':
965 if 'msvcltcg' in ARGUMENTS:
966 print "Warning: forcing msvcltcg on as it is required for pgo (%s)" % options['pgo']
967 options['msvcltcg'] = 'on'
Andrei Popescu31002712010-02-23 13:46:05 +0000968 if options['arch'] == 'mips':
969 if ('regexp' in ARGUMENTS) and options['regexp'] == 'native':
970 # Print a warning if native regexp is specified for mips
971 print "Warning: forcing regexp to interpreted for mips"
972 options['regexp'] = 'interpreted'
Steve Blocka7e24c12009-10-30 11:49:00 +0000973
974
975def ParseEnvOverrides(arg, imports):
976 # The environment overrides are in the format NAME0:value0,NAME1:value1,...
977 # The environment imports are in the format NAME0,NAME1,...
978 overrides = {}
979 for var in imports.split(','):
980 if var in os.environ:
981 overrides[var] = os.environ[var]
982 for override in arg.split(','):
983 pos = override.find(':')
984 if pos == -1:
985 continue
986 overrides[override[:pos].strip()] = override[pos+1:].strip()
987 return overrides
988
989
990def BuildSpecific(env, mode, env_overrides):
991 options = {'mode': mode}
992 for option in SIMPLE_OPTIONS:
993 options[option] = env[option]
Steve Block6ded16b2010-05-10 14:33:55 +0100994 PostprocessOptions(options, env['os'])
Steve Blocka7e24c12009-10-30 11:49:00 +0000995
996 context = BuildContext(options, env_overrides, samples=SplitList(env['sample']))
997
998 # Remove variables which can't be imported from the user's external
999 # environment into a construction environment.
1000 user_environ = os.environ.copy()
1001 try:
1002 del user_environ['ENV']
1003 except KeyError:
1004 pass
1005
1006 library_flags = context.AddRelevantFlags(user_environ, LIBRARY_FLAGS)
1007 v8_flags = context.AddRelevantFlags(library_flags, V8_EXTRA_FLAGS)
1008 mksnapshot_flags = context.AddRelevantFlags(library_flags, MKSNAPSHOT_EXTRA_FLAGS)
1009 dtoa_flags = context.AddRelevantFlags(library_flags, DTOA_EXTRA_FLAGS)
1010 cctest_flags = context.AddRelevantFlags(v8_flags, CCTEST_EXTRA_FLAGS)
1011 sample_flags = context.AddRelevantFlags(user_environ, SAMPLE_FLAGS)
1012 d8_flags = context.AddRelevantFlags(library_flags, D8_FLAGS)
1013
1014 context.flags = {
1015 'v8': v8_flags,
1016 'mksnapshot': mksnapshot_flags,
1017 'dtoa': dtoa_flags,
1018 'cctest': cctest_flags,
1019 'sample': sample_flags,
1020 'd8': d8_flags
1021 }
1022
1023 # Generate library base name.
1024 target_id = mode
1025 suffix = SUFFIXES[target_id]
1026 library_name = 'v8' + suffix
1027 version = GetVersion()
1028 if context.options['soname'] == 'on':
1029 # When building shared object with SONAME version the library name.
1030 library_name += '-' + version
Steve Blocka7e24c12009-10-30 11:49:00 +00001031
1032 # Generate library SONAME if required by the build.
1033 if context.options['soname'] == 'on':
1034 soname = GetSpecificSONAME()
1035 if soname == '':
1036 soname = 'lib' + library_name + '.so'
1037 env['SONAME'] = soname
1038
1039 # Build the object files by invoking SCons recursively.
1040 (object_files, shell_files, mksnapshot) = env.SConscript(
1041 join('src', 'SConscript'),
1042 build_dir=join('obj', target_id),
1043 exports='context',
1044 duplicate=False
1045 )
1046
1047 context.mksnapshot_targets.append(mksnapshot)
1048
1049 # Link the object files into a library.
1050 env.Replace(**context.flags['v8'])
Leon Clarked91b9f72010-01-27 17:25:45 +00001051
Steve Blocka7e24c12009-10-30 11:49:00 +00001052 context.ApplyEnvOverrides(env)
1053 if context.options['library'] == 'static':
1054 library = env.StaticLibrary(library_name, object_files)
1055 else:
1056 # There seems to be a glitch in the way scons decides where to put
1057 # PDB files when compiling using MSVC so we specify it manually.
1058 # This should not affect any other platforms.
1059 pdb_name = library_name + '.dll.pdb'
1060 library = env.SharedLibrary(library_name, object_files, PDB=pdb_name)
1061 context.library_targets.append(library)
1062
1063 d8_env = Environment()
1064 d8_env.Replace(**context.flags['d8'])
Leon Clarkee46be812010-01-19 14:06:41 +00001065 context.ApplyEnvOverrides(d8_env)
Steve Blocka7e24c12009-10-30 11:49:00 +00001066 shell = d8_env.Program('d8' + suffix, object_files + shell_files)
1067 context.d8_targets.append(shell)
1068
1069 for sample in context.samples:
Steve Block6ded16b2010-05-10 14:33:55 +01001070 sample_env = Environment()
Steve Blocka7e24c12009-10-30 11:49:00 +00001071 sample_env.Replace(**context.flags['sample'])
Steve Block6ded16b2010-05-10 14:33:55 +01001072 sample_env.Prepend(LIBS=[library_name])
Steve Blocka7e24c12009-10-30 11:49:00 +00001073 context.ApplyEnvOverrides(sample_env)
1074 sample_object = sample_env.SConscript(
1075 join('samples', 'SConscript'),
1076 build_dir=join('obj', 'sample', sample, target_id),
1077 exports='sample context',
1078 duplicate=False
1079 )
1080 sample_name = sample + suffix
1081 sample_program = sample_env.Program(sample_name, sample_object)
1082 sample_env.Depends(sample_program, library)
1083 context.sample_targets.append(sample_program)
1084
Steve Block6ded16b2010-05-10 14:33:55 +01001085 cctest_env = env.Copy()
1086 cctest_env.Prepend(LIBS=[library_name])
1087 cctest_program = cctest_env.SConscript(
Steve Blocka7e24c12009-10-30 11:49:00 +00001088 join('test', 'cctest', 'SConscript'),
1089 build_dir=join('obj', 'test', target_id),
1090 exports='context object_files',
1091 duplicate=False
1092 )
1093 context.cctest_targets.append(cctest_program)
1094
1095 return context
1096
1097
1098def Build():
1099 opts = GetOptions()
1100 env = Environment(options=opts)
1101 Help(opts.GenerateHelpText(env))
1102 VerifyOptions(env)
1103 env_overrides = ParseEnvOverrides(env['env'], env['importenv'])
1104
1105 SourceSignatures(env['sourcesignatures'])
1106
1107 libraries = []
1108 mksnapshots = []
1109 cctests = []
1110 samples = []
1111 d8s = []
1112 modes = SplitList(env['mode'])
1113 for mode in modes:
1114 context = BuildSpecific(env.Copy(), mode, env_overrides)
1115 libraries += context.library_targets
1116 mksnapshots += context.mksnapshot_targets
1117 cctests += context.cctest_targets
1118 samples += context.sample_targets
1119 d8s += context.d8_targets
1120
1121 env.Alias('library', libraries)
1122 env.Alias('mksnapshot', mksnapshots)
1123 env.Alias('cctests', cctests)
1124 env.Alias('sample', samples)
1125 env.Alias('d8', d8s)
1126
1127 if env['sample']:
1128 env.Default('sample')
1129 else:
1130 env.Default('library')
1131
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001132 if env['cache']:
1133 CacheDir(env['cache'])
Steve Blocka7e24c12009-10-30 11:49:00 +00001134
1135# We disable deprecation warnings because we need to be able to use
1136# env.Copy without getting warnings for compatibility with older
1137# version of scons. Also, there's a bug in some revisions that
1138# doesn't allow this flag to be set, so we swallow any exceptions.
1139# Lovely.
1140try:
1141 SetOption('warn', 'no-deprecated')
1142except:
1143 pass
1144
1145
1146Build()