SConstruct revision 2655
1955SN/A# -*- mode:python -*-
2955SN/A
311408Sandreas.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# While in this directory ('m5'), just type 'scons' to build the default
34955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
35955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
36955SN/A# the optimized full-system version).
37955SN/A#
38955SN/A# You can build M5 in a different directory as long as there is a
39955SN/A# 'build/<CONFIG>' somewhere along the target path.  The build system
40955SN/A# expdects that all configs under the same build directory are being
41955SN/A# built for the same host system.
422665Ssaidi@eecs.umich.edu#
432665Ssaidi@eecs.umich.edu# Examples:
445863Snate@binkert.org#   These two commands are equivalent.  The '-u' option tells scons to
45955SN/A#   search up the directory tree for this SConstruct file.
46955SN/A#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
47955SN/A#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
48955SN/A#   These two commands are equivalent and demonstrate building in a
49955SN/A#   directory outside of the source tree.  The '-C' option tells scons
508878Ssteve.reinhardt@amd.com#   to chdir to the specified directory to find this SConstruct file.
512632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
528878Ssteve.reinhardt@amd.com#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
532632Sstever@eecs.umich.edu#
54955SN/A# You can use 'scons -H' to print scons options.  If you're in this
558878Ssteve.reinhardt@amd.com# 'm5' directory (or use -u or -C to tell scons where to find this
562632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
572761Sstever@eecs.umich.edu# options as well.
582632Sstever@eecs.umich.edu#
592632Sstever@eecs.umich.edu###################################################
602632Sstever@eecs.umich.edu
612761Sstever@eecs.umich.edu# Python library imports
622761Sstever@eecs.umich.eduimport sys
632761Sstever@eecs.umich.eduimport os
648878Ssteve.reinhardt@amd.com
658878Ssteve.reinhardt@amd.com# Check for recent-enough Python and SCons versions
662761Sstever@eecs.umich.eduEnsurePythonVersion(2,3)
672761Sstever@eecs.umich.edu
682761Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
692761Sstever@eecs.umich.edu# 3-element version number.
702761Sstever@eecs.umich.edumin_scons_version = (0,96,91)
718878Ssteve.reinhardt@amd.comtry:
728878Ssteve.reinhardt@amd.com    EnsureSConsVersion(*min_scons_version)
732632Sstever@eecs.umich.eduexcept:
742632Sstever@eecs.umich.edu    print "Error checking current SCons version."
758878Ssteve.reinhardt@amd.com    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
768878Ssteve.reinhardt@amd.com    Exit(2)
772632Sstever@eecs.umich.edu    
78955SN/A
79955SN/A# The absolute path to the current directory (where this file lives).
80955SN/AROOT = Dir('.').abspath
815863Snate@binkert.org
825863Snate@binkert.org# Paths to the M5 and external source trees.
835863Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src')
845863Snate@binkert.org
855863Snate@binkert.org# tell python where to find m5 python code
865863Snate@binkert.orgsys.path.append(os.path.join(ROOT, 'src/python'))
875863Snate@binkert.org
885863Snate@binkert.org###################################################
895863Snate@binkert.org#
905863Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
915863Snate@binkert.org# the target(s).
928878Ssteve.reinhardt@amd.com#
935863Snate@binkert.org###################################################
945863Snate@binkert.org
955863Snate@binkert.org# Find default configuration & binary.
969812Sandreas.hansson@arm.comDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
979812Sandreas.hansson@arm.com
985863Snate@binkert.org# Ask SCons which directory it was invoked from.
999812Sandreas.hansson@arm.comlaunch_dir = GetLaunchDir()
1005863Snate@binkert.org
1015863Snate@binkert.org# Make targets relative to invocation directory
1025863Snate@binkert.orgabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1039812Sandreas.hansson@arm.com                  BUILD_TARGETS)
1049812Sandreas.hansson@arm.com
1055863Snate@binkert.org# helper function: find last occurrence of element in list
1065863Snate@binkert.orgdef rfind(l, elt, offs = -1):
1078878Ssteve.reinhardt@amd.com    for i in range(len(l)+offs, 0, -1):
1085863Snate@binkert.org        if l[i] == elt:
1095863Snate@binkert.org            return i
1105863Snate@binkert.org    raise ValueError, "element not found"
1116654Snate@binkert.org
11210196SCurtis.Dunham@arm.com# Each target must have 'build' in the interior of the path; the
113955SN/A# directory below this will determine the build parameters.  For
1145396Ssaidi@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
11511401Sandreas.sandberg@arm.com# recognize that ALPHA_SE specifies the configuration because it
1165863Snate@binkert.org# follow 'build' in the bulid path.
1175863Snate@binkert.org
1184202Sbinkertn@umich.edu# Generate a list of the unique build roots and configs that the
1195863Snate@binkert.org# collected targets reference.
1205863Snate@binkert.orgbuild_paths = []
1215863Snate@binkert.orgbuild_root = None
1225863Snate@binkert.orgfor t in abs_targets:
123955SN/A    path_dirs = t.split('/')
1246654Snate@binkert.org    try:
1255273Sstever@gmail.com        build_top = rfind(path_dirs, 'build', -2)
1265871Snate@binkert.org    except:
1275273Sstever@gmail.com        print "Error: no non-leaf 'build' dir found on target path", t
1286655Snate@binkert.org        Exit(1)
1298878Ssteve.reinhardt@amd.com    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1306655Snate@binkert.org    if not build_root:
1316655Snate@binkert.org        build_root = this_build_root
1329219Spower.jg@gmail.com    else:
1336655Snate@binkert.org        if this_build_root != build_root:
1345871Snate@binkert.org            print "Error: build targets not under same build root\n"\
1356654Snate@binkert.org                  "  %s\n  %s" % (build_root, this_build_root)
1368947Sandreas.hansson@arm.com            Exit(1)
1375396Ssaidi@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1388120Sgblack@eecs.umich.edu    if build_path not in build_paths:
1398120Sgblack@eecs.umich.edu        build_paths.append(build_path)
1408120Sgblack@eecs.umich.edu
1418120Sgblack@eecs.umich.edu###################################################
1428120Sgblack@eecs.umich.edu#
1438120Sgblack@eecs.umich.edu# Set up the default build environment.  This environment is copied
1448120Sgblack@eecs.umich.edu# and modified according to each selected configuration.
1458120Sgblack@eecs.umich.edu#
1468879Ssteve.reinhardt@amd.com###################################################
1478879Ssteve.reinhardt@amd.com
1488879Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
1498879Ssteve.reinhardt@amd.com                  ROOT = ROOT,
1508879Ssteve.reinhardt@amd.com                  SRCDIR = SRCDIR)
1518879Ssteve.reinhardt@amd.com
1528879Ssteve.reinhardt@amd.comenv.SConsignFile("sconsign")
1538879Ssteve.reinhardt@amd.com
1548879Ssteve.reinhardt@amd.com# I waffle on this setting... it does avoid a few painful but
1558879Ssteve.reinhardt@amd.com# unnecessary builds, but it also seems to make trivial builds take
1568879Ssteve.reinhardt@amd.com# noticeably longer.
1578879Ssteve.reinhardt@amd.comif False:
1588879Ssteve.reinhardt@amd.com    env.TargetSignatures('content')
1598120Sgblack@eecs.umich.edu
1608120Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
1618120Sgblack@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1628120Sgblack@eecs.umich.edu
1638120Sgblack@eecs.umich.edu# Set up default C++ compiler flags
1648120Sgblack@eecs.umich.eduenv.Append(CCFLAGS='-pipe')
1658120Sgblack@eecs.umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing')
1668120Sgblack@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1678120Sgblack@eecs.umich.eduif sys.platform == 'cygwin':
1688120Sgblack@eecs.umich.edu    # cygwin has some header file issues...
1698120Sgblack@eecs.umich.edu    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1708120Sgblack@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')])
1718120Sgblack@eecs.umich.edu
1728120Sgblack@eecs.umich.edu# Environment args for linking in Python interpreter.
1738879Ssteve.reinhardt@amd.com# Should really have an option for setting the version instead of
1748879Ssteve.reinhardt@amd.com# having 2.4 hardwired in here...
1758879Ssteve.reinhardt@amd.comenv.Append(CPPPATH='/usr/include/python2.4')
1768879Ssteve.reinhardt@amd.comenv.Append(LIBS='python2.4')
17710458Sandreas.hansson@arm.com
17810458Sandreas.hansson@arm.com# Other default libraries
17910458Sandreas.hansson@arm.comenv.Append(LIBS=['z'])
1808879Ssteve.reinhardt@amd.com
1818879Ssteve.reinhardt@amd.com# Platform-specific configuration.  Note again that we assume that all
1828879Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform.
1838879Ssteve.reinhardt@amd.comconf = Configure(env,
1849227Sandreas.hansson@arm.com                 conf_dir = os.path.join(build_root, '.scons_config'),
1859227Sandreas.hansson@arm.com                 log_file = os.path.join(build_root, 'scons_config.log'))
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', '<>')
1898879Ssteve.reinhardt@amd.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."
19210453SAndrew.Bardsley@arm.com
19310456SCurtis.Dunham@arm.com# Check for mysql.
19410456SCurtis.Dunham@arm.commysql_config = WhereIs('mysql_config')
19510456SCurtis.Dunham@arm.comhave_mysql = mysql_config != None
19610457Sandreas.hansson@arm.com
19710457Sandreas.hansson@arm.com# Check MySQL version.
19811342Sandreas.hansson@arm.comif have_mysql:
19911342Sandreas.hansson@arm.com    mysql_version = os.popen(mysql_config + ' --version').read()
2008120Sgblack@eecs.umich.edu    mysql_version = mysql_version.split('.')
2018947Sandreas.hansson@arm.com    mysql_major = int(mysql_version[0])
2027816Ssteve.reinhardt@amd.com    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.
2056121Snate@binkert.org    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2065871Snate@binkert.org        print "Warning: MySQL v4.1 or newer required."
2075871Snate@binkert.org        have_mysql = False
2089926Sstan.czerniawski@arm.com
2099926Sstan.czerniawski@arm.com# Set up mysql_config commands.
2109119Sandreas.hansson@arm.comif have_mysql:
21110068Sandreas.hansson@arm.com    mysql_config_include = mysql_config + ' --include'
21210068Sandreas.hansson@arm.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
213955SN/A        # older mysql_config versions don't support --include, use
2149416SAndreas.Sandberg@ARM.com        # --cflags instead
21511342Sandreas.hansson@arm.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
21611212Sjoseph.gross@amd.com    # This seems to work in all versions
21711212Sjoseph.gross@amd.com    mysql_config_libs = mysql_config + ' --libs'
21811212Sjoseph.gross@amd.com
21911212Sjoseph.gross@amd.comenv = conf.Finish()
22011212Sjoseph.gross@amd.com
2219416SAndreas.Sandberg@ARM.com# Define the universe of supported ISAs
2229416SAndreas.Sandberg@ARM.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2235871Snate@binkert.org
22410584Sandreas.hansson@arm.com# Define the universe of supported CPU models
2259416SAndreas.Sandberg@ARM.comenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2269416SAndreas.Sandberg@ARM.com                       'FullCPU', 'AlphaFullCPU']
2275871Snate@binkert.org
228955SN/A# Sticky options get saved in the options file so they persist from
22910671Sandreas.hansson@arm.com# one invocation to the next (unless overridden, in which case the new
23010671Sandreas.hansson@arm.com# value becomes sticky).
23110671Sandreas.hansson@arm.comsticky_opts = Options(args=ARGUMENTS)
23210671Sandreas.hansson@arm.comsticky_opts.AddOptions(
2338881Smarc.orr@gmail.com    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2346121Snate@binkert.org    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2356121Snate@binkert.org    # There's a bug in scons 0.96.1 that causes ListOptions with list
2361533SN/A    # values (more than one value) not to be able to be restored from
2379239Sandreas.hansson@arm.com    # a saved option file.  If this causes trouble then upgrade to
2389239Sandreas.hansson@arm.com    # scons 0.96.90 or later.
2399239Sandreas.hansson@arm.com    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2409239Sandreas.hansson@arm.com               env['ALL_CPU_LIST']),
2419239Sandreas.hansson@arm.com    BoolOption('ALPHA_TLASER',
2429239Sandreas.hansson@arm.com               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2439239Sandreas.hansson@arm.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2449239Sandreas.hansson@arm.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2459239Sandreas.hansson@arm.com               False),
2469239Sandreas.hansson@arm.com    BoolOption('SS_COMPATIBLE_FP',
2479239Sandreas.hansson@arm.com               'Make floating-point results compatible with SimpleScalar',
2489239Sandreas.hansson@arm.com               False),
2496655Snate@binkert.org    BoolOption('USE_SSE2',
2506655Snate@binkert.org               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2516655Snate@binkert.org               False),
2526655Snate@binkert.org    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2535871Snate@binkert.org    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2545871Snate@binkert.org    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2555863Snate@binkert.org    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2565871Snate@binkert.org    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2578878Ssteve.reinhardt@amd.com    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2585871Snate@binkert.org    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2595871Snate@binkert.org    )
2605871Snate@binkert.org
2615863Snate@binkert.org# Non-sticky options only apply to the current build.
2626121Snate@binkert.orgnonsticky_opts = Options(args=ARGUMENTS)
2635863Snate@binkert.orgnonsticky_opts.AddOptions(
26411408Sandreas.sandberg@arm.com    BoolOption('update_ref', 'Update test reference outputs', False)
26511408Sandreas.sandberg@arm.com    )
2668336Ssteve.reinhardt@amd.com
26711469SCurtis.Dunham@arm.com# These options get exported to #defines in config/*.hh (see m5/SConscript).
26811469SCurtis.Dunham@arm.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2698336Ssteve.reinhardt@amd.com                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2704678Snate@binkert.org                     'STATS_BINNING']
27111887Sandreas.sandberg@arm.com
27211887Sandreas.sandberg@arm.com# Define a handy 'no-op' action
27311887Sandreas.sandberg@arm.comdef no_action(target, source, env):
27411887Sandreas.sandberg@arm.com    return 0
27511887Sandreas.sandberg@arm.com
27611887Sandreas.sandberg@arm.comenv.NoAction = Action(no_action, None)
27711887Sandreas.sandberg@arm.com
27811887Sandreas.sandberg@arm.com###################################################
27911887Sandreas.sandberg@arm.com#
28011887Sandreas.sandberg@arm.com# Define a SCons builder for configuration flag headers.
28111887Sandreas.sandberg@arm.com#
28211408Sandreas.sandberg@arm.com###################################################
28311401Sandreas.sandberg@arm.com
28411401Sandreas.sandberg@arm.com# This function generates a config header file that #defines the
28511401Sandreas.sandberg@arm.com# option symbol to the current option setting (0 or 1).  The source
28611401Sandreas.sandberg@arm.com# operands are the name of the option and a Value node containing the
28711401Sandreas.sandberg@arm.com# value of the option.
28811401Sandreas.sandberg@arm.comdef build_config_file(target, source, env):
2898336Ssteve.reinhardt@amd.com    (option, value) = [s.get_contents() for s in source]
2908336Ssteve.reinhardt@amd.com    f = file(str(target[0]), 'w')
2918336Ssteve.reinhardt@amd.com    print >> f, '#define', option, value
2924678Snate@binkert.org    f.close()
29311401Sandreas.sandberg@arm.com    return None
2944678Snate@binkert.org
2954678Snate@binkert.org# Generate the message to be printed when building the config file.
29611401Sandreas.sandberg@arm.comdef build_config_file_string(target, source, env):
29711401Sandreas.sandberg@arm.com    (option, value) = [s.get_contents() for s in source]
2988336Ssteve.reinhardt@amd.com    return "Defining %s as %s in %s." % (option, value, target[0])
2994678Snate@binkert.org
3008336Ssteve.reinhardt@amd.com# Combine the two functions into a scons Action object.
3018336Ssteve.reinhardt@amd.comconfig_action = Action(build_config_file, build_config_file_string)
3028336Ssteve.reinhardt@amd.com
3038336Ssteve.reinhardt@amd.com# The emitter munges the source & target node lists to reflect what
3048336Ssteve.reinhardt@amd.com# we're really doing.
3058336Ssteve.reinhardt@amd.comdef config_emitter(target, source, env):
3065871Snate@binkert.org    # extract option name from Builder arg
3075871Snate@binkert.org    option = str(target[0])
3088336Ssteve.reinhardt@amd.com    # True target is config header file
30911408Sandreas.sandberg@arm.com    target = os.path.join('config', option.lower() + '.hh')
31011408Sandreas.sandberg@arm.com    # Force value to 0/1 even if it's a Python bool
31111408Sandreas.sandberg@arm.com    val = int(eval(str(env[option])))
31211408Sandreas.sandberg@arm.com    # Sources are option name & value (packaged in SCons Value nodes)
31311408Sandreas.sandberg@arm.com    return ([target], [Value(option), Value(val)])
31411408Sandreas.sandberg@arm.com
31511408Sandreas.sandberg@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action)
3168336Ssteve.reinhardt@amd.com
31711401Sandreas.sandberg@arm.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
31811401Sandreas.sandberg@arm.com
31911401Sandreas.sandberg@arm.com###################################################
3205871Snate@binkert.org#
3218336Ssteve.reinhardt@amd.com# Define a SCons builder for copying files.  This is used by the
3228336Ssteve.reinhardt@amd.com# Python zipfile code in src/python/SConscript, but is placed up here
32311401Sandreas.sandberg@arm.com# since it's potentially more generally applicable.
32411401Sandreas.sandberg@arm.com#
32511401Sandreas.sandberg@arm.com###################################################
32611401Sandreas.sandberg@arm.com
32711401Sandreas.sandberg@arm.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3284678Snate@binkert.org
3295871Snate@binkert.orgenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3304678Snate@binkert.org
33111401Sandreas.sandberg@arm.com###################################################
33211401Sandreas.sandberg@arm.com#
33311401Sandreas.sandberg@arm.com# Define a simple SCons builder to concatenate files.
33411401Sandreas.sandberg@arm.com#
33511401Sandreas.sandberg@arm.com# Used to append the Python zip archive to the executable.
33611401Sandreas.sandberg@arm.com#
33711401Sandreas.sandberg@arm.com###################################################
33811401Sandreas.sandberg@arm.com
33911401Sandreas.sandberg@arm.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
34011401Sandreas.sandberg@arm.com                                          'chmod +x $TARGET']))
34111401Sandreas.sandberg@arm.com
34211401Sandreas.sandberg@arm.comenv.Append(BUILDERS = { 'Concat' : concat_builder })
34311450Sandreas.sandberg@arm.com
34411450Sandreas.sandberg@arm.com
34511450Sandreas.sandberg@arm.com# base help text
34611450Sandreas.sandberg@arm.comhelp_text = '''
34711450Sandreas.sandberg@arm.comUsage: scons [scons options] [build options] [target(s)]
34811450Sandreas.sandberg@arm.com
34911450Sandreas.sandberg@arm.com'''
35011450Sandreas.sandberg@arm.com
35111450Sandreas.sandberg@arm.com# libelf build is shared across all configs in the build root.
35211450Sandreas.sandberg@arm.comenv.SConscript('ext/libelf/SConscript',
35311450Sandreas.sandberg@arm.com               build_dir = os.path.join(build_root, 'libelf'),
35411401Sandreas.sandberg@arm.com               exports = 'env')
35511450Sandreas.sandberg@arm.com
35611450Sandreas.sandberg@arm.com###################################################
35711450Sandreas.sandberg@arm.com#
35811401Sandreas.sandberg@arm.com# Define build environments for selected configurations.
35911450Sandreas.sandberg@arm.com#
36011401Sandreas.sandberg@arm.com###################################################
3618336Ssteve.reinhardt@amd.com
3628336Ssteve.reinhardt@amd.com# rename base env
3638336Ssteve.reinhardt@amd.combase_env = env
3648336Ssteve.reinhardt@amd.com
3658336Ssteve.reinhardt@amd.comfor build_path in build_paths:
3668336Ssteve.reinhardt@amd.com    print "Building in", build_path
3678336Ssteve.reinhardt@amd.com    # build_dir is the tail component of build path, and is used to
3688336Ssteve.reinhardt@amd.com    # determine the build parameters (e.g., 'ALPHA_SE')
3698336Ssteve.reinhardt@amd.com    (build_root, build_dir) = os.path.split(build_path)
3708336Ssteve.reinhardt@amd.com    # Make a copy of the build-root environment to use for this config.
37111401Sandreas.sandberg@arm.com    env = base_env.Copy()
37211401Sandreas.sandberg@arm.com
3738336Ssteve.reinhardt@amd.com    # Set env options according to the build directory config.
3748336Ssteve.reinhardt@amd.com    sticky_opts.files = []
3758336Ssteve.reinhardt@amd.com    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
3765871Snate@binkert.org    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
37711476Sandreas.sandberg@arm.com    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
37811476Sandreas.sandberg@arm.com    current_opts_file = os.path.join(build_root, 'options', build_dir)
37911476Sandreas.sandberg@arm.com    if os.path.isfile(current_opts_file):
38011476Sandreas.sandberg@arm.com        sticky_opts.files.append(current_opts_file)
38111476Sandreas.sandberg@arm.com        print "Using saved options file %s" % current_opts_file
38211476Sandreas.sandberg@arm.com    else:
38311476Sandreas.sandberg@arm.com        # Build dir-specific options file doesn't exist.
38411476Sandreas.sandberg@arm.com
38511476Sandreas.sandberg@arm.com        # Make sure the directory is there so we can create it later
38611887Sandreas.sandberg@arm.com        opt_dir = os.path.dirname(current_opts_file)
38711887Sandreas.sandberg@arm.com        if not os.path.isdir(opt_dir):
38811887Sandreas.sandberg@arm.com            os.mkdir(opt_dir)
38911408Sandreas.sandberg@arm.com
39011887Sandreas.sandberg@arm.com        # Get default build options from source tree.  Options are
39111887Sandreas.sandberg@arm.com        # normally determined by name of $BUILD_DIR, but can be
39211887Sandreas.sandberg@arm.com        # overriden by 'default=' arg on command line.
39311887Sandreas.sandberg@arm.com        default_opts_file = os.path.join('build_opts',
39411887Sandreas.sandberg@arm.com                                         ARGUMENTS.get('default', build_dir))
39511887Sandreas.sandberg@arm.com        if os.path.isfile(default_opts_file):
39611887Sandreas.sandberg@arm.com            sticky_opts.files.append(default_opts_file)
39711887Sandreas.sandberg@arm.com            print "Options file %s not found,\n  using defaults in %s" \
39811887Sandreas.sandberg@arm.com                  % (current_opts_file, default_opts_file)
39911887Sandreas.sandberg@arm.com        else:
40011887Sandreas.sandberg@arm.com            print "Error: cannot find options file %s or %s" \
40111887Sandreas.sandberg@arm.com                  % (current_opts_file, default_opts_file)
40211887Sandreas.sandberg@arm.com            Exit(1)
40311887Sandreas.sandberg@arm.com
40411887Sandreas.sandberg@arm.com    # Apply current option settings to env
40511887Sandreas.sandberg@arm.com    sticky_opts.Update(env)
40611887Sandreas.sandberg@arm.com    nonsticky_opts.Update(env)
40711887Sandreas.sandberg@arm.com
40811887Sandreas.sandberg@arm.com    help_text += "Sticky options for %s:\n" % build_dir \
40911887Sandreas.sandberg@arm.com                 + sticky_opts.GenerateHelpText(env) \
41011887Sandreas.sandberg@arm.com                 + "\nNon-sticky options for %s:\n" % build_dir \
41111887Sandreas.sandberg@arm.com                 + nonsticky_opts.GenerateHelpText(env)
41211887Sandreas.sandberg@arm.com
41311887Sandreas.sandberg@arm.com    # Process option settings.
41411476Sandreas.sandberg@arm.com
41511476Sandreas.sandberg@arm.com    if not have_fenv and env['USE_FENV']:
41611408Sandreas.sandberg@arm.com        print "Warning: <fenv.h> not available; " \
41711408Sandreas.sandberg@arm.com              "forcing USE_FENV to False in", build_dir + "."
41811408Sandreas.sandberg@arm.com        env['USE_FENV'] = False
41911408Sandreas.sandberg@arm.com
42011408Sandreas.sandberg@arm.com    if not env['USE_FENV']:
42111408Sandreas.sandberg@arm.com        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
42211408Sandreas.sandberg@arm.com        print "         FP results may deviate slightly from other platforms."
42311887Sandreas.sandberg@arm.com
42411887Sandreas.sandberg@arm.com    if env['EFENCE']:
42511476Sandreas.sandberg@arm.com        env.Append(LIBS=['efence'])
42611887Sandreas.sandberg@arm.com
42711887Sandreas.sandberg@arm.com    if env['USE_MYSQL']:
42811476Sandreas.sandberg@arm.com        if not have_mysql:
42911476Sandreas.sandberg@arm.com            print "Warning: MySQL not available; " \
43011476Sandreas.sandberg@arm.com                  "forcing USE_MYSQL to False in", build_dir + "."
43111476Sandreas.sandberg@arm.com            env['USE_MYSQL'] = False
4326121Snate@binkert.org        else:
433955SN/A            print "Compiling in", build_dir, "with MySQL support."
434955SN/A            env.ParseConfig(mysql_config_libs)
4352632Sstever@eecs.umich.edu            env.ParseConfig(mysql_config_include)
4362632Sstever@eecs.umich.edu
437955SN/A    # Save sticky option settings back to current options file
438955SN/A    sticky_opts.Save(current_opts_file, env)
439955SN/A
440955SN/A    # Do this after we save setting back, or else we'll tack on an
4418878Ssteve.reinhardt@amd.com    # extra 'qdo' every time we run scons.
442955SN/A    if env['BATCH']:
4432632Sstever@eecs.umich.edu        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4442632Sstever@eecs.umich.edu        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4452632Sstever@eecs.umich.edu
4462632Sstever@eecs.umich.edu    if env['USE_SSE2']:
4472632Sstever@eecs.umich.edu        env.Append(CCFLAGS='-msse2')
4482632Sstever@eecs.umich.edu
4492632Sstever@eecs.umich.edu    # The m5/SConscript file sets up the build rules in 'env' according
4508268Ssteve.reinhardt@amd.com    # to the configured options.  It returns a list of environments,
4518268Ssteve.reinhardt@amd.com    # one for each variant build (debug, opt, etc.)
4528268Ssteve.reinhardt@amd.com    envList = SConscript('src/SConscript', build_dir = build_path,
4538268Ssteve.reinhardt@amd.com                         exports = 'env', duplicate = False)
4548268Ssteve.reinhardt@amd.com
4558268Ssteve.reinhardt@amd.com    # Set up the regression tests for each build.
4568268Ssteve.reinhardt@amd.com#    for e in envList:
4572632Sstever@eecs.umich.edu#        SConscript('m5-test/SConscript',
4582632Sstever@eecs.umich.edu#                   build_dir = os.path.join(build_dir, 'test', e.Label),
4592632Sstever@eecs.umich.edu#                   exports = { 'env' : e }, duplicate = False)
4602632Sstever@eecs.umich.edu
4618268Ssteve.reinhardt@amd.comHelp(help_text)
4622632Sstever@eecs.umich.edu
4638268Ssteve.reinhardt@amd.com###################################################
4648268Ssteve.reinhardt@amd.com#
4658268Ssteve.reinhardt@amd.com# Let SCons do its thing.  At this point SCons will use the defined
4668268Ssteve.reinhardt@amd.com# build environments to build the requested targets.
4673718Sstever@eecs.umich.edu#
4682634Sstever@eecs.umich.edu###################################################
4692634Sstever@eecs.umich.edu
4705863Snate@binkert.org