SConstruct revision 9883
1955SN/A# -*- mode:python -*- 2955SN/A 311408Sandreas.sandberg@arm.com# Copyright (c) 2013 ARM Limited 49812Sandreas.hansson@arm.com# All rights reserved. 59812Sandreas.hansson@arm.com# 69812Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall 79812Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual 89812Sandreas.hansson@arm.com# property including but not limited to intellectual property relating 99812Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software 109812Sandreas.hansson@arm.com# licensed hereunder. You may use the software subject to the license 119812Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated 129812Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software, 139812Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form. 149812Sandreas.hansson@arm.com# 157816Ssteve.reinhardt@amd.com# Copyright (c) 2011 Advanced Micro Devices, Inc. 165871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 171762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 18955SN/A# All rights reserved. 19955SN/A# 20955SN/A# Redistribution and use in source and binary forms, with or without 21955SN/A# modification, are permitted provided that the following conditions are 22955SN/A# met: redistributions of source code must retain the above copyright 23955SN/A# notice, this list of conditions and the following disclaimer; 24955SN/A# redistributions in binary form must reproduce the above copyright 25955SN/A# notice, this list of conditions and the following disclaimer in the 26955SN/A# documentation and/or other materials provided with the distribution; 27955SN/A# neither the name of the copyright holders nor the names of its 28955SN/A# contributors may be used to endorse or promote products derived from 29955SN/A# this software without specific prior written permission. 30955SN/A# 31955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 422665Ssaidi@eecs.umich.edu# 432665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 445863Snate@binkert.org# Nathan Binkert 45955SN/A 46955SN/A################################################### 47955SN/A# 48955SN/A# SCons top-level build description (SConstruct) file. 49955SN/A# 508878Ssteve.reinhardt@amd.com# While in this directory ('gem5'), just type 'scons' to build the default 512632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 528878Ssteve.reinhardt@amd.com# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 532632Sstever@eecs.umich.edu# the optimized full-system version). 54955SN/A# 558878Ssteve.reinhardt@amd.com# You can build gem5 in a different directory as long as there is a 562632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 572761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 582632Sstever@eecs.umich.edu# built for the same host system. 592632Sstever@eecs.umich.edu# 602632Sstever@eecs.umich.edu# Examples: 612761Sstever@eecs.umich.edu# 622761Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 632761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 648878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug 658878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug 662761Sstever@eecs.umich.edu# 672761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 682761Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 692761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 702761Sstever@eecs.umich.edu# file. 718878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 728878Ssteve.reinhardt@amd.com# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug 732632Sstever@eecs.umich.edu# 742632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 758878Ssteve.reinhardt@amd.com# 'gem5' directory (or use -u or -C to tell scons where to find this 768878Ssteve.reinhardt@amd.com# file), you can use 'scons -h' to print all the gem5-specific build 772632Sstever@eecs.umich.edu# options as well. 78955SN/A# 79955SN/A################################################### 80955SN/A 815863Snate@binkert.org# Check for recent-enough Python and SCons versions. 825863Snate@binkert.orgtry: 835863Snate@binkert.org # Really old versions of scons only take two options for the 845863Snate@binkert.org # function, so check once without the revision and once with the 855863Snate@binkert.org # revision, the first instance will fail for stuff other than 865863Snate@binkert.org # 0.98, and the second will fail for 0.98.0 875863Snate@binkert.org EnsureSConsVersion(0, 98) 885863Snate@binkert.org EnsureSConsVersion(0, 98, 1) 895863Snate@binkert.orgexcept SystemExit, e: 905863Snate@binkert.org print """ 915863Snate@binkert.orgFor more details, see: 928878Ssteve.reinhardt@amd.com http://gem5.org/Dependencies 935863Snate@binkert.org""" 945863Snate@binkert.org raise 955863Snate@binkert.org 969812Sandreas.hansson@arm.com# We ensure the python version early because because python-config 979812Sandreas.hansson@arm.com# requires python 2.5 985863Snate@binkert.orgtry: 999812Sandreas.hansson@arm.com EnsurePythonVersion(2, 5) 1005863Snate@binkert.orgexcept SystemExit, e: 1015863Snate@binkert.org print """ 1025863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 1039812Sandreas.hansson@arm.comrearranging your PATH so that scons finds the non-default 'python' and 1049812Sandreas.hansson@arm.com'python-config' first. 1055863Snate@binkert.org 1065863Snate@binkert.orgFor more details, see: 1078878Ssteve.reinhardt@amd.com http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 1085863Snate@binkert.org""" 1095863Snate@binkert.org raise 1105863Snate@binkert.org 1116654Snate@binkert.org# Global Python includes 11210196SCurtis.Dunham@arm.comimport os 113955SN/Aimport re 1145396Ssaidi@eecs.umich.eduimport subprocess 11511401Sandreas.sandberg@arm.comimport sys 1165863Snate@binkert.org 1175863Snate@binkert.orgfrom os import mkdir, environ 1184202Sbinkertn@umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath 1195863Snate@binkert.orgfrom os.path import exists, isdir, isfile 1205863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1215863Snate@binkert.org 1225863Snate@binkert.org# SCons includes 123955SN/Aimport SCons 1246654Snate@binkert.orgimport SCons.Node 1255273Sstever@gmail.com 1265871Snate@binkert.orgextra_python_paths = [ 1275273Sstever@gmail.com Dir('src/python').srcnode().abspath, # gem5 includes 1286655Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1298878Ssteve.reinhardt@amd.com ] 1306655Snate@binkert.org 1316655Snate@binkert.orgsys.path[1:1] = extra_python_paths 1329219Spower.jg@gmail.com 1336655Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1345871Snate@binkert.orgfrom m5.util.terminal import get_termcap 1356654Snate@binkert.org 1368947Sandreas.hansson@arm.comhelp_texts = { 1375396Ssaidi@eecs.umich.edu "options" : "", 1388120Sgblack@eecs.umich.edu "global_vars" : "", 1398120Sgblack@eecs.umich.edu "local_vars" : "" 1408120Sgblack@eecs.umich.edu} 1418120Sgblack@eecs.umich.edu 1428120Sgblack@eecs.umich.eduExport("help_texts") 1438120Sgblack@eecs.umich.edu 1448120Sgblack@eecs.umich.edu 1458120Sgblack@eecs.umich.edu# There's a bug in scons in that (1) by default, the help texts from 1468879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h' 1478879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the 1488879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once 1498879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get 1508879Ssteve.reinhardt@amd.com# at the help texts from AddOptions. See: 1518879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1528879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1538879Ssteve.reinhardt@amd.com# This hack lets us extract the help text from AddOptions and 1548879Ssteve.reinhardt@amd.com# re-inject it via Help(). Ideally someday this bug will be fixed and 1558879Ssteve.reinhardt@amd.com# we can just use AddOption directly. 1568879Ssteve.reinhardt@amd.comdef AddLocalOption(*args, **kwargs): 1578879Ssteve.reinhardt@amd.com col_width = 30 1588879Ssteve.reinhardt@amd.com 1598120Sgblack@eecs.umich.edu help = " " + ", ".join(args) 1608120Sgblack@eecs.umich.edu if "help" in kwargs: 1618120Sgblack@eecs.umich.edu length = len(help) 1628120Sgblack@eecs.umich.edu if length >= col_width: 1638120Sgblack@eecs.umich.edu help += "\n" + " " * col_width 1648120Sgblack@eecs.umich.edu else: 1658120Sgblack@eecs.umich.edu help += " " * (col_width - length) 1668120Sgblack@eecs.umich.edu help += kwargs["help"] 1678120Sgblack@eecs.umich.edu help_texts["options"] += help + "\n" 1688120Sgblack@eecs.umich.edu 1698120Sgblack@eecs.umich.edu AddOption(*args, **kwargs) 1708120Sgblack@eecs.umich.edu 1718120Sgblack@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true', 1728120Sgblack@eecs.umich.edu help="Add color to abbreviated scons output") 1738879Ssteve.reinhardt@amd.comAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1748879Ssteve.reinhardt@amd.com help="Don't add color to abbreviated scons output") 1758879Ssteve.reinhardt@amd.comAddLocalOption('--default', dest='default', type='string', action='store', 1768879Ssteve.reinhardt@amd.com help='Override which build_opts file to use for defaults') 17710458Sandreas.hansson@arm.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 17810458Sandreas.hansson@arm.com help='Disable style checking hooks') 17910458Sandreas.hansson@arm.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1808879Ssteve.reinhardt@amd.com help='Disable Link-Time Optimization for fast') 1818879Ssteve.reinhardt@amd.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1828879Ssteve.reinhardt@amd.com help='Update test reference outputs') 1838879Ssteve.reinhardt@amd.comAddLocalOption('--verbose', dest='verbose', action='store_true', 1849227Sandreas.hansson@arm.com help='Print full tool command lines') 1859227Sandreas.hansson@arm.com 1868879Ssteve.reinhardt@amd.comtermcap = get_termcap(GetOption('use_colors')) 1878879Ssteve.reinhardt@amd.com 1888879Ssteve.reinhardt@amd.com######################################################################## 1898879Ssteve.reinhardt@amd.com# 19010453SAndrew.Bardsley@arm.com# Set up the main build environment. 19110453SAndrew.Bardsley@arm.com# 19210453SAndrew.Bardsley@arm.com######################################################################## 19310456SCurtis.Dunham@arm.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 19410456SCurtis.Dunham@arm.com 'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PYTHONPATH', 19510456SCurtis.Dunham@arm.com 'RANLIB', 'SWIG' ]) 19610457Sandreas.hansson@arm.com 19710457Sandreas.hansson@arm.comuse_prefixes = [ 19811342Sandreas.hansson@arm.com "M5", # M5 configuration (e.g., path to kernels) 19911342Sandreas.hansson@arm.com "DISTCC_", # distcc (distributed compiler wrapper) configuration 2008120Sgblack@eecs.umich.edu "CCACHE_", # ccache (caching compiler wrapper) configuration 2018947Sandreas.hansson@arm.com "CCC_", # clang static analyzer configuration 2027816Ssteve.reinhardt@amd.com ] 2035871Snate@binkert.org 2045871Snate@binkert.orguse_env = {} 2056121Snate@binkert.orgfor key,val in os.environ.iteritems(): 2065871Snate@binkert.org if key in use_vars or \ 2075871Snate@binkert.org any([key.startswith(prefix) for prefix in use_prefixes]): 2089926Sstan.czerniawski@arm.com use_env[key] = val 2099926Sstan.czerniawski@arm.com 2109119Sandreas.hansson@arm.commain = Environment(ENV=use_env) 21110068Sandreas.hansson@arm.commain.Decider('MD5-timestamp') 21210068Sandreas.hansson@arm.commain.root = Dir(".") # The current directory (where this file lives). 213955SN/Amain.srcdir = Dir("src") # The source directory 2149416SAndreas.Sandberg@ARM.com 21511342Sandreas.hansson@arm.commain_dict_keys = main.Dictionary().keys() 21611212Sjoseph.gross@amd.com 21711212Sjoseph.gross@amd.com# Check that we have a C/C++ compiler 21811212Sjoseph.gross@amd.comif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 21911212Sjoseph.gross@amd.com print "No C++ compiler installed (package g++ on Ubuntu and RedHat)" 22011212Sjoseph.gross@amd.com Exit(1) 2219416SAndreas.Sandberg@ARM.com 2229416SAndreas.Sandberg@ARM.com# Check that swig is present 2235871Snate@binkert.orgif not 'SWIG' in main_dict_keys: 22410584Sandreas.hansson@arm.com print "swig is not installed (package swig on Ubuntu and RedHat)" 2259416SAndreas.Sandberg@ARM.com Exit(1) 2269416SAndreas.Sandberg@ARM.com 2275871Snate@binkert.org# add useful python code PYTHONPATH so it can be used by subprocesses 228955SN/A# as well 22910671Sandreas.hansson@arm.commain.AppendENVPath('PYTHONPATH', extra_python_paths) 23010671Sandreas.hansson@arm.com 23110671Sandreas.hansson@arm.com######################################################################## 23210671Sandreas.hansson@arm.com# 2338881Smarc.orr@gmail.com# Mercurial Stuff. 2346121Snate@binkert.org# 2356121Snate@binkert.org# If the gem5 directory is a mercurial repository, we should do some 2361533SN/A# extra things. 2379239Sandreas.hansson@arm.com# 2389239Sandreas.hansson@arm.com######################################################################## 2399239Sandreas.hansson@arm.com 2409239Sandreas.hansson@arm.comhgdir = main.root.Dir(".hg") 2419239Sandreas.hansson@arm.com 2429239Sandreas.hansson@arm.commercurial_style_message = """ 2439239Sandreas.hansson@arm.comYou're missing the gem5 style hook, which automatically checks your code 2449239Sandreas.hansson@arm.comagainst the gem5 style rules on hg commit and qrefresh commands. This 2459239Sandreas.hansson@arm.comscript will now install the hook in your .hg/hgrc file. 2469239Sandreas.hansson@arm.comPress enter to continue, or ctrl-c to abort: """ 2479239Sandreas.hansson@arm.com 2489239Sandreas.hansson@arm.commercurial_style_hook = """ 2496655Snate@binkert.org# The following lines were automatically added by gem5/SConstruct 2506655Snate@binkert.org# to provide the gem5 style-checking hooks 2516655Snate@binkert.org[extensions] 2526655Snate@binkert.orgstyle = %s/util/style.py 2535871Snate@binkert.org 2545871Snate@binkert.org[hooks] 2555863Snate@binkert.orgpretxncommit.style = python:style.check_style 2565871Snate@binkert.orgpre-qrefresh.style = python:style.check_style 2578878Ssteve.reinhardt@amd.com# End of SConstruct additions 2585871Snate@binkert.org 2595871Snate@binkert.org""" % (main.root.abspath) 2605871Snate@binkert.org 2615863Snate@binkert.orgmercurial_lib_not_found = """ 2626121Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook. If 26311408Sandreas.sandberg@arm.comyou are a gem5 developer, please fix this and run the style 2645863Snate@binkert.orghook. It is important. 26511408Sandreas.sandberg@arm.com""" 26611408Sandreas.sandberg@arm.com 2678336Ssteve.reinhardt@amd.com# Check for style hook and prompt for installation if it's not there. 2688336Ssteve.reinhardt@amd.com# Skip this if --ignore-style was specified, there's no .hg dir to 26911408Sandreas.sandberg@arm.com# install a hook in, or there's no interactive terminal to prompt. 2708336Ssteve.reinhardt@amd.comif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2714678Snate@binkert.org style_hook = True 27211408Sandreas.sandberg@arm.com try: 27311408Sandreas.sandberg@arm.com from mercurial import ui 27411408Sandreas.sandberg@arm.com ui = ui.ui() 27511401Sandreas.sandberg@arm.com ui.readconfig(hgdir.File('hgrc').abspath) 27611401Sandreas.sandberg@arm.com style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 27711401Sandreas.sandberg@arm.com ui.config('hooks', 'pre-qrefresh.style', None) 27811401Sandreas.sandberg@arm.com except ImportError: 27911401Sandreas.sandberg@arm.com print mercurial_lib_not_found 28011401Sandreas.sandberg@arm.com 2818336Ssteve.reinhardt@amd.com if not style_hook: 2828336Ssteve.reinhardt@amd.com print mercurial_style_message, 2838336Ssteve.reinhardt@amd.com # continue unless user does ctrl-c/ctrl-d etc. 2844678Snate@binkert.org try: 28511401Sandreas.sandberg@arm.com raw_input() 2864678Snate@binkert.org except: 2874678Snate@binkert.org print "Input exception, exiting scons.\n" 28811401Sandreas.sandberg@arm.com sys.exit(1) 28911401Sandreas.sandberg@arm.com hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2908336Ssteve.reinhardt@amd.com print "Adding style hook to", hgrc_path, "\n" 2914678Snate@binkert.org try: 2928336Ssteve.reinhardt@amd.com hgrc = open(hgrc_path, 'a') 2938336Ssteve.reinhardt@amd.com hgrc.write(mercurial_style_hook) 2948336Ssteve.reinhardt@amd.com hgrc.close() 2958336Ssteve.reinhardt@amd.com except: 2968336Ssteve.reinhardt@amd.com print "Error updating", hgrc_path 2978336Ssteve.reinhardt@amd.com sys.exit(1) 2985871Snate@binkert.org 2995871Snate@binkert.org 3008336Ssteve.reinhardt@amd.com################################################### 30111408Sandreas.sandberg@arm.com# 30211408Sandreas.sandberg@arm.com# Figure out which configurations to set up based on the path(s) of 30311408Sandreas.sandberg@arm.com# the target(s). 30411408Sandreas.sandberg@arm.com# 30511408Sandreas.sandberg@arm.com################################################### 30611408Sandreas.sandberg@arm.com 30711408Sandreas.sandberg@arm.com# Find default configuration & binary. 3088336Ssteve.reinhardt@amd.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 30911401Sandreas.sandberg@arm.com 31011401Sandreas.sandberg@arm.com# helper function: find last occurrence of element in list 31111401Sandreas.sandberg@arm.comdef rfind(l, elt, offs = -1): 3125871Snate@binkert.org for i in range(len(l)+offs, 0, -1): 3138336Ssteve.reinhardt@amd.com if l[i] == elt: 3148336Ssteve.reinhardt@amd.com return i 31511401Sandreas.sandberg@arm.com raise ValueError, "element not found" 31611401Sandreas.sandberg@arm.com 31711401Sandreas.sandberg@arm.com# Take a list of paths (or SCons Nodes) and return a list with all 31811401Sandreas.sandberg@arm.com# paths made absolute and ~-expanded. Paths will be interpreted 31911401Sandreas.sandberg@arm.com# relative to the launch directory unless a different root is provided 3204678Snate@binkert.orgdef makePathListAbsolute(path_list, root=GetLaunchDir()): 3215871Snate@binkert.org return [abspath(joinpath(root, expanduser(str(p)))) 3224678Snate@binkert.org for p in path_list] 32311401Sandreas.sandberg@arm.com 32411401Sandreas.sandberg@arm.com# Each target must have 'build' in the interior of the path; the 32511401Sandreas.sandberg@arm.com# directory below this will determine the build parameters. For 32611401Sandreas.sandberg@arm.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 32711401Sandreas.sandberg@arm.com# recognize that ALPHA_SE specifies the configuration because it 32811401Sandreas.sandberg@arm.com# follow 'build' in the build path. 32911401Sandreas.sandberg@arm.com 33011401Sandreas.sandberg@arm.com# The funky assignment to "[:]" is needed to replace the list contents 33111401Sandreas.sandberg@arm.com# in place rather than reassign the symbol to a new list, which 33211401Sandreas.sandberg@arm.com# doesn't work (obviously!). 33311401Sandreas.sandberg@arm.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 33411401Sandreas.sandberg@arm.com 33511401Sandreas.sandberg@arm.com# Generate a list of the unique build roots and configs that the 33611401Sandreas.sandberg@arm.com# collected targets reference. 33711401Sandreas.sandberg@arm.comvariant_paths = [] 33811401Sandreas.sandberg@arm.combuild_root = None 33911401Sandreas.sandberg@arm.comfor t in BUILD_TARGETS: 34011401Sandreas.sandberg@arm.com path_dirs = t.split('/') 34111401Sandreas.sandberg@arm.com try: 34211401Sandreas.sandberg@arm.com build_top = rfind(path_dirs, 'build', -2) 34311401Sandreas.sandberg@arm.com except: 34411401Sandreas.sandberg@arm.com print "Error: no non-leaf 'build' dir found on target path", t 34511401Sandreas.sandberg@arm.com Exit(1) 34611401Sandreas.sandberg@arm.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 34711401Sandreas.sandberg@arm.com if not build_root: 34811401Sandreas.sandberg@arm.com build_root = this_build_root 34911401Sandreas.sandberg@arm.com else: 35011401Sandreas.sandberg@arm.com if this_build_root != build_root: 35111401Sandreas.sandberg@arm.com print "Error: build targets not under same build root\n"\ 35211401Sandreas.sandberg@arm.com " %s\n %s" % (build_root, this_build_root) 35311401Sandreas.sandberg@arm.com Exit(1) 35411401Sandreas.sandberg@arm.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 3558336Ssteve.reinhardt@amd.com if variant_path not in variant_paths: 3568336Ssteve.reinhardt@amd.com variant_paths.append(variant_path) 3578336Ssteve.reinhardt@amd.com 3588336Ssteve.reinhardt@amd.com# Make sure build_root exists (might not if this is the first build there) 3598336Ssteve.reinhardt@amd.comif not isdir(build_root): 3608336Ssteve.reinhardt@amd.com mkdir(build_root) 3618336Ssteve.reinhardt@amd.commain['BUILDROOT'] = build_root 3628336Ssteve.reinhardt@amd.com 3638336Ssteve.reinhardt@amd.comExport('main') 3648336Ssteve.reinhardt@amd.com 36511401Sandreas.sandberg@arm.commain.SConsignFile(joinpath(build_root, "sconsign")) 36611401Sandreas.sandberg@arm.com 3678336Ssteve.reinhardt@amd.com# Default duplicate option is to use hard links, but this messes up 3688336Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves 3698336Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link. Symbolic 3705871Snate@binkert.org# (soft) links work better. 37111408Sandreas.sandberg@arm.commain.SetOption('duplicate', 'soft-copy') 37211408Sandreas.sandberg@arm.com 37311408Sandreas.sandberg@arm.com# 37411408Sandreas.sandberg@arm.com# Set up global sticky variables... these are common to an entire build 37511408Sandreas.sandberg@arm.com# tree (not specific to a particular build like ALPHA_SE) 37611408Sandreas.sandberg@arm.com# 37711408Sandreas.sandberg@arm.com 37811408Sandreas.sandberg@arm.comglobal_vars_file = joinpath(build_root, 'variables.global') 37911408Sandreas.sandberg@arm.com 38011408Sandreas.sandberg@arm.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 38111408Sandreas.sandberg@arm.com 38211408Sandreas.sandberg@arm.comglobal_vars.AddVariables( 38311408Sandreas.sandberg@arm.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 38411408Sandreas.sandberg@arm.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 38511408Sandreas.sandberg@arm.com ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 38611408Sandreas.sandberg@arm.com ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 38711408Sandreas.sandberg@arm.com ('BATCH', 'Use batch pool for build and tests', False), 38811408Sandreas.sandberg@arm.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 38911408Sandreas.sandberg@arm.com ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 39011408Sandreas.sandberg@arm.com ('EXTRAS', 'Add extra directories to the compilation', '') 39111408Sandreas.sandberg@arm.com ) 3926121Snate@binkert.org 393955SN/A# Update main environment with values from ARGUMENTS & global_vars_file 394955SN/Aglobal_vars.Update(main) 3952632Sstever@eecs.umich.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3962632Sstever@eecs.umich.edu 397955SN/A# Save sticky variable settings back to current variables file 398955SN/Aglobal_vars.Save(global_vars_file, main) 399955SN/A 400955SN/A# Parse EXTRAS variable to build list of all directories where we're 4018878Ssteve.reinhardt@amd.com# look for sources etc. This list is exported as extras_dir_list. 402955SN/Abase_dir = main.srcdir.abspath 4032632Sstever@eecs.umich.eduif main['EXTRAS']: 4042632Sstever@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 4052632Sstever@eecs.umich.eduelse: 4062632Sstever@eecs.umich.edu extras_dir_list = [] 4072632Sstever@eecs.umich.edu 4082632Sstever@eecs.umich.eduExport('base_dir') 4092632Sstever@eecs.umich.eduExport('extras_dir_list') 4108268Ssteve.reinhardt@amd.com 4118268Ssteve.reinhardt@amd.com# the ext directory should be on the #includes path 4128268Ssteve.reinhardt@amd.commain.Append(CPPPATH=[Dir('ext')]) 4138268Ssteve.reinhardt@amd.com 4148268Ssteve.reinhardt@amd.comdef strip_build_path(path, env): 4158268Ssteve.reinhardt@amd.com path = str(path) 4168268Ssteve.reinhardt@amd.com variant_base = env['BUILDROOT'] + os.path.sep 4172632Sstever@eecs.umich.edu if path.startswith(variant_base): 4182632Sstever@eecs.umich.edu path = path[len(variant_base):] 4192632Sstever@eecs.umich.edu elif path.startswith('build/'): 4202632Sstever@eecs.umich.edu path = path[6:] 4218268Ssteve.reinhardt@amd.com return path 4222632Sstever@eecs.umich.edu 4238268Ssteve.reinhardt@amd.com# Generate a string of the form: 4248268Ssteve.reinhardt@amd.com# common/path/prefix/src1, src2 -> tgt1, tgt2 4258268Ssteve.reinhardt@amd.com# to print while building. 4268268Ssteve.reinhardt@amd.comclass Transform(object): 4273718Sstever@eecs.umich.edu # all specific color settings should be here and nowhere else 4282634Sstever@eecs.umich.edu tool_color = termcap.Normal 4292634Sstever@eecs.umich.edu pfx_color = termcap.Yellow 4305863Snate@binkert.org srcs_color = termcap.Yellow + termcap.Bold 4312638Sstever@eecs.umich.edu arrow_color = termcap.Blue + termcap.Bold 4328268Ssteve.reinhardt@amd.com tgts_color = termcap.Yellow + termcap.Bold 4332632Sstever@eecs.umich.edu 4342632Sstever@eecs.umich.edu def __init__(self, tool, max_sources=99): 4352632Sstever@eecs.umich.edu self.format = self.tool_color + (" [%8s] " % tool) \ 4362632Sstever@eecs.umich.edu + self.pfx_color + "%s" \ 4372632Sstever@eecs.umich.edu + self.srcs_color + "%s" \ 4381858SN/A + self.arrow_color + " -> " \ 4393716Sstever@eecs.umich.edu + self.tgts_color + "%s" \ 4402638Sstever@eecs.umich.edu + termcap.Normal 4412638Sstever@eecs.umich.edu self.max_sources = max_sources 4422638Sstever@eecs.umich.edu 4432638Sstever@eecs.umich.edu def __call__(self, target, source, env, for_signature=None): 4442638Sstever@eecs.umich.edu # truncate source list according to max_sources param 4452638Sstever@eecs.umich.edu source = source[0:self.max_sources] 4462638Sstever@eecs.umich.edu def strip(f): 4475863Snate@binkert.org return strip_build_path(str(f), env) 4485863Snate@binkert.org if len(source) > 0: 4495863Snate@binkert.org srcs = map(strip, source) 450955SN/A else: 4515341Sstever@gmail.com srcs = [''] 4525341Sstever@gmail.com tgts = map(strip, target) 4535863Snate@binkert.org # surprisingly, os.path.commonprefix is a dumb char-by-char string 4547756SAli.Saidi@ARM.com # operation that has nothing to do with paths. 4555341Sstever@gmail.com com_pfx = os.path.commonprefix(srcs + tgts) 4566121Snate@binkert.org com_pfx_len = len(com_pfx) 4574494Ssaidi@eecs.umich.edu if com_pfx: 4586121Snate@binkert.org # do some cleanup and sanity checking on common prefix 4591105SN/A if com_pfx[-1] == ".": 4602667Sstever@eecs.umich.edu # prefix matches all but file extension: ok 4612667Sstever@eecs.umich.edu # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4622667Sstever@eecs.umich.edu com_pfx = com_pfx[0:-1] 4632667Sstever@eecs.umich.edu elif com_pfx[-1] == "/": 4646121Snate@binkert.org # common prefix is directory path: OK 4652667Sstever@eecs.umich.edu pass 4665341Sstever@gmail.com else: 4675863Snate@binkert.org src0_len = len(srcs[0]) 4685341Sstever@gmail.com tgt0_len = len(tgts[0]) 4695341Sstever@gmail.com if src0_len == com_pfx_len: 4705341Sstever@gmail.com # source is a substring of target, OK 4718120Sgblack@eecs.umich.edu pass 4725341Sstever@gmail.com elif tgt0_len == com_pfx_len: 4738120Sgblack@eecs.umich.edu # target is a substring of source, need to back up to 4745341Sstever@gmail.com # avoid empty string on RHS of arrow 4758120Sgblack@eecs.umich.edu sep_idx = com_pfx.rfind(".") 4766121Snate@binkert.org if sep_idx != -1: 4776121Snate@binkert.org com_pfx = com_pfx[0:sep_idx] 4788980Ssteve.reinhardt@amd.com else: 4799396Sandreas.hansson@arm.com com_pfx = '' 4805397Ssaidi@eecs.umich.edu elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4815397Ssaidi@eecs.umich.edu # still splitting at file extension: ok 4827727SAli.Saidi@ARM.com pass 4838268Ssteve.reinhardt@amd.com else: 4846168Snate@binkert.org # probably a fluke; ignore it 4855341Sstever@gmail.com com_pfx = '' 4868120Sgblack@eecs.umich.edu # recalculate length in case com_pfx was modified 4878120Sgblack@eecs.umich.edu com_pfx_len = len(com_pfx) 4888120Sgblack@eecs.umich.edu def fmt(files): 4896814Sgblack@eecs.umich.edu f = map(lambda s: s[com_pfx_len:], files) 4905863Snate@binkert.org return ', '.join(f) 4918120Sgblack@eecs.umich.edu return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4925341Sstever@gmail.com 4935863Snate@binkert.orgExport('Transform') 4948268Ssteve.reinhardt@amd.com 4956121Snate@binkert.org# enable the regression script to use the termcap 4966121Snate@binkert.orgmain['TERMCAP'] = termcap 4978268Ssteve.reinhardt@amd.com 4985742Snate@binkert.orgif GetOption('verbose'): 4995742Snate@binkert.org def MakeAction(action, string, *args, **kwargs): 5005341Sstever@gmail.com return Action(action, *args, **kwargs) 5015742Snate@binkert.orgelse: 5025742Snate@binkert.org MakeAction = Action 5035341Sstever@gmail.com main['CCCOMSTR'] = Transform("CC") 5046017Snate@binkert.org main['CXXCOMSTR'] = Transform("CXX") 5056121Snate@binkert.org main['ASCOMSTR'] = Transform("AS") 5066017Snate@binkert.org main['SWIGCOMSTR'] = Transform("SWIG") 5077816Ssteve.reinhardt@amd.com main['ARCOMSTR'] = Transform("AR", 0) 5087756SAli.Saidi@ARM.com main['LINKCOMSTR'] = Transform("LINK", 0) 5097756SAli.Saidi@ARM.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 5107756SAli.Saidi@ARM.com main['M4COMSTR'] = Transform("M4") 5117756SAli.Saidi@ARM.com main['SHCCCOMSTR'] = Transform("SHCC") 5127756SAli.Saidi@ARM.com main['SHCXXCOMSTR'] = Transform("SHCXX") 5137756SAli.Saidi@ARM.comExport('MakeAction') 5147756SAli.Saidi@ARM.com 5157756SAli.Saidi@ARM.com# Initialize the Link-Time Optimization (LTO) flags 5167816Ssteve.reinhardt@amd.commain['LTO_CCFLAGS'] = [] 5177816Ssteve.reinhardt@amd.commain['LTO_LDFLAGS'] = [] 5187816Ssteve.reinhardt@amd.com 5197816Ssteve.reinhardt@amd.com# According to the readme, tcmalloc works best if the compiler doesn't 5207816Ssteve.reinhardt@amd.com# assume that we're using the builtin malloc and friends. These flags 5217816Ssteve.reinhardt@amd.com# are compiler-specific, so we need to set them after we detect which 5227816Ssteve.reinhardt@amd.com# compiler we're using. 5237816Ssteve.reinhardt@amd.commain['TCMALLOC_CCFLAGS'] = [] 5247816Ssteve.reinhardt@amd.com 5257816Ssteve.reinhardt@amd.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 5267756SAli.Saidi@ARM.comCXX_V = readCommand([main['CXX'],'-V'], exception=False) 5277816Ssteve.reinhardt@amd.com 5287816Ssteve.reinhardt@amd.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 5297816Ssteve.reinhardt@amd.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 5307816Ssteve.reinhardt@amd.comif main['GCC'] + main['CLANG'] > 1: 5317816Ssteve.reinhardt@amd.com print 'Error: How can we have two at the same time?' 5327816Ssteve.reinhardt@amd.com Exit(1) 5337816Ssteve.reinhardt@amd.com 5347816Ssteve.reinhardt@amd.com# Set up default C++ compiler flags 5357816Ssteve.reinhardt@amd.comif main['GCC'] or main['CLANG']: 5367816Ssteve.reinhardt@amd.com # As gcc and clang share many flags, do the common parts here 5377816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-pipe']) 5387816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 5397816Ssteve.reinhardt@amd.com # Enable -Wall and then disable the few warnings that we 5407816Ssteve.reinhardt@amd.com # consistently violate 5417816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5427816Ssteve.reinhardt@amd.com # We always compile using C++11, but only gcc >= 4.7 and clang 3.1 5437816Ssteve.reinhardt@amd.com # actually use that name, so we stick with c++0x 5447816Ssteve.reinhardt@amd.com main.Append(CXXFLAGS=['-std=c++0x']) 5457816Ssteve.reinhardt@amd.com # Add selected sanity checks from -Wextra 5467816Ssteve.reinhardt@amd.com main.Append(CXXFLAGS=['-Wmissing-field-initializers', 5477816Ssteve.reinhardt@amd.com '-Woverloaded-virtual']) 5487816Ssteve.reinhardt@amd.comelse: 5497816Ssteve.reinhardt@amd.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 5507816Ssteve.reinhardt@amd.com print "Don't know what compiler options to use for your compiler." 5517816Ssteve.reinhardt@amd.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 5527816Ssteve.reinhardt@amd.com print termcap.Yellow + ' version:' + termcap.Normal, 5537816Ssteve.reinhardt@amd.com if not CXX_version: 5547816Ssteve.reinhardt@amd.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 5557816Ssteve.reinhardt@amd.com termcap.Normal 5567816Ssteve.reinhardt@amd.com else: 5577816Ssteve.reinhardt@amd.com print CXX_version.replace('\n', '<nl>') 5587816Ssteve.reinhardt@amd.com print " If you're trying to use a compiler other than GCC" 5597816Ssteve.reinhardt@amd.com print " or clang, there appears to be something wrong with your" 5607816Ssteve.reinhardt@amd.com print " environment." 5617816Ssteve.reinhardt@amd.com print " " 5627816Ssteve.reinhardt@amd.com print " If you are trying to use a compiler other than those listed" 5637816Ssteve.reinhardt@amd.com print " above you will need to ease fix SConstruct and " 5647816Ssteve.reinhardt@amd.com print " src/SConscript to support that compiler." 5657816Ssteve.reinhardt@amd.com Exit(1) 5667816Ssteve.reinhardt@amd.com 5677816Ssteve.reinhardt@amd.comif main['GCC']: 5687816Ssteve.reinhardt@amd.com # Check for a supported version of gcc, >= 4.4 is needed for c++0x 5697816Ssteve.reinhardt@amd.com # support. See http://gcc.gnu.org/projects/cxx0x.html for details 5707816Ssteve.reinhardt@amd.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5717816Ssteve.reinhardt@amd.com if compareVersions(gcc_version, "4.4") < 0: 5727816Ssteve.reinhardt@amd.com print 'Error: gcc version 4.4 or newer required.' 5737816Ssteve.reinhardt@amd.com print ' Installed version:', gcc_version 5747816Ssteve.reinhardt@amd.com Exit(1) 5757816Ssteve.reinhardt@amd.com 5767816Ssteve.reinhardt@amd.com main['GCC_VERSION'] = gcc_version 5777816Ssteve.reinhardt@amd.com 5787816Ssteve.reinhardt@amd.com # Check for versions with bugs 5797816Ssteve.reinhardt@amd.com if not compareVersions(gcc_version, '4.4.1') or \ 5807816Ssteve.reinhardt@amd.com not compareVersions(gcc_version, '4.4.2'): 5817816Ssteve.reinhardt@amd.com print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5827816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-fno-tree-vectorize']) 5837816Ssteve.reinhardt@amd.com 5847816Ssteve.reinhardt@amd.com # LTO support is only really working properly from 4.6 and beyond 5857816Ssteve.reinhardt@amd.com if compareVersions(gcc_version, '4.6') >= 0: 5867816Ssteve.reinhardt@amd.com # Add the appropriate Link-Time Optimization (LTO) flags 5877816Ssteve.reinhardt@amd.com # unless LTO is explicitly turned off. Note that these flags 5888947Sandreas.hansson@arm.com # are only used by the fast target. 5898947Sandreas.hansson@arm.com if not GetOption('no_lto'): 5907756SAli.Saidi@ARM.com # Pass the LTO flag when compiling to produce GIMPLE 5918120Sgblack@eecs.umich.edu # output, we merely create the flags here and only append 5927756SAli.Saidi@ARM.com # them later/ 5937756SAli.Saidi@ARM.com main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 5947756SAli.Saidi@ARM.com 5957756SAli.Saidi@ARM.com # Use the same amount of jobs for LTO as we are running 5967816Ssteve.reinhardt@amd.com # scons with, we hardcode the use of the linker plugin 5977816Ssteve.reinhardt@amd.com # which requires either gold or GNU ld >= 2.21 5987816Ssteve.reinhardt@amd.com main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'), 5997816Ssteve.reinhardt@amd.com '-fuse-linker-plugin'] 6007816Ssteve.reinhardt@amd.com 6017816Ssteve.reinhardt@amd.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 6027816Ssteve.reinhardt@amd.com '-fno-builtin-realloc', '-fno-builtin-free']) 6037816Ssteve.reinhardt@amd.com 6047816Ssteve.reinhardt@amd.comelif main['CLANG']: 6057816Ssteve.reinhardt@amd.com # Check for a supported version of clang, >= 2.9 is needed to 6067756SAli.Saidi@ARM.com # support similar features as gcc 4.4. See 6077756SAli.Saidi@ARM.com # http://clang.llvm.org/cxx_status.html for details 6089227Sandreas.hansson@arm.com clang_version_re = re.compile(".* version (\d+\.\d+)") 6099227Sandreas.hansson@arm.com clang_version_match = clang_version_re.match(CXX_version) 6109227Sandreas.hansson@arm.com if (clang_version_match): 6119227Sandreas.hansson@arm.com clang_version = clang_version_match.groups()[0] 6129590Sandreas@sandberg.pp.se if compareVersions(clang_version, "2.9") < 0: 6139590Sandreas@sandberg.pp.se print 'Error: clang version 2.9 or newer required.' 6149590Sandreas@sandberg.pp.se print ' Installed version:', clang_version 6159590Sandreas@sandberg.pp.se Exit(1) 6169590Sandreas@sandberg.pp.se else: 6179590Sandreas@sandberg.pp.se print 'Error: Unable to determine clang version.' 6186654Snate@binkert.org Exit(1) 6196654Snate@binkert.org 6205871Snate@binkert.org # clang has a few additional warnings that we disable, 6216121Snate@binkert.org # tautological comparisons are allowed due to unsigned integers 6228946Sandreas.hansson@arm.com # being compared to constants that happen to be 0, and extraneous 6239419Sandreas.hansson@arm.com # parantheses are allowed due to Ruby's printing of the AST, 6243940Ssaidi@eecs.umich.edu # finally self assignments are allowed as the generated CPU code 6253918Ssaidi@eecs.umich.edu # is relying on this 6263918Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Wno-tautological-compare', 6271858SN/A '-Wno-parentheses', 6289556Sandreas.hansson@arm.com '-Wno-self-assign']) 6299556Sandreas.hansson@arm.com 6309556Sandreas.hansson@arm.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 6319556Sandreas.hansson@arm.com 63211294Sandreas.hansson@arm.com # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 63311294Sandreas.hansson@arm.com # opposed to libstdc++, as the later is dated. 63411294Sandreas.hansson@arm.com if sys.platform == "darwin": 63511294Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-stdlib=libc++']) 63610878Sandreas.hansson@arm.com main.Append(LIBS=['c++']) 63710878Sandreas.hansson@arm.com 6389556Sandreas.hansson@arm.comelse: 6399556Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 6409556Sandreas.hansson@arm.com print "Don't know what compiler options to use for your compiler." 6419556Sandreas.hansson@arm.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 6429556Sandreas.hansson@arm.com print termcap.Yellow + ' version:' + termcap.Normal, 6439556Sandreas.hansson@arm.com if not CXX_version: 6449556Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 6459556Sandreas.hansson@arm.com termcap.Normal 6469556Sandreas.hansson@arm.com else: 6479556Sandreas.hansson@arm.com print CXX_version.replace('\n', '<nl>') 6489556Sandreas.hansson@arm.com print " If you're trying to use a compiler other than GCC" 6499556Sandreas.hansson@arm.com print " or clang, there appears to be something wrong with your" 6509556Sandreas.hansson@arm.com print " environment." 6519556Sandreas.hansson@arm.com print " " 6529556Sandreas.hansson@arm.com print " If you are trying to use a compiler other than those listed" 6539556Sandreas.hansson@arm.com print " above you will need to ease fix SConstruct and " 6549556Sandreas.hansson@arm.com print " src/SConscript to support that compiler." 6559556Sandreas.hansson@arm.com Exit(1) 6569556Sandreas.hansson@arm.com 6576121Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby) 65810878Sandreas.hansson@arm.commain['YACCFLAGS'] = '-d' 65910238Sandreas.hansson@arm.commain['YACCHXXFILESUFFIX'] = '.hh' 66010878Sandreas.hansson@arm.com 6619420Sandreas.hansson@arm.com# Do this after we save setting back, or else we'll tack on an 66210878Sandreas.hansson@arm.com# extra 'qdo' every time we run scons. 66310878Sandreas.hansson@arm.comif main['BATCH']: 6649420Sandreas.hansson@arm.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 6659420Sandreas.hansson@arm.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 6669420Sandreas.hansson@arm.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 6679420Sandreas.hansson@arm.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 6689420Sandreas.hansson@arm.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 66910264Sandreas.hansson@arm.com 67010264Sandreas.hansson@arm.comif sys.platform == 'cygwin': 67110264Sandreas.hansson@arm.com # cygwin has some header file issues... 67210264Sandreas.hansson@arm.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 67310264Sandreas.hansson@arm.com 67410866Sandreas.hansson@arm.com# Check for the protobuf compiler 67510866Sandreas.hansson@arm.comprotoc_version = readCommand([main['PROTOC'], '--version'], 67610264Sandreas.hansson@arm.com exception='').split() 67710866Sandreas.hansson@arm.com 67810866Sandreas.hansson@arm.com# First two words should be "libprotoc x.y.z" 67910866Sandreas.hansson@arm.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 68010866Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + \ 68110866Sandreas.hansson@arm.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + \ 68210866Sandreas.hansson@arm.com ' Please install protobuf-compiler for tracing support.' + \ 68310866Sandreas.hansson@arm.com termcap.Normal 68410264Sandreas.hansson@arm.com main['PROTOC'] = False 68510264Sandreas.hansson@arm.comelse: 68610264Sandreas.hansson@arm.com # Based on the availability of the compress stream wrappers, 68710264Sandreas.hansson@arm.com # require 2.1.0 68810264Sandreas.hansson@arm.com min_protoc_version = '2.1.0' 68910264Sandreas.hansson@arm.com if compareVersions(protoc_version[1], min_protoc_version) < 0: 69010264Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + \ 69110457Sandreas.hansson@arm.com 'Warning: protoc version', min_protoc_version, \ 69210457Sandreas.hansson@arm.com 'or newer required.\n' + \ 69310457Sandreas.hansson@arm.com ' Installed version:', protoc_version[1], \ 69410457Sandreas.hansson@arm.com termcap.Normal 69510457Sandreas.hansson@arm.com main['PROTOC'] = False 69610457Sandreas.hansson@arm.com else: 69710457Sandreas.hansson@arm.com # Attempt to determine the appropriate include path and 69810457Sandreas.hansson@arm.com # library path using pkg-config, that means we also need to 69910457Sandreas.hansson@arm.com # check for pkg-config. Note that it is possible to use 70010238Sandreas.hansson@arm.com # protobuf without the involvement of pkg-config. Later on we 70110238Sandreas.hansson@arm.com # check go a library config check and at that point the test 70210238Sandreas.hansson@arm.com # will fail if libprotobuf cannot be found. 70310238Sandreas.hansson@arm.com if readCommand(['pkg-config', '--version'], exception=''): 70410238Sandreas.hansson@arm.com try: 70510238Sandreas.hansson@arm.com # Attempt to establish what linking flags to add for protobuf 70610416Sandreas.hansson@arm.com # using pkg-config 70710238Sandreas.hansson@arm.com main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 7089227Sandreas.hansson@arm.com except: 70910238Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + \ 71010416Sandreas.hansson@arm.com 'Warning: pkg-config could not get protobuf flags.' + \ 71110416Sandreas.hansson@arm.com termcap.Normal 7129227Sandreas.hansson@arm.com 7139590Sandreas@sandberg.pp.se# Check for SWIG 7149590Sandreas@sandberg.pp.seif not main.has_key('SWIG'): 7159590Sandreas@sandberg.pp.se print 'Error: SWIG utility not found.' 7168737Skoansin.tan@gmail.com print ' Please install (see http://www.swig.org) and retry.' 71710878Sandreas.hansson@arm.com Exit(1) 71810878Sandreas.hansson@arm.com 7199420Sandreas.hansson@arm.com# Check for appropriate SWIG version 7208737Skoansin.tan@gmail.comswig_version = readCommand([main['SWIG'], '-version'], exception='').split() 72110106SMitch.Hayenga@arm.com# First 3 words should be "SWIG Version x.y.z" 7228737Skoansin.tan@gmail.comif len(swig_version) < 3 or \ 7238737Skoansin.tan@gmail.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 72410878Sandreas.hansson@arm.com print 'Error determining SWIG version.' 72510878Sandreas.hansson@arm.com Exit(1) 7268737Skoansin.tan@gmail.com 7278737Skoansin.tan@gmail.commin_swig_version = '1.3.34' 7288737Skoansin.tan@gmail.comif compareVersions(swig_version[2], min_swig_version) < 0: 7298737Skoansin.tan@gmail.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 7308737Skoansin.tan@gmail.com print ' Installed version:', swig_version[2] 7318737Skoansin.tan@gmail.com Exit(1) 73211294Sandreas.hansson@arm.com 7339556Sandreas.hansson@arm.com# Older versions of swig do not play well with more recent versions of 7349556Sandreas.hansson@arm.com# gcc due to assumptions on implicit includes (cstddef) and use of 7359556Sandreas.hansson@arm.com# namespaces 73611294Sandreas.hansson@arm.comif main['GCC'] and compareVersions(gcc_version, '4.6') > 0 and \ 73710278SAndreas.Sandberg@ARM.com compareVersions(swig_version[2], '2') < 0: 73810278SAndreas.Sandberg@ARM.com print '\n' + termcap.Yellow + termcap.Bold + \ 73910278SAndreas.Sandberg@ARM.com 'Warning: SWIG 1.x cause issues with gcc 4.6 and later.\n' + \ 74010278SAndreas.Sandberg@ARM.com termcap.Normal + \ 74110278SAndreas.Sandberg@ARM.com 'Use SWIG 2.x to avoid assumptions on implicit includes\n' + \ 74210278SAndreas.Sandberg@ARM.com 'and use of namespaces\n' 7439556Sandreas.hansson@arm.com 7449590Sandreas@sandberg.pp.se# Set up SWIG flags & scanner 7459590Sandreas@sandberg.pp.seswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 7469420Sandreas.hansson@arm.commain.Append(SWIGFLAGS=swig_flags) 7479846Sandreas.hansson@arm.com 7489846Sandreas.hansson@arm.com# filter out all existing swig scanners, they mess up the dependency 7499846Sandreas.hansson@arm.com# stuff for some reason 7509846Sandreas.hansson@arm.comscanners = [] 7518946Sandreas.hansson@arm.comfor scanner in main['SCANNERS']: 7523918Ssaidi@eecs.umich.edu skeys = scanner.skeys 7539068SAli.Saidi@ARM.com if skeys == '.i': 7549068SAli.Saidi@ARM.com continue 7559068SAli.Saidi@ARM.com 7569068SAli.Saidi@ARM.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 7579068SAli.Saidi@ARM.com continue 7589068SAli.Saidi@ARM.com 7599068SAli.Saidi@ARM.com scanners.append(scanner) 7609068SAli.Saidi@ARM.com 7619068SAli.Saidi@ARM.com# add the new swig scanner that we like better 7629419Sandreas.hansson@arm.comfrom SCons.Scanner import ClassicCPP as CPPScanner 7639068SAli.Saidi@ARM.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 7649068SAli.Saidi@ARM.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 7659068SAli.Saidi@ARM.com 7669068SAli.Saidi@ARM.com# replace the scanners list that has what we want 7679068SAli.Saidi@ARM.commain['SCANNERS'] = scanners 7689068SAli.Saidi@ARM.com 7693918Ssaidi@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 7703918Ssaidi@eecs.umich.edu# figure out if the compiler adds leading underscores to global 7716157Snate@binkert.org# variables. This is needed for the autogenerated asm files that we 7726157Snate@binkert.org# use for embedding the python code. 7736157Snate@binkert.orgdef CheckLeading(context): 7746157Snate@binkert.org context.Message("Checking for leading underscore in global variables...") 7755397Ssaidi@eecs.umich.edu # 1) Define a global variable called x from asm so the C compiler 7765397Ssaidi@eecs.umich.edu # won't change the symbol at all. 7776121Snate@binkert.org # 2) Declare that variable. 7786121Snate@binkert.org # 3) Use the variable 7796121Snate@binkert.org # 7806121Snate@binkert.org # If the compiler prepends an underscore, this will successfully 7816121Snate@binkert.org # link because the external symbol 'x' will be called '_x' which 7826121Snate@binkert.org # was defined by the asm statement. If the compiler does not 7835397Ssaidi@eecs.umich.edu # prepend an underscore, this will not successfully link because 7841851SN/A # '_x' will have been defined by assembly, while the C portion of 7851851SN/A # the code will be trying to use 'x' 7867739Sgblack@eecs.umich.edu ret = context.TryLink(''' 787955SN/A asm(".globl _x; _x: .byte 0"); 7889396Sandreas.hansson@arm.com extern int x; 7899396Sandreas.hansson@arm.com int main() { return x; } 7909396Sandreas.hansson@arm.com ''', extension=".c") 7919396Sandreas.hansson@arm.com context.env.Append(LEADING_UNDERSCORE=ret) 7929396Sandreas.hansson@arm.com context.Result(ret) 7939396Sandreas.hansson@arm.com return ret 7949396Sandreas.hansson@arm.com 7959396Sandreas.hansson@arm.com# Platform-specific configuration. Note again that we assume that all 7969396Sandreas.hansson@arm.com# builds under a given build root run on the same host platform. 7979396Sandreas.hansson@arm.comconf = Configure(main, 7989396Sandreas.hansson@arm.com conf_dir = joinpath(build_root, '.scons_config'), 7999396Sandreas.hansson@arm.com log_file = joinpath(build_root, 'scons_config.log'), 8009396Sandreas.hansson@arm.com custom_tests = { 'CheckLeading' : CheckLeading }) 8019396Sandreas.hansson@arm.com 8029396Sandreas.hansson@arm.com# Check for leading underscores. Don't really need to worry either 8039396Sandreas.hansson@arm.com# way so don't need to check the return code. 8049477Sandreas.hansson@arm.comconf.CheckLeading() 8059477Sandreas.hansson@arm.com 8069477Sandreas.hansson@arm.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 8079477Sandreas.hansson@arm.comtry: 8089477Sandreas.hansson@arm.com import platform 8099477Sandreas.hansson@arm.com uname = platform.uname() 8109477Sandreas.hansson@arm.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 8119477Sandreas.hansson@arm.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 8129477Sandreas.hansson@arm.com main.Append(CCFLAGS=['-arch', 'x86_64']) 8139477Sandreas.hansson@arm.com main.Append(CFLAGS=['-arch', 'x86_64']) 8149477Sandreas.hansson@arm.com main.Append(LINKFLAGS=['-arch', 'x86_64']) 8159477Sandreas.hansson@arm.com main.Append(ASFLAGS=['-arch', 'x86_64']) 8169477Sandreas.hansson@arm.comexcept: 8179477Sandreas.hansson@arm.com pass 8189477Sandreas.hansson@arm.com 8199477Sandreas.hansson@arm.com# Recent versions of scons substitute a "Null" object for Configure() 8209477Sandreas.hansson@arm.com# when configuration isn't necessary, e.g., if the "--help" option is 8219477Sandreas.hansson@arm.com# present. Unfortuantely this Null object always returns false, 8229477Sandreas.hansson@arm.com# breaking all our configuration checks. We replace it with our own 8239477Sandreas.hansson@arm.com# more optimistic null object that returns True instead. 8249477Sandreas.hansson@arm.comif not conf: 8259477Sandreas.hansson@arm.com def NullCheck(*args, **kwargs): 8269396Sandreas.hansson@arm.com return True 8273053Sstever@eecs.umich.edu 8286121Snate@binkert.org class NullConf: 8293053Sstever@eecs.umich.edu def __init__(self, env): 8303053Sstever@eecs.umich.edu self.env = env 8313053Sstever@eecs.umich.edu def Finish(self): 8323053Sstever@eecs.umich.edu return self.env 8333053Sstever@eecs.umich.edu def __getattr__(self, mname): 8349072Sandreas.hansson@arm.com return NullCheck 8353053Sstever@eecs.umich.edu 8364742Sstever@eecs.umich.edu conf = NullConf(main) 8374742Sstever@eecs.umich.edu 8383053Sstever@eecs.umich.edu# Cache build files in the supplied directory. 8393053Sstever@eecs.umich.eduif main['M5_BUILD_CACHE']: 8403053Sstever@eecs.umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 84110181SCurtis.Dunham@arm.com CacheDir(main['M5_BUILD_CACHE']) 8426654Snate@binkert.org 8433053Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 8443053Sstever@eecs.umich.edu# interpreter. We rely on python-config to resolve the appropriate 8453053Sstever@eecs.umich.edu# includes and linker flags. ParseConfig does not seem to understand 8463053Sstever@eecs.umich.edu# the more exotic linker flags such as -Xlinker and -export-dynamic so 84710425Sandreas.hansson@arm.com# we add them explicitly below. If you want to link in an alternate 84810425Sandreas.hansson@arm.com# version of python, see above for instructions on how to invoke 84910425Sandreas.hansson@arm.com# scons with the appropriate PATH set. 85010425Sandreas.hansson@arm.compy_includes = readCommand(['python-config', '--includes'], 85110425Sandreas.hansson@arm.com exception='').split() 85210425Sandreas.hansson@arm.com# Strip the -I from the include folders before adding them to the 85310425Sandreas.hansson@arm.com# CPPPATH 85410425Sandreas.hansson@arm.commain.Append(CPPPATH=map(lambda inc: inc[2:], py_includes)) 85510425Sandreas.hansson@arm.com 85610425Sandreas.hansson@arm.com# Read the linker flags and split them into libraries and other link 85710425Sandreas.hansson@arm.com# flags. The libraries are added later through the call the CheckLib. 8582667Sstever@eecs.umich.edupy_ld_flags = readCommand(['python-config', '--ldflags'], exception='').split() 8594554Sbinkertn@umich.edupy_libs = [] 8606121Snate@binkert.orgfor lib in py_ld_flags: 8612667Sstever@eecs.umich.edu if not lib.startswith('-l'): 86210710Sandreas.hansson@arm.com main.Append(LINKFLAGS=[lib]) 86310710Sandreas.hansson@arm.com else: 86410710Sandreas.hansson@arm.com lib = lib[2:] 86510710Sandreas.hansson@arm.com if lib not in py_libs: 86610710Sandreas.hansson@arm.com py_libs.append(lib) 86710710Sandreas.hansson@arm.com 86810710Sandreas.hansson@arm.com# verify that this stuff works 86910710Sandreas.hansson@arm.comif not conf.CheckHeader('Python.h', '<>'): 87010710Sandreas.hansson@arm.com print "Error: can't find Python.h header in", py_includes 87110384SCurtis.Dunham@arm.com print "Install Python headers (package python-dev on Ubuntu and RedHat)" 8724554Sbinkertn@umich.edu Exit(1) 8734554Sbinkertn@umich.edu 8744554Sbinkertn@umich.edufor lib in py_libs: 8756121Snate@binkert.org if not conf.CheckLib(lib): 8764554Sbinkertn@umich.edu print "Error: can't find library %s required by python" % lib 8774554Sbinkertn@umich.edu Exit(1) 8784554Sbinkertn@umich.edu 8794781Snate@binkert.org# On Solaris you need to use libsocket for socket ops 8804554Sbinkertn@umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 8814554Sbinkertn@umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 8822667Sstever@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 8834554Sbinkertn@umich.edu Exit(1) 8844554Sbinkertn@umich.edu 8854554Sbinkertn@umich.edu# Check for zlib. If the check passes, libz will be automatically 8864554Sbinkertn@umich.edu# added to the LIBS environment variable. 8872667Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 8884554Sbinkertn@umich.edu print 'Error: did not find needed zlib compression library '\ 8892667Sstever@eecs.umich.edu 'and/or zlib.h header file.' 8904554Sbinkertn@umich.edu print ' Please install zlib and try again.' 8916121Snate@binkert.org Exit(1) 8922667Sstever@eecs.umich.edu 8939986Sandreas@sandberg.pp.se# If we have the protobuf compiler, also make sure we have the 8949986Sandreas@sandberg.pp.se# development libraries. If the check passes, libprotobuf will be 8959986Sandreas@sandberg.pp.se# automatically added to the LIBS environment variable. After 8969986Sandreas@sandberg.pp.se# this, we can use the HAVE_PROTOBUF flag to determine if we have 8979986Sandreas@sandberg.pp.se# got both protoc and libprotobuf available. 8989986Sandreas@sandberg.pp.semain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 8999986Sandreas@sandberg.pp.se conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 9009986Sandreas@sandberg.pp.se 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 9019986Sandreas@sandberg.pp.se 9029986Sandreas@sandberg.pp.se# If we have the compiler but not the library, print another warning. 9039986Sandreas@sandberg.pp.seif main['PROTOC'] and not main['HAVE_PROTOBUF']: 9049986Sandreas@sandberg.pp.se print termcap.Yellow + termcap.Bold + \ 9059986Sandreas@sandberg.pp.se 'Warning: did not find protocol buffer library and/or headers.\n' + \ 9069986Sandreas@sandberg.pp.se ' Please install libprotobuf-dev for tracing support.' + \ 9079986Sandreas@sandberg.pp.se termcap.Normal 9089986Sandreas@sandberg.pp.se 9099986Sandreas@sandberg.pp.se# Check for librt. 9109986Sandreas@sandberg.pp.sehave_posix_clock = \ 9119986Sandreas@sandberg.pp.se conf.CheckLibWithHeader(None, 'time.h', 'C', 9129986Sandreas@sandberg.pp.se 'clock_nanosleep(0,0,NULL,NULL);') or \ 9132638Sstever@eecs.umich.edu conf.CheckLibWithHeader('rt', 'time.h', 'C', 9142638Sstever@eecs.umich.edu 'clock_nanosleep(0,0,NULL,NULL);') 9156121Snate@binkert.org 9163716Sstever@eecs.umich.eduif conf.CheckLib('tcmalloc'): 9175522Snate@binkert.org main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 9189986Sandreas@sandberg.pp.seelif conf.CheckLib('tcmalloc_minimal'): 9199986Sandreas@sandberg.pp.se main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 9209986Sandreas@sandberg.pp.seelse: 9215522Snate@binkert.org print termcap.Yellow + termcap.Bold + \ 9225227Ssaidi@eecs.umich.edu "You can get a 12% performance improvement by installing tcmalloc "\ 9235227Ssaidi@eecs.umich.edu "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \ 9245227Ssaidi@eecs.umich.edu termcap.Normal 9255227Ssaidi@eecs.umich.edu 9266654Snate@binkert.orgif not have_posix_clock: 9276654Snate@binkert.org print "Can't find library for POSIX clocks." 9287769SAli.Saidi@ARM.com 9297769SAli.Saidi@ARM.com# Check for <fenv.h> (C99 FP environment control) 9307769SAli.Saidi@ARM.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 9317769SAli.Saidi@ARM.comif not have_fenv: 9325227Ssaidi@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 9335227Ssaidi@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 9345227Ssaidi@eecs.umich.edu 9355204Sstever@gmail.com# Check if we should enable KVM-based hardware virtualization 9365204Sstever@gmail.comhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 9375204Sstever@gmail.comif not have_kvm: 9385204Sstever@gmail.com print "Info: Header file <linux/kvm.h> not found, " \ 9395204Sstever@gmail.com "disabling KVM support." 9405204Sstever@gmail.com 9415204Sstever@gmail.com# Check if the requested target ISA is compatible with the host 9425204Sstever@gmail.comdef is_isa_kvm_compatible(isa): 9435204Sstever@gmail.com isa_comp_table = { 9445204Sstever@gmail.com "arm" : ( "armv7l" ), 9455204Sstever@gmail.com "x86" : ( "x86_64" ), 9465204Sstever@gmail.com } 9475204Sstever@gmail.com try: 9485204Sstever@gmail.com import platform 9495204Sstever@gmail.com host_isa = platform.machine() 9505204Sstever@gmail.com except: 9515204Sstever@gmail.com print "Warning: Failed to determine host ISA." 9526121Snate@binkert.org return False 9535204Sstever@gmail.com 9547727SAli.Saidi@ARM.com return host_isa in isa_comp_table.get(isa, []) 9557727SAli.Saidi@ARM.com 9567727SAli.Saidi@ARM.com 9577727SAli.Saidi@ARM.com###################################################################### 9587727SAli.Saidi@ARM.com# 95910453SAndrew.Bardsley@arm.com# Finish the configuration 96010453SAndrew.Bardsley@arm.com# 96110453SAndrew.Bardsley@arm.commain = conf.Finish() 96210453SAndrew.Bardsley@arm.com 96310453SAndrew.Bardsley@arm.com###################################################################### 96410453SAndrew.Bardsley@arm.com# 96510453SAndrew.Bardsley@arm.com# Collect all non-global variables 96610453SAndrew.Bardsley@arm.com# 96710453SAndrew.Bardsley@arm.com 96810453SAndrew.Bardsley@arm.com# Define the universe of supported ISAs 96910453SAndrew.Bardsley@arm.comall_isa_list = [ ] 97010160Sandreas.hansson@arm.comExport('all_isa_list') 97110453SAndrew.Bardsley@arm.com 97210453SAndrew.Bardsley@arm.comclass CpuModel(object): 97310453SAndrew.Bardsley@arm.com '''The CpuModel class encapsulates everything the ISA parser needs to 97410453SAndrew.Bardsley@arm.com know about a particular CPU model.''' 97510453SAndrew.Bardsley@arm.com 97610453SAndrew.Bardsley@arm.com # Dict of available CPU model objects. Accessible as CpuModel.dict. 97710453SAndrew.Bardsley@arm.com dict = {} 97810453SAndrew.Bardsley@arm.com list = [] 9799812Sandreas.hansson@arm.com defaults = [] 98010453SAndrew.Bardsley@arm.com 98110453SAndrew.Bardsley@arm.com # Constructor. Automatically adds models to CpuModel.dict. 98210453SAndrew.Bardsley@arm.com def __init__(self, name, filename, includes, strings, default=False): 98310453SAndrew.Bardsley@arm.com self.name = name # name of model 98410453SAndrew.Bardsley@arm.com self.filename = filename # filename for output exec code 98510453SAndrew.Bardsley@arm.com self.includes = includes # include files needed in exec file 98610453SAndrew.Bardsley@arm.com # The 'strings' dict holds all the per-CPU symbols we can 98710453SAndrew.Bardsley@arm.com # substitute into templates etc. 98810453SAndrew.Bardsley@arm.com self.strings = strings 98910453SAndrew.Bardsley@arm.com 99010453SAndrew.Bardsley@arm.com # This cpu is enabled by default 99110453SAndrew.Bardsley@arm.com self.default = default 9927727SAli.Saidi@ARM.com 99310453SAndrew.Bardsley@arm.com # Add self to dict 99410453SAndrew.Bardsley@arm.com if name in CpuModel.dict: 99510453SAndrew.Bardsley@arm.com raise AttributeError, "CpuModel '%s' already registered" % name 99610453SAndrew.Bardsley@arm.com CpuModel.dict[name] = self 99710453SAndrew.Bardsley@arm.com CpuModel.list.append(name) 9983118Sstever@eecs.umich.edu 99910453SAndrew.Bardsley@arm.comExport('CpuModel') 100010453SAndrew.Bardsley@arm.com 100110453SAndrew.Bardsley@arm.com# Sticky variables get saved in the variables file so they persist from 100210453SAndrew.Bardsley@arm.com# one invocation to the next (unless overridden, in which case the new 10033118Sstever@eecs.umich.edu# value becomes sticky). 10043483Ssaidi@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS) 10053494Ssaidi@eecs.umich.eduExport('sticky_vars') 10063494Ssaidi@eecs.umich.edu 10073483Ssaidi@eecs.umich.edu# Sticky variables that should be exported 10083483Ssaidi@eecs.umich.eduexport_vars = [] 10093483Ssaidi@eecs.umich.eduExport('export_vars') 10103053Sstever@eecs.umich.edu 10113053Sstever@eecs.umich.edu# For Ruby 10123918Ssaidi@eecs.umich.eduall_protocols = [] 10133053Sstever@eecs.umich.eduExport('all_protocols') 10143053Sstever@eecs.umich.eduprotocol_dirs = [] 10153053Sstever@eecs.umich.eduExport('protocol_dirs') 10163053Sstever@eecs.umich.eduslicc_includes = [] 10173053Sstever@eecs.umich.eduExport('slicc_includes') 10189396Sandreas.hansson@arm.com 10199396Sandreas.hansson@arm.com# Walk the tree and execute all SConsopts scripts that wil add to the 10209396Sandreas.hansson@arm.com# above variables 10219396Sandreas.hansson@arm.comif not GetOption('verbose'): 10229396Sandreas.hansson@arm.com print "Reading SConsopts" 10239396Sandreas.hansson@arm.comfor bdir in [ base_dir ] + extras_dir_list: 10249396Sandreas.hansson@arm.com if not isdir(bdir): 10259396Sandreas.hansson@arm.com print "Error: directory '%s' does not exist" % bdir 10269396Sandreas.hansson@arm.com Exit(1) 10279477Sandreas.hansson@arm.com for root, dirs, files in os.walk(bdir): 10289396Sandreas.hansson@arm.com if 'SConsopts' in files: 10299477Sandreas.hansson@arm.com if GetOption('verbose'): 10309477Sandreas.hansson@arm.com print "Reading", joinpath(root, 'SConsopts') 10319477Sandreas.hansson@arm.com SConscript(joinpath(root, 'SConsopts')) 10329477Sandreas.hansson@arm.com 10339396Sandreas.hansson@arm.comall_isa_list.sort() 10347840Snate@binkert.org 10357865Sgblack@eecs.umich.edusticky_vars.AddVariables( 10367865Sgblack@eecs.umich.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 10377865Sgblack@eecs.umich.edu ListVariable('CPU_MODELS', 'CPU models', 10387865Sgblack@eecs.umich.edu sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 10397865Sgblack@eecs.umich.edu sorted(CpuModel.list)), 10407840Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 10419900Sandreas@sandberg.pp.se False), 10429900Sandreas@sandberg.pp.se BoolVariable('SS_COMPATIBLE_FP', 10439900Sandreas@sandberg.pp.se 'Make floating-point results compatible with SimpleScalar', 10449900Sandreas@sandberg.pp.se False), 104510456SCurtis.Dunham@arm.com BoolVariable('USE_SSE2', 104610456SCurtis.Dunham@arm.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 104710456SCurtis.Dunham@arm.com False), 104810456SCurtis.Dunham@arm.com BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 104910456SCurtis.Dunham@arm.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 105010456SCurtis.Dunham@arm.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 105110456SCurtis.Dunham@arm.com BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm), 105210456SCurtis.Dunham@arm.com EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 105310456SCurtis.Dunham@arm.com all_protocols), 105410456SCurtis.Dunham@arm.com ) 10559045SAli.Saidi@ARM.com 105611235Sandreas.sandberg@arm.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 105711235Sandreas.sandberg@arm.comexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'CP_ANNOTATE', 105811235Sandreas.sandberg@arm.com 'USE_POSIX_CLOCK', 'PROTOCOL', 'HAVE_PROTOBUF'] 105911235Sandreas.sandberg@arm.com 106011235Sandreas.sandberg@arm.com################################################### 106111235Sandreas.sandberg@arm.com# 106211235Sandreas.sandberg@arm.com# Define a SCons builder for configuration flag headers. 106311235Sandreas.sandberg@arm.com# 106411235Sandreas.sandberg@arm.com################################################### 106511235Sandreas.sandberg@arm.com 106611235Sandreas.sandberg@arm.com# This function generates a config header file that #defines the 106711235Sandreas.sandberg@arm.com# variable symbol to the current variable setting (0 or 1). The source 106811235Sandreas.sandberg@arm.com# operands are the name of the variable and a Value node containing the 106911235Sandreas.sandberg@arm.com# value of the variable. 107011235Sandreas.sandberg@arm.comdef build_config_file(target, source, env): 10717840Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 10727840Snate@binkert.org f = file(str(target[0]), 'w') 10737840Snate@binkert.org print >> f, '#define', variable, value 10741858SN/A f.close() 10751858SN/A return None 10761858SN/A 10771858SN/A# Combine the two functions into a scons Action object. 10781858SN/Aconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 10791858SN/A 10809903Sandreas.hansson@arm.com# The emitter munges the source & target node lists to reflect what 10819903Sandreas.hansson@arm.com# we're really doing. 10829903Sandreas.hansson@arm.comdef config_emitter(target, source, env): 10839903Sandreas.hansson@arm.com # extract variable name from Builder arg 108410841Sandreas.sandberg@arm.com variable = str(target[0]) 10859651SAndreas.Sandberg@ARM.com # True target is config header file 10869903Sandreas.hansson@arm.com target = joinpath('config', variable.lower() + '.hh') 10879651SAndreas.Sandberg@ARM.com val = env[variable] 10889651SAndreas.Sandberg@ARM.com if isinstance(val, bool): 108910841Sandreas.sandberg@arm.com # Force value to 0/1 109010841Sandreas.sandberg@arm.com val = int(val) 109110841Sandreas.sandberg@arm.com elif isinstance(val, str): 109210841Sandreas.sandberg@arm.com val = '"' + val + '"' 109310841Sandreas.sandberg@arm.com 109410841Sandreas.sandberg@arm.com # Sources are variable name & value (packaged in SCons Value nodes) 10959651SAndreas.Sandberg@ARM.com return ([target], [Value(variable), Value(val)]) 10969651SAndreas.Sandberg@ARM.com 10979651SAndreas.Sandberg@ARM.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 10989651SAndreas.Sandberg@ARM.com 10999651SAndreas.Sandberg@ARM.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 11009651SAndreas.Sandberg@ARM.com 11019651SAndreas.Sandberg@ARM.com# libelf build is shared across all configs in the build root. 11029651SAndreas.Sandberg@ARM.commain.SConscript('ext/libelf/SConscript', 11039651SAndreas.Sandberg@ARM.com variant_dir = joinpath(build_root, 'libelf')) 110410841Sandreas.sandberg@arm.com 110510841Sandreas.sandberg@arm.com# gzstream build is shared across all configs in the build root. 110610841Sandreas.sandberg@arm.commain.SConscript('ext/gzstream/SConscript', 110710841Sandreas.sandberg@arm.com variant_dir = joinpath(build_root, 'gzstream')) 110810841Sandreas.sandberg@arm.com 110910841Sandreas.sandberg@arm.com# libfdt build is shared across all configs in the build root. 111010860Sandreas.sandberg@arm.commain.SConscript('ext/libfdt/SConscript', 111110841Sandreas.sandberg@arm.com variant_dir = joinpath(build_root, 'libfdt')) 111210841Sandreas.sandberg@arm.com 111310841Sandreas.sandberg@arm.com################################################### 111410841Sandreas.sandberg@arm.com# 111510841Sandreas.sandberg@arm.com# This function is used to set up a directory with switching headers 111610841Sandreas.sandberg@arm.com# 111710841Sandreas.sandberg@arm.com################################################### 111810841Sandreas.sandberg@arm.com 111910841Sandreas.sandberg@arm.commain['ALL_ISA_LIST'] = all_isa_list 112010841Sandreas.sandberg@arm.comdef make_switching_dir(dname, switch_headers, env): 112110841Sandreas.sandberg@arm.com # Generate the header. target[0] is the full path of the output 11229651SAndreas.Sandberg@ARM.com # header to generate. 'source' is a dummy variable, since we get the 11239651SAndreas.Sandberg@ARM.com # list of ISAs from env['ALL_ISA_LIST']. 11249986Sandreas@sandberg.pp.se def gen_switch_hdr(target, source, env): 11259986Sandreas@sandberg.pp.se fname = str(target[0]) 11269986Sandreas@sandberg.pp.se f = open(fname, 'w') 11279986Sandreas@sandberg.pp.se isa = env['TARGET_ISA'].lower() 11289986Sandreas@sandberg.pp.se print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 11299986Sandreas@sandberg.pp.se f.close() 11305863Snate@binkert.org 11315863Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 11325863Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 11335863Snate@binkert.org # should get re-executed. 11346121Snate@binkert.org switch_hdr_action = MakeAction(gen_switch_hdr, 11351858SN/A Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 11365863Snate@binkert.org 11375863Snate@binkert.org # Instantiate actions for each header 11385863Snate@binkert.org for hdr in switch_headers: 11395863Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 11405863Snate@binkert.orgExport('make_switching_dir') 11412139SN/A 11424202Sbinkertn@umich.edu################################################### 114311308Santhony.gutierrez@amd.com# 11444202Sbinkertn@umich.edu# Define build environments for selected configurations. 114511308Santhony.gutierrez@amd.com# 11462139SN/A################################################### 11476994Snate@binkert.org 11486994Snate@binkert.orgfor variant_path in variant_paths: 11496994Snate@binkert.org print "Building in", variant_path 11506994Snate@binkert.org 11516994Snate@binkert.org # Make a copy of the build-root environment to use for this config. 11526994Snate@binkert.org env = main.Clone() 11536994Snate@binkert.org env['BUILDDIR'] = variant_path 11546994Snate@binkert.org 115510319SAndreas.Sandberg@ARM.com # variant_dir is the tail component of build path, and is used to 11566994Snate@binkert.org # determine the build parameters (e.g., 'ALPHA_SE') 11576994Snate@binkert.org (build_root, variant_dir) = splitpath(variant_path) 11586994Snate@binkert.org 11596994Snate@binkert.org # Set env variables according to the build directory config. 11606994Snate@binkert.org sticky_vars.files = [] 11616994Snate@binkert.org # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 11626994Snate@binkert.org # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 11636994Snate@binkert.org # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 11646994Snate@binkert.org current_vars_file = joinpath(build_root, 'variables', variant_dir) 11656994Snate@binkert.org if isfile(current_vars_file): 11666994Snate@binkert.org sticky_vars.files.append(current_vars_file) 11672155SN/A print "Using saved variables file %s" % current_vars_file 11685863Snate@binkert.org else: 11691869SN/A # Build dir-specific variables file doesn't exist. 11701869SN/A 11715863Snate@binkert.org # Make sure the directory is there so we can create it later 11725863Snate@binkert.org opt_dir = dirname(current_vars_file) 11734202Sbinkertn@umich.edu if not isdir(opt_dir): 11746108Snate@binkert.org mkdir(opt_dir) 11756108Snate@binkert.org 11766108Snate@binkert.org # Get default build variables from source tree. Variables are 11776108Snate@binkert.org # normally determined by name of $VARIANT_DIR, but can be 11789219Spower.jg@gmail.com # overridden by '--default=' arg on command line. 11799219Spower.jg@gmail.com default = GetOption('default') 11809219Spower.jg@gmail.com opts_dir = joinpath(main.root.abspath, 'build_opts') 11819219Spower.jg@gmail.com if default: 11829219Spower.jg@gmail.com default_vars_files = [joinpath(build_root, 'variables', default), 11839219Spower.jg@gmail.com joinpath(opts_dir, default)] 11849219Spower.jg@gmail.com else: 11859219Spower.jg@gmail.com default_vars_files = [joinpath(opts_dir, variant_dir)] 11864202Sbinkertn@umich.edu existing_files = filter(isfile, default_vars_files) 11875863Snate@binkert.org if existing_files: 118810135SCurtis.Dunham@arm.com default_vars_file = existing_files[0] 11898474Sgblack@eecs.umich.edu sticky_vars.files.append(default_vars_file) 11905742Snate@binkert.org print "Variables file %s not found,\n using defaults in %s" \ 11918268Ssteve.reinhardt@amd.com % (current_vars_file, default_vars_file) 11928268Ssteve.reinhardt@amd.com else: 11938268Ssteve.reinhardt@amd.com print "Error: cannot find variables file %s or " \ 11945742Snate@binkert.org "default file(s) %s" \ 11955341Sstever@gmail.com % (current_vars_file, ' or '.join(default_vars_files)) 11968474Sgblack@eecs.umich.edu Exit(1) 11978474Sgblack@eecs.umich.edu 11985342Sstever@gmail.com # Apply current variable settings to env 11994202Sbinkertn@umich.edu sticky_vars.Update(env) 12004202Sbinkertn@umich.edu 120111308Santhony.gutierrez@amd.com help_texts["local_vars"] += \ 12024202Sbinkertn@umich.edu "Build variables for %s:\n" % variant_dir \ 12035863Snate@binkert.org + sticky_vars.GenerateHelpText(env) 12045863Snate@binkert.org 120511308Santhony.gutierrez@amd.com # Process variable settings. 12066994Snate@binkert.org 12076994Snate@binkert.org if not have_fenv and env['USE_FENV']: 120810319SAndreas.Sandberg@ARM.com print "Warning: <fenv.h> not available; " \ 12095863Snate@binkert.org "forcing USE_FENV to False in", variant_dir + "." 12105863Snate@binkert.org env['USE_FENV'] = False 12115863Snate@binkert.org 12125863Snate@binkert.org if not env['USE_FENV']: 12135863Snate@binkert.org print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 12145863Snate@binkert.org print " FP results may deviate slightly from other platforms." 12155863Snate@binkert.org 12165863Snate@binkert.org if env['EFENCE']: 12177840Snate@binkert.org env.Append(LIBS=['efence']) 12185863Snate@binkert.org 12195952Ssaidi@eecs.umich.edu if env['USE_KVM']: 12209651SAndreas.Sandberg@ARM.com if not have_kvm: 122111308Santhony.gutierrez@amd.com print "Warning: Can not enable KVM, host seems to lack KVM support" 12229219Spower.jg@gmail.com env['USE_KVM'] = False 12239219Spower.jg@gmail.com elif not is_isa_kvm_compatible(env['TARGET_ISA']): 122411235Sandreas.sandberg@arm.com print "Info: KVM support disabled due to unsupported host and " \ 122511235Sandreas.sandberg@arm.com "target ISA combination" 12261869SN/A env['USE_KVM'] = False 12271858SN/A 12285863Snate@binkert.org # Save sticky variable settings back to current variables file 122911308Santhony.gutierrez@amd.com sticky_vars.Save(current_vars_file, env) 123011308Santhony.gutierrez@amd.com 123111308Santhony.gutierrez@amd.com if env['USE_SSE2']: 12321858SN/A env.Append(CCFLAGS=['-msse2']) 1233955SN/A 1234955SN/A # The src/SConscript file sets up the build rules in 'env' according 12351869SN/A # to the configured variables. It returns a list of environments, 12361869SN/A # one for each variant build (debug, opt, etc.) 12371869SN/A envList = SConscript('src/SConscript', variant_dir = variant_path, 12381869SN/A exports = 'env') 12391869SN/A 12405863Snate@binkert.org # Set up the regression tests for each build. 12415863Snate@binkert.org for e in envList: 12425863Snate@binkert.org SConscript('tests/SConscript', 12431869SN/A variant_dir = joinpath(variant_path, 'tests', e.Label), 12445863Snate@binkert.org exports = { 'env' : e }, duplicate = False) 12451869SN/A 12465863Snate@binkert.org# base help text 12471869SN/AHelp(''' 12481869SN/AUsage: scons [scons options] [build variables] [target(s)] 12491869SN/A 12501869SN/AExtra scons options: 12518483Sgblack@eecs.umich.edu%(options)s 12521869SN/A 12531869SN/AGlobal build variables: 12541869SN/A%(global_vars)s 12551869SN/A 12565863Snate@binkert.org%(local_vars)s 12575863Snate@binkert.org''' % help_texts) 12581869SN/A