SConstruct revision 5396
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
4955SN/A# All rights reserved.
5955SN/A#
6955SN/A# Redistribution and use in source and binary forms, with or without
7955SN/A# modification, are permitted provided that the following conditions are
8955SN/A# met: redistributions of source code must retain the above copyright
9955SN/A# notice, this list of conditions and the following disclaimer;
10955SN/A# redistributions in binary form must reproduce the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer in the
12955SN/A# documentation and/or other materials provided with the distribution;
13955SN/A# neither the name of the copyright holders nor the names of its
14955SN/A# contributors may be used to endorse or promote products derived from
15955SN/A# this software without specific prior written permission.
16955SN/A#
17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
305863Snate@binkert.org
31955SN/A###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
35955SN/A# While in this directory ('m5'), just type 'scons' to build the default
362632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
372632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
382632Sstever@eecs.umich.edu# the optimized full-system version).
392632Sstever@eecs.umich.edu#
40955SN/A# You can build M5 in a different directory as long as there is a
412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
422632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
432761Sstever@eecs.umich.edu# built for the same host system.
442632Sstever@eecs.umich.edu#
452632Sstever@eecs.umich.edu# Examples:
462632Sstever@eecs.umich.edu#
472761Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
482761Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
492761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
502632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512632Sstever@eecs.umich.edu#
522761Sstever@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
532761Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
542761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
552761Sstever@eecs.umich.edu#   file.
562761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
572632Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
582632Sstever@eecs.umich.edu#
592632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
602632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
622632Sstever@eecs.umich.edu# options as well.
632632Sstever@eecs.umich.edu#
64955SN/A###################################################
65955SN/A
66955SN/Aimport sys
675863Snate@binkert.orgimport os
685863Snate@binkert.orgimport re
695863Snate@binkert.org
705863Snate@binkert.orgfrom os.path import isdir, isfile, join as joinpath
715863Snate@binkert.org
725863Snate@binkert.orgimport SCons
735863Snate@binkert.org
745863Snate@binkert.org# Check for recent-enough Python and SCons versions.  If your system's
755863Snate@binkert.org# default installation of Python is not recent enough, you can use a
765863Snate@binkert.org# non-default installation of the Python interpreter by either (1)
775863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python'
785863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the
795863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
805863Snate@binkert.orgEnsurePythonVersion(2,4)
815863Snate@binkert.org
825863Snate@binkert.org# Import subprocess after we check the version since it doesn't exist in
835863Snate@binkert.org# Python < 2.4.
845863Snate@binkert.orgimport subprocess
855863Snate@binkert.org
865863Snate@binkert.org# helper function: compare arrays or strings of version numbers.
875863Snate@binkert.org# E.g., compare_version((1,3,25), (1,4,1)')
885863Snate@binkert.org# returns -1, 0, 1 if v1 is <, ==, > v2
895863Snate@binkert.orgdef compare_versions(v1, v2):
905863Snate@binkert.org    def make_version_list(v):
915863Snate@binkert.org        if isinstance(v, (list,tuple)):
925863Snate@binkert.org            return v
935863Snate@binkert.org        elif isinstance(v, str):
945863Snate@binkert.org            return map(int, v.split('.'))
955863Snate@binkert.org        else:
965863Snate@binkert.org            raise TypeError
975863Snate@binkert.org
98955SN/A    v1 = make_version_list(v1)
995396Ssaidi@eecs.umich.edu    v2 = make_version_list(v2)
1005863Snate@binkert.org    # Compare corresponding elements of lists
1015863Snate@binkert.org    for n1,n2 in zip(v1, v2):
1024202Sbinkertn@umich.edu        if n1 < n2: return -1
1035863Snate@binkert.org        if n1 > n2: return  1
1045863Snate@binkert.org    # all corresponding values are equal... see if one has extra values
1055863Snate@binkert.org    if len(v1) < len(v2): return -1
1065863Snate@binkert.org    if len(v1) > len(v2): return  1
107955SN/A    return 0
1085273Sstever@gmail.com
1095273Sstever@gmail.com# SCons version numbers need special processing because they can have
1105863Snate@binkert.org# charecters and an release date embedded in them. This function does
1115863Snate@binkert.org# the magic to extract them in a similar way to the SCons internal function
1125863Snate@binkert.org# function does and then checks that the current version is not contained in
1135863Snate@binkert.org# a list of version tuples (bad_ver_strs)
1145863Snate@binkert.orgdef CheckSCons(bad_ver_strs):
1155863Snate@binkert.org    def scons_ver(v):
1165227Ssaidi@eecs.umich.edu        num_parts = v.split(' ')[0].split('.')
1175396Ssaidi@eecs.umich.edu        major = int(num_parts[0])
1185396Ssaidi@eecs.umich.edu        minor = int(re.match('\d+', num_parts[1]).group())
1195396Ssaidi@eecs.umich.edu        rev = 0
1205396Ssaidi@eecs.umich.edu        rdate = 0
1215396Ssaidi@eecs.umich.edu        if len(num_parts) > 2:
1225396Ssaidi@eecs.umich.edu            try: rev = int(re.match('\d+', num_parts[2]).group())
1235396Ssaidi@eecs.umich.edu            except: pass
1245396Ssaidi@eecs.umich.edu            rev_parts = num_parts[2].split('d')
1255588Ssaidi@eecs.umich.edu            if len(rev_parts) > 1:
1265396Ssaidi@eecs.umich.edu                rdate = int(re.match('\d+', rev_parts[1]).group())
1275396Ssaidi@eecs.umich.edu
1285396Ssaidi@eecs.umich.edu        return (major, minor, rev, rdate)
1295396Ssaidi@eecs.umich.edu
1305396Ssaidi@eecs.umich.edu    sc_ver = scons_ver(SCons.__version__)
1315396Ssaidi@eecs.umich.edu    for bad_ver in bad_ver_strs:
1325396Ssaidi@eecs.umich.edu        bv = (scons_ver(bad_ver[0]), scons_ver(bad_ver[1]))
1335396Ssaidi@eecs.umich.edu        if  compare_versions(sc_ver, bv[0]) != -1 and\
1345396Ssaidi@eecs.umich.edu            compare_versions(sc_ver, bv[1]) != 1:
1355396Ssaidi@eecs.umich.edu            print "The version of SCons that you have installed: ", SCons.__version__
1365396Ssaidi@eecs.umich.edu            print "has a bug that prevents it from working correctly with M5."
1375396Ssaidi@eecs.umich.edu            print "Please install a version NOT contained within the following",
1385396Ssaidi@eecs.umich.edu            print "ranges (inclusive):"
1395396Ssaidi@eecs.umich.edu            for bad_ver in bad_ver_strs:
140955SN/A                print "    %s - %s" % bad_ver
141955SN/A            Exit(2)
142955SN/A
1433717Sstever@eecs.umich.eduCheckSCons(( 
1443716Sstever@eecs.umich.edu    # We need a version that is 0.96.91 or newer
145955SN/A    ('0.0.0', '0.96.90'), 
1461533SN/A    # This range has a bug with linking directories into the build dir
1473716Sstever@eecs.umich.edu    # that only have header files in them 
1481533SN/A    ('0.97.0d20071212', '0.98.0')
1495863Snate@binkert.org    ))
1505863Snate@binkert.org
1515863Snate@binkert.org
1525863Snate@binkert.org# The absolute path to the current directory (where this file lives).
1535863Snate@binkert.orgROOT = Dir('.').abspath
1545863Snate@binkert.org
1555863Snate@binkert.org# Path to the M5 source tree.
1565863Snate@binkert.orgSRCDIR = joinpath(ROOT, 'src')
1575863Snate@binkert.org
1585863Snate@binkert.org# tell python where to find m5 python code
1595863Snate@binkert.orgsys.path.append(joinpath(ROOT, 'src/python'))
1605863Snate@binkert.org
1615863Snate@binkert.orgdef check_style_hook(ui):
1625863Snate@binkert.org    ui.readconfig(joinpath(ROOT, '.hg', 'hgrc'))
1635863Snate@binkert.org    style_hook = ui.config('hooks', 'pretxncommit.style', None)
1645863Snate@binkert.org
1655863Snate@binkert.org    if not style_hook:
1665863Snate@binkert.org        print """\
1675863Snate@binkert.orgYou're missing the M5 style hook.
1684678Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style.
1694678Snate@binkert.org
1704678Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc
1714678Snate@binkert.orgor your personal .hgrc
1724678Snate@binkert.org----------------
1734678Snate@binkert.org
1744678Snate@binkert.org[extensions]
1754678Snate@binkert.orgstyle = %s/util/style.py
1764678Snate@binkert.org
1774678Snate@binkert.org[hooks]
1784678Snate@binkert.orgpretxncommit.style = python:style.check_whitespace
1794678Snate@binkert.org""" % (ROOT)
1804678Snate@binkert.org        sys.exit(1)
1814678Snate@binkert.org
1824678Snate@binkert.orgif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')):
1834678Snate@binkert.org    try:
1844678Snate@binkert.org        from mercurial import ui
1854678Snate@binkert.org        check_style_hook(ui.ui())
1864678Snate@binkert.org    except ImportError:
1874678Snate@binkert.org        pass
1884678Snate@binkert.org
1894973Ssaidi@eecs.umich.edu###################################################
1904678Snate@binkert.org#
1914678Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
1924678Snate@binkert.org# the target(s).
1934678Snate@binkert.org#
1944678Snate@binkert.org###################################################
1954678Snate@binkert.org
1965863Snate@binkert.org# Find default configuration & binary.
197955SN/ADefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
198955SN/A
1992632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
2002632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
201955SN/A    for i in range(len(l)+offs, 0, -1):
202955SN/A        if l[i] == elt:
203955SN/A            return i
204955SN/A    raise ValueError, "element not found"
2055863Snate@binkert.org
206955SN/A# Each target must have 'build' in the interior of the path; the
2072632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
2082632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
2092632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
2102632Sstever@eecs.umich.edu# follow 'build' in the bulid path.
2112632Sstever@eecs.umich.edu
2122632Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is
2132632Sstever@eecs.umich.eduif COMMAND_LINE_TARGETS:
2142632Sstever@eecs.umich.edu    # Ask SCons which directory it was invoked from
2152632Sstever@eecs.umich.edu    launch_dir = GetLaunchDir()
2162632Sstever@eecs.umich.edu    # Make targets relative to invocation directory
2172632Sstever@eecs.umich.edu    abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))),
2182632Sstever@eecs.umich.edu                      COMMAND_LINE_TARGETS)
2192632Sstever@eecs.umich.eduelse:
2203718Sstever@eecs.umich.edu    # Default targets are relative to root of tree
2213718Sstever@eecs.umich.edu    abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))),
2223718Sstever@eecs.umich.edu                      DEFAULT_TARGETS)
2233718Sstever@eecs.umich.edu
2243718Sstever@eecs.umich.edu
2255863Snate@binkert.org# Generate a list of the unique build roots and configs that the
2265863Snate@binkert.org# collected targets reference.
2273718Sstever@eecs.umich.edubuild_paths = []
2283718Sstever@eecs.umich.edubuild_root = None
2295863Snate@binkert.orgfor t in abs_targets:
2305863Snate@binkert.org    path_dirs = t.split('/')
2313718Sstever@eecs.umich.edu    try:
2323718Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
2332634Sstever@eecs.umich.edu    except:
2342634Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
2355863Snate@binkert.org        Exit(1)
2362638Sstever@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
2372632Sstever@eecs.umich.edu    if not build_root:
2382632Sstever@eecs.umich.edu        build_root = this_build_root
2392632Sstever@eecs.umich.edu    else:
2402632Sstever@eecs.umich.edu        if this_build_root != build_root:
2412632Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
2422632Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
2431858SN/A            Exit(1)
2443716Sstever@eecs.umich.edu    build_path = joinpath('/',*path_dirs[:build_top+2])
2452638Sstever@eecs.umich.edu    if build_path not in build_paths:
2462638Sstever@eecs.umich.edu        build_paths.append(build_path)
2472638Sstever@eecs.umich.edu
2482638Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there)
2492638Sstever@eecs.umich.eduif not isdir(build_root):
2502638Sstever@eecs.umich.edu    os.mkdir(build_root)
2512638Sstever@eecs.umich.edu
2525863Snate@binkert.org###################################################
2535863Snate@binkert.org#
2545863Snate@binkert.org# Set up the default build environment.  This environment is copied
255955SN/A# and modified according to each selected configuration.
2565341Sstever@gmail.com#
2575341Sstever@gmail.com###################################################
2585863Snate@binkert.org
2595341Sstever@gmail.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
260955SN/A                  ROOT = ROOT,
261955SN/A                  SRCDIR = SRCDIR)
262955SN/A
263955SN/AExport('env')
264955SN/A
265955SN/Aenv.SConsignFile(joinpath(build_root,"sconsign"))
266955SN/A
2675863Snate@binkert.org# Default duplicate option is to use hard links, but this messes up
2681858SN/A# when you use emacs to edit a file in the target dir, as emacs moves
2695863Snate@binkert.org# file to file~ then copies to file, breaking the link.  Symbolic
2705863Snate@binkert.org# (soft) links work better.
271955SN/Aenv.SetOption('duplicate', 'soft-copy')
2724494Ssaidi@eecs.umich.edu
2734494Ssaidi@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but
2745863Snate@binkert.org# unnecessary builds, but it also seems to make trivial builds take
2751105SN/A# noticeably longer.
2762667Sstever@eecs.umich.eduif False:
2772667Sstever@eecs.umich.edu    env.TargetSignatures('content')
2782667Sstever@eecs.umich.edu
2792667Sstever@eecs.umich.edu#
2802667Sstever@eecs.umich.edu# Set up global sticky options... these are common to an entire build
2812667Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE)
2825341Sstever@gmail.com#
2835863Snate@binkert.org
2845341Sstever@gmail.com# Option validators & converters for global sticky options
2855341Sstever@gmail.comdef PathListMakeAbsolute(val):
2865341Sstever@gmail.com    if not val:
2875863Snate@binkert.org        return val
2885341Sstever@gmail.com    f = lambda p: os.path.abspath(os.path.expanduser(p))
2895341Sstever@gmail.com    return ':'.join(map(f, val.split(':')))
2905341Sstever@gmail.com
2915863Snate@binkert.orgdef PathListAllExist(key, val, env):
2925341Sstever@gmail.com    if not val:
2935341Sstever@gmail.com        return
2945341Sstever@gmail.com    paths = val.split(':')
2955341Sstever@gmail.com    for path in paths:
2965341Sstever@gmail.com        if not isdir(path):
2975341Sstever@gmail.com            raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
2985341Sstever@gmail.com
2995341Sstever@gmail.comglobal_sticky_opts_file = joinpath(build_root, 'options.global')
3005341Sstever@gmail.com
3015341Sstever@gmail.comglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS)
3025863Snate@binkert.org
3035341Sstever@gmail.comglobal_sticky_opts.AddOptions(
3045863Snate@binkert.org    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
3055341Sstever@gmail.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
3065863Snate@binkert.org    ('EXTRAS', 'Add Extra directories to the compilation', '',
3075863Snate@binkert.org     PathListAllExist, PathListMakeAbsolute)
3085863Snate@binkert.org    )    
3095397Ssaidi@eecs.umich.edu
3105397Ssaidi@eecs.umich.edu
3115341Sstever@gmail.com# base help text
3125341Sstever@gmail.comhelp_text = '''
3135341Sstever@gmail.comUsage: scons [scons options] [build options] [target(s)]
3145341Sstever@gmail.com
3155341Sstever@gmail.com'''
3165341Sstever@gmail.com
3175341Sstever@gmail.comhelp_text += "Global sticky options:\n" \
3185341Sstever@gmail.com             + global_sticky_opts.GenerateHelpText(env)
3195863Snate@binkert.org
3205341Sstever@gmail.com# Update env with values from ARGUMENTS & file global_sticky_opts_file
3215341Sstever@gmail.comglobal_sticky_opts.Update(env)
3225863Snate@binkert.org
3235341Sstever@gmail.com# Save sticky option settings back to current options file
3245863Snate@binkert.orgglobal_sticky_opts.Save(global_sticky_opts_file, env)
3255863Snate@binkert.org
3265341Sstever@gmail.com# Parse EXTRAS option to build list of all directories where we're
3275863Snate@binkert.org# look for sources etc.  This list is exported as base_dir_list.
3285863Snate@binkert.orgbase_dir_list = [joinpath(ROOT, 'src')]
3295341Sstever@gmail.comif env['EXTRAS']:
3305863Snate@binkert.org    base_dir_list += env['EXTRAS'].split(':')
3315341Sstever@gmail.com
3325742Snate@binkert.orgExport('base_dir_list')
3335341Sstever@gmail.com
3345742Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package.
3355742Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) })
3365742Snate@binkert.orgenv['GCC'] = False
3375341Sstever@gmail.comenv['SUNCC'] = False
3385742Snate@binkert.orgenv['ICC'] = False
3395742Snate@binkert.orgenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True,
3405341Sstever@gmail.com        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3412632Sstever@eecs.umich.edu        close_fds=True).communicate()[0].find('GCC') >= 0
3425199Sstever@gmail.comenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
3435863Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3445863Snate@binkert.org        close_fds=True).communicate()[0].find('Sun C++') >= 0
3455863Snate@binkert.orgenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
3463942Ssaidi@eecs.umich.edu        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3473940Ssaidi@eecs.umich.edu        close_fds=True).communicate()[0].find('Intel') >= 0
3483918Ssaidi@eecs.umich.eduif env['GCC'] + env['SUNCC'] + env['ICC'] > 1:
3493918Ssaidi@eecs.umich.edu    print 'Error: How can we have two at the same time?'
3501858SN/A    Exit(1)
3513918Ssaidi@eecs.umich.edu
3523918Ssaidi@eecs.umich.edu
3533918Ssaidi@eecs.umich.edu# Set up default C++ compiler flags
3543918Ssaidi@eecs.umich.eduif env['GCC']:
3555571Snate@binkert.org    env.Append(CCFLAGS='-pipe')
3563940Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-fno-strict-aliasing')
3573940Ssaidi@eecs.umich.edu    env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
3583918Ssaidi@eecs.umich.eduelif env['ICC']:
3593918Ssaidi@eecs.umich.edu    pass #Fix me... add warning flags once we clean up icc warnings
3603918Ssaidi@eecs.umich.eduelif env['SUNCC']:
3613918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-Qoption ccfe')
3623918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-features=gcc')
3633918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-features=extensions')
3643918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-library=stlport4')
3653918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-xar')
3663918Ssaidi@eecs.umich.edu#    env.Append(CCFLAGS='-instances=semiexplicit')
3673940Ssaidi@eecs.umich.eduelse:
3683918Ssaidi@eecs.umich.edu    print 'Error: Don\'t know what compiler options to use for your compiler.'
3693918Ssaidi@eecs.umich.edu    print '       Please fix SConstruct and src/SConscript and try again.'
3705397Ssaidi@eecs.umich.edu    Exit(1)
3715397Ssaidi@eecs.umich.edu
3725397Ssaidi@eecs.umich.eduif sys.platform == 'cygwin':
3735708Ssaidi@eecs.umich.edu    # cygwin has some header file issues...
3745708Ssaidi@eecs.umich.edu    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
3755708Ssaidi@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')])
3765708Ssaidi@eecs.umich.edu
3775708Ssaidi@eecs.umich.edu# Check for SWIG
3785397Ssaidi@eecs.umich.eduif not env.has_key('SWIG'):
3791851SN/A    print 'Error: SWIG utility not found.'
3801851SN/A    print '       Please install (see http://www.swig.org) and retry.'
3811858SN/A    Exit(1)
3825200Sstever@gmail.com
383955SN/A# Check for appropriate SWIG version
3843053Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split()
3853053Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z"
3863053Sstever@eecs.umich.eduif len(swig_version) < 3 or \
3873053Sstever@eecs.umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
3883053Sstever@eecs.umich.edu    print 'Error determining SWIG version.'
3893053Sstever@eecs.umich.edu    Exit(1)
3903053Sstever@eecs.umich.edu
3915863Snate@binkert.orgmin_swig_version = '1.3.28'
3923053Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0:
3934742Sstever@eecs.umich.edu    print 'Error: SWIG version', min_swig_version, 'or newer required.'
3944742Sstever@eecs.umich.edu    print '       Installed version:', swig_version[2]
3953053Sstever@eecs.umich.edu    Exit(1)
3963053Sstever@eecs.umich.edu
3973053Sstever@eecs.umich.edu# Set up SWIG flags & scanner
3983053Sstever@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
3993053Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=swig_flags)
4003053Sstever@eecs.umich.edu
4013053Sstever@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency
4023053Sstever@eecs.umich.edu# stuff for some reason
4033053Sstever@eecs.umich.eduscanners = []
4042667Sstever@eecs.umich.edufor scanner in env['SCANNERS']:
4054554Sbinkertn@umich.edu    skeys = scanner.skeys
4064554Sbinkertn@umich.edu    if skeys == '.i':
4072667Sstever@eecs.umich.edu        continue
4084554Sbinkertn@umich.edu
4094554Sbinkertn@umich.edu    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
4104554Sbinkertn@umich.edu        continue
4114554Sbinkertn@umich.edu
4124554Sbinkertn@umich.edu    scanners.append(scanner)
4134554Sbinkertn@umich.edu
4144554Sbinkertn@umich.edu# add the new swig scanner that we like better
4154781Snate@binkert.orgfrom SCons.Scanner import ClassicCPP as CPPScanner
4164554Sbinkertn@umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
4174554Sbinkertn@umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
4182667Sstever@eecs.umich.edu
4194554Sbinkertn@umich.edu# replace the scanners list that has what we want
4204554Sbinkertn@umich.eduenv['SCANNERS'] = scanners
4214554Sbinkertn@umich.edu
4224554Sbinkertn@umich.edu# Platform-specific configuration.  Note again that we assume that all
4232667Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
4244554Sbinkertn@umich.educonf = Configure(env,
4252667Sstever@eecs.umich.edu                 conf_dir = joinpath(build_root, '.scons_config'),
4264554Sbinkertn@umich.edu                 log_file = joinpath(build_root, 'scons_config.log'))
4274554Sbinkertn@umich.edu
4282667Sstever@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
4295522Snate@binkert.orgtry:
4305522Snate@binkert.org    import platform
4315522Snate@binkert.org    uname = platform.uname()
4325522Snate@binkert.org    if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
4335522Snate@binkert.org        if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True,
4345522Snate@binkert.org               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
4355522Snate@binkert.org               close_fds=True).communicate()[0][0]):
4365522Snate@binkert.org            env.Append(CCFLAGS='-arch x86_64')
4375522Snate@binkert.org            env.Append(CFLAGS='-arch x86_64')
4385522Snate@binkert.org            env.Append(LINKFLAGS='-arch x86_64')
4395522Snate@binkert.org            env.Append(ASFLAGS='-arch x86_64')
4405522Snate@binkert.org            env['OSX64bit'] = True
4415522Snate@binkert.orgexcept:
4425522Snate@binkert.org    pass
4435522Snate@binkert.org
4445522Snate@binkert.org# Recent versions of scons substitute a "Null" object for Configure()
4455522Snate@binkert.org# when configuration isn't necessary, e.g., if the "--help" option is
4465522Snate@binkert.org# present.  Unfortuantely this Null object always returns false,
4475522Snate@binkert.org# breaking all our configuration checks.  We replace it with our own
4485522Snate@binkert.org# more optimistic null object that returns True instead.
4495522Snate@binkert.orgif not conf:
4505522Snate@binkert.org    def NullCheck(*args, **kwargs):
4515522Snate@binkert.org        return True
4525522Snate@binkert.org
4535522Snate@binkert.org    class NullConf:
4545522Snate@binkert.org        def __init__(self, env):
4552638Sstever@eecs.umich.edu            self.env = env
4562638Sstever@eecs.umich.edu        def Finish(self):
4572638Sstever@eecs.umich.edu            return self.env
4583716Sstever@eecs.umich.edu        def __getattr__(self, mname):
4595522Snate@binkert.org            return NullCheck
4605522Snate@binkert.org
4615522Snate@binkert.org    conf = NullConf(env)
4625522Snate@binkert.org
4635522Snate@binkert.org# Find Python include and library directories for embedding the
4645522Snate@binkert.org# interpreter.  For consistency, we will use the same Python
4651858SN/A# installation used to run scons (and thus this script).  If you want
4665227Ssaidi@eecs.umich.edu# to link in an alternate version, see above for instructions on how
4675227Ssaidi@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
4685227Ssaidi@eecs.umich.edu
4695227Ssaidi@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating
4705227Ssaidi@eecs.umich.edu# include & library files
4715863Snate@binkert.orgpy_version_name = 'python' + sys.version[:3]
4725227Ssaidi@eecs.umich.edu
4735227Ssaidi@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4
4745227Ssaidi@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name)
4755227Ssaidi@eecs.umich.eduenv.Append(CPPPATH = py_header_path)
4765227Ssaidi@eecs.umich.edu# verify that it works
4775227Ssaidi@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
4785227Ssaidi@eecs.umich.edu    print "Error: can't find Python.h header in", py_header_path
4795204Sstever@gmail.com    Exit(1)
4805204Sstever@gmail.com
4815204Sstever@gmail.com# add library path too if it's not in the default place
4825204Sstever@gmail.compy_lib_path = None
4835204Sstever@gmail.comif sys.exec_prefix != '/usr':
4845204Sstever@gmail.com    py_lib_path = joinpath(sys.exec_prefix, 'lib')
4855204Sstever@gmail.comelif sys.platform == 'cygwin':
4865204Sstever@gmail.com    # cygwin puts the .dll in /bin for some reason
4875204Sstever@gmail.com    py_lib_path = '/bin'
4885204Sstever@gmail.comif py_lib_path:
4895204Sstever@gmail.com    env.Append(LIBPATH = py_lib_path)
4905204Sstever@gmail.com    print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
4915204Sstever@gmail.comif not conf.CheckLib(py_version_name):
4925204Sstever@gmail.com    print "Error: can't find Python library", py_version_name
4935204Sstever@gmail.com    Exit(1)
4945204Sstever@gmail.com
4955204Sstever@gmail.com# On Solaris you need to use libsocket for socket ops
4965204Sstever@gmail.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4975204Sstever@gmail.com   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4983118Sstever@eecs.umich.edu       print "Can't find library with socket calls (e.g. accept())"
4993118Sstever@eecs.umich.edu       Exit(1)
5003118Sstever@eecs.umich.edu
5013118Sstever@eecs.umich.edu# Check for zlib.  If the check passes, libz will be automatically
5023118Sstever@eecs.umich.edu# added to the LIBS environment variable.
5035863Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
5043118Sstever@eecs.umich.edu    print 'Error: did not find needed zlib compression library '\
5055863Snate@binkert.org          'and/or zlib.h header file.'
5063118Sstever@eecs.umich.edu    print '       Please install zlib and try again.'
5075863Snate@binkert.org    Exit(1)
5085863Snate@binkert.org
5095863Snate@binkert.org# Check for <fenv.h> (C99 FP environment control)
5105863Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>')
5115863Snate@binkert.orgif not have_fenv:
5125863Snate@binkert.org    print "Warning: Header file <fenv.h> not found."
5135863Snate@binkert.org    print "         This host has no IEEE FP rounding mode control."
5145863Snate@binkert.org
5155863Snate@binkert.org# Check for mysql.
5165863Snate@binkert.orgmysql_config = WhereIs('mysql_config')
5175863Snate@binkert.orghave_mysql = mysql_config != None
5185863Snate@binkert.org
5195863Snate@binkert.org# Check MySQL version.
5205863Snate@binkert.orgif have_mysql:
5215863Snate@binkert.org    mysql_version = os.popen(mysql_config + ' --version').read()
5225863Snate@binkert.org    min_mysql_version = '4.1'
5235863Snate@binkert.org    if compare_versions(mysql_version, min_mysql_version) < 0:
5245863Snate@binkert.org        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
5255863Snate@binkert.org        print '         Version', mysql_version, 'detected.'
5265863Snate@binkert.org        have_mysql = False
5275863Snate@binkert.org
5285863Snate@binkert.org# Set up mysql_config commands.
5295863Snate@binkert.orgif have_mysql:
5305863Snate@binkert.org    mysql_config_include = mysql_config + ' --include'
5315863Snate@binkert.org    if os.system(mysql_config_include + ' > /dev/null') != 0:
5323118Sstever@eecs.umich.edu        # older mysql_config versions don't support --include, use
5335863Snate@binkert.org        # --cflags instead
5343118Sstever@eecs.umich.edu        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
5353118Sstever@eecs.umich.edu    # This seems to work in all versions
5365863Snate@binkert.org    mysql_config_libs = mysql_config + ' --libs'
5375863Snate@binkert.org
5385863Snate@binkert.orgenv = conf.Finish()
5395863Snate@binkert.org
5405863Snate@binkert.org# Define the universe of supported ISAs
5415863Snate@binkert.orgall_isa_list = [ ]
5423118Sstever@eecs.umich.eduExport('all_isa_list')
5433483Ssaidi@eecs.umich.edu
5443494Ssaidi@eecs.umich.edu# Define the universe of supported CPU models
5453494Ssaidi@eecs.umich.eduall_cpu_list = [ ]
5463483Ssaidi@eecs.umich.edudefault_cpus = [ ]
5473483Ssaidi@eecs.umich.eduExport('all_cpu_list', 'default_cpus')
5483483Ssaidi@eecs.umich.edu
5493053Sstever@eecs.umich.edu# Sticky options get saved in the options file so they persist from
5503053Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
5513918Ssaidi@eecs.umich.edu# value becomes sticky).
5523053Sstever@eecs.umich.edusticky_opts = Options(args=ARGUMENTS)
5533053Sstever@eecs.umich.eduExport('sticky_opts')
5543053Sstever@eecs.umich.edu
5553053Sstever@eecs.umich.edu# Non-sticky options only apply to the current build.
5563053Sstever@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS)
5571858SN/AExport('nonsticky_opts')
5581858SN/A
5591858SN/A# Walk the tree and execute all SConsopts scripts that wil add to the
5601858SN/A# above options
5611858SN/Afor base_dir in base_dir_list:
5621858SN/A    for root, dirs, files in os.walk(base_dir):
5635863Snate@binkert.org        if 'SConsopts' in files:
5645863Snate@binkert.org            print "Reading", joinpath(root, 'SConsopts')
5651859SN/A            SConscript(joinpath(root, 'SConsopts'))
5665863Snate@binkert.org
5671858SN/Aall_isa_list.sort()
5685863Snate@binkert.orgall_cpu_list.sort()
5691858SN/Adefault_cpus.sort()
5701859SN/A
5711859SN/Asticky_opts.AddOptions(
5725863Snate@binkert.org    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
5733053Sstever@eecs.umich.edu    BoolOption('FULL_SYSTEM', 'Full-system support', False),
5743053Sstever@eecs.umich.edu    # There's a bug in scons 0.96.1 that causes ListOptions with list
5753053Sstever@eecs.umich.edu    # values (more than one value) not to be able to be restored from
5763053Sstever@eecs.umich.edu    # a saved option file.  If this causes trouble then upgrade to
5771859SN/A    # scons 0.96.90 or later.
5781859SN/A    ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
5791859SN/A    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
5801859SN/A    BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
5811859SN/A               False),
5821859SN/A    BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
5831859SN/A               False),
5841859SN/A    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
5851862SN/A               False),
5861859SN/A    BoolOption('SS_COMPATIBLE_FP',
5871859SN/A               'Make floating-point results compatible with SimpleScalar',
5881859SN/A               False),
5895863Snate@binkert.org    BoolOption('USE_SSE2',
5905863Snate@binkert.org               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
5915863Snate@binkert.org               False),
5925863Snate@binkert.org    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
5931858SN/A    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
5941858SN/A    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
5955863Snate@binkert.org    BoolOption('BATCH', 'Use batch pool for build and tests', False),
5965863Snate@binkert.org    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
5975863Snate@binkert.org    ('PYTHONHOME',
5985863Snate@binkert.org     'Override the default PYTHONHOME for this system (use with caution)',
5995863Snate@binkert.org     '%s:%s' % (sys.prefix, sys.exec_prefix)),
6002139SN/A    )
6014202Sbinkertn@umich.edu
6024202Sbinkertn@umich.edunonsticky_opts.AddOptions(
6032139SN/A    BoolOption('update_ref', 'Update test reference outputs', False)
6042155SN/A    )
6054202Sbinkertn@umich.edu
6064202Sbinkertn@umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript).
6074202Sbinkertn@umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
6082155SN/A                     'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \
6095863Snate@binkert.org                     'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \
6101869SN/A                     'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
6111869SN/A
6125863Snate@binkert.org# Define a handy 'no-op' action
6135863Snate@binkert.orgdef no_action(target, source, env):
6144202Sbinkertn@umich.edu    return 0
6155863Snate@binkert.org
6165863Snate@binkert.orgenv.NoAction = Action(no_action, None)
6175863Snate@binkert.org
6184202Sbinkertn@umich.edu###################################################
6194202Sbinkertn@umich.edu#
6205863Snate@binkert.org# Define a SCons builder for configuration flag headers.
6215742Snate@binkert.org#
6225742Snate@binkert.org###################################################
6235341Sstever@gmail.com
6245342Sstever@gmail.com# This function generates a config header file that #defines the
6255342Sstever@gmail.com# option symbol to the current option setting (0 or 1).  The source
6264202Sbinkertn@umich.edu# operands are the name of the option and a Value node containing the
6274202Sbinkertn@umich.edu# value of the option.
6284202Sbinkertn@umich.edudef build_config_file(target, source, env):
6294202Sbinkertn@umich.edu    (option, value) = [s.get_contents() for s in source]
6304202Sbinkertn@umich.edu    f = file(str(target[0]), 'w')
6315863Snate@binkert.org    print >> f, '#define', option, value
6325863Snate@binkert.org    f.close()
6335863Snate@binkert.org    return None
6345863Snate@binkert.org
6355863Snate@binkert.org# Generate the message to be printed when building the config file.
6365863Snate@binkert.orgdef build_config_file_string(target, source, env):
6375863Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
6385863Snate@binkert.org    return "Defining %s as %s in %s." % (option, value, target[0])
6395863Snate@binkert.org
6405863Snate@binkert.org# Combine the two functions into a scons Action object.
6415863Snate@binkert.orgconfig_action = Action(build_config_file, build_config_file_string)
6425863Snate@binkert.org
6435863Snate@binkert.org# The emitter munges the source & target node lists to reflect what
6445863Snate@binkert.org# we're really doing.
6455863Snate@binkert.orgdef config_emitter(target, source, env):
6465863Snate@binkert.org    # extract option name from Builder arg
6475863Snate@binkert.org    option = str(target[0])
6485863Snate@binkert.org    # True target is config header file
6495863Snate@binkert.org    target = joinpath('config', option.lower() + '.hh')
6505863Snate@binkert.org    val = env[option]
6511869SN/A    if isinstance(val, bool):
6521858SN/A        # Force value to 0/1
6535863Snate@binkert.org        val = int(val)
6545863Snate@binkert.org    elif isinstance(val, str):
6551869SN/A        val = '"' + val + '"'
6561858SN/A
6575863Snate@binkert.org    # Sources are option name & value (packaged in SCons Value nodes)
6585863Snate@binkert.org    return ([target], [Value(option), Value(val)])
6595863Snate@binkert.org
6605863Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action)
6615863Snate@binkert.org
6621858SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
663955SN/A
664955SN/A###################################################
6651869SN/A#
6661869SN/A# Define a SCons builder for copying files.  This is used by the
6671869SN/A# Python zipfile code in src/python/SConscript, but is placed up here
6681869SN/A# since it's potentially more generally applicable.
6691869SN/A#
6705863Snate@binkert.org###################################################
6715863Snate@binkert.org
6725863Snate@binkert.orgcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
6731869SN/A
6745863Snate@binkert.orgenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
6751869SN/A
6765863Snate@binkert.org###################################################
6771869SN/A#
6781869SN/A# Define a simple SCons builder to concatenate files.
6791869SN/A#
6801869SN/A# Used to append the Python zip archive to the executable.
6811869SN/A#
6825863Snate@binkert.org###################################################
6835863Snate@binkert.org
6841869SN/Aconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
6851869SN/A                                          'chmod +x $TARGET']))
6861869SN/A
6871869SN/Aenv.Append(BUILDERS = { 'Concat' : concat_builder })
6881869SN/A
6891869SN/A
6901869SN/A# libelf build is shared across all configs in the build root.
6915863Snate@binkert.orgenv.SConscript('ext/libelf/SConscript',
6925863Snate@binkert.org               build_dir = joinpath(build_root, 'libelf'),
6931869SN/A               exports = 'env')
6945863Snate@binkert.org
6955863Snate@binkert.org###################################################
6963356Sbinkertn@umich.edu#
6973356Sbinkertn@umich.edu# This function is used to set up a directory with switching headers
6983356Sbinkertn@umich.edu#
6993356Sbinkertn@umich.edu###################################################
7003356Sbinkertn@umich.edu
7014781Snate@binkert.orgenv['ALL_ISA_LIST'] = all_isa_list
7025863Snate@binkert.orgdef make_switching_dir(dirname, switch_headers, env):
7035863Snate@binkert.org    # Generate the header.  target[0] is the full path of the output
7041869SN/A    # header to generate.  'source' is a dummy variable, since we get the
7051869SN/A    # list of ISAs from env['ALL_ISA_LIST'].
7061869SN/A    def gen_switch_hdr(target, source, env):
7071869SN/A        fname = str(target[0])
7081869SN/A        basename = os.path.basename(fname)
7092638Sstever@eecs.umich.edu        f = open(fname, 'w')
7102638Sstever@eecs.umich.edu        f.write('#include "arch/isa_specific.hh"\n')
7115863Snate@binkert.org        cond = '#if'
7122638Sstever@eecs.umich.edu        for isa in all_isa_list:
7132638Sstever@eecs.umich.edu            f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
7145749Scws3k@cs.virginia.edu                    % (cond, isa.upper(), dirname, isa, basename))
7155749Scws3k@cs.virginia.edu            cond = '#elif'
7165863Snate@binkert.org        f.write('#else\n#error "THE_ISA not set"\n#endif\n')
7175749Scws3k@cs.virginia.edu        f.close()
7185749Scws3k@cs.virginia.edu        return 0
7191869SN/A
7201869SN/A    # String to print when generating header
7213546Sgblack@eecs.umich.edu    def gen_switch_hdr_string(target, source, env):
7223546Sgblack@eecs.umich.edu        return "Generating switch header " + str(target[0])
7233546Sgblack@eecs.umich.edu
7243546Sgblack@eecs.umich.edu    # Build SCons Action object. 'varlist' specifies env vars that this
7254202Sbinkertn@umich.edu    # action depends on; when env['ALL_ISA_LIST'] changes these actions
7265863Snate@binkert.org    # should get re-executed.
7273546Sgblack@eecs.umich.edu    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
7283546Sgblack@eecs.umich.edu                               varlist=['ALL_ISA_LIST'])
7293546Sgblack@eecs.umich.edu
7303546Sgblack@eecs.umich.edu    # Instantiate actions for each header
7314781Snate@binkert.org    for hdr in switch_headers:
7325863Snate@binkert.org        env.Command(hdr, [], switch_hdr_action)
7334781Snate@binkert.orgExport('make_switching_dir')
7344781Snate@binkert.org
7354781Snate@binkert.org###################################################
7364781Snate@binkert.org#
7374781Snate@binkert.org# Define build environments for selected configurations.
7385863Snate@binkert.org#
7394781Snate@binkert.org###################################################
7404781Snate@binkert.org
7414781Snate@binkert.org# rename base env
7424781Snate@binkert.orgbase_env = env
7433546Sgblack@eecs.umich.edu
7443546Sgblack@eecs.umich.edufor build_path in build_paths:
7453546Sgblack@eecs.umich.edu    print "Building in", build_path
7464781Snate@binkert.org
7473546Sgblack@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
7483546Sgblack@eecs.umich.edu    env = base_env.Copy()
7493546Sgblack@eecs.umich.edu    env['BUILDDIR'] = build_path
7503546Sgblack@eecs.umich.edu
7513546Sgblack@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
7523546Sgblack@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
7533546Sgblack@eecs.umich.edu    (build_root, build_dir) = os.path.split(build_path)
7543546Sgblack@eecs.umich.edu
7553546Sgblack@eecs.umich.edu    # Set env options according to the build directory config.
7563546Sgblack@eecs.umich.edu    sticky_opts.files = []
7574202Sbinkertn@umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
7583546Sgblack@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
7593546Sgblack@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
7603546Sgblack@eecs.umich.edu    current_opts_file = joinpath(build_root, 'options', build_dir)
761955SN/A    if isfile(current_opts_file):
762955SN/A        sticky_opts.files.append(current_opts_file)
763955SN/A        print "Using saved options file %s" % current_opts_file
764955SN/A    else:
7651858SN/A        # Build dir-specific options file doesn't exist.
7661858SN/A
7671858SN/A        # Make sure the directory is there so we can create it later
7685863Snate@binkert.org        opt_dir = os.path.dirname(current_opts_file)
7695863Snate@binkert.org        if not isdir(opt_dir):
7705343Sstever@gmail.com            os.mkdir(opt_dir)
7715343Sstever@gmail.com
7725863Snate@binkert.org        # Get default build options from source tree.  Options are
7735863Snate@binkert.org        # normally determined by name of $BUILD_DIR, but can be
7744773Snate@binkert.org        # overriden by 'default=' arg on command line.
7755863Snate@binkert.org        default_opts_file = joinpath('build_opts',
7762632Sstever@eecs.umich.edu                                     ARGUMENTS.get('default', build_dir))
7775863Snate@binkert.org        if isfile(default_opts_file):
7782023SN/A            sticky_opts.files.append(default_opts_file)
7795863Snate@binkert.org            print "Options file %s not found,\n  using defaults in %s" \
7805863Snate@binkert.org                  % (current_opts_file, default_opts_file)
7815863Snate@binkert.org        else:
7825863Snate@binkert.org            print "Error: cannot find options file %s or %s" \
7835863Snate@binkert.org                  % (current_opts_file, default_opts_file)
7845863Snate@binkert.org            Exit(1)
7855863Snate@binkert.org
7865863Snate@binkert.org    # Apply current option settings to env
7875863Snate@binkert.org    sticky_opts.Update(env)
7882632Sstever@eecs.umich.edu    nonsticky_opts.Update(env)
7895863Snate@binkert.org
7902023SN/A    help_text += "\nSticky options for %s:\n" % build_dir \
7912632Sstever@eecs.umich.edu                 + sticky_opts.GenerateHelpText(env) \
7925863Snate@binkert.org                 + "\nNon-sticky options for %s:\n" % build_dir \
7935342Sstever@gmail.com                 + nonsticky_opts.GenerateHelpText(env)
7945863Snate@binkert.org
7952632Sstever@eecs.umich.edu    # Process option settings.
7965863Snate@binkert.org
7975863Snate@binkert.org    if not have_fenv and env['USE_FENV']:
7982632Sstever@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
7995863Snate@binkert.org              "forcing USE_FENV to False in", build_dir + "."
8005863Snate@binkert.org        env['USE_FENV'] = False
8015863Snate@binkert.org
8025863Snate@binkert.org    if not env['USE_FENV']:
8035863Snate@binkert.org        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
8045863Snate@binkert.org        print "         FP results may deviate slightly from other platforms."
8052632Sstever@eecs.umich.edu
8065863Snate@binkert.org    if env['EFENCE']:
8075863Snate@binkert.org        env.Append(LIBS=['efence'])
8082632Sstever@eecs.umich.edu
8091888SN/A    if env['USE_MYSQL']:
8105863Snate@binkert.org        if not have_mysql:
8115863Snate@binkert.org            print "Warning: MySQL not available; " \
8125863Snate@binkert.org                  "forcing USE_MYSQL to False in", build_dir + "."
8131858SN/A            env['USE_MYSQL'] = False
8145863Snate@binkert.org        else:
8155863Snate@binkert.org            print "Compiling in", build_dir, "with MySQL support."
8165863Snate@binkert.org            env.ParseConfig(mysql_config_libs)
8175863Snate@binkert.org            env.ParseConfig(mysql_config_include)
8182598SN/A
8195863Snate@binkert.org    # Save sticky option settings back to current options file
8201858SN/A    sticky_opts.Save(current_opts_file, env)
8211858SN/A
8221858SN/A    # Do this after we save setting back, or else we'll tack on an
8235863Snate@binkert.org    # extra 'qdo' every time we run scons.
8241858SN/A    if env['BATCH']:
8251858SN/A        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
8261858SN/A        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
8275863Snate@binkert.org
8281871SN/A    if env['USE_SSE2']:
8291858SN/A        env.Append(CCFLAGS='-msse2')
8301858SN/A
8311858SN/A    # The src/SConscript file sets up the build rules in 'env' according
8321858SN/A    # to the configured options.  It returns a list of environments,
8331858SN/A    # one for each variant build (debug, opt, etc.)
8341858SN/A    envList = SConscript('src/SConscript', build_dir = build_path,
8351858SN/A                         exports = 'env')
8365863Snate@binkert.org
8371858SN/A    # Set up the regression tests for each build.
8381858SN/A    for e in envList:
8395863Snate@binkert.org        SConscript('tests/SConscript',
8401859SN/A                   build_dir = joinpath(build_path, 'tests', e.Label),
8411859SN/A                   exports = { 'env' : e }, duplicate = False)
8421869SN/A
8435863Snate@binkert.orgHelp(help_text)
8445863Snate@binkert.org
8451869SN/A
8461965SN/A###################################################
8471965SN/A#
8481965SN/A# Let SCons do its thing.  At this point SCons will use the defined
8492761Sstever@eecs.umich.edu# build environments to build the requested targets.
8505863Snate@binkert.org#
8511869SN/A###################################################
8525863Snate@binkert.org
8532667Sstever@eecs.umich.edu