SConstruct revision 2632
1955SN/A# -*- mode:python -*-
2955SN/A
39812Sandreas.hansson@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from
157816Ssteve.reinhardt@amd.com# this software without specific prior written permission.
165871Snate@binkert.org#
171762SN/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.
28955SN/A
29955SN/A###################################################
30955SN/A#
31955SN/A# SCons top-level build description (SConstruct) file.
32955SN/A#
33955SN/A# While in this directory ('m5'), just type 'scons' to build the default
34955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
35955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
36955SN/A# the optimized full-system version).
37955SN/A#
38955SN/A# You can build M5 in a different directory as long as there is a
39955SN/A# 'build/<CONFIG>' somewhere along the target path.  The build system
40955SN/A# expdects that all configs under the same build directory are being
41955SN/A# built for the same host system.
422665Ssaidi@eecs.umich.edu#
432665Ssaidi@eecs.umich.edu# Examples:
445863Snate@binkert.org#   These two commands are equivalent.  The '-u' option tells scons to
45955SN/A#   search up the directory tree for this SConstruct file.
46955SN/A#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
47955SN/A#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
48955SN/A#   These two commands are equivalent and demonstrate building in a
49955SN/A#   directory outside of the source tree.  The '-C' option tells scons
508878Ssteve.reinhardt@amd.com#   to chdir to the specified directory to find this SConstruct file.
512632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
528878Ssteve.reinhardt@amd.com#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
532632Sstever@eecs.umich.edu#
54955SN/A# You can use 'scons -H' to print scons options.  If you're in this
558878Ssteve.reinhardt@amd.com# 'm5' directory (or use -u or -C to tell scons where to find this
562632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
572761Sstever@eecs.umich.edu# options as well.
582632Sstever@eecs.umich.edu#
592632Sstever@eecs.umich.edu###################################################
602632Sstever@eecs.umich.edu
612761Sstever@eecs.umich.edu# Python library imports
622761Sstever@eecs.umich.eduimport sys
632761Sstever@eecs.umich.eduimport os
648878Ssteve.reinhardt@amd.com
658878Ssteve.reinhardt@amd.com# Check for recent-enough Python and SCons versions
662761Sstever@eecs.umich.eduEnsurePythonVersion(2,3)
672761Sstever@eecs.umich.eduEnsureSConsVersion(0,96,91)
682761Sstever@eecs.umich.edu
692761Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives).
702761Sstever@eecs.umich.eduROOT = Dir('.').abspath
718878Ssteve.reinhardt@amd.com
728878Ssteve.reinhardt@amd.com# Paths to the M5 and external source trees.
732632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'src')
742632Sstever@eecs.umich.edu
758878Ssteve.reinhardt@amd.com# tell python where to find m5 python code
768878Ssteve.reinhardt@amd.comsys.path.append(os.path.join(ROOT, 'src/python'))
772632Sstever@eecs.umich.edu
78955SN/A###################################################
79955SN/A#
80955SN/A# Figure out which configurations to set up based on the path(s) of
815863Snate@binkert.org# the target(s).
825863Snate@binkert.org#
835863Snate@binkert.org###################################################
845863Snate@binkert.org
855863Snate@binkert.org# Find default configuration & binary.
865863Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
875863Snate@binkert.org
885863Snate@binkert.org# Ask SCons which directory it was invoked from.
895863Snate@binkert.orglaunch_dir = GetLaunchDir()
905863Snate@binkert.org
915863Snate@binkert.org# Make targets relative to invocation directory
928878Ssteve.reinhardt@amd.comabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
935863Snate@binkert.org                  BUILD_TARGETS)
945863Snate@binkert.org
955863Snate@binkert.org# helper function: find last occurrence of element in list
969812Sandreas.hansson@arm.comdef rfind(l, elt, offs = -1):
979812Sandreas.hansson@arm.com    for i in range(len(l)+offs, 0, -1):
985863Snate@binkert.org        if l[i] == elt:
999812Sandreas.hansson@arm.com            return i
1005863Snate@binkert.org    raise ValueError, "element not found"
1015863Snate@binkert.org
1025863Snate@binkert.org# Each target must have 'build' in the interior of the path; the
1039812Sandreas.hansson@arm.com# directory below this will determine the build parameters.  For
1049812Sandreas.hansson@arm.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1055863Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it
1065863Snate@binkert.org# follow 'build' in the bulid path.
1078878Ssteve.reinhardt@amd.com
1085863Snate@binkert.org# Generate a list of the unique configs that the collected targets
1095863Snate@binkert.org# reference.
1105863Snate@binkert.orgbuild_paths = []
1116654Snate@binkert.orgfor t in abs_targets:
11210196SCurtis.Dunham@arm.com    path_dirs = t.split('/')
113955SN/A    try:
1145396Ssaidi@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1155863Snate@binkert.org    except:
1165863Snate@binkert.org        print "Error: no non-leaf 'build' dir found on target path", t
1174202Sbinkertn@umich.edu        Exit(1)
1185863Snate@binkert.org    config_dir = os.path.join('/',*path_dirs[:build_top+2])
1195863Snate@binkert.org    if config_dir not in build_paths:
1205863Snate@binkert.org        build_paths.append(config_dir)
1215863Snate@binkert.org
122955SN/A###################################################
1236654Snate@binkert.org#
1245273Sstever@gmail.com# Set up the default build environment.  This environment is copied
1255871Snate@binkert.org# and modified according to each selected configuration.
1265273Sstever@gmail.com#
1276655Snate@binkert.org###################################################
1288878Ssteve.reinhardt@amd.com
1296655Snate@binkert.orgenv = Environment(ENV = os.environ,  # inherit user's environment vars
1306655Snate@binkert.org                  ROOT = ROOT,
1319219Spower.jg@gmail.com                  SRCDIR = SRCDIR)
1326655Snate@binkert.org
1335871Snate@binkert.orgenv.SConsignFile("sconsign")
1346654Snate@binkert.org
1358947Sandreas.hansson@arm.com# I waffle on this setting... it does avoid a few painful but
1365396Ssaidi@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take
1378120Sgblack@eecs.umich.edu# noticeably longer.
1388120Sgblack@eecs.umich.eduif False:
1398120Sgblack@eecs.umich.edu    env.TargetSignatures('content')
1408120Sgblack@eecs.umich.edu
1418120Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
1428120Sgblack@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1438120Sgblack@eecs.umich.edu
1448120Sgblack@eecs.umich.edu# Set up default C++ compiler flags
1458879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-pipe')
1468879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-fno-strict-aliasing')
1478879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1488879Ssteve.reinhardt@amd.comif sys.platform == 'cygwin':
1498879Ssteve.reinhardt@amd.com    # cygwin has some header file issues...
1508879Ssteve.reinhardt@amd.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1518879Ssteve.reinhardt@amd.comenv.Append(CPPPATH=[Dir('ext/dnet')])
1528879Ssteve.reinhardt@amd.com
1538879Ssteve.reinhardt@amd.com# Default libraries
1548879Ssteve.reinhardt@amd.comenv.Append(LIBS=['z'])
1558879Ssteve.reinhardt@amd.com
1568879Ssteve.reinhardt@amd.com# Platform-specific configuration
1578879Ssteve.reinhardt@amd.comconf = Configure(env)
1588120Sgblack@eecs.umich.edu
1598120Sgblack@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
1608120Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
1618120Sgblack@eecs.umich.eduif not have_fenv:
1628120Sgblack@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
1638120Sgblack@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
1648120Sgblack@eecs.umich.edu
1658120Sgblack@eecs.umich.edu# Check for mysql.
1668120Sgblack@eecs.umich.edumysql_config = WhereIs('mysql_config')
1678120Sgblack@eecs.umich.eduhave_mysql = mysql_config != None
1688120Sgblack@eecs.umich.edu
1698120Sgblack@eecs.umich.edu# Check MySQL version.
1708120Sgblack@eecs.umich.eduif have_mysql:
1718120Sgblack@eecs.umich.edu    mysql_version = os.popen(mysql_config + ' --version').read()
1728879Ssteve.reinhardt@amd.com    mysql_version = mysql_version.split('.')
1738879Ssteve.reinhardt@amd.com    mysql_major = int(mysql_version[0])
1748879Ssteve.reinhardt@amd.com    mysql_minor = int(mysql_version[1])
1758879Ssteve.reinhardt@amd.com    # This version check is probably overly conservative, but it deals
1768879Ssteve.reinhardt@amd.com    # with the versions we have installed.
1778879Ssteve.reinhardt@amd.com    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
1788879Ssteve.reinhardt@amd.com        print "Warning: MySQL v4.1 or newer required."
1798879Ssteve.reinhardt@amd.com        have_mysql = False
1809227Sandreas.hansson@arm.com
1819227Sandreas.hansson@arm.com# Set up mysql_config commands.
1828879Ssteve.reinhardt@amd.comif have_mysql:
1838879Ssteve.reinhardt@amd.com    mysql_config_include = mysql_config + ' --include'
1848879Ssteve.reinhardt@amd.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
1858879Ssteve.reinhardt@amd.com        # older mysql_config versions don't support --include, use
18610453SAndrew.Bardsley@arm.com        # --cflags instead
18710453SAndrew.Bardsley@arm.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
18810453SAndrew.Bardsley@arm.com    # This seems to work in all versions
18910456SCurtis.Dunham@arm.com    mysql_config_libs = mysql_config + ' --libs'
19010456SCurtis.Dunham@arm.com
19110456SCurtis.Dunham@arm.comenv = conf.Finish()
1928120Sgblack@eecs.umich.edu
1938947Sandreas.hansson@arm.com# Define the universe of supported ISAs
1947816Ssteve.reinhardt@amd.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
1955871Snate@binkert.org
1965871Snate@binkert.org# Define the universe of supported CPU models
1976121Snate@binkert.orgenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
1985871Snate@binkert.org                       'FastCPU', 'FullCPU', 'AlphaFullCPU']
1995871Snate@binkert.org
2009926Sstan.czerniawski@arm.com# Sticky options get saved in the options file so they persist from
2019926Sstan.czerniawski@arm.com# one invocation to the next (unless overridden, in which case the new
2029119Sandreas.hansson@arm.com# value becomes sticky).
20310068Sandreas.hansson@arm.comsticky_opts = Options(args=ARGUMENTS)
20410068Sandreas.hansson@arm.comsticky_opts.AddOptions(
205955SN/A    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2069416SAndreas.Sandberg@ARM.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2079416SAndreas.Sandberg@ARM.com    # There's a bug in scons 0.96.1 that causes ListOptions with list
2089416SAndreas.Sandberg@ARM.com    # values (more than one value) not to be able to be restored from
2099416SAndreas.Sandberg@ARM.com    # a saved option file.  If this causes trouble then upgrade to
2109416SAndreas.Sandberg@ARM.com    # scons 0.96.90 or later.
2119416SAndreas.Sandberg@ARM.com    ListOption('CPU_MODELS', 'CPU models', 'all', env['ALL_CPU_LIST']),
2129416SAndreas.Sandberg@ARM.com    BoolOption('ALPHA_TLASER',
2135871Snate@binkert.org               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2145871Snate@binkert.org    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2159416SAndreas.Sandberg@ARM.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2169416SAndreas.Sandberg@ARM.com               False),
2175871Snate@binkert.org    BoolOption('SS_COMPATIBLE_FP',
218955SN/A               'Make floating-point results compatible with SimpleScalar',
2196121Snate@binkert.org               False),
2208881Smarc.orr@gmail.com    BoolOption('USE_SSE2',
2216121Snate@binkert.org               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2226121Snate@binkert.org               False),
2231533SN/A    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2249239Sandreas.hansson@arm.com    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2259239Sandreas.hansson@arm.com    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2269239Sandreas.hansson@arm.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2279239Sandreas.hansson@arm.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2289239Sandreas.hansson@arm.com    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2299239Sandreas.hansson@arm.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2309239Sandreas.hansson@arm.com    )
2319239Sandreas.hansson@arm.com
2329239Sandreas.hansson@arm.com# Non-sticky options only apply to the current build.
2339239Sandreas.hansson@arm.comnonsticky_opts = Options(args=ARGUMENTS)
2349239Sandreas.hansson@arm.comnonsticky_opts.AddOptions(
2359239Sandreas.hansson@arm.com    BoolOption('update_ref', 'Update test reference outputs', False)
2366655Snate@binkert.org    )
2376655Snate@binkert.org
2386655Snate@binkert.org# These options get exported to #defines in config/*.hh (see m5/SConscript).
2396655Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2405871Snate@binkert.org                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2415871Snate@binkert.org                     'STATS_BINNING']
2425863Snate@binkert.org
2435871Snate@binkert.org# Define a handy 'no-op' action
2448878Ssteve.reinhardt@amd.comdef no_action(target, source, env):
2455871Snate@binkert.org    return 0
2465871Snate@binkert.org
2475871Snate@binkert.orgenv.NoAction = Action(no_action, None)
2485863Snate@binkert.org
2496121Snate@binkert.org# libelf build is described in its own SConscript file.
2505863Snate@binkert.org# SConscript-global is the build in build/libelf shared among all
2515871Snate@binkert.org# configs.
2528336Ssteve.reinhardt@amd.comenv.SConscript('src/libelf/SConscript-global', exports = 'env')
2538336Ssteve.reinhardt@amd.com
2548336Ssteve.reinhardt@amd.com###################################################
2558336Ssteve.reinhardt@amd.com#
2564678Snate@binkert.org# Define a SCons builder for configuration flag headers.
2578336Ssteve.reinhardt@amd.com#
2588336Ssteve.reinhardt@amd.com###################################################
2598336Ssteve.reinhardt@amd.com
2604678Snate@binkert.org# This function generates a config header file that #defines the
2614678Snate@binkert.org# option symbol to the current option setting (0 or 1).  The source
2624678Snate@binkert.org# operands are the name of the option and a Value node containing the
2634678Snate@binkert.org# value of the option.
2647827Snate@binkert.orgdef build_config_file(target, source, env):
2657827Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
2668336Ssteve.reinhardt@amd.com    f = file(str(target[0]), 'w')
2674678Snate@binkert.org    print >> f, '#define', option, value
2688336Ssteve.reinhardt@amd.com    f.close()
2698336Ssteve.reinhardt@amd.com    return None
2708336Ssteve.reinhardt@amd.com
2718336Ssteve.reinhardt@amd.com# Generate the message to be printed when building the config file.
2728336Ssteve.reinhardt@amd.comdef build_config_file_string(target, source, env):
2738336Ssteve.reinhardt@amd.com    (option, value) = [s.get_contents() for s in source]
2745871Snate@binkert.org    return "Defining %s as %s in %s." % (option, value, target[0])
2755871Snate@binkert.org
2768336Ssteve.reinhardt@amd.com# Combine the two functions into a scons Action object.
2778336Ssteve.reinhardt@amd.comconfig_action = Action(build_config_file, build_config_file_string)
2788336Ssteve.reinhardt@amd.com
2798336Ssteve.reinhardt@amd.com# The emitter munges the source & target node lists to reflect what
2808336Ssteve.reinhardt@amd.com# we're really doing.
2815871Snate@binkert.orgdef config_emitter(target, source, env):
2828336Ssteve.reinhardt@amd.com    # extract option name from Builder arg
2838336Ssteve.reinhardt@amd.com    option = str(target[0])
2848336Ssteve.reinhardt@amd.com    # True target is config header file
2858336Ssteve.reinhardt@amd.com    target = os.path.join('config', option.lower() + '.hh')
2868336Ssteve.reinhardt@amd.com    # Force value to 0/1 even if it's a Python bool
2874678Snate@binkert.org    val = int(eval(str(env[option])))
2885871Snate@binkert.org    # Sources are option name & value (packaged in SCons Value nodes)
2894678Snate@binkert.org    return ([target], [Value(option), Value(val)])
2908336Ssteve.reinhardt@amd.com
2918336Ssteve.reinhardt@amd.comconfig_builder = Builder(emitter = config_emitter, action = config_action)
2928336Ssteve.reinhardt@amd.com
2938336Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
2948336Ssteve.reinhardt@amd.com
2958336Ssteve.reinhardt@amd.com###################################################
2968336Ssteve.reinhardt@amd.com#
2978336Ssteve.reinhardt@amd.com# Define build environments for selected configurations.
2988336Ssteve.reinhardt@amd.com#
2998336Ssteve.reinhardt@amd.com###################################################
3008336Ssteve.reinhardt@amd.com
3018336Ssteve.reinhardt@amd.com# rename base env
3028336Ssteve.reinhardt@amd.combase_env = env
3038336Ssteve.reinhardt@amd.com
3048336Ssteve.reinhardt@amd.comhelp_text = '''
3058336Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)]
3068336Ssteve.reinhardt@amd.com
3075871Snate@binkert.org'''
3086121Snate@binkert.org
309955SN/Afor build_path in build_paths:
310955SN/A    print "Building in", build_path
3112632Sstever@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
3122632Sstever@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
313955SN/A    (build_root, build_dir) = os.path.split(build_path)
314955SN/A    # Make a copy of the default environment to use for this config.
315955SN/A    env = base_env.Copy()
316955SN/A
3178878Ssteve.reinhardt@amd.com    # Set env options according to the build directory config.
318955SN/A    sticky_opts.files = []
3192632Sstever@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
3202632Sstever@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
3212632Sstever@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
3222632Sstever@eecs.umich.edu    current_opts_file = os.path.join(build_root, 'options', build_dir)
3232632Sstever@eecs.umich.edu    if os.path.isfile(current_opts_file):
3242632Sstever@eecs.umich.edu        sticky_opts.files.append(current_opts_file)
3252632Sstever@eecs.umich.edu        print "Using saved options file %s" % current_opts_file
3268268Ssteve.reinhardt@amd.com    else:
3278268Ssteve.reinhardt@amd.com        # Build dir-specific options file doesn't exist.
3288268Ssteve.reinhardt@amd.com
3298268Ssteve.reinhardt@amd.com        # Make sure the directory is there so we can create it later
3308268Ssteve.reinhardt@amd.com        opt_dir = os.path.dirname(current_opts_file)
3318268Ssteve.reinhardt@amd.com        if not os.path.isdir(opt_dir):
3328268Ssteve.reinhardt@amd.com            os.mkdir(opt_dir)
3332632Sstever@eecs.umich.edu
3342632Sstever@eecs.umich.edu        # Get default build options from source tree.  Options are
3352632Sstever@eecs.umich.edu        # normally determined by name of $BUILD_DIR, but can be
3362632Sstever@eecs.umich.edu        # overriden by 'default=' arg on command line.
3378268Ssteve.reinhardt@amd.com        default_opts_file = os.path.join('build_opts',
3382632Sstever@eecs.umich.edu                                         ARGUMENTS.get('default', build_dir))
3398268Ssteve.reinhardt@amd.com        if os.path.isfile(default_opts_file):
3408268Ssteve.reinhardt@amd.com            sticky_opts.files.append(default_opts_file)
3418268Ssteve.reinhardt@amd.com            print "Options file %s not found,\n  using defaults in %s" \
3428268Ssteve.reinhardt@amd.com                  % (current_opts_file, default_opts_file)
3433718Sstever@eecs.umich.edu        else:
3442634Sstever@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
3452634Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
3465863Snate@binkert.org            Exit(1)
3472638Sstever@eecs.umich.edu
3488268Ssteve.reinhardt@amd.com    # Apply current option settings to env
3492632Sstever@eecs.umich.edu    sticky_opts.Update(env)
3502632Sstever@eecs.umich.edu    nonsticky_opts.Update(env)
3512632Sstever@eecs.umich.edu
3522632Sstever@eecs.umich.edu    help_text += "Sticky options for %s:\n" % build_dir \
3532632Sstever@eecs.umich.edu                 + sticky_opts.GenerateHelpText(env) \
3541858SN/A                 + "\nNon-sticky options for %s:\n" % build_dir \
3553716Sstever@eecs.umich.edu                 + nonsticky_opts.GenerateHelpText(env)
3562638Sstever@eecs.umich.edu
3572638Sstever@eecs.umich.edu    # Process option settings.
3582638Sstever@eecs.umich.edu
3592638Sstever@eecs.umich.edu    if not have_fenv and env['USE_FENV']:
3602638Sstever@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
3612638Sstever@eecs.umich.edu              "forcing USE_FENV to False in", build_dir + "."
3622638Sstever@eecs.umich.edu        env['USE_FENV'] = False
3635863Snate@binkert.org
3645863Snate@binkert.org    if not env['USE_FENV']:
3655863Snate@binkert.org        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
366955SN/A        print "         FP results may deviate slightly from other platforms."
3675341Sstever@gmail.com
3685341Sstever@gmail.com    if env['EFENCE']:
3695863Snate@binkert.org        env.Append(LIBS=['efence'])
3707756SAli.Saidi@ARM.com
3715341Sstever@gmail.com    if env['USE_MYSQL']:
3726121Snate@binkert.org        if not have_mysql:
3734494Ssaidi@eecs.umich.edu            print "Warning: MySQL not available; " \
3746121Snate@binkert.org                  "forcing USE_MYSQL to False in", build_dir + "."
3751105SN/A            env['USE_MYSQL'] = False
3762667Sstever@eecs.umich.edu        else:
3772667Sstever@eecs.umich.edu            print "Compiling in", build_dir, "with MySQL support."
3782667Sstever@eecs.umich.edu            env.ParseConfig(mysql_config_libs)
3792667Sstever@eecs.umich.edu            env.ParseConfig(mysql_config_include)
3806121Snate@binkert.org
3812667Sstever@eecs.umich.edu    # Save sticky option settings back to current options file
3825341Sstever@gmail.com    sticky_opts.Save(current_opts_file, env)
3835863Snate@binkert.org
3845341Sstever@gmail.com    # Do this after we save setting back, or else we'll tack on an
3855341Sstever@gmail.com    # extra 'qdo' every time we run scons.
3865341Sstever@gmail.com    if env['BATCH']:
3878120Sgblack@eecs.umich.edu        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
3885341Sstever@gmail.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
3898120Sgblack@eecs.umich.edu
3905341Sstever@gmail.com    if env['USE_SSE2']:
3918120Sgblack@eecs.umich.edu        env.Append(CCFLAGS='-msse2')
3926121Snate@binkert.org
3936121Snate@binkert.org    # The m5/SConscript file sets up the build rules in 'env' according
3948980Ssteve.reinhardt@amd.com    # to the configured options.  It returns a list of environments,
3959396Sandreas.hansson@arm.com    # one for each variant build (debug, opt, etc.)
3965397Ssaidi@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
3975397Ssaidi@eecs.umich.edu                         exports = 'env', duplicate = False)
3987727SAli.Saidi@ARM.com
3998268Ssteve.reinhardt@amd.com    # Set up the regression tests for each build.
4006168Snate@binkert.org#    for e in envList:
4015341Sstever@gmail.com#        SConscript('m5-test/SConscript',
4028120Sgblack@eecs.umich.edu#                   build_dir = os.path.join(build_dir, 'test', e.Label),
4038120Sgblack@eecs.umich.edu#                   exports = { 'env' : e }, duplicate = False)
4048120Sgblack@eecs.umich.edu
4056814Sgblack@eecs.umich.eduHelp(help_text)
4065863Snate@binkert.org
4078120Sgblack@eecs.umich.edu###################################################
4085341Sstever@gmail.com#
4095863Snate@binkert.org# Let SCons do its thing.  At this point SCons will use the defined
4108268Ssteve.reinhardt@amd.com# build environments to build the requested targets.
4116121Snate@binkert.org#
4126121Snate@binkert.org###################################################
4138268Ssteve.reinhardt@amd.com
4145742Snate@binkert.org