SConstruct revision 14037
1955SN/A# -*- mode:python -*- 2955SN/A 310841Sandreas.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.orgfrom re import match 969812Sandreas.hansson@arm.com 979812Sandreas.hansson@arm.com# SCons includes 985863Snate@binkert.orgimport SCons 999812Sandreas.hansson@arm.comimport SCons.Node 1005863Snate@binkert.orgimport SCons.Node.FS 1015863Snate@binkert.org 1025863Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1039812Sandreas.hansson@arm.com 1049812Sandreas.hansson@arm.comhelp_texts = { 1055863Snate@binkert.org "options" : "", 1065863Snate@binkert.org "global_vars" : "", 1078878Ssteve.reinhardt@amd.com "local_vars" : "" 1085863Snate@binkert.org} 1095863Snate@binkert.org 1105863Snate@binkert.orgExport("help_texts") 1116654Snate@binkert.org 11210196SCurtis.Dunham@arm.com 113955SN/A# There's a bug in scons in that (1) by default, the help texts from 1145396Ssaidi@eecs.umich.edu# AddOption() are supposed to be displayed when you type 'scons -h' 1155863Snate@binkert.org# and (2) you can override the help displayed by 'scons -h' using the 1165863Snate@binkert.org# Help() function, but these two features are incompatible: once 1174202Sbinkertn@umich.edu# you've overridden the help text using Help(), there's no way to get 1185863Snate@binkert.org# at the help texts from AddOptions. See: 1195863Snate@binkert.org# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1205863Snate@binkert.org# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1215863Snate@binkert.org# This hack lets us extract the help text from AddOptions and 122955SN/A# re-inject it via Help(). Ideally someday this bug will be fixed and 1236654Snate@binkert.org# we can just use AddOption directly. 1245273Sstever@gmail.comdef AddLocalOption(*args, **kwargs): 1255871Snate@binkert.org col_width = 30 1265273Sstever@gmail.com 1276655Snate@binkert.org help = " " + ", ".join(args) 1288878Ssteve.reinhardt@amd.com if "help" in kwargs: 1296655Snate@binkert.org length = len(help) 1306655Snate@binkert.org if length >= col_width: 1319219Spower.jg@gmail.com help += "\n" + " " * col_width 1326655Snate@binkert.org else: 1335871Snate@binkert.org help += " " * (col_width - length) 1346654Snate@binkert.org help += kwargs["help"] 1358947Sandreas.hansson@arm.com help_texts["options"] += help + "\n" 1365396Ssaidi@eecs.umich.edu 1378120Sgblack@eecs.umich.edu AddOption(*args, **kwargs) 1388120Sgblack@eecs.umich.edu 1398120Sgblack@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true', 1408120Sgblack@eecs.umich.edu help="Add color to abbreviated scons output") 1418120Sgblack@eecs.umich.eduAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1428120Sgblack@eecs.umich.edu help="Don't add color to abbreviated scons output") 1438120Sgblack@eecs.umich.eduAddLocalOption('--with-cxx-config', dest='with_cxx_config', 1448120Sgblack@eecs.umich.edu action='store_true', 1458879Ssteve.reinhardt@amd.com help="Build with support for C++-based configuration") 1468879Ssteve.reinhardt@amd.comAddLocalOption('--default', dest='default', type='string', action='store', 1478879Ssteve.reinhardt@amd.com help='Override which build_opts file to use for defaults') 1488879Ssteve.reinhardt@amd.comAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1498879Ssteve.reinhardt@amd.com help='Disable style checking hooks') 1508879Ssteve.reinhardt@amd.comAddLocalOption('--gold-linker', dest='gold_linker', action='store_true', 1518879Ssteve.reinhardt@amd.com help='Use the gold linker') 1528879Ssteve.reinhardt@amd.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1538879Ssteve.reinhardt@amd.com help='Disable Link-Time Optimization for fast') 1548879Ssteve.reinhardt@amd.comAddLocalOption('--force-lto', dest='force_lto', action='store_true', 1558879Ssteve.reinhardt@amd.com help='Use Link-Time Optimization instead of partial linking' + 1568879Ssteve.reinhardt@amd.com ' when the compiler doesn\'t support using them together.') 1578879Ssteve.reinhardt@amd.comAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1588120Sgblack@eecs.umich.edu help='Update test reference outputs') 1598120Sgblack@eecs.umich.eduAddLocalOption('--verbose', dest='verbose', action='store_true', 1608120Sgblack@eecs.umich.edu help='Print full tool command lines') 1618120Sgblack@eecs.umich.eduAddLocalOption('--without-python', dest='without_python', 1628120Sgblack@eecs.umich.edu action='store_true', 1638120Sgblack@eecs.umich.edu help='Build without Python configuration support') 1648120Sgblack@eecs.umich.eduAddLocalOption('--without-tcmalloc', dest='without_tcmalloc', 1658120Sgblack@eecs.umich.edu action='store_true', 1668120Sgblack@eecs.umich.edu help='Disable linking against tcmalloc') 1678120Sgblack@eecs.umich.eduAddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true', 1688120Sgblack@eecs.umich.edu help='Build with Undefined Behavior Sanitizer if available') 1698120Sgblack@eecs.umich.eduAddLocalOption('--with-asan', dest='with_asan', action='store_true', 1708120Sgblack@eecs.umich.edu help='Build with Address Sanitizer if available') 1718120Sgblack@eecs.umich.edu 1728879Ssteve.reinhardt@amd.comif GetOption('no_lto') and GetOption('force_lto'): 1738879Ssteve.reinhardt@amd.com print('--no-lto and --force-lto are mutually exclusive') 1748879Ssteve.reinhardt@amd.com Exit(1) 1758879Ssteve.reinhardt@amd.com 17610458Sandreas.hansson@arm.com######################################################################## 17710458Sandreas.hansson@arm.com# 17810458Sandreas.hansson@arm.com# Set up the main build environment. 1798879Ssteve.reinhardt@amd.com# 1808879Ssteve.reinhardt@amd.com######################################################################## 1818879Ssteve.reinhardt@amd.com 1828879Ssteve.reinhardt@amd.commain = Environment() 1839227Sandreas.hansson@arm.com 1849227Sandreas.hansson@arm.comfrom gem5_scons import Transform 1858879Ssteve.reinhardt@amd.comfrom gem5_scons.util import get_termcap 1868879Ssteve.reinhardt@amd.comtermcap = get_termcap() 1878879Ssteve.reinhardt@amd.com 1888879Ssteve.reinhardt@amd.commain_dict_keys = main.Dictionary().keys() 18910453SAndrew.Bardsley@arm.com 19010453SAndrew.Bardsley@arm.com# Check that we have a C/C++ compiler 19110453SAndrew.Bardsley@arm.comif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 19210456SCurtis.Dunham@arm.com print("No C++ compiler installed (package g++ on Ubuntu and RedHat)") 19310456SCurtis.Dunham@arm.com Exit(1) 19410456SCurtis.Dunham@arm.com 19510457Sandreas.hansson@arm.com################################################### 19610457Sandreas.hansson@arm.com# 1978120Sgblack@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 1988947Sandreas.hansson@arm.com# the target(s). 1997816Ssteve.reinhardt@amd.com# 2005871Snate@binkert.org################################################### 2015871Snate@binkert.org 2026121Snate@binkert.org# Find default configuration & binary. 2035871Snate@binkert.orgDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2045871Snate@binkert.org 2059926Sstan.czerniawski@arm.com# helper function: find last occurrence of element in list 2069926Sstan.czerniawski@arm.comdef rfind(l, elt, offs = -1): 2079119Sandreas.hansson@arm.com for i in range(len(l)+offs, 0, -1): 20810068Sandreas.hansson@arm.com if l[i] == elt: 20910068Sandreas.hansson@arm.com return i 210955SN/A raise ValueError, "element not found" 2119416SAndreas.Sandberg@ARM.com 2129416SAndreas.Sandberg@ARM.com# Take a list of paths (or SCons Nodes) and return a list with all 2139416SAndreas.Sandberg@ARM.com# paths made absolute and ~-expanded. Paths will be interpreted 2149416SAndreas.Sandberg@ARM.com# relative to the launch directory unless a different root is provided 2159416SAndreas.Sandberg@ARM.comdef makePathListAbsolute(path_list, root=GetLaunchDir()): 2169416SAndreas.Sandberg@ARM.com return [abspath(joinpath(root, expanduser(str(p)))) 2179416SAndreas.Sandberg@ARM.com for p in path_list] 2185871Snate@binkert.org 21910584Sandreas.hansson@arm.comdef find_first_prog(prog_names): 2209416SAndreas.Sandberg@ARM.com """Find the absolute path to the first existing binary in prog_names""" 2219416SAndreas.Sandberg@ARM.com 2225871Snate@binkert.org if not isinstance(prog_names, (list, tuple)): 223955SN/A prog_names = [ prog_names ] 22410671Sandreas.hansson@arm.com 22510671Sandreas.hansson@arm.com for p in prog_names: 22610671Sandreas.hansson@arm.com p = main.WhereIs(p) 22710671Sandreas.hansson@arm.com if p is not None: 2288881Smarc.orr@gmail.com return p 2296121Snate@binkert.org 2306121Snate@binkert.org return None 2311533SN/A 2329239Sandreas.hansson@arm.com# Each target must have 'build' in the interior of the path; the 2339239Sandreas.hansson@arm.com# directory below this will determine the build parameters. For 2349239Sandreas.hansson@arm.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2359239Sandreas.hansson@arm.com# recognize that ALPHA_SE specifies the configuration because it 2369239Sandreas.hansson@arm.com# follow 'build' in the build path. 2379239Sandreas.hansson@arm.com 2389239Sandreas.hansson@arm.com# The funky assignment to "[:]" is needed to replace the list contents 2399239Sandreas.hansson@arm.com# in place rather than reassign the symbol to a new list, which 2409239Sandreas.hansson@arm.com# doesn't work (obviously!). 2419239Sandreas.hansson@arm.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 2429239Sandreas.hansson@arm.com 2439239Sandreas.hansson@arm.com# Generate a list of the unique build roots and configs that the 2446655Snate@binkert.org# collected targets reference. 2456655Snate@binkert.orgvariant_paths = [] 2466655Snate@binkert.orgbuild_root = None 2476655Snate@binkert.orgfor t in BUILD_TARGETS: 2485871Snate@binkert.org path_dirs = t.split('/') 2495871Snate@binkert.org try: 2505863Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 2515871Snate@binkert.org except: 2528878Ssteve.reinhardt@amd.com print("Error: no non-leaf 'build' dir found on target path", t) 2535871Snate@binkert.org Exit(1) 2545871Snate@binkert.org this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2555871Snate@binkert.org if not build_root: 2565863Snate@binkert.org build_root = this_build_root 2576121Snate@binkert.org else: 2585863Snate@binkert.org if this_build_root != build_root: 2595871Snate@binkert.org print("Error: build targets not under same build root\n" 2608336Ssteve.reinhardt@amd.com " %s\n %s" % (build_root, this_build_root)) 2618336Ssteve.reinhardt@amd.com Exit(1) 2628336Ssteve.reinhardt@amd.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 2638336Ssteve.reinhardt@amd.com if variant_path not in variant_paths: 2644678Snate@binkert.org variant_paths.append(variant_path) 2658336Ssteve.reinhardt@amd.com 2668336Ssteve.reinhardt@amd.com# Make sure build_root exists (might not if this is the first build there) 2678336Ssteve.reinhardt@amd.comif not isdir(build_root): 2684678Snate@binkert.org mkdir(build_root) 2694678Snate@binkert.orgmain['BUILDROOT'] = build_root 2704678Snate@binkert.org 2714678Snate@binkert.orgExport('main') 2727827Snate@binkert.org 2737827Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign")) 2748336Ssteve.reinhardt@amd.com 2754678Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 2768336Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves 2778336Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link. Symbolic 2788336Ssteve.reinhardt@amd.com# (soft) links work better. 2798336Ssteve.reinhardt@amd.commain.SetOption('duplicate', 'soft-copy') 2808336Ssteve.reinhardt@amd.com 2818336Ssteve.reinhardt@amd.com# 2825871Snate@binkert.org# Set up global sticky variables... these are common to an entire build 2835871Snate@binkert.org# tree (not specific to a particular build like ALPHA_SE) 2848336Ssteve.reinhardt@amd.com# 2858336Ssteve.reinhardt@amd.com 2868336Ssteve.reinhardt@amd.comglobal_vars_file = joinpath(build_root, 'variables.global') 2878336Ssteve.reinhardt@amd.com 2888336Ssteve.reinhardt@amd.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 2895871Snate@binkert.org 2908336Ssteve.reinhardt@amd.comglobal_vars.AddVariables( 2918336Ssteve.reinhardt@amd.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 2928336Ssteve.reinhardt@amd.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 2938336Ssteve.reinhardt@amd.com ('PYTHON_CONFIG', 'Python config binary to use', 2948336Ssteve.reinhardt@amd.com [ 'python2.7-config', 'python-config' ]), 2954678Snate@binkert.org ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 2965871Snate@binkert.org ('BATCH', 'Use batch pool for build and tests', False), 2974678Snate@binkert.org ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 2988336Ssteve.reinhardt@amd.com ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 2998336Ssteve.reinhardt@amd.com ('EXTRAS', 'Add extra directories to the compilation', '') 3008336Ssteve.reinhardt@amd.com ) 3018336Ssteve.reinhardt@amd.com 3028336Ssteve.reinhardt@amd.com# Update main environment with values from ARGUMENTS & global_vars_file 3038336Ssteve.reinhardt@amd.comglobal_vars.Update(main) 3048336Ssteve.reinhardt@amd.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3058336Ssteve.reinhardt@amd.com 3068336Ssteve.reinhardt@amd.com# Save sticky variable settings back to current variables file 3078336Ssteve.reinhardt@amd.comglobal_vars.Save(global_vars_file, main) 3088336Ssteve.reinhardt@amd.com 3098336Ssteve.reinhardt@amd.com# Parse EXTRAS variable to build list of all directories where we're 3108336Ssteve.reinhardt@amd.com# look for sources etc. This list is exported as extras_dir_list. 3118336Ssteve.reinhardt@amd.combase_dir = main.srcdir.abspath 3128336Ssteve.reinhardt@amd.comif main['EXTRAS']: 3138336Ssteve.reinhardt@amd.com extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3148336Ssteve.reinhardt@amd.comelse: 3155871Snate@binkert.org extras_dir_list = [] 3166121Snate@binkert.org 317955SN/AExport('base_dir') 318955SN/AExport('extras_dir_list') 3192632Sstever@eecs.umich.edu 3202632Sstever@eecs.umich.edu# the ext directory should be on the #includes path 321955SN/Amain.Append(CPPPATH=[Dir('ext')]) 322955SN/A 323955SN/A# Add shared top-level headers 324955SN/Amain.Prepend(CPPPATH=Dir('include')) 3258878Ssteve.reinhardt@amd.com 326955SN/Aif GetOption('verbose'): 3272632Sstever@eecs.umich.edu def MakeAction(action, string, *args, **kwargs): 3282632Sstever@eecs.umich.edu return Action(action, *args, **kwargs) 3292632Sstever@eecs.umich.eduelse: 3302632Sstever@eecs.umich.edu MakeAction = Action 3312632Sstever@eecs.umich.edu main['CCCOMSTR'] = Transform("CC") 3322632Sstever@eecs.umich.edu main['CXXCOMSTR'] = Transform("CXX") 3332632Sstever@eecs.umich.edu main['ASCOMSTR'] = Transform("AS") 3348268Ssteve.reinhardt@amd.com main['ARCOMSTR'] = Transform("AR", 0) 3358268Ssteve.reinhardt@amd.com main['LINKCOMSTR'] = Transform("LINK", 0) 3368268Ssteve.reinhardt@amd.com main['SHLINKCOMSTR'] = Transform("SHLINK", 0) 3378268Ssteve.reinhardt@amd.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 3388268Ssteve.reinhardt@amd.com main['M4COMSTR'] = Transform("M4") 3398268Ssteve.reinhardt@amd.com main['SHCCCOMSTR'] = Transform("SHCC") 3408268Ssteve.reinhardt@amd.com main['SHCXXCOMSTR'] = Transform("SHCXX") 3412632Sstever@eecs.umich.eduExport('MakeAction') 3422632Sstever@eecs.umich.edu 3432632Sstever@eecs.umich.edu# Initialize the Link-Time Optimization (LTO) flags 3442632Sstever@eecs.umich.edumain['LTO_CCFLAGS'] = [] 3458268Ssteve.reinhardt@amd.commain['LTO_LDFLAGS'] = [] 3462632Sstever@eecs.umich.edu 3478268Ssteve.reinhardt@amd.com# According to the readme, tcmalloc works best if the compiler doesn't 3488268Ssteve.reinhardt@amd.com# assume that we're using the builtin malloc and friends. These flags 3498268Ssteve.reinhardt@amd.com# are compiler-specific, so we need to set them after we detect which 3508268Ssteve.reinhardt@amd.com# compiler we're using. 3513718Sstever@eecs.umich.edumain['TCMALLOC_CCFLAGS'] = [] 3522634Sstever@eecs.umich.edu 3532634Sstever@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 3545863Snate@binkert.orgCXX_V = readCommand([main['CXX'],'-V'], exception=False) 3552638Sstever@eecs.umich.edu 3568268Ssteve.reinhardt@amd.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3572632Sstever@eecs.umich.edumain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 3582632Sstever@eecs.umich.eduif main['GCC'] + main['CLANG'] > 1: 3592632Sstever@eecs.umich.edu print('Error: How can we have two at the same time?') 3602632Sstever@eecs.umich.edu Exit(1) 3612632Sstever@eecs.umich.edu 3621858SN/A# Set up default C++ compiler flags 3633716Sstever@eecs.umich.eduif main['GCC'] or main['CLANG']: 3642638Sstever@eecs.umich.edu # As gcc and clang share many flags, do the common parts here 3652638Sstever@eecs.umich.edu main.Append(CCFLAGS=['-pipe']) 3662638Sstever@eecs.umich.edu main.Append(CCFLAGS=['-fno-strict-aliasing']) 3672638Sstever@eecs.umich.edu # Enable -Wall and -Wextra and then disable the few warnings that 3682638Sstever@eecs.umich.edu # we consistently violate 3692638Sstever@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wundef', '-Wextra', 3702638Sstever@eecs.umich.edu '-Wno-sign-compare', '-Wno-unused-parameter']) 3715863Snate@binkert.org # We always compile using C++11 3725863Snate@binkert.org main.Append(CXXFLAGS=['-std=c++11']) 3735863Snate@binkert.org if sys.platform.startswith('freebsd'): 374955SN/A main.Append(CCFLAGS=['-I/usr/local/include']) 3755341Sstever@gmail.com main.Append(CXXFLAGS=['-I/usr/local/include']) 3765341Sstever@gmail.com 3775863Snate@binkert.org main['FILTER_PSHLINKFLAGS'] = lambda x: str(x).replace(' -shared', '') 3787756SAli.Saidi@ARM.com main['PSHLINKFLAGS'] = main.subst('${FILTER_PSHLINKFLAGS(SHLINKFLAGS)}') 3795341Sstever@gmail.com if GetOption('gold_linker'): 3806121Snate@binkert.org main.Append(LINKFLAGS='-fuse-ld=gold') 3814494Ssaidi@eecs.umich.edu main['PLINKFLAGS'] = main.subst('${LINKFLAGS}') 3826121Snate@binkert.org shared_partial_flags = ['-r', '-nostdlib'] 3831105SN/A main.Append(PSHLINKFLAGS=shared_partial_flags) 3842667Sstever@eecs.umich.edu main.Append(PLINKFLAGS=shared_partial_flags) 3852667Sstever@eecs.umich.edu 3862667Sstever@eecs.umich.edu # Treat warnings as errors but white list some warnings that we 3872667Sstever@eecs.umich.edu # want to allow (e.g., deprecation warnings). 3886121Snate@binkert.org main.Append(CCFLAGS=['-Werror', 3892667Sstever@eecs.umich.edu '-Wno-error=deprecated-declarations', 3905341Sstever@gmail.com '-Wno-error=deprecated', 3915863Snate@binkert.org ]) 3925341Sstever@gmail.comelse: 3935341Sstever@gmail.com print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 3945341Sstever@gmail.com print("Don't know what compiler options to use for your compiler.") 3958120Sgblack@eecs.umich.edu print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 3965341Sstever@gmail.com print(termcap.Yellow + ' version:' + termcap.Normal, end = ' ') 3978120Sgblack@eecs.umich.edu if not CXX_version: 3985341Sstever@gmail.com print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 3998120Sgblack@eecs.umich.edu termcap.Normal) 4006121Snate@binkert.org else: 4016121Snate@binkert.org print(CXX_version.replace('\n', '<nl>')) 4028980Ssteve.reinhardt@amd.com print(" If you're trying to use a compiler other than GCC") 4039396Sandreas.hansson@arm.com print(" or clang, there appears to be something wrong with your") 4045397Ssaidi@eecs.umich.edu print(" environment.") 4055397Ssaidi@eecs.umich.edu print(" ") 4067727SAli.Saidi@ARM.com print(" If you are trying to use a compiler other than those listed") 4078268Ssteve.reinhardt@amd.com print(" above you will need to ease fix SConstruct and ") 4086168Snate@binkert.org print(" src/SConscript to support that compiler.") 4095341Sstever@gmail.com Exit(1) 4108120Sgblack@eecs.umich.edu 4118120Sgblack@eecs.umich.eduif main['GCC']: 4128120Sgblack@eecs.umich.edu # Check for a supported version of gcc. >= 4.8 is chosen for its 4136814Sgblack@eecs.umich.edu # level of c++11 support. See 4145863Snate@binkert.org # http://gcc.gnu.org/projects/cxx0x.html for details. 4158120Sgblack@eecs.umich.edu gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4165341Sstever@gmail.com if compareVersions(gcc_version, "4.8") < 0: 4175863Snate@binkert.org print('Error: gcc version 4.8 or newer required.') 4188268Ssteve.reinhardt@amd.com print(' Installed version: ', gcc_version) 4196121Snate@binkert.org Exit(1) 4206121Snate@binkert.org 4218268Ssteve.reinhardt@amd.com main['GCC_VERSION'] = gcc_version 4225742Snate@binkert.org 4235742Snate@binkert.org if compareVersions(gcc_version, '4.9') >= 0: 4245341Sstever@gmail.com # Incremental linking with LTO is currently broken in gcc versions 4255742Snate@binkert.org # 4.9 and above. A version where everything works completely hasn't 4265742Snate@binkert.org # yet been identified. 4275341Sstever@gmail.com # 4286017Snate@binkert.org # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67548 4296121Snate@binkert.org main['BROKEN_INCREMENTAL_LTO'] = True 4306017Snate@binkert.org if compareVersions(gcc_version, '6.0') >= 0: 4317816Ssteve.reinhardt@amd.com # gcc versions 6.0 and greater accept an -flinker-output flag which 4327756SAli.Saidi@ARM.com # selects what type of output the linker should generate. This is 4337756SAli.Saidi@ARM.com # necessary for incremental lto to work, but is also broken in 4347756SAli.Saidi@ARM.com # current versions of gcc. It may not be necessary in future 4357756SAli.Saidi@ARM.com # versions. We add it here since it might be, and as a reminder that 4367756SAli.Saidi@ARM.com # it exists. It's excluded if lto is being forced. 4377756SAli.Saidi@ARM.com # 4387756SAli.Saidi@ARM.com # https://gcc.gnu.org/gcc-6/changes.html 4397756SAli.Saidi@ARM.com # https://gcc.gnu.org/ml/gcc-patches/2015-11/msg03161.html 4407816Ssteve.reinhardt@amd.com # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69866 4417816Ssteve.reinhardt@amd.com if not GetOption('force_lto'): 4427816Ssteve.reinhardt@amd.com main.Append(PSHLINKFLAGS='-flinker-output=rel') 4437816Ssteve.reinhardt@amd.com main.Append(PLINKFLAGS='-flinker-output=rel') 4447816Ssteve.reinhardt@amd.com 4457816Ssteve.reinhardt@amd.com # Make sure we warn if the user has requested to compile with the 4467816Ssteve.reinhardt@amd.com # Undefined Benahvior Sanitizer and this version of gcc does not 4477816Ssteve.reinhardt@amd.com # support it. 4487816Ssteve.reinhardt@amd.com if GetOption('with_ubsan') and \ 4497816Ssteve.reinhardt@amd.com compareVersions(gcc_version, '4.9') < 0: 4507756SAli.Saidi@ARM.com print(termcap.Yellow + termcap.Bold + 4517816Ssteve.reinhardt@amd.com 'Warning: UBSan is only supported using gcc 4.9 and later.' + 4527816Ssteve.reinhardt@amd.com termcap.Normal) 4537816Ssteve.reinhardt@amd.com 4547816Ssteve.reinhardt@amd.com disable_lto = GetOption('no_lto') 4557816Ssteve.reinhardt@amd.com if not disable_lto and main.get('BROKEN_INCREMENTAL_LTO', False) and \ 4567816Ssteve.reinhardt@amd.com not GetOption('force_lto'): 4577816Ssteve.reinhardt@amd.com print(termcap.Yellow + termcap.Bold + 4587816Ssteve.reinhardt@amd.com 'Warning: Your compiler doesn\'t support incremental linking' + 4597816Ssteve.reinhardt@amd.com ' and lto at the same time, so lto is being disabled. To force' + 4607816Ssteve.reinhardt@amd.com ' lto on anyway, use the --force-lto option. That will disable' + 4617816Ssteve.reinhardt@amd.com ' partial linking.' + 4627816Ssteve.reinhardt@amd.com termcap.Normal) 4637816Ssteve.reinhardt@amd.com disable_lto = True 4647816Ssteve.reinhardt@amd.com 4657816Ssteve.reinhardt@amd.com # Add the appropriate Link-Time Optimization (LTO) flags 4667816Ssteve.reinhardt@amd.com # unless LTO is explicitly turned off. Note that these flags 4677816Ssteve.reinhardt@amd.com # are only used by the fast target. 4687816Ssteve.reinhardt@amd.com if not disable_lto: 4697816Ssteve.reinhardt@amd.com # Pass the LTO flag when compiling to produce GIMPLE 4707816Ssteve.reinhardt@amd.com # output, we merely create the flags here and only append 4717816Ssteve.reinhardt@amd.com # them later 4727816Ssteve.reinhardt@amd.com main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 4737816Ssteve.reinhardt@amd.com 4747816Ssteve.reinhardt@amd.com # Use the same amount of jobs for LTO as we are running 4757816Ssteve.reinhardt@amd.com # scons with 4767816Ssteve.reinhardt@amd.com main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 4777816Ssteve.reinhardt@amd.com 4787816Ssteve.reinhardt@amd.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 4797816Ssteve.reinhardt@amd.com '-fno-builtin-realloc', '-fno-builtin-free']) 4807816Ssteve.reinhardt@amd.com 4817816Ssteve.reinhardt@amd.com # The address sanitizer is available for gcc >= 4.8 4827816Ssteve.reinhardt@amd.com if GetOption('with_asan'): 4837816Ssteve.reinhardt@amd.com if GetOption('with_ubsan') and \ 4847816Ssteve.reinhardt@amd.com compareVersions(main['GCC_VERSION'], '4.9') >= 0: 4857816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-fsanitize=address,undefined', 4867816Ssteve.reinhardt@amd.com '-fno-omit-frame-pointer'], 4877816Ssteve.reinhardt@amd.com LINKFLAGS='-fsanitize=address,undefined') 4887816Ssteve.reinhardt@amd.com else: 4897816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-fsanitize=address', 4907816Ssteve.reinhardt@amd.com '-fno-omit-frame-pointer'], 4917816Ssteve.reinhardt@amd.com LINKFLAGS='-fsanitize=address') 4927816Ssteve.reinhardt@amd.com # Only gcc >= 4.9 supports UBSan, so check both the version 4937816Ssteve.reinhardt@amd.com # and the command-line option before adding the compiler and 4947816Ssteve.reinhardt@amd.com # linker flags. 4957816Ssteve.reinhardt@amd.com elif GetOption('with_ubsan') and \ 4967816Ssteve.reinhardt@amd.com compareVersions(main['GCC_VERSION'], '4.9') >= 0: 4977816Ssteve.reinhardt@amd.com main.Append(CCFLAGS='-fsanitize=undefined') 4987816Ssteve.reinhardt@amd.com main.Append(LINKFLAGS='-fsanitize=undefined') 4997816Ssteve.reinhardt@amd.com 5007816Ssteve.reinhardt@amd.comelif main['CLANG']: 5017816Ssteve.reinhardt@amd.com # Check for a supported version of clang, >= 3.1 is needed to 5027816Ssteve.reinhardt@amd.com # support similar features as gcc 4.8. See 5037816Ssteve.reinhardt@amd.com # http://clang.llvm.org/cxx_status.html for details 5047816Ssteve.reinhardt@amd.com clang_version_re = re.compile(".* version (\d+\.\d+)") 5057816Ssteve.reinhardt@amd.com clang_version_match = clang_version_re.search(CXX_version) 5067816Ssteve.reinhardt@amd.com if (clang_version_match): 5077816Ssteve.reinhardt@amd.com clang_version = clang_version_match.groups()[0] 5087816Ssteve.reinhardt@amd.com if compareVersions(clang_version, "3.1") < 0: 5097816Ssteve.reinhardt@amd.com print('Error: clang version 3.1 or newer required.') 5107816Ssteve.reinhardt@amd.com print(' Installed version:', clang_version) 5117816Ssteve.reinhardt@amd.com Exit(1) 5128947Sandreas.hansson@arm.com else: 5138947Sandreas.hansson@arm.com print('Error: Unable to determine clang version.') 5147756SAli.Saidi@ARM.com Exit(1) 5158120Sgblack@eecs.umich.edu 5167756SAli.Saidi@ARM.com # clang has a few additional warnings that we disable, extraneous 5177756SAli.Saidi@ARM.com # parantheses are allowed due to Ruby's printing of the AST, 5187756SAli.Saidi@ARM.com # finally self assignments are allowed as the generated CPU code 5197756SAli.Saidi@ARM.com # is relying on this 5207816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-Wno-parentheses', 5217816Ssteve.reinhardt@amd.com '-Wno-self-assign', 5227816Ssteve.reinhardt@amd.com # Some versions of libstdc++ (4.8?) seem to 5237816Ssteve.reinhardt@amd.com # use struct hash and class hash 5247816Ssteve.reinhardt@amd.com # interchangeably. 5257816Ssteve.reinhardt@amd.com '-Wno-mismatched-tags', 5267816Ssteve.reinhardt@amd.com ]) 5277816Ssteve.reinhardt@amd.com 5287816Ssteve.reinhardt@amd.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 5297816Ssteve.reinhardt@amd.com 5307756SAli.Saidi@ARM.com # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 5317756SAli.Saidi@ARM.com # opposed to libstdc++, as the later is dated. 5329227Sandreas.hansson@arm.com if sys.platform == "darwin": 5339227Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-stdlib=libc++']) 5349227Sandreas.hansson@arm.com main.Append(LIBS=['c++']) 5359227Sandreas.hansson@arm.com 5369590Sandreas@sandberg.pp.se # On FreeBSD we need libthr. 5379590Sandreas@sandberg.pp.se if sys.platform.startswith('freebsd'): 5389590Sandreas@sandberg.pp.se main.Append(LIBS=['thr']) 5399590Sandreas@sandberg.pp.se 5409590Sandreas@sandberg.pp.se # We require clang >= 3.1, so there is no need to check any 5419590Sandreas@sandberg.pp.se # versions here. 5426654Snate@binkert.org if GetOption('with_ubsan'): 5436654Snate@binkert.org if GetOption('with_asan'): 5445871Snate@binkert.org main.Append(CCFLAGS=['-fsanitize=address,undefined', 5456121Snate@binkert.org '-fno-omit-frame-pointer'], 5468946Sandreas.hansson@arm.com LINKFLAGS='-fsanitize=address,undefined') 5479419Sandreas.hansson@arm.com else: 5483940Ssaidi@eecs.umich.edu main.Append(CCFLAGS='-fsanitize=undefined', 5493918Ssaidi@eecs.umich.edu LINKFLAGS='-fsanitize=undefined') 5503918Ssaidi@eecs.umich.edu 5511858SN/A elif GetOption('with_asan'): 5529556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-fsanitize=address', 5539556Sandreas.hansson@arm.com '-fno-omit-frame-pointer'], 5549556Sandreas.hansson@arm.com LINKFLAGS='-fsanitize=address') 5559556Sandreas.hansson@arm.com 5569556Sandreas.hansson@arm.comelse: 5579556Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 5589556Sandreas.hansson@arm.com print("Don't know what compiler options to use for your compiler.") 55910878Sandreas.hansson@arm.com print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 56010878Sandreas.hansson@arm.com print(termcap.Yellow + ' version:' + termcap.Normal, end=' ') 5619556Sandreas.hansson@arm.com if not CXX_version: 5629556Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 5639556Sandreas.hansson@arm.com termcap.Normal) 5649556Sandreas.hansson@arm.com else: 5659556Sandreas.hansson@arm.com print(CXX_version.replace('\n', '<nl>')) 5669556Sandreas.hansson@arm.com print(" If you're trying to use a compiler other than GCC") 5679556Sandreas.hansson@arm.com print(" or clang, there appears to be something wrong with your") 5689556Sandreas.hansson@arm.com print(" environment.") 5699556Sandreas.hansson@arm.com print(" ") 5709556Sandreas.hansson@arm.com print(" If you are trying to use a compiler other than those listed") 5719556Sandreas.hansson@arm.com print(" above you will need to ease fix SConstruct and ") 5729556Sandreas.hansson@arm.com print(" src/SConscript to support that compiler.") 5739556Sandreas.hansson@arm.com Exit(1) 5749556Sandreas.hansson@arm.com 5759556Sandreas.hansson@arm.com# Set up common yacc/bison flags (needed for Ruby) 5769556Sandreas.hansson@arm.commain['YACCFLAGS'] = '-d' 5779556Sandreas.hansson@arm.commain['YACCHXXFILESUFFIX'] = '.hh' 5789556Sandreas.hansson@arm.com 5799556Sandreas.hansson@arm.com# Do this after we save setting back, or else we'll tack on an 5809556Sandreas.hansson@arm.com# extra 'qdo' every time we run scons. 5819556Sandreas.hansson@arm.comif main['BATCH']: 5829556Sandreas.hansson@arm.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5836121Snate@binkert.org main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 58410878Sandreas.hansson@arm.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 58510238Sandreas.hansson@arm.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 58610878Sandreas.hansson@arm.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5879420Sandreas.hansson@arm.com 58810878Sandreas.hansson@arm.comif sys.platform == 'cygwin': 58910878Sandreas.hansson@arm.com # cygwin has some header file issues... 5909420Sandreas.hansson@arm.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 5919420Sandreas.hansson@arm.com 5929420Sandreas.hansson@arm.com# Check for the protobuf compiler 5939420Sandreas.hansson@arm.comprotoc_version = readCommand([main['PROTOC'], '--version'], 5949420Sandreas.hansson@arm.com exception='').split() 59510264Sandreas.hansson@arm.com 59610264Sandreas.hansson@arm.com# First two words should be "libprotoc x.y.z" 59710264Sandreas.hansson@arm.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 59810264Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 59910264Sandreas.hansson@arm.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + 60010866Sandreas.hansson@arm.com ' Please install protobuf-compiler for tracing support.' + 60110866Sandreas.hansson@arm.com termcap.Normal) 60210264Sandreas.hansson@arm.com main['PROTOC'] = False 60310866Sandreas.hansson@arm.comelse: 60410866Sandreas.hansson@arm.com # Based on the availability of the compress stream wrappers, 60510866Sandreas.hansson@arm.com # require 2.1.0 60610866Sandreas.hansson@arm.com min_protoc_version = '2.1.0' 60710866Sandreas.hansson@arm.com if compareVersions(protoc_version[1], min_protoc_version) < 0: 60810866Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 60910866Sandreas.hansson@arm.com 'Warning: protoc version', min_protoc_version, 61010264Sandreas.hansson@arm.com 'or newer required.\n' + 61110264Sandreas.hansson@arm.com ' Installed version:', protoc_version[1], 61210264Sandreas.hansson@arm.com termcap.Normal) 61310264Sandreas.hansson@arm.com main['PROTOC'] = False 61410264Sandreas.hansson@arm.com else: 61510264Sandreas.hansson@arm.com # Attempt to determine the appropriate include path and 61610264Sandreas.hansson@arm.com # library path using pkg-config, that means we also need to 61710457Sandreas.hansson@arm.com # check for pkg-config. Note that it is possible to use 61810457Sandreas.hansson@arm.com # protobuf without the involvement of pkg-config. Later on we 61910457Sandreas.hansson@arm.com # check go a library config check and at that point the test 62010457Sandreas.hansson@arm.com # will fail if libprotobuf cannot be found. 62110457Sandreas.hansson@arm.com if readCommand(['pkg-config', '--version'], exception=''): 62210457Sandreas.hansson@arm.com try: 62310457Sandreas.hansson@arm.com # Attempt to establish what linking flags to add for protobuf 62410457Sandreas.hansson@arm.com # using pkg-config 62510457Sandreas.hansson@arm.com main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 62610238Sandreas.hansson@arm.com except: 62710238Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 62810238Sandreas.hansson@arm.com 'Warning: pkg-config could not get protobuf flags.' + 62910238Sandreas.hansson@arm.com termcap.Normal) 63010238Sandreas.hansson@arm.com 63110238Sandreas.hansson@arm.com 63210416Sandreas.hansson@arm.com# Check for 'timeout' from GNU coreutils. If present, regressions will 63310238Sandreas.hansson@arm.com# be run with a time limit. We require version 8.13 since we rely on 6349227Sandreas.hansson@arm.com# support for the '--foreground' option. 63510238Sandreas.hansson@arm.comif sys.platform.startswith('freebsd'): 63610416Sandreas.hansson@arm.com timeout_lines = readCommand(['gtimeout', '--version'], 63710416Sandreas.hansson@arm.com exception='').splitlines() 6389227Sandreas.hansson@arm.comelse: 6399590Sandreas@sandberg.pp.se timeout_lines = readCommand(['timeout', '--version'], 6409590Sandreas@sandberg.pp.se exception='').splitlines() 6419590Sandreas@sandberg.pp.se# Get the first line and tokenize it 6428737Skoansin.tan@gmail.comtimeout_version = timeout_lines[0].split() if timeout_lines else [] 64310878Sandreas.hansson@arm.commain['TIMEOUT'] = timeout_version and \ 64410878Sandreas.hansson@arm.com compareVersions(timeout_version[-1], '8.13') >= 0 6459420Sandreas.hansson@arm.com 6468737Skoansin.tan@gmail.com# Add a custom Check function to test for structure members. 64710106SMitch.Hayenga@arm.comdef CheckMember(context, include, decl, member, include_quotes="<>"): 6488737Skoansin.tan@gmail.com context.Message("Checking for member %s in %s..." % 6498737Skoansin.tan@gmail.com (member, decl)) 65010878Sandreas.hansson@arm.com text = """ 65110878Sandreas.hansson@arm.com#include %(header)s 6528737Skoansin.tan@gmail.comint main(){ 6538737Skoansin.tan@gmail.com %(decl)s test; 6548737Skoansin.tan@gmail.com (void)test.%(member)s; 6558737Skoansin.tan@gmail.com return 0; 6568737Skoansin.tan@gmail.com}; 6578737Skoansin.tan@gmail.com""" % { "header" : include_quotes[0] + include + include_quotes[1], 6589556Sandreas.hansson@arm.com "decl" : decl, 6599556Sandreas.hansson@arm.com "member" : member, 6609556Sandreas.hansson@arm.com } 6619556Sandreas.hansson@arm.com 6629556Sandreas.hansson@arm.com ret = context.TryCompile(text, extension=".cc") 6639556Sandreas.hansson@arm.com context.Result(ret) 6649556Sandreas.hansson@arm.com return ret 6659556Sandreas.hansson@arm.com 66610278SAndreas.Sandberg@ARM.com# Platform-specific configuration. Note again that we assume that all 66710278SAndreas.Sandberg@ARM.com# builds under a given build root run on the same host platform. 66810278SAndreas.Sandberg@ARM.comconf = Configure(main, 66910278SAndreas.Sandberg@ARM.com conf_dir = joinpath(build_root, '.scons_config'), 67010278SAndreas.Sandberg@ARM.com log_file = joinpath(build_root, 'scons_config.log'), 67110278SAndreas.Sandberg@ARM.com custom_tests = { 6729556Sandreas.hansson@arm.com 'CheckMember' : CheckMember, 6739590Sandreas@sandberg.pp.se }) 6749590Sandreas@sandberg.pp.se 6759420Sandreas.hansson@arm.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6769846Sandreas.hansson@arm.comtry: 6779846Sandreas.hansson@arm.com import platform 6789846Sandreas.hansson@arm.com uname = platform.uname() 6799846Sandreas.hansson@arm.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6808946Sandreas.hansson@arm.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6813918Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-arch', 'x86_64']) 6829068SAli.Saidi@ARM.com main.Append(CFLAGS=['-arch', 'x86_64']) 6839068SAli.Saidi@ARM.com main.Append(LINKFLAGS=['-arch', 'x86_64']) 6849068SAli.Saidi@ARM.com main.Append(ASFLAGS=['-arch', 'x86_64']) 6859068SAli.Saidi@ARM.comexcept: 6869068SAli.Saidi@ARM.com pass 6879068SAli.Saidi@ARM.com 6889068SAli.Saidi@ARM.com# Recent versions of scons substitute a "Null" object for Configure() 6899068SAli.Saidi@ARM.com# when configuration isn't necessary, e.g., if the "--help" option is 6909068SAli.Saidi@ARM.com# present. Unfortuantely this Null object always returns false, 6919419Sandreas.hansson@arm.com# breaking all our configuration checks. We replace it with our own 6929068SAli.Saidi@ARM.com# more optimistic null object that returns True instead. 6939068SAli.Saidi@ARM.comif not conf: 6949068SAli.Saidi@ARM.com def NullCheck(*args, **kwargs): 6959068SAli.Saidi@ARM.com return True 6969068SAli.Saidi@ARM.com 6979068SAli.Saidi@ARM.com class NullConf: 6983918Ssaidi@eecs.umich.edu def __init__(self, env): 6993918Ssaidi@eecs.umich.edu self.env = env 7006157Snate@binkert.org def Finish(self): 7016157Snate@binkert.org return self.env 7026157Snate@binkert.org def __getattr__(self, mname): 7036157Snate@binkert.org return NullCheck 7045397Ssaidi@eecs.umich.edu 7055397Ssaidi@eecs.umich.edu conf = NullConf(main) 7066121Snate@binkert.org 7076121Snate@binkert.org# Cache build files in the supplied directory. 7086121Snate@binkert.orgif main['M5_BUILD_CACHE']: 7096121Snate@binkert.org print('Using build cache located at', main['M5_BUILD_CACHE']) 7106121Snate@binkert.org CacheDir(main['M5_BUILD_CACHE']) 7116121Snate@binkert.org 7125397Ssaidi@eecs.umich.edumain['USE_PYTHON'] = not GetOption('without_python') 7131851SN/Aif main['USE_PYTHON']: 7141851SN/A # Find Python include and library directories for embedding the 7157739Sgblack@eecs.umich.edu # interpreter. We rely on python-config to resolve the appropriate 716955SN/A # includes and linker flags. ParseConfig does not seem to understand 7179396Sandreas.hansson@arm.com # the more exotic linker flags such as -Xlinker and -export-dynamic so 7189396Sandreas.hansson@arm.com # we add them explicitly below. If you want to link in an alternate 7199396Sandreas.hansson@arm.com # version of python, see above for instructions on how to invoke 7209396Sandreas.hansson@arm.com # scons with the appropriate PATH set. 7219396Sandreas.hansson@arm.com 7229396Sandreas.hansson@arm.com python_config = find_first_prog(main['PYTHON_CONFIG']) 7239396Sandreas.hansson@arm.com if python_config is None: 7249396Sandreas.hansson@arm.com print("Error: can't find a suitable python-config, tried %s" % \ 7259396Sandreas.hansson@arm.com main['PYTHON_CONFIG']) 7269396Sandreas.hansson@arm.com Exit(1) 7279396Sandreas.hansson@arm.com 7289396Sandreas.hansson@arm.com print("Info: Using Python config: %s" % (python_config, )) 7299396Sandreas.hansson@arm.com py_includes = readCommand([python_config, '--includes'], 7309396Sandreas.hansson@arm.com exception='').split() 7319396Sandreas.hansson@arm.com py_includes = filter(lambda s: match(r'.*\/include\/.*',s), py_includes) 7329396Sandreas.hansson@arm.com # Strip the -I from the include folders before adding them to the 7339477Sandreas.hansson@arm.com # CPPPATH 7349477Sandreas.hansson@arm.com py_includes = map(lambda s: s[2:] if s.startswith('-I') else s, py_includes) 7359477Sandreas.hansson@arm.com main.Append(CPPPATH=py_includes) 7369477Sandreas.hansson@arm.com 7379477Sandreas.hansson@arm.com # Read the linker flags and split them into libraries and other link 7389477Sandreas.hansson@arm.com # flags. The libraries are added later through the call the CheckLib. 7399477Sandreas.hansson@arm.com py_ld_flags = readCommand([python_config, '--ldflags'], 7409477Sandreas.hansson@arm.com exception='').split() 7419477Sandreas.hansson@arm.com py_libs = [] 7429477Sandreas.hansson@arm.com for lib in py_ld_flags: 7439477Sandreas.hansson@arm.com if not lib.startswith('-l'): 7449477Sandreas.hansson@arm.com main.Append(LINKFLAGS=[lib]) 7459477Sandreas.hansson@arm.com else: 7469477Sandreas.hansson@arm.com lib = lib[2:] 7479477Sandreas.hansson@arm.com if lib not in py_libs: 7489477Sandreas.hansson@arm.com py_libs.append(lib) 7499477Sandreas.hansson@arm.com 7509477Sandreas.hansson@arm.com # verify that this stuff works 7519477Sandreas.hansson@arm.com if not conf.CheckHeader('Python.h', '<>'): 7529477Sandreas.hansson@arm.com print("Error: Check failed for Python.h header in", py_includes) 7539477Sandreas.hansson@arm.com print("Two possible reasons:") 7549477Sandreas.hansson@arm.com print("1. Python headers are not installed (You can install the " 7559396Sandreas.hansson@arm.com "package python-dev on Ubuntu and RedHat)") 7563053Sstever@eecs.umich.edu print("2. SCons is using a wrong C compiler. This can happen if " 7576121Snate@binkert.org "CC has the wrong value.") 7583053Sstever@eecs.umich.edu print("CC = %s" % main['CC']) 7593053Sstever@eecs.umich.edu Exit(1) 7603053Sstever@eecs.umich.edu 7613053Sstever@eecs.umich.edu for lib in py_libs: 7623053Sstever@eecs.umich.edu if not conf.CheckLib(lib): 7639072Sandreas.hansson@arm.com print("Error: can't find library %s required by python" % lib) 7643053Sstever@eecs.umich.edu Exit(1) 7654742Sstever@eecs.umich.edu 7664742Sstever@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 7673053Sstever@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7683053Sstever@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7693053Sstever@eecs.umich.edu print("Can't find library with socket calls (e.g. accept())") 77010181SCurtis.Dunham@arm.com Exit(1) 7716654Snate@binkert.org 7723053Sstever@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 7733053Sstever@eecs.umich.edu# added to the LIBS environment variable. 7743053Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7753053Sstever@eecs.umich.edu print('Error: did not find needed zlib compression library ' 77610425Sandreas.hansson@arm.com 'and/or zlib.h header file.') 77710425Sandreas.hansson@arm.com print(' Please install zlib and try again.') 77810425Sandreas.hansson@arm.com Exit(1) 77910425Sandreas.hansson@arm.com 78010425Sandreas.hansson@arm.com# If we have the protobuf compiler, also make sure we have the 78110425Sandreas.hansson@arm.com# development libraries. If the check passes, libprotobuf will be 78210425Sandreas.hansson@arm.com# automatically added to the LIBS environment variable. After 78310425Sandreas.hansson@arm.com# this, we can use the HAVE_PROTOBUF flag to determine if we have 78410425Sandreas.hansson@arm.com# got both protoc and libprotobuf available. 78510425Sandreas.hansson@arm.commain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 78610425Sandreas.hansson@arm.com conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 7872667Sstever@eecs.umich.edu 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 7884554Sbinkertn@umich.edu 7896121Snate@binkert.org# Valgrind gets much less confused if you tell it when you're using 7902667Sstever@eecs.umich.edu# alternative stacks. 79110710Sandreas.hansson@arm.commain['HAVE_VALGRIND'] = conf.CheckCHeader('valgrind/valgrind.h') 79210710Sandreas.hansson@arm.com 79310710Sandreas.hansson@arm.com# If we have the compiler but not the library, print another warning. 79410710Sandreas.hansson@arm.comif main['PROTOC'] and not main['HAVE_PROTOBUF']: 79510710Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 79610710Sandreas.hansson@arm.com 'Warning: did not find protocol buffer library and/or headers.\n' + 79710710Sandreas.hansson@arm.com ' Please install libprotobuf-dev for tracing support.' + 79810710Sandreas.hansson@arm.com termcap.Normal) 79910710Sandreas.hansson@arm.com 80010384SCurtis.Dunham@arm.com# Check for librt. 8014554Sbinkertn@umich.eduhave_posix_clock = \ 8024554Sbinkertn@umich.edu conf.CheckLibWithHeader(None, 'time.h', 'C', 8034554Sbinkertn@umich.edu 'clock_nanosleep(0,0,NULL,NULL);') or \ 8046121Snate@binkert.org conf.CheckLibWithHeader('rt', 'time.h', 'C', 8054554Sbinkertn@umich.edu 'clock_nanosleep(0,0,NULL,NULL);') 8064554Sbinkertn@umich.edu 8074554Sbinkertn@umich.eduhave_posix_timers = \ 8084781Snate@binkert.org conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', 8094554Sbinkertn@umich.edu 'timer_create(CLOCK_MONOTONIC, NULL, NULL);') 8104554Sbinkertn@umich.edu 8112667Sstever@eecs.umich.eduif not GetOption('without_tcmalloc'): 8124554Sbinkertn@umich.edu if conf.CheckLib('tcmalloc'): 8134554Sbinkertn@umich.edu main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 8144554Sbinkertn@umich.edu elif conf.CheckLib('tcmalloc_minimal'): 8154554Sbinkertn@umich.edu main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 8162667Sstever@eecs.umich.edu else: 8174554Sbinkertn@umich.edu print(termcap.Yellow + termcap.Bold + 8182667Sstever@eecs.umich.edu "You can get a 12% performance improvement by " 8194554Sbinkertn@umich.edu "installing tcmalloc (libgoogle-perftools-dev package " 8206121Snate@binkert.org "on Ubuntu or RedHat)." + termcap.Normal) 8212667Sstever@eecs.umich.edu 8229986Sandreas@sandberg.pp.se 8239986Sandreas@sandberg.pp.se# Detect back trace implementations. The last implementation in the 8249986Sandreas@sandberg.pp.se# list will be used by default. 8259986Sandreas@sandberg.pp.sebacktrace_impls = [ "none" ] 8269986Sandreas@sandberg.pp.se 8279986Sandreas@sandberg.pp.sebacktrace_checker = 'char temp;' + \ 8289986Sandreas@sandberg.pp.se ' backtrace_symbols_fd((void*)&temp, 0, 0);' 8299986Sandreas@sandberg.pp.seif conf.CheckLibWithHeader(None, 'execinfo.h', 'C', backtrace_checker): 8309986Sandreas@sandberg.pp.se backtrace_impls.append("glibc") 8319986Sandreas@sandberg.pp.seelif conf.CheckLibWithHeader('execinfo', 'execinfo.h', 'C', 8329986Sandreas@sandberg.pp.se backtrace_checker): 8339986Sandreas@sandberg.pp.se # NetBSD and FreeBSD need libexecinfo. 8349986Sandreas@sandberg.pp.se backtrace_impls.append("glibc") 8359986Sandreas@sandberg.pp.se main.Append(LIBS=['execinfo']) 8369986Sandreas@sandberg.pp.se 8379986Sandreas@sandberg.pp.seif backtrace_impls[-1] == "none": 8389986Sandreas@sandberg.pp.se default_backtrace_impl = "none" 8399986Sandreas@sandberg.pp.se print(termcap.Yellow + termcap.Bold + 8409986Sandreas@sandberg.pp.se "No suitable back trace implementation found." + 8419986Sandreas@sandberg.pp.se termcap.Normal) 8422638Sstever@eecs.umich.edu 8432638Sstever@eecs.umich.eduif not have_posix_clock: 8446121Snate@binkert.org print("Can't find library for POSIX clocks.") 8453716Sstever@eecs.umich.edu 8465522Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 8479986Sandreas@sandberg.pp.sehave_fenv = conf.CheckHeader('fenv.h', '<>') 8489986Sandreas@sandberg.pp.seif not have_fenv: 8499986Sandreas@sandberg.pp.se print("Warning: Header file <fenv.h> not found.") 8505522Snate@binkert.org print(" This host has no IEEE FP rounding mode control.") 8515227Ssaidi@eecs.umich.edu 8525227Ssaidi@eecs.umich.edu# Check for <png.h> (libpng library needed if wanting to dump 8535227Ssaidi@eecs.umich.edu# frame buffer image in png format) 8545227Ssaidi@eecs.umich.eduhave_png = conf.CheckHeader('png.h', '<>') 8556654Snate@binkert.orgif not have_png: 8566654Snate@binkert.org print("Warning: Header file <png.h> not found.") 8577769SAli.Saidi@ARM.com print(" This host has no libpng library.") 8587769SAli.Saidi@ARM.com print(" Disabling support for PNG framebuffers.") 8597769SAli.Saidi@ARM.com 8607769SAli.Saidi@ARM.com# Check if we should enable KVM-based hardware virtualization. The API 8615227Ssaidi@eecs.umich.edu# we rely on exists since version 2.6.36 of the kernel, but somehow 8625227Ssaidi@eecs.umich.edu# the KVM_API_VERSION does not reflect the change. We test for one of 8635227Ssaidi@eecs.umich.edu# the types as a fall back. 8645204Sstever@gmail.comhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 8655204Sstever@gmail.comif not have_kvm: 8665204Sstever@gmail.com print("Info: Compatible header file <linux/kvm.h> not found, " 8675204Sstever@gmail.com "disabling KVM support.") 8685204Sstever@gmail.com 8695204Sstever@gmail.com# Check if the TUN/TAP driver is available. 8705204Sstever@gmail.comhave_tuntap = conf.CheckHeader('linux/if_tun.h', '<>') 8715204Sstever@gmail.comif not have_tuntap: 8725204Sstever@gmail.com print("Info: Compatible header file <linux/if_tun.h> not found.") 8735204Sstever@gmail.com 8745204Sstever@gmail.com# x86 needs support for xsave. We test for the structure here since we 8755204Sstever@gmail.com# won't be able to run new tests by the time we know which ISA we're 8765204Sstever@gmail.com# targeting. 8775204Sstever@gmail.comhave_kvm_xsave = conf.CheckTypeSize('struct kvm_xsave', 8785204Sstever@gmail.com '#include <linux/kvm.h>') != 0 8795204Sstever@gmail.com 8805204Sstever@gmail.com# Check if the requested target ISA is compatible with the host 8816121Snate@binkert.orgdef is_isa_kvm_compatible(isa): 8825204Sstever@gmail.com try: 8837727SAli.Saidi@ARM.com import platform 8847727SAli.Saidi@ARM.com host_isa = platform.machine() 8857727SAli.Saidi@ARM.com except: 8867727SAli.Saidi@ARM.com print("Warning: Failed to determine host ISA.") 8877727SAli.Saidi@ARM.com return False 88810453SAndrew.Bardsley@arm.com 88910453SAndrew.Bardsley@arm.com if not have_posix_timers: 89010453SAndrew.Bardsley@arm.com print("Warning: Can not enable KVM, host seems to lack support " 89110453SAndrew.Bardsley@arm.com "for POSIX timers") 89210453SAndrew.Bardsley@arm.com return False 89310453SAndrew.Bardsley@arm.com 89410453SAndrew.Bardsley@arm.com if isa == "arm": 89510453SAndrew.Bardsley@arm.com return host_isa in ( "armv7l", "aarch64" ) 89610453SAndrew.Bardsley@arm.com elif isa == "x86": 89710453SAndrew.Bardsley@arm.com if host_isa != "x86_64": 89810453SAndrew.Bardsley@arm.com return False 89910160Sandreas.hansson@arm.com 90010453SAndrew.Bardsley@arm.com if not have_kvm_xsave: 90110453SAndrew.Bardsley@arm.com print("KVM on x86 requires xsave support in kernel headers.") 90210453SAndrew.Bardsley@arm.com return False 90310453SAndrew.Bardsley@arm.com 90410453SAndrew.Bardsley@arm.com return True 90510453SAndrew.Bardsley@arm.com else: 90610453SAndrew.Bardsley@arm.com return False 90710453SAndrew.Bardsley@arm.com 9089812Sandreas.hansson@arm.com 90910453SAndrew.Bardsley@arm.com# Check if the exclude_host attribute is available. We want this to 91010453SAndrew.Bardsley@arm.com# get accurate instruction counts in KVM. 91110453SAndrew.Bardsley@arm.commain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember( 91210453SAndrew.Bardsley@arm.com 'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host') 91310453SAndrew.Bardsley@arm.com 91410453SAndrew.Bardsley@arm.com 91510453SAndrew.Bardsley@arm.com###################################################################### 91610453SAndrew.Bardsley@arm.com# 91710453SAndrew.Bardsley@arm.com# Finish the configuration 91810453SAndrew.Bardsley@arm.com# 91910453SAndrew.Bardsley@arm.commain = conf.Finish() 92010453SAndrew.Bardsley@arm.com 9217727SAli.Saidi@ARM.com###################################################################### 92210453SAndrew.Bardsley@arm.com# 92310453SAndrew.Bardsley@arm.com# Collect all non-global variables 92410453SAndrew.Bardsley@arm.com# 92510453SAndrew.Bardsley@arm.com 92610453SAndrew.Bardsley@arm.com# Define the universe of supported ISAs 9273118Sstever@eecs.umich.eduall_isa_list = [ ] 92810453SAndrew.Bardsley@arm.comall_gpu_isa_list = [ ] 92910453SAndrew.Bardsley@arm.comExport('all_isa_list') 93010453SAndrew.Bardsley@arm.comExport('all_gpu_isa_list') 93110453SAndrew.Bardsley@arm.com 9323118Sstever@eecs.umich.educlass CpuModel(object): 9333483Ssaidi@eecs.umich.edu '''The CpuModel class encapsulates everything the ISA parser needs to 9343494Ssaidi@eecs.umich.edu know about a particular CPU model.''' 9353494Ssaidi@eecs.umich.edu 9363483Ssaidi@eecs.umich.edu # Dict of available CPU model objects. Accessible as CpuModel.dict. 9373483Ssaidi@eecs.umich.edu dict = {} 9383483Ssaidi@eecs.umich.edu 9393053Sstever@eecs.umich.edu # Constructor. Automatically adds models to CpuModel.dict. 9403053Sstever@eecs.umich.edu def __init__(self, name, default=False): 9413918Ssaidi@eecs.umich.edu self.name = name # name of model 9423053Sstever@eecs.umich.edu 9433053Sstever@eecs.umich.edu # This cpu is enabled by default 9443053Sstever@eecs.umich.edu self.default = default 9453053Sstever@eecs.umich.edu 9463053Sstever@eecs.umich.edu # Add self to dict 9479396Sandreas.hansson@arm.com if name in CpuModel.dict: 9489396Sandreas.hansson@arm.com raise AttributeError, "CpuModel '%s' already registered" % name 9499396Sandreas.hansson@arm.com CpuModel.dict[name] = self 9509396Sandreas.hansson@arm.com 9519396Sandreas.hansson@arm.comExport('CpuModel') 9529396Sandreas.hansson@arm.com 9539396Sandreas.hansson@arm.com# Sticky variables get saved in the variables file so they persist from 9549396Sandreas.hansson@arm.com# one invocation to the next (unless overridden, in which case the new 9559396Sandreas.hansson@arm.com# value becomes sticky). 9569477Sandreas.hansson@arm.comsticky_vars = Variables(args=ARGUMENTS) 9579396Sandreas.hansson@arm.comExport('sticky_vars') 9589477Sandreas.hansson@arm.com 9599477Sandreas.hansson@arm.com# Sticky variables that should be exported 9609477Sandreas.hansson@arm.comexport_vars = [] 9619477Sandreas.hansson@arm.comExport('export_vars') 9629396Sandreas.hansson@arm.com 9637840Snate@binkert.org# For Ruby 9647865Sgblack@eecs.umich.eduall_protocols = [] 9657865Sgblack@eecs.umich.eduExport('all_protocols') 9667865Sgblack@eecs.umich.eduprotocol_dirs = [] 9677865Sgblack@eecs.umich.eduExport('protocol_dirs') 9687865Sgblack@eecs.umich.eduslicc_includes = [] 9697840Snate@binkert.orgExport('slicc_includes') 9709900Sandreas@sandberg.pp.se 9719900Sandreas@sandberg.pp.se# Walk the tree and execute all SConsopts scripts that wil add to the 9729900Sandreas@sandberg.pp.se# above variables 9739900Sandreas@sandberg.pp.seif GetOption('verbose'): 97410456SCurtis.Dunham@arm.com print("Reading SConsopts") 97510456SCurtis.Dunham@arm.comfor bdir in [ base_dir ] + extras_dir_list: 97610456SCurtis.Dunham@arm.com if not isdir(bdir): 97710456SCurtis.Dunham@arm.com print("Error: directory '%s' does not exist" % bdir) 97810456SCurtis.Dunham@arm.com Exit(1) 97910456SCurtis.Dunham@arm.com for root, dirs, files in os.walk(bdir): 98010456SCurtis.Dunham@arm.com if 'SConsopts' in files: 98110456SCurtis.Dunham@arm.com if GetOption('verbose'): 98210456SCurtis.Dunham@arm.com print("Reading", joinpath(root, 'SConsopts')) 98310456SCurtis.Dunham@arm.com SConscript(joinpath(root, 'SConsopts')) 9849045SAli.Saidi@ARM.com 9857840Snate@binkert.orgall_isa_list.sort() 9867840Snate@binkert.orgall_gpu_isa_list.sort() 9877840Snate@binkert.org 9881858SN/Asticky_vars.AddVariables( 9891858SN/A EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 9901858SN/A EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'hsail', all_gpu_isa_list), 9911858SN/A ListVariable('CPU_MODELS', 'CPU models', 9921858SN/A sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 9931858SN/A sorted(CpuModel.dict.keys())), 9949903Sandreas.hansson@arm.com BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 9959903Sandreas.hansson@arm.com False), 9969903Sandreas.hansson@arm.com BoolVariable('SS_COMPATIBLE_FP', 9979903Sandreas.hansson@arm.com 'Make floating-point results compatible with SimpleScalar', 99810841Sandreas.sandberg@arm.com False), 9999651SAndreas.Sandberg@ARM.com BoolVariable('USE_SSE2', 10009903Sandreas.hansson@arm.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 10019651SAndreas.Sandberg@ARM.com False), 10029651SAndreas.Sandberg@ARM.com BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 100310841Sandreas.sandberg@arm.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 100410841Sandreas.sandberg@arm.com BoolVariable('USE_PNG', 'Enable support for PNG images', have_png), 100510841Sandreas.sandberg@arm.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', 100610841Sandreas.sandberg@arm.com False), 100710841Sandreas.sandberg@arm.com BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', 100810841Sandreas.sandberg@arm.com have_kvm), 10099651SAndreas.Sandberg@ARM.com BoolVariable('USE_TUNTAP', 10109651SAndreas.Sandberg@ARM.com 'Enable using a tap device to bridge to the host network', 10119651SAndreas.Sandberg@ARM.com have_tuntap), 10129651SAndreas.Sandberg@ARM.com BoolVariable('BUILD_GPU', 'Build the compute-GPU model', False), 10139651SAndreas.Sandberg@ARM.com EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 10149651SAndreas.Sandberg@ARM.com all_protocols), 10159651SAndreas.Sandberg@ARM.com EnumVariable('BACKTRACE_IMPL', 'Post-mortem dump implementation', 10169651SAndreas.Sandberg@ARM.com backtrace_impls[-1], backtrace_impls), 10179651SAndreas.Sandberg@ARM.com ('NUMBER_BITS_PER_SET', 'Max elements in set (default 64)', 101810841Sandreas.sandberg@arm.com 64), 101910841Sandreas.sandberg@arm.com ) 102010841Sandreas.sandberg@arm.com 102110841Sandreas.sandberg@arm.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 102210841Sandreas.sandberg@arm.comexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA', 102310841Sandreas.sandberg@arm.com 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP', 102410860Sandreas.sandberg@arm.com 'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_VALGRIND', 102510841Sandreas.sandberg@arm.com 'HAVE_PERF_ATTR_EXCLUDE_HOST', 'USE_PNG', 102610841Sandreas.sandberg@arm.com 'NUMBER_BITS_PER_SET'] 102710841Sandreas.sandberg@arm.com 102810841Sandreas.sandberg@arm.com################################################### 102910841Sandreas.sandberg@arm.com# 103010841Sandreas.sandberg@arm.com# Define a SCons builder for configuration flag headers. 103110841Sandreas.sandberg@arm.com# 103210841Sandreas.sandberg@arm.com################################################### 103310841Sandreas.sandberg@arm.com 103410841Sandreas.sandberg@arm.com# This function generates a config header file that #defines the 103510841Sandreas.sandberg@arm.com# variable symbol to the current variable setting (0 or 1). The source 10369651SAndreas.Sandberg@ARM.com# operands are the name of the variable and a Value node containing the 10379651SAndreas.Sandberg@ARM.com# value of the variable. 10389986Sandreas@sandberg.pp.sedef build_config_file(target, source, env): 10399986Sandreas@sandberg.pp.se (variable, value) = [s.get_contents() for s in source] 10409986Sandreas@sandberg.pp.se f = file(str(target[0]), 'w') 10419986Sandreas@sandberg.pp.se print('#define', variable, value, file=f) 10429986Sandreas@sandberg.pp.se f.close() 10439986Sandreas@sandberg.pp.se return None 10445863Snate@binkert.org 10455863Snate@binkert.org# Combine the two functions into a scons Action object. 10465863Snate@binkert.orgconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 10475863Snate@binkert.org 10486121Snate@binkert.org# The emitter munges the source & target node lists to reflect what 10491858SN/A# we're really doing. 10505863Snate@binkert.orgdef config_emitter(target, source, env): 10515863Snate@binkert.org # extract variable name from Builder arg 10525863Snate@binkert.org variable = str(target[0]) 10535863Snate@binkert.org # True target is config header file 10545863Snate@binkert.org target = joinpath('config', variable.lower() + '.hh') 10552139SN/A val = env[variable] 10564202Sbinkertn@umich.edu if isinstance(val, bool): 10574202Sbinkertn@umich.edu # Force value to 0/1 10582139SN/A val = int(val) 10596994Snate@binkert.org elif isinstance(val, str): 10606994Snate@binkert.org val = '"' + val + '"' 10616994Snate@binkert.org 10626994Snate@binkert.org # Sources are variable name & value (packaged in SCons Value nodes) 10636994Snate@binkert.org return ([target], [Value(variable), Value(val)]) 10646994Snate@binkert.org 10656994Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 10666994Snate@binkert.org 106710319SAndreas.Sandberg@ARM.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 10686994Snate@binkert.org 10696994Snate@binkert.org################################################### 10706994Snate@binkert.org# 10716994Snate@binkert.org# Builders for static and shared partially linked object files. 10726994Snate@binkert.org# 10736994Snate@binkert.org################################################### 10746994Snate@binkert.org 10756994Snate@binkert.orgpartial_static_builder = Builder(action=SCons.Defaults.LinkAction, 10766994Snate@binkert.org src_suffix='$OBJSUFFIX', 10776994Snate@binkert.org src_builder=['StaticObject', 'Object'], 10786994Snate@binkert.org LINKFLAGS='$PLINKFLAGS', 10792155SN/A LIBS='') 10805863Snate@binkert.org 10811869SN/Adef partial_shared_emitter(target, source, env): 10821869SN/A for tgt in target: 10835863Snate@binkert.org tgt.attributes.shared = 1 10845863Snate@binkert.org return (target, source) 10854202Sbinkertn@umich.edupartial_shared_builder = Builder(action=SCons.Defaults.ShLinkAction, 10866108Snate@binkert.org emitter=partial_shared_emitter, 10876108Snate@binkert.org src_suffix='$SHOBJSUFFIX', 10886108Snate@binkert.org src_builder='SharedObject', 10896108Snate@binkert.org SHLINKFLAGS='$PSHLINKFLAGS', 10909219Spower.jg@gmail.com LIBS='') 10919219Spower.jg@gmail.com 10929219Spower.jg@gmail.commain.Append(BUILDERS = { 'PartialShared' : partial_shared_builder, 10939219Spower.jg@gmail.com 'PartialStatic' : partial_static_builder }) 10949219Spower.jg@gmail.com 10959219Spower.jg@gmail.comdef add_local_rpath(env, *targets): 10969219Spower.jg@gmail.com '''Set up an RPATH for a library which lives in the build directory. 10979219Spower.jg@gmail.com 10984202Sbinkertn@umich.edu The construction environment variable BIN_RPATH_PREFIX should be set to 10995863Snate@binkert.org the relative path of the build directory starting from the location of the 110010135SCurtis.Dunham@arm.com binary.''' 11018474Sgblack@eecs.umich.edu for target in targets: 11025742Snate@binkert.org target = env.Entry(target) 11038268Ssteve.reinhardt@amd.com if not isinstance(target, SCons.Node.FS.Dir): 11048268Ssteve.reinhardt@amd.com target = target.dir 11058268Ssteve.reinhardt@amd.com relpath = os.path.relpath(target.abspath, env['BUILDDIR']) 11065742Snate@binkert.org components = [ 11075341Sstever@gmail.com '\\$$ORIGIN', 11088474Sgblack@eecs.umich.edu '${BIN_RPATH_PREFIX}', 11098474Sgblack@eecs.umich.edu relpath 11105342Sstever@gmail.com ] 11114202Sbinkertn@umich.edu env.Append(RPATH=[env.Literal(os.path.join(*components))]) 11124202Sbinkertn@umich.edu 11134202Sbinkertn@umich.eduif sys.platform != "darwin": 11145863Snate@binkert.org main.Append(LINKFLAGS=Split('-z origin')) 11155863Snate@binkert.org 11166994Snate@binkert.orgmain.AddMethod(add_local_rpath, 'AddLocalRPATH') 11176994Snate@binkert.org 111810319SAndreas.Sandberg@ARM.com# builds in ext are shared across all configs in the build root. 11195863Snate@binkert.orgext_dir = abspath(joinpath(str(main.root), 'ext')) 11205863Snate@binkert.orgext_build_dirs = [] 11215863Snate@binkert.orgfor root, dirs, files in os.walk(ext_dir): 11225863Snate@binkert.org if 'SConscript' in files: 11235863Snate@binkert.org build_dir = os.path.relpath(root, ext_dir) 11245863Snate@binkert.org ext_build_dirs.append(build_dir) 11255863Snate@binkert.org main.SConscript(joinpath(root, 'SConscript'), 11265863Snate@binkert.org variant_dir=joinpath(build_root, build_dir)) 11277840Snate@binkert.org 11285863Snate@binkert.orggdb_xml_dir = joinpath(ext_dir, 'gdb-xml') 11295952Ssaidi@eecs.umich.eduExport('gdb_xml_dir') 11309651SAndreas.Sandberg@ARM.com 11319219Spower.jg@gmail.commain.Prepend(CPPPATH=Dir('ext/pybind11/include/')) 11329219Spower.jg@gmail.com 11331869SN/A################################################### 11341858SN/A# 11355863Snate@binkert.org# This builder and wrapper method are used to set up a directory with 11369420Sandreas.hansson@arm.com# switching headers. Those are headers which are in a generic location and 113710607Sgabeblack@google.com# that include more specific headers from a directory chosen at build time 11389986Sandreas@sandberg.pp.se# based on the current build settings. 11391858SN/A# 1140955SN/A################################################### 1141955SN/A 11421869SN/Adef build_switching_header(target, source, env): 11431869SN/A path = str(target[0]) 11441869SN/A subdir = str(source[0]) 11451869SN/A dp, fp = os.path.split(path) 11461869SN/A dp = os.path.relpath(os.path.realpath(dp), 11475863Snate@binkert.org os.path.realpath(env['BUILDDIR'])) 11485863Snate@binkert.org with open(path, 'w') as hdr: 11495863Snate@binkert.org print('#include "%s/%s/%s"' % (dp, subdir, fp), file=hdr) 11501869SN/A 11515863Snate@binkert.orgswitching_header_action = MakeAction(build_switching_header, 11521869SN/A Transform('GENERATE')) 11535863Snate@binkert.org 11541869SN/Aswitching_header_builder = Builder(action=switching_header_action, 11551869SN/A source_factory=Value, 11561869SN/A single_source=True) 11571869SN/A 11588483Sgblack@eecs.umich.edumain.Append(BUILDERS = { 'SwitchingHeader': switching_header_builder }) 11591869SN/A 11601869SN/Adef switching_headers(self, headers, source): 11611869SN/A for header in headers: 11621869SN/A self.SwitchingHeader(header, source) 11635863Snate@binkert.org 11645863Snate@binkert.orgmain.AddMethod(switching_headers, 'SwitchingHeaders') 11651869SN/A 11665863Snate@binkert.org################################################### 11675863Snate@binkert.org# 11683356Sbinkertn@umich.edu# Define build environments for selected configurations. 11693356Sbinkertn@umich.edu# 11703356Sbinkertn@umich.edu################################################### 11713356Sbinkertn@umich.edu 11723356Sbinkertn@umich.edufor variant_path in variant_paths: 11734781Snate@binkert.org if not GetOption('silent'): 11745863Snate@binkert.org print("Building in", variant_path) 11755863Snate@binkert.org 11761869SN/A # Make a copy of the build-root environment to use for this config. 11771869SN/A env = main.Clone() 11781869SN/A env['BUILDDIR'] = variant_path 11796121Snate@binkert.org 11801869SN/A # variant_dir is the tail component of build path, and is used to 11812638Sstever@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 11826121Snate@binkert.org (build_root, variant_dir) = splitpath(variant_path) 11836121Snate@binkert.org 11842638Sstever@eecs.umich.edu # Set env variables according to the build directory config. 11855749Scws3k@cs.virginia.edu sticky_vars.files = [] 11866121Snate@binkert.org # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 11876121Snate@binkert.org # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 11885749Scws3k@cs.virginia.edu # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 11899537Satgutier@umich.edu current_vars_file = joinpath(build_root, 'variables', variant_dir) 11909537Satgutier@umich.edu if isfile(current_vars_file): 11919537Satgutier@umich.edu sticky_vars.files.append(current_vars_file) 11929537Satgutier@umich.edu if not GetOption('silent'): 11939888Sandreas@sandberg.pp.se print("Using saved variables file %s" % current_vars_file) 11949888Sandreas@sandberg.pp.se elif variant_dir in ext_build_dirs: 11959888Sandreas@sandberg.pp.se # Things in ext are built without a variant directory. 11969888Sandreas@sandberg.pp.se continue 119710066Sandreas.hansson@arm.com else: 119810066Sandreas.hansson@arm.com # Build dir-specific variables file doesn't exist. 119910066Sandreas.hansson@arm.com 120010066Sandreas.hansson@arm.com # Make sure the directory is there so we can create it later 120110428Sandreas.hansson@arm.com opt_dir = dirname(current_vars_file) 120210428Sandreas.hansson@arm.com if not isdir(opt_dir): 120310428Sandreas.hansson@arm.com mkdir(opt_dir) 120410428Sandreas.hansson@arm.com 120510915Sandreas.sandberg@arm.com # Get default build variables from source tree. Variables are 120610915Sandreas.sandberg@arm.com # normally determined by name of $VARIANT_DIR, but can be 120710915Sandreas.sandberg@arm.com # overridden by '--default=' arg on command line. 120810915Sandreas.sandberg@arm.com default = GetOption('default') 12091869SN/A opts_dir = joinpath(main.root.abspath, 'build_opts') 12101869SN/A if default: 12113546Sgblack@eecs.umich.edu default_vars_files = [joinpath(build_root, 'variables', default), 12123546Sgblack@eecs.umich.edu joinpath(opts_dir, default)] 12133546Sgblack@eecs.umich.edu else: 12143546Sgblack@eecs.umich.edu default_vars_files = [joinpath(opts_dir, variant_dir)] 12156121Snate@binkert.org existing_files = filter(isfile, default_vars_files) 121610196SCurtis.Dunham@arm.com if existing_files: 12175863Snate@binkert.org default_vars_file = existing_files[0] 12183546Sgblack@eecs.umich.edu sticky_vars.files.append(default_vars_file) 12193546Sgblack@eecs.umich.edu print("Variables file %s not found,\n using defaults in %s" 12203546Sgblack@eecs.umich.edu % (current_vars_file, default_vars_file)) 12213546Sgblack@eecs.umich.edu else: 12224781Snate@binkert.org print("Error: cannot find variables file %s or " 12236658Snate@binkert.org "default file(s) %s" 122410196SCurtis.Dunham@arm.com % (current_vars_file, ' or '.join(default_vars_files))) 122510196SCurtis.Dunham@arm.com Exit(1) 122610196SCurtis.Dunham@arm.com 122710196SCurtis.Dunham@arm.com # Apply current variable settings to env 122810196SCurtis.Dunham@arm.com sticky_vars.Update(env) 122910196SCurtis.Dunham@arm.com 123010196SCurtis.Dunham@arm.com help_texts["local_vars"] += \ 12313546Sgblack@eecs.umich.edu "Build variables for %s:\n" % variant_dir \ 12323546Sgblack@eecs.umich.edu + sticky_vars.GenerateHelpText(env) 12333546Sgblack@eecs.umich.edu 12343546Sgblack@eecs.umich.edu # Process variable settings. 12357756SAli.Saidi@ARM.com 12367816Ssteve.reinhardt@amd.com if not have_fenv and env['USE_FENV']: 12373546Sgblack@eecs.umich.edu print("Warning: <fenv.h> not available; " 12383546Sgblack@eecs.umich.edu "forcing USE_FENV to False in", variant_dir + ".") 12393546Sgblack@eecs.umich.edu env['USE_FENV'] = False 12403546Sgblack@eecs.umich.edu 124110196SCurtis.Dunham@arm.com if not env['USE_FENV']: 124210196SCurtis.Dunham@arm.com print("Warning: No IEEE FP rounding mode control in", 124310196SCurtis.Dunham@arm.com variant_dir + ".") 124410196SCurtis.Dunham@arm.com print(" FP results may deviate slightly from other platforms.") 124510196SCurtis.Dunham@arm.com 12464202Sbinkertn@umich.edu if not have_png and env['USE_PNG']: 12473546Sgblack@eecs.umich.edu print("Warning: <png.h> not available; " 124810196SCurtis.Dunham@arm.com "forcing USE_PNG to False in", variant_dir + ".") 124910196SCurtis.Dunham@arm.com env['USE_PNG'] = False 125010196SCurtis.Dunham@arm.com 125110196SCurtis.Dunham@arm.com if env['USE_PNG']: 125210196SCurtis.Dunham@arm.com env.Append(LIBS=['png']) 125310196SCurtis.Dunham@arm.com 125410196SCurtis.Dunham@arm.com if env['EFENCE']: 125510196SCurtis.Dunham@arm.com env.Append(LIBS=['efence']) 125610196SCurtis.Dunham@arm.com 125710196SCurtis.Dunham@arm.com if env['USE_KVM']: 125810196SCurtis.Dunham@arm.com if not have_kvm: 125910196SCurtis.Dunham@arm.com print("Warning: Can not enable KVM, host seems to " 126010196SCurtis.Dunham@arm.com "lack KVM support") 126110196SCurtis.Dunham@arm.com env['USE_KVM'] = False 126210196SCurtis.Dunham@arm.com elif not is_isa_kvm_compatible(env['TARGET_ISA']): 126310196SCurtis.Dunham@arm.com print("Info: KVM support disabled due to unsupported host and " 126410196SCurtis.Dunham@arm.com "target ISA combination") 126510196SCurtis.Dunham@arm.com env['USE_KVM'] = False 126610196SCurtis.Dunham@arm.com 126710196SCurtis.Dunham@arm.com if env['USE_TUNTAP']: 126810196SCurtis.Dunham@arm.com if not have_tuntap: 126910196SCurtis.Dunham@arm.com print("Warning: Can't connect EtherTap with a tap device.") 127010196SCurtis.Dunham@arm.com env['USE_TUNTAP'] = False 127110196SCurtis.Dunham@arm.com 12723546Sgblack@eecs.umich.edu if env['BUILD_GPU']: 12733546Sgblack@eecs.umich.edu env.Append(CPPDEFINES=['BUILD_GPU']) 1274955SN/A 1275955SN/A # Warn about missing optional functionality 1276955SN/A if env['USE_KVM']: 1277955SN/A if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']: 12785863Snate@binkert.org print("Warning: perf_event headers lack support for the " 127910135SCurtis.Dunham@arm.com "exclude_host attribute. KVM instruction counts will " 128010135SCurtis.Dunham@arm.com "be inaccurate.") 12815343Sstever@gmail.com 12825343Sstever@gmail.com # Save sticky variable settings back to current variables file 12836121Snate@binkert.org sticky_vars.Save(current_vars_file, env) 12845863Snate@binkert.org 12854773Snate@binkert.org if env['USE_SSE2']: 12865863Snate@binkert.org env.Append(CCFLAGS=['-msse2']) 12872632Sstever@eecs.umich.edu 12885863Snate@binkert.org # The src/SConscript file sets up the build rules in 'env' according 12892023SN/A # to the configured variables. It returns a list of environments, 12905863Snate@binkert.org # one for each variant build (debug, opt, etc.) 12915863Snate@binkert.org SConscript('src/SConscript', variant_dir = variant_path, exports = 'env') 12925863Snate@binkert.org 12935863Snate@binkert.org# base help text 12945863Snate@binkert.orgHelp(''' 12955863Snate@binkert.orgUsage: scons [scons options] [build variables] [target(s)] 12965863Snate@binkert.org 12975863Snate@binkert.orgExtra scons options: 129810135SCurtis.Dunham@arm.com%(options)s 129910135SCurtis.Dunham@arm.com 13002632Sstever@eecs.umich.eduGlobal build variables: 13015863Snate@binkert.org%(global_vars)s 13022023SN/A 13032632Sstever@eecs.umich.edu%(local_vars)s 13045863Snate@binkert.org''' % help_texts) 13055342Sstever@gmail.com