SConstruct revision 8878
1955SN/A# -*- mode:python -*-
2955SN/A
39812Sandreas.hansson@arm.com# Copyright (c) 2011 Advanced Micro Devices, Inc.
49812Sandreas.hansson@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company
59812Sandreas.hansson@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
69812Sandreas.hansson@arm.com# All rights reserved.
79812Sandreas.hansson@arm.com#
89812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
99812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
109812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
129812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
139812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
149812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
157816Ssteve.reinhardt@amd.com# neither the name of the copyright holders nor the names of its
165871Snate@binkert.org# contributors may be used to endorse or promote products derived from
171762SN/A# this software without specific prior written permission.
18955SN/A#
19955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30955SN/A#
31955SN/A# Authors: Steve Reinhardt
32955SN/A#          Nathan Binkert
33955SN/A
34955SN/A###################################################
35955SN/A#
36955SN/A# SCons top-level build description (SConstruct) file.
37955SN/A#
38955SN/A# While in this directory ('gem5'), just type 'scons' to build the default
39955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
40955SN/A# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for
41955SN/A# the optimized full-system version).
422665Ssaidi@eecs.umich.edu#
432665Ssaidi@eecs.umich.edu# You can build gem5 in a different directory as long as there is a
445863Snate@binkert.org# 'build/<CONFIG>' somewhere along the target path.  The build system
45955SN/A# expects that all configs under the same build directory are being
46955SN/A# built for the same host system.
47955SN/A#
48955SN/A# Examples:
49955SN/A#
508878Ssteve.reinhardt@amd.com#   The following two commands are equivalent.  The '-u' option tells
512632Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
528878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug
532632Sstever@eecs.umich.edu#   % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug
54955SN/A#
558878Ssteve.reinhardt@amd.com#   The following two commands are equivalent and demonstrate building
562632Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
572761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
582632Sstever@eecs.umich.edu#   file.
592632Sstever@eecs.umich.edu#   % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug
602632Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug
612761Sstever@eecs.umich.edu#
622761Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
632761Sstever@eecs.umich.edu# 'gem5' directory (or use -u or -C to tell scons where to find this
648878Ssteve.reinhardt@amd.com# file), you can use 'scons -h' to print all the gem5-specific build
658878Ssteve.reinhardt@amd.com# options as well.
662761Sstever@eecs.umich.edu#
672761Sstever@eecs.umich.edu###################################################
682761Sstever@eecs.umich.edu
692761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions.
702761Sstever@eecs.umich.edutry:
718878Ssteve.reinhardt@amd.com    # Really old versions of scons only take two options for the
728878Ssteve.reinhardt@amd.com    # function, so check once without the revision and once with the
732632Sstever@eecs.umich.edu    # revision, the first instance will fail for stuff other than
742632Sstever@eecs.umich.edu    # 0.98, and the second will fail for 0.98.0
758878Ssteve.reinhardt@amd.com    EnsureSConsVersion(0, 98)
768878Ssteve.reinhardt@amd.com    EnsureSConsVersion(0, 98, 1)
772632Sstever@eecs.umich.eduexcept SystemExit, e:
78955SN/A    print """
79955SN/AFor more details, see:
80955SN/A    http://gem5.org/Dependencies
815863Snate@binkert.org"""
825863Snate@binkert.org    raise
835863Snate@binkert.org
845863Snate@binkert.org# We ensure the python version early because we have stuff that
855863Snate@binkert.org# requires python 2.4
865863Snate@binkert.orgtry:
875863Snate@binkert.org    EnsurePythonVersion(2, 4)
885863Snate@binkert.orgexcept SystemExit, e:
895863Snate@binkert.org    print """
905863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by
915863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default
928878Ssteve.reinhardt@amd.com'python' first or (2) explicitly invoking an alternative interpreter
935863Snate@binkert.orgon the scons script.
945863Snate@binkert.org
955863Snate@binkert.orgFor more details, see:
969812Sandreas.hansson@arm.com    http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation
979812Sandreas.hansson@arm.com"""
985863Snate@binkert.org    raise
999812Sandreas.hansson@arm.com
1005863Snate@binkert.org# Global Python includes
1015863Snate@binkert.orgimport os
1025863Snate@binkert.orgimport re
1039812Sandreas.hansson@arm.comimport subprocess
1049812Sandreas.hansson@arm.comimport sys
1055863Snate@binkert.org
1065863Snate@binkert.orgfrom os import mkdir, environ
1078878Ssteve.reinhardt@amd.comfrom os.path import abspath, basename, dirname, expanduser, normpath
1085863Snate@binkert.orgfrom os.path import exists,  isdir, isfile
1095863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath
1105863Snate@binkert.org
1116654Snate@binkert.org# SCons includes
11210196SCurtis.Dunham@arm.comimport SCons
113955SN/Aimport SCons.Node
1145396Ssaidi@eecs.umich.edu
1155863Snate@binkert.orgextra_python_paths = [
1165863Snate@binkert.org    Dir('src/python').srcnode().abspath, # gem5 includes
1174202Sbinkertn@umich.edu    Dir('ext/ply').srcnode().abspath, # ply is used by several files
1185863Snate@binkert.org    ]
1195863Snate@binkert.org    
1205863Snate@binkert.orgsys.path[1:1] = extra_python_paths
1215863Snate@binkert.org
122955SN/Afrom m5.util import compareVersions, readCommand
1236654Snate@binkert.org
1245273Sstever@gmail.comhelp_texts = {
1255871Snate@binkert.org    "options" : "",
1265273Sstever@gmail.com    "global_vars" : "",
1276655Snate@binkert.org    "local_vars" : ""
1288878Ssteve.reinhardt@amd.com}
1296655Snate@binkert.org
1306655Snate@binkert.orgExport("help_texts")
1319219Spower.jg@gmail.com
1326655Snate@binkert.orgdef AddM5Option(*args, **kwargs):
1335871Snate@binkert.org    col_width = 30
1346654Snate@binkert.org
1358947Sandreas.hansson@arm.com    help = "  " + ", ".join(args)
1365396Ssaidi@eecs.umich.edu    if "help" in kwargs:
1378120Sgblack@eecs.umich.edu        length = len(help)
1388120Sgblack@eecs.umich.edu        if length >= col_width:
1398120Sgblack@eecs.umich.edu            help += "\n" + " " * col_width
1408120Sgblack@eecs.umich.edu        else:
1418120Sgblack@eecs.umich.edu            help += " " * (col_width - length)
1428120Sgblack@eecs.umich.edu        help += kwargs["help"]
1438120Sgblack@eecs.umich.edu    help_texts["options"] += help + "\n"
1448120Sgblack@eecs.umich.edu
1458879Ssteve.reinhardt@amd.com    AddOption(*args, **kwargs)
1468879Ssteve.reinhardt@amd.com
1478879Ssteve.reinhardt@amd.comAddM5Option('--colors', dest='use_colors', action='store_true',
1488879Ssteve.reinhardt@amd.com            help="Add color to abbreviated scons output")
1498879Ssteve.reinhardt@amd.comAddM5Option('--no-colors', dest='use_colors', action='store_false',
1508879Ssteve.reinhardt@amd.com            help="Don't add color to abbreviated scons output")
1518879Ssteve.reinhardt@amd.comAddM5Option('--default', dest='default', type='string', action='store',
1528879Ssteve.reinhardt@amd.com            help='Override which build_opts file to use for defaults')
1538879Ssteve.reinhardt@amd.comAddM5Option('--ignore-style', dest='ignore_style', action='store_true',
1548879Ssteve.reinhardt@amd.com            help='Disable style checking hooks')
1558879Ssteve.reinhardt@amd.comAddM5Option('--update-ref', dest='update_ref', action='store_true',
1568879Ssteve.reinhardt@amd.com            help='Update test reference outputs')
1578879Ssteve.reinhardt@amd.comAddM5Option('--verbose', dest='verbose', action='store_true',
1588120Sgblack@eecs.umich.edu            help='Print full tool command lines')
1598120Sgblack@eecs.umich.edu
1608120Sgblack@eecs.umich.eduuse_colors = GetOption('use_colors')
1618120Sgblack@eecs.umich.eduif use_colors:
1628120Sgblack@eecs.umich.edu    from m5.util.terminal import termcap
1638120Sgblack@eecs.umich.eduelif use_colors is None:
1648120Sgblack@eecs.umich.edu    # option unspecified; default behavior is to use colors iff isatty
1658120Sgblack@eecs.umich.edu    from m5.util.terminal import tty_termcap as termcap
1668120Sgblack@eecs.umich.eduelse:
1678120Sgblack@eecs.umich.edu    from m5.util.terminal import no_termcap as termcap
1688120Sgblack@eecs.umich.edu
1698120Sgblack@eecs.umich.edu########################################################################
1708120Sgblack@eecs.umich.edu#
1718120Sgblack@eecs.umich.edu# Set up the main build environment.
1728879Ssteve.reinhardt@amd.com#
1738879Ssteve.reinhardt@amd.com########################################################################
1748879Ssteve.reinhardt@amd.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
1758879Ssteve.reinhardt@amd.com                 'PYTHONPATH', 'RANLIB' ])
1768879Ssteve.reinhardt@amd.com
1778879Ssteve.reinhardt@amd.comuse_env = {}
1788879Ssteve.reinhardt@amd.comfor key,val in os.environ.iteritems():
1798879Ssteve.reinhardt@amd.com    if key in use_vars or key.startswith("M5"):
1809227Sandreas.hansson@arm.com        use_env[key] = val
1819227Sandreas.hansson@arm.com
1828879Ssteve.reinhardt@amd.commain = Environment(ENV=use_env)
1838879Ssteve.reinhardt@amd.commain.root = Dir(".")         # The current directory (where this file lives).
1848879Ssteve.reinhardt@amd.commain.srcdir = Dir("src")     # The source directory
1858879Ssteve.reinhardt@amd.com
1868120Sgblack@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses
1878947Sandreas.hansson@arm.com# as well
1887816Ssteve.reinhardt@amd.commain.AppendENVPath('PYTHONPATH', extra_python_paths)
1895871Snate@binkert.org
1905871Snate@binkert.org########################################################################
1916121Snate@binkert.org#
1925871Snate@binkert.org# Mercurial Stuff.
1935871Snate@binkert.org#
1949926Sstan.czerniawski@arm.com# If the gem5 directory is a mercurial repository, we should do some
1959926Sstan.czerniawski@arm.com# extra things.
1969119Sandreas.hansson@arm.com#
19710068Sandreas.hansson@arm.com########################################################################
19810068Sandreas.hansson@arm.com
199955SN/Ahgdir = main.root.Dir(".hg")
2009416SAndreas.Sandberg@ARM.com
2019416SAndreas.Sandberg@ARM.commercurial_style_message = """
2029416SAndreas.Sandberg@ARM.comYou're missing the gem5 style hook, which automatically checks your code
2039416SAndreas.Sandberg@ARM.comagainst the gem5 style rules on hg commit and qrefresh commands.  This
2049416SAndreas.Sandberg@ARM.comscript will now install the hook in your .hg/hgrc file.
2059416SAndreas.Sandberg@ARM.comPress enter to continue, or ctrl-c to abort: """
2069416SAndreas.Sandberg@ARM.com
2075871Snate@binkert.orgmercurial_style_hook = """
2085871Snate@binkert.org# The following lines were automatically added by gem5/SConstruct
2099416SAndreas.Sandberg@ARM.com# to provide the gem5 style-checking hooks
2109416SAndreas.Sandberg@ARM.com[extensions]
2115871Snate@binkert.orgstyle = %s/util/style.py
212955SN/A
2136121Snate@binkert.org[hooks]
2148881Smarc.orr@gmail.compretxncommit.style = python:style.check_style
2156121Snate@binkert.orgpre-qrefresh.style = python:style.check_style
2166121Snate@binkert.org# End of SConstruct additions
2171533SN/A
2189239Sandreas.hansson@arm.com""" % (main.root.abspath)
2199239Sandreas.hansson@arm.com
2209239Sandreas.hansson@arm.commercurial_lib_not_found = """
2219239Sandreas.hansson@arm.comMercurial libraries cannot be found, ignoring style hook.  If
2229239Sandreas.hansson@arm.comyou are a gem5 developer, please fix this and run the style
2239239Sandreas.hansson@arm.comhook. It is important.
2249239Sandreas.hansson@arm.com"""
2259239Sandreas.hansson@arm.com
2269239Sandreas.hansson@arm.com# Check for style hook and prompt for installation if it's not there.
2279239Sandreas.hansson@arm.com# Skip this if --ignore-style was specified, there's no .hg dir to
2289239Sandreas.hansson@arm.com# install a hook in, or there's no interactive terminal to prompt.
2299239Sandreas.hansson@arm.comif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty():
2306655Snate@binkert.org    style_hook = True
2316655Snate@binkert.org    try:
2326655Snate@binkert.org        from mercurial import ui
2336655Snate@binkert.org        ui = ui.ui()
2345871Snate@binkert.org        ui.readconfig(hgdir.File('hgrc').abspath)
2355871Snate@binkert.org        style_hook = ui.config('hooks', 'pretxncommit.style', None) and \
2365863Snate@binkert.org                     ui.config('hooks', 'pre-qrefresh.style', None)
2375871Snate@binkert.org    except ImportError:
2388878Ssteve.reinhardt@amd.com        print mercurial_lib_not_found
2395871Snate@binkert.org
2405871Snate@binkert.org    if not style_hook:
2415871Snate@binkert.org        print mercurial_style_message,
2425863Snate@binkert.org        # continue unless user does ctrl-c/ctrl-d etc.
2436121Snate@binkert.org        try:
2445863Snate@binkert.org            raw_input()
2455871Snate@binkert.org        except:
2468336Ssteve.reinhardt@amd.com            print "Input exception, exiting scons.\n"
2478336Ssteve.reinhardt@amd.com            sys.exit(1)
2488336Ssteve.reinhardt@amd.com        hgrc_path = '%s/.hg/hgrc' % main.root.abspath
2498336Ssteve.reinhardt@amd.com        print "Adding style hook to", hgrc_path, "\n"
2504678Snate@binkert.org        try:
2518336Ssteve.reinhardt@amd.com            hgrc = open(hgrc_path, 'a')
2528336Ssteve.reinhardt@amd.com            hgrc.write(mercurial_style_hook)
2538336Ssteve.reinhardt@amd.com            hgrc.close()
2544678Snate@binkert.org        except:
2554678Snate@binkert.org            print "Error updating", hgrc_path
2564678Snate@binkert.org            sys.exit(1)
2574678Snate@binkert.org
2587827Snate@binkert.org
2597827Snate@binkert.org###################################################
2608336Ssteve.reinhardt@amd.com#
2614678Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
2628336Ssteve.reinhardt@amd.com# the target(s).
2638336Ssteve.reinhardt@amd.com#
2648336Ssteve.reinhardt@amd.com###################################################
2658336Ssteve.reinhardt@amd.com
2668336Ssteve.reinhardt@amd.com# Find default configuration & binary.
2678336Ssteve.reinhardt@amd.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug'))
2685871Snate@binkert.org
2695871Snate@binkert.org# helper function: find last occurrence of element in list
2708336Ssteve.reinhardt@amd.comdef rfind(l, elt, offs = -1):
2718336Ssteve.reinhardt@amd.com    for i in range(len(l)+offs, 0, -1):
2728336Ssteve.reinhardt@amd.com        if l[i] == elt:
2738336Ssteve.reinhardt@amd.com            return i
2748336Ssteve.reinhardt@amd.com    raise ValueError, "element not found"
2755871Snate@binkert.org
2768336Ssteve.reinhardt@amd.com# Take a list of paths (or SCons Nodes) and return a list with all
2778336Ssteve.reinhardt@amd.com# paths made absolute and ~-expanded.  Paths will be interpreted
2788336Ssteve.reinhardt@amd.com# relative to the launch directory unless a different root is provided
2798336Ssteve.reinhardt@amd.comdef makePathListAbsolute(path_list, root=GetLaunchDir()):
2808336Ssteve.reinhardt@amd.com    return [abspath(joinpath(root, expanduser(str(p))))
2814678Snate@binkert.org            for p in path_list]
2825871Snate@binkert.org
2834678Snate@binkert.org# Each target must have 'build' in the interior of the path; the
2848336Ssteve.reinhardt@amd.com# directory below this will determine the build parameters.  For
2858336Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
2868336Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it
2878336Ssteve.reinhardt@amd.com# follow 'build' in the build path.
2888336Ssteve.reinhardt@amd.com
2898336Ssteve.reinhardt@amd.com# The funky assignment to "[:]" is needed to replace the list contents
2908336Ssteve.reinhardt@amd.com# in place rather than reassign the symbol to a new list, which
2918336Ssteve.reinhardt@amd.com# doesn't work (obviously!).
2928336Ssteve.reinhardt@amd.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)
2938336Ssteve.reinhardt@amd.com
2948336Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the
2958336Ssteve.reinhardt@amd.com# collected targets reference.
2968336Ssteve.reinhardt@amd.comvariant_paths = []
2978336Ssteve.reinhardt@amd.combuild_root = None
2988336Ssteve.reinhardt@amd.comfor t in BUILD_TARGETS:
2998336Ssteve.reinhardt@amd.com    path_dirs = t.split('/')
3008336Ssteve.reinhardt@amd.com    try:
3015871Snate@binkert.org        build_top = rfind(path_dirs, 'build', -2)
3026121Snate@binkert.org    except:
303955SN/A        print "Error: no non-leaf 'build' dir found on target path", t
304955SN/A        Exit(1)
3052632Sstever@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
3062632Sstever@eecs.umich.edu    if not build_root:
307955SN/A        build_root = this_build_root
308955SN/A    else:
309955SN/A        if this_build_root != build_root:
310955SN/A            print "Error: build targets not under same build root\n"\
3118878Ssteve.reinhardt@amd.com                  "  %s\n  %s" % (build_root, this_build_root)
312955SN/A            Exit(1)
3132632Sstever@eecs.umich.edu    variant_path = joinpath('/',*path_dirs[:build_top+2])
3142632Sstever@eecs.umich.edu    if variant_path not in variant_paths:
3152632Sstever@eecs.umich.edu        variant_paths.append(variant_path)
3162632Sstever@eecs.umich.edu
3172632Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there)
3182632Sstever@eecs.umich.eduif not isdir(build_root):
3192632Sstever@eecs.umich.edu    mkdir(build_root)
3208268Ssteve.reinhardt@amd.commain['BUILDROOT'] = build_root
3218268Ssteve.reinhardt@amd.com
3228268Ssteve.reinhardt@amd.comExport('main')
3238268Ssteve.reinhardt@amd.com
3248268Ssteve.reinhardt@amd.commain.SConsignFile(joinpath(build_root, "sconsign"))
3258268Ssteve.reinhardt@amd.com
3268268Ssteve.reinhardt@amd.com# Default duplicate option is to use hard links, but this messes up
3272632Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
3282632Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
3292632Sstever@eecs.umich.edu# (soft) links work better.
3302632Sstever@eecs.umich.edumain.SetOption('duplicate', 'soft-copy')
3318268Ssteve.reinhardt@amd.com
3322632Sstever@eecs.umich.edu#
3338268Ssteve.reinhardt@amd.com# Set up global sticky variables... these are common to an entire build
3348268Ssteve.reinhardt@amd.com# tree (not specific to a particular build like ALPHA_SE)
3358268Ssteve.reinhardt@amd.com#
3368268Ssteve.reinhardt@amd.com
3373718Sstever@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global')
3382634Sstever@eecs.umich.edu
3392634Sstever@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS)
3405863Snate@binkert.org
3412638Sstever@eecs.umich.eduglobal_vars.AddVariables(
3428268Ssteve.reinhardt@amd.com    ('CC', 'C compiler', environ.get('CC', main['CC'])),
3432632Sstever@eecs.umich.edu    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
3442632Sstever@eecs.umich.edu    ('BATCH', 'Use batch pool for build and tests', False),
3452632Sstever@eecs.umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3462632Sstever@eecs.umich.edu    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
3472632Sstever@eecs.umich.edu    ('EXTRAS', 'Add extra directories to the compilation', '')
3481858SN/A    )
3493716Sstever@eecs.umich.edu
3502638Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_vars_file
3512638Sstever@eecs.umich.eduglobal_vars.Update(main)
3522638Sstever@eecs.umich.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main)
3532638Sstever@eecs.umich.edu
3542638Sstever@eecs.umich.edu# Save sticky variable settings back to current variables file
3552638Sstever@eecs.umich.eduglobal_vars.Save(global_vars_file, main)
3562638Sstever@eecs.umich.edu
3575863Snate@binkert.org# Parse EXTRAS variable to build list of all directories where we're
3585863Snate@binkert.org# look for sources etc.  This list is exported as extras_dir_list.
3595863Snate@binkert.orgbase_dir = main.srcdir.abspath
360955SN/Aif main['EXTRAS']:
3615341Sstever@gmail.com    extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':'))
3625341Sstever@gmail.comelse:
3635863Snate@binkert.org    extras_dir_list = []
3647756SAli.Saidi@ARM.com
3655341Sstever@gmail.comExport('base_dir')
3666121Snate@binkert.orgExport('extras_dir_list')
3674494Ssaidi@eecs.umich.edu
3686121Snate@binkert.org# the ext directory should be on the #includes path
3691105SN/Amain.Append(CPPPATH=[Dir('ext')])
3702667Sstever@eecs.umich.edu
3712667Sstever@eecs.umich.edudef strip_build_path(path, env):
3722667Sstever@eecs.umich.edu    path = str(path)
3732667Sstever@eecs.umich.edu    variant_base = env['BUILDROOT'] + os.path.sep
3746121Snate@binkert.org    if path.startswith(variant_base):
3752667Sstever@eecs.umich.edu        path = path[len(variant_base):]
3765341Sstever@gmail.com    elif path.startswith('build/'):
3775863Snate@binkert.org        path = path[6:]
3785341Sstever@gmail.com    return path
3795341Sstever@gmail.com
3805341Sstever@gmail.com# Generate a string of the form:
3818120Sgblack@eecs.umich.edu#   common/path/prefix/src1, src2 -> tgt1, tgt2
3825341Sstever@gmail.com# to print while building.
3838120Sgblack@eecs.umich.educlass Transform(object):
3845341Sstever@gmail.com    # all specific color settings should be here and nowhere else
3858120Sgblack@eecs.umich.edu    tool_color = termcap.Normal
3866121Snate@binkert.org    pfx_color = termcap.Yellow
3876121Snate@binkert.org    srcs_color = termcap.Yellow + termcap.Bold
3888980Ssteve.reinhardt@amd.com    arrow_color = termcap.Blue + termcap.Bold
3899396Sandreas.hansson@arm.com    tgts_color = termcap.Yellow + termcap.Bold
3905397Ssaidi@eecs.umich.edu
3915397Ssaidi@eecs.umich.edu    def __init__(self, tool, max_sources=99):
3927727SAli.Saidi@ARM.com        self.format = self.tool_color + (" [%8s] " % tool) \
3938268Ssteve.reinhardt@amd.com                      + self.pfx_color + "%s" \
3946168Snate@binkert.org                      + self.srcs_color + "%s" \
3955341Sstever@gmail.com                      + self.arrow_color + " -> " \
3968120Sgblack@eecs.umich.edu                      + self.tgts_color + "%s" \
3978120Sgblack@eecs.umich.edu                      + termcap.Normal
3988120Sgblack@eecs.umich.edu        self.max_sources = max_sources
3996814Sgblack@eecs.umich.edu
4005863Snate@binkert.org    def __call__(self, target, source, env, for_signature=None):
4018120Sgblack@eecs.umich.edu        # truncate source list according to max_sources param
4025341Sstever@gmail.com        source = source[0:self.max_sources]
4035863Snate@binkert.org        def strip(f):
4048268Ssteve.reinhardt@amd.com            return strip_build_path(str(f), env)
4056121Snate@binkert.org        if len(source) > 0:
4066121Snate@binkert.org            srcs = map(strip, source)
4078268Ssteve.reinhardt@amd.com        else:
4085742Snate@binkert.org            srcs = ['']
4095742Snate@binkert.org        tgts = map(strip, target)
4105341Sstever@gmail.com        # surprisingly, os.path.commonprefix is a dumb char-by-char string
4115742Snate@binkert.org        # operation that has nothing to do with paths.
4125742Snate@binkert.org        com_pfx = os.path.commonprefix(srcs + tgts)
4135341Sstever@gmail.com        com_pfx_len = len(com_pfx)
4146017Snate@binkert.org        if com_pfx:
4156121Snate@binkert.org            # do some cleanup and sanity checking on common prefix
4166017Snate@binkert.org            if com_pfx[-1] == ".":
4177816Ssteve.reinhardt@amd.com                # prefix matches all but file extension: ok
4187756SAli.Saidi@ARM.com                # back up one to change 'foo.cc -> o' to 'foo.cc -> .o'
4197756SAli.Saidi@ARM.com                com_pfx = com_pfx[0:-1]
4207756SAli.Saidi@ARM.com            elif com_pfx[-1] == "/":
4217756SAli.Saidi@ARM.com                # common prefix is directory path: OK
4227756SAli.Saidi@ARM.com                pass
4237756SAli.Saidi@ARM.com            else:
4247756SAli.Saidi@ARM.com                src0_len = len(srcs[0])
4257756SAli.Saidi@ARM.com                tgt0_len = len(tgts[0])
4267816Ssteve.reinhardt@amd.com                if src0_len == com_pfx_len:
4277816Ssteve.reinhardt@amd.com                    # source is a substring of target, OK
4287816Ssteve.reinhardt@amd.com                    pass
4297816Ssteve.reinhardt@amd.com                elif tgt0_len == com_pfx_len:
4307816Ssteve.reinhardt@amd.com                    # target is a substring of source, need to back up to
4317816Ssteve.reinhardt@amd.com                    # avoid empty string on RHS of arrow
4327816Ssteve.reinhardt@amd.com                    sep_idx = com_pfx.rfind(".")
4337816Ssteve.reinhardt@amd.com                    if sep_idx != -1:
4347816Ssteve.reinhardt@amd.com                        com_pfx = com_pfx[0:sep_idx]
4357816Ssteve.reinhardt@amd.com                    else:
4367756SAli.Saidi@ARM.com                        com_pfx = ''
4377816Ssteve.reinhardt@amd.com                elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".":
4387816Ssteve.reinhardt@amd.com                    # still splitting at file extension: ok
4397816Ssteve.reinhardt@amd.com                    pass
4407816Ssteve.reinhardt@amd.com                else:
4417816Ssteve.reinhardt@amd.com                    # probably a fluke; ignore it
4427816Ssteve.reinhardt@amd.com                    com_pfx = ''
4437816Ssteve.reinhardt@amd.com        # recalculate length in case com_pfx was modified
4447816Ssteve.reinhardt@amd.com        com_pfx_len = len(com_pfx)
4457816Ssteve.reinhardt@amd.com        def fmt(files):
4467816Ssteve.reinhardt@amd.com            f = map(lambda s: s[com_pfx_len:], files)
4477816Ssteve.reinhardt@amd.com            return ', '.join(f)
4487816Ssteve.reinhardt@amd.com        return self.format % (com_pfx, fmt(srcs), fmt(tgts))
4497816Ssteve.reinhardt@amd.com
4507816Ssteve.reinhardt@amd.comExport('Transform')
4517816Ssteve.reinhardt@amd.com
4527816Ssteve.reinhardt@amd.com
4537816Ssteve.reinhardt@amd.comif GetOption('verbose'):
4547816Ssteve.reinhardt@amd.com    def MakeAction(action, string, *args, **kwargs):
4557816Ssteve.reinhardt@amd.com        return Action(action, *args, **kwargs)
4567816Ssteve.reinhardt@amd.comelse:
4577816Ssteve.reinhardt@amd.com    MakeAction = Action
4587816Ssteve.reinhardt@amd.com    main['CCCOMSTR']        = Transform("CC")
4597816Ssteve.reinhardt@amd.com    main['CXXCOMSTR']       = Transform("CXX")
4607816Ssteve.reinhardt@amd.com    main['ASCOMSTR']        = Transform("AS")
4617816Ssteve.reinhardt@amd.com    main['SWIGCOMSTR']      = Transform("SWIG")
4627816Ssteve.reinhardt@amd.com    main['ARCOMSTR']        = Transform("AR", 0)
4637816Ssteve.reinhardt@amd.com    main['LINKCOMSTR']      = Transform("LINK", 0)
4647816Ssteve.reinhardt@amd.com    main['RANLIBCOMSTR']    = Transform("RANLIB", 0)
4657816Ssteve.reinhardt@amd.com    main['M4COMSTR']        = Transform("M4")
4667816Ssteve.reinhardt@amd.com    main['SHCCCOMSTR']      = Transform("SHCC")
4677816Ssteve.reinhardt@amd.com    main['SHCXXCOMSTR']     = Transform("SHCXX")
4687816Ssteve.reinhardt@amd.comExport('MakeAction')
4697816Ssteve.reinhardt@amd.com
4707816Ssteve.reinhardt@amd.comCXX_version = readCommand([main['CXX'],'--version'], exception=False)
4717816Ssteve.reinhardt@amd.comCXX_V = readCommand([main['CXX'],'-V'], exception=False)
4727816Ssteve.reinhardt@amd.com
4737816Ssteve.reinhardt@amd.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
4747816Ssteve.reinhardt@amd.commain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
4757816Ssteve.reinhardt@amd.commain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
4767816Ssteve.reinhardt@amd.commain['CLANG'] = CXX_V and CXX_V.find('clang') >= 0
4777816Ssteve.reinhardt@amd.comif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1:
4787816Ssteve.reinhardt@amd.com    print 'Error: How can we have two at the same time?'
4797816Ssteve.reinhardt@amd.com    Exit(1)
4807816Ssteve.reinhardt@amd.com
4817816Ssteve.reinhardt@amd.com# Set up default C++ compiler flags
4827816Ssteve.reinhardt@amd.comif main['GCC']:
4837816Ssteve.reinhardt@amd.com    main.Append(CCFLAGS=['-pipe'])
4847816Ssteve.reinhardt@amd.com    main.Append(CCFLAGS=['-fno-strict-aliasing'])
4857816Ssteve.reinhardt@amd.com    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
4867816Ssteve.reinhardt@amd.com    main.Append(CXXFLAGS=['-Wno-deprecated'])
4877816Ssteve.reinhardt@amd.com    # Read the GCC version to check for versions with bugs
4887816Ssteve.reinhardt@amd.com    # Note CCVERSION doesn't work here because it is run with the CC
4897816Ssteve.reinhardt@amd.com    # before we override it from the command line
4907816Ssteve.reinhardt@amd.com    gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False)
4917816Ssteve.reinhardt@amd.com    main['GCC_VERSION'] = gcc_version
4927816Ssteve.reinhardt@amd.com    if not compareVersions(gcc_version, '4.4.1') or \
4937816Ssteve.reinhardt@amd.com       not compareVersions(gcc_version, '4.4.2'):
4947816Ssteve.reinhardt@amd.com        print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.'
4957816Ssteve.reinhardt@amd.com        main.Append(CCFLAGS=['-fno-tree-vectorize'])
4967816Ssteve.reinhardt@amd.comelif main['ICC']:
4977816Ssteve.reinhardt@amd.com    pass #Fix me... add warning flags once we clean up icc warnings
4988947Sandreas.hansson@arm.comelif main['SUNCC']:
4998947Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-Qoption ccfe'])
5007756SAli.Saidi@ARM.com    main.Append(CCFLAGS=['-features=gcc'])
5018120Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-features=extensions'])
5027756SAli.Saidi@ARM.com    main.Append(CCFLAGS=['-library=stlport4'])
5037756SAli.Saidi@ARM.com    main.Append(CCFLAGS=['-xar'])
5047756SAli.Saidi@ARM.com    #main.Append(CCFLAGS=['-instances=semiexplicit'])
5057756SAli.Saidi@ARM.comelif main['CLANG']:
5067816Ssteve.reinhardt@amd.com    clang_version_re = re.compile(".* version (\d+\.\d+)")
5077816Ssteve.reinhardt@amd.com    clang_version_match = clang_version_re.match(CXX_version)
5087816Ssteve.reinhardt@amd.com    if (clang_version_match):
5097816Ssteve.reinhardt@amd.com        clang_version = clang_version_match.groups()[0]
5107816Ssteve.reinhardt@amd.com        if compareVersions(clang_version, "2.9") < 0:
5117816Ssteve.reinhardt@amd.com            print 'Error: clang version 2.9 or newer required.'
5127816Ssteve.reinhardt@amd.com            print '       Installed version:', clang_version
5137816Ssteve.reinhardt@amd.com            Exit(1)
5147816Ssteve.reinhardt@amd.com    else:
5157816Ssteve.reinhardt@amd.com        print 'Error: Unable to determine clang version.'
5167756SAli.Saidi@ARM.com        Exit(1)
5177756SAli.Saidi@ARM.com
5189227Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-pipe'])
5199227Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-fno-strict-aliasing'])
5209227Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
5219227Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-Wno-tautological-compare'])
5229590Sandreas@sandberg.pp.se    main.Append(CCFLAGS=['-Wno-self-assign'])
5239590Sandreas@sandberg.pp.seelse:
5249590Sandreas@sandberg.pp.se    print 'Error: Don\'t know what compiler options to use for your compiler.'
5259590Sandreas@sandberg.pp.se    print '       Please fix SConstruct and src/SConscript and try again.'
5269590Sandreas@sandberg.pp.se    Exit(1)
5279590Sandreas@sandberg.pp.se
5286654Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby)
5296654Snate@binkert.orgmain['YACCFLAGS'] = '-d'
5305871Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh'
5316121Snate@binkert.org
5328946Sandreas.hansson@arm.com# Do this after we save setting back, or else we'll tack on an
5339419Sandreas.hansson@arm.com# extra 'qdo' every time we run scons.
5343940Ssaidi@eecs.umich.eduif main['BATCH']:
5353918Ssaidi@eecs.umich.edu    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
5363918Ssaidi@eecs.umich.edu    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
5371858SN/A    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
5389556Sandreas.hansson@arm.com    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
5399556Sandreas.hansson@arm.com    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
5409556Sandreas.hansson@arm.com
5419556Sandreas.hansson@arm.comif sys.platform == 'cygwin':
5429556Sandreas.hansson@arm.com    # cygwin has some header file issues...
5439556Sandreas.hansson@arm.com    main.Append(CCFLAGS=["-Wno-uninitialized"])
5449556Sandreas.hansson@arm.com
5459556Sandreas.hansson@arm.com# Check for SWIG
5469556Sandreas.hansson@arm.comif not main.has_key('SWIG'):
5479556Sandreas.hansson@arm.com    print 'Error: SWIG utility not found.'
5489556Sandreas.hansson@arm.com    print '       Please install (see http://www.swig.org) and retry.'
5499556Sandreas.hansson@arm.com    Exit(1)
5509556Sandreas.hansson@arm.com
5519556Sandreas.hansson@arm.com# Check for appropriate SWIG version
5529556Sandreas.hansson@arm.comswig_version = readCommand(('swig', '-version'), exception='').split()
5539556Sandreas.hansson@arm.com# First 3 words should be "SWIG Version x.y.z"
5549556Sandreas.hansson@arm.comif len(swig_version) < 3 or \
5559556Sandreas.hansson@arm.com        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
5569556Sandreas.hansson@arm.com    print 'Error determining SWIG version.'
5579556Sandreas.hansson@arm.com    Exit(1)
5589556Sandreas.hansson@arm.com
5599556Sandreas.hansson@arm.commin_swig_version = '1.3.28'
5609556Sandreas.hansson@arm.comif compareVersions(swig_version[2], min_swig_version) < 0:
5619556Sandreas.hansson@arm.com    print 'Error: SWIG version', min_swig_version, 'or newer required.'
5629556Sandreas.hansson@arm.com    print '       Installed version:', swig_version[2]
5639556Sandreas.hansson@arm.com    Exit(1)
5649556Sandreas.hansson@arm.com
5659556Sandreas.hansson@arm.com# Set up SWIG flags & scanner
5669556Sandreas.hansson@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
5679556Sandreas.hansson@arm.commain.Append(SWIGFLAGS=swig_flags)
5689556Sandreas.hansson@arm.com
5699556Sandreas.hansson@arm.com# filter out all existing swig scanners, they mess up the dependency
5706121Snate@binkert.org# stuff for some reason
5719420Sandreas.hansson@arm.comscanners = []
5729420Sandreas.hansson@arm.comfor scanner in main['SCANNERS']:
5739420Sandreas.hansson@arm.com    skeys = scanner.skeys
5749420Sandreas.hansson@arm.com    if skeys == '.i':
5759420Sandreas.hansson@arm.com        continue
5769420Sandreas.hansson@arm.com
5779420Sandreas.hansson@arm.com    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
5789420Sandreas.hansson@arm.com        continue
5799420Sandreas.hansson@arm.com
5809420Sandreas.hansson@arm.com    scanners.append(scanner)
5819420Sandreas.hansson@arm.com
5827618SAli.Saidi@arm.com# add the new swig scanner that we like better
5837618SAli.Saidi@arm.comfrom SCons.Scanner import ClassicCPP as CPPScanner
5847618SAli.Saidi@arm.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
5857739Sgblack@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
5869227Sandreas.hansson@arm.com
5879227Sandreas.hansson@arm.com# replace the scanners list that has what we want
5889227Sandreas.hansson@arm.commain['SCANNERS'] = scanners
5899227Sandreas.hansson@arm.com
5909227Sandreas.hansson@arm.com# Add a custom Check function to the Configure context so that we can
5919227Sandreas.hansson@arm.com# figure out if the compiler adds leading underscores to global
5929227Sandreas.hansson@arm.com# variables.  This is needed for the autogenerated asm files that we
5939227Sandreas.hansson@arm.com# use for embedding the python code.
5949227Sandreas.hansson@arm.comdef CheckLeading(context):
5959227Sandreas.hansson@arm.com    context.Message("Checking for leading underscore in global variables...")
5969227Sandreas.hansson@arm.com    # 1) Define a global variable called x from asm so the C compiler
5979227Sandreas.hansson@arm.com    #    won't change the symbol at all.
5989227Sandreas.hansson@arm.com    # 2) Declare that variable.
5999227Sandreas.hansson@arm.com    # 3) Use the variable
6009227Sandreas.hansson@arm.com    #
6019227Sandreas.hansson@arm.com    # If the compiler prepends an underscore, this will successfully
6029227Sandreas.hansson@arm.com    # link because the external symbol 'x' will be called '_x' which
6039227Sandreas.hansson@arm.com    # was defined by the asm statement.  If the compiler does not
6049590Sandreas@sandberg.pp.se    # prepend an underscore, this will not successfully link because
6059590Sandreas@sandberg.pp.se    # '_x' will have been defined by assembly, while the C portion of
6069590Sandreas@sandberg.pp.se    # the code will be trying to use 'x'
6078737Skoansin.tan@gmail.com    ret = context.TryLink('''
6089420Sandreas.hansson@arm.com        asm(".globl _x; _x: .byte 0");
6099420Sandreas.hansson@arm.com        extern int x;
6109420Sandreas.hansson@arm.com        int main() { return x; }
6118737Skoansin.tan@gmail.com        ''', extension=".c")
61210106SMitch.Hayenga@arm.com    context.env.Append(LEADING_UNDERSCORE=ret)
6138737Skoansin.tan@gmail.com    context.Result(ret)
6148737Skoansin.tan@gmail.com    return ret
6158737Skoansin.tan@gmail.com
6168737Skoansin.tan@gmail.com# Platform-specific configuration.  Note again that we assume that all
6178737Skoansin.tan@gmail.com# builds under a given build root run on the same host platform.
6188737Skoansin.tan@gmail.comconf = Configure(main,
6198737Skoansin.tan@gmail.com                 conf_dir = joinpath(build_root, '.scons_config'),
6208737Skoansin.tan@gmail.com                 log_file = joinpath(build_root, 'scons_config.log'),
6218737Skoansin.tan@gmail.com                 custom_tests = { 'CheckLeading' : CheckLeading })
6228737Skoansin.tan@gmail.com
6239556Sandreas.hansson@arm.com# Check for leading underscores.  Don't really need to worry either
6249556Sandreas.hansson@arm.com# way so don't need to check the return code.
6259556Sandreas.hansson@arm.comconf.CheckLeading()
6269556Sandreas.hansson@arm.com
6279556Sandreas.hansson@arm.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin
6289556Sandreas.hansson@arm.comtry:
6299556Sandreas.hansson@arm.com    import platform
6309556Sandreas.hansson@arm.com    uname = platform.uname()
6319556Sandreas.hansson@arm.com    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
6329556Sandreas.hansson@arm.com        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
6339590Sandreas@sandberg.pp.se            main.Append(CCFLAGS=['-arch', 'x86_64'])
6349590Sandreas@sandberg.pp.se            main.Append(CFLAGS=['-arch', 'x86_64'])
6359420Sandreas.hansson@arm.com            main.Append(LINKFLAGS=['-arch', 'x86_64'])
6369846Sandreas.hansson@arm.com            main.Append(ASFLAGS=['-arch', 'x86_64'])
6379846Sandreas.hansson@arm.comexcept:
6389846Sandreas.hansson@arm.com    pass
6399846Sandreas.hansson@arm.com
6408946Sandreas.hansson@arm.com# Recent versions of scons substitute a "Null" object for Configure()
6413918Ssaidi@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is
6429068SAli.Saidi@ARM.com# present.  Unfortuantely this Null object always returns false,
6439068SAli.Saidi@ARM.com# breaking all our configuration checks.  We replace it with our own
6449068SAli.Saidi@ARM.com# more optimistic null object that returns True instead.
6459068SAli.Saidi@ARM.comif not conf:
6469068SAli.Saidi@ARM.com    def NullCheck(*args, **kwargs):
6479068SAli.Saidi@ARM.com        return True
6489068SAli.Saidi@ARM.com
6499068SAli.Saidi@ARM.com    class NullConf:
6509068SAli.Saidi@ARM.com        def __init__(self, env):
6519419Sandreas.hansson@arm.com            self.env = env
6529068SAli.Saidi@ARM.com        def Finish(self):
6539068SAli.Saidi@ARM.com            return self.env
6549068SAli.Saidi@ARM.com        def __getattr__(self, mname):
6559068SAli.Saidi@ARM.com            return NullCheck
6569068SAli.Saidi@ARM.com
6579068SAli.Saidi@ARM.com    conf = NullConf(main)
6583918Ssaidi@eecs.umich.edu
6593918Ssaidi@eecs.umich.edu# Find Python include and library directories for embedding the
6606157Snate@binkert.org# interpreter.  For consistency, we will use the same Python
6616157Snate@binkert.org# installation used to run scons (and thus this script).  If you want
6626157Snate@binkert.org# to link in an alternate version, see above for instructions on how
6636157Snate@binkert.org# to invoke scons with a different copy of the Python interpreter.
6645397Ssaidi@eecs.umich.edufrom distutils import sysconfig
6655397Ssaidi@eecs.umich.edu
6666121Snate@binkert.orgpy_getvar = sysconfig.get_config_var
6676121Snate@binkert.org
6686121Snate@binkert.orgpy_debug = getattr(sys, 'pydebug', False)
6696121Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "")
6706121Snate@binkert.org
6716121Snate@binkert.orgpy_general_include = sysconfig.get_python_inc()
6725397Ssaidi@eecs.umich.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True)
6731851SN/Apy_includes = [ py_general_include ]
6741851SN/Aif py_platform_include != py_general_include:
6757739Sgblack@eecs.umich.edu    py_includes.append(py_platform_include)
676955SN/A
6779396Sandreas.hansson@arm.compy_lib_path = [ py_getvar('LIBDIR') ]
6789396Sandreas.hansson@arm.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no
6799396Sandreas.hansson@arm.com# shared library in prefix/lib/.
6809396Sandreas.hansson@arm.comif not py_getvar('Py_ENABLE_SHARED'):
6819396Sandreas.hansson@arm.com    py_lib_path.append(py_getvar('LIBPL'))
6829396Sandreas.hansson@arm.com
6839396Sandreas.hansson@arm.compy_libs = []
6849396Sandreas.hansson@arm.comfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
6859396Sandreas.hansson@arm.com    if not lib.startswith('-l'):
6869396Sandreas.hansson@arm.com        # Python requires some special flags to link (e.g. -framework
6879396Sandreas.hansson@arm.com        # common on OS X systems), assume appending preserves order
6889396Sandreas.hansson@arm.com        main.Append(LINKFLAGS=[lib])
6899396Sandreas.hansson@arm.com    else:
6909396Sandreas.hansson@arm.com        lib = lib[2:]
6919396Sandreas.hansson@arm.com        if lib not in py_libs:
6929396Sandreas.hansson@arm.com            py_libs.append(lib)
6939477Sandreas.hansson@arm.compy_libs.append(py_version)
6949477Sandreas.hansson@arm.com
6959477Sandreas.hansson@arm.commain.Append(CPPPATH=py_includes)
6969477Sandreas.hansson@arm.commain.Append(LIBPATH=py_lib_path)
6979477Sandreas.hansson@arm.com
6989477Sandreas.hansson@arm.com# Cache build files in the supplied directory.
6999477Sandreas.hansson@arm.comif main['M5_BUILD_CACHE']:
7009477Sandreas.hansson@arm.com    print 'Using build cache located at', main['M5_BUILD_CACHE']
7019477Sandreas.hansson@arm.com    CacheDir(main['M5_BUILD_CACHE'])
7029477Sandreas.hansson@arm.com
7039477Sandreas.hansson@arm.com
7049477Sandreas.hansson@arm.com# verify that this stuff works
7059477Sandreas.hansson@arm.comif not conf.CheckHeader('Python.h', '<>'):
7069477Sandreas.hansson@arm.com    print "Error: can't find Python.h header in", py_includes
7079477Sandreas.hansson@arm.com    Exit(1)
7089477Sandreas.hansson@arm.com
7099477Sandreas.hansson@arm.comfor lib in py_libs:
7109477Sandreas.hansson@arm.com    if not conf.CheckLib(lib):
7119477Sandreas.hansson@arm.com        print "Error: can't find library %s required by python" % lib
7129477Sandreas.hansson@arm.com        Exit(1)
7139477Sandreas.hansson@arm.com
7149477Sandreas.hansson@arm.com# On Solaris you need to use libsocket for socket ops
7159396Sandreas.hansson@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
7163053Sstever@eecs.umich.edu   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
7176121Snate@binkert.org       print "Can't find library with socket calls (e.g. accept())"
7183053Sstever@eecs.umich.edu       Exit(1)
7193053Sstever@eecs.umich.edu
7203053Sstever@eecs.umich.edu# Check for zlib.  If the check passes, libz will be automatically
7213053Sstever@eecs.umich.edu# added to the LIBS environment variable.
7223053Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
7239072Sandreas.hansson@arm.com    print 'Error: did not find needed zlib compression library '\
7243053Sstever@eecs.umich.edu          'and/or zlib.h header file.'
7254742Sstever@eecs.umich.edu    print '       Please install zlib and try again.'
7264742Sstever@eecs.umich.edu    Exit(1)
7273053Sstever@eecs.umich.edu
7283053Sstever@eecs.umich.edu# Check for librt.
7293053Sstever@eecs.umich.eduhave_posix_clock = \
73010181SCurtis.Dunham@arm.com    conf.CheckLibWithHeader(None, 'time.h', 'C',
7316654Snate@binkert.org                            'clock_nanosleep(0,0,NULL,NULL);') or \
7323053Sstever@eecs.umich.edu    conf.CheckLibWithHeader('rt', 'time.h', 'C',
7333053Sstever@eecs.umich.edu                            'clock_nanosleep(0,0,NULL,NULL);')
7343053Sstever@eecs.umich.edu
7353053Sstever@eecs.umich.eduif not have_posix_clock:
7362667Sstever@eecs.umich.edu    print "Can't find library for POSIX clocks."
7374554Sbinkertn@umich.edu
7386121Snate@binkert.org# Check for <fenv.h> (C99 FP environment control)
7392667Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
7404554Sbinkertn@umich.eduif not have_fenv:
7414554Sbinkertn@umich.edu    print "Warning: Header file <fenv.h> not found."
7424554Sbinkertn@umich.edu    print "         This host has no IEEE FP rounding mode control."
7436121Snate@binkert.org
7444554Sbinkertn@umich.edu######################################################################
7454554Sbinkertn@umich.edu#
7464554Sbinkertn@umich.edu# Finish the configuration
7474781Snate@binkert.org#
7484554Sbinkertn@umich.edumain = conf.Finish()
7494554Sbinkertn@umich.edu
7502667Sstever@eecs.umich.edu######################################################################
7514554Sbinkertn@umich.edu#
7524554Sbinkertn@umich.edu# Collect all non-global variables
7534554Sbinkertn@umich.edu#
7544554Sbinkertn@umich.edu
7552667Sstever@eecs.umich.edu# Define the universe of supported ISAs
7564554Sbinkertn@umich.eduall_isa_list = [ ]
7572667Sstever@eecs.umich.eduExport('all_isa_list')
7584554Sbinkertn@umich.edu
7596121Snate@binkert.orgclass CpuModel(object):
7602667Sstever@eecs.umich.edu    '''The CpuModel class encapsulates everything the ISA parser needs to
7615522Snate@binkert.org    know about a particular CPU model.'''
7625522Snate@binkert.org
7635522Snate@binkert.org    # Dict of available CPU model objects.  Accessible as CpuModel.dict.
7645522Snate@binkert.org    dict = {}
7655522Snate@binkert.org    list = []
7665522Snate@binkert.org    defaults = []
7675522Snate@binkert.org
7685522Snate@binkert.org    # Constructor.  Automatically adds models to CpuModel.dict.
7695522Snate@binkert.org    def __init__(self, name, filename, includes, strings, default=False):
7705522Snate@binkert.org        self.name = name           # name of model
7715522Snate@binkert.org        self.filename = filename   # filename for output exec code
7725522Snate@binkert.org        self.includes = includes   # include files needed in exec file
7735522Snate@binkert.org        # The 'strings' dict holds all the per-CPU symbols we can
7745522Snate@binkert.org        # substitute into templates etc.
7755522Snate@binkert.org        self.strings = strings
7765522Snate@binkert.org
7775522Snate@binkert.org        # This cpu is enabled by default
7785522Snate@binkert.org        self.default = default
7795522Snate@binkert.org
7805522Snate@binkert.org        # Add self to dict
7815522Snate@binkert.org        if name in CpuModel.dict:
7825522Snate@binkert.org            raise AttributeError, "CpuModel '%s' already registered" % name
7835522Snate@binkert.org        CpuModel.dict[name] = self
7845522Snate@binkert.org        CpuModel.list.append(name)
7855522Snate@binkert.org
7865522Snate@binkert.orgExport('CpuModel')
7879986Sandreas@sandberg.pp.se
7889986Sandreas@sandberg.pp.se# Sticky variables get saved in the variables file so they persist from
7899986Sandreas@sandberg.pp.se# one invocation to the next (unless overridden, in which case the new
7909986Sandreas@sandberg.pp.se# value becomes sticky).
7919986Sandreas@sandberg.pp.sesticky_vars = Variables(args=ARGUMENTS)
7929986Sandreas@sandberg.pp.seExport('sticky_vars')
7939986Sandreas@sandberg.pp.se
7949986Sandreas@sandberg.pp.se# Sticky variables that should be exported
7959986Sandreas@sandberg.pp.seexport_vars = []
7969986Sandreas@sandberg.pp.seExport('export_vars')
7979986Sandreas@sandberg.pp.se
7989986Sandreas@sandberg.pp.se# Walk the tree and execute all SConsopts scripts that wil add to the
7999986Sandreas@sandberg.pp.se# above variables
8009986Sandreas@sandberg.pp.seif not GetOption('verbose'):
8019986Sandreas@sandberg.pp.se    print "Reading SConsopts"
8029986Sandreas@sandberg.pp.sefor bdir in [ base_dir ] + extras_dir_list:
8039986Sandreas@sandberg.pp.se    if not isdir(bdir):
8049986Sandreas@sandberg.pp.se        print "Error: directory '%s' does not exist" % bdir
8059986Sandreas@sandberg.pp.se        Exit(1)
8069986Sandreas@sandberg.pp.se    for root, dirs, files in os.walk(bdir):
8072638Sstever@eecs.umich.edu        if 'SConsopts' in files:
8082638Sstever@eecs.umich.edu            if GetOption('verbose'):
8096121Snate@binkert.org                print "Reading", joinpath(root, 'SConsopts')
8103716Sstever@eecs.umich.edu            SConscript(joinpath(root, 'SConsopts'))
8115522Snate@binkert.org
8129986Sandreas@sandberg.pp.seall_isa_list.sort()
8139986Sandreas@sandberg.pp.se
8149986Sandreas@sandberg.pp.sesticky_vars.AddVariables(
8159986Sandreas@sandberg.pp.se    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
8165522Snate@binkert.org    ListVariable('CPU_MODELS', 'CPU models',
8175522Snate@binkert.org                 sorted(n for n,m in CpuModel.dict.iteritems() if m.default),
8185522Snate@binkert.org                 sorted(CpuModel.list)),
8195522Snate@binkert.org    BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
8201858SN/A    BoolVariable('FORCE_FAST_ALLOC',
8215227Ssaidi@eecs.umich.edu                 'Enable fast object allocator, even for gem5.debug', False),
8225227Ssaidi@eecs.umich.edu    BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
8235227Ssaidi@eecs.umich.edu                 False),
8245227Ssaidi@eecs.umich.edu    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
8256654Snate@binkert.org                 False),
8266654Snate@binkert.org    BoolVariable('SS_COMPATIBLE_FP',
8277769SAli.Saidi@ARM.com                 'Make floating-point results compatible with SimpleScalar',
8287769SAli.Saidi@ARM.com                 False),
8297769SAli.Saidi@ARM.com    BoolVariable('USE_SSE2',
8307769SAli.Saidi@ARM.com                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
8315227Ssaidi@eecs.umich.edu                 False),
8325227Ssaidi@eecs.umich.edu    BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
8335227Ssaidi@eecs.umich.edu    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
8345204Sstever@gmail.com    BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
8355204Sstever@gmail.com    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
8365204Sstever@gmail.com    )
8375204Sstever@gmail.com
8385204Sstever@gmail.com# These variables get exported to #defines in config/*.hh (see src/SConscript).
8395204Sstever@gmail.comexport_vars += ['USE_FENV', 'NO_FAST_ALLOC', 'FORCE_FAST_ALLOC',
8405204Sstever@gmail.com                'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', 'USE_CHECKER',
8415204Sstever@gmail.com                'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK' ]
8425204Sstever@gmail.com
8435204Sstever@gmail.com###################################################
8445204Sstever@gmail.com#
8455204Sstever@gmail.com# Define a SCons builder for configuration flag headers.
8465204Sstever@gmail.com#
8475204Sstever@gmail.com###################################################
8485204Sstever@gmail.com
8495204Sstever@gmail.com# This function generates a config header file that #defines the
8505204Sstever@gmail.com# variable symbol to the current variable setting (0 or 1).  The source
8516121Snate@binkert.org# operands are the name of the variable and a Value node containing the
8525204Sstever@gmail.com# value of the variable.
8537727SAli.Saidi@ARM.comdef build_config_file(target, source, env):
8547727SAli.Saidi@ARM.com    (variable, value) = [s.get_contents() for s in source]
8557727SAli.Saidi@ARM.com    f = file(str(target[0]), 'w')
8567727SAli.Saidi@ARM.com    print >> f, '#define', variable, value
8577727SAli.Saidi@ARM.com    f.close()
8589812Sandreas.hansson@arm.com    return None
8599812Sandreas.hansson@arm.com
8609812Sandreas.hansson@arm.com# Combine the two functions into a scons Action object.
8619812Sandreas.hansson@arm.comconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2))
8629812Sandreas.hansson@arm.com
8639812Sandreas.hansson@arm.com# The emitter munges the source & target node lists to reflect what
8649812Sandreas.hansson@arm.com# we're really doing.
86510158Sstian@dream-web.nodef config_emitter(target, source, env):
86610158Sstian@dream-web.no    # extract variable name from Builder arg
86710158Sstian@dream-web.no    variable = str(target[0])
86810158Sstian@dream-web.no    # True target is config header file
86910160Sandreas.hansson@arm.com    target = joinpath('config', variable.lower() + '.hh')
87010160Sandreas.hansson@arm.com    val = env[variable]
87110158Sstian@dream-web.no    if isinstance(val, bool):
8729812Sandreas.hansson@arm.com        # Force value to 0/1
8739812Sandreas.hansson@arm.com        val = int(val)
8749812Sandreas.hansson@arm.com    elif isinstance(val, str):
8759812Sandreas.hansson@arm.com        val = '"' + val + '"'
8769812Sandreas.hansson@arm.com
8779812Sandreas.hansson@arm.com    # Sources are variable name & value (packaged in SCons Value nodes)
8789812Sandreas.hansson@arm.com    return ([target], [Value(variable), Value(val)])
87910158Sstian@dream-web.no
8809812Sandreas.hansson@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action)
8819812Sandreas.hansson@arm.com
8829812Sandreas.hansson@arm.commain.Append(BUILDERS = { 'ConfigFile' : config_builder })
8839812Sandreas.hansson@arm.com
8849812Sandreas.hansson@arm.com# libelf build is shared across all configs in the build root.
8859812Sandreas.hansson@arm.commain.SConscript('ext/libelf/SConscript',
8869812Sandreas.hansson@arm.com                variant_dir = joinpath(build_root, 'libelf'))
8879812Sandreas.hansson@arm.com
8887727SAli.Saidi@ARM.com# gzstream build is shared across all configs in the build root.
8895863Snate@binkert.orgmain.SConscript('ext/gzstream/SConscript',
8903118Sstever@eecs.umich.edu                variant_dir = joinpath(build_root, 'gzstream'))
8915863Snate@binkert.org
8929239Sandreas.hansson@arm.com###################################################
8933118Sstever@eecs.umich.edu#
8943118Sstever@eecs.umich.edu# This function is used to set up a directory with switching headers
8955863Snate@binkert.org#
8965863Snate@binkert.org###################################################
8975863Snate@binkert.org
8985863Snate@binkert.orgmain['ALL_ISA_LIST'] = all_isa_list
8993118Sstever@eecs.umich.edudef make_switching_dir(dname, switch_headers, env):
9003483Ssaidi@eecs.umich.edu    # Generate the header.  target[0] is the full path of the output
9013494Ssaidi@eecs.umich.edu    # header to generate.  'source' is a dummy variable, since we get the
9023494Ssaidi@eecs.umich.edu    # list of ISAs from env['ALL_ISA_LIST'].
9033483Ssaidi@eecs.umich.edu    def gen_switch_hdr(target, source, env):
9043483Ssaidi@eecs.umich.edu        fname = str(target[0])
9053483Ssaidi@eecs.umich.edu        f = open(fname, 'w')
9063053Sstever@eecs.umich.edu        isa = env['TARGET_ISA'].lower()
9073053Sstever@eecs.umich.edu        print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
9083918Ssaidi@eecs.umich.edu        f.close()
9093053Sstever@eecs.umich.edu
9103053Sstever@eecs.umich.edu    # Build SCons Action object. 'varlist' specifies env vars that this
9113053Sstever@eecs.umich.edu    # action depends on; when env['ALL_ISA_LIST'] changes these actions
9123053Sstever@eecs.umich.edu    # should get re-executed.
9133053Sstever@eecs.umich.edu    switch_hdr_action = MakeAction(gen_switch_hdr,
9149396Sandreas.hansson@arm.com                          Transform("GENERATE"), varlist=['ALL_ISA_LIST'])
9159396Sandreas.hansson@arm.com
9169396Sandreas.hansson@arm.com    # Instantiate actions for each header
9179396Sandreas.hansson@arm.com    for hdr in switch_headers:
9189396Sandreas.hansson@arm.com        env.Command(hdr, [], switch_hdr_action)
9199396Sandreas.hansson@arm.comExport('make_switching_dir')
9209396Sandreas.hansson@arm.com
9219396Sandreas.hansson@arm.com###################################################
9229396Sandreas.hansson@arm.com#
9239477Sandreas.hansson@arm.com# Define build environments for selected configurations.
9249396Sandreas.hansson@arm.com#
9259477Sandreas.hansson@arm.com###################################################
9269477Sandreas.hansson@arm.com
9279477Sandreas.hansson@arm.comfor variant_path in variant_paths:
9289477Sandreas.hansson@arm.com    print "Building in", variant_path
9299396Sandreas.hansson@arm.com
9307840Snate@binkert.org    # Make a copy of the build-root environment to use for this config.
9317865Sgblack@eecs.umich.edu    env = main.Clone()
9327865Sgblack@eecs.umich.edu    env['BUILDDIR'] = variant_path
9337865Sgblack@eecs.umich.edu
9347865Sgblack@eecs.umich.edu    # variant_dir is the tail component of build path, and is used to
9357865Sgblack@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
9367840Snate@binkert.org    (build_root, variant_dir) = splitpath(variant_path)
9379900Sandreas@sandberg.pp.se
9389900Sandreas@sandberg.pp.se    # Set env variables according to the build directory config.
9399900Sandreas@sandberg.pp.se    sticky_vars.files = []
9409900Sandreas@sandberg.pp.se    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
9419591Sandreas@sandberg.pp.se    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
9429591Sandreas@sandberg.pp.se    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
9439591Sandreas@sandberg.pp.se    current_vars_file = joinpath(build_root, 'variables', variant_dir)
9449590Sandreas@sandberg.pp.se    if isfile(current_vars_file):
9459590Sandreas@sandberg.pp.se        sticky_vars.files.append(current_vars_file)
9469045SAli.Saidi@ARM.com        print "Using saved variables file %s" % current_vars_file
9479045SAli.Saidi@ARM.com    else:
9489071Sandreas.hansson@arm.com        # Build dir-specific variables file doesn't exist.
9499071Sandreas.hansson@arm.com
9509045SAli.Saidi@ARM.com        # Make sure the directory is there so we can create it later
9517840Snate@binkert.org        opt_dir = dirname(current_vars_file)
9527840Snate@binkert.org        if not isdir(opt_dir):
9537840Snate@binkert.org            mkdir(opt_dir)
9541858SN/A
9551858SN/A        # Get default build variables from source tree.  Variables are
9561858SN/A        # normally determined by name of $VARIANT_DIR, but can be
9571858SN/A        # overridden by '--default=' arg on command line.
9581858SN/A        default = GetOption('default')
9591858SN/A        opts_dir = joinpath(main.root.abspath, 'build_opts')
9609903Sandreas.hansson@arm.com        if default:
9619903Sandreas.hansson@arm.com            default_vars_files = [joinpath(build_root, 'variables', default),
9629903Sandreas.hansson@arm.com                                  joinpath(opts_dir, default)]
9639903Sandreas.hansson@arm.com        else:
9649903Sandreas.hansson@arm.com            default_vars_files = [joinpath(opts_dir, variant_dir)]
9659903Sandreas.hansson@arm.com        existing_files = filter(isfile, default_vars_files)
9669651SAndreas.Sandberg@ARM.com        if existing_files:
9679903Sandreas.hansson@arm.com            default_vars_file = existing_files[0]
9689651SAndreas.Sandberg@ARM.com            sticky_vars.files.append(default_vars_file)
9699651SAndreas.Sandberg@ARM.com            print "Variables file %s not found,\n  using defaults in %s" \
9709651SAndreas.Sandberg@ARM.com                  % (current_vars_file, default_vars_file)
9719651SAndreas.Sandberg@ARM.com        else:
9729651SAndreas.Sandberg@ARM.com            print "Error: cannot find variables file %s or " \
9739657Sandreas.sandberg@arm.com                  "default file(s) %s" \
9749883Sandreas@sandberg.pp.se                  % (current_vars_file, ' or '.join(default_vars_files))
9759651SAndreas.Sandberg@ARM.com            Exit(1)
9769651SAndreas.Sandberg@ARM.com
9779651SAndreas.Sandberg@ARM.com    # Apply current variable settings to env
9789651SAndreas.Sandberg@ARM.com    sticky_vars.Update(env)
9799651SAndreas.Sandberg@ARM.com
9809651SAndreas.Sandberg@ARM.com    help_texts["local_vars"] += \
9819651SAndreas.Sandberg@ARM.com        "Build variables for %s:\n" % variant_dir \
9829651SAndreas.Sandberg@ARM.com                 + sticky_vars.GenerateHelpText(env)
9839651SAndreas.Sandberg@ARM.com
9849651SAndreas.Sandberg@ARM.com    # Process variable settings.
9859651SAndreas.Sandberg@ARM.com
9869986Sandreas@sandberg.pp.se    if not have_fenv and env['USE_FENV']:
9879986Sandreas@sandberg.pp.se        print "Warning: <fenv.h> not available; " \
9889986Sandreas@sandberg.pp.se              "forcing USE_FENV to False in", variant_dir + "."
9899986Sandreas@sandberg.pp.se        env['USE_FENV'] = False
9909986Sandreas@sandberg.pp.se
9919986Sandreas@sandberg.pp.se    if not env['USE_FENV']:
9925863Snate@binkert.org        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
9935863Snate@binkert.org        print "         FP results may deviate slightly from other platforms."
9945863Snate@binkert.org
9955863Snate@binkert.org    if env['EFENCE']:
9966121Snate@binkert.org        env.Append(LIBS=['efence'])
9971858SN/A
9985863Snate@binkert.org    # Save sticky variable settings back to current variables file
9995863Snate@binkert.org    sticky_vars.Save(current_vars_file, env)
10005863Snate@binkert.org
10015863Snate@binkert.org    if env['USE_SSE2']:
10025863Snate@binkert.org        env.Append(CCFLAGS=['-msse2'])
10032139SN/A
10044202Sbinkertn@umich.edu    # The src/SConscript file sets up the build rules in 'env' according
10054202Sbinkertn@umich.edu    # to the configured variables.  It returns a list of environments,
10062139SN/A    # one for each variant build (debug, opt, etc.)
10076994Snate@binkert.org    envList = SConscript('src/SConscript', variant_dir = variant_path,
10086994Snate@binkert.org                         exports = 'env')
10096994Snate@binkert.org
10106994Snate@binkert.org    # Set up the regression tests for each build.
10116994Snate@binkert.org    for e in envList:
10126994Snate@binkert.org        SConscript('tests/SConscript',
10136994Snate@binkert.org                   variant_dir = joinpath(variant_path, 'tests', e.Label),
10146994Snate@binkert.org                   exports = { 'env' : e }, duplicate = False)
10156994Snate@binkert.org
10166994Snate@binkert.org# base help text
10176994Snate@binkert.orgHelp('''
10186994Snate@binkert.orgUsage: scons [scons options] [build variables] [target(s)]
10196994Snate@binkert.org
10206994Snate@binkert.orgExtra scons options:
10216994Snate@binkert.org%(options)s
10226994Snate@binkert.org
10236994Snate@binkert.orgGlobal build variables:
10246994Snate@binkert.org%(global_vars)s
10256994Snate@binkert.org
10266994Snate@binkert.org%(local_vars)s
10276994Snate@binkert.org''' % help_texts)
10286994Snate@binkert.org