SConstruct revision 2635
17586SAli.Saidi@arm.com# -*- mode:python -*-
27586SAli.Saidi@arm.com
37586SAli.Saidi@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
47586SAli.Saidi@arm.com# All rights reserved.
57586SAli.Saidi@arm.com#
67586SAli.Saidi@arm.com# Redistribution and use in source and binary forms, with or without
77586SAli.Saidi@arm.com# modification, are permitted provided that the following conditions are
87586SAli.Saidi@arm.com# met: redistributions of source code must retain the above copyright
97586SAli.Saidi@arm.com# notice, this list of conditions and the following disclaimer;
107586SAli.Saidi@arm.com# redistributions in binary form must reproduce the above copyright
117586SAli.Saidi@arm.com# notice, this list of conditions and the following disclaimer in the
127586SAli.Saidi@arm.com# documentation and/or other materials provided with the distribution;
137905SBrad.Beckmann@amd.com# neither the name of the copyright holders nor the names of its
145323Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
152934Sktlim@umich.edu# this software without specific prior written permission.
162934Sktlim@umich.edu#
172934Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182934Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192934Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202934Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212934Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222934Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232934Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242934Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252934Sktlim@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262934Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272934Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282934Sktlim@umich.edu
292934Sktlim@umich.edu###################################################
302934Sktlim@umich.edu#
312934Sktlim@umich.edu# SCons top-level build description (SConstruct) file.
322934Sktlim@umich.edu#
332934Sktlim@umich.edu# While in this directory ('m5'), just type 'scons' to build the default
342934Sktlim@umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
352934Sktlim@umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
362934Sktlim@umich.edu# the optimized full-system version).
372934Sktlim@umich.edu#
382934Sktlim@umich.edu# You can build M5 in a different directory as long as there is a
392934Sktlim@umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
402934Sktlim@umich.edu# expdects that all configs under the same build directory are being
412934Sktlim@umich.edu# built for the same host system.
422934Sktlim@umich.edu#
432995Ssaidi@eecs.umich.edu# Examples:
442934Sktlim@umich.edu#   These two commands are equivalent.  The '-u' option tells scons to
452934Sktlim@umich.edu#   search up the directory tree for this SConstruct file.
462934Sktlim@umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
472934Sktlim@umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
482934Sktlim@umich.edu#   These two commands are equivalent and demonstrate building in a
492934Sktlim@umich.edu#   directory outside of the source tree.  The '-C' option tells scons
502934Sktlim@umich.edu#   to chdir to the specified directory to find this SConstruct file.
512934Sktlim@umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
526122SSteve.Reinhardt@amd.com#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
536122SSteve.Reinhardt@amd.com#
546122SSteve.Reinhardt@amd.com# You can use 'scons -H' to print scons options.  If you're in this
556122SSteve.Reinhardt@amd.com# 'm5' directory (or use -u or -C to tell scons where to find this
566122SSteve.Reinhardt@amd.com# file), you can use 'scons -h' to print all the M5-specific build
574520Ssaidi@eecs.umich.edu# options as well.
584520Ssaidi@eecs.umich.edu#
594982Ssaidi@eecs.umich.edu###################################################
604520Ssaidi@eecs.umich.edu
614520Ssaidi@eecs.umich.edu# Python library imports
622934Sktlim@umich.eduimport sys
632934Sktlim@umich.eduimport os
643005Sstever@eecs.umich.edu
653005Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions
663304Sstever@eecs.umich.eduEnsurePythonVersion(2,3)
672995Ssaidi@eecs.umich.eduEnsureSConsVersion(0,96,91)
682934Sktlim@umich.edu
696122SSteve.Reinhardt@amd.com# The absolute path to the current directory (where this file lives).
704965Ssaidi@eecs.umich.eduROOT = Dir('.').abspath
715266Sksewell@umich.edu
722934Sktlim@umich.edu# Paths to the M5 and external source trees.
732934Sktlim@umich.eduSRCDIR = os.path.join(ROOT, 'src')
742934Sktlim@umich.edu
752934Sktlim@umich.edu# tell python where to find m5 python code
762934Sktlim@umich.edusys.path.append(os.path.join(ROOT, 'src/python'))
772995Ssaidi@eecs.umich.edu
782934Sktlim@umich.edu###################################################
792934Sktlim@umich.edu#
802934Sktlim@umich.edu# Figure out which configurations to set up based on the path(s) of
812934Sktlim@umich.edu# the target(s).
822934Sktlim@umich.edu#
832995Ssaidi@eecs.umich.edu###################################################
842934Sktlim@umich.edu
852934Sktlim@umich.edu# Find default configuration & binary.
862953Sktlim@umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
875478Snate@binkert.org
882934Sktlim@umich.edu# Ask SCons which directory it was invoked from.
893449Shsul@eecs.umich.edulaunch_dir = GetLaunchDir()
902934Sktlim@umich.edu
912934Sktlim@umich.edu# Make targets relative to invocation directory
922934Sktlim@umich.eduabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
932934Sktlim@umich.edu                  BUILD_TARGETS)
942934Sktlim@umich.edu
957014SBrad.Beckmann@amd.com# helper function: find last occurrence of element in list
966765SBrad.Beckmann@amd.comdef rfind(l, elt, offs = -1):
976765SBrad.Beckmann@amd.com    for i in range(len(l)+offs, 0, -1):
986765SBrad.Beckmann@amd.com        if l[i] == elt:
996765SBrad.Beckmann@amd.com            return i
1006765SBrad.Beckmann@amd.com    raise ValueError, "element not found"
1017014SBrad.Beckmann@amd.com
1027014SBrad.Beckmann@amd.com# Each target must have 'build' in the interior of the path; the
1036765SBrad.Beckmann@amd.com# directory below this will determine the build parameters.  For
1046765SBrad.Beckmann@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1056765SBrad.Beckmann@amd.com# recognize that ALPHA_SE specifies the configuration because it
1066765SBrad.Beckmann@amd.com# follow 'build' in the bulid path.
1076765SBrad.Beckmann@amd.com
1086765SBrad.Beckmann@amd.com# Generate a list of the unique build roots and configs that the
1096765SBrad.Beckmann@amd.com# collected targets reference.
1106893SBrad.Beckmann@amd.combuild_paths = []
1116893SBrad.Beckmann@amd.combuild_roots = []
1126893SBrad.Beckmann@amd.comfor t in abs_targets:
1136893SBrad.Beckmann@amd.com    path_dirs = t.split('/')
1146893SBrad.Beckmann@amd.com    try:
1156893SBrad.Beckmann@amd.com        build_top = rfind(path_dirs, 'build', -2)
1167014SBrad.Beckmann@amd.com    except:
1176893SBrad.Beckmann@amd.com        print "Error: no non-leaf 'build' dir found on target path", t
1186765SBrad.Beckmann@amd.com        Exit(1)
1196765SBrad.Beckmann@amd.com    build_root = os.path.join('/',*path_dirs[:build_top+1])
1206765SBrad.Beckmann@amd.com    if build_root not in build_roots:
1216765SBrad.Beckmann@amd.com        build_roots.append(build_root)
1226765SBrad.Beckmann@amd.com    build_path = os.path.join('/',*path_dirs[:build_top+2])
1236765SBrad.Beckmann@amd.com    if build_path not in build_paths:
1246765SBrad.Beckmann@amd.com        build_paths.append(build_path)
1256765SBrad.Beckmann@amd.com
1266765SBrad.Beckmann@amd.com###################################################
1276893SBrad.Beckmann@amd.com#
1287633SBrad.Beckmann@amd.com# Set up the default build environment.  This environment is copied
1297633SBrad.Beckmann@amd.com# and modified according to each selected configuration.
1306893SBrad.Beckmann@amd.com#
1317633SBrad.Beckmann@amd.com###################################################
1326765SBrad.Beckmann@amd.com
1336765SBrad.Beckmann@amd.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
1346765SBrad.Beckmann@amd.com                  ROOT = ROOT,
1356765SBrad.Beckmann@amd.com                  SRCDIR = SRCDIR)
1366765SBrad.Beckmann@amd.com
1376765SBrad.Beckmann@amd.comenv.SConsignFile("sconsign")
1386765SBrad.Beckmann@amd.com
1396765SBrad.Beckmann@amd.com# I waffle on this setting... it does avoid a few painful but
1406765SBrad.Beckmann@amd.com# unnecessary builds, but it also seems to make trivial builds take
1416765SBrad.Beckmann@amd.com# noticeably longer.
1426765SBrad.Beckmann@amd.comif False:
1436765SBrad.Beckmann@amd.com    env.TargetSignatures('content')
1446765SBrad.Beckmann@amd.com
1453584Ssaidi@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
1464486Sbinkertn@umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1474486Sbinkertn@umich.edu
1484486Sbinkertn@umich.edu# Set up default C++ compiler flags
1494486Sbinkertn@umich.eduenv.Append(CCFLAGS='-pipe')
1504486Sbinkertn@umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing')
1514486Sbinkertn@umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1524486Sbinkertn@umich.eduif sys.platform == 'cygwin':
1533584Ssaidi@eecs.umich.edu    # cygwin has some header file issues...
1543584Ssaidi@eecs.umich.edu    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1553584Ssaidi@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')])
1563584Ssaidi@eecs.umich.edu
1573584Ssaidi@eecs.umich.edu# Default libraries
1583743Sgblack@eecs.umich.eduenv.Append(LIBS=['z'])
1596122SSteve.Reinhardt@amd.com
1604972Ssaidi@eecs.umich.edu# Platform-specific configuration
1613743Sgblack@eecs.umich.educonf = Configure(env)
1624104Ssaidi@eecs.umich.edu
1633743Sgblack@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
1643823Ssaidi@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
1653814Ssaidi@eecs.umich.eduif not have_fenv:
1663743Sgblack@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
1673743Sgblack@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
1683584Ssaidi@eecs.umich.edu
1693814Ssaidi@eecs.umich.edu# Check for mysql.
1703584Ssaidi@eecs.umich.edumysql_config = WhereIs('mysql_config')
1713745Sgblack@eecs.umich.eduhave_mysql = mysql_config != None
1723745Sgblack@eecs.umich.edu
1733745Sgblack@eecs.umich.edu# Check MySQL version.
1743584Ssaidi@eecs.umich.eduif have_mysql:
1753898Ssaidi@eecs.umich.edu    mysql_version = os.popen(mysql_config + ' --version').read()
1763898Ssaidi@eecs.umich.edu    mysql_version = mysql_version.split('.')
1773898Ssaidi@eecs.umich.edu    mysql_major = int(mysql_version[0])
1784103Ssaidi@eecs.umich.edu    mysql_minor = int(mysql_version[1])
1794103Ssaidi@eecs.umich.edu    # This version check is probably overly conservative, but it deals
1804103Ssaidi@eecs.umich.edu    # with the versions we have installed.
1813745Sgblack@eecs.umich.edu    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
1823745Sgblack@eecs.umich.edu        print "Warning: MySQL v4.1 or newer required."
1833745Sgblack@eecs.umich.edu        have_mysql = False
1843584Ssaidi@eecs.umich.edu
1853584Ssaidi@eecs.umich.edu# Set up mysql_config commands.
1863584Ssaidi@eecs.umich.eduif have_mysql:
1877586SAli.Saidi@arm.com    mysql_config_include = mysql_config + ' --include'
1887586SAli.Saidi@arm.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
1897586SAli.Saidi@arm.com        # older mysql_config versions don't support --include, use
1907586SAli.Saidi@arm.com        # --cflags instead
1917586SAli.Saidi@arm.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
1927586SAli.Saidi@arm.com    # This seems to work in all versions
1937586SAli.Saidi@arm.com    mysql_config_libs = mysql_config + ' --libs'
1947586SAli.Saidi@arm.com
1957586SAli.Saidi@arm.comenv = conf.Finish()
1967586SAli.Saidi@arm.com
1977586SAli.Saidi@arm.com# Define the universe of supported ISAs
1987586SAli.Saidi@arm.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
1997586SAli.Saidi@arm.com
2007586SAli.Saidi@arm.com# Define the universe of supported CPU models
2017586SAli.Saidi@arm.comenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2027586SAli.Saidi@arm.com                       'FastCPU', 'FullCPU', 'AlphaFullCPU']
2037586SAli.Saidi@arm.com
2047730SAli.Saidi@ARM.com# Sticky options get saved in the options file so they persist from
2057730SAli.Saidi@ARM.com# one invocation to the next (unless overridden, in which case the new
2067586SAli.Saidi@arm.com# value becomes sticky).
2077586SAli.Saidi@arm.comsticky_opts = Options(args=ARGUMENTS)
2087586SAli.Saidi@arm.comsticky_opts.AddOptions(
2097730SAli.Saidi@ARM.com    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2107586SAli.Saidi@arm.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2117586SAli.Saidi@arm.com    # There's a bug in scons 0.96.1 that causes ListOptions with list
2127586SAli.Saidi@arm.com    # values (more than one value) not to be able to be restored from
2137750SAli.Saidi@ARM.com    # a saved option file.  If this causes trouble then upgrade to
2147750SAli.Saidi@ARM.com    # scons 0.96.90 or later.
2157750SAli.Saidi@ARM.com    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2167750SAli.Saidi@ARM.com               env['ALL_CPU_LIST']),
2177750SAli.Saidi@ARM.com    BoolOption('ALPHA_TLASER',
2187750SAli.Saidi@ARM.com               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2197750SAli.Saidi@ARM.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2207750SAli.Saidi@ARM.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2217750SAli.Saidi@ARM.com               False),
2227750SAli.Saidi@ARM.com    BoolOption('SS_COMPATIBLE_FP',
2237586SAli.Saidi@arm.com               'Make floating-point results compatible with SimpleScalar',
2247586SAli.Saidi@arm.com               False),
2257586SAli.Saidi@arm.com    BoolOption('USE_SSE2',
2267586SAli.Saidi@arm.com               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2277586SAli.Saidi@arm.com               False),
2287586SAli.Saidi@arm.com    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2297586SAli.Saidi@arm.com    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2307586SAli.Saidi@arm.com    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2317586SAli.Saidi@arm.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2327586SAli.Saidi@arm.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2337586SAli.Saidi@arm.com    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2347586SAli.Saidi@arm.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2357586SAli.Saidi@arm.com    )
2367586SAli.Saidi@arm.com
2377586SAli.Saidi@arm.com# Non-sticky options only apply to the current build.
2387586SAli.Saidi@arm.comnonsticky_opts = Options(args=ARGUMENTS)
2397586SAli.Saidi@arm.comnonsticky_opts.AddOptions(
2407586SAli.Saidi@arm.com    BoolOption('update_ref', 'Update test reference outputs', False)
2417730SAli.Saidi@ARM.com    )
2427730SAli.Saidi@ARM.com
2437730SAli.Saidi@ARM.com# These options get exported to #defines in config/*.hh (see m5/SConscript).
2447730SAli.Saidi@ARM.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2457586SAli.Saidi@arm.com                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2467586SAli.Saidi@arm.com                     'STATS_BINNING']
2477586SAli.Saidi@arm.com
2487586SAli.Saidi@arm.com# Define a handy 'no-op' action
2495222Sksewell@umich.edudef no_action(target, source, env):
2505222Sksewell@umich.edu    return 0
2515222Sksewell@umich.edu
2525222Sksewell@umich.eduenv.NoAction = Action(no_action, None)
2535222Sksewell@umich.edu
2545222Sksewell@umich.edu###################################################
2555222Sksewell@umich.edu#
2565222Sksewell@umich.edu# Define a SCons builder for configuration flag headers.
2575222Sksewell@umich.edu#
2585222Sksewell@umich.edu###################################################
2595222Sksewell@umich.edu
2605222Sksewell@umich.edu# This function generates a config header file that #defines the
2616122SSteve.Reinhardt@amd.com# option symbol to the current option setting (0 or 1).  The source
2625222Sksewell@umich.edu# operands are the name of the option and a Value node containing the
2635222Sksewell@umich.edu# value of the option.
2645222Sksewell@umich.edudef build_config_file(target, source, env):
2655222Sksewell@umich.edu    (option, value) = [s.get_contents() for s in source]
2665222Sksewell@umich.edu    f = file(str(target[0]), 'w')
2675222Sksewell@umich.edu    print >> f, '#define', option, value
2685222Sksewell@umich.edu    f.close()
2695222Sksewell@umich.edu    return None
2705222Sksewell@umich.edu
2715222Sksewell@umich.edu# Generate the message to be printed when building the config file.
2725222Sksewell@umich.edudef build_config_file_string(target, source, env):
2735222Sksewell@umich.edu    (option, value) = [s.get_contents() for s in source]
2745222Sksewell@umich.edu    return "Defining %s as %s in %s." % (option, value, target[0])
2755222Sksewell@umich.edu
2765222Sksewell@umich.edu# Combine the two functions into a scons Action object.
2775222Sksewell@umich.educonfig_action = Action(build_config_file, build_config_file_string)
2785222Sksewell@umich.edu
2795478Snate@binkert.org# The emitter munges the source & target node lists to reflect what
2805222Sksewell@umich.edu# we're really doing.
2815222Sksewell@umich.edudef config_emitter(target, source, env):
2825222Sksewell@umich.edu    # extract option name from Builder arg
2835222Sksewell@umich.edu    option = str(target[0])
2845222Sksewell@umich.edu    # True target is config header file
2855222Sksewell@umich.edu    target = os.path.join('config', option.lower() + '.hh')
2865323Sgblack@eecs.umich.edu    # Force value to 0/1 even if it's a Python bool
2875357Sgblack@eecs.umich.edu    val = int(eval(str(env[option])))
2885323Sgblack@eecs.umich.edu    # Sources are option name & value (packaged in SCons Value nodes)
2895323Sgblack@eecs.umich.edu    return ([target], [Value(option), Value(val)])
2907905SBrad.Beckmann@amd.com
2917905SBrad.Beckmann@amd.comconfig_builder = Builder(emitter = config_emitter, action = config_action)
2927905SBrad.Beckmann@amd.com
2937905SBrad.Beckmann@amd.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
2947905SBrad.Beckmann@amd.com
2957905SBrad.Beckmann@amd.com# base help text
2967905SBrad.Beckmann@amd.comhelp_text = '''
2977905SBrad.Beckmann@amd.comUsage: scons [scons options] [build options] [target(s)]
2987905SBrad.Beckmann@amd.com
2997905SBrad.Beckmann@amd.com'''
3007905SBrad.Beckmann@amd.com
3017905SBrad.Beckmann@amd.com###################################################
3027905SBrad.Beckmann@amd.com#
3037905SBrad.Beckmann@amd.com# Define build environments for selected configurations.
3047905SBrad.Beckmann@amd.com#
3057905SBrad.Beckmann@amd.com###################################################
3067905SBrad.Beckmann@amd.com
3077905SBrad.Beckmann@amd.com# rename base env
3087905SBrad.Beckmann@amd.combase_env = env
3097905SBrad.Beckmann@amd.com
3107905SBrad.Beckmann@amd.com# Spme things (just libelf currently) are shared across all configs in
3117905SBrad.Beckmann@amd.com# a "build root".  Need to define how to build these just once for
3127905SBrad.Beckmann@amd.com# each referenced root.
3137905SBrad.Beckmann@amd.combuild_root_env = {}
3147905SBrad.Beckmann@amd.comfor build_root in build_roots:
3157905SBrad.Beckmann@amd.com    env = base_env.Copy()
3167905SBrad.Beckmann@amd.com    env.SConscript('ext/libelf/SConscript',
3177905SBrad.Beckmann@amd.com                   build_dir = os.path.join(build_root, 'libelf'),
3185613Sgblack@eecs.umich.edu                   exports = 'env')
3195613Sgblack@eecs.umich.edu    build_root_env[build_root] = env
3205613Sgblack@eecs.umich.edu
3215133Sgblack@eecs.umich.edufor build_path in build_paths:
3225133Sgblack@eecs.umich.edu    print "Building in", build_path
3235133Sgblack@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
3245133Sgblack@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
3255133Sgblack@eecs.umich.edu    (build_root, build_dir) = os.path.split(build_path)
3266802Sgblack@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
3276802Sgblack@eecs.umich.edu    env = build_root_env[build_root].Copy()
3285133Sgblack@eecs.umich.edu
3295450Sgblack@eecs.umich.edu    # Set env options according to the build directory config.
3305613Sgblack@eecs.umich.edu    sticky_opts.files = []
3315613Sgblack@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
3325638Sgblack@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
3337905SBrad.Beckmann@amd.com    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
3347905SBrad.Beckmann@amd.com    current_opts_file = os.path.join(build_root, 'options', build_dir)
3357905SBrad.Beckmann@amd.com    if os.path.isfile(current_opts_file):
3367905SBrad.Beckmann@amd.com        sticky_opts.files.append(current_opts_file)
3377937SBrad.Beckmann@amd.com        print "Using saved options file %s" % current_opts_file
3387937SBrad.Beckmann@amd.com    else:
3397937SBrad.Beckmann@amd.com        # Build dir-specific options file doesn't exist.
3407905SBrad.Beckmann@amd.com
3417905SBrad.Beckmann@amd.com        # Make sure the directory is there so we can create it later
3425613Sgblack@eecs.umich.edu        opt_dir = os.path.dirname(current_opts_file)
3435613Sgblack@eecs.umich.edu        if not os.path.isdir(opt_dir):
3445613Sgblack@eecs.umich.edu            os.mkdir(opt_dir)
3455841Sgblack@eecs.umich.edu
3465841Sgblack@eecs.umich.edu        # Get default build options from source tree.  Options are
3475841Sgblack@eecs.umich.edu        # normally determined by name of $BUILD_DIR, but can be
3485841Sgblack@eecs.umich.edu        # overriden by 'default=' arg on command line.
3495841Sgblack@eecs.umich.edu        default_opts_file = os.path.join('build_opts',
3505841Sgblack@eecs.umich.edu                                         ARGUMENTS.get('default', build_dir))
3515841Sgblack@eecs.umich.edu        if os.path.isfile(default_opts_file):
3525615Sgblack@eecs.umich.edu            sticky_opts.files.append(default_opts_file)
3535615Sgblack@eecs.umich.edu            print "Options file %s not found,\n  using defaults in %s" \
3545615Sgblack@eecs.umich.edu                  % (current_opts_file, default_opts_file)
3555615Sgblack@eecs.umich.edu        else:
3565641Sgblack@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
3576135Sgblack@eecs.umich.edu                  % (current_opts_file, default_opts_file)
3586135Sgblack@eecs.umich.edu            Exit(1)
3596135Sgblack@eecs.umich.edu
3606135Sgblack@eecs.umich.edu    # Apply current option settings to env
3616135Sgblack@eecs.umich.edu    sticky_opts.Update(env)
3626135Sgblack@eecs.umich.edu    nonsticky_opts.Update(env)
3636135Sgblack@eecs.umich.edu
3645644Sgblack@eecs.umich.edu    help_text += "Sticky options for %s:\n" % build_dir \
3656135Sgblack@eecs.umich.edu                 + sticky_opts.GenerateHelpText(env) \
3665644Sgblack@eecs.umich.edu                 + "\nNon-sticky options for %s:\n" % build_dir \
3675644Sgblack@eecs.umich.edu                 + nonsticky_opts.GenerateHelpText(env)
3685644Sgblack@eecs.umich.edu
3696135Sgblack@eecs.umich.edu    # Process option settings.
3705644Sgblack@eecs.umich.edu
3715644Sgblack@eecs.umich.edu    if not have_fenv and env['USE_FENV']:
3725644Sgblack@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
3735843Sgblack@eecs.umich.edu              "forcing USE_FENV to False in", build_dir + "."
3745843Sgblack@eecs.umich.edu        env['USE_FENV'] = False
3755843Sgblack@eecs.umich.edu
3765843Sgblack@eecs.umich.edu    if not env['USE_FENV']:
3775843Sgblack@eecs.umich.edu        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
3785843Sgblack@eecs.umich.edu        print "         FP results may deviate slightly from other platforms."
3795843Sgblack@eecs.umich.edu
3805843Sgblack@eecs.umich.edu    if env['EFENCE']:
3815843Sgblack@eecs.umich.edu        env.Append(LIBS=['efence'])
3825843Sgblack@eecs.umich.edu
3835843Sgblack@eecs.umich.edu    if env['USE_MYSQL']:
3846044Sgblack@eecs.umich.edu        if not have_mysql:
3855843Sgblack@eecs.umich.edu            print "Warning: MySQL not available; " \
3866074Sgblack@eecs.umich.edu                  "forcing USE_MYSQL to False in", build_dir + "."
3876135Sgblack@eecs.umich.edu            env['USE_MYSQL'] = False
3886135Sgblack@eecs.umich.edu        else:
3896135Sgblack@eecs.umich.edu            print "Compiling in", build_dir, "with MySQL support."
3906135Sgblack@eecs.umich.edu            env.ParseConfig(mysql_config_libs)
3916135Sgblack@eecs.umich.edu            env.ParseConfig(mysql_config_include)
3926135Sgblack@eecs.umich.edu
3936135Sgblack@eecs.umich.edu    # Save sticky option settings back to current options file
3946135Sgblack@eecs.umich.edu    sticky_opts.Save(current_opts_file, env)
3956135Sgblack@eecs.umich.edu
3966135Sgblack@eecs.umich.edu    # Do this after we save setting back, or else we'll tack on an
3976135Sgblack@eecs.umich.edu    # extra 'qdo' every time we run scons.
3986135Sgblack@eecs.umich.edu    if env['BATCH']:
3996135Sgblack@eecs.umich.edu        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4006135Sgblack@eecs.umich.edu        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4016135Sgblack@eecs.umich.edu
4026135Sgblack@eecs.umich.edu    if env['USE_SSE2']:
4036135Sgblack@eecs.umich.edu        env.Append(CCFLAGS='-msse2')
4046135Sgblack@eecs.umich.edu
4056135Sgblack@eecs.umich.edu    # The m5/SConscript file sets up the build rules in 'env' according
4066135Sgblack@eecs.umich.edu    # to the configured options.  It returns a list of environments,
4076135Sgblack@eecs.umich.edu    # one for each variant build (debug, opt, etc.)
4086135Sgblack@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
4096135Sgblack@eecs.umich.edu                         exports = 'env', duplicate = False)
4105641Sgblack@eecs.umich.edu
4117925Sgblack@eecs.umich.edu    # Set up the regression tests for each build.
4127925Sgblack@eecs.umich.edu#    for e in envList:
4137925Sgblack@eecs.umich.edu#        SConscript('m5-test/SConscript',
4147925Sgblack@eecs.umich.edu#                   build_dir = os.path.join(build_dir, 'test', e.Label),
4157925Sgblack@eecs.umich.edu#                   exports = { 'env' : e }, duplicate = False)
4167925Sgblack@eecs.umich.edu
4177925Sgblack@eecs.umich.eduHelp(help_text)
4187925Sgblack@eecs.umich.edu
4197925Sgblack@eecs.umich.edu###################################################
4207925Sgblack@eecs.umich.edu#
4217925Sgblack@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
4227925Sgblack@eecs.umich.edu# build environments to build the requested targets.
4237925Sgblack@eecs.umich.edu#
4247925Sgblack@eecs.umich.edu###################################################
4257925Sgblack@eecs.umich.edu
4267925Sgblack@eecs.umich.edu