SConstruct revision 3036
1955SN/A# -*- mode:python -*-
2955SN/A
35871Snate@binkert.org# Copyright (c) 2004-2005 The Regents of The University of Michigan
41762SN/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.
28955SN/A#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
302665Ssaidi@eecs.umich.edu
315863Snate@binkert.org###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
35955SN/A# While in this directory ('m5'), just type 'scons' to build the default
36955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
372632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
382632Sstever@eecs.umich.edu# the optimized full-system version).
392632Sstever@eecs.umich.edu#
402632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a
41955SN/A# 'build/<CONFIG>' somewhere along the target path.  The build system
422632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
432632Sstever@eecs.umich.edu# built for the same host system.
442761Sstever@eecs.umich.edu#
452632Sstever@eecs.umich.edu# Examples:
462632Sstever@eecs.umich.edu#
472632Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
482761Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
492761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
502761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512632Sstever@eecs.umich.edu#
522632Sstever@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
532761Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
542761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
552761Sstever@eecs.umich.edu#   file.
562761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
572761Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
582632Sstever@eecs.umich.edu#
592632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
602632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
622632Sstever@eecs.umich.edu# options as well.
632632Sstever@eecs.umich.edu#
642632Sstever@eecs.umich.edu###################################################
65955SN/A
66955SN/A# Python library imports
67955SN/Aimport sys
685863Snate@binkert.orgimport os
695863Snate@binkert.org
705863Snate@binkert.org# Check for recent-enough Python and SCons versions.  If your system's
715863Snate@binkert.org# default installation of Python is not recent enough, you can use a
725863Snate@binkert.org# non-default installation of the Python interpreter by either (1)
735863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python'
745863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the
755863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
765863Snate@binkert.orgEnsurePythonVersion(2,4)
775863Snate@binkert.org
785863Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
795863Snate@binkert.org# 3-element version number.
805863Snate@binkert.orgmin_scons_version = (0,96,91)
815863Snate@binkert.orgtry:
825863Snate@binkert.org    EnsureSConsVersion(*min_scons_version)
835863Snate@binkert.orgexcept:
845863Snate@binkert.org    print "Error checking current SCons version."
855863Snate@binkert.org    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
865863Snate@binkert.org    Exit(2)
875863Snate@binkert.org    
885863Snate@binkert.org
895863Snate@binkert.org# The absolute path to the current directory (where this file lives).
905863Snate@binkert.orgROOT = Dir('.').abspath
915863Snate@binkert.org
925863Snate@binkert.org# Paths to the M5 and external source trees.
935863Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src')
945863Snate@binkert.org
955863Snate@binkert.org# tell python where to find m5 python code
965863Snate@binkert.orgsys.path.append(os.path.join(ROOT, 'src/python'))
975863Snate@binkert.org
985863Snate@binkert.org###################################################
996654Snate@binkert.org#
100955SN/A# Figure out which configurations to set up based on the path(s) of
1015396Ssaidi@eecs.umich.edu# the target(s).
1025863Snate@binkert.org#
1035863Snate@binkert.org###################################################
1044202Sbinkertn@umich.edu
1055863Snate@binkert.org# Find default configuration & binary.
1065863Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1075863Snate@binkert.org
1085863Snate@binkert.org# Ask SCons which directory it was invoked from.
109955SN/Alaunch_dir = GetLaunchDir()
1106654Snate@binkert.org
1115273Sstever@gmail.com# Make targets relative to invocation directory
1125871Snate@binkert.orgabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1135273Sstever@gmail.com                  BUILD_TARGETS)
1146655Snate@binkert.org
1156655Snate@binkert.org# helper function: find last occurrence of element in list
1166655Snate@binkert.orgdef rfind(l, elt, offs = -1):
1176655Snate@binkert.org    for i in range(len(l)+offs, 0, -1):
1186655Snate@binkert.org        if l[i] == elt:
1196655Snate@binkert.org            return i
1205871Snate@binkert.org    raise ValueError, "element not found"
1216654Snate@binkert.org
1225396Ssaidi@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1235871Snate@binkert.org# directory below this will determine the build parameters.  For
1245871Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1256121Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it
1265871Snate@binkert.org# follow 'build' in the bulid path.
1275871Snate@binkert.org
1286003Snate@binkert.org# Generate a list of the unique build roots and configs that the
1296655Snate@binkert.org# collected targets reference.
130955SN/Abuild_paths = []
1315871Snate@binkert.orgbuild_root = None
1325871Snate@binkert.orgfor t in abs_targets:
1335871Snate@binkert.org    path_dirs = t.split('/')
1345871Snate@binkert.org    try:
135955SN/A        build_top = rfind(path_dirs, 'build', -2)
1366121Snate@binkert.org    except:
1376121Snate@binkert.org        print "Error: no non-leaf 'build' dir found on target path", t
1386121Snate@binkert.org        Exit(1)
1391533SN/A    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1406655Snate@binkert.org    if not build_root:
1416655Snate@binkert.org        build_root = this_build_root
1426655Snate@binkert.org    else:
1436655Snate@binkert.org        if this_build_root != build_root:
1445871Snate@binkert.org            print "Error: build targets not under same build root\n"\
1455871Snate@binkert.org                  "  %s\n  %s" % (build_root, this_build_root)
1465863Snate@binkert.org            Exit(1)
1475871Snate@binkert.org    build_path = os.path.join('/',*path_dirs[:build_top+2])
1485871Snate@binkert.org    if build_path not in build_paths:
1495871Snate@binkert.org        build_paths.append(build_path)
1505871Snate@binkert.org
1515871Snate@binkert.org###################################################
1525863Snate@binkert.org#
1536121Snate@binkert.org# Set up the default build environment.  This environment is copied
1545863Snate@binkert.org# and modified according to each selected configuration.
1555871Snate@binkert.org#
1564678Snate@binkert.org###################################################
1574678Snate@binkert.org
1584678Snate@binkert.orgenv = Environment(ENV = os.environ,  # inherit user's environment vars
1594678Snate@binkert.org                  ROOT = ROOT,
1604678Snate@binkert.org                  SRCDIR = SRCDIR)
1614678Snate@binkert.org
1624678Snate@binkert.orgenv.SConsignFile(os.path.join(build_root,"sconsign"))
1634678Snate@binkert.org
1644678Snate@binkert.org# Default duplicate option is to use hard links, but this messes up
1654678Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves
1664678Snate@binkert.org# file to file~ then copies to file, breaking the link.  Symbolic
1674678Snate@binkert.org# (soft) links work better.
1686121Snate@binkert.orgenv.SetOption('duplicate', 'soft-copy')
1694678Snate@binkert.org
1705871Snate@binkert.org# I waffle on this setting... it does avoid a few painful but
1715871Snate@binkert.org# unnecessary builds, but it also seems to make trivial builds take
1725871Snate@binkert.org# noticeably longer.
1735871Snate@binkert.orgif False:
1745871Snate@binkert.org    env.TargetSignatures('content')
1755871Snate@binkert.org
1765871Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package.
1775871Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1785871Snate@binkert.org
1795871Snate@binkert.org# Set up default C++ compiler flags
1805871Snate@binkert.orgenv.Append(CCFLAGS='-pipe')
1815871Snate@binkert.orgenv.Append(CCFLAGS='-fno-strict-aliasing')
1825871Snate@binkert.orgenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1835990Ssaidi@eecs.umich.eduif sys.platform == 'cygwin':
1845871Snate@binkert.org    # cygwin has some header file issues...
1855871Snate@binkert.org    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1865871Snate@binkert.orgenv.Append(CPPPATH=[Dir('ext/dnet')])
1874678Snate@binkert.org
1886654Snate@binkert.org# Find Python include and library directories for embedding the
1895871Snate@binkert.org# interpreter.  For consistency, we will use the same Python
1905871Snate@binkert.org# installation used to run scons (and thus this script).  If you want
1915871Snate@binkert.org# to link in an alternate version, see above for instructions on how
1925871Snate@binkert.org# to invoke scons with a different copy of the Python interpreter.
1935871Snate@binkert.org
1945871Snate@binkert.org# Get brief Python version name (e.g., "python2.4") for locating
1955871Snate@binkert.org# include & library files
1965871Snate@binkert.orgpy_version_name = 'python' + sys.version[:3]
1975871Snate@binkert.org
1984678Snate@binkert.org# include path, e.g. /usr/local/include/python2.4
1995871Snate@binkert.orgenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
2004678Snate@binkert.orgenv.Append(LIBS = py_version_name)
2015871Snate@binkert.org# add library path too if it's not in the default place
2025871Snate@binkert.orgif sys.exec_prefix != '/usr':
2035871Snate@binkert.org    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
2045871Snate@binkert.org
2055871Snate@binkert.org# Set up SWIG flags & scanner
2065871Snate@binkert.org
2075871Snate@binkert.orgenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2085871Snate@binkert.org
2095871Snate@binkert.orgimport SCons.Scanner
2106121Snate@binkert.org
2116121Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2125863Snate@binkert.org
213955SN/Aswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
214955SN/A                                        swig_inc_re)
2152632Sstever@eecs.umich.edu
2162632Sstever@eecs.umich.eduenv.Append(SCANNERS = swig_scanner)
217955SN/A
218955SN/A# Other default libraries
219955SN/Aenv.Append(LIBS=['z'])
220955SN/A
2215863Snate@binkert.org# Platform-specific configuration.  Note again that we assume that all
222955SN/A# builds under a given build root run on the same host platform.
2232632Sstever@eecs.umich.educonf = Configure(env,
2242632Sstever@eecs.umich.edu                 conf_dir = os.path.join(build_root, '.scons_config'),
2252632Sstever@eecs.umich.edu                 log_file = os.path.join(build_root, 'scons_config.log'))
2262632Sstever@eecs.umich.edu
2272632Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
2282632Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
2292632Sstever@eecs.umich.eduif not have_fenv:
2302632Sstever@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
2312632Sstever@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
2322632Sstever@eecs.umich.edu
2332632Sstever@eecs.umich.edu# Check for mysql.
2342632Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config')
2352632Sstever@eecs.umich.eduhave_mysql = mysql_config != None
2363718Sstever@eecs.umich.edu
2373718Sstever@eecs.umich.edu# Check MySQL version.
2383718Sstever@eecs.umich.eduif have_mysql:
2393718Sstever@eecs.umich.edu    mysql_version = os.popen(mysql_config + ' --version').read()
2403718Sstever@eecs.umich.edu    mysql_version = mysql_version.split('.')
2415863Snate@binkert.org    mysql_major = int(mysql_version[0])
2425863Snate@binkert.org    mysql_minor = int(mysql_version[1])
2433718Sstever@eecs.umich.edu    # This version check is probably overly conservative, but it deals
2443718Sstever@eecs.umich.edu    # with the versions we have installed.
2456121Snate@binkert.org    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2465863Snate@binkert.org        print "Warning: MySQL v4.1 or newer required."
2473718Sstever@eecs.umich.edu        have_mysql = False
2483718Sstever@eecs.umich.edu
2492634Sstever@eecs.umich.edu# Set up mysql_config commands.
2502634Sstever@eecs.umich.eduif have_mysql:
2515863Snate@binkert.org    mysql_config_include = mysql_config + ' --include'
2522638Sstever@eecs.umich.edu    if os.system(mysql_config_include + ' > /dev/null') != 0:
2532632Sstever@eecs.umich.edu        # older mysql_config versions don't support --include, use
2542632Sstever@eecs.umich.edu        # --cflags instead
2552632Sstever@eecs.umich.edu        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2562632Sstever@eecs.umich.edu    # This seems to work in all versions
2572632Sstever@eecs.umich.edu    mysql_config_libs = mysql_config + ' --libs'
2582632Sstever@eecs.umich.edu
2591858SN/Aenv = conf.Finish()
2603716Sstever@eecs.umich.edu
2612638Sstever@eecs.umich.edu# Define the universe of supported ISAs
2622638Sstever@eecs.umich.eduenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2632638Sstever@eecs.umich.edu
2642638Sstever@eecs.umich.edu# Define the universe of supported CPU models
2652638Sstever@eecs.umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2662638Sstever@eecs.umich.edu                       'FullCPU', 'O3CPU',
2672638Sstever@eecs.umich.edu                       'OzoneCPU']
2685863Snate@binkert.org
2695863Snate@binkert.org# Sticky options get saved in the options file so they persist from
2705863Snate@binkert.org# one invocation to the next (unless overridden, in which case the new
271955SN/A# value becomes sticky).
2725341Sstever@gmail.comsticky_opts = Options(args=ARGUMENTS)
2735341Sstever@gmail.comsticky_opts.AddOptions(
2745863Snate@binkert.org    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2755341Sstever@gmail.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2766121Snate@binkert.org    # There's a bug in scons 0.96.1 that causes ListOptions with list
2774494Ssaidi@eecs.umich.edu    # values (more than one value) not to be able to be restored from
2786121Snate@binkert.org    # a saved option file.  If this causes trouble then upgrade to
2791105SN/A    # scons 0.96.90 or later.
2802667Sstever@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2812667Sstever@eecs.umich.edu               env['ALL_CPU_LIST']),
2822667Sstever@eecs.umich.edu    BoolOption('ALPHA_TLASER',
2832667Sstever@eecs.umich.edu               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2846121Snate@binkert.org    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2852667Sstever@eecs.umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2865341Sstever@gmail.com               False),
2875863Snate@binkert.org    BoolOption('SS_COMPATIBLE_FP',
2885341Sstever@gmail.com               'Make floating-point results compatible with SimpleScalar',
2895341Sstever@gmail.com               False),
2905341Sstever@gmail.com    BoolOption('USE_SSE2',
2915863Snate@binkert.org               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2925341Sstever@gmail.com               False),
2935341Sstever@gmail.com    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2945341Sstever@gmail.com    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2955863Snate@binkert.org    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
2965341Sstever@gmail.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2975341Sstever@gmail.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2985341Sstever@gmail.com    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2995341Sstever@gmail.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
3005341Sstever@gmail.com    )
3015341Sstever@gmail.com
3025341Sstever@gmail.com# Non-sticky options only apply to the current build.
3035341Sstever@gmail.comnonsticky_opts = Options(args=ARGUMENTS)
3045341Sstever@gmail.comnonsticky_opts.AddOptions(
3055341Sstever@gmail.com    ListOption('TEST_CPU_MODELS', 'CPU models to test if regression is being run', '',
3065863Snate@binkert.org               env['ALL_CPU_LIST']),
3075341Sstever@gmail.com    BoolOption('update_ref', 'Update test reference outputs', False)
3085863Snate@binkert.org    )
3095341Sstever@gmail.com
3105863Snate@binkert.org# These options get exported to #defines in config/*.hh (see src/SConscript).
3116121Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3126121Snate@binkert.org                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3135397Ssaidi@eecs.umich.edu                     'USE_CHECKER']
3145397Ssaidi@eecs.umich.edu
3155341Sstever@gmail.com# Define a handy 'no-op' action
3166168Snate@binkert.orgdef no_action(target, source, env):
3176168Snate@binkert.org    return 0
3185341Sstever@gmail.com
3195341Sstever@gmail.comenv.NoAction = Action(no_action, None)
3205341Sstever@gmail.com
3215341Sstever@gmail.com###################################################
3225341Sstever@gmail.com#
3235863Snate@binkert.org# Define a SCons builder for configuration flag headers.
3245341Sstever@gmail.com#
3255341Sstever@gmail.com###################################################
3266121Snate@binkert.org
3276121Snate@binkert.org# This function generates a config header file that #defines the
3285341Sstever@gmail.com# option symbol to the current option setting (0 or 1).  The source
3296814Sgblack@eecs.umich.edu# operands are the name of the option and a Value node containing the
3306814Sgblack@eecs.umich.edu# value of the option.
3315863Snate@binkert.orgdef build_config_file(target, source, env):
3326121Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
3335341Sstever@gmail.com    f = file(str(target[0]), 'w')
3345863Snate@binkert.org    print >> f, '#define', option, value
3355341Sstever@gmail.com    f.close()
3366121Snate@binkert.org    return None
3376121Snate@binkert.org
3386121Snate@binkert.org# Generate the message to be printed when building the config file.
3395742Snate@binkert.orgdef build_config_file_string(target, source, env):
3405742Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
3415341Sstever@gmail.com    return "Defining %s as %s in %s." % (option, value, target[0])
3425742Snate@binkert.org
3435742Snate@binkert.org# Combine the two functions into a scons Action object.
3445341Sstever@gmail.comconfig_action = Action(build_config_file, build_config_file_string)
3456017Snate@binkert.org
3466121Snate@binkert.org# The emitter munges the source & target node lists to reflect what
3476017Snate@binkert.org# we're really doing.
3486654Snate@binkert.orgdef config_emitter(target, source, env):
3496654Snate@binkert.org    # extract option name from Builder arg
3505871Snate@binkert.org    option = str(target[0])
3516121Snate@binkert.org    # True target is config header file
3526121Snate@binkert.org    target = os.path.join('config', option.lower() + '.hh')
3536121Snate@binkert.org    # Force value to 0/1 even if it's a Python bool
3546121Snate@binkert.org    val = int(eval(str(env[option])))
3553940Ssaidi@eecs.umich.edu    # Sources are option name & value (packaged in SCons Value nodes)
3563918Ssaidi@eecs.umich.edu    return ([target], [Value(option), Value(val)])
3573918Ssaidi@eecs.umich.edu
3581858SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
3596121Snate@binkert.org
3606121Snate@binkert.orgenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3616121Snate@binkert.org
3626143Snate@binkert.org###################################################
3636121Snate@binkert.org#
3647618SAli.Saidi@arm.com# Define a SCons builder for copying files.  This is used by the
3657618SAli.Saidi@arm.com# Python zipfile code in src/python/SConscript, but is placed up here
3667618SAli.Saidi@arm.com# since it's potentially more generally applicable.
3677618SAli.Saidi@arm.com#
3687618SAli.Saidi@arm.com###################################################
3697618SAli.Saidi@arm.com
3707618SAli.Saidi@arm.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3717618SAli.Saidi@arm.com
3726121Snate@binkert.orgenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3733940Ssaidi@eecs.umich.edu
3746121Snate@binkert.org###################################################
3756121Snate@binkert.org#
3766121Snate@binkert.org# Define a simple SCons builder to concatenate files.
3776121Snate@binkert.org#
3786121Snate@binkert.org# Used to append the Python zip archive to the executable.
3796121Snate@binkert.org#
3806121Snate@binkert.org###################################################
3813918Ssaidi@eecs.umich.edu
3823918Ssaidi@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3833940Ssaidi@eecs.umich.edu                                          'chmod +x $TARGET']))
3843918Ssaidi@eecs.umich.edu
3853918Ssaidi@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder })
3866157Snate@binkert.org
3876157Snate@binkert.org
3886157Snate@binkert.org# base help text
3896157Snate@binkert.orghelp_text = '''
3905397Ssaidi@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)]
3915397Ssaidi@eecs.umich.edu
3926121Snate@binkert.org'''
3936121Snate@binkert.org
3946121Snate@binkert.org# libelf build is shared across all configs in the build root.
3956121Snate@binkert.orgenv.SConscript('ext/libelf/SConscript',
3966121Snate@binkert.org               build_dir = os.path.join(build_root, 'libelf'),
3976121Snate@binkert.org               exports = 'env')
3985397Ssaidi@eecs.umich.edu
3991851SN/A###################################################
4001851SN/A#
4016655Snate@binkert.org# Define build environments for selected configurations.
402955SN/A#
4033053Sstever@eecs.umich.edu###################################################
4046121Snate@binkert.org
4053053Sstever@eecs.umich.edu# rename base env
4063053Sstever@eecs.umich.edubase_env = env
4073053Sstever@eecs.umich.edu
4083053Sstever@eecs.umich.edufor build_path in build_paths:
4093053Sstever@eecs.umich.edu    print "Building in", build_path
4106654Snate@binkert.org    # build_dir is the tail component of build path, and is used to
4113053Sstever@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
4124742Sstever@eecs.umich.edu    (build_root, build_dir) = os.path.split(build_path)
4134742Sstever@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
4143053Sstever@eecs.umich.edu    env = base_env.Copy()
4153053Sstever@eecs.umich.edu
4163053Sstever@eecs.umich.edu    # Set env options according to the build directory config.
4173053Sstever@eecs.umich.edu    sticky_opts.files = []
4186654Snate@binkert.org    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
4193053Sstever@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
4203053Sstever@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
4213053Sstever@eecs.umich.edu    current_opts_file = os.path.join(build_root, 'options', build_dir)
4223053Sstever@eecs.umich.edu    if os.path.isfile(current_opts_file):
4232667Sstever@eecs.umich.edu        sticky_opts.files.append(current_opts_file)
4244554Sbinkertn@umich.edu        print "Using saved options file %s" % current_opts_file
4256121Snate@binkert.org    else:
4262667Sstever@eecs.umich.edu        # Build dir-specific options file doesn't exist.
4274554Sbinkertn@umich.edu
4284554Sbinkertn@umich.edu        # Make sure the directory is there so we can create it later
4294554Sbinkertn@umich.edu        opt_dir = os.path.dirname(current_opts_file)
4306121Snate@binkert.org        if not os.path.isdir(opt_dir):
4314554Sbinkertn@umich.edu            os.mkdir(opt_dir)
4324554Sbinkertn@umich.edu
4334554Sbinkertn@umich.edu        # Get default build options from source tree.  Options are
4344781Snate@binkert.org        # normally determined by name of $BUILD_DIR, but can be
4354554Sbinkertn@umich.edu        # overriden by 'default=' arg on command line.
4364554Sbinkertn@umich.edu        default_opts_file = os.path.join('build_opts',
4372667Sstever@eecs.umich.edu                                         ARGUMENTS.get('default', build_dir))
4384554Sbinkertn@umich.edu        if os.path.isfile(default_opts_file):
4394554Sbinkertn@umich.edu            sticky_opts.files.append(default_opts_file)
4404554Sbinkertn@umich.edu            print "Options file %s not found,\n  using defaults in %s" \
4414554Sbinkertn@umich.edu                  % (current_opts_file, default_opts_file)
4422667Sstever@eecs.umich.edu        else:
4434554Sbinkertn@umich.edu            print "Error: cannot find options file %s or %s" \
4442667Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4454554Sbinkertn@umich.edu            Exit(1)
4466121Snate@binkert.org
4472667Sstever@eecs.umich.edu    # Apply current option settings to env
4485522Snate@binkert.org    sticky_opts.Update(env)
4495522Snate@binkert.org    nonsticky_opts.Update(env)
4505522Snate@binkert.org
4515522Snate@binkert.org    help_text += "Sticky options for %s:\n" % build_dir \
4525522Snate@binkert.org                 + sticky_opts.GenerateHelpText(env) \
4535522Snate@binkert.org                 + "\nNon-sticky options for %s:\n" % build_dir \
4545522Snate@binkert.org                 + nonsticky_opts.GenerateHelpText(env)
4555522Snate@binkert.org
4565522Snate@binkert.org    # Process option settings.
4575522Snate@binkert.org
4585522Snate@binkert.org    if not have_fenv and env['USE_FENV']:
4595522Snate@binkert.org        print "Warning: <fenv.h> not available; " \
4605522Snate@binkert.org              "forcing USE_FENV to False in", build_dir + "."
4615522Snate@binkert.org        env['USE_FENV'] = False
4625522Snate@binkert.org
4635522Snate@binkert.org    if not env['USE_FENV']:
4645522Snate@binkert.org        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4655522Snate@binkert.org        print "         FP results may deviate slightly from other platforms."
4665522Snate@binkert.org
4675522Snate@binkert.org    if env['EFENCE']:
4685522Snate@binkert.org        env.Append(LIBS=['efence'])
4695522Snate@binkert.org
4705522Snate@binkert.org    if env['USE_MYSQL']:
4715522Snate@binkert.org        if not have_mysql:
4725522Snate@binkert.org            print "Warning: MySQL not available; " \
4735522Snate@binkert.org                  "forcing USE_MYSQL to False in", build_dir + "."
4742638Sstever@eecs.umich.edu            env['USE_MYSQL'] = False
4752638Sstever@eecs.umich.edu        else:
4766121Snate@binkert.org            print "Compiling in", build_dir, "with MySQL support."
4773716Sstever@eecs.umich.edu            env.ParseConfig(mysql_config_libs)
4785522Snate@binkert.org            env.ParseConfig(mysql_config_include)
4795522Snate@binkert.org
4805522Snate@binkert.org    # Save sticky option settings back to current options file
4815522Snate@binkert.org    sticky_opts.Save(current_opts_file, env)
4825522Snate@binkert.org
4835522Snate@binkert.org    # Do this after we save setting back, or else we'll tack on an
4841858SN/A    # extra 'qdo' every time we run scons.
4855227Ssaidi@eecs.umich.edu    if env['BATCH']:
4865227Ssaidi@eecs.umich.edu        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4875227Ssaidi@eecs.umich.edu        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4885227Ssaidi@eecs.umich.edu
4896654Snate@binkert.org    if env['USE_SSE2']:
4906654Snate@binkert.org        env.Append(CCFLAGS='-msse2')
4916121Snate@binkert.org
4926121Snate@binkert.org    # The src/SConscript file sets up the build rules in 'env' according
4936121Snate@binkert.org    # to the configured options.  It returns a list of environments,
4946121Snate@binkert.org    # one for each variant build (debug, opt, etc.)
4955227Ssaidi@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
4965227Ssaidi@eecs.umich.edu                         exports = 'env')
4975227Ssaidi@eecs.umich.edu
4985204Sstever@gmail.com    # Set up the regression tests for each build.
4995204Sstever@gmail.com    for e in envList:
5005204Sstever@gmail.com        SConscript('tests/SConscript',
5015204Sstever@gmail.com                   build_dir = os.path.join(build_path, 'tests', e.Label),
5025204Sstever@gmail.com                   exports = { 'env' : e }, duplicate = False)
5035204Sstever@gmail.com
5045204Sstever@gmail.comHelp(help_text)
5055204Sstever@gmail.com
5065204Sstever@gmail.com###################################################
5075204Sstever@gmail.com#
5085204Sstever@gmail.com# Let SCons do its thing.  At this point SCons will use the defined
5095204Sstever@gmail.com# build environments to build the requested targets.
5105204Sstever@gmail.com#
5115204Sstever@gmail.com###################################################
5125204Sstever@gmail.com
5135204Sstever@gmail.com