SConstruct revision 5385
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
695342Sstever@gmail.comfrom os.path import isdir, isfile, join as joinpath
70955SN/A
715273Sstever@gmail.comimport SCons
725273Sstever@gmail.com
732656Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions.  If your system's
742656Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a
752656Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1)
762656Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python'
772656Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the
782656Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
792656Sstever@eecs.umich.eduEnsurePythonVersion(2,4)
802653Sstever@eecs.umich.edu
815227Ssaidi@eecs.umich.edu# Import subprocess after we check the version since it doesn't exist in
825227Ssaidi@eecs.umich.edu# Python < 2.4.
835227Ssaidi@eecs.umich.eduimport subprocess
845227Ssaidi@eecs.umich.edu
852653Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
862653Sstever@eecs.umich.edu# 3-element version number.
872653Sstever@eecs.umich.edumin_scons_version = (0,96,91)
882653Sstever@eecs.umich.edutry:
892653Sstever@eecs.umich.edu    EnsureSConsVersion(*min_scons_version)
902653Sstever@eecs.umich.eduexcept:
912653Sstever@eecs.umich.edu    print "Error checking current SCons version."
922653Sstever@eecs.umich.edu    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
932653Sstever@eecs.umich.edu    Exit(2)
944781Snate@binkert.org
951852SN/A
96955SN/A# The absolute path to the current directory (where this file lives).
97955SN/AROOT = Dir('.').abspath
98955SN/A
993717Sstever@eecs.umich.edu# Path to the M5 source tree.
1003716Sstever@eecs.umich.eduSRCDIR = joinpath(ROOT, 'src')
101955SN/A
1021533SN/A# tell python where to find m5 python code
1033716Sstever@eecs.umich.edusys.path.append(joinpath(ROOT, 'src/python'))
1041533SN/A
1054678Snate@binkert.orgdef check_style_hook(ui):
1064678Snate@binkert.org    ui.readconfig(joinpath(ROOT, '.hg', 'hgrc'))
1074678Snate@binkert.org    style_hook = ui.config('hooks', 'pretxncommit.style', None)
1084678Snate@binkert.org
1094678Snate@binkert.org    if not style_hook:
1104678Snate@binkert.org        print """\
1114678Snate@binkert.orgYou're missing the M5 style hook.
1124678Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style.
1134678Snate@binkert.org
1144678Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc
1154678Snate@binkert.orgor your personal .hgrc
1164678Snate@binkert.org----------------
1174678Snate@binkert.org
1184678Snate@binkert.org[extensions]
1194678Snate@binkert.orgstyle = %s/util/style.py
1204678Snate@binkert.org
1214678Snate@binkert.org[hooks]
1224678Snate@binkert.orgpretxncommit.style = python:style.check_whitespace
1234678Snate@binkert.org""" % (ROOT)
1244678Snate@binkert.org        sys.exit(1)
1254678Snate@binkert.org
1264973Ssaidi@eecs.umich.eduif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')):
1274678Snate@binkert.org    try:
1284678Snate@binkert.org        from mercurial import ui
1294678Snate@binkert.org        check_style_hook(ui.ui())
1304678Snate@binkert.org    except ImportError:
1314678Snate@binkert.org        pass
1324678Snate@binkert.org
133955SN/A###################################################
134955SN/A#
1352632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
1362632Sstever@eecs.umich.edu# the target(s).
137955SN/A#
138955SN/A###################################################
139955SN/A
140955SN/A# Find default configuration & binary.
1412632Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
142955SN/A
1432632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
1442632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
1452632Sstever@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1462632Sstever@eecs.umich.edu        if l[i] == elt:
1472632Sstever@eecs.umich.edu            return i
1482632Sstever@eecs.umich.edu    raise ValueError, "element not found"
1492632Sstever@eecs.umich.edu
1503053Sstever@eecs.umich.edu# helper function: compare dotted version numbers.
1513053Sstever@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1')
1523053Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2
1533053Sstever@eecs.umich.edudef compare_versions(v1, v2):
1543053Sstever@eecs.umich.edu    # Convert dotted strings to lists
1553053Sstever@eecs.umich.edu    v1 = map(int, v1.split('.'))
1563053Sstever@eecs.umich.edu    v2 = map(int, v2.split('.'))
1573053Sstever@eecs.umich.edu    # Compare corresponding elements of lists
1583053Sstever@eecs.umich.edu    for n1,n2 in zip(v1, v2):
1593053Sstever@eecs.umich.edu        if n1 < n2: return -1
1603053Sstever@eecs.umich.edu        if n1 > n2: return  1
1613053Sstever@eecs.umich.edu    # all corresponding values are equal... see if one has extra values
1623053Sstever@eecs.umich.edu    if len(v1) < len(v2): return -1
1633053Sstever@eecs.umich.edu    if len(v1) > len(v2): return  1
1643053Sstever@eecs.umich.edu    return 0
1653053Sstever@eecs.umich.edu
1662632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1672632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
1682632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1692632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1702632Sstever@eecs.umich.edu# follow 'build' in the bulid path.
1712632Sstever@eecs.umich.edu
1723718Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is
1733718Sstever@eecs.umich.eduif COMMAND_LINE_TARGETS:
1743718Sstever@eecs.umich.edu    # Ask SCons which directory it was invoked from
1753718Sstever@eecs.umich.edu    launch_dir = GetLaunchDir()
1763718Sstever@eecs.umich.edu    # Make targets relative to invocation directory
1773718Sstever@eecs.umich.edu    abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))),
1783718Sstever@eecs.umich.edu                      COMMAND_LINE_TARGETS)
1793718Sstever@eecs.umich.eduelse:
1803718Sstever@eecs.umich.edu    # Default targets are relative to root of tree
1813718Sstever@eecs.umich.edu    abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))),
1823718Sstever@eecs.umich.edu                      DEFAULT_TARGETS)
1833718Sstever@eecs.umich.edu
1843718Sstever@eecs.umich.edu
1852634Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the
1862634Sstever@eecs.umich.edu# collected targets reference.
1872632Sstever@eecs.umich.edubuild_paths = []
1882638Sstever@eecs.umich.edubuild_root = None
1892632Sstever@eecs.umich.edufor t in abs_targets:
1902632Sstever@eecs.umich.edu    path_dirs = t.split('/')
1912632Sstever@eecs.umich.edu    try:
1922632Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1932632Sstever@eecs.umich.edu    except:
1942632Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1951858SN/A        Exit(1)
1963716Sstever@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
1972638Sstever@eecs.umich.edu    if not build_root:
1982638Sstever@eecs.umich.edu        build_root = this_build_root
1992638Sstever@eecs.umich.edu    else:
2002638Sstever@eecs.umich.edu        if this_build_root != build_root:
2012638Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
2022638Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
2032638Sstever@eecs.umich.edu            Exit(1)
2043716Sstever@eecs.umich.edu    build_path = joinpath('/',*path_dirs[:build_top+2])
2052634Sstever@eecs.umich.edu    if build_path not in build_paths:
2062634Sstever@eecs.umich.edu        build_paths.append(build_path)
207955SN/A
2085341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there)
2095341Sstever@gmail.comif not isdir(build_root):
2105341Sstever@gmail.com    os.mkdir(build_root)
2115341Sstever@gmail.com
212955SN/A###################################################
213955SN/A#
214955SN/A# Set up the default build environment.  This environment is copied
215955SN/A# and modified according to each selected configuration.
216955SN/A#
217955SN/A###################################################
218955SN/A
2191858SN/Aenv = Environment(ENV = os.environ,  # inherit user's environment vars
2201858SN/A                  ROOT = ROOT,
2212632Sstever@eecs.umich.edu                  SRCDIR = SRCDIR)
222955SN/A
2234494Ssaidi@eecs.umich.eduExport('env')
2244494Ssaidi@eecs.umich.edu
2253716Sstever@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign"))
2261105SN/A
2272667Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up
2282667Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
2292667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
2302667Sstever@eecs.umich.edu# (soft) links work better.
2312667Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy')
2322667Sstever@eecs.umich.edu
2331869SN/A# I waffle on this setting... it does avoid a few painful but
2341869SN/A# unnecessary builds, but it also seems to make trivial builds take
2351869SN/A# noticeably longer.
2361869SN/Aif False:
2371869SN/A    env.TargetSignatures('content')
2381065SN/A
2395341Sstever@gmail.com#
2405341Sstever@gmail.com# Set up global sticky options... these are common to an entire build
2415341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE)
2425341Sstever@gmail.com#
2435341Sstever@gmail.com
2445341Sstever@gmail.com# Option validators & converters for global sticky options
2455341Sstever@gmail.comdef PathListMakeAbsolute(val):
2465341Sstever@gmail.com    if not val:
2475341Sstever@gmail.com        return val
2485341Sstever@gmail.com    f = lambda p: os.path.abspath(os.path.expanduser(p))
2495341Sstever@gmail.com    return ':'.join(map(f, val.split(':')))
2505341Sstever@gmail.com
2515341Sstever@gmail.comdef PathListAllExist(key, val, env):
2525341Sstever@gmail.com    if not val:
2535341Sstever@gmail.com        return
2545341Sstever@gmail.com    paths = val.split(':')
2555341Sstever@gmail.com    for path in paths:
2565341Sstever@gmail.com        if not isdir(path):
2575341Sstever@gmail.com            raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
2585341Sstever@gmail.com
2595341Sstever@gmail.comglobal_sticky_opts_file = joinpath(build_root, 'options.global')
2605341Sstever@gmail.com
2615341Sstever@gmail.comglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS)
2625341Sstever@gmail.com
2635341Sstever@gmail.comglobal_sticky_opts.AddOptions(
2645341Sstever@gmail.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2655341Sstever@gmail.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2665341Sstever@gmail.com    ('EXTRAS', 'Add Extra directories to the compilation', '',
2675341Sstever@gmail.com     PathListAllExist, PathListMakeAbsolute)
2685341Sstever@gmail.com    )    
2695341Sstever@gmail.com
2705341Sstever@gmail.com
2715341Sstever@gmail.com# base help text
2725341Sstever@gmail.comhelp_text = '''
2735341Sstever@gmail.comUsage: scons [scons options] [build options] [target(s)]
2745341Sstever@gmail.com
2755341Sstever@gmail.com'''
2765341Sstever@gmail.com
2775341Sstever@gmail.comhelp_text += "Global sticky options:\n" \
2785341Sstever@gmail.com             + global_sticky_opts.GenerateHelpText(env)
2795341Sstever@gmail.com
2805341Sstever@gmail.com# Update env with values from ARGUMENTS & file global_sticky_opts_file
2815341Sstever@gmail.comglobal_sticky_opts.Update(env)
2825341Sstever@gmail.com
2835341Sstever@gmail.com# Save sticky option settings back to current options file
2845341Sstever@gmail.comglobal_sticky_opts.Save(global_sticky_opts_file, env)
2855341Sstever@gmail.com
2865341Sstever@gmail.com# Parse EXTRAS option to build list of all directories where we're
2875341Sstever@gmail.com# look for sources etc.  This list is exported as base_dir_list.
2885344Sstever@gmail.combase_dir_list = [joinpath(ROOT, 'src')]
2895341Sstever@gmail.comif env['EXTRAS']:
2905341Sstever@gmail.com    base_dir_list += env['EXTRAS'].split(':')
2915341Sstever@gmail.com
2925341Sstever@gmail.comExport('base_dir_list')
2935341Sstever@gmail.com
2942632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
2955199Sstever@gmail.comenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) })
2963918Ssaidi@eecs.umich.eduenv['GCC'] = False
2973918Ssaidi@eecs.umich.eduenv['SUNCC'] = False
2983940Ssaidi@eecs.umich.eduenv['ICC'] = False
2994781Snate@binkert.orgenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True,
3004781Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3013918Ssaidi@eecs.umich.edu        close_fds=True).communicate()[0].find('GCC') >= 0
3024781Snate@binkert.orgenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
3034781Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3043918Ssaidi@eecs.umich.edu        close_fds=True).communicate()[0].find('Sun C++') >= 0
3054781Snate@binkert.orgenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
3064781Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3073940Ssaidi@eecs.umich.edu        close_fds=True).communicate()[0].find('Intel') >= 0
3083942Ssaidi@eecs.umich.eduif env['GCC'] + env['SUNCC'] + env['ICC'] > 1:
3093940Ssaidi@eecs.umich.edu    print 'Error: How can we have two at the same time?'
3103918Ssaidi@eecs.umich.edu    Exit(1)
3113918Ssaidi@eecs.umich.edu
312955SN/A
3131858SN/A# Set up default C++ compiler flags
3143918Ssaidi@eecs.umich.eduif env['GCC']:
3153918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-pipe')
3163918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-fno-strict-aliasing')
3173918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
3183940Ssaidi@eecs.umich.eduelif env['ICC']:
3193940Ssaidi@eecs.umich.edu    pass #Fix me... add warning flags once we clean up icc warnings
3203918Ssaidi@eecs.umich.eduelif env['SUNCC']:
3213918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-Qoption ccfe')
3223918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-features=gcc')
3233918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-features=extensions')
3243918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-library=stlport4')
3253918Ssaidi@eecs.umich.edu    env.Append(CCFLAGS='-xar')
3263918Ssaidi@eecs.umich.edu#    env.Append(CCFLAGS='-instances=semiexplicit')
3273918Ssaidi@eecs.umich.eduelse:
3283918Ssaidi@eecs.umich.edu    print 'Error: Don\'t know what compiler options to use for your compiler.'
3293940Ssaidi@eecs.umich.edu    print '       Please fix SConstruct and src/SConscript and try again.'
3303918Ssaidi@eecs.umich.edu    Exit(1)
3313918Ssaidi@eecs.umich.edu
3321851SN/Aif sys.platform == 'cygwin':
3331851SN/A    # cygwin has some header file issues...
3341858SN/A    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
3355200Sstever@gmail.comenv.Append(CPPPATH=[Dir('ext/dnet')])
336955SN/A
3373053Sstever@eecs.umich.edu# Check for SWIG
3383053Sstever@eecs.umich.eduif not env.has_key('SWIG'):
3393053Sstever@eecs.umich.edu    print 'Error: SWIG utility not found.'
3403053Sstever@eecs.umich.edu    print '       Please install (see http://www.swig.org) and retry.'
3413053Sstever@eecs.umich.edu    Exit(1)
3423053Sstever@eecs.umich.edu
3433053Sstever@eecs.umich.edu# Check for appropriate SWIG version
3443053Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split()
3453053Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z"
3464742Sstever@eecs.umich.eduif len(swig_version) < 3 or \
3474742Sstever@eecs.umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
3483053Sstever@eecs.umich.edu    print 'Error determining SWIG version.'
3493053Sstever@eecs.umich.edu    Exit(1)
3503053Sstever@eecs.umich.edu
3513053Sstever@eecs.umich.edumin_swig_version = '1.3.28'
3523053Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0:
3533053Sstever@eecs.umich.edu    print 'Error: SWIG version', min_swig_version, 'or newer required.'
3543053Sstever@eecs.umich.edu    print '       Installed version:', swig_version[2]
3553053Sstever@eecs.umich.edu    Exit(1)
3563053Sstever@eecs.umich.edu
3572667Sstever@eecs.umich.edu# Set up SWIG flags & scanner
3584554Sbinkertn@umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
3594554Sbinkertn@umich.eduenv.Append(SWIGFLAGS=swig_flags)
3602667Sstever@eecs.umich.edu
3614554Sbinkertn@umich.edu# filter out all existing swig scanners, they mess up the dependency
3624554Sbinkertn@umich.edu# stuff for some reason
3634554Sbinkertn@umich.eduscanners = []
3644554Sbinkertn@umich.edufor scanner in env['SCANNERS']:
3654554Sbinkertn@umich.edu    skeys = scanner.skeys
3664554Sbinkertn@umich.edu    if skeys == '.i':
3674554Sbinkertn@umich.edu        continue
3684781Snate@binkert.org
3694554Sbinkertn@umich.edu    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
3704554Sbinkertn@umich.edu        continue
3712667Sstever@eecs.umich.edu
3724554Sbinkertn@umich.edu    scanners.append(scanner)
3734554Sbinkertn@umich.edu
3744554Sbinkertn@umich.edu# add the new swig scanner that we like better
3754554Sbinkertn@umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner
3762667Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
3774554Sbinkertn@umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
3782667Sstever@eecs.umich.edu
3794554Sbinkertn@umich.edu# replace the scanners list that has what we want
3804554Sbinkertn@umich.eduenv['SCANNERS'] = scanners
3812667Sstever@eecs.umich.edu
3822638Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
3832638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
3842638Sstever@eecs.umich.educonf = Configure(env,
3853716Sstever@eecs.umich.edu                 conf_dir = joinpath(build_root, '.scons_config'),
3863716Sstever@eecs.umich.edu                 log_file = joinpath(build_root, 'scons_config.log'))
3871858SN/A
3885227Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
3895227Ssaidi@eecs.umich.edutry:
3905227Ssaidi@eecs.umich.edu    import platform
3915227Ssaidi@eecs.umich.edu    uname = platform.uname()
3925227Ssaidi@eecs.umich.edu    if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
3935227Ssaidi@eecs.umich.edu        if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True,
3945227Ssaidi@eecs.umich.edu               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3955227Ssaidi@eecs.umich.edu               close_fds=True).communicate()[0][0]):
3965227Ssaidi@eecs.umich.edu            env.Append(CCFLAGS='-arch x86_64')
3975227Ssaidi@eecs.umich.edu            env.Append(CFLAGS='-arch x86_64')
3985227Ssaidi@eecs.umich.edu            env.Append(LINKFLAGS='-arch x86_64')
3995227Ssaidi@eecs.umich.edu            env.Append(ASFLAGS='-arch x86_64')
4005274Ssaidi@eecs.umich.edu            env['OSX64bit'] = True
4015227Ssaidi@eecs.umich.eduexcept:
4025227Ssaidi@eecs.umich.edu    pass
4035227Ssaidi@eecs.umich.edu
4045204Sstever@gmail.com# Recent versions of scons substitute a "Null" object for Configure()
4055204Sstever@gmail.com# when configuration isn't necessary, e.g., if the "--help" option is
4065204Sstever@gmail.com# present.  Unfortuantely this Null object always returns false,
4075204Sstever@gmail.com# breaking all our configuration checks.  We replace it with our own
4085204Sstever@gmail.com# more optimistic null object that returns True instead.
4095204Sstever@gmail.comif not conf:
4105204Sstever@gmail.com    def NullCheck(*args, **kwargs):
4115204Sstever@gmail.com        return True
4125204Sstever@gmail.com
4135204Sstever@gmail.com    class NullConf:
4145204Sstever@gmail.com        def __init__(self, env):
4155204Sstever@gmail.com            self.env = env
4165204Sstever@gmail.com        def Finish(self):
4175204Sstever@gmail.com            return self.env
4185204Sstever@gmail.com        def __getattr__(self, mname):
4195204Sstever@gmail.com            return NullCheck
4205204Sstever@gmail.com
4215204Sstever@gmail.com    conf = NullConf(env)
4225204Sstever@gmail.com
4233118Sstever@eecs.umich.edu# Find Python include and library directories for embedding the
4243118Sstever@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
4253118Sstever@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
4263118Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
4273118Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
4283118Sstever@eecs.umich.edu
4293118Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating
4303118Sstever@eecs.umich.edu# include & library files
4313118Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3]
4323118Sstever@eecs.umich.edu
4333118Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4
4343716Sstever@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name)
4353118Sstever@eecs.umich.eduenv.Append(CPPPATH = py_header_path)
4363118Sstever@eecs.umich.edu# verify that it works
4373118Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
4383118Sstever@eecs.umich.edu    print "Error: can't find Python.h header in", py_header_path
4393118Sstever@eecs.umich.edu    Exit(1)
4403118Sstever@eecs.umich.edu
4413118Sstever@eecs.umich.edu# add library path too if it's not in the default place
4423118Sstever@eecs.umich.edupy_lib_path = None
4433118Sstever@eecs.umich.eduif sys.exec_prefix != '/usr':
4443716Sstever@eecs.umich.edu    py_lib_path = joinpath(sys.exec_prefix, 'lib')
4453118Sstever@eecs.umich.eduelif sys.platform == 'cygwin':
4463118Sstever@eecs.umich.edu    # cygwin puts the .dll in /bin for some reason
4473118Sstever@eecs.umich.edu    py_lib_path = '/bin'
4483118Sstever@eecs.umich.eduif py_lib_path:
4493118Sstever@eecs.umich.edu    env.Append(LIBPATH = py_lib_path)
4503118Sstever@eecs.umich.edu    print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
4513118Sstever@eecs.umich.eduif not conf.CheckLib(py_version_name):
4523118Sstever@eecs.umich.edu    print "Error: can't find Python library", py_version_name
4533118Sstever@eecs.umich.edu    Exit(1)
4543118Sstever@eecs.umich.edu
4553483Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops
4563494Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4573494Ssaidi@eecs.umich.edu   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4583483Ssaidi@eecs.umich.edu       print "Can't find library with socket calls (e.g. accept())"
4593483Ssaidi@eecs.umich.edu       Exit(1)
4603483Ssaidi@eecs.umich.edu
4613053Sstever@eecs.umich.edu# Check for zlib.  If the check passes, libz will be automatically
4623053Sstever@eecs.umich.edu# added to the LIBS environment variable.
4633918Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
4643053Sstever@eecs.umich.edu    print 'Error: did not find needed zlib compression library '\
4653053Sstever@eecs.umich.edu          'and/or zlib.h header file.'
4663053Sstever@eecs.umich.edu    print '       Please install zlib and try again.'
4673053Sstever@eecs.umich.edu    Exit(1)
4683053Sstever@eecs.umich.edu
4691858SN/A# Check for <fenv.h> (C99 FP environment control)
4701858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>')
4711858SN/Aif not have_fenv:
4721858SN/A    print "Warning: Header file <fenv.h> not found."
4731858SN/A    print "         This host has no IEEE FP rounding mode control."
4741858SN/A
4751859SN/A# Check for mysql.
4761858SN/Amysql_config = WhereIs('mysql_config')
4771858SN/Ahave_mysql = mysql_config != None
4781858SN/A
4791859SN/A# Check MySQL version.
4801859SN/Aif have_mysql:
4811862SN/A    mysql_version = os.popen(mysql_config + ' --version').read()
4823053Sstever@eecs.umich.edu    min_mysql_version = '4.1'
4833053Sstever@eecs.umich.edu    if compare_versions(mysql_version, min_mysql_version) < 0:
4843053Sstever@eecs.umich.edu        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
4853053Sstever@eecs.umich.edu        print '         Version', mysql_version, 'detected.'
4861859SN/A        have_mysql = False
4871859SN/A
4881859SN/A# Set up mysql_config commands.
4891859SN/Aif have_mysql:
4901859SN/A    mysql_config_include = mysql_config + ' --include'
4911859SN/A    if os.system(mysql_config_include + ' > /dev/null') != 0:
4921859SN/A        # older mysql_config versions don't support --include, use
4931859SN/A        # --cflags instead
4941862SN/A        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
4951859SN/A    # This seems to work in all versions
4961859SN/A    mysql_config_libs = mysql_config + ' --libs'
4971859SN/A
4981858SN/Aenv = conf.Finish()
4991858SN/A
5002139SN/A# Define the universe of supported ISAs
5014202Sbinkertn@umich.eduall_isa_list = [ ]
5024202Sbinkertn@umich.eduExport('all_isa_list')
5032139SN/A
5042155SN/A# Define the universe of supported CPU models
5054202Sbinkertn@umich.eduall_cpu_list = [ ]
5064202Sbinkertn@umich.edudefault_cpus = [ ]
5074202Sbinkertn@umich.eduExport('all_cpu_list', 'default_cpus')
5082155SN/A
5091869SN/A# Sticky options get saved in the options file so they persist from
5101869SN/A# one invocation to the next (unless overridden, in which case the new
5111869SN/A# value becomes sticky).
5121869SN/Asticky_opts = Options(args=ARGUMENTS)
5134202Sbinkertn@umich.eduExport('sticky_opts')
5144202Sbinkertn@umich.edu
5154202Sbinkertn@umich.edu# Non-sticky options only apply to the current build.
5164202Sbinkertn@umich.edunonsticky_opts = Options(args=ARGUMENTS)
5174202Sbinkertn@umich.eduExport('nonsticky_opts')
5184202Sbinkertn@umich.edu
5194202Sbinkertn@umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the
5204202Sbinkertn@umich.edu# above options
5215341Sstever@gmail.comfor base_dir in base_dir_list:
5225341Sstever@gmail.com    for root, dirs, files in os.walk(base_dir):
5235341Sstever@gmail.com        if 'SConsopts' in files:
5245342Sstever@gmail.com            print "Reading", joinpath(root, 'SConsopts')
5255342Sstever@gmail.com            SConscript(joinpath(root, 'SConsopts'))
5264202Sbinkertn@umich.edu
5274202Sbinkertn@umich.eduall_isa_list.sort()
5284202Sbinkertn@umich.eduall_cpu_list.sort()
5294202Sbinkertn@umich.edudefault_cpus.sort()
5304202Sbinkertn@umich.edu
5311869SN/Asticky_opts.AddOptions(
5324202Sbinkertn@umich.edu    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
5331869SN/A    BoolOption('FULL_SYSTEM', 'Full-system support', False),
5342508SN/A    # There's a bug in scons 0.96.1 that causes ListOptions with list
5352508SN/A    # values (more than one value) not to be able to be restored from
5362508SN/A    # a saved option file.  If this causes trouble then upgrade to
5372508SN/A    # scons 0.96.90 or later.
5384202Sbinkertn@umich.edu    ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
5391869SN/A    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
5405385Sstever@gmail.com    BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
5415385Sstever@gmail.com               False),
5425385Sstever@gmail.com    BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
5435385Sstever@gmail.com               False),
5441869SN/A    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
5451869SN/A               False),
5461869SN/A    BoolOption('SS_COMPATIBLE_FP',
5471869SN/A               'Make floating-point results compatible with SimpleScalar',
5481869SN/A               False),
5491965SN/A    BoolOption('USE_SSE2',
5501965SN/A               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
5511965SN/A               False),
5521869SN/A    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
5531869SN/A    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
5542733Sktlim@umich.edu    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
5551884SN/A    BoolOption('BATCH', 'Use batch pool for build and tests', False),
5563356Sbinkertn@umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
5573356Sbinkertn@umich.edu    ('PYTHONHOME',
5583356Sbinkertn@umich.edu     'Override the default PYTHONHOME for this system (use with caution)',
5594773Snate@binkert.org     '%s:%s' % (sys.prefix, sys.exec_prefix)),
5601869SN/A    )
5611858SN/A
5621869SN/Anonsticky_opts.AddOptions(
5631869SN/A    BoolOption('update_ref', 'Update test reference outputs', False)
5641869SN/A    )
5651858SN/A
5662761Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript).
5671869SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
5685385Sstever@gmail.com                     'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \
5695385Sstever@gmail.com                     'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \
5703584Ssaidi@eecs.umich.edu                     'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
5711869SN/A
5721869SN/A# Define a handy 'no-op' action
5731869SN/Adef no_action(target, source, env):
5741869SN/A    return 0
5751869SN/A
5761869SN/Aenv.NoAction = Action(no_action, None)
5771858SN/A
578955SN/A###################################################
579955SN/A#
5801869SN/A# Define a SCons builder for configuration flag headers.
5811869SN/A#
5821869SN/A###################################################
5831869SN/A
5841869SN/A# This function generates a config header file that #defines the
5851869SN/A# option symbol to the current option setting (0 or 1).  The source
5861869SN/A# operands are the name of the option and a Value node containing the
5871869SN/A# value of the option.
5881869SN/Adef build_config_file(target, source, env):
5891869SN/A    (option, value) = [s.get_contents() for s in source]
5901869SN/A    f = file(str(target[0]), 'w')
5911869SN/A    print >> f, '#define', option, value
5921869SN/A    f.close()
5931869SN/A    return None
5941869SN/A
5951869SN/A# Generate the message to be printed when building the config file.
5961869SN/Adef build_config_file_string(target, source, env):
5971869SN/A    (option, value) = [s.get_contents() for s in source]
5981869SN/A    return "Defining %s as %s in %s." % (option, value, target[0])
5991869SN/A
6001869SN/A# Combine the two functions into a scons Action object.
6011869SN/Aconfig_action = Action(build_config_file, build_config_file_string)
6021869SN/A
6031869SN/A# The emitter munges the source & target node lists to reflect what
6041869SN/A# we're really doing.
6051869SN/Adef config_emitter(target, source, env):
6061869SN/A    # extract option name from Builder arg
6071869SN/A    option = str(target[0])
6081869SN/A    # True target is config header file
6093716Sstever@eecs.umich.edu    target = joinpath('config', option.lower() + '.hh')
6103356Sbinkertn@umich.edu    val = env[option]
6113356Sbinkertn@umich.edu    if isinstance(val, bool):
6123356Sbinkertn@umich.edu        # Force value to 0/1
6133356Sbinkertn@umich.edu        val = int(val)
6143356Sbinkertn@umich.edu    elif isinstance(val, str):
6153356Sbinkertn@umich.edu        val = '"' + val + '"'
6164781Snate@binkert.org
6171869SN/A    # Sources are option name & value (packaged in SCons Value nodes)
6181869SN/A    return ([target], [Value(option), Value(val)])
6191869SN/A
6201869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
6211869SN/A
6221869SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
6231869SN/A
6242655Sstever@eecs.umich.edu###################################################
6252655Sstever@eecs.umich.edu#
6262655Sstever@eecs.umich.edu# Define a SCons builder for copying files.  This is used by the
6272655Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here
6282655Sstever@eecs.umich.edu# since it's potentially more generally applicable.
6292655Sstever@eecs.umich.edu#
6302655Sstever@eecs.umich.edu###################################################
6312655Sstever@eecs.umich.edu
6322655Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
6332655Sstever@eecs.umich.edu
6342655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
6352655Sstever@eecs.umich.edu
6362655Sstever@eecs.umich.edu###################################################
6372655Sstever@eecs.umich.edu#
6382655Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files.
6392655Sstever@eecs.umich.edu#
6402655Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable.
6412655Sstever@eecs.umich.edu#
6422655Sstever@eecs.umich.edu###################################################
6432655Sstever@eecs.umich.edu
6442655Sstever@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
6452655Sstever@eecs.umich.edu                                          'chmod +x $TARGET']))
6462655Sstever@eecs.umich.edu
6472655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder })
6482655Sstever@eecs.umich.edu
6492655Sstever@eecs.umich.edu
6502638Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root.
6512638Sstever@eecs.umich.eduenv.SConscript('ext/libelf/SConscript',
6523716Sstever@eecs.umich.edu               build_dir = joinpath(build_root, 'libelf'),
6532638Sstever@eecs.umich.edu               exports = 'env')
6542638Sstever@eecs.umich.edu
6551869SN/A###################################################
6561869SN/A#
6573546Sgblack@eecs.umich.edu# This function is used to set up a directory with switching headers
6583546Sgblack@eecs.umich.edu#
6593546Sgblack@eecs.umich.edu###################################################
6603546Sgblack@eecs.umich.edu
6614202Sbinkertn@umich.eduenv['ALL_ISA_LIST'] = all_isa_list
6623546Sgblack@eecs.umich.edudef make_switching_dir(dirname, switch_headers, env):
6633546Sgblack@eecs.umich.edu    # Generate the header.  target[0] is the full path of the output
6643546Sgblack@eecs.umich.edu    # header to generate.  'source' is a dummy variable, since we get the
6653546Sgblack@eecs.umich.edu    # list of ISAs from env['ALL_ISA_LIST'].
6663546Sgblack@eecs.umich.edu    def gen_switch_hdr(target, source, env):
6674781Snate@binkert.org        fname = str(target[0])
6684781Snate@binkert.org        basename = os.path.basename(fname)
6694781Snate@binkert.org        f = open(fname, 'w')
6704781Snate@binkert.org        f.write('#include "arch/isa_specific.hh"\n')
6714781Snate@binkert.org        cond = '#if'
6724781Snate@binkert.org        for isa in all_isa_list:
6734781Snate@binkert.org            f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
6744781Snate@binkert.org                    % (cond, isa.upper(), dirname, isa, basename))
6754781Snate@binkert.org            cond = '#elif'
6764781Snate@binkert.org        f.write('#else\n#error "THE_ISA not set"\n#endif\n')
6774781Snate@binkert.org        f.close()
6784781Snate@binkert.org        return 0
6793546Sgblack@eecs.umich.edu
6803546Sgblack@eecs.umich.edu    # String to print when generating header
6813546Sgblack@eecs.umich.edu    def gen_switch_hdr_string(target, source, env):
6824781Snate@binkert.org        return "Generating switch header " + str(target[0])
6833546Sgblack@eecs.umich.edu
6843546Sgblack@eecs.umich.edu    # Build SCons Action object. 'varlist' specifies env vars that this
6853546Sgblack@eecs.umich.edu    # action depends on; when env['ALL_ISA_LIST'] changes these actions
6863546Sgblack@eecs.umich.edu    # should get re-executed.
6873546Sgblack@eecs.umich.edu    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
6883546Sgblack@eecs.umich.edu                               varlist=['ALL_ISA_LIST'])
6893546Sgblack@eecs.umich.edu
6903546Sgblack@eecs.umich.edu    # Instantiate actions for each header
6913546Sgblack@eecs.umich.edu    for hdr in switch_headers:
6923546Sgblack@eecs.umich.edu        env.Command(hdr, [], switch_hdr_action)
6934202Sbinkertn@umich.eduExport('make_switching_dir')
6943546Sgblack@eecs.umich.edu
6953546Sgblack@eecs.umich.edu###################################################
6963546Sgblack@eecs.umich.edu#
697955SN/A# Define build environments for selected configurations.
698955SN/A#
699955SN/A###################################################
700955SN/A
7011858SN/A# rename base env
7021858SN/Abase_env = env
7031858SN/A
7042632Sstever@eecs.umich.edufor build_path in build_paths:
7052632Sstever@eecs.umich.edu    print "Building in", build_path
7065343Sstever@gmail.com
7075343Sstever@gmail.com    # Make a copy of the build-root environment to use for this config.
7085343Sstever@gmail.com    env = base_env.Copy()
7094773Snate@binkert.org    env['BUILDDIR'] = build_path
7104773Snate@binkert.org
7112632Sstever@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
7122632Sstever@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
7132632Sstever@eecs.umich.edu    (build_root, build_dir) = os.path.split(build_path)
7142023SN/A
7152632Sstever@eecs.umich.edu    # Set env options according to the build directory config.
7162632Sstever@eecs.umich.edu    sticky_opts.files = []
7172632Sstever@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
7182632Sstever@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
7192632Sstever@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
7203716Sstever@eecs.umich.edu    current_opts_file = joinpath(build_root, 'options', build_dir)
7215342Sstever@gmail.com    if isfile(current_opts_file):
7222632Sstever@eecs.umich.edu        sticky_opts.files.append(current_opts_file)
7232632Sstever@eecs.umich.edu        print "Using saved options file %s" % current_opts_file
7242632Sstever@eecs.umich.edu    else:
7252632Sstever@eecs.umich.edu        # Build dir-specific options file doesn't exist.
7262023SN/A
7272632Sstever@eecs.umich.edu        # Make sure the directory is there so we can create it later
7282632Sstever@eecs.umich.edu        opt_dir = os.path.dirname(current_opts_file)
7295342Sstever@gmail.com        if not isdir(opt_dir):
7301889SN/A            os.mkdir(opt_dir)
7312632Sstever@eecs.umich.edu
7322632Sstever@eecs.umich.edu        # Get default build options from source tree.  Options are
7332632Sstever@eecs.umich.edu        # normally determined by name of $BUILD_DIR, but can be
7342632Sstever@eecs.umich.edu        # overriden by 'default=' arg on command line.
7353716Sstever@eecs.umich.edu        default_opts_file = joinpath('build_opts',
7363716Sstever@eecs.umich.edu                                     ARGUMENTS.get('default', build_dir))
7375342Sstever@gmail.com        if isfile(default_opts_file):
7382632Sstever@eecs.umich.edu            sticky_opts.files.append(default_opts_file)
7392632Sstever@eecs.umich.edu            print "Options file %s not found,\n  using defaults in %s" \
7402632Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
7412632Sstever@eecs.umich.edu        else:
7422632Sstever@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
7432632Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
7442632Sstever@eecs.umich.edu            Exit(1)
7451888SN/A
7461888SN/A    # Apply current option settings to env
7471869SN/A    sticky_opts.Update(env)
7481869SN/A    nonsticky_opts.Update(env)
7491858SN/A
7505341Sstever@gmail.com    help_text += "\nSticky options for %s:\n" % build_dir \
7512598SN/A                 + sticky_opts.GenerateHelpText(env) \
7522598SN/A                 + "\nNon-sticky options for %s:\n" % build_dir \
7532598SN/A                 + nonsticky_opts.GenerateHelpText(env)
7542598SN/A
7551858SN/A    # Process option settings.
7561858SN/A
7571858SN/A    if not have_fenv and env['USE_FENV']:
7581858SN/A        print "Warning: <fenv.h> not available; " \
7591858SN/A              "forcing USE_FENV to False in", build_dir + "."
7601858SN/A        env['USE_FENV'] = False
7611858SN/A
7621858SN/A    if not env['USE_FENV']:
7631858SN/A        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
7641871SN/A        print "         FP results may deviate slightly from other platforms."
7651858SN/A
7661858SN/A    if env['EFENCE']:
7671858SN/A        env.Append(LIBS=['efence'])
7681858SN/A
7691858SN/A    if env['USE_MYSQL']:
7701858SN/A        if not have_mysql:
7711858SN/A            print "Warning: MySQL not available; " \
7721858SN/A                  "forcing USE_MYSQL to False in", build_dir + "."
7731858SN/A            env['USE_MYSQL'] = False
7741858SN/A        else:
7751858SN/A            print "Compiling in", build_dir, "with MySQL support."
7761859SN/A            env.ParseConfig(mysql_config_libs)
7771859SN/A            env.ParseConfig(mysql_config_include)
7781869SN/A
7791888SN/A    # Save sticky option settings back to current options file
7802632Sstever@eecs.umich.edu    sticky_opts.Save(current_opts_file, env)
7811869SN/A
7821884SN/A    # Do this after we save setting back, or else we'll tack on an
7831884SN/A    # extra 'qdo' every time we run scons.
7841884SN/A    if env['BATCH']:
7851884SN/A        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
7861884SN/A        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
7871884SN/A
7881965SN/A    if env['USE_SSE2']:
7891965SN/A        env.Append(CCFLAGS='-msse2')
7901965SN/A
7912761Sstever@eecs.umich.edu    # The src/SConscript file sets up the build rules in 'env' according
7921869SN/A    # to the configured options.  It returns a list of environments,
7931869SN/A    # one for each variant build (debug, opt, etc.)
7942632Sstever@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
7952667Sstever@eecs.umich.edu                         exports = 'env')
7961869SN/A
7971869SN/A    # Set up the regression tests for each build.
7982929Sktlim@umich.edu    for e in envList:
7992929Sktlim@umich.edu        SConscript('tests/SConscript',
8003716Sstever@eecs.umich.edu                   build_dir = joinpath(build_path, 'tests', e.Label),
8012929Sktlim@umich.edu                   exports = { 'env' : e }, duplicate = False)
802955SN/A
8032598SN/AHelp(help_text)
8042598SN/A
8053546Sgblack@eecs.umich.edu
806955SN/A###################################################
807955SN/A#
808955SN/A# Let SCons do its thing.  At this point SCons will use the defined
8091530SN/A# build environments to build the requested targets.
810955SN/A#
811955SN/A###################################################
812955SN/A
813