SConstruct revision 5522
1955SN/A# -*- mode:python -*- 2955SN/A 35871Snate@binkert.org# Copyright (c) 2004-2005 The Regents of The University of Michigan 41762SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28955SN/A# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 302665Ssaidi@eecs.umich.edu 315863Snate@binkert.org################################################### 32955SN/A# 33955SN/A# SCons top-level build description (SConstruct) file. 34955SN/A# 35955SN/A# While in this directory ('m5'), just type 'scons' to build the default 36955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 372632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 382632Sstever@eecs.umich.edu# the optimized full-system version). 392632Sstever@eecs.umich.edu# 402632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 41955SN/A# 'build/<CONFIG>' somewhere along the target path. The build system 422632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 432632Sstever@eecs.umich.edu# built for the same host system. 442761Sstever@eecs.umich.edu# 452632Sstever@eecs.umich.edu# Examples: 462632Sstever@eecs.umich.edu# 472632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 482761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 492761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 502761Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512632Sstever@eecs.umich.edu# 522632Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 532761Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 542761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 552761Sstever@eecs.umich.edu# file. 562761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 572761Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 582632Sstever@eecs.umich.edu# 592632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 602632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 622632Sstever@eecs.umich.edu# options as well. 632632Sstever@eecs.umich.edu# 642632Sstever@eecs.umich.edu################################################### 65955SN/A 66955SN/Aimport sys 67955SN/Aimport os 685863Snate@binkert.orgimport re 695863Snate@binkert.org 705863Snate@binkert.orgfrom os.path import isdir, isfile, join as joinpath 715863Snate@binkert.org 725863Snate@binkert.orgimport SCons 735863Snate@binkert.org 745863Snate@binkert.org# Check for recent-enough Python and SCons versions. If your system's 755863Snate@binkert.org# default installation of Python is not recent enough, you can use a 765863Snate@binkert.org# non-default installation of the Python interpreter by either (1) 775863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python' 785863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the 795863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 805863Snate@binkert.orgEnsurePythonVersion(2,4) 815863Snate@binkert.org 825863Snate@binkert.org# Import subprocess after we check the version since it doesn't exist in 835863Snate@binkert.org# Python < 2.4. 845863Snate@binkert.orgimport subprocess 855863Snate@binkert.org 865863Snate@binkert.org# helper function: compare arrays or strings of version numbers. 875863Snate@binkert.org# E.g., compare_version((1,3,25), (1,4,1)') 885863Snate@binkert.org# returns -1, 0, 1 if v1 is <, ==, > v2 895863Snate@binkert.orgdef compare_versions(v1, v2): 905863Snate@binkert.org def make_version_list(v): 915863Snate@binkert.org if isinstance(v, (list,tuple)): 925863Snate@binkert.org return v 935863Snate@binkert.org elif isinstance(v, str): 945863Snate@binkert.org return map(int, v.split('.')) 955863Snate@binkert.org else: 965863Snate@binkert.org raise TypeError 975863Snate@binkert.org 985863Snate@binkert.org v1 = make_version_list(v1) 996654Snate@binkert.org v2 = make_version_list(v2) 100955SN/A # Compare corresponding elements of lists 1015396Ssaidi@eecs.umich.edu for n1,n2 in zip(v1, v2): 1025863Snate@binkert.org if n1 < n2: return -1 1035863Snate@binkert.org if n1 > n2: return 1 1044202Sbinkertn@umich.edu # all corresponding values are equal... see if one has extra values 1055863Snate@binkert.org if len(v1) < len(v2): return -1 1065863Snate@binkert.org if len(v1) > len(v2): return 1 1075863Snate@binkert.org return 0 1085863Snate@binkert.org 109955SN/A# SCons version numbers need special processing because they can have 1106654Snate@binkert.org# charecters and an release date embedded in them. This function does 1115273Sstever@gmail.com# the magic to extract them in a similar way to the SCons internal function 1125871Snate@binkert.org# function does and then checks that the current version is not contained in 1135273Sstever@gmail.com# a list of version tuples (bad_ver_strs) 1146655Snate@binkert.orgdef CheckSCons(bad_ver_strs): 1156655Snate@binkert.org def scons_ver(v): 1166655Snate@binkert.org num_parts = v.split(' ')[0].split('.') 1176655Snate@binkert.org major = int(num_parts[0]) 1186655Snate@binkert.org minor = int(re.match('\d+', num_parts[1]).group()) 1196655Snate@binkert.org rev = 0 1205871Snate@binkert.org rdate = 0 1216654Snate@binkert.org if len(num_parts) > 2: 1225396Ssaidi@eecs.umich.edu try: rev = int(re.match('\d+', num_parts[2]).group()) 1235871Snate@binkert.org except: pass 1245871Snate@binkert.org rev_parts = num_parts[2].split('d') 1256121Snate@binkert.org if len(rev_parts) > 1: 1265871Snate@binkert.org rdate = int(re.match('\d+', rev_parts[1]).group()) 1275871Snate@binkert.org 1286003Snate@binkert.org return (major, minor, rev, rdate) 1296655Snate@binkert.org 130955SN/A sc_ver = scons_ver(SCons.__version__) 1315871Snate@binkert.org for bad_ver in bad_ver_strs: 1325871Snate@binkert.org bv = (scons_ver(bad_ver[0]), scons_ver(bad_ver[1])) 1335871Snate@binkert.org if compare_versions(sc_ver, bv[0]) != -1 and\ 1345871Snate@binkert.org compare_versions(sc_ver, bv[1]) != 1: 135955SN/A print "The version of SCons that you have installed: ", SCons.__version__ 1366121Snate@binkert.org print "has a bug that prevents it from working correctly with M5." 1376121Snate@binkert.org print "Please install a version NOT contained within the following", 1386121Snate@binkert.org print "ranges (inclusive):" 1391533SN/A for bad_ver in bad_ver_strs: 1406655Snate@binkert.org print " %s - %s" % bad_ver 1416655Snate@binkert.org Exit(2) 1426655Snate@binkert.org 1436655Snate@binkert.orgCheckSCons(( 1445871Snate@binkert.org # We need a version that is 0.96.91 or newer 1455871Snate@binkert.org ('0.0.0', '0.96.90'), 1465863Snate@binkert.org )) 1475871Snate@binkert.org 1485871Snate@binkert.org 1495871Snate@binkert.org# The absolute path to the current directory (where this file lives). 1505871Snate@binkert.orgROOT = Dir('.').abspath 1515871Snate@binkert.org 1525863Snate@binkert.org# Path to the M5 source tree. 1536121Snate@binkert.orgSRCDIR = joinpath(ROOT, 'src') 1545863Snate@binkert.org 1555871Snate@binkert.org# tell python where to find m5 python code 1564678Snate@binkert.orgsys.path.append(joinpath(ROOT, 'src/python')) 1574678Snate@binkert.org 1584678Snate@binkert.orgdef check_style_hook(ui): 1594678Snate@binkert.org ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 1604678Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) 1614678Snate@binkert.org 1624678Snate@binkert.org if not style_hook: 1634678Snate@binkert.org print """\ 1644678Snate@binkert.orgYou're missing the M5 style hook. 1654678Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style. 1664678Snate@binkert.org 1674678Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc 1686121Snate@binkert.orgor your personal .hgrc 1694678Snate@binkert.org---------------- 1705871Snate@binkert.org 1715871Snate@binkert.org[extensions] 1725871Snate@binkert.orgstyle = %s/util/style.py 1735871Snate@binkert.org 1745871Snate@binkert.org[hooks] 1755871Snate@binkert.orgpretxncommit.style = python:style.check_whitespace 1765871Snate@binkert.org""" % (ROOT) 1775871Snate@binkert.org sys.exit(1) 1785871Snate@binkert.org 1795871Snate@binkert.orgif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1805871Snate@binkert.org try: 1815871Snate@binkert.org from mercurial import ui 1825871Snate@binkert.org check_style_hook(ui.ui()) 1835990Ssaidi@eecs.umich.edu except ImportError: 1845871Snate@binkert.org pass 1855871Snate@binkert.org 1865871Snate@binkert.org################################################### 1874678Snate@binkert.org# 1886654Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 1895871Snate@binkert.org# the target(s). 1905871Snate@binkert.org# 1915871Snate@binkert.org################################################### 1925871Snate@binkert.org 1935871Snate@binkert.org# Find default configuration & binary. 1945871Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1955871Snate@binkert.org 1965871Snate@binkert.org# helper function: find last occurrence of element in list 1975871Snate@binkert.orgdef rfind(l, elt, offs = -1): 1984678Snate@binkert.org for i in range(len(l)+offs, 0, -1): 1995871Snate@binkert.org if l[i] == elt: 2004678Snate@binkert.org return i 2015871Snate@binkert.org raise ValueError, "element not found" 2025871Snate@binkert.org 2035871Snate@binkert.org# Each target must have 'build' in the interior of the path; the 2045871Snate@binkert.org# directory below this will determine the build parameters. For 2055871Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2065871Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 2075871Snate@binkert.org# follow 'build' in the bulid path. 2085871Snate@binkert.org 2095871Snate@binkert.org# Generate absolute paths to targets so we can see where the build dir is 2106121Snate@binkert.orgif COMMAND_LINE_TARGETS: 2116121Snate@binkert.org # Ask SCons which directory it was invoked from 2125863Snate@binkert.org launch_dir = GetLaunchDir() 213955SN/A # Make targets relative to invocation directory 214955SN/A abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 2152632Sstever@eecs.umich.edu COMMAND_LINE_TARGETS) 2162632Sstever@eecs.umich.eduelse: 217955SN/A # Default targets are relative to root of tree 218955SN/A abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 219955SN/A DEFAULT_TARGETS) 220955SN/A 2215863Snate@binkert.org 222955SN/A# Generate a list of the unique build roots and configs that the 2232632Sstever@eecs.umich.edu# collected targets reference. 2242632Sstever@eecs.umich.edubuild_paths = [] 2252632Sstever@eecs.umich.edubuild_root = None 2262632Sstever@eecs.umich.edufor t in abs_targets: 2272632Sstever@eecs.umich.edu path_dirs = t.split('/') 2282632Sstever@eecs.umich.edu try: 2292632Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 2302632Sstever@eecs.umich.edu except: 2312632Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 2322632Sstever@eecs.umich.edu Exit(1) 2332632Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2342632Sstever@eecs.umich.edu if not build_root: 2352632Sstever@eecs.umich.edu build_root = this_build_root 2363718Sstever@eecs.umich.edu else: 2373718Sstever@eecs.umich.edu if this_build_root != build_root: 2383718Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 2393718Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 2403718Sstever@eecs.umich.edu Exit(1) 2415863Snate@binkert.org build_path = joinpath('/',*path_dirs[:build_top+2]) 2425863Snate@binkert.org if build_path not in build_paths: 2433718Sstever@eecs.umich.edu build_paths.append(build_path) 2443718Sstever@eecs.umich.edu 2456121Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 2465863Snate@binkert.orgif not isdir(build_root): 2473718Sstever@eecs.umich.edu os.mkdir(build_root) 2483718Sstever@eecs.umich.edu 2492634Sstever@eecs.umich.edu################################################### 2502634Sstever@eecs.umich.edu# 2515863Snate@binkert.org# Set up the default build environment. This environment is copied 2522638Sstever@eecs.umich.edu# and modified according to each selected configuration. 2532632Sstever@eecs.umich.edu# 2542632Sstever@eecs.umich.edu################################################### 2552632Sstever@eecs.umich.edu 2562632Sstever@eecs.umich.eduenv = Environment(ENV = os.environ, # inherit user's environment vars 2572632Sstever@eecs.umich.edu ROOT = ROOT, 2582632Sstever@eecs.umich.edu SRCDIR = SRCDIR) 2591858SN/A 2603716Sstever@eecs.umich.eduExport('env') 2612638Sstever@eecs.umich.edu 2622638Sstever@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign")) 2632638Sstever@eecs.umich.edu 2642638Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 2652638Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 2662638Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2672638Sstever@eecs.umich.edu# (soft) links work better. 2685863Snate@binkert.orgenv.SetOption('duplicate', 'soft-copy') 2695863Snate@binkert.org 2705863Snate@binkert.org# I waffle on this setting... it does avoid a few painful but 271955SN/A# unnecessary builds, but it also seems to make trivial builds take 2725341Sstever@gmail.com# noticeably longer. 2735341Sstever@gmail.comif False: 2745863Snate@binkert.org env.TargetSignatures('content') 2755341Sstever@gmail.com 2766121Snate@binkert.org# 2774494Ssaidi@eecs.umich.edu# Set up global sticky options... these are common to an entire build 2786121Snate@binkert.org# tree (not specific to a particular build like ALPHA_SE) 2791105SN/A# 2802667Sstever@eecs.umich.edu 2812667Sstever@eecs.umich.edu# Option validators & converters for global sticky options 2822667Sstever@eecs.umich.edudef PathListMakeAbsolute(val): 2832667Sstever@eecs.umich.edu if not val: 2846121Snate@binkert.org return val 2852667Sstever@eecs.umich.edu f = lambda p: os.path.abspath(os.path.expanduser(p)) 2865341Sstever@gmail.com return ':'.join(map(f, val.split(':'))) 2875863Snate@binkert.org 2885341Sstever@gmail.comdef PathListAllExist(key, val, env): 2895341Sstever@gmail.com if not val: 2905341Sstever@gmail.com return 2915863Snate@binkert.org paths = val.split(':') 2925341Sstever@gmail.com for path in paths: 2935341Sstever@gmail.com if not isdir(path): 2945341Sstever@gmail.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 2955863Snate@binkert.org 2965341Sstever@gmail.comglobal_sticky_opts_file = joinpath(build_root, 'options.global') 2975341Sstever@gmail.com 2985341Sstever@gmail.comglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS) 2995341Sstever@gmail.com 3005341Sstever@gmail.comglobal_sticky_opts.AddOptions( 3015341Sstever@gmail.com ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3025341Sstever@gmail.com ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3035341Sstever@gmail.com ('BATCH', 'Use batch pool for build and tests', False), 3045341Sstever@gmail.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3055341Sstever@gmail.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3065863Snate@binkert.org PathListAllExist, PathListMakeAbsolute) 3075341Sstever@gmail.com ) 3085863Snate@binkert.org 3095341Sstever@gmail.com 3105863Snate@binkert.org# base help text 3116121Snate@binkert.orghelp_text = ''' 3126121Snate@binkert.orgUsage: scons [scons options] [build options] [target(s)] 3135397Ssaidi@eecs.umich.edu 3145397Ssaidi@eecs.umich.edu''' 3155341Sstever@gmail.com 3166168Snate@binkert.orghelp_text += "Global sticky options:\n" \ 3176168Snate@binkert.org + global_sticky_opts.GenerateHelpText(env) 3186168Snate@binkert.org 3195341Sstever@gmail.com# Update env with values from ARGUMENTS & file global_sticky_opts_file 3205341Sstever@gmail.comglobal_sticky_opts.Update(env) 3215341Sstever@gmail.com 3225341Sstever@gmail.com# Save sticky option settings back to current options file 3235341Sstever@gmail.comglobal_sticky_opts.Save(global_sticky_opts_file, env) 3245863Snate@binkert.org 3255341Sstever@gmail.com# Parse EXTRAS option to build list of all directories where we're 3265341Sstever@gmail.com# look for sources etc. This list is exported as base_dir_list. 3276121Snate@binkert.orgbase_dir_list = [joinpath(ROOT, 'src')] 3286121Snate@binkert.orgif env['EXTRAS']: 3295341Sstever@gmail.com base_dir_list += env['EXTRAS'].split(':') 3306814Sgblack@eecs.umich.edu 3316814Sgblack@eecs.umich.eduExport('base_dir_list') 3325863Snate@binkert.org 3336121Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package. 3345341Sstever@gmail.comenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 3355863Snate@binkert.orgenv['GCC'] = False 3365341Sstever@gmail.comenv['SUNCC'] = False 3376121Snate@binkert.orgenv['ICC'] = False 3386121Snate@binkert.orgenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 3396121Snate@binkert.org stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3405742Snate@binkert.org close_fds=True).communicate()[0].find('GCC') >= 0 3415742Snate@binkert.orgenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3425341Sstever@gmail.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3435742Snate@binkert.org close_fds=True).communicate()[0].find('Sun C++') >= 0 3445742Snate@binkert.orgenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3455341Sstever@gmail.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3466017Snate@binkert.org close_fds=True).communicate()[0].find('Intel') >= 0 3476121Snate@binkert.orgif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3486017Snate@binkert.org print 'Error: How can we have two at the same time?' 3496654Snate@binkert.org Exit(1) 3506654Snate@binkert.org 3515871Snate@binkert.org 3526121Snate@binkert.org# Set up default C++ compiler flags 3536121Snate@binkert.orgif env['GCC']: 3546121Snate@binkert.org env.Append(CCFLAGS='-pipe') 3556121Snate@binkert.org env.Append(CCFLAGS='-fno-strict-aliasing') 3563940Ssaidi@eecs.umich.edu env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3573918Ssaidi@eecs.umich.eduelif env['ICC']: 3583918Ssaidi@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 3591858SN/Aelif env['SUNCC']: 3606121Snate@binkert.org env.Append(CCFLAGS='-Qoption ccfe') 3616121Snate@binkert.org env.Append(CCFLAGS='-features=gcc') 3626121Snate@binkert.org env.Append(CCFLAGS='-features=extensions') 3636143Snate@binkert.org env.Append(CCFLAGS='-library=stlport4') 3646121Snate@binkert.org env.Append(CCFLAGS='-xar') 3656121Snate@binkert.org# env.Append(CCFLAGS='-instances=semiexplicit') 3663940Ssaidi@eecs.umich.eduelse: 3676121Snate@binkert.org print 'Error: Don\'t know what compiler options to use for your compiler.' 3686121Snate@binkert.org print ' Please fix SConstruct and src/SConscript and try again.' 3696121Snate@binkert.org Exit(1) 3706121Snate@binkert.org 3716121Snate@binkert.org# Do this after we save setting back, or else we'll tack on an 3726121Snate@binkert.org# extra 'qdo' every time we run scons. 3736121Snate@binkert.orgif env['BATCH']: 3743918Ssaidi@eecs.umich.edu env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 3753918Ssaidi@eecs.umich.edu env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 3763940Ssaidi@eecs.umich.edu 3773918Ssaidi@eecs.umich.eduif sys.platform == 'cygwin': 3783918Ssaidi@eecs.umich.edu # cygwin has some header file issues... 3796157Snate@binkert.org env.Append(CCFLAGS=Split("-Wno-uninitialized")) 3806157Snate@binkert.orgenv.Append(CPPPATH=[Dir('ext/dnet')]) 3816157Snate@binkert.org 3826157Snate@binkert.org# Check for SWIG 3835397Ssaidi@eecs.umich.eduif not env.has_key('SWIG'): 3845397Ssaidi@eecs.umich.edu print 'Error: SWIG utility not found.' 3856121Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 3866121Snate@binkert.org Exit(1) 3876121Snate@binkert.org 3886121Snate@binkert.org# Check for appropriate SWIG version 3896121Snate@binkert.orgswig_version = os.popen('swig -version').read().split() 3906121Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 3915397Ssaidi@eecs.umich.eduif len(swig_version) < 3 or \ 3921851SN/A swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 3931851SN/A print 'Error determining SWIG version.' 3946655Snate@binkert.org Exit(1) 395955SN/A 3963053Sstever@eecs.umich.edumin_swig_version = '1.3.28' 3976121Snate@binkert.orgif compare_versions(swig_version[2], min_swig_version) < 0: 3983053Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 3993053Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 4003053Sstever@eecs.umich.edu Exit(1) 4013053Sstever@eecs.umich.edu 4023053Sstever@eecs.umich.edu# Set up SWIG flags & scanner 4036654Snate@binkert.orgswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4043053Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=swig_flags) 4054742Sstever@eecs.umich.edu 4064742Sstever@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 4073053Sstever@eecs.umich.edu# stuff for some reason 4083053Sstever@eecs.umich.eduscanners = [] 4093053Sstever@eecs.umich.edufor scanner in env['SCANNERS']: 4103053Sstever@eecs.umich.edu skeys = scanner.skeys 4116654Snate@binkert.org if skeys == '.i': 4123053Sstever@eecs.umich.edu continue 4133053Sstever@eecs.umich.edu 4143053Sstever@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4153053Sstever@eecs.umich.edu continue 4162667Sstever@eecs.umich.edu 4174554Sbinkertn@umich.edu scanners.append(scanner) 4186121Snate@binkert.org 4192667Sstever@eecs.umich.edu# add the new swig scanner that we like better 4204554Sbinkertn@umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 4214554Sbinkertn@umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4224554Sbinkertn@umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4236121Snate@binkert.org 4244554Sbinkertn@umich.edu# replace the scanners list that has what we want 4254554Sbinkertn@umich.eduenv['SCANNERS'] = scanners 4264554Sbinkertn@umich.edu 4274781Snate@binkert.org# Add a custom Check function to the Configure context so that we can 4284554Sbinkertn@umich.edu# figure out if the compiler adds leading underscores to global 4294554Sbinkertn@umich.edu# variables. This is needed for the autogenerated asm files that we 4302667Sstever@eecs.umich.edu# use for embedding the python code. 4314554Sbinkertn@umich.edudef CheckLeading(context): 4324554Sbinkertn@umich.edu context.Message("Checking for leading underscore in global variables...") 4334554Sbinkertn@umich.edu # 1) Define a global variable called x from asm so the C compiler 4344554Sbinkertn@umich.edu # won't change the symbol at all. 4352667Sstever@eecs.umich.edu # 2) Declare that variable. 4364554Sbinkertn@umich.edu # 3) Use the variable 4372667Sstever@eecs.umich.edu # 4384554Sbinkertn@umich.edu # If the compiler prepends an underscore, this will successfully 4396121Snate@binkert.org # link because the external symbol 'x' will be called '_x' which 4402667Sstever@eecs.umich.edu # was defined by the asm statement. If the compiler does not 4415522Snate@binkert.org # prepend an underscore, this will not successfully link because 4425522Snate@binkert.org # '_x' will have been defined by assembly, while the C portion of 4435522Snate@binkert.org # the code will be trying to use 'x' 4445522Snate@binkert.org ret = context.TryLink(''' 4455522Snate@binkert.org asm(".globl _x; _x: .byte 0"); 4465522Snate@binkert.org extern int x; 4475522Snate@binkert.org int main() { return x; } 4485522Snate@binkert.org ''', extension=".c") 4495522Snate@binkert.org context.env.Append(LEADING_UNDERSCORE=ret) 4505522Snate@binkert.org context.Result(ret) 4515522Snate@binkert.org return ret 4525522Snate@binkert.org 4535522Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 4545522Snate@binkert.org# builds under a given build root run on the same host platform. 4555522Snate@binkert.orgconf = Configure(env, 4565522Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 4575522Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 4585522Snate@binkert.org custom_tests = { 'CheckLeading' : CheckLeading }) 4595522Snate@binkert.org 4605522Snate@binkert.org# Check for leading underscores. Don't really need to worry either 4615522Snate@binkert.org# way so don't need to check the return code. 4625522Snate@binkert.orgconf.CheckLeading() 4635522Snate@binkert.org 4645522Snate@binkert.org# Check if we should compile a 64 bit binary on Mac OS X/Darwin 4655522Snate@binkert.orgtry: 4665522Snate@binkert.org import platform 4672638Sstever@eecs.umich.edu uname = platform.uname() 4682638Sstever@eecs.umich.edu if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 4696121Snate@binkert.org if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 4703716Sstever@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 4715522Snate@binkert.org close_fds=True).communicate()[0][0]): 4725522Snate@binkert.org env.Append(CCFLAGS='-arch x86_64') 4735522Snate@binkert.org env.Append(CFLAGS='-arch x86_64') 4745522Snate@binkert.org env.Append(LINKFLAGS='-arch x86_64') 4755522Snate@binkert.org env.Append(ASFLAGS='-arch x86_64') 4765522Snate@binkert.orgexcept: 4771858SN/A pass 4785227Ssaidi@eecs.umich.edu 4795227Ssaidi@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 4805227Ssaidi@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 4815227Ssaidi@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 4826654Snate@binkert.org# breaking all our configuration checks. We replace it with our own 4836654Snate@binkert.org# more optimistic null object that returns True instead. 4846121Snate@binkert.orgif not conf: 4856121Snate@binkert.org def NullCheck(*args, **kwargs): 4866121Snate@binkert.org return True 4876121Snate@binkert.org 4885227Ssaidi@eecs.umich.edu class NullConf: 4895227Ssaidi@eecs.umich.edu def __init__(self, env): 4905227Ssaidi@eecs.umich.edu self.env = env 4915204Sstever@gmail.com def Finish(self): 4925204Sstever@gmail.com return self.env 4935204Sstever@gmail.com def __getattr__(self, mname): 4945204Sstever@gmail.com return NullCheck 4955204Sstever@gmail.com 4965204Sstever@gmail.com conf = NullConf(env) 4975204Sstever@gmail.com 4985204Sstever@gmail.com# Find Python include and library directories for embedding the 4995204Sstever@gmail.com# interpreter. For consistency, we will use the same Python 5005204Sstever@gmail.com# installation used to run scons (and thus this script). If you want 5015204Sstever@gmail.com# to link in an alternate version, see above for instructions on how 5025204Sstever@gmail.com# to invoke scons with a different copy of the Python interpreter. 5035204Sstever@gmail.com 5045204Sstever@gmail.com# Get brief Python version name (e.g., "python2.4") for locating 5055204Sstever@gmail.com# include & library files 5065204Sstever@gmail.compy_version_name = 'python' + sys.version[:3] 5075204Sstever@gmail.com 5086121Snate@binkert.org# include path, e.g. /usr/local/include/python2.4 5095204Sstever@gmail.compy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 5103118Sstever@eecs.umich.eduenv.Append(CPPPATH = py_header_path) 5113118Sstever@eecs.umich.edu# verify that it works 5123118Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 5133118Sstever@eecs.umich.edu print "Error: can't find Python.h header in", py_header_path 5143118Sstever@eecs.umich.edu Exit(1) 5155863Snate@binkert.org 5163118Sstever@eecs.umich.edu# add library path too if it's not in the default place 5175863Snate@binkert.orgpy_lib_path = None 5183118Sstever@eecs.umich.eduif sys.exec_prefix != '/usr': 5195863Snate@binkert.org py_lib_path = joinpath(sys.exec_prefix, 'lib') 5205863Snate@binkert.orgelif sys.platform == 'cygwin': 5215863Snate@binkert.org # cygwin puts the .dll in /bin for some reason 5225863Snate@binkert.org py_lib_path = '/bin' 5235863Snate@binkert.orgif py_lib_path: 5245863Snate@binkert.org env.Append(LIBPATH = py_lib_path) 5255863Snate@binkert.org print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 5265863Snate@binkert.orgif not conf.CheckLib(py_version_name): 5276003Snate@binkert.org print "Error: can't find Python library", py_version_name 5285863Snate@binkert.org Exit(1) 5295863Snate@binkert.org 5305863Snate@binkert.org# On Solaris you need to use libsocket for socket ops 5316120Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5325863Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5335863Snate@binkert.org print "Can't find library with socket calls (e.g. accept())" 5345863Snate@binkert.org Exit(1) 5356120Snate@binkert.org 5366120Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 5375863Snate@binkert.org# added to the LIBS environment variable. 5385863Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5396120Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 5405863Snate@binkert.org 'and/or zlib.h header file.' 5416121Snate@binkert.org print ' Please install zlib and try again.' 5426121Snate@binkert.org Exit(1) 5435863Snate@binkert.org 5445863Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 5453118Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 5465863Snate@binkert.orgif not have_fenv: 5473118Sstever@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 5483118Sstever@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 5495863Snate@binkert.org 5505863Snate@binkert.org# Check for mysql. 5515863Snate@binkert.orgmysql_config = WhereIs('mysql_config') 5525863Snate@binkert.orghave_mysql = mysql_config != None 5533118Sstever@eecs.umich.edu 5543483Ssaidi@eecs.umich.edu# Check MySQL version. 5553494Ssaidi@eecs.umich.eduif have_mysql: 5563494Ssaidi@eecs.umich.edu mysql_version = os.popen(mysql_config + ' --version').read() 5573483Ssaidi@eecs.umich.edu min_mysql_version = '4.1' 5583483Ssaidi@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 5593483Ssaidi@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 5603053Sstever@eecs.umich.edu print ' Version', mysql_version, 'detected.' 5613053Sstever@eecs.umich.edu have_mysql = False 5623918Ssaidi@eecs.umich.edu 5633053Sstever@eecs.umich.edu# Set up mysql_config commands. 5643053Sstever@eecs.umich.eduif have_mysql: 5653053Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 5663053Sstever@eecs.umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 5673053Sstever@eecs.umich.edu # older mysql_config versions don't support --include, use 5681858SN/A # --cflags instead 5691858SN/A mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 5701858SN/A # This seems to work in all versions 5711858SN/A mysql_config_libs = mysql_config + ' --libs' 5721858SN/A 5731858SN/Aenv = conf.Finish() 5745863Snate@binkert.org 5755863Snate@binkert.org# Define the universe of supported ISAs 5761859SN/Aall_isa_list = [ ] 5775863Snate@binkert.orgExport('all_isa_list') 5781858SN/A 5795863Snate@binkert.org# Define the universe of supported CPU models 5801858SN/Aall_cpu_list = [ ] 5811859SN/Adefault_cpus = [ ] 5821859SN/AExport('all_cpu_list', 'default_cpus') 5836654Snate@binkert.org 5843053Sstever@eecs.umich.edu# Sticky options get saved in the options file so they persist from 5856654Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 5863053Sstever@eecs.umich.edu# value becomes sticky). 5873053Sstever@eecs.umich.edusticky_opts = Options(args=ARGUMENTS) 5881859SN/AExport('sticky_opts') 5891859SN/A 5901859SN/A# Non-sticky options only apply to the current build. 5911859SN/Anonsticky_opts = Options(args=ARGUMENTS) 5921859SN/AExport('nonsticky_opts') 5931859SN/A 5941859SN/A# Walk the tree and execute all SConsopts scripts that wil add to the 5951859SN/A# above options 5961862SN/Afor base_dir in base_dir_list: 5971859SN/A for root, dirs, files in os.walk(base_dir): 5981859SN/A if 'SConsopts' in files: 5991859SN/A print "Reading", joinpath(root, 'SConsopts') 6005863Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 6015863Snate@binkert.org 6025863Snate@binkert.orgall_isa_list.sort() 6035863Snate@binkert.orgall_cpu_list.sort() 6046121Snate@binkert.orgdefault_cpus.sort() 6051858SN/A 6065863Snate@binkert.orgsticky_opts.AddOptions( 6075863Snate@binkert.org EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6085863Snate@binkert.org BoolOption('FULL_SYSTEM', 'Full-system support', False), 6095863Snate@binkert.org # There's a bug in scons 0.96.1 that causes ListOptions with list 6105863Snate@binkert.org # values (more than one value) not to be able to be restored from 6112139SN/A # a saved option file. If this causes trouble then upgrade to 6124202Sbinkertn@umich.edu # scons 0.96.90 or later. 6134202Sbinkertn@umich.edu ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 6142139SN/A BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6156994Snate@binkert.org BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6166994Snate@binkert.org False), 6176994Snate@binkert.org BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6186994Snate@binkert.org False), 6196994Snate@binkert.org BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 6206994Snate@binkert.org False), 6216994Snate@binkert.org BoolOption('SS_COMPATIBLE_FP', 6226994Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 6236994Snate@binkert.org False), 6246994Snate@binkert.org BoolOption('USE_SSE2', 6256994Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 6266994Snate@binkert.org False), 6276994Snate@binkert.org BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6286994Snate@binkert.org BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6296994Snate@binkert.org BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 6306994Snate@binkert.org ) 6316994Snate@binkert.org 6326994Snate@binkert.orgnonsticky_opts.AddOptions( 6336994Snate@binkert.org BoolOption('update_ref', 'Update test reference outputs', False) 6346994Snate@binkert.org ) 6356994Snate@binkert.org 6366994Snate@binkert.org# These options get exported to #defines in config/*.hh (see src/SConscript). 6376994Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 6386994Snate@binkert.org 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 6396994Snate@binkert.org 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 6406994Snate@binkert.org 'USE_CHECKER', 'TARGET_ISA'] 6416994Snate@binkert.org 6426994Snate@binkert.org# Define a handy 'no-op' action 6432155SN/Adef no_action(target, source, env): 6445863Snate@binkert.org return 0 6451869SN/A 6461869SN/Aenv.NoAction = Action(no_action, None) 6475863Snate@binkert.org 6485863Snate@binkert.org################################################### 6494202Sbinkertn@umich.edu# 6506108Snate@binkert.org# Define a SCons builder for configuration flag headers. 6516108Snate@binkert.org# 6526108Snate@binkert.org################################################### 6536108Snate@binkert.org 6545863Snate@binkert.org# This function generates a config header file that #defines the 6555863Snate@binkert.org# option symbol to the current option setting (0 or 1). The source 6565863Snate@binkert.org# operands are the name of the option and a Value node containing the 6574202Sbinkertn@umich.edu# value of the option. 6584202Sbinkertn@umich.edudef build_config_file(target, source, env): 6595863Snate@binkert.org (option, value) = [s.get_contents() for s in source] 6605742Snate@binkert.org f = file(str(target[0]), 'w') 6615742Snate@binkert.org print >> f, '#define', option, value 6625341Sstever@gmail.com f.close() 6635342Sstever@gmail.com return None 6645342Sstever@gmail.com 6654202Sbinkertn@umich.edu# Generate the message to be printed when building the config file. 6664202Sbinkertn@umich.edudef build_config_file_string(target, source, env): 6674202Sbinkertn@umich.edu (option, value) = [s.get_contents() for s in source] 6685863Snate@binkert.org return "Defining %s as %s in %s." % (option, value, target[0]) 6695863Snate@binkert.org 6705863Snate@binkert.org# Combine the two functions into a scons Action object. 6716994Snate@binkert.orgconfig_action = Action(build_config_file, build_config_file_string) 6726994Snate@binkert.org 6736994Snate@binkert.org# The emitter munges the source & target node lists to reflect what 6745863Snate@binkert.org# we're really doing. 6755863Snate@binkert.orgdef config_emitter(target, source, env): 6765863Snate@binkert.org # extract option name from Builder arg 6775863Snate@binkert.org option = str(target[0]) 6785863Snate@binkert.org # True target is config header file 6795863Snate@binkert.org target = joinpath('config', option.lower() + '.hh') 6805863Snate@binkert.org val = env[option] 6815863Snate@binkert.org if isinstance(val, bool): 6825863Snate@binkert.org # Force value to 0/1 6835863Snate@binkert.org val = int(val) 6845863Snate@binkert.org elif isinstance(val, str): 6855863Snate@binkert.org val = '"' + val + '"' 6865863Snate@binkert.org 6875863Snate@binkert.org # Sources are option name & value (packaged in SCons Value nodes) 6885863Snate@binkert.org return ([target], [Value(option), Value(val)]) 6895863Snate@binkert.org 6905952Ssaidi@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 6911869SN/A 6921858SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 6935863Snate@binkert.org 6945863Snate@binkert.org################################################### 6951869SN/A# 6961858SN/A# Define a SCons builder for copying files. This is used by the 6975863Snate@binkert.org# Python zipfile code in src/python/SConscript, but is placed up here 6986108Snate@binkert.org# since it's potentially more generally applicable. 6996108Snate@binkert.org# 7006108Snate@binkert.org################################################### 7011858SN/A 702955SN/Acopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 703955SN/A 7041869SN/Aenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 7051869SN/A 7061869SN/A################################################### 7071869SN/A# 7081869SN/A# Define a simple SCons builder to concatenate files. 7095863Snate@binkert.org# 7105863Snate@binkert.org# Used to append the Python zip archive to the executable. 7115863Snate@binkert.org# 7121869SN/A################################################### 7135863Snate@binkert.org 7141869SN/Aconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 7155863Snate@binkert.org 'chmod +x $TARGET'])) 7161869SN/A 7171869SN/Aenv.Append(BUILDERS = { 'Concat' : concat_builder }) 7181869SN/A 7191869SN/A 7201869SN/A# libelf build is shared across all configs in the build root. 7215863Snate@binkert.orgenv.SConscript('ext/libelf/SConscript', 7225863Snate@binkert.org build_dir = joinpath(build_root, 'libelf'), 7231869SN/A exports = 'env') 7241869SN/A 7251869SN/A################################################### 7261869SN/A# 7271869SN/A# This function is used to set up a directory with switching headers 7281869SN/A# 7291869SN/A################################################### 7305863Snate@binkert.org 7315863Snate@binkert.orgenv['ALL_ISA_LIST'] = all_isa_list 7321869SN/Adef make_switching_dir(dirname, switch_headers, env): 7335863Snate@binkert.org # Generate the header. target[0] is the full path of the output 7345863Snate@binkert.org # header to generate. 'source' is a dummy variable, since we get the 7353356Sbinkertn@umich.edu # list of ISAs from env['ALL_ISA_LIST']. 7363356Sbinkertn@umich.edu def gen_switch_hdr(target, source, env): 7373356Sbinkertn@umich.edu fname = str(target[0]) 7383356Sbinkertn@umich.edu basename = os.path.basename(fname) 7393356Sbinkertn@umich.edu f = open(fname, 'w') 7404781Snate@binkert.org f.write('#include "arch/isa_specific.hh"\n') 7415863Snate@binkert.org cond = '#if' 7425863Snate@binkert.org for isa in all_isa_list: 7431869SN/A f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 7441869SN/A % (cond, isa.upper(), dirname, isa, basename)) 7451869SN/A cond = '#elif' 7466121Snate@binkert.org f.write('#else\n#error "THE_ISA not set"\n#endif\n') 7471869SN/A f.close() 7482638Sstever@eecs.umich.edu return 0 7496121Snate@binkert.org 7506121Snate@binkert.org # String to print when generating header 7512638Sstever@eecs.umich.edu def gen_switch_hdr_string(target, source, env): 7525749Scws3k@cs.virginia.edu return "Generating switch header " + str(target[0]) 7536121Snate@binkert.org 7546121Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 7555749Scws3k@cs.virginia.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 7561869SN/A # should get re-executed. 7571869SN/A switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 7583546Sgblack@eecs.umich.edu varlist=['ALL_ISA_LIST']) 7593546Sgblack@eecs.umich.edu 7603546Sgblack@eecs.umich.edu # Instantiate actions for each header 7613546Sgblack@eecs.umich.edu for hdr in switch_headers: 7626121Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 7635863Snate@binkert.orgExport('make_switching_dir') 7643546Sgblack@eecs.umich.edu 7653546Sgblack@eecs.umich.edu################################################### 7663546Sgblack@eecs.umich.edu# 7673546Sgblack@eecs.umich.edu# Define build environments for selected configurations. 7684781Snate@binkert.org# 7694781Snate@binkert.org################################################### 7706658Snate@binkert.org 7716658Snate@binkert.org# rename base env 7724781Snate@binkert.orgbase_env = env 7733546Sgblack@eecs.umich.edu 7743546Sgblack@eecs.umich.edufor build_path in build_paths: 7753546Sgblack@eecs.umich.edu print "Building in", build_path 7764781Snate@binkert.org 7773546Sgblack@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 7783546Sgblack@eecs.umich.edu env = base_env.Copy() 7793546Sgblack@eecs.umich.edu env['BUILDDIR'] = build_path 7803546Sgblack@eecs.umich.edu 7813546Sgblack@eecs.umich.edu # build_dir is the tail component of build path, and is used to 7823546Sgblack@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 7833546Sgblack@eecs.umich.edu (build_root, build_dir) = os.path.split(build_path) 7843546Sgblack@eecs.umich.edu 7853546Sgblack@eecs.umich.edu # Set env options according to the build directory config. 7863546Sgblack@eecs.umich.edu sticky_opts.files = [] 7874202Sbinkertn@umich.edu # Options for $BUILD_ROOT/$BUILD_DIR are stored in 7883546Sgblack@eecs.umich.edu # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 7893546Sgblack@eecs.umich.edu # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 7903546Sgblack@eecs.umich.edu current_opts_file = joinpath(build_root, 'options', build_dir) 791955SN/A if isfile(current_opts_file): 792955SN/A sticky_opts.files.append(current_opts_file) 793955SN/A print "Using saved options file %s" % current_opts_file 794955SN/A else: 7955863Snate@binkert.org # Build dir-specific options file doesn't exist. 7965863Snate@binkert.org 7975343Sstever@gmail.com # Make sure the directory is there so we can create it later 7985343Sstever@gmail.com opt_dir = os.path.dirname(current_opts_file) 7996121Snate@binkert.org if not isdir(opt_dir): 8005863Snate@binkert.org os.mkdir(opt_dir) 8014773Snate@binkert.org 8025863Snate@binkert.org # Get default build options from source tree. Options are 8032632Sstever@eecs.umich.edu # normally determined by name of $BUILD_DIR, but can be 8045863Snate@binkert.org # overriden by 'default=' arg on command line. 8052023SN/A default_opts_file = joinpath('build_opts', 8065863Snate@binkert.org ARGUMENTS.get('default', build_dir)) 8075863Snate@binkert.org if isfile(default_opts_file): 8085863Snate@binkert.org sticky_opts.files.append(default_opts_file) 8095863Snate@binkert.org print "Options file %s not found,\n using defaults in %s" \ 8105863Snate@binkert.org % (current_opts_file, default_opts_file) 8115863Snate@binkert.org else: 8125863Snate@binkert.org print "Error: cannot find options file %s or %s" \ 8135863Snate@binkert.org % (current_opts_file, default_opts_file) 8145863Snate@binkert.org Exit(1) 8152632Sstever@eecs.umich.edu 8165863Snate@binkert.org # Apply current option settings to env 8172023SN/A sticky_opts.Update(env) 8182632Sstever@eecs.umich.edu nonsticky_opts.Update(env) 8195863Snate@binkert.org 8205342Sstever@gmail.com help_text += "\nSticky options for %s:\n" % build_dir \ 8215863Snate@binkert.org + sticky_opts.GenerateHelpText(env) \ 8222632Sstever@eecs.umich.edu + "\nNon-sticky options for %s:\n" % build_dir \ 8235863Snate@binkert.org + nonsticky_opts.GenerateHelpText(env) 8245863Snate@binkert.org 8252632Sstever@eecs.umich.edu # Process option settings. 8265863Snate@binkert.org 8275863Snate@binkert.org if not have_fenv and env['USE_FENV']: 8285863Snate@binkert.org print "Warning: <fenv.h> not available; " \ 8295863Snate@binkert.org "forcing USE_FENV to False in", build_dir + "." 8305863Snate@binkert.org env['USE_FENV'] = False 8315863Snate@binkert.org 8322632Sstever@eecs.umich.edu if not env['USE_FENV']: 8335863Snate@binkert.org print "Warning: No IEEE FP rounding mode control in", build_dir + "." 8345863Snate@binkert.org print " FP results may deviate slightly from other platforms." 8352632Sstever@eecs.umich.edu 8361888SN/A if env['EFENCE']: 8375863Snate@binkert.org env.Append(LIBS=['efence']) 8385863Snate@binkert.org 8395863Snate@binkert.org if env['USE_MYSQL']: 8401858SN/A if not have_mysql: 8415863Snate@binkert.org print "Warning: MySQL not available; " \ 8425863Snate@binkert.org "forcing USE_MYSQL to False in", build_dir + "." 8435863Snate@binkert.org env['USE_MYSQL'] = False 8445863Snate@binkert.org else: 8452598SN/A print "Compiling in", build_dir, "with MySQL support." 8465863Snate@binkert.org env.ParseConfig(mysql_config_libs) 8471858SN/A env.ParseConfig(mysql_config_include) 8481858SN/A 8491858SN/A # Save sticky option settings back to current options file 8505863Snate@binkert.org sticky_opts.Save(current_opts_file, env) 8511858SN/A 8521858SN/A if env['USE_SSE2']: 8531858SN/A env.Append(CCFLAGS='-msse2') 8545863Snate@binkert.org 8551871SN/A # The src/SConscript file sets up the build rules in 'env' according 8561858SN/A # to the configured options. It returns a list of environments, 8571858SN/A # one for each variant build (debug, opt, etc.) 8581858SN/A envList = SConscript('src/SConscript', build_dir = build_path, 8591858SN/A exports = 'env') 8601858SN/A 8611858SN/A # Set up the regression tests for each build. 8621858SN/A for e in envList: 8635863Snate@binkert.org SConscript('tests/SConscript', 8641858SN/A build_dir = joinpath(build_path, 'tests', e.Label), 8651858SN/A exports = { 'env' : e }, duplicate = False) 8665863Snate@binkert.org 8671859SN/AHelp(help_text) 8681859SN/A 8691869SN/A 8705863Snate@binkert.org################################################### 8715863Snate@binkert.org# 8721869SN/A# Let SCons do its thing. At this point SCons will use the defined 8731965SN/A# build environments to build the requested targets. 8741965SN/A# 8751965SN/A################################################### 8762761Sstever@eecs.umich.edu 8775863Snate@binkert.org