SConstruct revision 9477
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. 305863Snate@binkert.org# 31955SN/A# Authors: Steve Reinhardt 32955SN/A# Nathan Binkert 33955SN/A 34955SN/A################################################### 35955SN/A# 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 392632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 40955SN/A# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 412632Sstever@eecs.umich.edu# the optimized full-system version). 422632Sstever@eecs.umich.edu# 432761Sstever@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 462632Sstever@eecs.umich.edu# built for the same host system. 472761Sstever@eecs.umich.edu# 482761Sstever@eecs.umich.edu# Examples: 492761Sstever@eecs.umich.edu# 502632Sstever@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. 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 562761Sstever@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 632632Sstever@eecs.umich.edu# '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# 675863Snate@binkert.org################################################### 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""" 98955SN/A raise 995396Ssaidi@eecs.umich.edu 1005863Snate@binkert.org# Global Python includes 1015863Snate@binkert.orgimport os 1024202Sbinkertn@umich.eduimport re 1035863Snate@binkert.orgimport subprocess 1045863Snate@binkert.orgimport sys 1055863Snate@binkert.org 1065863Snate@binkert.orgfrom os import mkdir, environ 107955SN/Afrom os.path import abspath, basename, dirname, expanduser, normpath 1085273Sstever@gmail.comfrom os.path import exists, isdir, isfile 1095273Sstever@gmail.comfrom os.path import join as joinpath, split as splitpath 1105863Snate@binkert.org 1115863Snate@binkert.org# SCons includes 1125863Snate@binkert.orgimport SCons 1135863Snate@binkert.orgimport SCons.Node 1145863Snate@binkert.org 1155863Snate@binkert.orgextra_python_paths = [ 1165227Ssaidi@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 1255588Ssaidi@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: 140955SN/A# http://scons.tigris.org/issues/show_bug.cgi?id=2356 141955SN/A# http://scons.tigris.org/issues/show_bug.cgi?id=2611 142955SN/A# This hack lets us extract the help text from AddOptions and 1433717Sstever@eecs.umich.edu# re-inject it via Help(). Ideally someday this bug will be fixed and 1443716Sstever@eecs.umich.edu# we can just use AddOption directly. 145955SN/Adef AddLocalOption(*args, **kwargs): 1461533SN/A col_width = 30 1473716Sstever@eecs.umich.edu 1481533SN/A help = " " + ", ".join(args) 1495863Snate@binkert.org if "help" in kwargs: 1505863Snate@binkert.org length = len(help) 1515863Snate@binkert.org if length >= col_width: 1525863Snate@binkert.org help += "\n" + " " * col_width 1535863Snate@binkert.org else: 1545863Snate@binkert.org help += " " * (col_width - length) 1555863Snate@binkert.org help += kwargs["help"] 1565863Snate@binkert.org help_texts["options"] += help + "\n" 1575863Snate@binkert.org 1585863Snate@binkert.org AddOption(*args, **kwargs) 1595863Snate@binkert.org 1605863Snate@binkert.orgAddLocalOption('--colors', dest='use_colors', action='store_true', 1615863Snate@binkert.org help="Add color to abbreviated scons output") 1625863Snate@binkert.orgAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1635863Snate@binkert.org help="Don't add color to abbreviated scons output") 1645863Snate@binkert.orgAddLocalOption('--default', dest='default', type='string', action='store', 1655863Snate@binkert.org help='Override which build_opts file to use for defaults') 1665863Snate@binkert.orgAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1675863Snate@binkert.org help='Disable style checking hooks') 1684678Snate@binkert.orgAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1694678Snate@binkert.org help='Disable Link-Time Optimization for fast') 1704678Snate@binkert.orgAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1714678Snate@binkert.org help='Update test reference outputs') 1724678Snate@binkert.orgAddLocalOption('--verbose', dest='verbose', action='store_true', 1734678Snate@binkert.org help='Print full tool command lines') 1744678Snate@binkert.org 1754678Snate@binkert.orgtermcap = get_termcap(GetOption('use_colors')) 1764678Snate@binkert.org 1774678Snate@binkert.org######################################################################## 1784678Snate@binkert.org# 1794678Snate@binkert.org# Set up the main build environment. 1804678Snate@binkert.org# 1814678Snate@binkert.org######################################################################## 1824678Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 1834678Snate@binkert.org 'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PYTHONPATH', 1844678Snate@binkert.org 'RANLIB', 'SWIG' ]) 1854678Snate@binkert.org 1864678Snate@binkert.orguse_prefixes = [ 1874678Snate@binkert.org "M5", # M5 configuration (e.g., path to kernels) 1884678Snate@binkert.org "DISTCC_", # distcc (distributed compiler wrapper) configuration 1894973Ssaidi@eecs.umich.edu "CCACHE_", # ccache (caching compiler wrapper) configuration 1904678Snate@binkert.org "CCC_", # clang static analyzer configuration 1914678Snate@binkert.org ] 1924678Snate@binkert.org 1934678Snate@binkert.orguse_env = {} 1944678Snate@binkert.orgfor key,val in os.environ.iteritems(): 1954678Snate@binkert.org if key in use_vars or \ 1965863Snate@binkert.org any([key.startswith(prefix) for prefix in use_prefixes]): 197955SN/A use_env[key] = val 198955SN/A 1992632Sstever@eecs.umich.edumain = Environment(ENV=use_env) 2002632Sstever@eecs.umich.edumain.Decider('MD5-timestamp') 201955SN/Amain.root = Dir(".") # The current directory (where this file lives). 202955SN/Amain.srcdir = Dir("src") # The source directory 203955SN/A 204955SN/Amain_dict_keys = main.Dictionary().keys() 2055863Snate@binkert.org 206955SN/A# Check that we have a C/C++ compiler 2072632Sstever@eecs.umich.eduif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 2082632Sstever@eecs.umich.edu print "No C++ compiler installed (package g++ on Ubuntu and RedHat)" 2092632Sstever@eecs.umich.edu Exit(1) 2102632Sstever@eecs.umich.edu 2112632Sstever@eecs.umich.edu# Check that swig is present 2122632Sstever@eecs.umich.eduif not 'SWIG' in main_dict_keys: 2132632Sstever@eecs.umich.edu print "swig is not installed (package swig on Ubuntu and RedHat)" 2142632Sstever@eecs.umich.edu Exit(1) 2152632Sstever@eecs.umich.edu 2162632Sstever@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 2172632Sstever@eecs.umich.edu# as well 2182632Sstever@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths) 2192632Sstever@eecs.umich.edu 2203718Sstever@eecs.umich.edu######################################################################## 2213718Sstever@eecs.umich.edu# 2223718Sstever@eecs.umich.edu# Mercurial Stuff. 2233718Sstever@eecs.umich.edu# 2243718Sstever@eecs.umich.edu# If the gem5 directory is a mercurial repository, we should do some 2255863Snate@binkert.org# extra things. 2265863Snate@binkert.org# 2273718Sstever@eecs.umich.edu######################################################################## 2283718Sstever@eecs.umich.edu 2295863Snate@binkert.orghgdir = main.root.Dir(".hg") 2305863Snate@binkert.org 2313718Sstever@eecs.umich.edumercurial_style_message = """ 2323718Sstever@eecs.umich.eduYou're missing the gem5 style hook, which automatically checks your code 2332634Sstever@eecs.umich.eduagainst the gem5 style rules on hg commit and qrefresh commands. This 2342634Sstever@eecs.umich.eduscript will now install the hook in your .hg/hgrc file. 2355863Snate@binkert.orgPress enter to continue, or ctrl-c to abort: """ 2362638Sstever@eecs.umich.edu 2372632Sstever@eecs.umich.edumercurial_style_hook = """ 2382632Sstever@eecs.umich.edu# The following lines were automatically added by gem5/SConstruct 2392632Sstever@eecs.umich.edu# to provide the gem5 style-checking hooks 2402632Sstever@eecs.umich.edu[extensions] 2412632Sstever@eecs.umich.edustyle = %s/util/style.py 2422632Sstever@eecs.umich.edu 2431858SN/A[hooks] 2443716Sstever@eecs.umich.edupretxncommit.style = python:style.check_style 2452638Sstever@eecs.umich.edupre-qrefresh.style = python:style.check_style 2462638Sstever@eecs.umich.edu# End of SConstruct additions 2472638Sstever@eecs.umich.edu 2482638Sstever@eecs.umich.edu""" % (main.root.abspath) 2492638Sstever@eecs.umich.edu 2502638Sstever@eecs.umich.edumercurial_lib_not_found = """ 2512638Sstever@eecs.umich.eduMercurial libraries cannot be found, ignoring style hook. If 2525863Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 2535863Snate@binkert.orghook. It is important. 2545863Snate@binkert.org""" 255955SN/A 2565341Sstever@gmail.com# Check for style hook and prompt for installation if it's not there. 2575341Sstever@gmail.com# Skip this if --ignore-style was specified, there's no .hg dir to 2585863Snate@binkert.org# install a hook in, or there's no interactive terminal to prompt. 2595341Sstever@gmail.comif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 260955SN/A style_hook = True 261955SN/A try: 262955SN/A from mercurial import ui 263955SN/A ui = ui.ui() 264955SN/A ui.readconfig(hgdir.File('hgrc').abspath) 265955SN/A style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 266955SN/A ui.config('hooks', 'pre-qrefresh.style', None) 2675863Snate@binkert.org except ImportError: 2681858SN/A print mercurial_lib_not_found 2695863Snate@binkert.org 2705863Snate@binkert.org if not style_hook: 271955SN/A print mercurial_style_message, 2724494Ssaidi@eecs.umich.edu # continue unless user does ctrl-c/ctrl-d etc. 2734494Ssaidi@eecs.umich.edu try: 2745863Snate@binkert.org raw_input() 2751105SN/A except: 2762667Sstever@eecs.umich.edu print "Input exception, exiting scons.\n" 2772667Sstever@eecs.umich.edu sys.exit(1) 2782667Sstever@eecs.umich.edu hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2792667Sstever@eecs.umich.edu print "Adding style hook to", hgrc_path, "\n" 2802667Sstever@eecs.umich.edu try: 2812667Sstever@eecs.umich.edu hgrc = open(hgrc_path, 'a') 2825341Sstever@gmail.com hgrc.write(mercurial_style_hook) 2835863Snate@binkert.org hgrc.close() 2845341Sstever@gmail.com except: 2855341Sstever@gmail.com print "Error updating", hgrc_path 2865341Sstever@gmail.com sys.exit(1) 2875863Snate@binkert.org 2885341Sstever@gmail.com 2895341Sstever@gmail.com################################################### 2905341Sstever@gmail.com# 2915863Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 2925341Sstever@gmail.com# the target(s). 2935341Sstever@gmail.com# 2945341Sstever@gmail.com################################################### 2955341Sstever@gmail.com 2965341Sstever@gmail.com# Find default configuration & binary. 2975341Sstever@gmail.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2985341Sstever@gmail.com 2995341Sstever@gmail.com# helper function: find last occurrence of element in list 3005341Sstever@gmail.comdef rfind(l, elt, offs = -1): 3015341Sstever@gmail.com for i in range(len(l)+offs, 0, -1): 3025863Snate@binkert.org if l[i] == elt: 3035341Sstever@gmail.com return i 3045863Snate@binkert.org raise ValueError, "element not found" 3055341Sstever@gmail.com 3065863Snate@binkert.org# Take a list of paths (or SCons Nodes) and return a list with all 3075863Snate@binkert.org# paths made absolute and ~-expanded. Paths will be interpreted 3085863Snate@binkert.org# relative to the launch directory unless a different root is provided 3095397Ssaidi@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 3105397Ssaidi@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 3115341Sstever@gmail.com for p in path_list] 3125341Sstever@gmail.com 3135341Sstever@gmail.com# Each target must have 'build' in the interior of the path; the 3145341Sstever@gmail.com# directory below this will determine the build parameters. For 3155341Sstever@gmail.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 3165341Sstever@gmail.com# recognize that ALPHA_SE specifies the configuration because it 3175341Sstever@gmail.com# follow 'build' in the build path. 3185341Sstever@gmail.com 3195863Snate@binkert.org# The funky assignment to "[:]" is needed to replace the list contents 3205341Sstever@gmail.com# in place rather than reassign the symbol to a new list, which 3215341Sstever@gmail.com# doesn't work (obviously!). 3225863Snate@binkert.orgBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 3235341Sstever@gmail.com 3245863Snate@binkert.org# Generate a list of the unique build roots and configs that the 3255863Snate@binkert.org# collected targets reference. 3265341Sstever@gmail.comvariant_paths = [] 3275863Snate@binkert.orgbuild_root = None 3285863Snate@binkert.orgfor t in BUILD_TARGETS: 3295341Sstever@gmail.com path_dirs = t.split('/') 3305863Snate@binkert.org try: 3315341Sstever@gmail.com build_top = rfind(path_dirs, 'build', -2) 3325742Snate@binkert.org except: 3335341Sstever@gmail.com print "Error: no non-leaf 'build' dir found on target path", t 3345742Snate@binkert.org Exit(1) 3355742Snate@binkert.org this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3365742Snate@binkert.org if not build_root: 3375341Sstever@gmail.com build_root = this_build_root 3385742Snate@binkert.org else: 3395742Snate@binkert.org if this_build_root != build_root: 3405341Sstever@gmail.com print "Error: build targets not under same build root\n"\ 3412632Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 3425199Sstever@gmail.com Exit(1) 3435863Snate@binkert.org variant_path = joinpath('/',*path_dirs[:build_top+2]) 3445863Snate@binkert.org if variant_path not in variant_paths: 3455863Snate@binkert.org variant_paths.append(variant_path) 3463942Ssaidi@eecs.umich.edu 3473940Ssaidi@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 3483918Ssaidi@eecs.umich.eduif not isdir(build_root): 3493918Ssaidi@eecs.umich.edu mkdir(build_root) 3501858SN/Amain['BUILDROOT'] = build_root 3513918Ssaidi@eecs.umich.edu 3523918Ssaidi@eecs.umich.eduExport('main') 3533918Ssaidi@eecs.umich.edu 3543918Ssaidi@eecs.umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 3555571Snate@binkert.org 3563940Ssaidi@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 3573940Ssaidi@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 3583918Ssaidi@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 3593918Ssaidi@eecs.umich.edu# (soft) links work better. 3603918Ssaidi@eecs.umich.edumain.SetOption('duplicate', 'soft-copy') 3613918Ssaidi@eecs.umich.edu 3623918Ssaidi@eecs.umich.edu# 3633918Ssaidi@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 3643918Ssaidi@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 3653918Ssaidi@eecs.umich.edu# 3663918Ssaidi@eecs.umich.edu 3673940Ssaidi@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 3683918Ssaidi@eecs.umich.edu 3693918Ssaidi@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3705397Ssaidi@eecs.umich.edu 3715397Ssaidi@eecs.umich.eduglobal_vars.AddVariables( 3725397Ssaidi@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3735708Ssaidi@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3745708Ssaidi@eecs.umich.edu ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 3755708Ssaidi@eecs.umich.edu ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 3765708Ssaidi@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3775708Ssaidi@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3785397Ssaidi@eecs.umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3791851SN/A ('EXTRAS', 'Add extra directories to the compilation', '') 3801851SN/A ) 3811858SN/A 3825200Sstever@gmail.com# Update main environment with values from ARGUMENTS & global_vars_file 383955SN/Aglobal_vars.Update(main) 3843053Sstever@eecs.umich.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3853053Sstever@eecs.umich.edu 3863053Sstever@eecs.umich.edu# Save sticky variable settings back to current variables file 3873053Sstever@eecs.umich.eduglobal_vars.Save(global_vars_file, main) 3883053Sstever@eecs.umich.edu 3893053Sstever@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3903053Sstever@eecs.umich.edu# look for sources etc. This list is exported as extras_dir_list. 3915863Snate@binkert.orgbase_dir = main.srcdir.abspath 3923053Sstever@eecs.umich.eduif main['EXTRAS']: 3934742Sstever@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3944742Sstever@eecs.umich.eduelse: 3953053Sstever@eecs.umich.edu extras_dir_list = [] 3963053Sstever@eecs.umich.edu 3973053Sstever@eecs.umich.eduExport('base_dir') 3983053Sstever@eecs.umich.eduExport('extras_dir_list') 3993053Sstever@eecs.umich.edu 4003053Sstever@eecs.umich.edu# the ext directory should be on the #includes path 4013053Sstever@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 4023053Sstever@eecs.umich.edu 4033053Sstever@eecs.umich.edudef strip_build_path(path, env): 4042667Sstever@eecs.umich.edu path = str(path) 4054554Sbinkertn@umich.edu variant_base = env['BUILDROOT'] + os.path.sep 4064554Sbinkertn@umich.edu if path.startswith(variant_base): 4072667Sstever@eecs.umich.edu path = path[len(variant_base):] 4084554Sbinkertn@umich.edu elif path.startswith('build/'): 4094554Sbinkertn@umich.edu path = path[6:] 4104554Sbinkertn@umich.edu return path 4114554Sbinkertn@umich.edu 4124554Sbinkertn@umich.edu# Generate a string of the form: 4134554Sbinkertn@umich.edu# common/path/prefix/src1, src2 -> tgt1, tgt2 4144554Sbinkertn@umich.edu# to print while building. 4154781Snate@binkert.orgclass Transform(object): 4164554Sbinkertn@umich.edu # all specific color settings should be here and nowhere else 4174554Sbinkertn@umich.edu tool_color = termcap.Normal 4182667Sstever@eecs.umich.edu pfx_color = termcap.Yellow 4194554Sbinkertn@umich.edu srcs_color = termcap.Yellow + termcap.Bold 4204554Sbinkertn@umich.edu arrow_color = termcap.Blue + termcap.Bold 4214554Sbinkertn@umich.edu tgts_color = termcap.Yellow + termcap.Bold 4224554Sbinkertn@umich.edu 4232667Sstever@eecs.umich.edu def __init__(self, tool, max_sources=99): 4244554Sbinkertn@umich.edu self.format = self.tool_color + (" [%8s] " % tool) \ 4252667Sstever@eecs.umich.edu + self.pfx_color + "%s" \ 4264554Sbinkertn@umich.edu + self.srcs_color + "%s" \ 4274554Sbinkertn@umich.edu + self.arrow_color + " -> " \ 4282667Sstever@eecs.umich.edu + self.tgts_color + "%s" \ 4295522Snate@binkert.org + termcap.Normal 4305522Snate@binkert.org self.max_sources = max_sources 4315522Snate@binkert.org 4325522Snate@binkert.org def __call__(self, target, source, env, for_signature=None): 4335522Snate@binkert.org # truncate source list according to max_sources param 4345522Snate@binkert.org source = source[0:self.max_sources] 4355522Snate@binkert.org def strip(f): 4365522Snate@binkert.org return strip_build_path(str(f), env) 4375522Snate@binkert.org if len(source) > 0: 4385522Snate@binkert.org srcs = map(strip, source) 4395522Snate@binkert.org else: 4405522Snate@binkert.org srcs = [''] 4415522Snate@binkert.org tgts = map(strip, target) 4425522Snate@binkert.org # surprisingly, os.path.commonprefix is a dumb char-by-char string 4435522Snate@binkert.org # operation that has nothing to do with paths. 4445522Snate@binkert.org com_pfx = os.path.commonprefix(srcs + tgts) 4455522Snate@binkert.org com_pfx_len = len(com_pfx) 4465522Snate@binkert.org if com_pfx: 4475522Snate@binkert.org # do some cleanup and sanity checking on common prefix 4485522Snate@binkert.org if com_pfx[-1] == ".": 4495522Snate@binkert.org # prefix matches all but file extension: ok 4505522Snate@binkert.org # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4515522Snate@binkert.org com_pfx = com_pfx[0:-1] 4525522Snate@binkert.org elif com_pfx[-1] == "/": 4535522Snate@binkert.org # common prefix is directory path: OK 4545522Snate@binkert.org pass 4552638Sstever@eecs.umich.edu else: 4562638Sstever@eecs.umich.edu src0_len = len(srcs[0]) 4572638Sstever@eecs.umich.edu tgt0_len = len(tgts[0]) 4583716Sstever@eecs.umich.edu if src0_len == com_pfx_len: 4595522Snate@binkert.org # source is a substring of target, OK 4605522Snate@binkert.org pass 4615522Snate@binkert.org elif tgt0_len == com_pfx_len: 4625522Snate@binkert.org # target is a substring of source, need to back up to 4635522Snate@binkert.org # avoid empty string on RHS of arrow 4645522Snate@binkert.org sep_idx = com_pfx.rfind(".") 4651858SN/A if sep_idx != -1: 4665227Ssaidi@eecs.umich.edu com_pfx = com_pfx[0:sep_idx] 4675227Ssaidi@eecs.umich.edu else: 4685227Ssaidi@eecs.umich.edu com_pfx = '' 4695227Ssaidi@eecs.umich.edu elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4705227Ssaidi@eecs.umich.edu # still splitting at file extension: ok 4715863Snate@binkert.org pass 4725227Ssaidi@eecs.umich.edu else: 4735227Ssaidi@eecs.umich.edu # probably a fluke; ignore it 4745227Ssaidi@eecs.umich.edu com_pfx = '' 4755227Ssaidi@eecs.umich.edu # recalculate length in case com_pfx was modified 4765227Ssaidi@eecs.umich.edu com_pfx_len = len(com_pfx) 4775227Ssaidi@eecs.umich.edu def fmt(files): 4785227Ssaidi@eecs.umich.edu f = map(lambda s: s[com_pfx_len:], files) 4795204Sstever@gmail.com return ', '.join(f) 4805204Sstever@gmail.com return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4815204Sstever@gmail.com 4825204Sstever@gmail.comExport('Transform') 4835204Sstever@gmail.com 4845204Sstever@gmail.com# enable the regression script to use the termcap 4855204Sstever@gmail.commain['TERMCAP'] = termcap 4865204Sstever@gmail.com 4875204Sstever@gmail.comif GetOption('verbose'): 4885204Sstever@gmail.com def MakeAction(action, string, *args, **kwargs): 4895204Sstever@gmail.com return Action(action, *args, **kwargs) 4905204Sstever@gmail.comelse: 4915204Sstever@gmail.com MakeAction = Action 4925204Sstever@gmail.com main['CCCOMSTR'] = Transform("CC") 4935204Sstever@gmail.com main['CXXCOMSTR'] = Transform("CXX") 4945204Sstever@gmail.com main['ASCOMSTR'] = Transform("AS") 4955204Sstever@gmail.com main['SWIGCOMSTR'] = Transform("SWIG") 4965204Sstever@gmail.com main['ARCOMSTR'] = Transform("AR", 0) 4975204Sstever@gmail.com main['LINKCOMSTR'] = Transform("LINK", 0) 4983118Sstever@eecs.umich.edu main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4993118Sstever@eecs.umich.edu main['M4COMSTR'] = Transform("M4") 5003118Sstever@eecs.umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 5013118Sstever@eecs.umich.edu main['SHCXXCOMSTR'] = Transform("SHCXX") 5023118Sstever@eecs.umich.eduExport('MakeAction') 5035863Snate@binkert.org 5043118Sstever@eecs.umich.edu# Initialize the Link-Time Optimization (LTO) flags 5055863Snate@binkert.orgmain['LTO_CCFLAGS'] = [] 5063118Sstever@eecs.umich.edumain['LTO_LDFLAGS'] = [] 5075863Snate@binkert.org 5085863Snate@binkert.orgCXX_version = readCommand([main['CXX'],'--version'], exception=False) 5095863Snate@binkert.orgCXX_V = readCommand([main['CXX'],'-V'], exception=False) 5105863Snate@binkert.org 5115863Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 5125863Snate@binkert.orgmain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 5135863Snate@binkert.orgif main['GCC'] + main['CLANG'] > 1: 5145863Snate@binkert.org print 'Error: How can we have two at the same time?' 5155863Snate@binkert.org Exit(1) 5165863Snate@binkert.org 5175863Snate@binkert.org# Set up default C++ compiler flags 5185863Snate@binkert.orgif main['GCC']: 5195863Snate@binkert.org # Check for a supported version of gcc, >= 4.4 is needed for c++0x 5205863Snate@binkert.org # support. See http://gcc.gnu.org/projects/cxx0x.html for details 5215863Snate@binkert.org gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5225863Snate@binkert.org if compareVersions(gcc_version, "4.4") < 0: 5235863Snate@binkert.org print 'Error: gcc version 4.4 or newer required.' 5245863Snate@binkert.org print ' Installed version:', gcc_version 5255863Snate@binkert.org Exit(1) 5265863Snate@binkert.org 5275863Snate@binkert.org main['GCC_VERSION'] = gcc_version 5285863Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 5295863Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 5305863Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5315863Snate@binkert.org main.Append(CXXFLAGS=['-std=c++0x']) 5323118Sstever@eecs.umich.edu 5335863Snate@binkert.org # Check for versions with bugs 5343118Sstever@eecs.umich.edu if not compareVersions(gcc_version, '4.4.1') or \ 5353118Sstever@eecs.umich.edu not compareVersions(gcc_version, '4.4.2'): 5365863Snate@binkert.org print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5375863Snate@binkert.org main.Append(CCFLAGS=['-fno-tree-vectorize']) 5385863Snate@binkert.org 5395863Snate@binkert.org # LTO support is only really working properly from 4.6 and beyond 5405863Snate@binkert.org if compareVersions(gcc_version, '4.6') >= 0: 5415863Snate@binkert.org # Add the appropriate Link-Time Optimization (LTO) flags 5423118Sstever@eecs.umich.edu # unless LTO is explicitly turned off. Note that these flags 5433483Ssaidi@eecs.umich.edu # are only used by the fast target. 5443494Ssaidi@eecs.umich.edu if not GetOption('no_lto'): 5453494Ssaidi@eecs.umich.edu # Pass the LTO flag when compiling to produce GIMPLE 5463483Ssaidi@eecs.umich.edu # output, we merely create the flags here and only append 5473483Ssaidi@eecs.umich.edu # them later/ 5483483Ssaidi@eecs.umich.edu main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 5493053Sstever@eecs.umich.edu 5503053Sstever@eecs.umich.edu # Use the same amount of jobs for LTO as we are running 5513918Ssaidi@eecs.umich.edu # scons with, we hardcode the use of the linker plugin 5523053Sstever@eecs.umich.edu # which requires either gold or GNU ld >= 2.21 5533053Sstever@eecs.umich.edu main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'), 5543053Sstever@eecs.umich.edu '-fuse-linker-plugin'] 5553053Sstever@eecs.umich.edu 5563053Sstever@eecs.umich.eduelif main['CLANG']: 5571858SN/A # Check for a supported version of clang, >= 2.9 is needed to 5581858SN/A # support similar features as gcc 4.4. See 5591858SN/A # http://clang.llvm.org/cxx_status.html for details 5601858SN/A clang_version_re = re.compile(".* version (\d+\.\d+)") 5611858SN/A clang_version_match = clang_version_re.match(CXX_version) 5621858SN/A if (clang_version_match): 5635863Snate@binkert.org clang_version = clang_version_match.groups()[0] 5645863Snate@binkert.org if compareVersions(clang_version, "2.9") < 0: 5651859SN/A print 'Error: clang version 2.9 or newer required.' 5665863Snate@binkert.org print ' Installed version:', clang_version 5671858SN/A Exit(1) 5685863Snate@binkert.org else: 5691858SN/A print 'Error: Unable to determine clang version.' 5701859SN/A Exit(1) 5711859SN/A 5725863Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 5733053Sstever@eecs.umich.edu main.Append(CCFLAGS=['-fno-strict-aliasing']) 5743053Sstever@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5753053Sstever@eecs.umich.edu main.Append(CCFLAGS=['-Wno-tautological-compare']) 5763053Sstever@eecs.umich.edu main.Append(CCFLAGS=['-Wno-self-assign']) 5771859SN/A # Ruby makes frequent use of extraneous parantheses in the printing 5781859SN/A # of if-statements 5791859SN/A main.Append(CCFLAGS=['-Wno-parentheses']) 5801859SN/A main.Append(CXXFLAGS=['-std=c++0x']) 5811859SN/A # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 5821859SN/A # opposed to libstdc++ to make the transition from TR1 to 5831859SN/A # C++11. See http://libcxx.llvm.org. However, clang has chosen a 5841859SN/A # strict implementation of the C++11 standard, and does not allow 5851862SN/A # incomplete types in template arguments (besides unique_ptr and 5861859SN/A # shared_ptr), and the libc++ STL containers create problems in 5871859SN/A # combination with the current gem5 code. For now, we stick with 5881859SN/A # libstdc++ and use the TR1 namespace. 5895863Snate@binkert.org # if sys.platform == "darwin": 5905863Snate@binkert.org # main.Append(CXXFLAGS=['-stdlib=libc++']) 5915863Snate@binkert.org 5925863Snate@binkert.orgelse: 5931858SN/A print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 5941858SN/A print "Don't know what compiler options to use for your compiler." 5955863Snate@binkert.org print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 5965863Snate@binkert.org print termcap.Yellow + ' version:' + termcap.Normal, 5975863Snate@binkert.org if not CXX_version: 5985863Snate@binkert.org print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 5995863Snate@binkert.org termcap.Normal 6002139SN/A else: 6014202Sbinkertn@umich.edu print CXX_version.replace('\n', '<nl>') 6024202Sbinkertn@umich.edu print " If you're trying to use a compiler other than GCC" 6032139SN/A print " or clang, there appears to be something wrong with your" 6042155SN/A print " environment." 6054202Sbinkertn@umich.edu print " " 6064202Sbinkertn@umich.edu print " If you are trying to use a compiler other than those listed" 6074202Sbinkertn@umich.edu print " above you will need to ease fix SConstruct and " 6082155SN/A print " src/SConscript to support that compiler." 6095863Snate@binkert.org Exit(1) 6101869SN/A 6111869SN/A# Set up common yacc/bison flags (needed for Ruby) 6125863Snate@binkert.orgmain['YACCFLAGS'] = '-d' 6135863Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh' 6144202Sbinkertn@umich.edu 6155863Snate@binkert.org# Do this after we save setting back, or else we'll tack on an 6165863Snate@binkert.org# extra 'qdo' every time we run scons. 6175863Snate@binkert.orgif main['BATCH']: 6184202Sbinkertn@umich.edu main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 6194202Sbinkertn@umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 6205863Snate@binkert.org main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 6215742Snate@binkert.org main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 6225742Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 6235341Sstever@gmail.com 6245342Sstever@gmail.comif sys.platform == 'cygwin': 6255342Sstever@gmail.com # cygwin has some header file issues... 6264202Sbinkertn@umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 6274202Sbinkertn@umich.edu 6284202Sbinkertn@umich.edu# Check for the protobuf compiler 6294202Sbinkertn@umich.eduprotoc_version = readCommand([main['PROTOC'], '--version'], 6304202Sbinkertn@umich.edu exception='').split() 6315863Snate@binkert.org 6325863Snate@binkert.org# First two words should be "libprotoc x.y.z" 6335863Snate@binkert.orgif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 6345863Snate@binkert.org print termcap.Yellow + termcap.Bold + \ 6355863Snate@binkert.org 'Warning: Protocol buffer compiler (protoc) not found.\n' + \ 6365863Snate@binkert.org ' Please install protobuf-compiler for tracing support.' + \ 6375863Snate@binkert.org termcap.Normal 6385863Snate@binkert.org main['PROTOC'] = False 6395863Snate@binkert.orgelse: 6405863Snate@binkert.org # Based on the availability of the compress stream wrappers, 6415863Snate@binkert.org # require 2.1.0 6425863Snate@binkert.org min_protoc_version = '2.1.0' 6435863Snate@binkert.org if compareVersions(protoc_version[1], min_protoc_version) < 0: 6445863Snate@binkert.org print termcap.Yellow + termcap.Bold + \ 6455863Snate@binkert.org 'Warning: protoc version', min_protoc_version, \ 6465863Snate@binkert.org 'or newer required.\n' + \ 6475863Snate@binkert.org ' Installed version:', protoc_version[1], \ 6485863Snate@binkert.org termcap.Normal 6495863Snate@binkert.org main['PROTOC'] = False 6505863Snate@binkert.org else: 6511869SN/A # Attempt to determine the appropriate include path and 6521858SN/A # library path using pkg-config, that means we also need to 6535863Snate@binkert.org # check for pkg-config. Note that it is possible to use 6545863Snate@binkert.org # protobuf without the involvement of pkg-config. Later on we 6551869SN/A # check go a library config check and at that point the test 6561858SN/A # will fail if libprotobuf cannot be found. 6575863Snate@binkert.org if readCommand(['pkg-config', '--version'], exception=''): 6585863Snate@binkert.org try: 6595863Snate@binkert.org # Attempt to establish what linking flags to add for protobuf 6605863Snate@binkert.org # using pkg-config 6615863Snate@binkert.org main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 6621858SN/A except: 663955SN/A print termcap.Yellow + termcap.Bold + \ 664955SN/A 'Warning: pkg-config could not get protobuf flags.' + \ 6651869SN/A termcap.Normal 6661869SN/A 6671869SN/A# Check for SWIG 6681869SN/Aif not main.has_key('SWIG'): 6691869SN/A print 'Error: SWIG utility not found.' 6705863Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 6715863Snate@binkert.org Exit(1) 6725863Snate@binkert.org 6731869SN/A# Check for appropriate SWIG version 6745863Snate@binkert.orgswig_version = readCommand([main['SWIG'], '-version'], exception='').split() 6751869SN/A# First 3 words should be "SWIG Version x.y.z" 6765863Snate@binkert.orgif len(swig_version) < 3 or \ 6771869SN/A swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 6781869SN/A print 'Error determining SWIG version.' 6791869SN/A Exit(1) 6801869SN/A 6811869SN/Amin_swig_version = '1.3.34' 6825863Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0: 6835863Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 6841869SN/A print ' Installed version:', swig_version[2] 6851869SN/A Exit(1) 6861869SN/A 6871869SN/A# Set up SWIG flags & scanner 6881869SN/Aswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 6891869SN/Amain.Append(SWIGFLAGS=swig_flags) 6901869SN/A 6915863Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 6925863Snate@binkert.org# stuff for some reason 6931869SN/Ascanners = [] 6945863Snate@binkert.orgfor scanner in main['SCANNERS']: 6955863Snate@binkert.org skeys = scanner.skeys 6963356Sbinkertn@umich.edu if skeys == '.i': 6973356Sbinkertn@umich.edu continue 6983356Sbinkertn@umich.edu 6993356Sbinkertn@umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 7003356Sbinkertn@umich.edu continue 7014781Snate@binkert.org 7025863Snate@binkert.org scanners.append(scanner) 7035863Snate@binkert.org 7041869SN/A# add the new swig scanner that we like better 7051869SN/Afrom SCons.Scanner import ClassicCPP as CPPScanner 7061869SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 7071869SN/Ascanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 7081869SN/A 7092638Sstever@eecs.umich.edu# replace the scanners list that has what we want 7102638Sstever@eecs.umich.edumain['SCANNERS'] = scanners 7115863Snate@binkert.org 7122638Sstever@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 7132638Sstever@eecs.umich.edu# figure out if the compiler adds leading underscores to global 7145749Scws3k@cs.virginia.edu# variables. This is needed for the autogenerated asm files that we 7155749Scws3k@cs.virginia.edu# use for embedding the python code. 7165863Snate@binkert.orgdef CheckLeading(context): 7175749Scws3k@cs.virginia.edu context.Message("Checking for leading underscore in global variables...") 7185749Scws3k@cs.virginia.edu # 1) Define a global variable called x from asm so the C compiler 7191869SN/A # won't change the symbol at all. 7201869SN/A # 2) Declare that variable. 7213546Sgblack@eecs.umich.edu # 3) Use the variable 7223546Sgblack@eecs.umich.edu # 7233546Sgblack@eecs.umich.edu # If the compiler prepends an underscore, this will successfully 7243546Sgblack@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 7254202Sbinkertn@umich.edu # was defined by the asm statement. If the compiler does not 7265863Snate@binkert.org # prepend an underscore, this will not successfully link because 7273546Sgblack@eecs.umich.edu # '_x' will have been defined by assembly, while the C portion of 7283546Sgblack@eecs.umich.edu # the code will be trying to use 'x' 7293546Sgblack@eecs.umich.edu ret = context.TryLink(''' 7303546Sgblack@eecs.umich.edu asm(".globl _x; _x: .byte 0"); 7314781Snate@binkert.org extern int x; 7325863Snate@binkert.org int main() { return x; } 7334781Snate@binkert.org ''', extension=".c") 7344781Snate@binkert.org context.env.Append(LEADING_UNDERSCORE=ret) 7354781Snate@binkert.org context.Result(ret) 7364781Snate@binkert.org return ret 7374781Snate@binkert.org 7385863Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 7394781Snate@binkert.org# builds under a given build root run on the same host platform. 7404781Snate@binkert.orgconf = Configure(main, 7414781Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 7424781Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 7433546Sgblack@eecs.umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 7443546Sgblack@eecs.umich.edu 7453546Sgblack@eecs.umich.edu# Check for leading underscores. Don't really need to worry either 7464781Snate@binkert.org# way so don't need to check the return code. 7473546Sgblack@eecs.umich.educonf.CheckLeading() 7483546Sgblack@eecs.umich.edu 7493546Sgblack@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 7503546Sgblack@eecs.umich.edutry: 7513546Sgblack@eecs.umich.edu import platform 7523546Sgblack@eecs.umich.edu uname = platform.uname() 7533546Sgblack@eecs.umich.edu if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 7543546Sgblack@eecs.umich.edu if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 7553546Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-arch', 'x86_64']) 7563546Sgblack@eecs.umich.edu main.Append(CFLAGS=['-arch', 'x86_64']) 7574202Sbinkertn@umich.edu main.Append(LINKFLAGS=['-arch', 'x86_64']) 7583546Sgblack@eecs.umich.edu main.Append(ASFLAGS=['-arch', 'x86_64']) 7593546Sgblack@eecs.umich.eduexcept: 7603546Sgblack@eecs.umich.edu pass 761955SN/A 762955SN/A# Recent versions of scons substitute a "Null" object for Configure() 763955SN/A# when configuration isn't necessary, e.g., if the "--help" option is 764955SN/A# present. Unfortuantely this Null object always returns false, 7651858SN/A# breaking all our configuration checks. We replace it with our own 7661858SN/A# more optimistic null object that returns True instead. 7671858SN/Aif not conf: 7685863Snate@binkert.org def NullCheck(*args, **kwargs): 7695863Snate@binkert.org return True 7705343Sstever@gmail.com 7715343Sstever@gmail.com class NullConf: 7725863Snate@binkert.org def __init__(self, env): 7735863Snate@binkert.org self.env = env 7744773Snate@binkert.org def Finish(self): 7755863Snate@binkert.org return self.env 7762632Sstever@eecs.umich.edu def __getattr__(self, mname): 7775863Snate@binkert.org return NullCheck 7782023SN/A 7795863Snate@binkert.org conf = NullConf(main) 7805863Snate@binkert.org 7815863Snate@binkert.org# Find Python include and library directories for embedding the 7825863Snate@binkert.org# interpreter. For consistency, we will use the same Python 7835863Snate@binkert.org# installation used to run scons (and thus this script). If you want 7845863Snate@binkert.org# to link in an alternate version, see above for instructions on how 7855863Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 7865863Snate@binkert.orgfrom distutils import sysconfig 7875863Snate@binkert.org 7882632Sstever@eecs.umich.edupy_getvar = sysconfig.get_config_var 7895863Snate@binkert.org 7902023SN/Apy_debug = getattr(sys, 'pydebug', False) 7912632Sstever@eecs.umich.edupy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 7925863Snate@binkert.org 7935342Sstever@gmail.compy_general_include = sysconfig.get_python_inc() 7945863Snate@binkert.orgpy_platform_include = sysconfig.get_python_inc(plat_specific=True) 7952632Sstever@eecs.umich.edupy_includes = [ py_general_include ] 7965863Snate@binkert.orgif py_platform_include != py_general_include: 7975863Snate@binkert.org py_includes.append(py_platform_include) 7982632Sstever@eecs.umich.edu 7995863Snate@binkert.orgpy_lib_path = [ py_getvar('LIBDIR') ] 8005863Snate@binkert.org# add the prefix/lib/pythonX.Y/config dir, but only if there is no 8015863Snate@binkert.org# shared library in prefix/lib/. 8025863Snate@binkert.orgif not py_getvar('Py_ENABLE_SHARED'): 8035863Snate@binkert.org py_lib_path.append(py_getvar('LIBPL')) 8045863Snate@binkert.org 8052632Sstever@eecs.umich.edupy_libs = [] 8065863Snate@binkert.orgfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 8075863Snate@binkert.org if not lib.startswith('-l'): 8082632Sstever@eecs.umich.edu # Python requires some special flags to link (e.g. -framework 8091888SN/A # common on OS X systems), assume appending preserves order 8105863Snate@binkert.org main.Append(LINKFLAGS=[lib]) 8115863Snate@binkert.org else: 8125863Snate@binkert.org lib = lib[2:] 8131858SN/A if lib not in py_libs: 8145863Snate@binkert.org py_libs.append(lib) 8155863Snate@binkert.orgpy_libs.append(py_version) 8165863Snate@binkert.org 8175863Snate@binkert.orgmain.Append(CPPPATH=py_includes) 8182598SN/Amain.Append(LIBPATH=py_lib_path) 8195863Snate@binkert.org 8201858SN/A# Cache build files in the supplied directory. 8211858SN/Aif main['M5_BUILD_CACHE']: 8221858SN/A print 'Using build cache located at', main['M5_BUILD_CACHE'] 8235863Snate@binkert.org CacheDir(main['M5_BUILD_CACHE']) 8241858SN/A 8251858SN/A 8261858SN/A# verify that this stuff works 8275863Snate@binkert.orgif not conf.CheckHeader('Python.h', '<>'): 8281871SN/A print "Error: can't find Python.h header in", py_includes 8291858SN/A print "Install Python headers (package python-dev on Ubuntu and RedHat)" 8301858SN/A Exit(1) 8311858SN/A 8321858SN/Afor lib in py_libs: 8331858SN/A if not conf.CheckLib(lib): 8341858SN/A print "Error: can't find library %s required by python" % lib 8351858SN/A Exit(1) 8365863Snate@binkert.org 8371858SN/A# On Solaris you need to use libsocket for socket ops 8381858SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 8395863Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 8401859SN/A print "Can't find library with socket calls (e.g. accept())" 8411859SN/A Exit(1) 8421869SN/A 8435863Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 8445863Snate@binkert.org# added to the LIBS environment variable. 8451869SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 8461965SN/A print 'Error: did not find needed zlib compression library '\ 8471965SN/A 'and/or zlib.h header file.' 8481965SN/A print ' Please install zlib and try again.' 8492761Sstever@eecs.umich.edu Exit(1) 8505863Snate@binkert.org 8511869SN/A# If we have the protobuf compiler, also make sure we have the 8525863Snate@binkert.org# development libraries. If the check passes, libprotobuf will be 8532667Sstever@eecs.umich.edu# automatically added to the LIBS environment variable. After 8541869SN/A# this, we can use the HAVE_PROTOBUF flag to determine if we have 8551869SN/A# got both protoc and libprotobuf available. 8562929Sktlim@umich.edumain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 8572929Sktlim@umich.edu conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 8585863Snate@binkert.org 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 8592929Sktlim@umich.edu 860955SN/A# If we have the compiler but not the library, print another warning. 8612598SN/Aif main['PROTOC'] and not main['HAVE_PROTOBUF']: 8622598SN/A print termcap.Yellow + termcap.Bold + \ 8633546Sgblack@eecs.umich.edu 'Warning: did not find protocol buffer library and/or headers.\n' + \ 864955SN/A ' Please install libprotobuf-dev for tracing support.' + \ 865955SN/A termcap.Normal 866955SN/A 8671530SN/A# Check for librt. 868955SN/Ahave_posix_clock = \ 869955SN/A conf.CheckLibWithHeader(None, 'time.h', 'C', 870955SN/A 'clock_nanosleep(0,0,NULL,NULL);') or \ 871 conf.CheckLibWithHeader('rt', 'time.h', 'C', 872 'clock_nanosleep(0,0,NULL,NULL);') 873 874if conf.CheckLib('tcmalloc_minimal'): 875 have_tcmalloc = True 876else: 877 have_tcmalloc = False 878 print termcap.Yellow + termcap.Bold + \ 879 "You can get a 12% performance improvement by installing tcmalloc "\ 880 "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \ 881 termcap.Normal 882 883if not have_posix_clock: 884 print "Can't find library for POSIX clocks." 885 886# Check for <fenv.h> (C99 FP environment control) 887have_fenv = conf.CheckHeader('fenv.h', '<>') 888if not have_fenv: 889 print "Warning: Header file <fenv.h> not found." 890 print " This host has no IEEE FP rounding mode control." 891 892###################################################################### 893# 894# Finish the configuration 895# 896main = conf.Finish() 897 898###################################################################### 899# 900# Collect all non-global variables 901# 902 903# Define the universe of supported ISAs 904all_isa_list = [ ] 905Export('all_isa_list') 906 907class CpuModel(object): 908 '''The CpuModel class encapsulates everything the ISA parser needs to 909 know about a particular CPU model.''' 910 911 # Dict of available CPU model objects. Accessible as CpuModel.dict. 912 dict = {} 913 list = [] 914 defaults = [] 915 916 # Constructor. Automatically adds models to CpuModel.dict. 917 def __init__(self, name, filename, includes, strings, default=False): 918 self.name = name # name of model 919 self.filename = filename # filename for output exec code 920 self.includes = includes # include files needed in exec file 921 # The 'strings' dict holds all the per-CPU symbols we can 922 # substitute into templates etc. 923 self.strings = strings 924 925 # This cpu is enabled by default 926 self.default = default 927 928 # Add self to dict 929 if name in CpuModel.dict: 930 raise AttributeError, "CpuModel '%s' already registered" % name 931 CpuModel.dict[name] = self 932 CpuModel.list.append(name) 933 934Export('CpuModel') 935 936# Sticky variables get saved in the variables file so they persist from 937# one invocation to the next (unless overridden, in which case the new 938# value becomes sticky). 939sticky_vars = Variables(args=ARGUMENTS) 940Export('sticky_vars') 941 942# Sticky variables that should be exported 943export_vars = [] 944Export('export_vars') 945 946# For Ruby 947all_protocols = [] 948Export('all_protocols') 949protocol_dirs = [] 950Export('protocol_dirs') 951slicc_includes = [] 952Export('slicc_includes') 953 954# Walk the tree and execute all SConsopts scripts that wil add to the 955# above variables 956if not GetOption('verbose'): 957 print "Reading SConsopts" 958for bdir in [ base_dir ] + extras_dir_list: 959 if not isdir(bdir): 960 print "Error: directory '%s' does not exist" % bdir 961 Exit(1) 962 for root, dirs, files in os.walk(bdir): 963 if 'SConsopts' in files: 964 if GetOption('verbose'): 965 print "Reading", joinpath(root, 'SConsopts') 966 SConscript(joinpath(root, 'SConsopts')) 967 968all_isa_list.sort() 969 970sticky_vars.AddVariables( 971 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 972 ListVariable('CPU_MODELS', 'CPU models', 973 sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 974 sorted(CpuModel.list)), 975 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 976 False), 977 BoolVariable('SS_COMPATIBLE_FP', 978 'Make floating-point results compatible with SimpleScalar', 979 False), 980 BoolVariable('USE_SSE2', 981 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 982 False), 983 BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 984 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 985 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 986 EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 987 all_protocols), 988 ) 989 990# These variables get exported to #defines in config/*.hh (see src/SConscript). 991export_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'CP_ANNOTATE', 992 'USE_POSIX_CLOCK', 'PROTOCOL', 'HAVE_PROTOBUF'] 993 994################################################### 995# 996# Define a SCons builder for configuration flag headers. 997# 998################################################### 999 1000# This function generates a config header file that #defines the 1001# variable symbol to the current variable setting (0 or 1). The source 1002# operands are the name of the variable and a Value node containing the 1003# value of the variable. 1004def build_config_file(target, source, env): 1005 (variable, value) = [s.get_contents() for s in source] 1006 f = file(str(target[0]), 'w') 1007 print >> f, '#define', variable, value 1008 f.close() 1009 return None 1010 1011# Combine the two functions into a scons Action object. 1012config_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 1013 1014# The emitter munges the source & target node lists to reflect what 1015# we're really doing. 1016def config_emitter(target, source, env): 1017 # extract variable name from Builder arg 1018 variable = str(target[0]) 1019 # True target is config header file 1020 target = joinpath('config', variable.lower() + '.hh') 1021 val = env[variable] 1022 if isinstance(val, bool): 1023 # Force value to 0/1 1024 val = int(val) 1025 elif isinstance(val, str): 1026 val = '"' + val + '"' 1027 1028 # Sources are variable name & value (packaged in SCons Value nodes) 1029 return ([target], [Value(variable), Value(val)]) 1030 1031config_builder = Builder(emitter = config_emitter, action = config_action) 1032 1033main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 1034 1035# libelf build is shared across all configs in the build root. 1036main.SConscript('ext/libelf/SConscript', 1037 variant_dir = joinpath(build_root, 'libelf')) 1038 1039# gzstream build is shared across all configs in the build root. 1040main.SConscript('ext/gzstream/SConscript', 1041 variant_dir = joinpath(build_root, 'gzstream')) 1042 1043################################################### 1044# 1045# This function is used to set up a directory with switching headers 1046# 1047################################################### 1048 1049main['ALL_ISA_LIST'] = all_isa_list 1050def make_switching_dir(dname, switch_headers, env): 1051 # Generate the header. target[0] is the full path of the output 1052 # header to generate. 'source' is a dummy variable, since we get the 1053 # list of ISAs from env['ALL_ISA_LIST']. 1054 def gen_switch_hdr(target, source, env): 1055 fname = str(target[0]) 1056 f = open(fname, 'w') 1057 isa = env['TARGET_ISA'].lower() 1058 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 1059 f.close() 1060 1061 # Build SCons Action object. 'varlist' specifies env vars that this 1062 # action depends on; when env['ALL_ISA_LIST'] changes these actions 1063 # should get re-executed. 1064 switch_hdr_action = MakeAction(gen_switch_hdr, 1065 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 1066 1067 # Instantiate actions for each header 1068 for hdr in switch_headers: 1069 env.Command(hdr, [], switch_hdr_action) 1070Export('make_switching_dir') 1071 1072################################################### 1073# 1074# Define build environments for selected configurations. 1075# 1076################################################### 1077 1078for variant_path in variant_paths: 1079 print "Building in", variant_path 1080 1081 # Make a copy of the build-root environment to use for this config. 1082 env = main.Clone() 1083 env['BUILDDIR'] = variant_path 1084 1085 # variant_dir is the tail component of build path, and is used to 1086 # determine the build parameters (e.g., 'ALPHA_SE') 1087 (build_root, variant_dir) = splitpath(variant_path) 1088 1089 # Set env variables according to the build directory config. 1090 sticky_vars.files = [] 1091 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 1092 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 1093 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 1094 current_vars_file = joinpath(build_root, 'variables', variant_dir) 1095 if isfile(current_vars_file): 1096 sticky_vars.files.append(current_vars_file) 1097 print "Using saved variables file %s" % current_vars_file 1098 else: 1099 # Build dir-specific variables file doesn't exist. 1100 1101 # Make sure the directory is there so we can create it later 1102 opt_dir = dirname(current_vars_file) 1103 if not isdir(opt_dir): 1104 mkdir(opt_dir) 1105 1106 # Get default build variables from source tree. Variables are 1107 # normally determined by name of $VARIANT_DIR, but can be 1108 # overridden by '--default=' arg on command line. 1109 default = GetOption('default') 1110 opts_dir = joinpath(main.root.abspath, 'build_opts') 1111 if default: 1112 default_vars_files = [joinpath(build_root, 'variables', default), 1113 joinpath(opts_dir, default)] 1114 else: 1115 default_vars_files = [joinpath(opts_dir, variant_dir)] 1116 existing_files = filter(isfile, default_vars_files) 1117 if existing_files: 1118 default_vars_file = existing_files[0] 1119 sticky_vars.files.append(default_vars_file) 1120 print "Variables file %s not found,\n using defaults in %s" \ 1121 % (current_vars_file, default_vars_file) 1122 else: 1123 print "Error: cannot find variables file %s or " \ 1124 "default file(s) %s" \ 1125 % (current_vars_file, ' or '.join(default_vars_files)) 1126 Exit(1) 1127 1128 # Apply current variable settings to env 1129 sticky_vars.Update(env) 1130 1131 help_texts["local_vars"] += \ 1132 "Build variables for %s:\n" % variant_dir \ 1133 + sticky_vars.GenerateHelpText(env) 1134 1135 # Process variable settings. 1136 1137 if not have_fenv and env['USE_FENV']: 1138 print "Warning: <fenv.h> not available; " \ 1139 "forcing USE_FENV to False in", variant_dir + "." 1140 env['USE_FENV'] = False 1141 1142 if not env['USE_FENV']: 1143 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 1144 print " FP results may deviate slightly from other platforms." 1145 1146 if env['EFENCE']: 1147 env.Append(LIBS=['efence']) 1148 1149 # Save sticky variable settings back to current variables file 1150 sticky_vars.Save(current_vars_file, env) 1151 1152 if env['USE_SSE2']: 1153 env.Append(CCFLAGS=['-msse2']) 1154 1155 if have_tcmalloc: 1156 env.Append(LIBS=['tcmalloc_minimal']) 1157 1158 # The src/SConscript file sets up the build rules in 'env' according 1159 # to the configured variables. It returns a list of environments, 1160 # one for each variant build (debug, opt, etc.) 1161 envList = SConscript('src/SConscript', variant_dir = variant_path, 1162 exports = 'env') 1163 1164 # Set up the regression tests for each build. 1165 for e in envList: 1166 SConscript('tests/SConscript', 1167 variant_dir = joinpath(variant_path, 'tests', e.Label), 1168 exports = { 'env' : e }, duplicate = False) 1169 1170# base help text 1171Help(''' 1172Usage: scons [scons options] [build variables] [target(s)] 1173 1174Extra scons options: 1175%(options)s 1176 1177Global build variables: 1178%(global_vars)s 1179 1180%(local_vars)s 1181''' % help_texts) 1182