SConstruct revision 7840
1955SN/A# -*- mode:python -*-
2955SN/A
311408Sandreas.sandberg@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 ('m5'), 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_FS/m5.opt' for
41955SN/A# the optimized full-system version).
422665Ssaidi@eecs.umich.edu#
432665Ssaidi@eecs.umich.edu# You can build M5 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>/m5 ; scons build/ALPHA_FS/m5.debug
532632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.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>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
602632Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.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# 'm5' 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 M5-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://m5sim.org/wiki/index.php/Compiling_M5
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://m5sim.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
11511401Sandreas.sandberg@arm.comextra_python_paths = [
1165863Snate@binkert.org    Dir('src/python').srcnode().abspath, # M5 includes
1175863Snate@binkert.org    Dir('ext/ply').srcnode().abspath, # ply is used by several files
1184202Sbinkertn@umich.edu    ]
1195863Snate@binkert.org    
1205863Snate@binkert.orgsys.path[1:1] = extra_python_paths
1215863Snate@binkert.org
1225863Snate@binkert.orgfrom m5.util import compareVersions, readCommand
123955SN/A
1246654Snate@binkert.orgAddOption('--colors', dest='use_colors', action='store_true')
1255273Sstever@gmail.comAddOption('--no-colors', dest='use_colors', action='store_false')
1265871Snate@binkert.orguse_colors = GetOption('use_colors')
1275273Sstever@gmail.com
1286655Snate@binkert.orgif use_colors:
1298878Ssteve.reinhardt@amd.com    from m5.util.terminal import termcap
1306655Snate@binkert.orgelif use_colors is None:
1316655Snate@binkert.org    # option unspecified; default behavior is to use colors iff isatty
1329219Spower.jg@gmail.com    from m5.util.terminal import tty_termcap as termcap
1336655Snate@binkert.orgelse:
1345871Snate@binkert.org    from m5.util.terminal import no_termcap as termcap
1356654Snate@binkert.org
1368947Sandreas.hansson@arm.com########################################################################
1375396Ssaidi@eecs.umich.edu#
1388120Sgblack@eecs.umich.edu# Set up the main build environment.
1398120Sgblack@eecs.umich.edu#
1408120Sgblack@eecs.umich.edu########################################################################
1418120Sgblack@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
1428120Sgblack@eecs.umich.edu                 'PYTHONPATH', 'RANLIB' ])
1438120Sgblack@eecs.umich.edu
1448120Sgblack@eecs.umich.eduuse_env = {}
1458120Sgblack@eecs.umich.edufor key,val in os.environ.iteritems():
1468879Ssteve.reinhardt@amd.com    if key in use_vars or key.startswith("M5"):
1478879Ssteve.reinhardt@amd.com        use_env[key] = val
1488879Ssteve.reinhardt@amd.com
1498879Ssteve.reinhardt@amd.commain = Environment(ENV=use_env)
1508879Ssteve.reinhardt@amd.commain.root = Dir(".")         # The current directory (where this file lives).
1518879Ssteve.reinhardt@amd.commain.srcdir = Dir("src")     # The source directory
1528879Ssteve.reinhardt@amd.com
1538879Ssteve.reinhardt@amd.com# add useful python code PYTHONPATH so it can be used by subprocesses
1548879Ssteve.reinhardt@amd.com# as well
1558879Ssteve.reinhardt@amd.commain.AppendENVPath('PYTHONPATH', extra_python_paths)
1568879Ssteve.reinhardt@amd.com
1578879Ssteve.reinhardt@amd.com########################################################################
1588879Ssteve.reinhardt@amd.com#
1598120Sgblack@eecs.umich.edu# Mercurial Stuff.
1608120Sgblack@eecs.umich.edu#
1618120Sgblack@eecs.umich.edu# If the M5 directory is a mercurial repository, we should do some
1628120Sgblack@eecs.umich.edu# extra things.
1638120Sgblack@eecs.umich.edu#
1648120Sgblack@eecs.umich.edu########################################################################
1658120Sgblack@eecs.umich.edu
1668120Sgblack@eecs.umich.eduhgdir = main.root.Dir(".hg")
1678120Sgblack@eecs.umich.edu
1688120Sgblack@eecs.umich.edumercurial_style_message = """
1698120Sgblack@eecs.umich.eduYou're missing the M5 style hook.
1708120Sgblack@eecs.umich.eduPlease install the hook so we can ensure that all code fits a common style.
1718120Sgblack@eecs.umich.edu
1728120Sgblack@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc
1738879Ssteve.reinhardt@amd.comor your personal .hgrc
1748879Ssteve.reinhardt@amd.com----------------
1758879Ssteve.reinhardt@amd.com
1768879Ssteve.reinhardt@amd.com[extensions]
17710458Sandreas.hansson@arm.comstyle = %s/util/style.py
17810458Sandreas.hansson@arm.com
17910458Sandreas.hansson@arm.com[hooks]
1808879Ssteve.reinhardt@amd.compretxncommit.style = python:style.check_style
1818879Ssteve.reinhardt@amd.compre-qrefresh.style = python:style.check_style
1828879Ssteve.reinhardt@amd.com""" % (main.root)
1838879Ssteve.reinhardt@amd.com
1849227Sandreas.hansson@arm.commercurial_bin_not_found = """
1859227Sandreas.hansson@arm.comMercurial binary cannot be found, unfortunately this means that we
18612063Sgabeblack@google.comcannot easily determine the version of M5 that you are running and
18712063Sgabeblack@google.comthis makes error messages more difficult to collect.  Please consider
18812063Sgabeblack@google.cominstalling mercurial if you choose to post an error message
1898879Ssteve.reinhardt@amd.com"""
1908879Ssteve.reinhardt@amd.com
1918879Ssteve.reinhardt@amd.commercurial_lib_not_found = """
1928879Ssteve.reinhardt@amd.comMercurial libraries cannot be found, ignoring style hook
19310453SAndrew.Bardsley@arm.comIf you are actually a M5 developer, please fix this and
19410453SAndrew.Bardsley@arm.comrun the style hook. It is important.
19510453SAndrew.Bardsley@arm.com"""
19610456SCurtis.Dunham@arm.com
19710456SCurtis.Dunham@arm.comhg_info = "Unknown"
19810456SCurtis.Dunham@arm.comif hgdir.exists():
19910457Sandreas.hansson@arm.com    # 1) Grab repository revision if we know it.
20010457Sandreas.hansson@arm.com    cmd = "hg id -n -i -t -b"
20111342Sandreas.hansson@arm.com    try:
20211342Sandreas.hansson@arm.com        hg_info = readCommand(cmd, cwd=main.root.abspath).strip()
2038120Sgblack@eecs.umich.edu    except OSError:
20412063Sgabeblack@google.com        print mercurial_bin_not_found
20512063Sgabeblack@google.com
20612063Sgabeblack@google.com    # 2) Ensure that the style hook is in place.
20712063Sgabeblack@google.com    try:
2088947Sandreas.hansson@arm.com        ui = None
2097816Ssteve.reinhardt@amd.com        if ARGUMENTS.get('IGNORE_STYLE') != 'True':
2105871Snate@binkert.org            from mercurial import ui
2115871Snate@binkert.org            ui = ui.ui()
2126121Snate@binkert.org    except ImportError:
2135871Snate@binkert.org        print mercurial_lib_not_found
2145871Snate@binkert.org
2159926Sstan.czerniawski@arm.com    if ui is not None:
2169926Sstan.czerniawski@arm.com        ui.readconfig(hgdir.File('hgrc').abspath)
2179119Sandreas.hansson@arm.com        style_hook = ui.config('hooks', 'pretxncommit.style', None)
21810068Sandreas.hansson@arm.com
21911989Sandreas.sandberg@arm.com        if not style_hook:
220955SN/A            print mercurial_style_message
2219416SAndreas.Sandberg@ARM.com            sys.exit(1)
22211342Sandreas.hansson@arm.comelse:
22311212Sjoseph.gross@amd.com    print ".hg directory not found"
22411212Sjoseph.gross@amd.com
22511212Sjoseph.gross@amd.commain['HG_INFO'] = hg_info
22611212Sjoseph.gross@amd.com
22711212Sjoseph.gross@amd.com###################################################
2289416SAndreas.Sandberg@ARM.com#
2299416SAndreas.Sandberg@ARM.com# Figure out which configurations to set up based on the path(s) of
2305871Snate@binkert.org# the target(s).
23110584Sandreas.hansson@arm.com#
2329416SAndreas.Sandberg@ARM.com###################################################
2339416SAndreas.Sandberg@ARM.com
2345871Snate@binkert.org# Find default configuration & binary.
235955SN/ADefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
23610671Sandreas.hansson@arm.com
23710671Sandreas.hansson@arm.com# helper function: find last occurrence of element in list
23810671Sandreas.hansson@arm.comdef rfind(l, elt, offs = -1):
23910671Sandreas.hansson@arm.com    for i in range(len(l)+offs, 0, -1):
2408881Smarc.orr@gmail.com        if l[i] == elt:
2416121Snate@binkert.org            return i
2426121Snate@binkert.org    raise ValueError, "element not found"
2431533SN/A
2449239Sandreas.hansson@arm.com# Each target must have 'build' in the interior of the path; the
2459239Sandreas.hansson@arm.com# directory below this will determine the build parameters.  For
2469239Sandreas.hansson@arm.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
2479239Sandreas.hansson@arm.com# recognize that ALPHA_SE specifies the configuration because it
2489239Sandreas.hansson@arm.com# follow 'build' in the bulid path.
2499239Sandreas.hansson@arm.com
2509239Sandreas.hansson@arm.com# Generate absolute paths to targets so we can see where the build dir is
2516655Snate@binkert.orgif COMMAND_LINE_TARGETS:
2526655Snate@binkert.org    # Ask SCons which directory it was invoked from
2536655Snate@binkert.org    launch_dir = GetLaunchDir()
2546655Snate@binkert.org    # Make targets relative to invocation directory
2555871Snate@binkert.org    abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \
2565871Snate@binkert.org                    COMMAND_LINE_TARGETS]
2575863Snate@binkert.orgelse:
2585871Snate@binkert.org    # Default targets are relative to root of tree
2598878Ssteve.reinhardt@amd.com    abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \
2605871Snate@binkert.org                    DEFAULT_TARGETS]
2615871Snate@binkert.org
2625871Snate@binkert.org
2635863Snate@binkert.org# Generate a list of the unique build roots and configs that the
2646121Snate@binkert.org# collected targets reference.
2655863Snate@binkert.orgvariant_paths = []
26611408Sandreas.sandberg@arm.combuild_root = None
26711408Sandreas.sandberg@arm.comfor t in abs_targets:
2688336Ssteve.reinhardt@amd.com    path_dirs = t.split('/')
26911469SCurtis.Dunham@arm.com    try:
27011469SCurtis.Dunham@arm.com        build_top = rfind(path_dirs, 'build', -2)
2718336Ssteve.reinhardt@amd.com    except:
2724678Snate@binkert.org        print "Error: no non-leaf 'build' dir found on target path", t
27311887Sandreas.sandberg@arm.com        Exit(1)
27411887Sandreas.sandberg@arm.com    this_build_root = joinpath('/',*path_dirs[:build_top+1])
27511887Sandreas.sandberg@arm.com    if not build_root:
27611887Sandreas.sandberg@arm.com        build_root = this_build_root
27711887Sandreas.sandberg@arm.com    else:
27811887Sandreas.sandberg@arm.com        if this_build_root != build_root:
27911887Sandreas.sandberg@arm.com            print "Error: build targets not under same build root\n"\
28011887Sandreas.sandberg@arm.com                  "  %s\n  %s" % (build_root, this_build_root)
28111887Sandreas.sandberg@arm.com            Exit(1)
28211887Sandreas.sandberg@arm.com    variant_path = joinpath('/',*path_dirs[:build_top+2])
28311887Sandreas.sandberg@arm.com    if variant_path not in variant_paths:
28411408Sandreas.sandberg@arm.com        variant_paths.append(variant_path)
28511401Sandreas.sandberg@arm.com
28611401Sandreas.sandberg@arm.com# Make sure build_root exists (might not if this is the first build there)
28711401Sandreas.sandberg@arm.comif not isdir(build_root):
28811401Sandreas.sandberg@arm.com    mkdir(build_root)
28911401Sandreas.sandberg@arm.commain['BUILDROOT'] = build_root
29011401Sandreas.sandberg@arm.com
2918336Ssteve.reinhardt@amd.comExport('main')
2928336Ssteve.reinhardt@amd.com
2938336Ssteve.reinhardt@amd.commain.SConsignFile(joinpath(build_root, "sconsign"))
2944678Snate@binkert.org
29511401Sandreas.sandberg@arm.com# Default duplicate option is to use hard links, but this messes up
2964678Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves
2974678Snate@binkert.org# file to file~ then copies to file, breaking the link.  Symbolic
29811401Sandreas.sandberg@arm.com# (soft) links work better.
29911401Sandreas.sandberg@arm.commain.SetOption('duplicate', 'soft-copy')
3008336Ssteve.reinhardt@amd.com
3014678Snate@binkert.org#
3028336Ssteve.reinhardt@amd.com# Set up global sticky variables... these are common to an entire build
3038336Ssteve.reinhardt@amd.com# tree (not specific to a particular build like ALPHA_SE)
3048336Ssteve.reinhardt@amd.com#
3058336Ssteve.reinhardt@amd.com
3068336Ssteve.reinhardt@amd.com# Variable validators & converters for global sticky variables
3078336Ssteve.reinhardt@amd.comdef PathListMakeAbsolute(val):
3085871Snate@binkert.org    if not val:
3095871Snate@binkert.org        return val
3108336Ssteve.reinhardt@amd.com    f = lambda p: abspath(expanduser(p))
31111408Sandreas.sandberg@arm.com    return ':'.join(map(f, val.split(':')))
31211408Sandreas.sandberg@arm.com
31311408Sandreas.sandberg@arm.comdef PathListAllExist(key, val, env):
31411408Sandreas.sandberg@arm.com    if not val:
31511408Sandreas.sandberg@arm.com        return
31611408Sandreas.sandberg@arm.com    paths = val.split(':')
31711408Sandreas.sandberg@arm.com    for path in paths:
3188336Ssteve.reinhardt@amd.com        if not isdir(path):
31911401Sandreas.sandberg@arm.com            raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
32011401Sandreas.sandberg@arm.com
32111401Sandreas.sandberg@arm.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global')
3225871Snate@binkert.org
3238336Ssteve.reinhardt@amd.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS)
3248336Ssteve.reinhardt@amd.comglobal_nonsticky_vars = Variables(args=ARGUMENTS)
32511401Sandreas.sandberg@arm.com
32611401Sandreas.sandberg@arm.comglobal_sticky_vars.AddVariables(
32711401Sandreas.sandberg@arm.com    ('CC', 'C compiler', environ.get('CC', main['CC'])),
32811401Sandreas.sandberg@arm.com    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
32911401Sandreas.sandberg@arm.com    ('BATCH', 'Use batch pool for build and tests', False),
3304678Snate@binkert.org    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3315871Snate@binkert.org    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
3324678Snate@binkert.org    ('EXTRAS', 'Add Extra directories to the compilation', '',
33311401Sandreas.sandberg@arm.com     PathListAllExist, PathListMakeAbsolute),
33411401Sandreas.sandberg@arm.com    )
33511401Sandreas.sandberg@arm.com
33611401Sandreas.sandberg@arm.comglobal_nonsticky_vars.AddVariables(
33711401Sandreas.sandberg@arm.com    ('VERBOSE', 'Print full tool command lines', False),
33811401Sandreas.sandberg@arm.com    ('update_ref', 'Update test reference outputs', False)
33911401Sandreas.sandberg@arm.com    )
34011401Sandreas.sandberg@arm.com
34111401Sandreas.sandberg@arm.com
34211401Sandreas.sandberg@arm.com# base help text
34311401Sandreas.sandberg@arm.comhelp_text = '''
34411401Sandreas.sandberg@arm.comUsage: scons [scons options] [build options] [target(s)]
34511450Sandreas.sandberg@arm.com
34611450Sandreas.sandberg@arm.comGlobal sticky options:
34711450Sandreas.sandberg@arm.com'''
34811450Sandreas.sandberg@arm.com
34911450Sandreas.sandberg@arm.com# Update main environment with values from ARGUMENTS & global_sticky_vars_file
35011450Sandreas.sandberg@arm.comglobal_sticky_vars.Update(main)
35111450Sandreas.sandberg@arm.comglobal_nonsticky_vars.Update(main)
35211450Sandreas.sandberg@arm.com
35311450Sandreas.sandberg@arm.comhelp_text += global_sticky_vars.GenerateHelpText(main)
35411450Sandreas.sandberg@arm.comhelp_text += global_nonsticky_vars.GenerateHelpText(main)
35511450Sandreas.sandberg@arm.com
35611401Sandreas.sandberg@arm.com# Save sticky variable settings back to current variables file
35711450Sandreas.sandberg@arm.comglobal_sticky_vars.Save(global_sticky_vars_file, main)
35811450Sandreas.sandberg@arm.com
35911450Sandreas.sandberg@arm.com# Parse EXTRAS variable to build list of all directories where we're
36011401Sandreas.sandberg@arm.com# look for sources etc.  This list is exported as base_dir_list.
36111450Sandreas.sandberg@arm.combase_dir = main.srcdir.abspath
36211401Sandreas.sandberg@arm.comif main['EXTRAS']:
3638336Ssteve.reinhardt@amd.com    extras_dir_list = main['EXTRAS'].split(':')
3648336Ssteve.reinhardt@amd.comelse:
3658336Ssteve.reinhardt@amd.com    extras_dir_list = []
3668336Ssteve.reinhardt@amd.com
3678336Ssteve.reinhardt@amd.comExport('base_dir')
3688336Ssteve.reinhardt@amd.comExport('extras_dir_list')
3698336Ssteve.reinhardt@amd.com
3708336Ssteve.reinhardt@amd.com# the ext directory should be on the #includes path
3718336Ssteve.reinhardt@amd.commain.Append(CPPPATH=[Dir('ext')])
3728336Ssteve.reinhardt@amd.com
37311401Sandreas.sandberg@arm.comdef strip_build_path(path, env):
37411401Sandreas.sandberg@arm.com    path = str(path)
3758336Ssteve.reinhardt@amd.com    variant_base = env['BUILDROOT'] + os.path.sep
3768336Ssteve.reinhardt@amd.com    if path.startswith(variant_base):
3778336Ssteve.reinhardt@amd.com        path = path[len(variant_base):]
3785871Snate@binkert.org    elif path.startswith('build/'):
37911476Sandreas.sandberg@arm.com        path = path[6:]
38011476Sandreas.sandberg@arm.com    return path
38111476Sandreas.sandberg@arm.com
38211476Sandreas.sandberg@arm.com# Generate a string of the form:
38311476Sandreas.sandberg@arm.com#   common/path/prefix/src1, src2 -> tgt1, tgt2
38411476Sandreas.sandberg@arm.com# to print while building.
38511476Sandreas.sandberg@arm.comclass Transform(object):
38611476Sandreas.sandberg@arm.com    # all specific color settings should be here and nowhere else
38711476Sandreas.sandberg@arm.com    tool_color = termcap.Normal
38811887Sandreas.sandberg@arm.com    pfx_color = termcap.Yellow
38911887Sandreas.sandberg@arm.com    srcs_color = termcap.Yellow + termcap.Bold
39011887Sandreas.sandberg@arm.com    arrow_color = termcap.Blue + termcap.Bold
39111408Sandreas.sandberg@arm.com    tgts_color = termcap.Yellow + termcap.Bold
39211887Sandreas.sandberg@arm.com
39311887Sandreas.sandberg@arm.com    def __init__(self, tool, max_sources=99):
39411887Sandreas.sandberg@arm.com        self.format = self.tool_color + (" [%8s] " % tool) \
39511887Sandreas.sandberg@arm.com                      + self.pfx_color + "%s" \
39611887Sandreas.sandberg@arm.com                      + self.srcs_color + "%s" \
39711887Sandreas.sandberg@arm.com                      + self.arrow_color + " -> " \
39811926Sgabeblack@google.com                      + self.tgts_color + "%s" \
39911926Sgabeblack@google.com                      + termcap.Normal
40011926Sgabeblack@google.com        self.max_sources = max_sources
40111926Sgabeblack@google.com
40211887Sandreas.sandberg@arm.com    def __call__(self, target, source, env, for_signature=None):
40311887Sandreas.sandberg@arm.com        # truncate source list according to max_sources param
40411944Sandreas.sandberg@arm.com        source = source[0:self.max_sources]
40511887Sandreas.sandberg@arm.com        def strip(f):
40611927Sgabeblack@google.com            return strip_build_path(str(f), env)
40711927Sgabeblack@google.com        if len(source) > 0:
40811927Sgabeblack@google.com            srcs = map(strip, source)
40911927Sgabeblack@google.com        else:
41011927Sgabeblack@google.com            srcs = ['']
41111927Sgabeblack@google.com        tgts = map(strip, target)
41211887Sandreas.sandberg@arm.com        # surprisingly, os.path.commonprefix is a dumb char-by-char string
41311928Sgabeblack@google.com        # operation that has nothing to do with paths.
41411928Sgabeblack@google.com        com_pfx = os.path.commonprefix(srcs + tgts)
41511887Sandreas.sandberg@arm.com        com_pfx_len = len(com_pfx)
41611887Sandreas.sandberg@arm.com        if com_pfx:
41711887Sandreas.sandberg@arm.com            # do some cleanup and sanity checking on common prefix
41811887Sandreas.sandberg@arm.com            if com_pfx[-1] == ".":
41911887Sandreas.sandberg@arm.com                # prefix matches all but file extension: ok
42011887Sandreas.sandberg@arm.com                # back up one to change 'foo.cc -> o' to 'foo.cc -> .o'
42111887Sandreas.sandberg@arm.com                com_pfx = com_pfx[0:-1]
42211887Sandreas.sandberg@arm.com            elif com_pfx[-1] == "/":
42311887Sandreas.sandberg@arm.com                # common prefix is directory path: OK
42411887Sandreas.sandberg@arm.com                pass
42511476Sandreas.sandberg@arm.com            else:
42611476Sandreas.sandberg@arm.com                src0_len = len(srcs[0])
42711408Sandreas.sandberg@arm.com                tgt0_len = len(tgts[0])
42811408Sandreas.sandberg@arm.com                if src0_len == com_pfx_len:
42911408Sandreas.sandberg@arm.com                    # source is a substring of target, OK
43011408Sandreas.sandberg@arm.com                    pass
43111408Sandreas.sandberg@arm.com                elif tgt0_len == com_pfx_len:
43211408Sandreas.sandberg@arm.com                    # target is a substring of source, need to back up to
43311408Sandreas.sandberg@arm.com                    # avoid empty string on RHS of arrow
43411887Sandreas.sandberg@arm.com                    sep_idx = com_pfx.rfind(".")
43511887Sandreas.sandberg@arm.com                    if sep_idx != -1:
43611476Sandreas.sandberg@arm.com                        com_pfx = com_pfx[0:sep_idx]
43711887Sandreas.sandberg@arm.com                    else:
43811887Sandreas.sandberg@arm.com                        com_pfx = ''
43911476Sandreas.sandberg@arm.com                elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".":
44011476Sandreas.sandberg@arm.com                    # still splitting at file extension: ok
44111476Sandreas.sandberg@arm.com                    pass
44211476Sandreas.sandberg@arm.com                else:
4436121Snate@binkert.org                    # probably a fluke; ignore it
444955SN/A                    com_pfx = ''
445955SN/A        # recalculate length in case com_pfx was modified
4462632Sstever@eecs.umich.edu        com_pfx_len = len(com_pfx)
4472632Sstever@eecs.umich.edu        def fmt(files):
448955SN/A            f = map(lambda s: s[com_pfx_len:], files)
449955SN/A            return ', '.join(f)
450955SN/A        return self.format % (com_pfx, fmt(srcs), fmt(tgts))
451955SN/A
4528878Ssteve.reinhardt@amd.comExport('Transform')
453955SN/A
4542632Sstever@eecs.umich.edu
4552632Sstever@eecs.umich.eduif main['VERBOSE']:
4562632Sstever@eecs.umich.edu    def MakeAction(action, string, *args, **kwargs):
4572632Sstever@eecs.umich.edu        return Action(action, *args, **kwargs)
4582632Sstever@eecs.umich.eduelse:
4592632Sstever@eecs.umich.edu    MakeAction = Action
4602632Sstever@eecs.umich.edu    main['CCCOMSTR']        = Transform("CC")
4618268Ssteve.reinhardt@amd.com    main['CXXCOMSTR']       = Transform("CXX")
4628268Ssteve.reinhardt@amd.com    main['ASCOMSTR']        = Transform("AS")
4638268Ssteve.reinhardt@amd.com    main['SWIGCOMSTR']      = Transform("SWIG")
4648268Ssteve.reinhardt@amd.com    main['ARCOMSTR']        = Transform("AR", 0)
4658268Ssteve.reinhardt@amd.com    main['LINKCOMSTR']      = Transform("LINK", 0)
4668268Ssteve.reinhardt@amd.com    main['RANLIBCOMSTR']    = Transform("RANLIB", 0)
4678268Ssteve.reinhardt@amd.com    main['M4COMSTR']        = Transform("M4")
4682632Sstever@eecs.umich.edu    main['SHCCCOMSTR']      = Transform("SHCC")
4692632Sstever@eecs.umich.edu    main['SHCXXCOMSTR']     = Transform("SHCXX")
4702632Sstever@eecs.umich.eduExport('MakeAction')
4712632Sstever@eecs.umich.edu
4728268Ssteve.reinhardt@amd.comCXX_version = readCommand([main['CXX'],'--version'], exception=False)
4732632Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False)
4748268Ssteve.reinhardt@amd.com
4758268Ssteve.reinhardt@amd.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
4768268Ssteve.reinhardt@amd.commain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
4778268Ssteve.reinhardt@amd.commain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
4783718Sstever@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1:
4792634Sstever@eecs.umich.edu    print 'Error: How can we have two at the same time?'
4802634Sstever@eecs.umich.edu    Exit(1)
4815863Snate@binkert.org
4822638Sstever@eecs.umich.edu# Set up default C++ compiler flags
4838268Ssteve.reinhardt@amd.comif main['GCC']:
4842632Sstever@eecs.umich.edu    main.Append(CCFLAGS=['-pipe'])
4852632Sstever@eecs.umich.edu    main.Append(CCFLAGS=['-fno-strict-aliasing'])
4862632Sstever@eecs.umich.edu    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
4872632Sstever@eecs.umich.edu    main.Append(CXXFLAGS=['-Wno-deprecated'])
4882632Sstever@eecs.umich.edu    # Read the GCC version to check for versions with bugs
4891858SN/A    # Note CCVERSION doesn't work here because it is run with the CC
4903716Sstever@eecs.umich.edu    # before we override it from the command line
4912638Sstever@eecs.umich.edu    gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False)
4922638Sstever@eecs.umich.edu    if not compareVersions(gcc_version, '4.4.1') or \
4932638Sstever@eecs.umich.edu       not compareVersions(gcc_version, '4.4.2'):
4942638Sstever@eecs.umich.edu        print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.'
4952638Sstever@eecs.umich.edu        main.Append(CCFLAGS=['-fno-tree-vectorize'])
4962638Sstever@eecs.umich.eduelif main['ICC']:
4972638Sstever@eecs.umich.edu    pass #Fix me... add warning flags once we clean up icc warnings
4985863Snate@binkert.orgelif main['SUNCC']:
4995863Snate@binkert.org    main.Append(CCFLAGS=['-Qoption ccfe'])
5005863Snate@binkert.org    main.Append(CCFLAGS=['-features=gcc'])
501955SN/A    main.Append(CCFLAGS=['-features=extensions'])
5025341Sstever@gmail.com    main.Append(CCFLAGS=['-library=stlport4'])
5035341Sstever@gmail.com    main.Append(CCFLAGS=['-xar'])
5045863Snate@binkert.org    #main.Append(CCFLAGS=['-instances=semiexplicit'])
5057756SAli.Saidi@ARM.comelse:
5065341Sstever@gmail.com    print 'Error: Don\'t know what compiler options to use for your compiler.'
5076121Snate@binkert.org    print '       Please fix SConstruct and src/SConscript and try again.'
5084494Ssaidi@eecs.umich.edu    Exit(1)
5096121Snate@binkert.org
5101105SN/A# Set up common yacc/bison flags (needed for Ruby)
5112667Sstever@eecs.umich.edumain['YACCFLAGS'] = '-d'
5122667Sstever@eecs.umich.edumain['YACCHXXFILESUFFIX'] = '.hh'
5132667Sstever@eecs.umich.edu
5142667Sstever@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an
5156121Snate@binkert.org# extra 'qdo' every time we run scons.
5162667Sstever@eecs.umich.eduif main['BATCH']:
5175341Sstever@gmail.com    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
5185863Snate@binkert.org    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
5195341Sstever@gmail.com    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
5205341Sstever@gmail.com    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
5215341Sstever@gmail.com    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
5228120Sgblack@eecs.umich.edu
5235341Sstever@gmail.comif sys.platform == 'cygwin':
5248120Sgblack@eecs.umich.edu    # cygwin has some header file issues...
5255341Sstever@gmail.com    main.Append(CCFLAGS=["-Wno-uninitialized"])
5268120Sgblack@eecs.umich.edu
5276121Snate@binkert.org# Check for SWIG
5286121Snate@binkert.orgif not main.has_key('SWIG'):
5299396Sandreas.hansson@arm.com    print 'Error: SWIG utility not found.'
5305397Ssaidi@eecs.umich.edu    print '       Please install (see http://www.swig.org) and retry.'
5315397Ssaidi@eecs.umich.edu    Exit(1)
5327727SAli.Saidi@ARM.com
5338268Ssteve.reinhardt@amd.com# Check for appropriate SWIG version
5346168Snate@binkert.orgswig_version = readCommand(('swig', '-version'), exception='').split()
5355341Sstever@gmail.com# First 3 words should be "SWIG Version x.y.z"
5368120Sgblack@eecs.umich.eduif len(swig_version) < 3 or \
5378120Sgblack@eecs.umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
5388120Sgblack@eecs.umich.edu    print 'Error determining SWIG version.'
5396814Sgblack@eecs.umich.edu    Exit(1)
5405863Snate@binkert.org
5418120Sgblack@eecs.umich.edumin_swig_version = '1.3.28'
5425341Sstever@gmail.comif compareVersions(swig_version[2], min_swig_version) < 0:
5435863Snate@binkert.org    print 'Error: SWIG version', min_swig_version, 'or newer required.'
5448268Ssteve.reinhardt@amd.com    print '       Installed version:', swig_version[2]
5456121Snate@binkert.org    Exit(1)
5466121Snate@binkert.org
5478268Ssteve.reinhardt@amd.com# Set up SWIG flags & scanner
5485742Snate@binkert.orgswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
5495742Snate@binkert.orgmain.Append(SWIGFLAGS=swig_flags)
5505341Sstever@gmail.com
5515742Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency
5525742Snate@binkert.org# stuff for some reason
5535341Sstever@gmail.comscanners = []
5546017Snate@binkert.orgfor scanner in main['SCANNERS']:
5556121Snate@binkert.org    skeys = scanner.skeys
5566017Snate@binkert.org    if skeys == '.i':
55712158Sandreas.sandberg@arm.com        continue
55812158Sandreas.sandberg@arm.com
55912158Sandreas.sandberg@arm.com    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
5607816Ssteve.reinhardt@amd.com        continue
5617756SAli.Saidi@ARM.com
5627756SAli.Saidi@ARM.com    scanners.append(scanner)
5637756SAli.Saidi@ARM.com
5647756SAli.Saidi@ARM.com# add the new swig scanner that we like better
5657756SAli.Saidi@ARM.comfrom SCons.Scanner import ClassicCPP as CPPScanner
5667756SAli.Saidi@ARM.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
5677756SAli.Saidi@ARM.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
5687756SAli.Saidi@ARM.com
5697816Ssteve.reinhardt@amd.com# replace the scanners list that has what we want
5707816Ssteve.reinhardt@amd.commain['SCANNERS'] = scanners
5717816Ssteve.reinhardt@amd.com
5727816Ssteve.reinhardt@amd.com# Add a custom Check function to the Configure context so that we can
5737816Ssteve.reinhardt@amd.com# figure out if the compiler adds leading underscores to global
5747816Ssteve.reinhardt@amd.com# variables.  This is needed for the autogenerated asm files that we
5757816Ssteve.reinhardt@amd.com# use for embedding the python code.
5767816Ssteve.reinhardt@amd.comdef CheckLeading(context):
5777816Ssteve.reinhardt@amd.com    context.Message("Checking for leading underscore in global variables...")
5787816Ssteve.reinhardt@amd.com    # 1) Define a global variable called x from asm so the C compiler
5797756SAli.Saidi@ARM.com    #    won't change the symbol at all.
5807816Ssteve.reinhardt@amd.com    # 2) Declare that variable.
5817816Ssteve.reinhardt@amd.com    # 3) Use the variable
5827816Ssteve.reinhardt@amd.com    #
5837816Ssteve.reinhardt@amd.com    # If the compiler prepends an underscore, this will successfully
5847816Ssteve.reinhardt@amd.com    # link because the external symbol 'x' will be called '_x' which
5857816Ssteve.reinhardt@amd.com    # was defined by the asm statement.  If the compiler does not
5867816Ssteve.reinhardt@amd.com    # prepend an underscore, this will not successfully link because
5877816Ssteve.reinhardt@amd.com    # '_x' will have been defined by assembly, while the C portion of
5887816Ssteve.reinhardt@amd.com    # the code will be trying to use 'x'
5897816Ssteve.reinhardt@amd.com    ret = context.TryLink('''
5907816Ssteve.reinhardt@amd.com        asm(".globl _x; _x: .byte 0");
5917816Ssteve.reinhardt@amd.com        extern int x;
5927816Ssteve.reinhardt@amd.com        int main() { return x; }
5937816Ssteve.reinhardt@amd.com        ''', extension=".c")
5947816Ssteve.reinhardt@amd.com    context.env.Append(LEADING_UNDERSCORE=ret)
5957816Ssteve.reinhardt@amd.com    context.Result(ret)
5967816Ssteve.reinhardt@amd.com    return ret
5977816Ssteve.reinhardt@amd.com
5987816Ssteve.reinhardt@amd.com# Platform-specific configuration.  Note again that we assume that all
5997816Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform.
6007816Ssteve.reinhardt@amd.comconf = Configure(main,
6017816Ssteve.reinhardt@amd.com                 conf_dir = joinpath(build_root, '.scons_config'),
6027816Ssteve.reinhardt@amd.com                 log_file = joinpath(build_root, 'scons_config.log'),
6037816Ssteve.reinhardt@amd.com                 custom_tests = { 'CheckLeading' : CheckLeading })
6047816Ssteve.reinhardt@amd.com
6057816Ssteve.reinhardt@amd.com# Check for leading underscores.  Don't really need to worry either
6067816Ssteve.reinhardt@amd.com# way so don't need to check the return code.
6077816Ssteve.reinhardt@amd.comconf.CheckLeading()
6087816Ssteve.reinhardt@amd.com
6097816Ssteve.reinhardt@amd.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin
6107816Ssteve.reinhardt@amd.comtry:
6117816Ssteve.reinhardt@amd.com    import platform
6127816Ssteve.reinhardt@amd.com    uname = platform.uname()
6137816Ssteve.reinhardt@amd.com    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
6147816Ssteve.reinhardt@amd.com        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
6157816Ssteve.reinhardt@amd.com            main.Append(CCFLAGS=['-arch', 'x86_64'])
6167816Ssteve.reinhardt@amd.com            main.Append(CFLAGS=['-arch', 'x86_64'])
6177816Ssteve.reinhardt@amd.com            main.Append(LINKFLAGS=['-arch', 'x86_64'])
6187816Ssteve.reinhardt@amd.com            main.Append(ASFLAGS=['-arch', 'x86_64'])
6197816Ssteve.reinhardt@amd.comexcept:
6207816Ssteve.reinhardt@amd.com    pass
6217816Ssteve.reinhardt@amd.com
6227816Ssteve.reinhardt@amd.com# Recent versions of scons substitute a "Null" object for Configure()
6237816Ssteve.reinhardt@amd.com# when configuration isn't necessary, e.g., if the "--help" option is
6247816Ssteve.reinhardt@amd.com# present.  Unfortuantely this Null object always returns false,
6257816Ssteve.reinhardt@amd.com# breaking all our configuration checks.  We replace it with our own
6267816Ssteve.reinhardt@amd.com# more optimistic null object that returns True instead.
6277816Ssteve.reinhardt@amd.comif not conf:
6287816Ssteve.reinhardt@amd.com    def NullCheck(*args, **kwargs):
6297816Ssteve.reinhardt@amd.com        return True
6307816Ssteve.reinhardt@amd.com
6317816Ssteve.reinhardt@amd.com    class NullConf:
6327816Ssteve.reinhardt@amd.com        def __init__(self, env):
6337816Ssteve.reinhardt@amd.com            self.env = env
6347816Ssteve.reinhardt@amd.com        def Finish(self):
6357816Ssteve.reinhardt@amd.com            return self.env
6367816Ssteve.reinhardt@amd.com        def __getattr__(self, mname):
6377816Ssteve.reinhardt@amd.com            return NullCheck
6387816Ssteve.reinhardt@amd.com
6397816Ssteve.reinhardt@amd.com    conf = NullConf(main)
6407816Ssteve.reinhardt@amd.com
6418947Sandreas.hansson@arm.com# Find Python include and library directories for embedding the
6428947Sandreas.hansson@arm.com# interpreter.  For consistency, we will use the same Python
6437756SAli.Saidi@ARM.com# installation used to run scons (and thus this script).  If you want
6448120Sgblack@eecs.umich.edu# to link in an alternate version, see above for instructions on how
6457756SAli.Saidi@ARM.com# to invoke scons with a different copy of the Python interpreter.
6467756SAli.Saidi@ARM.comfrom distutils import sysconfig
6477756SAli.Saidi@ARM.com
6487756SAli.Saidi@ARM.compy_getvar = sysconfig.get_config_var
6497816Ssteve.reinhardt@amd.com
6507816Ssteve.reinhardt@amd.compy_debug = getattr(sys, 'pydebug', False)
6517816Ssteve.reinhardt@amd.compy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "")
6527816Ssteve.reinhardt@amd.com
6537816Ssteve.reinhardt@amd.compy_general_include = sysconfig.get_python_inc()
65411979Sgabeblack@google.compy_platform_include = sysconfig.get_python_inc(plat_specific=True)
6557816Ssteve.reinhardt@amd.compy_includes = [ py_general_include ]
6567816Ssteve.reinhardt@amd.comif py_platform_include != py_general_include:
6577816Ssteve.reinhardt@amd.com    py_includes.append(py_platform_include)
6587816Ssteve.reinhardt@amd.com
6597756SAli.Saidi@ARM.compy_lib_path = [ py_getvar('LIBDIR') ]
6607756SAli.Saidi@ARM.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no
6619227Sandreas.hansson@arm.com# shared library in prefix/lib/.
6629227Sandreas.hansson@arm.comif not py_getvar('Py_ENABLE_SHARED'):
6639227Sandreas.hansson@arm.com    py_lib_path.append(py_getvar('LIBPL'))
6649227Sandreas.hansson@arm.com
6659590Sandreas@sandberg.pp.sepy_libs = []
6669590Sandreas@sandberg.pp.sefor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
6679590Sandreas@sandberg.pp.se    assert lib.startswith('-l')
6689590Sandreas@sandberg.pp.se    lib = lib[2:]   
6699590Sandreas@sandberg.pp.se    if lib not in py_libs:
6709590Sandreas@sandberg.pp.se        py_libs.append(lib)
6716654Snate@binkert.orgpy_libs.append(py_version)
6726654Snate@binkert.org
6735871Snate@binkert.orgmain.Append(CPPPATH=py_includes)
6746121Snate@binkert.orgmain.Append(LIBPATH=py_lib_path)
6758946Sandreas.hansson@arm.com
6769419Sandreas.hansson@arm.com# Cache build files in the supplied directory.
6773940Ssaidi@eecs.umich.eduif main['M5_BUILD_CACHE']:
6783918Ssaidi@eecs.umich.edu    print 'Using build cache located at', main['M5_BUILD_CACHE']
6793918Ssaidi@eecs.umich.edu    CacheDir(main['M5_BUILD_CACHE'])
6801858SN/A
6819556Sandreas.hansson@arm.com
6829556Sandreas.hansson@arm.com# verify that this stuff works
6839556Sandreas.hansson@arm.comif not conf.CheckHeader('Python.h', '<>'):
6849556Sandreas.hansson@arm.com    print "Error: can't find Python.h header in", py_includes
68511294Sandreas.hansson@arm.com    Exit(1)
68611294Sandreas.hansson@arm.com
68711294Sandreas.hansson@arm.comfor lib in py_libs:
68811294Sandreas.hansson@arm.com    if not conf.CheckLib(lib):
68910878Sandreas.hansson@arm.com        print "Error: can't find library %s required by python" % lib
69010878Sandreas.hansson@arm.com        Exit(1)
69111811Sbaz21@cam.ac.uk
69211811Sbaz21@cam.ac.uk# On Solaris you need to use libsocket for socket ops
69311811Sbaz21@cam.ac.ukif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
69411982Sgabeblack@google.com   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
69511982Sgabeblack@google.com       print "Can't find library with socket calls (e.g. accept())"
69611982Sgabeblack@google.com       Exit(1)
69711982Sgabeblack@google.com
69811992Sgabeblack@google.com# Check for zlib.  If the check passes, libz will be automatically
69911982Sgabeblack@google.com# added to the LIBS environment variable.
70011982Sgabeblack@google.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
7019556Sandreas.hansson@arm.com    print 'Error: did not find needed zlib compression library '\
7029556Sandreas.hansson@arm.com          'and/or zlib.h header file.'
7039556Sandreas.hansson@arm.com    print '       Please install zlib and try again.'
7049556Sandreas.hansson@arm.com    Exit(1)
7059556Sandreas.hansson@arm.com
7069556Sandreas.hansson@arm.com# Check for librt.
7079556Sandreas.hansson@arm.comhave_posix_clock = conf.CheckLib(None, 'clock_nanosleep', 'time.h') or \
7089556Sandreas.hansson@arm.com    conf.CheckLib('rt', 'clock_nanosleep', 'time.h')
7099556Sandreas.hansson@arm.com
7109556Sandreas.hansson@arm.comif not have_posix_clock:
7119556Sandreas.hansson@arm.com    print "Can't find library for POSIX clocks."
7129556Sandreas.hansson@arm.com
7139556Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control)
7149556Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
7159556Sandreas.hansson@arm.comif not have_fenv:
7169556Sandreas.hansson@arm.com    print "Warning: Header file <fenv.h> not found."
7179556Sandreas.hansson@arm.com    print "         This host has no IEEE FP rounding mode control."
7189556Sandreas.hansson@arm.com
7199556Sandreas.hansson@arm.com######################################################################
7206121Snate@binkert.org#
72111500Sandreas.hansson@arm.com# Check for mysql.
72210238Sandreas.hansson@arm.com#
72310878Sandreas.hansson@arm.commysql_config = WhereIs('mysql_config')
7249420Sandreas.hansson@arm.comhave_mysql = bool(mysql_config)
72511500Sandreas.hansson@arm.com
72611500Sandreas.hansson@arm.com# Check MySQL version.
7279420Sandreas.hansson@arm.comif have_mysql:
7289420Sandreas.hansson@arm.com    mysql_version = readCommand(mysql_config + ' --version')
7299420Sandreas.hansson@arm.com    min_mysql_version = '4.1'
7309420Sandreas.hansson@arm.com    if compareVersions(mysql_version, min_mysql_version) < 0:
7319420Sandreas.hansson@arm.com        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
73212063Sgabeblack@google.com        print '         Version', mysql_version, 'detected.'
73312063Sgabeblack@google.com        have_mysql = False
73412063Sgabeblack@google.com
73512063Sgabeblack@google.com# Set up mysql_config commands.
73612063Sgabeblack@google.comif have_mysql:
73712063Sgabeblack@google.com    mysql_config_include = mysql_config + ' --include'
73812063Sgabeblack@google.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
73912063Sgabeblack@google.com        # older mysql_config versions don't support --include, use
74012063Sgabeblack@google.com        # --cflags instead
74112063Sgabeblack@google.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
74212063Sgabeblack@google.com    # This seems to work in all versions
74312063Sgabeblack@google.com    mysql_config_libs = mysql_config + ' --libs'
74412063Sgabeblack@google.com
74512063Sgabeblack@google.com######################################################################
74612063Sgabeblack@google.com#
74712063Sgabeblack@google.com# Finish the configuration
74812063Sgabeblack@google.com#
74912063Sgabeblack@google.commain = conf.Finish()
75012063Sgabeblack@google.com
75112063Sgabeblack@google.com######################################################################
75212063Sgabeblack@google.com#
75312063Sgabeblack@google.com# Collect all non-global variables
75410264Sandreas.hansson@arm.com#
75510264Sandreas.hansson@arm.com
75610264Sandreas.hansson@arm.com# Define the universe of supported ISAs
75710264Sandreas.hansson@arm.comall_isa_list = [ ]
75811925Sgabeblack@google.comExport('all_isa_list')
75911925Sgabeblack@google.com
76011500Sandreas.hansson@arm.comclass CpuModel(object):
76110264Sandreas.hansson@arm.com    '''The CpuModel class encapsulates everything the ISA parser needs to
76211500Sandreas.hansson@arm.com    know about a particular CPU model.'''
76311500Sandreas.hansson@arm.com
76411500Sandreas.hansson@arm.com    # Dict of available CPU model objects.  Accessible as CpuModel.dict.
76511500Sandreas.hansson@arm.com    dict = {}
76610866Sandreas.hansson@arm.com    list = []
76711500Sandreas.hansson@arm.com    defaults = []
76811500Sandreas.hansson@arm.com
76911500Sandreas.hansson@arm.com    # Constructor.  Automatically adds models to CpuModel.dict.
77011500Sandreas.hansson@arm.com    def __init__(self, name, filename, includes, strings, default=False):
77111500Sandreas.hansson@arm.com        self.name = name           # name of model
77211500Sandreas.hansson@arm.com        self.filename = filename   # filename for output exec code
77311500Sandreas.hansson@arm.com        self.includes = includes   # include files needed in exec file
77410264Sandreas.hansson@arm.com        # The 'strings' dict holds all the per-CPU symbols we can
77510457Sandreas.hansson@arm.com        # substitute into templates etc.
77610457Sandreas.hansson@arm.com        self.strings = strings
77710457Sandreas.hansson@arm.com
77810457Sandreas.hansson@arm.com        # This cpu is enabled by default
77910457Sandreas.hansson@arm.com        self.default = default
78010457Sandreas.hansson@arm.com
78110457Sandreas.hansson@arm.com        # Add self to dict
78210457Sandreas.hansson@arm.com        if name in CpuModel.dict:
78310457Sandreas.hansson@arm.com            raise AttributeError, "CpuModel '%s' already registered" % name
78412063Sgabeblack@google.com        CpuModel.dict[name] = self
78512063Sgabeblack@google.com        CpuModel.list.append(name)
78612063Sgabeblack@google.com
78712063Sgabeblack@google.comExport('CpuModel')
78812063Sgabeblack@google.com
78912063Sgabeblack@google.com# Sticky variables get saved in the variables file so they persist from
79012063Sgabeblack@google.com# one invocation to the next (unless overridden, in which case the new
79112063Sgabeblack@google.com# value becomes sticky).
79212063Sgabeblack@google.comsticky_vars = Variables(args=ARGUMENTS)
79312063Sgabeblack@google.comExport('sticky_vars')
79412063Sgabeblack@google.com
79510238Sandreas.hansson@arm.com# Sticky variables that should be exported
79610238Sandreas.hansson@arm.comexport_vars = []
79710238Sandreas.hansson@arm.comExport('export_vars')
79812063Sgabeblack@google.com
79910238Sandreas.hansson@arm.com# Walk the tree and execute all SConsopts scripts that wil add to the
80010238Sandreas.hansson@arm.com# above variables
80110416Sandreas.hansson@arm.comfor bdir in [ base_dir ] + extras_dir_list:
80210238Sandreas.hansson@arm.com    for root, dirs, files in os.walk(bdir):
8039227Sandreas.hansson@arm.com        if 'SConsopts' in files:
80410238Sandreas.hansson@arm.com            print "Reading", joinpath(root, 'SConsopts')
80510416Sandreas.hansson@arm.com            SConscript(joinpath(root, 'SConsopts'))
80610416Sandreas.hansson@arm.com
8079227Sandreas.hansson@arm.comall_isa_list.sort()
8089590Sandreas@sandberg.pp.se
8099590Sandreas@sandberg.pp.sesticky_vars.AddVariables(
8109590Sandreas@sandberg.pp.se    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
81111497SMatteo.Andreozzi@arm.com    BoolVariable('FULL_SYSTEM', 'Full-system support', False),
81211497SMatteo.Andreozzi@arm.com    ListVariable('CPU_MODELS', 'CPU models',
81311497SMatteo.Andreozzi@arm.com                 sorted(n for n,m in CpuModel.dict.iteritems() if m.default),
81411497SMatteo.Andreozzi@arm.com                 sorted(CpuModel.list)),
8158737Skoansin.tan@gmail.com    BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
81610878Sandreas.hansson@arm.com    BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
81711500Sandreas.hansson@arm.com                 False),
8189420Sandreas.hansson@arm.com    BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
8198737Skoansin.tan@gmail.com                 False),
82010106SMitch.Hayenga@arm.com    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
8218737Skoansin.tan@gmail.com                 False),
8228737Skoansin.tan@gmail.com    BoolVariable('SS_COMPATIBLE_FP',
82310878Sandreas.hansson@arm.com                 'Make floating-point results compatible with SimpleScalar',
82410878Sandreas.hansson@arm.com                 False),
8258737Skoansin.tan@gmail.com    BoolVariable('USE_SSE2',
8268737Skoansin.tan@gmail.com                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
8278737Skoansin.tan@gmail.com                 False),
8288737Skoansin.tan@gmail.com    BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
8298737Skoansin.tan@gmail.com    BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
8308737Skoansin.tan@gmail.com    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
83111294Sandreas.hansson@arm.com    BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
8329556Sandreas.hansson@arm.com    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
8339556Sandreas.hansson@arm.com    BoolVariable('RUBY', 'Build with Ruby', False),
8349556Sandreas.hansson@arm.com    )
83511294Sandreas.hansson@arm.com
83610278SAndreas.Sandberg@ARM.com# These variables get exported to #defines in config/*.hh (see src/SConscript).
83710278SAndreas.Sandberg@ARM.comexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL',
83810278SAndreas.Sandberg@ARM.com                'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS',
83910278SAndreas.Sandberg@ARM.com                'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE',
84010278SAndreas.Sandberg@ARM.com                'USE_POSIX_CLOCK' ]
84110278SAndreas.Sandberg@ARM.com
8429556Sandreas.hansson@arm.com###################################################
8439590Sandreas@sandberg.pp.se#
8449590Sandreas@sandberg.pp.se# Define a SCons builder for configuration flag headers.
8459420Sandreas.hansson@arm.com#
8469846Sandreas.hansson@arm.com###################################################
8479846Sandreas.hansson@arm.com
8489846Sandreas.hansson@arm.com# This function generates a config header file that #defines the
8499846Sandreas.hansson@arm.com# variable symbol to the current variable setting (0 or 1).  The source
8508946Sandreas.hansson@arm.com# operands are the name of the variable and a Value node containing the
85111811Sbaz21@cam.ac.uk# value of the variable.
85211811Sbaz21@cam.ac.ukdef build_config_file(target, source, env):
85311811Sbaz21@cam.ac.uk    (variable, value) = [s.get_contents() for s in source]
85411811Sbaz21@cam.ac.uk    f = file(str(target[0]), 'w')
8553918Ssaidi@eecs.umich.edu    print >> f, '#define', variable, value
8569068SAli.Saidi@ARM.com    f.close()
8579068SAli.Saidi@ARM.com    return None
8589068SAli.Saidi@ARM.com
8599068SAli.Saidi@ARM.com# Generate the message to be printed when building the config file.
8609068SAli.Saidi@ARM.comdef build_config_file_string(target, source, env):
8619068SAli.Saidi@ARM.com    (variable, value) = [s.get_contents() for s in source]
8629068SAli.Saidi@ARM.com    return "Defining %s as %s in %s." % (variable, value, target[0])
8639068SAli.Saidi@ARM.com
8649068SAli.Saidi@ARM.com# Combine the two functions into a scons Action object.
8659419Sandreas.hansson@arm.comconfig_action = Action(build_config_file, build_config_file_string)
8669068SAli.Saidi@ARM.com
8679068SAli.Saidi@ARM.com# The emitter munges the source & target node lists to reflect what
8689068SAli.Saidi@ARM.com# we're really doing.
8699068SAli.Saidi@ARM.comdef config_emitter(target, source, env):
8709068SAli.Saidi@ARM.com    # extract variable name from Builder arg
8719068SAli.Saidi@ARM.com    variable = str(target[0])
8723918Ssaidi@eecs.umich.edu    # True target is config header file
8733918Ssaidi@eecs.umich.edu    target = joinpath('config', variable.lower() + '.hh')
8746157Snate@binkert.org    val = env[variable]
8756157Snate@binkert.org    if isinstance(val, bool):
8766157Snate@binkert.org        # Force value to 0/1
8776157Snate@binkert.org        val = int(val)
8785397Ssaidi@eecs.umich.edu    elif isinstance(val, str):
8795397Ssaidi@eecs.umich.edu        val = '"' + val + '"'
8806121Snate@binkert.org
8816121Snate@binkert.org    # Sources are variable name & value (packaged in SCons Value nodes)
8826121Snate@binkert.org    return ([target], [Value(variable), Value(val)])
8836121Snate@binkert.org
8846121Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action)
8856121Snate@binkert.org
8865397Ssaidi@eecs.umich.edumain.Append(BUILDERS = { 'ConfigFile' : config_builder })
8871851SN/A
8881851SN/A# libelf build is shared across all configs in the build root.
8897739Sgblack@eecs.umich.edumain.SConscript('ext/libelf/SConscript',
890955SN/A                variant_dir = joinpath(build_root, 'libelf'))
8919396Sandreas.hansson@arm.com
8929396Sandreas.hansson@arm.com# gzstream build is shared across all configs in the build root.
8939396Sandreas.hansson@arm.commain.SConscript('ext/gzstream/SConscript',
8949396Sandreas.hansson@arm.com                variant_dir = joinpath(build_root, 'gzstream'))
8959396Sandreas.hansson@arm.com
8969396Sandreas.hansson@arm.com###################################################
8979396Sandreas.hansson@arm.com#
8989396Sandreas.hansson@arm.com# This function is used to set up a directory with switching headers
8999396Sandreas.hansson@arm.com#
9009396Sandreas.hansson@arm.com###################################################
9019396Sandreas.hansson@arm.com
9029396Sandreas.hansson@arm.commain['ALL_ISA_LIST'] = all_isa_list
9039396Sandreas.hansson@arm.comdef make_switching_dir(dname, switch_headers, env):
9049396Sandreas.hansson@arm.com    # Generate the header.  target[0] is the full path of the output
9059396Sandreas.hansson@arm.com    # header to generate.  'source' is a dummy variable, since we get the
9069396Sandreas.hansson@arm.com    # list of ISAs from env['ALL_ISA_LIST'].
9079477Sandreas.hansson@arm.com    def gen_switch_hdr(target, source, env):
9089477Sandreas.hansson@arm.com        fname = str(target[0])
9099477Sandreas.hansson@arm.com        f = open(fname, 'w')
9109477Sandreas.hansson@arm.com        isa = env['TARGET_ISA'].lower()
9119477Sandreas.hansson@arm.com        print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
9129477Sandreas.hansson@arm.com        f.close()
9139477Sandreas.hansson@arm.com
9149477Sandreas.hansson@arm.com    # Build SCons Action object. 'varlist' specifies env vars that this
9159477Sandreas.hansson@arm.com    # action depends on; when env['ALL_ISA_LIST'] changes these actions
9169477Sandreas.hansson@arm.com    # should get re-executed.
9179477Sandreas.hansson@arm.com    switch_hdr_action = MakeAction(gen_switch_hdr,
9189477Sandreas.hansson@arm.com                          Transform("GENERATE"), varlist=['ALL_ISA_LIST'])
9199477Sandreas.hansson@arm.com
9209477Sandreas.hansson@arm.com    # Instantiate actions for each header
9219477Sandreas.hansson@arm.com    for hdr in switch_headers:
9229477Sandreas.hansson@arm.com        env.Command(hdr, [], switch_hdr_action)
9239477Sandreas.hansson@arm.comExport('make_switching_dir')
9249477Sandreas.hansson@arm.com
9259477Sandreas.hansson@arm.com###################################################
9269477Sandreas.hansson@arm.com#
9279477Sandreas.hansson@arm.com# Define build environments for selected configurations.
9289477Sandreas.hansson@arm.com#
9299396Sandreas.hansson@arm.com###################################################
9302667Sstever@eecs.umich.edu
93110710Sandreas.hansson@arm.comfor variant_path in variant_paths:
93210710Sandreas.hansson@arm.com    print "Building in", variant_path
93310710Sandreas.hansson@arm.com
93411811Sbaz21@cam.ac.uk    # Make a copy of the build-root environment to use for this config.
93511811Sbaz21@cam.ac.uk    env = main.Clone()
93611811Sbaz21@cam.ac.uk    env['BUILDDIR'] = variant_path
93711811Sbaz21@cam.ac.uk
93811811Sbaz21@cam.ac.uk    # variant_dir is the tail component of build path, and is used to
93911811Sbaz21@cam.ac.uk    # determine the build parameters (e.g., 'ALPHA_SE')
94010710Sandreas.hansson@arm.com    (build_root, variant_dir) = splitpath(variant_path)
94110710Sandreas.hansson@arm.com
94210710Sandreas.hansson@arm.com    # Set env variables according to the build directory config.
94310710Sandreas.hansson@arm.com    sticky_vars.files = []
94410384SCurtis.Dunham@arm.com    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
9459986Sandreas@sandberg.pp.se    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
9469986Sandreas@sandberg.pp.se    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
9479986Sandreas@sandberg.pp.se    current_vars_file = joinpath(build_root, 'variables', variant_dir)
9489986Sandreas@sandberg.pp.se    if isfile(current_vars_file):
9499986Sandreas@sandberg.pp.se        sticky_vars.files.append(current_vars_file)
9509986Sandreas@sandberg.pp.se        print "Using saved variables file %s" % current_vars_file
9519986Sandreas@sandberg.pp.se    else:
9529986Sandreas@sandberg.pp.se        # Build dir-specific variables file doesn't exist.
9539986Sandreas@sandberg.pp.se
9549986Sandreas@sandberg.pp.se        # Make sure the directory is there so we can create it later
9559986Sandreas@sandberg.pp.se        opt_dir = dirname(current_vars_file)
9569986Sandreas@sandberg.pp.se        if not isdir(opt_dir):
9579986Sandreas@sandberg.pp.se            mkdir(opt_dir)
9589986Sandreas@sandberg.pp.se
9599986Sandreas@sandberg.pp.se        # Get default build variables from source tree.  Variables are
9609986Sandreas@sandberg.pp.se        # normally determined by name of $VARIANT_DIR, but can be
9619986Sandreas@sandberg.pp.se        # overriden by 'default=' arg on command line.
9629986Sandreas@sandberg.pp.se        default_vars_file = joinpath('build_opts',
9639986Sandreas@sandberg.pp.se                                     ARGUMENTS.get('default', variant_dir))
9649986Sandreas@sandberg.pp.se        if isfile(default_vars_file):
9652638Sstever@eecs.umich.edu            sticky_vars.files.append(default_vars_file)
9662638Sstever@eecs.umich.edu            print "Variables file %s not found,\n  using defaults in %s" \
9676121Snate@binkert.org                  % (current_vars_file, default_vars_file)
9683716Sstever@eecs.umich.edu        else:
9695522Snate@binkert.org            print "Error: cannot find variables file %s or %s" \
9709986Sandreas@sandberg.pp.se                  % (current_vars_file, default_vars_file)
9719986Sandreas@sandberg.pp.se            Exit(1)
9729986Sandreas@sandberg.pp.se
9735522Snate@binkert.org    # Apply current variable settings to env
9745227Ssaidi@eecs.umich.edu    sticky_vars.Update(env)
9755227Ssaidi@eecs.umich.edu
9765227Ssaidi@eecs.umich.edu    help_text += "\nSticky variables for %s:\n" % variant_dir \
9775227Ssaidi@eecs.umich.edu                 + sticky_vars.GenerateHelpText(env)
9786654Snate@binkert.org
9796654Snate@binkert.org    # Process variable settings.
9807769SAli.Saidi@ARM.com
9817769SAli.Saidi@ARM.com    if not have_fenv and env['USE_FENV']:
9827769SAli.Saidi@ARM.com        print "Warning: <fenv.h> not available; " \
9837769SAli.Saidi@ARM.com              "forcing USE_FENV to False in", variant_dir + "."
9845227Ssaidi@eecs.umich.edu        env['USE_FENV'] = False
9855227Ssaidi@eecs.umich.edu
9865227Ssaidi@eecs.umich.edu    if not env['USE_FENV']:
9875204Sstever@gmail.com        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
9885204Sstever@gmail.com        print "         FP results may deviate slightly from other platforms."
9895204Sstever@gmail.com
9905204Sstever@gmail.com    if env['EFENCE']:
9915204Sstever@gmail.com        env.Append(LIBS=['efence'])
9925204Sstever@gmail.com
9935204Sstever@gmail.com    if env['USE_MYSQL']:
9945204Sstever@gmail.com        if not have_mysql:
9955204Sstever@gmail.com            print "Warning: MySQL not available; " \
9965204Sstever@gmail.com                  "forcing USE_MYSQL to False in", variant_dir + "."
9975204Sstever@gmail.com            env['USE_MYSQL'] = False
9985204Sstever@gmail.com        else:
9995204Sstever@gmail.com            print "Compiling in", variant_dir, "with MySQL support."
10005204Sstever@gmail.com            env.ParseConfig(mysql_config_libs)
10015204Sstever@gmail.com            env.ParseConfig(mysql_config_include)
10025204Sstever@gmail.com
10035204Sstever@gmail.com    # Save sticky variable settings back to current variables file
10046121Snate@binkert.org    sticky_vars.Save(current_vars_file, env)
10055204Sstever@gmail.com
10067727SAli.Saidi@ARM.com    if env['USE_SSE2']:
10077727SAli.Saidi@ARM.com        env.Append(CCFLAGS=['-msse2'])
10087727SAli.Saidi@ARM.com
10097727SAli.Saidi@ARM.com    # The src/SConscript file sets up the build rules in 'env' according
10107727SAli.Saidi@ARM.com    # to the configured variables.  It returns a list of environments,
101111988Sandreas.sandberg@arm.com    # one for each variant build (debug, opt, etc.)
101211988Sandreas.sandberg@arm.com    envList = SConscript('src/SConscript', variant_dir = variant_path,
101310453SAndrew.Bardsley@arm.com                         exports = 'env')
101410453SAndrew.Bardsley@arm.com
101510453SAndrew.Bardsley@arm.com    # Set up the regression tests for each build.
101610453SAndrew.Bardsley@arm.com    for e in envList:
101710453SAndrew.Bardsley@arm.com        SConscript('tests/SConscript',
101810453SAndrew.Bardsley@arm.com                   variant_dir = joinpath(variant_path, 'tests', e.Label),
101910453SAndrew.Bardsley@arm.com                   exports = { 'env' : e }, duplicate = False)
102010453SAndrew.Bardsley@arm.com
102110453SAndrew.Bardsley@arm.comHelp(help_text)
102210453SAndrew.Bardsley@arm.com