SConstruct revision 7457:95160760db54
1955SN/A# -*- mode:python -*- 2955SN/A 312230Sgiacomo.travaglini@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""" 8112563Sgabeblack@google.com raise 8212563Sgabeblack@google.com 836654Snate@binkert.org# We ensure the python version early because we have stuff that 8410196SCurtis.Dunham@arm.com# requires python 2.4 85955SN/Atry: 865396Ssaidi@eecs.umich.edu EnsurePythonVersion(2, 4) 8711401Sandreas.sandberg@arm.comexcept SystemExit, e: 885863Snate@binkert.org print """ 895863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 904202Sbinkertn@umich.edueither (1) rearranging your PATH so that scons finds the non-default 915863Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter 925863Snate@binkert.orgon the scons script. 935863Snate@binkert.org 945863Snate@binkert.orgFor more details, see: 95955SN/A http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 966654Snate@binkert.org""" 975273Sstever@gmail.com raise 985871Snate@binkert.org 995273Sstever@gmail.com# Global Python includes 1006654Snate@binkert.orgimport os 1015396Ssaidi@eecs.umich.eduimport re 1028120Sgblack@eecs.umich.eduimport subprocess 1038120Sgblack@eecs.umich.eduimport sys 1048120Sgblack@eecs.umich.edu 1058120Sgblack@eecs.umich.edufrom os import mkdir, environ 1068120Sgblack@eecs.umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath 1078120Sgblack@eecs.umich.edufrom os.path import exists, isdir, isfile 1088120Sgblack@eecs.umich.edufrom os.path import join as joinpath, split as splitpath 1098120Sgblack@eecs.umich.edu 1108879Ssteve.reinhardt@amd.com# SCons includes 1118879Ssteve.reinhardt@amd.comimport SCons 1128879Ssteve.reinhardt@amd.comimport SCons.Node 1138879Ssteve.reinhardt@amd.com 1148879Ssteve.reinhardt@amd.comextra_python_paths = [ 1158879Ssteve.reinhardt@amd.com Dir('src/python').srcnode().abspath, # M5 includes 1168879Ssteve.reinhardt@amd.com Dir('ext/ply').srcnode().abspath, # ply is used by several files 1178879Ssteve.reinhardt@amd.com ] 1188879Ssteve.reinhardt@amd.com 1198879Ssteve.reinhardt@amd.comsys.path[1:1] = extra_python_paths 1208879Ssteve.reinhardt@amd.com 1218879Ssteve.reinhardt@amd.comfrom m5.util import compareVersions, readCommand 1228879Ssteve.reinhardt@amd.com 1238120Sgblack@eecs.umich.edu######################################################################## 1248120Sgblack@eecs.umich.edu# 1258120Sgblack@eecs.umich.edu# Set up the main build environment. 1268120Sgblack@eecs.umich.edu# 1278120Sgblack@eecs.umich.edu######################################################################## 1288120Sgblack@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1298120Sgblack@eecs.umich.edu 'PYTHONPATH', 'RANLIB' ]) 1308120Sgblack@eecs.umich.edu 1318120Sgblack@eecs.umich.eduuse_env = {} 1328120Sgblack@eecs.umich.edufor key,val in os.environ.iteritems(): 1338120Sgblack@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1348120Sgblack@eecs.umich.edu use_env[key] = val 1358120Sgblack@eecs.umich.edu 1368120Sgblack@eecs.umich.edumain = Environment(ENV=use_env) 1378879Ssteve.reinhardt@amd.commain.root = Dir(".") # The current directory (where this file lives). 1388879Ssteve.reinhardt@amd.commain.srcdir = Dir("src") # The source directory 1398879Ssteve.reinhardt@amd.com 1408879Ssteve.reinhardt@amd.com# add useful python code PYTHONPATH so it can be used by subprocesses 14110458Sandreas.hansson@arm.com# as well 14210458Sandreas.hansson@arm.commain.AppendENVPath('PYTHONPATH', extra_python_paths) 14310458Sandreas.hansson@arm.com 1448879Ssteve.reinhardt@amd.com######################################################################## 1458879Ssteve.reinhardt@amd.com# 1468879Ssteve.reinhardt@amd.com# Mercurial Stuff. 1478879Ssteve.reinhardt@amd.com# 14813421Sciro.santilli@arm.com# If the M5 directory is a mercurial repository, we should do some 14913421Sciro.santilli@arm.com# extra things. 1509227Sandreas.hansson@arm.com# 1519227Sandreas.hansson@arm.com######################################################################## 15212063Sgabeblack@google.com 15312063Sgabeblack@google.comhgdir = main.root.Dir(".hg") 15412063Sgabeblack@google.com 1558879Ssteve.reinhardt@amd.commercurial_style_message = """ 1568879Ssteve.reinhardt@amd.comYou're missing the M5 style hook. 1578879Ssteve.reinhardt@amd.comPlease install the hook so we can ensure that all code fits a common style. 1588879Ssteve.reinhardt@amd.com 15910453SAndrew.Bardsley@arm.comAll you'd need to do is add the following lines to your repository .hg/hgrc 16010453SAndrew.Bardsley@arm.comor your personal .hgrc 16110453SAndrew.Bardsley@arm.com---------------- 16210456SCurtis.Dunham@arm.com 16310456SCurtis.Dunham@arm.com[extensions] 16410456SCurtis.Dunham@arm.comstyle = %s/util/style.py 16510457Sandreas.hansson@arm.com 16610457Sandreas.hansson@arm.com[hooks] 16711342Sandreas.hansson@arm.compretxncommit.style = python:style.check_whitespace 16811342Sandreas.hansson@arm.com""" % (main.root) 1698120Sgblack@eecs.umich.edu 17012063Sgabeblack@google.commercurial_bin_not_found = """ 17112563Sgabeblack@google.comMercurial binary cannot be found, unfortunately this means that we 17212063Sgabeblack@google.comcannot easily determine the version of M5 that you are running and 17312063Sgabeblack@google.comthis makes error messages more difficult to collect. Please consider 1745871Snate@binkert.orginstalling mercurial if you choose to post an error message 1755871Snate@binkert.org""" 1766121Snate@binkert.org 1775871Snate@binkert.orgmercurial_lib_not_found = """ 1785871Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook 1799926Sstan.czerniawski@arm.comIf you are actually a M5 developer, please fix this and 18012243Sgabeblack@google.comrun the style hook. It is important. 1811533SN/A""" 18212246Sgabeblack@google.com 18312246Sgabeblack@google.comhg_info = "Unknown" 18412246Sgabeblack@google.comif hgdir.exists(): 18512246Sgabeblack@google.com # 1) Grab repository revision if we know it. 1869239Sandreas.hansson@arm.com cmd = "hg id -n -i -t -b" 1879239Sandreas.hansson@arm.com try: 1889239Sandreas.hansson@arm.com hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 1899239Sandreas.hansson@arm.com except OSError: 19012563Sgabeblack@google.com print mercurial_bin_not_found 1919239Sandreas.hansson@arm.com 1929239Sandreas.hansson@arm.com # 2) Ensure that the style hook is in place. 193955SN/A try: 194955SN/A ui = None 1952632Sstever@eecs.umich.edu if ARGUMENTS.get('IGNORE_STYLE') != 'True': 1962632Sstever@eecs.umich.edu from mercurial import ui 197955SN/A ui = ui.ui() 198955SN/A except ImportError: 199955SN/A print mercurial_lib_not_found 200955SN/A 2018878Ssteve.reinhardt@amd.com if ui is not None: 202955SN/A ui.readconfig(hgdir.File('hgrc').abspath) 2032632Sstever@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) 2042632Sstever@eecs.umich.edu 2052632Sstever@eecs.umich.edu if not style_hook: 2062632Sstever@eecs.umich.edu print mercurial_style_message 2072632Sstever@eecs.umich.edu sys.exit(1) 2082632Sstever@eecs.umich.eduelse: 2092632Sstever@eecs.umich.edu print ".hg directory not found" 2108268Ssteve.reinhardt@amd.com 2118268Ssteve.reinhardt@amd.commain['HG_INFO'] = hg_info 2128268Ssteve.reinhardt@amd.com 2138268Ssteve.reinhardt@amd.com################################################### 2148268Ssteve.reinhardt@amd.com# 2158268Ssteve.reinhardt@amd.com# Figure out which configurations to set up based on the path(s) of 2168268Ssteve.reinhardt@amd.com# the target(s). 2172632Sstever@eecs.umich.edu# 2182632Sstever@eecs.umich.edu################################################### 2192632Sstever@eecs.umich.edu 2202632Sstever@eecs.umich.edu# Find default configuration & binary. 2218268Ssteve.reinhardt@amd.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2222632Sstever@eecs.umich.edu 2238268Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list 2248268Ssteve.reinhardt@amd.comdef rfind(l, elt, offs = -1): 2258268Ssteve.reinhardt@amd.com for i in range(len(l)+offs, 0, -1): 2268268Ssteve.reinhardt@amd.com if l[i] == elt: 2273718Sstever@eecs.umich.edu return i 2282634Sstever@eecs.umich.edu raise ValueError, "element not found" 2292634Sstever@eecs.umich.edu 2305863Snate@binkert.org# Each target must have 'build' in the interior of the path; the 2312638Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2328268Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2332632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 2342632Sstever@eecs.umich.edu# follow 'build' in the bulid path. 2352632Sstever@eecs.umich.edu 2362632Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is 23712563Sgabeblack@google.comif COMMAND_LINE_TARGETS: 2381858SN/A # Ask SCons which directory it was invoked from 2393716Sstever@eecs.umich.edu launch_dir = GetLaunchDir() 2402638Sstever@eecs.umich.edu # Make targets relative to invocation directory 2412638Sstever@eecs.umich.edu abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2422638Sstever@eecs.umich.edu COMMAND_LINE_TARGETS] 2432638Sstever@eecs.umich.eduelse: 24412563Sgabeblack@google.com # Default targets are relative to root of tree 24512563Sgabeblack@google.com abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2462638Sstever@eecs.umich.edu DEFAULT_TARGETS] 2475863Snate@binkert.org 2485863Snate@binkert.org 2495863Snate@binkert.org# Generate a list of the unique build roots and configs that the 250955SN/A# collected targets reference. 2515341Sstever@gmail.comvariant_paths = [] 2525341Sstever@gmail.combuild_root = None 2535863Snate@binkert.orgfor t in abs_targets: 2547756SAli.Saidi@ARM.com path_dirs = t.split('/') 2555341Sstever@gmail.com try: 2566121Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 2574494Ssaidi@eecs.umich.edu except: 2586121Snate@binkert.org print "Error: no non-leaf 'build' dir found on target path", t 2591105SN/A Exit(1) 2602667Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2612667Sstever@eecs.umich.edu if not build_root: 2622667Sstever@eecs.umich.edu build_root = this_build_root 2632667Sstever@eecs.umich.edu else: 2646121Snate@binkert.org if this_build_root != build_root: 2652667Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 2665341Sstever@gmail.com " %s\n %s" % (build_root, this_build_root) 2675863Snate@binkert.org Exit(1) 2685341Sstever@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 2695341Sstever@gmail.com if variant_path not in variant_paths: 2705341Sstever@gmail.com variant_paths.append(variant_path) 2718120Sgblack@eecs.umich.edu 2725341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there) 2738120Sgblack@eecs.umich.eduif not isdir(build_root): 2745341Sstever@gmail.com mkdir(build_root) 2758120Sgblack@eecs.umich.edu 2766121Snate@binkert.orgExport('main') 2776121Snate@binkert.org 2789396Sandreas.hansson@arm.commain.SConsignFile(joinpath(build_root, "sconsign")) 2795397Ssaidi@eecs.umich.edu 2805397Ssaidi@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 2817727SAli.Saidi@ARM.com# when you use emacs to edit a file in the target dir, as emacs moves 2828268Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link. Symbolic 2836168Snate@binkert.org# (soft) links work better. 2845341Sstever@gmail.commain.SetOption('duplicate', 'soft-copy') 2858120Sgblack@eecs.umich.edu 2868120Sgblack@eecs.umich.edu# 2878120Sgblack@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 2886814Sgblack@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 2895863Snate@binkert.org# 2908120Sgblack@eecs.umich.edu 2915341Sstever@gmail.com# Variable validators & converters for global sticky variables 2925863Snate@binkert.orgdef PathListMakeAbsolute(val): 2938268Ssteve.reinhardt@amd.com if not val: 2946121Snate@binkert.org return val 2956121Snate@binkert.org f = lambda p: abspath(expanduser(p)) 2968268Ssteve.reinhardt@amd.com return ':'.join(map(f, val.split(':'))) 2975742Snate@binkert.org 2985742Snate@binkert.orgdef PathListAllExist(key, val, env): 2995341Sstever@gmail.com if not val: 3005742Snate@binkert.org return 3015742Snate@binkert.org paths = val.split(':') 3025341Sstever@gmail.com for path in paths: 3036017Snate@binkert.org if not isdir(path): 3046121Snate@binkert.org raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3056017Snate@binkert.org 30612158Sandreas.sandberg@arm.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 30712158Sandreas.sandberg@arm.com 30812158Sandreas.sandberg@arm.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3098120Sgblack@eecs.umich.edu 3107756SAli.Saidi@ARM.comglobal_sticky_vars.AddVariables( 3117756SAli.Saidi@ARM.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 3127756SAli.Saidi@ARM.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3137756SAli.Saidi@ARM.com ('BATCH', 'Use batch pool for build and tests', False), 3147816Ssteve.reinhardt@amd.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3157816Ssteve.reinhardt@amd.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3167816Ssteve.reinhardt@amd.com PathListAllExist, PathListMakeAbsolute), 3177816Ssteve.reinhardt@amd.com ) 3187816Ssteve.reinhardt@amd.com 31911979Sgabeblack@google.com# base help text 3207816Ssteve.reinhardt@amd.comhelp_text = ''' 3217816Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)] 3227816Ssteve.reinhardt@amd.com 3237816Ssteve.reinhardt@amd.comGlobal sticky options: 3247756SAli.Saidi@ARM.com''' 3257756SAli.Saidi@ARM.com 3269227Sandreas.hansson@arm.com# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3279227Sandreas.hansson@arm.comglobal_sticky_vars.Update(main) 3289227Sandreas.hansson@arm.com 3299227Sandreas.hansson@arm.comhelp_text += global_sticky_vars.GenerateHelpText(main) 3309590Sandreas@sandberg.pp.se 3319590Sandreas@sandberg.pp.se# Save sticky variable settings back to current variables file 3329590Sandreas@sandberg.pp.seglobal_sticky_vars.Save(global_sticky_vars_file, main) 3339590Sandreas@sandberg.pp.se 3349590Sandreas@sandberg.pp.se# Parse EXTRAS variable to build list of all directories where we're 3359590Sandreas@sandberg.pp.se# look for sources etc. This list is exported as base_dir_list. 3366654Snate@binkert.orgbase_dir = main.srcdir.abspath 3376654Snate@binkert.orgif main['EXTRAS']: 3385871Snate@binkert.org extras_dir_list = main['EXTRAS'].split(':') 3396121Snate@binkert.orgelse: 3408946Sandreas.hansson@arm.com extras_dir_list = [] 3419419Sandreas.hansson@arm.com 34212563Sgabeblack@google.comExport('base_dir') 3433918Ssaidi@eecs.umich.eduExport('extras_dir_list') 3443918Ssaidi@eecs.umich.edu 3451858SN/A# the ext directory should be on the #includes path 3469556Sandreas.hansson@arm.commain.Append(CPPPATH=[Dir('ext')]) 3479556Sandreas.hansson@arm.com 3489556Sandreas.hansson@arm.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 3499556Sandreas.hansson@arm.comCXX_V = readCommand([main['CXX'],'-V'], exception=False) 35011294Sandreas.hansson@arm.com 35111294Sandreas.hansson@arm.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 35211294Sandreas.hansson@arm.commain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 35311294Sandreas.hansson@arm.commain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 35410878Sandreas.hansson@arm.comif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 35510878Sandreas.hansson@arm.com print 'Error: How can we have two at the same time?' 35611811Sbaz21@cam.ac.uk Exit(1) 35711811Sbaz21@cam.ac.uk 35811811Sbaz21@cam.ac.uk# Set up default C++ compiler flags 35911982Sgabeblack@google.comif main['GCC']: 36011982Sgabeblack@google.com main.Append(CCFLAGS='-pipe') 36111982Sgabeblack@google.com main.Append(CCFLAGS='-fno-strict-aliasing') 36213421Sciro.santilli@arm.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 36313421Sciro.santilli@arm.com main.Append(CXXFLAGS='-Wno-deprecated') 36411982Sgabeblack@google.comelif main['ICC']: 36511992Sgabeblack@google.com pass #Fix me... add warning flags once we clean up icc warnings 36611982Sgabeblack@google.comelif main['SUNCC']: 36711982Sgabeblack@google.com main.Append(CCFLAGS='-Qoption ccfe') 36812305Sgabeblack@google.com main.Append(CCFLAGS='-features=gcc') 36912305Sgabeblack@google.com main.Append(CCFLAGS='-features=extensions') 37012305Sgabeblack@google.com main.Append(CCFLAGS='-library=stlport4') 37112305Sgabeblack@google.com main.Append(CCFLAGS='-xar') 37212305Sgabeblack@google.com #main.Append(CCFLAGS='-instances=semiexplicit') 37312305Sgabeblack@google.comelse: 37412305Sgabeblack@google.com print 'Error: Don\'t know what compiler options to use for your compiler.' 3759556Sandreas.hansson@arm.com print ' Please fix SConstruct and src/SConscript and try again.' 37612563Sgabeblack@google.com Exit(1) 37712563Sgabeblack@google.com 37812563Sgabeblack@google.com# Set up common yacc/bison flags (needed for Ruby) 37912563Sgabeblack@google.commain['YACCFLAGS'] = '-d' 3809556Sandreas.hansson@arm.commain['YACCHXXFILESUFFIX'] = '.hh' 38112563Sgabeblack@google.com 38212563Sgabeblack@google.com# Do this after we save setting back, or else we'll tack on an 3839556Sandreas.hansson@arm.com# extra 'qdo' every time we run scons. 38412563Sgabeblack@google.comif main['BATCH']: 38512563Sgabeblack@google.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 38612563Sgabeblack@google.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 38712563Sgabeblack@google.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 38812563Sgabeblack@google.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 38912563Sgabeblack@google.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 39012563Sgabeblack@google.com 39112563Sgabeblack@google.comif sys.platform == 'cygwin': 3929556Sandreas.hansson@arm.com # cygwin has some header file issues... 3939556Sandreas.hansson@arm.com main.Append(CCFLAGS="-Wno-uninitialized") 3946121Snate@binkert.org 39511500Sandreas.hansson@arm.com# Check for SWIG 39610238Sandreas.hansson@arm.comif not main.has_key('SWIG'): 39710878Sandreas.hansson@arm.com print 'Error: SWIG utility not found.' 3989420Sandreas.hansson@arm.com print ' Please install (see http://www.swig.org) and retry.' 39911500Sandreas.hansson@arm.com Exit(1) 40012563Sgabeblack@google.com 40112563Sgabeblack@google.com# Check for appropriate SWIG version 4029420Sandreas.hansson@arm.comswig_version = readCommand(('swig', '-version'), exception='').split() 4039420Sandreas.hansson@arm.com# First 3 words should be "SWIG Version x.y.z" 4049420Sandreas.hansson@arm.comif len(swig_version) < 3 or \ 4059420Sandreas.hansson@arm.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 40612063Sgabeblack@google.com print 'Error determining SWIG version.' 40712063Sgabeblack@google.com Exit(1) 40812063Sgabeblack@google.com 40912063Sgabeblack@google.commin_swig_version = '1.3.28' 41012063Sgabeblack@google.comif compareVersions(swig_version[2], min_swig_version) < 0: 41112063Sgabeblack@google.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 41212063Sgabeblack@google.com print ' Installed version:', swig_version[2] 41312063Sgabeblack@google.com Exit(1) 41412063Sgabeblack@google.com 41512063Sgabeblack@google.com# Set up SWIG flags & scanner 41612063Sgabeblack@google.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 41712063Sgabeblack@google.commain.Append(SWIGFLAGS=swig_flags) 41812063Sgabeblack@google.com 41912063Sgabeblack@google.com# filter out all existing swig scanners, they mess up the dependency 42012063Sgabeblack@google.com# stuff for some reason 42112063Sgabeblack@google.comscanners = [] 42212063Sgabeblack@google.comfor scanner in main['SCANNERS']: 42312063Sgabeblack@google.com skeys = scanner.skeys 42412063Sgabeblack@google.com if skeys == '.i': 42512063Sgabeblack@google.com continue 42612063Sgabeblack@google.com 42712063Sgabeblack@google.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 42810457Sandreas.hansson@arm.com continue 42910457Sandreas.hansson@arm.com 43010457Sandreas.hansson@arm.com scanners.append(scanner) 43110457Sandreas.hansson@arm.com 43210457Sandreas.hansson@arm.com# add the new swig scanner that we like better 43312563Sgabeblack@google.comfrom SCons.Scanner import ClassicCPP as CPPScanner 43412563Sgabeblack@google.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 43512563Sgabeblack@google.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 43610457Sandreas.hansson@arm.com 43712063Sgabeblack@google.com# replace the scanners list that has what we want 43812063Sgabeblack@google.commain['SCANNERS'] = scanners 43912063Sgabeblack@google.com 44012563Sgabeblack@google.com# Add a custom Check function to the Configure context so that we can 44112563Sgabeblack@google.com# figure out if the compiler adds leading underscores to global 44212563Sgabeblack@google.com# variables. This is needed for the autogenerated asm files that we 44312563Sgabeblack@google.com# use for embedding the python code. 44412563Sgabeblack@google.comdef CheckLeading(context): 44512563Sgabeblack@google.com context.Message("Checking for leading underscore in global variables...") 44612063Sgabeblack@google.com # 1) Define a global variable called x from asm so the C compiler 44712063Sgabeblack@google.com # won't change the symbol at all. 44810238Sandreas.hansson@arm.com # 2) Declare that variable. 44910238Sandreas.hansson@arm.com # 3) Use the variable 45010238Sandreas.hansson@arm.com # 45112063Sgabeblack@google.com # If the compiler prepends an underscore, this will successfully 45210238Sandreas.hansson@arm.com # link because the external symbol 'x' will be called '_x' which 45310238Sandreas.hansson@arm.com # was defined by the asm statement. If the compiler does not 45410416Sandreas.hansson@arm.com # prepend an underscore, this will not successfully link because 45510238Sandreas.hansson@arm.com # '_x' will have been defined by assembly, while the C portion of 4569227Sandreas.hansson@arm.com # the code will be trying to use 'x' 45710238Sandreas.hansson@arm.com ret = context.TryLink(''' 45810416Sandreas.hansson@arm.com asm(".globl _x; _x: .byte 0"); 45910416Sandreas.hansson@arm.com extern int x; 4609227Sandreas.hansson@arm.com int main() { return x; } 4619590Sandreas@sandberg.pp.se ''', extension=".c") 4629590Sandreas@sandberg.pp.se context.env.Append(LEADING_UNDERSCORE=ret) 4639590Sandreas@sandberg.pp.se context.Result(ret) 46412304Sgabeblack@google.com return ret 46512304Sgabeblack@google.com 46612304Sgabeblack@google.com# Platform-specific configuration. Note again that we assume that all 46712688Sgiacomo.travaglini@arm.com# builds under a given build root run on the same host platform. 46812688Sgiacomo.travaglini@arm.comconf = Configure(main, 46912688Sgiacomo.travaglini@arm.com conf_dir = joinpath(build_root, '.scons_config'), 47013020Sshunhsingou@google.com log_file = joinpath(build_root, 'scons_config.log'), 47112304Sgabeblack@google.com custom_tests = { 'CheckLeading' : CheckLeading }) 47212688Sgiacomo.travaglini@arm.com 47312688Sgiacomo.travaglini@arm.com# Check for leading underscores. Don't really need to worry either 47413020Sshunhsingou@google.com# way so don't need to check the return code. 47512304Sgabeblack@google.comconf.CheckLeading() 47612304Sgabeblack@google.com 47712304Sgabeblack@google.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 47812304Sgabeblack@google.comtry: 47912688Sgiacomo.travaglini@arm.com import platform 48012688Sgiacomo.travaglini@arm.com uname = platform.uname() 48112688Sgiacomo.travaglini@arm.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 48212304Sgabeblack@google.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 4838737Skoansin.tan@gmail.com main.Append(CCFLAGS='-arch x86_64') 48410878Sandreas.hansson@arm.com main.Append(CFLAGS='-arch x86_64') 48511500Sandreas.hansson@arm.com main.Append(LINKFLAGS='-arch x86_64') 4869420Sandreas.hansson@arm.com main.Append(ASFLAGS='-arch x86_64') 4878737Skoansin.tan@gmail.comexcept: 48810106SMitch.Hayenga@arm.com pass 4898737Skoansin.tan@gmail.com 4908737Skoansin.tan@gmail.com# Recent versions of scons substitute a "Null" object for Configure() 49110878Sandreas.hansson@arm.com# when configuration isn't necessary, e.g., if the "--help" option is 49212563Sgabeblack@google.com# present. Unfortuantely this Null object always returns false, 49312563Sgabeblack@google.com# breaking all our configuration checks. We replace it with our own 4948737Skoansin.tan@gmail.com# more optimistic null object that returns True instead. 4958737Skoansin.tan@gmail.comif not conf: 49612563Sgabeblack@google.com def NullCheck(*args, **kwargs): 4978737Skoansin.tan@gmail.com return True 4988737Skoansin.tan@gmail.com 49911294Sandreas.hansson@arm.com class NullConf: 5009556Sandreas.hansson@arm.com def __init__(self, env): 5019556Sandreas.hansson@arm.com self.env = env 5029556Sandreas.hansson@arm.com def Finish(self): 50311294Sandreas.hansson@arm.com return self.env 50410278SAndreas.Sandberg@ARM.com def __getattr__(self, mname): 50510278SAndreas.Sandberg@ARM.com return NullCheck 50610278SAndreas.Sandberg@ARM.com 50710278SAndreas.Sandberg@ARM.com conf = NullConf(main) 50810278SAndreas.Sandberg@ARM.com 50910278SAndreas.Sandberg@ARM.com# Find Python include and library directories for embedding the 5109556Sandreas.hansson@arm.com# interpreter. For consistency, we will use the same Python 5119590Sandreas@sandberg.pp.se# installation used to run scons (and thus this script). If you want 5129590Sandreas@sandberg.pp.se# to link in an alternate version, see above for instructions on how 5139420Sandreas.hansson@arm.com# to invoke scons with a different copy of the Python interpreter. 5149846Sandreas.hansson@arm.comfrom distutils import sysconfig 5159846Sandreas.hansson@arm.com 5169846Sandreas.hansson@arm.compy_getvar = sysconfig.get_config_var 5179846Sandreas.hansson@arm.com 5188946Sandreas.hansson@arm.compy_debug = getattr(sys, 'pydebug', False) 51911811Sbaz21@cam.ac.ukpy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 52011811Sbaz21@cam.ac.uk 52111811Sbaz21@cam.ac.ukpy_general_include = sysconfig.get_python_inc() 52211811Sbaz21@cam.ac.ukpy_platform_include = sysconfig.get_python_inc(plat_specific=True) 52312304Sgabeblack@google.compy_includes = [ py_general_include ] 52412304Sgabeblack@google.comif py_platform_include != py_general_include: 52512304Sgabeblack@google.com py_includes.append(py_platform_include) 52612304Sgabeblack@google.com 52713020Sshunhsingou@google.compy_lib_path = [ py_getvar('LIBDIR') ] 52813020Sshunhsingou@google.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no 52912304Sgabeblack@google.com# shared library in prefix/lib/. 53012304Sgabeblack@google.comif not py_getvar('Py_ENABLE_SHARED'): 53113020Sshunhsingou@google.com py_lib_path.append(py_getvar('LIBPL')) 53213020Sshunhsingou@google.com 53312304Sgabeblack@google.compy_libs = [] 53412304Sgabeblack@google.comfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 53513020Sshunhsingou@google.com assert lib.startswith('-l') 53613020Sshunhsingou@google.com lib = lib[2:] 53712304Sgabeblack@google.com if lib not in py_libs: 53812304Sgabeblack@google.com py_libs.append(lib) 5393918Ssaidi@eecs.umich.edupy_libs.append(py_version) 54012563Sgabeblack@google.com 54112563Sgabeblack@google.commain.Append(CPPPATH=py_includes) 54212563Sgabeblack@google.commain.Append(LIBPATH=py_lib_path) 54312563Sgabeblack@google.com 5449068SAli.Saidi@ARM.com# verify that this stuff works 54512563Sgabeblack@google.comif not conf.CheckHeader('Python.h', '<>'): 54612563Sgabeblack@google.com print "Error: can't find Python.h header in", py_includes 5479068SAli.Saidi@ARM.com Exit(1) 54812563Sgabeblack@google.com 54912563Sgabeblack@google.comfor lib in py_libs: 55012563Sgabeblack@google.com if not conf.CheckLib(lib): 55112563Sgabeblack@google.com print "Error: can't find library %s required by python" % lib 55212563Sgabeblack@google.com Exit(1) 55312563Sgabeblack@google.com 55412563Sgabeblack@google.com# On Solaris you need to use libsocket for socket ops 55512563Sgabeblack@google.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5563918Ssaidi@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5573918Ssaidi@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 5586157Snate@binkert.org Exit(1) 5596157Snate@binkert.org 5606157Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 5616157Snate@binkert.org# added to the LIBS environment variable. 5625397Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5635397Ssaidi@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 5646121Snate@binkert.org 'and/or zlib.h header file.' 5656121Snate@binkert.org print ' Please install zlib and try again.' 5666121Snate@binkert.org Exit(1) 5676121Snate@binkert.org 5686121Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 5696121Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>') 5705397Ssaidi@eecs.umich.eduif not have_fenv: 5711851SN/A print "Warning: Header file <fenv.h> not found." 5721851SN/A print " This host has no IEEE FP rounding mode control." 5737739Sgblack@eecs.umich.edu 574955SN/A###################################################################### 5759396Sandreas.hansson@arm.com# 5769396Sandreas.hansson@arm.com# Check for mysql. 5779396Sandreas.hansson@arm.com# 5789396Sandreas.hansson@arm.commysql_config = WhereIs('mysql_config') 5799396Sandreas.hansson@arm.comhave_mysql = bool(mysql_config) 5809396Sandreas.hansson@arm.com 58112563Sgabeblack@google.com# Check MySQL version. 58212563Sgabeblack@google.comif have_mysql: 58312563Sgabeblack@google.com mysql_version = readCommand(mysql_config + ' --version') 58412563Sgabeblack@google.com min_mysql_version = '4.1' 5859396Sandreas.hansson@arm.com if compareVersions(mysql_version, min_mysql_version) < 0: 5869396Sandreas.hansson@arm.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 5879396Sandreas.hansson@arm.com print ' Version', mysql_version, 'detected.' 5889396Sandreas.hansson@arm.com have_mysql = False 5899396Sandreas.hansson@arm.com 5909396Sandreas.hansson@arm.com# Set up mysql_config commands. 59112563Sgabeblack@google.comif have_mysql: 59212563Sgabeblack@google.com mysql_config_include = mysql_config + ' --include' 59312563Sgabeblack@google.com if os.system(mysql_config_include + ' > /dev/null') != 0: 59412563Sgabeblack@google.com # older mysql_config versions don't support --include, use 59512563Sgabeblack@google.com # --cflags instead 5969477Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 5979477Sandreas.hansson@arm.com # This seems to work in all versions 5989477Sandreas.hansson@arm.com mysql_config_libs = mysql_config + ' --libs' 5999477Sandreas.hansson@arm.com 6009477Sandreas.hansson@arm.com###################################################################### 6019477Sandreas.hansson@arm.com# 6029477Sandreas.hansson@arm.com# Finish the configuration 6039477Sandreas.hansson@arm.com# 6049477Sandreas.hansson@arm.commain = conf.Finish() 6059477Sandreas.hansson@arm.com 6069477Sandreas.hansson@arm.com###################################################################### 6079477Sandreas.hansson@arm.com# 6089477Sandreas.hansson@arm.com# Collect all non-global variables 6099477Sandreas.hansson@arm.com# 61012563Sgabeblack@google.com 61112563Sgabeblack@google.com# Define the universe of supported ISAs 61212563Sgabeblack@google.comall_isa_list = [ ] 6139396Sandreas.hansson@arm.comExport('all_isa_list') 6142667Sstever@eecs.umich.edu 61510710Sandreas.hansson@arm.comclass CpuModel(object): 61610710Sandreas.hansson@arm.com '''The CpuModel class encapsulates everything the ISA parser needs to 61710710Sandreas.hansson@arm.com know about a particular CPU model.''' 61811811Sbaz21@cam.ac.uk 61911811Sbaz21@cam.ac.uk # Dict of available CPU model objects. Accessible as CpuModel.dict. 62011811Sbaz21@cam.ac.uk dict = {} 62111811Sbaz21@cam.ac.uk list = [] 62211811Sbaz21@cam.ac.uk defaults = [] 62311811Sbaz21@cam.ac.uk 62410710Sandreas.hansson@arm.com # Constructor. Automatically adds models to CpuModel.dict. 62510710Sandreas.hansson@arm.com def __init__(self, name, filename, includes, strings, default=False): 62610710Sandreas.hansson@arm.com self.name = name # name of model 62710710Sandreas.hansson@arm.com self.filename = filename # filename for output exec code 62810384SCurtis.Dunham@arm.com self.includes = includes # include files needed in exec file 6299986Sandreas@sandberg.pp.se # The 'strings' dict holds all the per-CPU symbols we can 6309986Sandreas@sandberg.pp.se # substitute into templates etc. 6319986Sandreas@sandberg.pp.se self.strings = strings 6329986Sandreas@sandberg.pp.se 6339986Sandreas@sandberg.pp.se # This cpu is enabled by default 6349986Sandreas@sandberg.pp.se self.default = default 6359986Sandreas@sandberg.pp.se 6369986Sandreas@sandberg.pp.se # Add self to dict 6379986Sandreas@sandberg.pp.se if name in CpuModel.dict: 6389986Sandreas@sandberg.pp.se raise AttributeError, "CpuModel '%s' already registered" % name 6399986Sandreas@sandberg.pp.se CpuModel.dict[name] = self 6409986Sandreas@sandberg.pp.se CpuModel.list.append(name) 6419986Sandreas@sandberg.pp.se 6429986Sandreas@sandberg.pp.seExport('CpuModel') 6439986Sandreas@sandberg.pp.se 6449986Sandreas@sandberg.pp.se# Sticky variables get saved in the variables file so they persist from 6459986Sandreas@sandberg.pp.se# one invocation to the next (unless overridden, in which case the new 6469986Sandreas@sandberg.pp.se# value becomes sticky). 6479986Sandreas@sandberg.pp.sesticky_vars = Variables(args=ARGUMENTS) 6489986Sandreas@sandberg.pp.seExport('sticky_vars') 6492638Sstever@eecs.umich.edu 6502638Sstever@eecs.umich.edu# Sticky variables that should be exported 6516121Snate@binkert.orgexport_vars = [] 6523716Sstever@eecs.umich.eduExport('export_vars') 6535522Snate@binkert.org 6549986Sandreas@sandberg.pp.se# Non-sticky variables only apply to the current build. 6559986Sandreas@sandberg.pp.senonsticky_vars = Variables(args=ARGUMENTS) 6569986Sandreas@sandberg.pp.seExport('nonsticky_vars') 6575522Snate@binkert.org 6585227Ssaidi@eecs.umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 6595227Ssaidi@eecs.umich.edu# above variables 6605227Ssaidi@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list: 6615227Ssaidi@eecs.umich.edu for root, dirs, files in os.walk(bdir): 6626654Snate@binkert.org if 'SConsopts' in files: 6636654Snate@binkert.org print "Reading", joinpath(root, 'SConsopts') 6647769SAli.Saidi@ARM.com SConscript(joinpath(root, 'SConsopts')) 6657769SAli.Saidi@ARM.com 6667769SAli.Saidi@ARM.comall_isa_list.sort() 6677769SAli.Saidi@ARM.com 6685227Ssaidi@eecs.umich.edusticky_vars.AddVariables( 6695227Ssaidi@eecs.umich.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6705227Ssaidi@eecs.umich.edu BoolVariable('FULL_SYSTEM', 'Full-system support', False), 6715204Sstever@gmail.com ListVariable('CPU_MODELS', 'CPU models', 6725204Sstever@gmail.com sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 6735204Sstever@gmail.com sorted(CpuModel.list)), 6745204Sstever@gmail.com BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6755204Sstever@gmail.com BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6765204Sstever@gmail.com False), 6775204Sstever@gmail.com BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6785204Sstever@gmail.com False), 6795204Sstever@gmail.com BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 6805204Sstever@gmail.com False), 6815204Sstever@gmail.com BoolVariable('SS_COMPATIBLE_FP', 6825204Sstever@gmail.com 'Make floating-point results compatible with SimpleScalar', 6835204Sstever@gmail.com False), 6845204Sstever@gmail.com BoolVariable('USE_SSE2', 6855204Sstever@gmail.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 6865204Sstever@gmail.com False), 6875204Sstever@gmail.com BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6886121Snate@binkert.org BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6895204Sstever@gmail.com BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 6907727SAli.Saidi@ARM.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 6917727SAli.Saidi@ARM.com BoolVariable('RUBY', 'Build with Ruby', False), 69212563Sgabeblack@google.com ) 6937727SAli.Saidi@ARM.com 6947727SAli.Saidi@ARM.comnonsticky_vars.AddVariables( 69511988Sandreas.sandberg@arm.com BoolVariable('update_ref', 'Update test reference outputs', False) 69611988Sandreas.sandberg@arm.com ) 69710453SAndrew.Bardsley@arm.com 69810453SAndrew.Bardsley@arm.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 69910453SAndrew.Bardsley@arm.comexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 70010453SAndrew.Bardsley@arm.com 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 70110453SAndrew.Bardsley@arm.com 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 70210453SAndrew.Bardsley@arm.com 70310453SAndrew.Bardsley@arm.com################################################### 70410453SAndrew.Bardsley@arm.com# 70510453SAndrew.Bardsley@arm.com# Define a SCons builder for configuration flag headers. 70610453SAndrew.Bardsley@arm.com# 70710160Sandreas.hansson@arm.com################################################### 70810453SAndrew.Bardsley@arm.com 70910453SAndrew.Bardsley@arm.com# This function generates a config header file that #defines the 71010453SAndrew.Bardsley@arm.com# variable symbol to the current variable setting (0 or 1). The source 71110453SAndrew.Bardsley@arm.com# operands are the name of the variable and a Value node containing the 71210453SAndrew.Bardsley@arm.com# value of the variable. 71310453SAndrew.Bardsley@arm.comdef build_config_file(target, source, env): 71410453SAndrew.Bardsley@arm.com (variable, value) = [s.get_contents() for s in source] 71510453SAndrew.Bardsley@arm.com f = file(str(target[0]), 'w') 7169812Sandreas.hansson@arm.com print >> f, '#define', variable, value 71710453SAndrew.Bardsley@arm.com f.close() 71810453SAndrew.Bardsley@arm.com return None 71910453SAndrew.Bardsley@arm.com 72010453SAndrew.Bardsley@arm.com# Generate the message to be printed when building the config file. 72110453SAndrew.Bardsley@arm.comdef build_config_file_string(target, source, env): 72210453SAndrew.Bardsley@arm.com (variable, value) = [s.get_contents() for s in source] 72310453SAndrew.Bardsley@arm.com return "Defining %s as %s in %s." % (variable, value, target[0]) 72410453SAndrew.Bardsley@arm.com 72510453SAndrew.Bardsley@arm.com# Combine the two functions into a scons Action object. 72610453SAndrew.Bardsley@arm.comconfig_action = Action(build_config_file, build_config_file_string) 72710453SAndrew.Bardsley@arm.com 72810453SAndrew.Bardsley@arm.com# The emitter munges the source & target node lists to reflect what 7297727SAli.Saidi@ARM.com# we're really doing. 73010453SAndrew.Bardsley@arm.comdef config_emitter(target, source, env): 73110453SAndrew.Bardsley@arm.com # extract variable name from Builder arg 73212790Smatteo.fusi@bsc.es variable = str(target[0]) 73312790Smatteo.fusi@bsc.es # True target is config header file 73412790Smatteo.fusi@bsc.es target = joinpath('config', variable.lower() + '.hh') 73512790Smatteo.fusi@bsc.es val = env[variable] 73612790Smatteo.fusi@bsc.es if isinstance(val, bool): 73712790Smatteo.fusi@bsc.es # Force value to 0/1 73812790Smatteo.fusi@bsc.es val = int(val) 73910453SAndrew.Bardsley@arm.com elif isinstance(val, str): 7403118Sstever@eecs.umich.edu val = '"' + val + '"' 74110453SAndrew.Bardsley@arm.com 74210453SAndrew.Bardsley@arm.com # Sources are variable name & value (packaged in SCons Value nodes) 74312563Sgabeblack@google.com return ([target], [Value(variable), Value(val)]) 74410453SAndrew.Bardsley@arm.com 7453118Sstever@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 7463483Ssaidi@eecs.umich.edu 7473494Ssaidi@eecs.umich.edumain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 7483494Ssaidi@eecs.umich.edu 74912563Sgabeblack@google.com# libelf build is shared across all configs in the build root. 7503483Ssaidi@eecs.umich.edumain.SConscript('ext/libelf/SConscript', 7513483Ssaidi@eecs.umich.edu variant_dir = joinpath(build_root, 'libelf')) 7523053Sstever@eecs.umich.edu 7533053Sstever@eecs.umich.edu# gzstream build is shared across all configs in the build root. 7543918Ssaidi@eecs.umich.edumain.SConscript('ext/gzstream/SConscript', 75512563Sgabeblack@google.com variant_dir = joinpath(build_root, 'gzstream')) 75612563Sgabeblack@google.com 75712563Sgabeblack@google.com################################################### 7583053Sstever@eecs.umich.edu# 7593053Sstever@eecs.umich.edu# This function is used to set up a directory with switching headers 7609396Sandreas.hansson@arm.com# 7619396Sandreas.hansson@arm.com################################################### 7629396Sandreas.hansson@arm.com 7639396Sandreas.hansson@arm.commain['ALL_ISA_LIST'] = all_isa_list 7649396Sandreas.hansson@arm.comdef make_switching_dir(dname, switch_headers, env): 7659396Sandreas.hansson@arm.com # Generate the header. target[0] is the full path of the output 7669396Sandreas.hansson@arm.com # header to generate. 'source' is a dummy variable, since we get the 7679396Sandreas.hansson@arm.com # list of ISAs from env['ALL_ISA_LIST']. 7689396Sandreas.hansson@arm.com def gen_switch_hdr(target, source, env): 76912920Sgabeblack@google.com fname = str(target[0]) 77012920Sgabeblack@google.com f = open(fname, 'w') 77112920Sgabeblack@google.com isa = env['TARGET_ISA'].lower() 77212920Sgabeblack@google.com print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 7739477Sandreas.hansson@arm.com f.close() 7749396Sandreas.hansson@arm.com 77512563Sgabeblack@google.com # String to print when generating header 77612563Sgabeblack@google.com def gen_switch_hdr_string(target, source, env): 77712563Sgabeblack@google.com return "Generating switch header " + str(target[0]) 77812563Sgabeblack@google.com 7799396Sandreas.hansson@arm.com # Build SCons Action object. 'varlist' specifies env vars that this 7807840Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 7817865Sgblack@eecs.umich.edu # should get re-executed. 7827865Sgblack@eecs.umich.edu switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 7837865Sgblack@eecs.umich.edu varlist=['ALL_ISA_LIST']) 7847865Sgblack@eecs.umich.edu 7857865Sgblack@eecs.umich.edu # Instantiate actions for each header 7867840Snate@binkert.org for hdr in switch_headers: 7879900Sandreas@sandberg.pp.se env.Command(hdr, [], switch_hdr_action) 7889900Sandreas@sandberg.pp.seExport('make_switching_dir') 7899900Sandreas@sandberg.pp.se 7909900Sandreas@sandberg.pp.se################################################### 79110456SCurtis.Dunham@arm.com# 79210456SCurtis.Dunham@arm.com# Define build environments for selected configurations. 79310456SCurtis.Dunham@arm.com# 79410456SCurtis.Dunham@arm.com################################################### 79510456SCurtis.Dunham@arm.com 79610456SCurtis.Dunham@arm.comfor variant_path in variant_paths: 79712563Sgabeblack@google.com print "Building in", variant_path 79812563Sgabeblack@google.com 79912563Sgabeblack@google.com # Make a copy of the build-root environment to use for this config. 80012563Sgabeblack@google.com env = main.Clone() 8019045SAli.Saidi@ARM.com env['BUILDDIR'] = variant_path 80211235Sandreas.sandberg@arm.com 80311235Sandreas.sandberg@arm.com # variant_dir is the tail component of build path, and is used to 80411235Sandreas.sandberg@arm.com # determine the build parameters (e.g., 'ALPHA_SE') 80511235Sandreas.sandberg@arm.com (build_root, variant_dir) = splitpath(variant_path) 80611235Sandreas.sandberg@arm.com 80712485Sjang.hanhwi@gmail.com # Set env variables according to the build directory config. 80812485Sjang.hanhwi@gmail.com sticky_vars.files = [] 80912485Sjang.hanhwi@gmail.com # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 81011235Sandreas.sandberg@arm.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 81111811Sbaz21@cam.ac.uk # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 81212485Sjang.hanhwi@gmail.com current_vars_file = joinpath(build_root, 'variables', variant_dir) 81311811Sbaz21@cam.ac.uk if isfile(current_vars_file): 81411811Sbaz21@cam.ac.uk sticky_vars.files.append(current_vars_file) 81511811Sbaz21@cam.ac.uk print "Using saved variables file %s" % current_vars_file 81611235Sandreas.sandberg@arm.com else: 81711235Sandreas.sandberg@arm.com # Build dir-specific variables file doesn't exist. 81811235Sandreas.sandberg@arm.com 81912563Sgabeblack@google.com # Make sure the directory is there so we can create it later 82012563Sgabeblack@google.com opt_dir = dirname(current_vars_file) 82112563Sgabeblack@google.com if not isdir(opt_dir): 82211235Sandreas.sandberg@arm.com mkdir(opt_dir) 8237840Snate@binkert.org 82412563Sgabeblack@google.com # Get default build variables from source tree. Variables are 8257840Snate@binkert.org # normally determined by name of $VARIANT_DIR, but can be 8261858SN/A # overriden by 'default=' arg on command line. 8271858SN/A default_vars_file = joinpath('build_opts', 8281858SN/A ARGUMENTS.get('default', variant_dir)) 82912563Sgabeblack@google.com if isfile(default_vars_file): 83012563Sgabeblack@google.com sticky_vars.files.append(default_vars_file) 8311858SN/A print "Variables file %s not found,\n using defaults in %s" \ 83212230Sgiacomo.travaglini@arm.com % (current_vars_file, default_vars_file) 83312230Sgiacomo.travaglini@arm.com else: 83412230Sgiacomo.travaglini@arm.com print "Error: cannot find variables file %s or %s" \ 83512230Sgiacomo.travaglini@arm.com % (current_vars_file, default_vars_file) 83612563Sgabeblack@google.com Exit(1) 83712563Sgabeblack@google.com 83812563Sgabeblack@google.com # Apply current variable settings to env 83912230Sgiacomo.travaglini@arm.com sticky_vars.Update(env) 8409903Sandreas.hansson@arm.com nonsticky_vars.Update(env) 8419903Sandreas.hansson@arm.com 8429903Sandreas.hansson@arm.com help_text += "\nSticky variables for %s:\n" % variant_dir \ 8439903Sandreas.hansson@arm.com + sticky_vars.GenerateHelpText(env) \ 84410841Sandreas.sandberg@arm.com + "\nNon-sticky variables for %s:\n" % variant_dir \ 8459651SAndreas.Sandberg@ARM.com + nonsticky_vars.GenerateHelpText(env) 84612563Sgabeblack@google.com 84712563Sgabeblack@google.com # Process variable settings. 8489651SAndreas.Sandberg@ARM.com 84912056Sgabeblack@google.com if not have_fenv and env['USE_FENV']: 85012056Sgabeblack@google.com print "Warning: <fenv.h> not available; " \ 85112056Sgabeblack@google.com "forcing USE_FENV to False in", variant_dir + "." 85212563Sgabeblack@google.com env['USE_FENV'] = False 85312056Sgabeblack@google.com 85410841Sandreas.sandberg@arm.com if not env['USE_FENV']: 85510841Sandreas.sandberg@arm.com print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 85610841Sandreas.sandberg@arm.com print " FP results may deviate slightly from other platforms." 85710841Sandreas.sandberg@arm.com 85810841Sandreas.sandberg@arm.com if env['EFENCE']: 85910841Sandreas.sandberg@arm.com env.Append(LIBS=['efence']) 8609651SAndreas.Sandberg@ARM.com 8619651SAndreas.Sandberg@ARM.com if env['USE_MYSQL']: 8629651SAndreas.Sandberg@ARM.com if not have_mysql: 8639651SAndreas.Sandberg@ARM.com print "Warning: MySQL not available; " \ 8649651SAndreas.Sandberg@ARM.com "forcing USE_MYSQL to False in", variant_dir + "." 8659651SAndreas.Sandberg@ARM.com env['USE_MYSQL'] = False 86612563Sgabeblack@google.com else: 8679651SAndreas.Sandberg@ARM.com print "Compiling in", variant_dir, "with MySQL support." 8689651SAndreas.Sandberg@ARM.com env.ParseConfig(mysql_config_libs) 86910841Sandreas.sandberg@arm.com env.ParseConfig(mysql_config_include) 87012563Sgabeblack@google.com 87112563Sgabeblack@google.com # Save sticky variable settings back to current variables file 87210841Sandreas.sandberg@arm.com sticky_vars.Save(current_vars_file, env) 87310841Sandreas.sandberg@arm.com 87410841Sandreas.sandberg@arm.com if env['USE_SSE2']: 87510860Sandreas.sandberg@arm.com env.Append(CCFLAGS='-msse2') 87610841Sandreas.sandberg@arm.com 87710841Sandreas.sandberg@arm.com # The src/SConscript file sets up the build rules in 'env' according 87810841Sandreas.sandberg@arm.com # to the configured variables. It returns a list of environments, 87910841Sandreas.sandberg@arm.com # one for each variant build (debug, opt, etc.) 88010841Sandreas.sandberg@arm.com envList = SConscript('src/SConscript', variant_dir = variant_path, 88112563Sgabeblack@google.com exports = 'env') 88210841Sandreas.sandberg@arm.com 88310841Sandreas.sandberg@arm.com # Set up the regression tests for each build. 88410841Sandreas.sandberg@arm.com for e in envList: 88510841Sandreas.sandberg@arm.com SConscript('tests/SConscript', 88610841Sandreas.sandberg@arm.com variant_dir = joinpath(variant_path, 'tests', e.Label), 8879651SAndreas.Sandberg@ARM.com exports = { 'env' : e }, duplicate = False) 8889651SAndreas.Sandberg@ARM.com 8899986Sandreas@sandberg.pp.seHelp(help_text) 8909986Sandreas@sandberg.pp.se