SConstruct revision 7840
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2011 Advanced Micro Devices, Inc. 4955SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 5955SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 6955SN/A# All rights reserved. 7955SN/A# 8955SN/A# Redistribution and use in source and binary forms, with or without 9955SN/A# modification, are permitted provided that the following conditions are 10955SN/A# met: redistributions of source code must retain the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer; 12955SN/A# redistributions in binary form must reproduce the above copyright 13955SN/A# notice, this list of conditions and the following disclaimer in the 14955SN/A# documentation and/or other materials provided with the distribution; 15955SN/A# neither the name of the copyright holders nor the names of its 16955SN/A# contributors may be used to endorse or promote products derived from 17955SN/A# this software without specific prior written permission. 18955SN/A# 19955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 282665Ssaidi@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 292665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30955SN/A# 31955SN/A# Authors: Steve Reinhardt 32955SN/A# Nathan Binkert 33955SN/A 34955SN/A################################################### 352632Sstever@eecs.umich.edu# 362632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 372632Sstever@eecs.umich.edu# 382632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 39955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 402632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 412632Sstever@eecs.umich.edu# the optimized full-system version). 422761Sstever@eecs.umich.edu# 432632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 442632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 452632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 462761Sstever@eecs.umich.edu# built for the same host system. 472761Sstever@eecs.umich.edu# 482761Sstever@eecs.umich.edu# Examples: 492632Sstever@eecs.umich.edu# 502632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 512761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 522761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 532761Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 542761Sstever@eecs.umich.edu# 552761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 562632Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 572632Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 582632Sstever@eecs.umich.edu# file. 592632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 602632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 612632Sstever@eecs.umich.edu# 622632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 63955SN/A# 'm5' directory (or use -u or -C to tell scons where to find this 64955SN/A# file), you can use 'scons -h' to print all the M5-specific build 65955SN/A# options as well. 66955SN/A# 67955SN/A################################################### 685396Ssaidi@eecs.umich.edu 694202Sbinkertn@umich.edu# Check for recent-enough Python and SCons versions. 705342Sstever@gmail.comtry: 71955SN/A # Really old versions of scons only take two options for the 725273Sstever@gmail.com # function, so check once without the revision and once with the 735273Sstever@gmail.com # revision, the first instance will fail for stuff other than 742656Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 752656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 762656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98, 1) 772656Sstever@eecs.umich.eduexcept SystemExit, e: 782656Sstever@eecs.umich.edu print """ 792656Sstever@eecs.umich.eduFor more details, see: 802656Sstever@eecs.umich.edu http://m5sim.org/wiki/index.php/Compiling_M5 812653Sstever@eecs.umich.edu""" 825227Ssaidi@eecs.umich.edu raise 835227Ssaidi@eecs.umich.edu 845227Ssaidi@eecs.umich.edu# We ensure the python version early because we have stuff that 855227Ssaidi@eecs.umich.edu# requires python 2.4 865396Ssaidi@eecs.umich.edutry: 875396Ssaidi@eecs.umich.edu EnsurePythonVersion(2, 4) 885396Ssaidi@eecs.umich.eduexcept SystemExit, e: 895396Ssaidi@eecs.umich.edu print """ 905396Ssaidi@eecs.umich.eduYou can use a non-default installation of the Python interpreter by 915396Ssaidi@eecs.umich.edueither (1) rearranging your PATH so that scons finds the non-default 925396Ssaidi@eecs.umich.edu'python' first or (2) explicitly invoking an alternative interpreter 935396Ssaidi@eecs.umich.eduon the scons script. 945588Ssaidi@eecs.umich.edu 955396Ssaidi@eecs.umich.eduFor more details, see: 965396Ssaidi@eecs.umich.edu http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 975396Ssaidi@eecs.umich.edu""" 985396Ssaidi@eecs.umich.edu raise 995396Ssaidi@eecs.umich.edu 1005396Ssaidi@eecs.umich.edu# Global Python includes 1015396Ssaidi@eecs.umich.eduimport os 1025396Ssaidi@eecs.umich.eduimport re 1035396Ssaidi@eecs.umich.eduimport subprocess 1045396Ssaidi@eecs.umich.eduimport sys 1055396Ssaidi@eecs.umich.edu 1065396Ssaidi@eecs.umich.edufrom os import mkdir, environ 1075396Ssaidi@eecs.umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath 1085396Ssaidi@eecs.umich.edufrom os.path import exists, isdir, isfile 1095396Ssaidi@eecs.umich.edufrom os.path import join as joinpath, split as splitpath 1105396Ssaidi@eecs.umich.edu 1115396Ssaidi@eecs.umich.edu# SCons includes 1125396Ssaidi@eecs.umich.eduimport SCons 1135396Ssaidi@eecs.umich.eduimport SCons.Node 1145396Ssaidi@eecs.umich.edu 1155396Ssaidi@eecs.umich.eduextra_python_paths = [ 1165396Ssaidi@eecs.umich.edu Dir('src/python').srcnode().abspath, # M5 includes 1175396Ssaidi@eecs.umich.edu Dir('ext/ply').srcnode().abspath, # ply is used by several files 1185396Ssaidi@eecs.umich.edu ] 1195396Ssaidi@eecs.umich.edu 1205396Ssaidi@eecs.umich.edusys.path[1:1] = extra_python_paths 1215396Ssaidi@eecs.umich.edu 1225396Ssaidi@eecs.umich.edufrom m5.util import compareVersions, readCommand 1235396Ssaidi@eecs.umich.edu 1245396Ssaidi@eecs.umich.eduAddOption('--colors', dest='use_colors', action='store_true') 1255396Ssaidi@eecs.umich.eduAddOption('--no-colors', dest='use_colors', action='store_false') 1265396Ssaidi@eecs.umich.eduuse_colors = GetOption('use_colors') 1275396Ssaidi@eecs.umich.edu 1285396Ssaidi@eecs.umich.eduif use_colors: 1295396Ssaidi@eecs.umich.edu from m5.util.terminal import termcap 1305396Ssaidi@eecs.umich.eduelif use_colors is None: 1315396Ssaidi@eecs.umich.edu # option unspecified; default behavior is to use colors iff isatty 1325396Ssaidi@eecs.umich.edu from m5.util.terminal import tty_termcap as termcap 1335396Ssaidi@eecs.umich.eduelse: 1345396Ssaidi@eecs.umich.edu from m5.util.terminal import no_termcap as termcap 1355396Ssaidi@eecs.umich.edu 1365396Ssaidi@eecs.umich.edu######################################################################## 1375396Ssaidi@eecs.umich.edu# 1385396Ssaidi@eecs.umich.edu# Set up the main build environment. 1395396Ssaidi@eecs.umich.edu# 1405396Ssaidi@eecs.umich.edu######################################################################## 1415396Ssaidi@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1425396Ssaidi@eecs.umich.edu 'PYTHONPATH', 'RANLIB' ]) 1435396Ssaidi@eecs.umich.edu 1445396Ssaidi@eecs.umich.eduuse_env = {} 1455396Ssaidi@eecs.umich.edufor key,val in os.environ.iteritems(): 1465396Ssaidi@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1474781Snate@binkert.org use_env[key] = val 1481852SN/A 149955SN/Amain = Environment(ENV=use_env) 150955SN/Amain.root = Dir(".") # The current directory (where this file lives). 151955SN/Amain.srcdir = Dir("src") # The source directory 1523717Sstever@eecs.umich.edu 1533716Sstever@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 154955SN/A# as well 1551533SN/Amain.AppendENVPath('PYTHONPATH', extra_python_paths) 1563716Sstever@eecs.umich.edu 1571533SN/A######################################################################## 1584678Snate@binkert.org# 1594678Snate@binkert.org# Mercurial Stuff. 1604678Snate@binkert.org# 1614678Snate@binkert.org# If the M5 directory is a mercurial repository, we should do some 1624678Snate@binkert.org# extra things. 1634678Snate@binkert.org# 1644678Snate@binkert.org######################################################################## 1654678Snate@binkert.org 1664678Snate@binkert.orghgdir = main.root.Dir(".hg") 1674678Snate@binkert.org 1684678Snate@binkert.orgmercurial_style_message = """ 1694678Snate@binkert.orgYou're missing the M5 style hook. 1704678Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style. 1714678Snate@binkert.org 1724678Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc 1734678Snate@binkert.orgor your personal .hgrc 1744678Snate@binkert.org---------------- 1754678Snate@binkert.org 1764678Snate@binkert.org[extensions] 1774678Snate@binkert.orgstyle = %s/util/style.py 1784678Snate@binkert.org 1794973Ssaidi@eecs.umich.edu[hooks] 1804678Snate@binkert.orgpretxncommit.style = python:style.check_style 1814678Snate@binkert.orgpre-qrefresh.style = python:style.check_style 1824678Snate@binkert.org""" % (main.root) 1834678Snate@binkert.org 1844678Snate@binkert.orgmercurial_bin_not_found = """ 1854678Snate@binkert.orgMercurial binary cannot be found, unfortunately this means that we 186955SN/Acannot easily determine the version of M5 that you are running and 187955SN/Athis makes error messages more difficult to collect. Please consider 1882632Sstever@eecs.umich.eduinstalling mercurial if you choose to post an error message 1892632Sstever@eecs.umich.edu""" 190955SN/A 191955SN/Amercurial_lib_not_found = """ 192955SN/AMercurial libraries cannot be found, ignoring style hook 193955SN/AIf you are actually a M5 developer, please fix this and 1942632Sstever@eecs.umich.edurun the style hook. It is important. 195955SN/A""" 1962632Sstever@eecs.umich.edu 1972632Sstever@eecs.umich.eduhg_info = "Unknown" 1982632Sstever@eecs.umich.eduif hgdir.exists(): 1992632Sstever@eecs.umich.edu # 1) Grab repository revision if we know it. 2002632Sstever@eecs.umich.edu cmd = "hg id -n -i -t -b" 2012632Sstever@eecs.umich.edu try: 2022632Sstever@eecs.umich.edu hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 2032632Sstever@eecs.umich.edu except OSError: 2042632Sstever@eecs.umich.edu print mercurial_bin_not_found 2052632Sstever@eecs.umich.edu 2062632Sstever@eecs.umich.edu # 2) Ensure that the style hook is in place. 2072632Sstever@eecs.umich.edu try: 2082632Sstever@eecs.umich.edu ui = None 2093718Sstever@eecs.umich.edu if ARGUMENTS.get('IGNORE_STYLE') != 'True': 2103718Sstever@eecs.umich.edu from mercurial import ui 2113718Sstever@eecs.umich.edu ui = ui.ui() 2123718Sstever@eecs.umich.edu except ImportError: 2133718Sstever@eecs.umich.edu print mercurial_lib_not_found 2143718Sstever@eecs.umich.edu 2153718Sstever@eecs.umich.edu if ui is not None: 2163718Sstever@eecs.umich.edu ui.readconfig(hgdir.File('hgrc').abspath) 2173718Sstever@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) 2183718Sstever@eecs.umich.edu 2193718Sstever@eecs.umich.edu if not style_hook: 2203718Sstever@eecs.umich.edu print mercurial_style_message 2213718Sstever@eecs.umich.edu sys.exit(1) 2222634Sstever@eecs.umich.eduelse: 2232634Sstever@eecs.umich.edu print ".hg directory not found" 2242632Sstever@eecs.umich.edu 2252638Sstever@eecs.umich.edumain['HG_INFO'] = hg_info 2262632Sstever@eecs.umich.edu 2272632Sstever@eecs.umich.edu################################################### 2282632Sstever@eecs.umich.edu# 2292632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2302632Sstever@eecs.umich.edu# the target(s). 2312632Sstever@eecs.umich.edu# 2321858SN/A################################################### 2333716Sstever@eecs.umich.edu 2342638Sstever@eecs.umich.edu# Find default configuration & binary. 2352638Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2362638Sstever@eecs.umich.edu 2372638Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 2382638Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 2392638Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2402638Sstever@eecs.umich.edu if l[i] == elt: 2413716Sstever@eecs.umich.edu return i 2422634Sstever@eecs.umich.edu raise ValueError, "element not found" 2432634Sstever@eecs.umich.edu 244955SN/A# Each target must have 'build' in the interior of the path; the 2455341Sstever@gmail.com# directory below this will determine the build parameters. For 2465341Sstever@gmail.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2475341Sstever@gmail.com# recognize that ALPHA_SE specifies the configuration because it 2485341Sstever@gmail.com# follow 'build' in the bulid path. 249955SN/A 250955SN/A# Generate absolute paths to targets so we can see where the build dir is 251955SN/Aif COMMAND_LINE_TARGETS: 252955SN/A # Ask SCons which directory it was invoked from 253955SN/A launch_dir = GetLaunchDir() 254955SN/A # Make targets relative to invocation directory 255955SN/A abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2561858SN/A COMMAND_LINE_TARGETS] 2571858SN/Aelse: 2582632Sstever@eecs.umich.edu # Default targets are relative to root of tree 259955SN/A abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2604494Ssaidi@eecs.umich.edu DEFAULT_TARGETS] 2614494Ssaidi@eecs.umich.edu 2623716Sstever@eecs.umich.edu 2631105SN/A# Generate a list of the unique build roots and configs that the 2642667Sstever@eecs.umich.edu# collected targets reference. 2652667Sstever@eecs.umich.eduvariant_paths = [] 2662667Sstever@eecs.umich.edubuild_root = None 2672667Sstever@eecs.umich.edufor t in abs_targets: 2682667Sstever@eecs.umich.edu path_dirs = t.split('/') 2692667Sstever@eecs.umich.edu try: 2701869SN/A build_top = rfind(path_dirs, 'build', -2) 2711869SN/A except: 2721869SN/A print "Error: no non-leaf 'build' dir found on target path", t 2731869SN/A Exit(1) 2741869SN/A this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2751065SN/A if not build_root: 2765341Sstever@gmail.com build_root = this_build_root 2775341Sstever@gmail.com else: 2785341Sstever@gmail.com if this_build_root != build_root: 2795341Sstever@gmail.com print "Error: build targets not under same build root\n"\ 2805341Sstever@gmail.com " %s\n %s" % (build_root, this_build_root) 2815341Sstever@gmail.com Exit(1) 2825341Sstever@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 2835341Sstever@gmail.com if variant_path not in variant_paths: 2845341Sstever@gmail.com variant_paths.append(variant_path) 2855341Sstever@gmail.com 2865341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there) 2875341Sstever@gmail.comif not isdir(build_root): 2885341Sstever@gmail.com mkdir(build_root) 2895341Sstever@gmail.commain['BUILDROOT'] = build_root 2905341Sstever@gmail.com 2915341Sstever@gmail.comExport('main') 2925341Sstever@gmail.com 2935341Sstever@gmail.commain.SConsignFile(joinpath(build_root, "sconsign")) 2945341Sstever@gmail.com 2955341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up 2965341Sstever@gmail.com# when you use emacs to edit a file in the target dir, as emacs moves 2975341Sstever@gmail.com# file to file~ then copies to file, breaking the link. Symbolic 2985341Sstever@gmail.com# (soft) links work better. 2995341Sstever@gmail.commain.SetOption('duplicate', 'soft-copy') 3005341Sstever@gmail.com 3015341Sstever@gmail.com# 3025341Sstever@gmail.com# Set up global sticky variables... these are common to an entire build 3035397Ssaidi@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 3045397Ssaidi@eecs.umich.edu# 3055341Sstever@gmail.com 3065341Sstever@gmail.com# Variable validators & converters for global sticky variables 3075341Sstever@gmail.comdef PathListMakeAbsolute(val): 3085341Sstever@gmail.com if not val: 3095341Sstever@gmail.com return val 3105341Sstever@gmail.com f = lambda p: abspath(expanduser(p)) 3115341Sstever@gmail.com return ':'.join(map(f, val.split(':'))) 3125341Sstever@gmail.com 3135341Sstever@gmail.comdef PathListAllExist(key, val, env): 3145341Sstever@gmail.com if not val: 3155341Sstever@gmail.com return 3165341Sstever@gmail.com paths = val.split(':') 3175341Sstever@gmail.com for path in paths: 3185341Sstever@gmail.com if not isdir(path): 3195341Sstever@gmail.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3205341Sstever@gmail.com 3215341Sstever@gmail.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3225341Sstever@gmail.com 3235341Sstever@gmail.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3245341Sstever@gmail.comglobal_nonsticky_vars = Variables(args=ARGUMENTS) 3255341Sstever@gmail.com 3265341Sstever@gmail.comglobal_sticky_vars.AddVariables( 3275742Snate@binkert.org ('CC', 'C compiler', environ.get('CC', main['CC'])), 3285341Sstever@gmail.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3295742Snate@binkert.org ('BATCH', 'Use batch pool for build and tests', False), 3305742Snate@binkert.org ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3315742Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3325341Sstever@gmail.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3335742Snate@binkert.org PathListAllExist, PathListMakeAbsolute), 3345742Snate@binkert.org ) 3355341Sstever@gmail.com 3362632Sstever@eecs.umich.eduglobal_nonsticky_vars.AddVariables( 3375199Sstever@gmail.com ('VERBOSE', 'Print full tool command lines', False), 3384781Snate@binkert.org ('update_ref', 'Update test reference outputs', False) 3394781Snate@binkert.org ) 3405550Snate@binkert.org 3414781Snate@binkert.org 3424781Snate@binkert.org# base help text 3433918Ssaidi@eecs.umich.eduhelp_text = ''' 3444781Snate@binkert.orgUsage: scons [scons options] [build options] [target(s)] 3454781Snate@binkert.org 3463940Ssaidi@eecs.umich.eduGlobal sticky options: 3473942Ssaidi@eecs.umich.edu''' 3483940Ssaidi@eecs.umich.edu 3493918Ssaidi@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3503918Ssaidi@eecs.umich.eduglobal_sticky_vars.Update(main) 351955SN/Aglobal_nonsticky_vars.Update(main) 3521858SN/A 3533918Ssaidi@eecs.umich.eduhelp_text += global_sticky_vars.GenerateHelpText(main) 3543918Ssaidi@eecs.umich.eduhelp_text += global_nonsticky_vars.GenerateHelpText(main) 3553918Ssaidi@eecs.umich.edu 3563918Ssaidi@eecs.umich.edu# Save sticky variable settings back to current variables file 3575571Snate@binkert.orgglobal_sticky_vars.Save(global_sticky_vars_file, main) 3583940Ssaidi@eecs.umich.edu 3593940Ssaidi@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3603918Ssaidi@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3613918Ssaidi@eecs.umich.edubase_dir = main.srcdir.abspath 3623918Ssaidi@eecs.umich.eduif main['EXTRAS']: 3633918Ssaidi@eecs.umich.edu extras_dir_list = main['EXTRAS'].split(':') 3643918Ssaidi@eecs.umich.eduelse: 3653918Ssaidi@eecs.umich.edu extras_dir_list = [] 3663918Ssaidi@eecs.umich.edu 3673918Ssaidi@eecs.umich.eduExport('base_dir') 3683918Ssaidi@eecs.umich.eduExport('extras_dir_list') 3693940Ssaidi@eecs.umich.edu 3703918Ssaidi@eecs.umich.edu# the ext directory should be on the #includes path 3713918Ssaidi@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3725397Ssaidi@eecs.umich.edu 3735397Ssaidi@eecs.umich.edudef strip_build_path(path, env): 3745397Ssaidi@eecs.umich.edu path = str(path) 3755708Ssaidi@eecs.umich.edu variant_base = env['BUILDROOT'] + os.path.sep 3765708Ssaidi@eecs.umich.edu if path.startswith(variant_base): 3775708Ssaidi@eecs.umich.edu path = path[len(variant_base):] 3785708Ssaidi@eecs.umich.edu elif path.startswith('build/'): 3795708Ssaidi@eecs.umich.edu path = path[6:] 3805397Ssaidi@eecs.umich.edu return path 3811851SN/A 3821851SN/A# Generate a string of the form: 3831858SN/A# common/path/prefix/src1, src2 -> tgt1, tgt2 3845200Sstever@gmail.com# to print while building. 385955SN/Aclass Transform(object): 3863053Sstever@eecs.umich.edu # all specific color settings should be here and nowhere else 3873053Sstever@eecs.umich.edu tool_color = termcap.Normal 3883053Sstever@eecs.umich.edu pfx_color = termcap.Yellow 3893053Sstever@eecs.umich.edu srcs_color = termcap.Yellow + termcap.Bold 3903053Sstever@eecs.umich.edu arrow_color = termcap.Blue + termcap.Bold 3913053Sstever@eecs.umich.edu tgts_color = termcap.Yellow + termcap.Bold 3923053Sstever@eecs.umich.edu 3933053Sstever@eecs.umich.edu def __init__(self, tool, max_sources=99): 3943053Sstever@eecs.umich.edu self.format = self.tool_color + (" [%8s] " % tool) \ 3954742Sstever@eecs.umich.edu + self.pfx_color + "%s" \ 3964742Sstever@eecs.umich.edu + self.srcs_color + "%s" \ 3973053Sstever@eecs.umich.edu + self.arrow_color + " -> " \ 3983053Sstever@eecs.umich.edu + self.tgts_color + "%s" \ 3993053Sstever@eecs.umich.edu + termcap.Normal 4003053Sstever@eecs.umich.edu self.max_sources = max_sources 4013053Sstever@eecs.umich.edu 4023053Sstever@eecs.umich.edu def __call__(self, target, source, env, for_signature=None): 4033053Sstever@eecs.umich.edu # truncate source list according to max_sources param 4043053Sstever@eecs.umich.edu source = source[0:self.max_sources] 4053053Sstever@eecs.umich.edu def strip(f): 4062667Sstever@eecs.umich.edu return strip_build_path(str(f), env) 4074554Sbinkertn@umich.edu if len(source) > 0: 4084554Sbinkertn@umich.edu srcs = map(strip, source) 4092667Sstever@eecs.umich.edu else: 4104554Sbinkertn@umich.edu srcs = [''] 4114554Sbinkertn@umich.edu tgts = map(strip, target) 4124554Sbinkertn@umich.edu # surprisingly, os.path.commonprefix is a dumb char-by-char string 4134554Sbinkertn@umich.edu # operation that has nothing to do with paths. 4144554Sbinkertn@umich.edu com_pfx = os.path.commonprefix(srcs + tgts) 4154554Sbinkertn@umich.edu com_pfx_len = len(com_pfx) 4164554Sbinkertn@umich.edu if com_pfx: 4174781Snate@binkert.org # do some cleanup and sanity checking on common prefix 4184554Sbinkertn@umich.edu if com_pfx[-1] == ".": 4194554Sbinkertn@umich.edu # prefix matches all but file extension: ok 4202667Sstever@eecs.umich.edu # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4214554Sbinkertn@umich.edu com_pfx = com_pfx[0:-1] 4224554Sbinkertn@umich.edu elif com_pfx[-1] == "/": 4234554Sbinkertn@umich.edu # common prefix is directory path: OK 4244554Sbinkertn@umich.edu pass 4252667Sstever@eecs.umich.edu else: 4264554Sbinkertn@umich.edu src0_len = len(srcs[0]) 4272667Sstever@eecs.umich.edu tgt0_len = len(tgts[0]) 4284554Sbinkertn@umich.edu if src0_len == com_pfx_len: 4294554Sbinkertn@umich.edu # source is a substring of target, OK 4302667Sstever@eecs.umich.edu pass 4315522Snate@binkert.org elif tgt0_len == com_pfx_len: 4325522Snate@binkert.org # target is a substring of source, need to back up to 4335522Snate@binkert.org # avoid empty string on RHS of arrow 4345522Snate@binkert.org sep_idx = com_pfx.rfind(".") 4355522Snate@binkert.org if sep_idx != -1: 4365522Snate@binkert.org com_pfx = com_pfx[0:sep_idx] 4375522Snate@binkert.org else: 4385522Snate@binkert.org com_pfx = '' 4395522Snate@binkert.org elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4405522Snate@binkert.org # still splitting at file extension: ok 4415522Snate@binkert.org pass 4425522Snate@binkert.org else: 4435522Snate@binkert.org # probably a fluke; ignore it 4445522Snate@binkert.org com_pfx = '' 4455522Snate@binkert.org # recalculate length in case com_pfx was modified 4465522Snate@binkert.org com_pfx_len = len(com_pfx) 4475522Snate@binkert.org def fmt(files): 4485522Snate@binkert.org f = map(lambda s: s[com_pfx_len:], files) 4495522Snate@binkert.org return ', '.join(f) 4505522Snate@binkert.org return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4515522Snate@binkert.org 4525522Snate@binkert.orgExport('Transform') 4535522Snate@binkert.org 4545522Snate@binkert.org 4555522Snate@binkert.orgif main['VERBOSE']: 4565522Snate@binkert.org def MakeAction(action, string, *args, **kwargs): 4572638Sstever@eecs.umich.edu return Action(action, *args, **kwargs) 4582638Sstever@eecs.umich.eduelse: 4592638Sstever@eecs.umich.edu MakeAction = Action 4603716Sstever@eecs.umich.edu main['CCCOMSTR'] = Transform("CC") 4615522Snate@binkert.org main['CXXCOMSTR'] = Transform("CXX") 4625522Snate@binkert.org main['ASCOMSTR'] = Transform("AS") 4635522Snate@binkert.org main['SWIGCOMSTR'] = Transform("SWIG") 4645522Snate@binkert.org main['ARCOMSTR'] = Transform("AR", 0) 4655522Snate@binkert.org main['LINKCOMSTR'] = Transform("LINK", 0) 4665522Snate@binkert.org main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4671858SN/A main['M4COMSTR'] = Transform("M4") 4685227Ssaidi@eecs.umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 4695227Ssaidi@eecs.umich.edu main['SHCXXCOMSTR'] = Transform("SHCXX") 4705227Ssaidi@eecs.umich.eduExport('MakeAction') 4715227Ssaidi@eecs.umich.edu 4725227Ssaidi@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4735227Ssaidi@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 4745227Ssaidi@eecs.umich.edu 4755227Ssaidi@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4765227Ssaidi@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4775227Ssaidi@eecs.umich.edumain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4785227Ssaidi@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 4795227Ssaidi@eecs.umich.edu print 'Error: How can we have two at the same time?' 4805227Ssaidi@eecs.umich.edu Exit(1) 4815227Ssaidi@eecs.umich.edu 4825227Ssaidi@eecs.umich.edu# Set up default C++ compiler flags 4835204Sstever@gmail.comif main['GCC']: 4845204Sstever@gmail.com main.Append(CCFLAGS=['-pipe']) 4855204Sstever@gmail.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 4865204Sstever@gmail.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4875204Sstever@gmail.com main.Append(CXXFLAGS=['-Wno-deprecated']) 4885204Sstever@gmail.com # Read the GCC version to check for versions with bugs 4895204Sstever@gmail.com # Note CCVERSION doesn't work here because it is run with the CC 4905204Sstever@gmail.com # before we override it from the command line 4915204Sstever@gmail.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4925204Sstever@gmail.com if not compareVersions(gcc_version, '4.4.1') or \ 4935204Sstever@gmail.com not compareVersions(gcc_version, '4.4.2'): 4945204Sstever@gmail.com print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 4955204Sstever@gmail.com main.Append(CCFLAGS=['-fno-tree-vectorize']) 4965204Sstever@gmail.comelif main['ICC']: 4975204Sstever@gmail.com pass #Fix me... add warning flags once we clean up icc warnings 4985204Sstever@gmail.comelif main['SUNCC']: 4995204Sstever@gmail.com main.Append(CCFLAGS=['-Qoption ccfe']) 5005204Sstever@gmail.com main.Append(CCFLAGS=['-features=gcc']) 5015204Sstever@gmail.com main.Append(CCFLAGS=['-features=extensions']) 5023118Sstever@eecs.umich.edu main.Append(CCFLAGS=['-library=stlport4']) 5033118Sstever@eecs.umich.edu main.Append(CCFLAGS=['-xar']) 5043118Sstever@eecs.umich.edu #main.Append(CCFLAGS=['-instances=semiexplicit']) 5053118Sstever@eecs.umich.eduelse: 5063118Sstever@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 5073118Sstever@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 5083118Sstever@eecs.umich.edu Exit(1) 5093118Sstever@eecs.umich.edu 5103118Sstever@eecs.umich.edu# Set up common yacc/bison flags (needed for Ruby) 5113118Sstever@eecs.umich.edumain['YACCFLAGS'] = '-d' 5123118Sstever@eecs.umich.edumain['YACCHXXFILESUFFIX'] = '.hh' 5133716Sstever@eecs.umich.edu 5143118Sstever@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 5153118Sstever@eecs.umich.edu# extra 'qdo' every time we run scons. 5163118Sstever@eecs.umich.eduif main['BATCH']: 5173118Sstever@eecs.umich.edu main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5183118Sstever@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5193118Sstever@eecs.umich.edu main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5203118Sstever@eecs.umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5213118Sstever@eecs.umich.edu main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5223118Sstever@eecs.umich.edu 5233716Sstever@eecs.umich.eduif sys.platform == 'cygwin': 5243118Sstever@eecs.umich.edu # cygwin has some header file issues... 5253118Sstever@eecs.umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 5263118Sstever@eecs.umich.edu 5273118Sstever@eecs.umich.edu# Check for SWIG 5283118Sstever@eecs.umich.eduif not main.has_key('SWIG'): 5293118Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 5303118Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 5313118Sstever@eecs.umich.edu Exit(1) 5323118Sstever@eecs.umich.edu 5333118Sstever@eecs.umich.edu# Check for appropriate SWIG version 5343483Ssaidi@eecs.umich.eduswig_version = readCommand(('swig', '-version'), exception='').split() 5353494Ssaidi@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 5363494Ssaidi@eecs.umich.eduif len(swig_version) < 3 or \ 5373483Ssaidi@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5383483Ssaidi@eecs.umich.edu print 'Error determining SWIG version.' 5393483Ssaidi@eecs.umich.edu Exit(1) 5403053Sstever@eecs.umich.edu 5413053Sstever@eecs.umich.edumin_swig_version = '1.3.28' 5423918Ssaidi@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0: 5433053Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 5443053Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 5453053Sstever@eecs.umich.edu Exit(1) 5463053Sstever@eecs.umich.edu 5473053Sstever@eecs.umich.edu# Set up SWIG flags & scanner 5481858SN/Aswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5491858SN/Amain.Append(SWIGFLAGS=swig_flags) 5501858SN/A 5511858SN/A# filter out all existing swig scanners, they mess up the dependency 5521858SN/A# stuff for some reason 5531858SN/Ascanners = [] 5541859SN/Afor scanner in main['SCANNERS']: 5551858SN/A skeys = scanner.skeys 5561858SN/A if skeys == '.i': 5571858SN/A continue 5581859SN/A 5591859SN/A if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5601862SN/A continue 5613053Sstever@eecs.umich.edu 5623053Sstever@eecs.umich.edu scanners.append(scanner) 5633053Sstever@eecs.umich.edu 5643053Sstever@eecs.umich.edu# add the new swig scanner that we like better 5651859SN/Afrom SCons.Scanner import ClassicCPP as CPPScanner 5661859SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 5671859SN/Ascanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 5681859SN/A 5691859SN/A# replace the scanners list that has what we want 5701859SN/Amain['SCANNERS'] = scanners 5711859SN/A 5721859SN/A# Add a custom Check function to the Configure context so that we can 5731862SN/A# figure out if the compiler adds leading underscores to global 5741859SN/A# variables. This is needed for the autogenerated asm files that we 5751859SN/A# use for embedding the python code. 5761859SN/Adef CheckLeading(context): 5771858SN/A context.Message("Checking for leading underscore in global variables...") 5781858SN/A # 1) Define a global variable called x from asm so the C compiler 5792139SN/A # won't change the symbol at all. 5804202Sbinkertn@umich.edu # 2) Declare that variable. 5814202Sbinkertn@umich.edu # 3) Use the variable 5822139SN/A # 5832155SN/A # If the compiler prepends an underscore, this will successfully 5844202Sbinkertn@umich.edu # link because the external symbol 'x' will be called '_x' which 5854202Sbinkertn@umich.edu # was defined by the asm statement. If the compiler does not 5864202Sbinkertn@umich.edu # prepend an underscore, this will not successfully link because 5872155SN/A # '_x' will have been defined by assembly, while the C portion of 5881869SN/A # the code will be trying to use 'x' 5891869SN/A ret = context.TryLink(''' 5901869SN/A asm(".globl _x; _x: .byte 0"); 5911869SN/A extern int x; 5924202Sbinkertn@umich.edu int main() { return x; } 5934202Sbinkertn@umich.edu ''', extension=".c") 5944202Sbinkertn@umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 5954202Sbinkertn@umich.edu context.Result(ret) 5964202Sbinkertn@umich.edu return ret 5974202Sbinkertn@umich.edu 5984202Sbinkertn@umich.edu# Platform-specific configuration. Note again that we assume that all 5994202Sbinkertn@umich.edu# builds under a given build root run on the same host platform. 6005742Snate@binkert.orgconf = Configure(main, 6015742Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 6025341Sstever@gmail.com log_file = joinpath(build_root, 'scons_config.log'), 6035342Sstever@gmail.com custom_tests = { 'CheckLeading' : CheckLeading }) 6045342Sstever@gmail.com 6054202Sbinkertn@umich.edu# Check for leading underscores. Don't really need to worry either 6064202Sbinkertn@umich.edu# way so don't need to check the return code. 6074202Sbinkertn@umich.educonf.CheckLeading() 6084202Sbinkertn@umich.edu 6094202Sbinkertn@umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6101869SN/Atry: 6114202Sbinkertn@umich.edu import platform 6121869SN/A uname = platform.uname() 6132508SN/A if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6142508SN/A if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6152508SN/A main.Append(CCFLAGS=['-arch', 'x86_64']) 6162508SN/A main.Append(CFLAGS=['-arch', 'x86_64']) 6174202Sbinkertn@umich.edu main.Append(LINKFLAGS=['-arch', 'x86_64']) 6181869SN/A main.Append(ASFLAGS=['-arch', 'x86_64']) 6195385Sstever@gmail.comexcept: 6205385Sstever@gmail.com pass 6215385Sstever@gmail.com 6225385Sstever@gmail.com# Recent versions of scons substitute a "Null" object for Configure() 6231869SN/A# when configuration isn't necessary, e.g., if the "--help" option is 6241869SN/A# present. Unfortuantely this Null object always returns false, 6251869SN/A# breaking all our configuration checks. We replace it with our own 6261869SN/A# more optimistic null object that returns True instead. 6271869SN/Aif not conf: 6281965SN/A def NullCheck(*args, **kwargs): 6291965SN/A return True 6301965SN/A 6311869SN/A class NullConf: 6321869SN/A def __init__(self, env): 6332733Sktlim@umich.edu self.env = env 6341869SN/A def Finish(self): 6351858SN/A return self.env 6361869SN/A def __getattr__(self, mname): 6371869SN/A return NullCheck 6381869SN/A 6391858SN/A conf = NullConf(main) 6402761Sstever@eecs.umich.edu 6411869SN/A# Find Python include and library directories for embedding the 6425385Sstever@gmail.com# interpreter. For consistency, we will use the same Python 6435385Sstever@gmail.com# installation used to run scons (and thus this script). If you want 6445522Snate@binkert.org# to link in an alternate version, see above for instructions on how 6451869SN/A# to invoke scons with a different copy of the Python interpreter. 6461869SN/Afrom distutils import sysconfig 6471869SN/A 6481869SN/Apy_getvar = sysconfig.get_config_var 6491869SN/A 6501869SN/Apy_debug = getattr(sys, 'pydebug', False) 6511858SN/Apy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 652955SN/A 653955SN/Apy_general_include = sysconfig.get_python_inc() 6541869SN/Apy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6551869SN/Apy_includes = [ py_general_include ] 6561869SN/Aif py_platform_include != py_general_include: 6571869SN/A py_includes.append(py_platform_include) 6581869SN/A 6591869SN/Apy_lib_path = [ py_getvar('LIBDIR') ] 6601869SN/A# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6611869SN/A# shared library in prefix/lib/. 6621869SN/Aif not py_getvar('Py_ENABLE_SHARED'): 6631869SN/A py_lib_path.append(py_getvar('LIBPL')) 6641869SN/A 6651869SN/Apy_libs = [] 6661869SN/Afor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 6671869SN/A assert lib.startswith('-l') 6681869SN/A lib = lib[2:] 6691869SN/A if lib not in py_libs: 6701869SN/A py_libs.append(lib) 6711869SN/Apy_libs.append(py_version) 6721869SN/A 6731869SN/Amain.Append(CPPPATH=py_includes) 6741869SN/Amain.Append(LIBPATH=py_lib_path) 6751869SN/A 6761869SN/A# Cache build files in the supplied directory. 6771869SN/Aif main['M5_BUILD_CACHE']: 6781869SN/A print 'Using build cache located at', main['M5_BUILD_CACHE'] 6791869SN/A CacheDir(main['M5_BUILD_CACHE']) 6801869SN/A 6811869SN/A 6821869SN/A# verify that this stuff works 6833716Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 6843356Sbinkertn@umich.edu print "Error: can't find Python.h header in", py_includes 6853356Sbinkertn@umich.edu Exit(1) 6863356Sbinkertn@umich.edu 6873356Sbinkertn@umich.edufor lib in py_libs: 6883356Sbinkertn@umich.edu if not conf.CheckLib(lib): 6893356Sbinkertn@umich.edu print "Error: can't find library %s required by python" % lib 6904781Snate@binkert.org Exit(1) 6911869SN/A 6921869SN/A# On Solaris you need to use libsocket for socket ops 6931869SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6941869SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6951869SN/A print "Can't find library with socket calls (e.g. accept())" 6961869SN/A Exit(1) 6971869SN/A 6982655Sstever@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 6992655Sstever@eecs.umich.edu# added to the LIBS environment variable. 7002655Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7012655Sstever@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 7022655Sstever@eecs.umich.edu 'and/or zlib.h header file.' 7032655Sstever@eecs.umich.edu print ' Please install zlib and try again.' 7042655Sstever@eecs.umich.edu Exit(1) 7052655Sstever@eecs.umich.edu 7062655Sstever@eecs.umich.edu# Check for librt. 7072655Sstever@eecs.umich.eduhave_posix_clock = conf.CheckLib(None, 'clock_nanosleep', 'time.h') or \ 7082655Sstever@eecs.umich.edu conf.CheckLib('rt', 'clock_nanosleep', 'time.h') 7092655Sstever@eecs.umich.edu 7102655Sstever@eecs.umich.eduif not have_posix_clock: 7112655Sstever@eecs.umich.edu print "Can't find library for POSIX clocks." 7122655Sstever@eecs.umich.edu 7132655Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 7142655Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 7152655Sstever@eecs.umich.eduif not have_fenv: 7162655Sstever@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 7172655Sstever@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 7182655Sstever@eecs.umich.edu 7192655Sstever@eecs.umich.edu###################################################################### 7202655Sstever@eecs.umich.edu# 7212655Sstever@eecs.umich.edu# Check for mysql. 7222655Sstever@eecs.umich.edu# 7232655Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config') 7242638Sstever@eecs.umich.eduhave_mysql = bool(mysql_config) 7252638Sstever@eecs.umich.edu 7263716Sstever@eecs.umich.edu# Check MySQL version. 7272638Sstever@eecs.umich.eduif have_mysql: 7282638Sstever@eecs.umich.edu mysql_version = readCommand(mysql_config + ' --version') 7291869SN/A min_mysql_version = '4.1' 7301869SN/A if compareVersions(mysql_version, min_mysql_version) < 0: 7313546Sgblack@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 7323546Sgblack@eecs.umich.edu print ' Version', mysql_version, 'detected.' 7333546Sgblack@eecs.umich.edu have_mysql = False 7343546Sgblack@eecs.umich.edu 7354202Sbinkertn@umich.edu# Set up mysql_config commands. 7363546Sgblack@eecs.umich.eduif have_mysql: 7373546Sgblack@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 7383546Sgblack@eecs.umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 7393546Sgblack@eecs.umich.edu # older mysql_config versions don't support --include, use 7403546Sgblack@eecs.umich.edu # --cflags instead 7414781Snate@binkert.org mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 7424781Snate@binkert.org # This seems to work in all versions 7434781Snate@binkert.org mysql_config_libs = mysql_config + ' --libs' 7444781Snate@binkert.org 7454781Snate@binkert.org###################################################################### 7464781Snate@binkert.org# 7474781Snate@binkert.org# Finish the configuration 7484781Snate@binkert.org# 7494781Snate@binkert.orgmain = conf.Finish() 7504781Snate@binkert.org 7514781Snate@binkert.org###################################################################### 7524781Snate@binkert.org# 7533546Sgblack@eecs.umich.edu# Collect all non-global variables 7543546Sgblack@eecs.umich.edu# 7553546Sgblack@eecs.umich.edu 7564781Snate@binkert.org# Define the universe of supported ISAs 7573546Sgblack@eecs.umich.eduall_isa_list = [ ] 7583546Sgblack@eecs.umich.eduExport('all_isa_list') 7593546Sgblack@eecs.umich.edu 7603546Sgblack@eecs.umich.educlass CpuModel(object): 7613546Sgblack@eecs.umich.edu '''The CpuModel class encapsulates everything the ISA parser needs to 7623546Sgblack@eecs.umich.edu know about a particular CPU model.''' 7633546Sgblack@eecs.umich.edu 7643546Sgblack@eecs.umich.edu # Dict of available CPU model objects. Accessible as CpuModel.dict. 7653546Sgblack@eecs.umich.edu dict = {} 7663546Sgblack@eecs.umich.edu list = [] 7674202Sbinkertn@umich.edu defaults = [] 7683546Sgblack@eecs.umich.edu 7693546Sgblack@eecs.umich.edu # Constructor. Automatically adds models to CpuModel.dict. 7703546Sgblack@eecs.umich.edu def __init__(self, name, filename, includes, strings, default=False): 771955SN/A self.name = name # name of model 772955SN/A self.filename = filename # filename for output exec code 773955SN/A self.includes = includes # include files needed in exec file 774955SN/A # The 'strings' dict holds all the per-CPU symbols we can 7751858SN/A # substitute into templates etc. 7761858SN/A self.strings = strings 7771858SN/A 7782632Sstever@eecs.umich.edu # This cpu is enabled by default 7792632Sstever@eecs.umich.edu self.default = default 7805343Sstever@gmail.com 7815343Sstever@gmail.com # Add self to dict 7825343Sstever@gmail.com if name in CpuModel.dict: 7834773Snate@binkert.org raise AttributeError, "CpuModel '%s' already registered" % name 7844773Snate@binkert.org CpuModel.dict[name] = self 7852632Sstever@eecs.umich.edu CpuModel.list.append(name) 7862632Sstever@eecs.umich.edu 7872632Sstever@eecs.umich.eduExport('CpuModel') 7882023SN/A 7892632Sstever@eecs.umich.edu# Sticky variables get saved in the variables file so they persist from 7902632Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 7912632Sstever@eecs.umich.edu# value becomes sticky). 7922632Sstever@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS) 7932632Sstever@eecs.umich.eduExport('sticky_vars') 7943716Sstever@eecs.umich.edu 7955342Sstever@gmail.com# Sticky variables that should be exported 7962632Sstever@eecs.umich.eduexport_vars = [] 7972632Sstever@eecs.umich.eduExport('export_vars') 7982632Sstever@eecs.umich.edu 7992632Sstever@eecs.umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 8002023SN/A# above variables 8012632Sstever@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list: 8022632Sstever@eecs.umich.edu for root, dirs, files in os.walk(bdir): 8035342Sstever@gmail.com if 'SConsopts' in files: 8041889SN/A print "Reading", joinpath(root, 'SConsopts') 8052632Sstever@eecs.umich.edu SConscript(joinpath(root, 'SConsopts')) 8062632Sstever@eecs.umich.edu 8072632Sstever@eecs.umich.eduall_isa_list.sort() 8082632Sstever@eecs.umich.edu 8093716Sstever@eecs.umich.edusticky_vars.AddVariables( 8103716Sstever@eecs.umich.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 8115342Sstever@gmail.com BoolVariable('FULL_SYSTEM', 'Full-system support', False), 8122632Sstever@eecs.umich.edu ListVariable('CPU_MODELS', 'CPU models', 8132632Sstever@eecs.umich.edu sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 8142632Sstever@eecs.umich.edu sorted(CpuModel.list)), 8152632Sstever@eecs.umich.edu BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 8162632Sstever@eecs.umich.edu BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 8172632Sstever@eecs.umich.edu False), 8182632Sstever@eecs.umich.edu BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 8191888SN/A False), 8201888SN/A BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 8211869SN/A False), 8221869SN/A BoolVariable('SS_COMPATIBLE_FP', 8231858SN/A 'Make floating-point results compatible with SimpleScalar', 8245341Sstever@gmail.com False), 8252598SN/A BoolVariable('USE_SSE2', 8262598SN/A 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 8272598SN/A False), 8282598SN/A BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 8291858SN/A BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 8301858SN/A BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 8311858SN/A BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 8321858SN/A BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 8331858SN/A BoolVariable('RUBY', 'Build with Ruby', False), 8341858SN/A ) 8351858SN/A 8361858SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript). 8371858SN/Aexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 8381871SN/A 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 8391858SN/A 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE', 8401858SN/A 'USE_POSIX_CLOCK' ] 8411858SN/A 8421858SN/A################################################### 8431858SN/A# 8441858SN/A# Define a SCons builder for configuration flag headers. 8451858SN/A# 8461858SN/A################################################### 8471858SN/A 8481858SN/A# This function generates a config header file that #defines the 8491858SN/A# variable symbol to the current variable setting (0 or 1). The source 8501859SN/A# operands are the name of the variable and a Value node containing the 8511859SN/A# value of the variable. 8521869SN/Adef build_config_file(target, source, env): 8531888SN/A (variable, value) = [s.get_contents() for s in source] 8542632Sstever@eecs.umich.edu f = file(str(target[0]), 'w') 8551869SN/A print >> f, '#define', variable, value 8561965SN/A f.close() 8571965SN/A return None 8581965SN/A 8592761Sstever@eecs.umich.edu# Generate the message to be printed when building the config file. 8601869SN/Adef build_config_file_string(target, source, env): 8611869SN/A (variable, value) = [s.get_contents() for s in source] 8622632Sstever@eecs.umich.edu return "Defining %s as %s in %s." % (variable, value, target[0]) 8632667Sstever@eecs.umich.edu 8641869SN/A# Combine the two functions into a scons Action object. 8651869SN/Aconfig_action = Action(build_config_file, build_config_file_string) 8662929Sktlim@umich.edu 8672929Sktlim@umich.edu# The emitter munges the source & target node lists to reflect what 8683716Sstever@eecs.umich.edu# we're really doing. 8692929Sktlim@umich.edudef config_emitter(target, source, env): 870955SN/A # extract variable name from Builder arg 8712598SN/A variable = str(target[0]) 8722598SN/A # True target is config header file 8733546Sgblack@eecs.umich.edu target = joinpath('config', variable.lower() + '.hh') 874955SN/A val = env[variable] 875955SN/A if isinstance(val, bool): 876955SN/A # Force value to 0/1 8771530SN/A val = int(val) 878955SN/A elif isinstance(val, str): 879955SN/A val = '"' + val + '"' 880955SN/A 881 # Sources are variable name & value (packaged in SCons Value nodes) 882 return ([target], [Value(variable), Value(val)]) 883 884config_builder = Builder(emitter = config_emitter, action = config_action) 885 886main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 887 888# libelf build is shared across all configs in the build root. 889main.SConscript('ext/libelf/SConscript', 890 variant_dir = joinpath(build_root, 'libelf')) 891 892# gzstream build is shared across all configs in the build root. 893main.SConscript('ext/gzstream/SConscript', 894 variant_dir = joinpath(build_root, 'gzstream')) 895 896################################################### 897# 898# This function is used to set up a directory with switching headers 899# 900################################################### 901 902main['ALL_ISA_LIST'] = all_isa_list 903def make_switching_dir(dname, switch_headers, env): 904 # Generate the header. target[0] is the full path of the output 905 # header to generate. 'source' is a dummy variable, since we get the 906 # list of ISAs from env['ALL_ISA_LIST']. 907 def gen_switch_hdr(target, source, env): 908 fname = str(target[0]) 909 f = open(fname, 'w') 910 isa = env['TARGET_ISA'].lower() 911 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 912 f.close() 913 914 # Build SCons Action object. 'varlist' specifies env vars that this 915 # action depends on; when env['ALL_ISA_LIST'] changes these actions 916 # should get re-executed. 917 switch_hdr_action = MakeAction(gen_switch_hdr, 918 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 919 920 # Instantiate actions for each header 921 for hdr in switch_headers: 922 env.Command(hdr, [], switch_hdr_action) 923Export('make_switching_dir') 924 925################################################### 926# 927# Define build environments for selected configurations. 928# 929################################################### 930 931for variant_path in variant_paths: 932 print "Building in", variant_path 933 934 # Make a copy of the build-root environment to use for this config. 935 env = main.Clone() 936 env['BUILDDIR'] = variant_path 937 938 # variant_dir is the tail component of build path, and is used to 939 # determine the build parameters (e.g., 'ALPHA_SE') 940 (build_root, variant_dir) = splitpath(variant_path) 941 942 # Set env variables according to the build directory config. 943 sticky_vars.files = [] 944 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 945 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 946 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 947 current_vars_file = joinpath(build_root, 'variables', variant_dir) 948 if isfile(current_vars_file): 949 sticky_vars.files.append(current_vars_file) 950 print "Using saved variables file %s" % current_vars_file 951 else: 952 # Build dir-specific variables file doesn't exist. 953 954 # Make sure the directory is there so we can create it later 955 opt_dir = dirname(current_vars_file) 956 if not isdir(opt_dir): 957 mkdir(opt_dir) 958 959 # Get default build variables from source tree. Variables are 960 # normally determined by name of $VARIANT_DIR, but can be 961 # overriden by 'default=' arg on command line. 962 default_vars_file = joinpath('build_opts', 963 ARGUMENTS.get('default', variant_dir)) 964 if isfile(default_vars_file): 965 sticky_vars.files.append(default_vars_file) 966 print "Variables file %s not found,\n using defaults in %s" \ 967 % (current_vars_file, default_vars_file) 968 else: 969 print "Error: cannot find variables file %s or %s" \ 970 % (current_vars_file, default_vars_file) 971 Exit(1) 972 973 # Apply current variable settings to env 974 sticky_vars.Update(env) 975 976 help_text += "\nSticky variables for %s:\n" % variant_dir \ 977 + sticky_vars.GenerateHelpText(env) 978 979 # Process variable settings. 980 981 if not have_fenv and env['USE_FENV']: 982 print "Warning: <fenv.h> not available; " \ 983 "forcing USE_FENV to False in", variant_dir + "." 984 env['USE_FENV'] = False 985 986 if not env['USE_FENV']: 987 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 988 print " FP results may deviate slightly from other platforms." 989 990 if env['EFENCE']: 991 env.Append(LIBS=['efence']) 992 993 if env['USE_MYSQL']: 994 if not have_mysql: 995 print "Warning: MySQL not available; " \ 996 "forcing USE_MYSQL to False in", variant_dir + "." 997 env['USE_MYSQL'] = False 998 else: 999 print "Compiling in", variant_dir, "with MySQL support." 1000 env.ParseConfig(mysql_config_libs) 1001 env.ParseConfig(mysql_config_include) 1002 1003 # Save sticky variable settings back to current variables file 1004 sticky_vars.Save(current_vars_file, env) 1005 1006 if env['USE_SSE2']: 1007 env.Append(CCFLAGS=['-msse2']) 1008 1009 # The src/SConscript file sets up the build rules in 'env' according 1010 # to the configured variables. It returns a list of environments, 1011 # one for each variant build (debug, opt, etc.) 1012 envList = SConscript('src/SConscript', variant_dir = variant_path, 1013 exports = 'env') 1014 1015 # Set up the regression tests for each build. 1016 for e in envList: 1017 SConscript('tests/SConscript', 1018 variant_dir = joinpath(variant_path, 'tests', e.Label), 1019 exports = { 'env' : e }, duplicate = False) 1020 1021Help(help_text) 1022