SConstruct revision 2667
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# Authors: Steve Reinhardt
30955SN/A
31955SN/A###################################################
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>'
37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
38955SN/A# the optimized full-system version).
39955SN/A#
40955SN/A# 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
422665Ssaidi@eecs.umich.edu# expdects that all configs under the same build directory are being
432665Ssaidi@eecs.umich.edu# built for the same host system.
445863Snate@binkert.org#
45955SN/A# Examples:
46955SN/A#   These two commands are equivalent.  The '-u' option tells scons to
47955SN/A#   search up the directory tree for this SConstruct file.
48955SN/A#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
49955SN/A#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
508878Ssteve.reinhardt@amd.com#   These two commands are equivalent and demonstrate building in a
512632Sstever@eecs.umich.edu#   directory outside of the source tree.  The '-C' option tells scons
528878Ssteve.reinhardt@amd.com#   to chdir to the specified directory to find this SConstruct file.
532632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
54955SN/A#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
558878Ssteve.reinhardt@amd.com#
562632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
572761Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
582632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
592632Sstever@eecs.umich.edu# options as well.
602632Sstever@eecs.umich.edu#
612761Sstever@eecs.umich.edu###################################################
622761Sstever@eecs.umich.edu
632761Sstever@eecs.umich.edu# Python library imports
648878Ssteve.reinhardt@amd.comimport sys
658878Ssteve.reinhardt@amd.comimport os
662761Sstever@eecs.umich.edu
672761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions.  If your system's
682761Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a
692761Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1)
702761Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python'
718878Ssteve.reinhardt@amd.com# first or (2) explicitly invoking an alternative interpreter on the
728878Ssteve.reinhardt@amd.com# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
732632Sstever@eecs.umich.eduEnsurePythonVersion(2,4)
742632Sstever@eecs.umich.edu
758878Ssteve.reinhardt@amd.com# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
768878Ssteve.reinhardt@amd.com# 3-element version number.
772632Sstever@eecs.umich.edumin_scons_version = (0,96,91)
78955SN/Atry:
79955SN/A    EnsureSConsVersion(*min_scons_version)
80955SN/Aexcept:
815863Snate@binkert.org    print "Error checking current SCons version."
825863Snate@binkert.org    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
835863Snate@binkert.org    Exit(2)
845863Snate@binkert.org    
855863Snate@binkert.org
865863Snate@binkert.org# The absolute path to the current directory (where this file lives).
875863Snate@binkert.orgROOT = Dir('.').abspath
885863Snate@binkert.org
895863Snate@binkert.org# Paths to the M5 and external source trees.
905863Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src')
915863Snate@binkert.org
928878Ssteve.reinhardt@amd.com# tell python where to find m5 python code
935863Snate@binkert.orgsys.path.append(os.path.join(ROOT, 'src/python'))
945863Snate@binkert.org
955863Snate@binkert.org###################################################
969812Sandreas.hansson@arm.com#
979812Sandreas.hansson@arm.com# Figure out which configurations to set up based on the path(s) of
985863Snate@binkert.org# the target(s).
999812Sandreas.hansson@arm.com#
1005863Snate@binkert.org###################################################
1015863Snate@binkert.org
1025863Snate@binkert.org# Find default configuration & binary.
1039812Sandreas.hansson@arm.comDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1049812Sandreas.hansson@arm.com
1055863Snate@binkert.org# Ask SCons which directory it was invoked from.
1065863Snate@binkert.orglaunch_dir = GetLaunchDir()
1078878Ssteve.reinhardt@amd.com
1085863Snate@binkert.org# Make targets relative to invocation directory
1095863Snate@binkert.orgabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1105863Snate@binkert.org                  BUILD_TARGETS)
1116654Snate@binkert.org
11210196SCurtis.Dunham@arm.com# helper function: find last occurrence of element in list
113955SN/Adef rfind(l, elt, offs = -1):
1145396Ssaidi@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1155863Snate@binkert.org        if l[i] == elt:
1165863Snate@binkert.org            return i
1174202Sbinkertn@umich.edu    raise ValueError, "element not found"
1185863Snate@binkert.org
1195863Snate@binkert.org# Each target must have 'build' in the interior of the path; the
1205863Snate@binkert.org# directory below this will determine the build parameters.  For
1215863Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
122955SN/A# recognize that ALPHA_SE specifies the configuration because it
1236654Snate@binkert.org# follow 'build' in the bulid path.
1245273Sstever@gmail.com
1255871Snate@binkert.org# Generate a list of the unique build roots and configs that the
1265273Sstever@gmail.com# collected targets reference.
1276655Snate@binkert.orgbuild_paths = []
1288878Ssteve.reinhardt@amd.combuild_root = None
1296655Snate@binkert.orgfor t in abs_targets:
1306655Snate@binkert.org    path_dirs = t.split('/')
1319219Spower.jg@gmail.com    try:
1326655Snate@binkert.org        build_top = rfind(path_dirs, 'build', -2)
1335871Snate@binkert.org    except:
1346654Snate@binkert.org        print "Error: no non-leaf 'build' dir found on target path", t
1358947Sandreas.hansson@arm.com        Exit(1)
1365396Ssaidi@eecs.umich.edu    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1378120Sgblack@eecs.umich.edu    if not build_root:
1388120Sgblack@eecs.umich.edu        build_root = this_build_root
1398120Sgblack@eecs.umich.edu    else:
1408120Sgblack@eecs.umich.edu        if this_build_root != build_root:
1418120Sgblack@eecs.umich.edu            print "Error: build targets not under same build root\n"\
1428120Sgblack@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
1438120Sgblack@eecs.umich.edu            Exit(1)
1448120Sgblack@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1458879Ssteve.reinhardt@amd.com    if build_path not in build_paths:
1468879Ssteve.reinhardt@amd.com        build_paths.append(build_path)
1478879Ssteve.reinhardt@amd.com
1488879Ssteve.reinhardt@amd.com###################################################
1498879Ssteve.reinhardt@amd.com#
1508879Ssteve.reinhardt@amd.com# Set up the default build environment.  This environment is copied
1518879Ssteve.reinhardt@amd.com# and modified according to each selected configuration.
1528879Ssteve.reinhardt@amd.com#
1538879Ssteve.reinhardt@amd.com###################################################
1548879Ssteve.reinhardt@amd.com
1558879Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
1568879Ssteve.reinhardt@amd.com                  ROOT = ROOT,
1578879Ssteve.reinhardt@amd.com                  SRCDIR = SRCDIR)
1588120Sgblack@eecs.umich.edu
1598120Sgblack@eecs.umich.eduenv.SConsignFile("sconsign")
1608120Sgblack@eecs.umich.edu
1618120Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up
1628120Sgblack@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
1638120Sgblack@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
1648120Sgblack@eecs.umich.edu# (soft) links work better.
1658120Sgblack@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy')
1668120Sgblack@eecs.umich.edu
1678120Sgblack@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but
1688120Sgblack@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take
1698120Sgblack@eecs.umich.edu# noticeably longer.
1708120Sgblack@eecs.umich.eduif False:
1718120Sgblack@eecs.umich.edu    env.TargetSignatures('content')
1728879Ssteve.reinhardt@amd.com
1738879Ssteve.reinhardt@amd.com# M5_PLY is used by isa_parser.py to find the PLY package.
1748879Ssteve.reinhardt@amd.comenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1758879Ssteve.reinhardt@amd.com
17610458Sandreas.hansson@arm.com# Set up default C++ compiler flags
17710458Sandreas.hansson@arm.comenv.Append(CCFLAGS='-pipe')
17810458Sandreas.hansson@arm.comenv.Append(CCFLAGS='-fno-strict-aliasing')
1798879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1808879Ssteve.reinhardt@amd.comif sys.platform == 'cygwin':
1818879Ssteve.reinhardt@amd.com    # cygwin has some header file issues...
1828879Ssteve.reinhardt@amd.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1839227Sandreas.hansson@arm.comenv.Append(CPPPATH=[Dir('ext/dnet')])
1849227Sandreas.hansson@arm.com
1858879Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the
1868879Ssteve.reinhardt@amd.com# interpreter.  For consistency, we will use the same Python
1878879Ssteve.reinhardt@amd.com# installation used to run scons (and thus this script).  If you want
1888879Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how
18910453SAndrew.Bardsley@arm.com# to invoke scons with a different copy of the Python interpreter.
19010453SAndrew.Bardsley@arm.com
19110453SAndrew.Bardsley@arm.com# Get brief Python version name (e.g., "python2.4") for locating
19210456SCurtis.Dunham@arm.com# include & library files
19310456SCurtis.Dunham@arm.compy_version_name = 'python' + sys.version[:3]
19410456SCurtis.Dunham@arm.com
19510457Sandreas.hansson@arm.com# include path, e.g. /usr/local/include/python2.4
19610457Sandreas.hansson@arm.comenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
1978120Sgblack@eecs.umich.eduenv.Append(LIBS = py_version_name)
1988947Sandreas.hansson@arm.com# add library path too if it's not in the default place
1997816Ssteve.reinhardt@amd.comif sys.exec_prefix != '/usr':
2005871Snate@binkert.org    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
2015871Snate@binkert.org
2026121Snate@binkert.org# Set up SWIG flags & scanner
2035871Snate@binkert.org
2045871Snate@binkert.orgenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2059926Sstan.czerniawski@arm.com
2069926Sstan.czerniawski@arm.comimport SCons.Scanner
2079119Sandreas.hansson@arm.com
20810068Sandreas.hansson@arm.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
20910068Sandreas.hansson@arm.com
210955SN/Aswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2119416SAndreas.Sandberg@ARM.com                                        swig_inc_re)
2129416SAndreas.Sandberg@ARM.com
2139416SAndreas.Sandberg@ARM.comenv.Append(SCANNERS = swig_scanner)
2149416SAndreas.Sandberg@ARM.com
2159416SAndreas.Sandberg@ARM.com# Other default libraries
2169416SAndreas.Sandberg@ARM.comenv.Append(LIBS=['z'])
2179416SAndreas.Sandberg@ARM.com
2185871Snate@binkert.org# Platform-specific configuration.  Note again that we assume that all
21910584Sandreas.hansson@arm.com# builds under a given build root run on the same host platform.
2209416SAndreas.Sandberg@ARM.comconf = Configure(env,
2219416SAndreas.Sandberg@ARM.com                 conf_dir = os.path.join(build_root, '.scons_config'),
2225871Snate@binkert.org                 log_file = os.path.join(build_root, 'scons_config.log'))
223955SN/A
22410671Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control)
22510671Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
22610671Sandreas.hansson@arm.comif not have_fenv:
22710671Sandreas.hansson@arm.com    print "Warning: Header file <fenv.h> not found."
2288881Smarc.orr@gmail.com    print "         This host has no IEEE FP rounding mode control."
2296121Snate@binkert.org
2306121Snate@binkert.org# Check for mysql.
2311533SN/Amysql_config = WhereIs('mysql_config')
2329239Sandreas.hansson@arm.comhave_mysql = mysql_config != None
2339239Sandreas.hansson@arm.com
2349239Sandreas.hansson@arm.com# Check MySQL version.
2359239Sandreas.hansson@arm.comif have_mysql:
2369239Sandreas.hansson@arm.com    mysql_version = os.popen(mysql_config + ' --version').read()
2379239Sandreas.hansson@arm.com    mysql_version = mysql_version.split('.')
2389239Sandreas.hansson@arm.com    mysql_major = int(mysql_version[0])
2399239Sandreas.hansson@arm.com    mysql_minor = int(mysql_version[1])
2409239Sandreas.hansson@arm.com    # This version check is probably overly conservative, but it deals
2419239Sandreas.hansson@arm.com    # with the versions we have installed.
2429239Sandreas.hansson@arm.com    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2439239Sandreas.hansson@arm.com        print "Warning: MySQL v4.1 or newer required."
2446655Snate@binkert.org        have_mysql = False
2456655Snate@binkert.org
2466655Snate@binkert.org# Set up mysql_config commands.
2476655Snate@binkert.orgif have_mysql:
2485871Snate@binkert.org    mysql_config_include = mysql_config + ' --include'
2495871Snate@binkert.org    if os.system(mysql_config_include + ' > /dev/null') != 0:
2505863Snate@binkert.org        # older mysql_config versions don't support --include, use
2515871Snate@binkert.org        # --cflags instead
2528878Ssteve.reinhardt@amd.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2535871Snate@binkert.org    # This seems to work in all versions
2545871Snate@binkert.org    mysql_config_libs = mysql_config + ' --libs'
2555871Snate@binkert.org
2565863Snate@binkert.orgenv = conf.Finish()
2576121Snate@binkert.org
2585863Snate@binkert.org# Define the universe of supported ISAs
2595871Snate@binkert.orgenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2608336Ssteve.reinhardt@amd.com
2618336Ssteve.reinhardt@amd.com# Define the universe of supported CPU models
2628336Ssteve.reinhardt@amd.comenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2638336Ssteve.reinhardt@amd.com                       'FullCPU', 'AlphaFullCPU']
2644678Snate@binkert.org
2658336Ssteve.reinhardt@amd.com# Sticky options get saved in the options file so they persist from
2668336Ssteve.reinhardt@amd.com# one invocation to the next (unless overridden, in which case the new
2678336Ssteve.reinhardt@amd.com# value becomes sticky).
2684678Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS)
2694678Snate@binkert.orgsticky_opts.AddOptions(
2704678Snate@binkert.org    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2714678Snate@binkert.org    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2727827Snate@binkert.org    # There's a bug in scons 0.96.1 that causes ListOptions with list
2737827Snate@binkert.org    # values (more than one value) not to be able to be restored from
2748336Ssteve.reinhardt@amd.com    # a saved option file.  If this causes trouble then upgrade to
2754678Snate@binkert.org    # scons 0.96.90 or later.
2768336Ssteve.reinhardt@amd.com    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2778336Ssteve.reinhardt@amd.com               env['ALL_CPU_LIST']),
2788336Ssteve.reinhardt@amd.com    BoolOption('ALPHA_TLASER',
2798336Ssteve.reinhardt@amd.com               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2808336Ssteve.reinhardt@amd.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2818336Ssteve.reinhardt@amd.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2825871Snate@binkert.org               False),
2835871Snate@binkert.org    BoolOption('SS_COMPATIBLE_FP',
2848336Ssteve.reinhardt@amd.com               'Make floating-point results compatible with SimpleScalar',
2858336Ssteve.reinhardt@amd.com               False),
2868336Ssteve.reinhardt@amd.com    BoolOption('USE_SSE2',
2878336Ssteve.reinhardt@amd.com               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2888336Ssteve.reinhardt@amd.com               False),
2895871Snate@binkert.org    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2908336Ssteve.reinhardt@amd.com    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2918336Ssteve.reinhardt@amd.com    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2928336Ssteve.reinhardt@amd.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2938336Ssteve.reinhardt@amd.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2948336Ssteve.reinhardt@amd.com    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2954678Snate@binkert.org    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2965871Snate@binkert.org    )
2974678Snate@binkert.org
2988336Ssteve.reinhardt@amd.com# Non-sticky options only apply to the current build.
2998336Ssteve.reinhardt@amd.comnonsticky_opts = Options(args=ARGUMENTS)
3008336Ssteve.reinhardt@amd.comnonsticky_opts.AddOptions(
3018336Ssteve.reinhardt@amd.com    BoolOption('update_ref', 'Update test reference outputs', False)
3028336Ssteve.reinhardt@amd.com    )
3038336Ssteve.reinhardt@amd.com
3048336Ssteve.reinhardt@amd.com# These options get exported to #defines in config/*.hh (see m5/SConscript).
3058336Ssteve.reinhardt@amd.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3068336Ssteve.reinhardt@amd.com                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3078336Ssteve.reinhardt@amd.com                     'STATS_BINNING']
3088336Ssteve.reinhardt@amd.com
3098336Ssteve.reinhardt@amd.com# Define a handy 'no-op' action
3108336Ssteve.reinhardt@amd.comdef no_action(target, source, env):
3118336Ssteve.reinhardt@amd.com    return 0
3128336Ssteve.reinhardt@amd.com
3138336Ssteve.reinhardt@amd.comenv.NoAction = Action(no_action, None)
3148336Ssteve.reinhardt@amd.com
3155871Snate@binkert.org###################################################
3166121Snate@binkert.org#
317955SN/A# Define a SCons builder for configuration flag headers.
318955SN/A#
3192632Sstever@eecs.umich.edu###################################################
3202632Sstever@eecs.umich.edu
321955SN/A# This function generates a config header file that #defines the
322955SN/A# option symbol to the current option setting (0 or 1).  The source
323955SN/A# operands are the name of the option and a Value node containing the
324955SN/A# value of the option.
3258878Ssteve.reinhardt@amd.comdef build_config_file(target, source, env):
326955SN/A    (option, value) = [s.get_contents() for s in source]
3272632Sstever@eecs.umich.edu    f = file(str(target[0]), 'w')
3282632Sstever@eecs.umich.edu    print >> f, '#define', option, value
3292632Sstever@eecs.umich.edu    f.close()
3302632Sstever@eecs.umich.edu    return None
3312632Sstever@eecs.umich.edu
3322632Sstever@eecs.umich.edu# Generate the message to be printed when building the config file.
3332632Sstever@eecs.umich.edudef build_config_file_string(target, source, env):
3348268Ssteve.reinhardt@amd.com    (option, value) = [s.get_contents() for s in source]
3358268Ssteve.reinhardt@amd.com    return "Defining %s as %s in %s." % (option, value, target[0])
3368268Ssteve.reinhardt@amd.com
3378268Ssteve.reinhardt@amd.com# Combine the two functions into a scons Action object.
3388268Ssteve.reinhardt@amd.comconfig_action = Action(build_config_file, build_config_file_string)
3398268Ssteve.reinhardt@amd.com
3408268Ssteve.reinhardt@amd.com# The emitter munges the source & target node lists to reflect what
3412632Sstever@eecs.umich.edu# we're really doing.
3422632Sstever@eecs.umich.edudef config_emitter(target, source, env):
3432632Sstever@eecs.umich.edu    # extract option name from Builder arg
3442632Sstever@eecs.umich.edu    option = str(target[0])
3458268Ssteve.reinhardt@amd.com    # True target is config header file
3462632Sstever@eecs.umich.edu    target = os.path.join('config', option.lower() + '.hh')
3478268Ssteve.reinhardt@amd.com    # Force value to 0/1 even if it's a Python bool
3488268Ssteve.reinhardt@amd.com    val = int(eval(str(env[option])))
3498268Ssteve.reinhardt@amd.com    # Sources are option name & value (packaged in SCons Value nodes)
3508268Ssteve.reinhardt@amd.com    return ([target], [Value(option), Value(val)])
3513718Sstever@eecs.umich.edu
3522634Sstever@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action)
3532634Sstever@eecs.umich.edu
3545863Snate@binkert.orgenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3552638Sstever@eecs.umich.edu
3568268Ssteve.reinhardt@amd.com###################################################
3572632Sstever@eecs.umich.edu#
3582632Sstever@eecs.umich.edu# Define a SCons builder for copying files.  This is used by the
3592632Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here
3602632Sstever@eecs.umich.edu# since it's potentially more generally applicable.
3612632Sstever@eecs.umich.edu#
3621858SN/A###################################################
3633716Sstever@eecs.umich.edu
3642638Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3652638Sstever@eecs.umich.edu
3662638Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3672638Sstever@eecs.umich.edu
3682638Sstever@eecs.umich.edu###################################################
3692638Sstever@eecs.umich.edu#
3702638Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files.
3715863Snate@binkert.org#
3725863Snate@binkert.org# Used to append the Python zip archive to the executable.
3735863Snate@binkert.org#
374955SN/A###################################################
3755341Sstever@gmail.com
3765341Sstever@gmail.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3775863Snate@binkert.org                                          'chmod +x $TARGET']))
3787756SAli.Saidi@ARM.com
3795341Sstever@gmail.comenv.Append(BUILDERS = { 'Concat' : concat_builder })
3806121Snate@binkert.org
3814494Ssaidi@eecs.umich.edu
3826121Snate@binkert.org# base help text
3831105SN/Ahelp_text = '''
3842667Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)]
3852667Sstever@eecs.umich.edu
3862667Sstever@eecs.umich.edu'''
3872667Sstever@eecs.umich.edu
3886121Snate@binkert.org# libelf build is shared across all configs in the build root.
3892667Sstever@eecs.umich.eduenv.SConscript('ext/libelf/SConscript',
3905341Sstever@gmail.com               build_dir = os.path.join(build_root, 'libelf'),
3915863Snate@binkert.org               exports = 'env')
3925341Sstever@gmail.com
3935341Sstever@gmail.com###################################################
3945341Sstever@gmail.com#
3958120Sgblack@eecs.umich.edu# Define build environments for selected configurations.
3965341Sstever@gmail.com#
3978120Sgblack@eecs.umich.edu###################################################
3985341Sstever@gmail.com
3998120Sgblack@eecs.umich.edu# rename base env
4006121Snate@binkert.orgbase_env = env
4016121Snate@binkert.org
4028980Ssteve.reinhardt@amd.comfor build_path in build_paths:
4039396Sandreas.hansson@arm.com    print "Building in", build_path
4045397Ssaidi@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
4055397Ssaidi@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
4067727SAli.Saidi@ARM.com    (build_root, build_dir) = os.path.split(build_path)
4078268Ssteve.reinhardt@amd.com    # Make a copy of the build-root environment to use for this config.
4086168Snate@binkert.org    env = base_env.Copy()
4095341Sstever@gmail.com
4108120Sgblack@eecs.umich.edu    # Set env options according to the build directory config.
4118120Sgblack@eecs.umich.edu    sticky_opts.files = []
4128120Sgblack@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
4136814Sgblack@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
4145863Snate@binkert.org    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
4158120Sgblack@eecs.umich.edu    current_opts_file = os.path.join(build_root, 'options', build_dir)
4165341Sstever@gmail.com    if os.path.isfile(current_opts_file):
4175863Snate@binkert.org        sticky_opts.files.append(current_opts_file)
4188268Ssteve.reinhardt@amd.com        print "Using saved options file %s" % current_opts_file
4196121Snate@binkert.org    else:
4206121Snate@binkert.org        # Build dir-specific options file doesn't exist.
4218268Ssteve.reinhardt@amd.com
4225742Snate@binkert.org        # Make sure the directory is there so we can create it later
4235742Snate@binkert.org        opt_dir = os.path.dirname(current_opts_file)
4245341Sstever@gmail.com        if not os.path.isdir(opt_dir):
4255742Snate@binkert.org            os.mkdir(opt_dir)
4265742Snate@binkert.org
4275341Sstever@gmail.com        # Get default build options from source tree.  Options are
4286017Snate@binkert.org        # normally determined by name of $BUILD_DIR, but can be
4296121Snate@binkert.org        # overriden by 'default=' arg on command line.
4306017Snate@binkert.org        default_opts_file = os.path.join('build_opts',
4317816Ssteve.reinhardt@amd.com                                         ARGUMENTS.get('default', build_dir))
4327756SAli.Saidi@ARM.com        if os.path.isfile(default_opts_file):
4337756SAli.Saidi@ARM.com            sticky_opts.files.append(default_opts_file)
4347756SAli.Saidi@ARM.com            print "Options file %s not found,\n  using defaults in %s" \
4357756SAli.Saidi@ARM.com                  % (current_opts_file, default_opts_file)
4367756SAli.Saidi@ARM.com        else:
4377756SAli.Saidi@ARM.com            print "Error: cannot find options file %s or %s" \
4387756SAli.Saidi@ARM.com                  % (current_opts_file, default_opts_file)
4397756SAli.Saidi@ARM.com            Exit(1)
4407816Ssteve.reinhardt@amd.com
4417816Ssteve.reinhardt@amd.com    # Apply current option settings to env
4427816Ssteve.reinhardt@amd.com    sticky_opts.Update(env)
4437816Ssteve.reinhardt@amd.com    nonsticky_opts.Update(env)
4447816Ssteve.reinhardt@amd.com
4457816Ssteve.reinhardt@amd.com    help_text += "Sticky options for %s:\n" % build_dir \
4467816Ssteve.reinhardt@amd.com                 + sticky_opts.GenerateHelpText(env) \
4477816Ssteve.reinhardt@amd.com                 + "\nNon-sticky options for %s:\n" % build_dir \
4487816Ssteve.reinhardt@amd.com                 + nonsticky_opts.GenerateHelpText(env)
4497816Ssteve.reinhardt@amd.com
4507756SAli.Saidi@ARM.com    # Process option settings.
4517816Ssteve.reinhardt@amd.com
4527816Ssteve.reinhardt@amd.com    if not have_fenv and env['USE_FENV']:
4537816Ssteve.reinhardt@amd.com        print "Warning: <fenv.h> not available; " \
4547816Ssteve.reinhardt@amd.com              "forcing USE_FENV to False in", build_dir + "."
4557816Ssteve.reinhardt@amd.com        env['USE_FENV'] = False
4567816Ssteve.reinhardt@amd.com
4577816Ssteve.reinhardt@amd.com    if not env['USE_FENV']:
4587816Ssteve.reinhardt@amd.com        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4597816Ssteve.reinhardt@amd.com        print "         FP results may deviate slightly from other platforms."
4607816Ssteve.reinhardt@amd.com
4617816Ssteve.reinhardt@amd.com    if env['EFENCE']:
4627816Ssteve.reinhardt@amd.com        env.Append(LIBS=['efence'])
4637816Ssteve.reinhardt@amd.com
4647816Ssteve.reinhardt@amd.com    if env['USE_MYSQL']:
4657816Ssteve.reinhardt@amd.com        if not have_mysql:
4667816Ssteve.reinhardt@amd.com            print "Warning: MySQL not available; " \
4677816Ssteve.reinhardt@amd.com                  "forcing USE_MYSQL to False in", build_dir + "."
4687816Ssteve.reinhardt@amd.com            env['USE_MYSQL'] = False
4697816Ssteve.reinhardt@amd.com        else:
4707816Ssteve.reinhardt@amd.com            print "Compiling in", build_dir, "with MySQL support."
4717816Ssteve.reinhardt@amd.com            env.ParseConfig(mysql_config_libs)
4727816Ssteve.reinhardt@amd.com            env.ParseConfig(mysql_config_include)
4737816Ssteve.reinhardt@amd.com
4747816Ssteve.reinhardt@amd.com    # Save sticky option settings back to current options file
4757816Ssteve.reinhardt@amd.com    sticky_opts.Save(current_opts_file, env)
4767816Ssteve.reinhardt@amd.com
4777816Ssteve.reinhardt@amd.com    # Do this after we save setting back, or else we'll tack on an
4787816Ssteve.reinhardt@amd.com    # extra 'qdo' every time we run scons.
4797816Ssteve.reinhardt@amd.com    if env['BATCH']:
4807816Ssteve.reinhardt@amd.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4817816Ssteve.reinhardt@amd.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4827816Ssteve.reinhardt@amd.com
4837816Ssteve.reinhardt@amd.com    if env['USE_SSE2']:
4847816Ssteve.reinhardt@amd.com        env.Append(CCFLAGS='-msse2')
4857816Ssteve.reinhardt@amd.com
4867816Ssteve.reinhardt@amd.com    # The m5/SConscript file sets up the build rules in 'env' according
4877816Ssteve.reinhardt@amd.com    # to the configured options.  It returns a list of environments,
4887816Ssteve.reinhardt@amd.com    # one for each variant build (debug, opt, etc.)
4897816Ssteve.reinhardt@amd.com    envList = SConscript('src/SConscript', build_dir = build_path,
4907816Ssteve.reinhardt@amd.com                         exports = 'env')
4917816Ssteve.reinhardt@amd.com
4927816Ssteve.reinhardt@amd.com    # Set up the regression tests for each build.
4937816Ssteve.reinhardt@amd.com#    for e in envList:
4947816Ssteve.reinhardt@amd.com#        SConscript('m5-test/SConscript',
4957816Ssteve.reinhardt@amd.com#                   build_dir = os.path.join(build_dir, 'test', e.Label),
4967816Ssteve.reinhardt@amd.com#                   exports = { 'env' : e }, duplicate = False)
4977816Ssteve.reinhardt@amd.com
4987816Ssteve.reinhardt@amd.comHelp(help_text)
4997816Ssteve.reinhardt@amd.com
5007816Ssteve.reinhardt@amd.com###################################################
5017816Ssteve.reinhardt@amd.com#
5027816Ssteve.reinhardt@amd.com# Let SCons do its thing.  At this point SCons will use the defined
5037816Ssteve.reinhardt@amd.com# build environments to build the requested targets.
5047816Ssteve.reinhardt@amd.com#
5057816Ssteve.reinhardt@amd.com###################################################
5067816Ssteve.reinhardt@amd.com
5077816Ssteve.reinhardt@amd.com