SConstruct revision 9068
1955SN/A# -*- mode:python -*-
2955SN/A
37816Ssteve.reinhardt@amd.com# Copyright (c) 2011 Advanced Micro Devices, Inc.
45871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company
51762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
6955SN/A# All rights reserved.
7955SN/A#
8955SN/A# Redistribution and use in source and binary forms, with or without
9955SN/A# modification, are permitted provided that the following conditions are
10955SN/A# met: redistributions of source code must retain the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer;
12955SN/A# redistributions in binary form must reproduce the above copyright
13955SN/A# notice, this list of conditions and the following disclaimer in the
14955SN/A# documentation and/or other materials provided with the distribution;
15955SN/A# neither the name of the copyright holders nor the names of its
16955SN/A# contributors may be used to endorse or promote products derived from
17955SN/A# this software without specific prior written permission.
18955SN/A#
19955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
302665Ssaidi@eecs.umich.edu#
312665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
325863Snate@binkert.org#          Nathan Binkert
33955SN/A
34955SN/A###################################################
35955SN/A#
36955SN/A# SCons top-level build description (SConstruct) file.
37955SN/A#
388878Ssteve.reinhardt@amd.com# While in this directory ('gem5'), just type 'scons' to build the default
392632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
408878Ssteve.reinhardt@amd.com# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for
412632Sstever@eecs.umich.edu# the optimized full-system version).
42955SN/A#
438878Ssteve.reinhardt@amd.com# You can build gem5 in a different directory as long as there is a
442632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
452761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
462632Sstever@eecs.umich.edu# built for the same host system.
472632Sstever@eecs.umich.edu#
482632Sstever@eecs.umich.edu# Examples:
492761Sstever@eecs.umich.edu#
502761Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
512761Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
528878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug
538878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug
542761Sstever@eecs.umich.edu#
552761Sstever@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
562761Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
572761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
582761Sstever@eecs.umich.edu#   file.
598878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug
608878Ssteve.reinhardt@amd.com#   % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug
612632Sstever@eecs.umich.edu#
622632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
638878Ssteve.reinhardt@amd.com# 'gem5' directory (or use -u or -C to tell scons where to find this
648878Ssteve.reinhardt@amd.com# file), you can use 'scons -h' to print all the gem5-specific build
652632Sstever@eecs.umich.edu# options as well.
66955SN/A#
67955SN/A###################################################
68955SN/A
695863Snate@binkert.org# Check for recent-enough Python and SCons versions.
705863Snate@binkert.orgtry:
715863Snate@binkert.org    # Really old versions of scons only take two options for the
725863Snate@binkert.org    # function, so check once without the revision and once with the
735863Snate@binkert.org    # revision, the first instance will fail for stuff other than
745863Snate@binkert.org    # 0.98, and the second will fail for 0.98.0
755863Snate@binkert.org    EnsureSConsVersion(0, 98)
765863Snate@binkert.org    EnsureSConsVersion(0, 98, 1)
775863Snate@binkert.orgexcept SystemExit, e:
785863Snate@binkert.org    print """
795863Snate@binkert.orgFor more details, see:
808878Ssteve.reinhardt@amd.com    http://gem5.org/Dependencies
815863Snate@binkert.org"""
825863Snate@binkert.org    raise
835863Snate@binkert.org
845863Snate@binkert.org# We ensure the python version early because we have stuff that
855863Snate@binkert.org# requires python 2.4
865863Snate@binkert.orgtry:
875863Snate@binkert.org    EnsurePythonVersion(2, 4)
885863Snate@binkert.orgexcept SystemExit, e:
895863Snate@binkert.org    print """
905863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by
915863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default
925863Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter
935863Snate@binkert.orgon the scons script.
945863Snate@binkert.org
955863Snate@binkert.orgFor more details, see:
968878Ssteve.reinhardt@amd.com    http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation
975863Snate@binkert.org"""
985863Snate@binkert.org    raise
995863Snate@binkert.org
1006654Snate@binkert.org# Global Python includes
101955SN/Aimport os
1025396Ssaidi@eecs.umich.eduimport re
1035863Snate@binkert.orgimport subprocess
1045863Snate@binkert.orgimport sys
1054202Sbinkertn@umich.edu
1065863Snate@binkert.orgfrom os import mkdir, environ
1075863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath
1085863Snate@binkert.orgfrom os.path import exists,  isdir, isfile
1095863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath
110955SN/A
1116654Snate@binkert.org# SCons includes
1125273Sstever@gmail.comimport SCons
1135871Snate@binkert.orgimport SCons.Node
1145273Sstever@gmail.com
1156655Snate@binkert.orgextra_python_paths = [
1168878Ssteve.reinhardt@amd.com    Dir('src/python').srcnode().abspath, # gem5 includes
1176655Snate@binkert.org    Dir('ext/ply').srcnode().abspath, # ply is used by several files
1186655Snate@binkert.org    ]
1196655Snate@binkert.org    
1206655Snate@binkert.orgsys.path[1:1] = extra_python_paths
1215871Snate@binkert.org
1226654Snate@binkert.orgfrom m5.util import compareVersions, readCommand
1235396Ssaidi@eecs.umich.edufrom m5.util.terminal import get_termcap
1248120Sgblack@eecs.umich.edu
1258120Sgblack@eecs.umich.eduhelp_texts = {
1268120Sgblack@eecs.umich.edu    "options" : "",
1278120Sgblack@eecs.umich.edu    "global_vars" : "",
1288120Sgblack@eecs.umich.edu    "local_vars" : ""
1298120Sgblack@eecs.umich.edu}
1308120Sgblack@eecs.umich.edu
1318120Sgblack@eecs.umich.eduExport("help_texts")
1328879Ssteve.reinhardt@amd.com
1338879Ssteve.reinhardt@amd.com
1348879Ssteve.reinhardt@amd.com# There's a bug in scons in that (1) by default, the help texts from
1358879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h'
1368879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the
1378879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once
1388879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get
1398879Ssteve.reinhardt@amd.com# at the help texts from AddOptions.  See:
1408879Ssteve.reinhardt@amd.com#     http://scons.tigris.org/issues/show_bug.cgi?id=2356
1418879Ssteve.reinhardt@amd.com#     http://scons.tigris.org/issues/show_bug.cgi?id=2611
1428879Ssteve.reinhardt@amd.com# This hack lets us extract the help text from AddOptions and
1438879Ssteve.reinhardt@amd.com# re-inject it via Help().  Ideally someday this bug will be fixed and
1448879Ssteve.reinhardt@amd.com# we can just use AddOption directly.
1458120Sgblack@eecs.umich.edudef AddLocalOption(*args, **kwargs):
1468120Sgblack@eecs.umich.edu    col_width = 30
1478120Sgblack@eecs.umich.edu
1488120Sgblack@eecs.umich.edu    help = "  " + ", ".join(args)
1498120Sgblack@eecs.umich.edu    if "help" in kwargs:
1508120Sgblack@eecs.umich.edu        length = len(help)
1518120Sgblack@eecs.umich.edu        if length >= col_width:
1528120Sgblack@eecs.umich.edu            help += "\n" + " " * col_width
1538120Sgblack@eecs.umich.edu        else:
1548120Sgblack@eecs.umich.edu            help += " " * (col_width - length)
1558120Sgblack@eecs.umich.edu        help += kwargs["help"]
1568120Sgblack@eecs.umich.edu    help_texts["options"] += help + "\n"
1578120Sgblack@eecs.umich.edu
1588120Sgblack@eecs.umich.edu    AddOption(*args, **kwargs)
1598879Ssteve.reinhardt@amd.com
1608879Ssteve.reinhardt@amd.comAddLocalOption('--colors', dest='use_colors', action='store_true',
1618879Ssteve.reinhardt@amd.com               help="Add color to abbreviated scons output")
1628879Ssteve.reinhardt@amd.comAddLocalOption('--no-colors', dest='use_colors', action='store_false',
1638879Ssteve.reinhardt@amd.com               help="Don't add color to abbreviated scons output")
1648879Ssteve.reinhardt@amd.comAddLocalOption('--default', dest='default', type='string', action='store',
1658879Ssteve.reinhardt@amd.com               help='Override which build_opts file to use for defaults')
1668879Ssteve.reinhardt@amd.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true',
1678879Ssteve.reinhardt@amd.com               help='Disable style checking hooks')
1688879Ssteve.reinhardt@amd.comAddLocalOption('--update-ref', dest='update_ref', action='store_true',
1698879Ssteve.reinhardt@amd.com               help='Update test reference outputs')
1708879Ssteve.reinhardt@amd.comAddLocalOption('--verbose', dest='verbose', action='store_true',
1718120Sgblack@eecs.umich.edu               help='Print full tool command lines')
1727816Ssteve.reinhardt@amd.com
1737816Ssteve.reinhardt@amd.comtermcap = get_termcap(GetOption('use_colors'))
1747816Ssteve.reinhardt@amd.com
1757816Ssteve.reinhardt@amd.com########################################################################
1767816Ssteve.reinhardt@amd.com#
1777816Ssteve.reinhardt@amd.com# Set up the main build environment.
1787816Ssteve.reinhardt@amd.com#
1797816Ssteve.reinhardt@amd.com########################################################################
1807816Ssteve.reinhardt@amd.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
1815871Snate@binkert.org                 'PYTHONPATH', 'RANLIB', 'SWIG' ])
1825871Snate@binkert.org
1836121Snate@binkert.orguse_env = {}
1845871Snate@binkert.orgfor key,val in os.environ.iteritems():
1855871Snate@binkert.org    if key in use_vars or key.startswith("M5"):
1866003Snate@binkert.org        use_env[key] = val
1876655Snate@binkert.org
188955SN/Amain = Environment(ENV=use_env)
1895871Snate@binkert.orgmain.Decider('MD5-timestamp')
1905871Snate@binkert.orgmain.root = Dir(".")         # The current directory (where this file lives).
1915871Snate@binkert.orgmain.srcdir = Dir("src")     # The source directory
1925871Snate@binkert.org
193955SN/A# add useful python code PYTHONPATH so it can be used by subprocesses
1946121Snate@binkert.org# as well
1956121Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths)
1966121Snate@binkert.org
1971533SN/A########################################################################
1986655Snate@binkert.org#
1996655Snate@binkert.org# Mercurial Stuff.
2006655Snate@binkert.org#
2016655Snate@binkert.org# If the gem5 directory is a mercurial repository, we should do some
2025871Snate@binkert.org# extra things.
2035871Snate@binkert.org#
2045863Snate@binkert.org########################################################################
2055871Snate@binkert.org
2068878Ssteve.reinhardt@amd.comhgdir = main.root.Dir(".hg")
2075871Snate@binkert.org
2085871Snate@binkert.orgmercurial_style_message = """
2095871Snate@binkert.orgYou're missing the gem5 style hook, which automatically checks your code
2105863Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands.  This
2116121Snate@binkert.orgscript will now install the hook in your .hg/hgrc file.
2125863Snate@binkert.orgPress enter to continue, or ctrl-c to abort: """
2135871Snate@binkert.org
2148336Ssteve.reinhardt@amd.commercurial_style_hook = """
2158336Ssteve.reinhardt@amd.com# The following lines were automatically added by gem5/SConstruct
2168336Ssteve.reinhardt@amd.com# to provide the gem5 style-checking hooks
2178336Ssteve.reinhardt@amd.com[extensions]
2184678Snate@binkert.orgstyle = %s/util/style.py
2198336Ssteve.reinhardt@amd.com
2208336Ssteve.reinhardt@amd.com[hooks]
2218336Ssteve.reinhardt@amd.compretxncommit.style = python:style.check_style
2224678Snate@binkert.orgpre-qrefresh.style = python:style.check_style
2234678Snate@binkert.org# End of SConstruct additions
2244678Snate@binkert.org
2254678Snate@binkert.org""" % (main.root.abspath)
2267827Snate@binkert.org
2277827Snate@binkert.orgmercurial_lib_not_found = """
2288336Ssteve.reinhardt@amd.comMercurial libraries cannot be found, ignoring style hook.  If
2294678Snate@binkert.orgyou are a gem5 developer, please fix this and run the style
2308336Ssteve.reinhardt@amd.comhook. It is important.
2318336Ssteve.reinhardt@amd.com"""
2328336Ssteve.reinhardt@amd.com
2338336Ssteve.reinhardt@amd.com# Check for style hook and prompt for installation if it's not there.
2348336Ssteve.reinhardt@amd.com# Skip this if --ignore-style was specified, there's no .hg dir to
2358336Ssteve.reinhardt@amd.com# install a hook in, or there's no interactive terminal to prompt.
2365871Snate@binkert.orgif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty():
2375871Snate@binkert.org    style_hook = True
2388336Ssteve.reinhardt@amd.com    try:
2398336Ssteve.reinhardt@amd.com        from mercurial import ui
2408336Ssteve.reinhardt@amd.com        ui = ui.ui()
2418336Ssteve.reinhardt@amd.com        ui.readconfig(hgdir.File('hgrc').abspath)
2428336Ssteve.reinhardt@amd.com        style_hook = ui.config('hooks', 'pretxncommit.style', None) and \
2435871Snate@binkert.org                     ui.config('hooks', 'pre-qrefresh.style', None)
2448336Ssteve.reinhardt@amd.com    except ImportError:
2458336Ssteve.reinhardt@amd.com        print mercurial_lib_not_found
2468336Ssteve.reinhardt@amd.com
2478336Ssteve.reinhardt@amd.com    if not style_hook:
2488336Ssteve.reinhardt@amd.com        print mercurial_style_message,
2494678Snate@binkert.org        # continue unless user does ctrl-c/ctrl-d etc.
2505871Snate@binkert.org        try:
2514678Snate@binkert.org            raw_input()
2528336Ssteve.reinhardt@amd.com        except:
2538336Ssteve.reinhardt@amd.com            print "Input exception, exiting scons.\n"
2548336Ssteve.reinhardt@amd.com            sys.exit(1)
2558336Ssteve.reinhardt@amd.com        hgrc_path = '%s/.hg/hgrc' % main.root.abspath
2568336Ssteve.reinhardt@amd.com        print "Adding style hook to", hgrc_path, "\n"
2578336Ssteve.reinhardt@amd.com        try:
2588336Ssteve.reinhardt@amd.com            hgrc = open(hgrc_path, 'a')
2598336Ssteve.reinhardt@amd.com            hgrc.write(mercurial_style_hook)
2608336Ssteve.reinhardt@amd.com            hgrc.close()
2618336Ssteve.reinhardt@amd.com        except:
2628336Ssteve.reinhardt@amd.com            print "Error updating", hgrc_path
2638336Ssteve.reinhardt@amd.com            sys.exit(1)
2648336Ssteve.reinhardt@amd.com
2658336Ssteve.reinhardt@amd.com
2668336Ssteve.reinhardt@amd.com###################################################
2678336Ssteve.reinhardt@amd.com#
2688336Ssteve.reinhardt@amd.com# Figure out which configurations to set up based on the path(s) of
2695871Snate@binkert.org# the target(s).
2706121Snate@binkert.org#
271955SN/A###################################################
272955SN/A
2732632Sstever@eecs.umich.edu# Find default configuration & binary.
2742632Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug'))
275955SN/A
276955SN/A# helper function: find last occurrence of element in list
277955SN/Adef rfind(l, elt, offs = -1):
278955SN/A    for i in range(len(l)+offs, 0, -1):
2798878Ssteve.reinhardt@amd.com        if l[i] == elt:
280955SN/A            return i
2812632Sstever@eecs.umich.edu    raise ValueError, "element not found"
2822632Sstever@eecs.umich.edu
2832632Sstever@eecs.umich.edu# Take a list of paths (or SCons Nodes) and return a list with all
2842632Sstever@eecs.umich.edu# paths made absolute and ~-expanded.  Paths will be interpreted
2852632Sstever@eecs.umich.edu# relative to the launch directory unless a different root is provided
2862632Sstever@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()):
2872632Sstever@eecs.umich.edu    return [abspath(joinpath(root, expanduser(str(p))))
2888268Ssteve.reinhardt@amd.com            for p in path_list]
2898268Ssteve.reinhardt@amd.com
2908268Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the
2918268Ssteve.reinhardt@amd.com# directory below this will determine the build parameters.  For
2928268Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
2938268Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it
2948268Ssteve.reinhardt@amd.com# follow 'build' in the build path.
2952632Sstever@eecs.umich.edu
2962632Sstever@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents
2972632Sstever@eecs.umich.edu# in place rather than reassign the symbol to a new list, which
2982632Sstever@eecs.umich.edu# doesn't work (obviously!).
2998268Ssteve.reinhardt@amd.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)
3002632Sstever@eecs.umich.edu
3018268Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the
3028268Ssteve.reinhardt@amd.com# collected targets reference.
3038268Ssteve.reinhardt@amd.comvariant_paths = []
3048268Ssteve.reinhardt@amd.combuild_root = None
3053718Sstever@eecs.umich.edufor t in BUILD_TARGETS:
3062634Sstever@eecs.umich.edu    path_dirs = t.split('/')
3072634Sstever@eecs.umich.edu    try:
3085863Snate@binkert.org        build_top = rfind(path_dirs, 'build', -2)
3092638Sstever@eecs.umich.edu    except:
3108268Ssteve.reinhardt@amd.com        print "Error: no non-leaf 'build' dir found on target path", t
3112632Sstever@eecs.umich.edu        Exit(1)
3122632Sstever@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
3132632Sstever@eecs.umich.edu    if not build_root:
3142632Sstever@eecs.umich.edu        build_root = this_build_root
3152632Sstever@eecs.umich.edu    else:
3161858SN/A        if this_build_root != build_root:
3173716Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
3182638Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
3192638Sstever@eecs.umich.edu            Exit(1)
3202638Sstever@eecs.umich.edu    variant_path = joinpath('/',*path_dirs[:build_top+2])
3212638Sstever@eecs.umich.edu    if variant_path not in variant_paths:
3222638Sstever@eecs.umich.edu        variant_paths.append(variant_path)
3232638Sstever@eecs.umich.edu
3242638Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there)
3255863Snate@binkert.orgif not isdir(build_root):
3265863Snate@binkert.org    mkdir(build_root)
3275863Snate@binkert.orgmain['BUILDROOT'] = build_root
328955SN/A
3295341Sstever@gmail.comExport('main')
3305341Sstever@gmail.com
3315863Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign"))
3327756SAli.Saidi@ARM.com
3335341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up
3346121Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves
3354494Ssaidi@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
3366121Snate@binkert.org# (soft) links work better.
3371105SN/Amain.SetOption('duplicate', 'soft-copy')
3382667Sstever@eecs.umich.edu
3392667Sstever@eecs.umich.edu#
3402667Sstever@eecs.umich.edu# Set up global sticky variables... these are common to an entire build
3412667Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE)
3426121Snate@binkert.org#
3432667Sstever@eecs.umich.edu
3445341Sstever@gmail.comglobal_vars_file = joinpath(build_root, 'variables.global')
3455863Snate@binkert.org
3465341Sstever@gmail.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS)
3475341Sstever@gmail.com
3485341Sstever@gmail.comglobal_vars.AddVariables(
3498120Sgblack@eecs.umich.edu    ('CC', 'C compiler', environ.get('CC', main['CC'])),
3505341Sstever@gmail.com    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
3518120Sgblack@eecs.umich.edu    ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])),
3525341Sstever@gmail.com    ('BATCH', 'Use batch pool for build and tests', False),
3538120Sgblack@eecs.umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3546121Snate@binkert.org    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
3556121Snate@binkert.org    ('EXTRAS', 'Add extra directories to the compilation', '')
3565397Ssaidi@eecs.umich.edu    )
3575397Ssaidi@eecs.umich.edu
3587727SAli.Saidi@ARM.com# Update main environment with values from ARGUMENTS & global_vars_file
3598268Ssteve.reinhardt@amd.comglobal_vars.Update(main)
3606168Snate@binkert.orghelp_texts["global_vars"] += global_vars.GenerateHelpText(main)
3615341Sstever@gmail.com
3628120Sgblack@eecs.umich.edu# Save sticky variable settings back to current variables file
3638120Sgblack@eecs.umich.eduglobal_vars.Save(global_vars_file, main)
3648120Sgblack@eecs.umich.edu
3656814Sgblack@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're
3665863Snate@binkert.org# look for sources etc.  This list is exported as extras_dir_list.
3678120Sgblack@eecs.umich.edubase_dir = main.srcdir.abspath
3685341Sstever@gmail.comif main['EXTRAS']:
3695863Snate@binkert.org    extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':'))
3708268Ssteve.reinhardt@amd.comelse:
3716121Snate@binkert.org    extras_dir_list = []
3726121Snate@binkert.org
3738268Ssteve.reinhardt@amd.comExport('base_dir')
3745742Snate@binkert.orgExport('extras_dir_list')
3755742Snate@binkert.org
3765341Sstever@gmail.com# the ext directory should be on the #includes path
3775742Snate@binkert.orgmain.Append(CPPPATH=[Dir('ext')])
3785742Snate@binkert.org
3795341Sstever@gmail.comdef strip_build_path(path, env):
3806017Snate@binkert.org    path = str(path)
3816121Snate@binkert.org    variant_base = env['BUILDROOT'] + os.path.sep
3826017Snate@binkert.org    if path.startswith(variant_base):
3837816Ssteve.reinhardt@amd.com        path = path[len(variant_base):]
3847756SAli.Saidi@ARM.com    elif path.startswith('build/'):
3857756SAli.Saidi@ARM.com        path = path[6:]
3867756SAli.Saidi@ARM.com    return path
3877756SAli.Saidi@ARM.com
3887756SAli.Saidi@ARM.com# Generate a string of the form:
3897756SAli.Saidi@ARM.com#   common/path/prefix/src1, src2 -> tgt1, tgt2
3907756SAli.Saidi@ARM.com# to print while building.
3917756SAli.Saidi@ARM.comclass Transform(object):
3927816Ssteve.reinhardt@amd.com    # all specific color settings should be here and nowhere else
3937816Ssteve.reinhardt@amd.com    tool_color = termcap.Normal
3947816Ssteve.reinhardt@amd.com    pfx_color = termcap.Yellow
3957816Ssteve.reinhardt@amd.com    srcs_color = termcap.Yellow + termcap.Bold
3967816Ssteve.reinhardt@amd.com    arrow_color = termcap.Blue + termcap.Bold
3977816Ssteve.reinhardt@amd.com    tgts_color = termcap.Yellow + termcap.Bold
3987816Ssteve.reinhardt@amd.com
3997816Ssteve.reinhardt@amd.com    def __init__(self, tool, max_sources=99):
4007816Ssteve.reinhardt@amd.com        self.format = self.tool_color + (" [%8s] " % tool) \
4017816Ssteve.reinhardt@amd.com                      + self.pfx_color + "%s" \
4027756SAli.Saidi@ARM.com                      + self.srcs_color + "%s" \
4037816Ssteve.reinhardt@amd.com                      + self.arrow_color + " -> " \
4047816Ssteve.reinhardt@amd.com                      + self.tgts_color + "%s" \
4057816Ssteve.reinhardt@amd.com                      + termcap.Normal
4067816Ssteve.reinhardt@amd.com        self.max_sources = max_sources
4077816Ssteve.reinhardt@amd.com
4087816Ssteve.reinhardt@amd.com    def __call__(self, target, source, env, for_signature=None):
4097816Ssteve.reinhardt@amd.com        # truncate source list according to max_sources param
4107816Ssteve.reinhardt@amd.com        source = source[0:self.max_sources]
4117816Ssteve.reinhardt@amd.com        def strip(f):
4127816Ssteve.reinhardt@amd.com            return strip_build_path(str(f), env)
4137816Ssteve.reinhardt@amd.com        if len(source) > 0:
4147816Ssteve.reinhardt@amd.com            srcs = map(strip, source)
4157816Ssteve.reinhardt@amd.com        else:
4167816Ssteve.reinhardt@amd.com            srcs = ['']
4177816Ssteve.reinhardt@amd.com        tgts = map(strip, target)
4187816Ssteve.reinhardt@amd.com        # surprisingly, os.path.commonprefix is a dumb char-by-char string
4197816Ssteve.reinhardt@amd.com        # operation that has nothing to do with paths.
4207816Ssteve.reinhardt@amd.com        com_pfx = os.path.commonprefix(srcs + tgts)
4217816Ssteve.reinhardt@amd.com        com_pfx_len = len(com_pfx)
4227816Ssteve.reinhardt@amd.com        if com_pfx:
4237816Ssteve.reinhardt@amd.com            # do some cleanup and sanity checking on common prefix
4247816Ssteve.reinhardt@amd.com            if com_pfx[-1] == ".":
4257816Ssteve.reinhardt@amd.com                # prefix matches all but file extension: ok
4267816Ssteve.reinhardt@amd.com                # back up one to change 'foo.cc -> o' to 'foo.cc -> .o'
4277816Ssteve.reinhardt@amd.com                com_pfx = com_pfx[0:-1]
4287816Ssteve.reinhardt@amd.com            elif com_pfx[-1] == "/":
4297816Ssteve.reinhardt@amd.com                # common prefix is directory path: OK
4307816Ssteve.reinhardt@amd.com                pass
4317816Ssteve.reinhardt@amd.com            else:
4327816Ssteve.reinhardt@amd.com                src0_len = len(srcs[0])
4337816Ssteve.reinhardt@amd.com                tgt0_len = len(tgts[0])
4347816Ssteve.reinhardt@amd.com                if src0_len == com_pfx_len:
4357816Ssteve.reinhardt@amd.com                    # source is a substring of target, OK
4367816Ssteve.reinhardt@amd.com                    pass
4377816Ssteve.reinhardt@amd.com                elif tgt0_len == com_pfx_len:
4387816Ssteve.reinhardt@amd.com                    # target is a substring of source, need to back up to
4397816Ssteve.reinhardt@amd.com                    # avoid empty string on RHS of arrow
4407816Ssteve.reinhardt@amd.com                    sep_idx = com_pfx.rfind(".")
4417816Ssteve.reinhardt@amd.com                    if sep_idx != -1:
4427816Ssteve.reinhardt@amd.com                        com_pfx = com_pfx[0:sep_idx]
4437816Ssteve.reinhardt@amd.com                    else:
4447816Ssteve.reinhardt@amd.com                        com_pfx = ''
4457816Ssteve.reinhardt@amd.com                elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".":
4467816Ssteve.reinhardt@amd.com                    # still splitting at file extension: ok
4477816Ssteve.reinhardt@amd.com                    pass
4487816Ssteve.reinhardt@amd.com                else:
4497816Ssteve.reinhardt@amd.com                    # probably a fluke; ignore it
4507816Ssteve.reinhardt@amd.com                    com_pfx = ''
4517816Ssteve.reinhardt@amd.com        # recalculate length in case com_pfx was modified
4527816Ssteve.reinhardt@amd.com        com_pfx_len = len(com_pfx)
4537816Ssteve.reinhardt@amd.com        def fmt(files):
4547816Ssteve.reinhardt@amd.com            f = map(lambda s: s[com_pfx_len:], files)
4557816Ssteve.reinhardt@amd.com            return ', '.join(f)
4567816Ssteve.reinhardt@amd.com        return self.format % (com_pfx, fmt(srcs), fmt(tgts))
4577816Ssteve.reinhardt@amd.com
4587816Ssteve.reinhardt@amd.comExport('Transform')
4597816Ssteve.reinhardt@amd.com
4607816Ssteve.reinhardt@amd.com# enable the regression script to use the termcap
4617816Ssteve.reinhardt@amd.commain['TERMCAP'] = termcap
4627816Ssteve.reinhardt@amd.com
4637816Ssteve.reinhardt@amd.comif GetOption('verbose'):
4647756SAli.Saidi@ARM.com    def MakeAction(action, string, *args, **kwargs):
4658120Sgblack@eecs.umich.edu        return Action(action, *args, **kwargs)
4667756SAli.Saidi@ARM.comelse:
4677756SAli.Saidi@ARM.com    MakeAction = Action
4687756SAli.Saidi@ARM.com    main['CCCOMSTR']        = Transform("CC")
4697756SAli.Saidi@ARM.com    main['CXXCOMSTR']       = Transform("CXX")
4707816Ssteve.reinhardt@amd.com    main['ASCOMSTR']        = Transform("AS")
4717816Ssteve.reinhardt@amd.com    main['SWIGCOMSTR']      = Transform("SWIG")
4727816Ssteve.reinhardt@amd.com    main['ARCOMSTR']        = Transform("AR", 0)
4737816Ssteve.reinhardt@amd.com    main['LINKCOMSTR']      = Transform("LINK", 0)
4747816Ssteve.reinhardt@amd.com    main['RANLIBCOMSTR']    = Transform("RANLIB", 0)
4757816Ssteve.reinhardt@amd.com    main['M4COMSTR']        = Transform("M4")
4767816Ssteve.reinhardt@amd.com    main['SHCCCOMSTR']      = Transform("SHCC")
4777816Ssteve.reinhardt@amd.com    main['SHCXXCOMSTR']     = Transform("SHCXX")
4787816Ssteve.reinhardt@amd.comExport('MakeAction')
4797816Ssteve.reinhardt@amd.com
4807756SAli.Saidi@ARM.comCXX_version = readCommand([main['CXX'],'--version'], exception=False)
4817756SAli.Saidi@ARM.comCXX_V = readCommand([main['CXX'],'-V'], exception=False)
4826654Snate@binkert.org
4836654Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
4845871Snate@binkert.orgmain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
4856121Snate@binkert.orgmain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
4866121Snate@binkert.orgmain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0
4876121Snate@binkert.orgif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1:
4888737Skoansin.tan@gmail.com    print 'Error: How can we have two at the same time?'
4898737Skoansin.tan@gmail.com    Exit(1)
4903940Ssaidi@eecs.umich.edu
4913918Ssaidi@eecs.umich.edu# Set up default C++ compiler flags
4923918Ssaidi@eecs.umich.eduif main['GCC']:
4931858SN/A    main.Append(CCFLAGS=['-pipe'])
4946121Snate@binkert.org    main.Append(CCFLAGS=['-fno-strict-aliasing'])
4957739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
4967739Sgblack@eecs.umich.edu    # Read the GCC version to check for versions with bugs
4976143Snate@binkert.org    # Note CCVERSION doesn't work here because it is run with the CC
4987739Sgblack@eecs.umich.edu    # before we override it from the command line
4997618SAli.Saidi@arm.com    gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False)
5007618SAli.Saidi@arm.com    main['GCC_VERSION'] = gcc_version
5017618SAli.Saidi@arm.com    if not compareVersions(gcc_version, '4.4.1') or \
5027618SAli.Saidi@arm.com       not compareVersions(gcc_version, '4.4.2'):
5038614Sgblack@eecs.umich.edu        print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.'
5047618SAli.Saidi@arm.com        main.Append(CCFLAGS=['-fno-tree-vectorize'])
5057618SAli.Saidi@arm.com    if compareVersions(gcc_version, '4.6') >= 0:
5067618SAli.Saidi@arm.com        main.Append(CXXFLAGS=['-std=c++0x'])
5077739Sgblack@eecs.umich.eduelif main['ICC']:
5086121Snate@binkert.org    pass #Fix me... add warning flags once we clean up icc warnings
5093940Ssaidi@eecs.umich.eduelif main['SUNCC']:
5106121Snate@binkert.org    main.Append(CCFLAGS=['-Qoption ccfe'])
5117739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-features=gcc'])
5127739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-features=extensions'])
5137739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-library=stlport4'])
5147739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-xar'])
5157739Sgblack@eecs.umich.edu    #main.Append(CCFLAGS=['-instances=semiexplicit'])
5167739Sgblack@eecs.umich.eduelif main['CLANG']:
5178737Skoansin.tan@gmail.com    clang_version_re = re.compile(".* version (\d+\.\d+)")
5188737Skoansin.tan@gmail.com    clang_version_match = clang_version_re.match(CXX_version)
5198737Skoansin.tan@gmail.com    if (clang_version_match):
5208737Skoansin.tan@gmail.com        clang_version = clang_version_match.groups()[0]
5218737Skoansin.tan@gmail.com        if compareVersions(clang_version, "2.9") < 0:
5228737Skoansin.tan@gmail.com            print 'Error: clang version 2.9 or newer required.'
5238737Skoansin.tan@gmail.com            print '       Installed version:', clang_version
5248737Skoansin.tan@gmail.com            Exit(1)
5258737Skoansin.tan@gmail.com    else:
5268737Skoansin.tan@gmail.com        print 'Error: Unable to determine clang version.'
5278737Skoansin.tan@gmail.com        Exit(1)
5288737Skoansin.tan@gmail.com
5298737Skoansin.tan@gmail.com    main.Append(CCFLAGS=['-pipe'])
5308737Skoansin.tan@gmail.com    main.Append(CCFLAGS=['-fno-strict-aliasing'])
5318737Skoansin.tan@gmail.com    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
5328737Skoansin.tan@gmail.com    main.Append(CCFLAGS=['-Wno-tautological-compare'])
5338737Skoansin.tan@gmail.com    main.Append(CCFLAGS=['-Wno-self-assign'])
5348737Skoansin.tan@gmail.com    # Ruby makes frequent use of extraneous parantheses in the printing
5353918Ssaidi@eecs.umich.edu    # of if-statements
5363918Ssaidi@eecs.umich.edu    main.Append(CCFLAGS=['-Wno-parentheses'])
5373940Ssaidi@eecs.umich.edu
5383918Ssaidi@eecs.umich.edu    if compareVersions(clang_version, "3") >= 0:
5393918Ssaidi@eecs.umich.edu        main.Append(CXXFLAGS=['-std=c++0x'])
5406157Snate@binkert.orgelse:
5416157Snate@binkert.org    print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal,
5426157Snate@binkert.org    print "Don't know what compiler options to use for your compiler."
5436157Snate@binkert.org    print termcap.Yellow + '       compiler:' + termcap.Normal, main['CXX']
5445397Ssaidi@eecs.umich.edu    print termcap.Yellow + '       version:' + termcap.Normal,
5455397Ssaidi@eecs.umich.edu    if not CXX_version:
5466121Snate@binkert.org        print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\
5476121Snate@binkert.org               termcap.Normal
5486121Snate@binkert.org    else:
5496121Snate@binkert.org        print CXX_version.replace('\n', '<nl>')
5506121Snate@binkert.org    print "       If you're trying to use a compiler other than GCC, ICC, SunCC,"
5516121Snate@binkert.org    print "       or clang, there appears to be something wrong with your"
5525397Ssaidi@eecs.umich.edu    print "       environment."
5531851SN/A    print "       "
5541851SN/A    print "       If you are trying to use a compiler other than those listed"
5557739Sgblack@eecs.umich.edu    print "       above you will need to ease fix SConstruct and "
556955SN/A    print "       src/SConscript to support that compiler."
5573053Sstever@eecs.umich.edu    Exit(1)
5586121Snate@binkert.org
5593053Sstever@eecs.umich.edu# Set up common yacc/bison flags (needed for Ruby)
5603053Sstever@eecs.umich.edumain['YACCFLAGS'] = '-d'
5613053Sstever@eecs.umich.edumain['YACCHXXFILESUFFIX'] = '.hh'
5623053Sstever@eecs.umich.edu
5633053Sstever@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an
5646654Snate@binkert.org# extra 'qdo' every time we run scons.
5653053Sstever@eecs.umich.eduif main['BATCH']:
5664742Sstever@eecs.umich.edu    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
5674742Sstever@eecs.umich.edu    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
5683053Sstever@eecs.umich.edu    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
5693053Sstever@eecs.umich.edu    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
5703053Sstever@eecs.umich.edu    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
5713053Sstever@eecs.umich.edu
5726654Snate@binkert.orgif sys.platform == 'cygwin':
5733053Sstever@eecs.umich.edu    # cygwin has some header file issues...
5743053Sstever@eecs.umich.edu    main.Append(CCFLAGS=["-Wno-uninitialized"])
5753053Sstever@eecs.umich.edu
5763053Sstever@eecs.umich.edu# Check for SWIG
5772667Sstever@eecs.umich.eduif not main.has_key('SWIG'):
5784554Sbinkertn@umich.edu    print 'Error: SWIG utility not found.'
5796121Snate@binkert.org    print '       Please install (see http://www.swig.org) and retry.'
5802667Sstever@eecs.umich.edu    Exit(1)
5814554Sbinkertn@umich.edu
5824554Sbinkertn@umich.edu# Check for appropriate SWIG version
5834554Sbinkertn@umich.eduswig_version = readCommand(('swig', '-version'), exception='').split()
5846121Snate@binkert.org# First 3 words should be "SWIG Version x.y.z"
5854554Sbinkertn@umich.eduif len(swig_version) < 3 or \
5864554Sbinkertn@umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
5874554Sbinkertn@umich.edu    print 'Error determining SWIG version.'
5884781Snate@binkert.org    Exit(1)
5894554Sbinkertn@umich.edu
5904554Sbinkertn@umich.edumin_swig_version = '1.3.34'
5912667Sstever@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0:
5924554Sbinkertn@umich.edu    print 'Error: SWIG version', min_swig_version, 'or newer required.'
5934554Sbinkertn@umich.edu    print '       Installed version:', swig_version[2]
5944554Sbinkertn@umich.edu    Exit(1)
5954554Sbinkertn@umich.edu
5962667Sstever@eecs.umich.edu# Set up SWIG flags & scanner
5974554Sbinkertn@umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
5982667Sstever@eecs.umich.edumain.Append(SWIGFLAGS=swig_flags)
5994554Sbinkertn@umich.edu
6006121Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency
6012667Sstever@eecs.umich.edu# stuff for some reason
6025522Snate@binkert.orgscanners = []
6035522Snate@binkert.orgfor scanner in main['SCANNERS']:
6045522Snate@binkert.org    skeys = scanner.skeys
6055522Snate@binkert.org    if skeys == '.i':
6065522Snate@binkert.org        continue
6075522Snate@binkert.org
6085522Snate@binkert.org    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
6095522Snate@binkert.org        continue
6105522Snate@binkert.org
6115522Snate@binkert.org    scanners.append(scanner)
6125522Snate@binkert.org
6135522Snate@binkert.org# add the new swig scanner that we like better
6145522Snate@binkert.orgfrom SCons.Scanner import ClassicCPP as CPPScanner
6155522Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
6165522Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
6175522Snate@binkert.org
6185522Snate@binkert.org# replace the scanners list that has what we want
6195522Snate@binkert.orgmain['SCANNERS'] = scanners
6205522Snate@binkert.org
6215522Snate@binkert.org# Add a custom Check function to the Configure context so that we can
6225522Snate@binkert.org# figure out if the compiler adds leading underscores to global
6235522Snate@binkert.org# variables.  This is needed for the autogenerated asm files that we
6245522Snate@binkert.org# use for embedding the python code.
6255522Snate@binkert.orgdef CheckLeading(context):
6265522Snate@binkert.org    context.Message("Checking for leading underscore in global variables...")
6275522Snate@binkert.org    # 1) Define a global variable called x from asm so the C compiler
6282638Sstever@eecs.umich.edu    #    won't change the symbol at all.
6292638Sstever@eecs.umich.edu    # 2) Declare that variable.
6306121Snate@binkert.org    # 3) Use the variable
6313716Sstever@eecs.umich.edu    #
6325522Snate@binkert.org    # If the compiler prepends an underscore, this will successfully
6335522Snate@binkert.org    # link because the external symbol 'x' will be called '_x' which
6345522Snate@binkert.org    # was defined by the asm statement.  If the compiler does not
6355522Snate@binkert.org    # prepend an underscore, this will not successfully link because
6365522Snate@binkert.org    # '_x' will have been defined by assembly, while the C portion of
6375522Snate@binkert.org    # the code will be trying to use 'x'
6381858SN/A    ret = context.TryLink('''
6395227Ssaidi@eecs.umich.edu        asm(".globl _x; _x: .byte 0");
6405227Ssaidi@eecs.umich.edu        extern int x;
6415227Ssaidi@eecs.umich.edu        int main() { return x; }
6425227Ssaidi@eecs.umich.edu        ''', extension=".c")
6436654Snate@binkert.org    context.env.Append(LEADING_UNDERSCORE=ret)
6446654Snate@binkert.org    context.Result(ret)
6457769SAli.Saidi@ARM.com    return ret
6467769SAli.Saidi@ARM.com
6477769SAli.Saidi@ARM.com# Platform-specific configuration.  Note again that we assume that all
6487769SAli.Saidi@ARM.com# builds under a given build root run on the same host platform.
6495227Ssaidi@eecs.umich.educonf = Configure(main,
6505227Ssaidi@eecs.umich.edu                 conf_dir = joinpath(build_root, '.scons_config'),
6515227Ssaidi@eecs.umich.edu                 log_file = joinpath(build_root, 'scons_config.log'),
6525204Sstever@gmail.com                 custom_tests = { 'CheckLeading' : CheckLeading })
6535204Sstever@gmail.com
6545204Sstever@gmail.com# Check for leading underscores.  Don't really need to worry either
6555204Sstever@gmail.com# way so don't need to check the return code.
6565204Sstever@gmail.comconf.CheckLeading()
6575204Sstever@gmail.com
6585204Sstever@gmail.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin
6595204Sstever@gmail.comtry:
6605204Sstever@gmail.com    import platform
6615204Sstever@gmail.com    uname = platform.uname()
6625204Sstever@gmail.com    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
6635204Sstever@gmail.com        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
6645204Sstever@gmail.com            main.Append(CCFLAGS=['-arch', 'x86_64'])
6655204Sstever@gmail.com            main.Append(CFLAGS=['-arch', 'x86_64'])
6665204Sstever@gmail.com            main.Append(LINKFLAGS=['-arch', 'x86_64'])
6675204Sstever@gmail.com            main.Append(ASFLAGS=['-arch', 'x86_64'])
6685204Sstever@gmail.comexcept:
6696121Snate@binkert.org    pass
6705204Sstever@gmail.com
6713118Sstever@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure()
6723118Sstever@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is
6733118Sstever@eecs.umich.edu# present.  Unfortuantely this Null object always returns false,
6743118Sstever@eecs.umich.edu# breaking all our configuration checks.  We replace it with our own
6753118Sstever@eecs.umich.edu# more optimistic null object that returns True instead.
6765863Snate@binkert.orgif not conf:
6773118Sstever@eecs.umich.edu    def NullCheck(*args, **kwargs):
6785863Snate@binkert.org        return True
6793118Sstever@eecs.umich.edu
6807457Snate@binkert.org    class NullConf:
6817457Snate@binkert.org        def __init__(self, env):
6825863Snate@binkert.org            self.env = env
6835863Snate@binkert.org        def Finish(self):
6845863Snate@binkert.org            return self.env
6855863Snate@binkert.org        def __getattr__(self, mname):
6865863Snate@binkert.org            return NullCheck
6875863Snate@binkert.org
6885863Snate@binkert.org    conf = NullConf(main)
6896003Snate@binkert.org
6905863Snate@binkert.org# Find Python include and library directories for embedding the
6915863Snate@binkert.org# interpreter.  For consistency, we will use the same Python
6925863Snate@binkert.org# installation used to run scons (and thus this script).  If you want
6936120Snate@binkert.org# to link in an alternate version, see above for instructions on how
6945863Snate@binkert.org# to invoke scons with a different copy of the Python interpreter.
6955863Snate@binkert.orgfrom distutils import sysconfig
6965863Snate@binkert.org
6978655Sandreas.hansson@arm.compy_getvar = sysconfig.get_config_var
6988655Sandreas.hansson@arm.com
6998655Sandreas.hansson@arm.compy_debug = getattr(sys, 'pydebug', False)
7008655Sandreas.hansson@arm.compy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "")
7018655Sandreas.hansson@arm.com
7028655Sandreas.hansson@arm.compy_general_include = sysconfig.get_python_inc()
7038655Sandreas.hansson@arm.compy_platform_include = sysconfig.get_python_inc(plat_specific=True)
7048655Sandreas.hansson@arm.compy_includes = [ py_general_include ]
7056120Snate@binkert.orgif py_platform_include != py_general_include:
7065863Snate@binkert.org    py_includes.append(py_platform_include)
7076121Snate@binkert.org
7086121Snate@binkert.orgpy_lib_path = [ py_getvar('LIBDIR') ]
7095863Snate@binkert.org# add the prefix/lib/pythonX.Y/config dir, but only if there is no
7107727SAli.Saidi@ARM.com# shared library in prefix/lib/.
7117727SAli.Saidi@ARM.comif not py_getvar('Py_ENABLE_SHARED'):
7127727SAli.Saidi@ARM.com    py_lib_path.append(py_getvar('LIBPL'))
7137727SAli.Saidi@ARM.com
7147727SAli.Saidi@ARM.compy_libs = []
7157727SAli.Saidi@ARM.comfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
7165863Snate@binkert.org    if not lib.startswith('-l'):
7173118Sstever@eecs.umich.edu        # Python requires some special flags to link (e.g. -framework
7185863Snate@binkert.org        # common on OS X systems), assume appending preserves order
7193118Sstever@eecs.umich.edu        main.Append(LINKFLAGS=[lib])
7203118Sstever@eecs.umich.edu    else:
7215863Snate@binkert.org        lib = lib[2:]
7225863Snate@binkert.org        if lib not in py_libs:
7235863Snate@binkert.org            py_libs.append(lib)
7245863Snate@binkert.orgpy_libs.append(py_version)
7253118Sstever@eecs.umich.edu
7263483Ssaidi@eecs.umich.edumain.Append(CPPPATH=py_includes)
7273494Ssaidi@eecs.umich.edumain.Append(LIBPATH=py_lib_path)
7283494Ssaidi@eecs.umich.edu
7293483Ssaidi@eecs.umich.edu# Cache build files in the supplied directory.
7303483Ssaidi@eecs.umich.eduif main['M5_BUILD_CACHE']:
7313483Ssaidi@eecs.umich.edu    print 'Using build cache located at', main['M5_BUILD_CACHE']
7323053Sstever@eecs.umich.edu    CacheDir(main['M5_BUILD_CACHE'])
7333053Sstever@eecs.umich.edu
7343918Ssaidi@eecs.umich.edu
7353053Sstever@eecs.umich.edu# verify that this stuff works
7363053Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
7373053Sstever@eecs.umich.edu    print "Error: can't find Python.h header in", py_includes
7383053Sstever@eecs.umich.edu    Exit(1)
7393053Sstever@eecs.umich.edu
7407840Snate@binkert.orgfor lib in py_libs:
7417865Sgblack@eecs.umich.edu    if not conf.CheckLib(lib):
7427865Sgblack@eecs.umich.edu        print "Error: can't find library %s required by python" % lib
7437865Sgblack@eecs.umich.edu        Exit(1)
7447865Sgblack@eecs.umich.edu
7457865Sgblack@eecs.umich.edu# On Solaris you need to use libsocket for socket ops
7467840Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
7477840Snate@binkert.org   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
7487840Snate@binkert.org       print "Can't find library with socket calls (e.g. accept())"
7497840Snate@binkert.org       Exit(1)
7501858SN/A
7511858SN/A# Check for zlib.  If the check passes, libz will be automatically
7521858SN/A# added to the LIBS environment variable.
7531858SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
7541858SN/A    print 'Error: did not find needed zlib compression library '\
7551858SN/A          'and/or zlib.h header file.'
7565863Snate@binkert.org    print '       Please install zlib and try again.'
7575863Snate@binkert.org    Exit(1)
7585863Snate@binkert.org
7595863Snate@binkert.org# Check for librt.
7606121Snate@binkert.orghave_posix_clock = \
7611858SN/A    conf.CheckLibWithHeader(None, 'time.h', 'C',
7625863Snate@binkert.org                            'clock_nanosleep(0,0,NULL,NULL);') or \
7635863Snate@binkert.org    conf.CheckLibWithHeader('rt', 'time.h', 'C',
7645863Snate@binkert.org                            'clock_nanosleep(0,0,NULL,NULL);')
7655863Snate@binkert.org
7665863Snate@binkert.orgif conf.CheckLib('tcmalloc_minimal'):
7672139SN/A    have_tcmalloc = True
7684202Sbinkertn@umich.eduelse:
7694202Sbinkertn@umich.edu    have_tcmalloc = False
7702139SN/A    print termcap.Yellow + termcap.Bold + \
7716994Snate@binkert.org          "You can get a 12% performance improvement by installing tcmalloc "\
7726994Snate@binkert.org          "(google-perftools package on Ubuntu or RedHat)." + termcap.Normal
7736994Snate@binkert.org
7746994Snate@binkert.orgif not have_posix_clock:
7756994Snate@binkert.org    print "Can't find library for POSIX clocks."
7766994Snate@binkert.org
7776994Snate@binkert.org# Check for <fenv.h> (C99 FP environment control)
7786994Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>')
7796994Snate@binkert.orgif not have_fenv:
7806994Snate@binkert.org    print "Warning: Header file <fenv.h> not found."
7816994Snate@binkert.org    print "         This host has no IEEE FP rounding mode control."
7826994Snate@binkert.org
7836994Snate@binkert.org######################################################################
7846994Snate@binkert.org#
7856994Snate@binkert.org# Finish the configuration
7866994Snate@binkert.org#
7876994Snate@binkert.orgmain = conf.Finish()
7886994Snate@binkert.org
7896994Snate@binkert.org######################################################################
7906994Snate@binkert.org#
7916994Snate@binkert.org# Collect all non-global variables
7926994Snate@binkert.org#
7936994Snate@binkert.org
7946994Snate@binkert.org# Define the universe of supported ISAs
7956994Snate@binkert.orgall_isa_list = [ ]
7966994Snate@binkert.orgExport('all_isa_list')
7976994Snate@binkert.org
7986994Snate@binkert.orgclass CpuModel(object):
7992155SN/A    '''The CpuModel class encapsulates everything the ISA parser needs to
8005863Snate@binkert.org    know about a particular CPU model.'''
8011869SN/A
8021869SN/A    # Dict of available CPU model objects.  Accessible as CpuModel.dict.
8035863Snate@binkert.org    dict = {}
8045863Snate@binkert.org    list = []
8054202Sbinkertn@umich.edu    defaults = []
8066108Snate@binkert.org
8076108Snate@binkert.org    # Constructor.  Automatically adds models to CpuModel.dict.
8086108Snate@binkert.org    def __init__(self, name, filename, includes, strings, default=False):
8096108Snate@binkert.org        self.name = name           # name of model
8104202Sbinkertn@umich.edu        self.filename = filename   # filename for output exec code
8115863Snate@binkert.org        self.includes = includes   # include files needed in exec file
8128474Sgblack@eecs.umich.edu        # The 'strings' dict holds all the per-CPU symbols we can
8138474Sgblack@eecs.umich.edu        # substitute into templates etc.
8145742Snate@binkert.org        self.strings = strings
8158268Ssteve.reinhardt@amd.com
8168268Ssteve.reinhardt@amd.com        # This cpu is enabled by default
8178268Ssteve.reinhardt@amd.com        self.default = default
8185742Snate@binkert.org
8195341Sstever@gmail.com        # Add self to dict
8208474Sgblack@eecs.umich.edu        if name in CpuModel.dict:
8218474Sgblack@eecs.umich.edu            raise AttributeError, "CpuModel '%s' already registered" % name
8225342Sstever@gmail.com        CpuModel.dict[name] = self
8234202Sbinkertn@umich.edu        CpuModel.list.append(name)
8244202Sbinkertn@umich.edu
8254202Sbinkertn@umich.eduExport('CpuModel')
8265863Snate@binkert.org
8275863Snate@binkert.org# Sticky variables get saved in the variables file so they persist from
8286994Snate@binkert.org# one invocation to the next (unless overridden, in which case the new
8296994Snate@binkert.org# value becomes sticky).
8306994Snate@binkert.orgsticky_vars = Variables(args=ARGUMENTS)
8315863Snate@binkert.orgExport('sticky_vars')
8328152Ssteve.reinhardt@amd.com
8338878Ssteve.reinhardt@amd.com# Sticky variables that should be exported
8345863Snate@binkert.orgexport_vars = []
8355863Snate@binkert.orgExport('export_vars')
8365863Snate@binkert.org
8375863Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the
8385863Snate@binkert.org# above variables
8395863Snate@binkert.orgif not GetOption('verbose'):
8405863Snate@binkert.org    print "Reading SConsopts"
8415863Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list:
8425863Snate@binkert.org    if not isdir(bdir):
8435863Snate@binkert.org        print "Error: directory '%s' does not exist" % bdir
8447840Snate@binkert.org        Exit(1)
8455863Snate@binkert.org    for root, dirs, files in os.walk(bdir):
8465863Snate@binkert.org        if 'SConsopts' in files:
8475952Ssaidi@eecs.umich.edu            if GetOption('verbose'):
8481869SN/A                print "Reading", joinpath(root, 'SConsopts')
8491858SN/A            SConscript(joinpath(root, 'SConsopts'))
8505863Snate@binkert.org
8518805Sgblack@eecs.umich.eduall_isa_list.sort()
8528805Sgblack@eecs.umich.edu
8538805Sgblack@eecs.umich.edusticky_vars.AddVariables(
8541858SN/A    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
855955SN/A    ListVariable('CPU_MODELS', 'CPU models',
856955SN/A                 sorted(n for n,m in CpuModel.dict.iteritems() if m.default),
8571869SN/A                 sorted(CpuModel.list)),
8581869SN/A    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
8591869SN/A                 False),
8601869SN/A    BoolVariable('SS_COMPATIBLE_FP',
8611869SN/A                 'Make floating-point results compatible with SimpleScalar',
8625863Snate@binkert.org                 False),
8635863Snate@binkert.org    BoolVariable('USE_SSE2',
8645863Snate@binkert.org                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
8651869SN/A                 False),
8665863Snate@binkert.org    BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
8671869SN/A    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
8685863Snate@binkert.org    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
8691869SN/A    )
8701869SN/A
8711869SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript).
8721869SN/Aexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP',
8738483Sgblack@eecs.umich.edu                'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK' ]
8741869SN/A
8751869SN/A###################################################
8761869SN/A#
8771869SN/A# Define a SCons builder for configuration flag headers.
8785863Snate@binkert.org#
8795863Snate@binkert.org###################################################
8801869SN/A
8815863Snate@binkert.org# This function generates a config header file that #defines the
8825863Snate@binkert.org# variable symbol to the current variable setting (0 or 1).  The source
8833356Sbinkertn@umich.edu# operands are the name of the variable and a Value node containing the
8843356Sbinkertn@umich.edu# value of the variable.
8853356Sbinkertn@umich.edudef build_config_file(target, source, env):
8863356Sbinkertn@umich.edu    (variable, value) = [s.get_contents() for s in source]
8873356Sbinkertn@umich.edu    f = file(str(target[0]), 'w')
8884781Snate@binkert.org    print >> f, '#define', variable, value
8895863Snate@binkert.org    f.close()
8905863Snate@binkert.org    return None
8911869SN/A
8921869SN/A# Combine the two functions into a scons Action object.
8931869SN/Aconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2))
8946121Snate@binkert.org
8951869SN/A# The emitter munges the source & target node lists to reflect what
8962638Sstever@eecs.umich.edu# we're really doing.
8976121Snate@binkert.orgdef config_emitter(target, source, env):
8986121Snate@binkert.org    # extract variable name from Builder arg
8992638Sstever@eecs.umich.edu    variable = str(target[0])
9005749Scws3k@cs.virginia.edu    # True target is config header file
9016121Snate@binkert.org    target = joinpath('config', variable.lower() + '.hh')
9026121Snate@binkert.org    val = env[variable]
9035749Scws3k@cs.virginia.edu    if isinstance(val, bool):
9041869SN/A        # Force value to 0/1
9051869SN/A        val = int(val)
9063546Sgblack@eecs.umich.edu    elif isinstance(val, str):
9073546Sgblack@eecs.umich.edu        val = '"' + val + '"'
9083546Sgblack@eecs.umich.edu
9093546Sgblack@eecs.umich.edu    # Sources are variable name & value (packaged in SCons Value nodes)
9106121Snate@binkert.org    return ([target], [Value(variable), Value(val)])
9115863Snate@binkert.org
9123546Sgblack@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action)
9133546Sgblack@eecs.umich.edu
9143546Sgblack@eecs.umich.edumain.Append(BUILDERS = { 'ConfigFile' : config_builder })
9153546Sgblack@eecs.umich.edu
9164781Snate@binkert.org# libelf build is shared across all configs in the build root.
9174781Snate@binkert.orgmain.SConscript('ext/libelf/SConscript',
9186658Snate@binkert.org                variant_dir = joinpath(build_root, 'libelf'))
9196658Snate@binkert.org
9204781Snate@binkert.org# gzstream build is shared across all configs in the build root.
9213546Sgblack@eecs.umich.edumain.SConscript('ext/gzstream/SConscript',
9223546Sgblack@eecs.umich.edu                variant_dir = joinpath(build_root, 'gzstream'))
9233546Sgblack@eecs.umich.edu
9243546Sgblack@eecs.umich.edu###################################################
9257756SAli.Saidi@ARM.com#
9267816Ssteve.reinhardt@amd.com# This function is used to set up a directory with switching headers
9273546Sgblack@eecs.umich.edu#
9283546Sgblack@eecs.umich.edu###################################################
9293546Sgblack@eecs.umich.edu
9303546Sgblack@eecs.umich.edumain['ALL_ISA_LIST'] = all_isa_list
9314202Sbinkertn@umich.edudef make_switching_dir(dname, switch_headers, env):
9323546Sgblack@eecs.umich.edu    # Generate the header.  target[0] is the full path of the output
9333546Sgblack@eecs.umich.edu    # header to generate.  'source' is a dummy variable, since we get the
9343546Sgblack@eecs.umich.edu    # list of ISAs from env['ALL_ISA_LIST'].
935955SN/A    def gen_switch_hdr(target, source, env):
936955SN/A        fname = str(target[0])
937955SN/A        f = open(fname, 'w')
938955SN/A        isa = env['TARGET_ISA'].lower()
9395863Snate@binkert.org        print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
9405863Snate@binkert.org        f.close()
9415343Sstever@gmail.com
9425343Sstever@gmail.com    # Build SCons Action object. 'varlist' specifies env vars that this
9436121Snate@binkert.org    # action depends on; when env['ALL_ISA_LIST'] changes these actions
9445863Snate@binkert.org    # should get re-executed.
9454773Snate@binkert.org    switch_hdr_action = MakeAction(gen_switch_hdr,
9465863Snate@binkert.org                          Transform("GENERATE"), varlist=['ALL_ISA_LIST'])
9472632Sstever@eecs.umich.edu
9485863Snate@binkert.org    # Instantiate actions for each header
9492023SN/A    for hdr in switch_headers:
9505863Snate@binkert.org        env.Command(hdr, [], switch_hdr_action)
9515863Snate@binkert.orgExport('make_switching_dir')
9525863Snate@binkert.org
9535863Snate@binkert.org###################################################
9545863Snate@binkert.org#
9555863Snate@binkert.org# Define build environments for selected configurations.
9565863Snate@binkert.org#
9575863Snate@binkert.org###################################################
9585863Snate@binkert.org
9592632Sstever@eecs.umich.edufor variant_path in variant_paths:
9605863Snate@binkert.org    print "Building in", variant_path
9612023SN/A
9622632Sstever@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
9635863Snate@binkert.org    env = main.Clone()
9645342Sstever@gmail.com    env['BUILDDIR'] = variant_path
9655863Snate@binkert.org
9662632Sstever@eecs.umich.edu    # variant_dir is the tail component of build path, and is used to
9675863Snate@binkert.org    # determine the build parameters (e.g., 'ALPHA_SE')
9685863Snate@binkert.org    (build_root, variant_dir) = splitpath(variant_path)
9698267Ssteve.reinhardt@amd.com
9708120Sgblack@eecs.umich.edu    # Set env variables according to the build directory config.
9718267Ssteve.reinhardt@amd.com    sticky_vars.files = []
9728267Ssteve.reinhardt@amd.com    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
9738267Ssteve.reinhardt@amd.com    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
9748267Ssteve.reinhardt@amd.com    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
9758267Ssteve.reinhardt@amd.com    current_vars_file = joinpath(build_root, 'variables', variant_dir)
9768267Ssteve.reinhardt@amd.com    if isfile(current_vars_file):
9778267Ssteve.reinhardt@amd.com        sticky_vars.files.append(current_vars_file)
9788267Ssteve.reinhardt@amd.com        print "Using saved variables file %s" % current_vars_file
9798267Ssteve.reinhardt@amd.com    else:
9805863Snate@binkert.org        # Build dir-specific variables file doesn't exist.
9815863Snate@binkert.org
9825863Snate@binkert.org        # Make sure the directory is there so we can create it later
9832632Sstever@eecs.umich.edu        opt_dir = dirname(current_vars_file)
9848267Ssteve.reinhardt@amd.com        if not isdir(opt_dir):
9858267Ssteve.reinhardt@amd.com            mkdir(opt_dir)
9868267Ssteve.reinhardt@amd.com
9872632Sstever@eecs.umich.edu        # Get default build variables from source tree.  Variables are
9881888SN/A        # normally determined by name of $VARIANT_DIR, but can be
9895863Snate@binkert.org        # overridden by '--default=' arg on command line.
9905863Snate@binkert.org        default = GetOption('default')
9911858SN/A        opts_dir = joinpath(main.root.abspath, 'build_opts')
9928120Sgblack@eecs.umich.edu        if default:
9938120Sgblack@eecs.umich.edu            default_vars_files = [joinpath(build_root, 'variables', default),
9947756SAli.Saidi@ARM.com                                  joinpath(opts_dir, default)]
9952598SN/A        else:
9965863Snate@binkert.org            default_vars_files = [joinpath(opts_dir, variant_dir)]
9971858SN/A        existing_files = filter(isfile, default_vars_files)
9981858SN/A        if existing_files:
9991858SN/A            default_vars_file = existing_files[0]
10005863Snate@binkert.org            sticky_vars.files.append(default_vars_file)
10011858SN/A            print "Variables file %s not found,\n  using defaults in %s" \
10021858SN/A                  % (current_vars_file, default_vars_file)
10031858SN/A        else:
10045863Snate@binkert.org            print "Error: cannot find variables file %s or " \
10051871SN/A                  "default file(s) %s" \
10061858SN/A                  % (current_vars_file, ' or '.join(default_vars_files))
10071858SN/A            Exit(1)
10081858SN/A
10091858SN/A    # Apply current variable settings to env
10105863Snate@binkert.org    sticky_vars.Update(env)
10115863Snate@binkert.org
10121869SN/A    help_texts["local_vars"] += \
10131965SN/A        "Build variables for %s:\n" % variant_dir \
10147739Sgblack@eecs.umich.edu                 + sticky_vars.GenerateHelpText(env)
10151965SN/A
10162761Sstever@eecs.umich.edu    # Process variable settings.
10175863Snate@binkert.org
10181869SN/A    if not have_fenv and env['USE_FENV']:
10195863Snate@binkert.org        print "Warning: <fenv.h> not available; " \
10202667Sstever@eecs.umich.edu              "forcing USE_FENV to False in", variant_dir + "."
10211869SN/A        env['USE_FENV'] = False
10221869SN/A
10232929Sktlim@umich.edu    if not env['USE_FENV']:
10242929Sktlim@umich.edu        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
10255863Snate@binkert.org        print "         FP results may deviate slightly from other platforms."
10262929Sktlim@umich.edu
1027955SN/A    if env['EFENCE']:
10288120Sgblack@eecs.umich.edu        env.Append(LIBS=['efence'])
10298120Sgblack@eecs.umich.edu
10308120Sgblack@eecs.umich.edu    # Save sticky variable settings back to current variables file
10318120Sgblack@eecs.umich.edu    sticky_vars.Save(current_vars_file, env)
10328120Sgblack@eecs.umich.edu
10338120Sgblack@eecs.umich.edu    if env['USE_SSE2']:
10348120Sgblack@eecs.umich.edu        env.Append(CCFLAGS=['-msse2'])
10358120Sgblack@eecs.umich.edu
10368120Sgblack@eecs.umich.edu    if have_tcmalloc:
10378120Sgblack@eecs.umich.edu        env.Append(LIBS=['tcmalloc_minimal'])
10388120Sgblack@eecs.umich.edu
10398120Sgblack@eecs.umich.edu    # The src/SConscript file sets up the build rules in 'env' according
1040    # to the configured variables.  It returns a list of environments,
1041    # one for each variant build (debug, opt, etc.)
1042    envList = SConscript('src/SConscript', variant_dir = variant_path,
1043                         exports = 'env')
1044
1045    # Set up the regression tests for each build.
1046    for e in envList:
1047        SConscript('tests/SConscript',
1048                   variant_dir = joinpath(variant_path, 'tests', e.Label),
1049                   exports = { 'env' : e }, duplicate = False)
1050
1051# base help text
1052Help('''
1053Usage: scons [scons options] [build variables] [target(s)]
1054
1055Extra scons options:
1056%(options)s
1057
1058Global build variables:
1059%(global_vars)s
1060
1061%(local_vars)s
1062''' % help_texts)
1063