SConstruct revision 6655
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company
4955SN/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
282665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
292665Ssaidi@eecs.umich.edu#
30955SN/A# Authors: Steve Reinhardt
31955SN/A#          Nathan Binkert
32955SN/A
33955SN/A###################################################
34955SN/A#
352632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file.
362632Sstever@eecs.umich.edu#
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>'
39955SN/A# 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#
422761Sstever@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
442632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
452632Sstever@eecs.umich.edu# built for the same host system.
462761Sstever@eecs.umich.edu#
472761Sstever@eecs.umich.edu# Examples:
482761Sstever@eecs.umich.edu#
492632Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
502632Sstever@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
522761Sstever@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
562632Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
572632Sstever@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
63955SN/A# file), you can use 'scons -h' to print all the M5-specific build
64955SN/A# options as well.
65955SN/A#
66955SN/A###################################################
67955SN/A
685396Ssaidi@eecs.umich.edu# Check for recent-enough Python and SCons versions.
694202Sbinkertn@umich.edutry:
705342Sstever@gmail.com    # Really old versions of scons only take two options for the
71955SN/A    # function, so check once without the revision and once with the
725273Sstever@gmail.com    # revision, the first instance will fail for stuff other than
735273Sstever@gmail.com    # 0.98, and the second will fail for 0.98.0
742656Sstever@eecs.umich.edu    EnsureSConsVersion(0, 98)
752656Sstever@eecs.umich.edu    EnsureSConsVersion(0, 98, 1)
762656Sstever@eecs.umich.eduexcept SystemExit, e:
772656Sstever@eecs.umich.edu    print """
782656Sstever@eecs.umich.eduFor more details, see:
792656Sstever@eecs.umich.edu    http://m5sim.org/wiki/index.php/Compiling_M5
802656Sstever@eecs.umich.edu"""
812653Sstever@eecs.umich.edu    raise
825227Ssaidi@eecs.umich.edu
835227Ssaidi@eecs.umich.edu# We ensure the python version early because we have stuff that
845227Ssaidi@eecs.umich.edu# requires python 2.4
855227Ssaidi@eecs.umich.edutry:
865396Ssaidi@eecs.umich.edu    EnsurePythonVersion(2, 4)
875396Ssaidi@eecs.umich.eduexcept SystemExit, e:
885396Ssaidi@eecs.umich.edu    print """
895396Ssaidi@eecs.umich.eduYou can use a non-default installation of the Python interpreter by
905396Ssaidi@eecs.umich.edueither (1) rearranging your PATH so that scons finds the non-default
915396Ssaidi@eecs.umich.edu'python' first or (2) explicitly invoking an alternative interpreter
925396Ssaidi@eecs.umich.eduon the scons script.
935396Ssaidi@eecs.umich.edu
945588Ssaidi@eecs.umich.eduFor more details, see:
955396Ssaidi@eecs.umich.edu    http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation
965396Ssaidi@eecs.umich.edu"""
975396Ssaidi@eecs.umich.edu    raise
985396Ssaidi@eecs.umich.edu
995396Ssaidi@eecs.umich.edu# Global Python includes
1005396Ssaidi@eecs.umich.eduimport os
1015396Ssaidi@eecs.umich.eduimport re
1025396Ssaidi@eecs.umich.eduimport subprocess
1035396Ssaidi@eecs.umich.eduimport sys
1045396Ssaidi@eecs.umich.edu
1055396Ssaidi@eecs.umich.edufrom os import mkdir, environ
1065396Ssaidi@eecs.umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath
1075396Ssaidi@eecs.umich.edufrom os.path import exists,  isdir, isfile
1085396Ssaidi@eecs.umich.edufrom os.path import join as joinpath, split as splitpath
1095396Ssaidi@eecs.umich.edu
1105396Ssaidi@eecs.umich.edu# SCons includes
1115396Ssaidi@eecs.umich.eduimport SCons
1125396Ssaidi@eecs.umich.eduimport SCons.Node
1135396Ssaidi@eecs.umich.edu
1145396Ssaidi@eecs.umich.eduextra_python_paths = [
1155396Ssaidi@eecs.umich.edu    Dir('src/python').srcnode().abspath, # M5 includes
1165396Ssaidi@eecs.umich.edu    Dir('ext/ply').srcnode().abspath, # ply is used by several files
1175396Ssaidi@eecs.umich.edu    ]
1185396Ssaidi@eecs.umich.edu    
1195396Ssaidi@eecs.umich.edusys.path[1:1] = extra_python_paths
1205396Ssaidi@eecs.umich.edu
1215396Ssaidi@eecs.umich.edufrom m5.util import compareVersions, readCommand
1225396Ssaidi@eecs.umich.edu
1235396Ssaidi@eecs.umich.edu########################################################################
1245396Ssaidi@eecs.umich.edu#
1255396Ssaidi@eecs.umich.edu# Set up the main build environment.
1265396Ssaidi@eecs.umich.edu#
1275396Ssaidi@eecs.umich.edu########################################################################
1285396Ssaidi@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
1295396Ssaidi@eecs.umich.edu                 'PYTHONPATH', 'RANLIB' ])
1305396Ssaidi@eecs.umich.edu
1315396Ssaidi@eecs.umich.eduuse_env = {}
1325396Ssaidi@eecs.umich.edufor key,val in os.environ.iteritems():
1335396Ssaidi@eecs.umich.edu    if key in use_vars or key.startswith("M5"):
1345396Ssaidi@eecs.umich.edu        use_env[key] = val
1355396Ssaidi@eecs.umich.edu
1365396Ssaidi@eecs.umich.edumain = Environment(ENV=use_env)
1375396Ssaidi@eecs.umich.edumain.root = Dir(".")         # The current directory (where this file lives).
1385396Ssaidi@eecs.umich.edumain.srcdir = Dir("src")     # The source directory
1395396Ssaidi@eecs.umich.edu
1405396Ssaidi@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses
1415396Ssaidi@eecs.umich.edu# as well
1425396Ssaidi@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths)
1435396Ssaidi@eecs.umich.edu
1445396Ssaidi@eecs.umich.edu########################################################################
1455396Ssaidi@eecs.umich.edu#
1465396Ssaidi@eecs.umich.edu# Mercurial Stuff.
1474781Snate@binkert.org#
1481852SN/A# If the M5 directory is a mercurial repository, we should do some
149955SN/A# extra things.
150955SN/A#
151955SN/A########################################################################
1523717Sstever@eecs.umich.edu
1533716Sstever@eecs.umich.eduhgdir = main.root.Dir(".hg")
154955SN/A
1551533SN/Amercurial_style_message = """
1563716Sstever@eecs.umich.eduYou're missing the M5 style hook.
1571533SN/APlease 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
1684678Snate@binkert.org""" % (main.root)
1694678Snate@binkert.org
1704678Snate@binkert.orgmercurial_bin_not_found = """
1714678Snate@binkert.orgMercurial binary cannot be found, unfortunately this means that we
1724678Snate@binkert.orgcannot easily determine the version of M5 that you are running and
1734678Snate@binkert.orgthis makes error messages more difficult to collect.  Please consider
1744678Snate@binkert.orginstalling mercurial if you choose to post an error message
1754678Snate@binkert.org"""
1764678Snate@binkert.org
1774678Snate@binkert.orgmercurial_lib_not_found = """
1784678Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook
1794973Ssaidi@eecs.umich.eduIf you are actually a M5 developer, please fix this and
1804678Snate@binkert.orgrun the style hook. It is important.
1814678Snate@binkert.org"""
1824678Snate@binkert.org
1834678Snate@binkert.orghg_info = "Unknown"
1844678Snate@binkert.orgif hgdir.exists():
1854678Snate@binkert.org    # 1) Grab repository revision if we know it.
186955SN/A    cmd = "hg id -n -i -t -b"
187955SN/A    try:
1882632Sstever@eecs.umich.edu        hg_info = readCommand(cmd, cwd=main.root.abspath).strip()
1892632Sstever@eecs.umich.edu    except OSError:
190955SN/A        print mercurial_bin_not_found
191955SN/A
192955SN/A    # 2) Ensure that the style hook is in place.
193955SN/A    try:
1942632Sstever@eecs.umich.edu        ui = None
195955SN/A        if ARGUMENTS.get('IGNORE_STYLE') != 'True':
1962632Sstever@eecs.umich.edu            from mercurial import ui
1972632Sstever@eecs.umich.edu            ui = ui.ui()
1982632Sstever@eecs.umich.edu    except ImportError:
1992632Sstever@eecs.umich.edu        print mercurial_lib_not_found
2002632Sstever@eecs.umich.edu
2012632Sstever@eecs.umich.edu    if ui is not None:
2022632Sstever@eecs.umich.edu        ui.readconfig(hgdir.File('hgrc').abspath)
2032632Sstever@eecs.umich.edu        style_hook = ui.config('hooks', 'pretxncommit.style', None)
2042632Sstever@eecs.umich.edu
2052632Sstever@eecs.umich.edu        if not style_hook:
2062632Sstever@eecs.umich.edu            print mercurial_style_message
2072632Sstever@eecs.umich.edu            sys.exit(1)
2082632Sstever@eecs.umich.eduelse:
2093718Sstever@eecs.umich.edu    print ".hg directory not found"
2103718Sstever@eecs.umich.edu
2113718Sstever@eecs.umich.edumain['HG_INFO'] = hg_info
2123718Sstever@eecs.umich.edu
2133718Sstever@eecs.umich.edu###################################################
2143718Sstever@eecs.umich.edu#
2153718Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
2163718Sstever@eecs.umich.edu# the target(s).
2173718Sstever@eecs.umich.edu#
2183718Sstever@eecs.umich.edu###################################################
2193718Sstever@eecs.umich.edu
2203718Sstever@eecs.umich.edu# Find default configuration & binary.
2213718Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
2222634Sstever@eecs.umich.edu
2232634Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
2242632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
2252638Sstever@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
2262632Sstever@eecs.umich.edu        if l[i] == elt:
2272632Sstever@eecs.umich.edu            return i
2282632Sstever@eecs.umich.edu    raise ValueError, "element not found"
2292632Sstever@eecs.umich.edu
2302632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
2312632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
2321858SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
2333716Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
2342638Sstever@eecs.umich.edu# follow 'build' in the bulid path.
2352638Sstever@eecs.umich.edu
2362638Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is
2372638Sstever@eecs.umich.eduif COMMAND_LINE_TARGETS:
2382638Sstever@eecs.umich.edu    # Ask SCons which directory it was invoked from
2392638Sstever@eecs.umich.edu    launch_dir = GetLaunchDir()
2402638Sstever@eecs.umich.edu    # Make targets relative to invocation directory
2413716Sstever@eecs.umich.edu    abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \
2422634Sstever@eecs.umich.edu                    COMMAND_LINE_TARGETS]
2432634Sstever@eecs.umich.eduelse:
244955SN/A    # Default targets are relative to root of tree
2455341Sstever@gmail.com    abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \
2465341Sstever@gmail.com                    DEFAULT_TARGETS]
2475341Sstever@gmail.com
2485341Sstever@gmail.com
249955SN/A# Generate a list of the unique build roots and configs that the
250955SN/A# collected targets reference.
251955SN/Avariant_paths = []
252955SN/Abuild_root = None
253955SN/Afor t in abs_targets:
254955SN/A    path_dirs = t.split('/')
255955SN/A    try:
2561858SN/A        build_top = rfind(path_dirs, 'build', -2)
2571858SN/A    except:
2582632Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
259955SN/A        Exit(1)
2604494Ssaidi@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
2614494Ssaidi@eecs.umich.edu    if not build_root:
2623716Sstever@eecs.umich.edu        build_root = this_build_root
2631105SN/A    else:
2642667Sstever@eecs.umich.edu        if this_build_root != build_root:
2652667Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
2662667Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
2672667Sstever@eecs.umich.edu            Exit(1)
2682667Sstever@eecs.umich.edu    variant_path = joinpath('/',*path_dirs[:build_top+2])
2692667Sstever@eecs.umich.edu    if variant_path not in variant_paths:
2701869SN/A        variant_paths.append(variant_path)
2711869SN/A
2721869SN/A# Make sure build_root exists (might not if this is the first build there)
2731869SN/Aif not isdir(build_root):
2741869SN/A    mkdir(build_root)
2751065SN/A
2765341Sstever@gmail.comExport('main')
2775341Sstever@gmail.com
2785341Sstever@gmail.commain.SConsignFile(joinpath(build_root, "sconsign"))
2795341Sstever@gmail.com
2805341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up
2815341Sstever@gmail.com# when you use emacs to edit a file in the target dir, as emacs moves
2825341Sstever@gmail.com# file to file~ then copies to file, breaking the link.  Symbolic
2835341Sstever@gmail.com# (soft) links work better.
2845341Sstever@gmail.commain.SetOption('duplicate', 'soft-copy')
2855341Sstever@gmail.com
2865341Sstever@gmail.com#
2875341Sstever@gmail.com# Set up global sticky variables... these are common to an entire build
2885341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE)
2895341Sstever@gmail.com#
2905341Sstever@gmail.com
2915341Sstever@gmail.com# Variable validators & converters for global sticky variables
2925341Sstever@gmail.comdef PathListMakeAbsolute(val):
2935341Sstever@gmail.com    if not val:
2945341Sstever@gmail.com        return val
2955341Sstever@gmail.com    f = lambda p: abspath(expanduser(p))
2965341Sstever@gmail.com    return ':'.join(map(f, val.split(':')))
2975341Sstever@gmail.com
2985341Sstever@gmail.comdef PathListAllExist(key, val, env):
2995341Sstever@gmail.com    if not val:
3005341Sstever@gmail.com        return
3015341Sstever@gmail.com    paths = val.split(':')
3025341Sstever@gmail.com    for path in paths:
3035397Ssaidi@eecs.umich.edu        if not isdir(path):
3045397Ssaidi@eecs.umich.edu            raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
3055341Sstever@gmail.com
3065341Sstever@gmail.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global')
3075341Sstever@gmail.com
3085341Sstever@gmail.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS)
3095341Sstever@gmail.com
3105341Sstever@gmail.comglobal_sticky_vars.AddVariables(
3115341Sstever@gmail.com    ('CC', 'C compiler', environ.get('CC', main['CC'])),
3125341Sstever@gmail.com    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
3135341Sstever@gmail.com    ('BATCH', 'Use batch pool for build and tests', False),
3145341Sstever@gmail.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3155341Sstever@gmail.com    ('EXTRAS', 'Add Extra directories to the compilation', '',
3165341Sstever@gmail.com     PathListAllExist, PathListMakeAbsolute),
3175341Sstever@gmail.com    BoolVariable('RUBY', 'Build with Ruby', False),
3185341Sstever@gmail.com    )
3195341Sstever@gmail.com
3205341Sstever@gmail.com# base help text
3215341Sstever@gmail.comhelp_text = '''
3225341Sstever@gmail.comUsage: scons [scons options] [build options] [target(s)]
3235341Sstever@gmail.com
3245341Sstever@gmail.comGlobal sticky options:
3255341Sstever@gmail.com'''
3265341Sstever@gmail.com
3275742Snate@binkert.orghelp_text += global_sticky_vars.GenerateHelpText(main)
3285341Sstever@gmail.com
3295742Snate@binkert.org# Update main environment with values from ARGUMENTS & global_sticky_vars_file
3305742Snate@binkert.orgglobal_sticky_vars.Update(main)
3315742Snate@binkert.org
3325341Sstever@gmail.com# Save sticky variable settings back to current variables file
3335742Snate@binkert.orgglobal_sticky_vars.Save(global_sticky_vars_file, main)
3345742Snate@binkert.org
3355341Sstever@gmail.com# Parse EXTRAS variable to build list of all directories where we're
3362632Sstever@eecs.umich.edu# look for sources etc.  This list is exported as base_dir_list.
3375199Sstever@gmail.combase_dir = main.srcdir.abspath
3384781Snate@binkert.orgif main['EXTRAS']:
3394781Snate@binkert.org    extras_dir_list = main['EXTRAS'].split(':')
3405550Snate@binkert.orgelse:
3414781Snate@binkert.org    extras_dir_list = []
3424781Snate@binkert.org
3433918Ssaidi@eecs.umich.eduExport('base_dir')
3444781Snate@binkert.orgExport('extras_dir_list')
3454781Snate@binkert.org
3463940Ssaidi@eecs.umich.edu# the ext directory should be on the #includes path
3473942Ssaidi@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')])
3483940Ssaidi@eecs.umich.edu
3493918Ssaidi@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False)
3503918Ssaidi@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False)
351955SN/A
3521858SN/Amain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
3533918Ssaidi@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
3543918Ssaidi@eecs.umich.edumain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
3553918Ssaidi@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1:
3563918Ssaidi@eecs.umich.edu    print 'Error: How can we have two at the same time?'
3575571Snate@binkert.org    Exit(1)
3583940Ssaidi@eecs.umich.edu
3593940Ssaidi@eecs.umich.edu# Set up default C++ compiler flags
3603918Ssaidi@eecs.umich.eduif main['GCC']:
3613918Ssaidi@eecs.umich.edu    main.Append(CCFLAGS='-pipe')
3623918Ssaidi@eecs.umich.edu    main.Append(CCFLAGS='-fno-strict-aliasing')
3633918Ssaidi@eecs.umich.edu    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
3643918Ssaidi@eecs.umich.edu    main.Append(CXXFLAGS='-Wno-deprecated')
3653918Ssaidi@eecs.umich.eduelif main['ICC']:
3663918Ssaidi@eecs.umich.edu    pass #Fix me... add warning flags once we clean up icc warnings
3673918Ssaidi@eecs.umich.eduelif main['SUNCC']:
3683918Ssaidi@eecs.umich.edu    main.Append(CCFLAGS='-Qoption ccfe')
3693940Ssaidi@eecs.umich.edu    main.Append(CCFLAGS='-features=gcc')
3703918Ssaidi@eecs.umich.edu    main.Append(CCFLAGS='-features=extensions')
3713918Ssaidi@eecs.umich.edu    main.Append(CCFLAGS='-library=stlport4')
3725397Ssaidi@eecs.umich.edu    main.Append(CCFLAGS='-xar')
3735397Ssaidi@eecs.umich.edu    #main.Append(CCFLAGS='-instances=semiexplicit')
3745397Ssaidi@eecs.umich.eduelse:
3755708Ssaidi@eecs.umich.edu    print 'Error: Don\'t know what compiler options to use for your compiler.'
3765708Ssaidi@eecs.umich.edu    print '       Please fix SConstruct and src/SConscript and try again.'
3775708Ssaidi@eecs.umich.edu    Exit(1)
3785708Ssaidi@eecs.umich.edu
3795708Ssaidi@eecs.umich.edu# Set up common yacc/bison flags (needed for Ruby)
3805397Ssaidi@eecs.umich.edumain['YACCFLAGS'] = '-d'
3811851SN/Amain['YACCHXXFILESUFFIX'] = '.hh'
3821851SN/A
3831858SN/A# Do this after we save setting back, or else we'll tack on an
3845200Sstever@gmail.com# extra 'qdo' every time we run scons.
385955SN/Aif main['BATCH']:
3863053Sstever@eecs.umich.edu    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
3873053Sstever@eecs.umich.edu    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
3883053Sstever@eecs.umich.edu    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
3893053Sstever@eecs.umich.edu    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
3903053Sstever@eecs.umich.edu    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
3913053Sstever@eecs.umich.edu
3923053Sstever@eecs.umich.eduif sys.platform == 'cygwin':
3933053Sstever@eecs.umich.edu    # cygwin has some header file issues...
3943053Sstever@eecs.umich.edu    main.Append(CCFLAGS="-Wno-uninitialized")
3954742Sstever@eecs.umich.edu
3964742Sstever@eecs.umich.edu# Check for SWIG
3973053Sstever@eecs.umich.eduif not main.has_key('SWIG'):
3983053Sstever@eecs.umich.edu    print 'Error: SWIG utility not found.'
3993053Sstever@eecs.umich.edu    print '       Please install (see http://www.swig.org) and retry.'
4003053Sstever@eecs.umich.edu    Exit(1)
4013053Sstever@eecs.umich.edu
4023053Sstever@eecs.umich.edu# Check for appropriate SWIG version
4033053Sstever@eecs.umich.eduswig_version = readCommand(('swig', '-version'), exception='').split()
4043053Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z"
4053053Sstever@eecs.umich.eduif len(swig_version) < 3 or \
4062667Sstever@eecs.umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
4074554Sbinkertn@umich.edu    print 'Error determining SWIG version.'
4084554Sbinkertn@umich.edu    Exit(1)
4092667Sstever@eecs.umich.edu
4104554Sbinkertn@umich.edumin_swig_version = '1.3.28'
4114554Sbinkertn@umich.eduif compareVersions(swig_version[2], min_swig_version) < 0:
4124554Sbinkertn@umich.edu    print 'Error: SWIG version', min_swig_version, 'or newer required.'
4134554Sbinkertn@umich.edu    print '       Installed version:', swig_version[2]
4144554Sbinkertn@umich.edu    Exit(1)
4154554Sbinkertn@umich.edu
4164554Sbinkertn@umich.edu# Set up SWIG flags & scanner
4174781Snate@binkert.orgswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
4184554Sbinkertn@umich.edumain.Append(SWIGFLAGS=swig_flags)
4194554Sbinkertn@umich.edu
4202667Sstever@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency
4214554Sbinkertn@umich.edu# stuff for some reason
4224554Sbinkertn@umich.eduscanners = []
4234554Sbinkertn@umich.edufor scanner in main['SCANNERS']:
4244554Sbinkertn@umich.edu    skeys = scanner.skeys
4252667Sstever@eecs.umich.edu    if skeys == '.i':
4264554Sbinkertn@umich.edu        continue
4272667Sstever@eecs.umich.edu
4284554Sbinkertn@umich.edu    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
4294554Sbinkertn@umich.edu        continue
4302667Sstever@eecs.umich.edu
4315522Snate@binkert.org    scanners.append(scanner)
4325522Snate@binkert.org
4335522Snate@binkert.org# add the new swig scanner that we like better
4345522Snate@binkert.orgfrom SCons.Scanner import ClassicCPP as CPPScanner
4355522Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
4365522Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
4375522Snate@binkert.org
4385522Snate@binkert.org# replace the scanners list that has what we want
4395522Snate@binkert.orgmain['SCANNERS'] = scanners
4405522Snate@binkert.org
4415522Snate@binkert.org# Add a custom Check function to the Configure context so that we can
4425522Snate@binkert.org# figure out if the compiler adds leading underscores to global
4435522Snate@binkert.org# variables.  This is needed for the autogenerated asm files that we
4445522Snate@binkert.org# use for embedding the python code.
4455522Snate@binkert.orgdef CheckLeading(context):
4465522Snate@binkert.org    context.Message("Checking for leading underscore in global variables...")
4475522Snate@binkert.org    # 1) Define a global variable called x from asm so the C compiler
4485522Snate@binkert.org    #    won't change the symbol at all.
4495522Snate@binkert.org    # 2) Declare that variable.
4505522Snate@binkert.org    # 3) Use the variable
4515522Snate@binkert.org    #
4525522Snate@binkert.org    # If the compiler prepends an underscore, this will successfully
4535522Snate@binkert.org    # link because the external symbol 'x' will be called '_x' which
4545522Snate@binkert.org    # was defined by the asm statement.  If the compiler does not
4555522Snate@binkert.org    # prepend an underscore, this will not successfully link because
4565522Snate@binkert.org    # '_x' will have been defined by assembly, while the C portion of
4572638Sstever@eecs.umich.edu    # the code will be trying to use 'x'
4582638Sstever@eecs.umich.edu    ret = context.TryLink('''
4592638Sstever@eecs.umich.edu        asm(".globl _x; _x: .byte 0");
4603716Sstever@eecs.umich.edu        extern int x;
4615522Snate@binkert.org        int main() { return x; }
4625522Snate@binkert.org        ''', extension=".c")
4635522Snate@binkert.org    context.env.Append(LEADING_UNDERSCORE=ret)
4645522Snate@binkert.org    context.Result(ret)
4655522Snate@binkert.org    return ret
4665522Snate@binkert.org
4671858SN/A# Platform-specific configuration.  Note again that we assume that all
4685227Ssaidi@eecs.umich.edu# builds under a given build root run on the same host platform.
4695227Ssaidi@eecs.umich.educonf = Configure(main,
4705227Ssaidi@eecs.umich.edu                 conf_dir = joinpath(build_root, '.scons_config'),
4715227Ssaidi@eecs.umich.edu                 log_file = joinpath(build_root, 'scons_config.log'),
4725227Ssaidi@eecs.umich.edu                 custom_tests = { 'CheckLeading' : CheckLeading })
4735227Ssaidi@eecs.umich.edu
4745227Ssaidi@eecs.umich.edu# Check for leading underscores.  Don't really need to worry either
4755227Ssaidi@eecs.umich.edu# way so don't need to check the return code.
4765227Ssaidi@eecs.umich.educonf.CheckLeading()
4775227Ssaidi@eecs.umich.edu
4785227Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
4795227Ssaidi@eecs.umich.edutry:
4805227Ssaidi@eecs.umich.edu    import platform
4815227Ssaidi@eecs.umich.edu    uname = platform.uname()
4825227Ssaidi@eecs.umich.edu    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
4835204Sstever@gmail.com        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
4845204Sstever@gmail.com            main.Append(CCFLAGS='-arch x86_64')
4855204Sstever@gmail.com            main.Append(CFLAGS='-arch x86_64')
4865204Sstever@gmail.com            main.Append(LINKFLAGS='-arch x86_64')
4875204Sstever@gmail.com            main.Append(ASFLAGS='-arch x86_64')
4885204Sstever@gmail.comexcept:
4895204Sstever@gmail.com    pass
4905204Sstever@gmail.com
4915204Sstever@gmail.com# Recent versions of scons substitute a "Null" object for Configure()
4925204Sstever@gmail.com# when configuration isn't necessary, e.g., if the "--help" option is
4935204Sstever@gmail.com# present.  Unfortuantely this Null object always returns false,
4945204Sstever@gmail.com# breaking all our configuration checks.  We replace it with our own
4955204Sstever@gmail.com# more optimistic null object that returns True instead.
4965204Sstever@gmail.comif not conf:
4975204Sstever@gmail.com    def NullCheck(*args, **kwargs):
4985204Sstever@gmail.com        return True
4995204Sstever@gmail.com
5005204Sstever@gmail.com    class NullConf:
5015204Sstever@gmail.com        def __init__(self, env):
5023118Sstever@eecs.umich.edu            self.env = env
5033118Sstever@eecs.umich.edu        def Finish(self):
5043118Sstever@eecs.umich.edu            return self.env
5053118Sstever@eecs.umich.edu        def __getattr__(self, mname):
5063118Sstever@eecs.umich.edu            return NullCheck
5073118Sstever@eecs.umich.edu
5083118Sstever@eecs.umich.edu    conf = NullConf(main)
5093118Sstever@eecs.umich.edu
5103118Sstever@eecs.umich.edu# Find Python include and library directories for embedding the
5113118Sstever@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
5123118Sstever@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
5133716Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
5143118Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
5153118Sstever@eecs.umich.edufrom distutils import sysconfig
5163118Sstever@eecs.umich.edu
5173118Sstever@eecs.umich.edupy_getvar = sysconfig.get_config_var
5183118Sstever@eecs.umich.edu
5193118Sstever@eecs.umich.edupy_version = 'python' + py_getvar('VERSION')
5203118Sstever@eecs.umich.edu
5213118Sstever@eecs.umich.edupy_general_include = sysconfig.get_python_inc()
5223118Sstever@eecs.umich.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True)
5233716Sstever@eecs.umich.edupy_includes = [ py_general_include ]
5243118Sstever@eecs.umich.eduif py_platform_include != py_general_include:
5253118Sstever@eecs.umich.edu    py_includes.append(py_platform_include)
5263118Sstever@eecs.umich.edu
5273118Sstever@eecs.umich.edupy_lib_path = [ py_getvar('LIBDIR') ]
5283118Sstever@eecs.umich.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no
5293118Sstever@eecs.umich.edu# shared library in prefix/lib/.
5303118Sstever@eecs.umich.eduif not py_getvar('Py_ENABLE_SHARED'):
5313118Sstever@eecs.umich.edu    py_lib_path.append(py_getvar('LIBPL'))
5323118Sstever@eecs.umich.edu
5333118Sstever@eecs.umich.edupy_libs = []
5343483Ssaidi@eecs.umich.edufor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
5353494Ssaidi@eecs.umich.edu    assert lib.startswith('-l')
5363494Ssaidi@eecs.umich.edu    lib = lib[2:]   
5373483Ssaidi@eecs.umich.edu    if lib not in py_libs:
5383483Ssaidi@eecs.umich.edu        py_libs.append(lib)
5393483Ssaidi@eecs.umich.edupy_libs.append(py_version)
5403053Sstever@eecs.umich.edu
5413053Sstever@eecs.umich.edumain.Append(CPPPATH=py_includes)
5423918Ssaidi@eecs.umich.edumain.Append(LIBPATH=py_lib_path)
5433053Sstever@eecs.umich.edu
5443053Sstever@eecs.umich.edu# verify that this stuff works
5453053Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
5463053Sstever@eecs.umich.edu    print "Error: can't find Python.h header in", py_includes
5473053Sstever@eecs.umich.edu    Exit(1)
5481858SN/A
5491858SN/Afor lib in py_libs:
5501858SN/A    if not conf.CheckLib(lib):
5511858SN/A        print "Error: can't find library %s required by python" % lib
5521858SN/A        Exit(1)
5531858SN/A
5541859SN/A# On Solaris you need to use libsocket for socket ops
5551858SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
5561858SN/A   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
5571858SN/A       print "Can't find library with socket calls (e.g. accept())"
5581859SN/A       Exit(1)
5591859SN/A
5601862SN/A# Check for zlib.  If the check passes, libz will be automatically
5613053Sstever@eecs.umich.edu# added to the LIBS environment variable.
5623053Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
5633053Sstever@eecs.umich.edu    print 'Error: did not find needed zlib compression library '\
5643053Sstever@eecs.umich.edu          'and/or zlib.h header file.'
5651859SN/A    print '       Please install zlib and try again.'
5661859SN/A    Exit(1)
5671859SN/A
5681859SN/A# Check for <fenv.h> (C99 FP environment control)
5691859SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>')
5701859SN/Aif not have_fenv:
5711859SN/A    print "Warning: Header file <fenv.h> not found."
5721859SN/A    print "         This host has no IEEE FP rounding mode control."
5731862SN/A
5741859SN/A######################################################################
5751859SN/A#
5761859SN/A# Check for mysql.
5771858SN/A#
5781858SN/Amysql_config = WhereIs('mysql_config')
5792139SN/Ahave_mysql = bool(mysql_config)
5804202Sbinkertn@umich.edu
5814202Sbinkertn@umich.edu# Check MySQL version.
5822139SN/Aif have_mysql:
5832155SN/A    mysql_version = readCommand(mysql_config + ' --version')
5844202Sbinkertn@umich.edu    min_mysql_version = '4.1'
5854202Sbinkertn@umich.edu    if compareVersions(mysql_version, min_mysql_version) < 0:
5864202Sbinkertn@umich.edu        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
5872155SN/A        print '         Version', mysql_version, 'detected.'
5881869SN/A        have_mysql = False
5891869SN/A
5901869SN/A# Set up mysql_config commands.
5911869SN/Aif have_mysql:
5924202Sbinkertn@umich.edu    mysql_config_include = mysql_config + ' --include'
5934202Sbinkertn@umich.edu    if os.system(mysql_config_include + ' > /dev/null') != 0:
5944202Sbinkertn@umich.edu        # older mysql_config versions don't support --include, use
5954202Sbinkertn@umich.edu        # --cflags instead
5964202Sbinkertn@umich.edu        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
5974202Sbinkertn@umich.edu    # This seems to work in all versions
5984202Sbinkertn@umich.edu    mysql_config_libs = mysql_config + ' --libs'
5994202Sbinkertn@umich.edu
6005742Snate@binkert.org######################################################################
6015742Snate@binkert.org#
6025341Sstever@gmail.com# Finish the configuration
6035342Sstever@gmail.com#
6045342Sstever@gmail.commain = conf.Finish()
6054202Sbinkertn@umich.edu
6064202Sbinkertn@umich.edu######################################################################
6074202Sbinkertn@umich.edu#
6084202Sbinkertn@umich.edu# Collect all non-global variables
6094202Sbinkertn@umich.edu#
6101869SN/A
6114202Sbinkertn@umich.edu# Define the universe of supported ISAs
6121869SN/Aall_isa_list = [ ]
6132508SN/AExport('all_isa_list')
6142508SN/A
6152508SN/A# Define the universe of supported CPU models
6162508SN/Aall_cpu_list = [ ]
6174202Sbinkertn@umich.edudefault_cpus = [ ]
6181869SN/AExport('all_cpu_list', 'default_cpus')
6195385Sstever@gmail.com
6205385Sstever@gmail.com# Sticky variables get saved in the variables file so they persist from
6215385Sstever@gmail.com# one invocation to the next (unless overridden, in which case the new
6225385Sstever@gmail.com# value becomes sticky).
6231869SN/Asticky_vars = Variables(args=ARGUMENTS)
6241869SN/AExport('sticky_vars')
6251869SN/A
6261869SN/A# Sticky variables that should be exported
6271869SN/Aexport_vars = []
6281965SN/AExport('export_vars')
6291965SN/A
6301965SN/A# Non-sticky variables only apply to the current build.
6311869SN/Anonsticky_vars = Variables(args=ARGUMENTS)
6321869SN/AExport('nonsticky_vars')
6332733Sktlim@umich.edu
6341869SN/A# Walk the tree and execute all SConsopts scripts that wil add to the
6351858SN/A# above variables
6361869SN/Afor bdir in [ base_dir ] + extras_dir_list:
6371869SN/A    for root, dirs, files in os.walk(bdir):
6381869SN/A        if 'SConsopts' in files:
6391858SN/A            print "Reading", joinpath(root, 'SConsopts')
6402761Sstever@eecs.umich.edu            SConscript(joinpath(root, 'SConsopts'))
6411869SN/A
6425385Sstever@gmail.comall_isa_list.sort()
6435385Sstever@gmail.comall_cpu_list.sort()
6445522Snate@binkert.orgdefault_cpus.sort()
6451869SN/A
6461869SN/Asticky_vars.AddVariables(
6471869SN/A    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
6481869SN/A    BoolVariable('FULL_SYSTEM', 'Full-system support', False),
6491869SN/A    ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
6501869SN/A    BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
6511858SN/A    BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
652955SN/A                 False),
653955SN/A    BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
6541869SN/A                 False),
6551869SN/A    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
6561869SN/A                 False),
6571869SN/A    BoolVariable('SS_COMPATIBLE_FP',
6581869SN/A                 'Make floating-point results compatible with SimpleScalar',
6591869SN/A                 False),
6601869SN/A    BoolVariable('USE_SSE2',
6611869SN/A                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
6621869SN/A                 False),
6631869SN/A    BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
6641869SN/A    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
6651869SN/A    BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
6661869SN/A    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
6671869SN/A    )
6681869SN/A
6691869SN/Anonsticky_vars.AddVariables(
6701869SN/A    BoolVariable('update_ref', 'Update test reference outputs', False)
6711869SN/A    )
6721869SN/A
6731869SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript).
6741869SN/Aexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL',
6751869SN/A                'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS',
6761869SN/A                'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE']
6771869SN/A
6781869SN/A###################################################
6791869SN/A#
6801869SN/A# Define a SCons builder for configuration flag headers.
6811869SN/A#
6821869SN/A###################################################
6833716Sstever@eecs.umich.edu
6843356Sbinkertn@umich.edu# This function generates a config header file that #defines the
6853356Sbinkertn@umich.edu# variable symbol to the current variable setting (0 or 1).  The source
6863356Sbinkertn@umich.edu# operands are the name of the variable and a Value node containing the
6873356Sbinkertn@umich.edu# value of the variable.
6883356Sbinkertn@umich.edudef build_config_file(target, source, env):
6893356Sbinkertn@umich.edu    (variable, value) = [s.get_contents() for s in source]
6904781Snate@binkert.org    f = file(str(target[0]), 'w')
6911869SN/A    print >> f, '#define', variable, value
6921869SN/A    f.close()
6931869SN/A    return None
6941869SN/A
6951869SN/A# Generate the message to be printed when building the config file.
6961869SN/Adef build_config_file_string(target, source, env):
6971869SN/A    (variable, value) = [s.get_contents() for s in source]
6982655Sstever@eecs.umich.edu    return "Defining %s as %s in %s." % (variable, value, target[0])
6992655Sstever@eecs.umich.edu
7002655Sstever@eecs.umich.edu# Combine the two functions into a scons Action object.
7012655Sstever@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string)
7022655Sstever@eecs.umich.edu
7032655Sstever@eecs.umich.edu# The emitter munges the source & target node lists to reflect what
7042655Sstever@eecs.umich.edu# we're really doing.
7052655Sstever@eecs.umich.edudef config_emitter(target, source, env):
7062655Sstever@eecs.umich.edu    # extract variable name from Builder arg
7072655Sstever@eecs.umich.edu    variable = str(target[0])
7082655Sstever@eecs.umich.edu    # True target is config header file
7092655Sstever@eecs.umich.edu    target = joinpath('config', variable.lower() + '.hh')
7102655Sstever@eecs.umich.edu    val = env[variable]
7112655Sstever@eecs.umich.edu    if isinstance(val, bool):
7122655Sstever@eecs.umich.edu        # Force value to 0/1
7132655Sstever@eecs.umich.edu        val = int(val)
7142655Sstever@eecs.umich.edu    elif isinstance(val, str):
7152655Sstever@eecs.umich.edu        val = '"' + val + '"'
7162655Sstever@eecs.umich.edu
7172655Sstever@eecs.umich.edu    # Sources are variable name & value (packaged in SCons Value nodes)
7182655Sstever@eecs.umich.edu    return ([target], [Value(variable), Value(val)])
7192655Sstever@eecs.umich.edu
7202655Sstever@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action)
7212655Sstever@eecs.umich.edu
7222655Sstever@eecs.umich.edumain.Append(BUILDERS = { 'ConfigFile' : config_builder })
7232655Sstever@eecs.umich.edu
7242638Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root.
7252638Sstever@eecs.umich.edumain.SConscript('ext/libelf/SConscript',
7263716Sstever@eecs.umich.edu                variant_dir = joinpath(build_root, 'libelf'))
7272638Sstever@eecs.umich.edu
7282638Sstever@eecs.umich.edu# gzstream build is shared across all configs in the build root.
7295749Scws3k@cs.virginia.edumain.SConscript('ext/gzstream/SConscript',
7305749Scws3k@cs.virginia.edu                variant_dir = joinpath(build_root, 'gzstream'))
7315749Scws3k@cs.virginia.edu
7325749Scws3k@cs.virginia.edu###################################################
7335749Scws3k@cs.virginia.edu#
7341869SN/A# This function is used to set up a directory with switching headers
7351869SN/A#
7363546Sgblack@eecs.umich.edu###################################################
7373546Sgblack@eecs.umich.edu
7383546Sgblack@eecs.umich.edumain['ALL_ISA_LIST'] = all_isa_list
7393546Sgblack@eecs.umich.edudef make_switching_dir(dname, switch_headers, env):
7404202Sbinkertn@umich.edu    # Generate the header.  target[0] is the full path of the output
7413546Sgblack@eecs.umich.edu    # header to generate.  'source' is a dummy variable, since we get the
7423546Sgblack@eecs.umich.edu    # list of ISAs from env['ALL_ISA_LIST'].
7433546Sgblack@eecs.umich.edu    def gen_switch_hdr(target, source, env):
7443546Sgblack@eecs.umich.edu        fname = str(target[0])
7453546Sgblack@eecs.umich.edu        bname = basename(fname)
7464781Snate@binkert.org        f = open(fname, 'w')
7474781Snate@binkert.org        f.write('#include "arch/isa_specific.hh"\n')
7484781Snate@binkert.org        cond = '#if'
7494781Snate@binkert.org        for isa in all_isa_list:
7504781Snate@binkert.org            f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
7514781Snate@binkert.org                    % (cond, isa.upper(), dname, isa, bname))
7524781Snate@binkert.org            cond = '#elif'
7534781Snate@binkert.org        f.write('#else\n#error "THE_ISA not set"\n#endif\n')
7544781Snate@binkert.org        f.close()
7554781Snate@binkert.org        return 0
7564781Snate@binkert.org
7574781Snate@binkert.org    # String to print when generating header
7583546Sgblack@eecs.umich.edu    def gen_switch_hdr_string(target, source, env):
7593546Sgblack@eecs.umich.edu        return "Generating switch header " + str(target[0])
7603546Sgblack@eecs.umich.edu
7614781Snate@binkert.org    # Build SCons Action object. 'varlist' specifies env vars that this
7623546Sgblack@eecs.umich.edu    # action depends on; when env['ALL_ISA_LIST'] changes these actions
7633546Sgblack@eecs.umich.edu    # should get re-executed.
7643546Sgblack@eecs.umich.edu    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
7653546Sgblack@eecs.umich.edu                               varlist=['ALL_ISA_LIST'])
7663546Sgblack@eecs.umich.edu
7673546Sgblack@eecs.umich.edu    # Instantiate actions for each header
7683546Sgblack@eecs.umich.edu    for hdr in switch_headers:
7693546Sgblack@eecs.umich.edu        env.Command(hdr, [], switch_hdr_action)
7703546Sgblack@eecs.umich.eduExport('make_switching_dir')
7713546Sgblack@eecs.umich.edu
7724202Sbinkertn@umich.edu###################################################
7733546Sgblack@eecs.umich.edu#
7743546Sgblack@eecs.umich.edu# Define build environments for selected configurations.
7753546Sgblack@eecs.umich.edu#
776955SN/A###################################################
777955SN/A
778955SN/Afor variant_path in variant_paths:
779955SN/A    print "Building in", variant_path
7801858SN/A
7811858SN/A    # Make a copy of the build-root environment to use for this config.
7821858SN/A    env = main.Clone()
7832632Sstever@eecs.umich.edu    env['BUILDDIR'] = variant_path
7842632Sstever@eecs.umich.edu
7855343Sstever@gmail.com    # variant_dir is the tail component of build path, and is used to
7865343Sstever@gmail.com    # determine the build parameters (e.g., 'ALPHA_SE')
7875343Sstever@gmail.com    (build_root, variant_dir) = splitpath(variant_path)
7884773Snate@binkert.org
7894773Snate@binkert.org    # Set env variables according to the build directory config.
7902632Sstever@eecs.umich.edu    sticky_vars.files = []
7912632Sstever@eecs.umich.edu    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
7922632Sstever@eecs.umich.edu    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
7932023SN/A    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
7942632Sstever@eecs.umich.edu    current_vars_file = joinpath(build_root, 'variables', variant_dir)
7952632Sstever@eecs.umich.edu    if isfile(current_vars_file):
7962632Sstever@eecs.umich.edu        sticky_vars.files.append(current_vars_file)
7972632Sstever@eecs.umich.edu        print "Using saved variables file %s" % current_vars_file
7982632Sstever@eecs.umich.edu    else:
7993716Sstever@eecs.umich.edu        # Build dir-specific variables file doesn't exist.
8005342Sstever@gmail.com
8012632Sstever@eecs.umich.edu        # Make sure the directory is there so we can create it later
8022632Sstever@eecs.umich.edu        opt_dir = dirname(current_vars_file)
8032632Sstever@eecs.umich.edu        if not isdir(opt_dir):
8042632Sstever@eecs.umich.edu            mkdir(opt_dir)
8052023SN/A
8062632Sstever@eecs.umich.edu        # Get default build variables from source tree.  Variables are
8072632Sstever@eecs.umich.edu        # normally determined by name of $VARIANT_DIR, but can be
8085342Sstever@gmail.com        # overriden by 'default=' arg on command line.
8091889SN/A        default_vars_file = joinpath('build_opts',
8102632Sstever@eecs.umich.edu                                     ARGUMENTS.get('default', variant_dir))
8112632Sstever@eecs.umich.edu        if isfile(default_vars_file):
8122632Sstever@eecs.umich.edu            sticky_vars.files.append(default_vars_file)
8132632Sstever@eecs.umich.edu            print "Variables file %s not found,\n  using defaults in %s" \
8143716Sstever@eecs.umich.edu                  % (current_vars_file, default_vars_file)
8153716Sstever@eecs.umich.edu        else:
8165342Sstever@gmail.com            print "Error: cannot find variables file %s or %s" \
8172632Sstever@eecs.umich.edu                  % (current_vars_file, default_vars_file)
8182632Sstever@eecs.umich.edu            Exit(1)
8192632Sstever@eecs.umich.edu
8202632Sstever@eecs.umich.edu    # Apply current variable settings to env
8212632Sstever@eecs.umich.edu    sticky_vars.Update(env)
8222632Sstever@eecs.umich.edu    nonsticky_vars.Update(env)
8232632Sstever@eecs.umich.edu
8241888SN/A    help_text += "\nSticky variables for %s:\n" % variant_dir \
8251888SN/A                 + sticky_vars.GenerateHelpText(env) \
8261869SN/A                 + "\nNon-sticky variables for %s:\n" % variant_dir \
8271869SN/A                 + nonsticky_vars.GenerateHelpText(env)
8281858SN/A
8295341Sstever@gmail.com    # Process variable settings.
8302598SN/A
8312598SN/A    if not have_fenv and env['USE_FENV']:
8322598SN/A        print "Warning: <fenv.h> not available; " \
8332598SN/A              "forcing USE_FENV to False in", variant_dir + "."
8341858SN/A        env['USE_FENV'] = False
8351858SN/A
8361858SN/A    if not env['USE_FENV']:
8371858SN/A        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
8381858SN/A        print "         FP results may deviate slightly from other platforms."
8391858SN/A
8401858SN/A    if env['EFENCE']:
8411858SN/A        env.Append(LIBS=['efence'])
8421858SN/A
8431871SN/A    if env['USE_MYSQL']:
8441858SN/A        if not have_mysql:
8451858SN/A            print "Warning: MySQL not available; " \
8461858SN/A                  "forcing USE_MYSQL to False in", variant_dir + "."
8471858SN/A            env['USE_MYSQL'] = False
8481858SN/A        else:
8491858SN/A            print "Compiling in", variant_dir, "with MySQL support."
8501858SN/A            env.ParseConfig(mysql_config_libs)
8511858SN/A            env.ParseConfig(mysql_config_include)
8521858SN/A
8531858SN/A    # Save sticky variable settings back to current variables file
8541858SN/A    sticky_vars.Save(current_vars_file, env)
8551859SN/A
8561859SN/A    if env['USE_SSE2']:
8571869SN/A        env.Append(CCFLAGS='-msse2')
8581888SN/A
8592632Sstever@eecs.umich.edu    # The src/SConscript file sets up the build rules in 'env' according
8601869SN/A    # to the configured variables.  It returns a list of environments,
8611965SN/A    # one for each variant build (debug, opt, etc.)
8621965SN/A    envList = SConscript('src/SConscript', variant_dir = variant_path,
8631965SN/A                         exports = 'env')
8642761Sstever@eecs.umich.edu
8651869SN/A    # Set up the regression tests for each build.
8661869SN/A    for e in envList:
8672632Sstever@eecs.umich.edu        SConscript('tests/SConscript',
8682667Sstever@eecs.umich.edu                   variant_dir = joinpath(variant_path, 'tests', e.Label),
8691869SN/A                   exports = { 'env' : e }, duplicate = False)
8701869SN/A
8712929Sktlim@umich.eduHelp(help_text)
8722929Sktlim@umich.edu