SConstruct revision 5708:96614cd66f76
12221SN/A# -*- mode:python -*- 22221SN/A 32221SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 42221SN/A# All rights reserved. 52221SN/A# 62221SN/A# Redistribution and use in source and binary forms, with or without 72221SN/A# modification, are permitted provided that the following conditions are 82221SN/A# met: redistributions of source code must retain the above copyright 92221SN/A# notice, this list of conditions and the following disclaimer; 102221SN/A# redistributions in binary form must reproduce the above copyright 112221SN/A# notice, this list of conditions and the following disclaimer in the 122221SN/A# documentation and/or other materials provided with the distribution; 132221SN/A# neither the name of the copyright holders nor the names of its 142221SN/A# contributors may be used to endorse or promote products derived from 152221SN/A# this software without specific prior written permission. 162221SN/A# 172221SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182221SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192221SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202221SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212221SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222221SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232221SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242221SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252221SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262221SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 302221SN/A 312221SN/A################################################### 323415Sgblack@eecs.umich.edu# 333415Sgblack@eecs.umich.edu# SCons top-level build description (SConstruct) file. 342223SN/A# 353415Sgblack@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 363578Sgblack@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 373415Sgblack@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 383415Sgblack@eecs.umich.edu# the optimized full-system version). 398750Sgblack@eecs.umich.edu# 403415Sgblack@eecs.umich.edu# You can build M5 in a different directory as long as there is a 412680Sktlim@umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 422800Ssaidi@eecs.umich.edu# expects that all configs under the same build directory are being 433523Sgblack@eecs.umich.edu# built for the same host system. 448767Sgblack@eecs.umich.edu# 453415Sgblack@eecs.umich.edu# Examples: 462800Ssaidi@eecs.umich.edu# 478750Sgblack@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 482221SN/A# scons to search up the directory tree for this SConstruct file. 493415Sgblack@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 503415Sgblack@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512223SN/A# 522221SN/A# The following two commands are equivalent and demonstrate building 532221SN/A# in a directory outside of the source tree. The '-C' option tells 543573Sgblack@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 553576Sgblack@eecs.umich.edu# file. 563576Sgblack@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 572221SN/A# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 583573Sgblack@eecs.umich.edu# 593576Sgblack@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 603576Sgblack@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 612221SN/A# file), you can use 'scons -h' to print all the M5-specific build 623573Sgblack@eecs.umich.edu# options as well. 633576Sgblack@eecs.umich.edu# 643576Sgblack@eecs.umich.edu################################################### 652221SN/A 663573Sgblack@eecs.umich.eduimport sys 673576Sgblack@eecs.umich.eduimport os 683576Sgblack@eecs.umich.eduimport re 692221SN/A 703573Sgblack@eecs.umich.edufrom os.path import isdir, isfile, join as joinpath 713576Sgblack@eecs.umich.edu 723576Sgblack@eecs.umich.eduimport SCons 732221SN/A 743573Sgblack@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 753576Sgblack@eecs.umich.edu# default installation of Python is not recent enough, you can use a 763576Sgblack@eecs.umich.edu# non-default installation of the Python interpreter by either (1) 772221SN/A# rearranging your PATH so that scons finds the non-default 'python' 783573Sgblack@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 793576Sgblack@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 803576Sgblack@eecs.umich.eduEnsurePythonVersion(2,4) 813576Sgblack@eecs.umich.edu 823576Sgblack@eecs.umich.edu# Import subprocess after we check the version since it doesn't exist in 833576Sgblack@eecs.umich.edu# Python < 2.4. 843576Sgblack@eecs.umich.eduimport subprocess 853576Sgblack@eecs.umich.edu 862221SN/A# helper function: compare arrays or strings of version numbers. 873573Sgblack@eecs.umich.edu# E.g., compare_version((1,3,25), (1,4,1)') 883576Sgblack@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 893576Sgblack@eecs.umich.edudef compare_versions(v1, v2): 902221SN/A def make_version_list(v): 913573Sgblack@eecs.umich.edu if isinstance(v, (list,tuple)): 923576Sgblack@eecs.umich.edu return v 933576Sgblack@eecs.umich.edu elif isinstance(v, str): 942221SN/A return map(lambda x: int(re.match('\d+', x).group()), v.split('.')) 953573Sgblack@eecs.umich.edu else: 963576Sgblack@eecs.umich.edu raise TypeError 973576Sgblack@eecs.umich.edu 983576Sgblack@eecs.umich.edu v1 = make_version_list(v1) 993576Sgblack@eecs.umich.edu v2 = make_version_list(v2) 1003576Sgblack@eecs.umich.edu # Compare corresponding elements of lists 1013576Sgblack@eecs.umich.edu for n1,n2 in zip(v1, v2): 1023576Sgblack@eecs.umich.edu if n1 < n2: return -1 1033576Sgblack@eecs.umich.edu if n1 > n2: return 1 1043576Sgblack@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1053576Sgblack@eecs.umich.edu if len(v1) < len(v2): return -1 1063576Sgblack@eecs.umich.edu if len(v1) > len(v2): return 1 1073576Sgblack@eecs.umich.edu return 0 1082221SN/A 1093573Sgblack@eecs.umich.edu# SCons version numbers need special processing because they can have 1103576Sgblack@eecs.umich.edu# charecters and an release date embedded in them. This function does 1113576Sgblack@eecs.umich.edu# the magic to extract them in a similar way to the SCons internal function 1122221SN/A# function does and then checks that the current version is not contained in 1133573Sgblack@eecs.umich.edu# a list of version tuples (bad_ver_strs) 1143576Sgblack@eecs.umich.edudef CheckSCons(bad_ver_strs): 1153576Sgblack@eecs.umich.edu def scons_ver(v): 1162221SN/A num_parts = v.split(' ')[0].split('.') 1173573Sgblack@eecs.umich.edu major = int(num_parts[0]) 1183576Sgblack@eecs.umich.edu minor = int(re.match('\d+', num_parts[1]).group()) 1193576Sgblack@eecs.umich.edu rev = 0 1202221SN/A rdate = 0 1213573Sgblack@eecs.umich.edu if len(num_parts) > 2: 1223576Sgblack@eecs.umich.edu try: rev = int(re.match('\d+', num_parts[2]).group()) 1233576Sgblack@eecs.umich.edu except: pass 1242221SN/A rev_parts = num_parts[2].split('d') 1253573Sgblack@eecs.umich.edu if len(rev_parts) > 1: 1263576Sgblack@eecs.umich.edu rdate = int(re.match('\d+', rev_parts[1]).group()) 1273576Sgblack@eecs.umich.edu 1282221SN/A return (major, minor, rev, rdate) 1293573Sgblack@eecs.umich.edu 1303576Sgblack@eecs.umich.edu sc_ver = scons_ver(SCons.__version__) 1313576Sgblack@eecs.umich.edu for bad_ver in bad_ver_strs: 1322223SN/A bv = (scons_ver(bad_ver[0]), scons_ver(bad_ver[1])) 1333573Sgblack@eecs.umich.edu if compare_versions(sc_ver, bv[0]) != -1 and\ 1343576Sgblack@eecs.umich.edu compare_versions(sc_ver, bv[1]) != 1: 1353576Sgblack@eecs.umich.edu print "The version of SCons that you have installed: ", SCons.__version__ 1362223SN/A print "has a bug that prevents it from working correctly with M5." 1373573Sgblack@eecs.umich.edu print "Please install a version NOT contained within the following", 1383576Sgblack@eecs.umich.edu print "ranges (inclusive):" 1393576Sgblack@eecs.umich.edu for bad_ver in bad_ver_strs: 1402223SN/A print " %s - %s" % bad_ver 1413573Sgblack@eecs.umich.edu Exit(2) 1423576Sgblack@eecs.umich.edu 1433576Sgblack@eecs.umich.eduCheckSCons(( 1442223SN/A # We need a version that is 0.96.91 or newer 1453573Sgblack@eecs.umich.edu ('0.0.0', '0.96.90'), 1463576Sgblack@eecs.umich.edu )) 1473576Sgblack@eecs.umich.edu 1483576Sgblack@eecs.umich.edu 1493576Sgblack@eecs.umich.edu# The absolute path to the current directory (where this file lives). 1503576Sgblack@eecs.umich.eduROOT = Dir('.').abspath 1513576Sgblack@eecs.umich.edu 1523576Sgblack@eecs.umich.edu# Path to the M5 source tree. 1532223SN/ASRCDIR = joinpath(ROOT, 'src') 1543573Sgblack@eecs.umich.edu 1553576Sgblack@eecs.umich.edu# tell python where to find m5 python code 1563576Sgblack@eecs.umich.edusys.path.append(joinpath(ROOT, 'src/python')) 1572223SN/A 1583573Sgblack@eecs.umich.edudef check_style_hook(ui): 1593576Sgblack@eecs.umich.edu ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 1603576Sgblack@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) 1612223SN/A 1623573Sgblack@eecs.umich.edu if not style_hook: 1633576Sgblack@eecs.umich.edu print """\ 1643576Sgblack@eecs.umich.eduYou're missing the M5 style hook. 1652223SN/APlease install the hook so we can ensure that all code fits a common style. 1663573Sgblack@eecs.umich.edu 1673576Sgblack@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc 1683576Sgblack@eecs.umich.eduor your personal .hgrc 1692223SN/A---------------- 1703573Sgblack@eecs.umich.edu 1713576Sgblack@eecs.umich.edu[extensions] 1723576Sgblack@eecs.umich.edustyle = %s/util/style.py 1732223SN/A 1743573Sgblack@eecs.umich.edu[hooks] 1753576Sgblack@eecs.umich.edupretxncommit.style = python:style.check_whitespace 1763576Sgblack@eecs.umich.edu""" % (ROOT) 1772223SN/A sys.exit(1) 1783573Sgblack@eecs.umich.edu 1793576Sgblack@eecs.umich.eduif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1803576Sgblack@eecs.umich.edu try: 1812223SN/A from mercurial import ui 1823573Sgblack@eecs.umich.edu check_style_hook(ui.ui()) 1833576Sgblack@eecs.umich.edu except ImportError: 1843576Sgblack@eecs.umich.edu pass 1852223SN/A 1863573Sgblack@eecs.umich.edu################################################### 1873576Sgblack@eecs.umich.edu# 1883576Sgblack@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 1892223SN/A# the target(s). 1903573Sgblack@eecs.umich.edu# 1913576Sgblack@eecs.umich.edu################################################### 1923576Sgblack@eecs.umich.edu 1932223SN/A# Find default configuration & binary. 1943576Sgblack@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1953576Sgblack@eecs.umich.edu 1963576Sgblack@eecs.umich.edu# helper function: find last occurrence of element in list 1973576Sgblack@eecs.umich.edudef rfind(l, elt, offs = -1): 1982527SN/A for i in range(len(l)+offs, 0, -1): 1993573Sgblack@eecs.umich.edu if l[i] == elt: 2003576Sgblack@eecs.umich.edu return i 2013890Ssaidi@eecs.umich.edu raise ValueError, "element not found" 2022223SN/A 2033573Sgblack@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2043576Sgblack@eecs.umich.edu# directory below this will determine the build parameters. For 2053576Sgblack@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2062223SN/A# recognize that ALPHA_SE specifies the configuration because it 2073573Sgblack@eecs.umich.edu# follow 'build' in the bulid path. 2083576Sgblack@eecs.umich.edu 2093576Sgblack@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is 2102223SN/Aif COMMAND_LINE_TARGETS: 2113573Sgblack@eecs.umich.edu # Ask SCons which directory it was invoked from 2124103Ssaidi@eecs.umich.edu launch_dir = GetLaunchDir() 2134103Ssaidi@eecs.umich.edu # Make targets relative to invocation directory 2144103Ssaidi@eecs.umich.edu abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 2154103Ssaidi@eecs.umich.edu COMMAND_LINE_TARGETS) 2163576Sgblack@eecs.umich.eduelse: 2173576Sgblack@eecs.umich.edu # Default targets are relative to root of tree 2182223SN/A abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 2193573Sgblack@eecs.umich.edu DEFAULT_TARGETS) 2203576Sgblack@eecs.umich.edu 2213576Sgblack@eecs.umich.edu 2222223SN/A# Generate a list of the unique build roots and configs that the 2233573Sgblack@eecs.umich.edu# collected targets reference. 2243576Sgblack@eecs.umich.edubuild_paths = [] 2253576Sgblack@eecs.umich.edubuild_root = None 2263576Sgblack@eecs.umich.edufor t in abs_targets: 2273576Sgblack@eecs.umich.edu path_dirs = t.split('/') 2283576Sgblack@eecs.umich.edu try: 2293576Sgblack@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 2303576Sgblack@eecs.umich.edu except: 2313576Sgblack@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 2323576Sgblack@eecs.umich.edu Exit(1) 2333576Sgblack@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2343576Sgblack@eecs.umich.edu if not build_root: 2353576Sgblack@eecs.umich.edu build_root = this_build_root 2363576Sgblack@eecs.umich.edu else: 2373576Sgblack@eecs.umich.edu if this_build_root != build_root: 2383576Sgblack@eecs.umich.edu print "Error: build targets not under same build root\n"\ 2393576Sgblack@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 2403576Sgblack@eecs.umich.edu Exit(1) 2413576Sgblack@eecs.umich.edu build_path = joinpath('/',*path_dirs[:build_top+2]) 2423576Sgblack@eecs.umich.edu if build_path not in build_paths: 2433576Sgblack@eecs.umich.edu build_paths.append(build_path) 2443576Sgblack@eecs.umich.edu 2453576Sgblack@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 2463576Sgblack@eecs.umich.eduif not isdir(build_root): 2473576Sgblack@eecs.umich.edu os.mkdir(build_root) 2483893Shsul@eecs.umich.edu 2493576Sgblack@eecs.umich.edu################################################### 2503576Sgblack@eecs.umich.edu# 2513576Sgblack@eecs.umich.edu# Set up the default build environment. This environment is copied 2523576Sgblack@eecs.umich.edu# and modified according to each selected configuration. 2533576Sgblack@eecs.umich.edu# 2543576Sgblack@eecs.umich.edu################################################### 2553576Sgblack@eecs.umich.edu 2563576Sgblack@eecs.umich.eduenv = Environment(ENV = os.environ, # inherit user's environment vars 2573576Sgblack@eecs.umich.edu ROOT = ROOT, 2583576Sgblack@eecs.umich.edu SRCDIR = SRCDIR) 2593576Sgblack@eecs.umich.edu 2603576Sgblack@eecs.umich.eduExport('env') 2613576Sgblack@eecs.umich.edu 2623576Sgblack@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign")) 2633576Sgblack@eecs.umich.edu 2643576Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 2653576Sgblack@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 2663576Sgblack@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2673576Sgblack@eecs.umich.edu# (soft) links work better. 2683576Sgblack@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 2693576Sgblack@eecs.umich.edu 2702223SN/A# I waffle on this setting... it does avoid a few painful but 2713415Sgblack@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 2723578Sgblack@eecs.umich.edu# noticeably longer. 2733578Sgblack@eecs.umich.eduif False: 2743415Sgblack@eecs.umich.edu env.TargetSignatures('content') 2753415Sgblack@eecs.umich.edu 2767741Sgblack@eecs.umich.edu# 2777741Sgblack@eecs.umich.edu# Set up global sticky options... these are common to an entire build 2783415Sgblack@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 2793578Sgblack@eecs.umich.edu# 2803578Sgblack@eecs.umich.edu 2814172Ssaidi@eecs.umich.edu# Option validators & converters for global sticky options 2827741Sgblack@eecs.umich.edudef PathListMakeAbsolute(val): 2833578Sgblack@eecs.umich.edu if not val: 2847741Sgblack@eecs.umich.edu return val 2853578Sgblack@eecs.umich.edu f = lambda p: os.path.abspath(os.path.expanduser(p)) 2864172Ssaidi@eecs.umich.edu return ':'.join(map(f, val.split(':'))) 2877741Sgblack@eecs.umich.edu 2887741Sgblack@eecs.umich.edudef PathListAllExist(key, val, env): 2894172Ssaidi@eecs.umich.edu if not val: 2903746Sgblack@eecs.umich.edu return 2914172Ssaidi@eecs.umich.edu paths = val.split(':') 2923578Sgblack@eecs.umich.edu for path in paths: 2933578Sgblack@eecs.umich.edu if not isdir(path): 2943578Sgblack@eecs.umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 2953578Sgblack@eecs.umich.edu 2963578Sgblack@eecs.umich.eduglobal_sticky_opts_file = joinpath(build_root, 'options.global') 2973578Sgblack@eecs.umich.edu 2983578Sgblack@eecs.umich.eduglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS) 2997741Sgblack@eecs.umich.edu 3007741Sgblack@eecs.umich.eduglobal_sticky_opts.AddOptions( 3013578Sgblack@eecs.umich.edu ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3024172Ssaidi@eecs.umich.edu ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3034172Ssaidi@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3044172Ssaidi@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3054172Ssaidi@eecs.umich.edu ('EXTRAS', 'Add Extra directories to the compilation', '', 3063761Sgblack@eecs.umich.edu PathListAllExist, PathListMakeAbsolute) 3074172Ssaidi@eecs.umich.edu ) 3084172Ssaidi@eecs.umich.edu 3094172Ssaidi@eecs.umich.edu 3104172Ssaidi@eecs.umich.edu# base help text 3117720Sgblack@eecs.umich.eduhelp_text = ''' 3123578Sgblack@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 3133578Sgblack@eecs.umich.edu 3143578Sgblack@eecs.umich.edu''' 3157720Sgblack@eecs.umich.edu 3163928Ssaidi@eecs.umich.eduhelp_text += "Global sticky options:\n" \ 3177741Sgblack@eecs.umich.edu + global_sticky_opts.GenerateHelpText(env) 3183578Sgblack@eecs.umich.edu 3197741Sgblack@eecs.umich.edu# Update env with values from ARGUMENTS & file global_sticky_opts_file 3203578Sgblack@eecs.umich.eduglobal_sticky_opts.Update(env) 3217741Sgblack@eecs.umich.edu 3223578Sgblack@eecs.umich.edu# Save sticky option settings back to current options file 3237741Sgblack@eecs.umich.eduglobal_sticky_opts.Save(global_sticky_opts_file, env) 3243578Sgblack@eecs.umich.edu 3257741Sgblack@eecs.umich.edu# Parse EXTRAS option to build list of all directories where we're 3263578Sgblack@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3273578Sgblack@eecs.umich.edubase_dir_list = [joinpath(ROOT, 'src')] 3287741Sgblack@eecs.umich.eduif env['EXTRAS']: 3294172Ssaidi@eecs.umich.edu base_dir_list += env['EXTRAS'].split(':') 3303578Sgblack@eecs.umich.edu 3317741Sgblack@eecs.umich.eduExport('base_dir_list') 3327720Sgblack@eecs.umich.edu 3337741Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 3347720Sgblack@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 3353578Sgblack@eecs.umich.eduenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 3367741Sgblack@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3374172Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('g++') >= 0 3383578Sgblack@eecs.umich.eduenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3397741Sgblack@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3404172Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('Sun C++') >= 0 3413578Sgblack@eecs.umich.eduenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3427741Sgblack@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3434172Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('Intel') >= 0 3443578Sgblack@eecs.umich.eduif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3453926Ssaidi@eecs.umich.edu print 'Error: How can we have two at the same time?' 3467741Sgblack@eecs.umich.edu Exit(1) 3474172Ssaidi@eecs.umich.edu 3483578Sgblack@eecs.umich.edu 3497741Sgblack@eecs.umich.edu# Set up default C++ compiler flags 3503578Sgblack@eecs.umich.eduif env['GCC']: 3517741Sgblack@eecs.umich.edu env.Append(CCFLAGS='-pipe') 3523578Sgblack@eecs.umich.edu env.Append(CCFLAGS='-fno-strict-aliasing') 3537741Sgblack@eecs.umich.edu env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3543578Sgblack@eecs.umich.edu env.Append(CXXFLAGS='-Wno-deprecated') 3557741Sgblack@eecs.umich.eduelif env['ICC']: 3563578Sgblack@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 3574172Ssaidi@eecs.umich.eduelif env['SUNCC']: 3583578Sgblack@eecs.umich.edu env.Append(CCFLAGS='-Qoption ccfe') 3593578Sgblack@eecs.umich.edu env.Append(CCFLAGS='-features=gcc') 3603893Shsul@eecs.umich.edu env.Append(CCFLAGS='-features=extensions') 3613415Sgblack@eecs.umich.edu env.Append(CCFLAGS='-library=stlport4') 3623893Shsul@eecs.umich.edu env.Append(CCFLAGS='-xar') 3633415Sgblack@eecs.umich.edu# env.Append(CCFLAGS='-instances=semiexplicit') 3643893Shsul@eecs.umich.eduelse: 3653415Sgblack@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 3663415Sgblack@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 3673415Sgblack@eecs.umich.edu Exit(1) 3683420Sgblack@eecs.umich.edu 3697741Sgblack@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 3703415Sgblack@eecs.umich.edu# extra 'qdo' every time we run scons. 3714172Ssaidi@eecs.umich.eduif env['BATCH']: 3723415Sgblack@eecs.umich.edu env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 3733415Sgblack@eecs.umich.edu env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 3743415Sgblack@eecs.umich.edu env['AS'] = env['BATCH_CMD'] + ' ' + env['AS'] 3757741Sgblack@eecs.umich.edu env['AR'] = env['BATCH_CMD'] + ' ' + env['AR'] 3767741Sgblack@eecs.umich.edu env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB'] 3777741Sgblack@eecs.umich.edu 3787741Sgblack@eecs.umich.eduif sys.platform == 'cygwin': 3797741Sgblack@eecs.umich.edu # cygwin has some header file issues... 3807741Sgblack@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 3817741Sgblack@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 3827741Sgblack@eecs.umich.edu 3837741Sgblack@eecs.umich.edu# Check for SWIG 3847741Sgblack@eecs.umich.eduif not env.has_key('SWIG'): 3857741Sgblack@eecs.umich.edu print 'Error: SWIG utility not found.' 3867741Sgblack@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 3877741Sgblack@eecs.umich.edu Exit(1) 3887741Sgblack@eecs.umich.edu 3897741Sgblack@eecs.umich.edu# Check for appropriate SWIG version 3907741Sgblack@eecs.umich.eduswig_version = os.popen('swig -version').read().split() 3917741Sgblack@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 3927741Sgblack@eecs.umich.eduif len(swig_version) < 3 or \ 3937741Sgblack@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 3947741Sgblack@eecs.umich.edu print 'Error determining SWIG version.' 3957741Sgblack@eecs.umich.edu Exit(1) 3967741Sgblack@eecs.umich.edu 3977741Sgblack@eecs.umich.edumin_swig_version = '1.3.28' 3987741Sgblack@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 3997741Sgblack@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 4007741Sgblack@eecs.umich.edu print ' Installed version:', swig_version[2] 4017741Sgblack@eecs.umich.edu Exit(1) 4027741Sgblack@eecs.umich.edu 4037741Sgblack@eecs.umich.edu# Set up SWIG flags & scanner 4047741Sgblack@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4057741Sgblack@eecs.umich.eduenv.Append(SWIGFLAGS=swig_flags) 4067741Sgblack@eecs.umich.edu 4077741Sgblack@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 4087741Sgblack@eecs.umich.edu# stuff for some reason 4097741Sgblack@eecs.umich.eduscanners = [] 4107741Sgblack@eecs.umich.edufor scanner in env['SCANNERS']: 4117741Sgblack@eecs.umich.edu skeys = scanner.skeys 4127741Sgblack@eecs.umich.edu if skeys == '.i': 4137741Sgblack@eecs.umich.edu continue 4147741Sgblack@eecs.umich.edu 4157741Sgblack@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4167741Sgblack@eecs.umich.edu continue 4177741Sgblack@eecs.umich.edu 4187741Sgblack@eecs.umich.edu scanners.append(scanner) 4197741Sgblack@eecs.umich.edu 4207741Sgblack@eecs.umich.edu# add the new swig scanner that we like better 4217741Sgblack@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 4227741Sgblack@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4237741Sgblack@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4247741Sgblack@eecs.umich.edu 4257741Sgblack@eecs.umich.edu# replace the scanners list that has what we want 4267741Sgblack@eecs.umich.eduenv['SCANNERS'] = scanners 4277741Sgblack@eecs.umich.edu 4287741Sgblack@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 4297741Sgblack@eecs.umich.edu# figure out if the compiler adds leading underscores to global 4307741Sgblack@eecs.umich.edu# variables. This is needed for the autogenerated asm files that we 4317741Sgblack@eecs.umich.edu# use for embedding the python code. 4327741Sgblack@eecs.umich.edudef CheckLeading(context): 4337741Sgblack@eecs.umich.edu context.Message("Checking for leading underscore in global variables...") 4347741Sgblack@eecs.umich.edu # 1) Define a global variable called x from asm so the C compiler 4357741Sgblack@eecs.umich.edu # won't change the symbol at all. 4367741Sgblack@eecs.umich.edu # 2) Declare that variable. 4377741Sgblack@eecs.umich.edu # 3) Use the variable 4387741Sgblack@eecs.umich.edu # 4397741Sgblack@eecs.umich.edu # If the compiler prepends an underscore, this will successfully 4407741Sgblack@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 4417741Sgblack@eecs.umich.edu # was defined by the asm statement. If the compiler does not 4427741Sgblack@eecs.umich.edu # prepend an underscore, this will not successfully link because 4437741Sgblack@eecs.umich.edu # '_x' will have been defined by assembly, while the C portion of 4447741Sgblack@eecs.umich.edu # the code will be trying to use 'x' 4457741Sgblack@eecs.umich.edu ret = context.TryLink(''' 4467741Sgblack@eecs.umich.edu asm(".globl _x; _x: .byte 0"); 4477741Sgblack@eecs.umich.edu extern int x; 4487741Sgblack@eecs.umich.edu int main() { return x; } 4497741Sgblack@eecs.umich.edu ''', extension=".c") 4507741Sgblack@eecs.umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 4517741Sgblack@eecs.umich.edu context.Result(ret) 4527741Sgblack@eecs.umich.edu return ret 4537741Sgblack@eecs.umich.edu 4547741Sgblack@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 4557741Sgblack@eecs.umich.edu# builds under a given build root run on the same host platform. 4567741Sgblack@eecs.umich.educonf = Configure(env, 4577741Sgblack@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 4587741Sgblack@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 4597741Sgblack@eecs.umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 4607741Sgblack@eecs.umich.edu 4617741Sgblack@eecs.umich.edu# Check for leading underscores. Don't really need to worry either 4627741Sgblack@eecs.umich.edu# way so don't need to check the return code. 4637741Sgblack@eecs.umich.educonf.CheckLeading() 4647741Sgblack@eecs.umich.edu 4657741Sgblack@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 4667741Sgblack@eecs.umich.edutry: 4677741Sgblack@eecs.umich.edu import platform 4687741Sgblack@eecs.umich.edu uname = platform.uname() 4697741Sgblack@eecs.umich.edu if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 4707741Sgblack@eecs.umich.edu if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 4717741Sgblack@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 4727741Sgblack@eecs.umich.edu close_fds=True).communicate()[0][0]): 4733578Sgblack@eecs.umich.edu env.Append(CCFLAGS='-arch x86_64') 4743585Sgblack@eecs.umich.edu env.Append(CFLAGS='-arch x86_64') 4753603Ssaidi@eecs.umich.edu env.Append(LINKFLAGS='-arch x86_64') 4763595Sgblack@eecs.umich.edu env.Append(ASFLAGS='-arch x86_64') 4773578Sgblack@eecs.umich.eduexcept: 4783578Sgblack@eecs.umich.edu pass 4793578Sgblack@eecs.umich.edu 4807741Sgblack@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 4817741Sgblack@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 4823578Sgblack@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 4834172Ssaidi@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 4843578Sgblack@eecs.umich.edu# more optimistic null object that returns True instead. 4853578Sgblack@eecs.umich.eduif not conf: 4863578Sgblack@eecs.umich.edu def NullCheck(*args, **kwargs): 4873578Sgblack@eecs.umich.edu return True 4887741Sgblack@eecs.umich.edu 4897741Sgblack@eecs.umich.edu class NullConf: 4903578Sgblack@eecs.umich.edu def __init__(self, env): 4914172Ssaidi@eecs.umich.edu self.env = env 4923578Sgblack@eecs.umich.edu def Finish(self): 4933578Sgblack@eecs.umich.edu return self.env 4943578Sgblack@eecs.umich.edu def __getattr__(self, mname): 4953578Sgblack@eecs.umich.edu return NullCheck 4963578Sgblack@eecs.umich.edu 4973578Sgblack@eecs.umich.edu conf = NullConf(env) 4987741Sgblack@eecs.umich.edu 4997741Sgblack@eecs.umich.edu# Find Python include and library directories for embedding the 5002221SN/A# interpreter. For consistency, we will use the same Python 5012680Sktlim@umich.edu# installation used to run scons (and thus this script). If you want 5028750Sgblack@eecs.umich.edu# to link in an alternate version, see above for instructions on how 5038750Sgblack@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 5048750Sgblack@eecs.umich.edu 5052223SN/A# Get brief Python version name (e.g., "python2.4") for locating 5062221SN/A# include & library files 5077741Sgblack@eecs.umich.edupy_version_name = 'python' + sys.version[:3] 5087741Sgblack@eecs.umich.edu 5094172Ssaidi@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4 5104172Ssaidi@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 5114172Ssaidi@eecs.umich.eduenv.Append(CPPPATH = py_header_path) 5124172Ssaidi@eecs.umich.edu# verify that it works 5133578Sgblack@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 5143578Sgblack@eecs.umich.edu print "Error: can't find Python.h header in", py_header_path 5153578Sgblack@eecs.umich.edu Exit(1) 5163578Sgblack@eecs.umich.edu 5173893Shsul@eecs.umich.edu# add library path too if it's not in the default place 5183746Sgblack@eecs.umich.edupy_lib_path = None 5193893Shsul@eecs.umich.eduif sys.exec_prefix != '/usr': 5203578Sgblack@eecs.umich.edu py_lib_path = joinpath(sys.exec_prefix, 'lib') 5213578Sgblack@eecs.umich.eduelif sys.platform == 'cygwin': 5223746Sgblack@eecs.umich.edu # cygwin puts the .dll in /bin for some reason 5233578Sgblack@eecs.umich.edu py_lib_path = '/bin' 5243578Sgblack@eecs.umich.eduif py_lib_path: 5253578Sgblack@eecs.umich.edu env.Append(LIBPATH = py_lib_path) 5263893Shsul@eecs.umich.edu print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 5273595Sgblack@eecs.umich.eduif not conf.CheckLib(py_version_name): 5283893Shsul@eecs.umich.edu print "Error: can't find Python library", py_version_name 5297741Sgblack@eecs.umich.edu Exit(1) 5307741Sgblack@eecs.umich.edu 5313578Sgblack@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 5323893Shsul@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5333825Ssaidi@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5347741Sgblack@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 5357741Sgblack@eecs.umich.edu Exit(1) 5367741Sgblack@eecs.umich.edu 5373893Shsul@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 5387741Sgblack@eecs.umich.edu# added to the LIBS environment variable. 5393578Sgblack@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5403585Sgblack@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 5413893Shsul@eecs.umich.edu 'and/or zlib.h header file.' 5425570Snate@binkert.org print ' Please install zlib and try again.' 5433578Sgblack@eecs.umich.edu Exit(1) 5443585Sgblack@eecs.umich.edu 5453826Ssaidi@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 5463578Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 5477741Sgblack@eecs.umich.eduif not have_fenv: 5483578Sgblack@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 5493578Sgblack@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 5507720Sgblack@eecs.umich.edu 5517720Sgblack@eecs.umich.edu# Check for mysql. 5527720Sgblack@eecs.umich.edumysql_config = WhereIs('mysql_config') 5537720Sgblack@eecs.umich.eduhave_mysql = mysql_config != None 5547720Sgblack@eecs.umich.edu 5557720Sgblack@eecs.umich.edu# Check MySQL version. 5567720Sgblack@eecs.umich.eduif have_mysql: 5573420Sgblack@eecs.umich.edu mysql_version = os.popen(mysql_config + ' --version').read() 5582221SN/A min_mysql_version = '4.1' 5597741Sgblack@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 5607741Sgblack@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 5613523Sgblack@eecs.umich.edu print ' Version', mysql_version, 'detected.' 5627741Sgblack@eecs.umich.edu have_mysql = False 5637741Sgblack@eecs.umich.edu 5647741Sgblack@eecs.umich.edu# Set up mysql_config commands. 5653595Sgblack@eecs.umich.eduif have_mysql: 5664172Ssaidi@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 5674172Ssaidi@eecs.umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 5684172Ssaidi@eecs.umich.edu # older mysql_config versions don't support --include, use 5693595Sgblack@eecs.umich.edu # --cflags instead 5707741Sgblack@eecs.umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 5714172Ssaidi@eecs.umich.edu # This seems to work in all versions 5723595Sgblack@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 5737741Sgblack@eecs.umich.edu 5744172Ssaidi@eecs.umich.eduenv = conf.Finish() 5757741Sgblack@eecs.umich.edu 5763628Sgblack@eecs.umich.edu# Define the universe of supported ISAs 5777741Sgblack@eecs.umich.eduall_isa_list = [ ] 5783628Sgblack@eecs.umich.eduExport('all_isa_list') 5797741Sgblack@eecs.umich.edu 5803628Sgblack@eecs.umich.edu# Define the universe of supported CPU models 5817741Sgblack@eecs.umich.eduall_cpu_list = [ ] 5823628Sgblack@eecs.umich.edudefault_cpus = [ ] 5834172Ssaidi@eecs.umich.eduExport('all_cpu_list', 'default_cpus') 5843595Sgblack@eecs.umich.edu 5857741Sgblack@eecs.umich.edu# Sticky options get saved in the options file so they persist from 5864172Ssaidi@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 5873595Sgblack@eecs.umich.edu# value becomes sticky). 5887741Sgblack@eecs.umich.edusticky_opts = Options(args=ARGUMENTS) 5897741Sgblack@eecs.umich.eduExport('sticky_opts') 5903746Sgblack@eecs.umich.edu 5913746Sgblack@eecs.umich.edu# Non-sticky options only apply to the current build. 5923595Sgblack@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS) 5933595Sgblack@eecs.umich.eduExport('nonsticky_opts') 5947720Sgblack@eecs.umich.edu 5957720Sgblack@eecs.umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 5967720Sgblack@eecs.umich.edu# above options 5977720Sgblack@eecs.umich.edufor base_dir in base_dir_list: 5987720Sgblack@eecs.umich.edu for root, dirs, files in os.walk(base_dir): 5997720Sgblack@eecs.umich.edu if 'SConsopts' in files: 6007720Sgblack@eecs.umich.edu print "Reading", joinpath(root, 'SConsopts') 6017720Sgblack@eecs.umich.edu SConscript(joinpath(root, 'SConsopts')) 6023595Sgblack@eecs.umich.edu 6037741Sgblack@eecs.umich.eduall_isa_list.sort() 6047741Sgblack@eecs.umich.eduall_cpu_list.sort() 6053523Sgblack@eecs.umich.edudefault_cpus.sort() 6063595Sgblack@eecs.umich.edu 6073595Sgblack@eecs.umich.edusticky_opts.AddOptions( 6083595Sgblack@eecs.umich.edu EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6094172Ssaidi@eecs.umich.edu BoolOption('FULL_SYSTEM', 'Full-system support', False), 6103595Sgblack@eecs.umich.edu # There's a bug in scons 0.96.1 that causes ListOptions with list 6113523Sgblack@eecs.umich.edu # values (more than one value) not to be able to be restored from 6127741Sgblack@eecs.umich.edu # a saved option file. If this causes trouble then upgrade to 6133523Sgblack@eecs.umich.edu # scons 0.96.90 or later. 6143523Sgblack@eecs.umich.edu ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 6153523Sgblack@eecs.umich.edu BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6163523Sgblack@eecs.umich.edu BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6173523Sgblack@eecs.umich.edu False), 6183523Sgblack@eecs.umich.edu BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6193523Sgblack@eecs.umich.edu False), 6203523Sgblack@eecs.umich.edu BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 6213523Sgblack@eecs.umich.edu False), 6222221SN/A BoolOption('SS_COMPATIBLE_FP', 6232221SN/A 'Make floating-point results compatible with SimpleScalar', 6247741Sgblack@eecs.umich.edu False), 6257741Sgblack@eecs.umich.edu BoolOption('USE_SSE2', 6264997Sgblack@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 6278767Sgblack@eecs.umich.edu False), 6288767Sgblack@eecs.umich.edu BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6294997Sgblack@eecs.umich.edu BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6308767Sgblack@eecs.umich.edu BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 6318767Sgblack@eecs.umich.edu ) 6328767Sgblack@eecs.umich.edu 6338767Sgblack@eecs.umich.edunonsticky_opts.AddOptions( 6348767Sgblack@eecs.umich.edu BoolOption('update_ref', 'Update test reference outputs', False) 6358767Sgblack@eecs.umich.edu ) 6368767Sgblack@eecs.umich.edu 6378767Sgblack@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript). 6388767Sgblack@eecs.umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 6398767Sgblack@eecs.umich.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 6404997Sgblack@eecs.umich.edu 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 6414997Sgblack@eecs.umich.edu 'USE_CHECKER', 'TARGET_ISA'] 6424997Sgblack@eecs.umich.edu 6437741Sgblack@eecs.umich.edu# Define a handy 'no-op' action 6447741Sgblack@eecs.umich.edudef no_action(target, source, env): 6454997Sgblack@eecs.umich.edu return 0 6468767Sgblack@eecs.umich.edu 6478767Sgblack@eecs.umich.eduenv.NoAction = Action(no_action, None) 6488767Sgblack@eecs.umich.edu 6498767Sgblack@eecs.umich.edu################################################### 6508767Sgblack@eecs.umich.edu# 6518767Sgblack@eecs.umich.edu# Define a SCons builder for configuration flag headers. 6528767Sgblack@eecs.umich.edu# 6538767Sgblack@eecs.umich.edu################################################### 6548767Sgblack@eecs.umich.edu 6558767Sgblack@eecs.umich.edu# This function generates a config header file that #defines the 6568767Sgblack@eecs.umich.edu# option symbol to the current option setting (0 or 1). The source 6578767Sgblack@eecs.umich.edu# operands are the name of the option and a Value node containing the 6588767Sgblack@eecs.umich.edu# value of the option. 6598767Sgblack@eecs.umich.edudef build_config_file(target, source, env): 6608767Sgblack@eecs.umich.edu (option, value) = [s.get_contents() for s in source] 6618767Sgblack@eecs.umich.edu f = file(str(target[0]), 'w') 6628767Sgblack@eecs.umich.edu print >> f, '#define', option, value 6634997Sgblack@eecs.umich.edu f.close() 6644997Sgblack@eecs.umich.edu return None 6654997Sgblack@eecs.umich.edu 6667741Sgblack@eecs.umich.edu# Generate the message to be printed when building the config file. 6677741Sgblack@eecs.umich.edudef build_config_file_string(target, source, env): 6683415Sgblack@eecs.umich.edu (option, value) = [s.get_contents() for s in source] 6698750Sgblack@eecs.umich.edu return "Defining %s as %s in %s." % (option, value, target[0]) 6703578Sgblack@eecs.umich.edu 6713415Sgblack@eecs.umich.edu# Combine the two functions into a scons Action object. 6723415Sgblack@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string) 6733415Sgblack@eecs.umich.edu 6743578Sgblack@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 6753415Sgblack@eecs.umich.edu# we're really doing. 6763415Sgblack@eecs.umich.edudef config_emitter(target, source, env): 6773415Sgblack@eecs.umich.edu # extract option name from Builder arg 6787741Sgblack@eecs.umich.edu option = str(target[0]) 6797720Sgblack@eecs.umich.edu # True target is config header file 6808750Sgblack@eecs.umich.edu target = joinpath('config', option.lower() + '.hh') 6818750Sgblack@eecs.umich.edu val = env[option] 6828750Sgblack@eecs.umich.edu if isinstance(val, bool): 6833415Sgblack@eecs.umich.edu # Force value to 0/1 6843415Sgblack@eecs.umich.edu val = int(val) 6857741Sgblack@eecs.umich.edu elif isinstance(val, str): 6867741Sgblack@eecs.umich.edu val = '"' + val + '"' 6873415Sgblack@eecs.umich.edu 6888750Sgblack@eecs.umich.edu # Sources are option name & value (packaged in SCons Value nodes) 6893578Sgblack@eecs.umich.edu return ([target], [Value(option), Value(val)]) 6903415Sgblack@eecs.umich.edu 6917741Sgblack@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 6923415Sgblack@eecs.umich.edu 6933578Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 6943415Sgblack@eecs.umich.edu 6953415Sgblack@eecs.umich.edu################################################### 6963415Sgblack@eecs.umich.edu# 6977741Sgblack@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 6987720Sgblack@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here 6998750Sgblack@eecs.umich.edu# since it's potentially more generally applicable. 7008750Sgblack@eecs.umich.edu# 7018750Sgblack@eecs.umich.edu################################################### 7023415Sgblack@eecs.umich.edu 7033415Sgblack@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 7047741Sgblack@eecs.umich.edu 7057741Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 7064111Sgblack@eecs.umich.edu 7078750Sgblack@eecs.umich.edu################################################### 7087741Sgblack@eecs.umich.edu# 7097741Sgblack@eecs.umich.edu# Define a simple SCons builder to concatenate files. 7107741Sgblack@eecs.umich.edu# 7114111Sgblack@eecs.umich.edu# Used to append the Python zip archive to the executable. 7124111Sgblack@eecs.umich.edu# 7134111Sgblack@eecs.umich.edu################################################### 7144111Sgblack@eecs.umich.edu 7154111Sgblack@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 7164111Sgblack@eecs.umich.edu 'chmod +x $TARGET'])) 7174111Sgblack@eecs.umich.edu 7184111Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder }) 7197741Sgblack@eecs.umich.edu 7207741Sgblack@eecs.umich.edu 7217720Sgblack@eecs.umich.edu# libelf build is shared across all configs in the build root. 7227720Sgblack@eecs.umich.eduenv.SConscript('ext/libelf/SConscript', 7237720Sgblack@eecs.umich.edu build_dir = joinpath(build_root, 'libelf'), 7248750Sgblack@eecs.umich.edu exports = 'env') 7258750Sgblack@eecs.umich.edu 7268750Sgblack@eecs.umich.edu################################################### 7274111Sgblack@eecs.umich.edu# 7284111Sgblack@eecs.umich.edu# This function is used to set up a directory with switching headers 7292223SN/A# 7302221SN/A################################################### 731 732env['ALL_ISA_LIST'] = all_isa_list 733def make_switching_dir(dirname, switch_headers, env): 734 # Generate the header. target[0] is the full path of the output 735 # header to generate. 'source' is a dummy variable, since we get the 736 # list of ISAs from env['ALL_ISA_LIST']. 737 def gen_switch_hdr(target, source, env): 738 fname = str(target[0]) 739 basename = os.path.basename(fname) 740 f = open(fname, 'w') 741 f.write('#include "arch/isa_specific.hh"\n') 742 cond = '#if' 743 for isa in all_isa_list: 744 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 745 % (cond, isa.upper(), dirname, isa, basename)) 746 cond = '#elif' 747 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 748 f.close() 749 return 0 750 751 # String to print when generating header 752 def gen_switch_hdr_string(target, source, env): 753 return "Generating switch header " + str(target[0]) 754 755 # Build SCons Action object. 'varlist' specifies env vars that this 756 # action depends on; when env['ALL_ISA_LIST'] changes these actions 757 # should get re-executed. 758 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 759 varlist=['ALL_ISA_LIST']) 760 761 # Instantiate actions for each header 762 for hdr in switch_headers: 763 env.Command(hdr, [], switch_hdr_action) 764Export('make_switching_dir') 765 766################################################### 767# 768# Define build environments for selected configurations. 769# 770################################################### 771 772# rename base env 773base_env = env 774 775for build_path in build_paths: 776 print "Building in", build_path 777 778 # Make a copy of the build-root environment to use for this config. 779 env = base_env.Copy() 780 env['BUILDDIR'] = build_path 781 782 # build_dir is the tail component of build path, and is used to 783 # determine the build parameters (e.g., 'ALPHA_SE') 784 (build_root, build_dir) = os.path.split(build_path) 785 786 # Set env options according to the build directory config. 787 sticky_opts.files = [] 788 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 789 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 790 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 791 current_opts_file = joinpath(build_root, 'options', build_dir) 792 if isfile(current_opts_file): 793 sticky_opts.files.append(current_opts_file) 794 print "Using saved options file %s" % current_opts_file 795 else: 796 # Build dir-specific options file doesn't exist. 797 798 # Make sure the directory is there so we can create it later 799 opt_dir = os.path.dirname(current_opts_file) 800 if not isdir(opt_dir): 801 os.mkdir(opt_dir) 802 803 # Get default build options from source tree. Options are 804 # normally determined by name of $BUILD_DIR, but can be 805 # overriden by 'default=' arg on command line. 806 default_opts_file = joinpath('build_opts', 807 ARGUMENTS.get('default', build_dir)) 808 if isfile(default_opts_file): 809 sticky_opts.files.append(default_opts_file) 810 print "Options file %s not found,\n using defaults in %s" \ 811 % (current_opts_file, default_opts_file) 812 else: 813 print "Error: cannot find options file %s or %s" \ 814 % (current_opts_file, default_opts_file) 815 Exit(1) 816 817 # Apply current option settings to env 818 sticky_opts.Update(env) 819 nonsticky_opts.Update(env) 820 821 help_text += "\nSticky options for %s:\n" % build_dir \ 822 + sticky_opts.GenerateHelpText(env) \ 823 + "\nNon-sticky options for %s:\n" % build_dir \ 824 + nonsticky_opts.GenerateHelpText(env) 825 826 # Process option settings. 827 828 if not have_fenv and env['USE_FENV']: 829 print "Warning: <fenv.h> not available; " \ 830 "forcing USE_FENV to False in", build_dir + "." 831 env['USE_FENV'] = False 832 833 if not env['USE_FENV']: 834 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 835 print " FP results may deviate slightly from other platforms." 836 837 if env['EFENCE']: 838 env.Append(LIBS=['efence']) 839 840 if env['USE_MYSQL']: 841 if not have_mysql: 842 print "Warning: MySQL not available; " \ 843 "forcing USE_MYSQL to False in", build_dir + "." 844 env['USE_MYSQL'] = False 845 else: 846 print "Compiling in", build_dir, "with MySQL support." 847 env.ParseConfig(mysql_config_libs) 848 env.ParseConfig(mysql_config_include) 849 850 # Save sticky option settings back to current options file 851 sticky_opts.Save(current_opts_file, env) 852 853 if env['USE_SSE2']: 854 env.Append(CCFLAGS='-msse2') 855 856 # The src/SConscript file sets up the build rules in 'env' according 857 # to the configured options. It returns a list of environments, 858 # one for each variant build (debug, opt, etc.) 859 envList = SConscript('src/SConscript', build_dir = build_path, 860 exports = 'env') 861 862 # Set up the regression tests for each build. 863 for e in envList: 864 SConscript('tests/SConscript', 865 build_dir = joinpath(build_path, 'tests', e.Label), 866 exports = { 'env' : e }, duplicate = False) 867 868Help(help_text) 869 870 871################################################### 872# 873# Let SCons do its thing. At this point SCons will use the defined 874# build environments to build the requested targets. 875# 876################################################### 877 878