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