SConstruct revision 7807
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 4955SN/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 282665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 292665Ssaidi@eecs.umich.edu# 30955SN/A# Authors: Steve Reinhardt 31955SN/A# Nathan Binkert 32955SN/A 33955SN/A################################################### 34955SN/A# 352632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 362632Sstever@eecs.umich.edu# 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>' 39955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 402632Sstever@eecs.umich.edu# the optimized full-system version). 412632Sstever@eecs.umich.edu# 422761Sstever@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 442632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 452632Sstever@eecs.umich.edu# built for the same host system. 462761Sstever@eecs.umich.edu# 472761Sstever@eecs.umich.edu# Examples: 482761Sstever@eecs.umich.edu# 492632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 502632Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 512761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 522761Sstever@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 562632Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 572632Sstever@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 63955SN/A# file), you can use 'scons -h' to print all the M5-specific build 64955SN/A# options as well. 65955SN/A# 66955SN/A################################################### 67955SN/A 684202Sbinkertn@umich.edu# Check for recent-enough Python and SCons versions. 694678Snate@binkert.orgtry: 70955SN/A # Really old versions of scons only take two options for the 715273Sstever@gmail.com # function, so check once without the revision and once with the 725273Sstever@gmail.com # revision, the first instance will fail for stuff other than 732656Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 742656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 752656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98, 1) 762656Sstever@eecs.umich.eduexcept SystemExit, e: 772656Sstever@eecs.umich.edu print """ 782656Sstever@eecs.umich.eduFor more details, see: 792656Sstever@eecs.umich.edu http://m5sim.org/wiki/index.php/Compiling_M5 802653Sstever@eecs.umich.edu""" 815227Ssaidi@eecs.umich.edu raise 825227Ssaidi@eecs.umich.edu 835227Ssaidi@eecs.umich.edu# We ensure the python version early because we have stuff that 845227Ssaidi@eecs.umich.edu# requires python 2.4 852653Sstever@eecs.umich.edutry: 862653Sstever@eecs.umich.edu EnsurePythonVersion(2, 4) 872653Sstever@eecs.umich.eduexcept SystemExit, e: 882653Sstever@eecs.umich.edu print """ 892653Sstever@eecs.umich.eduYou can use a non-default installation of the Python interpreter by 902653Sstever@eecs.umich.edueither (1) rearranging your PATH so that scons finds the non-default 912653Sstever@eecs.umich.edu'python' first or (2) explicitly invoking an alternative interpreter 922653Sstever@eecs.umich.eduon the scons script. 932653Sstever@eecs.umich.edu 944781Snate@binkert.orgFor more details, see: 951852SN/A http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 96955SN/A""" 97955SN/A raise 98955SN/A 993717Sstever@eecs.umich.edu# Global Python includes 1003716Sstever@eecs.umich.eduimport os 101955SN/Aimport re 1021533SN/Aimport subprocess 1033716Sstever@eecs.umich.eduimport sys 1041533SN/A 1054678Snate@binkert.orgfrom os import mkdir, environ 1064678Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1074678Snate@binkert.orgfrom os.path import exists, isdir, isfile 1084678Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1094678Snate@binkert.org 1104678Snate@binkert.org# SCons includes 1114678Snate@binkert.orgimport SCons 1124678Snate@binkert.orgimport SCons.Node 1134678Snate@binkert.org 1144678Snate@binkert.orgextra_python_paths = [ 1154678Snate@binkert.org Dir('src/python').srcnode().abspath, # M5 includes 1164678Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1174678Snate@binkert.org ] 1184678Snate@binkert.org 1194678Snate@binkert.orgsys.path[1:1] = extra_python_paths 1204678Snate@binkert.org 1214678Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1224678Snate@binkert.org 1234678Snate@binkert.org######################################################################## 1244678Snate@binkert.org# 1254678Snate@binkert.org# Set up the main build environment. 1264973Ssaidi@eecs.umich.edu# 1274678Snate@binkert.org######################################################################## 1284678Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1294678Snate@binkert.org 'PYTHONPATH', 'RANLIB' ]) 1304678Snate@binkert.org 1314678Snate@binkert.orguse_env = {} 1324678Snate@binkert.orgfor key,val in os.environ.iteritems(): 133955SN/A if key in use_vars or key.startswith("M5"): 134955SN/A use_env[key] = val 1352632Sstever@eecs.umich.edu 1362632Sstever@eecs.umich.edumain = Environment(ENV=use_env) 137955SN/Amain.root = Dir(".") # The current directory (where this file lives). 138955SN/Amain.srcdir = Dir("src") # The source directory 139955SN/A 140955SN/A# add useful python code PYTHONPATH so it can be used by subprocesses 1412632Sstever@eecs.umich.edu# as well 142955SN/Amain.AppendENVPath('PYTHONPATH', extra_python_paths) 1432632Sstever@eecs.umich.edu 1442632Sstever@eecs.umich.edu######################################################################## 1452632Sstever@eecs.umich.edu# 1462632Sstever@eecs.umich.edu# Mercurial Stuff. 1472632Sstever@eecs.umich.edu# 1482632Sstever@eecs.umich.edu# If the M5 directory is a mercurial repository, we should do some 1492632Sstever@eecs.umich.edu# extra things. 1503053Sstever@eecs.umich.edu# 1513053Sstever@eecs.umich.edu######################################################################## 1523053Sstever@eecs.umich.edu 1533053Sstever@eecs.umich.eduhgdir = main.root.Dir(".hg") 1543053Sstever@eecs.umich.edu 1553053Sstever@eecs.umich.edumercurial_style_message = """ 1563053Sstever@eecs.umich.eduYou're missing the M5 style hook. 1573053Sstever@eecs.umich.eduPlease install the hook so we can ensure that all code fits a common style. 1583053Sstever@eecs.umich.edu 1593053Sstever@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc 1603053Sstever@eecs.umich.eduor your personal .hgrc 1613053Sstever@eecs.umich.edu---------------- 1623053Sstever@eecs.umich.edu 1633053Sstever@eecs.umich.edu[extensions] 1643053Sstever@eecs.umich.edustyle = %s/util/style.py 1653053Sstever@eecs.umich.edu 1662632Sstever@eecs.umich.edu[hooks] 1672632Sstever@eecs.umich.edupretxncommit.style = python:style.check_whitespace 1682632Sstever@eecs.umich.edupre-qrefresh.style = python:style.check_whitespace 1692632Sstever@eecs.umich.edu""" % (main.root) 1702632Sstever@eecs.umich.edu 1712632Sstever@eecs.umich.edumercurial_bin_not_found = """ 1723718Sstever@eecs.umich.eduMercurial binary cannot be found, unfortunately this means that we 1733718Sstever@eecs.umich.educannot easily determine the version of M5 that you are running and 1743718Sstever@eecs.umich.eduthis makes error messages more difficult to collect. Please consider 1753718Sstever@eecs.umich.eduinstalling mercurial if you choose to post an error message 1763718Sstever@eecs.umich.edu""" 1773718Sstever@eecs.umich.edu 1783718Sstever@eecs.umich.edumercurial_lib_not_found = """ 1793718Sstever@eecs.umich.eduMercurial libraries cannot be found, ignoring style hook 1803718Sstever@eecs.umich.eduIf you are actually a M5 developer, please fix this and 1813718Sstever@eecs.umich.edurun the style hook. It is important. 1823718Sstever@eecs.umich.edu""" 1833718Sstever@eecs.umich.edu 1843718Sstever@eecs.umich.eduhg_info = "Unknown" 1852634Sstever@eecs.umich.eduif hgdir.exists(): 1862634Sstever@eecs.umich.edu # 1) Grab repository revision if we know it. 1872632Sstever@eecs.umich.edu cmd = "hg id -n -i -t -b" 1882638Sstever@eecs.umich.edu try: 1892632Sstever@eecs.umich.edu hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 1902632Sstever@eecs.umich.edu except OSError: 1912632Sstever@eecs.umich.edu print mercurial_bin_not_found 1922632Sstever@eecs.umich.edu 1932632Sstever@eecs.umich.edu # 2) Ensure that the style hook is in place. 1942632Sstever@eecs.umich.edu try: 1951858SN/A ui = None 1963716Sstever@eecs.umich.edu if ARGUMENTS.get('IGNORE_STYLE') != 'True': 1972638Sstever@eecs.umich.edu from mercurial import ui 1982638Sstever@eecs.umich.edu ui = ui.ui() 1992638Sstever@eecs.umich.edu except ImportError: 2002638Sstever@eecs.umich.edu print mercurial_lib_not_found 2012638Sstever@eecs.umich.edu 2022638Sstever@eecs.umich.edu if ui is not None: 2032638Sstever@eecs.umich.edu ui.readconfig(hgdir.File('hgrc').abspath) 2043716Sstever@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) 2052634Sstever@eecs.umich.edu 2062634Sstever@eecs.umich.edu if not style_hook: 207955SN/A print mercurial_style_message 208955SN/A sys.exit(1) 209955SN/Aelse: 210955SN/A print ".hg directory not found" 211955SN/A 212955SN/Amain['HG_INFO'] = hg_info 213955SN/A 214955SN/A################################################### 2151858SN/A# 2161858SN/A# Figure out which configurations to set up based on the path(s) of 2172632Sstever@eecs.umich.edu# the target(s). 218955SN/A# 2194781Snate@binkert.org################################################### 2203643Ssaidi@eecs.umich.edu 2213643Ssaidi@eecs.umich.edu# Find default configuration & binary. 2223643Ssaidi@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2233643Ssaidi@eecs.umich.edu 2243643Ssaidi@eecs.umich.edu# helper function: find last occurrence of element in list 2253643Ssaidi@eecs.umich.edudef rfind(l, elt, offs = -1): 2263643Ssaidi@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2274494Ssaidi@eecs.umich.edu if l[i] == elt: 2284494Ssaidi@eecs.umich.edu return i 2293716Sstever@eecs.umich.edu raise ValueError, "element not found" 2301105SN/A 2312667Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2322667Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2332667Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2342667Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 2352667Sstever@eecs.umich.edu# follow 'build' in the bulid path. 2362667Sstever@eecs.umich.edu 2371869SN/A# Generate absolute paths to targets so we can see where the build dir is 2381869SN/Aif COMMAND_LINE_TARGETS: 2391869SN/A # Ask SCons which directory it was invoked from 2401869SN/A launch_dir = GetLaunchDir() 2411869SN/A # Make targets relative to invocation directory 2421065SN/A abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2432632Sstever@eecs.umich.edu COMMAND_LINE_TARGETS] 2445199Sstever@gmail.comelse: 2453918Ssaidi@eecs.umich.edu # Default targets are relative to root of tree 2463918Ssaidi@eecs.umich.edu abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2473940Ssaidi@eecs.umich.edu DEFAULT_TARGETS] 2484781Snate@binkert.org 2494781Snate@binkert.org 2503918Ssaidi@eecs.umich.edu# Generate a list of the unique build roots and configs that the 2514781Snate@binkert.org# collected targets reference. 2524781Snate@binkert.orgvariant_paths = [] 2533918Ssaidi@eecs.umich.edubuild_root = None 2544781Snate@binkert.orgfor t in abs_targets: 2554781Snate@binkert.org path_dirs = t.split('/') 2563940Ssaidi@eecs.umich.edu try: 2573942Ssaidi@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 2583940Ssaidi@eecs.umich.edu except: 2593918Ssaidi@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 2603918Ssaidi@eecs.umich.edu Exit(1) 261955SN/A this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2621858SN/A if not build_root: 2633918Ssaidi@eecs.umich.edu build_root = this_build_root 2643918Ssaidi@eecs.umich.edu else: 2653918Ssaidi@eecs.umich.edu if this_build_root != build_root: 2663918Ssaidi@eecs.umich.edu print "Error: build targets not under same build root\n"\ 2673940Ssaidi@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 2683940Ssaidi@eecs.umich.edu Exit(1) 2693918Ssaidi@eecs.umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 2703918Ssaidi@eecs.umich.edu if variant_path not in variant_paths: 2713918Ssaidi@eecs.umich.edu variant_paths.append(variant_path) 2723918Ssaidi@eecs.umich.edu 2733918Ssaidi@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 2743918Ssaidi@eecs.umich.eduif not isdir(build_root): 2753918Ssaidi@eecs.umich.edu mkdir(build_root) 2763918Ssaidi@eecs.umich.edumain['BUILDROOT'] = build_root 2773918Ssaidi@eecs.umich.edu 2783940Ssaidi@eecs.umich.eduExport('main') 2793918Ssaidi@eecs.umich.edu 2803918Ssaidi@eecs.umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 2811851SN/A 2821851SN/A# Default duplicate option is to use hard links, but this messes up 2831858SN/A# when you use emacs to edit a file in the target dir, as emacs moves 2845200Sstever@gmail.com# file to file~ then copies to file, breaking the link. Symbolic 285955SN/A# (soft) links work better. 2863053Sstever@eecs.umich.edumain.SetOption('duplicate', 'soft-copy') 2873053Sstever@eecs.umich.edu 2883053Sstever@eecs.umich.edu# 2893053Sstever@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 2903053Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 2913053Sstever@eecs.umich.edu# 2923053Sstever@eecs.umich.edu 2933053Sstever@eecs.umich.edu# Variable validators & converters for global sticky variables 2943053Sstever@eecs.umich.edudef PathListMakeAbsolute(val): 2954742Sstever@eecs.umich.edu if not val: 2964742Sstever@eecs.umich.edu return val 2973053Sstever@eecs.umich.edu f = lambda p: abspath(expanduser(p)) 2983053Sstever@eecs.umich.edu return ':'.join(map(f, val.split(':'))) 2993053Sstever@eecs.umich.edu 3003053Sstever@eecs.umich.edudef PathListAllExist(key, val, env): 3013053Sstever@eecs.umich.edu if not val: 3023053Sstever@eecs.umich.edu return 3033053Sstever@eecs.umich.edu paths = val.split(':') 3043053Sstever@eecs.umich.edu for path in paths: 3053053Sstever@eecs.umich.edu if not isdir(path): 3062667Sstever@eecs.umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3074554Sbinkertn@umich.edu 3084554Sbinkertn@umich.eduglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3092667Sstever@eecs.umich.edu 3104554Sbinkertn@umich.eduglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3114554Sbinkertn@umich.eduglobal_nonsticky_vars = Variables(args=ARGUMENTS) 3124554Sbinkertn@umich.edu 3134554Sbinkertn@umich.eduglobal_sticky_vars.AddVariables( 3144554Sbinkertn@umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3154554Sbinkertn@umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3164554Sbinkertn@umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3174781Snate@binkert.org ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3184554Sbinkertn@umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3194554Sbinkertn@umich.edu ('EXTRAS', 'Add Extra directories to the compilation', '', 3202667Sstever@eecs.umich.edu PathListAllExist, PathListMakeAbsolute), 3214554Sbinkertn@umich.edu ) 3224554Sbinkertn@umich.edu 3234554Sbinkertn@umich.eduglobal_nonsticky_vars.AddVariables( 3244554Sbinkertn@umich.edu ('VERBOSE', 'Print full tool command lines', False), 3252667Sstever@eecs.umich.edu ('update_ref', 'Update test reference outputs', False) 3264554Sbinkertn@umich.edu ) 3272667Sstever@eecs.umich.edu 3284554Sbinkertn@umich.edu 3294554Sbinkertn@umich.edu# base help text 3302667Sstever@eecs.umich.eduhelp_text = ''' 3312638Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 3322638Sstever@eecs.umich.edu 3332638Sstever@eecs.umich.eduGlobal sticky options: 3343716Sstever@eecs.umich.edu''' 3353716Sstever@eecs.umich.edu 3361858SN/A# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3375227Ssaidi@eecs.umich.eduglobal_sticky_vars.Update(main) 3385227Ssaidi@eecs.umich.eduglobal_nonsticky_vars.Update(main) 3395227Ssaidi@eecs.umich.edu 3405227Ssaidi@eecs.umich.eduhelp_text += global_sticky_vars.GenerateHelpText(main) 3415227Ssaidi@eecs.umich.eduhelp_text += global_nonsticky_vars.GenerateHelpText(main) 3425227Ssaidi@eecs.umich.edu 3435227Ssaidi@eecs.umich.edu# Save sticky variable settings back to current variables file 3445227Ssaidi@eecs.umich.eduglobal_sticky_vars.Save(global_sticky_vars_file, main) 3455227Ssaidi@eecs.umich.edu 3465227Ssaidi@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3475227Ssaidi@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3485227Ssaidi@eecs.umich.edubase_dir = main.srcdir.abspath 3495274Ssaidi@eecs.umich.eduif main['EXTRAS']: 3505227Ssaidi@eecs.umich.edu extras_dir_list = main['EXTRAS'].split(':') 3515227Ssaidi@eecs.umich.eduelse: 3525227Ssaidi@eecs.umich.edu extras_dir_list = [] 3535204Sstever@gmail.com 3545204Sstever@gmail.comExport('base_dir') 3555204Sstever@gmail.comExport('extras_dir_list') 3565204Sstever@gmail.com 3575204Sstever@gmail.com# the ext directory should be on the #includes path 3585204Sstever@gmail.commain.Append(CPPPATH=[Dir('ext')]) 3595204Sstever@gmail.com 3605204Sstever@gmail.comdef _STRIP(path, env): 3615204Sstever@gmail.com path = str(path) 3625204Sstever@gmail.com variant_base = env['BUILDROOT'] + os.path.sep 3635204Sstever@gmail.com if path.startswith(variant_base): 3645204Sstever@gmail.com path = path[len(variant_base):] 3655204Sstever@gmail.com elif path.startswith('build/'): 3665204Sstever@gmail.com path = path[6:] 3675204Sstever@gmail.com return path 3685204Sstever@gmail.com 3695204Sstever@gmail.comdef _STRIP_SOURCE(target, source, env, for_signature): 3705204Sstever@gmail.com return _STRIP(source[0], env) 3715204Sstever@gmail.commain['STRIP_SOURCE'] = _STRIP_SOURCE 3723118Sstever@eecs.umich.edu 3733118Sstever@eecs.umich.edudef _STRIP_TARGET(target, source, env, for_signature): 3743118Sstever@eecs.umich.edu return _STRIP(target[0], env) 3753118Sstever@eecs.umich.edumain['STRIP_TARGET'] = _STRIP_TARGET 3763118Sstever@eecs.umich.edu 3773118Sstever@eecs.umich.eduif main['VERBOSE']: 3783118Sstever@eecs.umich.edu def MakeAction(action, string, *args, **kwargs): 3793118Sstever@eecs.umich.edu return Action(action, *args, **kwargs) 3803118Sstever@eecs.umich.eduelse: 3813118Sstever@eecs.umich.edu MakeAction = Action 3823118Sstever@eecs.umich.edu main['CCCOMSTR'] = ' [ CC] $STRIP_SOURCE' 3833716Sstever@eecs.umich.edu main['CXXCOMSTR'] = ' [ CXX] $STRIP_SOURCE' 3843118Sstever@eecs.umich.edu main['ASCOMSTR'] = ' [ AS] $STRIP_SOURCE' 3853118Sstever@eecs.umich.edu main['SWIGCOMSTR'] = ' [ SWIG] $STRIP_SOURCE' 3863118Sstever@eecs.umich.edu main['ARCOMSTR'] = ' [ AR] $STRIP_TARGET' 3873118Sstever@eecs.umich.edu main['LINKCOMSTR'] = ' [ LINK] $STRIP_TARGET' 3883118Sstever@eecs.umich.edu main['RANLIBCOMSTR'] = ' [ RANLIB] $STRIP_TARGET' 3893118Sstever@eecs.umich.edu main['M4COMSTR'] = ' [ M4] $STRIP_TARGET' 3903118Sstever@eecs.umich.edu main['SHCCCOMSTR'] = ' [ SHCC] $STRIP_TARGET' 3913118Sstever@eecs.umich.edu main['SHCXXCOMSTR'] = ' [ SHCXX] $STRIP_TARGET' 3923118Sstever@eecs.umich.eduExport('MakeAction') 3933716Sstever@eecs.umich.edu 3943118Sstever@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 3953118Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 3963118Sstever@eecs.umich.edu 3973118Sstever@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3983118Sstever@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3993118Sstever@eecs.umich.edumain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4003118Sstever@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 4013118Sstever@eecs.umich.edu print 'Error: How can we have two at the same time?' 4023118Sstever@eecs.umich.edu Exit(1) 4033118Sstever@eecs.umich.edu 4043483Ssaidi@eecs.umich.edu# Set up default C++ compiler flags 4053494Ssaidi@eecs.umich.eduif main['GCC']: 4063494Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-pipe']) 4073483Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-fno-strict-aliasing']) 4083483Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4093483Ssaidi@eecs.umich.edu main.Append(CXXFLAGS=['-Wno-deprecated']) 4103053Sstever@eecs.umich.edu # Read the GCC version to check for versions with bugs 4113053Sstever@eecs.umich.edu # Note CCVERSION doesn't work here because it is run with the CC 4123918Ssaidi@eecs.umich.edu # before we override it from the command line 4133053Sstever@eecs.umich.edu gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4143053Sstever@eecs.umich.edu if not compareVersions(gcc_version, '4.4.1') or \ 4153053Sstever@eecs.umich.edu not compareVersions(gcc_version, '4.4.2'): 4163053Sstever@eecs.umich.edu print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 4173053Sstever@eecs.umich.edu main.Append(CCFLAGS=['-fno-tree-vectorize']) 4181858SN/Aelif main['ICC']: 4191858SN/A pass #Fix me... add warning flags once we clean up icc warnings 4201858SN/Aelif main['SUNCC']: 4211858SN/A main.Append(CCFLAGS=['-Qoption ccfe']) 4221858SN/A main.Append(CCFLAGS=['-features=gcc']) 4231858SN/A main.Append(CCFLAGS=['-features=extensions']) 4241859SN/A main.Append(CCFLAGS=['-library=stlport4']) 4251858SN/A main.Append(CCFLAGS=['-xar']) 4261858SN/A #main.Append(CCFLAGS=['-instances=semiexplicit']) 4271858SN/Aelse: 4281859SN/A print 'Error: Don\'t know what compiler options to use for your compiler.' 4291859SN/A print ' Please fix SConstruct and src/SConscript and try again.' 4301862SN/A Exit(1) 4313053Sstever@eecs.umich.edu 4323053Sstever@eecs.umich.edu# Set up common yacc/bison flags (needed for Ruby) 4333053Sstever@eecs.umich.edumain['YACCFLAGS'] = '-d' 4343053Sstever@eecs.umich.edumain['YACCHXXFILESUFFIX'] = '.hh' 4351859SN/A 4361859SN/A# Do this after we save setting back, or else we'll tack on an 4371859SN/A# extra 'qdo' every time we run scons. 4381859SN/Aif main['BATCH']: 4391859SN/A main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 4401859SN/A main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 4411859SN/A main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 4421859SN/A main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 4431862SN/A main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 4441859SN/A 4451859SN/Aif sys.platform == 'cygwin': 4461859SN/A # cygwin has some header file issues... 4471858SN/A main.Append(CCFLAGS=["-Wno-uninitialized"]) 4481858SN/A 4492139SN/A# Check for SWIG 4504202Sbinkertn@umich.eduif not main.has_key('SWIG'): 4514202Sbinkertn@umich.edu print 'Error: SWIG utility not found.' 4522139SN/A print ' Please install (see http://www.swig.org) and retry.' 4532155SN/A Exit(1) 4544202Sbinkertn@umich.edu 4554202Sbinkertn@umich.edu# Check for appropriate SWIG version 4564202Sbinkertn@umich.eduswig_version = readCommand(('swig', '-version'), exception='').split() 4572155SN/A# First 3 words should be "SWIG Version x.y.z" 4581869SN/Aif len(swig_version) < 3 or \ 4591869SN/A swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 4601869SN/A print 'Error determining SWIG version.' 4611869SN/A Exit(1) 4624202Sbinkertn@umich.edu 4634202Sbinkertn@umich.edumin_swig_version = '1.3.28' 4644202Sbinkertn@umich.eduif compareVersions(swig_version[2], min_swig_version) < 0: 4654202Sbinkertn@umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 4664202Sbinkertn@umich.edu print ' Installed version:', swig_version[2] 4674202Sbinkertn@umich.edu Exit(1) 4684202Sbinkertn@umich.edu 4694202Sbinkertn@umich.edu# Set up SWIG flags & scanner 4704202Sbinkertn@umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4714202Sbinkertn@umich.edumain.Append(SWIGFLAGS=swig_flags) 4724202Sbinkertn@umich.edu 4734202Sbinkertn@umich.edu# filter out all existing swig scanners, they mess up the dependency 4744202Sbinkertn@umich.edu# stuff for some reason 4754202Sbinkertn@umich.eduscanners = [] 4764202Sbinkertn@umich.edufor scanner in main['SCANNERS']: 4774202Sbinkertn@umich.edu skeys = scanner.skeys 4785273Sstever@gmail.com if skeys == '.i': 4795273Sstever@gmail.com continue 4805273Sstever@gmail.com 4815273Sstever@gmail.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4825273Sstever@gmail.com continue 4835273Sstever@gmail.com 4845273Sstever@gmail.com scanners.append(scanner) 4854775Snate@binkert.org 4864775Snate@binkert.org# add the new swig scanner that we like better 4874773Snate@binkert.orgfrom SCons.Scanner import ClassicCPP as CPPScanner 4884773Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4894773Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4905273Sstever@gmail.com 4914773Snate@binkert.org# replace the scanners list that has what we want 4921869SN/Amain['SCANNERS'] = scanners 4934202Sbinkertn@umich.edu 4941869SN/A# Add a custom Check function to the Configure context so that we can 4952508SN/A# figure out if the compiler adds leading underscores to global 4962508SN/A# variables. This is needed for the autogenerated asm files that we 4972508SN/A# use for embedding the python code. 4982508SN/Adef CheckLeading(context): 4994202Sbinkertn@umich.edu context.Message("Checking for leading underscore in global variables...") 5001869SN/A # 1) Define a global variable called x from asm so the C compiler 5011869SN/A # won't change the symbol at all. 5021869SN/A # 2) Declare that variable. 5031869SN/A # 3) Use the variable 5041869SN/A # 5051869SN/A # If the compiler prepends an underscore, this will successfully 5061965SN/A # link because the external symbol 'x' will be called '_x' which 5071965SN/A # was defined by the asm statement. If the compiler does not 5081965SN/A # prepend an underscore, this will not successfully link because 5091869SN/A # '_x' will have been defined by assembly, while the C portion of 5101869SN/A # the code will be trying to use 'x' 5112733Sktlim@umich.edu ret = context.TryLink(''' 5121869SN/A asm(".globl _x; _x: .byte 0"); 5131884SN/A extern int x; 5141884SN/A int main() { return x; } 5153356Sbinkertn@umich.edu ''', extension=".c") 5163356Sbinkertn@umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 5173356Sbinkertn@umich.edu context.Result(ret) 5184773Snate@binkert.org return ret 5194773Snate@binkert.org 5205273Sstever@gmail.com# Platform-specific configuration. Note again that we assume that all 5211869SN/A# builds under a given build root run on the same host platform. 5221858SN/Aconf = Configure(main, 5231869SN/A conf_dir = joinpath(build_root, '.scons_config'), 5241869SN/A log_file = joinpath(build_root, 'scons_config.log'), 5251869SN/A custom_tests = { 'CheckLeading' : CheckLeading }) 5261858SN/A 5272761Sstever@eecs.umich.edu# Check for leading underscores. Don't really need to worry either 5281869SN/A# way so don't need to check the return code. 5292733Sktlim@umich.educonf.CheckLeading() 5303584Ssaidi@eecs.umich.edu 5311869SN/A# Check if we should compile a 64 bit binary on Mac OS X/Darwin 5321869SN/Atry: 5331869SN/A import platform 5341869SN/A uname = platform.uname() 5351869SN/A if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 5361869SN/A if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 5371858SN/A main.Append(CCFLAGS=['-arch', 'x86_64']) 538955SN/A main.Append(CFLAGS=['-arch', 'x86_64']) 539955SN/A main.Append(LINKFLAGS=['-arch', 'x86_64']) 5401869SN/A main.Append(ASFLAGS=['-arch', 'x86_64']) 5411869SN/Aexcept: 5421869SN/A pass 5431869SN/A 5441869SN/A# Recent versions of scons substitute a "Null" object for Configure() 5451869SN/A# when configuration isn't necessary, e.g., if the "--help" option is 5461869SN/A# present. Unfortuantely this Null object always returns false, 5471869SN/A# breaking all our configuration checks. We replace it with our own 5481869SN/A# more optimistic null object that returns True instead. 5491869SN/Aif not conf: 5501869SN/A def NullCheck(*args, **kwargs): 5511869SN/A return True 5521869SN/A 5531869SN/A class NullConf: 5541869SN/A def __init__(self, env): 5551869SN/A self.env = env 5561869SN/A def Finish(self): 5571869SN/A return self.env 5581869SN/A def __getattr__(self, mname): 5591869SN/A return NullCheck 5601869SN/A 5611869SN/A conf = NullConf(main) 5621869SN/A 5631869SN/A# Find Python include and library directories for embedding the 5641869SN/A# interpreter. For consistency, we will use the same Python 5651869SN/A# installation used to run scons (and thus this script). If you want 5661869SN/A# to link in an alternate version, see above for instructions on how 5671869SN/A# to invoke scons with a different copy of the Python interpreter. 5681869SN/Afrom distutils import sysconfig 5693716Sstever@eecs.umich.edu 5703356Sbinkertn@umich.edupy_getvar = sysconfig.get_config_var 5713356Sbinkertn@umich.edu 5723356Sbinkertn@umich.edupy_debug = getattr(sys, 'pydebug', False) 5733356Sbinkertn@umich.edupy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 5743356Sbinkertn@umich.edu 5753356Sbinkertn@umich.edupy_general_include = sysconfig.get_python_inc() 5764781Snate@binkert.orgpy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5771869SN/Apy_includes = [ py_general_include ] 5781869SN/Aif py_platform_include != py_general_include: 5791869SN/A py_includes.append(py_platform_include) 5801869SN/A 5811869SN/Apy_lib_path = [ py_getvar('LIBDIR') ] 5821869SN/A# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5831869SN/A# shared library in prefix/lib/. 5842655Sstever@eecs.umich.eduif not py_getvar('Py_ENABLE_SHARED'): 5852655Sstever@eecs.umich.edu py_lib_path.append(py_getvar('LIBPL')) 5862655Sstever@eecs.umich.edu 5872655Sstever@eecs.umich.edupy_libs = [] 5882655Sstever@eecs.umich.edufor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 5892655Sstever@eecs.umich.edu assert lib.startswith('-l') 5902655Sstever@eecs.umich.edu lib = lib[2:] 5912655Sstever@eecs.umich.edu if lib not in py_libs: 5922655Sstever@eecs.umich.edu py_libs.append(lib) 5932655Sstever@eecs.umich.edupy_libs.append(py_version) 5942655Sstever@eecs.umich.edu 5952655Sstever@eecs.umich.edumain.Append(CPPPATH=py_includes) 5962655Sstever@eecs.umich.edumain.Append(LIBPATH=py_lib_path) 5972655Sstever@eecs.umich.edu 5982655Sstever@eecs.umich.edu# Cache build files in the supplied directory. 5992655Sstever@eecs.umich.eduif main['M5_BUILD_CACHE']: 6002655Sstever@eecs.umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 6012655Sstever@eecs.umich.edu CacheDir(main['M5_BUILD_CACHE']) 6022655Sstever@eecs.umich.edu 6032655Sstever@eecs.umich.edu 6042655Sstever@eecs.umich.edu# verify that this stuff works 6052655Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 6062655Sstever@eecs.umich.edu print "Error: can't find Python.h header in", py_includes 6072655Sstever@eecs.umich.edu Exit(1) 6082655Sstever@eecs.umich.edu 6092655Sstever@eecs.umich.edufor lib in py_libs: 6102634Sstever@eecs.umich.edu if not conf.CheckLib(lib): 6112634Sstever@eecs.umich.edu print "Error: can't find library %s required by python" % lib 6122634Sstever@eecs.umich.edu Exit(1) 6132634Sstever@eecs.umich.edu 6142634Sstever@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 6152634Sstever@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6162638Sstever@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6172638Sstever@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 6183716Sstever@eecs.umich.edu Exit(1) 6192638Sstever@eecs.umich.edu 6202638Sstever@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 6211869SN/A# added to the LIBS environment variable. 6221869SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 6233546Sgblack@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 6243546Sgblack@eecs.umich.edu 'and/or zlib.h header file.' 6253546Sgblack@eecs.umich.edu print ' Please install zlib and try again.' 6263546Sgblack@eecs.umich.edu Exit(1) 6274202Sbinkertn@umich.edu 6283546Sgblack@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 6293546Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 6303546Sgblack@eecs.umich.eduif not have_fenv: 6313546Sgblack@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 6323546Sgblack@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 6334781Snate@binkert.org 6344781Snate@binkert.org###################################################################### 6354781Snate@binkert.org# 6364781Snate@binkert.org# Check for mysql. 6374781Snate@binkert.org# 6384781Snate@binkert.orgmysql_config = WhereIs('mysql_config') 6394781Snate@binkert.orghave_mysql = bool(mysql_config) 6404781Snate@binkert.org 6414781Snate@binkert.org# Check MySQL version. 6424781Snate@binkert.orgif have_mysql: 6434781Snate@binkert.org mysql_version = readCommand(mysql_config + ' --version') 6444781Snate@binkert.org min_mysql_version = '4.1' 6453546Sgblack@eecs.umich.edu if compareVersions(mysql_version, min_mysql_version) < 0: 6463546Sgblack@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 6473546Sgblack@eecs.umich.edu print ' Version', mysql_version, 'detected.' 6484781Snate@binkert.org have_mysql = False 6493546Sgblack@eecs.umich.edu 6503546Sgblack@eecs.umich.edu# Set up mysql_config commands. 6513546Sgblack@eecs.umich.eduif have_mysql: 6523546Sgblack@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 6533546Sgblack@eecs.umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 6543546Sgblack@eecs.umich.edu # older mysql_config versions don't support --include, use 6553546Sgblack@eecs.umich.edu # --cflags instead 6563546Sgblack@eecs.umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 6573546Sgblack@eecs.umich.edu # This seems to work in all versions 6583546Sgblack@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 6594202Sbinkertn@umich.edu 6603546Sgblack@eecs.umich.edu###################################################################### 6613546Sgblack@eecs.umich.edu# 6623546Sgblack@eecs.umich.edu# Finish the configuration 663955SN/A# 664955SN/Amain = conf.Finish() 665955SN/A 666955SN/A###################################################################### 6671858SN/A# 6681858SN/A# Collect all non-global variables 6691858SN/A# 6702632Sstever@eecs.umich.edu 6712632Sstever@eecs.umich.edu# Define the universe of supported ISAs 6724773Snate@binkert.orgall_isa_list = [ ] 6734773Snate@binkert.orgExport('all_isa_list') 6742632Sstever@eecs.umich.edu 6752632Sstever@eecs.umich.educlass CpuModel(object): 6762632Sstever@eecs.umich.edu '''The CpuModel class encapsulates everything the ISA parser needs to 6772634Sstever@eecs.umich.edu know about a particular CPU model.''' 6782638Sstever@eecs.umich.edu 6792023SN/A # Dict of available CPU model objects. Accessible as CpuModel.dict. 6802632Sstever@eecs.umich.edu dict = {} 6812632Sstever@eecs.umich.edu list = [] 6822632Sstever@eecs.umich.edu defaults = [] 6832632Sstever@eecs.umich.edu 6842632Sstever@eecs.umich.edu # Constructor. Automatically adds models to CpuModel.dict. 6853716Sstever@eecs.umich.edu def __init__(self, name, filename, includes, strings, default=False): 6862632Sstever@eecs.umich.edu self.name = name # name of model 6872632Sstever@eecs.umich.edu self.filename = filename # filename for output exec code 6882632Sstever@eecs.umich.edu self.includes = includes # include files needed in exec file 6892632Sstever@eecs.umich.edu # The 'strings' dict holds all the per-CPU symbols we can 6902632Sstever@eecs.umich.edu # substitute into templates etc. 6912023SN/A self.strings = strings 6922632Sstever@eecs.umich.edu 6932632Sstever@eecs.umich.edu # This cpu is enabled by default 6941889SN/A self.default = default 6951889SN/A 6962632Sstever@eecs.umich.edu # Add self to dict 6972632Sstever@eecs.umich.edu if name in CpuModel.dict: 6982632Sstever@eecs.umich.edu raise AttributeError, "CpuModel '%s' already registered" % name 6992632Sstever@eecs.umich.edu CpuModel.dict[name] = self 7003716Sstever@eecs.umich.edu CpuModel.list.append(name) 7013716Sstever@eecs.umich.edu 7022632Sstever@eecs.umich.eduExport('CpuModel') 7032632Sstever@eecs.umich.edu 7042632Sstever@eecs.umich.edu# Sticky variables get saved in the variables file so they persist from 7052632Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 7062632Sstever@eecs.umich.edu# value becomes sticky). 7072632Sstever@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS) 7082632Sstever@eecs.umich.eduExport('sticky_vars') 7092632Sstever@eecs.umich.edu 7101888SN/A# Sticky variables that should be exported 7111888SN/Aexport_vars = [] 7121869SN/AExport('export_vars') 7131869SN/A 7141858SN/A# Walk the tree and execute all SConsopts scripts that wil add to the 7152598SN/A# above variables 7162598SN/Afor bdir in [ base_dir ] + extras_dir_list: 7172598SN/A for root, dirs, files in os.walk(bdir): 7182598SN/A if 'SConsopts' in files: 7192598SN/A print "Reading", joinpath(root, 'SConsopts') 7201858SN/A SConscript(joinpath(root, 'SConsopts')) 7211858SN/A 7221858SN/Aall_isa_list.sort() 7231858SN/A 7241858SN/Asticky_vars.AddVariables( 7251858SN/A EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 7261858SN/A BoolVariable('FULL_SYSTEM', 'Full-system support', False), 7271858SN/A ListVariable('CPU_MODELS', 'CPU models', 7281858SN/A sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 7291871SN/A sorted(CpuModel.list)), 7301858SN/A BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 7311858SN/A BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 7321858SN/A False), 7331858SN/A BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 7341858SN/A False), 7351858SN/A BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 7361858SN/A False), 7371858SN/A BoolVariable('SS_COMPATIBLE_FP', 7381858SN/A 'Make floating-point results compatible with SimpleScalar', 7391858SN/A False), 7401858SN/A BoolVariable('USE_SSE2', 7411859SN/A 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 7421859SN/A False), 7431869SN/A BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 7441888SN/A BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 7452632Sstever@eecs.umich.edu BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 7461869SN/A BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 7471884SN/A BoolVariable('RUBY', 'Build with Ruby', False), 7481884SN/A ) 7491884SN/A 7501884SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript). 7511884SN/Aexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 7521884SN/A 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 7531965SN/A 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 7541965SN/A 7551965SN/A################################################### 7562761Sstever@eecs.umich.edu# 7571869SN/A# Define a SCons builder for configuration flag headers. 7581869SN/A# 7592632Sstever@eecs.umich.edu################################################### 7602667Sstever@eecs.umich.edu 7611869SN/A# This function generates a config header file that #defines the 7621869SN/A# variable symbol to the current variable setting (0 or 1). The source 7632929Sktlim@umich.edu# operands are the name of the variable and a Value node containing the 7642929Sktlim@umich.edu# value of the variable. 7653716Sstever@eecs.umich.edudef build_config_file(target, source, env): 7662929Sktlim@umich.edu (variable, value) = [s.get_contents() for s in source] 767955SN/A f = file(str(target[0]), 'w') 7682598SN/A print >> f, '#define', variable, value 7692598SN/A f.close() 7703546Sgblack@eecs.umich.edu return None 771955SN/A 772955SN/A# Generate the message to be printed when building the config file. 773955SN/Adef build_config_file_string(target, source, env): 7741530SN/A (variable, value) = [s.get_contents() for s in source] 775955SN/A return "Defining %s as %s in %s." % (variable, value, target[0]) 776955SN/A 777955SN/A# Combine the two functions into a scons Action object. 778config_action = Action(build_config_file, build_config_file_string) 779 780# The emitter munges the source & target node lists to reflect what 781# we're really doing. 782def config_emitter(target, source, env): 783 # extract variable name from Builder arg 784 variable = str(target[0]) 785 # True target is config header file 786 target = joinpath('config', variable.lower() + '.hh') 787 val = env[variable] 788 if isinstance(val, bool): 789 # Force value to 0/1 790 val = int(val) 791 elif isinstance(val, str): 792 val = '"' + val + '"' 793 794 # Sources are variable name & value (packaged in SCons Value nodes) 795 return ([target], [Value(variable), Value(val)]) 796 797config_builder = Builder(emitter = config_emitter, action = config_action) 798 799main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 800 801# libelf build is shared across all configs in the build root. 802main.SConscript('ext/libelf/SConscript', 803 variant_dir = joinpath(build_root, 'libelf')) 804 805# gzstream build is shared across all configs in the build root. 806main.SConscript('ext/gzstream/SConscript', 807 variant_dir = joinpath(build_root, 'gzstream')) 808 809################################################### 810# 811# This function is used to set up a directory with switching headers 812# 813################################################### 814 815main['ALL_ISA_LIST'] = all_isa_list 816def make_switching_dir(dname, switch_headers, env): 817 # Generate the header. target[0] is the full path of the output 818 # header to generate. 'source' is a dummy variable, since we get the 819 # list of ISAs from env['ALL_ISA_LIST']. 820 def gen_switch_hdr(target, source, env): 821 fname = str(target[0]) 822 f = open(fname, 'w') 823 isa = env['TARGET_ISA'].lower() 824 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 825 f.close() 826 827 # Build SCons Action object. 'varlist' specifies env vars that this 828 # action depends on; when env['ALL_ISA_LIST'] changes these actions 829 # should get re-executed. 830 switch_hdr_action = MakeAction(gen_switch_hdr, 831 " [GENERATE] $STRIP_TARGET", varlist=['ALL_ISA_LIST']) 832 833 # Instantiate actions for each header 834 for hdr in switch_headers: 835 env.Command(hdr, [], switch_hdr_action) 836Export('make_switching_dir') 837 838################################################### 839# 840# Define build environments for selected configurations. 841# 842################################################### 843 844for variant_path in variant_paths: 845 print "Building in", variant_path 846 847 # Make a copy of the build-root environment to use for this config. 848 env = main.Clone() 849 env['BUILDDIR'] = variant_path 850 851 # variant_dir is the tail component of build path, and is used to 852 # determine the build parameters (e.g., 'ALPHA_SE') 853 (build_root, variant_dir) = splitpath(variant_path) 854 855 # Set env variables according to the build directory config. 856 sticky_vars.files = [] 857 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 858 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 859 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 860 current_vars_file = joinpath(build_root, 'variables', variant_dir) 861 if isfile(current_vars_file): 862 sticky_vars.files.append(current_vars_file) 863 print "Using saved variables file %s" % current_vars_file 864 else: 865 # Build dir-specific variables file doesn't exist. 866 867 # Make sure the directory is there so we can create it later 868 opt_dir = dirname(current_vars_file) 869 if not isdir(opt_dir): 870 mkdir(opt_dir) 871 872 # Get default build variables from source tree. Variables are 873 # normally determined by name of $VARIANT_DIR, but can be 874 # overriden by 'default=' arg on command line. 875 default_vars_file = joinpath('build_opts', 876 ARGUMENTS.get('default', variant_dir)) 877 if isfile(default_vars_file): 878 sticky_vars.files.append(default_vars_file) 879 print "Variables file %s not found,\n using defaults in %s" \ 880 % (current_vars_file, default_vars_file) 881 else: 882 print "Error: cannot find variables file %s or %s" \ 883 % (current_vars_file, default_vars_file) 884 Exit(1) 885 886 # Apply current variable settings to env 887 sticky_vars.Update(env) 888 889 help_text += "\nSticky variables for %s:\n" % variant_dir \ 890 + sticky_vars.GenerateHelpText(env) 891 892 # Process variable settings. 893 894 if not have_fenv and env['USE_FENV']: 895 print "Warning: <fenv.h> not available; " \ 896 "forcing USE_FENV to False in", variant_dir + "." 897 env['USE_FENV'] = False 898 899 if not env['USE_FENV']: 900 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 901 print " FP results may deviate slightly from other platforms." 902 903 if env['EFENCE']: 904 env.Append(LIBS=['efence']) 905 906 if env['USE_MYSQL']: 907 if not have_mysql: 908 print "Warning: MySQL not available; " \ 909 "forcing USE_MYSQL to False in", variant_dir + "." 910 env['USE_MYSQL'] = False 911 else: 912 print "Compiling in", variant_dir, "with MySQL support." 913 env.ParseConfig(mysql_config_libs) 914 env.ParseConfig(mysql_config_include) 915 916 # Save sticky variable settings back to current variables file 917 sticky_vars.Save(current_vars_file, env) 918 919 if env['USE_SSE2']: 920 env.Append(CCFLAGS=['-msse2']) 921 922 # The src/SConscript file sets up the build rules in 'env' according 923 # to the configured variables. It returns a list of environments, 924 # one for each variant build (debug, opt, etc.) 925 envList = SConscript('src/SConscript', variant_dir = variant_path, 926 exports = 'env') 927 928 # Set up the regression tests for each build. 929 for e in envList: 930 SConscript('tests/SConscript', 931 variant_dir = joinpath(variant_path, 'tests', e.Label), 932 exports = { 'env' : e }, duplicate = False) 933 934Help(help_text) 935