SConstruct revision 5341
1955SN/A# -*- mode:python -*-
2955SN/A
35871Snate@binkert.org# Copyright (c) 2004-2005 The Regents of The University of Michigan
41762SN/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.
28955SN/A#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
302665Ssaidi@eecs.umich.edu
315863Snate@binkert.org###################################################
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
36955SN/A# 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#
402632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a
41955SN/A# '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
432632Sstever@eecs.umich.edu# built for the same host system.
442761Sstever@eecs.umich.edu#
452632Sstever@eecs.umich.edu# Examples:
462632Sstever@eecs.umich.edu#
472632Sstever@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
502761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512632Sstever@eecs.umich.edu#
522632Sstever@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
572761Sstever@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#
642632Sstever@eecs.umich.edu###################################################
65955SN/A
66955SN/Aimport sys
67955SN/Aimport os
685863Snate@binkert.org
695863Snate@binkert.orgfrom os.path import isdir, join as joinpath
705863Snate@binkert.org
715863Snate@binkert.orgimport SCons
725863Snate@binkert.org
735863Snate@binkert.org# Check for recent-enough Python and SCons versions.  If your system's
745863Snate@binkert.org# default installation of Python is not recent enough, you can use a
755863Snate@binkert.org# non-default installation of the Python interpreter by either (1)
765863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python'
775863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the
785863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
795863Snate@binkert.orgEnsurePythonVersion(2,4)
805863Snate@binkert.org
815863Snate@binkert.org# Import subprocess after we check the version since it doesn't exist in
825863Snate@binkert.org# Python < 2.4.
835863Snate@binkert.orgimport subprocess
845863Snate@binkert.org
855863Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
865863Snate@binkert.org# 3-element version number.
875863Snate@binkert.orgmin_scons_version = (0,96,91)
885863Snate@binkert.orgtry:
895863Snate@binkert.org    EnsureSConsVersion(*min_scons_version)
905863Snate@binkert.orgexcept:
915863Snate@binkert.org    print "Error checking current SCons version."
925863Snate@binkert.org    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
935863Snate@binkert.org    Exit(2)
945863Snate@binkert.org
955863Snate@binkert.org
965863Snate@binkert.org# The absolute path to the current directory (where this file lives).
975863Snate@binkert.orgROOT = Dir('.').abspath
985863Snate@binkert.org
99955SN/A# Path to the M5 source tree.
1005396Ssaidi@eecs.umich.eduSRCDIR = joinpath(ROOT, 'src')
1015863Snate@binkert.org
1025863Snate@binkert.org# tell python where to find m5 python code
1034202Sbinkertn@umich.edusys.path.append(joinpath(ROOT, 'src/python'))
1045863Snate@binkert.org
1055863Snate@binkert.orgdef check_style_hook(ui):
1065863Snate@binkert.org    ui.readconfig(joinpath(ROOT, '.hg', 'hgrc'))
1075863Snate@binkert.org    style_hook = ui.config('hooks', 'pretxncommit.style', None)
108955SN/A
1095273Sstever@gmail.com    if not style_hook:
1105871Snate@binkert.org        print """\
1115273Sstever@gmail.comYou're missing the M5 style hook.
1125871Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style.
1135863Snate@binkert.org
1145863Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc
1155863Snate@binkert.orgor your personal .hgrc
1165871Snate@binkert.org----------------
1175872Snate@binkert.org
1185872Snate@binkert.org[extensions]
1195872Snate@binkert.orgstyle = %s/util/style.py
1205871Snate@binkert.org
1215871Snate@binkert.org[hooks]
1225871Snate@binkert.orgpretxncommit.style = python:style.check_whitespace
1235871Snate@binkert.org""" % (ROOT)
1245871Snate@binkert.org        sys.exit(1)
1255871Snate@binkert.org
1265871Snate@binkert.orgif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')):
1275871Snate@binkert.org    try:
1285871Snate@binkert.org        from mercurial import ui
1295871Snate@binkert.org        check_style_hook(ui.ui())
1305871Snate@binkert.org    except ImportError:
1315871Snate@binkert.org        pass
1325871Snate@binkert.org
1335871Snate@binkert.org###################################################
1345863Snate@binkert.org#
1355227Ssaidi@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
1365396Ssaidi@eecs.umich.edu# the target(s).
1375396Ssaidi@eecs.umich.edu#
1385396Ssaidi@eecs.umich.edu###################################################
1395396Ssaidi@eecs.umich.edu
1405396Ssaidi@eecs.umich.edu# Find default configuration & binary.
1415396Ssaidi@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1425396Ssaidi@eecs.umich.edu
1435396Ssaidi@eecs.umich.edu# helper function: find last occurrence of element in list
1445588Ssaidi@eecs.umich.edudef rfind(l, elt, offs = -1):
1455396Ssaidi@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1465396Ssaidi@eecs.umich.edu        if l[i] == elt:
1475396Ssaidi@eecs.umich.edu            return i
1485396Ssaidi@eecs.umich.edu    raise ValueError, "element not found"
1495396Ssaidi@eecs.umich.edu
1505396Ssaidi@eecs.umich.edu# helper function: compare dotted version numbers.
1515396Ssaidi@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1')
1525396Ssaidi@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2
1535396Ssaidi@eecs.umich.edudef compare_versions(v1, v2):
1545396Ssaidi@eecs.umich.edu    # Convert dotted strings to lists
1555396Ssaidi@eecs.umich.edu    v1 = map(int, v1.split('.'))
1565396Ssaidi@eecs.umich.edu    v2 = map(int, v2.split('.'))
1575396Ssaidi@eecs.umich.edu    # Compare corresponding elements of lists
1585396Ssaidi@eecs.umich.edu    for n1,n2 in zip(v1, v2):
1595871Snate@binkert.org        if n1 < n2: return -1
1605871Snate@binkert.org        if n1 > n2: return  1
1615871Snate@binkert.org    # all corresponding values are equal... see if one has extra values
1625871Snate@binkert.org    if len(v1) < len(v2): return -1
1635871Snate@binkert.org    if len(v1) > len(v2): return  1
1646003Snate@binkert.org    return 0
1656003Snate@binkert.org
166955SN/A# Each target must have 'build' in the interior of the path; the
1675871Snate@binkert.org# directory below this will determine the build parameters.  For
1685871Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1695871Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it
1705871Snate@binkert.org# follow 'build' in the bulid path.
171955SN/A
1725871Snate@binkert.org# Generate absolute paths to targets so we can see where the build dir is
1735871Snate@binkert.orgif COMMAND_LINE_TARGETS:
1745871Snate@binkert.org    # Ask SCons which directory it was invoked from
1751533SN/A    launch_dir = GetLaunchDir()
1765871Snate@binkert.org    # Make targets relative to invocation directory
1775871Snate@binkert.org    abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))),
1785863Snate@binkert.org                      COMMAND_LINE_TARGETS)
1795871Snate@binkert.orgelse:
1805871Snate@binkert.org    # Default targets are relative to root of tree
1815871Snate@binkert.org    abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))),
1825871Snate@binkert.org                      DEFAULT_TARGETS)
1835871Snate@binkert.org
1845863Snate@binkert.org
1855871Snate@binkert.org# Generate a list of the unique build roots and configs that the
1865863Snate@binkert.org# collected targets reference.
1875871Snate@binkert.orgbuild_paths = []
1884678Snate@binkert.orgbuild_root = None
1894678Snate@binkert.orgfor t in abs_targets:
1904678Snate@binkert.org    path_dirs = t.split('/')
1914678Snate@binkert.org    try:
1924678Snate@binkert.org        build_top = rfind(path_dirs, 'build', -2)
1934678Snate@binkert.org    except:
1944678Snate@binkert.org        print "Error: no non-leaf 'build' dir found on target path", t
1954678Snate@binkert.org        Exit(1)
1964678Snate@binkert.org    this_build_root = joinpath('/',*path_dirs[:build_top+1])
1974678Snate@binkert.org    if not build_root:
1984678Snate@binkert.org        build_root = this_build_root
1994678Snate@binkert.org    else:
2005871Snate@binkert.org        if this_build_root != build_root:
2014678Snate@binkert.org            print "Error: build targets not under same build root\n"\
2025871Snate@binkert.org                  "  %s\n  %s" % (build_root, this_build_root)
2035871Snate@binkert.org            Exit(1)
2045871Snate@binkert.org    build_path = joinpath('/',*path_dirs[:build_top+2])
2055871Snate@binkert.org    if build_path not in build_paths:
2065871Snate@binkert.org        build_paths.append(build_path)
2075871Snate@binkert.org
2085871Snate@binkert.org# Make sure build_root exists (might not if this is the first build there)
2095871Snate@binkert.orgif not isdir(build_root):
2105871Snate@binkert.org    os.mkdir(build_root)
2115871Snate@binkert.org
2125871Snate@binkert.org###################################################
2135871Snate@binkert.org#
2145871Snate@binkert.org# Set up the default build environment.  This environment is copied
2155990Ssaidi@eecs.umich.edu# and modified according to each selected configuration.
2165871Snate@binkert.org#
2175871Snate@binkert.org###################################################
2185871Snate@binkert.org
2194678Snate@binkert.orgenv = Environment(ENV = os.environ,  # inherit user's environment vars
2205871Snate@binkert.org                  ROOT = ROOT,
2215871Snate@binkert.org                  SRCDIR = SRCDIR)
2225871Snate@binkert.org
2235871Snate@binkert.orgExport('env')
2245871Snate@binkert.org
2255871Snate@binkert.orgenv.SConsignFile(joinpath(build_root,"sconsign"))
2265871Snate@binkert.org
2275871Snate@binkert.org# Default duplicate option is to use hard links, but this messes up
2285871Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves
2295871Snate@binkert.org# file to file~ then copies to file, breaking the link.  Symbolic
2304678Snate@binkert.org# (soft) links work better.
2315871Snate@binkert.orgenv.SetOption('duplicate', 'soft-copy')
2324678Snate@binkert.org
2335871Snate@binkert.org# I waffle on this setting... it does avoid a few painful but
2345871Snate@binkert.org# unnecessary builds, but it also seems to make trivial builds take
2355871Snate@binkert.org# noticeably longer.
2365871Snate@binkert.orgif False:
2375871Snate@binkert.org    env.TargetSignatures('content')
2385871Snate@binkert.org
2395871Snate@binkert.org#
2405871Snate@binkert.org# Set up global sticky options... these are common to an entire build
2415871Snate@binkert.org# tree (not specific to a particular build like ALPHA_SE)
2425990Ssaidi@eecs.umich.edu#
2435863Snate@binkert.org
244955SN/A# Option validators & converters for global sticky options
245955SN/Adef PathListMakeAbsolute(val):
2462632Sstever@eecs.umich.edu    if not val:
2472632Sstever@eecs.umich.edu        return val
248955SN/A    f = lambda p: os.path.abspath(os.path.expanduser(p))
249955SN/A    return ':'.join(map(f, val.split(':')))
250955SN/A
251955SN/Adef PathListAllExist(key, val, env):
2525863Snate@binkert.org    if not val:
253955SN/A        return
2542632Sstever@eecs.umich.edu    paths = val.split(':')
2552632Sstever@eecs.umich.edu    for path in paths:
2562632Sstever@eecs.umich.edu        if not isdir(path):
2572632Sstever@eecs.umich.edu            raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
2582632Sstever@eecs.umich.edu
2592632Sstever@eecs.umich.eduglobal_sticky_opts_file = joinpath(build_root, 'options.global')
2602632Sstever@eecs.umich.edu
2612632Sstever@eecs.umich.eduglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS)
2622632Sstever@eecs.umich.edu
2632632Sstever@eecs.umich.eduglobal_sticky_opts.AddOptions(
2642632Sstever@eecs.umich.edu    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2652632Sstever@eecs.umich.edu    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2662632Sstever@eecs.umich.edu    ('EXTRAS', 'Add Extra directories to the compilation', '',
2673718Sstever@eecs.umich.edu     PathListAllExist, PathListMakeAbsolute)
2683718Sstever@eecs.umich.edu    )    
2693718Sstever@eecs.umich.edu
2703718Sstever@eecs.umich.edu
2713718Sstever@eecs.umich.edu# base help text
2725863Snate@binkert.orghelp_text = '''
2735863Snate@binkert.orgUsage: scons [scons options] [build options] [target(s)]
2743718Sstever@eecs.umich.edu
2753718Sstever@eecs.umich.edu'''
2765863Snate@binkert.org
2775863Snate@binkert.orghelp_text += "Global sticky options:\n" \
2783718Sstever@eecs.umich.edu             + global_sticky_opts.GenerateHelpText(env)
2793718Sstever@eecs.umich.edu
2802634Sstever@eecs.umich.edu# Update env with values from ARGUMENTS & file global_sticky_opts_file
2812634Sstever@eecs.umich.eduglobal_sticky_opts.Update(env)
2825863Snate@binkert.org
2832638Sstever@eecs.umich.edu# Save sticky option settings back to current options file
2842632Sstever@eecs.umich.eduglobal_sticky_opts.Save(global_sticky_opts_file, env)
2852632Sstever@eecs.umich.edu
2862632Sstever@eecs.umich.edu# Parse EXTRAS option to build list of all directories where we're
2872632Sstever@eecs.umich.edu# look for sources etc.  This list is exported as base_dir_list.
2882632Sstever@eecs.umich.edubase_dir_list = [ROOT]
2892632Sstever@eecs.umich.eduif env['EXTRAS']:
2901858SN/A    base_dir_list += env['EXTRAS'].split(':')
2913716Sstever@eecs.umich.edu
2922638Sstever@eecs.umich.eduExport('base_dir_list')
2932638Sstever@eecs.umich.edu
2942638Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
2952638Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) })
2962638Sstever@eecs.umich.eduenv['GCC'] = False
2972638Sstever@eecs.umich.eduenv['SUNCC'] = False
2982638Sstever@eecs.umich.eduenv['ICC'] = False
2995863Snate@binkert.orgenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True,
3005863Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3015863Snate@binkert.org        close_fds=True).communicate()[0].find('GCC') >= 0
302955SN/Aenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
3035341Sstever@gmail.com        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3045341Sstever@gmail.com        close_fds=True).communicate()[0].find('Sun C++') >= 0
3055863Snate@binkert.orgenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
3065341Sstever@gmail.com        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3074494Ssaidi@eecs.umich.edu        close_fds=True).communicate()[0].find('Intel') >= 0
3084494Ssaidi@eecs.umich.eduif env['GCC'] + env['SUNCC'] + env['ICC'] > 1:
3095863Snate@binkert.org    print 'Error: How can we have two at the same time?'
3101105SN/A    Exit(1)
3112667Sstever@eecs.umich.edu
3122667Sstever@eecs.umich.edu
3132667Sstever@eecs.umich.edu# Set up default C++ compiler flags
3142667Sstever@eecs.umich.eduif env['GCC']:
3152667Sstever@eecs.umich.edu    env.Append(CCFLAGS='-pipe')
3162667Sstever@eecs.umich.edu    env.Append(CCFLAGS='-fno-strict-aliasing')
3175341Sstever@gmail.com    env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
3185863Snate@binkert.orgelif env['ICC']:
3195341Sstever@gmail.com    pass #Fix me... add warning flags once we clean up icc warnings
3205341Sstever@gmail.comelif env['SUNCC']:
3215341Sstever@gmail.com    env.Append(CCFLAGS='-Qoption ccfe')
3225863Snate@binkert.org    env.Append(CCFLAGS='-features=gcc')
3235341Sstever@gmail.com    env.Append(CCFLAGS='-features=extensions')
3245341Sstever@gmail.com    env.Append(CCFLAGS='-library=stlport4')
3255341Sstever@gmail.com    env.Append(CCFLAGS='-xar')
3265863Snate@binkert.org#    env.Append(CCFLAGS='-instances=semiexplicit')
3275341Sstever@gmail.comelse:
3285341Sstever@gmail.com    print 'Error: Don\'t know what compiler options to use for your compiler.'
3295341Sstever@gmail.com    print '       Please fix SConstruct and src/SConscript and try again.'
3305341Sstever@gmail.com    Exit(1)
3315341Sstever@gmail.com
3325341Sstever@gmail.comif sys.platform == 'cygwin':
3335341Sstever@gmail.com    # cygwin has some header file issues...
3345341Sstever@gmail.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
3355341Sstever@gmail.comenv.Append(CPPPATH=[Dir('ext/dnet')])
3365341Sstever@gmail.com
3375863Snate@binkert.org# Check for SWIG
3385341Sstever@gmail.comif not env.has_key('SWIG'):
3395863Snate@binkert.org    print 'Error: SWIG utility not found.'
3405341Sstever@gmail.com    print '       Please install (see http://www.swig.org) and retry.'
3415863Snate@binkert.org    Exit(1)
3425863Snate@binkert.org
3435863Snate@binkert.org# Check for appropriate SWIG version
3445397Ssaidi@eecs.umich.eduswig_version = os.popen('swig -version').read().split()
3455397Ssaidi@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z"
3465341Sstever@gmail.comif len(swig_version) < 3 or \
3475341Sstever@gmail.com        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
3485341Sstever@gmail.com    print 'Error determining SWIG version.'
3495341Sstever@gmail.com    Exit(1)
3505341Sstever@gmail.com
3515341Sstever@gmail.commin_swig_version = '1.3.28'
3525341Sstever@gmail.comif compare_versions(swig_version[2], min_swig_version) < 0:
3535341Sstever@gmail.com    print 'Error: SWIG version', min_swig_version, 'or newer required.'
3545863Snate@binkert.org    print '       Installed version:', swig_version[2]
3555341Sstever@gmail.com    Exit(1)
3565341Sstever@gmail.com
3575863Snate@binkert.org# Set up SWIG flags & scanner
3585341Sstever@gmail.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
3595863Snate@binkert.orgenv.Append(SWIGFLAGS=swig_flags)
3605863Snate@binkert.org
3615341Sstever@gmail.com# filter out all existing swig scanners, they mess up the dependency
3625863Snate@binkert.org# stuff for some reason
3635863Snate@binkert.orgscanners = []
3645341Sstever@gmail.comfor scanner in env['SCANNERS']:
3655863Snate@binkert.org    skeys = scanner.skeys
3665341Sstever@gmail.com    if skeys == '.i':
3675871Snate@binkert.org        continue
3685341Sstever@gmail.com
3695742Snate@binkert.org    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
3705742Snate@binkert.org        continue
3715742Snate@binkert.org
3725341Sstever@gmail.com    scanners.append(scanner)
3735742Snate@binkert.org
3745742Snate@binkert.org# add the new swig scanner that we like better
3755341Sstever@gmail.comfrom SCons.Scanner import ClassicCPP as CPPScanner
3766017Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
3776017Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
3786017Snate@binkert.org
3792632Sstever@eecs.umich.edu# replace the scanners list that has what we want
3806016Snate@binkert.orgenv['SCANNERS'] = scanners
3815871Snate@binkert.org
3825871Snate@binkert.org# Platform-specific configuration.  Note again that we assume that all
3835871Snate@binkert.org# builds under a given build root run on the same host platform.
3845871Snate@binkert.orgconf = Configure(env,
3855871Snate@binkert.org                 conf_dir = joinpath(build_root, '.scons_config'),
3865871Snate@binkert.org                 log_file = joinpath(build_root, 'scons_config.log'))
3875871Snate@binkert.org
3883942Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
3893940Ssaidi@eecs.umich.edutry:
3903918Ssaidi@eecs.umich.edu    import platform
3913918Ssaidi@eecs.umich.edu    uname = platform.uname()
3921858SN/A    if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
3933918Ssaidi@eecs.umich.edu        if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True,
3943918Ssaidi@eecs.umich.edu               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3953918Ssaidi@eecs.umich.edu               close_fds=True).communicate()[0][0]):
3963918Ssaidi@eecs.umich.edu            env.Append(CCFLAGS='-arch x86_64')
3975571Snate@binkert.org            env.Append(CFLAGS='-arch x86_64')
3983940Ssaidi@eecs.umich.edu            env.Append(LINKFLAGS='-arch x86_64')
3993940Ssaidi@eecs.umich.edu            env.Append(ASFLAGS='-arch x86_64')
4003918Ssaidi@eecs.umich.edu            env['OSX64bit'] = True
4013918Ssaidi@eecs.umich.eduexcept:
4023918Ssaidi@eecs.umich.edu    pass
4033918Ssaidi@eecs.umich.edu
4043918Ssaidi@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure()
4053918Ssaidi@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is
4065871Snate@binkert.org# present.  Unfortuantely this Null object always returns false,
4073918Ssaidi@eecs.umich.edu# breaking all our configuration checks.  We replace it with our own
4083918Ssaidi@eecs.umich.edu# more optimistic null object that returns True instead.
4093940Ssaidi@eecs.umich.eduif not conf:
4103918Ssaidi@eecs.umich.edu    def NullCheck(*args, **kwargs):
4113918Ssaidi@eecs.umich.edu        return True
4125397Ssaidi@eecs.umich.edu
4135397Ssaidi@eecs.umich.edu    class NullConf:
4145397Ssaidi@eecs.umich.edu        def __init__(self, env):
4155708Ssaidi@eecs.umich.edu            self.env = env
4165708Ssaidi@eecs.umich.edu        def Finish(self):
4175708Ssaidi@eecs.umich.edu            return self.env
4185708Ssaidi@eecs.umich.edu        def __getattr__(self, mname):
4195708Ssaidi@eecs.umich.edu            return NullCheck
4205397Ssaidi@eecs.umich.edu
4211851SN/A    conf = NullConf(env)
4221851SN/A
4231858SN/A# Find Python include and library directories for embedding the
424955SN/A# interpreter.  For consistency, we will use the same Python
4253053Sstever@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
4263053Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
4273053Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
4283053Sstever@eecs.umich.edu
4293053Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating
4303053Sstever@eecs.umich.edu# include & library files
4313053Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3]
4325871Snate@binkert.org
4333053Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4
4344742Sstever@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name)
4354742Sstever@eecs.umich.eduenv.Append(CPPPATH = py_header_path)
4363053Sstever@eecs.umich.edu# verify that it works
4373053Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
4383053Sstever@eecs.umich.edu    print "Error: can't find Python.h header in", py_header_path
4393053Sstever@eecs.umich.edu    Exit(1)
4403053Sstever@eecs.umich.edu
4413053Sstever@eecs.umich.edu# add library path too if it's not in the default place
4423053Sstever@eecs.umich.edupy_lib_path = None
4433053Sstever@eecs.umich.eduif sys.exec_prefix != '/usr':
4443053Sstever@eecs.umich.edu    py_lib_path = joinpath(sys.exec_prefix, 'lib')
4452667Sstever@eecs.umich.eduelif sys.platform == 'cygwin':
4464554Sbinkertn@umich.edu    # cygwin puts the .dll in /bin for some reason
4474554Sbinkertn@umich.edu    py_lib_path = '/bin'
4482667Sstever@eecs.umich.eduif py_lib_path:
4494554Sbinkertn@umich.edu    env.Append(LIBPATH = py_lib_path)
4504554Sbinkertn@umich.edu    print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
4514554Sbinkertn@umich.eduif not conf.CheckLib(py_version_name):
4524554Sbinkertn@umich.edu    print "Error: can't find Python library", py_version_name
4534554Sbinkertn@umich.edu    Exit(1)
4544554Sbinkertn@umich.edu
4554554Sbinkertn@umich.edu# On Solaris you need to use libsocket for socket ops
4564781Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4574554Sbinkertn@umich.edu   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4584554Sbinkertn@umich.edu       print "Can't find library with socket calls (e.g. accept())"
4592667Sstever@eecs.umich.edu       Exit(1)
4604554Sbinkertn@umich.edu
4614554Sbinkertn@umich.edu# Check for zlib.  If the check passes, libz will be automatically
4624554Sbinkertn@umich.edu# added to the LIBS environment variable.
4634554Sbinkertn@umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
4642667Sstever@eecs.umich.edu    print 'Error: did not find needed zlib compression library '\
4654554Sbinkertn@umich.edu          'and/or zlib.h header file.'
4662667Sstever@eecs.umich.edu    print '       Please install zlib and try again.'
4674554Sbinkertn@umich.edu    Exit(1)
4684554Sbinkertn@umich.edu
4692667Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
4705522Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>')
4715522Snate@binkert.orgif not have_fenv:
4725522Snate@binkert.org    print "Warning: Header file <fenv.h> not found."
4735522Snate@binkert.org    print "         This host has no IEEE FP rounding mode control."
4745522Snate@binkert.org
4755522Snate@binkert.org# Check for mysql.
4765522Snate@binkert.orgmysql_config = WhereIs('mysql_config')
4775522Snate@binkert.orghave_mysql = mysql_config != None
4785522Snate@binkert.org
4795522Snate@binkert.org# Check MySQL version.
4805522Snate@binkert.orgif have_mysql:
4815522Snate@binkert.org    mysql_version = os.popen(mysql_config + ' --version').read()
4825522Snate@binkert.org    min_mysql_version = '4.1'
4835522Snate@binkert.org    if compare_versions(mysql_version, min_mysql_version) < 0:
4845522Snate@binkert.org        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
4855522Snate@binkert.org        print '         Version', mysql_version, 'detected.'
4865522Snate@binkert.org        have_mysql = False
4875522Snate@binkert.org
4885522Snate@binkert.org# Set up mysql_config commands.
4895522Snate@binkert.orgif have_mysql:
4905522Snate@binkert.org    mysql_config_include = mysql_config + ' --include'
4915522Snate@binkert.org    if os.system(mysql_config_include + ' > /dev/null') != 0:
4925522Snate@binkert.org        # older mysql_config versions don't support --include, use
4935522Snate@binkert.org        # --cflags instead
4945522Snate@binkert.org        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
4955522Snate@binkert.org    # This seems to work in all versions
4962638Sstever@eecs.umich.edu    mysql_config_libs = mysql_config + ' --libs'
4972638Sstever@eecs.umich.edu
4982638Sstever@eecs.umich.eduenv = conf.Finish()
4993716Sstever@eecs.umich.edu
5005522Snate@binkert.org# Define the universe of supported ISAs
5015522Snate@binkert.orgall_isa_list = [ ]
5025522Snate@binkert.orgExport('all_isa_list')
5035522Snate@binkert.org
5045522Snate@binkert.org# Define the universe of supported CPU models
5055522Snate@binkert.orgall_cpu_list = [ ]
5061858SN/Adefault_cpus = [ ]
5075227Ssaidi@eecs.umich.eduExport('all_cpu_list', 'default_cpus')
5085227Ssaidi@eecs.umich.edu
5095227Ssaidi@eecs.umich.edu# Sticky options get saved in the options file so they persist from
5105227Ssaidi@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
5115227Ssaidi@eecs.umich.edu# value becomes sticky).
5125863Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS)
5135227Ssaidi@eecs.umich.eduExport('sticky_opts')
5145227Ssaidi@eecs.umich.edu
5155227Ssaidi@eecs.umich.edu# Non-sticky options only apply to the current build.
5165227Ssaidi@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS)
5175227Ssaidi@eecs.umich.eduExport('nonsticky_opts')
5185227Ssaidi@eecs.umich.edu
5195227Ssaidi@eecs.umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the
5205204Sstever@gmail.com# above options
5215204Sstever@gmail.comfor base_dir in base_dir_list:
5225204Sstever@gmail.com    for root, dirs, files in os.walk(base_dir):
5235204Sstever@gmail.com        if 'SConsopts' in files:
5245204Sstever@gmail.com            print "Reading", os.path.join(root, 'SConsopts')
5255204Sstever@gmail.com            SConscript(os.path.join(root, 'SConsopts'))
5265204Sstever@gmail.com
5275204Sstever@gmail.comall_isa_list.sort()
5285204Sstever@gmail.comall_cpu_list.sort()
5295204Sstever@gmail.comdefault_cpus.sort()
5305204Sstever@gmail.com
5315204Sstever@gmail.comsticky_opts.AddOptions(
5325204Sstever@gmail.com    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
5335204Sstever@gmail.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
5345204Sstever@gmail.com    # There's a bug in scons 0.96.1 that causes ListOptions with list
5355204Sstever@gmail.com    # values (more than one value) not to be able to be restored from
5365204Sstever@gmail.com    # a saved option file.  If this causes trouble then upgrade to
5375204Sstever@gmail.com    # scons 0.96.90 or later.
5385204Sstever@gmail.com    ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
5393118Sstever@eecs.umich.edu    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
5403118Sstever@eecs.umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
5413118Sstever@eecs.umich.edu               False),
5423118Sstever@eecs.umich.edu    BoolOption('SS_COMPATIBLE_FP',
5433118Sstever@eecs.umich.edu               'Make floating-point results compatible with SimpleScalar',
5445863Snate@binkert.org               False),
5453118Sstever@eecs.umich.edu    BoolOption('USE_SSE2',
5465863Snate@binkert.org               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
5473118Sstever@eecs.umich.edu               False),
5485863Snate@binkert.org    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
5495863Snate@binkert.org    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
5505863Snate@binkert.org    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
5515863Snate@binkert.org    BoolOption('BATCH', 'Use batch pool for build and tests', False),
5525863Snate@binkert.org    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
5535863Snate@binkert.org    ('PYTHONHOME',
5545863Snate@binkert.org     'Override the default PYTHONHOME for this system (use with caution)',
5555863Snate@binkert.org     '%s:%s' % (sys.prefix, sys.exec_prefix)),
5566003Snate@binkert.org    )
5575863Snate@binkert.org
5585863Snate@binkert.orgnonsticky_opts.AddOptions(
5595863Snate@binkert.org    BoolOption('update_ref', 'Update test reference outputs', False)
5605863Snate@binkert.org    )
5615863Snate@binkert.org
5625863Snate@binkert.org# These options get exported to #defines in config/*.hh (see src/SConscript).
5635863Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
5645863Snate@binkert.org                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
5655863Snate@binkert.org                     'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
5665863Snate@binkert.org
5675863Snate@binkert.org# Define a handy 'no-op' action
5685863Snate@binkert.orgdef no_action(target, source, env):
5695863Snate@binkert.org    return 0
5705863Snate@binkert.org
5715863Snate@binkert.orgenv.NoAction = Action(no_action, None)
5723118Sstever@eecs.umich.edu
5735863Snate@binkert.org###################################################
5743118Sstever@eecs.umich.edu#
5753118Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers.
5765863Snate@binkert.org#
5775863Snate@binkert.org###################################################
5785863Snate@binkert.org
5795863Snate@binkert.org# This function generates a config header file that #defines the
5805863Snate@binkert.org# option symbol to the current option setting (0 or 1).  The source
5815863Snate@binkert.org# operands are the name of the option and a Value node containing the
5823118Sstever@eecs.umich.edu# value of the option.
5833483Ssaidi@eecs.umich.edudef build_config_file(target, source, env):
5843494Ssaidi@eecs.umich.edu    (option, value) = [s.get_contents() for s in source]
5853494Ssaidi@eecs.umich.edu    f = file(str(target[0]), 'w')
5863483Ssaidi@eecs.umich.edu    print >> f, '#define', option, value
5873483Ssaidi@eecs.umich.edu    f.close()
5883483Ssaidi@eecs.umich.edu    return None
5893053Sstever@eecs.umich.edu
5903053Sstever@eecs.umich.edu# Generate the message to be printed when building the config file.
5913918Ssaidi@eecs.umich.edudef build_config_file_string(target, source, env):
5923053Sstever@eecs.umich.edu    (option, value) = [s.get_contents() for s in source]
5933053Sstever@eecs.umich.edu    return "Defining %s as %s in %s." % (option, value, target[0])
5943053Sstever@eecs.umich.edu
5953053Sstever@eecs.umich.edu# Combine the two functions into a scons Action object.
5963053Sstever@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string)
5971858SN/A
5981858SN/A# The emitter munges the source & target node lists to reflect what
5991858SN/A# we're really doing.
6001858SN/Adef config_emitter(target, source, env):
6011858SN/A    # extract option name from Builder arg
6021858SN/A    option = str(target[0])
6035863Snate@binkert.org    # True target is config header file
6045863Snate@binkert.org    target = joinpath('config', option.lower() + '.hh')
6051859SN/A    val = env[option]
6065863Snate@binkert.org    if isinstance(val, bool):
6071858SN/A        # Force value to 0/1
6085863Snate@binkert.org        val = int(val)
6091858SN/A    elif isinstance(val, str):
6101859SN/A        val = '"' + val + '"'
6111859SN/A
6125863Snate@binkert.org    # Sources are option name & value (packaged in SCons Value nodes)
6133053Sstever@eecs.umich.edu    return ([target], [Value(option), Value(val)])
6143053Sstever@eecs.umich.edu
6153053Sstever@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action)
6163053Sstever@eecs.umich.edu
6171859SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
6181859SN/A
6191859SN/A###################################################
6201859SN/A#
6211859SN/A# Define a SCons builder for copying files.  This is used by the
6221859SN/A# Python zipfile code in src/python/SConscript, but is placed up here
6231859SN/A# since it's potentially more generally applicable.
6241859SN/A#
6251862SN/A###################################################
6261859SN/A
6271859SN/Acopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
6281859SN/A
6295863Snate@binkert.orgenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
6305863Snate@binkert.org
6315863Snate@binkert.org###################################################
6325863Snate@binkert.org#
6331858SN/A# Define a simple SCons builder to concatenate files.
6341858SN/A#
6355863Snate@binkert.org# Used to append the Python zip archive to the executable.
6365863Snate@binkert.org#
6375863Snate@binkert.org###################################################
6385863Snate@binkert.org
6395863Snate@binkert.orgconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
6405871Snate@binkert.org                                          'chmod +x $TARGET']))
6415871Snate@binkert.org
6422139SN/Aenv.Append(BUILDERS = { 'Concat' : concat_builder })
6434202Sbinkertn@umich.edu
6444202Sbinkertn@umich.edu
6452139SN/A# libelf build is shared across all configs in the build root.
6462155SN/Aenv.SConscript('ext/libelf/SConscript',
6474202Sbinkertn@umich.edu               build_dir = joinpath(build_root, 'libelf'),
6484202Sbinkertn@umich.edu               exports = 'env')
6494202Sbinkertn@umich.edu
6502155SN/A###################################################
6515863Snate@binkert.org#
6521869SN/A# This function is used to set up a directory with switching headers
6531869SN/A#
6545863Snate@binkert.org###################################################
6555863Snate@binkert.org
6564202Sbinkertn@umich.eduenv['ALL_ISA_LIST'] = all_isa_list
6576108Snate@binkert.orgdef make_switching_dir(dirname, switch_headers, env):
6586108Snate@binkert.org    # Generate the header.  target[0] is the full path of the output
6596108Snate@binkert.org    # header to generate.  'source' is a dummy variable, since we get the
6606108Snate@binkert.org    # list of ISAs from env['ALL_ISA_LIST'].
6615863Snate@binkert.org    def gen_switch_hdr(target, source, env):
6625863Snate@binkert.org        fname = str(target[0])
6635863Snate@binkert.org        basename = os.path.basename(fname)
6644202Sbinkertn@umich.edu        f = open(fname, 'w')
6654202Sbinkertn@umich.edu        f.write('#include "arch/isa_specific.hh"\n')
6665863Snate@binkert.org        cond = '#if'
6675742Snate@binkert.org        for isa in all_isa_list:
6685742Snate@binkert.org            f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
6695341Sstever@gmail.com                    % (cond, isa.upper(), dirname, isa, basename))
6705342Sstever@gmail.com            cond = '#elif'
6715342Sstever@gmail.com        f.write('#else\n#error "THE_ISA not set"\n#endif\n')
6724202Sbinkertn@umich.edu        f.close()
6734202Sbinkertn@umich.edu        return 0
6744202Sbinkertn@umich.edu
6754202Sbinkertn@umich.edu    # String to print when generating header
6764202Sbinkertn@umich.edu    def gen_switch_hdr_string(target, source, env):
6775863Snate@binkert.org        return "Generating switch header " + str(target[0])
6785863Snate@binkert.org
6795863Snate@binkert.org    # Build SCons Action object. 'varlist' specifies env vars that this
6805863Snate@binkert.org    # action depends on; when env['ALL_ISA_LIST'] changes these actions
6815863Snate@binkert.org    # should get re-executed.
6825863Snate@binkert.org    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
6835863Snate@binkert.org                               varlist=['ALL_ISA_LIST'])
6845863Snate@binkert.org
6855863Snate@binkert.org    # Instantiate actions for each header
6865863Snate@binkert.org    for hdr in switch_headers:
6875863Snate@binkert.org        env.Command(hdr, [], switch_hdr_action)
6885863Snate@binkert.orgExport('make_switching_dir')
6895863Snate@binkert.org
6905863Snate@binkert.org###################################################
6915863Snate@binkert.org#
6925863Snate@binkert.org# Define build environments for selected configurations.
6935863Snate@binkert.org#
6945863Snate@binkert.org###################################################
6955863Snate@binkert.org
6965863Snate@binkert.org# rename base env
6975952Ssaidi@eecs.umich.edubase_env = env
6981869SN/A
6991858SN/Afor build_path in build_paths:
7005863Snate@binkert.org    print "Building in", build_path
7015863Snate@binkert.org    env['BUILDDIR'] = build_path
7021869SN/A
7031858SN/A    # build_dir is the tail component of build path, and is used to
7045863Snate@binkert.org    # determine the build parameters (e.g., 'ALPHA_SE')
7056108Snate@binkert.org    (build_root, build_dir) = os.path.split(build_path)
7066108Snate@binkert.org    # Make a copy of the build-root environment to use for this config.
7076108Snate@binkert.org    env = base_env.Copy()
7081858SN/A
709955SN/A    # Set env options according to the build directory config.
710955SN/A    sticky_opts.files = []
7111869SN/A    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
7121869SN/A    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
7131869SN/A    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
7141869SN/A    current_opts_file = joinpath(build_root, 'options', build_dir)
7151869SN/A    if os.path.isfile(current_opts_file):
7165863Snate@binkert.org        sticky_opts.files.append(current_opts_file)
7175863Snate@binkert.org        print "Using saved options file %s" % current_opts_file
7185863Snate@binkert.org    else:
7191869SN/A        # Build dir-specific options file doesn't exist.
7205863Snate@binkert.org
7211869SN/A        # Make sure the directory is there so we can create it later
7225863Snate@binkert.org        opt_dir = os.path.dirname(current_opts_file)
7231869SN/A        if not os.path.isdir(opt_dir):
7241869SN/A            os.mkdir(opt_dir)
7251869SN/A
7261869SN/A        # Get default build options from source tree.  Options are
7271869SN/A        # normally determined by name of $BUILD_DIR, but can be
7285863Snate@binkert.org        # overriden by 'default=' arg on command line.
7295863Snate@binkert.org        default_opts_file = joinpath('build_opts',
7301869SN/A                                     ARGUMENTS.get('default', build_dir))
7311869SN/A        if os.path.isfile(default_opts_file):
7321869SN/A            sticky_opts.files.append(default_opts_file)
7331869SN/A            print "Options file %s not found,\n  using defaults in %s" \
7341869SN/A                  % (current_opts_file, default_opts_file)
7351869SN/A        else:
7361869SN/A            print "Error: cannot find options file %s or %s" \
7375863Snate@binkert.org                  % (current_opts_file, default_opts_file)
7385863Snate@binkert.org            Exit(1)
7391869SN/A
7405863Snate@binkert.org    # Apply current option settings to env
7415863Snate@binkert.org    sticky_opts.Update(env)
7423356Sbinkertn@umich.edu    nonsticky_opts.Update(env)
7433356Sbinkertn@umich.edu
7443356Sbinkertn@umich.edu    help_text += "\nSticky options for %s:\n" % build_dir \
7453356Sbinkertn@umich.edu                 + sticky_opts.GenerateHelpText(env) \
7463356Sbinkertn@umich.edu                 + "\nNon-sticky options for %s:\n" % build_dir \
7474781Snate@binkert.org                 + nonsticky_opts.GenerateHelpText(env)
7485863Snate@binkert.org
7495863Snate@binkert.org    # Process option settings.
7501869SN/A
7511869SN/A    if not have_fenv and env['USE_FENV']:
7521869SN/A        print "Warning: <fenv.h> not available; " \
7531869SN/A              "forcing USE_FENV to False in", build_dir + "."
7541869SN/A        env['USE_FENV'] = False
7552638Sstever@eecs.umich.edu
7562638Sstever@eecs.umich.edu    if not env['USE_FENV']:
7575871Snate@binkert.org        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
7582638Sstever@eecs.umich.edu        print "         FP results may deviate slightly from other platforms."
7595749Scws3k@cs.virginia.edu
7605749Scws3k@cs.virginia.edu    if env['EFENCE']:
7615871Snate@binkert.org        env.Append(LIBS=['efence'])
7625749Scws3k@cs.virginia.edu
7631869SN/A    if env['USE_MYSQL']:
7641869SN/A        if not have_mysql:
7653546Sgblack@eecs.umich.edu            print "Warning: MySQL not available; " \
7663546Sgblack@eecs.umich.edu                  "forcing USE_MYSQL to False in", build_dir + "."
7673546Sgblack@eecs.umich.edu            env['USE_MYSQL'] = False
7683546Sgblack@eecs.umich.edu        else:
7694202Sbinkertn@umich.edu            print "Compiling in", build_dir, "with MySQL support."
7705863Snate@binkert.org            env.ParseConfig(mysql_config_libs)
7713546Sgblack@eecs.umich.edu            env.ParseConfig(mysql_config_include)
7723546Sgblack@eecs.umich.edu
7733546Sgblack@eecs.umich.edu    # Save sticky option settings back to current options file
7743546Sgblack@eecs.umich.edu    sticky_opts.Save(current_opts_file, env)
7754781Snate@binkert.org
7765863Snate@binkert.org    # Do this after we save setting back, or else we'll tack on an
7774781Snate@binkert.org    # extra 'qdo' every time we run scons.
7784781Snate@binkert.org    if env['BATCH']:
7794781Snate@binkert.org        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
7804781Snate@binkert.org        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
7814781Snate@binkert.org
7825863Snate@binkert.org    if env['USE_SSE2']:
7834781Snate@binkert.org        env.Append(CCFLAGS='-msse2')
7844781Snate@binkert.org
7854781Snate@binkert.org    # The src/SConscript file sets up the build rules in 'env' according
7864781Snate@binkert.org    # to the configured options.  It returns a list of environments,
7873546Sgblack@eecs.umich.edu    # one for each variant build (debug, opt, etc.)
7883546Sgblack@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
7893546Sgblack@eecs.umich.edu                         exports = 'env')
7904781Snate@binkert.org
7913546Sgblack@eecs.umich.edu    # Set up the regression tests for each build.
7923546Sgblack@eecs.umich.edu    for e in envList:
7933546Sgblack@eecs.umich.edu        SConscript('tests/SConscript',
7943546Sgblack@eecs.umich.edu                   build_dir = joinpath(build_path, 'tests', e.Label),
7953546Sgblack@eecs.umich.edu                   exports = { 'env' : e }, duplicate = False)
7963546Sgblack@eecs.umich.edu
7973546Sgblack@eecs.umich.eduHelp(help_text)
7983546Sgblack@eecs.umich.edu
7993546Sgblack@eecs.umich.edu
8003546Sgblack@eecs.umich.edu###################################################
8014202Sbinkertn@umich.edu#
8023546Sgblack@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
8033546Sgblack@eecs.umich.edu# build environments to build the requested targets.
8043546Sgblack@eecs.umich.edu#
805955SN/A###################################################
806955SN/A
807955SN/A