SConstruct revision 8297
1955SN/A# -*- mode:python -*- 2955SN/A 35871Snate@binkert.org# Copyright (c) 2011 Advanced Micro Devices, Inc. 41762SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 5955SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 6955SN/A# All rights reserved. 7955SN/A# 8955SN/A# Redistribution and use in source and binary forms, with or without 9955SN/A# modification, are permitted provided that the following conditions are 10955SN/A# met: redistributions of source code must retain the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer; 12955SN/A# redistributions in binary form must reproduce the above copyright 13955SN/A# notice, this list of conditions and the following disclaimer in the 14955SN/A# documentation and/or other materials provided with the distribution; 15955SN/A# neither the name of the copyright holders nor the names of its 16955SN/A# contributors may be used to endorse or promote products derived from 17955SN/A# this software without specific prior written permission. 18955SN/A# 19955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 292665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 302665Ssaidi@eecs.umich.edu# 315863Snate@binkert.org# Authors: Steve Reinhardt 32955SN/A# Nathan Binkert 33955SN/A 34955SN/A################################################### 35955SN/A# 36955SN/A# SCons top-level build description (SConstruct) file. 372632Sstever@eecs.umich.edu# 382632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 392632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 402632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 41955SN/A# the optimized full-system version). 422632Sstever@eecs.umich.edu# 432632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 442761Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 452632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 462632Sstever@eecs.umich.edu# built for the same host system. 472632Sstever@eecs.umich.edu# 482761Sstever@eecs.umich.edu# Examples: 492761Sstever@eecs.umich.edu# 502761Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 512632Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 522632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 532761Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 542761Sstever@eecs.umich.edu# 552761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 562761Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 572761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 582632Sstever@eecs.umich.edu# file. 592632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 602632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 612632Sstever@eecs.umich.edu# 622632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 632632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 642632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 65955SN/A# options as well. 66955SN/A# 67955SN/A################################################### 685863Snate@binkert.org 695863Snate@binkert.org# Check for recent-enough Python and SCons versions. 705863Snate@binkert.orgtry: 715863Snate@binkert.org # Really old versions of scons only take two options for the 725863Snate@binkert.org # function, so check once without the revision and once with the 735863Snate@binkert.org # revision, the first instance will fail for stuff other than 745863Snate@binkert.org # 0.98, and the second will fail for 0.98.0 755863Snate@binkert.org EnsureSConsVersion(0, 98) 765863Snate@binkert.org EnsureSConsVersion(0, 98, 1) 775863Snate@binkert.orgexcept SystemExit, e: 785863Snate@binkert.org print """ 795863Snate@binkert.orgFor more details, see: 805863Snate@binkert.org http://m5sim.org/wiki/index.php/Compiling_M5 815863Snate@binkert.org""" 825863Snate@binkert.org raise 835863Snate@binkert.org 845863Snate@binkert.org# We ensure the python version early because we have stuff that 855863Snate@binkert.org# requires python 2.4 865863Snate@binkert.orgtry: 875863Snate@binkert.org EnsurePythonVersion(2, 4) 885863Snate@binkert.orgexcept SystemExit, e: 895863Snate@binkert.org print """ 905863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 915863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 925863Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter 935863Snate@binkert.orgon the scons script. 945863Snate@binkert.org 955863Snate@binkert.orgFor more details, see: 965863Snate@binkert.org http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 975863Snate@binkert.org""" 985863Snate@binkert.org raise 99955SN/A 1005396Ssaidi@eecs.umich.edu# Global Python includes 1015863Snate@binkert.orgimport os 1025863Snate@binkert.orgimport re 1034202Sbinkertn@umich.eduimport subprocess 1045863Snate@binkert.orgimport sys 1055863Snate@binkert.org 1065863Snate@binkert.orgfrom os import mkdir, environ 1075863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 108955SN/Afrom os.path import exists, isdir, isfile 1095273Sstever@gmail.comfrom os.path import join as joinpath, split as splitpath 1105871Snate@binkert.org 1115273Sstever@gmail.com# SCons includes 1125871Snate@binkert.orgimport SCons 1135863Snate@binkert.orgimport SCons.Node 1145863Snate@binkert.org 1155863Snate@binkert.orgextra_python_paths = [ 1165871Snate@binkert.org Dir('src/python').srcnode().abspath, # M5 includes 1175872Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1185872Snate@binkert.org ] 1195872Snate@binkert.org 1205871Snate@binkert.orgsys.path[1:1] = extra_python_paths 1215871Snate@binkert.org 1225871Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1235871Snate@binkert.org 1245871Snate@binkert.orghelp_texts = { 1255871Snate@binkert.org "options" : "", 1265871Snate@binkert.org "global_vars" : "", 1275871Snate@binkert.org "local_vars" : "" 1285871Snate@binkert.org} 1295871Snate@binkert.org 1305871Snate@binkert.orgExport("help_texts") 1315871Snate@binkert.org 1325871Snate@binkert.orgdef AddM5Option(*args, **kwargs): 1335871Snate@binkert.org col_width = 30 1345863Snate@binkert.org 1355227Ssaidi@eecs.umich.edu help = " " + ", ".join(args) 1365396Ssaidi@eecs.umich.edu if "help" in kwargs: 1375396Ssaidi@eecs.umich.edu length = len(help) 1385396Ssaidi@eecs.umich.edu if length >= col_width: 1395396Ssaidi@eecs.umich.edu help += "\n" + " " * col_width 1405396Ssaidi@eecs.umich.edu else: 1415396Ssaidi@eecs.umich.edu help += " " * (col_width - length) 1425396Ssaidi@eecs.umich.edu help += kwargs["help"] 1435396Ssaidi@eecs.umich.edu help_texts["options"] += help + "\n" 1445588Ssaidi@eecs.umich.edu 1455396Ssaidi@eecs.umich.edu AddOption(*args, **kwargs) 1465396Ssaidi@eecs.umich.edu 1475396Ssaidi@eecs.umich.eduAddM5Option('--colors', dest='use_colors', action='store_true', 1485396Ssaidi@eecs.umich.edu help="Add color to abbreviated scons output") 1495396Ssaidi@eecs.umich.eduAddM5Option('--no-colors', dest='use_colors', action='store_false', 1505396Ssaidi@eecs.umich.edu help="Don't add color to abbreviated scons output") 1515396Ssaidi@eecs.umich.eduAddM5Option('--default', dest='default', type='string', action='store', 1525396Ssaidi@eecs.umich.edu help='Override which build_opts file to use for defaults') 1535396Ssaidi@eecs.umich.eduAddM5Option('--ignore-style', dest='ignore_style', action='store_true', 1545396Ssaidi@eecs.umich.edu help='Disable style checking hooks') 1555396Ssaidi@eecs.umich.eduAddM5Option('--update-ref', dest='update_ref', action='store_true', 1565396Ssaidi@eecs.umich.edu help='Update test reference outputs') 1575396Ssaidi@eecs.umich.eduAddM5Option('--verbose', dest='verbose', action='store_true', 1585396Ssaidi@eecs.umich.edu help='Print full tool command lines') 1595871Snate@binkert.org 1605871Snate@binkert.orguse_colors = GetOption('use_colors') 1615871Snate@binkert.orgif use_colors: 1625871Snate@binkert.org from m5.util.terminal import termcap 1635871Snate@binkert.orgelif use_colors is None: 1645871Snate@binkert.org # option unspecified; default behavior is to use colors iff isatty 165955SN/A from m5.util.terminal import tty_termcap as termcap 1665871Snate@binkert.orgelse: 1675871Snate@binkert.org from m5.util.terminal import no_termcap as termcap 1685871Snate@binkert.org 1695871Snate@binkert.org######################################################################## 170955SN/A# 1715871Snate@binkert.org# Set up the main build environment. 1725871Snate@binkert.org# 1735871Snate@binkert.org######################################################################## 1741533SN/Ause_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1755871Snate@binkert.org 'PYTHONPATH', 'RANLIB' ]) 1765871Snate@binkert.org 1775863Snate@binkert.orguse_env = {} 1785871Snate@binkert.orgfor key,val in os.environ.iteritems(): 1795871Snate@binkert.org if key in use_vars or key.startswith("M5"): 1805871Snate@binkert.org use_env[key] = val 1815871Snate@binkert.org 1825871Snate@binkert.orgmain = Environment(ENV=use_env) 1835863Snate@binkert.orgmain.root = Dir(".") # The current directory (where this file lives). 1845871Snate@binkert.orgmain.srcdir = Dir("src") # The source directory 1855863Snate@binkert.org 1865871Snate@binkert.org# add useful python code PYTHONPATH so it can be used by subprocesses 1874678Snate@binkert.org# as well 1884678Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths) 1894678Snate@binkert.org 1904678Snate@binkert.org######################################################################## 1914678Snate@binkert.org# 1924678Snate@binkert.org# Mercurial Stuff. 1934678Snate@binkert.org# 1944678Snate@binkert.org# If the M5 directory is a mercurial repository, we should do some 1954678Snate@binkert.org# extra things. 1964678Snate@binkert.org# 1974678Snate@binkert.org######################################################################## 1984678Snate@binkert.org 1995871Snate@binkert.orghgdir = main.root.Dir(".hg") 2004678Snate@binkert.org 2015871Snate@binkert.orgmercurial_style_message = """ 2025871Snate@binkert.orgYou're missing the M5 style hook. 2035871Snate@binkert.orgPlease install the hook so we can ensure that all code fits a common style. 2045871Snate@binkert.org 2055871Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc 2065871Snate@binkert.orgor your personal .hgrc 2075871Snate@binkert.org---------------- 2085871Snate@binkert.org 2095871Snate@binkert.org[extensions] 2105871Snate@binkert.orgstyle = %s/util/style.py 2115871Snate@binkert.org 2125871Snate@binkert.org[hooks] 2135871Snate@binkert.orgpretxncommit.style = python:style.check_style 2145871Snate@binkert.orgpre-qrefresh.style = python:style.check_style 2155871Snate@binkert.org""" % (main.root) 2165871Snate@binkert.org 2174678Snate@binkert.orgmercurial_bin_not_found = """ 2185871Snate@binkert.orgMercurial binary cannot be found, unfortunately this means that we 2195871Snate@binkert.orgcannot easily determine the version of M5 that you are running and 2205871Snate@binkert.orgthis makes error messages more difficult to collect. Please consider 2215871Snate@binkert.orginstalling mercurial if you choose to post an error message 2225871Snate@binkert.org""" 2235871Snate@binkert.org 2245871Snate@binkert.orgmercurial_lib_not_found = """ 2255871Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook 2265871Snate@binkert.orgIf you are actually a M5 developer, please fix this and 2275871Snate@binkert.orgrun the style hook. It is important. 2285871Snate@binkert.org""" 2295871Snate@binkert.org 2305871Snate@binkert.orgif hgdir.exists(): 2314678Snate@binkert.org # Ensure that the style hook is in place. 2325871Snate@binkert.org try: 2334678Snate@binkert.org ui = None 2345871Snate@binkert.org if not GetOption('ignore_style'): 2355871Snate@binkert.org from mercurial import ui 2365871Snate@binkert.org ui = ui.ui() 2375871Snate@binkert.org except ImportError: 2385871Snate@binkert.org print mercurial_lib_not_found 2395871Snate@binkert.org 2405871Snate@binkert.org if ui is not None: 2415871Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2425871Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) 2435863Snate@binkert.org 244955SN/A if not style_hook: 245955SN/A print mercurial_style_message 2462632Sstever@eecs.umich.edu sys.exit(1) 2472632Sstever@eecs.umich.eduelse: 248955SN/A print ".hg directory not found" 249955SN/A 250955SN/A################################################### 251955SN/A# 2525863Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 253955SN/A# the target(s). 2542632Sstever@eecs.umich.edu# 2552632Sstever@eecs.umich.edu################################################### 2562632Sstever@eecs.umich.edu 2572632Sstever@eecs.umich.edu# Find default configuration & binary. 2582632Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2592632Sstever@eecs.umich.edu 2602632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 2612632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 2622632Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2632632Sstever@eecs.umich.edu if l[i] == elt: 2642632Sstever@eecs.umich.edu return i 2652632Sstever@eecs.umich.edu raise ValueError, "element not found" 2662632Sstever@eecs.umich.edu 2673718Sstever@eecs.umich.edu# Take a list of paths (or SCons Nodes) and return a list with all 2683718Sstever@eecs.umich.edu# paths made absolute and ~-expanded. Paths will be interpreted 2693718Sstever@eecs.umich.edu# relative to the launch directory unless a different root is provided 2703718Sstever@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 2713718Sstever@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 2725863Snate@binkert.org for p in path_list] 2735863Snate@binkert.org 2743718Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2753718Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2765863Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2775863Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 2783718Sstever@eecs.umich.edu# follow 'build' in the build path. 2793718Sstever@eecs.umich.edu 2802634Sstever@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 2812634Sstever@eecs.umich.edu# in place rather than reassign the symbol to a new list, which 2825863Snate@binkert.org# doesn't work (obviously!). 2832638Sstever@eecs.umich.eduBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 2842632Sstever@eecs.umich.edu 2852632Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 2862632Sstever@eecs.umich.edu# collected targets reference. 2872632Sstever@eecs.umich.eduvariant_paths = [] 2882632Sstever@eecs.umich.edubuild_root = None 2892632Sstever@eecs.umich.edufor t in BUILD_TARGETS: 2901858SN/A path_dirs = t.split('/') 2913716Sstever@eecs.umich.edu try: 2922638Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 2932638Sstever@eecs.umich.edu except: 2942638Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 2952638Sstever@eecs.umich.edu Exit(1) 2962638Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2972638Sstever@eecs.umich.edu if not build_root: 2982638Sstever@eecs.umich.edu build_root = this_build_root 2995863Snate@binkert.org else: 3005863Snate@binkert.org if this_build_root != build_root: 3015863Snate@binkert.org print "Error: build targets not under same build root\n"\ 302955SN/A " %s\n %s" % (build_root, this_build_root) 3035341Sstever@gmail.com Exit(1) 3045341Sstever@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 3055863Snate@binkert.org if variant_path not in variant_paths: 3065341Sstever@gmail.com variant_paths.append(variant_path) 3074494Ssaidi@eecs.umich.edu 3084494Ssaidi@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 3095863Snate@binkert.orgif not isdir(build_root): 3101105SN/A mkdir(build_root) 3112667Sstever@eecs.umich.edumain['BUILDROOT'] = build_root 3122667Sstever@eecs.umich.edu 3132667Sstever@eecs.umich.eduExport('main') 3142667Sstever@eecs.umich.edu 3152667Sstever@eecs.umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 3162667Sstever@eecs.umich.edu 3175341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up 3185863Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 3195341Sstever@gmail.com# file to file~ then copies to file, breaking the link. Symbolic 3205341Sstever@gmail.com# (soft) links work better. 3215341Sstever@gmail.commain.SetOption('duplicate', 'soft-copy') 3225863Snate@binkert.org 3235341Sstever@gmail.com# 3245341Sstever@gmail.com# Set up global sticky variables... these are common to an entire build 3255341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE) 3265863Snate@binkert.org# 3275341Sstever@gmail.com 3285341Sstever@gmail.comglobal_vars_file = joinpath(build_root, 'variables.global') 3295341Sstever@gmail.com 3305341Sstever@gmail.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3315341Sstever@gmail.com 3325341Sstever@gmail.comglobal_vars.AddVariables( 3335341Sstever@gmail.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 3345341Sstever@gmail.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3355341Sstever@gmail.com ('BATCH', 'Use batch pool for build and tests', False), 3365341Sstever@gmail.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3375863Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3385341Sstever@gmail.com ('EXTRAS', 'Add extra directories to the compilation', '') 3395863Snate@binkert.org ) 3405341Sstever@gmail.com 3415863Snate@binkert.org# Update main environment with values from ARGUMENTS & global_vars_file 3425863Snate@binkert.orgglobal_vars.Update(main) 3435863Snate@binkert.orghelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3445397Ssaidi@eecs.umich.edu 3455397Ssaidi@eecs.umich.edu# Save sticky variable settings back to current variables file 3465341Sstever@gmail.comglobal_vars.Save(global_vars_file, main) 3475341Sstever@gmail.com 3485341Sstever@gmail.com# Parse EXTRAS variable to build list of all directories where we're 3495341Sstever@gmail.com# look for sources etc. This list is exported as extras_dir_list. 3505341Sstever@gmail.combase_dir = main.srcdir.abspath 3515341Sstever@gmail.comif main['EXTRAS']: 3525341Sstever@gmail.com extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3535341Sstever@gmail.comelse: 3545863Snate@binkert.org extras_dir_list = [] 3555341Sstever@gmail.com 3565341Sstever@gmail.comExport('base_dir') 3575863Snate@binkert.orgExport('extras_dir_list') 3585341Sstever@gmail.com 3595863Snate@binkert.org# the ext directory should be on the #includes path 3605863Snate@binkert.orgmain.Append(CPPPATH=[Dir('ext')]) 3615341Sstever@gmail.com 3625863Snate@binkert.orgdef strip_build_path(path, env): 3635863Snate@binkert.org path = str(path) 3645341Sstever@gmail.com variant_base = env['BUILDROOT'] + os.path.sep 3655863Snate@binkert.org if path.startswith(variant_base): 3665341Sstever@gmail.com path = path[len(variant_base):] 3675871Snate@binkert.org elif path.startswith('build/'): 3685341Sstever@gmail.com path = path[6:] 3695742Snate@binkert.org return path 3705742Snate@binkert.org 3715742Snate@binkert.org# Generate a string of the form: 3725341Sstever@gmail.com# common/path/prefix/src1, src2 -> tgt1, tgt2 3735742Snate@binkert.org# to print while building. 3745742Snate@binkert.orgclass Transform(object): 3755341Sstever@gmail.com # all specific color settings should be here and nowhere else 3762632Sstever@eecs.umich.edu tool_color = termcap.Normal 3775199Sstever@gmail.com pfx_color = termcap.Yellow 3785871Snate@binkert.org srcs_color = termcap.Yellow + termcap.Bold 3795871Snate@binkert.org arrow_color = termcap.Blue + termcap.Bold 3805871Snate@binkert.org tgts_color = termcap.Yellow + termcap.Bold 3815871Snate@binkert.org 3825871Snate@binkert.org def __init__(self, tool, max_sources=99): 3835871Snate@binkert.org self.format = self.tool_color + (" [%8s] " % tool) \ 3845871Snate@binkert.org + self.pfx_color + "%s" \ 3853942Ssaidi@eecs.umich.edu + self.srcs_color + "%s" \ 3863940Ssaidi@eecs.umich.edu + self.arrow_color + " -> " \ 3873918Ssaidi@eecs.umich.edu + self.tgts_color + "%s" \ 3883918Ssaidi@eecs.umich.edu + termcap.Normal 3891858SN/A self.max_sources = max_sources 3903918Ssaidi@eecs.umich.edu 3913918Ssaidi@eecs.umich.edu def __call__(self, target, source, env, for_signature=None): 3923918Ssaidi@eecs.umich.edu # truncate source list according to max_sources param 3933918Ssaidi@eecs.umich.edu source = source[0:self.max_sources] 3945571Snate@binkert.org def strip(f): 3953940Ssaidi@eecs.umich.edu return strip_build_path(str(f), env) 3963940Ssaidi@eecs.umich.edu if len(source) > 0: 3973918Ssaidi@eecs.umich.edu srcs = map(strip, source) 3983918Ssaidi@eecs.umich.edu else: 3993918Ssaidi@eecs.umich.edu srcs = [''] 4003918Ssaidi@eecs.umich.edu tgts = map(strip, target) 4013918Ssaidi@eecs.umich.edu # surprisingly, os.path.commonprefix is a dumb char-by-char string 4023918Ssaidi@eecs.umich.edu # operation that has nothing to do with paths. 4035871Snate@binkert.org com_pfx = os.path.commonprefix(srcs + tgts) 4043918Ssaidi@eecs.umich.edu com_pfx_len = len(com_pfx) 4053918Ssaidi@eecs.umich.edu if com_pfx: 4063940Ssaidi@eecs.umich.edu # do some cleanup and sanity checking on common prefix 4073918Ssaidi@eecs.umich.edu if com_pfx[-1] == ".": 4083918Ssaidi@eecs.umich.edu # prefix matches all but file extension: ok 4095397Ssaidi@eecs.umich.edu # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4105397Ssaidi@eecs.umich.edu com_pfx = com_pfx[0:-1] 4115397Ssaidi@eecs.umich.edu elif com_pfx[-1] == "/": 4125708Ssaidi@eecs.umich.edu # common prefix is directory path: OK 4135708Ssaidi@eecs.umich.edu pass 4145708Ssaidi@eecs.umich.edu else: 4155708Ssaidi@eecs.umich.edu src0_len = len(srcs[0]) 4165708Ssaidi@eecs.umich.edu tgt0_len = len(tgts[0]) 4175397Ssaidi@eecs.umich.edu if src0_len == com_pfx_len: 4181851SN/A # source is a substring of target, OK 4191851SN/A pass 4201858SN/A elif tgt0_len == com_pfx_len: 4215200Sstever@gmail.com # target is a substring of source, need to back up to 422955SN/A # avoid empty string on RHS of arrow 4233053Sstever@eecs.umich.edu sep_idx = com_pfx.rfind(".") 4243053Sstever@eecs.umich.edu if sep_idx != -1: 4253053Sstever@eecs.umich.edu com_pfx = com_pfx[0:sep_idx] 4263053Sstever@eecs.umich.edu else: 4273053Sstever@eecs.umich.edu com_pfx = '' 4283053Sstever@eecs.umich.edu elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4293053Sstever@eecs.umich.edu # still splitting at file extension: ok 4305871Snate@binkert.org pass 4313053Sstever@eecs.umich.edu else: 4324742Sstever@eecs.umich.edu # probably a fluke; ignore it 4334742Sstever@eecs.umich.edu com_pfx = '' 4343053Sstever@eecs.umich.edu # recalculate length in case com_pfx was modified 4353053Sstever@eecs.umich.edu com_pfx_len = len(com_pfx) 4363053Sstever@eecs.umich.edu def fmt(files): 4373053Sstever@eecs.umich.edu f = map(lambda s: s[com_pfx_len:], files) 4383053Sstever@eecs.umich.edu return ', '.join(f) 4393053Sstever@eecs.umich.edu return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4403053Sstever@eecs.umich.edu 4413053Sstever@eecs.umich.eduExport('Transform') 4423053Sstever@eecs.umich.edu 4432667Sstever@eecs.umich.edu 4444554Sbinkertn@umich.eduif GetOption('verbose'): 4454554Sbinkertn@umich.edu def MakeAction(action, string, *args, **kwargs): 4462667Sstever@eecs.umich.edu return Action(action, *args, **kwargs) 4474554Sbinkertn@umich.eduelse: 4484554Sbinkertn@umich.edu MakeAction = Action 4494554Sbinkertn@umich.edu main['CCCOMSTR'] = Transform("CC") 4504554Sbinkertn@umich.edu main['CXXCOMSTR'] = Transform("CXX") 4514554Sbinkertn@umich.edu main['ASCOMSTR'] = Transform("AS") 4524554Sbinkertn@umich.edu main['SWIGCOMSTR'] = Transform("SWIG") 4534554Sbinkertn@umich.edu main['ARCOMSTR'] = Transform("AR", 0) 4544781Snate@binkert.org main['LINKCOMSTR'] = Transform("LINK", 0) 4554554Sbinkertn@umich.edu main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4564554Sbinkertn@umich.edu main['M4COMSTR'] = Transform("M4") 4572667Sstever@eecs.umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 4584554Sbinkertn@umich.edu main['SHCXXCOMSTR'] = Transform("SHCXX") 4594554Sbinkertn@umich.eduExport('MakeAction') 4604554Sbinkertn@umich.edu 4614554Sbinkertn@umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4622667Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 4634554Sbinkertn@umich.edu 4642667Sstever@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4654554Sbinkertn@umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4664554Sbinkertn@umich.edumain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4672667Sstever@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 4685522Snate@binkert.org print 'Error: How can we have two at the same time?' 4695522Snate@binkert.org Exit(1) 4705522Snate@binkert.org 4715522Snate@binkert.org# Set up default C++ compiler flags 4725522Snate@binkert.orgif main['GCC']: 4735522Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 4745522Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 4755522Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4765522Snate@binkert.org main.Append(CXXFLAGS=['-Wno-deprecated']) 4775522Snate@binkert.org # Read the GCC version to check for versions with bugs 4785522Snate@binkert.org # Note CCVERSION doesn't work here because it is run with the CC 4795522Snate@binkert.org # before we override it from the command line 4805522Snate@binkert.org gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4815522Snate@binkert.org if not compareVersions(gcc_version, '4.4.1') or \ 4825522Snate@binkert.org not compareVersions(gcc_version, '4.4.2'): 4835522Snate@binkert.org print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 4845522Snate@binkert.org main.Append(CCFLAGS=['-fno-tree-vectorize']) 4855522Snate@binkert.orgelif main['ICC']: 4865522Snate@binkert.org pass #Fix me... add warning flags once we clean up icc warnings 4875522Snate@binkert.orgelif main['SUNCC']: 4885522Snate@binkert.org main.Append(CCFLAGS=['-Qoption ccfe']) 4895522Snate@binkert.org main.Append(CCFLAGS=['-features=gcc']) 4905522Snate@binkert.org main.Append(CCFLAGS=['-features=extensions']) 4915522Snate@binkert.org main.Append(CCFLAGS=['-library=stlport4']) 4925522Snate@binkert.org main.Append(CCFLAGS=['-xar']) 4935522Snate@binkert.org #main.Append(CCFLAGS=['-instances=semiexplicit']) 4942638Sstever@eecs.umich.eduelse: 4952638Sstever@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 4962638Sstever@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 4973716Sstever@eecs.umich.edu Exit(1) 4985522Snate@binkert.org 4995522Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby) 5005522Snate@binkert.orgmain['YACCFLAGS'] = '-d' 5015522Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh' 5025522Snate@binkert.org 5035522Snate@binkert.org# Do this after we save setting back, or else we'll tack on an 5041858SN/A# extra 'qdo' every time we run scons. 5055227Ssaidi@eecs.umich.eduif main['BATCH']: 5065227Ssaidi@eecs.umich.edu main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5075227Ssaidi@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5085227Ssaidi@eecs.umich.edu main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5095227Ssaidi@eecs.umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5105863Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5115227Ssaidi@eecs.umich.edu 5125227Ssaidi@eecs.umich.eduif sys.platform == 'cygwin': 5135227Ssaidi@eecs.umich.edu # cygwin has some header file issues... 5145227Ssaidi@eecs.umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 5155227Ssaidi@eecs.umich.edu 5165227Ssaidi@eecs.umich.edu# Check for SWIG 5175227Ssaidi@eecs.umich.eduif not main.has_key('SWIG'): 5185204Sstever@gmail.com print 'Error: SWIG utility not found.' 5195204Sstever@gmail.com print ' Please install (see http://www.swig.org) and retry.' 5205204Sstever@gmail.com Exit(1) 5215204Sstever@gmail.com 5225204Sstever@gmail.com# Check for appropriate SWIG version 5235204Sstever@gmail.comswig_version = readCommand(('swig', '-version'), exception='').split() 5245204Sstever@gmail.com# First 3 words should be "SWIG Version x.y.z" 5255204Sstever@gmail.comif len(swig_version) < 3 or \ 5265204Sstever@gmail.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5275204Sstever@gmail.com print 'Error determining SWIG version.' 5285204Sstever@gmail.com Exit(1) 5295204Sstever@gmail.com 5305204Sstever@gmail.commin_swig_version = '1.3.28' 5315204Sstever@gmail.comif compareVersions(swig_version[2], min_swig_version) < 0: 5325204Sstever@gmail.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 5335204Sstever@gmail.com print ' Installed version:', swig_version[2] 5345204Sstever@gmail.com Exit(1) 5355204Sstever@gmail.com 5365204Sstever@gmail.com# Set up SWIG flags & scanner 5373118Sstever@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5383118Sstever@eecs.umich.edumain.Append(SWIGFLAGS=swig_flags) 5393118Sstever@eecs.umich.edu 5403118Sstever@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 5413118Sstever@eecs.umich.edu# stuff for some reason 5425863Snate@binkert.orgscanners = [] 5433118Sstever@eecs.umich.edufor scanner in main['SCANNERS']: 5445863Snate@binkert.org skeys = scanner.skeys 5453118Sstever@eecs.umich.edu if skeys == '.i': 5465863Snate@binkert.org continue 5475863Snate@binkert.org 5485863Snate@binkert.org if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5495863Snate@binkert.org continue 5505863Snate@binkert.org 5515863Snate@binkert.org scanners.append(scanner) 5525863Snate@binkert.org 5535863Snate@binkert.org# add the new swig scanner that we like better 5545863Snate@binkert.orgfrom SCons.Scanner import ClassicCPP as CPPScanner 5555863Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 5565863Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 5575863Snate@binkert.org 5585863Snate@binkert.org# replace the scanners list that has what we want 5595863Snate@binkert.orgmain['SCANNERS'] = scanners 5605863Snate@binkert.org 5615863Snate@binkert.org# Add a custom Check function to the Configure context so that we can 5625863Snate@binkert.org# figure out if the compiler adds leading underscores to global 5635863Snate@binkert.org# variables. This is needed for the autogenerated asm files that we 5645863Snate@binkert.org# use for embedding the python code. 5655863Snate@binkert.orgdef CheckLeading(context): 5665863Snate@binkert.org context.Message("Checking for leading underscore in global variables...") 5675863Snate@binkert.org # 1) Define a global variable called x from asm so the C compiler 5685863Snate@binkert.org # won't change the symbol at all. 5695863Snate@binkert.org # 2) Declare that variable. 5705863Snate@binkert.org # 3) Use the variable 5713118Sstever@eecs.umich.edu # 5725863Snate@binkert.org # If the compiler prepends an underscore, this will successfully 5733118Sstever@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 5743118Sstever@eecs.umich.edu # was defined by the asm statement. If the compiler does not 5755863Snate@binkert.org # prepend an underscore, this will not successfully link because 5765863Snate@binkert.org # '_x' will have been defined by assembly, while the C portion of 5775863Snate@binkert.org # the code will be trying to use 'x' 5785863Snate@binkert.org ret = context.TryLink(''' 5795863Snate@binkert.org asm(".globl _x; _x: .byte 0"); 5805863Snate@binkert.org extern int x; 5813118Sstever@eecs.umich.edu int main() { return x; } 5823483Ssaidi@eecs.umich.edu ''', extension=".c") 5833494Ssaidi@eecs.umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 5843494Ssaidi@eecs.umich.edu context.Result(ret) 5853483Ssaidi@eecs.umich.edu return ret 5863483Ssaidi@eecs.umich.edu 5873483Ssaidi@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 5883053Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 5893053Sstever@eecs.umich.educonf = Configure(main, 5903918Ssaidi@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 5913053Sstever@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 5923053Sstever@eecs.umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 5933053Sstever@eecs.umich.edu 5943053Sstever@eecs.umich.edu# Check for leading underscores. Don't really need to worry either 5953053Sstever@eecs.umich.edu# way so don't need to check the return code. 5961858SN/Aconf.CheckLeading() 5971858SN/A 5981858SN/A# Check if we should compile a 64 bit binary on Mac OS X/Darwin 5991858SN/Atry: 6001858SN/A import platform 6011858SN/A uname = platform.uname() 6025863Snate@binkert.org if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6035863Snate@binkert.org if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6041859SN/A main.Append(CCFLAGS=['-arch', 'x86_64']) 6055863Snate@binkert.org main.Append(CFLAGS=['-arch', 'x86_64']) 6061858SN/A main.Append(LINKFLAGS=['-arch', 'x86_64']) 6075863Snate@binkert.org main.Append(ASFLAGS=['-arch', 'x86_64']) 6081858SN/Aexcept: 6091859SN/A pass 6101859SN/A 6115863Snate@binkert.org# Recent versions of scons substitute a "Null" object for Configure() 6123053Sstever@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 6133053Sstever@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 6143053Sstever@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 6153053Sstever@eecs.umich.edu# more optimistic null object that returns True instead. 6161859SN/Aif not conf: 6171859SN/A def NullCheck(*args, **kwargs): 6181859SN/A return True 6191859SN/A 6201859SN/A class NullConf: 6211859SN/A def __init__(self, env): 6221859SN/A self.env = env 6231859SN/A def Finish(self): 6241862SN/A return self.env 6251859SN/A def __getattr__(self, mname): 6261859SN/A return NullCheck 6271859SN/A 6285863Snate@binkert.org conf = NullConf(main) 6295863Snate@binkert.org 6305863Snate@binkert.org# Find Python include and library directories for embedding the 6315863Snate@binkert.org# interpreter. For consistency, we will use the same Python 6321858SN/A# installation used to run scons (and thus this script). If you want 6331858SN/A# to link in an alternate version, see above for instructions on how 6345863Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 6355863Snate@binkert.orgfrom distutils import sysconfig 6365863Snate@binkert.org 6375863Snate@binkert.orgpy_getvar = sysconfig.get_config_var 6385863Snate@binkert.org 6395871Snate@binkert.orgpy_debug = getattr(sys, 'pydebug', False) 6405871Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6412139SN/A 6424202Sbinkertn@umich.edupy_general_include = sysconfig.get_python_inc() 6434202Sbinkertn@umich.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6442139SN/Apy_includes = [ py_general_include ] 6452155SN/Aif py_platform_include != py_general_include: 6464202Sbinkertn@umich.edu py_includes.append(py_platform_include) 6474202Sbinkertn@umich.edu 6484202Sbinkertn@umich.edupy_lib_path = [ py_getvar('LIBDIR') ] 6492155SN/A# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6505863Snate@binkert.org# shared library in prefix/lib/. 6511869SN/Aif not py_getvar('Py_ENABLE_SHARED'): 6521869SN/A py_lib_path.append(py_getvar('LIBPL')) 6535863Snate@binkert.org 6545863Snate@binkert.orgpy_libs = [] 6554202Sbinkertn@umich.edufor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 6565863Snate@binkert.org assert lib.startswith('-l') 6575863Snate@binkert.org lib = lib[2:] 6585863Snate@binkert.org if lib not in py_libs: 6594202Sbinkertn@umich.edu py_libs.append(lib) 6604202Sbinkertn@umich.edupy_libs.append(py_version) 6615863Snate@binkert.org 6625742Snate@binkert.orgmain.Append(CPPPATH=py_includes) 6635742Snate@binkert.orgmain.Append(LIBPATH=py_lib_path) 6645341Sstever@gmail.com 6655342Sstever@gmail.com# Cache build files in the supplied directory. 6665342Sstever@gmail.comif main['M5_BUILD_CACHE']: 6674202Sbinkertn@umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 6684202Sbinkertn@umich.edu CacheDir(main['M5_BUILD_CACHE']) 6694202Sbinkertn@umich.edu 6704202Sbinkertn@umich.edu 6714202Sbinkertn@umich.edu# verify that this stuff works 6725863Snate@binkert.orgif not conf.CheckHeader('Python.h', '<>'): 6735863Snate@binkert.org print "Error: can't find Python.h header in", py_includes 6745863Snate@binkert.org Exit(1) 6755863Snate@binkert.org 6765863Snate@binkert.orgfor lib in py_libs: 6775863Snate@binkert.org if not conf.CheckLib(lib): 6785863Snate@binkert.org print "Error: can't find library %s required by python" % lib 6795863Snate@binkert.org Exit(1) 6805863Snate@binkert.org 6815863Snate@binkert.org# On Solaris you need to use libsocket for socket ops 6825863Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6835863Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6845863Snate@binkert.org print "Can't find library with socket calls (e.g. accept())" 6855863Snate@binkert.org Exit(1) 6865863Snate@binkert.org 6875863Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 6885863Snate@binkert.org# added to the LIBS environment variable. 6895863Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 6905863Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 6915863Snate@binkert.org 'and/or zlib.h header file.' 6925952Ssaidi@eecs.umich.edu print ' Please install zlib and try again.' 6931869SN/A Exit(1) 6941858SN/A 6955863Snate@binkert.org# Check for librt. 6965863Snate@binkert.orghave_posix_clock = \ 6971869SN/A conf.CheckLibWithHeader(None, 'time.h', 'C', 6981858SN/A 'clock_nanosleep(0,0,NULL,NULL);') or \ 6995863Snate@binkert.org conf.CheckLibWithHeader('rt', 'time.h', 'C', 7005863Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') 7015863Snate@binkert.org 7025863Snate@binkert.orgif not have_posix_clock: 7035952Ssaidi@eecs.umich.edu print "Can't find library for POSIX clocks." 7041858SN/A 705955SN/A# Check for <fenv.h> (C99 FP environment control) 706955SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 7071869SN/Aif not have_fenv: 7081869SN/A print "Warning: Header file <fenv.h> not found." 7091869SN/A print " This host has no IEEE FP rounding mode control." 7101869SN/A 7111869SN/A###################################################################### 7125863Snate@binkert.org# 7135863Snate@binkert.org# Finish the configuration 7145863Snate@binkert.org# 7151869SN/Amain = conf.Finish() 7165863Snate@binkert.org 7171869SN/A###################################################################### 7185863Snate@binkert.org# 7191869SN/A# Collect all non-global variables 7201869SN/A# 7211869SN/A 7221869SN/A# Define the universe of supported ISAs 7231869SN/Aall_isa_list = [ ] 7245863Snate@binkert.orgExport('all_isa_list') 7255863Snate@binkert.org 7261869SN/Aclass CpuModel(object): 7271869SN/A '''The CpuModel class encapsulates everything the ISA parser needs to 7281869SN/A know about a particular CPU model.''' 7291869SN/A 7301869SN/A # Dict of available CPU model objects. Accessible as CpuModel.dict. 7311869SN/A dict = {} 7321869SN/A list = [] 7335863Snate@binkert.org defaults = [] 7345863Snate@binkert.org 7351869SN/A # Constructor. Automatically adds models to CpuModel.dict. 7365863Snate@binkert.org def __init__(self, name, filename, includes, strings, default=False): 7375863Snate@binkert.org self.name = name # name of model 7383356Sbinkertn@umich.edu self.filename = filename # filename for output exec code 7393356Sbinkertn@umich.edu self.includes = includes # include files needed in exec file 7403356Sbinkertn@umich.edu # The 'strings' dict holds all the per-CPU symbols we can 7413356Sbinkertn@umich.edu # substitute into templates etc. 7423356Sbinkertn@umich.edu self.strings = strings 7434781Snate@binkert.org 7445863Snate@binkert.org # This cpu is enabled by default 7455863Snate@binkert.org self.default = default 7461869SN/A 7471869SN/A # Add self to dict 7481869SN/A if name in CpuModel.dict: 7491869SN/A raise AttributeError, "CpuModel '%s' already registered" % name 7501869SN/A CpuModel.dict[name] = self 7512638Sstever@eecs.umich.edu CpuModel.list.append(name) 7522638Sstever@eecs.umich.edu 7535871Snate@binkert.orgExport('CpuModel') 7542638Sstever@eecs.umich.edu 7555749Scws3k@cs.virginia.edu# Sticky variables get saved in the variables file so they persist from 7565749Scws3k@cs.virginia.edu# one invocation to the next (unless overridden, in which case the new 7575871Snate@binkert.org# value becomes sticky). 7585749Scws3k@cs.virginia.edusticky_vars = Variables(args=ARGUMENTS) 7591869SN/AExport('sticky_vars') 7601869SN/A 7613546Sgblack@eecs.umich.edu# Sticky variables that should be exported 7623546Sgblack@eecs.umich.eduexport_vars = [] 7633546Sgblack@eecs.umich.eduExport('export_vars') 7643546Sgblack@eecs.umich.edu 7654202Sbinkertn@umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 7665863Snate@binkert.org# above variables 7673546Sgblack@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list: 7683546Sgblack@eecs.umich.edu if not isdir(bdir): 7693546Sgblack@eecs.umich.edu print "Error: directory '%s' does not exist" % bdir 7703546Sgblack@eecs.umich.edu Exit(1) 7714781Snate@binkert.org for root, dirs, files in os.walk(bdir): 7725863Snate@binkert.org if 'SConsopts' in files: 7734781Snate@binkert.org print "Reading", joinpath(root, 'SConsopts') 7744781Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 7754781Snate@binkert.org 7764781Snate@binkert.orgall_isa_list.sort() 7774781Snate@binkert.org 7785863Snate@binkert.orgsticky_vars.AddVariables( 7794781Snate@binkert.org EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 7804781Snate@binkert.org BoolVariable('FULL_SYSTEM', 'Full-system support', False), 7814781Snate@binkert.org ListVariable('CPU_MODELS', 'CPU models', 7824781Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 7833546Sgblack@eecs.umich.edu sorted(CpuModel.list)), 7843546Sgblack@eecs.umich.edu BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 7853546Sgblack@eecs.umich.edu BoolVariable('FORCE_FAST_ALLOC', 7864781Snate@binkert.org 'Enable fast object allocator, even for m5.debug', False), 7873546Sgblack@eecs.umich.edu BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 7883546Sgblack@eecs.umich.edu False), 7893546Sgblack@eecs.umich.edu BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 7903546Sgblack@eecs.umich.edu False), 7913546Sgblack@eecs.umich.edu BoolVariable('SS_COMPATIBLE_FP', 7923546Sgblack@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 7933546Sgblack@eecs.umich.edu False), 7943546Sgblack@eecs.umich.edu BoolVariable('USE_SSE2', 7953546Sgblack@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 7963546Sgblack@eecs.umich.edu False), 7974202Sbinkertn@umich.edu BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 7983546Sgblack@eecs.umich.edu BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 7993546Sgblack@eecs.umich.edu BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 8003546Sgblack@eecs.umich.edu BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 801955SN/A BoolVariable('RUBY', 'Build with Ruby', False), 802955SN/A ) 803955SN/A 804955SN/A# These variables get exported to #defines in config/*.hh (see src/SConscript). 8051858SN/Aexport_vars += ['FULL_SYSTEM', 'USE_FENV', 8061858SN/A 'NO_FAST_ALLOC', 'FORCE_FAST_ALLOC', 'FAST_ALLOC_STATS', 8071858SN/A 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE', 8085863Snate@binkert.org 'USE_POSIX_CLOCK' ] 8095863Snate@binkert.org 8105343Sstever@gmail.com################################################### 8115343Sstever@gmail.com# 8125863Snate@binkert.org# Define a SCons builder for configuration flag headers. 8135863Snate@binkert.org# 8144773Snate@binkert.org################################################### 8155863Snate@binkert.org 8162632Sstever@eecs.umich.edu# This function generates a config header file that #defines the 8175863Snate@binkert.org# variable symbol to the current variable setting (0 or 1). The source 8182023SN/A# operands are the name of the variable and a Value node containing the 8195863Snate@binkert.org# value of the variable. 8205863Snate@binkert.orgdef build_config_file(target, source, env): 8215863Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 8225863Snate@binkert.org f = file(str(target[0]), 'w') 8235863Snate@binkert.org print >> f, '#define', variable, value 8245863Snate@binkert.org f.close() 8255863Snate@binkert.org return None 8265863Snate@binkert.org 8275863Snate@binkert.org# Generate the message to be printed when building the config file. 8282632Sstever@eecs.umich.edudef build_config_file_string(target, source, env): 8295863Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 8302023SN/A return "Defining %s as %s in %s." % (variable, value, target[0]) 8312632Sstever@eecs.umich.edu 8325863Snate@binkert.org# Combine the two functions into a scons Action object. 8335342Sstever@gmail.comconfig_action = Action(build_config_file, build_config_file_string) 8345863Snate@binkert.org 8352632Sstever@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 8365863Snate@binkert.org# we're really doing. 8375863Snate@binkert.orgdef config_emitter(target, source, env): 8382632Sstever@eecs.umich.edu # extract variable name from Builder arg 8395863Snate@binkert.org variable = str(target[0]) 8405863Snate@binkert.org # True target is config header file 8415863Snate@binkert.org target = joinpath('config', variable.lower() + '.hh') 8425863Snate@binkert.org val = env[variable] 8435863Snate@binkert.org if isinstance(val, bool): 8445863Snate@binkert.org # Force value to 0/1 8452632Sstever@eecs.umich.edu val = int(val) 8465863Snate@binkert.org elif isinstance(val, str): 8475863Snate@binkert.org val = '"' + val + '"' 8482632Sstever@eecs.umich.edu 8491888SN/A # Sources are variable name & value (packaged in SCons Value nodes) 8505863Snate@binkert.org return ([target], [Value(variable), Value(val)]) 8515863Snate@binkert.org 8525863Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 8531858SN/A 8545863Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 8555863Snate@binkert.org 8565863Snate@binkert.org# libelf build is shared across all configs in the build root. 8575863Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 8582598SN/A variant_dir = joinpath(build_root, 'libelf')) 8595863Snate@binkert.org 8601858SN/A# gzstream build is shared across all configs in the build root. 8611858SN/Amain.SConscript('ext/gzstream/SConscript', 8621858SN/A variant_dir = joinpath(build_root, 'gzstream')) 8635863Snate@binkert.org 8641858SN/A################################################### 8651858SN/A# 8661858SN/A# This function is used to set up a directory with switching headers 8675863Snate@binkert.org# 8681871SN/A################################################### 8691858SN/A 8701858SN/Amain['ALL_ISA_LIST'] = all_isa_list 8711858SN/Adef make_switching_dir(dname, switch_headers, env): 8721858SN/A # Generate the header. target[0] is the full path of the output 8731858SN/A # header to generate. 'source' is a dummy variable, since we get the 8741858SN/A # list of ISAs from env['ALL_ISA_LIST']. 8751858SN/A def gen_switch_hdr(target, source, env): 8765863Snate@binkert.org fname = str(target[0]) 8771858SN/A f = open(fname, 'w') 8781858SN/A isa = env['TARGET_ISA'].lower() 8795863Snate@binkert.org print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 8801859SN/A f.close() 8811859SN/A 8821869SN/A # Build SCons Action object. 'varlist' specifies env vars that this 8835863Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 8845863Snate@binkert.org # should get re-executed. 8851869SN/A switch_hdr_action = MakeAction(gen_switch_hdr, 8861965SN/A Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 8871965SN/A 8881965SN/A # Instantiate actions for each header 8892761Sstever@eecs.umich.edu for hdr in switch_headers: 8905863Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 8911869SN/AExport('make_switching_dir') 8925863Snate@binkert.org 8932667Sstever@eecs.umich.edu################################################### 8941869SN/A# 8951869SN/A# Define build environments for selected configurations. 8962929Sktlim@umich.edu# 8972929Sktlim@umich.edu################################################### 8985863Snate@binkert.org 8992929Sktlim@umich.edufor variant_path in variant_paths: 900955SN/A print "Building in", variant_path 9012598SN/A 902 # Make a copy of the build-root environment to use for this config. 903 env = main.Clone() 904 env['BUILDDIR'] = variant_path 905 906 # variant_dir is the tail component of build path, and is used to 907 # determine the build parameters (e.g., 'ALPHA_SE') 908 (build_root, variant_dir) = splitpath(variant_path) 909 910 # Set env variables according to the build directory config. 911 sticky_vars.files = [] 912 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 913 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 914 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 915 current_vars_file = joinpath(build_root, 'variables', variant_dir) 916 if isfile(current_vars_file): 917 sticky_vars.files.append(current_vars_file) 918 print "Using saved variables file %s" % current_vars_file 919 else: 920 # Build dir-specific variables file doesn't exist. 921 922 # Make sure the directory is there so we can create it later 923 opt_dir = dirname(current_vars_file) 924 if not isdir(opt_dir): 925 mkdir(opt_dir) 926 927 # Get default build variables from source tree. Variables are 928 # normally determined by name of $VARIANT_DIR, but can be 929 # overridden by '--default=' arg on command line. 930 default = GetOption('default') 931 opts_dir = joinpath(main.root.abspath, 'build_opts') 932 if default: 933 default_vars_files = [joinpath(build_root, 'variables', default), 934 joinpath(opts_dir, default)] 935 else: 936 default_vars_files = [joinpath(opts_dir, variant_dir)] 937 existing_files = filter(isfile, default_vars_files) 938 if existing_files: 939 default_vars_file = existing_files[0] 940 sticky_vars.files.append(default_vars_file) 941 print "Variables file %s not found,\n using defaults in %s" \ 942 % (current_vars_file, default_vars_file) 943 else: 944 print "Error: cannot find variables file %s or " \ 945 "default file(s) %s" \ 946 % (current_vars_file, ' or '.join(default_vars_files)) 947 Exit(1) 948 949 # Apply current variable settings to env 950 sticky_vars.Update(env) 951 952 help_texts["local_vars"] += \ 953 "Build variables for %s:\n" % variant_dir \ 954 + sticky_vars.GenerateHelpText(env) 955 956 # Process variable settings. 957 958 if not have_fenv and env['USE_FENV']: 959 print "Warning: <fenv.h> not available; " \ 960 "forcing USE_FENV to False in", variant_dir + "." 961 env['USE_FENV'] = False 962 963 if not env['USE_FENV']: 964 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 965 print " FP results may deviate slightly from other platforms." 966 967 if env['EFENCE']: 968 env.Append(LIBS=['efence']) 969 970 # Save sticky variable settings back to current variables file 971 sticky_vars.Save(current_vars_file, env) 972 973 if env['USE_SSE2']: 974 env.Append(CCFLAGS=['-msse2']) 975 976 # The src/SConscript file sets up the build rules in 'env' according 977 # to the configured variables. It returns a list of environments, 978 # one for each variant build (debug, opt, etc.) 979 envList = SConscript('src/SConscript', variant_dir = variant_path, 980 exports = 'env') 981 982 # Set up the regression tests for each build. 983 for e in envList: 984 SConscript('tests/SConscript', 985 variant_dir = joinpath(variant_path, 'tests', e.Label), 986 exports = { 'env' : e }, duplicate = False) 987 988# base help text 989Help(''' 990Usage: scons [scons options] [build variables] [target(s)] 991 992Extra scons options: 993%(options)s 994 995Global build variables: 996%(global_vars)s 997 998%(local_vars)s 999''' % help_texts) 1000