SConstruct revision 11408
1955SN/A# -*- mode:python -*- 2955SN/A 310841Sandreas.sandberg@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 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 1155863Snate@binkert.orgimport shutil 1165863Snate@binkert.orgimport subprocess 1174202Sbinkertn@umich.eduimport sys 1185863Snate@binkert.org 1195863Snate@binkert.orgfrom os import mkdir, environ 1205863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1215863Snate@binkert.orgfrom os.path import exists, isdir, isfile 122955SN/Afrom os.path import join as joinpath, split as splitpath 1236654Snate@binkert.org 1245273Sstever@gmail.com# SCons includes 1255871Snate@binkert.orgimport SCons 1265273Sstever@gmail.comimport SCons.Node 1276655Snate@binkert.org 1288878Ssteve.reinhardt@amd.comextra_python_paths = [ 1296655Snate@binkert.org Dir('src/python').srcnode().abspath, # gem5 includes 1306655Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1319219Spower.jg@gmail.com ] 1326655Snate@binkert.org 1335871Snate@binkert.orgsys.path[1:1] = extra_python_paths 1346654Snate@binkert.org 1358947Sandreas.hansson@arm.comfrom m5.util import compareVersions, readCommand 1365396Ssaidi@eecs.umich.edufrom m5.util.terminal import get_termcap 1378120Sgblack@eecs.umich.edu 1388120Sgblack@eecs.umich.eduhelp_texts = { 1398120Sgblack@eecs.umich.edu "options" : "", 1408120Sgblack@eecs.umich.edu "global_vars" : "", 1418120Sgblack@eecs.umich.edu "local_vars" : "" 1428120Sgblack@eecs.umich.edu} 1438120Sgblack@eecs.umich.edu 1448120Sgblack@eecs.umich.eduExport("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' 1498879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the 1508879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once 1518879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get 1528879Ssteve.reinhardt@amd.com# at the help texts from AddOptions. See: 1538879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1548879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1558879Ssteve.reinhardt@amd.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. 1588120Sgblack@eecs.umich.edudef AddLocalOption(*args, **kwargs): 1598120Sgblack@eecs.umich.edu col_width = 30 1608120Sgblack@eecs.umich.edu 1618120Sgblack@eecs.umich.edu help = " " + ", ".join(args) 1628120Sgblack@eecs.umich.edu if "help" in kwargs: 1638120Sgblack@eecs.umich.edu length = len(help) 1648120Sgblack@eecs.umich.edu if length >= col_width: 1658120Sgblack@eecs.umich.edu help += "\n" + " " * col_width 1668120Sgblack@eecs.umich.edu else: 1678120Sgblack@eecs.umich.edu help += " " * (col_width - length) 1688120Sgblack@eecs.umich.edu help += kwargs["help"] 1698120Sgblack@eecs.umich.edu help_texts["options"] += help + "\n" 1708120Sgblack@eecs.umich.edu 1718120Sgblack@eecs.umich.edu AddOption(*args, **kwargs) 1728879Ssteve.reinhardt@amd.com 1738879Ssteve.reinhardt@amd.comAddLocalOption('--colors', dest='use_colors', action='store_true', 1748879Ssteve.reinhardt@amd.com help="Add color to abbreviated scons output") 1758879Ssteve.reinhardt@amd.comAddLocalOption('--no-colors', dest='use_colors', action='store_false', 17610458Sandreas.hansson@arm.com help="Don't add color to abbreviated scons output") 17710458Sandreas.hansson@arm.comAddLocalOption('--with-cxx-config', dest='with_cxx_config', 17810458Sandreas.hansson@arm.com action='store_true', 1798879Ssteve.reinhardt@amd.com help="Build with support for C++-based configuration") 1808879Ssteve.reinhardt@amd.comAddLocalOption('--default', dest='default', type='string', action='store', 1818879Ssteve.reinhardt@amd.com help='Override which build_opts file to use for defaults') 1828879Ssteve.reinhardt@amd.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1839227Sandreas.hansson@arm.com help='Disable style checking hooks') 1849227Sandreas.hansson@arm.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1858879Ssteve.reinhardt@amd.com help='Disable Link-Time Optimization for fast') 1868879Ssteve.reinhardt@amd.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1878879Ssteve.reinhardt@amd.com help='Update test reference outputs') 1888879Ssteve.reinhardt@amd.comAddLocalOption('--verbose', dest='verbose', action='store_true', 18910453SAndrew.Bardsley@arm.com help='Print full tool command lines') 19010453SAndrew.Bardsley@arm.comAddLocalOption('--without-python', dest='without_python', 19110453SAndrew.Bardsley@arm.com action='store_true', 19210456SCurtis.Dunham@arm.com help='Build without Python configuration support') 19310456SCurtis.Dunham@arm.comAddLocalOption('--without-tcmalloc', dest='without_tcmalloc', 19410456SCurtis.Dunham@arm.com action='store_true', 19510457Sandreas.hansson@arm.com help='Disable linking against tcmalloc') 19610457Sandreas.hansson@arm.comAddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true', 1978120Sgblack@eecs.umich.edu help='Build with Undefined Behavior Sanitizer if available') 1988947Sandreas.hansson@arm.comAddLocalOption('--with-asan', dest='with_asan', action='store_true', 1997816Ssteve.reinhardt@amd.com help='Build with Address Sanitizer if available') 2005871Snate@binkert.org 2015871Snate@binkert.orgtermcap = get_termcap(GetOption('use_colors')) 2026121Snate@binkert.org 2035871Snate@binkert.org######################################################################## 2045871Snate@binkert.org# 2059926Sstan.czerniawski@arm.com# Set up the main build environment. 2069926Sstan.czerniawski@arm.com# 2079119Sandreas.hansson@arm.com######################################################################## 20810068Sandreas.hansson@arm.com 20910068Sandreas.hansson@arm.com# export TERM so that clang reports errors in color 210955SN/Ause_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 2119416SAndreas.Sandberg@ARM.com 'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PROTOC', 2129416SAndreas.Sandberg@ARM.com 'PYTHONPATH', 'RANLIB', 'SWIG', 'TERM' ]) 2139416SAndreas.Sandberg@ARM.com 2149416SAndreas.Sandberg@ARM.comuse_prefixes = [ 2159416SAndreas.Sandberg@ARM.com "ASAN_", # address sanitizer symbolizer path and settings 2169416SAndreas.Sandberg@ARM.com "CCACHE_", # ccache (caching compiler wrapper) configuration 2179416SAndreas.Sandberg@ARM.com "CCC_", # clang static analyzer configuration 2185871Snate@binkert.org "DISTCC_", # distcc (distributed compiler wrapper) configuration 21910584Sandreas.hansson@arm.com "INCLUDE_SERVER_", # distcc pump server settings 2209416SAndreas.Sandberg@ARM.com "M5", # M5 configuration (e.g., path to kernels) 2219416SAndreas.Sandberg@ARM.com ] 2225871Snate@binkert.org 223955SN/Ause_env = {} 22410671Sandreas.hansson@arm.comfor key,val in sorted(os.environ.iteritems()): 22510671Sandreas.hansson@arm.com if key in use_vars or \ 22610671Sandreas.hansson@arm.com any([key.startswith(prefix) for prefix in use_prefixes]): 22710671Sandreas.hansson@arm.com use_env[key] = val 2288881Smarc.orr@gmail.com 2296121Snate@binkert.org# Tell scons to avoid implicit command dependencies to avoid issues 2306121Snate@binkert.org# with the param wrappes being compiled twice (see 2311533SN/A# http://scons.tigris.org/issues/show_bug.cgi?id=2811) 2329239Sandreas.hansson@arm.commain = Environment(ENV=use_env, IMPLICIT_COMMAND_DEPENDENCIES=0) 2339239Sandreas.hansson@arm.commain.Decider('MD5-timestamp') 2349239Sandreas.hansson@arm.commain.root = Dir(".") # The current directory (where this file lives). 2359239Sandreas.hansson@arm.commain.srcdir = Dir("src") # The source directory 2369239Sandreas.hansson@arm.com 2379239Sandreas.hansson@arm.commain_dict_keys = main.Dictionary().keys() 2389239Sandreas.hansson@arm.com 2399239Sandreas.hansson@arm.com# Check that we have a C/C++ compiler 2409239Sandreas.hansson@arm.comif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 2419239Sandreas.hansson@arm.com print "No C++ compiler installed (package g++ on Ubuntu and RedHat)" 2429239Sandreas.hansson@arm.com Exit(1) 2439239Sandreas.hansson@arm.com 2446655Snate@binkert.org# Check that swig is present 2456655Snate@binkert.orgif not 'SWIG' in main_dict_keys: 2466655Snate@binkert.org print "swig is not installed (package swig on Ubuntu and RedHat)" 2476655Snate@binkert.org Exit(1) 2485871Snate@binkert.org 2495871Snate@binkert.org# add useful python code PYTHONPATH so it can be used by subprocesses 2505863Snate@binkert.org# as well 2515871Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths) 2528878Ssteve.reinhardt@amd.com 2535871Snate@binkert.org######################################################################## 2545871Snate@binkert.org# 2555871Snate@binkert.org# Mercurial Stuff. 2565863Snate@binkert.org# 2576121Snate@binkert.org# If the gem5 directory is a mercurial repository, we should do some 2585863Snate@binkert.org# extra things. 2595871Snate@binkert.org# 2608336Ssteve.reinhardt@amd.com######################################################################## 2618336Ssteve.reinhardt@amd.com 2628336Ssteve.reinhardt@amd.comhgdir = main.root.Dir(".hg") 2638336Ssteve.reinhardt@amd.comgitdir = main.root.Dir(".git") 2644678Snate@binkert.org 2658336Ssteve.reinhardt@amd.com 2668336Ssteve.reinhardt@amd.comstyle_message = """ 2678336Ssteve.reinhardt@amd.comYou're missing the gem5 style hook, which automatically checks your code 2684678Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands. This 2694678Snate@binkert.orgscript will now install the hook in your %s. 2704678Snate@binkert.orgPress enter to continue, or ctrl-c to abort: """ 2714678Snate@binkert.org 2727827Snate@binkert.orgmercurial_style_message = style_message % ".hg/hgrc file" 2737827Snate@binkert.orggit_style_message = style_message % ".git/hooks/ directory" 2748336Ssteve.reinhardt@amd.com 2754678Snate@binkert.orgmercurial_style_upgrade_message = """ 2768336Ssteve.reinhardt@amd.comYour Mercurial style hooks are not up-to-date. This script will now 2778336Ssteve.reinhardt@amd.comtry to automatically update them. A backup of your hgrc will be saved 2788336Ssteve.reinhardt@amd.comin .hg/hgrc.old. 2798336Ssteve.reinhardt@amd.comPress enter to continue, or ctrl-c to abort: """ 2808336Ssteve.reinhardt@amd.com 2818336Ssteve.reinhardt@amd.commercurial_style_hook = """ 2825871Snate@binkert.org# The following lines were automatically added by gem5/SConstruct 2835871Snate@binkert.org# to provide the gem5 style-checking hooks 2848336Ssteve.reinhardt@amd.com[extensions] 2858336Ssteve.reinhardt@amd.comhgstyle = %s/util/hgstyle.py 2868336Ssteve.reinhardt@amd.com 2878336Ssteve.reinhardt@amd.com[hooks] 2888336Ssteve.reinhardt@amd.compretxncommit.style = python:hgstyle.check_style 2895871Snate@binkert.orgpre-qrefresh.style = python:hgstyle.check_style 2908336Ssteve.reinhardt@amd.com# End of SConstruct additions 2918336Ssteve.reinhardt@amd.com 2928336Ssteve.reinhardt@amd.com""" % (main.root.abspath) 2938336Ssteve.reinhardt@amd.com 2948336Ssteve.reinhardt@amd.commercurial_lib_not_found = """ 2954678Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook. If 2965871Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 2974678Snate@binkert.orghook. It is important. 2988336Ssteve.reinhardt@amd.com""" 2998336Ssteve.reinhardt@amd.com 3008336Ssteve.reinhardt@amd.com# Check for style hook and prompt for installation if it's not there. 3018336Ssteve.reinhardt@amd.com# Skip this if --ignore-style was specified, there's no interactive 3028336Ssteve.reinhardt@amd.com# terminal to prompt, or no recognized revision control system can be 3038336Ssteve.reinhardt@amd.com# found. 3048336Ssteve.reinhardt@amd.comignore_style = GetOption('ignore_style') or not sys.stdin.isatty() 3058336Ssteve.reinhardt@amd.com 3068336Ssteve.reinhardt@amd.com# Try wire up Mercurial to the style hooks 3078336Ssteve.reinhardt@amd.comif not ignore_style and hgdir.exists(): 3088336Ssteve.reinhardt@amd.com style_hook = True 3098336Ssteve.reinhardt@amd.com style_hooks = tuple() 3108336Ssteve.reinhardt@amd.com hgrc = hgdir.File('hgrc') 3118336Ssteve.reinhardt@amd.com hgrc_old = hgdir.File('hgrc.old') 3128336Ssteve.reinhardt@amd.com try: 3138336Ssteve.reinhardt@amd.com from mercurial import ui 3148336Ssteve.reinhardt@amd.com ui = ui.ui() 3155871Snate@binkert.org ui.readconfig(hgrc.abspath) 3166121Snate@binkert.org style_hooks = (ui.config('hooks', 'pretxncommit.style', None), 317955SN/A ui.config('hooks', 'pre-qrefresh.style', None)) 318955SN/A style_hook = all(style_hooks) 3192632Sstever@eecs.umich.edu style_extension = ui.config('extensions', 'style', None) 3202632Sstever@eecs.umich.edu except ImportError: 321955SN/A print mercurial_lib_not_found 322955SN/A 323955SN/A if "python:style.check_style" in style_hooks: 324955SN/A # Try to upgrade the style hooks 3258878Ssteve.reinhardt@amd.com print mercurial_style_upgrade_message 326955SN/A # continue unless user does ctrl-c/ctrl-d etc. 3272632Sstever@eecs.umich.edu try: 3282632Sstever@eecs.umich.edu raw_input() 3292632Sstever@eecs.umich.edu except: 3302632Sstever@eecs.umich.edu print "Input exception, exiting scons.\n" 3312632Sstever@eecs.umich.edu sys.exit(1) 3322632Sstever@eecs.umich.edu shutil.copyfile(hgrc.abspath, hgrc_old.abspath) 3332632Sstever@eecs.umich.edu re_style_hook = re.compile(r"^([^=#]+)\.style\s*=\s*([^#\s]+).*") 3348268Ssteve.reinhardt@amd.com re_style_extension = re.compile("style\s*=\s*([^#\s]+).*") 3358268Ssteve.reinhardt@amd.com with open(hgrc_old.abspath, 'r') as old, \ 3368268Ssteve.reinhardt@amd.com open(hgrc.abspath, 'w') as new: 3378268Ssteve.reinhardt@amd.com 3388268Ssteve.reinhardt@amd.com for l in old: 3398268Ssteve.reinhardt@amd.com m_hook = re_style_hook.match(l) 3408268Ssteve.reinhardt@amd.com m_ext = re_style_extension.match(l) 3412632Sstever@eecs.umich.edu if m_hook: 3422632Sstever@eecs.umich.edu hook, check = m_hook.groups() 3432632Sstever@eecs.umich.edu if check != "python:style.check_style": 3442632Sstever@eecs.umich.edu print "Warning: %s.style is using a non-default " \ 3458268Ssteve.reinhardt@amd.com "checker: %s" % (hook, check) 3462632Sstever@eecs.umich.edu if hook not in ("pretxncommit", "pre-qrefresh"): 3478268Ssteve.reinhardt@amd.com print "Warning: Updating unknown style hook: %s" % hook 3488268Ssteve.reinhardt@amd.com 3498268Ssteve.reinhardt@amd.com l = "%s.style = python:hgstyle.check_style\n" % hook 3508268Ssteve.reinhardt@amd.com elif m_ext and m_ext.group(1) == style_extension: 3513718Sstever@eecs.umich.edu l = "hgstyle = %s/util/hgstyle.py\n" % main.root.abspath 3522634Sstever@eecs.umich.edu 3532634Sstever@eecs.umich.edu new.write(l) 3545863Snate@binkert.org elif not style_hook: 3552638Sstever@eecs.umich.edu print mercurial_style_message, 3568268Ssteve.reinhardt@amd.com # continue unless user does ctrl-c/ctrl-d etc. 3572632Sstever@eecs.umich.edu try: 3582632Sstever@eecs.umich.edu raw_input() 3592632Sstever@eecs.umich.edu except: 3602632Sstever@eecs.umich.edu print "Input exception, exiting scons.\n" 3612632Sstever@eecs.umich.edu sys.exit(1) 3621858SN/A hgrc_path = '%s/.hg/hgrc' % main.root.abspath 3633716Sstever@eecs.umich.edu print "Adding style hook to", hgrc_path, "\n" 3642638Sstever@eecs.umich.edu try: 3652638Sstever@eecs.umich.edu with open(hgrc_path, 'a') as f: 3662638Sstever@eecs.umich.edu f.write(mercurial_style_hook) 3672638Sstever@eecs.umich.edu except: 3682638Sstever@eecs.umich.edu print "Error updating", hgrc_path 3692638Sstever@eecs.umich.edu sys.exit(1) 3702638Sstever@eecs.umich.edu 3715863Snate@binkert.org# Try to wire up git to the style hooks 3725863Snate@binkert.orggit_pre_commit_hook = gitdir.File("hooks/pre-commit") 3735863Snate@binkert.orgif not ignore_style and gitdir.exists() and not git_pre_commit_hook.exists(): 374955SN/A git_style_script = File("util/git-pre-commit.py") 3755341Sstever@gmail.com 3765341Sstever@gmail.com print git_style_message, 3775863Snate@binkert.org try: 3787756SAli.Saidi@ARM.com raw_input() 3795341Sstever@gmail.com except: 3806121Snate@binkert.org print "Input exception, exiting scons.\n" 3814494Ssaidi@eecs.umich.edu sys.exit(1) 3826121Snate@binkert.org 3831105SN/A try: 3842667Sstever@eecs.umich.edu rel_style_script = os.path.relpath( 3852667Sstever@eecs.umich.edu git_style_script.get_abspath(), 3862667Sstever@eecs.umich.edu git_pre_commit_hook.Dir(".").get_abspath()) 3872667Sstever@eecs.umich.edu os.symlink(rel_style_script, git_pre_commit_hook.get_abspath()) 3886121Snate@binkert.org except: 3892667Sstever@eecs.umich.edu print "Error updating git pre-commit hook" 3905341Sstever@gmail.com raise 3915863Snate@binkert.org sys.exit(1) 3925341Sstever@gmail.com 3935341Sstever@gmail.com################################################### 3945341Sstever@gmail.com# 3958120Sgblack@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 3965341Sstever@gmail.com# the target(s). 3978120Sgblack@eecs.umich.edu# 3985341Sstever@gmail.com################################################### 3998120Sgblack@eecs.umich.edu 4006121Snate@binkert.org# Find default configuration & binary. 4016121Snate@binkert.orgDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 4028980Ssteve.reinhardt@amd.com 4039396Sandreas.hansson@arm.com# helper function: find last occurrence of element in list 4045397Ssaidi@eecs.umich.edudef rfind(l, elt, offs = -1): 4055397Ssaidi@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 4067727SAli.Saidi@ARM.com if l[i] == elt: 4078268Ssteve.reinhardt@amd.com return i 4086168Snate@binkert.org raise ValueError, "element not found" 4095341Sstever@gmail.com 4108120Sgblack@eecs.umich.edu# Take a list of paths (or SCons Nodes) and return a list with all 4118120Sgblack@eecs.umich.edu# paths made absolute and ~-expanded. Paths will be interpreted 4128120Sgblack@eecs.umich.edu# relative to the launch directory unless a different root is provided 4136814Sgblack@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 4145863Snate@binkert.org return [abspath(joinpath(root, expanduser(str(p)))) 4158120Sgblack@eecs.umich.edu for p in path_list] 4165341Sstever@gmail.com 4175863Snate@binkert.org# Each target must have 'build' in the interior of the path; the 4188268Ssteve.reinhardt@amd.com# directory below this will determine the build parameters. For 4196121Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 4206121Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 4218268Ssteve.reinhardt@amd.com# follow 'build' in the build path. 4225742Snate@binkert.org 4235742Snate@binkert.org# The funky assignment to "[:]" is needed to replace the list contents 4245341Sstever@gmail.com# in place rather than reassign the symbol to a new list, which 4255742Snate@binkert.org# doesn't work (obviously!). 4265742Snate@binkert.orgBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 4275341Sstever@gmail.com 4286017Snate@binkert.org# Generate a list of the unique build roots and configs that the 4296121Snate@binkert.org# collected targets reference. 4306017Snate@binkert.orgvariant_paths = [] 4317816Ssteve.reinhardt@amd.combuild_root = None 4327756SAli.Saidi@ARM.comfor t in BUILD_TARGETS: 4337756SAli.Saidi@ARM.com path_dirs = t.split('/') 4347756SAli.Saidi@ARM.com try: 4357756SAli.Saidi@ARM.com build_top = rfind(path_dirs, 'build', -2) 4367756SAli.Saidi@ARM.com except: 4377756SAli.Saidi@ARM.com print "Error: no non-leaf 'build' dir found on target path", t 4387756SAli.Saidi@ARM.com Exit(1) 4397756SAli.Saidi@ARM.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 4407816Ssteve.reinhardt@amd.com if not build_root: 4417816Ssteve.reinhardt@amd.com build_root = this_build_root 4427816Ssteve.reinhardt@amd.com else: 4437816Ssteve.reinhardt@amd.com if this_build_root != build_root: 4447816Ssteve.reinhardt@amd.com print "Error: build targets not under same build root\n"\ 4457816Ssteve.reinhardt@amd.com " %s\n %s" % (build_root, this_build_root) 4467816Ssteve.reinhardt@amd.com Exit(1) 4477816Ssteve.reinhardt@amd.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 4487816Ssteve.reinhardt@amd.com if variant_path not in variant_paths: 4497816Ssteve.reinhardt@amd.com variant_paths.append(variant_path) 4507756SAli.Saidi@ARM.com 4517816Ssteve.reinhardt@amd.com# Make sure build_root exists (might not if this is the first build there) 4527816Ssteve.reinhardt@amd.comif not isdir(build_root): 4537816Ssteve.reinhardt@amd.com mkdir(build_root) 4547816Ssteve.reinhardt@amd.commain['BUILDROOT'] = build_root 4557816Ssteve.reinhardt@amd.com 4567816Ssteve.reinhardt@amd.comExport('main') 4577816Ssteve.reinhardt@amd.com 4587816Ssteve.reinhardt@amd.commain.SConsignFile(joinpath(build_root, "sconsign")) 4597816Ssteve.reinhardt@amd.com 4607816Ssteve.reinhardt@amd.com# Default duplicate option is to use hard links, but this messes up 4617816Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves 4627816Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link. Symbolic 4637816Ssteve.reinhardt@amd.com# (soft) links work better. 4647816Ssteve.reinhardt@amd.commain.SetOption('duplicate', 'soft-copy') 4657816Ssteve.reinhardt@amd.com 4667816Ssteve.reinhardt@amd.com# 4677816Ssteve.reinhardt@amd.com# Set up global sticky variables... these are common to an entire build 4687816Ssteve.reinhardt@amd.com# tree (not specific to a particular build like ALPHA_SE) 4697816Ssteve.reinhardt@amd.com# 4707816Ssteve.reinhardt@amd.com 4717816Ssteve.reinhardt@amd.comglobal_vars_file = joinpath(build_root, 'variables.global') 4727816Ssteve.reinhardt@amd.com 4737816Ssteve.reinhardt@amd.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 4747816Ssteve.reinhardt@amd.com 4757816Ssteve.reinhardt@amd.comglobal_vars.AddVariables( 4767816Ssteve.reinhardt@amd.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 4777816Ssteve.reinhardt@amd.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 4787816Ssteve.reinhardt@amd.com ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 4797816Ssteve.reinhardt@amd.com ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 4807816Ssteve.reinhardt@amd.com ('BATCH', 'Use batch pool for build and tests', False), 4817816Ssteve.reinhardt@amd.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 4827816Ssteve.reinhardt@amd.com ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 4837816Ssteve.reinhardt@amd.com ('EXTRAS', 'Add extra directories to the compilation', '') 4847816Ssteve.reinhardt@amd.com ) 4857816Ssteve.reinhardt@amd.com 4867816Ssteve.reinhardt@amd.com# Update main environment with values from ARGUMENTS & global_vars_file 4877816Ssteve.reinhardt@amd.comglobal_vars.Update(main) 4887816Ssteve.reinhardt@amd.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 4897816Ssteve.reinhardt@amd.com 4907816Ssteve.reinhardt@amd.com# Save sticky variable settings back to current variables file 4917816Ssteve.reinhardt@amd.comglobal_vars.Save(global_vars_file, main) 4927816Ssteve.reinhardt@amd.com 4937816Ssteve.reinhardt@amd.com# Parse EXTRAS variable to build list of all directories where we're 4947816Ssteve.reinhardt@amd.com# look for sources etc. This list is exported as extras_dir_list. 4957816Ssteve.reinhardt@amd.combase_dir = main.srcdir.abspath 4967816Ssteve.reinhardt@amd.comif main['EXTRAS']: 4977816Ssteve.reinhardt@amd.com extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 4987816Ssteve.reinhardt@amd.comelse: 4997816Ssteve.reinhardt@amd.com extras_dir_list = [] 5007816Ssteve.reinhardt@amd.com 5017816Ssteve.reinhardt@amd.comExport('base_dir') 5027816Ssteve.reinhardt@amd.comExport('extras_dir_list') 5037816Ssteve.reinhardt@amd.com 5047816Ssteve.reinhardt@amd.com# the ext directory should be on the #includes path 5057816Ssteve.reinhardt@amd.commain.Append(CPPPATH=[Dir('ext')]) 5067816Ssteve.reinhardt@amd.com 5077816Ssteve.reinhardt@amd.comdef strip_build_path(path, env): 5087816Ssteve.reinhardt@amd.com path = str(path) 5097816Ssteve.reinhardt@amd.com variant_base = env['BUILDROOT'] + os.path.sep 5107816Ssteve.reinhardt@amd.com if path.startswith(variant_base): 5117816Ssteve.reinhardt@amd.com path = path[len(variant_base):] 5128947Sandreas.hansson@arm.com elif path.startswith('build/'): 5138947Sandreas.hansson@arm.com path = path[6:] 5147756SAli.Saidi@ARM.com return path 5158120Sgblack@eecs.umich.edu 5167756SAli.Saidi@ARM.com# Generate a string of the form: 5177756SAli.Saidi@ARM.com# common/path/prefix/src1, src2 -> tgt1, tgt2 5187756SAli.Saidi@ARM.com# to print while building. 5197756SAli.Saidi@ARM.comclass Transform(object): 5207816Ssteve.reinhardt@amd.com # all specific color settings should be here and nowhere else 5217816Ssteve.reinhardt@amd.com tool_color = termcap.Normal 5227816Ssteve.reinhardt@amd.com pfx_color = termcap.Yellow 5237816Ssteve.reinhardt@amd.com srcs_color = termcap.Yellow + termcap.Bold 5247816Ssteve.reinhardt@amd.com arrow_color = termcap.Blue + termcap.Bold 5257816Ssteve.reinhardt@amd.com tgts_color = termcap.Yellow + termcap.Bold 5267816Ssteve.reinhardt@amd.com 5277816Ssteve.reinhardt@amd.com def __init__(self, tool, max_sources=99): 5287816Ssteve.reinhardt@amd.com self.format = self.tool_color + (" [%8s] " % tool) \ 5297816Ssteve.reinhardt@amd.com + self.pfx_color + "%s" \ 5307756SAli.Saidi@ARM.com + self.srcs_color + "%s" \ 5317756SAli.Saidi@ARM.com + self.arrow_color + " -> " \ 5329227Sandreas.hansson@arm.com + self.tgts_color + "%s" \ 5339227Sandreas.hansson@arm.com + termcap.Normal 5349227Sandreas.hansson@arm.com self.max_sources = max_sources 5359227Sandreas.hansson@arm.com 5369590Sandreas@sandberg.pp.se def __call__(self, target, source, env, for_signature=None): 5379590Sandreas@sandberg.pp.se # truncate source list according to max_sources param 5389590Sandreas@sandberg.pp.se source = source[0:self.max_sources] 5399590Sandreas@sandberg.pp.se def strip(f): 5409590Sandreas@sandberg.pp.se return strip_build_path(str(f), env) 5419590Sandreas@sandberg.pp.se if len(source) > 0: 5426654Snate@binkert.org srcs = map(strip, source) 5436654Snate@binkert.org else: 5445871Snate@binkert.org srcs = [''] 5456121Snate@binkert.org tgts = map(strip, target) 5468946Sandreas.hansson@arm.com # surprisingly, os.path.commonprefix is a dumb char-by-char string 5479419Sandreas.hansson@arm.com # operation that has nothing to do with paths. 5483940Ssaidi@eecs.umich.edu com_pfx = os.path.commonprefix(srcs + tgts) 5493918Ssaidi@eecs.umich.edu com_pfx_len = len(com_pfx) 5503918Ssaidi@eecs.umich.edu if com_pfx: 5511858SN/A # do some cleanup and sanity checking on common prefix 5529556Sandreas.hansson@arm.com if com_pfx[-1] == ".": 5539556Sandreas.hansson@arm.com # prefix matches all but file extension: ok 5549556Sandreas.hansson@arm.com # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 5559556Sandreas.hansson@arm.com com_pfx = com_pfx[0:-1] 5569556Sandreas.hansson@arm.com elif com_pfx[-1] == "/": 5579556Sandreas.hansson@arm.com # common prefix is directory path: OK 5589556Sandreas.hansson@arm.com pass 5599556Sandreas.hansson@arm.com else: 5609556Sandreas.hansson@arm.com src0_len = len(srcs[0]) 5619556Sandreas.hansson@arm.com tgt0_len = len(tgts[0]) 5629556Sandreas.hansson@arm.com if src0_len == com_pfx_len: 5639556Sandreas.hansson@arm.com # source is a substring of target, OK 5649556Sandreas.hansson@arm.com pass 5659556Sandreas.hansson@arm.com elif tgt0_len == com_pfx_len: 5669556Sandreas.hansson@arm.com # target is a substring of source, need to back up to 5679556Sandreas.hansson@arm.com # avoid empty string on RHS of arrow 5689556Sandreas.hansson@arm.com sep_idx = com_pfx.rfind(".") 5699556Sandreas.hansson@arm.com if sep_idx != -1: 5709556Sandreas.hansson@arm.com com_pfx = com_pfx[0:sep_idx] 5719556Sandreas.hansson@arm.com else: 5729556Sandreas.hansson@arm.com com_pfx = '' 5739556Sandreas.hansson@arm.com elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 5749556Sandreas.hansson@arm.com # still splitting at file extension: ok 5759556Sandreas.hansson@arm.com pass 5769556Sandreas.hansson@arm.com else: 5779556Sandreas.hansson@arm.com # probably a fluke; ignore it 5789556Sandreas.hansson@arm.com com_pfx = '' 5799556Sandreas.hansson@arm.com # recalculate length in case com_pfx was modified 5809556Sandreas.hansson@arm.com com_pfx_len = len(com_pfx) 5819556Sandreas.hansson@arm.com def fmt(files): 5829556Sandreas.hansson@arm.com f = map(lambda s: s[com_pfx_len:], files) 5839556Sandreas.hansson@arm.com return ', '.join(f) 5846121Snate@binkert.org return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 58510238Sandreas.hansson@arm.com 58610238Sandreas.hansson@arm.comExport('Transform') 58710238Sandreas.hansson@arm.com 58810238Sandreas.hansson@arm.com# enable the regression script to use the termcap 5899420Sandreas.hansson@arm.commain['TERMCAP'] = termcap 59010238Sandreas.hansson@arm.com 59110238Sandreas.hansson@arm.comif GetOption('verbose'): 5929420Sandreas.hansson@arm.com def MakeAction(action, string, *args, **kwargs): 5939420Sandreas.hansson@arm.com return Action(action, *args, **kwargs) 5949420Sandreas.hansson@arm.comelse: 5959420Sandreas.hansson@arm.com MakeAction = Action 5969420Sandreas.hansson@arm.com main['CCCOMSTR'] = Transform("CC") 59710264Sandreas.hansson@arm.com main['CXXCOMSTR'] = Transform("CXX") 59810264Sandreas.hansson@arm.com main['ASCOMSTR'] = Transform("AS") 59910264Sandreas.hansson@arm.com main['SWIGCOMSTR'] = Transform("SWIG") 60010264Sandreas.hansson@arm.com main['ARCOMSTR'] = Transform("AR", 0) 60110264Sandreas.hansson@arm.com main['LINKCOMSTR'] = Transform("LINK", 0) 60210866Sandreas.hansson@arm.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 60310866Sandreas.hansson@arm.com main['M4COMSTR'] = Transform("M4") 60410264Sandreas.hansson@arm.com main['SHCCCOMSTR'] = Transform("SHCC") 60510866Sandreas.hansson@arm.com main['SHCXXCOMSTR'] = Transform("SHCXX") 60610866Sandreas.hansson@arm.comExport('MakeAction') 60710866Sandreas.hansson@arm.com 60810866Sandreas.hansson@arm.com# Initialize the Link-Time Optimization (LTO) flags 60910866Sandreas.hansson@arm.commain['LTO_CCFLAGS'] = [] 61010866Sandreas.hansson@arm.commain['LTO_LDFLAGS'] = [] 61110866Sandreas.hansson@arm.com 61210264Sandreas.hansson@arm.com# According to the readme, tcmalloc works best if the compiler doesn't 61310264Sandreas.hansson@arm.com# assume that we're using the builtin malloc and friends. These flags 61410264Sandreas.hansson@arm.com# are compiler-specific, so we need to set them after we detect which 61510264Sandreas.hansson@arm.com# compiler we're using. 61610264Sandreas.hansson@arm.commain['TCMALLOC_CCFLAGS'] = [] 61710264Sandreas.hansson@arm.com 61810264Sandreas.hansson@arm.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 61910457Sandreas.hansson@arm.comCXX_V = readCommand([main['CXX'],'-V'], exception=False) 62010457Sandreas.hansson@arm.com 62110457Sandreas.hansson@arm.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 62210457Sandreas.hansson@arm.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 62310457Sandreas.hansson@arm.comif main['GCC'] + main['CLANG'] > 1: 62410457Sandreas.hansson@arm.com print 'Error: How can we have two at the same time?' 62510457Sandreas.hansson@arm.com Exit(1) 62610457Sandreas.hansson@arm.com 62710457Sandreas.hansson@arm.com# Set up default C++ compiler flags 62810238Sandreas.hansson@arm.comif main['GCC'] or main['CLANG']: 62910238Sandreas.hansson@arm.com # As gcc and clang share many flags, do the common parts here 63010238Sandreas.hansson@arm.com main.Append(CCFLAGS=['-pipe']) 63110238Sandreas.hansson@arm.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 63210238Sandreas.hansson@arm.com # Enable -Wall and -Wextra and then disable the few warnings that 63310238Sandreas.hansson@arm.com # we consistently violate 63410416Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wall', '-Wundef', '-Wextra', 63510238Sandreas.hansson@arm.com '-Wno-sign-compare', '-Wno-unused-parameter']) 6369227Sandreas.hansson@arm.com # We always compile using C++11 63710238Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-std=c++11']) 63810416Sandreas.hansson@arm.comelse: 63910416Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 6409227Sandreas.hansson@arm.com print "Don't know what compiler options to use for your compiler." 6419590Sandreas@sandberg.pp.se print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 6429590Sandreas@sandberg.pp.se print termcap.Yellow + ' version:' + termcap.Normal, 6439590Sandreas@sandberg.pp.se if not CXX_version: 6448737Skoansin.tan@gmail.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 64510238Sandreas.hansson@arm.com termcap.Normal 64610238Sandreas.hansson@arm.com else: 6479420Sandreas.hansson@arm.com print CXX_version.replace('\n', '<nl>') 6488737Skoansin.tan@gmail.com print " If you're trying to use a compiler other than GCC" 64910106SMitch.Hayenga@arm.com print " or clang, there appears to be something wrong with your" 6508737Skoansin.tan@gmail.com print " environment." 6518737Skoansin.tan@gmail.com print " " 65210238Sandreas.hansson@arm.com print " If you are trying to use a compiler other than those listed" 65310238Sandreas.hansson@arm.com print " above you will need to ease fix SConstruct and " 6548737Skoansin.tan@gmail.com print " src/SConscript to support that compiler." 6558737Skoansin.tan@gmail.com Exit(1) 6568737Skoansin.tan@gmail.com 6578737Skoansin.tan@gmail.comif main['GCC']: 6588737Skoansin.tan@gmail.com # Check for a supported version of gcc. >= 4.7 is chosen for its 6598737Skoansin.tan@gmail.com # level of c++11 support. See 6609556Sandreas.hansson@arm.com # http://gcc.gnu.org/projects/cxx0x.html for details. 6619556Sandreas.hansson@arm.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 6629556Sandreas.hansson@arm.com if compareVersions(gcc_version, "4.7") < 0: 6639556Sandreas.hansson@arm.com print 'Error: gcc version 4.7 or newer required.' 6649556Sandreas.hansson@arm.com print ' Installed version:', gcc_version 6659556Sandreas.hansson@arm.com Exit(1) 6669556Sandreas.hansson@arm.com 6679556Sandreas.hansson@arm.com main['GCC_VERSION'] = gcc_version 66810278SAndreas.Sandberg@ARM.com 66910278SAndreas.Sandberg@ARM.com # gcc from version 4.8 and above generates "rep; ret" instructions 67010278SAndreas.Sandberg@ARM.com # to avoid performance penalties on certain AMD chips. Older 67110278SAndreas.Sandberg@ARM.com # assemblers detect this as an error, "Error: expecting string 67210278SAndreas.Sandberg@ARM.com # instruction after `rep'" 67310278SAndreas.Sandberg@ARM.com if compareVersions(gcc_version, "4.8") > 0: 6749556Sandreas.hansson@arm.com as_version_raw = readCommand([main['AS'], '-v', '/dev/null'], 6759590Sandreas@sandberg.pp.se exception=False).split() 6769590Sandreas@sandberg.pp.se 6779420Sandreas.hansson@arm.com # version strings may contain extra distro-specific 6789846Sandreas.hansson@arm.com # qualifiers, so play it safe and keep only what comes before 6799846Sandreas.hansson@arm.com # the first hyphen 6809846Sandreas.hansson@arm.com as_version = as_version_raw[-1].split('-')[0] if as_version_raw \ 6819846Sandreas.hansson@arm.com else None 6828946Sandreas.hansson@arm.com 6833918Ssaidi@eecs.umich.edu if not as_version or compareVersions(as_version, "2.23") < 0: 6849068SAli.Saidi@ARM.com print termcap.Yellow + termcap.Bold + \ 6859068SAli.Saidi@ARM.com 'Warning: This combination of gcc and binutils have' + \ 6869068SAli.Saidi@ARM.com ' known incompatibilities.\n' + \ 6879068SAli.Saidi@ARM.com ' If you encounter build problems, please update ' + \ 6889068SAli.Saidi@ARM.com 'binutils to 2.23.' + \ 6899068SAli.Saidi@ARM.com termcap.Normal 6909068SAli.Saidi@ARM.com 6919068SAli.Saidi@ARM.com # Make sure we warn if the user has requested to compile with the 6929068SAli.Saidi@ARM.com # Undefined Benahvior Sanitizer and this version of gcc does not 6939419Sandreas.hansson@arm.com # support it. 6949068SAli.Saidi@ARM.com if GetOption('with_ubsan') and \ 6959068SAli.Saidi@ARM.com compareVersions(gcc_version, '4.9') < 0: 6969068SAli.Saidi@ARM.com print termcap.Yellow + termcap.Bold + \ 6979068SAli.Saidi@ARM.com 'Warning: UBSan is only supported using gcc 4.9 and later.' + \ 6989068SAli.Saidi@ARM.com termcap.Normal 6999068SAli.Saidi@ARM.com 7003918Ssaidi@eecs.umich.edu # Add the appropriate Link-Time Optimization (LTO) flags 7013918Ssaidi@eecs.umich.edu # unless LTO is explicitly turned off. Note that these flags 7026157Snate@binkert.org # are only used by the fast target. 7036157Snate@binkert.org if not GetOption('no_lto'): 7046157Snate@binkert.org # Pass the LTO flag when compiling to produce GIMPLE 7056157Snate@binkert.org # output, we merely create the flags here and only append 7065397Ssaidi@eecs.umich.edu # them later 7075397Ssaidi@eecs.umich.edu main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 7086121Snate@binkert.org 7096121Snate@binkert.org # Use the same amount of jobs for LTO as we are running 7106121Snate@binkert.org # scons with 7116121Snate@binkert.org main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 7126121Snate@binkert.org 7136121Snate@binkert.org main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 7145397Ssaidi@eecs.umich.edu '-fno-builtin-realloc', '-fno-builtin-free']) 7151851SN/A 7161851SN/Aelif main['CLANG']: 7177739Sgblack@eecs.umich.edu # Check for a supported version of clang, >= 3.1 is needed to 718955SN/A # support similar features as gcc 4.7. See 7199396Sandreas.hansson@arm.com # http://clang.llvm.org/cxx_status.html for details 7209396Sandreas.hansson@arm.com clang_version_re = re.compile(".* version (\d+\.\d+)") 7219396Sandreas.hansson@arm.com clang_version_match = clang_version_re.search(CXX_version) 7229396Sandreas.hansson@arm.com if (clang_version_match): 7239396Sandreas.hansson@arm.com clang_version = clang_version_match.groups()[0] 7249396Sandreas.hansson@arm.com if compareVersions(clang_version, "3.1") < 0: 7259396Sandreas.hansson@arm.com print 'Error: clang version 3.1 or newer required.' 7269396Sandreas.hansson@arm.com print ' Installed version:', clang_version 7279396Sandreas.hansson@arm.com Exit(1) 7289396Sandreas.hansson@arm.com else: 7299396Sandreas.hansson@arm.com print 'Error: Unable to determine clang version.' 7309396Sandreas.hansson@arm.com Exit(1) 7319396Sandreas.hansson@arm.com 7329396Sandreas.hansson@arm.com # clang has a few additional warnings that we disable, extraneous 7339396Sandreas.hansson@arm.com # parantheses are allowed due to Ruby's printing of the AST, 7349396Sandreas.hansson@arm.com # finally self assignments are allowed as the generated CPU code 7359477Sandreas.hansson@arm.com # is relying on this 7369477Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-parentheses', 7379477Sandreas.hansson@arm.com '-Wno-self-assign', 7389477Sandreas.hansson@arm.com # Some versions of libstdc++ (4.8?) seem to 7399477Sandreas.hansson@arm.com # use struct hash and class hash 7409477Sandreas.hansson@arm.com # interchangeably. 7419477Sandreas.hansson@arm.com '-Wno-mismatched-tags', 7429477Sandreas.hansson@arm.com ]) 7439477Sandreas.hansson@arm.com 7449477Sandreas.hansson@arm.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 7459477Sandreas.hansson@arm.com 7469477Sandreas.hansson@arm.com # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 7479477Sandreas.hansson@arm.com # opposed to libstdc++, as the later is dated. 7489477Sandreas.hansson@arm.com if sys.platform == "darwin": 7499477Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-stdlib=libc++']) 7509477Sandreas.hansson@arm.com main.Append(LIBS=['c++']) 7519477Sandreas.hansson@arm.com 7529477Sandreas.hansson@arm.comelse: 7539477Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 7549477Sandreas.hansson@arm.com print "Don't know what compiler options to use for your compiler." 7559477Sandreas.hansson@arm.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 7569477Sandreas.hansson@arm.com print termcap.Yellow + ' version:' + termcap.Normal, 7579396Sandreas.hansson@arm.com if not CXX_version: 7583053Sstever@eecs.umich.edu print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 7596121Snate@binkert.org termcap.Normal 7603053Sstever@eecs.umich.edu else: 7613053Sstever@eecs.umich.edu print CXX_version.replace('\n', '<nl>') 7623053Sstever@eecs.umich.edu print " If you're trying to use a compiler other than GCC" 7633053Sstever@eecs.umich.edu print " or clang, there appears to be something wrong with your" 7643053Sstever@eecs.umich.edu print " environment." 7659072Sandreas.hansson@arm.com print " " 7663053Sstever@eecs.umich.edu print " If you are trying to use a compiler other than those listed" 7674742Sstever@eecs.umich.edu print " above you will need to ease fix SConstruct and " 7684742Sstever@eecs.umich.edu print " src/SConscript to support that compiler." 7693053Sstever@eecs.umich.edu Exit(1) 7703053Sstever@eecs.umich.edu 7713053Sstever@eecs.umich.edu# Set up common yacc/bison flags (needed for Ruby) 77210181SCurtis.Dunham@arm.commain['YACCFLAGS'] = '-d' 7736654Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh' 7743053Sstever@eecs.umich.edu 7753053Sstever@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 7763053Sstever@eecs.umich.edu# extra 'qdo' every time we run scons. 7773053Sstever@eecs.umich.eduif main['BATCH']: 77810425Sandreas.hansson@arm.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 77910425Sandreas.hansson@arm.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 78010425Sandreas.hansson@arm.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 78110425Sandreas.hansson@arm.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 78210425Sandreas.hansson@arm.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 78310425Sandreas.hansson@arm.com 78410425Sandreas.hansson@arm.comif sys.platform == 'cygwin': 78510425Sandreas.hansson@arm.com # cygwin has some header file issues... 78610425Sandreas.hansson@arm.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 78710425Sandreas.hansson@arm.com 78810425Sandreas.hansson@arm.com# Check for the protobuf compiler 7892667Sstever@eecs.umich.eduprotoc_version = readCommand([main['PROTOC'], '--version'], 7904554Sbinkertn@umich.edu exception='').split() 7916121Snate@binkert.org 7922667Sstever@eecs.umich.edu# First two words should be "libprotoc x.y.z" 79310710Sandreas.hansson@arm.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 79410710Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + \ 79510710Sandreas.hansson@arm.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + \ 79610710Sandreas.hansson@arm.com ' Please install protobuf-compiler for tracing support.' + \ 79710710Sandreas.hansson@arm.com termcap.Normal 79810710Sandreas.hansson@arm.com main['PROTOC'] = False 79910710Sandreas.hansson@arm.comelse: 80010710Sandreas.hansson@arm.com # Based on the availability of the compress stream wrappers, 80110710Sandreas.hansson@arm.com # require 2.1.0 80210384SCurtis.Dunham@arm.com min_protoc_version = '2.1.0' 8034554Sbinkertn@umich.edu if compareVersions(protoc_version[1], min_protoc_version) < 0: 8044554Sbinkertn@umich.edu print termcap.Yellow + termcap.Bold + \ 8054554Sbinkertn@umich.edu 'Warning: protoc version', min_protoc_version, \ 8066121Snate@binkert.org 'or newer required.\n' + \ 8074554Sbinkertn@umich.edu ' Installed version:', protoc_version[1], \ 8084554Sbinkertn@umich.edu termcap.Normal 8094554Sbinkertn@umich.edu main['PROTOC'] = False 8104781Snate@binkert.org else: 8114554Sbinkertn@umich.edu # Attempt to determine the appropriate include path and 8124554Sbinkertn@umich.edu # library path using pkg-config, that means we also need to 8132667Sstever@eecs.umich.edu # check for pkg-config. Note that it is possible to use 8144554Sbinkertn@umich.edu # protobuf without the involvement of pkg-config. Later on we 8154554Sbinkertn@umich.edu # check go a library config check and at that point the test 8164554Sbinkertn@umich.edu # will fail if libprotobuf cannot be found. 8174554Sbinkertn@umich.edu if readCommand(['pkg-config', '--version'], exception=''): 8182667Sstever@eecs.umich.edu try: 8194554Sbinkertn@umich.edu # Attempt to establish what linking flags to add for protobuf 8202667Sstever@eecs.umich.edu # using pkg-config 8214554Sbinkertn@umich.edu main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 8226121Snate@binkert.org except: 8232667Sstever@eecs.umich.edu print termcap.Yellow + termcap.Bold + \ 8245522Snate@binkert.org 'Warning: pkg-config could not get protobuf flags.' + \ 8255522Snate@binkert.org termcap.Normal 8265522Snate@binkert.org 8275522Snate@binkert.org# Check for SWIG 8285522Snate@binkert.orgif not main.has_key('SWIG'): 8295522Snate@binkert.org print 'Error: SWIG utility not found.' 8305522Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 8315522Snate@binkert.org Exit(1) 8325522Snate@binkert.org 8335522Snate@binkert.org# Check for appropriate SWIG version 8345522Snate@binkert.orgswig_version = readCommand([main['SWIG'], '-version'], exception='').split() 8355522Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 8365522Snate@binkert.orgif len(swig_version) < 3 or \ 8375522Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 8385522Snate@binkert.org print 'Error determining SWIG version.' 8395522Snate@binkert.org Exit(1) 8405522Snate@binkert.org 8415522Snate@binkert.orgmin_swig_version = '2.0.4' 8425522Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0: 8435522Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 8445522Snate@binkert.org print ' Installed version:', swig_version[2] 8455522Snate@binkert.org Exit(1) 8465522Snate@binkert.org 8475522Snate@binkert.org# Check for known incompatibilities. The standard library shipped with 8485522Snate@binkert.org# gcc >= 4.9 does not play well with swig versions prior to 3.0 8495522Snate@binkert.orgif main['GCC'] and compareVersions(gcc_version, '4.9') >= 0 and \ 8509986Sandreas@sandberg.pp.se compareVersions(swig_version[2], '3.0') < 0: 8519986Sandreas@sandberg.pp.se print termcap.Yellow + termcap.Bold + \ 8529986Sandreas@sandberg.pp.se 'Warning: This combination of gcc and swig have' + \ 8539986Sandreas@sandberg.pp.se ' known incompatibilities.\n' + \ 8549986Sandreas@sandberg.pp.se ' If you encounter build problems, please update ' + \ 8559986Sandreas@sandberg.pp.se 'swig to 3.0 or later.' + \ 8569986Sandreas@sandberg.pp.se termcap.Normal 8579986Sandreas@sandberg.pp.se 8589986Sandreas@sandberg.pp.se# Set up SWIG flags & scanner 8599986Sandreas@sandberg.pp.seswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 8609986Sandreas@sandberg.pp.semain.Append(SWIGFLAGS=swig_flags) 8619986Sandreas@sandberg.pp.se 8629986Sandreas@sandberg.pp.se# Check for 'timeout' from GNU coreutils. If present, regressions will 8639986Sandreas@sandberg.pp.se# be run with a time limit. We require version 8.13 since we rely on 8649986Sandreas@sandberg.pp.se# support for the '--foreground' option. 8659986Sandreas@sandberg.pp.setimeout_lines = readCommand(['timeout', '--version'], 8669986Sandreas@sandberg.pp.se exception='').splitlines() 8679986Sandreas@sandberg.pp.se# Get the first line and tokenize it 8689986Sandreas@sandberg.pp.setimeout_version = timeout_lines[0].split() if timeout_lines else [] 8699986Sandreas@sandberg.pp.semain['TIMEOUT'] = timeout_version and \ 8702638Sstever@eecs.umich.edu compareVersions(timeout_version[-1], '8.13') >= 0 8712638Sstever@eecs.umich.edu 8726121Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 8733716Sstever@eecs.umich.edu# stuff for some reason 8745522Snate@binkert.orgscanners = [] 8759986Sandreas@sandberg.pp.sefor scanner in main['SCANNERS']: 8769986Sandreas@sandberg.pp.se skeys = scanner.skeys 8779986Sandreas@sandberg.pp.se if skeys == '.i': 8789986Sandreas@sandberg.pp.se continue 8795522Snate@binkert.org 8805522Snate@binkert.org if isinstance(skeys, (list, tuple)) and '.i' in skeys: 8815522Snate@binkert.org continue 8825522Snate@binkert.org 8831858SN/A scanners.append(scanner) 8845227Ssaidi@eecs.umich.edu 8855227Ssaidi@eecs.umich.edu# add the new swig scanner that we like better 8865227Ssaidi@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 8875227Ssaidi@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 8886654Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 8896654Snate@binkert.org 8907769SAli.Saidi@ARM.com# replace the scanners list that has what we want 8917769SAli.Saidi@ARM.commain['SCANNERS'] = scanners 8927769SAli.Saidi@ARM.com 8937769SAli.Saidi@ARM.com# Add a custom Check function to test for structure members. 8945227Ssaidi@eecs.umich.edudef CheckMember(context, include, decl, member, include_quotes="<>"): 8955227Ssaidi@eecs.umich.edu context.Message("Checking for member %s in %s..." % 8965227Ssaidi@eecs.umich.edu (member, decl)) 8975204Sstever@gmail.com text = """ 8985204Sstever@gmail.com#include %(header)s 8995204Sstever@gmail.comint main(){ 9005204Sstever@gmail.com %(decl)s test; 9015204Sstever@gmail.com (void)test.%(member)s; 9025204Sstever@gmail.com return 0; 9035204Sstever@gmail.com}; 9045204Sstever@gmail.com""" % { "header" : include_quotes[0] + include + include_quotes[1], 9055204Sstever@gmail.com "decl" : decl, 9065204Sstever@gmail.com "member" : member, 9075204Sstever@gmail.com } 9085204Sstever@gmail.com 9095204Sstever@gmail.com ret = context.TryCompile(text, extension=".cc") 9105204Sstever@gmail.com context.Result(ret) 9115204Sstever@gmail.com return ret 9125204Sstever@gmail.com 9135204Sstever@gmail.com# Platform-specific configuration. Note again that we assume that all 9146121Snate@binkert.org# builds under a given build root run on the same host platform. 9155204Sstever@gmail.comconf = Configure(main, 9167727SAli.Saidi@ARM.com conf_dir = joinpath(build_root, '.scons_config'), 9177727SAli.Saidi@ARM.com log_file = joinpath(build_root, 'scons_config.log'), 9187727SAli.Saidi@ARM.com custom_tests = { 9197727SAli.Saidi@ARM.com 'CheckMember' : CheckMember, 9207727SAli.Saidi@ARM.com }) 92110453SAndrew.Bardsley@arm.com 92210453SAndrew.Bardsley@arm.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 92310453SAndrew.Bardsley@arm.comtry: 92410453SAndrew.Bardsley@arm.com import platform 92510453SAndrew.Bardsley@arm.com uname = platform.uname() 92610453SAndrew.Bardsley@arm.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 92710453SAndrew.Bardsley@arm.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 92810453SAndrew.Bardsley@arm.com main.Append(CCFLAGS=['-arch', 'x86_64']) 92910453SAndrew.Bardsley@arm.com main.Append(CFLAGS=['-arch', 'x86_64']) 93010453SAndrew.Bardsley@arm.com main.Append(LINKFLAGS=['-arch', 'x86_64']) 93110453SAndrew.Bardsley@arm.com main.Append(ASFLAGS=['-arch', 'x86_64']) 93210160Sandreas.hansson@arm.comexcept: 93310453SAndrew.Bardsley@arm.com pass 93410453SAndrew.Bardsley@arm.com 93510453SAndrew.Bardsley@arm.com# Recent versions of scons substitute a "Null" object for Configure() 93610453SAndrew.Bardsley@arm.com# when configuration isn't necessary, e.g., if the "--help" option is 93710453SAndrew.Bardsley@arm.com# present. Unfortuantely this Null object always returns false, 93810453SAndrew.Bardsley@arm.com# breaking all our configuration checks. We replace it with our own 93910453SAndrew.Bardsley@arm.com# more optimistic null object that returns True instead. 94010453SAndrew.Bardsley@arm.comif not conf: 9419812Sandreas.hansson@arm.com def NullCheck(*args, **kwargs): 94210453SAndrew.Bardsley@arm.com return True 94310453SAndrew.Bardsley@arm.com 94410453SAndrew.Bardsley@arm.com class NullConf: 94510453SAndrew.Bardsley@arm.com def __init__(self, env): 94610453SAndrew.Bardsley@arm.com self.env = env 94710453SAndrew.Bardsley@arm.com def Finish(self): 94810453SAndrew.Bardsley@arm.com return self.env 94910453SAndrew.Bardsley@arm.com def __getattr__(self, mname): 95010453SAndrew.Bardsley@arm.com return NullCheck 95110453SAndrew.Bardsley@arm.com 95210453SAndrew.Bardsley@arm.com conf = NullConf(main) 95310453SAndrew.Bardsley@arm.com 9547727SAli.Saidi@ARM.com# Cache build files in the supplied directory. 95510453SAndrew.Bardsley@arm.comif main['M5_BUILD_CACHE']: 95610453SAndrew.Bardsley@arm.com print 'Using build cache located at', main['M5_BUILD_CACHE'] 95710453SAndrew.Bardsley@arm.com CacheDir(main['M5_BUILD_CACHE']) 95810453SAndrew.Bardsley@arm.com 95910453SAndrew.Bardsley@arm.comif not GetOption('without_python'): 9603118Sstever@eecs.umich.edu # Find Python include and library directories for embedding the 96110453SAndrew.Bardsley@arm.com # interpreter. We rely on python-config to resolve the appropriate 96210453SAndrew.Bardsley@arm.com # includes and linker flags. ParseConfig does not seem to understand 96310453SAndrew.Bardsley@arm.com # the more exotic linker flags such as -Xlinker and -export-dynamic so 96410453SAndrew.Bardsley@arm.com # we add them explicitly below. If you want to link in an alternate 9653118Sstever@eecs.umich.edu # version of python, see above for instructions on how to invoke 9663483Ssaidi@eecs.umich.edu # scons with the appropriate PATH set. 9673494Ssaidi@eecs.umich.edu # 9683494Ssaidi@eecs.umich.edu # First we check if python2-config exists, else we use python-config 9693483Ssaidi@eecs.umich.edu python_config = readCommand(['which', 'python2-config'], 9703483Ssaidi@eecs.umich.edu exception='').strip() 9713483Ssaidi@eecs.umich.edu if not os.path.exists(python_config): 9723053Sstever@eecs.umich.edu python_config = readCommand(['which', 'python-config'], 9733053Sstever@eecs.umich.edu exception='').strip() 9743918Ssaidi@eecs.umich.edu py_includes = readCommand([python_config, '--includes'], 9753053Sstever@eecs.umich.edu exception='').split() 9763053Sstever@eecs.umich.edu # Strip the -I from the include folders before adding them to the 9773053Sstever@eecs.umich.edu # CPPPATH 9783053Sstever@eecs.umich.edu main.Append(CPPPATH=map(lambda inc: inc[2:], py_includes)) 9793053Sstever@eecs.umich.edu 9809396Sandreas.hansson@arm.com # Read the linker flags and split them into libraries and other link 9819396Sandreas.hansson@arm.com # flags. The libraries are added later through the call the CheckLib. 9829396Sandreas.hansson@arm.com py_ld_flags = readCommand([python_config, '--ldflags'], 9839396Sandreas.hansson@arm.com exception='').split() 9849396Sandreas.hansson@arm.com py_libs = [] 9859396Sandreas.hansson@arm.com for lib in py_ld_flags: 9869396Sandreas.hansson@arm.com if not lib.startswith('-l'): 9879396Sandreas.hansson@arm.com main.Append(LINKFLAGS=[lib]) 9889396Sandreas.hansson@arm.com else: 9899477Sandreas.hansson@arm.com lib = lib[2:] 9909396Sandreas.hansson@arm.com if lib not in py_libs: 9919477Sandreas.hansson@arm.com py_libs.append(lib) 9929477Sandreas.hansson@arm.com 9939477Sandreas.hansson@arm.com # verify that this stuff works 9949477Sandreas.hansson@arm.com if not conf.CheckHeader('Python.h', '<>'): 9959396Sandreas.hansson@arm.com print "Error: can't find Python.h header in", py_includes 9967840Snate@binkert.org print "Install Python headers (package python-dev on Ubuntu and RedHat)" 9977865Sgblack@eecs.umich.edu Exit(1) 9987865Sgblack@eecs.umich.edu 9997865Sgblack@eecs.umich.edu for lib in py_libs: 10007865Sgblack@eecs.umich.edu if not conf.CheckLib(lib): 10017865Sgblack@eecs.umich.edu print "Error: can't find library %s required by python" % lib 10027840Snate@binkert.org Exit(1) 10039900Sandreas@sandberg.pp.se 10049900Sandreas@sandberg.pp.se# On Solaris you need to use libsocket for socket ops 10059900Sandreas@sandberg.pp.seif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 10069900Sandreas@sandberg.pp.se if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 100710456SCurtis.Dunham@arm.com print "Can't find library with socket calls (e.g. accept())" 100810456SCurtis.Dunham@arm.com Exit(1) 100910456SCurtis.Dunham@arm.com 101010456SCurtis.Dunham@arm.com# Check for zlib. If the check passes, libz will be automatically 101110456SCurtis.Dunham@arm.com# added to the LIBS environment variable. 101210456SCurtis.Dunham@arm.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 101310456SCurtis.Dunham@arm.com print 'Error: did not find needed zlib compression library '\ 101410456SCurtis.Dunham@arm.com 'and/or zlib.h header file.' 101510456SCurtis.Dunham@arm.com print ' Please install zlib and try again.' 101610456SCurtis.Dunham@arm.com Exit(1) 10179045SAli.Saidi@ARM.com 10187840Snate@binkert.org# If we have the protobuf compiler, also make sure we have the 10197840Snate@binkert.org# development libraries. If the check passes, libprotobuf will be 10207840Snate@binkert.org# automatically added to the LIBS environment variable. After 10211858SN/A# this, we can use the HAVE_PROTOBUF flag to determine if we have 10221858SN/A# got both protoc and libprotobuf available. 10231858SN/Amain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 10241858SN/A conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 10251858SN/A 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 10261858SN/A 10279903Sandreas.hansson@arm.com# If we have the compiler but not the library, print another warning. 10289903Sandreas.hansson@arm.comif main['PROTOC'] and not main['HAVE_PROTOBUF']: 10299903Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + \ 10309903Sandreas.hansson@arm.com 'Warning: did not find protocol buffer library and/or headers.\n' + \ 103110841Sandreas.sandberg@arm.com ' Please install libprotobuf-dev for tracing support.' + \ 10329651SAndreas.Sandberg@ARM.com termcap.Normal 10339903Sandreas.hansson@arm.com 10349651SAndreas.Sandberg@ARM.com# Check for librt. 10359651SAndreas.Sandberg@ARM.comhave_posix_clock = \ 103610841Sandreas.sandberg@arm.com conf.CheckLibWithHeader(None, 'time.h', 'C', 103710841Sandreas.sandberg@arm.com 'clock_nanosleep(0,0,NULL,NULL);') or \ 103810841Sandreas.sandberg@arm.com conf.CheckLibWithHeader('rt', 'time.h', 'C', 103910841Sandreas.sandberg@arm.com 'clock_nanosleep(0,0,NULL,NULL);') 104010841Sandreas.sandberg@arm.com 104110841Sandreas.sandberg@arm.comhave_posix_timers = \ 10429651SAndreas.Sandberg@ARM.com conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', 10439651SAndreas.Sandberg@ARM.com 'timer_create(CLOCK_MONOTONIC, NULL, NULL);') 10449651SAndreas.Sandberg@ARM.com 10459651SAndreas.Sandberg@ARM.comif not GetOption('without_tcmalloc'): 10469651SAndreas.Sandberg@ARM.com if conf.CheckLib('tcmalloc'): 10479651SAndreas.Sandberg@ARM.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 10489651SAndreas.Sandberg@ARM.com elif conf.CheckLib('tcmalloc_minimal'): 10499651SAndreas.Sandberg@ARM.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 10509651SAndreas.Sandberg@ARM.com else: 105110841Sandreas.sandberg@arm.com print termcap.Yellow + termcap.Bold + \ 105210841Sandreas.sandberg@arm.com "You can get a 12% performance improvement by "\ 105310841Sandreas.sandberg@arm.com "installing tcmalloc (libgoogle-perftools-dev package "\ 105410841Sandreas.sandberg@arm.com "on Ubuntu or RedHat)." + termcap.Normal 105510841Sandreas.sandberg@arm.com 105610841Sandreas.sandberg@arm.com 105710860Sandreas.sandberg@arm.com# Detect back trace implementations. The last implementation in the 105810841Sandreas.sandberg@arm.com# list will be used by default. 105910841Sandreas.sandberg@arm.combacktrace_impls = [ "none" ] 106010841Sandreas.sandberg@arm.com 106110841Sandreas.sandberg@arm.comif conf.CheckLibWithHeader(None, 'execinfo.h', 'C', 106210841Sandreas.sandberg@arm.com 'backtrace_symbols_fd((void*)0, 0, 0);'): 106310841Sandreas.sandberg@arm.com backtrace_impls.append("glibc") 106410841Sandreas.sandberg@arm.com 106510841Sandreas.sandberg@arm.comif backtrace_impls[-1] == "none": 106610841Sandreas.sandberg@arm.com default_backtrace_impl = "none" 106710841Sandreas.sandberg@arm.com print termcap.Yellow + termcap.Bold + \ 106810841Sandreas.sandberg@arm.com "No suitable back trace implementation found." + \ 10699651SAndreas.Sandberg@ARM.com termcap.Normal 10709651SAndreas.Sandberg@ARM.com 10719986Sandreas@sandberg.pp.seif not have_posix_clock: 10729986Sandreas@sandberg.pp.se print "Can't find library for POSIX clocks." 10739986Sandreas@sandberg.pp.se 10749986Sandreas@sandberg.pp.se# Check for <fenv.h> (C99 FP environment control) 10759986Sandreas@sandberg.pp.sehave_fenv = conf.CheckHeader('fenv.h', '<>') 10769986Sandreas@sandberg.pp.seif not have_fenv: 10775863Snate@binkert.org print "Warning: Header file <fenv.h> not found." 10785863Snate@binkert.org print " This host has no IEEE FP rounding mode control." 10795863Snate@binkert.org 10805863Snate@binkert.org# Check if we should enable KVM-based hardware virtualization. The API 10816121Snate@binkert.org# we rely on exists since version 2.6.36 of the kernel, but somehow 10821858SN/A# the KVM_API_VERSION does not reflect the change. We test for one of 10835863Snate@binkert.org# the types as a fall back. 10845863Snate@binkert.orghave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 10855863Snate@binkert.orgif not have_kvm: 10865863Snate@binkert.org print "Info: Compatible header file <linux/kvm.h> not found, " \ 10875863Snate@binkert.org "disabling KVM support." 10882139SN/A 10894202Sbinkertn@umich.edu# x86 needs support for xsave. We test for the structure here since we 10904202Sbinkertn@umich.edu# won't be able to run new tests by the time we know which ISA we're 10912139SN/A# targeting. 10926994Snate@binkert.orghave_kvm_xsave = conf.CheckTypeSize('struct kvm_xsave', 10936994Snate@binkert.org '#include <linux/kvm.h>') != 0 10946994Snate@binkert.org 10956994Snate@binkert.org# Check if the requested target ISA is compatible with the host 10966994Snate@binkert.orgdef is_isa_kvm_compatible(isa): 10976994Snate@binkert.org try: 10986994Snate@binkert.org import platform 10996994Snate@binkert.org host_isa = platform.machine() 110010319SAndreas.Sandberg@ARM.com except: 11016994Snate@binkert.org print "Warning: Failed to determine host ISA." 11026994Snate@binkert.org return False 11036994Snate@binkert.org 11046994Snate@binkert.org if not have_posix_timers: 11056994Snate@binkert.org print "Warning: Can not enable KVM, host seems to lack support " \ 11066994Snate@binkert.org "for POSIX timers" 11076994Snate@binkert.org return False 11086994Snate@binkert.org 11096994Snate@binkert.org if isa == "arm": 11106994Snate@binkert.org return host_isa in ( "armv7l", "aarch64" ) 11116994Snate@binkert.org elif isa == "x86": 11122155SN/A if host_isa != "x86_64": 11135863Snate@binkert.org return False 11141869SN/A 11151869SN/A if not have_kvm_xsave: 11165863Snate@binkert.org print "KVM on x86 requires xsave support in kernel headers." 11175863Snate@binkert.org return False 11184202Sbinkertn@umich.edu 11196108Snate@binkert.org return True 11206108Snate@binkert.org else: 11216108Snate@binkert.org return False 11226108Snate@binkert.org 11239219Spower.jg@gmail.com 11249219Spower.jg@gmail.com# Check if the exclude_host attribute is available. We want this to 11259219Spower.jg@gmail.com# get accurate instruction counts in KVM. 11269219Spower.jg@gmail.commain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember( 11279219Spower.jg@gmail.com 'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host') 11289219Spower.jg@gmail.com 11299219Spower.jg@gmail.com 11309219Spower.jg@gmail.com###################################################################### 11314202Sbinkertn@umich.edu# 11325863Snate@binkert.org# Finish the configuration 113310135SCurtis.Dunham@arm.com# 11348474Sgblack@eecs.umich.edumain = conf.Finish() 11355742Snate@binkert.org 11368268Ssteve.reinhardt@amd.com###################################################################### 11378268Ssteve.reinhardt@amd.com# 11388268Ssteve.reinhardt@amd.com# Collect all non-global variables 11395742Snate@binkert.org# 11405341Sstever@gmail.com 11418474Sgblack@eecs.umich.edu# Define the universe of supported ISAs 11428474Sgblack@eecs.umich.eduall_isa_list = [ ] 11435342Sstever@gmail.comall_gpu_isa_list = [ ] 11444202Sbinkertn@umich.eduExport('all_isa_list') 11454202Sbinkertn@umich.eduExport('all_gpu_isa_list') 11464202Sbinkertn@umich.edu 11475863Snate@binkert.orgclass CpuModel(object): 11485863Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 11496994Snate@binkert.org know about a particular CPU model.''' 11506994Snate@binkert.org 115110319SAndreas.Sandberg@ARM.com # Dict of available CPU model objects. Accessible as CpuModel.dict. 11525863Snate@binkert.org dict = {} 11535863Snate@binkert.org 11545863Snate@binkert.org # Constructor. Automatically adds models to CpuModel.dict. 11555863Snate@binkert.org def __init__(self, name, default=False): 11565863Snate@binkert.org self.name = name # name of model 11575863Snate@binkert.org 11585863Snate@binkert.org # This cpu is enabled by default 11595863Snate@binkert.org self.default = default 11607840Snate@binkert.org 11615863Snate@binkert.org # Add self to dict 11625952Ssaidi@eecs.umich.edu if name in CpuModel.dict: 11639651SAndreas.Sandberg@ARM.com raise AttributeError, "CpuModel '%s' already registered" % name 11649219Spower.jg@gmail.com CpuModel.dict[name] = self 11659219Spower.jg@gmail.com 11661869SN/AExport('CpuModel') 11671858SN/A 11685863Snate@binkert.org# Sticky variables get saved in the variables file so they persist from 11699420Sandreas.hansson@arm.com# one invocation to the next (unless overridden, in which case the new 117010607Sgabeblack@google.com# value becomes sticky). 11719986Sandreas@sandberg.pp.sesticky_vars = Variables(args=ARGUMENTS) 11721858SN/AExport('sticky_vars') 1173955SN/A 1174955SN/A# Sticky variables that should be exported 11751869SN/Aexport_vars = [] 11761869SN/AExport('export_vars') 11771869SN/A 11781869SN/A# For Ruby 11791869SN/Aall_protocols = [] 11805863Snate@binkert.orgExport('all_protocols') 11815863Snate@binkert.orgprotocol_dirs = [] 11825863Snate@binkert.orgExport('protocol_dirs') 11831869SN/Aslicc_includes = [] 11845863Snate@binkert.orgExport('slicc_includes') 11851869SN/A 11865863Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 11871869SN/A# above variables 11881869SN/Aif GetOption('verbose'): 11891869SN/A print "Reading SConsopts" 11901869SN/Afor bdir in [ base_dir ] + extras_dir_list: 11918483Sgblack@eecs.umich.edu if not isdir(bdir): 11921869SN/A print "Error: directory '%s' does not exist" % bdir 11931869SN/A Exit(1) 11941869SN/A for root, dirs, files in os.walk(bdir): 11951869SN/A if 'SConsopts' in files: 11965863Snate@binkert.org if GetOption('verbose'): 11975863Snate@binkert.org print "Reading", joinpath(root, 'SConsopts') 11981869SN/A SConscript(joinpath(root, 'SConsopts')) 11995863Snate@binkert.org 12005863Snate@binkert.orgall_isa_list.sort() 12013356Sbinkertn@umich.eduall_gpu_isa_list.sort() 12023356Sbinkertn@umich.edu 12033356Sbinkertn@umich.edusticky_vars.AddVariables( 12043356Sbinkertn@umich.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 12053356Sbinkertn@umich.edu EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'hsail', all_gpu_isa_list), 12064781Snate@binkert.org ListVariable('CPU_MODELS', 'CPU models', 12075863Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 12085863Snate@binkert.org sorted(CpuModel.dict.keys())), 12091869SN/A BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 12101869SN/A False), 12111869SN/A BoolVariable('SS_COMPATIBLE_FP', 12126121Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 12131869SN/A False), 12142638Sstever@eecs.umich.edu BoolVariable('USE_SSE2', 12156121Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 12166121Snate@binkert.org False), 12172638Sstever@eecs.umich.edu BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 12185749Scws3k@cs.virginia.edu BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 12196121Snate@binkert.org BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 12206121Snate@binkert.org BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm), 12215749Scws3k@cs.virginia.edu BoolVariable('BUILD_GPU', 'Build the compute-GPU model', False), 12229537Satgutier@umich.edu EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 12239537Satgutier@umich.edu all_protocols), 12249537Satgutier@umich.edu EnumVariable('BACKTRACE_IMPL', 'Post-mortem dump implementation', 12259537Satgutier@umich.edu backtrace_impls[-1], backtrace_impls) 12269888Sandreas@sandberg.pp.se ) 12279888Sandreas@sandberg.pp.se 12289888Sandreas@sandberg.pp.se# These variables get exported to #defines in config/*.hh (see src/SConscript). 12299888Sandreas@sandberg.pp.seexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA', 123010066Sandreas.hansson@arm.com 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'PROTOCOL', 123110066Sandreas.hansson@arm.com 'HAVE_PROTOBUF', 'HAVE_PERF_ATTR_EXCLUDE_HOST'] 123210066Sandreas.hansson@arm.com 123310066Sandreas.hansson@arm.com################################################### 123410428Sandreas.hansson@arm.com# 123510428Sandreas.hansson@arm.com# Define a SCons builder for configuration flag headers. 123610428Sandreas.hansson@arm.com# 123710428Sandreas.hansson@arm.com################################################### 12381869SN/A 12391869SN/A# This function generates a config header file that #defines the 12403546Sgblack@eecs.umich.edu# variable symbol to the current variable setting (0 or 1). The source 12413546Sgblack@eecs.umich.edu# operands are the name of the variable and a Value node containing the 12423546Sgblack@eecs.umich.edu# value of the variable. 12433546Sgblack@eecs.umich.edudef build_config_file(target, source, env): 12446121Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 124510196SCurtis.Dunham@arm.com f = file(str(target[0]), 'w') 12465863Snate@binkert.org print >> f, '#define', variable, value 12473546Sgblack@eecs.umich.edu f.close() 12483546Sgblack@eecs.umich.edu return None 12493546Sgblack@eecs.umich.edu 12503546Sgblack@eecs.umich.edu# Combine the two functions into a scons Action object. 12514781Snate@binkert.orgconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 12526658Snate@binkert.org 125310196SCurtis.Dunham@arm.com# The emitter munges the source & target node lists to reflect what 125410196SCurtis.Dunham@arm.com# we're really doing. 125510196SCurtis.Dunham@arm.comdef config_emitter(target, source, env): 125610196SCurtis.Dunham@arm.com # extract variable name from Builder arg 125710196SCurtis.Dunham@arm.com variable = str(target[0]) 125810196SCurtis.Dunham@arm.com # True target is config header file 125910196SCurtis.Dunham@arm.com target = joinpath('config', variable.lower() + '.hh') 12603546Sgblack@eecs.umich.edu val = env[variable] 12613546Sgblack@eecs.umich.edu if isinstance(val, bool): 12623546Sgblack@eecs.umich.edu # Force value to 0/1 12633546Sgblack@eecs.umich.edu val = int(val) 12647756SAli.Saidi@ARM.com elif isinstance(val, str): 12657816Ssteve.reinhardt@amd.com val = '"' + val + '"' 12663546Sgblack@eecs.umich.edu 12673546Sgblack@eecs.umich.edu # Sources are variable name & value (packaged in SCons Value nodes) 12683546Sgblack@eecs.umich.edu return ([target], [Value(variable), Value(val)]) 12693546Sgblack@eecs.umich.edu 127010196SCurtis.Dunham@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 127110196SCurtis.Dunham@arm.com 127210196SCurtis.Dunham@arm.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 127310196SCurtis.Dunham@arm.com 127410196SCurtis.Dunham@arm.com# libelf build is shared across all configs in the build root. 12754202Sbinkertn@umich.edumain.SConscript('ext/libelf/SConscript', 12763546Sgblack@eecs.umich.edu variant_dir = joinpath(build_root, 'libelf')) 127710196SCurtis.Dunham@arm.com 127810196SCurtis.Dunham@arm.com# iostream3 build is shared across all configs in the build root. 127910196SCurtis.Dunham@arm.commain.SConscript('ext/iostream3/SConscript', 128010196SCurtis.Dunham@arm.com variant_dir = joinpath(build_root, 'iostream3')) 128110196SCurtis.Dunham@arm.com 128210196SCurtis.Dunham@arm.com# libfdt build is shared across all configs in the build root. 128310196SCurtis.Dunham@arm.commain.SConscript('ext/libfdt/SConscript', 128410196SCurtis.Dunham@arm.com variant_dir = joinpath(build_root, 'libfdt')) 128510196SCurtis.Dunham@arm.com 128610196SCurtis.Dunham@arm.com# fputils build is shared across all configs in the build root. 128710196SCurtis.Dunham@arm.commain.SConscript('ext/fputils/SConscript', 128810196SCurtis.Dunham@arm.com variant_dir = joinpath(build_root, 'fputils')) 128910196SCurtis.Dunham@arm.com 129010196SCurtis.Dunham@arm.com# DRAMSim2 build is shared across all configs in the build root. 129110196SCurtis.Dunham@arm.commain.SConscript('ext/dramsim2/SConscript', 129210196SCurtis.Dunham@arm.com variant_dir = joinpath(build_root, 'dramsim2')) 129310196SCurtis.Dunham@arm.com 129410196SCurtis.Dunham@arm.com# DRAMPower build is shared across all configs in the build root. 129510196SCurtis.Dunham@arm.commain.SConscript('ext/drampower/SConscript', 129610196SCurtis.Dunham@arm.com variant_dir = joinpath(build_root, 'drampower')) 129710196SCurtis.Dunham@arm.com 129810196SCurtis.Dunham@arm.com# nomali build is shared across all configs in the build root. 129910196SCurtis.Dunham@arm.commain.SConscript('ext/nomali/SConscript', 130010196SCurtis.Dunham@arm.com variant_dir = joinpath(build_root, 'nomali')) 13013546Sgblack@eecs.umich.edu 13023546Sgblack@eecs.umich.edu################################################### 1303955SN/A# 1304955SN/A# This function is used to set up a directory with switching headers 1305955SN/A# 1306955SN/A################################################### 13075863Snate@binkert.org 130810135SCurtis.Dunham@arm.commain['ALL_ISA_LIST'] = all_isa_list 130910135SCurtis.Dunham@arm.commain['ALL_GPU_ISA_LIST'] = all_gpu_isa_list 13105343Sstever@gmail.comall_isa_deps = {} 13115343Sstever@gmail.comdef make_switching_dir(dname, switch_headers, env): 13126121Snate@binkert.org # Generate the header. target[0] is the full path of the output 13135863Snate@binkert.org # header to generate. 'source' is a dummy variable, since we get the 13144773Snate@binkert.org # list of ISAs from env['ALL_ISA_LIST']. 13155863Snate@binkert.org def gen_switch_hdr(target, source, env): 13162632Sstever@eecs.umich.edu fname = str(target[0]) 13175863Snate@binkert.org isa = env['TARGET_ISA'].lower() 13182023SN/A try: 13195863Snate@binkert.org f = open(fname, 'w') 13205863Snate@binkert.org print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 13215863Snate@binkert.org f.close() 13225863Snate@binkert.org except IOError: 13235863Snate@binkert.org print "Failed to create %s" % fname 13245863Snate@binkert.org raise 13255863Snate@binkert.org 13265863Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 132710135SCurtis.Dunham@arm.com # action depends on; when env['ALL_ISA_LIST'] changes these actions 132810135SCurtis.Dunham@arm.com # should get re-executed. 13292632Sstever@eecs.umich.edu switch_hdr_action = MakeAction(gen_switch_hdr, 13305863Snate@binkert.org Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 13312023SN/A 13322632Sstever@eecs.umich.edu # Instantiate actions for each header 13335863Snate@binkert.org for hdr in switch_headers: 13345342Sstever@gmail.com env.Command(hdr, [], switch_hdr_action) 13355863Snate@binkert.org 13362632Sstever@eecs.umich.edu isa_target = Dir('.').up().name.lower().replace('_', '-') 13375863Snate@binkert.org env['PHONY_BASE'] = '#'+isa_target 13385863Snate@binkert.org all_isa_deps[isa_target] = None 13398267Ssteve.reinhardt@amd.com 13408120Sgblack@eecs.umich.eduExport('make_switching_dir') 13418267Ssteve.reinhardt@amd.com 13428267Ssteve.reinhardt@amd.comdef make_gpu_switching_dir(dname, switch_headers, env): 13438267Ssteve.reinhardt@amd.com # Generate the header. target[0] is the full path of the output 13448267Ssteve.reinhardt@amd.com # header to generate. 'source' is a dummy variable, since we get the 13458267Ssteve.reinhardt@amd.com # list of ISAs from env['ALL_ISA_LIST']. 13468267Ssteve.reinhardt@amd.com def gen_switch_hdr(target, source, env): 13478267Ssteve.reinhardt@amd.com fname = str(target[0]) 13488267Ssteve.reinhardt@amd.com 13498267Ssteve.reinhardt@amd.com isa = env['TARGET_GPU_ISA'].lower() 13505863Snate@binkert.org 13515863Snate@binkert.org try: 13525863Snate@binkert.org f = open(fname, 'w') 13532632Sstever@eecs.umich.edu print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 13548267Ssteve.reinhardt@amd.com f.close() 13558267Ssteve.reinhardt@amd.com except IOError: 13568267Ssteve.reinhardt@amd.com print "Failed to create %s" % fname 13572632Sstever@eecs.umich.edu raise 13581888SN/A 13595863Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 13605863Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 13611858SN/A # should get re-executed. 13628120Sgblack@eecs.umich.edu switch_hdr_action = MakeAction(gen_switch_hdr, 13638120Sgblack@eecs.umich.edu Transform("GENERATE"), varlist=['ALL_ISA_GPU_LIST']) 13647756SAli.Saidi@ARM.com 13652598SN/A # Instantiate actions for each header 13665863Snate@binkert.org for hdr in switch_headers: 13671858SN/A env.Command(hdr, [], switch_hdr_action) 13681858SN/A 13691858SN/AExport('make_gpu_switching_dir') 13705863Snate@binkert.org 13711858SN/A# all-isas -> all-deps -> all-environs -> all_targets 13721858SN/Amain.Alias('#all-isas', []) 13731858SN/Amain.Alias('#all-deps', '#all-isas') 13745863Snate@binkert.org 13751871SN/A# Dummy target to ensure all environments are created before telling 13761858SN/A# SCons what to actually make (the command line arguments). We attach 13771858SN/A# them to the dependence graph after the environments are complete. 13781858SN/AORIG_BUILD_TARGETS = list(BUILD_TARGETS) # force a copy; gets closure to work. 13791858SN/Adef environsComplete(target, source, env): 13809651SAndreas.Sandberg@ARM.com for t in ORIG_BUILD_TARGETS: 13819651SAndreas.Sandberg@ARM.com main.Depends('#all-targets', t) 13829651SAndreas.Sandberg@ARM.com 13839651SAndreas.Sandberg@ARM.com# Each build/* switching_dir attaches its *-environs target to #all-environs. 13849651SAndreas.Sandberg@ARM.commain.Append(BUILDERS = {'CompleteEnvirons' : 13859651SAndreas.Sandberg@ARM.com Builder(action=MakeAction(environsComplete, None))}) 13869651SAndreas.Sandberg@ARM.commain.CompleteEnvirons('#all-environs', []) 13879651SAndreas.Sandberg@ARM.com 13889651SAndreas.Sandberg@ARM.comdef doNothing(**ignored): pass 13899986Sandreas@sandberg.pp.semain.Append(BUILDERS = {'Dummy': Builder(action=MakeAction(doNothing, None))}) 13909986Sandreas@sandberg.pp.se 13919986Sandreas@sandberg.pp.se# The final target to which all the original targets ultimately get attached. 13929986Sandreas@sandberg.pp.semain.Dummy('#all-targets', '#all-environs') 13939986Sandreas@sandberg.pp.seBUILD_TARGETS[:] = ['#all-targets'] 13949986Sandreas@sandberg.pp.se 13959986Sandreas@sandberg.pp.se################################################### 13965863Snate@binkert.org# 13975863Snate@binkert.org# Define build environments for selected configurations. 13981869SN/A# 13991965SN/A################################################### 14007739Sgblack@eecs.umich.edu 14011965SN/Afor variant_path in variant_paths: 14022761Sstever@eecs.umich.edu if not GetOption('silent'): 14035863Snate@binkert.org print "Building in", variant_path 14041869SN/A 140510196SCurtis.Dunham@arm.com # Make a copy of the build-root environment to use for this config. 14061869SN/A env = main.Clone() 140710196SCurtis.Dunham@arm.com env['BUILDDIR'] = variant_path 140810196SCurtis.Dunham@arm.com 140910196SCurtis.Dunham@arm.com # variant_dir is the tail component of build path, and is used to 141010196SCurtis.Dunham@arm.com # determine the build parameters (e.g., 'ALPHA_SE') 141110196SCurtis.Dunham@arm.com (build_root, variant_dir) = splitpath(variant_path) 141210196SCurtis.Dunham@arm.com 141310196SCurtis.Dunham@arm.com # Set env variables according to the build directory config. 141410196SCurtis.Dunham@arm.com sticky_vars.files = [] 141510196SCurtis.Dunham@arm.com # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 141610196SCurtis.Dunham@arm.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 141710196SCurtis.Dunham@arm.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 141810196SCurtis.Dunham@arm.com current_vars_file = joinpath(build_root, 'variables', variant_dir) 141910196SCurtis.Dunham@arm.com if isfile(current_vars_file): 142010196SCurtis.Dunham@arm.com sticky_vars.files.append(current_vars_file) 142110196SCurtis.Dunham@arm.com if not GetOption('silent'): 142210196SCurtis.Dunham@arm.com print "Using saved variables file %s" % current_vars_file 142310196SCurtis.Dunham@arm.com else: 1424955SN/A # Build dir-specific variables file doesn't exist. 14258120Sgblack@eecs.umich.edu 14268120Sgblack@eecs.umich.edu # Make sure the directory is there so we can create it later 14278120Sgblack@eecs.umich.edu opt_dir = dirname(current_vars_file) 14288120Sgblack@eecs.umich.edu if not isdir(opt_dir): 14298120Sgblack@eecs.umich.edu mkdir(opt_dir) 14308120Sgblack@eecs.umich.edu 14318120Sgblack@eecs.umich.edu # Get default build variables from source tree. Variables are 14328120Sgblack@eecs.umich.edu # normally determined by name of $VARIANT_DIR, but can be 14338120Sgblack@eecs.umich.edu # overridden by '--default=' arg on command line. 14348120Sgblack@eecs.umich.edu default = GetOption('default') 14358120Sgblack@eecs.umich.edu opts_dir = joinpath(main.root.abspath, 'build_opts') 14368120Sgblack@eecs.umich.edu if default: 1437 default_vars_files = [joinpath(build_root, 'variables', default), 1438 joinpath(opts_dir, default)] 1439 else: 1440 default_vars_files = [joinpath(opts_dir, variant_dir)] 1441 existing_files = filter(isfile, default_vars_files) 1442 if existing_files: 1443 default_vars_file = existing_files[0] 1444 sticky_vars.files.append(default_vars_file) 1445 print "Variables file %s not found,\n using defaults in %s" \ 1446 % (current_vars_file, default_vars_file) 1447 else: 1448 print "Error: cannot find variables file %s or " \ 1449 "default file(s) %s" \ 1450 % (current_vars_file, ' or '.join(default_vars_files)) 1451 Exit(1) 1452 1453 # Apply current variable settings to env 1454 sticky_vars.Update(env) 1455 1456 help_texts["local_vars"] += \ 1457 "Build variables for %s:\n" % variant_dir \ 1458 + sticky_vars.GenerateHelpText(env) 1459 1460 # Process variable settings. 1461 1462 if not have_fenv and env['USE_FENV']: 1463 print "Warning: <fenv.h> not available; " \ 1464 "forcing USE_FENV to False in", variant_dir + "." 1465 env['USE_FENV'] = False 1466 1467 if not env['USE_FENV']: 1468 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 1469 print " FP results may deviate slightly from other platforms." 1470 1471 if env['EFENCE']: 1472 env.Append(LIBS=['efence']) 1473 1474 if env['USE_KVM']: 1475 if not have_kvm: 1476 print "Warning: Can not enable KVM, host seems to lack KVM support" 1477 env['USE_KVM'] = False 1478 elif not is_isa_kvm_compatible(env['TARGET_ISA']): 1479 print "Info: KVM support disabled due to unsupported host and " \ 1480 "target ISA combination" 1481 env['USE_KVM'] = False 1482 1483 # Warn about missing optional functionality 1484 if env['USE_KVM']: 1485 if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']: 1486 print "Warning: perf_event headers lack support for the " \ 1487 "exclude_host attribute. KVM instruction counts will " \ 1488 "be inaccurate." 1489 1490 # Save sticky variable settings back to current variables file 1491 sticky_vars.Save(current_vars_file, env) 1492 1493 if env['USE_SSE2']: 1494 env.Append(CCFLAGS=['-msse2']) 1495 1496 # The src/SConscript file sets up the build rules in 'env' according 1497 # to the configured variables. It returns a list of environments, 1498 # one for each variant build (debug, opt, etc.) 1499 SConscript('src/SConscript', variant_dir = variant_path, exports = 'env') 1500 1501def pairwise(iterable): 1502 "s -> (s0,s1), (s1,s2), (s2, s3), ..." 1503 a, b = itertools.tee(iterable) 1504 b.next() 1505 return itertools.izip(a, b) 1506 1507# Create false dependencies so SCons will parse ISAs, establish 1508# dependencies, and setup the build Environments serially. Either 1509# SCons (likely) and/or our SConscripts (possibly) cannot cope with -j 1510# greater than 1. It appears to be standard race condition stuff; it 1511# doesn't always fail, but usually, and the behaviors are different. 1512# Every time I tried to remove this, builds would fail in some 1513# creative new way. So, don't do that. You'll want to, though, because 1514# tests/SConscript takes a long time to make its Environments. 1515for t1, t2 in pairwise(sorted(all_isa_deps.iterkeys())): 1516 main.Depends('#%s-deps' % t2, '#%s-deps' % t1) 1517 main.Depends('#%s-environs' % t2, '#%s-environs' % t1) 1518 1519# base help text 1520Help(''' 1521Usage: scons [scons options] [build variables] [target(s)] 1522 1523Extra scons options: 1524%(options)s 1525 1526Global build variables: 1527%(global_vars)s 1528 1529%(local_vars)s 1530''' % help_texts) 1531