SConstruct revision 2665
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#
294762Snate@binkert.org# Authors: Steve Reinhardt
30955SN/A
314762Snate@binkert.org###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
344202Sbinkertn@umich.edu#
354382Sbinkertn@umich.edu# While in this directory ('m5'), just type 'scons' to build the default
364202Sbinkertn@umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
374762Snate@binkert.org# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
384762Snate@binkert.org# the optimized full-system version).
394762Snate@binkert.org#
40955SN/A# You can build M5 in a different directory as long as there is a
414381Sbinkertn@umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
424381Sbinkertn@umich.edu# expdects that all configs under the same build directory are being
43955SN/A# built for the same host system.
44955SN/A#
45955SN/A# Examples:
464202Sbinkertn@umich.edu#   These two commands are equivalent.  The '-u' option tells scons to
47955SN/A#   search up the directory tree for this SConstruct file.
484382Sbinkertn@umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
494382Sbinkertn@umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
504382Sbinkertn@umich.edu#   These two commands are equivalent and demonstrate building in a
514762Snate@binkert.org#   directory outside of the source tree.  The '-C' option tells scons
524762Snate@binkert.org#   to chdir to the specified directory to find this SConstruct file.
534762Snate@binkert.org#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
544762Snate@binkert.org#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
554762Snate@binkert.org#
564762Snate@binkert.org# You can use 'scons -H' to print scons options.  If you're in this
574762Snate@binkert.org# 'm5' directory (or use -u or -C to tell scons where to find this
584762Snate@binkert.org# file), you can use 'scons -h' to print all the M5-specific build
594762Snate@binkert.org# options as well.
604762Snate@binkert.org#
614762Snate@binkert.org###################################################
624762Snate@binkert.org
634762Snate@binkert.org# Python library imports
644762Snate@binkert.orgimport sys
654762Snate@binkert.orgimport os
664762Snate@binkert.org
674762Snate@binkert.org# Check for recent-enough Python and SCons versions.  If your system's
684762Snate@binkert.org# default installation of Python is not recent enough, you can use a
694762Snate@binkert.org# non-default installation of the Python interpreter by either (1)
704762Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python'
714762Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the
724762Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
734762Snate@binkert.orgEnsurePythonVersion(2,4)
744762Snate@binkert.org
754762Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
764762Snate@binkert.org# 3-element version number.
774762Snate@binkert.orgmin_scons_version = (0,96,91)
784762Snate@binkert.orgtry:
794762Snate@binkert.org    EnsureSConsVersion(*min_scons_version)
804762Snate@binkert.orgexcept:
814762Snate@binkert.org    print "Error checking current SCons version."
824762Snate@binkert.org    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
834762Snate@binkert.org    Exit(2)
844382Sbinkertn@umich.edu    
854762Snate@binkert.org
864382Sbinkertn@umich.edu# The absolute path to the current directory (where this file lives).
874762Snate@binkert.orgROOT = Dir('.').abspath
884381Sbinkertn@umich.edu
894762Snate@binkert.org# Paths to the M5 and external source trees.
904762Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src')
914762Snate@binkert.org
924762Snate@binkert.org# tell python where to find m5 python code
934762Snate@binkert.orgsys.path.append(os.path.join(ROOT, 'src/python'))
944762Snate@binkert.org
954762Snate@binkert.org###################################################
964762Snate@binkert.org#
974762Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
984762Snate@binkert.org# the target(s).
994762Snate@binkert.org#
1004762Snate@binkert.org###################################################
1014762Snate@binkert.org
1024762Snate@binkert.org# Find default configuration & binary.
1034762Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1044762Snate@binkert.org
1054762Snate@binkert.org# Ask SCons which directory it was invoked from.
1064762Snate@binkert.orglaunch_dir = GetLaunchDir()
1074762Snate@binkert.org
1084762Snate@binkert.org# Make targets relative to invocation directory
1094762Snate@binkert.orgabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1104762Snate@binkert.org                  BUILD_TARGETS)
1114762Snate@binkert.org
1124762Snate@binkert.org# helper function: find last occurrence of element in list
1134762Snate@binkert.orgdef rfind(l, elt, offs = -1):
1144762Snate@binkert.org    for i in range(len(l)+offs, 0, -1):
1154762Snate@binkert.org        if l[i] == elt:
1164762Snate@binkert.org            return i
1174762Snate@binkert.org    raise ValueError, "element not found"
1184762Snate@binkert.org
1194762Snate@binkert.org# Each target must have 'build' in the interior of the path; the
1204762Snate@binkert.org# directory below this will determine the build parameters.  For
1214762Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1224762Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it
1234762Snate@binkert.org# follow 'build' in the bulid path.
1244762Snate@binkert.org
1254762Snate@binkert.org# Generate a list of the unique build roots and configs that the
1264762Snate@binkert.org# collected targets reference.
1274762Snate@binkert.orgbuild_paths = []
1284762Snate@binkert.orgbuild_root = None
129955SN/Afor t in abs_targets:
1304382Sbinkertn@umich.edu    path_dirs = t.split('/')
1314202Sbinkertn@umich.edu    try:
1324382Sbinkertn@umich.edu        build_top = rfind(path_dirs, 'build', -2)
1334382Sbinkertn@umich.edu    except:
1344382Sbinkertn@umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1354382Sbinkertn@umich.edu        Exit(1)
1364382Sbinkertn@umich.edu    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1374382Sbinkertn@umich.edu    if not build_root:
1385192Ssaidi@eecs.umich.edu        build_root = this_build_root
1395192Ssaidi@eecs.umich.edu    else:
1405192Ssaidi@eecs.umich.edu        if this_build_root != build_root:
1415192Ssaidi@eecs.umich.edu            print "Error: build targets not under same build root\n"\
1425192Ssaidi@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
1435192Ssaidi@eecs.umich.edu            Exit(1)
1445192Ssaidi@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1455192Ssaidi@eecs.umich.edu    if build_path not in build_paths:
1465192Ssaidi@eecs.umich.edu        build_paths.append(build_path)
1475192Ssaidi@eecs.umich.edu
1485192Ssaidi@eecs.umich.edu###################################################
1495192Ssaidi@eecs.umich.edu#
1505192Ssaidi@eecs.umich.edu# Set up the default build environment.  This environment is copied
1515192Ssaidi@eecs.umich.edu# and modified according to each selected configuration.
1525192Ssaidi@eecs.umich.edu#
1535192Ssaidi@eecs.umich.edu###################################################
1545192Ssaidi@eecs.umich.edu
1555192Ssaidi@eecs.umich.eduenv = Environment(ENV = os.environ,  # inherit user's environment vars
1565192Ssaidi@eecs.umich.edu                  ROOT = ROOT,
1575192Ssaidi@eecs.umich.edu                  SRCDIR = SRCDIR)
1585192Ssaidi@eecs.umich.edu
1595192Ssaidi@eecs.umich.eduenv.SConsignFile("sconsign")
1605192Ssaidi@eecs.umich.edu
1615192Ssaidi@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but
1625192Ssaidi@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take
1635192Ssaidi@eecs.umich.edu# noticeably longer.
1645192Ssaidi@eecs.umich.eduif False:
1655192Ssaidi@eecs.umich.edu    env.TargetSignatures('content')
1665192Ssaidi@eecs.umich.edu
1675192Ssaidi@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
1685192Ssaidi@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1695192Ssaidi@eecs.umich.edu
1704382Sbinkertn@umich.edu# Set up default C++ compiler flags
1714382Sbinkertn@umich.eduenv.Append(CCFLAGS='-pipe')
1724382Sbinkertn@umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing')
1732667Sstever@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1742667Sstever@eecs.umich.eduif sys.platform == 'cygwin':
1752667Sstever@eecs.umich.edu    # cygwin has some header file issues...
1762667Sstever@eecs.umich.edu    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1772667Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')])
1782667Sstever@eecs.umich.edu
1792037SN/A# Find Python include and library directories for embedding the
1802037SN/A# interpreter.  For consistency, we will use the same Python
1812037SN/A# installation used to run scons (and thus this script).  If you want
1824382Sbinkertn@umich.edu# to link in an alternate version, see above for instructions on how
1834762Snate@binkert.org# to invoke scons with a different copy of the Python interpreter.
1844202Sbinkertn@umich.edu
1854382Sbinkertn@umich.edu# Get brief Python version name (e.g., "python2.4") for locating
1864202Sbinkertn@umich.edu# include & library files
1874202Sbinkertn@umich.edupy_version_name = 'python' + sys.version[:3]
1884202Sbinkertn@umich.edu
1894202Sbinkertn@umich.edu# include path, e.g. /usr/local/include/python2.4
1904202Sbinkertn@umich.eduenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
1914762Snate@binkert.orgenv.Append(LIBS = py_version_name)
1924202Sbinkertn@umich.edu# add library path too if it's not in the default place
1934202Sbinkertn@umich.eduif sys.exec_prefix != '/usr':
1944202Sbinkertn@umich.edu    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
1954202Sbinkertn@umich.edu
1964202Sbinkertn@umich.edu# Other default libraries
1971858SN/Aenv.Append(LIBS=['z'])
1985068Sgblack@eecs.umich.edu
1995068Sgblack@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
2005068Sgblack@eecs.umich.edu# builds under a given build root run on the same host platform.
2015068Sgblack@eecs.umich.educonf = Configure(env,
2025068Sgblack@eecs.umich.edu                 conf_dir = os.path.join(build_root, '.scons_config'),
2035068Sgblack@eecs.umich.edu                 log_file = os.path.join(build_root, 'scons_config.log'))
2045068Sgblack@eecs.umich.edu
2055068Sgblack@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
2065068Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
2075068Sgblack@eecs.umich.eduif not have_fenv:
2085068Sgblack@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
2094773Snate@binkert.org    print "         This host has no IEEE FP rounding mode control."
2101858SN/A
2111858SN/A# Check for mysql.
2121085SN/Amysql_config = WhereIs('mysql_config')
2134382Sbinkertn@umich.eduhave_mysql = mysql_config != None
2144382Sbinkertn@umich.edu
2154762Snate@binkert.org# Check MySQL version.
2164762Snate@binkert.orgif have_mysql:
2174762Snate@binkert.org    mysql_version = os.popen(mysql_config + ' --version').read()
2184762Snate@binkert.org    mysql_version = mysql_version.split('.')
2194762Snate@binkert.org    mysql_major = int(mysql_version[0])
2204762Snate@binkert.org    mysql_minor = int(mysql_version[1])
2214762Snate@binkert.org    # This version check is probably overly conservative, but it deals
2224762Snate@binkert.org    # with the versions we have installed.
2234762Snate@binkert.org    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2244762Snate@binkert.org        print "Warning: MySQL v4.1 or newer required."
2254762Snate@binkert.org        have_mysql = False
2264762Snate@binkert.org
2274762Snate@binkert.org# Set up mysql_config commands.
2284762Snate@binkert.orgif have_mysql:
2294762Snate@binkert.org    mysql_config_include = mysql_config + ' --include'
2304762Snate@binkert.org    if os.system(mysql_config_include + ' > /dev/null') != 0:
2314762Snate@binkert.org        # older mysql_config versions don't support --include, use
2324762Snate@binkert.org        # --cflags instead
2334762Snate@binkert.org        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2344762Snate@binkert.org    # This seems to work in all versions
2354762Snate@binkert.org    mysql_config_libs = mysql_config + ' --libs'
2364762Snate@binkert.org
2374762Snate@binkert.orgenv = conf.Finish()
2384762Snate@binkert.org
2394762Snate@binkert.org# Define the universe of supported ISAs
2404762Snate@binkert.orgenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2414762Snate@binkert.org
2424762Snate@binkert.org# Define the universe of supported CPU models
2434762Snate@binkert.orgenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2444762Snate@binkert.org                       'FullCPU', 'AlphaFullCPU']
2454762Snate@binkert.org
2464762Snate@binkert.org# Sticky options get saved in the options file so they persist from
2474762Snate@binkert.org# one invocation to the next (unless overridden, in which case the new
2484762Snate@binkert.org# value becomes sticky).
2494762Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS)
2504382Sbinkertn@umich.edusticky_opts.AddOptions(
2514382Sbinkertn@umich.edu    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2524762Snate@binkert.org    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2534762Snate@binkert.org    # There's a bug in scons 0.96.1 that causes ListOptions with list
2544762Snate@binkert.org    # values (more than one value) not to be able to be restored from
2554382Sbinkertn@umich.edu    # a saved option file.  If this causes trouble then upgrade to
2564382Sbinkertn@umich.edu    # scons 0.96.90 or later.
2574762Snate@binkert.org    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2584382Sbinkertn@umich.edu               env['ALL_CPU_LIST']),
2594382Sbinkertn@umich.edu    BoolOption('ALPHA_TLASER',
2604762Snate@binkert.org               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2614382Sbinkertn@umich.edu    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2624382Sbinkertn@umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2634762Snate@binkert.org               False),
2644382Sbinkertn@umich.edu    BoolOption('SS_COMPATIBLE_FP',
2654762Snate@binkert.org               'Make floating-point results compatible with SimpleScalar',
2664762Snate@binkert.org               False),
2674382Sbinkertn@umich.edu    BoolOption('USE_SSE2',
2684382Sbinkertn@umich.edu               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2694762Snate@binkert.org               False),
2704762Snate@binkert.org    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2714762Snate@binkert.org    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2724762Snate@binkert.org    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2734762Snate@binkert.org    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2744762Snate@binkert.org    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2754762Snate@binkert.org    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2764762Snate@binkert.org    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2774762Snate@binkert.org    )
2784762Snate@binkert.org
2794762Snate@binkert.org# Non-sticky options only apply to the current build.
2804762Snate@binkert.orgnonsticky_opts = Options(args=ARGUMENTS)
2814762Snate@binkert.orgnonsticky_opts.AddOptions(
2824762Snate@binkert.org    BoolOption('update_ref', 'Update test reference outputs', False)
2834762Snate@binkert.org    )
2844762Snate@binkert.org
2854762Snate@binkert.org# These options get exported to #defines in config/*.hh (see m5/SConscript).
2864762Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2874762Snate@binkert.org                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2884762Snate@binkert.org                     'STATS_BINNING']
2894762Snate@binkert.org
2904762Snate@binkert.org# Define a handy 'no-op' action
2914762Snate@binkert.orgdef no_action(target, source, env):
2924762Snate@binkert.org    return 0
2934762Snate@binkert.org
2944762Snate@binkert.orgenv.NoAction = Action(no_action, None)
2954762Snate@binkert.org
2964762Snate@binkert.org###################################################
2974762Snate@binkert.org#
2984762Snate@binkert.org# Define a SCons builder for configuration flag headers.
2994762Snate@binkert.org#
3004762Snate@binkert.org###################################################
3014762Snate@binkert.org
3024762Snate@binkert.org# This function generates a config header file that #defines the
3034762Snate@binkert.org# option symbol to the current option setting (0 or 1).  The source
3044762Snate@binkert.org# operands are the name of the option and a Value node containing the
3054762Snate@binkert.org# value of the option.
3064762Snate@binkert.orgdef build_config_file(target, source, env):
3074762Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
3084762Snate@binkert.org    f = file(str(target[0]), 'w')
3094762Snate@binkert.org    print >> f, '#define', option, value
3104762Snate@binkert.org    f.close()
3114762Snate@binkert.org    return None
3124762Snate@binkert.org
3134762Snate@binkert.org# Generate the message to be printed when building the config file.
3144762Snate@binkert.orgdef build_config_file_string(target, source, env):
3154762Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
3164762Snate@binkert.org    return "Defining %s as %s in %s." % (option, value, target[0])
3174762Snate@binkert.org
3184382Sbinkertn@umich.edu# Combine the two functions into a scons Action object.
3194762Snate@binkert.orgconfig_action = Action(build_config_file, build_config_file_string)
3204382Sbinkertn@umich.edu
3214762Snate@binkert.org# The emitter munges the source & target node lists to reflect what
3224382Sbinkertn@umich.edu# we're really doing.
3234762Snate@binkert.orgdef config_emitter(target, source, env):
3244762Snate@binkert.org    # extract option name from Builder arg
3254762Snate@binkert.org    option = str(target[0])
3264762Snate@binkert.org    # True target is config header file
3274382Sbinkertn@umich.edu    target = os.path.join('config', option.lower() + '.hh')
3284382Sbinkertn@umich.edu    # Force value to 0/1 even if it's a Python bool
3294382Sbinkertn@umich.edu    val = int(eval(str(env[option])))
3304382Sbinkertn@umich.edu    # Sources are option name & value (packaged in SCons Value nodes)
3314382Sbinkertn@umich.edu    return ([target], [Value(option), Value(val)])
3324382Sbinkertn@umich.edu
3334762Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action)
3344382Sbinkertn@umich.edu
3354382Sbinkertn@umich.eduenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3364382Sbinkertn@umich.edu
3374382Sbinkertn@umich.edu###################################################
3384762Snate@binkert.org#
3394762Snate@binkert.org# Define a SCons builder for copying files.  This is used by the
3404762Snate@binkert.org# Python zipfile code in src/python/SConscript, but is placed up here
3414382Sbinkertn@umich.edu# since it's potentially more generally applicable.
3425192Ssaidi@eecs.umich.edu#
3435192Ssaidi@eecs.umich.edu###################################################
3445192Ssaidi@eecs.umich.edu
3455192Ssaidi@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3465192Ssaidi@eecs.umich.edu
3475192Ssaidi@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3485192Ssaidi@eecs.umich.edu
3495192Ssaidi@eecs.umich.edu###################################################
3505192Ssaidi@eecs.umich.edu#
3514762Snate@binkert.org# Define a simple SCons builder to concatenate files.
3524382Sbinkertn@umich.edu#
3534382Sbinkertn@umich.edu# Used to append the Python zip archive to the executable.
3544382Sbinkertn@umich.edu#
3554762Snate@binkert.org###################################################
3564762Snate@binkert.org
3574382Sbinkertn@umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3584382Sbinkertn@umich.edu                                          'chmod +x $TARGET']))
3594382Sbinkertn@umich.edu
3604762Snate@binkert.orgenv.Append(BUILDERS = { 'Concat' : concat_builder })
3614382Sbinkertn@umich.edu
3624382Sbinkertn@umich.edu
3634762Snate@binkert.org# base help text
3644762Snate@binkert.orghelp_text = '''
3654762Snate@binkert.orgUsage: scons [scons options] [build options] [target(s)]
3664382Sbinkertn@umich.edu
3674382Sbinkertn@umich.edu'''
3684382Sbinkertn@umich.edu
3694382Sbinkertn@umich.edu# libelf build is shared across all configs in the build root.
3704382Sbinkertn@umich.eduenv.SConscript('ext/libelf/SConscript',
3714382Sbinkertn@umich.edu               build_dir = os.path.join(build_root, 'libelf'),
3724382Sbinkertn@umich.edu               exports = 'env')
3734382Sbinkertn@umich.edu
3744382Sbinkertn@umich.edu###################################################
3754382Sbinkertn@umich.edu#
376955SN/A# Define build environments for selected configurations.
377955SN/A#
378955SN/A###################################################
379955SN/A
3801108SN/A# rename base env
381955SN/Abase_env = env
382955SN/A
383955SN/Afor build_path in build_paths:
384955SN/A    print "Building in", build_path
385955SN/A    # build_dir is the tail component of build path, and is used to
386955SN/A    # determine the build parameters (e.g., 'ALPHA_SE')
387955SN/A    (build_root, build_dir) = os.path.split(build_path)
388955SN/A    # Make a copy of the build-root environment to use for this config.
389955SN/A    env = base_env.Copy()
3902655Sstever@eecs.umich.edu
3912655Sstever@eecs.umich.edu    # Set env options according to the build directory config.
3922655Sstever@eecs.umich.edu    sticky_opts.files = []
3932655Sstever@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
3942655Sstever@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
3952655Sstever@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
3962655Sstever@eecs.umich.edu    current_opts_file = os.path.join(build_root, 'options', build_dir)
3972655Sstever@eecs.umich.edu    if os.path.isfile(current_opts_file):
3982655Sstever@eecs.umich.edu        sticky_opts.files.append(current_opts_file)
3992655Sstever@eecs.umich.edu        print "Using saved options file %s" % current_opts_file
4004762Snate@binkert.org    else:
4012655Sstever@eecs.umich.edu        # Build dir-specific options file doesn't exist.
4022655Sstever@eecs.umich.edu
4034007Ssaidi@eecs.umich.edu        # Make sure the directory is there so we can create it later
4044596Sbinkertn@umich.edu        opt_dir = os.path.dirname(current_opts_file)
4054007Ssaidi@eecs.umich.edu        if not os.path.isdir(opt_dir):
4064596Sbinkertn@umich.edu            os.mkdir(opt_dir)
4074596Sbinkertn@umich.edu
4082655Sstever@eecs.umich.edu        # Get default build options from source tree.  Options are
4094382Sbinkertn@umich.edu        # normally determined by name of $BUILD_DIR, but can be
4102655Sstever@eecs.umich.edu        # overriden by 'default=' arg on command line.
4112655Sstever@eecs.umich.edu        default_opts_file = os.path.join('build_opts',
4122655Sstever@eecs.umich.edu                                         ARGUMENTS.get('default', build_dir))
413955SN/A        if os.path.isfile(default_opts_file):
4143918Ssaidi@eecs.umich.edu            sticky_opts.files.append(default_opts_file)
4153918Ssaidi@eecs.umich.edu            print "Options file %s not found,\n  using defaults in %s" \
4163918Ssaidi@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4173918Ssaidi@eecs.umich.edu        else:
4183918Ssaidi@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
4193918Ssaidi@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4203918Ssaidi@eecs.umich.edu            Exit(1)
4213918Ssaidi@eecs.umich.edu
4223918Ssaidi@eecs.umich.edu    # Apply current option settings to env
4233918Ssaidi@eecs.umich.edu    sticky_opts.Update(env)
4243918Ssaidi@eecs.umich.edu    nonsticky_opts.Update(env)
4253918Ssaidi@eecs.umich.edu
4263918Ssaidi@eecs.umich.edu    help_text += "Sticky options for %s:\n" % build_dir \
4273918Ssaidi@eecs.umich.edu                 + sticky_opts.GenerateHelpText(env) \
4283940Ssaidi@eecs.umich.edu                 + "\nNon-sticky options for %s:\n" % build_dir \
4293940Ssaidi@eecs.umich.edu                 + nonsticky_opts.GenerateHelpText(env)
4303940Ssaidi@eecs.umich.edu
4313942Ssaidi@eecs.umich.edu    # Process option settings.
4323940Ssaidi@eecs.umich.edu
4333515Ssaidi@eecs.umich.edu    if not have_fenv and env['USE_FENV']:
4343918Ssaidi@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
4354762Snate@binkert.org              "forcing USE_FENV to False in", build_dir + "."
4363515Ssaidi@eecs.umich.edu        env['USE_FENV'] = False
4372655Sstever@eecs.umich.edu
4383918Ssaidi@eecs.umich.edu    if not env['USE_FENV']:
4393619Sbinkertn@umich.edu        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
440955SN/A        print "         FP results may deviate slightly from other platforms."
441955SN/A
4422655Sstever@eecs.umich.edu    if env['EFENCE']:
4433918Ssaidi@eecs.umich.edu        env.Append(LIBS=['efence'])
4443619Sbinkertn@umich.edu
445955SN/A    if env['USE_MYSQL']:
446955SN/A        if not have_mysql:
4472655Sstever@eecs.umich.edu            print "Warning: MySQL not available; " \
4483918Ssaidi@eecs.umich.edu                  "forcing USE_MYSQL to False in", build_dir + "."
4493619Sbinkertn@umich.edu            env['USE_MYSQL'] = False
450955SN/A        else:
451955SN/A            print "Compiling in", build_dir, "with MySQL support."
4522655Sstever@eecs.umich.edu            env.ParseConfig(mysql_config_libs)
4533918Ssaidi@eecs.umich.edu            env.ParseConfig(mysql_config_include)
4543683Sstever@eecs.umich.edu
4552655Sstever@eecs.umich.edu    # Save sticky option settings back to current options file
4561869SN/A    sticky_opts.Save(current_opts_file, env)
4571869SN/A
458    # Do this after we save setting back, or else we'll tack on an
459    # extra 'qdo' every time we run scons.
460    if env['BATCH']:
461        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
462        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
463
464    if env['USE_SSE2']:
465        env.Append(CCFLAGS='-msse2')
466
467    # The m5/SConscript file sets up the build rules in 'env' according
468    # to the configured options.  It returns a list of environments,
469    # one for each variant build (debug, opt, etc.)
470    envList = SConscript('src/SConscript', build_dir = build_path,
471                         exports = 'env', duplicate = False)
472
473    # Set up the regression tests for each build.
474#    for e in envList:
475#        SConscript('m5-test/SConscript',
476#                   build_dir = os.path.join(build_dir, 'test', e.Label),
477#                   exports = { 'env' : e }, duplicate = False)
478
479Help(help_text)
480
481###################################################
482#
483# Let SCons do its thing.  At this point SCons will use the defined
484# build environments to build the requested targets.
485#
486###################################################
487
488