SConstruct revision 6016:9116be67b6d8
1360SN/A# -*- mode:python -*- 210850SGiacomo.Gabrielli@arm.com 310796Sbrandon.potter@amd.com# Copyright (c) 2009 The Hewlett-Packard Development Company 410027SChris.Adeniyi-Jones@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 510027SChris.Adeniyi-Jones@arm.com# All rights reserved. 610027SChris.Adeniyi-Jones@arm.com# 710027SChris.Adeniyi-Jones@arm.com# Redistribution and use in source and binary forms, with or without 810027SChris.Adeniyi-Jones@arm.com# modification, are permitted provided that the following conditions are 910027SChris.Adeniyi-Jones@arm.com# met: redistributions of source code must retain the above copyright 1010027SChris.Adeniyi-Jones@arm.com# notice, this list of conditions and the following disclaimer; 1110027SChris.Adeniyi-Jones@arm.com# redistributions in binary form must reproduce the above copyright 1210027SChris.Adeniyi-Jones@arm.com# notice, this list of conditions and the following disclaimer in the 1310027SChris.Adeniyi-Jones@arm.com# documentation and/or other materials provided with the distribution; 1410027SChris.Adeniyi-Jones@arm.com# neither the name of the copyright holders nor the names of its 151458SN/A# contributors may be used to endorse or promote products derived from 16360SN/A# this software without specific prior written permission. 17360SN/A# 18360SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19360SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20360SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21360SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22360SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23360SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24360SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25360SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26360SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27360SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28360SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29360SN/A# 30360SN/A# Authors: Steve Reinhardt 31360SN/A# Nathan Binkert 32360SN/A 33360SN/A################################################### 34360SN/A# 35360SN/A# SCons top-level build description (SConstruct) file. 36360SN/A# 37360SN/A# While in this directory ('m5'), just type 'scons' to build the default 38360SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 39360SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 402665Ssaidi@eecs.umich.edu# the optimized full-system version). 412665Ssaidi@eecs.umich.edu# 422665Ssaidi@eecs.umich.edu# You can build M5 in a different directory as long as there is a 43360SN/A# 'build/<CONFIG>' somewhere along the target path. The build system 44360SN/A# expects that all configs under the same build directory are being 451354SN/A# built for the same host system. 461354SN/A# 47360SN/A# Examples: 482764Sstever@eecs.umich.edu# 499202Spalle@lyckegaard.dk# The following two commands are equivalent. The '-u' option tells 509202Spalle@lyckegaard.dk# scons to search up the directory tree for this SConstruct file. 512064SN/A# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 5211799Sbrandon.potter@amd.com# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 5311799Sbrandon.potter@amd.com# 5411799Sbrandon.potter@amd.com# The following two commands are equivalent and demonstrate building 5511799Sbrandon.potter@amd.com# in a directory outside of the source tree. The '-C' option tells 5611799Sbrandon.potter@amd.com# scons to chdir to the specified directory to find this SConstruct 5711799Sbrandon.potter@amd.com# file. 58360SN/A# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 59360SN/A# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 60360SN/A# 61360SN/A# You can use 'scons -H' to print scons options. If you're in this 62360SN/A# 'm5' directory (or use -u or -C to tell scons where to find this 63360SN/A# file), you can use 'scons -h' to print all the M5-specific build 641809SN/A# options as well. 6511800Sbrandon.potter@amd.com# 6611392Sbrandon.potter@amd.com################################################### 671809SN/A 6811392Sbrandon.potter@amd.com# Check for recent-enough Python and SCons versions. 6911383Sbrandon.potter@amd.comtry: 703113Sgblack@eecs.umich.edu # Really old versions of scons only take two options for the 7111799Sbrandon.potter@amd.com # function, so check once without the revision and once with the 7211759Sbrandon.potter@amd.com # revision, the first instance will fail for stuff other than 7311812Sbaz21@cam.ac.uk # 0.98, and the second will fail for 0.98.0 7411812Sbaz21@cam.ac.uk EnsureSConsVersion(0, 98) 7511799Sbrandon.potter@amd.com EnsureSConsVersion(0, 98, 1) 768229Snate@binkert.orgexcept SystemExit, e: 778229Snate@binkert.org print """ 7811594Santhony.gutierrez@amd.comFor more details, see: 797075Snate@binkert.org http://m5sim.org/wiki/index.php/Compiling_M5 808229Snate@binkert.org""" 8111856Sbrandon.potter@amd.com raise 827075Snate@binkert.org 83360SN/A# We ensure the python version early because we have stuff that 8411886Sbrandon.potter@amd.com# requires python 2.4 8511800Sbrandon.potter@amd.comtry: 8611392Sbrandon.potter@amd.com EnsurePythonVersion(2, 4) 872462SN/Aexcept SystemExit, e: 881354SN/A print """ 896216Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 906658Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 912474SN/A'python' first or (2) explicitly invoking an alternative interpreter 922680Sktlim@umich.eduon the scons script. 938229Snate@binkert.org 9411886Sbrandon.potter@amd.comFor more details, see: 9510496Ssteve.reinhardt@amd.com http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 968229Snate@binkert.org""" 9711794Sbrandon.potter@amd.com raise 9811886Sbrandon.potter@amd.com 9910497Ssteve.reinhardt@amd.comimport os 10011794Sbrandon.potter@amd.comimport re 101360SN/Aimport subprocess 102360SN/Aimport sys 103360SN/A 104360SN/Afrom os import mkdir, environ 105360SN/Afrom os.path import abspath, basename, dirname, expanduser, normpath 106360SN/Afrom os.path import exists, isdir, isfile 107360SN/Afrom os.path import join as joinpath, split as splitpath 108360SN/A 109360SN/Aimport SCons 110360SN/Aimport SCons.Node 111378SN/A 1121706SN/Adef read_command(cmd, **kwargs): 11311851Sbrandon.potter@amd.com """run the command cmd, read the results and return them 114378SN/A this is sorta like `cmd` in shell""" 115378SN/A from subprocess import Popen, PIPE, STDOUT 116378SN/A 117378SN/A if isinstance(cmd, str): 118378SN/A cmd = cmd.split() 1191706SN/A 12011851Sbrandon.potter@amd.com no_exception = 'exception' in kwargs 121360SN/A exception = kwargs.pop('exception', None) 12211760Sbrandon.potter@amd.com 12311760Sbrandon.potter@amd.com kwargs.setdefault('shell', False) 12411851Sbrandon.potter@amd.com kwargs.setdefault('stdout', PIPE) 12511760Sbrandon.potter@amd.com kwargs.setdefault('stderr', STDOUT) 1266109Ssanchezd@stanford.edu kwargs.setdefault('close_fds', True) 1271706SN/A try: 12811851Sbrandon.potter@amd.com subp = Popen(cmd, **kwargs) 129378SN/A except Exception, e: 1306109Ssanchezd@stanford.edu if no_exception: 1316109Ssanchezd@stanford.edu return exception 13211851Sbrandon.potter@amd.com raise 1336109Ssanchezd@stanford.edu 13411886Sbrandon.potter@amd.com return subp.communicate()[0] 13511886Sbrandon.potter@amd.com 13611886Sbrandon.potter@amd.com# helper function: compare arrays or strings of version numbers. 13711886Sbrandon.potter@amd.com# E.g., compare_version((1,3,25), (1,4,1)') 138378SN/A# returns -1, 0, 1 if v1 is <, ==, > v2 1391706SN/Adef compare_versions(v1, v2): 14011851Sbrandon.potter@amd.com def make_version_list(v): 141378SN/A if isinstance(v, (list,tuple)): 1425748SSteve.Reinhardt@amd.com return v 1435748SSteve.Reinhardt@amd.com elif isinstance(v, str): 14411851Sbrandon.potter@amd.com return map(lambda x: int(re.match('\d+', x).group()), v.split('.')) 145378SN/A else: 146378SN/A raise TypeError 1471706SN/A 14811851Sbrandon.potter@amd.com v1 = make_version_list(v1) 149378SN/A v2 = make_version_list(v2) 15011886Sbrandon.potter@amd.com # Compare corresponding elements of lists 1511706SN/A for n1,n2 in zip(v1, v2): 15211851Sbrandon.potter@amd.com if n1 < n2: return -1 153378SN/A if n1 > n2: return 1 154378SN/A # all corresponding values are equal... see if one has extra values 1551706SN/A if len(v1) < len(v2): return -1 15611851Sbrandon.potter@amd.com if len(v1) > len(v2): return 1 157378SN/A return 0 158378SN/A 1591706SN/A######################################################################## 16011851Sbrandon.potter@amd.com# 161378SN/A# Set up the base build environment. 1624118Sgblack@eecs.umich.edu# 1634118Sgblack@eecs.umich.edu######################################################################## 16411851Sbrandon.potter@amd.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1654118Sgblack@eecs.umich.edu 'RANLIB' ]) 166378SN/A 1671706SN/Ause_env = {} 16811851Sbrandon.potter@amd.comfor key,val in os.environ.iteritems(): 169378SN/A if key in use_vars or key.startswith("M5"): 170378SN/A use_env[key] = val 1711706SN/A 17211851Sbrandon.potter@amd.comenv = Environment(ENV=use_env) 173360SN/Aenv.root = Dir(".") # The current directory (where this file lives). 1745513SMichael.Adler@intel.comenv.srcdir = Dir("src") # The source directory 1755513SMichael.Adler@intel.com 17611851Sbrandon.potter@amd.com######################################################################## 1775513SMichael.Adler@intel.com# 17810203SAli.Saidi@ARM.com# Mercurial Stuff. 17910203SAli.Saidi@ARM.com# 18011851Sbrandon.potter@amd.com# If the M5 directory is a mercurial repository, we should do some 18110203SAli.Saidi@ARM.com# extra things. 1825513SMichael.Adler@intel.com# 18311851Sbrandon.potter@amd.com######################################################################## 1845513SMichael.Adler@intel.com 185511SN/Ahgdir = env.root.Dir(".hg") 18610633Smichaelupton@gmail.com 18711851Sbrandon.potter@amd.commercurial_style_message = """ 18810633Smichaelupton@gmail.comYou're missing the M5 style hook. 1891706SN/APlease install the hook so we can ensure that all code fits a common style. 19011851Sbrandon.potter@amd.com 191511SN/AAll you'd need to do is add the following lines to your repository .hg/hgrc 1925513SMichael.Adler@intel.comor your personal .hgrc 1935513SMichael.Adler@intel.com---------------- 19411851Sbrandon.potter@amd.com 1955513SMichael.Adler@intel.com[extensions] 196511SN/Astyle = %s/util/style.py 1971706SN/A 19811851Sbrandon.potter@amd.com[hooks] 1991706SN/Apretxncommit.style = python:style.check_whitespace 2001706SN/A""" % (env.root) 2011706SN/A 2021706SN/Amercurial_bin_not_found = """ 20311851Sbrandon.potter@amd.comMercurial binary cannot be found, unfortunately this means that we 2041706SN/Acannot easily determine the version of M5 that you are running and 2051706SN/Athis makes error messages more difficult to collect. Please consider 2061706SN/Ainstalling mercurial if you choose to post an error message 2071706SN/A""" 20811851Sbrandon.potter@amd.com 2091706SN/Amercurial_lib_not_found = """ 210511SN/AMercurial libraries cannot be found, ignoring style hook 2116703Svince@csl.cornell.eduIf you are actually a M5 developer, please fix this and 2126703Svince@csl.cornell.edurun the style hook. It is important. 21311851Sbrandon.potter@amd.com""" 2146703Svince@csl.cornell.edu 2156685Stjones1@inf.ed.ac.ukhg_info = "Unknown" 2166685Stjones1@inf.ed.ac.ukif hgdir.exists(): 21711851Sbrandon.potter@amd.com # 1) Grab repository revision if we know it. 2186685Stjones1@inf.ed.ac.uk cmd = "hg id -n -i -t -b" 2196685Stjones1@inf.ed.ac.uk try: 2205513SMichael.Adler@intel.com hg_info = read_command(cmd, cwd=env.root.abspath).strip() 2215513SMichael.Adler@intel.com except OSError: 22211851Sbrandon.potter@amd.com print mercurial_bin_not_found 2235513SMichael.Adler@intel.com 22411885Sbrandon.potter@amd.com # 2) Ensure that the style hook is in place. 22511885Sbrandon.potter@amd.com try: 22611885Sbrandon.potter@amd.com ui = None 2275513SMichael.Adler@intel.com if ARGUMENTS.get('IGNORE_STYLE') != 'True': 2281999SN/A from mercurial import ui 2291999SN/A ui = ui.ui() 23011851Sbrandon.potter@amd.com except ImportError: 2311999SN/A print mercurial_lib_not_found 23211885Sbrandon.potter@amd.com 23311885Sbrandon.potter@amd.com if ui is not None: 23411885Sbrandon.potter@amd.com ui.readconfig(hgdir.File('hgrc').abspath) 2351999SN/A style_hook = ui.config('hooks', 'pretxncommit.style', None) 2361999SN/A 2371999SN/A if not style_hook: 23811851Sbrandon.potter@amd.com print mercurial_style_message 2391999SN/A sys.exit(1) 2403079Sstever@eecs.umich.eduelse: 2413079Sstever@eecs.umich.edu print ".hg directory not found" 24211851Sbrandon.potter@amd.comenv['HG_INFO'] = hg_info 2433079Sstever@eecs.umich.edu 24411875Sbrandon.potter@amd.com################################################### 2452093SN/A# 24611851Sbrandon.potter@amd.com# Figure out which configurations to set up based on the path(s) of 2472093SN/A# the target(s). 2482687Sksewell@umich.edu# 2492687Sksewell@umich.edu################################################### 25011851Sbrandon.potter@amd.com 2512687Sksewell@umich.edu# Find default configuration & binary. 2522238SN/ADefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2532238SN/A 25411851Sbrandon.potter@amd.com# helper function: find last occurrence of element in list 2552238SN/Adef rfind(l, elt, offs = -1): 2562238SN/A for i in range(len(l)+offs, 0, -1): 2572238SN/A if l[i] == elt: 25811851Sbrandon.potter@amd.com return i 2592238SN/A raise ValueError, "element not found" 2602238SN/A 2612238SN/A# Each target must have 'build' in the interior of the path; the 26211851Sbrandon.potter@amd.com# directory below this will determine the build parameters. For 2632238SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2642238SN/A# recognize that ALPHA_SE specifies the configuration because it 2652238SN/A# follow 'build' in the bulid path. 26611851Sbrandon.potter@amd.com 2672238SN/A# Generate absolute paths to targets so we can see where the build dir is 2682238SN/Aif COMMAND_LINE_TARGETS: 2692238SN/A # Ask SCons which directory it was invoked from 27011851Sbrandon.potter@amd.com launch_dir = GetLaunchDir() 2712238SN/A # Make targets relative to invocation directory 2722238SN/A abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2732238SN/A COMMAND_LINE_TARGETS] 27411851Sbrandon.potter@amd.comelse: 2752238SN/A # Default targets are relative to root of tree 2762238SN/A abs_targets = [ normpath(joinpath(ROOT, str(x))) for x in \ 2772238SN/A DEFAULT_TARGETS] 27811851Sbrandon.potter@amd.com 2792238SN/A 2809455Smitch.hayenga+gem5@gmail.com# Generate a list of the unique build roots and configs that the 2819455Smitch.hayenga+gem5@gmail.com# collected targets reference. 28211851Sbrandon.potter@amd.comvariant_paths = [] 28310203SAli.Saidi@ARM.combuild_root = None 28411851Sbrandon.potter@amd.comfor t in abs_targets: 28511851Sbrandon.potter@amd.com path_dirs = t.split('/') 2869455Smitch.hayenga+gem5@gmail.com try: 2879112Smarc.orr@gmail.com build_top = rfind(path_dirs, 'build', -2) 2889112Smarc.orr@gmail.com except: 2899112Smarc.orr@gmail.com print "Error: no non-leaf 'build' dir found on target path", t 2909112Smarc.orr@gmail.com Exit(1) 2919112Smarc.orr@gmail.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 29211851Sbrandon.potter@amd.com if not build_root: 2939112Smarc.orr@gmail.com build_root = this_build_root 2949112Smarc.orr@gmail.com else: 2959112Smarc.orr@gmail.com if this_build_root != build_root: 2969112Smarc.orr@gmail.com print "Error: build targets not under same build root\n"\ 2979112Smarc.orr@gmail.com " %s\n %s" % (build_root, this_build_root) 2989112Smarc.orr@gmail.com Exit(1) 2999112Smarc.orr@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 3009112Smarc.orr@gmail.com if variant_path not in variant_paths: 3019112Smarc.orr@gmail.com variant_paths.append(variant_path) 3029112Smarc.orr@gmail.com 3039112Smarc.orr@gmail.com# Make sure build_root exists (might not if this is the first build there) 3049112Smarc.orr@gmail.comif not isdir(build_root): 3059112Smarc.orr@gmail.com mkdir(build_root) 3069112Smarc.orr@gmail.com 3079112Smarc.orr@gmail.comExport('env') 30811886Sbrandon.potter@amd.com 3099112Smarc.orr@gmail.comenv.SConsignFile(joinpath(build_root, "sconsign")) 3109112Smarc.orr@gmail.com 3119238Slluc.alvarez@bsc.es# Default duplicate option is to use hard links, but this messes up 3129112Smarc.orr@gmail.com# when you use emacs to edit a file in the target dir, as emacs moves 3139112Smarc.orr@gmail.com# file to file~ then copies to file, breaking the link. Symbolic 3149112Smarc.orr@gmail.com# (soft) links work better. 31511886Sbrandon.potter@amd.comenv.SetOption('duplicate', 'soft-copy') 3169112Smarc.orr@gmail.com 3179112Smarc.orr@gmail.com# 3189112Smarc.orr@gmail.com# Set up global sticky variables... these are common to an entire build 3199112Smarc.orr@gmail.com# tree (not specific to a particular build like ALPHA_SE) 3209112Smarc.orr@gmail.com# 3219112Smarc.orr@gmail.com 32211367Sandreas.hansson@arm.com# Variable validators & converters for global sticky variables 3239112Smarc.orr@gmail.comdef PathListMakeAbsolute(val): 32411321Ssteve.reinhardt@amd.com if not val: 32511886Sbrandon.potter@amd.com return val 3269112Smarc.orr@gmail.com f = lambda p: abspath(expanduser(p)) 3279112Smarc.orr@gmail.com return ':'.join(map(f, val.split(':'))) 3289112Smarc.orr@gmail.com 3299112Smarc.orr@gmail.comdef PathListAllExist(key, val, env): 3309112Smarc.orr@gmail.com if not val: 3319112Smarc.orr@gmail.com return 3329112Smarc.orr@gmail.com paths = val.split(':') 3339112Smarc.orr@gmail.com for path in paths: 3349112Smarc.orr@gmail.com if not isdir(path): 3359112Smarc.orr@gmail.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3369112Smarc.orr@gmail.com 3379112Smarc.orr@gmail.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3389112Smarc.orr@gmail.com 3399112Smarc.orr@gmail.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 34011886Sbrandon.potter@amd.com 34111886Sbrandon.potter@amd.comglobal_sticky_vars.AddVariables( 3429112Smarc.orr@gmail.com ('CC', 'C compiler', environ.get('CC', env['CC'])), 3439112Smarc.orr@gmail.com ('CXX', 'C++ compiler', environ.get('CXX', env['CXX'])), 3449112Smarc.orr@gmail.com ('BATCH', 'Use batch pool for build and tests', False), 3459112Smarc.orr@gmail.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3469112Smarc.orr@gmail.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3479112Smarc.orr@gmail.com PathListAllExist, PathListMakeAbsolute) 3489112Smarc.orr@gmail.com ) 3499112Smarc.orr@gmail.com 3509112Smarc.orr@gmail.com# base help text 3519112Smarc.orr@gmail.comhelp_text = ''' 3529112Smarc.orr@gmail.comUsage: scons [scons options] [build options] [target(s)] 3539112Smarc.orr@gmail.com 35411321Ssteve.reinhardt@amd.comGlobal sticky options: 3559112Smarc.orr@gmail.com''' 3569112Smarc.orr@gmail.com 3579112Smarc.orr@gmail.comhelp_text += global_sticky_vars.GenerateHelpText(env) 3589112Smarc.orr@gmail.com 35911886Sbrandon.potter@amd.com# Update env with values from ARGUMENTS & file global_sticky_vars_file 36011886Sbrandon.potter@amd.comglobal_sticky_vars.Update(env) 36111886Sbrandon.potter@amd.com 3629112Smarc.orr@gmail.com# Save sticky variable settings back to current variables file 3639112Smarc.orr@gmail.comglobal_sticky_vars.Save(global_sticky_vars_file, env) 36411886Sbrandon.potter@amd.com 3659112Smarc.orr@gmail.com# Parse EXTRAS variable to build list of all directories where we're 3669112Smarc.orr@gmail.com# look for sources etc. This list is exported as base_dir_list. 3679112Smarc.orr@gmail.combase_dir = env.srcdir.abspath 3689112Smarc.orr@gmail.comif env['EXTRAS']: 3699112Smarc.orr@gmail.com extras_dir_list = env['EXTRAS'].split(':') 3702238SN/Aelse: 3712238SN/A extras_dir_list = [] 3722238SN/A 3732238SN/AExport('base_dir') 37411851Sbrandon.potter@amd.comExport('extras_dir_list') 3752238SN/A 3762238SN/A# M5_PLY is used by isa_parser.py to find the PLY package. 3772238SN/Aenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath }) 37811851Sbrandon.potter@amd.com 3792238SN/ACXX_version = read_command([env['CXX'],'--version'], exception=False) 3802238SN/ACXX_V = read_command([env['CXX'],'-V'], exception=False) 3812238SN/A 38211851Sbrandon.potter@amd.comenv['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3832238SN/Aenv['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3842238SN/Aenv['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 3852238SN/Aif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 38611851Sbrandon.potter@amd.com print 'Error: How can we have two at the same time?' 3872238SN/A Exit(1) 3882238SN/A 3891354SN/A# Set up default C++ compiler flags 3901354SN/Aif env['GCC']: 39110796Sbrandon.potter@amd.com env.Append(CCFLAGS='-pipe') 39210796Sbrandon.potter@amd.com env.Append(CCFLAGS='-fno-strict-aliasing') 3931354SN/A env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3941354SN/A env.Append(CXXFLAGS='-Wno-deprecated') 3951354SN/Aelif env['ICC']: 3961354SN/A pass #Fix me... add warning flags once we clean up icc warnings 3971354SN/Aelif env['SUNCC']: 3981354SN/A env.Append(CCFLAGS='-Qoption ccfe') 3991354SN/A env.Append(CCFLAGS='-features=gcc') 4001354SN/A env.Append(CCFLAGS='-features=extensions') 4011354SN/A env.Append(CCFLAGS='-library=stlport4') 4021354SN/A env.Append(CCFLAGS='-xar') 40310796Sbrandon.potter@amd.com #env.Append(CCFLAGS='-instances=semiexplicit') 4041354SN/Aelse: 40510796Sbrandon.potter@amd.com print 'Error: Don\'t know what compiler options to use for your compiler.' 4061354SN/A print ' Please fix SConstruct and src/SConscript and try again.' 4071354SN/A Exit(1) 4081354SN/A 4091354SN/A# Do this after we save setting back, or else we'll tack on an 41010796Sbrandon.potter@amd.com# extra 'qdo' every time we run scons. 41110796Sbrandon.potter@amd.comif env['BATCH']: 41210796Sbrandon.potter@amd.com env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 41310796Sbrandon.potter@amd.com env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 41410796Sbrandon.potter@amd.com env['AS'] = env['BATCH_CMD'] + ' ' + env['AS'] 41510796Sbrandon.potter@amd.com env['AR'] = env['BATCH_CMD'] + ' ' + env['AR'] 41610796Sbrandon.potter@amd.com env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB'] 41710796Sbrandon.potter@amd.com 41810796Sbrandon.potter@amd.comif sys.platform == 'cygwin': 41910796Sbrandon.potter@amd.com # cygwin has some header file issues... 42010796Sbrandon.potter@amd.com env.Append(CCFLAGS=Split("-Wno-uninitialized")) 421360SN/Aenv.Append(CPPPATH=[Dir('ext/dnet')]) 422360SN/A 423360SN/A# Check for SWIG 424360SN/Aif not env.has_key('SWIG'): 425360SN/A print 'Error: SWIG utility not found.' 426360SN/A print ' Please install (see http://www.swig.org) and retry.' 427360SN/A Exit(1) 42811759Sbrandon.potter@amd.com 4293113Sgblack@eecs.umich.edu# Check for appropriate SWIG version 4303113Sgblack@eecs.umich.eduswig_version = read_command(('swig', '-version'), exception='').split() 4313113Sgblack@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 4323113Sgblack@eecs.umich.eduif len(swig_version) < 3 or \ 4333113Sgblack@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 4343113Sgblack@eecs.umich.edu print 'Error determining SWIG version.' 4353113Sgblack@eecs.umich.edu Exit(1) 4363113Sgblack@eecs.umich.edu 4373113Sgblack@eecs.umich.edumin_swig_version = '1.3.28' 4383113Sgblack@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 4393113Sgblack@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 4403113Sgblack@eecs.umich.edu print ' Installed version:', swig_version[2] 4413113Sgblack@eecs.umich.edu Exit(1) 4423113Sgblack@eecs.umich.edu 4433113Sgblack@eecs.umich.edu# Set up SWIG flags & scanner 4443113Sgblack@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4454189Sgblack@eecs.umich.eduenv.Append(SWIGFLAGS=swig_flags) 4464189Sgblack@eecs.umich.edu 4473113Sgblack@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 4483113Sgblack@eecs.umich.edu# stuff for some reason 4493113Sgblack@eecs.umich.eduscanners = [] 4503113Sgblack@eecs.umich.edufor scanner in env['SCANNERS']: 4518737Skoansin.tan@gmail.com skeys = scanner.skeys 4523113Sgblack@eecs.umich.edu if skeys == '.i': 4538737Skoansin.tan@gmail.com continue 4543277Sgblack@eecs.umich.edu 4555515SMichael.Adler@intel.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4565515SMichael.Adler@intel.com continue 4575515SMichael.Adler@intel.com 4585515SMichael.Adler@intel.com scanners.append(scanner) 4595515SMichael.Adler@intel.com 4608737Skoansin.tan@gmail.com# add the new swig scanner that we like better 4613277Sgblack@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 4628737Skoansin.tan@gmail.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4633277Sgblack@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4648737Skoansin.tan@gmail.com 4653277Sgblack@eecs.umich.edu# replace the scanners list that has what we want 4668737Skoansin.tan@gmail.comenv['SCANNERS'] = scanners 4673113Sgblack@eecs.umich.edu 4683113Sgblack@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 4693113Sgblack@eecs.umich.edu# figure out if the compiler adds leading underscores to global 4703113Sgblack@eecs.umich.edu# variables. This is needed for the autogenerated asm files that we 4718737Skoansin.tan@gmail.com# use for embedding the python code. 4723113Sgblack@eecs.umich.edudef CheckLeading(context): 4738737Skoansin.tan@gmail.com context.Message("Checking for leading underscore in global variables...") 4743114Sgblack@eecs.umich.edu # 1) Define a global variable called x from asm so the C compiler 4758737Skoansin.tan@gmail.com # won't change the symbol at all. 4763114Sgblack@eecs.umich.edu # 2) Declare that variable. 4778737Skoansin.tan@gmail.com # 3) Use the variable 4783114Sgblack@eecs.umich.edu # 4798737Skoansin.tan@gmail.com # If the compiler prepends an underscore, this will successfully 4804061Sgblack@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 4814061Sgblack@eecs.umich.edu # was defined by the asm statement. If the compiler does not 4824061Sgblack@eecs.umich.edu # prepend an underscore, this will not successfully link because 4838737Skoansin.tan@gmail.com # '_x' will have been defined by assembly, while the C portion of 4843113Sgblack@eecs.umich.edu # the code will be trying to use 'x' 4858737Skoansin.tan@gmail.com ret = context.TryLink(''' 4863113Sgblack@eecs.umich.edu asm(".globl _x; _x: .byte 0"); 4873113Sgblack@eecs.umich.edu extern int x; 4883113Sgblack@eecs.umich.edu int main() { return x; } 4893113Sgblack@eecs.umich.edu ''', extension=".c") 4903113Sgblack@eecs.umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 4913113Sgblack@eecs.umich.edu context.Result(ret) 4923113Sgblack@eecs.umich.edu return ret 4933113Sgblack@eecs.umich.edu 4944189Sgblack@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 4954189Sgblack@eecs.umich.edu# builds under a given build root run on the same host platform. 4963113Sgblack@eecs.umich.educonf = Configure(env, 4973113Sgblack@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 4983113Sgblack@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 4998737Skoansin.tan@gmail.com custom_tests = { 'CheckLeading' : CheckLeading }) 5003113Sgblack@eecs.umich.edu 5018737Skoansin.tan@gmail.com# Check for leading underscores. Don't really need to worry either 5023113Sgblack@eecs.umich.edu# way so don't need to check the return code. 5038737Skoansin.tan@gmail.comconf.CheckLeading() 5043113Sgblack@eecs.umich.edu 5053113Sgblack@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 5063113Sgblack@eecs.umich.edutry: 5073113Sgblack@eecs.umich.edu import platform 5083113Sgblack@eecs.umich.edu uname = platform.uname() 5093113Sgblack@eecs.umich.edu if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 5103113Sgblack@eecs.umich.edu if int(read_command('sysctl -n hw.cpu64bit_capable')[0]): 5113113Sgblack@eecs.umich.edu env.Append(CCFLAGS='-arch x86_64') 5123113Sgblack@eecs.umich.edu env.Append(CFLAGS='-arch x86_64') 5133113Sgblack@eecs.umich.edu env.Append(LINKFLAGS='-arch x86_64') 5148852Sandreas.hansson@arm.com env.Append(ASFLAGS='-arch x86_64') 5153113Sgblack@eecs.umich.eduexcept: 5163113Sgblack@eecs.umich.edu pass 5173113Sgblack@eecs.umich.edu 5183113Sgblack@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 5193113Sgblack@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 5203113Sgblack@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 5213113Sgblack@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 5223113Sgblack@eecs.umich.edu# more optimistic null object that returns True instead. 5233113Sgblack@eecs.umich.eduif not conf: 5243113Sgblack@eecs.umich.edu def NullCheck(*args, **kwargs): 5258852Sandreas.hansson@arm.com return True 5263113Sgblack@eecs.umich.edu 5273113Sgblack@eecs.umich.edu class NullConf: 5283113Sgblack@eecs.umich.edu def __init__(self, env): 5293113Sgblack@eecs.umich.edu self.env = env 5306686Stjones1@inf.ed.ac.uk def Finish(self): 5313113Sgblack@eecs.umich.edu return self.env 5323113Sgblack@eecs.umich.edu def __getattr__(self, mname): 5333113Sgblack@eecs.umich.edu return NullCheck 53411759Sbrandon.potter@amd.com 53511759Sbrandon.potter@amd.com conf = NullConf(env) 53611759Sbrandon.potter@amd.com 53711759Sbrandon.potter@amd.com# Find Python include and library directories for embedding the 53811759Sbrandon.potter@amd.com# interpreter. For consistency, we will use the same Python 53911759Sbrandon.potter@amd.com# installation used to run scons (and thus this script). If you want 54011759Sbrandon.potter@amd.com# to link in an alternate version, see above for instructions on how 54111812Sbaz21@cam.ac.uk# to invoke scons with a different copy of the Python interpreter. 54211812Sbaz21@cam.ac.ukfrom distutils import sysconfig 54311812Sbaz21@cam.ac.uk 54411759Sbrandon.potter@amd.compy_getvar = sysconfig.get_config_var 54511812Sbaz21@cam.ac.uk 54611759Sbrandon.potter@amd.compy_version = 'python' + py_getvar('VERSION') 54711759Sbrandon.potter@amd.com 54811759Sbrandon.potter@amd.compy_general_include = sysconfig.get_python_inc() 54911759Sbrandon.potter@amd.compy_platform_include = sysconfig.get_python_inc(plat_specific=True) 55011759Sbrandon.potter@amd.compy_includes = [ py_general_include ] 55111759Sbrandon.potter@amd.comif py_platform_include != py_general_include: 55211759Sbrandon.potter@amd.com py_includes.append(py_platform_include) 55311812Sbaz21@cam.ac.uk 55411812Sbaz21@cam.ac.ukpy_lib_path = [ py_getvar('LIBDIR') ] 55511812Sbaz21@cam.ac.uk# add the prefix/lib/pythonX.Y/config dir, but only if there is no 55611812Sbaz21@cam.ac.uk# shared library in prefix/lib/. 55711812Sbaz21@cam.ac.ukif not py_getvar('Py_ENABLE_SHARED'): 55811812Sbaz21@cam.ac.uk py_lib_path.append('-L' + py_getvar('LIBPL')) 55911812Sbaz21@cam.ac.uk 56011759Sbrandon.potter@amd.compy_libs = [] 56111759Sbrandon.potter@amd.comfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 56211812Sbaz21@cam.ac.uk if lib not in py_libs: 56311812Sbaz21@cam.ac.uk py_libs.append(lib) 56411759Sbrandon.potter@amd.compy_libs.append('-l' + py_version) 56511812Sbaz21@cam.ac.uk 56611812Sbaz21@cam.ac.ukenv.Append(CPPPATH=py_includes) 56711812Sbaz21@cam.ac.ukenv.Append(LIBPATH=py_lib_path) 56811812Sbaz21@cam.ac.uk 56911812Sbaz21@cam.ac.uk# verify that this stuff works 57011812Sbaz21@cam.ac.ukif not conf.CheckHeader('Python.h', '<>'): 57111812Sbaz21@cam.ac.uk print "Error: can't find Python.h header in", py_includes 57211759Sbrandon.potter@amd.com Exit(1) 57311759Sbrandon.potter@amd.com 57411759Sbrandon.potter@amd.comfor lib in py_libs: 57511759Sbrandon.potter@amd.com assert lib.startswith('-l') 576378SN/A lib = lib[2:] 577378SN/A if not conf.CheckLib(lib): 5789141Smarc.orr@gmail.com print "Error: can't find library %s required by python" % lib 5799141Smarc.orr@gmail.com Exit(1) 580360SN/A 5811450SN/A# On Solaris you need to use libsocket for socket ops 58211856Sbrandon.potter@amd.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 583360SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5846701Sgblack@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 58511856Sbrandon.potter@amd.com Exit(1) 58611856Sbrandon.potter@amd.com 587360SN/A# Check for zlib. If the check passes, libz will be automatically 58810930Sbrandon.potter@amd.com# added to the LIBS environment variable. 589360SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 59011856Sbrandon.potter@amd.com print 'Error: did not find needed zlib compression library '\ 59111856Sbrandon.potter@amd.com 'and/or zlib.h header file.' 59210496Ssteve.reinhardt@amd.com print ' Please install zlib and try again.' 59311856Sbrandon.potter@amd.com Exit(1) 59411856Sbrandon.potter@amd.com 5951458SN/A# Check for <fenv.h> (C99 FP environment control) 596360SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 59711856Sbrandon.potter@amd.comif not have_fenv: 59811856Sbrandon.potter@amd.com print "Warning: Header file <fenv.h> not found." 59911856Sbrandon.potter@amd.com print " This host has no IEEE FP rounding mode control." 60011856Sbrandon.potter@amd.com 60111856Sbrandon.potter@amd.com###################################################################### 60211856Sbrandon.potter@amd.com# 60311856Sbrandon.potter@amd.com# Check for mysql. 60411856Sbrandon.potter@amd.com# 60510496Ssteve.reinhardt@amd.commysql_config = WhereIs('mysql_config') 60611856Sbrandon.potter@amd.comhave_mysql = bool(mysql_config) 60711856Sbrandon.potter@amd.com 60811856Sbrandon.potter@amd.com# Check MySQL version. 60911856Sbrandon.potter@amd.comif have_mysql: 61011856Sbrandon.potter@amd.com mysql_version = read_command(mysql_config + ' --version') 61110930Sbrandon.potter@amd.com min_mysql_version = '4.1' 6129141Smarc.orr@gmail.com if compare_versions(mysql_version, min_mysql_version) < 0: 613360SN/A print 'Warning: MySQL', min_mysql_version, 'or newer required.' 614360SN/A print ' Version', mysql_version, 'detected.' 615360SN/A have_mysql = False 61610027SChris.Adeniyi-Jones@arm.com 61711851Sbrandon.potter@amd.com# Set up mysql_config commands. 61810027SChris.Adeniyi-Jones@arm.comif have_mysql: 619360SN/A mysql_config_include = mysql_config + ' --include' 620360SN/A if os.system(mysql_config_include + ' > /dev/null') != 0: 621360SN/A # older mysql_config versions don't support --include, use 6228852Sandreas.hansson@arm.com # --cflags instead 6236701Sgblack@eecs.umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 6241458SN/A # This seems to work in all versions 625360SN/A mysql_config_libs = mysql_config + ' --libs' 6266701Sgblack@eecs.umich.edu 6276701Sgblack@eecs.umich.edu###################################################################### 628360SN/A# 629360SN/A# Finish the configuration 630360SN/A# 631360SN/Aenv = conf.Finish() 632360SN/A 633360SN/A###################################################################### 634360SN/A# 635360SN/A# Collect all non-global variables 636360SN/A# 637360SN/A 638360SN/AExport('env') 639360SN/A 6401706SN/A# Define the universe of supported ISAs 641360SN/Aall_isa_list = [ ] 642360SN/AExport('all_isa_list') 643360SN/A 644360SN/A# Define the universe of supported CPU models 645360SN/Aall_cpu_list = [ ] 6463669Sbinkertn@umich.edudefault_cpus = [ ] 6473669Sbinkertn@umich.eduExport('all_cpu_list', 'default_cpus') 6483669Sbinkertn@umich.edu 6491706SN/A# Sticky variables get saved in the variables file so they persist from 6501706SN/A# one invocation to the next (unless overridden, in which case the new 65110496Ssteve.reinhardt@amd.com# value becomes sticky). 65210496Ssteve.reinhardt@amd.comsticky_vars = Variables(args=ARGUMENTS) 65310496Ssteve.reinhardt@amd.comExport('sticky_vars') 65410496Ssteve.reinhardt@amd.com 65510496Ssteve.reinhardt@amd.com# Non-sticky variables only apply to the current build. 65610496Ssteve.reinhardt@amd.comnonsticky_vars = Variables(args=ARGUMENTS) 65710496Ssteve.reinhardt@amd.comExport('nonsticky_vars') 65810496Ssteve.reinhardt@amd.com 65910496Ssteve.reinhardt@amd.com# Walk the tree and execute all SConsopts scripts that wil add to the 66010496Ssteve.reinhardt@amd.com# above variables 66111856Sbrandon.potter@amd.comfor bdir in [ base_dir ] + extras_dir_list: 66210496Ssteve.reinhardt@amd.com for root, dirs, files in os.walk(bdir): 66310496Ssteve.reinhardt@amd.com if 'SConsopts' in files: 66410496Ssteve.reinhardt@amd.com print "Reading", joinpath(root, 'SConsopts') 66510496Ssteve.reinhardt@amd.com SConscript(joinpath(root, 'SConsopts')) 66610496Ssteve.reinhardt@amd.com 66710496Ssteve.reinhardt@amd.comall_isa_list.sort() 66810496Ssteve.reinhardt@amd.comall_cpu_list.sort() 66910496Ssteve.reinhardt@amd.comdefault_cpus.sort() 67010496Ssteve.reinhardt@amd.com 6715795Ssaidi@eecs.umich.edusticky_vars.AddVariables( 6729143Ssteve.reinhardt@amd.com EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6739142Ssteve.reinhardt@amd.com BoolVariable('FULL_SYSTEM', 'Full-system support', False), 6749142Ssteve.reinhardt@amd.com ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 6759143Ssteve.reinhardt@amd.com BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6765795Ssaidi@eecs.umich.edu BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6779143Ssteve.reinhardt@amd.com False), 6785795Ssaidi@eecs.umich.edu BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6795795Ssaidi@eecs.umich.edu False), 6805795Ssaidi@eecs.umich.edu BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 6819143Ssteve.reinhardt@amd.com False), 6825795Ssaidi@eecs.umich.edu BoolVariable('SS_COMPATIBLE_FP', 683360SN/A 'Make floating-point results compatible with SimpleScalar', 6849143Ssteve.reinhardt@amd.com False), 6859143Ssteve.reinhardt@amd.com BoolVariable('USE_SSE2', 6869143Ssteve.reinhardt@amd.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 68711856Sbrandon.potter@amd.com False), 68811856Sbrandon.potter@amd.com BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 68911856Sbrandon.potter@amd.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 690360SN/A BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 691360SN/A BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 69210027SChris.Adeniyi-Jones@arm.com ) 69310027SChris.Adeniyi-Jones@arm.com 69410027SChris.Adeniyi-Jones@arm.comnonsticky_vars.AddVariables( 69511851Sbrandon.potter@amd.com BoolVariable('update_ref', 'Update test reference outputs', False) 69610027SChris.Adeniyi-Jones@arm.com ) 69710027SChris.Adeniyi-Jones@arm.com 69810027SChris.Adeniyi-Jones@arm.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 69910027SChris.Adeniyi-Jones@arm.comenv.ExportVariables = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 70010027SChris.Adeniyi-Jones@arm.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 70110027SChris.Adeniyi-Jones@arm.com 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 70210027SChris.Adeniyi-Jones@arm.com 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 70310027SChris.Adeniyi-Jones@arm.com 70411851Sbrandon.potter@amd.com################################################### 70511851Sbrandon.potter@amd.com# 70610027SChris.Adeniyi-Jones@arm.com# Define a SCons builder for configuration flag headers. 70710027SChris.Adeniyi-Jones@arm.com# 70810027SChris.Adeniyi-Jones@arm.com################################################### 70910027SChris.Adeniyi-Jones@arm.com 71010027SChris.Adeniyi-Jones@arm.com# This function generates a config header file that #defines the 71110027SChris.Adeniyi-Jones@arm.com# variable symbol to the current variable setting (0 or 1). The source 71210027SChris.Adeniyi-Jones@arm.com# operands are the name of the variable and a Value node containing the 71310027SChris.Adeniyi-Jones@arm.com# value of the variable. 71410633Smichaelupton@gmail.comdef build_config_file(target, source, env): 71510633Smichaelupton@gmail.com (variable, value) = [s.get_contents() for s in source] 71610633Smichaelupton@gmail.com f = file(str(target[0]), 'w') 71711851Sbrandon.potter@amd.com print >> f, '#define', variable, value 71810633Smichaelupton@gmail.com f.close() 71910633Smichaelupton@gmail.com return None 72010633Smichaelupton@gmail.com 72110633Smichaelupton@gmail.com# Generate the message to be printed when building the config file. 72210633Smichaelupton@gmail.comdef build_config_file_string(target, source, env): 72310633Smichaelupton@gmail.com (variable, value) = [s.get_contents() for s in source] 72410633Smichaelupton@gmail.com return "Defining %s as %s in %s." % (variable, value, target[0]) 72510633Smichaelupton@gmail.com 72610633Smichaelupton@gmail.com# Combine the two functions into a scons Action object. 72710633Smichaelupton@gmail.comconfig_action = Action(build_config_file, build_config_file_string) 72810203SAli.Saidi@ARM.com 72910203SAli.Saidi@ARM.com# The emitter munges the source & target node lists to reflect what 73010203SAli.Saidi@ARM.com# we're really doing. 73111851Sbrandon.potter@amd.comdef config_emitter(target, source, env): 73211851Sbrandon.potter@amd.com # extract variable name from Builder arg 73310203SAli.Saidi@ARM.com variable = str(target[0]) 73410203SAli.Saidi@ARM.com # True target is config header file 73510203SAli.Saidi@ARM.com target = joinpath('config', variable.lower() + '.hh') 73610203SAli.Saidi@ARM.com val = env[variable] 73710203SAli.Saidi@ARM.com if isinstance(val, bool): 73810203SAli.Saidi@ARM.com # Force value to 0/1 73910203SAli.Saidi@ARM.com val = int(val) 74010203SAli.Saidi@ARM.com elif isinstance(val, str): 74110203SAli.Saidi@ARM.com val = '"' + val + '"' 74210203SAli.Saidi@ARM.com 74310203SAli.Saidi@ARM.com # Sources are variable name & value (packaged in SCons Value nodes) 74411851Sbrandon.potter@amd.com return ([target], [Value(variable), Value(val)]) 74511851Sbrandon.potter@amd.com 74610203SAli.Saidi@ARM.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 74710203SAli.Saidi@ARM.com 74810203SAli.Saidi@ARM.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 74910203SAli.Saidi@ARM.com 75010203SAli.Saidi@ARM.com# libelf build is shared across all configs in the build root. 75110203SAli.Saidi@ARM.comenv.SConscript('ext/libelf/SConscript', 75210203SAli.Saidi@ARM.com variant_dir = joinpath(build_root, 'libelf')) 75310203SAli.Saidi@ARM.com 75410850SGiacomo.Gabrielli@arm.com# gzstream build is shared across all configs in the build root. 75510850SGiacomo.Gabrielli@arm.comenv.SConscript('ext/gzstream/SConscript', 75610850SGiacomo.Gabrielli@arm.com variant_dir = joinpath(build_root, 'gzstream')) 75711851Sbrandon.potter@amd.com 75810850SGiacomo.Gabrielli@arm.com################################################### 75910850SGiacomo.Gabrielli@arm.com# 76010850SGiacomo.Gabrielli@arm.com# This function is used to set up a directory with switching headers 76110850SGiacomo.Gabrielli@arm.com# 76210850SGiacomo.Gabrielli@arm.com################################################### 76310850SGiacomo.Gabrielli@arm.com 76410850SGiacomo.Gabrielli@arm.comenv['ALL_ISA_LIST'] = all_isa_list 76510850SGiacomo.Gabrielli@arm.comdef make_switching_dir(dname, switch_headers, env): 76610850SGiacomo.Gabrielli@arm.com # Generate the header. target[0] is the full path of the output 76710850SGiacomo.Gabrielli@arm.com # header to generate. 'source' is a dummy variable, since we get the 76810850SGiacomo.Gabrielli@arm.com # list of ISAs from env['ALL_ISA_LIST']. 76910850SGiacomo.Gabrielli@arm.com def gen_switch_hdr(target, source, env): 77010850SGiacomo.Gabrielli@arm.com fname = str(target[0]) 77110850SGiacomo.Gabrielli@arm.com bname = basename(fname) 77210850SGiacomo.Gabrielli@arm.com f = open(fname, 'w') 77310850SGiacomo.Gabrielli@arm.com f.write('#include "arch/isa_specific.hh"\n') 77410850SGiacomo.Gabrielli@arm.com cond = '#if' 77510850SGiacomo.Gabrielli@arm.com for isa in all_isa_list: 77610850SGiacomo.Gabrielli@arm.com f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 77710850SGiacomo.Gabrielli@arm.com % (cond, isa.upper(), dname, isa, bname)) 77810850SGiacomo.Gabrielli@arm.com cond = '#elif' 77910850SGiacomo.Gabrielli@arm.com f.write('#else\n#error "THE_ISA not set"\n#endif\n') 78010850SGiacomo.Gabrielli@arm.com f.close() 78110850SGiacomo.Gabrielli@arm.com return 0 78210850SGiacomo.Gabrielli@arm.com 78310850SGiacomo.Gabrielli@arm.com # String to print when generating header 78410850SGiacomo.Gabrielli@arm.com def gen_switch_hdr_string(target, source, env): 78510850SGiacomo.Gabrielli@arm.com return "Generating switch header " + str(target[0]) 78610850SGiacomo.Gabrielli@arm.com 78710850SGiacomo.Gabrielli@arm.com # Build SCons Action object. 'varlist' specifies env vars that this 78810850SGiacomo.Gabrielli@arm.com # action depends on; when env['ALL_ISA_LIST'] changes these actions 78910850SGiacomo.Gabrielli@arm.com # should get re-executed. 7906640Svince@csl.cornell.edu switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 7916640Svince@csl.cornell.edu varlist=['ALL_ISA_LIST']) 7926640Svince@csl.cornell.edu 79311851Sbrandon.potter@amd.com # Instantiate actions for each header 79411851Sbrandon.potter@amd.com for hdr in switch_headers: 7956640Svince@csl.cornell.edu env.Command(hdr, [], switch_hdr_action) 7966640Svince@csl.cornell.eduExport('make_switching_dir') 7976701Sgblack@eecs.umich.edu 7986701Sgblack@eecs.umich.edu################################################### 79910793Sbrandon.potter@amd.com# 8006640Svince@csl.cornell.edu# Define build environments for selected configurations. 80111758Sbrandon.potter@amd.com# 80211758Sbrandon.potter@amd.com################################################### 80311758Sbrandon.potter@amd.com 8046640Svince@csl.cornell.edu# rename base env 8058706Sandreas.hansson@arm.combase_env = env 8066640Svince@csl.cornell.edu 8076701Sgblack@eecs.umich.edufor variant_path in variant_paths: 8086640Svince@csl.cornell.edu print "Building in", variant_path 809360SN/A 8101999SN/A # Make a copy of the build-root environment to use for this config. 8111999SN/A env = base_env.Clone() 8121999SN/A env['BUILDDIR'] = variant_path 81311851Sbrandon.potter@amd.com 8142680Sktlim@umich.edu # variant_dir is the tail component of build path, and is used to 8151999SN/A # determine the build parameters (e.g., 'ALPHA_SE') 8161999SN/A (build_root, variant_dir) = splitpath(variant_path) 8171999SN/A 8186701Sgblack@eecs.umich.edu # Set env variables according to the build directory config. 8198852Sandreas.hansson@arm.com sticky_vars.files = [] 8206701Sgblack@eecs.umich.edu # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 8211999SN/A # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 8226701Sgblack@eecs.umich.edu # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 8231999SN/A current_vars_file = joinpath(build_root, 'variables', variant_dir) 8246701Sgblack@eecs.umich.edu if isfile(current_vars_file): 8251999SN/A sticky_vars.files.append(current_vars_file) 8261999SN/A print "Using saved variables file %s" % current_vars_file 8271999SN/A else: 8281999SN/A # Build dir-specific variables file doesn't exist. 8291999SN/A 8303669Sbinkertn@umich.edu # Make sure the directory is there so we can create it later 8313669Sbinkertn@umich.edu opt_dir = dirname(current_vars_file) 8323669Sbinkertn@umich.edu if not isdir(opt_dir): 8331999SN/A mkdir(opt_dir) 8341999SN/A 8351999SN/A # Get default build variables from source tree. Variables are 8362218SN/A # normally determined by name of $VARIANT_DIR, but can be 8371999SN/A # overriden by 'default=' arg on command line. 8381999SN/A default_vars_file = joinpath('build_opts', 8391999SN/A ARGUMENTS.get('default', variant_dir)) 8401999SN/A if isfile(default_vars_file): 8411999SN/A sticky_vars.files.append(default_vars_file) 8421999SN/A print "Variables file %s not found,\n using defaults in %s" \ 8431999SN/A % (current_vars_file, default_vars_file) 8441999SN/A else: 84511856Sbrandon.potter@amd.com print "Error: cannot find variables file %s or %s" \ 8461999SN/A % (current_vars_file, default_vars_file) 8476701Sgblack@eecs.umich.edu Exit(1) 84811856Sbrandon.potter@amd.com 84911856Sbrandon.potter@amd.com # Apply current variable settings to env 85010931Sbrandon.potter@amd.com sticky_vars.Update(env) 85111856Sbrandon.potter@amd.com nonsticky_vars.Update(env) 85211856Sbrandon.potter@amd.com 8531999SN/A help_text += "\nSticky variables for %s:\n" % variant_dir \ 85411856Sbrandon.potter@amd.com + sticky_vars.GenerateHelpText(env) \ 8551999SN/A + "\nNon-sticky variables for %s:\n" % variant_dir \ 85611856Sbrandon.potter@amd.com + nonsticky_vars.GenerateHelpText(env) 8571999SN/A 85811856Sbrandon.potter@amd.com # Process variable settings. 8591999SN/A 86011856Sbrandon.potter@amd.com if not have_fenv and env['USE_FENV']: 8611999SN/A print "Warning: <fenv.h> not available; " \ 8621999SN/A "forcing USE_FENV to False in", variant_dir + "." 8635877Shsul@eecs.umich.edu env['USE_FENV'] = False 8645877Shsul@eecs.umich.edu 8655877Shsul@eecs.umich.edu if not env['USE_FENV']: 86611851Sbrandon.potter@amd.com print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 8675877Shsul@eecs.umich.edu print " FP results may deviate slightly from other platforms." 8686701Sgblack@eecs.umich.edu 8696701Sgblack@eecs.umich.edu if env['EFENCE']: 8706701Sgblack@eecs.umich.edu env.Append(LIBS=['efence']) 8716701Sgblack@eecs.umich.edu 8726701Sgblack@eecs.umich.edu if env['USE_MYSQL']: 87310027SChris.Adeniyi-Jones@arm.com if not have_mysql: 87410027SChris.Adeniyi-Jones@arm.com print "Warning: MySQL not available; " \ 87510027SChris.Adeniyi-Jones@arm.com "forcing USE_MYSQL to False in", variant_dir + "." 87610027SChris.Adeniyi-Jones@arm.com env['USE_MYSQL'] = False 87710027SChris.Adeniyi-Jones@arm.com else: 8785877Shsul@eecs.umich.edu print "Compiling in", variant_dir, "with MySQL support." 87910318Sandreas.hansson@arm.com env.ParseConfig(mysql_config_libs) 88010318Sandreas.hansson@arm.com env.ParseConfig(mysql_config_include) 8815877Shsul@eecs.umich.edu 8825877Shsul@eecs.umich.edu # Save sticky variable settings back to current variables file 8835877Shsul@eecs.umich.edu sticky_vars.Save(current_vars_file, env) 8845877Shsul@eecs.umich.edu 88510486Stjablin@gmail.com if env['USE_SSE2']: 88610486Stjablin@gmail.com env.Append(CCFLAGS='-msse2') 8875877Shsul@eecs.umich.edu 88811905SBrandon.Potter@amd.com # The src/SConscript file sets up the build rules in 'env' according 88911905SBrandon.Potter@amd.com # to the configured variables. It returns a list of environments, 89011905SBrandon.Potter@amd.com # one for each variant build (debug, opt, etc.) 89111905SBrandon.Potter@amd.com envList = SConscript('src/SConscript', variant_dir = variant_path, 89210027SChris.Adeniyi-Jones@arm.com exports = 'env') 8935877Shsul@eecs.umich.edu 89411905SBrandon.Potter@amd.com # Set up the regression tests for each build. 89511905SBrandon.Potter@amd.com for e in envList: 8965877Shsul@eecs.umich.edu SConscript('tests/SConscript', 8975877Shsul@eecs.umich.edu variant_dir = joinpath(variant_path, 'tests', e.Label), 89810027SChris.Adeniyi-Jones@arm.com exports = { 'env' : e }, duplicate = False) 8995877Shsul@eecs.umich.edu 9005877Shsul@eecs.umich.eduHelp(help_text) 9015877Shsul@eecs.umich.edu