SConstruct revision 4773
1955SN/A# -*- mode:python -*-
2955SN/A
37816Ssteve.reinhardt@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
45871Snate@binkert.org# All rights reserved.
51762SN/A#
6955SN/A# Redistribution and use in source and binary forms, with or without
7955SN/A# modification, are permitted provided that the following conditions are
8955SN/A# met: redistributions of source code must retain the above copyright
9955SN/A# notice, this list of conditions and the following disclaimer;
10955SN/A# redistributions in binary form must reproduce the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer in the
12955SN/A# documentation and/or other materials provided with the distribution;
13955SN/A# neither the name of the copyright holders nor the names of its
14955SN/A# contributors may be used to endorse or promote products derived from
15955SN/A# this software without specific prior written permission.
16955SN/A#
17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28955SN/A#
29955SN/A# Authors: Steve Reinhardt
302665Ssaidi@eecs.umich.edu
312665Ssaidi@eecs.umich.edu###################################################
325863Snate@binkert.org#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
35955SN/A# While in this directory ('m5'), just type 'scons' to build the default
36955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
388878Ssteve.reinhardt@amd.com# the optimized full-system version).
392632Sstever@eecs.umich.edu#
408878Ssteve.reinhardt@amd.com# 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
42955SN/A# expects that all configs under the same build directory are being
438878Ssteve.reinhardt@amd.com# built for the same host system.
442632Sstever@eecs.umich.edu#
452761Sstever@eecs.umich.edu# Examples:
462632Sstever@eecs.umich.edu#
472632Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
482632Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
492761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
502761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512761Sstever@eecs.umich.edu#
528878Ssteve.reinhardt@amd.com#   The following two commands are equivalent and demonstrate building
538878Ssteve.reinhardt@amd.com#   in a directory outside of the source tree.  The '-C' option tells
542761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
552761Sstever@eecs.umich.edu#   file.
562761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
572761Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
582761Sstever@eecs.umich.edu#
598878Ssteve.reinhardt@amd.com# You can use 'scons -H' to print scons options.  If you're in this
608878Ssteve.reinhardt@amd.com# '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.
638878Ssteve.reinhardt@amd.com#
648878Ssteve.reinhardt@amd.com###################################################
652632Sstever@eecs.umich.edu
66955SN/Aimport sys
67955SN/Aimport os
68955SN/Aimport subprocess
695863Snate@binkert.org
705863Snate@binkert.orgfrom os.path import isdir, join as joinpath
715863Snate@binkert.org
725863Snate@binkert.org# Check for recent-enough Python and SCons versions.  If your system's
735863Snate@binkert.org# default installation of Python is not recent enough, you can use a
745863Snate@binkert.org# non-default installation of the Python interpreter by either (1)
755863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python'
765863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the
775863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
785863Snate@binkert.orgEnsurePythonVersion(2,4)
795863Snate@binkert.org
808878Ssteve.reinhardt@amd.com# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
815863Snate@binkert.org# 3-element version number.
825863Snate@binkert.orgmin_scons_version = (0,96,91)
835863Snate@binkert.orgtry:
845863Snate@binkert.org    EnsureSConsVersion(*min_scons_version)
855863Snate@binkert.orgexcept:
865863Snate@binkert.org    print "Error checking current SCons version."
875863Snate@binkert.org    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
885863Snate@binkert.org    Exit(2)
895863Snate@binkert.org    
905863Snate@binkert.org
915863Snate@binkert.org# The absolute path to the current directory (where this file lives).
925863Snate@binkert.orgROOT = Dir('.').abspath
935863Snate@binkert.org
945863Snate@binkert.org# Path to the M5 source tree.
955863Snate@binkert.orgSRCDIR = joinpath(ROOT, 'src')
968878Ssteve.reinhardt@amd.com
975863Snate@binkert.org# tell python where to find m5 python code
985863Snate@binkert.orgsys.path.append(joinpath(ROOT, 'src/python'))
995863Snate@binkert.org
1006654Snate@binkert.orgdef check_style_hook(ui):
101955SN/A    ui.readconfig(joinpath(ROOT, '.hg', 'hgrc'))
1025396Ssaidi@eecs.umich.edu    style_hook = ui.config('hooks', 'pretxncommit.style', None)
1035863Snate@binkert.org
1045863Snate@binkert.org    if not style_hook:
1054202Sbinkertn@umich.edu        print """\
1065863Snate@binkert.orgYou're missing the M5 style hook.
1075863Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style.
1085863Snate@binkert.org
1095863Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc
110955SN/Aor your personal .hgrc
1116654Snate@binkert.org----------------
1125273Sstever@gmail.com
1135871Snate@binkert.org[extensions]
1145273Sstever@gmail.comstyle = %s/util/style.py
1156655Snate@binkert.org
1168878Ssteve.reinhardt@amd.com[hooks]
1176655Snate@binkert.orgpretxncommit.style = python:style.check_whitespace
1186655Snate@binkert.org""" % (ROOT)
1196655Snate@binkert.org        sys.exit(1)
1206655Snate@binkert.org
1215871Snate@binkert.orgif isdir(joinpath(ROOT, '.hg')):
1226654Snate@binkert.org    try:
1238947Sandreas.hansson@arm.com        from mercurial import ui
1245396Ssaidi@eecs.umich.edu        check_style_hook(ui.ui())
1258120Sgblack@eecs.umich.edu    except ImportError:
1268120Sgblack@eecs.umich.edu        pass
1278120Sgblack@eecs.umich.edu
1288120Sgblack@eecs.umich.edu###################################################
1298120Sgblack@eecs.umich.edu#
1308120Sgblack@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
1318120Sgblack@eecs.umich.edu# the target(s).
1328120Sgblack@eecs.umich.edu#
1338879Ssteve.reinhardt@amd.com###################################################
1348879Ssteve.reinhardt@amd.com
1358879Ssteve.reinhardt@amd.com# Find default configuration & binary.
1368879Ssteve.reinhardt@amd.comDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1378879Ssteve.reinhardt@amd.com
1388879Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list
1398879Ssteve.reinhardt@amd.comdef rfind(l, elt, offs = -1):
1408879Ssteve.reinhardt@amd.com    for i in range(len(l)+offs, 0, -1):
1418879Ssteve.reinhardt@amd.com        if l[i] == elt:
1428879Ssteve.reinhardt@amd.com            return i
1438879Ssteve.reinhardt@amd.com    raise ValueError, "element not found"
1448879Ssteve.reinhardt@amd.com
1458879Ssteve.reinhardt@amd.com# helper function: compare dotted version numbers.
1468120Sgblack@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1')
1478120Sgblack@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2
1488120Sgblack@eecs.umich.edudef compare_versions(v1, v2):
1498120Sgblack@eecs.umich.edu    # Convert dotted strings to lists
1508120Sgblack@eecs.umich.edu    v1 = map(int, v1.split('.'))
1518120Sgblack@eecs.umich.edu    v2 = map(int, v2.split('.'))
1528120Sgblack@eecs.umich.edu    # Compare corresponding elements of lists
1538120Sgblack@eecs.umich.edu    for n1,n2 in zip(v1, v2):
1548120Sgblack@eecs.umich.edu        if n1 < n2: return -1
1558120Sgblack@eecs.umich.edu        if n1 > n2: return  1
1568120Sgblack@eecs.umich.edu    # all corresponding values are equal... see if one has extra values
1578120Sgblack@eecs.umich.edu    if len(v1) < len(v2): return -1
1588120Sgblack@eecs.umich.edu    if len(v1) > len(v2): return  1
1598120Sgblack@eecs.umich.edu    return 0
1608879Ssteve.reinhardt@amd.com
1618879Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the
1628879Ssteve.reinhardt@amd.com# directory below this will determine the build parameters.  For
1638879Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1648879Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it
1658879Ssteve.reinhardt@amd.com# follow 'build' in the bulid path.
1668879Ssteve.reinhardt@amd.com
1678879Ssteve.reinhardt@amd.com# Generate absolute paths to targets so we can see where the build dir is
1688879Ssteve.reinhardt@amd.comif COMMAND_LINE_TARGETS:
1698879Ssteve.reinhardt@amd.com    # Ask SCons which directory it was invoked from
1708879Ssteve.reinhardt@amd.com    launch_dir = GetLaunchDir()
1718879Ssteve.reinhardt@amd.com    # Make targets relative to invocation directory
1728120Sgblack@eecs.umich.edu    abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))),
1738947Sandreas.hansson@arm.com                      COMMAND_LINE_TARGETS)
1747816Ssteve.reinhardt@amd.comelse:
1755871Snate@binkert.org    # Default targets are relative to root of tree
1765871Snate@binkert.org    abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))),
1776121Snate@binkert.org                      DEFAULT_TARGETS)
1785871Snate@binkert.org
1795871Snate@binkert.org
1806003Snate@binkert.org# Generate a list of the unique build roots and configs that the
1818980Ssteve.reinhardt@amd.com# collected targets reference.
182955SN/Abuild_paths = []
1835871Snate@binkert.orgbuild_root = None
1845871Snate@binkert.orgfor t in abs_targets:
1855871Snate@binkert.org    path_dirs = t.split('/')
1865871Snate@binkert.org    try:
187955SN/A        build_top = rfind(path_dirs, 'build', -2)
1886121Snate@binkert.org    except:
1898881Smarc.orr@gmail.com        print "Error: no non-leaf 'build' dir found on target path", t
1906121Snate@binkert.org        Exit(1)
1916121Snate@binkert.org    this_build_root = joinpath('/',*path_dirs[:build_top+1])
1921533SN/A    if not build_root:
1936655Snate@binkert.org        build_root = this_build_root
1946655Snate@binkert.org    else:
1956655Snate@binkert.org        if this_build_root != build_root:
1966655Snate@binkert.org            print "Error: build targets not under same build root\n"\
1975871Snate@binkert.org                  "  %s\n  %s" % (build_root, this_build_root)
1985871Snate@binkert.org            Exit(1)
1995863Snate@binkert.org    build_path = joinpath('/',*path_dirs[:build_top+2])
2005871Snate@binkert.org    if build_path not in build_paths:
2018878Ssteve.reinhardt@amd.com        build_paths.append(build_path)
2025871Snate@binkert.org
2035871Snate@binkert.org###################################################
2045871Snate@binkert.org#
2055863Snate@binkert.org# Set up the default build environment.  This environment is copied
2066121Snate@binkert.org# and modified according to each selected configuration.
2075863Snate@binkert.org#
2085871Snate@binkert.org###################################################
2098336Ssteve.reinhardt@amd.com
2108336Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
2118336Ssteve.reinhardt@amd.com                  ROOT = ROOT,
2128336Ssteve.reinhardt@amd.com                  SRCDIR = SRCDIR)
2134678Snate@binkert.org
2148336Ssteve.reinhardt@amd.com#Parse CC/CXX early so that we use the correct compiler for 
2158336Ssteve.reinhardt@amd.com# to test for dependencies/versions/libraries/includes
2168336Ssteve.reinhardt@amd.comif ARGUMENTS.get('CC', None):
2174678Snate@binkert.org    env['CC'] = ARGUMENTS.get('CC')
2184678Snate@binkert.org
2194678Snate@binkert.orgif ARGUMENTS.get('CXX', None):
2204678Snate@binkert.org    env['CXX'] = ARGUMENTS.get('CXX')
2217827Snate@binkert.org
2227827Snate@binkert.orgExport('env')
2238336Ssteve.reinhardt@amd.com
2244678Snate@binkert.orgenv.SConsignFile(joinpath(build_root,"sconsign"))
2258336Ssteve.reinhardt@amd.com
2268336Ssteve.reinhardt@amd.com# Default duplicate option is to use hard links, but this messes up
2278336Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves
2288336Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link.  Symbolic
2298336Ssteve.reinhardt@amd.com# (soft) links work better.
2308336Ssteve.reinhardt@amd.comenv.SetOption('duplicate', 'soft-copy')
2315871Snate@binkert.org
2325871Snate@binkert.org# I waffle on this setting... it does avoid a few painful but
2338336Ssteve.reinhardt@amd.com# unnecessary builds, but it also seems to make trivial builds take
2348336Ssteve.reinhardt@amd.com# noticeably longer.
2358336Ssteve.reinhardt@amd.comif False:
2368336Ssteve.reinhardt@amd.com    env.TargetSignatures('content')
2378336Ssteve.reinhardt@amd.com
2385871Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package.
2398336Ssteve.reinhardt@amd.comenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
2408336Ssteve.reinhardt@amd.comenv['GCC'] = False
2418336Ssteve.reinhardt@amd.comenv['SUNCC'] = False
2428336Ssteve.reinhardt@amd.comenv['ICC'] = False
2438336Ssteve.reinhardt@amd.comenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 
2444678Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 
2455871Snate@binkert.org        close_fds=True).communicate()[0].find('GCC') >= 0
2464678Snate@binkert.orgenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 
2478336Ssteve.reinhardt@amd.com        stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 
2488336Ssteve.reinhardt@amd.com        close_fds=True).communicate()[0].find('Sun C++') >= 0
2498336Ssteve.reinhardt@amd.comenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 
2508336Ssteve.reinhardt@amd.com        stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 
2518336Ssteve.reinhardt@amd.com        close_fds=True).communicate()[0].find('Intel') >= 0
2528336Ssteve.reinhardt@amd.comif env['GCC'] + env['SUNCC'] + env['ICC'] > 1:
2538336Ssteve.reinhardt@amd.com    print 'Error: How can we have two at the same time?'
2548336Ssteve.reinhardt@amd.com    Exit(1)
2558336Ssteve.reinhardt@amd.com
2568336Ssteve.reinhardt@amd.com
2578336Ssteve.reinhardt@amd.com# Set up default C++ compiler flags
2588336Ssteve.reinhardt@amd.comif env['GCC']:
2598336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS='-pipe')
2608336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS='-fno-strict-aliasing')
2618336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2628336Ssteve.reinhardt@amd.comelif env['ICC']:
2638336Ssteve.reinhardt@amd.com    pass #Fix me... add warning flags once we clean up icc warnings
2645871Snate@binkert.orgelif env['SUNCC']:
2656121Snate@binkert.org    env.Append(CCFLAGS='-Qoption ccfe')
266955SN/A    env.Append(CCFLAGS='-features=gcc')
267955SN/A    env.Append(CCFLAGS='-features=extensions')
2682632Sstever@eecs.umich.edu    env.Append(CCFLAGS='-library=stlport4')
2692632Sstever@eecs.umich.edu    env.Append(CCFLAGS='-xar')
270955SN/A#    env.Append(CCFLAGS='-instances=semiexplicit')
271955SN/Aelse:
272955SN/A    print 'Error: Don\'t know what compiler options to use for your compiler.'
273955SN/A    print '       Please fix SConstruct and src/SConscript and try again.'
2748878Ssteve.reinhardt@amd.com    Exit(1)
275955SN/A
2762632Sstever@eecs.umich.eduif sys.platform == 'cygwin':
2772632Sstever@eecs.umich.edu    # cygwin has some header file issues...
2782632Sstever@eecs.umich.edu    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
2792632Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')])
2802632Sstever@eecs.umich.edu
2812632Sstever@eecs.umich.edu# Check for SWIG
2822632Sstever@eecs.umich.eduif not env.has_key('SWIG'):
2838268Ssteve.reinhardt@amd.com    print 'Error: SWIG utility not found.'
2848268Ssteve.reinhardt@amd.com    print '       Please install (see http://www.swig.org) and retry.'
2858268Ssteve.reinhardt@amd.com    Exit(1)
2868268Ssteve.reinhardt@amd.com
2878268Ssteve.reinhardt@amd.com# Check for appropriate SWIG version
2888268Ssteve.reinhardt@amd.comswig_version = os.popen('swig -version').read().split()
2898268Ssteve.reinhardt@amd.com# First 3 words should be "SWIG Version x.y.z"
2902632Sstever@eecs.umich.eduif len(swig_version) < 3 or \
2912632Sstever@eecs.umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
2922632Sstever@eecs.umich.edu    print 'Error determining SWIG version.'
2932632Sstever@eecs.umich.edu    Exit(1)
2948268Ssteve.reinhardt@amd.com
2952632Sstever@eecs.umich.edumin_swig_version = '1.3.28'
2968268Ssteve.reinhardt@amd.comif compare_versions(swig_version[2], min_swig_version) < 0:
2978268Ssteve.reinhardt@amd.com    print 'Error: SWIG version', min_swig_version, 'or newer required.'
2988268Ssteve.reinhardt@amd.com    print '       Installed version:', swig_version[2]
2998268Ssteve.reinhardt@amd.com    Exit(1)
3003718Sstever@eecs.umich.edu
3012634Sstever@eecs.umich.edu# Set up SWIG flags & scanner
3022634Sstever@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
3035863Snate@binkert.orgenv.Append(SWIGFLAGS=swig_flags)
3042638Sstever@eecs.umich.edu
3058268Ssteve.reinhardt@amd.com# filter out all existing swig scanners, they mess up the dependency
3062632Sstever@eecs.umich.edu# stuff for some reason
3072632Sstever@eecs.umich.eduscanners = []
3082632Sstever@eecs.umich.edufor scanner in env['SCANNERS']:
3092632Sstever@eecs.umich.edu    skeys = scanner.skeys
3102632Sstever@eecs.umich.edu    if skeys == '.i':
3111858SN/A        continue
3123716Sstever@eecs.umich.edu    
3132638Sstever@eecs.umich.edu    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
3142638Sstever@eecs.umich.edu        continue
3152638Sstever@eecs.umich.edu
3162638Sstever@eecs.umich.edu    scanners.append(scanner)
3172638Sstever@eecs.umich.edu
3182638Sstever@eecs.umich.edu# add the new swig scanner that we like better
3192638Sstever@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner
3205863Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
3215863Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
3225863Snate@binkert.org
323955SN/A# replace the scanners list that has what we want
3245341Sstever@gmail.comenv['SCANNERS'] = scanners
3255341Sstever@gmail.com
3265863Snate@binkert.org# Platform-specific configuration.  Note again that we assume that all
3277756SAli.Saidi@ARM.com# builds under a given build root run on the same host platform.
3285341Sstever@gmail.comconf = Configure(env,
3296121Snate@binkert.org                 conf_dir = joinpath(build_root, '.scons_config'),
3304494Ssaidi@eecs.umich.edu                 log_file = joinpath(build_root, 'scons_config.log'))
3316121Snate@binkert.org
3321105SN/A# Find Python include and library directories for embedding the
3332667Sstever@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
3342667Sstever@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
3352667Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
3362667Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
3376121Snate@binkert.org
3382667Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating
3395341Sstever@gmail.com# include & library files
3405863Snate@binkert.orgpy_version_name = 'python' + sys.version[:3]
3415341Sstever@gmail.com
3425341Sstever@gmail.com# include path, e.g. /usr/local/include/python2.4
3435341Sstever@gmail.compy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name)
3448120Sgblack@eecs.umich.eduenv.Append(CPPPATH = py_header_path)
3455341Sstever@gmail.com# verify that it works
3468120Sgblack@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
3475341Sstever@gmail.com    print "Error: can't find Python.h header in", py_header_path
3488120Sgblack@eecs.umich.edu    Exit(1)
3496121Snate@binkert.org
3506121Snate@binkert.org# add library path too if it's not in the default place
3518980Ssteve.reinhardt@amd.compy_lib_path = None
3525397Ssaidi@eecs.umich.eduif sys.exec_prefix != '/usr':
3535397Ssaidi@eecs.umich.edu    py_lib_path = joinpath(sys.exec_prefix, 'lib')
3547727SAli.Saidi@ARM.comelif sys.platform == 'cygwin':
3558268Ssteve.reinhardt@amd.com    # cygwin puts the .dll in /bin for some reason
3566168Snate@binkert.org    py_lib_path = '/bin'
3575341Sstever@gmail.comif py_lib_path:
3588120Sgblack@eecs.umich.edu    env.Append(LIBPATH = py_lib_path)
3598120Sgblack@eecs.umich.edu    print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
3608120Sgblack@eecs.umich.eduif not conf.CheckLib(py_version_name):
3616814Sgblack@eecs.umich.edu    print "Error: can't find Python library", py_version_name
3625863Snate@binkert.org    Exit(1)
3638120Sgblack@eecs.umich.edu
3645341Sstever@gmail.com# On Solaris you need to use libsocket for socket ops
3655863Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
3668268Ssteve.reinhardt@amd.com   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
3676121Snate@binkert.org       print "Can't find library with socket calls (e.g. accept())"
3686121Snate@binkert.org       Exit(1)
3698268Ssteve.reinhardt@amd.com
3705742Snate@binkert.org# Check for zlib.  If the check passes, libz will be automatically
3715742Snate@binkert.org# added to the LIBS environment variable.
3725341Sstever@gmail.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
3735742Snate@binkert.org    print 'Error: did not find needed zlib compression library '\
3745742Snate@binkert.org          'and/or zlib.h header file.'
3755341Sstever@gmail.com    print '       Please install zlib and try again.'
3766017Snate@binkert.org    Exit(1)
3776121Snate@binkert.org
3786017Snate@binkert.org# Check for <fenv.h> (C99 FP environment control)
3797816Ssteve.reinhardt@amd.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
3807756SAli.Saidi@ARM.comif not have_fenv:
3817756SAli.Saidi@ARM.com    print "Warning: Header file <fenv.h> not found."
3827756SAli.Saidi@ARM.com    print "         This host has no IEEE FP rounding mode control."
3837756SAli.Saidi@ARM.com
3847756SAli.Saidi@ARM.com# Check for mysql.
3857756SAli.Saidi@ARM.commysql_config = WhereIs('mysql_config')
3867756SAli.Saidi@ARM.comhave_mysql = mysql_config != None
3877756SAli.Saidi@ARM.com
3887816Ssteve.reinhardt@amd.com# Check MySQL version.
3897816Ssteve.reinhardt@amd.comif have_mysql:
3907816Ssteve.reinhardt@amd.com    mysql_version = os.popen(mysql_config + ' --version').read()
3917816Ssteve.reinhardt@amd.com    min_mysql_version = '4.1'
3927816Ssteve.reinhardt@amd.com    if compare_versions(mysql_version, min_mysql_version) < 0:
3937816Ssteve.reinhardt@amd.com        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
3947816Ssteve.reinhardt@amd.com        print '         Version', mysql_version, 'detected.'
3957816Ssteve.reinhardt@amd.com        have_mysql = False
3967816Ssteve.reinhardt@amd.com
3977816Ssteve.reinhardt@amd.com# Set up mysql_config commands.
3987756SAli.Saidi@ARM.comif have_mysql:
3997816Ssteve.reinhardt@amd.com    mysql_config_include = mysql_config + ' --include'
4007816Ssteve.reinhardt@amd.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
4017816Ssteve.reinhardt@amd.com        # older mysql_config versions don't support --include, use
4027816Ssteve.reinhardt@amd.com        # --cflags instead
4037816Ssteve.reinhardt@amd.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
4047816Ssteve.reinhardt@amd.com    # This seems to work in all versions
4057816Ssteve.reinhardt@amd.com    mysql_config_libs = mysql_config + ' --libs'
4067816Ssteve.reinhardt@amd.com
4077816Ssteve.reinhardt@amd.comenv = conf.Finish()
4087816Ssteve.reinhardt@amd.com
4097816Ssteve.reinhardt@amd.com# Define the universe of supported ISAs
4107816Ssteve.reinhardt@amd.comall_isa_list = [ ]
4117816Ssteve.reinhardt@amd.comExport('all_isa_list')
4127816Ssteve.reinhardt@amd.com
4137816Ssteve.reinhardt@amd.com# Define the universe of supported CPU models
4147816Ssteve.reinhardt@amd.comall_cpu_list = [ ]
4157816Ssteve.reinhardt@amd.comdefault_cpus = [ ]
4167816Ssteve.reinhardt@amd.comExport('all_cpu_list', 'default_cpus')
4177816Ssteve.reinhardt@amd.com
4187816Ssteve.reinhardt@amd.com# Sticky options get saved in the options file so they persist from
4197816Ssteve.reinhardt@amd.com# one invocation to the next (unless overridden, in which case the new
4207816Ssteve.reinhardt@amd.com# value becomes sticky).
4217816Ssteve.reinhardt@amd.comsticky_opts = Options(args=ARGUMENTS)
4227816Ssteve.reinhardt@amd.comExport('sticky_opts')
4237816Ssteve.reinhardt@amd.com
4247816Ssteve.reinhardt@amd.com# Non-sticky options only apply to the current build.
4257816Ssteve.reinhardt@amd.comnonsticky_opts = Options(args=ARGUMENTS)
4267816Ssteve.reinhardt@amd.comExport('nonsticky_opts')
4277816Ssteve.reinhardt@amd.com
4287816Ssteve.reinhardt@amd.com# Walk the tree and execute all SConsopts scripts that wil add to the
4297816Ssteve.reinhardt@amd.com# above options
4307816Ssteve.reinhardt@amd.comfor root, dirs, files in os.walk('.'):
4317816Ssteve.reinhardt@amd.com    if 'SConsopts' in files:
4327816Ssteve.reinhardt@amd.com        SConscript(os.path.join(root, 'SConsopts'))
4337816Ssteve.reinhardt@amd.com
4347816Ssteve.reinhardt@amd.comall_isa_list.sort()
4357816Ssteve.reinhardt@amd.comall_cpu_list.sort()
4367816Ssteve.reinhardt@amd.comdefault_cpus.sort()
4377816Ssteve.reinhardt@amd.com
4387816Ssteve.reinhardt@amd.comdef ExtraPathValidator(key, val, env):
4397816Ssteve.reinhardt@amd.com    paths = val.split(':')
4407816Ssteve.reinhardt@amd.com    for path in paths:
4417816Ssteve.reinhardt@amd.com        path = os.path.expanduser(path)
4427816Ssteve.reinhardt@amd.com        if not isdir(path):
4437816Ssteve.reinhardt@amd.com            raise AttributeError, "Invalid path: '%s'" % path
4447816Ssteve.reinhardt@amd.com
4457816Ssteve.reinhardt@amd.comsticky_opts.AddOptions(
4467816Ssteve.reinhardt@amd.com    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
4477816Ssteve.reinhardt@amd.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
4487816Ssteve.reinhardt@amd.com    # There's a bug in scons 0.96.1 that causes ListOptions with list
4497816Ssteve.reinhardt@amd.com    # values (more than one value) not to be able to be restored from
4507816Ssteve.reinhardt@amd.com    # a saved option file.  If this causes trouble then upgrade to
4517816Ssteve.reinhardt@amd.com    # scons 0.96.90 or later.
4527816Ssteve.reinhardt@amd.com    ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
4537816Ssteve.reinhardt@amd.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
4547816Ssteve.reinhardt@amd.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
4557816Ssteve.reinhardt@amd.com               False),
4567816Ssteve.reinhardt@amd.com    BoolOption('SS_COMPATIBLE_FP',
4577816Ssteve.reinhardt@amd.com               'Make floating-point results compatible with SimpleScalar',
4587816Ssteve.reinhardt@amd.com               False),
4597816Ssteve.reinhardt@amd.com    BoolOption('USE_SSE2',
4608947Sandreas.hansson@arm.com               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
4618947Sandreas.hansson@arm.com               False),
4627756SAli.Saidi@ARM.com    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
4638120Sgblack@eecs.umich.edu    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
4647756SAli.Saidi@ARM.com    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
4657756SAli.Saidi@ARM.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
4667756SAli.Saidi@ARM.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
4677756SAli.Saidi@ARM.com    BoolOption('BATCH', 'Use batch pool for build and tests', False),
4687816Ssteve.reinhardt@amd.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
4697816Ssteve.reinhardt@amd.com    ('PYTHONHOME',
4707816Ssteve.reinhardt@amd.com     'Override the default PYTHONHOME for this system (use with caution)',
4717816Ssteve.reinhardt@amd.com     '%s:%s' % (sys.prefix, sys.exec_prefix)),
4727816Ssteve.reinhardt@amd.com    ('EXTRAS', 'Add Extra directories to the compilation', '',
4737816Ssteve.reinhardt@amd.com     ExtraPathValidator)
4747816Ssteve.reinhardt@amd.com    )
4757816Ssteve.reinhardt@amd.com
4767816Ssteve.reinhardt@amd.comnonsticky_opts.AddOptions(
4777816Ssteve.reinhardt@amd.com    BoolOption('update_ref', 'Update test reference outputs', False)
4787756SAli.Saidi@ARM.com    )
4797756SAli.Saidi@ARM.com
4806654Snate@binkert.org# These options get exported to #defines in config/*.hh (see src/SConscript).
4816654Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
4825871Snate@binkert.org                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
4836121Snate@binkert.org                     'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
4846121Snate@binkert.org
4856121Snate@binkert.org# Define a handy 'no-op' action
4868946Sandreas.hansson@arm.comdef no_action(target, source, env):
4878737Skoansin.tan@gmail.com    return 0
4883940Ssaidi@eecs.umich.edu
4893918Ssaidi@eecs.umich.eduenv.NoAction = Action(no_action, None)
4903918Ssaidi@eecs.umich.edu
4911858SN/A###################################################
4926121Snate@binkert.org#
4937739Sgblack@eecs.umich.edu# Define a SCons builder for configuration flag headers.
4947739Sgblack@eecs.umich.edu#
4956143Snate@binkert.org###################################################
4967618SAli.Saidi@arm.com
4977618SAli.Saidi@arm.com# This function generates a config header file that #defines the
4987618SAli.Saidi@arm.com# option symbol to the current option setting (0 or 1).  The source
4997618SAli.Saidi@arm.com# operands are the name of the option and a Value node containing the
5008614Sgblack@eecs.umich.edu# value of the option.
5017618SAli.Saidi@arm.comdef build_config_file(target, source, env):
5027618SAli.Saidi@arm.com    (option, value) = [s.get_contents() for s in source]
5037618SAli.Saidi@arm.com    f = file(str(target[0]), 'w')
5047739Sgblack@eecs.umich.edu    print >> f, '#define', option, value
5058946Sandreas.hansson@arm.com    f.close()
5068946Sandreas.hansson@arm.com    return None
5076121Snate@binkert.org
5083940Ssaidi@eecs.umich.edu# Generate the message to be printed when building the config file.
5096121Snate@binkert.orgdef build_config_file_string(target, source, env):
5107739Sgblack@eecs.umich.edu    (option, value) = [s.get_contents() for s in source]
5117739Sgblack@eecs.umich.edu    return "Defining %s as %s in %s." % (option, value, target[0])
5127739Sgblack@eecs.umich.edu
5137739Sgblack@eecs.umich.edu# Combine the two functions into a scons Action object.
5147739Sgblack@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string)
5157739Sgblack@eecs.umich.edu
5168737Skoansin.tan@gmail.com# The emitter munges the source & target node lists to reflect what
5178737Skoansin.tan@gmail.com# we're really doing.
5188737Skoansin.tan@gmail.comdef config_emitter(target, source, env):
5198737Skoansin.tan@gmail.com    # extract option name from Builder arg
5208737Skoansin.tan@gmail.com    option = str(target[0])
5218737Skoansin.tan@gmail.com    # True target is config header file
5228737Skoansin.tan@gmail.com    target = joinpath('config', option.lower() + '.hh')
5238737Skoansin.tan@gmail.com    val = env[option]
5248737Skoansin.tan@gmail.com    if isinstance(val, bool):
5258737Skoansin.tan@gmail.com        # Force value to 0/1
5268737Skoansin.tan@gmail.com        val = int(val)
5278737Skoansin.tan@gmail.com    elif isinstance(val, str):
5288737Skoansin.tan@gmail.com        val = '"' + val + '"'
5298737Skoansin.tan@gmail.com        
5308737Skoansin.tan@gmail.com    # Sources are option name & value (packaged in SCons Value nodes)
5318737Skoansin.tan@gmail.com    return ([target], [Value(option), Value(val)])
5328737Skoansin.tan@gmail.com
5338737Skoansin.tan@gmail.comconfig_builder = Builder(emitter = config_emitter, action = config_action)
5348946Sandreas.hansson@arm.com
5358946Sandreas.hansson@arm.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
5368946Sandreas.hansson@arm.com
5378946Sandreas.hansson@arm.com###################################################
5388946Sandreas.hansson@arm.com#
5398946Sandreas.hansson@arm.com# Define a SCons builder for copying files.  This is used by the
5403918Ssaidi@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here
5413918Ssaidi@eecs.umich.edu# since it's potentially more generally applicable.
5423940Ssaidi@eecs.umich.edu#
5433918Ssaidi@eecs.umich.edu###################################################
5443918Ssaidi@eecs.umich.edu
5456157Snate@binkert.orgcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
5466157Snate@binkert.org
5476157Snate@binkert.orgenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
5486157Snate@binkert.org
5495397Ssaidi@eecs.umich.edu###################################################
5505397Ssaidi@eecs.umich.edu#
5516121Snate@binkert.org# Define a simple SCons builder to concatenate files.
5526121Snate@binkert.org#
5536121Snate@binkert.org# Used to append the Python zip archive to the executable.
5546121Snate@binkert.org#
5556121Snate@binkert.org###################################################
5566121Snate@binkert.org
5575397Ssaidi@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
5581851SN/A                                          'chmod +x $TARGET']))
5591851SN/A
5607739Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder })
561955SN/A
5623053Sstever@eecs.umich.edu
5636121Snate@binkert.org# base help text
5643053Sstever@eecs.umich.eduhelp_text = '''
5653053Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)]
5663053Sstever@eecs.umich.edu
5673053Sstever@eecs.umich.edu'''
5683053Sstever@eecs.umich.edu
5696654Snate@binkert.org# libelf build is shared across all configs in the build root.
5703053Sstever@eecs.umich.eduenv.SConscript('ext/libelf/SConscript',
5714742Sstever@eecs.umich.edu               build_dir = joinpath(build_root, 'libelf'),
5724742Sstever@eecs.umich.edu               exports = 'env')
5733053Sstever@eecs.umich.edu
5743053Sstever@eecs.umich.edu###################################################
5753053Sstever@eecs.umich.edu#
5768960Ssteve.reinhardt@amd.com# This function is used to set up a directory with switching headers
5776654Snate@binkert.org#
5783053Sstever@eecs.umich.edu###################################################
5793053Sstever@eecs.umich.edu
5803053Sstever@eecs.umich.eduenv['ALL_ISA_LIST'] = all_isa_list
5813053Sstever@eecs.umich.edudef make_switching_dir(dirname, switch_headers, env):
5822667Sstever@eecs.umich.edu    # Generate the header.  target[0] is the full path of the output
5834554Sbinkertn@umich.edu    # header to generate.  'source' is a dummy variable, since we get the
5846121Snate@binkert.org    # list of ISAs from env['ALL_ISA_LIST'].
5852667Sstever@eecs.umich.edu    def gen_switch_hdr(target, source, env):
5864554Sbinkertn@umich.edu	fname = str(target[0])
5874554Sbinkertn@umich.edu	basename = os.path.basename(fname)
5884554Sbinkertn@umich.edu	f = open(fname, 'w')
5896121Snate@binkert.org	f.write('#include "arch/isa_specific.hh"\n')
5904554Sbinkertn@umich.edu	cond = '#if'
5914554Sbinkertn@umich.edu	for isa in all_isa_list:
5924554Sbinkertn@umich.edu	    f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
5934781Snate@binkert.org		    % (cond, isa.upper(), dirname, isa, basename))
5944554Sbinkertn@umich.edu	    cond = '#elif'
5954554Sbinkertn@umich.edu	f.write('#else\n#error "THE_ISA not set"\n#endif\n')
5962667Sstever@eecs.umich.edu	f.close()
5974554Sbinkertn@umich.edu	return 0
5984554Sbinkertn@umich.edu
5994554Sbinkertn@umich.edu    # String to print when generating header
6004554Sbinkertn@umich.edu    def gen_switch_hdr_string(target, source, env):
6012667Sstever@eecs.umich.edu	return "Generating switch header " + str(target[0])
6024554Sbinkertn@umich.edu
6032667Sstever@eecs.umich.edu    # Build SCons Action object. 'varlist' specifies env vars that this
6044554Sbinkertn@umich.edu    # action depends on; when env['ALL_ISA_LIST'] changes these actions
6056121Snate@binkert.org    # should get re-executed.
6062667Sstever@eecs.umich.edu    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
6075522Snate@binkert.org                               varlist=['ALL_ISA_LIST'])
6085522Snate@binkert.org
6095522Snate@binkert.org    # Instantiate actions for each header
6105522Snate@binkert.org    for hdr in switch_headers:
6115522Snate@binkert.org        env.Command(hdr, [], switch_hdr_action)
6125522Snate@binkert.orgExport('make_switching_dir')
6135522Snate@binkert.org
6145522Snate@binkert.org###################################################
6155522Snate@binkert.org#
6165522Snate@binkert.org# Define build environments for selected configurations.
6175522Snate@binkert.org#
6185522Snate@binkert.org###################################################
6195522Snate@binkert.org
6205522Snate@binkert.org# rename base env
6215522Snate@binkert.orgbase_env = env
6225522Snate@binkert.org
6235522Snate@binkert.orgfor build_path in build_paths:
6245522Snate@binkert.org    print "Building in", build_path
6255522Snate@binkert.org    env['BUILDDIR'] = build_path
6265522Snate@binkert.org
6275522Snate@binkert.org    # build_dir is the tail component of build path, and is used to
6285522Snate@binkert.org    # determine the build parameters (e.g., 'ALPHA_SE')
6295522Snate@binkert.org    (build_root, build_dir) = os.path.split(build_path)
6305522Snate@binkert.org    # Make a copy of the build-root environment to use for this config.
6315522Snate@binkert.org    env = base_env.Copy()
6325522Snate@binkert.org
6332638Sstever@eecs.umich.edu    # Set env options according to the build directory config.
6342638Sstever@eecs.umich.edu    sticky_opts.files = []
6356121Snate@binkert.org    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
6363716Sstever@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
6375522Snate@binkert.org    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
6385522Snate@binkert.org    current_opts_file = joinpath(build_root, 'options', build_dir)
6395522Snate@binkert.org    if os.path.isfile(current_opts_file):
6405522Snate@binkert.org        sticky_opts.files.append(current_opts_file)
6415522Snate@binkert.org        print "Using saved options file %s" % current_opts_file
6425522Snate@binkert.org    else:
6431858SN/A        # Build dir-specific options file doesn't exist.
6445227Ssaidi@eecs.umich.edu
6455227Ssaidi@eecs.umich.edu        # Make sure the directory is there so we can create it later
6465227Ssaidi@eecs.umich.edu        opt_dir = os.path.dirname(current_opts_file)
6475227Ssaidi@eecs.umich.edu        if not os.path.isdir(opt_dir):
6486654Snate@binkert.org            os.mkdir(opt_dir)
6496654Snate@binkert.org
6507769SAli.Saidi@ARM.com        # Get default build options from source tree.  Options are
6517769SAli.Saidi@ARM.com        # normally determined by name of $BUILD_DIR, but can be
6527769SAli.Saidi@ARM.com        # overriden by 'default=' arg on command line.
6537769SAli.Saidi@ARM.com        default_opts_file = joinpath('build_opts',
6545227Ssaidi@eecs.umich.edu                                     ARGUMENTS.get('default', build_dir))
6555227Ssaidi@eecs.umich.edu        if os.path.isfile(default_opts_file):
6565227Ssaidi@eecs.umich.edu            sticky_opts.files.append(default_opts_file)
6575204Sstever@gmail.com            print "Options file %s not found,\n  using defaults in %s" \
6585204Sstever@gmail.com                  % (current_opts_file, default_opts_file)
6595204Sstever@gmail.com        else:
6605204Sstever@gmail.com            print "Error: cannot find options file %s or %s" \
6615204Sstever@gmail.com                  % (current_opts_file, default_opts_file)
6625204Sstever@gmail.com            Exit(1)
6635204Sstever@gmail.com
6645204Sstever@gmail.com    # Apply current option settings to env
6655204Sstever@gmail.com    sticky_opts.Update(env)
6665204Sstever@gmail.com    nonsticky_opts.Update(env)
6675204Sstever@gmail.com
6685204Sstever@gmail.com    help_text += "Sticky options for %s:\n" % build_dir \
6695204Sstever@gmail.com                 + sticky_opts.GenerateHelpText(env) \
6705204Sstever@gmail.com                 + "\nNon-sticky options for %s:\n" % build_dir \
6715204Sstever@gmail.com                 + nonsticky_opts.GenerateHelpText(env)
6725204Sstever@gmail.com
6735204Sstever@gmail.com    # Process option settings.
6746121Snate@binkert.org
6755204Sstever@gmail.com    if not have_fenv and env['USE_FENV']:
6763118Sstever@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
6773118Sstever@eecs.umich.edu              "forcing USE_FENV to False in", build_dir + "."
6783118Sstever@eecs.umich.edu        env['USE_FENV'] = False
6793118Sstever@eecs.umich.edu
6803118Sstever@eecs.umich.edu    if not env['USE_FENV']:
6815863Snate@binkert.org        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
6823118Sstever@eecs.umich.edu        print "         FP results may deviate slightly from other platforms."
6835863Snate@binkert.org
6843118Sstever@eecs.umich.edu    if env['EFENCE']:
6857457Snate@binkert.org        env.Append(LIBS=['efence'])
6867457Snate@binkert.org
6875863Snate@binkert.org    if env['USE_MYSQL']:
6885863Snate@binkert.org        if not have_mysql:
6895863Snate@binkert.org            print "Warning: MySQL not available; " \
6905863Snate@binkert.org                  "forcing USE_MYSQL to False in", build_dir + "."
6915863Snate@binkert.org            env['USE_MYSQL'] = False
6925863Snate@binkert.org        else:
6935863Snate@binkert.org            print "Compiling in", build_dir, "with MySQL support."
6946003Snate@binkert.org            env.ParseConfig(mysql_config_libs)
6955863Snate@binkert.org            env.ParseConfig(mysql_config_include)
6965863Snate@binkert.org
6975863Snate@binkert.org    # Save sticky option settings back to current options file
6986120Snate@binkert.org    sticky_opts.Save(current_opts_file, env)
6995863Snate@binkert.org
7005863Snate@binkert.org    # Do this after we save setting back, or else we'll tack on an
7015863Snate@binkert.org    # extra 'qdo' every time we run scons.
7028655Sandreas.hansson@arm.com    if env['BATCH']:
7038655Sandreas.hansson@arm.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
7048655Sandreas.hansson@arm.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
7058655Sandreas.hansson@arm.com
7068655Sandreas.hansson@arm.com    if env['USE_SSE2']:
7078655Sandreas.hansson@arm.com        env.Append(CCFLAGS='-msse2')
7088655Sandreas.hansson@arm.com
7098655Sandreas.hansson@arm.com    # The src/SConscript file sets up the build rules in 'env' according
7106120Snate@binkert.org    # to the configured options.  It returns a list of environments,
7115863Snate@binkert.org    # one for each variant build (debug, opt, etc.)
7126121Snate@binkert.org    envList = SConscript('src/SConscript', build_dir = build_path,
7136121Snate@binkert.org                         exports = 'env')
7145863Snate@binkert.org
7157727SAli.Saidi@ARM.com    # Set up the regression tests for each build.
7167727SAli.Saidi@ARM.com    for e in envList:
7177727SAli.Saidi@ARM.com        SConscript('tests/SConscript',
7187727SAli.Saidi@ARM.com                   build_dir = joinpath(build_path, 'tests', e.Label),
7197727SAli.Saidi@ARM.com                   exports = { 'env' : e }, duplicate = False)
7207727SAli.Saidi@ARM.com
7215863Snate@binkert.orgHelp(help_text)
7223118Sstever@eecs.umich.edu
7235863Snate@binkert.org
7243118Sstever@eecs.umich.edu###################################################
7253118Sstever@eecs.umich.edu#
7265863Snate@binkert.org# Let SCons do its thing.  At this point SCons will use the defined
7275863Snate@binkert.org# build environments to build the requested targets.
7285863Snate@binkert.org#
7295863Snate@binkert.org###################################################
7303118Sstever@eecs.umich.edu
7313483Ssaidi@eecs.umich.edu