SConstruct revision 9657
1955SN/A# -*- mode:python -*- 2955SN/A 37816Ssteve.reinhardt@amd.com# Copyright (c) 2011 Advanced Micro Devices, Inc. 45871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 51762SN/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 29955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 302665Ssaidi@eecs.umich.edu# 312665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 325863Snate@binkert.org# Nathan Binkert 33955SN/A 34955SN/A################################################### 35955SN/A# 36955SN/A# SCons top-level build description (SConstruct) file. 37955SN/A# 388878Ssteve.reinhardt@amd.com# 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>' 408878Ssteve.reinhardt@amd.com# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 412632Sstever@eecs.umich.edu# the optimized full-system version). 42955SN/A# 438878Ssteve.reinhardt@amd.com# 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 452761Sstever@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# 482632Sstever@eecs.umich.edu# Examples: 492761Sstever@eecs.umich.edu# 502761Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 512761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 528878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug 538878Ssteve.reinhardt@amd.com# % 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 582761Sstever@eecs.umich.edu# file. 598878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 608878Ssteve.reinhardt@amd.com# % 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 638878Ssteve.reinhardt@amd.com# 'gem5' directory (or use -u or -C to tell scons where to find this 648878Ssteve.reinhardt@amd.com# file), you can use 'scons -h' to print all the gem5-specific build 652632Sstever@eecs.umich.edu# options as well. 66955SN/A# 67955SN/A################################################### 68955SN/A 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: 808878Ssteve.reinhardt@amd.com 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: 968878Ssteve.reinhardt@amd.com http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 975863Snate@binkert.org""" 985863Snate@binkert.org raise 995863Snate@binkert.org 1006654Snate@binkert.org# Global Python includes 101955SN/Aimport os 1025396Ssaidi@eecs.umich.eduimport re 1035863Snate@binkert.orgimport subprocess 1045863Snate@binkert.orgimport sys 1054202Sbinkertn@umich.edu 1065863Snate@binkert.orgfrom os import mkdir, environ 1075863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1085863Snate@binkert.orgfrom os.path import exists, isdir, isfile 1095863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 110955SN/A 1116654Snate@binkert.org# SCons includes 1125273Sstever@gmail.comimport SCons 1135871Snate@binkert.orgimport SCons.Node 1145273Sstever@gmail.com 1156655Snate@binkert.orgextra_python_paths = [ 1168878Ssteve.reinhardt@amd.com Dir('src/python').srcnode().abspath, # gem5 includes 1176655Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1186655Snate@binkert.org ] 1196655Snate@binkert.org 1206655Snate@binkert.orgsys.path[1:1] = extra_python_paths 1215871Snate@binkert.org 1226654Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1238947Sandreas.hansson@arm.comfrom m5.util.terminal import get_termcap 1245396Ssaidi@eecs.umich.edu 1258120Sgblack@eecs.umich.eduhelp_texts = { 1268120Sgblack@eecs.umich.edu "options" : "", 1278120Sgblack@eecs.umich.edu "global_vars" : "", 1288120Sgblack@eecs.umich.edu "local_vars" : "" 1298120Sgblack@eecs.umich.edu} 1308120Sgblack@eecs.umich.edu 1318120Sgblack@eecs.umich.eduExport("help_texts") 1328120Sgblack@eecs.umich.edu 1338879Ssteve.reinhardt@amd.com 1348879Ssteve.reinhardt@amd.com# There's a bug in scons in that (1) by default, the help texts from 1358879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h' 1368879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the 1378879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once 1388879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get 1398879Ssteve.reinhardt@amd.com# at the help texts from AddOptions. See: 1408879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1418879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1428879Ssteve.reinhardt@amd.com# This hack lets us extract the help text from AddOptions and 1438879Ssteve.reinhardt@amd.com# re-inject it via Help(). Ideally someday this bug will be fixed and 1448879Ssteve.reinhardt@amd.com# we can just use AddOption directly. 1458879Ssteve.reinhardt@amd.comdef AddLocalOption(*args, **kwargs): 1468120Sgblack@eecs.umich.edu col_width = 30 1478120Sgblack@eecs.umich.edu 1488120Sgblack@eecs.umich.edu help = " " + ", ".join(args) 1498120Sgblack@eecs.umich.edu if "help" in kwargs: 1508120Sgblack@eecs.umich.edu length = len(help) 1518120Sgblack@eecs.umich.edu if length >= col_width: 1528120Sgblack@eecs.umich.edu help += "\n" + " " * col_width 1538120Sgblack@eecs.umich.edu else: 1548120Sgblack@eecs.umich.edu help += " " * (col_width - length) 1558120Sgblack@eecs.umich.edu help += kwargs["help"] 1568120Sgblack@eecs.umich.edu help_texts["options"] += help + "\n" 1578120Sgblack@eecs.umich.edu 1588120Sgblack@eecs.umich.edu AddOption(*args, **kwargs) 1598120Sgblack@eecs.umich.edu 1608879Ssteve.reinhardt@amd.comAddLocalOption('--colors', dest='use_colors', action='store_true', 1618879Ssteve.reinhardt@amd.com help="Add color to abbreviated scons output") 1628879Ssteve.reinhardt@amd.comAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1638879Ssteve.reinhardt@amd.com help="Don't add color to abbreviated scons output") 1648879Ssteve.reinhardt@amd.comAddLocalOption('--default', dest='default', type='string', action='store', 1658879Ssteve.reinhardt@amd.com help='Override which build_opts file to use for defaults') 1668879Ssteve.reinhardt@amd.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1678879Ssteve.reinhardt@amd.com help='Disable style checking hooks') 1688879Ssteve.reinhardt@amd.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1698879Ssteve.reinhardt@amd.com help='Disable Link-Time Optimization for fast') 1708879Ssteve.reinhardt@amd.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1718879Ssteve.reinhardt@amd.com help='Update test reference outputs') 1728120Sgblack@eecs.umich.eduAddLocalOption('--verbose', dest='verbose', action='store_true', 1738947Sandreas.hansson@arm.com help='Print full tool command lines') 1747816Ssteve.reinhardt@amd.com 1755871Snate@binkert.orgtermcap = get_termcap(GetOption('use_colors')) 1765871Snate@binkert.org 1776121Snate@binkert.org######################################################################## 1785871Snate@binkert.org# 1795871Snate@binkert.org# Set up the main build environment. 1809119Sandreas.hansson@arm.com# 1819119Sandreas.hansson@arm.com######################################################################## 182955SN/Ause_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 1835871Snate@binkert.org 'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PYTHONPATH', 1845871Snate@binkert.org 'RANLIB', 'SWIG' ]) 1855871Snate@binkert.org 1865871Snate@binkert.orguse_prefixes = [ 187955SN/A "M5", # M5 configuration (e.g., path to kernels) 1886121Snate@binkert.org "DISTCC_", # distcc (distributed compiler wrapper) configuration 1898881Smarc.orr@gmail.com "CCACHE_", # ccache (caching compiler wrapper) configuration 1906121Snate@binkert.org "CCC_", # clang static analyzer configuration 1916121Snate@binkert.org ] 1921533SN/A 1936655Snate@binkert.orguse_env = {} 1946655Snate@binkert.orgfor key,val in os.environ.iteritems(): 1956655Snate@binkert.org if key in use_vars or \ 1966655Snate@binkert.org any([key.startswith(prefix) for prefix in use_prefixes]): 1975871Snate@binkert.org use_env[key] = val 1985871Snate@binkert.org 1995863Snate@binkert.orgmain = Environment(ENV=use_env) 2005871Snate@binkert.orgmain.Decider('MD5-timestamp') 2018878Ssteve.reinhardt@amd.commain.root = Dir(".") # The current directory (where this file lives). 2025871Snate@binkert.orgmain.srcdir = Dir("src") # The source directory 2035871Snate@binkert.org 2045871Snate@binkert.orgmain_dict_keys = main.Dictionary().keys() 2055863Snate@binkert.org 2066121Snate@binkert.org# Check that we have a C/C++ compiler 2075863Snate@binkert.orgif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 2085871Snate@binkert.org print "No C++ compiler installed (package g++ on Ubuntu and RedHat)" 2098336Ssteve.reinhardt@amd.com Exit(1) 2108336Ssteve.reinhardt@amd.com 2118336Ssteve.reinhardt@amd.com# Check that swig is present 2128336Ssteve.reinhardt@amd.comif not 'SWIG' in main_dict_keys: 2134678Snate@binkert.org print "swig is not installed (package swig on Ubuntu and RedHat)" 2148336Ssteve.reinhardt@amd.com Exit(1) 2158336Ssteve.reinhardt@amd.com 2168336Ssteve.reinhardt@amd.com# add useful python code PYTHONPATH so it can be used by subprocesses 2174678Snate@binkert.org# as well 2184678Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths) 2194678Snate@binkert.org 2204678Snate@binkert.org######################################################################## 2217827Snate@binkert.org# 2227827Snate@binkert.org# Mercurial Stuff. 2238336Ssteve.reinhardt@amd.com# 2244678Snate@binkert.org# If the gem5 directory is a mercurial repository, we should do some 2258336Ssteve.reinhardt@amd.com# extra things. 2268336Ssteve.reinhardt@amd.com# 2278336Ssteve.reinhardt@amd.com######################################################################## 2288336Ssteve.reinhardt@amd.com 2298336Ssteve.reinhardt@amd.comhgdir = main.root.Dir(".hg") 2308336Ssteve.reinhardt@amd.com 2315871Snate@binkert.orgmercurial_style_message = """ 2325871Snate@binkert.orgYou're missing the gem5 style hook, which automatically checks your code 2338336Ssteve.reinhardt@amd.comagainst the gem5 style rules on hg commit and qrefresh commands. This 2348336Ssteve.reinhardt@amd.comscript will now install the hook in your .hg/hgrc file. 2358336Ssteve.reinhardt@amd.comPress enter to continue, or ctrl-c to abort: """ 2368336Ssteve.reinhardt@amd.com 2378336Ssteve.reinhardt@amd.commercurial_style_hook = """ 2385871Snate@binkert.org# The following lines were automatically added by gem5/SConstruct 2398336Ssteve.reinhardt@amd.com# to provide the gem5 style-checking hooks 2408336Ssteve.reinhardt@amd.com[extensions] 2418336Ssteve.reinhardt@amd.comstyle = %s/util/style.py 2428336Ssteve.reinhardt@amd.com 2438336Ssteve.reinhardt@amd.com[hooks] 2444678Snate@binkert.orgpretxncommit.style = python:style.check_style 2455871Snate@binkert.orgpre-qrefresh.style = python:style.check_style 2464678Snate@binkert.org# End of SConstruct additions 2478336Ssteve.reinhardt@amd.com 2488336Ssteve.reinhardt@amd.com""" % (main.root.abspath) 2498336Ssteve.reinhardt@amd.com 2508336Ssteve.reinhardt@amd.commercurial_lib_not_found = """ 2518336Ssteve.reinhardt@amd.comMercurial libraries cannot be found, ignoring style hook. If 2528336Ssteve.reinhardt@amd.comyou are a gem5 developer, please fix this and run the style 2538336Ssteve.reinhardt@amd.comhook. It is important. 2548336Ssteve.reinhardt@amd.com""" 2558336Ssteve.reinhardt@amd.com 2568336Ssteve.reinhardt@amd.com# Check for style hook and prompt for installation if it's not there. 2578336Ssteve.reinhardt@amd.com# Skip this if --ignore-style was specified, there's no .hg dir to 2588336Ssteve.reinhardt@amd.com# install a hook in, or there's no interactive terminal to prompt. 2598336Ssteve.reinhardt@amd.comif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2608336Ssteve.reinhardt@amd.com style_hook = True 2618336Ssteve.reinhardt@amd.com try: 2628336Ssteve.reinhardt@amd.com from mercurial import ui 2638336Ssteve.reinhardt@amd.com ui = ui.ui() 2645871Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2656121Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 266955SN/A ui.config('hooks', 'pre-qrefresh.style', None) 267955SN/A except ImportError: 2682632Sstever@eecs.umich.edu print mercurial_lib_not_found 2692632Sstever@eecs.umich.edu 270955SN/A if not style_hook: 271955SN/A print mercurial_style_message, 272955SN/A # continue unless user does ctrl-c/ctrl-d etc. 273955SN/A try: 2748878Ssteve.reinhardt@amd.com raw_input() 275955SN/A except: 2762632Sstever@eecs.umich.edu print "Input exception, exiting scons.\n" 2772632Sstever@eecs.umich.edu sys.exit(1) 2782632Sstever@eecs.umich.edu hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2792632Sstever@eecs.umich.edu print "Adding style hook to", hgrc_path, "\n" 2802632Sstever@eecs.umich.edu try: 2812632Sstever@eecs.umich.edu hgrc = open(hgrc_path, 'a') 2822632Sstever@eecs.umich.edu hgrc.write(mercurial_style_hook) 2838268Ssteve.reinhardt@amd.com hgrc.close() 2848268Ssteve.reinhardt@amd.com except: 2858268Ssteve.reinhardt@amd.com print "Error updating", hgrc_path 2868268Ssteve.reinhardt@amd.com sys.exit(1) 2878268Ssteve.reinhardt@amd.com 2888268Ssteve.reinhardt@amd.com 2898268Ssteve.reinhardt@amd.com################################################### 2902632Sstever@eecs.umich.edu# 2912632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2922632Sstever@eecs.umich.edu# the target(s). 2932632Sstever@eecs.umich.edu# 2948268Ssteve.reinhardt@amd.com################################################### 2952632Sstever@eecs.umich.edu 2968268Ssteve.reinhardt@amd.com# Find default configuration & binary. 2978268Ssteve.reinhardt@amd.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2988268Ssteve.reinhardt@amd.com 2998268Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list 3003718Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 3012634Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 3022634Sstever@eecs.umich.edu if l[i] == elt: 3035863Snate@binkert.org return i 3042638Sstever@eecs.umich.edu raise ValueError, "element not found" 3058268Ssteve.reinhardt@amd.com 3062632Sstever@eecs.umich.edu# Take a list of paths (or SCons Nodes) and return a list with all 3072632Sstever@eecs.umich.edu# paths made absolute and ~-expanded. Paths will be interpreted 3082632Sstever@eecs.umich.edu# relative to the launch directory unless a different root is provided 3092632Sstever@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 3102632Sstever@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 3111858SN/A for p in path_list] 3123716Sstever@eecs.umich.edu 3132638Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 3142638Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 3152638Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 3162638Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 3172638Sstever@eecs.umich.edu# follow 'build' in the build path. 3182638Sstever@eecs.umich.edu 3192638Sstever@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 3205863Snate@binkert.org# in place rather than reassign the symbol to a new list, which 3215863Snate@binkert.org# doesn't work (obviously!). 3225863Snate@binkert.orgBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 323955SN/A 3245341Sstever@gmail.com# Generate a list of the unique build roots and configs that the 3255341Sstever@gmail.com# collected targets reference. 3265863Snate@binkert.orgvariant_paths = [] 3277756SAli.Saidi@ARM.combuild_root = None 3285341Sstever@gmail.comfor t in BUILD_TARGETS: 3296121Snate@binkert.org path_dirs = t.split('/') 3304494Ssaidi@eecs.umich.edu try: 3316121Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 3321105SN/A except: 3332667Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 3342667Sstever@eecs.umich.edu Exit(1) 3352667Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3362667Sstever@eecs.umich.edu if not build_root: 3376121Snate@binkert.org build_root = this_build_root 3382667Sstever@eecs.umich.edu else: 3395341Sstever@gmail.com if this_build_root != build_root: 3405863Snate@binkert.org print "Error: build targets not under same build root\n"\ 3415341Sstever@gmail.com " %s\n %s" % (build_root, this_build_root) 3425341Sstever@gmail.com Exit(1) 3435341Sstever@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 3448120Sgblack@eecs.umich.edu if variant_path not in variant_paths: 3455341Sstever@gmail.com variant_paths.append(variant_path) 3468120Sgblack@eecs.umich.edu 3475341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there) 3488120Sgblack@eecs.umich.eduif not isdir(build_root): 3496121Snate@binkert.org mkdir(build_root) 3506121Snate@binkert.orgmain['BUILDROOT'] = build_root 3518980Ssteve.reinhardt@amd.com 3525397Ssaidi@eecs.umich.eduExport('main') 3535397Ssaidi@eecs.umich.edu 3547727SAli.Saidi@ARM.commain.SConsignFile(joinpath(build_root, "sconsign")) 3558268Ssteve.reinhardt@amd.com 3566168Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 3575341Sstever@gmail.com# when you use emacs to edit a file in the target dir, as emacs moves 3588120Sgblack@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 3598120Sgblack@eecs.umich.edu# (soft) links work better. 3608120Sgblack@eecs.umich.edumain.SetOption('duplicate', 'soft-copy') 3616814Sgblack@eecs.umich.edu 3625863Snate@binkert.org# 3638120Sgblack@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 3645341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE) 3655863Snate@binkert.org# 3668268Ssteve.reinhardt@amd.com 3676121Snate@binkert.orgglobal_vars_file = joinpath(build_root, 'variables.global') 3686121Snate@binkert.org 3698268Ssteve.reinhardt@amd.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3705742Snate@binkert.org 3715742Snate@binkert.orgglobal_vars.AddVariables( 3725341Sstever@gmail.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 3735742Snate@binkert.org ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3745742Snate@binkert.org ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 3755341Sstever@gmail.com ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 3766017Snate@binkert.org ('BATCH', 'Use batch pool for build and tests', False), 3776121Snate@binkert.org ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3786017Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3797816Ssteve.reinhardt@amd.com ('EXTRAS', 'Add extra directories to the compilation', '') 3807756SAli.Saidi@ARM.com ) 3817756SAli.Saidi@ARM.com 3827756SAli.Saidi@ARM.com# Update main environment with values from ARGUMENTS & global_vars_file 3837756SAli.Saidi@ARM.comglobal_vars.Update(main) 3847756SAli.Saidi@ARM.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3857756SAli.Saidi@ARM.com 3867756SAli.Saidi@ARM.com# Save sticky variable settings back to current variables file 3877756SAli.Saidi@ARM.comglobal_vars.Save(global_vars_file, main) 3887816Ssteve.reinhardt@amd.com 3897816Ssteve.reinhardt@amd.com# Parse EXTRAS variable to build list of all directories where we're 3907816Ssteve.reinhardt@amd.com# look for sources etc. This list is exported as extras_dir_list. 3917816Ssteve.reinhardt@amd.combase_dir = main.srcdir.abspath 3927816Ssteve.reinhardt@amd.comif main['EXTRAS']: 3937816Ssteve.reinhardt@amd.com extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3947816Ssteve.reinhardt@amd.comelse: 3957816Ssteve.reinhardt@amd.com extras_dir_list = [] 3967816Ssteve.reinhardt@amd.com 3977816Ssteve.reinhardt@amd.comExport('base_dir') 3987756SAli.Saidi@ARM.comExport('extras_dir_list') 3997816Ssteve.reinhardt@amd.com 4007816Ssteve.reinhardt@amd.com# the ext directory should be on the #includes path 4017816Ssteve.reinhardt@amd.commain.Append(CPPPATH=[Dir('ext')]) 4027816Ssteve.reinhardt@amd.com 4037816Ssteve.reinhardt@amd.comdef strip_build_path(path, env): 4047816Ssteve.reinhardt@amd.com path = str(path) 4057816Ssteve.reinhardt@amd.com variant_base = env['BUILDROOT'] + os.path.sep 4067816Ssteve.reinhardt@amd.com if path.startswith(variant_base): 4077816Ssteve.reinhardt@amd.com path = path[len(variant_base):] 4087816Ssteve.reinhardt@amd.com elif path.startswith('build/'): 4097816Ssteve.reinhardt@amd.com path = path[6:] 4107816Ssteve.reinhardt@amd.com return path 4117816Ssteve.reinhardt@amd.com 4127816Ssteve.reinhardt@amd.com# Generate a string of the form: 4137816Ssteve.reinhardt@amd.com# common/path/prefix/src1, src2 -> tgt1, tgt2 4147816Ssteve.reinhardt@amd.com# to print while building. 4157816Ssteve.reinhardt@amd.comclass Transform(object): 4167816Ssteve.reinhardt@amd.com # all specific color settings should be here and nowhere else 4177816Ssteve.reinhardt@amd.com tool_color = termcap.Normal 4187816Ssteve.reinhardt@amd.com pfx_color = termcap.Yellow 4197816Ssteve.reinhardt@amd.com srcs_color = termcap.Yellow + termcap.Bold 4207816Ssteve.reinhardt@amd.com arrow_color = termcap.Blue + termcap.Bold 4217816Ssteve.reinhardt@amd.com tgts_color = termcap.Yellow + termcap.Bold 4227816Ssteve.reinhardt@amd.com 4237816Ssteve.reinhardt@amd.com def __init__(self, tool, max_sources=99): 4247816Ssteve.reinhardt@amd.com self.format = self.tool_color + (" [%8s] " % tool) \ 4257816Ssteve.reinhardt@amd.com + self.pfx_color + "%s" \ 4267816Ssteve.reinhardt@amd.com + self.srcs_color + "%s" \ 4277816Ssteve.reinhardt@amd.com + self.arrow_color + " -> " \ 4287816Ssteve.reinhardt@amd.com + self.tgts_color + "%s" \ 4297816Ssteve.reinhardt@amd.com + termcap.Normal 4307816Ssteve.reinhardt@amd.com self.max_sources = max_sources 4317816Ssteve.reinhardt@amd.com 4327816Ssteve.reinhardt@amd.com def __call__(self, target, source, env, for_signature=None): 4337816Ssteve.reinhardt@amd.com # truncate source list according to max_sources param 4347816Ssteve.reinhardt@amd.com source = source[0:self.max_sources] 4357816Ssteve.reinhardt@amd.com def strip(f): 4367816Ssteve.reinhardt@amd.com return strip_build_path(str(f), env) 4377816Ssteve.reinhardt@amd.com if len(source) > 0: 4387816Ssteve.reinhardt@amd.com srcs = map(strip, source) 4397816Ssteve.reinhardt@amd.com else: 4407816Ssteve.reinhardt@amd.com srcs = [''] 4417816Ssteve.reinhardt@amd.com tgts = map(strip, target) 4427816Ssteve.reinhardt@amd.com # surprisingly, os.path.commonprefix is a dumb char-by-char string 4437816Ssteve.reinhardt@amd.com # operation that has nothing to do with paths. 4447816Ssteve.reinhardt@amd.com com_pfx = os.path.commonprefix(srcs + tgts) 4457816Ssteve.reinhardt@amd.com com_pfx_len = len(com_pfx) 4467816Ssteve.reinhardt@amd.com if com_pfx: 4477816Ssteve.reinhardt@amd.com # do some cleanup and sanity checking on common prefix 4487816Ssteve.reinhardt@amd.com if com_pfx[-1] == ".": 4497816Ssteve.reinhardt@amd.com # prefix matches all but file extension: ok 4507816Ssteve.reinhardt@amd.com # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4517816Ssteve.reinhardt@amd.com com_pfx = com_pfx[0:-1] 4527816Ssteve.reinhardt@amd.com elif com_pfx[-1] == "/": 4537816Ssteve.reinhardt@amd.com # common prefix is directory path: OK 4547816Ssteve.reinhardt@amd.com pass 4557816Ssteve.reinhardt@amd.com else: 4567816Ssteve.reinhardt@amd.com src0_len = len(srcs[0]) 4577816Ssteve.reinhardt@amd.com tgt0_len = len(tgts[0]) 4587816Ssteve.reinhardt@amd.com if src0_len == com_pfx_len: 4597816Ssteve.reinhardt@amd.com # source is a substring of target, OK 4608947Sandreas.hansson@arm.com pass 4618947Sandreas.hansson@arm.com elif tgt0_len == com_pfx_len: 4627756SAli.Saidi@ARM.com # target is a substring of source, need to back up to 4638120Sgblack@eecs.umich.edu # avoid empty string on RHS of arrow 4647756SAli.Saidi@ARM.com sep_idx = com_pfx.rfind(".") 4657756SAli.Saidi@ARM.com if sep_idx != -1: 4667756SAli.Saidi@ARM.com com_pfx = com_pfx[0:sep_idx] 4677756SAli.Saidi@ARM.com else: 4687816Ssteve.reinhardt@amd.com com_pfx = '' 4697816Ssteve.reinhardt@amd.com elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4707816Ssteve.reinhardt@amd.com # still splitting at file extension: ok 4717816Ssteve.reinhardt@amd.com pass 4727816Ssteve.reinhardt@amd.com else: 4737816Ssteve.reinhardt@amd.com # probably a fluke; ignore it 4747816Ssteve.reinhardt@amd.com com_pfx = '' 4757816Ssteve.reinhardt@amd.com # recalculate length in case com_pfx was modified 4767816Ssteve.reinhardt@amd.com com_pfx_len = len(com_pfx) 4777816Ssteve.reinhardt@amd.com def fmt(files): 4787756SAli.Saidi@ARM.com f = map(lambda s: s[com_pfx_len:], files) 4797756SAli.Saidi@ARM.com return ', '.join(f) 4806654Snate@binkert.org return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4816654Snate@binkert.org 4825871Snate@binkert.orgExport('Transform') 4836121Snate@binkert.org 4846121Snate@binkert.org# enable the regression script to use the termcap 4856121Snate@binkert.orgmain['TERMCAP'] = termcap 4868946Sandreas.hansson@arm.com 4878737Skoansin.tan@gmail.comif GetOption('verbose'): 4883940Ssaidi@eecs.umich.edu def MakeAction(action, string, *args, **kwargs): 4893918Ssaidi@eecs.umich.edu return Action(action, *args, **kwargs) 4903918Ssaidi@eecs.umich.eduelse: 4911858SN/A MakeAction = Action 4926121Snate@binkert.org main['CCCOMSTR'] = Transform("CC") 4937739Sgblack@eecs.umich.edu main['CXXCOMSTR'] = Transform("CXX") 4947739Sgblack@eecs.umich.edu main['ASCOMSTR'] = Transform("AS") 4956143Snate@binkert.org main['SWIGCOMSTR'] = Transform("SWIG") 4967618SAli.Saidi@arm.com main['ARCOMSTR'] = Transform("AR", 0) 4977618SAli.Saidi@arm.com main['LINKCOMSTR'] = Transform("LINK", 0) 4987618SAli.Saidi@arm.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4997618SAli.Saidi@arm.com main['M4COMSTR'] = Transform("M4") 5008614Sgblack@eecs.umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 5017618SAli.Saidi@arm.com main['SHCXXCOMSTR'] = Transform("SHCXX") 5027618SAli.Saidi@arm.comExport('MakeAction') 5037618SAli.Saidi@arm.com 5047739Sgblack@eecs.umich.edu# Initialize the Link-Time Optimization (LTO) flags 5058946Sandreas.hansson@arm.commain['LTO_CCFLAGS'] = [] 5068946Sandreas.hansson@arm.commain['LTO_LDFLAGS'] = [] 5076121Snate@binkert.org 5083940Ssaidi@eecs.umich.edu# According to the readme, tcmalloc works best if the compiler doesn't 5096121Snate@binkert.org# assume that we're using the builtin malloc and friends. These flags 5107739Sgblack@eecs.umich.edu# are compiler-specific, so we need to set them after we detect which 5117739Sgblack@eecs.umich.edu# compiler we're using. 5127739Sgblack@eecs.umich.edumain['TCMALLOC_CCFLAGS'] = [] 5137739Sgblack@eecs.umich.edu 5147739Sgblack@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 5157739Sgblack@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 5168737Skoansin.tan@gmail.com 5178737Skoansin.tan@gmail.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 5188737Skoansin.tan@gmail.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 5198737Skoansin.tan@gmail.comif main['GCC'] + main['CLANG'] > 1: 5208737Skoansin.tan@gmail.com print 'Error: How can we have two at the same time?' 5218737Skoansin.tan@gmail.com Exit(1) 5228737Skoansin.tan@gmail.com 5238737Skoansin.tan@gmail.com# Set up default C++ compiler flags 5248737Skoansin.tan@gmail.comif main['GCC'] or main['CLANG']: 5258737Skoansin.tan@gmail.com # As gcc and clang share many flags, do the common parts here 5268737Skoansin.tan@gmail.com main.Append(CCFLAGS=['-pipe']) 5278737Skoansin.tan@gmail.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 5288737Skoansin.tan@gmail.com # Enable -Wall and then disable the few warnings that we 5298737Skoansin.tan@gmail.com # consistently violate 5308737Skoansin.tan@gmail.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5318737Skoansin.tan@gmail.com # We always compile using C++11, but only gcc >= 4.7 and clang 3.1 5328737Skoansin.tan@gmail.com # actually use that name, so we stick with c++0x 5338737Skoansin.tan@gmail.com main.Append(CXXFLAGS=['-std=c++0x']) 5348946Sandreas.hansson@arm.com # Add selected sanity checks from -Wextra 5358946Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-Wmissing-field-initializers', 5368946Sandreas.hansson@arm.com '-Woverloaded-virtual']) 5378946Sandreas.hansson@arm.comelse: 5388946Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 5398946Sandreas.hansson@arm.com print "Don't know what compiler options to use for your compiler." 5403918Ssaidi@eecs.umich.edu print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 5419068SAli.Saidi@ARM.com print termcap.Yellow + ' version:' + termcap.Normal, 5429068SAli.Saidi@ARM.com if not CXX_version: 5439068SAli.Saidi@ARM.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 5449068SAli.Saidi@ARM.com termcap.Normal 5459068SAli.Saidi@ARM.com else: 5469068SAli.Saidi@ARM.com print CXX_version.replace('\n', '<nl>') 5479068SAli.Saidi@ARM.com print " If you're trying to use a compiler other than GCC" 5489068SAli.Saidi@ARM.com print " or clang, there appears to be something wrong with your" 5499068SAli.Saidi@ARM.com print " environment." 5509068SAli.Saidi@ARM.com print " " 5519068SAli.Saidi@ARM.com print " If you are trying to use a compiler other than those listed" 5529068SAli.Saidi@ARM.com print " above you will need to ease fix SConstruct and " 5539068SAli.Saidi@ARM.com print " src/SConscript to support that compiler." 5549068SAli.Saidi@ARM.com Exit(1) 5559068SAli.Saidi@ARM.com 5569068SAli.Saidi@ARM.comif main['GCC']: 5573918Ssaidi@eecs.umich.edu # Check for a supported version of gcc, >= 4.4 is needed for c++0x 5583918Ssaidi@eecs.umich.edu # support. See http://gcc.gnu.org/projects/cxx0x.html for details 5596157Snate@binkert.org gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5606157Snate@binkert.org if compareVersions(gcc_version, "4.4") < 0: 5616157Snate@binkert.org print 'Error: gcc version 4.4 or newer required.' 5626157Snate@binkert.org print ' Installed version:', gcc_version 5635397Ssaidi@eecs.umich.edu Exit(1) 5645397Ssaidi@eecs.umich.edu 5656121Snate@binkert.org main['GCC_VERSION'] = gcc_version 5666121Snate@binkert.org 5676121Snate@binkert.org # Check for versions with bugs 5686121Snate@binkert.org if not compareVersions(gcc_version, '4.4.1') or \ 5696121Snate@binkert.org not compareVersions(gcc_version, '4.4.2'): 5706121Snate@binkert.org print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5715397Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-fno-tree-vectorize']) 5721851SN/A 5731851SN/A # LTO support is only really working properly from 4.6 and beyond 5747739Sgblack@eecs.umich.edu if compareVersions(gcc_version, '4.6') >= 0: 575955SN/A # Add the appropriate Link-Time Optimization (LTO) flags 5763053Sstever@eecs.umich.edu # unless LTO is explicitly turned off. Note that these flags 5776121Snate@binkert.org # are only used by the fast target. 5783053Sstever@eecs.umich.edu if not GetOption('no_lto'): 5793053Sstever@eecs.umich.edu # Pass the LTO flag when compiling to produce GIMPLE 5803053Sstever@eecs.umich.edu # output, we merely create the flags here and only append 5813053Sstever@eecs.umich.edu # them later/ 5823053Sstever@eecs.umich.edu main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 5839072Sandreas.hansson@arm.com 5843053Sstever@eecs.umich.edu # Use the same amount of jobs for LTO as we are running 5854742Sstever@eecs.umich.edu # scons with, we hardcode the use of the linker plugin 5864742Sstever@eecs.umich.edu # which requires either gold or GNU ld >= 2.21 5873053Sstever@eecs.umich.edu main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'), 5883053Sstever@eecs.umich.edu '-fuse-linker-plugin'] 5893053Sstever@eecs.umich.edu 5908960Ssteve.reinhardt@amd.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 5916654Snate@binkert.org '-fno-builtin-realloc', '-fno-builtin-free']) 5923053Sstever@eecs.umich.edu 5933053Sstever@eecs.umich.eduelif main['CLANG']: 5943053Sstever@eecs.umich.edu # Check for a supported version of clang, >= 2.9 is needed to 5953053Sstever@eecs.umich.edu # support similar features as gcc 4.4. See 5962667Sstever@eecs.umich.edu # http://clang.llvm.org/cxx_status.html for details 5974554Sbinkertn@umich.edu clang_version_re = re.compile(".* version (\d+\.\d+)") 5986121Snate@binkert.org clang_version_match = clang_version_re.match(CXX_version) 5992667Sstever@eecs.umich.edu if (clang_version_match): 6004554Sbinkertn@umich.edu clang_version = clang_version_match.groups()[0] 6014554Sbinkertn@umich.edu if compareVersions(clang_version, "2.9") < 0: 6024554Sbinkertn@umich.edu print 'Error: clang version 2.9 or newer required.' 6036121Snate@binkert.org print ' Installed version:', clang_version 6044554Sbinkertn@umich.edu Exit(1) 6054554Sbinkertn@umich.edu else: 6064554Sbinkertn@umich.edu print 'Error: Unable to determine clang version.' 6074781Snate@binkert.org Exit(1) 6084554Sbinkertn@umich.edu 6094554Sbinkertn@umich.edu # clang has a few additional warnings that we disable, 6102667Sstever@eecs.umich.edu # tautological comparisons are allowed due to unsigned integers 6114554Sbinkertn@umich.edu # being compared to constants that happen to be 0, and extraneous 6124554Sbinkertn@umich.edu # parantheses are allowed due to Ruby's printing of the AST, 6134554Sbinkertn@umich.edu # finally self assignments are allowed as the generated CPU code 6144554Sbinkertn@umich.edu # is relying on this 6152667Sstever@eecs.umich.edu main.Append(CCFLAGS=['-Wno-tautological-compare', 6164554Sbinkertn@umich.edu '-Wno-parentheses', 6172667Sstever@eecs.umich.edu '-Wno-self-assign']) 6184554Sbinkertn@umich.edu 6196121Snate@binkert.org main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 6202667Sstever@eecs.umich.edu 6215522Snate@binkert.org # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 6225522Snate@binkert.org # opposed to libstdc++ to make the transition from TR1 to 6235522Snate@binkert.org # C++11. See http://libcxx.llvm.org. However, clang has chosen a 6245522Snate@binkert.org # strict implementation of the C++11 standard, and does not allow 6255522Snate@binkert.org # incomplete types in template arguments (besides unique_ptr and 6265522Snate@binkert.org # shared_ptr), and the libc++ STL containers create problems in 6275522Snate@binkert.org # combination with the current gem5 code. For now, we stick with 6285522Snate@binkert.org # libstdc++ and use the TR1 namespace. 6295522Snate@binkert.org # if sys.platform == "darwin": 6305522Snate@binkert.org # main.Append(CXXFLAGS=['-stdlib=libc++']) 6315522Snate@binkert.org 6325522Snate@binkert.orgelse: 6335522Snate@binkert.org print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 6345522Snate@binkert.org print "Don't know what compiler options to use for your compiler." 6355522Snate@binkert.org print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 6365522Snate@binkert.org print termcap.Yellow + ' version:' + termcap.Normal, 6375522Snate@binkert.org if not CXX_version: 6385522Snate@binkert.org print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 6395522Snate@binkert.org termcap.Normal 6405522Snate@binkert.org else: 6415522Snate@binkert.org print CXX_version.replace('\n', '<nl>') 6425522Snate@binkert.org print " If you're trying to use a compiler other than GCC" 6435522Snate@binkert.org print " or clang, there appears to be something wrong with your" 6445522Snate@binkert.org print " environment." 6455522Snate@binkert.org print " " 6465522Snate@binkert.org print " If you are trying to use a compiler other than those listed" 6472638Sstever@eecs.umich.edu print " above you will need to ease fix SConstruct and " 6482638Sstever@eecs.umich.edu print " src/SConscript to support that compiler." 6496121Snate@binkert.org Exit(1) 6503716Sstever@eecs.umich.edu 6515522Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby) 6525522Snate@binkert.orgmain['YACCFLAGS'] = '-d' 6535522Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh' 6545522Snate@binkert.org 6555522Snate@binkert.org# Do this after we save setting back, or else we'll tack on an 6565522Snate@binkert.org# extra 'qdo' every time we run scons. 6571858SN/Aif main['BATCH']: 6585227Ssaidi@eecs.umich.edu main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 6595227Ssaidi@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 6605227Ssaidi@eecs.umich.edu main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 6615227Ssaidi@eecs.umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 6626654Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 6636654Snate@binkert.org 6647769SAli.Saidi@ARM.comif sys.platform == 'cygwin': 6657769SAli.Saidi@ARM.com # cygwin has some header file issues... 6667769SAli.Saidi@ARM.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 6677769SAli.Saidi@ARM.com 6685227Ssaidi@eecs.umich.edu# Check for the protobuf compiler 6695227Ssaidi@eecs.umich.eduprotoc_version = readCommand([main['PROTOC'], '--version'], 6705227Ssaidi@eecs.umich.edu exception='').split() 6715204Sstever@gmail.com 6725204Sstever@gmail.com# First two words should be "libprotoc x.y.z" 6735204Sstever@gmail.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 6745204Sstever@gmail.com print termcap.Yellow + termcap.Bold + \ 6755204Sstever@gmail.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + \ 6765204Sstever@gmail.com ' Please install protobuf-compiler for tracing support.' + \ 6775204Sstever@gmail.com termcap.Normal 6785204Sstever@gmail.com main['PROTOC'] = False 6795204Sstever@gmail.comelse: 6805204Sstever@gmail.com # Based on the availability of the compress stream wrappers, 6815204Sstever@gmail.com # require 2.1.0 6825204Sstever@gmail.com min_protoc_version = '2.1.0' 6835204Sstever@gmail.com if compareVersions(protoc_version[1], min_protoc_version) < 0: 6845204Sstever@gmail.com print termcap.Yellow + termcap.Bold + \ 6855204Sstever@gmail.com 'Warning: protoc version', min_protoc_version, \ 6865204Sstever@gmail.com 'or newer required.\n' + \ 6875204Sstever@gmail.com ' Installed version:', protoc_version[1], \ 6886121Snate@binkert.org termcap.Normal 6895204Sstever@gmail.com main['PROTOC'] = False 6903118Sstever@eecs.umich.edu else: 6913118Sstever@eecs.umich.edu # Attempt to determine the appropriate include path and 6923118Sstever@eecs.umich.edu # library path using pkg-config, that means we also need to 6933118Sstever@eecs.umich.edu # check for pkg-config. Note that it is possible to use 6943118Sstever@eecs.umich.edu # protobuf without the involvement of pkg-config. Later on we 6955863Snate@binkert.org # check go a library config check and at that point the test 6963118Sstever@eecs.umich.edu # will fail if libprotobuf cannot be found. 6975863Snate@binkert.org if readCommand(['pkg-config', '--version'], exception=''): 6983118Sstever@eecs.umich.edu try: 6997457Snate@binkert.org # Attempt to establish what linking flags to add for protobuf 7007457Snate@binkert.org # using pkg-config 7015863Snate@binkert.org main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 7025863Snate@binkert.org except: 7035863Snate@binkert.org print termcap.Yellow + termcap.Bold + \ 7045863Snate@binkert.org 'Warning: pkg-config could not get protobuf flags.' + \ 7055863Snate@binkert.org termcap.Normal 7065863Snate@binkert.org 7075863Snate@binkert.org# Check for SWIG 7086003Snate@binkert.orgif not main.has_key('SWIG'): 7095863Snate@binkert.org print 'Error: SWIG utility not found.' 7105863Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 7115863Snate@binkert.org Exit(1) 7126120Snate@binkert.org 7135863Snate@binkert.org# Check for appropriate SWIG version 7145863Snate@binkert.orgswig_version = readCommand([main['SWIG'], '-version'], exception='').split() 7155863Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 7168655Sandreas.hansson@arm.comif len(swig_version) < 3 or \ 7178655Sandreas.hansson@arm.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 7188655Sandreas.hansson@arm.com print 'Error determining SWIG version.' 7198655Sandreas.hansson@arm.com Exit(1) 7208655Sandreas.hansson@arm.com 7218655Sandreas.hansson@arm.commin_swig_version = '1.3.34' 7228655Sandreas.hansson@arm.comif compareVersions(swig_version[2], min_swig_version) < 0: 7238655Sandreas.hansson@arm.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 7246120Snate@binkert.org print ' Installed version:', swig_version[2] 7255863Snate@binkert.org Exit(1) 7266121Snate@binkert.org 7276121Snate@binkert.orgif swig_version[2] == "2.0.9": 7285863Snate@binkert.org print '\n' + termcap.Yellow + termcap.Bold + \ 7297727SAli.Saidi@ARM.com 'Warning: SWIG version 2.0.9 sometimes generates broken code.\n' + \ 7307727SAli.Saidi@ARM.com termcap.Normal + \ 7317727SAli.Saidi@ARM.com 'This problem only affects some platforms and some Python\n' + \ 7327727SAli.Saidi@ARM.com 'versions. See the following SWIG bug report for details:\n' + \ 7337727SAli.Saidi@ARM.com 'http://sourceforge.net/p/swig/bugs/1297/\n' 7347727SAli.Saidi@ARM.com 7355863Snate@binkert.org 7363118Sstever@eecs.umich.edu# Set up SWIG flags & scanner 7375863Snate@binkert.orgswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 7383118Sstever@eecs.umich.edumain.Append(SWIGFLAGS=swig_flags) 7393118Sstever@eecs.umich.edu 7405863Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 7415863Snate@binkert.org# stuff for some reason 7425863Snate@binkert.orgscanners = [] 7435863Snate@binkert.orgfor scanner in main['SCANNERS']: 7443118Sstever@eecs.umich.edu skeys = scanner.skeys 7453483Ssaidi@eecs.umich.edu if skeys == '.i': 7463494Ssaidi@eecs.umich.edu continue 7473494Ssaidi@eecs.umich.edu 7483483Ssaidi@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 7493483Ssaidi@eecs.umich.edu continue 7503483Ssaidi@eecs.umich.edu 7513053Sstever@eecs.umich.edu scanners.append(scanner) 7523053Sstever@eecs.umich.edu 7533918Ssaidi@eecs.umich.edu# add the new swig scanner that we like better 7543053Sstever@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 7553053Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 7563053Sstever@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 7573053Sstever@eecs.umich.edu 7583053Sstever@eecs.umich.edu# replace the scanners list that has what we want 7597840Snate@binkert.orgmain['SCANNERS'] = scanners 7607865Sgblack@eecs.umich.edu 7617865Sgblack@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 7627865Sgblack@eecs.umich.edu# figure out if the compiler adds leading underscores to global 7637865Sgblack@eecs.umich.edu# variables. This is needed for the autogenerated asm files that we 7647865Sgblack@eecs.umich.edu# use for embedding the python code. 7657840Snate@binkert.orgdef CheckLeading(context): 7669045SAli.Saidi@ARM.com context.Message("Checking for leading underscore in global variables...") 7679045SAli.Saidi@ARM.com # 1) Define a global variable called x from asm so the C compiler 7689045SAli.Saidi@ARM.com # won't change the symbol at all. 7699045SAli.Saidi@ARM.com # 2) Declare that variable. 7709045SAli.Saidi@ARM.com # 3) Use the variable 7719045SAli.Saidi@ARM.com # 7729071Sandreas.hansson@arm.com # If the compiler prepends an underscore, this will successfully 7739071Sandreas.hansson@arm.com # link because the external symbol 'x' will be called '_x' which 7749045SAli.Saidi@ARM.com # was defined by the asm statement. If the compiler does not 7757840Snate@binkert.org # prepend an underscore, this will not successfully link because 7767840Snate@binkert.org # '_x' will have been defined by assembly, while the C portion of 7777840Snate@binkert.org # the code will be trying to use 'x' 7781858SN/A ret = context.TryLink(''' 7791858SN/A asm(".globl _x; _x: .byte 0"); 7801858SN/A extern int x; 7811858SN/A int main() { return x; } 7821858SN/A ''', extension=".c") 7831858SN/A context.env.Append(LEADING_UNDERSCORE=ret) 7845863Snate@binkert.org context.Result(ret) 7855863Snate@binkert.org return ret 7865863Snate@binkert.org 7875863Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 7886121Snate@binkert.org# builds under a given build root run on the same host platform. 7891858SN/Aconf = Configure(main, 7905863Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 7915863Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 7925863Snate@binkert.org custom_tests = { 'CheckLeading' : CheckLeading }) 7935863Snate@binkert.org 7945863Snate@binkert.org# Check for leading underscores. Don't really need to worry either 7952139SN/A# way so don't need to check the return code. 7964202Sbinkertn@umich.educonf.CheckLeading() 7974202Sbinkertn@umich.edu 7982139SN/A# Check if we should compile a 64 bit binary on Mac OS X/Darwin 7996994Snate@binkert.orgtry: 8006994Snate@binkert.org import platform 8016994Snate@binkert.org uname = platform.uname() 8026994Snate@binkert.org if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 8036994Snate@binkert.org if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 8046994Snate@binkert.org main.Append(CCFLAGS=['-arch', 'x86_64']) 8056994Snate@binkert.org main.Append(CFLAGS=['-arch', 'x86_64']) 8066994Snate@binkert.org main.Append(LINKFLAGS=['-arch', 'x86_64']) 8076994Snate@binkert.org main.Append(ASFLAGS=['-arch', 'x86_64']) 8086994Snate@binkert.orgexcept: 8096994Snate@binkert.org pass 8106994Snate@binkert.org 8116994Snate@binkert.org# Recent versions of scons substitute a "Null" object for Configure() 8126994Snate@binkert.org# when configuration isn't necessary, e.g., if the "--help" option is 8136994Snate@binkert.org# present. Unfortuantely this Null object always returns false, 8146994Snate@binkert.org# breaking all our configuration checks. We replace it with our own 8156994Snate@binkert.org# more optimistic null object that returns True instead. 8166994Snate@binkert.orgif not conf: 8176994Snate@binkert.org def NullCheck(*args, **kwargs): 8186994Snate@binkert.org return True 8196994Snate@binkert.org 8206994Snate@binkert.org class NullConf: 8216994Snate@binkert.org def __init__(self, env): 8226994Snate@binkert.org self.env = env 8236994Snate@binkert.org def Finish(self): 8246994Snate@binkert.org return self.env 8256994Snate@binkert.org def __getattr__(self, mname): 8266994Snate@binkert.org return NullCheck 8272155SN/A 8285863Snate@binkert.org conf = NullConf(main) 8291869SN/A 8301869SN/A# Find Python include and library directories for embedding the 8315863Snate@binkert.org# interpreter. For consistency, we will use the same Python 8325863Snate@binkert.org# installation used to run scons (and thus this script). If you want 8334202Sbinkertn@umich.edu# to link in an alternate version, see above for instructions on how 8346108Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 8356108Snate@binkert.orgfrom distutils import sysconfig 8366108Snate@binkert.org 8376108Snate@binkert.orgpy_getvar = sysconfig.get_config_var 8384202Sbinkertn@umich.edu 8395863Snate@binkert.orgpy_debug = getattr(sys, 'pydebug', False) 8408474Sgblack@eecs.umich.edupy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 8418474Sgblack@eecs.umich.edu 8425742Snate@binkert.orgpy_general_include = sysconfig.get_python_inc() 8438268Ssteve.reinhardt@amd.compy_platform_include = sysconfig.get_python_inc(plat_specific=True) 8448268Ssteve.reinhardt@amd.compy_includes = [ py_general_include ] 8458268Ssteve.reinhardt@amd.comif py_platform_include != py_general_include: 8465742Snate@binkert.org py_includes.append(py_platform_include) 8475341Sstever@gmail.com 8488474Sgblack@eecs.umich.edupy_lib_path = [ py_getvar('LIBDIR') ] 8498474Sgblack@eecs.umich.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no 8505342Sstever@gmail.com# shared library in prefix/lib/. 8514202Sbinkertn@umich.eduif not py_getvar('Py_ENABLE_SHARED'): 8524202Sbinkertn@umich.edu py_lib_path.append(py_getvar('LIBPL')) 8534202Sbinkertn@umich.edu # Python requires the flags in LINKFORSHARED to be added the 8545863Snate@binkert.org # linker flags when linking with a statically with Python. Failing 8555863Snate@binkert.org # to do so can lead to errors from the Python's dynamic module 8566994Snate@binkert.org # loader at start up. 8576994Snate@binkert.org main.Append(LINKFLAGS=[py_getvar('LINKFORSHARED').split()]) 8586994Snate@binkert.org 8595863Snate@binkert.orgpy_libs = [] 8605863Snate@binkert.orgfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 8615863Snate@binkert.org if not lib.startswith('-l'): 8625863Snate@binkert.org # Python requires some special flags to link (e.g. -framework 8635863Snate@binkert.org # common on OS X systems), assume appending preserves order 8645863Snate@binkert.org main.Append(LINKFLAGS=[lib]) 8655863Snate@binkert.org else: 8665863Snate@binkert.org lib = lib[2:] 8677840Snate@binkert.org if lib not in py_libs: 8685863Snate@binkert.org py_libs.append(lib) 8695952Ssaidi@eecs.umich.edupy_libs.append(py_version) 8701869SN/A 8711858SN/Amain.Append(CPPPATH=py_includes) 8725863Snate@binkert.orgmain.Append(LIBPATH=py_lib_path) 8739044SAli.Saidi@ARM.com 8748805Sgblack@eecs.umich.edu# Cache build files in the supplied directory. 8751858SN/Aif main['M5_BUILD_CACHE']: 876955SN/A print 'Using build cache located at', main['M5_BUILD_CACHE'] 877955SN/A CacheDir(main['M5_BUILD_CACHE']) 8781869SN/A 8791869SN/A 8801869SN/A# verify that this stuff works 8811869SN/Aif not conf.CheckHeader('Python.h', '<>'): 8821869SN/A print "Error: can't find Python.h header in", py_includes 8835863Snate@binkert.org print "Install Python headers (package python-dev on Ubuntu and RedHat)" 8845863Snate@binkert.org Exit(1) 8855863Snate@binkert.org 8861869SN/Afor lib in py_libs: 8875863Snate@binkert.org if not conf.CheckLib(lib): 8881869SN/A print "Error: can't find library %s required by python" % lib 8895863Snate@binkert.org Exit(1) 8901869SN/A 8911869SN/A# On Solaris you need to use libsocket for socket ops 8921869SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 8931869SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 8948483Sgblack@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 8951869SN/A Exit(1) 8961869SN/A 8971869SN/A# Check for zlib. If the check passes, libz will be automatically 8981869SN/A# added to the LIBS environment variable. 8995863Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 9005863Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 9011869SN/A 'and/or zlib.h header file.' 9025863Snate@binkert.org print ' Please install zlib and try again.' 9035863Snate@binkert.org Exit(1) 9043356Sbinkertn@umich.edu 9053356Sbinkertn@umich.edu# If we have the protobuf compiler, also make sure we have the 9063356Sbinkertn@umich.edu# development libraries. If the check passes, libprotobuf will be 9073356Sbinkertn@umich.edu# automatically added to the LIBS environment variable. After 9083356Sbinkertn@umich.edu# this, we can use the HAVE_PROTOBUF flag to determine if we have 9094781Snate@binkert.org# got both protoc and libprotobuf available. 9105863Snate@binkert.orgmain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 9115863Snate@binkert.org conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 9121869SN/A 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 9131869SN/A 9141869SN/A# If we have the compiler but not the library, print another warning. 9156121Snate@binkert.orgif main['PROTOC'] and not main['HAVE_PROTOBUF']: 9161869SN/A print termcap.Yellow + termcap.Bold + \ 9172638Sstever@eecs.umich.edu 'Warning: did not find protocol buffer library and/or headers.\n' + \ 9186121Snate@binkert.org ' Please install libprotobuf-dev for tracing support.' + \ 9196121Snate@binkert.org termcap.Normal 9202638Sstever@eecs.umich.edu 9215749Scws3k@cs.virginia.edu# Check for librt. 9226121Snate@binkert.orghave_posix_clock = \ 9236121Snate@binkert.org conf.CheckLibWithHeader(None, 'time.h', 'C', 9245749Scws3k@cs.virginia.edu 'clock_nanosleep(0,0,NULL,NULL);') or \ 9251869SN/A conf.CheckLibWithHeader('rt', 'time.h', 'C', 9261869SN/A 'clock_nanosleep(0,0,NULL,NULL);') 9273546Sgblack@eecs.umich.edu 9283546Sgblack@eecs.umich.eduif conf.CheckLib('tcmalloc'): 9293546Sgblack@eecs.umich.edu main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 9303546Sgblack@eecs.umich.eduelif conf.CheckLib('tcmalloc_minimal'): 9316121Snate@binkert.org main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 9325863Snate@binkert.orgelse: 9333546Sgblack@eecs.umich.edu print termcap.Yellow + termcap.Bold + \ 9343546Sgblack@eecs.umich.edu "You can get a 12% performance improvement by installing tcmalloc "\ 9353546Sgblack@eecs.umich.edu "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \ 9363546Sgblack@eecs.umich.edu termcap.Normal 9374781Snate@binkert.org 9384781Snate@binkert.orgif not have_posix_clock: 9396658Snate@binkert.org print "Can't find library for POSIX clocks." 9406658Snate@binkert.org 9414781Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 9423546Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 9433546Sgblack@eecs.umich.eduif not have_fenv: 9443546Sgblack@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 9453546Sgblack@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 9467756SAli.Saidi@ARM.com 9477816Ssteve.reinhardt@amd.com# Check if we should enable KVM-based hardware virtualization 9483546Sgblack@eecs.umich.eduhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 9493546Sgblack@eecs.umich.eduif not have_kvm: 9503546Sgblack@eecs.umich.edu print "Info: Header file <linux/kvm.h> not found, " \ 9513546Sgblack@eecs.umich.edu "disabling KVM support." 9524202Sbinkertn@umich.edu 9533546Sgblack@eecs.umich.edu# Check if the requested target ISA is compatible with the host 9543546Sgblack@eecs.umich.edudef is_isa_kvm_compatible(isa): 9553546Sgblack@eecs.umich.edu isa_comp_table = { 956955SN/A "arm" : ( "armv7l" ), 957955SN/A } 958955SN/A try: 959955SN/A import platform 9605863Snate@binkert.org host_isa = platform.machine() 9615863Snate@binkert.org except: 9625343Sstever@gmail.com print "Warning: Failed to determine host ISA." 9635343Sstever@gmail.com return False 9646121Snate@binkert.org 9655863Snate@binkert.org return host_isa in isa_comp_table.get(isa, []) 9664773Snate@binkert.org 9675863Snate@binkert.org 9682632Sstever@eecs.umich.edu###################################################################### 9695863Snate@binkert.org# 9702023SN/A# Finish the configuration 9715863Snate@binkert.org# 9725863Snate@binkert.orgmain = conf.Finish() 9735863Snate@binkert.org 9745863Snate@binkert.org###################################################################### 9755863Snate@binkert.org# 9765863Snate@binkert.org# Collect all non-global variables 9775863Snate@binkert.org# 9785863Snate@binkert.org 9795863Snate@binkert.org# Define the universe of supported ISAs 9802632Sstever@eecs.umich.eduall_isa_list = [ ] 9815863Snate@binkert.orgExport('all_isa_list') 9822023SN/A 9832632Sstever@eecs.umich.educlass CpuModel(object): 9845863Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 9855342Sstever@gmail.com know about a particular CPU model.''' 9865863Snate@binkert.org 9872632Sstever@eecs.umich.edu # Dict of available CPU model objects. Accessible as CpuModel.dict. 9885863Snate@binkert.org dict = {} 9895863Snate@binkert.org list = [] 9908267Ssteve.reinhardt@amd.com defaults = [] 9918120Sgblack@eecs.umich.edu 9928267Ssteve.reinhardt@amd.com # Constructor. Automatically adds models to CpuModel.dict. 9938267Ssteve.reinhardt@amd.com def __init__(self, name, filename, includes, strings, default=False): 9948267Ssteve.reinhardt@amd.com self.name = name # name of model 9958267Ssteve.reinhardt@amd.com self.filename = filename # filename for output exec code 9968267Ssteve.reinhardt@amd.com self.includes = includes # include files needed in exec file 9978267Ssteve.reinhardt@amd.com # The 'strings' dict holds all the per-CPU symbols we can 9988267Ssteve.reinhardt@amd.com # substitute into templates etc. 9998267Ssteve.reinhardt@amd.com self.strings = strings 10008267Ssteve.reinhardt@amd.com 10015863Snate@binkert.org # This cpu is enabled by default 10025863Snate@binkert.org self.default = default 10035863Snate@binkert.org 10042632Sstever@eecs.umich.edu # Add self to dict 10058267Ssteve.reinhardt@amd.com if name in CpuModel.dict: 10068267Ssteve.reinhardt@amd.com raise AttributeError, "CpuModel '%s' already registered" % name 10078267Ssteve.reinhardt@amd.com CpuModel.dict[name] = self 10082632Sstever@eecs.umich.edu CpuModel.list.append(name) 10091888SN/A 10105863Snate@binkert.orgExport('CpuModel') 10115863Snate@binkert.org 10121858SN/A# Sticky variables get saved in the variables file so they persist from 10138120Sgblack@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 10148120Sgblack@eecs.umich.edu# value becomes sticky). 10157756SAli.Saidi@ARM.comsticky_vars = Variables(args=ARGUMENTS) 10162598SN/AExport('sticky_vars') 10175863Snate@binkert.org 10181858SN/A# Sticky variables that should be exported 10191858SN/Aexport_vars = [] 10201858SN/AExport('export_vars') 10215863Snate@binkert.org 10221858SN/A# For Ruby 10231858SN/Aall_protocols = [] 10241858SN/AExport('all_protocols') 10255863Snate@binkert.orgprotocol_dirs = [] 10261871SN/AExport('protocol_dirs') 10271858SN/Aslicc_includes = [] 10281858SN/AExport('slicc_includes') 10291858SN/A 10301858SN/A# Walk the tree and execute all SConsopts scripts that wil add to the 10315863Snate@binkert.org# above variables 10325863Snate@binkert.orgif not GetOption('verbose'): 10331869SN/A print "Reading SConsopts" 10341965SN/Afor bdir in [ base_dir ] + extras_dir_list: 10357739Sgblack@eecs.umich.edu if not isdir(bdir): 10361965SN/A print "Error: directory '%s' does not exist" % bdir 10379045SAli.Saidi@ARM.com Exit(1) 10389045SAli.Saidi@ARM.com for root, dirs, files in os.walk(bdir): 10399045SAli.Saidi@ARM.com if 'SConsopts' in files: 10402761Sstever@eecs.umich.edu if GetOption('verbose'): 10415863Snate@binkert.org print "Reading", joinpath(root, 'SConsopts') 10421869SN/A SConscript(joinpath(root, 'SConsopts')) 10435863Snate@binkert.org 10442667Sstever@eecs.umich.eduall_isa_list.sort() 10451869SN/A 10461869SN/Asticky_vars.AddVariables( 10472929Sktlim@umich.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 10482929Sktlim@umich.edu ListVariable('CPU_MODELS', 'CPU models', 10495863Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 10502929Sktlim@umich.edu sorted(CpuModel.list)), 1051955SN/A BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 10528120Sgblack@eecs.umich.edu False), 10538120Sgblack@eecs.umich.edu BoolVariable('SS_COMPATIBLE_FP', 10548120Sgblack@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 10558120Sgblack@eecs.umich.edu False), 10568120Sgblack@eecs.umich.edu BoolVariable('USE_SSE2', 10578120Sgblack@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 10588120Sgblack@eecs.umich.edu False), 10598120Sgblack@eecs.umich.edu BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 10608120Sgblack@eecs.umich.edu BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 10618120Sgblack@eecs.umich.edu BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 10628120Sgblack@eecs.umich.edu BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm), 10638120Sgblack@eecs.umich.edu EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 1064 all_protocols), 1065 ) 1066 1067# These variables get exported to #defines in config/*.hh (see src/SConscript). 1068export_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'CP_ANNOTATE', 1069 'USE_POSIX_CLOCK', 'PROTOCOL', 'HAVE_PROTOBUF'] 1070 1071################################################### 1072# 1073# Define a SCons builder for configuration flag headers. 1074# 1075################################################### 1076 1077# This function generates a config header file that #defines the 1078# variable symbol to the current variable setting (0 or 1). The source 1079# operands are the name of the variable and a Value node containing the 1080# value of the variable. 1081def build_config_file(target, source, env): 1082 (variable, value) = [s.get_contents() for s in source] 1083 f = file(str(target[0]), 'w') 1084 print >> f, '#define', variable, value 1085 f.close() 1086 return None 1087 1088# Combine the two functions into a scons Action object. 1089config_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 1090 1091# The emitter munges the source & target node lists to reflect what 1092# we're really doing. 1093def config_emitter(target, source, env): 1094 # extract variable name from Builder arg 1095 variable = str(target[0]) 1096 # True target is config header file 1097 target = joinpath('config', variable.lower() + '.hh') 1098 val = env[variable] 1099 if isinstance(val, bool): 1100 # Force value to 0/1 1101 val = int(val) 1102 elif isinstance(val, str): 1103 val = '"' + val + '"' 1104 1105 # Sources are variable name & value (packaged in SCons Value nodes) 1106 return ([target], [Value(variable), Value(val)]) 1107 1108config_builder = Builder(emitter = config_emitter, action = config_action) 1109 1110main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 1111 1112# libelf build is shared across all configs in the build root. 1113main.SConscript('ext/libelf/SConscript', 1114 variant_dir = joinpath(build_root, 'libelf')) 1115 1116# gzstream build is shared across all configs in the build root. 1117main.SConscript('ext/gzstream/SConscript', 1118 variant_dir = joinpath(build_root, 'gzstream')) 1119 1120# libfdt build is shared across all configs in the build root. 1121main.SConscript('ext/libfdt/SConscript', 1122 variant_dir = joinpath(build_root, 'libfdt')) 1123 1124################################################### 1125# 1126# This function is used to set up a directory with switching headers 1127# 1128################################################### 1129 1130main['ALL_ISA_LIST'] = all_isa_list 1131def make_switching_dir(dname, switch_headers, env): 1132 # Generate the header. target[0] is the full path of the output 1133 # header to generate. 'source' is a dummy variable, since we get the 1134 # list of ISAs from env['ALL_ISA_LIST']. 1135 def gen_switch_hdr(target, source, env): 1136 fname = str(target[0]) 1137 f = open(fname, 'w') 1138 isa = env['TARGET_ISA'].lower() 1139 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 1140 f.close() 1141 1142 # Build SCons Action object. 'varlist' specifies env vars that this 1143 # action depends on; when env['ALL_ISA_LIST'] changes these actions 1144 # should get re-executed. 1145 switch_hdr_action = MakeAction(gen_switch_hdr, 1146 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 1147 1148 # Instantiate actions for each header 1149 for hdr in switch_headers: 1150 env.Command(hdr, [], switch_hdr_action) 1151Export('make_switching_dir') 1152 1153################################################### 1154# 1155# Define build environments for selected configurations. 1156# 1157################################################### 1158 1159for variant_path in variant_paths: 1160 print "Building in", variant_path 1161 1162 # Make a copy of the build-root environment to use for this config. 1163 env = main.Clone() 1164 env['BUILDDIR'] = variant_path 1165 1166 # variant_dir is the tail component of build path, and is used to 1167 # determine the build parameters (e.g., 'ALPHA_SE') 1168 (build_root, variant_dir) = splitpath(variant_path) 1169 1170 # Set env variables according to the build directory config. 1171 sticky_vars.files = [] 1172 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 1173 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 1174 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 1175 current_vars_file = joinpath(build_root, 'variables', variant_dir) 1176 if isfile(current_vars_file): 1177 sticky_vars.files.append(current_vars_file) 1178 print "Using saved variables file %s" % current_vars_file 1179 else: 1180 # Build dir-specific variables file doesn't exist. 1181 1182 # Make sure the directory is there so we can create it later 1183 opt_dir = dirname(current_vars_file) 1184 if not isdir(opt_dir): 1185 mkdir(opt_dir) 1186 1187 # Get default build variables from source tree. Variables are 1188 # normally determined by name of $VARIANT_DIR, but can be 1189 # overridden by '--default=' arg on command line. 1190 default = GetOption('default') 1191 opts_dir = joinpath(main.root.abspath, 'build_opts') 1192 if default: 1193 default_vars_files = [joinpath(build_root, 'variables', default), 1194 joinpath(opts_dir, default)] 1195 else: 1196 default_vars_files = [joinpath(opts_dir, variant_dir)] 1197 existing_files = filter(isfile, default_vars_files) 1198 if existing_files: 1199 default_vars_file = existing_files[0] 1200 sticky_vars.files.append(default_vars_file) 1201 print "Variables file %s not found,\n using defaults in %s" \ 1202 % (current_vars_file, default_vars_file) 1203 else: 1204 print "Error: cannot find variables file %s or " \ 1205 "default file(s) %s" \ 1206 % (current_vars_file, ' or '.join(default_vars_files)) 1207 Exit(1) 1208 1209 # Apply current variable settings to env 1210 sticky_vars.Update(env) 1211 1212 help_texts["local_vars"] += \ 1213 "Build variables for %s:\n" % variant_dir \ 1214 + sticky_vars.GenerateHelpText(env) 1215 1216 # Process variable settings. 1217 1218 if not have_fenv and env['USE_FENV']: 1219 print "Warning: <fenv.h> not available; " \ 1220 "forcing USE_FENV to False in", variant_dir + "." 1221 env['USE_FENV'] = False 1222 1223 if not env['USE_FENV']: 1224 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 1225 print " FP results may deviate slightly from other platforms." 1226 1227 if env['EFENCE']: 1228 env.Append(LIBS=['efence']) 1229 1230 if env['USE_KVM']: 1231 if not have_kvm: 1232 print "Warning: Can not enable KVM, host seems to lack KVM support" 1233 env['USE_KVM'] = False 1234 elif not is_isa_kvm_compatible(env['TARGET_ISA']): 1235 print "Info: KVM support disabled due to unsupported host and " \ 1236 "target ISA combination" 1237 env['USE_KVM'] = False 1238 1239 # Save sticky variable settings back to current variables file 1240 sticky_vars.Save(current_vars_file, env) 1241 1242 if env['USE_SSE2']: 1243 env.Append(CCFLAGS=['-msse2']) 1244 1245 # The src/SConscript file sets up the build rules in 'env' according 1246 # to the configured variables. It returns a list of environments, 1247 # one for each variant build (debug, opt, etc.) 1248 envList = SConscript('src/SConscript', variant_dir = variant_path, 1249 exports = 'env') 1250 1251 # Set up the regression tests for each build. 1252 for e in envList: 1253 SConscript('tests/SConscript', 1254 variant_dir = joinpath(variant_path, 'tests', e.Label), 1255 exports = { 'env' : e }, duplicate = False) 1256 1257# base help text 1258Help(''' 1259Usage: scons [scons options] [build variables] [target(s)] 1260 1261Extra scons options: 1262%(options)s 1263 1264Global build variables: 1265%(global_vars)s 1266 1267%(local_vars)s 1268''' % help_texts) 1269