SConstruct revision 7450
1955SN/A# -*- mode:python -*-
2955SN/A
37816Ssteve.reinhardt@amd.com# Copyright (c) 2009 The Hewlett-Packard Development Company
45871Snate@binkert.org# Copyright (c) 2004-2005 The Regents of The University of Michigan
51762SN/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.
29955SN/A#
302665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
312665Ssaidi@eecs.umich.edu#          Nathan Binkert
325863Snate@binkert.org
33955SN/A###################################################
34955SN/A#
35955SN/A# SCons top-level build description (SConstruct) file.
36955SN/A#
37955SN/A# 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).
412632Sstever@eecs.umich.edu#
42955SN/A# 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
442632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
452761Sstever@eecs.umich.edu# built for the same host system.
462632Sstever@eecs.umich.edu#
472632Sstever@eecs.umich.edu# Examples:
482632Sstever@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.
512761Sstever@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
532632Sstever@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.
582761Sstever@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.
652632Sstever@eecs.umich.edu#
66955SN/A###################################################
67955SN/A
68955SN/A# 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
995863Snate@binkert.org# Global Python includes
1006654Snate@binkert.orgimport os
101955SN/Aimport re
1025396Ssaidi@eecs.umich.eduimport subprocess
1035863Snate@binkert.orgimport sys
1045863Snate@binkert.org
1054202Sbinkertn@umich.edufrom 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
1095863Snate@binkert.org
110955SN/A# SCons includes
1116654Snate@binkert.orgimport SCons
1125273Sstever@gmail.comimport SCons.Node
1135871Snate@binkert.org
1145273Sstever@gmail.comextra_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
1206655Snate@binkert.org
1215871Snate@binkert.orgfrom m5.util import compareVersions, readCommand
1226654Snate@binkert.org
1235396Ssaidi@eecs.umich.edu########################################################################
1248120Sgblack@eecs.umich.edu#
1258120Sgblack@eecs.umich.edu# Set up the main build environment.
1268120Sgblack@eecs.umich.edu#
1278120Sgblack@eecs.umich.edu########################################################################
1288120Sgblack@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
1298120Sgblack@eecs.umich.edu                 'PYTHONPATH', 'RANLIB' ])
1308120Sgblack@eecs.umich.edu
1318120Sgblack@eecs.umich.eduuse_env = {}
1328120Sgblack@eecs.umich.edufor key,val in os.environ.iteritems():
1338120Sgblack@eecs.umich.edu    if key in use_vars or key.startswith("M5"):
1348120Sgblack@eecs.umich.edu        use_env[key] = val
1358120Sgblack@eecs.umich.edu
1368120Sgblack@eecs.umich.edumain = Environment(ENV=use_env)
1378120Sgblack@eecs.umich.edumain.root = Dir(".")         # The current directory (where this file lives).
1388120Sgblack@eecs.umich.edumain.srcdir = Dir("src")     # The source directory
1398120Sgblack@eecs.umich.edu
1408120Sgblack@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses
1418120Sgblack@eecs.umich.edu# as well
1428120Sgblack@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths)
1438120Sgblack@eecs.umich.edu
1448120Sgblack@eecs.umich.edu########################################################################
1458120Sgblack@eecs.umich.edu#
1468120Sgblack@eecs.umich.edu# Mercurial Stuff.
1478120Sgblack@eecs.umich.edu#
1488120Sgblack@eecs.umich.edu# If the M5 directory is a mercurial repository, we should do some
1498120Sgblack@eecs.umich.edu# extra things.
1508120Sgblack@eecs.umich.edu#
1518120Sgblack@eecs.umich.edu########################################################################
1528120Sgblack@eecs.umich.edu
1538120Sgblack@eecs.umich.eduhgdir = main.root.Dir(".hg")
1548120Sgblack@eecs.umich.edu
1558120Sgblack@eecs.umich.edumercurial_style_message = """
1568120Sgblack@eecs.umich.eduYou're missing the M5 style hook.
1578120Sgblack@eecs.umich.eduPlease install the hook so we can ensure that all code fits a common style.
1588120Sgblack@eecs.umich.edu
1598120Sgblack@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc
1607816Ssteve.reinhardt@amd.comor your personal .hgrc
1617816Ssteve.reinhardt@amd.com----------------
1627816Ssteve.reinhardt@amd.com
1637816Ssteve.reinhardt@amd.com[extensions]
1647816Ssteve.reinhardt@amd.comstyle = %s/util/style.py
1657816Ssteve.reinhardt@amd.com
1667816Ssteve.reinhardt@amd.com[hooks]
1677816Ssteve.reinhardt@amd.compretxncommit.style = python:style.check_whitespace
1687816Ssteve.reinhardt@amd.com""" % (main.root)
1695871Snate@binkert.org
1705871Snate@binkert.orgmercurial_bin_not_found = """
1716121Snate@binkert.orgMercurial binary cannot be found, unfortunately this means that we
1725871Snate@binkert.orgcannot easily determine the version of M5 that you are running and
1735871Snate@binkert.orgthis makes error messages more difficult to collect.  Please consider
1746003Snate@binkert.orginstalling mercurial if you choose to post an error message
1756655Snate@binkert.org"""
176955SN/A
1775871Snate@binkert.orgmercurial_lib_not_found = """
1785871Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook
1795871Snate@binkert.orgIf you are actually a M5 developer, please fix this and
1805871Snate@binkert.orgrun the style hook. It is important.
181955SN/A"""
1826121Snate@binkert.org
1836121Snate@binkert.orghg_info = "Unknown"
1846121Snate@binkert.orgif hgdir.exists():
1851533SN/A    # 1) Grab repository revision if we know it.
1866655Snate@binkert.org    cmd = "hg id -n -i -t -b"
1876655Snate@binkert.org    try:
1886655Snate@binkert.org        hg_info = readCommand(cmd, cwd=main.root.abspath).strip()
1896655Snate@binkert.org    except OSError:
1905871Snate@binkert.org        print mercurial_bin_not_found
1915871Snate@binkert.org
1925863Snate@binkert.org    # 2) Ensure that the style hook is in place.
1935871Snate@binkert.org    try:
1945871Snate@binkert.org        ui = None
1955871Snate@binkert.org        if ARGUMENTS.get('IGNORE_STYLE') != 'True':
1965871Snate@binkert.org            from mercurial import ui
1975871Snate@binkert.org            ui = ui.ui()
1985863Snate@binkert.org    except ImportError:
1996121Snate@binkert.org        print mercurial_lib_not_found
2005863Snate@binkert.org
2015871Snate@binkert.org    if ui is not None:
2028336Ssteve.reinhardt@amd.com        ui.readconfig(hgdir.File('hgrc').abspath)
2038336Ssteve.reinhardt@amd.com        style_hook = ui.config('hooks', 'pretxncommit.style', None)
2048336Ssteve.reinhardt@amd.com
2058336Ssteve.reinhardt@amd.com        if not style_hook:
2064678Snate@binkert.org            print mercurial_style_message
2078336Ssteve.reinhardt@amd.com            sys.exit(1)
2088336Ssteve.reinhardt@amd.comelse:
2098336Ssteve.reinhardt@amd.com    print ".hg directory not found"
2104678Snate@binkert.org
2114678Snate@binkert.orgmain['HG_INFO'] = hg_info
2124678Snate@binkert.org
2134678Snate@binkert.org###################################################
2147827Snate@binkert.org#
2157827Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
2168336Ssteve.reinhardt@amd.com# the target(s).
2174678Snate@binkert.org#
2188336Ssteve.reinhardt@amd.com###################################################
2198336Ssteve.reinhardt@amd.com
2208336Ssteve.reinhardt@amd.com# Find default configuration & binary.
2218336Ssteve.reinhardt@amd.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
2228336Ssteve.reinhardt@amd.com
2238336Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list
2245871Snate@binkert.orgdef rfind(l, elt, offs = -1):
2255871Snate@binkert.org    for i in range(len(l)+offs, 0, -1):
2268336Ssteve.reinhardt@amd.com        if l[i] == elt:
2278336Ssteve.reinhardt@amd.com            return i
2288336Ssteve.reinhardt@amd.com    raise ValueError, "element not found"
2298336Ssteve.reinhardt@amd.com
2308336Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the
2315871Snate@binkert.org# directory below this will determine the build parameters.  For
2328336Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
2338336Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it
2348336Ssteve.reinhardt@amd.com# follow 'build' in the bulid path.
2358336Ssteve.reinhardt@amd.com
2368336Ssteve.reinhardt@amd.com# Generate absolute paths to targets so we can see where the build dir is
2374678Snate@binkert.orgif COMMAND_LINE_TARGETS:
2385871Snate@binkert.org    # Ask SCons which directory it was invoked from
2394678Snate@binkert.org    launch_dir = GetLaunchDir()
2408336Ssteve.reinhardt@amd.com    # Make targets relative to invocation directory
2418336Ssteve.reinhardt@amd.com    abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \
2428336Ssteve.reinhardt@amd.com                    COMMAND_LINE_TARGETS]
2438336Ssteve.reinhardt@amd.comelse:
2448336Ssteve.reinhardt@amd.com    # Default targets are relative to root of tree
2458336Ssteve.reinhardt@amd.com    abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \
2468336Ssteve.reinhardt@amd.com                    DEFAULT_TARGETS]
2478336Ssteve.reinhardt@amd.com
2488336Ssteve.reinhardt@amd.com
2498336Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the
2508336Ssteve.reinhardt@amd.com# collected targets reference.
2518336Ssteve.reinhardt@amd.comvariant_paths = []
2528336Ssteve.reinhardt@amd.combuild_root = None
2538336Ssteve.reinhardt@amd.comfor t in abs_targets:
2548336Ssteve.reinhardt@amd.com    path_dirs = t.split('/')
2558336Ssteve.reinhardt@amd.com    try:
2568336Ssteve.reinhardt@amd.com        build_top = rfind(path_dirs, 'build', -2)
2575871Snate@binkert.org    except:
2586121Snate@binkert.org        print "Error: no non-leaf 'build' dir found on target path", t
259955SN/A        Exit(1)
260955SN/A    this_build_root = joinpath('/',*path_dirs[:build_top+1])
2612632Sstever@eecs.umich.edu    if not build_root:
2622632Sstever@eecs.umich.edu        build_root = this_build_root
263955SN/A    else:
264955SN/A        if this_build_root != build_root:
265955SN/A            print "Error: build targets not under same build root\n"\
266955SN/A                  "  %s\n  %s" % (build_root, this_build_root)
2675863Snate@binkert.org            Exit(1)
268955SN/A    variant_path = joinpath('/',*path_dirs[:build_top+2])
2692632Sstever@eecs.umich.edu    if variant_path not in variant_paths:
2702632Sstever@eecs.umich.edu        variant_paths.append(variant_path)
2712632Sstever@eecs.umich.edu
2722632Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there)
2732632Sstever@eecs.umich.eduif not isdir(build_root):
2742632Sstever@eecs.umich.edu    mkdir(build_root)
2752632Sstever@eecs.umich.edu
2768268Ssteve.reinhardt@amd.comExport('main')
2778268Ssteve.reinhardt@amd.com
2788268Ssteve.reinhardt@amd.commain.SConsignFile(joinpath(build_root, "sconsign"))
2798268Ssteve.reinhardt@amd.com
2808268Ssteve.reinhardt@amd.com# Default duplicate option is to use hard links, but this messes up
2818268Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves
2828268Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link.  Symbolic
2832632Sstever@eecs.umich.edu# (soft) links work better.
2842632Sstever@eecs.umich.edumain.SetOption('duplicate', 'soft-copy')
2852632Sstever@eecs.umich.edu
2862632Sstever@eecs.umich.edu#
2878268Ssteve.reinhardt@amd.com# Set up global sticky variables... these are common to an entire build
2882632Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE)
2898268Ssteve.reinhardt@amd.com#
2908268Ssteve.reinhardt@amd.com
2918268Ssteve.reinhardt@amd.com# Variable validators & converters for global sticky variables
2928268Ssteve.reinhardt@amd.comdef PathListMakeAbsolute(val):
2933718Sstever@eecs.umich.edu    if not val:
2942634Sstever@eecs.umich.edu        return val
2952634Sstever@eecs.umich.edu    f = lambda p: abspath(expanduser(p))
2965863Snate@binkert.org    return ':'.join(map(f, val.split(':')))
2972638Sstever@eecs.umich.edu
2988268Ssteve.reinhardt@amd.comdef PathListAllExist(key, val, env):
2992632Sstever@eecs.umich.edu    if not val:
3002632Sstever@eecs.umich.edu        return
3012632Sstever@eecs.umich.edu    paths = val.split(':')
3022632Sstever@eecs.umich.edu    for path in paths:
3032632Sstever@eecs.umich.edu        if not isdir(path):
3041858SN/A            raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
3053716Sstever@eecs.umich.edu
3062638Sstever@eecs.umich.eduglobal_sticky_vars_file = joinpath(build_root, 'variables.global')
3072638Sstever@eecs.umich.edu
3082638Sstever@eecs.umich.eduglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS)
3092638Sstever@eecs.umich.edu
3102638Sstever@eecs.umich.eduglobal_sticky_vars.AddVariables(
3112638Sstever@eecs.umich.edu    ('CC', 'C compiler', environ.get('CC', main['CC'])),
3122638Sstever@eecs.umich.edu    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
3135863Snate@binkert.org    ('BATCH', 'Use batch pool for build and tests', False),
3145863Snate@binkert.org    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3155863Snate@binkert.org    ('EXTRAS', 'Add Extra directories to the compilation', '',
316955SN/A     PathListAllExist, PathListMakeAbsolute),
3175341Sstever@gmail.com    )
3185341Sstever@gmail.com
3195863Snate@binkert.org# base help text
3207756SAli.Saidi@ARM.comhelp_text = '''
3215341Sstever@gmail.comUsage: scons [scons options] [build options] [target(s)]
3226121Snate@binkert.org
3234494Ssaidi@eecs.umich.eduGlobal sticky options:
3246121Snate@binkert.org'''
3251105SN/A
3262667Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_sticky_vars_file
3272667Sstever@eecs.umich.eduglobal_sticky_vars.Update(main)
3282667Sstever@eecs.umich.edu
3292667Sstever@eecs.umich.eduhelp_text += global_sticky_vars.GenerateHelpText(main)
3306121Snate@binkert.org
3312667Sstever@eecs.umich.edu# Save sticky variable settings back to current variables file
3325341Sstever@gmail.comglobal_sticky_vars.Save(global_sticky_vars_file, main)
3335863Snate@binkert.org
3345341Sstever@gmail.com# Parse EXTRAS variable to build list of all directories where we're
3355341Sstever@gmail.com# look for sources etc.  This list is exported as base_dir_list.
3365341Sstever@gmail.combase_dir = main.srcdir.abspath
3378120Sgblack@eecs.umich.eduif main['EXTRAS']:
3385341Sstever@gmail.com    extras_dir_list = main['EXTRAS'].split(':')
3398120Sgblack@eecs.umich.eduelse:
3405341Sstever@gmail.com    extras_dir_list = []
3418120Sgblack@eecs.umich.edu
3426121Snate@binkert.orgExport('base_dir')
3436121Snate@binkert.orgExport('extras_dir_list')
3445397Ssaidi@eecs.umich.edu
3455397Ssaidi@eecs.umich.edu# the ext directory should be on the #includes path
3467727SAli.Saidi@ARM.commain.Append(CPPPATH=[Dir('ext')])
3478268Ssteve.reinhardt@amd.com
3486168Snate@binkert.orgCXX_version = readCommand([main['CXX'],'--version'], exception=False)
3495341Sstever@gmail.comCXX_V = readCommand([main['CXX'],'-V'], exception=False)
3508120Sgblack@eecs.umich.edu
3518120Sgblack@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
3528120Sgblack@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
3536814Sgblack@eecs.umich.edumain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
3545863Snate@binkert.orgif main['GCC'] + main['SUNCC'] + main['ICC'] > 1:
3558120Sgblack@eecs.umich.edu    print 'Error: How can we have two at the same time?'
3565341Sstever@gmail.com    Exit(1)
3575863Snate@binkert.org
3588268Ssteve.reinhardt@amd.com# Set up default C++ compiler flags
3596121Snate@binkert.orgif main['GCC']:
3606121Snate@binkert.org    main.Append(CCFLAGS='-pipe')
3618268Ssteve.reinhardt@amd.com    main.Append(CCFLAGS='-fno-strict-aliasing')
3625742Snate@binkert.org    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
3635742Snate@binkert.org    main.Append(CXXFLAGS='-Wno-deprecated')
3645341Sstever@gmail.comelif main['ICC']:
3655742Snate@binkert.org    pass #Fix me... add warning flags once we clean up icc warnings
3665742Snate@binkert.orgelif main['SUNCC']:
3675341Sstever@gmail.com    main.Append(CCFLAGS='-Qoption ccfe')
3686017Snate@binkert.org    main.Append(CCFLAGS='-features=gcc')
3696121Snate@binkert.org    main.Append(CCFLAGS='-features=extensions')
3706017Snate@binkert.org    main.Append(CCFLAGS='-library=stlport4')
3717816Ssteve.reinhardt@amd.com    main.Append(CCFLAGS='-xar')
3727756SAli.Saidi@ARM.com    #main.Append(CCFLAGS='-instances=semiexplicit')
3737756SAli.Saidi@ARM.comelse:
3747756SAli.Saidi@ARM.com    print 'Error: Don\'t know what compiler options to use for your compiler.'
3757756SAli.Saidi@ARM.com    print '       Please fix SConstruct and src/SConscript and try again.'
3767756SAli.Saidi@ARM.com    Exit(1)
3777756SAli.Saidi@ARM.com
3787756SAli.Saidi@ARM.com# Set up common yacc/bison flags (needed for Ruby)
3797756SAli.Saidi@ARM.commain['YACCFLAGS'] = '-d'
3807816Ssteve.reinhardt@amd.commain['YACCHXXFILESUFFIX'] = '.hh'
3817816Ssteve.reinhardt@amd.com
3827816Ssteve.reinhardt@amd.com# Do this after we save setting back, or else we'll tack on an
3837816Ssteve.reinhardt@amd.com# extra 'qdo' every time we run scons.
3847816Ssteve.reinhardt@amd.comif main['BATCH']:
3857816Ssteve.reinhardt@amd.com    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
3867816Ssteve.reinhardt@amd.com    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
3877816Ssteve.reinhardt@amd.com    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
3887816Ssteve.reinhardt@amd.com    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
3897816Ssteve.reinhardt@amd.com    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
3907756SAli.Saidi@ARM.com
3917816Ssteve.reinhardt@amd.comif sys.platform == 'cygwin':
3927816Ssteve.reinhardt@amd.com    # cygwin has some header file issues...
3937816Ssteve.reinhardt@amd.com    main.Append(CCFLAGS="-Wno-uninitialized")
3947816Ssteve.reinhardt@amd.com
3957816Ssteve.reinhardt@amd.com# Check for SWIG
3967816Ssteve.reinhardt@amd.comif not main.has_key('SWIG'):
3977816Ssteve.reinhardt@amd.com    print 'Error: SWIG utility not found.'
3987816Ssteve.reinhardt@amd.com    print '       Please install (see http://www.swig.org) and retry.'
3997816Ssteve.reinhardt@amd.com    Exit(1)
4007816Ssteve.reinhardt@amd.com
4017816Ssteve.reinhardt@amd.com# Check for appropriate SWIG version
4027816Ssteve.reinhardt@amd.comswig_version = readCommand(('swig', '-version'), exception='').split()
4037816Ssteve.reinhardt@amd.com# First 3 words should be "SWIG Version x.y.z"
4047816Ssteve.reinhardt@amd.comif len(swig_version) < 3 or \
4057816Ssteve.reinhardt@amd.com        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
4067816Ssteve.reinhardt@amd.com    print 'Error determining SWIG version.'
4077816Ssteve.reinhardt@amd.com    Exit(1)
4087816Ssteve.reinhardt@amd.com
4097816Ssteve.reinhardt@amd.commin_swig_version = '1.3.28'
4107816Ssteve.reinhardt@amd.comif compareVersions(swig_version[2], min_swig_version) < 0:
4117816Ssteve.reinhardt@amd.com    print 'Error: SWIG version', min_swig_version, 'or newer required.'
4127816Ssteve.reinhardt@amd.com    print '       Installed version:', swig_version[2]
4137816Ssteve.reinhardt@amd.com    Exit(1)
4147816Ssteve.reinhardt@amd.com
4157816Ssteve.reinhardt@amd.com# Set up SWIG flags & scanner
4167816Ssteve.reinhardt@amd.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
4177816Ssteve.reinhardt@amd.commain.Append(SWIGFLAGS=swig_flags)
4187816Ssteve.reinhardt@amd.com
4197816Ssteve.reinhardt@amd.com# filter out all existing swig scanners, they mess up the dependency
4207816Ssteve.reinhardt@amd.com# stuff for some reason
4217816Ssteve.reinhardt@amd.comscanners = []
4227816Ssteve.reinhardt@amd.comfor scanner in main['SCANNERS']:
4237816Ssteve.reinhardt@amd.com    skeys = scanner.skeys
4247816Ssteve.reinhardt@amd.com    if skeys == '.i':
4257816Ssteve.reinhardt@amd.com        continue
4267816Ssteve.reinhardt@amd.com
4277816Ssteve.reinhardt@amd.com    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
4287816Ssteve.reinhardt@amd.com        continue
4297816Ssteve.reinhardt@amd.com
4307816Ssteve.reinhardt@amd.com    scanners.append(scanner)
4317816Ssteve.reinhardt@amd.com
4327816Ssteve.reinhardt@amd.com# add the new swig scanner that we like better
4337816Ssteve.reinhardt@amd.comfrom SCons.Scanner import ClassicCPP as CPPScanner
4347816Ssteve.reinhardt@amd.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
4357816Ssteve.reinhardt@amd.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
4367816Ssteve.reinhardt@amd.com
4377816Ssteve.reinhardt@amd.com# replace the scanners list that has what we want
4387816Ssteve.reinhardt@amd.commain['SCANNERS'] = scanners
4397816Ssteve.reinhardt@amd.com
4407816Ssteve.reinhardt@amd.com# Add a custom Check function to the Configure context so that we can
4417816Ssteve.reinhardt@amd.com# figure out if the compiler adds leading underscores to global
4427816Ssteve.reinhardt@amd.com# variables.  This is needed for the autogenerated asm files that we
4437816Ssteve.reinhardt@amd.com# use for embedding the python code.
4447816Ssteve.reinhardt@amd.comdef CheckLeading(context):
4457816Ssteve.reinhardt@amd.com    context.Message("Checking for leading underscore in global variables...")
4467816Ssteve.reinhardt@amd.com    # 1) Define a global variable called x from asm so the C compiler
4477816Ssteve.reinhardt@amd.com    #    won't change the symbol at all.
4487816Ssteve.reinhardt@amd.com    # 2) Declare that variable.
4497816Ssteve.reinhardt@amd.com    # 3) Use the variable
4507816Ssteve.reinhardt@amd.com    #
4517816Ssteve.reinhardt@amd.com    # If the compiler prepends an underscore, this will successfully
4527756SAli.Saidi@ARM.com    # link because the external symbol 'x' will be called '_x' which
4538120Sgblack@eecs.umich.edu    # was defined by the asm statement.  If the compiler does not
4547756SAli.Saidi@ARM.com    # prepend an underscore, this will not successfully link because
4557756SAli.Saidi@ARM.com    # '_x' will have been defined by assembly, while the C portion of
4567756SAli.Saidi@ARM.com    # the code will be trying to use 'x'
4577756SAli.Saidi@ARM.com    ret = context.TryLink('''
4587816Ssteve.reinhardt@amd.com        asm(".globl _x; _x: .byte 0");
4597816Ssteve.reinhardt@amd.com        extern int x;
4607816Ssteve.reinhardt@amd.com        int main() { return x; }
4617816Ssteve.reinhardt@amd.com        ''', extension=".c")
4627816Ssteve.reinhardt@amd.com    context.env.Append(LEADING_UNDERSCORE=ret)
4637816Ssteve.reinhardt@amd.com    context.Result(ret)
4647816Ssteve.reinhardt@amd.com    return ret
4657816Ssteve.reinhardt@amd.com
4667816Ssteve.reinhardt@amd.com# Platform-specific configuration.  Note again that we assume that all
4677816Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform.
4687756SAli.Saidi@ARM.comconf = Configure(main,
4697756SAli.Saidi@ARM.com                 conf_dir = joinpath(build_root, '.scons_config'),
4706654Snate@binkert.org                 log_file = joinpath(build_root, 'scons_config.log'),
4716654Snate@binkert.org                 custom_tests = { 'CheckLeading' : CheckLeading })
4725871Snate@binkert.org
4736121Snate@binkert.org# Check for leading underscores.  Don't really need to worry either
4746121Snate@binkert.org# way so don't need to check the return code.
4756121Snate@binkert.orgconf.CheckLeading()
4766121Snate@binkert.org
4773940Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
4783918Ssaidi@eecs.umich.edutry:
4793918Ssaidi@eecs.umich.edu    import platform
4801858SN/A    uname = platform.uname()
4816121Snate@binkert.org    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
4827739Sgblack@eecs.umich.edu        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
4837739Sgblack@eecs.umich.edu            main.Append(CCFLAGS='-arch x86_64')
4846143Snate@binkert.org            main.Append(CFLAGS='-arch x86_64')
4857739Sgblack@eecs.umich.edu            main.Append(LINKFLAGS='-arch x86_64')
4867618SAli.Saidi@arm.com            main.Append(ASFLAGS='-arch x86_64')
4877618SAli.Saidi@arm.comexcept:
4887618SAli.Saidi@arm.com    pass
4897618SAli.Saidi@arm.com
4908614Sgblack@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure()
4917618SAli.Saidi@arm.com# when configuration isn't necessary, e.g., if the "--help" option is
4927618SAli.Saidi@arm.com# present.  Unfortuantely this Null object always returns false,
4937618SAli.Saidi@arm.com# breaking all our configuration checks.  We replace it with our own
4947739Sgblack@eecs.umich.edu# more optimistic null object that returns True instead.
4956121Snate@binkert.orgif not conf:
4963940Ssaidi@eecs.umich.edu    def NullCheck(*args, **kwargs):
4976121Snate@binkert.org        return True
4987739Sgblack@eecs.umich.edu
4997739Sgblack@eecs.umich.edu    class NullConf:
5007739Sgblack@eecs.umich.edu        def __init__(self, env):
5017739Sgblack@eecs.umich.edu            self.env = env
5027739Sgblack@eecs.umich.edu        def Finish(self):
5037739Sgblack@eecs.umich.edu            return self.env
5043918Ssaidi@eecs.umich.edu        def __getattr__(self, mname):
5053918Ssaidi@eecs.umich.edu            return NullCheck
5063940Ssaidi@eecs.umich.edu
5073918Ssaidi@eecs.umich.edu    conf = NullConf(main)
5083918Ssaidi@eecs.umich.edu
5096157Snate@binkert.org# Find Python include and library directories for embedding the
5106157Snate@binkert.org# interpreter.  For consistency, we will use the same Python
5116157Snate@binkert.org# installation used to run scons (and thus this script).  If you want
5126157Snate@binkert.org# to link in an alternate version, see above for instructions on how
5135397Ssaidi@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
5145397Ssaidi@eecs.umich.edufrom distutils import sysconfig
5156121Snate@binkert.org
5166121Snate@binkert.orgpy_getvar = sysconfig.get_config_var
5176121Snate@binkert.org
5186121Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION')
5196121Snate@binkert.org
5206121Snate@binkert.orgpy_general_include = sysconfig.get_python_inc()
5215397Ssaidi@eecs.umich.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True)
5221851SN/Apy_includes = [ py_general_include ]
5231851SN/Aif py_platform_include != py_general_include:
5247739Sgblack@eecs.umich.edu    py_includes.append(py_platform_include)
525955SN/A
5263053Sstever@eecs.umich.edupy_lib_path = [ py_getvar('LIBDIR') ]
5276121Snate@binkert.org# add the prefix/lib/pythonX.Y/config dir, but only if there is no
5283053Sstever@eecs.umich.edu# shared library in prefix/lib/.
5293053Sstever@eecs.umich.eduif not py_getvar('Py_ENABLE_SHARED'):
5303053Sstever@eecs.umich.edu    py_lib_path.append(py_getvar('LIBPL'))
5313053Sstever@eecs.umich.edu
5323053Sstever@eecs.umich.edupy_libs = []
5336654Snate@binkert.orgfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
5343053Sstever@eecs.umich.edu    assert lib.startswith('-l')
5354742Sstever@eecs.umich.edu    lib = lib[2:]   
5364742Sstever@eecs.umich.edu    if lib not in py_libs:
5373053Sstever@eecs.umich.edu        py_libs.append(lib)
5383053Sstever@eecs.umich.edupy_libs.append(py_version)
5393053Sstever@eecs.umich.edu
5403053Sstever@eecs.umich.edumain.Append(CPPPATH=py_includes)
5416654Snate@binkert.orgmain.Append(LIBPATH=py_lib_path)
5423053Sstever@eecs.umich.edu
5433053Sstever@eecs.umich.edu# verify that this stuff works
5443053Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
5453053Sstever@eecs.umich.edu    print "Error: can't find Python.h header in", py_includes
5462667Sstever@eecs.umich.edu    Exit(1)
5474554Sbinkertn@umich.edu
5486121Snate@binkert.orgfor lib in py_libs:
5492667Sstever@eecs.umich.edu    if not conf.CheckLib(lib):
5504554Sbinkertn@umich.edu        print "Error: can't find library %s required by python" % lib
5514554Sbinkertn@umich.edu        Exit(1)
5524554Sbinkertn@umich.edu
5536121Snate@binkert.org# On Solaris you need to use libsocket for socket ops
5544554Sbinkertn@umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
5554554Sbinkertn@umich.edu   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
5564554Sbinkertn@umich.edu       print "Can't find library with socket calls (e.g. accept())"
5574781Snate@binkert.org       Exit(1)
5584554Sbinkertn@umich.edu
5594554Sbinkertn@umich.edu# Check for zlib.  If the check passes, libz will be automatically
5602667Sstever@eecs.umich.edu# added to the LIBS environment variable.
5614554Sbinkertn@umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
5624554Sbinkertn@umich.edu    print 'Error: did not find needed zlib compression library '\
5634554Sbinkertn@umich.edu          'and/or zlib.h header file.'
5644554Sbinkertn@umich.edu    print '       Please install zlib and try again.'
5652667Sstever@eecs.umich.edu    Exit(1)
5664554Sbinkertn@umich.edu
5672667Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
5684554Sbinkertn@umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
5696121Snate@binkert.orgif not have_fenv:
5702667Sstever@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
5715522Snate@binkert.org    print "         This host has no IEEE FP rounding mode control."
5725522Snate@binkert.org
5735522Snate@binkert.org######################################################################
5745522Snate@binkert.org#
5755522Snate@binkert.org# Check for mysql.
5765522Snate@binkert.org#
5775522Snate@binkert.orgmysql_config = WhereIs('mysql_config')
5785522Snate@binkert.orghave_mysql = bool(mysql_config)
5795522Snate@binkert.org
5805522Snate@binkert.org# Check MySQL version.
5815522Snate@binkert.orgif have_mysql:
5825522Snate@binkert.org    mysql_version = readCommand(mysql_config + ' --version')
5835522Snate@binkert.org    min_mysql_version = '4.1'
5845522Snate@binkert.org    if compareVersions(mysql_version, min_mysql_version) < 0:
5855522Snate@binkert.org        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
5865522Snate@binkert.org        print '         Version', mysql_version, 'detected.'
5875522Snate@binkert.org        have_mysql = False
5885522Snate@binkert.org
5895522Snate@binkert.org# Set up mysql_config commands.
5905522Snate@binkert.orgif have_mysql:
5915522Snate@binkert.org    mysql_config_include = mysql_config + ' --include'
5925522Snate@binkert.org    if os.system(mysql_config_include + ' > /dev/null') != 0:
5935522Snate@binkert.org        # older mysql_config versions don't support --include, use
5945522Snate@binkert.org        # --cflags instead
5955522Snate@binkert.org        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
5965522Snate@binkert.org    # This seems to work in all versions
5972638Sstever@eecs.umich.edu    mysql_config_libs = mysql_config + ' --libs'
5982638Sstever@eecs.umich.edu
5996121Snate@binkert.org######################################################################
6003716Sstever@eecs.umich.edu#
6015522Snate@binkert.org# Finish the configuration
6025522Snate@binkert.org#
6035522Snate@binkert.orgmain = conf.Finish()
6045522Snate@binkert.org
6055522Snate@binkert.org######################################################################
6065522Snate@binkert.org#
6071858SN/A# Collect all non-global variables
6085227Ssaidi@eecs.umich.edu#
6095227Ssaidi@eecs.umich.edu
6105227Ssaidi@eecs.umich.edu# Define the universe of supported ISAs
6115227Ssaidi@eecs.umich.eduall_isa_list = [ ]
6126654Snate@binkert.orgExport('all_isa_list')
6136654Snate@binkert.org
6147769SAli.Saidi@ARM.comclass CpuModel(object):
6157769SAli.Saidi@ARM.com    '''The CpuModel class encapsulates everything the ISA parser needs to
6167769SAli.Saidi@ARM.com    know about a particular CPU model.'''
6177769SAli.Saidi@ARM.com
6185227Ssaidi@eecs.umich.edu    # Dict of available CPU model objects.  Accessible as CpuModel.dict.
6195227Ssaidi@eecs.umich.edu    dict = {}
6205227Ssaidi@eecs.umich.edu    list = []
6215204Sstever@gmail.com    defaults = []
6225204Sstever@gmail.com
6235204Sstever@gmail.com    # Constructor.  Automatically adds models to CpuModel.dict.
6245204Sstever@gmail.com    def __init__(self, name, filename, includes, strings, default=False):
6255204Sstever@gmail.com        self.name = name           # name of model
6265204Sstever@gmail.com        self.filename = filename   # filename for output exec code
6275204Sstever@gmail.com        self.includes = includes   # include files needed in exec file
6285204Sstever@gmail.com        # The 'strings' dict holds all the per-CPU symbols we can
6295204Sstever@gmail.com        # substitute into templates etc.
6305204Sstever@gmail.com        self.strings = strings
6315204Sstever@gmail.com
6325204Sstever@gmail.com        # This cpu is enabled by default
6335204Sstever@gmail.com        self.default = default
6345204Sstever@gmail.com
6355204Sstever@gmail.com        # Add self to dict
6365204Sstever@gmail.com        if name in CpuModel.dict:
6375204Sstever@gmail.com            raise AttributeError, "CpuModel '%s' already registered" % name
6386121Snate@binkert.org        CpuModel.dict[name] = self
6395204Sstever@gmail.com        CpuModel.list.append(name)
6403118Sstever@eecs.umich.edu
6413118Sstever@eecs.umich.eduExport('CpuModel')
6423118Sstever@eecs.umich.edu
6433118Sstever@eecs.umich.edu# Sticky variables get saved in the variables file so they persist from
6443118Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
6455863Snate@binkert.org# value becomes sticky).
6463118Sstever@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS)
6475863Snate@binkert.orgExport('sticky_vars')
6483118Sstever@eecs.umich.edu
6497457Snate@binkert.org# Sticky variables that should be exported
6507457Snate@binkert.orgexport_vars = []
6515863Snate@binkert.orgExport('export_vars')
6525863Snate@binkert.org
6535863Snate@binkert.org# Non-sticky variables only apply to the current build.
6545863Snate@binkert.orgnonsticky_vars = Variables(args=ARGUMENTS)
6555863Snate@binkert.orgExport('nonsticky_vars')
6565863Snate@binkert.org
6575863Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the
6586003Snate@binkert.org# above variables
6595863Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list:
6605863Snate@binkert.org    for root, dirs, files in os.walk(bdir):
6615863Snate@binkert.org        if 'SConsopts' in files:
6626120Snate@binkert.org            print "Reading", joinpath(root, 'SConsopts')
6635863Snate@binkert.org            SConscript(joinpath(root, 'SConsopts'))
6645863Snate@binkert.org
6655863Snate@binkert.orgall_isa_list.sort()
6666120Snate@binkert.org
6676120Snate@binkert.orgsticky_vars.AddVariables(
6685863Snate@binkert.org    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
6695863Snate@binkert.org    BoolVariable('FULL_SYSTEM', 'Full-system support', False),
6706120Snate@binkert.org    ListVariable('CPU_MODELS', 'CPU models',
6715863Snate@binkert.org                 sorted(n for n,m in CpuModel.dict.iteritems() if m.default),
6726121Snate@binkert.org                 sorted(CpuModel.list)),
6736121Snate@binkert.org    BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
6745863Snate@binkert.org    BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
6757727SAli.Saidi@ARM.com                 False),
6767727SAli.Saidi@ARM.com    BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
6777727SAli.Saidi@ARM.com                 False),
6787727SAli.Saidi@ARM.com    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
6797727SAli.Saidi@ARM.com                 False),
6807727SAli.Saidi@ARM.com    BoolVariable('SS_COMPATIBLE_FP',
6815863Snate@binkert.org                 'Make floating-point results compatible with SimpleScalar',
6823118Sstever@eecs.umich.edu                 False),
6835863Snate@binkert.org    BoolVariable('USE_SSE2',
6843118Sstever@eecs.umich.edu                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
6853118Sstever@eecs.umich.edu                 False),
6865863Snate@binkert.org    BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
6875863Snate@binkert.org    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
6885863Snate@binkert.org    BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
6895863Snate@binkert.org    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
6903118Sstever@eecs.umich.edu    BoolVariable('RUBY', 'Build with Ruby', False),
6913483Ssaidi@eecs.umich.edu    )
6923494Ssaidi@eecs.umich.edu
6933494Ssaidi@eecs.umich.edunonsticky_vars.AddVariables(
6943483Ssaidi@eecs.umich.edu    BoolVariable('update_ref', 'Update test reference outputs', False)
6953483Ssaidi@eecs.umich.edu    )
6963483Ssaidi@eecs.umich.edu
6973053Sstever@eecs.umich.edu# These variables get exported to #defines in config/*.hh (see src/SConscript).
6983053Sstever@eecs.umich.eduexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL',
6993918Ssaidi@eecs.umich.edu                'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS',
7003053Sstever@eecs.umich.edu                'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE']
7013053Sstever@eecs.umich.edu
7023053Sstever@eecs.umich.edu###################################################
7033053Sstever@eecs.umich.edu#
7043053Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers.
7057840Snate@binkert.org#
7067865Sgblack@eecs.umich.edu###################################################
7077865Sgblack@eecs.umich.edu
7087865Sgblack@eecs.umich.edu# This function generates a config header file that #defines the
7097865Sgblack@eecs.umich.edu# variable symbol to the current variable setting (0 or 1).  The source
7107865Sgblack@eecs.umich.edu# operands are the name of the variable and a Value node containing the
7117840Snate@binkert.org# value of the variable.
7127840Snate@binkert.orgdef build_config_file(target, source, env):
7137840Snate@binkert.org    (variable, value) = [s.get_contents() for s in source]
7147840Snate@binkert.org    f = file(str(target[0]), 'w')
7151858SN/A    print >> f, '#define', variable, value
7161858SN/A    f.close()
7171858SN/A    return None
7181858SN/A
7191858SN/A# Generate the message to be printed when building the config file.
7201858SN/Adef build_config_file_string(target, source, env):
7215863Snate@binkert.org    (variable, value) = [s.get_contents() for s in source]
7225863Snate@binkert.org    return "Defining %s as %s in %s." % (variable, value, target[0])
7235863Snate@binkert.org
7245863Snate@binkert.org# Combine the two functions into a scons Action object.
7256121Snate@binkert.orgconfig_action = Action(build_config_file, build_config_file_string)
7261858SN/A
7275863Snate@binkert.org# The emitter munges the source & target node lists to reflect what
7285863Snate@binkert.org# we're really doing.
7295863Snate@binkert.orgdef config_emitter(target, source, env):
7305863Snate@binkert.org    # extract variable name from Builder arg
7315863Snate@binkert.org    variable = str(target[0])
7322139SN/A    # True target is config header file
7334202Sbinkertn@umich.edu    target = joinpath('config', variable.lower() + '.hh')
7344202Sbinkertn@umich.edu    val = env[variable]
7352139SN/A    if isinstance(val, bool):
7366994Snate@binkert.org        # Force value to 0/1
7376994Snate@binkert.org        val = int(val)
7386994Snate@binkert.org    elif isinstance(val, str):
7396994Snate@binkert.org        val = '"' + val + '"'
7406994Snate@binkert.org
7416994Snate@binkert.org    # Sources are variable name & value (packaged in SCons Value nodes)
7426994Snate@binkert.org    return ([target], [Value(variable), Value(val)])
7436994Snate@binkert.org
7446994Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action)
7456994Snate@binkert.org
7466994Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder })
7476994Snate@binkert.org
7486994Snate@binkert.org# libelf build is shared across all configs in the build root.
7496994Snate@binkert.orgmain.SConscript('ext/libelf/SConscript',
7506994Snate@binkert.org                variant_dir = joinpath(build_root, 'libelf'))
7516994Snate@binkert.org
7526994Snate@binkert.org# gzstream build is shared across all configs in the build root.
7536994Snate@binkert.orgmain.SConscript('ext/gzstream/SConscript',
7546994Snate@binkert.org                variant_dir = joinpath(build_root, 'gzstream'))
7556994Snate@binkert.org
7566994Snate@binkert.org###################################################
7576994Snate@binkert.org#
7586994Snate@binkert.org# This function is used to set up a directory with switching headers
7596994Snate@binkert.org#
7606994Snate@binkert.org###################################################
7616994Snate@binkert.org
7626994Snate@binkert.orgmain['ALL_ISA_LIST'] = all_isa_list
7636994Snate@binkert.orgdef make_switching_dir(dname, switch_headers, env):
7642155SN/A    # Generate the header.  target[0] is the full path of the output
7655863Snate@binkert.org    # header to generate.  'source' is a dummy variable, since we get the
7661869SN/A    # list of ISAs from env['ALL_ISA_LIST'].
7671869SN/A    def gen_switch_hdr(target, source, env):
7685863Snate@binkert.org        fname = str(target[0])
7695863Snate@binkert.org        f = open(fname, 'w')
7704202Sbinkertn@umich.edu        isa = env['TARGET_ISA'].lower()
7716108Snate@binkert.org        print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname))
7726108Snate@binkert.org        f.close()
7736108Snate@binkert.org
7746108Snate@binkert.org    # String to print when generating header
7754202Sbinkertn@umich.edu    def gen_switch_hdr_string(target, source, env):
7765863Snate@binkert.org        return "Generating switch header " + str(target[0])
7778474Sgblack@eecs.umich.edu
7788474Sgblack@eecs.umich.edu    # Build SCons Action object. 'varlist' specifies env vars that this
7795742Snate@binkert.org    # action depends on; when env['ALL_ISA_LIST'] changes these actions
7808268Ssteve.reinhardt@amd.com    # should get re-executed.
7818268Ssteve.reinhardt@amd.com    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
7828268Ssteve.reinhardt@amd.com                               varlist=['ALL_ISA_LIST'])
7835742Snate@binkert.org
7845341Sstever@gmail.com    # Instantiate actions for each header
7858474Sgblack@eecs.umich.edu    for hdr in switch_headers:
7868474Sgblack@eecs.umich.edu        env.Command(hdr, [], switch_hdr_action)
7875342Sstever@gmail.comExport('make_switching_dir')
7884202Sbinkertn@umich.edu
7894202Sbinkertn@umich.edu###################################################
7904202Sbinkertn@umich.edu#
7915863Snate@binkert.org# Define build environments for selected configurations.
7925863Snate@binkert.org#
7935863Snate@binkert.org###################################################
7946994Snate@binkert.org
7956994Snate@binkert.orgfor variant_path in variant_paths:
7966994Snate@binkert.org    print "Building in", variant_path
7975863Snate@binkert.org
7988152Ssteve.reinhardt@amd.com    # Make a copy of the build-root environment to use for this config.
7998152Ssteve.reinhardt@amd.com    env = main.Clone()
8005863Snate@binkert.org    env['BUILDDIR'] = variant_path
8015863Snate@binkert.org
8025863Snate@binkert.org    # variant_dir is the tail component of build path, and is used to
8035863Snate@binkert.org    # determine the build parameters (e.g., 'ALPHA_SE')
8045863Snate@binkert.org    (build_root, variant_dir) = splitpath(variant_path)
8055863Snate@binkert.org
8065863Snate@binkert.org    # Set env variables according to the build directory config.
8075863Snate@binkert.org    sticky_vars.files = []
8085863Snate@binkert.org    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
8095863Snate@binkert.org    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
8107840Snate@binkert.org    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
8115863Snate@binkert.org    current_vars_file = joinpath(build_root, 'variables', variant_dir)
8125863Snate@binkert.org    if isfile(current_vars_file):
8135952Ssaidi@eecs.umich.edu        sticky_vars.files.append(current_vars_file)
8141869SN/A        print "Using saved variables file %s" % current_vars_file
8151858SN/A    else:
8165863Snate@binkert.org        # Build dir-specific variables file doesn't exist.
8178297Snate@binkert.org
8188152Ssteve.reinhardt@amd.com        # Make sure the directory is there so we can create it later
8197840Snate@binkert.org        opt_dir = dirname(current_vars_file)
8207840Snate@binkert.org        if not isdir(opt_dir):
8211858SN/A            mkdir(opt_dir)
822955SN/A
823955SN/A        # Get default build variables from source tree.  Variables are
8241869SN/A        # normally determined by name of $VARIANT_DIR, but can be
8251869SN/A        # overriden by 'default=' arg on command line.
8261869SN/A        default_vars_file = joinpath('build_opts',
8271869SN/A                                     ARGUMENTS.get('default', variant_dir))
8281869SN/A        if isfile(default_vars_file):
8295863Snate@binkert.org            sticky_vars.files.append(default_vars_file)
8305863Snate@binkert.org            print "Variables file %s not found,\n  using defaults in %s" \
8315863Snate@binkert.org                  % (current_vars_file, default_vars_file)
8321869SN/A        else:
8335863Snate@binkert.org            print "Error: cannot find variables file %s or %s" \
8341869SN/A                  % (current_vars_file, default_vars_file)
8355863Snate@binkert.org            Exit(1)
8361869SN/A
8371869SN/A    # Apply current variable settings to env
8381869SN/A    sticky_vars.Update(env)
8391869SN/A    nonsticky_vars.Update(env)
8408483Sgblack@eecs.umich.edu
8411869SN/A    help_text += "\nSticky variables for %s:\n" % variant_dir \
8421869SN/A                 + sticky_vars.GenerateHelpText(env) \
8431869SN/A                 + "\nNon-sticky variables for %s:\n" % variant_dir \
8441869SN/A                 + nonsticky_vars.GenerateHelpText(env)
8455863Snate@binkert.org
8465863Snate@binkert.org    # Process variable settings.
8471869SN/A
8485863Snate@binkert.org    if not have_fenv and env['USE_FENV']:
8495863Snate@binkert.org        print "Warning: <fenv.h> not available; " \
8503356Sbinkertn@umich.edu              "forcing USE_FENV to False in", variant_dir + "."
8513356Sbinkertn@umich.edu        env['USE_FENV'] = False
8523356Sbinkertn@umich.edu
8533356Sbinkertn@umich.edu    if not env['USE_FENV']:
8543356Sbinkertn@umich.edu        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
8554781Snate@binkert.org        print "         FP results may deviate slightly from other platforms."
8565863Snate@binkert.org
8575863Snate@binkert.org    if env['EFENCE']:
8581869SN/A        env.Append(LIBS=['efence'])
8591869SN/A
8601869SN/A    if env['USE_MYSQL']:
8616121Snate@binkert.org        if not have_mysql:
8621869SN/A            print "Warning: MySQL not available; " \
8632638Sstever@eecs.umich.edu                  "forcing USE_MYSQL to False in", variant_dir + "."
8646121Snate@binkert.org            env['USE_MYSQL'] = False
8656121Snate@binkert.org        else:
8662638Sstever@eecs.umich.edu            print "Compiling in", variant_dir, "with MySQL support."
8675749Scws3k@cs.virginia.edu            env.ParseConfig(mysql_config_libs)
8686121Snate@binkert.org            env.ParseConfig(mysql_config_include)
8696121Snate@binkert.org
8705749Scws3k@cs.virginia.edu    # Save sticky variable settings back to current variables file
8711869SN/A    sticky_vars.Save(current_vars_file, env)
8721869SN/A
8733546Sgblack@eecs.umich.edu    if env['USE_SSE2']:
8743546Sgblack@eecs.umich.edu        env.Append(CCFLAGS='-msse2')
8753546Sgblack@eecs.umich.edu
8763546Sgblack@eecs.umich.edu    # The src/SConscript file sets up the build rules in 'env' according
8776121Snate@binkert.org    # to the configured variables.  It returns a list of environments,
8785863Snate@binkert.org    # one for each variant build (debug, opt, etc.)
8793546Sgblack@eecs.umich.edu    envList = SConscript('src/SConscript', variant_dir = variant_path,
8803546Sgblack@eecs.umich.edu                         exports = 'env')
8813546Sgblack@eecs.umich.edu
8823546Sgblack@eecs.umich.edu    # Set up the regression tests for each build.
8834781Snate@binkert.org    for e in envList:
8844781Snate@binkert.org        SConscript('tests/SConscript',
8856658Snate@binkert.org                   variant_dir = joinpath(variant_path, 'tests', e.Label),
8866658Snate@binkert.org                   exports = { 'env' : e }, duplicate = False)
8874781Snate@binkert.org
8883546Sgblack@eecs.umich.eduHelp(help_text)
8893546Sgblack@eecs.umich.edu