SConstruct revision 8947
1955SN/A# -*- mode:python -*- 2955SN/A 35871Snate@binkert.org# Copyright (c) 2011 Advanced Micro Devices, Inc. 41762SN/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 28955SN/A# (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. 302665Ssaidi@eecs.umich.edu# 315863Snate@binkert.org# Authors: Steve Reinhardt 32955SN/A# Nathan Binkert 33955SN/A 34955SN/A################################################### 35955SN/A# 36955SN/A# 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 392632Sstever@eecs.umich.edu# 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 41955SN/A# the optimized full-system version). 422632Sstever@eecs.umich.edu# 432632Sstever@eecs.umich.edu# You can build gem5 in a different directory as long as there is a 442761Sstever@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 462632Sstever@eecs.umich.edu# built for the same host system. 472632Sstever@eecs.umich.edu# 482761Sstever@eecs.umich.edu# Examples: 492761Sstever@eecs.umich.edu# 502761Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 512632Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 522632Sstever@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 562761Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 572761Sstever@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 632632Sstever@eecs.umich.edu# 'gem5' directory (or use -u or -C to tell scons where to find this 642632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the gem5-specific build 65955SN/A# options as well. 66955SN/A# 67955SN/A################################################### 685863Snate@binkert.org 695863Snate@binkert.org# Check for recent-enough Python and SCons versions. 705863Snate@binkert.orgtry: 715863Snate@binkert.org # Really old versions of scons only take two options for the 725863Snate@binkert.org # function, so check once without the revision and once with the 735863Snate@binkert.org # revision, the first instance will fail for stuff other than 745863Snate@binkert.org # 0.98, and the second will fail for 0.98.0 755863Snate@binkert.org EnsureSConsVersion(0, 98) 765863Snate@binkert.org EnsureSConsVersion(0, 98, 1) 775863Snate@binkert.orgexcept SystemExit, e: 785863Snate@binkert.org print """ 795863Snate@binkert.orgFor more details, see: 805863Snate@binkert.org http://gem5.org/Dependencies 815863Snate@binkert.org""" 825863Snate@binkert.org raise 835863Snate@binkert.org 845863Snate@binkert.org# We ensure the python version early because we have stuff that 855863Snate@binkert.org# requires python 2.4 865863Snate@binkert.orgtry: 875863Snate@binkert.org EnsurePythonVersion(2, 4) 885863Snate@binkert.orgexcept SystemExit, e: 895863Snate@binkert.org print """ 905863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 915863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 925863Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter 935863Snate@binkert.orgon the scons script. 945863Snate@binkert.org 955863Snate@binkert.orgFor more details, see: 965863Snate@binkert.org http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 975863Snate@binkert.org""" 985863Snate@binkert.org raise 99955SN/A 1005396Ssaidi@eecs.umich.edu# Global Python includes 1015863Snate@binkert.orgimport os 1025863Snate@binkert.orgimport re 1034202Sbinkertn@umich.eduimport subprocess 1045863Snate@binkert.orgimport sys 1055863Snate@binkert.org 1065863Snate@binkert.orgfrom os import mkdir, environ 1075863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 108955SN/Afrom os.path import exists, isdir, isfile 1095273Sstever@gmail.comfrom os.path import join as joinpath, split as splitpath 1105871Snate@binkert.org 1115273Sstever@gmail.com# SCons includes 1125871Snate@binkert.orgimport SCons 1135863Snate@binkert.orgimport SCons.Node 1145863Snate@binkert.org 1155863Snate@binkert.orgextra_python_paths = [ 1165871Snate@binkert.org Dir('src/python').srcnode().abspath, # gem5 includes 1175872Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1185872Snate@binkert.org ] 1195872Snate@binkert.org 1205871Snate@binkert.orgsys.path[1:1] = extra_python_paths 1215871Snate@binkert.org 1225871Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1235871Snate@binkert.orgfrom m5.util.terminal import get_termcap 1245871Snate@binkert.org 1255871Snate@binkert.orghelp_texts = { 1265871Snate@binkert.org "options" : "", 1275871Snate@binkert.org "global_vars" : "", 1285871Snate@binkert.org "local_vars" : "" 1295871Snate@binkert.org} 1305871Snate@binkert.org 1315871Snate@binkert.orgExport("help_texts") 1325871Snate@binkert.org 1335871Snate@binkert.org 1345863Snate@binkert.org# There's a bug in scons in that (1) by default, the help texts from 1355227Ssaidi@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 1445588Ssaidi@eecs.umich.edu# we can just use AddOption directly. 1455396Ssaidi@eecs.umich.edudef AddLocalOption(*args, **kwargs): 1465396Ssaidi@eecs.umich.edu col_width = 30 1475396Ssaidi@eecs.umich.edu 1485396Ssaidi@eecs.umich.edu help = " " + ", ".join(args) 1495396Ssaidi@eecs.umich.edu if "help" in kwargs: 1505396Ssaidi@eecs.umich.edu length = len(help) 1515396Ssaidi@eecs.umich.edu if length >= col_width: 1525396Ssaidi@eecs.umich.edu help += "\n" + " " * col_width 1535396Ssaidi@eecs.umich.edu else: 1545396Ssaidi@eecs.umich.edu help += " " * (col_width - length) 1555396Ssaidi@eecs.umich.edu help += kwargs["help"] 1565396Ssaidi@eecs.umich.edu help_texts["options"] += help + "\n" 1575396Ssaidi@eecs.umich.edu 1585396Ssaidi@eecs.umich.edu AddOption(*args, **kwargs) 1595871Snate@binkert.org 1605871Snate@binkert.orgAddLocalOption('--colors', dest='use_colors', action='store_true', 1615871Snate@binkert.org help="Add color to abbreviated scons output") 1625871Snate@binkert.orgAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1635871Snate@binkert.org help="Don't add color to abbreviated scons output") 1646003Snate@binkert.orgAddLocalOption('--default', dest='default', type='string', action='store', 1656003Snate@binkert.org help='Override which build_opts file to use for defaults') 166955SN/AAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1675871Snate@binkert.org help='Disable style checking hooks') 1685871Snate@binkert.orgAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1695871Snate@binkert.org help='Update test reference outputs') 1705871Snate@binkert.orgAddLocalOption('--verbose', dest='verbose', action='store_true', 171955SN/A help='Print full tool command lines') 1725871Snate@binkert.org 1735871Snate@binkert.orgtermcap = get_termcap(GetOption('use_colors')) 1745871Snate@binkert.org 1751533SN/A######################################################################## 1765871Snate@binkert.org# 1775871Snate@binkert.org# Set up the main build environment. 1785863Snate@binkert.org# 1795871Snate@binkert.org######################################################################## 1805871Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1815871Snate@binkert.org 'PYTHONPATH', 'RANLIB' ]) 1825871Snate@binkert.org 1835871Snate@binkert.orguse_env = {} 1845863Snate@binkert.orgfor key,val in os.environ.iteritems(): 1855871Snate@binkert.org if key in use_vars or key.startswith("M5"): 1865863Snate@binkert.org use_env[key] = val 1875871Snate@binkert.org 1884678Snate@binkert.orgmain = Environment(ENV=use_env) 1894678Snate@binkert.orgmain.Decider('MD5-timestamp') 1904678Snate@binkert.orgmain.root = Dir(".") # The current directory (where this file lives). 1914678Snate@binkert.orgmain.srcdir = Dir("src") # The source directory 1924678Snate@binkert.org 1934678Snate@binkert.org# add useful python code PYTHONPATH so it can be used by subprocesses 1944678Snate@binkert.org# as well 1954678Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths) 1964678Snate@binkert.org 1974678Snate@binkert.org######################################################################## 1984678Snate@binkert.org# 1994678Snate@binkert.org# Mercurial Stuff. 2005871Snate@binkert.org# 2014678Snate@binkert.org# If the gem5 directory is a mercurial repository, we should do some 2025871Snate@binkert.org# extra things. 2035871Snate@binkert.org# 2045871Snate@binkert.org######################################################################## 2055871Snate@binkert.org 2065871Snate@binkert.orghgdir = main.root.Dir(".hg") 2075871Snate@binkert.org 2085871Snate@binkert.orgmercurial_style_message = """ 2095871Snate@binkert.orgYou're missing the gem5 style hook, which automatically checks your code 2105871Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands. This 2115871Snate@binkert.orgscript will now install the hook in your .hg/hgrc file. 2125871Snate@binkert.orgPress enter to continue, or ctrl-c to abort: """ 2135871Snate@binkert.org 2145871Snate@binkert.orgmercurial_style_hook = """ 2155990Ssaidi@eecs.umich.edu# The following lines were automatically added by gem5/SConstruct 2165871Snate@binkert.org# to provide the gem5 style-checking hooks 2175871Snate@binkert.org[extensions] 2185871Snate@binkert.orgstyle = %s/util/style.py 2194678Snate@binkert.org 2205871Snate@binkert.org[hooks] 2215871Snate@binkert.orgpretxncommit.style = python:style.check_style 2225871Snate@binkert.orgpre-qrefresh.style = python:style.check_style 2235871Snate@binkert.org# End of SConstruct additions 2245871Snate@binkert.org 2255871Snate@binkert.org""" % (main.root.abspath) 2265871Snate@binkert.org 2275871Snate@binkert.orgmercurial_lib_not_found = """ 2285871Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook. If 2295871Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 2304678Snate@binkert.orghook. It is important. 2315871Snate@binkert.org""" 2324678Snate@binkert.org 2335871Snate@binkert.org# Check for style hook and prompt for installation if it's not there. 2345871Snate@binkert.org# Skip this if --ignore-style was specified, there's no .hg dir to 2355871Snate@binkert.org# install a hook in, or there's no interactive terminal to prompt. 2365871Snate@binkert.orgif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2375871Snate@binkert.org style_hook = True 2385871Snate@binkert.org try: 2395871Snate@binkert.org from mercurial import ui 2405871Snate@binkert.org ui = ui.ui() 2415871Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2425990Ssaidi@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2435863Snate@binkert.org ui.config('hooks', 'pre-qrefresh.style', None) 244955SN/A except ImportError: 245955SN/A print mercurial_lib_not_found 2462632Sstever@eecs.umich.edu 2472632Sstever@eecs.umich.edu if not style_hook: 248955SN/A print mercurial_style_message, 249955SN/A # continue unless user does ctrl-c/ctrl-d etc. 250955SN/A try: 251955SN/A raw_input() 2525863Snate@binkert.org except: 253955SN/A print "Input exception, exiting scons.\n" 2542632Sstever@eecs.umich.edu sys.exit(1) 2552632Sstever@eecs.umich.edu hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2562632Sstever@eecs.umich.edu print "Adding style hook to", hgrc_path, "\n" 2572632Sstever@eecs.umich.edu try: 2582632Sstever@eecs.umich.edu hgrc = open(hgrc_path, 'a') 2592632Sstever@eecs.umich.edu hgrc.write(mercurial_style_hook) 2602632Sstever@eecs.umich.edu hgrc.close() 2612632Sstever@eecs.umich.edu except: 2622632Sstever@eecs.umich.edu print "Error updating", hgrc_path 2632632Sstever@eecs.umich.edu sys.exit(1) 2642632Sstever@eecs.umich.edu 2652632Sstever@eecs.umich.edu 2662632Sstever@eecs.umich.edu################################################### 2673718Sstever@eecs.umich.edu# 2683718Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2693718Sstever@eecs.umich.edu# the target(s). 2703718Sstever@eecs.umich.edu# 2713718Sstever@eecs.umich.edu################################################### 2725863Snate@binkert.org 2735863Snate@binkert.org# Find default configuration & binary. 2743718Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2753718Sstever@eecs.umich.edu 2765863Snate@binkert.org# helper function: find last occurrence of element in list 2775863Snate@binkert.orgdef rfind(l, elt, offs = -1): 2783718Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2793718Sstever@eecs.umich.edu if l[i] == elt: 2802634Sstever@eecs.umich.edu return i 2812634Sstever@eecs.umich.edu raise ValueError, "element not found" 2825863Snate@binkert.org 2832638Sstever@eecs.umich.edu# Take a list of paths (or SCons Nodes) and return a list with all 2842632Sstever@eecs.umich.edu# paths made absolute and ~-expanded. Paths will be interpreted 2852632Sstever@eecs.umich.edu# relative to the launch directory unless a different root is provided 2862632Sstever@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 2872632Sstever@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 2882632Sstever@eecs.umich.edu for p in path_list] 2892632Sstever@eecs.umich.edu 2901858SN/A# Each target must have 'build' in the interior of the path; the 2913716Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2922638Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2932638Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 2942638Sstever@eecs.umich.edu# follow 'build' in the build path. 2952638Sstever@eecs.umich.edu 2962638Sstever@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 2972638Sstever@eecs.umich.edu# in place rather than reassign the symbol to a new list, which 2982638Sstever@eecs.umich.edu# doesn't work (obviously!). 2995863Snate@binkert.orgBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 3005863Snate@binkert.org 3015863Snate@binkert.org# Generate a list of the unique build roots and configs that the 302955SN/A# collected targets reference. 3035341Sstever@gmail.comvariant_paths = [] 3045341Sstever@gmail.combuild_root = None 3055863Snate@binkert.orgfor t in BUILD_TARGETS: 3065341Sstever@gmail.com path_dirs = t.split('/') 3074494Ssaidi@eecs.umich.edu try: 3084494Ssaidi@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 3095863Snate@binkert.org except: 3101105SN/A print "Error: no non-leaf 'build' dir found on target path", t 3112667Sstever@eecs.umich.edu Exit(1) 3122667Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3132667Sstever@eecs.umich.edu if not build_root: 3142667Sstever@eecs.umich.edu build_root = this_build_root 3152667Sstever@eecs.umich.edu else: 3162667Sstever@eecs.umich.edu if this_build_root != build_root: 3175341Sstever@gmail.com print "Error: build targets not under same build root\n"\ 3185863Snate@binkert.org " %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: 3225863Snate@binkert.org 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): 3265863Snate@binkert.org mkdir(build_root) 3275341Sstever@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 3335341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up 3345341Sstever@gmail.com# when you use emacs to edit a file in the target dir, as emacs moves 3355341Sstever@gmail.com# file to file~ then copies to file, breaking the link. Symbolic 3365341Sstever@gmail.com# (soft) links work better. 3375863Snate@binkert.orgmain.SetOption('duplicate', 'soft-copy') 3385341Sstever@gmail.com 3395863Snate@binkert.org# 3405341Sstever@gmail.com# Set up global sticky variables... these are common to an entire build 3415863Snate@binkert.org# tree (not specific to a particular build like ALPHA_SE) 3425863Snate@binkert.org# 3435863Snate@binkert.org 3445397Ssaidi@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 3455397Ssaidi@eecs.umich.edu 3465341Sstever@gmail.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3475341Sstever@gmail.com 3485341Sstever@gmail.comglobal_vars.AddVariables( 3495341Sstever@gmail.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 3505341Sstever@gmail.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3515341Sstever@gmail.com ('BATCH', 'Use batch pool for build and tests', False), 3525341Sstever@gmail.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3535341Sstever@gmail.com ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3545863Snate@binkert.org ('EXTRAS', 'Add extra directories to the compilation', '') 3555341Sstever@gmail.com ) 3565341Sstever@gmail.com 3575863Snate@binkert.org# Update main environment with values from ARGUMENTS & global_vars_file 3585341Sstever@gmail.comglobal_vars.Update(main) 3595863Snate@binkert.orghelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3605863Snate@binkert.org 3615341Sstever@gmail.com# Save sticky variable settings back to current variables file 3625863Snate@binkert.orgglobal_vars.Save(global_vars_file, main) 3635863Snate@binkert.org 3645341Sstever@gmail.com# Parse EXTRAS variable to build list of all directories where we're 3655863Snate@binkert.org# look for sources etc. This list is exported as extras_dir_list. 3665341Sstever@gmail.combase_dir = main.srcdir.abspath 3675871Snate@binkert.orgif main['EXTRAS']: 3685341Sstever@gmail.com extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3695742Snate@binkert.orgelse: 3705742Snate@binkert.org extras_dir_list = [] 3715742Snate@binkert.org 3725341Sstever@gmail.comExport('base_dir') 3735742Snate@binkert.orgExport('extras_dir_list') 3745742Snate@binkert.org 3755341Sstever@gmail.com# the ext directory should be on the #includes path 3762632Sstever@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3776016Snate@binkert.org 3785871Snate@binkert.orgdef strip_build_path(path, env): 3795871Snate@binkert.org path = str(path) 3805871Snate@binkert.org variant_base = env['BUILDROOT'] + os.path.sep 3815871Snate@binkert.org if path.startswith(variant_base): 3825871Snate@binkert.org path = path[len(variant_base):] 3835871Snate@binkert.org elif path.startswith('build/'): 3845871Snate@binkert.org path = path[6:] 3853942Ssaidi@eecs.umich.edu return path 3863940Ssaidi@eecs.umich.edu 3873918Ssaidi@eecs.umich.edu# Generate a string of the form: 3883918Ssaidi@eecs.umich.edu# common/path/prefix/src1, src2 -> tgt1, tgt2 3891858SN/A# to print while building. 3903918Ssaidi@eecs.umich.educlass Transform(object): 3913918Ssaidi@eecs.umich.edu # all specific color settings should be here and nowhere else 3923918Ssaidi@eecs.umich.edu tool_color = termcap.Normal 3933918Ssaidi@eecs.umich.edu pfx_color = termcap.Yellow 3945571Snate@binkert.org srcs_color = termcap.Yellow + termcap.Bold 3953940Ssaidi@eecs.umich.edu arrow_color = termcap.Blue + termcap.Bold 3963940Ssaidi@eecs.umich.edu tgts_color = termcap.Yellow + termcap.Bold 3973918Ssaidi@eecs.umich.edu 3983918Ssaidi@eecs.umich.edu def __init__(self, tool, max_sources=99): 3993918Ssaidi@eecs.umich.edu self.format = self.tool_color + (" [%8s] " % tool) \ 4003918Ssaidi@eecs.umich.edu + self.pfx_color + "%s" \ 4013918Ssaidi@eecs.umich.edu + self.srcs_color + "%s" \ 4023918Ssaidi@eecs.umich.edu + self.arrow_color + " -> " \ 4035871Snate@binkert.org + self.tgts_color + "%s" \ 4043918Ssaidi@eecs.umich.edu + termcap.Normal 4053918Ssaidi@eecs.umich.edu self.max_sources = max_sources 4063940Ssaidi@eecs.umich.edu 4073918Ssaidi@eecs.umich.edu def __call__(self, target, source, env, for_signature=None): 4083918Ssaidi@eecs.umich.edu # truncate source list according to max_sources param 4095397Ssaidi@eecs.umich.edu source = source[0:self.max_sources] 4105397Ssaidi@eecs.umich.edu def strip(f): 4115397Ssaidi@eecs.umich.edu return strip_build_path(str(f), env) 4125708Ssaidi@eecs.umich.edu if len(source) > 0: 4135708Ssaidi@eecs.umich.edu srcs = map(strip, source) 4145708Ssaidi@eecs.umich.edu else: 4155708Ssaidi@eecs.umich.edu srcs = [''] 4165708Ssaidi@eecs.umich.edu tgts = map(strip, target) 4175397Ssaidi@eecs.umich.edu # surprisingly, os.path.commonprefix is a dumb char-by-char string 4181851SN/A # operation that has nothing to do with paths. 4191851SN/A com_pfx = os.path.commonprefix(srcs + tgts) 4201858SN/A com_pfx_len = len(com_pfx) 4215200Sstever@gmail.com if com_pfx: 422955SN/A # do some cleanup and sanity checking on common prefix 4233053Sstever@eecs.umich.edu if com_pfx[-1] == ".": 4243053Sstever@eecs.umich.edu # prefix matches all but file extension: ok 4253053Sstever@eecs.umich.edu # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4263053Sstever@eecs.umich.edu com_pfx = com_pfx[0:-1] 4273053Sstever@eecs.umich.edu elif com_pfx[-1] == "/": 4283053Sstever@eecs.umich.edu # common prefix is directory path: OK 4293053Sstever@eecs.umich.edu pass 4305871Snate@binkert.org else: 4313053Sstever@eecs.umich.edu src0_len = len(srcs[0]) 4324742Sstever@eecs.umich.edu tgt0_len = len(tgts[0]) 4334742Sstever@eecs.umich.edu if src0_len == com_pfx_len: 4343053Sstever@eecs.umich.edu # source is a substring of target, OK 4353053Sstever@eecs.umich.edu pass 4363053Sstever@eecs.umich.edu elif tgt0_len == com_pfx_len: 4373053Sstever@eecs.umich.edu # target is a substring of source, need to back up to 4383053Sstever@eecs.umich.edu # avoid empty string on RHS of arrow 4393053Sstever@eecs.umich.edu sep_idx = com_pfx.rfind(".") 4403053Sstever@eecs.umich.edu if sep_idx != -1: 4413053Sstever@eecs.umich.edu com_pfx = com_pfx[0:sep_idx] 4423053Sstever@eecs.umich.edu else: 4432667Sstever@eecs.umich.edu com_pfx = '' 4444554Sbinkertn@umich.edu elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4454554Sbinkertn@umich.edu # still splitting at file extension: ok 4462667Sstever@eecs.umich.edu pass 4474554Sbinkertn@umich.edu else: 4484554Sbinkertn@umich.edu # probably a fluke; ignore it 4494554Sbinkertn@umich.edu com_pfx = '' 4504554Sbinkertn@umich.edu # recalculate length in case com_pfx was modified 4514554Sbinkertn@umich.edu com_pfx_len = len(com_pfx) 4524554Sbinkertn@umich.edu def fmt(files): 4534554Sbinkertn@umich.edu f = map(lambda s: s[com_pfx_len:], files) 4544781Snate@binkert.org return ', '.join(f) 4554554Sbinkertn@umich.edu return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4564554Sbinkertn@umich.edu 4572667Sstever@eecs.umich.eduExport('Transform') 4584554Sbinkertn@umich.edu 4594554Sbinkertn@umich.edu# enable the regression script to use the termcap 4604554Sbinkertn@umich.edumain['TERMCAP'] = termcap 4614554Sbinkertn@umich.edu 4622667Sstever@eecs.umich.eduif GetOption('verbose'): 4634554Sbinkertn@umich.edu def MakeAction(action, string, *args, **kwargs): 4642667Sstever@eecs.umich.edu return Action(action, *args, **kwargs) 4654554Sbinkertn@umich.eduelse: 4664554Sbinkertn@umich.edu MakeAction = Action 4672667Sstever@eecs.umich.edu main['CCCOMSTR'] = Transform("CC") 4685522Snate@binkert.org main['CXXCOMSTR'] = Transform("CXX") 4695522Snate@binkert.org main['ASCOMSTR'] = Transform("AS") 4705522Snate@binkert.org main['SWIGCOMSTR'] = Transform("SWIG") 4715522Snate@binkert.org main['ARCOMSTR'] = Transform("AR", 0) 4725522Snate@binkert.org main['LINKCOMSTR'] = Transform("LINK", 0) 4735522Snate@binkert.org main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4745522Snate@binkert.org main['M4COMSTR'] = Transform("M4") 4755522Snate@binkert.org main['SHCCCOMSTR'] = Transform("SHCC") 4765522Snate@binkert.org main['SHCXXCOMSTR'] = Transform("SHCXX") 4775522Snate@binkert.orgExport('MakeAction') 4785522Snate@binkert.org 4795522Snate@binkert.orgCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4805522Snate@binkert.orgCXX_V = readCommand([main['CXX'],'-V'], exception=False) 4815522Snate@binkert.org 4825522Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4835522Snate@binkert.orgmain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4845522Snate@binkert.orgmain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4855522Snate@binkert.orgmain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 4865522Snate@binkert.orgif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: 4875522Snate@binkert.org print 'Error: How can we have two at the same time?' 4885522Snate@binkert.org Exit(1) 4895522Snate@binkert.org 4905522Snate@binkert.org# Set up default C++ compiler flags 4915522Snate@binkert.orgif main['GCC']: 4925522Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 4935522Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 4942638Sstever@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4952638Sstever@eecs.umich.edu # Read the GCC version to check for versions with bugs 4962638Sstever@eecs.umich.edu # Note CCVERSION doesn't work here because it is run with the CC 4973716Sstever@eecs.umich.edu # before we override it from the command line 4985522Snate@binkert.org gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4995522Snate@binkert.org main['GCC_VERSION'] = gcc_version 5005522Snate@binkert.org if not compareVersions(gcc_version, '4.4.1') or \ 5015522Snate@binkert.org not compareVersions(gcc_version, '4.4.2'): 5025522Snate@binkert.org print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5035522Snate@binkert.org main.Append(CCFLAGS=['-fno-tree-vectorize']) 5041858SN/A if compareVersions(gcc_version, '4.6') >= 0: 5055227Ssaidi@eecs.umich.edu main.Append(CXXFLAGS=['-std=c++0x']) 5065227Ssaidi@eecs.umich.eduelif main['ICC']: 5075227Ssaidi@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 5085227Ssaidi@eecs.umich.eduelif main['SUNCC']: 5095227Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Qoption ccfe']) 5105863Snate@binkert.org main.Append(CCFLAGS=['-features=gcc']) 5115227Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-features=extensions']) 5125227Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-library=stlport4']) 5135227Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-xar']) 5145227Ssaidi@eecs.umich.edu #main.Append(CCFLAGS=['-instances=semiexplicit']) 5155227Ssaidi@eecs.umich.eduelif main['CLANG']: 5165227Ssaidi@eecs.umich.edu clang_version_re = re.compile(".* version (\d+\.\d+)") 5175227Ssaidi@eecs.umich.edu clang_version_match = clang_version_re.match(CXX_version) 5185204Sstever@gmail.com if (clang_version_match): 5195204Sstever@gmail.com clang_version = clang_version_match.groups()[0] 5205204Sstever@gmail.com if compareVersions(clang_version, "2.9") < 0: 5215204Sstever@gmail.com print 'Error: clang version 2.9 or newer required.' 5225204Sstever@gmail.com print ' Installed version:', clang_version 5235204Sstever@gmail.com Exit(1) 5245204Sstever@gmail.com else: 5255204Sstever@gmail.com print 'Error: Unable to determine clang version.' 5265204Sstever@gmail.com Exit(1) 5275204Sstever@gmail.com 5285204Sstever@gmail.com main.Append(CCFLAGS=['-pipe']) 5295204Sstever@gmail.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 5305204Sstever@gmail.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5315204Sstever@gmail.com main.Append(CCFLAGS=['-Wno-tautological-compare']) 5325204Sstever@gmail.com main.Append(CCFLAGS=['-Wno-self-assign']) 5335204Sstever@gmail.com # Ruby makes frequent use of extraneous parantheses in the printing 5345204Sstever@gmail.com # of if-statements 5355204Sstever@gmail.com main.Append(CCFLAGS=['-Wno-parentheses']) 5365204Sstever@gmail.com 5373118Sstever@eecs.umich.edu if compareVersions(clang_version, "3") >= 0: 5383118Sstever@eecs.umich.edu main.Append(CXXFLAGS=['-std=c++0x']) 5393118Sstever@eecs.umich.eduelse: 5403118Sstever@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 5413118Sstever@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 5425863Snate@binkert.org Exit(1) 5433118Sstever@eecs.umich.edu 5445863Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby) 5453118Sstever@eecs.umich.edumain['YACCFLAGS'] = '-d' 5465863Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh' 5475863Snate@binkert.org 5485863Snate@binkert.org# Do this after we save setting back, or else we'll tack on an 5495863Snate@binkert.org# extra 'qdo' every time we run scons. 5505863Snate@binkert.orgif main['BATCH']: 5515863Snate@binkert.org main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5525863Snate@binkert.org main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5535863Snate@binkert.org main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5546003Snate@binkert.org main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5555863Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5565863Snate@binkert.org 5575863Snate@binkert.orgif sys.platform == 'cygwin': 5585863Snate@binkert.org # cygwin has some header file issues... 5595863Snate@binkert.org main.Append(CCFLAGS=["-Wno-uninitialized"]) 5605863Snate@binkert.org 5615863Snate@binkert.org# Check for SWIG 5625863Snate@binkert.orgif not main.has_key('SWIG'): 5635863Snate@binkert.org print 'Error: SWIG utility not found.' 5645863Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 5655863Snate@binkert.org Exit(1) 5665863Snate@binkert.org 5675863Snate@binkert.org# Check for appropriate SWIG version 5685863Snate@binkert.orgswig_version = readCommand(('swig', '-version'), exception='').split() 5695863Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 5703118Sstever@eecs.umich.eduif len(swig_version) < 3 or \ 5715863Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5723118Sstever@eecs.umich.edu print 'Error determining SWIG version.' 5733118Sstever@eecs.umich.edu Exit(1) 5745863Snate@binkert.org 5755863Snate@binkert.orgmin_swig_version = '1.3.28' 5765863Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0: 5775863Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 5785863Snate@binkert.org print ' Installed version:', swig_version[2] 5795863Snate@binkert.org Exit(1) 5803118Sstever@eecs.umich.edu 5813483Ssaidi@eecs.umich.edu# Set up SWIG flags & scanner 5823494Ssaidi@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5833494Ssaidi@eecs.umich.edumain.Append(SWIGFLAGS=swig_flags) 5843483Ssaidi@eecs.umich.edu 5853483Ssaidi@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 5863483Ssaidi@eecs.umich.edu# stuff for some reason 5873053Sstever@eecs.umich.eduscanners = [] 5883053Sstever@eecs.umich.edufor scanner in main['SCANNERS']: 5893918Ssaidi@eecs.umich.edu skeys = scanner.skeys 5903053Sstever@eecs.umich.edu if skeys == '.i': 5913053Sstever@eecs.umich.edu continue 5923053Sstever@eecs.umich.edu 5933053Sstever@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5943053Sstever@eecs.umich.edu continue 5951858SN/A 5961858SN/A scanners.append(scanner) 5971858SN/A 5981858SN/A# add the new swig scanner that we like better 5991858SN/Afrom SCons.Scanner import ClassicCPP as CPPScanner 6001858SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 6015863Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 6025863Snate@binkert.org 6031859SN/A# replace the scanners list that has what we want 6045863Snate@binkert.orgmain['SCANNERS'] = scanners 6051858SN/A 6065863Snate@binkert.org# Add a custom Check function to the Configure context so that we can 6071858SN/A# figure out if the compiler adds leading underscores to global 6081859SN/A# variables. This is needed for the autogenerated asm files that we 6091859SN/A# use for embedding the python code. 6105863Snate@binkert.orgdef CheckLeading(context): 6113053Sstever@eecs.umich.edu context.Message("Checking for leading underscore in global variables...") 6123053Sstever@eecs.umich.edu # 1) Define a global variable called x from asm so the C compiler 6133053Sstever@eecs.umich.edu # won't change the symbol at all. 6143053Sstever@eecs.umich.edu # 2) Declare that variable. 6151859SN/A # 3) Use the variable 6161859SN/A # 6171859SN/A # If the compiler prepends an underscore, this will successfully 6181859SN/A # link because the external symbol 'x' will be called '_x' which 6191859SN/A # was defined by the asm statement. If the compiler does not 6201859SN/A # prepend an underscore, this will not successfully link because 6211859SN/A # '_x' will have been defined by assembly, while the C portion of 6221859SN/A # the code will be trying to use 'x' 6231862SN/A ret = context.TryLink(''' 6241859SN/A asm(".globl _x; _x: .byte 0"); 6251859SN/A extern int x; 6261859SN/A int main() { return x; } 6275863Snate@binkert.org ''', extension=".c") 6285863Snate@binkert.org context.env.Append(LEADING_UNDERSCORE=ret) 6295863Snate@binkert.org context.Result(ret) 6305863Snate@binkert.org return ret 6311858SN/A 6321858SN/A# Platform-specific configuration. Note again that we assume that all 6335863Snate@binkert.org# builds under a given build root run on the same host platform. 6345863Snate@binkert.orgconf = Configure(main, 6355863Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 6365863Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 6375863Snate@binkert.org custom_tests = { 'CheckLeading' : CheckLeading }) 6385871Snate@binkert.org 6395871Snate@binkert.org# Check for leading underscores. Don't really need to worry either 6402139SN/A# way so don't need to check the return code. 6414202Sbinkertn@umich.educonf.CheckLeading() 6424202Sbinkertn@umich.edu 6432139SN/A# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6442155SN/Atry: 6454202Sbinkertn@umich.edu import platform 6464202Sbinkertn@umich.edu uname = platform.uname() 6474202Sbinkertn@umich.edu if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6482155SN/A if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6495863Snate@binkert.org main.Append(CCFLAGS=['-arch', 'x86_64']) 6501869SN/A main.Append(CFLAGS=['-arch', 'x86_64']) 6511869SN/A main.Append(LINKFLAGS=['-arch', 'x86_64']) 6525863Snate@binkert.org main.Append(ASFLAGS=['-arch', 'x86_64']) 6535863Snate@binkert.orgexcept: 6544202Sbinkertn@umich.edu pass 6555863Snate@binkert.org 6565863Snate@binkert.org# Recent versions of scons substitute a "Null" object for Configure() 6575863Snate@binkert.org# when configuration isn't necessary, e.g., if the "--help" option is 6584202Sbinkertn@umich.edu# present. Unfortuantely this Null object always returns false, 6594202Sbinkertn@umich.edu# breaking all our configuration checks. We replace it with our own 6605863Snate@binkert.org# more optimistic null object that returns True instead. 6615742Snate@binkert.orgif not conf: 6625742Snate@binkert.org def NullCheck(*args, **kwargs): 6635341Sstever@gmail.com return True 6645342Sstever@gmail.com 6655342Sstever@gmail.com class NullConf: 6664202Sbinkertn@umich.edu def __init__(self, env): 6674202Sbinkertn@umich.edu self.env = env 6684202Sbinkertn@umich.edu def Finish(self): 6694202Sbinkertn@umich.edu return self.env 6704202Sbinkertn@umich.edu def __getattr__(self, mname): 6715863Snate@binkert.org return NullCheck 6725863Snate@binkert.org 6735863Snate@binkert.org conf = NullConf(main) 6745863Snate@binkert.org 6755863Snate@binkert.org# Find Python include and library directories for embedding the 6765863Snate@binkert.org# interpreter. For consistency, we will use the same Python 6775863Snate@binkert.org# installation used to run scons (and thus this script). If you want 6785863Snate@binkert.org# to link in an alternate version, see above for instructions on how 6795863Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 6805863Snate@binkert.orgfrom distutils import sysconfig 6815863Snate@binkert.org 6825863Snate@binkert.orgpy_getvar = sysconfig.get_config_var 6835863Snate@binkert.org 6845863Snate@binkert.orgpy_debug = getattr(sys, 'pydebug', False) 6855863Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6865863Snate@binkert.org 6875863Snate@binkert.orgpy_general_include = sysconfig.get_python_inc() 6885863Snate@binkert.orgpy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6895863Snate@binkert.orgpy_includes = [ py_general_include ] 6905863Snate@binkert.orgif py_platform_include != py_general_include: 6915952Ssaidi@eecs.umich.edu py_includes.append(py_platform_include) 6921869SN/A 6931858SN/Apy_lib_path = [ py_getvar('LIBDIR') ] 6945863Snate@binkert.org# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6955863Snate@binkert.org# shared library in prefix/lib/. 6961869SN/Aif not py_getvar('Py_ENABLE_SHARED'): 6971858SN/A py_lib_path.append(py_getvar('LIBPL')) 6985863Snate@binkert.org 6995863Snate@binkert.orgpy_libs = [] 7005863Snate@binkert.orgfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 7015863Snate@binkert.org if not lib.startswith('-l'): 7025952Ssaidi@eecs.umich.edu # Python requires some special flags to link (e.g. -framework 7031858SN/A # common on OS X systems), assume appending preserves order 704955SN/A main.Append(LINKFLAGS=[lib]) 705955SN/A else: 7061869SN/A lib = lib[2:] 7071869SN/A if lib not in py_libs: 7081869SN/A py_libs.append(lib) 7091869SN/Apy_libs.append(py_version) 7101869SN/A 7115863Snate@binkert.orgmain.Append(CPPPATH=py_includes) 7125863Snate@binkert.orgmain.Append(LIBPATH=py_lib_path) 7135863Snate@binkert.org 7141869SN/A# Cache build files in the supplied directory. 7155863Snate@binkert.orgif main['M5_BUILD_CACHE']: 7161869SN/A print 'Using build cache located at', main['M5_BUILD_CACHE'] 7175863Snate@binkert.org CacheDir(main['M5_BUILD_CACHE']) 7181869SN/A 7191869SN/A 7201869SN/A# verify that this stuff works 7211869SN/Aif not conf.CheckHeader('Python.h', '<>'): 7221869SN/A print "Error: can't find Python.h header in", py_includes 7235863Snate@binkert.org Exit(1) 7245863Snate@binkert.org 7251869SN/Afor lib in py_libs: 7261869SN/A if not conf.CheckLib(lib): 7271869SN/A print "Error: can't find library %s required by python" % lib 7281869SN/A Exit(1) 7291869SN/A 7301869SN/A# On Solaris you need to use libsocket for socket ops 7311869SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7325863Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7335863Snate@binkert.org print "Can't find library with socket calls (e.g. accept())" 7341869SN/A Exit(1) 7355863Snate@binkert.org 7365863Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 7373356Sbinkertn@umich.edu# added to the LIBS environment variable. 7383356Sbinkertn@umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7393356Sbinkertn@umich.edu print 'Error: did not find needed zlib compression library '\ 7403356Sbinkertn@umich.edu 'and/or zlib.h header file.' 7413356Sbinkertn@umich.edu print ' Please install zlib and try again.' 7424781Snate@binkert.org Exit(1) 7435863Snate@binkert.org 7445863Snate@binkert.org# Check for librt. 7451869SN/Ahave_posix_clock = \ 7461869SN/A conf.CheckLibWithHeader(None, 'time.h', 'C', 7471869SN/A 'clock_nanosleep(0,0,NULL,NULL);') or \ 7481869SN/A conf.CheckLibWithHeader('rt', 'time.h', 'C', 7491869SN/A 'clock_nanosleep(0,0,NULL,NULL);') 7502638Sstever@eecs.umich.edu 7512638Sstever@eecs.umich.eduif not have_posix_clock: 7525871Snate@binkert.org print "Can't find library for POSIX clocks." 7532638Sstever@eecs.umich.edu 7545749Scws3k@cs.virginia.edu# Check for <fenv.h> (C99 FP environment control) 7555749Scws3k@cs.virginia.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 7565871Snate@binkert.orgif not have_fenv: 7575749Scws3k@cs.virginia.edu print "Warning: Header file <fenv.h> not found." 7581869SN/A print " This host has no IEEE FP rounding mode control." 7591869SN/A 7603546Sgblack@eecs.umich.edu###################################################################### 7613546Sgblack@eecs.umich.edu# 7623546Sgblack@eecs.umich.edu# Finish the configuration 7633546Sgblack@eecs.umich.edu# 7644202Sbinkertn@umich.edumain = conf.Finish() 7655863Snate@binkert.org 7663546Sgblack@eecs.umich.edu###################################################################### 7673546Sgblack@eecs.umich.edu# 7683546Sgblack@eecs.umich.edu# Collect all non-global variables 7693546Sgblack@eecs.umich.edu# 7704781Snate@binkert.org 7715863Snate@binkert.org# Define the universe of supported ISAs 7724781Snate@binkert.orgall_isa_list = [ ] 7734781Snate@binkert.orgExport('all_isa_list') 7744781Snate@binkert.org 7754781Snate@binkert.orgclass CpuModel(object): 7764781Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 7775863Snate@binkert.org know about a particular CPU model.''' 7784781Snate@binkert.org 7794781Snate@binkert.org # Dict of available CPU model objects. Accessible as CpuModel.dict. 7804781Snate@binkert.org dict = {} 7814781Snate@binkert.org list = [] 7823546Sgblack@eecs.umich.edu defaults = [] 7833546Sgblack@eecs.umich.edu 7843546Sgblack@eecs.umich.edu # Constructor. Automatically adds models to CpuModel.dict. 7854781Snate@binkert.org def __init__(self, name, filename, includes, strings, default=False): 7863546Sgblack@eecs.umich.edu self.name = name # name of model 7873546Sgblack@eecs.umich.edu self.filename = filename # filename for output exec code 7883546Sgblack@eecs.umich.edu self.includes = includes # include files needed in exec file 7893546Sgblack@eecs.umich.edu # The 'strings' dict holds all the per-CPU symbols we can 7903546Sgblack@eecs.umich.edu # substitute into templates etc. 7913546Sgblack@eecs.umich.edu self.strings = strings 7923546Sgblack@eecs.umich.edu 7933546Sgblack@eecs.umich.edu # This cpu is enabled by default 7943546Sgblack@eecs.umich.edu self.default = default 7953546Sgblack@eecs.umich.edu 7964202Sbinkertn@umich.edu # Add self to dict 7973546Sgblack@eecs.umich.edu if name in CpuModel.dict: 7983546Sgblack@eecs.umich.edu raise AttributeError, "CpuModel '%s' already registered" % name 7993546Sgblack@eecs.umich.edu CpuModel.dict[name] = self 800955SN/A CpuModel.list.append(name) 801955SN/A 802955SN/AExport('CpuModel') 803955SN/A 8041858SN/A# Sticky variables get saved in the variables file so they persist from 8051858SN/A# one invocation to the next (unless overridden, in which case the new 8061858SN/A# value becomes sticky). 8075863Snate@binkert.orgsticky_vars = Variables(args=ARGUMENTS) 8085863Snate@binkert.orgExport('sticky_vars') 8095343Sstever@gmail.com 8105343Sstever@gmail.com# Sticky variables that should be exported 8115863Snate@binkert.orgexport_vars = [] 8125863Snate@binkert.orgExport('export_vars') 8134773Snate@binkert.org 8145863Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 8152632Sstever@eecs.umich.edu# above variables 8165863Snate@binkert.orgif not GetOption('verbose'): 8172023SN/A print "Reading SConsopts" 8185863Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list: 8195863Snate@binkert.org if not isdir(bdir): 8205863Snate@binkert.org print "Error: directory '%s' does not exist" % bdir 8215863Snate@binkert.org Exit(1) 8225863Snate@binkert.org for root, dirs, files in os.walk(bdir): 8235863Snate@binkert.org if 'SConsopts' in files: 8245863Snate@binkert.org if GetOption('verbose'): 8255863Snate@binkert.org print "Reading", joinpath(root, 'SConsopts') 8265863Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 8272632Sstever@eecs.umich.edu 8285863Snate@binkert.orgall_isa_list.sort() 8292023SN/A 8302632Sstever@eecs.umich.edusticky_vars.AddVariables( 8315863Snate@binkert.org EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 8325342Sstever@gmail.com ListVariable('CPU_MODELS', 'CPU models', 8335863Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 8342632Sstever@eecs.umich.edu sorted(CpuModel.list)), 8355863Snate@binkert.org BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 8365863Snate@binkert.org BoolVariable('FORCE_FAST_ALLOC', 8372632Sstever@eecs.umich.edu 'Enable fast object allocator, even for gem5.debug', False), 8385863Snate@binkert.org BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 8395863Snate@binkert.org False), 8405863Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 8415863Snate@binkert.org False), 8425863Snate@binkert.org BoolVariable('SS_COMPATIBLE_FP', 8435863Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 8442632Sstever@eecs.umich.edu False), 8455863Snate@binkert.org BoolVariable('USE_SSE2', 8465863Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 8472632Sstever@eecs.umich.edu False), 8481888SN/A BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 8495863Snate@binkert.org BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 8505863Snate@binkert.org BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 8515863Snate@binkert.org ) 8521858SN/A 8535863Snate@binkert.org# These variables get exported to #defines in config/*.hh (see src/SConscript). 8545863Snate@binkert.orgexport_vars += ['USE_FENV', 'NO_FAST_ALLOC', 'FORCE_FAST_ALLOC', 8555863Snate@binkert.org 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', 8565863Snate@binkert.org 'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK' ] 8572598SN/A 8585863Snate@binkert.org################################################### 8591858SN/A# 8601858SN/A# Define a SCons builder for configuration flag headers. 8611858SN/A# 8625863Snate@binkert.org################################################### 8631858SN/A 8641858SN/A# This function generates a config header file that #defines the 8651858SN/A# variable symbol to the current variable setting (0 or 1). The source 8665863Snate@binkert.org# operands are the name of the variable and a Value node containing the 8671871SN/A# value of the variable. 8681858SN/Adef build_config_file(target, source, env): 8691858SN/A (variable, value) = [s.get_contents() for s in source] 8701858SN/A f = file(str(target[0]), 'w') 8711858SN/A print >> f, '#define', variable, value 8721858SN/A f.close() 8731858SN/A return None 8741858SN/A 8755863Snate@binkert.org# Combine the two functions into a scons Action object. 8761858SN/Aconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 8771858SN/A 8785863Snate@binkert.org# The emitter munges the source & target node lists to reflect what 8791859SN/A# we're really doing. 8801859SN/Adef config_emitter(target, source, env): 8811869SN/A # extract variable name from Builder arg 8825863Snate@binkert.org variable = str(target[0]) 8835863Snate@binkert.org # True target is config header file 8841869SN/A target = joinpath('config', variable.lower() + '.hh') 8851965SN/A val = env[variable] 8861965SN/A if isinstance(val, bool): 8871965SN/A # Force value to 0/1 8882761Sstever@eecs.umich.edu val = int(val) 8895863Snate@binkert.org elif isinstance(val, str): 8901869SN/A val = '"' + val + '"' 8915863Snate@binkert.org 8922667Sstever@eecs.umich.edu # Sources are variable name & value (packaged in SCons Value nodes) 8931869SN/A return ([target], [Value(variable), Value(val)]) 8941869SN/A 8952929Sktlim@umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 8962929Sktlim@umich.edu 8975863Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 8982929Sktlim@umich.edu 899955SN/A# libelf build is shared across all configs in the build root. 9002598SN/Amain.SConscript('ext/libelf/SConscript', 901 variant_dir = joinpath(build_root, 'libelf')) 902 903# gzstream build is shared across all configs in the build root. 904main.SConscript('ext/gzstream/SConscript', 905 variant_dir = joinpath(build_root, 'gzstream')) 906 907################################################### 908# 909# This function is used to set up a directory with switching headers 910# 911################################################### 912 913main['ALL_ISA_LIST'] = all_isa_list 914def make_switching_dir(dname, switch_headers, env): 915 # Generate the header. target[0] is the full path of the output 916 # header to generate. 'source' is a dummy variable, since we get the 917 # list of ISAs from env['ALL_ISA_LIST']. 918 def gen_switch_hdr(target, source, env): 919 fname = str(target[0]) 920 f = open(fname, 'w') 921 isa = env['TARGET_ISA'].lower() 922 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 923 f.close() 924 925 # Build SCons Action object. 'varlist' specifies env vars that this 926 # action depends on; when env['ALL_ISA_LIST'] changes these actions 927 # should get re-executed. 928 switch_hdr_action = MakeAction(gen_switch_hdr, 929 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 930 931 # Instantiate actions for each header 932 for hdr in switch_headers: 933 env.Command(hdr, [], switch_hdr_action) 934Export('make_switching_dir') 935 936################################################### 937# 938# Define build environments for selected configurations. 939# 940################################################### 941 942for variant_path in variant_paths: 943 print "Building in", variant_path 944 945 # Make a copy of the build-root environment to use for this config. 946 env = main.Clone() 947 env['BUILDDIR'] = variant_path 948 949 # variant_dir is the tail component of build path, and is used to 950 # determine the build parameters (e.g., 'ALPHA_SE') 951 (build_root, variant_dir) = splitpath(variant_path) 952 953 # Set env variables according to the build directory config. 954 sticky_vars.files = [] 955 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 956 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 957 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 958 current_vars_file = joinpath(build_root, 'variables', variant_dir) 959 if isfile(current_vars_file): 960 sticky_vars.files.append(current_vars_file) 961 print "Using saved variables file %s" % current_vars_file 962 else: 963 # Build dir-specific variables file doesn't exist. 964 965 # Make sure the directory is there so we can create it later 966 opt_dir = dirname(current_vars_file) 967 if not isdir(opt_dir): 968 mkdir(opt_dir) 969 970 # Get default build variables from source tree. Variables are 971 # normally determined by name of $VARIANT_DIR, but can be 972 # overridden by '--default=' arg on command line. 973 default = GetOption('default') 974 opts_dir = joinpath(main.root.abspath, 'build_opts') 975 if default: 976 default_vars_files = [joinpath(build_root, 'variables', default), 977 joinpath(opts_dir, default)] 978 else: 979 default_vars_files = [joinpath(opts_dir, variant_dir)] 980 existing_files = filter(isfile, default_vars_files) 981 if existing_files: 982 default_vars_file = existing_files[0] 983 sticky_vars.files.append(default_vars_file) 984 print "Variables file %s not found,\n using defaults in %s" \ 985 % (current_vars_file, default_vars_file) 986 else: 987 print "Error: cannot find variables file %s or " \ 988 "default file(s) %s" \ 989 % (current_vars_file, ' or '.join(default_vars_files)) 990 Exit(1) 991 992 # Apply current variable settings to env 993 sticky_vars.Update(env) 994 995 help_texts["local_vars"] += \ 996 "Build variables for %s:\n" % variant_dir \ 997 + sticky_vars.GenerateHelpText(env) 998 999 # Process variable settings. 1000 1001 if not have_fenv and env['USE_FENV']: 1002 print "Warning: <fenv.h> not available; " \ 1003 "forcing USE_FENV to False in", variant_dir + "." 1004 env['USE_FENV'] = False 1005 1006 if not env['USE_FENV']: 1007 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 1008 print " FP results may deviate slightly from other platforms." 1009 1010 if env['EFENCE']: 1011 env.Append(LIBS=['efence']) 1012 1013 # Save sticky variable settings back to current variables file 1014 sticky_vars.Save(current_vars_file, env) 1015 1016 if env['USE_SSE2']: 1017 env.Append(CCFLAGS=['-msse2']) 1018 1019 # The src/SConscript file sets up the build rules in 'env' according 1020 # to the configured variables. It returns a list of environments, 1021 # one for each variant build (debug, opt, etc.) 1022 envList = SConscript('src/SConscript', variant_dir = variant_path, 1023 exports = 'env') 1024 1025 # Set up the regression tests for each build. 1026 for e in envList: 1027 SConscript('tests/SConscript', 1028 variant_dir = joinpath(variant_path, 'tests', e.Label), 1029 exports = { 'env' : e }, duplicate = False) 1030 1031# base help text 1032Help(''' 1033Usage: scons [scons options] [build variables] [target(s)] 1034 1035Extra scons options: 1036%(options)s 1037 1038Global build variables: 1039%(global_vars)s 1040 1041%(local_vars)s 1042''' % help_texts) 1043