fix console printing bug
[gem5.git] / SConstruct
1 # -*- mode:python -*-
2
3 # Copyright (c) 2004-2005 The Regents of The University of Michigan
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met: redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer;
10 # redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution;
13 # neither the name of the copyright holders nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #
29 # Authors: Steve Reinhardt
30
31 ###################################################
32 #
33 # SCons top-level build description (SConstruct) file.
34 #
35 # While in this directory ('m5'), just type 'scons' to build the default
36 # configuration (see below), or type 'scons build/<CONFIG>/<binary>'
37 # to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
38 # the optimized full-system version).
39 #
40 # You can build M5 in a different directory as long as there is a
41 # 'build/<CONFIG>' somewhere along the target path. The build system
42 # expects that all configs under the same build directory are being
43 # built for the same host system.
44 #
45 # Examples:
46 #
47 # The following two commands are equivalent. The '-u' option tells
48 # scons to search up the directory tree for this SConstruct file.
49 # % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
50 # % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
51 #
52 # The following two commands are equivalent and demonstrate building
53 # in a directory outside of the source tree. The '-C' option tells
54 # scons to chdir to the specified directory to find this SConstruct
55 # file.
56 # % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
57 # % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
58 #
59 # You can use 'scons -H' to print scons options. If you're in this
60 # 'm5' directory (or use -u or -C to tell scons where to find this
61 # file), you can use 'scons -h' to print all the M5-specific build
62 # options as well.
63 #
64 ###################################################
65
66 import sys
67 import os
68 import subprocess
69
70 from os.path import join as joinpath
71
72 # Check for recent-enough Python and SCons versions. If your system's
73 # default installation of Python is not recent enough, you can use a
74 # non-default installation of the Python interpreter by either (1)
75 # rearranging your PATH so that scons finds the non-default 'python'
76 # first or (2) explicitly invoking an alternative interpreter on the
77 # scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
78 EnsurePythonVersion(2,4)
79
80 # Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
81 # 3-element version number.
82 min_scons_version = (0,96,91)
83 try:
84 EnsureSConsVersion(*min_scons_version)
85 except:
86 print "Error checking current SCons version."
87 print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
88 Exit(2)
89
90
91 # The absolute path to the current directory (where this file lives).
92 ROOT = Dir('.').abspath
93
94 # Path to the M5 source tree.
95 SRCDIR = joinpath(ROOT, 'src')
96
97 # tell python where to find m5 python code
98 sys.path.append(joinpath(ROOT, 'src/python'))
99
100 ###################################################
101 #
102 # Figure out which configurations to set up based on the path(s) of
103 # the target(s).
104 #
105 ###################################################
106
107 # Find default configuration & binary.
108 Default(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
109
110 # helper function: find last occurrence of element in list
111 def rfind(l, elt, offs = -1):
112 for i in range(len(l)+offs, 0, -1):
113 if l[i] == elt:
114 return i
115 raise ValueError, "element not found"
116
117 # helper function: compare dotted version numbers.
118 # E.g., compare_version('1.3.25', '1.4.1')
119 # returns -1, 0, 1 if v1 is <, ==, > v2
120 def compare_versions(v1, v2):
121 # Convert dotted strings to lists
122 v1 = map(int, v1.split('.'))
123 v2 = map(int, v2.split('.'))
124 # Compare corresponding elements of lists
125 for n1,n2 in zip(v1, v2):
126 if n1 < n2: return -1
127 if n1 > n2: return 1
128 # all corresponding values are equal... see if one has extra values
129 if len(v1) < len(v2): return -1
130 if len(v1) > len(v2): return 1
131 return 0
132
133 # Each target must have 'build' in the interior of the path; the
134 # directory below this will determine the build parameters. For
135 # example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
136 # recognize that ALPHA_SE specifies the configuration because it
137 # follow 'build' in the bulid path.
138
139 # Generate absolute paths to targets so we can see where the build dir is
140 if COMMAND_LINE_TARGETS:
141 # Ask SCons which directory it was invoked from
142 launch_dir = GetLaunchDir()
143 # Make targets relative to invocation directory
144 abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))),
145 COMMAND_LINE_TARGETS)
146 else:
147 # Default targets are relative to root of tree
148 abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))),
149 DEFAULT_TARGETS)
150
151
152 # Generate a list of the unique build roots and configs that the
153 # collected targets reference.
154 build_paths = []
155 build_root = None
156 for t in abs_targets:
157 path_dirs = t.split('/')
158 try:
159 build_top = rfind(path_dirs, 'build', -2)
160 except:
161 print "Error: no non-leaf 'build' dir found on target path", t
162 Exit(1)
163 this_build_root = joinpath('/',*path_dirs[:build_top+1])
164 if not build_root:
165 build_root = this_build_root
166 else:
167 if this_build_root != build_root:
168 print "Error: build targets not under same build root\n"\
169 " %s\n %s" % (build_root, this_build_root)
170 Exit(1)
171 build_path = joinpath('/',*path_dirs[:build_top+2])
172 if build_path not in build_paths:
173 build_paths.append(build_path)
174
175 ###################################################
176 #
177 # Set up the default build environment. This environment is copied
178 # and modified according to each selected configuration.
179 #
180 ###################################################
181
182 env = Environment(ENV = os.environ, # inherit user's environment vars
183 ROOT = ROOT,
184 SRCDIR = SRCDIR)
185 Export('env')
186
187 #Parse CC/CXX early so that we use the correct compiler for
188 # to test for dependencies/versions/libraries/includes
189 if ARGUMENTS.get('CC', None):
190 env['CC'] = ARGUMENTS.get('CC')
191
192 if ARGUMENTS.get('CXX', None):
193 env['CXX'] = ARGUMENTS.get('CXX')
194
195 env.SConsignFile(joinpath(build_root,"sconsign"))
196
197 # Default duplicate option is to use hard links, but this messes up
198 # when you use emacs to edit a file in the target dir, as emacs moves
199 # file to file~ then copies to file, breaking the link. Symbolic
200 # (soft) links work better.
201 env.SetOption('duplicate', 'soft-copy')
202
203 # I waffle on this setting... it does avoid a few painful but
204 # unnecessary builds, but it also seems to make trivial builds take
205 # noticeably longer.
206 if False:
207 env.TargetSignatures('content')
208
209 # M5_PLY is used by isa_parser.py to find the PLY package.
210 env.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
211 env['GCC'] = False
212 env['SUNCC'] = False
213 env['ICC'] = False
214 env['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True,
215 stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
216 close_fds=True).communicate()[0].find('GCC') >= 0
217 env['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
218 stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
219 close_fds=True).communicate()[0].find('Sun C++') >= 0
220 env['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
221 stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
222 close_fds=True).communicate()[0].find('Intel') >= 0
223 if env['GCC'] + env['SUNCC'] + env['ICC'] > 1:
224 print 'Error: How can we have two at the same time?'
225 Exit(1)
226
227
228 # Set up default C++ compiler flags
229 if env['GCC']:
230 env.Append(CCFLAGS='-pipe')
231 env.Append(CCFLAGS='-fno-strict-aliasing')
232 env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
233 elif env['ICC']:
234 pass #Fix me... add warning flags once we clean up icc warnings
235 elif env['SUNCC']:
236 env.Append(CCFLAGS='-Qoption ccfe')
237 env.Append(CCFLAGS='-features=gcc')
238 env.Append(CCFLAGS='-features=extensions')
239 env.Append(CCFLAGS='-library=stlport4')
240 env.Append(CCFLAGS='-xar')
241 # env.Append(CCFLAGS='-instances=semiexplicit')
242 else:
243 print 'Error: Don\'t know what compiler options to use for your compiler.'
244 print ' Please fix SConstruct and src/SConscript and try again.'
245 Exit(1)
246
247 if sys.platform == 'cygwin':
248 # cygwin has some header file issues...
249 env.Append(CCFLAGS=Split("-Wno-uninitialized"))
250 env.Append(CPPPATH=[Dir('ext/dnet')])
251
252 # Check for SWIG
253 if not env.has_key('SWIG'):
254 print 'Error: SWIG utility not found.'
255 print ' Please install (see http://www.swig.org) and retry.'
256 Exit(1)
257
258 # Check for appropriate SWIG version
259 swig_version = os.popen('swig -version').read().split()
260 # First 3 words should be "SWIG Version x.y.z"
261 if swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
262 print 'Error determining SWIG version.'
263 Exit(1)
264
265 min_swig_version = '1.3.28'
266 if compare_versions(swig_version[2], min_swig_version) < 0:
267 print 'Error: SWIG version', min_swig_version, 'or newer required.'
268 print ' Installed version:', swig_version[2]
269 Exit(1)
270
271 # Set up SWIG flags & scanner
272 env.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
273
274 import SCons.Scanner
275
276 swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
277
278 swig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
279 swig_inc_re)
280
281 env.Append(SCANNERS = swig_scanner)
282
283 # Platform-specific configuration. Note again that we assume that all
284 # builds under a given build root run on the same host platform.
285 conf = Configure(env,
286 conf_dir = joinpath(build_root, '.scons_config'),
287 log_file = joinpath(build_root, 'scons_config.log'))
288
289 # Find Python include and library directories for embedding the
290 # interpreter. For consistency, we will use the same Python
291 # installation used to run scons (and thus this script). If you want
292 # to link in an alternate version, see above for instructions on how
293 # to invoke scons with a different copy of the Python interpreter.
294
295 # Get brief Python version name (e.g., "python2.4") for locating
296 # include & library files
297 py_version_name = 'python' + sys.version[:3]
298
299 # include path, e.g. /usr/local/include/python2.4
300 py_header_path = joinpath(sys.exec_prefix, 'include', py_version_name)
301 env.Append(CPPPATH = py_header_path)
302 # verify that it works
303 if not conf.CheckHeader('Python.h', '<>'):
304 print "Error: can't find Python.h header in", py_header_path
305 Exit(1)
306
307 # add library path too if it's not in the default place
308 py_lib_path = None
309 if sys.exec_prefix != '/usr':
310 py_lib_path = joinpath(sys.exec_prefix, 'lib')
311 elif sys.platform == 'cygwin':
312 # cygwin puts the .dll in /bin for some reason
313 py_lib_path = '/bin'
314 if py_lib_path:
315 env.Append(LIBPATH = py_lib_path)
316 print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
317 if not conf.CheckLib(py_version_name):
318 print "Error: can't find Python library", py_version_name
319 Exit(1)
320
321 # On Solaris you need to use libsocket for socket ops
322 if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
323 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
324 print "Can't find library with socket calls (e.g. accept())"
325 Exit(1)
326
327 # Check for zlib. If the check passes, libz will be automatically
328 # added to the LIBS environment variable.
329 if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
330 print 'Error: did not find needed zlib compression library '\
331 'and/or zlib.h header file.'
332 print ' Please install zlib and try again.'
333 Exit(1)
334
335 # Check for <fenv.h> (C99 FP environment control)
336 have_fenv = conf.CheckHeader('fenv.h', '<>')
337 if not have_fenv:
338 print "Warning: Header file <fenv.h> not found."
339 print " This host has no IEEE FP rounding mode control."
340
341 # Check for mysql.
342 mysql_config = WhereIs('mysql_config')
343 have_mysql = mysql_config != None
344
345 # Check MySQL version.
346 if have_mysql:
347 mysql_version = os.popen(mysql_config + ' --version').read()
348 min_mysql_version = '4.1'
349 if compare_versions(mysql_version, min_mysql_version) < 0:
350 print 'Warning: MySQL', min_mysql_version, 'or newer required.'
351 print ' Version', mysql_version, 'detected.'
352 have_mysql = False
353
354 # Set up mysql_config commands.
355 if have_mysql:
356 mysql_config_include = mysql_config + ' --include'
357 if os.system(mysql_config_include + ' > /dev/null') != 0:
358 # older mysql_config versions don't support --include, use
359 # --cflags instead
360 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
361 # This seems to work in all versions
362 mysql_config_libs = mysql_config + ' --libs'
363
364 env = conf.Finish()
365
366 # Define the universe of supported ISAs
367 all_isa_list = [ ]
368 Export('all_isa_list')
369
370 # Define the universe of supported CPU models
371 all_cpu_list = [ ]
372 default_cpus = [ ]
373 Export('all_cpu_list', 'default_cpus')
374
375 # Sticky options get saved in the options file so they persist from
376 # one invocation to the next (unless overridden, in which case the new
377 # value becomes sticky).
378 sticky_opts = Options(args=ARGUMENTS)
379 Export('sticky_opts')
380
381 # Non-sticky options only apply to the current build.
382 nonsticky_opts = Options(args=ARGUMENTS)
383 Export('nonsticky_opts')
384
385 # Walk the tree and execute all SConsopts scripts that wil add to the
386 # above options
387 for root, dirs, files in os.walk('.'):
388 if 'SConsopts' in files:
389 SConscript(os.path.join(root, 'SConsopts'))
390
391 all_isa_list.sort()
392 all_cpu_list.sort()
393 default_cpus.sort()
394
395 sticky_opts.AddOptions(
396 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
397 BoolOption('FULL_SYSTEM', 'Full-system support', False),
398 # There's a bug in scons 0.96.1 that causes ListOptions with list
399 # values (more than one value) not to be able to be restored from
400 # a saved option file. If this causes trouble then upgrade to
401 # scons 0.96.90 or later.
402 ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
403 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
404 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
405 False),
406 BoolOption('SS_COMPATIBLE_FP',
407 'Make floating-point results compatible with SimpleScalar',
408 False),
409 BoolOption('USE_SSE2',
410 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
411 False),
412 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
413 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
414 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
415 ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
416 ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
417 BoolOption('BATCH', 'Use batch pool for build and tests', False),
418 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
419 ('PYTHONHOME',
420 'Override the default PYTHONHOME for this system (use with caution)',
421 '%s:%s' % (sys.prefix, sys.exec_prefix))
422 )
423
424 nonsticky_opts.AddOptions(
425 BoolOption('update_ref', 'Update test reference outputs', False)
426 )
427
428 # These options get exported to #defines in config/*.hh (see src/SConscript).
429 env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
430 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
431 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
432
433 # Define a handy 'no-op' action
434 def no_action(target, source, env):
435 return 0
436
437 env.NoAction = Action(no_action, None)
438
439 ###################################################
440 #
441 # Define a SCons builder for configuration flag headers.
442 #
443 ###################################################
444
445 # This function generates a config header file that #defines the
446 # option symbol to the current option setting (0 or 1). The source
447 # operands are the name of the option and a Value node containing the
448 # value of the option.
449 def build_config_file(target, source, env):
450 (option, value) = [s.get_contents() for s in source]
451 f = file(str(target[0]), 'w')
452 print >> f, '#define', option, value
453 f.close()
454 return None
455
456 # Generate the message to be printed when building the config file.
457 def build_config_file_string(target, source, env):
458 (option, value) = [s.get_contents() for s in source]
459 return "Defining %s as %s in %s." % (option, value, target[0])
460
461 # Combine the two functions into a scons Action object.
462 config_action = Action(build_config_file, build_config_file_string)
463
464 # The emitter munges the source & target node lists to reflect what
465 # we're really doing.
466 def config_emitter(target, source, env):
467 # extract option name from Builder arg
468 option = str(target[0])
469 # True target is config header file
470 target = joinpath('config', option.lower() + '.hh')
471 val = env[option]
472 if isinstance(val, bool):
473 # Force value to 0/1
474 val = int(val)
475 elif isinstance(val, str):
476 val = '"' + val + '"'
477
478 # Sources are option name & value (packaged in SCons Value nodes)
479 return ([target], [Value(option), Value(val)])
480
481 config_builder = Builder(emitter = config_emitter, action = config_action)
482
483 env.Append(BUILDERS = { 'ConfigFile' : config_builder })
484
485 ###################################################
486 #
487 # Define a SCons builder for copying files. This is used by the
488 # Python zipfile code in src/python/SConscript, but is placed up here
489 # since it's potentially more generally applicable.
490 #
491 ###################################################
492
493 copy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
494
495 env.Append(BUILDERS = { 'CopyFile' : copy_builder })
496
497 ###################################################
498 #
499 # Define a simple SCons builder to concatenate files.
500 #
501 # Used to append the Python zip archive to the executable.
502 #
503 ###################################################
504
505 concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
506 'chmod +x $TARGET']))
507
508 env.Append(BUILDERS = { 'Concat' : concat_builder })
509
510
511 # base help text
512 help_text = '''
513 Usage: scons [scons options] [build options] [target(s)]
514
515 '''
516
517 # libelf build is shared across all configs in the build root.
518 env.SConscript('ext/libelf/SConscript',
519 build_dir = joinpath(build_root, 'libelf'),
520 exports = 'env')
521
522 ###################################################
523 #
524 # This function is used to set up a directory with switching headers
525 #
526 ###################################################
527
528 env['ALL_ISA_LIST'] = all_isa_list
529 def make_switching_dir(dirname, switch_headers, env):
530 # Generate the header. target[0] is the full path of the output
531 # header to generate. 'source' is a dummy variable, since we get the
532 # list of ISAs from env['ALL_ISA_LIST'].
533 def gen_switch_hdr(target, source, env):
534 fname = str(target[0])
535 basename = os.path.basename(fname)
536 f = open(fname, 'w')
537 f.write('#include "arch/isa_specific.hh"\n')
538 cond = '#if'
539 for isa in all_isa_list:
540 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
541 % (cond, isa.upper(), dirname, isa, basename))
542 cond = '#elif'
543 f.write('#else\n#error "THE_ISA not set"\n#endif\n')
544 f.close()
545 return 0
546
547 # String to print when generating header
548 def gen_switch_hdr_string(target, source, env):
549 return "Generating switch header " + str(target[0])
550
551 # Build SCons Action object. 'varlist' specifies env vars that this
552 # action depends on; when env['ALL_ISA_LIST'] changes these actions
553 # should get re-executed.
554 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
555 varlist=['ALL_ISA_LIST'])
556
557 # Instantiate actions for each header
558 for hdr in switch_headers:
559 env.Command(hdr, [], switch_hdr_action)
560 Export('make_switching_dir')
561
562 ###################################################
563 #
564 # Define build environments for selected configurations.
565 #
566 ###################################################
567
568 # rename base env
569 base_env = env
570
571 for build_path in build_paths:
572 print "Building in", build_path
573 # build_dir is the tail component of build path, and is used to
574 # determine the build parameters (e.g., 'ALPHA_SE')
575 (build_root, build_dir) = os.path.split(build_path)
576 # Make a copy of the build-root environment to use for this config.
577 env = base_env.Copy()
578
579 # Set env options according to the build directory config.
580 sticky_opts.files = []
581 # Options for $BUILD_ROOT/$BUILD_DIR are stored in
582 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
583 # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
584 current_opts_file = joinpath(build_root, 'options', build_dir)
585 if os.path.isfile(current_opts_file):
586 sticky_opts.files.append(current_opts_file)
587 print "Using saved options file %s" % current_opts_file
588 else:
589 # Build dir-specific options file doesn't exist.
590
591 # Make sure the directory is there so we can create it later
592 opt_dir = os.path.dirname(current_opts_file)
593 if not os.path.isdir(opt_dir):
594 os.mkdir(opt_dir)
595
596 # Get default build options from source tree. Options are
597 # normally determined by name of $BUILD_DIR, but can be
598 # overriden by 'default=' arg on command line.
599 default_opts_file = joinpath('build_opts',
600 ARGUMENTS.get('default', build_dir))
601 if os.path.isfile(default_opts_file):
602 sticky_opts.files.append(default_opts_file)
603 print "Options file %s not found,\n using defaults in %s" \
604 % (current_opts_file, default_opts_file)
605 else:
606 print "Error: cannot find options file %s or %s" \
607 % (current_opts_file, default_opts_file)
608 Exit(1)
609
610 # Apply current option settings to env
611 sticky_opts.Update(env)
612 nonsticky_opts.Update(env)
613
614 help_text += "Sticky options for %s:\n" % build_dir \
615 + sticky_opts.GenerateHelpText(env) \
616 + "\nNon-sticky options for %s:\n" % build_dir \
617 + nonsticky_opts.GenerateHelpText(env)
618
619 # Process option settings.
620
621 if not have_fenv and env['USE_FENV']:
622 print "Warning: <fenv.h> not available; " \
623 "forcing USE_FENV to False in", build_dir + "."
624 env['USE_FENV'] = False
625
626 if not env['USE_FENV']:
627 print "Warning: No IEEE FP rounding mode control in", build_dir + "."
628 print " FP results may deviate slightly from other platforms."
629
630 if env['EFENCE']:
631 env.Append(LIBS=['efence'])
632
633 if env['USE_MYSQL']:
634 if not have_mysql:
635 print "Warning: MySQL not available; " \
636 "forcing USE_MYSQL to False in", build_dir + "."
637 env['USE_MYSQL'] = False
638 else:
639 print "Compiling in", build_dir, "with MySQL support."
640 env.ParseConfig(mysql_config_libs)
641 env.ParseConfig(mysql_config_include)
642
643 # Save sticky option settings back to current options file
644 sticky_opts.Save(current_opts_file, env)
645
646 # Do this after we save setting back, or else we'll tack on an
647 # extra 'qdo' every time we run scons.
648 if env['BATCH']:
649 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC']
650 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
651
652 if env['USE_SSE2']:
653 env.Append(CCFLAGS='-msse2')
654
655 # The src/SConscript file sets up the build rules in 'env' according
656 # to the configured options. It returns a list of environments,
657 # one for each variant build (debug, opt, etc.)
658 envList = SConscript('src/SConscript', build_dir = build_path,
659 exports = 'env')
660
661 # Set up the regression tests for each build.
662 for e in envList:
663 SConscript('tests/SConscript',
664 build_dir = joinpath(build_path, 'tests', e.Label),
665 exports = { 'env' : e }, duplicate = False)
666
667 Help(help_text)
668
669
670 ###################################################
671 #
672 # Let SCons do its thing. At this point SCons will use the defined
673 # build environments to build the requested targets.
674 #
675 ###################################################
676