SConstruct revision 5872:98f6215dffce
1955SN/A# -*- mode:python -*- 2955SN/A 310841Sandreas.sandberg@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company 49812Sandreas.hansson@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 59812Sandreas.hansson@arm.com# All rights reserved. 69812Sandreas.hansson@arm.com# 79812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 89812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 99812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 109812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 119812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 129812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 139812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 149812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 157816Ssteve.reinhardt@amd.com# contributors may be used to endorse or promote products derived from 165871Snate@binkert.org# this software without specific prior written permission. 171762SN/A# 18955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29955SN/A# 30955SN/A# Authors: Steve Reinhardt 31955SN/A# Nathan Binkert 32955SN/A 33955SN/A################################################### 34955SN/A# 35955SN/A# SCons top-level build description (SConstruct) file. 36955SN/A# 37955SN/A# While in this directory ('m5'), just type 'scons' to build the default 38955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 39955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 40955SN/A# the optimized full-system version). 41955SN/A# 422665Ssaidi@eecs.umich.edu# You can build M5 in a different directory as long as there is a 432665Ssaidi@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 445863Snate@binkert.org# expects that all configs under the same build directory are being 45955SN/A# built for the same host system. 46955SN/A# 47955SN/A# Examples: 48955SN/A# 49955SN/A# The following two commands are equivalent. The '-u' option tells 508878Ssteve.reinhardt@amd.com# scons to search up the directory tree for this SConstruct file. 512632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 528878Ssteve.reinhardt@amd.com# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 532632Sstever@eecs.umich.edu# 54955SN/A# The following two commands are equivalent and demonstrate building 558878Ssteve.reinhardt@amd.com# in a directory outside of the source tree. The '-C' option tells 562632Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 572761Sstever@eecs.umich.edu# file. 582632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 592632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 602632Sstever@eecs.umich.edu# 612761Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 622761Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 632761Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 648878Ssteve.reinhardt@amd.com# options as well. 658878Ssteve.reinhardt@amd.com# 662761Sstever@eecs.umich.edu################################################### 672761Sstever@eecs.umich.edu 682761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. 692761Sstever@eecs.umich.edutry: 702761Sstever@eecs.umich.edu # Really old versions of scons only take two options for the 718878Ssteve.reinhardt@amd.com # function, so check once without the revision and once with the 728878Ssteve.reinhardt@amd.com # revision, the first instance will fail for stuff other than 732632Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 742632Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 758878Ssteve.reinhardt@amd.com EnsureSConsVersion(0, 98, 1) 768878Ssteve.reinhardt@amd.comexcept SystemExit, e: 772632Sstever@eecs.umich.edu print """ 78955SN/AFor more details, see: 79955SN/A http://m5sim.org/wiki/index.php/Compiling_M5 80955SN/A""" 815863Snate@binkert.org raise 825863Snate@binkert.org 835863Snate@binkert.org# We ensure the python version early because we have stuff that 845863Snate@binkert.org# requires python 2.4 855863Snate@binkert.orgtry: 865863Snate@binkert.org EnsurePythonVersion(2, 4) 875863Snate@binkert.orgexcept SystemExit, e: 885863Snate@binkert.org print """ 895863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 905863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 915863Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter 928878Ssteve.reinhardt@amd.comon the scons script. 935863Snate@binkert.org 945863Snate@binkert.orgFor more details, see: 955863Snate@binkert.org http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 969812Sandreas.hansson@arm.com""" 979812Sandreas.hansson@arm.com raise 985863Snate@binkert.org 999812Sandreas.hansson@arm.comimport os 1005863Snate@binkert.orgimport re 1015863Snate@binkert.orgimport subprocess 1025863Snate@binkert.orgimport sys 1039812Sandreas.hansson@arm.com 1049812Sandreas.hansson@arm.comfrom os import mkdir, environ 1055863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1065863Snate@binkert.orgfrom os.path import exists, isdir, isfile 1078878Ssteve.reinhardt@amd.comfrom os.path import join as joinpath, split as splitpath 1085863Snate@binkert.org 1095863Snate@binkert.orgimport SCons 1105863Snate@binkert.orgimport SCons.Node 1116654Snate@binkert.org 11210196SCurtis.Dunham@arm.comdef read_command(cmd, **kwargs): 113955SN/A """run the command cmd, read the results and return them 1145396Ssaidi@eecs.umich.edu this is sorta like `cmd` in shell""" 11511401Sandreas.sandberg@arm.com from subprocess import Popen, PIPE, STDOUT 1165863Snate@binkert.org 1175863Snate@binkert.org if isinstance(cmd, str): 1184202Sbinkertn@umich.edu cmd = cmd.split() 1195863Snate@binkert.org 1205863Snate@binkert.org no_exception = 'exception' in kwargs 1215863Snate@binkert.org exception = kwargs.pop('exception', None) 1225863Snate@binkert.org 123955SN/A kwargs.setdefault('shell', False) 1246654Snate@binkert.org kwargs.setdefault('stdout', PIPE) 1255273Sstever@gmail.com kwargs.setdefault('stderr', STDOUT) 1265871Snate@binkert.org kwargs.setdefault('close_fds', True) 1275273Sstever@gmail.com try: 1286655Snate@binkert.org subp = Popen(cmd, **kwargs) 1298878Ssteve.reinhardt@amd.com except Exception, e: 1306655Snate@binkert.org if no_exception: 1316655Snate@binkert.org return exception 1329219Spower.jg@gmail.com raise 1336655Snate@binkert.org 1345871Snate@binkert.org return subp.communicate()[0] 1356654Snate@binkert.org 1368947Sandreas.hansson@arm.com# helper function: compare arrays or strings of version numbers. 1375396Ssaidi@eecs.umich.edu# E.g., compare_version((1,3,25), (1,4,1)') 1388120Sgblack@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1398120Sgblack@eecs.umich.edudef compare_versions(v1, v2): 1408120Sgblack@eecs.umich.edu def make_version_list(v): 1418120Sgblack@eecs.umich.edu if isinstance(v, (list,tuple)): 1428120Sgblack@eecs.umich.edu return v 1438120Sgblack@eecs.umich.edu elif isinstance(v, str): 1448120Sgblack@eecs.umich.edu return map(lambda x: int(re.match('\d+', x).group()), v.split('.')) 1458120Sgblack@eecs.umich.edu else: 1468879Ssteve.reinhardt@amd.com raise TypeError 1478879Ssteve.reinhardt@amd.com 1488879Ssteve.reinhardt@amd.com v1 = make_version_list(v1) 1498879Ssteve.reinhardt@amd.com v2 = make_version_list(v2) 1508879Ssteve.reinhardt@amd.com # Compare corresponding elements of lists 1518879Ssteve.reinhardt@amd.com for n1,n2 in zip(v1, v2): 1528879Ssteve.reinhardt@amd.com if n1 < n2: return -1 1538879Ssteve.reinhardt@amd.com if n1 > n2: return 1 1548879Ssteve.reinhardt@amd.com # all corresponding values are equal... see if one has extra values 1558879Ssteve.reinhardt@amd.com if len(v1) < len(v2): return -1 1568879Ssteve.reinhardt@amd.com if len(v1) > len(v2): return 1 1578879Ssteve.reinhardt@amd.com return 0 1588879Ssteve.reinhardt@amd.com 1598120Sgblack@eecs.umich.edu######################################################################## 1608120Sgblack@eecs.umich.edu# 1618120Sgblack@eecs.umich.edu# Set up the base build environment. 1628120Sgblack@eecs.umich.edu# 1638120Sgblack@eecs.umich.edu######################################################################## 1648120Sgblack@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'PATH', 'RANLIB' ]) 1658120Sgblack@eecs.umich.edu 1668120Sgblack@eecs.umich.eduuse_env = {} 1678120Sgblack@eecs.umich.edufor key,val in os.environ.iteritems(): 1688120Sgblack@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1698120Sgblack@eecs.umich.edu use_env[key] = val 1708120Sgblack@eecs.umich.edu 1718120Sgblack@eecs.umich.eduenv = Environment(ENV=use_env) 1728120Sgblack@eecs.umich.eduenv.root = Dir(".") # The current directory (where this file lives). 1738879Ssteve.reinhardt@amd.comenv.srcdir = Dir("src") # The source directory 1748879Ssteve.reinhardt@amd.com 1758879Ssteve.reinhardt@amd.com######################################################################## 1768879Ssteve.reinhardt@amd.com# 17710458Sandreas.hansson@arm.com# Mercurial Stuff. 17810458Sandreas.hansson@arm.com# 17910458Sandreas.hansson@arm.com# If the M5 directory is a mercurial repository, we should do some 1808879Ssteve.reinhardt@amd.com# extra things. 1818879Ssteve.reinhardt@amd.com# 1828879Ssteve.reinhardt@amd.com######################################################################## 1838879Ssteve.reinhardt@amd.com 1849227Sandreas.hansson@arm.comhgdir = env.root.Dir(".hg") 1859227Sandreas.hansson@arm.com 1868879Ssteve.reinhardt@amd.commercurial_style_message = """ 1878879Ssteve.reinhardt@amd.comYou're missing the M5 style hook. 1888879Ssteve.reinhardt@amd.comPlease install the hook so we can ensure that all code fits a common style. 1898879Ssteve.reinhardt@amd.com 19010453SAndrew.Bardsley@arm.comAll you'd need to do is add the following lines to your repository .hg/hgrc 19110453SAndrew.Bardsley@arm.comor your personal .hgrc 19210453SAndrew.Bardsley@arm.com---------------- 19310456SCurtis.Dunham@arm.com 19410456SCurtis.Dunham@arm.com[extensions] 19510456SCurtis.Dunham@arm.comstyle = %s/util/style.py 19610457Sandreas.hansson@arm.com 19710457Sandreas.hansson@arm.com[hooks] 19811342Sandreas.hansson@arm.compretxncommit.style = python:style.check_whitespace 19911342Sandreas.hansson@arm.com""" % (env.root) 2008120Sgblack@eecs.umich.edu 2018947Sandreas.hansson@arm.commercurial_bin_not_found = """ 2027816Ssteve.reinhardt@amd.comMercurial binary cannot be found, unfortunately this means that we 2035871Snate@binkert.orgcannot easily determine the version of M5 that you are running and 2045871Snate@binkert.orgthis makes error messages more difficult to collect. Please consider 2056121Snate@binkert.orginstalling mercurial if you choose to post an error message 2065871Snate@binkert.org""" 2075871Snate@binkert.org 2089926Sstan.czerniawski@arm.commercurial_lib_not_found = """ 2099926Sstan.czerniawski@arm.comMercurial libraries cannot be found, ignoring style hook 2109119Sandreas.hansson@arm.comIf you are actually a M5 developer, please fix this and 21110068Sandreas.hansson@arm.comrun the style hook. It is important. 21210068Sandreas.hansson@arm.com""" 213955SN/A 2149416SAndreas.Sandberg@ARM.comif hgdir.exists(): 21511342Sandreas.hansson@arm.com # 1) Grab repository revision if we know it. 21611212Sjoseph.gross@amd.com cmd = "hg id -n -i -t -b" 21711212Sjoseph.gross@amd.com try: 21811212Sjoseph.gross@amd.com hg_info = read_command(cmd, cwd=env.root.abspath).strip() 21911212Sjoseph.gross@amd.com except OSError: 22011212Sjoseph.gross@amd.com hg_info = "Unknown" 2219416SAndreas.Sandberg@ARM.com print mercurial_bin_not_found 2229416SAndreas.Sandberg@ARM.com 2235871Snate@binkert.org env['HG_INFO'] = hg_info 22410584Sandreas.hansson@arm.com 2259416SAndreas.Sandberg@ARM.com # 2) Ensure that the style hook is in place. 2269416SAndreas.Sandberg@ARM.com try: 2275871Snate@binkert.org ui = None 228955SN/A if ARGUMENTS.get('IGNORE_STYLE') != 'True': 22910671Sandreas.hansson@arm.com from mercurial import ui 23010671Sandreas.hansson@arm.com ui = ui.ui() 23110671Sandreas.hansson@arm.com except ImportError: 23210671Sandreas.hansson@arm.com print mercurial_lib_not_found 2338881Smarc.orr@gmail.com 2346121Snate@binkert.org if ui is not None: 2356121Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2361533SN/A style_hook = ui.config('hooks', 'pretxncommit.style', None) 2379239Sandreas.hansson@arm.com 2389239Sandreas.hansson@arm.com if not style_hook: 2399239Sandreas.hansson@arm.com print mercurial_style_message 2409239Sandreas.hansson@arm.com sys.exit(1) 2419239Sandreas.hansson@arm.comelse: 2429239Sandreas.hansson@arm.com print ".hg directory not found" 2439239Sandreas.hansson@arm.com 2449239Sandreas.hansson@arm.com################################################### 2459239Sandreas.hansson@arm.com# 2469239Sandreas.hansson@arm.com# Figure out which configurations to set up based on the path(s) of 2479239Sandreas.hansson@arm.com# the target(s). 2489239Sandreas.hansson@arm.com# 2496655Snate@binkert.org################################################### 2506655Snate@binkert.org 2516655Snate@binkert.org# Find default configuration & binary. 2526655Snate@binkert.orgDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2535871Snate@binkert.org 2545871Snate@binkert.org# helper function: find last occurrence of element in list 2555863Snate@binkert.orgdef rfind(l, elt, offs = -1): 2565871Snate@binkert.org for i in range(len(l)+offs, 0, -1): 2578878Ssteve.reinhardt@amd.com if l[i] == elt: 2585871Snate@binkert.org return i 2595871Snate@binkert.org raise ValueError, "element not found" 2605871Snate@binkert.org 2615863Snate@binkert.org# Each target must have 'build' in the interior of the path; the 2626121Snate@binkert.org# directory below this will determine the build parameters. For 2635863Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2645871Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 2658336Ssteve.reinhardt@amd.com# follow 'build' in the bulid path. 2668336Ssteve.reinhardt@amd.com 2678336Ssteve.reinhardt@amd.com# Generate absolute paths to targets so we can see where the build dir is 2688336Ssteve.reinhardt@amd.comif COMMAND_LINE_TARGETS: 2694678Snate@binkert.org # Ask SCons which directory it was invoked from 27011401Sandreas.sandberg@arm.com launch_dir = GetLaunchDir() 27111401Sandreas.sandberg@arm.com # Make targets relative to invocation directory 27211401Sandreas.sandberg@arm.com abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 27311401Sandreas.sandberg@arm.com COMMAND_LINE_TARGETS] 27411401Sandreas.sandberg@arm.comelse: 27511401Sandreas.sandberg@arm.com # Default targets are relative to root of tree 2768336Ssteve.reinhardt@amd.com abs_targets = [ normpath(joinpath(ROOT, str(x))) for x in \ 2778336Ssteve.reinhardt@amd.com DEFAULT_TARGETS] 2788336Ssteve.reinhardt@amd.com 2794678Snate@binkert.org 28011401Sandreas.sandberg@arm.com# Generate a list of the unique build roots and configs that the 2814678Snate@binkert.org# collected targets reference. 2824678Snate@binkert.orgvariant_paths = [] 28311401Sandreas.sandberg@arm.combuild_root = None 28411401Sandreas.sandberg@arm.comfor t in abs_targets: 2858336Ssteve.reinhardt@amd.com path_dirs = t.split('/') 2864678Snate@binkert.org try: 2878336Ssteve.reinhardt@amd.com build_top = rfind(path_dirs, 'build', -2) 2888336Ssteve.reinhardt@amd.com except: 2898336Ssteve.reinhardt@amd.com print "Error: no non-leaf 'build' dir found on target path", t 2908336Ssteve.reinhardt@amd.com Exit(1) 2918336Ssteve.reinhardt@amd.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2928336Ssteve.reinhardt@amd.com if not build_root: 2935871Snate@binkert.org build_root = this_build_root 2945871Snate@binkert.org else: 2958336Ssteve.reinhardt@amd.com if this_build_root != build_root: 2968336Ssteve.reinhardt@amd.com print "Error: build targets not under same build root\n"\ 2978336Ssteve.reinhardt@amd.com " %s\n %s" % (build_root, this_build_root) 2988336Ssteve.reinhardt@amd.com Exit(1) 2998336Ssteve.reinhardt@amd.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 30011401Sandreas.sandberg@arm.com if variant_path not in variant_paths: 30111401Sandreas.sandberg@arm.com variant_paths.append(variant_path) 30211401Sandreas.sandberg@arm.com 3035871Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 3048336Ssteve.reinhardt@amd.comif not isdir(build_root): 3058336Ssteve.reinhardt@amd.com mkdir(build_root) 30611401Sandreas.sandberg@arm.com 30711401Sandreas.sandberg@arm.comExport('env') 30811401Sandreas.sandberg@arm.com 30911401Sandreas.sandberg@arm.comenv.SConsignFile(joinpath(build_root, "sconsign")) 31011401Sandreas.sandberg@arm.com 3114678Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 3125871Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 3134678Snate@binkert.org# file to file~ then copies to file, breaking the link. Symbolic 31411401Sandreas.sandberg@arm.com# (soft) links work better. 31511401Sandreas.sandberg@arm.comenv.SetOption('duplicate', 'soft-copy') 31611401Sandreas.sandberg@arm.com 31711401Sandreas.sandberg@arm.com# 31811401Sandreas.sandberg@arm.com# Set up global sticky variables... these are common to an entire build 31911401Sandreas.sandberg@arm.com# tree (not specific to a particular build like ALPHA_SE) 32011401Sandreas.sandberg@arm.com# 32111401Sandreas.sandberg@arm.com 32211401Sandreas.sandberg@arm.com# Variable validators & converters for global sticky variables 32311401Sandreas.sandberg@arm.comdef PathListMakeAbsolute(val): 32411401Sandreas.sandberg@arm.com if not val: 32511401Sandreas.sandberg@arm.com return val 32611401Sandreas.sandberg@arm.com f = lambda p: abspath(expanduser(p)) 32711401Sandreas.sandberg@arm.com return ':'.join(map(f, val.split(':'))) 32811401Sandreas.sandberg@arm.com 32911401Sandreas.sandberg@arm.comdef PathListAllExist(key, val, env): 33011401Sandreas.sandberg@arm.com if not val: 33111401Sandreas.sandberg@arm.com return 33211401Sandreas.sandberg@arm.com paths = val.split(':') 33311401Sandreas.sandberg@arm.com for path in paths: 33411401Sandreas.sandberg@arm.com if not isdir(path): 33511401Sandreas.sandberg@arm.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 33611401Sandreas.sandberg@arm.com 33711401Sandreas.sandberg@arm.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 33811401Sandreas.sandberg@arm.com 33911401Sandreas.sandberg@arm.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 34011401Sandreas.sandberg@arm.com 34111401Sandreas.sandberg@arm.comglobal_sticky_vars.AddVariables( 34211401Sandreas.sandberg@arm.com ('CC', 'C compiler', environ.get('CC', env['CC'])), 34311401Sandreas.sandberg@arm.com ('CXX', 'C++ compiler', environ.get('CXX', env['CXX'])), 34411401Sandreas.sandberg@arm.com ('BATCH', 'Use batch pool for build and tests', False), 34511401Sandreas.sandberg@arm.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3468336Ssteve.reinhardt@amd.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3478336Ssteve.reinhardt@amd.com PathListAllExist, PathListMakeAbsolute) 3488336Ssteve.reinhardt@amd.com ) 3498336Ssteve.reinhardt@amd.com 3508336Ssteve.reinhardt@amd.com# base help text 3518336Ssteve.reinhardt@amd.comhelp_text = ''' 3528336Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)] 3538336Ssteve.reinhardt@amd.com 3548336Ssteve.reinhardt@amd.comGlobal sticky options: 3558336Ssteve.reinhardt@amd.com''' 35611401Sandreas.sandberg@arm.com 35711401Sandreas.sandberg@arm.comhelp_text += global_sticky_vars.GenerateHelpText(env) 3588336Ssteve.reinhardt@amd.com 3598336Ssteve.reinhardt@amd.com# Update env with values from ARGUMENTS & file global_sticky_vars_file 3608336Ssteve.reinhardt@amd.comglobal_sticky_vars.Update(env) 3615871Snate@binkert.org 3626121Snate@binkert.org# Save sticky variable settings back to current variables file 363955SN/Aglobal_sticky_vars.Save(global_sticky_vars_file, env) 364955SN/A 3652632Sstever@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3662632Sstever@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 367955SN/Abase_dir = env.srcdir.abspath 368955SN/Aif env['EXTRAS']: 369955SN/A extras_dir_list = env['EXTRAS'].split(':') 370955SN/Aelse: 3718878Ssteve.reinhardt@amd.com extras_dir_list = [] 372955SN/A 3732632Sstever@eecs.umich.eduExport('base_dir') 3742632Sstever@eecs.umich.eduExport('extras_dir_list') 3752632Sstever@eecs.umich.edu 3762632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 3772632Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 3782632Sstever@eecs.umich.edu 3792632Sstever@eecs.umich.eduCXX_version = read_command([env['CXX'],'--version'], exception=False) 3808268Ssteve.reinhardt@amd.comCXX_V = read_command([env['CXX'],'-V'], exception=False) 3818268Ssteve.reinhardt@amd.com 3828268Ssteve.reinhardt@amd.comenv['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3838268Ssteve.reinhardt@amd.comenv['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3848268Ssteve.reinhardt@amd.comenv['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 3858268Ssteve.reinhardt@amd.comif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3868268Ssteve.reinhardt@amd.com print 'Error: How can we have two at the same time?' 3872632Sstever@eecs.umich.edu Exit(1) 3882632Sstever@eecs.umich.edu 3892632Sstever@eecs.umich.edu# Set up default C++ compiler flags 3902632Sstever@eecs.umich.eduif env['GCC']: 3918268Ssteve.reinhardt@amd.com env.Append(CCFLAGS='-pipe') 3922632Sstever@eecs.umich.edu env.Append(CCFLAGS='-fno-strict-aliasing') 3938268Ssteve.reinhardt@amd.com env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3948268Ssteve.reinhardt@amd.com env.Append(CXXFLAGS='-Wno-deprecated') 3958268Ssteve.reinhardt@amd.comelif env['ICC']: 3968268Ssteve.reinhardt@amd.com pass #Fix me... add warning flags once we clean up icc warnings 3973718Sstever@eecs.umich.eduelif env['SUNCC']: 3982634Sstever@eecs.umich.edu env.Append(CCFLAGS='-Qoption ccfe') 3992634Sstever@eecs.umich.edu env.Append(CCFLAGS='-features=gcc') 4005863Snate@binkert.org env.Append(CCFLAGS='-features=extensions') 4012638Sstever@eecs.umich.edu env.Append(CCFLAGS='-library=stlport4') 4028268Ssteve.reinhardt@amd.com env.Append(CCFLAGS='-xar') 4032632Sstever@eecs.umich.edu #env.Append(CCFLAGS='-instances=semiexplicit') 4042632Sstever@eecs.umich.eduelse: 4052632Sstever@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 4062632Sstever@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 4072632Sstever@eecs.umich.edu Exit(1) 4081858SN/A 4093716Sstever@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 4102638Sstever@eecs.umich.edu# extra 'qdo' every time we run scons. 4112638Sstever@eecs.umich.eduif env['BATCH']: 4122638Sstever@eecs.umich.edu env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 4132638Sstever@eecs.umich.edu env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 4142638Sstever@eecs.umich.edu env['AS'] = env['BATCH_CMD'] + ' ' + env['AS'] 4152638Sstever@eecs.umich.edu env['AR'] = env['BATCH_CMD'] + ' ' + env['AR'] 4162638Sstever@eecs.umich.edu env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB'] 4175863Snate@binkert.org 4185863Snate@binkert.orgif sys.platform == 'cygwin': 4195863Snate@binkert.org # cygwin has some header file issues... 420955SN/A env.Append(CCFLAGS=Split("-Wno-uninitialized")) 4215341Sstever@gmail.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 4225341Sstever@gmail.com 4235863Snate@binkert.org# Check for SWIG 4247756SAli.Saidi@ARM.comif not env.has_key('SWIG'): 4255341Sstever@gmail.com print 'Error: SWIG utility not found.' 4266121Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 4274494Ssaidi@eecs.umich.edu Exit(1) 4286121Snate@binkert.org 4291105SN/A# Check for appropriate SWIG version 4302667Sstever@eecs.umich.eduswig_version = read_command(('swig', '-version'), exception='').split() 4312667Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 4322667Sstever@eecs.umich.eduif len(swig_version) < 3 or \ 4332667Sstever@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 4346121Snate@binkert.org print 'Error determining SWIG version.' 4352667Sstever@eecs.umich.edu Exit(1) 4365341Sstever@gmail.com 4375863Snate@binkert.orgmin_swig_version = '1.3.28' 4385341Sstever@gmail.comif compare_versions(swig_version[2], min_swig_version) < 0: 4395341Sstever@gmail.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 4405341Sstever@gmail.com print ' Installed version:', swig_version[2] 4418120Sgblack@eecs.umich.edu Exit(1) 4425341Sstever@gmail.com 4438120Sgblack@eecs.umich.edu# Set up SWIG flags & scanner 4445341Sstever@gmail.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4458120Sgblack@eecs.umich.eduenv.Append(SWIGFLAGS=swig_flags) 4466121Snate@binkert.org 4476121Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 4488980Ssteve.reinhardt@amd.com# stuff for some reason 4499396Sandreas.hansson@arm.comscanners = [] 4505397Ssaidi@eecs.umich.edufor scanner in env['SCANNERS']: 4515397Ssaidi@eecs.umich.edu skeys = scanner.skeys 4527727SAli.Saidi@ARM.com if skeys == '.i': 4538268Ssteve.reinhardt@amd.com continue 4546168Snate@binkert.org 4555341Sstever@gmail.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4568120Sgblack@eecs.umich.edu continue 4578120Sgblack@eecs.umich.edu 4588120Sgblack@eecs.umich.edu scanners.append(scanner) 4596814Sgblack@eecs.umich.edu 4605863Snate@binkert.org# add the new swig scanner that we like better 4618120Sgblack@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 4625341Sstever@gmail.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4635863Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4648268Ssteve.reinhardt@amd.com 4656121Snate@binkert.org# replace the scanners list that has what we want 4666121Snate@binkert.orgenv['SCANNERS'] = scanners 4678268Ssteve.reinhardt@amd.com 4685742Snate@binkert.org# Add a custom Check function to the Configure context so that we can 4695742Snate@binkert.org# figure out if the compiler adds leading underscores to global 4705341Sstever@gmail.com# variables. This is needed for the autogenerated asm files that we 4715742Snate@binkert.org# use for embedding the python code. 4725742Snate@binkert.orgdef CheckLeading(context): 4735341Sstever@gmail.com context.Message("Checking for leading underscore in global variables...") 4746017Snate@binkert.org # 1) Define a global variable called x from asm so the C compiler 4756121Snate@binkert.org # won't change the symbol at all. 4766017Snate@binkert.org # 2) Declare that variable. 4777816Ssteve.reinhardt@amd.com # 3) Use the variable 4787756SAli.Saidi@ARM.com # 4797756SAli.Saidi@ARM.com # If the compiler prepends an underscore, this will successfully 4807756SAli.Saidi@ARM.com # link because the external symbol 'x' will be called '_x' which 4817756SAli.Saidi@ARM.com # was defined by the asm statement. If the compiler does not 4827756SAli.Saidi@ARM.com # prepend an underscore, this will not successfully link because 4837756SAli.Saidi@ARM.com # '_x' will have been defined by assembly, while the C portion of 4847756SAli.Saidi@ARM.com # the code will be trying to use 'x' 4857756SAli.Saidi@ARM.com ret = context.TryLink(''' 4867816Ssteve.reinhardt@amd.com asm(".globl _x; _x: .byte 0"); 4877816Ssteve.reinhardt@amd.com extern int x; 4887816Ssteve.reinhardt@amd.com int main() { return x; } 4897816Ssteve.reinhardt@amd.com ''', extension=".c") 4907816Ssteve.reinhardt@amd.com context.env.Append(LEADING_UNDERSCORE=ret) 4917816Ssteve.reinhardt@amd.com context.Result(ret) 4927816Ssteve.reinhardt@amd.com return ret 4937816Ssteve.reinhardt@amd.com 4947816Ssteve.reinhardt@amd.com# Platform-specific configuration. Note again that we assume that all 4957816Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform. 4967756SAli.Saidi@ARM.comconf = Configure(env, 4977816Ssteve.reinhardt@amd.com conf_dir = joinpath(build_root, '.scons_config'), 4987816Ssteve.reinhardt@amd.com log_file = joinpath(build_root, 'scons_config.log'), 4997816Ssteve.reinhardt@amd.com custom_tests = { 'CheckLeading' : CheckLeading }) 5007816Ssteve.reinhardt@amd.com 5017816Ssteve.reinhardt@amd.com# Check for leading underscores. Don't really need to worry either 5027816Ssteve.reinhardt@amd.com# way so don't need to check the return code. 5037816Ssteve.reinhardt@amd.comconf.CheckLeading() 5047816Ssteve.reinhardt@amd.com 5057816Ssteve.reinhardt@amd.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 5067816Ssteve.reinhardt@amd.comtry: 5077816Ssteve.reinhardt@amd.com import platform 5087816Ssteve.reinhardt@amd.com uname = platform.uname() 5097816Ssteve.reinhardt@amd.com if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 5107816Ssteve.reinhardt@amd.com if int(read_command('sysctl -n hw.cpu64bit_capable')[0]): 5117816Ssteve.reinhardt@amd.com env.Append(CCFLAGS='-arch x86_64') 5127816Ssteve.reinhardt@amd.com env.Append(CFLAGS='-arch x86_64') 5137816Ssteve.reinhardt@amd.com env.Append(LINKFLAGS='-arch x86_64') 5147816Ssteve.reinhardt@amd.com env.Append(ASFLAGS='-arch x86_64') 5157816Ssteve.reinhardt@amd.comexcept: 5167816Ssteve.reinhardt@amd.com pass 5177816Ssteve.reinhardt@amd.com 5187816Ssteve.reinhardt@amd.com# Recent versions of scons substitute a "Null" object for Configure() 5197816Ssteve.reinhardt@amd.com# when configuration isn't necessary, e.g., if the "--help" option is 5207816Ssteve.reinhardt@amd.com# present. Unfortuantely this Null object always returns false, 5217816Ssteve.reinhardt@amd.com# breaking all our configuration checks. We replace it with our own 5227816Ssteve.reinhardt@amd.com# more optimistic null object that returns True instead. 5237816Ssteve.reinhardt@amd.comif not conf: 5247816Ssteve.reinhardt@amd.com def NullCheck(*args, **kwargs): 5257816Ssteve.reinhardt@amd.com return True 5267816Ssteve.reinhardt@amd.com 5277816Ssteve.reinhardt@amd.com class NullConf: 5287816Ssteve.reinhardt@amd.com def __init__(self, env): 5297816Ssteve.reinhardt@amd.com self.env = env 5307816Ssteve.reinhardt@amd.com def Finish(self): 5317816Ssteve.reinhardt@amd.com return self.env 5327816Ssteve.reinhardt@amd.com def __getattr__(self, mname): 5337816Ssteve.reinhardt@amd.com return NullCheck 5347816Ssteve.reinhardt@amd.com 5357816Ssteve.reinhardt@amd.com conf = NullConf(env) 5367816Ssteve.reinhardt@amd.com 5377816Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the 5387816Ssteve.reinhardt@amd.com# interpreter. For consistency, we will use the same Python 5397816Ssteve.reinhardt@amd.com# installation used to run scons (and thus this script). If you want 5407816Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how 5417816Ssteve.reinhardt@amd.com# to invoke scons with a different copy of the Python interpreter. 5427816Ssteve.reinhardt@amd.comfrom distutils import sysconfig 5437816Ssteve.reinhardt@amd.com 5447816Ssteve.reinhardt@amd.compy_getvar = sysconfig.get_config_var 5457816Ssteve.reinhardt@amd.com 5467816Ssteve.reinhardt@amd.compy_version = 'python' + py_getvar('VERSION') 5477816Ssteve.reinhardt@amd.com 5487816Ssteve.reinhardt@amd.compy_general_include = sysconfig.get_python_inc() 5497816Ssteve.reinhardt@amd.compy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5507816Ssteve.reinhardt@amd.compy_includes = [ py_general_include ] 5517816Ssteve.reinhardt@amd.comif py_platform_include != py_general_include: 5527816Ssteve.reinhardt@amd.com py_includes.append(py_platform_include) 5537816Ssteve.reinhardt@amd.com 5547816Ssteve.reinhardt@amd.compy_lib_path = [] 5557816Ssteve.reinhardt@amd.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5567816Ssteve.reinhardt@amd.com# shared library in prefix/lib/. 5577816Ssteve.reinhardt@amd.comif not py_getvar('Py_ENABLE_SHARED'): 5588947Sandreas.hansson@arm.com py_lib_path.append('-L' + py_getvar('LIBPL')) 5598947Sandreas.hansson@arm.com 5607756SAli.Saidi@ARM.compy_libs = [] 5618120Sgblack@eecs.umich.edufor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 5627756SAli.Saidi@ARM.com if lib not in py_libs: 5637756SAli.Saidi@ARM.com py_libs.append(lib) 5647756SAli.Saidi@ARM.compy_libs.append('-l' + py_version) 5657756SAli.Saidi@ARM.com 5667816Ssteve.reinhardt@amd.comenv.Append(CPPPATH=py_includes) 5677816Ssteve.reinhardt@amd.comenv.Append(LIBPATH=py_lib_path) 5687816Ssteve.reinhardt@amd.com#env.Append(LIBS=py_libs) 5697816Ssteve.reinhardt@amd.com 5707816Ssteve.reinhardt@amd.com# verify that this stuff works 5717816Ssteve.reinhardt@amd.comif not conf.CheckHeader('Python.h', '<>'): 5727816Ssteve.reinhardt@amd.com print "Error: can't find Python.h header in", py_includes 5737816Ssteve.reinhardt@amd.com Exit(1) 5747816Ssteve.reinhardt@amd.com 5757816Ssteve.reinhardt@amd.comfor lib in py_libs: 5767756SAli.Saidi@ARM.com assert lib.startswith('-l') 5777756SAli.Saidi@ARM.com lib = lib[2:] 5789227Sandreas.hansson@arm.com if not conf.CheckLib(lib): 5799227Sandreas.hansson@arm.com print "Error: can't find library %s required by python" % lib 5809227Sandreas.hansson@arm.com Exit(1) 5819227Sandreas.hansson@arm.com 5829590Sandreas@sandberg.pp.se# On Solaris you need to use libsocket for socket ops 5839590Sandreas@sandberg.pp.seif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5849590Sandreas@sandberg.pp.se if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5859590Sandreas@sandberg.pp.se print "Can't find library with socket calls (e.g. accept())" 5869590Sandreas@sandberg.pp.se Exit(1) 5879590Sandreas@sandberg.pp.se 5886654Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 5896654Snate@binkert.org# added to the LIBS environment variable. 5905871Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5916121Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 5928946Sandreas.hansson@arm.com 'and/or zlib.h header file.' 5939419Sandreas.hansson@arm.com print ' Please install zlib and try again.' 5943940Ssaidi@eecs.umich.edu Exit(1) 5953918Ssaidi@eecs.umich.edu 5963918Ssaidi@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 5971858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 5989556Sandreas.hansson@arm.comif not have_fenv: 5999556Sandreas.hansson@arm.com print "Warning: Header file <fenv.h> not found." 6009556Sandreas.hansson@arm.com print " This host has no IEEE FP rounding mode control." 6019556Sandreas.hansson@arm.com 60211294Sandreas.hansson@arm.com###################################################################### 60311294Sandreas.hansson@arm.com# 60411294Sandreas.hansson@arm.com# Check for mysql. 60511294Sandreas.hansson@arm.com# 60610878Sandreas.hansson@arm.commysql_config = WhereIs('mysql_config') 60710878Sandreas.hansson@arm.comhave_mysql = bool(mysql_config) 6089556Sandreas.hansson@arm.com 6099556Sandreas.hansson@arm.com# Check MySQL version. 6109556Sandreas.hansson@arm.comif have_mysql: 6119556Sandreas.hansson@arm.com mysql_version = read_command(mysql_config + ' --version') 6129556Sandreas.hansson@arm.com min_mysql_version = '4.1' 6139556Sandreas.hansson@arm.com if compare_versions(mysql_version, min_mysql_version) < 0: 6149556Sandreas.hansson@arm.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 6159556Sandreas.hansson@arm.com print ' Version', mysql_version, 'detected.' 6169556Sandreas.hansson@arm.com have_mysql = False 6179556Sandreas.hansson@arm.com 6189556Sandreas.hansson@arm.com# Set up mysql_config commands. 6199556Sandreas.hansson@arm.comif have_mysql: 6209556Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --include' 6219556Sandreas.hansson@arm.com if os.system(mysql_config_include + ' > /dev/null') != 0: 6229556Sandreas.hansson@arm.com # older mysql_config versions don't support --include, use 6239556Sandreas.hansson@arm.com # --cflags instead 6249556Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 6259556Sandreas.hansson@arm.com # This seems to work in all versions 6269556Sandreas.hansson@arm.com mysql_config_libs = mysql_config + ' --libs' 6276121Snate@binkert.org 62810878Sandreas.hansson@arm.com###################################################################### 62910238Sandreas.hansson@arm.com# 63010878Sandreas.hansson@arm.com# Finish the configuration 6319420Sandreas.hansson@arm.com# 63210878Sandreas.hansson@arm.comenv = conf.Finish() 63310878Sandreas.hansson@arm.com 6349420Sandreas.hansson@arm.com###################################################################### 6359420Sandreas.hansson@arm.com# 6369420Sandreas.hansson@arm.com# Collect all non-global variables 6379420Sandreas.hansson@arm.com# 6389420Sandreas.hansson@arm.com 63910264Sandreas.hansson@arm.comExport('env') 64010264Sandreas.hansson@arm.com 64110264Sandreas.hansson@arm.com# Define the universe of supported ISAs 64210264Sandreas.hansson@arm.comall_isa_list = [ ] 64310264Sandreas.hansson@arm.comExport('all_isa_list') 64410866Sandreas.hansson@arm.com 64510866Sandreas.hansson@arm.com# Define the universe of supported CPU models 64610264Sandreas.hansson@arm.comall_cpu_list = [ ] 64710866Sandreas.hansson@arm.comdefault_cpus = [ ] 64810866Sandreas.hansson@arm.comExport('all_cpu_list', 'default_cpus') 64910866Sandreas.hansson@arm.com 65010866Sandreas.hansson@arm.com# Sticky variables get saved in the variables file so they persist from 65110866Sandreas.hansson@arm.com# one invocation to the next (unless overridden, in which case the new 65210866Sandreas.hansson@arm.com# value becomes sticky). 65310866Sandreas.hansson@arm.comsticky_vars = Variables(args=ARGUMENTS) 65410264Sandreas.hansson@arm.comExport('sticky_vars') 65510264Sandreas.hansson@arm.com 65610264Sandreas.hansson@arm.com# Non-sticky variables only apply to the current build. 65710264Sandreas.hansson@arm.comnonsticky_vars = Variables(args=ARGUMENTS) 65810264Sandreas.hansson@arm.comExport('nonsticky_vars') 65910264Sandreas.hansson@arm.com 66010264Sandreas.hansson@arm.com# Walk the tree and execute all SConsopts scripts that wil add to the 66110457Sandreas.hansson@arm.com# above variables 66210457Sandreas.hansson@arm.comfor bdir in [ base_dir ] + extras_dir_list: 66310457Sandreas.hansson@arm.com for root, dirs, files in os.walk(bdir): 66410457Sandreas.hansson@arm.com if 'SConsopts' in files: 66510457Sandreas.hansson@arm.com print "Reading", joinpath(root, 'SConsopts') 66610457Sandreas.hansson@arm.com SConscript(joinpath(root, 'SConsopts')) 66710457Sandreas.hansson@arm.com 66810457Sandreas.hansson@arm.comall_isa_list.sort() 66910457Sandreas.hansson@arm.comall_cpu_list.sort() 67010238Sandreas.hansson@arm.comdefault_cpus.sort() 67110238Sandreas.hansson@arm.com 67210238Sandreas.hansson@arm.comsticky_vars.AddVariables( 67310238Sandreas.hansson@arm.com EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 67410238Sandreas.hansson@arm.com BoolVariable('FULL_SYSTEM', 'Full-system support', False), 67510238Sandreas.hansson@arm.com ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 67610416Sandreas.hansson@arm.com BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 67710238Sandreas.hansson@arm.com BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6789227Sandreas.hansson@arm.com False), 67910238Sandreas.hansson@arm.com BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 68010416Sandreas.hansson@arm.com False), 68110416Sandreas.hansson@arm.com BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 6829227Sandreas.hansson@arm.com False), 6839590Sandreas@sandberg.pp.se BoolVariable('SS_COMPATIBLE_FP', 6849590Sandreas@sandberg.pp.se 'Make floating-point results compatible with SimpleScalar', 6859590Sandreas@sandberg.pp.se False), 6868737Skoansin.tan@gmail.com BoolVariable('USE_SSE2', 68710878Sandreas.hansson@arm.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 68810878Sandreas.hansson@arm.com False), 6899420Sandreas.hansson@arm.com BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6908737Skoansin.tan@gmail.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 69110106SMitch.Hayenga@arm.com BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 6928737Skoansin.tan@gmail.com ) 6938737Skoansin.tan@gmail.com 69410878Sandreas.hansson@arm.comnonsticky_vars.AddVariables( 69510878Sandreas.hansson@arm.com BoolVariable('update_ref', 'Update test reference outputs', False) 6968737Skoansin.tan@gmail.com ) 6978737Skoansin.tan@gmail.com 6988737Skoansin.tan@gmail.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 6998737Skoansin.tan@gmail.comenv.ExportVariables = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 7008737Skoansin.tan@gmail.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 7018737Skoansin.tan@gmail.com 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 70211294Sandreas.hansson@arm.com 'USE_CHECKER', 'TARGET_ISA'] 7039556Sandreas.hansson@arm.com 7049556Sandreas.hansson@arm.com################################################### 7059556Sandreas.hansson@arm.com# 70611294Sandreas.hansson@arm.com# Define a SCons builder for configuration flag headers. 70710278SAndreas.Sandberg@ARM.com# 70810278SAndreas.Sandberg@ARM.com################################################### 70910278SAndreas.Sandberg@ARM.com 71010278SAndreas.Sandberg@ARM.com# This function generates a config header file that #defines the 71110278SAndreas.Sandberg@ARM.com# variable symbol to the current variable setting (0 or 1). The source 71210278SAndreas.Sandberg@ARM.com# operands are the name of the variable and a Value node containing the 7139556Sandreas.hansson@arm.com# value of the variable. 7149590Sandreas@sandberg.pp.sedef build_config_file(target, source, env): 7159590Sandreas@sandberg.pp.se (variable, value) = [s.get_contents() for s in source] 7169420Sandreas.hansson@arm.com f = file(str(target[0]), 'w') 7179846Sandreas.hansson@arm.com print >> f, '#define', variable, value 7189846Sandreas.hansson@arm.com f.close() 7199846Sandreas.hansson@arm.com return None 7209846Sandreas.hansson@arm.com 7218946Sandreas.hansson@arm.com# Generate the message to be printed when building the config file. 7223918Ssaidi@eecs.umich.edudef build_config_file_string(target, source, env): 7239068SAli.Saidi@ARM.com (variable, value) = [s.get_contents() for s in source] 7249068SAli.Saidi@ARM.com return "Defining %s as %s in %s." % (variable, value, target[0]) 7259068SAli.Saidi@ARM.com 7269068SAli.Saidi@ARM.com# Combine the two functions into a scons Action object. 7279068SAli.Saidi@ARM.comconfig_action = Action(build_config_file, build_config_file_string) 7289068SAli.Saidi@ARM.com 7299068SAli.Saidi@ARM.com# The emitter munges the source & target node lists to reflect what 7309068SAli.Saidi@ARM.com# we're really doing. 7319068SAli.Saidi@ARM.comdef config_emitter(target, source, env): 7329419Sandreas.hansson@arm.com # extract variable name from Builder arg 7339068SAli.Saidi@ARM.com variable = str(target[0]) 7349068SAli.Saidi@ARM.com # True target is config header file 7359068SAli.Saidi@ARM.com target = joinpath('config', variable.lower() + '.hh') 7369068SAli.Saidi@ARM.com val = env[variable] 7379068SAli.Saidi@ARM.com if isinstance(val, bool): 7389068SAli.Saidi@ARM.com # Force value to 0/1 7393918Ssaidi@eecs.umich.edu val = int(val) 7403918Ssaidi@eecs.umich.edu elif isinstance(val, str): 7416157Snate@binkert.org val = '"' + val + '"' 7426157Snate@binkert.org 7436157Snate@binkert.org # Sources are variable name & value (packaged in SCons Value nodes) 7446157Snate@binkert.org return ([target], [Value(variable), Value(val)]) 7455397Ssaidi@eecs.umich.edu 7465397Ssaidi@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 7476121Snate@binkert.org 7486121Snate@binkert.orgenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 7496121Snate@binkert.org 7506121Snate@binkert.org# libelf build is shared across all configs in the build root. 7516121Snate@binkert.orgenv.SConscript('ext/libelf/SConscript', 7526121Snate@binkert.org variant_dir = joinpath(build_root, 'libelf')) 7535397Ssaidi@eecs.umich.edu 7541851SN/A# gzstream build is shared across all configs in the build root. 7551851SN/Aenv.SConscript('ext/gzstream/SConscript', 7567739Sgblack@eecs.umich.edu variant_dir = joinpath(build_root, 'gzstream')) 757955SN/A 7589396Sandreas.hansson@arm.com################################################### 7599396Sandreas.hansson@arm.com# 7609396Sandreas.hansson@arm.com# This function is used to set up a directory with switching headers 7619396Sandreas.hansson@arm.com# 7629396Sandreas.hansson@arm.com################################################### 7639396Sandreas.hansson@arm.com 7649396Sandreas.hansson@arm.comenv['ALL_ISA_LIST'] = all_isa_list 7659396Sandreas.hansson@arm.comdef make_switching_dir(dname, switch_headers, env): 7669396Sandreas.hansson@arm.com # Generate the header. target[0] is the full path of the output 7679396Sandreas.hansson@arm.com # header to generate. 'source' is a dummy variable, since we get the 7689396Sandreas.hansson@arm.com # list of ISAs from env['ALL_ISA_LIST']. 7699396Sandreas.hansson@arm.com def gen_switch_hdr(target, source, env): 7709396Sandreas.hansson@arm.com fname = str(target[0]) 7719396Sandreas.hansson@arm.com bname = basename(fname) 7729396Sandreas.hansson@arm.com f = open(fname, 'w') 7739396Sandreas.hansson@arm.com f.write('#include "arch/isa_specific.hh"\n') 7749477Sandreas.hansson@arm.com cond = '#if' 7759477Sandreas.hansson@arm.com for isa in all_isa_list: 7769477Sandreas.hansson@arm.com f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 7779477Sandreas.hansson@arm.com % (cond, isa.upper(), dname, isa, bname)) 7789477Sandreas.hansson@arm.com cond = '#elif' 7799477Sandreas.hansson@arm.com f.write('#else\n#error "THE_ISA not set"\n#endif\n') 7809477Sandreas.hansson@arm.com f.close() 7819477Sandreas.hansson@arm.com return 0 7829477Sandreas.hansson@arm.com 7839477Sandreas.hansson@arm.com # String to print when generating header 7849477Sandreas.hansson@arm.com def gen_switch_hdr_string(target, source, env): 7859477Sandreas.hansson@arm.com return "Generating switch header " + str(target[0]) 7869477Sandreas.hansson@arm.com 7879477Sandreas.hansson@arm.com # Build SCons Action object. 'varlist' specifies env vars that this 7889477Sandreas.hansson@arm.com # action depends on; when env['ALL_ISA_LIST'] changes these actions 7899477Sandreas.hansson@arm.com # should get re-executed. 7909477Sandreas.hansson@arm.com switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 7919477Sandreas.hansson@arm.com varlist=['ALL_ISA_LIST']) 7929477Sandreas.hansson@arm.com 7939477Sandreas.hansson@arm.com # Instantiate actions for each header 7949477Sandreas.hansson@arm.com for hdr in switch_headers: 7959477Sandreas.hansson@arm.com env.Command(hdr, [], switch_hdr_action) 7969396Sandreas.hansson@arm.comExport('make_switching_dir') 7973053Sstever@eecs.umich.edu 7986121Snate@binkert.org################################################### 7993053Sstever@eecs.umich.edu# 8003053Sstever@eecs.umich.edu# Define build environments for selected configurations. 8013053Sstever@eecs.umich.edu# 8023053Sstever@eecs.umich.edu################################################### 8033053Sstever@eecs.umich.edu 8049072Sandreas.hansson@arm.com# rename base env 8053053Sstever@eecs.umich.edubase_env = env 8064742Sstever@eecs.umich.edu 8074742Sstever@eecs.umich.edufor variant_path in variant_paths: 8083053Sstever@eecs.umich.edu print "Building in", variant_path 8093053Sstever@eecs.umich.edu 8103053Sstever@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 81110181SCurtis.Dunham@arm.com env = base_env.Clone() 8126654Snate@binkert.org env['BUILDDIR'] = variant_path 8133053Sstever@eecs.umich.edu 8143053Sstever@eecs.umich.edu # variant_dir is the tail component of build path, and is used to 8153053Sstever@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 8163053Sstever@eecs.umich.edu (build_root, variant_dir) = splitpath(variant_path) 81710425Sandreas.hansson@arm.com 81810425Sandreas.hansson@arm.com # Set env variables according to the build directory config. 81910425Sandreas.hansson@arm.com sticky_vars.files = [] 82010425Sandreas.hansson@arm.com # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 82110425Sandreas.hansson@arm.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 82210425Sandreas.hansson@arm.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 82310425Sandreas.hansson@arm.com current_vars_file = joinpath(build_root, 'variables', variant_dir) 82410425Sandreas.hansson@arm.com if isfile(current_vars_file): 82510425Sandreas.hansson@arm.com sticky_vars.files.append(current_vars_file) 82610425Sandreas.hansson@arm.com print "Using saved variables file %s" % current_vars_file 82710425Sandreas.hansson@arm.com else: 8282667Sstever@eecs.umich.edu # Build dir-specific variables file doesn't exist. 8294554Sbinkertn@umich.edu 8306121Snate@binkert.org # Make sure the directory is there so we can create it later 8312667Sstever@eecs.umich.edu opt_dir = dirname(current_vars_file) 83210710Sandreas.hansson@arm.com if not isdir(opt_dir): 83310710Sandreas.hansson@arm.com mkdir(opt_dir) 83410710Sandreas.hansson@arm.com 83510710Sandreas.hansson@arm.com # Get default build variables from source tree. Variables are 83610710Sandreas.hansson@arm.com # normally determined by name of $VARIANT_DIR, but can be 83710710Sandreas.hansson@arm.com # overriden by 'default=' arg on command line. 83810710Sandreas.hansson@arm.com default_vars_file = joinpath('build_opts', 83910710Sandreas.hansson@arm.com ARGUMENTS.get('default', variant_dir)) 84010710Sandreas.hansson@arm.com if isfile(default_vars_file): 84110384SCurtis.Dunham@arm.com sticky_vars.files.append(default_vars_file) 8424554Sbinkertn@umich.edu print "Variables file %s not found,\n using defaults in %s" \ 8434554Sbinkertn@umich.edu % (current_vars_file, default_vars_file) 8444554Sbinkertn@umich.edu else: 8456121Snate@binkert.org print "Error: cannot find variables file %s or %s" \ 8464554Sbinkertn@umich.edu % (current_vars_file, default_vars_file) 8474554Sbinkertn@umich.edu Exit(1) 8484554Sbinkertn@umich.edu 8494781Snate@binkert.org # Apply current variable settings to env 8504554Sbinkertn@umich.edu sticky_vars.Update(env) 8514554Sbinkertn@umich.edu nonsticky_vars.Update(env) 8522667Sstever@eecs.umich.edu 8534554Sbinkertn@umich.edu help_text += "\nSticky variables for %s:\n" % variant_dir \ 8544554Sbinkertn@umich.edu + sticky_vars.GenerateHelpText(env) \ 8554554Sbinkertn@umich.edu + "\nNon-sticky variables for %s:\n" % variant_dir \ 8564554Sbinkertn@umich.edu + nonsticky_vars.GenerateHelpText(env) 8572667Sstever@eecs.umich.edu 8584554Sbinkertn@umich.edu # Process variable settings. 8592667Sstever@eecs.umich.edu 8604554Sbinkertn@umich.edu if not have_fenv and env['USE_FENV']: 8616121Snate@binkert.org print "Warning: <fenv.h> not available; " \ 8622667Sstever@eecs.umich.edu "forcing USE_FENV to False in", variant_dir + "." 8639986Sandreas@sandberg.pp.se env['USE_FENV'] = False 8649986Sandreas@sandberg.pp.se 8659986Sandreas@sandberg.pp.se if not env['USE_FENV']: 8669986Sandreas@sandberg.pp.se print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 8679986Sandreas@sandberg.pp.se print " FP results may deviate slightly from other platforms." 8689986Sandreas@sandberg.pp.se 8699986Sandreas@sandberg.pp.se if env['EFENCE']: 8709986Sandreas@sandberg.pp.se env.Append(LIBS=['efence']) 8719986Sandreas@sandberg.pp.se 8729986Sandreas@sandberg.pp.se if env['USE_MYSQL']: 8739986Sandreas@sandberg.pp.se if not have_mysql: 8749986Sandreas@sandberg.pp.se print "Warning: MySQL not available; " \ 8759986Sandreas@sandberg.pp.se "forcing USE_MYSQL to False in", variant_dir + "." 8769986Sandreas@sandberg.pp.se env['USE_MYSQL'] = False 8779986Sandreas@sandberg.pp.se else: 8789986Sandreas@sandberg.pp.se print "Compiling in", variant_dir, "with MySQL support." 8799986Sandreas@sandberg.pp.se env.ParseConfig(mysql_config_libs) 8809986Sandreas@sandberg.pp.se env.ParseConfig(mysql_config_include) 8819986Sandreas@sandberg.pp.se 8829986Sandreas@sandberg.pp.se # Save sticky variable settings back to current variables file 8832638Sstever@eecs.umich.edu sticky_vars.Save(current_vars_file, env) 8842638Sstever@eecs.umich.edu 8856121Snate@binkert.org if env['USE_SSE2']: 8863716Sstever@eecs.umich.edu env.Append(CCFLAGS='-msse2') 8875522Snate@binkert.org 8889986Sandreas@sandberg.pp.se # The src/SConscript file sets up the build rules in 'env' according 8899986Sandreas@sandberg.pp.se # to the configured variables. It returns a list of environments, 8909986Sandreas@sandberg.pp.se # one for each variant build (debug, opt, etc.) 8915522Snate@binkert.org envList = SConscript('src/SConscript', variant_dir = variant_path, 8925227Ssaidi@eecs.umich.edu exports = 'env') 8935227Ssaidi@eecs.umich.edu 8945227Ssaidi@eecs.umich.edu # Set up the regression tests for each build. 8955227Ssaidi@eecs.umich.edu for e in envList: 8966654Snate@binkert.org SConscript('tests/SConscript', 8976654Snate@binkert.org variant_dir = joinpath(variant_path, 'tests', e.Label), 8987769SAli.Saidi@ARM.com exports = { 'env' : e }, duplicate = False) 8997769SAli.Saidi@ARM.com 9007769SAli.Saidi@ARM.comHelp(help_text) 9017769SAli.Saidi@ARM.com