SConstruct revision 10181
1955SN/A# -*- mode:python -*-
2955SN/A
311408Sandreas.sandberg@arm.com# Copyright (c) 2013 ARM Limited
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall
79812Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual
89812Sandreas.hansson@arm.com# property including but not limited to intellectual property relating
99812Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software
109812Sandreas.hansson@arm.com# licensed hereunder.  You may use the software subject to the license
119812Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated
129812Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software,
139812Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form.
149812Sandreas.hansson@arm.com#
157816Ssteve.reinhardt@amd.com# Copyright (c) 2011 Advanced Micro Devices, Inc.
165871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company
171762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
18955SN/A# All rights reserved.
19955SN/A#
20955SN/A# Redistribution and use in source and binary forms, with or without
21955SN/A# modification, are permitted provided that the following conditions are
22955SN/A# met: redistributions of source code must retain the above copyright
23955SN/A# notice, this list of conditions and the following disclaimer;
24955SN/A# redistributions in binary form must reproduce the above copyright
25955SN/A# notice, this list of conditions and the following disclaimer in the
26955SN/A# documentation and/or other materials provided with the distribution;
27955SN/A# neither the name of the copyright holders nor the names of its
28955SN/A# contributors may be used to endorse or promote products derived from
29955SN/A# this software without specific prior written permission.
30955SN/A#
31955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
422665Ssaidi@eecs.umich.edu#
432665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
445863Snate@binkert.org#          Nathan Binkert
45955SN/A
46955SN/A###################################################
47955SN/A#
48955SN/A# SCons top-level build description (SConstruct) file.
49955SN/A#
508878Ssteve.reinhardt@amd.com# While in this directory ('gem5'), just type 'scons' to build the default
512632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
528878Ssteve.reinhardt@amd.com# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for
532632Sstever@eecs.umich.edu# the optimized full-system version).
54955SN/A#
558878Ssteve.reinhardt@amd.com# You can build gem5 in a different directory as long as there is a
562632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
572761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
582632Sstever@eecs.umich.edu# built for the same host system.
592632Sstever@eecs.umich.edu#
602632Sstever@eecs.umich.edu# Examples:
612761Sstever@eecs.umich.edu#
622761Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
632761Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
648878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug
658878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug
662761Sstever@eecs.umich.edu#
672761Sstever@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
682761Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
692761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
702761Sstever@eecs.umich.edu#   file.
718878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug
728878Ssteve.reinhardt@amd.com#   % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug
732632Sstever@eecs.umich.edu#
742632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
758878Ssteve.reinhardt@amd.com# 'gem5' directory (or use -u or -C to tell scons where to find this
768878Ssteve.reinhardt@amd.com# file), you can use 'scons -h' to print all the gem5-specific build
772632Sstever@eecs.umich.edu# options as well.
78955SN/A#
79955SN/A###################################################
80955SN/A
815863Snate@binkert.org# Check for recent-enough Python and SCons versions.
825863Snate@binkert.orgtry:
835863Snate@binkert.org    # Really old versions of scons only take two options for the
845863Snate@binkert.org    # function, so check once without the revision and once with the
855863Snate@binkert.org    # revision, the first instance will fail for stuff other than
865863Snate@binkert.org    # 0.98, and the second will fail for 0.98.0
875863Snate@binkert.org    EnsureSConsVersion(0, 98)
885863Snate@binkert.org    EnsureSConsVersion(0, 98, 1)
895863Snate@binkert.orgexcept SystemExit, e:
905863Snate@binkert.org    print """
915863Snate@binkert.orgFor more details, see:
928878Ssteve.reinhardt@amd.com    http://gem5.org/Dependencies
935863Snate@binkert.org"""
945863Snate@binkert.org    raise
955863Snate@binkert.org
969812Sandreas.hansson@arm.com# We ensure the python version early because because python-config
979812Sandreas.hansson@arm.com# requires python 2.5
985863Snate@binkert.orgtry:
999812Sandreas.hansson@arm.com    EnsurePythonVersion(2, 5)
1005863Snate@binkert.orgexcept SystemExit, e:
1015863Snate@binkert.org    print """
1025863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by
1039812Sandreas.hansson@arm.comrearranging your PATH so that scons finds the non-default 'python' and
1049812Sandreas.hansson@arm.com'python-config' first.
1055863Snate@binkert.org
1065863Snate@binkert.orgFor more details, see:
1078878Ssteve.reinhardt@amd.com    http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation
1085863Snate@binkert.org"""
1095863Snate@binkert.org    raise
1105863Snate@binkert.org
1116654Snate@binkert.org# Global Python includes
11210196SCurtis.Dunham@arm.comimport os
113955SN/Aimport re
1145396Ssaidi@eecs.umich.eduimport subprocess
11511401Sandreas.sandberg@arm.comimport sys
1165863Snate@binkert.org
1175863Snate@binkert.orgfrom os import mkdir, environ
1184202Sbinkertn@umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath
1195863Snate@binkert.orgfrom os.path import exists,  isdir, isfile
1205863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath
1215863Snate@binkert.org
1225863Snate@binkert.org# SCons includes
123955SN/Aimport SCons
1246654Snate@binkert.orgimport SCons.Node
1255273Sstever@gmail.com
1265871Snate@binkert.orgextra_python_paths = [
1275273Sstever@gmail.com    Dir('src/python').srcnode().abspath, # gem5 includes
1286655Snate@binkert.org    Dir('ext/ply').srcnode().abspath, # ply is used by several files
1298878Ssteve.reinhardt@amd.com    ]
1306655Snate@binkert.org
1316655Snate@binkert.orgsys.path[1:1] = extra_python_paths
1329219Spower.jg@gmail.com
1336655Snate@binkert.orgfrom m5.util import compareVersions, readCommand
1345871Snate@binkert.orgfrom m5.util.terminal import get_termcap
1356654Snate@binkert.org
1368947Sandreas.hansson@arm.comhelp_texts = {
1375396Ssaidi@eecs.umich.edu    "options" : "",
1388120Sgblack@eecs.umich.edu    "global_vars" : "",
1398120Sgblack@eecs.umich.edu    "local_vars" : ""
1408120Sgblack@eecs.umich.edu}
1418120Sgblack@eecs.umich.edu
1428120Sgblack@eecs.umich.eduExport("help_texts")
1438120Sgblack@eecs.umich.edu
1448120Sgblack@eecs.umich.edu
1458120Sgblack@eecs.umich.edu# There's a bug in scons in that (1) by default, the help texts from
1468879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h'
1478879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the
1488879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once
1498879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get
1508879Ssteve.reinhardt@amd.com# at the help texts from AddOptions.  See:
1518879Ssteve.reinhardt@amd.com#     http://scons.tigris.org/issues/show_bug.cgi?id=2356
1528879Ssteve.reinhardt@amd.com#     http://scons.tigris.org/issues/show_bug.cgi?id=2611
1538879Ssteve.reinhardt@amd.com# This hack lets us extract the help text from AddOptions and
1548879Ssteve.reinhardt@amd.com# re-inject it via Help().  Ideally someday this bug will be fixed and
1558879Ssteve.reinhardt@amd.com# we can just use AddOption directly.
1568879Ssteve.reinhardt@amd.comdef AddLocalOption(*args, **kwargs):
1578879Ssteve.reinhardt@amd.com    col_width = 30
1588879Ssteve.reinhardt@amd.com
1598120Sgblack@eecs.umich.edu    help = "  " + ", ".join(args)
1608120Sgblack@eecs.umich.edu    if "help" in kwargs:
1618120Sgblack@eecs.umich.edu        length = len(help)
1628120Sgblack@eecs.umich.edu        if length >= col_width:
1638120Sgblack@eecs.umich.edu            help += "\n" + " " * col_width
1648120Sgblack@eecs.umich.edu        else:
1658120Sgblack@eecs.umich.edu            help += " " * (col_width - length)
1668120Sgblack@eecs.umich.edu        help += kwargs["help"]
1678120Sgblack@eecs.umich.edu    help_texts["options"] += help + "\n"
1688120Sgblack@eecs.umich.edu
1698120Sgblack@eecs.umich.edu    AddOption(*args, **kwargs)
1708120Sgblack@eecs.umich.edu
1718120Sgblack@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true',
1728120Sgblack@eecs.umich.edu               help="Add color to abbreviated scons output")
1738879Ssteve.reinhardt@amd.comAddLocalOption('--no-colors', dest='use_colors', action='store_false',
1748879Ssteve.reinhardt@amd.com               help="Don't add color to abbreviated scons output")
1758879Ssteve.reinhardt@amd.comAddLocalOption('--default', dest='default', type='string', action='store',
1768879Ssteve.reinhardt@amd.com               help='Override which build_opts file to use for defaults')
17710458Sandreas.hansson@arm.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true',
17810458Sandreas.hansson@arm.com               help='Disable style checking hooks')
17910458Sandreas.hansson@arm.comAddLocalOption('--no-lto', dest='no_lto', action='store_true',
1808879Ssteve.reinhardt@amd.com               help='Disable Link-Time Optimization for fast')
1818879Ssteve.reinhardt@amd.comAddLocalOption('--update-ref', dest='update_ref', action='store_true',
1828879Ssteve.reinhardt@amd.com               help='Update test reference outputs')
1838879Ssteve.reinhardt@amd.comAddLocalOption('--verbose', dest='verbose', action='store_true',
1849227Sandreas.hansson@arm.com               help='Print full tool command lines')
1859227Sandreas.hansson@arm.com
1868879Ssteve.reinhardt@amd.comtermcap = get_termcap(GetOption('use_colors'))
1878879Ssteve.reinhardt@amd.com
1888879Ssteve.reinhardt@amd.com########################################################################
1898879Ssteve.reinhardt@amd.com#
19010453SAndrew.Bardsley@arm.com# Set up the main build environment.
19110453SAndrew.Bardsley@arm.com#
19210453SAndrew.Bardsley@arm.com########################################################################
19310456SCurtis.Dunham@arm.com
19410456SCurtis.Dunham@arm.com# export TERM so that clang reports errors in color
19510456SCurtis.Dunham@arm.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH',
19610457Sandreas.hansson@arm.com                 'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PROTOC',
19710457Sandreas.hansson@arm.com                 'PYTHONPATH', 'RANLIB', 'SWIG', 'TERM' ])
19811342Sandreas.hansson@arm.com
19911342Sandreas.hansson@arm.comuse_prefixes = [
2008120Sgblack@eecs.umich.edu    "M5",           # M5 configuration (e.g., path to kernels)
2018947Sandreas.hansson@arm.com    "DISTCC_",      # distcc (distributed compiler wrapper) configuration
2027816Ssteve.reinhardt@amd.com    "CCACHE_",      # ccache (caching compiler wrapper) configuration
2035871Snate@binkert.org    "CCC_",         # clang static analyzer configuration
2045871Snate@binkert.org    ]
2056121Snate@binkert.org
2065871Snate@binkert.orguse_env = {}
2075871Snate@binkert.orgfor key,val in os.environ.iteritems():
2089926Sstan.czerniawski@arm.com    if key in use_vars or \
2099926Sstan.czerniawski@arm.com            any([key.startswith(prefix) for prefix in use_prefixes]):
2109119Sandreas.hansson@arm.com        use_env[key] = val
21110068Sandreas.hansson@arm.com
21210068Sandreas.hansson@arm.commain = Environment(ENV=use_env)
213955SN/Amain.Decider('MD5-timestamp')
2149416SAndreas.Sandberg@ARM.commain.root = Dir(".")         # The current directory (where this file lives).
21511342Sandreas.hansson@arm.commain.srcdir = Dir("src")     # The source directory
21611212Sjoseph.gross@amd.com
21711212Sjoseph.gross@amd.commain_dict_keys = main.Dictionary().keys()
21811212Sjoseph.gross@amd.com
21911212Sjoseph.gross@amd.com# Check that we have a C/C++ compiler
22011212Sjoseph.gross@amd.comif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys):
2219416SAndreas.Sandberg@ARM.com    print "No C++ compiler installed (package g++ on Ubuntu and RedHat)"
2229416SAndreas.Sandberg@ARM.com    Exit(1)
2235871Snate@binkert.org
22410584Sandreas.hansson@arm.com# Check that swig is present
2259416SAndreas.Sandberg@ARM.comif not 'SWIG' in main_dict_keys:
2269416SAndreas.Sandberg@ARM.com    print "swig is not installed (package swig on Ubuntu and RedHat)"
2275871Snate@binkert.org    Exit(1)
228955SN/A
22910671Sandreas.hansson@arm.com# add useful python code PYTHONPATH so it can be used by subprocesses
23010671Sandreas.hansson@arm.com# as well
23110671Sandreas.hansson@arm.commain.AppendENVPath('PYTHONPATH', extra_python_paths)
23210671Sandreas.hansson@arm.com
2338881Smarc.orr@gmail.com########################################################################
2346121Snate@binkert.org#
2356121Snate@binkert.org# Mercurial Stuff.
2361533SN/A#
2379239Sandreas.hansson@arm.com# If the gem5 directory is a mercurial repository, we should do some
2389239Sandreas.hansson@arm.com# extra things.
2399239Sandreas.hansson@arm.com#
2409239Sandreas.hansson@arm.com########################################################################
2419239Sandreas.hansson@arm.com
2429239Sandreas.hansson@arm.comhgdir = main.root.Dir(".hg")
2439239Sandreas.hansson@arm.com
2449239Sandreas.hansson@arm.commercurial_style_message = """
2459239Sandreas.hansson@arm.comYou're missing the gem5 style hook, which automatically checks your code
2469239Sandreas.hansson@arm.comagainst the gem5 style rules on hg commit and qrefresh commands.  This
2479239Sandreas.hansson@arm.comscript will now install the hook in your .hg/hgrc file.
2489239Sandreas.hansson@arm.comPress enter to continue, or ctrl-c to abort: """
2496655Snate@binkert.org
2506655Snate@binkert.orgmercurial_style_hook = """
2516655Snate@binkert.org# The following lines were automatically added by gem5/SConstruct
2526655Snate@binkert.org# to provide the gem5 style-checking hooks
2535871Snate@binkert.org[extensions]
2545871Snate@binkert.orgstyle = %s/util/style.py
2555863Snate@binkert.org
2565871Snate@binkert.org[hooks]
2578878Ssteve.reinhardt@amd.compretxncommit.style = python:style.check_style
2585871Snate@binkert.orgpre-qrefresh.style = python:style.check_style
2595871Snate@binkert.org# End of SConstruct additions
2605871Snate@binkert.org
2615863Snate@binkert.org""" % (main.root.abspath)
2626121Snate@binkert.org
2635863Snate@binkert.orgmercurial_lib_not_found = """
26411408Sandreas.sandberg@arm.comMercurial libraries cannot be found, ignoring style hook.  If
26511408Sandreas.sandberg@arm.comyou are a gem5 developer, please fix this and run the style
2668336Ssteve.reinhardt@amd.comhook. It is important.
26711469SCurtis.Dunham@arm.com"""
26811469SCurtis.Dunham@arm.com
2698336Ssteve.reinhardt@amd.com# Check for style hook and prompt for installation if it's not there.
2704678Snate@binkert.org# Skip this if --ignore-style was specified, there's no .hg dir to
27111887Sandreas.sandberg@arm.com# install a hook in, or there's no interactive terminal to prompt.
27211887Sandreas.sandberg@arm.comif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty():
27311887Sandreas.sandberg@arm.com    style_hook = True
27411887Sandreas.sandberg@arm.com    try:
27511887Sandreas.sandberg@arm.com        from mercurial import ui
27611887Sandreas.sandberg@arm.com        ui = ui.ui()
27711887Sandreas.sandberg@arm.com        ui.readconfig(hgdir.File('hgrc').abspath)
27811887Sandreas.sandberg@arm.com        style_hook = ui.config('hooks', 'pretxncommit.style', None) and \
27911887Sandreas.sandberg@arm.com                     ui.config('hooks', 'pre-qrefresh.style', None)
28011887Sandreas.sandberg@arm.com    except ImportError:
28111887Sandreas.sandberg@arm.com        print mercurial_lib_not_found
28211408Sandreas.sandberg@arm.com
28311401Sandreas.sandberg@arm.com    if not style_hook:
28411401Sandreas.sandberg@arm.com        print mercurial_style_message,
28511401Sandreas.sandberg@arm.com        # continue unless user does ctrl-c/ctrl-d etc.
28611401Sandreas.sandberg@arm.com        try:
28711401Sandreas.sandberg@arm.com            raw_input()
28811401Sandreas.sandberg@arm.com        except:
2898336Ssteve.reinhardt@amd.com            print "Input exception, exiting scons.\n"
2908336Ssteve.reinhardt@amd.com            sys.exit(1)
2918336Ssteve.reinhardt@amd.com        hgrc_path = '%s/.hg/hgrc' % main.root.abspath
2924678Snate@binkert.org        print "Adding style hook to", hgrc_path, "\n"
29311401Sandreas.sandberg@arm.com        try:
2944678Snate@binkert.org            hgrc = open(hgrc_path, 'a')
2954678Snate@binkert.org            hgrc.write(mercurial_style_hook)
29611401Sandreas.sandberg@arm.com            hgrc.close()
29711401Sandreas.sandberg@arm.com        except:
2988336Ssteve.reinhardt@amd.com            print "Error updating", hgrc_path
2994678Snate@binkert.org            sys.exit(1)
3008336Ssteve.reinhardt@amd.com
3018336Ssteve.reinhardt@amd.com
3028336Ssteve.reinhardt@amd.com###################################################
3038336Ssteve.reinhardt@amd.com#
3048336Ssteve.reinhardt@amd.com# Figure out which configurations to set up based on the path(s) of
3058336Ssteve.reinhardt@amd.com# the target(s).
3065871Snate@binkert.org#
3075871Snate@binkert.org###################################################
3088336Ssteve.reinhardt@amd.com
30911408Sandreas.sandberg@arm.com# Find default configuration & binary.
31011408Sandreas.sandberg@arm.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug'))
31111408Sandreas.sandberg@arm.com
31211408Sandreas.sandberg@arm.com# helper function: find last occurrence of element in list
31311408Sandreas.sandberg@arm.comdef rfind(l, elt, offs = -1):
31411408Sandreas.sandberg@arm.com    for i in range(len(l)+offs, 0, -1):
31511408Sandreas.sandberg@arm.com        if l[i] == elt:
3168336Ssteve.reinhardt@amd.com            return i
31711401Sandreas.sandberg@arm.com    raise ValueError, "element not found"
31811401Sandreas.sandberg@arm.com
31911401Sandreas.sandberg@arm.com# Take a list of paths (or SCons Nodes) and return a list with all
3205871Snate@binkert.org# paths made absolute and ~-expanded.  Paths will be interpreted
3218336Ssteve.reinhardt@amd.com# relative to the launch directory unless a different root is provided
3228336Ssteve.reinhardt@amd.comdef makePathListAbsolute(path_list, root=GetLaunchDir()):
32311401Sandreas.sandberg@arm.com    return [abspath(joinpath(root, expanduser(str(p))))
32411401Sandreas.sandberg@arm.com            for p in path_list]
32511401Sandreas.sandberg@arm.com
32611401Sandreas.sandberg@arm.com# Each target must have 'build' in the interior of the path; the
32711401Sandreas.sandberg@arm.com# directory below this will determine the build parameters.  For
3284678Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
3295871Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it
3304678Snate@binkert.org# follow 'build' in the build path.
33111401Sandreas.sandberg@arm.com
33211401Sandreas.sandberg@arm.com# The funky assignment to "[:]" is needed to replace the list contents
33311401Sandreas.sandberg@arm.com# in place rather than reassign the symbol to a new list, which
33411401Sandreas.sandberg@arm.com# doesn't work (obviously!).
33511401Sandreas.sandberg@arm.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)
33611401Sandreas.sandberg@arm.com
33711401Sandreas.sandberg@arm.com# Generate a list of the unique build roots and configs that the
33811401Sandreas.sandberg@arm.com# collected targets reference.
33911401Sandreas.sandberg@arm.comvariant_paths = []
34011401Sandreas.sandberg@arm.combuild_root = None
34111401Sandreas.sandberg@arm.comfor t in BUILD_TARGETS:
34211401Sandreas.sandberg@arm.com    path_dirs = t.split('/')
34311450Sandreas.sandberg@arm.com    try:
34411450Sandreas.sandberg@arm.com        build_top = rfind(path_dirs, 'build', -2)
34511450Sandreas.sandberg@arm.com    except:
34611450Sandreas.sandberg@arm.com        print "Error: no non-leaf 'build' dir found on target path", t
34711450Sandreas.sandberg@arm.com        Exit(1)
34811450Sandreas.sandberg@arm.com    this_build_root = joinpath('/',*path_dirs[:build_top+1])
34911450Sandreas.sandberg@arm.com    if not build_root:
35011450Sandreas.sandberg@arm.com        build_root = this_build_root
35111450Sandreas.sandberg@arm.com    else:
35211450Sandreas.sandberg@arm.com        if this_build_root != build_root:
35311450Sandreas.sandberg@arm.com            print "Error: build targets not under same build root\n"\
35411401Sandreas.sandberg@arm.com                  "  %s\n  %s" % (build_root, this_build_root)
35511450Sandreas.sandberg@arm.com            Exit(1)
35611450Sandreas.sandberg@arm.com    variant_path = joinpath('/',*path_dirs[:build_top+2])
35711450Sandreas.sandberg@arm.com    if variant_path not in variant_paths:
35811401Sandreas.sandberg@arm.com        variant_paths.append(variant_path)
35911450Sandreas.sandberg@arm.com
36011401Sandreas.sandberg@arm.com# Make sure build_root exists (might not if this is the first build there)
3618336Ssteve.reinhardt@amd.comif not isdir(build_root):
3628336Ssteve.reinhardt@amd.com    mkdir(build_root)
3638336Ssteve.reinhardt@amd.commain['BUILDROOT'] = build_root
3648336Ssteve.reinhardt@amd.com
3658336Ssteve.reinhardt@amd.comExport('main')
3668336Ssteve.reinhardt@amd.com
3678336Ssteve.reinhardt@amd.commain.SConsignFile(joinpath(build_root, "sconsign"))
3688336Ssteve.reinhardt@amd.com
3698336Ssteve.reinhardt@amd.com# Default duplicate option is to use hard links, but this messes up
3708336Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves
37111401Sandreas.sandberg@arm.com# file to file~ then copies to file, breaking the link.  Symbolic
37211401Sandreas.sandberg@arm.com# (soft) links work better.
3738336Ssteve.reinhardt@amd.commain.SetOption('duplicate', 'soft-copy')
3748336Ssteve.reinhardt@amd.com
3758336Ssteve.reinhardt@amd.com#
3765871Snate@binkert.org# Set up global sticky variables... these are common to an entire build
37711476Sandreas.sandberg@arm.com# tree (not specific to a particular build like ALPHA_SE)
37811476Sandreas.sandberg@arm.com#
37911476Sandreas.sandberg@arm.com
38011476Sandreas.sandberg@arm.comglobal_vars_file = joinpath(build_root, 'variables.global')
38111476Sandreas.sandberg@arm.com
38211476Sandreas.sandberg@arm.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS)
38311476Sandreas.sandberg@arm.com
38411476Sandreas.sandberg@arm.comglobal_vars.AddVariables(
38511476Sandreas.sandberg@arm.com    ('CC', 'C compiler', environ.get('CC', main['CC'])),
38611887Sandreas.sandberg@arm.com    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
38711887Sandreas.sandberg@arm.com    ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])),
38811887Sandreas.sandberg@arm.com    ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')),
38911408Sandreas.sandberg@arm.com    ('BATCH', 'Use batch pool for build and tests', False),
39011887Sandreas.sandberg@arm.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
39111887Sandreas.sandberg@arm.com    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
39211887Sandreas.sandberg@arm.com    ('EXTRAS', 'Add extra directories to the compilation', '')
39311887Sandreas.sandberg@arm.com    )
39411887Sandreas.sandberg@arm.com
39511887Sandreas.sandberg@arm.com# Update main environment with values from ARGUMENTS & global_vars_file
39611887Sandreas.sandberg@arm.comglobal_vars.Update(main)
39711887Sandreas.sandberg@arm.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main)
39811887Sandreas.sandberg@arm.com
39911887Sandreas.sandberg@arm.com# Save sticky variable settings back to current variables file
40011887Sandreas.sandberg@arm.comglobal_vars.Save(global_vars_file, main)
40111887Sandreas.sandberg@arm.com
40211887Sandreas.sandberg@arm.com# Parse EXTRAS variable to build list of all directories where we're
40311887Sandreas.sandberg@arm.com# look for sources etc.  This list is exported as extras_dir_list.
40411887Sandreas.sandberg@arm.combase_dir = main.srcdir.abspath
40511887Sandreas.sandberg@arm.comif main['EXTRAS']:
40611887Sandreas.sandberg@arm.com    extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':'))
40711887Sandreas.sandberg@arm.comelse:
40811887Sandreas.sandberg@arm.com    extras_dir_list = []
40911887Sandreas.sandberg@arm.com
41011887Sandreas.sandberg@arm.comExport('base_dir')
41111887Sandreas.sandberg@arm.comExport('extras_dir_list')
41211887Sandreas.sandberg@arm.com
41311887Sandreas.sandberg@arm.com# the ext directory should be on the #includes path
41411476Sandreas.sandberg@arm.commain.Append(CPPPATH=[Dir('ext')])
41511476Sandreas.sandberg@arm.com
41611408Sandreas.sandberg@arm.comdef strip_build_path(path, env):
41711408Sandreas.sandberg@arm.com    path = str(path)
41811408Sandreas.sandberg@arm.com    variant_base = env['BUILDROOT'] + os.path.sep
41911408Sandreas.sandberg@arm.com    if path.startswith(variant_base):
42011408Sandreas.sandberg@arm.com        path = path[len(variant_base):]
42111408Sandreas.sandberg@arm.com    elif path.startswith('build/'):
42211408Sandreas.sandberg@arm.com        path = path[6:]
42311887Sandreas.sandberg@arm.com    return path
42411887Sandreas.sandberg@arm.com
42511476Sandreas.sandberg@arm.com# Generate a string of the form:
42611887Sandreas.sandberg@arm.com#   common/path/prefix/src1, src2 -> tgt1, tgt2
42711887Sandreas.sandberg@arm.com# to print while building.
42811476Sandreas.sandberg@arm.comclass Transform(object):
42911476Sandreas.sandberg@arm.com    # all specific color settings should be here and nowhere else
43011476Sandreas.sandberg@arm.com    tool_color = termcap.Normal
43111476Sandreas.sandberg@arm.com    pfx_color = termcap.Yellow
4326121Snate@binkert.org    srcs_color = termcap.Yellow + termcap.Bold
433955SN/A    arrow_color = termcap.Blue + termcap.Bold
434955SN/A    tgts_color = termcap.Yellow + termcap.Bold
4352632Sstever@eecs.umich.edu
4362632Sstever@eecs.umich.edu    def __init__(self, tool, max_sources=99):
437955SN/A        self.format = self.tool_color + (" [%8s] " % tool) \
438955SN/A                      + self.pfx_color + "%s" \
439955SN/A                      + self.srcs_color + "%s" \
440955SN/A                      + self.arrow_color + " -> " \
4418878Ssteve.reinhardt@amd.com                      + self.tgts_color + "%s" \
442955SN/A                      + termcap.Normal
4432632Sstever@eecs.umich.edu        self.max_sources = max_sources
4442632Sstever@eecs.umich.edu
4452632Sstever@eecs.umich.edu    def __call__(self, target, source, env, for_signature=None):
4462632Sstever@eecs.umich.edu        # truncate source list according to max_sources param
4472632Sstever@eecs.umich.edu        source = source[0:self.max_sources]
4482632Sstever@eecs.umich.edu        def strip(f):
4492632Sstever@eecs.umich.edu            return strip_build_path(str(f), env)
4508268Ssteve.reinhardt@amd.com        if len(source) > 0:
4518268Ssteve.reinhardt@amd.com            srcs = map(strip, source)
4528268Ssteve.reinhardt@amd.com        else:
4538268Ssteve.reinhardt@amd.com            srcs = ['']
4548268Ssteve.reinhardt@amd.com        tgts = map(strip, target)
4558268Ssteve.reinhardt@amd.com        # surprisingly, os.path.commonprefix is a dumb char-by-char string
4568268Ssteve.reinhardt@amd.com        # operation that has nothing to do with paths.
4572632Sstever@eecs.umich.edu        com_pfx = os.path.commonprefix(srcs + tgts)
4582632Sstever@eecs.umich.edu        com_pfx_len = len(com_pfx)
4592632Sstever@eecs.umich.edu        if com_pfx:
4602632Sstever@eecs.umich.edu            # do some cleanup and sanity checking on common prefix
4618268Ssteve.reinhardt@amd.com            if com_pfx[-1] == ".":
4622632Sstever@eecs.umich.edu                # prefix matches all but file extension: ok
4638268Ssteve.reinhardt@amd.com                # back up one to change 'foo.cc -> o' to 'foo.cc -> .o'
4648268Ssteve.reinhardt@amd.com                com_pfx = com_pfx[0:-1]
4658268Ssteve.reinhardt@amd.com            elif com_pfx[-1] == "/":
4668268Ssteve.reinhardt@amd.com                # common prefix is directory path: OK
4673718Sstever@eecs.umich.edu                pass
4682634Sstever@eecs.umich.edu            else:
4692634Sstever@eecs.umich.edu                src0_len = len(srcs[0])
4705863Snate@binkert.org                tgt0_len = len(tgts[0])
4712638Sstever@eecs.umich.edu                if src0_len == com_pfx_len:
4728268Ssteve.reinhardt@amd.com                    # source is a substring of target, OK
4732632Sstever@eecs.umich.edu                    pass
4742632Sstever@eecs.umich.edu                elif tgt0_len == com_pfx_len:
4752632Sstever@eecs.umich.edu                    # target is a substring of source, need to back up to
4762632Sstever@eecs.umich.edu                    # avoid empty string on RHS of arrow
4772632Sstever@eecs.umich.edu                    sep_idx = com_pfx.rfind(".")
4781858SN/A                    if sep_idx != -1:
4793716Sstever@eecs.umich.edu                        com_pfx = com_pfx[0:sep_idx]
4802638Sstever@eecs.umich.edu                    else:
4812638Sstever@eecs.umich.edu                        com_pfx = ''
4822638Sstever@eecs.umich.edu                elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".":
4832638Sstever@eecs.umich.edu                    # still splitting at file extension: ok
4842638Sstever@eecs.umich.edu                    pass
4852638Sstever@eecs.umich.edu                else:
4862638Sstever@eecs.umich.edu                    # probably a fluke; ignore it
4875863Snate@binkert.org                    com_pfx = ''
4885863Snate@binkert.org        # recalculate length in case com_pfx was modified
4895863Snate@binkert.org        com_pfx_len = len(com_pfx)
490955SN/A        def fmt(files):
4915341Sstever@gmail.com            f = map(lambda s: s[com_pfx_len:], files)
4925341Sstever@gmail.com            return ', '.join(f)
4935863Snate@binkert.org        return self.format % (com_pfx, fmt(srcs), fmt(tgts))
4947756SAli.Saidi@ARM.com
4955341Sstever@gmail.comExport('Transform')
4966121Snate@binkert.org
4974494Ssaidi@eecs.umich.edu# enable the regression script to use the termcap
4986121Snate@binkert.orgmain['TERMCAP'] = termcap
4991105SN/A
5002667Sstever@eecs.umich.eduif GetOption('verbose'):
5012667Sstever@eecs.umich.edu    def MakeAction(action, string, *args, **kwargs):
5022667Sstever@eecs.umich.edu        return Action(action, *args, **kwargs)
5032667Sstever@eecs.umich.eduelse:
5046121Snate@binkert.org    MakeAction = Action
5052667Sstever@eecs.umich.edu    main['CCCOMSTR']        = Transform("CC")
5065341Sstever@gmail.com    main['CXXCOMSTR']       = Transform("CXX")
5075863Snate@binkert.org    main['ASCOMSTR']        = Transform("AS")
5085341Sstever@gmail.com    main['SWIGCOMSTR']      = Transform("SWIG")
5095341Sstever@gmail.com    main['ARCOMSTR']        = Transform("AR", 0)
5105341Sstever@gmail.com    main['LINKCOMSTR']      = Transform("LINK", 0)
5118120Sgblack@eecs.umich.edu    main['RANLIBCOMSTR']    = Transform("RANLIB", 0)
5125341Sstever@gmail.com    main['M4COMSTR']        = Transform("M4")
5138120Sgblack@eecs.umich.edu    main['SHCCCOMSTR']      = Transform("SHCC")
5145341Sstever@gmail.com    main['SHCXXCOMSTR']     = Transform("SHCXX")
5158120Sgblack@eecs.umich.eduExport('MakeAction')
5166121Snate@binkert.org
5176121Snate@binkert.org# Initialize the Link-Time Optimization (LTO) flags
5188980Ssteve.reinhardt@amd.commain['LTO_CCFLAGS'] = []
5199396Sandreas.hansson@arm.commain['LTO_LDFLAGS'] = []
5205397Ssaidi@eecs.umich.edu
5215397Ssaidi@eecs.umich.edu# According to the readme, tcmalloc works best if the compiler doesn't
5227727SAli.Saidi@ARM.com# assume that we're using the builtin malloc and friends. These flags
5238268Ssteve.reinhardt@amd.com# are compiler-specific, so we need to set them after we detect which
5246168Snate@binkert.org# compiler we're using.
5255341Sstever@gmail.commain['TCMALLOC_CCFLAGS'] = []
5268120Sgblack@eecs.umich.edu
5278120Sgblack@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False)
5288120Sgblack@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False)
5296814Sgblack@eecs.umich.edu
5305863Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
5318120Sgblack@eecs.umich.edumain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0
5325341Sstever@gmail.comif main['GCC'] + main['CLANG'] > 1:
5335863Snate@binkert.org    print 'Error: How can we have two at the same time?'
5348268Ssteve.reinhardt@amd.com    Exit(1)
5356121Snate@binkert.org
5366121Snate@binkert.org# Set up default C++ compiler flags
5378268Ssteve.reinhardt@amd.comif main['GCC'] or main['CLANG']:
5385742Snate@binkert.org    # As gcc and clang share many flags, do the common parts here
5395742Snate@binkert.org    main.Append(CCFLAGS=['-pipe'])
5405341Sstever@gmail.com    main.Append(CCFLAGS=['-fno-strict-aliasing'])
5415742Snate@binkert.org    # Enable -Wall and then disable the few warnings that we
5425742Snate@binkert.org    # consistently violate
5435341Sstever@gmail.com    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
5446017Snate@binkert.org    # We always compile using C++11, but only gcc >= 4.7 and clang 3.1
5456121Snate@binkert.org    # actually use that name, so we stick with c++0x
5466017Snate@binkert.org    main.Append(CXXFLAGS=['-std=c++0x'])
5477816Ssteve.reinhardt@amd.com    # Add selected sanity checks from -Wextra
5487756SAli.Saidi@ARM.com    main.Append(CXXFLAGS=['-Wmissing-field-initializers',
5497756SAli.Saidi@ARM.com                          '-Woverloaded-virtual'])
5507756SAli.Saidi@ARM.comelse:
5517756SAli.Saidi@ARM.com    print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal,
5527756SAli.Saidi@ARM.com    print "Don't know what compiler options to use for your compiler."
5537756SAli.Saidi@ARM.com    print termcap.Yellow + '       compiler:' + termcap.Normal, main['CXX']
5547756SAli.Saidi@ARM.com    print termcap.Yellow + '       version:' + termcap.Normal,
5557756SAli.Saidi@ARM.com    if not CXX_version:
5567816Ssteve.reinhardt@amd.com        print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\
5577816Ssteve.reinhardt@amd.com               termcap.Normal
5587816Ssteve.reinhardt@amd.com    else:
5597816Ssteve.reinhardt@amd.com        print CXX_version.replace('\n', '<nl>')
5607816Ssteve.reinhardt@amd.com    print "       If you're trying to use a compiler other than GCC"
5617816Ssteve.reinhardt@amd.com    print "       or clang, there appears to be something wrong with your"
5627816Ssteve.reinhardt@amd.com    print "       environment."
5637816Ssteve.reinhardt@amd.com    print "       "
5647816Ssteve.reinhardt@amd.com    print "       If you are trying to use a compiler other than those listed"
5657816Ssteve.reinhardt@amd.com    print "       above you will need to ease fix SConstruct and "
5667756SAli.Saidi@ARM.com    print "       src/SConscript to support that compiler."
5677816Ssteve.reinhardt@amd.com    Exit(1)
5687816Ssteve.reinhardt@amd.com
5697816Ssteve.reinhardt@amd.comif main['GCC']:
5707816Ssteve.reinhardt@amd.com    # Check for a supported version of gcc, >= 4.4 is needed for c++0x
5717816Ssteve.reinhardt@amd.com    # support. See http://gcc.gnu.org/projects/cxx0x.html for details
5727816Ssteve.reinhardt@amd.com    gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False)
5737816Ssteve.reinhardt@amd.com    if compareVersions(gcc_version, "4.4") < 0:
5747816Ssteve.reinhardt@amd.com        print 'Error: gcc version 4.4 or newer required.'
5757816Ssteve.reinhardt@amd.com        print '       Installed version:', gcc_version
5767816Ssteve.reinhardt@amd.com        Exit(1)
5777816Ssteve.reinhardt@amd.com
5787816Ssteve.reinhardt@amd.com    main['GCC_VERSION'] = gcc_version
5797816Ssteve.reinhardt@amd.com
5807816Ssteve.reinhardt@amd.com    # Check for versions with bugs
5817816Ssteve.reinhardt@amd.com    if not compareVersions(gcc_version, '4.4.1') or \
5827816Ssteve.reinhardt@amd.com       not compareVersions(gcc_version, '4.4.2'):
5837816Ssteve.reinhardt@amd.com        print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.'
5847816Ssteve.reinhardt@amd.com        main.Append(CCFLAGS=['-fno-tree-vectorize'])
5857816Ssteve.reinhardt@amd.com
5867816Ssteve.reinhardt@amd.com    # LTO support is only really working properly from 4.6 and beyond
5877816Ssteve.reinhardt@amd.com    if compareVersions(gcc_version, '4.6') >= 0:
5887816Ssteve.reinhardt@amd.com        # Add the appropriate Link-Time Optimization (LTO) flags
5897816Ssteve.reinhardt@amd.com        # unless LTO is explicitly turned off. Note that these flags
5907816Ssteve.reinhardt@amd.com        # are only used by the fast target.
5917816Ssteve.reinhardt@amd.com        if not GetOption('no_lto'):
5927816Ssteve.reinhardt@amd.com            # Pass the LTO flag when compiling to produce GIMPLE
5937816Ssteve.reinhardt@amd.com            # output, we merely create the flags here and only append
5947816Ssteve.reinhardt@amd.com            # them later/
5957816Ssteve.reinhardt@amd.com            main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')]
5967816Ssteve.reinhardt@amd.com
5977816Ssteve.reinhardt@amd.com            # Use the same amount of jobs for LTO as we are running
5987816Ssteve.reinhardt@amd.com            # scons with, we hardcode the use of the linker plugin
5997816Ssteve.reinhardt@amd.com            # which requires either gold or GNU ld >= 2.21
6007816Ssteve.reinhardt@amd.com            main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'),
6017816Ssteve.reinhardt@amd.com                                   '-fuse-linker-plugin']
6027816Ssteve.reinhardt@amd.com
6037816Ssteve.reinhardt@amd.com    main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc',
6047816Ssteve.reinhardt@amd.com                                  '-fno-builtin-realloc', '-fno-builtin-free'])
6057816Ssteve.reinhardt@amd.com
6067816Ssteve.reinhardt@amd.comelif main['CLANG']:
6077816Ssteve.reinhardt@amd.com    # Check for a supported version of clang, >= 2.9 is needed to
6087816Ssteve.reinhardt@amd.com    # support similar features as gcc 4.4. See
6097816Ssteve.reinhardt@amd.com    # http://clang.llvm.org/cxx_status.html for details
6107816Ssteve.reinhardt@amd.com    clang_version_re = re.compile(".* version (\d+\.\d+)")
6117816Ssteve.reinhardt@amd.com    clang_version_match = clang_version_re.search(CXX_version)
6127816Ssteve.reinhardt@amd.com    if (clang_version_match):
6137816Ssteve.reinhardt@amd.com        clang_version = clang_version_match.groups()[0]
6147816Ssteve.reinhardt@amd.com        if compareVersions(clang_version, "2.9") < 0:
6157816Ssteve.reinhardt@amd.com            print 'Error: clang version 2.9 or newer required.'
6167816Ssteve.reinhardt@amd.com            print '       Installed version:', clang_version
6177816Ssteve.reinhardt@amd.com            Exit(1)
6187816Ssteve.reinhardt@amd.com    else:
6197816Ssteve.reinhardt@amd.com        print 'Error: Unable to determine clang version.'
6207816Ssteve.reinhardt@amd.com        Exit(1)
6217816Ssteve.reinhardt@amd.com
6227816Ssteve.reinhardt@amd.com    # clang has a few additional warnings that we disable,
6237816Ssteve.reinhardt@amd.com    # tautological comparisons are allowed due to unsigned integers
6247816Ssteve.reinhardt@amd.com    # being compared to constants that happen to be 0, and extraneous
6257816Ssteve.reinhardt@amd.com    # parantheses are allowed due to Ruby's printing of the AST,
6267816Ssteve.reinhardt@amd.com    # finally self assignments are allowed as the generated CPU code
6277816Ssteve.reinhardt@amd.com    # is relying on this
6288947Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-Wno-tautological-compare',
6298947Sandreas.hansson@arm.com                         '-Wno-parentheses',
6307756SAli.Saidi@ARM.com                         '-Wno-self-assign'])
6318120Sgblack@eecs.umich.edu
6327756SAli.Saidi@ARM.com    main.Append(TCMALLOC_CCFLAGS=['-fno-builtin'])
6337756SAli.Saidi@ARM.com
6347756SAli.Saidi@ARM.com    # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as
6357756SAli.Saidi@ARM.com    # opposed to libstdc++, as the later is dated.
6367816Ssteve.reinhardt@amd.com    if sys.platform == "darwin":
6377816Ssteve.reinhardt@amd.com        main.Append(CXXFLAGS=['-stdlib=libc++'])
6387816Ssteve.reinhardt@amd.com        main.Append(LIBS=['c++'])
6397816Ssteve.reinhardt@amd.com
6407816Ssteve.reinhardt@amd.comelse:
6417816Ssteve.reinhardt@amd.com    print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal,
6427816Ssteve.reinhardt@amd.com    print "Don't know what compiler options to use for your compiler."
6437816Ssteve.reinhardt@amd.com    print termcap.Yellow + '       compiler:' + termcap.Normal, main['CXX']
6447816Ssteve.reinhardt@amd.com    print termcap.Yellow + '       version:' + termcap.Normal,
6457816Ssteve.reinhardt@amd.com    if not CXX_version:
6467756SAli.Saidi@ARM.com        print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\
6477756SAli.Saidi@ARM.com               termcap.Normal
6489227Sandreas.hansson@arm.com    else:
6499227Sandreas.hansson@arm.com        print CXX_version.replace('\n', '<nl>')
6509227Sandreas.hansson@arm.com    print "       If you're trying to use a compiler other than GCC"
6519227Sandreas.hansson@arm.com    print "       or clang, there appears to be something wrong with your"
6529590Sandreas@sandberg.pp.se    print "       environment."
6539590Sandreas@sandberg.pp.se    print "       "
6549590Sandreas@sandberg.pp.se    print "       If you are trying to use a compiler other than those listed"
6559590Sandreas@sandberg.pp.se    print "       above you will need to ease fix SConstruct and "
6569590Sandreas@sandberg.pp.se    print "       src/SConscript to support that compiler."
6579590Sandreas@sandberg.pp.se    Exit(1)
6586654Snate@binkert.org
6596654Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby)
6605871Snate@binkert.orgmain['YACCFLAGS'] = '-d'
6616121Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh'
6628946Sandreas.hansson@arm.com
6639419Sandreas.hansson@arm.com# Do this after we save setting back, or else we'll tack on an
6643940Ssaidi@eecs.umich.edu# extra 'qdo' every time we run scons.
6653918Ssaidi@eecs.umich.eduif main['BATCH']:
6663918Ssaidi@eecs.umich.edu    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
6671858SN/A    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
6689556Sandreas.hansson@arm.com    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
6699556Sandreas.hansson@arm.com    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
6709556Sandreas.hansson@arm.com    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
6719556Sandreas.hansson@arm.com
67211294Sandreas.hansson@arm.comif sys.platform == 'cygwin':
67311294Sandreas.hansson@arm.com    # cygwin has some header file issues...
67411294Sandreas.hansson@arm.com    main.Append(CCFLAGS=["-Wno-uninitialized"])
67511294Sandreas.hansson@arm.com
67610878Sandreas.hansson@arm.com# Check for the protobuf compiler
67710878Sandreas.hansson@arm.comprotoc_version = readCommand([main['PROTOC'], '--version'],
67811811Sbaz21@cam.ac.uk                             exception='').split()
67911811Sbaz21@cam.ac.uk
68011811Sbaz21@cam.ac.uk# First two words should be "libprotoc x.y.z"
6819556Sandreas.hansson@arm.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc':
6829556Sandreas.hansson@arm.com    print termcap.Yellow + termcap.Bold + \
6839556Sandreas.hansson@arm.com        'Warning: Protocol buffer compiler (protoc) not found.\n' + \
6849556Sandreas.hansson@arm.com        '         Please install protobuf-compiler for tracing support.' + \
6859556Sandreas.hansson@arm.com        termcap.Normal
6869556Sandreas.hansson@arm.com    main['PROTOC'] = False
6879556Sandreas.hansson@arm.comelse:
6889556Sandreas.hansson@arm.com    # Based on the availability of the compress stream wrappers,
6899556Sandreas.hansson@arm.com    # require 2.1.0
6909556Sandreas.hansson@arm.com    min_protoc_version = '2.1.0'
6919556Sandreas.hansson@arm.com    if compareVersions(protoc_version[1], min_protoc_version) < 0:
6929556Sandreas.hansson@arm.com        print termcap.Yellow + termcap.Bold + \
6939556Sandreas.hansson@arm.com            'Warning: protoc version', min_protoc_version, \
6949556Sandreas.hansson@arm.com            'or newer required.\n' + \
6959556Sandreas.hansson@arm.com            '         Installed version:', protoc_version[1], \
6969556Sandreas.hansson@arm.com            termcap.Normal
6979556Sandreas.hansson@arm.com        main['PROTOC'] = False
6989556Sandreas.hansson@arm.com    else:
6999556Sandreas.hansson@arm.com        # Attempt to determine the appropriate include path and
7006121Snate@binkert.org        # library path using pkg-config, that means we also need to
70111500Sandreas.hansson@arm.com        # check for pkg-config. Note that it is possible to use
70210238Sandreas.hansson@arm.com        # protobuf without the involvement of pkg-config. Later on we
70310878Sandreas.hansson@arm.com        # check go a library config check and at that point the test
7049420Sandreas.hansson@arm.com        # will fail if libprotobuf cannot be found.
70511500Sandreas.hansson@arm.com        if readCommand(['pkg-config', '--version'], exception=''):
70611500Sandreas.hansson@arm.com            try:
7079420Sandreas.hansson@arm.com                # Attempt to establish what linking flags to add for protobuf
7089420Sandreas.hansson@arm.com                # using pkg-config
7099420Sandreas.hansson@arm.com                main.ParseConfig('pkg-config --cflags --libs-only-L protobuf')
7109420Sandreas.hansson@arm.com            except:
7119420Sandreas.hansson@arm.com                print termcap.Yellow + termcap.Bold + \
71210264Sandreas.hansson@arm.com                    'Warning: pkg-config could not get protobuf flags.' + \
71310264Sandreas.hansson@arm.com                    termcap.Normal
71410264Sandreas.hansson@arm.com
71510264Sandreas.hansson@arm.com# Check for SWIG
71611925Sgabeblack@google.comif not main.has_key('SWIG'):
71711925Sgabeblack@google.com    print 'Error: SWIG utility not found.'
71811500Sandreas.hansson@arm.com    print '       Please install (see http://www.swig.org) and retry.'
71910264Sandreas.hansson@arm.com    Exit(1)
72011500Sandreas.hansson@arm.com
72111500Sandreas.hansson@arm.com# Check for appropriate SWIG version
72211500Sandreas.hansson@arm.comswig_version = readCommand([main['SWIG'], '-version'], exception='').split()
72311500Sandreas.hansson@arm.com# First 3 words should be "SWIG Version x.y.z"
72410866Sandreas.hansson@arm.comif len(swig_version) < 3 or \
72511500Sandreas.hansson@arm.com        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
72611500Sandreas.hansson@arm.com    print 'Error determining SWIG version.'
72711500Sandreas.hansson@arm.com    Exit(1)
72811500Sandreas.hansson@arm.com
72911500Sandreas.hansson@arm.commin_swig_version = '2.0.4'
73011500Sandreas.hansson@arm.comif compareVersions(swig_version[2], min_swig_version) < 0:
73111500Sandreas.hansson@arm.com    print 'Error: SWIG version', min_swig_version, 'or newer required.'
73210264Sandreas.hansson@arm.com    print '       Installed version:', swig_version[2]
73310457Sandreas.hansson@arm.com    Exit(1)
73410457Sandreas.hansson@arm.com
73510457Sandreas.hansson@arm.com# Set up SWIG flags & scanner
73610457Sandreas.hansson@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
73710457Sandreas.hansson@arm.commain.Append(SWIGFLAGS=swig_flags)
73810457Sandreas.hansson@arm.com
73910457Sandreas.hansson@arm.com# filter out all existing swig scanners, they mess up the dependency
74010457Sandreas.hansson@arm.com# stuff for some reason
74110457Sandreas.hansson@arm.comscanners = []
74210238Sandreas.hansson@arm.comfor scanner in main['SCANNERS']:
74310238Sandreas.hansson@arm.com    skeys = scanner.skeys
74410238Sandreas.hansson@arm.com    if skeys == '.i':
74510238Sandreas.hansson@arm.com        continue
74610238Sandreas.hansson@arm.com
74710238Sandreas.hansson@arm.com    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
74810416Sandreas.hansson@arm.com        continue
74910238Sandreas.hansson@arm.com
7509227Sandreas.hansson@arm.com    scanners.append(scanner)
75110238Sandreas.hansson@arm.com
75210416Sandreas.hansson@arm.com# add the new swig scanner that we like better
75310416Sandreas.hansson@arm.comfrom SCons.Scanner import ClassicCPP as CPPScanner
7549227Sandreas.hansson@arm.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
7559590Sandreas@sandberg.pp.sescanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
7569590Sandreas@sandberg.pp.se
7579590Sandreas@sandberg.pp.se# replace the scanners list that has what we want
75811497SMatteo.Andreozzi@arm.commain['SCANNERS'] = scanners
75911497SMatteo.Andreozzi@arm.com
76011497SMatteo.Andreozzi@arm.com# Add a custom Check function to the Configure context so that we can
76111497SMatteo.Andreozzi@arm.com# figure out if the compiler adds leading underscores to global
7628737Skoansin.tan@gmail.com# variables.  This is needed for the autogenerated asm files that we
76310878Sandreas.hansson@arm.com# use for embedding the python code.
76411500Sandreas.hansson@arm.comdef CheckLeading(context):
7659420Sandreas.hansson@arm.com    context.Message("Checking for leading underscore in global variables...")
7668737Skoansin.tan@gmail.com    # 1) Define a global variable called x from asm so the C compiler
76710106SMitch.Hayenga@arm.com    #    won't change the symbol at all.
7688737Skoansin.tan@gmail.com    # 2) Declare that variable.
7698737Skoansin.tan@gmail.com    # 3) Use the variable
77010878Sandreas.hansson@arm.com    #
77110878Sandreas.hansson@arm.com    # If the compiler prepends an underscore, this will successfully
7728737Skoansin.tan@gmail.com    # link because the external symbol 'x' will be called '_x' which
7738737Skoansin.tan@gmail.com    # was defined by the asm statement.  If the compiler does not
7748737Skoansin.tan@gmail.com    # prepend an underscore, this will not successfully link because
7758737Skoansin.tan@gmail.com    # '_x' will have been defined by assembly, while the C portion of
7768737Skoansin.tan@gmail.com    # the code will be trying to use 'x'
7778737Skoansin.tan@gmail.com    ret = context.TryLink('''
77811294Sandreas.hansson@arm.com        asm(".globl _x; _x: .byte 0");
7799556Sandreas.hansson@arm.com        extern int x;
7809556Sandreas.hansson@arm.com        int main() { return x; }
7819556Sandreas.hansson@arm.com        ''', extension=".c")
78211294Sandreas.hansson@arm.com    context.env.Append(LEADING_UNDERSCORE=ret)
78310278SAndreas.Sandberg@ARM.com    context.Result(ret)
78410278SAndreas.Sandberg@ARM.com    return ret
78510278SAndreas.Sandberg@ARM.com
78610278SAndreas.Sandberg@ARM.com# Add a custom Check function to test for structure members.
78710278SAndreas.Sandberg@ARM.comdef CheckMember(context, include, decl, member, include_quotes="<>"):
78810278SAndreas.Sandberg@ARM.com    context.Message("Checking for member %s in %s..." %
7899556Sandreas.hansson@arm.com                    (member, decl))
7909590Sandreas@sandberg.pp.se    text = """
7919590Sandreas@sandberg.pp.se#include %(header)s
7929420Sandreas.hansson@arm.comint main(){
7939846Sandreas.hansson@arm.com  %(decl)s test;
7949846Sandreas.hansson@arm.com  (void)test.%(member)s;
7959846Sandreas.hansson@arm.com  return 0;
7969846Sandreas.hansson@arm.com};
7978946Sandreas.hansson@arm.com""" % { "header" : include_quotes[0] + include + include_quotes[1],
79811811Sbaz21@cam.ac.uk        "decl" : decl,
79911811Sbaz21@cam.ac.uk        "member" : member,
80011811Sbaz21@cam.ac.uk        }
80111811Sbaz21@cam.ac.uk
8023918Ssaidi@eecs.umich.edu    ret = context.TryCompile(text, extension=".cc")
8039068SAli.Saidi@ARM.com    context.Result(ret)
8049068SAli.Saidi@ARM.com    return ret
8059068SAli.Saidi@ARM.com
8069068SAli.Saidi@ARM.com# Platform-specific configuration.  Note again that we assume that all
8079068SAli.Saidi@ARM.com# builds under a given build root run on the same host platform.
8089068SAli.Saidi@ARM.comconf = Configure(main,
8099068SAli.Saidi@ARM.com                 conf_dir = joinpath(build_root, '.scons_config'),
8109068SAli.Saidi@ARM.com                 log_file = joinpath(build_root, 'scons_config.log'),
8119068SAli.Saidi@ARM.com                 custom_tests = {
8129419Sandreas.hansson@arm.com        'CheckLeading' : CheckLeading,
8139068SAli.Saidi@ARM.com        'CheckMember' : CheckMember,
8149068SAli.Saidi@ARM.com        })
8159068SAli.Saidi@ARM.com
8169068SAli.Saidi@ARM.com# Check for leading underscores.  Don't really need to worry either
8179068SAli.Saidi@ARM.com# way so don't need to check the return code.
8189068SAli.Saidi@ARM.comconf.CheckLeading()
8193918Ssaidi@eecs.umich.edu
8203918Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
8216157Snate@binkert.orgtry:
8226157Snate@binkert.org    import platform
8236157Snate@binkert.org    uname = platform.uname()
8246157Snate@binkert.org    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
8255397Ssaidi@eecs.umich.edu        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
8265397Ssaidi@eecs.umich.edu            main.Append(CCFLAGS=['-arch', 'x86_64'])
8276121Snate@binkert.org            main.Append(CFLAGS=['-arch', 'x86_64'])
8286121Snate@binkert.org            main.Append(LINKFLAGS=['-arch', 'x86_64'])
8296121Snate@binkert.org            main.Append(ASFLAGS=['-arch', 'x86_64'])
8306121Snate@binkert.orgexcept:
8316121Snate@binkert.org    pass
8326121Snate@binkert.org
8335397Ssaidi@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure()
8341851SN/A# when configuration isn't necessary, e.g., if the "--help" option is
8351851SN/A# present.  Unfortuantely this Null object always returns false,
8367739Sgblack@eecs.umich.edu# breaking all our configuration checks.  We replace it with our own
837955SN/A# more optimistic null object that returns True instead.
8389396Sandreas.hansson@arm.comif not conf:
8399396Sandreas.hansson@arm.com    def NullCheck(*args, **kwargs):
8409396Sandreas.hansson@arm.com        return True
8419396Sandreas.hansson@arm.com
8429396Sandreas.hansson@arm.com    class NullConf:
8439396Sandreas.hansson@arm.com        def __init__(self, env):
8449396Sandreas.hansson@arm.com            self.env = env
8459396Sandreas.hansson@arm.com        def Finish(self):
8469396Sandreas.hansson@arm.com            return self.env
8479396Sandreas.hansson@arm.com        def __getattr__(self, mname):
8489396Sandreas.hansson@arm.com            return NullCheck
8499396Sandreas.hansson@arm.com
8509396Sandreas.hansson@arm.com    conf = NullConf(main)
8519396Sandreas.hansson@arm.com
8529396Sandreas.hansson@arm.com# Cache build files in the supplied directory.
8539396Sandreas.hansson@arm.comif main['M5_BUILD_CACHE']:
8549477Sandreas.hansson@arm.com    print 'Using build cache located at', main['M5_BUILD_CACHE']
8559477Sandreas.hansson@arm.com    CacheDir(main['M5_BUILD_CACHE'])
8569477Sandreas.hansson@arm.com
8579477Sandreas.hansson@arm.com# Find Python include and library directories for embedding the
8589477Sandreas.hansson@arm.com# interpreter. We rely on python-config to resolve the appropriate
8599477Sandreas.hansson@arm.com# includes and linker flags. ParseConfig does not seem to understand
8609477Sandreas.hansson@arm.com# the more exotic linker flags such as -Xlinker and -export-dynamic so
8619477Sandreas.hansson@arm.com# we add them explicitly below. If you want to link in an alternate
8629477Sandreas.hansson@arm.com# version of python, see above for instructions on how to invoke
8639477Sandreas.hansson@arm.com# scons with the appropriate PATH set.
8649477Sandreas.hansson@arm.com#
8659477Sandreas.hansson@arm.com# First we check if python2-config exists, else we use python-config
8669477Sandreas.hansson@arm.compython_config = readCommand(['which', 'python2-config'], exception='').strip()
8679477Sandreas.hansson@arm.comif not os.path.exists(python_config):
8689477Sandreas.hansson@arm.com    python_config = readCommand(['which', 'python-config'],
8699477Sandreas.hansson@arm.com                                exception='').strip()
8709477Sandreas.hansson@arm.compy_includes = readCommand([python_config, '--includes'],
8719477Sandreas.hansson@arm.com                          exception='').split()
8729477Sandreas.hansson@arm.com# Strip the -I from the include folders before adding them to the
8739477Sandreas.hansson@arm.com# CPPPATH
8749477Sandreas.hansson@arm.commain.Append(CPPPATH=map(lambda inc: inc[2:], py_includes))
8759477Sandreas.hansson@arm.com
8769396Sandreas.hansson@arm.com# Read the linker flags and split them into libraries and other link
8773053Sstever@eecs.umich.edu# flags. The libraries are added later through the call the CheckLib.
8786121Snate@binkert.orgpy_ld_flags = readCommand([python_config, '--ldflags'], exception='').split()
8793053Sstever@eecs.umich.edupy_libs = []
8803053Sstever@eecs.umich.edufor lib in py_ld_flags:
8813053Sstever@eecs.umich.edu     if not lib.startswith('-l'):
8823053Sstever@eecs.umich.edu         main.Append(LINKFLAGS=[lib])
8833053Sstever@eecs.umich.edu     else:
8849072Sandreas.hansson@arm.com         lib = lib[2:]
8853053Sstever@eecs.umich.edu         if lib not in py_libs:
8864742Sstever@eecs.umich.edu             py_libs.append(lib)
8874742Sstever@eecs.umich.edu
8883053Sstever@eecs.umich.edu# verify that this stuff works
8893053Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
8903053Sstever@eecs.umich.edu    print "Error: can't find Python.h header in", py_includes
89110181SCurtis.Dunham@arm.com    print "Install Python headers (package python-dev on Ubuntu and RedHat)"
8926654Snate@binkert.org    Exit(1)
8933053Sstever@eecs.umich.edu
8943053Sstever@eecs.umich.edufor lib in py_libs:
8953053Sstever@eecs.umich.edu    if not conf.CheckLib(lib):
8963053Sstever@eecs.umich.edu        print "Error: can't find library %s required by python" % lib
89710425Sandreas.hansson@arm.com        Exit(1)
89810425Sandreas.hansson@arm.com
89910425Sandreas.hansson@arm.com# On Solaris you need to use libsocket for socket ops
90010425Sandreas.hansson@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
90110425Sandreas.hansson@arm.com   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
90210425Sandreas.hansson@arm.com       print "Can't find library with socket calls (e.g. accept())"
90310425Sandreas.hansson@arm.com       Exit(1)
90410425Sandreas.hansson@arm.com
90510425Sandreas.hansson@arm.com# Check for zlib.  If the check passes, libz will be automatically
90610425Sandreas.hansson@arm.com# added to the LIBS environment variable.
90710425Sandreas.hansson@arm.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
9082667Sstever@eecs.umich.edu    print 'Error: did not find needed zlib compression library '\
9094554Sbinkertn@umich.edu          'and/or zlib.h header file.'
9106121Snate@binkert.org    print '       Please install zlib and try again.'
9112667Sstever@eecs.umich.edu    Exit(1)
91210710Sandreas.hansson@arm.com
91310710Sandreas.hansson@arm.com# If we have the protobuf compiler, also make sure we have the
91410710Sandreas.hansson@arm.com# development libraries. If the check passes, libprotobuf will be
91511811Sbaz21@cam.ac.uk# automatically added to the LIBS environment variable. After
91611811Sbaz21@cam.ac.uk# this, we can use the HAVE_PROTOBUF flag to determine if we have
91711811Sbaz21@cam.ac.uk# got both protoc and libprotobuf available.
91811811Sbaz21@cam.ac.ukmain['HAVE_PROTOBUF'] = main['PROTOC'] and \
91911811Sbaz21@cam.ac.uk    conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h',
92011811Sbaz21@cam.ac.uk                            'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;')
92110710Sandreas.hansson@arm.com
92210710Sandreas.hansson@arm.com# If we have the compiler but not the library, print another warning.
92310710Sandreas.hansson@arm.comif main['PROTOC'] and not main['HAVE_PROTOBUF']:
92410710Sandreas.hansson@arm.com    print termcap.Yellow + termcap.Bold + \
92510384SCurtis.Dunham@arm.com        'Warning: did not find protocol buffer library and/or headers.\n' + \
9264554Sbinkertn@umich.edu    '       Please install libprotobuf-dev for tracing support.' + \
9274554Sbinkertn@umich.edu    termcap.Normal
9284554Sbinkertn@umich.edu
9296121Snate@binkert.org# Check for librt.
9304554Sbinkertn@umich.eduhave_posix_clock = \
9314554Sbinkertn@umich.edu    conf.CheckLibWithHeader(None, 'time.h', 'C',
9324554Sbinkertn@umich.edu                            'clock_nanosleep(0,0,NULL,NULL);') or \
9334781Snate@binkert.org    conf.CheckLibWithHeader('rt', 'time.h', 'C',
9344554Sbinkertn@umich.edu                            'clock_nanosleep(0,0,NULL,NULL);')
9354554Sbinkertn@umich.edu
9362667Sstever@eecs.umich.eduhave_posix_timers = \
9374554Sbinkertn@umich.edu    conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C',
9384554Sbinkertn@umich.edu                            'timer_create(CLOCK_MONOTONIC, NULL, NULL);')
9394554Sbinkertn@umich.edu
9404554Sbinkertn@umich.eduif conf.CheckLib('tcmalloc'):
9412667Sstever@eecs.umich.edu    main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS'])
9424554Sbinkertn@umich.eduelif conf.CheckLib('tcmalloc_minimal'):
9432667Sstever@eecs.umich.edu    main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS'])
9444554Sbinkertn@umich.eduelse:
9456121Snate@binkert.org    print termcap.Yellow + termcap.Bold + \
9462667Sstever@eecs.umich.edu          "You can get a 12% performance improvement by installing tcmalloc "\
9479986Sandreas@sandberg.pp.se          "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \
9489986Sandreas@sandberg.pp.se          termcap.Normal
9499986Sandreas@sandberg.pp.se
9509986Sandreas@sandberg.pp.seif not have_posix_clock:
9519986Sandreas@sandberg.pp.se    print "Can't find library for POSIX clocks."
9529986Sandreas@sandberg.pp.se
9539986Sandreas@sandberg.pp.se# Check for <fenv.h> (C99 FP environment control)
9549986Sandreas@sandberg.pp.sehave_fenv = conf.CheckHeader('fenv.h', '<>')
9559986Sandreas@sandberg.pp.seif not have_fenv:
9569986Sandreas@sandberg.pp.se    print "Warning: Header file <fenv.h> not found."
9579986Sandreas@sandberg.pp.se    print "         This host has no IEEE FP rounding mode control."
9589986Sandreas@sandberg.pp.se
9599986Sandreas@sandberg.pp.se# Check if we should enable KVM-based hardware virtualization. The API
9609986Sandreas@sandberg.pp.se# we rely on exists since version 2.6.36 of the kernel, but somehow
9619986Sandreas@sandberg.pp.se# the KVM_API_VERSION does not reflect the change. We test for one of
9629986Sandreas@sandberg.pp.se# the types as a fall back.
9639986Sandreas@sandberg.pp.sehave_kvm = conf.CheckHeader('linux/kvm.h', '<>') and \
9649986Sandreas@sandberg.pp.se    conf.CheckTypeSize('struct kvm_xsave', '#include <linux/kvm.h>') != 0
9659986Sandreas@sandberg.pp.seif not have_kvm:
9669986Sandreas@sandberg.pp.se    print "Info: Compatible header file <linux/kvm.h> not found, " \
9672638Sstever@eecs.umich.edu        "disabling KVM support."
9682638Sstever@eecs.umich.edu
9696121Snate@binkert.org# Check if the requested target ISA is compatible with the host
9703716Sstever@eecs.umich.edudef is_isa_kvm_compatible(isa):
9715522Snate@binkert.org    isa_comp_table = {
9729986Sandreas@sandberg.pp.se        "arm" : ( "armv7l" ),
9739986Sandreas@sandberg.pp.se        "x86" : ( "x86_64" ),
9749986Sandreas@sandberg.pp.se        }
9755522Snate@binkert.org    try:
9765227Ssaidi@eecs.umich.edu        import platform
9775227Ssaidi@eecs.umich.edu        host_isa = platform.machine()
9785227Ssaidi@eecs.umich.edu    except:
9795227Ssaidi@eecs.umich.edu        print "Warning: Failed to determine host ISA."
9806654Snate@binkert.org        return False
9816654Snate@binkert.org
9827769SAli.Saidi@ARM.com    return host_isa in isa_comp_table.get(isa, [])
9837769SAli.Saidi@ARM.com
9847769SAli.Saidi@ARM.com
9857769SAli.Saidi@ARM.com# Check if the exclude_host attribute is available. We want this to
9865227Ssaidi@eecs.umich.edu# get accurate instruction counts in KVM.
9875227Ssaidi@eecs.umich.edumain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember(
9885227Ssaidi@eecs.umich.edu    'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host')
9895204Sstever@gmail.com
9905204Sstever@gmail.com
9915204Sstever@gmail.com######################################################################
9925204Sstever@gmail.com#
9935204Sstever@gmail.com# Finish the configuration
9945204Sstever@gmail.com#
9955204Sstever@gmail.commain = conf.Finish()
9965204Sstever@gmail.com
9975204Sstever@gmail.com######################################################################
9985204Sstever@gmail.com#
9995204Sstever@gmail.com# Collect all non-global variables
10005204Sstever@gmail.com#
10015204Sstever@gmail.com
10025204Sstever@gmail.com# Define the universe of supported ISAs
10035204Sstever@gmail.comall_isa_list = [ ]
10045204Sstever@gmail.comExport('all_isa_list')
10055204Sstever@gmail.com
10066121Snate@binkert.orgclass CpuModel(object):
10075204Sstever@gmail.com    '''The CpuModel class encapsulates everything the ISA parser needs to
10087727SAli.Saidi@ARM.com    know about a particular CPU model.'''
10097727SAli.Saidi@ARM.com
10107727SAli.Saidi@ARM.com    # Dict of available CPU model objects.  Accessible as CpuModel.dict.
10117727SAli.Saidi@ARM.com    dict = {}
10127727SAli.Saidi@ARM.com    list = []
101310453SAndrew.Bardsley@arm.com    defaults = []
101410453SAndrew.Bardsley@arm.com
101510453SAndrew.Bardsley@arm.com    # Constructor.  Automatically adds models to CpuModel.dict.
101610453SAndrew.Bardsley@arm.com    def __init__(self, name, filename, includes, strings, default=False):
101710453SAndrew.Bardsley@arm.com        self.name = name           # name of model
101810453SAndrew.Bardsley@arm.com        self.filename = filename   # filename for output exec code
101910453SAndrew.Bardsley@arm.com        self.includes = includes   # include files needed in exec file
102010453SAndrew.Bardsley@arm.com        # The 'strings' dict holds all the per-CPU symbols we can
102110453SAndrew.Bardsley@arm.com        # substitute into templates etc.
102210453SAndrew.Bardsley@arm.com        self.strings = strings
102310453SAndrew.Bardsley@arm.com
102410160Sandreas.hansson@arm.com        # This cpu is enabled by default
102510453SAndrew.Bardsley@arm.com        self.default = default
102610453SAndrew.Bardsley@arm.com
102710453SAndrew.Bardsley@arm.com        # Add self to dict
102810453SAndrew.Bardsley@arm.com        if name in CpuModel.dict:
102910453SAndrew.Bardsley@arm.com            raise AttributeError, "CpuModel '%s' already registered" % name
103010453SAndrew.Bardsley@arm.com        CpuModel.dict[name] = self
103110453SAndrew.Bardsley@arm.com        CpuModel.list.append(name)
103210453SAndrew.Bardsley@arm.com
10339812Sandreas.hansson@arm.comExport('CpuModel')
103410453SAndrew.Bardsley@arm.com
103510453SAndrew.Bardsley@arm.com# Sticky variables get saved in the variables file so they persist from
103610453SAndrew.Bardsley@arm.com# one invocation to the next (unless overridden, in which case the new
103710453SAndrew.Bardsley@arm.com# value becomes sticky).
103810453SAndrew.Bardsley@arm.comsticky_vars = Variables(args=ARGUMENTS)
103910453SAndrew.Bardsley@arm.comExport('sticky_vars')
104010453SAndrew.Bardsley@arm.com
104110453SAndrew.Bardsley@arm.com# Sticky variables that should be exported
104210453SAndrew.Bardsley@arm.comexport_vars = []
104310453SAndrew.Bardsley@arm.comExport('export_vars')
104410453SAndrew.Bardsley@arm.com
104510453SAndrew.Bardsley@arm.com# For Ruby
10467727SAli.Saidi@ARM.comall_protocols = []
104710453SAndrew.Bardsley@arm.comExport('all_protocols')
104810453SAndrew.Bardsley@arm.comprotocol_dirs = []
104910453SAndrew.Bardsley@arm.comExport('protocol_dirs')
105010453SAndrew.Bardsley@arm.comslicc_includes = []
105110453SAndrew.Bardsley@arm.comExport('slicc_includes')
10523118Sstever@eecs.umich.edu
105310453SAndrew.Bardsley@arm.com# Walk the tree and execute all SConsopts scripts that wil add to the
105410453SAndrew.Bardsley@arm.com# above variables
105510453SAndrew.Bardsley@arm.comif GetOption('verbose'):
105610453SAndrew.Bardsley@arm.com    print "Reading SConsopts"
10573118Sstever@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list:
10583483Ssaidi@eecs.umich.edu    if not isdir(bdir):
10593494Ssaidi@eecs.umich.edu        print "Error: directory '%s' does not exist" % bdir
10603494Ssaidi@eecs.umich.edu        Exit(1)
10613483Ssaidi@eecs.umich.edu    for root, dirs, files in os.walk(bdir):
10623483Ssaidi@eecs.umich.edu        if 'SConsopts' in files:
10633483Ssaidi@eecs.umich.edu            if GetOption('verbose'):
10643053Sstever@eecs.umich.edu                print "Reading", joinpath(root, 'SConsopts')
10653053Sstever@eecs.umich.edu            SConscript(joinpath(root, 'SConsopts'))
10663918Ssaidi@eecs.umich.edu
10673053Sstever@eecs.umich.eduall_isa_list.sort()
10683053Sstever@eecs.umich.edu
10693053Sstever@eecs.umich.edusticky_vars.AddVariables(
10703053Sstever@eecs.umich.edu    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
10713053Sstever@eecs.umich.edu    ListVariable('CPU_MODELS', 'CPU models',
10729396Sandreas.hansson@arm.com                 sorted(n for n,m in CpuModel.dict.iteritems() if m.default),
10739396Sandreas.hansson@arm.com                 sorted(CpuModel.list)),
10749396Sandreas.hansson@arm.com    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
10759396Sandreas.hansson@arm.com                 False),
10769396Sandreas.hansson@arm.com    BoolVariable('SS_COMPATIBLE_FP',
10779396Sandreas.hansson@arm.com                 'Make floating-point results compatible with SimpleScalar',
10789396Sandreas.hansson@arm.com                 False),
10799396Sandreas.hansson@arm.com    BoolVariable('USE_SSE2',
10809396Sandreas.hansson@arm.com                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
10819477Sandreas.hansson@arm.com                 False),
10829396Sandreas.hansson@arm.com    BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
10839477Sandreas.hansson@arm.com    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
10849477Sandreas.hansson@arm.com    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
10859477Sandreas.hansson@arm.com    BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm),
10869477Sandreas.hansson@arm.com    EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None',
10879396Sandreas.hansson@arm.com                  all_protocols),
10887840Snate@binkert.org    )
10897865Sgblack@eecs.umich.edu
10907865Sgblack@eecs.umich.edu# These variables get exported to #defines in config/*.hh (see src/SConscript).
10917865Sgblack@eecs.umich.eduexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'CP_ANNOTATE',
10927865Sgblack@eecs.umich.edu                'USE_POSIX_CLOCK', 'PROTOCOL', 'HAVE_PROTOBUF',
10937865Sgblack@eecs.umich.edu                'HAVE_PERF_ATTR_EXCLUDE_HOST']
10947840Snate@binkert.org
10959900Sandreas@sandberg.pp.se###################################################
10969900Sandreas@sandberg.pp.se#
10979900Sandreas@sandberg.pp.se# Define a SCons builder for configuration flag headers.
10989900Sandreas@sandberg.pp.se#
109910456SCurtis.Dunham@arm.com###################################################
110010456SCurtis.Dunham@arm.com
110110456SCurtis.Dunham@arm.com# This function generates a config header file that #defines the
110210456SCurtis.Dunham@arm.com# variable symbol to the current variable setting (0 or 1).  The source
110310456SCurtis.Dunham@arm.com# operands are the name of the variable and a Value node containing the
110410456SCurtis.Dunham@arm.com# value of the variable.
110510456SCurtis.Dunham@arm.comdef build_config_file(target, source, env):
110610456SCurtis.Dunham@arm.com    (variable, value) = [s.get_contents() for s in source]
110710456SCurtis.Dunham@arm.com    f = file(str(target[0]), 'w')
110810456SCurtis.Dunham@arm.com    print >> f, '#define', variable, value
11099045SAli.Saidi@ARM.com    f.close()
111011235Sandreas.sandberg@arm.com    return None
111111235Sandreas.sandberg@arm.com
111211235Sandreas.sandberg@arm.com# Combine the two functions into a scons Action object.
111311235Sandreas.sandberg@arm.comconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2))
111411235Sandreas.sandberg@arm.com
111511235Sandreas.sandberg@arm.com# The emitter munges the source & target node lists to reflect what
111611235Sandreas.sandberg@arm.com# we're really doing.
111711235Sandreas.sandberg@arm.comdef config_emitter(target, source, env):
111811811Sbaz21@cam.ac.uk    # extract variable name from Builder arg
111911811Sbaz21@cam.ac.uk    variable = str(target[0])
112011811Sbaz21@cam.ac.uk    # True target is config header file
112111811Sbaz21@cam.ac.uk    target = joinpath('config', variable.lower() + '.hh')
112211811Sbaz21@cam.ac.uk    val = env[variable]
112311235Sandreas.sandberg@arm.com    if isinstance(val, bool):
112411235Sandreas.sandberg@arm.com        # Force value to 0/1
112511235Sandreas.sandberg@arm.com        val = int(val)
112611235Sandreas.sandberg@arm.com    elif isinstance(val, str):
112711235Sandreas.sandberg@arm.com        val = '"' + val + '"'
112811235Sandreas.sandberg@arm.com
112911235Sandreas.sandberg@arm.com    # Sources are variable name & value (packaged in SCons Value nodes)
11307840Snate@binkert.org    return ([target], [Value(variable), Value(val)])
11317840Snate@binkert.org
11327840Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action)
11331858SN/A
11341858SN/Amain.Append(BUILDERS = { 'ConfigFile' : config_builder })
11351858SN/A
11361858SN/A# libelf build is shared across all configs in the build root.
11371858SN/Amain.SConscript('ext/libelf/SConscript',
11381858SN/A                variant_dir = joinpath(build_root, 'libelf'))
11399903Sandreas.hansson@arm.com
11409903Sandreas.hansson@arm.com# gzstream build is shared across all configs in the build root.
11419903Sandreas.hansson@arm.commain.SConscript('ext/gzstream/SConscript',
11429903Sandreas.hansson@arm.com                variant_dir = joinpath(build_root, 'gzstream'))
114310841Sandreas.sandberg@arm.com
11449651SAndreas.Sandberg@ARM.com# libfdt build is shared across all configs in the build root.
11459903Sandreas.hansson@arm.commain.SConscript('ext/libfdt/SConscript',
11469651SAndreas.Sandberg@ARM.com                variant_dir = joinpath(build_root, 'libfdt'))
11479651SAndreas.Sandberg@ARM.com
114810841Sandreas.sandberg@arm.com# fputils build is shared across all configs in the build root.
114910841Sandreas.sandberg@arm.commain.SConscript('ext/fputils/SConscript',
115010841Sandreas.sandberg@arm.com                variant_dir = joinpath(build_root, 'fputils'))
115110841Sandreas.sandberg@arm.com
115210841Sandreas.sandberg@arm.com# DRAMSim2 build is shared across all configs in the build root.
115310841Sandreas.sandberg@arm.commain.SConscript('ext/dramsim2/SConscript',
11549651SAndreas.Sandberg@ARM.com                variant_dir = joinpath(build_root, 'dramsim2'))
11559651SAndreas.Sandberg@ARM.com
11569651SAndreas.Sandberg@ARM.com###################################################
11579651SAndreas.Sandberg@ARM.com#
11589651SAndreas.Sandberg@ARM.com# This function is used to set up a directory with switching headers
11599651SAndreas.Sandberg@ARM.com#
11609651SAndreas.Sandberg@ARM.com###################################################
11619651SAndreas.Sandberg@ARM.com
11629651SAndreas.Sandberg@ARM.commain['ALL_ISA_LIST'] = all_isa_list
116310841Sandreas.sandberg@arm.comdef make_switching_dir(dname, switch_headers, env):
116410841Sandreas.sandberg@arm.com    # Generate the header.  target[0] is the full path of the output
116510841Sandreas.sandberg@arm.com    # header to generate.  'source' is a dummy variable, since we get the
116610841Sandreas.sandberg@arm.com    # list of ISAs from env['ALL_ISA_LIST'].
116710841Sandreas.sandberg@arm.com    def gen_switch_hdr(target, source, env):
116810841Sandreas.sandberg@arm.com        fname = str(target[0])
116910860Sandreas.sandberg@arm.com        f = open(fname, 'w')
117010841Sandreas.sandberg@arm.com        isa = env['TARGET_ISA'].lower()
117110841Sandreas.sandberg@arm.com        print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
117210841Sandreas.sandberg@arm.com        f.close()
117310841Sandreas.sandberg@arm.com
117410841Sandreas.sandberg@arm.com    # Build SCons Action object. 'varlist' specifies env vars that this
117510841Sandreas.sandberg@arm.com    # action depends on; when env['ALL_ISA_LIST'] changes these actions
117610841Sandreas.sandberg@arm.com    # should get re-executed.
117710841Sandreas.sandberg@arm.com    switch_hdr_action = MakeAction(gen_switch_hdr,
117810841Sandreas.sandberg@arm.com                          Transform("GENERATE"), varlist=['ALL_ISA_LIST'])
117910841Sandreas.sandberg@arm.com
118010841Sandreas.sandberg@arm.com    # Instantiate actions for each header
11819651SAndreas.Sandberg@ARM.com    for hdr in switch_headers:
11829651SAndreas.Sandberg@ARM.com        env.Command(hdr, [], switch_hdr_action)
11839986Sandreas@sandberg.pp.seExport('make_switching_dir')
11849986Sandreas@sandberg.pp.se
11859986Sandreas@sandberg.pp.se###################################################
11869986Sandreas@sandberg.pp.se#
11879986Sandreas@sandberg.pp.se# Define build environments for selected configurations.
11889986Sandreas@sandberg.pp.se#
11895863Snate@binkert.org###################################################
11905863Snate@binkert.org
11915863Snate@binkert.orgfor variant_path in variant_paths:
11925863Snate@binkert.org    if not GetOption('silent'):
11936121Snate@binkert.org        print "Building in", variant_path
11941858SN/A
11955863Snate@binkert.org    # Make a copy of the build-root environment to use for this config.
11965863Snate@binkert.org    env = main.Clone()
11975863Snate@binkert.org    env['BUILDDIR'] = variant_path
11985863Snate@binkert.org
11995863Snate@binkert.org    # variant_dir is the tail component of build path, and is used to
12002139SN/A    # determine the build parameters (e.g., 'ALPHA_SE')
12014202Sbinkertn@umich.edu    (build_root, variant_dir) = splitpath(variant_path)
120211308Santhony.gutierrez@amd.com
12034202Sbinkertn@umich.edu    # Set env variables according to the build directory config.
120411308Santhony.gutierrez@amd.com    sticky_vars.files = []
12052139SN/A    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
12066994Snate@binkert.org    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
12076994Snate@binkert.org    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
12086994Snate@binkert.org    current_vars_file = joinpath(build_root, 'variables', variant_dir)
12096994Snate@binkert.org    if isfile(current_vars_file):
12106994Snate@binkert.org        sticky_vars.files.append(current_vars_file)
12116994Snate@binkert.org        if not GetOption('silent'):
12126994Snate@binkert.org            print "Using saved variables file %s" % current_vars_file
12136994Snate@binkert.org    else:
121410319SAndreas.Sandberg@ARM.com        # Build dir-specific variables file doesn't exist.
12156994Snate@binkert.org
12166994Snate@binkert.org        # Make sure the directory is there so we can create it later
12176994Snate@binkert.org        opt_dir = dirname(current_vars_file)
12186994Snate@binkert.org        if not isdir(opt_dir):
12196994Snate@binkert.org            mkdir(opt_dir)
12206994Snate@binkert.org
12216994Snate@binkert.org        # Get default build variables from source tree.  Variables are
12226994Snate@binkert.org        # normally determined by name of $VARIANT_DIR, but can be
12236994Snate@binkert.org        # overridden by '--default=' arg on command line.
12246994Snate@binkert.org        default = GetOption('default')
12256994Snate@binkert.org        opts_dir = joinpath(main.root.abspath, 'build_opts')
12262155SN/A        if default:
12275863Snate@binkert.org            default_vars_files = [joinpath(build_root, 'variables', default),
12281869SN/A                                  joinpath(opts_dir, default)]
12291869SN/A        else:
12305863Snate@binkert.org            default_vars_files = [joinpath(opts_dir, variant_dir)]
12315863Snate@binkert.org        existing_files = filter(isfile, default_vars_files)
12324202Sbinkertn@umich.edu        if existing_files:
12336108Snate@binkert.org            default_vars_file = existing_files[0]
12346108Snate@binkert.org            sticky_vars.files.append(default_vars_file)
12356108Snate@binkert.org            print "Variables file %s not found,\n  using defaults in %s" \
12366108Snate@binkert.org                  % (current_vars_file, default_vars_file)
12379219Spower.jg@gmail.com        else:
12389219Spower.jg@gmail.com            print "Error: cannot find variables file %s or " \
12399219Spower.jg@gmail.com                  "default file(s) %s" \
12409219Spower.jg@gmail.com                  % (current_vars_file, ' or '.join(default_vars_files))
12419219Spower.jg@gmail.com            Exit(1)
12429219Spower.jg@gmail.com
12439219Spower.jg@gmail.com    # Apply current variable settings to env
12449219Spower.jg@gmail.com    sticky_vars.Update(env)
12454202Sbinkertn@umich.edu
12465863Snate@binkert.org    help_texts["local_vars"] += \
124710135SCurtis.Dunham@arm.com        "Build variables for %s:\n" % variant_dir \
12488474Sgblack@eecs.umich.edu                 + sticky_vars.GenerateHelpText(env)
12495742Snate@binkert.org
12508268Ssteve.reinhardt@amd.com    # Process variable settings.
12518268Ssteve.reinhardt@amd.com
12528268Ssteve.reinhardt@amd.com    if not have_fenv and env['USE_FENV']:
12535742Snate@binkert.org        print "Warning: <fenv.h> not available; " \
12545341Sstever@gmail.com              "forcing USE_FENV to False in", variant_dir + "."
12558474Sgblack@eecs.umich.edu        env['USE_FENV'] = False
12568474Sgblack@eecs.umich.edu
12575342Sstever@gmail.com    if not env['USE_FENV']:
12584202Sbinkertn@umich.edu        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
12594202Sbinkertn@umich.edu        print "         FP results may deviate slightly from other platforms."
126011308Santhony.gutierrez@amd.com
12614202Sbinkertn@umich.edu    if env['EFENCE']:
12625863Snate@binkert.org        env.Append(LIBS=['efence'])
12635863Snate@binkert.org
126411308Santhony.gutierrez@amd.com    if env['USE_KVM']:
12656994Snate@binkert.org        if not have_kvm:
12666994Snate@binkert.org            print "Warning: Can not enable KVM, host seems to lack KVM support"
126710319SAndreas.Sandberg@ARM.com            env['USE_KVM'] = False
12685863Snate@binkert.org        elif not have_posix_timers:
12695863Snate@binkert.org            print "Warning: Can not enable KVM, host seems to lack support " \
12705863Snate@binkert.org                "for POSIX timers"
12715863Snate@binkert.org            env['USE_KVM'] = False
12725863Snate@binkert.org        elif not is_isa_kvm_compatible(env['TARGET_ISA']):
12735863Snate@binkert.org            print "Info: KVM support disabled due to unsupported host and " \
12745863Snate@binkert.org                "target ISA combination"
12755863Snate@binkert.org            env['USE_KVM'] = False
12767840Snate@binkert.org
12775863Snate@binkert.org    # Warn about missing optional functionality
12785952Ssaidi@eecs.umich.edu    if env['USE_KVM']:
12799651SAndreas.Sandberg@ARM.com        if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']:
128011308Santhony.gutierrez@amd.com            print "Warning: perf_event headers lack support for the " \
12819219Spower.jg@gmail.com                "exclude_host attribute. KVM instruction counts will " \
12829219Spower.jg@gmail.com                "be inaccurate."
128311235Sandreas.sandberg@arm.com
128411235Sandreas.sandberg@arm.com    # Save sticky variable settings back to current variables file
12851869SN/A    sticky_vars.Save(current_vars_file, env)
12861858SN/A
12875863Snate@binkert.org    if env['USE_SSE2']:
128811308Santhony.gutierrez@amd.com        env.Append(CCFLAGS=['-msse2'])
128911308Santhony.gutierrez@amd.com
129011308Santhony.gutierrez@amd.com    # The src/SConscript file sets up the build rules in 'env' according
12911858SN/A    # to the configured variables.  It returns a list of environments,
1292955SN/A    # one for each variant build (debug, opt, etc.)
1293955SN/A    envList = SConscript('src/SConscript', variant_dir = variant_path,
12941869SN/A                         exports = 'env')
12951869SN/A
12961869SN/A    # Set up the regression tests for each build.
12971869SN/A    for e in envList:
12981869SN/A        SConscript('tests/SConscript',
12995863Snate@binkert.org                   variant_dir = joinpath(variant_path, 'tests', e.Label),
13005863Snate@binkert.org                   exports = { 'env' : e }, duplicate = False)
13015863Snate@binkert.org
13021869SN/A# base help text
13035863Snate@binkert.orgHelp('''
13041869SN/AUsage: scons [scons options] [build variables] [target(s)]
13055863Snate@binkert.org
13061869SN/AExtra scons options:
13071869SN/A%(options)s
13081869SN/A
13091869SN/AGlobal build variables:
13108483Sgblack@eecs.umich.edu%(global_vars)s
13111869SN/A
13121869SN/A%(local_vars)s
13131869SN/A''' % help_texts)
13141869SN/A