SConstruct revision 3356
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
11210196SCurtis.Dunham@arm.comabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
113955SN/A                  BUILD_TARGETS)
1145396Ssaidi@eecs.umich.edu
1155863Snate@binkert.org# helper function: find last occurrence of element in list
1165863Snate@binkert.orgdef rfind(l, elt, offs = -1):
1174202Sbinkertn@umich.edu    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"
1215863Snate@binkert.org
122955SN/A# helper function: compare dotted version numbers.
1236654Snate@binkert.org# E.g., compare_version('1.3.25', '1.4.1')
1245273Sstever@gmail.com# returns -1, 0, 1 if v1 is <, ==, > v2
1255871Snate@binkert.orgdef compare_versions(v1, v2):
1265273Sstever@gmail.com    # Convert dotted strings to lists
1276655Snate@binkert.org    v1 = map(int, v1.split('.'))
1288878Ssteve.reinhardt@amd.com    v2 = map(int, v2.split('.'))
1296655Snate@binkert.org    # Compare corresponding elements of lists
1306655Snate@binkert.org    for n1,n2 in zip(v1, v2):
1319219Spower.jg@gmail.com        if n1 < n2: return -1
1326655Snate@binkert.org        if n1 > n2: return  1
1335871Snate@binkert.org    # all corresponding values are equal... see if one has extra values
1346654Snate@binkert.org    if len(v1) < len(v2): return -1
1358947Sandreas.hansson@arm.com    if len(v1) > len(v2): return  1
1365396Ssaidi@eecs.umich.edu    return 0
1378120Sgblack@eecs.umich.edu
1388120Sgblack@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1398120Sgblack@eecs.umich.edu# directory below this will determine the build parameters.  For
1408120Sgblack@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1418120Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1428120Sgblack@eecs.umich.edu# follow 'build' in the bulid path.
1438120Sgblack@eecs.umich.edu
1448120Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the
1458879Ssteve.reinhardt@amd.com# collected targets reference.
1468879Ssteve.reinhardt@amd.combuild_paths = []
1478879Ssteve.reinhardt@amd.combuild_root = None
1488879Ssteve.reinhardt@amd.comfor t in abs_targets:
1498879Ssteve.reinhardt@amd.com    path_dirs = t.split('/')
1508879Ssteve.reinhardt@amd.com    try:
1518879Ssteve.reinhardt@amd.com        build_top = rfind(path_dirs, 'build', -2)
1528879Ssteve.reinhardt@amd.com    except:
1538879Ssteve.reinhardt@amd.com        print "Error: no non-leaf 'build' dir found on target path", t
1548879Ssteve.reinhardt@amd.com        Exit(1)
1558879Ssteve.reinhardt@amd.com    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1568879Ssteve.reinhardt@amd.com    if not build_root:
1578879Ssteve.reinhardt@amd.com        build_root = this_build_root
1588120Sgblack@eecs.umich.edu    else:
1598120Sgblack@eecs.umich.edu        if this_build_root != build_root:
1608120Sgblack@eecs.umich.edu            print "Error: build targets not under same build root\n"\
1618120Sgblack@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
1628120Sgblack@eecs.umich.edu            Exit(1)
1638120Sgblack@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1648120Sgblack@eecs.umich.edu    if build_path not in build_paths:
1658120Sgblack@eecs.umich.edu        build_paths.append(build_path)
1668120Sgblack@eecs.umich.edu
1678120Sgblack@eecs.umich.edu###################################################
1688120Sgblack@eecs.umich.edu#
1698120Sgblack@eecs.umich.edu# Set up the default build environment.  This environment is copied
1708120Sgblack@eecs.umich.edu# and modified according to each selected configuration.
1718120Sgblack@eecs.umich.edu#
1728879Ssteve.reinhardt@amd.com###################################################
1738879Ssteve.reinhardt@amd.com
1748879Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
1758879Ssteve.reinhardt@amd.com                  ROOT = ROOT,
1768879Ssteve.reinhardt@amd.com                  SRCDIR = SRCDIR)
1778879Ssteve.reinhardt@amd.com
1788879Ssteve.reinhardt@amd.comenv.SConsignFile(os.path.join(build_root,"sconsign"))
1798879Ssteve.reinhardt@amd.com
1809227Sandreas.hansson@arm.com# Default duplicate option is to use hard links, but this messes up
1819227Sandreas.hansson@arm.com# when you use emacs to edit a file in the target dir, as emacs moves
1828879Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link.  Symbolic
1838879Ssteve.reinhardt@amd.com# (soft) links work better.
1848879Ssteve.reinhardt@amd.comenv.SetOption('duplicate', 'soft-copy')
1858879Ssteve.reinhardt@amd.com
18610453SAndrew.Bardsley@arm.com# I waffle on this setting... it does avoid a few painful but
18710453SAndrew.Bardsley@arm.com# unnecessary builds, but it also seems to make trivial builds take
18810453SAndrew.Bardsley@arm.com# noticeably longer.
18910456SCurtis.Dunham@arm.comif False:
19010456SCurtis.Dunham@arm.com    env.TargetSignatures('content')
19110456SCurtis.Dunham@arm.com
1928120Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
1938947Sandreas.hansson@arm.comenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1947816Ssteve.reinhardt@amd.com
1955871Snate@binkert.org# Set up default C++ compiler flags
1965871Snate@binkert.orgenv.Append(CCFLAGS='-pipe')
1976121Snate@binkert.orgenv.Append(CCFLAGS='-fno-strict-aliasing')
1985871Snate@binkert.orgenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1995871Snate@binkert.orgif sys.platform == 'cygwin':
2009926Sstan.czerniawski@arm.com    # cygwin has some header file issues...
2019926Sstan.czerniawski@arm.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
2029119Sandreas.hansson@arm.comenv.Append(CPPPATH=[Dir('ext/dnet')])
20310068Sandreas.hansson@arm.com
20410068Sandreas.hansson@arm.com# Check for SWIG
205955SN/Aif not env.has_key('SWIG'):
2069416SAndreas.Sandberg@ARM.com    print 'Error: SWIG utility not found.'
2079416SAndreas.Sandberg@ARM.com    print '       Please install (see http://www.swig.org) and retry.'
2089416SAndreas.Sandberg@ARM.com    Exit(1)
2099416SAndreas.Sandberg@ARM.com
2109416SAndreas.Sandberg@ARM.com# Check for appropriate SWIG version
2119416SAndreas.Sandberg@ARM.comswig_version = os.popen('swig -version').read().split()
2129416SAndreas.Sandberg@ARM.com# First 3 words should be "SWIG Version x.y.z"
2135871Snate@binkert.orgif swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
2145871Snate@binkert.org    print 'Error determining SWIG version.'
2159416SAndreas.Sandberg@ARM.com    Exit(1)
2169416SAndreas.Sandberg@ARM.com
2175871Snate@binkert.orgmin_swig_version = '1.3.28'
218955SN/Aif compare_versions(swig_version[2], min_swig_version) < 0:
2196121Snate@binkert.org    print 'Error: SWIG version', min_swig_version, 'or newer required.'
2208881Smarc.orr@gmail.com    print '       Installed version:', swig_version[2]
2216121Snate@binkert.org    Exit(1)
2226121Snate@binkert.org
2231533SN/A# Set up SWIG flags & scanner
2249239Sandreas.hansson@arm.comenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2259239Sandreas.hansson@arm.com
2269239Sandreas.hansson@arm.comimport SCons.Scanner
2279239Sandreas.hansson@arm.com
2289239Sandreas.hansson@arm.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2299239Sandreas.hansson@arm.com
2309239Sandreas.hansson@arm.comswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2319239Sandreas.hansson@arm.com                                        swig_inc_re)
2329239Sandreas.hansson@arm.com
2339239Sandreas.hansson@arm.comenv.Append(SCANNERS = swig_scanner)
2349239Sandreas.hansson@arm.com
2359239Sandreas.hansson@arm.com# Platform-specific configuration.  Note again that we assume that all
2366655Snate@binkert.org# builds under a given build root run on the same host platform.
2376655Snate@binkert.orgconf = Configure(env,
2386655Snate@binkert.org                 conf_dir = os.path.join(build_root, '.scons_config'),
2396655Snate@binkert.org                 log_file = os.path.join(build_root, 'scons_config.log'))
2405871Snate@binkert.org
2415871Snate@binkert.org# Find Python include and library directories for embedding the
2425863Snate@binkert.org# interpreter.  For consistency, we will use the same Python
2435871Snate@binkert.org# installation used to run scons (and thus this script).  If you want
2448878Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how
2455871Snate@binkert.org# to invoke scons with a different copy of the Python interpreter.
2465871Snate@binkert.org
2475871Snate@binkert.org# Get brief Python version name (e.g., "python2.4") for locating
2485863Snate@binkert.org# include & library files
2496121Snate@binkert.orgpy_version_name = 'python' + sys.version[:3]
2505863Snate@binkert.org
2515871Snate@binkert.org# include path, e.g. /usr/local/include/python2.4
2528336Ssteve.reinhardt@amd.compy_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name)
2538336Ssteve.reinhardt@amd.comenv.Append(CPPPATH = py_header_path)
2548336Ssteve.reinhardt@amd.com# verify that it works
2558336Ssteve.reinhardt@amd.comif not conf.CheckHeader('Python.h', '<>'):
2564678Snate@binkert.org    print "Error: can't find Python.h header in", py_header_path
2578336Ssteve.reinhardt@amd.com    Exit(1)
2588336Ssteve.reinhardt@amd.com
2598336Ssteve.reinhardt@amd.com# add library path too if it's not in the default place
2604678Snate@binkert.orgpy_lib_path = None
2614678Snate@binkert.orgif sys.exec_prefix != '/usr':
2624678Snate@binkert.org    py_lib_path = os.path.join(sys.exec_prefix, 'lib')
2634678Snate@binkert.orgelif sys.platform == 'cygwin':
2647827Snate@binkert.org    # cygwin puts the .dll in /bin for some reason
2657827Snate@binkert.org    py_lib_path = '/bin'
2668336Ssteve.reinhardt@amd.comif py_lib_path:
2674678Snate@binkert.org    env.Append(LIBPATH = py_lib_path)
2688336Ssteve.reinhardt@amd.com    print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
2698336Ssteve.reinhardt@amd.comif not conf.CheckLib(py_version_name):
2708336Ssteve.reinhardt@amd.com    print "Error: can't find Python library", py_version_name
2718336Ssteve.reinhardt@amd.com    Exit(1)
2728336Ssteve.reinhardt@amd.com
2738336Ssteve.reinhardt@amd.com# Check for zlib.  If the check passes, libz will be automatically
2745871Snate@binkert.org# added to the LIBS environment variable.
2755871Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'):
2768336Ssteve.reinhardt@amd.com    print 'Error: did not find needed zlib compression library '\
2778336Ssteve.reinhardt@amd.com          'and/or zlib.h header file.'
2788336Ssteve.reinhardt@amd.com    print '       Please install zlib and try again.'
2798336Ssteve.reinhardt@amd.com    Exit(1)
2808336Ssteve.reinhardt@amd.com
2815871Snate@binkert.org# Check for <fenv.h> (C99 FP environment control)
2828336Ssteve.reinhardt@amd.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
2838336Ssteve.reinhardt@amd.comif not have_fenv:
2848336Ssteve.reinhardt@amd.com    print "Warning: Header file <fenv.h> not found."
2858336Ssteve.reinhardt@amd.com    print "         This host has no IEEE FP rounding mode control."
2868336Ssteve.reinhardt@amd.com
2874678Snate@binkert.org# Check for mysql.
2885871Snate@binkert.orgmysql_config = WhereIs('mysql_config')
2894678Snate@binkert.orghave_mysql = mysql_config != None
2908336Ssteve.reinhardt@amd.com
2918336Ssteve.reinhardt@amd.com# Check MySQL version.
2928336Ssteve.reinhardt@amd.comif have_mysql:
2938336Ssteve.reinhardt@amd.com    mysql_version = os.popen(mysql_config + ' --version').read()
2948336Ssteve.reinhardt@amd.com    min_mysql_version = '4.1'
2958336Ssteve.reinhardt@amd.com    if compare_versions(mysql_version, min_mysql_version) < 0:
2968336Ssteve.reinhardt@amd.com        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
2978336Ssteve.reinhardt@amd.com        print '         Version', mysql_version, 'detected.'
2988336Ssteve.reinhardt@amd.com        have_mysql = False
2998336Ssteve.reinhardt@amd.com
3008336Ssteve.reinhardt@amd.com# Set up mysql_config commands.
3018336Ssteve.reinhardt@amd.comif have_mysql:
3028336Ssteve.reinhardt@amd.com    mysql_config_include = mysql_config + ' --include'
3038336Ssteve.reinhardt@amd.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
3048336Ssteve.reinhardt@amd.com        # older mysql_config versions don't support --include, use
3058336Ssteve.reinhardt@amd.com        # --cflags instead
3068336Ssteve.reinhardt@amd.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
3075871Snate@binkert.org    # This seems to work in all versions
3086121Snate@binkert.org    mysql_config_libs = mysql_config + ' --libs'
309955SN/A
310955SN/Aenv = conf.Finish()
3112632Sstever@eecs.umich.edu
3122632Sstever@eecs.umich.edu# Define the universe of supported ISAs
313955SN/Aenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
314955SN/A
315955SN/A# Define the universe of supported CPU models
316955SN/Aenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
3178878Ssteve.reinhardt@amd.com                       'FullCPU', 'O3CPU',
318955SN/A                       'OzoneCPU']
3192632Sstever@eecs.umich.edu
3202632Sstever@eecs.umich.edu# Sticky options get saved in the options file so they persist from
3212632Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
3222632Sstever@eecs.umich.edu# value becomes sticky).
3232632Sstever@eecs.umich.edusticky_opts = Options(args=ARGUMENTS)
3242632Sstever@eecs.umich.edusticky_opts.AddOptions(
3252632Sstever@eecs.umich.edu    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
3268268Ssteve.reinhardt@amd.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
3278268Ssteve.reinhardt@amd.com    # There's a bug in scons 0.96.1 that causes ListOptions with list
3288268Ssteve.reinhardt@amd.com    # values (more than one value) not to be able to be restored from
3298268Ssteve.reinhardt@amd.com    # a saved option file.  If this causes trouble then upgrade to
3308268Ssteve.reinhardt@amd.com    # scons 0.96.90 or later.
3318268Ssteve.reinhardt@amd.com    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
3328268Ssteve.reinhardt@amd.com               env['ALL_CPU_LIST']),
3332632Sstever@eecs.umich.edu    BoolOption('ALPHA_TLASER',
3342632Sstever@eecs.umich.edu               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
3352632Sstever@eecs.umich.edu    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
3362632Sstever@eecs.umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
3378268Ssteve.reinhardt@amd.com               False),
3382632Sstever@eecs.umich.edu    BoolOption('SS_COMPATIBLE_FP',
3398268Ssteve.reinhardt@amd.com               'Make floating-point results compatible with SimpleScalar',
3408268Ssteve.reinhardt@amd.com               False),
3418268Ssteve.reinhardt@amd.com    BoolOption('USE_SSE2',
3428268Ssteve.reinhardt@amd.com               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
3433718Sstever@eecs.umich.edu               False),
3442634Sstever@eecs.umich.edu    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
3452634Sstever@eecs.umich.edu    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
3465863Snate@binkert.org    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
3472638Sstever@eecs.umich.edu    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
3488268Ssteve.reinhardt@amd.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
3492632Sstever@eecs.umich.edu    BoolOption('BATCH', 'Use batch pool for build and tests', False),
3502632Sstever@eecs.umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3512632Sstever@eecs.umich.edu    ('PYTHONHOME',
3522632Sstever@eecs.umich.edu     'Override the default PYTHONHOME for this system (use with caution)',
3532632Sstever@eecs.umich.edu     '%s:%s' % (sys.prefix, sys.exec_prefix))
3541858SN/A    )
3553716Sstever@eecs.umich.edu
3562638Sstever@eecs.umich.edu# Non-sticky options only apply to the current build.
3572638Sstever@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS)
3582638Sstever@eecs.umich.edunonsticky_opts.AddOptions(
3592638Sstever@eecs.umich.edu    BoolOption('update_ref', 'Update test reference outputs', False)
3602638Sstever@eecs.umich.edu    )
3612638Sstever@eecs.umich.edu
3622638Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript).
3635863Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3645863Snate@binkert.org                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3655863Snate@binkert.org                     'USE_CHECKER', 'PYTHONHOME']
366955SN/A
3675341Sstever@gmail.com# Define a handy 'no-op' action
3685341Sstever@gmail.comdef no_action(target, source, env):
3695863Snate@binkert.org    return 0
3707756SAli.Saidi@ARM.com
3715341Sstever@gmail.comenv.NoAction = Action(no_action, None)
3726121Snate@binkert.org
3734494Ssaidi@eecs.umich.edu###################################################
3746121Snate@binkert.org#
3751105SN/A# Define a SCons builder for configuration flag headers.
3762667Sstever@eecs.umich.edu#
3772667Sstever@eecs.umich.edu###################################################
3782667Sstever@eecs.umich.edu
3792667Sstever@eecs.umich.edu# This function generates a config header file that #defines the
3806121Snate@binkert.org# option symbol to the current option setting (0 or 1).  The source
3812667Sstever@eecs.umich.edu# operands are the name of the option and a Value node containing the
3825341Sstever@gmail.com# value of the option.
3835863Snate@binkert.orgdef build_config_file(target, source, env):
3845341Sstever@gmail.com    (option, value) = [s.get_contents() for s in source]
3855341Sstever@gmail.com    f = file(str(target[0]), 'w')
3865341Sstever@gmail.com    print >> f, '#define', option, value
3878120Sgblack@eecs.umich.edu    f.close()
3885341Sstever@gmail.com    return None
3898120Sgblack@eecs.umich.edu
3905341Sstever@gmail.com# Generate the message to be printed when building the config file.
3918120Sgblack@eecs.umich.edudef build_config_file_string(target, source, env):
3926121Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
3936121Snate@binkert.org    return "Defining %s as %s in %s." % (option, value, target[0])
3948980Ssteve.reinhardt@amd.com
3959396Sandreas.hansson@arm.com# Combine the two functions into a scons Action object.
3965397Ssaidi@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string)
3975397Ssaidi@eecs.umich.edu
3987727SAli.Saidi@ARM.com# The emitter munges the source & target node lists to reflect what
3998268Ssteve.reinhardt@amd.com# we're really doing.
4006168Snate@binkert.orgdef config_emitter(target, source, env):
4015341Sstever@gmail.com    # extract option name from Builder arg
4028120Sgblack@eecs.umich.edu    option = str(target[0])
4038120Sgblack@eecs.umich.edu    # True target is config header file
4048120Sgblack@eecs.umich.edu    target = os.path.join('config', option.lower() + '.hh')
4056814Sgblack@eecs.umich.edu    val = env[option]
4065863Snate@binkert.org    if isinstance(val, bool):
4078120Sgblack@eecs.umich.edu        # Force value to 0/1
4085341Sstever@gmail.com        val = int(val)
4095863Snate@binkert.org    elif isinstance(val, str):
4108268Ssteve.reinhardt@amd.com        val = '"' + val + '"'
4116121Snate@binkert.org        
4126121Snate@binkert.org    # Sources are option name & value (packaged in SCons Value nodes)
4138268Ssteve.reinhardt@amd.com    return ([target], [Value(option), Value(val)])
4145742Snate@binkert.org
4155742Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action)
4165341Sstever@gmail.com
4175742Snate@binkert.orgenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
4185742Snate@binkert.org
4195341Sstever@gmail.com###################################################
4206017Snate@binkert.org#
4216121Snate@binkert.org# Define a SCons builder for copying files.  This is used by the
4226017Snate@binkert.org# Python zipfile code in src/python/SConscript, but is placed up here
4237816Ssteve.reinhardt@amd.com# since it's potentially more generally applicable.
4247756SAli.Saidi@ARM.com#
4257756SAli.Saidi@ARM.com###################################################
4267756SAli.Saidi@ARM.com
4277756SAli.Saidi@ARM.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
4287756SAli.Saidi@ARM.com
4297756SAli.Saidi@ARM.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
4307756SAli.Saidi@ARM.com
4317756SAli.Saidi@ARM.com###################################################
4327816Ssteve.reinhardt@amd.com#
4337816Ssteve.reinhardt@amd.com# Define a simple SCons builder to concatenate files.
4347816Ssteve.reinhardt@amd.com#
4357816Ssteve.reinhardt@amd.com# Used to append the Python zip archive to the executable.
4367816Ssteve.reinhardt@amd.com#
4377816Ssteve.reinhardt@amd.com###################################################
4387816Ssteve.reinhardt@amd.com
4397816Ssteve.reinhardt@amd.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
4407816Ssteve.reinhardt@amd.com                                          'chmod +x $TARGET']))
4417816Ssteve.reinhardt@amd.com
4427756SAli.Saidi@ARM.comenv.Append(BUILDERS = { 'Concat' : concat_builder })
4437816Ssteve.reinhardt@amd.com
4447816Ssteve.reinhardt@amd.com
4457816Ssteve.reinhardt@amd.com# base help text
4467816Ssteve.reinhardt@amd.comhelp_text = '''
4477816Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)]
4487816Ssteve.reinhardt@amd.com
4497816Ssteve.reinhardt@amd.com'''
4507816Ssteve.reinhardt@amd.com
4517816Ssteve.reinhardt@amd.com# libelf build is shared across all configs in the build root.
4527816Ssteve.reinhardt@amd.comenv.SConscript('ext/libelf/SConscript',
4537816Ssteve.reinhardt@amd.com               build_dir = os.path.join(build_root, 'libelf'),
4547816Ssteve.reinhardt@amd.com               exports = 'env')
4557816Ssteve.reinhardt@amd.com
4567816Ssteve.reinhardt@amd.com###################################################
4577816Ssteve.reinhardt@amd.com#
4587816Ssteve.reinhardt@amd.com# Define build environments for selected configurations.
4597816Ssteve.reinhardt@amd.com#
4607816Ssteve.reinhardt@amd.com###################################################
4617816Ssteve.reinhardt@amd.com
4627816Ssteve.reinhardt@amd.com# rename base env
4637816Ssteve.reinhardt@amd.combase_env = env
4647816Ssteve.reinhardt@amd.com
4657816Ssteve.reinhardt@amd.comfor build_path in build_paths:
4667816Ssteve.reinhardt@amd.com    print "Building in", build_path
4677816Ssteve.reinhardt@amd.com    # build_dir is the tail component of build path, and is used to
4687816Ssteve.reinhardt@amd.com    # determine the build parameters (e.g., 'ALPHA_SE')
4697816Ssteve.reinhardt@amd.com    (build_root, build_dir) = os.path.split(build_path)
4707816Ssteve.reinhardt@amd.com    # Make a copy of the build-root environment to use for this config.
4717816Ssteve.reinhardt@amd.com    env = base_env.Copy()
4727816Ssteve.reinhardt@amd.com
4737816Ssteve.reinhardt@amd.com    # Set env options according to the build directory config.
4747816Ssteve.reinhardt@amd.com    sticky_opts.files = []
4757816Ssteve.reinhardt@amd.com    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
4767816Ssteve.reinhardt@amd.com    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
4777816Ssteve.reinhardt@amd.com    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
4787816Ssteve.reinhardt@amd.com    current_opts_file = os.path.join(build_root, 'options', build_dir)
4797816Ssteve.reinhardt@amd.com    if os.path.isfile(current_opts_file):
4807816Ssteve.reinhardt@amd.com        sticky_opts.files.append(current_opts_file)
4817816Ssteve.reinhardt@amd.com        print "Using saved options file %s" % current_opts_file
4827816Ssteve.reinhardt@amd.com    else:
4837816Ssteve.reinhardt@amd.com        # Build dir-specific options file doesn't exist.
4847816Ssteve.reinhardt@amd.com
4857816Ssteve.reinhardt@amd.com        # Make sure the directory is there so we can create it later
4867816Ssteve.reinhardt@amd.com        opt_dir = os.path.dirname(current_opts_file)
4877816Ssteve.reinhardt@amd.com        if not os.path.isdir(opt_dir):
4887816Ssteve.reinhardt@amd.com            os.mkdir(opt_dir)
4897816Ssteve.reinhardt@amd.com
4907816Ssteve.reinhardt@amd.com        # Get default build options from source tree.  Options are
4917816Ssteve.reinhardt@amd.com        # normally determined by name of $BUILD_DIR, but can be
4927816Ssteve.reinhardt@amd.com        # overriden by 'default=' arg on command line.
4937816Ssteve.reinhardt@amd.com        default_opts_file = os.path.join('build_opts',
4947816Ssteve.reinhardt@amd.com                                         ARGUMENTS.get('default', build_dir))
4957816Ssteve.reinhardt@amd.com        if os.path.isfile(default_opts_file):
4967816Ssteve.reinhardt@amd.com            sticky_opts.files.append(default_opts_file)
4977816Ssteve.reinhardt@amd.com            print "Options file %s not found,\n  using defaults in %s" \
4987816Ssteve.reinhardt@amd.com                  % (current_opts_file, default_opts_file)
4997816Ssteve.reinhardt@amd.com        else:
5007816Ssteve.reinhardt@amd.com            print "Error: cannot find options file %s or %s" \
5017816Ssteve.reinhardt@amd.com                  % (current_opts_file, default_opts_file)
5027816Ssteve.reinhardt@amd.com            Exit(1)
5037816Ssteve.reinhardt@amd.com
5048947Sandreas.hansson@arm.com    # Apply current option settings to env
5058947Sandreas.hansson@arm.com    sticky_opts.Update(env)
5067756SAli.Saidi@ARM.com    nonsticky_opts.Update(env)
5078120Sgblack@eecs.umich.edu
5087756SAli.Saidi@ARM.com    help_text += "Sticky options for %s:\n" % build_dir \
5097756SAli.Saidi@ARM.com                 + sticky_opts.GenerateHelpText(env) \
5107756SAli.Saidi@ARM.com                 + "\nNon-sticky options for %s:\n" % build_dir \
5117756SAli.Saidi@ARM.com                 + nonsticky_opts.GenerateHelpText(env)
5127816Ssteve.reinhardt@amd.com
5137816Ssteve.reinhardt@amd.com    # Process option settings.
5147816Ssteve.reinhardt@amd.com
5157816Ssteve.reinhardt@amd.com    if not have_fenv and env['USE_FENV']:
5167816Ssteve.reinhardt@amd.com        print "Warning: <fenv.h> not available; " \
5177816Ssteve.reinhardt@amd.com              "forcing USE_FENV to False in", build_dir + "."
5187816Ssteve.reinhardt@amd.com        env['USE_FENV'] = False
5197816Ssteve.reinhardt@amd.com
5207816Ssteve.reinhardt@amd.com    if not env['USE_FENV']:
5217816Ssteve.reinhardt@amd.com        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
5227756SAli.Saidi@ARM.com        print "         FP results may deviate slightly from other platforms."
5237756SAli.Saidi@ARM.com
5249227Sandreas.hansson@arm.com    if env['EFENCE']:
5259227Sandreas.hansson@arm.com        env.Append(LIBS=['efence'])
5269227Sandreas.hansson@arm.com
5279227Sandreas.hansson@arm.com    if env['USE_MYSQL']:
5289590Sandreas@sandberg.pp.se        if not have_mysql:
5299590Sandreas@sandberg.pp.se            print "Warning: MySQL not available; " \
5309590Sandreas@sandberg.pp.se                  "forcing USE_MYSQL to False in", build_dir + "."
5319590Sandreas@sandberg.pp.se            env['USE_MYSQL'] = False
5329590Sandreas@sandberg.pp.se        else:
5339590Sandreas@sandberg.pp.se            print "Compiling in", build_dir, "with MySQL support."
5346654Snate@binkert.org            env.ParseConfig(mysql_config_libs)
5356654Snate@binkert.org            env.ParseConfig(mysql_config_include)
5365871Snate@binkert.org
5376121Snate@binkert.org    # Save sticky option settings back to current options file
5388946Sandreas.hansson@arm.com    sticky_opts.Save(current_opts_file, env)
5399419Sandreas.hansson@arm.com
5403940Ssaidi@eecs.umich.edu    # Do this after we save setting back, or else we'll tack on an
5413918Ssaidi@eecs.umich.edu    # extra 'qdo' every time we run scons.
5423918Ssaidi@eecs.umich.edu    if env['BATCH']:
5431858SN/A        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
5449556Sandreas.hansson@arm.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
5459556Sandreas.hansson@arm.com
5469556Sandreas.hansson@arm.com    if env['USE_SSE2']:
5479556Sandreas.hansson@arm.com        env.Append(CCFLAGS='-msse2')
5489556Sandreas.hansson@arm.com
5499556Sandreas.hansson@arm.com    # The src/SConscript file sets up the build rules in 'env' according
5509556Sandreas.hansson@arm.com    # to the configured options.  It returns a list of environments,
5519556Sandreas.hansson@arm.com    # one for each variant build (debug, opt, etc.)
5529556Sandreas.hansson@arm.com    envList = SConscript('src/SConscript', build_dir = build_path,
5539556Sandreas.hansson@arm.com                         exports = 'env')
5549556Sandreas.hansson@arm.com
5559556Sandreas.hansson@arm.com    # Set up the regression tests for each build.
5569556Sandreas.hansson@arm.com    for e in envList:
5579556Sandreas.hansson@arm.com        SConscript('tests/SConscript',
5589556Sandreas.hansson@arm.com                   build_dir = os.path.join(build_path, 'tests', e.Label),
5599556Sandreas.hansson@arm.com                   exports = { 'env' : e }, duplicate = False)
5609556Sandreas.hansson@arm.com
5619556Sandreas.hansson@arm.comHelp(help_text)
5629556Sandreas.hansson@arm.com
5639556Sandreas.hansson@arm.com###################################################
5649556Sandreas.hansson@arm.com#
5659556Sandreas.hansson@arm.com# Let SCons do its thing.  At this point SCons will use the defined
5669556Sandreas.hansson@arm.com# build environments to build the requested targets.
5679556Sandreas.hansson@arm.com#
5689556Sandreas.hansson@arm.com###################################################
5699556Sandreas.hansson@arm.com
5709556Sandreas.hansson@arm.com