SConstruct revision 5863
1955SN/A# -*- mode:python -*- 2955SN/A 312230Sgiacomo.travaglini@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 49812Sandreas.hansson@arm.com# All rights reserved. 59812Sandreas.hansson@arm.com# 69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from 157816Ssteve.reinhardt@amd.com# this software without specific prior written permission. 165871Snate@binkert.org# 171762SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28955SN/A# 29955SN/A# Authors: Steve Reinhardt 30955SN/A# Nathan Binkert 31955SN/A 32955SN/A################################################### 33955SN/A# 34955SN/A# SCons top-level build description (SConstruct) file. 35955SN/A# 36955SN/A# While in this directory ('m5'), just type 'scons' to build the default 37955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 38955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 39955SN/A# the optimized full-system version). 40955SN/A# 41955SN/A# You can build M5 in a different directory as long as there is a 422665Ssaidi@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 432665Ssaidi@eecs.umich.edu# expects that all configs under the same build directory are being 445863Snate@binkert.org# built for the same host system. 45955SN/A# 46955SN/A# Examples: 47955SN/A# 48955SN/A# The following two commands are equivalent. The '-u' option tells 49955SN/A# scons to search up the directory tree for this SConstruct file. 508878Ssteve.reinhardt@amd.com# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 512632Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 528878Ssteve.reinhardt@amd.com# 532632Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 54955SN/A# in a directory outside of the source tree. The '-C' option tells 558878Ssteve.reinhardt@amd.com# scons to chdir to the specified directory to find this SConstruct 562632Sstever@eecs.umich.edu# file. 572761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 582632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 592632Sstever@eecs.umich.edu# 602632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 612761Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 622761Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 632761Sstever@eecs.umich.edu# options as well. 648878Ssteve.reinhardt@amd.com# 658878Ssteve.reinhardt@amd.com################################################### 662761Sstever@eecs.umich.edu 672761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. 682761Sstever@eecs.umich.edutry: 692761Sstever@eecs.umich.edu # Really old versions of scons only take two options for the 702761Sstever@eecs.umich.edu # function, so check once without the revision and once with the 718878Ssteve.reinhardt@amd.com # revision, the first instance will fail for stuff other than 728878Ssteve.reinhardt@amd.com # 0.98, and the second will fail for 0.98.0 732632Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 742632Sstever@eecs.umich.edu EnsureSConsVersion(0, 98, 1) 758878Ssteve.reinhardt@amd.comexcept SystemExit, e: 768878Ssteve.reinhardt@amd.com print """ 772632Sstever@eecs.umich.eduFor more details, see: 78955SN/A http://m5sim.org/wiki/index.php/Compiling_M5 79955SN/A""" 80955SN/A raise 8112563Sgabeblack@google.com 8212563Sgabeblack@google.com# We ensure the python version early because we have stuff that 836654Snate@binkert.org# requires python 2.4 8410196SCurtis.Dunham@arm.comtry: 85955SN/A EnsurePythonVersion(2, 4) 865396Ssaidi@eecs.umich.eduexcept SystemExit, e: 8711401Sandreas.sandberg@arm.com print """ 885863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 895863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 904202Sbinkertn@umich.edu'python' first or (2) explicitly invoking an alternative interpreter 915863Snate@binkert.orgon the scons script. 925863Snate@binkert.org 935863Snate@binkert.orgFor more details, see: 945863Snate@binkert.org http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 9513541Sandrea.mondelli@ucf.edu""" 96955SN/A raise 976654Snate@binkert.org 985273Sstever@gmail.comimport os 995871Snate@binkert.orgimport re 1005273Sstever@gmail.comimport subprocess 1016654Snate@binkert.orgimport sys 1025396Ssaidi@eecs.umich.edu 1038120Sgblack@eecs.umich.edufrom os import mkdir, environ 1048120Sgblack@eecs.umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath 1058120Sgblack@eecs.umich.edufrom os.path import exists, isdir, isfile 1068120Sgblack@eecs.umich.edufrom os.path import join as joinpath, split as splitpath 1078120Sgblack@eecs.umich.edu 1088120Sgblack@eecs.umich.eduimport SCons 1098120Sgblack@eecs.umich.edu 1108120Sgblack@eecs.umich.edudef read_command(cmd): 1118879Ssteve.reinhardt@amd.com """run the command cmd, read the results and return them 1128879Ssteve.reinhardt@amd.com this is sorta like `cmd` in shell""" 1138879Ssteve.reinhardt@amd.com from subprocess import Popen, PIPE, STDOUT 1148879Ssteve.reinhardt@amd.com subp = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT, close_fds=True) 1158879Ssteve.reinhardt@amd.com return subp.communicate()[0] 1168879Ssteve.reinhardt@amd.com 1178879Ssteve.reinhardt@amd.com# helper function: compare arrays or strings of version numbers. 1188879Ssteve.reinhardt@amd.com# E.g., compare_version((1,3,25), (1,4,1)') 1198879Ssteve.reinhardt@amd.com# returns -1, 0, 1 if v1 is <, ==, > v2 1208879Ssteve.reinhardt@amd.comdef compare_versions(v1, v2): 1218879Ssteve.reinhardt@amd.com def make_version_list(v): 1228879Ssteve.reinhardt@amd.com if isinstance(v, (list,tuple)): 1238879Ssteve.reinhardt@amd.com return v 1248120Sgblack@eecs.umich.edu elif isinstance(v, str): 1258120Sgblack@eecs.umich.edu return map(lambda x: int(re.match('\d+', x).group()), v.split('.')) 1268120Sgblack@eecs.umich.edu else: 1278120Sgblack@eecs.umich.edu raise TypeError 1288120Sgblack@eecs.umich.edu 1298120Sgblack@eecs.umich.edu v1 = make_version_list(v1) 1308120Sgblack@eecs.umich.edu v2 = make_version_list(v2) 1318120Sgblack@eecs.umich.edu # Compare corresponding elements of lists 1328120Sgblack@eecs.umich.edu for n1,n2 in zip(v1, v2): 1338120Sgblack@eecs.umich.edu if n1 < n2: return -1 1348120Sgblack@eecs.umich.edu if n1 > n2: return 1 1358120Sgblack@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1368120Sgblack@eecs.umich.edu if len(v1) < len(v2): return -1 1378120Sgblack@eecs.umich.edu if len(v1) > len(v2): return 1 1388879Ssteve.reinhardt@amd.com return 0 1398879Ssteve.reinhardt@amd.com 1408879Ssteve.reinhardt@amd.com# The absolute path to the current directory (where this file lives). 1418879Ssteve.reinhardt@amd.comROOT = Dir('.').abspath 14210458Sandreas.hansson@arm.com 14310458Sandreas.hansson@arm.com# Path to the M5 source tree. 14410458Sandreas.hansson@arm.comSRCDIR = joinpath(ROOT, 'src') 1458879Ssteve.reinhardt@amd.com 1468879Ssteve.reinhardt@amd.com# tell python where to find m5 python code 1478879Ssteve.reinhardt@amd.comsys.path.append(joinpath(ROOT, 'src/python')) 1488879Ssteve.reinhardt@amd.com 14913421Sciro.santilli@arm.com################################################### 15013421Sciro.santilli@arm.com# Mercurial Stuff. 1519227Sandreas.hansson@arm.com# 1) Grab repository revision if we know it. 1529227Sandreas.hansson@arm.com# 2) Ensure that the style hook is in place. 15312063Sgabeblack@google.com################################################### 15412063Sgabeblack@google.com 15512063Sgabeblack@google.comhg_info = "Unknown" 1568879Ssteve.reinhardt@amd.comtry: 1578879Ssteve.reinhardt@amd.com if not exists(ROOT) or not isdir(ROOT) or \ 1588879Ssteve.reinhardt@amd.com not exists(joinpath(ROOT, ".hg")): 1598879Ssteve.reinhardt@amd.com raise ValueError(".hg directory not found") 16010453SAndrew.Bardsley@arm.com hg_info = read_command("cd %s; hg id -n -i -t -b" % ROOT).strip() 16110453SAndrew.Bardsley@arm.comexcept ImportError, e: 16210453SAndrew.Bardsley@arm.com print "Mercurial not found" 16310456SCurtis.Dunham@arm.comexcept ValueError, e: 16410456SCurtis.Dunham@arm.com print e 16510456SCurtis.Dunham@arm.comexcept Exception, e: 16610457Sandreas.hansson@arm.com print "Other mercurial exception: %s" % e 16710457Sandreas.hansson@arm.com 16811342Sandreas.hansson@arm.comdef check_style_hook(ui): 16911342Sandreas.hansson@arm.com ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 1708120Sgblack@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) 17112063Sgabeblack@google.com 17212563Sgabeblack@google.com if not style_hook: 17312063Sgabeblack@google.com print """\ 17412063Sgabeblack@google.comYou're missing the M5 style hook. 1755871Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style. 1765871Snate@binkert.org 1776121Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc 1785871Snate@binkert.orgor your personal .hgrc 1795871Snate@binkert.org---------------- 1809926Sstan.czerniawski@arm.com 18112243Sgabeblack@google.com[extensions] 1821533SN/Astyle = %s/util/style.py 18312246Sgabeblack@google.com 18412246Sgabeblack@google.com[hooks] 18512246Sgabeblack@google.compretxncommit.style = python:style.check_whitespace 18612246Sgabeblack@google.com""" % (ROOT) 1879239Sandreas.hansson@arm.com sys.exit(1) 1889239Sandreas.hansson@arm.com 1899239Sandreas.hansson@arm.comif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1909239Sandreas.hansson@arm.com try: 19112563Sgabeblack@google.com from mercurial import ui 1929239Sandreas.hansson@arm.com check_style_hook(ui.ui()) 1939239Sandreas.hansson@arm.com except ImportError: 194955SN/A pass 195955SN/A 1962632Sstever@eecs.umich.edu 1972632Sstever@eecs.umich.edu################################################### 198955SN/A# 199955SN/A# Figure out which configurations to set up based on the path(s) of 200955SN/A# the target(s). 201955SN/A# 2028878Ssteve.reinhardt@amd.com################################################### 203955SN/A 2042632Sstever@eecs.umich.edu# Find default configuration & binary. 2052632Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2062632Sstever@eecs.umich.edu 2072632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 2082632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 2092632Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2102632Sstever@eecs.umich.edu if l[i] == elt: 2118268Ssteve.reinhardt@amd.com return i 2128268Ssteve.reinhardt@amd.com raise ValueError, "element not found" 2138268Ssteve.reinhardt@amd.com 2148268Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the 2158268Ssteve.reinhardt@amd.com# directory below this will determine the build parameters. For 2168268Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2178268Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it 2182632Sstever@eecs.umich.edu# follow 'build' in the bulid path. 2192632Sstever@eecs.umich.edu 2202632Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is 2212632Sstever@eecs.umich.eduif COMMAND_LINE_TARGETS: 2228268Ssteve.reinhardt@amd.com # Ask SCons which directory it was invoked from 2232632Sstever@eecs.umich.edu launch_dir = GetLaunchDir() 2248268Ssteve.reinhardt@amd.com # Make targets relative to invocation directory 2258268Ssteve.reinhardt@amd.com abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2268268Ssteve.reinhardt@amd.com COMMAND_LINE_TARGETS] 2278268Ssteve.reinhardt@amd.comelse: 2283718Sstever@eecs.umich.edu # Default targets are relative to root of tree 2292634Sstever@eecs.umich.edu abs_targets = [ normpath(joinpath(ROOT, str(x))) for x in \ 2302634Sstever@eecs.umich.edu DEFAULT_TARGETS] 2315863Snate@binkert.org 2322638Sstever@eecs.umich.edu 2338268Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the 2342632Sstever@eecs.umich.edu# collected targets reference. 2352632Sstever@eecs.umich.eduvariant_paths = [] 2362632Sstever@eecs.umich.edubuild_root = None 2372632Sstever@eecs.umich.edufor t in abs_targets: 23812563Sgabeblack@google.com path_dirs = t.split('/') 2391858SN/A try: 2403716Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 2412638Sstever@eecs.umich.edu except: 2422638Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 2432638Sstever@eecs.umich.edu Exit(1) 2442638Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 24512563Sgabeblack@google.com if not build_root: 24612563Sgabeblack@google.com build_root = this_build_root 2472638Sstever@eecs.umich.edu else: 2485863Snate@binkert.org if this_build_root != build_root: 2495863Snate@binkert.org print "Error: build targets not under same build root\n"\ 2505863Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 251955SN/A Exit(1) 2525341Sstever@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 2535341Sstever@gmail.com if variant_path not in variant_paths: 2545863Snate@binkert.org variant_paths.append(variant_path) 2557756SAli.Saidi@ARM.com 2565341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there) 2576121Snate@binkert.orgif not isdir(build_root): 2584494Ssaidi@eecs.umich.edu mkdir(build_root) 2596121Snate@binkert.org 2601105SN/A################################################### 2612667Sstever@eecs.umich.edu# 2622667Sstever@eecs.umich.edu# Set up the default build environment. This environment is copied 2632667Sstever@eecs.umich.edu# and modified according to each selected configuration. 2642667Sstever@eecs.umich.edu# 2656121Snate@binkert.org################################################### 2662667Sstever@eecs.umich.edu 2675341Sstever@gmail.comenv = Environment(ENV = environ, # inherit user's environment vars 2685863Snate@binkert.org ROOT = ROOT, 2695341Sstever@gmail.com SRCDIR = SRCDIR, 2705341Sstever@gmail.com HG_INFO = hg_info) 2715341Sstever@gmail.com 2728120Sgblack@eecs.umich.eduExport('env') 2735341Sstever@gmail.com 2748120Sgblack@eecs.umich.eduenv.SConsignFile(joinpath(build_root, "sconsign")) 2755341Sstever@gmail.com 2768120Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 2776121Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 2786121Snate@binkert.org# file to file~ then copies to file, breaking the link. Symbolic 2799396Sandreas.hansson@arm.com# (soft) links work better. 2805397Ssaidi@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 2815397Ssaidi@eecs.umich.edu 2827727SAli.Saidi@ARM.com# 2838268Ssteve.reinhardt@amd.com# Set up global sticky variables... these are common to an entire build 2846168Snate@binkert.org# tree (not specific to a particular build like ALPHA_SE) 2855341Sstever@gmail.com# 2868120Sgblack@eecs.umich.edu 2878120Sgblack@eecs.umich.edu# Variable validators & converters for global sticky variables 2888120Sgblack@eecs.umich.edudef PathListMakeAbsolute(val): 2896814Sgblack@eecs.umich.edu if not val: 2905863Snate@binkert.org return val 2918120Sgblack@eecs.umich.edu f = lambda p: abspath(expanduser(p)) 2925341Sstever@gmail.com return ':'.join(map(f, val.split(':'))) 2935863Snate@binkert.org 2948268Ssteve.reinhardt@amd.comdef PathListAllExist(key, val, env): 2956121Snate@binkert.org if not val: 2966121Snate@binkert.org return 2978268Ssteve.reinhardt@amd.com paths = val.split(':') 2985742Snate@binkert.org for path in paths: 2995742Snate@binkert.org if not isdir(path): 3005341Sstever@gmail.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3015742Snate@binkert.org 3025742Snate@binkert.orgglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3035341Sstever@gmail.com 3046017Snate@binkert.orgglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3056121Snate@binkert.org 3066017Snate@binkert.orgglobal_sticky_vars.AddVariables( 30712158Sandreas.sandberg@arm.com ('CC', 'C compiler', environ.get('CC', env['CC'])), 30812158Sandreas.sandberg@arm.com ('CXX', 'C++ compiler', environ.get('CXX', env['CXX'])), 30912158Sandreas.sandberg@arm.com ('BATCH', 'Use batch pool for build and tests', False), 3108120Sgblack@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3117756SAli.Saidi@ARM.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3127756SAli.Saidi@ARM.com PathListAllExist, PathListMakeAbsolute) 3137756SAli.Saidi@ARM.com ) 3147756SAli.Saidi@ARM.com 3157816Ssteve.reinhardt@amd.com# base help text 3167816Ssteve.reinhardt@amd.comhelp_text = ''' 3177816Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)] 3187816Ssteve.reinhardt@amd.com 3197816Ssteve.reinhardt@amd.comGlobal sticky options: 32011979Sgabeblack@google.com''' 3217816Ssteve.reinhardt@amd.com 3227816Ssteve.reinhardt@amd.comhelp_text += global_sticky_vars.GenerateHelpText(env) 3237816Ssteve.reinhardt@amd.com 3247816Ssteve.reinhardt@amd.com# Update env with values from ARGUMENTS & file global_sticky_vars_file 3257756SAli.Saidi@ARM.comglobal_sticky_vars.Update(env) 3267756SAli.Saidi@ARM.com 3279227Sandreas.hansson@arm.com# Save sticky variable settings back to current variables file 3289227Sandreas.hansson@arm.comglobal_sticky_vars.Save(global_sticky_vars_file, env) 3299227Sandreas.hansson@arm.com 3309227Sandreas.hansson@arm.com# Parse EXTRAS variable to build list of all directories where we're 3319590Sandreas@sandberg.pp.se# look for sources etc. This list is exported as base_dir_list. 3329590Sandreas@sandberg.pp.sebase_dir = joinpath(ROOT, 'src') 3339590Sandreas@sandberg.pp.seif env['EXTRAS']: 3349590Sandreas@sandberg.pp.se extras_dir_list = env['EXTRAS'].split(':') 3359590Sandreas@sandberg.pp.seelse: 3369590Sandreas@sandberg.pp.se extras_dir_list = [] 3376654Snate@binkert.org 3386654Snate@binkert.orgExport('base_dir') 3395871Snate@binkert.orgExport('extras_dir_list') 3406121Snate@binkert.org 3418946Sandreas.hansson@arm.com# M5_PLY is used by isa_parser.py to find the PLY package. 3429419Sandreas.hansson@arm.comenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 34312563Sgabeblack@google.comenv['GCC'] = read_command(env['CXX'] + ' --version').find('g++') >= 0 3443918Ssaidi@eecs.umich.eduenv['SUNCC'] = read_command(env['CXX'] + ' -V').find('Sun C++') >= 0 3453918Ssaidi@eecs.umich.eduenv['ICC'] = read_command(env['CXX'] + ' -V').find('Intel') >= 0 3461858SN/Aif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3479556Sandreas.hansson@arm.com print 'Error: How can we have two at the same time?' 3489556Sandreas.hansson@arm.com Exit(1) 3499556Sandreas.hansson@arm.com 3509556Sandreas.hansson@arm.com# Set up default C++ compiler flags 35111294Sandreas.hansson@arm.comif env['GCC']: 35211294Sandreas.hansson@arm.com env.Append(CCFLAGS='-pipe') 35311294Sandreas.hansson@arm.com env.Append(CCFLAGS='-fno-strict-aliasing') 35411294Sandreas.hansson@arm.com env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 35510878Sandreas.hansson@arm.com env.Append(CXXFLAGS='-Wno-deprecated') 35610878Sandreas.hansson@arm.comelif env['ICC']: 35711811Sbaz21@cam.ac.uk pass #Fix me... add warning flags once we clean up icc warnings 35811811Sbaz21@cam.ac.ukelif env['SUNCC']: 35911811Sbaz21@cam.ac.uk env.Append(CCFLAGS='-Qoption ccfe') 36011982Sgabeblack@google.com env.Append(CCFLAGS='-features=gcc') 36111982Sgabeblack@google.com env.Append(CCFLAGS='-features=extensions') 36211982Sgabeblack@google.com env.Append(CCFLAGS='-library=stlport4') 36313421Sciro.santilli@arm.com env.Append(CCFLAGS='-xar') 36413421Sciro.santilli@arm.com# env.Append(CCFLAGS='-instances=semiexplicit') 36511982Sgabeblack@google.comelse: 36611992Sgabeblack@google.com print 'Error: Don\'t know what compiler options to use for your compiler.' 36711982Sgabeblack@google.com print ' Please fix SConstruct and src/SConscript and try again.' 36811982Sgabeblack@google.com Exit(1) 36912305Sgabeblack@google.com 37012305Sgabeblack@google.com# Do this after we save setting back, or else we'll tack on an 37112305Sgabeblack@google.com# extra 'qdo' every time we run scons. 37212305Sgabeblack@google.comif env['BATCH']: 37312305Sgabeblack@google.com env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 37412305Sgabeblack@google.com env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 37512305Sgabeblack@google.com env['AS'] = env['BATCH_CMD'] + ' ' + env['AS'] 3769556Sandreas.hansson@arm.com env['AR'] = env['BATCH_CMD'] + ' ' + env['AR'] 37712563Sgabeblack@google.com env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB'] 37812563Sgabeblack@google.com 37912563Sgabeblack@google.comif sys.platform == 'cygwin': 38012563Sgabeblack@google.com # cygwin has some header file issues... 3819556Sandreas.hansson@arm.com env.Append(CCFLAGS=Split("-Wno-uninitialized")) 38212563Sgabeblack@google.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 38312563Sgabeblack@google.com 3849556Sandreas.hansson@arm.com# Check for SWIG 38512563Sgabeblack@google.comif not env.has_key('SWIG'): 38612563Sgabeblack@google.com print 'Error: SWIG utility not found.' 38712563Sgabeblack@google.com print ' Please install (see http://www.swig.org) and retry.' 38812563Sgabeblack@google.com Exit(1) 38912563Sgabeblack@google.com 39012563Sgabeblack@google.com# Check for appropriate SWIG version 39112563Sgabeblack@google.comswig_version = read_command('swig -version').split() 39212563Sgabeblack@google.com# First 3 words should be "SWIG Version x.y.z" 3939556Sandreas.hansson@arm.comif len(swig_version) < 3 or \ 3949556Sandreas.hansson@arm.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 3956121Snate@binkert.org print 'Error determining SWIG version.' 39611500Sandreas.hansson@arm.com Exit(1) 39710238Sandreas.hansson@arm.com 39810878Sandreas.hansson@arm.commin_swig_version = '1.3.28' 3999420Sandreas.hansson@arm.comif compare_versions(swig_version[2], min_swig_version) < 0: 40011500Sandreas.hansson@arm.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 40112563Sgabeblack@google.com print ' Installed version:', swig_version[2] 40212563Sgabeblack@google.com Exit(1) 4039420Sandreas.hansson@arm.com 4049420Sandreas.hansson@arm.com# Set up SWIG flags & scanner 4059420Sandreas.hansson@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4069420Sandreas.hansson@arm.comenv.Append(SWIGFLAGS=swig_flags) 40712063Sgabeblack@google.com 40812063Sgabeblack@google.com# filter out all existing swig scanners, they mess up the dependency 40912063Sgabeblack@google.com# stuff for some reason 41012063Sgabeblack@google.comscanners = [] 41112063Sgabeblack@google.comfor scanner in env['SCANNERS']: 41212063Sgabeblack@google.com skeys = scanner.skeys 41312063Sgabeblack@google.com if skeys == '.i': 41412063Sgabeblack@google.com continue 41512063Sgabeblack@google.com 41612063Sgabeblack@google.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 41712063Sgabeblack@google.com continue 41812063Sgabeblack@google.com 41912063Sgabeblack@google.com scanners.append(scanner) 42012063Sgabeblack@google.com 42112063Sgabeblack@google.com# add the new swig scanner that we like better 42212063Sgabeblack@google.comfrom SCons.Scanner import ClassicCPP as CPPScanner 42312063Sgabeblack@google.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 42412063Sgabeblack@google.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 42512063Sgabeblack@google.com 42612063Sgabeblack@google.com# replace the scanners list that has what we want 42712063Sgabeblack@google.comenv['SCANNERS'] = scanners 42812063Sgabeblack@google.com 42910457Sandreas.hansson@arm.com# Add a custom Check function to the Configure context so that we can 43010457Sandreas.hansson@arm.com# figure out if the compiler adds leading underscores to global 43110457Sandreas.hansson@arm.com# variables. This is needed for the autogenerated asm files that we 43210457Sandreas.hansson@arm.com# use for embedding the python code. 43310457Sandreas.hansson@arm.comdef CheckLeading(context): 43412563Sgabeblack@google.com context.Message("Checking for leading underscore in global variables...") 43512563Sgabeblack@google.com # 1) Define a global variable called x from asm so the C compiler 43612563Sgabeblack@google.com # won't change the symbol at all. 43710457Sandreas.hansson@arm.com # 2) Declare that variable. 43812063Sgabeblack@google.com # 3) Use the variable 43912063Sgabeblack@google.com # 44012063Sgabeblack@google.com # If the compiler prepends an underscore, this will successfully 44112563Sgabeblack@google.com # link because the external symbol 'x' will be called '_x' which 44212563Sgabeblack@google.com # was defined by the asm statement. If the compiler does not 44312563Sgabeblack@google.com # prepend an underscore, this will not successfully link because 44412563Sgabeblack@google.com # '_x' will have been defined by assembly, while the C portion of 44512563Sgabeblack@google.com # the code will be trying to use 'x' 44612563Sgabeblack@google.com ret = context.TryLink(''' 44712063Sgabeblack@google.com asm(".globl _x; _x: .byte 0"); 44812063Sgabeblack@google.com extern int x; 44910238Sandreas.hansson@arm.com int main() { return x; } 45010238Sandreas.hansson@arm.com ''', extension=".c") 45110238Sandreas.hansson@arm.com context.env.Append(LEADING_UNDERSCORE=ret) 45212063Sgabeblack@google.com context.Result(ret) 45310238Sandreas.hansson@arm.com return ret 45410238Sandreas.hansson@arm.com 45510416Sandreas.hansson@arm.com# Platform-specific configuration. Note again that we assume that all 45610238Sandreas.hansson@arm.com# builds under a given build root run on the same host platform. 4579227Sandreas.hansson@arm.comconf = Configure(env, 45810238Sandreas.hansson@arm.com conf_dir = joinpath(build_root, '.scons_config'), 45910416Sandreas.hansson@arm.com log_file = joinpath(build_root, 'scons_config.log'), 46010416Sandreas.hansson@arm.com custom_tests = { 'CheckLeading' : CheckLeading }) 4619227Sandreas.hansson@arm.com 4629590Sandreas@sandberg.pp.se# Check for leading underscores. Don't really need to worry either 4639590Sandreas@sandberg.pp.se# way so don't need to check the return code. 4649590Sandreas@sandberg.pp.seconf.CheckLeading() 46512304Sgabeblack@google.com 46612304Sgabeblack@google.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 46712304Sgabeblack@google.comtry: 46812688Sgiacomo.travaglini@arm.com import platform 46912688Sgiacomo.travaglini@arm.com uname = platform.uname() 47012688Sgiacomo.travaglini@arm.com if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 47113020Sshunhsingou@google.com if int(read_command('sysctl -n hw.cpu64bit_capable')[0]): 47212304Sgabeblack@google.com env.Append(CCFLAGS='-arch x86_64') 47312688Sgiacomo.travaglini@arm.com env.Append(CFLAGS='-arch x86_64') 47412688Sgiacomo.travaglini@arm.com env.Append(LINKFLAGS='-arch x86_64') 47513020Sshunhsingou@google.com env.Append(ASFLAGS='-arch x86_64') 47612304Sgabeblack@google.comexcept: 47712304Sgabeblack@google.com pass 47812304Sgabeblack@google.com 47912304Sgabeblack@google.com# Recent versions of scons substitute a "Null" object for Configure() 48012688Sgiacomo.travaglini@arm.com# when configuration isn't necessary, e.g., if the "--help" option is 48112688Sgiacomo.travaglini@arm.com# present. Unfortuantely this Null object always returns false, 48212688Sgiacomo.travaglini@arm.com# breaking all our configuration checks. We replace it with our own 48312304Sgabeblack@google.com# more optimistic null object that returns True instead. 4848737Skoansin.tan@gmail.comif not conf: 48510878Sandreas.hansson@arm.com def NullCheck(*args, **kwargs): 48611500Sandreas.hansson@arm.com return True 4879420Sandreas.hansson@arm.com 4888737Skoansin.tan@gmail.com class NullConf: 48910106SMitch.Hayenga@arm.com def __init__(self, env): 4908737Skoansin.tan@gmail.com self.env = env 4918737Skoansin.tan@gmail.com def Finish(self): 49210878Sandreas.hansson@arm.com return self.env 49312563Sgabeblack@google.com def __getattr__(self, mname): 49412563Sgabeblack@google.com return NullCheck 4958737Skoansin.tan@gmail.com 4968737Skoansin.tan@gmail.com conf = NullConf(env) 49712563Sgabeblack@google.com 4988737Skoansin.tan@gmail.com# Find Python include and library directories for embedding the 4998737Skoansin.tan@gmail.com# interpreter. For consistency, we will use the same Python 50011294Sandreas.hansson@arm.com# installation used to run scons (and thus this script). If you want 5019556Sandreas.hansson@arm.com# to link in an alternate version, see above for instructions on how 5029556Sandreas.hansson@arm.com# to invoke scons with a different copy of the Python interpreter. 5039556Sandreas.hansson@arm.comfrom distutils import sysconfig 50411294Sandreas.hansson@arm.com 50510278SAndreas.Sandberg@ARM.compy_getvar = sysconfig.get_config_var 50610278SAndreas.Sandberg@ARM.com 50710278SAndreas.Sandberg@ARM.compy_version = 'python' + py_getvar('VERSION') 50810278SAndreas.Sandberg@ARM.com 50910278SAndreas.Sandberg@ARM.compy_general_include = sysconfig.get_python_inc() 51010278SAndreas.Sandberg@ARM.compy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5119556Sandreas.hansson@arm.compy_includes = [ py_general_include ] 5129590Sandreas@sandberg.pp.seif py_platform_include != py_general_include: 5139590Sandreas@sandberg.pp.se py_includes.append(py_platform_include) 5149420Sandreas.hansson@arm.com 5159846Sandreas.hansson@arm.compy_lib_path = [] 5169846Sandreas.hansson@arm.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5179846Sandreas.hansson@arm.com# shared library in prefix/lib/. 5189846Sandreas.hansson@arm.comif not py_getvar('Py_ENABLE_SHARED'): 5198946Sandreas.hansson@arm.com py_lib_path.append('-L' + py_getvar('LIBPL')) 52011811Sbaz21@cam.ac.uk 52111811Sbaz21@cam.ac.ukpy_libs = [] 52211811Sbaz21@cam.ac.ukfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 52311811Sbaz21@cam.ac.uk if lib not in py_libs: 52412304Sgabeblack@google.com py_libs.append(lib) 52512304Sgabeblack@google.compy_libs.append('-l' + py_version) 52612304Sgabeblack@google.com 52712304Sgabeblack@google.comenv.Append(CPPPATH=py_includes) 52813020Sshunhsingou@google.comenv.Append(LIBPATH=py_lib_path) 52913020Sshunhsingou@google.com#env.Append(LIBS=py_libs) 53012304Sgabeblack@google.com 53112304Sgabeblack@google.com# verify that this stuff works 53213020Sshunhsingou@google.comif not conf.CheckHeader('Python.h', '<>'): 53313020Sshunhsingou@google.com print "Error: can't find Python.h header in", py_includes 53412304Sgabeblack@google.com Exit(1) 53512304Sgabeblack@google.com 53613020Sshunhsingou@google.comfor lib in py_libs: 53713020Sshunhsingou@google.com assert lib.startswith('-l') 53812304Sgabeblack@google.com lib = lib[2:] 53912304Sgabeblack@google.com if not conf.CheckLib(lib): 5403918Ssaidi@eecs.umich.edu print "Error: can't find library %s required by python" % lib 54112563Sgabeblack@google.com Exit(1) 54212563Sgabeblack@google.com 54312563Sgabeblack@google.com# On Solaris you need to use libsocket for socket ops 54412563Sgabeblack@google.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5459068SAli.Saidi@ARM.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 54612563Sgabeblack@google.com print "Can't find library with socket calls (e.g. accept())" 54712563Sgabeblack@google.com Exit(1) 5489068SAli.Saidi@ARM.com 54912563Sgabeblack@google.com# Check for zlib. If the check passes, libz will be automatically 55012563Sgabeblack@google.com# added to the LIBS environment variable. 55112563Sgabeblack@google.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 55212563Sgabeblack@google.com print 'Error: did not find needed zlib compression library '\ 55312563Sgabeblack@google.com 'and/or zlib.h header file.' 55412563Sgabeblack@google.com print ' Please install zlib and try again.' 55512563Sgabeblack@google.com Exit(1) 55612563Sgabeblack@google.com 5573918Ssaidi@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 5583918Ssaidi@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 5596157Snate@binkert.orgif not have_fenv: 5606157Snate@binkert.org print "Warning: Header file <fenv.h> not found." 5616157Snate@binkert.org print " This host has no IEEE FP rounding mode control." 5626157Snate@binkert.org 5635397Ssaidi@eecs.umich.edu###################################################################### 5645397Ssaidi@eecs.umich.edu# 5656121Snate@binkert.org# Check for mysql. 5666121Snate@binkert.org# 5676121Snate@binkert.orgmysql_config = WhereIs('mysql_config') 5686121Snate@binkert.orghave_mysql = bool(mysql_config) 5696121Snate@binkert.org 5706121Snate@binkert.org# Check MySQL version. 5715397Ssaidi@eecs.umich.eduif have_mysql: 5721851SN/A mysql_version = read_command(mysql_config + ' --version') 5731851SN/A min_mysql_version = '4.1' 5747739Sgblack@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 575955SN/A print 'Warning: MySQL', min_mysql_version, 'or newer required.' 5769396Sandreas.hansson@arm.com print ' Version', mysql_version, 'detected.' 5779396Sandreas.hansson@arm.com have_mysql = False 5789396Sandreas.hansson@arm.com 5799396Sandreas.hansson@arm.com# Set up mysql_config commands. 5809396Sandreas.hansson@arm.comif have_mysql: 5819396Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --include' 58212563Sgabeblack@google.com if os.system(mysql_config_include + ' > /dev/null') != 0: 58312563Sgabeblack@google.com # older mysql_config versions don't support --include, use 58412563Sgabeblack@google.com # --cflags instead 58512563Sgabeblack@google.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 5869396Sandreas.hansson@arm.com # This seems to work in all versions 5879396Sandreas.hansson@arm.com mysql_config_libs = mysql_config + ' --libs' 5889396Sandreas.hansson@arm.com 5899396Sandreas.hansson@arm.com###################################################################### 5909396Sandreas.hansson@arm.com# 5919396Sandreas.hansson@arm.com# Finish the configuration 59212563Sgabeblack@google.com# 59312563Sgabeblack@google.comenv = conf.Finish() 59412563Sgabeblack@google.com 59512563Sgabeblack@google.com###################################################################### 59612563Sgabeblack@google.com# 5979477Sandreas.hansson@arm.com# Collect all non-global variables 5989477Sandreas.hansson@arm.com# 5999477Sandreas.hansson@arm.com 6009477Sandreas.hansson@arm.com# Define the universe of supported ISAs 6019477Sandreas.hansson@arm.comall_isa_list = [ ] 6029477Sandreas.hansson@arm.comExport('all_isa_list') 6039477Sandreas.hansson@arm.com 6049477Sandreas.hansson@arm.com# Define the universe of supported CPU models 6059477Sandreas.hansson@arm.comall_cpu_list = [ ] 6069477Sandreas.hansson@arm.comdefault_cpus = [ ] 6079477Sandreas.hansson@arm.comExport('all_cpu_list', 'default_cpus') 6089477Sandreas.hansson@arm.com 6099477Sandreas.hansson@arm.com# Sticky variables get saved in the variables file so they persist from 6109477Sandreas.hansson@arm.com# one invocation to the next (unless overridden, in which case the new 61112563Sgabeblack@google.com# value becomes sticky). 61212563Sgabeblack@google.comsticky_vars = Variables(args=ARGUMENTS) 61312563Sgabeblack@google.comExport('sticky_vars') 6149396Sandreas.hansson@arm.com 6152667Sstever@eecs.umich.edu# Non-sticky variables only apply to the current build. 61610710Sandreas.hansson@arm.comnonsticky_vars = Variables(args=ARGUMENTS) 61710710Sandreas.hansson@arm.comExport('nonsticky_vars') 61810710Sandreas.hansson@arm.com 61911811Sbaz21@cam.ac.uk# Walk the tree and execute all SConsopts scripts that wil add to the 62011811Sbaz21@cam.ac.uk# above variables 62111811Sbaz21@cam.ac.ukfor bdir in [ base_dir ] + extras_dir_list: 62211811Sbaz21@cam.ac.uk for root, dirs, files in os.walk(bdir): 62311811Sbaz21@cam.ac.uk if 'SConsopts' in files: 62411811Sbaz21@cam.ac.uk print "Reading", joinpath(root, 'SConsopts') 62510710Sandreas.hansson@arm.com SConscript(joinpath(root, 'SConsopts')) 62610710Sandreas.hansson@arm.com 62710710Sandreas.hansson@arm.comall_isa_list.sort() 62810710Sandreas.hansson@arm.comall_cpu_list.sort() 62910384SCurtis.Dunham@arm.comdefault_cpus.sort() 6309986Sandreas@sandberg.pp.se 6319986Sandreas@sandberg.pp.sesticky_vars.AddVariables( 6329986Sandreas@sandberg.pp.se EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6339986Sandreas@sandberg.pp.se BoolVariable('FULL_SYSTEM', 'Full-system support', False), 6349986Sandreas@sandberg.pp.se ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 6359986Sandreas@sandberg.pp.se BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6369986Sandreas@sandberg.pp.se BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6379986Sandreas@sandberg.pp.se False), 6389986Sandreas@sandberg.pp.se BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6399986Sandreas@sandberg.pp.se False), 6409986Sandreas@sandberg.pp.se BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 6419986Sandreas@sandberg.pp.se False), 6429986Sandreas@sandberg.pp.se BoolVariable('SS_COMPATIBLE_FP', 6439986Sandreas@sandberg.pp.se 'Make floating-point results compatible with SimpleScalar', 6449986Sandreas@sandberg.pp.se False), 6459986Sandreas@sandberg.pp.se BoolVariable('USE_SSE2', 6469986Sandreas@sandberg.pp.se 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 6479986Sandreas@sandberg.pp.se False), 6489986Sandreas@sandberg.pp.se BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6499986Sandreas@sandberg.pp.se BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6502638Sstever@eecs.umich.edu BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 6512638Sstever@eecs.umich.edu ) 6526121Snate@binkert.org 6533716Sstever@eecs.umich.edunonsticky_vars.AddVariables( 6545522Snate@binkert.org BoolVariable('update_ref', 'Update test reference outputs', False) 6559986Sandreas@sandberg.pp.se ) 6569986Sandreas@sandberg.pp.se 6579986Sandreas@sandberg.pp.se# These variables get exported to #defines in config/*.hh (see src/SConscript). 6585522Snate@binkert.orgenv.ExportVariables = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 6595227Ssaidi@eecs.umich.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 6605227Ssaidi@eecs.umich.edu 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 6615227Ssaidi@eecs.umich.edu 'USE_CHECKER', 'TARGET_ISA'] 6625227Ssaidi@eecs.umich.edu 6636654Snate@binkert.org################################################### 6646654Snate@binkert.org# 6657769SAli.Saidi@ARM.com# Define a SCons builder for configuration flag headers. 6667769SAli.Saidi@ARM.com# 6677769SAli.Saidi@ARM.com################################################### 6687769SAli.Saidi@ARM.com 6695227Ssaidi@eecs.umich.edu# This function generates a config header file that #defines the 6705227Ssaidi@eecs.umich.edu# variable symbol to the current variable setting (0 or 1). The source 6715227Ssaidi@eecs.umich.edu# operands are the name of the variable and a Value node containing the 6725204Sstever@gmail.com# value of the variable. 6735204Sstever@gmail.comdef build_config_file(target, source, env): 6745204Sstever@gmail.com (variable, value) = [s.get_contents() for s in source] 6755204Sstever@gmail.com f = file(str(target[0]), 'w') 6765204Sstever@gmail.com print >> f, '#define', variable, value 6775204Sstever@gmail.com f.close() 6785204Sstever@gmail.com return None 6795204Sstever@gmail.com 6805204Sstever@gmail.com# Generate the message to be printed when building the config file. 6815204Sstever@gmail.comdef build_config_file_string(target, source, env): 6825204Sstever@gmail.com (variable, value) = [s.get_contents() for s in source] 6835204Sstever@gmail.com return "Defining %s as %s in %s." % (variable, value, target[0]) 6845204Sstever@gmail.com 6855204Sstever@gmail.com# Combine the two functions into a scons Action object. 6865204Sstever@gmail.comconfig_action = Action(build_config_file, build_config_file_string) 6875204Sstever@gmail.com 6885204Sstever@gmail.com# The emitter munges the source & target node lists to reflect what 6896121Snate@binkert.org# we're really doing. 6905204Sstever@gmail.comdef config_emitter(target, source, env): 6917727SAli.Saidi@ARM.com # extract variable name from Builder arg 6927727SAli.Saidi@ARM.com variable = str(target[0]) 69312563Sgabeblack@google.com # True target is config header file 6947727SAli.Saidi@ARM.com target = joinpath('config', variable.lower() + '.hh') 6957727SAli.Saidi@ARM.com val = env[variable] 69611988Sandreas.sandberg@arm.com if isinstance(val, bool): 69711988Sandreas.sandberg@arm.com # Force value to 0/1 69810453SAndrew.Bardsley@arm.com val = int(val) 69910453SAndrew.Bardsley@arm.com elif isinstance(val, str): 70010453SAndrew.Bardsley@arm.com val = '"' + val + '"' 70110453SAndrew.Bardsley@arm.com 70210453SAndrew.Bardsley@arm.com # Sources are variable name & value (packaged in SCons Value nodes) 70310453SAndrew.Bardsley@arm.com return ([target], [Value(variable), Value(val)]) 70410453SAndrew.Bardsley@arm.com 70510453SAndrew.Bardsley@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 70610453SAndrew.Bardsley@arm.com 70710453SAndrew.Bardsley@arm.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 70810160Sandreas.hansson@arm.com 70910453SAndrew.Bardsley@arm.com# libelf build is shared across all configs in the build root. 71010453SAndrew.Bardsley@arm.comenv.SConscript('ext/libelf/SConscript', 71110453SAndrew.Bardsley@arm.com variant_dir = joinpath(build_root, 'libelf'), 71210453SAndrew.Bardsley@arm.com exports = 'env') 71310453SAndrew.Bardsley@arm.com 71413541Sandrea.mondelli@ucf.edu# gzstream build is shared across all configs in the build root. 71510453SAndrew.Bardsley@arm.comenv.SConscript('ext/gzstream/SConscript', 71610453SAndrew.Bardsley@arm.com variant_dir = joinpath(build_root, 'gzstream'), 71713541Sandrea.mondelli@ucf.edu exports = 'env') 71813541Sandrea.mondelli@ucf.edu 7199812Sandreas.hansson@arm.com################################################### 72010453SAndrew.Bardsley@arm.com# 72110453SAndrew.Bardsley@arm.com# This function is used to set up a directory with switching headers 72210453SAndrew.Bardsley@arm.com# 72310453SAndrew.Bardsley@arm.com################################################### 72410453SAndrew.Bardsley@arm.com 72510453SAndrew.Bardsley@arm.comenv['ALL_ISA_LIST'] = all_isa_list 72610453SAndrew.Bardsley@arm.comdef make_switching_dir(dname, switch_headers, env): 72710453SAndrew.Bardsley@arm.com # Generate the header. target[0] is the full path of the output 72810453SAndrew.Bardsley@arm.com # header to generate. 'source' is a dummy variable, since we get the 72910453SAndrew.Bardsley@arm.com # list of ISAs from env['ALL_ISA_LIST']. 73010453SAndrew.Bardsley@arm.com def gen_switch_hdr(target, source, env): 73110453SAndrew.Bardsley@arm.com fname = str(target[0]) 7327727SAli.Saidi@ARM.com bname = basename(fname) 73310453SAndrew.Bardsley@arm.com f = open(fname, 'w') 73410453SAndrew.Bardsley@arm.com f.write('#include "arch/isa_specific.hh"\n') 73512790Smatteo.fusi@bsc.es cond = '#if' 73612790Smatteo.fusi@bsc.es for isa in all_isa_list: 73712790Smatteo.fusi@bsc.es f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 73812790Smatteo.fusi@bsc.es % (cond, isa.upper(), dname, isa, bname)) 73912790Smatteo.fusi@bsc.es cond = '#elif' 74012790Smatteo.fusi@bsc.es f.write('#else\n#error "THE_ISA not set"\n#endif\n') 74112790Smatteo.fusi@bsc.es f.close() 74210453SAndrew.Bardsley@arm.com return 0 7433118Sstever@eecs.umich.edu 74410453SAndrew.Bardsley@arm.com # String to print when generating header 74510453SAndrew.Bardsley@arm.com def gen_switch_hdr_string(target, source, env): 74612563Sgabeblack@google.com return "Generating switch header " + str(target[0]) 74710453SAndrew.Bardsley@arm.com 7483118Sstever@eecs.umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 7493483Ssaidi@eecs.umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 7503494Ssaidi@eecs.umich.edu # should get re-executed. 7513494Ssaidi@eecs.umich.edu switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 75212563Sgabeblack@google.com varlist=['ALL_ISA_LIST']) 7533483Ssaidi@eecs.umich.edu 7543483Ssaidi@eecs.umich.edu # Instantiate actions for each header 7553053Sstever@eecs.umich.edu for hdr in switch_headers: 7563053Sstever@eecs.umich.edu env.Command(hdr, [], switch_hdr_action) 7573918Ssaidi@eecs.umich.eduExport('make_switching_dir') 75812563Sgabeblack@google.com 75912563Sgabeblack@google.com################################################### 76012563Sgabeblack@google.com# 7613053Sstever@eecs.umich.edu# Define build environments for selected configurations. 7623053Sstever@eecs.umich.edu# 7639396Sandreas.hansson@arm.com################################################### 7649396Sandreas.hansson@arm.com 7659396Sandreas.hansson@arm.com# rename base env 7669396Sandreas.hansson@arm.combase_env = env 7679396Sandreas.hansson@arm.com 7689396Sandreas.hansson@arm.comfor variant_path in variant_paths: 7699396Sandreas.hansson@arm.com print "Building in", variant_path 7709396Sandreas.hansson@arm.com 7719396Sandreas.hansson@arm.com # Make a copy of the build-root environment to use for this config. 77212920Sgabeblack@google.com env = base_env.Clone() 77312920Sgabeblack@google.com env['BUILDDIR'] = variant_path 77412920Sgabeblack@google.com 77512920Sgabeblack@google.com # variant_dir is the tail component of build path, and is used to 7769477Sandreas.hansson@arm.com # determine the build parameters (e.g., 'ALPHA_SE') 7779396Sandreas.hansson@arm.com (build_root, variant_dir) = splitpath(variant_path) 77812563Sgabeblack@google.com 77912563Sgabeblack@google.com # Set env variables according to the build directory config. 78012563Sgabeblack@google.com sticky_vars.files = [] 78112563Sgabeblack@google.com # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 7829396Sandreas.hansson@arm.com # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 7837840Snate@binkert.org # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 7847865Sgblack@eecs.umich.edu current_vars_file = joinpath(build_root, 'variables', variant_dir) 7857865Sgblack@eecs.umich.edu if isfile(current_vars_file): 7867865Sgblack@eecs.umich.edu sticky_vars.files.append(current_vars_file) 7877865Sgblack@eecs.umich.edu print "Using saved variables file %s" % current_vars_file 7887865Sgblack@eecs.umich.edu else: 7897840Snate@binkert.org # Build dir-specific variables file doesn't exist. 7909900Sandreas@sandberg.pp.se 7919900Sandreas@sandberg.pp.se # Make sure the directory is there so we can create it later 7929900Sandreas@sandberg.pp.se opt_dir = dirname(current_vars_file) 7939900Sandreas@sandberg.pp.se if not isdir(opt_dir): 79410456SCurtis.Dunham@arm.com mkdir(opt_dir) 79510456SCurtis.Dunham@arm.com 79610456SCurtis.Dunham@arm.com # Get default build variables from source tree. Variables are 79710456SCurtis.Dunham@arm.com # normally determined by name of $VARIANT_DIR, but can be 79810456SCurtis.Dunham@arm.com # overriden by 'default=' arg on command line. 79910456SCurtis.Dunham@arm.com default_vars_file = joinpath('build_opts', 80012563Sgabeblack@google.com ARGUMENTS.get('default', variant_dir)) 80112563Sgabeblack@google.com if isfile(default_vars_file): 80212563Sgabeblack@google.com sticky_vars.files.append(default_vars_file) 80312563Sgabeblack@google.com print "Variables file %s not found,\n using defaults in %s" \ 8049045SAli.Saidi@ARM.com % (current_vars_file, default_vars_file) 80511235Sandreas.sandberg@arm.com else: 80611235Sandreas.sandberg@arm.com print "Error: cannot find variables file %s or %s" \ 80711235Sandreas.sandberg@arm.com % (current_vars_file, default_vars_file) 80811235Sandreas.sandberg@arm.com Exit(1) 80911235Sandreas.sandberg@arm.com 81012485Sjang.hanhwi@gmail.com # Apply current variable settings to env 81112485Sjang.hanhwi@gmail.com sticky_vars.Update(env) 81212485Sjang.hanhwi@gmail.com nonsticky_vars.Update(env) 81311235Sandreas.sandberg@arm.com 81411811Sbaz21@cam.ac.uk help_text += "\nSticky variables for %s:\n" % variant_dir \ 81512485Sjang.hanhwi@gmail.com + sticky_vars.GenerateHelpText(env) \ 81611811Sbaz21@cam.ac.uk + "\nNon-sticky variables for %s:\n" % variant_dir \ 81711811Sbaz21@cam.ac.uk + nonsticky_vars.GenerateHelpText(env) 81811811Sbaz21@cam.ac.uk 81911235Sandreas.sandberg@arm.com # Process variable settings. 82011235Sandreas.sandberg@arm.com 82111235Sandreas.sandberg@arm.com if not have_fenv and env['USE_FENV']: 82212563Sgabeblack@google.com print "Warning: <fenv.h> not available; " \ 82312563Sgabeblack@google.com "forcing USE_FENV to False in", variant_dir + "." 82412563Sgabeblack@google.com env['USE_FENV'] = False 82511235Sandreas.sandberg@arm.com 8267840Snate@binkert.org if not env['USE_FENV']: 82712563Sgabeblack@google.com print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 8287840Snate@binkert.org print " FP results may deviate slightly from other platforms." 8291858SN/A 8301858SN/A if env['EFENCE']: 8311858SN/A env.Append(LIBS=['efence']) 83212563Sgabeblack@google.com 83312563Sgabeblack@google.com if env['USE_MYSQL']: 8341858SN/A if not have_mysql: 83512230Sgiacomo.travaglini@arm.com print "Warning: MySQL not available; " \ 83612230Sgiacomo.travaglini@arm.com "forcing USE_MYSQL to False in", variant_dir + "." 83712230Sgiacomo.travaglini@arm.com env['USE_MYSQL'] = False 83812230Sgiacomo.travaglini@arm.com else: 83912563Sgabeblack@google.com print "Compiling in", variant_dir, "with MySQL support." 84012563Sgabeblack@google.com env.ParseConfig(mysql_config_libs) 84112563Sgabeblack@google.com env.ParseConfig(mysql_config_include) 84212230Sgiacomo.travaglini@arm.com 8439903Sandreas.hansson@arm.com # Save sticky variable settings back to current variables file 8449903Sandreas.hansson@arm.com sticky_vars.Save(current_vars_file, env) 8459903Sandreas.hansson@arm.com 8469903Sandreas.hansson@arm.com if env['USE_SSE2']: 84710841Sandreas.sandberg@arm.com env.Append(CCFLAGS='-msse2') 8489651SAndreas.Sandberg@ARM.com 84912563Sgabeblack@google.com # The src/SConscript file sets up the build rules in 'env' according 85012563Sgabeblack@google.com # to the configured variables. It returns a list of environments, 8519651SAndreas.Sandberg@ARM.com # one for each variant build (debug, opt, etc.) 85212056Sgabeblack@google.com envList = SConscript('src/SConscript', variant_dir = variant_path, 85312056Sgabeblack@google.com exports = 'env') 85412056Sgabeblack@google.com 85512563Sgabeblack@google.com # Set up the regression tests for each build. 85612056Sgabeblack@google.com for e in envList: 85710841Sandreas.sandberg@arm.com SConscript('tests/SConscript', 85810841Sandreas.sandberg@arm.com variant_dir = joinpath(variant_path, 'tests', e.Label), 85910841Sandreas.sandberg@arm.com exports = { 'env' : e }, duplicate = False) 86010841Sandreas.sandberg@arm.com 86110841Sandreas.sandberg@arm.comHelp(help_text) 86210841Sandreas.sandberg@arm.com 8639651SAndreas.Sandberg@ARM.com 8649651SAndreas.Sandberg@ARM.com################################################### 8659651SAndreas.Sandberg@ARM.com# 8669651SAndreas.Sandberg@ARM.com# Let SCons do its thing. At this point SCons will use the defined 8679651SAndreas.Sandberg@ARM.com# build environments to build the requested targets. 8689651SAndreas.Sandberg@ARM.com# 86912563Sgabeblack@google.com################################################### 8709651SAndreas.Sandberg@ARM.com 8719651SAndreas.Sandberg@ARM.com