SConstruct revision 2929
1955SN/A# -*- mode:python -*-
2955SN/A
39812Sandreas.hansson@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from
157816Ssteve.reinhardt@amd.com# this software without specific prior written permission.
165871Snate@binkert.org#
171762SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28955SN/A#
29955SN/A# Authors: Steve Reinhardt
30955SN/A
31955SN/A###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
35955SN/A# While in this directory ('m5'), just type 'scons' to build the default
36955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
38955SN/A# the optimized full-system version).
39955SN/A#
40955SN/A# You can build M5 in a different directory as long as there is a
41955SN/A# 'build/<CONFIG>' somewhere along the target path.  The build system
422665Ssaidi@eecs.umich.edu# expects that all configs under the same build directory are being
432665Ssaidi@eecs.umich.edu# built for the same host system.
445863Snate@binkert.org#
45955SN/A# Examples:
46955SN/A#
47955SN/A#   The following two commands are equivalent.  The '-u' option tells
48955SN/A#   scons to search up the directory tree for this SConstruct file.
49955SN/A#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
508878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512632Sstever@eecs.umich.edu#
528878Ssteve.reinhardt@amd.com#   The following two commands are equivalent and demonstrate building
532632Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
54955SN/A#   scons to chdir to the specified directory to find this SConstruct
558878Ssteve.reinhardt@amd.com#   file.
562632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
572761Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
582632Sstever@eecs.umich.edu#
592632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
602632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
612761Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
622761Sstever@eecs.umich.edu# options as well.
632761Sstever@eecs.umich.edu#
648878Ssteve.reinhardt@amd.com###################################################
658878Ssteve.reinhardt@amd.com
662761Sstever@eecs.umich.edu# Python library imports
672761Sstever@eecs.umich.eduimport sys
682761Sstever@eecs.umich.eduimport os
692761Sstever@eecs.umich.edu
702761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions.  If your system's
718878Ssteve.reinhardt@amd.com# default installation of Python is not recent enough, you can use a
728878Ssteve.reinhardt@amd.com# non-default installation of the Python interpreter by either (1)
732632Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python'
742632Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the
758878Ssteve.reinhardt@amd.com# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
768878Ssteve.reinhardt@amd.comEnsurePythonVersion(2,4)
772632Sstever@eecs.umich.edu
78955SN/A# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
79955SN/A# 3-element version number.
80955SN/Amin_scons_version = (0,96,91)
815863Snate@binkert.orgtry:
825863Snate@binkert.org    EnsureSConsVersion(*min_scons_version)
835863Snate@binkert.orgexcept:
845863Snate@binkert.org    print "Error checking current SCons version."
855863Snate@binkert.org    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
865863Snate@binkert.org    Exit(2)
875863Snate@binkert.org    
885863Snate@binkert.org
895863Snate@binkert.org# The absolute path to the current directory (where this file lives).
905863Snate@binkert.orgROOT = Dir('.').abspath
915863Snate@binkert.org
928878Ssteve.reinhardt@amd.com# Paths to the M5 and external source trees.
935863Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src')
945863Snate@binkert.org
955863Snate@binkert.org# tell python where to find m5 python code
969812Sandreas.hansson@arm.comsys.path.append(os.path.join(ROOT, 'src/python'))
979812Sandreas.hansson@arm.com
985863Snate@binkert.org###################################################
999812Sandreas.hansson@arm.com#
1005863Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
1015863Snate@binkert.org# the target(s).
1025863Snate@binkert.org#
1039812Sandreas.hansson@arm.com###################################################
1049812Sandreas.hansson@arm.com
1055863Snate@binkert.org# Find default configuration & binary.
1065863Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1078878Ssteve.reinhardt@amd.com
1085863Snate@binkert.org# Ask SCons which directory it was invoked from.
1095863Snate@binkert.orglaunch_dir = GetLaunchDir()
1105863Snate@binkert.org
1116654Snate@binkert.org# Make targets relative to invocation directory
112955SN/Aabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1135396Ssaidi@eecs.umich.edu                  BUILD_TARGETS)
1145863Snate@binkert.org
1155863Snate@binkert.org# helper function: find last occurrence of element in list
1164202Sbinkertn@umich.edudef rfind(l, elt, offs = -1):
1175863Snate@binkert.org    for i in range(len(l)+offs, 0, -1):
1185863Snate@binkert.org        if l[i] == elt:
1195863Snate@binkert.org            return i
1205863Snate@binkert.org    raise ValueError, "element not found"
121955SN/A
1226654Snate@binkert.org# Each target must have 'build' in the interior of the path; the
1235273Sstever@gmail.com# directory below this will determine the build parameters.  For
1245871Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1255273Sstever@gmail.com# recognize that ALPHA_SE specifies the configuration because it
1266655Snate@binkert.org# follow 'build' in the bulid path.
1278878Ssteve.reinhardt@amd.com
1286655Snate@binkert.org# Generate a list of the unique build roots and configs that the
1296655Snate@binkert.org# collected targets reference.
1309219Spower.jg@gmail.combuild_paths = []
1316655Snate@binkert.orgbuild_root = None
1325871Snate@binkert.orgfor t in abs_targets:
1336654Snate@binkert.org    path_dirs = t.split('/')
1348947Sandreas.hansson@arm.com    try:
1355396Ssaidi@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1368120Sgblack@eecs.umich.edu    except:
1378120Sgblack@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1388120Sgblack@eecs.umich.edu        Exit(1)
1398120Sgblack@eecs.umich.edu    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1408120Sgblack@eecs.umich.edu    if not build_root:
1418120Sgblack@eecs.umich.edu        build_root = this_build_root
1428120Sgblack@eecs.umich.edu    else:
1438120Sgblack@eecs.umich.edu        if this_build_root != build_root:
1448879Ssteve.reinhardt@amd.com            print "Error: build targets not under same build root\n"\
1458879Ssteve.reinhardt@amd.com                  "  %s\n  %s" % (build_root, this_build_root)
1468879Ssteve.reinhardt@amd.com            Exit(1)
1478879Ssteve.reinhardt@amd.com    build_path = os.path.join('/',*path_dirs[:build_top+2])
1488879Ssteve.reinhardt@amd.com    if build_path not in build_paths:
1498879Ssteve.reinhardt@amd.com        build_paths.append(build_path)
1508879Ssteve.reinhardt@amd.com
1518879Ssteve.reinhardt@amd.com###################################################
1528879Ssteve.reinhardt@amd.com#
1538879Ssteve.reinhardt@amd.com# Set up the default build environment.  This environment is copied
1548879Ssteve.reinhardt@amd.com# and modified according to each selected configuration.
1558879Ssteve.reinhardt@amd.com#
1568879Ssteve.reinhardt@amd.com###################################################
1578120Sgblack@eecs.umich.edu
1588120Sgblack@eecs.umich.eduenv = Environment(ENV = os.environ,  # inherit user's environment vars
1598120Sgblack@eecs.umich.edu                  ROOT = ROOT,
1608120Sgblack@eecs.umich.edu                  SRCDIR = SRCDIR)
1618120Sgblack@eecs.umich.edu
1628120Sgblack@eecs.umich.eduenv.SConsignFile(os.path.join(build_root,"sconsign"))
1638120Sgblack@eecs.umich.edu
1648120Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up
1658120Sgblack@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
1668120Sgblack@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
1678120Sgblack@eecs.umich.edu# (soft) links work better.
1688120Sgblack@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy')
1698120Sgblack@eecs.umich.edu
1708120Sgblack@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but
1718879Ssteve.reinhardt@amd.com# unnecessary builds, but it also seems to make trivial builds take
1728879Ssteve.reinhardt@amd.com# noticeably longer.
1738879Ssteve.reinhardt@amd.comif False:
1748879Ssteve.reinhardt@amd.com    env.TargetSignatures('content')
1758879Ssteve.reinhardt@amd.com
1768879Ssteve.reinhardt@amd.com# M5_PLY is used by isa_parser.py to find the PLY package.
1778879Ssteve.reinhardt@amd.comenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1788879Ssteve.reinhardt@amd.com
1799227Sandreas.hansson@arm.com# Set up default C++ compiler flags
1809227Sandreas.hansson@arm.comenv.Append(CCFLAGS='-pipe')
1818879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-fno-strict-aliasing')
1828879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1838879Ssteve.reinhardt@amd.comif sys.platform == 'cygwin':
1848879Ssteve.reinhardt@amd.com    # cygwin has some header file issues...
1858120Sgblack@eecs.umich.edu    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1868947Sandreas.hansson@arm.comenv.Append(CPPPATH=[Dir('ext/dnet')])
1877816Ssteve.reinhardt@amd.com
1885871Snate@binkert.org# Find Python include and library directories for embedding the
1895871Snate@binkert.org# interpreter.  For consistency, we will use the same Python
1906121Snate@binkert.org# installation used to run scons (and thus this script).  If you want
1915871Snate@binkert.org# to link in an alternate version, see above for instructions on how
1925871Snate@binkert.org# to invoke scons with a different copy of the Python interpreter.
1939119Sandreas.hansson@arm.com
1949396Sandreas.hansson@arm.com# Get brief Python version name (e.g., "python2.4") for locating
1959396Sandreas.hansson@arm.com# include & library files
196955SN/Apy_version_name = 'python' + sys.version[:3]
1979416SAndreas.Sandberg@ARM.com
1989416SAndreas.Sandberg@ARM.com# include path, e.g. /usr/local/include/python2.4
1999416SAndreas.Sandberg@ARM.comenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
2009416SAndreas.Sandberg@ARM.comenv.Append(LIBS = py_version_name)
2019416SAndreas.Sandberg@ARM.com# add library path too if it's not in the default place
2029416SAndreas.Sandberg@ARM.comif sys.exec_prefix != '/usr':
2039416SAndreas.Sandberg@ARM.com    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
2045871Snate@binkert.org
2055871Snate@binkert.org# Set up SWIG flags & scanner
2069416SAndreas.Sandberg@ARM.com
2079416SAndreas.Sandberg@ARM.comenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2085871Snate@binkert.org
209955SN/Aimport SCons.Scanner
2106121Snate@binkert.org
2118881Smarc.orr@gmail.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2126121Snate@binkert.org
2136121Snate@binkert.orgswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2141533SN/A                                        swig_inc_re)
2159239Sandreas.hansson@arm.com
2169239Sandreas.hansson@arm.comenv.Append(SCANNERS = swig_scanner)
2179239Sandreas.hansson@arm.com
2189239Sandreas.hansson@arm.com# Other default libraries
2199239Sandreas.hansson@arm.comenv.Append(LIBS=['z'])
2209239Sandreas.hansson@arm.com
2219239Sandreas.hansson@arm.com# Platform-specific configuration.  Note again that we assume that all
2229239Sandreas.hansson@arm.com# builds under a given build root run on the same host platform.
2239239Sandreas.hansson@arm.comconf = Configure(env,
2249239Sandreas.hansson@arm.com                 conf_dir = os.path.join(build_root, '.scons_config'),
2259239Sandreas.hansson@arm.com                 log_file = os.path.join(build_root, 'scons_config.log'))
2269239Sandreas.hansson@arm.com
2276655Snate@binkert.org# Check for <fenv.h> (C99 FP environment control)
2286655Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>')
2296655Snate@binkert.orgif not have_fenv:
2306655Snate@binkert.org    print "Warning: Header file <fenv.h> not found."
2315871Snate@binkert.org    print "         This host has no IEEE FP rounding mode control."
2325871Snate@binkert.org
2335863Snate@binkert.org# Check for mysql.
2345871Snate@binkert.orgmysql_config = WhereIs('mysql_config')
2358878Ssteve.reinhardt@amd.comhave_mysql = mysql_config != None
2365871Snate@binkert.org
2375871Snate@binkert.org# Check MySQL version.
2385871Snate@binkert.orgif have_mysql:
2395863Snate@binkert.org    mysql_version = os.popen(mysql_config + ' --version').read()
2406121Snate@binkert.org    mysql_version = mysql_version.split('.')
2415863Snate@binkert.org    mysql_major = int(mysql_version[0])
2425871Snate@binkert.org    mysql_minor = int(mysql_version[1])
2438336Ssteve.reinhardt@amd.com    # This version check is probably overly conservative, but it deals
2448336Ssteve.reinhardt@amd.com    # with the versions we have installed.
2458336Ssteve.reinhardt@amd.com    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2468336Ssteve.reinhardt@amd.com        print "Warning: MySQL v4.1 or newer required."
2474678Snate@binkert.org        have_mysql = False
2488336Ssteve.reinhardt@amd.com
2498336Ssteve.reinhardt@amd.com# Set up mysql_config commands.
2508336Ssteve.reinhardt@amd.comif have_mysql:
2514678Snate@binkert.org    mysql_config_include = mysql_config + ' --include'
2524678Snate@binkert.org    if os.system(mysql_config_include + ' > /dev/null') != 0:
2534678Snate@binkert.org        # older mysql_config versions don't support --include, use
2544678Snate@binkert.org        # --cflags instead
2557827Snate@binkert.org        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2567827Snate@binkert.org    # This seems to work in all versions
2578336Ssteve.reinhardt@amd.com    mysql_config_libs = mysql_config + ' --libs'
2584678Snate@binkert.org
2598336Ssteve.reinhardt@amd.comenv = conf.Finish()
2608336Ssteve.reinhardt@amd.com
2618336Ssteve.reinhardt@amd.com# Define the universe of supported ISAs
2628336Ssteve.reinhardt@amd.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2638336Ssteve.reinhardt@amd.com
2648336Ssteve.reinhardt@amd.com# Define the universe of supported CPU models
2655871Snate@binkert.orgenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2665871Snate@binkert.org                       'FullCPU', 'O3CPU',
2678336Ssteve.reinhardt@amd.com                       'OzoneCPU']
2688336Ssteve.reinhardt@amd.com
2698336Ssteve.reinhardt@amd.com# Sticky options get saved in the options file so they persist from
2708336Ssteve.reinhardt@amd.com# one invocation to the next (unless overridden, in which case the new
2718336Ssteve.reinhardt@amd.com# value becomes sticky).
2725871Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS)
2738336Ssteve.reinhardt@amd.comsticky_opts.AddOptions(
2748336Ssteve.reinhardt@amd.com    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2758336Ssteve.reinhardt@amd.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2768336Ssteve.reinhardt@amd.com    # There's a bug in scons 0.96.1 that causes ListOptions with list
2778336Ssteve.reinhardt@amd.com    # values (more than one value) not to be able to be restored from
2784678Snate@binkert.org    # a saved option file.  If this causes trouble then upgrade to
2795871Snate@binkert.org    # scons 0.96.90 or later.
2804678Snate@binkert.org    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2818336Ssteve.reinhardt@amd.com               env['ALL_CPU_LIST']),
2828336Ssteve.reinhardt@amd.com    BoolOption('ALPHA_TLASER',
2838336Ssteve.reinhardt@amd.com               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2848336Ssteve.reinhardt@amd.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2858336Ssteve.reinhardt@amd.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2868336Ssteve.reinhardt@amd.com               False),
2878336Ssteve.reinhardt@amd.com    BoolOption('SS_COMPATIBLE_FP',
2888336Ssteve.reinhardt@amd.com               'Make floating-point results compatible with SimpleScalar',
2898336Ssteve.reinhardt@amd.com               False),
2908336Ssteve.reinhardt@amd.com    BoolOption('USE_SSE2',
2918336Ssteve.reinhardt@amd.com               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2928336Ssteve.reinhardt@amd.com               False),
2938336Ssteve.reinhardt@amd.com    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2948336Ssteve.reinhardt@amd.com    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2958336Ssteve.reinhardt@amd.com    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
2968336Ssteve.reinhardt@amd.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2978336Ssteve.reinhardt@amd.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2985871Snate@binkert.org    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2996121Snate@binkert.org    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
300955SN/A    )
301955SN/A
3022632Sstever@eecs.umich.edu# Non-sticky options only apply to the current build.
3032632Sstever@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS)
304955SN/Anonsticky_opts.AddOptions(
305955SN/A    BoolOption('update_ref', 'Update test reference outputs', False)
306955SN/A    )
307955SN/A
3088878Ssteve.reinhardt@amd.com# These options get exported to #defines in config/*.hh (see src/SConscript).
309955SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3102632Sstever@eecs.umich.edu                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3112632Sstever@eecs.umich.edu                     'USE_CHECKER']
3122632Sstever@eecs.umich.edu
3132632Sstever@eecs.umich.edu# Define a handy 'no-op' action
3142632Sstever@eecs.umich.edudef no_action(target, source, env):
3152632Sstever@eecs.umich.edu    return 0
3162632Sstever@eecs.umich.edu
3178268Ssteve.reinhardt@amd.comenv.NoAction = Action(no_action, None)
3188268Ssteve.reinhardt@amd.com
3198268Ssteve.reinhardt@amd.com###################################################
3208268Ssteve.reinhardt@amd.com#
3218268Ssteve.reinhardt@amd.com# Define a SCons builder for configuration flag headers.
3228268Ssteve.reinhardt@amd.com#
3238268Ssteve.reinhardt@amd.com###################################################
3242632Sstever@eecs.umich.edu
3252632Sstever@eecs.umich.edu# This function generates a config header file that #defines the
3262632Sstever@eecs.umich.edu# option symbol to the current option setting (0 or 1).  The source
3272632Sstever@eecs.umich.edu# operands are the name of the option and a Value node containing the
3288268Ssteve.reinhardt@amd.com# value of the option.
3292632Sstever@eecs.umich.edudef build_config_file(target, source, env):
3308268Ssteve.reinhardt@amd.com    (option, value) = [s.get_contents() for s in source]
3318268Ssteve.reinhardt@amd.com    f = file(str(target[0]), 'w')
3328268Ssteve.reinhardt@amd.com    print >> f, '#define', option, value
3338268Ssteve.reinhardt@amd.com    f.close()
3343718Sstever@eecs.umich.edu    return None
3352634Sstever@eecs.umich.edu
3362634Sstever@eecs.umich.edu# Generate the message to be printed when building the config file.
3375863Snate@binkert.orgdef build_config_file_string(target, source, env):
3382638Sstever@eecs.umich.edu    (option, value) = [s.get_contents() for s in source]
3398268Ssteve.reinhardt@amd.com    return "Defining %s as %s in %s." % (option, value, target[0])
3402632Sstever@eecs.umich.edu
3412632Sstever@eecs.umich.edu# Combine the two functions into a scons Action object.
3422632Sstever@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string)
3432632Sstever@eecs.umich.edu
3442632Sstever@eecs.umich.edu# The emitter munges the source & target node lists to reflect what
3451858SN/A# we're really doing.
3463716Sstever@eecs.umich.edudef config_emitter(target, source, env):
3472638Sstever@eecs.umich.edu    # extract option name from Builder arg
3482638Sstever@eecs.umich.edu    option = str(target[0])
3492638Sstever@eecs.umich.edu    # True target is config header file
3502638Sstever@eecs.umich.edu    target = os.path.join('config', option.lower() + '.hh')
3512638Sstever@eecs.umich.edu    # Force value to 0/1 even if it's a Python bool
3522638Sstever@eecs.umich.edu    val = int(eval(str(env[option])))
3532638Sstever@eecs.umich.edu    # Sources are option name & value (packaged in SCons Value nodes)
3545863Snate@binkert.org    return ([target], [Value(option), Value(val)])
3555863Snate@binkert.org
3565863Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action)
357955SN/A
3585341Sstever@gmail.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3595341Sstever@gmail.com
3605863Snate@binkert.org###################################################
3617756SAli.Saidi@ARM.com#
3625341Sstever@gmail.com# Define a SCons builder for copying files.  This is used by the
3636121Snate@binkert.org# Python zipfile code in src/python/SConscript, but is placed up here
3644494Ssaidi@eecs.umich.edu# since it's potentially more generally applicable.
3656121Snate@binkert.org#
3661105SN/A###################################################
3672667Sstever@eecs.umich.edu
3682667Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3692667Sstever@eecs.umich.edu
3702667Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3716121Snate@binkert.org
3722667Sstever@eecs.umich.edu###################################################
3735341Sstever@gmail.com#
3745863Snate@binkert.org# Define a simple SCons builder to concatenate files.
3755341Sstever@gmail.com#
3765341Sstever@gmail.com# Used to append the Python zip archive to the executable.
3775341Sstever@gmail.com#
3788120Sgblack@eecs.umich.edu###################################################
3795341Sstever@gmail.com
3808120Sgblack@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3815341Sstever@gmail.com                                          'chmod +x $TARGET']))
3828120Sgblack@eecs.umich.edu
3836121Snate@binkert.orgenv.Append(BUILDERS = { 'Concat' : concat_builder })
3846121Snate@binkert.org
3858980Ssteve.reinhardt@amd.com
3869396Sandreas.hansson@arm.com# base help text
3875397Ssaidi@eecs.umich.eduhelp_text = '''
3885397Ssaidi@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)]
3897727SAli.Saidi@ARM.com
3908268Ssteve.reinhardt@amd.com'''
3916168Snate@binkert.org
3925341Sstever@gmail.com# libelf build is shared across all configs in the build root.
3938120Sgblack@eecs.umich.eduenv.SConscript('ext/libelf/SConscript',
3948120Sgblack@eecs.umich.edu               build_dir = os.path.join(build_root, 'libelf'),
3958120Sgblack@eecs.umich.edu               exports = 'env')
3966814Sgblack@eecs.umich.edu
3975863Snate@binkert.org###################################################
3988120Sgblack@eecs.umich.edu#
3995341Sstever@gmail.com# Define build environments for selected configurations.
4005863Snate@binkert.org#
4018268Ssteve.reinhardt@amd.com###################################################
4026121Snate@binkert.org
4036121Snate@binkert.org# rename base env
4048268Ssteve.reinhardt@amd.combase_env = env
4055742Snate@binkert.org
4065742Snate@binkert.orgfor build_path in build_paths:
4075341Sstever@gmail.com    print "Building in", build_path
4085742Snate@binkert.org    # build_dir is the tail component of build path, and is used to
4095742Snate@binkert.org    # determine the build parameters (e.g., 'ALPHA_SE')
4105341Sstever@gmail.com    (build_root, build_dir) = os.path.split(build_path)
4116017Snate@binkert.org    # Make a copy of the build-root environment to use for this config.
4126121Snate@binkert.org    env = base_env.Copy()
4136017Snate@binkert.org
4147816Ssteve.reinhardt@amd.com    # Set env options according to the build directory config.
4157756SAli.Saidi@ARM.com    sticky_opts.files = []
4167756SAli.Saidi@ARM.com    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
4177756SAli.Saidi@ARM.com    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
4187756SAli.Saidi@ARM.com    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
4197756SAli.Saidi@ARM.com    current_opts_file = os.path.join(build_root, 'options', build_dir)
4207756SAli.Saidi@ARM.com    if os.path.isfile(current_opts_file):
4217756SAli.Saidi@ARM.com        sticky_opts.files.append(current_opts_file)
4227756SAli.Saidi@ARM.com        print "Using saved options file %s" % current_opts_file
4237816Ssteve.reinhardt@amd.com    else:
4247816Ssteve.reinhardt@amd.com        # Build dir-specific options file doesn't exist.
4257816Ssteve.reinhardt@amd.com
4267816Ssteve.reinhardt@amd.com        # Make sure the directory is there so we can create it later
4277816Ssteve.reinhardt@amd.com        opt_dir = os.path.dirname(current_opts_file)
4287816Ssteve.reinhardt@amd.com        if not os.path.isdir(opt_dir):
4297816Ssteve.reinhardt@amd.com            os.mkdir(opt_dir)
4307816Ssteve.reinhardt@amd.com
4317816Ssteve.reinhardt@amd.com        # Get default build options from source tree.  Options are
4327816Ssteve.reinhardt@amd.com        # normally determined by name of $BUILD_DIR, but can be
4337756SAli.Saidi@ARM.com        # overriden by 'default=' arg on command line.
4347816Ssteve.reinhardt@amd.com        default_opts_file = os.path.join('build_opts',
4357816Ssteve.reinhardt@amd.com                                         ARGUMENTS.get('default', build_dir))
4367816Ssteve.reinhardt@amd.com        if os.path.isfile(default_opts_file):
4377816Ssteve.reinhardt@amd.com            sticky_opts.files.append(default_opts_file)
4387816Ssteve.reinhardt@amd.com            print "Options file %s not found,\n  using defaults in %s" \
4397816Ssteve.reinhardt@amd.com                  % (current_opts_file, default_opts_file)
4407816Ssteve.reinhardt@amd.com        else:
4417816Ssteve.reinhardt@amd.com            print "Error: cannot find options file %s or %s" \
4427816Ssteve.reinhardt@amd.com                  % (current_opts_file, default_opts_file)
4437816Ssteve.reinhardt@amd.com            Exit(1)
4447816Ssteve.reinhardt@amd.com
4457816Ssteve.reinhardt@amd.com    # Apply current option settings to env
4467816Ssteve.reinhardt@amd.com    sticky_opts.Update(env)
4477816Ssteve.reinhardt@amd.com    nonsticky_opts.Update(env)
4487816Ssteve.reinhardt@amd.com
4497816Ssteve.reinhardt@amd.com    help_text += "Sticky options for %s:\n" % build_dir \
4507816Ssteve.reinhardt@amd.com                 + sticky_opts.GenerateHelpText(env) \
4517816Ssteve.reinhardt@amd.com                 + "\nNon-sticky options for %s:\n" % build_dir \
4527816Ssteve.reinhardt@amd.com                 + nonsticky_opts.GenerateHelpText(env)
4537816Ssteve.reinhardt@amd.com
4547816Ssteve.reinhardt@amd.com    # Process option settings.
4557816Ssteve.reinhardt@amd.com
4567816Ssteve.reinhardt@amd.com    if not have_fenv and env['USE_FENV']:
4577816Ssteve.reinhardt@amd.com        print "Warning: <fenv.h> not available; " \
4587816Ssteve.reinhardt@amd.com              "forcing USE_FENV to False in", build_dir + "."
4597816Ssteve.reinhardt@amd.com        env['USE_FENV'] = False
4607816Ssteve.reinhardt@amd.com
4617816Ssteve.reinhardt@amd.com    if not env['USE_FENV']:
4627816Ssteve.reinhardt@amd.com        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4637816Ssteve.reinhardt@amd.com        print "         FP results may deviate slightly from other platforms."
4647816Ssteve.reinhardt@amd.com
4657816Ssteve.reinhardt@amd.com    if env['EFENCE']:
4667816Ssteve.reinhardt@amd.com        env.Append(LIBS=['efence'])
4677816Ssteve.reinhardt@amd.com
4687816Ssteve.reinhardt@amd.com    if env['USE_MYSQL']:
4697816Ssteve.reinhardt@amd.com        if not have_mysql:
4707816Ssteve.reinhardt@amd.com            print "Warning: MySQL not available; " \
4717816Ssteve.reinhardt@amd.com                  "forcing USE_MYSQL to False in", build_dir + "."
4727816Ssteve.reinhardt@amd.com            env['USE_MYSQL'] = False
4737816Ssteve.reinhardt@amd.com        else:
4747816Ssteve.reinhardt@amd.com            print "Compiling in", build_dir, "with MySQL support."
4757816Ssteve.reinhardt@amd.com            env.ParseConfig(mysql_config_libs)
4767816Ssteve.reinhardt@amd.com            env.ParseConfig(mysql_config_include)
4777816Ssteve.reinhardt@amd.com
4787816Ssteve.reinhardt@amd.com    # Save sticky option settings back to current options file
4797816Ssteve.reinhardt@amd.com    sticky_opts.Save(current_opts_file, env)
4807816Ssteve.reinhardt@amd.com
4817816Ssteve.reinhardt@amd.com    # Do this after we save setting back, or else we'll tack on an
4827816Ssteve.reinhardt@amd.com    # extra 'qdo' every time we run scons.
4837816Ssteve.reinhardt@amd.com    if env['BATCH']:
4847816Ssteve.reinhardt@amd.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4857816Ssteve.reinhardt@amd.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4867816Ssteve.reinhardt@amd.com
4877816Ssteve.reinhardt@amd.com    if env['USE_SSE2']:
4887816Ssteve.reinhardt@amd.com        env.Append(CCFLAGS='-msse2')
4897816Ssteve.reinhardt@amd.com
4907816Ssteve.reinhardt@amd.com    # The src/SConscript file sets up the build rules in 'env' according
4917816Ssteve.reinhardt@amd.com    # to the configured options.  It returns a list of environments,
4927816Ssteve.reinhardt@amd.com    # one for each variant build (debug, opt, etc.)
4937816Ssteve.reinhardt@amd.com    envList = SConscript('src/SConscript', build_dir = build_path,
4947816Ssteve.reinhardt@amd.com                         exports = 'env')
4958947Sandreas.hansson@arm.com
4968947Sandreas.hansson@arm.com    # Set up the regression tests for each build.
4977756SAli.Saidi@ARM.com    for e in envList:
4988120Sgblack@eecs.umich.edu        SConscript('tests/SConscript',
4997756SAli.Saidi@ARM.com                   build_dir = os.path.join(build_path, 'test', e.Label),
5007756SAli.Saidi@ARM.com                   exports = { 'env' : e }, duplicate = False)
5017756SAli.Saidi@ARM.com
5027756SAli.Saidi@ARM.comHelp(help_text)
5037816Ssteve.reinhardt@amd.com
5047816Ssteve.reinhardt@amd.com###################################################
5057816Ssteve.reinhardt@amd.com#
5067816Ssteve.reinhardt@amd.com# Let SCons do its thing.  At this point SCons will use the defined
5077816Ssteve.reinhardt@amd.com# build environments to build the requested targets.
5087816Ssteve.reinhardt@amd.com#
5097816Ssteve.reinhardt@amd.com###################################################
5107816Ssteve.reinhardt@amd.com
5117816Ssteve.reinhardt@amd.com