SConstruct revision 14209
1955SN/A# -*- mode:python -*-
2955SN/A
314209Sandreas.sandberg@arm.com# Copyright (c) 2013, 2015-2019 ARM Limited
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# The license below extends only to copyright in the software and shall
79812Sandreas.hansson@arm.com# not be construed as granting a license to any other intellectual
89812Sandreas.hansson@arm.com# property including but not limited to intellectual property relating
99812Sandreas.hansson@arm.com# to a hardware implementation of the functionality of the software
109812Sandreas.hansson@arm.com# licensed hereunder.  You may use the software subject to the license
119812Sandreas.hansson@arm.com# terms below provided that you ensure that this notice is replicated
129812Sandreas.hansson@arm.com# unmodified and in its entirety in all distributions of the software,
139812Sandreas.hansson@arm.com# modified or unmodified, in source code or in binary form.
149812Sandreas.hansson@arm.com#
157816Ssteve.reinhardt@amd.com# Copyright (c) 2011 Advanced Micro Devices, Inc.
165871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company
171762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
18955SN/A# All rights reserved.
19955SN/A#
20955SN/A# Redistribution and use in source and binary forms, with or without
21955SN/A# modification, are permitted provided that the following conditions are
22955SN/A# met: redistributions of source code must retain the above copyright
23955SN/A# notice, this list of conditions and the following disclaimer;
24955SN/A# redistributions in binary form must reproduce the above copyright
25955SN/A# notice, this list of conditions and the following disclaimer in the
26955SN/A# documentation and/or other materials provided with the distribution;
27955SN/A# neither the name of the copyright holders nor the names of its
28955SN/A# contributors may be used to endorse or promote products derived from
29955SN/A# this software without specific prior written permission.
30955SN/A#
31955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
422665Ssaidi@eecs.umich.edu#
432665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
445863Snate@binkert.org#          Nathan Binkert
45955SN/A
46955SN/A###################################################
47955SN/A#
48955SN/A# SCons top-level build description (SConstruct) file.
49955SN/A#
508878Ssteve.reinhardt@amd.com# While in this directory ('gem5'), just type 'scons' to build the default
512632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
528878Ssteve.reinhardt@amd.com# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for
532632Sstever@eecs.umich.edu# the optimized full-system version).
54955SN/A#
558878Ssteve.reinhardt@amd.com# You can build gem5 in a different directory as long as there is a
562632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
572761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
582632Sstever@eecs.umich.edu# built for the same host system.
592632Sstever@eecs.umich.edu#
602632Sstever@eecs.umich.edu# Examples:
612761Sstever@eecs.umich.edu#
622761Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
632761Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
648878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug
658878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug
662761Sstever@eecs.umich.edu#
672761Sstever@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
682761Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
692761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
702761Sstever@eecs.umich.edu#   file.
718878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug
728878Ssteve.reinhardt@amd.com#   % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug
732632Sstever@eecs.umich.edu#
742632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
758878Ssteve.reinhardt@amd.com# 'gem5' directory (or use -u or -C to tell scons where to find this
768878Ssteve.reinhardt@amd.com# file), you can use 'scons -h' to print all the gem5-specific build
772632Sstever@eecs.umich.edu# options as well.
78955SN/A#
79955SN/A###################################################
80955SN/A
8112563Sgabeblack@google.comfrom __future__ import print_function
8212563Sgabeblack@google.com
836654Snate@binkert.org# Global Python includes
8410196SCurtis.Dunham@arm.comimport itertools
85955SN/Aimport os
865396Ssaidi@eecs.umich.eduimport re
8711401Sandreas.sandberg@arm.comimport shutil
885863Snate@binkert.orgimport subprocess
895863Snate@binkert.orgimport sys
904202Sbinkertn@umich.edu
915863Snate@binkert.orgfrom os import mkdir, environ
925863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath
935863Snate@binkert.orgfrom os.path import exists,  isdir, isfile
945863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath
9513541Sandrea.mondelli@ucf.edufrom re import match
96955SN/A
976654Snate@binkert.org# SCons includes
985273Sstever@gmail.comimport SCons
995871Snate@binkert.orgimport SCons.Node
10013758Sgabeblack@google.comimport SCons.Node.FS
1015273Sstever@gmail.com
1026654Snate@binkert.orgfrom m5.util import compareVersions, readCommand
1035396Ssaidi@eecs.umich.edu
1048120Sgblack@eecs.umich.eduhelp_texts = {
1058120Sgblack@eecs.umich.edu    "options" : "",
1068120Sgblack@eecs.umich.edu    "global_vars" : "",
1078120Sgblack@eecs.umich.edu    "local_vars" : ""
1088120Sgblack@eecs.umich.edu}
1098120Sgblack@eecs.umich.edu
1108120Sgblack@eecs.umich.eduExport("help_texts")
1118120Sgblack@eecs.umich.edu
1128879Ssteve.reinhardt@amd.com
1138879Ssteve.reinhardt@amd.com# There's a bug in scons in that (1) by default, the help texts from
1148879Ssteve.reinhardt@amd.com# AddOption() are supposed to be displayed when you type 'scons -h'
1158879Ssteve.reinhardt@amd.com# and (2) you can override the help displayed by 'scons -h' using the
1168879Ssteve.reinhardt@amd.com# Help() function, but these two features are incompatible: once
1178879Ssteve.reinhardt@amd.com# you've overridden the help text using Help(), there's no way to get
1188879Ssteve.reinhardt@amd.com# at the help texts from AddOptions.  See:
1198879Ssteve.reinhardt@amd.com#     http://scons.tigris.org/issues/show_bug.cgi?id=2356
1208879Ssteve.reinhardt@amd.com#     http://scons.tigris.org/issues/show_bug.cgi?id=2611
1218879Ssteve.reinhardt@amd.com# This hack lets us extract the help text from AddOptions and
1228879Ssteve.reinhardt@amd.com# re-inject it via Help().  Ideally someday this bug will be fixed and
1238879Ssteve.reinhardt@amd.com# we can just use AddOption directly.
1248879Ssteve.reinhardt@amd.comdef AddLocalOption(*args, **kwargs):
1258120Sgblack@eecs.umich.edu    col_width = 30
1268120Sgblack@eecs.umich.edu
1278120Sgblack@eecs.umich.edu    help = "  " + ", ".join(args)
1288120Sgblack@eecs.umich.edu    if "help" in kwargs:
1298120Sgblack@eecs.umich.edu        length = len(help)
1308120Sgblack@eecs.umich.edu        if length >= col_width:
1318120Sgblack@eecs.umich.edu            help += "\n" + " " * col_width
1328120Sgblack@eecs.umich.edu        else:
1338120Sgblack@eecs.umich.edu            help += " " * (col_width - length)
1348120Sgblack@eecs.umich.edu        help += kwargs["help"]
1358120Sgblack@eecs.umich.edu    help_texts["options"] += help + "\n"
1368120Sgblack@eecs.umich.edu
1378120Sgblack@eecs.umich.edu    AddOption(*args, **kwargs)
1388120Sgblack@eecs.umich.edu
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")
14310458Sandreas.hansson@arm.comAddLocalOption('--with-cxx-config', dest='with_cxx_config',
14410458Sandreas.hansson@arm.com               action='store_true',
14510458Sandreas.hansson@arm.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')
15013421Sciro.santilli@arm.comAddLocalOption('--gold-linker', dest='gold_linker', action='store_true',
15113421Sciro.santilli@arm.com               help='Use the gold linker')
1529227Sandreas.hansson@arm.comAddLocalOption('--no-lto', dest='no_lto', action='store_true',
1539227Sandreas.hansson@arm.com               help='Disable Link-Time Optimization for fast')
15412063Sgabeblack@google.comAddLocalOption('--force-lto', dest='force_lto', action='store_true',
15512063Sgabeblack@google.com               help='Use Link-Time Optimization instead of partial linking' +
15612063Sgabeblack@google.com                    ' when the compiler doesn\'t support using them together.')
1578879Ssteve.reinhardt@amd.comAddLocalOption('--update-ref', dest='update_ref', action='store_true',
1588879Ssteve.reinhardt@amd.com               help='Update test reference outputs')
1598879Ssteve.reinhardt@amd.comAddLocalOption('--verbose', dest='verbose', action='store_true',
1608879Ssteve.reinhardt@amd.com               help='Print full tool command lines')
16110453SAndrew.Bardsley@arm.comAddLocalOption('--without-python', dest='without_python',
16210453SAndrew.Bardsley@arm.com               action='store_true',
16310453SAndrew.Bardsley@arm.com               help='Build without Python configuration support')
16410456SCurtis.Dunham@arm.comAddLocalOption('--without-tcmalloc', dest='without_tcmalloc',
16510456SCurtis.Dunham@arm.com               action='store_true',
16610456SCurtis.Dunham@arm.com               help='Disable linking against tcmalloc')
16710457Sandreas.hansson@arm.comAddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true',
16810457Sandreas.hansson@arm.com               help='Build with Undefined Behavior Sanitizer if available')
16911342Sandreas.hansson@arm.comAddLocalOption('--with-asan', dest='with_asan', action='store_true',
17011342Sandreas.hansson@arm.com               help='Build with Address Sanitizer if available')
1718120Sgblack@eecs.umich.edu
17212063Sgabeblack@google.comif GetOption('no_lto') and GetOption('force_lto'):
17312563Sgabeblack@google.com    print('--no-lto and --force-lto are mutually exclusive')
17412063Sgabeblack@google.com    Exit(1)
17512063Sgabeblack@google.com
1765871Snate@binkert.org########################################################################
1775871Snate@binkert.org#
1786121Snate@binkert.org# Set up the main build environment.
1795871Snate@binkert.org#
1805871Snate@binkert.org########################################################################
1819926Sstan.czerniawski@arm.com
18212243Sgabeblack@google.commain = Environment()
1831533SN/A
18412246Sgabeblack@google.comfrom gem5_scons import Transform
18512246Sgabeblack@google.comfrom gem5_scons.util import get_termcap
18612246Sgabeblack@google.comtermcap = get_termcap()
18712246Sgabeblack@google.com
1889239Sandreas.hansson@arm.commain_dict_keys = main.Dictionary().keys()
1899239Sandreas.hansson@arm.com
1909239Sandreas.hansson@arm.com# Check that we have a C/C++ compiler
1919239Sandreas.hansson@arm.comif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys):
19212563Sgabeblack@google.com    print("No C++ compiler installed (package g++ on Ubuntu and RedHat)")
1939239Sandreas.hansson@arm.com    Exit(1)
1949239Sandreas.hansson@arm.com
195955SN/A###################################################
196955SN/A#
1972632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
1982632Sstever@eecs.umich.edu# the target(s).
199955SN/A#
200955SN/A###################################################
201955SN/A
202955SN/A# Find default configuration & binary.
2038878Ssteve.reinhardt@amd.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug'))
204955SN/A
2052632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
2062632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
2072632Sstever@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
2082632Sstever@eecs.umich.edu        if l[i] == elt:
2092632Sstever@eecs.umich.edu            return i
2102632Sstever@eecs.umich.edu    raise ValueError, "element not found"
2112632Sstever@eecs.umich.edu
2128268Ssteve.reinhardt@amd.com# Take a list of paths (or SCons Nodes) and return a list with all
2138268Ssteve.reinhardt@amd.com# paths made absolute and ~-expanded.  Paths will be interpreted
2148268Ssteve.reinhardt@amd.com# relative to the launch directory unless a different root is provided
2158268Ssteve.reinhardt@amd.comdef makePathListAbsolute(path_list, root=GetLaunchDir()):
2168268Ssteve.reinhardt@amd.com    return [abspath(joinpath(root, expanduser(str(p))))
2178268Ssteve.reinhardt@amd.com            for p in path_list]
2188268Ssteve.reinhardt@amd.com
21913715Sandreas.sandberg@arm.comdef find_first_prog(prog_names):
22013715Sandreas.sandberg@arm.com    """Find the absolute path to the first existing binary in prog_names"""
22113715Sandreas.sandberg@arm.com
22213715Sandreas.sandberg@arm.com    if not isinstance(prog_names, (list, tuple)):
22313715Sandreas.sandberg@arm.com        prog_names = [ prog_names ]
22413715Sandreas.sandberg@arm.com
22513715Sandreas.sandberg@arm.com    for p in prog_names:
22613715Sandreas.sandberg@arm.com        p = main.WhereIs(p)
22713715Sandreas.sandberg@arm.com        if p is not None:
22813715Sandreas.sandberg@arm.com            return p
22913715Sandreas.sandberg@arm.com
23013715Sandreas.sandberg@arm.com    return None
23113715Sandreas.sandberg@arm.com
2322632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
2332632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
2342632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
2352632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
2368268Ssteve.reinhardt@amd.com# follow 'build' in the build path.
2372632Sstever@eecs.umich.edu
2388268Ssteve.reinhardt@amd.com# The funky assignment to "[:]" is needed to replace the list contents
2398268Ssteve.reinhardt@amd.com# in place rather than reassign the symbol to a new list, which
2408268Ssteve.reinhardt@amd.com# doesn't work (obviously!).
2418268Ssteve.reinhardt@amd.comBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS)
2423718Sstever@eecs.umich.edu
2432634Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the
2442634Sstever@eecs.umich.edu# collected targets reference.
2455863Snate@binkert.orgvariant_paths = []
2462638Sstever@eecs.umich.edubuild_root = None
2478268Ssteve.reinhardt@amd.comfor t in BUILD_TARGETS:
2482632Sstever@eecs.umich.edu    path_dirs = t.split('/')
2492632Sstever@eecs.umich.edu    try:
2502632Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
2512632Sstever@eecs.umich.edu    except:
25212563Sgabeblack@google.com        print("Error: no non-leaf 'build' dir found on target path", t)
2531858SN/A        Exit(1)
2543716Sstever@eecs.umich.edu    this_build_root = joinpath('/',*path_dirs[:build_top+1])
2552638Sstever@eecs.umich.edu    if not build_root:
2562638Sstever@eecs.umich.edu        build_root = this_build_root
2572638Sstever@eecs.umich.edu    else:
2582638Sstever@eecs.umich.edu        if this_build_root != build_root:
25912563Sgabeblack@google.com            print("Error: build targets not under same build root\n"
26012563Sgabeblack@google.com                  "  %s\n  %s" % (build_root, this_build_root))
2612638Sstever@eecs.umich.edu            Exit(1)
2625863Snate@binkert.org    variant_path = joinpath('/',*path_dirs[:build_top+2])
2635863Snate@binkert.org    if variant_path not in variant_paths:
2645863Snate@binkert.org        variant_paths.append(variant_path)
265955SN/A
2665341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there)
2675341Sstever@gmail.comif not isdir(build_root):
2685863Snate@binkert.org    mkdir(build_root)
2697756SAli.Saidi@ARM.commain['BUILDROOT'] = build_root
2705341Sstever@gmail.com
2716121Snate@binkert.orgExport('main')
2724494Ssaidi@eecs.umich.edu
2736121Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign"))
2741105SN/A
2752667Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up
2762667Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
2772667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
2782667Sstever@eecs.umich.edu# (soft) links work better.
2796121Snate@binkert.orgmain.SetOption('duplicate', 'soft-copy')
2802667Sstever@eecs.umich.edu
2815341Sstever@gmail.com#
2825863Snate@binkert.org# Set up global sticky variables... these are common to an entire build
2835341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE)
2845341Sstever@gmail.com#
2855341Sstever@gmail.com
2868120Sgblack@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global')
2875341Sstever@gmail.com
2888120Sgblack@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS)
2895341Sstever@gmail.com
2908120Sgblack@eecs.umich.eduglobal_vars.AddVariables(
2916121Snate@binkert.org    ('CC', 'C compiler', environ.get('CC', main['CC'])),
2926121Snate@binkert.org    ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])),
29314044Sciro.santilli@arm.com    ('CCFLAGS_EXTRA', 'Extra C and C++ compiler flags', ''),
29414044Sciro.santilli@arm.com    ('LDFLAGS_EXTRA', 'Extra linker flags', ''),
29513715Sandreas.sandberg@arm.com    ('PYTHON_CONFIG', 'Python config binary to use',
29613715Sandreas.sandberg@arm.com     [ 'python2.7-config', 'python-config' ]),
2979396Sandreas.hansson@arm.com    ('PROTOC', 'protoc tool', environ.get('PROTOC', 'protoc')),
2985397Ssaidi@eecs.umich.edu    ('BATCH', 'Use batch pool for build and tests', False),
2995397Ssaidi@eecs.umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
3007727SAli.Saidi@ARM.com    ('M5_BUILD_CACHE', 'Cache built objects in this directory', False),
3018268Ssteve.reinhardt@amd.com    ('EXTRAS', 'Add extra directories to the compilation', '')
3026168Snate@binkert.org    )
3035341Sstever@gmail.com
3048120Sgblack@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_vars_file
3058120Sgblack@eecs.umich.eduglobal_vars.Update(main)
3068120Sgblack@eecs.umich.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main)
3076814Sgblack@eecs.umich.edu
3085863Snate@binkert.org# Save sticky variable settings back to current variables file
3098120Sgblack@eecs.umich.eduglobal_vars.Save(global_vars_file, main)
3105341Sstever@gmail.com
3115863Snate@binkert.org# 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.
3136121Snate@binkert.orgbase_dir = main.srcdir.abspath
3146121Snate@binkert.orgif main['EXTRAS']:
3158268Ssteve.reinhardt@amd.com    extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':'))
3165742Snate@binkert.orgelse:
3175742Snate@binkert.org    extras_dir_list = []
3185341Sstever@gmail.com
3195742Snate@binkert.orgExport('base_dir')
3205742Snate@binkert.orgExport('extras_dir_list')
3215341Sstever@gmail.com
3226017Snate@binkert.org# the ext directory should be on the #includes path
3236121Snate@binkert.orgmain.Append(CPPPATH=[Dir('ext')])
3246017Snate@binkert.org
32512158Sandreas.sandberg@arm.com# Add shared top-level headers
32612158Sandreas.sandberg@arm.commain.Prepend(CPPPATH=Dir('include'))
32712158Sandreas.sandberg@arm.com
3288120Sgblack@eecs.umich.eduif GetOption('verbose'):
3297756SAli.Saidi@ARM.com    def MakeAction(action, string, *args, **kwargs):
3307756SAli.Saidi@ARM.com        return Action(action, *args, **kwargs)
3317756SAli.Saidi@ARM.comelse:
3327756SAli.Saidi@ARM.com    MakeAction = Action
3337816Ssteve.reinhardt@amd.com    main['CCCOMSTR']        = Transform("CC")
3347816Ssteve.reinhardt@amd.com    main['CXXCOMSTR']       = Transform("CXX")
3357816Ssteve.reinhardt@amd.com    main['ASCOMSTR']        = Transform("AS")
3367816Ssteve.reinhardt@amd.com    main['ARCOMSTR']        = Transform("AR", 0)
3377816Ssteve.reinhardt@amd.com    main['LINKCOMSTR']      = Transform("LINK", 0)
33811979Sgabeblack@google.com    main['SHLINKCOMSTR']    = Transform("SHLINK", 0)
3397816Ssteve.reinhardt@amd.com    main['RANLIBCOMSTR']    = Transform("RANLIB", 0)
3407816Ssteve.reinhardt@amd.com    main['M4COMSTR']        = Transform("M4")
3417816Ssteve.reinhardt@amd.com    main['SHCCCOMSTR']      = Transform("SHCC")
3427816Ssteve.reinhardt@amd.com    main['SHCXXCOMSTR']     = Transform("SHCXX")
3437756SAli.Saidi@ARM.comExport('MakeAction')
3447756SAli.Saidi@ARM.com
3459227Sandreas.hansson@arm.com# Initialize the Link-Time Optimization (LTO) flags
3469227Sandreas.hansson@arm.commain['LTO_CCFLAGS'] = []
3479227Sandreas.hansson@arm.commain['LTO_LDFLAGS'] = []
3489227Sandreas.hansson@arm.com
3499590Sandreas@sandberg.pp.se# According to the readme, tcmalloc works best if the compiler doesn't
3509590Sandreas@sandberg.pp.se# assume that we're using the builtin malloc and friends. These flags
3519590Sandreas@sandberg.pp.se# are compiler-specific, so we need to set them after we detect which
3529590Sandreas@sandberg.pp.se# compiler we're using.
3539590Sandreas@sandberg.pp.semain['TCMALLOC_CCFLAGS'] = []
3549590Sandreas@sandberg.pp.se
3556654Snate@binkert.orgCXX_version = readCommand([main['CXX'],'--version'], exception=False)
3566654Snate@binkert.orgCXX_V = readCommand([main['CXX'],'-V'], exception=False)
3575871Snate@binkert.org
3586121Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0
3598946Sandreas.hansson@arm.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0
3609419Sandreas.hansson@arm.comif main['GCC'] + main['CLANG'] > 1:
36112563Sgabeblack@google.com    print('Error: How can we have two at the same time?')
3623918Ssaidi@eecs.umich.edu    Exit(1)
3633918Ssaidi@eecs.umich.edu
3641858SN/A# Set up default C++ compiler flags
3659556Sandreas.hansson@arm.comif main['GCC'] or main['CLANG']:
3669556Sandreas.hansson@arm.com    # As gcc and clang share many flags, do the common parts here
3679556Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-pipe'])
3689556Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-fno-strict-aliasing'])
36911294Sandreas.hansson@arm.com    # Enable -Wall and -Wextra and then disable the few warnings that
37011294Sandreas.hansson@arm.com    # we consistently violate
37111294Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-Wall', '-Wundef', '-Wextra',
37211294Sandreas.hansson@arm.com                         '-Wno-sign-compare', '-Wno-unused-parameter'])
37310878Sandreas.hansson@arm.com    # We always compile using C++11
37410878Sandreas.hansson@arm.com    main.Append(CXXFLAGS=['-std=c++11'])
37511811Sbaz21@cam.ac.uk    if sys.platform.startswith('freebsd'):
37611811Sbaz21@cam.ac.uk        main.Append(CCFLAGS=['-I/usr/local/include'])
37711811Sbaz21@cam.ac.uk        main.Append(CXXFLAGS=['-I/usr/local/include'])
37811982Sgabeblack@google.com
37911982Sgabeblack@google.com    main['FILTER_PSHLINKFLAGS'] = lambda x: str(x).replace(' -shared', '')
38011982Sgabeblack@google.com    main['PSHLINKFLAGS'] = main.subst('${FILTER_PSHLINKFLAGS(SHLINKFLAGS)}')
38113421Sciro.santilli@arm.com    if GetOption('gold_linker'):
38213421Sciro.santilli@arm.com        main.Append(LINKFLAGS='-fuse-ld=gold')
38311982Sgabeblack@google.com    main['PLINKFLAGS'] = main.subst('${LINKFLAGS}')
38411992Sgabeblack@google.com    shared_partial_flags = ['-r', '-nostdlib']
38511982Sgabeblack@google.com    main.Append(PSHLINKFLAGS=shared_partial_flags)
38611982Sgabeblack@google.com    main.Append(PLINKFLAGS=shared_partial_flags)
38712305Sgabeblack@google.com
38812305Sgabeblack@google.com    # Treat warnings as errors but white list some warnings that we
38912305Sgabeblack@google.com    # want to allow (e.g., deprecation warnings).
39012305Sgabeblack@google.com    main.Append(CCFLAGS=['-Werror',
39112305Sgabeblack@google.com                         '-Wno-error=deprecated-declarations',
39212305Sgabeblack@google.com                         '-Wno-error=deprecated',
39312305Sgabeblack@google.com                        ])
3949556Sandreas.hansson@arm.comelse:
39512563Sgabeblack@google.com    print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ')
39612563Sgabeblack@google.com    print("Don't know what compiler options to use for your compiler.")
39712563Sgabeblack@google.com    print(termcap.Yellow + '       compiler:' + termcap.Normal, main['CXX'])
39812563Sgabeblack@google.com    print(termcap.Yellow + '       version:' + termcap.Normal, end = ' ')
3999556Sandreas.hansson@arm.com    if not CXX_version:
40012563Sgabeblack@google.com        print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +
40112563Sgabeblack@google.com              termcap.Normal)
4029556Sandreas.hansson@arm.com    else:
40312563Sgabeblack@google.com        print(CXX_version.replace('\n', '<nl>'))
40412563Sgabeblack@google.com    print("       If you're trying to use a compiler other than GCC")
40512563Sgabeblack@google.com    print("       or clang, there appears to be something wrong with your")
40612563Sgabeblack@google.com    print("       environment.")
40712563Sgabeblack@google.com    print("       ")
40812563Sgabeblack@google.com    print("       If you are trying to use a compiler other than those listed")
40912563Sgabeblack@google.com    print("       above you will need to ease fix SConstruct and ")
41012563Sgabeblack@google.com    print("       src/SConscript to support that compiler.")
4119556Sandreas.hansson@arm.com    Exit(1)
4129556Sandreas.hansson@arm.com
4136121Snate@binkert.orgif main['GCC']:
41411500Sandreas.hansson@arm.com    # Check for a supported version of gcc. >= 4.8 is chosen for its
41510238Sandreas.hansson@arm.com    # level of c++11 support. See
41610878Sandreas.hansson@arm.com    # http://gcc.gnu.org/projects/cxx0x.html for details.
4179420Sandreas.hansson@arm.com    gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False)
41811500Sandreas.hansson@arm.com    if compareVersions(gcc_version, "4.8") < 0:
41912563Sgabeblack@google.com        print('Error: gcc version 4.8 or newer required.')
42012563Sgabeblack@google.com        print('       Installed version: ', gcc_version)
4219420Sandreas.hansson@arm.com        Exit(1)
4229420Sandreas.hansson@arm.com
4239420Sandreas.hansson@arm.com    main['GCC_VERSION'] = gcc_version
4249420Sandreas.hansson@arm.com
42512063Sgabeblack@google.com    if compareVersions(gcc_version, '4.9') >= 0:
42612063Sgabeblack@google.com        # Incremental linking with LTO is currently broken in gcc versions
42712063Sgabeblack@google.com        # 4.9 and above. A version where everything works completely hasn't
42812063Sgabeblack@google.com        # yet been identified.
42912063Sgabeblack@google.com        #
43012063Sgabeblack@google.com        # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67548
43112063Sgabeblack@google.com        main['BROKEN_INCREMENTAL_LTO'] = True
43212063Sgabeblack@google.com    if compareVersions(gcc_version, '6.0') >= 0:
43312063Sgabeblack@google.com        # gcc versions 6.0 and greater accept an -flinker-output flag which
43412063Sgabeblack@google.com        # selects what type of output the linker should generate. This is
43512063Sgabeblack@google.com        # necessary for incremental lto to work, but is also broken in
43612063Sgabeblack@google.com        # current versions of gcc. It may not be necessary in future
43712063Sgabeblack@google.com        # versions. We add it here since it might be, and as a reminder that
43812063Sgabeblack@google.com        # it exists. It's excluded if lto is being forced.
43912063Sgabeblack@google.com        #
44012063Sgabeblack@google.com        # https://gcc.gnu.org/gcc-6/changes.html
44112063Sgabeblack@google.com        # https://gcc.gnu.org/ml/gcc-patches/2015-11/msg03161.html
44212063Sgabeblack@google.com        # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69866
44312063Sgabeblack@google.com        if not GetOption('force_lto'):
44412063Sgabeblack@google.com            main.Append(PSHLINKFLAGS='-flinker-output=rel')
44512063Sgabeblack@google.com            main.Append(PLINKFLAGS='-flinker-output=rel')
44612063Sgabeblack@google.com
44710457Sandreas.hansson@arm.com    # Make sure we warn if the user has requested to compile with the
44810457Sandreas.hansson@arm.com    # Undefined Benahvior Sanitizer and this version of gcc does not
44910457Sandreas.hansson@arm.com    # support it.
45010457Sandreas.hansson@arm.com    if GetOption('with_ubsan') and \
45110457Sandreas.hansson@arm.com            compareVersions(gcc_version, '4.9') < 0:
45212563Sgabeblack@google.com        print(termcap.Yellow + termcap.Bold +
45312563Sgabeblack@google.com            'Warning: UBSan is only supported using gcc 4.9 and later.' +
45412563Sgabeblack@google.com            termcap.Normal)
45510457Sandreas.hansson@arm.com
45612063Sgabeblack@google.com    disable_lto = GetOption('no_lto')
45712063Sgabeblack@google.com    if not disable_lto and main.get('BROKEN_INCREMENTAL_LTO', False) and \
45812063Sgabeblack@google.com            not GetOption('force_lto'):
45912563Sgabeblack@google.com        print(termcap.Yellow + termcap.Bold +
46012563Sgabeblack@google.com            'Warning: Your compiler doesn\'t support incremental linking' +
46112563Sgabeblack@google.com            ' and lto at the same time, so lto is being disabled. To force' +
46212563Sgabeblack@google.com            ' lto on anyway, use the --force-lto option. That will disable' +
46312563Sgabeblack@google.com            ' partial linking.' +
46412563Sgabeblack@google.com            termcap.Normal)
46512063Sgabeblack@google.com        disable_lto = True
46612063Sgabeblack@google.com
46710238Sandreas.hansson@arm.com    # Add the appropriate Link-Time Optimization (LTO) flags
46810238Sandreas.hansson@arm.com    # unless LTO is explicitly turned off. Note that these flags
46910238Sandreas.hansson@arm.com    # are only used by the fast target.
47012063Sgabeblack@google.com    if not disable_lto:
47110238Sandreas.hansson@arm.com        # Pass the LTO flag when compiling to produce GIMPLE
47210238Sandreas.hansson@arm.com        # output, we merely create the flags here and only append
47310416Sandreas.hansson@arm.com        # them later
47410238Sandreas.hansson@arm.com        main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')]
4759227Sandreas.hansson@arm.com
47610238Sandreas.hansson@arm.com        # Use the same amount of jobs for LTO as we are running
47710416Sandreas.hansson@arm.com        # scons with
47810416Sandreas.hansson@arm.com        main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')]
4799227Sandreas.hansson@arm.com
4809590Sandreas@sandberg.pp.se    main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc',
4819590Sandreas@sandberg.pp.se                                  '-fno-builtin-realloc', '-fno-builtin-free'])
4829590Sandreas@sandberg.pp.se
48312304Sgabeblack@google.com    # The address sanitizer is available for gcc >= 4.8
48412304Sgabeblack@google.com    if GetOption('with_asan'):
48512304Sgabeblack@google.com        if GetOption('with_ubsan') and \
48612688Sgiacomo.travaglini@arm.com                compareVersions(main['GCC_VERSION'], '4.9') >= 0:
48712688Sgiacomo.travaglini@arm.com            main.Append(CCFLAGS=['-fsanitize=address,undefined',
48812688Sgiacomo.travaglini@arm.com                                 '-fno-omit-frame-pointer'],
48913020Sshunhsingou@google.com                        LINKFLAGS='-fsanitize=address,undefined')
49012304Sgabeblack@google.com        else:
49112688Sgiacomo.travaglini@arm.com            main.Append(CCFLAGS=['-fsanitize=address',
49212688Sgiacomo.travaglini@arm.com                                 '-fno-omit-frame-pointer'],
49313020Sshunhsingou@google.com                        LINKFLAGS='-fsanitize=address')
49412304Sgabeblack@google.com    # Only gcc >= 4.9 supports UBSan, so check both the version
49512304Sgabeblack@google.com    # and the command-line option before adding the compiler and
49612304Sgabeblack@google.com    # linker flags.
49712304Sgabeblack@google.com    elif GetOption('with_ubsan') and \
49812688Sgiacomo.travaglini@arm.com            compareVersions(main['GCC_VERSION'], '4.9') >= 0:
49912688Sgiacomo.travaglini@arm.com        main.Append(CCFLAGS='-fsanitize=undefined')
50012688Sgiacomo.travaglini@arm.com        main.Append(LINKFLAGS='-fsanitize=undefined')
50112304Sgabeblack@google.com
5028737Skoansin.tan@gmail.comelif main['CLANG']:
50310878Sandreas.hansson@arm.com    # Check for a supported version of clang, >= 3.1 is needed to
50411500Sandreas.hansson@arm.com    # support similar features as gcc 4.8. See
5059420Sandreas.hansson@arm.com    # http://clang.llvm.org/cxx_status.html for details
5068737Skoansin.tan@gmail.com    clang_version_re = re.compile(".* version (\d+\.\d+)")
50710106SMitch.Hayenga@arm.com    clang_version_match = clang_version_re.search(CXX_version)
5088737Skoansin.tan@gmail.com    if (clang_version_match):
5098737Skoansin.tan@gmail.com        clang_version = clang_version_match.groups()[0]
51010878Sandreas.hansson@arm.com        if compareVersions(clang_version, "3.1") < 0:
51112563Sgabeblack@google.com            print('Error: clang version 3.1 or newer required.')
51212563Sgabeblack@google.com            print('       Installed version:', clang_version)
5138737Skoansin.tan@gmail.com            Exit(1)
5148737Skoansin.tan@gmail.com    else:
51512563Sgabeblack@google.com        print('Error: Unable to determine clang version.')
5168737Skoansin.tan@gmail.com        Exit(1)
5178737Skoansin.tan@gmail.com
51811294Sandreas.hansson@arm.com    # clang has a few additional warnings that we disable, extraneous
5199556Sandreas.hansson@arm.com    # parantheses are allowed due to Ruby's printing of the AST,
5209556Sandreas.hansson@arm.com    # finally self assignments are allowed as the generated CPU code
5219556Sandreas.hansson@arm.com    # is relying on this
52211294Sandreas.hansson@arm.com    main.Append(CCFLAGS=['-Wno-parentheses',
52310278SAndreas.Sandberg@ARM.com                         '-Wno-self-assign',
52410278SAndreas.Sandberg@ARM.com                         # Some versions of libstdc++ (4.8?) seem to
52510278SAndreas.Sandberg@ARM.com                         # use struct hash and class hash
52610278SAndreas.Sandberg@ARM.com                         # interchangeably.
52710278SAndreas.Sandberg@ARM.com                         '-Wno-mismatched-tags',
52810278SAndreas.Sandberg@ARM.com                         ])
5299556Sandreas.hansson@arm.com
5309590Sandreas@sandberg.pp.se    main.Append(TCMALLOC_CCFLAGS=['-fno-builtin'])
5319590Sandreas@sandberg.pp.se
5329420Sandreas.hansson@arm.com    # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as
5339846Sandreas.hansson@arm.com    # opposed to libstdc++, as the later is dated.
5349846Sandreas.hansson@arm.com    if sys.platform == "darwin":
5359846Sandreas.hansson@arm.com        main.Append(CXXFLAGS=['-stdlib=libc++'])
5369846Sandreas.hansson@arm.com        main.Append(LIBS=['c++'])
5378946Sandreas.hansson@arm.com
53811811Sbaz21@cam.ac.uk    # On FreeBSD we need libthr.
53911811Sbaz21@cam.ac.uk    if sys.platform.startswith('freebsd'):
54011811Sbaz21@cam.ac.uk        main.Append(LIBS=['thr'])
54111811Sbaz21@cam.ac.uk
54212304Sgabeblack@google.com    # We require clang >= 3.1, so there is no need to check any
54312304Sgabeblack@google.com    # versions here.
54412304Sgabeblack@google.com    if GetOption('with_ubsan'):
54512304Sgabeblack@google.com        if GetOption('with_asan'):
54613020Sshunhsingou@google.com            main.Append(CCFLAGS=['-fsanitize=address,undefined',
54713020Sshunhsingou@google.com                                 '-fno-omit-frame-pointer'],
54812304Sgabeblack@google.com                       LINKFLAGS='-fsanitize=address,undefined')
54912304Sgabeblack@google.com        else:
55013020Sshunhsingou@google.com            main.Append(CCFLAGS='-fsanitize=undefined',
55113020Sshunhsingou@google.com                        LINKFLAGS='-fsanitize=undefined')
55212304Sgabeblack@google.com
55312304Sgabeblack@google.com    elif GetOption('with_asan'):
55413020Sshunhsingou@google.com        main.Append(CCFLAGS=['-fsanitize=address',
55513020Sshunhsingou@google.com                             '-fno-omit-frame-pointer'],
55612304Sgabeblack@google.com                   LINKFLAGS='-fsanitize=address')
55712304Sgabeblack@google.com
5583918Ssaidi@eecs.umich.eduelse:
55912563Sgabeblack@google.com    print(termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, end=' ')
56012563Sgabeblack@google.com    print("Don't know what compiler options to use for your compiler.")
56112563Sgabeblack@google.com    print(termcap.Yellow + '       compiler:' + termcap.Normal, main['CXX'])
56212563Sgabeblack@google.com    print(termcap.Yellow + '       version:' + termcap.Normal, end=' ')
5639068SAli.Saidi@ARM.com    if not CXX_version:
56412563Sgabeblack@google.com        print(termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +
56512563Sgabeblack@google.com              termcap.Normal)
5669068SAli.Saidi@ARM.com    else:
56712563Sgabeblack@google.com        print(CXX_version.replace('\n', '<nl>'))
56812563Sgabeblack@google.com    print("       If you're trying to use a compiler other than GCC")
56912563Sgabeblack@google.com    print("       or clang, there appears to be something wrong with your")
57012563Sgabeblack@google.com    print("       environment.")
57112563Sgabeblack@google.com    print("       ")
57212563Sgabeblack@google.com    print("       If you are trying to use a compiler other than those listed")
57312563Sgabeblack@google.com    print("       above you will need to ease fix SConstruct and ")
57412563Sgabeblack@google.com    print("       src/SConscript to support that compiler.")
5753918Ssaidi@eecs.umich.edu    Exit(1)
5763918Ssaidi@eecs.umich.edu
5776157Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby)
5786157Snate@binkert.orgmain['YACCFLAGS'] = '-d'
5796157Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh'
5806157Snate@binkert.org
5815397Ssaidi@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an
5825397Ssaidi@eecs.umich.edu# extra 'qdo' every time we run scons.
5836121Snate@binkert.orgif main['BATCH']:
5846121Snate@binkert.org    main['CC']     = main['BATCH_CMD'] + ' ' + main['CC']
5856121Snate@binkert.org    main['CXX']    = main['BATCH_CMD'] + ' ' + main['CXX']
5866121Snate@binkert.org    main['AS']     = main['BATCH_CMD'] + ' ' + main['AS']
5876121Snate@binkert.org    main['AR']     = main['BATCH_CMD'] + ' ' + main['AR']
5886121Snate@binkert.org    main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB']
5895397Ssaidi@eecs.umich.edu
5901851SN/Aif sys.platform == 'cygwin':
5911851SN/A    # cygwin has some header file issues...
5927739Sgblack@eecs.umich.edu    main.Append(CCFLAGS=["-Wno-uninitialized"])
593955SN/A
59414209Sandreas.sandberg@arm.com
59514209Sandreas.sandberg@arm.comhave_pkg_config = readCommand(['pkg-config', '--version'], exception='')
59614209Sandreas.sandberg@arm.com
5979396Sandreas.hansson@arm.com# Check for the protobuf compiler
5989396Sandreas.hansson@arm.comprotoc_version = readCommand([main['PROTOC'], '--version'],
5999396Sandreas.hansson@arm.com                             exception='').split()
6009396Sandreas.hansson@arm.com
6019396Sandreas.hansson@arm.com# First two words should be "libprotoc x.y.z"
6029396Sandreas.hansson@arm.comif len(protoc_version) < 2 or protoc_version[0] != 'libprotoc':
60312563Sgabeblack@google.com    print(termcap.Yellow + termcap.Bold +
60412563Sgabeblack@google.com        'Warning: Protocol buffer compiler (protoc) not found.\n' +
60512563Sgabeblack@google.com        '         Please install protobuf-compiler for tracing support.' +
60612563Sgabeblack@google.com        termcap.Normal)
6079396Sandreas.hansson@arm.com    main['PROTOC'] = False
6089396Sandreas.hansson@arm.comelse:
6099396Sandreas.hansson@arm.com    # Based on the availability of the compress stream wrappers,
6109396Sandreas.hansson@arm.com    # require 2.1.0
6119396Sandreas.hansson@arm.com    min_protoc_version = '2.1.0'
6129396Sandreas.hansson@arm.com    if compareVersions(protoc_version[1], min_protoc_version) < 0:
61312563Sgabeblack@google.com        print(termcap.Yellow + termcap.Bold +
61412563Sgabeblack@google.com            'Warning: protoc version', min_protoc_version,
61512563Sgabeblack@google.com            'or newer required.\n' +
61612563Sgabeblack@google.com            '         Installed version:', protoc_version[1],
61712563Sgabeblack@google.com            termcap.Normal)
6189477Sandreas.hansson@arm.com        main['PROTOC'] = False
6199477Sandreas.hansson@arm.com    else:
6209477Sandreas.hansson@arm.com        # Attempt to determine the appropriate include path and
6219477Sandreas.hansson@arm.com        # library path using pkg-config, that means we also need to
6229477Sandreas.hansson@arm.com        # check for pkg-config. Note that it is possible to use
6239477Sandreas.hansson@arm.com        # protobuf without the involvement of pkg-config. Later on we
6249477Sandreas.hansson@arm.com        # check go a library config check and at that point the test
6259477Sandreas.hansson@arm.com        # will fail if libprotobuf cannot be found.
62614209Sandreas.sandberg@arm.com        if have_pkg_config:
6279477Sandreas.hansson@arm.com            try:
6289477Sandreas.hansson@arm.com                # Attempt to establish what linking flags to add for protobuf
6299477Sandreas.hansson@arm.com                # using pkg-config
6309477Sandreas.hansson@arm.com                main.ParseConfig('pkg-config --cflags --libs-only-L protobuf')
6319477Sandreas.hansson@arm.com            except:
63212563Sgabeblack@google.com                print(termcap.Yellow + termcap.Bold +
63312563Sgabeblack@google.com                    'Warning: pkg-config could not get protobuf flags.' +
63412563Sgabeblack@google.com                    termcap.Normal)
6359396Sandreas.hansson@arm.com
6362667Sstever@eecs.umich.edu
63710710Sandreas.hansson@arm.com# Check for 'timeout' from GNU coreutils. If present, regressions will
63810710Sandreas.hansson@arm.com# be run with a time limit. We require version 8.13 since we rely on
63910710Sandreas.hansson@arm.com# support for the '--foreground' option.
64011811Sbaz21@cam.ac.ukif sys.platform.startswith('freebsd'):
64111811Sbaz21@cam.ac.uk    timeout_lines = readCommand(['gtimeout', '--version'],
64211811Sbaz21@cam.ac.uk                                exception='').splitlines()
64311811Sbaz21@cam.ac.ukelse:
64411811Sbaz21@cam.ac.uk    timeout_lines = readCommand(['timeout', '--version'],
64511811Sbaz21@cam.ac.uk                                exception='').splitlines()
64610710Sandreas.hansson@arm.com# Get the first line and tokenize it
64710710Sandreas.hansson@arm.comtimeout_version = timeout_lines[0].split() if timeout_lines else []
64810710Sandreas.hansson@arm.commain['TIMEOUT'] =  timeout_version and \
64910710Sandreas.hansson@arm.com    compareVersions(timeout_version[-1], '8.13') >= 0
65010384SCurtis.Dunham@arm.com
6519986Sandreas@sandberg.pp.se# Add a custom Check function to test for structure members.
6529986Sandreas@sandberg.pp.sedef CheckMember(context, include, decl, member, include_quotes="<>"):
6539986Sandreas@sandberg.pp.se    context.Message("Checking for member %s in %s..." %
6549986Sandreas@sandberg.pp.se                    (member, decl))
6559986Sandreas@sandberg.pp.se    text = """
6569986Sandreas@sandberg.pp.se#include %(header)s
6579986Sandreas@sandberg.pp.seint main(){
6589986Sandreas@sandberg.pp.se  %(decl)s test;
6599986Sandreas@sandberg.pp.se  (void)test.%(member)s;
6609986Sandreas@sandberg.pp.se  return 0;
6619986Sandreas@sandberg.pp.se};
6629986Sandreas@sandberg.pp.se""" % { "header" : include_quotes[0] + include + include_quotes[1],
6639986Sandreas@sandberg.pp.se        "decl" : decl,
6649986Sandreas@sandberg.pp.se        "member" : member,
6659986Sandreas@sandberg.pp.se        }
6669986Sandreas@sandberg.pp.se
6679986Sandreas@sandberg.pp.se    ret = context.TryCompile(text, extension=".cc")
6689986Sandreas@sandberg.pp.se    context.Result(ret)
6699986Sandreas@sandberg.pp.se    return ret
6709986Sandreas@sandberg.pp.se
6712638Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
6722638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
6736121Snate@binkert.orgconf = Configure(main,
6743716Sstever@eecs.umich.edu                 conf_dir = joinpath(build_root, '.scons_config'),
6755522Snate@binkert.org                 log_file = joinpath(build_root, 'scons_config.log'),
6769986Sandreas@sandberg.pp.se                 custom_tests = {
6779986Sandreas@sandberg.pp.se        'CheckMember' : CheckMember,
6789986Sandreas@sandberg.pp.se        })
6795522Snate@binkert.org
6805227Ssaidi@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin
6815227Ssaidi@eecs.umich.edutry:
6825227Ssaidi@eecs.umich.edu    import platform
6835227Ssaidi@eecs.umich.edu    uname = platform.uname()
6846654Snate@binkert.org    if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0:
6856654Snate@binkert.org        if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
6867769SAli.Saidi@ARM.com            main.Append(CCFLAGS=['-arch', 'x86_64'])
6877769SAli.Saidi@ARM.com            main.Append(CFLAGS=['-arch', 'x86_64'])
6887769SAli.Saidi@ARM.com            main.Append(LINKFLAGS=['-arch', 'x86_64'])
6897769SAli.Saidi@ARM.com            main.Append(ASFLAGS=['-arch', 'x86_64'])
6905227Ssaidi@eecs.umich.eduexcept:
6915227Ssaidi@eecs.umich.edu    pass
6925227Ssaidi@eecs.umich.edu
6935204Sstever@gmail.com# Recent versions of scons substitute a "Null" object for Configure()
6945204Sstever@gmail.com# when configuration isn't necessary, e.g., if the "--help" option is
6955204Sstever@gmail.com# present.  Unfortuantely this Null object always returns false,
6965204Sstever@gmail.com# breaking all our configuration checks.  We replace it with our own
6975204Sstever@gmail.com# more optimistic null object that returns True instead.
6985204Sstever@gmail.comif not conf:
6995204Sstever@gmail.com    def NullCheck(*args, **kwargs):
7005204Sstever@gmail.com        return True
7015204Sstever@gmail.com
7025204Sstever@gmail.com    class NullConf:
7035204Sstever@gmail.com        def __init__(self, env):
7045204Sstever@gmail.com            self.env = env
7055204Sstever@gmail.com        def Finish(self):
7065204Sstever@gmail.com            return self.env
7075204Sstever@gmail.com        def __getattr__(self, mname):
7085204Sstever@gmail.com            return NullCheck
7095204Sstever@gmail.com
7106121Snate@binkert.org    conf = NullConf(main)
7115204Sstever@gmail.com
7127727SAli.Saidi@ARM.com# Cache build files in the supplied directory.
7137727SAli.Saidi@ARM.comif main['M5_BUILD_CACHE']:
71412563Sgabeblack@google.com    print('Using build cache located at', main['M5_BUILD_CACHE'])
7157727SAli.Saidi@ARM.com    CacheDir(main['M5_BUILD_CACHE'])
7167727SAli.Saidi@ARM.com
71711988Sandreas.sandberg@arm.commain['USE_PYTHON'] = not GetOption('without_python')
71811988Sandreas.sandberg@arm.comif main['USE_PYTHON']:
71910453SAndrew.Bardsley@arm.com    # Find Python include and library directories for embedding the
72010453SAndrew.Bardsley@arm.com    # interpreter. We rely on python-config to resolve the appropriate
72110453SAndrew.Bardsley@arm.com    # includes and linker flags. ParseConfig does not seem to understand
72210453SAndrew.Bardsley@arm.com    # the more exotic linker flags such as -Xlinker and -export-dynamic so
72310453SAndrew.Bardsley@arm.com    # we add them explicitly below. If you want to link in an alternate
72410453SAndrew.Bardsley@arm.com    # version of python, see above for instructions on how to invoke
72510453SAndrew.Bardsley@arm.com    # scons with the appropriate PATH set.
72613715Sandreas.sandberg@arm.com
72713715Sandreas.sandberg@arm.com    python_config = find_first_prog(main['PYTHON_CONFIG'])
72813715Sandreas.sandberg@arm.com    if python_config is None:
72913715Sandreas.sandberg@arm.com        print("Error: can't find a suitable python-config, tried %s" % \
73013715Sandreas.sandberg@arm.com              main['PYTHON_CONFIG'])
73113715Sandreas.sandberg@arm.com        Exit(1)
73213715Sandreas.sandberg@arm.com
73313715Sandreas.sandberg@arm.com    print("Info: Using Python config: %s" % (python_config, ))
73410453SAndrew.Bardsley@arm.com    py_includes = readCommand([python_config, '--includes'],
73510453SAndrew.Bardsley@arm.com                              exception='').split()
73613541Sandrea.mondelli@ucf.edu    py_includes = filter(lambda s: match(r'.*\/include\/.*',s), py_includes)
73710453SAndrew.Bardsley@arm.com    # Strip the -I from the include folders before adding them to the
73810453SAndrew.Bardsley@arm.com    # CPPPATH
73913541Sandrea.mondelli@ucf.edu    py_includes = map(lambda s: s[2:] if s.startswith('-I') else s, py_includes)
74013541Sandrea.mondelli@ucf.edu    main.Append(CPPPATH=py_includes)
7419812Sandreas.hansson@arm.com
74210453SAndrew.Bardsley@arm.com    # Read the linker flags and split them into libraries and other link
74310453SAndrew.Bardsley@arm.com    # flags. The libraries are added later through the call the CheckLib.
74410453SAndrew.Bardsley@arm.com    py_ld_flags = readCommand([python_config, '--ldflags'],
74510453SAndrew.Bardsley@arm.com        exception='').split()
74610453SAndrew.Bardsley@arm.com    py_libs = []
74710453SAndrew.Bardsley@arm.com    for lib in py_ld_flags:
74810453SAndrew.Bardsley@arm.com         if not lib.startswith('-l'):
74910453SAndrew.Bardsley@arm.com             main.Append(LINKFLAGS=[lib])
75010453SAndrew.Bardsley@arm.com         else:
75110453SAndrew.Bardsley@arm.com             lib = lib[2:]
75210453SAndrew.Bardsley@arm.com             if lib not in py_libs:
75310453SAndrew.Bardsley@arm.com                 py_libs.append(lib)
7547727SAli.Saidi@ARM.com
75510453SAndrew.Bardsley@arm.com    # verify that this stuff works
75610453SAndrew.Bardsley@arm.com    if not conf.CheckHeader('Python.h', '<>'):
75712790Smatteo.fusi@bsc.es        print("Error: Check failed for Python.h header in", py_includes)
75812790Smatteo.fusi@bsc.es        print("Two possible reasons:")
75912790Smatteo.fusi@bsc.es        print("1. Python headers are not installed (You can install the "
76012790Smatteo.fusi@bsc.es              "package python-dev on Ubuntu and RedHat)")
76112790Smatteo.fusi@bsc.es        print("2. SCons is using a wrong C compiler. This can happen if "
76212790Smatteo.fusi@bsc.es              "CC has the wrong value.")
76312790Smatteo.fusi@bsc.es        print("CC = %s" % main['CC'])
76410453SAndrew.Bardsley@arm.com        Exit(1)
7653118Sstever@eecs.umich.edu
76610453SAndrew.Bardsley@arm.com    for lib in py_libs:
76710453SAndrew.Bardsley@arm.com        if not conf.CheckLib(lib):
76812563Sgabeblack@google.com            print("Error: can't find library %s required by python" % lib)
76910453SAndrew.Bardsley@arm.com            Exit(1)
7703118Sstever@eecs.umich.edu
7713483Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops
7723494Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
7733494Ssaidi@eecs.umich.edu   if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
77412563Sgabeblack@google.com       print("Can't find library with socket calls (e.g. accept())")
7753483Ssaidi@eecs.umich.edu       Exit(1)
7763483Ssaidi@eecs.umich.edu
7773053Sstever@eecs.umich.edu# Check for zlib.  If the check passes, libz will be automatically
7783053Sstever@eecs.umich.edu# added to the LIBS environment variable.
7793918Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
78012563Sgabeblack@google.com    print('Error: did not find needed zlib compression library '
78112563Sgabeblack@google.com          'and/or zlib.h header file.')
78212563Sgabeblack@google.com    print('       Please install zlib and try again.')
7833053Sstever@eecs.umich.edu    Exit(1)
7843053Sstever@eecs.umich.edu
7859396Sandreas.hansson@arm.com# If we have the protobuf compiler, also make sure we have the
7869396Sandreas.hansson@arm.com# development libraries. If the check passes, libprotobuf will be
7879396Sandreas.hansson@arm.com# automatically added to the LIBS environment variable. After
7889396Sandreas.hansson@arm.com# this, we can use the HAVE_PROTOBUF flag to determine if we have
7899396Sandreas.hansson@arm.com# got both protoc and libprotobuf available.
7909396Sandreas.hansson@arm.commain['HAVE_PROTOBUF'] = main['PROTOC'] and \
7919396Sandreas.hansson@arm.com    conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h',
7929396Sandreas.hansson@arm.com                            'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;')
7939396Sandreas.hansson@arm.com
79412920Sgabeblack@google.com# Valgrind gets much less confused if you tell it when you're using
79512920Sgabeblack@google.com# alternative stacks.
79612920Sgabeblack@google.commain['HAVE_VALGRIND'] = conf.CheckCHeader('valgrind/valgrind.h')
79712920Sgabeblack@google.com
7989477Sandreas.hansson@arm.com# If we have the compiler but not the library, print another warning.
7999396Sandreas.hansson@arm.comif main['PROTOC'] and not main['HAVE_PROTOBUF']:
80012563Sgabeblack@google.com    print(termcap.Yellow + termcap.Bold +
80112563Sgabeblack@google.com        'Warning: did not find protocol buffer library and/or headers.\n' +
80212563Sgabeblack@google.com    '       Please install libprotobuf-dev for tracing support.' +
80312563Sgabeblack@google.com    termcap.Normal)
8049396Sandreas.hansson@arm.com
8057840Snate@binkert.org# Check for librt.
8067865Sgblack@eecs.umich.eduhave_posix_clock = \
8077865Sgblack@eecs.umich.edu    conf.CheckLibWithHeader(None, 'time.h', 'C',
8087865Sgblack@eecs.umich.edu                            'clock_nanosleep(0,0,NULL,NULL);') or \
8097865Sgblack@eecs.umich.edu    conf.CheckLibWithHeader('rt', 'time.h', 'C',
8107865Sgblack@eecs.umich.edu                            'clock_nanosleep(0,0,NULL,NULL);')
8117840Snate@binkert.org
8129900Sandreas@sandberg.pp.sehave_posix_timers = \
8139900Sandreas@sandberg.pp.se    conf.CheckLibWithHeader([None, 'rt'], [ 'time.h', 'signal.h' ], 'C',
8149900Sandreas@sandberg.pp.se                            'timer_create(CLOCK_MONOTONIC, NULL, NULL);')
8159900Sandreas@sandberg.pp.se
81610456SCurtis.Dunham@arm.comif not GetOption('without_tcmalloc'):
81710456SCurtis.Dunham@arm.com    if conf.CheckLib('tcmalloc'):
81810456SCurtis.Dunham@arm.com        main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS'])
81910456SCurtis.Dunham@arm.com    elif conf.CheckLib('tcmalloc_minimal'):
82010456SCurtis.Dunham@arm.com        main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS'])
82110456SCurtis.Dunham@arm.com    else:
82212563Sgabeblack@google.com        print(termcap.Yellow + termcap.Bold +
82312563Sgabeblack@google.com              "You can get a 12% performance improvement by "
82412563Sgabeblack@google.com              "installing tcmalloc (libgoogle-perftools-dev package "
82512563Sgabeblack@google.com              "on Ubuntu or RedHat)." + termcap.Normal)
8269045SAli.Saidi@ARM.com
82711235Sandreas.sandberg@arm.com
82811235Sandreas.sandberg@arm.com# Detect back trace implementations. The last implementation in the
82911235Sandreas.sandberg@arm.com# list will be used by default.
83011235Sandreas.sandberg@arm.combacktrace_impls = [ "none" ]
83111235Sandreas.sandberg@arm.com
83212485Sjang.hanhwi@gmail.combacktrace_checker = 'char temp;' + \
83312485Sjang.hanhwi@gmail.com    ' backtrace_symbols_fd((void*)&temp, 0, 0);'
83412485Sjang.hanhwi@gmail.comif conf.CheckLibWithHeader(None, 'execinfo.h', 'C', backtrace_checker):
83511235Sandreas.sandberg@arm.com    backtrace_impls.append("glibc")
83611811Sbaz21@cam.ac.ukelif conf.CheckLibWithHeader('execinfo', 'execinfo.h', 'C',
83712485Sjang.hanhwi@gmail.com                             backtrace_checker):
83811811Sbaz21@cam.ac.uk    # NetBSD and FreeBSD need libexecinfo.
83911811Sbaz21@cam.ac.uk    backtrace_impls.append("glibc")
84011811Sbaz21@cam.ac.uk    main.Append(LIBS=['execinfo'])
84111235Sandreas.sandberg@arm.com
84211235Sandreas.sandberg@arm.comif backtrace_impls[-1] == "none":
84311235Sandreas.sandberg@arm.com    default_backtrace_impl = "none"
84412563Sgabeblack@google.com    print(termcap.Yellow + termcap.Bold +
84512563Sgabeblack@google.com        "No suitable back trace implementation found." +
84612563Sgabeblack@google.com        termcap.Normal)
84711235Sandreas.sandberg@arm.com
8487840Snate@binkert.orgif not have_posix_clock:
84912563Sgabeblack@google.com    print("Can't find library for POSIX clocks.")
8507840Snate@binkert.org
8511858SN/A# Check for <fenv.h> (C99 FP environment control)
8521858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>')
8531858SN/Aif not have_fenv:
85412563Sgabeblack@google.com    print("Warning: Header file <fenv.h> not found.")
85512563Sgabeblack@google.com    print("         This host has no IEEE FP rounding mode control.")
8561858SN/A
85712230Sgiacomo.travaglini@arm.com# Check for <png.h> (libpng library needed if wanting to dump
85812230Sgiacomo.travaglini@arm.com# frame buffer image in png format)
85912230Sgiacomo.travaglini@arm.comhave_png = conf.CheckHeader('png.h', '<>')
86012230Sgiacomo.travaglini@arm.comif not have_png:
86112563Sgabeblack@google.com    print("Warning: Header file <png.h> not found.")
86212563Sgabeblack@google.com    print("         This host has no libpng library.")
86312563Sgabeblack@google.com    print("         Disabling support for PNG framebuffers.")
86412230Sgiacomo.travaglini@arm.com
8659903Sandreas.hansson@arm.com# Check if we should enable KVM-based hardware virtualization. The API
8669903Sandreas.hansson@arm.com# we rely on exists since version 2.6.36 of the kernel, but somehow
8679903Sandreas.hansson@arm.com# the KVM_API_VERSION does not reflect the change. We test for one of
8689903Sandreas.hansson@arm.com# the types as a fall back.
86910841Sandreas.sandberg@arm.comhave_kvm = conf.CheckHeader('linux/kvm.h', '<>')
8709651SAndreas.Sandberg@ARM.comif not have_kvm:
87112563Sgabeblack@google.com    print("Info: Compatible header file <linux/kvm.h> not found, "
87212563Sgabeblack@google.com          "disabling KVM support.")
8739651SAndreas.Sandberg@ARM.com
87412056Sgabeblack@google.com# Check if the TUN/TAP driver is available.
87512056Sgabeblack@google.comhave_tuntap = conf.CheckHeader('linux/if_tun.h', '<>')
87612056Sgabeblack@google.comif not have_tuntap:
87712563Sgabeblack@google.com    print("Info: Compatible header file <linux/if_tun.h> not found.")
87812056Sgabeblack@google.com
87910841Sandreas.sandberg@arm.com# x86 needs support for xsave. We test for the structure here since we
88010841Sandreas.sandberg@arm.com# won't be able to run new tests by the time we know which ISA we're
88110841Sandreas.sandberg@arm.com# targeting.
88210841Sandreas.sandberg@arm.comhave_kvm_xsave = conf.CheckTypeSize('struct kvm_xsave',
88310841Sandreas.sandberg@arm.com                                    '#include <linux/kvm.h>') != 0
88410841Sandreas.sandberg@arm.com
8859651SAndreas.Sandberg@ARM.com# Check if the requested target ISA is compatible with the host
8869651SAndreas.Sandberg@ARM.comdef is_isa_kvm_compatible(isa):
8879651SAndreas.Sandberg@ARM.com    try:
8889651SAndreas.Sandberg@ARM.com        import platform
8899651SAndreas.Sandberg@ARM.com        host_isa = platform.machine()
8909651SAndreas.Sandberg@ARM.com    except:
89112563Sgabeblack@google.com        print("Warning: Failed to determine host ISA.")
8929651SAndreas.Sandberg@ARM.com        return False
8939651SAndreas.Sandberg@ARM.com
89410841Sandreas.sandberg@arm.com    if not have_posix_timers:
89512563Sgabeblack@google.com        print("Warning: Can not enable KVM, host seems to lack support "
89612563Sgabeblack@google.com              "for POSIX timers")
89710841Sandreas.sandberg@arm.com        return False
89810841Sandreas.sandberg@arm.com
89910841Sandreas.sandberg@arm.com    if isa == "arm":
90010860Sandreas.sandberg@arm.com        return host_isa in ( "armv7l", "aarch64" )
90110841Sandreas.sandberg@arm.com    elif isa == "x86":
90210841Sandreas.sandberg@arm.com        if host_isa != "x86_64":
90310841Sandreas.sandberg@arm.com            return False
90410841Sandreas.sandberg@arm.com
90510841Sandreas.sandberg@arm.com        if not have_kvm_xsave:
90612563Sgabeblack@google.com            print("KVM on x86 requires xsave support in kernel headers.")
90710841Sandreas.sandberg@arm.com            return False
90810841Sandreas.sandberg@arm.com
90910841Sandreas.sandberg@arm.com        return True
91010841Sandreas.sandberg@arm.com    else:
91110841Sandreas.sandberg@arm.com        return False
9129651SAndreas.Sandberg@ARM.com
9139651SAndreas.Sandberg@ARM.com
9149986Sandreas@sandberg.pp.se# Check if the exclude_host attribute is available. We want this to
9159986Sandreas@sandberg.pp.se# get accurate instruction counts in KVM.
9169986Sandreas@sandberg.pp.semain['HAVE_PERF_ATTR_EXCLUDE_HOST'] = conf.CheckMember(
9179986Sandreas@sandberg.pp.se    'linux/perf_event.h', 'struct perf_event_attr', 'exclude_host')
9189986Sandreas@sandberg.pp.se
91914209Sandreas.sandberg@arm.comdef check_hdf5():
92014209Sandreas.sandberg@arm.com    return \
92114209Sandreas.sandberg@arm.com        conf.CheckLibWithHeader('hdf5', 'hdf5.h', 'C',
92214209Sandreas.sandberg@arm.com                                'H5Fcreate("", 0, 0, 0);') and \
92314209Sandreas.sandberg@arm.com        conf.CheckLibWithHeader('hdf5_cpp', 'H5Cpp.h', 'C++',
92414209Sandreas.sandberg@arm.com                                'H5::H5File("", 0);')
92514209Sandreas.sandberg@arm.com
92614209Sandreas.sandberg@arm.comdef check_hdf5_pkg(name):
92714209Sandreas.sandberg@arm.com    print("Checking for %s using pkg-config..." % name, end="")
92814209Sandreas.sandberg@arm.com    if not have_pkg_config:
92914209Sandreas.sandberg@arm.com        print(" pkg-config not found")
93014209Sandreas.sandberg@arm.com        return False
93114209Sandreas.sandberg@arm.com
93214209Sandreas.sandberg@arm.com    try:
93314209Sandreas.sandberg@arm.com        main.ParseConfig('pkg-config --cflags-only-I --libs-only-L %s' % name)
93414209Sandreas.sandberg@arm.com        print(" yes")
93514209Sandreas.sandberg@arm.com        return True
93614209Sandreas.sandberg@arm.com    except:
93714209Sandreas.sandberg@arm.com        print(" no")
93814209Sandreas.sandberg@arm.com        return False
93914209Sandreas.sandberg@arm.com
94014209Sandreas.sandberg@arm.com# Check if there is a pkg-config configuration for hdf5. If we find
94114209Sandreas.sandberg@arm.com# it, setup the environment to enable linking and header inclusion. We
94214209Sandreas.sandberg@arm.com# don't actually try to include any headers or link with hdf5 at this
94314209Sandreas.sandberg@arm.com# stage.
94414209Sandreas.sandberg@arm.comif not check_hdf5_pkg('hdf5-serial'):
94514209Sandreas.sandberg@arm.com    check_hdf5_pkg('hdf5')
94614209Sandreas.sandberg@arm.com
94714209Sandreas.sandberg@arm.com# Check if the HDF5 libraries can be found. This check respects the
94814209Sandreas.sandberg@arm.com# include path and library path provided by pkg-config. We perform
94914209Sandreas.sandberg@arm.com# this check even if there isn't a pkg-config configuration for hdf5
95014209Sandreas.sandberg@arm.com# since some installations don't use pkg-config.
95114209Sandreas.sandberg@arm.comhave_hdf5 = check_hdf5()
95214209Sandreas.sandberg@arm.comif not have_hdf5:
95314209Sandreas.sandberg@arm.com    print("Warning: Couldn't find any HDF5 C++ libraries. Disabling")
95414209Sandreas.sandberg@arm.com    print("         HDF5 support.")
9559986Sandreas@sandberg.pp.se
9565863Snate@binkert.org######################################################################
9575863Snate@binkert.org#
9585863Snate@binkert.org# Finish the configuration
9595863Snate@binkert.org#
9606121Snate@binkert.orgmain = conf.Finish()
9611858SN/A
9625863Snate@binkert.org######################################################################
9635863Snate@binkert.org#
9645863Snate@binkert.org# Collect all non-global variables
9655863Snate@binkert.org#
9665863Snate@binkert.org
9672139SN/A# Define the universe of supported ISAs
9684202Sbinkertn@umich.eduall_isa_list = [ ]
96911308Santhony.gutierrez@amd.comall_gpu_isa_list = [ ]
9704202Sbinkertn@umich.eduExport('all_isa_list')
97111308Santhony.gutierrez@amd.comExport('all_gpu_isa_list')
9722139SN/A
9736994Snate@binkert.orgclass CpuModel(object):
9746994Snate@binkert.org    '''The CpuModel class encapsulates everything the ISA parser needs to
9756994Snate@binkert.org    know about a particular CPU model.'''
9766994Snate@binkert.org
9776994Snate@binkert.org    # Dict of available CPU model objects.  Accessible as CpuModel.dict.
9786994Snate@binkert.org    dict = {}
9796994Snate@binkert.org
9806994Snate@binkert.org    # Constructor.  Automatically adds models to CpuModel.dict.
98110319SAndreas.Sandberg@ARM.com    def __init__(self, name, default=False):
9826994Snate@binkert.org        self.name = name           # name of model
9836994Snate@binkert.org
9846994Snate@binkert.org        # This cpu is enabled by default
9856994Snate@binkert.org        self.default = default
9866994Snate@binkert.org
9876994Snate@binkert.org        # Add self to dict
9886994Snate@binkert.org        if name in CpuModel.dict:
9896994Snate@binkert.org            raise AttributeError, "CpuModel '%s' already registered" % name
9906994Snate@binkert.org        CpuModel.dict[name] = self
9916994Snate@binkert.org
9926994Snate@binkert.orgExport('CpuModel')
9932155SN/A
9945863Snate@binkert.org# Sticky variables get saved in the variables file so they persist from
9951869SN/A# one invocation to the next (unless overridden, in which case the new
9961869SN/A# value becomes sticky).
9975863Snate@binkert.orgsticky_vars = Variables(args=ARGUMENTS)
9985863Snate@binkert.orgExport('sticky_vars')
9994202Sbinkertn@umich.edu
10006108Snate@binkert.org# Sticky variables that should be exported
10016108Snate@binkert.orgexport_vars = []
10026108Snate@binkert.orgExport('export_vars')
10036108Snate@binkert.org
10049219Spower.jg@gmail.com# For Ruby
10059219Spower.jg@gmail.comall_protocols = []
10069219Spower.jg@gmail.comExport('all_protocols')
10079219Spower.jg@gmail.comprotocol_dirs = []
10089219Spower.jg@gmail.comExport('protocol_dirs')
10099219Spower.jg@gmail.comslicc_includes = []
10109219Spower.jg@gmail.comExport('slicc_includes')
10119219Spower.jg@gmail.com
10124202Sbinkertn@umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the
10135863Snate@binkert.org# above variables
101410135SCurtis.Dunham@arm.comif GetOption('verbose'):
101512563Sgabeblack@google.com    print("Reading SConsopts")
10165742Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list:
10178268Ssteve.reinhardt@amd.com    if not isdir(bdir):
101812563Sgabeblack@google.com        print("Error: directory '%s' does not exist" % bdir)
10198268Ssteve.reinhardt@amd.com        Exit(1)
10205742Snate@binkert.org    for root, dirs, files in os.walk(bdir):
10215341Sstever@gmail.com        if 'SConsopts' in files:
10228474Sgblack@eecs.umich.edu            if GetOption('verbose'):
102312563Sgabeblack@google.com                print("Reading", joinpath(root, 'SConsopts'))
10245342Sstever@gmail.com            SConscript(joinpath(root, 'SConsopts'))
10254202Sbinkertn@umich.edu
10264202Sbinkertn@umich.eduall_isa_list.sort()
102711308Santhony.gutierrez@amd.comall_gpu_isa_list.sort()
10284202Sbinkertn@umich.edu
10295863Snate@binkert.orgsticky_vars.AddVariables(
10305863Snate@binkert.org    EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
103111308Santhony.gutierrez@amd.com    EnumVariable('TARGET_GPU_ISA', 'Target GPU ISA', 'hsail', all_gpu_isa_list),
10326994Snate@binkert.org    ListVariable('CPU_MODELS', 'CPU models',
10336994Snate@binkert.org                 sorted(n for n,m in CpuModel.dict.iteritems() if m.default),
103410319SAndreas.Sandberg@ARM.com                 sorted(CpuModel.dict.keys())),
10355863Snate@binkert.org    BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
10365863Snate@binkert.org                 False),
10375863Snate@binkert.org    BoolVariable('SS_COMPATIBLE_FP',
10385863Snate@binkert.org                 'Make floating-point results compatible with SimpleScalar',
10395863Snate@binkert.org                 False),
10405863Snate@binkert.org    BoolVariable('USE_SSE2',
10415863Snate@binkert.org                 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
10425863Snate@binkert.org                 False),
10437840Snate@binkert.org    BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock),
10445863Snate@binkert.org    BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
104512230Sgiacomo.travaglini@arm.com    BoolVariable('USE_PNG',  'Enable support for PNG images', have_png),
104612230Sgiacomo.travaglini@arm.com    BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability',
104712230Sgiacomo.travaglini@arm.com                 False),
104812230Sgiacomo.travaglini@arm.com    BoolVariable('USE_KVM', 'Enable hardware virtualized (KVM) CPU models',
104912230Sgiacomo.travaglini@arm.com                 have_kvm),
105012056Sgabeblack@google.com    BoolVariable('USE_TUNTAP',
105112056Sgabeblack@google.com                 'Enable using a tap device to bridge to the host network',
105212056Sgabeblack@google.com                 have_tuntap),
105311308Santhony.gutierrez@amd.com    BoolVariable('BUILD_GPU', 'Build the compute-GPU model', False),
10549219Spower.jg@gmail.com    EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None',
10559219Spower.jg@gmail.com                  all_protocols),
105611235Sandreas.sandberg@arm.com    EnumVariable('BACKTRACE_IMPL', 'Post-mortem dump implementation',
105714037Sjohnathan.alsop@amd.com                 backtrace_impls[-1], backtrace_impls),
105814037Sjohnathan.alsop@amd.com    ('NUMBER_BITS_PER_SET', 'Max elements in set (default 64)',
105914037Sjohnathan.alsop@amd.com                 64),
106014209Sandreas.sandberg@arm.com    BoolVariable('USE_HDF5', 'Enable the HDF5 support', have_hdf5),
10611869SN/A    )
10621858SN/A
10635863Snate@binkert.org# These variables get exported to #defines in config/*.hh (see src/SConscript).
106411308Santhony.gutierrez@amd.comexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA',
106512061Sjason@lowepower.com                'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP',
106612920Sgabeblack@google.com                'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_VALGRIND',
106714037Sjohnathan.alsop@amd.com                'HAVE_PERF_ATTR_EXCLUDE_HOST', 'USE_PNG',
106814209Sandreas.sandberg@arm.com                'NUMBER_BITS_PER_SET', 'USE_HDF5']
10691858SN/A
1070955SN/A###################################################
1071955SN/A#
10721869SN/A# Define a SCons builder for configuration flag headers.
10731869SN/A#
10741869SN/A###################################################
10751869SN/A
10761869SN/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.
10801869SN/Adef build_config_file(target, source, env):
10815863Snate@binkert.org    (variable, value) = [s.get_contents() for s in source]
10821869SN/A    f = file(str(target[0]), 'w')
108312563Sgabeblack@google.com    print('#define', variable, value, file=f)
10841869SN/A    f.close()
10851869SN/A    return None
10861869SN/A
10871869SN/A# Combine the two functions into a scons Action object.
10888483Sgblack@eecs.umich.educonfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2))
10891869SN/A
10901869SN/A# The emitter munges the source & target node lists to reflect what
10911869SN/A# we're really doing.
10921869SN/Adef config_emitter(target, source, env):
10935863Snate@binkert.org    # extract variable name from Builder arg
10945863Snate@binkert.org    variable = str(target[0])
10951869SN/A    # True target is config header file
10965863Snate@binkert.org    target = joinpath('config', variable.lower() + '.hh')
10975863Snate@binkert.org    val = env[variable]
10983356Sbinkertn@umich.edu    if isinstance(val, bool):
10993356Sbinkertn@umich.edu        # Force value to 0/1
11003356Sbinkertn@umich.edu        val = int(val)
11013356Sbinkertn@umich.edu    elif isinstance(val, str):
11023356Sbinkertn@umich.edu        val = '"' + val + '"'
11034781Snate@binkert.org
11045863Snate@binkert.org    # Sources are variable name & value (packaged in SCons Value nodes)
11055863Snate@binkert.org    return ([target], [Value(variable), Value(val)])
11061869SN/A
11071869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
11081869SN/A
11096121Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder })
11101869SN/A
111111982Sgabeblack@google.com###################################################
111211982Sgabeblack@google.com#
111311982Sgabeblack@google.com# Builders for static and shared partially linked object files.
111411982Sgabeblack@google.com#
111511982Sgabeblack@google.com###################################################
111611982Sgabeblack@google.com
111711982Sgabeblack@google.compartial_static_builder = Builder(action=SCons.Defaults.LinkAction,
111811982Sgabeblack@google.com                                 src_suffix='$OBJSUFFIX',
111911982Sgabeblack@google.com                                 src_builder=['StaticObject', 'Object'],
112011982Sgabeblack@google.com                                 LINKFLAGS='$PLINKFLAGS',
112111982Sgabeblack@google.com                                 LIBS='')
112211982Sgabeblack@google.com
112311982Sgabeblack@google.comdef partial_shared_emitter(target, source, env):
112411982Sgabeblack@google.com    for tgt in target:
112511982Sgabeblack@google.com        tgt.attributes.shared = 1
112611982Sgabeblack@google.com    return (target, source)
112711982Sgabeblack@google.compartial_shared_builder = Builder(action=SCons.Defaults.ShLinkAction,
112811982Sgabeblack@google.com                                 emitter=partial_shared_emitter,
112911982Sgabeblack@google.com                                 src_suffix='$SHOBJSUFFIX',
113011982Sgabeblack@google.com                                 src_builder='SharedObject',
113111982Sgabeblack@google.com                                 SHLINKFLAGS='$PSHLINKFLAGS',
113211982Sgabeblack@google.com                                 LIBS='')
113311982Sgabeblack@google.com
113411982Sgabeblack@google.commain.Append(BUILDERS = { 'PartialShared' : partial_shared_builder,
113511982Sgabeblack@google.com                         'PartialStatic' : partial_static_builder })
113611982Sgabeblack@google.com
113713706Sgabeblack@google.comdef add_local_rpath(env, *targets):
113813706Sgabeblack@google.com    '''Set up an RPATH for a library which lives in the build directory.
113913706Sgabeblack@google.com
114013706Sgabeblack@google.com    The construction environment variable BIN_RPATH_PREFIX should be set to
114113706Sgabeblack@google.com    the relative path of the build directory starting from the location of the
114213706Sgabeblack@google.com    binary.'''
114313706Sgabeblack@google.com    for target in targets:
114413706Sgabeblack@google.com        target = env.Entry(target)
114513758Sgabeblack@google.com        if not isinstance(target, SCons.Node.FS.Dir):
114613706Sgabeblack@google.com            target = target.dir
114713706Sgabeblack@google.com        relpath = os.path.relpath(target.abspath, env['BUILDDIR'])
114813706Sgabeblack@google.com        components = [
114913706Sgabeblack@google.com            '\\$$ORIGIN',
115013706Sgabeblack@google.com            '${BIN_RPATH_PREFIX}',
115113706Sgabeblack@google.com            relpath
115213706Sgabeblack@google.com        ]
115313706Sgabeblack@google.com        env.Append(RPATH=[env.Literal(os.path.join(*components))])
115413706Sgabeblack@google.com
115513713SAndrea.Mondelli@ucf.eduif sys.platform != "darwin":
115613713SAndrea.Mondelli@ucf.edu    main.Append(LINKFLAGS=Split('-z origin'))
115713713SAndrea.Mondelli@ucf.edu
115813706Sgabeblack@google.commain.AddMethod(add_local_rpath, 'AddLocalRPATH')
115913706Sgabeblack@google.com
116011978Sgabeblack@google.com# builds in ext are shared across all configs in the build root.
116111978Sgabeblack@google.comext_dir = abspath(joinpath(str(main.root), 'ext'))
116212034Sgabeblack@google.comext_build_dirs = []
116311978Sgabeblack@google.comfor root, dirs, files in os.walk(ext_dir):
116411978Sgabeblack@google.com    if 'SConscript' in files:
116511978Sgabeblack@google.com        build_dir = os.path.relpath(root, ext_dir)
116612034Sgabeblack@google.com        ext_build_dirs.append(build_dir)
116711978Sgabeblack@google.com        main.SConscript(joinpath(root, 'SConscript'),
116811978Sgabeblack@google.com                        variant_dir=joinpath(build_root, build_dir))
116910915Sandreas.sandberg@arm.com
117013577Sciro.santilli@arm.comgdb_xml_dir = joinpath(ext_dir, 'gdb-xml')
117113577Sciro.santilli@arm.comExport('gdb_xml_dir')
117213577Sciro.santilli@arm.com
117311986Sandreas.sandberg@arm.commain.Prepend(CPPPATH=Dir('ext/pybind11/include/'))
117411986Sandreas.sandberg@arm.com
11751869SN/A###################################################
11761869SN/A#
117712015Sgabeblack@google.com# This builder and wrapper method are used to set up a directory with
117812015Sgabeblack@google.com# switching headers. Those are headers which are in a generic location and
117912015Sgabeblack@google.com# that include more specific headers from a directory chosen at build time
118012015Sgabeblack@google.com# based on the current build settings.
11813546Sgblack@eecs.umich.edu#
11823546Sgblack@eecs.umich.edu###################################################
11833546Sgblack@eecs.umich.edu
118412015Sgabeblack@google.comdef build_switching_header(target, source, env):
118512015Sgabeblack@google.com    path = str(target[0])
118612015Sgabeblack@google.com    subdir = str(source[0])
118712015Sgabeblack@google.com    dp, fp = os.path.split(path)
118812015Sgabeblack@google.com    dp = os.path.relpath(os.path.realpath(dp),
118912015Sgabeblack@google.com                         os.path.realpath(env['BUILDDIR']))
119012015Sgabeblack@google.com    with open(path, 'w') as hdr:
119112563Sgabeblack@google.com        print('#include "%s/%s/%s"' % (dp, subdir, fp), file=hdr)
11923546Sgblack@eecs.umich.edu
119312015Sgabeblack@google.comswitching_header_action = MakeAction(build_switching_header,
119412015Sgabeblack@google.com                                     Transform('GENERATE'))
119510196SCurtis.Dunham@arm.com
119612015Sgabeblack@google.comswitching_header_builder = Builder(action=switching_header_action,
119712015Sgabeblack@google.com                                   source_factory=Value,
119812015Sgabeblack@google.com                                   single_source=True)
119912015Sgabeblack@google.com
120012015Sgabeblack@google.commain.Append(BUILDERS = { 'SwitchingHeader': switching_header_builder })
120112015Sgabeblack@google.com
120212015Sgabeblack@google.comdef switching_headers(self, headers, source):
120312015Sgabeblack@google.com    for header in headers:
120412015Sgabeblack@google.com        self.SwitchingHeader(header, source)
120512015Sgabeblack@google.com
120612015Sgabeblack@google.commain.AddMethod(switching_headers, 'SwitchingHeaders')
12073546Sgblack@eecs.umich.edu
12083546Sgblack@eecs.umich.edu###################################################
12093546Sgblack@eecs.umich.edu#
1210955SN/A# Define build environments for selected configurations.
1211955SN/A#
1212955SN/A###################################################
1213955SN/A
12145863Snate@binkert.orgfor variant_path in variant_paths:
121510135SCurtis.Dunham@arm.com    if not GetOption('silent'):
121612563Sgabeblack@google.com        print("Building in", variant_path)
12175343Sstever@gmail.com
12185343Sstever@gmail.com    # Make a copy of the build-root environment to use for this config.
12196121Snate@binkert.org    env = main.Clone()
12205863Snate@binkert.org    env['BUILDDIR'] = variant_path
12214773Snate@binkert.org
12225863Snate@binkert.org    # variant_dir is the tail component of build path, and is used to
12232632Sstever@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
12245863Snate@binkert.org    (build_root, variant_dir) = splitpath(variant_path)
12252023SN/A
12265863Snate@binkert.org    # Set env variables according to the build directory config.
12275863Snate@binkert.org    sticky_vars.files = []
12285863Snate@binkert.org    # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
12295863Snate@binkert.org    # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
12305863Snate@binkert.org    # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
12315863Snate@binkert.org    current_vars_file = joinpath(build_root, 'variables', variant_dir)
12325863Snate@binkert.org    if isfile(current_vars_file):
12335863Snate@binkert.org        sticky_vars.files.append(current_vars_file)
123410135SCurtis.Dunham@arm.com        if not GetOption('silent'):
123512563Sgabeblack@google.com            print("Using saved variables file %s" % current_vars_file)
123612034Sgabeblack@google.com    elif variant_dir in ext_build_dirs:
123712034Sgabeblack@google.com        # Things in ext are built without a variant directory.
123812034Sgabeblack@google.com        continue
12392632Sstever@eecs.umich.edu    else:
12405863Snate@binkert.org        # Build dir-specific variables file doesn't exist.
12412023SN/A
12422632Sstever@eecs.umich.edu        # Make sure the directory is there so we can create it later
12435863Snate@binkert.org        opt_dir = dirname(current_vars_file)
12445342Sstever@gmail.com        if not isdir(opt_dir):
12455863Snate@binkert.org            mkdir(opt_dir)
12462632Sstever@eecs.umich.edu
12475863Snate@binkert.org        # Get default build variables from source tree.  Variables are
12485863Snate@binkert.org        # normally determined by name of $VARIANT_DIR, but can be
12498267Ssteve.reinhardt@amd.com        # overridden by '--default=' arg on command line.
12508120Sgblack@eecs.umich.edu        default = GetOption('default')
12518267Ssteve.reinhardt@amd.com        opts_dir = joinpath(main.root.abspath, 'build_opts')
12528267Ssteve.reinhardt@amd.com        if default:
12538267Ssteve.reinhardt@amd.com            default_vars_files = [joinpath(build_root, 'variables', default),
12548267Ssteve.reinhardt@amd.com                                  joinpath(opts_dir, default)]
12558267Ssteve.reinhardt@amd.com        else:
12568267Ssteve.reinhardt@amd.com            default_vars_files = [joinpath(opts_dir, variant_dir)]
12578267Ssteve.reinhardt@amd.com        existing_files = filter(isfile, default_vars_files)
12588267Ssteve.reinhardt@amd.com        if existing_files:
12598267Ssteve.reinhardt@amd.com            default_vars_file = existing_files[0]
12605863Snate@binkert.org            sticky_vars.files.append(default_vars_file)
126112563Sgabeblack@google.com            print("Variables file %s not found,\n  using defaults in %s"
126212563Sgabeblack@google.com                  % (current_vars_file, default_vars_file))
12632632Sstever@eecs.umich.edu        else:
126412563Sgabeblack@google.com            print("Error: cannot find variables file %s or "
126512563Sgabeblack@google.com                  "default file(s) %s"
126612563Sgabeblack@google.com                  % (current_vars_file, ' or '.join(default_vars_files)))
12672632Sstever@eecs.umich.edu            Exit(1)
12681888SN/A
12695863Snate@binkert.org    # Apply current variable settings to env
12705863Snate@binkert.org    sticky_vars.Update(env)
12711858SN/A
12728120Sgblack@eecs.umich.edu    help_texts["local_vars"] += \
12738120Sgblack@eecs.umich.edu        "Build variables for %s:\n" % variant_dir \
12747756SAli.Saidi@ARM.com                 + sticky_vars.GenerateHelpText(env)
12752598SN/A
12765863Snate@binkert.org    # Process variable settings.
12771858SN/A
12781858SN/A    if not have_fenv and env['USE_FENV']:
127912563Sgabeblack@google.com        print("Warning: <fenv.h> not available; "
128012563Sgabeblack@google.com              "forcing USE_FENV to False in", variant_dir + ".")
12811858SN/A        env['USE_FENV'] = False
12821858SN/A
12831858SN/A    if not env['USE_FENV']:
128412563Sgabeblack@google.com        print("Warning: No IEEE FP rounding mode control in",
128512563Sgabeblack@google.com              variant_dir + ".")
128612563Sgabeblack@google.com        print("         FP results may deviate slightly from other platforms.")
12871858SN/A
128812230Sgiacomo.travaglini@arm.com    if not have_png and env['USE_PNG']:
128912563Sgabeblack@google.com        print("Warning: <png.h> not available; "
129012563Sgabeblack@google.com              "forcing USE_PNG to False in", variant_dir + ".")
129112230Sgiacomo.travaglini@arm.com        env['USE_PNG'] = False
129212230Sgiacomo.travaglini@arm.com
129312230Sgiacomo.travaglini@arm.com    if env['USE_PNG']:
129412230Sgiacomo.travaglini@arm.com        env.Append(LIBS=['png'])
129512230Sgiacomo.travaglini@arm.com
12961858SN/A    if env['EFENCE']:
12971858SN/A        env.Append(LIBS=['efence'])
12981858SN/A
12999651SAndreas.Sandberg@ARM.com    if env['USE_KVM']:
13009651SAndreas.Sandberg@ARM.com        if not have_kvm:
130112563Sgabeblack@google.com            print("Warning: Can not enable KVM, host seems to "
130212563Sgabeblack@google.com                  "lack KVM support")
13039651SAndreas.Sandberg@ARM.com            env['USE_KVM'] = False
13049651SAndreas.Sandberg@ARM.com        elif not is_isa_kvm_compatible(env['TARGET_ISA']):
130512563Sgabeblack@google.com            print("Info: KVM support disabled due to unsupported host and "
130612563Sgabeblack@google.com                  "target ISA combination")
13079651SAndreas.Sandberg@ARM.com            env['USE_KVM'] = False
13089651SAndreas.Sandberg@ARM.com
130912056Sgabeblack@google.com    if env['USE_TUNTAP']:
131012056Sgabeblack@google.com        if not have_tuntap:
131112563Sgabeblack@google.com            print("Warning: Can't connect EtherTap with a tap device.")
131212056Sgabeblack@google.com            env['USE_TUNTAP'] = False
131312056Sgabeblack@google.com
131411798Santhony.gutierrez@amd.com    if env['BUILD_GPU']:
131511798Santhony.gutierrez@amd.com        env.Append(CPPDEFINES=['BUILD_GPU'])
131611798Santhony.gutierrez@amd.com
13179986Sandreas@sandberg.pp.se    # Warn about missing optional functionality
13189986Sandreas@sandberg.pp.se    if env['USE_KVM']:
13199986Sandreas@sandberg.pp.se        if not main['HAVE_PERF_ATTR_EXCLUDE_HOST']:
132012563Sgabeblack@google.com            print("Warning: perf_event headers lack support for the "
132112563Sgabeblack@google.com                  "exclude_host attribute. KVM instruction counts will "
132212563Sgabeblack@google.com                  "be inaccurate.")
13239986Sandreas@sandberg.pp.se
13245863Snate@binkert.org    # Save sticky variable settings back to current variables file
13255863Snate@binkert.org    sticky_vars.Save(current_vars_file, env)
13261869SN/A
13271965SN/A    if env['USE_SSE2']:
13287739Sgblack@eecs.umich.edu        env.Append(CCFLAGS=['-msse2'])
13291965SN/A
133014044Sciro.santilli@arm.com    env.Append(CCFLAGS='$CCFLAGS_EXTRA')
133114044Sciro.santilli@arm.com    env.Append(LINKFLAGS='$LDFLAGS_EXTRA')
133214044Sciro.santilli@arm.com
13332761Sstever@eecs.umich.edu    # The src/SConscript file sets up the build rules in 'env' according
13345863Snate@binkert.org    # to the configured variables.  It returns a list of environments,
13351869SN/A    # one for each variant build (debug, opt, etc.)
133610196SCurtis.Dunham@arm.com    SConscript('src/SConscript', variant_dir = variant_path, exports = 'env')
13371869SN/A
13388120Sgblack@eecs.umich.edu# base help text
13398120Sgblack@eecs.umich.eduHelp('''
13408120Sgblack@eecs.umich.eduUsage: scons [scons options] [build variables] [target(s)]
13418120Sgblack@eecs.umich.edu
13428120Sgblack@eecs.umich.eduExtra scons options:
13438120Sgblack@eecs.umich.edu%(options)s
13448120Sgblack@eecs.umich.edu
13458120Sgblack@eecs.umich.eduGlobal build variables:
13468120Sgblack@eecs.umich.edu%(global_vars)s
13478120Sgblack@eecs.umich.edu
13488120Sgblack@eecs.umich.edu%(local_vars)s
13498120Sgblack@eecs.umich.edu''' % help_texts)
1350