SConstruct revision 10106
1955SN/A# -*- mode:python -*- 2955SN/A 310841Sandreas.sandberg@arm.com# Copyright (c) 2013 ARM Limited 49812Sandreas.hansson@arm.com# All rights reserved. 59812Sandreas.hansson@arm.com# 69812Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall 79812Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual 89812Sandreas.hansson@arm.com# property including but not limited to intellectual property relating 99812Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software 109812Sandreas.hansson@arm.com# licensed hereunder. You may use the software subject to the license 119812Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated 129812Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software, 139812Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form. 149812Sandreas.hansson@arm.com# 157816Ssteve.reinhardt@amd.com# Copyright (c) 2011 Advanced Micro Devices, Inc. 165871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 171762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 18955SN/A# All rights reserved. 19955SN/A# 20955SN/A# Redistribution and use in source and binary forms, with or without 21955SN/A# modification, are permitted provided that the following conditions are 22955SN/A# met: redistributions of source code must retain the above copyright 23955SN/A# notice, this list of conditions and the following disclaimer; 24955SN/A# redistributions in binary form must reproduce the above copyright 25955SN/A# notice, this list of conditions and the following disclaimer in the 26955SN/A# documentation and/or other materials provided with the distribution; 27955SN/A# neither the name of the copyright holders nor the names of its 28955SN/A# contributors may be used to endorse or promote products derived from 29955SN/A# this software without specific prior written permission. 30955SN/A# 31955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 422665Ssaidi@eecs.umich.edu# 432665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 445863Snate@binkert.org# Nathan Binkert 45955SN/A 46955SN/A################################################### 47955SN/A# 48955SN/A# SCons top-level build description (SConstruct) file. 49955SN/A# 508878Ssteve.reinhardt@amd.com# While in this directory ('gem5'), just type 'scons' to build the default 512632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 528878Ssteve.reinhardt@amd.com# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 532632Sstever@eecs.umich.edu# the optimized full-system version). 54955SN/A# 558878Ssteve.reinhardt@amd.com# You can build gem5 in a different directory as long as there is a 562632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 572761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 582632Sstever@eecs.umich.edu# built for the same host system. 592632Sstever@eecs.umich.edu# 602632Sstever@eecs.umich.edu# Examples: 612761Sstever@eecs.umich.edu# 622761Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 632761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 648878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug 658878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug 662761Sstever@eecs.umich.edu# 672761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 682761Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 692761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 702761Sstever@eecs.umich.edu# file. 718878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 728878Ssteve.reinhardt@amd.com# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug 732632Sstever@eecs.umich.edu# 742632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 758878Ssteve.reinhardt@amd.com# 'gem5' directory (or use -u or -C to tell scons where to find this 768878Ssteve.reinhardt@amd.com# file), you can use 'scons -h' to print all the gem5-specific build 772632Sstever@eecs.umich.edu# options as well. 78955SN/A# 79955SN/A################################################### 80955SN/A 815863Snate@binkert.org# Check for recent-enough Python and SCons versions. 825863Snate@binkert.orgtry: 835863Snate@binkert.org # Really old versions of scons only take two options for the 845863Snate@binkert.org # function, so check once without the revision and once with the 855863Snate@binkert.org # revision, the first instance will fail for stuff other than 865863Snate@binkert.org # 0.98, and the second will fail for 0.98.0 875863Snate@binkert.org EnsureSConsVersion(0, 98) 885863Snate@binkert.org EnsureSConsVersion(0, 98, 1) 895863Snate@binkert.orgexcept SystemExit, e: 905863Snate@binkert.org print """ 915863Snate@binkert.orgFor more details, see: 928878Ssteve.reinhardt@amd.com http://gem5.org/Dependencies 935863Snate@binkert.org""" 945863Snate@binkert.org raise 955863Snate@binkert.org 969812Sandreas.hansson@arm.com# We ensure the python version early because because python-config 979812Sandreas.hansson@arm.com# requires python 2.5 985863Snate@binkert.orgtry: 999812Sandreas.hansson@arm.com EnsurePythonVersion(2, 5) 1005863Snate@binkert.orgexcept SystemExit, e: 1015863Snate@binkert.org print """ 1025863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 1039812Sandreas.hansson@arm.comrearranging your PATH so that scons finds the non-default 'python' and 1049812Sandreas.hansson@arm.com'python-config' first. 1055863Snate@binkert.org 1065863Snate@binkert.orgFor more details, see: 1078878Ssteve.reinhardt@amd.com http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 1085863Snate@binkert.org""" 1095863Snate@binkert.org raise 1105863Snate@binkert.org 1116654Snate@binkert.org# Global Python includes 11210196SCurtis.Dunham@arm.comimport os 113955SN/Aimport re 1145396Ssaidi@eecs.umich.eduimport subprocess 1155863Snate@binkert.orgimport sys 1165863Snate@binkert.org 1174202Sbinkertn@umich.edufrom os import mkdir, environ 1185863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1195863Snate@binkert.orgfrom os.path import exists, isdir, isfile 1205863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1215863Snate@binkert.org 122955SN/A# SCons includes 1236654Snate@binkert.orgimport SCons 1245273Sstever@gmail.comimport SCons.Node 1255871Snate@binkert.org 1265273Sstever@gmail.comextra_python_paths = [ 1276655Snate@binkert.org Dir('src/python').srcnode().abspath, # gem5 includes 1288878Ssteve.reinhardt@amd.com Dir('ext/ply').srcnode().abspath, # ply is used by several files 1296655Snate@binkert.org ] 1306655Snate@binkert.org 1319219Spower.jg@gmail.comsys.path[1:1] = extra_python_paths 1326655Snate@binkert.org 1335871Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1346654Snate@binkert.orgfrom m5.util.terminal import get_termcap 1358947Sandreas.hansson@arm.com 1365396Ssaidi@eecs.umich.eduhelp_texts = { 1378120Sgblack@eecs.umich.edu "options" : "", 1388120Sgblack@eecs.umich.edu "global_vars" : "", 1398120Sgblack@eecs.umich.edu "local_vars" : "" 1408120Sgblack@eecs.umich.edu} 1418120Sgblack@eecs.umich.edu 1428120Sgblack@eecs.umich.eduExport("help_texts") 1438120Sgblack@eecs.umich.edu 1448120Sgblack@eecs.umich.edu 1458879Ssteve.reinhardt@amd.com# There's a bug in scons in that (1) by default, the help texts from 1468879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h' 1478879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the 1488879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once 1498879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get 1508879Ssteve.reinhardt@amd.com# at the help texts from AddOptions. See: 1518879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1528879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1538879Ssteve.reinhardt@amd.com# This hack lets us extract the help text from AddOptions and 1548879Ssteve.reinhardt@amd.com# re-inject it via Help(). Ideally someday this bug will be fixed and 1558879Ssteve.reinhardt@amd.com# we can just use AddOption directly. 1568879Ssteve.reinhardt@amd.comdef AddLocalOption(*args, **kwargs): 1578879Ssteve.reinhardt@amd.com col_width = 30 1588120Sgblack@eecs.umich.edu 1598120Sgblack@eecs.umich.edu help = " " + ", ".join(args) 1608120Sgblack@eecs.umich.edu if "help" in kwargs: 1618120Sgblack@eecs.umich.edu length = len(help) 1628120Sgblack@eecs.umich.edu if length >= col_width: 1638120Sgblack@eecs.umich.edu help += "\n" + " " * col_width 1648120Sgblack@eecs.umich.edu else: 1658120Sgblack@eecs.umich.edu help += " " * (col_width - length) 1668120Sgblack@eecs.umich.edu help += kwargs["help"] 1678120Sgblack@eecs.umich.edu help_texts["options"] += help + "\n" 1688120Sgblack@eecs.umich.edu 1698120Sgblack@eecs.umich.edu AddOption(*args, **kwargs) 1708120Sgblack@eecs.umich.edu 1718120Sgblack@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true', 1728879Ssteve.reinhardt@amd.com help="Add color to abbreviated scons output") 1738879Ssteve.reinhardt@amd.comAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1748879Ssteve.reinhardt@amd.com help="Don't add color to abbreviated scons output") 1758879Ssteve.reinhardt@amd.comAddLocalOption('--default', dest='default', type='string', action='store', 17610458Sandreas.hansson@arm.com help='Override which build_opts file to use for defaults') 17710458Sandreas.hansson@arm.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 17810458Sandreas.hansson@arm.com help='Disable style checking hooks') 1798879Ssteve.reinhardt@amd.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1808879Ssteve.reinhardt@amd.com help='Disable Link-Time Optimization for fast') 1818879Ssteve.reinhardt@amd.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1828879Ssteve.reinhardt@amd.com help='Update test reference outputs') 1839227Sandreas.hansson@arm.comAddLocalOption('--verbose', dest='verbose', action='store_true', 1849227Sandreas.hansson@arm.com help='Print full tool command lines') 1858879Ssteve.reinhardt@amd.com 1868879Ssteve.reinhardt@amd.comtermcap = get_termcap(GetOption('use_colors')) 1878879Ssteve.reinhardt@amd.com 1888879Ssteve.reinhardt@amd.com######################################################################## 18910453SAndrew.Bardsley@arm.com# 19010453SAndrew.Bardsley@arm.com# Set up the main build environment. 19110453SAndrew.Bardsley@arm.com# 19210456SCurtis.Dunham@arm.com######################################################################## 19310456SCurtis.Dunham@arm.com 19410456SCurtis.Dunham@arm.com# export TERM so that clang reports errors in color 19510457Sandreas.hansson@arm.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 19610457Sandreas.hansson@arm.com 'LIBRARY_PATH', 'PATH', 'PKG_CONFIG_PATH', 'PROTOC', 1978120Sgblack@eecs.umich.edu 'PYTHONPATH', 'RANLIB', 'SWIG', 'TERM' ]) 1988947Sandreas.hansson@arm.com 1997816Ssteve.reinhardt@amd.comuse_prefixes = [ 2005871Snate@binkert.org "M5", # M5 configuration (e.g., path to kernels) 2015871Snate@binkert.org "DISTCC_", # distcc (distributed compiler wrapper) configuration 2026121Snate@binkert.org "CCACHE_", # ccache (caching compiler wrapper) configuration 2035871Snate@binkert.org "CCC_", # clang static analyzer configuration 2045871Snate@binkert.org ] 2059926Sstan.czerniawski@arm.com 2069926Sstan.czerniawski@arm.comuse_env = {} 2079119Sandreas.hansson@arm.comfor key,val in os.environ.iteritems(): 20810068Sandreas.hansson@arm.com if key in use_vars or \ 20910068Sandreas.hansson@arm.com any([key.startswith(prefix) for prefix in use_prefixes]): 210955SN/A use_env[key] = val 2119416SAndreas.Sandberg@ARM.com 21211212Sjoseph.gross@amd.commain = Environment(ENV=use_env) 21311212Sjoseph.gross@amd.commain.Decider('MD5-timestamp') 21411212Sjoseph.gross@amd.commain.root = Dir(".") # The current directory (where this file lives). 21511212Sjoseph.gross@amd.commain.srcdir = Dir("src") # The source directory 21611212Sjoseph.gross@amd.com 2179416SAndreas.Sandberg@ARM.commain_dict_keys = main.Dictionary().keys() 2189416SAndreas.Sandberg@ARM.com 2195871Snate@binkert.org# Check that we have a C/C++ compiler 22010584Sandreas.hansson@arm.comif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 2219416SAndreas.Sandberg@ARM.com print "No C++ compiler installed (package g++ on Ubuntu and RedHat)" 2229416SAndreas.Sandberg@ARM.com Exit(1) 2235871Snate@binkert.org 224955SN/A# Check that swig is present 22510671Sandreas.hansson@arm.comif not 'SWIG' in main_dict_keys: 22610671Sandreas.hansson@arm.com print "swig is not installed (package swig on Ubuntu and RedHat)" 22710671Sandreas.hansson@arm.com Exit(1) 22810671Sandreas.hansson@arm.com 2298881Smarc.orr@gmail.com# add useful python code PYTHONPATH so it can be used by subprocesses 2306121Snate@binkert.org# as well 2316121Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths) 2321533SN/A 2339239Sandreas.hansson@arm.com######################################################################## 2349239Sandreas.hansson@arm.com# 2359239Sandreas.hansson@arm.com# Mercurial Stuff. 2369239Sandreas.hansson@arm.com# 2379239Sandreas.hansson@arm.com# If the gem5 directory is a mercurial repository, we should do some 2389239Sandreas.hansson@arm.com# extra things. 2399239Sandreas.hansson@arm.com# 2409239Sandreas.hansson@arm.com######################################################################## 2419239Sandreas.hansson@arm.com 2429239Sandreas.hansson@arm.comhgdir = main.root.Dir(".hg") 2439239Sandreas.hansson@arm.com 2449239Sandreas.hansson@arm.commercurial_style_message = """ 2456655Snate@binkert.orgYou're missing the gem5 style hook, which automatically checks your code 2466655Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands. This 2476655Snate@binkert.orgscript will now install the hook in your .hg/hgrc file. 2486655Snate@binkert.orgPress enter to continue, or ctrl-c to abort: """ 2495871Snate@binkert.org 2505871Snate@binkert.orgmercurial_style_hook = """ 2515863Snate@binkert.org# The following lines were automatically added by gem5/SConstruct 2525871Snate@binkert.org# to provide the gem5 style-checking hooks 2538878Ssteve.reinhardt@amd.com[extensions] 2545871Snate@binkert.orgstyle = %s/util/style.py 2555871Snate@binkert.org 2565871Snate@binkert.org[hooks] 2575863Snate@binkert.orgpretxncommit.style = python:style.check_style 2586121Snate@binkert.orgpre-qrefresh.style = python:style.check_style 2595863Snate@binkert.org# End of SConstruct additions 2605871Snate@binkert.org 2618336Ssteve.reinhardt@amd.com""" % (main.root.abspath) 2628336Ssteve.reinhardt@amd.com 2638336Ssteve.reinhardt@amd.commercurial_lib_not_found = """ 2648336Ssteve.reinhardt@amd.comMercurial libraries cannot be found, ignoring style hook. If 2654678Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 2668336Ssteve.reinhardt@amd.comhook. It is important. 2678336Ssteve.reinhardt@amd.com""" 2688336Ssteve.reinhardt@amd.com 2694678Snate@binkert.org# Check for style hook and prompt for installation if it's not there. 2704678Snate@binkert.org# Skip this if --ignore-style was specified, there's no .hg dir to 2714678Snate@binkert.org# install a hook in, or there's no interactive terminal to prompt. 2724678Snate@binkert.orgif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2737827Snate@binkert.org style_hook = True 2747827Snate@binkert.org try: 2758336Ssteve.reinhardt@amd.com from mercurial import ui 2764678Snate@binkert.org ui = ui.ui() 2778336Ssteve.reinhardt@amd.com ui.readconfig(hgdir.File('hgrc').abspath) 2788336Ssteve.reinhardt@amd.com style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2798336Ssteve.reinhardt@amd.com ui.config('hooks', 'pre-qrefresh.style', None) 2808336Ssteve.reinhardt@amd.com except ImportError: 2818336Ssteve.reinhardt@amd.com print mercurial_lib_not_found 2828336Ssteve.reinhardt@amd.com 2835871Snate@binkert.org if not style_hook: 2845871Snate@binkert.org print mercurial_style_message, 2858336Ssteve.reinhardt@amd.com # continue unless user does ctrl-c/ctrl-d etc. 2868336Ssteve.reinhardt@amd.com try: 2878336Ssteve.reinhardt@amd.com raw_input() 2888336Ssteve.reinhardt@amd.com except: 2898336Ssteve.reinhardt@amd.com print "Input exception, exiting scons.\n" 2905871Snate@binkert.org sys.exit(1) 2918336Ssteve.reinhardt@amd.com hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2928336Ssteve.reinhardt@amd.com print "Adding style hook to", hgrc_path, "\n" 2938336Ssteve.reinhardt@amd.com try: 2948336Ssteve.reinhardt@amd.com hgrc = open(hgrc_path, 'a') 2958336Ssteve.reinhardt@amd.com hgrc.write(mercurial_style_hook) 2964678Snate@binkert.org hgrc.close() 2975871Snate@binkert.org except: 2984678Snate@binkert.org print "Error updating", hgrc_path 2998336Ssteve.reinhardt@amd.com sys.exit(1) 3008336Ssteve.reinhardt@amd.com 3018336Ssteve.reinhardt@amd.com 3028336Ssteve.reinhardt@amd.com################################################### 3038336Ssteve.reinhardt@amd.com# 3048336Ssteve.reinhardt@amd.com# Figure out which configurations to set up based on the path(s) of 3058336Ssteve.reinhardt@amd.com# the target(s). 3068336Ssteve.reinhardt@amd.com# 3078336Ssteve.reinhardt@amd.com################################################### 3088336Ssteve.reinhardt@amd.com 3098336Ssteve.reinhardt@amd.com# Find default configuration & binary. 3108336Ssteve.reinhardt@amd.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 3118336Ssteve.reinhardt@amd.com 3128336Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list 3138336Ssteve.reinhardt@amd.comdef rfind(l, elt, offs = -1): 3148336Ssteve.reinhardt@amd.com for i in range(len(l)+offs, 0, -1): 3158336Ssteve.reinhardt@amd.com if l[i] == elt: 3165871Snate@binkert.org return i 3176121Snate@binkert.org raise ValueError, "element not found" 318955SN/A 319955SN/A# Take a list of paths (or SCons Nodes) and return a list with all 3202632Sstever@eecs.umich.edu# paths made absolute and ~-expanded. Paths will be interpreted 3212632Sstever@eecs.umich.edu# relative to the launch directory unless a different root is provided 322955SN/Adef makePathListAbsolute(path_list, root=GetLaunchDir()): 323955SN/A return [abspath(joinpath(root, expanduser(str(p)))) 324955SN/A for p in path_list] 325955SN/A 3268878Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the 327955SN/A# directory below this will determine the build parameters. For 3282632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 3292632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 3302632Sstever@eecs.umich.edu# follow 'build' in the build path. 3312632Sstever@eecs.umich.edu 3322632Sstever@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 3332632Sstever@eecs.umich.edu# in place rather than reassign the symbol to a new list, which 3342632Sstever@eecs.umich.edu# doesn't work (obviously!). 3358268Ssteve.reinhardt@amd.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 3368268Ssteve.reinhardt@amd.com 3378268Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the 3388268Ssteve.reinhardt@amd.com# collected targets reference. 3398268Ssteve.reinhardt@amd.comvariant_paths = [] 3408268Ssteve.reinhardt@amd.combuild_root = None 3418268Ssteve.reinhardt@amd.comfor t in BUILD_TARGETS: 3422632Sstever@eecs.umich.edu path_dirs = t.split('/') 3432632Sstever@eecs.umich.edu try: 3442632Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 3452632Sstever@eecs.umich.edu except: 3468268Ssteve.reinhardt@amd.com print "Error: no non-leaf 'build' dir found on target path", t 3472632Sstever@eecs.umich.edu Exit(1) 3488268Ssteve.reinhardt@amd.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3498268Ssteve.reinhardt@amd.com if not build_root: 3508268Ssteve.reinhardt@amd.com build_root = this_build_root 3518268Ssteve.reinhardt@amd.com else: 3523718Sstever@eecs.umich.edu if this_build_root != build_root: 3532634Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 3542634Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 3555863Snate@binkert.org Exit(1) 3562638Sstever@eecs.umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 3578268Ssteve.reinhardt@amd.com if variant_path not in variant_paths: 3582632Sstever@eecs.umich.edu variant_paths.append(variant_path) 3592632Sstever@eecs.umich.edu 3602632Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 3612632Sstever@eecs.umich.eduif not isdir(build_root): 3622632Sstever@eecs.umich.edu mkdir(build_root) 3631858SN/Amain['BUILDROOT'] = build_root 3643716Sstever@eecs.umich.edu 3652638Sstever@eecs.umich.eduExport('main') 3662638Sstever@eecs.umich.edu 3672638Sstever@eecs.umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 3682638Sstever@eecs.umich.edu 3692638Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 3702638Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 3712638Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 3725863Snate@binkert.org# (soft) links work better. 3735863Snate@binkert.orgmain.SetOption('duplicate', 'soft-copy') 3745863Snate@binkert.org 375955SN/A# 3765341Sstever@gmail.com# Set up global sticky variables... these are common to an entire build 3775341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE) 3785863Snate@binkert.org# 3797756SAli.Saidi@ARM.com 3805341Sstever@gmail.comglobal_vars_file = joinpath(build_root, 'variables.global') 3816121Snate@binkert.org 3824494Ssaidi@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3836121Snate@binkert.org 3841105SN/Aglobal_vars.AddVariables( 3852667Sstever@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3862667Sstever@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3872667Sstever@eecs.umich.edu ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 3882667Sstever@eecs.umich.edu ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 3896121Snate@binkert.org ('BATCH', 'Use batch pool for build and tests', False), 3902667Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3915341Sstever@gmail.com ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3925863Snate@binkert.org ('EXTRAS', 'Add extra directories to the compilation', '') 3935341Sstever@gmail.com ) 3945341Sstever@gmail.com 3955341Sstever@gmail.com# Update main environment with values from ARGUMENTS & global_vars_file 3968120Sgblack@eecs.umich.eduglobal_vars.Update(main) 3975341Sstever@gmail.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3988120Sgblack@eecs.umich.edu 3995341Sstever@gmail.com# Save sticky variable settings back to current variables file 4008120Sgblack@eecs.umich.eduglobal_vars.Save(global_vars_file, main) 4016121Snate@binkert.org 4026121Snate@binkert.org# Parse EXTRAS variable to build list of all directories where we're 4038980Ssteve.reinhardt@amd.com# look for sources etc. This list is exported as extras_dir_list. 4049396Sandreas.hansson@arm.combase_dir = main.srcdir.abspath 4055397Ssaidi@eecs.umich.eduif main['EXTRAS']: 4065397Ssaidi@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 4077727SAli.Saidi@ARM.comelse: 4088268Ssteve.reinhardt@amd.com extras_dir_list = [] 4096168Snate@binkert.org 4105341Sstever@gmail.comExport('base_dir') 4118120Sgblack@eecs.umich.eduExport('extras_dir_list') 4128120Sgblack@eecs.umich.edu 4138120Sgblack@eecs.umich.edu# the ext directory should be on the #includes path 4146814Sgblack@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 4155863Snate@binkert.org 4168120Sgblack@eecs.umich.edudef strip_build_path(path, env): 4175341Sstever@gmail.com path = str(path) 4185863Snate@binkert.org variant_base = env['BUILDROOT'] + os.path.sep 4198268Ssteve.reinhardt@amd.com if path.startswith(variant_base): 4206121Snate@binkert.org path = path[len(variant_base):] 4216121Snate@binkert.org elif path.startswith('build/'): 4228268Ssteve.reinhardt@amd.com path = path[6:] 4235742Snate@binkert.org return path 4245742Snate@binkert.org 4255341Sstever@gmail.com# Generate a string of the form: 4265742Snate@binkert.org# common/path/prefix/src1, src2 -> tgt1, tgt2 4275742Snate@binkert.org# to print while building. 4285341Sstever@gmail.comclass Transform(object): 4296017Snate@binkert.org # all specific color settings should be here and nowhere else 4306121Snate@binkert.org tool_color = termcap.Normal 4316017Snate@binkert.org pfx_color = termcap.Yellow 4327816Ssteve.reinhardt@amd.com srcs_color = termcap.Yellow + termcap.Bold 4337756SAli.Saidi@ARM.com arrow_color = termcap.Blue + termcap.Bold 4347756SAli.Saidi@ARM.com tgts_color = termcap.Yellow + termcap.Bold 4357756SAli.Saidi@ARM.com 4367756SAli.Saidi@ARM.com def __init__(self, tool, max_sources=99): 4377756SAli.Saidi@ARM.com self.format = self.tool_color + (" [%8s] " % tool) \ 4387756SAli.Saidi@ARM.com + self.pfx_color + "%s" \ 4397756SAli.Saidi@ARM.com + self.srcs_color + "%s" \ 4407756SAli.Saidi@ARM.com + self.arrow_color + " -> " \ 4417816Ssteve.reinhardt@amd.com + self.tgts_color + "%s" \ 4427816Ssteve.reinhardt@amd.com + termcap.Normal 4437816Ssteve.reinhardt@amd.com self.max_sources = max_sources 4447816Ssteve.reinhardt@amd.com 4457816Ssteve.reinhardt@amd.com def __call__(self, target, source, env, for_signature=None): 4467816Ssteve.reinhardt@amd.com # truncate source list according to max_sources param 4477816Ssteve.reinhardt@amd.com source = source[0:self.max_sources] 4487816Ssteve.reinhardt@amd.com def strip(f): 4497816Ssteve.reinhardt@amd.com return strip_build_path(str(f), env) 4507816Ssteve.reinhardt@amd.com if len(source) > 0: 4517756SAli.Saidi@ARM.com srcs = map(strip, source) 4527816Ssteve.reinhardt@amd.com else: 4537816Ssteve.reinhardt@amd.com srcs = [''] 4547816Ssteve.reinhardt@amd.com tgts = map(strip, target) 4557816Ssteve.reinhardt@amd.com # surprisingly, os.path.commonprefix is a dumb char-by-char string 4567816Ssteve.reinhardt@amd.com # operation that has nothing to do with paths. 4577816Ssteve.reinhardt@amd.com com_pfx = os.path.commonprefix(srcs + tgts) 4587816Ssteve.reinhardt@amd.com com_pfx_len = len(com_pfx) 4597816Ssteve.reinhardt@amd.com if com_pfx: 4607816Ssteve.reinhardt@amd.com # do some cleanup and sanity checking on common prefix 4617816Ssteve.reinhardt@amd.com if com_pfx[-1] == ".": 4627816Ssteve.reinhardt@amd.com # prefix matches all but file extension: ok 4637816Ssteve.reinhardt@amd.com # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4647816Ssteve.reinhardt@amd.com com_pfx = com_pfx[0:-1] 4657816Ssteve.reinhardt@amd.com elif com_pfx[-1] == "/": 4667816Ssteve.reinhardt@amd.com # common prefix is directory path: OK 4677816Ssteve.reinhardt@amd.com pass 4687816Ssteve.reinhardt@amd.com else: 4697816Ssteve.reinhardt@amd.com src0_len = len(srcs[0]) 4707816Ssteve.reinhardt@amd.com tgt0_len = len(tgts[0]) 4717816Ssteve.reinhardt@amd.com if src0_len == com_pfx_len: 4727816Ssteve.reinhardt@amd.com # source is a substring of target, OK 4737816Ssteve.reinhardt@amd.com pass 4747816Ssteve.reinhardt@amd.com elif tgt0_len == com_pfx_len: 4757816Ssteve.reinhardt@amd.com # target is a substring of source, need to back up to 4767816Ssteve.reinhardt@amd.com # avoid empty string on RHS of arrow 4777816Ssteve.reinhardt@amd.com sep_idx = com_pfx.rfind(".") 4787816Ssteve.reinhardt@amd.com if sep_idx != -1: 4797816Ssteve.reinhardt@amd.com com_pfx = com_pfx[0:sep_idx] 4807816Ssteve.reinhardt@amd.com else: 4817816Ssteve.reinhardt@amd.com com_pfx = '' 4827816Ssteve.reinhardt@amd.com elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4837816Ssteve.reinhardt@amd.com # still splitting at file extension: ok 4847816Ssteve.reinhardt@amd.com pass 4857816Ssteve.reinhardt@amd.com else: 4867816Ssteve.reinhardt@amd.com # probably a fluke; ignore it 4877816Ssteve.reinhardt@amd.com com_pfx = '' 4887816Ssteve.reinhardt@amd.com # recalculate length in case com_pfx was modified 4897816Ssteve.reinhardt@amd.com com_pfx_len = len(com_pfx) 4907816Ssteve.reinhardt@amd.com def fmt(files): 4917816Ssteve.reinhardt@amd.com f = map(lambda s: s[com_pfx_len:], files) 4927816Ssteve.reinhardt@amd.com return ', '.join(f) 4937816Ssteve.reinhardt@amd.com return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4947816Ssteve.reinhardt@amd.com 4957816Ssteve.reinhardt@amd.comExport('Transform') 4967816Ssteve.reinhardt@amd.com 4977816Ssteve.reinhardt@amd.com# enable the regression script to use the termcap 4987816Ssteve.reinhardt@amd.commain['TERMCAP'] = termcap 4997816Ssteve.reinhardt@amd.com 5007816Ssteve.reinhardt@amd.comif GetOption('verbose'): 5017816Ssteve.reinhardt@amd.com def MakeAction(action, string, *args, **kwargs): 5027816Ssteve.reinhardt@amd.com return Action(action, *args, **kwargs) 5037816Ssteve.reinhardt@amd.comelse: 5047816Ssteve.reinhardt@amd.com MakeAction = Action 5057816Ssteve.reinhardt@amd.com main['CCCOMSTR'] = Transform("CC") 5067816Ssteve.reinhardt@amd.com main['CXXCOMSTR'] = Transform("CXX") 5077816Ssteve.reinhardt@amd.com main['ASCOMSTR'] = Transform("AS") 5087816Ssteve.reinhardt@amd.com main['SWIGCOMSTR'] = Transform("SWIG") 5097816Ssteve.reinhardt@amd.com main['ARCOMSTR'] = Transform("AR", 0) 5107816Ssteve.reinhardt@amd.com main['LINKCOMSTR'] = Transform("LINK", 0) 5117816Ssteve.reinhardt@amd.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 5127816Ssteve.reinhardt@amd.com main['M4COMSTR'] = Transform("M4") 5138947Sandreas.hansson@arm.com main['SHCCCOMSTR'] = Transform("SHCC") 5148947Sandreas.hansson@arm.com main['SHCXXCOMSTR'] = Transform("SHCXX") 5157756SAli.Saidi@ARM.comExport('MakeAction') 5168120Sgblack@eecs.umich.edu 5177756SAli.Saidi@ARM.com# Initialize the Link-Time Optimization (LTO) flags 5187756SAli.Saidi@ARM.commain['LTO_CCFLAGS'] = [] 5197756SAli.Saidi@ARM.commain['LTO_LDFLAGS'] = [] 5207756SAli.Saidi@ARM.com 5217816Ssteve.reinhardt@amd.com# According to the readme, tcmalloc works best if the compiler doesn't 5227816Ssteve.reinhardt@amd.com# assume that we're using the builtin malloc and friends. These flags 5237816Ssteve.reinhardt@amd.com# are compiler-specific, so we need to set them after we detect which 5247816Ssteve.reinhardt@amd.com# compiler we're using. 5257816Ssteve.reinhardt@amd.commain['TCMALLOC_CCFLAGS'] = [] 5267816Ssteve.reinhardt@amd.com 5277816Ssteve.reinhardt@amd.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 5287816Ssteve.reinhardt@amd.comCXX_V = readCommand([main['CXX'],'-V'], exception=False) 5297816Ssteve.reinhardt@amd.com 5307816Ssteve.reinhardt@amd.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 5317756SAli.Saidi@ARM.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 5327756SAli.Saidi@ARM.comif main['GCC'] + main['CLANG'] > 1: 5339227Sandreas.hansson@arm.com print 'Error: How can we have two at the same time?' 5349227Sandreas.hansson@arm.com Exit(1) 5359227Sandreas.hansson@arm.com 5369227Sandreas.hansson@arm.com# Set up default C++ compiler flags 5379590Sandreas@sandberg.pp.seif main['GCC'] or main['CLANG']: 5389590Sandreas@sandberg.pp.se # As gcc and clang share many flags, do the common parts here 5399590Sandreas@sandberg.pp.se main.Append(CCFLAGS=['-pipe']) 5409590Sandreas@sandberg.pp.se main.Append(CCFLAGS=['-fno-strict-aliasing']) 5419590Sandreas@sandberg.pp.se # Enable -Wall and then disable the few warnings that we 5429590Sandreas@sandberg.pp.se # consistently violate 5436654Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5446654Snate@binkert.org # We always compile using C++11, but only gcc >= 4.7 and clang 3.1 5455871Snate@binkert.org # actually use that name, so we stick with c++0x 5466121Snate@binkert.org main.Append(CXXFLAGS=['-std=c++0x']) 5478946Sandreas.hansson@arm.com # Add selected sanity checks from -Wextra 5489419Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-Wmissing-field-initializers', 5493940Ssaidi@eecs.umich.edu '-Woverloaded-virtual']) 5503918Ssaidi@eecs.umich.eduelse: 5513918Ssaidi@eecs.umich.edu print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 5521858SN/A print "Don't know what compiler options to use for your compiler." 5539556Sandreas.hansson@arm.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 5549556Sandreas.hansson@arm.com print termcap.Yellow + ' version:' + termcap.Normal, 5559556Sandreas.hansson@arm.com if not CXX_version: 5569556Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 55711294Sandreas.hansson@arm.com termcap.Normal 55811294Sandreas.hansson@arm.com else: 55911294Sandreas.hansson@arm.com print CXX_version.replace('\n', '<nl>') 56011294Sandreas.hansson@arm.com print " If you're trying to use a compiler other than GCC" 56110878Sandreas.hansson@arm.com print " or clang, there appears to be something wrong with your" 56210878Sandreas.hansson@arm.com print " environment." 5639556Sandreas.hansson@arm.com print " " 5649556Sandreas.hansson@arm.com print " If you are trying to use a compiler other than those listed" 5659556Sandreas.hansson@arm.com print " above you will need to ease fix SConstruct and " 5669556Sandreas.hansson@arm.com print " src/SConscript to support that compiler." 5679556Sandreas.hansson@arm.com Exit(1) 5689556Sandreas.hansson@arm.com 5699556Sandreas.hansson@arm.comif main['GCC']: 5709556Sandreas.hansson@arm.com # Check for a supported version of gcc, >= 4.4 is needed for c++0x 5719556Sandreas.hansson@arm.com # support. See http://gcc.gnu.org/projects/cxx0x.html for details 5729556Sandreas.hansson@arm.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5739556Sandreas.hansson@arm.com if compareVersions(gcc_version, "4.4") < 0: 5749556Sandreas.hansson@arm.com print 'Error: gcc version 4.4 or newer required.' 5759556Sandreas.hansson@arm.com print ' Installed version:', gcc_version 5769556Sandreas.hansson@arm.com Exit(1) 5779556Sandreas.hansson@arm.com 5789556Sandreas.hansson@arm.com main['GCC_VERSION'] = gcc_version 5799556Sandreas.hansson@arm.com 5809556Sandreas.hansson@arm.com # Check for versions with bugs 5819556Sandreas.hansson@arm.com if not compareVersions(gcc_version, '4.4.1') or \ 5826121Snate@binkert.org not compareVersions(gcc_version, '4.4.2'): 58310878Sandreas.hansson@arm.com print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 58410238Sandreas.hansson@arm.com main.Append(CCFLAGS=['-fno-tree-vectorize']) 58510878Sandreas.hansson@arm.com 5869420Sandreas.hansson@arm.com # LTO support is only really working properly from 4.6 and beyond 58710878Sandreas.hansson@arm.com if compareVersions(gcc_version, '4.6') >= 0: 58810878Sandreas.hansson@arm.com # Add the appropriate Link-Time Optimization (LTO) flags 5899420Sandreas.hansson@arm.com # unless LTO is explicitly turned off. Note that these flags 5909420Sandreas.hansson@arm.com # are only used by the fast target. 5919420Sandreas.hansson@arm.com if not GetOption('no_lto'): 5929420Sandreas.hansson@arm.com # Pass the LTO flag when compiling to produce GIMPLE 5939420Sandreas.hansson@arm.com # output, we merely create the flags here and only append 59410264Sandreas.hansson@arm.com # them later/ 59510264Sandreas.hansson@arm.com main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 59610264Sandreas.hansson@arm.com 59710264Sandreas.hansson@arm.com # Use the same amount of jobs for LTO as we are running 59810264Sandreas.hansson@arm.com # scons with, we hardcode the use of the linker plugin 59910866Sandreas.hansson@arm.com # which requires either gold or GNU ld >= 2.21 60010866Sandreas.hansson@arm.com main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'), 60110264Sandreas.hansson@arm.com '-fuse-linker-plugin'] 60210866Sandreas.hansson@arm.com 60310866Sandreas.hansson@arm.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 60410866Sandreas.hansson@arm.com '-fno-builtin-realloc', '-fno-builtin-free']) 60510866Sandreas.hansson@arm.com 60610866Sandreas.hansson@arm.comelif main['CLANG']: 60710866Sandreas.hansson@arm.com # Check for a supported version of clang, >= 2.9 is needed to 60810866Sandreas.hansson@arm.com # support similar features as gcc 4.4. See 60910264Sandreas.hansson@arm.com # http://clang.llvm.org/cxx_status.html for details 61010264Sandreas.hansson@arm.com clang_version_re = re.compile(".* version (\d+\.\d+)") 61110264Sandreas.hansson@arm.com clang_version_match = clang_version_re.search(CXX_version) 61210264Sandreas.hansson@arm.com if (clang_version_match): 61310264Sandreas.hansson@arm.com clang_version = clang_version_match.groups()[0] 61410264Sandreas.hansson@arm.com if compareVersions(clang_version, "2.9") < 0: 61510264Sandreas.hansson@arm.com print 'Error: clang version 2.9 or newer required.' 61610457Sandreas.hansson@arm.com print ' Installed version:', clang_version 61710457Sandreas.hansson@arm.com Exit(1) 61810457Sandreas.hansson@arm.com else: 61910457Sandreas.hansson@arm.com print 'Error: Unable to determine clang version.' 62010457Sandreas.hansson@arm.com Exit(1) 62110457Sandreas.hansson@arm.com 62210457Sandreas.hansson@arm.com # clang has a few additional warnings that we disable, 62310457Sandreas.hansson@arm.com # tautological comparisons are allowed due to unsigned integers 62410457Sandreas.hansson@arm.com # being compared to constants that happen to be 0, and extraneous 62510238Sandreas.hansson@arm.com # parantheses are allowed due to Ruby's printing of the AST, 62610238Sandreas.hansson@arm.com # finally self assignments are allowed as the generated CPU code 62710238Sandreas.hansson@arm.com # is relying on this 62810238Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-tautological-compare', 62910238Sandreas.hansson@arm.com '-Wno-parentheses', 63010238Sandreas.hansson@arm.com '-Wno-self-assign']) 63110416Sandreas.hansson@arm.com 63210238Sandreas.hansson@arm.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 6339227Sandreas.hansson@arm.com 63410238Sandreas.hansson@arm.com # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 63510416Sandreas.hansson@arm.com # opposed to libstdc++, as the later is dated. 63610416Sandreas.hansson@arm.com if sys.platform == "darwin": 6379227Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-stdlib=libc++']) 6389590Sandreas@sandberg.pp.se main.Append(LIBS=['c++']) 6399590Sandreas@sandberg.pp.se 6409590Sandreas@sandberg.pp.seelse: 6418737Skoansin.tan@gmail.com print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 64210878Sandreas.hansson@arm.com print "Don't know what compiler options to use for your compiler." 64310878Sandreas.hansson@arm.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 6449420Sandreas.hansson@arm.com print termcap.Yellow + ' version:' + termcap.Normal, 6458737Skoansin.tan@gmail.com if not CXX_version: 64610106SMitch.Hayenga@arm.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 6478737Skoansin.tan@gmail.com termcap.Normal 6488737Skoansin.tan@gmail.com else: 64910878Sandreas.hansson@arm.com print CXX_version.replace('\n', '<nl>') 65010878Sandreas.hansson@arm.com print " If you're trying to use a compiler other than GCC" 6518737Skoansin.tan@gmail.com print " or clang, there appears to be something wrong with your" 6528737Skoansin.tan@gmail.com print " environment." 6538737Skoansin.tan@gmail.com print " " 6548737Skoansin.tan@gmail.com print " If you are trying to use a compiler other than those listed" 6558737Skoansin.tan@gmail.com print " above you will need to ease fix SConstruct and " 6568737Skoansin.tan@gmail.com print " src/SConscript to support that compiler." 65711294Sandreas.hansson@arm.com Exit(1) 6589556Sandreas.hansson@arm.com 6599556Sandreas.hansson@arm.com# Set up common yacc/bison flags (needed for Ruby) 6609556Sandreas.hansson@arm.commain['YACCFLAGS'] = '-d' 66111294Sandreas.hansson@arm.commain['YACCHXXFILESUFFIX'] = '.hh' 66210278SAndreas.Sandberg@ARM.com 66310278SAndreas.Sandberg@ARM.com# Do this after we save setting back, or else we'll tack on an 66410278SAndreas.Sandberg@ARM.com# extra 'qdo' every time we run scons. 66510278SAndreas.Sandberg@ARM.comif main['BATCH']: 66610278SAndreas.Sandberg@ARM.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 66710278SAndreas.Sandberg@ARM.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 6689556Sandreas.hansson@arm.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 6699590Sandreas@sandberg.pp.se main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 6709590Sandreas@sandberg.pp.se main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 6719420Sandreas.hansson@arm.com 6729846Sandreas.hansson@arm.comif sys.platform == 'cygwin': 6739846Sandreas.hansson@arm.com # cygwin has some header file issues... 6749846Sandreas.hansson@arm.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 6759846Sandreas.hansson@arm.com 6768946Sandreas.hansson@arm.com# Check for the protobuf compiler 6773918Ssaidi@eecs.umich.eduprotoc_version = readCommand([main['PROTOC'], '--version'], 6789068SAli.Saidi@ARM.com exception='').split() 6799068SAli.Saidi@ARM.com 6809068SAli.Saidi@ARM.com# First two words should be "libprotoc x.y.z" 6819068SAli.Saidi@ARM.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 6829068SAli.Saidi@ARM.com print termcap.Yellow + termcap.Bold + \ 6839068SAli.Saidi@ARM.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + \ 6849068SAli.Saidi@ARM.com ' Please install protobuf-compiler for tracing support.' + \ 6859068SAli.Saidi@ARM.com termcap.Normal 6869068SAli.Saidi@ARM.com main['PROTOC'] = False 6879419Sandreas.hansson@arm.comelse: 6889068SAli.Saidi@ARM.com # Based on the availability of the compress stream wrappers, 6899068SAli.Saidi@ARM.com # require 2.1.0 6909068SAli.Saidi@ARM.com min_protoc_version = '2.1.0' 6919068SAli.Saidi@ARM.com if compareVersions(protoc_version[1], min_protoc_version) < 0: 6929068SAli.Saidi@ARM.com print termcap.Yellow + termcap.Bold + \ 6939068SAli.Saidi@ARM.com 'Warning: protoc version', min_protoc_version, \ 6943918Ssaidi@eecs.umich.edu 'or newer required.\n' + \ 6953918Ssaidi@eecs.umich.edu ' Installed version:', protoc_version[1], \ 6966157Snate@binkert.org termcap.Normal 6976157Snate@binkert.org main['PROTOC'] = False 6986157Snate@binkert.org else: 6996157Snate@binkert.org # Attempt to determine the appropriate include path and 7005397Ssaidi@eecs.umich.edu # library path using pkg-config, that means we also need to 7015397Ssaidi@eecs.umich.edu # check for pkg-config. Note that it is possible to use 7026121Snate@binkert.org # protobuf without the involvement of pkg-config. Later on we 7036121Snate@binkert.org # check go a library config check and at that point the test 7046121Snate@binkert.org # will fail if libprotobuf cannot be found. 7056121Snate@binkert.org if readCommand(['pkg-config', '--version'], exception=''): 7066121Snate@binkert.org try: 7076121Snate@binkert.org # Attempt to establish what linking flags to add for protobuf 7085397Ssaidi@eecs.umich.edu # using pkg-config 7091851SN/A main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 7101851SN/A except: 7117739Sgblack@eecs.umich.edu print termcap.Yellow + termcap.Bold + \ 712955SN/A 'Warning: pkg-config could not get protobuf flags.' + \ 7139396Sandreas.hansson@arm.com termcap.Normal 7149396Sandreas.hansson@arm.com 7159396Sandreas.hansson@arm.com# Check for SWIG 7169396Sandreas.hansson@arm.comif not main.has_key('SWIG'): 7179396Sandreas.hansson@arm.com print 'Error: SWIG utility not found.' 7189396Sandreas.hansson@arm.com print ' Please install (see http://www.swig.org) and retry.' 7199396Sandreas.hansson@arm.com Exit(1) 7209396Sandreas.hansson@arm.com 7219396Sandreas.hansson@arm.com# Check for appropriate SWIG version 7229396Sandreas.hansson@arm.comswig_version = readCommand([main['SWIG'], '-version'], exception='').split() 7239396Sandreas.hansson@arm.com# First 3 words should be "SWIG Version x.y.z" 7249396Sandreas.hansson@arm.comif len(swig_version) < 3 or \ 7259396Sandreas.hansson@arm.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 7269396Sandreas.hansson@arm.com print 'Error determining SWIG version.' 7279396Sandreas.hansson@arm.com Exit(1) 7289396Sandreas.hansson@arm.com 7299477Sandreas.hansson@arm.commin_swig_version = '1.3.34' 7309477Sandreas.hansson@arm.comif compareVersions(swig_version[2], min_swig_version) < 0: 7319477Sandreas.hansson@arm.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 7329477Sandreas.hansson@arm.com print ' Installed version:', swig_version[2] 7339477Sandreas.hansson@arm.com Exit(1) 7349477Sandreas.hansson@arm.com 7359477Sandreas.hansson@arm.com# Older versions of swig do not play well with more recent versions of 7369477Sandreas.hansson@arm.com# gcc due to assumptions on implicit includes (cstddef) and use of 7379477Sandreas.hansson@arm.com# namespaces 7389477Sandreas.hansson@arm.comif main['GCC'] and compareVersions(gcc_version, '4.6') > 0 and \ 7399477Sandreas.hansson@arm.com compareVersions(swig_version[2], '2') < 0: 7409477Sandreas.hansson@arm.com print '\n' + termcap.Yellow + termcap.Bold + \ 7419477Sandreas.hansson@arm.com 'Warning: SWIG 1.x cause issues with gcc 4.6 and later.\n' + \ 7429477Sandreas.hansson@arm.com termcap.Normal + \ 7439477Sandreas.hansson@arm.com 'Use SWIG 2.x to avoid assumptions on implicit includes\n' + \ 7449477Sandreas.hansson@arm.com 'and use of namespaces\n' 7459477Sandreas.hansson@arm.com 7469477Sandreas.hansson@arm.com# Set up SWIG flags & scanner 7479477Sandreas.hansson@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 7489477Sandreas.hansson@arm.commain.Append(SWIGFLAGS=swig_flags) 7499477Sandreas.hansson@arm.com 7509477Sandreas.hansson@arm.com# filter out all existing swig scanners, they mess up the dependency 7519396Sandreas.hansson@arm.com# stuff for some reason 7523053Sstever@eecs.umich.eduscanners = [] 7536121Snate@binkert.orgfor scanner in main['SCANNERS']: 7543053Sstever@eecs.umich.edu skeys = scanner.skeys 7553053Sstever@eecs.umich.edu if skeys == '.i': 7563053Sstever@eecs.umich.edu continue 7573053Sstever@eecs.umich.edu 7583053Sstever@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 7599072Sandreas.hansson@arm.com continue 7603053Sstever@eecs.umich.edu 7614742Sstever@eecs.umich.edu scanners.append(scanner) 7624742Sstever@eecs.umich.edu 7633053Sstever@eecs.umich.edu# add the new swig scanner that we like better 7643053Sstever@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 7653053Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 76610181SCurtis.Dunham@arm.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 7676654Snate@binkert.org 7683053Sstever@eecs.umich.edu# replace the scanners list that has what we want 7693053Sstever@eecs.umich.edumain['SCANNERS'] = scanners 7703053Sstever@eecs.umich.edu 7713053Sstever@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 77210425Sandreas.hansson@arm.com# figure out if the compiler adds leading underscores to global 77310425Sandreas.hansson@arm.com# variables. This is needed for the autogenerated asm files that we 77410425Sandreas.hansson@arm.com# use for embedding the python code. 77510425Sandreas.hansson@arm.comdef CheckLeading(context): 77610425Sandreas.hansson@arm.com context.Message("Checking for leading underscore in global variables...") 77710425Sandreas.hansson@arm.com # 1) Define a global variable called x from asm so the C compiler 77810425Sandreas.hansson@arm.com # won't change the symbol at all. 77910425Sandreas.hansson@arm.com # 2) Declare that variable. 78010425Sandreas.hansson@arm.com # 3) Use the variable 78110425Sandreas.hansson@arm.com # 78210425Sandreas.hansson@arm.com # If the compiler prepends an underscore, this will successfully 7832667Sstever@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 7844554Sbinkertn@umich.edu # was defined by the asm statement. If the compiler does not 7856121Snate@binkert.org # prepend an underscore, this will not successfully link because 7862667Sstever@eecs.umich.edu # '_x' will have been defined by assembly, while the C portion of 78710710Sandreas.hansson@arm.com # the code will be trying to use 'x' 78810710Sandreas.hansson@arm.com ret = context.TryLink(''' 78910710Sandreas.hansson@arm.com asm(".globl _x; _x: .byte 0"); 79010710Sandreas.hansson@arm.com extern int x; 79110710Sandreas.hansson@arm.com int main() { return x; } 79210710Sandreas.hansson@arm.com ''', extension=".c") 79310710Sandreas.hansson@arm.com context.env.Append(LEADING_UNDERSCORE=ret) 79410710Sandreas.hansson@arm.com context.Result(ret) 79510710Sandreas.hansson@arm.com return ret 79610384SCurtis.Dunham@arm.com 7974554Sbinkertn@umich.edu# Add a custom Check function to test for structure members. 7984554Sbinkertn@umich.edudef CheckMember(context, include, decl, member, include_quotes="<>"): 7994554Sbinkertn@umich.edu context.Message("Checking for member %s in %s..." % 8006121Snate@binkert.org (member, decl)) 8014554Sbinkertn@umich.edu text = """ 8024554Sbinkertn@umich.edu#include %(header)s 8034554Sbinkertn@umich.eduint main(){ 8044781Snate@binkert.org %(decl)s test; 8054554Sbinkertn@umich.edu (void)test.%(member)s; 8064554Sbinkertn@umich.edu return 0; 8072667Sstever@eecs.umich.edu}; 8084554Sbinkertn@umich.edu""" % { "header" : include_quotes[0] + include + include_quotes[1], 8094554Sbinkertn@umich.edu "decl" : decl, 8104554Sbinkertn@umich.edu "member" : member, 8114554Sbinkertn@umich.edu } 8122667Sstever@eecs.umich.edu 8134554Sbinkertn@umich.edu ret = context.TryCompile(text, extension=".cc") 8142667Sstever@eecs.umich.edu context.Result(ret) 8154554Sbinkertn@umich.edu return ret 8166121Snate@binkert.org 8172667Sstever@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 8189986Sandreas@sandberg.pp.se# builds under a given build root run on the same host platform. 8199986Sandreas@sandberg.pp.seconf = Configure(main, 8209986Sandreas@sandberg.pp.se conf_dir = joinpath(build_root, '.scons_config'), 8219986Sandreas@sandberg.pp.se log_file = joinpath(build_root, 'scons_config.log'), 8229986Sandreas@sandberg.pp.se custom_tests = { 8239986Sandreas@sandberg.pp.se 'CheckLeading' : CheckLeading, 8249986Sandreas@sandberg.pp.se 'CheckMember' : CheckMember, 8259986Sandreas@sandberg.pp.se }) 8269986Sandreas@sandberg.pp.se 8279986Sandreas@sandberg.pp.se# Check for leading underscores. Don't really need to worry either 8289986Sandreas@sandberg.pp.se# way so don't need to check the return code. 8299986Sandreas@sandberg.pp.seconf.CheckLeading() 8309986Sandreas@sandberg.pp.se 8319986Sandreas@sandberg.pp.se# Check if we should compile a 64 bit binary on Mac OS X/Darwin 8329986Sandreas@sandberg.pp.setry: 8339986Sandreas@sandberg.pp.se import platform 8349986Sandreas@sandberg.pp.se uname = platform.uname() 8359986Sandreas@sandberg.pp.se if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 8369986Sandreas@sandberg.pp.se if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 8379986Sandreas@sandberg.pp.se main.Append(CCFLAGS=['-arch', 'x86_64']) 8382638Sstever@eecs.umich.edu main.Append(CFLAGS=['-arch', 'x86_64']) 8392638Sstever@eecs.umich.edu main.Append(LINKFLAGS=['-arch', 'x86_64']) 8406121Snate@binkert.org main.Append(ASFLAGS=['-arch', 'x86_64']) 8413716Sstever@eecs.umich.eduexcept: 8425522Snate@binkert.org pass 8439986Sandreas@sandberg.pp.se 8449986Sandreas@sandberg.pp.se# Recent versions of scons substitute a "Null" object for Configure() 8459986Sandreas@sandberg.pp.se# when configuration isn't necessary, e.g., if the "--help" option is 8465522Snate@binkert.org# present. Unfortuantely this Null object always returns false, 8475227Ssaidi@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 8485227Ssaidi@eecs.umich.edu# more optimistic null object that returns True instead. 8495227Ssaidi@eecs.umich.eduif not conf: 8505227Ssaidi@eecs.umich.edu def NullCheck(*args, **kwargs): 8516654Snate@binkert.org return True 8526654Snate@binkert.org 8537769SAli.Saidi@ARM.com class NullConf: 8547769SAli.Saidi@ARM.com def __init__(self, env): 8557769SAli.Saidi@ARM.com self.env = env 8567769SAli.Saidi@ARM.com def Finish(self): 8575227Ssaidi@eecs.umich.edu return self.env 8585227Ssaidi@eecs.umich.edu def __getattr__(self, mname): 8595227Ssaidi@eecs.umich.edu return NullCheck 8605204Sstever@gmail.com 8615204Sstever@gmail.com conf = NullConf(main) 8625204Sstever@gmail.com 8635204Sstever@gmail.com# Cache build files in the supplied directory. 8645204Sstever@gmail.comif main['M5_BUILD_CACHE']: 8655204Sstever@gmail.com print 'Using build cache located at', main['M5_BUILD_CACHE'] 8665204Sstever@gmail.com CacheDir(main['M5_BUILD_CACHE']) 8675204Sstever@gmail.com 8685204Sstever@gmail.com# Find Python include and library directories for embedding the 8695204Sstever@gmail.com# interpreter. We rely on python-config to resolve the appropriate 8705204Sstever@gmail.com# includes and linker flags. ParseConfig does not seem to understand 8715204Sstever@gmail.com# the more exotic linker flags such as -Xlinker and -export-dynamic so 8725204Sstever@gmail.com# we add them explicitly below. If you want to link in an alternate 8735204Sstever@gmail.com# version of python, see above for instructions on how to invoke 8745204Sstever@gmail.com# scons with the appropriate PATH set. 8755204Sstever@gmail.compy_includes = readCommand(['python-config', '--includes'], 8765204Sstever@gmail.com exception='').split() 8776121Snate@binkert.org# Strip the -I from the include folders before adding them to the 8785204Sstever@gmail.com# CPPPATH 8797727SAli.Saidi@ARM.commain.Append(CPPPATH=map(lambda inc: inc[2:], py_includes)) 8807727SAli.Saidi@ARM.com 8817727SAli.Saidi@ARM.com# Read the linker flags and split them into libraries and other link 8827727SAli.Saidi@ARM.com# flags. The libraries are added later through the call the CheckLib. 8837727SAli.Saidi@ARM.compy_ld_flags = readCommand(['python-config', '--ldflags'], exception='').split() 88410453SAndrew.Bardsley@arm.compy_libs = [] 88510453SAndrew.Bardsley@arm.comfor lib in py_ld_flags: 88610453SAndrew.Bardsley@arm.com if not lib.startswith('-l'): 88710453SAndrew.Bardsley@arm.com main.Append(LINKFLAGS=[lib]) 88810453SAndrew.Bardsley@arm.com else: 88910453SAndrew.Bardsley@arm.com lib = lib[2:] 89010453SAndrew.Bardsley@arm.com if lib not in py_libs: 89110453SAndrew.Bardsley@arm.com py_libs.append(lib) 89210453SAndrew.Bardsley@arm.com 89310453SAndrew.Bardsley@arm.com# verify that this stuff works 89410453SAndrew.Bardsley@arm.comif not conf.CheckHeader('Python.h', '<>'): 89510160Sandreas.hansson@arm.com print "Error: can't find Python.h header in", py_includes 89610453SAndrew.Bardsley@arm.com print "Install Python headers (package python-dev on Ubuntu and RedHat)" 89710453SAndrew.Bardsley@arm.com Exit(1) 89810453SAndrew.Bardsley@arm.com 89910453SAndrew.Bardsley@arm.comfor lib in py_libs: 90010453SAndrew.Bardsley@arm.com if not conf.CheckLib(lib): 90110453SAndrew.Bardsley@arm.com print "Error: can't find library %s required by python" % lib 90210453SAndrew.Bardsley@arm.com Exit(1) 90310453SAndrew.Bardsley@arm.com 9049812Sandreas.hansson@arm.com# On Solaris you need to use libsocket for socket ops 90510453SAndrew.Bardsley@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 90610453SAndrew.Bardsley@arm.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 90710453SAndrew.Bardsley@arm.com print "Can't find library with socket calls (e.g. accept())" 90810453SAndrew.Bardsley@arm.com Exit(1) 90910453SAndrew.Bardsley@arm.com 91010453SAndrew.Bardsley@arm.com# Check for zlib. If the check passes, libz will be automatically 91110453SAndrew.Bardsley@arm.com# added to the LIBS environment variable. 91210453SAndrew.Bardsley@arm.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 91310453SAndrew.Bardsley@arm.com print 'Error: did not find needed zlib compression library '\ 91410453SAndrew.Bardsley@arm.com 'and/or zlib.h header file.' 91510453SAndrew.Bardsley@arm.com print ' Please install zlib and try again.' 91610453SAndrew.Bardsley@arm.com Exit(1) 9177727SAli.Saidi@ARM.com 91810453SAndrew.Bardsley@arm.com# If we have the protobuf compiler, also make sure we have the 91910453SAndrew.Bardsley@arm.com# development libraries. If the check passes, libprotobuf will be 92010453SAndrew.Bardsley@arm.com# automatically added to the LIBS environment variable. After 92110453SAndrew.Bardsley@arm.com# this, we can use the HAVE_PROTOBUF flag to determine if we have 92210453SAndrew.Bardsley@arm.com# got both protoc and libprotobuf available. 9233118Sstever@eecs.umich.edumain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 92410453SAndrew.Bardsley@arm.com conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 92510453SAndrew.Bardsley@arm.com 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 92610453SAndrew.Bardsley@arm.com 92710453SAndrew.Bardsley@arm.com# If we have the compiler but not the library, print another warning. 9283118Sstever@eecs.umich.eduif main['PROTOC'] and not main['HAVE_PROTOBUF']: 9293483Ssaidi@eecs.umich.edu print termcap.Yellow + termcap.Bold + \ 9303494Ssaidi@eecs.umich.edu 'Warning: did not find protocol buffer library and/or headers.\n' + \ 9313494Ssaidi@eecs.umich.edu ' Please install libprotobuf-dev for tracing support.' + \ 9323483Ssaidi@eecs.umich.edu termcap.Normal 9333483Ssaidi@eecs.umich.edu 9343483Ssaidi@eecs.umich.edu# Check for librt. 9353053Sstever@eecs.umich.eduhave_posix_clock = \ 9363053Sstever@eecs.umich.edu conf.CheckLibWithHeader(None, 'time.h', 'C', 9373918Ssaidi@eecs.umich.edu 'clock_nanosleep(0,0,NULL,NULL);') or \ 9383053Sstever@eecs.umich.edu conf.CheckLibWithHeader('rt', 'time.h', 'C', 9393053Sstever@eecs.umich.edu 'clock_nanosleep(0,0,NULL,NULL);') 9403053Sstever@eecs.umich.edu 9413053Sstever@eecs.umich.eduhave_posix_timers = \ 9423053Sstever@eecs.umich.edu conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', 9439396Sandreas.hansson@arm.com 'timer_create(CLOCK_MONOTONIC, NULL, NULL);') 9449396Sandreas.hansson@arm.com 9459396Sandreas.hansson@arm.comif conf.CheckLib('tcmalloc'): 9469396Sandreas.hansson@arm.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 9479396Sandreas.hansson@arm.comelif conf.CheckLib('tcmalloc_minimal'): 9489396Sandreas.hansson@arm.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 9499396Sandreas.hansson@arm.comelse: 9509396Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + \ 9519396Sandreas.hansson@arm.com "You can get a 12% performance improvement by installing tcmalloc "\ 9529477Sandreas.hansson@arm.com "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \ 9539396Sandreas.hansson@arm.com termcap.Normal 9549477Sandreas.hansson@arm.com 9559477Sandreas.hansson@arm.comif not have_posix_clock: 9569477Sandreas.hansson@arm.com print "Can't find library for POSIX clocks." 9579477Sandreas.hansson@arm.com 9589396Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control) 9597840Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>') 9607865Sgblack@eecs.umich.eduif not have_fenv: 9617865Sgblack@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 9627865Sgblack@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 9637865Sgblack@eecs.umich.edu 9647865Sgblack@eecs.umich.edu# Check if we should enable KVM-based hardware virtualization. The API 9657840Snate@binkert.org# we rely on exists since version 2.6.36 of the kernel, but somehow 9669900Sandreas@sandberg.pp.se# the KVM_API_VERSION does not reflect the change. We test for one of 9679900Sandreas@sandberg.pp.se# the types as a fall back. 9689900Sandreas@sandberg.pp.sehave_kvm = conf.CheckHeader('linux/kvm.h', '<>') and \ 9699900Sandreas@sandberg.pp.se conf.CheckTypeSize('struct kvm_xsave', '#include <linux/kvm.h>') != 0 97010456SCurtis.Dunham@arm.comif not have_kvm: 97110456SCurtis.Dunham@arm.com print "Info: Compatible header file <linux/kvm.h> not found, " \ 97210456SCurtis.Dunham@arm.com "disabling KVM support." 97310456SCurtis.Dunham@arm.com 97410456SCurtis.Dunham@arm.com# Check if the requested target ISA is compatible with the host 97510456SCurtis.Dunham@arm.comdef is_isa_kvm_compatible(isa): 97610456SCurtis.Dunham@arm.com isa_comp_table = { 97710456SCurtis.Dunham@arm.com "arm" : ( "armv7l" ), 97810456SCurtis.Dunham@arm.com "x86" : ( "x86_64" ), 97910456SCurtis.Dunham@arm.com } 9809045SAli.Saidi@ARM.com try: 98111235Sandreas.sandberg@arm.com import platform 98211235Sandreas.sandberg@arm.com host_isa = platform.machine() 98311235Sandreas.sandberg@arm.com except: 98411235Sandreas.sandberg@arm.com print "Warning: Failed to determine host ISA." 98511235Sandreas.sandberg@arm.com return False 98611235Sandreas.sandberg@arm.com 98711235Sandreas.sandberg@arm.com return host_isa in isa_comp_table.get(isa, []) 98811235Sandreas.sandberg@arm.com 98911235Sandreas.sandberg@arm.com 99011235Sandreas.sandberg@arm.com# Check if the exclude_host attribute is available. We want this to 99111235Sandreas.sandberg@arm.com# get accurate instruction counts in KVM. 99211235Sandreas.sandberg@arm.commain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember( 99311235Sandreas.sandberg@arm.com 'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host') 99411235Sandreas.sandberg@arm.com 99511235Sandreas.sandberg@arm.com 9967840Snate@binkert.org###################################################################### 9977840Snate@binkert.org# 9987840Snate@binkert.org# Finish the configuration 9991858SN/A# 10001858SN/Amain = conf.Finish() 10011858SN/A 10021858SN/A###################################################################### 10031858SN/A# 10041858SN/A# Collect all non-global variables 10059903Sandreas.hansson@arm.com# 10069903Sandreas.hansson@arm.com 10079903Sandreas.hansson@arm.com# Define the universe of supported ISAs 10089903Sandreas.hansson@arm.comall_isa_list = [ ] 100910841Sandreas.sandberg@arm.comExport('all_isa_list') 10109651SAndreas.Sandberg@ARM.com 10119903Sandreas.hansson@arm.comclass CpuModel(object): 10129651SAndreas.Sandberg@ARM.com '''The CpuModel class encapsulates everything the ISA parser needs to 10139651SAndreas.Sandberg@ARM.com know about a particular CPU model.''' 101410841Sandreas.sandberg@arm.com 101510841Sandreas.sandberg@arm.com # Dict of available CPU model objects. Accessible as CpuModel.dict. 101610841Sandreas.sandberg@arm.com dict = {} 101710841Sandreas.sandberg@arm.com list = [] 101810841Sandreas.sandberg@arm.com defaults = [] 101910841Sandreas.sandberg@arm.com 10209651SAndreas.Sandberg@ARM.com # Constructor. Automatically adds models to CpuModel.dict. 10219651SAndreas.Sandberg@ARM.com def __init__(self, name, filename, includes, strings, default=False): 10229651SAndreas.Sandberg@ARM.com self.name = name # name of model 10239651SAndreas.Sandberg@ARM.com self.filename = filename # filename for output exec code 10249651SAndreas.Sandberg@ARM.com self.includes = includes # include files needed in exec file 10259651SAndreas.Sandberg@ARM.com # The 'strings' dict holds all the per-CPU symbols we can 10269651SAndreas.Sandberg@ARM.com # substitute into templates etc. 10279651SAndreas.Sandberg@ARM.com self.strings = strings 10289651SAndreas.Sandberg@ARM.com 102910841Sandreas.sandberg@arm.com # This cpu is enabled by default 103010841Sandreas.sandberg@arm.com self.default = default 103110841Sandreas.sandberg@arm.com 103210841Sandreas.sandberg@arm.com # Add self to dict 103310841Sandreas.sandberg@arm.com if name in CpuModel.dict: 103410841Sandreas.sandberg@arm.com raise AttributeError, "CpuModel '%s' already registered" % name 103510860Sandreas.sandberg@arm.com CpuModel.dict[name] = self 103610841Sandreas.sandberg@arm.com CpuModel.list.append(name) 103710841Sandreas.sandberg@arm.com 103810841Sandreas.sandberg@arm.comExport('CpuModel') 103910841Sandreas.sandberg@arm.com 104010841Sandreas.sandberg@arm.com# Sticky variables get saved in the variables file so they persist from 104110841Sandreas.sandberg@arm.com# one invocation to the next (unless overridden, in which case the new 104210841Sandreas.sandberg@arm.com# value becomes sticky). 104310841Sandreas.sandberg@arm.comsticky_vars = Variables(args=ARGUMENTS) 104410841Sandreas.sandberg@arm.comExport('sticky_vars') 104510841Sandreas.sandberg@arm.com 104610841Sandreas.sandberg@arm.com# Sticky variables that should be exported 10479651SAndreas.Sandberg@ARM.comexport_vars = [] 10489651SAndreas.Sandberg@ARM.comExport('export_vars') 10499986Sandreas@sandberg.pp.se 10509986Sandreas@sandberg.pp.se# For Ruby 10519986Sandreas@sandberg.pp.seall_protocols = [] 10529986Sandreas@sandberg.pp.seExport('all_protocols') 10539986Sandreas@sandberg.pp.seprotocol_dirs = [] 10549986Sandreas@sandberg.pp.seExport('protocol_dirs') 10555863Snate@binkert.orgslicc_includes = [] 10565863Snate@binkert.orgExport('slicc_includes') 10575863Snate@binkert.org 10585863Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 10596121Snate@binkert.org# above variables 10601858SN/Aif not GetOption('verbose'): 10615863Snate@binkert.org print "Reading SConsopts" 10625863Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list: 10635863Snate@binkert.org if not isdir(bdir): 10645863Snate@binkert.org print "Error: directory '%s' does not exist" % bdir 10655863Snate@binkert.org Exit(1) 10662139SN/A for root, dirs, files in os.walk(bdir): 10674202Sbinkertn@umich.edu if 'SConsopts' in files: 10684202Sbinkertn@umich.edu if GetOption('verbose'): 10692139SN/A print "Reading", joinpath(root, 'SConsopts') 10706994Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 10716994Snate@binkert.org 10726994Snate@binkert.orgall_isa_list.sort() 10736994Snate@binkert.org 10746994Snate@binkert.orgsticky_vars.AddVariables( 10756994Snate@binkert.org EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 10766994Snate@binkert.org ListVariable('CPU_MODELS', 'CPU models', 10776994Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 107810319SAndreas.Sandberg@ARM.com sorted(CpuModel.list)), 10796994Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 10806994Snate@binkert.org False), 10816994Snate@binkert.org BoolVariable('SS_COMPATIBLE_FP', 10826994Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 10836994Snate@binkert.org False), 10846994Snate@binkert.org BoolVariable('USE_SSE2', 10856994Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 10866994Snate@binkert.org False), 10876994Snate@binkert.org BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 10886994Snate@binkert.org BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 10896994Snate@binkert.org BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 10902155SN/A BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', have_kvm), 10915863Snate@binkert.org EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 10921869SN/A all_protocols), 10931869SN/A ) 10945863Snate@binkert.org 10955863Snate@binkert.org# These variables get exported to #defines in config/*.hh (see src/SConscript). 10964202Sbinkertn@umich.eduexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'CP_ANNOTATE', 10976108Snate@binkert.org 'USE_POSIX_CLOCK', 'PROTOCOL', 'HAVE_PROTOBUF', 10986108Snate@binkert.org 'HAVE_PERF_ATTR_EXCLUDE_HOST'] 10996108Snate@binkert.org 11006108Snate@binkert.org################################################### 11019219Spower.jg@gmail.com# 11029219Spower.jg@gmail.com# Define a SCons builder for configuration flag headers. 11039219Spower.jg@gmail.com# 11049219Spower.jg@gmail.com################################################### 11059219Spower.jg@gmail.com 11069219Spower.jg@gmail.com# This function generates a config header file that #defines the 11079219Spower.jg@gmail.com# variable symbol to the current variable setting (0 or 1). The source 11089219Spower.jg@gmail.com# operands are the name of the variable and a Value node containing the 11094202Sbinkertn@umich.edu# value of the variable. 11105863Snate@binkert.orgdef build_config_file(target, source, env): 111110135SCurtis.Dunham@arm.com (variable, value) = [s.get_contents() for s in source] 11128474Sgblack@eecs.umich.edu f = file(str(target[0]), 'w') 11135742Snate@binkert.org print >> f, '#define', variable, value 11148268Ssteve.reinhardt@amd.com f.close() 11158268Ssteve.reinhardt@amd.com return None 11168268Ssteve.reinhardt@amd.com 11175742Snate@binkert.org# Combine the two functions into a scons Action object. 11185341Sstever@gmail.comconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 11198474Sgblack@eecs.umich.edu 11208474Sgblack@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 11215342Sstever@gmail.com# we're really doing. 11224202Sbinkertn@umich.edudef config_emitter(target, source, env): 11234202Sbinkertn@umich.edu # extract variable name from Builder arg 11244202Sbinkertn@umich.edu variable = str(target[0]) 11255863Snate@binkert.org # True target is config header file 11265863Snate@binkert.org target = joinpath('config', variable.lower() + '.hh') 11276994Snate@binkert.org val = env[variable] 11286994Snate@binkert.org if isinstance(val, bool): 112910319SAndreas.Sandberg@ARM.com # Force value to 0/1 11305863Snate@binkert.org val = int(val) 11315863Snate@binkert.org elif isinstance(val, str): 11325863Snate@binkert.org val = '"' + val + '"' 11335863Snate@binkert.org 11345863Snate@binkert.org # Sources are variable name & value (packaged in SCons Value nodes) 11355863Snate@binkert.org return ([target], [Value(variable), Value(val)]) 11365863Snate@binkert.org 11375863Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 11387840Snate@binkert.org 11395863Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 11405952Ssaidi@eecs.umich.edu 11419651SAndreas.Sandberg@ARM.com# libelf build is shared across all configs in the build root. 11429219Spower.jg@gmail.commain.SConscript('ext/libelf/SConscript', 11439219Spower.jg@gmail.com variant_dir = joinpath(build_root, 'libelf')) 114411235Sandreas.sandberg@arm.com 114511235Sandreas.sandberg@arm.com# gzstream build is shared across all configs in the build root. 11461869SN/Amain.SConscript('ext/gzstream/SConscript', 11471858SN/A variant_dir = joinpath(build_root, 'gzstream')) 11485863Snate@binkert.org 11499420Sandreas.hansson@arm.com# libfdt build is shared across all configs in the build root. 115010607Sgabeblack@google.commain.SConscript('ext/libfdt/SConscript', 11519986Sandreas@sandberg.pp.se variant_dir = joinpath(build_root, 'libfdt')) 11521858SN/A 1153955SN/A# fputils build is shared across all configs in the build root. 1154955SN/Amain.SConscript('ext/fputils/SConscript', 11551869SN/A variant_dir = joinpath(build_root, 'fputils')) 11561869SN/A 11571869SN/A# DRAMSim2 build is shared across all configs in the build root. 11581869SN/Amain.SConscript('ext/dramsim2/SConscript', 11591869SN/A variant_dir = joinpath(build_root, 'dramsim2')) 11605863Snate@binkert.org 11615863Snate@binkert.org################################################### 11625863Snate@binkert.org# 11631869SN/A# This function is used to set up a directory with switching headers 11645863Snate@binkert.org# 11651869SN/A################################################### 11665863Snate@binkert.org 11671869SN/Amain['ALL_ISA_LIST'] = all_isa_list 11681869SN/Adef make_switching_dir(dname, switch_headers, env): 11691869SN/A # Generate the header. target[0] is the full path of the output 11701869SN/A # header to generate. 'source' is a dummy variable, since we get the 11718483Sgblack@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 11721869SN/A def gen_switch_hdr(target, source, env): 11731869SN/A fname = str(target[0]) 11741869SN/A f = open(fname, 'w') 11751869SN/A isa = env['TARGET_ISA'].lower() 11765863Snate@binkert.org print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 11775863Snate@binkert.org f.close() 11781869SN/A 11795863Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 11805863Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 11813356Sbinkertn@umich.edu # should get re-executed. 11823356Sbinkertn@umich.edu switch_hdr_action = MakeAction(gen_switch_hdr, 11833356Sbinkertn@umich.edu Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 11843356Sbinkertn@umich.edu 11853356Sbinkertn@umich.edu # Instantiate actions for each header 11864781Snate@binkert.org for hdr in switch_headers: 11875863Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 11885863Snate@binkert.orgExport('make_switching_dir') 11891869SN/A 11901869SN/A################################################### 11911869SN/A# 11926121Snate@binkert.org# Define build environments for selected configurations. 11931869SN/A# 11942638Sstever@eecs.umich.edu################################################### 11956121Snate@binkert.org 11966121Snate@binkert.orgfor variant_path in variant_paths: 11972638Sstever@eecs.umich.edu print "Building in", variant_path 119811293Sandreas.hansson@arm.com 119911293Sandreas.hansson@arm.com # Make a copy of the build-root environment to use for this config. 120011293Sandreas.hansson@arm.com env = main.Clone() 12015749Scws3k@cs.virginia.edu env['BUILDDIR'] = variant_path 12029537Satgutier@umich.edu 12039537Satgutier@umich.edu # variant_dir is the tail component of build path, and is used to 12049537Satgutier@umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 12059537Satgutier@umich.edu (build_root, variant_dir) = splitpath(variant_path) 12069888Sandreas@sandberg.pp.se 12079888Sandreas@sandberg.pp.se # Set env variables according to the build directory config. 12089888Sandreas@sandberg.pp.se sticky_vars.files = [] 12099888Sandreas@sandberg.pp.se # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 121010066Sandreas.hansson@arm.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 121110066Sandreas.hansson@arm.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 121210066Sandreas.hansson@arm.com current_vars_file = joinpath(build_root, 'variables', variant_dir) 121310066Sandreas.hansson@arm.com if isfile(current_vars_file): 121410428Sandreas.hansson@arm.com sticky_vars.files.append(current_vars_file) 121510428Sandreas.hansson@arm.com print "Using saved variables file %s" % current_vars_file 121610428Sandreas.hansson@arm.com else: 121710428Sandreas.hansson@arm.com # Build dir-specific variables file doesn't exist. 121810915Sandreas.sandberg@arm.com 121910915Sandreas.sandberg@arm.com # Make sure the directory is there so we can create it later 122010915Sandreas.sandberg@arm.com opt_dir = dirname(current_vars_file) 122110915Sandreas.sandberg@arm.com if not isdir(opt_dir): 12221869SN/A mkdir(opt_dir) 12231869SN/A 12243546Sgblack@eecs.umich.edu # Get default build variables from source tree. Variables are 12253546Sgblack@eecs.umich.edu # normally determined by name of $VARIANT_DIR, but can be 12263546Sgblack@eecs.umich.edu # overridden by '--default=' arg on command line. 12273546Sgblack@eecs.umich.edu default = GetOption('default') 12286121Snate@binkert.org opts_dir = joinpath(main.root.abspath, 'build_opts') 122910196SCurtis.Dunham@arm.com if default: 12305863Snate@binkert.org default_vars_files = [joinpath(build_root, 'variables', default), 12313546Sgblack@eecs.umich.edu joinpath(opts_dir, default)] 12323546Sgblack@eecs.umich.edu else: 12333546Sgblack@eecs.umich.edu default_vars_files = [joinpath(opts_dir, variant_dir)] 12343546Sgblack@eecs.umich.edu existing_files = filter(isfile, default_vars_files) 12354781Snate@binkert.org if existing_files: 12366658Snate@binkert.org default_vars_file = existing_files[0] 123710196SCurtis.Dunham@arm.com sticky_vars.files.append(default_vars_file) 123810196SCurtis.Dunham@arm.com print "Variables file %s not found,\n using defaults in %s" \ 123910196SCurtis.Dunham@arm.com % (current_vars_file, default_vars_file) 124010196SCurtis.Dunham@arm.com else: 124110196SCurtis.Dunham@arm.com print "Error: cannot find variables file %s or " \ 124210196SCurtis.Dunham@arm.com "default file(s) %s" \ 124310196SCurtis.Dunham@arm.com % (current_vars_file, ' or '.join(default_vars_files)) 12443546Sgblack@eecs.umich.edu Exit(1) 12453546Sgblack@eecs.umich.edu 12463546Sgblack@eecs.umich.edu # Apply current variable settings to env 12473546Sgblack@eecs.umich.edu sticky_vars.Update(env) 12487756SAli.Saidi@ARM.com 12497816Ssteve.reinhardt@amd.com help_texts["local_vars"] += \ 12503546Sgblack@eecs.umich.edu "Build variables for %s:\n" % variant_dir \ 12513546Sgblack@eecs.umich.edu + sticky_vars.GenerateHelpText(env) 12523546Sgblack@eecs.umich.edu 12533546Sgblack@eecs.umich.edu # Process variable settings. 125410196SCurtis.Dunham@arm.com 125510196SCurtis.Dunham@arm.com if not have_fenv and env['USE_FENV']: 125610196SCurtis.Dunham@arm.com print "Warning: <fenv.h> not available; " \ 125710196SCurtis.Dunham@arm.com "forcing USE_FENV to False in", variant_dir + "." 125810196SCurtis.Dunham@arm.com env['USE_FENV'] = False 12594202Sbinkertn@umich.edu 12603546Sgblack@eecs.umich.edu if not env['USE_FENV']: 126110196SCurtis.Dunham@arm.com print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 126210196SCurtis.Dunham@arm.com print " FP results may deviate slightly from other platforms." 126310196SCurtis.Dunham@arm.com 126410196SCurtis.Dunham@arm.com if env['EFENCE']: 126510196SCurtis.Dunham@arm.com env.Append(LIBS=['efence']) 126610196SCurtis.Dunham@arm.com 126710196SCurtis.Dunham@arm.com if env['USE_KVM']: 126810196SCurtis.Dunham@arm.com if not have_kvm: 126910196SCurtis.Dunham@arm.com print "Warning: Can not enable KVM, host seems to lack KVM support" 127010196SCurtis.Dunham@arm.com env['USE_KVM'] = False 127110196SCurtis.Dunham@arm.com elif not have_posix_timers: 127210196SCurtis.Dunham@arm.com print "Warning: Can not enable KVM, host seems to lack support " \ 127310196SCurtis.Dunham@arm.com "for POSIX timers" 127410196SCurtis.Dunham@arm.com env['USE_KVM'] = False 127510196SCurtis.Dunham@arm.com elif not is_isa_kvm_compatible(env['TARGET_ISA']): 127610196SCurtis.Dunham@arm.com print "Info: KVM support disabled due to unsupported host and " \ 127710196SCurtis.Dunham@arm.com "target ISA combination" 127810196SCurtis.Dunham@arm.com env['USE_KVM'] = False 127910196SCurtis.Dunham@arm.com 128010196SCurtis.Dunham@arm.com # Warn about missing optional functionality 128110196SCurtis.Dunham@arm.com if env['USE_KVM']: 128210196SCurtis.Dunham@arm.com if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']: 128310196SCurtis.Dunham@arm.com print "Warning: perf_event headers lack support for the " \ 128410196SCurtis.Dunham@arm.com "exclude_host attribute. KVM instruction counts will " \ 12853546Sgblack@eecs.umich.edu "be inaccurate." 12863546Sgblack@eecs.umich.edu 1287955SN/A # Save sticky variable settings back to current variables file 1288955SN/A sticky_vars.Save(current_vars_file, env) 1289955SN/A 1290955SN/A if env['USE_SSE2']: 12915863Snate@binkert.org env.Append(CCFLAGS=['-msse2']) 129210135SCurtis.Dunham@arm.com 129310135SCurtis.Dunham@arm.com # The src/SConscript file sets up the build rules in 'env' according 12945343Sstever@gmail.com # to the configured variables. It returns a list of environments, 12955343Sstever@gmail.com # one for each variant build (debug, opt, etc.) 12966121Snate@binkert.org envList = SConscript('src/SConscript', variant_dir = variant_path, 12975863Snate@binkert.org exports = 'env') 12984773Snate@binkert.org 12995863Snate@binkert.org # Set up the regression tests for each build. 13002632Sstever@eecs.umich.edu for e in envList: 13015863Snate@binkert.org SConscript('tests/SConscript', 13022023SN/A variant_dir = joinpath(variant_path, 'tests', e.Label), 13035863Snate@binkert.org exports = { 'env' : e }, duplicate = False) 13045863Snate@binkert.org 13055863Snate@binkert.org# base help text 13065863Snate@binkert.orgHelp(''' 13075863Snate@binkert.orgUsage: scons [scons options] [build variables] [target(s)] 13085863Snate@binkert.org 13095863Snate@binkert.orgExtra scons options: 13105863Snate@binkert.org%(options)s 131110135SCurtis.Dunham@arm.com 131210135SCurtis.Dunham@arm.comGlobal build variables: 13132632Sstever@eecs.umich.edu%(global_vars)s 13145863Snate@binkert.org 13152023SN/A%(local_vars)s 13162632Sstever@eecs.umich.edu''' % help_texts) 13175863Snate@binkert.org