SConstruct revision 2665
1955SN/A# -*- mode:python -*-
2955SN/A
37816Ssteve.reinhardt@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
45871Snate@binkert.org# All rights reserved.
51762SN/A#
6955SN/A# Redistribution and use in source and binary forms, with or without
7955SN/A# modification, are permitted provided that the following conditions are
8955SN/A# met: redistributions of source code must retain the above copyright
9955SN/A# notice, this list of conditions and the following disclaimer;
10955SN/A# redistributions in binary form must reproduce the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer in the
12955SN/A# documentation and/or other materials provided with the distribution;
13955SN/A# neither the name of the copyright holders nor the names of its
14955SN/A# contributors may be used to endorse or promote products derived from
15955SN/A# this software without specific prior written permission.
16955SN/A#
17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28955SN/A#
29955SN/A# Authors: Steve Reinhardt
302665Ssaidi@eecs.umich.edu
312665Ssaidi@eecs.umich.edu###################################################
325863Snate@binkert.org#
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
382632Sstever@eecs.umich.edu# the optimized full-system version).
392632Sstever@eecs.umich.edu#
402632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a
412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
42955SN/A# 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#
452761Sstever@eecs.umich.edu# Examples:
462632Sstever@eecs.umich.edu#   These two commands are equivalent.  The '-u' option tells scons to
472632Sstever@eecs.umich.edu#   search up the directory tree for this SConstruct file.
482632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
492761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
502761Sstever@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
522632Sstever@eecs.umich.edu#   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
542761Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
552761Sstever@eecs.umich.edu#
562761Sstever@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
582761Sstever@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
632632Sstever@eecs.umich.edu# Python library imports
642632Sstever@eecs.umich.eduimport sys
652632Sstever@eecs.umich.eduimport 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
695863Snate@binkert.org# non-default installation of the Python interpreter by either (1)
705863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python'
715863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the
725863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
735863Snate@binkert.orgEnsurePythonVersion(2,4)
745863Snate@binkert.org
755863Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
765863Snate@binkert.org# 3-element version number.
775863Snate@binkert.orgmin_scons_version = (0,96,91)
785863Snate@binkert.orgtry:
795863Snate@binkert.org    EnsureSConsVersion(*min_scons_version)
805863Snate@binkert.orgexcept:
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
925863Snate@binkert.org# 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###################################################
965863Snate@binkert.org#
975863Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
985863Snate@binkert.org# the target(s).
995863Snate@binkert.org#
1006654Snate@binkert.org###################################################
101955SN/A
1025396Ssaidi@eecs.umich.edu# Find default configuration & binary.
1035863Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1045863Snate@binkert.org
1054202Sbinkertn@umich.edu# Ask SCons which directory it was invoked from.
1065863Snate@binkert.orglaunch_dir = GetLaunchDir()
1075863Snate@binkert.org
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))),
110955SN/A                  BUILD_TARGETS)
1116654Snate@binkert.org
1125273Sstever@gmail.com# helper function: find last occurrence of element in list
1135871Snate@binkert.orgdef rfind(l, elt, offs = -1):
1145273Sstever@gmail.com    for i in range(len(l)+offs, 0, -1):
1156655Snate@binkert.org        if l[i] == elt:
1166655Snate@binkert.org            return i
1176655Snate@binkert.org    raise ValueError, "element not found"
1186655Snate@binkert.org
1196655Snate@binkert.org# Each target must have 'build' in the interior of the path; the
1206655Snate@binkert.org# directory below this will determine the build parameters.  For
1215871Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1226654Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it
1235396Ssaidi@eecs.umich.edu# follow 'build' in the bulid path.
1247816Ssteve.reinhardt@amd.com
1257816Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the
1267816Ssteve.reinhardt@amd.com# collected targets reference.
1277816Ssteve.reinhardt@amd.combuild_paths = []
1287816Ssteve.reinhardt@amd.combuild_root = None
1297816Ssteve.reinhardt@amd.comfor t in abs_targets:
1307816Ssteve.reinhardt@amd.com    path_dirs = t.split('/')
1317816Ssteve.reinhardt@amd.com    try:
1327816Ssteve.reinhardt@amd.com        build_top = rfind(path_dirs, 'build', -2)
1337816Ssteve.reinhardt@amd.com    except:
1347816Ssteve.reinhardt@amd.com        print "Error: no non-leaf 'build' dir found on target path", t
1357816Ssteve.reinhardt@amd.com        Exit(1)
1365871Snate@binkert.org    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1375871Snate@binkert.org    if not build_root:
1386121Snate@binkert.org        build_root = this_build_root
1395871Snate@binkert.org    else:
1405871Snate@binkert.org        if this_build_root != build_root:
1416003Snate@binkert.org            print "Error: build targets not under same build root\n"\
1426655Snate@binkert.org                  "  %s\n  %s" % (build_root, this_build_root)
143955SN/A            Exit(1)
1445871Snate@binkert.org    build_path = os.path.join('/',*path_dirs[:build_top+2])
1455871Snate@binkert.org    if build_path not in build_paths:
1465871Snate@binkert.org        build_paths.append(build_path)
1475871Snate@binkert.org
148955SN/A###################################################
1496121Snate@binkert.org#
1506121Snate@binkert.org# Set up the default build environment.  This environment is copied
1516121Snate@binkert.org# and modified according to each selected configuration.
1521533SN/A#
1536655Snate@binkert.org###################################################
1546655Snate@binkert.org
1556655Snate@binkert.orgenv = Environment(ENV = os.environ,  # inherit user's environment vars
1566655Snate@binkert.org                  ROOT = ROOT,
1575871Snate@binkert.org                  SRCDIR = SRCDIR)
1585871Snate@binkert.org
1595863Snate@binkert.orgenv.SConsignFile("sconsign")
1605871Snate@binkert.org
1615871Snate@binkert.org# I waffle on this setting... it does avoid a few painful but
1625871Snate@binkert.org# unnecessary builds, but it also seems to make trivial builds take
1635871Snate@binkert.org# noticeably longer.
1645871Snate@binkert.orgif False:
1655863Snate@binkert.org    env.TargetSignatures('content')
1666121Snate@binkert.org
1675863Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package.
1685871Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1694678Snate@binkert.org
1704678Snate@binkert.org# Set up default C++ compiler flags
1714678Snate@binkert.orgenv.Append(CCFLAGS='-pipe')
1724678Snate@binkert.orgenv.Append(CCFLAGS='-fno-strict-aliasing')
1734678Snate@binkert.orgenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1744678Snate@binkert.orgif sys.platform == 'cygwin':
1754678Snate@binkert.org    # cygwin has some header file issues...
1764678Snate@binkert.org    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1774678Snate@binkert.orgenv.Append(CPPPATH=[Dir('ext/dnet')])
1784678Snate@binkert.org
1794678Snate@binkert.org# Find Python include and library directories for embedding the
1807827Snate@binkert.org# interpreter.  For consistency, we will use the same Python
1817827Snate@binkert.org# installation used to run scons (and thus this script).  If you want
1826121Snate@binkert.org# to link in an alternate version, see above for instructions on how
1834678Snate@binkert.org# to invoke scons with a different copy of the Python interpreter.
1845871Snate@binkert.org
1855871Snate@binkert.org# Get brief Python version name (e.g., "python2.4") for locating
1865871Snate@binkert.org# include & library files
1875871Snate@binkert.orgpy_version_name = 'python' + sys.version[:3]
1885871Snate@binkert.org
1895871Snate@binkert.org# include path, e.g. /usr/local/include/python2.4
1905871Snate@binkert.orgenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
1915871Snate@binkert.orgenv.Append(LIBS = py_version_name)
1925871Snate@binkert.org# add library path too if it's not in the default place
1935871Snate@binkert.orgif sys.exec_prefix != '/usr':
1945871Snate@binkert.org    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
1955871Snate@binkert.org
1965871Snate@binkert.org# Other default libraries
1975990Ssaidi@eecs.umich.eduenv.Append(LIBS=['z'])
1985871Snate@binkert.org
1995871Snate@binkert.org# Platform-specific configuration.  Note again that we assume that all
2005871Snate@binkert.org# builds under a given build root run on the same host platform.
2014678Snate@binkert.orgconf = Configure(env,
2026654Snate@binkert.org                 conf_dir = os.path.join(build_root, '.scons_config'),
2035871Snate@binkert.org                 log_file = os.path.join(build_root, 'scons_config.log'))
2045871Snate@binkert.org
2055871Snate@binkert.org# Check for <fenv.h> (C99 FP environment control)
2065871Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>')
2075871Snate@binkert.orgif not have_fenv:
2085871Snate@binkert.org    print "Warning: Header file <fenv.h> not found."
2095871Snate@binkert.org    print "         This host has no IEEE FP rounding mode control."
2105871Snate@binkert.org
2115871Snate@binkert.org# Check for mysql.
2124678Snate@binkert.orgmysql_config = WhereIs('mysql_config')
2135871Snate@binkert.orghave_mysql = mysql_config != None
2144678Snate@binkert.org
2155871Snate@binkert.org# Check MySQL version.
2165871Snate@binkert.orgif have_mysql:
2175871Snate@binkert.org    mysql_version = os.popen(mysql_config + ' --version').read()
2185871Snate@binkert.org    mysql_version = mysql_version.split('.')
2195871Snate@binkert.org    mysql_major = int(mysql_version[0])
2205871Snate@binkert.org    mysql_minor = int(mysql_version[1])
2215871Snate@binkert.org    # This version check is probably overly conservative, but it deals
2225871Snate@binkert.org    # with the versions we have installed.
2235871Snate@binkert.org    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2246121Snate@binkert.org        print "Warning: MySQL v4.1 or newer required."
2256121Snate@binkert.org        have_mysql = False
2265863Snate@binkert.org
227955SN/A# Set up mysql_config commands.
228955SN/Aif have_mysql:
2292632Sstever@eecs.umich.edu    mysql_config_include = mysql_config + ' --include'
2302632Sstever@eecs.umich.edu    if os.system(mysql_config_include + ' > /dev/null') != 0:
231955SN/A        # older mysql_config versions don't support --include, use
232955SN/A        # --cflags instead
233955SN/A        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
234955SN/A    # This seems to work in all versions
2355863Snate@binkert.org    mysql_config_libs = mysql_config + ' --libs'
236955SN/A
2372632Sstever@eecs.umich.eduenv = conf.Finish()
2382632Sstever@eecs.umich.edu
2392632Sstever@eecs.umich.edu# Define the universe of supported ISAs
2402632Sstever@eecs.umich.eduenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2412632Sstever@eecs.umich.edu
2422632Sstever@eecs.umich.edu# Define the universe of supported CPU models
2432632Sstever@eecs.umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2442632Sstever@eecs.umich.edu                       'FullCPU', 'AlphaFullCPU']
2452632Sstever@eecs.umich.edu
2462632Sstever@eecs.umich.edu# Sticky options get saved in the options file so they persist from
2472632Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
2482632Sstever@eecs.umich.edu# value becomes sticky).
2492632Sstever@eecs.umich.edusticky_opts = Options(args=ARGUMENTS)
2503718Sstever@eecs.umich.edusticky_opts.AddOptions(
2513718Sstever@eecs.umich.edu    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2523718Sstever@eecs.umich.edu    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2533718Sstever@eecs.umich.edu    # There's a bug in scons 0.96.1 that causes ListOptions with list
2543718Sstever@eecs.umich.edu    # values (more than one value) not to be able to be restored from
2555863Snate@binkert.org    # a saved option file.  If this causes trouble then upgrade to
2565863Snate@binkert.org    # scons 0.96.90 or later.
2573718Sstever@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2583718Sstever@eecs.umich.edu               env['ALL_CPU_LIST']),
2596121Snate@binkert.org    BoolOption('ALPHA_TLASER',
2605863Snate@binkert.org               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2613718Sstever@eecs.umich.edu    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2623718Sstever@eecs.umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2632634Sstever@eecs.umich.edu               False),
2642634Sstever@eecs.umich.edu    BoolOption('SS_COMPATIBLE_FP',
2655863Snate@binkert.org               'Make floating-point results compatible with SimpleScalar',
2662638Sstever@eecs.umich.edu               False),
2672632Sstever@eecs.umich.edu    BoolOption('USE_SSE2',
2682632Sstever@eecs.umich.edu               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2692632Sstever@eecs.umich.edu               False),
2702632Sstever@eecs.umich.edu    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2712632Sstever@eecs.umich.edu    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2722632Sstever@eecs.umich.edu    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2731858SN/A    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2743716Sstever@eecs.umich.edu    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2752638Sstever@eecs.umich.edu    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2762638Sstever@eecs.umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
2772638Sstever@eecs.umich.edu    )
2782638Sstever@eecs.umich.edu
2792638Sstever@eecs.umich.edu# Non-sticky options only apply to the current build.
2802638Sstever@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS)
2812638Sstever@eecs.umich.edunonsticky_opts.AddOptions(
2825863Snate@binkert.org    BoolOption('update_ref', 'Update test reference outputs', False)
2835863Snate@binkert.org    )
2845863Snate@binkert.org
285955SN/A# These options get exported to #defines in config/*.hh (see m5/SConscript).
2865341Sstever@gmail.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2875341Sstever@gmail.com                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2885863Snate@binkert.org                     'STATS_BINNING']
2897756SAli.Saidi@ARM.com
2905341Sstever@gmail.com# Define a handy 'no-op' action
2916121Snate@binkert.orgdef no_action(target, source, env):
2924494Ssaidi@eecs.umich.edu    return 0
2936121Snate@binkert.org
2941105SN/Aenv.NoAction = Action(no_action, None)
2952667Sstever@eecs.umich.edu
2962667Sstever@eecs.umich.edu###################################################
2972667Sstever@eecs.umich.edu#
2982667Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers.
2996121Snate@binkert.org#
3002667Sstever@eecs.umich.edu###################################################
3015341Sstever@gmail.com
3025863Snate@binkert.org# This function generates a config header file that #defines the
3035341Sstever@gmail.com# option symbol to the current option setting (0 or 1).  The source
3045341Sstever@gmail.com# operands are the name of the option and a Value node containing the
3055341Sstever@gmail.com# value of the option.
3065863Snate@binkert.orgdef build_config_file(target, source, env):
3075341Sstever@gmail.com    (option, value) = [s.get_contents() for s in source]
3085341Sstever@gmail.com    f = file(str(target[0]), 'w')
3095341Sstever@gmail.com    print >> f, '#define', option, value
3105863Snate@binkert.org    f.close()
3115341Sstever@gmail.com    return None
3125341Sstever@gmail.com
3135341Sstever@gmail.com# Generate the message to be printed when building the config file.
3145341Sstever@gmail.comdef build_config_file_string(target, source, env):
3155341Sstever@gmail.com    (option, value) = [s.get_contents() for s in source]
3165341Sstever@gmail.com    return "Defining %s as %s in %s." % (option, value, target[0])
3175341Sstever@gmail.com
3185341Sstever@gmail.com# Combine the two functions into a scons Action object.
3195341Sstever@gmail.comconfig_action = Action(build_config_file, build_config_file_string)
3205341Sstever@gmail.com
3215863Snate@binkert.org# The emitter munges the source & target node lists to reflect what
3225341Sstever@gmail.com# we're really doing.
3235863Snate@binkert.orgdef config_emitter(target, source, env):
3247756SAli.Saidi@ARM.com    # extract option name from Builder arg
3255341Sstever@gmail.com    option = str(target[0])
3265863Snate@binkert.org    # True target is config header file
3276121Snate@binkert.org    target = os.path.join('config', option.lower() + '.hh')
3286121Snate@binkert.org    # Force value to 0/1 even if it's a Python bool
3295397Ssaidi@eecs.umich.edu    val = int(eval(str(env[option])))
3305397Ssaidi@eecs.umich.edu    # Sources are option name & value (packaged in SCons Value nodes)
3317727SAli.Saidi@ARM.com    return ([target], [Value(option), Value(val)])
3325341Sstever@gmail.com
3336168Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action)
3346168Snate@binkert.org
3355341Sstever@gmail.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3367756SAli.Saidi@ARM.com
3377756SAli.Saidi@ARM.com###################################################
3387756SAli.Saidi@ARM.com#
3397756SAli.Saidi@ARM.com# Define a SCons builder for copying files.  This is used by the
3407756SAli.Saidi@ARM.com# Python zipfile code in src/python/SConscript, but is placed up here
3417756SAli.Saidi@ARM.com# since it's potentially more generally applicable.
3425341Sstever@gmail.com#
3435341Sstever@gmail.com###################################################
3445341Sstever@gmail.com
3455341Sstever@gmail.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3465863Snate@binkert.org
3475341Sstever@gmail.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3485341Sstever@gmail.com
3496121Snate@binkert.org###################################################
3506121Snate@binkert.org#
3517756SAli.Saidi@ARM.com# Define a simple SCons builder to concatenate files.
3525341Sstever@gmail.com#
3536814Sgblack@eecs.umich.edu# Used to append the Python zip archive to the executable.
3547756SAli.Saidi@ARM.com#
3556814Sgblack@eecs.umich.edu###################################################
3565863Snate@binkert.org
3576121Snate@binkert.orgconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3585341Sstever@gmail.com                                          'chmod +x $TARGET']))
3595863Snate@binkert.org
3605341Sstever@gmail.comenv.Append(BUILDERS = { 'Concat' : concat_builder })
3616121Snate@binkert.org
3626121Snate@binkert.org
3636121Snate@binkert.org# base help text
3645742Snate@binkert.orghelp_text = '''
3655742Snate@binkert.orgUsage: scons [scons options] [build options] [target(s)]
3665341Sstever@gmail.com
3675742Snate@binkert.org'''
3685742Snate@binkert.org
3695341Sstever@gmail.com# libelf build is shared across all configs in the build root.
3706017Snate@binkert.orgenv.SConscript('ext/libelf/SConscript',
3716121Snate@binkert.org               build_dir = os.path.join(build_root, 'libelf'),
3726017Snate@binkert.org               exports = 'env')
3737816Ssteve.reinhardt@amd.com
3747756SAli.Saidi@ARM.com###################################################
3757756SAli.Saidi@ARM.com#
3767756SAli.Saidi@ARM.com# Define build environments for selected configurations.
3777756SAli.Saidi@ARM.com#
3787756SAli.Saidi@ARM.com###################################################
3797756SAli.Saidi@ARM.com
3807756SAli.Saidi@ARM.com# rename base env
3817756SAli.Saidi@ARM.combase_env = env
3827816Ssteve.reinhardt@amd.com
3837816Ssteve.reinhardt@amd.comfor build_path in build_paths:
3847816Ssteve.reinhardt@amd.com    print "Building in", build_path
3857816Ssteve.reinhardt@amd.com    # build_dir is the tail component of build path, and is used to
3867816Ssteve.reinhardt@amd.com    # determine the build parameters (e.g., 'ALPHA_SE')
3877816Ssteve.reinhardt@amd.com    (build_root, build_dir) = os.path.split(build_path)
3887816Ssteve.reinhardt@amd.com    # Make a copy of the build-root environment to use for this config.
3897816Ssteve.reinhardt@amd.com    env = base_env.Copy()
3907816Ssteve.reinhardt@amd.com
3917816Ssteve.reinhardt@amd.com    # Set env options according to the build directory config.
3927756SAli.Saidi@ARM.com    sticky_opts.files = []
3937816Ssteve.reinhardt@amd.com    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
3947816Ssteve.reinhardt@amd.com    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
3957816Ssteve.reinhardt@amd.com    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
3967816Ssteve.reinhardt@amd.com    current_opts_file = os.path.join(build_root, 'options', build_dir)
3977816Ssteve.reinhardt@amd.com    if os.path.isfile(current_opts_file):
3987816Ssteve.reinhardt@amd.com        sticky_opts.files.append(current_opts_file)
3997816Ssteve.reinhardt@amd.com        print "Using saved options file %s" % current_opts_file
4007816Ssteve.reinhardt@amd.com    else:
4017816Ssteve.reinhardt@amd.com        # Build dir-specific options file doesn't exist.
4027816Ssteve.reinhardt@amd.com
4037816Ssteve.reinhardt@amd.com        # Make sure the directory is there so we can create it later
4047816Ssteve.reinhardt@amd.com        opt_dir = os.path.dirname(current_opts_file)
4057816Ssteve.reinhardt@amd.com        if not os.path.isdir(opt_dir):
4067816Ssteve.reinhardt@amd.com            os.mkdir(opt_dir)
4077816Ssteve.reinhardt@amd.com
4087816Ssteve.reinhardt@amd.com        # Get default build options from source tree.  Options are
4097816Ssteve.reinhardt@amd.com        # normally determined by name of $BUILD_DIR, but can be
4107816Ssteve.reinhardt@amd.com        # overriden by 'default=' arg on command line.
4117816Ssteve.reinhardt@amd.com        default_opts_file = os.path.join('build_opts',
4127816Ssteve.reinhardt@amd.com                                         ARGUMENTS.get('default', build_dir))
4137816Ssteve.reinhardt@amd.com        if os.path.isfile(default_opts_file):
4147816Ssteve.reinhardt@amd.com            sticky_opts.files.append(default_opts_file)
4157816Ssteve.reinhardt@amd.com            print "Options file %s not found,\n  using defaults in %s" \
4167816Ssteve.reinhardt@amd.com                  % (current_opts_file, default_opts_file)
4177816Ssteve.reinhardt@amd.com        else:
4187816Ssteve.reinhardt@amd.com            print "Error: cannot find options file %s or %s" \
4197816Ssteve.reinhardt@amd.com                  % (current_opts_file, default_opts_file)
4207816Ssteve.reinhardt@amd.com            Exit(1)
4217816Ssteve.reinhardt@amd.com
4227816Ssteve.reinhardt@amd.com    # Apply current option settings to env
4237816Ssteve.reinhardt@amd.com    sticky_opts.Update(env)
4247816Ssteve.reinhardt@amd.com    nonsticky_opts.Update(env)
4257816Ssteve.reinhardt@amd.com
4267816Ssteve.reinhardt@amd.com    help_text += "Sticky options for %s:\n" % build_dir \
4277816Ssteve.reinhardt@amd.com                 + sticky_opts.GenerateHelpText(env) \
4287816Ssteve.reinhardt@amd.com                 + "\nNon-sticky options for %s:\n" % build_dir \
4297816Ssteve.reinhardt@amd.com                 + nonsticky_opts.GenerateHelpText(env)
4307816Ssteve.reinhardt@amd.com
4317816Ssteve.reinhardt@amd.com    # Process option settings.
4327816Ssteve.reinhardt@amd.com
4337816Ssteve.reinhardt@amd.com    if not have_fenv and env['USE_FENV']:
4347816Ssteve.reinhardt@amd.com        print "Warning: <fenv.h> not available; " \
4357816Ssteve.reinhardt@amd.com              "forcing USE_FENV to False in", build_dir + "."
4367816Ssteve.reinhardt@amd.com        env['USE_FENV'] = False
4377816Ssteve.reinhardt@amd.com
4387816Ssteve.reinhardt@amd.com    if not env['USE_FENV']:
4397816Ssteve.reinhardt@amd.com        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4407816Ssteve.reinhardt@amd.com        print "         FP results may deviate slightly from other platforms."
4417816Ssteve.reinhardt@amd.com
4427816Ssteve.reinhardt@amd.com    if env['EFENCE']:
4437816Ssteve.reinhardt@amd.com        env.Append(LIBS=['efence'])
4447816Ssteve.reinhardt@amd.com
4457816Ssteve.reinhardt@amd.com    if env['USE_MYSQL']:
4467816Ssteve.reinhardt@amd.com        if not have_mysql:
4477816Ssteve.reinhardt@amd.com            print "Warning: MySQL not available; " \
4487816Ssteve.reinhardt@amd.com                  "forcing USE_MYSQL to False in", build_dir + "."
4497816Ssteve.reinhardt@amd.com            env['USE_MYSQL'] = False
4507816Ssteve.reinhardt@amd.com        else:
4517816Ssteve.reinhardt@amd.com            print "Compiling in", build_dir, "with MySQL support."
4527816Ssteve.reinhardt@amd.com            env.ParseConfig(mysql_config_libs)
4537816Ssteve.reinhardt@amd.com            env.ParseConfig(mysql_config_include)
4547756SAli.Saidi@ARM.com
4557756SAli.Saidi@ARM.com    # Save sticky option settings back to current options file
4567756SAli.Saidi@ARM.com    sticky_opts.Save(current_opts_file, env)
4577756SAli.Saidi@ARM.com
4587756SAli.Saidi@ARM.com    # Do this after we save setting back, or else we'll tack on an
4597756SAli.Saidi@ARM.com    # extra 'qdo' every time we run scons.
4607816Ssteve.reinhardt@amd.com    if env['BATCH']:
4617816Ssteve.reinhardt@amd.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4627816Ssteve.reinhardt@amd.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4637816Ssteve.reinhardt@amd.com
4647816Ssteve.reinhardt@amd.com    if env['USE_SSE2']:
4657816Ssteve.reinhardt@amd.com        env.Append(CCFLAGS='-msse2')
4667816Ssteve.reinhardt@amd.com
4677816Ssteve.reinhardt@amd.com    # The m5/SConscript file sets up the build rules in 'env' according
4687816Ssteve.reinhardt@amd.com    # to the configured options.  It returns a list of environments,
4697816Ssteve.reinhardt@amd.com    # one for each variant build (debug, opt, etc.)
4707756SAli.Saidi@ARM.com    envList = SConscript('src/SConscript', build_dir = build_path,
4717756SAli.Saidi@ARM.com                         exports = 'env', duplicate = False)
4726654Snate@binkert.org
4736654Snate@binkert.org    # Set up the regression tests for each build.
4745871Snate@binkert.org#    for e in envList:
4756121Snate@binkert.org#        SConscript('m5-test/SConscript',
4766121Snate@binkert.org#                   build_dir = os.path.join(build_dir, 'test', e.Label),
4776121Snate@binkert.org#                   exports = { 'env' : e }, duplicate = False)
4786121Snate@binkert.org
4793940Ssaidi@eecs.umich.eduHelp(help_text)
4803918Ssaidi@eecs.umich.edu
4813918Ssaidi@eecs.umich.edu###################################################
4821858SN/A#
4836121Snate@binkert.org# Let SCons do its thing.  At this point SCons will use the defined
4847739Sgblack@eecs.umich.edu# build environments to build the requested targets.
4857739Sgblack@eecs.umich.edu#
4866143Snate@binkert.org###################################################
4877739Sgblack@eecs.umich.edu
4887618SAli.Saidi@arm.com