SConstruct revision 9227
1955SN/A# -*- mode:python -*- 2955SN/A 39812Sandreas.hansson@arm.com# Copyright (c) 2011 Advanced Micro Devices, Inc. 49812Sandreas.hansson@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company 59812Sandreas.hansson@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 69812Sandreas.hansson@arm.com# All rights reserved. 79812Sandreas.hansson@arm.com# 89812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 99812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 109812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 129812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 139812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 149812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 157816Ssteve.reinhardt@amd.com# neither the name of the copyright holders nor the names of its 165871Snate@binkert.org# contributors may be used to endorse or promote products derived from 171762SN/A# this software without specific prior written permission. 18955SN/A# 19955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30955SN/A# 31955SN/A# Authors: Steve Reinhardt 32955SN/A# Nathan Binkert 33955SN/A 34955SN/A################################################### 35955SN/A# 36955SN/A# SCons top-level build description (SConstruct) file. 37955SN/A# 38955SN/A# While in this directory ('gem5'), just type 'scons' to build the default 39955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 40955SN/A# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 41955SN/A# the optimized full-system version). 422665Ssaidi@eecs.umich.edu# 432665Ssaidi@eecs.umich.edu# You can build gem5 in a different directory as long as there is a 445863Snate@binkert.org# 'build/<CONFIG>' somewhere along the target path. The build system 45955SN/A# expects that all configs under the same build directory are being 46955SN/A# built for the same host system. 47955SN/A# 48955SN/A# Examples: 49955SN/A# 508878Ssteve.reinhardt@amd.com# The following two commands are equivalent. The '-u' option tells 512632Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 528878Ssteve.reinhardt@amd.com# % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug 532632Sstever@eecs.umich.edu# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug 54955SN/A# 558878Ssteve.reinhardt@amd.com# The following two commands are equivalent and demonstrate building 562632Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 572761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 582632Sstever@eecs.umich.edu# file. 592632Sstever@eecs.umich.edu# % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 602632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug 612761Sstever@eecs.umich.edu# 622761Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 632761Sstever@eecs.umich.edu# 'gem5' directory (or use -u or -C to tell scons where to find this 648878Ssteve.reinhardt@amd.com# file), you can use 'scons -h' to print all the gem5-specific build 658878Ssteve.reinhardt@amd.com# options as well. 662761Sstever@eecs.umich.edu# 672761Sstever@eecs.umich.edu################################################### 682761Sstever@eecs.umich.edu 692761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. 702761Sstever@eecs.umich.edutry: 718878Ssteve.reinhardt@amd.com # Really old versions of scons only take two options for the 728878Ssteve.reinhardt@amd.com # function, so check once without the revision and once with the 732632Sstever@eecs.umich.edu # revision, the first instance will fail for stuff other than 742632Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 758878Ssteve.reinhardt@amd.com EnsureSConsVersion(0, 98) 768878Ssteve.reinhardt@amd.com EnsureSConsVersion(0, 98, 1) 772632Sstever@eecs.umich.eduexcept SystemExit, e: 78955SN/A print """ 79955SN/AFor more details, see: 80955SN/A http://gem5.org/Dependencies 815863Snate@binkert.org""" 825863Snate@binkert.org raise 835863Snate@binkert.org 845863Snate@binkert.org# We ensure the python version early because we have stuff that 855863Snate@binkert.org# requires python 2.4 865863Snate@binkert.orgtry: 875863Snate@binkert.org EnsurePythonVersion(2, 4) 885863Snate@binkert.orgexcept SystemExit, e: 895863Snate@binkert.org print """ 905863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 915863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 928878Ssteve.reinhardt@amd.com'python' first or (2) explicitly invoking an alternative interpreter 935863Snate@binkert.orgon the scons script. 945863Snate@binkert.org 955863Snate@binkert.orgFor more details, see: 969812Sandreas.hansson@arm.com http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 979812Sandreas.hansson@arm.com""" 985863Snate@binkert.org raise 999812Sandreas.hansson@arm.com 1005863Snate@binkert.org# Global Python includes 1015863Snate@binkert.orgimport os 1025863Snate@binkert.orgimport re 1039812Sandreas.hansson@arm.comimport subprocess 1049812Sandreas.hansson@arm.comimport sys 1055863Snate@binkert.org 1065863Snate@binkert.orgfrom os import mkdir, environ 1078878Ssteve.reinhardt@amd.comfrom os.path import abspath, basename, dirname, expanduser, normpath 1085863Snate@binkert.orgfrom os.path import exists, isdir, isfile 1095863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1105863Snate@binkert.org 1116654Snate@binkert.org# SCons includes 112955SN/Aimport SCons 1135396Ssaidi@eecs.umich.eduimport SCons.Node 1145863Snate@binkert.org 1155863Snate@binkert.orgextra_python_paths = [ 1164202Sbinkertn@umich.edu Dir('src/python').srcnode().abspath, # gem5 includes 1175863Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1185863Snate@binkert.org ] 1195863Snate@binkert.org 1205863Snate@binkert.orgsys.path[1:1] = extra_python_paths 121955SN/A 1226654Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1235273Sstever@gmail.comfrom m5.util.terminal import get_termcap 1245871Snate@binkert.org 1255273Sstever@gmail.comhelp_texts = { 1266655Snate@binkert.org "options" : "", 1278878Ssteve.reinhardt@amd.com "global_vars" : "", 1286655Snate@binkert.org "local_vars" : "" 1296655Snate@binkert.org} 1309219Spower.jg@gmail.com 1316655Snate@binkert.orgExport("help_texts") 1325871Snate@binkert.org 1336654Snate@binkert.org 1348947Sandreas.hansson@arm.com# There's a bug in scons in that (1) by default, the help texts from 1355396Ssaidi@eecs.umich.edu# AddOption() are supposed to be displayed when you type 'scons -h' 1368120Sgblack@eecs.umich.edu# and (2) you can override the help displayed by 'scons -h' using the 1378120Sgblack@eecs.umich.edu# Help() function, but these two features are incompatible: once 1388120Sgblack@eecs.umich.edu# you've overridden the help text using Help(), there's no way to get 1398120Sgblack@eecs.umich.edu# at the help texts from AddOptions. See: 1408120Sgblack@eecs.umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1418120Sgblack@eecs.umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1428120Sgblack@eecs.umich.edu# This hack lets us extract the help text from AddOptions and 1438120Sgblack@eecs.umich.edu# re-inject it via Help(). Ideally someday this bug will be fixed and 1448879Ssteve.reinhardt@amd.com# we can just use AddOption directly. 1458879Ssteve.reinhardt@amd.comdef AddLocalOption(*args, **kwargs): 1468879Ssteve.reinhardt@amd.com col_width = 30 1478879Ssteve.reinhardt@amd.com 1488879Ssteve.reinhardt@amd.com help = " " + ", ".join(args) 1498879Ssteve.reinhardt@amd.com if "help" in kwargs: 1508879Ssteve.reinhardt@amd.com length = len(help) 1518879Ssteve.reinhardt@amd.com if length >= col_width: 1528879Ssteve.reinhardt@amd.com help += "\n" + " " * col_width 1538879Ssteve.reinhardt@amd.com else: 1548879Ssteve.reinhardt@amd.com help += " " * (col_width - length) 1558879Ssteve.reinhardt@amd.com help += kwargs["help"] 1568879Ssteve.reinhardt@amd.com help_texts["options"] += help + "\n" 1578120Sgblack@eecs.umich.edu 1588120Sgblack@eecs.umich.edu AddOption(*args, **kwargs) 1598120Sgblack@eecs.umich.edu 1608120Sgblack@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true', 1618120Sgblack@eecs.umich.edu help="Add color to abbreviated scons output") 1628120Sgblack@eecs.umich.eduAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1638120Sgblack@eecs.umich.edu help="Don't add color to abbreviated scons output") 1648120Sgblack@eecs.umich.eduAddLocalOption('--default', dest='default', type='string', action='store', 1658120Sgblack@eecs.umich.edu help='Override which build_opts file to use for defaults') 1668120Sgblack@eecs.umich.eduAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1678120Sgblack@eecs.umich.edu help='Disable style checking hooks') 1688120Sgblack@eecs.umich.eduAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1698120Sgblack@eecs.umich.edu help='Disable Link-Time Optimization for fast') 1708120Sgblack@eecs.umich.eduAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1718879Ssteve.reinhardt@amd.com help='Update test reference outputs') 1728879Ssteve.reinhardt@amd.comAddLocalOption('--verbose', dest='verbose', action='store_true', 1738879Ssteve.reinhardt@amd.com help='Print full tool command lines') 1748879Ssteve.reinhardt@amd.com 1758879Ssteve.reinhardt@amd.comtermcap = get_termcap(GetOption('use_colors')) 1768879Ssteve.reinhardt@amd.com 1778879Ssteve.reinhardt@amd.com######################################################################## 1788879Ssteve.reinhardt@amd.com# 1799227Sandreas.hansson@arm.com# Set up the main build environment. 1809227Sandreas.hansson@arm.com# 1818879Ssteve.reinhardt@amd.com######################################################################## 1828879Ssteve.reinhardt@amd.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 1838879Ssteve.reinhardt@amd.com 'LIBRARY_PATH', 'PATH', 'PYTHONPATH', 'RANLIB', 'SWIG' ]) 1848879Ssteve.reinhardt@amd.com 1858120Sgblack@eecs.umich.eduuse_env = {} 1868947Sandreas.hansson@arm.comfor key,val in os.environ.iteritems(): 1877816Ssteve.reinhardt@amd.com if key in use_vars or key.startswith("M5"): 1885871Snate@binkert.org use_env[key] = val 1895871Snate@binkert.org 1906121Snate@binkert.orgmain = Environment(ENV=use_env) 1915871Snate@binkert.orgmain.Decider('MD5-timestamp') 1925871Snate@binkert.orgmain.root = Dir(".") # The current directory (where this file lives). 1939926Sstan.czerniawski@arm.commain.srcdir = Dir("src") # The source directory 1949926Sstan.czerniawski@arm.com 1959119Sandreas.hansson@arm.com# add useful python code PYTHONPATH so it can be used by subprocesses 1969396Sandreas.hansson@arm.com# as well 1979926Sstan.czerniawski@arm.commain.AppendENVPath('PYTHONPATH', extra_python_paths) 198955SN/A 1999416SAndreas.Sandberg@ARM.com######################################################################## 2009416SAndreas.Sandberg@ARM.com# 2019416SAndreas.Sandberg@ARM.com# Mercurial Stuff. 2029416SAndreas.Sandberg@ARM.com# 2039416SAndreas.Sandberg@ARM.com# If the gem5 directory is a mercurial repository, we should do some 2049416SAndreas.Sandberg@ARM.com# extra things. 2059416SAndreas.Sandberg@ARM.com# 2065871Snate@binkert.org######################################################################## 2075871Snate@binkert.org 2089416SAndreas.Sandberg@ARM.comhgdir = main.root.Dir(".hg") 2099416SAndreas.Sandberg@ARM.com 2105871Snate@binkert.orgmercurial_style_message = """ 211955SN/AYou're missing the gem5 style hook, which automatically checks your code 2126121Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands. This 2138881Smarc.orr@gmail.comscript will now install the hook in your .hg/hgrc file. 2146121Snate@binkert.orgPress enter to continue, or ctrl-c to abort: """ 2156121Snate@binkert.org 2161533SN/Amercurial_style_hook = """ 2179239Sandreas.hansson@arm.com# The following lines were automatically added by gem5/SConstruct 2189239Sandreas.hansson@arm.com# to provide the gem5 style-checking hooks 2199239Sandreas.hansson@arm.com[extensions] 2209239Sandreas.hansson@arm.comstyle = %s/util/style.py 2219239Sandreas.hansson@arm.com 2229239Sandreas.hansson@arm.com[hooks] 2239239Sandreas.hansson@arm.compretxncommit.style = python:style.check_style 2249239Sandreas.hansson@arm.compre-qrefresh.style = python:style.check_style 2259239Sandreas.hansson@arm.com# End of SConstruct additions 2269239Sandreas.hansson@arm.com 2279239Sandreas.hansson@arm.com""" % (main.root.abspath) 2289239Sandreas.hansson@arm.com 2296655Snate@binkert.orgmercurial_lib_not_found = """ 2306655Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook. If 2316655Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 2326655Snate@binkert.orghook. It is important. 2335871Snate@binkert.org""" 2345871Snate@binkert.org 2355863Snate@binkert.org# Check for style hook and prompt for installation if it's not there. 2365871Snate@binkert.org# Skip this if --ignore-style was specified, there's no .hg dir to 2378878Ssteve.reinhardt@amd.com# install a hook in, or there's no interactive terminal to prompt. 2385871Snate@binkert.orgif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2395871Snate@binkert.org style_hook = True 2405871Snate@binkert.org try: 2415863Snate@binkert.org from mercurial import ui 2426121Snate@binkert.org ui = ui.ui() 2435863Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2445871Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2458336Ssteve.reinhardt@amd.com ui.config('hooks', 'pre-qrefresh.style', None) 2468336Ssteve.reinhardt@amd.com except ImportError: 2478336Ssteve.reinhardt@amd.com print mercurial_lib_not_found 2488336Ssteve.reinhardt@amd.com 2494678Snate@binkert.org if not style_hook: 2508336Ssteve.reinhardt@amd.com print mercurial_style_message, 2518336Ssteve.reinhardt@amd.com # continue unless user does ctrl-c/ctrl-d etc. 2528336Ssteve.reinhardt@amd.com try: 2534678Snate@binkert.org raw_input() 2544678Snate@binkert.org except: 2554678Snate@binkert.org print "Input exception, exiting scons.\n" 2564678Snate@binkert.org sys.exit(1) 2577827Snate@binkert.org hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2587827Snate@binkert.org print "Adding style hook to", hgrc_path, "\n" 2598336Ssteve.reinhardt@amd.com try: 2604678Snate@binkert.org hgrc = open(hgrc_path, 'a') 2618336Ssteve.reinhardt@amd.com hgrc.write(mercurial_style_hook) 2628336Ssteve.reinhardt@amd.com hgrc.close() 2638336Ssteve.reinhardt@amd.com except: 2648336Ssteve.reinhardt@amd.com print "Error updating", hgrc_path 2658336Ssteve.reinhardt@amd.com sys.exit(1) 2668336Ssteve.reinhardt@amd.com 2675871Snate@binkert.org 2685871Snate@binkert.org################################################### 2698336Ssteve.reinhardt@amd.com# 2708336Ssteve.reinhardt@amd.com# Figure out which configurations to set up based on the path(s) of 2718336Ssteve.reinhardt@amd.com# the target(s). 2728336Ssteve.reinhardt@amd.com# 2738336Ssteve.reinhardt@amd.com################################################### 2745871Snate@binkert.org 2758336Ssteve.reinhardt@amd.com# Find default configuration & binary. 2768336Ssteve.reinhardt@amd.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2778336Ssteve.reinhardt@amd.com 2788336Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list 2798336Ssteve.reinhardt@amd.comdef rfind(l, elt, offs = -1): 2804678Snate@binkert.org for i in range(len(l)+offs, 0, -1): 2815871Snate@binkert.org if l[i] == elt: 2824678Snate@binkert.org return i 2838336Ssteve.reinhardt@amd.com raise ValueError, "element not found" 2848336Ssteve.reinhardt@amd.com 2858336Ssteve.reinhardt@amd.com# Take a list of paths (or SCons Nodes) and return a list with all 2868336Ssteve.reinhardt@amd.com# paths made absolute and ~-expanded. Paths will be interpreted 2878336Ssteve.reinhardt@amd.com# relative to the launch directory unless a different root is provided 2888336Ssteve.reinhardt@amd.comdef makePathListAbsolute(path_list, root=GetLaunchDir()): 2898336Ssteve.reinhardt@amd.com return [abspath(joinpath(root, expanduser(str(p)))) 2908336Ssteve.reinhardt@amd.com for p in path_list] 2918336Ssteve.reinhardt@amd.com 2928336Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the 2938336Ssteve.reinhardt@amd.com# directory below this will determine the build parameters. For 2948336Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2958336Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it 2968336Ssteve.reinhardt@amd.com# follow 'build' in the build path. 2978336Ssteve.reinhardt@amd.com 2988336Ssteve.reinhardt@amd.com# The funky assignment to "[:]" is needed to replace the list contents 2998336Ssteve.reinhardt@amd.com# in place rather than reassign the symbol to a new list, which 3005871Snate@binkert.org# doesn't work (obviously!). 3016121Snate@binkert.orgBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 302955SN/A 303955SN/A# Generate a list of the unique build roots and configs that the 3042632Sstever@eecs.umich.edu# collected targets reference. 3052632Sstever@eecs.umich.eduvariant_paths = [] 306955SN/Abuild_root = None 307955SN/Afor t in BUILD_TARGETS: 308955SN/A path_dirs = t.split('/') 309955SN/A try: 3108878Ssteve.reinhardt@amd.com build_top = rfind(path_dirs, 'build', -2) 311955SN/A except: 3122632Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 3132632Sstever@eecs.umich.edu Exit(1) 3142632Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3152632Sstever@eecs.umich.edu if not build_root: 3162632Sstever@eecs.umich.edu build_root = this_build_root 3172632Sstever@eecs.umich.edu else: 3182632Sstever@eecs.umich.edu if this_build_root != build_root: 3198268Ssteve.reinhardt@amd.com print "Error: build targets not under same build root\n"\ 3208268Ssteve.reinhardt@amd.com " %s\n %s" % (build_root, this_build_root) 3218268Ssteve.reinhardt@amd.com Exit(1) 3228268Ssteve.reinhardt@amd.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 3238268Ssteve.reinhardt@amd.com if variant_path not in variant_paths: 3248268Ssteve.reinhardt@amd.com variant_paths.append(variant_path) 3258268Ssteve.reinhardt@amd.com 3262632Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 3272632Sstever@eecs.umich.eduif not isdir(build_root): 3282632Sstever@eecs.umich.edu mkdir(build_root) 3292632Sstever@eecs.umich.edumain['BUILDROOT'] = build_root 3308268Ssteve.reinhardt@amd.com 3312632Sstever@eecs.umich.eduExport('main') 3328268Ssteve.reinhardt@amd.com 3338268Ssteve.reinhardt@amd.commain.SConsignFile(joinpath(build_root, "sconsign")) 3348268Ssteve.reinhardt@amd.com 3358268Ssteve.reinhardt@amd.com# Default duplicate option is to use hard links, but this messes up 3363718Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 3372634Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 3382634Sstever@eecs.umich.edu# (soft) links work better. 3395863Snate@binkert.orgmain.SetOption('duplicate', 'soft-copy') 3402638Sstever@eecs.umich.edu 3418268Ssteve.reinhardt@amd.com# 3422632Sstever@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 3432632Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 3442632Sstever@eecs.umich.edu# 3452632Sstever@eecs.umich.edu 3462632Sstever@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 3471858SN/A 3483716Sstever@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3492638Sstever@eecs.umich.edu 3502638Sstever@eecs.umich.eduglobal_vars.AddVariables( 3512638Sstever@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3522638Sstever@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3532638Sstever@eecs.umich.edu ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 3542638Sstever@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3552638Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3565863Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3575863Snate@binkert.org ('EXTRAS', 'Add extra directories to the compilation', '') 3585863Snate@binkert.org ) 359955SN/A 3605341Sstever@gmail.com# Update main environment with values from ARGUMENTS & global_vars_file 3615341Sstever@gmail.comglobal_vars.Update(main) 3625863Snate@binkert.orghelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3637756SAli.Saidi@ARM.com 3645341Sstever@gmail.com# Save sticky variable settings back to current variables file 3656121Snate@binkert.orgglobal_vars.Save(global_vars_file, main) 3664494Ssaidi@eecs.umich.edu 3676121Snate@binkert.org# Parse EXTRAS variable to build list of all directories where we're 3681105SN/A# look for sources etc. This list is exported as extras_dir_list. 3692667Sstever@eecs.umich.edubase_dir = main.srcdir.abspath 3702667Sstever@eecs.umich.eduif main['EXTRAS']: 3712667Sstever@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3722667Sstever@eecs.umich.eduelse: 3736121Snate@binkert.org extras_dir_list = [] 3742667Sstever@eecs.umich.edu 3755341Sstever@gmail.comExport('base_dir') 3765863Snate@binkert.orgExport('extras_dir_list') 3775341Sstever@gmail.com 3785341Sstever@gmail.com# the ext directory should be on the #includes path 3795341Sstever@gmail.commain.Append(CPPPATH=[Dir('ext')]) 3808120Sgblack@eecs.umich.edu 3815341Sstever@gmail.comdef strip_build_path(path, env): 3828120Sgblack@eecs.umich.edu path = str(path) 3835341Sstever@gmail.com variant_base = env['BUILDROOT'] + os.path.sep 3848120Sgblack@eecs.umich.edu if path.startswith(variant_base): 3856121Snate@binkert.org path = path[len(variant_base):] 3866121Snate@binkert.org elif path.startswith('build/'): 3878980Ssteve.reinhardt@amd.com path = path[6:] 3889396Sandreas.hansson@arm.com return path 3895397Ssaidi@eecs.umich.edu 3905397Ssaidi@eecs.umich.edu# Generate a string of the form: 3917727SAli.Saidi@ARM.com# common/path/prefix/src1, src2 -> tgt1, tgt2 3928268Ssteve.reinhardt@amd.com# to print while building. 3936168Snate@binkert.orgclass Transform(object): 3945341Sstever@gmail.com # all specific color settings should be here and nowhere else 3958120Sgblack@eecs.umich.edu tool_color = termcap.Normal 3968120Sgblack@eecs.umich.edu pfx_color = termcap.Yellow 3978120Sgblack@eecs.umich.edu srcs_color = termcap.Yellow + termcap.Bold 3986814Sgblack@eecs.umich.edu arrow_color = termcap.Blue + termcap.Bold 3995863Snate@binkert.org tgts_color = termcap.Yellow + termcap.Bold 4008120Sgblack@eecs.umich.edu 4015341Sstever@gmail.com def __init__(self, tool, max_sources=99): 4025863Snate@binkert.org self.format = self.tool_color + (" [%8s] " % tool) \ 4038268Ssteve.reinhardt@amd.com + self.pfx_color + "%s" \ 4046121Snate@binkert.org + self.srcs_color + "%s" \ 4056121Snate@binkert.org + self.arrow_color + " -> " \ 4068268Ssteve.reinhardt@amd.com + self.tgts_color + "%s" \ 4075742Snate@binkert.org + termcap.Normal 4085742Snate@binkert.org self.max_sources = max_sources 4095341Sstever@gmail.com 4105742Snate@binkert.org def __call__(self, target, source, env, for_signature=None): 4115742Snate@binkert.org # truncate source list according to max_sources param 4125341Sstever@gmail.com source = source[0:self.max_sources] 4136017Snate@binkert.org def strip(f): 4146121Snate@binkert.org return strip_build_path(str(f), env) 4156017Snate@binkert.org if len(source) > 0: 4167816Ssteve.reinhardt@amd.com srcs = map(strip, source) 4177756SAli.Saidi@ARM.com else: 4187756SAli.Saidi@ARM.com srcs = [''] 4197756SAli.Saidi@ARM.com tgts = map(strip, target) 4207756SAli.Saidi@ARM.com # surprisingly, os.path.commonprefix is a dumb char-by-char string 4217756SAli.Saidi@ARM.com # operation that has nothing to do with paths. 4227756SAli.Saidi@ARM.com com_pfx = os.path.commonprefix(srcs + tgts) 4237756SAli.Saidi@ARM.com com_pfx_len = len(com_pfx) 4247756SAli.Saidi@ARM.com if com_pfx: 4257816Ssteve.reinhardt@amd.com # do some cleanup and sanity checking on common prefix 4267816Ssteve.reinhardt@amd.com if com_pfx[-1] == ".": 4277816Ssteve.reinhardt@amd.com # prefix matches all but file extension: ok 4287816Ssteve.reinhardt@amd.com # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4297816Ssteve.reinhardt@amd.com com_pfx = com_pfx[0:-1] 4307816Ssteve.reinhardt@amd.com elif com_pfx[-1] == "/": 4317816Ssteve.reinhardt@amd.com # common prefix is directory path: OK 4327816Ssteve.reinhardt@amd.com pass 4337816Ssteve.reinhardt@amd.com else: 4347816Ssteve.reinhardt@amd.com src0_len = len(srcs[0]) 4357756SAli.Saidi@ARM.com tgt0_len = len(tgts[0]) 4367816Ssteve.reinhardt@amd.com if src0_len == com_pfx_len: 4377816Ssteve.reinhardt@amd.com # source is a substring of target, OK 4387816Ssteve.reinhardt@amd.com pass 4397816Ssteve.reinhardt@amd.com elif tgt0_len == com_pfx_len: 4407816Ssteve.reinhardt@amd.com # target is a substring of source, need to back up to 4417816Ssteve.reinhardt@amd.com # avoid empty string on RHS of arrow 4427816Ssteve.reinhardt@amd.com sep_idx = com_pfx.rfind(".") 4437816Ssteve.reinhardt@amd.com if sep_idx != -1: 4447816Ssteve.reinhardt@amd.com com_pfx = com_pfx[0:sep_idx] 4457816Ssteve.reinhardt@amd.com else: 4467816Ssteve.reinhardt@amd.com com_pfx = '' 4477816Ssteve.reinhardt@amd.com elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4487816Ssteve.reinhardt@amd.com # still splitting at file extension: ok 4497816Ssteve.reinhardt@amd.com pass 4507816Ssteve.reinhardt@amd.com else: 4517816Ssteve.reinhardt@amd.com # probably a fluke; ignore it 4527816Ssteve.reinhardt@amd.com com_pfx = '' 4537816Ssteve.reinhardt@amd.com # recalculate length in case com_pfx was modified 4547816Ssteve.reinhardt@amd.com com_pfx_len = len(com_pfx) 4557816Ssteve.reinhardt@amd.com def fmt(files): 4567816Ssteve.reinhardt@amd.com f = map(lambda s: s[com_pfx_len:], files) 4577816Ssteve.reinhardt@amd.com return ', '.join(f) 4587816Ssteve.reinhardt@amd.com return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4597816Ssteve.reinhardt@amd.com 4607816Ssteve.reinhardt@amd.comExport('Transform') 4617816Ssteve.reinhardt@amd.com 4627816Ssteve.reinhardt@amd.com# enable the regression script to use the termcap 4637816Ssteve.reinhardt@amd.commain['TERMCAP'] = termcap 4647816Ssteve.reinhardt@amd.com 4657816Ssteve.reinhardt@amd.comif GetOption('verbose'): 4667816Ssteve.reinhardt@amd.com def MakeAction(action, string, *args, **kwargs): 4677816Ssteve.reinhardt@amd.com return Action(action, *args, **kwargs) 4687816Ssteve.reinhardt@amd.comelse: 4697816Ssteve.reinhardt@amd.com MakeAction = Action 4707816Ssteve.reinhardt@amd.com main['CCCOMSTR'] = Transform("CC") 4717816Ssteve.reinhardt@amd.com main['CXXCOMSTR'] = Transform("CXX") 4727816Ssteve.reinhardt@amd.com main['ASCOMSTR'] = Transform("AS") 4737816Ssteve.reinhardt@amd.com main['SWIGCOMSTR'] = Transform("SWIG") 4747816Ssteve.reinhardt@amd.com main['ARCOMSTR'] = Transform("AR", 0) 4757816Ssteve.reinhardt@amd.com main['LINKCOMSTR'] = Transform("LINK", 0) 4767816Ssteve.reinhardt@amd.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4777816Ssteve.reinhardt@amd.com main['M4COMSTR'] = Transform("M4") 4787816Ssteve.reinhardt@amd.com main['SHCCCOMSTR'] = Transform("SHCC") 4797816Ssteve.reinhardt@amd.com main['SHCXXCOMSTR'] = Transform("SHCXX") 4807816Ssteve.reinhardt@amd.comExport('MakeAction') 4817816Ssteve.reinhardt@amd.com 4827816Ssteve.reinhardt@amd.com# Initialize the Link-Time Optimization (LTO) flags 4837816Ssteve.reinhardt@amd.commain['LTO_CCFLAGS'] = [] 4847816Ssteve.reinhardt@amd.commain['LTO_LDFLAGS'] = [] 4857816Ssteve.reinhardt@amd.com 4867816Ssteve.reinhardt@amd.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4877816Ssteve.reinhardt@amd.comCXX_V = readCommand([main['CXX'],'-V'], exception=False) 4887816Ssteve.reinhardt@amd.com 4897816Ssteve.reinhardt@amd.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4907816Ssteve.reinhardt@amd.commain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4917816Ssteve.reinhardt@amd.commain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4927816Ssteve.reinhardt@amd.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 4937816Ssteve.reinhardt@amd.comif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: 4947816Ssteve.reinhardt@amd.com print 'Error: How can we have two at the same time?' 4957816Ssteve.reinhardt@amd.com Exit(1) 4967816Ssteve.reinhardt@amd.com 4978947Sandreas.hansson@arm.com# Set up default C++ compiler flags 4988947Sandreas.hansson@arm.comif main['GCC']: 4997756SAli.Saidi@ARM.com main.Append(CCFLAGS=['-pipe']) 5008120Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-fno-strict-aliasing']) 5017756SAli.Saidi@ARM.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5027756SAli.Saidi@ARM.com # Read the GCC version to check for versions with bugs 5037756SAli.Saidi@ARM.com # Note CCVERSION doesn't work here because it is run with the CC 5047756SAli.Saidi@ARM.com # before we override it from the command line 5057816Ssteve.reinhardt@amd.com gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5067816Ssteve.reinhardt@amd.com main['GCC_VERSION'] = gcc_version 5077816Ssteve.reinhardt@amd.com if not compareVersions(gcc_version, '4.4.1') or \ 5087816Ssteve.reinhardt@amd.com not compareVersions(gcc_version, '4.4.2'): 5097816Ssteve.reinhardt@amd.com print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5107816Ssteve.reinhardt@amd.com main.Append(CCFLAGS=['-fno-tree-vectorize']) 5117816Ssteve.reinhardt@amd.com # c++0x support in gcc is useful already from 4.4, see 5127816Ssteve.reinhardt@amd.com # http://gcc.gnu.org/projects/cxx0x.html for details 5137816Ssteve.reinhardt@amd.com if compareVersions(gcc_version, '4.4') >= 0: 5147816Ssteve.reinhardt@amd.com main.Append(CXXFLAGS=['-std=c++0x']) 5157756SAli.Saidi@ARM.com 5167756SAli.Saidi@ARM.com # LTO support is only really working properly from 4.6 and beyond 5179227Sandreas.hansson@arm.com if compareVersions(gcc_version, '4.6') >= 0: 5189227Sandreas.hansson@arm.com # Add the appropriate Link-Time Optimization (LTO) flags 5199227Sandreas.hansson@arm.com # unless LTO is explicitly turned off. Note that these flags 5209227Sandreas.hansson@arm.com # are only used by the fast target. 5219590Sandreas@sandberg.pp.se if not GetOption('no_lto'): 5229590Sandreas@sandberg.pp.se # Pass the LTO flag when compiling to produce GIMPLE 5239590Sandreas@sandberg.pp.se # output, we merely create the flags here and only append 5249590Sandreas@sandberg.pp.se # them later/ 5259590Sandreas@sandberg.pp.se main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 5269590Sandreas@sandberg.pp.se 5276654Snate@binkert.org # Use the same amount of jobs for LTO as we are running 5286654Snate@binkert.org # scons with, we hardcode the use of the linker plugin 5295871Snate@binkert.org # which requires either gold or GNU ld >= 2.21 5306121Snate@binkert.org main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'), 5318946Sandreas.hansson@arm.com '-fuse-linker-plugin'] 5329419Sandreas.hansson@arm.com 5333940Ssaidi@eecs.umich.eduelif main['ICC']: 5343918Ssaidi@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 5353918Ssaidi@eecs.umich.eduelif main['SUNCC']: 5361858SN/A main.Append(CCFLAGS=['-Qoption ccfe']) 5379556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-features=gcc']) 5389556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-features=extensions']) 5399556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-library=stlport4']) 5409556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-xar']) 5419556Sandreas.hansson@arm.com #main.Append(CCFLAGS=['-instances=semiexplicit']) 5429556Sandreas.hansson@arm.comelif main['CLANG']: 5439556Sandreas.hansson@arm.com clang_version_re = re.compile(".* version (\d+\.\d+)") 5449556Sandreas.hansson@arm.com clang_version_match = clang_version_re.match(CXX_version) 5459556Sandreas.hansson@arm.com if (clang_version_match): 5469556Sandreas.hansson@arm.com clang_version = clang_version_match.groups()[0] 5479556Sandreas.hansson@arm.com if compareVersions(clang_version, "2.9") < 0: 5489556Sandreas.hansson@arm.com print 'Error: clang version 2.9 or newer required.' 5499556Sandreas.hansson@arm.com print ' Installed version:', clang_version 5509556Sandreas.hansson@arm.com Exit(1) 5519556Sandreas.hansson@arm.com else: 5529556Sandreas.hansson@arm.com print 'Error: Unable to determine clang version.' 5539556Sandreas.hansson@arm.com Exit(1) 5549556Sandreas.hansson@arm.com 5559556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-pipe']) 5569556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 5579556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5589556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-tautological-compare']) 5599556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-self-assign']) 5609556Sandreas.hansson@arm.com # Ruby makes frequent use of extraneous parantheses in the printing 5619556Sandreas.hansson@arm.com # of if-statements 5629556Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wno-parentheses']) 5639556Sandreas.hansson@arm.com 5649556Sandreas.hansson@arm.com # clang 2.9 does not play well with c++0x as it ships with C++ 5659556Sandreas.hansson@arm.com # headers that produce errors, this was fixed in 3.0 5669556Sandreas.hansson@arm.com if compareVersions(clang_version, "3") >= 0: 5679556Sandreas.hansson@arm.com main.Append(CXXFLAGS=['-std=c++0x']) 5689556Sandreas.hansson@arm.comelse: 5696121Snate@binkert.org print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 5709420Sandreas.hansson@arm.com print "Don't know what compiler options to use for your compiler." 5719420Sandreas.hansson@arm.com print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 5729420Sandreas.hansson@arm.com print termcap.Yellow + ' version:' + termcap.Normal, 5739420Sandreas.hansson@arm.com if not CXX_version: 5749420Sandreas.hansson@arm.com print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 5759420Sandreas.hansson@arm.com termcap.Normal 5769420Sandreas.hansson@arm.com else: 5779420Sandreas.hansson@arm.com print CXX_version.replace('\n', '<nl>') 5789420Sandreas.hansson@arm.com print " If you're trying to use a compiler other than GCC, ICC, SunCC," 5799420Sandreas.hansson@arm.com print " or clang, there appears to be something wrong with your" 5809420Sandreas.hansson@arm.com print " environment." 5817618SAli.Saidi@arm.com print " " 5827618SAli.Saidi@arm.com print " If you are trying to use a compiler other than those listed" 5837618SAli.Saidi@arm.com print " above you will need to ease fix SConstruct and " 5847739Sgblack@eecs.umich.edu print " src/SConscript to support that compiler." 5859227Sandreas.hansson@arm.com Exit(1) 5869227Sandreas.hansson@arm.com 5879227Sandreas.hansson@arm.com# Set up common yacc/bison flags (needed for Ruby) 5889227Sandreas.hansson@arm.commain['YACCFLAGS'] = '-d' 5899227Sandreas.hansson@arm.commain['YACCHXXFILESUFFIX'] = '.hh' 5909227Sandreas.hansson@arm.com 5919227Sandreas.hansson@arm.com# Do this after we save setting back, or else we'll tack on an 5929227Sandreas.hansson@arm.com# extra 'qdo' every time we run scons. 5939227Sandreas.hansson@arm.comif main['BATCH']: 5949227Sandreas.hansson@arm.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5959227Sandreas.hansson@arm.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5969227Sandreas.hansson@arm.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5979227Sandreas.hansson@arm.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5989227Sandreas.hansson@arm.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5999227Sandreas.hansson@arm.com 6009227Sandreas.hansson@arm.comif sys.platform == 'cygwin': 6019227Sandreas.hansson@arm.com # cygwin has some header file issues... 6029227Sandreas.hansson@arm.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 6039590Sandreas@sandberg.pp.se 6049590Sandreas@sandberg.pp.se# Check for SWIG 6059590Sandreas@sandberg.pp.seif not main.has_key('SWIG'): 6068737Skoansin.tan@gmail.com print 'Error: SWIG utility not found.' 6079420Sandreas.hansson@arm.com print ' Please install (see http://www.swig.org) and retry.' 6089420Sandreas.hansson@arm.com Exit(1) 6099420Sandreas.hansson@arm.com 6108737Skoansin.tan@gmail.com# Check for appropriate SWIG version 6118737Skoansin.tan@gmail.comswig_version = readCommand([main['SWIG'], '-version'], exception='').split() 6128737Skoansin.tan@gmail.com# First 3 words should be "SWIG Version x.y.z" 6138737Skoansin.tan@gmail.comif len(swig_version) < 3 or \ 6148737Skoansin.tan@gmail.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 6158737Skoansin.tan@gmail.com print 'Error determining SWIG version.' 6168737Skoansin.tan@gmail.com Exit(1) 6178737Skoansin.tan@gmail.com 6188737Skoansin.tan@gmail.commin_swig_version = '1.3.34' 6198737Skoansin.tan@gmail.comif compareVersions(swig_version[2], min_swig_version) < 0: 6208737Skoansin.tan@gmail.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 6218737Skoansin.tan@gmail.com print ' Installed version:', swig_version[2] 6229556Sandreas.hansson@arm.com Exit(1) 6239556Sandreas.hansson@arm.com 6249556Sandreas.hansson@arm.com# Set up SWIG flags & scanner 6259556Sandreas.hansson@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 6269556Sandreas.hansson@arm.commain.Append(SWIGFLAGS=swig_flags) 6279556Sandreas.hansson@arm.com 6289556Sandreas.hansson@arm.com# filter out all existing swig scanners, they mess up the dependency 6299556Sandreas.hansson@arm.com# stuff for some reason 6309556Sandreas.hansson@arm.comscanners = [] 6319556Sandreas.hansson@arm.comfor scanner in main['SCANNERS']: 6329590Sandreas@sandberg.pp.se skeys = scanner.skeys 6339590Sandreas@sandberg.pp.se if skeys == '.i': 6349420Sandreas.hansson@arm.com continue 6359846Sandreas.hansson@arm.com 6369846Sandreas.hansson@arm.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 6379846Sandreas.hansson@arm.com continue 6389846Sandreas.hansson@arm.com 6398946Sandreas.hansson@arm.com scanners.append(scanner) 6403918Ssaidi@eecs.umich.edu 6419068SAli.Saidi@ARM.com# add the new swig scanner that we like better 6429068SAli.Saidi@ARM.comfrom SCons.Scanner import ClassicCPP as CPPScanner 6439068SAli.Saidi@ARM.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 6449068SAli.Saidi@ARM.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 6459068SAli.Saidi@ARM.com 6469068SAli.Saidi@ARM.com# replace the scanners list that has what we want 6479068SAli.Saidi@ARM.commain['SCANNERS'] = scanners 6489068SAli.Saidi@ARM.com 6499068SAli.Saidi@ARM.com# Add a custom Check function to the Configure context so that we can 6509419Sandreas.hansson@arm.com# figure out if the compiler adds leading underscores to global 6519068SAli.Saidi@ARM.com# variables. This is needed for the autogenerated asm files that we 6529068SAli.Saidi@ARM.com# use for embedding the python code. 6539068SAli.Saidi@ARM.comdef CheckLeading(context): 6549068SAli.Saidi@ARM.com context.Message("Checking for leading underscore in global variables...") 6559068SAli.Saidi@ARM.com # 1) Define a global variable called x from asm so the C compiler 6569068SAli.Saidi@ARM.com # won't change the symbol at all. 6573918Ssaidi@eecs.umich.edu # 2) Declare that variable. 6583918Ssaidi@eecs.umich.edu # 3) Use the variable 6596157Snate@binkert.org # 6606157Snate@binkert.org # If the compiler prepends an underscore, this will successfully 6616157Snate@binkert.org # link because the external symbol 'x' will be called '_x' which 6626157Snate@binkert.org # was defined by the asm statement. If the compiler does not 6635397Ssaidi@eecs.umich.edu # prepend an underscore, this will not successfully link because 6645397Ssaidi@eecs.umich.edu # '_x' will have been defined by assembly, while the C portion of 6656121Snate@binkert.org # the code will be trying to use 'x' 6666121Snate@binkert.org ret = context.TryLink(''' 6676121Snate@binkert.org asm(".globl _x; _x: .byte 0"); 6686121Snate@binkert.org extern int x; 6696121Snate@binkert.org int main() { return x; } 6706121Snate@binkert.org ''', extension=".c") 6715397Ssaidi@eecs.umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 6721851SN/A context.Result(ret) 6731851SN/A return ret 6747739Sgblack@eecs.umich.edu 675955SN/A# Platform-specific configuration. Note again that we assume that all 6769396Sandreas.hansson@arm.com# builds under a given build root run on the same host platform. 6779396Sandreas.hansson@arm.comconf = Configure(main, 6789396Sandreas.hansson@arm.com conf_dir = joinpath(build_root, '.scons_config'), 6799396Sandreas.hansson@arm.com log_file = joinpath(build_root, 'scons_config.log'), 6809396Sandreas.hansson@arm.com custom_tests = { 'CheckLeading' : CheckLeading }) 6819396Sandreas.hansson@arm.com 6829396Sandreas.hansson@arm.com# Check for leading underscores. Don't really need to worry either 6839396Sandreas.hansson@arm.com# way so don't need to check the return code. 6849396Sandreas.hansson@arm.comconf.CheckLeading() 6859396Sandreas.hansson@arm.com 6869396Sandreas.hansson@arm.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6879396Sandreas.hansson@arm.comtry: 6889396Sandreas.hansson@arm.com import platform 6899396Sandreas.hansson@arm.com uname = platform.uname() 6909396Sandreas.hansson@arm.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6919396Sandreas.hansson@arm.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6929477Sandreas.hansson@arm.com main.Append(CCFLAGS=['-arch', 'x86_64']) 6939477Sandreas.hansson@arm.com main.Append(CFLAGS=['-arch', 'x86_64']) 6949477Sandreas.hansson@arm.com main.Append(LINKFLAGS=['-arch', 'x86_64']) 6959477Sandreas.hansson@arm.com main.Append(ASFLAGS=['-arch', 'x86_64']) 6969477Sandreas.hansson@arm.comexcept: 6979477Sandreas.hansson@arm.com pass 6989477Sandreas.hansson@arm.com 6999477Sandreas.hansson@arm.com# Recent versions of scons substitute a "Null" object for Configure() 7009477Sandreas.hansson@arm.com# when configuration isn't necessary, e.g., if the "--help" option is 7019477Sandreas.hansson@arm.com# present. Unfortuantely this Null object always returns false, 7029477Sandreas.hansson@arm.com# breaking all our configuration checks. We replace it with our own 7039477Sandreas.hansson@arm.com# more optimistic null object that returns True instead. 7049477Sandreas.hansson@arm.comif not conf: 7059477Sandreas.hansson@arm.com def NullCheck(*args, **kwargs): 7069477Sandreas.hansson@arm.com return True 7079477Sandreas.hansson@arm.com 7089477Sandreas.hansson@arm.com class NullConf: 7099477Sandreas.hansson@arm.com def __init__(self, env): 7109477Sandreas.hansson@arm.com self.env = env 7119477Sandreas.hansson@arm.com def Finish(self): 7129477Sandreas.hansson@arm.com return self.env 7139477Sandreas.hansson@arm.com def __getattr__(self, mname): 7149396Sandreas.hansson@arm.com return NullCheck 7153053Sstever@eecs.umich.edu 7166121Snate@binkert.org conf = NullConf(main) 7173053Sstever@eecs.umich.edu 7183053Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 7193053Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 7203053Sstever@eecs.umich.edu# installation used to run scons (and thus this script). If you want 7213053Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how 7229072Sandreas.hansson@arm.com# to invoke scons with a different copy of the Python interpreter. 7233053Sstever@eecs.umich.edufrom distutils import sysconfig 7244742Sstever@eecs.umich.edu 7254742Sstever@eecs.umich.edupy_getvar = sysconfig.get_config_var 7263053Sstever@eecs.umich.edu 7273053Sstever@eecs.umich.edupy_debug = getattr(sys, 'pydebug', False) 7283053Sstever@eecs.umich.edupy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 7298960Ssteve.reinhardt@amd.com 7306654Snate@binkert.orgpy_general_include = sysconfig.get_python_inc() 7313053Sstever@eecs.umich.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True) 7323053Sstever@eecs.umich.edupy_includes = [ py_general_include ] 7333053Sstever@eecs.umich.eduif py_platform_include != py_general_include: 7343053Sstever@eecs.umich.edu py_includes.append(py_platform_include) 7359877Sandreas.hansson@arm.com 7369877Sandreas.hansson@arm.compy_lib_path = [ py_getvar('LIBDIR') ] 7379877Sandreas.hansson@arm.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no 7389877Sandreas.hansson@arm.com# shared library in prefix/lib/. 7399877Sandreas.hansson@arm.comif not py_getvar('Py_ENABLE_SHARED'): 7409585Sandreas@sandberg.pp.se py_lib_path.append(py_getvar('LIBPL')) 7419877Sandreas.hansson@arm.com 7429585Sandreas@sandberg.pp.sepy_libs = [] 7439877Sandreas.hansson@arm.comfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 7449877Sandreas.hansson@arm.com if not lib.startswith('-l'): 7459585Sandreas@sandberg.pp.se # Python requires some special flags to link (e.g. -framework 7462667Sstever@eecs.umich.edu # common on OS X systems), assume appending preserves order 7474554Sbinkertn@umich.edu main.Append(LINKFLAGS=[lib]) 7486121Snate@binkert.org else: 7492667Sstever@eecs.umich.edu lib = lib[2:] 7504554Sbinkertn@umich.edu if lib not in py_libs: 7514554Sbinkertn@umich.edu py_libs.append(lib) 7524554Sbinkertn@umich.edupy_libs.append(py_version) 7536121Snate@binkert.org 7544554Sbinkertn@umich.edumain.Append(CPPPATH=py_includes) 7554554Sbinkertn@umich.edumain.Append(LIBPATH=py_lib_path) 7564554Sbinkertn@umich.edu 7574781Snate@binkert.org# Cache build files in the supplied directory. 7584554Sbinkertn@umich.eduif main['M5_BUILD_CACHE']: 7594554Sbinkertn@umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 7602667Sstever@eecs.umich.edu CacheDir(main['M5_BUILD_CACHE']) 7614554Sbinkertn@umich.edu 7624554Sbinkertn@umich.edu 7634554Sbinkertn@umich.edu# verify that this stuff works 7644554Sbinkertn@umich.eduif not conf.CheckHeader('Python.h', '<>'): 7652667Sstever@eecs.umich.edu print "Error: can't find Python.h header in", py_includes 7664554Sbinkertn@umich.edu Exit(1) 7672667Sstever@eecs.umich.edu 7684554Sbinkertn@umich.edufor lib in py_libs: 7696121Snate@binkert.org if not conf.CheckLib(lib): 7702667Sstever@eecs.umich.edu print "Error: can't find library %s required by python" % lib 7715522Snate@binkert.org Exit(1) 7725522Snate@binkert.org 7735522Snate@binkert.org# On Solaris you need to use libsocket for socket ops 7745522Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7755522Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7765522Snate@binkert.org print "Can't find library with socket calls (e.g. accept())" 7775522Snate@binkert.org Exit(1) 7785522Snate@binkert.org 7795522Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 7805522Snate@binkert.org# added to the LIBS environment variable. 7815522Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7825522Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 7835522Snate@binkert.org 'and/or zlib.h header file.' 7845522Snate@binkert.org print ' Please install zlib and try again.' 7855522Snate@binkert.org Exit(1) 7865522Snate@binkert.org 7875522Snate@binkert.org# Check for librt. 7885522Snate@binkert.orghave_posix_clock = \ 7895522Snate@binkert.org conf.CheckLibWithHeader(None, 'time.h', 'C', 7905522Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') or \ 7915522Snate@binkert.org conf.CheckLibWithHeader('rt', 'time.h', 'C', 7925522Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') 7935522Snate@binkert.org 7945522Snate@binkert.orgif conf.CheckLib('tcmalloc_minimal'): 7955522Snate@binkert.org have_tcmalloc = True 7965522Snate@binkert.orgelse: 7979986Sandreas@sandberg.pp.se have_tcmalloc = False 7989986Sandreas@sandberg.pp.se print termcap.Yellow + termcap.Bold + \ 7999986Sandreas@sandberg.pp.se "You can get a 12% performance improvement by installing tcmalloc "\ 8009986Sandreas@sandberg.pp.se "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \ 8019986Sandreas@sandberg.pp.se termcap.Normal 8029986Sandreas@sandberg.pp.se 8039986Sandreas@sandberg.pp.seif not have_posix_clock: 8049986Sandreas@sandberg.pp.se print "Can't find library for POSIX clocks." 8059986Sandreas@sandberg.pp.se 8069986Sandreas@sandberg.pp.se# Check for <fenv.h> (C99 FP environment control) 8079986Sandreas@sandberg.pp.sehave_fenv = conf.CheckHeader('fenv.h', '<>') 8089986Sandreas@sandberg.pp.seif not have_fenv: 8099986Sandreas@sandberg.pp.se print "Warning: Header file <fenv.h> not found." 8109986Sandreas@sandberg.pp.se print " This host has no IEEE FP rounding mode control." 8119986Sandreas@sandberg.pp.se 8129986Sandreas@sandberg.pp.se###################################################################### 8139986Sandreas@sandberg.pp.se# 8149986Sandreas@sandberg.pp.se# Finish the configuration 8159986Sandreas@sandberg.pp.se# 8169986Sandreas@sandberg.pp.semain = conf.Finish() 8172638Sstever@eecs.umich.edu 8182638Sstever@eecs.umich.edu###################################################################### 8196121Snate@binkert.org# 8203716Sstever@eecs.umich.edu# Collect all non-global variables 8215522Snate@binkert.org# 8229986Sandreas@sandberg.pp.se 8239986Sandreas@sandberg.pp.se# Define the universe of supported ISAs 8249986Sandreas@sandberg.pp.seall_isa_list = [ ] 8259986Sandreas@sandberg.pp.seExport('all_isa_list') 8265522Snate@binkert.org 8275522Snate@binkert.orgclass CpuModel(object): 8285522Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 8295522Snate@binkert.org know about a particular CPU model.''' 8301858SN/A 8315227Ssaidi@eecs.umich.edu # Dict of available CPU model objects. Accessible as CpuModel.dict. 8325227Ssaidi@eecs.umich.edu dict = {} 8335227Ssaidi@eecs.umich.edu list = [] 8345227Ssaidi@eecs.umich.edu defaults = [] 8356654Snate@binkert.org 8366654Snate@binkert.org # Constructor. Automatically adds models to CpuModel.dict. 8377769SAli.Saidi@ARM.com def __init__(self, name, filename, includes, strings, default=False): 8387769SAli.Saidi@ARM.com self.name = name # name of model 8397769SAli.Saidi@ARM.com self.filename = filename # filename for output exec code 8407769SAli.Saidi@ARM.com self.includes = includes # include files needed in exec file 8415227Ssaidi@eecs.umich.edu # The 'strings' dict holds all the per-CPU symbols we can 8425227Ssaidi@eecs.umich.edu # substitute into templates etc. 8435227Ssaidi@eecs.umich.edu self.strings = strings 8445204Sstever@gmail.com 8455204Sstever@gmail.com # This cpu is enabled by default 8465204Sstever@gmail.com self.default = default 8475204Sstever@gmail.com 8485204Sstever@gmail.com # Add self to dict 8495204Sstever@gmail.com if name in CpuModel.dict: 8505204Sstever@gmail.com raise AttributeError, "CpuModel '%s' already registered" % name 8515204Sstever@gmail.com CpuModel.dict[name] = self 8525204Sstever@gmail.com CpuModel.list.append(name) 8535204Sstever@gmail.com 8545204Sstever@gmail.comExport('CpuModel') 8555204Sstever@gmail.com 8565204Sstever@gmail.com# Sticky variables get saved in the variables file so they persist from 8575204Sstever@gmail.com# one invocation to the next (unless overridden, in which case the new 8585204Sstever@gmail.com# value becomes sticky). 8595204Sstever@gmail.comsticky_vars = Variables(args=ARGUMENTS) 8605204Sstever@gmail.comExport('sticky_vars') 8616121Snate@binkert.org 8625204Sstever@gmail.com# Sticky variables that should be exported 8637727SAli.Saidi@ARM.comexport_vars = [] 8647727SAli.Saidi@ARM.comExport('export_vars') 8657727SAli.Saidi@ARM.com 8667727SAli.Saidi@ARM.com# For Ruby 8677727SAli.Saidi@ARM.comall_protocols = [] 8689812Sandreas.hansson@arm.comExport('all_protocols') 8699812Sandreas.hansson@arm.comprotocol_dirs = [] 8709812Sandreas.hansson@arm.comExport('protocol_dirs') 8719812Sandreas.hansson@arm.comslicc_includes = [] 8729812Sandreas.hansson@arm.comExport('slicc_includes') 8739812Sandreas.hansson@arm.com 8749812Sandreas.hansson@arm.com# Walk the tree and execute all SConsopts scripts that wil add to the 8759812Sandreas.hansson@arm.com# above variables 8769812Sandreas.hansson@arm.comif not GetOption('verbose'): 8779812Sandreas.hansson@arm.com print "Reading SConsopts" 8789812Sandreas.hansson@arm.comfor bdir in [ base_dir ] + extras_dir_list: 8799812Sandreas.hansson@arm.com if not isdir(bdir): 8809812Sandreas.hansson@arm.com print "Error: directory '%s' does not exist" % bdir 8819812Sandreas.hansson@arm.com Exit(1) 8829812Sandreas.hansson@arm.com for root, dirs, files in os.walk(bdir): 8839812Sandreas.hansson@arm.com if 'SConsopts' in files: 8849812Sandreas.hansson@arm.com if GetOption('verbose'): 8859812Sandreas.hansson@arm.com print "Reading", joinpath(root, 'SConsopts') 8869812Sandreas.hansson@arm.com SConscript(joinpath(root, 'SConsopts')) 8879812Sandreas.hansson@arm.com 8889812Sandreas.hansson@arm.comall_isa_list.sort() 8899812Sandreas.hansson@arm.com 8909812Sandreas.hansson@arm.comsticky_vars.AddVariables( 8919812Sandreas.hansson@arm.com EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 8927727SAli.Saidi@ARM.com ListVariable('CPU_MODELS', 'CPU models', 8935863Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 8943118Sstever@eecs.umich.edu sorted(CpuModel.list)), 8955863Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 8969239Sandreas.hansson@arm.com False), 8973118Sstever@eecs.umich.edu BoolVariable('SS_COMPATIBLE_FP', 8983118Sstever@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 8995863Snate@binkert.org False), 9005863Snate@binkert.org BoolVariable('USE_SSE2', 9015863Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 9025863Snate@binkert.org False), 9033118Sstever@eecs.umich.edu BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 9043483Ssaidi@eecs.umich.edu BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 9053494Ssaidi@eecs.umich.edu BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 9063494Ssaidi@eecs.umich.edu EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 9073483Ssaidi@eecs.umich.edu all_protocols), 9083483Ssaidi@eecs.umich.edu ) 9093483Ssaidi@eecs.umich.edu 9103053Sstever@eecs.umich.edu# These variables get exported to #defines in config/*.hh (see src/SConscript). 9113053Sstever@eecs.umich.eduexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 9123918Ssaidi@eecs.umich.edu 'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'PROTOCOL', 9133053Sstever@eecs.umich.edu ] 9143053Sstever@eecs.umich.edu 9153053Sstever@eecs.umich.edu################################################### 9163053Sstever@eecs.umich.edu# 9173053Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers. 9189396Sandreas.hansson@arm.com# 9199396Sandreas.hansson@arm.com################################################### 9209396Sandreas.hansson@arm.com 9219396Sandreas.hansson@arm.com# This function generates a config header file that #defines the 9229396Sandreas.hansson@arm.com# variable symbol to the current variable setting (0 or 1). The source 9239396Sandreas.hansson@arm.com# operands are the name of the variable and a Value node containing the 9249396Sandreas.hansson@arm.com# value of the variable. 9259396Sandreas.hansson@arm.comdef build_config_file(target, source, env): 9269396Sandreas.hansson@arm.com (variable, value) = [s.get_contents() for s in source] 9279477Sandreas.hansson@arm.com f = file(str(target[0]), 'w') 9289396Sandreas.hansson@arm.com print >> f, '#define', variable, value 9299477Sandreas.hansson@arm.com f.close() 9309477Sandreas.hansson@arm.com return None 9319477Sandreas.hansson@arm.com 9329477Sandreas.hansson@arm.com# Combine the two functions into a scons Action object. 9339396Sandreas.hansson@arm.comconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 9347840Snate@binkert.org 9357865Sgblack@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 9367865Sgblack@eecs.umich.edu# we're really doing. 9377865Sgblack@eecs.umich.edudef config_emitter(target, source, env): 9387865Sgblack@eecs.umich.edu # extract variable name from Builder arg 9397865Sgblack@eecs.umich.edu variable = str(target[0]) 9407840Snate@binkert.org # True target is config header file 9419900Sandreas@sandberg.pp.se target = joinpath('config', variable.lower() + '.hh') 9429900Sandreas@sandberg.pp.se val = env[variable] 9439900Sandreas@sandberg.pp.se if isinstance(val, bool): 9449900Sandreas@sandberg.pp.se # Force value to 0/1 9459591Sandreas@sandberg.pp.se val = int(val) 9469591Sandreas@sandberg.pp.se elif isinstance(val, str): 9479591Sandreas@sandberg.pp.se val = '"' + val + '"' 9489590Sandreas@sandberg.pp.se 9499590Sandreas@sandberg.pp.se # Sources are variable name & value (packaged in SCons Value nodes) 9509045SAli.Saidi@ARM.com return ([target], [Value(variable), Value(val)]) 9519045SAli.Saidi@ARM.com 9529071Sandreas.hansson@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 9539071Sandreas.hansson@arm.com 9549045SAli.Saidi@ARM.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 9557840Snate@binkert.org 9567840Snate@binkert.org# libelf build is shared across all configs in the build root. 9577840Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 9581858SN/A variant_dir = joinpath(build_root, 'libelf')) 9591858SN/A 9601858SN/A# gzstream build is shared across all configs in the build root. 9611858SN/Amain.SConscript('ext/gzstream/SConscript', 9621858SN/A variant_dir = joinpath(build_root, 'gzstream')) 9631858SN/A 9649903Sandreas.hansson@arm.com################################################### 9659903Sandreas.hansson@arm.com# 9669903Sandreas.hansson@arm.com# This function is used to set up a directory with switching headers 9679903Sandreas.hansson@arm.com# 9689903Sandreas.hansson@arm.com################################################### 9699903Sandreas.hansson@arm.com 9709651SAndreas.Sandberg@ARM.commain['ALL_ISA_LIST'] = all_isa_list 9719903Sandreas.hansson@arm.comdef make_switching_dir(dname, switch_headers, env): 9729651SAndreas.Sandberg@ARM.com # Generate the header. target[0] is the full path of the output 9739651SAndreas.Sandberg@ARM.com # header to generate. 'source' is a dummy variable, since we get the 9749651SAndreas.Sandberg@ARM.com # list of ISAs from env['ALL_ISA_LIST']. 9759651SAndreas.Sandberg@ARM.com def gen_switch_hdr(target, source, env): 9769651SAndreas.Sandberg@ARM.com fname = str(target[0]) 9779657Sandreas.sandberg@arm.com f = open(fname, 'w') 9789883Sandreas@sandberg.pp.se isa = env['TARGET_ISA'].lower() 9799651SAndreas.Sandberg@ARM.com print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 9809651SAndreas.Sandberg@ARM.com f.close() 9819651SAndreas.Sandberg@ARM.com 9829651SAndreas.Sandberg@ARM.com # Build SCons Action object. 'varlist' specifies env vars that this 9839651SAndreas.Sandberg@ARM.com # action depends on; when env['ALL_ISA_LIST'] changes these actions 9849651SAndreas.Sandberg@ARM.com # should get re-executed. 9859651SAndreas.Sandberg@ARM.com switch_hdr_action = MakeAction(gen_switch_hdr, 9869651SAndreas.Sandberg@ARM.com Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 9879651SAndreas.Sandberg@ARM.com 9889651SAndreas.Sandberg@ARM.com # Instantiate actions for each header 9899651SAndreas.Sandberg@ARM.com for hdr in switch_headers: 9909986Sandreas@sandberg.pp.se env.Command(hdr, [], switch_hdr_action) 9919986Sandreas@sandberg.pp.seExport('make_switching_dir') 9929986Sandreas@sandberg.pp.se 9939986Sandreas@sandberg.pp.se################################################### 9949986Sandreas@sandberg.pp.se# 9959986Sandreas@sandberg.pp.se# Define build environments for selected configurations. 9965863Snate@binkert.org# 9975863Snate@binkert.org################################################### 9985863Snate@binkert.org 9995863Snate@binkert.orgfor variant_path in variant_paths: 10006121Snate@binkert.org print "Building in", variant_path 10011858SN/A 10025863Snate@binkert.org # Make a copy of the build-root environment to use for this config. 10035863Snate@binkert.org env = main.Clone() 10045863Snate@binkert.org env['BUILDDIR'] = variant_path 10055863Snate@binkert.org 10065863Snate@binkert.org # variant_dir is the tail component of build path, and is used to 10072139SN/A # determine the build parameters (e.g., 'ALPHA_SE') 10084202Sbinkertn@umich.edu (build_root, variant_dir) = splitpath(variant_path) 10094202Sbinkertn@umich.edu 10102139SN/A # Set env variables according to the build directory config. 10116994Snate@binkert.org sticky_vars.files = [] 10126994Snate@binkert.org # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 10136994Snate@binkert.org # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 10146994Snate@binkert.org # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 10156994Snate@binkert.org current_vars_file = joinpath(build_root, 'variables', variant_dir) 10166994Snate@binkert.org if isfile(current_vars_file): 10176994Snate@binkert.org sticky_vars.files.append(current_vars_file) 10186994Snate@binkert.org print "Using saved variables file %s" % current_vars_file 10196994Snate@binkert.org else: 10206994Snate@binkert.org # Build dir-specific variables file doesn't exist. 10216994Snate@binkert.org 10226994Snate@binkert.org # Make sure the directory is there so we can create it later 10236994Snate@binkert.org opt_dir = dirname(current_vars_file) 10246994Snate@binkert.org if not isdir(opt_dir): 10256994Snate@binkert.org mkdir(opt_dir) 10266994Snate@binkert.org 10276994Snate@binkert.org # Get default build variables from source tree. Variables are 10286994Snate@binkert.org # normally determined by name of $VARIANT_DIR, but can be 10296994Snate@binkert.org # overridden by '--default=' arg on command line. 10306994Snate@binkert.org default = GetOption('default') 10316994Snate@binkert.org opts_dir = joinpath(main.root.abspath, 'build_opts') 10326994Snate@binkert.org if default: 10336994Snate@binkert.org default_vars_files = [joinpath(build_root, 'variables', default), 10346994Snate@binkert.org joinpath(opts_dir, default)] 10356994Snate@binkert.org else: 10366994Snate@binkert.org default_vars_files = [joinpath(opts_dir, variant_dir)] 10376994Snate@binkert.org existing_files = filter(isfile, default_vars_files) 10386994Snate@binkert.org if existing_files: 10392155SN/A default_vars_file = existing_files[0] 10405863Snate@binkert.org sticky_vars.files.append(default_vars_file) 10411869SN/A print "Variables file %s not found,\n using defaults in %s" \ 10421869SN/A % (current_vars_file, default_vars_file) 10435863Snate@binkert.org else: 10445863Snate@binkert.org print "Error: cannot find variables file %s or " \ 10454202Sbinkertn@umich.edu "default file(s) %s" \ 10466108Snate@binkert.org % (current_vars_file, ' or '.join(default_vars_files)) 10476108Snate@binkert.org Exit(1) 10486108Snate@binkert.org 10496108Snate@binkert.org # Apply current variable settings to env 10509219Spower.jg@gmail.com sticky_vars.Update(env) 10519219Spower.jg@gmail.com 10529219Spower.jg@gmail.com help_texts["local_vars"] += \ 10539219Spower.jg@gmail.com "Build variables for %s:\n" % variant_dir \ 10549219Spower.jg@gmail.com + sticky_vars.GenerateHelpText(env) 10559219Spower.jg@gmail.com 10569219Spower.jg@gmail.com # Process variable settings. 10579219Spower.jg@gmail.com 10584202Sbinkertn@umich.edu if not have_fenv and env['USE_FENV']: 10595863Snate@binkert.org print "Warning: <fenv.h> not available; " \ 10608474Sgblack@eecs.umich.edu "forcing USE_FENV to False in", variant_dir + "." 10618474Sgblack@eecs.umich.edu env['USE_FENV'] = False 10625742Snate@binkert.org 10638268Ssteve.reinhardt@amd.com if not env['USE_FENV']: 10648268Ssteve.reinhardt@amd.com print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 10658268Ssteve.reinhardt@amd.com print " FP results may deviate slightly from other platforms." 10665742Snate@binkert.org 10675341Sstever@gmail.com if env['EFENCE']: 10688474Sgblack@eecs.umich.edu env.Append(LIBS=['efence']) 10698474Sgblack@eecs.umich.edu 10705342Sstever@gmail.com # Save sticky variable settings back to current variables file 10714202Sbinkertn@umich.edu sticky_vars.Save(current_vars_file, env) 10724202Sbinkertn@umich.edu 10734202Sbinkertn@umich.edu if env['USE_SSE2']: 10745863Snate@binkert.org env.Append(CCFLAGS=['-msse2']) 10755863Snate@binkert.org 10766994Snate@binkert.org if have_tcmalloc: 10776994Snate@binkert.org env.Append(LIBS=['tcmalloc_minimal']) 10786994Snate@binkert.org 10795863Snate@binkert.org # The src/SConscript file sets up the build rules in 'env' according 10805863Snate@binkert.org # to the configured variables. It returns a list of environments, 10815863Snate@binkert.org # one for each variant build (debug, opt, etc.) 10825863Snate@binkert.org envList = SConscript('src/SConscript', variant_dir = variant_path, 10835863Snate@binkert.org exports = 'env') 10845863Snate@binkert.org 10855863Snate@binkert.org # Set up the regression tests for each build. 10865863Snate@binkert.org for e in envList: 10877840Snate@binkert.org SConscript('tests/SConscript', 10885863Snate@binkert.org variant_dir = joinpath(variant_path, 'tests', e.Label), 10895952Ssaidi@eecs.umich.edu exports = { 'env' : e }, duplicate = False) 10909651SAndreas.Sandberg@ARM.com 10919219Spower.jg@gmail.com# base help text 10929219Spower.jg@gmail.comHelp(''' 10931869SN/AUsage: scons [scons options] [build variables] [target(s)] 10941858SN/A 10955863Snate@binkert.orgExtra scons options: 10969420Sandreas.hansson@arm.com%(options)s 10979986Sandreas@sandberg.pp.se 10989986Sandreas@sandberg.pp.seGlobal build variables: 10991858SN/A%(global_vars)s 1100955SN/A 1101955SN/A%(local_vars)s 11021869SN/A''' % help_texts) 11031869SN/A