SConstruct revision 6994
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 685396Ssaidi@eecs.umich.edu# Check for recent-enough Python and SCons versions. 694202Sbinkertn@umich.edutry: 705342Sstever@gmail.com # Really old versions of scons only take two options for the 71955SN/A # function, so check once without the revision and once with the 725273Sstever@gmail.com # revision, the first instance will fail for stuff other than 735273Sstever@gmail.com # 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 802656Sstever@eecs.umich.edu""" 812653Sstever@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 855227Ssaidi@eecs.umich.edutry: 865396Ssaidi@eecs.umich.edu EnsurePythonVersion(2, 4) 875396Ssaidi@eecs.umich.eduexcept SystemExit, e: 885396Ssaidi@eecs.umich.edu print """ 895396Ssaidi@eecs.umich.eduYou can use a non-default installation of the Python interpreter by 905396Ssaidi@eecs.umich.edueither (1) rearranging your PATH so that scons finds the non-default 915396Ssaidi@eecs.umich.edu'python' first or (2) explicitly invoking an alternative interpreter 925396Ssaidi@eecs.umich.eduon the scons script. 935396Ssaidi@eecs.umich.edu 945396Ssaidi@eecs.umich.eduFor more details, see: 955396Ssaidi@eecs.umich.edu http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 965396Ssaidi@eecs.umich.edu""" 975396Ssaidi@eecs.umich.edu raise 985396Ssaidi@eecs.umich.edu 995396Ssaidi@eecs.umich.edu# Global Python includes 1005396Ssaidi@eecs.umich.eduimport os 1015396Ssaidi@eecs.umich.eduimport re 1025396Ssaidi@eecs.umich.eduimport subprocess 1035396Ssaidi@eecs.umich.eduimport sys 1045396Ssaidi@eecs.umich.edu 1055396Ssaidi@eecs.umich.edufrom os import mkdir, environ 1065396Ssaidi@eecs.umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath 1075396Ssaidi@eecs.umich.edufrom os.path import exists, isdir, isfile 1085396Ssaidi@eecs.umich.edufrom os.path import join as joinpath, split as splitpath 1095396Ssaidi@eecs.umich.edu 1105396Ssaidi@eecs.umich.edu# SCons includes 1115396Ssaidi@eecs.umich.eduimport SCons 1125396Ssaidi@eecs.umich.eduimport SCons.Node 1135396Ssaidi@eecs.umich.edu 1145396Ssaidi@eecs.umich.eduextra_python_paths = [ 1155396Ssaidi@eecs.umich.edu Dir('src/python').srcnode().abspath, # M5 includes 1165396Ssaidi@eecs.umich.edu Dir('ext/ply').srcnode().abspath, # ply is used by several files 1175396Ssaidi@eecs.umich.edu ] 1185396Ssaidi@eecs.umich.edu 1195396Ssaidi@eecs.umich.edusys.path[1:1] = extra_python_paths 1205396Ssaidi@eecs.umich.edu 1215396Ssaidi@eecs.umich.edufrom m5.util import compareVersions, readCommand 1225396Ssaidi@eecs.umich.edu 1235396Ssaidi@eecs.umich.edu######################################################################## 1245396Ssaidi@eecs.umich.edu# 1255396Ssaidi@eecs.umich.edu# Set up the main build environment. 1265396Ssaidi@eecs.umich.edu# 1275396Ssaidi@eecs.umich.edu######################################################################## 1285396Ssaidi@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1295396Ssaidi@eecs.umich.edu 'PYTHONPATH', 'RANLIB' ]) 1305396Ssaidi@eecs.umich.edu 1315396Ssaidi@eecs.umich.eduuse_env = {} 1325396Ssaidi@eecs.umich.edufor key,val in os.environ.iteritems(): 1335396Ssaidi@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1345396Ssaidi@eecs.umich.edu use_env[key] = val 1355396Ssaidi@eecs.umich.edu 1365396Ssaidi@eecs.umich.edumain = Environment(ENV=use_env) 1375396Ssaidi@eecs.umich.edumain.root = Dir(".") # The current directory (where this file lives). 1385396Ssaidi@eecs.umich.edumain.srcdir = Dir("src") # The source directory 1395396Ssaidi@eecs.umich.edu 1405396Ssaidi@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 1415396Ssaidi@eecs.umich.edu# as well 1425396Ssaidi@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths) 1435396Ssaidi@eecs.umich.edu 1445396Ssaidi@eecs.umich.edu######################################################################## 1455396Ssaidi@eecs.umich.edu# 1465396Ssaidi@eecs.umich.edu# Mercurial Stuff. 1474781Snate@binkert.org# 1481852SN/A# If the M5 directory is a mercurial repository, we should do some 149955SN/A# extra things. 150955SN/A# 151955SN/A######################################################################## 1523717Sstever@eecs.umich.edu 1533716Sstever@eecs.umich.eduhgdir = main.root.Dir(".hg") 154955SN/A 1551533SN/Amercurial_style_message = """ 1563716Sstever@eecs.umich.eduYou're missing the M5 style hook. 1571533SN/APlease install the hook so we can ensure that all code fits a common style. 1584678Snate@binkert.org 1594678Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc 1604678Snate@binkert.orgor your personal .hgrc 1614678Snate@binkert.org---------------- 1624678Snate@binkert.org 1634678Snate@binkert.org[extensions] 1644678Snate@binkert.orgstyle = %s/util/style.py 1654678Snate@binkert.org 1664678Snate@binkert.org[hooks] 1674678Snate@binkert.orgpretxncommit.style = python:style.check_whitespace 1684678Snate@binkert.org""" % (main.root) 1694678Snate@binkert.org 1704678Snate@binkert.orgmercurial_bin_not_found = """ 1714678Snate@binkert.orgMercurial binary cannot be found, unfortunately this means that we 1724678Snate@binkert.orgcannot easily determine the version of M5 that you are running and 1734678Snate@binkert.orgthis makes error messages more difficult to collect. Please consider 1744678Snate@binkert.orginstalling mercurial if you choose to post an error message 1754678Snate@binkert.org""" 1764678Snate@binkert.org 1774678Snate@binkert.orgmercurial_lib_not_found = """ 1784678Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook 1794973Ssaidi@eecs.umich.eduIf you are actually a M5 developer, please fix this and 1804678Snate@binkert.orgrun the style hook. It is important. 1814678Snate@binkert.org""" 1824678Snate@binkert.org 1834678Snate@binkert.orghg_info = "Unknown" 1844678Snate@binkert.orgif hgdir.exists(): 1854678Snate@binkert.org # 1) Grab repository revision if we know it. 186955SN/A cmd = "hg id -n -i -t -b" 187955SN/A try: 1882632Sstever@eecs.umich.edu hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 1892632Sstever@eecs.umich.edu except OSError: 190955SN/A print mercurial_bin_not_found 191955SN/A 192955SN/A # 2) Ensure that the style hook is in place. 193955SN/A try: 1942632Sstever@eecs.umich.edu ui = None 195955SN/A if ARGUMENTS.get('IGNORE_STYLE') != 'True': 1962632Sstever@eecs.umich.edu from mercurial import ui 1972632Sstever@eecs.umich.edu ui = ui.ui() 1982632Sstever@eecs.umich.edu except ImportError: 1992632Sstever@eecs.umich.edu print mercurial_lib_not_found 2002632Sstever@eecs.umich.edu 2012632Sstever@eecs.umich.edu if ui is not None: 2022632Sstever@eecs.umich.edu ui.readconfig(hgdir.File('hgrc').abspath) 2032632Sstever@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) 2042632Sstever@eecs.umich.edu 2052632Sstever@eecs.umich.edu if not style_hook: 2062632Sstever@eecs.umich.edu print mercurial_style_message 2072632Sstever@eecs.umich.edu sys.exit(1) 2082632Sstever@eecs.umich.eduelse: 2093718Sstever@eecs.umich.edu print ".hg directory not found" 2103718Sstever@eecs.umich.edu 2113718Sstever@eecs.umich.edumain['HG_INFO'] = hg_info 2123718Sstever@eecs.umich.edu 2133718Sstever@eecs.umich.edu################################################### 2143718Sstever@eecs.umich.edu# 2153718Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2163718Sstever@eecs.umich.edu# the target(s). 2173718Sstever@eecs.umich.edu# 2183718Sstever@eecs.umich.edu################################################### 2193718Sstever@eecs.umich.edu 2203718Sstever@eecs.umich.edu# Find default configuration & binary. 2213718Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2222634Sstever@eecs.umich.edu 2232634Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 2242632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 2252638Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2262632Sstever@eecs.umich.edu if l[i] == elt: 2272632Sstever@eecs.umich.edu return i 2282632Sstever@eecs.umich.edu raise ValueError, "element not found" 2292632Sstever@eecs.umich.edu 2302632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2312632Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2321858SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2333716Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 2342638Sstever@eecs.umich.edu# follow 'build' in the bulid path. 2352638Sstever@eecs.umich.edu 2362638Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is 2372638Sstever@eecs.umich.eduif COMMAND_LINE_TARGETS: 2382638Sstever@eecs.umich.edu # Ask SCons which directory it was invoked from 2392638Sstever@eecs.umich.edu launch_dir = GetLaunchDir() 2402638Sstever@eecs.umich.edu # Make targets relative to invocation directory 2413716Sstever@eecs.umich.edu abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2422634Sstever@eecs.umich.edu COMMAND_LINE_TARGETS] 2432634Sstever@eecs.umich.eduelse: 244955SN/A # Default targets are relative to root of tree 2455341Sstever@gmail.com abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2465341Sstever@gmail.com DEFAULT_TARGETS] 2475341Sstever@gmail.com 2485341Sstever@gmail.com 249955SN/A# Generate a list of the unique build roots and configs that the 250955SN/A# collected targets reference. 251955SN/Avariant_paths = [] 252955SN/Abuild_root = None 253955SN/Afor t in abs_targets: 254955SN/A path_dirs = t.split('/') 255955SN/A try: 2561858SN/A build_top = rfind(path_dirs, 'build', -2) 2571858SN/A except: 2582632Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 259955SN/A Exit(1) 2604494Ssaidi@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2614494Ssaidi@eecs.umich.edu if not build_root: 2623716Sstever@eecs.umich.edu build_root = this_build_root 2631105SN/A else: 2642667Sstever@eecs.umich.edu if this_build_root != build_root: 2652667Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 2662667Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 2672667Sstever@eecs.umich.edu Exit(1) 2682667Sstever@eecs.umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 2692667Sstever@eecs.umich.edu if variant_path not in variant_paths: 2701869SN/A variant_paths.append(variant_path) 2711869SN/A 2721869SN/A# Make sure build_root exists (might not if this is the first build there) 2731869SN/Aif not isdir(build_root): 2741869SN/A mkdir(build_root) 2751065SN/A 2765341Sstever@gmail.comExport('main') 2775341Sstever@gmail.com 2785341Sstever@gmail.commain.SConsignFile(joinpath(build_root, "sconsign")) 2795341Sstever@gmail.com 2805341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up 2815341Sstever@gmail.com# when you use emacs to edit a file in the target dir, as emacs moves 2825341Sstever@gmail.com# file to file~ then copies to file, breaking the link. Symbolic 2835341Sstever@gmail.com# (soft) links work better. 2845341Sstever@gmail.commain.SetOption('duplicate', 'soft-copy') 2855341Sstever@gmail.com 2865341Sstever@gmail.com# 2875341Sstever@gmail.com# Set up global sticky variables... these are common to an entire build 2885341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE) 2895341Sstever@gmail.com# 2905341Sstever@gmail.com 2915341Sstever@gmail.com# Variable validators & converters for global sticky variables 2925341Sstever@gmail.comdef PathListMakeAbsolute(val): 2935341Sstever@gmail.com if not val: 2945341Sstever@gmail.com return val 2955341Sstever@gmail.com f = lambda p: abspath(expanduser(p)) 2965341Sstever@gmail.com return ':'.join(map(f, val.split(':'))) 2975341Sstever@gmail.com 2985341Sstever@gmail.comdef PathListAllExist(key, val, env): 2995341Sstever@gmail.com if not val: 3005341Sstever@gmail.com return 3015341Sstever@gmail.com paths = val.split(':') 3025341Sstever@gmail.com for path in paths: 3035397Ssaidi@eecs.umich.edu if not isdir(path): 3045397Ssaidi@eecs.umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3055341Sstever@gmail.com 3065341Sstever@gmail.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3075341Sstever@gmail.com 3085341Sstever@gmail.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3095341Sstever@gmail.com 3105341Sstever@gmail.comglobal_sticky_vars.AddVariables( 3115341Sstever@gmail.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 3125341Sstever@gmail.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3135341Sstever@gmail.com ('BATCH', 'Use batch pool for build and tests', False), 3145341Sstever@gmail.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3155341Sstever@gmail.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3165341Sstever@gmail.com PathListAllExist, PathListMakeAbsolute), 3175341Sstever@gmail.com BoolVariable('RUBY', 'Build with Ruby', False), 3185341Sstever@gmail.com ) 3195341Sstever@gmail.com 3205341Sstever@gmail.com# base help text 3215341Sstever@gmail.comhelp_text = ''' 3225341Sstever@gmail.comUsage: scons [scons options] [build options] [target(s)] 3235341Sstever@gmail.com 3245341Sstever@gmail.comGlobal sticky options: 3255341Sstever@gmail.com''' 3265341Sstever@gmail.com 3275344Sstever@gmail.com# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3285341Sstever@gmail.comglobal_sticky_vars.Update(main) 3295341Sstever@gmail.com 3305341Sstever@gmail.comhelp_text += global_sticky_vars.GenerateHelpText(main) 3315341Sstever@gmail.com 3325341Sstever@gmail.com# Save sticky variable settings back to current variables file 3332632Sstever@eecs.umich.eduglobal_sticky_vars.Save(global_sticky_vars_file, main) 3345199Sstever@gmail.com 3353918Ssaidi@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3363918Ssaidi@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3373940Ssaidi@eecs.umich.edubase_dir = main.srcdir.abspath 3384781Snate@binkert.orgif main['EXTRAS']: 3394781Snate@binkert.org extras_dir_list = main['EXTRAS'].split(':') 3403918Ssaidi@eecs.umich.eduelse: 3414781Snate@binkert.org extras_dir_list = [] 3424781Snate@binkert.org 3433918Ssaidi@eecs.umich.eduExport('base_dir') 3444781Snate@binkert.orgExport('extras_dir_list') 3454781Snate@binkert.org 3463940Ssaidi@eecs.umich.edu# the ext directory should be on the #includes path 3473942Ssaidi@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3483940Ssaidi@eecs.umich.edu 3493918Ssaidi@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 3503918Ssaidi@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 351955SN/A 3521858SN/Amain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3533918Ssaidi@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3543918Ssaidi@eecs.umich.edumain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 3553918Ssaidi@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 3563918Ssaidi@eecs.umich.edu print 'Error: How can we have two at the same time?' 3573940Ssaidi@eecs.umich.edu Exit(1) 3583940Ssaidi@eecs.umich.edu 3593918Ssaidi@eecs.umich.edu# Set up default C++ compiler flags 3603918Ssaidi@eecs.umich.eduif main['GCC']: 3613918Ssaidi@eecs.umich.edu main.Append(CCFLAGS='-pipe') 3623918Ssaidi@eecs.umich.edu main.Append(CCFLAGS='-fno-strict-aliasing') 3633918Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 3643918Ssaidi@eecs.umich.edu main.Append(CXXFLAGS='-Wno-deprecated') 3653918Ssaidi@eecs.umich.eduelif main['ICC']: 3663918Ssaidi@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 3673918Ssaidi@eecs.umich.eduelif main['SUNCC']: 3683940Ssaidi@eecs.umich.edu main.Append(CCFLAGS='-Qoption ccfe') 3693918Ssaidi@eecs.umich.edu main.Append(CCFLAGS='-features=gcc') 3703918Ssaidi@eecs.umich.edu main.Append(CCFLAGS='-features=extensions') 3715397Ssaidi@eecs.umich.edu main.Append(CCFLAGS='-library=stlport4') 3725397Ssaidi@eecs.umich.edu main.Append(CCFLAGS='-xar') 3735397Ssaidi@eecs.umich.edu #main.Append(CCFLAGS='-instances=semiexplicit') 3745397Ssaidi@eecs.umich.eduelse: 3755397Ssaidi@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 3765397Ssaidi@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 3771851SN/A Exit(1) 3781851SN/A 3791858SN/A# Set up common yacc/bison flags (needed for Ruby) 3805200Sstever@gmail.commain['YACCFLAGS'] = '-d' 381955SN/Amain['YACCHXXFILESUFFIX'] = '.hh' 3823053Sstever@eecs.umich.edu 3833053Sstever@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 3843053Sstever@eecs.umich.edu# extra 'qdo' every time we run scons. 3853053Sstever@eecs.umich.eduif main['BATCH']: 3863053Sstever@eecs.umich.edu main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 3873053Sstever@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 3883053Sstever@eecs.umich.edu main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 3893053Sstever@eecs.umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 3903053Sstever@eecs.umich.edu main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 3914742Sstever@eecs.umich.edu 3924742Sstever@eecs.umich.eduif sys.platform == 'cygwin': 3933053Sstever@eecs.umich.edu # cygwin has some header file issues... 3943053Sstever@eecs.umich.edu main.Append(CCFLAGS="-Wno-uninitialized") 3953053Sstever@eecs.umich.edu 3963053Sstever@eecs.umich.edu# Check for SWIG 3973053Sstever@eecs.umich.eduif not main.has_key('SWIG'): 3983053Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 3993053Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 4003053Sstever@eecs.umich.edu Exit(1) 4013053Sstever@eecs.umich.edu 4022667Sstever@eecs.umich.edu# Check for appropriate SWIG version 4034554Sbinkertn@umich.eduswig_version = readCommand(('swig', '-version'), exception='').split() 4044554Sbinkertn@umich.edu# First 3 words should be "SWIG Version x.y.z" 4052667Sstever@eecs.umich.eduif len(swig_version) < 3 or \ 4064554Sbinkertn@umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 4074554Sbinkertn@umich.edu print 'Error determining SWIG version.' 4084554Sbinkertn@umich.edu Exit(1) 4094554Sbinkertn@umich.edu 4104554Sbinkertn@umich.edumin_swig_version = '1.3.28' 4114554Sbinkertn@umich.eduif compareVersions(swig_version[2], min_swig_version) < 0: 4124554Sbinkertn@umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 4134781Snate@binkert.org print ' Installed version:', swig_version[2] 4144554Sbinkertn@umich.edu Exit(1) 4154554Sbinkertn@umich.edu 4162667Sstever@eecs.umich.edu# Set up SWIG flags & scanner 4174554Sbinkertn@umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4184554Sbinkertn@umich.edumain.Append(SWIGFLAGS=swig_flags) 4194554Sbinkertn@umich.edu 4204554Sbinkertn@umich.edu# filter out all existing swig scanners, they mess up the dependency 4212667Sstever@eecs.umich.edu# stuff for some reason 4224554Sbinkertn@umich.eduscanners = [] 4232667Sstever@eecs.umich.edufor scanner in main['SCANNERS']: 4244554Sbinkertn@umich.edu skeys = scanner.skeys 4254554Sbinkertn@umich.edu if skeys == '.i': 4262667Sstever@eecs.umich.edu continue 4275522Snate@binkert.org 4285522Snate@binkert.org if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4295522Snate@binkert.org continue 4305522Snate@binkert.org 4315522Snate@binkert.org scanners.append(scanner) 4325522Snate@binkert.org 4335522Snate@binkert.org# add the new swig scanner that we like better 4345522Snate@binkert.orgfrom SCons.Scanner import ClassicCPP as CPPScanner 4355522Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4365522Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4375522Snate@binkert.org 4385522Snate@binkert.org# replace the scanners list that has what we want 4395522Snate@binkert.orgmain['SCANNERS'] = scanners 4405522Snate@binkert.org 4415522Snate@binkert.org# Add a custom Check function to the Configure context so that we can 4425522Snate@binkert.org# figure out if the compiler adds leading underscores to global 4435522Snate@binkert.org# variables. This is needed for the autogenerated asm files that we 4445522Snate@binkert.org# use for embedding the python code. 4455522Snate@binkert.orgdef CheckLeading(context): 4465522Snate@binkert.org context.Message("Checking for leading underscore in global variables...") 4475522Snate@binkert.org # 1) Define a global variable called x from asm so the C compiler 4485522Snate@binkert.org # won't change the symbol at all. 4495522Snate@binkert.org # 2) Declare that variable. 4505522Snate@binkert.org # 3) Use the variable 4515522Snate@binkert.org # 4525522Snate@binkert.org # If the compiler prepends an underscore, this will successfully 4532638Sstever@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 4542638Sstever@eecs.umich.edu # was defined by the asm statement. If the compiler does not 4552638Sstever@eecs.umich.edu # prepend an underscore, this will not successfully link because 4563716Sstever@eecs.umich.edu # '_x' will have been defined by assembly, while the C portion of 4575522Snate@binkert.org # the code will be trying to use 'x' 4585522Snate@binkert.org ret = context.TryLink(''' 4595522Snate@binkert.org asm(".globl _x; _x: .byte 0"); 4605522Snate@binkert.org extern int x; 4615522Snate@binkert.org int main() { return x; } 4625522Snate@binkert.org ''', extension=".c") 4631858SN/A context.env.Append(LEADING_UNDERSCORE=ret) 4645227Ssaidi@eecs.umich.edu context.Result(ret) 4655227Ssaidi@eecs.umich.edu return ret 4665227Ssaidi@eecs.umich.edu 4675227Ssaidi@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 4685227Ssaidi@eecs.umich.edu# builds under a given build root run on the same host platform. 4695227Ssaidi@eecs.umich.educonf = Configure(main, 4705227Ssaidi@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 4715227Ssaidi@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 4725227Ssaidi@eecs.umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 4735227Ssaidi@eecs.umich.edu 4745227Ssaidi@eecs.umich.edu# Check for leading underscores. Don't really need to worry either 4755227Ssaidi@eecs.umich.edu# way so don't need to check the return code. 4765227Ssaidi@eecs.umich.educonf.CheckLeading() 4775227Ssaidi@eecs.umich.edu 4785227Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 4795204Sstever@gmail.comtry: 4805204Sstever@gmail.com import platform 4815204Sstever@gmail.com uname = platform.uname() 4825204Sstever@gmail.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 4835204Sstever@gmail.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 4845204Sstever@gmail.com main.Append(CCFLAGS='-arch x86_64') 4855204Sstever@gmail.com main.Append(CFLAGS='-arch x86_64') 4865204Sstever@gmail.com main.Append(LINKFLAGS='-arch x86_64') 4875204Sstever@gmail.com main.Append(ASFLAGS='-arch x86_64') 4885204Sstever@gmail.comexcept: 4895204Sstever@gmail.com pass 4905204Sstever@gmail.com 4915204Sstever@gmail.com# Recent versions of scons substitute a "Null" object for Configure() 4925204Sstever@gmail.com# when configuration isn't necessary, e.g., if the "--help" option is 4935204Sstever@gmail.com# present. Unfortuantely this Null object always returns false, 4945204Sstever@gmail.com# breaking all our configuration checks. We replace it with our own 4955204Sstever@gmail.com# more optimistic null object that returns True instead. 4965204Sstever@gmail.comif not conf: 4975204Sstever@gmail.com def NullCheck(*args, **kwargs): 4983118Sstever@eecs.umich.edu return True 4993118Sstever@eecs.umich.edu 5003118Sstever@eecs.umich.edu class NullConf: 5013118Sstever@eecs.umich.edu def __init__(self, env): 5023118Sstever@eecs.umich.edu self.env = env 5033118Sstever@eecs.umich.edu def Finish(self): 5043118Sstever@eecs.umich.edu return self.env 5053118Sstever@eecs.umich.edu def __getattr__(self, mname): 5063118Sstever@eecs.umich.edu return NullCheck 5073118Sstever@eecs.umich.edu 5083118Sstever@eecs.umich.edu conf = NullConf(main) 5093716Sstever@eecs.umich.edu 5103118Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 5113118Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 5123118Sstever@eecs.umich.edu# installation used to run scons (and thus this script). If you want 5133118Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how 5143118Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 5153118Sstever@eecs.umich.edufrom distutils import sysconfig 5163118Sstever@eecs.umich.edu 5173118Sstever@eecs.umich.edupy_getvar = sysconfig.get_config_var 5183118Sstever@eecs.umich.edu 5193716Sstever@eecs.umich.edupy_version = 'python' + py_getvar('VERSION') 5203118Sstever@eecs.umich.edu 5213118Sstever@eecs.umich.edupy_general_include = sysconfig.get_python_inc() 5223118Sstever@eecs.umich.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5233118Sstever@eecs.umich.edupy_includes = [ py_general_include ] 5243118Sstever@eecs.umich.eduif py_platform_include != py_general_include: 5253118Sstever@eecs.umich.edu py_includes.append(py_platform_include) 5263118Sstever@eecs.umich.edu 5273118Sstever@eecs.umich.edupy_lib_path = [ py_getvar('LIBDIR') ] 5283118Sstever@eecs.umich.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5293118Sstever@eecs.umich.edu# shared library in prefix/lib/. 5303483Ssaidi@eecs.umich.eduif not py_getvar('Py_ENABLE_SHARED'): 5313494Ssaidi@eecs.umich.edu py_lib_path.append(py_getvar('LIBPL')) 5323494Ssaidi@eecs.umich.edu 5333483Ssaidi@eecs.umich.edupy_libs = [] 5343483Ssaidi@eecs.umich.edufor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 5353483Ssaidi@eecs.umich.edu assert lib.startswith('-l') 5363053Sstever@eecs.umich.edu lib = lib[2:] 5373053Sstever@eecs.umich.edu if lib not in py_libs: 5383918Ssaidi@eecs.umich.edu py_libs.append(lib) 5393053Sstever@eecs.umich.edupy_libs.append(py_version) 5403053Sstever@eecs.umich.edu 5413053Sstever@eecs.umich.edumain.Append(CPPPATH=py_includes) 5423053Sstever@eecs.umich.edumain.Append(LIBPATH=py_lib_path) 5433053Sstever@eecs.umich.edu 5441858SN/A# verify that this stuff works 5451858SN/Aif not conf.CheckHeader('Python.h', '<>'): 5461858SN/A print "Error: can't find Python.h header in", py_includes 5471858SN/A Exit(1) 5481858SN/A 5491858SN/Afor lib in py_libs: 5501859SN/A if not conf.CheckLib(lib): 5511858SN/A print "Error: can't find library %s required by python" % lib 5521858SN/A Exit(1) 5531858SN/A 5541859SN/A# On Solaris you need to use libsocket for socket ops 5551859SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5561862SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5573053Sstever@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 5583053Sstever@eecs.umich.edu Exit(1) 5593053Sstever@eecs.umich.edu 5603053Sstever@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 5611859SN/A# added to the LIBS environment variable. 5621859SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5631859SN/A print 'Error: did not find needed zlib compression library '\ 5641859SN/A 'and/or zlib.h header file.' 5651859SN/A print ' Please install zlib and try again.' 5661859SN/A Exit(1) 5671859SN/A 5681859SN/A# Check for <fenv.h> (C99 FP environment control) 5691862SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 5701859SN/Aif not have_fenv: 5711859SN/A print "Warning: Header file <fenv.h> not found." 5721859SN/A print " This host has no IEEE FP rounding mode control." 5731858SN/A 5741858SN/A###################################################################### 5752139SN/A# 5764202Sbinkertn@umich.edu# Check for mysql. 5774202Sbinkertn@umich.edu# 5782139SN/Amysql_config = WhereIs('mysql_config') 5792155SN/Ahave_mysql = bool(mysql_config) 5804202Sbinkertn@umich.edu 5814202Sbinkertn@umich.edu# Check MySQL version. 5824202Sbinkertn@umich.eduif have_mysql: 5832155SN/A mysql_version = readCommand(mysql_config + ' --version') 5841869SN/A min_mysql_version = '4.1' 5851869SN/A if compareVersions(mysql_version, min_mysql_version) < 0: 5861869SN/A print 'Warning: MySQL', min_mysql_version, 'or newer required.' 5871869SN/A print ' Version', mysql_version, 'detected.' 5884202Sbinkertn@umich.edu have_mysql = False 5894202Sbinkertn@umich.edu 5904202Sbinkertn@umich.edu# Set up mysql_config commands. 5914202Sbinkertn@umich.eduif have_mysql: 5924202Sbinkertn@umich.edu mysql_config_include = mysql_config + ' --include' 5934202Sbinkertn@umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 5944202Sbinkertn@umich.edu # older mysql_config versions don't support --include, use 5954202Sbinkertn@umich.edu # --cflags instead 5965341Sstever@gmail.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 5975341Sstever@gmail.com # This seems to work in all versions 5985341Sstever@gmail.com mysql_config_libs = mysql_config + ' --libs' 5995342Sstever@gmail.com 6005342Sstever@gmail.com###################################################################### 6014202Sbinkertn@umich.edu# 6024202Sbinkertn@umich.edu# Finish the configuration 6034202Sbinkertn@umich.edu# 6044202Sbinkertn@umich.edumain = conf.Finish() 6054202Sbinkertn@umich.edu 6061869SN/A###################################################################### 6074202Sbinkertn@umich.edu# 6081869SN/A# Collect all non-global variables 6092508SN/A# 6102508SN/A 6112508SN/A# Define the universe of supported ISAs 6122508SN/Aall_isa_list = [ ] 6134202Sbinkertn@umich.eduExport('all_isa_list') 6141869SN/A 6155385Sstever@gmail.comclass CpuModel(object): 6165385Sstever@gmail.com '''The CpuModel class encapsulates everything the ISA parser needs to 6175385Sstever@gmail.com know about a particular CPU model.''' 6185385Sstever@gmail.com 6191869SN/A # Dict of available CPU model objects. Accessible as CpuModel.dict. 6201869SN/A dict = {} 6211869SN/A list = [] 6221869SN/A defaults = [] 6231869SN/A 6241965SN/A # Constructor. Automatically adds models to CpuModel.dict. 6251965SN/A def __init__(self, name, filename, includes, strings, default=False): 6261965SN/A self.name = name # name of model 6271869SN/A self.filename = filename # filename for output exec code 6281869SN/A self.includes = includes # include files needed in exec file 6292733Sktlim@umich.edu # The 'strings' dict holds all the per-CPU symbols we can 6301869SN/A # substitute into templates etc. 6311858SN/A self.strings = strings 6321869SN/A 6331869SN/A # This cpu is enabled by default 6341869SN/A self.default = default 6351858SN/A 6362761Sstever@eecs.umich.edu # Add self to dict 6371869SN/A if name in CpuModel.dict: 6385385Sstever@gmail.com raise AttributeError, "CpuModel '%s' already registered" % name 6395385Sstever@gmail.com CpuModel.dict[name] = self 6405522Snate@binkert.org CpuModel.list.append(name) 6411869SN/A 6421869SN/AExport('CpuModel') 6431869SN/A 6441869SN/A# Sticky variables get saved in the variables file so they persist from 6451869SN/A# one invocation to the next (unless overridden, in which case the new 6461869SN/A# value becomes sticky). 6471858SN/Asticky_vars = Variables(args=ARGUMENTS) 648955SN/AExport('sticky_vars') 649955SN/A 6501869SN/A# Sticky variables that should be exported 6511869SN/Aexport_vars = [] 6521869SN/AExport('export_vars') 6531869SN/A 6541869SN/A# Non-sticky variables only apply to the current build. 6551869SN/Anonsticky_vars = Variables(args=ARGUMENTS) 6561869SN/AExport('nonsticky_vars') 6571869SN/A 6581869SN/A# Walk the tree and execute all SConsopts scripts that wil add to the 6591869SN/A# above variables 6601869SN/Afor bdir in [ base_dir ] + extras_dir_list: 6611869SN/A for root, dirs, files in os.walk(bdir): 6621869SN/A if 'SConsopts' in files: 6631869SN/A print "Reading", joinpath(root, 'SConsopts') 6641869SN/A SConscript(joinpath(root, 'SConsopts')) 6651869SN/A 6661869SN/Aall_isa_list.sort() 6671869SN/A 6681869SN/Asticky_vars.AddVariables( 6691869SN/A EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6701869SN/A BoolVariable('FULL_SYSTEM', 'Full-system support', False), 6711869SN/A ListVariable('CPU_MODELS', 'CPU models', 6721869SN/A sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 6731869SN/A sorted(CpuModel.list)), 6741869SN/A BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6751869SN/A BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6761869SN/A False), 6771869SN/A BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6781869SN/A False), 6793716Sstever@eecs.umich.edu BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 6803356Sbinkertn@umich.edu False), 6813356Sbinkertn@umich.edu BoolVariable('SS_COMPATIBLE_FP', 6823356Sbinkertn@umich.edu 'Make floating-point results compatible with SimpleScalar', 6833356Sbinkertn@umich.edu False), 6843356Sbinkertn@umich.edu BoolVariable('USE_SSE2', 6853356Sbinkertn@umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 6864781Snate@binkert.org False), 6871869SN/A BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6881869SN/A BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6891869SN/A BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 6901869SN/A BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 6911869SN/A ) 6921869SN/A 6931869SN/Anonsticky_vars.AddVariables( 6942655Sstever@eecs.umich.edu BoolVariable('update_ref', 'Update test reference outputs', False) 6952655Sstever@eecs.umich.edu ) 6962655Sstever@eecs.umich.edu 6972655Sstever@eecs.umich.edu# These variables get exported to #defines in config/*.hh (see src/SConscript). 6982655Sstever@eecs.umich.eduexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 6992655Sstever@eecs.umich.edu 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 7002655Sstever@eecs.umich.edu 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 7012655Sstever@eecs.umich.edu 7022655Sstever@eecs.umich.edu################################################### 7032655Sstever@eecs.umich.edu# 7042655Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers. 7052655Sstever@eecs.umich.edu# 7062655Sstever@eecs.umich.edu################################################### 7072655Sstever@eecs.umich.edu 7082655Sstever@eecs.umich.edu# This function generates a config header file that #defines the 7092655Sstever@eecs.umich.edu# variable symbol to the current variable setting (0 or 1). The source 7102655Sstever@eecs.umich.edu# operands are the name of the variable and a Value node containing the 7112655Sstever@eecs.umich.edu# value of the variable. 7122655Sstever@eecs.umich.edudef build_config_file(target, source, env): 7132655Sstever@eecs.umich.edu (variable, value) = [s.get_contents() for s in source] 7142655Sstever@eecs.umich.edu f = file(str(target[0]), 'w') 7152655Sstever@eecs.umich.edu print >> f, '#define', variable, value 7162655Sstever@eecs.umich.edu f.close() 7172655Sstever@eecs.umich.edu return None 7182655Sstever@eecs.umich.edu 7192655Sstever@eecs.umich.edu# Generate the message to be printed when building the config file. 7202638Sstever@eecs.umich.edudef build_config_file_string(target, source, env): 7212638Sstever@eecs.umich.edu (variable, value) = [s.get_contents() for s in source] 7223716Sstever@eecs.umich.edu return "Defining %s as %s in %s." % (variable, value, target[0]) 7232638Sstever@eecs.umich.edu 7242638Sstever@eecs.umich.edu# Combine the two functions into a scons Action object. 7251869SN/Aconfig_action = Action(build_config_file, build_config_file_string) 7261869SN/A 7273546Sgblack@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 7283546Sgblack@eecs.umich.edu# we're really doing. 7293546Sgblack@eecs.umich.edudef config_emitter(target, source, env): 7303546Sgblack@eecs.umich.edu # extract variable name from Builder arg 7314202Sbinkertn@umich.edu variable = str(target[0]) 7323546Sgblack@eecs.umich.edu # True target is config header file 7333546Sgblack@eecs.umich.edu target = joinpath('config', variable.lower() + '.hh') 7343546Sgblack@eecs.umich.edu val = env[variable] 7353546Sgblack@eecs.umich.edu if isinstance(val, bool): 7363546Sgblack@eecs.umich.edu # Force value to 0/1 7374781Snate@binkert.org val = int(val) 7384781Snate@binkert.org elif isinstance(val, str): 7394781Snate@binkert.org val = '"' + val + '"' 7404781Snate@binkert.org 7414781Snate@binkert.org # Sources are variable name & value (packaged in SCons Value nodes) 7424781Snate@binkert.org return ([target], [Value(variable), Value(val)]) 7434781Snate@binkert.org 7444781Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 7454781Snate@binkert.org 7464781Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 7474781Snate@binkert.org 7484781Snate@binkert.org# libelf build is shared across all configs in the build root. 7493546Sgblack@eecs.umich.edumain.SConscript('ext/libelf/SConscript', 7503546Sgblack@eecs.umich.edu variant_dir = joinpath(build_root, 'libelf')) 7513546Sgblack@eecs.umich.edu 7524781Snate@binkert.org# gzstream build is shared across all configs in the build root. 7533546Sgblack@eecs.umich.edumain.SConscript('ext/gzstream/SConscript', 7543546Sgblack@eecs.umich.edu variant_dir = joinpath(build_root, 'gzstream')) 7553546Sgblack@eecs.umich.edu 7563546Sgblack@eecs.umich.edu################################################### 7573546Sgblack@eecs.umich.edu# 7583546Sgblack@eecs.umich.edu# This function is used to set up a directory with switching headers 7593546Sgblack@eecs.umich.edu# 7603546Sgblack@eecs.umich.edu################################################### 7613546Sgblack@eecs.umich.edu 7623546Sgblack@eecs.umich.edumain['ALL_ISA_LIST'] = all_isa_list 7634202Sbinkertn@umich.edudef make_switching_dir(dname, switch_headers, env): 7643546Sgblack@eecs.umich.edu # Generate the header. target[0] is the full path of the output 7653546Sgblack@eecs.umich.edu # header to generate. 'source' is a dummy variable, since we get the 7663546Sgblack@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 767955SN/A def gen_switch_hdr(target, source, env): 768955SN/A fname = str(target[0]) 769955SN/A f = open(fname, 'w') 770955SN/A isa = env['TARGET_ISA'].lower() 7711858SN/A print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 7721858SN/A f.close() 7731858SN/A 7742632Sstever@eecs.umich.edu # String to print when generating header 7752632Sstever@eecs.umich.edu def gen_switch_hdr_string(target, source, env): 7765343Sstever@gmail.com return "Generating switch header " + str(target[0]) 7775343Sstever@gmail.com 7785343Sstever@gmail.com # Build SCons Action object. 'varlist' specifies env vars that this 7794773Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 7804773Snate@binkert.org # should get re-executed. 7812632Sstever@eecs.umich.edu switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 7822632Sstever@eecs.umich.edu varlist=['ALL_ISA_LIST']) 7832632Sstever@eecs.umich.edu 7842023SN/A # Instantiate actions for each header 7852632Sstever@eecs.umich.edu for hdr in switch_headers: 7862632Sstever@eecs.umich.edu env.Command(hdr, [], switch_hdr_action) 7872632Sstever@eecs.umich.eduExport('make_switching_dir') 7882632Sstever@eecs.umich.edu 7892632Sstever@eecs.umich.edu################################################### 7903716Sstever@eecs.umich.edu# 7915342Sstever@gmail.com# Define build environments for selected configurations. 7922632Sstever@eecs.umich.edu# 7932632Sstever@eecs.umich.edu################################################### 7942632Sstever@eecs.umich.edu 7952632Sstever@eecs.umich.edufor variant_path in variant_paths: 7962023SN/A print "Building in", variant_path 7972632Sstever@eecs.umich.edu 7982632Sstever@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 7995342Sstever@gmail.com env = main.Clone() 8001889SN/A env['BUILDDIR'] = variant_path 8012632Sstever@eecs.umich.edu 8022632Sstever@eecs.umich.edu # variant_dir is the tail component of build path, and is used to 8032632Sstever@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 8042632Sstever@eecs.umich.edu (build_root, variant_dir) = splitpath(variant_path) 8053716Sstever@eecs.umich.edu 8063716Sstever@eecs.umich.edu # Set env variables according to the build directory config. 8075342Sstever@gmail.com sticky_vars.files = [] 8082632Sstever@eecs.umich.edu # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 8092632Sstever@eecs.umich.edu # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 8102632Sstever@eecs.umich.edu # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 8112632Sstever@eecs.umich.edu current_vars_file = joinpath(build_root, 'variables', variant_dir) 8122632Sstever@eecs.umich.edu if isfile(current_vars_file): 8132632Sstever@eecs.umich.edu sticky_vars.files.append(current_vars_file) 8142632Sstever@eecs.umich.edu print "Using saved variables file %s" % current_vars_file 8151888SN/A else: 8161888SN/A # Build dir-specific variables file doesn't exist. 8171869SN/A 8181869SN/A # Make sure the directory is there so we can create it later 8191858SN/A opt_dir = dirname(current_vars_file) 8205341Sstever@gmail.com if not isdir(opt_dir): 8212598SN/A mkdir(opt_dir) 8222598SN/A 8232598SN/A # Get default build variables from source tree. Variables are 8242598SN/A # normally determined by name of $VARIANT_DIR, but can be 8251858SN/A # overriden by 'default=' arg on command line. 8261858SN/A default_vars_file = joinpath('build_opts', 8271858SN/A ARGUMENTS.get('default', variant_dir)) 8281858SN/A if isfile(default_vars_file): 8291858SN/A sticky_vars.files.append(default_vars_file) 8301858SN/A print "Variables file %s not found,\n using defaults in %s" \ 8311858SN/A % (current_vars_file, default_vars_file) 8321858SN/A else: 8331858SN/A print "Error: cannot find variables file %s or %s" \ 8341871SN/A % (current_vars_file, default_vars_file) 8351858SN/A Exit(1) 8361858SN/A 8371858SN/A # Apply current variable settings to env 8381858SN/A sticky_vars.Update(env) 8391858SN/A nonsticky_vars.Update(env) 8401858SN/A 8411858SN/A help_text += "\nSticky variables for %s:\n" % variant_dir \ 8421858SN/A + sticky_vars.GenerateHelpText(env) \ 8431858SN/A + "\nNon-sticky variables for %s:\n" % variant_dir \ 8441858SN/A + nonsticky_vars.GenerateHelpText(env) 8451858SN/A 8461859SN/A # Process variable settings. 8471859SN/A 8481869SN/A if not have_fenv and env['USE_FENV']: 8491888SN/A print "Warning: <fenv.h> not available; " \ 8502632Sstever@eecs.umich.edu "forcing USE_FENV to False in", variant_dir + "." 8511869SN/A env['USE_FENV'] = False 8521965SN/A 8531965SN/A if not env['USE_FENV']: 8541965SN/A print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 8552761Sstever@eecs.umich.edu print " FP results may deviate slightly from other platforms." 8561869SN/A 8571869SN/A if env['EFENCE']: 8582632Sstever@eecs.umich.edu env.Append(LIBS=['efence']) 8592667Sstever@eecs.umich.edu 8601869SN/A if env['USE_MYSQL']: 8611869SN/A if not have_mysql: 8622929Sktlim@umich.edu print "Warning: MySQL not available; " \ 8632929Sktlim@umich.edu "forcing USE_MYSQL to False in", variant_dir + "." 8643716Sstever@eecs.umich.edu env['USE_MYSQL'] = False 8652929Sktlim@umich.edu else: 866955SN/A print "Compiling in", variant_dir, "with MySQL support." 8672598SN/A env.ParseConfig(mysql_config_libs) 8682598SN/A env.ParseConfig(mysql_config_include) 8693546Sgblack@eecs.umich.edu 870955SN/A # Save sticky variable settings back to current variables file 871955SN/A sticky_vars.Save(current_vars_file, env) 872955SN/A 8731530SN/A if env['USE_SSE2']: 874955SN/A env.Append(CCFLAGS='-msse2') 875955SN/A 876955SN/A # The src/SConscript file sets up the build rules in 'env' according 877 # to the configured variables. It returns a list of environments, 878 # one for each variant build (debug, opt, etc.) 879 envList = SConscript('src/SConscript', variant_dir = variant_path, 880 exports = 'env') 881 882 # Set up the regression tests for each build. 883 for e in envList: 884 SConscript('tests/SConscript', 885 variant_dir = joinpath(variant_path, 'tests', e.Label), 886 exports = { 'env' : e }, duplicate = False) 887 888Help(help_text) 889