SConstruct revision 2665
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
4955SN/A# All rights reserved.
5955SN/A#
6955SN/A# Redistribution and use in source and binary forms, with or without
7955SN/A# modification, are permitted provided that the following conditions are
8955SN/A# met: redistributions of source code must retain the above copyright
9955SN/A# notice, this list of conditions and the following disclaimer;
10955SN/A# redistributions in binary form must reproduce the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer in the
12955SN/A# documentation and/or other materials provided with the distribution;
13955SN/A# neither the name of the copyright holders nor the names of its
14955SN/A# contributors may be used to endorse or promote products derived from
15955SN/A# this software without specific prior written permission.
16955SN/A#
17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
30955SN/A
31955SN/A###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
352632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default
362632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
372632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
382632Sstever@eecs.umich.edu# the optimized full-system version).
39955SN/A#
402632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a
412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
422632Sstever@eecs.umich.edu# expdects that all configs under the same build directory are being
432632Sstever@eecs.umich.edu# built for the same host system.
442632Sstever@eecs.umich.edu#
452632Sstever@eecs.umich.edu# Examples:
462632Sstever@eecs.umich.edu#   These two commands are equivalent.  The '-u' option tells scons to
472632Sstever@eecs.umich.edu#   search up the directory tree for this SConstruct file.
482632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
492632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
502632Sstever@eecs.umich.edu#   These two commands are equivalent and demonstrate building in a
512632Sstever@eecs.umich.edu#   directory outside of the source tree.  The '-C' option tells scons
522632Sstever@eecs.umich.edu#   to chdir to the specified directory to find this SConstruct file.
532632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
542632Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
552632Sstever@eecs.umich.edu#
562632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
572632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
582632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
592632Sstever@eecs.umich.edu# options as well.
60955SN/A#
61955SN/A###################################################
62955SN/A
63955SN/A# Python library imports
64955SN/Aimport sys
65955SN/Aimport os
66955SN/A
672656Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions.  If your system's
682656Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a
692656Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1)
702656Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python'
712656Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the
722656Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
732656Sstever@eecs.umich.eduEnsurePythonVersion(2,4)
742653Sstever@eecs.umich.edu
752653Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
762653Sstever@eecs.umich.edu# 3-element version number.
772653Sstever@eecs.umich.edumin_scons_version = (0,96,91)
782653Sstever@eecs.umich.edutry:
792653Sstever@eecs.umich.edu    EnsureSConsVersion(*min_scons_version)
802653Sstever@eecs.umich.eduexcept:
812653Sstever@eecs.umich.edu    print "Error checking current SCons version."
822653Sstever@eecs.umich.edu    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
832653Sstever@eecs.umich.edu    Exit(2)
842653Sstever@eecs.umich.edu    
851852SN/A
86955SN/A# The absolute path to the current directory (where this file lives).
87955SN/AROOT = Dir('.').abspath
88955SN/A
892632Sstever@eecs.umich.edu# Paths to the M5 and external source trees.
902632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'src')
91955SN/A
921533SN/A# tell python where to find m5 python code
932632Sstever@eecs.umich.edusys.path.append(os.path.join(ROOT, 'src/python'))
941533SN/A
95955SN/A###################################################
96955SN/A#
972632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
982632Sstever@eecs.umich.edu# the target(s).
99955SN/A#
100955SN/A###################################################
101955SN/A
102955SN/A# Find default configuration & binary.
1032632Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
104955SN/A
1052632Sstever@eecs.umich.edu# Ask SCons which directory it was invoked from.
106955SN/Alaunch_dir = GetLaunchDir()
107955SN/A
1082632Sstever@eecs.umich.edu# Make targets relative to invocation directory
1092632Sstever@eecs.umich.eduabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1102632Sstever@eecs.umich.edu                  BUILD_TARGETS)
1112632Sstever@eecs.umich.edu
1122632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
1132632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
1142632Sstever@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1152632Sstever@eecs.umich.edu        if l[i] == elt:
1162632Sstever@eecs.umich.edu            return i
1172632Sstever@eecs.umich.edu    raise ValueError, "element not found"
1182632Sstever@eecs.umich.edu
1192632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1202632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
1212632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1222632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1232632Sstever@eecs.umich.edu# follow 'build' in the bulid path.
1242632Sstever@eecs.umich.edu
1252634Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the
1262634Sstever@eecs.umich.edu# collected targets reference.
1272632Sstever@eecs.umich.edubuild_paths = []
1282638Sstever@eecs.umich.edubuild_root = None
1292632Sstever@eecs.umich.edufor t in abs_targets:
1302632Sstever@eecs.umich.edu    path_dirs = t.split('/')
1312632Sstever@eecs.umich.edu    try:
1322632Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1332632Sstever@eecs.umich.edu    except:
1342632Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1351858SN/A        Exit(1)
1362638Sstever@eecs.umich.edu    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1372638Sstever@eecs.umich.edu    if not build_root:
1382638Sstever@eecs.umich.edu        build_root = this_build_root
1392638Sstever@eecs.umich.edu    else:
1402638Sstever@eecs.umich.edu        if this_build_root != build_root:
1412638Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
1422638Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
1432638Sstever@eecs.umich.edu            Exit(1)
1442634Sstever@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1452634Sstever@eecs.umich.edu    if build_path not in build_paths:
1462634Sstever@eecs.umich.edu        build_paths.append(build_path)
147955SN/A
148955SN/A###################################################
149955SN/A#
150955SN/A# Set up the default build environment.  This environment is copied
151955SN/A# and modified according to each selected configuration.
152955SN/A#
153955SN/A###################################################
154955SN/A
1551858SN/Aenv = Environment(ENV = os.environ,  # inherit user's environment vars
1561858SN/A                  ROOT = ROOT,
1572632Sstever@eecs.umich.edu                  SRCDIR = SRCDIR)
158955SN/A
1591858SN/Aenv.SConsignFile("sconsign")
1601105SN/A
1611869SN/A# I waffle on this setting... it does avoid a few painful but
1621869SN/A# unnecessary builds, but it also seems to make trivial builds take
1631869SN/A# noticeably longer.
1641869SN/Aif False:
1651869SN/A    env.TargetSignatures('content')
1661065SN/A
1672632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
1682632Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
169955SN/A
1701858SN/A# Set up default C++ compiler flags
1711858SN/Aenv.Append(CCFLAGS='-pipe')
1721858SN/Aenv.Append(CCFLAGS='-fno-strict-aliasing')
1731858SN/Aenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1741851SN/Aif sys.platform == 'cygwin':
1751851SN/A    # cygwin has some header file issues...
1761858SN/A    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1772632Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')])
178955SN/A
1792656Sstever@eecs.umich.edu# Find Python include and library directories for embedding the
1802656Sstever@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
1812656Sstever@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
1822656Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
1832656Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
1842656Sstever@eecs.umich.edu
1852656Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating
1862656Sstever@eecs.umich.edu# include & library files
1872656Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3]
1882656Sstever@eecs.umich.edu
1892656Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4
1902656Sstever@eecs.umich.eduenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
1912656Sstever@eecs.umich.eduenv.Append(LIBS = py_version_name)
1922656Sstever@eecs.umich.edu# add library path too if it's not in the default place
1932656Sstever@eecs.umich.eduif sys.exec_prefix != '/usr':
1942656Sstever@eecs.umich.edu    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
1952655Sstever@eecs.umich.edu
1962655Sstever@eecs.umich.edu# Other default libraries
1971858SN/Aenv.Append(LIBS=['z'])
1981858SN/A
1992638Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
2002638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
2012638Sstever@eecs.umich.educonf = Configure(env,
2022638Sstever@eecs.umich.edu                 conf_dir = os.path.join(build_root, '.scons_config'),
2032638Sstever@eecs.umich.edu                 log_file = os.path.join(build_root, 'scons_config.log'))
2041858SN/A
2051858SN/A# Check for <fenv.h> (C99 FP environment control)
2061858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>')
2071858SN/Aif not have_fenv:
2081858SN/A    print "Warning: Header file <fenv.h> not found."
2091858SN/A    print "         This host has no IEEE FP rounding mode control."
2101858SN/A
2111859SN/A# Check for mysql.
2121858SN/Amysql_config = WhereIs('mysql_config')
2131858SN/Ahave_mysql = mysql_config != None
2141858SN/A
2151859SN/A# Check MySQL version.
2161859SN/Aif have_mysql:
2171862SN/A    mysql_version = os.popen(mysql_config + ' --version').read()
2181862SN/A    mysql_version = mysql_version.split('.')
2191862SN/A    mysql_major = int(mysql_version[0])
2201862SN/A    mysql_minor = int(mysql_version[1])
2211859SN/A    # This version check is probably overly conservative, but it deals
2221859SN/A    # with the versions we have installed.
2231963SN/A    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2241963SN/A        print "Warning: MySQL v4.1 or newer required."
2251859SN/A        have_mysql = False
2261859SN/A
2271859SN/A# Set up mysql_config commands.
2281859SN/Aif have_mysql:
2291859SN/A    mysql_config_include = mysql_config + ' --include'
2301859SN/A    if os.system(mysql_config_include + ' > /dev/null') != 0:
2311859SN/A        # older mysql_config versions don't support --include, use
2321859SN/A        # --cflags instead
2331862SN/A        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2341859SN/A    # This seems to work in all versions
2351859SN/A    mysql_config_libs = mysql_config + ' --libs'
2361859SN/A
2371858SN/Aenv = conf.Finish()
2381858SN/A
2392139SN/A# Define the universe of supported ISAs
2402139SN/Aenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2412139SN/A
2422155SN/A# Define the universe of supported CPU models
2432623SN/Aenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2442637Sstever@eecs.umich.edu                       'FullCPU', 'AlphaFullCPU']
2452155SN/A
2461869SN/A# Sticky options get saved in the options file so they persist from
2471869SN/A# one invocation to the next (unless overridden, in which case the new
2481869SN/A# value becomes sticky).
2491869SN/Asticky_opts = Options(args=ARGUMENTS)
2501869SN/Asticky_opts.AddOptions(
2512139SN/A    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2521869SN/A    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2532508SN/A    # There's a bug in scons 0.96.1 that causes ListOptions with list
2542508SN/A    # values (more than one value) not to be able to be restored from
2552508SN/A    # a saved option file.  If this causes trouble then upgrade to
2562508SN/A    # scons 0.96.90 or later.
2572635Sstever@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2582635Sstever@eecs.umich.edu               env['ALL_CPU_LIST']),
2591869SN/A    BoolOption('ALPHA_TLASER',
2601869SN/A               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2611869SN/A    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2621869SN/A    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2631869SN/A               False),
2641869SN/A    BoolOption('SS_COMPATIBLE_FP',
2651869SN/A               'Make floating-point results compatible with SimpleScalar',
2661869SN/A               False),
2671965SN/A    BoolOption('USE_SSE2',
2681965SN/A               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2691965SN/A               False),
2701869SN/A    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2711869SN/A    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2721869SN/A    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2731869SN/A    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2741884SN/A    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2751884SN/A    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2761884SN/A    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2771869SN/A    )
2781858SN/A
2791869SN/A# Non-sticky options only apply to the current build.
2801869SN/Anonsticky_opts = Options(args=ARGUMENTS)
2811869SN/Anonsticky_opts.AddOptions(
2821869SN/A    BoolOption('update_ref', 'Update test reference outputs', False)
2831869SN/A    )
2841858SN/A
2851869SN/A# These options get exported to #defines in config/*.hh (see m5/SConscript).
2861869SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2871869SN/A                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2881869SN/A                     'STATS_BINNING']
2891869SN/A
2901869SN/A# Define a handy 'no-op' action
2911869SN/Adef no_action(target, source, env):
2921869SN/A    return 0
2931869SN/A
2941869SN/Aenv.NoAction = Action(no_action, None)
2951858SN/A
296955SN/A###################################################
297955SN/A#
2981869SN/A# Define a SCons builder for configuration flag headers.
2991869SN/A#
3001869SN/A###################################################
3011869SN/A
3021869SN/A# This function generates a config header file that #defines the
3031869SN/A# option symbol to the current option setting (0 or 1).  The source
3041869SN/A# operands are the name of the option and a Value node containing the
3051869SN/A# value of the option.
3061869SN/Adef build_config_file(target, source, env):
3071869SN/A    (option, value) = [s.get_contents() for s in source]
3081869SN/A    f = file(str(target[0]), 'w')
3091869SN/A    print >> f, '#define', option, value
3101869SN/A    f.close()
3111869SN/A    return None
3121869SN/A
3131869SN/A# Generate the message to be printed when building the config file.
3141869SN/Adef build_config_file_string(target, source, env):
3151869SN/A    (option, value) = [s.get_contents() for s in source]
3161869SN/A    return "Defining %s as %s in %s." % (option, value, target[0])
3171869SN/A
3181869SN/A# Combine the two functions into a scons Action object.
3191869SN/Aconfig_action = Action(build_config_file, build_config_file_string)
3201869SN/A
3211869SN/A# The emitter munges the source & target node lists to reflect what
3221869SN/A# we're really doing.
3231869SN/Adef config_emitter(target, source, env):
3241869SN/A    # extract option name from Builder arg
3251869SN/A    option = str(target[0])
3261869SN/A    # True target is config header file
3271869SN/A    target = os.path.join('config', option.lower() + '.hh')
3281869SN/A    # Force value to 0/1 even if it's a Python bool
3291869SN/A    val = int(eval(str(env[option])))
3301869SN/A    # Sources are option name & value (packaged in SCons Value nodes)
3311869SN/A    return ([target], [Value(option), Value(val)])
3321869SN/A
3331869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
3341869SN/A
3351869SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3361869SN/A
3372655Sstever@eecs.umich.edu###################################################
3382655Sstever@eecs.umich.edu#
3392655Sstever@eecs.umich.edu# Define a SCons builder for copying files.  This is used by the
3402655Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here
3412655Sstever@eecs.umich.edu# since it's potentially more generally applicable.
3422655Sstever@eecs.umich.edu#
3432655Sstever@eecs.umich.edu###################################################
3442655Sstever@eecs.umich.edu
3452655Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3462655Sstever@eecs.umich.edu
3472655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3482655Sstever@eecs.umich.edu
3492655Sstever@eecs.umich.edu###################################################
3502655Sstever@eecs.umich.edu#
3512655Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files.
3522655Sstever@eecs.umich.edu#
3532655Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable.
3542655Sstever@eecs.umich.edu#
3552655Sstever@eecs.umich.edu###################################################
3562655Sstever@eecs.umich.edu
3572655Sstever@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3582655Sstever@eecs.umich.edu                                          'chmod +x $TARGET']))
3592655Sstever@eecs.umich.edu
3602655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder })
3612655Sstever@eecs.umich.edu
3622655Sstever@eecs.umich.edu
3632634Sstever@eecs.umich.edu# base help text
3642634Sstever@eecs.umich.eduhelp_text = '''
3652634Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)]
3662634Sstever@eecs.umich.edu
3672634Sstever@eecs.umich.edu'''
3682634Sstever@eecs.umich.edu
3692638Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root.
3702638Sstever@eecs.umich.eduenv.SConscript('ext/libelf/SConscript',
3712638Sstever@eecs.umich.edu               build_dir = os.path.join(build_root, 'libelf'),
3722638Sstever@eecs.umich.edu               exports = 'env')
3732638Sstever@eecs.umich.edu
3741869SN/A###################################################
3751869SN/A#
376955SN/A# Define build environments for selected configurations.
377955SN/A#
378955SN/A###################################################
379955SN/A
3801858SN/A# rename base env
3811858SN/Abase_env = env
3821858SN/A
3832632Sstever@eecs.umich.edufor build_path in build_paths:
3842632Sstever@eecs.umich.edu    print "Building in", build_path
3852632Sstever@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
3862632Sstever@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
3872632Sstever@eecs.umich.edu    (build_root, build_dir) = os.path.split(build_path)
3882634Sstever@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
3892638Sstever@eecs.umich.edu    env = base_env.Copy()
3902023SN/A
3912632Sstever@eecs.umich.edu    # Set env options according to the build directory config.
3922632Sstever@eecs.umich.edu    sticky_opts.files = []
3932632Sstever@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
3942632Sstever@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
3952632Sstever@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
3962632Sstever@eecs.umich.edu    current_opts_file = os.path.join(build_root, 'options', build_dir)
3972632Sstever@eecs.umich.edu    if os.path.isfile(current_opts_file):
3982632Sstever@eecs.umich.edu        sticky_opts.files.append(current_opts_file)
3992632Sstever@eecs.umich.edu        print "Using saved options file %s" % current_opts_file
4002632Sstever@eecs.umich.edu    else:
4012632Sstever@eecs.umich.edu        # Build dir-specific options file doesn't exist.
4022023SN/A
4032632Sstever@eecs.umich.edu        # Make sure the directory is there so we can create it later
4042632Sstever@eecs.umich.edu        opt_dir = os.path.dirname(current_opts_file)
4051889SN/A        if not os.path.isdir(opt_dir):
4061889SN/A            os.mkdir(opt_dir)
4072632Sstever@eecs.umich.edu
4082632Sstever@eecs.umich.edu        # Get default build options from source tree.  Options are
4092632Sstever@eecs.umich.edu        # normally determined by name of $BUILD_DIR, but can be
4102632Sstever@eecs.umich.edu        # overriden by 'default=' arg on command line.
4112632Sstever@eecs.umich.edu        default_opts_file = os.path.join('build_opts',
4122632Sstever@eecs.umich.edu                                         ARGUMENTS.get('default', build_dir))
4132632Sstever@eecs.umich.edu        if os.path.isfile(default_opts_file):
4142632Sstever@eecs.umich.edu            sticky_opts.files.append(default_opts_file)
4152632Sstever@eecs.umich.edu            print "Options file %s not found,\n  using defaults in %s" \
4162632Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4172632Sstever@eecs.umich.edu        else:
4182632Sstever@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
4192632Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4202632Sstever@eecs.umich.edu            Exit(1)
4211888SN/A
4221888SN/A    # Apply current option settings to env
4231869SN/A    sticky_opts.Update(env)
4241869SN/A    nonsticky_opts.Update(env)
4251858SN/A
4262598SN/A    help_text += "Sticky options for %s:\n" % build_dir \
4272598SN/A                 + sticky_opts.GenerateHelpText(env) \
4282598SN/A                 + "\nNon-sticky options for %s:\n" % build_dir \
4292598SN/A                 + nonsticky_opts.GenerateHelpText(env)
4302598SN/A
4311858SN/A    # Process option settings.
4321858SN/A
4331858SN/A    if not have_fenv and env['USE_FENV']:
4341858SN/A        print "Warning: <fenv.h> not available; " \
4351858SN/A              "forcing USE_FENV to False in", build_dir + "."
4361858SN/A        env['USE_FENV'] = False
4371858SN/A
4381858SN/A    if not env['USE_FENV']:
4391858SN/A        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4401871SN/A        print "         FP results may deviate slightly from other platforms."
4411858SN/A
4421858SN/A    if env['EFENCE']:
4431858SN/A        env.Append(LIBS=['efence'])
4441858SN/A
4451858SN/A    if env['USE_MYSQL']:
4461858SN/A        if not have_mysql:
4471858SN/A            print "Warning: MySQL not available; " \
4481858SN/A                  "forcing USE_MYSQL to False in", build_dir + "."
4491858SN/A            env['USE_MYSQL'] = False
4501858SN/A        else:
4511858SN/A            print "Compiling in", build_dir, "with MySQL support."
4521859SN/A            env.ParseConfig(mysql_config_libs)
4531859SN/A            env.ParseConfig(mysql_config_include)
4541869SN/A
4551888SN/A    # Save sticky option settings back to current options file
4562632Sstever@eecs.umich.edu    sticky_opts.Save(current_opts_file, env)
4571869SN/A
4581884SN/A    # Do this after we save setting back, or else we'll tack on an
4591884SN/A    # extra 'qdo' every time we run scons.
4601884SN/A    if env['BATCH']:
4611884SN/A        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4621884SN/A        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4631884SN/A
4641965SN/A    if env['USE_SSE2']:
4651965SN/A        env.Append(CCFLAGS='-msse2')
4661965SN/A
467955SN/A    # The m5/SConscript file sets up the build rules in 'env' according
4681869SN/A    # to the configured options.  It returns a list of environments,
4691869SN/A    # one for each variant build (debug, opt, etc.)
4702632Sstever@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
4711869SN/A                         exports = 'env', duplicate = False)
4721869SN/A
4731869SN/A    # Set up the regression tests for each build.
4742632Sstever@eecs.umich.edu#    for e in envList:
4752632Sstever@eecs.umich.edu#        SConscript('m5-test/SConscript',
4762632Sstever@eecs.umich.edu#                   build_dir = os.path.join(build_dir, 'test', e.Label),
4772632Sstever@eecs.umich.edu#                   exports = { 'env' : e }, duplicate = False)
478955SN/A
4792598SN/AHelp(help_text)
4802598SN/A
481955SN/A###################################################
482955SN/A#
483955SN/A# Let SCons do its thing.  At this point SCons will use the defined
4841530SN/A# build environments to build the requested targets.
485955SN/A#
486955SN/A###################################################
487955SN/A
488