SConstruct revision 13421
1955SN/A# -*- mode:python -*- 2955SN/A 311408Sandreas.sandberg@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 815863Snate@binkert.orgfrom __future__ import print_function 825863Snate@binkert.org 835863Snate@binkert.org# Global Python includes 845863Snate@binkert.orgimport itertools 855863Snate@binkert.orgimport os 865863Snate@binkert.orgimport re 875863Snate@binkert.orgimport shutil 885863Snate@binkert.orgimport subprocess 895863Snate@binkert.orgimport sys 905863Snate@binkert.org 915863Snate@binkert.orgfrom os import mkdir, environ 928878Ssteve.reinhardt@amd.comfrom 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 955863Snate@binkert.org 969812Sandreas.hansson@arm.com# SCons includes 979812Sandreas.hansson@arm.comimport SCons 985863Snate@binkert.orgimport SCons.Node 999812Sandreas.hansson@arm.com 1005863Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1015863Snate@binkert.org 1025863Snate@binkert.orghelp_texts = { 1039812Sandreas.hansson@arm.com "options" : "", 1049812Sandreas.hansson@arm.com "global_vars" : "", 1055863Snate@binkert.org "local_vars" : "" 1065863Snate@binkert.org} 1078878Ssteve.reinhardt@amd.com 1085863Snate@binkert.orgExport("help_texts") 1095863Snate@binkert.org 1105863Snate@binkert.org 1116654Snate@binkert.org# There's a bug in scons in that (1) by default, the help texts from 11210196SCurtis.Dunham@arm.com# AddOption() are supposed to be displayed when you type 'scons -h' 113955SN/A# and (2) you can override the help displayed by 'scons -h' using the 1145396Ssaidi@eecs.umich.edu# Help() function, but these two features are incompatible: once 11511401Sandreas.sandberg@arm.com# you've overridden the help text using Help(), there's no way to get 1165863Snate@binkert.org# at the help texts from AddOptions. See: 1175863Snate@binkert.org# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1184202Sbinkertn@umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1195863Snate@binkert.org# This hack lets us extract the help text from AddOptions and 1205863Snate@binkert.org# re-inject it via Help(). Ideally someday this bug will be fixed and 1215863Snate@binkert.org# we can just use AddOption directly. 1225863Snate@binkert.orgdef AddLocalOption(*args, **kwargs): 123955SN/A col_width = 30 1246654Snate@binkert.org 1255273Sstever@gmail.com help = " " + ", ".join(args) 1265871Snate@binkert.org if "help" in kwargs: 1275273Sstever@gmail.com length = len(help) 1286655Snate@binkert.org if length >= col_width: 1298878Ssteve.reinhardt@amd.com help += "\n" + " " * col_width 1306655Snate@binkert.org else: 1316655Snate@binkert.org help += " " * (col_width - length) 1329219Spower.jg@gmail.com help += kwargs["help"] 1336655Snate@binkert.org help_texts["options"] += help + "\n" 1345871Snate@binkert.org 1356654Snate@binkert.org AddOption(*args, **kwargs) 1368947Sandreas.hansson@arm.com 1375396Ssaidi@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true', 1388120Sgblack@eecs.umich.edu help="Add color to abbreviated scons output") 1398120Sgblack@eecs.umich.eduAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1408120Sgblack@eecs.umich.edu help="Don't add color to abbreviated scons output") 1418120Sgblack@eecs.umich.eduAddLocalOption('--with-cxx-config', dest='with_cxx_config', 1428120Sgblack@eecs.umich.edu action='store_true', 1438120Sgblack@eecs.umich.edu help="Build with support for C++-based configuration") 1448120Sgblack@eecs.umich.eduAddLocalOption('--default', dest='default', type='string', action='store', 1458120Sgblack@eecs.umich.edu help='Override which build_opts file to use for defaults') 1468879Ssteve.reinhardt@amd.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1478879Ssteve.reinhardt@amd.com help='Disable style checking hooks') 1488879Ssteve.reinhardt@amd.comAddLocalOption('--gold-linker', dest='gold_linker', action='store_true', 1498879Ssteve.reinhardt@amd.com help='Use the gold linker') 1508879Ssteve.reinhardt@amd.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1518879Ssteve.reinhardt@amd.com help='Disable Link-Time Optimization for fast') 1528879Ssteve.reinhardt@amd.comAddLocalOption('--force-lto', dest='force_lto', action='store_true', 1538879Ssteve.reinhardt@amd.com help='Use Link-Time Optimization instead of partial linking' + 1548879Ssteve.reinhardt@amd.com ' when the compiler doesn\'t support using them together.') 1558879Ssteve.reinhardt@amd.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1568879Ssteve.reinhardt@amd.com help='Update test reference outputs') 1578879Ssteve.reinhardt@amd.comAddLocalOption('--verbose', dest='verbose', action='store_true', 1588879Ssteve.reinhardt@amd.com help='Print full tool command lines') 1598120Sgblack@eecs.umich.eduAddLocalOption('--without-python', dest='without_python', 1608120Sgblack@eecs.umich.edu action='store_true', 1618120Sgblack@eecs.umich.edu help='Build without Python configuration support') 1628120Sgblack@eecs.umich.eduAddLocalOption('--without-tcmalloc', dest='without_tcmalloc', 1638120Sgblack@eecs.umich.edu action='store_true', 1648120Sgblack@eecs.umich.edu help='Disable linking against tcmalloc') 1658120Sgblack@eecs.umich.eduAddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true', 1668120Sgblack@eecs.umich.edu help='Build with Undefined Behavior Sanitizer if available') 1678120Sgblack@eecs.umich.eduAddLocalOption('--with-asan', dest='with_asan', action='store_true', 1688120Sgblack@eecs.umich.edu help='Build with Address Sanitizer if available') 1698120Sgblack@eecs.umich.edu 1708120Sgblack@eecs.umich.eduif GetOption('no_lto') and GetOption('force_lto'): 1718120Sgblack@eecs.umich.edu print('--no-lto and --force-lto are mutually exclusive') 1728120Sgblack@eecs.umich.edu Exit(1) 1738879Ssteve.reinhardt@amd.com 1748879Ssteve.reinhardt@amd.com######################################################################## 1758879Ssteve.reinhardt@amd.com# 1768879Ssteve.reinhardt@amd.com# Set up the main build environment. 17710458Sandreas.hansson@arm.com# 17810458Sandreas.hansson@arm.com######################################################################## 17910458Sandreas.hansson@arm.com 1808879Ssteve.reinhardt@amd.commain = Environment() 1818879Ssteve.reinhardt@amd.com 1828879Ssteve.reinhardt@amd.comfrom gem5_scons import Transform 1838879Ssteve.reinhardt@amd.comfrom gem5_scons.util import get_termcap 1849227Sandreas.hansson@arm.comtermcap = get_termcap() 1859227Sandreas.hansson@arm.com 1868879Ssteve.reinhardt@amd.commain_dict_keys = main.Dictionary().keys() 1878879Ssteve.reinhardt@amd.com 1888879Ssteve.reinhardt@amd.com# Check that we have a C/C++ compiler 1898879Ssteve.reinhardt@amd.comif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 19010453SAndrew.Bardsley@arm.com print("No C++ compiler installed (package g++ on Ubuntu and RedHat)") 19110453SAndrew.Bardsley@arm.com Exit(1) 19210453SAndrew.Bardsley@arm.com 19310456SCurtis.Dunham@arm.com################################################### 19410456SCurtis.Dunham@arm.com# 19510456SCurtis.Dunham@arm.com# Figure out which configurations to set up based on the path(s) of 19610457Sandreas.hansson@arm.com# the target(s). 19710457Sandreas.hansson@arm.com# 19811342Sandreas.hansson@arm.com################################################### 19911342Sandreas.hansson@arm.com 2008120Sgblack@eecs.umich.edu# Find default configuration & binary. 2018947Sandreas.hansson@arm.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2027816Ssteve.reinhardt@amd.com 2035871Snate@binkert.org# helper function: find last occurrence of element in list 2045871Snate@binkert.orgdef rfind(l, elt, offs = -1): 2056121Snate@binkert.org for i in range(len(l)+offs, 0, -1): 2065871Snate@binkert.org if l[i] == elt: 2075871Snate@binkert.org return i 2089926Sstan.czerniawski@arm.com raise ValueError, "element not found" 2099926Sstan.czerniawski@arm.com 2109119Sandreas.hansson@arm.com# Take a list of paths (or SCons Nodes) and return a list with all 21110068Sandreas.hansson@arm.com# paths made absolute and ~-expanded. Paths will be interpreted 21210068Sandreas.hansson@arm.com# relative to the launch directory unless a different root is provided 213955SN/Adef makePathListAbsolute(path_list, root=GetLaunchDir()): 2149416SAndreas.Sandberg@ARM.com return [abspath(joinpath(root, expanduser(str(p)))) 21511342Sandreas.hansson@arm.com for p in path_list] 21611212Sjoseph.gross@amd.com 21711212Sjoseph.gross@amd.com# Each target must have 'build' in the interior of the path; the 21811212Sjoseph.gross@amd.com# directory below this will determine the build parameters. For 21911212Sjoseph.gross@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 22011212Sjoseph.gross@amd.com# recognize that ALPHA_SE specifies the configuration because it 2219416SAndreas.Sandberg@ARM.com# follow 'build' in the build path. 2229416SAndreas.Sandberg@ARM.com 2235871Snate@binkert.org# The funky assignment to "[:]" is needed to replace the list contents 22410584Sandreas.hansson@arm.com# in place rather than reassign the symbol to a new list, which 2259416SAndreas.Sandberg@ARM.com# doesn't work (obviously!). 2269416SAndreas.Sandberg@ARM.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 2275871Snate@binkert.org 228955SN/A# Generate a list of the unique build roots and configs that the 22910671Sandreas.hansson@arm.com# collected targets reference. 23010671Sandreas.hansson@arm.comvariant_paths = [] 23110671Sandreas.hansson@arm.combuild_root = None 23210671Sandreas.hansson@arm.comfor t in BUILD_TARGETS: 2338881Smarc.orr@gmail.com path_dirs = t.split('/') 2346121Snate@binkert.org try: 2356121Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 2361533SN/A except: 2379239Sandreas.hansson@arm.com print("Error: no non-leaf 'build' dir found on target path", t) 2389239Sandreas.hansson@arm.com Exit(1) 2399239Sandreas.hansson@arm.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2409239Sandreas.hansson@arm.com if not build_root: 2419239Sandreas.hansson@arm.com build_root = this_build_root 2429239Sandreas.hansson@arm.com else: 2439239Sandreas.hansson@arm.com if this_build_root != build_root: 2449239Sandreas.hansson@arm.com print("Error: build targets not under same build root\n" 2459239Sandreas.hansson@arm.com " %s\n %s" % (build_root, this_build_root)) 2469239Sandreas.hansson@arm.com Exit(1) 2479239Sandreas.hansson@arm.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 2489239Sandreas.hansson@arm.com if variant_path not in variant_paths: 2496655Snate@binkert.org variant_paths.append(variant_path) 2506655Snate@binkert.org 2516655Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 2526655Snate@binkert.orgif not isdir(build_root): 2535871Snate@binkert.org mkdir(build_root) 2545871Snate@binkert.orgmain['BUILDROOT'] = build_root 2555863Snate@binkert.org 2565871Snate@binkert.orgExport('main') 2578878Ssteve.reinhardt@amd.com 2585871Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign")) 2595871Snate@binkert.org 2605871Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 2615863Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 2626121Snate@binkert.org# file to file~ then copies to file, breaking the link. Symbolic 2635863Snate@binkert.org# (soft) links work better. 26411408Sandreas.sandberg@arm.commain.SetOption('duplicate', 'soft-copy') 26511408Sandreas.sandberg@arm.com 2668336Ssteve.reinhardt@amd.com# 26711469SCurtis.Dunham@arm.com# Set up global sticky variables... these are common to an entire build 26811469SCurtis.Dunham@arm.com# tree (not specific to a particular build like ALPHA_SE) 2698336Ssteve.reinhardt@amd.com# 2704678Snate@binkert.org 27111469SCurtis.Dunham@arm.comglobal_vars_file = joinpath(build_root, 'variables.global') 27211469SCurtis.Dunham@arm.com 27311469SCurtis.Dunham@arm.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 27411469SCurtis.Dunham@arm.com 27511408Sandreas.sandberg@arm.comglobal_vars.AddVariables( 27611401Sandreas.sandberg@arm.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 27711401Sandreas.sandberg@arm.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 27811401Sandreas.sandberg@arm.com ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 27911401Sandreas.sandberg@arm.com ('BATCH', 'Use batch pool for build and tests', False), 28011401Sandreas.sandberg@arm.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 28111401Sandreas.sandberg@arm.com ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 2828336Ssteve.reinhardt@amd.com ('EXTRAS', 'Add extra directories to the compilation', '') 2838336Ssteve.reinhardt@amd.com ) 2848336Ssteve.reinhardt@amd.com 2854678Snate@binkert.org# Update main environment with values from ARGUMENTS & global_vars_file 28611401Sandreas.sandberg@arm.comglobal_vars.Update(main) 2874678Snate@binkert.orghelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 2884678Snate@binkert.org 28911401Sandreas.sandberg@arm.com# Save sticky variable settings back to current variables file 29011401Sandreas.sandberg@arm.comglobal_vars.Save(global_vars_file, main) 2918336Ssteve.reinhardt@amd.com 2924678Snate@binkert.org# Parse EXTRAS variable to build list of all directories where we're 2938336Ssteve.reinhardt@amd.com# look for sources etc. This list is exported as extras_dir_list. 2948336Ssteve.reinhardt@amd.combase_dir = main.srcdir.abspath 2958336Ssteve.reinhardt@amd.comif main['EXTRAS']: 2968336Ssteve.reinhardt@amd.com extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 2978336Ssteve.reinhardt@amd.comelse: 2988336Ssteve.reinhardt@amd.com extras_dir_list = [] 2995871Snate@binkert.org 3005871Snate@binkert.orgExport('base_dir') 3018336Ssteve.reinhardt@amd.comExport('extras_dir_list') 30211408Sandreas.sandberg@arm.com 30311408Sandreas.sandberg@arm.com# the ext directory should be on the #includes path 30411408Sandreas.sandberg@arm.commain.Append(CPPPATH=[Dir('ext')]) 30511408Sandreas.sandberg@arm.com 30611408Sandreas.sandberg@arm.com# Add shared top-level headers 30711408Sandreas.sandberg@arm.commain.Prepend(CPPPATH=Dir('include')) 30811408Sandreas.sandberg@arm.com 3098336Ssteve.reinhardt@amd.comif GetOption('verbose'): 31011401Sandreas.sandberg@arm.com def MakeAction(action, string, *args, **kwargs): 31111401Sandreas.sandberg@arm.com return Action(action, *args, **kwargs) 31211401Sandreas.sandberg@arm.comelse: 3135871Snate@binkert.org MakeAction = Action 3148336Ssteve.reinhardt@amd.com main['CCCOMSTR'] = Transform("CC") 3158336Ssteve.reinhardt@amd.com main['CXXCOMSTR'] = Transform("CXX") 31611401Sandreas.sandberg@arm.com main['ASCOMSTR'] = Transform("AS") 31711401Sandreas.sandberg@arm.com main['ARCOMSTR'] = Transform("AR", 0) 31811401Sandreas.sandberg@arm.com main['LINKCOMSTR'] = Transform("LINK", 0) 31911401Sandreas.sandberg@arm.com main['SHLINKCOMSTR'] = Transform("SHLINK", 0) 32011401Sandreas.sandberg@arm.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 3214678Snate@binkert.org main['M4COMSTR'] = Transform("M4") 3225871Snate@binkert.org main['SHCCCOMSTR'] = Transform("SHCC") 3234678Snate@binkert.org main['SHCXXCOMSTR'] = Transform("SHCXX") 32411401Sandreas.sandberg@arm.comExport('MakeAction') 32511401Sandreas.sandberg@arm.com 32611401Sandreas.sandberg@arm.com# Initialize the Link-Time Optimization (LTO) flags 32711401Sandreas.sandberg@arm.commain['LTO_CCFLAGS'] = [] 32811401Sandreas.sandberg@arm.commain['LTO_LDFLAGS'] = [] 32911401Sandreas.sandberg@arm.com 33011401Sandreas.sandberg@arm.com# According to the readme, tcmalloc works best if the compiler doesn't 33111401Sandreas.sandberg@arm.com# assume that we're using the builtin malloc and friends. These flags 33211401Sandreas.sandberg@arm.com# are compiler-specific, so we need to set them after we detect which 33311401Sandreas.sandberg@arm.com# compiler we're using. 33411401Sandreas.sandberg@arm.commain['TCMALLOC_CCFLAGS'] = [] 33511401Sandreas.sandberg@arm.com 33611450Sandreas.sandberg@arm.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 33711450Sandreas.sandberg@arm.comCXX_V = readCommand([main['CXX'],'-V'], exception=False) 33811450Sandreas.sandberg@arm.com 33911450Sandreas.sandberg@arm.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 34011450Sandreas.sandberg@arm.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 34111450Sandreas.sandberg@arm.comif main['GCC'] + main['CLANG'] > 1: 34211450Sandreas.sandberg@arm.com print('Error: How can we have two at the same time?') 34311450Sandreas.sandberg@arm.com Exit(1) 34411450Sandreas.sandberg@arm.com 34511450Sandreas.sandberg@arm.com# Set up default C++ compiler flags 34611450Sandreas.sandberg@arm.comif main['GCC'] or main['CLANG']: 34711401Sandreas.sandberg@arm.com # As gcc and clang share many flags, do the common parts here 34811450Sandreas.sandberg@arm.com main.Append(CCFLAGS=['-pipe']) 34911450Sandreas.sandberg@arm.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 35011450Sandreas.sandberg@arm.com # Enable -Wall and -Wextra and then disable the few warnings that 35111401Sandreas.sandberg@arm.com # we consistently violate 35211450Sandreas.sandberg@arm.com main.Append(CCFLAGS=['-Wall', '-Wundef', '-Wextra', 35311401Sandreas.sandberg@arm.com '-Wno-sign-compare', '-Wno-unused-parameter']) 3548336Ssteve.reinhardt@amd.com # We always compile using C++11 3558336Ssteve.reinhardt@amd.com main.Append(CXXFLAGS=['-std=c++11']) 3568336Ssteve.reinhardt@amd.com if sys.platform.startswith('freebsd'): 3578336Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-I/usr/local/include']) 3588336Ssteve.reinhardt@amd.com main.Append(CXXFLAGS=['-I/usr/local/include']) 3598336Ssteve.reinhardt@amd.com 3608336Ssteve.reinhardt@amd.com main['FILTER_PSHLINKFLAGS'] = lambda x: str(x).replace(' -shared', '') 3618336Ssteve.reinhardt@amd.com main['PSHLINKFLAGS'] = main.subst('${FILTER_PSHLINKFLAGS(SHLINKFLAGS)}') 3628336Ssteve.reinhardt@amd.com if GetOption('gold_linker'): 3638336Ssteve.reinhardt@amd.com main.Append(LINKFLAGS='-fuse-ld=gold') 36411401Sandreas.sandberg@arm.com main['PLINKFLAGS'] = main.subst('${LINKFLAGS}') 36511401Sandreas.sandberg@arm.com shared_partial_flags = ['-r', '-nostdlib'] 3668336Ssteve.reinhardt@amd.com main.Append(PSHLINKFLAGS=shared_partial_flags) 3678336Ssteve.reinhardt@amd.com main.Append(PLINKFLAGS=shared_partial_flags) 3688336Ssteve.reinhardt@amd.com 3695871Snate@binkert.org # Treat warnings as errors but white list some warnings that we 37011476Sandreas.sandberg@arm.com # want to allow (e.g., deprecation warnings). 37111476Sandreas.sandberg@arm.com main.Append(CCFLAGS=['-Werror', 37211476Sandreas.sandberg@arm.com '-Wno-error=deprecated-declarations', 37311476Sandreas.sandberg@arm.com '-Wno-error=deprecated', 37411476Sandreas.sandberg@arm.com ]) 37511476Sandreas.sandberg@arm.comelse: 37611476Sandreas.sandberg@arm.com print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 37711476Sandreas.sandberg@arm.com print("Don't know what compiler options to use for your compiler.") 37811476Sandreas.sandberg@arm.com print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 37911476Sandreas.sandberg@arm.com print(termcap.Yellow + ' version:' + termcap.Normal, end = ' ') 38011408Sandreas.sandberg@arm.com if not CXX_version: 38111408Sandreas.sandberg@arm.com print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 38211476Sandreas.sandberg@arm.com termcap.Normal) 38311476Sandreas.sandberg@arm.com else: 38411476Sandreas.sandberg@arm.com print(CXX_version.replace('\n', '<nl>')) 38511408Sandreas.sandberg@arm.com print(" If you're trying to use a compiler other than GCC") 38611408Sandreas.sandberg@arm.com print(" or clang, there appears to be something wrong with your") 38711408Sandreas.sandberg@arm.com print(" environment.") 38811408Sandreas.sandberg@arm.com print(" ") 38911408Sandreas.sandberg@arm.com print(" If you are trying to use a compiler other than those listed") 39011408Sandreas.sandberg@arm.com print(" above you will need to ease fix SConstruct and ") 39111408Sandreas.sandberg@arm.com print(" src/SConscript to support that compiler.") 39211476Sandreas.sandberg@arm.com Exit(1) 39311476Sandreas.sandberg@arm.com 39411476Sandreas.sandberg@arm.comif main['GCC']: 39511476Sandreas.sandberg@arm.com # Check for a supported version of gcc. >= 4.8 is chosen for its 39611476Sandreas.sandberg@arm.com # level of c++11 support. See 39711476Sandreas.sandberg@arm.com # http://gcc.gnu.org/projects/cxx0x.html for details. 39811408Sandreas.sandberg@arm.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 39911408Sandreas.sandberg@arm.com if compareVersions(gcc_version, "4.8") < 0: 40011476Sandreas.sandberg@arm.com print('Error: gcc version 4.8 or newer required.') 40111476Sandreas.sandberg@arm.com print(' Installed version: ', gcc_version) 40211476Sandreas.sandberg@arm.com Exit(1) 40311476Sandreas.sandberg@arm.com 40411476Sandreas.sandberg@arm.com main['GCC_VERSION'] = gcc_version 40511408Sandreas.sandberg@arm.com 40611408Sandreas.sandberg@arm.com if compareVersions(gcc_version, '4.9') >= 0: 40711408Sandreas.sandberg@arm.com # Incremental linking with LTO is currently broken in gcc versions 40811476Sandreas.sandberg@arm.com # 4.9 and above. A version where everything works completely hasn't 40911476Sandreas.sandberg@arm.com # yet been identified. 41011476Sandreas.sandberg@arm.com # 41111476Sandreas.sandberg@arm.com # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67548 4126121Snate@binkert.org main['BROKEN_INCREMENTAL_LTO'] = True 413955SN/A if compareVersions(gcc_version, '6.0') >= 0: 414955SN/A # gcc versions 6.0 and greater accept an -flinker-output flag which 4152632Sstever@eecs.umich.edu # selects what type of output the linker should generate. This is 4162632Sstever@eecs.umich.edu # necessary for incremental lto to work, but is also broken in 417955SN/A # current versions of gcc. It may not be necessary in future 418955SN/A # versions. We add it here since it might be, and as a reminder that 419955SN/A # it exists. It's excluded if lto is being forced. 420955SN/A # 4218878Ssteve.reinhardt@amd.com # https://gcc.gnu.org/gcc-6/changes.html 422955SN/A # https://gcc.gnu.org/ml/gcc-patches/2015-11/msg03161.html 4232632Sstever@eecs.umich.edu # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69866 4242632Sstever@eecs.umich.edu if not GetOption('force_lto'): 4252632Sstever@eecs.umich.edu main.Append(PSHLINKFLAGS='-flinker-output=rel') 4262632Sstever@eecs.umich.edu main.Append(PLINKFLAGS='-flinker-output=rel') 4272632Sstever@eecs.umich.edu 4282632Sstever@eecs.umich.edu # Make sure we warn if the user has requested to compile with the 4292632Sstever@eecs.umich.edu # Undefined Benahvior Sanitizer and this version of gcc does not 4308268Ssteve.reinhardt@amd.com # support it. 4318268Ssteve.reinhardt@amd.com if GetOption('with_ubsan') and \ 4328268Ssteve.reinhardt@amd.com compareVersions(gcc_version, '4.9') < 0: 4338268Ssteve.reinhardt@amd.com print(termcap.Yellow + termcap.Bold + 4348268Ssteve.reinhardt@amd.com 'Warning: UBSan is only supported using gcc 4.9 and later.' + 4358268Ssteve.reinhardt@amd.com termcap.Normal) 4368268Ssteve.reinhardt@amd.com 4372632Sstever@eecs.umich.edu disable_lto = GetOption('no_lto') 4382632Sstever@eecs.umich.edu if not disable_lto and main.get('BROKEN_INCREMENTAL_LTO', False) and \ 4392632Sstever@eecs.umich.edu not GetOption('force_lto'): 4402632Sstever@eecs.umich.edu print(termcap.Yellow + termcap.Bold + 4418268Ssteve.reinhardt@amd.com 'Warning: Your compiler doesn\'t support incremental linking' + 4422632Sstever@eecs.umich.edu ' and lto at the same time, so lto is being disabled. To force' + 4438268Ssteve.reinhardt@amd.com ' lto on anyway, use the --force-lto option. That will disable' + 4448268Ssteve.reinhardt@amd.com ' partial linking.' + 4458268Ssteve.reinhardt@amd.com termcap.Normal) 4468268Ssteve.reinhardt@amd.com disable_lto = True 4473718Sstever@eecs.umich.edu 4482634Sstever@eecs.umich.edu # Add the appropriate Link-Time Optimization (LTO) flags 4492634Sstever@eecs.umich.edu # unless LTO is explicitly turned off. Note that these flags 4505863Snate@binkert.org # are only used by the fast target. 4512638Sstever@eecs.umich.edu if not disable_lto: 4528268Ssteve.reinhardt@amd.com # Pass the LTO flag when compiling to produce GIMPLE 4532632Sstever@eecs.umich.edu # output, we merely create the flags here and only append 4542632Sstever@eecs.umich.edu # them later 4552632Sstever@eecs.umich.edu main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 4562632Sstever@eecs.umich.edu 4572632Sstever@eecs.umich.edu # Use the same amount of jobs for LTO as we are running 4581858SN/A # scons with 4593716Sstever@eecs.umich.edu main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 4602638Sstever@eecs.umich.edu 4612638Sstever@eecs.umich.edu main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 4622638Sstever@eecs.umich.edu '-fno-builtin-realloc', '-fno-builtin-free']) 4632638Sstever@eecs.umich.edu 4642638Sstever@eecs.umich.edu # The address sanitizer is available for gcc >= 4.8 4652638Sstever@eecs.umich.edu if GetOption('with_asan'): 4662638Sstever@eecs.umich.edu if GetOption('with_ubsan') and \ 4675863Snate@binkert.org compareVersions(main['GCC_VERSION'], '4.9') >= 0: 4685863Snate@binkert.org main.Append(CCFLAGS=['-fsanitize=address,undefined', 4695863Snate@binkert.org '-fno-omit-frame-pointer'], 470955SN/A LINKFLAGS='-fsanitize=address,undefined') 4715341Sstever@gmail.com else: 4725341Sstever@gmail.com main.Append(CCFLAGS=['-fsanitize=address', 4735863Snate@binkert.org '-fno-omit-frame-pointer'], 4747756SAli.Saidi@ARM.com LINKFLAGS='-fsanitize=address') 4755341Sstever@gmail.com # Only gcc >= 4.9 supports UBSan, so check both the version 4766121Snate@binkert.org # and the command-line option before adding the compiler and 4774494Ssaidi@eecs.umich.edu # linker flags. 4786121Snate@binkert.org elif GetOption('with_ubsan') and \ 4791105SN/A compareVersions(main['GCC_VERSION'], '4.9') >= 0: 4802667Sstever@eecs.umich.edu main.Append(CCFLAGS='-fsanitize=undefined') 4812667Sstever@eecs.umich.edu main.Append(LINKFLAGS='-fsanitize=undefined') 4822667Sstever@eecs.umich.edu 4832667Sstever@eecs.umich.eduelif main['CLANG']: 4846121Snate@binkert.org # Check for a supported version of clang, >= 3.1 is needed to 4852667Sstever@eecs.umich.edu # support similar features as gcc 4.8. See 4865341Sstever@gmail.com # http://clang.llvm.org/cxx_status.html for details 4875863Snate@binkert.org clang_version_re = re.compile(".* version (\d+\.\d+)") 4885341Sstever@gmail.com clang_version_match = clang_version_re.search(CXX_version) 4895341Sstever@gmail.com if (clang_version_match): 4905341Sstever@gmail.com clang_version = clang_version_match.groups()[0] 4918120Sgblack@eecs.umich.edu if compareVersions(clang_version, "3.1") < 0: 4925341Sstever@gmail.com print('Error: clang version 3.1 or newer required.') 4938120Sgblack@eecs.umich.edu print(' Installed version:', clang_version) 4945341Sstever@gmail.com Exit(1) 4958120Sgblack@eecs.umich.edu else: 4966121Snate@binkert.org print('Error: Unable to determine clang version.') 4976121Snate@binkert.org Exit(1) 4988980Ssteve.reinhardt@amd.com 4999396Sandreas.hansson@arm.com # clang has a few additional warnings that we disable, extraneous 5005397Ssaidi@eecs.umich.edu # parantheses are allowed due to Ruby's printing of the AST, 5015397Ssaidi@eecs.umich.edu # finally self assignments are allowed as the generated CPU code 5027727SAli.Saidi@ARM.com # is relying on this 5038268Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-Wno-parentheses', 5046168Snate@binkert.org '-Wno-self-assign', 5055341Sstever@gmail.com # Some versions of libstdc++ (4.8?) seem to 5068120Sgblack@eecs.umich.edu # use struct hash and class hash 5078120Sgblack@eecs.umich.edu # interchangeably. 5088120Sgblack@eecs.umich.edu '-Wno-mismatched-tags', 5096814Sgblack@eecs.umich.edu ]) 5105863Snate@binkert.org 5118120Sgblack@eecs.umich.edu main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 5125341Sstever@gmail.com 5135863Snate@binkert.org # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 5148268Ssteve.reinhardt@amd.com # opposed to libstdc++, as the later is dated. 5156121Snate@binkert.org if sys.platform == "darwin": 5166121Snate@binkert.org main.Append(CXXFLAGS=['-stdlib=libc++']) 5178268Ssteve.reinhardt@amd.com main.Append(LIBS=['c++']) 5185742Snate@binkert.org 5195742Snate@binkert.org # On FreeBSD we need libthr. 5205341Sstever@gmail.com if sys.platform.startswith('freebsd'): 5215742Snate@binkert.org main.Append(LIBS=['thr']) 5225742Snate@binkert.org 5235341Sstever@gmail.com # We require clang >= 3.1, so there is no need to check any 5246017Snate@binkert.org # versions here. 5256121Snate@binkert.org if GetOption('with_ubsan'): 5266017Snate@binkert.org if GetOption('with_asan'): 5277816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-fsanitize=address,undefined', 5287756SAli.Saidi@ARM.com '-fno-omit-frame-pointer'], 5297756SAli.Saidi@ARM.com LINKFLAGS='-fsanitize=address,undefined') 5307756SAli.Saidi@ARM.com else: 5317756SAli.Saidi@ARM.com main.Append(CCFLAGS='-fsanitize=undefined', 5327756SAli.Saidi@ARM.com LINKFLAGS='-fsanitize=undefined') 5337756SAli.Saidi@ARM.com 5347756SAli.Saidi@ARM.com elif GetOption('with_asan'): 5357756SAli.Saidi@ARM.com main.Append(CCFLAGS=['-fsanitize=address', 5367816Ssteve.reinhardt@amd.com '-fno-omit-frame-pointer'], 5377816Ssteve.reinhardt@amd.com LINKFLAGS='-fsanitize=address') 5387816Ssteve.reinhardt@amd.com 5397816Ssteve.reinhardt@amd.comelse: 5407816Ssteve.reinhardt@amd.com print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 5417816Ssteve.reinhardt@amd.com print("Don't know what compiler options to use for your compiler.") 5427816Ssteve.reinhardt@amd.com print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 5437816Ssteve.reinhardt@amd.com print(termcap.Yellow + ' version:' + termcap.Normal, end=' ') 5447816Ssteve.reinhardt@amd.com if not CXX_version: 5457816Ssteve.reinhardt@amd.com print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 5467756SAli.Saidi@ARM.com termcap.Normal) 5477816Ssteve.reinhardt@amd.com else: 5487816Ssteve.reinhardt@amd.com print(CXX_version.replace('\n', '<nl>')) 5497816Ssteve.reinhardt@amd.com print(" If you're trying to use a compiler other than GCC") 5507816Ssteve.reinhardt@amd.com print(" or clang, there appears to be something wrong with your") 5517816Ssteve.reinhardt@amd.com print(" environment.") 5527816Ssteve.reinhardt@amd.com print(" ") 5537816Ssteve.reinhardt@amd.com print(" If you are trying to use a compiler other than those listed") 5547816Ssteve.reinhardt@amd.com print(" above you will need to ease fix SConstruct and ") 5557816Ssteve.reinhardt@amd.com print(" src/SConscript to support that compiler.") 5567816Ssteve.reinhardt@amd.com Exit(1) 5577816Ssteve.reinhardt@amd.com 5587816Ssteve.reinhardt@amd.com# Set up common yacc/bison flags (needed for Ruby) 5597816Ssteve.reinhardt@amd.commain['YACCFLAGS'] = '-d' 5607816Ssteve.reinhardt@amd.commain['YACCHXXFILESUFFIX'] = '.hh' 5617816Ssteve.reinhardt@amd.com 5627816Ssteve.reinhardt@amd.com# Do this after we save setting back, or else we'll tack on an 5637816Ssteve.reinhardt@amd.com# extra 'qdo' every time we run scons. 5647816Ssteve.reinhardt@amd.comif main['BATCH']: 5657816Ssteve.reinhardt@amd.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5667816Ssteve.reinhardt@amd.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5677816Ssteve.reinhardt@amd.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5687816Ssteve.reinhardt@amd.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5697816Ssteve.reinhardt@amd.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5707816Ssteve.reinhardt@amd.com 5717816Ssteve.reinhardt@amd.comif sys.platform == 'cygwin': 5727816Ssteve.reinhardt@amd.com # cygwin has some header file issues... 5737816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 5747816Ssteve.reinhardt@amd.com 5757816Ssteve.reinhardt@amd.com# Check for the protobuf compiler 5767816Ssteve.reinhardt@amd.comprotoc_version = readCommand([main['PROTOC'], '--version'], 5777816Ssteve.reinhardt@amd.com exception='').split() 5787816Ssteve.reinhardt@amd.com 5797816Ssteve.reinhardt@amd.com# First two words should be "libprotoc x.y.z" 5807816Ssteve.reinhardt@amd.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 5817816Ssteve.reinhardt@amd.com print(termcap.Yellow + termcap.Bold + 5827816Ssteve.reinhardt@amd.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + 5837816Ssteve.reinhardt@amd.com ' Please install protobuf-compiler for tracing support.' + 5847816Ssteve.reinhardt@amd.com termcap.Normal) 5857816Ssteve.reinhardt@amd.com main['PROTOC'] = False 5867816Ssteve.reinhardt@amd.comelse: 5877816Ssteve.reinhardt@amd.com # Based on the availability of the compress stream wrappers, 5887816Ssteve.reinhardt@amd.com # require 2.1.0 5897816Ssteve.reinhardt@amd.com min_protoc_version = '2.1.0' 5907816Ssteve.reinhardt@amd.com if compareVersions(protoc_version[1], min_protoc_version) < 0: 5917816Ssteve.reinhardt@amd.com print(termcap.Yellow + termcap.Bold + 5927816Ssteve.reinhardt@amd.com 'Warning: protoc version', min_protoc_version, 5937816Ssteve.reinhardt@amd.com 'or newer required.\n' + 5947816Ssteve.reinhardt@amd.com ' Installed version:', protoc_version[1], 5957816Ssteve.reinhardt@amd.com termcap.Normal) 5967816Ssteve.reinhardt@amd.com main['PROTOC'] = False 5977816Ssteve.reinhardt@amd.com else: 5987816Ssteve.reinhardt@amd.com # Attempt to determine the appropriate include path and 5997816Ssteve.reinhardt@amd.com # library path using pkg-config, that means we also need to 6007816Ssteve.reinhardt@amd.com # check for pkg-config. Note that it is possible to use 6017816Ssteve.reinhardt@amd.com # protobuf without the involvement of pkg-config. Later on we 6027816Ssteve.reinhardt@amd.com # check go a library config check and at that point the test 6037816Ssteve.reinhardt@amd.com # will fail if libprotobuf cannot be found. 6047816Ssteve.reinhardt@amd.com if readCommand(['pkg-config', '--version'], exception=''): 6057816Ssteve.reinhardt@amd.com try: 6067816Ssteve.reinhardt@amd.com # Attempt to establish what linking flags to add for protobuf 6077816Ssteve.reinhardt@amd.com # using pkg-config 6088947Sandreas.hansson@arm.com main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 6098947Sandreas.hansson@arm.com except: 6107756SAli.Saidi@ARM.com print(termcap.Yellow + termcap.Bold + 6118120Sgblack@eecs.umich.edu 'Warning: pkg-config could not get protobuf flags.' + 6127756SAli.Saidi@ARM.com termcap.Normal) 6137756SAli.Saidi@ARM.com 6147756SAli.Saidi@ARM.com 6157756SAli.Saidi@ARM.com# Check for 'timeout' from GNU coreutils. If present, regressions will 6167816Ssteve.reinhardt@amd.com# be run with a time limit. We require version 8.13 since we rely on 6177816Ssteve.reinhardt@amd.com# support for the '--foreground' option. 6187816Ssteve.reinhardt@amd.comif sys.platform.startswith('freebsd'): 6197816Ssteve.reinhardt@amd.com timeout_lines = readCommand(['gtimeout', '--version'], 6207816Ssteve.reinhardt@amd.com exception='').splitlines() 6217816Ssteve.reinhardt@amd.comelse: 6227816Ssteve.reinhardt@amd.com timeout_lines = readCommand(['timeout', '--version'], 6237816Ssteve.reinhardt@amd.com exception='').splitlines() 6247816Ssteve.reinhardt@amd.com# Get the first line and tokenize it 6257816Ssteve.reinhardt@amd.comtimeout_version = timeout_lines[0].split() if timeout_lines else [] 6267756SAli.Saidi@ARM.commain['TIMEOUT'] = timeout_version and \ 6277756SAli.Saidi@ARM.com compareVersions(timeout_version[-1], '8.13') >= 0 6289227Sandreas.hansson@arm.com 6299227Sandreas.hansson@arm.com# Add a custom Check function to test for structure members. 6309227Sandreas.hansson@arm.comdef CheckMember(context, include, decl, member, include_quotes="<>"): 6319227Sandreas.hansson@arm.com context.Message("Checking for member %s in %s..." % 6329590Sandreas@sandberg.pp.se (member, decl)) 6339590Sandreas@sandberg.pp.se text = """ 6349590Sandreas@sandberg.pp.se#include %(header)s 6359590Sandreas@sandberg.pp.seint main(){ 6369590Sandreas@sandberg.pp.se %(decl)s test; 6379590Sandreas@sandberg.pp.se (void)test.%(member)s; 6386654Snate@binkert.org return 0; 6396654Snate@binkert.org}; 6405871Snate@binkert.org""" % { "header" : include_quotes[0] + include + include_quotes[1], 6416121Snate@binkert.org "decl" : decl, 6428946Sandreas.hansson@arm.com "member" : member, 6439419Sandreas.hansson@arm.com } 6443940Ssaidi@eecs.umich.edu 6453918Ssaidi@eecs.umich.edu ret = context.TryCompile(text, extension=".cc") 6463918Ssaidi@eecs.umich.edu context.Result(ret) 6471858SN/A return ret 6489556Sandreas.hansson@arm.com 6499556Sandreas.hansson@arm.com# Platform-specific configuration. Note again that we assume that all 6509556Sandreas.hansson@arm.com# builds under a given build root run on the same host platform. 6519556Sandreas.hansson@arm.comconf = Configure(main, 65211294Sandreas.hansson@arm.com conf_dir = joinpath(build_root, '.scons_config'), 65311294Sandreas.hansson@arm.com log_file = joinpath(build_root, 'scons_config.log'), 65411294Sandreas.hansson@arm.com custom_tests = { 65511294Sandreas.hansson@arm.com 'CheckMember' : CheckMember, 65610878Sandreas.hansson@arm.com }) 65710878Sandreas.hansson@arm.com 6589556Sandreas.hansson@arm.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6599556Sandreas.hansson@arm.comtry: 6609556Sandreas.hansson@arm.com import platform 6619556Sandreas.hansson@arm.com uname = platform.uname() 6629556Sandreas.hansson@arm.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6639556Sandreas.hansson@arm.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6649556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-arch', 'x86_64']) 6659556Sandreas.hansson@arm.com main.Append(CFLAGS=['-arch', 'x86_64']) 6669556Sandreas.hansson@arm.com main.Append(LINKFLAGS=['-arch', 'x86_64']) 6679556Sandreas.hansson@arm.com main.Append(ASFLAGS=['-arch', 'x86_64']) 6689556Sandreas.hansson@arm.comexcept: 6699556Sandreas.hansson@arm.com pass 6709556Sandreas.hansson@arm.com 6719556Sandreas.hansson@arm.com# Recent versions of scons substitute a "Null" object for Configure() 6729556Sandreas.hansson@arm.com# when configuration isn't necessary, e.g., if the "--help" option is 6739556Sandreas.hansson@arm.com# present. Unfortuantely this Null object always returns false, 6749556Sandreas.hansson@arm.com# breaking all our configuration checks. We replace it with our own 6759556Sandreas.hansson@arm.com# more optimistic null object that returns True instead. 6769556Sandreas.hansson@arm.comif not conf: 6776121Snate@binkert.org def NullCheck(*args, **kwargs): 67811500Sandreas.hansson@arm.com return True 67910238Sandreas.hansson@arm.com 68010878Sandreas.hansson@arm.com class NullConf: 6819420Sandreas.hansson@arm.com def __init__(self, env): 68211500Sandreas.hansson@arm.com self.env = env 68311500Sandreas.hansson@arm.com def Finish(self): 6849420Sandreas.hansson@arm.com return self.env 6859420Sandreas.hansson@arm.com def __getattr__(self, mname): 6869420Sandreas.hansson@arm.com return NullCheck 6879420Sandreas.hansson@arm.com 6889420Sandreas.hansson@arm.com conf = NullConf(main) 68910264Sandreas.hansson@arm.com 69010264Sandreas.hansson@arm.com# Cache build files in the supplied directory. 69110264Sandreas.hansson@arm.comif main['M5_BUILD_CACHE']: 69210264Sandreas.hansson@arm.com print('Using build cache located at', main['M5_BUILD_CACHE']) 69311500Sandreas.hansson@arm.com CacheDir(main['M5_BUILD_CACHE']) 69411500Sandreas.hansson@arm.com 69510264Sandreas.hansson@arm.commain['USE_PYTHON'] = not GetOption('without_python') 69611500Sandreas.hansson@arm.comif main['USE_PYTHON']: 69711500Sandreas.hansson@arm.com # Find Python include and library directories for embedding the 69811500Sandreas.hansson@arm.com # interpreter. We rely on python-config to resolve the appropriate 69911500Sandreas.hansson@arm.com # includes and linker flags. ParseConfig does not seem to understand 70010866Sandreas.hansson@arm.com # the more exotic linker flags such as -Xlinker and -export-dynamic so 70111500Sandreas.hansson@arm.com # we add them explicitly below. If you want to link in an alternate 70211500Sandreas.hansson@arm.com # version of python, see above for instructions on how to invoke 70311500Sandreas.hansson@arm.com # scons with the appropriate PATH set. 70411500Sandreas.hansson@arm.com # 70511500Sandreas.hansson@arm.com # First we check if python2-config exists, else we use python-config 70611500Sandreas.hansson@arm.com python_config = readCommand(['which', 'python2-config'], 70711500Sandreas.hansson@arm.com exception='').strip() 70810264Sandreas.hansson@arm.com if not os.path.exists(python_config): 70910457Sandreas.hansson@arm.com python_config = readCommand(['which', 'python-config'], 71010457Sandreas.hansson@arm.com exception='').strip() 71110457Sandreas.hansson@arm.com py_includes = readCommand([python_config, '--includes'], 71210457Sandreas.hansson@arm.com exception='').split() 71310457Sandreas.hansson@arm.com # Strip the -I from the include folders before adding them to the 71410457Sandreas.hansson@arm.com # CPPPATH 71510457Sandreas.hansson@arm.com main.Append(CPPPATH=map(lambda inc: inc[2:], py_includes)) 71610457Sandreas.hansson@arm.com 71710457Sandreas.hansson@arm.com # Read the linker flags and split them into libraries and other link 71810238Sandreas.hansson@arm.com # flags. The libraries are added later through the call the CheckLib. 71910238Sandreas.hansson@arm.com py_ld_flags = readCommand([python_config, '--ldflags'], 72010238Sandreas.hansson@arm.com exception='').split() 72110238Sandreas.hansson@arm.com py_libs = [] 72210238Sandreas.hansson@arm.com for lib in py_ld_flags: 72310238Sandreas.hansson@arm.com if not lib.startswith('-l'): 72410416Sandreas.hansson@arm.com main.Append(LINKFLAGS=[lib]) 72510238Sandreas.hansson@arm.com else: 7269227Sandreas.hansson@arm.com lib = lib[2:] 72710238Sandreas.hansson@arm.com if lib not in py_libs: 72810416Sandreas.hansson@arm.com py_libs.append(lib) 72910416Sandreas.hansson@arm.com 7309227Sandreas.hansson@arm.com # verify that this stuff works 7319590Sandreas@sandberg.pp.se if not conf.CheckHeader('Python.h', '<>'): 7329590Sandreas@sandberg.pp.se print("Error: Check failed for Python.h header in", py_includes) 7339590Sandreas@sandberg.pp.se print("Two possible reasons:") 73411497SMatteo.Andreozzi@arm.com print("1. Python headers are not installed (You can install the " 73511497SMatteo.Andreozzi@arm.com "package python-dev on Ubuntu and RedHat)") 73611497SMatteo.Andreozzi@arm.com print("2. SCons is using a wrong C compiler. This can happen if " 73711497SMatteo.Andreozzi@arm.com "CC has the wrong value.") 7388737Skoansin.tan@gmail.com print("CC = %s" % main['CC']) 73910878Sandreas.hansson@arm.com Exit(1) 74011500Sandreas.hansson@arm.com 7419420Sandreas.hansson@arm.com for lib in py_libs: 7428737Skoansin.tan@gmail.com if not conf.CheckLib(lib): 74310106SMitch.Hayenga@arm.com print("Error: can't find library %s required by python" % lib) 7448737Skoansin.tan@gmail.com Exit(1) 7458737Skoansin.tan@gmail.com 74610878Sandreas.hansson@arm.com# On Solaris you need to use libsocket for socket ops 74710878Sandreas.hansson@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7488737Skoansin.tan@gmail.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7498737Skoansin.tan@gmail.com print("Can't find library with socket calls (e.g. accept())") 7508737Skoansin.tan@gmail.com Exit(1) 7518737Skoansin.tan@gmail.com 7528737Skoansin.tan@gmail.com# Check for zlib. If the check passes, libz will be automatically 7538737Skoansin.tan@gmail.com# added to the LIBS environment variable. 75411294Sandreas.hansson@arm.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7559556Sandreas.hansson@arm.com print('Error: did not find needed zlib compression library ' 7569556Sandreas.hansson@arm.com 'and/or zlib.h header file.') 7579556Sandreas.hansson@arm.com print(' Please install zlib and try again.') 75811294Sandreas.hansson@arm.com Exit(1) 75910278SAndreas.Sandberg@ARM.com 76010278SAndreas.Sandberg@ARM.com# If we have the protobuf compiler, also make sure we have the 76110278SAndreas.Sandberg@ARM.com# development libraries. If the check passes, libprotobuf will be 76210278SAndreas.Sandberg@ARM.com# automatically added to the LIBS environment variable. After 76310278SAndreas.Sandberg@ARM.com# this, we can use the HAVE_PROTOBUF flag to determine if we have 76410278SAndreas.Sandberg@ARM.com# got both protoc and libprotobuf available. 7659556Sandreas.hansson@arm.commain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 7669590Sandreas@sandberg.pp.se conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 7679590Sandreas@sandberg.pp.se 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 7689420Sandreas.hansson@arm.com 7699846Sandreas.hansson@arm.com# Valgrind gets much less confused if you tell it when you're using 7709846Sandreas.hansson@arm.com# alternative stacks. 7719846Sandreas.hansson@arm.commain['HAVE_VALGRIND'] = conf.CheckCHeader('valgrind/valgrind.h') 7729846Sandreas.hansson@arm.com 7738946Sandreas.hansson@arm.com# If we have the compiler but not the library, print another warning. 7743918Ssaidi@eecs.umich.eduif main['PROTOC'] and not main['HAVE_PROTOBUF']: 7759068SAli.Saidi@ARM.com print(termcap.Yellow + termcap.Bold + 7769068SAli.Saidi@ARM.com 'Warning: did not find protocol buffer library and/or headers.\n' + 7779068SAli.Saidi@ARM.com ' Please install libprotobuf-dev for tracing support.' + 7789068SAli.Saidi@ARM.com termcap.Normal) 7799068SAli.Saidi@ARM.com 7809068SAli.Saidi@ARM.com# Check for librt. 7819068SAli.Saidi@ARM.comhave_posix_clock = \ 7829068SAli.Saidi@ARM.com conf.CheckLibWithHeader(None, 'time.h', 'C', 7839068SAli.Saidi@ARM.com 'clock_nanosleep(0,0,NULL,NULL);') or \ 7849419Sandreas.hansson@arm.com conf.CheckLibWithHeader('rt', 'time.h', 'C', 7859068SAli.Saidi@ARM.com 'clock_nanosleep(0,0,NULL,NULL);') 7869068SAli.Saidi@ARM.com 7879068SAli.Saidi@ARM.comhave_posix_timers = \ 7889068SAli.Saidi@ARM.com conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', 7899068SAli.Saidi@ARM.com 'timer_create(CLOCK_MONOTONIC, NULL, NULL);') 7909068SAli.Saidi@ARM.com 7913918Ssaidi@eecs.umich.eduif not GetOption('without_tcmalloc'): 7923918Ssaidi@eecs.umich.edu if conf.CheckLib('tcmalloc'): 7936157Snate@binkert.org main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 7946157Snate@binkert.org elif conf.CheckLib('tcmalloc_minimal'): 7956157Snate@binkert.org main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 7966157Snate@binkert.org else: 7975397Ssaidi@eecs.umich.edu print(termcap.Yellow + termcap.Bold + 7985397Ssaidi@eecs.umich.edu "You can get a 12% performance improvement by " 7996121Snate@binkert.org "installing tcmalloc (libgoogle-perftools-dev package " 8006121Snate@binkert.org "on Ubuntu or RedHat)." + termcap.Normal) 8016121Snate@binkert.org 8026121Snate@binkert.org 8036121Snate@binkert.org# Detect back trace implementations. The last implementation in the 8046121Snate@binkert.org# list will be used by default. 8055397Ssaidi@eecs.umich.edubacktrace_impls = [ "none" ] 8061851SN/A 8071851SN/Abacktrace_checker = 'char temp;' + \ 8087739Sgblack@eecs.umich.edu ' backtrace_symbols_fd((void*)&temp, 0, 0);' 809955SN/Aif conf.CheckLibWithHeader(None, 'execinfo.h', 'C', backtrace_checker): 8109396Sandreas.hansson@arm.com backtrace_impls.append("glibc") 8119396Sandreas.hansson@arm.comelif conf.CheckLibWithHeader('execinfo', 'execinfo.h', 'C', 8129396Sandreas.hansson@arm.com backtrace_checker): 8139396Sandreas.hansson@arm.com # NetBSD and FreeBSD need libexecinfo. 8149396Sandreas.hansson@arm.com backtrace_impls.append("glibc") 8159396Sandreas.hansson@arm.com main.Append(LIBS=['execinfo']) 8169396Sandreas.hansson@arm.com 8179396Sandreas.hansson@arm.comif backtrace_impls[-1] == "none": 8189396Sandreas.hansson@arm.com default_backtrace_impl = "none" 8199396Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 8209396Sandreas.hansson@arm.com "No suitable back trace implementation found." + 8219396Sandreas.hansson@arm.com termcap.Normal) 8229396Sandreas.hansson@arm.com 8239396Sandreas.hansson@arm.comif not have_posix_clock: 8249396Sandreas.hansson@arm.com print("Can't find library for POSIX clocks.") 8259396Sandreas.hansson@arm.com 8269477Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control) 8279477Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 8289477Sandreas.hansson@arm.comif not have_fenv: 8299477Sandreas.hansson@arm.com print("Warning: Header file <fenv.h> not found.") 8309477Sandreas.hansson@arm.com print(" This host has no IEEE FP rounding mode control.") 8319477Sandreas.hansson@arm.com 8329477Sandreas.hansson@arm.com# Check for <png.h> (libpng library needed if wanting to dump 8339477Sandreas.hansson@arm.com# frame buffer image in png format) 8349477Sandreas.hansson@arm.comhave_png = conf.CheckHeader('png.h', '<>') 8359477Sandreas.hansson@arm.comif not have_png: 8369477Sandreas.hansson@arm.com print("Warning: Header file <png.h> not found.") 8379477Sandreas.hansson@arm.com print(" This host has no libpng library.") 8389477Sandreas.hansson@arm.com print(" Disabling support for PNG framebuffers.") 8399477Sandreas.hansson@arm.com 8409477Sandreas.hansson@arm.com# Check if we should enable KVM-based hardware virtualization. The API 8419477Sandreas.hansson@arm.com# we rely on exists since version 2.6.36 of the kernel, but somehow 8429477Sandreas.hansson@arm.com# the KVM_API_VERSION does not reflect the change. We test for one of 8439477Sandreas.hansson@arm.com# the types as a fall back. 8449477Sandreas.hansson@arm.comhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 8459477Sandreas.hansson@arm.comif not have_kvm: 8469477Sandreas.hansson@arm.com print("Info: Compatible header file <linux/kvm.h> not found, " 8479477Sandreas.hansson@arm.com "disabling KVM support.") 8489396Sandreas.hansson@arm.com 8493053Sstever@eecs.umich.edu# Check if the TUN/TAP driver is available. 8506121Snate@binkert.orghave_tuntap = conf.CheckHeader('linux/if_tun.h', '<>') 8513053Sstever@eecs.umich.eduif not have_tuntap: 8523053Sstever@eecs.umich.edu print("Info: Compatible header file <linux/if_tun.h> not found.") 8533053Sstever@eecs.umich.edu 8543053Sstever@eecs.umich.edu# x86 needs support for xsave. We test for the structure here since we 8553053Sstever@eecs.umich.edu# won't be able to run new tests by the time we know which ISA we're 8569072Sandreas.hansson@arm.com# targeting. 8573053Sstever@eecs.umich.eduhave_kvm_xsave = conf.CheckTypeSize('struct kvm_xsave', 8584742Sstever@eecs.umich.edu '#include <linux/kvm.h>') != 0 8594742Sstever@eecs.umich.edu 8603053Sstever@eecs.umich.edu# Check if the requested target ISA is compatible with the host 8613053Sstever@eecs.umich.edudef is_isa_kvm_compatible(isa): 8623053Sstever@eecs.umich.edu try: 86310181SCurtis.Dunham@arm.com import platform 8646654Snate@binkert.org host_isa = platform.machine() 8653053Sstever@eecs.umich.edu except: 8663053Sstever@eecs.umich.edu print("Warning: Failed to determine host ISA.") 8673053Sstever@eecs.umich.edu return False 8683053Sstever@eecs.umich.edu 86910425Sandreas.hansson@arm.com if not have_posix_timers: 87010425Sandreas.hansson@arm.com print("Warning: Can not enable KVM, host seems to lack support " 87110425Sandreas.hansson@arm.com "for POSIX timers") 87210425Sandreas.hansson@arm.com return False 87310425Sandreas.hansson@arm.com 87410425Sandreas.hansson@arm.com if isa == "arm": 87510425Sandreas.hansson@arm.com return host_isa in ( "armv7l", "aarch64" ) 87610425Sandreas.hansson@arm.com elif isa == "x86": 87710425Sandreas.hansson@arm.com if host_isa != "x86_64": 87810425Sandreas.hansson@arm.com return False 87910425Sandreas.hansson@arm.com 8802667Sstever@eecs.umich.edu if not have_kvm_xsave: 8814554Sbinkertn@umich.edu print("KVM on x86 requires xsave support in kernel headers.") 8826121Snate@binkert.org return False 8832667Sstever@eecs.umich.edu 88410710Sandreas.hansson@arm.com return True 88510710Sandreas.hansson@arm.com else: 88610710Sandreas.hansson@arm.com return False 88710710Sandreas.hansson@arm.com 88810710Sandreas.hansson@arm.com 88910710Sandreas.hansson@arm.com# Check if the exclude_host attribute is available. We want this to 89010710Sandreas.hansson@arm.com# get accurate instruction counts in KVM. 89110710Sandreas.hansson@arm.commain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember( 89210710Sandreas.hansson@arm.com 'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host') 89310384SCurtis.Dunham@arm.com 8944554Sbinkertn@umich.edu 8954554Sbinkertn@umich.edu###################################################################### 8964554Sbinkertn@umich.edu# 8976121Snate@binkert.org# Finish the configuration 8984554Sbinkertn@umich.edu# 8994554Sbinkertn@umich.edumain = conf.Finish() 9004554Sbinkertn@umich.edu 9014781Snate@binkert.org###################################################################### 9024554Sbinkertn@umich.edu# 9034554Sbinkertn@umich.edu# Collect all non-global variables 9042667Sstever@eecs.umich.edu# 9054554Sbinkertn@umich.edu 9064554Sbinkertn@umich.edu# Define the universe of supported ISAs 9074554Sbinkertn@umich.eduall_isa_list = [ ] 9084554Sbinkertn@umich.eduall_gpu_isa_list = [ ] 9092667Sstever@eecs.umich.eduExport('all_isa_list') 9104554Sbinkertn@umich.eduExport('all_gpu_isa_list') 9112667Sstever@eecs.umich.edu 9124554Sbinkertn@umich.educlass CpuModel(object): 9136121Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 9142667Sstever@eecs.umich.edu know about a particular CPU model.''' 9159986Sandreas@sandberg.pp.se 9169986Sandreas@sandberg.pp.se # Dict of available CPU model objects. Accessible as CpuModel.dict. 9179986Sandreas@sandberg.pp.se dict = {} 9189986Sandreas@sandberg.pp.se 9199986Sandreas@sandberg.pp.se # Constructor. Automatically adds models to CpuModel.dict. 9209986Sandreas@sandberg.pp.se def __init__(self, name, default=False): 9219986Sandreas@sandberg.pp.se self.name = name # name of model 9229986Sandreas@sandberg.pp.se 9239986Sandreas@sandberg.pp.se # This cpu is enabled by default 9249986Sandreas@sandberg.pp.se self.default = default 9259986Sandreas@sandberg.pp.se 9269986Sandreas@sandberg.pp.se # Add self to dict 9279986Sandreas@sandberg.pp.se if name in CpuModel.dict: 9289986Sandreas@sandberg.pp.se raise AttributeError, "CpuModel '%s' already registered" % name 9299986Sandreas@sandberg.pp.se CpuModel.dict[name] = self 9309986Sandreas@sandberg.pp.se 9319986Sandreas@sandberg.pp.seExport('CpuModel') 9329986Sandreas@sandberg.pp.se 9339986Sandreas@sandberg.pp.se# Sticky variables get saved in the variables file so they persist from 9349986Sandreas@sandberg.pp.se# one invocation to the next (unless overridden, in which case the new 9352638Sstever@eecs.umich.edu# value becomes sticky). 9362638Sstever@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS) 9376121Snate@binkert.orgExport('sticky_vars') 9383716Sstever@eecs.umich.edu 9395522Snate@binkert.org# Sticky variables that should be exported 9409986Sandreas@sandberg.pp.seexport_vars = [] 9419986Sandreas@sandberg.pp.seExport('export_vars') 9429986Sandreas@sandberg.pp.se 9435522Snate@binkert.org# For Ruby 9445227Ssaidi@eecs.umich.eduall_protocols = [] 9455227Ssaidi@eecs.umich.eduExport('all_protocols') 9465227Ssaidi@eecs.umich.eduprotocol_dirs = [] 9475227Ssaidi@eecs.umich.eduExport('protocol_dirs') 9486654Snate@binkert.orgslicc_includes = [] 9496654Snate@binkert.orgExport('slicc_includes') 9507769SAli.Saidi@ARM.com 9517769SAli.Saidi@ARM.com# Walk the tree and execute all SConsopts scripts that wil add to the 9527769SAli.Saidi@ARM.com# above variables 9537769SAli.Saidi@ARM.comif GetOption('verbose'): 9545227Ssaidi@eecs.umich.edu print("Reading SConsopts") 9555227Ssaidi@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list: 9565227Ssaidi@eecs.umich.edu if not isdir(bdir): 9575204Sstever@gmail.com print("Error: directory '%s' does not exist" % bdir) 9585204Sstever@gmail.com Exit(1) 9595204Sstever@gmail.com for root, dirs, files in os.walk(bdir): 9605204Sstever@gmail.com if 'SConsopts' in files: 9615204Sstever@gmail.com if GetOption('verbose'): 9625204Sstever@gmail.com print("Reading", joinpath(root, 'SConsopts')) 9635204Sstever@gmail.com SConscript(joinpath(root, 'SConsopts')) 9645204Sstever@gmail.com 9655204Sstever@gmail.comall_isa_list.sort() 9665204Sstever@gmail.comall_gpu_isa_list.sort() 9675204Sstever@gmail.com 9685204Sstever@gmail.comsticky_vars.AddVariables( 9695204Sstever@gmail.com EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 9705204Sstever@gmail.com EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'hsail', all_gpu_isa_list), 9715204Sstever@gmail.com ListVariable('CPU_MODELS', 'CPU models', 9725204Sstever@gmail.com sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 9735204Sstever@gmail.com sorted(CpuModel.dict.keys())), 9746121Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 9755204Sstever@gmail.com False), 9767727SAli.Saidi@ARM.com BoolVariable('SS_COMPATIBLE_FP', 9777727SAli.Saidi@ARM.com 'Make floating-point results compatible with SimpleScalar', 9787727SAli.Saidi@ARM.com False), 9797727SAli.Saidi@ARM.com BoolVariable('USE_SSE2', 9807727SAli.Saidi@ARM.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 98110453SAndrew.Bardsley@arm.com False), 98210453SAndrew.Bardsley@arm.com BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 98310453SAndrew.Bardsley@arm.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 98410453SAndrew.Bardsley@arm.com BoolVariable('USE_PNG', 'Enable support for PNG images', have_png), 98510453SAndrew.Bardsley@arm.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', 98610453SAndrew.Bardsley@arm.com False), 98710453SAndrew.Bardsley@arm.com BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', 98810453SAndrew.Bardsley@arm.com have_kvm), 98910453SAndrew.Bardsley@arm.com BoolVariable('USE_TUNTAP', 99010453SAndrew.Bardsley@arm.com 'Enable using a tap device to bridge to the host network', 99110453SAndrew.Bardsley@arm.com have_tuntap), 99210160Sandreas.hansson@arm.com BoolVariable('BUILD_GPU', 'Build the compute-GPU model', False), 99310453SAndrew.Bardsley@arm.com EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 99410453SAndrew.Bardsley@arm.com all_protocols), 99510453SAndrew.Bardsley@arm.com EnumVariable('BACKTRACE_IMPL', 'Post-mortem dump implementation', 99610453SAndrew.Bardsley@arm.com backtrace_impls[-1], backtrace_impls) 99710453SAndrew.Bardsley@arm.com ) 99810453SAndrew.Bardsley@arm.com 99910453SAndrew.Bardsley@arm.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 100010453SAndrew.Bardsley@arm.comexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA', 10019812Sandreas.hansson@arm.com 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP', 100210453SAndrew.Bardsley@arm.com 'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_VALGRIND', 100310453SAndrew.Bardsley@arm.com 'HAVE_PERF_ATTR_EXCLUDE_HOST', 'USE_PNG'] 100410453SAndrew.Bardsley@arm.com 100510453SAndrew.Bardsley@arm.com################################################### 100610453SAndrew.Bardsley@arm.com# 100710453SAndrew.Bardsley@arm.com# Define a SCons builder for configuration flag headers. 100810453SAndrew.Bardsley@arm.com# 100910453SAndrew.Bardsley@arm.com################################################### 101010453SAndrew.Bardsley@arm.com 101110453SAndrew.Bardsley@arm.com# This function generates a config header file that #defines the 101210453SAndrew.Bardsley@arm.com# variable symbol to the current variable setting (0 or 1). The source 101310453SAndrew.Bardsley@arm.com# operands are the name of the variable and a Value node containing the 10147727SAli.Saidi@ARM.com# value of the variable. 101510453SAndrew.Bardsley@arm.comdef build_config_file(target, source, env): 101610453SAndrew.Bardsley@arm.com (variable, value) = [s.get_contents() for s in source] 101710453SAndrew.Bardsley@arm.com f = file(str(target[0]), 'w') 101810453SAndrew.Bardsley@arm.com print('#define', variable, value, file=f) 101910453SAndrew.Bardsley@arm.com f.close() 10203118Sstever@eecs.umich.edu return None 102110453SAndrew.Bardsley@arm.com 102210453SAndrew.Bardsley@arm.com# Combine the two functions into a scons Action object. 102310453SAndrew.Bardsley@arm.comconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 102410453SAndrew.Bardsley@arm.com 10253118Sstever@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 10263483Ssaidi@eecs.umich.edu# we're really doing. 10273494Ssaidi@eecs.umich.edudef config_emitter(target, source, env): 10283494Ssaidi@eecs.umich.edu # extract variable name from Builder arg 10293483Ssaidi@eecs.umich.edu variable = str(target[0]) 10303483Ssaidi@eecs.umich.edu # True target is config header file 10313483Ssaidi@eecs.umich.edu target = joinpath('config', variable.lower() + '.hh') 10323053Sstever@eecs.umich.edu val = env[variable] 10333053Sstever@eecs.umich.edu if isinstance(val, bool): 10343918Ssaidi@eecs.umich.edu # Force value to 0/1 10353053Sstever@eecs.umich.edu val = int(val) 10363053Sstever@eecs.umich.edu elif isinstance(val, str): 10373053Sstever@eecs.umich.edu val = '"' + val + '"' 10383053Sstever@eecs.umich.edu 10393053Sstever@eecs.umich.edu # Sources are variable name & value (packaged in SCons Value nodes) 10409396Sandreas.hansson@arm.com return ([target], [Value(variable), Value(val)]) 10419396Sandreas.hansson@arm.com 10429396Sandreas.hansson@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 10439396Sandreas.hansson@arm.com 10449396Sandreas.hansson@arm.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 10459396Sandreas.hansson@arm.com 10469396Sandreas.hansson@arm.com################################################### 10479396Sandreas.hansson@arm.com# 10489396Sandreas.hansson@arm.com# Builders for static and shared partially linked object files. 10499477Sandreas.hansson@arm.com# 10509396Sandreas.hansson@arm.com################################################### 10519477Sandreas.hansson@arm.com 10529477Sandreas.hansson@arm.compartial_static_builder = Builder(action=SCons.Defaults.LinkAction, 10539477Sandreas.hansson@arm.com src_suffix='$OBJSUFFIX', 10549477Sandreas.hansson@arm.com src_builder=['StaticObject', 'Object'], 10559396Sandreas.hansson@arm.com LINKFLAGS='$PLINKFLAGS', 10567840Snate@binkert.org LIBS='') 10577865Sgblack@eecs.umich.edu 10587865Sgblack@eecs.umich.edudef partial_shared_emitter(target, source, env): 10597865Sgblack@eecs.umich.edu for tgt in target: 10607865Sgblack@eecs.umich.edu tgt.attributes.shared = 1 10617865Sgblack@eecs.umich.edu return (target, source) 10627840Snate@binkert.orgpartial_shared_builder = Builder(action=SCons.Defaults.ShLinkAction, 10639900Sandreas@sandberg.pp.se emitter=partial_shared_emitter, 10649900Sandreas@sandberg.pp.se src_suffix='$SHOBJSUFFIX', 10659900Sandreas@sandberg.pp.se src_builder='SharedObject', 10669900Sandreas@sandberg.pp.se SHLINKFLAGS='$PSHLINKFLAGS', 106710456SCurtis.Dunham@arm.com LIBS='') 106810456SCurtis.Dunham@arm.com 106910456SCurtis.Dunham@arm.commain.Append(BUILDERS = { 'PartialShared' : partial_shared_builder, 107010456SCurtis.Dunham@arm.com 'PartialStatic' : partial_static_builder }) 107110456SCurtis.Dunham@arm.com 107210456SCurtis.Dunham@arm.com# builds in ext are shared across all configs in the build root. 107310456SCurtis.Dunham@arm.comext_dir = abspath(joinpath(str(main.root), 'ext')) 107410456SCurtis.Dunham@arm.comext_build_dirs = [] 107510456SCurtis.Dunham@arm.comfor root, dirs, files in os.walk(ext_dir): 107610456SCurtis.Dunham@arm.com if 'SConscript' in files: 10779045SAli.Saidi@ARM.com build_dir = os.path.relpath(root, ext_dir) 107811235Sandreas.sandberg@arm.com ext_build_dirs.append(build_dir) 107911235Sandreas.sandberg@arm.com main.SConscript(joinpath(root, 'SConscript'), 108011235Sandreas.sandberg@arm.com variant_dir=joinpath(build_root, build_dir)) 108111235Sandreas.sandberg@arm.com 108211235Sandreas.sandberg@arm.commain.Prepend(CPPPATH=Dir('ext/pybind11/include/')) 108311235Sandreas.sandberg@arm.com 108411235Sandreas.sandberg@arm.com################################################### 108511235Sandreas.sandberg@arm.com# 108611235Sandreas.sandberg@arm.com# This builder and wrapper method are used to set up a directory with 108711235Sandreas.sandberg@arm.com# switching headers. Those are headers which are in a generic location and 108811235Sandreas.sandberg@arm.com# that include more specific headers from a directory chosen at build time 108911235Sandreas.sandberg@arm.com# based on the current build settings. 109011235Sandreas.sandberg@arm.com# 109111235Sandreas.sandberg@arm.com################################################### 109211235Sandreas.sandberg@arm.com 10937840Snate@binkert.orgdef build_switching_header(target, source, env): 10947840Snate@binkert.org path = str(target[0]) 10957840Snate@binkert.org subdir = str(source[0]) 10961858SN/A dp, fp = os.path.split(path) 10971858SN/A dp = os.path.relpath(os.path.realpath(dp), 10981858SN/A os.path.realpath(env['BUILDDIR'])) 10991858SN/A with open(path, 'w') as hdr: 11001858SN/A print('#include "%s/%s/%s"' % (dp, subdir, fp), file=hdr) 11011858SN/A 11029903Sandreas.hansson@arm.comswitching_header_action = MakeAction(build_switching_header, 11039903Sandreas.hansson@arm.com Transform('GENERATE')) 11049903Sandreas.hansson@arm.com 11059903Sandreas.hansson@arm.comswitching_header_builder = Builder(action=switching_header_action, 110610841Sandreas.sandberg@arm.com source_factory=Value, 11079651SAndreas.Sandberg@ARM.com single_source=True) 11089903Sandreas.hansson@arm.com 11099651SAndreas.Sandberg@ARM.commain.Append(BUILDERS = { 'SwitchingHeader': switching_header_builder }) 11109651SAndreas.Sandberg@ARM.com 111110841Sandreas.sandberg@arm.comdef switching_headers(self, headers, source): 111210841Sandreas.sandberg@arm.com for header in headers: 111310841Sandreas.sandberg@arm.com self.SwitchingHeader(header, source) 111410841Sandreas.sandberg@arm.com 111510841Sandreas.sandberg@arm.commain.AddMethod(switching_headers, 'SwitchingHeaders') 111610841Sandreas.sandberg@arm.com 11179651SAndreas.Sandberg@ARM.com################################################### 11189651SAndreas.Sandberg@ARM.com# 11199651SAndreas.Sandberg@ARM.com# Define build environments for selected configurations. 11209651SAndreas.Sandberg@ARM.com# 11219651SAndreas.Sandberg@ARM.com################################################### 11229651SAndreas.Sandberg@ARM.com 11239651SAndreas.Sandberg@ARM.comfor variant_path in variant_paths: 11249651SAndreas.Sandberg@ARM.com if not GetOption('silent'): 11259651SAndreas.Sandberg@ARM.com print("Building in", variant_path) 112610841Sandreas.sandberg@arm.com 112710841Sandreas.sandberg@arm.com # Make a copy of the build-root environment to use for this config. 112810841Sandreas.sandberg@arm.com env = main.Clone() 112910841Sandreas.sandberg@arm.com env['BUILDDIR'] = variant_path 113010841Sandreas.sandberg@arm.com 113110841Sandreas.sandberg@arm.com # variant_dir is the tail component of build path, and is used to 113210860Sandreas.sandberg@arm.com # determine the build parameters (e.g., 'ALPHA_SE') 113310841Sandreas.sandberg@arm.com (build_root, variant_dir) = splitpath(variant_path) 113410841Sandreas.sandberg@arm.com 113510841Sandreas.sandberg@arm.com # Set env variables according to the build directory config. 113610841Sandreas.sandberg@arm.com sticky_vars.files = [] 113710841Sandreas.sandberg@arm.com # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 113810841Sandreas.sandberg@arm.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 113910841Sandreas.sandberg@arm.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 114010841Sandreas.sandberg@arm.com current_vars_file = joinpath(build_root, 'variables', variant_dir) 114110841Sandreas.sandberg@arm.com if isfile(current_vars_file): 114210841Sandreas.sandberg@arm.com sticky_vars.files.append(current_vars_file) 114310841Sandreas.sandberg@arm.com if not GetOption('silent'): 11449651SAndreas.Sandberg@ARM.com print("Using saved variables file %s" % current_vars_file) 11459651SAndreas.Sandberg@ARM.com elif variant_dir in ext_build_dirs: 11469986Sandreas@sandberg.pp.se # Things in ext are built without a variant directory. 11479986Sandreas@sandberg.pp.se continue 11489986Sandreas@sandberg.pp.se else: 11499986Sandreas@sandberg.pp.se # Build dir-specific variables file doesn't exist. 11509986Sandreas@sandberg.pp.se 11519986Sandreas@sandberg.pp.se # Make sure the directory is there so we can create it later 11525863Snate@binkert.org opt_dir = dirname(current_vars_file) 11535863Snate@binkert.org if not isdir(opt_dir): 11545863Snate@binkert.org mkdir(opt_dir) 11555863Snate@binkert.org 11566121Snate@binkert.org # Get default build variables from source tree. Variables are 11571858SN/A # normally determined by name of $VARIANT_DIR, but can be 11585863Snate@binkert.org # overridden by '--default=' arg on command line. 11595863Snate@binkert.org default = GetOption('default') 11605863Snate@binkert.org opts_dir = joinpath(main.root.abspath, 'build_opts') 11615863Snate@binkert.org if default: 11625863Snate@binkert.org default_vars_files = [joinpath(build_root, 'variables', default), 11632139SN/A joinpath(opts_dir, default)] 11644202Sbinkertn@umich.edu else: 116511308Santhony.gutierrez@amd.com default_vars_files = [joinpath(opts_dir, variant_dir)] 11664202Sbinkertn@umich.edu existing_files = filter(isfile, default_vars_files) 116711308Santhony.gutierrez@amd.com if existing_files: 11682139SN/A default_vars_file = existing_files[0] 11696994Snate@binkert.org sticky_vars.files.append(default_vars_file) 11706994Snate@binkert.org print("Variables file %s not found,\n using defaults in %s" 11716994Snate@binkert.org % (current_vars_file, default_vars_file)) 11726994Snate@binkert.org else: 11736994Snate@binkert.org print("Error: cannot find variables file %s or " 11746994Snate@binkert.org "default file(s) %s" 11756994Snate@binkert.org % (current_vars_file, ' or '.join(default_vars_files))) 11766994Snate@binkert.org Exit(1) 117710319SAndreas.Sandberg@ARM.com 11786994Snate@binkert.org # Apply current variable settings to env 11796994Snate@binkert.org sticky_vars.Update(env) 11806994Snate@binkert.org 11816994Snate@binkert.org help_texts["local_vars"] += \ 11826994Snate@binkert.org "Build variables for %s:\n" % variant_dir \ 11836994Snate@binkert.org + sticky_vars.GenerateHelpText(env) 11846994Snate@binkert.org 11856994Snate@binkert.org # Process variable settings. 11866994Snate@binkert.org 11876994Snate@binkert.org if not have_fenv and env['USE_FENV']: 11886994Snate@binkert.org print("Warning: <fenv.h> not available; " 11892155SN/A "forcing USE_FENV to False in", variant_dir + ".") 11905863Snate@binkert.org env['USE_FENV'] = False 11911869SN/A 11921869SN/A if not env['USE_FENV']: 11935863Snate@binkert.org print("Warning: No IEEE FP rounding mode control in", 11945863Snate@binkert.org variant_dir + ".") 11954202Sbinkertn@umich.edu print(" FP results may deviate slightly from other platforms.") 11966108Snate@binkert.org 11976108Snate@binkert.org if not have_png and env['USE_PNG']: 11986108Snate@binkert.org print("Warning: <png.h> not available; " 11996108Snate@binkert.org "forcing USE_PNG to False in", variant_dir + ".") 12009219Spower.jg@gmail.com env['USE_PNG'] = False 12019219Spower.jg@gmail.com 12029219Spower.jg@gmail.com if env['USE_PNG']: 12039219Spower.jg@gmail.com env.Append(LIBS=['png']) 12049219Spower.jg@gmail.com 12059219Spower.jg@gmail.com if env['EFENCE']: 12069219Spower.jg@gmail.com env.Append(LIBS=['efence']) 12079219Spower.jg@gmail.com 12084202Sbinkertn@umich.edu if env['USE_KVM']: 12095863Snate@binkert.org if not have_kvm: 121010135SCurtis.Dunham@arm.com print("Warning: Can not enable KVM, host seems to " 12118474Sgblack@eecs.umich.edu "lack KVM support") 12125742Snate@binkert.org env['USE_KVM'] = False 12138268Ssteve.reinhardt@amd.com elif not is_isa_kvm_compatible(env['TARGET_ISA']): 12148268Ssteve.reinhardt@amd.com print("Info: KVM support disabled due to unsupported host and " 12158268Ssteve.reinhardt@amd.com "target ISA combination") 12165742Snate@binkert.org env['USE_KVM'] = False 12175341Sstever@gmail.com 12188474Sgblack@eecs.umich.edu if env['USE_TUNTAP']: 12198474Sgblack@eecs.umich.edu if not have_tuntap: 12205342Sstever@gmail.com print("Warning: Can't connect EtherTap with a tap device.") 12214202Sbinkertn@umich.edu env['USE_TUNTAP'] = False 12224202Sbinkertn@umich.edu 122311308Santhony.gutierrez@amd.com if env['BUILD_GPU']: 12244202Sbinkertn@umich.edu env.Append(CPPDEFINES=['BUILD_GPU']) 12255863Snate@binkert.org 12265863Snate@binkert.org # Warn about missing optional functionality 122711308Santhony.gutierrez@amd.com if env['USE_KVM']: 12286994Snate@binkert.org if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']: 12296994Snate@binkert.org print("Warning: perf_event headers lack support for the " 123010319SAndreas.Sandberg@ARM.com "exclude_host attribute. KVM instruction counts will " 12315863Snate@binkert.org "be inaccurate.") 12325863Snate@binkert.org 12335863Snate@binkert.org # Save sticky variable settings back to current variables file 12345863Snate@binkert.org sticky_vars.Save(current_vars_file, env) 12355863Snate@binkert.org 12365863Snate@binkert.org if env['USE_SSE2']: 12375863Snate@binkert.org env.Append(CCFLAGS=['-msse2']) 12385863Snate@binkert.org 12397840Snate@binkert.org # The src/SConscript file sets up the build rules in 'env' according 12405863Snate@binkert.org # to the configured variables. It returns a list of environments, 12415952Ssaidi@eecs.umich.edu # one for each variant build (debug, opt, etc.) 12429651SAndreas.Sandberg@ARM.com SConscript('src/SConscript', variant_dir = variant_path, exports = 'env') 124311308Santhony.gutierrez@amd.com 12449219Spower.jg@gmail.com# base help text 12459219Spower.jg@gmail.comHelp(''' 124611235Sandreas.sandberg@arm.comUsage: scons [scons options] [build variables] [target(s)] 124711235Sandreas.sandberg@arm.com 12481869SN/AExtra scons options: 12491858SN/A%(options)s 12505863Snate@binkert.org 125111308Santhony.gutierrez@amd.comGlobal build variables: 125211308Santhony.gutierrez@amd.com%(global_vars)s 125311308Santhony.gutierrez@amd.com 12541858SN/A%(local_vars)s 1255955SN/A''' % help_texts) 1256955SN/A