SConstruct revision 9068:d421f95f92d9
17405SAli.Saidi@ARM.com# -*- mode:python -*-
211573SDylan.Johnson@ARM.com
37405SAli.Saidi@ARM.com# Copyright (c) 2011 Advanced Micro Devices, Inc.
47405SAli.Saidi@ARM.com# Copyright (c) 2009 The Hewlett-Packard Development Company
57405SAli.Saidi@ARM.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
67405SAli.Saidi@ARM.com# All rights reserved.
77405SAli.Saidi@ARM.com#
87405SAli.Saidi@ARM.com# Redistribution and use in source and binary forms, with or without
97405SAli.Saidi@ARM.com# modification, are permitted provided that the following conditions are
107405SAli.Saidi@ARM.com# met: redistributions of source code must retain the above copyright
117405SAli.Saidi@ARM.com# notice, this list of conditions and the following disclaimer;
127405SAli.Saidi@ARM.com# redistributions in binary form must reproduce the above copyright
137405SAli.Saidi@ARM.com# notice, this list of conditions and the following disclaimer in the
147405SAli.Saidi@ARM.com# documentation and/or other materials provided with the distribution;
157405SAli.Saidi@ARM.com# neither the name of the copyright holders nor the names of its
167405SAli.Saidi@ARM.com# contributors may be used to endorse or promote products derived from
177405SAli.Saidi@ARM.com# this software without specific prior written permission.
187405SAli.Saidi@ARM.com#
197405SAli.Saidi@ARM.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
207405SAli.Saidi@ARM.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
217405SAli.Saidi@ARM.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
227405SAli.Saidi@ARM.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
237405SAli.Saidi@ARM.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
247405SAli.Saidi@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
257405SAli.Saidi@ARM.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
267405SAli.Saidi@ARM.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
277405SAli.Saidi@ARM.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
287405SAli.Saidi@ARM.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
297405SAli.Saidi@ARM.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
307405SAli.Saidi@ARM.com#
317405SAli.Saidi@ARM.com# Authors: Steve Reinhardt
327405SAli.Saidi@ARM.com#          Nathan Binkert
337405SAli.Saidi@ARM.com
347405SAli.Saidi@ARM.com###################################################
357405SAli.Saidi@ARM.com#
367405SAli.Saidi@ARM.com# SCons top-level build description (SConstruct) file.
377405SAli.Saidi@ARM.com#
387405SAli.Saidi@ARM.com# While in this directory ('gem5'), just type 'scons' to build the default
397405SAli.Saidi@ARM.com# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
407405SAli.Saidi@ARM.com# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for
417405SAli.Saidi@ARM.com# the optimized full-system version).
4210461SAndreas.Sandberg@ARM.com#
439050Schander.sudanthi@arm.com# You can build gem5 in a different directory as long as there is a
4412406Sgabeblack@google.com# 'build/<CONFIG>' somewhere along the target path.  The build system
4511793Sbrandon.potter@amd.com# expects that all configs under the same build directory are being
468887Sgeoffrey.blake@arm.com# built for the same host system.
478232Snate@binkert.org#
488232Snate@binkert.org# Examples:
4910844Sandreas.sandberg@arm.com#
509384SAndreas.Sandberg@arm.com#   The following two commands are equivalent.  The '-u' option tells
517678Sgblack@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
528059SAli.Saidi@ARM.com#   % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug
538284SAli.Saidi@ARM.com#   % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug
547405SAli.Saidi@ARM.com#
557405SAli.Saidi@ARM.com#   The following two commands are equivalent and demonstrate building
567405SAli.Saidi@ARM.com#   in a directory outside of the source tree.  The '-C' option tells
577405SAli.Saidi@ARM.com#   scons to chdir to the specified directory to find this SConstruct
589384SAndreas.Sandberg@arm.com#   file.
5910461SAndreas.Sandberg@ARM.com#   % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug
6010461SAndreas.Sandberg@ARM.com#   % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug
6111165SRekai.GonzalezAlberquilla@arm.com#
6212109SRekai.GonzalezAlberquilla@arm.com# You can use 'scons -H' to print scons options.  If you're in this
6312479SCurtis.Dunham@arm.com# 'gem5' directory (or use -u or -C to tell scons where to find this
649384SAndreas.Sandberg@arm.com# file), you can use 'scons -h' to print all the gem5-specific build
6511770SCurtis.Dunham@arm.com# options as well.
6610037SARM gem5 Developers#
6710461SAndreas.Sandberg@ARM.com###################################################
6810461SAndreas.Sandberg@ARM.com
6910461SAndreas.Sandberg@ARM.com# Check for recent-enough Python and SCons versions.
7010461SAndreas.Sandberg@ARM.comtry:
7110461SAndreas.Sandberg@ARM.com    # Really old versions of scons only take two options for the
7210461SAndreas.Sandberg@ARM.com    # function, so check once without the revision and once with the
7310609Sandreas.sandberg@arm.com    # revision, the first instance will fail for stuff other than
7410609Sandreas.sandberg@arm.com    # 0.98, and the second will fail for 0.98.0
7510609Sandreas.sandberg@arm.com    EnsureSConsVersion(0, 98)
7610037SARM gem5 Developers    EnsureSConsVersion(0, 98, 1)
7710037SARM gem5 Developersexcept SystemExit, e:
7810037SARM gem5 Developers    print """
7910037SARM gem5 DevelopersFor more details, see:
8011771SCurtis.Dunham@arm.com    http://gem5.org/Dependencies
8110037SARM gem5 Developers"""
8210037SARM gem5 Developers    raise
8310037SARM gem5 Developers
8410037SARM gem5 Developers# We ensure the python version early because we have stuff that
8510037SARM gem5 Developers# requires python 2.4
8610037SARM gem5 Developerstry:
8711771SCurtis.Dunham@arm.com    EnsurePythonVersion(2, 4)
8810037SARM gem5 Developersexcept SystemExit, e:
8910037SARM gem5 Developers    print """
9010037SARM gem5 DevelopersYou can use a non-default installation of the Python interpreter by
9110037SARM gem5 Developerseither (1) rearranging your PATH so that scons finds the non-default
9210037SARM gem5 Developers'python' first or (2) explicitly invoking an alternative interpreter
9312477SCurtis.Dunham@arm.comon the scons script.
9410037SARM gem5 Developers
9510037SARM gem5 DevelopersFor more details, see:
969384SAndreas.Sandberg@arm.com    http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation
979384SAndreas.Sandberg@arm.com"""
989384SAndreas.Sandberg@arm.com    raise
9912479SCurtis.Dunham@arm.com
10012479SCurtis.Dunham@arm.com# Global Python includes
1019384SAndreas.Sandberg@arm.comimport os
1029384SAndreas.Sandberg@arm.comimport re
1039384SAndreas.Sandberg@arm.comimport subprocess
1049384SAndreas.Sandberg@arm.comimport sys
1059384SAndreas.Sandberg@arm.com
1069384SAndreas.Sandberg@arm.comfrom os import mkdir, environ
1077427Sgblack@eecs.umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath
1087427Sgblack@eecs.umich.edufrom os.path import exists,  isdir, isfile
1097427Sgblack@eecs.umich.edufrom os.path import join as joinpath, split as splitpath
1109385SAndreas.Sandberg@arm.com
1119385SAndreas.Sandberg@arm.com# SCons includes
1127427Sgblack@eecs.umich.eduimport SCons
1137427Sgblack@eecs.umich.eduimport SCons.Node
11410037SARM gem5 Developers
11510037SARM gem5 Developersextra_python_paths = [
11610037SARM gem5 Developers    Dir('src/python').srcnode().abspath, # gem5 includes
11710037SARM gem5 Developers    Dir('ext/ply').srcnode().abspath, # ply is used by several files
11810037SARM gem5 Developers    ]
11910037SARM gem5 Developers    
12010037SARM gem5 Developerssys.path[1:1] = extra_python_paths
12110037SARM gem5 Developers
12210037SARM gem5 Developersfrom m5.util import compareVersions, readCommand
12310037SARM gem5 Developersfrom m5.util.terminal import get_termcap
12410037SARM gem5 Developers
12510037SARM gem5 Developershelp_texts = {
12610037SARM gem5 Developers    "options" : "",
12710037SARM gem5 Developers    "global_vars" : "",
1287427Sgblack@eecs.umich.edu    "local_vars" : ""
1297427Sgblack@eecs.umich.edu}
1307427Sgblack@eecs.umich.edu
1317427Sgblack@eecs.umich.eduExport("help_texts")
1327427Sgblack@eecs.umich.edu
1337427Sgblack@eecs.umich.edu
13410037SARM gem5 Developers# There's a bug in scons in that (1) by default, the help texts from
13510037SARM gem5 Developers# AddOption() are supposed to be displayed when you type 'scons -h'
13610037SARM gem5 Developers# and (2) you can override the help displayed by 'scons -h' using the
13710037SARM gem5 Developers# Help() function, but these two features are incompatible: once
1387427Sgblack@eecs.umich.edu# you've overridden the help text using Help(), there's no way to get
1397427Sgblack@eecs.umich.edu# at the help texts from AddOptions.  See:
1407427Sgblack@eecs.umich.edu#     http://scons.tigris.org/issues/show_bug.cgi?id=2356
14110037SARM gem5 Developers#     http://scons.tigris.org/issues/show_bug.cgi?id=2611
14210204SAli.Saidi@ARM.com# This hack lets us extract the help text from AddOptions and
14310204SAli.Saidi@ARM.com# re-inject it via Help().  Ideally someday this bug will be fixed and
14410037SARM gem5 Developers# we can just use AddOption directly.
1457427Sgblack@eecs.umich.edudef AddLocalOption(*args, **kwargs):
14610037SARM gem5 Developers    col_width = 30
1477427Sgblack@eecs.umich.edu
14810037SARM gem5 Developers    help = "  " + ", ".join(args)
1497427Sgblack@eecs.umich.edu    if "help" in kwargs:
1507427Sgblack@eecs.umich.edu        length = len(help)
15110037SARM gem5 Developers        if length >= col_width:
1527427Sgblack@eecs.umich.edu            help += "\n" + " " * col_width
1537427Sgblack@eecs.umich.edu        else:
1547427Sgblack@eecs.umich.edu            help += " " * (col_width - length)
1557427Sgblack@eecs.umich.edu        help += kwargs["help"]
1567427Sgblack@eecs.umich.edu    help_texts["options"] += help + "\n"
1577427Sgblack@eecs.umich.edu
1587427Sgblack@eecs.umich.edu    AddOption(*args, **kwargs)
1597427Sgblack@eecs.umich.edu
1607427Sgblack@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true',
1617427Sgblack@eecs.umich.edu               help="Add color to abbreviated scons output")
1627427Sgblack@eecs.umich.eduAddLocalOption('--no-colors', dest='use_colors', action='store_false',
1637427Sgblack@eecs.umich.edu               help="Don't add color to abbreviated scons output")
1647427Sgblack@eecs.umich.eduAddLocalOption('--default', dest='default', type='string', action='store',
1657427Sgblack@eecs.umich.edu               help='Override which build_opts file to use for defaults')
1667427Sgblack@eecs.umich.eduAddLocalOption('--ignore-style', dest='ignore_style', action='store_true',
1677427Sgblack@eecs.umich.edu               help='Disable style checking hooks')
1687427Sgblack@eecs.umich.eduAddLocalOption('--update-ref', dest='update_ref', action='store_true',
1697427Sgblack@eecs.umich.edu               help='Update test reference outputs')
1707427Sgblack@eecs.umich.eduAddLocalOption('--verbose', dest='verbose', action='store_true',
1717427Sgblack@eecs.umich.edu               help='Print full tool command lines')
1727427Sgblack@eecs.umich.edu
1737427Sgblack@eecs.umich.edutermcap = get_termcap(GetOption('use_colors'))
1747427Sgblack@eecs.umich.edu
1757436Sdam.sunwoo@arm.com########################################################################
1767436Sdam.sunwoo@arm.com#
17710037SARM gem5 Developers# Set up the main build environment.
17810037SARM gem5 Developers#
1797436Sdam.sunwoo@arm.com########################################################################
1807436Sdam.sunwoo@arm.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
1817436Sdam.sunwoo@arm.com                 'PYTHONPATH', 'RANLIB', 'SWIG' ])
1827436Sdam.sunwoo@arm.com
1837436Sdam.sunwoo@arm.comuse_env = {}
1847436Sdam.sunwoo@arm.comfor key,val in os.environ.iteritems():
1857436Sdam.sunwoo@arm.com    if key in use_vars or key.startswith("M5"):
1867436Sdam.sunwoo@arm.com        use_env[key] = val
1877436Sdam.sunwoo@arm.com
1887436Sdam.sunwoo@arm.commain = Environment(ENV=use_env)
1897436Sdam.sunwoo@arm.commain.Decider('MD5-timestamp')
1907436Sdam.sunwoo@arm.commain.root = Dir(".")         # The current directory (where this file lives).
19110037SARM gem5 Developersmain.srcdir = Dir("src")     # The source directory
1927436Sdam.sunwoo@arm.com
1937436Sdam.sunwoo@arm.com# add useful python code PYTHONPATH so it can be used by subprocesses
1947436Sdam.sunwoo@arm.com# as well
1957436Sdam.sunwoo@arm.commain.AppendENVPath('PYTHONPATH', extra_python_paths)
1967436Sdam.sunwoo@arm.com
1977436Sdam.sunwoo@arm.com########################################################################
1987436Sdam.sunwoo@arm.com#
1997436Sdam.sunwoo@arm.com# Mercurial Stuff.
2007436Sdam.sunwoo@arm.com#
2017436Sdam.sunwoo@arm.com# If the gem5 directory is a mercurial repository, we should do some
2027436Sdam.sunwoo@arm.com# extra things.
2037436Sdam.sunwoo@arm.com#
2047436Sdam.sunwoo@arm.com########################################################################
2057436Sdam.sunwoo@arm.com
2067436Sdam.sunwoo@arm.comhgdir = main.root.Dir(".hg")
2077436Sdam.sunwoo@arm.com
2087644Sali.saidi@arm.commercurial_style_message = """
2098147SAli.Saidi@ARM.comYou're missing the gem5 style hook, which automatically checks your code
2109385SAndreas.Sandberg@arm.comagainst the gem5 style rules on hg commit and qrefresh commands.  This
2119385SAndreas.Sandberg@arm.comscript will now install the hook in your .hg/hgrc file.
2129385SAndreas.Sandberg@arm.comPress enter to continue, or ctrl-c to abort: """
2139385SAndreas.Sandberg@arm.com
2149385SAndreas.Sandberg@arm.commercurial_style_hook = """
2159385SAndreas.Sandberg@arm.com# The following lines were automatically added by gem5/SConstruct
2169385SAndreas.Sandberg@arm.com# to provide the gem5 style-checking hooks
2179385SAndreas.Sandberg@arm.com[extensions]
2189385SAndreas.Sandberg@arm.comstyle = %s/util/style.py
2199385SAndreas.Sandberg@arm.com
2209385SAndreas.Sandberg@arm.com[hooks]
2219385SAndreas.Sandberg@arm.compretxncommit.style = python:style.check_style
2229385SAndreas.Sandberg@arm.compre-qrefresh.style = python:style.check_style
2239385SAndreas.Sandberg@arm.com# End of SConstruct additions
22410037SARM gem5 Developers
22510037SARM gem5 Developers""" % (main.root.abspath)
22610037SARM gem5 Developers
22710037SARM gem5 Developersmercurial_lib_not_found = """
22810037SARM gem5 DevelopersMercurial libraries cannot be found, ignoring style hook.  If
22910037SARM gem5 Developersyou are a gem5 developer, please fix this and run the style
23010037SARM gem5 Developershook. It is important.
23110037SARM gem5 Developers"""
23210037SARM gem5 Developers
23310037SARM gem5 Developers# Check for style hook and prompt for installation if it's not there.
23410037SARM gem5 Developers# Skip this if --ignore-style was specified, there's no .hg dir to
23510037SARM gem5 Developers# install a hook in, or there's no interactive terminal to prompt.
23610037SARM gem5 Developersif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty():
23710037SARM gem5 Developers    style_hook = True
23810037SARM gem5 Developers    try:
23910037SARM gem5 Developers        from mercurial import ui
2408147SAli.Saidi@ARM.com        ui = ui.ui()
2417427Sgblack@eecs.umich.edu        ui.readconfig(hgdir.File('hgrc').abspath)
2427427Sgblack@eecs.umich.edu        style_hook = ui.config('hooks', 'pretxncommit.style', None) and \
2437427Sgblack@eecs.umich.edu                     ui.config('hooks', 'pre-qrefresh.style', None)
24410037SARM gem5 Developers    except ImportError:
24510037SARM gem5 Developers        print mercurial_lib_not_found
24610037SARM gem5 Developers
24710037SARM gem5 Developers    if not style_hook:
24810037SARM gem5 Developers        print mercurial_style_message,
24910037SARM gem5 Developers        # continue unless user does ctrl-c/ctrl-d etc.
25010037SARM gem5 Developers        try:
25110037SARM gem5 Developers            raw_input()
25210037SARM gem5 Developers        except:
25310037SARM gem5 Developers            print "Input exception, exiting scons.\n"
25410037SARM gem5 Developers            sys.exit(1)
25510037SARM gem5 Developers        hgrc_path = '%s/.hg/hgrc' % main.root.abspath
25610037SARM gem5 Developers        print "Adding style hook to", hgrc_path, "\n"
25710037SARM gem5 Developers        try:
25810037SARM gem5 Developers            hgrc = open(hgrc_path, 'a')
25910037SARM gem5 Developers            hgrc.write(mercurial_style_hook)
26010037SARM gem5 Developers            hgrc.close()
26110037SARM gem5 Developers        except:
26210037SARM gem5 Developers            print "Error updating", hgrc_path
26310037SARM gem5 Developers            sys.exit(1)
26410037SARM gem5 Developers
26510037SARM gem5 Developers
26610037SARM gem5 Developers###################################################
26710037SARM gem5 Developers#
26810037SARM gem5 Developers# Figure out which configurations to set up based on the path(s) of
26910037SARM gem5 Developers# the target(s).
27010037SARM gem5 Developers#
27110037SARM gem5 Developers###################################################
27210037SARM gem5 Developers
27310037SARM gem5 Developers# Find default configuration & binary.
27410037SARM gem5 DevelopersDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug'))
27510037SARM gem5 Developers
27610037SARM gem5 Developers# helper function: find last occurrence of element in list
27710037SARM gem5 Developersdef rfind(l, elt, offs = -1):
27810037SARM gem5 Developers    for i in range(len(l)+offs, 0, -1):
27910037SARM gem5 Developers        if l[i] == elt:
28011770SCurtis.Dunham@arm.com            return i
28110037SARM gem5 Developers    raise ValueError, "element not found"
28211574SCurtis.Dunham@arm.com
28311770SCurtis.Dunham@arm.com# Take a list of paths (or SCons Nodes) and return a list with all
28411770SCurtis.Dunham@arm.com# paths made absolute and ~-expanded.  Paths will be interpreted
28510037SARM gem5 Developers# relative to the launch directory unless a different root is provided
28611770SCurtis.Dunham@arm.comdef makePathListAbsolute(path_list, root=GetLaunchDir()):
28711770SCurtis.Dunham@arm.com    return [abspath(joinpath(root, expanduser(str(p))))
28810037SARM gem5 Developers            for p in path_list]
28910037SARM gem5 Developers
29010037SARM gem5 Developers# Each target must have 'build' in the interior of the path; the
29110037SARM gem5 Developers# directory below this will determine the build parameters.  For
29210037SARM gem5 Developers# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
29310037SARM gem5 Developers# recognize that ALPHA_SE specifies the configuration because it
29410037SARM gem5 Developers# follow 'build' in the build path.
29510461SAndreas.Sandberg@ARM.com
29610461SAndreas.Sandberg@ARM.com# The funky assignment to "[:]" is needed to replace the list contents
29710461SAndreas.Sandberg@ARM.com# in place rather than reassign the symbol to a new list, which
29810461SAndreas.Sandberg@ARM.com# doesn't work (obviously!).
29910037SARM gem5 DevelopersBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)
30010037SARM gem5 Developers
30110037SARM gem5 Developers# Generate a list of the unique build roots and configs that the
30210037SARM gem5 Developers# collected targets reference.
30310037SARM gem5 Developersvariant_paths = []
30410037SARM gem5 Developersbuild_root = None
30510461SAndreas.Sandberg@ARM.comfor t in BUILD_TARGETS:
30610461SAndreas.Sandberg@ARM.com    path_dirs = t.split('/')
30710461SAndreas.Sandberg@ARM.com    try:
30810461SAndreas.Sandberg@ARM.com        build_top = rfind(path_dirs, 'build', -2)
30910461SAndreas.Sandberg@ARM.com    except:
31010037SARM gem5 Developers        print "Error: no non-leaf 'build' dir found on target path", t
31110037SARM gem5 Developers        Exit(1)
31210037SARM gem5 Developers    this_build_root = joinpath('/',*path_dirs[:build_top+1])
31310037SARM gem5 Developers    if not build_root:
31410037SARM gem5 Developers        build_root = this_build_root
31511574SCurtis.Dunham@arm.com    else:
31610037SARM gem5 Developers        if this_build_root != build_root:
31710037SARM gem5 Developers            print "Error: build targets not under same build root\n"\
31810037SARM gem5 Developers                  "  %s\n  %s" % (build_root, this_build_root)
31911574SCurtis.Dunham@arm.com            Exit(1)
32010037SARM gem5 Developers    variant_path = joinpath('/',*path_dirs[:build_top+2])
32110037SARM gem5 Developers    if variant_path not in variant_paths:
32210037SARM gem5 Developers        variant_paths.append(variant_path)
32310037SARM gem5 Developers
32410037SARM gem5 Developers# Make sure build_root exists (might not if this is the first build there)
32510037SARM gem5 Developersif not isdir(build_root):
32610037SARM gem5 Developers    mkdir(build_root)
32710037SARM gem5 Developersmain['BUILDROOT'] = build_root
32810037SARM gem5 Developers
32910037SARM gem5 DevelopersExport('main')
3307405SAli.Saidi@ARM.com
33110035Sandreas.hansson@arm.commain.SConsignFile(joinpath(build_root, "sconsign"))
3327405SAli.Saidi@ARM.com
3337405SAli.Saidi@ARM.com# Default duplicate option is to use hard links, but this messes up
3347614Sminkyu.jeong@arm.com# when you use emacs to edit a file in the target dir, as emacs moves
33512478SCurtis.Dunham@arm.com# file to file~ then copies to file, breaking the link.  Symbolic
33612478SCurtis.Dunham@arm.com# (soft) links work better.
33712478SCurtis.Dunham@arm.commain.SetOption('duplicate', 'soft-copy')
33812478SCurtis.Dunham@arm.com
33912478SCurtis.Dunham@arm.com#
34012478SCurtis.Dunham@arm.com# Set up global sticky variables... these are common to an entire build
34112478SCurtis.Dunham@arm.com# tree (not specific to a particular build like ALPHA_SE)
34212478SCurtis.Dunham@arm.com#
34312478SCurtis.Dunham@arm.com
34412478SCurtis.Dunham@arm.comglobal_vars_file = joinpath(build_root, 'variables.global')
34512478SCurtis.Dunham@arm.com
34612478SCurtis.Dunham@arm.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS)
34712478SCurtis.Dunham@arm.com
34812478SCurtis.Dunham@arm.comglobal_vars.AddVariables(
34912478SCurtis.Dunham@arm.com    ('CC', 'C compiler', environ.get('CC', main['CC'])),
35012478SCurtis.Dunham@arm.com    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
3517405SAli.Saidi@ARM.com    ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])),
3527405SAli.Saidi@ARM.com    ('BATCH', 'Use batch pool for build and tests', False),
3537405SAli.Saidi@ARM.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3547405SAli.Saidi@ARM.com    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
3557405SAli.Saidi@ARM.com    ('EXTRAS', 'Add extra directories to the compilation', '')
3567405SAli.Saidi@ARM.com    )
35710037SARM gem5 Developers
35810037SARM gem5 Developers# Update main environment with values from ARGUMENTS & global_vars_file
35910037SARM gem5 Developersglobal_vars.Update(main)
3609050Schander.sudanthi@arm.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main)
3617405SAli.Saidi@ARM.com
36210037SARM gem5 Developers# Save sticky variable settings back to current variables file
36310037SARM gem5 Developersglobal_vars.Save(global_vars_file, main)
3647720Sgblack@eecs.umich.edu
3657720Sgblack@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're
3667405SAli.Saidi@ARM.com# look for sources etc.  This list is exported as extras_dir_list.
3677405SAli.Saidi@ARM.combase_dir = main.srcdir.abspath
3687757SAli.Saidi@ARM.comif main['EXTRAS']:
36910037SARM gem5 Developers    extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':'))
37010037SARM gem5 Developerselse:
37110037SARM gem5 Developers    extras_dir_list = []
37210037SARM gem5 Developers
37310037SARM gem5 DevelopersExport('base_dir')
37410037SARM gem5 DevelopersExport('extras_dir_list')
37510037SARM gem5 Developers
37610037SARM gem5 Developers# the ext directory should be on the #includes path
37710037SARM gem5 Developersmain.Append(CPPPATH=[Dir('ext')])
37810037SARM gem5 Developers
37910037SARM gem5 Developersdef strip_build_path(path, env):
38010037SARM gem5 Developers    path = str(path)
38110037SARM gem5 Developers    variant_base = env['BUILDROOT'] + os.path.sep
38210037SARM gem5 Developers    if path.startswith(variant_base):
38310037SARM gem5 Developers        path = path[len(variant_base):]
38410037SARM gem5 Developers    elif path.startswith('build/'):
38510037SARM gem5 Developers        path = path[6:]
38610037SARM gem5 Developers    return path
38710037SARM gem5 Developers
38810037SARM gem5 Developers# Generate a string of the form:
38910037SARM gem5 Developers#   common/path/prefix/src1, src2 -> tgt1, tgt2
39010037SARM gem5 Developers# to print while building.
39110037SARM gem5 Developersclass Transform(object):
39210037SARM gem5 Developers    # all specific color settings should be here and nowhere else
39310037SARM gem5 Developers    tool_color = termcap.Normal
39410037SARM gem5 Developers    pfx_color = termcap.Yellow
39510037SARM gem5 Developers    srcs_color = termcap.Yellow + termcap.Bold
39610037SARM gem5 Developers    arrow_color = termcap.Blue + termcap.Bold
39710037SARM gem5 Developers    tgts_color = termcap.Yellow + termcap.Bold
39810037SARM gem5 Developers
39910037SARM gem5 Developers    def __init__(self, tool, max_sources=99):
40010037SARM gem5 Developers        self.format = self.tool_color + (" [%8s] " % tool) \
40110037SARM gem5 Developers                      + self.pfx_color + "%s" \
40210037SARM gem5 Developers                      + self.srcs_color + "%s" \
40310037SARM gem5 Developers                      + self.arrow_color + " -> " \
40410037SARM gem5 Developers                      + self.tgts_color + "%s" \
40510037SARM gem5 Developers                      + termcap.Normal
40610037SARM gem5 Developers        self.max_sources = max_sources
40710037SARM gem5 Developers
40810037SARM gem5 Developers    def __call__(self, target, source, env, for_signature=None):
40910037SARM gem5 Developers        # truncate source list according to max_sources param
41010037SARM gem5 Developers        source = source[0:self.max_sources]
41110037SARM gem5 Developers        def strip(f):
41210037SARM gem5 Developers            return strip_build_path(str(f), env)
41310037SARM gem5 Developers        if len(source) > 0:
41410037SARM gem5 Developers            srcs = map(strip, source)
4158284SAli.Saidi@ARM.com        else:
41610037SARM gem5 Developers            srcs = ['']
41710037SARM gem5 Developers        tgts = map(strip, target)
41810037SARM gem5 Developers        # surprisingly, os.path.commonprefix is a dumb char-by-char string
41910037SARM gem5 Developers        # operation that has nothing to do with paths.
4209050Schander.sudanthi@arm.com        com_pfx = os.path.commonprefix(srcs + tgts)
42110037SARM gem5 Developers        com_pfx_len = len(com_pfx)
42210037SARM gem5 Developers        if com_pfx:
42310037SARM gem5 Developers            # do some cleanup and sanity checking on common prefix
42410037SARM gem5 Developers            if com_pfx[-1] == ".":
42510037SARM gem5 Developers                # prefix matches all but file extension: ok
42610037SARM gem5 Developers                # back up one to change 'foo.cc -> o' to 'foo.cc -> .o'
42710037SARM gem5 Developers                com_pfx = com_pfx[0:-1]
42810037SARM gem5 Developers            elif com_pfx[-1] == "/":
42910037SARM gem5 Developers                # common prefix is directory path: OK
43010037SARM gem5 Developers                pass
43110037SARM gem5 Developers            else:
43210037SARM gem5 Developers                src0_len = len(srcs[0])
43310037SARM gem5 Developers                tgt0_len = len(tgts[0])
43410037SARM gem5 Developers                if src0_len == com_pfx_len:
43510037SARM gem5 Developers                    # source is a substring of target, OK
43610037SARM gem5 Developers                    pass
43710037SARM gem5 Developers                elif tgt0_len == com_pfx_len:
43810037SARM gem5 Developers                    # target is a substring of source, need to back up to
4399050Schander.sudanthi@arm.com                    # avoid empty string on RHS of arrow
4408284SAli.Saidi@ARM.com                    sep_idx = com_pfx.rfind(".")
44110037SARM gem5 Developers                    if sep_idx != -1:
44210037SARM gem5 Developers                        com_pfx = com_pfx[0:sep_idx]
44310037SARM gem5 Developers                    else:
44410037SARM gem5 Developers                        com_pfx = ''
44510037SARM gem5 Developers                elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".":
44610037SARM gem5 Developers                    # still splitting at file extension: ok
44710037SARM gem5 Developers                    pass
4487405SAli.Saidi@ARM.com                else:
4497731SAli.Saidi@ARM.com                    # probably a fluke; ignore it
4508468Swade.walker@arm.com                    com_pfx = ''
4518468Swade.walker@arm.com        # recalculate length in case com_pfx was modified
4528468Swade.walker@arm.com        com_pfx_len = len(com_pfx)
4537405SAli.Saidi@ARM.com        def fmt(files):
4547731SAli.Saidi@ARM.com            f = map(lambda s: s[com_pfx_len:], files)
4557405SAli.Saidi@ARM.com            return ', '.join(f)
4567405SAli.Saidi@ARM.com        return self.format % (com_pfx, fmt(srcs), fmt(tgts))
45711809Sbaz21@cam.ac.uk
45811809Sbaz21@cam.ac.ukExport('Transform')
4599130Satgutier@umich.edu
4609130Satgutier@umich.edu# enable the regression script to use the termcap
4619130Satgutier@umich.edumain['TERMCAP'] = termcap
4629130Satgutier@umich.edu
4639814Sandreas.hansson@arm.comif GetOption('verbose'):
4649130Satgutier@umich.edu    def MakeAction(action, string, *args, **kwargs):
4659130Satgutier@umich.edu        return Action(action, *args, **kwargs)
4669130Satgutier@umich.eduelse:
4679130Satgutier@umich.edu    MakeAction = Action
4689130Satgutier@umich.edu    main['CCCOMSTR']        = Transform("CC")
4699130Satgutier@umich.edu    main['CXXCOMSTR']       = Transform("CXX")
4709130Satgutier@umich.edu    main['ASCOMSTR']        = Transform("AS")
4719130Satgutier@umich.edu    main['SWIGCOMSTR']      = Transform("SWIG")
4729130Satgutier@umich.edu    main['ARCOMSTR']        = Transform("AR", 0)
4739130Satgutier@umich.edu    main['LINKCOMSTR']      = Transform("LINK", 0)
4749130Satgutier@umich.edu    main['RANLIBCOMSTR']    = Transform("RANLIB", 0)
4759130Satgutier@umich.edu    main['M4COMSTR']        = Transform("M4")
4769130Satgutier@umich.edu    main['SHCCCOMSTR']      = Transform("SHCC")
4779130Satgutier@umich.edu    main['SHCXXCOMSTR']     = Transform("SHCXX")
4789130Satgutier@umich.eduExport('MakeAction')
4799130Satgutier@umich.edu
4809130Satgutier@umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False)
4819130Satgutier@umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False)
4829130Satgutier@umich.edu
4839130Satgutier@umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
4849130Satgutier@umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
4859130Satgutier@umich.edumain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
4867583SAli.Saidi@arm.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0
4877583SAli.Saidi@arm.comif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1:
4887583SAli.Saidi@arm.com    print 'Error: How can we have two at the same time?'
48910461SAndreas.Sandberg@ARM.com    Exit(1)
49010461SAndreas.Sandberg@ARM.com
49110461SAndreas.Sandberg@ARM.com# Set up default C++ compiler flags
49210461SAndreas.Sandberg@ARM.comif main['GCC']:
49310461SAndreas.Sandberg@ARM.com    main.Append(CCFLAGS=['-pipe'])
49410461SAndreas.Sandberg@ARM.com    main.Append(CCFLAGS=['-fno-strict-aliasing'])
49510461SAndreas.Sandberg@ARM.com    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
4968302SAli.Saidi@ARM.com    # Read the GCC version to check for versions with bugs
4978302SAli.Saidi@ARM.com    # Note CCVERSION doesn't work here because it is run with the CC
4987783SGiacomo.Gabrielli@arm.com    # before we override it from the command line
4997783SGiacomo.Gabrielli@arm.com    gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False)
5007783SGiacomo.Gabrielli@arm.com    main['GCC_VERSION'] = gcc_version
5017783SGiacomo.Gabrielli@arm.com    if not compareVersions(gcc_version, '4.4.1') or \
50210037SARM gem5 Developers       not compareVersions(gcc_version, '4.4.2'):
50310037SARM gem5 Developers        print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.'
50410037SARM gem5 Developers        main.Append(CCFLAGS=['-fno-tree-vectorize'])
50510037SARM gem5 Developers    if compareVersions(gcc_version, '4.6') >= 0:
50610037SARM gem5 Developers        main.Append(CXXFLAGS=['-std=c++0x'])
50710037SARM gem5 Developerselif main['ICC']:
50810037SARM gem5 Developers    pass #Fix me... add warning flags once we clean up icc warnings
50910037SARM gem5 Developerselif main['SUNCC']:
51010037SARM gem5 Developers    main.Append(CCFLAGS=['-Qoption ccfe'])
51110037SARM gem5 Developers    main.Append(CCFLAGS=['-features=gcc'])
51210037SARM gem5 Developers    main.Append(CCFLAGS=['-features=extensions'])
51310037SARM gem5 Developers    main.Append(CCFLAGS=['-library=stlport4'])
51410037SARM gem5 Developers    main.Append(CCFLAGS=['-xar'])
51510037SARM gem5 Developers    #main.Append(CCFLAGS=['-instances=semiexplicit'])
51610037SARM gem5 Developerselif main['CLANG']:
51710037SARM gem5 Developers    clang_version_re = re.compile(".* version (\d+\.\d+)")
51810037SARM gem5 Developers    clang_version_match = clang_version_re.match(CXX_version)
51910037SARM gem5 Developers    if (clang_version_match):
52010037SARM gem5 Developers        clang_version = clang_version_match.groups()[0]
52110037SARM gem5 Developers        if compareVersions(clang_version, "2.9") < 0:
52210037SARM gem5 Developers            print 'Error: clang version 2.9 or newer required.'
52310037SARM gem5 Developers            print '       Installed version:', clang_version
52410037SARM gem5 Developers            Exit(1)
52510037SARM gem5 Developers    else:
52610037SARM gem5 Developers        print 'Error: Unable to determine clang version.'
52710037SARM gem5 Developers        Exit(1)
52810037SARM gem5 Developers
52910037SARM gem5 Developers    main.Append(CCFLAGS=['-pipe'])
53010037SARM gem5 Developers    main.Append(CCFLAGS=['-fno-strict-aliasing'])
53110037SARM gem5 Developers    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
53210037SARM gem5 Developers    main.Append(CCFLAGS=['-Wno-tautological-compare'])
53310037SARM gem5 Developers    main.Append(CCFLAGS=['-Wno-self-assign'])
53410037SARM gem5 Developers    # Ruby makes frequent use of extraneous parantheses in the printing
53510037SARM gem5 Developers    # of if-statements
53610037SARM gem5 Developers    main.Append(CCFLAGS=['-Wno-parentheses'])
53710037SARM gem5 Developers
53810037SARM gem5 Developers    if compareVersions(clang_version, "3") >= 0:
53910037SARM gem5 Developers        main.Append(CXXFLAGS=['-std=c++0x'])
54010338SCurtis.Dunham@arm.comelse:
54110338SCurtis.Dunham@arm.com    print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal,
54210338SCurtis.Dunham@arm.com    print "Don't know what compiler options to use for your compiler."
54310037SARM gem5 Developers    print termcap.Yellow + '       compiler:' + termcap.Normal, main['CXX']
54410037SARM gem5 Developers    print termcap.Yellow + '       version:' + termcap.Normal,
54510037SARM gem5 Developers    if not CXX_version:
54610037SARM gem5 Developers        print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\
54710037SARM gem5 Developers               termcap.Normal
54810037SARM gem5 Developers    else:
54910037SARM gem5 Developers        print CXX_version.replace('\n', '<nl>')
55010037SARM gem5 Developers    print "       If you're trying to use a compiler other than GCC, ICC, SunCC,"
55110037SARM gem5 Developers    print "       or clang, there appears to be something wrong with your"
55210037SARM gem5 Developers    print "       environment."
55310037SARM gem5 Developers    print "       "
55410037SARM gem5 Developers    print "       If you are trying to use a compiler other than those listed"
55510037SARM gem5 Developers    print "       above you will need to ease fix SConstruct and "
55610037SARM gem5 Developers    print "       src/SConscript to support that compiler."
55710037SARM gem5 Developers    Exit(1)
55810037SARM gem5 Developers
55910037SARM gem5 Developers# Set up common yacc/bison flags (needed for Ruby)
56010037SARM gem5 Developersmain['YACCFLAGS'] = '-d'
56110037SARM gem5 Developersmain['YACCHXXFILESUFFIX'] = '.hh'
56210037SARM gem5 Developers
56310037SARM gem5 Developers# Do this after we save setting back, or else we'll tack on an
56410037SARM gem5 Developers# extra 'qdo' every time we run scons.
56510037SARM gem5 Developersif main['BATCH']:
56610037SARM gem5 Developers    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
56710037SARM gem5 Developers    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
56810037SARM gem5 Developers    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
56910037SARM gem5 Developers    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
57010037SARM gem5 Developers    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
5718549Sdaniel.johnson@arm.com
5728868SMatt.Horsnell@arm.comif sys.platform == 'cygwin':
5738868SMatt.Horsnell@arm.com    # cygwin has some header file issues...
5748868SMatt.Horsnell@arm.com    main.Append(CCFLAGS=["-Wno-uninitialized"])
5758868SMatt.Horsnell@arm.com
5768868SMatt.Horsnell@arm.com# Check for SWIG
5778868SMatt.Horsnell@arm.comif not main.has_key('SWIG'):
5788868SMatt.Horsnell@arm.com    print 'Error: SWIG utility not found.'
5798868SMatt.Horsnell@arm.com    print '       Please install (see http://www.swig.org) and retry.'
5808868SMatt.Horsnell@arm.com    Exit(1)
58110461SAndreas.Sandberg@ARM.com
5828868SMatt.Horsnell@arm.com# Check for appropriate SWIG version
58310461SAndreas.Sandberg@ARM.comswig_version = readCommand(('swig', '-version'), exception='').split()
58410037SARM gem5 Developers# First 3 words should be "SWIG Version x.y.z"
5858868SMatt.Horsnell@arm.comif len(swig_version) < 3 or \
58610037SARM gem5 Developers        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
58711150Smitch.hayenga@arm.com    print 'Error determining SWIG version.'
58810037SARM gem5 Developers    Exit(1)
58910037SARM gem5 Developers
59010037SARM gem5 Developersmin_swig_version = '1.3.34'
59110037SARM gem5 Developersif compareVersions(swig_version[2], min_swig_version) < 0:
59211150Smitch.hayenga@arm.com    print 'Error: SWIG version', min_swig_version, 'or newer required.'
59310037SARM gem5 Developers    print '       Installed version:', swig_version[2]
59410037SARM gem5 Developers    Exit(1)
59510037SARM gem5 Developers
59610037SARM gem5 Developers# Set up SWIG flags & scanner
59710037SARM gem5 Developersswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
59810037SARM gem5 Developersmain.Append(SWIGFLAGS=swig_flags)
59910037SARM gem5 Developers
60010037SARM gem5 Developers# filter out all existing swig scanners, they mess up the dependency
60110037SARM gem5 Developers# stuff for some reason
60210037SARM gem5 Developersscanners = []
60310037SARM gem5 Developersfor scanner in main['SCANNERS']:
60410037SARM gem5 Developers    skeys = scanner.skeys
60510037SARM gem5 Developers    if skeys == '.i':
60610037SARM gem5 Developers        continue
60710037SARM gem5 Developers
60810037SARM gem5 Developers    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
60910037SARM gem5 Developers        continue
61010037SARM gem5 Developers
61110037SARM gem5 Developers    scanners.append(scanner)
61210037SARM gem5 Developers
61310037SARM gem5 Developers# add the new swig scanner that we like better
61410037SARM gem5 Developersfrom SCons.Scanner import ClassicCPP as CPPScanner
61510037SARM gem5 Developersswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
61610037SARM gem5 Developersscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
61710037SARM gem5 Developers
61810037SARM gem5 Developers# replace the scanners list that has what we want
61910037SARM gem5 Developersmain['SCANNERS'] = scanners
62010037SARM gem5 Developers
62110037SARM gem5 Developers# Add a custom Check function to the Configure context so that we can
62211769SCurtis.Dunham@arm.com# figure out if the compiler adds leading underscores to global
62311769SCurtis.Dunham@arm.com# variables.  This is needed for the autogenerated asm files that we
62410037SARM gem5 Developers# use for embedding the python code.
62511770SCurtis.Dunham@arm.comdef CheckLeading(context):
62611770SCurtis.Dunham@arm.com    context.Message("Checking for leading underscore in global variables...")
62710037SARM gem5 Developers    # 1) Define a global variable called x from asm so the C compiler
62811770SCurtis.Dunham@arm.com    #    won't change the symbol at all.
62911769SCurtis.Dunham@arm.com    # 2) Declare that variable.
63010844Sandreas.sandberg@arm.com    # 3) Use the variable
63111772SCurtis.Dunham@arm.com    #
63211772SCurtis.Dunham@arm.com    # If the compiler prepends an underscore, this will successfully
63311772SCurtis.Dunham@arm.com    # link because the external symbol 'x' will be called '_x' which
63411772SCurtis.Dunham@arm.com    # was defined by the asm statement.  If the compiler does not
63511774SCurtis.Dunham@arm.com    # prepend an underscore, this will not successfully link because
63611774SCurtis.Dunham@arm.com    # '_x' will have been defined by assembly, while the C portion of
63711774SCurtis.Dunham@arm.com    # the code will be trying to use 'x'
63811774SCurtis.Dunham@arm.com    ret = context.TryLink('''
63911774SCurtis.Dunham@arm.com        asm(".globl _x; _x: .byte 0");
64011774SCurtis.Dunham@arm.com        extern int x;
64111774SCurtis.Dunham@arm.com        int main() { return x; }
64211773SCurtis.Dunham@arm.com        ''', extension=".c")
64311773SCurtis.Dunham@arm.com    context.env.Append(LEADING_UNDERSCORE=ret)
64411773SCurtis.Dunham@arm.com    context.Result(ret)
64511773SCurtis.Dunham@arm.com    return ret
64611773SCurtis.Dunham@arm.com
64711773SCurtis.Dunham@arm.com# Platform-specific configuration.  Note again that we assume that all
64811773SCurtis.Dunham@arm.com# builds under a given build root run on the same host platform.
64911772SCurtis.Dunham@arm.comconf = Configure(main,
65010037SARM gem5 Developers                 conf_dir = joinpath(build_root, '.scons_config'),
65110844Sandreas.sandberg@arm.com                 log_file = joinpath(build_root, 'scons_config.log'),
65210844Sandreas.sandberg@arm.com                 custom_tests = { 'CheckLeading' : CheckLeading })
65310844Sandreas.sandberg@arm.com
65410844Sandreas.sandberg@arm.com# Check for leading underscores.  Don't really need to worry either
65510844Sandreas.sandberg@arm.com# way so don't need to check the return code.
65610844Sandreas.sandberg@arm.comconf.CheckLeading()
65710188Sgeoffrey.blake@arm.com
65810037SARM gem5 Developers# Check if we should compile a 64 bit binary on Mac OS X/Darwin
65910037SARM gem5 Developerstry:
6607405SAli.Saidi@ARM.com    import platform
6617405SAli.Saidi@ARM.com    uname = platform.uname()
6627405SAli.Saidi@ARM.com    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
6637405SAli.Saidi@ARM.com        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
6647405SAli.Saidi@ARM.com            main.Append(CCFLAGS=['-arch', 'x86_64'])
6657405SAli.Saidi@ARM.com            main.Append(CFLAGS=['-arch', 'x86_64'])
6667405SAli.Saidi@ARM.com            main.Append(LINKFLAGS=['-arch', 'x86_64'])
6677405SAli.Saidi@ARM.com            main.Append(ASFLAGS=['-arch', 'x86_64'])
6687614Sminkyu.jeong@arm.comexcept:
66912478SCurtis.Dunham@arm.com    pass
67012478SCurtis.Dunham@arm.com
67112478SCurtis.Dunham@arm.com# Recent versions of scons substitute a "Null" object for Configure()
67212478SCurtis.Dunham@arm.com# when configuration isn't necessary, e.g., if the "--help" option is
67312478SCurtis.Dunham@arm.com# present.  Unfortuantely this Null object always returns false,
67411771SCurtis.Dunham@arm.com# breaking all our configuration checks.  We replace it with our own
67512478SCurtis.Dunham@arm.com# more optimistic null object that returns True instead.
67612478SCurtis.Dunham@arm.comif not conf:
67710037SARM gem5 Developers    def NullCheck(*args, **kwargs):
67812478SCurtis.Dunham@arm.com        return True
67910037SARM gem5 Developers
68012478SCurtis.Dunham@arm.com    class NullConf:
68110037SARM gem5 Developers        def __init__(self, env):
68212478SCurtis.Dunham@arm.com            self.env = env
68310037SARM gem5 Developers        def Finish(self):
6847405SAli.Saidi@ARM.com            return self.env
6857405SAli.Saidi@ARM.com        def __getattr__(self, mname):
68612406Sgabeblack@google.com            return NullCheck
68712406Sgabeblack@google.com
68812406Sgabeblack@google.com    conf = NullConf(main)
68912406Sgabeblack@google.com
69012406Sgabeblack@google.com# Find Python include and library directories for embedding the
69112406Sgabeblack@google.com# interpreter.  For consistency, we will use the same Python
69212406Sgabeblack@google.com# installation used to run scons (and thus this script).  If you want
69312406Sgabeblack@google.com# to link in an alternate version, see above for instructions on how
69412406Sgabeblack@google.com# to invoke scons with a different copy of the Python interpreter.
69512406Sgabeblack@google.comfrom distutils import sysconfig
69612406Sgabeblack@google.com
69712406Sgabeblack@google.compy_getvar = sysconfig.get_config_var
69812406Sgabeblack@google.com
69912406Sgabeblack@google.compy_debug = getattr(sys, 'pydebug', False)
70012406Sgabeblack@google.compy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "")
70112406Sgabeblack@google.com
70212406Sgabeblack@google.compy_general_include = sysconfig.get_python_inc()
70312406Sgabeblack@google.compy_platform_include = sysconfig.get_python_inc(plat_specific=True)
70412406Sgabeblack@google.compy_includes = [ py_general_include ]
70512406Sgabeblack@google.comif py_platform_include != py_general_include:
70612406Sgabeblack@google.com    py_includes.append(py_platform_include)
70712406Sgabeblack@google.com
7087405SAli.Saidi@ARM.compy_lib_path = [ py_getvar('LIBDIR') ]
7097405SAli.Saidi@ARM.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no
7107405SAli.Saidi@ARM.com# shared library in prefix/lib/.
7117749SAli.Saidi@ARM.comif not py_getvar('Py_ENABLE_SHARED'):
7127405SAli.Saidi@ARM.com    py_lib_path.append(py_getvar('LIBPL'))
7138284SAli.Saidi@ARM.com
71410037SARM gem5 Developerspy_libs = []
71510037SARM gem5 Developersfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
7168284SAli.Saidi@ARM.com    if not lib.startswith('-l'):
7178284SAli.Saidi@ARM.com        # Python requires some special flags to link (e.g. -framework
71810037SARM gem5 Developers        # common on OS X systems), assume appending preserves order
71910037SARM gem5 Developers        main.Append(LINKFLAGS=[lib])
72010037SARM gem5 Developers    else:
7218284SAli.Saidi@ARM.com        lib = lib[2:]
7227405SAli.Saidi@ARM.com        if lib not in py_libs:
7237405SAli.Saidi@ARM.com            py_libs.append(lib)
7247749SAli.Saidi@ARM.compy_libs.append(py_version)
7257749SAli.Saidi@ARM.com
7267749SAli.Saidi@ARM.commain.Append(CPPPATH=py_includes)
7277749SAli.Saidi@ARM.commain.Append(LIBPATH=py_lib_path)
7287405SAli.Saidi@ARM.com
72912510Sgiacomo.travaglini@arm.com# Cache build files in the supplied directory.
73012406Sgabeblack@google.comif main['M5_BUILD_CACHE']:
73112406Sgabeblack@google.com    print 'Using build cache located at', main['M5_BUILD_CACHE']
7327749SAli.Saidi@ARM.com    CacheDir(main['M5_BUILD_CACHE'])
7337749SAli.Saidi@ARM.com
7347614Sminkyu.jeong@arm.com
7357614Sminkyu.jeong@arm.com# verify that this stuff works
7367720Sgblack@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
7377720Sgblack@eecs.umich.edu    print "Error: can't find Python.h header in", py_includes
7387720Sgblack@eecs.umich.edu    Exit(1)
7398887Sgeoffrey.blake@arm.com
7408887Sgeoffrey.blake@arm.comfor lib in py_libs:
7418887Sgeoffrey.blake@arm.com    if not conf.CheckLib(lib):
7428887Sgeoffrey.blake@arm.com        print "Error: can't find library %s required by python" % lib
7438887Sgeoffrey.blake@arm.com        Exit(1)
7448887Sgeoffrey.blake@arm.com
7458887Sgeoffrey.blake@arm.com# On Solaris you need to use libsocket for socket ops
7468887Sgeoffrey.blake@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
7478887Sgeoffrey.blake@arm.com   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
7487408Sgblack@eecs.umich.edu       print "Can't find library with socket calls (e.g. accept())"
74910037SARM gem5 Developers       Exit(1)
75010037SARM gem5 Developers
75110037SARM gem5 Developers# Check for zlib.  If the check passes, libz will be automatically
75210037SARM gem5 Developers# added to the LIBS environment variable.
75310037SARM gem5 Developersif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
75410037SARM gem5 Developers    print 'Error: did not find needed zlib compression library '\
75510037SARM gem5 Developers          'and/or zlib.h header file.'
75610037SARM gem5 Developers    print '       Please install zlib and try again.'
75710037SARM gem5 Developers    Exit(1)
75810037SARM gem5 Developers
75910037SARM gem5 Developers# Check for librt.
7607408Sgblack@eecs.umich.eduhave_posix_clock = \
7617408Sgblack@eecs.umich.edu    conf.CheckLibWithHeader(None, 'time.h', 'C',
7628206SWilliam.Wang@arm.com                            'clock_nanosleep(0,0,NULL,NULL);') or \
7638206SWilliam.Wang@arm.com    conf.CheckLibWithHeader('rt', 'time.h', 'C',
7648206SWilliam.Wang@arm.com                            'clock_nanosleep(0,0,NULL,NULL);')
7658206SWilliam.Wang@arm.com
7668206SWilliam.Wang@arm.comif conf.CheckLib('tcmalloc_minimal'):
7678206SWilliam.Wang@arm.com    have_tcmalloc = True
7688206SWilliam.Wang@arm.comelse:
7698206SWilliam.Wang@arm.com    have_tcmalloc = False
77010037SARM gem5 Developers    print termcap.Yellow + termcap.Bold + \
77110037SARM gem5 Developers          "You can get a 12% performance improvement by installing tcmalloc "\
77210037SARM gem5 Developers          "(google-perftools package on Ubuntu or RedHat)." + termcap.Normal
77310037SARM gem5 Developers
77410037SARM gem5 Developersif not have_posix_clock:
77510037SARM gem5 Developers    print "Can't find library for POSIX clocks."
77610037SARM gem5 Developers
77710037SARM gem5 Developers# Check for <fenv.h> (C99 FP environment control)
77810037SARM gem5 Developershave_fenv = conf.CheckHeader('fenv.h', '<>')
77910037SARM gem5 Developersif not have_fenv:
78010037SARM gem5 Developers    print "Warning: Header file <fenv.h> not found."
78110037SARM gem5 Developers    print "         This host has no IEEE FP rounding mode control."
78210037SARM gem5 Developers
78310037SARM gem5 Developers######################################################################
7848206SWilliam.Wang@arm.com#
78510037SARM gem5 Developers# Finish the configuration
78610037SARM gem5 Developers#
78710037SARM gem5 Developersmain = conf.Finish()
78810037SARM gem5 Developers
78910037SARM gem5 Developers######################################################################
79010037SARM gem5 Developers#
79110037SARM gem5 Developers# Collect all non-global variables
79210037SARM gem5 Developers#
79310037SARM gem5 Developers
79410037SARM gem5 Developers# Define the universe of supported ISAs
79510037SARM gem5 Developersall_isa_list = [ ]
79610037SARM gem5 DevelopersExport('all_isa_list')
79710037SARM gem5 Developers
79810037SARM gem5 Developersclass CpuModel(object):
79910037SARM gem5 Developers    '''The CpuModel class encapsulates everything the ISA parser needs to
80010037SARM gem5 Developers    know about a particular CPU model.'''
80110037SARM gem5 Developers
80210037SARM gem5 Developers    # Dict of available CPU model objects.  Accessible as CpuModel.dict.
80310037SARM gem5 Developers    dict = {}
80410037SARM gem5 Developers    list = []
80510037SARM gem5 Developers    defaults = []
80610037SARM gem5 Developers
80710037SARM gem5 Developers    # Constructor.  Automatically adds models to CpuModel.dict.
80810037SARM gem5 Developers    def __init__(self, name, filename, includes, strings, default=False):
80910037SARM gem5 Developers        self.name = name           # name of model
81010037SARM gem5 Developers        self.filename = filename   # filename for output exec code
81110037SARM gem5 Developers        self.includes = includes   # include files needed in exec file
81210037SARM gem5 Developers        # The 'strings' dict holds all the per-CPU symbols we can
81310037SARM gem5 Developers        # substitute into templates etc.
81410037SARM gem5 Developers        self.strings = strings
81510037SARM gem5 Developers
81610037SARM gem5 Developers        # This cpu is enabled by default
81710037SARM gem5 Developers        self.default = default
81810037SARM gem5 Developers
81910037SARM gem5 Developers        # Add self to dict
82010037SARM gem5 Developers        if name in CpuModel.dict:
82110037SARM gem5 Developers            raise AttributeError, "CpuModel '%s' already registered" % name
82210037SARM gem5 Developers        CpuModel.dict[name] = self
82310037SARM gem5 Developers        CpuModel.list.append(name)
82410037SARM gem5 Developers
8258206SWilliam.Wang@arm.comExport('CpuModel')
8268206SWilliam.Wang@arm.com
8277408Sgblack@eecs.umich.edu# Sticky variables get saved in the variables file so they persist from
8287408Sgblack@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
8297408Sgblack@eecs.umich.edu# value becomes sticky).
8307731SAli.Saidi@ARM.comsticky_vars = Variables(args=ARGUMENTS)
8318206SWilliam.Wang@arm.comExport('sticky_vars')
83210037SARM gem5 Developers
83310037SARM gem5 Developers# Sticky variables that should be exported
83410037SARM gem5 Developersexport_vars = []
83510037SARM gem5 DevelopersExport('export_vars')
83610037SARM gem5 Developers
8377408Sgblack@eecs.umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the
8387408Sgblack@eecs.umich.edu# above variables
8397408Sgblack@eecs.umich.eduif not GetOption('verbose'):
8407408Sgblack@eecs.umich.edu    print "Reading SConsopts"
8417408Sgblack@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list:
8427408Sgblack@eecs.umich.edu    if not isdir(bdir):
8437408Sgblack@eecs.umich.edu        print "Error: directory '%s' does not exist" % bdir
8447408Sgblack@eecs.umich.edu        Exit(1)
8457408Sgblack@eecs.umich.edu    for root, dirs, files in os.walk(bdir):
8467408Sgblack@eecs.umich.edu        if 'SConsopts' in files:
84710037SARM gem5 Developers            if GetOption('verbose'):
84810037SARM gem5 Developers                print "Reading", joinpath(root, 'SConsopts')
84910037SARM gem5 Developers            SConscript(joinpath(root, 'SConsopts'))
85010037SARM gem5 Developers
85110037SARM gem5 Developersall_isa_list.sort()
85210037SARM gem5 Developers
8537408Sgblack@eecs.umich.edusticky_vars.AddVariables(
8547408Sgblack@eecs.umich.edu    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
8557408Sgblack@eecs.umich.edu    ListVariable('CPU_MODELS', 'CPU models',
8567408Sgblack@eecs.umich.edu                 sorted(n for n,m in CpuModel.dict.iteritems() if m.default),
8577408Sgblack@eecs.umich.edu                 sorted(CpuModel.list)),
8587408Sgblack@eecs.umich.edu    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
8597408Sgblack@eecs.umich.edu                 False),
8607408Sgblack@eecs.umich.edu    BoolVariable('SS_COMPATIBLE_FP',
8617408Sgblack@eecs.umich.edu                 'Make floating-point results compatible with SimpleScalar',
8627408Sgblack@eecs.umich.edu                 False),
8637408Sgblack@eecs.umich.edu    BoolVariable('USE_SSE2',
8647408Sgblack@eecs.umich.edu                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
86510037SARM gem5 Developers                 False),
86610037SARM gem5 Developers    BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
8679377Sgblack@eecs.umich.edu    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
8687408Sgblack@eecs.umich.edu    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
8697408Sgblack@eecs.umich.edu    )
87010037SARM gem5 Developers
87110037SARM gem5 Developers# These variables get exported to #defines in config/*.hh (see src/SConscript).
87210037SARM gem5 Developersexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP',
87310037SARM gem5 Developers                'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK' ]
87410037SARM gem5 Developers
87510037SARM gem5 Developers###################################################
87610037SARM gem5 Developers#
87710037SARM gem5 Developers# Define a SCons builder for configuration flag headers.
87810037SARM gem5 Developers#
87910037SARM gem5 Developers###################################################
88010037SARM gem5 Developers
88110037SARM gem5 Developers# This function generates a config header file that #defines the
88210037SARM gem5 Developers# variable symbol to the current variable setting (0 or 1).  The source
88310037SARM gem5 Developers# operands are the name of the variable and a Value node containing the
88410037SARM gem5 Developers# value of the variable.
88510037SARM gem5 Developersdef build_config_file(target, source, env):
88610037SARM gem5 Developers    (variable, value) = [s.get_contents() for s in source]
88710037SARM gem5 Developers    f = file(str(target[0]), 'w')
88810037SARM gem5 Developers    print >> f, '#define', variable, value
88910037SARM gem5 Developers    f.close()
89010037SARM gem5 Developers    return None
89110037SARM gem5 Developers
89210037SARM gem5 Developers# Combine the two functions into a scons Action object.
89310037SARM gem5 Developersconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2))
89410037SARM gem5 Developers
89510037SARM gem5 Developers# The emitter munges the source & target node lists to reflect what
89610037SARM gem5 Developers# we're really doing.
89710037SARM gem5 Developersdef config_emitter(target, source, env):
89810037SARM gem5 Developers    # extract variable name from Builder arg
89910037SARM gem5 Developers    variable = str(target[0])
90010037SARM gem5 Developers    # True target is config header file
90110037SARM gem5 Developers    target = joinpath('config', variable.lower() + '.hh')
90210037SARM gem5 Developers    val = env[variable]
90310037SARM gem5 Developers    if isinstance(val, bool):
90410037SARM gem5 Developers        # Force value to 0/1
90510037SARM gem5 Developers        val = int(val)
90610037SARM gem5 Developers    elif isinstance(val, str):
90710037SARM gem5 Developers        val = '"' + val + '"'
90810037SARM gem5 Developers
90910037SARM gem5 Developers    # Sources are variable name & value (packaged in SCons Value nodes)
91010037SARM gem5 Developers    return ([target], [Value(variable), Value(val)])
91110037SARM gem5 Developers
91210037SARM gem5 Developersconfig_builder = Builder(emitter = config_emitter, action = config_action)
9138302SAli.Saidi@ARM.com
9148302SAli.Saidi@ARM.commain.Append(BUILDERS = { 'ConfigFile' : config_builder })
9158302SAli.Saidi@ARM.com
91610037SARM gem5 Developers# libelf build is shared across all configs in the build root.
9178302SAli.Saidi@ARM.commain.SConscript('ext/libelf/SConscript',
9188302SAli.Saidi@ARM.com                variant_dir = joinpath(build_root, 'libelf'))
9198302SAli.Saidi@ARM.com
9207783SGiacomo.Gabrielli@arm.com# gzstream build is shared across all configs in the build root.
9217783SGiacomo.Gabrielli@arm.commain.SConscript('ext/gzstream/SConscript',
92210037SARM gem5 Developers                variant_dir = joinpath(build_root, 'gzstream'))
92310037SARM gem5 Developers
9247783SGiacomo.Gabrielli@arm.com###################################################
9257783SGiacomo.Gabrielli@arm.com#
9267783SGiacomo.Gabrielli@arm.com# This function is used to set up a directory with switching headers
9277783SGiacomo.Gabrielli@arm.com#
9287783SGiacomo.Gabrielli@arm.com###################################################
92910037SARM gem5 Developers
93010037SARM gem5 Developersmain['ALL_ISA_LIST'] = all_isa_list
9317783SGiacomo.Gabrielli@arm.comdef make_switching_dir(dname, switch_headers, env):
9327783SGiacomo.Gabrielli@arm.com    # Generate the header.  target[0] is the full path of the output
9337783SGiacomo.Gabrielli@arm.com    # header to generate.  'source' is a dummy variable, since we get the
9347408Sgblack@eecs.umich.edu    # list of ISAs from env['ALL_ISA_LIST'].
9357408Sgblack@eecs.umich.edu    def gen_switch_hdr(target, source, env):
9368206SWilliam.Wang@arm.com        fname = str(target[0])
9378206SWilliam.Wang@arm.com        f = open(fname, 'w')
9387408Sgblack@eecs.umich.edu        isa = env['TARGET_ISA'].lower()
9397408Sgblack@eecs.umich.edu        print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
94010037SARM gem5 Developers        f.close()
9417408Sgblack@eecs.umich.edu
9427408Sgblack@eecs.umich.edu    # Build SCons Action object. 'varlist' specifies env vars that this
94310037SARM gem5 Developers    # action depends on; when env['ALL_ISA_LIST'] changes these actions
94410037SARM gem5 Developers    # should get re-executed.
94510037SARM gem5 Developers    switch_hdr_action = MakeAction(gen_switch_hdr,
94610037SARM gem5 Developers                          Transform("GENERATE"), varlist=['ALL_ISA_LIST'])
94710037SARM gem5 Developers
94810037SARM gem5 Developers    # Instantiate actions for each header
94910037SARM gem5 Developers    for hdr in switch_headers:
95010037SARM gem5 Developers        env.Command(hdr, [], switch_hdr_action)
95110037SARM gem5 DevelopersExport('make_switching_dir')
95210037SARM gem5 Developers
95310037SARM gem5 Developers###################################################
95410037SARM gem5 Developers#
95510037SARM gem5 Developers# Define build environments for selected configurations.
95610037SARM gem5 Developers#
95710037SARM gem5 Developers###################################################
95810037SARM gem5 Developers
95910037SARM gem5 Developersfor variant_path in variant_paths:
96010037SARM gem5 Developers    print "Building in", variant_path
96110037SARM gem5 Developers
96210037SARM gem5 Developers    # Make a copy of the build-root environment to use for this config.
96310037SARM gem5 Developers    env = main.Clone()
96410037SARM gem5 Developers    env['BUILDDIR'] = variant_path
96510037SARM gem5 Developers
96610037SARM gem5 Developers    # variant_dir is the tail component of build path, and is used to
96710037SARM gem5 Developers    # determine the build parameters (e.g., 'ALPHA_SE')
96810037SARM gem5 Developers    (build_root, variant_dir) = splitpath(variant_path)
96910037SARM gem5 Developers
97010037SARM gem5 Developers    # Set env variables according to the build directory config.
97110037SARM gem5 Developers    sticky_vars.files = []
97210037SARM gem5 Developers    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
97310037SARM gem5 Developers    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
97410037SARM gem5 Developers    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
97512406Sgabeblack@google.com    current_vars_file = joinpath(build_root, 'variables', variant_dir)
97612406Sgabeblack@google.com    if isfile(current_vars_file):
97710037SARM gem5 Developers        sticky_vars.files.append(current_vars_file)
9787408Sgblack@eecs.umich.edu        print "Using saved variables file %s" % current_vars_file
9797408Sgblack@eecs.umich.edu    else:
9807408Sgblack@eecs.umich.edu        # Build dir-specific variables file doesn't exist.
98110037SARM gem5 Developers
98211769SCurtis.Dunham@arm.com        # Make sure the directory is there so we can create it later
98311769SCurtis.Dunham@arm.com        opt_dir = dirname(current_vars_file)
98410037SARM gem5 Developers        if not isdir(opt_dir):
9857408Sgblack@eecs.umich.edu            mkdir(opt_dir)
98610037SARM gem5 Developers
98710037SARM gem5 Developers        # Get default build variables from source tree.  Variables are
98812406Sgabeblack@google.com        # normally determined by name of $VARIANT_DIR, but can be
98912406Sgabeblack@google.com        # overridden by '--default=' arg on command line.
9907408Sgblack@eecs.umich.edu        default = GetOption('default')
9919385SAndreas.Sandberg@arm.com        opts_dir = joinpath(main.root.abspath, 'build_opts')
9929385SAndreas.Sandberg@arm.com        if default:
9939385SAndreas.Sandberg@arm.com            default_vars_files = [joinpath(build_root, 'variables', default),
99410461SAndreas.Sandberg@ARM.com                                  joinpath(opts_dir, default)]
9959385SAndreas.Sandberg@arm.com        else:
9969385SAndreas.Sandberg@arm.com            default_vars_files = [joinpath(opts_dir, variant_dir)]
9979385SAndreas.Sandberg@arm.com        existing_files = filter(isfile, default_vars_files)
9989385SAndreas.Sandberg@arm.com        if existing_files:
9999385SAndreas.Sandberg@arm.com            default_vars_file = existing_files[0]
10009385SAndreas.Sandberg@arm.com            sticky_vars.files.append(default_vars_file)
10019385SAndreas.Sandberg@arm.com            print "Variables file %s not found,\n  using defaults in %s" \
10029385SAndreas.Sandberg@arm.com                  % (current_vars_file, default_vars_file)
10039385SAndreas.Sandberg@arm.com        else:
10049385SAndreas.Sandberg@arm.com            print "Error: cannot find variables file %s or " \
10059385SAndreas.Sandberg@arm.com                  "default file(s) %s" \
10069385SAndreas.Sandberg@arm.com                  % (current_vars_file, ' or '.join(default_vars_files))
10079385SAndreas.Sandberg@arm.com            Exit(1)
10087408Sgblack@eecs.umich.edu
10097408Sgblack@eecs.umich.edu    # Apply current variable settings to env
10107408Sgblack@eecs.umich.edu    sticky_vars.Update(env)
101110037SARM gem5 Developers
101210037SARM gem5 Developers    help_texts["local_vars"] += \
101310037SARM gem5 Developers        "Build variables for %s:\n" % variant_dir \
101410037SARM gem5 Developers                 + sticky_vars.GenerateHelpText(env)
101510037SARM gem5 Developers
101610037SARM gem5 Developers    # Process variable settings.
101710037SARM gem5 Developers
101810037SARM gem5 Developers    if not have_fenv and env['USE_FENV']:
101910037SARM gem5 Developers        print "Warning: <fenv.h> not available; " \
102010037SARM gem5 Developers              "forcing USE_FENV to False in", variant_dir + "."
102110037SARM gem5 Developers        env['USE_FENV'] = False
10229385SAndreas.Sandberg@arm.com
10237408Sgblack@eecs.umich.edu    if not env['USE_FENV']:
10249385SAndreas.Sandberg@arm.com        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
102510037SARM gem5 Developers        print "         FP results may deviate slightly from other platforms."
10267408Sgblack@eecs.umich.edu
102710037SARM gem5 Developers    if env['EFENCE']:
102810037SARM gem5 Developers        env.Append(LIBS=['efence'])
102910037SARM gem5 Developers
103010037SARM gem5 Developers    # Save sticky variable settings back to current variables file
103110037SARM gem5 Developers    sticky_vars.Save(current_vars_file, env)
10328284SAli.Saidi@ARM.com
10338284SAli.Saidi@ARM.com    if env['USE_SSE2']:
10348284SAli.Saidi@ARM.com        env.Append(CCFLAGS=['-msse2'])
103512406Sgabeblack@google.com
103612406Sgabeblack@google.com    if have_tcmalloc:
10378887Sgeoffrey.blake@arm.com        env.Append(LIBS=['tcmalloc_minimal'])
10388887Sgeoffrey.blake@arm.com
10398887Sgeoffrey.blake@arm.com    # The src/SConscript file sets up the build rules in 'env' according
10408733Sgeoffrey.blake@arm.com    # to the configured variables.  It returns a list of environments,
104112406Sgabeblack@google.com    # one for each variant build (debug, opt, etc.)
104212406Sgabeblack@google.com    envList = SConscript('src/SConscript', variant_dir = variant_path,
104312406Sgabeblack@google.com                         exports = 'env')
104412406Sgabeblack@google.com
10458733Sgeoffrey.blake@arm.com    # Set up the regression tests for each build.
10468284SAli.Saidi@ARM.com    for e in envList:
10477408Sgblack@eecs.umich.edu        SConscript('tests/SConscript',
104810037SARM gem5 Developers                   variant_dir = joinpath(variant_path, 'tests', e.Label),
10497408Sgblack@eecs.umich.edu                   exports = { 'env' : e }, duplicate = False)
105010037SARM gem5 Developers
105110037SARM gem5 Developers# base help text
105210037SARM gem5 DevelopersHelp('''
105310037SARM gem5 DevelopersUsage: scons [scons options] [build variables] [target(s)]
105412406Sgabeblack@google.com
10557408Sgblack@eecs.umich.eduExtra scons options:
105610037SARM gem5 Developers%(options)s
10577408Sgblack@eecs.umich.edu
105810037SARM gem5 DevelopersGlobal build variables:
105910037SARM gem5 Developers%(global_vars)s
106010037SARM gem5 Developers
106110037SARM gem5 Developers%(local_vars)s
106212406Sgabeblack@google.com''' % help_texts)
10637408Sgblack@eecs.umich.edu