SConstruct revision 14209
1955SN/A# -*- mode:python -*- 2955SN/A 37816Ssteve.reinhardt@amd.com# Copyright (c) 2013, 2015-2019 ARM Limited 45871Snate@binkert.org# All rights reserved. 51762SN/A# 6955SN/A# The license below extends only to copyright in the software and shall 7955SN/A# not be construed as granting a license to any other intellectual 8955SN/A# property including but not limited to intellectual property relating 9955SN/A# to a hardware implementation of the functionality of the software 10955SN/A# licensed hereunder. You may use the software subject to the license 11955SN/A# terms below provided that you ensure that this notice is replicated 12955SN/A# unmodified and in its entirety in all distributions of the software, 13955SN/A# modified or unmodified, in source code or in binary form. 14955SN/A# 15955SN/A# Copyright (c) 2011 Advanced Micro Devices, Inc. 16955SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 17955SN/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. 302665Ssaidi@eecs.umich.edu# 312665Ssaidi@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 325863Snate@binkert.org# "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, 388878Ssteve.reinhardt@amd.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 392632Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 408878Ssteve.reinhardt@amd.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 412632Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42955SN/A# 438878Ssteve.reinhardt@amd.com# Authors: Steve Reinhardt 442632Sstever@eecs.umich.edu# Nathan Binkert 452761Sstever@eecs.umich.edu 462632Sstever@eecs.umich.edu################################################### 472632Sstever@eecs.umich.edu# 482632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 492761Sstever@eecs.umich.edu# 502761Sstever@eecs.umich.edu# While in this directory ('gem5'), just type 'scons' to build the default 512761Sstever@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 538878Ssteve.reinhardt@amd.com# the optimized full-system version). 542761Sstever@eecs.umich.edu# 552761Sstever@eecs.umich.edu# You can build gem5 in a different directory as long as there is a 562761Sstever@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 582761Sstever@eecs.umich.edu# built for the same host system. 598878Ssteve.reinhardt@amd.com# 608878Ssteve.reinhardt@amd.com# Examples: 612632Sstever@eecs.umich.edu# 622632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 638878Ssteve.reinhardt@amd.com# 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 652632Sstever@eecs.umich.edu# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug 66955SN/A# 67955SN/A# The following two commands are equivalent and demonstrate building 68955SN/A# in a directory outside of the source tree. The '-C' option tells 695863Snate@binkert.org# scons to chdir to the specified directory to find this SConstruct 705863Snate@binkert.org# file. 715863Snate@binkert.org# % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 725863Snate@binkert.org# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug 735863Snate@binkert.org# 745863Snate@binkert.org# You can use 'scons -H' to print scons options. If you're in this 755863Snate@binkert.org# 'gem5' directory (or use -u or -C to tell scons where to find this 765863Snate@binkert.org# file), you can use 'scons -h' to print all the gem5-specific build 775863Snate@binkert.org# options as well. 785863Snate@binkert.org# 795863Snate@binkert.org################################################### 808878Ssteve.reinhardt@amd.com 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 925863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 935863Snate@binkert.orgfrom os.path import exists, isdir, isfile 945863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 955863Snate@binkert.orgfrom re import match 968878Ssteve.reinhardt@amd.com 975863Snate@binkert.org# SCons includes 985863Snate@binkert.orgimport SCons 995863Snate@binkert.orgimport SCons.Node 1006654Snate@binkert.orgimport SCons.Node.FS 101955SN/A 1025396Ssaidi@eecs.umich.edufrom m5.util import compareVersions, readCommand 1035863Snate@binkert.org 1045863Snate@binkert.orghelp_texts = { 1054202Sbinkertn@umich.edu "options" : "", 1065863Snate@binkert.org "global_vars" : "", 1075863Snate@binkert.org "local_vars" : "" 1085863Snate@binkert.org} 1095863Snate@binkert.org 110955SN/AExport("help_texts") 1116654Snate@binkert.org 1125273Sstever@gmail.com 1135871Snate@binkert.org# There's a bug in scons in that (1) by default, the help texts from 1145273Sstever@gmail.com# AddOption() are supposed to be displayed when you type 'scons -h' 1156655Snate@binkert.org# and (2) you can override the help displayed by 'scons -h' using the 1168878Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once 1176655Snate@binkert.org# you've overridden the help text using Help(), there's no way to get 1186655Snate@binkert.org# at the help texts from AddOptions. See: 1199219Spower.jg@gmail.com# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1206655Snate@binkert.org# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1215871Snate@binkert.org# This hack lets us extract the help text from AddOptions and 1226654Snate@binkert.org# re-inject it via Help(). Ideally someday this bug will be fixed and 1238947Sandreas.hansson@arm.com# we can just use AddOption directly. 1245396Ssaidi@eecs.umich.edudef AddLocalOption(*args, **kwargs): 1258120Sgblack@eecs.umich.edu col_width = 30 1268120Sgblack@eecs.umich.edu 1278120Sgblack@eecs.umich.edu help = " " + ", ".join(args) 1288120Sgblack@eecs.umich.edu if "help" in kwargs: 1298120Sgblack@eecs.umich.edu length = len(help) 1308120Sgblack@eecs.umich.edu if length >= col_width: 1318120Sgblack@eecs.umich.edu help += "\n" + " " * col_width 1328120Sgblack@eecs.umich.edu else: 1338879Ssteve.reinhardt@amd.com help += " " * (col_width - length) 1348879Ssteve.reinhardt@amd.com help += kwargs["help"] 1358879Ssteve.reinhardt@amd.com help_texts["options"] += help + "\n" 1368879Ssteve.reinhardt@amd.com 1378879Ssteve.reinhardt@amd.com AddOption(*args, **kwargs) 1388879Ssteve.reinhardt@amd.com 1398879Ssteve.reinhardt@amd.comAddLocalOption('--colors', dest='use_colors', action='store_true', 1408879Ssteve.reinhardt@amd.com help="Add color to abbreviated scons output") 1418879Ssteve.reinhardt@amd.comAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1428879Ssteve.reinhardt@amd.com help="Don't add color to abbreviated scons output") 1438879Ssteve.reinhardt@amd.comAddLocalOption('--with-cxx-config', dest='with_cxx_config', 1448879Ssteve.reinhardt@amd.com action='store_true', 1458879Ssteve.reinhardt@amd.com help="Build with support for C++-based configuration") 1468120Sgblack@eecs.umich.eduAddLocalOption('--default', dest='default', type='string', action='store', 1478120Sgblack@eecs.umich.edu help='Override which build_opts file to use for defaults') 1488120Sgblack@eecs.umich.eduAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1498120Sgblack@eecs.umich.edu help='Disable style checking hooks') 1508120Sgblack@eecs.umich.eduAddLocalOption('--gold-linker', dest='gold_linker', action='store_true', 1518120Sgblack@eecs.umich.edu help='Use the gold linker') 1528120Sgblack@eecs.umich.eduAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1538120Sgblack@eecs.umich.edu help='Disable Link-Time Optimization for fast') 1548120Sgblack@eecs.umich.eduAddLocalOption('--force-lto', dest='force_lto', action='store_true', 1558120Sgblack@eecs.umich.edu help='Use Link-Time Optimization instead of partial linking' + 1568120Sgblack@eecs.umich.edu ' when the compiler doesn\'t support using them together.') 1578120Sgblack@eecs.umich.eduAddLocalOption('--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', 1608879Ssteve.reinhardt@amd.com help='Print full tool command lines') 1618879Ssteve.reinhardt@amd.comAddLocalOption('--without-python', dest='without_python', 1628879Ssteve.reinhardt@amd.com action='store_true', 1638879Ssteve.reinhardt@amd.com help='Build without Python configuration support') 1648879Ssteve.reinhardt@amd.comAddLocalOption('--without-tcmalloc', dest='without_tcmalloc', 1658879Ssteve.reinhardt@amd.com action='store_true', 1668879Ssteve.reinhardt@amd.com help='Disable linking against tcmalloc') 1678879Ssteve.reinhardt@amd.comAddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true', 1689227Sandreas.hansson@arm.com help='Build with Undefined Behavior Sanitizer if available') 1699227Sandreas.hansson@arm.comAddLocalOption('--with-asan', dest='with_asan', action='store_true', 1708879Ssteve.reinhardt@amd.com help='Build with Address Sanitizer if available') 1718879Ssteve.reinhardt@amd.com 1728879Ssteve.reinhardt@amd.comif GetOption('no_lto') and GetOption('force_lto'): 1738879Ssteve.reinhardt@amd.com print('--no-lto and --force-lto are mutually exclusive') 1748120Sgblack@eecs.umich.edu Exit(1) 1758947Sandreas.hansson@arm.com 1767816Ssteve.reinhardt@amd.com######################################################################## 1775871Snate@binkert.org# 1785871Snate@binkert.org# Set up the main build environment. 1796121Snate@binkert.org# 1805871Snate@binkert.org######################################################################## 1815871Snate@binkert.org 1829119Sandreas.hansson@arm.commain = Environment() 1839396Sandreas.hansson@arm.com 1849396Sandreas.hansson@arm.comfrom gem5_scons import Transform 185955SN/Afrom gem5_scons.util import get_termcap 1869416SAndreas.Sandberg@ARM.comtermcap = get_termcap() 1879416SAndreas.Sandberg@ARM.com 1889416SAndreas.Sandberg@ARM.commain_dict_keys = main.Dictionary().keys() 1899416SAndreas.Sandberg@ARM.com 1909416SAndreas.Sandberg@ARM.com# Check that we have a C/C++ compiler 1919416SAndreas.Sandberg@ARM.comif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 1929416SAndreas.Sandberg@ARM.com print("No C++ compiler installed (package g++ on Ubuntu and RedHat)") 1935871Snate@binkert.org Exit(1) 1945871Snate@binkert.org 1959416SAndreas.Sandberg@ARM.com################################################### 1969416SAndreas.Sandberg@ARM.com# 1975871Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 198955SN/A# the target(s). 1996121Snate@binkert.org# 2008881Smarc.orr@gmail.com################################################### 2016121Snate@binkert.org 2026121Snate@binkert.org# Find default configuration & binary. 2031533SN/ADefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2049239Sandreas.hansson@arm.com 2059239Sandreas.hansson@arm.com# helper function: find last occurrence of element in list 2069239Sandreas.hansson@arm.comdef rfind(l, elt, offs = -1): 2079239Sandreas.hansson@arm.com for i in range(len(l)+offs, 0, -1): 2089239Sandreas.hansson@arm.com if l[i] == elt: 2099239Sandreas.hansson@arm.com return i 2109239Sandreas.hansson@arm.com raise ValueError, "element not found" 2119239Sandreas.hansson@arm.com 2129239Sandreas.hansson@arm.com# Take a list of paths (or SCons Nodes) and return a list with all 2139239Sandreas.hansson@arm.com# paths made absolute and ~-expanded. Paths will be interpreted 2149239Sandreas.hansson@arm.com# relative to the launch directory unless a different root is provided 2159239Sandreas.hansson@arm.comdef makePathListAbsolute(path_list, root=GetLaunchDir()): 2166655Snate@binkert.org return [abspath(joinpath(root, expanduser(str(p)))) 2176655Snate@binkert.org for p in path_list] 2186655Snate@binkert.org 2196655Snate@binkert.orgdef find_first_prog(prog_names): 2205871Snate@binkert.org """Find the absolute path to the first existing binary in prog_names""" 2215871Snate@binkert.org 2225863Snate@binkert.org if not isinstance(prog_names, (list, tuple)): 2235871Snate@binkert.org prog_names = [ prog_names ] 2248878Ssteve.reinhardt@amd.com 2255871Snate@binkert.org for p in prog_names: 2265871Snate@binkert.org p = main.WhereIs(p) 2275871Snate@binkert.org if p is not None: 2285863Snate@binkert.org return p 2296121Snate@binkert.org 2305863Snate@binkert.org return None 2315871Snate@binkert.org 2328336Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the 2338336Ssteve.reinhardt@amd.com# directory below this will determine the build parameters. For 2348336Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2358336Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it 2364678Snate@binkert.org# follow 'build' in the build path. 2378336Ssteve.reinhardt@amd.com 2388336Ssteve.reinhardt@amd.com# The funky assignment to "[:]" is needed to replace the list contents 2398336Ssteve.reinhardt@amd.com# in place rather than reassign the symbol to a new list, which 2404678Snate@binkert.org# doesn't work (obviously!). 2414678Snate@binkert.orgBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 2424678Snate@binkert.org 2434678Snate@binkert.org# Generate a list of the unique build roots and configs that the 2447827Snate@binkert.org# collected targets reference. 2457827Snate@binkert.orgvariant_paths = [] 2468336Ssteve.reinhardt@amd.combuild_root = None 2474678Snate@binkert.orgfor t in BUILD_TARGETS: 2488336Ssteve.reinhardt@amd.com path_dirs = t.split('/') 2498336Ssteve.reinhardt@amd.com try: 2508336Ssteve.reinhardt@amd.com build_top = rfind(path_dirs, 'build', -2) 2518336Ssteve.reinhardt@amd.com except: 2528336Ssteve.reinhardt@amd.com print("Error: no non-leaf 'build' dir found on target path", t) 2538336Ssteve.reinhardt@amd.com Exit(1) 2545871Snate@binkert.org this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2555871Snate@binkert.org if not build_root: 2568336Ssteve.reinhardt@amd.com build_root = this_build_root 2578336Ssteve.reinhardt@amd.com else: 2588336Ssteve.reinhardt@amd.com if this_build_root != build_root: 2598336Ssteve.reinhardt@amd.com print("Error: build targets not under same build root\n" 2608336Ssteve.reinhardt@amd.com " %s\n %s" % (build_root, this_build_root)) 2615871Snate@binkert.org 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: 2648336Ssteve.reinhardt@amd.com 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) 2674678Snate@binkert.orgif not isdir(build_root): 2685871Snate@binkert.org mkdir(build_root) 2694678Snate@binkert.orgmain['BUILDROOT'] = build_root 2708336Ssteve.reinhardt@amd.com 2718336Ssteve.reinhardt@amd.comExport('main') 2728336Ssteve.reinhardt@amd.com 2738336Ssteve.reinhardt@amd.commain.SConsignFile(joinpath(build_root, "sconsign")) 2748336Ssteve.reinhardt@amd.com 2758336Ssteve.reinhardt@amd.com# 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# 2828336Ssteve.reinhardt@amd.com# Set up global sticky variables... these are common to an entire build 2838336Ssteve.reinhardt@amd.com# 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') 2875871Snate@binkert.org 2886121Snate@binkert.orgglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 289955SN/A 290955SN/Aglobal_vars.AddVariables( 2912632Sstever@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 2922632Sstever@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 293955SN/A ('CCFLAGS_EXTRA', 'Extra C and C++ compiler flags', ''), 294955SN/A ('LDFLAGS_EXTRA', 'Extra linker flags', ''), 295955SN/A ('PYTHON_CONFIG', 'Python config binary to use', 296955SN/A [ 'python2.7-config', 'python-config' ]), 2978878Ssteve.reinhardt@amd.com ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')), 298955SN/A ('BATCH', 'Use batch pool for build and tests', False), 2992632Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3002632Sstever@eecs.umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3012632Sstever@eecs.umich.edu ('EXTRAS', 'Add extra directories to the compilation', '') 3022632Sstever@eecs.umich.edu ) 3032632Sstever@eecs.umich.edu 3042632Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_vars_file 3052632Sstever@eecs.umich.eduglobal_vars.Update(main) 3068268Ssteve.reinhardt@amd.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3078268Ssteve.reinhardt@amd.com 3088268Ssteve.reinhardt@amd.com# Save sticky variable settings back to current variables file 3098268Ssteve.reinhardt@amd.comglobal_vars.Save(global_vars_file, main) 3108268Ssteve.reinhardt@amd.com 3118268Ssteve.reinhardt@amd.com# Parse EXTRAS variable to build list of all directories where we're 3128268Ssteve.reinhardt@amd.com# look for sources etc. This list is exported as extras_dir_list. 3132632Sstever@eecs.umich.edubase_dir = main.srcdir.abspath 3142632Sstever@eecs.umich.eduif main['EXTRAS']: 3152632Sstever@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3162632Sstever@eecs.umich.eduelse: 3178268Ssteve.reinhardt@amd.com extras_dir_list = [] 3182632Sstever@eecs.umich.edu 3198268Ssteve.reinhardt@amd.comExport('base_dir') 3208268Ssteve.reinhardt@amd.comExport('extras_dir_list') 3218268Ssteve.reinhardt@amd.com 3228268Ssteve.reinhardt@amd.com# the ext directory should be on the #includes path 3233718Sstever@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3242634Sstever@eecs.umich.edu 3252634Sstever@eecs.umich.edu# Add shared top-level headers 3265863Snate@binkert.orgmain.Prepend(CPPPATH=Dir('include')) 3272638Sstever@eecs.umich.edu 3288268Ssteve.reinhardt@amd.comif GetOption('verbose'): 3292632Sstever@eecs.umich.edu def MakeAction(action, string, *args, **kwargs): 3302632Sstever@eecs.umich.edu return Action(action, *args, **kwargs) 3312632Sstever@eecs.umich.eduelse: 3322632Sstever@eecs.umich.edu MakeAction = Action 3332632Sstever@eecs.umich.edu main['CCCOMSTR'] = Transform("CC") 3341858SN/A main['CXXCOMSTR'] = Transform("CXX") 3353716Sstever@eecs.umich.edu main['ASCOMSTR'] = Transform("AS") 3362638Sstever@eecs.umich.edu main['ARCOMSTR'] = Transform("AR", 0) 3372638Sstever@eecs.umich.edu main['LINKCOMSTR'] = Transform("LINK", 0) 3382638Sstever@eecs.umich.edu main['SHLINKCOMSTR'] = Transform("SHLINK", 0) 3392638Sstever@eecs.umich.edu main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 3402638Sstever@eecs.umich.edu main['M4COMSTR'] = Transform("M4") 3412638Sstever@eecs.umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 3422638Sstever@eecs.umich.edu main['SHCXXCOMSTR'] = Transform("SHCXX") 3435863Snate@binkert.orgExport('MakeAction') 3445863Snate@binkert.org 3455863Snate@binkert.org# Initialize the Link-Time Optimization (LTO) flags 346955SN/Amain['LTO_CCFLAGS'] = [] 3475341Sstever@gmail.commain['LTO_LDFLAGS'] = [] 3485341Sstever@gmail.com 3495863Snate@binkert.org# According to the readme, tcmalloc works best if the compiler doesn't 3507756SAli.Saidi@ARM.com# assume that we're using the builtin malloc and friends. These flags 3515341Sstever@gmail.com# are compiler-specific, so we need to set them after we detect which 3526121Snate@binkert.org# compiler we're using. 3534494Ssaidi@eecs.umich.edumain['TCMALLOC_CCFLAGS'] = [] 3546121Snate@binkert.org 3551105SN/ACXX_version = readCommand([main['CXX'],'--version'], exception=False) 3562667Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 3572667Sstever@eecs.umich.edu 3582667Sstever@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3592667Sstever@eecs.umich.edumain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 3606121Snate@binkert.orgif main['GCC'] + main['CLANG'] > 1: 3612667Sstever@eecs.umich.edu print('Error: How can we have two at the same time?') 3625341Sstever@gmail.com Exit(1) 3635863Snate@binkert.org 3645341Sstever@gmail.com# Set up default C++ compiler flags 3655341Sstever@gmail.comif main['GCC'] or main['CLANG']: 3665341Sstever@gmail.com # As gcc and clang share many flags, do the common parts here 3678120Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-pipe']) 3685341Sstever@gmail.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 3698120Sgblack@eecs.umich.edu # Enable -Wall and -Wextra and then disable the few warnings that 3705341Sstever@gmail.com # we consistently violate 3718120Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wundef', '-Wextra', 3726121Snate@binkert.org '-Wno-sign-compare', '-Wno-unused-parameter']) 3736121Snate@binkert.org # We always compile using C++11 3748980Ssteve.reinhardt@amd.com main.Append(CXXFLAGS=['-std=c++11']) 3759396Sandreas.hansson@arm.com if sys.platform.startswith('freebsd'): 3765397Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-I/usr/local/include']) 3775397Ssaidi@eecs.umich.edu main.Append(CXXFLAGS=['-I/usr/local/include']) 3787727SAli.Saidi@ARM.com 3798268Ssteve.reinhardt@amd.com main['FILTER_PSHLINKFLAGS'] = lambda x: str(x).replace(' -shared', '') 3806168Snate@binkert.org main['PSHLINKFLAGS'] = main.subst('${FILTER_PSHLINKFLAGS(SHLINKFLAGS)}') 3815341Sstever@gmail.com if GetOption('gold_linker'): 3828120Sgblack@eecs.umich.edu main.Append(LINKFLAGS='-fuse-ld=gold') 3838120Sgblack@eecs.umich.edu main['PLINKFLAGS'] = main.subst('${LINKFLAGS}') 3848120Sgblack@eecs.umich.edu shared_partial_flags = ['-r', '-nostdlib'] 3856814Sgblack@eecs.umich.edu main.Append(PSHLINKFLAGS=shared_partial_flags) 3865863Snate@binkert.org main.Append(PLINKFLAGS=shared_partial_flags) 3878120Sgblack@eecs.umich.edu 3885341Sstever@gmail.com # Treat warnings as errors but white list some warnings that we 3895863Snate@binkert.org # want to allow (e.g., deprecation warnings). 3908268Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-Werror', 3916121Snate@binkert.org '-Wno-error=deprecated-declarations', 3926121Snate@binkert.org '-Wno-error=deprecated', 3938268Ssteve.reinhardt@amd.com ]) 3945742Snate@binkert.orgelse: 3955742Snate@binkert.org print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 3965341Sstever@gmail.com print("Don't know what compiler options to use for your compiler.") 3975742Snate@binkert.org print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 3985742Snate@binkert.org print(termcap.Yellow + ' version:' + termcap.Normal, end = ' ') 3995341Sstever@gmail.com if not CXX_version: 4006017Snate@binkert.org print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 4016121Snate@binkert.org termcap.Normal) 4026017Snate@binkert.org else: 4037816Ssteve.reinhardt@amd.com print(CXX_version.replace('\n', '<nl>')) 4047756SAli.Saidi@ARM.com print(" If you're trying to use a compiler other than GCC") 4057756SAli.Saidi@ARM.com print(" or clang, there appears to be something wrong with your") 4067756SAli.Saidi@ARM.com print(" environment.") 4077756SAli.Saidi@ARM.com print(" ") 4087756SAli.Saidi@ARM.com print(" If you are trying to use a compiler other than those listed") 4097756SAli.Saidi@ARM.com print(" above you will need to ease fix SConstruct and ") 4107756SAli.Saidi@ARM.com print(" src/SConscript to support that compiler.") 4117756SAli.Saidi@ARM.com Exit(1) 4127816Ssteve.reinhardt@amd.com 4137816Ssteve.reinhardt@amd.comif main['GCC']: 4147816Ssteve.reinhardt@amd.com # Check for a supported version of gcc. >= 4.8 is chosen for its 4157816Ssteve.reinhardt@amd.com # level of c++11 support. See 4167816Ssteve.reinhardt@amd.com # http://gcc.gnu.org/projects/cxx0x.html for details. 4177816Ssteve.reinhardt@amd.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4187816Ssteve.reinhardt@amd.com if compareVersions(gcc_version, "4.8") < 0: 4197816Ssteve.reinhardt@amd.com print('Error: gcc version 4.8 or newer required.') 4207816Ssteve.reinhardt@amd.com print(' Installed version: ', gcc_version) 4217816Ssteve.reinhardt@amd.com Exit(1) 4227756SAli.Saidi@ARM.com 4237816Ssteve.reinhardt@amd.com main['GCC_VERSION'] = gcc_version 4247816Ssteve.reinhardt@amd.com 4257816Ssteve.reinhardt@amd.com if compareVersions(gcc_version, '4.9') >= 0: 4267816Ssteve.reinhardt@amd.com # Incremental linking with LTO is currently broken in gcc versions 4277816Ssteve.reinhardt@amd.com # 4.9 and above. A version where everything works completely hasn't 4287816Ssteve.reinhardt@amd.com # yet been identified. 4297816Ssteve.reinhardt@amd.com # 4307816Ssteve.reinhardt@amd.com # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67548 4317816Ssteve.reinhardt@amd.com main['BROKEN_INCREMENTAL_LTO'] = True 4327816Ssteve.reinhardt@amd.com if compareVersions(gcc_version, '6.0') >= 0: 4337816Ssteve.reinhardt@amd.com # gcc versions 6.0 and greater accept an -flinker-output flag which 4347816Ssteve.reinhardt@amd.com # selects what type of output the linker should generate. This is 4357816Ssteve.reinhardt@amd.com # necessary for incremental lto to work, but is also broken in 4367816Ssteve.reinhardt@amd.com # current versions of gcc. It may not be necessary in future 4377816Ssteve.reinhardt@amd.com # versions. We add it here since it might be, and as a reminder that 4387816Ssteve.reinhardt@amd.com # it exists. It's excluded if lto is being forced. 4397816Ssteve.reinhardt@amd.com # 4407816Ssteve.reinhardt@amd.com # https://gcc.gnu.org/gcc-6/changes.html 4417816Ssteve.reinhardt@amd.com # https://gcc.gnu.org/ml/gcc-patches/2015-11/msg03161.html 4427816Ssteve.reinhardt@amd.com # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69866 4437816Ssteve.reinhardt@amd.com if not GetOption('force_lto'): 4447816Ssteve.reinhardt@amd.com main.Append(PSHLINKFLAGS='-flinker-output=rel') 4457816Ssteve.reinhardt@amd.com main.Append(PLINKFLAGS='-flinker-output=rel') 4467816Ssteve.reinhardt@amd.com 4477816Ssteve.reinhardt@amd.com # Make sure we warn if the user has requested to compile with the 4487816Ssteve.reinhardt@amd.com # Undefined Benahvior Sanitizer and this version of gcc does not 4497816Ssteve.reinhardt@amd.com # support it. 4507816Ssteve.reinhardt@amd.com if GetOption('with_ubsan') and \ 4517816Ssteve.reinhardt@amd.com compareVersions(gcc_version, '4.9') < 0: 4527816Ssteve.reinhardt@amd.com print(termcap.Yellow + termcap.Bold + 4537816Ssteve.reinhardt@amd.com 'Warning: UBSan is only supported using gcc 4.9 and later.' + 4547816Ssteve.reinhardt@amd.com termcap.Normal) 4557816Ssteve.reinhardt@amd.com 4567816Ssteve.reinhardt@amd.com disable_lto = GetOption('no_lto') 4577816Ssteve.reinhardt@amd.com if not disable_lto and main.get('BROKEN_INCREMENTAL_LTO', False) and \ 4587816Ssteve.reinhardt@amd.com not GetOption('force_lto'): 4597816Ssteve.reinhardt@amd.com print(termcap.Yellow + termcap.Bold + 4607816Ssteve.reinhardt@amd.com 'Warning: Your compiler doesn\'t support incremental linking' + 4617816Ssteve.reinhardt@amd.com ' and lto at the same time, so lto is being disabled. To force' + 4627816Ssteve.reinhardt@amd.com ' lto on anyway, use the --force-lto option. That will disable' + 4637816Ssteve.reinhardt@amd.com ' partial linking.' + 4647816Ssteve.reinhardt@amd.com termcap.Normal) 4657816Ssteve.reinhardt@amd.com disable_lto = True 4667816Ssteve.reinhardt@amd.com 4677816Ssteve.reinhardt@amd.com # Add the appropriate Link-Time Optimization (LTO) flags 4687816Ssteve.reinhardt@amd.com # unless LTO is explicitly turned off. Note that these flags 4697816Ssteve.reinhardt@amd.com # are only used by the fast target. 4707816Ssteve.reinhardt@amd.com if not disable_lto: 4717816Ssteve.reinhardt@amd.com # Pass the LTO flag when compiling to produce GIMPLE 4727816Ssteve.reinhardt@amd.com # output, we merely create the flags here and only append 4737816Ssteve.reinhardt@amd.com # them later 4747816Ssteve.reinhardt@amd.com main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 4757816Ssteve.reinhardt@amd.com 4767816Ssteve.reinhardt@amd.com # Use the same amount of jobs for LTO as we are running 4777816Ssteve.reinhardt@amd.com # scons with 4787816Ssteve.reinhardt@amd.com main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 4797816Ssteve.reinhardt@amd.com 4807816Ssteve.reinhardt@amd.com main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', 4817816Ssteve.reinhardt@amd.com '-fno-builtin-realloc', '-fno-builtin-free']) 4827816Ssteve.reinhardt@amd.com 4837816Ssteve.reinhardt@amd.com # The address sanitizer is available for gcc >= 4.8 4848947Sandreas.hansson@arm.com if GetOption('with_asan'): 4858947Sandreas.hansson@arm.com if GetOption('with_ubsan') and \ 4867756SAli.Saidi@ARM.com compareVersions(main['GCC_VERSION'], '4.9') >= 0: 4878120Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-fsanitize=address,undefined', 4887756SAli.Saidi@ARM.com '-fno-omit-frame-pointer'], 4897756SAli.Saidi@ARM.com LINKFLAGS='-fsanitize=address,undefined') 4907756SAli.Saidi@ARM.com else: 4917756SAli.Saidi@ARM.com main.Append(CCFLAGS=['-fsanitize=address', 4927816Ssteve.reinhardt@amd.com '-fno-omit-frame-pointer'], 4937816Ssteve.reinhardt@amd.com LINKFLAGS='-fsanitize=address') 4947816Ssteve.reinhardt@amd.com # Only gcc >= 4.9 supports UBSan, so check both the version 4957816Ssteve.reinhardt@amd.com # and the command-line option before adding the compiler and 4967816Ssteve.reinhardt@amd.com # linker flags. 4977816Ssteve.reinhardt@amd.com elif GetOption('with_ubsan') and \ 4987816Ssteve.reinhardt@amd.com compareVersions(main['GCC_VERSION'], '4.9') >= 0: 4997816Ssteve.reinhardt@amd.com main.Append(CCFLAGS='-fsanitize=undefined') 5007816Ssteve.reinhardt@amd.com main.Append(LINKFLAGS='-fsanitize=undefined') 5017816Ssteve.reinhardt@amd.com 5027756SAli.Saidi@ARM.comelif main['CLANG']: 5037756SAli.Saidi@ARM.com # Check for a supported version of clang, >= 3.1 is needed to 5049227Sandreas.hansson@arm.com # support similar features as gcc 4.8. See 5059227Sandreas.hansson@arm.com # http://clang.llvm.org/cxx_status.html for details 5069227Sandreas.hansson@arm.com clang_version_re = re.compile(".* version (\d+\.\d+)") 5079227Sandreas.hansson@arm.com clang_version_match = clang_version_re.search(CXX_version) 5086654Snate@binkert.org if (clang_version_match): 5096654Snate@binkert.org clang_version = clang_version_match.groups()[0] 5105871Snate@binkert.org if compareVersions(clang_version, "3.1") < 0: 5116121Snate@binkert.org print('Error: clang version 3.1 or newer required.') 5128946Sandreas.hansson@arm.com print(' Installed version:', clang_version) 5139419Sandreas.hansson@arm.com Exit(1) 5143940Ssaidi@eecs.umich.edu else: 5153918Ssaidi@eecs.umich.edu print('Error: Unable to determine clang version.') 5163918Ssaidi@eecs.umich.edu Exit(1) 5171858SN/A 5186121Snate@binkert.org # clang has a few additional warnings that we disable, extraneous 5199420Sandreas.hansson@arm.com # parantheses are allowed due to Ruby's printing of the AST, 5209420Sandreas.hansson@arm.com # finally self assignments are allowed as the generated CPU code 5219420Sandreas.hansson@arm.com # is relying on this 5229420Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-parentheses', 5239420Sandreas.hansson@arm.com '-Wno-self-assign', 5249420Sandreas.hansson@arm.com # Some versions of libstdc++ (4.8?) seem to 5259420Sandreas.hansson@arm.com # use struct hash and class hash 5269420Sandreas.hansson@arm.com # interchangeably. 5279420Sandreas.hansson@arm.com '-Wno-mismatched-tags', 5287739Sgblack@eecs.umich.edu ]) 5297739Sgblack@eecs.umich.edu 5306143Snate@binkert.org main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) 5319420Sandreas.hansson@arm.com 5329420Sandreas.hansson@arm.com # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as 5339420Sandreas.hansson@arm.com # opposed to libstdc++, as the later is dated. 5347618SAli.Saidi@arm.com if sys.platform == "darwin": 5357618SAli.Saidi@arm.com main.Append(CXXFLAGS=['-stdlib=libc++']) 5367618SAli.Saidi@arm.com main.Append(LIBS=['c++']) 5377739Sgblack@eecs.umich.edu 5389227Sandreas.hansson@arm.com # On FreeBSD we need libthr. 5399227Sandreas.hansson@arm.com if sys.platform.startswith('freebsd'): 5409227Sandreas.hansson@arm.com main.Append(LIBS=['thr']) 5419227Sandreas.hansson@arm.com 5429227Sandreas.hansson@arm.com # We require clang >= 3.1, so there is no need to check any 5439227Sandreas.hansson@arm.com # versions here. 5449227Sandreas.hansson@arm.com if GetOption('with_ubsan'): 5459227Sandreas.hansson@arm.com if GetOption('with_asan'): 5469227Sandreas.hansson@arm.com main.Append(CCFLAGS=['-fsanitize=address,undefined', 5479227Sandreas.hansson@arm.com '-fno-omit-frame-pointer'], 5489227Sandreas.hansson@arm.com LINKFLAGS='-fsanitize=address,undefined') 5499227Sandreas.hansson@arm.com else: 5509227Sandreas.hansson@arm.com main.Append(CCFLAGS='-fsanitize=undefined', 5519227Sandreas.hansson@arm.com LINKFLAGS='-fsanitize=undefined') 5529227Sandreas.hansson@arm.com 5539227Sandreas.hansson@arm.com elif GetOption('with_asan'): 5549227Sandreas.hansson@arm.com main.Append(CCFLAGS=['-fsanitize=address', 5559227Sandreas.hansson@arm.com '-fno-omit-frame-pointer'], 5568737Skoansin.tan@gmail.com LINKFLAGS='-fsanitize=address') 5579420Sandreas.hansson@arm.com 5589420Sandreas.hansson@arm.comelse: 5599420Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ') 5608737Skoansin.tan@gmail.com print("Don't know what compiler options to use for your compiler.") 5618737Skoansin.tan@gmail.com print(termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX']) 5628737Skoansin.tan@gmail.com print(termcap.Yellow + ' version:' + termcap.Normal, end=' ') 5638737Skoansin.tan@gmail.com if not CXX_version: 5648737Skoansin.tan@gmail.com print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" + 5658737Skoansin.tan@gmail.com termcap.Normal) 5668737Skoansin.tan@gmail.com else: 5678737Skoansin.tan@gmail.com print(CXX_version.replace('\n', '<nl>')) 5688737Skoansin.tan@gmail.com print(" If you're trying to use a compiler other than GCC") 5698737Skoansin.tan@gmail.com print(" or clang, there appears to be something wrong with your") 5708737Skoansin.tan@gmail.com print(" environment.") 5718737Skoansin.tan@gmail.com print(" ") 5728737Skoansin.tan@gmail.com print(" If you are trying to use a compiler other than those listed") 5738737Skoansin.tan@gmail.com print(" above you will need to ease fix SConstruct and ") 5748737Skoansin.tan@gmail.com print(" src/SConscript to support that compiler.") 5758737Skoansin.tan@gmail.com Exit(1) 5768737Skoansin.tan@gmail.com 5778946Sandreas.hansson@arm.com# Set up common yacc/bison flags (needed for Ruby) 5788946Sandreas.hansson@arm.commain['YACCFLAGS'] = '-d' 5798946Sandreas.hansson@arm.commain['YACCHXXFILESUFFIX'] = '.hh' 5809420Sandreas.hansson@arm.com 5819420Sandreas.hansson@arm.com# Do this after we save setting back, or else we'll tack on an 5829420Sandreas.hansson@arm.com# extra 'qdo' every time we run scons. 5839420Sandreas.hansson@arm.comif main['BATCH']: 5849420Sandreas.hansson@arm.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5859420Sandreas.hansson@arm.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5869420Sandreas.hansson@arm.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5879420Sandreas.hansson@arm.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5889420Sandreas.hansson@arm.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5899420Sandreas.hansson@arm.com 5909420Sandreas.hansson@arm.comif sys.platform == 'cygwin': 5918946Sandreas.hansson@arm.com # cygwin has some header file issues... 5923918Ssaidi@eecs.umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 5939068SAli.Saidi@ARM.com 5949068SAli.Saidi@ARM.com 5959068SAli.Saidi@ARM.comhave_pkg_config = readCommand(['pkg-config', '--version'], exception='') 5969068SAli.Saidi@ARM.com 5979068SAli.Saidi@ARM.com# Check for the protobuf compiler 5989068SAli.Saidi@ARM.comprotoc_version = readCommand([main['PROTOC'], '--version'], 5999068SAli.Saidi@ARM.com exception='').split() 6009068SAli.Saidi@ARM.com 6019068SAli.Saidi@ARM.com# First two words should be "libprotoc x.y.z" 6029419Sandreas.hansson@arm.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc': 6039068SAli.Saidi@ARM.com print(termcap.Yellow + termcap.Bold + 6049068SAli.Saidi@ARM.com 'Warning: Protocol buffer compiler (protoc) not found.\n' + 6059068SAli.Saidi@ARM.com ' Please install protobuf-compiler for tracing support.' + 6069068SAli.Saidi@ARM.com termcap.Normal) 6079068SAli.Saidi@ARM.com main['PROTOC'] = False 6089068SAli.Saidi@ARM.comelse: 6093918Ssaidi@eecs.umich.edu # Based on the availability of the compress stream wrappers, 6103918Ssaidi@eecs.umich.edu # require 2.1.0 6116157Snate@binkert.org min_protoc_version = '2.1.0' 6126157Snate@binkert.org if compareVersions(protoc_version[1], min_protoc_version) < 0: 6136157Snate@binkert.org print(termcap.Yellow + termcap.Bold + 6146157Snate@binkert.org 'Warning: protoc version', min_protoc_version, 6155397Ssaidi@eecs.umich.edu 'or newer required.\n' + 6165397Ssaidi@eecs.umich.edu ' Installed version:', protoc_version[1], 6176121Snate@binkert.org termcap.Normal) 6186121Snate@binkert.org main['PROTOC'] = False 6196121Snate@binkert.org else: 6206121Snate@binkert.org # Attempt to determine the appropriate include path and 6216121Snate@binkert.org # library path using pkg-config, that means we also need to 6226121Snate@binkert.org # check for pkg-config. Note that it is possible to use 6235397Ssaidi@eecs.umich.edu # protobuf without the involvement of pkg-config. Later on we 6241851SN/A # check go a library config check and at that point the test 6251851SN/A # will fail if libprotobuf cannot be found. 6267739Sgblack@eecs.umich.edu if have_pkg_config: 627955SN/A try: 6289396Sandreas.hansson@arm.com # Attempt to establish what linking flags to add for protobuf 6299396Sandreas.hansson@arm.com # using pkg-config 6309396Sandreas.hansson@arm.com main.ParseConfig('pkg-config --cflags --libs-only-L protobuf') 6319396Sandreas.hansson@arm.com except: 6329396Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 6339396Sandreas.hansson@arm.com 'Warning: pkg-config could not get protobuf flags.' + 6349396Sandreas.hansson@arm.com termcap.Normal) 6359396Sandreas.hansson@arm.com 6369396Sandreas.hansson@arm.com 6379396Sandreas.hansson@arm.com# Check for 'timeout' from GNU coreutils. If present, regressions will 6389396Sandreas.hansson@arm.com# be run with a time limit. We require version 8.13 since we rely on 6399396Sandreas.hansson@arm.com# support for the '--foreground' option. 6409396Sandreas.hansson@arm.comif sys.platform.startswith('freebsd'): 6419396Sandreas.hansson@arm.com timeout_lines = readCommand(['gtimeout', '--version'], 6429396Sandreas.hansson@arm.com exception='').splitlines() 6439396Sandreas.hansson@arm.comelse: 6449396Sandreas.hansson@arm.com timeout_lines = readCommand(['timeout', '--version'], 6459396Sandreas.hansson@arm.com exception='').splitlines() 6469396Sandreas.hansson@arm.com# Get the first line and tokenize it 6479396Sandreas.hansson@arm.comtimeout_version = timeout_lines[0].split() if timeout_lines else [] 6489396Sandreas.hansson@arm.commain['TIMEOUT'] = timeout_version and \ 6499396Sandreas.hansson@arm.com compareVersions(timeout_version[-1], '8.13') >= 0 6509396Sandreas.hansson@arm.com 6519396Sandreas.hansson@arm.com# Add a custom Check function to test for structure members. 6529396Sandreas.hansson@arm.comdef CheckMember(context, include, decl, member, include_quotes="<>"): 6539396Sandreas.hansson@arm.com context.Message("Checking for member %s in %s..." % 6549396Sandreas.hansson@arm.com (member, decl)) 6559396Sandreas.hansson@arm.com text = """ 6563053Sstever@eecs.umich.edu#include %(header)s 6576121Snate@binkert.orgint main(){ 6583053Sstever@eecs.umich.edu %(decl)s test; 6593053Sstever@eecs.umich.edu (void)test.%(member)s; 6603053Sstever@eecs.umich.edu return 0; 6613053Sstever@eecs.umich.edu}; 6623053Sstever@eecs.umich.edu""" % { "header" : include_quotes[0] + include + include_quotes[1], 6639072Sandreas.hansson@arm.com "decl" : decl, 6643053Sstever@eecs.umich.edu "member" : member, 6654742Sstever@eecs.umich.edu } 6664742Sstever@eecs.umich.edu 6673053Sstever@eecs.umich.edu ret = context.TryCompile(text, extension=".cc") 6683053Sstever@eecs.umich.edu context.Result(ret) 6693053Sstever@eecs.umich.edu return ret 6708960Ssteve.reinhardt@amd.com 6716654Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 6723053Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 6733053Sstever@eecs.umich.educonf = Configure(main, 6743053Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 6753053Sstever@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 6762667Sstever@eecs.umich.edu custom_tests = { 6774554Sbinkertn@umich.edu 'CheckMember' : CheckMember, 6786121Snate@binkert.org }) 6792667Sstever@eecs.umich.edu 6804554Sbinkertn@umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6814554Sbinkertn@umich.edutry: 6824554Sbinkertn@umich.edu import platform 6836121Snate@binkert.org uname = platform.uname() 6844554Sbinkertn@umich.edu if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6854554Sbinkertn@umich.edu if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6864554Sbinkertn@umich.edu main.Append(CCFLAGS=['-arch', 'x86_64']) 6874781Snate@binkert.org main.Append(CFLAGS=['-arch', 'x86_64']) 6884554Sbinkertn@umich.edu main.Append(LINKFLAGS=['-arch', 'x86_64']) 6894554Sbinkertn@umich.edu main.Append(ASFLAGS=['-arch', 'x86_64']) 6902667Sstever@eecs.umich.eduexcept: 6914554Sbinkertn@umich.edu pass 6924554Sbinkertn@umich.edu 6934554Sbinkertn@umich.edu# Recent versions of scons substitute a "Null" object for Configure() 6944554Sbinkertn@umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 6952667Sstever@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 6964554Sbinkertn@umich.edu# breaking all our configuration checks. We replace it with our own 6972667Sstever@eecs.umich.edu# more optimistic null object that returns True instead. 6984554Sbinkertn@umich.eduif not conf: 6996121Snate@binkert.org def NullCheck(*args, **kwargs): 7002667Sstever@eecs.umich.edu return True 7015522Snate@binkert.org 7025522Snate@binkert.org class NullConf: 7035522Snate@binkert.org def __init__(self, env): 7045522Snate@binkert.org self.env = env 7055522Snate@binkert.org def Finish(self): 7065522Snate@binkert.org return self.env 7075522Snate@binkert.org def __getattr__(self, mname): 7085522Snate@binkert.org return NullCheck 7095522Snate@binkert.org 7105522Snate@binkert.org conf = NullConf(main) 7115522Snate@binkert.org 7125522Snate@binkert.org# Cache build files in the supplied directory. 7135522Snate@binkert.orgif main['M5_BUILD_CACHE']: 7145522Snate@binkert.org print('Using build cache located at', main['M5_BUILD_CACHE']) 7155522Snate@binkert.org CacheDir(main['M5_BUILD_CACHE']) 7165522Snate@binkert.org 7175522Snate@binkert.orgmain['USE_PYTHON'] = not GetOption('without_python') 7185522Snate@binkert.orgif main['USE_PYTHON']: 7195522Snate@binkert.org # Find Python include and library directories for embedding the 7205522Snate@binkert.org # interpreter. We rely on python-config to resolve the appropriate 7215522Snate@binkert.org # includes and linker flags. ParseConfig does not seem to understand 7225522Snate@binkert.org # the more exotic linker flags such as -Xlinker and -export-dynamic so 7235522Snate@binkert.org # we add them explicitly below. If you want to link in an alternate 7245522Snate@binkert.org # version of python, see above for instructions on how to invoke 7255522Snate@binkert.org # scons with the appropriate PATH set. 7265522Snate@binkert.org 7272638Sstever@eecs.umich.edu python_config = find_first_prog(main['PYTHON_CONFIG']) 7282638Sstever@eecs.umich.edu if python_config is None: 7296121Snate@binkert.org print("Error: can't find a suitable python-config, tried %s" % \ 7303716Sstever@eecs.umich.edu main['PYTHON_CONFIG']) 7315522Snate@binkert.org Exit(1) 7329420Sandreas.hansson@arm.com 7335522Snate@binkert.org print("Info: Using Python config: %s" % (python_config, )) 7345522Snate@binkert.org py_includes = readCommand([python_config, '--includes'], 7355522Snate@binkert.org exception='').split() 7365522Snate@binkert.org py_includes = filter(lambda s: match(r'.*\/include\/.*',s), py_includes) 7371858SN/A # Strip the -I from the include folders before adding them to the 7385227Ssaidi@eecs.umich.edu # CPPPATH 7395227Ssaidi@eecs.umich.edu py_includes = map(lambda s: s[2:] if s.startswith('-I') else s, py_includes) 7405227Ssaidi@eecs.umich.edu main.Append(CPPPATH=py_includes) 7415227Ssaidi@eecs.umich.edu 7426654Snate@binkert.org # Read the linker flags and split them into libraries and other link 7436654Snate@binkert.org # flags. The libraries are added later through the call the CheckLib. 7447769SAli.Saidi@ARM.com py_ld_flags = readCommand([python_config, '--ldflags'], 7457769SAli.Saidi@ARM.com exception='').split() 7467769SAli.Saidi@ARM.com py_libs = [] 7477769SAli.Saidi@ARM.com for lib in py_ld_flags: 7485227Ssaidi@eecs.umich.edu if not lib.startswith('-l'): 7495227Ssaidi@eecs.umich.edu main.Append(LINKFLAGS=[lib]) 7505227Ssaidi@eecs.umich.edu else: 7515204Sstever@gmail.com lib = lib[2:] 7525204Sstever@gmail.com if lib not in py_libs: 7535204Sstever@gmail.com py_libs.append(lib) 7545204Sstever@gmail.com 7555204Sstever@gmail.com # verify that this stuff works 7565204Sstever@gmail.com if not conf.CheckHeader('Python.h', '<>'): 7575204Sstever@gmail.com print("Error: Check failed for Python.h header in", py_includes) 7585204Sstever@gmail.com print("Two possible reasons:") 7595204Sstever@gmail.com print("1. Python headers are not installed (You can install the " 7605204Sstever@gmail.com "package python-dev on Ubuntu and RedHat)") 7615204Sstever@gmail.com print("2. SCons is using a wrong C compiler. This can happen if " 7625204Sstever@gmail.com "CC has the wrong value.") 7635204Sstever@gmail.com print("CC = %s" % main['CC']) 7645204Sstever@gmail.com Exit(1) 7655204Sstever@gmail.com 7665204Sstever@gmail.com for lib in py_libs: 7675204Sstever@gmail.com if not conf.CheckLib(lib): 7686121Snate@binkert.org print("Error: can't find library %s required by python" % lib) 7695204Sstever@gmail.com Exit(1) 7703118Sstever@eecs.umich.edu 7713118Sstever@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 7723118Sstever@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7733118Sstever@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7743118Sstever@eecs.umich.edu print("Can't find library with socket calls (e.g. accept())") 7755863Snate@binkert.org Exit(1) 7763118Sstever@eecs.umich.edu 7775863Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 7783118Sstever@eecs.umich.edu# added to the LIBS environment variable. 7797457Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7807457Snate@binkert.org print('Error: did not find needed zlib compression library ' 7815863Snate@binkert.org 'and/or zlib.h header file.') 7825863Snate@binkert.org print(' Please install zlib and try again.') 7835863Snate@binkert.org Exit(1) 7845863Snate@binkert.org 7855863Snate@binkert.org# If we have the protobuf compiler, also make sure we have the 7865863Snate@binkert.org# development libraries. If the check passes, libprotobuf will be 7875863Snate@binkert.org# automatically added to the LIBS environment variable. After 7886003Snate@binkert.org# this, we can use the HAVE_PROTOBUF flag to determine if we have 7895863Snate@binkert.org# got both protoc and libprotobuf available. 7905863Snate@binkert.orgmain['HAVE_PROTOBUF'] = main['PROTOC'] and \ 7915863Snate@binkert.org conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h', 7926120Snate@binkert.org 'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;') 7935863Snate@binkert.org 7945863Snate@binkert.org# Valgrind gets much less confused if you tell it when you're using 7955863Snate@binkert.org# alternative stacks. 7968655Sandreas.hansson@arm.commain['HAVE_VALGRIND'] = conf.CheckCHeader('valgrind/valgrind.h') 7978655Sandreas.hansson@arm.com 7988655Sandreas.hansson@arm.com# If we have the compiler but not the library, print another warning. 7998655Sandreas.hansson@arm.comif main['PROTOC'] and not main['HAVE_PROTOBUF']: 8008655Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 8018655Sandreas.hansson@arm.com 'Warning: did not find protocol buffer library and/or headers.\n' + 8028655Sandreas.hansson@arm.com ' Please install libprotobuf-dev for tracing support.' + 8038655Sandreas.hansson@arm.com termcap.Normal) 8046120Snate@binkert.org 8055863Snate@binkert.org# Check for librt. 8066121Snate@binkert.orghave_posix_clock = \ 8076121Snate@binkert.org conf.CheckLibWithHeader(None, 'time.h', 'C', 8085863Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') or \ 8097727SAli.Saidi@ARM.com conf.CheckLibWithHeader('rt', 'time.h', 'C', 8107727SAli.Saidi@ARM.com 'clock_nanosleep(0,0,NULL,NULL);') 8117727SAli.Saidi@ARM.com 8127727SAli.Saidi@ARM.comhave_posix_timers = \ 8137727SAli.Saidi@ARM.com conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C', 8147727SAli.Saidi@ARM.com 'timer_create(CLOCK_MONOTONIC, NULL, NULL);') 8155863Snate@binkert.org 8163118Sstever@eecs.umich.eduif not GetOption('without_tcmalloc'): 8175863Snate@binkert.org if conf.CheckLib('tcmalloc'): 8189239Sandreas.hansson@arm.com main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 8193118Sstever@eecs.umich.edu elif conf.CheckLib('tcmalloc_minimal'): 8203118Sstever@eecs.umich.edu main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) 8215863Snate@binkert.org else: 8225863Snate@binkert.org print(termcap.Yellow + termcap.Bold + 8235863Snate@binkert.org "You can get a 12% performance improvement by " 8245863Snate@binkert.org "installing tcmalloc (libgoogle-perftools-dev package " 8253118Sstever@eecs.umich.edu "on Ubuntu or RedHat)." + termcap.Normal) 8263483Ssaidi@eecs.umich.edu 8273494Ssaidi@eecs.umich.edu 8283494Ssaidi@eecs.umich.edu# Detect back trace implementations. The last implementation in the 8293483Ssaidi@eecs.umich.edu# list will be used by default. 8303483Ssaidi@eecs.umich.edubacktrace_impls = [ "none" ] 8313483Ssaidi@eecs.umich.edu 8323053Sstever@eecs.umich.edubacktrace_checker = 'char temp;' + \ 8333053Sstever@eecs.umich.edu ' backtrace_symbols_fd((void*)&temp, 0, 0);' 8343918Ssaidi@eecs.umich.eduif conf.CheckLibWithHeader(None, 'execinfo.h', 'C', backtrace_checker): 8353053Sstever@eecs.umich.edu backtrace_impls.append("glibc") 8363053Sstever@eecs.umich.eduelif conf.CheckLibWithHeader('execinfo', 'execinfo.h', 'C', 8373053Sstever@eecs.umich.edu backtrace_checker): 8383053Sstever@eecs.umich.edu # NetBSD and FreeBSD need libexecinfo. 8393053Sstever@eecs.umich.edu backtrace_impls.append("glibc") 8409396Sandreas.hansson@arm.com main.Append(LIBS=['execinfo']) 8419396Sandreas.hansson@arm.com 8429396Sandreas.hansson@arm.comif backtrace_impls[-1] == "none": 8439396Sandreas.hansson@arm.com default_backtrace_impl = "none" 8449396Sandreas.hansson@arm.com print(termcap.Yellow + termcap.Bold + 8459396Sandreas.hansson@arm.com "No suitable back trace implementation found." + 8469396Sandreas.hansson@arm.com termcap.Normal) 8479396Sandreas.hansson@arm.com 8489396Sandreas.hansson@arm.comif not have_posix_clock: 8499396Sandreas.hansson@arm.com print("Can't find library for POSIX clocks.") 8509396Sandreas.hansson@arm.com 8519396Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control) 8529396Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 8539396Sandreas.hansson@arm.comif not have_fenv: 8549396Sandreas.hansson@arm.com print("Warning: Header file <fenv.h> not found.") 8557840Snate@binkert.org print(" This host has no IEEE FP rounding mode control.") 8567865Sgblack@eecs.umich.edu 8577865Sgblack@eecs.umich.edu# Check for <png.h> (libpng library needed if wanting to dump 8587865Sgblack@eecs.umich.edu# frame buffer image in png format) 8597865Sgblack@eecs.umich.eduhave_png = conf.CheckHeader('png.h', '<>') 8607865Sgblack@eecs.umich.eduif not have_png: 8617840Snate@binkert.org print("Warning: Header file <png.h> not found.") 8629045SAli.Saidi@ARM.com print(" This host has no libpng library.") 8639045SAli.Saidi@ARM.com print(" Disabling support for PNG framebuffers.") 8649045SAli.Saidi@ARM.com 8659045SAli.Saidi@ARM.com# Check if we should enable KVM-based hardware virtualization. The API 8669045SAli.Saidi@ARM.com# we rely on exists since version 2.6.36 of the kernel, but somehow 8679045SAli.Saidi@ARM.com# the KVM_API_VERSION does not reflect the change. We test for one of 8689071Sandreas.hansson@arm.com# the types as a fall back. 8699071Sandreas.hansson@arm.comhave_kvm = conf.CheckHeader('linux/kvm.h', '<>') 8709045SAli.Saidi@ARM.comif not have_kvm: 8717840Snate@binkert.org print("Info: Compatible header file <linux/kvm.h> not found, " 8727840Snate@binkert.org "disabling KVM support.") 8737840Snate@binkert.org 8741858SN/A# Check if the TUN/TAP driver is available. 8751858SN/Ahave_tuntap = conf.CheckHeader('linux/if_tun.h', '<>') 8761858SN/Aif not have_tuntap: 8771858SN/A print("Info: Compatible header file <linux/if_tun.h> not found.") 8781858SN/A 8791858SN/A# x86 needs support for xsave. We test for the structure here since we 8805863Snate@binkert.org# won't be able to run new tests by the time we know which ISA we're 8815863Snate@binkert.org# targeting. 8825863Snate@binkert.orghave_kvm_xsave = conf.CheckTypeSize('struct kvm_xsave', 8835863Snate@binkert.org '#include <linux/kvm.h>') != 0 8846121Snate@binkert.org 8851858SN/A# Check if the requested target ISA is compatible with the host 8865863Snate@binkert.orgdef is_isa_kvm_compatible(isa): 8875863Snate@binkert.org try: 8885863Snate@binkert.org import platform 8895863Snate@binkert.org host_isa = platform.machine() 8905863Snate@binkert.org except: 8912139SN/A print("Warning: Failed to determine host ISA.") 8924202Sbinkertn@umich.edu return False 8934202Sbinkertn@umich.edu 8942139SN/A if not have_posix_timers: 8956994Snate@binkert.org print("Warning: Can not enable KVM, host seems to lack support " 8966994Snate@binkert.org "for POSIX timers") 8976994Snate@binkert.org return False 8986994Snate@binkert.org 8996994Snate@binkert.org if isa == "arm": 9006994Snate@binkert.org return host_isa in ( "armv7l", "aarch64" ) 9016994Snate@binkert.org elif isa == "x86": 9026994Snate@binkert.org if host_isa != "x86_64": 9036994Snate@binkert.org return False 9046994Snate@binkert.org 9056994Snate@binkert.org if not have_kvm_xsave: 9066994Snate@binkert.org print("KVM on x86 requires xsave support in kernel headers.") 9076994Snate@binkert.org return False 9086994Snate@binkert.org 9096994Snate@binkert.org return True 9106994Snate@binkert.org else: 9116994Snate@binkert.org return False 9126994Snate@binkert.org 9136994Snate@binkert.org 9146994Snate@binkert.org# Check if the exclude_host attribute is available. We want this to 9156994Snate@binkert.org# get accurate instruction counts in KVM. 9166994Snate@binkert.orgmain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember( 9176994Snate@binkert.org 'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host') 9186994Snate@binkert.org 9196994Snate@binkert.orgdef check_hdf5(): 9206994Snate@binkert.org return \ 9216994Snate@binkert.org conf.CheckLibWithHeader('hdf5', 'hdf5.h', 'C', 9226994Snate@binkert.org 'H5Fcreate("", 0, 0, 0);') and \ 9232155SN/A conf.CheckLibWithHeader('hdf5_cpp', 'H5Cpp.h', 'C++', 9245863Snate@binkert.org 'H5::H5File("", 0);') 9251869SN/A 9261869SN/Adef check_hdf5_pkg(name): 9275863Snate@binkert.org print("Checking for %s using pkg-config..." % name, end="") 9285863Snate@binkert.org if not have_pkg_config: 9294202Sbinkertn@umich.edu print(" pkg-config not found") 9306108Snate@binkert.org return False 9316108Snate@binkert.org 9326108Snate@binkert.org try: 9336108Snate@binkert.org main.ParseConfig('pkg-config --cflags-only-I --libs-only-L %s' % name) 9349219Spower.jg@gmail.com print(" yes") 9359219Spower.jg@gmail.com return True 9369219Spower.jg@gmail.com except: 9379219Spower.jg@gmail.com print(" no") 9389219Spower.jg@gmail.com return False 9399219Spower.jg@gmail.com 9409219Spower.jg@gmail.com# Check if there is a pkg-config configuration for hdf5. If we find 9419219Spower.jg@gmail.com# it, setup the environment to enable linking and header inclusion. We 9424202Sbinkertn@umich.edu# don't actually try to include any headers or link with hdf5 at this 9435863Snate@binkert.org# stage. 9448474Sgblack@eecs.umich.eduif not check_hdf5_pkg('hdf5-serial'): 9458474Sgblack@eecs.umich.edu check_hdf5_pkg('hdf5') 9465742Snate@binkert.org 9478268Ssteve.reinhardt@amd.com# Check if the HDF5 libraries can be found. This check respects the 9488268Ssteve.reinhardt@amd.com# include path and library path provided by pkg-config. We perform 9498268Ssteve.reinhardt@amd.com# this check even if there isn't a pkg-config configuration for hdf5 9505742Snate@binkert.org# since some installations don't use pkg-config. 9515341Sstever@gmail.comhave_hdf5 = check_hdf5() 9528474Sgblack@eecs.umich.eduif not have_hdf5: 9538474Sgblack@eecs.umich.edu print("Warning: Couldn't find any HDF5 C++ libraries. Disabling") 9545342Sstever@gmail.com print(" HDF5 support.") 9554202Sbinkertn@umich.edu 9564202Sbinkertn@umich.edu###################################################################### 9574202Sbinkertn@umich.edu# 9585863Snate@binkert.org# Finish the configuration 9595863Snate@binkert.org# 9606994Snate@binkert.orgmain = conf.Finish() 9616994Snate@binkert.org 9626994Snate@binkert.org###################################################################### 9635863Snate@binkert.org# 9645863Snate@binkert.org# Collect all non-global variables 9655863Snate@binkert.org# 9665863Snate@binkert.org 9675863Snate@binkert.org# Define the universe of supported ISAs 9685863Snate@binkert.orgall_isa_list = [ ] 9695863Snate@binkert.orgall_gpu_isa_list = [ ] 9705863Snate@binkert.orgExport('all_isa_list') 9717840Snate@binkert.orgExport('all_gpu_isa_list') 9725863Snate@binkert.org 9735952Ssaidi@eecs.umich.educlass CpuModel(object): 9749219Spower.jg@gmail.com '''The CpuModel class encapsulates everything the ISA parser needs to 9759219Spower.jg@gmail.com know about a particular CPU model.''' 9761869SN/A 9771858SN/A # Dict of available CPU model objects. Accessible as CpuModel.dict. 9785863Snate@binkert.org dict = {} 9799420Sandreas.hansson@arm.com 9809420Sandreas.hansson@arm.com # Constructor. Automatically adds models to CpuModel.dict. 9811858SN/A def __init__(self, name, default=False): 982955SN/A self.name = name # name of model 983955SN/A 9841869SN/A # This cpu is enabled by default 9851869SN/A self.default = default 9861869SN/A 9871869SN/A # Add self to dict 9881869SN/A if name in CpuModel.dict: 9895863Snate@binkert.org raise AttributeError, "CpuModel '%s' already registered" % name 9905863Snate@binkert.org CpuModel.dict[name] = self 9915863Snate@binkert.org 9921869SN/AExport('CpuModel') 9935863Snate@binkert.org 9941869SN/A# Sticky variables get saved in the variables file so they persist from 9955863Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 9961869SN/A# value becomes sticky). 9971869SN/Asticky_vars = Variables(args=ARGUMENTS) 9981869SN/AExport('sticky_vars') 9991869SN/A 10008483Sgblack@eecs.umich.edu# Sticky variables that should be exported 10011869SN/Aexport_vars = [] 10021869SN/AExport('export_vars') 10031869SN/A 10041869SN/A# For Ruby 10055863Snate@binkert.orgall_protocols = [] 10065863Snate@binkert.orgExport('all_protocols') 10071869SN/Aprotocol_dirs = [] 10085863Snate@binkert.orgExport('protocol_dirs') 10095863Snate@binkert.orgslicc_includes = [] 10103356Sbinkertn@umich.eduExport('slicc_includes') 10113356Sbinkertn@umich.edu 10123356Sbinkertn@umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 10133356Sbinkertn@umich.edu# above variables 10143356Sbinkertn@umich.eduif GetOption('verbose'): 10154781Snate@binkert.org print("Reading SConsopts") 10165863Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list: 10175863Snate@binkert.org if not isdir(bdir): 10181869SN/A print("Error: directory '%s' does not exist" % bdir) 10191869SN/A Exit(1) 10201869SN/A for root, dirs, files in os.walk(bdir): 10216121Snate@binkert.org if 'SConsopts' in files: 10221869SN/A if GetOption('verbose'): 10232638Sstever@eecs.umich.edu print("Reading", joinpath(root, 'SConsopts')) 10246121Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 10256121Snate@binkert.org 10262638Sstever@eecs.umich.eduall_isa_list.sort() 10275749Scws3k@cs.virginia.eduall_gpu_isa_list.sort() 10286121Snate@binkert.org 10296121Snate@binkert.orgsticky_vars.AddVariables( 10305749Scws3k@cs.virginia.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 10311869SN/A EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'hsail', all_gpu_isa_list), 10321869SN/A ListVariable('CPU_MODELS', 'CPU models', 10333546Sgblack@eecs.umich.edu sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 10343546Sgblack@eecs.umich.edu sorted(CpuModel.dict.keys())), 10353546Sgblack@eecs.umich.edu BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 10363546Sgblack@eecs.umich.edu False), 10376121Snate@binkert.org BoolVariable('SS_COMPATIBLE_FP', 10385863Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 10393546Sgblack@eecs.umich.edu False), 10403546Sgblack@eecs.umich.edu BoolVariable('USE_SSE2', 10413546Sgblack@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 10423546Sgblack@eecs.umich.edu False), 10434781Snate@binkert.org BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 10444781Snate@binkert.org BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 10456658Snate@binkert.org BoolVariable('USE_PNG', 'Enable support for PNG images', have_png), 10466658Snate@binkert.org BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', 10474781Snate@binkert.org False), 10483546Sgblack@eecs.umich.edu BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models', 10493546Sgblack@eecs.umich.edu have_kvm), 10503546Sgblack@eecs.umich.edu BoolVariable('USE_TUNTAP', 10513546Sgblack@eecs.umich.edu 'Enable using a tap device to bridge to the host network', 10527756SAli.Saidi@ARM.com have_tuntap), 10537816Ssteve.reinhardt@amd.com BoolVariable('BUILD_GPU', 'Build the compute-GPU model', False), 10543546Sgblack@eecs.umich.edu EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 10553546Sgblack@eecs.umich.edu all_protocols), 10563546Sgblack@eecs.umich.edu EnumVariable('BACKTRACE_IMPL', 'Post-mortem dump implementation', 10573546Sgblack@eecs.umich.edu backtrace_impls[-1], backtrace_impls), 10584202Sbinkertn@umich.edu ('NUMBER_BITS_PER_SET', 'Max elements in set (default 64)', 10593546Sgblack@eecs.umich.edu 64), 10603546Sgblack@eecs.umich.edu BoolVariable('USE_HDF5', 'Enable the HDF5 support', have_hdf5), 10613546Sgblack@eecs.umich.edu ) 1062955SN/A 1063955SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript). 1064955SN/Aexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA', 1065955SN/A 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP', 10665863Snate@binkert.org 'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_VALGRIND', 10675863Snate@binkert.org 'HAVE_PERF_ATTR_EXCLUDE_HOST', 'USE_PNG', 10685343Sstever@gmail.com 'NUMBER_BITS_PER_SET', 'USE_HDF5'] 10695343Sstever@gmail.com 10706121Snate@binkert.org################################################### 10715863Snate@binkert.org# 10724773Snate@binkert.org# Define a SCons builder for configuration flag headers. 10735863Snate@binkert.org# 10742632Sstever@eecs.umich.edu################################################### 10755863Snate@binkert.org 10762023SN/A# This function generates a config header file that #defines the 10775863Snate@binkert.org# variable symbol to the current variable setting (0 or 1). The source 10785863Snate@binkert.org# operands are the name of the variable and a Value node containing the 10795863Snate@binkert.org# value of the variable. 10805863Snate@binkert.orgdef build_config_file(target, source, env): 10815863Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 10825863Snate@binkert.org f = file(str(target[0]), 'w') 10835863Snate@binkert.org print('#define', variable, value, file=f) 10845863Snate@binkert.org f.close() 10855863Snate@binkert.org return None 10862632Sstever@eecs.umich.edu 10875863Snate@binkert.org# Combine the two functions into a scons Action object. 10882023SN/Aconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 10892632Sstever@eecs.umich.edu 10905863Snate@binkert.org# The emitter munges the source & target node lists to reflect what 10915342Sstever@gmail.com# we're really doing. 10925863Snate@binkert.orgdef config_emitter(target, source, env): 10932632Sstever@eecs.umich.edu # extract variable name from Builder arg 10945863Snate@binkert.org variable = str(target[0]) 10955863Snate@binkert.org # True target is config header file 10968267Ssteve.reinhardt@amd.com target = joinpath('config', variable.lower() + '.hh') 10978120Sgblack@eecs.umich.edu val = env[variable] 10988267Ssteve.reinhardt@amd.com if isinstance(val, bool): 10998267Ssteve.reinhardt@amd.com # Force value to 0/1 11008267Ssteve.reinhardt@amd.com val = int(val) 11018267Ssteve.reinhardt@amd.com elif isinstance(val, str): 11028267Ssteve.reinhardt@amd.com val = '"' + val + '"' 11038267Ssteve.reinhardt@amd.com 11048267Ssteve.reinhardt@amd.com # Sources are variable name & value (packaged in SCons Value nodes) 11058267Ssteve.reinhardt@amd.com return ([target], [Value(variable), Value(val)]) 11068267Ssteve.reinhardt@amd.com 11075863Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 11085863Snate@binkert.org 11095863Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 11102632Sstever@eecs.umich.edu 11118267Ssteve.reinhardt@amd.com################################################### 11128267Ssteve.reinhardt@amd.com# 11138267Ssteve.reinhardt@amd.com# Builders for static and shared partially linked object files. 11142632Sstever@eecs.umich.edu# 11151888SN/A################################################### 11165863Snate@binkert.org 11175863Snate@binkert.orgpartial_static_builder = Builder(action=SCons.Defaults.LinkAction, 11181858SN/A src_suffix='$OBJSUFFIX', 11198120Sgblack@eecs.umich.edu src_builder=['StaticObject', 'Object'], 11208120Sgblack@eecs.umich.edu LINKFLAGS='$PLINKFLAGS', 11217756SAli.Saidi@ARM.com LIBS='') 11222598SN/A 11235863Snate@binkert.orgdef partial_shared_emitter(target, source, env): 11241858SN/A for tgt in target: 11251858SN/A tgt.attributes.shared = 1 11261858SN/A return (target, source) 11275863Snate@binkert.orgpartial_shared_builder = Builder(action=SCons.Defaults.ShLinkAction, 11281858SN/A emitter=partial_shared_emitter, 11291858SN/A src_suffix='$SHOBJSUFFIX', 11301858SN/A src_builder='SharedObject', 11315863Snate@binkert.org SHLINKFLAGS='$PSHLINKFLAGS', 11321871SN/A LIBS='') 11331858SN/A 11341858SN/Amain.Append(BUILDERS = { 'PartialShared' : partial_shared_builder, 11351858SN/A 'PartialStatic' : partial_static_builder }) 11361858SN/A 11375863Snate@binkert.orgdef add_local_rpath(env, *targets): 11385863Snate@binkert.org '''Set up an RPATH for a library which lives in the build directory. 11391869SN/A 11401965SN/A The construction environment variable BIN_RPATH_PREFIX should be set to 11417739Sgblack@eecs.umich.edu the relative path of the build directory starting from the location of the 11421965SN/A binary.''' 11439045SAli.Saidi@ARM.com for target in targets: 11449045SAli.Saidi@ARM.com target = env.Entry(target) 11459045SAli.Saidi@ARM.com if not isinstance(target, SCons.Node.FS.Dir): 11462761Sstever@eecs.umich.edu target = target.dir 11475863Snate@binkert.org relpath = os.path.relpath(target.abspath, env['BUILDDIR']) 11481869SN/A components = [ 11495863Snate@binkert.org '\\$$ORIGIN', 11502667Sstever@eecs.umich.edu '${BIN_RPATH_PREFIX}', 11511869SN/A relpath 11521869SN/A ] 11532929Sktlim@umich.edu env.Append(RPATH=[env.Literal(os.path.join(*components))]) 11542929Sktlim@umich.edu 11555863Snate@binkert.orgif sys.platform != "darwin": 11562929Sktlim@umich.edu main.Append(LINKFLAGS=Split('-z origin')) 1157955SN/A 11588120Sgblack@eecs.umich.edumain.AddMethod(add_local_rpath, 'AddLocalRPATH') 11598120Sgblack@eecs.umich.edu 11608120Sgblack@eecs.umich.edu# builds in ext are shared across all configs in the build root. 11618120Sgblack@eecs.umich.eduext_dir = abspath(joinpath(str(main.root), 'ext')) 11628120Sgblack@eecs.umich.eduext_build_dirs = [] 11638120Sgblack@eecs.umich.edufor root, dirs, files in os.walk(ext_dir): 11648120Sgblack@eecs.umich.edu if 'SConscript' in files: 11658120Sgblack@eecs.umich.edu build_dir = os.path.relpath(root, ext_dir) 11668120Sgblack@eecs.umich.edu ext_build_dirs.append(build_dir) 11678120Sgblack@eecs.umich.edu main.SConscript(joinpath(root, 'SConscript'), 11688120Sgblack@eecs.umich.edu variant_dir=joinpath(build_root, build_dir)) 11698120Sgblack@eecs.umich.edu 1170gdb_xml_dir = joinpath(ext_dir, 'gdb-xml') 1171Export('gdb_xml_dir') 1172 1173main.Prepend(CPPPATH=Dir('ext/pybind11/include/')) 1174 1175################################################### 1176# 1177# This builder and wrapper method are used to set up a directory with 1178# switching headers. Those are headers which are in a generic location and 1179# that include more specific headers from a directory chosen at build time 1180# based on the current build settings. 1181# 1182################################################### 1183 1184def build_switching_header(target, source, env): 1185 path = str(target[0]) 1186 subdir = str(source[0]) 1187 dp, fp = os.path.split(path) 1188 dp = os.path.relpath(os.path.realpath(dp), 1189 os.path.realpath(env['BUILDDIR'])) 1190 with open(path, 'w') as hdr: 1191 print('#include "%s/%s/%s"' % (dp, subdir, fp), file=hdr) 1192 1193switching_header_action = MakeAction(build_switching_header, 1194 Transform('GENERATE')) 1195 1196switching_header_builder = Builder(action=switching_header_action, 1197 source_factory=Value, 1198 single_source=True) 1199 1200main.Append(BUILDERS = { 'SwitchingHeader': switching_header_builder }) 1201 1202def switching_headers(self, headers, source): 1203 for header in headers: 1204 self.SwitchingHeader(header, source) 1205 1206main.AddMethod(switching_headers, 'SwitchingHeaders') 1207 1208################################################### 1209# 1210# Define build environments for selected configurations. 1211# 1212################################################### 1213 1214for variant_path in variant_paths: 1215 if not GetOption('silent'): 1216 print("Building in", variant_path) 1217 1218 # Make a copy of the build-root environment to use for this config. 1219 env = main.Clone() 1220 env['BUILDDIR'] = variant_path 1221 1222 # variant_dir is the tail component of build path, and is used to 1223 # determine the build parameters (e.g., 'ALPHA_SE') 1224 (build_root, variant_dir) = splitpath(variant_path) 1225 1226 # Set env variables according to the build directory config. 1227 sticky_vars.files = [] 1228 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 1229 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 1230 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 1231 current_vars_file = joinpath(build_root, 'variables', variant_dir) 1232 if isfile(current_vars_file): 1233 sticky_vars.files.append(current_vars_file) 1234 if not GetOption('silent'): 1235 print("Using saved variables file %s" % current_vars_file) 1236 elif variant_dir in ext_build_dirs: 1237 # Things in ext are built without a variant directory. 1238 continue 1239 else: 1240 # Build dir-specific variables file doesn't exist. 1241 1242 # Make sure the directory is there so we can create it later 1243 opt_dir = dirname(current_vars_file) 1244 if not isdir(opt_dir): 1245 mkdir(opt_dir) 1246 1247 # Get default build variables from source tree. Variables are 1248 # normally determined by name of $VARIANT_DIR, but can be 1249 # overridden by '--default=' arg on command line. 1250 default = GetOption('default') 1251 opts_dir = joinpath(main.root.abspath, 'build_opts') 1252 if default: 1253 default_vars_files = [joinpath(build_root, 'variables', default), 1254 joinpath(opts_dir, default)] 1255 else: 1256 default_vars_files = [joinpath(opts_dir, variant_dir)] 1257 existing_files = filter(isfile, default_vars_files) 1258 if existing_files: 1259 default_vars_file = existing_files[0] 1260 sticky_vars.files.append(default_vars_file) 1261 print("Variables file %s not found,\n using defaults in %s" 1262 % (current_vars_file, default_vars_file)) 1263 else: 1264 print("Error: cannot find variables file %s or " 1265 "default file(s) %s" 1266 % (current_vars_file, ' or '.join(default_vars_files))) 1267 Exit(1) 1268 1269 # Apply current variable settings to env 1270 sticky_vars.Update(env) 1271 1272 help_texts["local_vars"] += \ 1273 "Build variables for %s:\n" % variant_dir \ 1274 + sticky_vars.GenerateHelpText(env) 1275 1276 # Process variable settings. 1277 1278 if not have_fenv and env['USE_FENV']: 1279 print("Warning: <fenv.h> not available; " 1280 "forcing USE_FENV to False in", variant_dir + ".") 1281 env['USE_FENV'] = False 1282 1283 if not env['USE_FENV']: 1284 print("Warning: No IEEE FP rounding mode control in", 1285 variant_dir + ".") 1286 print(" FP results may deviate slightly from other platforms.") 1287 1288 if not have_png and env['USE_PNG']: 1289 print("Warning: <png.h> not available; " 1290 "forcing USE_PNG to False in", variant_dir + ".") 1291 env['USE_PNG'] = False 1292 1293 if env['USE_PNG']: 1294 env.Append(LIBS=['png']) 1295 1296 if env['EFENCE']: 1297 env.Append(LIBS=['efence']) 1298 1299 if env['USE_KVM']: 1300 if not have_kvm: 1301 print("Warning: Can not enable KVM, host seems to " 1302 "lack KVM support") 1303 env['USE_KVM'] = False 1304 elif not is_isa_kvm_compatible(env['TARGET_ISA']): 1305 print("Info: KVM support disabled due to unsupported host and " 1306 "target ISA combination") 1307 env['USE_KVM'] = False 1308 1309 if env['USE_TUNTAP']: 1310 if not have_tuntap: 1311 print("Warning: Can't connect EtherTap with a tap device.") 1312 env['USE_TUNTAP'] = False 1313 1314 if env['BUILD_GPU']: 1315 env.Append(CPPDEFINES=['BUILD_GPU']) 1316 1317 # Warn about missing optional functionality 1318 if env['USE_KVM']: 1319 if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']: 1320 print("Warning: perf_event headers lack support for the " 1321 "exclude_host attribute. KVM instruction counts will " 1322 "be inaccurate.") 1323 1324 # Save sticky variable settings back to current variables file 1325 sticky_vars.Save(current_vars_file, env) 1326 1327 if env['USE_SSE2']: 1328 env.Append(CCFLAGS=['-msse2']) 1329 1330 env.Append(CCFLAGS='$CCFLAGS_EXTRA') 1331 env.Append(LINKFLAGS='$LDFLAGS_EXTRA') 1332 1333 # The src/SConscript file sets up the build rules in 'env' according 1334 # to the configured variables. It returns a list of environments, 1335 # one for each variant build (debug, opt, etc.) 1336 SConscript('src/SConscript', variant_dir = variant_path, exports = 'env') 1337 1338# base help text 1339Help(''' 1340Usage: scons [scons options] [build variables] [target(s)] 1341 1342Extra scons options: 1343%(options)s 1344 1345Global build variables: 1346%(global_vars)s 1347 1348%(local_vars)s 1349''' % help_texts) 1350