SConstruct revision 2598
1955SN/A# -*- mode:python -*-
2955SN/A
310841Sandreas.sandberg@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# To build M5, you need a directory with three things:
34955SN/A# 1. A copy of this file (named SConstruct).
35955SN/A# 2. A link named 'm5' to the top of the M5 simulator source tree.
36955SN/A# 3. A link named 'ext' to the top of the M5 external source tree.
37955SN/A#
38955SN/A# Then type 'scons' to build the default configuration (see below), or
39955SN/A# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
40955SN/A# 'ALPHA_FS/m5.opt' for the optimized full-system version).
41955SN/A#
422665Ssaidi@eecs.umich.edu###################################################
432665Ssaidi@eecs.umich.edu
445863Snate@binkert.org# Python library imports
45955SN/Aimport sys
46955SN/Aimport os
47955SN/A
48955SN/A# Check for recent-enough Python and SCons versions
49955SN/AEnsurePythonVersion(2,3)
508878Ssteve.reinhardt@amd.comEnsureSConsVersion(0,96)
512632Sstever@eecs.umich.edu
528878Ssteve.reinhardt@amd.com# The absolute path to the current directory (where this file lives).
532632Sstever@eecs.umich.eduROOT = Dir('.').abspath
54955SN/A
558878Ssteve.reinhardt@amd.com# Paths to the M5 and external source trees (local symlinks).
562632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'm5')
572761Sstever@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):
612761Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
622761Sstever@eecs.umich.edu    Exit(1)
632761Sstever@eecs.umich.edu
648878Ssteve.reinhardt@amd.comif not os.path.isdir('ext'):
658878Ssteve.reinhardt@amd.com    print "Error: '%s' must be a link to the M5 external source tree." \
662761Sstever@eecs.umich.edu          % EXT_SRCDIR
672761Sstever@eecs.umich.edu    Exit(1)
682761Sstever@eecs.umich.edu
692761Sstever@eecs.umich.edu# tell python where to find m5 python code
702761Sstever@eecs.umich.edusys.path.append(os.path.join(SRCDIR, 'python'))
718878Ssteve.reinhardt@amd.com
728878Ssteve.reinhardt@amd.com###################################################
732632Sstever@eecs.umich.edu#
742632Sstever@eecs.umich.edu# Figure out which configurations to set up.
758878Ssteve.reinhardt@amd.com#
768878Ssteve.reinhardt@amd.com#
772632Sstever@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations
78955SN/A# and options, so we have to infer which ones the user wants.
79955SN/A#
80955SN/A# 1. If there are command-line targets, the configuration(s) are inferred
815863Snate@binkert.org#    from the directories of those targets.  If scons was invoked from a
825863Snate@binkert.org#    subdirectory (using 'scons -u'), those targets have to be
835863Snate@binkert.org#    interpreted relative to that subdirectory.
845863Snate@binkert.org#
855863Snate@binkert.org# 2. If there are no command-line targets, and scons was invoked from a
865863Snate@binkert.org#    subdirectory (using 'scons -u'), the configuration is inferred from
875863Snate@binkert.org#    the name of the subdirectory.
885863Snate@binkert.org#
895863Snate@binkert.org# 3. If there are no command-line targets and scons was invoked from
905863Snate@binkert.org#    the root build directory, a default configuration is used.  The
915863Snate@binkert.org#    built-in default is ALPHA_SE, but this can be overridden by setting the
928878Ssteve.reinhardt@amd.com#    M5_DEFAULT_CONFIG shell environment veriable.
935863Snate@binkert.org#
945863Snate@binkert.org# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
955863Snate@binkert.org# this can be overridden by setting the M5_DEFAULT_BINARY shell
969812Sandreas.hansson@arm.com# environment veriable.
979812Sandreas.hansson@arm.com#
985863Snate@binkert.org###################################################
999812Sandreas.hansson@arm.com
1005863Snate@binkert.org# Find default configuration & binary.
1015863Snate@binkert.orgdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
1025863Snate@binkert.orgdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1039812Sandreas.hansson@arm.com
1049812Sandreas.hansson@arm.com# Ask SCons which directory it was invoked from.  If you invoke SCons
1055863Snate@binkert.org# from a subdirectory you must use the '-u' flag.
1065863Snate@binkert.orglaunch_dir = GetLaunchDir()
1078878Ssteve.reinhardt@amd.com
1085863Snate@binkert.org# Build a list 'my_targets' of all the targets relative to ROOT.
1095863Snate@binkert.orgif launch_dir == ROOT:
1105863Snate@binkert.org    # invoked from root build dir
1116654Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
11210196SCurtis.Dunham@arm.com        # easy: use specified targets as is
113955SN/A        my_targets = COMMAND_LINE_TARGETS
1145396Ssaidi@eecs.umich.edu    else:
1155863Snate@binkert.org        # default target (ALPHA_SE/m5.debug, unless overridden)
1165863Snate@binkert.org        target = os.path.join(default_config, default_binary)
1174202Sbinkertn@umich.edu        my_targets = [target]
1185863Snate@binkert.org        Default(target)
1195863Snate@binkert.orgelse:
1205863Snate@binkert.org    # invoked from subdirectory
1215863Snate@binkert.org    if not launch_dir.startswith(ROOT):
122955SN/A        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
1236654Snate@binkert.org              (launch_dir, ROOT)
1245273Sstever@gmail.com        Exit(1)
1255871Snate@binkert.org    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
1265273Sstever@gmail.com    launch_dir = launch_dir[len(ROOT)+1:]
1276655Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
1288878Ssteve.reinhardt@amd.com        # make specified targets relative to ROOT
1296655Snate@binkert.org        my_targets = map(lambda x: os.path.join(launch_dir, x),
1306655Snate@binkert.org                         COMMAND_LINE_TARGETS)
1319219Spower.jg@gmail.com    else:
1326655Snate@binkert.org        # build default binary (m5.debug, unless overridden) using the
1335871Snate@binkert.org        # config inferred by the invocation directory (the first
1346654Snate@binkert.org        # subdirectory after ROOT)
1358947Sandreas.hansson@arm.com        target = os.path.join(launch_dir.split('/')[0], default_binary)
1365396Ssaidi@eecs.umich.edu        my_targets = [target]
1378120Sgblack@eecs.umich.edu        Default(target)
1388120Sgblack@eecs.umich.edu
1398120Sgblack@eecs.umich.edu# Normalize target paths (gets rid of '..' in the middle, etc.)
1408120Sgblack@eecs.umich.edumy_targets = map(os.path.normpath, my_targets)
1418120Sgblack@eecs.umich.edu
1428120Sgblack@eecs.umich.edu# Generate a list of the unique configs that the collected targets reference.
1438120Sgblack@eecs.umich.edubuild_dirs = []
1448120Sgblack@eecs.umich.edufor t in my_targets:
1458879Ssteve.reinhardt@amd.com    dir = t.split('/')[0]
1468879Ssteve.reinhardt@amd.com    if dir not in build_dirs:
1478879Ssteve.reinhardt@amd.com        build_dirs.append(dir)
1488879Ssteve.reinhardt@amd.com
1498879Ssteve.reinhardt@amd.com###################################################
1508879Ssteve.reinhardt@amd.com#
1518879Ssteve.reinhardt@amd.com# Set up the default build environment.  This environment is copied
1528879Ssteve.reinhardt@amd.com# and modified according to each selected configuration.
1538879Ssteve.reinhardt@amd.com#
1548879Ssteve.reinhardt@amd.com###################################################
1558879Ssteve.reinhardt@amd.com
1568879Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
1578879Ssteve.reinhardt@amd.com                  ROOT = ROOT,
1588120Sgblack@eecs.umich.edu                  SRCDIR = SRCDIR,
1598120Sgblack@eecs.umich.edu                  EXT_SRCDIR = EXT_SRCDIR)
1608120Sgblack@eecs.umich.edu
1618120Sgblack@eecs.umich.eduenv.SConsignFile("sconsign")
1628120Sgblack@eecs.umich.edu
1638120Sgblack@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but
1648120Sgblack@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take
1658120Sgblack@eecs.umich.edu# noticeably longer.
1668120Sgblack@eecs.umich.eduif False:
1678120Sgblack@eecs.umich.edu    env.TargetSignatures('content')
1688120Sgblack@eecs.umich.edu
1698120Sgblack@eecs.umich.edu# M5_EXT is used by isa_parser.py to find the PLY package.
1708120Sgblack@eecs.umich.eduenv.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
1718120Sgblack@eecs.umich.edu
1728879Ssteve.reinhardt@amd.com# Set up default C++ compiler flags
1738879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-pipe')
1748879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-fno-strict-aliasing')
1758879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
17610458Sandreas.hansson@arm.comif sys.platform == 'cygwin':
17710458Sandreas.hansson@arm.com    # cygwin has some header file issues...
17810458Sandreas.hansson@arm.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1798879Ssteve.reinhardt@amd.comenv.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
1808879Ssteve.reinhardt@amd.com
1818879Ssteve.reinhardt@amd.com# Default libraries
1828879Ssteve.reinhardt@amd.comenv.Append(LIBS=['z'])
1839227Sandreas.hansson@arm.com
1849227Sandreas.hansson@arm.com# Platform-specific configuration
1858879Ssteve.reinhardt@amd.comconf = Configure(env)
1868879Ssteve.reinhardt@amd.com
1878879Ssteve.reinhardt@amd.com# Check for <fenv.h> (C99 FP environment control)
1888879Ssteve.reinhardt@amd.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
18910453SAndrew.Bardsley@arm.comif not have_fenv:
19010453SAndrew.Bardsley@arm.com    print "Warning: Header file <fenv.h> not found."
19110453SAndrew.Bardsley@arm.com    print "         This host has no IEEE FP rounding mode control."
19210456SCurtis.Dunham@arm.com
19310456SCurtis.Dunham@arm.com# Check for mysql.
19410456SCurtis.Dunham@arm.commysql_config = WhereIs('mysql_config')
19510457Sandreas.hansson@arm.comhave_mysql = mysql_config != None
19610457Sandreas.hansson@arm.com
1978120Sgblack@eecs.umich.edu# Check MySQL version.
1988947Sandreas.hansson@arm.comif have_mysql:
1997816Ssteve.reinhardt@amd.com    mysql_version = os.popen(mysql_config + ' --version').read()
2005871Snate@binkert.org    mysql_version = mysql_version.split('.')
2015871Snate@binkert.org    mysql_major = int(mysql_version[0])
2026121Snate@binkert.org    mysql_minor = int(mysql_version[1])
2035871Snate@binkert.org    # This version check is probably overly conservative, but it deals
2045871Snate@binkert.org    # with the versions we have installed.
2059926Sstan.czerniawski@arm.com    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2069926Sstan.czerniawski@arm.com        print "Warning: MySQL v4.1 or newer required."
2079119Sandreas.hansson@arm.com        have_mysql = False
20810068Sandreas.hansson@arm.com
20910068Sandreas.hansson@arm.com# Set up mysql_config commands.
210955SN/Aif have_mysql:
2119416SAndreas.Sandberg@ARM.com    mysql_config_include = mysql_config + ' --include'
21211212Sjoseph.gross@amd.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
21311212Sjoseph.gross@amd.com        # older mysql_config versions don't support --include, use
21411212Sjoseph.gross@amd.com        # --cflags instead
21511212Sjoseph.gross@amd.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
21611212Sjoseph.gross@amd.com    # This seems to work in all versions
2179416SAndreas.Sandberg@ARM.com    mysql_config_libs = mysql_config + ' --libs'
2189416SAndreas.Sandberg@ARM.com
2195871Snate@binkert.orgenv = conf.Finish()
22010584Sandreas.hansson@arm.com
2219416SAndreas.Sandberg@ARM.com# Define the universe of supported ISAs
2229416SAndreas.Sandberg@ARM.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2235871Snate@binkert.org
224955SN/A# Define the universe of supported CPU models
22510671Sandreas.hansson@arm.comenv['ALL_CPU_LIST'] = ['SimpleCPU', 'FastCPU', 'FullCPU', 'AlphaFullCPU']
22610671Sandreas.hansson@arm.com
22710671Sandreas.hansson@arm.com# Sticky options get saved in the options file so they persist from
22810671Sandreas.hansson@arm.com# one invocation to the next (unless overridden, in which case the new
2298881Smarc.orr@gmail.com# value becomes sticky).
2306121Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS)
2316121Snate@binkert.orgsticky_opts.AddOptions(
2321533SN/A    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2339239Sandreas.hansson@arm.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2349239Sandreas.hansson@arm.com    # There's a bug in scons 0.96.1 that causes ListOptions with list
2359239Sandreas.hansson@arm.com    # values (more than one value) not to be able to be restored from
2369239Sandreas.hansson@arm.com    # a saved option file.  If this causes trouble then upgrade to
2379239Sandreas.hansson@arm.com    # scons 0.96.90 or later.
2389239Sandreas.hansson@arm.com    ListOption('CPU_MODELS', 'CPU models', 'all', env['ALL_CPU_LIST']),
2399239Sandreas.hansson@arm.com    BoolOption('ALPHA_TLASER',
2409239Sandreas.hansson@arm.com               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2419239Sandreas.hansson@arm.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2429239Sandreas.hansson@arm.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2439239Sandreas.hansson@arm.com               False),
2449239Sandreas.hansson@arm.com    BoolOption('SS_COMPATIBLE_FP',
2456655Snate@binkert.org               'Make floating-point results compatible with SimpleScalar',
2466655Snate@binkert.org               False),
2476655Snate@binkert.org    BoolOption('USE_SSE2',
2486655Snate@binkert.org               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2495871Snate@binkert.org               False),
2505871Snate@binkert.org    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2515863Snate@binkert.org    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2525871Snate@binkert.org    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2538878Ssteve.reinhardt@amd.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2545871Snate@binkert.org    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2555871Snate@binkert.org    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2565871Snate@binkert.org    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2575863Snate@binkert.org    )
2586121Snate@binkert.org
2595863Snate@binkert.org# Non-sticky options only apply to the current build.
2605871Snate@binkert.orgnonsticky_opts = Options(args=ARGUMENTS)
2618336Ssteve.reinhardt@amd.comnonsticky_opts.AddOptions(
2628336Ssteve.reinhardt@amd.com    BoolOption('update_ref', 'Update test reference outputs', False)
2638336Ssteve.reinhardt@amd.com    )
2648336Ssteve.reinhardt@amd.com
2654678Snate@binkert.org# These options get exported to #defines in config/*.hh (see m5/SConscript).
2668336Ssteve.reinhardt@amd.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2678336Ssteve.reinhardt@amd.com                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2688336Ssteve.reinhardt@amd.com                     'STATS_BINNING']
2694678Snate@binkert.org
2704678Snate@binkert.org# Define a handy 'no-op' action
2714678Snate@binkert.orgdef no_action(target, source, env):
2724678Snate@binkert.org    return 0
2737827Snate@binkert.org
2747827Snate@binkert.orgenv.NoAction = Action(no_action, None)
2758336Ssteve.reinhardt@amd.com
2764678Snate@binkert.org# libelf build is described in its own SConscript file.
2778336Ssteve.reinhardt@amd.com# SConscript-global is the build in build/libelf shared among all
2788336Ssteve.reinhardt@amd.com# configs.
2798336Ssteve.reinhardt@amd.comenv.SConscript('m5/libelf/SConscript-global', exports = 'env')
2808336Ssteve.reinhardt@amd.com
2818336Ssteve.reinhardt@amd.com###################################################
2828336Ssteve.reinhardt@amd.com#
2835871Snate@binkert.org# Define a SCons builder for configuration flag headers.
2845871Snate@binkert.org#
2858336Ssteve.reinhardt@amd.com###################################################
2868336Ssteve.reinhardt@amd.com
2878336Ssteve.reinhardt@amd.com# This function generates a config header file that #defines the
2888336Ssteve.reinhardt@amd.com# option symbol to the current option setting (0 or 1).  The source
2898336Ssteve.reinhardt@amd.com# operands are the name of the option and a Value node containing the
2905871Snate@binkert.org# value of the option.
2918336Ssteve.reinhardt@amd.comdef build_config_file(target, source, env):
2928336Ssteve.reinhardt@amd.com    (option, value) = [s.get_contents() for s in source]
2938336Ssteve.reinhardt@amd.com    f = file(str(target[0]), 'w')
2948336Ssteve.reinhardt@amd.com    print >> f, '#define', option, value
2958336Ssteve.reinhardt@amd.com    f.close()
2964678Snate@binkert.org    return None
2975871Snate@binkert.org
2984678Snate@binkert.org# Generate the message to be printed when building the config file.
2998336Ssteve.reinhardt@amd.comdef build_config_file_string(target, source, env):
3008336Ssteve.reinhardt@amd.com    (option, value) = [s.get_contents() for s in source]
3018336Ssteve.reinhardt@amd.com    return "Defining %s as %s in %s." % (option, value, target[0])
3028336Ssteve.reinhardt@amd.com
3038336Ssteve.reinhardt@amd.com# Combine the two functions into a scons Action object.
3048336Ssteve.reinhardt@amd.comconfig_action = Action(build_config_file, build_config_file_string)
3058336Ssteve.reinhardt@amd.com
3068336Ssteve.reinhardt@amd.com# The emitter munges the source & target node lists to reflect what
3078336Ssteve.reinhardt@amd.com# we're really doing.
3088336Ssteve.reinhardt@amd.comdef config_emitter(target, source, env):
3098336Ssteve.reinhardt@amd.com    # extract option name from Builder arg
3108336Ssteve.reinhardt@amd.com    option = str(target[0])
3118336Ssteve.reinhardt@amd.com    # True target is config header file
3128336Ssteve.reinhardt@amd.com    target = os.path.join('config', option.lower() + '.hh')
3138336Ssteve.reinhardt@amd.com    # Force value to 0/1 even if it's a Python bool
3148336Ssteve.reinhardt@amd.com    val = int(eval(str(env[option])))
3158336Ssteve.reinhardt@amd.com    # Sources are option name & value (packaged in SCons Value nodes)
3165871Snate@binkert.org    return ([target], [Value(option), Value(val)])
3176121Snate@binkert.org
318955SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
319955SN/A
3202632Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3212632Sstever@eecs.umich.edu
322955SN/A###################################################
323955SN/A#
324955SN/A# Define build environments for selected configurations.
325955SN/A#
3268878Ssteve.reinhardt@amd.com###################################################
327955SN/A
3282632Sstever@eecs.umich.edu# rename base env
3292632Sstever@eecs.umich.edubase_env = env
3302632Sstever@eecs.umich.edu
3312632Sstever@eecs.umich.eduhelp_text = '''
3322632Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)]
3332632Sstever@eecs.umich.edu
3342632Sstever@eecs.umich.edu'''
3358268Ssteve.reinhardt@amd.com
3368268Ssteve.reinhardt@amd.comfor build_dir in build_dirs:
3378268Ssteve.reinhardt@amd.com    # Make a copy of the default environment to use for this config.
3388268Ssteve.reinhardt@amd.com    env = base_env.Copy()
3398268Ssteve.reinhardt@amd.com
3408268Ssteve.reinhardt@amd.com    # Record what build_dir was in the environment
3418268Ssteve.reinhardt@amd.com    env.Append(BUILD_DIR=build_dir);
3422632Sstever@eecs.umich.edu
3432632Sstever@eecs.umich.edu    # Set env according to the build directory config.
3442632Sstever@eecs.umich.edu
3452632Sstever@eecs.umich.edu    sticky_opts.files = []
3468268Ssteve.reinhardt@amd.com    # Name of default options file is taken from 'default=' on command
3472632Sstever@eecs.umich.edu    # line if set, otherwise name of build dir.
3488268Ssteve.reinhardt@amd.com    default_options_file = os.path.join('default_options',
3498268Ssteve.reinhardt@amd.com                                        ARGUMENTS.get('default', build_dir))
3508268Ssteve.reinhardt@amd.com    if os.path.isfile(default_options_file):
3518268Ssteve.reinhardt@amd.com        sticky_opts.files.append(default_options_file)
3523718Sstever@eecs.umich.edu    current_options_file = os.path.join('options', build_dir)
3532634Sstever@eecs.umich.edu    if os.path.isfile(current_options_file):
3542634Sstever@eecs.umich.edu        sticky_opts.files.append(current_options_file)
3555863Snate@binkert.org    else:
3562638Sstever@eecs.umich.edu        # if file doesn't exist, make sure at least the directory is there
3578268Ssteve.reinhardt@amd.com        # so we can create it later
3582632Sstever@eecs.umich.edu        opt_dir = os.path.dirname(current_options_file)
3592632Sstever@eecs.umich.edu        if not os.path.isdir(opt_dir):
3602632Sstever@eecs.umich.edu            os.mkdir(opt_dir)
3612632Sstever@eecs.umich.edu    if not sticky_opts.files:
3622632Sstever@eecs.umich.edu        print "%s: No options file found in options, using defaults." \
3631858SN/A              % build_dir
3643716Sstever@eecs.umich.edu
3652638Sstever@eecs.umich.edu    # Apply current option settings to env
3662638Sstever@eecs.umich.edu    sticky_opts.Update(env)
3672638Sstever@eecs.umich.edu    nonsticky_opts.Update(env)
3682638Sstever@eecs.umich.edu
3692638Sstever@eecs.umich.edu    help_text += "Sticky options for %s:\n" % build_dir \
3702638Sstever@eecs.umich.edu                 + sticky_opts.GenerateHelpText(env) \
3712638Sstever@eecs.umich.edu                 + "\nNon-sticky options for %s:\n" % build_dir \
3725863Snate@binkert.org                 + nonsticky_opts.GenerateHelpText(env)
3735863Snate@binkert.org
3745863Snate@binkert.org    # Process option settings.
375955SN/A
3765341Sstever@gmail.com    if not have_fenv and env['USE_FENV']:
3775341Sstever@gmail.com        print "Warning: <fenv.h> not available; " \
3785863Snate@binkert.org              "forcing USE_FENV to False in", build_dir + "."
3797756SAli.Saidi@ARM.com        env['USE_FENV'] = False
3805341Sstever@gmail.com
3816121Snate@binkert.org    if not env['USE_FENV']:
3824494Ssaidi@eecs.umich.edu        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
3836121Snate@binkert.org        print "         FP results may deviate slightly from other platforms."
3841105SN/A
3852667Sstever@eecs.umich.edu    if env['EFENCE']:
3862667Sstever@eecs.umich.edu        env.Append(LIBS=['efence'])
3872667Sstever@eecs.umich.edu
3882667Sstever@eecs.umich.edu    if env['USE_MYSQL']:
3896121Snate@binkert.org        if not have_mysql:
3902667Sstever@eecs.umich.edu            print "Warning: MySQL not available; " \
3915341Sstever@gmail.com                  "forcing USE_MYSQL to False in", build_dir + "."
3925863Snate@binkert.org            env['USE_MYSQL'] = False
3935341Sstever@gmail.com        else:
3945341Sstever@gmail.com            print "Compiling in", build_dir, "with MySQL support."
3955341Sstever@gmail.com            env.ParseConfig(mysql_config_libs)
3968120Sgblack@eecs.umich.edu            env.ParseConfig(mysql_config_include)
3975341Sstever@gmail.com
3988120Sgblack@eecs.umich.edu    # Save sticky option settings back to current options file
3995341Sstever@gmail.com    sticky_opts.Save(current_options_file, env)
4008120Sgblack@eecs.umich.edu
4016121Snate@binkert.org    # Do this after we save setting back, or else we'll tack on an
4026121Snate@binkert.org    # extra 'qdo' every time we run scons.
4038980Ssteve.reinhardt@amd.com    if env['BATCH']:
4049396Sandreas.hansson@arm.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4055397Ssaidi@eecs.umich.edu        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4065397Ssaidi@eecs.umich.edu
4077727SAli.Saidi@ARM.com    if env['USE_SSE2']:
4088268Ssteve.reinhardt@amd.com        env.Append(CCFLAGS='-msse2')
4096168Snate@binkert.org
4105341Sstever@gmail.com    # The m5/SConscript file sets up the build rules in 'env' according
4118120Sgblack@eecs.umich.edu    # to the configured options.  It returns a list of environments,
4128120Sgblack@eecs.umich.edu    # one for each variant build (debug, opt, etc.)
4138120Sgblack@eecs.umich.edu    envList = SConscript('m5/SConscript', build_dir = build_dir,
4146814Sgblack@eecs.umich.edu                         exports = 'env', duplicate = False)
4155863Snate@binkert.org
4168120Sgblack@eecs.umich.edu    # Set up the regression tests for each build.
4175341Sstever@gmail.com    for e in envList:
4185863Snate@binkert.org        SConscript('m5-test/SConscript',
4198268Ssteve.reinhardt@amd.com                   build_dir = os.path.join(build_dir, 'test', e.Label),
4206121Snate@binkert.org                   exports = { 'env' : e }, duplicate = False)
4216121Snate@binkert.org
4228268Ssteve.reinhardt@amd.comHelp(help_text)
4235742Snate@binkert.org
4245742Snate@binkert.org###################################################
4255341Sstever@gmail.com#
4265742Snate@binkert.org# Let SCons do its thing.  At this point SCons will use the defined
4275742Snate@binkert.org# build environments to build the requested targets.
4285341Sstever@gmail.com#
4296017Snate@binkert.org###################################################
4306121Snate@binkert.org
4316017Snate@binkert.org