SConstruct revision 6654
1955SN/A# -*- mode:python -*-
2955SN/A
35871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company
41762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
5955SN/A# All rights reserved.
6955SN/A#
7955SN/A# Redistribution and use in source and binary forms, with or without
8955SN/A# modification, are permitted provided that the following conditions are
9955SN/A# met: redistributions of source code must retain the above copyright
10955SN/A# notice, this list of conditions and the following disclaimer;
11955SN/A# redistributions in binary form must reproduce the above copyright
12955SN/A# notice, this list of conditions and the following disclaimer in the
13955SN/A# documentation and/or other materials provided with the distribution;
14955SN/A# neither the name of the copyright holders nor the names of its
15955SN/A# contributors may be used to endorse or promote products derived from
16955SN/A# this software without specific prior written permission.
17955SN/A#
18955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
292665Ssaidi@eecs.umich.edu#
302665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
315863Snate@binkert.org#          Nathan Binkert
32955SN/A
33955SN/A###################################################
34955SN/A#
35955SN/A# SCons top-level build description (SConstruct) file.
36955SN/A#
372632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default
382632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
392632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
402632Sstever@eecs.umich.edu# the optimized full-system version).
41955SN/A#
422632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a
432632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
442761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
452632Sstever@eecs.umich.edu# built for the same host system.
462632Sstever@eecs.umich.edu#
472632Sstever@eecs.umich.edu# Examples:
482761Sstever@eecs.umich.edu#
492761Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
502761Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
512632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
522632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
532761Sstever@eecs.umich.edu#
542761Sstever@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
552761Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
562761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
572761Sstever@eecs.umich.edu#   file.
582632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
592632Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
602632Sstever@eecs.umich.edu#
612632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
622632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
632632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
642632Sstever@eecs.umich.edu# options as well.
65955SN/A#
66955SN/A###################################################
67955SN/A
685863Snate@binkert.org# Check for recent-enough Python and SCons versions.
695863Snate@binkert.orgtry:
705863Snate@binkert.org    # Really old versions of scons only take two options for the
715863Snate@binkert.org    # function, so check once without the revision and once with the
725863Snate@binkert.org    # revision, the first instance will fail for stuff other than
735863Snate@binkert.org    # 0.98, and the second will fail for 0.98.0
745863Snate@binkert.org    EnsureSConsVersion(0, 98)
755863Snate@binkert.org    EnsureSConsVersion(0, 98, 1)
765863Snate@binkert.orgexcept SystemExit, e:
775863Snate@binkert.org    print """
785863Snate@binkert.orgFor more details, see:
795863Snate@binkert.org    http://m5sim.org/wiki/index.php/Compiling_M5
805863Snate@binkert.org"""
815863Snate@binkert.org    raise
825863Snate@binkert.org
835863Snate@binkert.org# We ensure the python version early because we have stuff that
845863Snate@binkert.org# requires python 2.4
855863Snate@binkert.orgtry:
865863Snate@binkert.org    EnsurePythonVersion(2, 4)
875863Snate@binkert.orgexcept SystemExit, e:
885863Snate@binkert.org    print """
895863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by
905863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default
915863Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter
925863Snate@binkert.orgon the scons script.
935863Snate@binkert.org
945863Snate@binkert.orgFor more details, see:
955863Snate@binkert.org    http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation
965863Snate@binkert.org"""
975863Snate@binkert.org    raise
985863Snate@binkert.org
996654Snate@binkert.org# Global Python includes
100955SN/Aimport os
1015396Ssaidi@eecs.umich.eduimport re
1025863Snate@binkert.orgimport subprocess
1035863Snate@binkert.orgimport sys
1044202Sbinkertn@umich.edu
1055863Snate@binkert.orgfrom os import mkdir, environ
1065863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath
1075863Snate@binkert.orgfrom os.path import exists,  isdir, isfile
1085863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath
109955SN/A
1106654Snate@binkert.org# SCons includes
1115273Sstever@gmail.comimport SCons
1125871Snate@binkert.orgimport SCons.Node
1135273Sstever@gmail.com
1146655Snate@binkert.org# M5 includes
1156655Snate@binkert.orgsys.path[1:1] = [ Dir('src/python').srcnode().abspath ]
1166655Snate@binkert.org
1176655Snate@binkert.orgfrom m5.util import compareVersions, readCommand
1186655Snate@binkert.org
1196655Snate@binkert.org########################################################################
1205871Snate@binkert.org#
1216654Snate@binkert.org# Set up the main build environment.
1225396Ssaidi@eecs.umich.edu#
1235871Snate@binkert.org########################################################################
1245871Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
1256121Snate@binkert.org                 'RANLIB' ])
1265871Snate@binkert.org
1275871Snate@binkert.orguse_env = {}
1286003Snate@binkert.orgfor key,val in os.environ.iteritems():
1296655Snate@binkert.org    if key in use_vars or key.startswith("M5"):
130955SN/A        use_env[key] = val
1315871Snate@binkert.org
1325871Snate@binkert.orgmain = Environment(ENV=use_env)
1335871Snate@binkert.orgmain.root = Dir(".")         # The current directory (where this file lives).
1345871Snate@binkert.orgmain.srcdir = Dir("src")     # The source directory
135955SN/A
1366121Snate@binkert.org########################################################################
1376121Snate@binkert.org#
1386121Snate@binkert.org# Mercurial Stuff.
1391533SN/A#
1406655Snate@binkert.org# If the M5 directory is a mercurial repository, we should do some
1416655Snate@binkert.org# extra things.
1426655Snate@binkert.org#
1436655Snate@binkert.org########################################################################
1445871Snate@binkert.org
1455871Snate@binkert.orghgdir = main.root.Dir(".hg")
1465863Snate@binkert.org
1475871Snate@binkert.orgmercurial_style_message = """
1485871Snate@binkert.orgYou're missing the M5 style hook.
1495871Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style.
1505871Snate@binkert.org
1515871Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc
1525863Snate@binkert.orgor your personal .hgrc
1536121Snate@binkert.org----------------
1545863Snate@binkert.org
1555871Snate@binkert.org[extensions]
1564678Snate@binkert.orgstyle = %s/util/style.py
1574678Snate@binkert.org
1584678Snate@binkert.org[hooks]
1594678Snate@binkert.orgpretxncommit.style = python:style.check_whitespace
1604678Snate@binkert.org""" % (main.root)
1614678Snate@binkert.org
1624678Snate@binkert.orgmercurial_bin_not_found = """
1634678Snate@binkert.orgMercurial binary cannot be found, unfortunately this means that we
1644678Snate@binkert.orgcannot easily determine the version of M5 that you are running and
1654678Snate@binkert.orgthis makes error messages more difficult to collect.  Please consider
1664678Snate@binkert.orginstalling mercurial if you choose to post an error message
1674678Snate@binkert.org"""
1686121Snate@binkert.org
1694678Snate@binkert.orgmercurial_lib_not_found = """
1705871Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook
1715871Snate@binkert.orgIf you are actually a M5 developer, please fix this and
1725871Snate@binkert.orgrun the style hook. It is important.
1735871Snate@binkert.org"""
1745871Snate@binkert.org
1755871Snate@binkert.orghg_info = "Unknown"
1765871Snate@binkert.orgif hgdir.exists():
1775871Snate@binkert.org    # 1) Grab repository revision if we know it.
1785871Snate@binkert.org    cmd = "hg id -n -i -t -b"
1795871Snate@binkert.org    try:
1805871Snate@binkert.org        hg_info = readCommand(cmd, cwd=main.root.abspath).strip()
1815871Snate@binkert.org    except OSError:
1825871Snate@binkert.org        print mercurial_bin_not_found
1835990Ssaidi@eecs.umich.edu
1845871Snate@binkert.org    # 2) Ensure that the style hook is in place.
1855871Snate@binkert.org    try:
1865871Snate@binkert.org        ui = None
1874678Snate@binkert.org        if ARGUMENTS.get('IGNORE_STYLE') != 'True':
1886654Snate@binkert.org            from mercurial import ui
1895871Snate@binkert.org            ui = ui.ui()
1905871Snate@binkert.org    except ImportError:
1915871Snate@binkert.org        print mercurial_lib_not_found
1925871Snate@binkert.org
1935871Snate@binkert.org    if ui is not None:
1945871Snate@binkert.org        ui.readconfig(hgdir.File('hgrc').abspath)
1955871Snate@binkert.org        style_hook = ui.config('hooks', 'pretxncommit.style', None)
1965871Snate@binkert.org
1975871Snate@binkert.org        if not style_hook:
1984678Snate@binkert.org            print mercurial_style_message
1995871Snate@binkert.org            sys.exit(1)
2004678Snate@binkert.orgelse:
2015871Snate@binkert.org    print ".hg directory not found"
2025871Snate@binkert.org
2035871Snate@binkert.orgmain['HG_INFO'] = hg_info
2045871Snate@binkert.org
2055871Snate@binkert.org###################################################
2065871Snate@binkert.org#
2075871Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
2085871Snate@binkert.org# the target(s).
2095871Snate@binkert.org#
2106121Snate@binkert.org###################################################
2116121Snate@binkert.org
2125863Snate@binkert.org# Find default configuration & binary.
213955SN/ADefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
214955SN/A
2152632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
2162632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
217955SN/A    for i in range(len(l)+offs, 0, -1):
218955SN/A        if l[i] == elt:
219955SN/A            return i
220955SN/A    raise ValueError, "element not found"
2215863Snate@binkert.org
222955SN/A# Each target must have 'build' in the interior of the path; the
2232632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
2242632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
2252632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
2262632Sstever@eecs.umich.edu# follow 'build' in the bulid path.
2272632Sstever@eecs.umich.edu
2282632Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is
2292632Sstever@eecs.umich.eduif COMMAND_LINE_TARGETS:
2302632Sstever@eecs.umich.edu    # Ask SCons which directory it was invoked from
2312632Sstever@eecs.umich.edu    launch_dir = GetLaunchDir()
2322632Sstever@eecs.umich.edu    # Make targets relative to invocation directory
2332632Sstever@eecs.umich.edu    abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \
2342632Sstever@eecs.umich.edu                    COMMAND_LINE_TARGETS]
2352632Sstever@eecs.umich.eduelse:
2363718Sstever@eecs.umich.edu    # Default targets are relative to root of tree
2373718Sstever@eecs.umich.edu    abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \
2383718Sstever@eecs.umich.edu                    DEFAULT_TARGETS]
2393718Sstever@eecs.umich.edu
2403718Sstever@eecs.umich.edu
2415863Snate@binkert.org# Generate a list of the unique build roots and configs that the
2425863Snate@binkert.org# collected targets reference.
2433718Sstever@eecs.umich.eduvariant_paths = []
2443718Sstever@eecs.umich.edubuild_root = None
2456121Snate@binkert.orgfor t in abs_targets:
2465863Snate@binkert.org    path_dirs = t.split('/')
2473718Sstever@eecs.umich.edu    try:
2483718Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
2492634Sstever@eecs.umich.edu    except:
2502634Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
2515863Snate@binkert.org        Exit(1)
2522638Sstever@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
2532632Sstever@eecs.umich.edu    if not build_root:
2542632Sstever@eecs.umich.edu        build_root = this_build_root
2552632Sstever@eecs.umich.edu    else:
2562632Sstever@eecs.umich.edu        if this_build_root != build_root:
2572632Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
2582632Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
2591858SN/A            Exit(1)
2603716Sstever@eecs.umich.edu    variant_path = joinpath('/',*path_dirs[:build_top+2])
2612638Sstever@eecs.umich.edu    if variant_path not in variant_paths:
2622638Sstever@eecs.umich.edu        variant_paths.append(variant_path)
2632638Sstever@eecs.umich.edu
2642638Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there)
2652638Sstever@eecs.umich.eduif not isdir(build_root):
2662638Sstever@eecs.umich.edu    mkdir(build_root)
2672638Sstever@eecs.umich.edu
2685863Snate@binkert.orgExport('main')
2695863Snate@binkert.org
2705863Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign"))
271955SN/A
2725341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up
2735341Sstever@gmail.com# when you use emacs to edit a file in the target dir, as emacs moves
2745863Snate@binkert.org# file to file~ then copies to file, breaking the link.  Symbolic
2757756SAli.Saidi@ARM.com# (soft) links work better.
2765341Sstever@gmail.commain.SetOption('duplicate', 'soft-copy')
2776121Snate@binkert.org
2784494Ssaidi@eecs.umich.edu#
2796121Snate@binkert.org# Set up global sticky variables... these are common to an entire build
2801105SN/A# tree (not specific to a particular build like ALPHA_SE)
2812667Sstever@eecs.umich.edu#
2822667Sstever@eecs.umich.edu
2832667Sstever@eecs.umich.edu# Variable validators & converters for global sticky variables
2842667Sstever@eecs.umich.edudef PathListMakeAbsolute(val):
2856121Snate@binkert.org    if not val:
2862667Sstever@eecs.umich.edu        return val
2875341Sstever@gmail.com    f = lambda p: abspath(expanduser(p))
2885863Snate@binkert.org    return ':'.join(map(f, val.split(':')))
2895341Sstever@gmail.com
2905341Sstever@gmail.comdef PathListAllExist(key, val, env):
2915341Sstever@gmail.com    if not val:
2925863Snate@binkert.org        return
2935341Sstever@gmail.com    paths = val.split(':')
2945341Sstever@gmail.com    for path in paths:
2955341Sstever@gmail.com        if not isdir(path):
2965863Snate@binkert.org            raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
2975341Sstever@gmail.com
2985341Sstever@gmail.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global')
2995341Sstever@gmail.com
3005341Sstever@gmail.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS)
3015341Sstever@gmail.com
3025341Sstever@gmail.comglobal_sticky_vars.AddVariables(
3035341Sstever@gmail.com    ('CC', 'C compiler', environ.get('CC', main['CC'])),
3045341Sstever@gmail.com    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
3055341Sstever@gmail.com    ('BATCH', 'Use batch pool for build and tests', False),
3065341Sstever@gmail.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3075863Snate@binkert.org    ('EXTRAS', 'Add Extra directories to the compilation', '',
3085341Sstever@gmail.com     PathListAllExist, PathListMakeAbsolute),
3095863Snate@binkert.org    BoolVariable('RUBY', 'Build with Ruby', False),
3107756SAli.Saidi@ARM.com    )
3115341Sstever@gmail.com
3125863Snate@binkert.org# base help text
3136121Snate@binkert.orghelp_text = '''
3146121Snate@binkert.orgUsage: scons [scons options] [build options] [target(s)]
3155397Ssaidi@eecs.umich.edu
3165397Ssaidi@eecs.umich.eduGlobal sticky options:
3177727SAli.Saidi@ARM.com'''
3185341Sstever@gmail.com
3196168Snate@binkert.orghelp_text += global_sticky_vars.GenerateHelpText(main)
3206168Snate@binkert.org
3215341Sstever@gmail.com# Update main environment with values from ARGUMENTS & global_sticky_vars_file
3227756SAli.Saidi@ARM.comglobal_sticky_vars.Update(main)
3237756SAli.Saidi@ARM.com
3247756SAli.Saidi@ARM.com# Save sticky variable settings back to current variables file
3257756SAli.Saidi@ARM.comglobal_sticky_vars.Save(global_sticky_vars_file, main)
3267756SAli.Saidi@ARM.com
3277756SAli.Saidi@ARM.com# Parse EXTRAS variable to build list of all directories where we're
3285341Sstever@gmail.com# look for sources etc.  This list is exported as base_dir_list.
3295341Sstever@gmail.combase_dir = main.srcdir.abspath
3305341Sstever@gmail.comif main['EXTRAS']:
3315341Sstever@gmail.com    extras_dir_list = main['EXTRAS'].split(':')
3325863Snate@binkert.orgelse:
3335341Sstever@gmail.com    extras_dir_list = []
3345341Sstever@gmail.com
3356121Snate@binkert.orgExport('base_dir')
3366121Snate@binkert.orgExport('extras_dir_list')
3377756SAli.Saidi@ARM.com
3385341Sstever@gmail.com# the ext directory should be on the #includes path
3396814Sgblack@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')])
3407756SAli.Saidi@ARM.com
3416814Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
3425863Snate@binkert.orgmain.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath })
3436121Snate@binkert.org
3445341Sstever@gmail.comCXX_version = readCommand([main['CXX'],'--version'], exception=False)
3455863Snate@binkert.orgCXX_V = readCommand([main['CXX'],'-V'], exception=False)
3465341Sstever@gmail.com
3476121Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
3486121Snate@binkert.orgmain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
3496121Snate@binkert.orgmain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
3505742Snate@binkert.orgif main['GCC'] + main['SUNCC'] + main['ICC'] > 1:
3515742Snate@binkert.org    print 'Error: How can we have two at the same time?'
3525341Sstever@gmail.com    Exit(1)
3535742Snate@binkert.org
3545742Snate@binkert.org# Set up default C++ compiler flags
3555341Sstever@gmail.comif main['GCC']:
3566017Snate@binkert.org    main.Append(CCFLAGS='-pipe')
3576121Snate@binkert.org    main.Append(CCFLAGS='-fno-strict-aliasing')
3586017Snate@binkert.org    main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef'])
3597756SAli.Saidi@ARM.com    main.Append(CXXFLAGS='-Wno-deprecated')
3607756SAli.Saidi@ARM.comelif main['ICC']:
3617756SAli.Saidi@ARM.com    pass #Fix me... add warning flags once we clean up icc warnings
3627756SAli.Saidi@ARM.comelif main['SUNCC']:
3637756SAli.Saidi@ARM.com    main.Append(CCFLAGS='-Qoption ccfe')
3647756SAli.Saidi@ARM.com    main.Append(CCFLAGS='-features=gcc')
3657756SAli.Saidi@ARM.com    main.Append(CCFLAGS='-features=extensions')
3667756SAli.Saidi@ARM.com    main.Append(CCFLAGS='-library=stlport4')
3677756SAli.Saidi@ARM.com    main.Append(CCFLAGS='-xar')
3687756SAli.Saidi@ARM.com    #main.Append(CCFLAGS='-instances=semiexplicit')
3697756SAli.Saidi@ARM.comelse:
3707756SAli.Saidi@ARM.com    print 'Error: Don\'t know what compiler options to use for your compiler.'
3717756SAli.Saidi@ARM.com    print '       Please fix SConstruct and src/SConscript and try again.'
3727756SAli.Saidi@ARM.com    Exit(1)
3737756SAli.Saidi@ARM.com
3747756SAli.Saidi@ARM.com# Set up common yacc/bison flags (needed for Ruby)
3757756SAli.Saidi@ARM.commain['YACCFLAGS'] = '-d'
3767756SAli.Saidi@ARM.commain['YACCHXXFILESUFFIX'] = '.hh'
3777756SAli.Saidi@ARM.com
3787756SAli.Saidi@ARM.com# Do this after we save setting back, or else we'll tack on an
3797756SAli.Saidi@ARM.com# extra 'qdo' every time we run scons.
3807756SAli.Saidi@ARM.comif main['BATCH']:
3817756SAli.Saidi@ARM.com    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
3827756SAli.Saidi@ARM.com    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
3837756SAli.Saidi@ARM.com    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
3847756SAli.Saidi@ARM.com    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
3857756SAli.Saidi@ARM.com    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
3867756SAli.Saidi@ARM.com
3877756SAli.Saidi@ARM.comif sys.platform == 'cygwin':
3887756SAli.Saidi@ARM.com    # cygwin has some header file issues...
3897756SAli.Saidi@ARM.com    main.Append(CCFLAGS=Split("-Wno-uninitialized"))
3907756SAli.Saidi@ARM.com
3917756SAli.Saidi@ARM.com# Check for SWIG
3927756SAli.Saidi@ARM.comif not main.has_key('SWIG'):
3936654Snate@binkert.org    print 'Error: SWIG utility not found.'
3946654Snate@binkert.org    print '       Please install (see http://www.swig.org) and retry.'
3955871Snate@binkert.org    Exit(1)
3966121Snate@binkert.org
3976121Snate@binkert.org# Check for appropriate SWIG version
3986121Snate@binkert.orgswig_version = readCommand(('swig', '-version'), exception='').split()
3996121Snate@binkert.org# First 3 words should be "SWIG Version x.y.z"
4003940Ssaidi@eecs.umich.eduif len(swig_version) < 3 or \
4013918Ssaidi@eecs.umich.edu        swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
4023918Ssaidi@eecs.umich.edu    print 'Error determining SWIG version.'
4031858SN/A    Exit(1)
4046121Snate@binkert.org
4057739Sgblack@eecs.umich.edumin_swig_version = '1.3.28'
4067739Sgblack@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0:
4076143Snate@binkert.org    print 'Error: SWIG version', min_swig_version, 'or newer required.'
4087739Sgblack@eecs.umich.edu    print '       Installed version:', swig_version[2]
4097618SAli.Saidi@arm.com    Exit(1)
4107618SAli.Saidi@arm.com
4117618SAli.Saidi@arm.com# Set up SWIG flags & scanner
4127618SAli.Saidi@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
4137618SAli.Saidi@arm.commain.Append(SWIGFLAGS=swig_flags)
4147618SAli.Saidi@arm.com
4157618SAli.Saidi@arm.com# filter out all existing swig scanners, they mess up the dependency
4167739Sgblack@eecs.umich.edu# stuff for some reason
4176121Snate@binkert.orgscanners = []
4183940Ssaidi@eecs.umich.edufor scanner in main['SCANNERS']:
4196121Snate@binkert.org    skeys = scanner.skeys
4207739Sgblack@eecs.umich.edu    if skeys == '.i':
4217739Sgblack@eecs.umich.edu        continue
4227739Sgblack@eecs.umich.edu
4237739Sgblack@eecs.umich.edu    if isinstance(skeys, (list, tuple)) and '.i' in skeys:
4247739Sgblack@eecs.umich.edu        continue
4257739Sgblack@eecs.umich.edu
4263918Ssaidi@eecs.umich.edu    scanners.append(scanner)
4273918Ssaidi@eecs.umich.edu
4283940Ssaidi@eecs.umich.edu# add the new swig scanner that we like better
4293918Ssaidi@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner
4303918Ssaidi@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
4316157Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
4326157Snate@binkert.org
4336157Snate@binkert.org# replace the scanners list that has what we want
4346157Snate@binkert.orgmain['SCANNERS'] = scanners
4355397Ssaidi@eecs.umich.edu
4365397Ssaidi@eecs.umich.edu# Add a custom Check function to the Configure context so that we can
4376121Snate@binkert.org# figure out if the compiler adds leading underscores to global
4386121Snate@binkert.org# variables.  This is needed for the autogenerated asm files that we
4396121Snate@binkert.org# use for embedding the python code.
4406121Snate@binkert.orgdef CheckLeading(context):
4416121Snate@binkert.org    context.Message("Checking for leading underscore in global variables...")
4426121Snate@binkert.org    # 1) Define a global variable called x from asm so the C compiler
4435397Ssaidi@eecs.umich.edu    #    won't change the symbol at all.
4441851SN/A    # 2) Declare that variable.
4451851SN/A    # 3) Use the variable
4467739Sgblack@eecs.umich.edu    #
447955SN/A    # If the compiler prepends an underscore, this will successfully
4483053Sstever@eecs.umich.edu    # link because the external symbol 'x' will be called '_x' which
4496121Snate@binkert.org    # was defined by the asm statement.  If the compiler does not
4503053Sstever@eecs.umich.edu    # prepend an underscore, this will not successfully link because
4513053Sstever@eecs.umich.edu    # '_x' will have been defined by assembly, while the C portion of
4523053Sstever@eecs.umich.edu    # the code will be trying to use 'x'
4533053Sstever@eecs.umich.edu    ret = context.TryLink('''
4543053Sstever@eecs.umich.edu        asm(".globl _x; _x: .byte 0");
4556654Snate@binkert.org        extern int x;
4563053Sstever@eecs.umich.edu        int main() { return x; }
4574742Sstever@eecs.umich.edu        ''', extension=".c")
4584742Sstever@eecs.umich.edu    context.env.Append(LEADING_UNDERSCORE=ret)
4593053Sstever@eecs.umich.edu    context.Result(ret)
4603053Sstever@eecs.umich.edu    return ret
4613053Sstever@eecs.umich.edu
4623053Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
4636654Snate@binkert.org# builds under a given build root run on the same host platform.
4643053Sstever@eecs.umich.educonf = Configure(main,
4653053Sstever@eecs.umich.edu                 conf_dir = joinpath(build_root, '.scons_config'),
4663053Sstever@eecs.umich.edu                 log_file = joinpath(build_root, 'scons_config.log'),
4673053Sstever@eecs.umich.edu                 custom_tests = { 'CheckLeading' : CheckLeading })
4682667Sstever@eecs.umich.edu
4694554Sbinkertn@umich.edu# Check for leading underscores.  Don't really need to worry either
4706121Snate@binkert.org# way so don't need to check the return code.
4712667Sstever@eecs.umich.educonf.CheckLeading()
4724554Sbinkertn@umich.edu
4734554Sbinkertn@umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
4744554Sbinkertn@umich.edutry:
4756121Snate@binkert.org    import platform
4764554Sbinkertn@umich.edu    uname = platform.uname()
4774554Sbinkertn@umich.edu    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
4784554Sbinkertn@umich.edu        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
4794781Snate@binkert.org            main.Append(CCFLAGS='-arch x86_64')
4804554Sbinkertn@umich.edu            main.Append(CFLAGS='-arch x86_64')
4814554Sbinkertn@umich.edu            main.Append(LINKFLAGS='-arch x86_64')
4822667Sstever@eecs.umich.edu            main.Append(ASFLAGS='-arch x86_64')
4834554Sbinkertn@umich.eduexcept:
4844554Sbinkertn@umich.edu    pass
4854554Sbinkertn@umich.edu
4864554Sbinkertn@umich.edu# Recent versions of scons substitute a "Null" object for Configure()
4872667Sstever@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is
4884554Sbinkertn@umich.edu# present.  Unfortuantely this Null object always returns false,
4892667Sstever@eecs.umich.edu# breaking all our configuration checks.  We replace it with our own
4904554Sbinkertn@umich.edu# more optimistic null object that returns True instead.
4916121Snate@binkert.orgif not conf:
4922667Sstever@eecs.umich.edu    def NullCheck(*args, **kwargs):
4935522Snate@binkert.org        return True
4945522Snate@binkert.org
4955522Snate@binkert.org    class NullConf:
4965522Snate@binkert.org        def __init__(self, env):
4975522Snate@binkert.org            self.env = env
4985522Snate@binkert.org        def Finish(self):
4995522Snate@binkert.org            return self.env
5005522Snate@binkert.org        def __getattr__(self, mname):
5015522Snate@binkert.org            return NullCheck
5025522Snate@binkert.org
5035522Snate@binkert.org    conf = NullConf(main)
5045522Snate@binkert.org
5055522Snate@binkert.org# Find Python include and library directories for embedding the
5065522Snate@binkert.org# interpreter.  For consistency, we will use the same Python
5075522Snate@binkert.org# installation used to run scons (and thus this script).  If you want
5085522Snate@binkert.org# to link in an alternate version, see above for instructions on how
5095522Snate@binkert.org# to invoke scons with a different copy of the Python interpreter.
5105522Snate@binkert.orgfrom distutils import sysconfig
5115522Snate@binkert.org
5125522Snate@binkert.orgpy_getvar = sysconfig.get_config_var
5135522Snate@binkert.org
5145522Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION')
5155522Snate@binkert.org
5165522Snate@binkert.orgpy_general_include = sysconfig.get_python_inc()
5175522Snate@binkert.orgpy_platform_include = sysconfig.get_python_inc(plat_specific=True)
5185522Snate@binkert.orgpy_includes = [ py_general_include ]
5192638Sstever@eecs.umich.eduif py_platform_include != py_general_include:
5202638Sstever@eecs.umich.edu    py_includes.append(py_platform_include)
5216121Snate@binkert.org
5223716Sstever@eecs.umich.edupy_lib_path = [ py_getvar('LIBDIR') ]
5235522Snate@binkert.org# add the prefix/lib/pythonX.Y/config dir, but only if there is no
5245522Snate@binkert.org# shared library in prefix/lib/.
5255522Snate@binkert.orgif not py_getvar('Py_ENABLE_SHARED'):
5265522Snate@binkert.org    py_lib_path.append(py_getvar('LIBPL'))
5275522Snate@binkert.org
5285522Snate@binkert.orgpy_libs = []
5291858SN/Afor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
5305227Ssaidi@eecs.umich.edu    assert lib.startswith('-l')
5315227Ssaidi@eecs.umich.edu    lib = lib[2:]   
5325227Ssaidi@eecs.umich.edu    if lib not in py_libs:
5335227Ssaidi@eecs.umich.edu        py_libs.append(lib)
5346654Snate@binkert.orgpy_libs.append(py_version)
5356654Snate@binkert.org
5367739Sgblack@eecs.umich.edumain.Append(CPPPATH=py_includes)
5377739Sgblack@eecs.umich.edumain.Append(LIBPATH=py_lib_path)
5387739Sgblack@eecs.umich.edu
5397739Sgblack@eecs.umich.edu# verify that this stuff works
5405227Ssaidi@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'):
5415227Ssaidi@eecs.umich.edu    print "Error: can't find Python.h header in", py_includes
5425227Ssaidi@eecs.umich.edu    Exit(1)
5435204Sstever@gmail.com
5445204Sstever@gmail.comfor lib in py_libs:
5455204Sstever@gmail.com    if not conf.CheckLib(lib):
5465204Sstever@gmail.com        print "Error: can't find library %s required by python" % lib
5475204Sstever@gmail.com        Exit(1)
5485204Sstever@gmail.com
5495204Sstever@gmail.com# On Solaris you need to use libsocket for socket ops
5505204Sstever@gmail.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
5515204Sstever@gmail.com   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
5525204Sstever@gmail.com       print "Can't find library with socket calls (e.g. accept())"
5535204Sstever@gmail.com       Exit(1)
5545204Sstever@gmail.com
5555204Sstever@gmail.com# Check for zlib.  If the check passes, libz will be automatically
5565204Sstever@gmail.com# added to the LIBS environment variable.
5575204Sstever@gmail.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
5585204Sstever@gmail.com    print 'Error: did not find needed zlib compression library '\
5595204Sstever@gmail.com          'and/or zlib.h header file.'
5606121Snate@binkert.org    print '       Please install zlib and try again.'
5615204Sstever@gmail.com    Exit(1)
5623118Sstever@eecs.umich.edu
5633118Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
5643118Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
5653118Sstever@eecs.umich.eduif not have_fenv:
5663118Sstever@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
5675863Snate@binkert.org    print "         This host has no IEEE FP rounding mode control."
5683118Sstever@eecs.umich.edu
5695863Snate@binkert.org######################################################################
5703118Sstever@eecs.umich.edu#
5717457Snate@binkert.org# Check for mysql.
5727457Snate@binkert.org#
5735863Snate@binkert.orgmysql_config = WhereIs('mysql_config')
5745863Snate@binkert.orghave_mysql = bool(mysql_config)
5755863Snate@binkert.org
5765863Snate@binkert.org# Check MySQL version.
5775863Snate@binkert.orgif have_mysql:
5785863Snate@binkert.org    mysql_version = readCommand(mysql_config + ' --version')
5795863Snate@binkert.org    min_mysql_version = '4.1'
5806003Snate@binkert.org    if compareVersions(mysql_version, min_mysql_version) < 0:
5815863Snate@binkert.org        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
5825863Snate@binkert.org        print '         Version', mysql_version, 'detected.'
5835863Snate@binkert.org        have_mysql = False
5846120Snate@binkert.org
5855863Snate@binkert.org# Set up mysql_config commands.
5865863Snate@binkert.orgif have_mysql:
5875863Snate@binkert.org    mysql_config_include = mysql_config + ' --include'
5886120Snate@binkert.org    if os.system(mysql_config_include + ' > /dev/null') != 0:
5896120Snate@binkert.org        # older mysql_config versions don't support --include, use
5905863Snate@binkert.org        # --cflags instead
5915863Snate@binkert.org        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
5926120Snate@binkert.org    # This seems to work in all versions
5935863Snate@binkert.org    mysql_config_libs = mysql_config + ' --libs'
5946121Snate@binkert.org
5956121Snate@binkert.org######################################################################
5965863Snate@binkert.org#
5977727SAli.Saidi@ARM.com# Finish the configuration
5987727SAli.Saidi@ARM.com#
5997727SAli.Saidi@ARM.commain = conf.Finish()
6007727SAli.Saidi@ARM.com
6017727SAli.Saidi@ARM.com######################################################################
6027727SAli.Saidi@ARM.com#
6035863Snate@binkert.org# Collect all non-global variables
6043118Sstever@eecs.umich.edu#
6055863Snate@binkert.org
6063118Sstever@eecs.umich.edu# Define the universe of supported ISAs
6073118Sstever@eecs.umich.eduall_isa_list = [ ]
6085863Snate@binkert.orgExport('all_isa_list')
6095863Snate@binkert.org
6105863Snate@binkert.org# Define the universe of supported CPU models
6115863Snate@binkert.orgall_cpu_list = [ ]
6123118Sstever@eecs.umich.edudefault_cpus = [ ]
6133483Ssaidi@eecs.umich.eduExport('all_cpu_list', 'default_cpus')
6143494Ssaidi@eecs.umich.edu
6153494Ssaidi@eecs.umich.edu# Sticky variables get saved in the variables file so they persist from
6163483Ssaidi@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
6173483Ssaidi@eecs.umich.edu# value becomes sticky).
6183483Ssaidi@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS)
6193053Sstever@eecs.umich.eduExport('sticky_vars')
6203053Sstever@eecs.umich.edu
6213918Ssaidi@eecs.umich.edu# Sticky variables that should be exported
6223053Sstever@eecs.umich.eduexport_vars = []
6233053Sstever@eecs.umich.eduExport('export_vars')
6243053Sstever@eecs.umich.edu
6253053Sstever@eecs.umich.edu# Non-sticky variables only apply to the current build.
6263053Sstever@eecs.umich.edunonsticky_vars = Variables(args=ARGUMENTS)
6271858SN/AExport('nonsticky_vars')
6281858SN/A
6291858SN/A# Walk the tree and execute all SConsopts scripts that wil add to the
6301858SN/A# above variables
6311858SN/Afor bdir in [ base_dir ] + extras_dir_list:
6321858SN/A    for root, dirs, files in os.walk(bdir):
6335863Snate@binkert.org        if 'SConsopts' in files:
6345863Snate@binkert.org            print "Reading", joinpath(root, 'SConsopts')
6351859SN/A            SConscript(joinpath(root, 'SConsopts'))
6365863Snate@binkert.org
6371858SN/Aall_isa_list.sort()
6385863Snate@binkert.orgall_cpu_list.sort()
6391858SN/Adefault_cpus.sort()
6401859SN/A
6411859SN/Asticky_vars.AddVariables(
6426654Snate@binkert.org    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
6433053Sstever@eecs.umich.edu    BoolVariable('FULL_SYSTEM', 'Full-system support', False),
6446654Snate@binkert.org    ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
6453053Sstever@eecs.umich.edu    BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
6463053Sstever@eecs.umich.edu    BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
6471859SN/A                 False),
6481859SN/A    BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
6491859SN/A                 False),
6501859SN/A    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
6511859SN/A                 False),
6521859SN/A    BoolVariable('SS_COMPATIBLE_FP',
6531859SN/A                 'Make floating-point results compatible with SimpleScalar',
6541859SN/A                 False),
6551862SN/A    BoolVariable('USE_SSE2',
6561859SN/A                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
6571859SN/A                 False),
6581859SN/A    BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
6595863Snate@binkert.org    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
6605863Snate@binkert.org    BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
6615863Snate@binkert.org    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
6625863Snate@binkert.org    )
6636121Snate@binkert.org
6641858SN/Anonsticky_vars.AddVariables(
6655863Snate@binkert.org    BoolVariable('update_ref', 'Update test reference outputs', False)
6665863Snate@binkert.org    )
6675863Snate@binkert.org
6685863Snate@binkert.org# These variables get exported to #defines in config/*.hh (see src/SConscript).
6695863Snate@binkert.orgexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL',
6702139SN/A                'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS',
6714202Sbinkertn@umich.edu                'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE']
6724202Sbinkertn@umich.edu
6732139SN/A###################################################
6746994Snate@binkert.org#
6756994Snate@binkert.org# Define a SCons builder for configuration flag headers.
6766994Snate@binkert.org#
6776994Snate@binkert.org###################################################
6786994Snate@binkert.org
6796994Snate@binkert.org# This function generates a config header file that #defines the
6806994Snate@binkert.org# variable symbol to the current variable setting (0 or 1).  The source
6816994Snate@binkert.org# operands are the name of the variable and a Value node containing the
6826994Snate@binkert.org# value of the variable.
6836994Snate@binkert.orgdef build_config_file(target, source, env):
6846994Snate@binkert.org    (variable, value) = [s.get_contents() for s in source]
6856994Snate@binkert.org    f = file(str(target[0]), 'w')
6866994Snate@binkert.org    print >> f, '#define', variable, value
6876994Snate@binkert.org    f.close()
6886994Snate@binkert.org    return None
6896994Snate@binkert.org
6906994Snate@binkert.org# Generate the message to be printed when building the config file.
6916994Snate@binkert.orgdef build_config_file_string(target, source, env):
6926994Snate@binkert.org    (variable, value) = [s.get_contents() for s in source]
6936994Snate@binkert.org    return "Defining %s as %s in %s." % (variable, value, target[0])
6946994Snate@binkert.org
6956994Snate@binkert.org# Combine the two functions into a scons Action object.
6966994Snate@binkert.orgconfig_action = Action(build_config_file, build_config_file_string)
6976994Snate@binkert.org
6986994Snate@binkert.org# The emitter munges the source & target node lists to reflect what
6996994Snate@binkert.org# we're really doing.
7006994Snate@binkert.orgdef config_emitter(target, source, env):
7016994Snate@binkert.org    # extract variable name from Builder arg
7022155SN/A    variable = str(target[0])
7035863Snate@binkert.org    # True target is config header file
7041869SN/A    target = joinpath('config', variable.lower() + '.hh')
7051869SN/A    val = env[variable]
7065863Snate@binkert.org    if isinstance(val, bool):
7075863Snate@binkert.org        # Force value to 0/1
7084202Sbinkertn@umich.edu        val = int(val)
7096108Snate@binkert.org    elif isinstance(val, str):
7106108Snate@binkert.org        val = '"' + val + '"'
7116108Snate@binkert.org
7126108Snate@binkert.org    # Sources are variable name & value (packaged in SCons Value nodes)
7134202Sbinkertn@umich.edu    return ([target], [Value(variable), Value(val)])
7145863Snate@binkert.org
7155742Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action)
7165742Snate@binkert.org
7175341Sstever@gmail.commain.Append(BUILDERS = { 'ConfigFile' : config_builder })
7185342Sstever@gmail.com
7195342Sstever@gmail.com# libelf build is shared across all configs in the build root.
7204202Sbinkertn@umich.edumain.SConscript('ext/libelf/SConscript',
7214202Sbinkertn@umich.edu                variant_dir = joinpath(build_root, 'libelf'))
7224202Sbinkertn@umich.edu
7235863Snate@binkert.org# gzstream build is shared across all configs in the build root.
7245863Snate@binkert.orgmain.SConscript('ext/gzstream/SConscript',
7255863Snate@binkert.org                variant_dir = joinpath(build_root, 'gzstream'))
7266994Snate@binkert.org
7276994Snate@binkert.org###################################################
7286994Snate@binkert.org#
7295863Snate@binkert.org# This function is used to set up a directory with switching headers
7305863Snate@binkert.org#
7315863Snate@binkert.org###################################################
7325863Snate@binkert.org
7335863Snate@binkert.orgmain['ALL_ISA_LIST'] = all_isa_list
7345863Snate@binkert.orgdef make_switching_dir(dname, switch_headers, env):
7355863Snate@binkert.org    # Generate the header.  target[0] is the full path of the output
7365863Snate@binkert.org    # header to generate.  'source' is a dummy variable, since we get the
7375863Snate@binkert.org    # list of ISAs from env['ALL_ISA_LIST'].
7385863Snate@binkert.org    def gen_switch_hdr(target, source, env):
7395863Snate@binkert.org        fname = str(target[0])
7405863Snate@binkert.org        bname = basename(fname)
7415863Snate@binkert.org        f = open(fname, 'w')
7425863Snate@binkert.org        f.write('#include "arch/isa_specific.hh"\n')
7435863Snate@binkert.org        cond = '#if'
7445863Snate@binkert.org        for isa in all_isa_list:
7455952Ssaidi@eecs.umich.edu            f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
7467450Sstever@gmail.com                    % (cond, isa.upper(), dname, isa, bname))
7471869SN/A            cond = '#elif'
7481858SN/A        f.write('#else\n#error "THE_ISA not set"\n#endif\n')
7495863Snate@binkert.org        f.close()
7506108Snate@binkert.org        return 0
7516108Snate@binkert.org
7526108Snate@binkert.org    # String to print when generating header
7531858SN/A    def gen_switch_hdr_string(target, source, env):
754955SN/A        return "Generating switch header " + str(target[0])
755955SN/A
7561869SN/A    # Build SCons Action object. 'varlist' specifies env vars that this
7571869SN/A    # action depends on; when env['ALL_ISA_LIST'] changes these actions
7581869SN/A    # should get re-executed.
7591869SN/A    switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
7601869SN/A                               varlist=['ALL_ISA_LIST'])
7615863Snate@binkert.org
7625863Snate@binkert.org    # Instantiate actions for each header
7635863Snate@binkert.org    for hdr in switch_headers:
7641869SN/A        env.Command(hdr, [], switch_hdr_action)
7655863Snate@binkert.orgExport('make_switching_dir')
7661869SN/A
7675863Snate@binkert.org###################################################
7681869SN/A#
7691869SN/A# Define build environments for selected configurations.
7701869SN/A#
7711869SN/A###################################################
7721869SN/A
7735863Snate@binkert.orgfor variant_path in variant_paths:
7745863Snate@binkert.org    print "Building in", variant_path
7751869SN/A
7761869SN/A    # Make a copy of the build-root environment to use for this config.
7771869SN/A    env = main.Clone()
7781869SN/A    env['BUILDDIR'] = variant_path
7791869SN/A
7801869SN/A    # variant_dir is the tail component of build path, and is used to
7811869SN/A    # determine the build parameters (e.g., 'ALPHA_SE')
7825863Snate@binkert.org    (build_root, variant_dir) = splitpath(variant_path)
7835863Snate@binkert.org
7841869SN/A    # Set env variables according to the build directory config.
7855863Snate@binkert.org    sticky_vars.files = []
7865863Snate@binkert.org    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
7873356Sbinkertn@umich.edu    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
7883356Sbinkertn@umich.edu    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
7893356Sbinkertn@umich.edu    current_vars_file = joinpath(build_root, 'variables', variant_dir)
7903356Sbinkertn@umich.edu    if isfile(current_vars_file):
7913356Sbinkertn@umich.edu        sticky_vars.files.append(current_vars_file)
7924781Snate@binkert.org        print "Using saved variables file %s" % current_vars_file
7935863Snate@binkert.org    else:
7945863Snate@binkert.org        # Build dir-specific variables file doesn't exist.
7951869SN/A
7961869SN/A        # Make sure the directory is there so we can create it later
7971869SN/A        opt_dir = dirname(current_vars_file)
7986121Snate@binkert.org        if not isdir(opt_dir):
7991869SN/A            mkdir(opt_dir)
8002638Sstever@eecs.umich.edu
8016121Snate@binkert.org        # Get default build variables from source tree.  Variables are
8026121Snate@binkert.org        # normally determined by name of $VARIANT_DIR, but can be
8032638Sstever@eecs.umich.edu        # overriden by 'default=' arg on command line.
8045749Scws3k@cs.virginia.edu        default_vars_file = joinpath('build_opts',
8056121Snate@binkert.org                                     ARGUMENTS.get('default', variant_dir))
8066121Snate@binkert.org        if isfile(default_vars_file):
8075749Scws3k@cs.virginia.edu            sticky_vars.files.append(default_vars_file)
8081869SN/A            print "Variables file %s not found,\n  using defaults in %s" \
8091869SN/A                  % (current_vars_file, default_vars_file)
8103546Sgblack@eecs.umich.edu        else:
8113546Sgblack@eecs.umich.edu            print "Error: cannot find variables file %s or %s" \
8123546Sgblack@eecs.umich.edu                  % (current_vars_file, default_vars_file)
8133546Sgblack@eecs.umich.edu            Exit(1)
8146121Snate@binkert.org
8155863Snate@binkert.org    # Apply current variable settings to env
8163546Sgblack@eecs.umich.edu    sticky_vars.Update(env)
8173546Sgblack@eecs.umich.edu    nonsticky_vars.Update(env)
8183546Sgblack@eecs.umich.edu
8193546Sgblack@eecs.umich.edu    help_text += "\nSticky variables for %s:\n" % variant_dir \
8204781Snate@binkert.org                 + sticky_vars.GenerateHelpText(env) \
8214781Snate@binkert.org                 + "\nNon-sticky variables for %s:\n" % variant_dir \
8226658Snate@binkert.org                 + nonsticky_vars.GenerateHelpText(env)
8236658Snate@binkert.org
8244781Snate@binkert.org    # Process variable settings.
8253546Sgblack@eecs.umich.edu
8263546Sgblack@eecs.umich.edu    if not have_fenv and env['USE_FENV']:
8273546Sgblack@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
8283546Sgblack@eecs.umich.edu              "forcing USE_FENV to False in", variant_dir + "."
8297756SAli.Saidi@ARM.com        env['USE_FENV'] = False
8307756SAli.Saidi@ARM.com
8313546Sgblack@eecs.umich.edu    if not env['USE_FENV']:
8323546Sgblack@eecs.umich.edu        print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
8333546Sgblack@eecs.umich.edu        print "         FP results may deviate slightly from other platforms."
8343546Sgblack@eecs.umich.edu
8354202Sbinkertn@umich.edu    if env['EFENCE']:
8363546Sgblack@eecs.umich.edu        env.Append(LIBS=['efence'])
8373546Sgblack@eecs.umich.edu
8383546Sgblack@eecs.umich.edu    if env['USE_MYSQL']:
839955SN/A        if not have_mysql:
840955SN/A            print "Warning: MySQL not available; " \
841955SN/A                  "forcing USE_MYSQL to False in", variant_dir + "."
842955SN/A            env['USE_MYSQL'] = False
8435863Snate@binkert.org        else:
8445863Snate@binkert.org            print "Compiling in", variant_dir, "with MySQL support."
8455343Sstever@gmail.com            env.ParseConfig(mysql_config_libs)
8465343Sstever@gmail.com            env.ParseConfig(mysql_config_include)
8476121Snate@binkert.org
8485863Snate@binkert.org    # Save sticky variable settings back to current variables file
8494773Snate@binkert.org    sticky_vars.Save(current_vars_file, env)
8505863Snate@binkert.org
8512632Sstever@eecs.umich.edu    if env['USE_SSE2']:
8525863Snate@binkert.org        env.Append(CCFLAGS='-msse2')
8532023SN/A
8545863Snate@binkert.org    # The src/SConscript file sets up the build rules in 'env' according
8555863Snate@binkert.org    # to the configured variables.  It returns a list of environments,
8565863Snate@binkert.org    # one for each variant build (debug, opt, etc.)
8575863Snate@binkert.org    envList = SConscript('src/SConscript', variant_dir = variant_path,
8585863Snate@binkert.org                         exports = 'env')
8595863Snate@binkert.org
8605863Snate@binkert.org    # Set up the regression tests for each build.
8615863Snate@binkert.org    for e in envList:
8625863Snate@binkert.org        SConscript('tests/SConscript',
8632632Sstever@eecs.umich.edu                   variant_dir = joinpath(variant_path, 'tests', e.Label),
8645863Snate@binkert.org                   exports = { 'env' : e }, duplicate = False)
8652023SN/A
8662632Sstever@eecs.umich.eduHelp(help_text)
8675863Snate@binkert.org