SConstruct revision 9044
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 ('gem5'), 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/gem5.opt' for 412632Sstever@eecs.umich.edu# the optimized full-system version). 422761Sstever@eecs.umich.edu# 432632Sstever@eecs.umich.edu# You can build gem5 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>/gem5 ; scons build/ALPHA/gem5.debug 532761Sstever@eecs.umich.edu# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.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>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 602632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.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# 'gem5' 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 gem5-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://gem5.org/Dependencies 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://gem5.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, # gem5 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.edufrom m5.util.terminal import get_termcap 1245396Ssaidi@eecs.umich.edu 1255396Ssaidi@eecs.umich.eduhelp_texts = { 1265396Ssaidi@eecs.umich.edu "options" : "", 1275396Ssaidi@eecs.umich.edu "global_vars" : "", 1285396Ssaidi@eecs.umich.edu "local_vars" : "" 1295396Ssaidi@eecs.umich.edu} 1305396Ssaidi@eecs.umich.edu 1315396Ssaidi@eecs.umich.eduExport("help_texts") 1325396Ssaidi@eecs.umich.edu 1335396Ssaidi@eecs.umich.edu 1345396Ssaidi@eecs.umich.edu# There's a bug in scons in that (1) by default, the help texts from 1355396Ssaidi@eecs.umich.edu# AddOption() are supposed to be displayed when you type 'scons -h' 1365396Ssaidi@eecs.umich.edu# and (2) you can override the help displayed by 'scons -h' using the 1375396Ssaidi@eecs.umich.edu# Help() function, but these two features are incompatible: once 1385396Ssaidi@eecs.umich.edu# you've overridden the help text using Help(), there's no way to get 1395396Ssaidi@eecs.umich.edu# at the help texts from AddOptions. See: 1405396Ssaidi@eecs.umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1415396Ssaidi@eecs.umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1425396Ssaidi@eecs.umich.edu# This hack lets us extract the help text from AddOptions and 1435396Ssaidi@eecs.umich.edu# re-inject it via Help(). Ideally someday this bug will be fixed and 1445396Ssaidi@eecs.umich.edu# we can just use AddOption directly. 1455396Ssaidi@eecs.umich.edudef AddLocalOption(*args, **kwargs): 1465396Ssaidi@eecs.umich.edu col_width = 30 1474781Snate@binkert.org 1481852SN/A help = " " + ", ".join(args) 149955SN/A if "help" in kwargs: 150955SN/A length = len(help) 151955SN/A if length >= col_width: 1523717Sstever@eecs.umich.edu help += "\n" + " " * col_width 1533716Sstever@eecs.umich.edu else: 154955SN/A help += " " * (col_width - length) 1551533SN/A help += kwargs["help"] 1563716Sstever@eecs.umich.edu help_texts["options"] += help + "\n" 1571533SN/A 1584678Snate@binkert.org AddOption(*args, **kwargs) 1594678Snate@binkert.org 1604678Snate@binkert.orgAddLocalOption('--colors', dest='use_colors', action='store_true', 1614678Snate@binkert.org help="Add color to abbreviated scons output") 1624678Snate@binkert.orgAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1634678Snate@binkert.org help="Don't add color to abbreviated scons output") 1644678Snate@binkert.orgAddLocalOption('--default', dest='default', type='string', action='store', 1654678Snate@binkert.org help='Override which build_opts file to use for defaults') 1664678Snate@binkert.orgAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1674678Snate@binkert.org help='Disable style checking hooks') 1684678Snate@binkert.orgAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1694678Snate@binkert.org help='Update test reference outputs') 1704678Snate@binkert.orgAddLocalOption('--verbose', dest='verbose', action='store_true', 1714678Snate@binkert.org help='Print full tool command lines') 1724678Snate@binkert.org 1734678Snate@binkert.orgtermcap = get_termcap(GetOption('use_colors')) 1744678Snate@binkert.org 1754678Snate@binkert.org######################################################################## 1764678Snate@binkert.org# 1774678Snate@binkert.org# Set up the main build environment. 1784678Snate@binkert.org# 1794973Ssaidi@eecs.umich.edu######################################################################## 1804678Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1814678Snate@binkert.org 'PYTHONPATH', 'RANLIB', 'SWIG' ]) 1824678Snate@binkert.org 1834678Snate@binkert.orguse_env = {} 1844678Snate@binkert.orgfor key,val in os.environ.iteritems(): 1854678Snate@binkert.org if key in use_vars or key.startswith("M5"): 186955SN/A use_env[key] = val 187955SN/A 1882632Sstever@eecs.umich.edumain = Environment(ENV=use_env) 1892632Sstever@eecs.umich.edumain.Decider('MD5-timestamp') 190955SN/Amain.root = Dir(".") # The current directory (where this file lives). 191955SN/Amain.srcdir = Dir("src") # The source directory 192955SN/A 193955SN/A# add useful python code PYTHONPATH so it can be used by subprocesses 1942632Sstever@eecs.umich.edu# as well 195955SN/Amain.AppendENVPath('PYTHONPATH', extra_python_paths) 1962632Sstever@eecs.umich.edu 1972632Sstever@eecs.umich.edu######################################################################## 1982632Sstever@eecs.umich.edu# 1992632Sstever@eecs.umich.edu# Mercurial Stuff. 2002632Sstever@eecs.umich.edu# 2012632Sstever@eecs.umich.edu# If the gem5 directory is a mercurial repository, we should do some 2022632Sstever@eecs.umich.edu# extra things. 2032632Sstever@eecs.umich.edu# 2042632Sstever@eecs.umich.edu######################################################################## 2052632Sstever@eecs.umich.edu 2062632Sstever@eecs.umich.eduhgdir = main.root.Dir(".hg") 2072632Sstever@eecs.umich.edu 2082632Sstever@eecs.umich.edumercurial_style_message = """ 2093718Sstever@eecs.umich.eduYou're missing the gem5 style hook, which automatically checks your code 2103718Sstever@eecs.umich.eduagainst the gem5 style rules on hg commit and qrefresh commands. This 2113718Sstever@eecs.umich.eduscript will now install the hook in your .hg/hgrc file. 2123718Sstever@eecs.umich.eduPress enter to continue, or ctrl-c to abort: """ 2133718Sstever@eecs.umich.edu 2143718Sstever@eecs.umich.edumercurial_style_hook = """ 2153718Sstever@eecs.umich.edu# The following lines were automatically added by gem5/SConstruct 2163718Sstever@eecs.umich.edu# to provide the gem5 style-checking hooks 2173718Sstever@eecs.umich.edu[extensions] 2183718Sstever@eecs.umich.edustyle = %s/util/style.py 2193718Sstever@eecs.umich.edu 2203718Sstever@eecs.umich.edu[hooks] 2213718Sstever@eecs.umich.edupretxncommit.style = python:style.check_style 2222634Sstever@eecs.umich.edupre-qrefresh.style = python:style.check_style 2232634Sstever@eecs.umich.edu# End of SConstruct additions 2242632Sstever@eecs.umich.edu 2252638Sstever@eecs.umich.edu""" % (main.root.abspath) 2262632Sstever@eecs.umich.edu 2272632Sstever@eecs.umich.edumercurial_lib_not_found = """ 2282632Sstever@eecs.umich.eduMercurial libraries cannot be found, ignoring style hook. If 2292632Sstever@eecs.umich.eduyou are a gem5 developer, please fix this and run the style 2302632Sstever@eecs.umich.eduhook. It is important. 2312632Sstever@eecs.umich.edu""" 2321858SN/A 2333716Sstever@eecs.umich.edu# Check for style hook and prompt for installation if it's not there. 2342638Sstever@eecs.umich.edu# Skip this if --ignore-style was specified, there's no .hg dir to 2352638Sstever@eecs.umich.edu# install a hook in, or there's no interactive terminal to prompt. 2362638Sstever@eecs.umich.eduif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2372638Sstever@eecs.umich.edu style_hook = True 2382638Sstever@eecs.umich.edu try: 2392638Sstever@eecs.umich.edu from mercurial import ui 2402638Sstever@eecs.umich.edu ui = ui.ui() 2413716Sstever@eecs.umich.edu ui.readconfig(hgdir.File('hgrc').abspath) 2422634Sstever@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2432634Sstever@eecs.umich.edu ui.config('hooks', 'pre-qrefresh.style', None) 244955SN/A except ImportError: 2455341Sstever@gmail.com print mercurial_lib_not_found 2465341Sstever@gmail.com 2475341Sstever@gmail.com if not style_hook: 2485341Sstever@gmail.com print mercurial_style_message, 249955SN/A # continue unless user does ctrl-c/ctrl-d etc. 250955SN/A try: 251955SN/A raw_input() 252955SN/A except: 253955SN/A print "Input exception, exiting scons.\n" 254955SN/A sys.exit(1) 255955SN/A hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2561858SN/A print "Adding style hook to", hgrc_path, "\n" 2571858SN/A try: 2582632Sstever@eecs.umich.edu hgrc = open(hgrc_path, 'a') 259955SN/A hgrc.write(mercurial_style_hook) 2604494Ssaidi@eecs.umich.edu hgrc.close() 2614494Ssaidi@eecs.umich.edu except: 2623716Sstever@eecs.umich.edu print "Error updating", hgrc_path 2631105SN/A sys.exit(1) 2642667Sstever@eecs.umich.edu 2652667Sstever@eecs.umich.edu 2662667Sstever@eecs.umich.edu################################################### 2672667Sstever@eecs.umich.edu# 2682667Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2692667Sstever@eecs.umich.edu# the target(s). 2701869SN/A# 2711869SN/A################################################### 2721869SN/A 2731869SN/A# Find default configuration & binary. 2741869SN/ADefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2751065SN/A 2765341Sstever@gmail.com# helper function: find last occurrence of element in list 2775341Sstever@gmail.comdef rfind(l, elt, offs = -1): 2785341Sstever@gmail.com for i in range(len(l)+offs, 0, -1): 2795341Sstever@gmail.com if l[i] == elt: 2805341Sstever@gmail.com return i 2815341Sstever@gmail.com raise ValueError, "element not found" 2825341Sstever@gmail.com 2835341Sstever@gmail.com# Take a list of paths (or SCons Nodes) and return a list with all 2845341Sstever@gmail.com# paths made absolute and ~-expanded. Paths will be interpreted 2855341Sstever@gmail.com# relative to the launch directory unless a different root is provided 2865341Sstever@gmail.comdef makePathListAbsolute(path_list, root=GetLaunchDir()): 2875341Sstever@gmail.com return [abspath(joinpath(root, expanduser(str(p)))) 2885341Sstever@gmail.com for p in path_list] 2895341Sstever@gmail.com 2905341Sstever@gmail.com# Each target must have 'build' in the interior of the path; the 2915341Sstever@gmail.com# directory below this will determine the build parameters. For 2925341Sstever@gmail.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2935341Sstever@gmail.com# recognize that ALPHA_SE specifies the configuration because it 2945341Sstever@gmail.com# follow 'build' in the build path. 2955341Sstever@gmail.com 2965341Sstever@gmail.com# The funky assignment to "[:]" is needed to replace the list contents 2975341Sstever@gmail.com# in place rather than reassign the symbol to a new list, which 2985341Sstever@gmail.com# doesn't work (obviously!). 2995341Sstever@gmail.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 3005341Sstever@gmail.com 3015341Sstever@gmail.com# Generate a list of the unique build roots and configs that the 3025341Sstever@gmail.com# collected targets reference. 3035397Ssaidi@eecs.umich.eduvariant_paths = [] 3045397Ssaidi@eecs.umich.edubuild_root = None 3055341Sstever@gmail.comfor t in BUILD_TARGETS: 3065341Sstever@gmail.com path_dirs = t.split('/') 3075341Sstever@gmail.com try: 3085341Sstever@gmail.com build_top = rfind(path_dirs, 'build', -2) 3095341Sstever@gmail.com except: 3105341Sstever@gmail.com print "Error: no non-leaf 'build' dir found on target path", t 3115341Sstever@gmail.com Exit(1) 3125341Sstever@gmail.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3135341Sstever@gmail.com if not build_root: 3145341Sstever@gmail.com build_root = this_build_root 3155341Sstever@gmail.com else: 3165341Sstever@gmail.com if this_build_root != build_root: 3175341Sstever@gmail.com print "Error: build targets not under same build root\n"\ 3185341Sstever@gmail.com " %s\n %s" % (build_root, this_build_root) 3195341Sstever@gmail.com Exit(1) 3205341Sstever@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 3215341Sstever@gmail.com if variant_path not in variant_paths: 3225341Sstever@gmail.com variant_paths.append(variant_path) 3235341Sstever@gmail.com 3245341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there) 3255341Sstever@gmail.comif not isdir(build_root): 3265341Sstever@gmail.com mkdir(build_root) 3275344Sstever@gmail.commain['BUILDROOT'] = build_root 3285341Sstever@gmail.com 3295341Sstever@gmail.comExport('main') 3305341Sstever@gmail.com 3315341Sstever@gmail.commain.SConsignFile(joinpath(build_root, "sconsign")) 3325341Sstever@gmail.com 3332632Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 3345199Sstever@gmail.com# when you use emacs to edit a file in the target dir, as emacs moves 3354781Snate@binkert.org# file to file~ then copies to file, breaking the link. Symbolic 3364781Snate@binkert.org# (soft) links work better. 3375550Snate@binkert.orgmain.SetOption('duplicate', 'soft-copy') 3384781Snate@binkert.org 3394781Snate@binkert.org# 3403918Ssaidi@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 3414781Snate@binkert.org# tree (not specific to a particular build like ALPHA_SE) 3424781Snate@binkert.org# 3433940Ssaidi@eecs.umich.edu 3443942Ssaidi@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 3453940Ssaidi@eecs.umich.edu 3463918Ssaidi@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3473918Ssaidi@eecs.umich.edu 348955SN/Aglobal_vars.AddVariables( 3491858SN/A ('CC', 'C compiler', environ.get('CC', main['CC'])), 3503918Ssaidi@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3513918Ssaidi@eecs.umich.edu ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 3523918Ssaidi@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3533918Ssaidi@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3545571Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3553940Ssaidi@eecs.umich.edu ('EXTRAS', 'Add extra directories to the compilation', '') 3563940Ssaidi@eecs.umich.edu ) 3573918Ssaidi@eecs.umich.edu 3583918Ssaidi@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_vars_file 3593918Ssaidi@eecs.umich.eduglobal_vars.Update(main) 3603918Ssaidi@eecs.umich.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3613918Ssaidi@eecs.umich.edu 3623918Ssaidi@eecs.umich.edu# Save sticky variable settings back to current variables file 3633918Ssaidi@eecs.umich.eduglobal_vars.Save(global_vars_file, main) 3643918Ssaidi@eecs.umich.edu 3653918Ssaidi@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3663940Ssaidi@eecs.umich.edu# look for sources etc. This list is exported as extras_dir_list. 3673918Ssaidi@eecs.umich.edubase_dir = main.srcdir.abspath 3683918Ssaidi@eecs.umich.eduif main['EXTRAS']: 3695397Ssaidi@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3705397Ssaidi@eecs.umich.eduelse: 3715397Ssaidi@eecs.umich.edu extras_dir_list = [] 3725397Ssaidi@eecs.umich.edu 3735397Ssaidi@eecs.umich.eduExport('base_dir') 3745397Ssaidi@eecs.umich.eduExport('extras_dir_list') 3751851SN/A 3761851SN/A# the ext directory should be on the #includes path 3771858SN/Amain.Append(CPPPATH=[Dir('ext')]) 3785200Sstever@gmail.com 379955SN/Adef strip_build_path(path, env): 3803053Sstever@eecs.umich.edu path = str(path) 3813053Sstever@eecs.umich.edu variant_base = env['BUILDROOT'] + os.path.sep 3823053Sstever@eecs.umich.edu if path.startswith(variant_base): 3833053Sstever@eecs.umich.edu path = path[len(variant_base):] 3843053Sstever@eecs.umich.edu elif path.startswith('build/'): 3853053Sstever@eecs.umich.edu path = path[6:] 3863053Sstever@eecs.umich.edu return path 3873053Sstever@eecs.umich.edu 3883053Sstever@eecs.umich.edu# Generate a string of the form: 3894742Sstever@eecs.umich.edu# common/path/prefix/src1, src2 -> tgt1, tgt2 3904742Sstever@eecs.umich.edu# to print while building. 3913053Sstever@eecs.umich.educlass Transform(object): 3923053Sstever@eecs.umich.edu # all specific color settings should be here and nowhere else 3933053Sstever@eecs.umich.edu tool_color = termcap.Normal 3943053Sstever@eecs.umich.edu pfx_color = termcap.Yellow 3953053Sstever@eecs.umich.edu srcs_color = termcap.Yellow + termcap.Bold 3963053Sstever@eecs.umich.edu arrow_color = termcap.Blue + termcap.Bold 3973053Sstever@eecs.umich.edu tgts_color = termcap.Yellow + termcap.Bold 3983053Sstever@eecs.umich.edu 3993053Sstever@eecs.umich.edu def __init__(self, tool, max_sources=99): 4002667Sstever@eecs.umich.edu self.format = self.tool_color + (" [%8s] " % tool) \ 4014554Sbinkertn@umich.edu + self.pfx_color + "%s" \ 4024554Sbinkertn@umich.edu + self.srcs_color + "%s" \ 4032667Sstever@eecs.umich.edu + self.arrow_color + " -> " \ 4044554Sbinkertn@umich.edu + self.tgts_color + "%s" \ 4054554Sbinkertn@umich.edu + termcap.Normal 4064554Sbinkertn@umich.edu self.max_sources = max_sources 4074554Sbinkertn@umich.edu 4084554Sbinkertn@umich.edu def __call__(self, target, source, env, for_signature=None): 4094554Sbinkertn@umich.edu # truncate source list according to max_sources param 4104554Sbinkertn@umich.edu source = source[0:self.max_sources] 4114781Snate@binkert.org def strip(f): 4124554Sbinkertn@umich.edu return strip_build_path(str(f), env) 4134554Sbinkertn@umich.edu if len(source) > 0: 4142667Sstever@eecs.umich.edu srcs = map(strip, source) 4154554Sbinkertn@umich.edu else: 4164554Sbinkertn@umich.edu srcs = [''] 4174554Sbinkertn@umich.edu tgts = map(strip, target) 4184554Sbinkertn@umich.edu # surprisingly, os.path.commonprefix is a dumb char-by-char string 4192667Sstever@eecs.umich.edu # operation that has nothing to do with paths. 4204554Sbinkertn@umich.edu com_pfx = os.path.commonprefix(srcs + tgts) 4212667Sstever@eecs.umich.edu com_pfx_len = len(com_pfx) 4224554Sbinkertn@umich.edu if com_pfx: 4234554Sbinkertn@umich.edu # do some cleanup and sanity checking on common prefix 4242667Sstever@eecs.umich.edu if com_pfx[-1] == ".": 4255522Snate@binkert.org # prefix matches all but file extension: ok 4265522Snate@binkert.org # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4275522Snate@binkert.org com_pfx = com_pfx[0:-1] 4285522Snate@binkert.org elif com_pfx[-1] == "/": 4295522Snate@binkert.org # common prefix is directory path: OK 4305522Snate@binkert.org pass 4315522Snate@binkert.org else: 4325522Snate@binkert.org src0_len = len(srcs[0]) 4335522Snate@binkert.org tgt0_len = len(tgts[0]) 4345522Snate@binkert.org if src0_len == com_pfx_len: 4355522Snate@binkert.org # source is a substring of target, OK 4365522Snate@binkert.org pass 4375522Snate@binkert.org elif tgt0_len == com_pfx_len: 4385522Snate@binkert.org # target is a substring of source, need to back up to 4395522Snate@binkert.org # avoid empty string on RHS of arrow 4405522Snate@binkert.org sep_idx = com_pfx.rfind(".") 4415522Snate@binkert.org if sep_idx != -1: 4425522Snate@binkert.org com_pfx = com_pfx[0:sep_idx] 4435522Snate@binkert.org else: 4445522Snate@binkert.org com_pfx = '' 4455522Snate@binkert.org elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4465522Snate@binkert.org # still splitting at file extension: ok 4475522Snate@binkert.org pass 4485522Snate@binkert.org else: 4495522Snate@binkert.org # probably a fluke; ignore it 4505522Snate@binkert.org com_pfx = '' 4512638Sstever@eecs.umich.edu # recalculate length in case com_pfx was modified 4522638Sstever@eecs.umich.edu com_pfx_len = len(com_pfx) 4532638Sstever@eecs.umich.edu def fmt(files): 4543716Sstever@eecs.umich.edu f = map(lambda s: s[com_pfx_len:], files) 4555522Snate@binkert.org return ', '.join(f) 4565522Snate@binkert.org return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4575522Snate@binkert.org 4585522Snate@binkert.orgExport('Transform') 4595522Snate@binkert.org 4605522Snate@binkert.org# enable the regression script to use the termcap 4611858SN/Amain['TERMCAP'] = termcap 4625227Ssaidi@eecs.umich.edu 4635227Ssaidi@eecs.umich.eduif GetOption('verbose'): 4645227Ssaidi@eecs.umich.edu def MakeAction(action, string, *args, **kwargs): 4655227Ssaidi@eecs.umich.edu return Action(action, *args, **kwargs) 4665227Ssaidi@eecs.umich.eduelse: 4675227Ssaidi@eecs.umich.edu MakeAction = Action 4685227Ssaidi@eecs.umich.edu main['CCCOMSTR'] = Transform("CC") 4695227Ssaidi@eecs.umich.edu main['CXXCOMSTR'] = Transform("CXX") 4705227Ssaidi@eecs.umich.edu main['ASCOMSTR'] = Transform("AS") 4715227Ssaidi@eecs.umich.edu main['SWIGCOMSTR'] = Transform("SWIG") 4725227Ssaidi@eecs.umich.edu main['ARCOMSTR'] = Transform("AR", 0) 4735227Ssaidi@eecs.umich.edu main['LINKCOMSTR'] = Transform("LINK", 0) 4745227Ssaidi@eecs.umich.edu main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4755227Ssaidi@eecs.umich.edu main['M4COMSTR'] = Transform("M4") 4765227Ssaidi@eecs.umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 4775204Sstever@gmail.com main['SHCXXCOMSTR'] = Transform("SHCXX") 4785204Sstever@gmail.comExport('MakeAction') 4795204Sstever@gmail.com 4805204Sstever@gmail.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4815204Sstever@gmail.comCXX_V = readCommand([main['CXX'],'-V'], exception=False) 4825204Sstever@gmail.com 4835204Sstever@gmail.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4845204Sstever@gmail.commain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4855204Sstever@gmail.commain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4865204Sstever@gmail.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 4875204Sstever@gmail.comif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: 4885204Sstever@gmail.com print 'Error: How can we have two at the same time?' 4895204Sstever@gmail.com Exit(1) 4905204Sstever@gmail.com 4915204Sstever@gmail.com# Set up default C++ compiler flags 4925204Sstever@gmail.comif main['GCC']: 4935204Sstever@gmail.com main.Append(CCFLAGS=['-pipe']) 4945204Sstever@gmail.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 4955204Sstever@gmail.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4963118Sstever@eecs.umich.edu # Read the GCC version to check for versions with bugs 4973118Sstever@eecs.umich.edu # Note CCVERSION doesn't work here because it is run with the CC 4983118Sstever@eecs.umich.edu # before we override it from the command line 4993118Sstever@eecs.umich.edu gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5003118Sstever@eecs.umich.edu main['GCC_VERSION'] = gcc_version 5013118Sstever@eecs.umich.edu if not compareVersions(gcc_version, '4.4.1') or \ 5023118Sstever@eecs.umich.edu not compareVersions(gcc_version, '4.4.2'): 5033118Sstever@eecs.umich.edu print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5043118Sstever@eecs.umich.edu main.Append(CCFLAGS=['-fno-tree-vectorize']) 5053118Sstever@eecs.umich.edu if compareVersions(gcc_version, '4.6') >= 0: 5063118Sstever@eecs.umich.edu main.Append(CXXFLAGS=['-std=c++0x']) 5073716Sstever@eecs.umich.eduelif main['ICC']: 5083118Sstever@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 5093118Sstever@eecs.umich.eduelif main['SUNCC']: 5103118Sstever@eecs.umich.edu main.Append(CCFLAGS=['-Qoption ccfe']) 5113118Sstever@eecs.umich.edu main.Append(CCFLAGS=['-features=gcc']) 5123118Sstever@eecs.umich.edu main.Append(CCFLAGS=['-features=extensions']) 5133118Sstever@eecs.umich.edu main.Append(CCFLAGS=['-library=stlport4']) 5143118Sstever@eecs.umich.edu main.Append(CCFLAGS=['-xar']) 5153118Sstever@eecs.umich.edu #main.Append(CCFLAGS=['-instances=semiexplicit']) 5163118Sstever@eecs.umich.eduelif main['CLANG']: 5173716Sstever@eecs.umich.edu clang_version_re = re.compile(".* version (\d+\.\d+)") 5183118Sstever@eecs.umich.edu clang_version_match = clang_version_re.match(CXX_version) 5193118Sstever@eecs.umich.edu if (clang_version_match): 5203118Sstever@eecs.umich.edu clang_version = clang_version_match.groups()[0] 5213118Sstever@eecs.umich.edu if compareVersions(clang_version, "2.9") < 0: 5223118Sstever@eecs.umich.edu print 'Error: clang version 2.9 or newer required.' 5233118Sstever@eecs.umich.edu print ' Installed version:', clang_version 5243118Sstever@eecs.umich.edu Exit(1) 5253118Sstever@eecs.umich.edu else: 5263118Sstever@eecs.umich.edu print 'Error: Unable to determine clang version.' 5273118Sstever@eecs.umich.edu Exit(1) 5283483Ssaidi@eecs.umich.edu 5293494Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-pipe']) 5303494Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-fno-strict-aliasing']) 5313483Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5323483Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Wno-tautological-compare']) 5333483Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Wno-self-assign']) 5343053Sstever@eecs.umich.edu # Ruby makes frequent use of extraneous parantheses in the printing 5353053Sstever@eecs.umich.edu # of if-statements 5363918Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Wno-parentheses']) 5373053Sstever@eecs.umich.edu 5383053Sstever@eecs.umich.edu if compareVersions(clang_version, "3") >= 0: 5393053Sstever@eecs.umich.edu main.Append(CXXFLAGS=['-std=c++0x']) 5403053Sstever@eecs.umich.eduelse: 5413053Sstever@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 5421858SN/A print ' Please fix SConstruct and src/SConscript and try again.' 5431858SN/A Exit(1) 5441858SN/A 5451858SN/A# Set up common yacc/bison flags (needed for Ruby) 5461858SN/Amain['YACCFLAGS'] = '-d' 5471858SN/Amain['YACCHXXFILESUFFIX'] = '.hh' 5481859SN/A 5491858SN/A# Do this after we save setting back, or else we'll tack on an 5501858SN/A# extra 'qdo' every time we run scons. 5511858SN/Aif main['BATCH']: 5521859SN/A main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5531859SN/A main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5541862SN/A main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5553053Sstever@eecs.umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5563053Sstever@eecs.umich.edu main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5573053Sstever@eecs.umich.edu 5583053Sstever@eecs.umich.eduif sys.platform == 'cygwin': 5591859SN/A # cygwin has some header file issues... 5601859SN/A main.Append(CCFLAGS=["-Wno-uninitialized"]) 5611859SN/A 5621859SN/A# Check for SWIG 5631859SN/Aif not main.has_key('SWIG'): 5641859SN/A print 'Error: SWIG utility not found.' 5651859SN/A print ' Please install (see http://www.swig.org) and retry.' 5661859SN/A Exit(1) 5671862SN/A 5681859SN/A# Check for appropriate SWIG version 5691859SN/Aswig_version = readCommand(('swig', '-version'), exception='').split() 5701859SN/A# First 3 words should be "SWIG Version x.y.z" 5711858SN/Aif len(swig_version) < 3 or \ 5721858SN/A swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5732139SN/A print 'Error determining SWIG version.' 5744202Sbinkertn@umich.edu Exit(1) 5754202Sbinkertn@umich.edu 5762139SN/Amin_swig_version = '1.3.34' 5772155SN/Aif compareVersions(swig_version[2], min_swig_version) < 0: 5784202Sbinkertn@umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 5794202Sbinkertn@umich.edu print ' Installed version:', swig_version[2] 5804202Sbinkertn@umich.edu Exit(1) 5812155SN/A 5821869SN/A# Set up SWIG flags & scanner 5831869SN/Aswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5841869SN/Amain.Append(SWIGFLAGS=swig_flags) 5851869SN/A 5864202Sbinkertn@umich.edu# filter out all existing swig scanners, they mess up the dependency 5874202Sbinkertn@umich.edu# stuff for some reason 5884202Sbinkertn@umich.eduscanners = [] 5894202Sbinkertn@umich.edufor scanner in main['SCANNERS']: 5904202Sbinkertn@umich.edu skeys = scanner.skeys 5914202Sbinkertn@umich.edu if skeys == '.i': 5924202Sbinkertn@umich.edu continue 5934202Sbinkertn@umich.edu 5945341Sstever@gmail.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5955341Sstever@gmail.com continue 5965341Sstever@gmail.com 5975342Sstever@gmail.com scanners.append(scanner) 5985342Sstever@gmail.com 5994202Sbinkertn@umich.edu# add the new swig scanner that we like better 6004202Sbinkertn@umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 6014202Sbinkertn@umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 6024202Sbinkertn@umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 6034202Sbinkertn@umich.edu 6041869SN/A# replace the scanners list that has what we want 6054202Sbinkertn@umich.edumain['SCANNERS'] = scanners 6061869SN/A 6072508SN/A# Add a custom Check function to the Configure context so that we can 6082508SN/A# figure out if the compiler adds leading underscores to global 6092508SN/A# variables. This is needed for the autogenerated asm files that we 6102508SN/A# use for embedding the python code. 6114202Sbinkertn@umich.edudef CheckLeading(context): 6121869SN/A context.Message("Checking for leading underscore in global variables...") 6135385Sstever@gmail.com # 1) Define a global variable called x from asm so the C compiler 6145385Sstever@gmail.com # won't change the symbol at all. 6155385Sstever@gmail.com # 2) Declare that variable. 6165385Sstever@gmail.com # 3) Use the variable 6171869SN/A # 6181869SN/A # If the compiler prepends an underscore, this will successfully 6191869SN/A # link because the external symbol 'x' will be called '_x' which 6201869SN/A # was defined by the asm statement. If the compiler does not 6211869SN/A # prepend an underscore, this will not successfully link because 6221965SN/A # '_x' will have been defined by assembly, while the C portion of 6231965SN/A # the code will be trying to use 'x' 6241965SN/A ret = context.TryLink(''' 6251869SN/A asm(".globl _x; _x: .byte 0"); 6261869SN/A extern int x; 6272733Sktlim@umich.edu int main() { return x; } 6281869SN/A ''', extension=".c") 6291858SN/A context.env.Append(LEADING_UNDERSCORE=ret) 6301869SN/A context.Result(ret) 6311869SN/A return ret 6321869SN/A 6331858SN/A# Platform-specific configuration. Note again that we assume that all 6342761Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 6351869SN/Aconf = Configure(main, 6365385Sstever@gmail.com conf_dir = joinpath(build_root, '.scons_config'), 6375385Sstever@gmail.com log_file = joinpath(build_root, 'scons_config.log'), 6385522Snate@binkert.org custom_tests = { 'CheckLeading' : CheckLeading }) 6391869SN/A 6401869SN/A# Check for leading underscores. Don't really need to worry either 6411869SN/A# way so don't need to check the return code. 6421869SN/Aconf.CheckLeading() 6431869SN/A 6441869SN/A# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6451858SN/Atry: 646955SN/A import platform 647955SN/A uname = platform.uname() 6481869SN/A if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6491869SN/A if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6501869SN/A main.Append(CCFLAGS=['-arch', 'x86_64']) 6511869SN/A main.Append(CFLAGS=['-arch', 'x86_64']) 6521869SN/A main.Append(LINKFLAGS=['-arch', 'x86_64']) 6531869SN/A main.Append(ASFLAGS=['-arch', 'x86_64']) 6541869SN/Aexcept: 6551869SN/A pass 6561869SN/A 6571869SN/A# Recent versions of scons substitute a "Null" object for Configure() 6581869SN/A# when configuration isn't necessary, e.g., if the "--help" option is 6591869SN/A# present. Unfortuantely this Null object always returns false, 6601869SN/A# breaking all our configuration checks. We replace it with our own 6611869SN/A# more optimistic null object that returns True instead. 6621869SN/Aif not conf: 6631869SN/A def NullCheck(*args, **kwargs): 6641869SN/A return True 6651869SN/A 6661869SN/A class NullConf: 6671869SN/A def __init__(self, env): 6681869SN/A self.env = env 6691869SN/A def Finish(self): 6701869SN/A return self.env 6711869SN/A def __getattr__(self, mname): 6721869SN/A return NullCheck 6731869SN/A 6741869SN/A conf = NullConf(main) 6751869SN/A 6761869SN/A# Find Python include and library directories for embedding the 6773716Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 6783356Sbinkertn@umich.edu# installation used to run scons (and thus this script). If you want 6793356Sbinkertn@umich.edu# to link in an alternate version, see above for instructions on how 6803356Sbinkertn@umich.edu# to invoke scons with a different copy of the Python interpreter. 6813356Sbinkertn@umich.edufrom distutils import sysconfig 6823356Sbinkertn@umich.edu 6833356Sbinkertn@umich.edupy_getvar = sysconfig.get_config_var 6844781Snate@binkert.org 6851869SN/Apy_debug = getattr(sys, 'pydebug', False) 6861869SN/Apy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6871869SN/A 6881869SN/Apy_general_include = sysconfig.get_python_inc() 6891869SN/Apy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6901869SN/Apy_includes = [ py_general_include ] 6911869SN/Aif py_platform_include != py_general_include: 6922655Sstever@eecs.umich.edu py_includes.append(py_platform_include) 6932655Sstever@eecs.umich.edu 6942655Sstever@eecs.umich.edupy_lib_path = [ py_getvar('LIBDIR') ] 6952655Sstever@eecs.umich.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6962655Sstever@eecs.umich.edu# shared library in prefix/lib/. 6972655Sstever@eecs.umich.eduif not py_getvar('Py_ENABLE_SHARED'): 6982655Sstever@eecs.umich.edu py_lib_path.append(py_getvar('LIBPL')) 6992655Sstever@eecs.umich.edu 7002655Sstever@eecs.umich.edupy_libs = [] 7012655Sstever@eecs.umich.edufor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 7022655Sstever@eecs.umich.edu if not lib.startswith('-l'): 7032655Sstever@eecs.umich.edu # Python requires some special flags to link (e.g. -framework 7042655Sstever@eecs.umich.edu # common on OS X systems), assume appending preserves order 7052655Sstever@eecs.umich.edu main.Append(LINKFLAGS=[lib]) 7062655Sstever@eecs.umich.edu else: 7072655Sstever@eecs.umich.edu lib = lib[2:] 7082655Sstever@eecs.umich.edu if lib not in py_libs: 7092655Sstever@eecs.umich.edu py_libs.append(lib) 7102655Sstever@eecs.umich.edupy_libs.append(py_version) 7112655Sstever@eecs.umich.edu 7122655Sstever@eecs.umich.edumain.Append(CPPPATH=py_includes) 7132655Sstever@eecs.umich.edumain.Append(LIBPATH=py_lib_path) 7142655Sstever@eecs.umich.edu 7152655Sstever@eecs.umich.edu# Cache build files in the supplied directory. 7162655Sstever@eecs.umich.eduif main['M5_BUILD_CACHE']: 7172655Sstever@eecs.umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 7182638Sstever@eecs.umich.edu CacheDir(main['M5_BUILD_CACHE']) 7192638Sstever@eecs.umich.edu 7203716Sstever@eecs.umich.edu 7212638Sstever@eecs.umich.edu# verify that this stuff works 7222638Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 7231869SN/A print "Error: can't find Python.h header in", py_includes 7241869SN/A Exit(1) 7253546Sgblack@eecs.umich.edu 7263546Sgblack@eecs.umich.edufor lib in py_libs: 7273546Sgblack@eecs.umich.edu if not conf.CheckLib(lib): 7283546Sgblack@eecs.umich.edu print "Error: can't find library %s required by python" % lib 7294202Sbinkertn@umich.edu Exit(1) 7303546Sgblack@eecs.umich.edu 7313546Sgblack@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 7323546Sgblack@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7333546Sgblack@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7343546Sgblack@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 7354781Snate@binkert.org Exit(1) 7364781Snate@binkert.org 7374781Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 7384781Snate@binkert.org# added to the LIBS environment variable. 7394781Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7404781Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 7414781Snate@binkert.org 'and/or zlib.h header file.' 7424781Snate@binkert.org print ' Please install zlib and try again.' 7434781Snate@binkert.org Exit(1) 7444781Snate@binkert.org 7454781Snate@binkert.org# Check for librt. 7464781Snate@binkert.orghave_posix_clock = \ 7473546Sgblack@eecs.umich.edu conf.CheckLibWithHeader(None, 'time.h', 'C', 7483546Sgblack@eecs.umich.edu 'clock_nanosleep(0,0,NULL,NULL);') or \ 7493546Sgblack@eecs.umich.edu conf.CheckLibWithHeader('rt', 'time.h', 'C', 7504781Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') 7513546Sgblack@eecs.umich.edu 7523546Sgblack@eecs.umich.eduif not have_posix_clock: 7533546Sgblack@eecs.umich.edu print "Can't find library for POSIX clocks." 7543546Sgblack@eecs.umich.edu 7553546Sgblack@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 7563546Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 7573546Sgblack@eecs.umich.eduif not have_fenv: 7583546Sgblack@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 7593546Sgblack@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 7603546Sgblack@eecs.umich.edu 7614202Sbinkertn@umich.edu###################################################################### 7623546Sgblack@eecs.umich.edu# 7633546Sgblack@eecs.umich.edu# Finish the configuration 7643546Sgblack@eecs.umich.edu# 765955SN/Amain = conf.Finish() 766955SN/A 767955SN/A###################################################################### 768955SN/A# 7691858SN/A# Collect all non-global variables 7701858SN/A# 7711858SN/A 7722632Sstever@eecs.umich.edu# Define the universe of supported ISAs 7732632Sstever@eecs.umich.eduall_isa_list = [ ] 7745343Sstever@gmail.comExport('all_isa_list') 7755343Sstever@gmail.com 7765343Sstever@gmail.comclass CpuModel(object): 7774773Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 7784773Snate@binkert.org know about a particular CPU model.''' 7792632Sstever@eecs.umich.edu 7802632Sstever@eecs.umich.edu # Dict of available CPU model objects. Accessible as CpuModel.dict. 7812632Sstever@eecs.umich.edu dict = {} 7822023SN/A list = [] 7832632Sstever@eecs.umich.edu defaults = [] 7842632Sstever@eecs.umich.edu 7852632Sstever@eecs.umich.edu # Constructor. Automatically adds models to CpuModel.dict. 7862632Sstever@eecs.umich.edu def __init__(self, name, filename, includes, strings, default=False): 7872632Sstever@eecs.umich.edu self.name = name # name of model 7883716Sstever@eecs.umich.edu self.filename = filename # filename for output exec code 7895342Sstever@gmail.com self.includes = includes # include files needed in exec file 7902632Sstever@eecs.umich.edu # The 'strings' dict holds all the per-CPU symbols we can 7912632Sstever@eecs.umich.edu # substitute into templates etc. 7922632Sstever@eecs.umich.edu self.strings = strings 7932632Sstever@eecs.umich.edu 7942023SN/A # This cpu is enabled by default 7952632Sstever@eecs.umich.edu self.default = default 7962632Sstever@eecs.umich.edu 7975342Sstever@gmail.com # Add self to dict 7981889SN/A if name in CpuModel.dict: 7992632Sstever@eecs.umich.edu raise AttributeError, "CpuModel '%s' already registered" % name 8002632Sstever@eecs.umich.edu CpuModel.dict[name] = self 8012632Sstever@eecs.umich.edu CpuModel.list.append(name) 8022632Sstever@eecs.umich.edu 8033716Sstever@eecs.umich.eduExport('CpuModel') 8043716Sstever@eecs.umich.edu 8055342Sstever@gmail.com# Sticky variables get saved in the variables file so they persist from 8062632Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 8072632Sstever@eecs.umich.edu# value becomes sticky). 8082632Sstever@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS) 8092632Sstever@eecs.umich.eduExport('sticky_vars') 8102632Sstever@eecs.umich.edu 8112632Sstever@eecs.umich.edu# Sticky variables that should be exported 8122632Sstever@eecs.umich.eduexport_vars = [] 8131888SN/AExport('export_vars') 8141888SN/A 8151869SN/A# Walk the tree and execute all SConsopts scripts that wil add to the 8161869SN/A# above variables 8171858SN/Aif not GetOption('verbose'): 8185341Sstever@gmail.com print "Reading SConsopts" 8192598SN/Afor bdir in [ base_dir ] + extras_dir_list: 8202598SN/A if not isdir(bdir): 8212598SN/A print "Error: directory '%s' does not exist" % bdir 8222598SN/A Exit(1) 8231858SN/A for root, dirs, files in os.walk(bdir): 8241858SN/A if 'SConsopts' in files: 8251858SN/A if GetOption('verbose'): 8261858SN/A print "Reading", joinpath(root, 'SConsopts') 8271858SN/A SConscript(joinpath(root, 'SConsopts')) 8281858SN/A 8291858SN/Aall_isa_list.sort() 8301858SN/A 8311858SN/Asticky_vars.AddVariables( 8321871SN/A EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 8331858SN/A ListVariable('CPU_MODELS', 'CPU models', 8341858SN/A sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 8351858SN/A sorted(CpuModel.list)), 8361858SN/A BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 8371858SN/A False), 8381858SN/A BoolVariable('SS_COMPATIBLE_FP', 8391858SN/A 'Make floating-point results compatible with SimpleScalar', 8401858SN/A False), 8411858SN/A BoolVariable('USE_SSE2', 8421858SN/A 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 8431858SN/A False), 8441859SN/A BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 8451859SN/A BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 8461869SN/A BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 8471888SN/A ) 8482632Sstever@eecs.umich.edu 8491869SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript). 8501965SN/Aexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 8511965SN/A 'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK' ] 8521965SN/A 8532761Sstever@eecs.umich.edu################################################### 8541869SN/A# 8551869SN/A# Define a SCons builder for configuration flag headers. 8562632Sstever@eecs.umich.edu# 8572667Sstever@eecs.umich.edu################################################### 8581869SN/A 8591869SN/A# This function generates a config header file that #defines the 8602929Sktlim@umich.edu# variable symbol to the current variable setting (0 or 1). The source 8612929Sktlim@umich.edu# operands are the name of the variable and a Value node containing the 8623716Sstever@eecs.umich.edu# value of the variable. 8632929Sktlim@umich.edudef build_config_file(target, source, env): 864955SN/A (variable, value) = [s.get_contents() for s in source] 8652598SN/A f = file(str(target[0]), 'w') 8662598SN/A print >> f, '#define', variable, value 8673546Sgblack@eecs.umich.edu f.close() 868955SN/A return None 869955SN/A 870955SN/A# Combine the two functions into a scons Action object. 8711530SN/Aconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 872955SN/A 873955SN/A# The emitter munges the source & target node lists to reflect what 874955SN/A# we're really doing. 875def config_emitter(target, source, env): 876 # extract variable name from Builder arg 877 variable = str(target[0]) 878 # True target is config header file 879 target = joinpath('config', variable.lower() + '.hh') 880 val = env[variable] 881 if isinstance(val, bool): 882 # Force value to 0/1 883 val = int(val) 884 elif isinstance(val, str): 885 val = '"' + val + '"' 886 887 # Sources are variable name & value (packaged in SCons Value nodes) 888 return ([target], [Value(variable), Value(val)]) 889 890config_builder = Builder(emitter = config_emitter, action = config_action) 891 892main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 893 894# libelf build is shared across all configs in the build root. 895main.SConscript('ext/libelf/SConscript', 896 variant_dir = joinpath(build_root, 'libelf')) 897 898# gzstream build is shared across all configs in the build root. 899main.SConscript('ext/gzstream/SConscript', 900 variant_dir = joinpath(build_root, 'gzstream')) 901 902################################################### 903# 904# This function is used to set up a directory with switching headers 905# 906################################################### 907 908main['ALL_ISA_LIST'] = all_isa_list 909def make_switching_dir(dname, switch_headers, env): 910 # Generate the header. target[0] is the full path of the output 911 # header to generate. 'source' is a dummy variable, since we get the 912 # list of ISAs from env['ALL_ISA_LIST']. 913 def gen_switch_hdr(target, source, env): 914 fname = str(target[0]) 915 f = open(fname, 'w') 916 isa = env['TARGET_ISA'].lower() 917 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 918 f.close() 919 920 # Build SCons Action object. 'varlist' specifies env vars that this 921 # action depends on; when env['ALL_ISA_LIST'] changes these actions 922 # should get re-executed. 923 switch_hdr_action = MakeAction(gen_switch_hdr, 924 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 925 926 # Instantiate actions for each header 927 for hdr in switch_headers: 928 env.Command(hdr, [], switch_hdr_action) 929Export('make_switching_dir') 930 931################################################### 932# 933# Define build environments for selected configurations. 934# 935################################################### 936 937for variant_path in variant_paths: 938 print "Building in", variant_path 939 940 # Make a copy of the build-root environment to use for this config. 941 env = main.Clone() 942 env['BUILDDIR'] = variant_path 943 944 # variant_dir is the tail component of build path, and is used to 945 # determine the build parameters (e.g., 'ALPHA_SE') 946 (build_root, variant_dir) = splitpath(variant_path) 947 948 # Set env variables according to the build directory config. 949 sticky_vars.files = [] 950 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 951 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 952 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 953 current_vars_file = joinpath(build_root, 'variables', variant_dir) 954 if isfile(current_vars_file): 955 sticky_vars.files.append(current_vars_file) 956 print "Using saved variables file %s" % current_vars_file 957 else: 958 # Build dir-specific variables file doesn't exist. 959 960 # Make sure the directory is there so we can create it later 961 opt_dir = dirname(current_vars_file) 962 if not isdir(opt_dir): 963 mkdir(opt_dir) 964 965 # Get default build variables from source tree. Variables are 966 # normally determined by name of $VARIANT_DIR, but can be 967 # overridden by '--default=' arg on command line. 968 default = GetOption('default') 969 opts_dir = joinpath(main.root.abspath, 'build_opts') 970 if default: 971 default_vars_files = [joinpath(build_root, 'variables', default), 972 joinpath(opts_dir, default)] 973 else: 974 default_vars_files = [joinpath(opts_dir, variant_dir)] 975 existing_files = filter(isfile, default_vars_files) 976 if existing_files: 977 default_vars_file = existing_files[0] 978 sticky_vars.files.append(default_vars_file) 979 print "Variables file %s not found,\n using defaults in %s" \ 980 % (current_vars_file, default_vars_file) 981 else: 982 print "Error: cannot find variables file %s or " \ 983 "default file(s) %s" \ 984 % (current_vars_file, ' or '.join(default_vars_files)) 985 Exit(1) 986 987 # Apply current variable settings to env 988 sticky_vars.Update(env) 989 990 help_texts["local_vars"] += \ 991 "Build variables for %s:\n" % variant_dir \ 992 + sticky_vars.GenerateHelpText(env) 993 994 # Process variable settings. 995 996 if not have_fenv and env['USE_FENV']: 997 print "Warning: <fenv.h> not available; " \ 998 "forcing USE_FENV to False in", variant_dir + "." 999 env['USE_FENV'] = False 1000 1001 if not env['USE_FENV']: 1002 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 1003 print " FP results may deviate slightly from other platforms." 1004 1005 if env['EFENCE']: 1006 env.Append(LIBS=['efence']) 1007 1008 # Save sticky variable settings back to current variables file 1009 sticky_vars.Save(current_vars_file, env) 1010 1011 if env['USE_SSE2']: 1012 env.Append(CCFLAGS=['-msse2']) 1013 1014 # The src/SConscript file sets up the build rules in 'env' according 1015 # to the configured variables. It returns a list of environments, 1016 # one for each variant build (debug, opt, etc.) 1017 envList = SConscript('src/SConscript', variant_dir = variant_path, 1018 exports = 'env') 1019 1020 # Set up the regression tests for each build. 1021 for e in envList: 1022 SConscript('tests/SConscript', 1023 variant_dir = joinpath(variant_path, 'tests', e.Label), 1024 exports = { 'env' : e }, duplicate = False) 1025 1026# base help text 1027Help(''' 1028Usage: scons [scons options] [build variables] [target(s)] 1029 1030Extra scons options: 1031%(options)s 1032 1033Global build variables: 1034%(global_vars)s 1035 1036%(local_vars)s 1037''' % help_texts) 1038