SConstruct revision 6108
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 4955SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 5955SN/A# All rights reserved. 6955SN/A# 7955SN/A# Redistribution and use in source and binary forms, with or without 8955SN/A# modification, are permitted provided that the following conditions are 9955SN/A# met: redistributions of source code must retain the above copyright 10955SN/A# notice, this list of conditions and the following disclaimer; 11955SN/A# redistributions in binary form must reproduce the above copyright 12955SN/A# notice, this list of conditions and the following disclaimer in the 13955SN/A# documentation and/or other materials provided with the distribution; 14955SN/A# neither the name of the copyright holders nor the names of its 15955SN/A# contributors may be used to endorse or promote products derived from 16955SN/A# this software without specific prior written permission. 17955SN/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 282665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 292665Ssaidi@eecs.umich.edu# 30955SN/A# Authors: Steve Reinhardt 31955SN/A# Nathan Binkert 32955SN/A 33955SN/A################################################### 34955SN/A# 352632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 362632Sstever@eecs.umich.edu# 372632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 382632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 39955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 402632Sstever@eecs.umich.edu# the optimized full-system version). 412632Sstever@eecs.umich.edu# 422761Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 432632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 442632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 452632Sstever@eecs.umich.edu# built for the same host system. 462761Sstever@eecs.umich.edu# 472761Sstever@eecs.umich.edu# Examples: 482761Sstever@eecs.umich.edu# 492632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 502632Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 512761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 522761Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 532761Sstever@eecs.umich.edu# 542761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 552761Sstever@eecs.umich.edu# 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 572632Sstever@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# 612632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 622632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 63955SN/A# file), you can use 'scons -h' to print all the M5-specific build 64955SN/A# options as well. 65955SN/A# 66955SN/A################################################### 67955SN/A 684202Sbinkertn@umich.edu# Check for recent-enough Python and SCons versions. 694678Snate@binkert.orgtry: 70955SN/A # Really old versions of scons only take two options for the 715273Sstever@gmail.com # function, so check once without the revision and once with the 725273Sstever@gmail.com # revision, the first instance will fail for stuff other than 732656Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 742656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 752656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98, 1) 762656Sstever@eecs.umich.eduexcept SystemExit, e: 772656Sstever@eecs.umich.edu print """ 782656Sstever@eecs.umich.eduFor more details, see: 792656Sstever@eecs.umich.edu http://m5sim.org/wiki/index.php/Compiling_M5 802653Sstever@eecs.umich.edu""" 815227Ssaidi@eecs.umich.edu raise 825227Ssaidi@eecs.umich.edu 835227Ssaidi@eecs.umich.edu# We ensure the python version early because we have stuff that 845227Ssaidi@eecs.umich.edu# requires python 2.4 852653Sstever@eecs.umich.edutry: 862653Sstever@eecs.umich.edu EnsurePythonVersion(2, 4) 872653Sstever@eecs.umich.eduexcept SystemExit, e: 882653Sstever@eecs.umich.edu print """ 892653Sstever@eecs.umich.eduYou can use a non-default installation of the Python interpreter by 902653Sstever@eecs.umich.edueither (1) rearranging your PATH so that scons finds the non-default 912653Sstever@eecs.umich.edu'python' first or (2) explicitly invoking an alternative interpreter 922653Sstever@eecs.umich.eduon the scons script. 932653Sstever@eecs.umich.edu 944781Snate@binkert.orgFor more details, see: 951852SN/A http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 96955SN/A""" 97955SN/A raise 98955SN/A 993717Sstever@eecs.umich.eduimport os 1003716Sstever@eecs.umich.eduimport re 101955SN/Aimport subprocess 1021533SN/Aimport sys 1033716Sstever@eecs.umich.edu 1041533SN/Afrom os import mkdir, environ 1054678Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1064678Snate@binkert.orgfrom os.path import exists, isdir, isfile 1074678Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1084678Snate@binkert.org 1094678Snate@binkert.orgimport SCons 1104678Snate@binkert.orgimport SCons.Node 1114678Snate@binkert.org 1124678Snate@binkert.orgdef read_command(cmd, **kwargs): 1134678Snate@binkert.org """run the command cmd, read the results and return them 1144678Snate@binkert.org this is sorta like `cmd` in shell""" 1154678Snate@binkert.org from subprocess import Popen, PIPE, STDOUT 1164678Snate@binkert.org 1174678Snate@binkert.org if isinstance(cmd, str): 1184678Snate@binkert.org cmd = cmd.split() 1194678Snate@binkert.org 1204678Snate@binkert.org no_exception = 'exception' in kwargs 1214678Snate@binkert.org exception = kwargs.pop('exception', None) 1224678Snate@binkert.org 1234678Snate@binkert.org kwargs.setdefault('shell', False) 1244678Snate@binkert.org kwargs.setdefault('stdout', PIPE) 1254678Snate@binkert.org kwargs.setdefault('stderr', STDOUT) 1264973Ssaidi@eecs.umich.edu kwargs.setdefault('close_fds', True) 1274678Snate@binkert.org try: 1284678Snate@binkert.org subp = Popen(cmd, **kwargs) 1294678Snate@binkert.org except Exception, e: 1304678Snate@binkert.org if no_exception: 1314678Snate@binkert.org return exception 1324678Snate@binkert.org raise 133955SN/A 134955SN/A return subp.communicate()[0] 1352632Sstever@eecs.umich.edu 1362632Sstever@eecs.umich.edu# helper function: compare arrays or strings of version numbers. 137955SN/A# E.g., compare_version((1,3,25), (1,4,1)') 138955SN/A# returns -1, 0, 1 if v1 is <, ==, > v2 139955SN/Adef compare_versions(v1, v2): 140955SN/A def make_version_list(v): 1412632Sstever@eecs.umich.edu if isinstance(v, (list,tuple)): 142955SN/A return v 1432632Sstever@eecs.umich.edu elif isinstance(v, str): 1442632Sstever@eecs.umich.edu return map(lambda x: int(re.match('\d+', x).group()), v.split('.')) 1452632Sstever@eecs.umich.edu else: 1462632Sstever@eecs.umich.edu raise TypeError 1472632Sstever@eecs.umich.edu 1482632Sstever@eecs.umich.edu v1 = make_version_list(v1) 1492632Sstever@eecs.umich.edu v2 = make_version_list(v2) 1503053Sstever@eecs.umich.edu # Compare corresponding elements of lists 1513053Sstever@eecs.umich.edu for n1,n2 in zip(v1, v2): 1523053Sstever@eecs.umich.edu if n1 < n2: return -1 1533053Sstever@eecs.umich.edu if n1 > n2: return 1 1543053Sstever@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1553053Sstever@eecs.umich.edu if len(v1) < len(v2): return -1 1563053Sstever@eecs.umich.edu if len(v1) > len(v2): return 1 1573053Sstever@eecs.umich.edu return 0 1583053Sstever@eecs.umich.edu 1593053Sstever@eecs.umich.edu######################################################################## 1603053Sstever@eecs.umich.edu# 1613053Sstever@eecs.umich.edu# Set up the base build environment. 1623053Sstever@eecs.umich.edu# 1633053Sstever@eecs.umich.edu######################################################################## 1643053Sstever@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1653053Sstever@eecs.umich.edu 'RANLIB' ]) 1662632Sstever@eecs.umich.edu 1672632Sstever@eecs.umich.eduuse_env = {} 1682632Sstever@eecs.umich.edufor key,val in os.environ.iteritems(): 1692632Sstever@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1702632Sstever@eecs.umich.edu use_env[key] = val 1712632Sstever@eecs.umich.edu 1723718Sstever@eecs.umich.eduenv = Environment(ENV=use_env) 1733718Sstever@eecs.umich.eduenv.root = Dir(".") # The current directory (where this file lives). 1743718Sstever@eecs.umich.eduenv.srcdir = Dir("src") # The source directory 1753718Sstever@eecs.umich.edu 1763718Sstever@eecs.umich.edu######################################################################## 1773718Sstever@eecs.umich.edu# 1783718Sstever@eecs.umich.edu# Mercurial Stuff. 1793718Sstever@eecs.umich.edu# 1803718Sstever@eecs.umich.edu# If the M5 directory is a mercurial repository, we should do some 1813718Sstever@eecs.umich.edu# extra things. 1823718Sstever@eecs.umich.edu# 1833718Sstever@eecs.umich.edu######################################################################## 1843718Sstever@eecs.umich.edu 1852634Sstever@eecs.umich.eduhgdir = env.root.Dir(".hg") 1862634Sstever@eecs.umich.edu 1872632Sstever@eecs.umich.edumercurial_style_message = """ 1882638Sstever@eecs.umich.eduYou're missing the M5 style hook. 1892632Sstever@eecs.umich.eduPlease install the hook so we can ensure that all code fits a common style. 1902632Sstever@eecs.umich.edu 1912632Sstever@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc 1922632Sstever@eecs.umich.eduor your personal .hgrc 1932632Sstever@eecs.umich.edu---------------- 1942632Sstever@eecs.umich.edu 1951858SN/A[extensions] 1963716Sstever@eecs.umich.edustyle = %s/util/style.py 1972638Sstever@eecs.umich.edu 1982638Sstever@eecs.umich.edu[hooks] 1992638Sstever@eecs.umich.edupretxncommit.style = python:style.check_whitespace 2002638Sstever@eecs.umich.edu""" % (env.root) 2012638Sstever@eecs.umich.edu 2022638Sstever@eecs.umich.edumercurial_bin_not_found = """ 2032638Sstever@eecs.umich.eduMercurial binary cannot be found, unfortunately this means that we 2043716Sstever@eecs.umich.educannot easily determine the version of M5 that you are running and 2052634Sstever@eecs.umich.eduthis makes error messages more difficult to collect. Please consider 2062634Sstever@eecs.umich.eduinstalling mercurial if you choose to post an error message 207955SN/A""" 2085341Sstever@gmail.com 2095341Sstever@gmail.commercurial_lib_not_found = """ 2105341Sstever@gmail.comMercurial libraries cannot be found, ignoring style hook 2115341Sstever@gmail.comIf you are actually a M5 developer, please fix this and 212955SN/Arun the style hook. It is important. 213955SN/A""" 214955SN/A 215955SN/Ahg_info = "Unknown" 216955SN/Aif hgdir.exists(): 217955SN/A # 1) Grab repository revision if we know it. 218955SN/A cmd = "hg id -n -i -t -b" 2191858SN/A try: 2201858SN/A hg_info = read_command(cmd, cwd=env.root.abspath).strip() 2212632Sstever@eecs.umich.edu except OSError: 222955SN/A print mercurial_bin_not_found 2234494Ssaidi@eecs.umich.edu 2244494Ssaidi@eecs.umich.edu # 2) Ensure that the style hook is in place. 2253716Sstever@eecs.umich.edu try: 2261105SN/A ui = None 2272667Sstever@eecs.umich.edu if ARGUMENTS.get('IGNORE_STYLE') != 'True': 2282667Sstever@eecs.umich.edu from mercurial import ui 2292667Sstever@eecs.umich.edu ui = ui.ui() 2302667Sstever@eecs.umich.edu except ImportError: 2312667Sstever@eecs.umich.edu print mercurial_lib_not_found 2322667Sstever@eecs.umich.edu 2331869SN/A if ui is not None: 2341869SN/A ui.readconfig(hgdir.File('hgrc').abspath) 2351869SN/A style_hook = ui.config('hooks', 'pretxncommit.style', None) 2361869SN/A 2371869SN/A if not style_hook: 2381065SN/A print mercurial_style_message 2395341Sstever@gmail.com sys.exit(1) 2405341Sstever@gmail.comelse: 2415341Sstever@gmail.com print ".hg directory not found" 2425341Sstever@gmail.comenv['HG_INFO'] = hg_info 2435341Sstever@gmail.com 2445341Sstever@gmail.com################################################### 2455341Sstever@gmail.com# 2465341Sstever@gmail.com# Figure out which configurations to set up based on the path(s) of 2475341Sstever@gmail.com# the target(s). 2485341Sstever@gmail.com# 2495341Sstever@gmail.com################################################### 2505341Sstever@gmail.com 2515341Sstever@gmail.com# Find default configuration & binary. 2525341Sstever@gmail.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2535341Sstever@gmail.com 2545341Sstever@gmail.com# helper function: find last occurrence of element in list 2555341Sstever@gmail.comdef rfind(l, elt, offs = -1): 2565341Sstever@gmail.com for i in range(len(l)+offs, 0, -1): 2575341Sstever@gmail.com if l[i] == elt: 2585341Sstever@gmail.com return i 2595341Sstever@gmail.com raise ValueError, "element not found" 2605341Sstever@gmail.com 2615341Sstever@gmail.com# Each target must have 'build' in the interior of the path; the 2625341Sstever@gmail.com# directory below this will determine the build parameters. For 2635341Sstever@gmail.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2645341Sstever@gmail.com# recognize that ALPHA_SE specifies the configuration because it 2655341Sstever@gmail.com# follow 'build' in the bulid path. 2665341Sstever@gmail.com 2675341Sstever@gmail.com# Generate absolute paths to targets so we can see where the build dir is 2685341Sstever@gmail.comif COMMAND_LINE_TARGETS: 2695341Sstever@gmail.com # Ask SCons which directory it was invoked from 2705341Sstever@gmail.com launch_dir = GetLaunchDir() 2715341Sstever@gmail.com # Make targets relative to invocation directory 2725341Sstever@gmail.com abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2735341Sstever@gmail.com COMMAND_LINE_TARGETS] 2745341Sstever@gmail.comelse: 2755341Sstever@gmail.com # Default targets are relative to root of tree 2765341Sstever@gmail.com abs_targets = [ normpath(joinpath(ROOT, str(x))) for x in \ 2775341Sstever@gmail.com DEFAULT_TARGETS] 2785341Sstever@gmail.com 2795341Sstever@gmail.com 2805341Sstever@gmail.com# Generate a list of the unique build roots and configs that the 2815341Sstever@gmail.com# collected targets reference. 2825341Sstever@gmail.comvariant_paths = [] 2835341Sstever@gmail.combuild_root = None 2845341Sstever@gmail.comfor t in abs_targets: 2855341Sstever@gmail.com path_dirs = t.split('/') 2865341Sstever@gmail.com try: 2875341Sstever@gmail.com build_top = rfind(path_dirs, 'build', -2) 2885341Sstever@gmail.com except: 2895341Sstever@gmail.com print "Error: no non-leaf 'build' dir found on target path", t 2905341Sstever@gmail.com Exit(1) 2915341Sstever@gmail.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2925341Sstever@gmail.com if not build_root: 2935341Sstever@gmail.com build_root = this_build_root 2942632Sstever@eecs.umich.edu else: 2955199Sstever@gmail.com if this_build_root != build_root: 2963918Ssaidi@eecs.umich.edu print "Error: build targets not under same build root\n"\ 2973918Ssaidi@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 2983940Ssaidi@eecs.umich.edu Exit(1) 2994781Snate@binkert.org variant_path = joinpath('/',*path_dirs[:build_top+2]) 3004781Snate@binkert.org if variant_path not in variant_paths: 3013918Ssaidi@eecs.umich.edu variant_paths.append(variant_path) 3024781Snate@binkert.org 3034781Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 3043918Ssaidi@eecs.umich.eduif not isdir(build_root): 3054781Snate@binkert.org mkdir(build_root) 3064781Snate@binkert.org 3073940Ssaidi@eecs.umich.eduExport('env') 3083942Ssaidi@eecs.umich.edu 3093940Ssaidi@eecs.umich.eduenv.SConsignFile(joinpath(build_root, "sconsign")) 3103918Ssaidi@eecs.umich.edu 3113918Ssaidi@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 312955SN/A# when you use emacs to edit a file in the target dir, as emacs moves 3131858SN/A# file to file~ then copies to file, breaking the link. Symbolic 3143918Ssaidi@eecs.umich.edu# (soft) links work better. 3153918Ssaidi@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 3163918Ssaidi@eecs.umich.edu 3173918Ssaidi@eecs.umich.edu# 3183940Ssaidi@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 3193940Ssaidi@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 3203918Ssaidi@eecs.umich.edu# 3213918Ssaidi@eecs.umich.edu 3223918Ssaidi@eecs.umich.edu# Variable validators & converters for global sticky variables 3233918Ssaidi@eecs.umich.edudef PathListMakeAbsolute(val): 3243918Ssaidi@eecs.umich.edu if not val: 3253918Ssaidi@eecs.umich.edu return val 3263918Ssaidi@eecs.umich.edu f = lambda p: abspath(expanduser(p)) 3273918Ssaidi@eecs.umich.edu return ':'.join(map(f, val.split(':'))) 3283918Ssaidi@eecs.umich.edu 3293940Ssaidi@eecs.umich.edudef PathListAllExist(key, val, env): 3303918Ssaidi@eecs.umich.edu if not val: 3313918Ssaidi@eecs.umich.edu return 3321851SN/A paths = val.split(':') 3331851SN/A for path in paths: 3341858SN/A if not isdir(path): 3355200Sstever@gmail.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 336955SN/A 3373053Sstever@eecs.umich.eduglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3383053Sstever@eecs.umich.edu 3393053Sstever@eecs.umich.eduglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3403053Sstever@eecs.umich.edu 3413053Sstever@eecs.umich.eduglobal_sticky_vars.AddVariables( 3423053Sstever@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', env['CC'])), 3433053Sstever@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', env['CXX'])), 3443053Sstever@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3453053Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3464742Sstever@eecs.umich.edu ('EXTRAS', 'Add Extra directories to the compilation', '', 3474742Sstever@eecs.umich.edu PathListAllExist, PathListMakeAbsolute) 3483053Sstever@eecs.umich.edu ) 3493053Sstever@eecs.umich.edu 3503053Sstever@eecs.umich.edu# base help text 3513053Sstever@eecs.umich.eduhelp_text = ''' 3523053Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 3533053Sstever@eecs.umich.edu 3543053Sstever@eecs.umich.eduGlobal sticky options: 3553053Sstever@eecs.umich.edu''' 3563053Sstever@eecs.umich.edu 3572667Sstever@eecs.umich.eduhelp_text += global_sticky_vars.GenerateHelpText(env) 3584554Sbinkertn@umich.edu 3594554Sbinkertn@umich.edu# Update env with values from ARGUMENTS & file global_sticky_vars_file 3602667Sstever@eecs.umich.eduglobal_sticky_vars.Update(env) 3614554Sbinkertn@umich.edu 3624554Sbinkertn@umich.edu# Save sticky variable settings back to current variables file 3634554Sbinkertn@umich.eduglobal_sticky_vars.Save(global_sticky_vars_file, env) 3644554Sbinkertn@umich.edu 3654554Sbinkertn@umich.edu# Parse EXTRAS variable to build list of all directories where we're 3664554Sbinkertn@umich.edu# look for sources etc. This list is exported as base_dir_list. 3674554Sbinkertn@umich.edubase_dir = env.srcdir.abspath 3684781Snate@binkert.orgif env['EXTRAS']: 3694554Sbinkertn@umich.edu extras_dir_list = env['EXTRAS'].split(':') 3704554Sbinkertn@umich.eduelse: 3712667Sstever@eecs.umich.edu extras_dir_list = [] 3724554Sbinkertn@umich.edu 3734554Sbinkertn@umich.eduExport('base_dir') 3744554Sbinkertn@umich.eduExport('extras_dir_list') 3754554Sbinkertn@umich.edu 3762667Sstever@eecs.umich.edu# the ext directory should be on the #includes path 3774554Sbinkertn@umich.eduenv.Append(CPPPATH=[Dir('ext')]) 3782667Sstever@eecs.umich.edu 3794554Sbinkertn@umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 3804554Sbinkertn@umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath }) 3812667Sstever@eecs.umich.edu 3822638Sstever@eecs.umich.eduCXX_version = read_command([env['CXX'],'--version'], exception=False) 3832638Sstever@eecs.umich.eduCXX_V = read_command([env['CXX'],'-V'], exception=False) 3842638Sstever@eecs.umich.edu 3853716Sstever@eecs.umich.eduenv['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3863716Sstever@eecs.umich.eduenv['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3871858SN/Aenv['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 3885227Ssaidi@eecs.umich.eduif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3895227Ssaidi@eecs.umich.edu print 'Error: How can we have two at the same time?' 3905227Ssaidi@eecs.umich.edu Exit(1) 3915227Ssaidi@eecs.umich.edu 3925227Ssaidi@eecs.umich.edu# Set up default C++ compiler flags 3935227Ssaidi@eecs.umich.eduif env['GCC']: 3945227Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-pipe') 3955227Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-fno-strict-aliasing') 3965227Ssaidi@eecs.umich.edu env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3975227Ssaidi@eecs.umich.edu env.Append(CXXFLAGS='-Wno-deprecated') 3985227Ssaidi@eecs.umich.eduelif env['ICC']: 3995227Ssaidi@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 4005274Ssaidi@eecs.umich.eduelif env['SUNCC']: 4015227Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-Qoption ccfe') 4025227Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-features=gcc') 4035227Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-features=extensions') 4045204Sstever@gmail.com env.Append(CCFLAGS='-library=stlport4') 4055204Sstever@gmail.com env.Append(CCFLAGS='-xar') 4065204Sstever@gmail.com #env.Append(CCFLAGS='-instances=semiexplicit') 4075204Sstever@gmail.comelse: 4085204Sstever@gmail.com print 'Error: Don\'t know what compiler options to use for your compiler.' 4095204Sstever@gmail.com print ' Please fix SConstruct and src/SConscript and try again.' 4105204Sstever@gmail.com Exit(1) 4115204Sstever@gmail.com 4125204Sstever@gmail.com# Do this after we save setting back, or else we'll tack on an 4135204Sstever@gmail.com# extra 'qdo' every time we run scons. 4145204Sstever@gmail.comif env['BATCH']: 4155204Sstever@gmail.com env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 4165204Sstever@gmail.com env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 4175204Sstever@gmail.com env['AS'] = env['BATCH_CMD'] + ' ' + env['AS'] 4185204Sstever@gmail.com env['AR'] = env['BATCH_CMD'] + ' ' + env['AR'] 4195204Sstever@gmail.com env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB'] 4205204Sstever@gmail.com 4215204Sstever@gmail.comif sys.platform == 'cygwin': 4225204Sstever@gmail.com # cygwin has some header file issues... 4233118Sstever@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 4243118Sstever@eecs.umich.edu 4253118Sstever@eecs.umich.edu# Check for SWIG 4263118Sstever@eecs.umich.eduif not env.has_key('SWIG'): 4273118Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 4283118Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 4293118Sstever@eecs.umich.edu Exit(1) 4303118Sstever@eecs.umich.edu 4313118Sstever@eecs.umich.edu# Check for appropriate SWIG version 4323118Sstever@eecs.umich.eduswig_version = read_command(('swig', '-version'), exception='').split() 4333118Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 4343716Sstever@eecs.umich.eduif len(swig_version) < 3 or \ 4353118Sstever@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 4363118Sstever@eecs.umich.edu print 'Error determining SWIG version.' 4373118Sstever@eecs.umich.edu Exit(1) 4383118Sstever@eecs.umich.edu 4393118Sstever@eecs.umich.edumin_swig_version = '1.3.28' 4403118Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 4413118Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 4423118Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 4433118Sstever@eecs.umich.edu Exit(1) 4443716Sstever@eecs.umich.edu 4453118Sstever@eecs.umich.edu# Set up SWIG flags & scanner 4463118Sstever@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4473118Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=swig_flags) 4483118Sstever@eecs.umich.edu 4493118Sstever@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 4503118Sstever@eecs.umich.edu# stuff for some reason 4513118Sstever@eecs.umich.eduscanners = [] 4523118Sstever@eecs.umich.edufor scanner in env['SCANNERS']: 4533118Sstever@eecs.umich.edu skeys = scanner.skeys 4543118Sstever@eecs.umich.edu if skeys == '.i': 4553483Ssaidi@eecs.umich.edu continue 4563494Ssaidi@eecs.umich.edu 4573494Ssaidi@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4583483Ssaidi@eecs.umich.edu continue 4593483Ssaidi@eecs.umich.edu 4603483Ssaidi@eecs.umich.edu scanners.append(scanner) 4613053Sstever@eecs.umich.edu 4623053Sstever@eecs.umich.edu# add the new swig scanner that we like better 4633918Ssaidi@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 4643053Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4653053Sstever@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4663053Sstever@eecs.umich.edu 4673053Sstever@eecs.umich.edu# replace the scanners list that has what we want 4683053Sstever@eecs.umich.eduenv['SCANNERS'] = scanners 4691858SN/A 4701858SN/A# Add a custom Check function to the Configure context so that we can 4711858SN/A# figure out if the compiler adds leading underscores to global 4721858SN/A# variables. This is needed for the autogenerated asm files that we 4731858SN/A# use for embedding the python code. 4741858SN/Adef CheckLeading(context): 4751859SN/A context.Message("Checking for leading underscore in global variables...") 4761858SN/A # 1) Define a global variable called x from asm so the C compiler 4771858SN/A # won't change the symbol at all. 4781858SN/A # 2) Declare that variable. 4791859SN/A # 3) Use the variable 4801859SN/A # 4811862SN/A # If the compiler prepends an underscore, this will successfully 4823053Sstever@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 4833053Sstever@eecs.umich.edu # was defined by the asm statement. If the compiler does not 4843053Sstever@eecs.umich.edu # prepend an underscore, this will not successfully link because 4853053Sstever@eecs.umich.edu # '_x' will have been defined by assembly, while the C portion of 4861859SN/A # the code will be trying to use 'x' 4871859SN/A ret = context.TryLink(''' 4881859SN/A asm(".globl _x; _x: .byte 0"); 4891859SN/A extern int x; 4901859SN/A int main() { return x; } 4911859SN/A ''', extension=".c") 4921859SN/A context.env.Append(LEADING_UNDERSCORE=ret) 4931859SN/A context.Result(ret) 4941862SN/A return ret 4951859SN/A 4961859SN/A# Platform-specific configuration. Note again that we assume that all 4971859SN/A# builds under a given build root run on the same host platform. 4981858SN/Aconf = Configure(env, 4991858SN/A conf_dir = joinpath(build_root, '.scons_config'), 5002139SN/A log_file = joinpath(build_root, 'scons_config.log'), 5014202Sbinkertn@umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 5024202Sbinkertn@umich.edu 5032139SN/A# Check for leading underscores. Don't really need to worry either 5042155SN/A# way so don't need to check the return code. 5054202Sbinkertn@umich.educonf.CheckLeading() 5064202Sbinkertn@umich.edu 5074202Sbinkertn@umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 5082155SN/Atry: 5091869SN/A import platform 5101869SN/A uname = platform.uname() 5111869SN/A if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 5121869SN/A if int(read_command('sysctl -n hw.cpu64bit_capable')[0]): 5134202Sbinkertn@umich.edu env.Append(CCFLAGS='-arch x86_64') 5144202Sbinkertn@umich.edu env.Append(CFLAGS='-arch x86_64') 5154202Sbinkertn@umich.edu env.Append(LINKFLAGS='-arch x86_64') 5164202Sbinkertn@umich.edu env.Append(ASFLAGS='-arch x86_64') 5174202Sbinkertn@umich.eduexcept: 5184202Sbinkertn@umich.edu pass 5194202Sbinkertn@umich.edu 5204202Sbinkertn@umich.edu# Recent versions of scons substitute a "Null" object for Configure() 5215341Sstever@gmail.com# when configuration isn't necessary, e.g., if the "--help" option is 5225341Sstever@gmail.com# present. Unfortuantely this Null object always returns false, 5235341Sstever@gmail.com# breaking all our configuration checks. We replace it with our own 5245341Sstever@gmail.com# more optimistic null object that returns True instead. 5255341Sstever@gmail.comif not conf: 5264202Sbinkertn@umich.edu def NullCheck(*args, **kwargs): 5274202Sbinkertn@umich.edu return True 5284202Sbinkertn@umich.edu 5294202Sbinkertn@umich.edu class NullConf: 5304202Sbinkertn@umich.edu def __init__(self, env): 5311869SN/A self.env = env 5324202Sbinkertn@umich.edu def Finish(self): 5331869SN/A return self.env 5342508SN/A def __getattr__(self, mname): 5352508SN/A return NullCheck 5362508SN/A 5372508SN/A conf = NullConf(env) 5384202Sbinkertn@umich.edu 5391869SN/A# Find Python include and library directories for embedding the 5401869SN/A# interpreter. For consistency, we will use the same Python 5411869SN/A# installation used to run scons (and thus this script). If you want 5421869SN/A# to link in an alternate version, see above for instructions on how 5431869SN/A# to invoke scons with a different copy of the Python interpreter. 5441869SN/Afrom distutils import sysconfig 5451965SN/A 5461965SN/Apy_getvar = sysconfig.get_config_var 5471965SN/A 5481869SN/Apy_version = 'python' + py_getvar('VERSION') 5491869SN/A 5502733Sktlim@umich.edupy_general_include = sysconfig.get_python_inc() 5511884SN/Apy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5523356Sbinkertn@umich.edupy_includes = [ py_general_include ] 5533356Sbinkertn@umich.eduif py_platform_include != py_general_include: 5543356Sbinkertn@umich.edu py_includes.append(py_platform_include) 5554773Snate@binkert.org 5561869SN/Apy_lib_path = [ py_getvar('LIBDIR') ] 5571858SN/A# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5581869SN/A# shared library in prefix/lib/. 5591869SN/Aif not py_getvar('Py_ENABLE_SHARED'): 5601869SN/A py_lib_path.append('-L' + py_getvar('LIBPL')) 5611858SN/A 5622761Sstever@eecs.umich.edupy_libs = [] 5631869SN/Afor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 5642733Sktlim@umich.edu if lib not in py_libs: 5653584Ssaidi@eecs.umich.edu py_libs.append(lib) 5661869SN/Apy_libs.append('-l' + py_version) 5671869SN/A 5681869SN/Aenv.Append(CPPPATH=py_includes) 5691869SN/Aenv.Append(LIBPATH=py_lib_path) 5701869SN/A 5711869SN/A# verify that this stuff works 5721858SN/Aif not conf.CheckHeader('Python.h', '<>'): 573955SN/A print "Error: can't find Python.h header in", py_includes 574955SN/A Exit(1) 5751869SN/A 5761869SN/Afor lib in py_libs: 5771869SN/A assert lib.startswith('-l') 5781869SN/A lib = lib[2:] 5791869SN/A if not conf.CheckLib(lib): 5801869SN/A print "Error: can't find library %s required by python" % lib 5811869SN/A Exit(1) 5821869SN/A 5831869SN/A# On Solaris you need to use libsocket for socket ops 5841869SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5851869SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5861869SN/A print "Can't find library with socket calls (e.g. accept())" 5871869SN/A Exit(1) 5881869SN/A 5891869SN/A# Check for zlib. If the check passes, libz will be automatically 5901869SN/A# added to the LIBS environment variable. 5911869SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5921869SN/A print 'Error: did not find needed zlib compression library '\ 5931869SN/A 'and/or zlib.h header file.' 5941869SN/A print ' Please install zlib and try again.' 5951869SN/A Exit(1) 5961869SN/A 5971869SN/A# Check for <fenv.h> (C99 FP environment control) 5981869SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 5991869SN/Aif not have_fenv: 6001869SN/A print "Warning: Header file <fenv.h> not found." 6011869SN/A print " This host has no IEEE FP rounding mode control." 6021869SN/A 6031869SN/A###################################################################### 6043716Sstever@eecs.umich.edu# 6053356Sbinkertn@umich.edu# Check for mysql. 6063356Sbinkertn@umich.edu# 6073356Sbinkertn@umich.edumysql_config = WhereIs('mysql_config') 6083356Sbinkertn@umich.eduhave_mysql = bool(mysql_config) 6093356Sbinkertn@umich.edu 6103356Sbinkertn@umich.edu# Check MySQL version. 6114781Snate@binkert.orgif have_mysql: 6121869SN/A mysql_version = read_command(mysql_config + ' --version') 6131869SN/A min_mysql_version = '4.1' 6141869SN/A if compare_versions(mysql_version, min_mysql_version) < 0: 6151869SN/A print 'Warning: MySQL', min_mysql_version, 'or newer required.' 6161869SN/A print ' Version', mysql_version, 'detected.' 6171869SN/A have_mysql = False 6181869SN/A 6192655Sstever@eecs.umich.edu# Set up mysql_config commands. 6202655Sstever@eecs.umich.eduif have_mysql: 6212655Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 6222655Sstever@eecs.umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 6232655Sstever@eecs.umich.edu # older mysql_config versions don't support --include, use 6242655Sstever@eecs.umich.edu # --cflags instead 6252655Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 6262655Sstever@eecs.umich.edu # This seems to work in all versions 6272655Sstever@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 6282655Sstever@eecs.umich.edu 6292655Sstever@eecs.umich.edu###################################################################### 6302655Sstever@eecs.umich.edu# 6312655Sstever@eecs.umich.edu# Finish the configuration 6322655Sstever@eecs.umich.edu# 6332655Sstever@eecs.umich.eduenv = conf.Finish() 6342655Sstever@eecs.umich.edu 6352655Sstever@eecs.umich.edu###################################################################### 6362655Sstever@eecs.umich.edu# 6372655Sstever@eecs.umich.edu# Collect all non-global variables 6382655Sstever@eecs.umich.edu# 6392655Sstever@eecs.umich.edu 6402655Sstever@eecs.umich.eduExport('env') 6412655Sstever@eecs.umich.edu 6422655Sstever@eecs.umich.edu# Define the universe of supported ISAs 6432655Sstever@eecs.umich.eduall_isa_list = [ ] 6442655Sstever@eecs.umich.eduExport('all_isa_list') 6452638Sstever@eecs.umich.edu 6462638Sstever@eecs.umich.edu# Define the universe of supported CPU models 6473716Sstever@eecs.umich.eduall_cpu_list = [ ] 6482638Sstever@eecs.umich.edudefault_cpus = [ ] 6492638Sstever@eecs.umich.eduExport('all_cpu_list', 'default_cpus') 6501869SN/A 6511869SN/A# Sticky variables get saved in the variables file so they persist from 6523546Sgblack@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 6533546Sgblack@eecs.umich.edu# value becomes sticky). 6543546Sgblack@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS) 6553546Sgblack@eecs.umich.eduExport('sticky_vars') 6564202Sbinkertn@umich.edu 6573546Sgblack@eecs.umich.edu# Sticky variables that should be exported 6583546Sgblack@eecs.umich.eduexport_vars = [] 6593546Sgblack@eecs.umich.eduExport('export_vars') 6603546Sgblack@eecs.umich.edu 6613546Sgblack@eecs.umich.edu# Non-sticky variables only apply to the current build. 6624781Snate@binkert.orgnonsticky_vars = Variables(args=ARGUMENTS) 6634781Snate@binkert.orgExport('nonsticky_vars') 6644781Snate@binkert.org 6654781Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 6664781Snate@binkert.org# above variables 6674781Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list: 6684781Snate@binkert.org for root, dirs, files in os.walk(bdir): 6694781Snate@binkert.org if 'SConsopts' in files: 6704781Snate@binkert.org print "Reading", joinpath(root, 'SConsopts') 6714781Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 6724781Snate@binkert.org 6734781Snate@binkert.orgall_isa_list.sort() 6743546Sgblack@eecs.umich.eduall_cpu_list.sort() 6753546Sgblack@eecs.umich.edudefault_cpus.sort() 6763546Sgblack@eecs.umich.edu 6774781Snate@binkert.orgsticky_vars.AddVariables( 6783546Sgblack@eecs.umich.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6793546Sgblack@eecs.umich.edu BoolVariable('FULL_SYSTEM', 'Full-system support', False), 6803546Sgblack@eecs.umich.edu ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 6813546Sgblack@eecs.umich.edu BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6823546Sgblack@eecs.umich.edu BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6833546Sgblack@eecs.umich.edu False), 6843546Sgblack@eecs.umich.edu BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6853546Sgblack@eecs.umich.edu False), 6863546Sgblack@eecs.umich.edu BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 6873546Sgblack@eecs.umich.edu False), 6884202Sbinkertn@umich.edu BoolVariable('SS_COMPATIBLE_FP', 6893546Sgblack@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 6903546Sgblack@eecs.umich.edu False), 6913546Sgblack@eecs.umich.edu BoolVariable('USE_SSE2', 692955SN/A 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 693955SN/A False), 694955SN/A BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 695955SN/A BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6961858SN/A BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 6971858SN/A BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 6981858SN/A ) 6992632Sstever@eecs.umich.edu 7002632Sstever@eecs.umich.edunonsticky_vars.AddVariables( 7014773Snate@binkert.org BoolVariable('update_ref', 'Update test reference outputs', False) 7024773Snate@binkert.org ) 7032632Sstever@eecs.umich.edu 7042632Sstever@eecs.umich.edu# These variables get exported to #defines in config/*.hh (see src/SConscript). 7052632Sstever@eecs.umich.eduexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 7062634Sstever@eecs.umich.edu 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 7072638Sstever@eecs.umich.edu 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 7082023SN/A 7092632Sstever@eecs.umich.edu################################################### 7102632Sstever@eecs.umich.edu# 7112632Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers. 7122632Sstever@eecs.umich.edu# 7132632Sstever@eecs.umich.edu################################################### 7143716Sstever@eecs.umich.edu 7152632Sstever@eecs.umich.edu# This function generates a config header file that #defines the 7162632Sstever@eecs.umich.edu# variable symbol to the current variable setting (0 or 1). The source 7172632Sstever@eecs.umich.edu# operands are the name of the variable and a Value node containing the 7182632Sstever@eecs.umich.edu# value of the variable. 7192632Sstever@eecs.umich.edudef build_config_file(target, source, env): 7202023SN/A (variable, value) = [s.get_contents() for s in source] 7212632Sstever@eecs.umich.edu f = file(str(target[0]), 'w') 7222632Sstever@eecs.umich.edu print >> f, '#define', variable, value 7231889SN/A f.close() 7241889SN/A return None 7252632Sstever@eecs.umich.edu 7262632Sstever@eecs.umich.edu# Generate the message to be printed when building the config file. 7272632Sstever@eecs.umich.edudef build_config_file_string(target, source, env): 7282632Sstever@eecs.umich.edu (variable, value) = [s.get_contents() for s in source] 7293716Sstever@eecs.umich.edu return "Defining %s as %s in %s." % (variable, value, target[0]) 7303716Sstever@eecs.umich.edu 7312632Sstever@eecs.umich.edu# Combine the two functions into a scons Action object. 7322632Sstever@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string) 7332632Sstever@eecs.umich.edu 7342632Sstever@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 7352632Sstever@eecs.umich.edu# we're really doing. 7362632Sstever@eecs.umich.edudef config_emitter(target, source, env): 7372632Sstever@eecs.umich.edu # extract variable name from Builder arg 7382632Sstever@eecs.umich.edu variable = str(target[0]) 7391888SN/A # True target is config header file 7401888SN/A target = joinpath('config', variable.lower() + '.hh') 7411869SN/A val = env[variable] 7421869SN/A if isinstance(val, bool): 7431858SN/A # Force value to 0/1 7445341Sstever@gmail.com val = int(val) 7452598SN/A elif isinstance(val, str): 7462598SN/A val = '"' + val + '"' 7472598SN/A 7482598SN/A # Sources are variable name & value (packaged in SCons Value nodes) 7491858SN/A return ([target], [Value(variable), Value(val)]) 7501858SN/A 7511858SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action) 7521858SN/A 7531858SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 7541858SN/A 7551858SN/A# libelf build is shared across all configs in the build root. 7561858SN/Aenv.SConscript('ext/libelf/SConscript', 7571858SN/A variant_dir = joinpath(build_root, 'libelf')) 7581871SN/A 7591858SN/A# gzstream build is shared across all configs in the build root. 7601858SN/Aenv.SConscript('ext/gzstream/SConscript', 7611858SN/A variant_dir = joinpath(build_root, 'gzstream')) 7621858SN/A 7631858SN/A################################################### 7641858SN/A# 7651858SN/A# This function is used to set up a directory with switching headers 7661858SN/A# 7671858SN/A################################################### 7681858SN/A 7691858SN/Aenv['ALL_ISA_LIST'] = all_isa_list 7701859SN/Adef make_switching_dir(dname, switch_headers, env): 7711859SN/A # Generate the header. target[0] is the full path of the output 7721869SN/A # header to generate. 'source' is a dummy variable, since we get the 7731888SN/A # list of ISAs from env['ALL_ISA_LIST']. 7742632Sstever@eecs.umich.edu def gen_switch_hdr(target, source, env): 7751869SN/A fname = str(target[0]) 7761884SN/A bname = basename(fname) 7771884SN/A f = open(fname, 'w') 7781884SN/A f.write('#include "arch/isa_specific.hh"\n') 7791884SN/A cond = '#if' 7801884SN/A for isa in all_isa_list: 7811884SN/A f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 7821965SN/A % (cond, isa.upper(), dname, isa, bname)) 7831965SN/A cond = '#elif' 7841965SN/A f.write('#else\n#error "THE_ISA not set"\n#endif\n') 7852761Sstever@eecs.umich.edu f.close() 7861869SN/A return 0 7871869SN/A 7882632Sstever@eecs.umich.edu # String to print when generating header 7892667Sstever@eecs.umich.edu def gen_switch_hdr_string(target, source, env): 7901869SN/A return "Generating switch header " + str(target[0]) 7911869SN/A 7922929Sktlim@umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 7932929Sktlim@umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 7943716Sstever@eecs.umich.edu # should get re-executed. 7952929Sktlim@umich.edu switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 796955SN/A varlist=['ALL_ISA_LIST']) 7972598SN/A 7982598SN/A # Instantiate actions for each header 7993546Sgblack@eecs.umich.edu for hdr in switch_headers: 800955SN/A env.Command(hdr, [], switch_hdr_action) 801955SN/AExport('make_switching_dir') 802955SN/A 8031530SN/A################################################### 804955SN/A# 805955SN/A# Define build environments for selected configurations. 806955SN/A# 807################################################### 808 809# rename base env 810base_env = env 811 812for variant_path in variant_paths: 813 print "Building in", variant_path 814 815 # Make a copy of the build-root environment to use for this config. 816 env = base_env.Clone() 817 env['BUILDDIR'] = variant_path 818 819 # variant_dir is the tail component of build path, and is used to 820 # determine the build parameters (e.g., 'ALPHA_SE') 821 (build_root, variant_dir) = splitpath(variant_path) 822 823 # Set env variables according to the build directory config. 824 sticky_vars.files = [] 825 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 826 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 827 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 828 current_vars_file = joinpath(build_root, 'variables', variant_dir) 829 if isfile(current_vars_file): 830 sticky_vars.files.append(current_vars_file) 831 print "Using saved variables file %s" % current_vars_file 832 else: 833 # Build dir-specific variables file doesn't exist. 834 835 # Make sure the directory is there so we can create it later 836 opt_dir = dirname(current_vars_file) 837 if not isdir(opt_dir): 838 mkdir(opt_dir) 839 840 # Get default build variables from source tree. Variables are 841 # normally determined by name of $VARIANT_DIR, but can be 842 # overriden by 'default=' arg on command line. 843 default_vars_file = joinpath('build_opts', 844 ARGUMENTS.get('default', variant_dir)) 845 if isfile(default_vars_file): 846 sticky_vars.files.append(default_vars_file) 847 print "Variables file %s not found,\n using defaults in %s" \ 848 % (current_vars_file, default_vars_file) 849 else: 850 print "Error: cannot find variables file %s or %s" \ 851 % (current_vars_file, default_vars_file) 852 Exit(1) 853 854 # Apply current variable settings to env 855 sticky_vars.Update(env) 856 nonsticky_vars.Update(env) 857 858 help_text += "\nSticky variables for %s:\n" % variant_dir \ 859 + sticky_vars.GenerateHelpText(env) \ 860 + "\nNon-sticky variables for %s:\n" % variant_dir \ 861 + nonsticky_vars.GenerateHelpText(env) 862 863 # Process variable settings. 864 865 if not have_fenv and env['USE_FENV']: 866 print "Warning: <fenv.h> not available; " \ 867 "forcing USE_FENV to False in", variant_dir + "." 868 env['USE_FENV'] = False 869 870 if not env['USE_FENV']: 871 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 872 print " FP results may deviate slightly from other platforms." 873 874 if env['EFENCE']: 875 env.Append(LIBS=['efence']) 876 877 if env['USE_MYSQL']: 878 if not have_mysql: 879 print "Warning: MySQL not available; " \ 880 "forcing USE_MYSQL to False in", variant_dir + "." 881 env['USE_MYSQL'] = False 882 else: 883 print "Compiling in", variant_dir, "with MySQL support." 884 env.ParseConfig(mysql_config_libs) 885 env.ParseConfig(mysql_config_include) 886 887 # Save sticky variable settings back to current variables file 888 sticky_vars.Save(current_vars_file, env) 889 890 if env['USE_SSE2']: 891 env.Append(CCFLAGS='-msse2') 892 893 # The src/SConscript file sets up the build rules in 'env' according 894 # to the configured variables. It returns a list of environments, 895 # one for each variant build (debug, opt, etc.) 896 envList = SConscript('src/SConscript', variant_dir = variant_path, 897 exports = 'env') 898 899 # Set up the regression tests for each build. 900 for e in envList: 901 SConscript('tests/SConscript', 902 variant_dir = joinpath(variant_path, 'tests', e.Label), 903 exports = { 'env' : e }, duplicate = False) 904 905Help(help_text) 906