SConstruct revision 5227
1955SN/A# -*- mode:python -*-
2955SN/A
39812Sandreas.hansson@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from
157816Ssteve.reinhardt@amd.com# this software without specific prior written permission.
165871Snate@binkert.org#
171762SN/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
30955SN/A
31955SN/A###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
35955SN/A# While in this directory ('m5'), just type 'scons' to build the default
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
38955SN/A# the optimized full-system version).
39955SN/A#
40955SN/A# You can build M5 in a different directory as long as there is a
41955SN/A# 'build/<CONFIG>' somewhere along the target path.  The build system
422665Ssaidi@eecs.umich.edu# expects that all configs under the same build directory are being
432665Ssaidi@eecs.umich.edu# built for the same host system.
445863Snate@binkert.org#
45955SN/A# Examples:
46955SN/A#
47955SN/A#   The following two commands are equivalent.  The '-u' option tells
48955SN/A#   scons to search up the directory tree for this SConstruct file.
49955SN/A#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
508878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512632Sstever@eecs.umich.edu#
528878Ssteve.reinhardt@amd.com#   The following two commands are equivalent and demonstrate building
532632Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
54955SN/A#   scons to chdir to the specified directory to find this SConstruct
558878Ssteve.reinhardt@amd.com#   file.
562632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
572761Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
582632Sstever@eecs.umich.edu#
592632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
602632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
612761Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
622761Sstever@eecs.umich.edu# options as well.
632761Sstever@eecs.umich.edu#
648878Ssteve.reinhardt@amd.com###################################################
658878Ssteve.reinhardt@amd.com
662761Sstever@eecs.umich.eduimport sys
672761Sstever@eecs.umich.eduimport os
682761Sstever@eecs.umich.edu
692761Sstever@eecs.umich.edufrom os.path import isdir, join as joinpath
702761Sstever@eecs.umich.edu
718878Ssteve.reinhardt@amd.com# Check for recent-enough Python and SCons versions.  If your system's
728878Ssteve.reinhardt@amd.com# default installation of Python is not recent enough, you can use a
732632Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1)
742632Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python'
758878Ssteve.reinhardt@amd.com# first or (2) explicitly invoking an alternative interpreter on the
768878Ssteve.reinhardt@amd.com# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
772632Sstever@eecs.umich.eduEnsurePythonVersion(2,4)
78955SN/A
79955SN/A# Import subprocess after we check the version since it doesn't exist in
80955SN/A# Python < 2.4.
815863Snate@binkert.orgimport subprocess
825863Snate@binkert.org
835863Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
845863Snate@binkert.org# 3-element version number.
855863Snate@binkert.orgmin_scons_version = (0,96,91)
865863Snate@binkert.orgtry:
875863Snate@binkert.org    EnsureSConsVersion(*min_scons_version)
885863Snate@binkert.orgexcept:
895863Snate@binkert.org    print "Error checking current SCons version."
905863Snate@binkert.org    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
915863Snate@binkert.org    Exit(2)
928878Ssteve.reinhardt@amd.com
935863Snate@binkert.org
945863Snate@binkert.org# The absolute path to the current directory (where this file lives).
955863Snate@binkert.orgROOT = Dir('.').abspath
969812Sandreas.hansson@arm.com
979812Sandreas.hansson@arm.com# Path to the M5 source tree.
985863Snate@binkert.orgSRCDIR = joinpath(ROOT, 'src')
999812Sandreas.hansson@arm.com
1005863Snate@binkert.org# tell python where to find m5 python code
1015863Snate@binkert.orgsys.path.append(joinpath(ROOT, 'src/python'))
1025863Snate@binkert.org
1039812Sandreas.hansson@arm.comdef check_style_hook(ui):
1049812Sandreas.hansson@arm.com    ui.readconfig(joinpath(ROOT, '.hg', 'hgrc'))
1055863Snate@binkert.org    style_hook = ui.config('hooks', 'pretxncommit.style', None)
1065863Snate@binkert.org
1078878Ssteve.reinhardt@amd.com    if not style_hook:
1085863Snate@binkert.org        print """\
1095863Snate@binkert.orgYou're missing the M5 style hook.
1105863Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style.
1116654Snate@binkert.org
112955SN/AAll you'd need to do is add the following lines to your repository .hg/hgrc
1135396Ssaidi@eecs.umich.eduor your personal .hgrc
1145863Snate@binkert.org----------------
1155863Snate@binkert.org
1164202Sbinkertn@umich.edu[extensions]
1175863Snate@binkert.orgstyle = %s/util/style.py
1185863Snate@binkert.org
1195863Snate@binkert.org[hooks]
1205863Snate@binkert.orgpretxncommit.style = python:style.check_whitespace
121955SN/A""" % (ROOT)
1226654Snate@binkert.org        sys.exit(1)
1235273Sstever@gmail.com
1245871Snate@binkert.orgif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')):
1255273Sstever@gmail.com    try:
1266655Snate@binkert.org        from mercurial import ui
1278878Ssteve.reinhardt@amd.com        check_style_hook(ui.ui())
1286655Snate@binkert.org    except ImportError:
1296655Snate@binkert.org        pass
1309219Spower.jg@gmail.com
1316655Snate@binkert.org###################################################
1325871Snate@binkert.org#
1336654Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
1348947Sandreas.hansson@arm.com# the target(s).
1355396Ssaidi@eecs.umich.edu#
1368120Sgblack@eecs.umich.edu###################################################
1378120Sgblack@eecs.umich.edu
1388120Sgblack@eecs.umich.edu# Find default configuration & binary.
1398120Sgblack@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1408120Sgblack@eecs.umich.edu
1418120Sgblack@eecs.umich.edu# helper function: find last occurrence of element in list
1428120Sgblack@eecs.umich.edudef rfind(l, elt, offs = -1):
1438120Sgblack@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1448879Ssteve.reinhardt@amd.com        if l[i] == elt:
1458879Ssteve.reinhardt@amd.com            return i
1468879Ssteve.reinhardt@amd.com    raise ValueError, "element not found"
1478879Ssteve.reinhardt@amd.com
1488879Ssteve.reinhardt@amd.com# helper function: compare dotted version numbers.
1498879Ssteve.reinhardt@amd.com# E.g., compare_version('1.3.25', '1.4.1')
1508879Ssteve.reinhardt@amd.com# returns -1, 0, 1 if v1 is <, ==, > v2
1518879Ssteve.reinhardt@amd.comdef compare_versions(v1, v2):
1528879Ssteve.reinhardt@amd.com    # Convert dotted strings to lists
1538879Ssteve.reinhardt@amd.com    v1 = map(int, v1.split('.'))
1548879Ssteve.reinhardt@amd.com    v2 = map(int, v2.split('.'))
1558879Ssteve.reinhardt@amd.com    # Compare corresponding elements of lists
1568879Ssteve.reinhardt@amd.com    for n1,n2 in zip(v1, v2):
1578120Sgblack@eecs.umich.edu        if n1 < n2: return -1
1588120Sgblack@eecs.umich.edu        if n1 > n2: return  1
1598120Sgblack@eecs.umich.edu    # all corresponding values are equal... see if one has extra values
1608120Sgblack@eecs.umich.edu    if len(v1) < len(v2): return -1
1618120Sgblack@eecs.umich.edu    if len(v1) > len(v2): return  1
1628120Sgblack@eecs.umich.edu    return 0
1638120Sgblack@eecs.umich.edu
1648120Sgblack@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1658120Sgblack@eecs.umich.edu# directory below this will determine the build parameters.  For
1668120Sgblack@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1678120Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1688120Sgblack@eecs.umich.edu# follow 'build' in the bulid path.
1698120Sgblack@eecs.umich.edu
1708120Sgblack@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is
1718879Ssteve.reinhardt@amd.comif COMMAND_LINE_TARGETS:
1728879Ssteve.reinhardt@amd.com    # Ask SCons which directory it was invoked from
1738879Ssteve.reinhardt@amd.com    launch_dir = GetLaunchDir()
1748879Ssteve.reinhardt@amd.com    # Make targets relative to invocation directory
1758879Ssteve.reinhardt@amd.com    abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))),
1768879Ssteve.reinhardt@amd.com                      COMMAND_LINE_TARGETS)
1778879Ssteve.reinhardt@amd.comelse:
1788879Ssteve.reinhardt@amd.com    # Default targets are relative to root of tree
1799227Sandreas.hansson@arm.com    abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))),
1809227Sandreas.hansson@arm.com                      DEFAULT_TARGETS)
1818879Ssteve.reinhardt@amd.com
1828879Ssteve.reinhardt@amd.com
1838879Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the
1848879Ssteve.reinhardt@amd.com# collected targets reference.
1858120Sgblack@eecs.umich.edubuild_paths = []
1868947Sandreas.hansson@arm.combuild_root = None
1877816Ssteve.reinhardt@amd.comfor t in abs_targets:
1885871Snate@binkert.org    path_dirs = t.split('/')
1895871Snate@binkert.org    try:
1906121Snate@binkert.org        build_top = rfind(path_dirs, 'build', -2)
1915871Snate@binkert.org    except:
1925871Snate@binkert.org        print "Error: no non-leaf 'build' dir found on target path", t
1939119Sandreas.hansson@arm.com        Exit(1)
1949396Sandreas.hansson@arm.com    this_build_root = joinpath('/',*path_dirs[:build_top+1])
1959396Sandreas.hansson@arm.com    if not build_root:
196955SN/A        build_root = this_build_root
1979416SAndreas.Sandberg@ARM.com    else:
1989416SAndreas.Sandberg@ARM.com        if this_build_root != build_root:
1999416SAndreas.Sandberg@ARM.com            print "Error: build targets not under same build root\n"\
2009416SAndreas.Sandberg@ARM.com                  "  %s\n  %s" % (build_root, this_build_root)
2019416SAndreas.Sandberg@ARM.com            Exit(1)
2029416SAndreas.Sandberg@ARM.com    build_path = joinpath('/',*path_dirs[:build_top+2])
2039416SAndreas.Sandberg@ARM.com    if build_path not in build_paths:
2045871Snate@binkert.org        build_paths.append(build_path)
2055871Snate@binkert.org
2069416SAndreas.Sandberg@ARM.com###################################################
2079416SAndreas.Sandberg@ARM.com#
2085871Snate@binkert.org# Set up the default build environment.  This environment is copied
209955SN/A# and modified according to each selected configuration.
2106121Snate@binkert.org#
2118881Smarc.orr@gmail.com###################################################
2126121Snate@binkert.org
2136121Snate@binkert.orgenv = Environment(ENV = os.environ,  # inherit user's environment vars
2141533SN/A                  ROOT = ROOT,
2159239Sandreas.hansson@arm.com                  SRCDIR = SRCDIR)
2169239Sandreas.hansson@arm.com
2179239Sandreas.hansson@arm.com#Parse CC/CXX early so that we use the correct compiler for
2189239Sandreas.hansson@arm.com# to test for dependencies/versions/libraries/includes
2199239Sandreas.hansson@arm.comif ARGUMENTS.get('CC', None):
2209239Sandreas.hansson@arm.com    env['CC'] = ARGUMENTS.get('CC')
2219239Sandreas.hansson@arm.com
2229239Sandreas.hansson@arm.comif ARGUMENTS.get('CXX', None):
2239239Sandreas.hansson@arm.com    env['CXX'] = ARGUMENTS.get('CXX')
2249239Sandreas.hansson@arm.com
2259239Sandreas.hansson@arm.comExport('env')
2269239Sandreas.hansson@arm.com
2276655Snate@binkert.orgenv.SConsignFile(joinpath(build_root,"sconsign"))
2286655Snate@binkert.org
2296655Snate@binkert.org# Default duplicate option is to use hard links, but this messes up
2306655Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves
2315871Snate@binkert.org# file to file~ then copies to file, breaking the link.  Symbolic
2325871Snate@binkert.org# (soft) links work better.
2335863Snate@binkert.orgenv.SetOption('duplicate', 'soft-copy')
2345871Snate@binkert.org
2358878Ssteve.reinhardt@amd.com# I waffle on this setting... it does avoid a few painful but
2365871Snate@binkert.org# unnecessary builds, but it also seems to make trivial builds take
2375871Snate@binkert.org# noticeably longer.
2385871Snate@binkert.orgif False:
2395863Snate@binkert.org    env.TargetSignatures('content')
2406121Snate@binkert.org
2415863Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package.
2425871Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) })
2438336Ssteve.reinhardt@amd.comenv['GCC'] = False
2448336Ssteve.reinhardt@amd.comenv['SUNCC'] = False
2458336Ssteve.reinhardt@amd.comenv['ICC'] = False
2468336Ssteve.reinhardt@amd.comenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True,
2474678Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
2488336Ssteve.reinhardt@amd.com        close_fds=True).communicate()[0].find('GCC') >= 0
2498336Ssteve.reinhardt@amd.comenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
2508336Ssteve.reinhardt@amd.com        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
2514678Snate@binkert.org        close_fds=True).communicate()[0].find('Sun C++') >= 0
2524678Snate@binkert.orgenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True,
2534678Snate@binkert.org        stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
2544678Snate@binkert.org        close_fds=True).communicate()[0].find('Intel') >= 0
2557827Snate@binkert.orgif env['GCC'] + env['SUNCC'] + env['ICC'] > 1:
2567827Snate@binkert.org    print 'Error: How can we have two at the same time?'
2578336Ssteve.reinhardt@amd.com    Exit(1)
2584678Snate@binkert.org
2598336Ssteve.reinhardt@amd.com
2608336Ssteve.reinhardt@amd.com# Set up default C++ compiler flags
2618336Ssteve.reinhardt@amd.comif env['GCC']:
2628336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS='-pipe')
2638336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS='-fno-strict-aliasing')
2648336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2655871Snate@binkert.orgelif env['ICC']:
2665871Snate@binkert.org    pass #Fix me... add warning flags once we clean up icc warnings
2678336Ssteve.reinhardt@amd.comelif env['SUNCC']:
2688336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS='-Qoption ccfe')
2698336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS='-features=gcc')
2708336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS='-features=extensions')
2718336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS='-library=stlport4')
2725871Snate@binkert.org    env.Append(CCFLAGS='-xar')
2738336Ssteve.reinhardt@amd.com#    env.Append(CCFLAGS='-instances=semiexplicit')
2748336Ssteve.reinhardt@amd.comelse:
2758336Ssteve.reinhardt@amd.com    print 'Error: Don\'t know what compiler options to use for your compiler.'
2768336Ssteve.reinhardt@amd.com    print '       Please fix SConstruct and src/SConscript and try again.'
2778336Ssteve.reinhardt@amd.com    Exit(1)
2784678Snate@binkert.org
2795871Snate@binkert.orgif sys.platform == 'cygwin':
2804678Snate@binkert.org    # cygwin has some header file issues...
2818336Ssteve.reinhardt@amd.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
2828336Ssteve.reinhardt@amd.comenv.Append(CPPPATH=[Dir('ext/dnet')])
2838336Ssteve.reinhardt@amd.com
2848336Ssteve.reinhardt@amd.com# Check for SWIG
2858336Ssteve.reinhardt@amd.comif not env.has_key('SWIG'):
2868336Ssteve.reinhardt@amd.com    print 'Error: SWIG utility not found.'
2878336Ssteve.reinhardt@amd.com    print '       Please install (see http://www.swig.org) and retry.'
2888336Ssteve.reinhardt@amd.com    Exit(1)
2898336Ssteve.reinhardt@amd.com
2908336Ssteve.reinhardt@amd.com# Check for appropriate SWIG version
2918336Ssteve.reinhardt@amd.comswig_version = os.popen('swig -version').read().split()
2928336Ssteve.reinhardt@amd.com# First 3 words should be "SWIG Version x.y.z"
2938336Ssteve.reinhardt@amd.comif len(swig_version) < 3 or \
2948336Ssteve.reinhardt@amd.com        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
2958336Ssteve.reinhardt@amd.com    print 'Error determining SWIG version.'
2968336Ssteve.reinhardt@amd.com    Exit(1)
2978336Ssteve.reinhardt@amd.com
2985871Snate@binkert.orgmin_swig_version = '1.3.28'
2996121Snate@binkert.orgif compare_versions(swig_version[2], min_swig_version) < 0:
300955SN/A    print 'Error: SWIG version', min_swig_version, 'or newer required.'
301955SN/A    print '       Installed version:', swig_version[2]
3022632Sstever@eecs.umich.edu    Exit(1)
3032632Sstever@eecs.umich.edu
304955SN/A# Set up SWIG flags & scanner
305955SN/Aswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
306955SN/Aenv.Append(SWIGFLAGS=swig_flags)
307955SN/A
3088878Ssteve.reinhardt@amd.com# filter out all existing swig scanners, they mess up the dependency
309955SN/A# stuff for some reason
3102632Sstever@eecs.umich.eduscanners = []
3112632Sstever@eecs.umich.edufor scanner in env['SCANNERS']:
3122632Sstever@eecs.umich.edu    skeys = scanner.skeys
3132632Sstever@eecs.umich.edu    if skeys == '.i':
3142632Sstever@eecs.umich.edu        continue
3152632Sstever@eecs.umich.edu
3162632Sstever@eecs.umich.edu    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
3178268Ssteve.reinhardt@amd.com        continue
3188268Ssteve.reinhardt@amd.com
3198268Ssteve.reinhardt@amd.com    scanners.append(scanner)
3208268Ssteve.reinhardt@amd.com
3218268Ssteve.reinhardt@amd.com# add the new swig scanner that we like better
3228268Ssteve.reinhardt@amd.comfrom SCons.Scanner import ClassicCPP as CPPScanner
3238268Ssteve.reinhardt@amd.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
3242632Sstever@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
3252632Sstever@eecs.umich.edu
3262632Sstever@eecs.umich.edu# replace the scanners list that has what we want
3272632Sstever@eecs.umich.eduenv['SCANNERS'] = scanners
3288268Ssteve.reinhardt@amd.com
3292632Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
3308268Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform.
3318268Ssteve.reinhardt@amd.comconf = Configure(env,
3328268Ssteve.reinhardt@amd.com                 conf_dir = joinpath(build_root, '.scons_config'),
3338268Ssteve.reinhardt@amd.com                 log_file = joinpath(build_root, 'scons_config.log'))
3343718Sstever@eecs.umich.edu
3352634Sstever@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
3362634Sstever@eecs.umich.edutry:
3375863Snate@binkert.org    import platform
3382638Sstever@eecs.umich.edu    uname = platform.uname()
3398268Ssteve.reinhardt@amd.com    if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
3402632Sstever@eecs.umich.edu        if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True,
3412632Sstever@eecs.umich.edu               stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
3422632Sstever@eecs.umich.edu               close_fds=True).communicate()[0][0]):
3432632Sstever@eecs.umich.edu            env.Append(CCFLAGS='-arch x86_64')
3442632Sstever@eecs.umich.edu            env.Append(CFLAGS='-arch x86_64')
3451858SN/A            env.Append(LINKFLAGS='-arch x86_64')
3463716Sstever@eecs.umich.edu            env.Append(ASFLAGS='-arch x86_64')
3472638Sstever@eecs.umich.eduexcept:
3482638Sstever@eecs.umich.edu    pass
3492638Sstever@eecs.umich.edu
3502638Sstever@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure()
3512638Sstever@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is
3522638Sstever@eecs.umich.edu# present.  Unfortuantely this Null object always returns false,
3532638Sstever@eecs.umich.edu# breaking all our configuration checks.  We replace it with our own
3545863Snate@binkert.org# more optimistic null object that returns True instead.
3555863Snate@binkert.orgif not conf:
3565863Snate@binkert.org    def NullCheck(*args, **kwargs):
357955SN/A        return True
3585341Sstever@gmail.com
3595341Sstever@gmail.com    class NullConf:
3605863Snate@binkert.org        def __init__(self, env):
3617756SAli.Saidi@ARM.com            self.env = env
3625341Sstever@gmail.com        def Finish(self):
3636121Snate@binkert.org            return self.env
3644494Ssaidi@eecs.umich.edu        def __getattr__(self, mname):
3656121Snate@binkert.org            return NullCheck
3661105SN/A
3672667Sstever@eecs.umich.edu    conf = NullConf(env)
3682667Sstever@eecs.umich.edu
3692667Sstever@eecs.umich.edu# Find Python include and library directories for embedding the
3702667Sstever@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
3716121Snate@binkert.org# installation used to run scons (and thus this script).  If you want
3722667Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
3735341Sstever@gmail.com# to invoke scons with a different copy of the Python interpreter.
3745863Snate@binkert.org
3755341Sstever@gmail.com# Get brief Python version name (e.g., "python2.4") for locating
3765341Sstever@gmail.com# include & library files
3775341Sstever@gmail.compy_version_name = 'python' + sys.version[:3]
3788120Sgblack@eecs.umich.edu
3795341Sstever@gmail.com# include path, e.g. /usr/local/include/python2.4
3808120Sgblack@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name)
3815341Sstever@gmail.comenv.Append(CPPPATH = py_header_path)
3828120Sgblack@eecs.umich.edu# verify that it works
3836121Snate@binkert.orgif not conf.CheckHeader('Python.h', '<>'):
3846121Snate@binkert.org    print "Error: can't find Python.h header in", py_header_path
3858980Ssteve.reinhardt@amd.com    Exit(1)
3869396Sandreas.hansson@arm.com
3875397Ssaidi@eecs.umich.edu# add library path too if it's not in the default place
3885397Ssaidi@eecs.umich.edupy_lib_path = None
3897727SAli.Saidi@ARM.comif sys.exec_prefix != '/usr':
3908268Ssteve.reinhardt@amd.com    py_lib_path = joinpath(sys.exec_prefix, 'lib')
3916168Snate@binkert.orgelif sys.platform == 'cygwin':
3925341Sstever@gmail.com    # cygwin puts the .dll in /bin for some reason
3938120Sgblack@eecs.umich.edu    py_lib_path = '/bin'
3948120Sgblack@eecs.umich.eduif py_lib_path:
3958120Sgblack@eecs.umich.edu    env.Append(LIBPATH = py_lib_path)
3966814Sgblack@eecs.umich.edu    print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name
3975863Snate@binkert.orgif not conf.CheckLib(py_version_name):
3988120Sgblack@eecs.umich.edu    print "Error: can't find Python library", py_version_name
3995341Sstever@gmail.com    Exit(1)
4005863Snate@binkert.org
4018268Ssteve.reinhardt@amd.com# On Solaris you need to use libsocket for socket ops
4026121Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4036121Snate@binkert.org   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
4048268Ssteve.reinhardt@amd.com       print "Can't find library with socket calls (e.g. accept())"
4055742Snate@binkert.org       Exit(1)
4065742Snate@binkert.org
4075341Sstever@gmail.com# Check for zlib.  If the check passes, libz will be automatically
4085742Snate@binkert.org# added to the LIBS environment variable.
4095742Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
4105341Sstever@gmail.com    print 'Error: did not find needed zlib compression library '\
4116017Snate@binkert.org          'and/or zlib.h header file.'
4126121Snate@binkert.org    print '       Please install zlib and try again.'
4136017Snate@binkert.org    Exit(1)
4147816Ssteve.reinhardt@amd.com
4157756SAli.Saidi@ARM.com# Check for <fenv.h> (C99 FP environment control)
4167756SAli.Saidi@ARM.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
4177756SAli.Saidi@ARM.comif not have_fenv:
4187756SAli.Saidi@ARM.com    print "Warning: Header file <fenv.h> not found."
4197756SAli.Saidi@ARM.com    print "         This host has no IEEE FP rounding mode control."
4207756SAli.Saidi@ARM.com
4217756SAli.Saidi@ARM.com# Check for mysql.
4227756SAli.Saidi@ARM.commysql_config = WhereIs('mysql_config')
4237816Ssteve.reinhardt@amd.comhave_mysql = mysql_config != None
4247816Ssteve.reinhardt@amd.com
4257816Ssteve.reinhardt@amd.com# Check MySQL version.
4267816Ssteve.reinhardt@amd.comif have_mysql:
4277816Ssteve.reinhardt@amd.com    mysql_version = os.popen(mysql_config + ' --version').read()
4287816Ssteve.reinhardt@amd.com    min_mysql_version = '4.1'
4297816Ssteve.reinhardt@amd.com    if compare_versions(mysql_version, min_mysql_version) < 0:
4307816Ssteve.reinhardt@amd.com        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
4317816Ssteve.reinhardt@amd.com        print '         Version', mysql_version, 'detected.'
4327816Ssteve.reinhardt@amd.com        have_mysql = False
4337756SAli.Saidi@ARM.com
4347816Ssteve.reinhardt@amd.com# Set up mysql_config commands.
4357816Ssteve.reinhardt@amd.comif have_mysql:
4367816Ssteve.reinhardt@amd.com    mysql_config_include = mysql_config + ' --include'
4377816Ssteve.reinhardt@amd.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
4387816Ssteve.reinhardt@amd.com        # older mysql_config versions don't support --include, use
4397816Ssteve.reinhardt@amd.com        # --cflags instead
4407816Ssteve.reinhardt@amd.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
4417816Ssteve.reinhardt@amd.com    # This seems to work in all versions
4427816Ssteve.reinhardt@amd.com    mysql_config_libs = mysql_config + ' --libs'
4437816Ssteve.reinhardt@amd.com
4447816Ssteve.reinhardt@amd.comenv = conf.Finish()
4457816Ssteve.reinhardt@amd.com
4467816Ssteve.reinhardt@amd.com# Define the universe of supported ISAs
4477816Ssteve.reinhardt@amd.comall_isa_list = [ ]
4487816Ssteve.reinhardt@amd.comExport('all_isa_list')
4497816Ssteve.reinhardt@amd.com
4507816Ssteve.reinhardt@amd.com# Define the universe of supported CPU models
4517816Ssteve.reinhardt@amd.comall_cpu_list = [ ]
4527816Ssteve.reinhardt@amd.comdefault_cpus = [ ]
4537816Ssteve.reinhardt@amd.comExport('all_cpu_list', 'default_cpus')
4547816Ssteve.reinhardt@amd.com
4557816Ssteve.reinhardt@amd.com# Sticky options get saved in the options file so they persist from
4567816Ssteve.reinhardt@amd.com# one invocation to the next (unless overridden, in which case the new
4577816Ssteve.reinhardt@amd.com# value becomes sticky).
4587816Ssteve.reinhardt@amd.comsticky_opts = Options(args=ARGUMENTS)
4597816Ssteve.reinhardt@amd.comExport('sticky_opts')
4607816Ssteve.reinhardt@amd.com
4617816Ssteve.reinhardt@amd.com# Non-sticky options only apply to the current build.
4627816Ssteve.reinhardt@amd.comnonsticky_opts = Options(args=ARGUMENTS)
4637816Ssteve.reinhardt@amd.comExport('nonsticky_opts')
4647816Ssteve.reinhardt@amd.com
4657816Ssteve.reinhardt@amd.com# Walk the tree and execute all SConsopts scripts that wil add to the
4667816Ssteve.reinhardt@amd.com# above options
4677816Ssteve.reinhardt@amd.comfor root, dirs, files in os.walk('.'):
4687816Ssteve.reinhardt@amd.com    if 'SConsopts' in files:
4697816Ssteve.reinhardt@amd.com        SConscript(os.path.join(root, 'SConsopts'))
4707816Ssteve.reinhardt@amd.com
4717816Ssteve.reinhardt@amd.comall_isa_list.sort()
4727816Ssteve.reinhardt@amd.comall_cpu_list.sort()
4737816Ssteve.reinhardt@amd.comdefault_cpus.sort()
4747816Ssteve.reinhardt@amd.com
4757816Ssteve.reinhardt@amd.comdef ExtraPathValidator(key, val, env):
4767816Ssteve.reinhardt@amd.com    if not val:
4777816Ssteve.reinhardt@amd.com        return
4787816Ssteve.reinhardt@amd.com    paths = val.split(':')
4797816Ssteve.reinhardt@amd.com    for path in paths:
4807816Ssteve.reinhardt@amd.com        path = os.path.expanduser(path)
4817816Ssteve.reinhardt@amd.com        if not isdir(path):
4827816Ssteve.reinhardt@amd.com            raise AttributeError, "Invalid path: '%s'" % path
4837816Ssteve.reinhardt@amd.com
4847816Ssteve.reinhardt@amd.comsticky_opts.AddOptions(
4857816Ssteve.reinhardt@amd.com    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
4867816Ssteve.reinhardt@amd.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
4877816Ssteve.reinhardt@amd.com    # There's a bug in scons 0.96.1 that causes ListOptions with list
4887816Ssteve.reinhardt@amd.com    # values (more than one value) not to be able to be restored from
4897816Ssteve.reinhardt@amd.com    # a saved option file.  If this causes trouble then upgrade to
4907816Ssteve.reinhardt@amd.com    # scons 0.96.90 or later.
4917816Ssteve.reinhardt@amd.com    ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
4927816Ssteve.reinhardt@amd.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
4937816Ssteve.reinhardt@amd.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
4947816Ssteve.reinhardt@amd.com               False),
4958947Sandreas.hansson@arm.com    BoolOption('SS_COMPATIBLE_FP',
4968947Sandreas.hansson@arm.com               'Make floating-point results compatible with SimpleScalar',
4977756SAli.Saidi@ARM.com               False),
4988120Sgblack@eecs.umich.edu    BoolOption('USE_SSE2',
4997756SAli.Saidi@ARM.com               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
5007756SAli.Saidi@ARM.com               False),
5017756SAli.Saidi@ARM.com    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
5027756SAli.Saidi@ARM.com    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
5037816Ssteve.reinhardt@amd.com    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
5047816Ssteve.reinhardt@amd.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
5057816Ssteve.reinhardt@amd.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
5067816Ssteve.reinhardt@amd.com    BoolOption('BATCH', 'Use batch pool for build and tests', False),
5077816Ssteve.reinhardt@amd.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
5087816Ssteve.reinhardt@amd.com    ('PYTHONHOME',
5097816Ssteve.reinhardt@amd.com     'Override the default PYTHONHOME for this system (use with caution)',
5107816Ssteve.reinhardt@amd.com     '%s:%s' % (sys.prefix, sys.exec_prefix)),
5117816Ssteve.reinhardt@amd.com    ('EXTRAS', 'Add Extra directories to the compilation', '',
5127816Ssteve.reinhardt@amd.com     ExtraPathValidator)
5137756SAli.Saidi@ARM.com    )
5147756SAli.Saidi@ARM.com
5159227Sandreas.hansson@arm.comnonsticky_opts.AddOptions(
5169227Sandreas.hansson@arm.com    BoolOption('update_ref', 'Update test reference outputs', False)
5179227Sandreas.hansson@arm.com    )
5189227Sandreas.hansson@arm.com
5199590Sandreas@sandberg.pp.se# These options get exported to #defines in config/*.hh (see src/SConscript).
5209590Sandreas@sandberg.pp.seenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
5219590Sandreas@sandberg.pp.se                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
5229590Sandreas@sandberg.pp.se                     'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
5239590Sandreas@sandberg.pp.se
5249590Sandreas@sandberg.pp.se# Define a handy 'no-op' action
5256654Snate@binkert.orgdef no_action(target, source, env):
5266654Snate@binkert.org    return 0
5275871Snate@binkert.org
5286121Snate@binkert.orgenv.NoAction = Action(no_action, None)
5298946Sandreas.hansson@arm.com
5309419Sandreas.hansson@arm.com###################################################
5313940Ssaidi@eecs.umich.edu#
5323918Ssaidi@eecs.umich.edu# Define a SCons builder for configuration flag headers.
5333918Ssaidi@eecs.umich.edu#
5341858SN/A###################################################
5359556Sandreas.hansson@arm.com
5369556Sandreas.hansson@arm.com# This function generates a config header file that #defines the
5379556Sandreas.hansson@arm.com# option symbol to the current option setting (0 or 1).  The source
5389556Sandreas.hansson@arm.com# operands are the name of the option and a Value node containing the
5399556Sandreas.hansson@arm.com# value of the option.
5409556Sandreas.hansson@arm.comdef build_config_file(target, source, env):
5419556Sandreas.hansson@arm.com    (option, value) = [s.get_contents() for s in source]
5429556Sandreas.hansson@arm.com    f = file(str(target[0]), 'w')
5439556Sandreas.hansson@arm.com    print >> f, '#define', option, value
5449556Sandreas.hansson@arm.com    f.close()
5459556Sandreas.hansson@arm.com    return None
5469556Sandreas.hansson@arm.com
5479556Sandreas.hansson@arm.com# Generate the message to be printed when building the config file.
5489556Sandreas.hansson@arm.comdef build_config_file_string(target, source, env):
5499556Sandreas.hansson@arm.com    (option, value) = [s.get_contents() for s in source]
5509556Sandreas.hansson@arm.com    return "Defining %s as %s in %s." % (option, value, target[0])
5519556Sandreas.hansson@arm.com
5529556Sandreas.hansson@arm.com# Combine the two functions into a scons Action object.
5539556Sandreas.hansson@arm.comconfig_action = Action(build_config_file, build_config_file_string)
5549556Sandreas.hansson@arm.com
5559556Sandreas.hansson@arm.com# The emitter munges the source & target node lists to reflect what
5569556Sandreas.hansson@arm.com# we're really doing.
5579556Sandreas.hansson@arm.comdef config_emitter(target, source, env):
5589556Sandreas.hansson@arm.com    # extract option name from Builder arg
5599556Sandreas.hansson@arm.com    option = str(target[0])
5609556Sandreas.hansson@arm.com    # True target is config header file
5619556Sandreas.hansson@arm.com    target = joinpath('config', option.lower() + '.hh')
5629556Sandreas.hansson@arm.com    val = env[option]
5639556Sandreas.hansson@arm.com    if isinstance(val, bool):
5649556Sandreas.hansson@arm.com        # Force value to 0/1
5659556Sandreas.hansson@arm.com        val = int(val)
5669556Sandreas.hansson@arm.com    elif isinstance(val, str):
5676121Snate@binkert.org        val = '"' + val + '"'
5689420Sandreas.hansson@arm.com
5699420Sandreas.hansson@arm.com    # Sources are option name & value (packaged in SCons Value nodes)
5709420Sandreas.hansson@arm.com    return ([target], [Value(option), Value(val)])
5719420Sandreas.hansson@arm.com
5729420Sandreas.hansson@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action)
5739420Sandreas.hansson@arm.com
5749420Sandreas.hansson@arm.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
5759420Sandreas.hansson@arm.com
5769420Sandreas.hansson@arm.com###################################################
5779420Sandreas.hansson@arm.com#
5789420Sandreas.hansson@arm.com# Define a SCons builder for copying files.  This is used by the
5797618SAli.Saidi@arm.com# Python zipfile code in src/python/SConscript, but is placed up here
5807618SAli.Saidi@arm.com# since it's potentially more generally applicable.
5817618SAli.Saidi@arm.com#
5827739Sgblack@eecs.umich.edu###################################################
5839227Sandreas.hansson@arm.com
5849227Sandreas.hansson@arm.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
5859227Sandreas.hansson@arm.com
5869227Sandreas.hansson@arm.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
5879227Sandreas.hansson@arm.com
5889227Sandreas.hansson@arm.com###################################################
5899227Sandreas.hansson@arm.com#
5909227Sandreas.hansson@arm.com# Define a simple SCons builder to concatenate files.
5919227Sandreas.hansson@arm.com#
5929227Sandreas.hansson@arm.com# Used to append the Python zip archive to the executable.
5939227Sandreas.hansson@arm.com#
5949227Sandreas.hansson@arm.com###################################################
5959227Sandreas.hansson@arm.com
5969227Sandreas.hansson@arm.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
5979227Sandreas.hansson@arm.com                                          'chmod +x $TARGET']))
5989227Sandreas.hansson@arm.com
5999227Sandreas.hansson@arm.comenv.Append(BUILDERS = { 'Concat' : concat_builder })
6009227Sandreas.hansson@arm.com
6019590Sandreas@sandberg.pp.se
6029590Sandreas@sandberg.pp.se# base help text
6039590Sandreas@sandberg.pp.sehelp_text = '''
6048737Skoansin.tan@gmail.comUsage: scons [scons options] [build options] [target(s)]
6059420Sandreas.hansson@arm.com
6069420Sandreas.hansson@arm.com'''
6079420Sandreas.hansson@arm.com
6088737Skoansin.tan@gmail.com# libelf build is shared across all configs in the build root.
6098737Skoansin.tan@gmail.comenv.SConscript('ext/libelf/SConscript',
6108737Skoansin.tan@gmail.com               build_dir = joinpath(build_root, 'libelf'),
6118737Skoansin.tan@gmail.com               exports = 'env')
6128737Skoansin.tan@gmail.com
6138737Skoansin.tan@gmail.com###################################################
6148737Skoansin.tan@gmail.com#
6158737Skoansin.tan@gmail.com# This function is used to set up a directory with switching headers
6168737Skoansin.tan@gmail.com#
6178737Skoansin.tan@gmail.com###################################################
6188737Skoansin.tan@gmail.com
6198737Skoansin.tan@gmail.comenv['ALL_ISA_LIST'] = all_isa_list
6209556Sandreas.hansson@arm.comdef make_switching_dir(dirname, switch_headers, env):
6219556Sandreas.hansson@arm.com    # Generate the header.  target[0] is the full path of the output
6229556Sandreas.hansson@arm.com    # header to generate.  'source' is a dummy variable, since we get the
6239556Sandreas.hansson@arm.com    # list of ISAs from env['ALL_ISA_LIST'].
6249556Sandreas.hansson@arm.com    def gen_switch_hdr(target, source, env):
6259556Sandreas.hansson@arm.com        fname = str(target[0])
6269556Sandreas.hansson@arm.com        basename = os.path.basename(fname)
6279556Sandreas.hansson@arm.com        f = open(fname, 'w')
6289556Sandreas.hansson@arm.com        f.write('#include "arch/isa_specific.hh"\n')
6299556Sandreas.hansson@arm.com        cond = '#if'
6309590Sandreas@sandberg.pp.se        for isa in all_isa_list:
6319590Sandreas@sandberg.pp.se            f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
6329420Sandreas.hansson@arm.com                    % (cond, isa.upper(), dirname, isa, basename))
6339846Sandreas.hansson@arm.com            cond = '#elif'
6349846Sandreas.hansson@arm.com        f.write('#else\n#error "THE_ISA not set"\n#endif\n')
6359846Sandreas.hansson@arm.com        f.close()
6369846Sandreas.hansson@arm.com        return 0
6378946Sandreas.hansson@arm.com
6383918Ssaidi@eecs.umich.edu    # String to print when generating header
6399068SAli.Saidi@ARM.com    def gen_switch_hdr_string(target, source, env):
6409068SAli.Saidi@ARM.com        return "Generating switch header " + str(target[0])
6419068SAli.Saidi@ARM.com
6429068SAli.Saidi@ARM.com    # Build SCons Action object. 'varlist' specifies env vars that this
6439068SAli.Saidi@ARM.com    # action depends on; when env['ALL_ISA_LIST'] changes these actions
6449068SAli.Saidi@ARM.com    # should get re-executed.
6459068SAli.Saidi@ARM.com    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
6469068SAli.Saidi@ARM.com                               varlist=['ALL_ISA_LIST'])
6479068SAli.Saidi@ARM.com
6489419Sandreas.hansson@arm.com    # Instantiate actions for each header
6499068SAli.Saidi@ARM.com    for hdr in switch_headers:
6509068SAli.Saidi@ARM.com        env.Command(hdr, [], switch_hdr_action)
6519068SAli.Saidi@ARM.comExport('make_switching_dir')
6529068SAli.Saidi@ARM.com
6539068SAli.Saidi@ARM.com###################################################
6549068SAli.Saidi@ARM.com#
6553918Ssaidi@eecs.umich.edu# Define build environments for selected configurations.
6563918Ssaidi@eecs.umich.edu#
6576157Snate@binkert.org###################################################
6586157Snate@binkert.org
6596157Snate@binkert.org# rename base env
6606157Snate@binkert.orgbase_env = env
6615397Ssaidi@eecs.umich.edu
6625397Ssaidi@eecs.umich.edufor build_path in build_paths:
6636121Snate@binkert.org    print "Building in", build_path
6646121Snate@binkert.org    env['BUILDDIR'] = build_path
6656121Snate@binkert.org
6666121Snate@binkert.org    # build_dir is the tail component of build path, and is used to
6676121Snate@binkert.org    # determine the build parameters (e.g., 'ALPHA_SE')
6686121Snate@binkert.org    (build_root, build_dir) = os.path.split(build_path)
6695397Ssaidi@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
6701851SN/A    env = base_env.Copy()
6711851SN/A
6727739Sgblack@eecs.umich.edu    # Set env options according to the build directory config.
673955SN/A    sticky_opts.files = []
6749396Sandreas.hansson@arm.com    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
6759396Sandreas.hansson@arm.com    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
6769396Sandreas.hansson@arm.com    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
6779396Sandreas.hansson@arm.com    current_opts_file = joinpath(build_root, 'options', build_dir)
6789396Sandreas.hansson@arm.com    if os.path.isfile(current_opts_file):
6799396Sandreas.hansson@arm.com        sticky_opts.files.append(current_opts_file)
6809396Sandreas.hansson@arm.com        print "Using saved options file %s" % current_opts_file
6819396Sandreas.hansson@arm.com    else:
6829396Sandreas.hansson@arm.com        # Build dir-specific options file doesn't exist.
6839396Sandreas.hansson@arm.com
6849396Sandreas.hansson@arm.com        # Make sure the directory is there so we can create it later
6859396Sandreas.hansson@arm.com        opt_dir = os.path.dirname(current_opts_file)
6869396Sandreas.hansson@arm.com        if not os.path.isdir(opt_dir):
6879396Sandreas.hansson@arm.com            os.mkdir(opt_dir)
6889396Sandreas.hansson@arm.com
6899396Sandreas.hansson@arm.com        # Get default build options from source tree.  Options are
6909477Sandreas.hansson@arm.com        # normally determined by name of $BUILD_DIR, but can be
6919477Sandreas.hansson@arm.com        # overriden by 'default=' arg on command line.
6929477Sandreas.hansson@arm.com        default_opts_file = joinpath('build_opts',
6939477Sandreas.hansson@arm.com                                     ARGUMENTS.get('default', build_dir))
6949477Sandreas.hansson@arm.com        if os.path.isfile(default_opts_file):
6959477Sandreas.hansson@arm.com            sticky_opts.files.append(default_opts_file)
6969477Sandreas.hansson@arm.com            print "Options file %s not found,\n  using defaults in %s" \
6979477Sandreas.hansson@arm.com                  % (current_opts_file, default_opts_file)
6989477Sandreas.hansson@arm.com        else:
6999477Sandreas.hansson@arm.com            print "Error: cannot find options file %s or %s" \
7009477Sandreas.hansson@arm.com                  % (current_opts_file, default_opts_file)
7019477Sandreas.hansson@arm.com            Exit(1)
7029477Sandreas.hansson@arm.com
7039477Sandreas.hansson@arm.com    # Apply current option settings to env
7049477Sandreas.hansson@arm.com    sticky_opts.Update(env)
7059477Sandreas.hansson@arm.com    nonsticky_opts.Update(env)
7069477Sandreas.hansson@arm.com
7079477Sandreas.hansson@arm.com    help_text += "Sticky options for %s:\n" % build_dir \
7089477Sandreas.hansson@arm.com                 + sticky_opts.GenerateHelpText(env) \
7099477Sandreas.hansson@arm.com                 + "\nNon-sticky options for %s:\n" % build_dir \
7109477Sandreas.hansson@arm.com                 + nonsticky_opts.GenerateHelpText(env)
7119477Sandreas.hansson@arm.com
7129396Sandreas.hansson@arm.com    # Process option settings.
7133053Sstever@eecs.umich.edu
7146121Snate@binkert.org    if not have_fenv and env['USE_FENV']:
7153053Sstever@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
7163053Sstever@eecs.umich.edu              "forcing USE_FENV to False in", build_dir + "."
7173053Sstever@eecs.umich.edu        env['USE_FENV'] = False
7183053Sstever@eecs.umich.edu
7193053Sstever@eecs.umich.edu    if not env['USE_FENV']:
7209072Sandreas.hansson@arm.com        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
7213053Sstever@eecs.umich.edu        print "         FP results may deviate slightly from other platforms."
7224742Sstever@eecs.umich.edu
7234742Sstever@eecs.umich.edu    if env['EFENCE']:
7243053Sstever@eecs.umich.edu        env.Append(LIBS=['efence'])
7253053Sstever@eecs.umich.edu
7263053Sstever@eecs.umich.edu    if env['USE_MYSQL']:
7278960Ssteve.reinhardt@amd.com        if not have_mysql:
7286654Snate@binkert.org            print "Warning: MySQL not available; " \
7293053Sstever@eecs.umich.edu                  "forcing USE_MYSQL to False in", build_dir + "."
7303053Sstever@eecs.umich.edu            env['USE_MYSQL'] = False
7313053Sstever@eecs.umich.edu        else:
7323053Sstever@eecs.umich.edu            print "Compiling in", build_dir, "with MySQL support."
7339877Sandreas.hansson@arm.com            env.ParseConfig(mysql_config_libs)
7349877Sandreas.hansson@arm.com            env.ParseConfig(mysql_config_include)
7359877Sandreas.hansson@arm.com
7369877Sandreas.hansson@arm.com    # Save sticky option settings back to current options file
7379877Sandreas.hansson@arm.com    sticky_opts.Save(current_opts_file, env)
7389585Sandreas@sandberg.pp.se
7399877Sandreas.hansson@arm.com    # Do this after we save setting back, or else we'll tack on an
7409585Sandreas@sandberg.pp.se    # extra 'qdo' every time we run scons.
7419877Sandreas.hansson@arm.com    if env['BATCH']:
7429877Sandreas.hansson@arm.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
7439585Sandreas@sandberg.pp.se        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
7442667Sstever@eecs.umich.edu
7454554Sbinkertn@umich.edu    if env['USE_SSE2']:
7466121Snate@binkert.org        env.Append(CCFLAGS='-msse2')
7472667Sstever@eecs.umich.edu
7484554Sbinkertn@umich.edu    # The src/SConscript file sets up the build rules in 'env' according
7494554Sbinkertn@umich.edu    # to the configured options.  It returns a list of environments,
7504554Sbinkertn@umich.edu    # one for each variant build (debug, opt, etc.)
7516121Snate@binkert.org    envList = SConscript('src/SConscript', build_dir = build_path,
7524554Sbinkertn@umich.edu                         exports = 'env')
7534554Sbinkertn@umich.edu
7544554Sbinkertn@umich.edu    # Set up the regression tests for each build.
7554781Snate@binkert.org    for e in envList:
7564554Sbinkertn@umich.edu        SConscript('tests/SConscript',
7574554Sbinkertn@umich.edu                   build_dir = joinpath(build_path, 'tests', e.Label),
7582667Sstever@eecs.umich.edu                   exports = { 'env' : e }, duplicate = False)
7594554Sbinkertn@umich.edu
7604554Sbinkertn@umich.eduHelp(help_text)
7614554Sbinkertn@umich.edu
7624554Sbinkertn@umich.edu
7632667Sstever@eecs.umich.edu###################################################
7644554Sbinkertn@umich.edu#
7652667Sstever@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
7664554Sbinkertn@umich.edu# build environments to build the requested targets.
7676121Snate@binkert.org#
7682667Sstever@eecs.umich.edu###################################################
7695522Snate@binkert.org
7705522Snate@binkert.org