SConstruct revision 10866
1955SN/A# -*- mode:python -*- 2955SN/A 311408Sandreas.sandberg@arm.com# Copyright (c) 2013, 2015 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 itertools 113955SN/Aimport os 1145396Ssaidi@eecs.umich.eduimport re 11511401Sandreas.sandberg@arm.comimport subprocess 1165863Snate@binkert.orgimport sys 1175863Snate@binkert.org 1184202Sbinkertn@umich.edufrom os import mkdir, environ 1195863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1205863Snate@binkert.orgfrom os.path import exists, isdir, isfile 1215863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1225863Snate@binkert.org 123955SN/A# SCons includes 1246654Snate@binkert.orgimport SCons 1255273Sstever@gmail.comimport SCons.Node 1265871Snate@binkert.org 1275273Sstever@gmail.comextra_python_paths = [ 1286655Snate@binkert.org Dir('src/python').srcnode().abspath, # gem5 includes 1298878Ssteve.reinhardt@amd.com Dir('ext/ply').srcnode().abspath, # ply is used by several files 1306655Snate@binkert.org ] 1316655Snate@binkert.org 1329219Spower.jg@gmail.comsys.path[1:1] = extra_python_paths 1336655Snate@binkert.org 1345871Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1356654Snate@binkert.orgfrom m5.util.terminal import get_termcap 1368947Sandreas.hansson@arm.com 1375396Ssaidi@eecs.umich.eduhelp_texts = { 1388120Sgblack@eecs.umich.edu "options" : "", 1398120Sgblack@eecs.umich.edu "global_vars" : "", 1408120Sgblack@eecs.umich.edu "local_vars" : "" 1418120Sgblack@eecs.umich.edu} 1428120Sgblack@eecs.umich.edu 1438120Sgblack@eecs.umich.eduExport("help_texts") 1448120Sgblack@eecs.umich.edu 1458120Sgblack@eecs.umich.edu 1468879Ssteve.reinhardt@amd.com# There's a bug in scons in that (1) by default, the help texts from 1478879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h' 1488879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the 1498879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once 1508879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get 1518879Ssteve.reinhardt@amd.com# at the help texts from AddOptions. See: 1528879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1538879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1548879Ssteve.reinhardt@amd.com# This hack lets us extract the help text from AddOptions and 1558879Ssteve.reinhardt@amd.com# re-inject it via Help(). Ideally someday this bug will be fixed and 1568879Ssteve.reinhardt@amd.com# we can just use AddOption directly. 1578879Ssteve.reinhardt@amd.comdef AddLocalOption(*args, **kwargs): 1588879Ssteve.reinhardt@amd.com col_width = 30 1598120Sgblack@eecs.umich.edu 1608120Sgblack@eecs.umich.edu help = " " + ", ".join(args) 1618120Sgblack@eecs.umich.edu if "help" in kwargs: 1628120Sgblack@eecs.umich.edu length = len(help) 1638120Sgblack@eecs.umich.edu if length >= col_width: 1648120Sgblack@eecs.umich.edu help += "\n" + " " * col_width 1658120Sgblack@eecs.umich.edu else: 1668120Sgblack@eecs.umich.edu help += " " * (col_width - length) 1678120Sgblack@eecs.umich.edu help += kwargs["help"] 1688120Sgblack@eecs.umich.edu help_texts["options"] += help + "\n" 1698120Sgblack@eecs.umich.edu 1708120Sgblack@eecs.umich.edu AddOption(*args, **kwargs) 1718120Sgblack@eecs.umich.edu 1728120Sgblack@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true', 1738879Ssteve.reinhardt@amd.com help="Add color to abbreviated scons output") 1748879Ssteve.reinhardt@amd.comAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1758879Ssteve.reinhardt@amd.com help="Don't add color to abbreviated scons output") 1768879Ssteve.reinhardt@amd.comAddLocalOption('--with-cxx-config', dest='with_cxx_config', 17710458Sandreas.hansson@arm.com action='store_true', 17810458Sandreas.hansson@arm.com help="Build with support for C++-based configuration") 17910458Sandreas.hansson@arm.comAddLocalOption('--default', dest='default', type='string', action='store', 1808879Ssteve.reinhardt@amd.com help='Override which build_opts file to use for defaults') 1818879Ssteve.reinhardt@amd.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1828879Ssteve.reinhardt@amd.com help='Disable style checking hooks') 1838879Ssteve.reinhardt@amd.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1849227Sandreas.hansson@arm.com help='Disable Link-Time Optimization for fast') 1859227Sandreas.hansson@arm.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1868879Ssteve.reinhardt@amd.com help='Update test reference outputs') 1878879Ssteve.reinhardt@amd.comAddLocalOption('--verbose', dest='verbose', action='store_true', 1888879Ssteve.reinhardt@amd.com help='Print full tool command lines') 1898879Ssteve.reinhardt@amd.comAddLocalOption('--without-python', dest='without_python', 19010453SAndrew.Bardsley@arm.com action='store_true', 19110453SAndrew.Bardsley@arm.com help='Build without Python configuration support') 19210453SAndrew.Bardsley@arm.comAddLocalOption('--without-tcmalloc', dest='without_tcmalloc', 19310456SCurtis.Dunham@arm.com action='store_true', 19410456SCurtis.Dunham@arm.com help='Disable linking against tcmalloc') 19510456SCurtis.Dunham@arm.comAddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true', 19610457Sandreas.hansson@arm.com help='Build with Undefined Behavior Sanitizer if available') 19710457Sandreas.hansson@arm.com 19811342Sandreas.hansson@arm.comtermcap = get_termcap(GetOption('use_colors')) 19911342Sandreas.hansson@arm.com 2008120Sgblack@eecs.umich.edu######################################################################## 2018947Sandreas.hansson@arm.com# 2027816Ssteve.reinhardt@amd.com# Set up the main build environment. 2035871Snate@binkert.org# 2045871Snate@binkert.org######################################################################## 2056121Snate@binkert.org 2065871Snate@binkert.org# export TERM so that clang reports errors in color 2075871Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 2089926Sstan.czerniawski@arm.com 'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PROTOC', 2099926Sstan.czerniawski@arm.com 'PYTHONPATH', 'RANLIB', 'SWIG', 'TERM' ]) 2109119Sandreas.hansson@arm.com 21110068Sandreas.hansson@arm.comuse_prefixes = [ 21210068Sandreas.hansson@arm.com "M5", # M5 configuration (e.g., path to kernels) 213955SN/A "DISTCC_", # distcc (distributed compiler wrapper) configuration 2149416SAndreas.Sandberg@ARM.com "CCACHE_", # ccache (caching compiler wrapper) configuration 21511342Sandreas.hansson@arm.com "CCC_", # clang static analyzer configuration 21611212Sjoseph.gross@amd.com ] 21711212Sjoseph.gross@amd.com 21811212Sjoseph.gross@amd.comuse_env = {} 21911212Sjoseph.gross@amd.comfor key,val in sorted(os.environ.iteritems()): 22011212Sjoseph.gross@amd.com if key in use_vars or \ 2219416SAndreas.Sandberg@ARM.com any([key.startswith(prefix) for prefix in use_prefixes]): 2229416SAndreas.Sandberg@ARM.com use_env[key] = val 2235871Snate@binkert.org 22410584Sandreas.hansson@arm.com# Tell scons to avoid implicit command dependencies to avoid issues 2259416SAndreas.Sandberg@ARM.com# with the param wrappes being compiled twice (see 2269416SAndreas.Sandberg@ARM.com# http://scons.tigris.org/issues/show_bug.cgi?id=2811) 2275871Snate@binkert.orgmain = Environment(ENV=use_env, IMPLICIT_COMMAND_DEPENDENCIES=0) 228955SN/Amain.Decider('MD5-timestamp') 22910671Sandreas.hansson@arm.commain.root = Dir(".") # The current directory (where this file lives). 23010671Sandreas.hansson@arm.commain.srcdir = Dir("src") # The source directory 23110671Sandreas.hansson@arm.com 23210671Sandreas.hansson@arm.commain_dict_keys = main.Dictionary().keys() 2338881Smarc.orr@gmail.com 2346121Snate@binkert.org# Check that we have a C/C++ compiler 2356121Snate@binkert.orgif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 2361533SN/A print "No C++ compiler installed (package g++ on Ubuntu and RedHat)" 2379239Sandreas.hansson@arm.com Exit(1) 2389239Sandreas.hansson@arm.com 2399239Sandreas.hansson@arm.com# Check that swig is present 2409239Sandreas.hansson@arm.comif not 'SWIG' in main_dict_keys: 2419239Sandreas.hansson@arm.com print "swig is not installed (package swig on Ubuntu and RedHat)" 2429239Sandreas.hansson@arm.com Exit(1) 2439239Sandreas.hansson@arm.com 2449239Sandreas.hansson@arm.com# add useful python code PYTHONPATH so it can be used by subprocesses 2459239Sandreas.hansson@arm.com# as well 2469239Sandreas.hansson@arm.commain.AppendENVPath('PYTHONPATH', extra_python_paths) 2479239Sandreas.hansson@arm.com 2489239Sandreas.hansson@arm.com######################################################################## 2496655Snate@binkert.org# 2506655Snate@binkert.org# Mercurial Stuff. 2516655Snate@binkert.org# 2526655Snate@binkert.org# If the gem5 directory is a mercurial repository, we should do some 2535871Snate@binkert.org# extra things. 2545871Snate@binkert.org# 2555863Snate@binkert.org######################################################################## 2565871Snate@binkert.org 2578878Ssteve.reinhardt@amd.comhgdir = main.root.Dir(".hg") 2585871Snate@binkert.org 2595871Snate@binkert.orgmercurial_style_message = """ 2605871Snate@binkert.orgYou're missing the gem5 style hook, which automatically checks your code 2615863Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands. This 2626121Snate@binkert.orgscript will now install the hook in your .hg/hgrc file. 26311408Sandreas.sandberg@arm.comPress enter to continue, or ctrl-c to abort: """ 2645863Snate@binkert.org 26511408Sandreas.sandberg@arm.commercurial_style_hook = """ 26611408Sandreas.sandberg@arm.com# The following lines were automatically added by gem5/SConstruct 2678336Ssteve.reinhardt@amd.com# to provide the gem5 style-checking hooks 2688336Ssteve.reinhardt@amd.com[extensions] 26911408Sandreas.sandberg@arm.comstyle = %s/util/style.py 2708336Ssteve.reinhardt@amd.com 2714678Snate@binkert.org[hooks] 27211408Sandreas.sandberg@arm.compretxncommit.style = python:style.check_style 27311408Sandreas.sandberg@arm.compre-qrefresh.style = python:style.check_style 27411408Sandreas.sandberg@arm.com# End of SConstruct additions 27511401Sandreas.sandberg@arm.com 27611401Sandreas.sandberg@arm.com""" % (main.root.abspath) 27711401Sandreas.sandberg@arm.com 27811401Sandreas.sandberg@arm.commercurial_lib_not_found = """ 27911401Sandreas.sandberg@arm.comMercurial libraries cannot be found, ignoring style hook. If 28011401Sandreas.sandberg@arm.comyou are a gem5 developer, please fix this and run the style 2818336Ssteve.reinhardt@amd.comhook. It is important. 2828336Ssteve.reinhardt@amd.com""" 2838336Ssteve.reinhardt@amd.com 2844678Snate@binkert.org# Check for style hook and prompt for installation if it's not there. 28511401Sandreas.sandberg@arm.com# Skip this if --ignore-style was specified, there's no .hg dir to 2864678Snate@binkert.org# install a hook in, or there's no interactive terminal to prompt. 2874678Snate@binkert.orgif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 28811401Sandreas.sandberg@arm.com style_hook = True 28911401Sandreas.sandberg@arm.com try: 2908336Ssteve.reinhardt@amd.com from mercurial import ui 2914678Snate@binkert.org ui = ui.ui() 2928336Ssteve.reinhardt@amd.com ui.readconfig(hgdir.File('hgrc').abspath) 2938336Ssteve.reinhardt@amd.com style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2948336Ssteve.reinhardt@amd.com ui.config('hooks', 'pre-qrefresh.style', None) 2958336Ssteve.reinhardt@amd.com except ImportError: 2968336Ssteve.reinhardt@amd.com print mercurial_lib_not_found 2978336Ssteve.reinhardt@amd.com 2985871Snate@binkert.org if not style_hook: 2995871Snate@binkert.org print mercurial_style_message, 3008336Ssteve.reinhardt@amd.com # continue unless user does ctrl-c/ctrl-d etc. 30111408Sandreas.sandberg@arm.com try: 30211408Sandreas.sandberg@arm.com raw_input() 30311408Sandreas.sandberg@arm.com except: 30411408Sandreas.sandberg@arm.com print "Input exception, exiting scons.\n" 30511408Sandreas.sandberg@arm.com sys.exit(1) 30611408Sandreas.sandberg@arm.com hgrc_path = '%s/.hg/hgrc' % main.root.abspath 30711408Sandreas.sandberg@arm.com print "Adding style hook to", hgrc_path, "\n" 3088336Ssteve.reinhardt@amd.com try: 30911401Sandreas.sandberg@arm.com hgrc = open(hgrc_path, 'a') 31011401Sandreas.sandberg@arm.com hgrc.write(mercurial_style_hook) 31111401Sandreas.sandberg@arm.com hgrc.close() 3125871Snate@binkert.org except: 3138336Ssteve.reinhardt@amd.com print "Error updating", hgrc_path 3148336Ssteve.reinhardt@amd.com sys.exit(1) 31511401Sandreas.sandberg@arm.com 31611401Sandreas.sandberg@arm.com 31711401Sandreas.sandberg@arm.com################################################### 31811401Sandreas.sandberg@arm.com# 31911401Sandreas.sandberg@arm.com# Figure out which configurations to set up based on the path(s) of 3204678Snate@binkert.org# the target(s). 3215871Snate@binkert.org# 3224678Snate@binkert.org################################################### 32311401Sandreas.sandberg@arm.com 32411401Sandreas.sandberg@arm.com# Find default configuration & binary. 32511401Sandreas.sandberg@arm.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 32611401Sandreas.sandberg@arm.com 32711401Sandreas.sandberg@arm.com# helper function: find last occurrence of element in list 32811401Sandreas.sandberg@arm.comdef rfind(l, elt, offs = -1): 32911401Sandreas.sandberg@arm.com for i in range(len(l)+offs, 0, -1): 33011401Sandreas.sandberg@arm.com if l[i] == elt: 33111401Sandreas.sandberg@arm.com return i 33211401Sandreas.sandberg@arm.com raise ValueError, "element not found" 33311401Sandreas.sandberg@arm.com 33411401Sandreas.sandberg@arm.com# Take a list of paths (or SCons Nodes) and return a list with all 33511401Sandreas.sandberg@arm.com# paths made absolute and ~-expanded. Paths will be interpreted 33611401Sandreas.sandberg@arm.com# relative to the launch directory unless a different root is provided 33711401Sandreas.sandberg@arm.comdef makePathListAbsolute(path_list, root=GetLaunchDir()): 33811401Sandreas.sandberg@arm.com return [abspath(joinpath(root, expanduser(str(p)))) 33911401Sandreas.sandberg@arm.com for p in path_list] 34011401Sandreas.sandberg@arm.com 34111401Sandreas.sandberg@arm.com# Each target must have 'build' in the interior of the path; the 34211401Sandreas.sandberg@arm.com# directory below this will determine the build parameters. For 34311401Sandreas.sandberg@arm.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 34411401Sandreas.sandberg@arm.com# recognize that ALPHA_SE specifies the configuration because it 34511401Sandreas.sandberg@arm.com# follow 'build' in the build path. 34611401Sandreas.sandberg@arm.com 34711401Sandreas.sandberg@arm.com# The funky assignment to "[:]" is needed to replace the list contents 34811401Sandreas.sandberg@arm.com# in place rather than reassign the symbol to a new list, which 34911401Sandreas.sandberg@arm.com# doesn't work (obviously!). 35011401Sandreas.sandberg@arm.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 35111401Sandreas.sandberg@arm.com 35211401Sandreas.sandberg@arm.com# Generate a list of the unique build roots and configs that the 35311401Sandreas.sandberg@arm.com# collected targets reference. 35411401Sandreas.sandberg@arm.comvariant_paths = [] 3558336Ssteve.reinhardt@amd.combuild_root = None 3568336Ssteve.reinhardt@amd.comfor t in BUILD_TARGETS: 3578336Ssteve.reinhardt@amd.com path_dirs = t.split('/') 3588336Ssteve.reinhardt@amd.com try: 3598336Ssteve.reinhardt@amd.com build_top = rfind(path_dirs, 'build', -2) 3608336Ssteve.reinhardt@amd.com except: 3618336Ssteve.reinhardt@amd.com print "Error: no non-leaf 'build' dir found on target path", t 3628336Ssteve.reinhardt@amd.com Exit(1) 3638336Ssteve.reinhardt@amd.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3648336Ssteve.reinhardt@amd.com if not build_root: 36511401Sandreas.sandberg@arm.com build_root = this_build_root 36611401Sandreas.sandberg@arm.com else: 3678336Ssteve.reinhardt@amd.com if this_build_root != build_root: 3688336Ssteve.reinhardt@amd.com print "Error: build targets not under same build root\n"\ 3698336Ssteve.reinhardt@amd.com " %s\n %s" % (build_root, this_build_root) 3705871Snate@binkert.org Exit(1) 37111408Sandreas.sandberg@arm.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 37211408Sandreas.sandberg@arm.com if variant_path not in variant_paths: 37311408Sandreas.sandberg@arm.com variant_paths.append(variant_path) 37411408Sandreas.sandberg@arm.com 37511408Sandreas.sandberg@arm.com# Make sure build_root exists (might not if this is the first build there) 37611408Sandreas.sandberg@arm.comif not isdir(build_root): 37711408Sandreas.sandberg@arm.com mkdir(build_root) 37811408Sandreas.sandberg@arm.commain['BUILDROOT'] = build_root 37911408Sandreas.sandberg@arm.com 38011408Sandreas.sandberg@arm.comExport('main') 38111408Sandreas.sandberg@arm.com 38211408Sandreas.sandberg@arm.commain.SConsignFile(joinpath(build_root, "sconsign")) 38311408Sandreas.sandberg@arm.com 38411408Sandreas.sandberg@arm.com# Default duplicate option is to use hard links, but this messes up 38511408Sandreas.sandberg@arm.com# when you use emacs to edit a file in the target dir, as emacs moves 38611408Sandreas.sandberg@arm.com# file to file~ then copies to file, breaking the link. Symbolic 38711408Sandreas.sandberg@arm.com# (soft) links work better. 38811408Sandreas.sandberg@arm.commain.SetOption('duplicate', 'soft-copy') 38911408Sandreas.sandberg@arm.com 39011408Sandreas.sandberg@arm.com# 39111408Sandreas.sandberg@arm.com# Set up global sticky variables... these are common to an entire build 3926121Snate@binkert.org# tree (not specific to a particular build like ALPHA_SE) 393955SN/A# 394955SN/A 3952632Sstever@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 3962632Sstever@eecs.umich.edu 397955SN/Aglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 398955SN/A 399955SN/Aglobal_vars.AddVariables( 400955SN/A ('CC', 'C compiler', environ.get('CC', main['CC'])), 4018878Ssteve.reinhardt@amd.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 402955SN/A ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 4032632Sstever@eecs.umich.edu ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 4042632Sstever@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 4052632Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 4062632Sstever@eecs.umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 4072632Sstever@eecs.umich.edu ('EXTRAS', 'Add extra directories to the compilation', '') 4082632Sstever@eecs.umich.edu ) 4092632Sstever@eecs.umich.edu 4108268Ssteve.reinhardt@amd.com# Update main environment with values from ARGUMENTS & global_vars_file 4118268Ssteve.reinhardt@amd.comglobal_vars.Update(main) 4128268Ssteve.reinhardt@amd.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 4138268Ssteve.reinhardt@amd.com 4148268Ssteve.reinhardt@amd.com# Save sticky variable settings back to current variables file 4158268Ssteve.reinhardt@amd.comglobal_vars.Save(global_vars_file, main) 4168268Ssteve.reinhardt@amd.com 4172632Sstever@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 4182632Sstever@eecs.umich.edu# look for sources etc. This list is exported as extras_dir_list. 4192632Sstever@eecs.umich.edubase_dir = main.srcdir.abspath 4202632Sstever@eecs.umich.eduif main['EXTRAS']: 4218268Ssteve.reinhardt@amd.com extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 4222632Sstever@eecs.umich.eduelse: 4238268Ssteve.reinhardt@amd.com extras_dir_list = [] 4248268Ssteve.reinhardt@amd.com 4258268Ssteve.reinhardt@amd.comExport('base_dir') 4268268Ssteve.reinhardt@amd.comExport('extras_dir_list') 4273718Sstever@eecs.umich.edu 4282634Sstever@eecs.umich.edu# the ext directory should be on the #includes path 4292634Sstever@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 4305863Snate@binkert.org 4312638Sstever@eecs.umich.edudef strip_build_path(path, env): 4328268Ssteve.reinhardt@amd.com path = str(path) 4332632Sstever@eecs.umich.edu variant_base = env['BUILDROOT'] + os.path.sep 4342632Sstever@eecs.umich.edu if path.startswith(variant_base): 4352632Sstever@eecs.umich.edu path = path[len(variant_base):] 4362632Sstever@eecs.umich.edu elif path.startswith('build/'): 4372632Sstever@eecs.umich.edu path = path[6:] 4381858SN/A return path 4393716Sstever@eecs.umich.edu 4402638Sstever@eecs.umich.edu# Generate a string of the form: 4412638Sstever@eecs.umich.edu# common/path/prefix/src1, src2 -> tgt1, tgt2 4422638Sstever@eecs.umich.edu# to print while building. 4432638Sstever@eecs.umich.educlass Transform(object): 4442638Sstever@eecs.umich.edu # all specific color settings should be here and nowhere else 4452638Sstever@eecs.umich.edu tool_color = termcap.Normal 4462638Sstever@eecs.umich.edu pfx_color = termcap.Yellow 4475863Snate@binkert.org srcs_color = termcap.Yellow + termcap.Bold 4485863Snate@binkert.org arrow_color = termcap.Blue + termcap.Bold 4495863Snate@binkert.org tgts_color = termcap.Yellow + termcap.Bold 450955SN/A 4515341Sstever@gmail.com def __init__(self, tool, max_sources=99): 4525341Sstever@gmail.com self.format = self.tool_color + (" [%8s] " % tool) \ 4535863Snate@binkert.org + self.pfx_color + "%s" \ 4547756SAli.Saidi@ARM.com + self.srcs_color + "%s" \ 4555341Sstever@gmail.com + self.arrow_color + " -> " \ 4566121Snate@binkert.org + self.tgts_color + "%s" \ 4574494Ssaidi@eecs.umich.edu + termcap.Normal 4586121Snate@binkert.org self.max_sources = max_sources 4591105SN/A 4602667Sstever@eecs.umich.edu def __call__(self, target, source, env, for_signature=None): 4612667Sstever@eecs.umich.edu # truncate source list according to max_sources param 4622667Sstever@eecs.umich.edu source = source[0:self.max_sources] 4632667Sstever@eecs.umich.edu def strip(f): 4646121Snate@binkert.org return strip_build_path(str(f), env) 4652667Sstever@eecs.umich.edu if len(source) > 0: 4665341Sstever@gmail.com srcs = map(strip, source) 4675863Snate@binkert.org else: 4685341Sstever@gmail.com srcs = [''] 4695341Sstever@gmail.com tgts = map(strip, target) 4705341Sstever@gmail.com # surprisingly, os.path.commonprefix is a dumb char-by-char string 4718120Sgblack@eecs.umich.edu # operation that has nothing to do with paths. 4725341Sstever@gmail.com com_pfx = os.path.commonprefix(srcs + tgts) 4738120Sgblack@eecs.umich.edu com_pfx_len = len(com_pfx) 4745341Sstever@gmail.com if com_pfx: 4758120Sgblack@eecs.umich.edu # do some cleanup and sanity checking on common prefix 4766121Snate@binkert.org if com_pfx[-1] == ".": 4776121Snate@binkert.org # prefix matches all but file extension: ok 4788980Ssteve.reinhardt@amd.com # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4799396Sandreas.hansson@arm.com com_pfx = com_pfx[0:-1] 4805397Ssaidi@eecs.umich.edu elif com_pfx[-1] == "/": 4815397Ssaidi@eecs.umich.edu # common prefix is directory path: OK 4827727SAli.Saidi@ARM.com pass 4838268Ssteve.reinhardt@amd.com else: 4846168Snate@binkert.org src0_len = len(srcs[0]) 4855341Sstever@gmail.com tgt0_len = len(tgts[0]) 4868120Sgblack@eecs.umich.edu if src0_len == com_pfx_len: 4878120Sgblack@eecs.umich.edu # source is a substring of target, OK 4888120Sgblack@eecs.umich.edu pass 4896814Sgblack@eecs.umich.edu elif tgt0_len == com_pfx_len: 4905863Snate@binkert.org # target is a substring of source, need to back up to 4918120Sgblack@eecs.umich.edu # avoid empty string on RHS of arrow 4925341Sstever@gmail.com sep_idx = com_pfx.rfind(".") 4935863Snate@binkert.org if sep_idx != -1: 4948268Ssteve.reinhardt@amd.com com_pfx = com_pfx[0:sep_idx] 4956121Snate@binkert.org else: 4966121Snate@binkert.org com_pfx = '' 4978268Ssteve.reinhardt@amd.com elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4985742Snate@binkert.org # still splitting at file extension: ok 4995742Snate@binkert.org pass 5005341Sstever@gmail.com else: 5015742Snate@binkert.org # probably a fluke; ignore it 5025742Snate@binkert.org com_pfx = '' 5035341Sstever@gmail.com # recalculate length in case com_pfx was modified 5046017Snate@binkert.org com_pfx_len = len(com_pfx) 5056121Snate@binkert.org def fmt(files): 5066017Snate@binkert.org f = map(lambda s: s[com_pfx_len:], files) 5077816Ssteve.reinhardt@amd.com return ', '.join(f) 5087756SAli.Saidi@ARM.com return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 5097756SAli.Saidi@ARM.com 5107756SAli.Saidi@ARM.comExport('Transform') 5117756SAli.Saidi@ARM.com 5127756SAli.Saidi@ARM.com# enable the regression script to use the termcap 5137756SAli.Saidi@ARM.commain['TERMCAP'] = termcap 5147756SAli.Saidi@ARM.com 5157756SAli.Saidi@ARM.comif GetOption('verbose'): 5167816Ssteve.reinhardt@amd.com def MakeAction(action, string, *args, **kwargs): 5177816Ssteve.reinhardt@amd.com return Action(action, *args, **kwargs) 5187816Ssteve.reinhardt@amd.comelse: 5197816Ssteve.reinhardt@amd.com MakeAction = Action 5207816Ssteve.reinhardt@amd.com main['CCCOMSTR'] = Transform("CC") 5217816Ssteve.reinhardt@amd.com main['CXXCOMSTR'] = Transform("CXX") 5227816Ssteve.reinhardt@amd.com main['ASCOMSTR'] = Transform("AS") 5237816Ssteve.reinhardt@amd.com main['SWIGCOMSTR'] = Transform("SWIG") 5247816Ssteve.reinhardt@amd.com main['ARCOMSTR'] = Transform("AR", 0) 5257816Ssteve.reinhardt@amd.com main['LINKCOMSTR'] = Transform("LINK", 0) 5267756SAli.Saidi@ARM.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 5277816Ssteve.reinhardt@amd.com main['M4COMSTR'] = Transform("M4") 5287816Ssteve.reinhardt@amd.com main['SHCCCOMSTR'] = Transform("SHCC") 5297816Ssteve.reinhardt@amd.com main['SHCXXCOMSTR'] = Transform("SHCXX") 5307816Ssteve.reinhardt@amd.comExport('MakeAction') 5317816Ssteve.reinhardt@amd.com 5327816Ssteve.reinhardt@amd.com# Initialize the Link-Time Optimization (LTO) flags 5337816Ssteve.reinhardt@amd.commain['LTO_CCFLAGS'] = [] 5347816Ssteve.reinhardt@amd.commain['LTO_LDFLAGS'] = [] 5357816Ssteve.reinhardt@amd.com 5367816Ssteve.reinhardt@amd.com# According to the readme, tcmalloc works best if the compiler doesn't 5377816Ssteve.reinhardt@amd.com# assume that we're using the builtin malloc and friends. These flags 5387816Ssteve.reinhardt@amd.com# are compiler-specific, so we need to set them after we detect which 5397816Ssteve.reinhardt@amd.com# compiler we're using. 5407816Ssteve.reinhardt@amd.commain['TCMALLOC_CCFLAGS'] = [] 5417816Ssteve.reinhardt@amd.com 5427816Ssteve.reinhardt@amd.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 5437816Ssteve.reinhardt@amd.comCXX_V = readCommand([main['CXX'],'-V'], exception=False) 5447816Ssteve.reinhardt@amd.com 5457816Ssteve.reinhardt@amd.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 5467816Ssteve.reinhardt@amd.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 5477816Ssteve.reinhardt@amd.comif main['GCC'] + main['CLANG'] > 1: 5487816Ssteve.reinhardt@amd.com print 'Error: How can we have two at the same time?' 5497816Ssteve.reinhardt@amd.com Exit(1) 5507816Ssteve.reinhardt@amd.com 5517816Ssteve.reinhardt@amd.com# Set up default C++ compiler flags 5527816Ssteve.reinhardt@amd.comif main['GCC'] or main['CLANG']: 5537816Ssteve.reinhardt@amd.com # As gcc and clang share many flags, do the common parts here 5547816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-pipe']) 5557816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 5567816Ssteve.reinhardt@amd.com # Enable -Wall and then disable the few warnings that we 5577816Ssteve.reinhardt@amd.com # consistently violate 5587816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5597816Ssteve.reinhardt@amd.com # We always compile using C++11, but only gcc >= 4.7 and clang 3.1 5607816Ssteve.reinhardt@amd.com # actually use that name, so we stick with c++0x 5617816Ssteve.reinhardt@amd.com main.Append(CXXFLAGS=['-std=c++0x']) 5627816Ssteve.reinhardt@amd.com # Add selected sanity checks from -Wextra 5637816Ssteve.reinhardt@amd.com main.Append(CXXFLAGS=['-Wmissing-field-initializers', 5647816Ssteve.reinhardt@amd.com '-Woverloaded-virtual']) 5657816Ssteve.reinhardt@amd.comelse: 5667816Ssteve.reinhardt@amd.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 5677816Ssteve.reinhardt@amd.com print "Don't know what compiler options to use for your compiler." 5687816Ssteve.reinhardt@amd.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 5697816Ssteve.reinhardt@amd.com print termcap.Yellow + ' version:' + termcap.Normal, 5707816Ssteve.reinhardt@amd.com if not CXX_version: 5717816Ssteve.reinhardt@amd.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 5727816Ssteve.reinhardt@amd.com termcap.Normal 5737816Ssteve.reinhardt@amd.com else: 5747816Ssteve.reinhardt@amd.com print CXX_version.replace('\n', '<nl>') 5757816Ssteve.reinhardt@amd.com print " If you're trying to use a compiler other than GCC" 5767816Ssteve.reinhardt@amd.com print " or clang, there appears to be something wrong with your" 5777816Ssteve.reinhardt@amd.com print " environment." 5787816Ssteve.reinhardt@amd.com print " " 5797816Ssteve.reinhardt@amd.com print " If you are trying to use a compiler other than those listed" 5807816Ssteve.reinhardt@amd.com print " above you will need to ease fix SConstruct and " 5817816Ssteve.reinhardt@amd.com print " src/SConscript to support that compiler." 5827816Ssteve.reinhardt@amd.com Exit(1) 5837816Ssteve.reinhardt@amd.com 5847816Ssteve.reinhardt@amd.comif main['GCC']: 5857816Ssteve.reinhardt@amd.com # Check for a supported version of gcc. >= 4.6 is chosen for its 5867816Ssteve.reinhardt@amd.com # level of c++11 support. See 5877816Ssteve.reinhardt@amd.com # http://gcc.gnu.org/projects/cxx0x.html for details. 4.6 is also 5888947Sandreas.hansson@arm.com # the first version with proper LTO support. 5898947Sandreas.hansson@arm.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5907756SAli.Saidi@ARM.com if compareVersions(gcc_version, "4.6") < 0: 5918120Sgblack@eecs.umich.edu print 'Error: gcc version 4.6 or newer required.' 5927756SAli.Saidi@ARM.com print ' Installed version:', gcc_version 5937756SAli.Saidi@ARM.com Exit(1) 5947756SAli.Saidi@ARM.com 5957756SAli.Saidi@ARM.com main['GCC_VERSION'] = gcc_version 5967816Ssteve.reinhardt@amd.com 5977816Ssteve.reinhardt@amd.com # gcc from version 4.8 and above generates "rep; ret" instructions 5987816Ssteve.reinhardt@amd.com # to avoid performance penalties on certain AMD chips. Older 5997816Ssteve.reinhardt@amd.com # assemblers detect this as an error, "Error: expecting string 6007816Ssteve.reinhardt@amd.com # instruction after `rep'" 6017816Ssteve.reinhardt@amd.com if compareVersions(gcc_version, "4.8") > 0: 6027816Ssteve.reinhardt@amd.com as_version_raw = readCommand([main['AS'], '-v', '/dev/null'], 6037816Ssteve.reinhardt@amd.com exception=False).split() 6047816Ssteve.reinhardt@amd.com 6057816Ssteve.reinhardt@amd.com # version strings may contain extra distro-specific 6067756SAli.Saidi@ARM.com # qualifiers, so play it safe and keep only what comes before 6077756SAli.Saidi@ARM.com # the first hyphen 6089227Sandreas.hansson@arm.com as_version = as_version_raw[-1].split('-')[0] if as_version_raw \ 6099227Sandreas.hansson@arm.com else None 6109227Sandreas.hansson@arm.com 6119227Sandreas.hansson@arm.com if not as_version or compareVersions(as_version, "2.23") < 0: 6129590Sandreas@sandberg.pp.se print termcap.Yellow + termcap.Bold + \ 6139590Sandreas@sandberg.pp.se 'Warning: This combination of gcc and binutils have' + \ 6149590Sandreas@sandberg.pp.se ' known incompatibilities.\n' + \ 6159590Sandreas@sandberg.pp.se ' If you encounter build problems, please update ' + \ 6169590Sandreas@sandberg.pp.se 'binutils to 2.23.' + \ 6179590Sandreas@sandberg.pp.se termcap.Normal 6186654Snate@binkert.org 6196654Snate@binkert.org # Make sure we warn if the user has requested to compile with the 6205871Snate@binkert.org # Undefined Benahvior Sanitizer and this version of gcc does not 6216121Snate@binkert.org # support it. 6228946Sandreas.hansson@arm.com if GetOption('with_ubsan') and \ 6239419Sandreas.hansson@arm.com compareVersions(gcc_version, '4.9') < 0: 6243940Ssaidi@eecs.umich.edu print termcap.Yellow + termcap.Bold + \ 6253918Ssaidi@eecs.umich.edu 'Warning: UBSan is only supported using gcc 4.9 and later.' + \ 6263918Ssaidi@eecs.umich.edu termcap.Normal 6271858SN/A 6289556Sandreas.hansson@arm.com # Add the appropriate Link-Time Optimization (LTO) flags 6299556Sandreas.hansson@arm.com # unless LTO is explicitly turned off. Note that these flags 6309556Sandreas.hansson@arm.com # are only used by the fast target. 6319556Sandreas.hansson@arm.com if not GetOption('no_lto'): 63211294Sandreas.hansson@arm.com # Pass the LTO flag when compiling to produce GIMPLE 63311294Sandreas.hansson@arm.com # output, we merely create the flags here and only append 63411294Sandreas.hansson@arm.com # them later 63511294Sandreas.hansson@arm.com main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 63610878Sandreas.hansson@arm.com 63710878Sandreas.hansson@arm.com # Use the same amount of jobs for LTO as we are running 6389556Sandreas.hansson@arm.com # scons with 6399556Sandreas.hansson@arm.com main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 6409556Sandreas.hansson@arm.com 6419556Sandreas.hansson@arm.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 6429556Sandreas.hansson@arm.com '-fno-builtin-realloc', '-fno-builtin-free']) 6439556Sandreas.hansson@arm.com 6449556Sandreas.hansson@arm.comelif main['CLANG']: 6459556Sandreas.hansson@arm.com # Check for a supported version of clang, >= 3.0 is needed to 6469556Sandreas.hansson@arm.com # support similar features as gcc 4.6. See 6479556Sandreas.hansson@arm.com # http://clang.llvm.org/cxx_status.html for details 6489556Sandreas.hansson@arm.com clang_version_re = re.compile(".* version (\d+\.\d+)") 6499556Sandreas.hansson@arm.com clang_version_match = clang_version_re.search(CXX_version) 6509556Sandreas.hansson@arm.com if (clang_version_match): 6519556Sandreas.hansson@arm.com clang_version = clang_version_match.groups()[0] 6529556Sandreas.hansson@arm.com if compareVersions(clang_version, "3.0") < 0: 6539556Sandreas.hansson@arm.com print 'Error: clang version 3.0 or newer required.' 6549556Sandreas.hansson@arm.com print ' Installed version:', clang_version 6559556Sandreas.hansson@arm.com Exit(1) 6569556Sandreas.hansson@arm.com else: 6576121Snate@binkert.org print 'Error: Unable to determine clang version.' 65810878Sandreas.hansson@arm.com Exit(1) 65910238Sandreas.hansson@arm.com 66010878Sandreas.hansson@arm.com # clang has a few additional warnings that we disable, 6619420Sandreas.hansson@arm.com # tautological comparisons are allowed due to unsigned integers 66210878Sandreas.hansson@arm.com # being compared to constants that happen to be 0, and extraneous 66310878Sandreas.hansson@arm.com # parantheses are allowed due to Ruby's printing of the AST, 6649420Sandreas.hansson@arm.com # finally self assignments are allowed as the generated CPU code 6659420Sandreas.hansson@arm.com # is relying on this 6669420Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-tautological-compare', 6679420Sandreas.hansson@arm.com '-Wno-parentheses', 6689420Sandreas.hansson@arm.com '-Wno-self-assign', 66910264Sandreas.hansson@arm.com # Some versions of libstdc++ (4.8?) seem to 67010264Sandreas.hansson@arm.com # use struct hash and class hash 67110264Sandreas.hansson@arm.com # interchangeably. 67210264Sandreas.hansson@arm.com '-Wno-mismatched-tags', 67310264Sandreas.hansson@arm.com ]) 67410866Sandreas.hansson@arm.com 67510866Sandreas.hansson@arm.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 67610264Sandreas.hansson@arm.com 67710866Sandreas.hansson@arm.com # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 67810866Sandreas.hansson@arm.com # opposed to libstdc++, as the later is dated. 67910866Sandreas.hansson@arm.com if sys.platform == "darwin": 68010866Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-stdlib=libc++']) 68110866Sandreas.hansson@arm.com main.Append(LIBS=['c++']) 68210866Sandreas.hansson@arm.com 68310866Sandreas.hansson@arm.comelse: 68410264Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 68510264Sandreas.hansson@arm.com print "Don't know what compiler options to use for your compiler." 68610264Sandreas.hansson@arm.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 68710264Sandreas.hansson@arm.com print termcap.Yellow + ' version:' + termcap.Normal, 68810264Sandreas.hansson@arm.com if not CXX_version: 68910264Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 69010264Sandreas.hansson@arm.com termcap.Normal 69110457Sandreas.hansson@arm.com else: 69210457Sandreas.hansson@arm.com print CXX_version.replace('\n', '<nl>') 69310457Sandreas.hansson@arm.com print " If you're trying to use a compiler other than GCC" 69410457Sandreas.hansson@arm.com print " or clang, there appears to be something wrong with your" 69510457Sandreas.hansson@arm.com print " environment." 69610457Sandreas.hansson@arm.com print " " 69710457Sandreas.hansson@arm.com print " If you are trying to use a compiler other than those listed" 69810457Sandreas.hansson@arm.com print " above you will need to ease fix SConstruct and " 69910457Sandreas.hansson@arm.com print " src/SConscript to support that compiler." 70010238Sandreas.hansson@arm.com Exit(1) 70110238Sandreas.hansson@arm.com 70210238Sandreas.hansson@arm.com# Set up common yacc/bison flags (needed for Ruby) 70310238Sandreas.hansson@arm.commain['YACCFLAGS'] = '-d' 70410238Sandreas.hansson@arm.commain['YACCHXXFILESUFFIX'] = '.hh' 70510238Sandreas.hansson@arm.com 70610416Sandreas.hansson@arm.com# Do this after we save setting back, or else we'll tack on an 70710238Sandreas.hansson@arm.com# extra 'qdo' every time we run scons. 7089227Sandreas.hansson@arm.comif main['BATCH']: 70910238Sandreas.hansson@arm.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 71010416Sandreas.hansson@arm.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 71110416Sandreas.hansson@arm.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 7129227Sandreas.hansson@arm.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 7139590Sandreas@sandberg.pp.se main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 7149590Sandreas@sandberg.pp.se 7159590Sandreas@sandberg.pp.seif sys.platform == 'cygwin': 7168737Skoansin.tan@gmail.com # cygwin has some header file issues... 71710878Sandreas.hansson@arm.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 71810878Sandreas.hansson@arm.com 7199420Sandreas.hansson@arm.com# Check for the protobuf compiler 7208737Skoansin.tan@gmail.comprotoc_version = readCommand([main['PROTOC'], '--version'], 72110106SMitch.Hayenga@arm.com exception='').split() 7228737Skoansin.tan@gmail.com 7238737Skoansin.tan@gmail.com# First two words should be "libprotoc x.y.z" 72410878Sandreas.hansson@arm.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 72510878Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + \ 7268737Skoansin.tan@gmail.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + \ 7278737Skoansin.tan@gmail.com ' Please install protobuf-compiler for tracing support.' + \ 7288737Skoansin.tan@gmail.com termcap.Normal 7298737Skoansin.tan@gmail.com main['PROTOC'] = False 7308737Skoansin.tan@gmail.comelse: 7318737Skoansin.tan@gmail.com # Based on the availability of the compress stream wrappers, 73211294Sandreas.hansson@arm.com # require 2.1.0 7339556Sandreas.hansson@arm.com min_protoc_version = '2.1.0' 7349556Sandreas.hansson@arm.com if compareVersions(protoc_version[1], min_protoc_version) < 0: 7359556Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + \ 73611294Sandreas.hansson@arm.com 'Warning: protoc version', min_protoc_version, \ 73710278SAndreas.Sandberg@ARM.com 'or newer required.\n' + \ 73810278SAndreas.Sandberg@ARM.com ' Installed version:', protoc_version[1], \ 73910278SAndreas.Sandberg@ARM.com termcap.Normal 74010278SAndreas.Sandberg@ARM.com main['PROTOC'] = False 74110278SAndreas.Sandberg@ARM.com else: 74210278SAndreas.Sandberg@ARM.com # Attempt to determine the appropriate include path and 7439556Sandreas.hansson@arm.com # library path using pkg-config, that means we also need to 7449590Sandreas@sandberg.pp.se # check for pkg-config. Note that it is possible to use 7459590Sandreas@sandberg.pp.se # protobuf without the involvement of pkg-config. Later on we 7469420Sandreas.hansson@arm.com # check go a library config check and at that point the test 7479846Sandreas.hansson@arm.com # will fail if libprotobuf cannot be found. 7489846Sandreas.hansson@arm.com if readCommand(['pkg-config', '--version'], exception=''): 7499846Sandreas.hansson@arm.com try: 7509846Sandreas.hansson@arm.com # Attempt to establish what linking flags to add for protobuf 7518946Sandreas.hansson@arm.com # using pkg-config 7523918Ssaidi@eecs.umich.edu main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 7539068SAli.Saidi@ARM.com except: 7549068SAli.Saidi@ARM.com print termcap.Yellow + termcap.Bold + \ 7559068SAli.Saidi@ARM.com 'Warning: pkg-config could not get protobuf flags.' + \ 7569068SAli.Saidi@ARM.com termcap.Normal 7579068SAli.Saidi@ARM.com 7589068SAli.Saidi@ARM.com# Check for SWIG 7599068SAli.Saidi@ARM.comif not main.has_key('SWIG'): 7609068SAli.Saidi@ARM.com print 'Error: SWIG utility not found.' 7619068SAli.Saidi@ARM.com print ' Please install (see http://www.swig.org) and retry.' 7629419Sandreas.hansson@arm.com Exit(1) 7639068SAli.Saidi@ARM.com 7649068SAli.Saidi@ARM.com# Check for appropriate SWIG version 7659068SAli.Saidi@ARM.comswig_version = readCommand([main['SWIG'], '-version'], exception='').split() 7669068SAli.Saidi@ARM.com# First 3 words should be "SWIG Version x.y.z" 7679068SAli.Saidi@ARM.comif len(swig_version) < 3 or \ 7689068SAli.Saidi@ARM.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 7693918Ssaidi@eecs.umich.edu print 'Error determining SWIG version.' 7703918Ssaidi@eecs.umich.edu Exit(1) 7716157Snate@binkert.org 7726157Snate@binkert.orgmin_swig_version = '2.0.4' 7736157Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0: 7746157Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 7755397Ssaidi@eecs.umich.edu print ' Installed version:', swig_version[2] 7765397Ssaidi@eecs.umich.edu Exit(1) 7776121Snate@binkert.org 7786121Snate@binkert.org# Check for known incompatibilities. The standard library shipped with 7796121Snate@binkert.org# gcc >= 4.9 does not play well with swig versions prior to 3.0 7806121Snate@binkert.orgif main['GCC'] and compareVersions(gcc_version, '4.9') >= 0 and \ 7816121Snate@binkert.org compareVersions(swig_version[2], '3.0') < 0: 7826121Snate@binkert.org print termcap.Yellow + termcap.Bold + \ 7835397Ssaidi@eecs.umich.edu 'Warning: This combination of gcc and swig have' + \ 7841851SN/A ' known incompatibilities.\n' + \ 7851851SN/A ' If you encounter build problems, please update ' + \ 7867739Sgblack@eecs.umich.edu 'swig to 3.0 or later.' + \ 787955SN/A termcap.Normal 7889396Sandreas.hansson@arm.com 7899396Sandreas.hansson@arm.com# Set up SWIG flags & scanner 7909396Sandreas.hansson@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 7919396Sandreas.hansson@arm.commain.Append(SWIGFLAGS=swig_flags) 7929396Sandreas.hansson@arm.com 7939396Sandreas.hansson@arm.com# Check for 'timeout' from GNU coreutils. If present, regressions will 7949396Sandreas.hansson@arm.com# be run with a time limit. We require version 8.13 since we rely on 7959396Sandreas.hansson@arm.com# support for the '--foreground' option. 7969396Sandreas.hansson@arm.comtimeout_lines = readCommand(['timeout', '--version'], 7979396Sandreas.hansson@arm.com exception='').splitlines() 7989396Sandreas.hansson@arm.com# Get the first line and tokenize it 7999396Sandreas.hansson@arm.comtimeout_version = timeout_lines[0].split() if timeout_lines else [] 8009396Sandreas.hansson@arm.commain['TIMEOUT'] = timeout_version and \ 8019396Sandreas.hansson@arm.com compareVersions(timeout_version[-1], '8.13') >= 0 8029396Sandreas.hansson@arm.com 8039396Sandreas.hansson@arm.com# filter out all existing swig scanners, they mess up the dependency 8049477Sandreas.hansson@arm.com# stuff for some reason 8059477Sandreas.hansson@arm.comscanners = [] 8069477Sandreas.hansson@arm.comfor scanner in main['SCANNERS']: 8079477Sandreas.hansson@arm.com skeys = scanner.skeys 8089477Sandreas.hansson@arm.com if skeys == '.i': 8099477Sandreas.hansson@arm.com continue 8109477Sandreas.hansson@arm.com 8119477Sandreas.hansson@arm.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 8129477Sandreas.hansson@arm.com continue 8139477Sandreas.hansson@arm.com 8149477Sandreas.hansson@arm.com scanners.append(scanner) 8159477Sandreas.hansson@arm.com 8169477Sandreas.hansson@arm.com# add the new swig scanner that we like better 8179477Sandreas.hansson@arm.comfrom SCons.Scanner import ClassicCPP as CPPScanner 8189477Sandreas.hansson@arm.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 8199477Sandreas.hansson@arm.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 8209477Sandreas.hansson@arm.com 8219477Sandreas.hansson@arm.com# replace the scanners list that has what we want 8229477Sandreas.hansson@arm.commain['SCANNERS'] = scanners 8239477Sandreas.hansson@arm.com 8249477Sandreas.hansson@arm.com# Add a custom Check function to the Configure context so that we can 8259477Sandreas.hansson@arm.com# figure out if the compiler adds leading underscores to global 8269396Sandreas.hansson@arm.com# variables. This is needed for the autogenerated asm files that we 8273053Sstever@eecs.umich.edu# use for embedding the python code. 8286121Snate@binkert.orgdef CheckLeading(context): 8293053Sstever@eecs.umich.edu context.Message("Checking for leading underscore in global variables...") 8303053Sstever@eecs.umich.edu # 1) Define a global variable called x from asm so the C compiler 8313053Sstever@eecs.umich.edu # won't change the symbol at all. 8323053Sstever@eecs.umich.edu # 2) Declare that variable. 8333053Sstever@eecs.umich.edu # 3) Use the variable 8349072Sandreas.hansson@arm.com # 8353053Sstever@eecs.umich.edu # If the compiler prepends an underscore, this will successfully 8364742Sstever@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 8374742Sstever@eecs.umich.edu # was defined by the asm statement. If the compiler does not 8383053Sstever@eecs.umich.edu # prepend an underscore, this will not successfully link because 8393053Sstever@eecs.umich.edu # '_x' will have been defined by assembly, while the C portion of 8403053Sstever@eecs.umich.edu # the code will be trying to use 'x' 84110181SCurtis.Dunham@arm.com ret = context.TryLink(''' 8426654Snate@binkert.org asm(".globl _x; _x: .byte 0"); 8433053Sstever@eecs.umich.edu extern int x; 8443053Sstever@eecs.umich.edu int main() { return x; } 8453053Sstever@eecs.umich.edu ''', extension=".c") 8463053Sstever@eecs.umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 84710425Sandreas.hansson@arm.com context.Result(ret) 84810425Sandreas.hansson@arm.com return ret 84910425Sandreas.hansson@arm.com 85010425Sandreas.hansson@arm.com# Add a custom Check function to test for structure members. 85110425Sandreas.hansson@arm.comdef CheckMember(context, include, decl, member, include_quotes="<>"): 85210425Sandreas.hansson@arm.com context.Message("Checking for member %s in %s..." % 85310425Sandreas.hansson@arm.com (member, decl)) 85410425Sandreas.hansson@arm.com text = """ 85510425Sandreas.hansson@arm.com#include %(header)s 85610425Sandreas.hansson@arm.comint main(){ 85710425Sandreas.hansson@arm.com %(decl)s test; 8582667Sstever@eecs.umich.edu (void)test.%(member)s; 8594554Sbinkertn@umich.edu return 0; 8606121Snate@binkert.org}; 8612667Sstever@eecs.umich.edu""" % { "header" : include_quotes[0] + include + include_quotes[1], 86210710Sandreas.hansson@arm.com "decl" : decl, 86310710Sandreas.hansson@arm.com "member" : member, 86410710Sandreas.hansson@arm.com } 86510710Sandreas.hansson@arm.com 86610710Sandreas.hansson@arm.com ret = context.TryCompile(text, extension=".cc") 86710710Sandreas.hansson@arm.com context.Result(ret) 86810710Sandreas.hansson@arm.com return ret 86910710Sandreas.hansson@arm.com 87010710Sandreas.hansson@arm.com# Platform-specific configuration. Note again that we assume that all 87110384SCurtis.Dunham@arm.com# builds under a given build root run on the same host platform. 8724554Sbinkertn@umich.educonf = Configure(main, 8734554Sbinkertn@umich.edu conf_dir = joinpath(build_root, '.scons_config'), 8744554Sbinkertn@umich.edu log_file = joinpath(build_root, 'scons_config.log'), 8756121Snate@binkert.org custom_tests = { 8764554Sbinkertn@umich.edu 'CheckLeading' : CheckLeading, 8774554Sbinkertn@umich.edu 'CheckMember' : CheckMember, 8784554Sbinkertn@umich.edu }) 8794781Snate@binkert.org 8804554Sbinkertn@umich.edu# Check for leading underscores. Don't really need to worry either 8814554Sbinkertn@umich.edu# way so don't need to check the return code. 8822667Sstever@eecs.umich.educonf.CheckLeading() 8834554Sbinkertn@umich.edu 8844554Sbinkertn@umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 8854554Sbinkertn@umich.edutry: 8864554Sbinkertn@umich.edu import platform 8872667Sstever@eecs.umich.edu uname = platform.uname() 8884554Sbinkertn@umich.edu if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 8892667Sstever@eecs.umich.edu if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 8904554Sbinkertn@umich.edu main.Append(CCFLAGS=['-arch', 'x86_64']) 8916121Snate@binkert.org main.Append(CFLAGS=['-arch', 'x86_64']) 8922667Sstever@eecs.umich.edu main.Append(LINKFLAGS=['-arch', 'x86_64']) 8939986Sandreas@sandberg.pp.se main.Append(ASFLAGS=['-arch', 'x86_64']) 8949986Sandreas@sandberg.pp.seexcept: 8959986Sandreas@sandberg.pp.se pass 8969986Sandreas@sandberg.pp.se 8979986Sandreas@sandberg.pp.se# Recent versions of scons substitute a "Null" object for Configure() 8989986Sandreas@sandberg.pp.se# when configuration isn't necessary, e.g., if the "--help" option is 8999986Sandreas@sandberg.pp.se# present. Unfortuantely this Null object always returns false, 9009986Sandreas@sandberg.pp.se# breaking all our configuration checks. We replace it with our own 9019986Sandreas@sandberg.pp.se# more optimistic null object that returns True instead. 9029986Sandreas@sandberg.pp.seif not conf: 9039986Sandreas@sandberg.pp.se def NullCheck(*args, **kwargs): 9049986Sandreas@sandberg.pp.se return True 9059986Sandreas@sandberg.pp.se 9069986Sandreas@sandberg.pp.se class NullConf: 9079986Sandreas@sandberg.pp.se def __init__(self, env): 9089986Sandreas@sandberg.pp.se self.env = env 9099986Sandreas@sandberg.pp.se def Finish(self): 9109986Sandreas@sandberg.pp.se return self.env 9119986Sandreas@sandberg.pp.se def __getattr__(self, mname): 9129986Sandreas@sandberg.pp.se return NullCheck 9132638Sstever@eecs.umich.edu 9142638Sstever@eecs.umich.edu conf = NullConf(main) 9156121Snate@binkert.org 9163716Sstever@eecs.umich.edu# Cache build files in the supplied directory. 9175522Snate@binkert.orgif main['M5_BUILD_CACHE']: 9189986Sandreas@sandberg.pp.se print 'Using build cache located at', main['M5_BUILD_CACHE'] 9199986Sandreas@sandberg.pp.se CacheDir(main['M5_BUILD_CACHE']) 9209986Sandreas@sandberg.pp.se 9215522Snate@binkert.orgif not GetOption('without_python'): 9225227Ssaidi@eecs.umich.edu # Find Python include and library directories for embedding the 9235227Ssaidi@eecs.umich.edu # interpreter. We rely on python-config to resolve the appropriate 9245227Ssaidi@eecs.umich.edu # includes and linker flags. ParseConfig does not seem to understand 9255227Ssaidi@eecs.umich.edu # the more exotic linker flags such as -Xlinker and -export-dynamic so 9266654Snate@binkert.org # we add them explicitly below. If you want to link in an alternate 9276654Snate@binkert.org # version of python, see above for instructions on how to invoke 9287769SAli.Saidi@ARM.com # scons with the appropriate PATH set. 9297769SAli.Saidi@ARM.com # 9307769SAli.Saidi@ARM.com # First we check if python2-config exists, else we use python-config 9317769SAli.Saidi@ARM.com python_config = readCommand(['which', 'python2-config'], 9325227Ssaidi@eecs.umich.edu exception='').strip() 9335227Ssaidi@eecs.umich.edu if not os.path.exists(python_config): 9345227Ssaidi@eecs.umich.edu python_config = readCommand(['which', 'python-config'], 9355204Sstever@gmail.com exception='').strip() 9365204Sstever@gmail.com py_includes = readCommand([python_config, '--includes'], 9375204Sstever@gmail.com exception='').split() 9385204Sstever@gmail.com # Strip the -I from the include folders before adding them to the 9395204Sstever@gmail.com # CPPPATH 9405204Sstever@gmail.com main.Append(CPPPATH=map(lambda inc: inc[2:], py_includes)) 9415204Sstever@gmail.com 9425204Sstever@gmail.com # Read the linker flags and split them into libraries and other link 9435204Sstever@gmail.com # flags. The libraries are added later through the call the CheckLib. 9445204Sstever@gmail.com py_ld_flags = readCommand([python_config, '--ldflags'], 9455204Sstever@gmail.com exception='').split() 9465204Sstever@gmail.com py_libs = [] 9475204Sstever@gmail.com for lib in py_ld_flags: 9485204Sstever@gmail.com if not lib.startswith('-l'): 9495204Sstever@gmail.com main.Append(LINKFLAGS=[lib]) 9505204Sstever@gmail.com else: 9515204Sstever@gmail.com lib = lib[2:] 9526121Snate@binkert.org if lib not in py_libs: 9535204Sstever@gmail.com py_libs.append(lib) 9547727SAli.Saidi@ARM.com 9557727SAli.Saidi@ARM.com # verify that this stuff works 9567727SAli.Saidi@ARM.com if not conf.CheckHeader('Python.h', '<>'): 9577727SAli.Saidi@ARM.com print "Error: can't find Python.h header in", py_includes 9587727SAli.Saidi@ARM.com print "Install Python headers (package python-dev on Ubuntu and RedHat)" 95910453SAndrew.Bardsley@arm.com Exit(1) 96010453SAndrew.Bardsley@arm.com 96110453SAndrew.Bardsley@arm.com for lib in py_libs: 96210453SAndrew.Bardsley@arm.com if not conf.CheckLib(lib): 96310453SAndrew.Bardsley@arm.com print "Error: can't find library %s required by python" % lib 96410453SAndrew.Bardsley@arm.com Exit(1) 96510453SAndrew.Bardsley@arm.com 96610453SAndrew.Bardsley@arm.com# On Solaris you need to use libsocket for socket ops 96710453SAndrew.Bardsley@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 96810453SAndrew.Bardsley@arm.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 96910453SAndrew.Bardsley@arm.com print "Can't find library with socket calls (e.g. accept())" 97010160Sandreas.hansson@arm.com Exit(1) 97110453SAndrew.Bardsley@arm.com 97210453SAndrew.Bardsley@arm.com# Check for zlib. If the check passes, libz will be automatically 97310453SAndrew.Bardsley@arm.com# added to the LIBS environment variable. 97410453SAndrew.Bardsley@arm.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 97510453SAndrew.Bardsley@arm.com print 'Error: did not find needed zlib compression library '\ 97610453SAndrew.Bardsley@arm.com 'and/or zlib.h header file.' 97710453SAndrew.Bardsley@arm.com print ' Please install zlib and try again.' 97810453SAndrew.Bardsley@arm.com Exit(1) 9799812Sandreas.hansson@arm.com 98010453SAndrew.Bardsley@arm.com# If we have the protobuf compiler, also make sure we have the 98110453SAndrew.Bardsley@arm.com# development libraries. If the check passes, libprotobuf will be 98210453SAndrew.Bardsley@arm.com# automatically added to the LIBS environment variable. After 98310453SAndrew.Bardsley@arm.com# this, we can use the HAVE_PROTOBUF flag to determine if we have 98410453SAndrew.Bardsley@arm.com# got both protoc and libprotobuf available. 98510453SAndrew.Bardsley@arm.commain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 98610453SAndrew.Bardsley@arm.com conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 98710453SAndrew.Bardsley@arm.com 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 98810453SAndrew.Bardsley@arm.com 98910453SAndrew.Bardsley@arm.com# If we have the compiler but not the library, print another warning. 99010453SAndrew.Bardsley@arm.comif main['PROTOC'] and not main['HAVE_PROTOBUF']: 99110453SAndrew.Bardsley@arm.com print termcap.Yellow + termcap.Bold + \ 9927727SAli.Saidi@ARM.com 'Warning: did not find protocol buffer library and/or headers.\n' + \ 99310453SAndrew.Bardsley@arm.com ' Please install libprotobuf-dev for tracing support.' + \ 99410453SAndrew.Bardsley@arm.com termcap.Normal 99510453SAndrew.Bardsley@arm.com 99610453SAndrew.Bardsley@arm.com# Check for librt. 99710453SAndrew.Bardsley@arm.comhave_posix_clock = \ 9983118Sstever@eecs.umich.edu conf.CheckLibWithHeader(None, 'time.h', 'C', 99910453SAndrew.Bardsley@arm.com 'clock_nanosleep(0,0,NULL,NULL);') or \ 100010453SAndrew.Bardsley@arm.com conf.CheckLibWithHeader('rt', 'time.h', 'C', 100110453SAndrew.Bardsley@arm.com 'clock_nanosleep(0,0,NULL,NULL);') 100210453SAndrew.Bardsley@arm.com 10033118Sstever@eecs.umich.eduhave_posix_timers = \ 10043483Ssaidi@eecs.umich.edu conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', 10053494Ssaidi@eecs.umich.edu 'timer_create(CLOCK_MONOTONIC, NULL, NULL);') 10063494Ssaidi@eecs.umich.edu 10073483Ssaidi@eecs.umich.eduif not GetOption('without_tcmalloc'): 10083483Ssaidi@eecs.umich.edu if conf.CheckLib('tcmalloc'): 10093483Ssaidi@eecs.umich.edu main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 10103053Sstever@eecs.umich.edu elif conf.CheckLib('tcmalloc_minimal'): 10113053Sstever@eecs.umich.edu main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 10123918Ssaidi@eecs.umich.edu else: 10133053Sstever@eecs.umich.edu print termcap.Yellow + termcap.Bold + \ 10143053Sstever@eecs.umich.edu "You can get a 12% performance improvement by "\ 10153053Sstever@eecs.umich.edu "installing tcmalloc (libgoogle-perftools-dev package "\ 10163053Sstever@eecs.umich.edu "on Ubuntu or RedHat)." + termcap.Normal 10173053Sstever@eecs.umich.edu 10189396Sandreas.hansson@arm.comif not have_posix_clock: 10199396Sandreas.hansson@arm.com print "Can't find library for POSIX clocks." 10209396Sandreas.hansson@arm.com 10219396Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control) 10229396Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 10239396Sandreas.hansson@arm.comif not have_fenv: 10249396Sandreas.hansson@arm.com print "Warning: Header file <fenv.h> not found." 10259396Sandreas.hansson@arm.com print " This host has no IEEE FP rounding mode control." 10269396Sandreas.hansson@arm.com 10279477Sandreas.hansson@arm.com# Check if we should enable KVM-based hardware virtualization. The API 10289396Sandreas.hansson@arm.com# we rely on exists since version 2.6.36 of the kernel, but somehow 10299477Sandreas.hansson@arm.com# the KVM_API_VERSION does not reflect the change. We test for one of 10309477Sandreas.hansson@arm.com# the types as a fall back. 10319477Sandreas.hansson@arm.comhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 10329477Sandreas.hansson@arm.comif not have_kvm: 10339396Sandreas.hansson@arm.com print "Info: Compatible header file <linux/kvm.h> not found, " \ 10347840Snate@binkert.org "disabling KVM support." 10357865Sgblack@eecs.umich.edu 10367865Sgblack@eecs.umich.edu# x86 needs support for xsave. We test for the structure here since we 10377865Sgblack@eecs.umich.edu# won't be able to run new tests by the time we know which ISA we're 10387865Sgblack@eecs.umich.edu# targeting. 10397865Sgblack@eecs.umich.eduhave_kvm_xsave = conf.CheckTypeSize('struct kvm_xsave', 10407840Snate@binkert.org '#include <linux/kvm.h>') != 0 10419900Sandreas@sandberg.pp.se 10429900Sandreas@sandberg.pp.se# Check if the requested target ISA is compatible with the host 10439900Sandreas@sandberg.pp.sedef is_isa_kvm_compatible(isa): 10449900Sandreas@sandberg.pp.se try: 104510456SCurtis.Dunham@arm.com import platform 104610456SCurtis.Dunham@arm.com host_isa = platform.machine() 104710456SCurtis.Dunham@arm.com except: 104810456SCurtis.Dunham@arm.com print "Warning: Failed to determine host ISA." 104910456SCurtis.Dunham@arm.com return False 105010456SCurtis.Dunham@arm.com 105110456SCurtis.Dunham@arm.com if not have_posix_timers: 105210456SCurtis.Dunham@arm.com print "Warning: Can not enable KVM, host seems to lack support " \ 105310456SCurtis.Dunham@arm.com "for POSIX timers" 105410456SCurtis.Dunham@arm.com return False 10559045SAli.Saidi@ARM.com 105611235Sandreas.sandberg@arm.com if isa == "arm": 105711235Sandreas.sandberg@arm.com return host_isa in ( "armv7l", "aarch64" ) 105811235Sandreas.sandberg@arm.com elif isa == "x86": 105911235Sandreas.sandberg@arm.com if host_isa != "x86_64": 106011235Sandreas.sandberg@arm.com return False 106111235Sandreas.sandberg@arm.com 106211235Sandreas.sandberg@arm.com if not have_kvm_xsave: 106311235Sandreas.sandberg@arm.com print "KVM on x86 requires xsave support in kernel headers." 106411235Sandreas.sandberg@arm.com return False 106511235Sandreas.sandberg@arm.com 106611235Sandreas.sandberg@arm.com return True 106711235Sandreas.sandberg@arm.com else: 106811235Sandreas.sandberg@arm.com return False 106911235Sandreas.sandberg@arm.com 107011235Sandreas.sandberg@arm.com 10717840Snate@binkert.org# Check if the exclude_host attribute is available. We want this to 10727840Snate@binkert.org# get accurate instruction counts in KVM. 10737840Snate@binkert.orgmain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember( 10741858SN/A 'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host') 10751858SN/A 10761858SN/A 10771858SN/A###################################################################### 10781858SN/A# 10791858SN/A# Finish the configuration 10809903Sandreas.hansson@arm.com# 10819903Sandreas.hansson@arm.commain = conf.Finish() 10829903Sandreas.hansson@arm.com 10839903Sandreas.hansson@arm.com###################################################################### 108410841Sandreas.sandberg@arm.com# 10859651SAndreas.Sandberg@ARM.com# Collect all non-global variables 10869903Sandreas.hansson@arm.com# 10879651SAndreas.Sandberg@ARM.com 10889651SAndreas.Sandberg@ARM.com# Define the universe of supported ISAs 108910841Sandreas.sandberg@arm.comall_isa_list = [ ] 109010841Sandreas.sandberg@arm.comExport('all_isa_list') 109110841Sandreas.sandberg@arm.com 109210841Sandreas.sandberg@arm.comclass CpuModel(object): 109310841Sandreas.sandberg@arm.com '''The CpuModel class encapsulates everything the ISA parser needs to 109410841Sandreas.sandberg@arm.com know about a particular CPU model.''' 10959651SAndreas.Sandberg@ARM.com 10969651SAndreas.Sandberg@ARM.com # Dict of available CPU model objects. Accessible as CpuModel.dict. 10979651SAndreas.Sandberg@ARM.com dict = {} 10989651SAndreas.Sandberg@ARM.com 10999651SAndreas.Sandberg@ARM.com # Constructor. Automatically adds models to CpuModel.dict. 11009651SAndreas.Sandberg@ARM.com def __init__(self, name, default=False): 11019651SAndreas.Sandberg@ARM.com self.name = name # name of model 11029651SAndreas.Sandberg@ARM.com 11039651SAndreas.Sandberg@ARM.com # This cpu is enabled by default 110410841Sandreas.sandberg@arm.com self.default = default 110510841Sandreas.sandberg@arm.com 110610841Sandreas.sandberg@arm.com # Add self to dict 110710841Sandreas.sandberg@arm.com if name in CpuModel.dict: 110810841Sandreas.sandberg@arm.com raise AttributeError, "CpuModel '%s' already registered" % name 110910841Sandreas.sandberg@arm.com CpuModel.dict[name] = self 111010860Sandreas.sandberg@arm.com 111110841Sandreas.sandberg@arm.comExport('CpuModel') 111210841Sandreas.sandberg@arm.com 111310841Sandreas.sandberg@arm.com# Sticky variables get saved in the variables file so they persist from 111410841Sandreas.sandberg@arm.com# one invocation to the next (unless overridden, in which case the new 111510841Sandreas.sandberg@arm.com# value becomes sticky). 111610841Sandreas.sandberg@arm.comsticky_vars = Variables(args=ARGUMENTS) 111710841Sandreas.sandberg@arm.comExport('sticky_vars') 111810841Sandreas.sandberg@arm.com 111910841Sandreas.sandberg@arm.com# Sticky variables that should be exported 112010841Sandreas.sandberg@arm.comexport_vars = [] 112110841Sandreas.sandberg@arm.comExport('export_vars') 11229651SAndreas.Sandberg@ARM.com 11239651SAndreas.Sandberg@ARM.com# For Ruby 11249986Sandreas@sandberg.pp.seall_protocols = [] 11259986Sandreas@sandberg.pp.seExport('all_protocols') 11269986Sandreas@sandberg.pp.seprotocol_dirs = [] 11279986Sandreas@sandberg.pp.seExport('protocol_dirs') 11289986Sandreas@sandberg.pp.seslicc_includes = [] 11299986Sandreas@sandberg.pp.seExport('slicc_includes') 11305863Snate@binkert.org 11315863Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 11325863Snate@binkert.org# above variables 11335863Snate@binkert.orgif GetOption('verbose'): 11346121Snate@binkert.org print "Reading SConsopts" 11351858SN/Afor bdir in [ base_dir ] + extras_dir_list: 11365863Snate@binkert.org if not isdir(bdir): 11375863Snate@binkert.org print "Error: directory '%s' does not exist" % bdir 11385863Snate@binkert.org Exit(1) 11395863Snate@binkert.org for root, dirs, files in os.walk(bdir): 11405863Snate@binkert.org if 'SConsopts' in files: 11412139SN/A if GetOption('verbose'): 11424202Sbinkertn@umich.edu print "Reading", joinpath(root, 'SConsopts') 114311308Santhony.gutierrez@amd.com SConscript(joinpath(root, 'SConsopts')) 11444202Sbinkertn@umich.edu 114511308Santhony.gutierrez@amd.comall_isa_list.sort() 11462139SN/A 11476994Snate@binkert.orgsticky_vars.AddVariables( 11486994Snate@binkert.org EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 11496994Snate@binkert.org ListVariable('CPU_MODELS', 'CPU models', 11506994Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 11516994Snate@binkert.org sorted(CpuModel.dict.keys())), 11526994Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 11536994Snate@binkert.org False), 11546994Snate@binkert.org BoolVariable('SS_COMPATIBLE_FP', 115510319SAndreas.Sandberg@ARM.com 'Make floating-point results compatible with SimpleScalar', 11566994Snate@binkert.org False), 11576994Snate@binkert.org BoolVariable('USE_SSE2', 11586994Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 11596994Snate@binkert.org False), 11606994Snate@binkert.org BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 11616994Snate@binkert.org BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 11626994Snate@binkert.org BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 11636994Snate@binkert.org BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm), 11646994Snate@binkert.org EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 11656994Snate@binkert.org all_protocols), 11666994Snate@binkert.org ) 11672155SN/A 11685863Snate@binkert.org# These variables get exported to #defines in config/*.hh (see src/SConscript). 11691869SN/Aexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'CP_ANNOTATE', 11701869SN/A 'USE_POSIX_CLOCK', 'USE_KVM', 'PROTOCOL', 'HAVE_PROTOBUF', 11715863Snate@binkert.org 'HAVE_PERF_ATTR_EXCLUDE_HOST'] 11725863Snate@binkert.org 11734202Sbinkertn@umich.edu################################################### 11746108Snate@binkert.org# 11756108Snate@binkert.org# Define a SCons builder for configuration flag headers. 11766108Snate@binkert.org# 11776108Snate@binkert.org################################################### 11789219Spower.jg@gmail.com 11799219Spower.jg@gmail.com# This function generates a config header file that #defines the 11809219Spower.jg@gmail.com# variable symbol to the current variable setting (0 or 1). The source 11819219Spower.jg@gmail.com# operands are the name of the variable and a Value node containing the 11829219Spower.jg@gmail.com# value of the variable. 11839219Spower.jg@gmail.comdef build_config_file(target, source, env): 11849219Spower.jg@gmail.com (variable, value) = [s.get_contents() for s in source] 11859219Spower.jg@gmail.com f = file(str(target[0]), 'w') 11864202Sbinkertn@umich.edu print >> f, '#define', variable, value 11875863Snate@binkert.org f.close() 118810135SCurtis.Dunham@arm.com return None 11898474Sgblack@eecs.umich.edu 11905742Snate@binkert.org# Combine the two functions into a scons Action object. 11918268Ssteve.reinhardt@amd.comconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 11928268Ssteve.reinhardt@amd.com 11938268Ssteve.reinhardt@amd.com# The emitter munges the source & target node lists to reflect what 11945742Snate@binkert.org# we're really doing. 11955341Sstever@gmail.comdef config_emitter(target, source, env): 11968474Sgblack@eecs.umich.edu # extract variable name from Builder arg 11978474Sgblack@eecs.umich.edu variable = str(target[0]) 11985342Sstever@gmail.com # True target is config header file 11994202Sbinkertn@umich.edu target = joinpath('config', variable.lower() + '.hh') 12004202Sbinkertn@umich.edu val = env[variable] 120111308Santhony.gutierrez@amd.com if isinstance(val, bool): 12024202Sbinkertn@umich.edu # Force value to 0/1 12035863Snate@binkert.org val = int(val) 12045863Snate@binkert.org elif isinstance(val, str): 120511308Santhony.gutierrez@amd.com val = '"' + val + '"' 12066994Snate@binkert.org 12076994Snate@binkert.org # Sources are variable name & value (packaged in SCons Value nodes) 120810319SAndreas.Sandberg@ARM.com return ([target], [Value(variable), Value(val)]) 12095863Snate@binkert.org 12105863Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 12115863Snate@binkert.org 12125863Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 12135863Snate@binkert.org 12145863Snate@binkert.org# libelf build is shared across all configs in the build root. 12155863Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 12165863Snate@binkert.org variant_dir = joinpath(build_root, 'libelf')) 12177840Snate@binkert.org 12185863Snate@binkert.org# gzstream build is shared across all configs in the build root. 12195952Ssaidi@eecs.umich.edumain.SConscript('ext/gzstream/SConscript', 12209651SAndreas.Sandberg@ARM.com variant_dir = joinpath(build_root, 'gzstream')) 122111308Santhony.gutierrez@amd.com 12229219Spower.jg@gmail.com# libfdt build is shared across all configs in the build root. 12239219Spower.jg@gmail.commain.SConscript('ext/libfdt/SConscript', 122411235Sandreas.sandberg@arm.com variant_dir = joinpath(build_root, 'libfdt')) 122511235Sandreas.sandberg@arm.com 12261869SN/A# fputils build is shared across all configs in the build root. 12271858SN/Amain.SConscript('ext/fputils/SConscript', 12285863Snate@binkert.org variant_dir = joinpath(build_root, 'fputils')) 122911308Santhony.gutierrez@amd.com 123011308Santhony.gutierrez@amd.com# DRAMSim2 build is shared across all configs in the build root. 123111308Santhony.gutierrez@amd.commain.SConscript('ext/dramsim2/SConscript', 12321858SN/A variant_dir = joinpath(build_root, 'dramsim2')) 1233955SN/A 1234955SN/A# DRAMPower build is shared across all configs in the build root. 12351869SN/Amain.SConscript('ext/drampower/SConscript', 12361869SN/A variant_dir = joinpath(build_root, 'drampower')) 12371869SN/A 12381869SN/A################################################### 12391869SN/A# 12405863Snate@binkert.org# This function is used to set up a directory with switching headers 12415863Snate@binkert.org# 12425863Snate@binkert.org################################################### 12431869SN/A 12445863Snate@binkert.orgmain['ALL_ISA_LIST'] = all_isa_list 12451869SN/Aall_isa_deps = {} 12465863Snate@binkert.orgdef make_switching_dir(dname, switch_headers, env): 12471869SN/A # Generate the header. target[0] is the full path of the output 12481869SN/A # header to generate. 'source' is a dummy variable, since we get the 12491869SN/A # list of ISAs from env['ALL_ISA_LIST']. 12501869SN/A def gen_switch_hdr(target, source, env): 12518483Sgblack@eecs.umich.edu fname = str(target[0]) 12521869SN/A isa = env['TARGET_ISA'].lower() 12531869SN/A try: 12541869SN/A f = open(fname, 'w') 12551869SN/A print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 12565863Snate@binkert.org f.close() 12575863Snate@binkert.org except IOError: 12581869SN/A print "Failed to create %s" % fname 12595863Snate@binkert.org raise 12605863Snate@binkert.org 12613356Sbinkertn@umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 12623356Sbinkertn@umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 12633356Sbinkertn@umich.edu # should get re-executed. 12643356Sbinkertn@umich.edu switch_hdr_action = MakeAction(gen_switch_hdr, 12653356Sbinkertn@umich.edu Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 12664781Snate@binkert.org 12675863Snate@binkert.org # Instantiate actions for each header 12685863Snate@binkert.org for hdr in switch_headers: 12691869SN/A env.Command(hdr, [], switch_hdr_action) 12701869SN/A 12711869SN/A isa_target = Dir('.').up().name.lower().replace('_', '-') 12726121Snate@binkert.org env['PHONY_BASE'] = '#'+isa_target 12731869SN/A all_isa_deps[isa_target] = None 12742638Sstever@eecs.umich.edu 12756121Snate@binkert.orgExport('make_switching_dir') 12766121Snate@binkert.org 12772638Sstever@eecs.umich.edu# all-isas -> all-deps -> all-environs -> all_targets 127811293Sandreas.hansson@arm.commain.Alias('#all-isas', []) 127911293Sandreas.hansson@arm.commain.Alias('#all-deps', '#all-isas') 128011293Sandreas.hansson@arm.com 12815749Scws3k@cs.virginia.edu# Dummy target to ensure all environments are created before telling 12829537Satgutier@umich.edu# SCons what to actually make (the command line arguments). We attach 12839537Satgutier@umich.edu# them to the dependence graph after the environments are complete. 12849537Satgutier@umich.eduORIG_BUILD_TARGETS = list(BUILD_TARGETS) # force a copy; gets closure to work. 12859537Satgutier@umich.edudef environsComplete(target, source, env): 12869888Sandreas@sandberg.pp.se for t in ORIG_BUILD_TARGETS: 12879888Sandreas@sandberg.pp.se main.Depends('#all-targets', t) 12889888Sandreas@sandberg.pp.se 12899888Sandreas@sandberg.pp.se# Each build/* switching_dir attaches its *-environs target to #all-environs. 129010066Sandreas.hansson@arm.commain.Append(BUILDERS = {'CompleteEnvirons' : 129110066Sandreas.hansson@arm.com Builder(action=MakeAction(environsComplete, None))}) 129210066Sandreas.hansson@arm.commain.CompleteEnvirons('#all-environs', []) 129310066Sandreas.hansson@arm.com 129410428Sandreas.hansson@arm.comdef doNothing(**ignored): pass 129510428Sandreas.hansson@arm.commain.Append(BUILDERS = {'Dummy': Builder(action=MakeAction(doNothing, None))}) 129610428Sandreas.hansson@arm.com 129710428Sandreas.hansson@arm.com# The final target to which all the original targets ultimately get attached. 129810915Sandreas.sandberg@arm.commain.Dummy('#all-targets', '#all-environs') 129910915Sandreas.sandberg@arm.comBUILD_TARGETS[:] = ['#all-targets'] 130010915Sandreas.sandberg@arm.com 130110915Sandreas.sandberg@arm.com################################################### 13021869SN/A# 13031869SN/A# Define build environments for selected configurations. 13043546Sgblack@eecs.umich.edu# 13053546Sgblack@eecs.umich.edu################################################### 13063546Sgblack@eecs.umich.edu 13073546Sgblack@eecs.umich.edufor variant_path in variant_paths: 13086121Snate@binkert.org if not GetOption('silent'): 130911308Santhony.gutierrez@amd.com print "Building in", variant_path 131010196SCurtis.Dunham@arm.com 13115863Snate@binkert.org # Make a copy of the build-root environment to use for this config. 13123546Sgblack@eecs.umich.edu env = main.Clone() 13133546Sgblack@eecs.umich.edu env['BUILDDIR'] = variant_path 13143546Sgblack@eecs.umich.edu 13153546Sgblack@eecs.umich.edu # variant_dir is the tail component of build path, and is used to 13164781Snate@binkert.org # determine the build parameters (e.g., 'ALPHA_SE') 13176658Snate@binkert.org (build_root, variant_dir) = splitpath(variant_path) 131810196SCurtis.Dunham@arm.com 131910196SCurtis.Dunham@arm.com # Set env variables according to the build directory config. 132010196SCurtis.Dunham@arm.com sticky_vars.files = [] 132110196SCurtis.Dunham@arm.com # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 132210196SCurtis.Dunham@arm.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 132310196SCurtis.Dunham@arm.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 132410196SCurtis.Dunham@arm.com current_vars_file = joinpath(build_root, 'variables', variant_dir) 13253546Sgblack@eecs.umich.edu if isfile(current_vars_file): 13263546Sgblack@eecs.umich.edu sticky_vars.files.append(current_vars_file) 13273546Sgblack@eecs.umich.edu if not GetOption('silent'): 13283546Sgblack@eecs.umich.edu print "Using saved variables file %s" % current_vars_file 13297756SAli.Saidi@ARM.com else: 13307816Ssteve.reinhardt@amd.com # Build dir-specific variables file doesn't exist. 13313546Sgblack@eecs.umich.edu 13323546Sgblack@eecs.umich.edu # Make sure the directory is there so we can create it later 13333546Sgblack@eecs.umich.edu opt_dir = dirname(current_vars_file) 13343546Sgblack@eecs.umich.edu if not isdir(opt_dir): 133510196SCurtis.Dunham@arm.com mkdir(opt_dir) 133610196SCurtis.Dunham@arm.com 133710196SCurtis.Dunham@arm.com # Get default build variables from source tree. Variables are 133810196SCurtis.Dunham@arm.com # normally determined by name of $VARIANT_DIR, but can be 133910196SCurtis.Dunham@arm.com # overridden by '--default=' arg on command line. 13404202Sbinkertn@umich.edu default = GetOption('default') 13413546Sgblack@eecs.umich.edu opts_dir = joinpath(main.root.abspath, 'build_opts') 134211308Santhony.gutierrez@amd.com if default: 134311308Santhony.gutierrez@amd.com default_vars_files = [joinpath(build_root, 'variables', default), 134411308Santhony.gutierrez@amd.com joinpath(opts_dir, default)] 134511308Santhony.gutierrez@amd.com else: 134611308Santhony.gutierrez@amd.com default_vars_files = [joinpath(opts_dir, variant_dir)] 134711308Santhony.gutierrez@amd.com existing_files = filter(isfile, default_vars_files) 134811308Santhony.gutierrez@amd.com if existing_files: 134911308Santhony.gutierrez@amd.com default_vars_file = existing_files[0] 135011308Santhony.gutierrez@amd.com sticky_vars.files.append(default_vars_file) 135111308Santhony.gutierrez@amd.com print "Variables file %s not found,\n using defaults in %s" \ 135211308Santhony.gutierrez@amd.com % (current_vars_file, default_vars_file) 135311308Santhony.gutierrez@amd.com else: 135411308Santhony.gutierrez@amd.com print "Error: cannot find variables file %s or " \ 135511308Santhony.gutierrez@amd.com "default file(s) %s" \ 135611308Santhony.gutierrez@amd.com % (current_vars_file, ' or '.join(default_vars_files)) 135711308Santhony.gutierrez@amd.com Exit(1) 135811308Santhony.gutierrez@amd.com 135911308Santhony.gutierrez@amd.com # Apply current variable settings to env 136011308Santhony.gutierrez@amd.com sticky_vars.Update(env) 136111308Santhony.gutierrez@amd.com 136211308Santhony.gutierrez@amd.com help_texts["local_vars"] += \ 136311308Santhony.gutierrez@amd.com "Build variables for %s:\n" % variant_dir \ 136411308Santhony.gutierrez@amd.com + sticky_vars.GenerateHelpText(env) 136511308Santhony.gutierrez@amd.com 136611308Santhony.gutierrez@amd.com # Process variable settings. 136711308Santhony.gutierrez@amd.com 136811308Santhony.gutierrez@amd.com if not have_fenv and env['USE_FENV']: 136911308Santhony.gutierrez@amd.com print "Warning: <fenv.h> not available; " \ 137011308Santhony.gutierrez@amd.com "forcing USE_FENV to False in", variant_dir + "." 137110196SCurtis.Dunham@arm.com env['USE_FENV'] = False 137210196SCurtis.Dunham@arm.com 137310196SCurtis.Dunham@arm.com if not env['USE_FENV']: 137410196SCurtis.Dunham@arm.com print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 137510196SCurtis.Dunham@arm.com print " FP results may deviate slightly from other platforms." 137610196SCurtis.Dunham@arm.com 137710196SCurtis.Dunham@arm.com if env['EFENCE']: 137810196SCurtis.Dunham@arm.com env.Append(LIBS=['efence']) 137910196SCurtis.Dunham@arm.com 138010196SCurtis.Dunham@arm.com if env['USE_KVM']: 138110196SCurtis.Dunham@arm.com if not have_kvm: 138210196SCurtis.Dunham@arm.com print "Warning: Can not enable KVM, host seems to lack KVM support" 138310196SCurtis.Dunham@arm.com env['USE_KVM'] = False 138410196SCurtis.Dunham@arm.com elif not is_isa_kvm_compatible(env['TARGET_ISA']): 138510196SCurtis.Dunham@arm.com print "Info: KVM support disabled due to unsupported host and " \ 138610196SCurtis.Dunham@arm.com "target ISA combination" 138710196SCurtis.Dunham@arm.com env['USE_KVM'] = False 138810196SCurtis.Dunham@arm.com 138910196SCurtis.Dunham@arm.com # Warn about missing optional functionality 139010196SCurtis.Dunham@arm.com if env['USE_KVM']: 139110196SCurtis.Dunham@arm.com if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']: 139210196SCurtis.Dunham@arm.com print "Warning: perf_event headers lack support for the " \ 139310196SCurtis.Dunham@arm.com "exclude_host attribute. KVM instruction counts will " \ 139410196SCurtis.Dunham@arm.com "be inaccurate." 13953546Sgblack@eecs.umich.edu 13963546Sgblack@eecs.umich.edu # Save sticky variable settings back to current variables file 1397955SN/A sticky_vars.Save(current_vars_file, env) 1398955SN/A 1399955SN/A if env['USE_SSE2']: 1400955SN/A env.Append(CCFLAGS=['-msse2']) 14015863Snate@binkert.org 140210135SCurtis.Dunham@arm.com # The src/SConscript file sets up the build rules in 'env' according 140310135SCurtis.Dunham@arm.com # to the configured variables. It returns a list of environments, 14045343Sstever@gmail.com # one for each variant build (debug, opt, etc.) 14055343Sstever@gmail.com SConscript('src/SConscript', variant_dir = variant_path, exports = 'env') 14066121Snate@binkert.org 14075863Snate@binkert.orgdef pairwise(iterable): 14084773Snate@binkert.org "s -> (s0,s1), (s1,s2), (s2, s3), ..." 14095863Snate@binkert.org a, b = itertools.tee(iterable) 14102632Sstever@eecs.umich.edu b.next() 14115863Snate@binkert.org return itertools.izip(a, b) 14122023SN/A 14135863Snate@binkert.org# Create false dependencies so SCons will parse ISAs, establish 14145863Snate@binkert.org# dependencies, and setup the build Environments serially. Either 14155863Snate@binkert.org# SCons (likely) and/or our SConscripts (possibly) cannot cope with -j 14165863Snate@binkert.org# greater than 1. It appears to be standard race condition stuff; it 14175863Snate@binkert.org# doesn't always fail, but usually, and the behaviors are different. 14185863Snate@binkert.org# Every time I tried to remove this, builds would fail in some 14195863Snate@binkert.org# creative new way. So, don't do that. You'll want to, though, because 14205863Snate@binkert.org# tests/SConscript takes a long time to make its Environments. 142110135SCurtis.Dunham@arm.comfor t1, t2 in pairwise(sorted(all_isa_deps.iterkeys())): 142210135SCurtis.Dunham@arm.com main.Depends('#%s-deps' % t2, '#%s-deps' % t1) 14232632Sstever@eecs.umich.edu main.Depends('#%s-environs' % t2, '#%s-environs' % t1) 14245863Snate@binkert.org 14252023SN/A# base help text 14262632Sstever@eecs.umich.eduHelp(''' 14275863Snate@binkert.orgUsage: scons [scons options] [build variables] [target(s)] 14285342Sstever@gmail.com 14295863Snate@binkert.orgExtra scons options: 14302632Sstever@eecs.umich.edu%(options)s 14315863Snate@binkert.org 14325863Snate@binkert.orgGlobal build variables: 14338267Ssteve.reinhardt@amd.com%(global_vars)s 14348120Sgblack@eecs.umich.edu 14358267Ssteve.reinhardt@amd.com%(local_vars)s 14368267Ssteve.reinhardt@amd.com''' % help_texts) 14378267Ssteve.reinhardt@amd.com