SConstruct revision 10158
11689SN/A# -*- mode:python -*-
22329SN/A
31689SN/A# Copyright (c) 2013 ARM Limited
41689SN/A# All rights reserved.
51689SN/A#
61689SN/A# The license below extends only to copyright in the software and shall
71689SN/A# not be construed as granting a license to any other intellectual
81689SN/A# property including but not limited to intellectual property relating
91689SN/A# to a hardware implementation of the functionality of the software
101689SN/A# licensed hereunder.  You may use the software subject to the license
111689SN/A# terms below provided that you ensure that this notice is replicated
121689SN/A# unmodified and in its entirety in all distributions of the software,
131689SN/A# modified or unmodified, in source code or in binary form.
141689SN/A#
151689SN/A# Copyright (c) 2011 Advanced Micro Devices, Inc.
161689SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company
171689SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
181689SN/A# All rights reserved.
191689SN/A#
201689SN/A# Redistribution and use in source and binary forms, with or without
211689SN/A# modification, are permitted provided that the following conditions are
221689SN/A# met: redistributions of source code must retain the above copyright
231689SN/A# notice, this list of conditions and the following disclaimer;
241689SN/A# redistributions in binary form must reproduce the above copyright
251689SN/A# notice, this list of conditions and the following disclaimer in the
261689SN/A# documentation and/or other materials provided with the distribution;
272665Ssaidi@eecs.umich.edu# neither the name of the copyright holders nor the names of its
282665Ssaidi@eecs.umich.edu# contributors may be used to endorse or promote products derived from
292935Sksewell@umich.edu# this software without specific prior written permission.
301689SN/A#
311689SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
321060SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
331060SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
343773Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
353773Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
361858SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
371717SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
381060SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
391061SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
404329Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
414329Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
424329Sktlim@umich.edu#
432292SN/A# Authors: Steve Reinhardt
442292SN/A#          Nathan Binkert
452292SN/A
462292SN/A###################################################
473788Sgblack@eecs.umich.edu#
483798Sgblack@eecs.umich.edu# SCons top-level build description (SConstruct) file.
492361SN/A#
502361SN/A# While in this directory ('gem5'), just type 'scons' to build the default
511060SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
522292SN/A# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for
532292SN/A# the optimized full-system version).
542292SN/A#
552292SN/A# You can build gem5 in a different directory as long as there is a
562292SN/A# 'build/<CONFIG>' somewhere along the target path.  The build system
572292SN/A# expects that all configs under the same build directory are being
582292SN/A# built for the same host system.
592292SN/A#
602292SN/A# Examples:
612292SN/A#
622292SN/A#   The following two commands are equivalent.  The '-u' option tells
632301SN/A#   scons to search up the directory tree for this SConstruct file.
642292SN/A#   % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug
652292SN/A#   % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug
662292SN/A#
672292SN/A#   The following two commands are equivalent and demonstrate building
682292SN/A#   in a directory outside of the source tree.  The '-C' option tells
692292SN/A#   scons to chdir to the specified directory to find this SConstruct
702292SN/A#   file.
712292SN/A#   % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug
722292SN/A#   % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug
732292SN/A#
742292SN/A# You can use 'scons -H' to print scons options.  If you're in this
752292SN/A# 'gem5' directory (or use -u or -C to tell scons where to find this
762292SN/A# file), you can use 'scons -h' to print all the gem5-specific build
772292SN/A# options as well.
782292SN/A#
792292SN/A###################################################
802292SN/A
811060SN/A# Check for recent-enough Python and SCons versions.
821060SN/Atry:
831061SN/A    # Really old versions of scons only take two options for the
841060SN/A    # function, so check once without the revision and once with the
852292SN/A    # revision, the first instance will fail for stuff other than
861062SN/A    # 0.98, and the second will fail for 0.98.0
871062SN/A    EnsureSConsVersion(0, 98)
882301SN/A    EnsureSConsVersion(0, 98, 1)
891062SN/Aexcept SystemExit, e:
901062SN/A    print """
911062SN/AFor more details, see:
922301SN/A    http://gem5.org/Dependencies
931062SN/A"""
941062SN/A    raise
951062SN/A
962301SN/A# We ensure the python version early because because python-config
971062SN/A# requires python 2.5
981062SN/Atry:
992301SN/A    EnsurePythonVersion(2, 5)
1002301SN/Aexcept SystemExit, e:
1012301SN/A    print """
1022301SN/AYou can use a non-default installation of the Python interpreter by
1032292SN/Arearranging your PATH so that scons finds the non-default 'python' and
1042301SN/A'python-config' first.
1052292SN/A
1062292SN/AFor more details, see:
1071062SN/A    http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation
1082301SN/A"""
1091062SN/A    raise
1101062SN/A
1111062SN/A# Global Python includes
1122301SN/Aimport os
1131062SN/Aimport re
1141062SN/Aimport subprocess
1151062SN/Aimport sys
1162301SN/A
1171062SN/Afrom os import mkdir, environ
1181062SN/Afrom os.path import abspath, basename, dirname, expanduser, normpath
1191062SN/Afrom os.path import exists,  isdir, isfile
1202301SN/Afrom os.path import join as joinpath, split as splitpath
1212292SN/A
1221062SN/A# SCons includes
1231062SN/Aimport SCons
1242301SN/Aimport SCons.Node
1252292SN/A
1261062SN/Aextra_python_paths = [
1272292SN/A    Dir('src/python').srcnode().abspath, # gem5 includes
1282301SN/A    Dir('ext/ply').srcnode().abspath, # ply is used by several files
1292292SN/A    ]
1302292SN/A
1311062SN/Asys.path[1:1] = extra_python_paths
1322301SN/A
1331062SN/Afrom m5.util import compareVersions, readCommand
1341062SN/Afrom m5.util.terminal import get_termcap
1351062SN/A
1362301SN/Ahelp_texts = {
1371062SN/A    "options" : "",
1381062SN/A    "global_vars" : "",
1391062SN/A    "local_vars" : ""
1402301SN/A}
1411062SN/A
1421062SN/AExport("help_texts")
1431062SN/A
1442301SN/A
1451062SN/A# There's a bug in scons in that (1) by default, the help texts from
1461062SN/A# AddOption() are supposed to be displayed when you type 'scons -h'
1471062SN/A# and (2) you can override the help displayed by 'scons -h' using the
1482301SN/A# Help() function, but these two features are incompatible: once
1491062SN/A# you've overridden the help text using Help(), there's no way to get
1501062SN/A# at the help texts from AddOptions.  See:
1512301SN/A#     http://scons.tigris.org/issues/show_bug.cgi?id=2356
1522301SN/A#     http://scons.tigris.org/issues/show_bug.cgi?id=2611
1532301SN/A# This hack lets us extract the help text from AddOptions and
1542301SN/A# re-inject it via Help().  Ideally someday this bug will be fixed and
1552301SN/A# we can just use AddOption directly.
1562301SN/Adef AddLocalOption(*args, **kwargs):
1572301SN/A    col_width = 30
1582301SN/A
1592301SN/A    help = "  " + ", ".join(args)
1602301SN/A    if "help" in kwargs:
1612307SN/A        length = len(help)
1622307SN/A        if length >= col_width:
1632307SN/A            help += "\n" + " " * col_width
1642307SN/A        else:
1652307SN/A            help += " " * (col_width - length)
1661062SN/A        help += kwargs["help"]
1671062SN/A    help_texts["options"] += help + "\n"
1681062SN/A
1691062SN/A    AddOption(*args, **kwargs)
1702292SN/A
1711060SN/AAddLocalOption('--colors', dest='use_colors', action='store_true',
1721060SN/A               help="Add color to abbreviated scons output")
1731060SN/AAddLocalOption('--no-colors', dest='use_colors', action='store_false',
1741060SN/A               help="Don't add color to abbreviated scons output")
1751060SN/AAddLocalOption('--default', dest='default', type='string', action='store',
1761060SN/A               help='Override which build_opts file to use for defaults')
1771060SN/AAddLocalOption('--ignore-style', dest='ignore_style', action='store_true',
1781060SN/A               help='Disable style checking hooks')
1791060SN/AAddLocalOption('--no-lto', dest='no_lto', action='store_true',
1801060SN/A               help='Disable Link-Time Optimization for fast')
1811060SN/AAddLocalOption('--update-ref', dest='update_ref', action='store_true',
1821060SN/A               help='Update test reference outputs')
1831060SN/AAddLocalOption('--verbose', dest='verbose', action='store_true',
1841061SN/A               help='Print full tool command lines')
1851060SN/A
1862292SN/Atermcap = get_termcap(GetOption('use_colors'))
1871060SN/A
1881060SN/A########################################################################
1891060SN/A#
1901060SN/A# Set up the main build environment.
1911060SN/A#
1921060SN/A########################################################################
1931060SN/A
1941061SN/A# export TERM so that clang reports errors in color
1951060SN/Ause_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH',
1962292SN/A                 'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PROTOC',
1971060SN/A                 'PYTHONPATH', 'RANLIB', 'SWIG', 'TERM' ])
1981060SN/A
1991060SN/Ause_prefixes = [
2001060SN/A    "M5",           # M5 configuration (e.g., path to kernels)
2011060SN/A    "DISTCC_",      # distcc (distributed compiler wrapper) configuration
2021060SN/A    "CCACHE_",      # ccache (caching compiler wrapper) configuration
2031060SN/A    "CCC_",         # clang static analyzer configuration
2041061SN/A    ]
2051060SN/A
2062292SN/Ause_env = {}
2071060SN/Afor key,val in os.environ.iteritems():
2082329SN/A    if key in use_vars or \
2092292SN/A            any([key.startswith(prefix) for prefix in use_prefixes]):
2102292SN/A        use_env[key] = val
2112292SN/A
2122292SN/Amain = Environment(ENV=use_env)
2132292SN/Amain.Decider('MD5-timestamp')
2142292SN/Amain.root = Dir(".")         # The current directory (where this file lives).
2151060SN/Amain.srcdir = Dir("src")     # The source directory
2161060SN/A
2172292SN/Amain_dict_keys = main.Dictionary().keys()
2182292SN/A
2192980Sgblack@eecs.umich.edu# Check that we have a C/C++ compiler
2202292SN/Aif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys):
2212292SN/A    print "No C++ compiler installed (package g++ on Ubuntu and RedHat)"
2222292SN/A    Exit(1)
2232292SN/A
2242292SN/A# Check that swig is present
2251061SN/Aif not 'SWIG' in main_dict_keys:
2261060SN/A    print "swig is not installed (package swig on Ubuntu and RedHat)"
2272292SN/A    Exit(1)
2281060SN/A
2292292SN/A# add useful python code PYTHONPATH so it can be used by subprocesses
2302292SN/A# as well
2311060SN/Amain.AppendENVPath('PYTHONPATH', extra_python_paths)
2321060SN/A
2331060SN/A########################################################################
2341061SN/A#
2351060SN/A# Mercurial Stuff.
2362292SN/A#
2371060SN/A# If the gem5 directory is a mercurial repository, we should do some
2382292SN/A# extra things.
2392292SN/A#
2401060SN/A########################################################################
2412292SN/A
2422292SN/Ahgdir = main.root.Dir(".hg")
2432292SN/A
2442292SN/Amercurial_style_message = """
2452292SN/AYou're missing the gem5 style hook, which automatically checks your code
2461060SN/Aagainst the gem5 style rules on hg commit and qrefresh commands.  This
2471060SN/Ascript will now install the hook in your .hg/hgrc file.
2481061SN/APress enter to continue, or ctrl-c to abort: """
2492863Sktlim@umich.edu
2502843Sktlim@umich.edumercurial_style_hook = """
2511060SN/A# The following lines were automatically added by gem5/SConstruct
2522348SN/A# to provide the gem5 style-checking hooks
2532843Sktlim@umich.edu[extensions]
2542863Sktlim@umich.edustyle = %s/util/style.py
2552316SN/A
2561060SN/A[hooks]
2572316SN/Apretxncommit.style = python:style.check_style
2582316SN/Apre-qrefresh.style = python:style.check_style
2592843Sktlim@umich.edu# End of SConstruct additions
2602316SN/A
2612348SN/A""" % (main.root.abspath)
2622307SN/A
2632980Sgblack@eecs.umich.edumercurial_lib_not_found = """
2642980Sgblack@eecs.umich.eduMercurial libraries cannot be found, ignoring style hook.  If
2652307SN/Ayou are a gem5 developer, please fix this and run the style
2662307SN/Ahook. It is important.
2672307SN/A"""
2682307SN/A
2692307SN/A# Check for style hook and prompt for installation if it's not there.
2702307SN/A# Skip this if --ignore-style was specified, there's no .hg dir to
2712307SN/A# install a hook in, or there's no interactive terminal to prompt.
2722307SN/Aif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty():
2732307SN/A    style_hook = True
2742307SN/A    try:
2752307SN/A        from mercurial import ui
2762307SN/A        ui = ui.ui()
2772307SN/A        ui.readconfig(hgdir.File('hgrc').abspath)
2782307SN/A        style_hook = ui.config('hooks', 'pretxncommit.style', None) and \
2792361SN/A                     ui.config('hooks', 'pre-qrefresh.style', None)
2802361SN/A    except ImportError:
2812361SN/A        print mercurial_lib_not_found
2822361SN/A
2832361SN/A    if not style_hook:
2842307SN/A        print mercurial_style_message,
2852307SN/A        # continue unless user does ctrl-c/ctrl-d etc.
2862307SN/A        try:
2872307SN/A            raw_input()
2881060SN/A        except:
2891060SN/A            print "Input exception, exiting scons.\n"
2901060SN/A            sys.exit(1)
2911061SN/A        hgrc_path = '%s/.hg/hgrc' % main.root.abspath
2921060SN/A        print "Adding style hook to", hgrc_path, "\n"
2932307SN/A        try:
2941060SN/A            hgrc = open(hgrc_path, 'a')
2952307SN/A            hgrc.write(mercurial_style_hook)
2962307SN/A            hgrc.close()
2971060SN/A        except:
2982329SN/A            print "Error updating", hgrc_path
2992307SN/A            sys.exit(1)
3002307SN/A
3011060SN/A
3022307SN/A###################################################
3032307SN/A#
3042307SN/A# Figure out which configurations to set up based on the path(s) of
3052307SN/A# the target(s).
3062307SN/A#
3072307SN/A###################################################
3082307SN/A
3092307SN/A# Find default configuration & binary.
3102307SN/ADefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug'))
3112307SN/A
3122307SN/A# helper function: find last occurrence of element in list
3132307SN/Adef rfind(l, elt, offs = -1):
3142307SN/A    for i in range(len(l)+offs, 0, -1):
3152307SN/A        if l[i] == elt:
3162935Sksewell@umich.edu            return i
3171858SN/A    raise ValueError, "element not found"
3182292SN/A
3191858SN/A# Take a list of paths (or SCons Nodes) and return a list with all
3202292SN/A# paths made absolute and ~-expanded.  Paths will be interpreted
3212292SN/A# relative to the launch directory unless a different root is provided
3222292SN/Adef makePathListAbsolute(path_list, root=GetLaunchDir()):
3232292SN/A    return [abspath(joinpath(root, expanduser(str(p))))
3243788Sgblack@eecs.umich.edu            for p in path_list]
3252292SN/A
3262698Sktlim@umich.edu# Each target must have 'build' in the interior of the path; the
3273788Sgblack@eecs.umich.edu# directory below this will determine the build parameters.  For
3282301SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
3293788Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
3303788Sgblack@eecs.umich.edu# follow 'build' in the build path.
3313788Sgblack@eecs.umich.edu
3323788Sgblack@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents
3333788Sgblack@eecs.umich.edu# in place rather than reassign the symbol to a new list, which
3343788Sgblack@eecs.umich.edu# doesn't work (obviously!).
3353788Sgblack@eecs.umich.eduBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)
3363788Sgblack@eecs.umich.edu
3373788Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the
3383788Sgblack@eecs.umich.edu# collected targets reference.
3393788Sgblack@eecs.umich.eduvariant_paths = []
3402292SN/Abuild_root = None
3412292SN/Afor t in BUILD_TARGETS:
3422292SN/A    path_dirs = t.split('/')
3432292SN/A    try:
3442292SN/A        build_top = rfind(path_dirs, 'build', -2)
3452329SN/A    except:
3462292SN/A        print "Error: no non-leaf 'build' dir found on target path", t
3472292SN/A        Exit(1)
3482292SN/A    this_build_root = joinpath('/',*path_dirs[:build_top+1])
3492935Sksewell@umich.edu    if not build_root:
3502935Sksewell@umich.edu        build_root = this_build_root
3512731Sktlim@umich.edu    else:
3522292SN/A        if this_build_root != build_root:
3532292SN/A            print "Error: build targets not under same build root\n"\
3542292SN/A                  "  %s\n  %s" % (build_root, this_build_root)
3552935Sksewell@umich.edu            Exit(1)
3562292SN/A    variant_path = joinpath('/',*path_dirs[:build_top+2])
3572292SN/A    if variant_path not in variant_paths:
3582935Sksewell@umich.edu        variant_paths.append(variant_path)
3594632Sgblack@eecs.umich.edu
3603093Sksewell@umich.edu# Make sure build_root exists (might not if this is the first build there)
3612292SN/Aif not isdir(build_root):
3622292SN/A    mkdir(build_root)
3633093Sksewell@umich.edumain['BUILDROOT'] = build_root
3644632Sgblack@eecs.umich.edu
3652935Sksewell@umich.eduExport('main')
3662292SN/A
3672292SN/Amain.SConsignFile(joinpath(build_root, "sconsign"))
3682292SN/A
3692292SN/A# Default duplicate option is to use hard links, but this messes up
3702292SN/A# when you use emacs to edit a file in the target dir, as emacs moves
3712292SN/A# file to file~ then copies to file, breaking the link.  Symbolic
3722292SN/A# (soft) links work better.
3732292SN/Amain.SetOption('duplicate', 'soft-copy')
3742292SN/A
3752292SN/A#
3762292SN/A# Set up global sticky variables... these are common to an entire build
3772292SN/A# tree (not specific to a particular build like ALPHA_SE)
3782292SN/A#
3792292SN/A
3802292SN/Aglobal_vars_file = joinpath(build_root, 'variables.global')
3812292SN/A
3823867Sbinkertn@umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS)
3833867Sbinkertn@umich.edu
3842292SN/Aglobal_vars.AddVariables(
3852292SN/A    ('CC', 'C compiler', environ.get('CC', main['CC'])),
3863867Sbinkertn@umich.edu    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
3872292SN/A    ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])),
3882292SN/A    ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')),
3892292SN/A    ('BATCH', 'Use batch pool for build and tests', False),
3902292SN/A    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3912292SN/A    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
3922292SN/A    ('EXTRAS', 'Add extra directories to the compilation', '')
3932292SN/A    )
3942292SN/A
3952292SN/A# Update main environment with values from ARGUMENTS & global_vars_file
3962292SN/Aglobal_vars.Update(main)
3972292SN/Ahelp_texts["global_vars"] += global_vars.GenerateHelpText(main)
3982292SN/A
3992292SN/A# Save sticky variable settings back to current variables file
4002292SN/Aglobal_vars.Save(global_vars_file, main)
4012292SN/A
4022292SN/A# Parse EXTRAS variable to build list of all directories where we're
4032292SN/A# look for sources etc.  This list is exported as extras_dir_list.
4042292SN/Abase_dir = main.srcdir.abspath
4053867Sbinkertn@umich.eduif main['EXTRAS']:
4062292SN/A    extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':'))
4073867Sbinkertn@umich.eduelse:
4082292SN/A    extras_dir_list = []
4092292SN/A
4102292SN/AExport('base_dir')
4112292SN/AExport('extras_dir_list')
4122292SN/A
4132292SN/A# the ext directory should be on the #includes path
4142292SN/Amain.Append(CPPPATH=[Dir('ext')])
4152292SN/A
4162292SN/Adef strip_build_path(path, env):
4172292SN/A    path = str(path)
4182292SN/A    variant_base = env['BUILDROOT'] + os.path.sep
4192292SN/A    if path.startswith(variant_base):
4202292SN/A        path = path[len(variant_base):]
4212292SN/A    elif path.startswith('build/'):
4222292SN/A        path = path[6:]
4232292SN/A    return path
4242292SN/A
4252292SN/A# Generate a string of the form:
4262292SN/A#   common/path/prefix/src1, src2 -> tgt1, tgt2
4272292SN/A# to print while building.
4282292SN/Aclass Transform(object):
4292292SN/A    # all specific color settings should be here and nowhere else
4302292SN/A    tool_color = termcap.Normal
4312292SN/A    pfx_color = termcap.Yellow
4322292SN/A    srcs_color = termcap.Yellow + termcap.Bold
4332292SN/A    arrow_color = termcap.Blue + termcap.Bold
4342292SN/A    tgts_color = termcap.Yellow + termcap.Bold
4352292SN/A
4362292SN/A    def __init__(self, tool, max_sources=99):
4372292SN/A        self.format = self.tool_color + (" [%8s] " % tool) \
4382292SN/A                      + self.pfx_color + "%s" \
4392292SN/A                      + self.srcs_color + "%s" \
4402292SN/A                      + self.arrow_color + " -> " \
4412292SN/A                      + self.tgts_color + "%s" \
4422292SN/A                      + termcap.Normal
4432292SN/A        self.max_sources = max_sources
4442301SN/A
4452301SN/A    def __call__(self, target, source, env, for_signature=None):
4463788Sgblack@eecs.umich.edu        # truncate source list according to max_sources param
4473788Sgblack@eecs.umich.edu        source = source[0:self.max_sources]
4483788Sgblack@eecs.umich.edu        def strip(f):
4493788Sgblack@eecs.umich.edu            return strip_build_path(str(f), env)
4503788Sgblack@eecs.umich.edu        if len(source) > 0:
4513788Sgblack@eecs.umich.edu            srcs = map(strip, source)
4523788Sgblack@eecs.umich.edu        else:
4533788Sgblack@eecs.umich.edu            srcs = ['']
4543798Sgblack@eecs.umich.edu        tgts = map(strip, target)
4553798Sgblack@eecs.umich.edu        # surprisingly, os.path.commonprefix is a dumb char-by-char string
4563798Sgblack@eecs.umich.edu        # operation that has nothing to do with paths.
4573798Sgblack@eecs.umich.edu        com_pfx = os.path.commonprefix(srcs + tgts)
4583798Sgblack@eecs.umich.edu        com_pfx_len = len(com_pfx)
4593798Sgblack@eecs.umich.edu        if com_pfx:
4602292SN/A            # do some cleanup and sanity checking on common prefix
4612292SN/A            if com_pfx[-1] == ".":
4622292SN/A                # prefix matches all but file extension: ok
4632292SN/A                # back up one to change 'foo.cc -> o' to 'foo.cc -> .o'
4642292SN/A                com_pfx = com_pfx[0:-1]
4652292SN/A            elif com_pfx[-1] == "/":
4662292SN/A                # common prefix is directory path: OK
4672292SN/A                pass
4682292SN/A            else:
4692292SN/A                src0_len = len(srcs[0])
4702292SN/A                tgt0_len = len(tgts[0])
4712292SN/A                if src0_len == com_pfx_len:
4722292SN/A                    # source is a substring of target, OK
4732292SN/A                    pass
4742292SN/A                elif tgt0_len == com_pfx_len:
4752292SN/A                    # target is a substring of source, need to back up to
4762292SN/A                    # avoid empty string on RHS of arrow
4772292SN/A                    sep_idx = com_pfx.rfind(".")
4782292SN/A                    if sep_idx != -1:
4792292SN/A                        com_pfx = com_pfx[0:sep_idx]
4801858SN/A                    else:
4811858SN/A                        com_pfx = ''
4821858SN/A                elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".":
4831858SN/A                    # still splitting at file extension: ok
4841858SN/A                    pass
4852292SN/A                else:
4861858SN/A                    # probably a fluke; ignore it
4872292SN/A                    com_pfx = ''
4882292SN/A        # recalculate length in case com_pfx was modified
4892292SN/A        com_pfx_len = len(com_pfx)
4902292SN/A        def fmt(files):
4911858SN/A            f = map(lambda s: s[com_pfx_len:], files)
4922292SN/A            return ', '.join(f)
4932292SN/A        return self.format % (com_pfx, fmt(srcs), fmt(tgts))
4942292SN/A
4952292SN/AExport('Transform')
4962292SN/A
4972292SN/A# enable the regression script to use the termcap
4982292SN/Amain['TERMCAP'] = termcap
4992292SN/A
5002292SN/Aif GetOption('verbose'):
5012292SN/A    def MakeAction(action, string, *args, **kwargs):
5022292SN/A        return Action(action, *args, **kwargs)
5032292SN/Aelse:
5042292SN/A    MakeAction = Action
5051858SN/A    main['CCCOMSTR']        = Transform("CC")
5062292SN/A    main['CXXCOMSTR']       = Transform("CXX")
5072292SN/A    main['ASCOMSTR']        = Transform("AS")
5082292SN/A    main['SWIGCOMSTR']      = Transform("SWIG")
5092292SN/A    main['ARCOMSTR']        = Transform("AR", 0)
5102292SN/A    main['LINKCOMSTR']      = Transform("LINK", 0)
5112292SN/A    main['RANLIBCOMSTR']    = Transform("RANLIB", 0)
5122292SN/A    main['M4COMSTR']        = Transform("M4")
5132292SN/A    main['SHCCCOMSTR']      = Transform("SHCC")
5142292SN/A    main['SHCXXCOMSTR']     = Transform("SHCXX")
5152292SN/AExport('MakeAction')
5162292SN/A
5172292SN/A# Initialize the Link-Time Optimization (LTO) flags
5182292SN/Amain['LTO_CCFLAGS'] = []
5192292SN/Amain['LTO_LDFLAGS'] = []
5202292SN/A
5212292SN/A# According to the readme, tcmalloc works best if the compiler doesn't
5222292SN/A# assume that we're using the builtin malloc and friends. These flags
5232292SN/A# are compiler-specific, so we need to set them after we detect which
5242292SN/A# compiler we're using.
5252292SN/Amain['TCMALLOC_CCFLAGS'] = []
5262292SN/A
5272292SN/ACXX_version = readCommand([main['CXX'],'--version'], exception=False)
5282292SN/ACXX_V = readCommand([main['CXX'],'-V'], exception=False)
5292292SN/A
5302292SN/Amain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
5312292SN/Amain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0
5322292SN/Aif main['GCC'] + main['CLANG'] > 1:
5332292SN/A    print 'Error: How can we have two at the same time?'
5342292SN/A    Exit(1)
5352292SN/A
5362292SN/A# Set up default C++ compiler flags
5372292SN/Aif main['GCC'] or main['CLANG']:
5382292SN/A    # As gcc and clang share many flags, do the common parts here
5392292SN/A    main.Append(CCFLAGS=['-pipe'])
5402292SN/A    main.Append(CCFLAGS=['-fno-strict-aliasing'])
5412292SN/A    # Enable -Wall and then disable the few warnings that we
5422292SN/A    # consistently violate
5432292SN/A    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
5442292SN/A    # We always compile using C++11, but only gcc >= 4.7 and clang 3.1
5452292SN/A    # actually use that name, so we stick with c++0x
5462292SN/A    main.Append(CXXFLAGS=['-std=c++0x'])
5472292SN/A    # Add selected sanity checks from -Wextra
5482292SN/A    main.Append(CXXFLAGS=['-Wmissing-field-initializers',
5492292SN/A                          '-Woverloaded-virtual'])
5502292SN/Aelse:
5512292SN/A    print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal,
5522292SN/A    print "Don't know what compiler options to use for your compiler."
5532292SN/A    print termcap.Yellow + '       compiler:' + termcap.Normal, main['CXX']
5542292SN/A    print termcap.Yellow + '       version:' + termcap.Normal,
5552292SN/A    if not CXX_version:
5562292SN/A        print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\
5572292SN/A               termcap.Normal
5582292SN/A    else:
5592292SN/A        print CXX_version.replace('\n', '<nl>')
5602292SN/A    print "       If you're trying to use a compiler other than GCC"
5612292SN/A    print "       or clang, there appears to be something wrong with your"
5622292SN/A    print "       environment."
5632292SN/A    print "       "
5642292SN/A    print "       If you are trying to use a compiler other than those listed"
5652292SN/A    print "       above you will need to ease fix SConstruct and "
5662292SN/A    print "       src/SConscript to support that compiler."
5672292SN/A    Exit(1)
5682292SN/A
5692292SN/Aif main['GCC']:
5702292SN/A    # Check for a supported version of gcc, >= 4.4 is needed for c++0x
5712292SN/A    # support. See http://gcc.gnu.org/projects/cxx0x.html for details
5722292SN/A    gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False)
5732292SN/A    if compareVersions(gcc_version, "4.4") < 0:
5742292SN/A        print 'Error: gcc version 4.4 or newer required.'
5752292SN/A        print '       Installed version:', gcc_version
5762292SN/A        Exit(1)
5772292SN/A
5782292SN/A    main['GCC_VERSION'] = gcc_version
5792292SN/A
5802292SN/A    # Check for versions with bugs
5812292SN/A    if not compareVersions(gcc_version, '4.4.1') or \
5822292SN/A       not compareVersions(gcc_version, '4.4.2'):
5832292SN/A        print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.'
5842292SN/A        main.Append(CCFLAGS=['-fno-tree-vectorize'])
5852292SN/A
5862292SN/A    # LTO support is only really working properly from 4.6 and beyond
5872292SN/A    if compareVersions(gcc_version, '4.6') >= 0:
5882292SN/A        # Add the appropriate Link-Time Optimization (LTO) flags
5892292SN/A        # unless LTO is explicitly turned off. Note that these flags
5902292SN/A        # are only used by the fast target.
5912292SN/A        if not GetOption('no_lto'):
5922292SN/A            # Pass the LTO flag when compiling to produce GIMPLE
5932292SN/A            # output, we merely create the flags here and only append
5942292SN/A            # them later/
5952292SN/A            main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')]
5962292SN/A
5972292SN/A            # Use the same amount of jobs for LTO as we are running
5982292SN/A            # scons with, we hardcode the use of the linker plugin
5992935Sksewell@umich.edu            # which requires either gold or GNU ld >= 2.21
6002292SN/A            main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'),
6012292SN/A                                   '-fuse-linker-plugin']
6022292SN/A
6032292SN/A    main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc',
6042292SN/A                                  '-fno-builtin-realloc', '-fno-builtin-free'])
6052292SN/A
6062292SN/Aelif main['CLANG']:
6072292SN/A    # Check for a supported version of clang, >= 2.9 is needed to
6082292SN/A    # support similar features as gcc 4.4. See
6092292SN/A    # http://clang.llvm.org/cxx_status.html for details
6102292SN/A    clang_version_re = re.compile(".* version (\d+\.\d+)")
6112292SN/A    clang_version_match = clang_version_re.search(CXX_version)
6122292SN/A    if (clang_version_match):
6132292SN/A        clang_version = clang_version_match.groups()[0]
6142292SN/A        if compareVersions(clang_version, "2.9") < 0:
6152292SN/A            print 'Error: clang version 2.9 or newer required.'
6162292SN/A            print '       Installed version:', clang_version
6172336SN/A            Exit(1)
6182336SN/A    else:
6192336SN/A        print 'Error: Unable to determine clang version.'
6202336SN/A        Exit(1)
6212336SN/A
6222336SN/A    # clang has a few additional warnings that we disable,
6232336SN/A    # tautological comparisons are allowed due to unsigned integers
6242336SN/A    # being compared to constants that happen to be 0, and extraneous
6252292SN/A    # parantheses are allowed due to Ruby's printing of the AST,
6262292SN/A    # finally self assignments are allowed as the generated CPU code
6272301SN/A    # is relying on this
6282301SN/A    main.Append(CCFLAGS=['-Wno-tautological-compare',
6292292SN/A                         '-Wno-parentheses',
6302301SN/A                         '-Wno-self-assign'])
6312301SN/A
6322301SN/A    main.Append(TCMALLOC_CCFLAGS=['-fno-builtin'])
6332292SN/A
6342301SN/A    # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as
6352292SN/A    # opposed to libstdc++, as the later is dated.
6362301SN/A    if sys.platform == "darwin":
6372292SN/A        main.Append(CXXFLAGS=['-stdlib=libc++'])
6382301SN/A        main.Append(LIBS=['c++'])
6392292SN/A
6402292SN/Aelse:
6412292SN/A    print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal,
6422292SN/A    print "Don't know what compiler options to use for your compiler."
6432336SN/A    print termcap.Yellow + '       compiler:' + termcap.Normal, main['CXX']
6442336SN/A    print termcap.Yellow + '       version:' + termcap.Normal,
6452292SN/A    if not CXX_version:
6462292SN/A        print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\
6472307SN/A               termcap.Normal
6482307SN/A    else:
6492292SN/A        print CXX_version.replace('\n', '<nl>')
6502292SN/A    print "       If you're trying to use a compiler other than GCC"
6512292SN/A    print "       or clang, there appears to be something wrong with your"
6522292SN/A    print "       environment."
6532292SN/A    print "       "
6542292SN/A    print "       If you are trying to use a compiler other than those listed"
6552292SN/A    print "       above you will need to ease fix SConstruct and "
6562292SN/A    print "       src/SConscript to support that compiler."
6572292SN/A    Exit(1)
6582292SN/A
6592292SN/A# Set up common yacc/bison flags (needed for Ruby)
6604345Sktlim@umich.edumain['YACCFLAGS'] = '-d'
6612292SN/Amain['YACCHXXFILESUFFIX'] = '.hh'
6622292SN/A
6632292SN/A# Do this after we save setting back, or else we'll tack on an
6642292SN/A# extra 'qdo' every time we run scons.
6652292SN/Aif main['BATCH']:
6662292SN/A    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
6672292SN/A    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
6682292SN/A    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
6692292SN/A    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
6702292SN/A    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
6712292SN/A
6722292SN/Aif sys.platform == 'cygwin':
6732292SN/A    # cygwin has some header file issues...
6742292SN/A    main.Append(CCFLAGS=["-Wno-uninitialized"])
6752292SN/A
6762292SN/A# Check for the protobuf compiler
6772292SN/Aprotoc_version = readCommand([main['PROTOC'], '--version'],
6782292SN/A                             exception='').split()
6792292SN/A
6802292SN/A# First two words should be "libprotoc x.y.z"
6812292SN/Aif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc':
6822292SN/A    print termcap.Yellow + termcap.Bold + \
6832292SN/A        'Warning: Protocol buffer compiler (protoc) not found.\n' + \
6842307SN/A        '         Please install protobuf-compiler for tracing support.' + \
6852292SN/A        termcap.Normal
6862292SN/A    main['PROTOC'] = False
6872292SN/Aelse:
6882292SN/A    # Based on the availability of the compress stream wrappers,
6892292SN/A    # require 2.1.0
6902292SN/A    min_protoc_version = '2.1.0'
6912292SN/A    if compareVersions(protoc_version[1], min_protoc_version) < 0:
6922292SN/A        print termcap.Yellow + termcap.Bold + \
6932292SN/A            'Warning: protoc version', min_protoc_version, \
6942292SN/A            'or newer required.\n' + \
6952292SN/A            '         Installed version:', protoc_version[1], \
6962292SN/A            termcap.Normal
6972292SN/A        main['PROTOC'] = False
6982292SN/A    else:
6992292SN/A        # Attempt to determine the appropriate include path and
7002292SN/A        # library path using pkg-config, that means we also need to
7012292SN/A        # check for pkg-config. Note that it is possible to use
7022292SN/A        # protobuf without the involvement of pkg-config. Later on we
7032292SN/A        # check go a library config check and at that point the test
7042292SN/A        # will fail if libprotobuf cannot be found.
7052292SN/A        if readCommand(['pkg-config', '--version'], exception=''):
7062292SN/A            try:
7072292SN/A                # Attempt to establish what linking flags to add for protobuf
7082292SN/A                # using pkg-config
7092292SN/A                main.ParseConfig('pkg-config --cflags --libs-only-L protobuf')
7102292SN/A            except:
7112292SN/A                print termcap.Yellow + termcap.Bold + \
7122292SN/A                    'Warning: pkg-config could not get protobuf flags.' + \
7132292SN/A                    termcap.Normal
7142292SN/A
7152292SN/A# Check for SWIG
7162292SN/Aif not main.has_key('SWIG'):
7172292SN/A    print 'Error: SWIG utility not found.'
7182292SN/A    print '       Please install (see http://www.swig.org) and retry.'
7192307SN/A    Exit(1)
7202307SN/A
7212292SN/A# Check for appropriate SWIG version
7222292SN/Aswig_version = readCommand([main['SWIG'], '-version'], exception='').split()
7232292SN/A# First 3 words should be "SWIG Version x.y.z"
7242292SN/Aif len(swig_version) < 3 or \
7253798Sgblack@eecs.umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
7263798Sgblack@eecs.umich.edu    print 'Error determining SWIG version.'
7273798Sgblack@eecs.umich.edu    Exit(1)
7283798Sgblack@eecs.umich.edu
7293798Sgblack@eecs.umich.edumin_swig_version = '1.3.34'
7303798Sgblack@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0:
7313798Sgblack@eecs.umich.edu    print 'Error: SWIG version', min_swig_version, 'or newer required.'
7323798Sgblack@eecs.umich.edu    print '       Installed version:', swig_version[2]
7333798Sgblack@eecs.umich.edu    Exit(1)
7342292SN/A
7353798Sgblack@eecs.umich.edu# Older versions of swig do not play well with more recent versions of
7362292SN/A# gcc due to assumptions on implicit includes (cstddef) and use of
7372292SN/A# namespaces
7382292SN/Aif main['GCC'] and compareVersions(gcc_version, '4.6') > 0 and \
7392292SN/A        compareVersions(swig_version[2], '2') < 0:
7402292SN/A    print '\n' + termcap.Yellow + termcap.Bold + \
7412292SN/A        'Warning: SWIG 1.x cause issues with gcc 4.6 and later.\n' + \
7422292SN/A        termcap.Normal + \
7432329SN/A        'Use SWIG 2.x to avoid assumptions on implicit includes\n' + \
7442292SN/A        'and use of namespaces\n'
7452292SN/A
7462329SN/A# Set up SWIG flags & scanner
7472292SN/Aswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
7482292SN/Amain.Append(SWIGFLAGS=swig_flags)
7492292SN/A
7502292SN/A# filter out all existing swig scanners, they mess up the dependency
7512292SN/A# stuff for some reason
7522292SN/Ascanners = []
7532292SN/Afor scanner in main['SCANNERS']:
7542292SN/A    skeys = scanner.skeys
7552292SN/A    if skeys == '.i':
7562292SN/A        continue
7573867Sbinkertn@umich.edu
7583867Sbinkertn@umich.edu    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
7592292SN/A        continue
7603867Sbinkertn@umich.edu
7613867Sbinkertn@umich.edu    scanners.append(scanner)
7623867Sbinkertn@umich.edu
7633867Sbinkertn@umich.edu# add the new swig scanner that we like better
7642292SN/Afrom SCons.Scanner import ClassicCPP as CPPScanner
7652292SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
7662292SN/Ascanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
7672292SN/A
7682292SN/A# replace the scanners list that has what we want
7692292SN/Amain['SCANNERS'] = scanners
7702292SN/A
7712292SN/A# Add a custom Check function to the Configure context so that we can
7722292SN/A# figure out if the compiler adds leading underscores to global
7732292SN/A# variables.  This is needed for the autogenerated asm files that we
7742292SN/A# use for embedding the python code.
7752292SN/Adef CheckLeading(context):
7763867Sbinkertn@umich.edu    context.Message("Checking for leading underscore in global variables...")
7773867Sbinkertn@umich.edu    # 1) Define a global variable called x from asm so the C compiler
7782292SN/A    #    won't change the symbol at all.
7793867Sbinkertn@umich.edu    # 2) Declare that variable.
7802292SN/A    # 3) Use the variable
7812292SN/A    #
7822292SN/A    # If the compiler prepends an underscore, this will successfully
7832292SN/A    # link because the external symbol 'x' will be called '_x' which
7842292SN/A    # was defined by the asm statement.  If the compiler does not
7852292SN/A    # prepend an underscore, this will not successfully link because
7862292SN/A    # '_x' will have been defined by assembly, while the C portion of
7872292SN/A    # the code will be trying to use 'x'
7882292SN/A    ret = context.TryLink('''
7892292SN/A        asm(".globl _x; _x: .byte 0");
7902292SN/A        extern int x;
7912292SN/A        int main() { return x; }
7922292SN/A        ''', extension=".c")
7932292SN/A    context.env.Append(LEADING_UNDERSCORE=ret)
7942292SN/A    context.Result(ret)
7952733Sktlim@umich.edu    return ret
7962292SN/A
7972292SN/A# Add a custom Check function to test for structure members.
7982292SN/Adef CheckMember(context, include, decl, member, include_quotes="<>"):
7992292SN/A    context.Message("Checking for member %s in %s..." %
8002292SN/A                    (member, decl))
8012292SN/A    text = """
8022292SN/A#include %(header)s
8032292SN/Aint main(){
8042733Sktlim@umich.edu  %(decl)s test;
8052292SN/A  (void)test.%(member)s;
8062292SN/A  return 0;
8072292SN/A};
8082292SN/A""" % { "header" : include_quotes[0] + include + include_quotes[1],
8092292SN/A        "decl" : decl,
8102292SN/A        "member" : member,
8112292SN/A        }
8122292SN/A
8132292SN/A    ret = context.TryCompile(text, extension=".cc")
8142292SN/A    context.Result(ret)
8152292SN/A    return ret
8162292SN/A
8172292SN/A# Platform-specific configuration.  Note again that we assume that all
8182292SN/A# builds under a given build root run on the same host platform.
8192292SN/Aconf = Configure(main,
8202292SN/A                 conf_dir = joinpath(build_root, '.scons_config'),
8212292SN/A                 log_file = joinpath(build_root, 'scons_config.log'),
8223798Sgblack@eecs.umich.edu                 custom_tests = {
8233798Sgblack@eecs.umich.edu        'CheckLeading' : CheckLeading,
8243798Sgblack@eecs.umich.edu        'CheckMember' : CheckMember,
8253798Sgblack@eecs.umich.edu        })
8262292SN/A
8272292SN/A# Check for leading underscores.  Don't really need to worry either
8282292SN/A# way so don't need to check the return code.
8292292SN/Aconf.CheckLeading()
8302292SN/A
8312329SN/A# Check if we should compile a 64 bit binary on Mac OS X/Darwin
8322329SN/Atry:
8332301SN/A    import platform
8342292SN/A    uname = platform.uname()
8352292SN/A    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
8362292SN/A        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
8372292SN/A            main.Append(CCFLAGS=['-arch', 'x86_64'])
8382292SN/A            main.Append(CFLAGS=['-arch', 'x86_64'])
8392292SN/A            main.Append(LINKFLAGS=['-arch', 'x86_64'])
8402292SN/A            main.Append(ASFLAGS=['-arch', 'x86_64'])
8412292SN/Aexcept:
8422292SN/A    pass
8432292SN/A
8442292SN/A# Recent versions of scons substitute a "Null" object for Configure()
8452292SN/A# when configuration isn't necessary, e.g., if the "--help" option is
8462292SN/A# present.  Unfortuantely this Null object always returns false,
8472292SN/A# breaking all our configuration checks.  We replace it with our own
8482292SN/A# more optimistic null object that returns True instead.
8492292SN/Aif not conf:
8502301SN/A    def NullCheck(*args, **kwargs):
8512292SN/A        return True
8522292SN/A
8532292SN/A    class NullConf:
8542292SN/A        def __init__(self, env):
8552292SN/A            self.env = env
8562292SN/A        def Finish(self):
8572292SN/A            return self.env
8582292SN/A        def __getattr__(self, mname):
8592292SN/A            return NullCheck
8602292SN/A
8612292SN/A    conf = NullConf(main)
8622292SN/A
8632292SN/A# Cache build files in the supplied directory.
8642292SN/Aif main['M5_BUILD_CACHE']:
8652292SN/A    print 'Using build cache located at', main['M5_BUILD_CACHE']
8662935Sksewell@umich.edu    CacheDir(main['M5_BUILD_CACHE'])
8672292SN/A
8682980Sgblack@eecs.umich.edu# Find Python include and library directories for embedding the
8692980Sgblack@eecs.umich.edu# interpreter. We rely on python-config to resolve the appropriate
8702292SN/A# includes and linker flags. ParseConfig does not seem to understand
8711060SN/A# the more exotic linker flags such as -Xlinker and -export-dynamic so
8721060SN/A# we add them explicitly below. If you want to link in an alternate
8732292SN/A# version of python, see above for instructions on how to invoke
8741060SN/A# scons with the appropriate PATH set.
8751060SN/A#
8761060SN/A# First we check if python2-config exists, else we use python-config
8771060SN/Apython_config = readCommand(['which', 'python2-config'], exception='').strip()
8781060SN/Aif not os.path.exists(python_config):
8792292SN/A    python_config = readCommand(['which', 'python-config'], exception='')
8802292SN/Apy_includes = readCommand([python_config, '--includes'],
8812292SN/A                          exception='').split()
8821062SN/A# Strip the -I from the include folders before adding them to the
8832292SN/A# CPPPATH
8842292SN/Amain.Append(CPPPATH=map(lambda inc: inc[2:], py_includes))
8851060SN/A
8862292SN/A# Read the linker flags and split them into libraries and other link
8872292SN/A# flags. The libraries are added later through the call the CheckLib.
8882292SN/Apy_ld_flags = readCommand([python_config, '--ldflags'], exception='').split()
8891060SN/Apy_libs = []
8902292SN/Afor lib in py_ld_flags:
8912292SN/A     if not lib.startswith('-l'):
8921062SN/A         main.Append(LINKFLAGS=[lib])
8932367SN/A     else:
8942367SN/A         lib = lib[2:]
8952367SN/A         if lib not in py_libs:
8962367SN/A             py_libs.append(lib)
8972367SN/A
8982292SN/A# verify that this stuff works
8991061SN/Aif not conf.CheckHeader('Python.h', '<>'):
9001062SN/A    print "Error: can't find Python.h header in", py_includes
9011060SN/A    print "Install Python headers (package python-dev on Ubuntu and RedHat)"
9021060SN/A    Exit(1)
9031060SN/A
9041060SN/Afor lib in py_libs:
9051060SN/A    if not conf.CheckLib(lib):
9062292SN/A        print "Error: can't find library %s required by python" % lib
9071060SN/A        Exit(1)
9082292SN/A
9092292SN/A# On Solaris you need to use libsocket for socket ops
9102292SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
9112292SN/A   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
9122980Sgblack@eecs.umich.edu       print "Can't find library with socket calls (e.g. accept())"
9132980Sgblack@eecs.umich.edu       Exit(1)
9141060SN/A
9151061SN/A# Check for zlib.  If the check passes, libz will be automatically
9161060SN/A# added to the LIBS environment variable.
9172292SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
9182292SN/A    print 'Error: did not find needed zlib compression library '\
9192292SN/A          'and/or zlib.h header file.'
9202292SN/A    print '       Please install zlib and try again.'
9212292SN/A    Exit(1)
9222292SN/A
9231060SN/A# If we have the protobuf compiler, also make sure we have the
9241060SN/A# development libraries. If the check passes, libprotobuf will be
9251060SN/A# automatically added to the LIBS environment variable. After
9262292SN/A# this, we can use the HAVE_PROTOBUF flag to determine if we have
9272292SN/A# got both protoc and libprotobuf available.
9282292SN/Amain['HAVE_PROTOBUF'] = main['PROTOC'] and \
9292292SN/A    conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h',
9302292SN/A                            'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;')
9312292SN/A
9322292SN/A# If we have the compiler but not the library, print another warning.
9331060SN/Aif main['PROTOC'] and not main['HAVE_PROTOBUF']:
9342329SN/A    print termcap.Yellow + termcap.Bold + \
9352329SN/A        'Warning: did not find protocol buffer library and/or headers.\n' + \
9362292SN/A    '       Please install libprotobuf-dev for tracing support.' + \
9371061SN/A    termcap.Normal
9382292SN/A
9392292SN/A# Check for librt.
9401061SN/Ahave_posix_clock = \
9412292SN/A    conf.CheckLibWithHeader(None, 'time.h', 'C',
9421060SN/A                            'clock_nanosleep(0,0,NULL,NULL);') or \
9431060SN/A    conf.CheckLibWithHeader('rt', 'time.h', 'C',
9441060SN/A                            'clock_nanosleep(0,0,NULL,NULL);')
9451061SN/A
9461061SN/Ahave_posix_timers = \
9472292SN/A    conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C',
9481061SN/A                            'timer_create(CLOCK_MONOTONIC, NULL, NULL);')
9492292SN/A
9502292SN/Aif conf.CheckLib('tcmalloc'):
9511061SN/A    main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS'])
9521061SN/Aelif conf.CheckLib('tcmalloc_minimal'):
9531061SN/A    main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS'])
9541061SN/Aelse:
9551061SN/A    print termcap.Yellow + termcap.Bold + \
9562292SN/A          "You can get a 12% performance improvement by installing tcmalloc "\
9571061SN/A          "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \
9583773Sgblack@eecs.umich.edu          termcap.Normal
9593773Sgblack@eecs.umich.edu
9603773Sgblack@eecs.umich.eduif not have_posix_clock:
9613773Sgblack@eecs.umich.edu    print "Can't find library for POSIX clocks."
9624352Sgblack@eecs.umich.edu
9634352Sgblack@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
9644352Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
9654352Sgblack@eecs.umich.eduif not have_fenv:
9664636Sgblack@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
9673773Sgblack@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
9684352Sgblack@eecs.umich.edu
9693773Sgblack@eecs.umich.edu# Check if we should enable KVM-based hardware virtualization. The API
9701061SN/A# we rely on exists since version 2.6.36 of the kernel, but somehow
9711061SN/A# the KVM_API_VERSION does not reflect the change. We test for one of
9721061SN/A# the types as a fall back.
9733773Sgblack@eecs.umich.eduhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') and \
9741061SN/A    conf.CheckTypeSize('struct kvm_xsave', '#include <linux/kvm.h>') != 0
9752292SN/Aif not have_kvm:
9763773Sgblack@eecs.umich.edu    print "Info: Compatible header file <linux/kvm.h> not found, " \
9772292SN/A        "disabling KVM support."
9781061SN/A
9791061SN/A# Check if the requested target ISA is compatible with the host
9801061SN/Adef is_isa_kvm_compatible(isa):
9812292SN/A    isa_comp_table = {
9822292SN/A        "arm" : ( "armv7l" ),
9834636Sgblack@eecs.umich.edu        "x86" : ( "x86_64" ),
9841061SN/A        }
9851061SN/A    try:
9864636Sgblack@eecs.umich.edu        import platform
9874636Sgblack@eecs.umich.edu        host_isa = platform.machine()
9881061SN/A    except:
9891062SN/A        print "Warning: Failed to determine host ISA."
9901062SN/A        return False
9911061SN/A
9921061SN/A    return host_isa in isa_comp_table.get(isa, [])
9931061SN/A
9941061SN/A
9951061SN/A# Check if the exclude_host attribute is available. We want this to
9962292SN/A# get accurate instruction counts in KVM.
9971061SN/Amain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember(
9982292SN/A    'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host')
9991061SN/A
10001061SN/A
10011061SN/A######################################################################
10022292SN/A#
10032292SN/A# Finish the configuration
10042292SN/A#
10053773Sgblack@eecs.umich.edumain = conf.Finish()
10063773Sgblack@eecs.umich.edu
10074352Sgblack@eecs.umich.edu######################################################################
10083773Sgblack@eecs.umich.edu#
10093773Sgblack@eecs.umich.edu# Collect all non-global variables
10104352Sgblack@eecs.umich.edu#
10114352Sgblack@eecs.umich.edu
10124352Sgblack@eecs.umich.edu# Define the universe of supported ISAs
10134352Sgblack@eecs.umich.eduall_isa_list = [ ]
10144636Sgblack@eecs.umich.eduExport('all_isa_list')
10153773Sgblack@eecs.umich.edu
10163773Sgblack@eecs.umich.educlass CpuModel(object):
10173773Sgblack@eecs.umich.edu    '''The CpuModel class encapsulates everything the ISA parser needs to
10181061SN/A    know about a particular CPU model.'''
10192292SN/A
10202292SN/A    # Dict of available CPU model objects.  Accessible as CpuModel.dict.
10213773Sgblack@eecs.umich.edu    dict = {}
10221061SN/A    list = []
10232292SN/A    defaults = []
10242292SN/A
10251062SN/A    # Constructor.  Automatically adds models to CpuModel.dict.
10262292SN/A    def __init__(self, name, filename, includes, strings, default=False):
10273773Sgblack@eecs.umich.edu        self.name = name           # name of model
10282292SN/A        self.filename = filename   # filename for output exec code
10291062SN/A        self.includes = includes   # include files needed in exec file
10302292SN/A        # The 'strings' dict holds all the per-CPU symbols we can
10313773Sgblack@eecs.umich.edu        # substitute into templates etc.
10322292SN/A        self.strings = strings
10332292SN/A
10341062SN/A        # This cpu is enabled by default
10352292SN/A        self.default = default
10361062SN/A
10372935Sksewell@umich.edu        # Add self to dict
10382935Sksewell@umich.edu        if name in CpuModel.dict:
10392935Sksewell@umich.edu            raise AttributeError, "CpuModel '%s' already registered" % name
10402292SN/A        CpuModel.dict[name] = self
10411062SN/A        CpuModel.list.append(name)
10422292SN/A
10432292SN/AExport('CpuModel')
10442292SN/A
10452292SN/A# Sticky variables get saved in the variables file so they persist from
10462292SN/A# one invocation to the next (unless overridden, in which case the new
10472292SN/A# value becomes sticky).
10482292SN/Asticky_vars = Variables(args=ARGUMENTS)
10492292SN/AExport('sticky_vars')
10501062SN/A
10512292SN/A# Sticky variables that should be exported
10521061SN/Aexport_vars = []
10531061SN/AExport('export_vars')
10541061SN/A
10551061SN/A# For Ruby
10561061SN/Aall_protocols = []
10572292SN/AExport('all_protocols')
10581061SN/Aprotocol_dirs = []
10592292SN/AExport('protocol_dirs')
10602292SN/Aslicc_includes = []
10612292SN/AExport('slicc_includes')
10622292SN/A
10632292SN/A# Walk the tree and execute all SConsopts scripts that wil add to the
10642292SN/A# above variables
10651061SN/Aif GetOption('verbose'):
10661061SN/A    print "Reading SConsopts"
10671061SN/Afor bdir in [ base_dir ] + extras_dir_list:
10681061SN/A    if not isdir(bdir):
10692292SN/A        print "Error: directory '%s' does not exist" % bdir
10701061SN/A        Exit(1)
10712292SN/A    for root, dirs, files in os.walk(bdir):
10722292SN/A        if 'SConsopts' in files:
10732292SN/A            if GetOption('verbose'):
10742292SN/A                print "Reading", joinpath(root, 'SConsopts')
10752292SN/A            SConscript(joinpath(root, 'SConsopts'))
10762292SN/A
10772292SN/Aall_isa_list.sort()
10782292SN/A
10792292SN/Asticky_vars.AddVariables(
10802292SN/A    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
10812292SN/A    ListVariable('CPU_MODELS', 'CPU models',
10822292SN/A                 sorted(n for n,m in CpuModel.dict.iteritems() if m.default),
10832292SN/A                 sorted(CpuModel.list)),
10842292SN/A    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
10852292SN/A                 False),
10862292SN/A    BoolVariable('SS_COMPATIBLE_FP',
10872292SN/A                 'Make floating-point results compatible with SimpleScalar',
10882292SN/A                 False),
10892292SN/A    BoolVariable('USE_SSE2',
10902292SN/A                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
10912292SN/A                 False),
10922292SN/A    BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
10932292SN/A    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
10942292SN/A    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
10952292SN/A    BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm),
10962292SN/A    EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None',
10972292SN/A                  all_protocols),
10982731Sktlim@umich.edu    )
10992292SN/A
11002292SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript).
11012292SN/Aexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'CP_ANNOTATE',
11022292SN/A                'USE_POSIX_CLOCK', 'PROTOCOL', 'HAVE_PROTOBUF',
11032292SN/A                'HAVE_PERF_ATTR_EXCLUDE_HOST']
11042292SN/A
11052292SN/A###################################################
11062292SN/A#
11072292SN/A# Define a SCons builder for configuration flag headers.
11082292SN/A#
11092292SN/A###################################################
11102292SN/A
11112292SN/A# This function generates a config header file that #defines the
11122292SN/A# variable symbol to the current variable setting (0 or 1).  The source
11132292SN/A# operands are the name of the variable and a Value node containing the
11142292SN/A# value of the variable.
11152292SN/Adef build_config_file(target, source, env):
11162292SN/A    (variable, value) = [s.get_contents() for s in source]
11172292SN/A    f = file(str(target[0]), 'w')
11182292SN/A    print >> f, '#define', variable, value
11192292SN/A    f.close()
11202292SN/A    return None
11212292SN/A
11222292SN/A# Combine the two functions into a scons Action object.
11232292SN/Aconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2))
11242292SN/A
11252292SN/A# The emitter munges the source & target node lists to reflect what
11262292SN/A# we're really doing.
11272292SN/Adef config_emitter(target, source, env):
11282292SN/A    # extract variable name from Builder arg
11292292SN/A    variable = str(target[0])
11302292SN/A    # True target is config header file
11312292SN/A    target = joinpath('config', variable.lower() + '.hh')
11322292SN/A    val = env[variable]
11332292SN/A    if isinstance(val, bool):
11342292SN/A        # Force value to 0/1
11352292SN/A        val = int(val)
11362292SN/A    elif isinstance(val, str):
11372292SN/A        val = '"' + val + '"'
11382292SN/A
11392292SN/A    # Sources are variable name & value (packaged in SCons Value nodes)
11402292SN/A    return ([target], [Value(variable), Value(val)])
11412292SN/A
11422292SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
11432292SN/A
11442292SN/Amain.Append(BUILDERS = { 'ConfigFile' : config_builder })
11452292SN/A
11462292SN/A# libelf build is shared across all configs in the build root.
11472292SN/Amain.SConscript('ext/libelf/SConscript',
11482292SN/A                variant_dir = joinpath(build_root, 'libelf'))
11492292SN/A
11502292SN/A# gzstream build is shared across all configs in the build root.
11512292SN/Amain.SConscript('ext/gzstream/SConscript',
11522301SN/A                variant_dir = joinpath(build_root, 'gzstream'))
11532292SN/A
11542301SN/A# libfdt build is shared across all configs in the build root.
11552292SN/Amain.SConscript('ext/libfdt/SConscript',
11562292SN/A                variant_dir = joinpath(build_root, 'libfdt'))
11572292SN/A
11582292SN/A# fputils build is shared across all configs in the build root.
11592292SN/Amain.SConscript('ext/fputils/SConscript',
11602292SN/A                variant_dir = joinpath(build_root, 'fputils'))
11612292SN/A
11622292SN/A# DRAMSim2 build is shared across all configs in the build root.
11632292SN/Amain.SConscript('ext/dramsim2/SConscript',
11642292SN/A                variant_dir = joinpath(build_root, 'dramsim2'))
11652292SN/A
11662292SN/A###################################################
11672292SN/A#
11682292SN/A# This function is used to set up a directory with switching headers
11692292SN/A#
11702292SN/A###################################################
11712292SN/A
11722292SN/Amain['ALL_ISA_LIST'] = all_isa_list
11732292SN/Adef make_switching_dir(dname, switch_headers, env):
11742292SN/A    # Generate the header.  target[0] is the full path of the output
11752292SN/A    # header to generate.  'source' is a dummy variable, since we get the
11762292SN/A    # list of ISAs from env['ALL_ISA_LIST'].
11772292SN/A    def gen_switch_hdr(target, source, env):
11782292SN/A        fname = str(target[0])
11792292SN/A        f = open(fname, 'w')
11802292SN/A        isa = env['TARGET_ISA'].lower()
11812292SN/A        print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
11822292SN/A        f.close()
11832292SN/A
11842292SN/A    # Build SCons Action object. 'varlist' specifies env vars that this
11852292SN/A    # action depends on; when env['ALL_ISA_LIST'] changes these actions
11862292SN/A    # should get re-executed.
11872292SN/A    switch_hdr_action = MakeAction(gen_switch_hdr,
11882292SN/A                          Transform("GENERATE"), varlist=['ALL_ISA_LIST'])
11892292SN/A
11902292SN/A    # Instantiate actions for each header
11912292SN/A    for hdr in switch_headers:
11922292SN/A        env.Command(hdr, [], switch_hdr_action)
11932292SN/AExport('make_switching_dir')
11942292SN/A
11952292SN/A###################################################
11962292SN/A#
11972292SN/A# Define build environments for selected configurations.
11982292SN/A#
11992292SN/A###################################################
12002292SN/A
12012292SN/Afor variant_path in variant_paths:
12022292SN/A    if not GetOption('silent'):
12032292SN/A        print "Building in", variant_path
12042292SN/A
12052292SN/A    # Make a copy of the build-root environment to use for this config.
12062292SN/A    env = main.Clone()
12072292SN/A    env['BUILDDIR'] = variant_path
12082301SN/A
12092292SN/A    # variant_dir is the tail component of build path, and is used to
12102292SN/A    # determine the build parameters (e.g., 'ALPHA_SE')
12112292SN/A    (build_root, variant_dir) = splitpath(variant_path)
12122292SN/A
12132292SN/A    # Set env variables according to the build directory config.
12142292SN/A    sticky_vars.files = []
12152292SN/A    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
12162292SN/A    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
12172292SN/A    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
12184632Sgblack@eecs.umich.edu    current_vars_file = joinpath(build_root, 'variables', variant_dir)
12192292SN/A    if isfile(current_vars_file):
12202292SN/A        sticky_vars.files.append(current_vars_file)
12212292SN/A        if not GetOption('silent'):
12222292SN/A            print "Using saved variables file %s" % current_vars_file
12232292SN/A    else:
12242292SN/A        # Build dir-specific variables file doesn't exist.
12252292SN/A
12262292SN/A        # Make sure the directory is there so we can create it later
12272292SN/A        opt_dir = dirname(current_vars_file)
12282292SN/A        if not isdir(opt_dir):
12292292SN/A            mkdir(opt_dir)
12302292SN/A
12312292SN/A        # Get default build variables from source tree.  Variables are
12322292SN/A        # normally determined by name of $VARIANT_DIR, but can be
12332292SN/A        # overridden by '--default=' arg on command line.
12342292SN/A        default = GetOption('default')
12352292SN/A        opts_dir = joinpath(main.root.abspath, 'build_opts')
12362292SN/A        if default:
12372292SN/A            default_vars_files = [joinpath(build_root, 'variables', default),
12382292SN/A                                  joinpath(opts_dir, default)]
12392292SN/A        else:
12402292SN/A            default_vars_files = [joinpath(opts_dir, variant_dir)]
12412292SN/A        existing_files = filter(isfile, default_vars_files)
12422292SN/A        if existing_files:
12432292SN/A            default_vars_file = existing_files[0]
12442292SN/A            sticky_vars.files.append(default_vars_file)
12452292SN/A            print "Variables file %s not found,\n  using defaults in %s" \
12462292SN/A                  % (current_vars_file, default_vars_file)
12472292SN/A        else:
12482292SN/A            print "Error: cannot find variables file %s or " \
12493798Sgblack@eecs.umich.edu                  "default file(s) %s" \
12503798Sgblack@eecs.umich.edu                  % (current_vars_file, ' or '.join(default_vars_files))
12513798Sgblack@eecs.umich.edu            Exit(1)
12522292SN/A
12533798Sgblack@eecs.umich.edu    # Apply current variable settings to env
12543798Sgblack@eecs.umich.edu    sticky_vars.Update(env)
12553798Sgblack@eecs.umich.edu
12563798Sgblack@eecs.umich.edu    help_texts["local_vars"] += \
12573798Sgblack@eecs.umich.edu        "Build variables for %s:\n" % variant_dir \
12583798Sgblack@eecs.umich.edu                 + sticky_vars.GenerateHelpText(env)
12593798Sgblack@eecs.umich.edu
12603798Sgblack@eecs.umich.edu    # Process variable settings.
12613788Sgblack@eecs.umich.edu
12623788Sgblack@eecs.umich.edu    if not have_fenv and env['USE_FENV']:
12632292SN/A        print "Warning: <fenv.h> not available; " \
12643788Sgblack@eecs.umich.edu              "forcing USE_FENV to False in", variant_dir + "."
12653788Sgblack@eecs.umich.edu        env['USE_FENV'] = False
12663788Sgblack@eecs.umich.edu
12672292SN/A    if not env['USE_FENV']:
12682292SN/A        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
12692301SN/A        print "         FP results may deviate slightly from other platforms."
12702292SN/A
12712301SN/A    if env['EFENCE']:
12722292SN/A        env.Append(LIBS=['efence'])
12732292SN/A
12742301SN/A    if env['USE_KVM']:
12752292SN/A        if not have_kvm:
12762292SN/A            print "Warning: Can not enable KVM, host seems to lack KVM support"
12772292SN/A            env['USE_KVM'] = False
12782292SN/A        elif not have_posix_timers:
12792292SN/A            print "Warning: Can not enable KVM, host seems to lack support " \
12802292SN/A                "for POSIX timers"
12812292SN/A            env['USE_KVM'] = False
12822301SN/A        elif not is_isa_kvm_compatible(env['TARGET_ISA']):
12832292SN/A            print "Info: KVM support disabled due to unsupported host and " \
12842292SN/A                "target ISA combination"
12852301SN/A            env['USE_KVM'] = False
12862292SN/A
12872292SN/A    # Warn about missing optional functionality
12882301SN/A    if env['USE_KVM']:
12892292SN/A        if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']:
12902301SN/A            print "Warning: perf_event headers lack support for the " \
12912292SN/A                "exclude_host attribute. KVM instruction counts will " \
12922292SN/A                "be inaccurate."
12932292SN/A
12942703Sktlim@umich.edu    # Save sticky variable settings back to current variables file
12952292SN/A    sticky_vars.Save(current_vars_file, env)
12962301SN/A
12972292SN/A    if env['USE_SSE2']:
12982292SN/A        env.Append(CCFLAGS=['-msse2'])
12992292SN/A
13002292SN/A    # The src/SConscript file sets up the build rules in 'env' according
13012292SN/A    # to the configured variables.  It returns a list of environments,
13022292SN/A    # one for each variant build (debug, opt, etc.)
13032292SN/A    envList = SConscript('src/SConscript', variant_dir = variant_path,
13041061SN/A                         exports = 'env')
13051061SN/A
13061060SN/A    # Set up the regression tests for each build.
13071060SN/A    for e in envList:
13082292SN/A        SConscript('tests/SConscript',
13092292SN/A                   variant_dir = joinpath(variant_path, 'tests', e.Label),
13101060SN/A                   exports = { 'env' : e }, duplicate = False)
13112292SN/A
13122292SN/A# base help text
13132292SN/AHelp('''
13141060SN/AUsage: scons [scons options] [build variables] [target(s)]
13151060SN/A
13161060SN/AExtra scons options:
13172292SN/A%(options)s
13182292SN/A
13192292SN/AGlobal build variables:
13202292SN/A%(global_vars)s
13212292SN/A
13222292SN/A%(local_vars)s
13232292SN/A''' % help_texts)
13242292SN/A