SConstruct revision 12056
1955SN/A# -*- mode:python -*- 2955SN/A 312230Sgiacomo.travaglini@arm.com# Copyright (c) 2013, 2015, 2016 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 8112563Sgabeblack@google.com# Check for recent-enough Python and SCons versions. 8212563Sgabeblack@google.comtry: 836654Snate@binkert.org # Really old versions of scons only take two options for the 8410196SCurtis.Dunham@arm.com # function, so check once without the revision and once with the 85955SN/A # revision, the first instance will fail for stuff other than 865396Ssaidi@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 8711401Sandreas.sandberg@arm.com EnsureSConsVersion(0, 98) 885863Snate@binkert.org EnsureSConsVersion(0, 98, 1) 895863Snate@binkert.orgexcept SystemExit, e: 904202Sbinkertn@umich.edu print """ 915863Snate@binkert.orgFor more details, see: 925863Snate@binkert.org http://gem5.org/Dependencies 935863Snate@binkert.org""" 945863Snate@binkert.org raise 9513541Sandrea.mondelli@ucf.edu 96955SN/A# We ensure the python version early because because python-config 976654Snate@binkert.org# requires python 2.5 985273Sstever@gmail.comtry: 995871Snate@binkert.org EnsurePythonVersion(2, 5) 1005273Sstever@gmail.comexcept SystemExit, e: 1016654Snate@binkert.org print """ 1025396Ssaidi@eecs.umich.eduYou can use a non-default installation of the Python interpreter by 1038120Sgblack@eecs.umich.edurearranging your PATH so that scons finds the non-default 'python' and 1048120Sgblack@eecs.umich.edu'python-config' first. 1058120Sgblack@eecs.umich.edu 1068120Sgblack@eecs.umich.eduFor more details, see: 1078120Sgblack@eecs.umich.edu http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 1088120Sgblack@eecs.umich.edu""" 1098120Sgblack@eecs.umich.edu raise 1108120Sgblack@eecs.umich.edu 1118879Ssteve.reinhardt@amd.com# Global Python includes 1128879Ssteve.reinhardt@amd.comimport itertools 1138879Ssteve.reinhardt@amd.comimport os 1148879Ssteve.reinhardt@amd.comimport re 1158879Ssteve.reinhardt@amd.comimport shutil 1168879Ssteve.reinhardt@amd.comimport subprocess 1178879Ssteve.reinhardt@amd.comimport sys 1188879Ssteve.reinhardt@amd.com 1198879Ssteve.reinhardt@amd.comfrom os import mkdir, environ 1208879Ssteve.reinhardt@amd.comfrom os.path import abspath, basename, dirname, expanduser, normpath 1218879Ssteve.reinhardt@amd.comfrom os.path import exists, isdir, isfile 1228879Ssteve.reinhardt@amd.comfrom os.path import join as joinpath, split as splitpath 1238879Ssteve.reinhardt@amd.com 1248120Sgblack@eecs.umich.edu# SCons includes 1258120Sgblack@eecs.umich.eduimport SCons 1268120Sgblack@eecs.umich.eduimport SCons.Node 1278120Sgblack@eecs.umich.edu 1288120Sgblack@eecs.umich.eduextra_python_paths = [ 1298120Sgblack@eecs.umich.edu Dir('src/python').srcnode().abspath, # gem5 includes 1308120Sgblack@eecs.umich.edu Dir('ext/ply').srcnode().abspath, # ply is used by several files 1318120Sgblack@eecs.umich.edu ] 1328120Sgblack@eecs.umich.edu 1338120Sgblack@eecs.umich.edusys.path[1:1] = extra_python_paths 1348120Sgblack@eecs.umich.edu 1358120Sgblack@eecs.umich.edufrom m5.util import compareVersions, readCommand 1368120Sgblack@eecs.umich.edufrom m5.util.terminal import get_termcap 1378120Sgblack@eecs.umich.edu 1388879Ssteve.reinhardt@amd.comhelp_texts = { 1398879Ssteve.reinhardt@amd.com "options" : "", 1408879Ssteve.reinhardt@amd.com "global_vars" : "", 1418879Ssteve.reinhardt@amd.com "local_vars" : "" 14210458Sandreas.hansson@arm.com} 14310458Sandreas.hansson@arm.com 14410458Sandreas.hansson@arm.comExport("help_texts") 1458879Ssteve.reinhardt@amd.com 1468879Ssteve.reinhardt@amd.com 1478879Ssteve.reinhardt@amd.com# There's a bug in scons in that (1) by default, the help texts from 1488879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h' 14913421Sciro.santilli@arm.com# and (2) you can override the help displayed by 'scons -h' using the 15013421Sciro.santilli@arm.com# Help() function, but these two features are incompatible: once 1519227Sandreas.hansson@arm.com# you've overridden the help text using Help(), there's no way to get 1529227Sandreas.hansson@arm.com# at the help texts from AddOptions. See: 15312063Sgabeblack@google.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 15412063Sgabeblack@google.com# http://scons.tigris.org/issues/show_bug.cgi?id=2611 15512063Sgabeblack@google.com# This hack lets us extract the help text from AddOptions and 1568879Ssteve.reinhardt@amd.com# re-inject it via Help(). Ideally someday this bug will be fixed and 1578879Ssteve.reinhardt@amd.com# we can just use AddOption directly. 1588879Ssteve.reinhardt@amd.comdef AddLocalOption(*args, **kwargs): 1598879Ssteve.reinhardt@amd.com col_width = 30 16010453SAndrew.Bardsley@arm.com 16110453SAndrew.Bardsley@arm.com help = " " + ", ".join(args) 16210453SAndrew.Bardsley@arm.com if "help" in kwargs: 16310456SCurtis.Dunham@arm.com length = len(help) 16410456SCurtis.Dunham@arm.com if length >= col_width: 16510456SCurtis.Dunham@arm.com help += "\n" + " " * col_width 16610457Sandreas.hansson@arm.com else: 16710457Sandreas.hansson@arm.com help += " " * (col_width - length) 16811342Sandreas.hansson@arm.com help += kwargs["help"] 16911342Sandreas.hansson@arm.com help_texts["options"] += help + "\n" 1708120Sgblack@eecs.umich.edu 17112063Sgabeblack@google.com AddOption(*args, **kwargs) 17212563Sgabeblack@google.com 17312063Sgabeblack@google.comAddLocalOption('--colors', dest='use_colors', action='store_true', 17412063Sgabeblack@google.com help="Add color to abbreviated scons output") 1755871Snate@binkert.orgAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1765871Snate@binkert.org help="Don't add color to abbreviated scons output") 1776121Snate@binkert.orgAddLocalOption('--with-cxx-config', dest='with_cxx_config', 1785871Snate@binkert.org action='store_true', 1795871Snate@binkert.org help="Build with support for C++-based configuration") 1809926Sstan.czerniawski@arm.comAddLocalOption('--default', dest='default', type='string', action='store', 18112243Sgabeblack@google.com help='Override which build_opts file to use for defaults') 1821533SN/AAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 18312246Sgabeblack@google.com help='Disable style checking hooks') 18412246Sgabeblack@google.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 18512246Sgabeblack@google.com help='Disable Link-Time Optimization for fast') 18612246Sgabeblack@google.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1879239Sandreas.hansson@arm.com help='Update test reference outputs') 1889239Sandreas.hansson@arm.comAddLocalOption('--verbose', dest='verbose', action='store_true', 1899239Sandreas.hansson@arm.com help='Print full tool command lines') 1909239Sandreas.hansson@arm.comAddLocalOption('--without-python', dest='without_python', 19112563Sgabeblack@google.com action='store_true', 1929239Sandreas.hansson@arm.com help='Build without Python configuration support') 1939239Sandreas.hansson@arm.comAddLocalOption('--without-tcmalloc', dest='without_tcmalloc', 194955SN/A action='store_true', 195955SN/A help='Disable linking against tcmalloc') 1962632Sstever@eecs.umich.eduAddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true', 1972632Sstever@eecs.umich.edu help='Build with Undefined Behavior Sanitizer if available') 198955SN/AAddLocalOption('--with-asan', dest='with_asan', action='store_true', 199955SN/A help='Build with Address Sanitizer if available') 200955SN/A 201955SN/Atermcap = get_termcap(GetOption('use_colors')) 2028878Ssteve.reinhardt@amd.com 203955SN/A######################################################################## 2042632Sstever@eecs.umich.edu# 2052632Sstever@eecs.umich.edu# Set up the main build environment. 2062632Sstever@eecs.umich.edu# 2072632Sstever@eecs.umich.edu######################################################################## 2082632Sstever@eecs.umich.edu 2092632Sstever@eecs.umich.edu# export TERM so that clang reports errors in color 2102632Sstever@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 2118268Ssteve.reinhardt@amd.com 'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PROTOC', 2128268Ssteve.reinhardt@amd.com 'PYTHONPATH', 'RANLIB', 'TERM' ]) 2138268Ssteve.reinhardt@amd.com 2148268Ssteve.reinhardt@amd.comuse_prefixes = [ 2158268Ssteve.reinhardt@amd.com "ASAN_", # address sanitizer symbolizer path and settings 2168268Ssteve.reinhardt@amd.com "CCACHE_", # ccache (caching compiler wrapper) configuration 2178268Ssteve.reinhardt@amd.com "CCC_", # clang static analyzer configuration 2182632Sstever@eecs.umich.edu "DISTCC_", # distcc (distributed compiler wrapper) configuration 2192632Sstever@eecs.umich.edu "INCLUDE_SERVER_", # distcc pump server settings 2202632Sstever@eecs.umich.edu "M5", # M5 configuration (e.g., path to kernels) 2212632Sstever@eecs.umich.edu ] 2228268Ssteve.reinhardt@amd.com 2232632Sstever@eecs.umich.eduuse_env = {} 2248268Ssteve.reinhardt@amd.comfor key,val in sorted(os.environ.iteritems()): 2258268Ssteve.reinhardt@amd.com if key in use_vars or \ 2268268Ssteve.reinhardt@amd.com any([key.startswith(prefix) for prefix in use_prefixes]): 2278268Ssteve.reinhardt@amd.com use_env[key] = val 2283718Sstever@eecs.umich.edu 2292634Sstever@eecs.umich.edu# Tell scons to avoid implicit command dependencies to avoid issues 2302634Sstever@eecs.umich.edu# with the param wrappes being compiled twice (see 2315863Snate@binkert.org# http://scons.tigris.org/issues/show_bug.cgi?id=2811) 2322638Sstever@eecs.umich.edumain = Environment(ENV=use_env, IMPLICIT_COMMAND_DEPENDENCIES=0) 2338268Ssteve.reinhardt@amd.commain.Decider('MD5-timestamp') 2342632Sstever@eecs.umich.edumain.root = Dir(".") # The current directory (where this file lives). 2352632Sstever@eecs.umich.edumain.srcdir = Dir("src") # The source directory 2362632Sstever@eecs.umich.edu 2372632Sstever@eecs.umich.edumain_dict_keys = main.Dictionary().keys() 23812563Sgabeblack@google.com 2391858SN/A# Check that we have a C/C++ compiler 2403716Sstever@eecs.umich.eduif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 2412638Sstever@eecs.umich.edu print "No C++ compiler installed (package g++ on Ubuntu and RedHat)" 2422638Sstever@eecs.umich.edu Exit(1) 2432638Sstever@eecs.umich.edu 2442638Sstever@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 24512563Sgabeblack@google.com# as well 24612563Sgabeblack@google.commain.AppendENVPath('PYTHONPATH', extra_python_paths) 2472638Sstever@eecs.umich.edu 2485863Snate@binkert.org######################################################################## 2495863Snate@binkert.org# 2505863Snate@binkert.org# Mercurial Stuff. 251955SN/A# 2525341Sstever@gmail.com# If the gem5 directory is a mercurial repository, we should do some 2535341Sstever@gmail.com# extra things. 2545863Snate@binkert.org# 2557756SAli.Saidi@ARM.com######################################################################## 2565341Sstever@gmail.com 2576121Snate@binkert.orghgdir = main.root.Dir(".hg") 2584494Ssaidi@eecs.umich.edu 2596121Snate@binkert.org 2601105SN/Astyle_message = """ 2612667Sstever@eecs.umich.eduYou're missing the gem5 style hook, which automatically checks your code 2622667Sstever@eecs.umich.eduagainst the gem5 style rules on %s. 2632667Sstever@eecs.umich.eduThis script will now install the hook in your %s. 2642667Sstever@eecs.umich.eduPress enter to continue, or ctrl-c to abort: """ 2656121Snate@binkert.org 2662667Sstever@eecs.umich.edumercurial_style_message = """ 2675341Sstever@gmail.comYou're missing the gem5 style hook, which automatically checks your code 2685863Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands. 2695341Sstever@gmail.comThis script will now install the hook in your .hg/hgrc file. 2705341Sstever@gmail.comPress enter to continue, or ctrl-c to abort: """ 2715341Sstever@gmail.com 2728120Sgblack@eecs.umich.edugit_style_message = """ 2735341Sstever@gmail.comYou're missing the gem5 style or commit message hook. These hooks help 2748120Sgblack@eecs.umich.eduto ensure that your code follows gem5's style rules on git commit. 2755341Sstever@gmail.comThis script will now install the hook in your .git/hooks/ directory. 2768120Sgblack@eecs.umich.eduPress enter to continue, or ctrl-c to abort: """ 2776121Snate@binkert.org 2786121Snate@binkert.orgmercurial_style_upgrade_message = """ 2799396Sandreas.hansson@arm.comYour Mercurial style hooks are not up-to-date. This script will now 2805397Ssaidi@eecs.umich.edutry to automatically update them. A backup of your hgrc will be saved 2815397Ssaidi@eecs.umich.eduin .hg/hgrc.old. 2827727SAli.Saidi@ARM.comPress enter to continue, or ctrl-c to abort: """ 2838268Ssteve.reinhardt@amd.com 2846168Snate@binkert.orgmercurial_style_hook = """ 2855341Sstever@gmail.com# The following lines were automatically added by gem5/SConstruct 2868120Sgblack@eecs.umich.edu# to provide the gem5 style-checking hooks 2878120Sgblack@eecs.umich.edu[extensions] 2888120Sgblack@eecs.umich.eduhgstyle = %s/util/hgstyle.py 2896814Sgblack@eecs.umich.edu 2905863Snate@binkert.org[hooks] 2918120Sgblack@eecs.umich.edupretxncommit.style = python:hgstyle.check_style 2925341Sstever@gmail.compre-qrefresh.style = python:hgstyle.check_style 2935863Snate@binkert.org# End of SConstruct additions 2948268Ssteve.reinhardt@amd.com 2956121Snate@binkert.org""" % (main.root.abspath) 2966121Snate@binkert.org 2978268Ssteve.reinhardt@amd.commercurial_lib_not_found = """ 2985742Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook. If 2995742Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 3005341Sstever@gmail.comhook. It is important. 3015742Snate@binkert.org""" 3025742Snate@binkert.org 3035341Sstever@gmail.com# Check for style hook and prompt for installation if it's not there. 3046017Snate@binkert.org# Skip this if --ignore-style was specified, there's no interactive 3056121Snate@binkert.org# terminal to prompt, or no recognized revision control system can be 3066017Snate@binkert.org# found. 30712158Sandreas.sandberg@arm.comignore_style = GetOption('ignore_style') or not sys.stdin.isatty() 30812158Sandreas.sandberg@arm.com 30912158Sandreas.sandberg@arm.com# Try wire up Mercurial to the style hooks 3108120Sgblack@eecs.umich.eduif not ignore_style and hgdir.exists(): 3117756SAli.Saidi@ARM.com style_hook = True 3127756SAli.Saidi@ARM.com style_hooks = tuple() 3137756SAli.Saidi@ARM.com hgrc = hgdir.File('hgrc') 3147756SAli.Saidi@ARM.com hgrc_old = hgdir.File('hgrc.old') 3157816Ssteve.reinhardt@amd.com try: 3167816Ssteve.reinhardt@amd.com from mercurial import ui 3177816Ssteve.reinhardt@amd.com ui = ui.ui() 3187816Ssteve.reinhardt@amd.com ui.readconfig(hgrc.abspath) 3197816Ssteve.reinhardt@amd.com style_hooks = (ui.config('hooks', 'pretxncommit.style', None), 32011979Sgabeblack@google.com ui.config('hooks', 'pre-qrefresh.style', None)) 3217816Ssteve.reinhardt@amd.com style_hook = all(style_hooks) 3227816Ssteve.reinhardt@amd.com style_extension = ui.config('extensions', 'style', None) 3237816Ssteve.reinhardt@amd.com except ImportError: 3247816Ssteve.reinhardt@amd.com print mercurial_lib_not_found 3257756SAli.Saidi@ARM.com 3267756SAli.Saidi@ARM.com if "python:style.check_style" in style_hooks: 3279227Sandreas.hansson@arm.com # Try to upgrade the style hooks 3289227Sandreas.hansson@arm.com print mercurial_style_upgrade_message 3299227Sandreas.hansson@arm.com # continue unless user does ctrl-c/ctrl-d etc. 3309227Sandreas.hansson@arm.com try: 3319590Sandreas@sandberg.pp.se raw_input() 3329590Sandreas@sandberg.pp.se except: 3339590Sandreas@sandberg.pp.se print "Input exception, exiting scons.\n" 3349590Sandreas@sandberg.pp.se sys.exit(1) 3359590Sandreas@sandberg.pp.se shutil.copyfile(hgrc.abspath, hgrc_old.abspath) 3369590Sandreas@sandberg.pp.se re_style_hook = re.compile(r"^([^=#]+)\.style\s*=\s*([^#\s]+).*") 3376654Snate@binkert.org re_style_extension = re.compile("style\s*=\s*([^#\s]+).*") 3386654Snate@binkert.org old, new = open(hgrc_old.abspath, 'r'), open(hgrc.abspath, 'w') 3395871Snate@binkert.org for l in old: 3406121Snate@binkert.org m_hook = re_style_hook.match(l) 3418946Sandreas.hansson@arm.com m_ext = re_style_extension.match(l) 3429419Sandreas.hansson@arm.com if m_hook: 34312563Sgabeblack@google.com hook, check = m_hook.groups() 3443918Ssaidi@eecs.umich.edu if check != "python:style.check_style": 3453918Ssaidi@eecs.umich.edu print "Warning: %s.style is using a non-default " \ 3461858SN/A "checker: %s" % (hook, check) 3479556Sandreas.hansson@arm.com if hook not in ("pretxncommit", "pre-qrefresh"): 3489556Sandreas.hansson@arm.com print "Warning: Updating unknown style hook: %s" % hook 3499556Sandreas.hansson@arm.com 3509556Sandreas.hansson@arm.com l = "%s.style = python:hgstyle.check_style\n" % hook 35111294Sandreas.hansson@arm.com elif m_ext and m_ext.group(1) == style_extension: 35211294Sandreas.hansson@arm.com l = "hgstyle = %s/util/hgstyle.py\n" % main.root.abspath 35311294Sandreas.hansson@arm.com 35411294Sandreas.hansson@arm.com new.write(l) 35510878Sandreas.hansson@arm.com elif not style_hook: 35610878Sandreas.hansson@arm.com print mercurial_style_message, 35711811Sbaz21@cam.ac.uk # continue unless user does ctrl-c/ctrl-d etc. 35811811Sbaz21@cam.ac.uk try: 35911811Sbaz21@cam.ac.uk raw_input() 36011982Sgabeblack@google.com except: 36111982Sgabeblack@google.com print "Input exception, exiting scons.\n" 36211982Sgabeblack@google.com sys.exit(1) 36313421Sciro.santilli@arm.com hgrc_path = '%s/.hg/hgrc' % main.root.abspath 36413421Sciro.santilli@arm.com print "Adding style hook to", hgrc_path, "\n" 36511982Sgabeblack@google.com try: 36611992Sgabeblack@google.com with open(hgrc_path, 'a') as f: 36711982Sgabeblack@google.com f.write(mercurial_style_hook) 36811982Sgabeblack@google.com except: 36912305Sgabeblack@google.com print "Error updating", hgrc_path 37012305Sgabeblack@google.com sys.exit(1) 37112305Sgabeblack@google.com 37212305Sgabeblack@google.comdef install_git_style_hooks(): 37312305Sgabeblack@google.com try: 37412305Sgabeblack@google.com gitdir = Dir(readCommand( 37512305Sgabeblack@google.com ["git", "rev-parse", "--git-dir"]).strip("\n")) 3769556Sandreas.hansson@arm.com except Exception, e: 37712563Sgabeblack@google.com print "Warning: Failed to find git repo directory: %s" % e 37812563Sgabeblack@google.com return 37912563Sgabeblack@google.com 38012563Sgabeblack@google.com git_hooks = gitdir.Dir("hooks") 3819556Sandreas.hansson@arm.com def hook_exists(hook_name): 38212563Sgabeblack@google.com hook = git_hooks.File(hook_name) 38312563Sgabeblack@google.com return hook.exists() 3849556Sandreas.hansson@arm.com 38512563Sgabeblack@google.com def hook_install(hook_name, script): 38612563Sgabeblack@google.com hook = git_hooks.File(hook_name) 38712563Sgabeblack@google.com if hook.exists(): 38812563Sgabeblack@google.com print "Warning: Can't install %s, hook already exists." % hook_name 38912563Sgabeblack@google.com return 39012563Sgabeblack@google.com 39112563Sgabeblack@google.com if hook.islink(): 39212563Sgabeblack@google.com print "Warning: Removing broken symlink for hook %s." % hook_name 3939556Sandreas.hansson@arm.com os.unlink(hook.get_abspath()) 3949556Sandreas.hansson@arm.com 3956121Snate@binkert.org if not git_hooks.exists(): 39611500Sandreas.hansson@arm.com mkdir(git_hooks.get_abspath()) 39710238Sandreas.hansson@arm.com git_hooks.clear() 39810878Sandreas.hansson@arm.com 3999420Sandreas.hansson@arm.com abs_symlink_hooks = git_hooks.islink() and \ 40011500Sandreas.hansson@arm.com os.path.isabs(os.readlink(git_hooks.get_abspath())) 40112563Sgabeblack@google.com 40212563Sgabeblack@google.com # Use a relative symlink if the hooks live in the source directory, 4039420Sandreas.hansson@arm.com # and the hooks directory is not a symlink to an absolute path. 4049420Sandreas.hansson@arm.com if hook.is_under(main.root) and not abs_symlink_hooks: 4059420Sandreas.hansson@arm.com script_path = os.path.relpath( 4069420Sandreas.hansson@arm.com os.path.realpath(script.get_abspath()), 40712063Sgabeblack@google.com os.path.realpath(hook.Dir(".").get_abspath())) 40812063Sgabeblack@google.com else: 40912063Sgabeblack@google.com script_path = script.get_abspath() 41012063Sgabeblack@google.com 41112063Sgabeblack@google.com try: 41212063Sgabeblack@google.com os.symlink(script_path, hook.get_abspath()) 41312063Sgabeblack@google.com except: 41412063Sgabeblack@google.com print "Error updating git %s hook" % hook_name 41512063Sgabeblack@google.com raise 41612063Sgabeblack@google.com 41712063Sgabeblack@google.com if hook_exists("pre-commit") and hook_exists("commit-msg"): 41812063Sgabeblack@google.com return 41912063Sgabeblack@google.com 42012063Sgabeblack@google.com print git_style_message, 42112063Sgabeblack@google.com try: 42212063Sgabeblack@google.com raw_input() 42312063Sgabeblack@google.com except: 42412063Sgabeblack@google.com print "Input exception, exiting scons.\n" 42512063Sgabeblack@google.com sys.exit(1) 42612063Sgabeblack@google.com 42712063Sgabeblack@google.com git_style_script = File("util/git-pre-commit.py") 42812063Sgabeblack@google.com git_msg_script = File("ext/git-commit-msg") 42910457Sandreas.hansson@arm.com 43010457Sandreas.hansson@arm.com hook_install("pre-commit", git_style_script) 43110457Sandreas.hansson@arm.com hook_install("commit-msg", git_msg_script) 43210457Sandreas.hansson@arm.com 43310457Sandreas.hansson@arm.com# Try to wire up git to the style hooks 43412563Sgabeblack@google.comif not ignore_style and main.root.Entry(".git").exists(): 43512563Sgabeblack@google.com install_git_style_hooks() 43612563Sgabeblack@google.com 43710457Sandreas.hansson@arm.com################################################### 43812063Sgabeblack@google.com# 43912063Sgabeblack@google.com# Figure out which configurations to set up based on the path(s) of 44012063Sgabeblack@google.com# the target(s). 44112563Sgabeblack@google.com# 44212563Sgabeblack@google.com################################################### 44312563Sgabeblack@google.com 44412563Sgabeblack@google.com# Find default configuration & binary. 44512563Sgabeblack@google.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 44612563Sgabeblack@google.com 44712063Sgabeblack@google.com# helper function: find last occurrence of element in list 44812063Sgabeblack@google.comdef rfind(l, elt, offs = -1): 44910238Sandreas.hansson@arm.com for i in range(len(l)+offs, 0, -1): 45010238Sandreas.hansson@arm.com if l[i] == elt: 45110238Sandreas.hansson@arm.com return i 45212063Sgabeblack@google.com raise ValueError, "element not found" 45310238Sandreas.hansson@arm.com 45410238Sandreas.hansson@arm.com# Take a list of paths (or SCons Nodes) and return a list with all 45510416Sandreas.hansson@arm.com# paths made absolute and ~-expanded. Paths will be interpreted 45610238Sandreas.hansson@arm.com# relative to the launch directory unless a different root is provided 4579227Sandreas.hansson@arm.comdef makePathListAbsolute(path_list, root=GetLaunchDir()): 45810238Sandreas.hansson@arm.com return [abspath(joinpath(root, expanduser(str(p)))) 45910416Sandreas.hansson@arm.com for p in path_list] 46010416Sandreas.hansson@arm.com 4619227Sandreas.hansson@arm.com# Each target must have 'build' in the interior of the path; the 4629590Sandreas@sandberg.pp.se# directory below this will determine the build parameters. For 4639590Sandreas@sandberg.pp.se# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 4649590Sandreas@sandberg.pp.se# recognize that ALPHA_SE specifies the configuration because it 46512304Sgabeblack@google.com# follow 'build' in the build path. 46612304Sgabeblack@google.com 46712304Sgabeblack@google.com# The funky assignment to "[:]" is needed to replace the list contents 46812688Sgiacomo.travaglini@arm.com# in place rather than reassign the symbol to a new list, which 46912688Sgiacomo.travaglini@arm.com# doesn't work (obviously!). 47012688Sgiacomo.travaglini@arm.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 47113020Sshunhsingou@google.com 47212304Sgabeblack@google.com# Generate a list of the unique build roots and configs that the 47312688Sgiacomo.travaglini@arm.com# collected targets reference. 47412688Sgiacomo.travaglini@arm.comvariant_paths = [] 47513020Sshunhsingou@google.combuild_root = None 47612304Sgabeblack@google.comfor t in BUILD_TARGETS: 47712304Sgabeblack@google.com path_dirs = t.split('/') 47812304Sgabeblack@google.com try: 47912304Sgabeblack@google.com build_top = rfind(path_dirs, 'build', -2) 48012688Sgiacomo.travaglini@arm.com except: 48112688Sgiacomo.travaglini@arm.com print "Error: no non-leaf 'build' dir found on target path", t 48212688Sgiacomo.travaglini@arm.com Exit(1) 48312304Sgabeblack@google.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 4848737Skoansin.tan@gmail.com if not build_root: 48510878Sandreas.hansson@arm.com build_root = this_build_root 48611500Sandreas.hansson@arm.com else: 4879420Sandreas.hansson@arm.com if this_build_root != build_root: 4888737Skoansin.tan@gmail.com print "Error: build targets not under same build root\n"\ 48910106SMitch.Hayenga@arm.com " %s\n %s" % (build_root, this_build_root) 4908737Skoansin.tan@gmail.com Exit(1) 4918737Skoansin.tan@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 49210878Sandreas.hansson@arm.com if variant_path not in variant_paths: 49312563Sgabeblack@google.com variant_paths.append(variant_path) 49412563Sgabeblack@google.com 4958737Skoansin.tan@gmail.com# Make sure build_root exists (might not if this is the first build there) 4968737Skoansin.tan@gmail.comif not isdir(build_root): 49712563Sgabeblack@google.com mkdir(build_root) 4988737Skoansin.tan@gmail.commain['BUILDROOT'] = build_root 4998737Skoansin.tan@gmail.com 50011294Sandreas.hansson@arm.comExport('main') 5019556Sandreas.hansson@arm.com 5029556Sandreas.hansson@arm.commain.SConsignFile(joinpath(build_root, "sconsign")) 5039556Sandreas.hansson@arm.com 50411294Sandreas.hansson@arm.com# Default duplicate option is to use hard links, but this messes up 50510278SAndreas.Sandberg@ARM.com# when you use emacs to edit a file in the target dir, as emacs moves 50610278SAndreas.Sandberg@ARM.com# file to file~ then copies to file, breaking the link. Symbolic 50710278SAndreas.Sandberg@ARM.com# (soft) links work better. 50810278SAndreas.Sandberg@ARM.commain.SetOption('duplicate', 'soft-copy') 50910278SAndreas.Sandberg@ARM.com 51010278SAndreas.Sandberg@ARM.com# 5119556Sandreas.hansson@arm.com# Set up global sticky variables... these are common to an entire build 5129590Sandreas@sandberg.pp.se# tree (not specific to a particular build like ALPHA_SE) 5139590Sandreas@sandberg.pp.se# 5149420Sandreas.hansson@arm.com 5159846Sandreas.hansson@arm.comglobal_vars_file = joinpath(build_root, 'variables.global') 5169846Sandreas.hansson@arm.com 5179846Sandreas.hansson@arm.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 5189846Sandreas.hansson@arm.com 5198946Sandreas.hansson@arm.comglobal_vars.AddVariables( 52011811Sbaz21@cam.ac.uk ('CC', 'C compiler', environ.get('CC', main['CC'])), 52111811Sbaz21@cam.ac.uk ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 52211811Sbaz21@cam.ac.uk ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 52311811Sbaz21@cam.ac.uk ('BATCH', 'Use batch pool for build and tests', False), 52412304Sgabeblack@google.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 52512304Sgabeblack@google.com ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 52612304Sgabeblack@google.com ('EXTRAS', 'Add extra directories to the compilation', '') 52712304Sgabeblack@google.com ) 52813020Sshunhsingou@google.com 52913020Sshunhsingou@google.com# Update main environment with values from ARGUMENTS & global_vars_file 53012304Sgabeblack@google.comglobal_vars.Update(main) 53112304Sgabeblack@google.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 53213020Sshunhsingou@google.com 53313020Sshunhsingou@google.com# Save sticky variable settings back to current variables file 53412304Sgabeblack@google.comglobal_vars.Save(global_vars_file, main) 53512304Sgabeblack@google.com 53613020Sshunhsingou@google.com# Parse EXTRAS variable to build list of all directories where we're 53713020Sshunhsingou@google.com# look for sources etc. This list is exported as extras_dir_list. 53812304Sgabeblack@google.combase_dir = main.srcdir.abspath 53912304Sgabeblack@google.comif main['EXTRAS']: 5403918Ssaidi@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 54112563Sgabeblack@google.comelse: 54212563Sgabeblack@google.com extras_dir_list = [] 54312563Sgabeblack@google.com 54412563Sgabeblack@google.comExport('base_dir') 5459068SAli.Saidi@ARM.comExport('extras_dir_list') 54612563Sgabeblack@google.com 54712563Sgabeblack@google.com# the ext directory should be on the #includes path 5489068SAli.Saidi@ARM.commain.Append(CPPPATH=[Dir('ext')]) 54912563Sgabeblack@google.com 55012563Sgabeblack@google.comdef strip_build_path(path, env): 55112563Sgabeblack@google.com path = str(path) 55212563Sgabeblack@google.com variant_base = env['BUILDROOT'] + os.path.sep 55312563Sgabeblack@google.com if path.startswith(variant_base): 55412563Sgabeblack@google.com path = path[len(variant_base):] 55512563Sgabeblack@google.com elif path.startswith('build/'): 55612563Sgabeblack@google.com path = path[6:] 5573918Ssaidi@eecs.umich.edu return path 5583918Ssaidi@eecs.umich.edu 5596157Snate@binkert.org# Generate a string of the form: 5606157Snate@binkert.org# common/path/prefix/src1, src2 -> tgt1, tgt2 5616157Snate@binkert.org# to print while building. 5626157Snate@binkert.orgclass Transform(object): 5635397Ssaidi@eecs.umich.edu # all specific color settings should be here and nowhere else 5645397Ssaidi@eecs.umich.edu tool_color = termcap.Normal 5656121Snate@binkert.org pfx_color = termcap.Yellow 5666121Snate@binkert.org srcs_color = termcap.Yellow + termcap.Bold 5676121Snate@binkert.org arrow_color = termcap.Blue + termcap.Bold 5686121Snate@binkert.org tgts_color = termcap.Yellow + termcap.Bold 5696121Snate@binkert.org 5706121Snate@binkert.org def __init__(self, tool, max_sources=99): 5715397Ssaidi@eecs.umich.edu self.format = self.tool_color + (" [%8s] " % tool) \ 5721851SN/A + self.pfx_color + "%s" \ 5731851SN/A + self.srcs_color + "%s" \ 5747739Sgblack@eecs.umich.edu + self.arrow_color + " -> " \ 575955SN/A + self.tgts_color + "%s" \ 5769396Sandreas.hansson@arm.com + termcap.Normal 5779396Sandreas.hansson@arm.com self.max_sources = max_sources 5789396Sandreas.hansson@arm.com 5799396Sandreas.hansson@arm.com def __call__(self, target, source, env, for_signature=None): 5809396Sandreas.hansson@arm.com # truncate source list according to max_sources param 5819396Sandreas.hansson@arm.com source = source[0:self.max_sources] 58212563Sgabeblack@google.com def strip(f): 58312563Sgabeblack@google.com return strip_build_path(str(f), env) 58412563Sgabeblack@google.com if len(source) > 0: 58512563Sgabeblack@google.com srcs = map(strip, source) 5869396Sandreas.hansson@arm.com else: 5879396Sandreas.hansson@arm.com srcs = [''] 5889396Sandreas.hansson@arm.com tgts = map(strip, target) 5899396Sandreas.hansson@arm.com # surprisingly, os.path.commonprefix is a dumb char-by-char string 5909396Sandreas.hansson@arm.com # operation that has nothing to do with paths. 5919396Sandreas.hansson@arm.com com_pfx = os.path.commonprefix(srcs + tgts) 59212563Sgabeblack@google.com com_pfx_len = len(com_pfx) 59312563Sgabeblack@google.com if com_pfx: 59412563Sgabeblack@google.com # do some cleanup and sanity checking on common prefix 59512563Sgabeblack@google.com if com_pfx[-1] == ".": 59612563Sgabeblack@google.com # prefix matches all but file extension: ok 5979477Sandreas.hansson@arm.com # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 5989477Sandreas.hansson@arm.com com_pfx = com_pfx[0:-1] 5999477Sandreas.hansson@arm.com elif com_pfx[-1] == "/": 6009477Sandreas.hansson@arm.com # common prefix is directory path: OK 6019477Sandreas.hansson@arm.com pass 6029477Sandreas.hansson@arm.com else: 6039477Sandreas.hansson@arm.com src0_len = len(srcs[0]) 6049477Sandreas.hansson@arm.com tgt0_len = len(tgts[0]) 6059477Sandreas.hansson@arm.com if src0_len == com_pfx_len: 6069477Sandreas.hansson@arm.com # source is a substring of target, OK 6079477Sandreas.hansson@arm.com pass 6089477Sandreas.hansson@arm.com elif tgt0_len == com_pfx_len: 6099477Sandreas.hansson@arm.com # target is a substring of source, need to back up to 6109477Sandreas.hansson@arm.com # avoid empty string on RHS of arrow 61112563Sgabeblack@google.com sep_idx = com_pfx.rfind(".") 61212563Sgabeblack@google.com if sep_idx != -1: 61312563Sgabeblack@google.com com_pfx = com_pfx[0:sep_idx] 6149396Sandreas.hansson@arm.com else: 6152667Sstever@eecs.umich.edu com_pfx = '' 61610710Sandreas.hansson@arm.com elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 61710710Sandreas.hansson@arm.com # still splitting at file extension: ok 61810710Sandreas.hansson@arm.com pass 61911811Sbaz21@cam.ac.uk else: 62011811Sbaz21@cam.ac.uk # probably a fluke; ignore it 62111811Sbaz21@cam.ac.uk com_pfx = '' 62211811Sbaz21@cam.ac.uk # recalculate length in case com_pfx was modified 62311811Sbaz21@cam.ac.uk com_pfx_len = len(com_pfx) 62411811Sbaz21@cam.ac.uk def fmt(files): 62510710Sandreas.hansson@arm.com f = map(lambda s: s[com_pfx_len:], files) 62610710Sandreas.hansson@arm.com return ', '.join(f) 62710710Sandreas.hansson@arm.com return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 62810710Sandreas.hansson@arm.com 62910384SCurtis.Dunham@arm.comExport('Transform') 6309986Sandreas@sandberg.pp.se 6319986Sandreas@sandberg.pp.se# enable the regression script to use the termcap 6329986Sandreas@sandberg.pp.semain['TERMCAP'] = termcap 6339986Sandreas@sandberg.pp.se 6349986Sandreas@sandberg.pp.seif GetOption('verbose'): 6359986Sandreas@sandberg.pp.se def MakeAction(action, string, *args, **kwargs): 6369986Sandreas@sandberg.pp.se return Action(action, *args, **kwargs) 6379986Sandreas@sandberg.pp.seelse: 6389986Sandreas@sandberg.pp.se MakeAction = Action 6399986Sandreas@sandberg.pp.se main['CCCOMSTR'] = Transform("CC") 6409986Sandreas@sandberg.pp.se main['CXXCOMSTR'] = Transform("CXX") 6419986Sandreas@sandberg.pp.se main['ASCOMSTR'] = Transform("AS") 6429986Sandreas@sandberg.pp.se main['ARCOMSTR'] = Transform("AR", 0) 6439986Sandreas@sandberg.pp.se main['LINKCOMSTR'] = Transform("LINK", 0) 6449986Sandreas@sandberg.pp.se main['SHLINKCOMSTR'] = Transform("SHLINK", 0) 6459986Sandreas@sandberg.pp.se main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 6469986Sandreas@sandberg.pp.se main['M4COMSTR'] = Transform("M4") 6479986Sandreas@sandberg.pp.se main['SHCCCOMSTR'] = Transform("SHCC") 6489986Sandreas@sandberg.pp.se main['SHCXXCOMSTR'] = Transform("SHCXX") 6499986Sandreas@sandberg.pp.seExport('MakeAction') 6502638Sstever@eecs.umich.edu 6512638Sstever@eecs.umich.edu# Initialize the Link-Time Optimization (LTO) flags 6526121Snate@binkert.orgmain['LTO_CCFLAGS'] = [] 6533716Sstever@eecs.umich.edumain['LTO_LDFLAGS'] = [] 6545522Snate@binkert.org 6559986Sandreas@sandberg.pp.se# According to the readme, tcmalloc works best if the compiler doesn't 6569986Sandreas@sandberg.pp.se# assume that we're using the builtin malloc and friends. These flags 6579986Sandreas@sandberg.pp.se# are compiler-specific, so we need to set them after we detect which 6585522Snate@binkert.org# compiler we're using. 6595227Ssaidi@eecs.umich.edumain['TCMALLOC_CCFLAGS'] = [] 6605227Ssaidi@eecs.umich.edu 6615227Ssaidi@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 6625227Ssaidi@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 6636654Snate@binkert.org 6646654Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 6657769SAli.Saidi@ARM.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 6667769SAli.Saidi@ARM.comif main['GCC'] + main['CLANG'] > 1: 6677769SAli.Saidi@ARM.com print 'Error: How can we have two at the same time?' 6687769SAli.Saidi@ARM.com Exit(1) 6695227Ssaidi@eecs.umich.edu 6705227Ssaidi@eecs.umich.edu# Set up default C++ compiler flags 6715227Ssaidi@eecs.umich.eduif main['GCC'] or main['CLANG']: 6725204Sstever@gmail.com # As gcc and clang share many flags, do the common parts here 6735204Sstever@gmail.com main.Append(CCFLAGS=['-pipe']) 6745204Sstever@gmail.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 6755204Sstever@gmail.com # Enable -Wall and -Wextra and then disable the few warnings that 6765204Sstever@gmail.com # we consistently violate 6775204Sstever@gmail.com main.Append(CCFLAGS=['-Wall', '-Wundef', '-Wextra', 6785204Sstever@gmail.com '-Wno-sign-compare', '-Wno-unused-parameter']) 6795204Sstever@gmail.com # We always compile using C++11 6805204Sstever@gmail.com main.Append(CXXFLAGS=['-std=c++11']) 6815204Sstever@gmail.com if sys.platform.startswith('freebsd'): 6825204Sstever@gmail.com main.Append(CCFLAGS=['-I/usr/local/include']) 6835204Sstever@gmail.com main.Append(CXXFLAGS=['-I/usr/local/include']) 6845204Sstever@gmail.com 6855204Sstever@gmail.com main['FILTER_PSHLINKFLAGS'] = lambda x: str(x).replace(' -shared', '') 6865204Sstever@gmail.com main['PSHLINKFLAGS'] = main.subst('${FILTER_PSHLINKFLAGS(SHLINKFLAGS)}') 6875204Sstever@gmail.com main['PLINKFLAGS'] = main.subst('${LINKFLAGS}') 6885204Sstever@gmail.com shared_partial_flags = ['-r', '-nostdlib'] 6896121Snate@binkert.org main.Append(PSHLINKFLAGS=shared_partial_flags) 6905204Sstever@gmail.com main.Append(PLINKFLAGS=shared_partial_flags) 6917727SAli.Saidi@ARM.comelse: 6927727SAli.Saidi@ARM.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 69312563Sgabeblack@google.com print "Don't know what compiler options to use for your compiler." 6947727SAli.Saidi@ARM.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 6957727SAli.Saidi@ARM.com print termcap.Yellow + ' version:' + termcap.Normal, 69611988Sandreas.sandberg@arm.com if not CXX_version: 69711988Sandreas.sandberg@arm.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 69810453SAndrew.Bardsley@arm.com termcap.Normal 69910453SAndrew.Bardsley@arm.com else: 70010453SAndrew.Bardsley@arm.com print CXX_version.replace('\n', '<nl>') 70110453SAndrew.Bardsley@arm.com print " If you're trying to use a compiler other than GCC" 70210453SAndrew.Bardsley@arm.com print " or clang, there appears to be something wrong with your" 70310453SAndrew.Bardsley@arm.com print " environment." 70410453SAndrew.Bardsley@arm.com print " " 70510453SAndrew.Bardsley@arm.com print " If you are trying to use a compiler other than those listed" 70610453SAndrew.Bardsley@arm.com print " above you will need to ease fix SConstruct and " 70710453SAndrew.Bardsley@arm.com print " src/SConscript to support that compiler." 70810160Sandreas.hansson@arm.com Exit(1) 70910453SAndrew.Bardsley@arm.com 71010453SAndrew.Bardsley@arm.comif main['GCC']: 71110453SAndrew.Bardsley@arm.com # Check for a supported version of gcc. >= 4.8 is chosen for its 71210453SAndrew.Bardsley@arm.com # level of c++11 support. See 71310453SAndrew.Bardsley@arm.com # http://gcc.gnu.org/projects/cxx0x.html for details. 71413541Sandrea.mondelli@ucf.edu gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 71510453SAndrew.Bardsley@arm.com if compareVersions(gcc_version, "4.8") < 0: 71610453SAndrew.Bardsley@arm.com print 'Error: gcc version 4.8 or newer required.' 71713541Sandrea.mondelli@ucf.edu print ' Installed version:', gcc_version 71813541Sandrea.mondelli@ucf.edu Exit(1) 7199812Sandreas.hansson@arm.com 72010453SAndrew.Bardsley@arm.com main['GCC_VERSION'] = gcc_version 72110453SAndrew.Bardsley@arm.com 72210453SAndrew.Bardsley@arm.com # gcc from version 4.8 and above generates "rep; ret" instructions 72310453SAndrew.Bardsley@arm.com # to avoid performance penalties on certain AMD chips. Older 72410453SAndrew.Bardsley@arm.com # assemblers detect this as an error, "Error: expecting string 72510453SAndrew.Bardsley@arm.com # instruction after `rep'" 72610453SAndrew.Bardsley@arm.com as_version_raw = readCommand([main['AS'], '-v', '/dev/null', 72710453SAndrew.Bardsley@arm.com '-o', '/dev/null'], 72810453SAndrew.Bardsley@arm.com exception=False).split() 72910453SAndrew.Bardsley@arm.com 73010453SAndrew.Bardsley@arm.com # version strings may contain extra distro-specific 73110453SAndrew.Bardsley@arm.com # qualifiers, so play it safe and keep only what comes before 7327727SAli.Saidi@ARM.com # the first hyphen 73310453SAndrew.Bardsley@arm.com as_version = as_version_raw[-1].split('-')[0] if as_version_raw else None 73410453SAndrew.Bardsley@arm.com 73512790Smatteo.fusi@bsc.es if not as_version or compareVersions(as_version, "2.23") < 0: 73612790Smatteo.fusi@bsc.es print termcap.Yellow + termcap.Bold + \ 73712790Smatteo.fusi@bsc.es 'Warning: This combination of gcc and binutils have' + \ 73812790Smatteo.fusi@bsc.es ' known incompatibilities.\n' + \ 73912790Smatteo.fusi@bsc.es ' If you encounter build problems, please update ' + \ 74012790Smatteo.fusi@bsc.es 'binutils to 2.23.' + \ 74112790Smatteo.fusi@bsc.es termcap.Normal 74210453SAndrew.Bardsley@arm.com 7433118Sstever@eecs.umich.edu # Make sure we warn if the user has requested to compile with the 74410453SAndrew.Bardsley@arm.com # Undefined Benahvior Sanitizer and this version of gcc does not 74510453SAndrew.Bardsley@arm.com # support it. 74612563Sgabeblack@google.com if GetOption('with_ubsan') and \ 74710453SAndrew.Bardsley@arm.com compareVersions(gcc_version, '4.9') < 0: 7483118Sstever@eecs.umich.edu print termcap.Yellow + termcap.Bold + \ 7493483Ssaidi@eecs.umich.edu 'Warning: UBSan is only supported using gcc 4.9 and later.' + \ 7503494Ssaidi@eecs.umich.edu termcap.Normal 7513494Ssaidi@eecs.umich.edu 75212563Sgabeblack@google.com # Add the appropriate Link-Time Optimization (LTO) flags 7533483Ssaidi@eecs.umich.edu # unless LTO is explicitly turned off. Note that these flags 7543483Ssaidi@eecs.umich.edu # are only used by the fast target. 7553053Sstever@eecs.umich.edu if not GetOption('no_lto'): 7563053Sstever@eecs.umich.edu # Pass the LTO flag when compiling to produce GIMPLE 7573918Ssaidi@eecs.umich.edu # output, we merely create the flags here and only append 75812563Sgabeblack@google.com # them later 75912563Sgabeblack@google.com main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 76012563Sgabeblack@google.com 7613053Sstever@eecs.umich.edu # Use the same amount of jobs for LTO as we are running 7623053Sstever@eecs.umich.edu # scons with 7639396Sandreas.hansson@arm.com main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 7649396Sandreas.hansson@arm.com 7659396Sandreas.hansson@arm.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 7669396Sandreas.hansson@arm.com '-fno-builtin-realloc', '-fno-builtin-free']) 7679396Sandreas.hansson@arm.com 7689396Sandreas.hansson@arm.com # add option to check for undeclared overrides 7699396Sandreas.hansson@arm.com if compareVersions(gcc_version, "5.0") > 0: 7709396Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-error=suggest-override']) 7719396Sandreas.hansson@arm.com 77212920Sgabeblack@google.comelif main['CLANG']: 77312920Sgabeblack@google.com # Check for a supported version of clang, >= 3.1 is needed to 77412920Sgabeblack@google.com # support similar features as gcc 4.8. See 77512920Sgabeblack@google.com # http://clang.llvm.org/cxx_status.html for details 7769477Sandreas.hansson@arm.com clang_version_re = re.compile(".* version (\d+\.\d+)") 7779396Sandreas.hansson@arm.com clang_version_match = clang_version_re.search(CXX_version) 77812563Sgabeblack@google.com if (clang_version_match): 77912563Sgabeblack@google.com clang_version = clang_version_match.groups()[0] 78012563Sgabeblack@google.com if compareVersions(clang_version, "3.1") < 0: 78112563Sgabeblack@google.com print 'Error: clang version 3.1 or newer required.' 7829396Sandreas.hansson@arm.com print ' Installed version:', clang_version 7837840Snate@binkert.org Exit(1) 7847865Sgblack@eecs.umich.edu else: 7857865Sgblack@eecs.umich.edu print 'Error: Unable to determine clang version.' 7867865Sgblack@eecs.umich.edu Exit(1) 7877865Sgblack@eecs.umich.edu 7887865Sgblack@eecs.umich.edu # clang has a few additional warnings that we disable, extraneous 7897840Snate@binkert.org # parantheses are allowed due to Ruby's printing of the AST, 7909900Sandreas@sandberg.pp.se # finally self assignments are allowed as the generated CPU code 7919900Sandreas@sandberg.pp.se # is relying on this 7929900Sandreas@sandberg.pp.se main.Append(CCFLAGS=['-Wno-parentheses', 7939900Sandreas@sandberg.pp.se '-Wno-self-assign', 79410456SCurtis.Dunham@arm.com # Some versions of libstdc++ (4.8?) seem to 79510456SCurtis.Dunham@arm.com # use struct hash and class hash 79610456SCurtis.Dunham@arm.com # interchangeably. 79710456SCurtis.Dunham@arm.com '-Wno-mismatched-tags', 79810456SCurtis.Dunham@arm.com ]) 79910456SCurtis.Dunham@arm.com 80012563Sgabeblack@google.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 80112563Sgabeblack@google.com 80212563Sgabeblack@google.com # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 80312563Sgabeblack@google.com # opposed to libstdc++, as the later is dated. 8049045SAli.Saidi@ARM.com if sys.platform == "darwin": 80511235Sandreas.sandberg@arm.com main.Append(CXXFLAGS=['-stdlib=libc++']) 80611235Sandreas.sandberg@arm.com main.Append(LIBS=['c++']) 80711235Sandreas.sandberg@arm.com 80811235Sandreas.sandberg@arm.com # On FreeBSD we need libthr. 80911235Sandreas.sandberg@arm.com if sys.platform.startswith('freebsd'): 81012485Sjang.hanhwi@gmail.com main.Append(LIBS=['thr']) 81112485Sjang.hanhwi@gmail.com 81212485Sjang.hanhwi@gmail.comelse: 81311235Sandreas.sandberg@arm.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 81411811Sbaz21@cam.ac.uk print "Don't know what compiler options to use for your compiler." 81512485Sjang.hanhwi@gmail.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 81611811Sbaz21@cam.ac.uk print termcap.Yellow + ' version:' + termcap.Normal, 81711811Sbaz21@cam.ac.uk if not CXX_version: 81811811Sbaz21@cam.ac.uk print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 81911235Sandreas.sandberg@arm.com termcap.Normal 82011235Sandreas.sandberg@arm.com else: 82111235Sandreas.sandberg@arm.com print CXX_version.replace('\n', '<nl>') 82212563Sgabeblack@google.com print " If you're trying to use a compiler other than GCC" 82312563Sgabeblack@google.com print " or clang, there appears to be something wrong with your" 82412563Sgabeblack@google.com print " environment." 82511235Sandreas.sandberg@arm.com print " " 8267840Snate@binkert.org print " If you are trying to use a compiler other than those listed" 82712563Sgabeblack@google.com print " above you will need to ease fix SConstruct and " 8287840Snate@binkert.org print " src/SConscript to support that compiler." 8291858SN/A Exit(1) 8301858SN/A 8311858SN/A# Set up common yacc/bison flags (needed for Ruby) 83212563Sgabeblack@google.commain['YACCFLAGS'] = '-d' 83312563Sgabeblack@google.commain['YACCHXXFILESUFFIX'] = '.hh' 8341858SN/A 83512230Sgiacomo.travaglini@arm.com# Do this after we save setting back, or else we'll tack on an 83612230Sgiacomo.travaglini@arm.com# extra 'qdo' every time we run scons. 83712230Sgiacomo.travaglini@arm.comif main['BATCH']: 83812230Sgiacomo.travaglini@arm.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 83912563Sgabeblack@google.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 84012563Sgabeblack@google.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 84112563Sgabeblack@google.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 84212230Sgiacomo.travaglini@arm.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 8439903Sandreas.hansson@arm.com 8449903Sandreas.hansson@arm.comif sys.platform == 'cygwin': 8459903Sandreas.hansson@arm.com # cygwin has some header file issues... 8469903Sandreas.hansson@arm.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 84710841Sandreas.sandberg@arm.com 8489651SAndreas.Sandberg@ARM.com# Check for the protobuf compiler 84912563Sgabeblack@google.comprotoc_version = readCommand([main['PROTOC'], '--version'], 85012563Sgabeblack@google.com exception='').split() 8519651SAndreas.Sandberg@ARM.com 85212056Sgabeblack@google.com# First two words should be "libprotoc x.y.z" 85312056Sgabeblack@google.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 85412056Sgabeblack@google.com print termcap.Yellow + termcap.Bold + \ 85512563Sgabeblack@google.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + \ 85612056Sgabeblack@google.com ' Please install protobuf-compiler for tracing support.' + \ 85710841Sandreas.sandberg@arm.com termcap.Normal 85810841Sandreas.sandberg@arm.com main['PROTOC'] = False 85910841Sandreas.sandberg@arm.comelse: 86010841Sandreas.sandberg@arm.com # Based on the availability of the compress stream wrappers, 86110841Sandreas.sandberg@arm.com # require 2.1.0 86210841Sandreas.sandberg@arm.com min_protoc_version = '2.1.0' 8639651SAndreas.Sandberg@ARM.com if compareVersions(protoc_version[1], min_protoc_version) < 0: 8649651SAndreas.Sandberg@ARM.com print termcap.Yellow + termcap.Bold + \ 8659651SAndreas.Sandberg@ARM.com 'Warning: protoc version', min_protoc_version, \ 8669651SAndreas.Sandberg@ARM.com 'or newer required.\n' + \ 8679651SAndreas.Sandberg@ARM.com ' Installed version:', protoc_version[1], \ 8689651SAndreas.Sandberg@ARM.com termcap.Normal 86912563Sgabeblack@google.com main['PROTOC'] = False 8709651SAndreas.Sandberg@ARM.com else: 8719651SAndreas.Sandberg@ARM.com # Attempt to determine the appropriate include path and 87210841Sandreas.sandberg@arm.com # library path using pkg-config, that means we also need to 87312563Sgabeblack@google.com # check for pkg-config. Note that it is possible to use 87412563Sgabeblack@google.com # protobuf without the involvement of pkg-config. Later on we 87510841Sandreas.sandberg@arm.com # check go a library config check and at that point the test 87610841Sandreas.sandberg@arm.com # will fail if libprotobuf cannot be found. 87710841Sandreas.sandberg@arm.com if readCommand(['pkg-config', '--version'], exception=''): 87810860Sandreas.sandberg@arm.com try: 87910841Sandreas.sandberg@arm.com # Attempt to establish what linking flags to add for protobuf 88010841Sandreas.sandberg@arm.com # using pkg-config 88110841Sandreas.sandberg@arm.com main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 88210841Sandreas.sandberg@arm.com except: 88310841Sandreas.sandberg@arm.com print termcap.Yellow + termcap.Bold + \ 88412563Sgabeblack@google.com 'Warning: pkg-config could not get protobuf flags.' + \ 88510841Sandreas.sandberg@arm.com termcap.Normal 88610841Sandreas.sandberg@arm.com 88710841Sandreas.sandberg@arm.com 88810841Sandreas.sandberg@arm.com# Check for 'timeout' from GNU coreutils. If present, regressions will 88910841Sandreas.sandberg@arm.com# be run with a time limit. We require version 8.13 since we rely on 8909651SAndreas.Sandberg@ARM.com# support for the '--foreground' option. 8919651SAndreas.Sandberg@ARM.comif sys.platform.startswith('freebsd'): 8929986Sandreas@sandberg.pp.se timeout_lines = readCommand(['gtimeout', '--version'], 8939986Sandreas@sandberg.pp.se exception='').splitlines() 8949986Sandreas@sandberg.pp.seelse: 8959986Sandreas@sandberg.pp.se timeout_lines = readCommand(['timeout', '--version'], 8969986Sandreas@sandberg.pp.se exception='').splitlines() 8979986Sandreas@sandberg.pp.se# Get the first line and tokenize it 8985863Snate@binkert.orgtimeout_version = timeout_lines[0].split() if timeout_lines else [] 8995863Snate@binkert.orgmain['TIMEOUT'] = timeout_version and \ 9005863Snate@binkert.org compareVersions(timeout_version[-1], '8.13') >= 0 9015863Snate@binkert.org 9026121Snate@binkert.org# Add a custom Check function to test for structure members. 9031858SN/Adef CheckMember(context, include, decl, member, include_quotes="<>"): 9045863Snate@binkert.org context.Message("Checking for member %s in %s..." % 9055863Snate@binkert.org (member, decl)) 9065863Snate@binkert.org text = """ 9075863Snate@binkert.org#include %(header)s 9085863Snate@binkert.orgint main(){ 9092139SN/A %(decl)s test; 9104202Sbinkertn@umich.edu (void)test.%(member)s; 91111308Santhony.gutierrez@amd.com return 0; 9124202Sbinkertn@umich.edu}; 91311308Santhony.gutierrez@amd.com""" % { "header" : include_quotes[0] + include + include_quotes[1], 9142139SN/A "decl" : decl, 9156994Snate@binkert.org "member" : member, 9166994Snate@binkert.org } 9176994Snate@binkert.org 9186994Snate@binkert.org ret = context.TryCompile(text, extension=".cc") 9196994Snate@binkert.org context.Result(ret) 9206994Snate@binkert.org return ret 9216994Snate@binkert.org 9226994Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 92310319SAndreas.Sandberg@ARM.com# builds under a given build root run on the same host platform. 9246994Snate@binkert.orgconf = Configure(main, 9256994Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 9266994Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 9276994Snate@binkert.org custom_tests = { 9286994Snate@binkert.org 'CheckMember' : CheckMember, 9296994Snate@binkert.org }) 9306994Snate@binkert.org 9316994Snate@binkert.org# Check if we should compile a 64 bit binary on Mac OS X/Darwin 9326994Snate@binkert.orgtry: 9336994Snate@binkert.org import platform 9346994Snate@binkert.org uname = platform.uname() 9352155SN/A if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 9365863Snate@binkert.org if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 9371869SN/A main.Append(CCFLAGS=['-arch', 'x86_64']) 9381869SN/A main.Append(CFLAGS=['-arch', 'x86_64']) 9395863Snate@binkert.org main.Append(LINKFLAGS=['-arch', 'x86_64']) 9405863Snate@binkert.org main.Append(ASFLAGS=['-arch', 'x86_64']) 9414202Sbinkertn@umich.eduexcept: 9426108Snate@binkert.org pass 9436108Snate@binkert.org 9446108Snate@binkert.org# Recent versions of scons substitute a "Null" object for Configure() 9456108Snate@binkert.org# when configuration isn't necessary, e.g., if the "--help" option is 9469219Spower.jg@gmail.com# present. Unfortuantely this Null object always returns false, 9479219Spower.jg@gmail.com# breaking all our configuration checks. We replace it with our own 9489219Spower.jg@gmail.com# more optimistic null object that returns True instead. 9499219Spower.jg@gmail.comif not conf: 9509219Spower.jg@gmail.com def NullCheck(*args, **kwargs): 9519219Spower.jg@gmail.com return True 9529219Spower.jg@gmail.com 9539219Spower.jg@gmail.com class NullConf: 9544202Sbinkertn@umich.edu def __init__(self, env): 9555863Snate@binkert.org self.env = env 95610135SCurtis.Dunham@arm.com def Finish(self): 95712563Sgabeblack@google.com return self.env 9585742Snate@binkert.org def __getattr__(self, mname): 9598268Ssteve.reinhardt@amd.com return NullCheck 96012563Sgabeblack@google.com 9618268Ssteve.reinhardt@amd.com conf = NullConf(main) 9625742Snate@binkert.org 9635341Sstever@gmail.com# Cache build files in the supplied directory. 9648474Sgblack@eecs.umich.eduif main['M5_BUILD_CACHE']: 96512563Sgabeblack@google.com print 'Using build cache located at', main['M5_BUILD_CACHE'] 9665342Sstever@gmail.com CacheDir(main['M5_BUILD_CACHE']) 9674202Sbinkertn@umich.edu 9684202Sbinkertn@umich.edumain['USE_PYTHON'] = not GetOption('without_python') 96911308Santhony.gutierrez@amd.comif main['USE_PYTHON']: 9704202Sbinkertn@umich.edu # Find Python include and library directories for embedding the 9715863Snate@binkert.org # interpreter. We rely on python-config to resolve the appropriate 9725863Snate@binkert.org # includes and linker flags. ParseConfig does not seem to understand 97311308Santhony.gutierrez@amd.com # the more exotic linker flags such as -Xlinker and -export-dynamic so 9746994Snate@binkert.org # we add them explicitly below. If you want to link in an alternate 9756994Snate@binkert.org # version of python, see above for instructions on how to invoke 97610319SAndreas.Sandberg@ARM.com # scons with the appropriate PATH set. 9775863Snate@binkert.org # 9785863Snate@binkert.org # First we check if python2-config exists, else we use python-config 9795863Snate@binkert.org python_config = readCommand(['which', 'python2-config'], 9805863Snate@binkert.org exception='').strip() 9815863Snate@binkert.org if not os.path.exists(python_config): 9825863Snate@binkert.org python_config = readCommand(['which', 'python-config'], 9835863Snate@binkert.org exception='').strip() 9845863Snate@binkert.org py_includes = readCommand([python_config, '--includes'], 9857840Snate@binkert.org exception='').split() 9865863Snate@binkert.org # Strip the -I from the include folders before adding them to the 98712230Sgiacomo.travaglini@arm.com # CPPPATH 98812230Sgiacomo.travaglini@arm.com main.Append(CPPPATH=map(lambda inc: inc[2:], py_includes)) 98912230Sgiacomo.travaglini@arm.com 99012230Sgiacomo.travaglini@arm.com # Read the linker flags and split them into libraries and other link 99112230Sgiacomo.travaglini@arm.com # flags. The libraries are added later through the call the CheckLib. 99212056Sgabeblack@google.com py_ld_flags = readCommand([python_config, '--ldflags'], 99312056Sgabeblack@google.com exception='').split() 99412056Sgabeblack@google.com py_libs = [] 99511308Santhony.gutierrez@amd.com for lib in py_ld_flags: 9969219Spower.jg@gmail.com if not lib.startswith('-l'): 9979219Spower.jg@gmail.com main.Append(LINKFLAGS=[lib]) 99811235Sandreas.sandberg@arm.com else: 99911235Sandreas.sandberg@arm.com lib = lib[2:] 10001869SN/A if lib not in py_libs: 10011858SN/A py_libs.append(lib) 10025863Snate@binkert.org 100311308Santhony.gutierrez@amd.com # verify that this stuff works 100412061Sjason@lowepower.com if not conf.CheckHeader('Python.h', '<>'): 100512920Sgabeblack@google.com print "Error: can't find Python.h header in", py_includes 100612920Sgabeblack@google.com print "Install Python headers (package python-dev on Ubuntu and RedHat)" 10071858SN/A Exit(1) 1008955SN/A 1009955SN/A for lib in py_libs: 10101869SN/A if not conf.CheckLib(lib): 10111869SN/A print "Error: can't find library %s required by python" % lib 10121869SN/A Exit(1) 10131869SN/A 10141869SN/A# On Solaris you need to use libsocket for socket ops 10155863Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 10165863Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 10175863Snate@binkert.org print "Can't find library with socket calls (e.g. accept())" 10181869SN/A Exit(1) 10195863Snate@binkert.org 10201869SN/A# Check for zlib. If the check passes, libz will be automatically 102112563Sgabeblack@google.com# added to the LIBS environment variable. 10221869SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 10231869SN/A print 'Error: did not find needed zlib compression library '\ 10241869SN/A 'and/or zlib.h header file.' 10251869SN/A print ' Please install zlib and try again.' 10268483Sgblack@eecs.umich.edu Exit(1) 10271869SN/A 10281869SN/A# If we have the protobuf compiler, also make sure we have the 10291869SN/A# development libraries. If the check passes, libprotobuf will be 10301869SN/A# automatically added to the LIBS environment variable. After 10315863Snate@binkert.org# this, we can use the HAVE_PROTOBUF flag to determine if we have 10325863Snate@binkert.org# got both protoc and libprotobuf available. 10331869SN/Amain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 10345863Snate@binkert.org conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 10355863Snate@binkert.org 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 10363356Sbinkertn@umich.edu 10373356Sbinkertn@umich.edu# If we have the compiler but not the library, print another warning. 10383356Sbinkertn@umich.eduif main['PROTOC'] and not main['HAVE_PROTOBUF']: 10393356Sbinkertn@umich.edu print termcap.Yellow + termcap.Bold + \ 10403356Sbinkertn@umich.edu 'Warning: did not find protocol buffer library and/or headers.\n' + \ 10414781Snate@binkert.org ' Please install libprotobuf-dev for tracing support.' + \ 10425863Snate@binkert.org termcap.Normal 10435863Snate@binkert.org 10441869SN/A# Check for librt. 10451869SN/Ahave_posix_clock = \ 10461869SN/A conf.CheckLibWithHeader(None, 'time.h', 'C', 10476121Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') or \ 10481869SN/A conf.CheckLibWithHeader('rt', 'time.h', 'C', 104911982Sgabeblack@google.com 'clock_nanosleep(0,0,NULL,NULL);') 105011982Sgabeblack@google.com 105111982Sgabeblack@google.comhave_posix_timers = \ 105211982Sgabeblack@google.com conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', 105311982Sgabeblack@google.com 'timer_create(CLOCK_MONOTONIC, NULL, NULL);') 105411982Sgabeblack@google.com 105511982Sgabeblack@google.comif not GetOption('without_tcmalloc'): 105611982Sgabeblack@google.com if conf.CheckLib('tcmalloc'): 105711982Sgabeblack@google.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 105811982Sgabeblack@google.com elif conf.CheckLib('tcmalloc_minimal'): 105911982Sgabeblack@google.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 106011982Sgabeblack@google.com else: 106111982Sgabeblack@google.com print termcap.Yellow + termcap.Bold + \ 106211982Sgabeblack@google.com "You can get a 12% performance improvement by "\ 106311982Sgabeblack@google.com "installing tcmalloc (libgoogle-perftools-dev package "\ 106411982Sgabeblack@google.com "on Ubuntu or RedHat)." + termcap.Normal 106511982Sgabeblack@google.com 106611982Sgabeblack@google.com 106711982Sgabeblack@google.com# Detect back trace implementations. The last implementation in the 106811982Sgabeblack@google.com# list will be used by default. 106911982Sgabeblack@google.combacktrace_impls = [ "none" ] 107011982Sgabeblack@google.com 107111982Sgabeblack@google.comif conf.CheckLibWithHeader(None, 'execinfo.h', 'C', 107211982Sgabeblack@google.com 'backtrace_symbols_fd((void*)0, 0, 0);'): 107311982Sgabeblack@google.com backtrace_impls.append("glibc") 107411982Sgabeblack@google.comelif conf.CheckLibWithHeader('execinfo', 'execinfo.h', 'C', 107513706Sgabeblack@google.com 'backtrace_symbols_fd((void*)0, 0, 0);'): 107613706Sgabeblack@google.com # NetBSD and FreeBSD need libexecinfo. 107713706Sgabeblack@google.com backtrace_impls.append("glibc") 107813706Sgabeblack@google.com main.Append(LIBS=['execinfo']) 107913706Sgabeblack@google.com 108013706Sgabeblack@google.comif backtrace_impls[-1] == "none": 108113706Sgabeblack@google.com default_backtrace_impl = "none" 108213706Sgabeblack@google.com print termcap.Yellow + termcap.Bold + \ 108313706Sgabeblack@google.com "No suitable back trace implementation found." + \ 108413706Sgabeblack@google.com termcap.Normal 108513706Sgabeblack@google.com 108613706Sgabeblack@google.comif not have_posix_clock: 108713706Sgabeblack@google.com print "Can't find library for POSIX clocks." 108813706Sgabeblack@google.com 108913706Sgabeblack@google.com# Check for <fenv.h> (C99 FP environment control) 109013706Sgabeblack@google.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 109113706Sgabeblack@google.comif not have_fenv: 109213706Sgabeblack@google.com print "Warning: Header file <fenv.h> not found." 109313713SAndrea.Mondelli@ucf.edu print " This host has no IEEE FP rounding mode control." 109413713SAndrea.Mondelli@ucf.edu 109513713SAndrea.Mondelli@ucf.edu# Check if we should enable KVM-based hardware virtualization. The API 109613706Sgabeblack@google.com# we rely on exists since version 2.6.36 of the kernel, but somehow 109713706Sgabeblack@google.com# the KVM_API_VERSION does not reflect the change. We test for one of 109811978Sgabeblack@google.com# the types as a fall back. 109911978Sgabeblack@google.comhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 110012034Sgabeblack@google.comif not have_kvm: 110111978Sgabeblack@google.com print "Info: Compatible header file <linux/kvm.h> not found, " \ 110211978Sgabeblack@google.com "disabling KVM support." 110311978Sgabeblack@google.com 110412034Sgabeblack@google.com# Check if the TUN/TAP driver is available. 110511978Sgabeblack@google.comhave_tuntap = conf.CheckHeader('linux/if_tun.h', '<>') 110611978Sgabeblack@google.comif not have_tuntap: 110710915Sandreas.sandberg@arm.com print "Info: Compatible header file <linux/if_tun.h> not found." 110813577Sciro.santilli@arm.com 110913577Sciro.santilli@arm.com# x86 needs support for xsave. We test for the structure here since we 111013577Sciro.santilli@arm.com# won't be able to run new tests by the time we know which ISA we're 111111986Sandreas.sandberg@arm.com# targeting. 111211986Sandreas.sandberg@arm.comhave_kvm_xsave = conf.CheckTypeSize('struct kvm_xsave', 11131869SN/A '#include <linux/kvm.h>') != 0 11141869SN/A 111512015Sgabeblack@google.com# Check if the requested target ISA is compatible with the host 111612015Sgabeblack@google.comdef is_isa_kvm_compatible(isa): 111712015Sgabeblack@google.com try: 111812015Sgabeblack@google.com import platform 11193546Sgblack@eecs.umich.edu host_isa = platform.machine() 11203546Sgblack@eecs.umich.edu except: 11213546Sgblack@eecs.umich.edu print "Warning: Failed to determine host ISA." 112212015Sgabeblack@google.com return False 112312015Sgabeblack@google.com 112412015Sgabeblack@google.com if not have_posix_timers: 112512015Sgabeblack@google.com print "Warning: Can not enable KVM, host seems to lack support " \ 112612015Sgabeblack@google.com "for POSIX timers" 112712015Sgabeblack@google.com return False 112812015Sgabeblack@google.com 112912563Sgabeblack@google.com if isa == "arm": 11303546Sgblack@eecs.umich.edu return host_isa in ( "armv7l", "aarch64" ) 113112015Sgabeblack@google.com elif isa == "x86": 113212015Sgabeblack@google.com if host_isa != "x86_64": 113310196SCurtis.Dunham@arm.com return False 113412015Sgabeblack@google.com 113512015Sgabeblack@google.com if not have_kvm_xsave: 113612015Sgabeblack@google.com print "KVM on x86 requires xsave support in kernel headers." 113712015Sgabeblack@google.com return False 113812015Sgabeblack@google.com 113912015Sgabeblack@google.com return True 114012015Sgabeblack@google.com else: 114112015Sgabeblack@google.com return False 114212015Sgabeblack@google.com 114312015Sgabeblack@google.com 114412015Sgabeblack@google.com# Check if the exclude_host attribute is available. We want this to 11453546Sgblack@eecs.umich.edu# get accurate instruction counts in KVM. 11463546Sgblack@eecs.umich.edumain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember( 11473546Sgblack@eecs.umich.edu 'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host') 1148955SN/A 1149955SN/A 1150955SN/A###################################################################### 1151955SN/A# 11525863Snate@binkert.org# Finish the configuration 115310135SCurtis.Dunham@arm.com# 115412563Sgabeblack@google.commain = conf.Finish() 11555343Sstever@gmail.com 11565343Sstever@gmail.com###################################################################### 11576121Snate@binkert.org# 11585863Snate@binkert.org# Collect all non-global variables 11594773Snate@binkert.org# 11605863Snate@binkert.org 11612632Sstever@eecs.umich.edu# Define the universe of supported ISAs 11625863Snate@binkert.orgall_isa_list = [ ] 11632023SN/Aall_gpu_isa_list = [ ] 11645863Snate@binkert.orgExport('all_isa_list') 11655863Snate@binkert.orgExport('all_gpu_isa_list') 11665863Snate@binkert.org 11675863Snate@binkert.orgclass CpuModel(object): 11685863Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 11695863Snate@binkert.org know about a particular CPU model.''' 11705863Snate@binkert.org 11715863Snate@binkert.org # Dict of available CPU model objects. Accessible as CpuModel.dict. 117210135SCurtis.Dunham@arm.com dict = {} 117312563Sgabeblack@google.com 117412034Sgabeblack@google.com # Constructor. Automatically adds models to CpuModel.dict. 117512034Sgabeblack@google.com def __init__(self, name, default=False): 117612034Sgabeblack@google.com self.name = name # name of model 11772632Sstever@eecs.umich.edu 11785863Snate@binkert.org # This cpu is enabled by default 11792023SN/A self.default = default 11802632Sstever@eecs.umich.edu 11815863Snate@binkert.org # Add self to dict 11825342Sstever@gmail.com if name in CpuModel.dict: 11835863Snate@binkert.org raise AttributeError, "CpuModel '%s' already registered" % name 11842632Sstever@eecs.umich.edu CpuModel.dict[name] = self 11855863Snate@binkert.org 11865863Snate@binkert.orgExport('CpuModel') 11878267Ssteve.reinhardt@amd.com 11888120Sgblack@eecs.umich.edu# Sticky variables get saved in the variables file so they persist from 11898267Ssteve.reinhardt@amd.com# one invocation to the next (unless overridden, in which case the new 11908267Ssteve.reinhardt@amd.com# value becomes sticky). 11918267Ssteve.reinhardt@amd.comsticky_vars = Variables(args=ARGUMENTS) 11928267Ssteve.reinhardt@amd.comExport('sticky_vars') 11938267Ssteve.reinhardt@amd.com 11948267Ssteve.reinhardt@amd.com# Sticky variables that should be exported 11958267Ssteve.reinhardt@amd.comexport_vars = [] 11968267Ssteve.reinhardt@amd.comExport('export_vars') 11978267Ssteve.reinhardt@amd.com 11985863Snate@binkert.org# For Ruby 119912563Sgabeblack@google.comall_protocols = [] 120012563Sgabeblack@google.comExport('all_protocols') 12012632Sstever@eecs.umich.eduprotocol_dirs = [] 120212563Sgabeblack@google.comExport('protocol_dirs') 120312563Sgabeblack@google.comslicc_includes = [] 120412563Sgabeblack@google.comExport('slicc_includes') 12052632Sstever@eecs.umich.edu 12061888SN/A# Walk the tree and execute all SConsopts scripts that wil add to the 12075863Snate@binkert.org# above variables 12085863Snate@binkert.orgif GetOption('verbose'): 12091858SN/A print "Reading SConsopts" 12108120Sgblack@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list: 12118120Sgblack@eecs.umich.edu if not isdir(bdir): 12127756SAli.Saidi@ARM.com print "Error: directory '%s' does not exist" % bdir 12132598SN/A Exit(1) 12145863Snate@binkert.org for root, dirs, files in os.walk(bdir): 12151858SN/A if 'SConsopts' in files: 12161858SN/A if GetOption('verbose'): 121712563Sgabeblack@google.com print "Reading", joinpath(root, 'SConsopts') 121812563Sgabeblack@google.com SConscript(joinpath(root, 'SConsopts')) 12191858SN/A 12201858SN/Aall_isa_list.sort() 12211858SN/Aall_gpu_isa_list.sort() 122212563Sgabeblack@google.com 122312563Sgabeblack@google.comsticky_vars.AddVariables( 122412563Sgabeblack@google.com EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 12251858SN/A EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'hsail', all_gpu_isa_list), 122612230Sgiacomo.travaglini@arm.com ListVariable('CPU_MODELS', 'CPU models', 122712563Sgabeblack@google.com sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 122812563Sgabeblack@google.com sorted(CpuModel.dict.keys())), 122912230Sgiacomo.travaglini@arm.com BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 123012230Sgiacomo.travaglini@arm.com False), 123112230Sgiacomo.travaglini@arm.com BoolVariable('SS_COMPATIBLE_FP', 123212230Sgiacomo.travaglini@arm.com 'Make floating-point results compatible with SimpleScalar', 123312230Sgiacomo.travaglini@arm.com False), 12341858SN/A BoolVariable('USE_SSE2', 12351858SN/A 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 12361858SN/A False), 12379651SAndreas.Sandberg@ARM.com BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 12389651SAndreas.Sandberg@ARM.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 123912563Sgabeblack@google.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 124012563Sgabeblack@google.com BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm), 12419651SAndreas.Sandberg@ARM.com BoolVariable('USE_TUNTAP', 12429651SAndreas.Sandberg@ARM.com 'Enable using a tap device to bridge to the host network', 124312563Sgabeblack@google.com have_tuntap), 124412563Sgabeblack@google.com BoolVariable('BUILD_GPU', 'Build the compute-GPU model', False), 12459651SAndreas.Sandberg@ARM.com EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 12469651SAndreas.Sandberg@ARM.com all_protocols), 124712056Sgabeblack@google.com EnumVariable('BACKTRACE_IMPL', 'Post-mortem dump implementation', 124812056Sgabeblack@google.com backtrace_impls[-1], backtrace_impls) 124912563Sgabeblack@google.com ) 125012056Sgabeblack@google.com 125112056Sgabeblack@google.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 125211798Santhony.gutierrez@amd.comexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA', 125311798Santhony.gutierrez@amd.com 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'PROTOCOL', 125411798Santhony.gutierrez@amd.com 'HAVE_PROTOBUF', 'HAVE_PERF_ATTR_EXCLUDE_HOST'] 12559986Sandreas@sandberg.pp.se 12569986Sandreas@sandberg.pp.se################################################### 12579986Sandreas@sandberg.pp.se# 125812563Sgabeblack@google.com# Define a SCons builder for configuration flag headers. 125912563Sgabeblack@google.com# 126012563Sgabeblack@google.com################################################### 12619986Sandreas@sandberg.pp.se 12625863Snate@binkert.org# This function generates a config header file that #defines the 12635863Snate@binkert.org# variable symbol to the current variable setting (0 or 1). The source 12641869SN/A# operands are the name of the variable and a Value node containing the 12651965SN/A# value of the variable. 12667739Sgblack@eecs.umich.edudef build_config_file(target, source, env): 12671965SN/A (variable, value) = [s.get_contents() for s in source] 12682761Sstever@eecs.umich.edu f = file(str(target[0]), 'w') 12695863Snate@binkert.org print >> f, '#define', variable, value 12701869SN/A f.close() 127110196SCurtis.Dunham@arm.com return None 12721869SN/A 12738120Sgblack@eecs.umich.edu# Combine the two functions into a scons Action object. 12748120Sgblack@eecs.umich.educonfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 12758120Sgblack@eecs.umich.edu 12768120Sgblack@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 12778120Sgblack@eecs.umich.edu# we're really doing. 12788120Sgblack@eecs.umich.edudef config_emitter(target, source, env): 12798120Sgblack@eecs.umich.edu # extract variable name from Builder arg 12808120Sgblack@eecs.umich.edu variable = str(target[0]) 12818120Sgblack@eecs.umich.edu # True target is config header file 12828120Sgblack@eecs.umich.edu target = joinpath('config', variable.lower() + '.hh') 12838120Sgblack@eecs.umich.edu val = env[variable] 12848120Sgblack@eecs.umich.edu if isinstance(val, bool): 1285 # Force value to 0/1 1286 val = int(val) 1287 elif isinstance(val, str): 1288 val = '"' + val + '"' 1289 1290 # Sources are variable name & value (packaged in SCons Value nodes) 1291 return ([target], [Value(variable), Value(val)]) 1292 1293config_builder = Builder(emitter = config_emitter, action = config_action) 1294 1295main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 1296 1297################################################### 1298# 1299# Builders for static and shared partially linked object files. 1300# 1301################################################### 1302 1303partial_static_builder = Builder(action=SCons.Defaults.LinkAction, 1304 src_suffix='$OBJSUFFIX', 1305 src_builder=['StaticObject', 'Object'], 1306 LINKFLAGS='$PLINKFLAGS', 1307 LIBS='') 1308 1309def partial_shared_emitter(target, source, env): 1310 for tgt in target: 1311 tgt.attributes.shared = 1 1312 return (target, source) 1313partial_shared_builder = Builder(action=SCons.Defaults.ShLinkAction, 1314 emitter=partial_shared_emitter, 1315 src_suffix='$SHOBJSUFFIX', 1316 src_builder='SharedObject', 1317 SHLINKFLAGS='$PSHLINKFLAGS', 1318 LIBS='') 1319 1320main.Append(BUILDERS = { 'PartialShared' : partial_shared_builder, 1321 'PartialStatic' : partial_static_builder }) 1322 1323# builds in ext are shared across all configs in the build root. 1324ext_dir = abspath(joinpath(str(main.root), 'ext')) 1325ext_build_dirs = [] 1326for root, dirs, files in os.walk(ext_dir): 1327 if 'SConscript' in files: 1328 build_dir = os.path.relpath(root, ext_dir) 1329 ext_build_dirs.append(build_dir) 1330 main.SConscript(joinpath(root, 'SConscript'), 1331 variant_dir=joinpath(build_root, build_dir)) 1332 1333main.Prepend(CPPPATH=Dir('ext/pybind11/include/')) 1334 1335################################################### 1336# 1337# This builder and wrapper method are used to set up a directory with 1338# switching headers. Those are headers which are in a generic location and 1339# that include more specific headers from a directory chosen at build time 1340# based on the current build settings. 1341# 1342################################################### 1343 1344def build_switching_header(target, source, env): 1345 path = str(target[0]) 1346 subdir = str(source[0]) 1347 dp, fp = os.path.split(path) 1348 dp = os.path.relpath(os.path.realpath(dp), 1349 os.path.realpath(env['BUILDDIR'])) 1350 with open(path, 'w') as hdr: 1351 print >>hdr, '#include "%s/%s/%s"' % (dp, subdir, fp) 1352 1353switching_header_action = MakeAction(build_switching_header, 1354 Transform('GENERATE')) 1355 1356switching_header_builder = Builder(action=switching_header_action, 1357 source_factory=Value, 1358 single_source=True) 1359 1360main.Append(BUILDERS = { 'SwitchingHeader': switching_header_builder }) 1361 1362def switching_headers(self, headers, source): 1363 for header in headers: 1364 self.SwitchingHeader(header, source) 1365 1366main.AddMethod(switching_headers, 'SwitchingHeaders') 1367 1368# all-isas -> all-deps -> all-environs -> all_targets 1369main.Alias('#all-isas', []) 1370main.Alias('#all-deps', '#all-isas') 1371 1372# Dummy target to ensure all environments are created before telling 1373# SCons what to actually make (the command line arguments). We attach 1374# them to the dependence graph after the environments are complete. 1375ORIG_BUILD_TARGETS = list(BUILD_TARGETS) # force a copy; gets closure to work. 1376def environsComplete(target, source, env): 1377 for t in ORIG_BUILD_TARGETS: 1378 main.Depends('#all-targets', t) 1379 1380# Each build/* switching_dir attaches its *-environs target to #all-environs. 1381main.Append(BUILDERS = {'CompleteEnvirons' : 1382 Builder(action=MakeAction(environsComplete, None))}) 1383main.CompleteEnvirons('#all-environs', []) 1384 1385def doNothing(**ignored): pass 1386main.Append(BUILDERS = {'Dummy': Builder(action=MakeAction(doNothing, None))}) 1387 1388# The final target to which all the original targets ultimately get attached. 1389main.Dummy('#all-targets', '#all-environs') 1390BUILD_TARGETS[:] = ['#all-targets'] 1391 1392################################################### 1393# 1394# Define build environments for selected configurations. 1395# 1396################################################### 1397 1398def variant_name(path): 1399 return os.path.basename(path).lower().replace('_', '-') 1400main['variant_name'] = variant_name 1401main['VARIANT_NAME'] = '${variant_name(BUILDDIR)}' 1402 1403for variant_path in variant_paths: 1404 if not GetOption('silent'): 1405 print "Building in", variant_path 1406 1407 # Make a copy of the build-root environment to use for this config. 1408 env = main.Clone() 1409 env['BUILDDIR'] = variant_path 1410 1411 # variant_dir is the tail component of build path, and is used to 1412 # determine the build parameters (e.g., 'ALPHA_SE') 1413 (build_root, variant_dir) = splitpath(variant_path) 1414 1415 # Set env variables according to the build directory config. 1416 sticky_vars.files = [] 1417 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 1418 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 1419 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 1420 current_vars_file = joinpath(build_root, 'variables', variant_dir) 1421 if isfile(current_vars_file): 1422 sticky_vars.files.append(current_vars_file) 1423 if not GetOption('silent'): 1424 print "Using saved variables file %s" % current_vars_file 1425 elif variant_dir in ext_build_dirs: 1426 # Things in ext are built without a variant directory. 1427 continue 1428 else: 1429 # Build dir-specific variables file doesn't exist. 1430 1431 # Make sure the directory is there so we can create it later 1432 opt_dir = dirname(current_vars_file) 1433 if not isdir(opt_dir): 1434 mkdir(opt_dir) 1435 1436 # Get default build variables from source tree. Variables are 1437 # normally determined by name of $VARIANT_DIR, but can be 1438 # overridden by '--default=' arg on command line. 1439 default = GetOption('default') 1440 opts_dir = joinpath(main.root.abspath, 'build_opts') 1441 if default: 1442 default_vars_files = [joinpath(build_root, 'variables', default), 1443 joinpath(opts_dir, default)] 1444 else: 1445 default_vars_files = [joinpath(opts_dir, variant_dir)] 1446 existing_files = filter(isfile, default_vars_files) 1447 if existing_files: 1448 default_vars_file = existing_files[0] 1449 sticky_vars.files.append(default_vars_file) 1450 print "Variables file %s not found,\n using defaults in %s" \ 1451 % (current_vars_file, default_vars_file) 1452 else: 1453 print "Error: cannot find variables file %s or " \ 1454 "default file(s) %s" \ 1455 % (current_vars_file, ' or '.join(default_vars_files)) 1456 Exit(1) 1457 1458 # Apply current variable settings to env 1459 sticky_vars.Update(env) 1460 1461 help_texts["local_vars"] += \ 1462 "Build variables for %s:\n" % variant_dir \ 1463 + sticky_vars.GenerateHelpText(env) 1464 1465 # Process variable settings. 1466 1467 if not have_fenv and env['USE_FENV']: 1468 print "Warning: <fenv.h> not available; " \ 1469 "forcing USE_FENV to False in", variant_dir + "." 1470 env['USE_FENV'] = False 1471 1472 if not env['USE_FENV']: 1473 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 1474 print " FP results may deviate slightly from other platforms." 1475 1476 if env['EFENCE']: 1477 env.Append(LIBS=['efence']) 1478 1479 if env['USE_KVM']: 1480 if not have_kvm: 1481 print "Warning: Can not enable KVM, host seems to lack KVM support" 1482 env['USE_KVM'] = False 1483 elif not is_isa_kvm_compatible(env['TARGET_ISA']): 1484 print "Info: KVM support disabled due to unsupported host and " \ 1485 "target ISA combination" 1486 env['USE_KVM'] = False 1487 1488 if env['USE_TUNTAP']: 1489 if not have_tuntap: 1490 print "Warning: Can't connect EtherTap with a tap device." 1491 env['USE_TUNTAP'] = False 1492 1493 if env['BUILD_GPU']: 1494 env.Append(CPPDEFINES=['BUILD_GPU']) 1495 1496 # Warn about missing optional functionality 1497 if env['USE_KVM']: 1498 if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']: 1499 print "Warning: perf_event headers lack support for the " \ 1500 "exclude_host attribute. KVM instruction counts will " \ 1501 "be inaccurate." 1502 1503 # Save sticky variable settings back to current variables file 1504 sticky_vars.Save(current_vars_file, env) 1505 1506 if env['USE_SSE2']: 1507 env.Append(CCFLAGS=['-msse2']) 1508 1509 # The src/SConscript file sets up the build rules in 'env' according 1510 # to the configured variables. It returns a list of environments, 1511 # one for each variant build (debug, opt, etc.) 1512 SConscript('src/SConscript', variant_dir = variant_path, exports = 'env') 1513 1514def pairwise(iterable): 1515 "s -> (s0,s1), (s1,s2), (s2, s3), ..." 1516 a, b = itertools.tee(iterable) 1517 b.next() 1518 return itertools.izip(a, b) 1519 1520variant_names = [variant_name(path) for path in variant_paths] 1521 1522# Create false dependencies so SCons will parse ISAs, establish 1523# dependencies, and setup the build Environments serially. Either 1524# SCons (likely) and/or our SConscripts (possibly) cannot cope with -j 1525# greater than 1. It appears to be standard race condition stuff; it 1526# doesn't always fail, but usually, and the behaviors are different. 1527# Every time I tried to remove this, builds would fail in some 1528# creative new way. So, don't do that. You'll want to, though, because 1529# tests/SConscript takes a long time to make its Environments. 1530for t1, t2 in pairwise(sorted(variant_names)): 1531 main.Depends('#%s-deps' % t2, '#%s-deps' % t1) 1532 main.Depends('#%s-environs' % t2, '#%s-environs' % t1) 1533 1534# base help text 1535Help(''' 1536Usage: scons [scons options] [build variables] [target(s)] 1537 1538Extra scons options: 1539%(options)s 1540 1541Global build variables: 1542%(global_vars)s 1543 1544%(local_vars)s 1545''' % help_texts) 1546