SConstruct revision 7807
1955SN/A# -*- mode:python -*-
2955SN/A
35871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company
41762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
5955SN/A# All rights reserved.
6955SN/A#
7955SN/A# Redistribution and use in source and binary forms, with or without
8955SN/A# modification, are permitted provided that the following conditions are
9955SN/A# met: redistributions of source code must retain the above copyright
10955SN/A# notice, this list of conditions and the following disclaimer;
11955SN/A# redistributions in binary form must reproduce the above copyright
12955SN/A# notice, this list of conditions and the following disclaimer in the
13955SN/A# documentation and/or other materials provided with the distribution;
14955SN/A# neither the name of the copyright holders nor the names of its
15955SN/A# contributors may be used to endorse or promote products derived from
16955SN/A# this software without specific prior written permission.
17955SN/A#
18955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
292665Ssaidi@eecs.umich.edu#
302665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
315863Snate@binkert.org#          Nathan Binkert
32955SN/A
33955SN/A###################################################
34955SN/A#
35955SN/A# SCons top-level build description (SConstruct) file.
36955SN/A#
372632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default
382632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
392632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
402632Sstever@eecs.umich.edu# the optimized full-system version).
41955SN/A#
422632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a
432632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
442761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
452632Sstever@eecs.umich.edu# built for the same host system.
462632Sstever@eecs.umich.edu#
472632Sstever@eecs.umich.edu# Examples:
482761Sstever@eecs.umich.edu#
492761Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
502761Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
512632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
522632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
532761Sstever@eecs.umich.edu#
542761Sstever@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
552761Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
562761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
572761Sstever@eecs.umich.edu#   file.
582632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
592632Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
602632Sstever@eecs.umich.edu#
612632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
622632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
632632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
642632Sstever@eecs.umich.edu# options as well.
65955SN/A#
66955SN/A###################################################
67955SN/A
685863Snate@binkert.org# Check for recent-enough Python and SCons versions.
695863Snate@binkert.orgtry:
705863Snate@binkert.org    # Really old versions of scons only take two options for the
715863Snate@binkert.org    # function, so check once without the revision and once with the
725863Snate@binkert.org    # revision, the first instance will fail for stuff other than
735863Snate@binkert.org    # 0.98, and the second will fail for 0.98.0
745863Snate@binkert.org    EnsureSConsVersion(0, 98)
755863Snate@binkert.org    EnsureSConsVersion(0, 98, 1)
765863Snate@binkert.orgexcept SystemExit, e:
775863Snate@binkert.org    print """
785863Snate@binkert.orgFor more details, see:
795863Snate@binkert.org    http://m5sim.org/wiki/index.php/Compiling_M5
805863Snate@binkert.org"""
815863Snate@binkert.org    raise
825863Snate@binkert.org
835863Snate@binkert.org# We ensure the python version early because we have stuff that
845863Snate@binkert.org# requires python 2.4
855863Snate@binkert.orgtry:
865863Snate@binkert.org    EnsurePythonVersion(2, 4)
875863Snate@binkert.orgexcept SystemExit, e:
885863Snate@binkert.org    print """
895863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by
905863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default
915863Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter
925863Snate@binkert.orgon the scons script.
935863Snate@binkert.org
945863Snate@binkert.orgFor more details, see:
955863Snate@binkert.org    http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation
965863Snate@binkert.org"""
975863Snate@binkert.org    raise
985863Snate@binkert.org
996654Snate@binkert.org# Global Python includes
100955SN/Aimport os
1015396Ssaidi@eecs.umich.eduimport re
1025863Snate@binkert.orgimport subprocess
1035863Snate@binkert.orgimport sys
1044202Sbinkertn@umich.edu
1055863Snate@binkert.orgfrom os import mkdir, environ
1065863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath
1075863Snate@binkert.orgfrom os.path import exists,  isdir, isfile
1085863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath
109955SN/A
1106654Snate@binkert.org# SCons includes
1115273Sstever@gmail.comimport SCons
1125871Snate@binkert.orgimport SCons.Node
1135273Sstever@gmail.com
1146655Snate@binkert.orgextra_python_paths = [
1156655Snate@binkert.org    Dir('src/python').srcnode().abspath, # M5 includes
1166655Snate@binkert.org    Dir('ext/ply').srcnode().abspath, # ply is used by several files
1176655Snate@binkert.org    ]
1186655Snate@binkert.org    
1196655Snate@binkert.orgsys.path[1:1] = extra_python_paths
1205871Snate@binkert.org
1216654Snate@binkert.orgfrom m5.util import compareVersions, readCommand
1225396Ssaidi@eecs.umich.edu
1235871Snate@binkert.org########################################################################
1245871Snate@binkert.org#
1256121Snate@binkert.org# Set up the main build environment.
1265871Snate@binkert.org#
1275871Snate@binkert.org########################################################################
1286003Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
1296655Snate@binkert.org                 'PYTHONPATH', 'RANLIB' ])
130955SN/A
1315871Snate@binkert.orguse_env = {}
1325871Snate@binkert.orgfor key,val in os.environ.iteritems():
1335871Snate@binkert.org    if key in use_vars or key.startswith("M5"):
1345871Snate@binkert.org        use_env[key] = val
135955SN/A
1366121Snate@binkert.orgmain = Environment(ENV=use_env)
1376121Snate@binkert.orgmain.root = Dir(".")         # The current directory (where this file lives).
1386121Snate@binkert.orgmain.srcdir = Dir("src")     # The source directory
1391533SN/A
1406655Snate@binkert.org# add useful python code PYTHONPATH so it can be used by subprocesses
1416655Snate@binkert.org# as well
1426655Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths)
1436655Snate@binkert.org
1445871Snate@binkert.org########################################################################
1455871Snate@binkert.org#
1465863Snate@binkert.org# Mercurial Stuff.
1475871Snate@binkert.org#
1485871Snate@binkert.org# If the M5 directory is a mercurial repository, we should do some
1495871Snate@binkert.org# extra things.
1505871Snate@binkert.org#
1515871Snate@binkert.org########################################################################
1525863Snate@binkert.org
1536121Snate@binkert.orghgdir = main.root.Dir(".hg")
1545863Snate@binkert.org
1555871Snate@binkert.orgmercurial_style_message = """
1564678Snate@binkert.orgYou're missing the M5 style hook.
1574678Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style.
1584678Snate@binkert.org
1594678Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc
1604678Snate@binkert.orgor your personal .hgrc
1614678Snate@binkert.org----------------
1624678Snate@binkert.org
1634678Snate@binkert.org[extensions]
1644678Snate@binkert.orgstyle = %s/util/style.py
1654678Snate@binkert.org
1664678Snate@binkert.org[hooks]
1674678Snate@binkert.orgpretxncommit.style = python:style.check_whitespace
1687807Snate@binkert.orgpre-qrefresh.style = python:style.check_whitespace
1696121Snate@binkert.org""" % (main.root)
1704678Snate@binkert.org
1715871Snate@binkert.orgmercurial_bin_not_found = """
1725871Snate@binkert.orgMercurial binary cannot be found, unfortunately this means that we
1735871Snate@binkert.orgcannot easily determine the version of M5 that you are running and
1745871Snate@binkert.orgthis makes error messages more difficult to collect.  Please consider
1755871Snate@binkert.orginstalling mercurial if you choose to post an error message
1765871Snate@binkert.org"""
1775871Snate@binkert.org
1785871Snate@binkert.orgmercurial_lib_not_found = """
1795871Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook
1805871Snate@binkert.orgIf you are actually a M5 developer, please fix this and
1815871Snate@binkert.orgrun the style hook. It is important.
1825871Snate@binkert.org"""
1835871Snate@binkert.org
1845990Ssaidi@eecs.umich.eduhg_info = "Unknown"
1855871Snate@binkert.orgif hgdir.exists():
1865871Snate@binkert.org    # 1) Grab repository revision if we know it.
1875871Snate@binkert.org    cmd = "hg id -n -i -t -b"
1884678Snate@binkert.org    try:
1896654Snate@binkert.org        hg_info = readCommand(cmd, cwd=main.root.abspath).strip()
1905871Snate@binkert.org    except OSError:
1915871Snate@binkert.org        print mercurial_bin_not_found
1925871Snate@binkert.org
1935871Snate@binkert.org    # 2) Ensure that the style hook is in place.
1945871Snate@binkert.org    try:
1955871Snate@binkert.org        ui = None
1965871Snate@binkert.org        if ARGUMENTS.get('IGNORE_STYLE') != 'True':
1975871Snate@binkert.org            from mercurial import ui
1985871Snate@binkert.org            ui = ui.ui()
1994678Snate@binkert.org    except ImportError:
2005871Snate@binkert.org        print mercurial_lib_not_found
2014678Snate@binkert.org
2025871Snate@binkert.org    if ui is not None:
2035871Snate@binkert.org        ui.readconfig(hgdir.File('hgrc').abspath)
2045871Snate@binkert.org        style_hook = ui.config('hooks', 'pretxncommit.style', None)
2055871Snate@binkert.org
2065871Snate@binkert.org        if not style_hook:
2075871Snate@binkert.org            print mercurial_style_message
2085871Snate@binkert.org            sys.exit(1)
2095871Snate@binkert.orgelse:
2105871Snate@binkert.org    print ".hg directory not found"
2116121Snate@binkert.org
2126121Snate@binkert.orgmain['HG_INFO'] = hg_info
2135863Snate@binkert.org
214955SN/A###################################################
215955SN/A#
2162632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
2172632Sstever@eecs.umich.edu# the target(s).
218955SN/A#
219955SN/A###################################################
220955SN/A
221955SN/A# Find default configuration & binary.
2225863Snate@binkert.orgDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
223955SN/A
2242632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
2252632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
2262632Sstever@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
2272632Sstever@eecs.umich.edu        if l[i] == elt:
2282632Sstever@eecs.umich.edu            return i
2292632Sstever@eecs.umich.edu    raise ValueError, "element not found"
2302632Sstever@eecs.umich.edu
2312632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
2322632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
2332632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
2342632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
2352632Sstever@eecs.umich.edu# follow 'build' in the bulid path.
2362632Sstever@eecs.umich.edu
2373718Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is
2383718Sstever@eecs.umich.eduif COMMAND_LINE_TARGETS:
2393718Sstever@eecs.umich.edu    # Ask SCons which directory it was invoked from
2403718Sstever@eecs.umich.edu    launch_dir = GetLaunchDir()
2413718Sstever@eecs.umich.edu    # Make targets relative to invocation directory
2425863Snate@binkert.org    abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \
2435863Snate@binkert.org                    COMMAND_LINE_TARGETS]
2443718Sstever@eecs.umich.eduelse:
2453718Sstever@eecs.umich.edu    # Default targets are relative to root of tree
2466121Snate@binkert.org    abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \
2475863Snate@binkert.org                    DEFAULT_TARGETS]
2483718Sstever@eecs.umich.edu
2493718Sstever@eecs.umich.edu
2502634Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the
2512634Sstever@eecs.umich.edu# collected targets reference.
2525863Snate@binkert.orgvariant_paths = []
2532638Sstever@eecs.umich.edubuild_root = None
2542632Sstever@eecs.umich.edufor t in abs_targets:
2552632Sstever@eecs.umich.edu    path_dirs = t.split('/')
2562632Sstever@eecs.umich.edu    try:
2572632Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
2582632Sstever@eecs.umich.edu    except:
2592632Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
2601858SN/A        Exit(1)
2613716Sstever@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
2622638Sstever@eecs.umich.edu    if not build_root:
2632638Sstever@eecs.umich.edu        build_root = this_build_root
2642638Sstever@eecs.umich.edu    else:
2652638Sstever@eecs.umich.edu        if this_build_root != build_root:
2662638Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
2672638Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
2682638Sstever@eecs.umich.edu            Exit(1)
2695863Snate@binkert.org    variant_path = joinpath('/',*path_dirs[:build_top+2])
2705863Snate@binkert.org    if variant_path not in variant_paths:
2715863Snate@binkert.org        variant_paths.append(variant_path)
272955SN/A
2735341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there)
2745341Sstever@gmail.comif not isdir(build_root):
2755863Snate@binkert.org    mkdir(build_root)
2767756SAli.Saidi@ARM.commain['BUILDROOT'] = build_root
2775341Sstever@gmail.com
2786121Snate@binkert.orgExport('main')
2794494Ssaidi@eecs.umich.edu
2806121Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign"))
2811105SN/A
2822667Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up
2832667Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
2842667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
2852667Sstever@eecs.umich.edu# (soft) links work better.
2866121Snate@binkert.orgmain.SetOption('duplicate', 'soft-copy')
2872667Sstever@eecs.umich.edu
2885341Sstever@gmail.com#
2895863Snate@binkert.org# Set up global sticky variables... these are common to an entire build
2905341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE)
2915341Sstever@gmail.com#
2925341Sstever@gmail.com
2935863Snate@binkert.org# Variable validators & converters for global sticky variables
2945341Sstever@gmail.comdef PathListMakeAbsolute(val):
2955341Sstever@gmail.com    if not val:
2965341Sstever@gmail.com        return val
2975863Snate@binkert.org    f = lambda p: abspath(expanduser(p))
2985341Sstever@gmail.com    return ':'.join(map(f, val.split(':')))
2995341Sstever@gmail.com
3005341Sstever@gmail.comdef PathListAllExist(key, val, env):
3015341Sstever@gmail.com    if not val:
3025341Sstever@gmail.com        return
3035341Sstever@gmail.com    paths = val.split(':')
3045341Sstever@gmail.com    for path in paths:
3055341Sstever@gmail.com        if not isdir(path):
3065341Sstever@gmail.com            raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
3075341Sstever@gmail.com
3085863Snate@binkert.orgglobal_sticky_vars_file = joinpath(build_root, 'variables.global')
3095341Sstever@gmail.com
3105863Snate@binkert.orgglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS)
3117756SAli.Saidi@ARM.comglobal_nonsticky_vars = Variables(args=ARGUMENTS)
3125341Sstever@gmail.com
3135863Snate@binkert.orgglobal_sticky_vars.AddVariables(
3146121Snate@binkert.org    ('CC', 'C compiler', environ.get('CC', main['CC'])),
3156121Snate@binkert.org    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
3165397Ssaidi@eecs.umich.edu    ('BATCH', 'Use batch pool for build and tests', False),
3175397Ssaidi@eecs.umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3187727SAli.Saidi@ARM.com    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
3195341Sstever@gmail.com    ('EXTRAS', 'Add Extra directories to the compilation', '',
3206168Snate@binkert.org     PathListAllExist, PathListMakeAbsolute),
3216168Snate@binkert.org    )
3225341Sstever@gmail.com
3237756SAli.Saidi@ARM.comglobal_nonsticky_vars.AddVariables(
3247756SAli.Saidi@ARM.com    ('VERBOSE', 'Print full tool command lines', False),
3257756SAli.Saidi@ARM.com    ('update_ref', 'Update test reference outputs', False)
3267756SAli.Saidi@ARM.com    )
3277756SAli.Saidi@ARM.com
3287756SAli.Saidi@ARM.com
3295341Sstever@gmail.com# base help text
3305341Sstever@gmail.comhelp_text = '''
3315341Sstever@gmail.comUsage: scons [scons options] [build options] [target(s)]
3325341Sstever@gmail.com
3335863Snate@binkert.orgGlobal sticky options:
3345341Sstever@gmail.com'''
3355341Sstever@gmail.com
3366121Snate@binkert.org# Update main environment with values from ARGUMENTS & global_sticky_vars_file
3376121Snate@binkert.orgglobal_sticky_vars.Update(main)
3387756SAli.Saidi@ARM.comglobal_nonsticky_vars.Update(main)
3395341Sstever@gmail.com
3406814Sgblack@eecs.umich.eduhelp_text += global_sticky_vars.GenerateHelpText(main)
3417756SAli.Saidi@ARM.comhelp_text += global_nonsticky_vars.GenerateHelpText(main)
3426814Sgblack@eecs.umich.edu
3435863Snate@binkert.org# Save sticky variable settings back to current variables file
3446121Snate@binkert.orgglobal_sticky_vars.Save(global_sticky_vars_file, main)
3455341Sstever@gmail.com
3465863Snate@binkert.org# Parse EXTRAS variable to build list of all directories where we're
3475341Sstever@gmail.com# look for sources etc.  This list is exported as base_dir_list.
3486121Snate@binkert.orgbase_dir = main.srcdir.abspath
3496121Snate@binkert.orgif main['EXTRAS']:
3506121Snate@binkert.org    extras_dir_list = main['EXTRAS'].split(':')
3515742Snate@binkert.orgelse:
3525742Snate@binkert.org    extras_dir_list = []
3535341Sstever@gmail.com
3545742Snate@binkert.orgExport('base_dir')
3555742Snate@binkert.orgExport('extras_dir_list')
3565341Sstever@gmail.com
3576017Snate@binkert.org# the ext directory should be on the #includes path
3586121Snate@binkert.orgmain.Append(CPPPATH=[Dir('ext')])
3596017Snate@binkert.org
3607756SAli.Saidi@ARM.comdef _STRIP(path, env):
3617756SAli.Saidi@ARM.com    path = str(path)
3627756SAli.Saidi@ARM.com    variant_base = env['BUILDROOT'] + os.path.sep
3637756SAli.Saidi@ARM.com    if path.startswith(variant_base):
3647756SAli.Saidi@ARM.com        path = path[len(variant_base):]
3657756SAli.Saidi@ARM.com    elif path.startswith('build/'):
3667756SAli.Saidi@ARM.com        path = path[6:]
3677756SAli.Saidi@ARM.com    return path
3687756SAli.Saidi@ARM.com
3697756SAli.Saidi@ARM.comdef _STRIP_SOURCE(target, source, env, for_signature):
3707756SAli.Saidi@ARM.com    return _STRIP(source[0], env)
3717756SAli.Saidi@ARM.commain['STRIP_SOURCE'] = _STRIP_SOURCE
3727756SAli.Saidi@ARM.com
3737756SAli.Saidi@ARM.comdef _STRIP_TARGET(target, source, env, for_signature):
3747756SAli.Saidi@ARM.com    return _STRIP(target[0], env)
3757756SAli.Saidi@ARM.commain['STRIP_TARGET'] = _STRIP_TARGET
3767756SAli.Saidi@ARM.com
3777756SAli.Saidi@ARM.comif main['VERBOSE']:
3787756SAli.Saidi@ARM.com    def MakeAction(action, string, *args, **kwargs):
3797756SAli.Saidi@ARM.com        return Action(action, *args, **kwargs)
3807756SAli.Saidi@ARM.comelse:
3817756SAli.Saidi@ARM.com    MakeAction = Action
3827756SAli.Saidi@ARM.com    main['CCCOMSTR']        = ' [      CC] $STRIP_SOURCE'
3837756SAli.Saidi@ARM.com    main['CXXCOMSTR']       = ' [     CXX] $STRIP_SOURCE'
3847756SAli.Saidi@ARM.com    main['ASCOMSTR']        = ' [      AS] $STRIP_SOURCE'
3857756SAli.Saidi@ARM.com    main['SWIGCOMSTR']      = ' [    SWIG] $STRIP_SOURCE'
3867756SAli.Saidi@ARM.com    main['ARCOMSTR']        = ' [      AR] $STRIP_TARGET'
3877756SAli.Saidi@ARM.com    main['LINKCOMSTR']      = ' [    LINK] $STRIP_TARGET'
3887756SAli.Saidi@ARM.com    main['RANLIBCOMSTR']    = ' [  RANLIB] $STRIP_TARGET'
3897756SAli.Saidi@ARM.com    main['M4COMSTR']        = ' [      M4] $STRIP_TARGET'
3907756SAli.Saidi@ARM.com    main['SHCCCOMSTR']      = ' [    SHCC] $STRIP_TARGET'
3917756SAli.Saidi@ARM.com    main['SHCXXCOMSTR']     = ' [   SHCXX] $STRIP_TARGET'
3927756SAli.Saidi@ARM.comExport('MakeAction')
3937756SAli.Saidi@ARM.com
3946654Snate@binkert.orgCXX_version = readCommand([main['CXX'],'--version'], exception=False)
3956654Snate@binkert.orgCXX_V = readCommand([main['CXX'],'-V'], exception=False)
3965871Snate@binkert.org
3976121Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
3986121Snate@binkert.orgmain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
3996121Snate@binkert.orgmain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
4006121Snate@binkert.orgif main['GCC'] + main['SUNCC'] + main['ICC'] > 1:
4013940Ssaidi@eecs.umich.edu    print 'Error: How can we have two at the same time?'
4023918Ssaidi@eecs.umich.edu    Exit(1)
4033918Ssaidi@eecs.umich.edu
4041858SN/A# Set up default C++ compiler flags
4056121Snate@binkert.orgif main['GCC']:
4067739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-pipe'])
4077739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-fno-strict-aliasing'])
4086143Snate@binkert.org    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
4097739Sgblack@eecs.umich.edu    main.Append(CXXFLAGS=['-Wno-deprecated'])
4107618SAli.Saidi@arm.com    # Read the GCC version to check for versions with bugs
4117618SAli.Saidi@arm.com    # Note CCVERSION doesn't work here because it is run with the CC
4127618SAli.Saidi@arm.com    # before we override it from the command line
4137618SAli.Saidi@arm.com    gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False)
4147618SAli.Saidi@arm.com    if not compareVersions(gcc_version, '4.4.1') or \
4157618SAli.Saidi@arm.com       not compareVersions(gcc_version, '4.4.2'):
4167618SAli.Saidi@arm.com        print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.'
4177739Sgblack@eecs.umich.edu        main.Append(CCFLAGS=['-fno-tree-vectorize'])
4186121Snate@binkert.orgelif main['ICC']:
4193940Ssaidi@eecs.umich.edu    pass #Fix me... add warning flags once we clean up icc warnings
4206121Snate@binkert.orgelif main['SUNCC']:
4217739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-Qoption ccfe'])
4227739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-features=gcc'])
4237739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-features=extensions'])
4247739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-library=stlport4'])
4257739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=['-xar'])
4267739Sgblack@eecs.umich.edu    #main.Append(CCFLAGS=['-instances=semiexplicit'])
4273918Ssaidi@eecs.umich.eduelse:
4283918Ssaidi@eecs.umich.edu    print 'Error: Don\'t know what compiler options to use for your compiler.'
4293940Ssaidi@eecs.umich.edu    print '       Please fix SConstruct and src/SConscript and try again.'
4303918Ssaidi@eecs.umich.edu    Exit(1)
4313918Ssaidi@eecs.umich.edu
4326157Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby)
4336157Snate@binkert.orgmain['YACCFLAGS'] = '-d'
4346157Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh'
4356157Snate@binkert.org
4365397Ssaidi@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an
4375397Ssaidi@eecs.umich.edu# extra 'qdo' every time we run scons.
4386121Snate@binkert.orgif main['BATCH']:
4396121Snate@binkert.org    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
4406121Snate@binkert.org    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
4416121Snate@binkert.org    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
4426121Snate@binkert.org    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
4436121Snate@binkert.org    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
4445397Ssaidi@eecs.umich.edu
4451851SN/Aif sys.platform == 'cygwin':
4461851SN/A    # cygwin has some header file issues...
4477739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=["-Wno-uninitialized"])
448955SN/A
4493053Sstever@eecs.umich.edu# Check for SWIG
4506121Snate@binkert.orgif not main.has_key('SWIG'):
4513053Sstever@eecs.umich.edu    print 'Error: SWIG utility not found.'
4523053Sstever@eecs.umich.edu    print '       Please install (see http://www.swig.org) and retry.'
4533053Sstever@eecs.umich.edu    Exit(1)
4543053Sstever@eecs.umich.edu
4553053Sstever@eecs.umich.edu# Check for appropriate SWIG version
4566654Snate@binkert.orgswig_version = readCommand(('swig', '-version'), exception='').split()
4573053Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z"
4584742Sstever@eecs.umich.eduif len(swig_version) < 3 or \
4594742Sstever@eecs.umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
4603053Sstever@eecs.umich.edu    print 'Error determining SWIG version.'
4613053Sstever@eecs.umich.edu    Exit(1)
4623053Sstever@eecs.umich.edu
4633053Sstever@eecs.umich.edumin_swig_version = '1.3.28'
4646654Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0:
4653053Sstever@eecs.umich.edu    print 'Error: SWIG version', min_swig_version, 'or newer required.'
4663053Sstever@eecs.umich.edu    print '       Installed version:', swig_version[2]
4673053Sstever@eecs.umich.edu    Exit(1)
4683053Sstever@eecs.umich.edu
4692667Sstever@eecs.umich.edu# Set up SWIG flags & scanner
4704554Sbinkertn@umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
4716121Snate@binkert.orgmain.Append(SWIGFLAGS=swig_flags)
4722667Sstever@eecs.umich.edu
4734554Sbinkertn@umich.edu# filter out all existing swig scanners, they mess up the dependency
4744554Sbinkertn@umich.edu# stuff for some reason
4754554Sbinkertn@umich.eduscanners = []
4766121Snate@binkert.orgfor scanner in main['SCANNERS']:
4774554Sbinkertn@umich.edu    skeys = scanner.skeys
4784554Sbinkertn@umich.edu    if skeys == '.i':
4794554Sbinkertn@umich.edu        continue
4804781Snate@binkert.org
4814554Sbinkertn@umich.edu    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
4824554Sbinkertn@umich.edu        continue
4832667Sstever@eecs.umich.edu
4844554Sbinkertn@umich.edu    scanners.append(scanner)
4854554Sbinkertn@umich.edu
4864554Sbinkertn@umich.edu# add the new swig scanner that we like better
4874554Sbinkertn@umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner
4882667Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
4894554Sbinkertn@umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
4902667Sstever@eecs.umich.edu
4914554Sbinkertn@umich.edu# replace the scanners list that has what we want
4926121Snate@binkert.orgmain['SCANNERS'] = scanners
4932667Sstever@eecs.umich.edu
4945522Snate@binkert.org# Add a custom Check function to the Configure context so that we can
4955522Snate@binkert.org# figure out if the compiler adds leading underscores to global
4965522Snate@binkert.org# variables.  This is needed for the autogenerated asm files that we
4975522Snate@binkert.org# use for embedding the python code.
4985522Snate@binkert.orgdef CheckLeading(context):
4995522Snate@binkert.org    context.Message("Checking for leading underscore in global variables...")
5005522Snate@binkert.org    # 1) Define a global variable called x from asm so the C compiler
5015522Snate@binkert.org    #    won't change the symbol at all.
5025522Snate@binkert.org    # 2) Declare that variable.
5035522Snate@binkert.org    # 3) Use the variable
5045522Snate@binkert.org    #
5055522Snate@binkert.org    # If the compiler prepends an underscore, this will successfully
5065522Snate@binkert.org    # link because the external symbol 'x' will be called '_x' which
5075522Snate@binkert.org    # was defined by the asm statement.  If the compiler does not
5085522Snate@binkert.org    # prepend an underscore, this will not successfully link because
5095522Snate@binkert.org    # '_x' will have been defined by assembly, while the C portion of
5105522Snate@binkert.org    # the code will be trying to use 'x'
5115522Snate@binkert.org    ret = context.TryLink('''
5125522Snate@binkert.org        asm(".globl _x; _x: .byte 0");
5135522Snate@binkert.org        extern int x;
5145522Snate@binkert.org        int main() { return x; }
5155522Snate@binkert.org        ''', extension=".c")
5165522Snate@binkert.org    context.env.Append(LEADING_UNDERSCORE=ret)
5175522Snate@binkert.org    context.Result(ret)
5185522Snate@binkert.org    return ret
5195522Snate@binkert.org
5202638Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
5212638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
5226121Snate@binkert.orgconf = Configure(main,
5233716Sstever@eecs.umich.edu                 conf_dir = joinpath(build_root, '.scons_config'),
5245522Snate@binkert.org                 log_file = joinpath(build_root, 'scons_config.log'),
5255522Snate@binkert.org                 custom_tests = { 'CheckLeading' : CheckLeading })
5265522Snate@binkert.org
5275522Snate@binkert.org# Check for leading underscores.  Don't really need to worry either
5285522Snate@binkert.org# way so don't need to check the return code.
5295522Snate@binkert.orgconf.CheckLeading()
5301858SN/A
5315227Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
5325227Ssaidi@eecs.umich.edutry:
5335227Ssaidi@eecs.umich.edu    import platform
5345227Ssaidi@eecs.umich.edu    uname = platform.uname()
5356654Snate@binkert.org    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
5366654Snate@binkert.org        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
5377769SAli.Saidi@ARM.com            main.Append(CCFLAGS=['-arch', 'x86_64'])
5387769SAli.Saidi@ARM.com            main.Append(CFLAGS=['-arch', 'x86_64'])
5397769SAli.Saidi@ARM.com            main.Append(LINKFLAGS=['-arch', 'x86_64'])
5407769SAli.Saidi@ARM.com            main.Append(ASFLAGS=['-arch', 'x86_64'])
5415227Ssaidi@eecs.umich.eduexcept:
5425227Ssaidi@eecs.umich.edu    pass
5435227Ssaidi@eecs.umich.edu
5445204Sstever@gmail.com# Recent versions of scons substitute a "Null" object for Configure()
5455204Sstever@gmail.com# when configuration isn't necessary, e.g., if the "--help" option is
5465204Sstever@gmail.com# present.  Unfortuantely this Null object always returns false,
5475204Sstever@gmail.com# breaking all our configuration checks.  We replace it with our own
5485204Sstever@gmail.com# more optimistic null object that returns True instead.
5495204Sstever@gmail.comif not conf:
5505204Sstever@gmail.com    def NullCheck(*args, **kwargs):
5515204Sstever@gmail.com        return True
5525204Sstever@gmail.com
5535204Sstever@gmail.com    class NullConf:
5545204Sstever@gmail.com        def __init__(self, env):
5555204Sstever@gmail.com            self.env = env
5565204Sstever@gmail.com        def Finish(self):
5575204Sstever@gmail.com            return self.env
5585204Sstever@gmail.com        def __getattr__(self, mname):
5595204Sstever@gmail.com            return NullCheck
5605204Sstever@gmail.com
5616121Snate@binkert.org    conf = NullConf(main)
5625204Sstever@gmail.com
5633118Sstever@eecs.umich.edu# Find Python include and library directories for embedding the
5643118Sstever@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
5653118Sstever@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
5663118Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
5673118Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
5685863Snate@binkert.orgfrom distutils import sysconfig
5693118Sstever@eecs.umich.edu
5705863Snate@binkert.orgpy_getvar = sysconfig.get_config_var
5713118Sstever@eecs.umich.edu
5727457Snate@binkert.orgpy_debug = getattr(sys, 'pydebug', False)
5737457Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "")
5745863Snate@binkert.org
5755863Snate@binkert.orgpy_general_include = sysconfig.get_python_inc()
5765863Snate@binkert.orgpy_platform_include = sysconfig.get_python_inc(plat_specific=True)
5775863Snate@binkert.orgpy_includes = [ py_general_include ]
5785863Snate@binkert.orgif py_platform_include != py_general_include:
5795863Snate@binkert.org    py_includes.append(py_platform_include)
5805863Snate@binkert.org
5816003Snate@binkert.orgpy_lib_path = [ py_getvar('LIBDIR') ]
5825863Snate@binkert.org# add the prefix/lib/pythonX.Y/config dir, but only if there is no
5835863Snate@binkert.org# shared library in prefix/lib/.
5845863Snate@binkert.orgif not py_getvar('Py_ENABLE_SHARED'):
5856120Snate@binkert.org    py_lib_path.append(py_getvar('LIBPL'))
5865863Snate@binkert.org
5875863Snate@binkert.orgpy_libs = []
5885863Snate@binkert.orgfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
5896120Snate@binkert.org    assert lib.startswith('-l')
5906120Snate@binkert.org    lib = lib[2:]   
5915863Snate@binkert.org    if lib not in py_libs:
5925863Snate@binkert.org        py_libs.append(lib)
5936120Snate@binkert.orgpy_libs.append(py_version)
5945863Snate@binkert.org
5956121Snate@binkert.orgmain.Append(CPPPATH=py_includes)
5966121Snate@binkert.orgmain.Append(LIBPATH=py_lib_path)
5975863Snate@binkert.org
5987727SAli.Saidi@ARM.com# Cache build files in the supplied directory.
5997727SAli.Saidi@ARM.comif main['M5_BUILD_CACHE']:
6007727SAli.Saidi@ARM.com    print 'Using build cache located at', main['M5_BUILD_CACHE']
6017727SAli.Saidi@ARM.com    CacheDir(main['M5_BUILD_CACHE'])
6027727SAli.Saidi@ARM.com
6037727SAli.Saidi@ARM.com
6045863Snate@binkert.org# verify that this stuff works
6053118Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
6065863Snate@binkert.org    print "Error: can't find Python.h header in", py_includes
6073118Sstever@eecs.umich.edu    Exit(1)
6083118Sstever@eecs.umich.edu
6095863Snate@binkert.orgfor lib in py_libs:
6105863Snate@binkert.org    if not conf.CheckLib(lib):
6115863Snate@binkert.org        print "Error: can't find library %s required by python" % lib
6125863Snate@binkert.org        Exit(1)
6133118Sstever@eecs.umich.edu
6143483Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops
6153494Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
6163494Ssaidi@eecs.umich.edu   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
6173483Ssaidi@eecs.umich.edu       print "Can't find library with socket calls (e.g. accept())"
6183483Ssaidi@eecs.umich.edu       Exit(1)
6193483Ssaidi@eecs.umich.edu
6203053Sstever@eecs.umich.edu# Check for zlib.  If the check passes, libz will be automatically
6213053Sstever@eecs.umich.edu# added to the LIBS environment variable.
6223918Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
6233053Sstever@eecs.umich.edu    print 'Error: did not find needed zlib compression library '\
6243053Sstever@eecs.umich.edu          'and/or zlib.h header file.'
6253053Sstever@eecs.umich.edu    print '       Please install zlib and try again.'
6263053Sstever@eecs.umich.edu    Exit(1)
6273053Sstever@eecs.umich.edu
6281858SN/A# Check for <fenv.h> (C99 FP environment control)
6291858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>')
6301858SN/Aif not have_fenv:
6311858SN/A    print "Warning: Header file <fenv.h> not found."
6321858SN/A    print "         This host has no IEEE FP rounding mode control."
6331858SN/A
6345863Snate@binkert.org######################################################################
6355863Snate@binkert.org#
6361859SN/A# Check for mysql.
6375863Snate@binkert.org#
6381858SN/Amysql_config = WhereIs('mysql_config')
6395863Snate@binkert.orghave_mysql = bool(mysql_config)
6401858SN/A
6411859SN/A# Check MySQL version.
6421859SN/Aif have_mysql:
6436654Snate@binkert.org    mysql_version = readCommand(mysql_config + ' --version')
6443053Sstever@eecs.umich.edu    min_mysql_version = '4.1'
6456654Snate@binkert.org    if compareVersions(mysql_version, min_mysql_version) < 0:
6463053Sstever@eecs.umich.edu        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
6473053Sstever@eecs.umich.edu        print '         Version', mysql_version, 'detected.'
6481859SN/A        have_mysql = False
6491859SN/A
6501859SN/A# Set up mysql_config commands.
6511859SN/Aif have_mysql:
6521859SN/A    mysql_config_include = mysql_config + ' --include'
6531859SN/A    if os.system(mysql_config_include + ' > /dev/null') != 0:
6541859SN/A        # older mysql_config versions don't support --include, use
6551859SN/A        # --cflags instead
6561862SN/A        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
6571859SN/A    # This seems to work in all versions
6581859SN/A    mysql_config_libs = mysql_config + ' --libs'
6591859SN/A
6605863Snate@binkert.org######################################################################
6615863Snate@binkert.org#
6625863Snate@binkert.org# Finish the configuration
6635863Snate@binkert.org#
6646121Snate@binkert.orgmain = conf.Finish()
6651858SN/A
6665863Snate@binkert.org######################################################################
6675863Snate@binkert.org#
6685863Snate@binkert.org# Collect all non-global variables
6695863Snate@binkert.org#
6705863Snate@binkert.org
6712139SN/A# Define the universe of supported ISAs
6724202Sbinkertn@umich.eduall_isa_list = [ ]
6734202Sbinkertn@umich.eduExport('all_isa_list')
6742139SN/A
6756994Snate@binkert.orgclass CpuModel(object):
6766994Snate@binkert.org    '''The CpuModel class encapsulates everything the ISA parser needs to
6776994Snate@binkert.org    know about a particular CPU model.'''
6786994Snate@binkert.org
6796994Snate@binkert.org    # Dict of available CPU model objects.  Accessible as CpuModel.dict.
6806994Snate@binkert.org    dict = {}
6816994Snate@binkert.org    list = []
6826994Snate@binkert.org    defaults = []
6836994Snate@binkert.org
6846994Snate@binkert.org    # Constructor.  Automatically adds models to CpuModel.dict.
6856994Snate@binkert.org    def __init__(self, name, filename, includes, strings, default=False):
6866994Snate@binkert.org        self.name = name           # name of model
6876994Snate@binkert.org        self.filename = filename   # filename for output exec code
6886994Snate@binkert.org        self.includes = includes   # include files needed in exec file
6896994Snate@binkert.org        # The 'strings' dict holds all the per-CPU symbols we can
6906994Snate@binkert.org        # substitute into templates etc.
6916994Snate@binkert.org        self.strings = strings
6926994Snate@binkert.org
6936994Snate@binkert.org        # This cpu is enabled by default
6946994Snate@binkert.org        self.default = default
6956994Snate@binkert.org
6966994Snate@binkert.org        # Add self to dict
6976994Snate@binkert.org        if name in CpuModel.dict:
6986994Snate@binkert.org            raise AttributeError, "CpuModel '%s' already registered" % name
6996994Snate@binkert.org        CpuModel.dict[name] = self
7006994Snate@binkert.org        CpuModel.list.append(name)
7016994Snate@binkert.org
7026994Snate@binkert.orgExport('CpuModel')
7032155SN/A
7045863Snate@binkert.org# Sticky variables get saved in the variables file so they persist from
7051869SN/A# one invocation to the next (unless overridden, in which case the new
7061869SN/A# value becomes sticky).
7075863Snate@binkert.orgsticky_vars = Variables(args=ARGUMENTS)
7085863Snate@binkert.orgExport('sticky_vars')
7094202Sbinkertn@umich.edu
7106108Snate@binkert.org# Sticky variables that should be exported
7116108Snate@binkert.orgexport_vars = []
7126108Snate@binkert.orgExport('export_vars')
7136108Snate@binkert.org
7144202Sbinkertn@umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the
7155863Snate@binkert.org# above variables
7165742Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list:
7175742Snate@binkert.org    for root, dirs, files in os.walk(bdir):
7185341Sstever@gmail.com        if 'SConsopts' in files:
7195342Sstever@gmail.com            print "Reading", joinpath(root, 'SConsopts')
7205342Sstever@gmail.com            SConscript(joinpath(root, 'SConsopts'))
7214202Sbinkertn@umich.edu
7224202Sbinkertn@umich.eduall_isa_list.sort()
7234202Sbinkertn@umich.edu
7245863Snate@binkert.orgsticky_vars.AddVariables(
7255863Snate@binkert.org    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
7265863Snate@binkert.org    BoolVariable('FULL_SYSTEM', 'Full-system support', False),
7276994Snate@binkert.org    ListVariable('CPU_MODELS', 'CPU models',
7286994Snate@binkert.org                 sorted(n for n,m in CpuModel.dict.iteritems() if m.default),
7296994Snate@binkert.org                 sorted(CpuModel.list)),
7305863Snate@binkert.org    BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
7315863Snate@binkert.org    BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
7325863Snate@binkert.org                 False),
7335863Snate@binkert.org    BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
7345863Snate@binkert.org                 False),
7355863Snate@binkert.org    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
7365863Snate@binkert.org                 False),
7375863Snate@binkert.org    BoolVariable('SS_COMPATIBLE_FP',
7385863Snate@binkert.org                 'Make floating-point results compatible with SimpleScalar',
7395863Snate@binkert.org                 False),
7405863Snate@binkert.org    BoolVariable('USE_SSE2',
7415863Snate@binkert.org                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
7425863Snate@binkert.org                 False),
7435863Snate@binkert.org    BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
7445863Snate@binkert.org    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
7455863Snate@binkert.org    BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
7465952Ssaidi@eecs.umich.edu    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
7477450Sstever@gmail.com    BoolVariable('RUBY', 'Build with Ruby', False),
7481869SN/A    )
7491858SN/A
7505863Snate@binkert.org# These variables get exported to #defines in config/*.hh (see src/SConscript).
7516108Snate@binkert.orgexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL',
7526108Snate@binkert.org                'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS',
7536108Snate@binkert.org                'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE']
7541858SN/A
755955SN/A###################################################
756955SN/A#
7571869SN/A# Define a SCons builder for configuration flag headers.
7581869SN/A#
7591869SN/A###################################################
7601869SN/A
7611869SN/A# This function generates a config header file that #defines the
7625863Snate@binkert.org# variable symbol to the current variable setting (0 or 1).  The source
7635863Snate@binkert.org# operands are the name of the variable and a Value node containing the
7645863Snate@binkert.org# value of the variable.
7651869SN/Adef build_config_file(target, source, env):
7665863Snate@binkert.org    (variable, value) = [s.get_contents() for s in source]
7671869SN/A    f = file(str(target[0]), 'w')
7685863Snate@binkert.org    print >> f, '#define', variable, value
7691869SN/A    f.close()
7701869SN/A    return None
7711869SN/A
7721869SN/A# Generate the message to be printed when building the config file.
7731869SN/Adef build_config_file_string(target, source, env):
7745863Snate@binkert.org    (variable, value) = [s.get_contents() for s in source]
7755863Snate@binkert.org    return "Defining %s as %s in %s." % (variable, value, target[0])
7761869SN/A
7771869SN/A# Combine the two functions into a scons Action object.
7781869SN/Aconfig_action = Action(build_config_file, build_config_file_string)
7791869SN/A
7801869SN/A# The emitter munges the source & target node lists to reflect what
7811869SN/A# we're really doing.
7821869SN/Adef config_emitter(target, source, env):
7835863Snate@binkert.org    # extract variable name from Builder arg
7845863Snate@binkert.org    variable = str(target[0])
7851869SN/A    # True target is config header file
7865863Snate@binkert.org    target = joinpath('config', variable.lower() + '.hh')
7875863Snate@binkert.org    val = env[variable]
7883356Sbinkertn@umich.edu    if isinstance(val, bool):
7893356Sbinkertn@umich.edu        # Force value to 0/1
7903356Sbinkertn@umich.edu        val = int(val)
7913356Sbinkertn@umich.edu    elif isinstance(val, str):
7923356Sbinkertn@umich.edu        val = '"' + val + '"'
7934781Snate@binkert.org
7945863Snate@binkert.org    # Sources are variable name & value (packaged in SCons Value nodes)
7955863Snate@binkert.org    return ([target], [Value(variable), Value(val)])
7961869SN/A
7971869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
7981869SN/A
7996121Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder })
8001869SN/A
8012638Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root.
8026121Snate@binkert.orgmain.SConscript('ext/libelf/SConscript',
8036121Snate@binkert.org                variant_dir = joinpath(build_root, 'libelf'))
8042638Sstever@eecs.umich.edu
8055749Scws3k@cs.virginia.edu# gzstream build is shared across all configs in the build root.
8066121Snate@binkert.orgmain.SConscript('ext/gzstream/SConscript',
8076121Snate@binkert.org                variant_dir = joinpath(build_root, 'gzstream'))
8085749Scws3k@cs.virginia.edu
8091869SN/A###################################################
8101869SN/A#
8113546Sgblack@eecs.umich.edu# This function is used to set up a directory with switching headers
8123546Sgblack@eecs.umich.edu#
8133546Sgblack@eecs.umich.edu###################################################
8143546Sgblack@eecs.umich.edu
8156121Snate@binkert.orgmain['ALL_ISA_LIST'] = all_isa_list
8165863Snate@binkert.orgdef make_switching_dir(dname, switch_headers, env):
8173546Sgblack@eecs.umich.edu    # Generate the header.  target[0] is the full path of the output
8183546Sgblack@eecs.umich.edu    # header to generate.  'source' is a dummy variable, since we get the
8193546Sgblack@eecs.umich.edu    # list of ISAs from env['ALL_ISA_LIST'].
8203546Sgblack@eecs.umich.edu    def gen_switch_hdr(target, source, env):
8214781Snate@binkert.org        fname = str(target[0])
8224781Snate@binkert.org        f = open(fname, 'w')
8236658Snate@binkert.org        isa = env['TARGET_ISA'].lower()
8246658Snate@binkert.org        print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
8254781Snate@binkert.org        f.close()
8263546Sgblack@eecs.umich.edu
8273546Sgblack@eecs.umich.edu    # Build SCons Action object. 'varlist' specifies env vars that this
8283546Sgblack@eecs.umich.edu    # action depends on; when env['ALL_ISA_LIST'] changes these actions
8293546Sgblack@eecs.umich.edu    # should get re-executed.
8307756SAli.Saidi@ARM.com    switch_hdr_action = MakeAction(gen_switch_hdr,
8317756SAli.Saidi@ARM.com                     " [GENERATE] $STRIP_TARGET", varlist=['ALL_ISA_LIST'])
8323546Sgblack@eecs.umich.edu
8333546Sgblack@eecs.umich.edu    # Instantiate actions for each header
8343546Sgblack@eecs.umich.edu    for hdr in switch_headers:
8353546Sgblack@eecs.umich.edu        env.Command(hdr, [], switch_hdr_action)
8364202Sbinkertn@umich.eduExport('make_switching_dir')
8373546Sgblack@eecs.umich.edu
8383546Sgblack@eecs.umich.edu###################################################
8393546Sgblack@eecs.umich.edu#
840955SN/A# Define build environments for selected configurations.
841955SN/A#
842955SN/A###################################################
843955SN/A
8445863Snate@binkert.orgfor variant_path in variant_paths:
8455863Snate@binkert.org    print "Building in", variant_path
8465343Sstever@gmail.com
8475343Sstever@gmail.com    # Make a copy of the build-root environment to use for this config.
8486121Snate@binkert.org    env = main.Clone()
8495863Snate@binkert.org    env['BUILDDIR'] = variant_path
8504773Snate@binkert.org
8515863Snate@binkert.org    # variant_dir is the tail component of build path, and is used to
8522632Sstever@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
8535863Snate@binkert.org    (build_root, variant_dir) = splitpath(variant_path)
8542023SN/A
8555863Snate@binkert.org    # Set env variables according to the build directory config.
8565863Snate@binkert.org    sticky_vars.files = []
8575863Snate@binkert.org    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
8585863Snate@binkert.org    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
8595863Snate@binkert.org    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
8605863Snate@binkert.org    current_vars_file = joinpath(build_root, 'variables', variant_dir)
8615863Snate@binkert.org    if isfile(current_vars_file):
8625863Snate@binkert.org        sticky_vars.files.append(current_vars_file)
8635863Snate@binkert.org        print "Using saved variables file %s" % current_vars_file
8642632Sstever@eecs.umich.edu    else:
8655863Snate@binkert.org        # Build dir-specific variables file doesn't exist.
8662023SN/A
8672632Sstever@eecs.umich.edu        # Make sure the directory is there so we can create it later
8685863Snate@binkert.org        opt_dir = dirname(current_vars_file)
8695342Sstever@gmail.com        if not isdir(opt_dir):
8705863Snate@binkert.org            mkdir(opt_dir)
8712632Sstever@eecs.umich.edu
8725863Snate@binkert.org        # Get default build variables from source tree.  Variables are
8735863Snate@binkert.org        # normally determined by name of $VARIANT_DIR, but can be
8742632Sstever@eecs.umich.edu        # overriden by 'default=' arg on command line.
8755863Snate@binkert.org        default_vars_file = joinpath('build_opts',
8765863Snate@binkert.org                                     ARGUMENTS.get('default', variant_dir))
8775863Snate@binkert.org        if isfile(default_vars_file):
8785863Snate@binkert.org            sticky_vars.files.append(default_vars_file)
8795863Snate@binkert.org            print "Variables file %s not found,\n  using defaults in %s" \
8805863Snate@binkert.org                  % (current_vars_file, default_vars_file)
8812632Sstever@eecs.umich.edu        else:
8825863Snate@binkert.org            print "Error: cannot find variables file %s or %s" \
8835863Snate@binkert.org                  % (current_vars_file, default_vars_file)
8842632Sstever@eecs.umich.edu            Exit(1)
8851888SN/A
8865863Snate@binkert.org    # Apply current variable settings to env
8875863Snate@binkert.org    sticky_vars.Update(env)
8881858SN/A
8895863Snate@binkert.org    help_text += "\nSticky variables for %s:\n" % variant_dir \
8907756SAli.Saidi@ARM.com                 + sticky_vars.GenerateHelpText(env)
8912598SN/A
8925863Snate@binkert.org    # Process variable settings.
8931858SN/A
8941858SN/A    if not have_fenv and env['USE_FENV']:
8951858SN/A        print "Warning: <fenv.h> not available; " \
8965863Snate@binkert.org              "forcing USE_FENV to False in", variant_dir + "."
8971858SN/A        env['USE_FENV'] = False
8981858SN/A
8991858SN/A    if not env['USE_FENV']:
9005863Snate@binkert.org        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
9011871SN/A        print "         FP results may deviate slightly from other platforms."
9021858SN/A
9031858SN/A    if env['EFENCE']:
9041858SN/A        env.Append(LIBS=['efence'])
9051858SN/A
9061858SN/A    if env['USE_MYSQL']:
9071858SN/A        if not have_mysql:
9081858SN/A            print "Warning: MySQL not available; " \
9095863Snate@binkert.org                  "forcing USE_MYSQL to False in", variant_dir + "."
9101858SN/A            env['USE_MYSQL'] = False
9111858SN/A        else:
9125863Snate@binkert.org            print "Compiling in", variant_dir, "with MySQL support."
9131859SN/A            env.ParseConfig(mysql_config_libs)
9141859SN/A            env.ParseConfig(mysql_config_include)
9151869SN/A
9165863Snate@binkert.org    # Save sticky variable settings back to current variables file
9175863Snate@binkert.org    sticky_vars.Save(current_vars_file, env)
9181869SN/A
9191965SN/A    if env['USE_SSE2']:
9207739Sgblack@eecs.umich.edu        env.Append(CCFLAGS=['-msse2'])
9211965SN/A
9222761Sstever@eecs.umich.edu    # The src/SConscript file sets up the build rules in 'env' according
9235863Snate@binkert.org    # to the configured variables.  It returns a list of environments,
9241869SN/A    # one for each variant build (debug, opt, etc.)
9255863Snate@binkert.org    envList = SConscript('src/SConscript', variant_dir = variant_path,
9262667Sstever@eecs.umich.edu                         exports = 'env')
9271869SN/A
9281869SN/A    # Set up the regression tests for each build.
9292929Sktlim@umich.edu    for e in envList:
9302929Sktlim@umich.edu        SConscript('tests/SConscript',
9315863Snate@binkert.org                   variant_dir = joinpath(variant_path, 'tests', e.Label),
9322929Sktlim@umich.edu                   exports = { 'env' : e }, duplicate = False)
933955SN/A
9342598SN/AHelp(help_text)
935