SConstruct revision 7756
1955SN/A# -*- mode:python -*- 2955SN/A 35871Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 41762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 5955SN/A# All rights reserved. 6955SN/A# 7955SN/A# Redistribution and use in source and binary forms, with or without 8955SN/A# modification, are permitted provided that the following conditions are 9955SN/A# met: redistributions of source code must retain the above copyright 10955SN/A# notice, this list of conditions and the following disclaimer; 11955SN/A# redistributions in binary form must reproduce the above copyright 12955SN/A# notice, this list of conditions and the following disclaimer in the 13955SN/A# documentation and/or other materials provided with the distribution; 14955SN/A# neither the name of the copyright holders nor the names of its 15955SN/A# contributors may be used to endorse or promote products derived from 16955SN/A# this software without specific prior written permission. 17955SN/A# 18955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 292665Ssaidi@eecs.umich.edu# 302665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 315863Snate@binkert.org# Nathan Binkert 32955SN/A 33955SN/A################################################### 34955SN/A# 35955SN/A# SCons top-level build description (SConstruct) file. 36955SN/A# 372632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 382632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 392632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 402632Sstever@eecs.umich.edu# the optimized full-system version). 41955SN/A# 422632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 432632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 442761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 452632Sstever@eecs.umich.edu# built for the same host system. 462632Sstever@eecs.umich.edu# 472632Sstever@eecs.umich.edu# Examples: 482761Sstever@eecs.umich.edu# 492761Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 502761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 512632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 522632Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 532761Sstever@eecs.umich.edu# 542761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 552761Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 562761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 572761Sstever@eecs.umich.edu# file. 582632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 592632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 602632Sstever@eecs.umich.edu# 612632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 622632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 632632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 642632Sstever@eecs.umich.edu# options as well. 65955SN/A# 66955SN/A################################################### 67955SN/A 685863Snate@binkert.org# Check for recent-enough Python and SCons versions. 695863Snate@binkert.orgtry: 705863Snate@binkert.org # Really old versions of scons only take two options for the 715863Snate@binkert.org # function, so check once without the revision and once with the 725863Snate@binkert.org # revision, the first instance will fail for stuff other than 735863Snate@binkert.org # 0.98, and the second will fail for 0.98.0 745863Snate@binkert.org EnsureSConsVersion(0, 98) 755863Snate@binkert.org EnsureSConsVersion(0, 98, 1) 765863Snate@binkert.orgexcept SystemExit, e: 775863Snate@binkert.org print """ 785863Snate@binkert.orgFor more details, see: 795863Snate@binkert.org http://m5sim.org/wiki/index.php/Compiling_M5 805863Snate@binkert.org""" 815863Snate@binkert.org raise 825863Snate@binkert.org 835863Snate@binkert.org# We ensure the python version early because we have stuff that 845863Snate@binkert.org# requires python 2.4 855863Snate@binkert.orgtry: 865863Snate@binkert.org EnsurePythonVersion(2, 4) 875863Snate@binkert.orgexcept SystemExit, e: 885863Snate@binkert.org print """ 895863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 905863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 915863Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter 925863Snate@binkert.orgon the scons script. 935863Snate@binkert.org 945863Snate@binkert.orgFor more details, see: 955863Snate@binkert.org http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 965863Snate@binkert.org""" 975863Snate@binkert.org raise 985863Snate@binkert.org 996654Snate@binkert.org# Global Python includes 100955SN/Aimport os 1015396Ssaidi@eecs.umich.eduimport re 1025863Snate@binkert.orgimport subprocess 1035863Snate@binkert.orgimport sys 1044202Sbinkertn@umich.edu 1055863Snate@binkert.orgfrom os import mkdir, environ 1065863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1075863Snate@binkert.orgfrom os.path import exists, isdir, isfile 1085863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 109955SN/A 1106654Snate@binkert.org# SCons includes 1115273Sstever@gmail.comimport SCons 1125871Snate@binkert.orgimport SCons.Node 1135273Sstever@gmail.com 1146654Snate@binkert.orgextra_python_paths = [ 1156654Snate@binkert.org Dir('src/python').srcnode().abspath, # M5 includes 1165871Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1176654Snate@binkert.org ] 1185396Ssaidi@eecs.umich.edu 1195871Snate@binkert.orgsys.path[1:1] = extra_python_paths 1205871Snate@binkert.org 1216121Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1225871Snate@binkert.org 1235871Snate@binkert.org######################################################################## 1246003Snate@binkert.org# 1256003Snate@binkert.org# Set up the main build environment. 126955SN/A# 1275871Snate@binkert.org######################################################################## 1285871Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1295871Snate@binkert.org 'PYTHONPATH', 'RANLIB' ]) 1305871Snate@binkert.org 131955SN/Ause_env = {} 1326121Snate@binkert.orgfor key,val in os.environ.iteritems(): 1336121Snate@binkert.org if key in use_vars or key.startswith("M5"): 1346121Snate@binkert.org use_env[key] = val 1351533SN/A 1365871Snate@binkert.orgmain = Environment(ENV=use_env) 1375871Snate@binkert.orgmain.root = Dir(".") # The current directory (where this file lives). 1385863Snate@binkert.orgmain.srcdir = Dir("src") # The source directory 1395871Snate@binkert.org 1405871Snate@binkert.org# add useful python code PYTHONPATH so it can be used by subprocesses 1415871Snate@binkert.org# as well 1425871Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths) 1435871Snate@binkert.org 1445863Snate@binkert.org######################################################################## 1456121Snate@binkert.org# 1465863Snate@binkert.org# Mercurial Stuff. 1475871Snate@binkert.org# 1484678Snate@binkert.org# If the M5 directory is a mercurial repository, we should do some 1494678Snate@binkert.org# extra things. 1504678Snate@binkert.org# 1514678Snate@binkert.org######################################################################## 1524678Snate@binkert.org 1534678Snate@binkert.orghgdir = main.root.Dir(".hg") 1544678Snate@binkert.org 1554678Snate@binkert.orgmercurial_style_message = """ 1564678Snate@binkert.orgYou're missing the M5 style hook. 1574678Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style. 1584678Snate@binkert.org 1594678Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc 1606121Snate@binkert.orgor your personal .hgrc 1614678Snate@binkert.org---------------- 1625871Snate@binkert.org 1635871Snate@binkert.org[extensions] 1645871Snate@binkert.orgstyle = %s/util/style.py 1655871Snate@binkert.org 1665871Snate@binkert.org[hooks] 1675871Snate@binkert.orgpretxncommit.style = python:style.check_whitespace 1685871Snate@binkert.org""" % (main.root) 1695871Snate@binkert.org 1705871Snate@binkert.orgmercurial_bin_not_found = """ 1715871Snate@binkert.orgMercurial binary cannot be found, unfortunately this means that we 1725871Snate@binkert.orgcannot easily determine the version of M5 that you are running and 1735871Snate@binkert.orgthis makes error messages more difficult to collect. Please consider 1745871Snate@binkert.orginstalling mercurial if you choose to post an error message 1755990Ssaidi@eecs.umich.edu""" 1765871Snate@binkert.org 1775871Snate@binkert.orgmercurial_lib_not_found = """ 1785871Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook 1794678Snate@binkert.orgIf you are actually a M5 developer, please fix this and 1806654Snate@binkert.orgrun the style hook. It is important. 1815871Snate@binkert.org""" 1825871Snate@binkert.org 1835871Snate@binkert.orghg_info = "Unknown" 1845871Snate@binkert.orgif hgdir.exists(): 1855871Snate@binkert.org # 1) Grab repository revision if we know it. 1865871Snate@binkert.org cmd = "hg id -n -i -t -b" 1875871Snate@binkert.org try: 1885871Snate@binkert.org hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 1895871Snate@binkert.org except OSError: 1904678Snate@binkert.org print mercurial_bin_not_found 1915871Snate@binkert.org 1924678Snate@binkert.org # 2) Ensure that the style hook is in place. 1935871Snate@binkert.org try: 1945871Snate@binkert.org ui = None 1955871Snate@binkert.org if ARGUMENTS.get('IGNORE_STYLE') != 'True': 1965871Snate@binkert.org from mercurial import ui 1975871Snate@binkert.org ui = ui.ui() 1985871Snate@binkert.org except ImportError: 1995871Snate@binkert.org print mercurial_lib_not_found 2005871Snate@binkert.org 2015871Snate@binkert.org if ui is not None: 2026121Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2036121Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) 2045863Snate@binkert.org 205955SN/A if not style_hook: 206955SN/A print mercurial_style_message 2072632Sstever@eecs.umich.edu sys.exit(1) 2082632Sstever@eecs.umich.eduelse: 209955SN/A print ".hg directory not found" 210955SN/A 211955SN/Amain['HG_INFO'] = hg_info 212955SN/A 2135863Snate@binkert.org################################################### 214955SN/A# 2152632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2162632Sstever@eecs.umich.edu# the target(s). 2172632Sstever@eecs.umich.edu# 2182632Sstever@eecs.umich.edu################################################### 2192632Sstever@eecs.umich.edu 2202632Sstever@eecs.umich.edu# Find default configuration & binary. 2212632Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2222632Sstever@eecs.umich.edu 2232632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 2242632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 2252632Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2262632Sstever@eecs.umich.edu if l[i] == elt: 2272632Sstever@eecs.umich.edu return i 2283718Sstever@eecs.umich.edu raise ValueError, "element not found" 2293718Sstever@eecs.umich.edu 2303718Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2313718Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2323718Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2335863Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 2345863Snate@binkert.org# follow 'build' in the bulid path. 2353718Sstever@eecs.umich.edu 2363718Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is 2376121Snate@binkert.orgif COMMAND_LINE_TARGETS: 2385863Snate@binkert.org # Ask SCons which directory it was invoked from 2393718Sstever@eecs.umich.edu launch_dir = GetLaunchDir() 2403718Sstever@eecs.umich.edu # Make targets relative to invocation directory 2412634Sstever@eecs.umich.edu abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2422634Sstever@eecs.umich.edu COMMAND_LINE_TARGETS] 2435863Snate@binkert.orgelse: 2442638Sstever@eecs.umich.edu # Default targets are relative to root of tree 2452632Sstever@eecs.umich.edu abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2462632Sstever@eecs.umich.edu DEFAULT_TARGETS] 2472632Sstever@eecs.umich.edu 2482632Sstever@eecs.umich.edu 2492632Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 2502632Sstever@eecs.umich.edu# collected targets reference. 2511858SN/Avariant_paths = [] 2523716Sstever@eecs.umich.edubuild_root = None 2532638Sstever@eecs.umich.edufor t in abs_targets: 2542638Sstever@eecs.umich.edu path_dirs = t.split('/') 2552638Sstever@eecs.umich.edu try: 2562638Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 2572638Sstever@eecs.umich.edu except: 2582638Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 2592638Sstever@eecs.umich.edu Exit(1) 2605863Snate@binkert.org this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2615863Snate@binkert.org if not build_root: 2625863Snate@binkert.org build_root = this_build_root 263955SN/A else: 2645341Sstever@gmail.com if this_build_root != build_root: 2655341Sstever@gmail.com print "Error: build targets not under same build root\n"\ 2665863Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 2675341Sstever@gmail.com Exit(1) 2686121Snate@binkert.org variant_path = joinpath('/',*path_dirs[:build_top+2]) 2694494Ssaidi@eecs.umich.edu if variant_path not in variant_paths: 2706121Snate@binkert.org variant_paths.append(variant_path) 2711105SN/A 2722667Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 2732667Sstever@eecs.umich.eduif not isdir(build_root): 2742667Sstever@eecs.umich.edu mkdir(build_root) 2752667Sstever@eecs.umich.edumain['BUILDROOT'] = build_root 2766121Snate@binkert.org 2772667Sstever@eecs.umich.eduExport('main') 2785341Sstever@gmail.com 2795863Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign")) 2805341Sstever@gmail.com 2815341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up 2825341Sstever@gmail.com# when you use emacs to edit a file in the target dir, as emacs moves 2835863Snate@binkert.org# file to file~ then copies to file, breaking the link. Symbolic 2845341Sstever@gmail.com# (soft) links work better. 2855341Sstever@gmail.commain.SetOption('duplicate', 'soft-copy') 2865341Sstever@gmail.com 2875863Snate@binkert.org# 2885341Sstever@gmail.com# Set up global sticky variables... these are common to an entire build 2895341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE) 2905341Sstever@gmail.com# 2915341Sstever@gmail.com 2925341Sstever@gmail.com# Variable validators & converters for global sticky variables 2935341Sstever@gmail.comdef PathListMakeAbsolute(val): 2945341Sstever@gmail.com if not val: 2955341Sstever@gmail.com return val 2965341Sstever@gmail.com f = lambda p: abspath(expanduser(p)) 2975341Sstever@gmail.com return ':'.join(map(f, val.split(':'))) 2985863Snate@binkert.org 2995341Sstever@gmail.comdef PathListAllExist(key, val, env): 3005863Snate@binkert.org if not val: 3015341Sstever@gmail.com return 3025863Snate@binkert.org paths = val.split(':') 3036121Snate@binkert.org for path in paths: 3046121Snate@binkert.org if not isdir(path): 3055397Ssaidi@eecs.umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3065397Ssaidi@eecs.umich.edu 3075341Sstever@gmail.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3086168Snate@binkert.org 3096168Snate@binkert.orgglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3106168Snate@binkert.orgglobal_nonsticky_vars = Variables(args=ARGUMENTS) 3115341Sstever@gmail.com 3125341Sstever@gmail.comglobal_sticky_vars.AddVariables( 3135341Sstever@gmail.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 3145341Sstever@gmail.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3155341Sstever@gmail.com ('BATCH', 'Use batch pool for build and tests', False), 3165863Snate@binkert.org ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3175341Sstever@gmail.com ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3185341Sstever@gmail.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3196121Snate@binkert.org PathListAllExist, PathListMakeAbsolute), 3205341Sstever@gmail.com ) 3216121Snate@binkert.org 3226121Snate@binkert.orgglobal_nonsticky_vars.AddVariables( 3235341Sstever@gmail.com ('VERBOSE', 'Print full tool command lines', False), 3245863Snate@binkert.org ('update_ref', 'Update test reference outputs', False) 3256121Snate@binkert.org ) 3265341Sstever@gmail.com 3275863Snate@binkert.org 3285341Sstever@gmail.com# base help text 3296121Snate@binkert.orghelp_text = ''' 3306121Snate@binkert.orgUsage: scons [scons options] [build options] [target(s)] 3316121Snate@binkert.org 3325742Snate@binkert.orgGlobal sticky options: 3335742Snate@binkert.org''' 3345341Sstever@gmail.com 3355742Snate@binkert.org# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3365742Snate@binkert.orgglobal_sticky_vars.Update(main) 3375341Sstever@gmail.comglobal_nonsticky_vars.Update(main) 3386017Snate@binkert.org 3396121Snate@binkert.orghelp_text += global_sticky_vars.GenerateHelpText(main) 3406017Snate@binkert.orghelp_text += global_nonsticky_vars.GenerateHelpText(main) 3412632Sstever@eecs.umich.edu 3426121Snate@binkert.org# Save sticky variable settings back to current variables file 3435871Snate@binkert.orgglobal_sticky_vars.Save(global_sticky_vars_file, main) 3446654Snate@binkert.org 3456654Snate@binkert.org# Parse EXTRAS variable to build list of all directories where we're 3465871Snate@binkert.org# look for sources etc. This list is exported as base_dir_list. 3476121Snate@binkert.orgbase_dir = main.srcdir.abspath 3486121Snate@binkert.orgif main['EXTRAS']: 3496121Snate@binkert.org extras_dir_list = main['EXTRAS'].split(':') 3506121Snate@binkert.orgelse: 3513940Ssaidi@eecs.umich.edu extras_dir_list = [] 3523918Ssaidi@eecs.umich.edu 3533918Ssaidi@eecs.umich.eduExport('base_dir') 3541858SN/AExport('extras_dir_list') 3556121Snate@binkert.org 3566121Snate@binkert.org# the ext directory should be on the #includes path 3576121Snate@binkert.orgmain.Append(CPPPATH=[Dir('ext')]) 3586143Snate@binkert.org 3596121Snate@binkert.orgdef _STRIP(path, env): 3606121Snate@binkert.org path = str(path) 3613940Ssaidi@eecs.umich.edu variant_base = env['BUILDROOT'] + os.path.sep 3626121Snate@binkert.org if path.startswith(variant_base): 3636121Snate@binkert.org path = path[len(variant_base):] 3646121Snate@binkert.org elif path.startswith('build/'): 3656121Snate@binkert.org path = path[6:] 3666121Snate@binkert.org return path 3676121Snate@binkert.org 3686121Snate@binkert.orgdef _STRIP_SOURCE(target, source, env, for_signature): 3693918Ssaidi@eecs.umich.edu return _STRIP(source[0], env) 3703918Ssaidi@eecs.umich.edumain['STRIP_SOURCE'] = _STRIP_SOURCE 3713940Ssaidi@eecs.umich.edu 3723918Ssaidi@eecs.umich.edudef _STRIP_TARGET(target, source, env, for_signature): 3733918Ssaidi@eecs.umich.edu return _STRIP(target[0], env) 3746157Snate@binkert.orgmain['STRIP_TARGET'] = _STRIP_TARGET 3756157Snate@binkert.org 3766157Snate@binkert.orgif main['VERBOSE']: 3776157Snate@binkert.org def MakeAction(action, string, *args, **kwargs): 3785397Ssaidi@eecs.umich.edu return Action(action, *args, **kwargs) 3795397Ssaidi@eecs.umich.eduelse: 3806121Snate@binkert.org MakeAction = Action 3816121Snate@binkert.org main['CCCOMSTR'] = ' [ CC] $STRIP_SOURCE' 3826121Snate@binkert.org main['CXXCOMSTR'] = ' [ CXX] $STRIP_SOURCE' 3836121Snate@binkert.org main['ASCOMSTR'] = ' [ AS] $STRIP_SOURCE' 3846121Snate@binkert.org main['SWIGCOMSTR'] = ' [ SWIG] $STRIP_SOURCE' 3856121Snate@binkert.org main['ARCOMSTR'] = ' [ AR] $STRIP_TARGET' 3865397Ssaidi@eecs.umich.edu main['LINKCOMSTR'] = ' [ LINK] $STRIP_TARGET' 3871851SN/A main['RANLIBCOMSTR'] = ' [ RANLIB] $STRIP_TARGET' 3881851SN/A main['M4COMSTR'] = ' [ M4] $STRIP_TARGET' 3896121Snate@binkert.org main['SHCCCOMSTR'] = ' [ SHCC] $STRIP_TARGET' 390955SN/A main['SHCXXCOMSTR'] = ' [ SHCXX] $STRIP_TARGET' 3913053Sstever@eecs.umich.eduExport('MakeAction') 3926121Snate@binkert.org 3933053Sstever@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 3943053Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 3953053Sstever@eecs.umich.edu 3963053Sstever@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3973053Sstever@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3986654Snate@binkert.orgmain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 3993053Sstever@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 4004742Sstever@eecs.umich.edu print 'Error: How can we have two at the same time?' 4014742Sstever@eecs.umich.edu Exit(1) 4023053Sstever@eecs.umich.edu 4033053Sstever@eecs.umich.edu# Set up default C++ compiler flags 4043053Sstever@eecs.umich.eduif main['GCC']: 4053053Sstever@eecs.umich.edu main.Append(CCFLAGS=['-pipe']) 4066654Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 4073053Sstever@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4083053Sstever@eecs.umich.edu main.Append(CXXFLAGS=['-Wno-deprecated']) 4093053Sstever@eecs.umich.edu # Read the GCC version to check for versions with bugs 4103053Sstever@eecs.umich.edu # Note CCVERSION doesn't work here because it is run with the CC 4112667Sstever@eecs.umich.edu # before we override it from the command line 4124554Sbinkertn@umich.edu gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4136121Snate@binkert.org if not compareVersions(gcc_version, '4.4.1') or \ 4142667Sstever@eecs.umich.edu not compareVersions(gcc_version, '4.4.2'): 4154554Sbinkertn@umich.edu print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 4164554Sbinkertn@umich.edu main.Append(CCFLAGS=['-fno-tree-vectorize']) 4174554Sbinkertn@umich.eduelif main['ICC']: 4186121Snate@binkert.org pass #Fix me... add warning flags once we clean up icc warnings 4194554Sbinkertn@umich.eduelif main['SUNCC']: 4204554Sbinkertn@umich.edu main.Append(CCFLAGS=['-Qoption ccfe']) 4214554Sbinkertn@umich.edu main.Append(CCFLAGS=['-features=gcc']) 4224781Snate@binkert.org main.Append(CCFLAGS=['-features=extensions']) 4234554Sbinkertn@umich.edu main.Append(CCFLAGS=['-library=stlport4']) 4244554Sbinkertn@umich.edu main.Append(CCFLAGS=['-xar']) 4252667Sstever@eecs.umich.edu #main.Append(CCFLAGS=['-instances=semiexplicit']) 4264554Sbinkertn@umich.eduelse: 4274554Sbinkertn@umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 4284554Sbinkertn@umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 4294554Sbinkertn@umich.edu Exit(1) 4302667Sstever@eecs.umich.edu 4314554Sbinkertn@umich.edu# Set up common yacc/bison flags (needed for Ruby) 4322667Sstever@eecs.umich.edumain['YACCFLAGS'] = '-d' 4334554Sbinkertn@umich.edumain['YACCHXXFILESUFFIX'] = '.hh' 4346121Snate@binkert.org 4352667Sstever@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 4365522Snate@binkert.org# extra 'qdo' every time we run scons. 4375522Snate@binkert.orgif main['BATCH']: 4385522Snate@binkert.org main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 4395522Snate@binkert.org main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 4405522Snate@binkert.org main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 4415522Snate@binkert.org main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 4425522Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 4435522Snate@binkert.org 4445522Snate@binkert.orgif sys.platform == 'cygwin': 4455522Snate@binkert.org # cygwin has some header file issues... 4465522Snate@binkert.org main.Append(CCFLAGS=["-Wno-uninitialized"]) 4475522Snate@binkert.org 4485522Snate@binkert.org# Check for SWIG 4495522Snate@binkert.orgif not main.has_key('SWIG'): 4505522Snate@binkert.org print 'Error: SWIG utility not found.' 4515522Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 4525522Snate@binkert.org Exit(1) 4535522Snate@binkert.org 4545522Snate@binkert.org# Check for appropriate SWIG version 4555522Snate@binkert.orgswig_version = readCommand(('swig', '-version'), exception='').split() 4565522Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 4575522Snate@binkert.orgif len(swig_version) < 3 or \ 4585522Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 4595522Snate@binkert.org print 'Error determining SWIG version.' 4605522Snate@binkert.org Exit(1) 4615522Snate@binkert.org 4622638Sstever@eecs.umich.edumin_swig_version = '1.3.28' 4632638Sstever@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0: 4646121Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 4653716Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 4665522Snate@binkert.org Exit(1) 4675522Snate@binkert.org 4685522Snate@binkert.org# Set up SWIG flags & scanner 4695522Snate@binkert.orgswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4705522Snate@binkert.orgmain.Append(SWIGFLAGS=swig_flags) 4715522Snate@binkert.org 4721858SN/A# filter out all existing swig scanners, they mess up the dependency 4735227Ssaidi@eecs.umich.edu# stuff for some reason 4745227Ssaidi@eecs.umich.eduscanners = [] 4755227Ssaidi@eecs.umich.edufor scanner in main['SCANNERS']: 4765227Ssaidi@eecs.umich.edu skeys = scanner.skeys 4776654Snate@binkert.org if skeys == '.i': 4786654Snate@binkert.org continue 4796121Snate@binkert.org 4806121Snate@binkert.org if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4816121Snate@binkert.org continue 4826121Snate@binkert.org 4835227Ssaidi@eecs.umich.edu scanners.append(scanner) 4845227Ssaidi@eecs.umich.edu 4855227Ssaidi@eecs.umich.edu# add the new swig scanner that we like better 4865204Sstever@gmail.comfrom SCons.Scanner import ClassicCPP as CPPScanner 4875204Sstever@gmail.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4885204Sstever@gmail.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4895204Sstever@gmail.com 4905204Sstever@gmail.com# replace the scanners list that has what we want 4915204Sstever@gmail.commain['SCANNERS'] = scanners 4925204Sstever@gmail.com 4935204Sstever@gmail.com# Add a custom Check function to the Configure context so that we can 4945204Sstever@gmail.com# figure out if the compiler adds leading underscores to global 4955204Sstever@gmail.com# variables. This is needed for the autogenerated asm files that we 4965204Sstever@gmail.com# use for embedding the python code. 4975204Sstever@gmail.comdef CheckLeading(context): 4985204Sstever@gmail.com context.Message("Checking for leading underscore in global variables...") 4995204Sstever@gmail.com # 1) Define a global variable called x from asm so the C compiler 5005204Sstever@gmail.com # won't change the symbol at all. 5015204Sstever@gmail.com # 2) Declare that variable. 5025204Sstever@gmail.com # 3) Use the variable 5036121Snate@binkert.org # 5045204Sstever@gmail.com # If the compiler prepends an underscore, this will successfully 5053118Sstever@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 5063118Sstever@eecs.umich.edu # was defined by the asm statement. If the compiler does not 5073118Sstever@eecs.umich.edu # prepend an underscore, this will not successfully link because 5083118Sstever@eecs.umich.edu # '_x' will have been defined by assembly, while the C portion of 5093118Sstever@eecs.umich.edu # the code will be trying to use 'x' 5105863Snate@binkert.org ret = context.TryLink(''' 5113118Sstever@eecs.umich.edu asm(".globl _x; _x: .byte 0"); 5125863Snate@binkert.org extern int x; 5133118Sstever@eecs.umich.edu int main() { return x; } 5145863Snate@binkert.org ''', extension=".c") 5155863Snate@binkert.org context.env.Append(LEADING_UNDERSCORE=ret) 5165863Snate@binkert.org context.Result(ret) 5175863Snate@binkert.org return ret 5185863Snate@binkert.org 5195863Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 5205863Snate@binkert.org# builds under a given build root run on the same host platform. 5215863Snate@binkert.orgconf = Configure(main, 5226003Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 5235863Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 5245863Snate@binkert.org custom_tests = { 'CheckLeading' : CheckLeading }) 5255863Snate@binkert.org 5266120Snate@binkert.org# Check for leading underscores. Don't really need to worry either 5275863Snate@binkert.org# way so don't need to check the return code. 5285863Snate@binkert.orgconf.CheckLeading() 5295863Snate@binkert.org 5306120Snate@binkert.org# Check if we should compile a 64 bit binary on Mac OS X/Darwin 5316120Snate@binkert.orgtry: 5325863Snate@binkert.org import platform 5335863Snate@binkert.org uname = platform.uname() 5346120Snate@binkert.org if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 5355863Snate@binkert.org if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 5366121Snate@binkert.org main.Append(CCFLAGS=['-arch x86_64']) 5376121Snate@binkert.org main.Append(CFLAGS=['-arch x86_64']) 5385863Snate@binkert.org main.Append(LINKFLAGS=['-arch x86_64']) 5395863Snate@binkert.org main.Append(ASFLAGS=['-arch x86_64']) 5403118Sstever@eecs.umich.eduexcept: 5415863Snate@binkert.org pass 5423118Sstever@eecs.umich.edu 5433118Sstever@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 5445863Snate@binkert.org# when configuration isn't necessary, e.g., if the "--help" option is 5455863Snate@binkert.org# present. Unfortuantely this Null object always returns false, 5465863Snate@binkert.org# breaking all our configuration checks. We replace it with our own 5475863Snate@binkert.org# more optimistic null object that returns True instead. 5483118Sstever@eecs.umich.eduif not conf: 5493483Ssaidi@eecs.umich.edu def NullCheck(*args, **kwargs): 5503494Ssaidi@eecs.umich.edu return True 5513494Ssaidi@eecs.umich.edu 5523483Ssaidi@eecs.umich.edu class NullConf: 5533483Ssaidi@eecs.umich.edu def __init__(self, env): 5543483Ssaidi@eecs.umich.edu self.env = env 5553053Sstever@eecs.umich.edu def Finish(self): 5563053Sstever@eecs.umich.edu return self.env 5573918Ssaidi@eecs.umich.edu def __getattr__(self, mname): 5583053Sstever@eecs.umich.edu return NullCheck 5593053Sstever@eecs.umich.edu 5603053Sstever@eecs.umich.edu conf = NullConf(main) 5613053Sstever@eecs.umich.edu 5623053Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 5631858SN/A# interpreter. For consistency, we will use the same Python 5641858SN/A# installation used to run scons (and thus this script). If you want 5651858SN/A# to link in an alternate version, see above for instructions on how 5661858SN/A# to invoke scons with a different copy of the Python interpreter. 5671858SN/Afrom distutils import sysconfig 5681858SN/A 5695863Snate@binkert.orgpy_getvar = sysconfig.get_config_var 5705863Snate@binkert.org 5711859SN/Apy_debug = getattr(sys, 'pydebug', False) 5725863Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 5731858SN/A 5745863Snate@binkert.orgpy_general_include = sysconfig.get_python_inc() 5751858SN/Apy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5761859SN/Apy_includes = [ py_general_include ] 5771859SN/Aif py_platform_include != py_general_include: 5786654Snate@binkert.org py_includes.append(py_platform_include) 5793053Sstever@eecs.umich.edu 5806654Snate@binkert.orgpy_lib_path = [ py_getvar('LIBDIR') ] 5813053Sstever@eecs.umich.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5823053Sstever@eecs.umich.edu# shared library in prefix/lib/. 5831859SN/Aif not py_getvar('Py_ENABLE_SHARED'): 5841859SN/A py_lib_path.append(py_getvar('LIBPL')) 5851859SN/A 5861859SN/Apy_libs = [] 5871859SN/Afor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 5881859SN/A assert lib.startswith('-l') 5891859SN/A lib = lib[2:] 5901859SN/A if lib not in py_libs: 5911862SN/A py_libs.append(lib) 5921859SN/Apy_libs.append(py_version) 5931859SN/A 5941859SN/Amain.Append(CPPPATH=py_includes) 5955863Snate@binkert.orgmain.Append(LIBPATH=py_lib_path) 5965863Snate@binkert.org 5975863Snate@binkert.org# Cache build files in the supplied directory. 5985863Snate@binkert.orgif main['M5_BUILD_CACHE']: 5996121Snate@binkert.org print 'Using build cache located at', main['M5_BUILD_CACHE'] 6001858SN/A CacheDir(main['M5_BUILD_CACHE']) 6015863Snate@binkert.org 6025863Snate@binkert.org 6035863Snate@binkert.org# verify that this stuff works 6045863Snate@binkert.orgif not conf.CheckHeader('Python.h', '<>'): 6055863Snate@binkert.org print "Error: can't find Python.h header in", py_includes 6062139SN/A Exit(1) 6074202Sbinkertn@umich.edu 6084202Sbinkertn@umich.edufor lib in py_libs: 6092139SN/A if not conf.CheckLib(lib): 6102155SN/A print "Error: can't find library %s required by python" % lib 6114202Sbinkertn@umich.edu Exit(1) 6124202Sbinkertn@umich.edu 6134202Sbinkertn@umich.edu# On Solaris you need to use libsocket for socket ops 6142155SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6155863Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6161869SN/A print "Can't find library with socket calls (e.g. accept())" 6171869SN/A Exit(1) 6185863Snate@binkert.org 6195863Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 6204202Sbinkertn@umich.edu# added to the LIBS environment variable. 6216108Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 6226108Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 6236108Snate@binkert.org 'and/or zlib.h header file.' 6246108Snate@binkert.org print ' Please install zlib and try again.' 6255863Snate@binkert.org Exit(1) 6265863Snate@binkert.org 6275863Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 6284202Sbinkertn@umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 6294202Sbinkertn@umich.eduif not have_fenv: 6305863Snate@binkert.org print "Warning: Header file <fenv.h> not found." 6315742Snate@binkert.org print " This host has no IEEE FP rounding mode control." 6325742Snate@binkert.org 6335341Sstever@gmail.com###################################################################### 6345342Sstever@gmail.com# 6355342Sstever@gmail.com# Check for mysql. 6364202Sbinkertn@umich.edu# 6374202Sbinkertn@umich.edumysql_config = WhereIs('mysql_config') 6384202Sbinkertn@umich.eduhave_mysql = bool(mysql_config) 6394202Sbinkertn@umich.edu 6404202Sbinkertn@umich.edu# Check MySQL version. 6415863Snate@binkert.orgif have_mysql: 6425863Snate@binkert.org mysql_version = readCommand(mysql_config + ' --version') 6435863Snate@binkert.org min_mysql_version = '4.1' 6445863Snate@binkert.org if compareVersions(mysql_version, min_mysql_version) < 0: 6455863Snate@binkert.org print 'Warning: MySQL', min_mysql_version, 'or newer required.' 6465863Snate@binkert.org print ' Version', mysql_version, 'detected.' 6475863Snate@binkert.org have_mysql = False 6485863Snate@binkert.org 6495863Snate@binkert.org# Set up mysql_config commands. 6505863Snate@binkert.orgif have_mysql: 6515863Snate@binkert.org mysql_config_include = mysql_config + ' --include' 6525863Snate@binkert.org if os.system(mysql_config_include + ' > /dev/null') != 0: 6535863Snate@binkert.org # older mysql_config versions don't support --include, use 6545863Snate@binkert.org # --cflags instead 6555863Snate@binkert.org mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 6565863Snate@binkert.org # This seems to work in all versions 6575863Snate@binkert.org mysql_config_libs = mysql_config + ' --libs' 6585863Snate@binkert.org 6595863Snate@binkert.org###################################################################### 6605863Snate@binkert.org# 6615952Ssaidi@eecs.umich.edu# Finish the configuration 6621869SN/A# 6631858SN/Amain = conf.Finish() 6645863Snate@binkert.org 6655863Snate@binkert.org###################################################################### 6661869SN/A# 6671858SN/A# Collect all non-global variables 6685863Snate@binkert.org# 6696108Snate@binkert.org 6706108Snate@binkert.org# Define the universe of supported ISAs 6716108Snate@binkert.orgall_isa_list = [ ] 6721858SN/AExport('all_isa_list') 673955SN/A 674955SN/Aclass CpuModel(object): 6751869SN/A '''The CpuModel class encapsulates everything the ISA parser needs to 6761869SN/A know about a particular CPU model.''' 6771869SN/A 6781869SN/A # Dict of available CPU model objects. Accessible as CpuModel.dict. 6791869SN/A dict = {} 6805863Snate@binkert.org list = [] 6815863Snate@binkert.org defaults = [] 6825863Snate@binkert.org 6831869SN/A # Constructor. Automatically adds models to CpuModel.dict. 6845863Snate@binkert.org def __init__(self, name, filename, includes, strings, default=False): 6851869SN/A self.name = name # name of model 6865863Snate@binkert.org self.filename = filename # filename for output exec code 6871869SN/A self.includes = includes # include files needed in exec file 6881869SN/A # The 'strings' dict holds all the per-CPU symbols we can 6891869SN/A # substitute into templates etc. 6901869SN/A self.strings = strings 6911869SN/A 6925863Snate@binkert.org # This cpu is enabled by default 6935863Snate@binkert.org self.default = default 6941869SN/A 6951869SN/A # Add self to dict 6961869SN/A if name in CpuModel.dict: 6971869SN/A raise AttributeError, "CpuModel '%s' already registered" % name 6981869SN/A CpuModel.dict[name] = self 6991869SN/A CpuModel.list.append(name) 7001869SN/A 7015863Snate@binkert.orgExport('CpuModel') 7025863Snate@binkert.org 7031869SN/A# Sticky variables get saved in the variables file so they persist from 7045863Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 7055863Snate@binkert.org# value becomes sticky). 7063356Sbinkertn@umich.edusticky_vars = Variables(args=ARGUMENTS) 7073356Sbinkertn@umich.eduExport('sticky_vars') 7083356Sbinkertn@umich.edu 7093356Sbinkertn@umich.edu# Sticky variables that should be exported 7103356Sbinkertn@umich.eduexport_vars = [] 7114781Snate@binkert.orgExport('export_vars') 7125863Snate@binkert.org 7135863Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 7141869SN/A# above variables 7151869SN/Afor bdir in [ base_dir ] + extras_dir_list: 7161869SN/A for root, dirs, files in os.walk(bdir): 7176121Snate@binkert.org if 'SConsopts' in files: 7181869SN/A print "Reading", joinpath(root, 'SConsopts') 7192638Sstever@eecs.umich.edu SConscript(joinpath(root, 'SConsopts')) 7206121Snate@binkert.org 7216121Snate@binkert.orgall_isa_list.sort() 7222638Sstever@eecs.umich.edu 7235749Scws3k@cs.virginia.edusticky_vars.AddVariables( 7246121Snate@binkert.org EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 7256121Snate@binkert.org BoolVariable('FULL_SYSTEM', 'Full-system support', False), 7265749Scws3k@cs.virginia.edu ListVariable('CPU_MODELS', 'CPU models', 7271869SN/A sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 7281869SN/A sorted(CpuModel.list)), 7293546Sgblack@eecs.umich.edu BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 7303546Sgblack@eecs.umich.edu BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 7313546Sgblack@eecs.umich.edu False), 7323546Sgblack@eecs.umich.edu BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 7336121Snate@binkert.org False), 7345863Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 7353546Sgblack@eecs.umich.edu False), 7363546Sgblack@eecs.umich.edu BoolVariable('SS_COMPATIBLE_FP', 7373546Sgblack@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 7383546Sgblack@eecs.umich.edu False), 7394781Snate@binkert.org BoolVariable('USE_SSE2', 7405863Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 7414781Snate@binkert.org False), 7424781Snate@binkert.org BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 7434781Snate@binkert.org BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 7444781Snate@binkert.org BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 7454781Snate@binkert.org BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 7465863Snate@binkert.org BoolVariable('RUBY', 'Build with Ruby', False), 7474781Snate@binkert.org ) 7484781Snate@binkert.org 7494781Snate@binkert.org# These variables get exported to #defines in config/*.hh (see src/SConscript). 7504781Snate@binkert.orgexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 7513546Sgblack@eecs.umich.edu 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 7523546Sgblack@eecs.umich.edu 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 7533546Sgblack@eecs.umich.edu 7544781Snate@binkert.org################################################### 7553546Sgblack@eecs.umich.edu# 7563546Sgblack@eecs.umich.edu# Define a SCons builder for configuration flag headers. 7573546Sgblack@eecs.umich.edu# 7583546Sgblack@eecs.umich.edu################################################### 7593546Sgblack@eecs.umich.edu 7603546Sgblack@eecs.umich.edu# This function generates a config header file that #defines the 7613546Sgblack@eecs.umich.edu# variable symbol to the current variable setting (0 or 1). The source 7623546Sgblack@eecs.umich.edu# operands are the name of the variable and a Value node containing the 7633546Sgblack@eecs.umich.edu# value of the variable. 7643546Sgblack@eecs.umich.edudef build_config_file(target, source, env): 7654202Sbinkertn@umich.edu (variable, value) = [s.get_contents() for s in source] 7663546Sgblack@eecs.umich.edu f = file(str(target[0]), 'w') 7673546Sgblack@eecs.umich.edu print >> f, '#define', variable, value 7683546Sgblack@eecs.umich.edu f.close() 769955SN/A return None 770955SN/A 771955SN/A# Generate the message to be printed when building the config file. 772955SN/Adef build_config_file_string(target, source, env): 7735863Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 7745863Snate@binkert.org return "Defining %s as %s in %s." % (variable, value, target[0]) 7755343Sstever@gmail.com 7765343Sstever@gmail.com# Combine the two functions into a scons Action object. 7776121Snate@binkert.orgconfig_action = Action(build_config_file, build_config_file_string) 7785863Snate@binkert.org 7794773Snate@binkert.org# The emitter munges the source & target node lists to reflect what 7805863Snate@binkert.org# we're really doing. 7812632Sstever@eecs.umich.edudef config_emitter(target, source, env): 7825863Snate@binkert.org # extract variable name from Builder arg 7832023SN/A variable = str(target[0]) 7845863Snate@binkert.org # True target is config header file 7855863Snate@binkert.org target = joinpath('config', variable.lower() + '.hh') 7865863Snate@binkert.org val = env[variable] 7875863Snate@binkert.org if isinstance(val, bool): 7885863Snate@binkert.org # Force value to 0/1 7895863Snate@binkert.org val = int(val) 7905863Snate@binkert.org elif isinstance(val, str): 7915863Snate@binkert.org val = '"' + val + '"' 7925863Snate@binkert.org 7932632Sstever@eecs.umich.edu # Sources are variable name & value (packaged in SCons Value nodes) 7945863Snate@binkert.org return ([target], [Value(variable), Value(val)]) 7952023SN/A 7962632Sstever@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 7975863Snate@binkert.org 7985342Sstever@gmail.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 7995863Snate@binkert.org 8002632Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root. 8015863Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 8025863Snate@binkert.org variant_dir = joinpath(build_root, 'libelf')) 8032632Sstever@eecs.umich.edu 8045863Snate@binkert.org# gzstream build is shared across all configs in the build root. 8055863Snate@binkert.orgmain.SConscript('ext/gzstream/SConscript', 8065863Snate@binkert.org variant_dir = joinpath(build_root, 'gzstream')) 8075863Snate@binkert.org 8085863Snate@binkert.org################################################### 8095863Snate@binkert.org# 8102632Sstever@eecs.umich.edu# This function is used to set up a directory with switching headers 8115863Snate@binkert.org# 8125863Snate@binkert.org################################################### 8132632Sstever@eecs.umich.edu 8141888SN/Amain['ALL_ISA_LIST'] = all_isa_list 8155863Snate@binkert.orgdef make_switching_dir(dname, switch_headers, env): 8165863Snate@binkert.org # Generate the header. target[0] is the full path of the output 8175863Snate@binkert.org # header to generate. 'source' is a dummy variable, since we get the 8181858SN/A # list of ISAs from env['ALL_ISA_LIST']. 8195863Snate@binkert.org def gen_switch_hdr(target, source, env): 8205863Snate@binkert.org fname = str(target[0]) 8215863Snate@binkert.org f = open(fname, 'w') 8225863Snate@binkert.org isa = env['TARGET_ISA'].lower() 8232598SN/A print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 8245863Snate@binkert.org f.close() 8251858SN/A 8261858SN/A # Build SCons Action object. 'varlist' specifies env vars that this 8271858SN/A # action depends on; when env['ALL_ISA_LIST'] changes these actions 8285863Snate@binkert.org # should get re-executed. 8291858SN/A switch_hdr_action = MakeAction(gen_switch_hdr, 8301858SN/A " [GENERATE] $STRIP_TARGET", varlist=['ALL_ISA_LIST']) 8311858SN/A 8325863Snate@binkert.org # Instantiate actions for each header 8331871SN/A for hdr in switch_headers: 8341858SN/A env.Command(hdr, [], switch_hdr_action) 8351858SN/AExport('make_switching_dir') 8361858SN/A 8371858SN/A################################################### 8381858SN/A# 8391858SN/A# Define build environments for selected configurations. 8401858SN/A# 8415863Snate@binkert.org################################################### 8421858SN/A 8431858SN/Afor variant_path in variant_paths: 8445863Snate@binkert.org print "Building in", variant_path 8451859SN/A 8461859SN/A # Make a copy of the build-root environment to use for this config. 8471869SN/A env = main.Clone() 8485863Snate@binkert.org env['BUILDDIR'] = variant_path 8495863Snate@binkert.org 8501869SN/A # variant_dir is the tail component of build path, and is used to 8511965SN/A # determine the build parameters (e.g., 'ALPHA_SE') 8521965SN/A (build_root, variant_dir) = splitpath(variant_path) 8531965SN/A 8542761Sstever@eecs.umich.edu # Set env variables according to the build directory config. 8555863Snate@binkert.org sticky_vars.files = [] 8561869SN/A # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 8575863Snate@binkert.org # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 8582667Sstever@eecs.umich.edu # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 8591869SN/A current_vars_file = joinpath(build_root, 'variables', variant_dir) 8601869SN/A if isfile(current_vars_file): 8612929Sktlim@umich.edu sticky_vars.files.append(current_vars_file) 8622929Sktlim@umich.edu print "Using saved variables file %s" % current_vars_file 8635863Snate@binkert.org else: 8642929Sktlim@umich.edu # Build dir-specific variables file doesn't exist. 865955SN/A 8662598SN/A # Make sure the directory is there so we can create it later 867 opt_dir = dirname(current_vars_file) 868 if not isdir(opt_dir): 869 mkdir(opt_dir) 870 871 # Get default build variables from source tree. Variables are 872 # normally determined by name of $VARIANT_DIR, but can be 873 # overriden by 'default=' arg on command line. 874 default_vars_file = joinpath('build_opts', 875 ARGUMENTS.get('default', variant_dir)) 876 if isfile(default_vars_file): 877 sticky_vars.files.append(default_vars_file) 878 print "Variables file %s not found,\n using defaults in %s" \ 879 % (current_vars_file, default_vars_file) 880 else: 881 print "Error: cannot find variables file %s or %s" \ 882 % (current_vars_file, default_vars_file) 883 Exit(1) 884 885 # Apply current variable settings to env 886 sticky_vars.Update(env) 887 888 help_text += "\nSticky variables for %s:\n" % variant_dir \ 889 + sticky_vars.GenerateHelpText(env) 890 891 # Process variable settings. 892 893 if not have_fenv and env['USE_FENV']: 894 print "Warning: <fenv.h> not available; " \ 895 "forcing USE_FENV to False in", variant_dir + "." 896 env['USE_FENV'] = False 897 898 if not env['USE_FENV']: 899 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 900 print " FP results may deviate slightly from other platforms." 901 902 if env['EFENCE']: 903 env.Append(LIBS=['efence']) 904 905 if env['USE_MYSQL']: 906 if not have_mysql: 907 print "Warning: MySQL not available; " \ 908 "forcing USE_MYSQL to False in", variant_dir + "." 909 env['USE_MYSQL'] = False 910 else: 911 print "Compiling in", variant_dir, "with MySQL support." 912 env.ParseConfig(mysql_config_libs) 913 env.ParseConfig(mysql_config_include) 914 915 # Save sticky variable settings back to current variables file 916 sticky_vars.Save(current_vars_file, env) 917 918 if env['USE_SSE2']: 919 env.Append(CCFLAGS=['-msse2']) 920 921 # The src/SConscript file sets up the build rules in 'env' according 922 # to the configured variables. It returns a list of environments, 923 # one for each variant build (debug, opt, etc.) 924 envList = SConscript('src/SConscript', variant_dir = variant_path, 925 exports = 'env') 926 927 # Set up the regression tests for each build. 928 for e in envList: 929 SConscript('tests/SConscript', 930 variant_dir = joinpath(variant_path, 'tests', e.Label), 931 exports = { 'env' : e }, duplicate = False) 932 933Help(help_text) 934