SConstruct revision 6157
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: 9513541Sandrea.mondelli@ucf.edu http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 96955SN/A""" 976654Snate@binkert.org raise 985273Sstever@gmail.com 995871Snate@binkert.orgimport os 1005273Sstever@gmail.comimport re 1016654Snate@binkert.orgimport subprocess 1025396Ssaidi@eecs.umich.eduimport sys 1038120Sgblack@eecs.umich.edu 1048120Sgblack@eecs.umich.edufrom os import mkdir, environ 1058120Sgblack@eecs.umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath 1068120Sgblack@eecs.umich.edufrom os.path import exists, isdir, isfile 1078120Sgblack@eecs.umich.edufrom os.path import join as joinpath, split as splitpath 1088120Sgblack@eecs.umich.edu 1098120Sgblack@eecs.umich.eduimport SCons 1108120Sgblack@eecs.umich.eduimport SCons.Node 1118879Ssteve.reinhardt@amd.com 1128879Ssteve.reinhardt@amd.comdef read_command(cmd, **kwargs): 1138879Ssteve.reinhardt@amd.com """run the command cmd, read the results and return them 1148879Ssteve.reinhardt@amd.com this is sorta like `cmd` in shell""" 1158879Ssteve.reinhardt@amd.com from subprocess import Popen, PIPE, STDOUT 1168879Ssteve.reinhardt@amd.com 1178879Ssteve.reinhardt@amd.com if isinstance(cmd, str): 1188879Ssteve.reinhardt@amd.com cmd = cmd.split() 1198879Ssteve.reinhardt@amd.com 1208879Ssteve.reinhardt@amd.com no_exception = 'exception' in kwargs 1218879Ssteve.reinhardt@amd.com exception = kwargs.pop('exception', None) 1228879Ssteve.reinhardt@amd.com 1238879Ssteve.reinhardt@amd.com kwargs.setdefault('shell', False) 1248120Sgblack@eecs.umich.edu kwargs.setdefault('stdout', PIPE) 1258120Sgblack@eecs.umich.edu kwargs.setdefault('stderr', STDOUT) 1268120Sgblack@eecs.umich.edu kwargs.setdefault('close_fds', True) 1278120Sgblack@eecs.umich.edu try: 1288120Sgblack@eecs.umich.edu subp = Popen(cmd, **kwargs) 1298120Sgblack@eecs.umich.edu except Exception, e: 1308120Sgblack@eecs.umich.edu if no_exception: 1318120Sgblack@eecs.umich.edu return exception 1328120Sgblack@eecs.umich.edu raise 1338120Sgblack@eecs.umich.edu 1348120Sgblack@eecs.umich.edu return subp.communicate()[0] 1358120Sgblack@eecs.umich.edu 1368120Sgblack@eecs.umich.edu# helper function: compare arrays or strings of version numbers. 1378120Sgblack@eecs.umich.edu# E.g., compare_version((1,3,25), (1,4,1)') 1388879Ssteve.reinhardt@amd.com# returns -1, 0, 1 if v1 is <, ==, > v2 1398879Ssteve.reinhardt@amd.comdef compare_versions(v1, v2): 1408879Ssteve.reinhardt@amd.com def make_version_list(v): 1418879Ssteve.reinhardt@amd.com if isinstance(v, (list,tuple)): 14210458Sandreas.hansson@arm.com return v 14310458Sandreas.hansson@arm.com elif isinstance(v, str): 14410458Sandreas.hansson@arm.com return map(lambda x: int(re.match('\d+', x).group()), v.split('.')) 1458879Ssteve.reinhardt@amd.com else: 1468879Ssteve.reinhardt@amd.com raise TypeError 1478879Ssteve.reinhardt@amd.com 1488879Ssteve.reinhardt@amd.com v1 = make_version_list(v1) 14913421Sciro.santilli@arm.com v2 = make_version_list(v2) 15013421Sciro.santilli@arm.com # Compare corresponding elements of lists 1519227Sandreas.hansson@arm.com for n1,n2 in zip(v1, v2): 1529227Sandreas.hansson@arm.com if n1 < n2: return -1 15312063Sgabeblack@google.com if n1 > n2: return 1 15412063Sgabeblack@google.com # all corresponding values are equal... see if one has extra values 15512063Sgabeblack@google.com if len(v1) < len(v2): return -1 1568879Ssteve.reinhardt@amd.com if len(v1) > len(v2): return 1 1578879Ssteve.reinhardt@amd.com return 0 1588879Ssteve.reinhardt@amd.com 1598879Ssteve.reinhardt@amd.com######################################################################## 16010453SAndrew.Bardsley@arm.com# 16110453SAndrew.Bardsley@arm.com# Set up the main build environment. 16210453SAndrew.Bardsley@arm.com# 16310456SCurtis.Dunham@arm.com######################################################################## 16410456SCurtis.Dunham@arm.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 16510456SCurtis.Dunham@arm.com 'RANLIB' ]) 16610457Sandreas.hansson@arm.com 16710457Sandreas.hansson@arm.comuse_env = {} 16811342Sandreas.hansson@arm.comfor key,val in os.environ.iteritems(): 16911342Sandreas.hansson@arm.com if key in use_vars or key.startswith("M5"): 1708120Sgblack@eecs.umich.edu use_env[key] = val 17112063Sgabeblack@google.com 17212563Sgabeblack@google.commain = Environment(ENV=use_env) 17312063Sgabeblack@google.commain.root = Dir(".") # The current directory (where this file lives). 17412063Sgabeblack@google.commain.srcdir = Dir("src") # The source directory 1755871Snate@binkert.org 1765871Snate@binkert.org######################################################################## 1776121Snate@binkert.org# 1785871Snate@binkert.org# Mercurial Stuff. 1795871Snate@binkert.org# 1809926Sstan.czerniawski@arm.com# If the M5 directory is a mercurial repository, we should do some 18112243Sgabeblack@google.com# extra things. 1821533SN/A# 18312246Sgabeblack@google.com######################################################################## 18412246Sgabeblack@google.com 18512246Sgabeblack@google.comhgdir = main.root.Dir(".hg") 18612246Sgabeblack@google.com 1879239Sandreas.hansson@arm.commercurial_style_message = """ 1889239Sandreas.hansson@arm.comYou're missing the M5 style hook. 1899239Sandreas.hansson@arm.comPlease install the hook so we can ensure that all code fits a common style. 1909239Sandreas.hansson@arm.com 19112563Sgabeblack@google.comAll you'd need to do is add the following lines to your repository .hg/hgrc 1929239Sandreas.hansson@arm.comor your personal .hgrc 1939239Sandreas.hansson@arm.com---------------- 194955SN/A 195955SN/A[extensions] 1962632Sstever@eecs.umich.edustyle = %s/util/style.py 1972632Sstever@eecs.umich.edu 198955SN/A[hooks] 199955SN/Apretxncommit.style = python:style.check_whitespace 200955SN/A""" % (main.root) 201955SN/A 2028878Ssteve.reinhardt@amd.commercurial_bin_not_found = """ 203955SN/AMercurial binary cannot be found, unfortunately this means that we 2042632Sstever@eecs.umich.educannot easily determine the version of M5 that you are running and 2052632Sstever@eecs.umich.eduthis makes error messages more difficult to collect. Please consider 2062632Sstever@eecs.umich.eduinstalling mercurial if you choose to post an error message 2072632Sstever@eecs.umich.edu""" 2082632Sstever@eecs.umich.edu 2092632Sstever@eecs.umich.edumercurial_lib_not_found = """ 2102632Sstever@eecs.umich.eduMercurial libraries cannot be found, ignoring style hook 2118268Ssteve.reinhardt@amd.comIf you are actually a M5 developer, please fix this and 2128268Ssteve.reinhardt@amd.comrun the style hook. It is important. 2138268Ssteve.reinhardt@amd.com""" 2148268Ssteve.reinhardt@amd.com 2158268Ssteve.reinhardt@amd.comhg_info = "Unknown" 2168268Ssteve.reinhardt@amd.comif hgdir.exists(): 2178268Ssteve.reinhardt@amd.com # 1) Grab repository revision if we know it. 2182632Sstever@eecs.umich.edu cmd = "hg id -n -i -t -b" 2192632Sstever@eecs.umich.edu try: 2202632Sstever@eecs.umich.edu hg_info = read_command(cmd, cwd=main.root.abspath).strip() 2212632Sstever@eecs.umich.edu except OSError: 2228268Ssteve.reinhardt@amd.com print mercurial_bin_not_found 2232632Sstever@eecs.umich.edu 2248268Ssteve.reinhardt@amd.com # 2) Ensure that the style hook is in place. 2258268Ssteve.reinhardt@amd.com try: 2268268Ssteve.reinhardt@amd.com ui = None 2278268Ssteve.reinhardt@amd.com if ARGUMENTS.get('IGNORE_STYLE') != 'True': 2283718Sstever@eecs.umich.edu from mercurial import ui 2292634Sstever@eecs.umich.edu ui = ui.ui() 2302634Sstever@eecs.umich.edu except ImportError: 2315863Snate@binkert.org print mercurial_lib_not_found 2322638Sstever@eecs.umich.edu 2338268Ssteve.reinhardt@amd.com if ui is not None: 2342632Sstever@eecs.umich.edu ui.readconfig(hgdir.File('hgrc').abspath) 2352632Sstever@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) 2362632Sstever@eecs.umich.edu 2372632Sstever@eecs.umich.edu if not style_hook: 23812563Sgabeblack@google.com print mercurial_style_message 2391858SN/A sys.exit(1) 2403716Sstever@eecs.umich.eduelse: 2412638Sstever@eecs.umich.edu print ".hg directory not found" 2422638Sstever@eecs.umich.edu 2432638Sstever@eecs.umich.edumain['HG_INFO'] = hg_info 2442638Sstever@eecs.umich.edu 24512563Sgabeblack@google.com################################################### 24612563Sgabeblack@google.com# 2472638Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2485863Snate@binkert.org# the target(s). 2495863Snate@binkert.org# 2505863Snate@binkert.org################################################### 251955SN/A 2525341Sstever@gmail.com# Find default configuration & binary. 2535341Sstever@gmail.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2545863Snate@binkert.org 2557756SAli.Saidi@ARM.com# helper function: find last occurrence of element in list 2565341Sstever@gmail.comdef rfind(l, elt, offs = -1): 2576121Snate@binkert.org for i in range(len(l)+offs, 0, -1): 2584494Ssaidi@eecs.umich.edu if l[i] == elt: 2596121Snate@binkert.org return i 2601105SN/A raise ValueError, "element not found" 2612667Sstever@eecs.umich.edu 2622667Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2632667Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2642667Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2656121Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 2662667Sstever@eecs.umich.edu# follow 'build' in the bulid path. 2675341Sstever@gmail.com 2685863Snate@binkert.org# Generate absolute paths to targets so we can see where the build dir is 2695341Sstever@gmail.comif COMMAND_LINE_TARGETS: 2705341Sstever@gmail.com # Ask SCons which directory it was invoked from 2715341Sstever@gmail.com launch_dir = GetLaunchDir() 2728120Sgblack@eecs.umich.edu # Make targets relative to invocation directory 2735341Sstever@gmail.com abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2748120Sgblack@eecs.umich.edu COMMAND_LINE_TARGETS] 2755341Sstever@gmail.comelse: 2768120Sgblack@eecs.umich.edu # Default targets are relative to root of tree 2776121Snate@binkert.org abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2786121Snate@binkert.org DEFAULT_TARGETS] 2799396Sandreas.hansson@arm.com 2805397Ssaidi@eecs.umich.edu 2815397Ssaidi@eecs.umich.edu# Generate a list of the unique build roots and configs that the 2827727SAli.Saidi@ARM.com# collected targets reference. 2838268Ssteve.reinhardt@amd.comvariant_paths = [] 2846168Snate@binkert.orgbuild_root = None 2855341Sstever@gmail.comfor t in abs_targets: 2868120Sgblack@eecs.umich.edu path_dirs = t.split('/') 2878120Sgblack@eecs.umich.edu try: 2888120Sgblack@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 2896814Sgblack@eecs.umich.edu except: 2905863Snate@binkert.org print "Error: no non-leaf 'build' dir found on target path", t 2918120Sgblack@eecs.umich.edu Exit(1) 2925341Sstever@gmail.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2935863Snate@binkert.org if not build_root: 2948268Ssteve.reinhardt@amd.com build_root = this_build_root 2956121Snate@binkert.org else: 2966121Snate@binkert.org if this_build_root != build_root: 2978268Ssteve.reinhardt@amd.com print "Error: build targets not under same build root\n"\ 2985742Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 2995742Snate@binkert.org Exit(1) 3005341Sstever@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 3015742Snate@binkert.org if variant_path not in variant_paths: 3025742Snate@binkert.org variant_paths.append(variant_path) 3035341Sstever@gmail.com 3046017Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 3056121Snate@binkert.orgif not isdir(build_root): 3066017Snate@binkert.org mkdir(build_root) 30712158Sandreas.sandberg@arm.com 30812158Sandreas.sandberg@arm.comExport('main') 30912158Sandreas.sandberg@arm.com 3108120Sgblack@eecs.umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 3117756SAli.Saidi@ARM.com 3127756SAli.Saidi@ARM.com# Default duplicate option is to use hard links, but this messes up 3137756SAli.Saidi@ARM.com# when you use emacs to edit a file in the target dir, as emacs moves 3147756SAli.Saidi@ARM.com# file to file~ then copies to file, breaking the link. Symbolic 3157816Ssteve.reinhardt@amd.com# (soft) links work better. 3167816Ssteve.reinhardt@amd.commain.SetOption('duplicate', 'soft-copy') 3177816Ssteve.reinhardt@amd.com 3187816Ssteve.reinhardt@amd.com# 3197816Ssteve.reinhardt@amd.com# Set up global sticky variables... these are common to an entire build 32011979Sgabeblack@google.com# tree (not specific to a particular build like ALPHA_SE) 3217816Ssteve.reinhardt@amd.com# 3227816Ssteve.reinhardt@amd.com 3237816Ssteve.reinhardt@amd.com# Variable validators & converters for global sticky variables 3247816Ssteve.reinhardt@amd.comdef PathListMakeAbsolute(val): 3257756SAli.Saidi@ARM.com if not val: 3267756SAli.Saidi@ARM.com return val 3279227Sandreas.hansson@arm.com f = lambda p: abspath(expanduser(p)) 3289227Sandreas.hansson@arm.com return ':'.join(map(f, val.split(':'))) 3299227Sandreas.hansson@arm.com 3309227Sandreas.hansson@arm.comdef PathListAllExist(key, val, env): 3319590Sandreas@sandberg.pp.se if not val: 3329590Sandreas@sandberg.pp.se return 3339590Sandreas@sandberg.pp.se paths = val.split(':') 3349590Sandreas@sandberg.pp.se for path in paths: 3359590Sandreas@sandberg.pp.se if not isdir(path): 3369590Sandreas@sandberg.pp.se raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3376654Snate@binkert.org 3386654Snate@binkert.orgglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3395871Snate@binkert.org 3406121Snate@binkert.orgglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3418946Sandreas.hansson@arm.com 3429419Sandreas.hansson@arm.comglobal_sticky_vars.AddVariables( 34312563Sgabeblack@google.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 3443918Ssaidi@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3453918Ssaidi@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3461858SN/A ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3479556Sandreas.hansson@arm.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3489556Sandreas.hansson@arm.com PathListAllExist, PathListMakeAbsolute) 3499556Sandreas.hansson@arm.com ) 3509556Sandreas.hansson@arm.com 35111294Sandreas.hansson@arm.com# base help text 35211294Sandreas.hansson@arm.comhelp_text = ''' 35311294Sandreas.hansson@arm.comUsage: scons [scons options] [build options] [target(s)] 35411294Sandreas.hansson@arm.com 35510878Sandreas.hansson@arm.comGlobal sticky options: 35610878Sandreas.hansson@arm.com''' 35711811Sbaz21@cam.ac.uk 35811811Sbaz21@cam.ac.ukhelp_text += global_sticky_vars.GenerateHelpText(main) 35911811Sbaz21@cam.ac.uk 36011982Sgabeblack@google.com# Update main environment with values from ARGUMENTS & global_sticky_vars_file 36111982Sgabeblack@google.comglobal_sticky_vars.Update(main) 36211982Sgabeblack@google.com 36313421Sciro.santilli@arm.com# Save sticky variable settings back to current variables file 36413421Sciro.santilli@arm.comglobal_sticky_vars.Save(global_sticky_vars_file, main) 36511982Sgabeblack@google.com 36611992Sgabeblack@google.com# Parse EXTRAS variable to build list of all directories where we're 36711982Sgabeblack@google.com# look for sources etc. This list is exported as base_dir_list. 36811982Sgabeblack@google.combase_dir = main.srcdir.abspath 36912305Sgabeblack@google.comif main['EXTRAS']: 37012305Sgabeblack@google.com extras_dir_list = main['EXTRAS'].split(':') 37112305Sgabeblack@google.comelse: 37212305Sgabeblack@google.com extras_dir_list = [] 37312305Sgabeblack@google.com 37412305Sgabeblack@google.comExport('base_dir') 37512305Sgabeblack@google.comExport('extras_dir_list') 3769556Sandreas.hansson@arm.com 37712563Sgabeblack@google.com# the ext directory should be on the #includes path 37812563Sgabeblack@google.commain.Append(CPPPATH=[Dir('ext')]) 37912563Sgabeblack@google.com 38012563Sgabeblack@google.com# M5_PLY is used by isa_parser.py to find the PLY package. 3819556Sandreas.hansson@arm.commain.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath }) 38212563Sgabeblack@google.com 38312563Sgabeblack@google.comCXX_version = read_command([main['CXX'],'--version'], exception=False) 3849556Sandreas.hansson@arm.comCXX_V = read_command([main['CXX'],'-V'], exception=False) 38512563Sgabeblack@google.com 38612563Sgabeblack@google.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 38712563Sgabeblack@google.commain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 38812563Sgabeblack@google.commain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 38912563Sgabeblack@google.comif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 39012563Sgabeblack@google.com print 'Error: How can we have two at the same time?' 39112563Sgabeblack@google.com Exit(1) 39212563Sgabeblack@google.com 3939556Sandreas.hansson@arm.com# Set up default C++ compiler flags 3949556Sandreas.hansson@arm.comif main['GCC']: 3956121Snate@binkert.org main.Append(CCFLAGS='-pipe') 39611500Sandreas.hansson@arm.com main.Append(CCFLAGS='-fno-strict-aliasing') 39710238Sandreas.hansson@arm.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 39810878Sandreas.hansson@arm.com main.Append(CXXFLAGS='-Wno-deprecated') 3999420Sandreas.hansson@arm.comelif main['ICC']: 40011500Sandreas.hansson@arm.com pass #Fix me... add warning flags once we clean up icc warnings 40112563Sgabeblack@google.comelif main['SUNCC']: 40212563Sgabeblack@google.com main.Append(CCFLAGS='-Qoption ccfe') 4039420Sandreas.hansson@arm.com main.Append(CCFLAGS='-features=gcc') 4049420Sandreas.hansson@arm.com main.Append(CCFLAGS='-features=extensions') 4059420Sandreas.hansson@arm.com main.Append(CCFLAGS='-library=stlport4') 4069420Sandreas.hansson@arm.com main.Append(CCFLAGS='-xar') 40712063Sgabeblack@google.com #main.Append(CCFLAGS='-instances=semiexplicit') 40812063Sgabeblack@google.comelse: 40912063Sgabeblack@google.com print 'Error: Don\'t know what compiler options to use for your compiler.' 41012063Sgabeblack@google.com print ' Please fix SConstruct and src/SConscript and try again.' 41112063Sgabeblack@google.com Exit(1) 41212063Sgabeblack@google.com 41312063Sgabeblack@google.com# Set up common yacc/bison flags (needed for Ruby) 41412063Sgabeblack@google.commain['YACCFLAGS'] = '-d' 41512063Sgabeblack@google.commain['YACCHXXFILESUFFIX'] = '.hh' 41612063Sgabeblack@google.com 41712063Sgabeblack@google.com# Do this after we save setting back, or else we'll tack on an 41812063Sgabeblack@google.com# extra 'qdo' every time we run scons. 41912063Sgabeblack@google.comif main['BATCH']: 42012063Sgabeblack@google.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 42112063Sgabeblack@google.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 42212063Sgabeblack@google.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 42312063Sgabeblack@google.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 42412063Sgabeblack@google.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 42512063Sgabeblack@google.com 42612063Sgabeblack@google.comif sys.platform == 'cygwin': 42712063Sgabeblack@google.com # cygwin has some header file issues... 42812063Sgabeblack@google.com main.Append(CCFLAGS=Split("-Wno-uninitialized")) 42910457Sandreas.hansson@arm.com 43010457Sandreas.hansson@arm.com# Check for SWIG 43110457Sandreas.hansson@arm.comif not main.has_key('SWIG'): 43210457Sandreas.hansson@arm.com print 'Error: SWIG utility not found.' 43310457Sandreas.hansson@arm.com print ' Please install (see http://www.swig.org) and retry.' 43412563Sgabeblack@google.com Exit(1) 43512563Sgabeblack@google.com 43612563Sgabeblack@google.com# Check for appropriate SWIG version 43710457Sandreas.hansson@arm.comswig_version = read_command(('swig', '-version'), exception='').split() 43812063Sgabeblack@google.com# First 3 words should be "SWIG Version x.y.z" 43912063Sgabeblack@google.comif len(swig_version) < 3 or \ 44012063Sgabeblack@google.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 44112563Sgabeblack@google.com print 'Error determining SWIG version.' 44212563Sgabeblack@google.com Exit(1) 44312563Sgabeblack@google.com 44412563Sgabeblack@google.commin_swig_version = '1.3.28' 44512563Sgabeblack@google.comif compare_versions(swig_version[2], min_swig_version) < 0: 44612563Sgabeblack@google.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 44712063Sgabeblack@google.com print ' Installed version:', swig_version[2] 44812063Sgabeblack@google.com Exit(1) 44910238Sandreas.hansson@arm.com 45010238Sandreas.hansson@arm.com# Set up SWIG flags & scanner 45110238Sandreas.hansson@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 45212063Sgabeblack@google.commain.Append(SWIGFLAGS=swig_flags) 45310238Sandreas.hansson@arm.com 45410238Sandreas.hansson@arm.com# filter out all existing swig scanners, they mess up the dependency 45510416Sandreas.hansson@arm.com# stuff for some reason 45610238Sandreas.hansson@arm.comscanners = [] 4579227Sandreas.hansson@arm.comfor scanner in main['SCANNERS']: 45810238Sandreas.hansson@arm.com skeys = scanner.skeys 45910416Sandreas.hansson@arm.com if skeys == '.i': 46010416Sandreas.hansson@arm.com continue 4619227Sandreas.hansson@arm.com 4629590Sandreas@sandberg.pp.se if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4639590Sandreas@sandberg.pp.se continue 4649590Sandreas@sandberg.pp.se 46512304Sgabeblack@google.com scanners.append(scanner) 46612304Sgabeblack@google.com 46712304Sgabeblack@google.com# add the new swig scanner that we like better 46812688Sgiacomo.travaglini@arm.comfrom SCons.Scanner import ClassicCPP as CPPScanner 46912688Sgiacomo.travaglini@arm.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 47012688Sgiacomo.travaglini@arm.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 47113020Sshunhsingou@google.com 47212304Sgabeblack@google.com# replace the scanners list that has what we want 47312688Sgiacomo.travaglini@arm.commain['SCANNERS'] = scanners 47412688Sgiacomo.travaglini@arm.com 47513020Sshunhsingou@google.com# Add a custom Check function to the Configure context so that we can 47612304Sgabeblack@google.com# figure out if the compiler adds leading underscores to global 47712304Sgabeblack@google.com# variables. This is needed for the autogenerated asm files that we 47812304Sgabeblack@google.com# use for embedding the python code. 47912304Sgabeblack@google.comdef CheckLeading(context): 48012688Sgiacomo.travaglini@arm.com context.Message("Checking for leading underscore in global variables...") 48112688Sgiacomo.travaglini@arm.com # 1) Define a global variable called x from asm so the C compiler 48212688Sgiacomo.travaglini@arm.com # won't change the symbol at all. 48312304Sgabeblack@google.com # 2) Declare that variable. 4848737Skoansin.tan@gmail.com # 3) Use the variable 48510878Sandreas.hansson@arm.com # 48611500Sandreas.hansson@arm.com # If the compiler prepends an underscore, this will successfully 4879420Sandreas.hansson@arm.com # link because the external symbol 'x' will be called '_x' which 4888737Skoansin.tan@gmail.com # was defined by the asm statement. If the compiler does not 48910106SMitch.Hayenga@arm.com # prepend an underscore, this will not successfully link because 4908737Skoansin.tan@gmail.com # '_x' will have been defined by assembly, while the C portion of 4918737Skoansin.tan@gmail.com # the code will be trying to use 'x' 49210878Sandreas.hansson@arm.com ret = context.TryLink(''' 49312563Sgabeblack@google.com asm(".globl _x; _x: .byte 0"); 49412563Sgabeblack@google.com extern int x; 4958737Skoansin.tan@gmail.com int main() { return x; } 4968737Skoansin.tan@gmail.com ''', extension=".c") 49712563Sgabeblack@google.com context.env.Append(LEADING_UNDERSCORE=ret) 4988737Skoansin.tan@gmail.com context.Result(ret) 4998737Skoansin.tan@gmail.com return ret 50011294Sandreas.hansson@arm.com 5019556Sandreas.hansson@arm.com# Platform-specific configuration. Note again that we assume that all 5029556Sandreas.hansson@arm.com# builds under a given build root run on the same host platform. 5039556Sandreas.hansson@arm.comconf = Configure(main, 50411294Sandreas.hansson@arm.com conf_dir = joinpath(build_root, '.scons_config'), 50510278SAndreas.Sandberg@ARM.com log_file = joinpath(build_root, 'scons_config.log'), 50610278SAndreas.Sandberg@ARM.com custom_tests = { 'CheckLeading' : CheckLeading }) 50710278SAndreas.Sandberg@ARM.com 50810278SAndreas.Sandberg@ARM.com# Check for leading underscores. Don't really need to worry either 50910278SAndreas.Sandberg@ARM.com# way so don't need to check the return code. 51010278SAndreas.Sandberg@ARM.comconf.CheckLeading() 5119556Sandreas.hansson@arm.com 5129590Sandreas@sandberg.pp.se# Check if we should compile a 64 bit binary on Mac OS X/Darwin 5139590Sandreas@sandberg.pp.setry: 5149420Sandreas.hansson@arm.com import platform 5159846Sandreas.hansson@arm.com uname = platform.uname() 5169846Sandreas.hansson@arm.com if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 5179846Sandreas.hansson@arm.com if int(read_command('sysctl -n hw.cpu64bit_capable')[0]): 5189846Sandreas.hansson@arm.com main.Append(CCFLAGS='-arch x86_64') 5198946Sandreas.hansson@arm.com main.Append(CFLAGS='-arch x86_64') 52011811Sbaz21@cam.ac.uk main.Append(LINKFLAGS='-arch x86_64') 52111811Sbaz21@cam.ac.uk main.Append(ASFLAGS='-arch x86_64') 52211811Sbaz21@cam.ac.ukexcept: 52311811Sbaz21@cam.ac.uk pass 52412304Sgabeblack@google.com 52512304Sgabeblack@google.com# Recent versions of scons substitute a "Null" object for Configure() 52612304Sgabeblack@google.com# when configuration isn't necessary, e.g., if the "--help" option is 52712304Sgabeblack@google.com# present. Unfortuantely this Null object always returns false, 52813020Sshunhsingou@google.com# breaking all our configuration checks. We replace it with our own 52913020Sshunhsingou@google.com# more optimistic null object that returns True instead. 53012304Sgabeblack@google.comif not conf: 53112304Sgabeblack@google.com def NullCheck(*args, **kwargs): 53213020Sshunhsingou@google.com return True 53313020Sshunhsingou@google.com 53412304Sgabeblack@google.com class NullConf: 53512304Sgabeblack@google.com def __init__(self, env): 53613020Sshunhsingou@google.com self.env = env 53713020Sshunhsingou@google.com def Finish(self): 53812304Sgabeblack@google.com return self.env 53912304Sgabeblack@google.com def __getattr__(self, mname): 5403918Ssaidi@eecs.umich.edu return NullCheck 54112563Sgabeblack@google.com 54212563Sgabeblack@google.com conf = NullConf(main) 54312563Sgabeblack@google.com 54412563Sgabeblack@google.com# Find Python include and library directories for embedding the 5459068SAli.Saidi@ARM.com# interpreter. For consistency, we will use the same Python 54612563Sgabeblack@google.com# installation used to run scons (and thus this script). If you want 54712563Sgabeblack@google.com# to link in an alternate version, see above for instructions on how 5489068SAli.Saidi@ARM.com# to invoke scons with a different copy of the Python interpreter. 54912563Sgabeblack@google.comfrom distutils import sysconfig 55012563Sgabeblack@google.com 55112563Sgabeblack@google.compy_getvar = sysconfig.get_config_var 55212563Sgabeblack@google.com 55312563Sgabeblack@google.compy_version = 'python' + py_getvar('VERSION') 55412563Sgabeblack@google.com 55512563Sgabeblack@google.compy_general_include = sysconfig.get_python_inc() 55612563Sgabeblack@google.compy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5573918Ssaidi@eecs.umich.edupy_includes = [ py_general_include ] 5583918Ssaidi@eecs.umich.eduif py_platform_include != py_general_include: 5596157Snate@binkert.org py_includes.append(py_platform_include) 5606157Snate@binkert.org 5616157Snate@binkert.orgpy_lib_path = [ py_getvar('LIBDIR') ] 5626157Snate@binkert.org# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5635397Ssaidi@eecs.umich.edu# shared library in prefix/lib/. 5645397Ssaidi@eecs.umich.eduif not py_getvar('Py_ENABLE_SHARED'): 5656121Snate@binkert.org py_lib_path.append(py_getvar('LIBPL')) 5666121Snate@binkert.org 5676121Snate@binkert.orgpy_libs = [] 5686121Snate@binkert.orgfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 5696121Snate@binkert.org assert lib.startswith('-l') 5706121Snate@binkert.org lib = lib[2:] 5715397Ssaidi@eecs.umich.edu if lib not in py_libs: 5721851SN/A py_libs.append(lib) 5731851SN/Apy_libs.append(py_version) 5747739Sgblack@eecs.umich.edu 575955SN/Amain.Append(CPPPATH=py_includes) 5769396Sandreas.hansson@arm.commain.Append(LIBPATH=py_lib_path) 5779396Sandreas.hansson@arm.com 5789396Sandreas.hansson@arm.com# verify that this stuff works 5799396Sandreas.hansson@arm.comif not conf.CheckHeader('Python.h', '<>'): 5809396Sandreas.hansson@arm.com print "Error: can't find Python.h header in", py_includes 5819396Sandreas.hansson@arm.com Exit(1) 58212563Sgabeblack@google.com 58312563Sgabeblack@google.comfor lib in py_libs: 58412563Sgabeblack@google.com if not conf.CheckLib(lib): 58512563Sgabeblack@google.com print "Error: can't find library %s required by python" % lib 5869396Sandreas.hansson@arm.com Exit(1) 5879396Sandreas.hansson@arm.com 5889396Sandreas.hansson@arm.com# On Solaris you need to use libsocket for socket ops 5899396Sandreas.hansson@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5909396Sandreas.hansson@arm.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5919396Sandreas.hansson@arm.com print "Can't find library with socket calls (e.g. accept())" 59212563Sgabeblack@google.com Exit(1) 59312563Sgabeblack@google.com 59412563Sgabeblack@google.com# Check for zlib. If the check passes, libz will be automatically 59512563Sgabeblack@google.com# added to the LIBS environment variable. 59612563Sgabeblack@google.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5979477Sandreas.hansson@arm.com print 'Error: did not find needed zlib compression library '\ 5989477Sandreas.hansson@arm.com 'and/or zlib.h header file.' 5999477Sandreas.hansson@arm.com print ' Please install zlib and try again.' 6009477Sandreas.hansson@arm.com Exit(1) 6019477Sandreas.hansson@arm.com 6029477Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control) 6039477Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 6049477Sandreas.hansson@arm.comif not have_fenv: 6059477Sandreas.hansson@arm.com print "Warning: Header file <fenv.h> not found." 6069477Sandreas.hansson@arm.com print " This host has no IEEE FP rounding mode control." 6079477Sandreas.hansson@arm.com 6089477Sandreas.hansson@arm.com###################################################################### 6099477Sandreas.hansson@arm.com# 6109477Sandreas.hansson@arm.com# Check for mysql. 61112563Sgabeblack@google.com# 61212563Sgabeblack@google.commysql_config = WhereIs('mysql_config') 61312563Sgabeblack@google.comhave_mysql = bool(mysql_config) 6149396Sandreas.hansson@arm.com 6152667Sstever@eecs.umich.edu# Check MySQL version. 61610710Sandreas.hansson@arm.comif have_mysql: 61710710Sandreas.hansson@arm.com mysql_version = read_command(mysql_config + ' --version') 61810710Sandreas.hansson@arm.com min_mysql_version = '4.1' 61911811Sbaz21@cam.ac.uk if compare_versions(mysql_version, min_mysql_version) < 0: 62011811Sbaz21@cam.ac.uk print 'Warning: MySQL', min_mysql_version, 'or newer required.' 62111811Sbaz21@cam.ac.uk print ' Version', mysql_version, 'detected.' 62211811Sbaz21@cam.ac.uk have_mysql = False 62311811Sbaz21@cam.ac.uk 62411811Sbaz21@cam.ac.uk# Set up mysql_config commands. 62510710Sandreas.hansson@arm.comif have_mysql: 62610710Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --include' 62710710Sandreas.hansson@arm.com if os.system(mysql_config_include + ' > /dev/null') != 0: 62810710Sandreas.hansson@arm.com # older mysql_config versions don't support --include, use 62910384SCurtis.Dunham@arm.com # --cflags instead 6309986Sandreas@sandberg.pp.se mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 6319986Sandreas@sandberg.pp.se # This seems to work in all versions 6329986Sandreas@sandberg.pp.se mysql_config_libs = mysql_config + ' --libs' 6339986Sandreas@sandberg.pp.se 6349986Sandreas@sandberg.pp.se###################################################################### 6359986Sandreas@sandberg.pp.se# 6369986Sandreas@sandberg.pp.se# Finish the configuration 6379986Sandreas@sandberg.pp.se# 6389986Sandreas@sandberg.pp.semain = conf.Finish() 6399986Sandreas@sandberg.pp.se 6409986Sandreas@sandberg.pp.se###################################################################### 6419986Sandreas@sandberg.pp.se# 6429986Sandreas@sandberg.pp.se# Collect all non-global variables 6439986Sandreas@sandberg.pp.se# 6449986Sandreas@sandberg.pp.se 6459986Sandreas@sandberg.pp.se# Define the universe of supported ISAs 6469986Sandreas@sandberg.pp.seall_isa_list = [ ] 6479986Sandreas@sandberg.pp.seExport('all_isa_list') 6489986Sandreas@sandberg.pp.se 6499986Sandreas@sandberg.pp.se# Define the universe of supported CPU models 6502638Sstever@eecs.umich.eduall_cpu_list = [ ] 6512638Sstever@eecs.umich.edudefault_cpus = [ ] 6526121Snate@binkert.orgExport('all_cpu_list', 'default_cpus') 6533716Sstever@eecs.umich.edu 6545522Snate@binkert.org# Sticky variables get saved in the variables file so they persist from 6559986Sandreas@sandberg.pp.se# one invocation to the next (unless overridden, in which case the new 6569986Sandreas@sandberg.pp.se# value becomes sticky). 6579986Sandreas@sandberg.pp.sesticky_vars = Variables(args=ARGUMENTS) 6585522Snate@binkert.orgExport('sticky_vars') 6595227Ssaidi@eecs.umich.edu 6605227Ssaidi@eecs.umich.edu# Sticky variables that should be exported 6615227Ssaidi@eecs.umich.eduexport_vars = [] 6625227Ssaidi@eecs.umich.eduExport('export_vars') 6636654Snate@binkert.org 6646654Snate@binkert.org# Non-sticky variables only apply to the current build. 6657769SAli.Saidi@ARM.comnonsticky_vars = Variables(args=ARGUMENTS) 6667769SAli.Saidi@ARM.comExport('nonsticky_vars') 6677769SAli.Saidi@ARM.com 6687769SAli.Saidi@ARM.com# Walk the tree and execute all SConsopts scripts that wil add to the 6695227Ssaidi@eecs.umich.edu# above variables 6705227Ssaidi@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list: 6715227Ssaidi@eecs.umich.edu for root, dirs, files in os.walk(bdir): 6725204Sstever@gmail.com if 'SConsopts' in files: 6735204Sstever@gmail.com print "Reading", joinpath(root, 'SConsopts') 6745204Sstever@gmail.com SConscript(joinpath(root, 'SConsopts')) 6755204Sstever@gmail.com 6765204Sstever@gmail.comall_isa_list.sort() 6775204Sstever@gmail.comall_cpu_list.sort() 6785204Sstever@gmail.comdefault_cpus.sort() 6795204Sstever@gmail.com 6805204Sstever@gmail.comsticky_vars.AddVariables( 6815204Sstever@gmail.com EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6825204Sstever@gmail.com BoolVariable('FULL_SYSTEM', 'Full-system support', False), 6835204Sstever@gmail.com ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 6845204Sstever@gmail.com BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6855204Sstever@gmail.com BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6865204Sstever@gmail.com False), 6875204Sstever@gmail.com BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6885204Sstever@gmail.com False), 6896121Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 6905204Sstever@gmail.com False), 6917727SAli.Saidi@ARM.com BoolVariable('SS_COMPATIBLE_FP', 6927727SAli.Saidi@ARM.com 'Make floating-point results compatible with SimpleScalar', 69312563Sgabeblack@google.com False), 6947727SAli.Saidi@ARM.com BoolVariable('USE_SSE2', 6957727SAli.Saidi@ARM.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 69611988Sandreas.sandberg@arm.com False), 69711988Sandreas.sandberg@arm.com BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 69810453SAndrew.Bardsley@arm.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 69910453SAndrew.Bardsley@arm.com BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 70010453SAndrew.Bardsley@arm.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 70110453SAndrew.Bardsley@arm.com ) 70210453SAndrew.Bardsley@arm.com 70310453SAndrew.Bardsley@arm.comnonsticky_vars.AddVariables( 70410453SAndrew.Bardsley@arm.com BoolVariable('update_ref', 'Update test reference outputs', False) 70510453SAndrew.Bardsley@arm.com ) 70610453SAndrew.Bardsley@arm.com 70710453SAndrew.Bardsley@arm.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 70810160Sandreas.hansson@arm.comexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 70910453SAndrew.Bardsley@arm.com 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 71010453SAndrew.Bardsley@arm.com 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 71110453SAndrew.Bardsley@arm.com 71210453SAndrew.Bardsley@arm.com################################################### 71310453SAndrew.Bardsley@arm.com# 71413541Sandrea.mondelli@ucf.edu# Define a SCons builder for configuration flag headers. 71510453SAndrew.Bardsley@arm.com# 71610453SAndrew.Bardsley@arm.com################################################### 71713541Sandrea.mondelli@ucf.edu 71813541Sandrea.mondelli@ucf.edu# This function generates a config header file that #defines the 7199812Sandreas.hansson@arm.com# variable symbol to the current variable setting (0 or 1). The source 72010453SAndrew.Bardsley@arm.com# operands are the name of the variable and a Value node containing the 72110453SAndrew.Bardsley@arm.com# value of the variable. 72210453SAndrew.Bardsley@arm.comdef build_config_file(target, source, env): 72310453SAndrew.Bardsley@arm.com (variable, value) = [s.get_contents() for s in source] 72410453SAndrew.Bardsley@arm.com f = file(str(target[0]), 'w') 72510453SAndrew.Bardsley@arm.com print >> f, '#define', variable, value 72610453SAndrew.Bardsley@arm.com f.close() 72710453SAndrew.Bardsley@arm.com return None 72810453SAndrew.Bardsley@arm.com 72910453SAndrew.Bardsley@arm.com# Generate the message to be printed when building the config file. 73010453SAndrew.Bardsley@arm.comdef build_config_file_string(target, source, env): 73110453SAndrew.Bardsley@arm.com (variable, value) = [s.get_contents() for s in source] 7327727SAli.Saidi@ARM.com return "Defining %s as %s in %s." % (variable, value, target[0]) 73310453SAndrew.Bardsley@arm.com 73410453SAndrew.Bardsley@arm.com# Combine the two functions into a scons Action object. 73512790Smatteo.fusi@bsc.esconfig_action = Action(build_config_file, build_config_file_string) 73612790Smatteo.fusi@bsc.es 73712790Smatteo.fusi@bsc.es# The emitter munges the source & target node lists to reflect what 73812790Smatteo.fusi@bsc.es# we're really doing. 73912790Smatteo.fusi@bsc.esdef config_emitter(target, source, env): 74012790Smatteo.fusi@bsc.es # extract variable name from Builder arg 74112790Smatteo.fusi@bsc.es variable = str(target[0]) 74210453SAndrew.Bardsley@arm.com # True target is config header file 7433118Sstever@eecs.umich.edu target = joinpath('config', variable.lower() + '.hh') 74410453SAndrew.Bardsley@arm.com val = env[variable] 74510453SAndrew.Bardsley@arm.com if isinstance(val, bool): 74612563Sgabeblack@google.com # Force value to 0/1 74710453SAndrew.Bardsley@arm.com val = int(val) 7483118Sstever@eecs.umich.edu elif isinstance(val, str): 7493483Ssaidi@eecs.umich.edu val = '"' + val + '"' 7503494Ssaidi@eecs.umich.edu 7513494Ssaidi@eecs.umich.edu # Sources are variable name & value (packaged in SCons Value nodes) 75212563Sgabeblack@google.com return ([target], [Value(variable), Value(val)]) 7533483Ssaidi@eecs.umich.edu 7543483Ssaidi@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 7553053Sstever@eecs.umich.edu 7563053Sstever@eecs.umich.edumain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 7573918Ssaidi@eecs.umich.edu 75812563Sgabeblack@google.com# libelf build is shared across all configs in the build root. 75912563Sgabeblack@google.commain.SConscript('ext/libelf/SConscript', 76012563Sgabeblack@google.com variant_dir = joinpath(build_root, 'libelf')) 7613053Sstever@eecs.umich.edu 7623053Sstever@eecs.umich.edu# gzstream build is shared across all configs in the build root. 7639396Sandreas.hansson@arm.commain.SConscript('ext/gzstream/SConscript', 7649396Sandreas.hansson@arm.com variant_dir = joinpath(build_root, 'gzstream')) 7659396Sandreas.hansson@arm.com 7669396Sandreas.hansson@arm.com################################################### 7679396Sandreas.hansson@arm.com# 7689396Sandreas.hansson@arm.com# This function is used to set up a directory with switching headers 7699396Sandreas.hansson@arm.com# 7709396Sandreas.hansson@arm.com################################################### 7719396Sandreas.hansson@arm.com 77212920Sgabeblack@google.commain['ALL_ISA_LIST'] = all_isa_list 77312920Sgabeblack@google.comdef make_switching_dir(dname, switch_headers, env): 77412920Sgabeblack@google.com # Generate the header. target[0] is the full path of the output 77512920Sgabeblack@google.com # header to generate. 'source' is a dummy variable, since we get the 7769477Sandreas.hansson@arm.com # list of ISAs from env['ALL_ISA_LIST']. 7779396Sandreas.hansson@arm.com def gen_switch_hdr(target, source, env): 77812563Sgabeblack@google.com fname = str(target[0]) 77912563Sgabeblack@google.com bname = basename(fname) 78012563Sgabeblack@google.com f = open(fname, 'w') 78112563Sgabeblack@google.com f.write('#include "arch/isa_specific.hh"\n') 7829396Sandreas.hansson@arm.com cond = '#if' 7837840Snate@binkert.org for isa in all_isa_list: 7847865Sgblack@eecs.umich.edu f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 7857865Sgblack@eecs.umich.edu % (cond, isa.upper(), dname, isa, bname)) 7867865Sgblack@eecs.umich.edu cond = '#elif' 7877865Sgblack@eecs.umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 7887865Sgblack@eecs.umich.edu f.close() 7897840Snate@binkert.org return 0 7909900Sandreas@sandberg.pp.se 7919900Sandreas@sandberg.pp.se # String to print when generating header 7929900Sandreas@sandberg.pp.se def gen_switch_hdr_string(target, source, env): 7939900Sandreas@sandberg.pp.se return "Generating switch header " + str(target[0]) 79410456SCurtis.Dunham@arm.com 79510456SCurtis.Dunham@arm.com # Build SCons Action object. 'varlist' specifies env vars that this 79610456SCurtis.Dunham@arm.com # action depends on; when env['ALL_ISA_LIST'] changes these actions 79710456SCurtis.Dunham@arm.com # should get re-executed. 79810456SCurtis.Dunham@arm.com switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 79910456SCurtis.Dunham@arm.com varlist=['ALL_ISA_LIST']) 80012563Sgabeblack@google.com 80112563Sgabeblack@google.com # Instantiate actions for each header 80212563Sgabeblack@google.com for hdr in switch_headers: 80312563Sgabeblack@google.com env.Command(hdr, [], switch_hdr_action) 8049045SAli.Saidi@ARM.comExport('make_switching_dir') 80511235Sandreas.sandberg@arm.com 80611235Sandreas.sandberg@arm.com################################################### 80711235Sandreas.sandberg@arm.com# 80811235Sandreas.sandberg@arm.com# Define build environments for selected configurations. 80911235Sandreas.sandberg@arm.com# 81012485Sjang.hanhwi@gmail.com################################################### 81112485Sjang.hanhwi@gmail.com 81212485Sjang.hanhwi@gmail.comfor variant_path in variant_paths: 81311235Sandreas.sandberg@arm.com print "Building in", variant_path 81411811Sbaz21@cam.ac.uk 81512485Sjang.hanhwi@gmail.com # Make a copy of the build-root environment to use for this config. 81611811Sbaz21@cam.ac.uk env = main.Clone() 81711811Sbaz21@cam.ac.uk env['BUILDDIR'] = variant_path 81811811Sbaz21@cam.ac.uk 81911235Sandreas.sandberg@arm.com # variant_dir is the tail component of build path, and is used to 82011235Sandreas.sandberg@arm.com # determine the build parameters (e.g., 'ALPHA_SE') 82111235Sandreas.sandberg@arm.com (build_root, variant_dir) = splitpath(variant_path) 82212563Sgabeblack@google.com 82312563Sgabeblack@google.com # Set env variables according to the build directory config. 82412563Sgabeblack@google.com sticky_vars.files = [] 82511235Sandreas.sandberg@arm.com # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 8267840Snate@binkert.org # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 82712563Sgabeblack@google.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 8287840Snate@binkert.org current_vars_file = joinpath(build_root, 'variables', variant_dir) 8291858SN/A if isfile(current_vars_file): 8301858SN/A sticky_vars.files.append(current_vars_file) 8311858SN/A print "Using saved variables file %s" % current_vars_file 83212563Sgabeblack@google.com else: 83312563Sgabeblack@google.com # Build dir-specific variables file doesn't exist. 8341858SN/A 83512230Sgiacomo.travaglini@arm.com # Make sure the directory is there so we can create it later 83612230Sgiacomo.travaglini@arm.com opt_dir = dirname(current_vars_file) 83712230Sgiacomo.travaglini@arm.com if not isdir(opt_dir): 83812230Sgiacomo.travaglini@arm.com mkdir(opt_dir) 83912563Sgabeblack@google.com 84012563Sgabeblack@google.com # Get default build variables from source tree. Variables are 84112563Sgabeblack@google.com # normally determined by name of $VARIANT_DIR, but can be 84212230Sgiacomo.travaglini@arm.com # overriden by 'default=' arg on command line. 8439903Sandreas.hansson@arm.com default_vars_file = joinpath('build_opts', 8449903Sandreas.hansson@arm.com ARGUMENTS.get('default', variant_dir)) 8459903Sandreas.hansson@arm.com if isfile(default_vars_file): 8469903Sandreas.hansson@arm.com sticky_vars.files.append(default_vars_file) 84710841Sandreas.sandberg@arm.com print "Variables file %s not found,\n using defaults in %s" \ 8489651SAndreas.Sandberg@ARM.com % (current_vars_file, default_vars_file) 84912563Sgabeblack@google.com else: 85012563Sgabeblack@google.com print "Error: cannot find variables file %s or %s" \ 8519651SAndreas.Sandberg@ARM.com % (current_vars_file, default_vars_file) 85212056Sgabeblack@google.com Exit(1) 85312056Sgabeblack@google.com 85412056Sgabeblack@google.com # Apply current variable settings to env 85512563Sgabeblack@google.com sticky_vars.Update(env) 85612056Sgabeblack@google.com nonsticky_vars.Update(env) 85710841Sandreas.sandberg@arm.com 85810841Sandreas.sandberg@arm.com help_text += "\nSticky variables for %s:\n" % variant_dir \ 85910841Sandreas.sandberg@arm.com + sticky_vars.GenerateHelpText(env) \ 86010841Sandreas.sandberg@arm.com + "\nNon-sticky variables for %s:\n" % variant_dir \ 86110841Sandreas.sandberg@arm.com + nonsticky_vars.GenerateHelpText(env) 86210841Sandreas.sandberg@arm.com 8639651SAndreas.Sandberg@ARM.com # Process variable settings. 8649651SAndreas.Sandberg@ARM.com 8659651SAndreas.Sandberg@ARM.com if not have_fenv and env['USE_FENV']: 8669651SAndreas.Sandberg@ARM.com print "Warning: <fenv.h> not available; " \ 8679651SAndreas.Sandberg@ARM.com "forcing USE_FENV to False in", variant_dir + "." 8689651SAndreas.Sandberg@ARM.com env['USE_FENV'] = False 86912563Sgabeblack@google.com 8709651SAndreas.Sandberg@ARM.com if not env['USE_FENV']: 8719651SAndreas.Sandberg@ARM.com print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 87210841Sandreas.sandberg@arm.com print " FP results may deviate slightly from other platforms." 87312563Sgabeblack@google.com 87412563Sgabeblack@google.com if env['EFENCE']: 87510841Sandreas.sandberg@arm.com env.Append(LIBS=['efence']) 87610841Sandreas.sandberg@arm.com 87710841Sandreas.sandberg@arm.com if env['USE_MYSQL']: 87810860Sandreas.sandberg@arm.com if not have_mysql: 87910841Sandreas.sandberg@arm.com print "Warning: MySQL not available; " \ 88010841Sandreas.sandberg@arm.com "forcing USE_MYSQL to False in", variant_dir + "." 88110841Sandreas.sandberg@arm.com env['USE_MYSQL'] = False 88210841Sandreas.sandberg@arm.com else: 88310841Sandreas.sandberg@arm.com print "Compiling in", variant_dir, "with MySQL support." 88412563Sgabeblack@google.com env.ParseConfig(mysql_config_libs) 88510841Sandreas.sandberg@arm.com env.ParseConfig(mysql_config_include) 88610841Sandreas.sandberg@arm.com 88710841Sandreas.sandberg@arm.com # Save sticky variable settings back to current variables file 88810841Sandreas.sandberg@arm.com sticky_vars.Save(current_vars_file, env) 88910841Sandreas.sandberg@arm.com 8909651SAndreas.Sandberg@ARM.com if env['USE_SSE2']: 8919651SAndreas.Sandberg@ARM.com env.Append(CCFLAGS='-msse2') 8929986Sandreas@sandberg.pp.se 8939986Sandreas@sandberg.pp.se # The src/SConscript file sets up the build rules in 'env' according 8949986Sandreas@sandberg.pp.se # to the configured variables. It returns a list of environments, 8959986Sandreas@sandberg.pp.se # one for each variant build (debug, opt, etc.) 8969986Sandreas@sandberg.pp.se envList = SConscript('src/SConscript', variant_dir = variant_path, 8979986Sandreas@sandberg.pp.se exports = 'env') 8985863Snate@binkert.org 8995863Snate@binkert.org # Set up the regression tests for each build. 9005863Snate@binkert.org for e in envList: 9015863Snate@binkert.org SConscript('tests/SConscript', 9026121Snate@binkert.org variant_dir = joinpath(variant_path, 'tests', e.Label), 9031858SN/A exports = { 'env' : e }, duplicate = False) 9045863Snate@binkert.org 9055863Snate@binkert.orgHelp(help_text) 9065863Snate@binkert.org