SConstruct revision 3584:8c3cdb2c001c
12600SN/A# -*- mode:python -*-
22600SN/A
32600SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
42600SN/A# All rights reserved.
52600SN/A#
62600SN/A# Redistribution and use in source and binary forms, with or without
72600SN/A# modification, are permitted provided that the following conditions are
82600SN/A# met: redistributions of source code must retain the above copyright
92600SN/A# notice, this list of conditions and the following disclaimer;
102600SN/A# redistributions in binary form must reproduce the above copyright
112600SN/A# notice, this list of conditions and the following disclaimer in the
122600SN/A# documentation and/or other materials provided with the distribution;
132600SN/A# neither the name of the copyright holders nor the names of its
142600SN/A# contributors may be used to endorse or promote products derived from
152600SN/A# this software without specific prior written permission.
162600SN/A#
172600SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182600SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192600SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202600SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212600SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222600SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232600SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242600SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252600SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262600SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292600SN/A# Authors: Steve Reinhardt
302600SN/A
312600SN/A###################################################
322600SN/A#
332600SN/A# SCons top-level build description (SConstruct) file.
342600SN/A#
352600SN/A# While in this directory ('m5'), just type 'scons' to build the default
362600SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
372600SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
382600SN/A# the optimized full-system version).
392600SN/A#
402600SN/A# You can build M5 in a different directory as long as there is a
413113Sgblack@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
422600SN/A# expects that all configs under the same build directory are being
433113Sgblack@eecs.umich.edu# built for the same host system.
442600SN/A#
452600SN/A# Examples:
462600SN/A#
472600SN/A#   The following two commands are equivalent.  The '-u' option tells
482600SN/A#   scons to search up the directory tree for this SConstruct file.
492600SN/A#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
502600SN/A#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512600SN/A#
523113Sgblack@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
533113Sgblack@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
542600SN/A#   scons to chdir to the specified directory to find this SConstruct
552600SN/A#   file.
562600SN/A#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
572600SN/A#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
582600SN/A#
593122Sgblack@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
602600SN/A# 'm5' directory (or use -u or -C to tell scons where to find this
612600SN/A# file), you can use 'scons -h' to print all the M5-specific build
622600SN/A# options as well.
632600SN/A#
642600SN/A###################################################
652600SN/A
662600SN/A# Python library imports
672600SN/Aimport sys
683122Sgblack@eecs.umich.eduimport os
692600SN/A
702600SN/A# Check for recent-enough Python and SCons versions.  If your system's
712600SN/A# default installation of Python is not recent enough, you can use a
722600SN/A# non-default installation of the Python interpreter by either (1)
732600SN/A# rearranging your PATH so that scons finds the non-default 'python'
742600SN/A# first or (2) explicitly invoking an alternative interpreter on the
752600SN/A# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
762600SN/AEnsurePythonVersion(2,4)
772600SN/A
783113Sgblack@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
795543Ssaidi@eecs.umich.edu# 3-element version number.
805543Ssaidi@eecs.umich.edumin_scons_version = (0,96,91)
815543Ssaidi@eecs.umich.edutry:
825543Ssaidi@eecs.umich.edu    EnsureSConsVersion(*min_scons_version)
835543Ssaidi@eecs.umich.eduexcept:
845543Ssaidi@eecs.umich.edu    print "Error checking current SCons version."
855543Ssaidi@eecs.umich.edu    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
865543Ssaidi@eecs.umich.edu    Exit(2)
875543Ssaidi@eecs.umich.edu    
885543Ssaidi@eecs.umich.edu
895543Ssaidi@eecs.umich.edu# The absolute path to the current directory (where this file lives).
903113Sgblack@eecs.umich.eduROOT = Dir('.').abspath
915543Ssaidi@eecs.umich.edu
925543Ssaidi@eecs.umich.edu# Paths to the M5 and external source trees.
932600SN/ASRCDIR = os.path.join(ROOT, 'src')
943113Sgblack@eecs.umich.edu
952600SN/A# tell python where to find m5 python code
962600SN/Asys.path.append(os.path.join(ROOT, 'src/python'))
973113Sgblack@eecs.umich.edu
985543Ssaidi@eecs.umich.edu###################################################
995543Ssaidi@eecs.umich.edu#
1005543Ssaidi@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
1015543Ssaidi@eecs.umich.edu# the target(s).
1025543Ssaidi@eecs.umich.edu#
1035543Ssaidi@eecs.umich.edu###################################################
1045543Ssaidi@eecs.umich.edu
1055543Ssaidi@eecs.umich.edu# Find default configuration & binary.
1065543Ssaidi@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1075543Ssaidi@eecs.umich.edu
1085543Ssaidi@eecs.umich.edu# Ask SCons which directory it was invoked from.
1093113Sgblack@eecs.umich.edulaunch_dir = GetLaunchDir()
1105543Ssaidi@eecs.umich.edu
1115543Ssaidi@eecs.umich.edu# Make targets relative to invocation directory
1122600SN/Aabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1133113Sgblack@eecs.umich.edu                  BUILD_TARGETS)
1142600SN/A
1152600SN/A# helper function: find last occurrence of element in list
1162600SN/Adef rfind(l, elt, offs = -1):
1172600SN/A    for i in range(len(l)+offs, 0, -1):
1182600SN/A        if l[i] == elt:
1193113Sgblack@eecs.umich.edu            return i
1205543Ssaidi@eecs.umich.edu    raise ValueError, "element not found"
1215543Ssaidi@eecs.umich.edu
1225543Ssaidi@eecs.umich.edu# helper function: compare dotted version numbers.
1235543Ssaidi@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1')
1245543Ssaidi@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2
1253113Sgblack@eecs.umich.edudef compare_versions(v1, v2):
1262600SN/A    # Convert dotted strings to lists
1272600SN/A    v1 = map(int, v1.split('.'))
1282600SN/A    v2 = map(int, v2.split('.'))
1292600SN/A    # Compare corresponding elements of lists
1302600SN/A    for n1,n2 in zip(v1, v2):
1312600SN/A        if n1 < n2: return -1
1322600SN/A        if n1 > n2: return  1
133    # all corresponding values are equal... see if one has extra values
134    if len(v1) < len(v2): return -1
135    if len(v1) > len(v2): return  1
136    return 0
137
138# Each target must have 'build' in the interior of the path; the
139# directory below this will determine the build parameters.  For
140# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
141# recognize that ALPHA_SE specifies the configuration because it
142# follow 'build' in the bulid path.
143
144# Generate a list of the unique build roots and configs that the
145# collected targets reference.
146build_paths = []
147build_root = None
148for t in abs_targets:
149    path_dirs = t.split('/')
150    try:
151        build_top = rfind(path_dirs, 'build', -2)
152    except:
153        print "Error: no non-leaf 'build' dir found on target path", t
154        Exit(1)
155    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
156    if not build_root:
157        build_root = this_build_root
158    else:
159        if this_build_root != build_root:
160            print "Error: build targets not under same build root\n"\
161                  "  %s\n  %s" % (build_root, this_build_root)
162            Exit(1)
163    build_path = os.path.join('/',*path_dirs[:build_top+2])
164    if build_path not in build_paths:
165        build_paths.append(build_path)
166
167###################################################
168#
169# Set up the default build environment.  This environment is copied
170# and modified according to each selected configuration.
171#
172###################################################
173
174env = Environment(ENV = os.environ,  # inherit user's environment vars
175                  ROOT = ROOT,
176                  SRCDIR = SRCDIR)
177
178env.SConsignFile(os.path.join(build_root,"sconsign"))
179
180# Default duplicate option is to use hard links, but this messes up
181# when you use emacs to edit a file in the target dir, as emacs moves
182# file to file~ then copies to file, breaking the link.  Symbolic
183# (soft) links work better.
184env.SetOption('duplicate', 'soft-copy')
185
186# I waffle on this setting... it does avoid a few painful but
187# unnecessary builds, but it also seems to make trivial builds take
188# noticeably longer.
189if False:
190    env.TargetSignatures('content')
191
192# M5_PLY is used by isa_parser.py to find the PLY package.
193env.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
194
195# Set up default C++ compiler flags
196env.Append(CCFLAGS='-pipe')
197env.Append(CCFLAGS='-fno-strict-aliasing')
198env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
199if sys.platform == 'cygwin':
200    # cygwin has some header file issues...
201    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
202env.Append(CPPPATH=[Dir('ext/dnet')])
203
204# Check for SWIG
205if not env.has_key('SWIG'):
206    print 'Error: SWIG utility not found.'
207    print '       Please install (see http://www.swig.org) and retry.'
208    Exit(1)
209
210# Check for appropriate SWIG version
211swig_version = os.popen('swig -version').read().split()
212# First 3 words should be "SWIG Version x.y.z"
213if swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
214    print 'Error determining SWIG version.'
215    Exit(1)
216
217min_swig_version = '1.3.28'
218if compare_versions(swig_version[2], min_swig_version) < 0:
219    print 'Error: SWIG version', min_swig_version, 'or newer required.'
220    print '       Installed version:', swig_version[2]
221    Exit(1)
222
223# Set up SWIG flags & scanner
224env.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
225
226import SCons.Scanner
227
228swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
229
230swig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
231                                        swig_inc_re)
232
233env.Append(SCANNERS = swig_scanner)
234
235# Platform-specific configuration.  Note again that we assume that all
236# builds under a given build root run on the same host platform.
237conf = Configure(env,
238                 conf_dir = os.path.join(build_root, '.scons_config'),
239                 log_file = os.path.join(build_root, 'scons_config.log'))
240
241# Find Python include and library directories for embedding the
242# interpreter.  For consistency, we will use the same Python
243# installation used to run scons (and thus this script).  If you want
244# to link in an alternate version, see above for instructions on how
245# to invoke scons with a different copy of the Python interpreter.
246
247# Get brief Python version name (e.g., "python2.4") for locating
248# include & library files
249py_version_name = 'python' + sys.version[:3]
250
251# include path, e.g. /usr/local/include/python2.4
252py_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name)
253env.Append(CPPPATH = py_header_path)
254# verify that it works
255if not conf.CheckHeader('Python.h', '<>'):
256    print "Error: can't find Python.h header in", py_header_path
257    Exit(1)
258
259# add library path too if it's not in the default place
260py_lib_path = None
261if sys.exec_prefix != '/usr':
262    py_lib_path = os.path.join(sys.exec_prefix, 'lib')
263elif sys.platform == 'cygwin':
264    # cygwin puts the .dll in /bin for some reason
265    py_lib_path = '/bin'
266if py_lib_path:
267    env.Append(LIBPATH = py_lib_path)
268    print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
269if not conf.CheckLib(py_version_name):
270    print "Error: can't find Python library", py_version_name
271    Exit(1)
272
273# On Solaris you need to use libsocket for socket ops
274if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
275   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
276       print "Can't find library with socket calls (e.g. accept())"
277       Exit(1)
278
279# Check for zlib.  If the check passes, libz will be automatically
280# added to the LIBS environment variable.
281if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'):
282    print 'Error: did not find needed zlib compression library '\
283          'and/or zlib.h header file.'
284    print '       Please install zlib and try again.'
285    Exit(1)
286
287# Check for <fenv.h> (C99 FP environment control)
288have_fenv = conf.CheckHeader('fenv.h', '<>')
289if not have_fenv:
290    print "Warning: Header file <fenv.h> not found."
291    print "         This host has no IEEE FP rounding mode control."
292
293# Check for mysql.
294mysql_config = WhereIs('mysql_config')
295have_mysql = mysql_config != None
296
297# Check MySQL version.
298if have_mysql:
299    mysql_version = os.popen(mysql_config + ' --version').read()
300    min_mysql_version = '4.1'
301    if compare_versions(mysql_version, min_mysql_version) < 0:
302        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
303        print '         Version', mysql_version, 'detected.'
304        have_mysql = False
305
306# Set up mysql_config commands.
307if have_mysql:
308    mysql_config_include = mysql_config + ' --include'
309    if os.system(mysql_config_include + ' > /dev/null') != 0:
310        # older mysql_config versions don't support --include, use
311        # --cflags instead
312        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
313    # This seems to work in all versions
314    mysql_config_libs = mysql_config + ' --libs'
315
316env = conf.Finish()
317
318# Define the universe of supported ISAs
319env['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
320
321# Define the universe of supported CPU models
322env['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
323                       'O3CPU', 'OzoneCPU']
324
325if os.path.isdir(os.path.join(SRCDIR, 'src/encumbered/cpu/full')):
326    env['ALL_CPU_LIST'] += ['FullCPU']
327
328# Sticky options get saved in the options file so they persist from
329# one invocation to the next (unless overridden, in which case the new
330# value becomes sticky).
331sticky_opts = Options(args=ARGUMENTS)
332sticky_opts.AddOptions(
333    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
334    BoolOption('FULL_SYSTEM', 'Full-system support', False),
335    # There's a bug in scons 0.96.1 that causes ListOptions with list
336    # values (more than one value) not to be able to be restored from
337    # a saved option file.  If this causes trouble then upgrade to
338    # scons 0.96.90 or later.
339    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
340               env['ALL_CPU_LIST']),
341    BoolOption('ALPHA_TLASER',
342               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
343    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
344    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
345               False),
346    BoolOption('SS_COMPATIBLE_FP',
347               'Make floating-point results compatible with SimpleScalar',
348               False),
349    BoolOption('USE_SSE2',
350               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
351               False),
352    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
353    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
354    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
355    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
356    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
357    BoolOption('BATCH', 'Use batch pool for build and tests', False),
358    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
359    ('PYTHONHOME',
360     'Override the default PYTHONHOME for this system (use with caution)',
361     '%s:%s' % (sys.prefix, sys.exec_prefix))
362    )
363
364# Non-sticky options only apply to the current build.
365nonsticky_opts = Options(args=ARGUMENTS)
366nonsticky_opts.AddOptions(
367    BoolOption('update_ref', 'Update test reference outputs', False)
368    )
369
370# These options get exported to #defines in config/*.hh (see src/SConscript).
371env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
372                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
373                     'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
374
375# Define a handy 'no-op' action
376def no_action(target, source, env):
377    return 0
378
379env.NoAction = Action(no_action, None)
380
381###################################################
382#
383# Define a SCons builder for configuration flag headers.
384#
385###################################################
386
387# This function generates a config header file that #defines the
388# option symbol to the current option setting (0 or 1).  The source
389# operands are the name of the option and a Value node containing the
390# value of the option.
391def build_config_file(target, source, env):
392    (option, value) = [s.get_contents() for s in source]
393    f = file(str(target[0]), 'w')
394    print >> f, '#define', option, value
395    f.close()
396    return None
397
398# Generate the message to be printed when building the config file.
399def build_config_file_string(target, source, env):
400    (option, value) = [s.get_contents() for s in source]
401    return "Defining %s as %s in %s." % (option, value, target[0])
402
403# Combine the two functions into a scons Action object.
404config_action = Action(build_config_file, build_config_file_string)
405
406# The emitter munges the source & target node lists to reflect what
407# we're really doing.
408def config_emitter(target, source, env):
409    # extract option name from Builder arg
410    option = str(target[0])
411    # True target is config header file
412    target = os.path.join('config', option.lower() + '.hh')
413    val = env[option]
414    if isinstance(val, bool):
415        # Force value to 0/1
416        val = int(val)
417    elif isinstance(val, str):
418        val = '"' + val + '"'
419        
420    # Sources are option name & value (packaged in SCons Value nodes)
421    return ([target], [Value(option), Value(val)])
422
423config_builder = Builder(emitter = config_emitter, action = config_action)
424
425env.Append(BUILDERS = { 'ConfigFile' : config_builder })
426
427###################################################
428#
429# Define a SCons builder for copying files.  This is used by the
430# Python zipfile code in src/python/SConscript, but is placed up here
431# since it's potentially more generally applicable.
432#
433###################################################
434
435copy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
436
437env.Append(BUILDERS = { 'CopyFile' : copy_builder })
438
439###################################################
440#
441# Define a simple SCons builder to concatenate files.
442#
443# Used to append the Python zip archive to the executable.
444#
445###################################################
446
447concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
448                                          'chmod +x $TARGET']))
449
450env.Append(BUILDERS = { 'Concat' : concat_builder })
451
452
453# base help text
454help_text = '''
455Usage: scons [scons options] [build options] [target(s)]
456
457'''
458
459# libelf build is shared across all configs in the build root.
460env.SConscript('ext/libelf/SConscript',
461               build_dir = os.path.join(build_root, 'libelf'),
462               exports = 'env')
463
464###################################################
465#
466# This function is used to set up a directory with switching headers
467#
468###################################################
469
470def make_switching_dir(dirname, switch_headers, env):
471    # Generate the header.  target[0] is the full path of the output
472    # header to generate.  'source' is a dummy variable, since we get the
473    # list of ISAs from env['ALL_ISA_LIST'].
474    def gen_switch_hdr(target, source, env):
475	fname = str(target[0])
476	basename = os.path.basename(fname)
477	f = open(fname, 'w')
478	f.write('#include "arch/isa_specific.hh"\n')
479	cond = '#if'
480	for isa in env['ALL_ISA_LIST']:
481	    f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
482		    % (cond, isa.upper(), dirname, isa, basename))
483	    cond = '#elif'
484	f.write('#else\n#error "THE_ISA not set"\n#endif\n')
485	f.close()
486	return 0
487
488    # String to print when generating header
489    def gen_switch_hdr_string(target, source, env):
490	return "Generating switch header " + str(target[0])
491
492    # Build SCons Action object. 'varlist' specifies env vars that this
493    # action depends on; when env['ALL_ISA_LIST'] changes these actions
494    # should get re-executed.
495    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
496                               varlist=['ALL_ISA_LIST'])
497
498    # Instantiate actions for each header
499    for hdr in switch_headers:
500        env.Command(hdr, [], switch_hdr_action)
501
502env.make_switching_dir = make_switching_dir
503
504###################################################
505#
506# Define build environments for selected configurations.
507#
508###################################################
509
510# rename base env
511base_env = env
512
513for build_path in build_paths:
514    print "Building in", build_path
515    # build_dir is the tail component of build path, and is used to
516    # determine the build parameters (e.g., 'ALPHA_SE')
517    (build_root, build_dir) = os.path.split(build_path)
518    # Make a copy of the build-root environment to use for this config.
519    env = base_env.Copy()
520
521    # Set env options according to the build directory config.
522    sticky_opts.files = []
523    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
524    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
525    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
526    current_opts_file = os.path.join(build_root, 'options', build_dir)
527    if os.path.isfile(current_opts_file):
528        sticky_opts.files.append(current_opts_file)
529        print "Using saved options file %s" % current_opts_file
530    else:
531        # Build dir-specific options file doesn't exist.
532
533        # Make sure the directory is there so we can create it later
534        opt_dir = os.path.dirname(current_opts_file)
535        if not os.path.isdir(opt_dir):
536            os.mkdir(opt_dir)
537
538        # Get default build options from source tree.  Options are
539        # normally determined by name of $BUILD_DIR, but can be
540        # overriden by 'default=' arg on command line.
541        default_opts_file = os.path.join('build_opts',
542                                         ARGUMENTS.get('default', build_dir))
543        if os.path.isfile(default_opts_file):
544            sticky_opts.files.append(default_opts_file)
545            print "Options file %s not found,\n  using defaults in %s" \
546                  % (current_opts_file, default_opts_file)
547        else:
548            print "Error: cannot find options file %s or %s" \
549                  % (current_opts_file, default_opts_file)
550            Exit(1)
551
552    # Apply current option settings to env
553    sticky_opts.Update(env)
554    nonsticky_opts.Update(env)
555
556    help_text += "Sticky options for %s:\n" % build_dir \
557                 + sticky_opts.GenerateHelpText(env) \
558                 + "\nNon-sticky options for %s:\n" % build_dir \
559                 + nonsticky_opts.GenerateHelpText(env)
560
561    # Process option settings.
562
563    if not have_fenv and env['USE_FENV']:
564        print "Warning: <fenv.h> not available; " \
565              "forcing USE_FENV to False in", build_dir + "."
566        env['USE_FENV'] = False
567
568    if not env['USE_FENV']:
569        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
570        print "         FP results may deviate slightly from other platforms."
571
572    if env['EFENCE']:
573        env.Append(LIBS=['efence'])
574
575    if env['USE_MYSQL']:
576        if not have_mysql:
577            print "Warning: MySQL not available; " \
578                  "forcing USE_MYSQL to False in", build_dir + "."
579            env['USE_MYSQL'] = False
580        else:
581            print "Compiling in", build_dir, "with MySQL support."
582            env.ParseConfig(mysql_config_libs)
583            env.ParseConfig(mysql_config_include)
584
585    # Save sticky option settings back to current options file
586    sticky_opts.Save(current_opts_file, env)
587
588    # Do this after we save setting back, or else we'll tack on an
589    # extra 'qdo' every time we run scons.
590    if env['BATCH']:
591        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
592        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
593
594    if env['USE_SSE2']:
595        env.Append(CCFLAGS='-msse2')
596
597    # The src/SConscript file sets up the build rules in 'env' according
598    # to the configured options.  It returns a list of environments,
599    # one for each variant build (debug, opt, etc.)
600    envList = SConscript('src/SConscript', build_dir = build_path,
601                         exports = 'env')
602
603    # Set up the regression tests for each build.
604    for e in envList:
605        SConscript('tests/SConscript',
606                   build_dir = os.path.join(build_path, 'tests', e.Label),
607                   exports = { 'env' : e }, duplicate = False)
608
609Help(help_text)
610
611
612###################################################
613#
614# Let SCons do its thing.  At this point SCons will use the defined
615# build environments to build the requested targets.
616#
617###################################################
618
619