SConstruct revision 13715
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 816654Snate@binkert.orgfrom __future__ import print_function 8210196SCurtis.Dunham@arm.com 83955SN/A# Global Python includes 845396Ssaidi@eecs.umich.eduimport itertools 8511401Sandreas.sandberg@arm.comimport os 865863Snate@binkert.orgimport re 875863Snate@binkert.orgimport shutil 884202Sbinkertn@umich.eduimport subprocess 895863Snate@binkert.orgimport sys 905863Snate@binkert.org 915863Snate@binkert.orgfrom os import mkdir, environ 925863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 93955SN/Afrom os.path import exists, isdir, isfile 946654Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 955273Sstever@gmail.comfrom re import match 965871Snate@binkert.org 975273Sstever@gmail.com# SCons includes 986654Snate@binkert.orgimport SCons 995396Ssaidi@eecs.umich.eduimport SCons.Node 1008120Sgblack@eecs.umich.edu 1018120Sgblack@eecs.umich.edufrom m5.util import compareVersions, readCommand 1028120Sgblack@eecs.umich.edu 1038120Sgblack@eecs.umich.eduhelp_texts = { 1048120Sgblack@eecs.umich.edu "options" : "", 1058120Sgblack@eecs.umich.edu "global_vars" : "", 1068120Sgblack@eecs.umich.edu "local_vars" : "" 1078120Sgblack@eecs.umich.edu} 1088879Ssteve.reinhardt@amd.com 1098879Ssteve.reinhardt@amd.comExport("help_texts") 1108879Ssteve.reinhardt@amd.com 1118879Ssteve.reinhardt@amd.com 1128879Ssteve.reinhardt@amd.com# There's a bug in scons in that (1) by default, the help texts from 1138879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h' 1148879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the 1158879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once 1168879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get 1178879Ssteve.reinhardt@amd.com# at the help texts from AddOptions. See: 1188879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1198879Ssteve.reinhardt@amd.com# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1208879Ssteve.reinhardt@amd.com# This hack lets us extract the help text from AddOptions and 1218120Sgblack@eecs.umich.edu# re-inject it via Help(). Ideally someday this bug will be fixed and 1228120Sgblack@eecs.umich.edu# we can just use AddOption directly. 1238120Sgblack@eecs.umich.edudef AddLocalOption(*args, **kwargs): 1248120Sgblack@eecs.umich.edu col_width = 30 1258120Sgblack@eecs.umich.edu 1268120Sgblack@eecs.umich.edu help = " " + ", ".join(args) 1278120Sgblack@eecs.umich.edu if "help" in kwargs: 1288120Sgblack@eecs.umich.edu length = len(help) 1298120Sgblack@eecs.umich.edu if length >= col_width: 1308120Sgblack@eecs.umich.edu help += "\n" + " " * col_width 1318120Sgblack@eecs.umich.edu else: 1328120Sgblack@eecs.umich.edu help += " " * (col_width - length) 1338120Sgblack@eecs.umich.edu help += kwargs["help"] 1348120Sgblack@eecs.umich.edu help_texts["options"] += help + "\n" 1358879Ssteve.reinhardt@amd.com 1368879Ssteve.reinhardt@amd.com AddOption(*args, **kwargs) 1378879Ssteve.reinhardt@amd.com 1388879Ssteve.reinhardt@amd.comAddLocalOption('--colors', dest='use_colors', action='store_true', 13910458Sandreas.hansson@arm.com help="Add color to abbreviated scons output") 14010458Sandreas.hansson@arm.comAddLocalOption('--no-colors', dest='use_colors', action='store_false', 14110458Sandreas.hansson@arm.com help="Don't add color to abbreviated scons output") 1428879Ssteve.reinhardt@amd.comAddLocalOption('--with-cxx-config', dest='with_cxx_config', 1438879Ssteve.reinhardt@amd.com action='store_true', 1448879Ssteve.reinhardt@amd.com help="Build with support for C++-based configuration") 1458879Ssteve.reinhardt@amd.comAddLocalOption('--default', dest='default', type='string', action='store', 1469227Sandreas.hansson@arm.com help='Override which build_opts file to use for defaults') 1479227Sandreas.hansson@arm.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 14812063Sgabeblack@google.com help='Disable style checking hooks') 14912063Sgabeblack@google.comAddLocalOption('--gold-linker', dest='gold_linker', action='store_true', 15012063Sgabeblack@google.com help='Use the gold linker') 1518879Ssteve.reinhardt@amd.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1528879Ssteve.reinhardt@amd.com help='Disable Link-Time Optimization for fast') 1538879Ssteve.reinhardt@amd.comAddLocalOption('--force-lto', dest='force_lto', action='store_true', 1548879Ssteve.reinhardt@amd.com help='Use Link-Time Optimization instead of partial linking' + 15510453SAndrew.Bardsley@arm.com ' when the compiler doesn\'t support using them together.') 15610453SAndrew.Bardsley@arm.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 15710453SAndrew.Bardsley@arm.com help='Update test reference outputs') 15810456SCurtis.Dunham@arm.comAddLocalOption('--verbose', dest='verbose', action='store_true', 15910456SCurtis.Dunham@arm.com help='Print full tool command lines') 16010456SCurtis.Dunham@arm.comAddLocalOption('--without-python', dest='without_python', 16110457Sandreas.hansson@arm.com action='store_true', 16210457Sandreas.hansson@arm.com help='Build without Python configuration support') 16311342Sandreas.hansson@arm.comAddLocalOption('--without-tcmalloc', dest='without_tcmalloc', 16411342Sandreas.hansson@arm.com action='store_true', 1658120Sgblack@eecs.umich.edu help='Disable linking against tcmalloc') 16612063Sgabeblack@google.comAddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true', 16712063Sgabeblack@google.com help='Build with Undefined Behavior Sanitizer if available') 16812063Sgabeblack@google.comAddLocalOption('--with-asan', dest='with_asan', action='store_true', 16912063Sgabeblack@google.com help='Build with Address Sanitizer if available') 1705871Snate@binkert.org 1715871Snate@binkert.orgif GetOption('no_lto') and GetOption('force_lto'): 1726121Snate@binkert.org print('--no-lto and --force-lto are mutually exclusive') 1735871Snate@binkert.org Exit(1) 1745871Snate@binkert.org 1759926Sstan.czerniawski@arm.com######################################################################## 17612243Sgabeblack@google.com# 1771533SN/A# Set up the main build environment. 17812246Sgabeblack@google.com# 17912246Sgabeblack@google.com######################################################################## 18012246Sgabeblack@google.com 18112246Sgabeblack@google.commain = Environment() 1829239Sandreas.hansson@arm.com 1839239Sandreas.hansson@arm.comfrom gem5_scons import Transform 1849239Sandreas.hansson@arm.comfrom gem5_scons.util import get_termcap 1859239Sandreas.hansson@arm.comtermcap = get_termcap() 1869239Sandreas.hansson@arm.com 1879239Sandreas.hansson@arm.commain_dict_keys = main.Dictionary().keys() 1889239Sandreas.hansson@arm.com 189955SN/A# Check that we have a C/C++ compiler 190955SN/Aif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 1912632Sstever@eecs.umich.edu print("No C++ compiler installed (package g++ on Ubuntu and RedHat)") 1922632Sstever@eecs.umich.edu Exit(1) 193955SN/A 194955SN/A################################################### 195955SN/A# 196955SN/A# Figure out which configurations to set up based on the path(s) of 1978878Ssteve.reinhardt@amd.com# the target(s). 198955SN/A# 1992632Sstever@eecs.umich.edu################################################### 2002632Sstever@eecs.umich.edu 2012632Sstever@eecs.umich.edu# Find default configuration & binary. 2022632Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2032632Sstever@eecs.umich.edu 2042632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 2052632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 2068268Ssteve.reinhardt@amd.com for i in range(len(l)+offs, 0, -1): 2078268Ssteve.reinhardt@amd.com if l[i] == elt: 2088268Ssteve.reinhardt@amd.com return i 2098268Ssteve.reinhardt@amd.com raise ValueError, "element not found" 2108268Ssteve.reinhardt@amd.com 2118268Ssteve.reinhardt@amd.com# Take a list of paths (or SCons Nodes) and return a list with all 2128268Ssteve.reinhardt@amd.com# paths made absolute and ~-expanded. Paths will be interpreted 2132632Sstever@eecs.umich.edu# relative to the launch directory unless a different root is provided 2142632Sstever@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 2152632Sstever@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 2162632Sstever@eecs.umich.edu for p in path_list] 2178268Ssteve.reinhardt@amd.com 2182632Sstever@eecs.umich.edudef find_first_prog(prog_names): 2198268Ssteve.reinhardt@amd.com """Find the absolute path to the first existing binary in prog_names""" 2208268Ssteve.reinhardt@amd.com 2218268Ssteve.reinhardt@amd.com if not isinstance(prog_names, (list, tuple)): 2228268Ssteve.reinhardt@amd.com prog_names = [ prog_names ] 2233718Sstever@eecs.umich.edu 2242634Sstever@eecs.umich.edu for p in prog_names: 2252634Sstever@eecs.umich.edu p = main.WhereIs(p) 2265863Snate@binkert.org if p is not None: 2272638Sstever@eecs.umich.edu return p 2288268Ssteve.reinhardt@amd.com 2292632Sstever@eecs.umich.edu return None 2302632Sstever@eecs.umich.edu 2312632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2322632Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2332632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2341858SN/A# recognize that ALPHA_SE specifies the configuration because it 2353716Sstever@eecs.umich.edu# follow 'build' in the build path. 2362638Sstever@eecs.umich.edu 2372638Sstever@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 2382638Sstever@eecs.umich.edu# in place rather than reassign the symbol to a new list, which 2392638Sstever@eecs.umich.edu# doesn't work (obviously!). 2402638Sstever@eecs.umich.eduBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 2412638Sstever@eecs.umich.edu 2422638Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 2435863Snate@binkert.org# collected targets reference. 2445863Snate@binkert.orgvariant_paths = [] 2455863Snate@binkert.orgbuild_root = None 246955SN/Afor t in BUILD_TARGETS: 2475341Sstever@gmail.com path_dirs = t.split('/') 2485341Sstever@gmail.com try: 2495863Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 2507756SAli.Saidi@ARM.com except: 2515341Sstever@gmail.com print("Error: no non-leaf 'build' dir found on target path", t) 2526121Snate@binkert.org Exit(1) 2534494Ssaidi@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2546121Snate@binkert.org if not build_root: 2551105SN/A build_root = this_build_root 2562667Sstever@eecs.umich.edu else: 2572667Sstever@eecs.umich.edu if this_build_root != build_root: 2582667Sstever@eecs.umich.edu print("Error: build targets not under same build root\n" 2592667Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root)) 2606121Snate@binkert.org Exit(1) 2612667Sstever@eecs.umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 2625341Sstever@gmail.com if variant_path not in variant_paths: 2635863Snate@binkert.org variant_paths.append(variant_path) 2645341Sstever@gmail.com 2655341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there) 2665341Sstever@gmail.comif not isdir(build_root): 2678120Sgblack@eecs.umich.edu mkdir(build_root) 2685341Sstever@gmail.commain['BUILDROOT'] = build_root 2698120Sgblack@eecs.umich.edu 2705341Sstever@gmail.comExport('main') 2718120Sgblack@eecs.umich.edu 2726121Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign")) 2736121Snate@binkert.org 2749396Sandreas.hansson@arm.com# Default duplicate option is to use hard links, but this messes up 2755397Ssaidi@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 2765397Ssaidi@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2777727SAli.Saidi@ARM.com# (soft) links work better. 2788268Ssteve.reinhardt@amd.commain.SetOption('duplicate', 'soft-copy') 2796168Snate@binkert.org 2805341Sstever@gmail.com# 2818120Sgblack@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 2828120Sgblack@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 2838120Sgblack@eecs.umich.edu# 2846814Sgblack@eecs.umich.edu 2855863Snate@binkert.orgglobal_vars_file = joinpath(build_root, 'variables.global') 2868120Sgblack@eecs.umich.edu 2875341Sstever@gmail.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 2885863Snate@binkert.org 2898268Ssteve.reinhardt@amd.comglobal_vars.AddVariables( 2906121Snate@binkert.org ('CC', 'C compiler', environ.get('CC', main['CC'])), 2916121Snate@binkert.org ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 2928268Ssteve.reinhardt@amd.com ('PYTHON_CONFIG', 'Python config binary to use', 2935742Snate@binkert.org [ 'python2.7-config', 'python-config' ]), 2945742Snate@binkert.org ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 2955341Sstever@gmail.com ('BATCH', 'Use batch pool for build and tests', False), 2965742Snate@binkert.org ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 2975742Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 2985341Sstever@gmail.com ('EXTRAS', 'Add extra directories to the compilation', '') 2996017Snate@binkert.org ) 3006121Snate@binkert.org 3016017Snate@binkert.org# Update main environment with values from ARGUMENTS & global_vars_file 30212158Sandreas.sandberg@arm.comglobal_vars.Update(main) 30312158Sandreas.sandberg@arm.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 30412158Sandreas.sandberg@arm.com 3058120Sgblack@eecs.umich.edu# Save sticky variable settings back to current variables file 3067756SAli.Saidi@ARM.comglobal_vars.Save(global_vars_file, main) 3077756SAli.Saidi@ARM.com 3087756SAli.Saidi@ARM.com# Parse EXTRAS variable to build list of all directories where we're 3097756SAli.Saidi@ARM.com# look for sources etc. This list is exported as extras_dir_list. 3107816Ssteve.reinhardt@amd.combase_dir = main.srcdir.abspath 3117816Ssteve.reinhardt@amd.comif main['EXTRAS']: 3127816Ssteve.reinhardt@amd.com extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3137816Ssteve.reinhardt@amd.comelse: 3147816Ssteve.reinhardt@amd.com extras_dir_list = [] 31511979Sgabeblack@google.com 3167816Ssteve.reinhardt@amd.comExport('base_dir') 3177816Ssteve.reinhardt@amd.comExport('extras_dir_list') 3187816Ssteve.reinhardt@amd.com 3197816Ssteve.reinhardt@amd.com# the ext directory should be on the #includes path 3207756SAli.Saidi@ARM.commain.Append(CPPPATH=[Dir('ext')]) 3217756SAli.Saidi@ARM.com 3229227Sandreas.hansson@arm.com# Add shared top-level headers 3239227Sandreas.hansson@arm.commain.Prepend(CPPPATH=Dir('include')) 3249227Sandreas.hansson@arm.com 3259227Sandreas.hansson@arm.comif GetOption('verbose'): 3269590Sandreas@sandberg.pp.se def MakeAction(action, string, *args, **kwargs): 3279590Sandreas@sandberg.pp.se return Action(action, *args, **kwargs) 3289590Sandreas@sandberg.pp.seelse: 3299590Sandreas@sandberg.pp.se MakeAction = Action 3309590Sandreas@sandberg.pp.se main['CCCOMSTR'] = Transform("CC") 3319590Sandreas@sandberg.pp.se main['CXXCOMSTR'] = Transform("CXX") 3326654Snate@binkert.org main['ASCOMSTR'] = Transform("AS") 3336654Snate@binkert.org main['ARCOMSTR'] = Transform("AR", 0) 3345871Snate@binkert.org main['LINKCOMSTR'] = Transform("LINK", 0) 3356121Snate@binkert.org main['SHLINKCOMSTR'] = Transform("SHLINK", 0) 3368946Sandreas.hansson@arm.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 3379419Sandreas.hansson@arm.com main['M4COMSTR'] = Transform("M4") 3383940Ssaidi@eecs.umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 3393918Ssaidi@eecs.umich.edu main['SHCXXCOMSTR'] = Transform("SHCXX") 3403918Ssaidi@eecs.umich.eduExport('MakeAction') 3411858SN/A 3429556Sandreas.hansson@arm.com# Initialize the Link-Time Optimization (LTO) flags 3439556Sandreas.hansson@arm.commain['LTO_CCFLAGS'] = [] 3449556Sandreas.hansson@arm.commain['LTO_LDFLAGS'] = [] 3459556Sandreas.hansson@arm.com 34611294Sandreas.hansson@arm.com# According to the readme, tcmalloc works best if the compiler doesn't 34711294Sandreas.hansson@arm.com# assume that we're using the builtin malloc and friends. These flags 34811294Sandreas.hansson@arm.com# are compiler-specific, so we need to set them after we detect which 34911294Sandreas.hansson@arm.com# compiler we're using. 35010878Sandreas.hansson@arm.commain['TCMALLOC_CCFLAGS'] = [] 35110878Sandreas.hansson@arm.com 35211811Sbaz21@cam.ac.ukCXX_version = readCommand([main['CXX'],'--version'], exception=False) 35311811Sbaz21@cam.ac.ukCXX_V = readCommand([main['CXX'],'-V'], exception=False) 35411811Sbaz21@cam.ac.uk 35511982Sgabeblack@google.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 35611982Sgabeblack@google.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 35711982Sgabeblack@google.comif main['GCC'] + main['CLANG'] > 1: 35811982Sgabeblack@google.com print('Error: How can we have two at the same time?') 35911992Sgabeblack@google.com Exit(1) 36011982Sgabeblack@google.com 36111982Sgabeblack@google.com# Set up default C++ compiler flags 36212305Sgabeblack@google.comif main['GCC'] or main['CLANG']: 36312305Sgabeblack@google.com # As gcc and clang share many flags, do the common parts here 36412305Sgabeblack@google.com main.Append(CCFLAGS=['-pipe']) 36512305Sgabeblack@google.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 36612305Sgabeblack@google.com # Enable -Wall and -Wextra and then disable the few warnings that 36712305Sgabeblack@google.com # we consistently violate 36812305Sgabeblack@google.com main.Append(CCFLAGS=['-Wall', '-Wundef', '-Wextra', 3699556Sandreas.hansson@arm.com '-Wno-sign-compare', '-Wno-unused-parameter']) 3709556Sandreas.hansson@arm.com # We always compile using C++11 3719556Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-std=c++11']) 3729556Sandreas.hansson@arm.com if sys.platform.startswith('freebsd'): 3739556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-I/usr/local/include']) 3749556Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-I/usr/local/include']) 3759556Sandreas.hansson@arm.com 3769556Sandreas.hansson@arm.com main['FILTER_PSHLINKFLAGS'] = lambda x: str(x).replace(' -shared', '') 3779556Sandreas.hansson@arm.com main['PSHLINKFLAGS'] = main.subst('${FILTER_PSHLINKFLAGS(SHLINKFLAGS)}') 3789556Sandreas.hansson@arm.com if GetOption('gold_linker'): 3799556Sandreas.hansson@arm.com main.Append(LINKFLAGS='-fuse-ld=gold') 3809556Sandreas.hansson@arm.com main['PLINKFLAGS'] = main.subst('${LINKFLAGS}') 3819556Sandreas.hansson@arm.com shared_partial_flags = ['-r', '-nostdlib'] 3829556Sandreas.hansson@arm.com main.Append(PSHLINKFLAGS=shared_partial_flags) 3839556Sandreas.hansson@arm.com main.Append(PLINKFLAGS=shared_partial_flags) 3849556Sandreas.hansson@arm.com 3859556Sandreas.hansson@arm.com # Treat warnings as errors but white list some warnings that we 3869556Sandreas.hansson@arm.com # want to allow (e.g., deprecation warnings). 3879556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Werror', 3886121Snate@binkert.org '-Wno-error=deprecated-declarations', 38911500Sandreas.hansson@arm.com '-Wno-error=deprecated', 39010238Sandreas.hansson@arm.com ]) 39110878Sandreas.hansson@arm.comelse: 3929420Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 39311500Sandreas.hansson@arm.com print("Don't know what compiler options to use for your compiler.") 39411500Sandreas.hansson@arm.com print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 3959420Sandreas.hansson@arm.com print(termcap.Yellow + ' version:' + termcap.Normal, end = ' ') 3969420Sandreas.hansson@arm.com if not CXX_version: 3979420Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 3989420Sandreas.hansson@arm.com termcap.Normal) 3999420Sandreas.hansson@arm.com else: 40012063Sgabeblack@google.com print(CXX_version.replace('\n', '<nl>')) 40112063Sgabeblack@google.com print(" If you're trying to use a compiler other than GCC") 40212063Sgabeblack@google.com print(" or clang, there appears to be something wrong with your") 40312063Sgabeblack@google.com print(" environment.") 40412063Sgabeblack@google.com print(" ") 40512063Sgabeblack@google.com print(" If you are trying to use a compiler other than those listed") 40612063Sgabeblack@google.com print(" above you will need to ease fix SConstruct and ") 40712063Sgabeblack@google.com print(" src/SConscript to support that compiler.") 40812063Sgabeblack@google.com Exit(1) 40912063Sgabeblack@google.com 41012063Sgabeblack@google.comif main['GCC']: 41112063Sgabeblack@google.com # Check for a supported version of gcc. >= 4.8 is chosen for its 41212063Sgabeblack@google.com # level of c++11 support. See 41312063Sgabeblack@google.com # http://gcc.gnu.org/projects/cxx0x.html for details. 41412063Sgabeblack@google.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 41512063Sgabeblack@google.com if compareVersions(gcc_version, "4.8") < 0: 41612063Sgabeblack@google.com print('Error: gcc version 4.8 or newer required.') 41712063Sgabeblack@google.com print(' Installed version: ', gcc_version) 41812063Sgabeblack@google.com Exit(1) 41912063Sgabeblack@google.com 42012063Sgabeblack@google.com main['GCC_VERSION'] = gcc_version 42112063Sgabeblack@google.com 42210264Sandreas.hansson@arm.com if compareVersions(gcc_version, '4.9') >= 0: 42310264Sandreas.hansson@arm.com # Incremental linking with LTO is currently broken in gcc versions 42410264Sandreas.hansson@arm.com # 4.9 and above. A version where everything works completely hasn't 42510264Sandreas.hansson@arm.com # yet been identified. 42611925Sgabeblack@google.com # 42711925Sgabeblack@google.com # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67548 42811500Sandreas.hansson@arm.com main['BROKEN_INCREMENTAL_LTO'] = True 42910264Sandreas.hansson@arm.com if compareVersions(gcc_version, '6.0') >= 0: 43011500Sandreas.hansson@arm.com # gcc versions 6.0 and greater accept an -flinker-output flag which 43111500Sandreas.hansson@arm.com # selects what type of output the linker should generate. This is 43211500Sandreas.hansson@arm.com # necessary for incremental lto to work, but is also broken in 43311500Sandreas.hansson@arm.com # current versions of gcc. It may not be necessary in future 43410866Sandreas.hansson@arm.com # versions. We add it here since it might be, and as a reminder that 43511500Sandreas.hansson@arm.com # it exists. It's excluded if lto is being forced. 43611500Sandreas.hansson@arm.com # 43711500Sandreas.hansson@arm.com # https://gcc.gnu.org/gcc-6/changes.html 43811500Sandreas.hansson@arm.com # https://gcc.gnu.org/ml/gcc-patches/2015-11/msg03161.html 43911500Sandreas.hansson@arm.com # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69866 44011500Sandreas.hansson@arm.com if not GetOption('force_lto'): 44111500Sandreas.hansson@arm.com main.Append(PSHLINKFLAGS='-flinker-output=rel') 44210264Sandreas.hansson@arm.com main.Append(PLINKFLAGS='-flinker-output=rel') 44310457Sandreas.hansson@arm.com 44410457Sandreas.hansson@arm.com # Make sure we warn if the user has requested to compile with the 44510457Sandreas.hansson@arm.com # Undefined Benahvior Sanitizer and this version of gcc does not 44610457Sandreas.hansson@arm.com # support it. 44710457Sandreas.hansson@arm.com if GetOption('with_ubsan') and \ 44810457Sandreas.hansson@arm.com compareVersions(gcc_version, '4.9') < 0: 44910457Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 45010457Sandreas.hansson@arm.com 'Warning: UBSan is only supported using gcc 4.9 and later.' + 45110457Sandreas.hansson@arm.com termcap.Normal) 45212063Sgabeblack@google.com 45312063Sgabeblack@google.com disable_lto = GetOption('no_lto') 45412063Sgabeblack@google.com if not disable_lto and main.get('BROKEN_INCREMENTAL_LTO', False) and \ 45512063Sgabeblack@google.com not GetOption('force_lto'): 45612063Sgabeblack@google.com print(termcap.Yellow + termcap.Bold + 45712063Sgabeblack@google.com 'Warning: Your compiler doesn\'t support incremental linking' + 45812063Sgabeblack@google.com ' and lto at the same time, so lto is being disabled. To force' + 45912063Sgabeblack@google.com ' lto on anyway, use the --force-lto option. That will disable' + 46012063Sgabeblack@google.com ' partial linking.' + 46112063Sgabeblack@google.com termcap.Normal) 46212063Sgabeblack@google.com disable_lto = True 46310238Sandreas.hansson@arm.com 46410238Sandreas.hansson@arm.com # Add the appropriate Link-Time Optimization (LTO) flags 46510238Sandreas.hansson@arm.com # unless LTO is explicitly turned off. Note that these flags 46612063Sgabeblack@google.com # are only used by the fast target. 46710238Sandreas.hansson@arm.com if not disable_lto: 46810238Sandreas.hansson@arm.com # Pass the LTO flag when compiling to produce GIMPLE 46910416Sandreas.hansson@arm.com # output, we merely create the flags here and only append 47010238Sandreas.hansson@arm.com # them later 4719227Sandreas.hansson@arm.com main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 47210238Sandreas.hansson@arm.com 47310416Sandreas.hansson@arm.com # Use the same amount of jobs for LTO as we are running 47410416Sandreas.hansson@arm.com # scons with 4759227Sandreas.hansson@arm.com main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 4769590Sandreas@sandberg.pp.se 4779590Sandreas@sandberg.pp.se main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 4789590Sandreas@sandberg.pp.se '-fno-builtin-realloc', '-fno-builtin-free']) 47911497SMatteo.Andreozzi@arm.com 48011497SMatteo.Andreozzi@arm.com # The address sanitizer is available for gcc >= 4.8 48111497SMatteo.Andreozzi@arm.com if GetOption('with_asan'): 48211497SMatteo.Andreozzi@arm.com if GetOption('with_ubsan') and \ 48312304Sgabeblack@google.com compareVersions(main['GCC_VERSION'], '4.9') >= 0: 48412304Sgabeblack@google.com main.Append(CCFLAGS=['-fsanitize=address,undefined', 48512304Sgabeblack@google.com '-fno-omit-frame-pointer'], 48612304Sgabeblack@google.com LINKFLAGS='-fsanitize=address,undefined') 48712304Sgabeblack@google.com else: 48812304Sgabeblack@google.com main.Append(CCFLAGS=['-fsanitize=address', 48912304Sgabeblack@google.com '-fno-omit-frame-pointer'], 49012304Sgabeblack@google.com LINKFLAGS='-fsanitize=address') 49112304Sgabeblack@google.com # Only gcc >= 4.9 supports UBSan, so check both the version 49212304Sgabeblack@google.com # and the command-line option before adding the compiler and 49312304Sgabeblack@google.com # linker flags. 49412304Sgabeblack@google.com elif GetOption('with_ubsan') and \ 49512304Sgabeblack@google.com compareVersions(main['GCC_VERSION'], '4.9') >= 0: 49612304Sgabeblack@google.com main.Append(CCFLAGS='-fsanitize=undefined') 49712304Sgabeblack@google.com main.Append(LINKFLAGS='-fsanitize=undefined') 49812304Sgabeblack@google.com 49912304Sgabeblack@google.comelif main['CLANG']: 50012304Sgabeblack@google.com # Check for a supported version of clang, >= 3.1 is needed to 50112304Sgabeblack@google.com # support similar features as gcc 4.8. See 5028737Skoansin.tan@gmail.com # http://clang.llvm.org/cxx_status.html for details 50310878Sandreas.hansson@arm.com clang_version_re = re.compile(".* version (\d+\.\d+)") 50411500Sandreas.hansson@arm.com clang_version_match = clang_version_re.search(CXX_version) 5059420Sandreas.hansson@arm.com if (clang_version_match): 5068737Skoansin.tan@gmail.com clang_version = clang_version_match.groups()[0] 50710106SMitch.Hayenga@arm.com if compareVersions(clang_version, "3.1") < 0: 5088737Skoansin.tan@gmail.com print('Error: clang version 3.1 or newer required.') 5098737Skoansin.tan@gmail.com print(' Installed version:', clang_version) 51010878Sandreas.hansson@arm.com Exit(1) 51110878Sandreas.hansson@arm.com else: 5128737Skoansin.tan@gmail.com print('Error: Unable to determine clang version.') 5138737Skoansin.tan@gmail.com Exit(1) 5148737Skoansin.tan@gmail.com 5158737Skoansin.tan@gmail.com # clang has a few additional warnings that we disable, extraneous 5168737Skoansin.tan@gmail.com # parantheses are allowed due to Ruby's printing of the AST, 5178737Skoansin.tan@gmail.com # finally self assignments are allowed as the generated CPU code 51811294Sandreas.hansson@arm.com # is relying on this 5199556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-parentheses', 5209556Sandreas.hansson@arm.com '-Wno-self-assign', 5219556Sandreas.hansson@arm.com # Some versions of libstdc++ (4.8?) seem to 52211294Sandreas.hansson@arm.com # use struct hash and class hash 52310278SAndreas.Sandberg@ARM.com # interchangeably. 52410278SAndreas.Sandberg@ARM.com '-Wno-mismatched-tags', 52510278SAndreas.Sandberg@ARM.com ]) 52610278SAndreas.Sandberg@ARM.com 52710278SAndreas.Sandberg@ARM.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 52810278SAndreas.Sandberg@ARM.com 5299556Sandreas.hansson@arm.com # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 5309590Sandreas@sandberg.pp.se # opposed to libstdc++, as the later is dated. 5319590Sandreas@sandberg.pp.se if sys.platform == "darwin": 5329420Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-stdlib=libc++']) 5339846Sandreas.hansson@arm.com main.Append(LIBS=['c++']) 5349846Sandreas.hansson@arm.com 5359846Sandreas.hansson@arm.com # On FreeBSD we need libthr. 5369846Sandreas.hansson@arm.com if sys.platform.startswith('freebsd'): 5378946Sandreas.hansson@arm.com main.Append(LIBS=['thr']) 53811811Sbaz21@cam.ac.uk 53911811Sbaz21@cam.ac.uk # We require clang >= 3.1, so there is no need to check any 54011811Sbaz21@cam.ac.uk # versions here. 54111811Sbaz21@cam.ac.uk if GetOption('with_ubsan'): 54212304Sgabeblack@google.com if GetOption('with_asan'): 54312304Sgabeblack@google.com main.Append(CCFLAGS=['-fsanitize=address,undefined', 54412304Sgabeblack@google.com '-fno-omit-frame-pointer'], 54512304Sgabeblack@google.com LINKFLAGS='-fsanitize=address,undefined') 54612304Sgabeblack@google.com else: 54712304Sgabeblack@google.com main.Append(CCFLAGS='-fsanitize=undefined', 54812304Sgabeblack@google.com LINKFLAGS='-fsanitize=undefined') 54912304Sgabeblack@google.com 55012304Sgabeblack@google.com elif GetOption('with_asan'): 55112304Sgabeblack@google.com main.Append(CCFLAGS=['-fsanitize=address', 55212304Sgabeblack@google.com '-fno-omit-frame-pointer'], 55312304Sgabeblack@google.com LINKFLAGS='-fsanitize=address') 55412304Sgabeblack@google.com 55512304Sgabeblack@google.comelse: 55612304Sgabeblack@google.com print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 55712304Sgabeblack@google.com print("Don't know what compiler options to use for your compiler.") 5583918Ssaidi@eecs.umich.edu print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 5599068SAli.Saidi@ARM.com print(termcap.Yellow + ' version:' + termcap.Normal, end=' ') 5609068SAli.Saidi@ARM.com if not CXX_version: 5619068SAli.Saidi@ARM.com print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 5629068SAli.Saidi@ARM.com termcap.Normal) 5639068SAli.Saidi@ARM.com else: 5649068SAli.Saidi@ARM.com print(CXX_version.replace('\n', '<nl>')) 5659068SAli.Saidi@ARM.com print(" If you're trying to use a compiler other than GCC") 5669068SAli.Saidi@ARM.com print(" or clang, there appears to be something wrong with your") 5679068SAli.Saidi@ARM.com print(" environment.") 5689419Sandreas.hansson@arm.com print(" ") 5699068SAli.Saidi@ARM.com print(" If you are trying to use a compiler other than those listed") 5709068SAli.Saidi@ARM.com print(" above you will need to ease fix SConstruct and ") 5719068SAli.Saidi@ARM.com print(" src/SConscript to support that compiler.") 5729068SAli.Saidi@ARM.com Exit(1) 5739068SAli.Saidi@ARM.com 5749068SAli.Saidi@ARM.com# Set up common yacc/bison flags (needed for Ruby) 5753918Ssaidi@eecs.umich.edumain['YACCFLAGS'] = '-d' 5763918Ssaidi@eecs.umich.edumain['YACCHXXFILESUFFIX'] = '.hh' 5776157Snate@binkert.org 5786157Snate@binkert.org# Do this after we save setting back, or else we'll tack on an 5796157Snate@binkert.org# extra 'qdo' every time we run scons. 5806157Snate@binkert.orgif main['BATCH']: 5815397Ssaidi@eecs.umich.edu main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5825397Ssaidi@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5836121Snate@binkert.org main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5846121Snate@binkert.org main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5856121Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5866121Snate@binkert.org 5876121Snate@binkert.orgif sys.platform == 'cygwin': 5886121Snate@binkert.org # cygwin has some header file issues... 5895397Ssaidi@eecs.umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 5901851SN/A 5911851SN/A# Check for the protobuf compiler 5927739Sgblack@eecs.umich.eduprotoc_version = readCommand([main['PROTOC'], '--version'], 593955SN/A exception='').split() 5949396Sandreas.hansson@arm.com 5959396Sandreas.hansson@arm.com# First two words should be "libprotoc x.y.z" 5969396Sandreas.hansson@arm.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 5979396Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 5989396Sandreas.hansson@arm.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + 5999396Sandreas.hansson@arm.com ' Please install protobuf-compiler for tracing support.' + 6009396Sandreas.hansson@arm.com termcap.Normal) 6019396Sandreas.hansson@arm.com main['PROTOC'] = False 6029396Sandreas.hansson@arm.comelse: 6039396Sandreas.hansson@arm.com # Based on the availability of the compress stream wrappers, 6049396Sandreas.hansson@arm.com # require 2.1.0 6059396Sandreas.hansson@arm.com min_protoc_version = '2.1.0' 6069396Sandreas.hansson@arm.com if compareVersions(protoc_version[1], min_protoc_version) < 0: 6079396Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 6089396Sandreas.hansson@arm.com 'Warning: protoc version', min_protoc_version, 6099396Sandreas.hansson@arm.com 'or newer required.\n' + 6109477Sandreas.hansson@arm.com ' Installed version:', protoc_version[1], 6119477Sandreas.hansson@arm.com termcap.Normal) 6129477Sandreas.hansson@arm.com main['PROTOC'] = False 6139477Sandreas.hansson@arm.com else: 6149477Sandreas.hansson@arm.com # Attempt to determine the appropriate include path and 6159477Sandreas.hansson@arm.com # library path using pkg-config, that means we also need to 6169477Sandreas.hansson@arm.com # check for pkg-config. Note that it is possible to use 6179477Sandreas.hansson@arm.com # protobuf without the involvement of pkg-config. Later on we 6189477Sandreas.hansson@arm.com # check go a library config check and at that point the test 6199477Sandreas.hansson@arm.com # will fail if libprotobuf cannot be found. 6209477Sandreas.hansson@arm.com if readCommand(['pkg-config', '--version'], exception=''): 6219477Sandreas.hansson@arm.com try: 6229477Sandreas.hansson@arm.com # Attempt to establish what linking flags to add for protobuf 6239477Sandreas.hansson@arm.com # using pkg-config 6249477Sandreas.hansson@arm.com main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 6259477Sandreas.hansson@arm.com except: 6269477Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 6279477Sandreas.hansson@arm.com 'Warning: pkg-config could not get protobuf flags.' + 6289477Sandreas.hansson@arm.com termcap.Normal) 6299477Sandreas.hansson@arm.com 6309477Sandreas.hansson@arm.com 6319477Sandreas.hansson@arm.com# Check for 'timeout' from GNU coreutils. If present, regressions will 6329396Sandreas.hansson@arm.com# be run with a time limit. We require version 8.13 since we rely on 6332667Sstever@eecs.umich.edu# support for the '--foreground' option. 63410710Sandreas.hansson@arm.comif sys.platform.startswith('freebsd'): 63510710Sandreas.hansson@arm.com timeout_lines = readCommand(['gtimeout', '--version'], 63610710Sandreas.hansson@arm.com exception='').splitlines() 63711811Sbaz21@cam.ac.ukelse: 63811811Sbaz21@cam.ac.uk timeout_lines = readCommand(['timeout', '--version'], 63911811Sbaz21@cam.ac.uk exception='').splitlines() 64011811Sbaz21@cam.ac.uk# Get the first line and tokenize it 64111811Sbaz21@cam.ac.uktimeout_version = timeout_lines[0].split() if timeout_lines else [] 64211811Sbaz21@cam.ac.ukmain['TIMEOUT'] = timeout_version and \ 64310710Sandreas.hansson@arm.com compareVersions(timeout_version[-1], '8.13') >= 0 64410710Sandreas.hansson@arm.com 64510710Sandreas.hansson@arm.com# Add a custom Check function to test for structure members. 64610710Sandreas.hansson@arm.comdef CheckMember(context, include, decl, member, include_quotes="<>"): 64710384SCurtis.Dunham@arm.com context.Message("Checking for member %s in %s..." % 6489986Sandreas@sandberg.pp.se (member, decl)) 6499986Sandreas@sandberg.pp.se text = """ 6509986Sandreas@sandberg.pp.se#include %(header)s 6519986Sandreas@sandberg.pp.seint main(){ 6529986Sandreas@sandberg.pp.se %(decl)s test; 6539986Sandreas@sandberg.pp.se (void)test.%(member)s; 6549986Sandreas@sandberg.pp.se return 0; 6559986Sandreas@sandberg.pp.se}; 6569986Sandreas@sandberg.pp.se""" % { "header" : include_quotes[0] + include + include_quotes[1], 6579986Sandreas@sandberg.pp.se "decl" : decl, 6589986Sandreas@sandberg.pp.se "member" : member, 6599986Sandreas@sandberg.pp.se } 6609986Sandreas@sandberg.pp.se 6619986Sandreas@sandberg.pp.se ret = context.TryCompile(text, extension=".cc") 6629986Sandreas@sandberg.pp.se context.Result(ret) 6639986Sandreas@sandberg.pp.se return ret 6649986Sandreas@sandberg.pp.se 6659986Sandreas@sandberg.pp.se# Platform-specific configuration. Note again that we assume that all 6669986Sandreas@sandberg.pp.se# builds under a given build root run on the same host platform. 6679986Sandreas@sandberg.pp.seconf = Configure(main, 6682638Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 6692638Sstever@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 6706121Snate@binkert.org custom_tests = { 6713716Sstever@eecs.umich.edu 'CheckMember' : CheckMember, 6725522Snate@binkert.org }) 6739986Sandreas@sandberg.pp.se 6749986Sandreas@sandberg.pp.se# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6759986Sandreas@sandberg.pp.setry: 6765522Snate@binkert.org import platform 6775227Ssaidi@eecs.umich.edu uname = platform.uname() 6785227Ssaidi@eecs.umich.edu if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6795227Ssaidi@eecs.umich.edu if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6805227Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-arch', 'x86_64']) 6816654Snate@binkert.org main.Append(CFLAGS=['-arch', 'x86_64']) 6826654Snate@binkert.org main.Append(LINKFLAGS=['-arch', 'x86_64']) 6837769SAli.Saidi@ARM.com main.Append(ASFLAGS=['-arch', 'x86_64']) 6847769SAli.Saidi@ARM.comexcept: 6857769SAli.Saidi@ARM.com pass 6867769SAli.Saidi@ARM.com 6875227Ssaidi@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 6885227Ssaidi@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 6895227Ssaidi@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 6905204Sstever@gmail.com# breaking all our configuration checks. We replace it with our own 6915204Sstever@gmail.com# more optimistic null object that returns True instead. 6925204Sstever@gmail.comif not conf: 6935204Sstever@gmail.com def NullCheck(*args, **kwargs): 6945204Sstever@gmail.com return True 6955204Sstever@gmail.com 6965204Sstever@gmail.com class NullConf: 6975204Sstever@gmail.com def __init__(self, env): 6985204Sstever@gmail.com self.env = env 6995204Sstever@gmail.com def Finish(self): 7005204Sstever@gmail.com return self.env 7015204Sstever@gmail.com def __getattr__(self, mname): 7025204Sstever@gmail.com return NullCheck 7035204Sstever@gmail.com 7045204Sstever@gmail.com conf = NullConf(main) 7055204Sstever@gmail.com 7065204Sstever@gmail.com# Cache build files in the supplied directory. 7076121Snate@binkert.orgif main['M5_BUILD_CACHE']: 7085204Sstever@gmail.com print('Using build cache located at', main['M5_BUILD_CACHE']) 7097727SAli.Saidi@ARM.com CacheDir(main['M5_BUILD_CACHE']) 7107727SAli.Saidi@ARM.com 7117727SAli.Saidi@ARM.commain['USE_PYTHON'] = not GetOption('without_python') 7127727SAli.Saidi@ARM.comif main['USE_PYTHON']: 7137727SAli.Saidi@ARM.com # Find Python include and library directories for embedding the 71411988Sandreas.sandberg@arm.com # interpreter. We rely on python-config to resolve the appropriate 71511988Sandreas.sandberg@arm.com # includes and linker flags. ParseConfig does not seem to understand 71610453SAndrew.Bardsley@arm.com # the more exotic linker flags such as -Xlinker and -export-dynamic so 71710453SAndrew.Bardsley@arm.com # we add them explicitly below. If you want to link in an alternate 71810453SAndrew.Bardsley@arm.com # version of python, see above for instructions on how to invoke 71910453SAndrew.Bardsley@arm.com # scons with the appropriate PATH set. 72010453SAndrew.Bardsley@arm.com 72110453SAndrew.Bardsley@arm.com python_config = find_first_prog(main['PYTHON_CONFIG']) 72210453SAndrew.Bardsley@arm.com if python_config is None: 72310453SAndrew.Bardsley@arm.com print("Error: can't find a suitable python-config, tried %s" % \ 72410453SAndrew.Bardsley@arm.com main['PYTHON_CONFIG']) 72510453SAndrew.Bardsley@arm.com Exit(1) 72610160Sandreas.hansson@arm.com 72710453SAndrew.Bardsley@arm.com print("Info: Using Python config: %s" % (python_config, )) 72810453SAndrew.Bardsley@arm.com py_includes = readCommand([python_config, '--includes'], 72910453SAndrew.Bardsley@arm.com exception='').split() 73010453SAndrew.Bardsley@arm.com py_includes = filter(lambda s: match(r'.*\/include\/.*',s), py_includes) 73110453SAndrew.Bardsley@arm.com # Strip the -I from the include folders before adding them to the 73210453SAndrew.Bardsley@arm.com # CPPPATH 73310453SAndrew.Bardsley@arm.com py_includes = map(lambda s: s[2:] if s.startswith('-I') else s, py_includes) 73410453SAndrew.Bardsley@arm.com main.Append(CPPPATH=py_includes) 7359812Sandreas.hansson@arm.com 73610453SAndrew.Bardsley@arm.com # Read the linker flags and split them into libraries and other link 73710453SAndrew.Bardsley@arm.com # flags. The libraries are added later through the call the CheckLib. 73810453SAndrew.Bardsley@arm.com py_ld_flags = readCommand([python_config, '--ldflags'], 73910453SAndrew.Bardsley@arm.com exception='').split() 74010453SAndrew.Bardsley@arm.com py_libs = [] 74110453SAndrew.Bardsley@arm.com for lib in py_ld_flags: 74210453SAndrew.Bardsley@arm.com if not lib.startswith('-l'): 74310453SAndrew.Bardsley@arm.com main.Append(LINKFLAGS=[lib]) 74410453SAndrew.Bardsley@arm.com else: 74510453SAndrew.Bardsley@arm.com lib = lib[2:] 74610453SAndrew.Bardsley@arm.com if lib not in py_libs: 74710453SAndrew.Bardsley@arm.com py_libs.append(lib) 7487727SAli.Saidi@ARM.com 74910453SAndrew.Bardsley@arm.com # verify that this stuff works 75010453SAndrew.Bardsley@arm.com if not conf.CheckHeader('Python.h', '<>'): 75110453SAndrew.Bardsley@arm.com print("Error: Check failed for Python.h header in", py_includes) 75210453SAndrew.Bardsley@arm.com print("Two possible reasons:") 75310453SAndrew.Bardsley@arm.com print("1. Python headers are not installed (You can install the " 7543118Sstever@eecs.umich.edu "package python-dev on Ubuntu and RedHat)") 75510453SAndrew.Bardsley@arm.com print("2. SCons is using a wrong C compiler. This can happen if " 75610453SAndrew.Bardsley@arm.com "CC has the wrong value.") 75710453SAndrew.Bardsley@arm.com print("CC = %s" % main['CC']) 75810453SAndrew.Bardsley@arm.com Exit(1) 7593118Sstever@eecs.umich.edu 7603483Ssaidi@eecs.umich.edu for lib in py_libs: 7613494Ssaidi@eecs.umich.edu if not conf.CheckLib(lib): 7623494Ssaidi@eecs.umich.edu print("Error: can't find library %s required by python" % lib) 7633483Ssaidi@eecs.umich.edu Exit(1) 7643483Ssaidi@eecs.umich.edu 7653483Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 7663053Sstever@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7673053Sstever@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7683918Ssaidi@eecs.umich.edu print("Can't find library with socket calls (e.g. accept())") 7693053Sstever@eecs.umich.edu Exit(1) 7703053Sstever@eecs.umich.edu 7713053Sstever@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 7723053Sstever@eecs.umich.edu# added to the LIBS environment variable. 7733053Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7749396Sandreas.hansson@arm.com print('Error: did not find needed zlib compression library ' 7759396Sandreas.hansson@arm.com 'and/or zlib.h header file.') 7769396Sandreas.hansson@arm.com print(' Please install zlib and try again.') 7779396Sandreas.hansson@arm.com Exit(1) 7789396Sandreas.hansson@arm.com 7799396Sandreas.hansson@arm.com# If we have the protobuf compiler, also make sure we have the 7809396Sandreas.hansson@arm.com# development libraries. If the check passes, libprotobuf will be 7819396Sandreas.hansson@arm.com# automatically added to the LIBS environment variable. After 7829396Sandreas.hansson@arm.com# this, we can use the HAVE_PROTOBUF flag to determine if we have 7839477Sandreas.hansson@arm.com# got both protoc and libprotobuf available. 7849396Sandreas.hansson@arm.commain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 7859477Sandreas.hansson@arm.com conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 7869477Sandreas.hansson@arm.com 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 7879477Sandreas.hansson@arm.com 7889477Sandreas.hansson@arm.com# Valgrind gets much less confused if you tell it when you're using 7899396Sandreas.hansson@arm.com# alternative stacks. 7907840Snate@binkert.orgmain['HAVE_VALGRIND'] = conf.CheckCHeader('valgrind/valgrind.h') 7917865Sgblack@eecs.umich.edu 7927865Sgblack@eecs.umich.edu# If we have the compiler but not the library, print another warning. 7937865Sgblack@eecs.umich.eduif main['PROTOC'] and not main['HAVE_PROTOBUF']: 7947865Sgblack@eecs.umich.edu print(termcap.Yellow + termcap.Bold + 7957865Sgblack@eecs.umich.edu 'Warning: did not find protocol buffer library and/or headers.\n' + 7967840Snate@binkert.org ' Please install libprotobuf-dev for tracing support.' + 7979900Sandreas@sandberg.pp.se termcap.Normal) 7989900Sandreas@sandberg.pp.se 7999900Sandreas@sandberg.pp.se# Check for librt. 8009900Sandreas@sandberg.pp.sehave_posix_clock = \ 80110456SCurtis.Dunham@arm.com conf.CheckLibWithHeader(None, 'time.h', 'C', 80210456SCurtis.Dunham@arm.com 'clock_nanosleep(0,0,NULL,NULL);') or \ 80310456SCurtis.Dunham@arm.com conf.CheckLibWithHeader('rt', 'time.h', 'C', 80410456SCurtis.Dunham@arm.com 'clock_nanosleep(0,0,NULL,NULL);') 80510456SCurtis.Dunham@arm.com 80610456SCurtis.Dunham@arm.comhave_posix_timers = \ 80710456SCurtis.Dunham@arm.com conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', 80810456SCurtis.Dunham@arm.com 'timer_create(CLOCK_MONOTONIC, NULL, NULL);') 80910456SCurtis.Dunham@arm.com 81010456SCurtis.Dunham@arm.comif not GetOption('without_tcmalloc'): 8119045SAli.Saidi@ARM.com if conf.CheckLib('tcmalloc'): 81211235Sandreas.sandberg@arm.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 81311235Sandreas.sandberg@arm.com elif conf.CheckLib('tcmalloc_minimal'): 81411235Sandreas.sandberg@arm.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 81511235Sandreas.sandberg@arm.com else: 81611235Sandreas.sandberg@arm.com print(termcap.Yellow + termcap.Bold + 81712485Sjang.hanhwi@gmail.com "You can get a 12% performance improvement by " 81812485Sjang.hanhwi@gmail.com "installing tcmalloc (libgoogle-perftools-dev package " 81912485Sjang.hanhwi@gmail.com "on Ubuntu or RedHat)." + termcap.Normal) 82011235Sandreas.sandberg@arm.com 82111811Sbaz21@cam.ac.uk 82212485Sjang.hanhwi@gmail.com# Detect back trace implementations. The last implementation in the 82311811Sbaz21@cam.ac.uk# list will be used by default. 82411811Sbaz21@cam.ac.ukbacktrace_impls = [ "none" ] 82511811Sbaz21@cam.ac.uk 82611235Sandreas.sandberg@arm.combacktrace_checker = 'char temp;' + \ 82711235Sandreas.sandberg@arm.com ' backtrace_symbols_fd((void*)&temp, 0, 0);' 82811235Sandreas.sandberg@arm.comif conf.CheckLibWithHeader(None, 'execinfo.h', 'C', backtrace_checker): 82911235Sandreas.sandberg@arm.com backtrace_impls.append("glibc") 83011235Sandreas.sandberg@arm.comelif conf.CheckLibWithHeader('execinfo', 'execinfo.h', 'C', 83111235Sandreas.sandberg@arm.com backtrace_checker): 83211235Sandreas.sandberg@arm.com # NetBSD and FreeBSD need libexecinfo. 8337840Snate@binkert.org backtrace_impls.append("glibc") 8347840Snate@binkert.org main.Append(LIBS=['execinfo']) 8357840Snate@binkert.org 8361858SN/Aif backtrace_impls[-1] == "none": 8371858SN/A default_backtrace_impl = "none" 8381858SN/A print(termcap.Yellow + termcap.Bold + 8391858SN/A "No suitable back trace implementation found." + 8401858SN/A termcap.Normal) 8411858SN/A 84212230Sgiacomo.travaglini@arm.comif not have_posix_clock: 84312230Sgiacomo.travaglini@arm.com print("Can't find library for POSIX clocks.") 84412230Sgiacomo.travaglini@arm.com 84512230Sgiacomo.travaglini@arm.com# Check for <fenv.h> (C99 FP environment control) 84612230Sgiacomo.travaglini@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 84712230Sgiacomo.travaglini@arm.comif not have_fenv: 84812230Sgiacomo.travaglini@arm.com print("Warning: Header file <fenv.h> not found.") 84912230Sgiacomo.travaglini@arm.com print(" This host has no IEEE FP rounding mode control.") 8509903Sandreas.hansson@arm.com 8519903Sandreas.hansson@arm.com# Check for <png.h> (libpng library needed if wanting to dump 8529903Sandreas.hansson@arm.com# frame buffer image in png format) 8539903Sandreas.hansson@arm.comhave_png = conf.CheckHeader('png.h', '<>') 85410841Sandreas.sandberg@arm.comif not have_png: 8559651SAndreas.Sandberg@ARM.com print("Warning: Header file <png.h> not found.") 8569903Sandreas.hansson@arm.com print(" This host has no libpng library.") 8579651SAndreas.Sandberg@ARM.com print(" Disabling support for PNG framebuffers.") 8589651SAndreas.Sandberg@ARM.com 85912056Sgabeblack@google.com# Check if we should enable KVM-based hardware virtualization. The API 86012056Sgabeblack@google.com# we rely on exists since version 2.6.36 of the kernel, but somehow 86112056Sgabeblack@google.com# the KVM_API_VERSION does not reflect the change. We test for one of 86212056Sgabeblack@google.com# the types as a fall back. 86312056Sgabeblack@google.comhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 86410841Sandreas.sandberg@arm.comif not have_kvm: 86510841Sandreas.sandberg@arm.com print("Info: Compatible header file <linux/kvm.h> not found, " 86610841Sandreas.sandberg@arm.com "disabling KVM support.") 86710841Sandreas.sandberg@arm.com 86810841Sandreas.sandberg@arm.com# Check if the TUN/TAP driver is available. 86910841Sandreas.sandberg@arm.comhave_tuntap = conf.CheckHeader('linux/if_tun.h', '<>') 8709651SAndreas.Sandberg@ARM.comif not have_tuntap: 8719651SAndreas.Sandberg@ARM.com print("Info: Compatible header file <linux/if_tun.h> not found.") 8729651SAndreas.Sandberg@ARM.com 8739651SAndreas.Sandberg@ARM.com# x86 needs support for xsave. We test for the structure here since we 8749651SAndreas.Sandberg@ARM.com# won't be able to run new tests by the time we know which ISA we're 8759651SAndreas.Sandberg@ARM.com# targeting. 8769651SAndreas.Sandberg@ARM.comhave_kvm_xsave = conf.CheckTypeSize('struct kvm_xsave', 8779651SAndreas.Sandberg@ARM.com '#include <linux/kvm.h>') != 0 8789651SAndreas.Sandberg@ARM.com 87910841Sandreas.sandberg@arm.com# Check if the requested target ISA is compatible with the host 88010841Sandreas.sandberg@arm.comdef is_isa_kvm_compatible(isa): 88110841Sandreas.sandberg@arm.com try: 88210841Sandreas.sandberg@arm.com import platform 88310841Sandreas.sandberg@arm.com host_isa = platform.machine() 88410841Sandreas.sandberg@arm.com except: 88510860Sandreas.sandberg@arm.com print("Warning: Failed to determine host ISA.") 88610841Sandreas.sandberg@arm.com return False 88710841Sandreas.sandberg@arm.com 88810841Sandreas.sandberg@arm.com if not have_posix_timers: 88910841Sandreas.sandberg@arm.com print("Warning: Can not enable KVM, host seems to lack support " 89010841Sandreas.sandberg@arm.com "for POSIX timers") 89110841Sandreas.sandberg@arm.com return False 89210841Sandreas.sandberg@arm.com 89310841Sandreas.sandberg@arm.com if isa == "arm": 89410841Sandreas.sandberg@arm.com return host_isa in ( "armv7l", "aarch64" ) 89510841Sandreas.sandberg@arm.com elif isa == "x86": 89610841Sandreas.sandberg@arm.com if host_isa != "x86_64": 8979651SAndreas.Sandberg@ARM.com return False 8989651SAndreas.Sandberg@ARM.com 8999986Sandreas@sandberg.pp.se if not have_kvm_xsave: 9009986Sandreas@sandberg.pp.se print("KVM on x86 requires xsave support in kernel headers.") 9019986Sandreas@sandberg.pp.se return False 9029986Sandreas@sandberg.pp.se 9039986Sandreas@sandberg.pp.se return True 9049986Sandreas@sandberg.pp.se else: 9055863Snate@binkert.org return False 9065863Snate@binkert.org 9075863Snate@binkert.org 9085863Snate@binkert.org# Check if the exclude_host attribute is available. We want this to 9096121Snate@binkert.org# get accurate instruction counts in KVM. 9101858SN/Amain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember( 9115863Snate@binkert.org 'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host') 9125863Snate@binkert.org 9135863Snate@binkert.org 9145863Snate@binkert.org###################################################################### 9155863Snate@binkert.org# 9162139SN/A# Finish the configuration 9174202Sbinkertn@umich.edu# 91811308Santhony.gutierrez@amd.commain = conf.Finish() 9194202Sbinkertn@umich.edu 92011308Santhony.gutierrez@amd.com###################################################################### 9212139SN/A# 9226994Snate@binkert.org# Collect all non-global variables 9236994Snate@binkert.org# 9246994Snate@binkert.org 9256994Snate@binkert.org# Define the universe of supported ISAs 9266994Snate@binkert.orgall_isa_list = [ ] 9276994Snate@binkert.orgall_gpu_isa_list = [ ] 9286994Snate@binkert.orgExport('all_isa_list') 9296994Snate@binkert.orgExport('all_gpu_isa_list') 93010319SAndreas.Sandberg@ARM.com 9316994Snate@binkert.orgclass CpuModel(object): 9326994Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 9336994Snate@binkert.org know about a particular CPU model.''' 9346994Snate@binkert.org 9356994Snate@binkert.org # Dict of available CPU model objects. Accessible as CpuModel.dict. 9366994Snate@binkert.org dict = {} 9376994Snate@binkert.org 9386994Snate@binkert.org # Constructor. Automatically adds models to CpuModel.dict. 9396994Snate@binkert.org def __init__(self, name, default=False): 9406994Snate@binkert.org self.name = name # name of model 9416994Snate@binkert.org 9422155SN/A # This cpu is enabled by default 9435863Snate@binkert.org self.default = default 9441869SN/A 9451869SN/A # Add self to dict 9465863Snate@binkert.org if name in CpuModel.dict: 9475863Snate@binkert.org raise AttributeError, "CpuModel '%s' already registered" % name 9484202Sbinkertn@umich.edu CpuModel.dict[name] = self 9496108Snate@binkert.org 9506108Snate@binkert.orgExport('CpuModel') 9516108Snate@binkert.org 9526108Snate@binkert.org# Sticky variables get saved in the variables file so they persist from 9539219Spower.jg@gmail.com# one invocation to the next (unless overridden, in which case the new 9549219Spower.jg@gmail.com# value becomes sticky). 9559219Spower.jg@gmail.comsticky_vars = Variables(args=ARGUMENTS) 9569219Spower.jg@gmail.comExport('sticky_vars') 9579219Spower.jg@gmail.com 9589219Spower.jg@gmail.com# Sticky variables that should be exported 9599219Spower.jg@gmail.comexport_vars = [] 9609219Spower.jg@gmail.comExport('export_vars') 9614202Sbinkertn@umich.edu 9625863Snate@binkert.org# For Ruby 96310135SCurtis.Dunham@arm.comall_protocols = [] 9648474Sgblack@eecs.umich.eduExport('all_protocols') 9655742Snate@binkert.orgprotocol_dirs = [] 9668268Ssteve.reinhardt@amd.comExport('protocol_dirs') 9678268Ssteve.reinhardt@amd.comslicc_includes = [] 9688268Ssteve.reinhardt@amd.comExport('slicc_includes') 9695742Snate@binkert.org 9705341Sstever@gmail.com# Walk the tree and execute all SConsopts scripts that wil add to the 9718474Sgblack@eecs.umich.edu# above variables 9728474Sgblack@eecs.umich.eduif GetOption('verbose'): 9735342Sstever@gmail.com print("Reading SConsopts") 9744202Sbinkertn@umich.edufor bdir in [ base_dir ] + extras_dir_list: 9754202Sbinkertn@umich.edu if not isdir(bdir): 97611308Santhony.gutierrez@amd.com print("Error: directory '%s' does not exist" % bdir) 9774202Sbinkertn@umich.edu Exit(1) 9785863Snate@binkert.org for root, dirs, files in os.walk(bdir): 9795863Snate@binkert.org if 'SConsopts' in files: 98011308Santhony.gutierrez@amd.com if GetOption('verbose'): 9816994Snate@binkert.org print("Reading", joinpath(root, 'SConsopts')) 9826994Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 98310319SAndreas.Sandberg@ARM.com 9845863Snate@binkert.orgall_isa_list.sort() 9855863Snate@binkert.orgall_gpu_isa_list.sort() 9865863Snate@binkert.org 9875863Snate@binkert.orgsticky_vars.AddVariables( 9885863Snate@binkert.org EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 9895863Snate@binkert.org EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'hsail', all_gpu_isa_list), 9905863Snate@binkert.org ListVariable('CPU_MODELS', 'CPU models', 9915863Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 9927840Snate@binkert.org sorted(CpuModel.dict.keys())), 9935863Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 99412230Sgiacomo.travaglini@arm.com False), 99512230Sgiacomo.travaglini@arm.com BoolVariable('SS_COMPATIBLE_FP', 99612230Sgiacomo.travaglini@arm.com 'Make floating-point results compatible with SimpleScalar', 99712230Sgiacomo.travaglini@arm.com False), 99812230Sgiacomo.travaglini@arm.com BoolVariable('USE_SSE2', 99912056Sgabeblack@google.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 100012056Sgabeblack@google.com False), 100112056Sgabeblack@google.com BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 100211308Santhony.gutierrez@amd.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 10039219Spower.jg@gmail.com BoolVariable('USE_PNG', 'Enable support for PNG images', have_png), 10049219Spower.jg@gmail.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', 100511235Sandreas.sandberg@arm.com False), 100611235Sandreas.sandberg@arm.com BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', 10071869SN/A have_kvm), 10081858SN/A BoolVariable('USE_TUNTAP', 10095863Snate@binkert.org 'Enable using a tap device to bridge to the host network', 101011308Santhony.gutierrez@amd.com have_tuntap), 101112061Sjason@lowepower.com BoolVariable('BUILD_GPU', 'Build the compute-GPU model', False), 101212230Sgiacomo.travaglini@arm.com EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 101312230Sgiacomo.travaglini@arm.com all_protocols), 10141858SN/A EnumVariable('BACKTRACE_IMPL', 'Post-mortem dump implementation', 1015955SN/A backtrace_impls[-1], backtrace_impls) 1016955SN/A ) 10171869SN/A 10181869SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript). 10191869SN/Aexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA', 10201869SN/A 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP', 10211869SN/A 'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_VALGRIND', 10225863Snate@binkert.org 'HAVE_PERF_ATTR_EXCLUDE_HOST', 'USE_PNG'] 10235863Snate@binkert.org 10245863Snate@binkert.org################################################### 10251869SN/A# 10265863Snate@binkert.org# Define a SCons builder for configuration flag headers. 10271869SN/A# 10285863Snate@binkert.org################################################### 10291869SN/A 10301869SN/A# This function generates a config header file that #defines the 10311869SN/A# variable symbol to the current variable setting (0 or 1). The source 10321869SN/A# operands are the name of the variable and a Value node containing the 10338483Sgblack@eecs.umich.edu# value of the variable. 10341869SN/Adef build_config_file(target, source, env): 10351869SN/A (variable, value) = [s.get_contents() for s in source] 10361869SN/A f = file(str(target[0]), 'w') 10371869SN/A print('#define', variable, value, file=f) 10385863Snate@binkert.org f.close() 10395863Snate@binkert.org return None 10401869SN/A 10415863Snate@binkert.org# Combine the two functions into a scons Action object. 10425863Snate@binkert.orgconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 10433356Sbinkertn@umich.edu 10443356Sbinkertn@umich.edu# The emitter munges the source & target node lists to reflect what 10453356Sbinkertn@umich.edu# we're really doing. 10463356Sbinkertn@umich.edudef config_emitter(target, source, env): 10473356Sbinkertn@umich.edu # extract variable name from Builder arg 10484781Snate@binkert.org variable = str(target[0]) 10495863Snate@binkert.org # True target is config header file 10505863Snate@binkert.org target = joinpath('config', variable.lower() + '.hh') 10511869SN/A val = env[variable] 10521869SN/A if isinstance(val, bool): 10531869SN/A # Force value to 0/1 10546121Snate@binkert.org val = int(val) 10551869SN/A elif isinstance(val, str): 105611982Sgabeblack@google.com val = '"' + val + '"' 105711982Sgabeblack@google.com 105811982Sgabeblack@google.com # Sources are variable name & value (packaged in SCons Value nodes) 105911982Sgabeblack@google.com return ([target], [Value(variable), Value(val)]) 106011982Sgabeblack@google.com 106111982Sgabeblack@google.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 106211982Sgabeblack@google.com 106311982Sgabeblack@google.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 106411982Sgabeblack@google.com 106511982Sgabeblack@google.com################################################### 106611982Sgabeblack@google.com# 106711982Sgabeblack@google.com# Builders for static and shared partially linked object files. 106811982Sgabeblack@google.com# 106911982Sgabeblack@google.com################################################### 107011982Sgabeblack@google.com 107111982Sgabeblack@google.compartial_static_builder = Builder(action=SCons.Defaults.LinkAction, 107211982Sgabeblack@google.com src_suffix='$OBJSUFFIX', 107311982Sgabeblack@google.com src_builder=['StaticObject', 'Object'], 107411982Sgabeblack@google.com LINKFLAGS='$PLINKFLAGS', 107511982Sgabeblack@google.com LIBS='') 107611982Sgabeblack@google.com 107711982Sgabeblack@google.comdef partial_shared_emitter(target, source, env): 107811982Sgabeblack@google.com for tgt in target: 107911982Sgabeblack@google.com tgt.attributes.shared = 1 108011982Sgabeblack@google.com return (target, source) 108111982Sgabeblack@google.compartial_shared_builder = Builder(action=SCons.Defaults.ShLinkAction, 108211978Sgabeblack@google.com emitter=partial_shared_emitter, 108311978Sgabeblack@google.com src_suffix='$SHOBJSUFFIX', 108412034Sgabeblack@google.com src_builder='SharedObject', 108511978Sgabeblack@google.com SHLINKFLAGS='$PSHLINKFLAGS', 108611978Sgabeblack@google.com LIBS='') 108711978Sgabeblack@google.com 108812034Sgabeblack@google.commain.Append(BUILDERS = { 'PartialShared' : partial_shared_builder, 108911978Sgabeblack@google.com 'PartialStatic' : partial_static_builder }) 109011978Sgabeblack@google.com 109110915Sandreas.sandberg@arm.comdef add_local_rpath(env, *targets): 109211986Sandreas.sandberg@arm.com '''Set up an RPATH for a library which lives in the build directory. 109311986Sandreas.sandberg@arm.com 10941869SN/A The construction environment variable BIN_RPATH_PREFIX should be set to 10951869SN/A the relative path of the build directory starting from the location of the 109612015Sgabeblack@google.com binary.''' 109712015Sgabeblack@google.com for target in targets: 109812015Sgabeblack@google.com target = env.Entry(target) 109912015Sgabeblack@google.com if not target.isdir(): 11003546Sgblack@eecs.umich.edu target = target.dir 11013546Sgblack@eecs.umich.edu relpath = os.path.relpath(target.abspath, env['BUILDDIR']) 11023546Sgblack@eecs.umich.edu components = [ 110312015Sgabeblack@google.com '\\$$ORIGIN', 110412015Sgabeblack@google.com '${BIN_RPATH_PREFIX}', 110512015Sgabeblack@google.com relpath 110612015Sgabeblack@google.com ] 110712015Sgabeblack@google.com env.Append(RPATH=[env.Literal(os.path.join(*components))]) 110812015Sgabeblack@google.com 110912015Sgabeblack@google.comif sys.platform != "darwin": 111012015Sgabeblack@google.com main.Append(LINKFLAGS=Split('-z origin')) 11113546Sgblack@eecs.umich.edu 111212015Sgabeblack@google.commain.AddMethod(add_local_rpath, 'AddLocalRPATH') 111312015Sgabeblack@google.com 111410196SCurtis.Dunham@arm.com# builds in ext are shared across all configs in the build root. 111512015Sgabeblack@google.comext_dir = abspath(joinpath(str(main.root), 'ext')) 111612015Sgabeblack@google.comext_build_dirs = [] 111712015Sgabeblack@google.comfor root, dirs, files in os.walk(ext_dir): 111812015Sgabeblack@google.com if 'SConscript' in files: 111912015Sgabeblack@google.com build_dir = os.path.relpath(root, ext_dir) 112012015Sgabeblack@google.com ext_build_dirs.append(build_dir) 112112015Sgabeblack@google.com main.SConscript(joinpath(root, 'SConscript'), 112212015Sgabeblack@google.com variant_dir=joinpath(build_root, build_dir)) 112312015Sgabeblack@google.com 112412015Sgabeblack@google.comgdb_xml_dir = joinpath(ext_dir, 'gdb-xml') 112512015Sgabeblack@google.comExport('gdb_xml_dir') 11263546Sgblack@eecs.umich.edu 11273546Sgblack@eecs.umich.edumain.Prepend(CPPPATH=Dir('ext/pybind11/include/')) 11283546Sgblack@eecs.umich.edu 1129955SN/A################################################### 1130955SN/A# 1131955SN/A# This builder and wrapper method are used to set up a directory with 1132955SN/A# switching headers. Those are headers which are in a generic location and 11335863Snate@binkert.org# that include more specific headers from a directory chosen at build time 113410135SCurtis.Dunham@arm.com# based on the current build settings. 113510135SCurtis.Dunham@arm.com# 11365343Sstever@gmail.com################################################### 11375343Sstever@gmail.com 11386121Snate@binkert.orgdef build_switching_header(target, source, env): 11395863Snate@binkert.org path = str(target[0]) 11404773Snate@binkert.org subdir = str(source[0]) 11415863Snate@binkert.org dp, fp = os.path.split(path) 11422632Sstever@eecs.umich.edu dp = os.path.relpath(os.path.realpath(dp), 11435863Snate@binkert.org os.path.realpath(env['BUILDDIR'])) 11442023SN/A with open(path, 'w') as hdr: 11455863Snate@binkert.org print('#include "%s/%s/%s"' % (dp, subdir, fp), file=hdr) 11465863Snate@binkert.org 11475863Snate@binkert.orgswitching_header_action = MakeAction(build_switching_header, 11485863Snate@binkert.org Transform('GENERATE')) 11495863Snate@binkert.org 11505863Snate@binkert.orgswitching_header_builder = Builder(action=switching_header_action, 11515863Snate@binkert.org source_factory=Value, 11525863Snate@binkert.org single_source=True) 115310135SCurtis.Dunham@arm.com 115410135SCurtis.Dunham@arm.commain.Append(BUILDERS = { 'SwitchingHeader': switching_header_builder }) 115512034Sgabeblack@google.com 115612034Sgabeblack@google.comdef switching_headers(self, headers, source): 115712034Sgabeblack@google.com for header in headers: 11582632Sstever@eecs.umich.edu self.SwitchingHeader(header, source) 11595863Snate@binkert.org 11602023SN/Amain.AddMethod(switching_headers, 'SwitchingHeaders') 11612632Sstever@eecs.umich.edu 11625863Snate@binkert.org################################################### 11635342Sstever@gmail.com# 11645863Snate@binkert.org# Define build environments for selected configurations. 11652632Sstever@eecs.umich.edu# 11665863Snate@binkert.org################################################### 11675863Snate@binkert.org 11688267Ssteve.reinhardt@amd.comfor variant_path in variant_paths: 11698120Sgblack@eecs.umich.edu if not GetOption('silent'): 11708267Ssteve.reinhardt@amd.com print("Building in", variant_path) 11718267Ssteve.reinhardt@amd.com 11728267Ssteve.reinhardt@amd.com # Make a copy of the build-root environment to use for this config. 11738267Ssteve.reinhardt@amd.com env = main.Clone() 11748267Ssteve.reinhardt@amd.com env['BUILDDIR'] = variant_path 11758267Ssteve.reinhardt@amd.com 11768267Ssteve.reinhardt@amd.com # variant_dir is the tail component of build path, and is used to 11778267Ssteve.reinhardt@amd.com # determine the build parameters (e.g., 'ALPHA_SE') 11788267Ssteve.reinhardt@amd.com (build_root, variant_dir) = splitpath(variant_path) 11795863Snate@binkert.org 11805863Snate@binkert.org # Set env variables according to the build directory config. 11815863Snate@binkert.org sticky_vars.files = [] 11822632Sstever@eecs.umich.edu # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 11838267Ssteve.reinhardt@amd.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 11848267Ssteve.reinhardt@amd.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 11858267Ssteve.reinhardt@amd.com current_vars_file = joinpath(build_root, 'variables', variant_dir) 11862632Sstever@eecs.umich.edu if isfile(current_vars_file): 11871888SN/A sticky_vars.files.append(current_vars_file) 11885863Snate@binkert.org if not GetOption('silent'): 11895863Snate@binkert.org print("Using saved variables file %s" % current_vars_file) 11901858SN/A elif variant_dir in ext_build_dirs: 11918120Sgblack@eecs.umich.edu # Things in ext are built without a variant directory. 11928120Sgblack@eecs.umich.edu continue 11937756SAli.Saidi@ARM.com else: 11942598SN/A # Build dir-specific variables file doesn't exist. 11955863Snate@binkert.org 11961858SN/A # Make sure the directory is there so we can create it later 11971858SN/A opt_dir = dirname(current_vars_file) 11981858SN/A if not isdir(opt_dir): 11995863Snate@binkert.org mkdir(opt_dir) 12001858SN/A 12011858SN/A # Get default build variables from source tree. Variables are 12021858SN/A # normally determined by name of $VARIANT_DIR, but can be 12035863Snate@binkert.org # overridden by '--default=' arg on command line. 12041871SN/A default = GetOption('default') 12051858SN/A opts_dir = joinpath(main.root.abspath, 'build_opts') 120612230Sgiacomo.travaglini@arm.com if default: 120712230Sgiacomo.travaglini@arm.com default_vars_files = [joinpath(build_root, 'variables', default), 120812230Sgiacomo.travaglini@arm.com joinpath(opts_dir, default)] 120912230Sgiacomo.travaglini@arm.com else: 121012230Sgiacomo.travaglini@arm.com default_vars_files = [joinpath(opts_dir, variant_dir)] 121112230Sgiacomo.travaglini@arm.com existing_files = filter(isfile, default_vars_files) 121212230Sgiacomo.travaglini@arm.com if existing_files: 121312230Sgiacomo.travaglini@arm.com default_vars_file = existing_files[0] 12141858SN/A sticky_vars.files.append(default_vars_file) 12151858SN/A print("Variables file %s not found,\n using defaults in %s" 12161858SN/A % (current_vars_file, default_vars_file)) 12179651SAndreas.Sandberg@ARM.com else: 12189651SAndreas.Sandberg@ARM.com print("Error: cannot find variables file %s or " 12199651SAndreas.Sandberg@ARM.com "default file(s) %s" 12209651SAndreas.Sandberg@ARM.com % (current_vars_file, ' or '.join(default_vars_files))) 12219651SAndreas.Sandberg@ARM.com Exit(1) 12229651SAndreas.Sandberg@ARM.com 12239651SAndreas.Sandberg@ARM.com # Apply current variable settings to env 12249651SAndreas.Sandberg@ARM.com sticky_vars.Update(env) 12259651SAndreas.Sandberg@ARM.com 122612056Sgabeblack@google.com help_texts["local_vars"] += \ 122712056Sgabeblack@google.com "Build variables for %s:\n" % variant_dir \ 122812056Sgabeblack@google.com + sticky_vars.GenerateHelpText(env) 122912056Sgabeblack@google.com 123012056Sgabeblack@google.com # Process variable settings. 123111798Santhony.gutierrez@amd.com 123211798Santhony.gutierrez@amd.com if not have_fenv and env['USE_FENV']: 123311798Santhony.gutierrez@amd.com print("Warning: <fenv.h> not available; " 12349986Sandreas@sandberg.pp.se "forcing USE_FENV to False in", variant_dir + ".") 12359986Sandreas@sandberg.pp.se env['USE_FENV'] = False 12369986Sandreas@sandberg.pp.se 12379986Sandreas@sandberg.pp.se if not env['USE_FENV']: 12389986Sandreas@sandberg.pp.se print("Warning: No IEEE FP rounding mode control in", 12399986Sandreas@sandberg.pp.se variant_dir + ".") 12409986Sandreas@sandberg.pp.se print(" FP results may deviate slightly from other platforms.") 12415863Snate@binkert.org 12425863Snate@binkert.org if not have_png and env['USE_PNG']: 12431869SN/A print("Warning: <png.h> not available; " 12441965SN/A "forcing USE_PNG to False in", variant_dir + ".") 12457739Sgblack@eecs.umich.edu env['USE_PNG'] = False 12461965SN/A 12472761Sstever@eecs.umich.edu if env['USE_PNG']: 12485863Snate@binkert.org env.Append(LIBS=['png']) 12491869SN/A 125010196SCurtis.Dunham@arm.com if env['EFENCE']: 12511869SN/A env.Append(LIBS=['efence']) 12528120Sgblack@eecs.umich.edu 12538120Sgblack@eecs.umich.edu if env['USE_KVM']: 12548120Sgblack@eecs.umich.edu if not have_kvm: 12558120Sgblack@eecs.umich.edu print("Warning: Can not enable KVM, host seems to " 12568120Sgblack@eecs.umich.edu "lack KVM support") 12578120Sgblack@eecs.umich.edu env['USE_KVM'] = False 12588120Sgblack@eecs.umich.edu elif not is_isa_kvm_compatible(env['TARGET_ISA']): 12598120Sgblack@eecs.umich.edu print("Info: KVM support disabled due to unsupported host and " 12608120Sgblack@eecs.umich.edu "target ISA combination") 12618120Sgblack@eecs.umich.edu env['USE_KVM'] = False 12628120Sgblack@eecs.umich.edu 12638120Sgblack@eecs.umich.edu if env['USE_TUNTAP']: 1264 if not have_tuntap: 1265 print("Warning: Can't connect EtherTap with a tap device.") 1266 env['USE_TUNTAP'] = False 1267 1268 if env['BUILD_GPU']: 1269 env.Append(CPPDEFINES=['BUILD_GPU']) 1270 1271 # Warn about missing optional functionality 1272 if env['USE_KVM']: 1273 if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']: 1274 print("Warning: perf_event headers lack support for the " 1275 "exclude_host attribute. KVM instruction counts will " 1276 "be inaccurate.") 1277 1278 # Save sticky variable settings back to current variables file 1279 sticky_vars.Save(current_vars_file, env) 1280 1281 if env['USE_SSE2']: 1282 env.Append(CCFLAGS=['-msse2']) 1283 1284 # The src/SConscript file sets up the build rules in 'env' according 1285 # to the configured variables. It returns a list of environments, 1286 # one for each variant build (debug, opt, etc.) 1287 SConscript('src/SConscript', variant_dir = variant_path, exports = 'env') 1288 1289# base help text 1290Help(''' 1291Usage: scons [scons options] [build variables] [target(s)] 1292 1293Extra scons options: 1294%(options)s 1295 1296Global build variables: 1297%(global_vars)s 1298 1299%(local_vars)s 1300''' % help_texts) 1301