SConstruct revision 2733
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
4955SN/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.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
30955SN/A
31955SN/A###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
352632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default
362632Sstever@eecs.umich.edu# 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).
39955SN/A#
402632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a
412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
422761Sstever@eecs.umich.edu# expdects that all configs under the same build directory are being
432632Sstever@eecs.umich.edu# built for the same host system.
442632Sstever@eecs.umich.edu#
452632Sstever@eecs.umich.edu# Examples:
462761Sstever@eecs.umich.edu#   These two commands are equivalent.  The '-u' option tells scons to
472761Sstever@eecs.umich.edu#   search up the directory tree for this SConstruct file.
482761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
492632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
502632Sstever@eecs.umich.edu#   These two commands are equivalent and demonstrate building in a
512761Sstever@eecs.umich.edu#   directory outside of the source tree.  The '-C' option tells scons
522761Sstever@eecs.umich.edu#   to chdir to the specified directory to find this SConstruct file.
532761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
542761Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
552761Sstever@eecs.umich.edu#
562632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
572632Sstever@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#
612632Sstever@eecs.umich.edu###################################################
622632Sstever@eecs.umich.edu
63955SN/A# Python library imports
64955SN/Aimport sys
65955SN/Aimport os
66955SN/A
67955SN/A# Check for recent-enough Python and SCons versions.  If your system's
68955SN/A# default installation of Python is not recent enough, you can use a
693716Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1)
70955SN/A# rearranging your PATH so that scons finds the non-default 'python'
712656Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the
722656Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
732656Sstever@eecs.umich.eduEnsurePythonVersion(2,4)
742656Sstever@eecs.umich.edu
752656Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
762656Sstever@eecs.umich.edu# 3-element version number.
772656Sstever@eecs.umich.edumin_scons_version = (0,96,91)
782653Sstever@eecs.umich.edutry:
792653Sstever@eecs.umich.edu    EnsureSConsVersion(*min_scons_version)
802653Sstever@eecs.umich.eduexcept:
812653Sstever@eecs.umich.edu    print "Error checking current SCons version."
822653Sstever@eecs.umich.edu    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
832653Sstever@eecs.umich.edu    Exit(2)
842653Sstever@eecs.umich.edu    
852653Sstever@eecs.umich.edu
862653Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives).
872653Sstever@eecs.umich.eduROOT = Dir('.').abspath
882653Sstever@eecs.umich.edu
891852SN/A# Paths to the M5 and external source trees.
90955SN/ASRCDIR = os.path.join(ROOT, 'src')
91955SN/A
92955SN/A# tell python where to find m5 python code
933717Sstever@eecs.umich.edusys.path.append(os.path.join(ROOT, 'src/python'))
943716Sstever@eecs.umich.edu
95955SN/A###################################################
961533SN/A#
973716Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
981533SN/A# the target(s).
99955SN/A#
100955SN/A###################################################
1012632Sstever@eecs.umich.edu
1022632Sstever@eecs.umich.edu# Find default configuration & binary.
103955SN/ADefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
104955SN/A
105955SN/A# Ask SCons which directory it was invoked from.
106955SN/Alaunch_dir = GetLaunchDir()
1072632Sstever@eecs.umich.edu
108955SN/A# Make targets relative to invocation directory
1092632Sstever@eecs.umich.eduabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
110955SN/A                  BUILD_TARGETS)
111955SN/A
1122632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
1133716Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
1142632Sstever@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1152632Sstever@eecs.umich.edu        if l[i] == elt:
1162632Sstever@eecs.umich.edu            return i
1172632Sstever@eecs.umich.edu    raise ValueError, "element not found"
1182632Sstever@eecs.umich.edu
1192632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1202632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
1212632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1222632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1233053Sstever@eecs.umich.edu# follow 'build' in the bulid path.
1243053Sstever@eecs.umich.edu
1253053Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the
1263053Sstever@eecs.umich.edu# collected targets reference.
1273053Sstever@eecs.umich.edubuild_paths = []
1283053Sstever@eecs.umich.edubuild_root = None
1293053Sstever@eecs.umich.edufor t in abs_targets:
1303053Sstever@eecs.umich.edu    path_dirs = t.split('/')
1313053Sstever@eecs.umich.edu    try:
1323053Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1333053Sstever@eecs.umich.edu    except:
1343053Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1353053Sstever@eecs.umich.edu        Exit(1)
1363053Sstever@eecs.umich.edu    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1373053Sstever@eecs.umich.edu    if not build_root:
1383053Sstever@eecs.umich.edu        build_root = this_build_root
1392632Sstever@eecs.umich.edu    else:
1402632Sstever@eecs.umich.edu        if this_build_root != build_root:
1412632Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
1422632Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
1432632Sstever@eecs.umich.edu            Exit(1)
1442632Sstever@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1452634Sstever@eecs.umich.edu    if build_path not in build_paths:
1462634Sstever@eecs.umich.edu        build_paths.append(build_path)
1472632Sstever@eecs.umich.edu
1482638Sstever@eecs.umich.edu###################################################
1492632Sstever@eecs.umich.edu#
1502632Sstever@eecs.umich.edu# Set up the default build environment.  This environment is copied
1512632Sstever@eecs.umich.edu# and modified according to each selected configuration.
1522632Sstever@eecs.umich.edu#
1532632Sstever@eecs.umich.edu###################################################
1542632Sstever@eecs.umich.edu
1551858SN/Aenv = Environment(ENV = os.environ,  # inherit user's environment vars
1563716Sstever@eecs.umich.edu                  ROOT = ROOT,
1572638Sstever@eecs.umich.edu                  SRCDIR = SRCDIR)
1582638Sstever@eecs.umich.edu
1592638Sstever@eecs.umich.eduenv.SConsignFile("sconsign")
1602638Sstever@eecs.umich.edu
1612638Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up
1622638Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
1632638Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
1643716Sstever@eecs.umich.edu# (soft) links work better.
1652634Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy')
1662634Sstever@eecs.umich.edu
167955SN/A# I waffle on this setting... it does avoid a few painful but
168955SN/A# unnecessary builds, but it also seems to make trivial builds take
169955SN/A# noticeably longer.
170955SN/Aif False:
171955SN/A    env.TargetSignatures('content')
172955SN/A
173955SN/A# M5_PLY is used by isa_parser.py to find the PLY package.
174955SN/Aenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1751858SN/A
1761858SN/A# Set up default C++ compiler flags
1772632Sstever@eecs.umich.eduenv.Append(CCFLAGS='-pipe')
178955SN/Aenv.Append(CCFLAGS='-fno-strict-aliasing')
1793643Ssaidi@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1803643Ssaidi@eecs.umich.eduif sys.platform == 'cygwin':
1813643Ssaidi@eecs.umich.edu    # cygwin has some header file issues...
1823643Ssaidi@eecs.umich.edu    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1833643Ssaidi@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')])
1843643Ssaidi@eecs.umich.edu
1853643Ssaidi@eecs.umich.edu# Find Python include and library directories for embedding the
1863643Ssaidi@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
1873716Sstever@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
1881105SN/A# to link in an alternate version, see above for instructions on how
1892667Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
1902667Sstever@eecs.umich.edu
1912667Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating
1922667Sstever@eecs.umich.edu# include & library files
1932667Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3]
1942667Sstever@eecs.umich.edu
1951869SN/A# include path, e.g. /usr/local/include/python2.4
1961869SN/Aenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
1971869SN/Aenv.Append(LIBS = py_version_name)
1981869SN/A# add library path too if it's not in the default place
1991869SN/Aif sys.exec_prefix != '/usr':
2001065SN/A    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
2012632Sstever@eecs.umich.edu
2022632Sstever@eecs.umich.edu# Set up SWIG flags & scanner
203955SN/A
2041858SN/Aenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2051858SN/A
2061858SN/Aimport SCons.Scanner
2071858SN/A
2081851SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2091851SN/A
2101858SN/Aswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2112632Sstever@eecs.umich.edu                                        swig_inc_re)
212955SN/A
2133053Sstever@eecs.umich.eduenv.Append(SCANNERS = swig_scanner)
2143053Sstever@eecs.umich.edu
2153053Sstever@eecs.umich.edu# Other default libraries
2163053Sstever@eecs.umich.eduenv.Append(LIBS=['z'])
2173053Sstever@eecs.umich.edu
2183053Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
2193053Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
2203053Sstever@eecs.umich.educonf = Configure(env,
2213053Sstever@eecs.umich.edu                 conf_dir = os.path.join(build_root, '.scons_config'),
2223053Sstever@eecs.umich.edu                 log_file = os.path.join(build_root, 'scons_config.log'))
2233053Sstever@eecs.umich.edu
2243053Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
2253053Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
2263053Sstever@eecs.umich.eduif not have_fenv:
2273053Sstever@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
2283053Sstever@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
2293053Sstever@eecs.umich.edu
2303053Sstever@eecs.umich.edu# Check for mysql.
2313053Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config')
2322667Sstever@eecs.umich.eduhave_mysql = mysql_config != None
2332667Sstever@eecs.umich.edu
2342667Sstever@eecs.umich.edu# Check MySQL version.
2352667Sstever@eecs.umich.eduif have_mysql:
2362667Sstever@eecs.umich.edu    mysql_version = os.popen(mysql_config + ' --version').read()
2372667Sstever@eecs.umich.edu    mysql_version = mysql_version.split('.')
2382667Sstever@eecs.umich.edu    mysql_major = int(mysql_version[0])
2392667Sstever@eecs.umich.edu    mysql_minor = int(mysql_version[1])
2402667Sstever@eecs.umich.edu    # This version check is probably overly conservative, but it deals
2412667Sstever@eecs.umich.edu    # with the versions we have installed.
2422667Sstever@eecs.umich.edu    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2432667Sstever@eecs.umich.edu        print "Warning: MySQL v4.1 or newer required."
2442638Sstever@eecs.umich.edu        have_mysql = False
2452638Sstever@eecs.umich.edu
2462638Sstever@eecs.umich.edu# Set up mysql_config commands.
2473716Sstever@eecs.umich.eduif have_mysql:
2483716Sstever@eecs.umich.edu    mysql_config_include = mysql_config + ' --include'
2491858SN/A    if os.system(mysql_config_include + ' > /dev/null') != 0:
2503118Sstever@eecs.umich.edu        # older mysql_config versions don't support --include, use
2513118Sstever@eecs.umich.edu        # --cflags instead
2523118Sstever@eecs.umich.edu        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2533118Sstever@eecs.umich.edu    # This seems to work in all versions
2543118Sstever@eecs.umich.edu    mysql_config_libs = mysql_config + ' --libs'
2553118Sstever@eecs.umich.edu
2563118Sstever@eecs.umich.eduenv = conf.Finish()
2573118Sstever@eecs.umich.edu
2583118Sstever@eecs.umich.edu# Define the universe of supported ISAs
2593118Sstever@eecs.umich.eduenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2603118Sstever@eecs.umich.edu
2613716Sstever@eecs.umich.edu# Define the universe of supported CPU models
2623118Sstever@eecs.umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2633118Sstever@eecs.umich.edu                       'FullCPU', 'AlphaO3CPU',
2643118Sstever@eecs.umich.edu                       'OzoneSimpleCPU', 'OzoneCPU']
2653118Sstever@eecs.umich.edu
2663118Sstever@eecs.umich.edu# Sticky options get saved in the options file so they persist from
2673118Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
2683118Sstever@eecs.umich.edu# value becomes sticky).
2693118Sstever@eecs.umich.edusticky_opts = Options(args=ARGUMENTS)
2703118Sstever@eecs.umich.edusticky_opts.AddOptions(
2713716Sstever@eecs.umich.edu    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2723118Sstever@eecs.umich.edu    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2733118Sstever@eecs.umich.edu    # There's a bug in scons 0.96.1 that causes ListOptions with list
2743118Sstever@eecs.umich.edu    # values (more than one value) not to be able to be restored from
2753118Sstever@eecs.umich.edu    # a saved option file.  If this causes trouble then upgrade to
2763118Sstever@eecs.umich.edu    # scons 0.96.90 or later.
2773118Sstever@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2783118Sstever@eecs.umich.edu               env['ALL_CPU_LIST']),
2793118Sstever@eecs.umich.edu    BoolOption('ALPHA_TLASER',
2803118Sstever@eecs.umich.edu               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2813118Sstever@eecs.umich.edu    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2823483Ssaidi@eecs.umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2833494Ssaidi@eecs.umich.edu               False),
2843494Ssaidi@eecs.umich.edu    BoolOption('SS_COMPATIBLE_FP',
2853483Ssaidi@eecs.umich.edu               'Make floating-point results compatible with SimpleScalar',
2863483Ssaidi@eecs.umich.edu               False),
2873483Ssaidi@eecs.umich.edu    BoolOption('USE_SSE2',
2883053Sstever@eecs.umich.edu               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2893053Sstever@eecs.umich.edu               False),
2903053Sstever@eecs.umich.edu    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2913053Sstever@eecs.umich.edu    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2923053Sstever@eecs.umich.edu    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
2933053Sstever@eecs.umich.edu    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2943053Sstever@eecs.umich.edu    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2953053Sstever@eecs.umich.edu    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2961858SN/A    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2971858SN/A    )
2981858SN/A
2991858SN/A# Non-sticky options only apply to the current build.
3001858SN/Anonsticky_opts = Options(args=ARGUMENTS)
3011858SN/Anonsticky_opts.AddOptions(
3021859SN/A    BoolOption('update_ref', 'Update test reference outputs', False)
3031858SN/A    )
3041858SN/A
3051858SN/A# These options get exported to #defines in config/*.hh (see m5/SConscript).
3061859SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3071859SN/A                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3081862SN/A                     'USE_CHECKER']
3093053Sstever@eecs.umich.edu
3103053Sstever@eecs.umich.edu# Define a handy 'no-op' action
3113053Sstever@eecs.umich.edudef no_action(target, source, env):
3123053Sstever@eecs.umich.edu    return 0
3131859SN/A
3141859SN/Aenv.NoAction = Action(no_action, None)
3151859SN/A
3161859SN/A###################################################
3171859SN/A#
3181859SN/A# Define a SCons builder for configuration flag headers.
3191859SN/A#
3201859SN/A###################################################
3211862SN/A
3221859SN/A# This function generates a config header file that #defines the
3231859SN/A# option symbol to the current option setting (0 or 1).  The source
3241859SN/A# operands are the name of the option and a Value node containing the
3251858SN/A# value of the option.
3261858SN/Adef build_config_file(target, source, env):
3272139SN/A    (option, value) = [s.get_contents() for s in source]
3282139SN/A    f = file(str(target[0]), 'w')
3292139SN/A    print >> f, '#define', option, value
3302155SN/A    f.close()
3312623SN/A    return None
3323583Sbinkertn@umich.edu
3333583Sbinkertn@umich.edu# Generate the message to be printed when building the config file.
3343717Sstever@eecs.umich.edudef build_config_file_string(target, source, env):
3353583Sbinkertn@umich.edu    (option, value) = [s.get_contents() for s in source]
3362155SN/A    return "Defining %s as %s in %s." % (option, value, target[0])
3371869SN/A
3381869SN/A# Combine the two functions into a scons Action object.
3391869SN/Aconfig_action = Action(build_config_file, build_config_file_string)
3401869SN/A
3411869SN/A# The emitter munges the source & target node lists to reflect what
3422139SN/A# we're really doing.
3431869SN/Adef config_emitter(target, source, env):
3442508SN/A    # extract option name from Builder arg
3452508SN/A    option = str(target[0])
3462508SN/A    # True target is config header file
3472508SN/A    target = os.path.join('config', option.lower() + '.hh')
3483685Sktlim@umich.edu    # Force value to 0/1 even if it's a Python bool
3492635Sstever@eecs.umich.edu    val = int(eval(str(env[option])))
3501869SN/A    # Sources are option name & value (packaged in SCons Value nodes)
3511869SN/A    return ([target], [Value(option), Value(val)])
3521869SN/A
3531869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
3541869SN/A
3551869SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3561869SN/A
3571869SN/A###################################################
3581965SN/A#
3591965SN/A# Define a SCons builder for copying files.  This is used by the
3601965SN/A# Python zipfile code in src/python/SConscript, but is placed up here
3611869SN/A# since it's potentially more generally applicable.
3621869SN/A#
3632733Sktlim@umich.edu###################################################
3641869SN/A
3651884SN/Acopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3661884SN/A
3673356Sbinkertn@umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3683356Sbinkertn@umich.edu
3693356Sbinkertn@umich.edu###################################################
3703356Sbinkertn@umich.edu#
3711869SN/A# Define a simple SCons builder to concatenate files.
3721858SN/A#
3731869SN/A# Used to append the Python zip archive to the executable.
3741869SN/A#
3751869SN/A###################################################
3761869SN/A
3771869SN/Aconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3781858SN/A                                          'chmod +x $TARGET']))
3792761Sstever@eecs.umich.edu
3801869SN/Aenv.Append(BUILDERS = { 'Concat' : concat_builder })
3812733Sktlim@umich.edu
3823584Ssaidi@eecs.umich.edu
3831869SN/A# base help text
3841869SN/Ahelp_text = '''
3851869SN/AUsage: scons [scons options] [build options] [target(s)]
3861869SN/A
3871869SN/A'''
3881869SN/A
3891858SN/A# libelf build is shared across all configs in the build root.
390955SN/Aenv.SConscript('ext/libelf/SConscript',
391955SN/A               build_dir = os.path.join(build_root, 'libelf'),
3921869SN/A               exports = 'env')
3931869SN/A
3941869SN/A###################################################
3951869SN/A#
3961869SN/A# Define build environments for selected configurations.
3971869SN/A#
3981869SN/A###################################################
3991869SN/A
4001869SN/A# rename base env
4011869SN/Abase_env = env
4021869SN/A
4031869SN/Afor build_path in build_paths:
4041869SN/A    print "Building in", build_path
4051869SN/A    # build_dir is the tail component of build path, and is used to
4061869SN/A    # determine the build parameters (e.g., 'ALPHA_SE')
4071869SN/A    (build_root, build_dir) = os.path.split(build_path)
4081869SN/A    # Make a copy of the build-root environment to use for this config.
4091869SN/A    env = base_env.Copy()
4101869SN/A
4111869SN/A    # Set env options according to the build directory config.
4121869SN/A    sticky_opts.files = []
4131869SN/A    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
4141869SN/A    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
4151869SN/A    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
4161869SN/A    current_opts_file = os.path.join(build_root, 'options', build_dir)
4171869SN/A    if os.path.isfile(current_opts_file):
4181869SN/A        sticky_opts.files.append(current_opts_file)
4191869SN/A        print "Using saved options file %s" % current_opts_file
4201869SN/A    else:
4213716Sstever@eecs.umich.edu        # Build dir-specific options file doesn't exist.
4223356Sbinkertn@umich.edu
4233356Sbinkertn@umich.edu        # Make sure the directory is there so we can create it later
4243356Sbinkertn@umich.edu        opt_dir = os.path.dirname(current_opts_file)
4253356Sbinkertn@umich.edu        if not os.path.isdir(opt_dir):
4263356Sbinkertn@umich.edu            os.mkdir(opt_dir)
4273356Sbinkertn@umich.edu
4283356Sbinkertn@umich.edu        # Get default build options from source tree.  Options are
4291869SN/A        # normally determined by name of $BUILD_DIR, but can be
4301869SN/A        # overriden by 'default=' arg on command line.
4311869SN/A        default_opts_file = os.path.join('build_opts',
4321869SN/A                                         ARGUMENTS.get('default', build_dir))
4331869SN/A        if os.path.isfile(default_opts_file):
4341869SN/A            sticky_opts.files.append(default_opts_file)
4351869SN/A            print "Options file %s not found,\n  using defaults in %s" \
4362655Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4372655Sstever@eecs.umich.edu        else:
4382655Sstever@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
4392655Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4402655Sstever@eecs.umich.edu            Exit(1)
4412655Sstever@eecs.umich.edu
4422655Sstever@eecs.umich.edu    # Apply current option settings to env
4432655Sstever@eecs.umich.edu    sticky_opts.Update(env)
4442655Sstever@eecs.umich.edu    nonsticky_opts.Update(env)
4452655Sstever@eecs.umich.edu
4462655Sstever@eecs.umich.edu    help_text += "Sticky options for %s:\n" % build_dir \
4472655Sstever@eecs.umich.edu                 + sticky_opts.GenerateHelpText(env) \
4482655Sstever@eecs.umich.edu                 + "\nNon-sticky options for %s:\n" % build_dir \
4492655Sstever@eecs.umich.edu                 + nonsticky_opts.GenerateHelpText(env)
4502655Sstever@eecs.umich.edu
4512655Sstever@eecs.umich.edu    # Process option settings.
4522655Sstever@eecs.umich.edu
4532655Sstever@eecs.umich.edu    if not have_fenv and env['USE_FENV']:
4542655Sstever@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
4552655Sstever@eecs.umich.edu              "forcing USE_FENV to False in", build_dir + "."
4562655Sstever@eecs.umich.edu        env['USE_FENV'] = False
4572655Sstever@eecs.umich.edu
4582655Sstever@eecs.umich.edu    if not env['USE_FENV']:
4592655Sstever@eecs.umich.edu        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4602655Sstever@eecs.umich.edu        print "         FP results may deviate slightly from other platforms."
4612655Sstever@eecs.umich.edu
4622634Sstever@eecs.umich.edu    if env['EFENCE']:
4632634Sstever@eecs.umich.edu        env.Append(LIBS=['efence'])
4642634Sstever@eecs.umich.edu
4652634Sstever@eecs.umich.edu    if env['USE_MYSQL']:
4662634Sstever@eecs.umich.edu        if not have_mysql:
4672634Sstever@eecs.umich.edu            print "Warning: MySQL not available; " \
4682638Sstever@eecs.umich.edu                  "forcing USE_MYSQL to False in", build_dir + "."
4692638Sstever@eecs.umich.edu            env['USE_MYSQL'] = False
4703716Sstever@eecs.umich.edu        else:
4712638Sstever@eecs.umich.edu            print "Compiling in", build_dir, "with MySQL support."
4722638Sstever@eecs.umich.edu            env.ParseConfig(mysql_config_libs)
4731869SN/A            env.ParseConfig(mysql_config_include)
4741869SN/A
4753546Sgblack@eecs.umich.edu    # Check if the Checker is being used.  If so append it to env['CPU_MODELS']
4763546Sgblack@eecs.umich.edu    if env['USE_CHECKER']:
4773546Sgblack@eecs.umich.edu        env['CPU_MODELS'].append('CheckerCPU')
4783546Sgblack@eecs.umich.edu
4793546Sgblack@eecs.umich.edu    # Save sticky option settings back to current options file
4803546Sgblack@eecs.umich.edu    sticky_opts.Save(current_opts_file, env)
4813546Sgblack@eecs.umich.edu
4823546Sgblack@eecs.umich.edu    # Do this after we save setting back, or else we'll tack on an
4833546Sgblack@eecs.umich.edu    # extra 'qdo' every time we run scons.
4843546Sgblack@eecs.umich.edu    if env['BATCH']:
4853546Sgblack@eecs.umich.edu        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4863546Sgblack@eecs.umich.edu        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4873546Sgblack@eecs.umich.edu
4883546Sgblack@eecs.umich.edu    if env['USE_SSE2']:
4893546Sgblack@eecs.umich.edu        env.Append(CCFLAGS='-msse2')
4903546Sgblack@eecs.umich.edu
4913546Sgblack@eecs.umich.edu    # The m5/SConscript file sets up the build rules in 'env' according
4923546Sgblack@eecs.umich.edu    # to the configured options.  It returns a list of environments,
4933546Sgblack@eecs.umich.edu    # one for each variant build (debug, opt, etc.)
4943546Sgblack@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
4953546Sgblack@eecs.umich.edu                         exports = 'env')
4963546Sgblack@eecs.umich.edu
4973546Sgblack@eecs.umich.edu    # Set up the regression tests for each build.
4983546Sgblack@eecs.umich.edu#    for e in envList:
4993546Sgblack@eecs.umich.edu#        SConscript('m5-test/SConscript',
5003546Sgblack@eecs.umich.edu#                   build_dir = os.path.join(build_dir, 'test', e.Label),
5013546Sgblack@eecs.umich.edu#                   exports = { 'env' : e }, duplicate = False)
5023546Sgblack@eecs.umich.edu
5033546Sgblack@eecs.umich.eduHelp(help_text)
5043546Sgblack@eecs.umich.edu
5053546Sgblack@eecs.umich.edu###################################################
5063546Sgblack@eecs.umich.edu#
5073546Sgblack@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
5083546Sgblack@eecs.umich.edu# build environments to build the requested targets.
5093546Sgblack@eecs.umich.edu#
5103546Sgblack@eecs.umich.edu###################################################
5113546Sgblack@eecs.umich.edu
5123546Sgblack@eecs.umich.edu