SConstruct revision 5227
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
30955SN/A
31955SN/A###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
352632Sstever@eecs.umich.edu# 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).
39955SN/A#
402632Sstever@eecs.umich.edu# 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
422761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
432632Sstever@eecs.umich.edu# built for the same host system.
442632Sstever@eecs.umich.edu#
452632Sstever@eecs.umich.edu# Examples:
462761Sstever@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.
492632Sstever@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
512761Sstever@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.
562632Sstever@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.
63955SN/A#
64955SN/A###################################################
65955SN/A
66955SN/Aimport sys
67955SN/Aimport os
684202Sbinkertn@umich.edu
694678Snate@binkert.orgfrom os.path import isdir, join as joinpath
70955SN/A
712656Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions.  If your system's
722656Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a
732656Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1)
742656Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python'
752656Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the
762656Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
772656Sstever@eecs.umich.eduEnsurePythonVersion(2,4)
782653Sstever@eecs.umich.edu
795227Ssaidi@eecs.umich.edu# Import subprocess after we check the version since it doesn't exist in
805227Ssaidi@eecs.umich.edu# Python < 2.4.
815227Ssaidi@eecs.umich.eduimport subprocess
825227Ssaidi@eecs.umich.edu
832653Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
842653Sstever@eecs.umich.edu# 3-element version number.
852653Sstever@eecs.umich.edumin_scons_version = (0,96,91)
862653Sstever@eecs.umich.edutry:
872653Sstever@eecs.umich.edu    EnsureSConsVersion(*min_scons_version)
882653Sstever@eecs.umich.eduexcept:
892653Sstever@eecs.umich.edu    print "Error checking current SCons version."
902653Sstever@eecs.umich.edu    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
912653Sstever@eecs.umich.edu    Exit(2)
924781Snate@binkert.org
931852SN/A
94955SN/A# The absolute path to the current directory (where this file lives).
95955SN/AROOT = Dir('.').abspath
96955SN/A
973717Sstever@eecs.umich.edu# Path to the M5 source tree.
983716Sstever@eecs.umich.eduSRCDIR = joinpath(ROOT, 'src')
99955SN/A
1001533SN/A# tell python where to find m5 python code
1013716Sstever@eecs.umich.edusys.path.append(joinpath(ROOT, 'src/python'))
1021533SN/A
1034678Snate@binkert.orgdef check_style_hook(ui):
1044678Snate@binkert.org    ui.readconfig(joinpath(ROOT, '.hg', 'hgrc'))
1054678Snate@binkert.org    style_hook = ui.config('hooks', 'pretxncommit.style', None)
1064678Snate@binkert.org
1074678Snate@binkert.org    if not style_hook:
1084678Snate@binkert.org        print """\
1094678Snate@binkert.orgYou're missing the M5 style hook.
1104678Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style.
1114678Snate@binkert.org
1124678Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc
1134678Snate@binkert.orgor your personal .hgrc
1144678Snate@binkert.org----------------
1154678Snate@binkert.org
1164678Snate@binkert.org[extensions]
1174678Snate@binkert.orgstyle = %s/util/style.py
1184678Snate@binkert.org
1194678Snate@binkert.org[hooks]
1204678Snate@binkert.orgpretxncommit.style = python:style.check_whitespace
1214678Snate@binkert.org""" % (ROOT)
1224678Snate@binkert.org        sys.exit(1)
1234678Snate@binkert.org
1244973Ssaidi@eecs.umich.eduif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')):
1254678Snate@binkert.org    try:
1264678Snate@binkert.org        from mercurial import ui
1274678Snate@binkert.org        check_style_hook(ui.ui())
1284678Snate@binkert.org    except ImportError:
1294678Snate@binkert.org        pass
1304678Snate@binkert.org
131955SN/A###################################################
132955SN/A#
1332632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
1342632Sstever@eecs.umich.edu# the target(s).
135955SN/A#
136955SN/A###################################################
137955SN/A
138955SN/A# Find default configuration & binary.
1392632Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
140955SN/A
1412632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
1422632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
1432632Sstever@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1442632Sstever@eecs.umich.edu        if l[i] == elt:
1452632Sstever@eecs.umich.edu            return i
1462632Sstever@eecs.umich.edu    raise ValueError, "element not found"
1472632Sstever@eecs.umich.edu
1483053Sstever@eecs.umich.edu# helper function: compare dotted version numbers.
1493053Sstever@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1')
1503053Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2
1513053Sstever@eecs.umich.edudef compare_versions(v1, v2):
1523053Sstever@eecs.umich.edu    # Convert dotted strings to lists
1533053Sstever@eecs.umich.edu    v1 = map(int, v1.split('.'))
1543053Sstever@eecs.umich.edu    v2 = map(int, v2.split('.'))
1553053Sstever@eecs.umich.edu    # Compare corresponding elements of lists
1563053Sstever@eecs.umich.edu    for n1,n2 in zip(v1, v2):
1573053Sstever@eecs.umich.edu        if n1 < n2: return -1
1583053Sstever@eecs.umich.edu        if n1 > n2: return  1
1593053Sstever@eecs.umich.edu    # all corresponding values are equal... see if one has extra values
1603053Sstever@eecs.umich.edu    if len(v1) < len(v2): return -1
1613053Sstever@eecs.umich.edu    if len(v1) > len(v2): return  1
1623053Sstever@eecs.umich.edu    return 0
1633053Sstever@eecs.umich.edu
1642632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1652632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
1662632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1672632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1682632Sstever@eecs.umich.edu# follow 'build' in the bulid path.
1692632Sstever@eecs.umich.edu
1703718Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is
1713718Sstever@eecs.umich.eduif COMMAND_LINE_TARGETS:
1723718Sstever@eecs.umich.edu    # Ask SCons which directory it was invoked from
1733718Sstever@eecs.umich.edu    launch_dir = GetLaunchDir()
1743718Sstever@eecs.umich.edu    # Make targets relative to invocation directory
1753718Sstever@eecs.umich.edu    abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))),
1763718Sstever@eecs.umich.edu                      COMMAND_LINE_TARGETS)
1773718Sstever@eecs.umich.eduelse:
1783718Sstever@eecs.umich.edu    # Default targets are relative to root of tree
1793718Sstever@eecs.umich.edu    abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))),
1803718Sstever@eecs.umich.edu                      DEFAULT_TARGETS)
1813718Sstever@eecs.umich.edu
1823718Sstever@eecs.umich.edu
1832634Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the
1842634Sstever@eecs.umich.edu# collected targets reference.
1852632Sstever@eecs.umich.edubuild_paths = []
1862638Sstever@eecs.umich.edubuild_root = None
1872632Sstever@eecs.umich.edufor t in abs_targets:
1882632Sstever@eecs.umich.edu    path_dirs = t.split('/')
1892632Sstever@eecs.umich.edu    try:
1902632Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1912632Sstever@eecs.umich.edu    except:
1922632Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1931858SN/A        Exit(1)
1943716Sstever@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
1952638Sstever@eecs.umich.edu    if not build_root:
1962638Sstever@eecs.umich.edu        build_root = this_build_root
1972638Sstever@eecs.umich.edu    else:
1982638Sstever@eecs.umich.edu        if this_build_root != build_root:
1992638Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
2002638Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
2012638Sstever@eecs.umich.edu            Exit(1)
2023716Sstever@eecs.umich.edu    build_path = joinpath('/',*path_dirs[:build_top+2])
2032634Sstever@eecs.umich.edu    if build_path not in build_paths:
2042634Sstever@eecs.umich.edu        build_paths.append(build_path)
205955SN/A
206955SN/A###################################################
207955SN/A#
208955SN/A# Set up the default build environment.  This environment is copied
209955SN/A# and modified according to each selected configuration.
210955SN/A#
211955SN/A###################################################
212955SN/A
2131858SN/Aenv = Environment(ENV = os.environ,  # inherit user's environment vars
2141858SN/A                  ROOT = ROOT,
2152632Sstever@eecs.umich.edu                  SRCDIR = SRCDIR)
216955SN/A
2174781Snate@binkert.org#Parse CC/CXX early so that we use the correct compiler for
2183643Ssaidi@eecs.umich.edu# to test for dependencies/versions/libraries/includes
2193643Ssaidi@eecs.umich.eduif ARGUMENTS.get('CC', None):
2203643Ssaidi@eecs.umich.edu    env['CC'] = ARGUMENTS.get('CC')
2213643Ssaidi@eecs.umich.edu
2223643Ssaidi@eecs.umich.eduif ARGUMENTS.get('CXX', None):
2233643Ssaidi@eecs.umich.edu    env['CXX'] = ARGUMENTS.get('CXX')
2243643Ssaidi@eecs.umich.edu
2254494Ssaidi@eecs.umich.eduExport('env')
2264494Ssaidi@eecs.umich.edu
2273716Sstever@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign"))
2281105SN/A
2292667Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up
2302667Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
2312667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
2322667Sstever@eecs.umich.edu# (soft) links work better.
2332667Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy')
2342667Sstever@eecs.umich.edu
2351869SN/A# I waffle on this setting... it does avoid a few painful but
2361869SN/A# unnecessary builds, but it also seems to make trivial builds take
2371869SN/A# noticeably longer.
2381869SN/Aif False:
2391869SN/A    env.TargetSignatures('content')
2401065SN/A
2412632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
2425199Sstever@gmail.comenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) })
2433918Ssaidi@eecs.umich.eduenv['GCC'] = False
2443918Ssaidi@eecs.umich.eduenv['SUNCC'] = False
2453940Ssaidi@eecs.umich.eduenv['ICC'] = False
2464781Snate@binkert.orgenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True,
2474781Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
2483918Ssaidi@eecs.umich.edu        close_fds=True).communicate()[0].find('GCC') >= 0
2494781Snate@binkert.orgenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
2504781Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
2513918Ssaidi@eecs.umich.edu        close_fds=True).communicate()[0].find('Sun C++') >= 0
2524781Snate@binkert.orgenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
2534781Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
2543940Ssaidi@eecs.umich.edu        close_fds=True).communicate()[0].find('Intel') >= 0
2553942Ssaidi@eecs.umich.eduif env['GCC'] + env['SUNCC'] + env['ICC'] > 1:
2563940Ssaidi@eecs.umich.edu    print 'Error: How can we have two at the same time?'
2573918Ssaidi@eecs.umich.edu    Exit(1)
2583918Ssaidi@eecs.umich.edu
259955SN/A
2601858SN/A# Set up default C++ compiler flags
2613918Ssaidi@eecs.umich.eduif env['GCC']:
2623918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-pipe')
2633918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-fno-strict-aliasing')
2643918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2653940Ssaidi@eecs.umich.eduelif env['ICC']:
2663940Ssaidi@eecs.umich.edu    pass #Fix me... add warning flags once we clean up icc warnings
2673918Ssaidi@eecs.umich.eduelif env['SUNCC']:
2683918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-Qoption ccfe')
2693918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-features=gcc')
2703918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-features=extensions')
2713918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-library=stlport4')
2723918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-xar')
2733918Ssaidi@eecs.umich.edu#    env.Append(CCFLAGS='-instances=semiexplicit')
2743918Ssaidi@eecs.umich.eduelse:
2753918Ssaidi@eecs.umich.edu    print 'Error: Don\'t know what compiler options to use for your compiler.'
2763940Ssaidi@eecs.umich.edu    print '       Please fix SConstruct and src/SConscript and try again.'
2773918Ssaidi@eecs.umich.edu    Exit(1)
2783918Ssaidi@eecs.umich.edu
2791851SN/Aif sys.platform == 'cygwin':
2801851SN/A    # cygwin has some header file issues...
2811858SN/A    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
2825200Sstever@gmail.comenv.Append(CPPPATH=[Dir('ext/dnet')])
283955SN/A
2843053Sstever@eecs.umich.edu# Check for SWIG
2853053Sstever@eecs.umich.eduif not env.has_key('SWIG'):
2863053Sstever@eecs.umich.edu    print 'Error: SWIG utility not found.'
2873053Sstever@eecs.umich.edu    print '       Please install (see http://www.swig.org) and retry.'
2883053Sstever@eecs.umich.edu    Exit(1)
2893053Sstever@eecs.umich.edu
2903053Sstever@eecs.umich.edu# Check for appropriate SWIG version
2913053Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split()
2923053Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z"
2934742Sstever@eecs.umich.eduif len(swig_version) < 3 or \
2944742Sstever@eecs.umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
2953053Sstever@eecs.umich.edu    print 'Error determining SWIG version.'
2963053Sstever@eecs.umich.edu    Exit(1)
2973053Sstever@eecs.umich.edu
2983053Sstever@eecs.umich.edumin_swig_version = '1.3.28'
2993053Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0:
3003053Sstever@eecs.umich.edu    print 'Error: SWIG version', min_swig_version, 'or newer required.'
3013053Sstever@eecs.umich.edu    print '       Installed version:', swig_version[2]
3023053Sstever@eecs.umich.edu    Exit(1)
3033053Sstever@eecs.umich.edu
3042667Sstever@eecs.umich.edu# Set up SWIG flags & scanner
3054554Sbinkertn@umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
3064554Sbinkertn@umich.eduenv.Append(SWIGFLAGS=swig_flags)
3072667Sstever@eecs.umich.edu
3084554Sbinkertn@umich.edu# filter out all existing swig scanners, they mess up the dependency
3094554Sbinkertn@umich.edu# stuff for some reason
3104554Sbinkertn@umich.eduscanners = []
3114554Sbinkertn@umich.edufor scanner in env['SCANNERS']:
3124554Sbinkertn@umich.edu    skeys = scanner.skeys
3134554Sbinkertn@umich.edu    if skeys == '.i':
3144554Sbinkertn@umich.edu        continue
3154781Snate@binkert.org
3164554Sbinkertn@umich.edu    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
3174554Sbinkertn@umich.edu        continue
3182667Sstever@eecs.umich.edu
3194554Sbinkertn@umich.edu    scanners.append(scanner)
3204554Sbinkertn@umich.edu
3214554Sbinkertn@umich.edu# add the new swig scanner that we like better
3224554Sbinkertn@umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner
3232667Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
3244554Sbinkertn@umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
3252667Sstever@eecs.umich.edu
3264554Sbinkertn@umich.edu# replace the scanners list that has what we want
3274554Sbinkertn@umich.eduenv['SCANNERS'] = scanners
3282667Sstever@eecs.umich.edu
3292638Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
3302638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
3312638Sstever@eecs.umich.educonf = Configure(env,
3323716Sstever@eecs.umich.edu                 conf_dir = joinpath(build_root, '.scons_config'),
3333716Sstever@eecs.umich.edu                 log_file = joinpath(build_root, 'scons_config.log'))
3341858SN/A
3355227Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
3365227Ssaidi@eecs.umich.edutry:
3375227Ssaidi@eecs.umich.edu    import platform
3385227Ssaidi@eecs.umich.edu    uname = platform.uname()
3395227Ssaidi@eecs.umich.edu    if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
3405227Ssaidi@eecs.umich.edu        if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True,
3415227Ssaidi@eecs.umich.edu               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3425227Ssaidi@eecs.umich.edu               close_fds=True).communicate()[0][0]):
3435227Ssaidi@eecs.umich.edu            env.Append(CCFLAGS='-arch x86_64')
3445227Ssaidi@eecs.umich.edu            env.Append(CFLAGS='-arch x86_64')
3455227Ssaidi@eecs.umich.edu            env.Append(LINKFLAGS='-arch x86_64')
3465227Ssaidi@eecs.umich.edu            env.Append(ASFLAGS='-arch x86_64')
3475227Ssaidi@eecs.umich.eduexcept:
3485227Ssaidi@eecs.umich.edu    pass
3495227Ssaidi@eecs.umich.edu
3505204Sstever@gmail.com# Recent versions of scons substitute a "Null" object for Configure()
3515204Sstever@gmail.com# when configuration isn't necessary, e.g., if the "--help" option is
3525204Sstever@gmail.com# present.  Unfortuantely this Null object always returns false,
3535204Sstever@gmail.com# breaking all our configuration checks.  We replace it with our own
3545204Sstever@gmail.com# more optimistic null object that returns True instead.
3555204Sstever@gmail.comif not conf:
3565204Sstever@gmail.com    def NullCheck(*args, **kwargs):
3575204Sstever@gmail.com        return True
3585204Sstever@gmail.com
3595204Sstever@gmail.com    class NullConf:
3605204Sstever@gmail.com        def __init__(self, env):
3615204Sstever@gmail.com            self.env = env
3625204Sstever@gmail.com        def Finish(self):
3635204Sstever@gmail.com            return self.env
3645204Sstever@gmail.com        def __getattr__(self, mname):
3655204Sstever@gmail.com            return NullCheck
3665204Sstever@gmail.com
3675204Sstever@gmail.com    conf = NullConf(env)
3685204Sstever@gmail.com
3693118Sstever@eecs.umich.edu# Find Python include and library directories for embedding the
3703118Sstever@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
3713118Sstever@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
3723118Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
3733118Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
3743118Sstever@eecs.umich.edu
3753118Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating
3763118Sstever@eecs.umich.edu# include & library files
3773118Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3]
3783118Sstever@eecs.umich.edu
3793118Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4
3803716Sstever@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name)
3813118Sstever@eecs.umich.eduenv.Append(CPPPATH = py_header_path)
3823118Sstever@eecs.umich.edu# verify that it works
3833118Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
3843118Sstever@eecs.umich.edu    print "Error: can't find Python.h header in", py_header_path
3853118Sstever@eecs.umich.edu    Exit(1)
3863118Sstever@eecs.umich.edu
3873118Sstever@eecs.umich.edu# add library path too if it's not in the default place
3883118Sstever@eecs.umich.edupy_lib_path = None
3893118Sstever@eecs.umich.eduif sys.exec_prefix != '/usr':
3903716Sstever@eecs.umich.edu    py_lib_path = joinpath(sys.exec_prefix, 'lib')
3913118Sstever@eecs.umich.eduelif sys.platform == 'cygwin':
3923118Sstever@eecs.umich.edu    # cygwin puts the .dll in /bin for some reason
3933118Sstever@eecs.umich.edu    py_lib_path = '/bin'
3943118Sstever@eecs.umich.eduif py_lib_path:
3953118Sstever@eecs.umich.edu    env.Append(LIBPATH = py_lib_path)
3963118Sstever@eecs.umich.edu    print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
3973118Sstever@eecs.umich.eduif not conf.CheckLib(py_version_name):
3983118Sstever@eecs.umich.edu    print "Error: can't find Python library", py_version_name
3993118Sstever@eecs.umich.edu    Exit(1)
4003118Sstever@eecs.umich.edu
4013483Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops
4023494Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4033494Ssaidi@eecs.umich.edu   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4043483Ssaidi@eecs.umich.edu       print "Can't find library with socket calls (e.g. accept())"
4053483Ssaidi@eecs.umich.edu       Exit(1)
4063483Ssaidi@eecs.umich.edu
4073053Sstever@eecs.umich.edu# Check for zlib.  If the check passes, libz will be automatically
4083053Sstever@eecs.umich.edu# added to the LIBS environment variable.
4093918Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
4103053Sstever@eecs.umich.edu    print 'Error: did not find needed zlib compression library '\
4113053Sstever@eecs.umich.edu          'and/or zlib.h header file.'
4123053Sstever@eecs.umich.edu    print '       Please install zlib and try again.'
4133053Sstever@eecs.umich.edu    Exit(1)
4143053Sstever@eecs.umich.edu
4151858SN/A# Check for <fenv.h> (C99 FP environment control)
4161858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>')
4171858SN/Aif not have_fenv:
4181858SN/A    print "Warning: Header file <fenv.h> not found."
4191858SN/A    print "         This host has no IEEE FP rounding mode control."
4201858SN/A
4211859SN/A# Check for mysql.
4221858SN/Amysql_config = WhereIs('mysql_config')
4231858SN/Ahave_mysql = mysql_config != None
4241858SN/A
4251859SN/A# Check MySQL version.
4261859SN/Aif have_mysql:
4271862SN/A    mysql_version = os.popen(mysql_config + ' --version').read()
4283053Sstever@eecs.umich.edu    min_mysql_version = '4.1'
4293053Sstever@eecs.umich.edu    if compare_versions(mysql_version, min_mysql_version) < 0:
4303053Sstever@eecs.umich.edu        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
4313053Sstever@eecs.umich.edu        print '         Version', mysql_version, 'detected.'
4321859SN/A        have_mysql = False
4331859SN/A
4341859SN/A# Set up mysql_config commands.
4351859SN/Aif have_mysql:
4361859SN/A    mysql_config_include = mysql_config + ' --include'
4371859SN/A    if os.system(mysql_config_include + ' > /dev/null') != 0:
4381859SN/A        # older mysql_config versions don't support --include, use
4391859SN/A        # --cflags instead
4401862SN/A        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
4411859SN/A    # This seems to work in all versions
4421859SN/A    mysql_config_libs = mysql_config + ' --libs'
4431859SN/A
4441858SN/Aenv = conf.Finish()
4451858SN/A
4462139SN/A# Define the universe of supported ISAs
4474202Sbinkertn@umich.eduall_isa_list = [ ]
4484202Sbinkertn@umich.eduExport('all_isa_list')
4492139SN/A
4502155SN/A# Define the universe of supported CPU models
4514202Sbinkertn@umich.eduall_cpu_list = [ ]
4524202Sbinkertn@umich.edudefault_cpus = [ ]
4534202Sbinkertn@umich.eduExport('all_cpu_list', 'default_cpus')
4542155SN/A
4551869SN/A# Sticky options get saved in the options file so they persist from
4561869SN/A# one invocation to the next (unless overridden, in which case the new
4571869SN/A# value becomes sticky).
4581869SN/Asticky_opts = Options(args=ARGUMENTS)
4594202Sbinkertn@umich.eduExport('sticky_opts')
4604202Sbinkertn@umich.edu
4614202Sbinkertn@umich.edu# Non-sticky options only apply to the current build.
4624202Sbinkertn@umich.edunonsticky_opts = Options(args=ARGUMENTS)
4634202Sbinkertn@umich.eduExport('nonsticky_opts')
4644202Sbinkertn@umich.edu
4654202Sbinkertn@umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the
4664202Sbinkertn@umich.edu# above options
4674202Sbinkertn@umich.edufor root, dirs, files in os.walk('.'):
4684202Sbinkertn@umich.edu    if 'SConsopts' in files:
4694202Sbinkertn@umich.edu        SConscript(os.path.join(root, 'SConsopts'))
4704202Sbinkertn@umich.edu
4714202Sbinkertn@umich.eduall_isa_list.sort()
4724202Sbinkertn@umich.eduall_cpu_list.sort()
4734202Sbinkertn@umich.edudefault_cpus.sort()
4744202Sbinkertn@umich.edu
4754773Snate@binkert.orgdef ExtraPathValidator(key, val, env):
4764775Snate@binkert.org    if not val:
4774775Snate@binkert.org        return
4784773Snate@binkert.org    paths = val.split(':')
4794773Snate@binkert.org    for path in paths:
4804773Snate@binkert.org        path = os.path.expanduser(path)
4814773Snate@binkert.org        if not isdir(path):
4824773Snate@binkert.org            raise AttributeError, "Invalid path: '%s'" % path
4834773Snate@binkert.org
4841869SN/Asticky_opts.AddOptions(
4854202Sbinkertn@umich.edu    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
4861869SN/A    BoolOption('FULL_SYSTEM', 'Full-system support', False),
4872508SN/A    # There's a bug in scons 0.96.1 that causes ListOptions with list
4882508SN/A    # values (more than one value) not to be able to be restored from
4892508SN/A    # a saved option file.  If this causes trouble then upgrade to
4902508SN/A    # scons 0.96.90 or later.
4914202Sbinkertn@umich.edu    ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
4921869SN/A    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
4931869SN/A    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
4941869SN/A               False),
4951869SN/A    BoolOption('SS_COMPATIBLE_FP',
4961869SN/A               'Make floating-point results compatible with SimpleScalar',
4971869SN/A               False),
4981965SN/A    BoolOption('USE_SSE2',
4991965SN/A               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
5001965SN/A               False),
5011869SN/A    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
5021869SN/A    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
5032733Sktlim@umich.edu    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
5041869SN/A    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
5051884SN/A    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
5061884SN/A    BoolOption('BATCH', 'Use batch pool for build and tests', False),
5073356Sbinkertn@umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
5083356Sbinkertn@umich.edu    ('PYTHONHOME',
5093356Sbinkertn@umich.edu     'Override the default PYTHONHOME for this system (use with caution)',
5104773Snate@binkert.org     '%s:%s' % (sys.prefix, sys.exec_prefix)),
5114773Snate@binkert.org    ('EXTRAS', 'Add Extra directories to the compilation', '',
5124773Snate@binkert.org     ExtraPathValidator)
5131869SN/A    )
5141858SN/A
5151869SN/Anonsticky_opts.AddOptions(
5161869SN/A    BoolOption('update_ref', 'Update test reference outputs', False)
5171869SN/A    )
5181858SN/A
5192761Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript).
5201869SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
5212733Sktlim@umich.edu                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
5223584Ssaidi@eecs.umich.edu                     'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
5231869SN/A
5241869SN/A# Define a handy 'no-op' action
5251869SN/Adef no_action(target, source, env):
5261869SN/A    return 0
5271869SN/A
5281869SN/Aenv.NoAction = Action(no_action, None)
5291858SN/A
530955SN/A###################################################
531955SN/A#
5321869SN/A# Define a SCons builder for configuration flag headers.
5331869SN/A#
5341869SN/A###################################################
5351869SN/A
5361869SN/A# This function generates a config header file that #defines the
5371869SN/A# option symbol to the current option setting (0 or 1).  The source
5381869SN/A# operands are the name of the option and a Value node containing the
5391869SN/A# value of the option.
5401869SN/Adef build_config_file(target, source, env):
5411869SN/A    (option, value) = [s.get_contents() for s in source]
5421869SN/A    f = file(str(target[0]), 'w')
5431869SN/A    print >> f, '#define', option, value
5441869SN/A    f.close()
5451869SN/A    return None
5461869SN/A
5471869SN/A# Generate the message to be printed when building the config file.
5481869SN/Adef build_config_file_string(target, source, env):
5491869SN/A    (option, value) = [s.get_contents() for s in source]
5501869SN/A    return "Defining %s as %s in %s." % (option, value, target[0])
5511869SN/A
5521869SN/A# Combine the two functions into a scons Action object.
5531869SN/Aconfig_action = Action(build_config_file, build_config_file_string)
5541869SN/A
5551869SN/A# The emitter munges the source & target node lists to reflect what
5561869SN/A# we're really doing.
5571869SN/Adef config_emitter(target, source, env):
5581869SN/A    # extract option name from Builder arg
5591869SN/A    option = str(target[0])
5601869SN/A    # True target is config header file
5613716Sstever@eecs.umich.edu    target = joinpath('config', option.lower() + '.hh')
5623356Sbinkertn@umich.edu    val = env[option]
5633356Sbinkertn@umich.edu    if isinstance(val, bool):
5643356Sbinkertn@umich.edu        # Force value to 0/1
5653356Sbinkertn@umich.edu        val = int(val)
5663356Sbinkertn@umich.edu    elif isinstance(val, str):
5673356Sbinkertn@umich.edu        val = '"' + val + '"'
5684781Snate@binkert.org
5691869SN/A    # Sources are option name & value (packaged in SCons Value nodes)
5701869SN/A    return ([target], [Value(option), Value(val)])
5711869SN/A
5721869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
5731869SN/A
5741869SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
5751869SN/A
5762655Sstever@eecs.umich.edu###################################################
5772655Sstever@eecs.umich.edu#
5782655Sstever@eecs.umich.edu# Define a SCons builder for copying files.  This is used by the
5792655Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here
5802655Sstever@eecs.umich.edu# since it's potentially more generally applicable.
5812655Sstever@eecs.umich.edu#
5822655Sstever@eecs.umich.edu###################################################
5832655Sstever@eecs.umich.edu
5842655Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
5852655Sstever@eecs.umich.edu
5862655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
5872655Sstever@eecs.umich.edu
5882655Sstever@eecs.umich.edu###################################################
5892655Sstever@eecs.umich.edu#
5902655Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files.
5912655Sstever@eecs.umich.edu#
5922655Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable.
5932655Sstever@eecs.umich.edu#
5942655Sstever@eecs.umich.edu###################################################
5952655Sstever@eecs.umich.edu
5962655Sstever@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
5972655Sstever@eecs.umich.edu                                          'chmod +x $TARGET']))
5982655Sstever@eecs.umich.edu
5992655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder })
6002655Sstever@eecs.umich.edu
6012655Sstever@eecs.umich.edu
6022634Sstever@eecs.umich.edu# base help text
6032634Sstever@eecs.umich.eduhelp_text = '''
6042634Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)]
6052634Sstever@eecs.umich.edu
6062634Sstever@eecs.umich.edu'''
6072634Sstever@eecs.umich.edu
6082638Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root.
6092638Sstever@eecs.umich.eduenv.SConscript('ext/libelf/SConscript',
6103716Sstever@eecs.umich.edu               build_dir = joinpath(build_root, 'libelf'),
6112638Sstever@eecs.umich.edu               exports = 'env')
6122638Sstever@eecs.umich.edu
6131869SN/A###################################################
6141869SN/A#
6153546Sgblack@eecs.umich.edu# This function is used to set up a directory with switching headers
6163546Sgblack@eecs.umich.edu#
6173546Sgblack@eecs.umich.edu###################################################
6183546Sgblack@eecs.umich.edu
6194202Sbinkertn@umich.eduenv['ALL_ISA_LIST'] = all_isa_list
6203546Sgblack@eecs.umich.edudef make_switching_dir(dirname, switch_headers, env):
6213546Sgblack@eecs.umich.edu    # Generate the header.  target[0] is the full path of the output
6223546Sgblack@eecs.umich.edu    # header to generate.  'source' is a dummy variable, since we get the
6233546Sgblack@eecs.umich.edu    # list of ISAs from env['ALL_ISA_LIST'].
6243546Sgblack@eecs.umich.edu    def gen_switch_hdr(target, source, env):
6254781Snate@binkert.org        fname = str(target[0])
6264781Snate@binkert.org        basename = os.path.basename(fname)
6274781Snate@binkert.org        f = open(fname, 'w')
6284781Snate@binkert.org        f.write('#include "arch/isa_specific.hh"\n')
6294781Snate@binkert.org        cond = '#if'
6304781Snate@binkert.org        for isa in all_isa_list:
6314781Snate@binkert.org            f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
6324781Snate@binkert.org                    % (cond, isa.upper(), dirname, isa, basename))
6334781Snate@binkert.org            cond = '#elif'
6344781Snate@binkert.org        f.write('#else\n#error "THE_ISA not set"\n#endif\n')
6354781Snate@binkert.org        f.close()
6364781Snate@binkert.org        return 0
6373546Sgblack@eecs.umich.edu
6383546Sgblack@eecs.umich.edu    # String to print when generating header
6393546Sgblack@eecs.umich.edu    def gen_switch_hdr_string(target, source, env):
6404781Snate@binkert.org        return "Generating switch header " + str(target[0])
6413546Sgblack@eecs.umich.edu
6423546Sgblack@eecs.umich.edu    # Build SCons Action object. 'varlist' specifies env vars that this
6433546Sgblack@eecs.umich.edu    # action depends on; when env['ALL_ISA_LIST'] changes these actions
6443546Sgblack@eecs.umich.edu    # should get re-executed.
6453546Sgblack@eecs.umich.edu    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
6463546Sgblack@eecs.umich.edu                               varlist=['ALL_ISA_LIST'])
6473546Sgblack@eecs.umich.edu
6483546Sgblack@eecs.umich.edu    # Instantiate actions for each header
6493546Sgblack@eecs.umich.edu    for hdr in switch_headers:
6503546Sgblack@eecs.umich.edu        env.Command(hdr, [], switch_hdr_action)
6514202Sbinkertn@umich.eduExport('make_switching_dir')
6523546Sgblack@eecs.umich.edu
6533546Sgblack@eecs.umich.edu###################################################
6543546Sgblack@eecs.umich.edu#
655955SN/A# Define build environments for selected configurations.
656955SN/A#
657955SN/A###################################################
658955SN/A
6591858SN/A# rename base env
6601858SN/Abase_env = env
6611858SN/A
6622632Sstever@eecs.umich.edufor build_path in build_paths:
6632632Sstever@eecs.umich.edu    print "Building in", build_path
6644773Snate@binkert.org    env['BUILDDIR'] = build_path
6654773Snate@binkert.org
6662632Sstever@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
6672632Sstever@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
6682632Sstever@eecs.umich.edu    (build_root, build_dir) = os.path.split(build_path)
6692634Sstever@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
6702638Sstever@eecs.umich.edu    env = base_env.Copy()
6712023SN/A
6722632Sstever@eecs.umich.edu    # Set env options according to the build directory config.
6732632Sstever@eecs.umich.edu    sticky_opts.files = []
6742632Sstever@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
6752632Sstever@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
6762632Sstever@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
6773716Sstever@eecs.umich.edu    current_opts_file = joinpath(build_root, 'options', build_dir)
6782632Sstever@eecs.umich.edu    if os.path.isfile(current_opts_file):
6792632Sstever@eecs.umich.edu        sticky_opts.files.append(current_opts_file)
6802632Sstever@eecs.umich.edu        print "Using saved options file %s" % current_opts_file
6812632Sstever@eecs.umich.edu    else:
6822632Sstever@eecs.umich.edu        # Build dir-specific options file doesn't exist.
6832023SN/A
6842632Sstever@eecs.umich.edu        # Make sure the directory is there so we can create it later
6852632Sstever@eecs.umich.edu        opt_dir = os.path.dirname(current_opts_file)
6861889SN/A        if not os.path.isdir(opt_dir):
6871889SN/A            os.mkdir(opt_dir)
6882632Sstever@eecs.umich.edu
6892632Sstever@eecs.umich.edu        # Get default build options from source tree.  Options are
6902632Sstever@eecs.umich.edu        # normally determined by name of $BUILD_DIR, but can be
6912632Sstever@eecs.umich.edu        # overriden by 'default=' arg on command line.
6923716Sstever@eecs.umich.edu        default_opts_file = joinpath('build_opts',
6933716Sstever@eecs.umich.edu                                     ARGUMENTS.get('default', build_dir))
6942632Sstever@eecs.umich.edu        if os.path.isfile(default_opts_file):
6952632Sstever@eecs.umich.edu            sticky_opts.files.append(default_opts_file)
6962632Sstever@eecs.umich.edu            print "Options file %s not found,\n  using defaults in %s" \
6972632Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
6982632Sstever@eecs.umich.edu        else:
6992632Sstever@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
7002632Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
7012632Sstever@eecs.umich.edu            Exit(1)
7021888SN/A
7031888SN/A    # Apply current option settings to env
7041869SN/A    sticky_opts.Update(env)
7051869SN/A    nonsticky_opts.Update(env)
7061858SN/A
7072598SN/A    help_text += "Sticky options for %s:\n" % build_dir \
7082598SN/A                 + sticky_opts.GenerateHelpText(env) \
7092598SN/A                 + "\nNon-sticky options for %s:\n" % build_dir \
7102598SN/A                 + nonsticky_opts.GenerateHelpText(env)
7112598SN/A
7121858SN/A    # Process option settings.
7131858SN/A
7141858SN/A    if not have_fenv and env['USE_FENV']:
7151858SN/A        print "Warning: <fenv.h> not available; " \
7161858SN/A              "forcing USE_FENV to False in", build_dir + "."
7171858SN/A        env['USE_FENV'] = False
7181858SN/A
7191858SN/A    if not env['USE_FENV']:
7201858SN/A        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
7211871SN/A        print "         FP results may deviate slightly from other platforms."
7221858SN/A
7231858SN/A    if env['EFENCE']:
7241858SN/A        env.Append(LIBS=['efence'])
7251858SN/A
7261858SN/A    if env['USE_MYSQL']:
7271858SN/A        if not have_mysql:
7281858SN/A            print "Warning: MySQL not available; " \
7291858SN/A                  "forcing USE_MYSQL to False in", build_dir + "."
7301858SN/A            env['USE_MYSQL'] = False
7311858SN/A        else:
7321858SN/A            print "Compiling in", build_dir, "with MySQL support."
7331859SN/A            env.ParseConfig(mysql_config_libs)
7341859SN/A            env.ParseConfig(mysql_config_include)
7351869SN/A
7361888SN/A    # Save sticky option settings back to current options file
7372632Sstever@eecs.umich.edu    sticky_opts.Save(current_opts_file, env)
7381869SN/A
7391884SN/A    # Do this after we save setting back, or else we'll tack on an
7401884SN/A    # extra 'qdo' every time we run scons.
7411884SN/A    if env['BATCH']:
7421884SN/A        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
7431884SN/A        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
7441884SN/A
7451965SN/A    if env['USE_SSE2']:
7461965SN/A        env.Append(CCFLAGS='-msse2')
7471965SN/A
7482761Sstever@eecs.umich.edu    # The src/SConscript file sets up the build rules in 'env' according
7491869SN/A    # to the configured options.  It returns a list of environments,
7501869SN/A    # one for each variant build (debug, opt, etc.)
7512632Sstever@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
7522667Sstever@eecs.umich.edu                         exports = 'env')
7531869SN/A
7541869SN/A    # Set up the regression tests for each build.
7552929Sktlim@umich.edu    for e in envList:
7562929Sktlim@umich.edu        SConscript('tests/SConscript',
7573716Sstever@eecs.umich.edu                   build_dir = joinpath(build_path, 'tests', e.Label),
7582929Sktlim@umich.edu                   exports = { 'env' : e }, duplicate = False)
759955SN/A
7602598SN/AHelp(help_text)
7612598SN/A
7623546Sgblack@eecs.umich.edu
763955SN/A###################################################
764955SN/A#
765955SN/A# Let SCons do its thing.  At this point SCons will use the defined
7661530SN/A# build environments to build the requested targets.
767955SN/A#
768955SN/A###################################################
769955SN/A
770