SConstruct revision 2508
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###################################################
30955SN/A#
31955SN/A# SCons top-level build description (SConstruct) file.
32955SN/A#
33955SN/A# To build M5, you need a directory with three things:
34955SN/A# 1. A copy of this file (named SConstruct).
352632Sstever@eecs.umich.edu# 2. A link named 'm5' to the top of the M5 simulator source tree.
362632Sstever@eecs.umich.edu# 3. A link named 'ext' to the top of the M5 external source tree.
372632Sstever@eecs.umich.edu#
382632Sstever@eecs.umich.edu# Then type 'scons' to build the default configuration (see below), or
39955SN/A# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
402632Sstever@eecs.umich.edu# 'ALPHA_FS/m5.opt' for the optimized full-system version).
412632Sstever@eecs.umich.edu#
422761Sstever@eecs.umich.edu###################################################
432632Sstever@eecs.umich.edu
442632Sstever@eecs.umich.edu# Python library imports
452632Sstever@eecs.umich.eduimport sys
462761Sstever@eecs.umich.eduimport os
472761Sstever@eecs.umich.edu
482761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions
492632Sstever@eecs.umich.eduEnsurePythonVersion(2,3)
502632Sstever@eecs.umich.eduEnsureSConsVersion(0,96)
512761Sstever@eecs.umich.edu
522761Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives).
532761Sstever@eecs.umich.eduROOT = Dir('.').abspath
542761Sstever@eecs.umich.edu
552761Sstever@eecs.umich.edu# Paths to the M5 and external source trees (local symlinks).
562632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'm5')
572632Sstever@eecs.umich.eduEXT_SRCDIR = os.path.join(ROOT, 'ext')
582632Sstever@eecs.umich.edu
592632Sstever@eecs.umich.edu# Check for 'm5' and 'ext' links, die if they don't exist.
602632Sstever@eecs.umich.eduif not os.path.isdir(SRCDIR):
612632Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
622632Sstever@eecs.umich.edu    Exit(1)
63955SN/A
64955SN/Aif not os.path.isdir('ext'):
65955SN/A    print "Error: '%s' must be a link to the M5 external source tree." \
66955SN/A          % EXT_SRCDIR
67955SN/A    Exit(1)
683918Ssaidi@eecs.umich.edu
694202Sbinkertn@umich.edu# tell python where to find m5 python code
704678Snate@binkert.orgsys.path.append(os.path.join(SRCDIR, 'python'))
71955SN/A
722656Sstever@eecs.umich.edu###################################################
732656Sstever@eecs.umich.edu#
742656Sstever@eecs.umich.edu# Figure out which configurations to set up.
752656Sstever@eecs.umich.edu#
762656Sstever@eecs.umich.edu#
772656Sstever@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations
782656Sstever@eecs.umich.edu# and options, so we have to infer which ones the user wants.
792653Sstever@eecs.umich.edu#
802653Sstever@eecs.umich.edu# 1. If there are command-line targets, the configuration(s) are inferred
812653Sstever@eecs.umich.edu#    from the directories of those targets.  If scons was invoked from a
822653Sstever@eecs.umich.edu#    subdirectory (using 'scons -u'), those targets have to be
832653Sstever@eecs.umich.edu#    interpreted relative to that subdirectory.
842653Sstever@eecs.umich.edu#
852653Sstever@eecs.umich.edu# 2. If there are no command-line targets, and scons was invoked from a
862653Sstever@eecs.umich.edu#    subdirectory (using 'scons -u'), the configuration is inferred from
872653Sstever@eecs.umich.edu#    the name of the subdirectory.
882653Sstever@eecs.umich.edu#
894781Snate@binkert.org# 3. If there are no command-line targets and scons was invoked from
901852SN/A#    the root build directory, a default configuration is used.  The
91955SN/A#    built-in default is ALPHA_SE, but this can be overridden by setting the
92955SN/A#    M5_DEFAULT_CONFIG shell environment veriable.
93955SN/A#
943717Sstever@eecs.umich.edu# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
953716Sstever@eecs.umich.edu# this can be overridden by setting the M5_DEFAULT_BINARY shell
96955SN/A# environment veriable.
971533SN/A#
983716Sstever@eecs.umich.edu###################################################
991533SN/A
1004678Snate@binkert.org# Find default configuration & binary.
1014678Snate@binkert.orgdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
1024678Snate@binkert.orgdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1034678Snate@binkert.org
1044678Snate@binkert.org# Ask SCons which directory it was invoked from.  If you invoke SCons
1054678Snate@binkert.org# from a subdirectory you must use the '-u' flag.
1064678Snate@binkert.orglaunch_dir = GetLaunchDir()
1074678Snate@binkert.org
1084678Snate@binkert.org# Build a list 'my_targets' of all the targets relative to ROOT.
1094678Snate@binkert.orgif launch_dir == ROOT:
1104678Snate@binkert.org    # invoked from root build dir
1114678Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
1124678Snate@binkert.org        # easy: use specified targets as is
1134678Snate@binkert.org        my_targets = COMMAND_LINE_TARGETS
1144678Snate@binkert.org    else:
1154678Snate@binkert.org        # default target (ALPHA_SE/m5.debug, unless overridden)
1164678Snate@binkert.org        target = os.path.join(default_config, default_binary)
1174678Snate@binkert.org        my_targets = [target]
1184678Snate@binkert.org        Default(target)
1194678Snate@binkert.orgelse:
1204678Snate@binkert.org    # invoked from subdirectory
1214973Ssaidi@eecs.umich.edu    if not launch_dir.startswith(ROOT):
1224678Snate@binkert.org        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
1234678Snate@binkert.org              (launch_dir, ROOT)
1244678Snate@binkert.org        Exit(1)
1254678Snate@binkert.org    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
1264678Snate@binkert.org    launch_dir = launch_dir[len(ROOT)+1:]
1274678Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
128955SN/A        # make specified targets relative to ROOT
129955SN/A        my_targets = map(lambda x: os.path.join(launch_dir, x),
1302632Sstever@eecs.umich.edu                         COMMAND_LINE_TARGETS)
1312632Sstever@eecs.umich.edu    else:
132955SN/A        # build default binary (m5.debug, unless overridden) using the
133955SN/A        # config inferred by the invocation directory (the first
134955SN/A        # subdirectory after ROOT)
135955SN/A        target = os.path.join(launch_dir.split('/')[0], default_binary)
1362632Sstever@eecs.umich.edu        my_targets = [target]
137955SN/A        Default(target)
1382632Sstever@eecs.umich.edu
1392632Sstever@eecs.umich.edu# Normalize target paths (gets rid of '..' in the middle, etc.)
1402632Sstever@eecs.umich.edumy_targets = map(os.path.normpath, my_targets)
1412632Sstever@eecs.umich.edu
1422632Sstever@eecs.umich.edu# Generate a list of the unique configs that the collected targets reference.
1432632Sstever@eecs.umich.edubuild_dirs = []
1442632Sstever@eecs.umich.edufor t in my_targets:
1453053Sstever@eecs.umich.edu    dir = t.split('/')[0]
1463053Sstever@eecs.umich.edu    if dir not in build_dirs:
1473053Sstever@eecs.umich.edu        build_dirs.append(dir)
1483053Sstever@eecs.umich.edu
1493053Sstever@eecs.umich.edu###################################################
1503053Sstever@eecs.umich.edu#
1513053Sstever@eecs.umich.edu# Set up the default build environment.  This environment is copied
1523053Sstever@eecs.umich.edu# and modified according to each selected configuration.
1533053Sstever@eecs.umich.edu#
1543053Sstever@eecs.umich.edu###################################################
1553053Sstever@eecs.umich.edu
1563053Sstever@eecs.umich.eduenv = Environment(ENV = os.environ,  # inherit user's environment vars
1573053Sstever@eecs.umich.edu                  ROOT = ROOT,
1583053Sstever@eecs.umich.edu                  SRCDIR = SRCDIR,
1593053Sstever@eecs.umich.edu                  EXT_SRCDIR = EXT_SRCDIR)
1603053Sstever@eecs.umich.edu
1612632Sstever@eecs.umich.eduenv.SConsignFile("sconsign")
1622632Sstever@eecs.umich.edu
1632632Sstever@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but
1642632Sstever@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take
1652632Sstever@eecs.umich.edu# noticeably longer.
1662632Sstever@eecs.umich.eduif False:
1673718Sstever@eecs.umich.edu    env.TargetSignatures('content')
1683718Sstever@eecs.umich.edu
1693718Sstever@eecs.umich.edu# M5_EXT is used by isa_parser.py to find the PLY package.
1703718Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
1713718Sstever@eecs.umich.edu
1723718Sstever@eecs.umich.edu# Set up default C++ compiler flags
1733718Sstever@eecs.umich.eduenv.Append(CCFLAGS='-pipe')
1743718Sstever@eecs.umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing')
1753718Sstever@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1763718Sstever@eecs.umich.eduif sys.platform == 'cygwin':
1773718Sstever@eecs.umich.edu    # cygwin has some header file issues...
1783718Sstever@eecs.umich.edu    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1793718Sstever@eecs.umich.eduenv.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
1802634Sstever@eecs.umich.edu
1812634Sstever@eecs.umich.edu# Default libraries
1822632Sstever@eecs.umich.eduenv.Append(LIBS=['z'])
1832638Sstever@eecs.umich.edu
1842632Sstever@eecs.umich.edu# Platform-specific configuration
1852632Sstever@eecs.umich.educonf = Configure(env)
1862632Sstever@eecs.umich.edu
1872632Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
1882632Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
1892632Sstever@eecs.umich.eduif not have_fenv:
1901858SN/A    print "Warning: Header file <fenv.h> not found."
1913716Sstever@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
1922638Sstever@eecs.umich.edu
1932638Sstever@eecs.umich.edu# Check for mysql.
1942638Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config')
1952638Sstever@eecs.umich.eduhave_mysql = mysql_config != None
1962638Sstever@eecs.umich.edu
1972638Sstever@eecs.umich.edu# Check MySQL version.
1982638Sstever@eecs.umich.eduif have_mysql:
1993716Sstever@eecs.umich.edu    mysql_version = os.popen(mysql_config + ' --version').read()
2002634Sstever@eecs.umich.edu    mysql_version = mysql_version.split('.')
2012634Sstever@eecs.umich.edu    mysql_major = int(mysql_version[0])
202955SN/A    mysql_minor = int(mysql_version[1])
203955SN/A    # This version check is probably overly conservative, but it deals
204955SN/A    # with the versions we have installed.
205955SN/A    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
206955SN/A        print "Warning: MySQL v4.1 or newer required."
207955SN/A        have_mysql = False
208955SN/A
209955SN/A# Set up mysql_config commands.
2101858SN/Aif have_mysql:
2111858SN/A    mysql_config_include = mysql_config + ' --include'
2122632Sstever@eecs.umich.edu    if os.system(mysql_config_include + ' > /dev/null') != 0:
213955SN/A        # older mysql_config versions don't support --include, use
2144781Snate@binkert.org        # --cflags instead
2153643Ssaidi@eecs.umich.edu        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2163643Ssaidi@eecs.umich.edu    # This seems to work in all versions
2173643Ssaidi@eecs.umich.edu    mysql_config_libs = mysql_config + ' --libs'
2183643Ssaidi@eecs.umich.edu
2193643Ssaidi@eecs.umich.eduenv = conf.Finish()
2203643Ssaidi@eecs.umich.edu
2213643Ssaidi@eecs.umich.edu# Define the universe of supported ISAs
2224494Ssaidi@eecs.umich.eduenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2234494Ssaidi@eecs.umich.edu
2243716Sstever@eecs.umich.edu# Define the universe of supported CPU models
2251105SN/Aenv['ALL_CPU_LIST'] = ['SimpleCPU', 'FastCPU', 'FullCPU', 'AlphaFullCPU']
2262667Sstever@eecs.umich.edu
2272667Sstever@eecs.umich.edu# Sticky options get saved in the options file so they persist from
2282667Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
2292667Sstever@eecs.umich.edu# value becomes sticky).
2302667Sstever@eecs.umich.edusticky_opts = Options(args=ARGUMENTS)
2312667Sstever@eecs.umich.edusticky_opts.AddOptions(
2321869SN/A    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2331869SN/A    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2341869SN/A    # There's a bug in scons 0.96.1 that causes ListOptions with list
2351869SN/A    # values (more than one value) not to be able to be restored from
2361869SN/A    # a saved option file.  If this causes trouble then upgrade to
2371065SN/A    # scons 0.96.90 or later.
2382632Sstever@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'all', env['ALL_CPU_LIST']),
2395199Sstever@gmail.com    BoolOption('ALPHA_TLASER',
2403918Ssaidi@eecs.umich.edu               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2413918Ssaidi@eecs.umich.edu    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2423940Ssaidi@eecs.umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2434781Snate@binkert.org               False),
2444781Snate@binkert.org    BoolOption('SS_COMPATIBLE_FP',
2453918Ssaidi@eecs.umich.edu               'Make floating-point results compatible with SimpleScalar',
2464781Snate@binkert.org               False),
2474781Snate@binkert.org    BoolOption('USE_SSE2',
2483918Ssaidi@eecs.umich.edu               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2494781Snate@binkert.org               False),
2504781Snate@binkert.org    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2513940Ssaidi@eecs.umich.edu    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2523942Ssaidi@eecs.umich.edu    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2533940Ssaidi@eecs.umich.edu    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2543918Ssaidi@eecs.umich.edu    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2553918Ssaidi@eecs.umich.edu    BoolOption('BATCH', 'Use batch pool for build and tests', False),
256955SN/A    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2571858SN/A    )
2583918Ssaidi@eecs.umich.edu
2593918Ssaidi@eecs.umich.edu# Non-sticky options only apply to the current build.
2603918Ssaidi@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS)
2613918Ssaidi@eecs.umich.edunonsticky_opts.AddOptions(
2623940Ssaidi@eecs.umich.edu    BoolOption('update_ref', 'Update test reference outputs', False)
2633940Ssaidi@eecs.umich.edu    )
2643918Ssaidi@eecs.umich.edu
2653918Ssaidi@eecs.umich.edu# These options get exported to #defines in config/*.hh (see m5/SConscript).
2663918Ssaidi@eecs.umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2673918Ssaidi@eecs.umich.edu                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2683918Ssaidi@eecs.umich.edu                     'STATS_BINNING']
2693918Ssaidi@eecs.umich.edu
2703918Ssaidi@eecs.umich.edu# Define a handy 'no-op' action
2713918Ssaidi@eecs.umich.edudef no_action(target, source, env):
2723918Ssaidi@eecs.umich.edu    return 0
2733940Ssaidi@eecs.umich.edu
2743918Ssaidi@eecs.umich.eduenv.NoAction = Action(no_action, None)
2753918Ssaidi@eecs.umich.edu
2761851SN/A# libelf build is described in its own SConscript file.
2771851SN/A# SConscript-global is the build in build/libelf shared among all
2781858SN/A# configs.
2795199Sstever@gmail.comenv.SConscript('m5/libelf/SConscript-global', exports = 'env')
280955SN/A
2813053Sstever@eecs.umich.edu###################################################
2823053Sstever@eecs.umich.edu#
2833053Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers.
2843053Sstever@eecs.umich.edu#
2853053Sstever@eecs.umich.edu###################################################
2863053Sstever@eecs.umich.edu
2873053Sstever@eecs.umich.edu# This function generates a config header file that #defines the
2883053Sstever@eecs.umich.edu# option symbol to the current option setting (0 or 1).  The source
2893053Sstever@eecs.umich.edu# operands are the name of the option and a Value node containing the
2904742Sstever@eecs.umich.edu# value of the option.
2914742Sstever@eecs.umich.edudef build_config_file(target, source, env):
2923053Sstever@eecs.umich.edu    (option, value) = [s.get_contents() for s in source]
2933053Sstever@eecs.umich.edu    f = file(str(target[0]), 'w')
2943053Sstever@eecs.umich.edu    print >> f, '#define', option, value
2953053Sstever@eecs.umich.edu    f.close()
2963053Sstever@eecs.umich.edu    return None
2973053Sstever@eecs.umich.edu
2983053Sstever@eecs.umich.edu# Generate the message to be printed when building the config file.
2993053Sstever@eecs.umich.edudef build_config_file_string(target, source, env):
3003053Sstever@eecs.umich.edu    (option, value) = [s.get_contents() for s in source]
3012667Sstever@eecs.umich.edu    return "Defining %s as %s in %s." % (option, value, target[0])
3024554Sbinkertn@umich.edu
3034554Sbinkertn@umich.edu# Combine the two functions into a scons Action object.
3042667Sstever@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string)
3054554Sbinkertn@umich.edu
3064554Sbinkertn@umich.edu# The emitter munges the source & target node lists to reflect what
3074554Sbinkertn@umich.edu# we're really doing.
3084554Sbinkertn@umich.edudef config_emitter(target, source, env):
3094554Sbinkertn@umich.edu    # extract option name from Builder arg
3104554Sbinkertn@umich.edu    option = str(target[0])
3114554Sbinkertn@umich.edu    # True target is config header file
3124781Snate@binkert.org    target = os.path.join('config', option.lower() + '.hh')
3134554Sbinkertn@umich.edu    # Force value to 0/1 even if it's a Python bool
3144554Sbinkertn@umich.edu    val = int(eval(str(env[option])))
3152667Sstever@eecs.umich.edu    # Sources are option name & value (packaged in SCons Value nodes)
3164554Sbinkertn@umich.edu    return ([target], [Value(option), Value(val)])
3174554Sbinkertn@umich.edu
3184554Sbinkertn@umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action)
3194554Sbinkertn@umich.edu
3202667Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3214554Sbinkertn@umich.edu
3222667Sstever@eecs.umich.edu###################################################
3234554Sbinkertn@umich.edu#
3244554Sbinkertn@umich.edu# Define build environments for selected configurations.
3252667Sstever@eecs.umich.edu#
3262638Sstever@eecs.umich.edu###################################################
3272638Sstever@eecs.umich.edu
3282638Sstever@eecs.umich.edu# rename base env
3293716Sstever@eecs.umich.edubase_env = env
3303716Sstever@eecs.umich.edu
3311858SN/Afor build_dir in build_dirs:
3323118Sstever@eecs.umich.edu    # Make a copy of the default environment to use for this config.
3333118Sstever@eecs.umich.edu    env = base_env.Copy()
3343118Sstever@eecs.umich.edu
3353118Sstever@eecs.umich.edu    # Record what build_dir was in the environment
3363118Sstever@eecs.umich.edu    env.Append(BUILD_DIR=build_dir);
3373118Sstever@eecs.umich.edu
3383118Sstever@eecs.umich.edu    # Set env according to the build directory config.
3393118Sstever@eecs.umich.edu
3403118Sstever@eecs.umich.edu    sticky_opts.files = []
3413118Sstever@eecs.umich.edu    # Name of default options file is taken from 'default=' on command
3423118Sstever@eecs.umich.edu    # line if set, otherwise name of build dir.
3433716Sstever@eecs.umich.edu    default_options_file = os.path.join('default_options',
3443118Sstever@eecs.umich.edu                                        ARGUMENTS.get('default', build_dir))
3453118Sstever@eecs.umich.edu    if os.path.isfile(default_options_file):
3463118Sstever@eecs.umich.edu        sticky_opts.files.append(default_options_file)
3473118Sstever@eecs.umich.edu    current_options_file = os.path.join('options', build_dir)
3483118Sstever@eecs.umich.edu    if os.path.isfile(current_options_file):
3493118Sstever@eecs.umich.edu        sticky_opts.files.append(current_options_file)
3503118Sstever@eecs.umich.edu    else:
3513118Sstever@eecs.umich.edu        # if file doesn't exist, make sure at least the directory is there
3523118Sstever@eecs.umich.edu        # so we can create it later
3533716Sstever@eecs.umich.edu        opt_dir = os.path.dirname(current_options_file)
3543118Sstever@eecs.umich.edu        if not os.path.isdir(opt_dir):
3553118Sstever@eecs.umich.edu            os.mkdir(opt_dir)
3563118Sstever@eecs.umich.edu    if not sticky_opts.files:
3573118Sstever@eecs.umich.edu        print "%s: No options file found in options, using defaults." \
3583118Sstever@eecs.umich.edu              % build_dir
3593118Sstever@eecs.umich.edu
3603118Sstever@eecs.umich.edu    # Apply current option settings to env
3613118Sstever@eecs.umich.edu    sticky_opts.Update(env)
3623118Sstever@eecs.umich.edu    nonsticky_opts.Update(env)
3633118Sstever@eecs.umich.edu
3643483Ssaidi@eecs.umich.edu    # Process option settings.
3653494Ssaidi@eecs.umich.edu
3663494Ssaidi@eecs.umich.edu    if not have_fenv and env['USE_FENV']:
3673483Ssaidi@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
3683483Ssaidi@eecs.umich.edu              "forcing USE_FENV to False in", build_dir + "."
3693483Ssaidi@eecs.umich.edu        env['USE_FENV'] = False
3703053Sstever@eecs.umich.edu
3713053Sstever@eecs.umich.edu    if not env['USE_FENV']:
3723918Ssaidi@eecs.umich.edu        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
3733053Sstever@eecs.umich.edu        print "         FP results may deviate slightly from other platforms."
3743053Sstever@eecs.umich.edu
3753053Sstever@eecs.umich.edu    if env['EFENCE']:
3763053Sstever@eecs.umich.edu        env.Append(LIBS=['efence'])
3773053Sstever@eecs.umich.edu
3781858SN/A    if env['USE_MYSQL']:
3791858SN/A        if not have_mysql:
3801858SN/A            print "Warning: MySQL not available; " \
3811858SN/A                  "forcing USE_MYSQL to False in", build_dir + "."
3821858SN/A            env['USE_MYSQL'] = False
3831858SN/A        else:
3841859SN/A            print "Compiling in", build_dir, "with MySQL support."
3851858SN/A            env.ParseConfig(mysql_config_libs)
3861858SN/A            env.ParseConfig(mysql_config_include)
3871858SN/A
3881859SN/A    # Save sticky option settings back to current options file
3891859SN/A    sticky_opts.Save(current_options_file, env)
3901862SN/A
3913053Sstever@eecs.umich.edu    # Do this after we save setting back, or else we'll tack on an
3923053Sstever@eecs.umich.edu    # extra 'qdo' every time we run scons.
3933053Sstever@eecs.umich.edu    if env['BATCH']:
3943053Sstever@eecs.umich.edu        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
3951859SN/A        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
3961859SN/A
3971859SN/A    if env['USE_SSE2']:
3981859SN/A        env.Append(CCFLAGS='-msse2')
3991859SN/A
4001859SN/A    # The m5/SConscript file sets up the build rules in 'env' according
4011859SN/A    # to the configured options.  It returns a list of environments,
4021859SN/A    # one for each variant build (debug, opt, etc.)
4031862SN/A    envList = SConscript('m5/SConscript', build_dir = build_dir,
4041859SN/A                         exports = 'env', duplicate = False)
4051859SN/A
4061859SN/A    # Set up the regression tests for each build.
4071858SN/A    for e in envList:
4081858SN/A        SConscript('m5-test/SConscript',
4092139SN/A                   build_dir = os.path.join(build_dir, 'test', e.Label),
4104202Sbinkertn@umich.edu                   exports = { 'env' : e }, duplicate = False)
4114202Sbinkertn@umich.edu
4122139SN/A###################################################
4132155SN/A#
4144202Sbinkertn@umich.edu# Let SCons do its thing.  At this point SCons will use the defined
4154202Sbinkertn@umich.edu# build environments to build the requested targets.
4164202Sbinkertn@umich.edu#
4172155SN/A###################################################
4181869SN/A
4191869SN/A