SConstruct revision 14037
1955SN/A# -*- mode:python -*- 2955SN/A 312230Sgiacomo.travaglini@arm.com# Copyright (c) 2013, 2015-2017 ARM Limited 49812Sandreas.hansson@arm.com# All rights reserved. 59812Sandreas.hansson@arm.com# 69812Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall 79812Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual 89812Sandreas.hansson@arm.com# property including but not limited to intellectual property relating 99812Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software 109812Sandreas.hansson@arm.com# licensed hereunder. You may use the software subject to the license 119812Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated 129812Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software, 139812Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form. 149812Sandreas.hansson@arm.com# 157816Ssteve.reinhardt@amd.com# Copyright (c) 2011 Advanced Micro Devices, Inc. 165871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 171762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 18955SN/A# All rights reserved. 19955SN/A# 20955SN/A# Redistribution and use in source and binary forms, with or without 21955SN/A# modification, are permitted provided that the following conditions are 22955SN/A# met: redistributions of source code must retain the above copyright 23955SN/A# notice, this list of conditions and the following disclaimer; 24955SN/A# redistributions in binary form must reproduce the above copyright 25955SN/A# notice, this list of conditions and the following disclaimer in the 26955SN/A# documentation and/or other materials provided with the distribution; 27955SN/A# neither the name of the copyright holders nor the names of its 28955SN/A# contributors may be used to endorse or promote products derived from 29955SN/A# this software without specific prior written permission. 30955SN/A# 31955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 422665Ssaidi@eecs.umich.edu# 432665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 445863Snate@binkert.org# Nathan Binkert 45955SN/A 46955SN/A################################################### 47955SN/A# 48955SN/A# SCons top-level build description (SConstruct) file. 49955SN/A# 508878Ssteve.reinhardt@amd.com# While in this directory ('gem5'), just type 'scons' to build the default 512632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 528878Ssteve.reinhardt@amd.com# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 532632Sstever@eecs.umich.edu# the optimized full-system version). 54955SN/A# 558878Ssteve.reinhardt@amd.com# You can build gem5 in a different directory as long as there is a 562632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 572761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 582632Sstever@eecs.umich.edu# built for the same host system. 592632Sstever@eecs.umich.edu# 602632Sstever@eecs.umich.edu# Examples: 612761Sstever@eecs.umich.edu# 622761Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 632761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 648878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug 658878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug 662761Sstever@eecs.umich.edu# 672761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 682761Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 692761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 702761Sstever@eecs.umich.edu# file. 718878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 728878Ssteve.reinhardt@amd.com# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug 732632Sstever@eecs.umich.edu# 742632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 758878Ssteve.reinhardt@amd.com# 'gem5' directory (or use -u or -C to tell scons where to find this 768878Ssteve.reinhardt@amd.com# file), you can use 'scons -h' to print all the gem5-specific build 772632Sstever@eecs.umich.edu# options as well. 78955SN/A# 79955SN/A################################################### 80955SN/A 8112563Sgabeblack@google.comfrom __future__ import print_function 8212563Sgabeblack@google.com 836654Snate@binkert.org# Global Python includes 8410196SCurtis.Dunham@arm.comimport itertools 85955SN/Aimport os 865396Ssaidi@eecs.umich.eduimport re 8711401Sandreas.sandberg@arm.comimport shutil 885863Snate@binkert.orgimport subprocess 895863Snate@binkert.orgimport sys 904202Sbinkertn@umich.edu 915863Snate@binkert.orgfrom os import mkdir, environ 925863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 935863Snate@binkert.orgfrom os.path import exists, isdir, isfile 945863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 95955SN/Afrom re import match 966654Snate@binkert.org 975273Sstever@gmail.com# SCons includes 985871Snate@binkert.orgimport SCons 995273Sstever@gmail.comimport SCons.Node 1006654Snate@binkert.orgimport SCons.Node.FS 1015396Ssaidi@eecs.umich.edu 1028120Sgblack@eecs.umich.edufrom m5.util import compareVersions, readCommand 1038120Sgblack@eecs.umich.edu 1048120Sgblack@eecs.umich.eduhelp_texts = { 1058120Sgblack@eecs.umich.edu "options" : "", 1068120Sgblack@eecs.umich.edu "global_vars" : "", 1078120Sgblack@eecs.umich.edu "local_vars" : "" 1088120Sgblack@eecs.umich.edu} 1098120Sgblack@eecs.umich.edu 1108879Ssteve.reinhardt@amd.comExport("help_texts") 1118879Ssteve.reinhardt@amd.com 1128879Ssteve.reinhardt@amd.com 1138879Ssteve.reinhardt@amd.com# There's a bug in scons in that (1) by default, the help texts from 1148879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h' 1158879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the 1168879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once 1178879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get 1188879Ssteve.reinhardt@amd.com# at the help texts from AddOptions. See: 1198879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1208879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1218879Ssteve.reinhardt@amd.com# This hack lets us extract the help text from AddOptions and 1228879Ssteve.reinhardt@amd.com# re-inject it via Help(). Ideally someday this bug will be fixed and 1238120Sgblack@eecs.umich.edu# we can just use AddOption directly. 1248120Sgblack@eecs.umich.edudef AddLocalOption(*args, **kwargs): 1258120Sgblack@eecs.umich.edu col_width = 30 1268120Sgblack@eecs.umich.edu 1278120Sgblack@eecs.umich.edu help = " " + ", ".join(args) 1288120Sgblack@eecs.umich.edu if "help" in kwargs: 1298120Sgblack@eecs.umich.edu length = len(help) 1308120Sgblack@eecs.umich.edu if length >= col_width: 1318120Sgblack@eecs.umich.edu help += "\n" + " " * col_width 1328120Sgblack@eecs.umich.edu else: 1338120Sgblack@eecs.umich.edu help += " " * (col_width - length) 1348120Sgblack@eecs.umich.edu help += kwargs["help"] 1358120Sgblack@eecs.umich.edu help_texts["options"] += help + "\n" 1368120Sgblack@eecs.umich.edu 1378879Ssteve.reinhardt@amd.com AddOption(*args, **kwargs) 1388879Ssteve.reinhardt@amd.com 1398879Ssteve.reinhardt@amd.comAddLocalOption('--colors', dest='use_colors', action='store_true', 1408879Ssteve.reinhardt@amd.com help="Add color to abbreviated scons output") 14110458Sandreas.hansson@arm.comAddLocalOption('--no-colors', dest='use_colors', action='store_false', 14210458Sandreas.hansson@arm.com help="Don't add color to abbreviated scons output") 14310458Sandreas.hansson@arm.comAddLocalOption('--with-cxx-config', dest='with_cxx_config', 1448879Ssteve.reinhardt@amd.com action='store_true', 1458879Ssteve.reinhardt@amd.com help="Build with support for C++-based configuration") 1468879Ssteve.reinhardt@amd.comAddLocalOption('--default', dest='default', type='string', action='store', 1478879Ssteve.reinhardt@amd.com help='Override which build_opts file to use for defaults') 1489227Sandreas.hansson@arm.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1499227Sandreas.hansson@arm.com help='Disable style checking hooks') 15012063Sgabeblack@google.comAddLocalOption('--gold-linker', dest='gold_linker', action='store_true', 15112063Sgabeblack@google.com help='Use the gold linker') 15212063Sgabeblack@google.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1538879Ssteve.reinhardt@amd.com help='Disable Link-Time Optimization for fast') 1548879Ssteve.reinhardt@amd.comAddLocalOption('--force-lto', dest='force_lto', action='store_true', 1558879Ssteve.reinhardt@amd.com help='Use Link-Time Optimization instead of partial linking' + 1568879Ssteve.reinhardt@amd.com ' when the compiler doesn\'t support using them together.') 15710453SAndrew.Bardsley@arm.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 15810453SAndrew.Bardsley@arm.com help='Update test reference outputs') 15910453SAndrew.Bardsley@arm.comAddLocalOption('--verbose', dest='verbose', action='store_true', 16010456SCurtis.Dunham@arm.com help='Print full tool command lines') 16110456SCurtis.Dunham@arm.comAddLocalOption('--without-python', dest='without_python', 16210456SCurtis.Dunham@arm.com action='store_true', 16310457Sandreas.hansson@arm.com help='Build without Python configuration support') 16410457Sandreas.hansson@arm.comAddLocalOption('--without-tcmalloc', dest='without_tcmalloc', 16511342Sandreas.hansson@arm.com action='store_true', 16611342Sandreas.hansson@arm.com help='Disable linking against tcmalloc') 1678120Sgblack@eecs.umich.eduAddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true', 16812063Sgabeblack@google.com help='Build with Undefined Behavior Sanitizer if available') 16912563Sgabeblack@google.comAddLocalOption('--with-asan', dest='with_asan', action='store_true', 17012063Sgabeblack@google.com help='Build with Address Sanitizer if available') 17112063Sgabeblack@google.com 1725871Snate@binkert.orgif GetOption('no_lto') and GetOption('force_lto'): 1735871Snate@binkert.org print('--no-lto and --force-lto are mutually exclusive') 1746121Snate@binkert.org Exit(1) 1755871Snate@binkert.org 1765871Snate@binkert.org######################################################################## 1779926Sstan.czerniawski@arm.com# 17812243Sgabeblack@google.com# Set up the main build environment. 1791533SN/A# 18012246Sgabeblack@google.com######################################################################## 18112246Sgabeblack@google.com 18212246Sgabeblack@google.commain = Environment() 18312246Sgabeblack@google.com 1849239Sandreas.hansson@arm.comfrom gem5_scons import Transform 1859239Sandreas.hansson@arm.comfrom gem5_scons.util import get_termcap 1869239Sandreas.hansson@arm.comtermcap = get_termcap() 1879239Sandreas.hansson@arm.com 18812563Sgabeblack@google.commain_dict_keys = main.Dictionary().keys() 1899239Sandreas.hansson@arm.com 1909239Sandreas.hansson@arm.com# Check that we have a C/C++ compiler 191955SN/Aif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 192955SN/A print("No C++ compiler installed (package g++ on Ubuntu and RedHat)") 1932632Sstever@eecs.umich.edu Exit(1) 1942632Sstever@eecs.umich.edu 195955SN/A################################################### 196955SN/A# 197955SN/A# Figure out which configurations to set up based on the path(s) of 198955SN/A# the target(s). 1998878Ssteve.reinhardt@amd.com# 200955SN/A################################################### 2012632Sstever@eecs.umich.edu 2022632Sstever@eecs.umich.edu# Find default configuration & binary. 2032632Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2042632Sstever@eecs.umich.edu 2052632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 2062632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 2072632Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2088268Ssteve.reinhardt@amd.com if l[i] == elt: 2098268Ssteve.reinhardt@amd.com return i 2108268Ssteve.reinhardt@amd.com raise ValueError, "element not found" 2118268Ssteve.reinhardt@amd.com 2128268Ssteve.reinhardt@amd.com# Take a list of paths (or SCons Nodes) and return a list with all 2138268Ssteve.reinhardt@amd.com# paths made absolute and ~-expanded. Paths will be interpreted 2148268Ssteve.reinhardt@amd.com# relative to the launch directory unless a different root is provided 2152632Sstever@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 2162632Sstever@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 2172632Sstever@eecs.umich.edu for p in path_list] 2182632Sstever@eecs.umich.edu 2198268Ssteve.reinhardt@amd.comdef find_first_prog(prog_names): 2202632Sstever@eecs.umich.edu """Find the absolute path to the first existing binary in prog_names""" 2218268Ssteve.reinhardt@amd.com 2228268Ssteve.reinhardt@amd.com if not isinstance(prog_names, (list, tuple)): 2238268Ssteve.reinhardt@amd.com prog_names = [ prog_names ] 2248268Ssteve.reinhardt@amd.com 2253718Sstever@eecs.umich.edu for p in prog_names: 2262634Sstever@eecs.umich.edu p = main.WhereIs(p) 2272634Sstever@eecs.umich.edu if p is not None: 2285863Snate@binkert.org return p 2292638Sstever@eecs.umich.edu 2308268Ssteve.reinhardt@amd.com return None 2312632Sstever@eecs.umich.edu 2322632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2332632Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2342632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 23512563Sgabeblack@google.com# recognize that ALPHA_SE specifies the configuration because it 2361858SN/A# follow 'build' in the build path. 2373716Sstever@eecs.umich.edu 2382638Sstever@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 2392638Sstever@eecs.umich.edu# in place rather than reassign the symbol to a new list, which 2402638Sstever@eecs.umich.edu# doesn't work (obviously!). 2412638Sstever@eecs.umich.eduBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 24212563Sgabeblack@google.com 24312563Sgabeblack@google.com# Generate a list of the unique build roots and configs that the 2442638Sstever@eecs.umich.edu# collected targets reference. 2455863Snate@binkert.orgvariant_paths = [] 2465863Snate@binkert.orgbuild_root = None 2475863Snate@binkert.orgfor t in BUILD_TARGETS: 248955SN/A path_dirs = t.split('/') 2495341Sstever@gmail.com try: 2505341Sstever@gmail.com build_top = rfind(path_dirs, 'build', -2) 2515863Snate@binkert.org except: 2527756SAli.Saidi@ARM.com print("Error: no non-leaf 'build' dir found on target path", t) 2535341Sstever@gmail.com Exit(1) 2546121Snate@binkert.org this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2554494Ssaidi@eecs.umich.edu if not build_root: 2566121Snate@binkert.org build_root = this_build_root 2571105SN/A else: 2582667Sstever@eecs.umich.edu if this_build_root != build_root: 2592667Sstever@eecs.umich.edu print("Error: build targets not under same build root\n" 2602667Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root)) 2612667Sstever@eecs.umich.edu Exit(1) 2626121Snate@binkert.org variant_path = joinpath('/',*path_dirs[:build_top+2]) 2632667Sstever@eecs.umich.edu if variant_path not in variant_paths: 2645341Sstever@gmail.com variant_paths.append(variant_path) 2655863Snate@binkert.org 2665341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there) 2675341Sstever@gmail.comif not isdir(build_root): 2685341Sstever@gmail.com mkdir(build_root) 2698120Sgblack@eecs.umich.edumain['BUILDROOT'] = build_root 2705341Sstever@gmail.com 2718120Sgblack@eecs.umich.eduExport('main') 2725341Sstever@gmail.com 2738120Sgblack@eecs.umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 2746121Snate@binkert.org 2756121Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 2769396Sandreas.hansson@arm.com# when you use emacs to edit a file in the target dir, as emacs moves 2775397Ssaidi@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2785397Ssaidi@eecs.umich.edu# (soft) links work better. 2797727SAli.Saidi@ARM.commain.SetOption('duplicate', 'soft-copy') 2808268Ssteve.reinhardt@amd.com 2816168Snate@binkert.org# 2825341Sstever@gmail.com# Set up global sticky variables... these are common to an entire build 2838120Sgblack@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 2848120Sgblack@eecs.umich.edu# 2858120Sgblack@eecs.umich.edu 2866814Sgblack@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 2875863Snate@binkert.org 2888120Sgblack@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 2895341Sstever@gmail.com 2905863Snate@binkert.orgglobal_vars.AddVariables( 2918268Ssteve.reinhardt@amd.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 2926121Snate@binkert.org ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 2936121Snate@binkert.org ('PYTHON_CONFIG', 'Python config binary to use', 2948268Ssteve.reinhardt@amd.com [ 'python2.7-config', 'python-config' ]), 2955742Snate@binkert.org ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 2965742Snate@binkert.org ('BATCH', 'Use batch pool for build and tests', False), 2975341Sstever@gmail.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 2985742Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 2995742Snate@binkert.org ('EXTRAS', 'Add extra directories to the compilation', '') 3005341Sstever@gmail.com ) 3016017Snate@binkert.org 3026121Snate@binkert.org# Update main environment with values from ARGUMENTS & global_vars_file 3036017Snate@binkert.orgglobal_vars.Update(main) 30412158Sandreas.sandberg@arm.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 30512158Sandreas.sandberg@arm.com 30612158Sandreas.sandberg@arm.com# Save sticky variable settings back to current variables file 3078120Sgblack@eecs.umich.eduglobal_vars.Save(global_vars_file, main) 3087756SAli.Saidi@ARM.com 3097756SAli.Saidi@ARM.com# Parse EXTRAS variable to build list of all directories where we're 3107756SAli.Saidi@ARM.com# look for sources etc. This list is exported as extras_dir_list. 3117756SAli.Saidi@ARM.combase_dir = main.srcdir.abspath 3127816Ssteve.reinhardt@amd.comif main['EXTRAS']: 3137816Ssteve.reinhardt@amd.com extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3147816Ssteve.reinhardt@amd.comelse: 3157816Ssteve.reinhardt@amd.com extras_dir_list = [] 3167816Ssteve.reinhardt@amd.com 31711979Sgabeblack@google.comExport('base_dir') 3187816Ssteve.reinhardt@amd.comExport('extras_dir_list') 3197816Ssteve.reinhardt@amd.com 3207816Ssteve.reinhardt@amd.com# the ext directory should be on the #includes path 3217816Ssteve.reinhardt@amd.commain.Append(CPPPATH=[Dir('ext')]) 3227756SAli.Saidi@ARM.com 3237756SAli.Saidi@ARM.com# Add shared top-level headers 3249227Sandreas.hansson@arm.commain.Prepend(CPPPATH=Dir('include')) 3259227Sandreas.hansson@arm.com 3269227Sandreas.hansson@arm.comif GetOption('verbose'): 3279227Sandreas.hansson@arm.com def MakeAction(action, string, *args, **kwargs): 3289590Sandreas@sandberg.pp.se return Action(action, *args, **kwargs) 3299590Sandreas@sandberg.pp.seelse: 3309590Sandreas@sandberg.pp.se MakeAction = Action 3319590Sandreas@sandberg.pp.se main['CCCOMSTR'] = Transform("CC") 3329590Sandreas@sandberg.pp.se main['CXXCOMSTR'] = Transform("CXX") 3339590Sandreas@sandberg.pp.se main['ASCOMSTR'] = Transform("AS") 3346654Snate@binkert.org main['ARCOMSTR'] = Transform("AR", 0) 3356654Snate@binkert.org main['LINKCOMSTR'] = Transform("LINK", 0) 3365871Snate@binkert.org main['SHLINKCOMSTR'] = Transform("SHLINK", 0) 3376121Snate@binkert.org main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 3388946Sandreas.hansson@arm.com main['M4COMSTR'] = Transform("M4") 3399419Sandreas.hansson@arm.com main['SHCCCOMSTR'] = Transform("SHCC") 34012563Sgabeblack@google.com main['SHCXXCOMSTR'] = Transform("SHCXX") 3413918Ssaidi@eecs.umich.eduExport('MakeAction') 3423918Ssaidi@eecs.umich.edu 3431858SN/A# Initialize the Link-Time Optimization (LTO) flags 3449556Sandreas.hansson@arm.commain['LTO_CCFLAGS'] = [] 3459556Sandreas.hansson@arm.commain['LTO_LDFLAGS'] = [] 3469556Sandreas.hansson@arm.com 3479556Sandreas.hansson@arm.com# According to the readme, tcmalloc works best if the compiler doesn't 34811294Sandreas.hansson@arm.com# assume that we're using the builtin malloc and friends. These flags 34911294Sandreas.hansson@arm.com# are compiler-specific, so we need to set them after we detect which 35011294Sandreas.hansson@arm.com# compiler we're using. 35111294Sandreas.hansson@arm.commain['TCMALLOC_CCFLAGS'] = [] 35210878Sandreas.hansson@arm.com 35310878Sandreas.hansson@arm.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 35411811Sbaz21@cam.ac.ukCXX_V = readCommand([main['CXX'],'-V'], exception=False) 35511811Sbaz21@cam.ac.uk 35611811Sbaz21@cam.ac.ukmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 35711982Sgabeblack@google.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 35811982Sgabeblack@google.comif main['GCC'] + main['CLANG'] > 1: 35911982Sgabeblack@google.com print('Error: How can we have two at the same time?') 36011982Sgabeblack@google.com Exit(1) 36111992Sgabeblack@google.com 36211982Sgabeblack@google.com# Set up default C++ compiler flags 36311982Sgabeblack@google.comif main['GCC'] or main['CLANG']: 36412305Sgabeblack@google.com # As gcc and clang share many flags, do the common parts here 36512305Sgabeblack@google.com main.Append(CCFLAGS=['-pipe']) 36612305Sgabeblack@google.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 36712305Sgabeblack@google.com # Enable -Wall and -Wextra and then disable the few warnings that 36812305Sgabeblack@google.com # we consistently violate 36912305Sgabeblack@google.com main.Append(CCFLAGS=['-Wall', '-Wundef', '-Wextra', 37012305Sgabeblack@google.com '-Wno-sign-compare', '-Wno-unused-parameter']) 3719556Sandreas.hansson@arm.com # We always compile using C++11 37212563Sgabeblack@google.com main.Append(CXXFLAGS=['-std=c++11']) 37312563Sgabeblack@google.com if sys.platform.startswith('freebsd'): 37412563Sgabeblack@google.com main.Append(CCFLAGS=['-I/usr/local/include']) 37512563Sgabeblack@google.com main.Append(CXXFLAGS=['-I/usr/local/include']) 3769556Sandreas.hansson@arm.com 37712563Sgabeblack@google.com main['FILTER_PSHLINKFLAGS'] = lambda x: str(x).replace(' -shared', '') 37812563Sgabeblack@google.com main['PSHLINKFLAGS'] = main.subst('${FILTER_PSHLINKFLAGS(SHLINKFLAGS)}') 3799556Sandreas.hansson@arm.com if GetOption('gold_linker'): 38012563Sgabeblack@google.com main.Append(LINKFLAGS='-fuse-ld=gold') 38112563Sgabeblack@google.com main['PLINKFLAGS'] = main.subst('${LINKFLAGS}') 38212563Sgabeblack@google.com shared_partial_flags = ['-r', '-nostdlib'] 38312563Sgabeblack@google.com main.Append(PSHLINKFLAGS=shared_partial_flags) 38412563Sgabeblack@google.com main.Append(PLINKFLAGS=shared_partial_flags) 38512563Sgabeblack@google.com 38612563Sgabeblack@google.com # Treat warnings as errors but white list some warnings that we 38712563Sgabeblack@google.com # want to allow (e.g., deprecation warnings). 3889556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Werror', 3899556Sandreas.hansson@arm.com '-Wno-error=deprecated-declarations', 3906121Snate@binkert.org '-Wno-error=deprecated', 39111500Sandreas.hansson@arm.com ]) 39210238Sandreas.hansson@arm.comelse: 39310878Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 3949420Sandreas.hansson@arm.com print("Don't know what compiler options to use for your compiler.") 39511500Sandreas.hansson@arm.com print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 39612563Sgabeblack@google.com print(termcap.Yellow + ' version:' + termcap.Normal, end = ' ') 39712563Sgabeblack@google.com if not CXX_version: 3989420Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 3999420Sandreas.hansson@arm.com termcap.Normal) 4009420Sandreas.hansson@arm.com else: 4019420Sandreas.hansson@arm.com print(CXX_version.replace('\n', '<nl>')) 40212063Sgabeblack@google.com print(" If you're trying to use a compiler other than GCC") 40312063Sgabeblack@google.com print(" or clang, there appears to be something wrong with your") 40412063Sgabeblack@google.com print(" environment.") 40512063Sgabeblack@google.com print(" ") 40612063Sgabeblack@google.com print(" If you are trying to use a compiler other than those listed") 40712063Sgabeblack@google.com print(" above you will need to ease fix SConstruct and ") 40812063Sgabeblack@google.com print(" src/SConscript to support that compiler.") 40912063Sgabeblack@google.com Exit(1) 41012063Sgabeblack@google.com 41112063Sgabeblack@google.comif main['GCC']: 41212063Sgabeblack@google.com # Check for a supported version of gcc. >= 4.8 is chosen for its 41312063Sgabeblack@google.com # level of c++11 support. See 41412063Sgabeblack@google.com # http://gcc.gnu.org/projects/cxx0x.html for details. 41512063Sgabeblack@google.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 41612063Sgabeblack@google.com if compareVersions(gcc_version, "4.8") < 0: 41712063Sgabeblack@google.com print('Error: gcc version 4.8 or newer required.') 41812063Sgabeblack@google.com print(' Installed version: ', gcc_version) 41912063Sgabeblack@google.com Exit(1) 42012063Sgabeblack@google.com 42112063Sgabeblack@google.com main['GCC_VERSION'] = gcc_version 42212063Sgabeblack@google.com 42312063Sgabeblack@google.com if compareVersions(gcc_version, '4.9') >= 0: 42410264Sandreas.hansson@arm.com # Incremental linking with LTO is currently broken in gcc versions 42510264Sandreas.hansson@arm.com # 4.9 and above. A version where everything works completely hasn't 42610264Sandreas.hansson@arm.com # yet been identified. 42710264Sandreas.hansson@arm.com # 42811925Sgabeblack@google.com # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67548 42911925Sgabeblack@google.com main['BROKEN_INCREMENTAL_LTO'] = True 43011500Sandreas.hansson@arm.com if compareVersions(gcc_version, '6.0') >= 0: 43110264Sandreas.hansson@arm.com # gcc versions 6.0 and greater accept an -flinker-output flag which 43211500Sandreas.hansson@arm.com # selects what type of output the linker should generate. This is 43311500Sandreas.hansson@arm.com # necessary for incremental lto to work, but is also broken in 43411500Sandreas.hansson@arm.com # current versions of gcc. It may not be necessary in future 43511500Sandreas.hansson@arm.com # versions. We add it here since it might be, and as a reminder that 43610866Sandreas.hansson@arm.com # it exists. It's excluded if lto is being forced. 43711500Sandreas.hansson@arm.com # 43812563Sgabeblack@google.com # https://gcc.gnu.org/gcc-6/changes.html 43912563Sgabeblack@google.com # https://gcc.gnu.org/ml/gcc-patches/2015-11/msg03161.html 44012563Sgabeblack@google.com # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69866 44112563Sgabeblack@google.com if not GetOption('force_lto'): 44212563Sgabeblack@google.com main.Append(PSHLINKFLAGS='-flinker-output=rel') 44312563Sgabeblack@google.com main.Append(PLINKFLAGS='-flinker-output=rel') 44410264Sandreas.hansson@arm.com 44510457Sandreas.hansson@arm.com # Make sure we warn if the user has requested to compile with the 44610457Sandreas.hansson@arm.com # Undefined Benahvior Sanitizer and this version of gcc does not 44710457Sandreas.hansson@arm.com # support it. 44810457Sandreas.hansson@arm.com if GetOption('with_ubsan') and \ 44910457Sandreas.hansson@arm.com compareVersions(gcc_version, '4.9') < 0: 45012563Sgabeblack@google.com print(termcap.Yellow + termcap.Bold + 45112563Sgabeblack@google.com 'Warning: UBSan is only supported using gcc 4.9 and later.' + 45212563Sgabeblack@google.com termcap.Normal) 45310457Sandreas.hansson@arm.com 45412063Sgabeblack@google.com disable_lto = GetOption('no_lto') 45512063Sgabeblack@google.com if not disable_lto and main.get('BROKEN_INCREMENTAL_LTO', False) and \ 45612063Sgabeblack@google.com not GetOption('force_lto'): 45712563Sgabeblack@google.com print(termcap.Yellow + termcap.Bold + 45812563Sgabeblack@google.com 'Warning: Your compiler doesn\'t support incremental linking' + 45912563Sgabeblack@google.com ' and lto at the same time, so lto is being disabled. To force' + 46012563Sgabeblack@google.com ' lto on anyway, use the --force-lto option. That will disable' + 46112563Sgabeblack@google.com ' partial linking.' + 46212563Sgabeblack@google.com termcap.Normal) 46312063Sgabeblack@google.com disable_lto = True 46412063Sgabeblack@google.com 46510238Sandreas.hansson@arm.com # Add the appropriate Link-Time Optimization (LTO) flags 46610238Sandreas.hansson@arm.com # unless LTO is explicitly turned off. Note that these flags 46710238Sandreas.hansson@arm.com # are only used by the fast target. 46812063Sgabeblack@google.com if not disable_lto: 46910238Sandreas.hansson@arm.com # Pass the LTO flag when compiling to produce GIMPLE 47010238Sandreas.hansson@arm.com # output, we merely create the flags here and only append 47110416Sandreas.hansson@arm.com # them later 47210238Sandreas.hansson@arm.com main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 4739227Sandreas.hansson@arm.com 47410238Sandreas.hansson@arm.com # Use the same amount of jobs for LTO as we are running 47510416Sandreas.hansson@arm.com # scons with 47610416Sandreas.hansson@arm.com main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 4779227Sandreas.hansson@arm.com 4789590Sandreas@sandberg.pp.se main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 4799590Sandreas@sandberg.pp.se '-fno-builtin-realloc', '-fno-builtin-free']) 4809590Sandreas@sandberg.pp.se 48112304Sgabeblack@google.com # The address sanitizer is available for gcc >= 4.8 48212304Sgabeblack@google.com if GetOption('with_asan'): 48312304Sgabeblack@google.com if GetOption('with_ubsan') and \ 48412688Sgiacomo.travaglini@arm.com compareVersions(main['GCC_VERSION'], '4.9') >= 0: 48512688Sgiacomo.travaglini@arm.com main.Append(CCFLAGS=['-fsanitize=address,undefined', 48612688Sgiacomo.travaglini@arm.com '-fno-omit-frame-pointer'], 48712304Sgabeblack@google.com LINKFLAGS='-fsanitize=address,undefined') 48812304Sgabeblack@google.com else: 48912688Sgiacomo.travaglini@arm.com main.Append(CCFLAGS=['-fsanitize=address', 49012688Sgiacomo.travaglini@arm.com '-fno-omit-frame-pointer'], 49112304Sgabeblack@google.com LINKFLAGS='-fsanitize=address') 49212304Sgabeblack@google.com # Only gcc >= 4.9 supports UBSan, so check both the version 49312304Sgabeblack@google.com # and the command-line option before adding the compiler and 49412304Sgabeblack@google.com # linker flags. 49512304Sgabeblack@google.com elif GetOption('with_ubsan') and \ 49612688Sgiacomo.travaglini@arm.com compareVersions(main['GCC_VERSION'], '4.9') >= 0: 49712688Sgiacomo.travaglini@arm.com main.Append(CCFLAGS='-fsanitize=undefined') 49812688Sgiacomo.travaglini@arm.com main.Append(LINKFLAGS='-fsanitize=undefined') 49912304Sgabeblack@google.com 5008737Skoansin.tan@gmail.comelif main['CLANG']: 50110878Sandreas.hansson@arm.com # Check for a supported version of clang, >= 3.1 is needed to 50211500Sandreas.hansson@arm.com # support similar features as gcc 4.8. See 5039420Sandreas.hansson@arm.com # http://clang.llvm.org/cxx_status.html for details 5048737Skoansin.tan@gmail.com clang_version_re = re.compile(".* version (\d+\.\d+)") 50510106SMitch.Hayenga@arm.com clang_version_match = clang_version_re.search(CXX_version) 5068737Skoansin.tan@gmail.com if (clang_version_match): 5078737Skoansin.tan@gmail.com clang_version = clang_version_match.groups()[0] 50810878Sandreas.hansson@arm.com if compareVersions(clang_version, "3.1") < 0: 50912563Sgabeblack@google.com print('Error: clang version 3.1 or newer required.') 51012563Sgabeblack@google.com print(' Installed version:', clang_version) 5118737Skoansin.tan@gmail.com Exit(1) 5128737Skoansin.tan@gmail.com else: 51312563Sgabeblack@google.com print('Error: Unable to determine clang version.') 5148737Skoansin.tan@gmail.com Exit(1) 5158737Skoansin.tan@gmail.com 51611294Sandreas.hansson@arm.com # clang has a few additional warnings that we disable, extraneous 5179556Sandreas.hansson@arm.com # parantheses are allowed due to Ruby's printing of the AST, 5189556Sandreas.hansson@arm.com # finally self assignments are allowed as the generated CPU code 5199556Sandreas.hansson@arm.com # is relying on this 52011294Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-parentheses', 52110278SAndreas.Sandberg@ARM.com '-Wno-self-assign', 52210278SAndreas.Sandberg@ARM.com # Some versions of libstdc++ (4.8?) seem to 52310278SAndreas.Sandberg@ARM.com # use struct hash and class hash 52410278SAndreas.Sandberg@ARM.com # interchangeably. 52510278SAndreas.Sandberg@ARM.com '-Wno-mismatched-tags', 52610278SAndreas.Sandberg@ARM.com ]) 5279556Sandreas.hansson@arm.com 5289590Sandreas@sandberg.pp.se main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 5299590Sandreas@sandberg.pp.se 5309420Sandreas.hansson@arm.com # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 5319846Sandreas.hansson@arm.com # opposed to libstdc++, as the later is dated. 5329846Sandreas.hansson@arm.com if sys.platform == "darwin": 5339846Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-stdlib=libc++']) 5349846Sandreas.hansson@arm.com main.Append(LIBS=['c++']) 5358946Sandreas.hansson@arm.com 53611811Sbaz21@cam.ac.uk # On FreeBSD we need libthr. 53711811Sbaz21@cam.ac.uk if sys.platform.startswith('freebsd'): 53811811Sbaz21@cam.ac.uk main.Append(LIBS=['thr']) 53911811Sbaz21@cam.ac.uk 54012304Sgabeblack@google.com # We require clang >= 3.1, so there is no need to check any 54112304Sgabeblack@google.com # versions here. 54212304Sgabeblack@google.com if GetOption('with_ubsan'): 54312304Sgabeblack@google.com if GetOption('with_asan'): 54412304Sgabeblack@google.com main.Append(CCFLAGS=['-fsanitize=address,undefined', 54512304Sgabeblack@google.com '-fno-omit-frame-pointer'], 54612304Sgabeblack@google.com LINKFLAGS='-fsanitize=address,undefined') 54712304Sgabeblack@google.com else: 54812304Sgabeblack@google.com main.Append(CCFLAGS='-fsanitize=undefined', 54912304Sgabeblack@google.com LINKFLAGS='-fsanitize=undefined') 55012304Sgabeblack@google.com 55112304Sgabeblack@google.com elif GetOption('with_asan'): 55212304Sgabeblack@google.com main.Append(CCFLAGS=['-fsanitize=address', 55312304Sgabeblack@google.com '-fno-omit-frame-pointer'], 55412304Sgabeblack@google.com LINKFLAGS='-fsanitize=address') 55512304Sgabeblack@google.com 5563918Ssaidi@eecs.umich.eduelse: 55712563Sgabeblack@google.com print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 55812563Sgabeblack@google.com print("Don't know what compiler options to use for your compiler.") 55912563Sgabeblack@google.com print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 56012563Sgabeblack@google.com print(termcap.Yellow + ' version:' + termcap.Normal, end=' ') 5619068SAli.Saidi@ARM.com if not CXX_version: 56212563Sgabeblack@google.com print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 56312563Sgabeblack@google.com termcap.Normal) 5649068SAli.Saidi@ARM.com else: 56512563Sgabeblack@google.com print(CXX_version.replace('\n', '<nl>')) 56612563Sgabeblack@google.com print(" If you're trying to use a compiler other than GCC") 56712563Sgabeblack@google.com print(" or clang, there appears to be something wrong with your") 56812563Sgabeblack@google.com print(" environment.") 56912563Sgabeblack@google.com print(" ") 57012563Sgabeblack@google.com print(" If you are trying to use a compiler other than those listed") 57112563Sgabeblack@google.com print(" above you will need to ease fix SConstruct and ") 57212563Sgabeblack@google.com print(" src/SConscript to support that compiler.") 5733918Ssaidi@eecs.umich.edu Exit(1) 5743918Ssaidi@eecs.umich.edu 5756157Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby) 5766157Snate@binkert.orgmain['YACCFLAGS'] = '-d' 5776157Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh' 5786157Snate@binkert.org 5795397Ssaidi@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 5805397Ssaidi@eecs.umich.edu# extra 'qdo' every time we run scons. 5816121Snate@binkert.orgif main['BATCH']: 5826121Snate@binkert.org main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5836121Snate@binkert.org main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5846121Snate@binkert.org main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5856121Snate@binkert.org main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5866121Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5875397Ssaidi@eecs.umich.edu 5881851SN/Aif sys.platform == 'cygwin': 5891851SN/A # cygwin has some header file issues... 5907739Sgblack@eecs.umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 591955SN/A 5929396Sandreas.hansson@arm.com# Check for the protobuf compiler 5939396Sandreas.hansson@arm.comprotoc_version = readCommand([main['PROTOC'], '--version'], 5949396Sandreas.hansson@arm.com exception='').split() 5959396Sandreas.hansson@arm.com 5969396Sandreas.hansson@arm.com# First two words should be "libprotoc x.y.z" 5979396Sandreas.hansson@arm.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 59812563Sgabeblack@google.com print(termcap.Yellow + termcap.Bold + 59912563Sgabeblack@google.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + 60012563Sgabeblack@google.com ' Please install protobuf-compiler for tracing support.' + 60112563Sgabeblack@google.com termcap.Normal) 6029396Sandreas.hansson@arm.com main['PROTOC'] = False 6039396Sandreas.hansson@arm.comelse: 6049396Sandreas.hansson@arm.com # Based on the availability of the compress stream wrappers, 6059396Sandreas.hansson@arm.com # require 2.1.0 6069396Sandreas.hansson@arm.com min_protoc_version = '2.1.0' 6079396Sandreas.hansson@arm.com if compareVersions(protoc_version[1], min_protoc_version) < 0: 60812563Sgabeblack@google.com print(termcap.Yellow + termcap.Bold + 60912563Sgabeblack@google.com 'Warning: protoc version', min_protoc_version, 61012563Sgabeblack@google.com 'or newer required.\n' + 61112563Sgabeblack@google.com ' Installed version:', protoc_version[1], 61212563Sgabeblack@google.com termcap.Normal) 6139477Sandreas.hansson@arm.com main['PROTOC'] = False 6149477Sandreas.hansson@arm.com else: 6159477Sandreas.hansson@arm.com # Attempt to determine the appropriate include path and 6169477Sandreas.hansson@arm.com # library path using pkg-config, that means we also need to 6179477Sandreas.hansson@arm.com # check for pkg-config. Note that it is possible to use 6189477Sandreas.hansson@arm.com # protobuf without the involvement of pkg-config. Later on we 6199477Sandreas.hansson@arm.com # check go a library config check and at that point the test 6209477Sandreas.hansson@arm.com # will fail if libprotobuf cannot be found. 6219477Sandreas.hansson@arm.com if readCommand(['pkg-config', '--version'], exception=''): 6229477Sandreas.hansson@arm.com try: 6239477Sandreas.hansson@arm.com # Attempt to establish what linking flags to add for protobuf 6249477Sandreas.hansson@arm.com # using pkg-config 6259477Sandreas.hansson@arm.com main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 6269477Sandreas.hansson@arm.com except: 62712563Sgabeblack@google.com print(termcap.Yellow + termcap.Bold + 62812563Sgabeblack@google.com 'Warning: pkg-config could not get protobuf flags.' + 62912563Sgabeblack@google.com termcap.Normal) 6309396Sandreas.hansson@arm.com 6312667Sstever@eecs.umich.edu 63210710Sandreas.hansson@arm.com# Check for 'timeout' from GNU coreutils. If present, regressions will 63310710Sandreas.hansson@arm.com# be run with a time limit. We require version 8.13 since we rely on 63410710Sandreas.hansson@arm.com# support for the '--foreground' option. 63511811Sbaz21@cam.ac.ukif sys.platform.startswith('freebsd'): 63611811Sbaz21@cam.ac.uk timeout_lines = readCommand(['gtimeout', '--version'], 63711811Sbaz21@cam.ac.uk exception='').splitlines() 63811811Sbaz21@cam.ac.ukelse: 63911811Sbaz21@cam.ac.uk timeout_lines = readCommand(['timeout', '--version'], 64011811Sbaz21@cam.ac.uk exception='').splitlines() 64110710Sandreas.hansson@arm.com# Get the first line and tokenize it 64210710Sandreas.hansson@arm.comtimeout_version = timeout_lines[0].split() if timeout_lines else [] 64310710Sandreas.hansson@arm.commain['TIMEOUT'] = timeout_version and \ 64410710Sandreas.hansson@arm.com compareVersions(timeout_version[-1], '8.13') >= 0 64510384SCurtis.Dunham@arm.com 6469986Sandreas@sandberg.pp.se# Add a custom Check function to test for structure members. 6479986Sandreas@sandberg.pp.sedef CheckMember(context, include, decl, member, include_quotes="<>"): 6489986Sandreas@sandberg.pp.se context.Message("Checking for member %s in %s..." % 6499986Sandreas@sandberg.pp.se (member, decl)) 6509986Sandreas@sandberg.pp.se text = """ 6519986Sandreas@sandberg.pp.se#include %(header)s 6529986Sandreas@sandberg.pp.seint main(){ 6539986Sandreas@sandberg.pp.se %(decl)s test; 6549986Sandreas@sandberg.pp.se (void)test.%(member)s; 6559986Sandreas@sandberg.pp.se return 0; 6569986Sandreas@sandberg.pp.se}; 6579986Sandreas@sandberg.pp.se""" % { "header" : include_quotes[0] + include + include_quotes[1], 6589986Sandreas@sandberg.pp.se "decl" : decl, 6599986Sandreas@sandberg.pp.se "member" : member, 6609986Sandreas@sandberg.pp.se } 6619986Sandreas@sandberg.pp.se 6629986Sandreas@sandberg.pp.se ret = context.TryCompile(text, extension=".cc") 6639986Sandreas@sandberg.pp.se context.Result(ret) 6649986Sandreas@sandberg.pp.se return ret 6659986Sandreas@sandberg.pp.se 6662638Sstever@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 6672638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 6686121Snate@binkert.orgconf = Configure(main, 6693716Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 6705522Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 6719986Sandreas@sandberg.pp.se custom_tests = { 6729986Sandreas@sandberg.pp.se 'CheckMember' : CheckMember, 6739986Sandreas@sandberg.pp.se }) 6745522Snate@binkert.org 6755227Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6765227Ssaidi@eecs.umich.edutry: 6775227Ssaidi@eecs.umich.edu import platform 6785227Ssaidi@eecs.umich.edu uname = platform.uname() 6796654Snate@binkert.org if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6806654Snate@binkert.org if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6817769SAli.Saidi@ARM.com main.Append(CCFLAGS=['-arch', 'x86_64']) 6827769SAli.Saidi@ARM.com main.Append(CFLAGS=['-arch', 'x86_64']) 6837769SAli.Saidi@ARM.com main.Append(LINKFLAGS=['-arch', 'x86_64']) 6847769SAli.Saidi@ARM.com main.Append(ASFLAGS=['-arch', 'x86_64']) 6855227Ssaidi@eecs.umich.eduexcept: 6865227Ssaidi@eecs.umich.edu pass 6875227Ssaidi@eecs.umich.edu 6885204Sstever@gmail.com# Recent versions of scons substitute a "Null" object for Configure() 6895204Sstever@gmail.com# when configuration isn't necessary, e.g., if the "--help" option is 6905204Sstever@gmail.com# present. Unfortuantely this Null object always returns false, 6915204Sstever@gmail.com# breaking all our configuration checks. We replace it with our own 6925204Sstever@gmail.com# more optimistic null object that returns True instead. 6935204Sstever@gmail.comif not conf: 6945204Sstever@gmail.com def NullCheck(*args, **kwargs): 6955204Sstever@gmail.com return True 6965204Sstever@gmail.com 6975204Sstever@gmail.com class NullConf: 6985204Sstever@gmail.com def __init__(self, env): 6995204Sstever@gmail.com self.env = env 7005204Sstever@gmail.com def Finish(self): 7015204Sstever@gmail.com return self.env 7025204Sstever@gmail.com def __getattr__(self, mname): 7035204Sstever@gmail.com return NullCheck 7045204Sstever@gmail.com 7056121Snate@binkert.org conf = NullConf(main) 7065204Sstever@gmail.com 7077727SAli.Saidi@ARM.com# Cache build files in the supplied directory. 7087727SAli.Saidi@ARM.comif main['M5_BUILD_CACHE']: 70912563Sgabeblack@google.com print('Using build cache located at', main['M5_BUILD_CACHE']) 7107727SAli.Saidi@ARM.com CacheDir(main['M5_BUILD_CACHE']) 7117727SAli.Saidi@ARM.com 71211988Sandreas.sandberg@arm.commain['USE_PYTHON'] = not GetOption('without_python') 71311988Sandreas.sandberg@arm.comif main['USE_PYTHON']: 71410453SAndrew.Bardsley@arm.com # Find Python include and library directories for embedding the 71510453SAndrew.Bardsley@arm.com # interpreter. We rely on python-config to resolve the appropriate 71610453SAndrew.Bardsley@arm.com # includes and linker flags. ParseConfig does not seem to understand 71710453SAndrew.Bardsley@arm.com # the more exotic linker flags such as -Xlinker and -export-dynamic so 71810453SAndrew.Bardsley@arm.com # we add them explicitly below. If you want to link in an alternate 71910453SAndrew.Bardsley@arm.com # version of python, see above for instructions on how to invoke 72010453SAndrew.Bardsley@arm.com # scons with the appropriate PATH set. 72110453SAndrew.Bardsley@arm.com 72210453SAndrew.Bardsley@arm.com python_config = find_first_prog(main['PYTHON_CONFIG']) 72310453SAndrew.Bardsley@arm.com if python_config is None: 72410160Sandreas.hansson@arm.com print("Error: can't find a suitable python-config, tried %s" % \ 72510453SAndrew.Bardsley@arm.com main['PYTHON_CONFIG']) 72610453SAndrew.Bardsley@arm.com Exit(1) 72710453SAndrew.Bardsley@arm.com 72810453SAndrew.Bardsley@arm.com print("Info: Using Python config: %s" % (python_config, )) 72910453SAndrew.Bardsley@arm.com py_includes = readCommand([python_config, '--includes'], 73010453SAndrew.Bardsley@arm.com exception='').split() 73110453SAndrew.Bardsley@arm.com py_includes = filter(lambda s: match(r'.*\/include\/.*',s), py_includes) 73210453SAndrew.Bardsley@arm.com # Strip the -I from the include folders before adding them to the 7339812Sandreas.hansson@arm.com # CPPPATH 73410453SAndrew.Bardsley@arm.com py_includes = map(lambda s: s[2:] if s.startswith('-I') else s, py_includes) 73510453SAndrew.Bardsley@arm.com main.Append(CPPPATH=py_includes) 73610453SAndrew.Bardsley@arm.com 73710453SAndrew.Bardsley@arm.com # Read the linker flags and split them into libraries and other link 73810453SAndrew.Bardsley@arm.com # flags. The libraries are added later through the call the CheckLib. 73910453SAndrew.Bardsley@arm.com py_ld_flags = readCommand([python_config, '--ldflags'], 74010453SAndrew.Bardsley@arm.com exception='').split() 74110453SAndrew.Bardsley@arm.com py_libs = [] 74210453SAndrew.Bardsley@arm.com for lib in py_ld_flags: 74310453SAndrew.Bardsley@arm.com if not lib.startswith('-l'): 74410453SAndrew.Bardsley@arm.com main.Append(LINKFLAGS=[lib]) 74510453SAndrew.Bardsley@arm.com else: 7467727SAli.Saidi@ARM.com lib = lib[2:] 74710453SAndrew.Bardsley@arm.com if lib not in py_libs: 74810453SAndrew.Bardsley@arm.com py_libs.append(lib) 74912790Smatteo.fusi@bsc.es 75012790Smatteo.fusi@bsc.es # verify that this stuff works 75112790Smatteo.fusi@bsc.es if not conf.CheckHeader('Python.h', '<>'): 75212790Smatteo.fusi@bsc.es print("Error: Check failed for Python.h header in", py_includes) 75312790Smatteo.fusi@bsc.es print("Two possible reasons:") 75412790Smatteo.fusi@bsc.es print("1. Python headers are not installed (You can install the " 75512790Smatteo.fusi@bsc.es "package python-dev on Ubuntu and RedHat)") 75610453SAndrew.Bardsley@arm.com print("2. SCons is using a wrong C compiler. This can happen if " 7573118Sstever@eecs.umich.edu "CC has the wrong value.") 75810453SAndrew.Bardsley@arm.com print("CC = %s" % main['CC']) 75910453SAndrew.Bardsley@arm.com Exit(1) 76012563Sgabeblack@google.com 76110453SAndrew.Bardsley@arm.com for lib in py_libs: 7623118Sstever@eecs.umich.edu if not conf.CheckLib(lib): 7633483Ssaidi@eecs.umich.edu print("Error: can't find library %s required by python" % lib) 7643494Ssaidi@eecs.umich.edu Exit(1) 7653494Ssaidi@eecs.umich.edu 76612563Sgabeblack@google.com# On Solaris you need to use libsocket for socket ops 7673483Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7683483Ssaidi@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7693053Sstever@eecs.umich.edu print("Can't find library with socket calls (e.g. accept())") 7703053Sstever@eecs.umich.edu Exit(1) 7713918Ssaidi@eecs.umich.edu 77212563Sgabeblack@google.com# Check for zlib. If the check passes, libz will be automatically 77312563Sgabeblack@google.com# added to the LIBS environment variable. 77412563Sgabeblack@google.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7753053Sstever@eecs.umich.edu print('Error: did not find needed zlib compression library ' 7763053Sstever@eecs.umich.edu 'and/or zlib.h header file.') 7779396Sandreas.hansson@arm.com print(' Please install zlib and try again.') 7789396Sandreas.hansson@arm.com Exit(1) 7799396Sandreas.hansson@arm.com 7809396Sandreas.hansson@arm.com# If we have the protobuf compiler, also make sure we have the 7819396Sandreas.hansson@arm.com# development libraries. If the check passes, libprotobuf will be 7829396Sandreas.hansson@arm.com# automatically added to the LIBS environment variable. After 7839396Sandreas.hansson@arm.com# this, we can use the HAVE_PROTOBUF flag to determine if we have 7849396Sandreas.hansson@arm.com# got both protoc and libprotobuf available. 7859396Sandreas.hansson@arm.commain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 7869477Sandreas.hansson@arm.com conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 7879396Sandreas.hansson@arm.com 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 78812563Sgabeblack@google.com 78912563Sgabeblack@google.com# Valgrind gets much less confused if you tell it when you're using 79012563Sgabeblack@google.com# alternative stacks. 79112563Sgabeblack@google.commain['HAVE_VALGRIND'] = conf.CheckCHeader('valgrind/valgrind.h') 7929396Sandreas.hansson@arm.com 7937840Snate@binkert.org# If we have the compiler but not the library, print another warning. 7947865Sgblack@eecs.umich.eduif main['PROTOC'] and not main['HAVE_PROTOBUF']: 7957865Sgblack@eecs.umich.edu print(termcap.Yellow + termcap.Bold + 7967865Sgblack@eecs.umich.edu 'Warning: did not find protocol buffer library and/or headers.\n' + 7977865Sgblack@eecs.umich.edu ' Please install libprotobuf-dev for tracing support.' + 7987865Sgblack@eecs.umich.edu termcap.Normal) 7997840Snate@binkert.org 8009900Sandreas@sandberg.pp.se# Check for librt. 8019900Sandreas@sandberg.pp.sehave_posix_clock = \ 8029900Sandreas@sandberg.pp.se conf.CheckLibWithHeader(None, 'time.h', 'C', 8039900Sandreas@sandberg.pp.se 'clock_nanosleep(0,0,NULL,NULL);') or \ 80410456SCurtis.Dunham@arm.com conf.CheckLibWithHeader('rt', 'time.h', 'C', 80510456SCurtis.Dunham@arm.com 'clock_nanosleep(0,0,NULL,NULL);') 80610456SCurtis.Dunham@arm.com 80710456SCurtis.Dunham@arm.comhave_posix_timers = \ 80810456SCurtis.Dunham@arm.com conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', 80910456SCurtis.Dunham@arm.com 'timer_create(CLOCK_MONOTONIC, NULL, NULL);') 81012563Sgabeblack@google.com 81112563Sgabeblack@google.comif not GetOption('without_tcmalloc'): 81212563Sgabeblack@google.com if conf.CheckLib('tcmalloc'): 81312563Sgabeblack@google.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 8149045SAli.Saidi@ARM.com elif conf.CheckLib('tcmalloc_minimal'): 81511235Sandreas.sandberg@arm.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 81611235Sandreas.sandberg@arm.com else: 81711235Sandreas.sandberg@arm.com print(termcap.Yellow + termcap.Bold + 81811235Sandreas.sandberg@arm.com "You can get a 12% performance improvement by " 81911235Sandreas.sandberg@arm.com "installing tcmalloc (libgoogle-perftools-dev package " 82012485Sjang.hanhwi@gmail.com "on Ubuntu or RedHat)." + termcap.Normal) 82112485Sjang.hanhwi@gmail.com 82212485Sjang.hanhwi@gmail.com 82311235Sandreas.sandberg@arm.com# Detect back trace implementations. The last implementation in the 82411811Sbaz21@cam.ac.uk# list will be used by default. 82512485Sjang.hanhwi@gmail.combacktrace_impls = [ "none" ] 82611811Sbaz21@cam.ac.uk 82711811Sbaz21@cam.ac.ukbacktrace_checker = 'char temp;' + \ 82811811Sbaz21@cam.ac.uk ' backtrace_symbols_fd((void*)&temp, 0, 0);' 82911235Sandreas.sandberg@arm.comif conf.CheckLibWithHeader(None, 'execinfo.h', 'C', backtrace_checker): 83011235Sandreas.sandberg@arm.com backtrace_impls.append("glibc") 83111235Sandreas.sandberg@arm.comelif conf.CheckLibWithHeader('execinfo', 'execinfo.h', 'C', 83212563Sgabeblack@google.com backtrace_checker): 83312563Sgabeblack@google.com # NetBSD and FreeBSD need libexecinfo. 83412563Sgabeblack@google.com backtrace_impls.append("glibc") 83511235Sandreas.sandberg@arm.com main.Append(LIBS=['execinfo']) 8367840Snate@binkert.org 83712563Sgabeblack@google.comif backtrace_impls[-1] == "none": 8387840Snate@binkert.org default_backtrace_impl = "none" 8391858SN/A print(termcap.Yellow + termcap.Bold + 8401858SN/A "No suitable back trace implementation found." + 8411858SN/A termcap.Normal) 84212563Sgabeblack@google.com 84312563Sgabeblack@google.comif not have_posix_clock: 8441858SN/A print("Can't find library for POSIX clocks.") 84512230Sgiacomo.travaglini@arm.com 84612230Sgiacomo.travaglini@arm.com# Check for <fenv.h> (C99 FP environment control) 84712230Sgiacomo.travaglini@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 84812230Sgiacomo.travaglini@arm.comif not have_fenv: 84912563Sgabeblack@google.com print("Warning: Header file <fenv.h> not found.") 85012563Sgabeblack@google.com print(" This host has no IEEE FP rounding mode control.") 85112563Sgabeblack@google.com 85212230Sgiacomo.travaglini@arm.com# Check for <png.h> (libpng library needed if wanting to dump 8539903Sandreas.hansson@arm.com# frame buffer image in png format) 8549903Sandreas.hansson@arm.comhave_png = conf.CheckHeader('png.h', '<>') 8559903Sandreas.hansson@arm.comif not have_png: 8569903Sandreas.hansson@arm.com print("Warning: Header file <png.h> not found.") 85710841Sandreas.sandberg@arm.com print(" This host has no libpng library.") 8589651SAndreas.Sandberg@ARM.com print(" Disabling support for PNG framebuffers.") 85912563Sgabeblack@google.com 86012563Sgabeblack@google.com# Check if we should enable KVM-based hardware virtualization. The API 8619651SAndreas.Sandberg@ARM.com# we rely on exists since version 2.6.36 of the kernel, but somehow 86212056Sgabeblack@google.com# the KVM_API_VERSION does not reflect the change. We test for one of 86312056Sgabeblack@google.com# the types as a fall back. 86412056Sgabeblack@google.comhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 86512563Sgabeblack@google.comif not have_kvm: 86612056Sgabeblack@google.com print("Info: Compatible header file <linux/kvm.h> not found, " 86710841Sandreas.sandberg@arm.com "disabling KVM support.") 86810841Sandreas.sandberg@arm.com 86910841Sandreas.sandberg@arm.com# Check if the TUN/TAP driver is available. 87010841Sandreas.sandberg@arm.comhave_tuntap = conf.CheckHeader('linux/if_tun.h', '<>') 87110841Sandreas.sandberg@arm.comif not have_tuntap: 87210841Sandreas.sandberg@arm.com print("Info: Compatible header file <linux/if_tun.h> not found.") 8739651SAndreas.Sandberg@ARM.com 8749651SAndreas.Sandberg@ARM.com# x86 needs support for xsave. We test for the structure here since we 8759651SAndreas.Sandberg@ARM.com# won't be able to run new tests by the time we know which ISA we're 8769651SAndreas.Sandberg@ARM.com# targeting. 8779651SAndreas.Sandberg@ARM.comhave_kvm_xsave = conf.CheckTypeSize('struct kvm_xsave', 8789651SAndreas.Sandberg@ARM.com '#include <linux/kvm.h>') != 0 87912563Sgabeblack@google.com 8809651SAndreas.Sandberg@ARM.com# Check if the requested target ISA is compatible with the host 8819651SAndreas.Sandberg@ARM.comdef is_isa_kvm_compatible(isa): 88210841Sandreas.sandberg@arm.com try: 88312563Sgabeblack@google.com import platform 88412563Sgabeblack@google.com host_isa = platform.machine() 88510841Sandreas.sandberg@arm.com except: 88610841Sandreas.sandberg@arm.com print("Warning: Failed to determine host ISA.") 88710841Sandreas.sandberg@arm.com return False 88810860Sandreas.sandberg@arm.com 88910841Sandreas.sandberg@arm.com if not have_posix_timers: 89010841Sandreas.sandberg@arm.com print("Warning: Can not enable KVM, host seems to lack support " 89110841Sandreas.sandberg@arm.com "for POSIX timers") 89210841Sandreas.sandberg@arm.com return False 89310841Sandreas.sandberg@arm.com 89412563Sgabeblack@google.com if isa == "arm": 89510841Sandreas.sandberg@arm.com return host_isa in ( "armv7l", "aarch64" ) 89610841Sandreas.sandberg@arm.com elif isa == "x86": 89710841Sandreas.sandberg@arm.com if host_isa != "x86_64": 89810841Sandreas.sandberg@arm.com return False 89910841Sandreas.sandberg@arm.com 9009651SAndreas.Sandberg@ARM.com if not have_kvm_xsave: 9019651SAndreas.Sandberg@ARM.com print("KVM on x86 requires xsave support in kernel headers.") 9029986Sandreas@sandberg.pp.se return False 9039986Sandreas@sandberg.pp.se 9049986Sandreas@sandberg.pp.se return True 9059986Sandreas@sandberg.pp.se else: 9069986Sandreas@sandberg.pp.se return False 9079986Sandreas@sandberg.pp.se 9085863Snate@binkert.org 9095863Snate@binkert.org# Check if the exclude_host attribute is available. We want this to 9105863Snate@binkert.org# get accurate instruction counts in KVM. 9115863Snate@binkert.orgmain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember( 9126121Snate@binkert.org 'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host') 9131858SN/A 9145863Snate@binkert.org 9155863Snate@binkert.org###################################################################### 9165863Snate@binkert.org# 9175863Snate@binkert.org# Finish the configuration 9185863Snate@binkert.org# 9192139SN/Amain = conf.Finish() 9204202Sbinkertn@umich.edu 92111308Santhony.gutierrez@amd.com###################################################################### 9224202Sbinkertn@umich.edu# 92311308Santhony.gutierrez@amd.com# Collect all non-global variables 9242139SN/A# 9256994Snate@binkert.org 9266994Snate@binkert.org# Define the universe of supported ISAs 9276994Snate@binkert.orgall_isa_list = [ ] 9286994Snate@binkert.orgall_gpu_isa_list = [ ] 9296994Snate@binkert.orgExport('all_isa_list') 9306994Snate@binkert.orgExport('all_gpu_isa_list') 9316994Snate@binkert.org 9326994Snate@binkert.orgclass CpuModel(object): 93310319SAndreas.Sandberg@ARM.com '''The CpuModel class encapsulates everything the ISA parser needs to 9346994Snate@binkert.org know about a particular CPU model.''' 9356994Snate@binkert.org 9366994Snate@binkert.org # Dict of available CPU model objects. Accessible as CpuModel.dict. 9376994Snate@binkert.org dict = {} 9386994Snate@binkert.org 9396994Snate@binkert.org # Constructor. Automatically adds models to CpuModel.dict. 9406994Snate@binkert.org def __init__(self, name, default=False): 9416994Snate@binkert.org self.name = name # name of model 9426994Snate@binkert.org 9436994Snate@binkert.org # This cpu is enabled by default 9446994Snate@binkert.org self.default = default 9452155SN/A 9465863Snate@binkert.org # Add self to dict 9471869SN/A if name in CpuModel.dict: 9481869SN/A raise AttributeError, "CpuModel '%s' already registered" % name 9495863Snate@binkert.org CpuModel.dict[name] = self 9505863Snate@binkert.org 9514202Sbinkertn@umich.eduExport('CpuModel') 9526108Snate@binkert.org 9536108Snate@binkert.org# Sticky variables get saved in the variables file so they persist from 9546108Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 9556108Snate@binkert.org# value becomes sticky). 9569219Spower.jg@gmail.comsticky_vars = Variables(args=ARGUMENTS) 9579219Spower.jg@gmail.comExport('sticky_vars') 9589219Spower.jg@gmail.com 9599219Spower.jg@gmail.com# Sticky variables that should be exported 9609219Spower.jg@gmail.comexport_vars = [] 9619219Spower.jg@gmail.comExport('export_vars') 9629219Spower.jg@gmail.com 9639219Spower.jg@gmail.com# For Ruby 9644202Sbinkertn@umich.eduall_protocols = [] 9655863Snate@binkert.orgExport('all_protocols') 96610135SCurtis.Dunham@arm.comprotocol_dirs = [] 96712563Sgabeblack@google.comExport('protocol_dirs') 9685742Snate@binkert.orgslicc_includes = [] 9698268Ssteve.reinhardt@amd.comExport('slicc_includes') 97012563Sgabeblack@google.com 9718268Ssteve.reinhardt@amd.com# Walk the tree and execute all SConsopts scripts that wil add to the 9725742Snate@binkert.org# above variables 9735341Sstever@gmail.comif GetOption('verbose'): 9748474Sgblack@eecs.umich.edu print("Reading SConsopts") 97512563Sgabeblack@google.comfor bdir in [ base_dir ] + extras_dir_list: 9765342Sstever@gmail.com if not isdir(bdir): 9774202Sbinkertn@umich.edu print("Error: directory '%s' does not exist" % bdir) 9784202Sbinkertn@umich.edu Exit(1) 97911308Santhony.gutierrez@amd.com for root, dirs, files in os.walk(bdir): 9804202Sbinkertn@umich.edu if 'SConsopts' in files: 9815863Snate@binkert.org if GetOption('verbose'): 9825863Snate@binkert.org print("Reading", joinpath(root, 'SConsopts')) 98311308Santhony.gutierrez@amd.com SConscript(joinpath(root, 'SConsopts')) 9846994Snate@binkert.org 9856994Snate@binkert.orgall_isa_list.sort() 98610319SAndreas.Sandberg@ARM.comall_gpu_isa_list.sort() 9875863Snate@binkert.org 9885863Snate@binkert.orgsticky_vars.AddVariables( 9895863Snate@binkert.org EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 9905863Snate@binkert.org EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'hsail', all_gpu_isa_list), 9915863Snate@binkert.org ListVariable('CPU_MODELS', 'CPU models', 9925863Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 9935863Snate@binkert.org sorted(CpuModel.dict.keys())), 9945863Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 9957840Snate@binkert.org False), 9965863Snate@binkert.org BoolVariable('SS_COMPATIBLE_FP', 99712230Sgiacomo.travaglini@arm.com 'Make floating-point results compatible with SimpleScalar', 99812230Sgiacomo.travaglini@arm.com False), 99912230Sgiacomo.travaglini@arm.com BoolVariable('USE_SSE2', 100012230Sgiacomo.travaglini@arm.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 100112230Sgiacomo.travaglini@arm.com False), 100212056Sgabeblack@google.com BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 100312056Sgabeblack@google.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 100412056Sgabeblack@google.com BoolVariable('USE_PNG', 'Enable support for PNG images', have_png), 100511308Santhony.gutierrez@amd.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', 10069219Spower.jg@gmail.com False), 10079219Spower.jg@gmail.com BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', 100811235Sandreas.sandberg@arm.com have_kvm), 100911235Sandreas.sandberg@arm.com BoolVariable('USE_TUNTAP', 10101869SN/A 'Enable using a tap device to bridge to the host network', 10111858SN/A have_tuntap), 10125863Snate@binkert.org BoolVariable('BUILD_GPU', 'Build the compute-GPU model', False), 101311308Santhony.gutierrez@amd.com EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 101412061Sjason@lowepower.com all_protocols), 101512230Sgiacomo.travaglini@arm.com EnumVariable('BACKTRACE_IMPL', 'Post-mortem dump implementation', 101612230Sgiacomo.travaglini@arm.com backtrace_impls[-1], backtrace_impls), 10171858SN/A ('NUMBER_BITS_PER_SET', 'Max elements in set (default 64)', 1018955SN/A 64), 1019955SN/A ) 10201869SN/A 10211869SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript). 10221869SN/Aexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA', 10231869SN/A 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP', 10241869SN/A 'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_VALGRIND', 10255863Snate@binkert.org 'HAVE_PERF_ATTR_EXCLUDE_HOST', 'USE_PNG', 10265863Snate@binkert.org 'NUMBER_BITS_PER_SET'] 10275863Snate@binkert.org 10281869SN/A################################################### 10295863Snate@binkert.org# 10301869SN/A# Define a SCons builder for configuration flag headers. 103112563Sgabeblack@google.com# 10321869SN/A################################################### 10331869SN/A 10341869SN/A# This function generates a config header file that #defines the 10351869SN/A# variable symbol to the current variable setting (0 or 1). The source 10368483Sgblack@eecs.umich.edu# operands are the name of the variable and a Value node containing the 10371869SN/A# value of the variable. 10381869SN/Adef build_config_file(target, source, env): 10391869SN/A (variable, value) = [s.get_contents() for s in source] 10401869SN/A f = file(str(target[0]), 'w') 10415863Snate@binkert.org print('#define', variable, value, file=f) 10425863Snate@binkert.org f.close() 10431869SN/A return None 10445863Snate@binkert.org 10455863Snate@binkert.org# Combine the two functions into a scons Action object. 10463356Sbinkertn@umich.educonfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 10473356Sbinkertn@umich.edu 10483356Sbinkertn@umich.edu# The emitter munges the source & target node lists to reflect what 10493356Sbinkertn@umich.edu# we're really doing. 10503356Sbinkertn@umich.edudef config_emitter(target, source, env): 10514781Snate@binkert.org # extract variable name from Builder arg 10525863Snate@binkert.org variable = str(target[0]) 10535863Snate@binkert.org # True target is config header file 10541869SN/A target = joinpath('config', variable.lower() + '.hh') 10551869SN/A val = env[variable] 10561869SN/A if isinstance(val, bool): 10576121Snate@binkert.org # Force value to 0/1 10581869SN/A val = int(val) 105911982Sgabeblack@google.com elif isinstance(val, str): 106011982Sgabeblack@google.com val = '"' + val + '"' 106111982Sgabeblack@google.com 106211982Sgabeblack@google.com # Sources are variable name & value (packaged in SCons Value nodes) 106311982Sgabeblack@google.com return ([target], [Value(variable), Value(val)]) 106411982Sgabeblack@google.com 106511982Sgabeblack@google.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 106611982Sgabeblack@google.com 106711982Sgabeblack@google.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 106811982Sgabeblack@google.com 106911982Sgabeblack@google.com################################################### 107011982Sgabeblack@google.com# 107111982Sgabeblack@google.com# Builders for static and shared partially linked object files. 107211982Sgabeblack@google.com# 107311982Sgabeblack@google.com################################################### 107411982Sgabeblack@google.com 107511982Sgabeblack@google.compartial_static_builder = Builder(action=SCons.Defaults.LinkAction, 107611982Sgabeblack@google.com src_suffix='$OBJSUFFIX', 107711982Sgabeblack@google.com src_builder=['StaticObject', 'Object'], 107811982Sgabeblack@google.com LINKFLAGS='$PLINKFLAGS', 107911982Sgabeblack@google.com LIBS='') 108011982Sgabeblack@google.com 108111982Sgabeblack@google.comdef partial_shared_emitter(target, source, env): 108211982Sgabeblack@google.com for tgt in target: 108311982Sgabeblack@google.com tgt.attributes.shared = 1 108411982Sgabeblack@google.com return (target, source) 108511978Sgabeblack@google.compartial_shared_builder = Builder(action=SCons.Defaults.ShLinkAction, 108611978Sgabeblack@google.com emitter=partial_shared_emitter, 108712034Sgabeblack@google.com src_suffix='$SHOBJSUFFIX', 108811978Sgabeblack@google.com src_builder='SharedObject', 108911978Sgabeblack@google.com SHLINKFLAGS='$PSHLINKFLAGS', 109011978Sgabeblack@google.com LIBS='') 109112034Sgabeblack@google.com 109211978Sgabeblack@google.commain.Append(BUILDERS = { 'PartialShared' : partial_shared_builder, 109311978Sgabeblack@google.com 'PartialStatic' : partial_static_builder }) 109410915Sandreas.sandberg@arm.com 109511986Sandreas.sandberg@arm.comdef add_local_rpath(env, *targets): 109611986Sandreas.sandberg@arm.com '''Set up an RPATH for a library which lives in the build directory. 10971869SN/A 10981869SN/A The construction environment variable BIN_RPATH_PREFIX should be set to 109912015Sgabeblack@google.com the relative path of the build directory starting from the location of the 110012015Sgabeblack@google.com binary.''' 110112015Sgabeblack@google.com for target in targets: 110212015Sgabeblack@google.com target = env.Entry(target) 11033546Sgblack@eecs.umich.edu if not isinstance(target, SCons.Node.FS.Dir): 11043546Sgblack@eecs.umich.edu target = target.dir 11053546Sgblack@eecs.umich.edu relpath = os.path.relpath(target.abspath, env['BUILDDIR']) 110612015Sgabeblack@google.com components = [ 110712015Sgabeblack@google.com '\\$$ORIGIN', 110812015Sgabeblack@google.com '${BIN_RPATH_PREFIX}', 110912015Sgabeblack@google.com relpath 111012015Sgabeblack@google.com ] 111112015Sgabeblack@google.com env.Append(RPATH=[env.Literal(os.path.join(*components))]) 111212015Sgabeblack@google.com 111312563Sgabeblack@google.comif sys.platform != "darwin": 11143546Sgblack@eecs.umich.edu main.Append(LINKFLAGS=Split('-z origin')) 111512015Sgabeblack@google.com 111612015Sgabeblack@google.commain.AddMethod(add_local_rpath, 'AddLocalRPATH') 111710196SCurtis.Dunham@arm.com 111812015Sgabeblack@google.com# builds in ext are shared across all configs in the build root. 111912015Sgabeblack@google.comext_dir = abspath(joinpath(str(main.root), 'ext')) 112012015Sgabeblack@google.comext_build_dirs = [] 112112015Sgabeblack@google.comfor root, dirs, files in os.walk(ext_dir): 112212015Sgabeblack@google.com if 'SConscript' in files: 112312015Sgabeblack@google.com build_dir = os.path.relpath(root, ext_dir) 112412015Sgabeblack@google.com ext_build_dirs.append(build_dir) 112512015Sgabeblack@google.com main.SConscript(joinpath(root, 'SConscript'), 112612015Sgabeblack@google.com variant_dir=joinpath(build_root, build_dir)) 112712015Sgabeblack@google.com 112812015Sgabeblack@google.comgdb_xml_dir = joinpath(ext_dir, 'gdb-xml') 11293546Sgblack@eecs.umich.eduExport('gdb_xml_dir') 11303546Sgblack@eecs.umich.edu 11313546Sgblack@eecs.umich.edumain.Prepend(CPPPATH=Dir('ext/pybind11/include/')) 1132955SN/A 1133955SN/A################################################### 1134955SN/A# 1135955SN/A# This builder and wrapper method are used to set up a directory with 11365863Snate@binkert.org# switching headers. Those are headers which are in a generic location and 113710135SCurtis.Dunham@arm.com# that include more specific headers from a directory chosen at build time 113812563Sgabeblack@google.com# based on the current build settings. 11395343Sstever@gmail.com# 11405343Sstever@gmail.com################################################### 11416121Snate@binkert.org 11425863Snate@binkert.orgdef build_switching_header(target, source, env): 11434773Snate@binkert.org path = str(target[0]) 11445863Snate@binkert.org subdir = str(source[0]) 11452632Sstever@eecs.umich.edu dp, fp = os.path.split(path) 11465863Snate@binkert.org dp = os.path.relpath(os.path.realpath(dp), 11472023SN/A os.path.realpath(env['BUILDDIR'])) 11485863Snate@binkert.org with open(path, 'w') as hdr: 11495863Snate@binkert.org print('#include "%s/%s/%s"' % (dp, subdir, fp), file=hdr) 11505863Snate@binkert.org 11515863Snate@binkert.orgswitching_header_action = MakeAction(build_switching_header, 11525863Snate@binkert.org Transform('GENERATE')) 11535863Snate@binkert.org 11545863Snate@binkert.orgswitching_header_builder = Builder(action=switching_header_action, 11555863Snate@binkert.org source_factory=Value, 115610135SCurtis.Dunham@arm.com single_source=True) 115712563Sgabeblack@google.com 115812034Sgabeblack@google.commain.Append(BUILDERS = { 'SwitchingHeader': switching_header_builder }) 115912034Sgabeblack@google.com 116012034Sgabeblack@google.comdef switching_headers(self, headers, source): 11612632Sstever@eecs.umich.edu for header in headers: 11625863Snate@binkert.org self.SwitchingHeader(header, source) 11632023SN/A 11642632Sstever@eecs.umich.edumain.AddMethod(switching_headers, 'SwitchingHeaders') 11655863Snate@binkert.org 11665342Sstever@gmail.com################################################### 11675863Snate@binkert.org# 11682632Sstever@eecs.umich.edu# Define build environments for selected configurations. 11695863Snate@binkert.org# 11705863Snate@binkert.org################################################### 11718267Ssteve.reinhardt@amd.com 11728120Sgblack@eecs.umich.edufor variant_path in variant_paths: 11738267Ssteve.reinhardt@amd.com if not GetOption('silent'): 11748267Ssteve.reinhardt@amd.com print("Building in", variant_path) 11758267Ssteve.reinhardt@amd.com 11768267Ssteve.reinhardt@amd.com # Make a copy of the build-root environment to use for this config. 11778267Ssteve.reinhardt@amd.com env = main.Clone() 11788267Ssteve.reinhardt@amd.com env['BUILDDIR'] = variant_path 11798267Ssteve.reinhardt@amd.com 11808267Ssteve.reinhardt@amd.com # variant_dir is the tail component of build path, and is used to 11818267Ssteve.reinhardt@amd.com # determine the build parameters (e.g., 'ALPHA_SE') 11825863Snate@binkert.org (build_root, variant_dir) = splitpath(variant_path) 118312563Sgabeblack@google.com 118412563Sgabeblack@google.com # Set env variables according to the build directory config. 11852632Sstever@eecs.umich.edu sticky_vars.files = [] 118612563Sgabeblack@google.com # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 118712563Sgabeblack@google.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 118812563Sgabeblack@google.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 11892632Sstever@eecs.umich.edu current_vars_file = joinpath(build_root, 'variables', variant_dir) 11901888SN/A if isfile(current_vars_file): 11915863Snate@binkert.org sticky_vars.files.append(current_vars_file) 11925863Snate@binkert.org if not GetOption('silent'): 11931858SN/A print("Using saved variables file %s" % current_vars_file) 11948120Sgblack@eecs.umich.edu elif variant_dir in ext_build_dirs: 11958120Sgblack@eecs.umich.edu # Things in ext are built without a variant directory. 11967756SAli.Saidi@ARM.com continue 11972598SN/A else: 11985863Snate@binkert.org # Build dir-specific variables file doesn't exist. 11991858SN/A 12001858SN/A # Make sure the directory is there so we can create it later 120112563Sgabeblack@google.com opt_dir = dirname(current_vars_file) 120212563Sgabeblack@google.com if not isdir(opt_dir): 12031858SN/A mkdir(opt_dir) 12041858SN/A 12051858SN/A # Get default build variables from source tree. Variables are 120612563Sgabeblack@google.com # normally determined by name of $VARIANT_DIR, but can be 120712563Sgabeblack@google.com # overridden by '--default=' arg on command line. 120812563Sgabeblack@google.com default = GetOption('default') 12091858SN/A opts_dir = joinpath(main.root.abspath, 'build_opts') 121012230Sgiacomo.travaglini@arm.com if default: 121112563Sgabeblack@google.com default_vars_files = [joinpath(build_root, 'variables', default), 121212563Sgabeblack@google.com joinpath(opts_dir, default)] 121312230Sgiacomo.travaglini@arm.com else: 121412230Sgiacomo.travaglini@arm.com default_vars_files = [joinpath(opts_dir, variant_dir)] 121512230Sgiacomo.travaglini@arm.com existing_files = filter(isfile, default_vars_files) 121612230Sgiacomo.travaglini@arm.com if existing_files: 121712230Sgiacomo.travaglini@arm.com default_vars_file = existing_files[0] 12181858SN/A sticky_vars.files.append(default_vars_file) 12191858SN/A print("Variables file %s not found,\n using defaults in %s" 12201858SN/A % (current_vars_file, default_vars_file)) 12219651SAndreas.Sandberg@ARM.com else: 12229651SAndreas.Sandberg@ARM.com print("Error: cannot find variables file %s or " 122312563Sgabeblack@google.com "default file(s) %s" 122412563Sgabeblack@google.com % (current_vars_file, ' or '.join(default_vars_files))) 12259651SAndreas.Sandberg@ARM.com Exit(1) 12269651SAndreas.Sandberg@ARM.com 122712563Sgabeblack@google.com # Apply current variable settings to env 122812563Sgabeblack@google.com sticky_vars.Update(env) 12299651SAndreas.Sandberg@ARM.com 12309651SAndreas.Sandberg@ARM.com help_texts["local_vars"] += \ 123112056Sgabeblack@google.com "Build variables for %s:\n" % variant_dir \ 123212056Sgabeblack@google.com + sticky_vars.GenerateHelpText(env) 123312563Sgabeblack@google.com 123412056Sgabeblack@google.com # Process variable settings. 123512056Sgabeblack@google.com 123611798Santhony.gutierrez@amd.com if not have_fenv and env['USE_FENV']: 123711798Santhony.gutierrez@amd.com print("Warning: <fenv.h> not available; " 123811798Santhony.gutierrez@amd.com "forcing USE_FENV to False in", variant_dir + ".") 12399986Sandreas@sandberg.pp.se env['USE_FENV'] = False 12409986Sandreas@sandberg.pp.se 12419986Sandreas@sandberg.pp.se if not env['USE_FENV']: 124212563Sgabeblack@google.com print("Warning: No IEEE FP rounding mode control in", 124312563Sgabeblack@google.com variant_dir + ".") 124412563Sgabeblack@google.com print(" FP results may deviate slightly from other platforms.") 12459986Sandreas@sandberg.pp.se 12465863Snate@binkert.org if not have_png and env['USE_PNG']: 12475863Snate@binkert.org print("Warning: <png.h> not available; " 12481869SN/A "forcing USE_PNG to False in", variant_dir + ".") 12491965SN/A env['USE_PNG'] = False 12507739Sgblack@eecs.umich.edu 12511965SN/A if env['USE_PNG']: 12522761Sstever@eecs.umich.edu env.Append(LIBS=['png']) 12535863Snate@binkert.org 12541869SN/A if env['EFENCE']: 125510196SCurtis.Dunham@arm.com env.Append(LIBS=['efence']) 12561869SN/A 12578120Sgblack@eecs.umich.edu if env['USE_KVM']: 12588120Sgblack@eecs.umich.edu if not have_kvm: 12598120Sgblack@eecs.umich.edu print("Warning: Can not enable KVM, host seems to " 12608120Sgblack@eecs.umich.edu "lack KVM support") 12618120Sgblack@eecs.umich.edu env['USE_KVM'] = False 12628120Sgblack@eecs.umich.edu elif not is_isa_kvm_compatible(env['TARGET_ISA']): 12638120Sgblack@eecs.umich.edu print("Info: KVM support disabled due to unsupported host and " 12648120Sgblack@eecs.umich.edu "target ISA combination") 12658120Sgblack@eecs.umich.edu env['USE_KVM'] = False 12668120Sgblack@eecs.umich.edu 12678120Sgblack@eecs.umich.edu if env['USE_TUNTAP']: 12688120Sgblack@eecs.umich.edu if not have_tuntap: 1269 print("Warning: Can't connect EtherTap with a tap device.") 1270 env['USE_TUNTAP'] = False 1271 1272 if env['BUILD_GPU']: 1273 env.Append(CPPDEFINES=['BUILD_GPU']) 1274 1275 # Warn about missing optional functionality 1276 if env['USE_KVM']: 1277 if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']: 1278 print("Warning: perf_event headers lack support for the " 1279 "exclude_host attribute. KVM instruction counts will " 1280 "be inaccurate.") 1281 1282 # Save sticky variable settings back to current variables file 1283 sticky_vars.Save(current_vars_file, env) 1284 1285 if env['USE_SSE2']: 1286 env.Append(CCFLAGS=['-msse2']) 1287 1288 # The src/SConscript file sets up the build rules in 'env' according 1289 # to the configured variables. It returns a list of environments, 1290 # one for each variant build (debug, opt, etc.) 1291 SConscript('src/SConscript', variant_dir = variant_path, exports = 'env') 1292 1293# base help text 1294Help(''' 1295Usage: scons [scons options] [build variables] [target(s)] 1296 1297Extra scons options: 1298%(options)s 1299 1300Global build variables: 1301%(global_vars)s 1302 1303%(local_vars)s 1304''' % help_texts) 1305