SConstruct revision 8737
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') 1616121Snate@binkert.orgif use_colors: 1625871Snate@binkert.org from m5.util.terminal import termcap 1635871Snate@binkert.orgelif use_colors is None: 1646003Snate@binkert.org # option unspecified; default behavior is to use colors iff isatty 1656003Snate@binkert.org from m5.util.terminal import tty_termcap as termcap 166955SN/Aelse: 1675871Snate@binkert.org from m5.util.terminal import no_termcap as termcap 1685871Snate@binkert.org 1695871Snate@binkert.org######################################################################## 1705871Snate@binkert.org# 171955SN/A# Set up the main build environment. 1726121Snate@binkert.org# 1736121Snate@binkert.org######################################################################## 1746121Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1751533SN/A 'PYTHONPATH', 'RANLIB' ]) 1765871Snate@binkert.org 1775871Snate@binkert.orguse_env = {} 1785863Snate@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) 1835871Snate@binkert.orgmain.root = Dir(".") # The current directory (where this file lives). 1845863Snate@binkert.orgmain.srcdir = Dir("src") # The source directory 1856121Snate@binkert.org 1865863Snate@binkert.org# add useful python code PYTHONPATH so it can be used by subprocesses 1875871Snate@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 1994678Snate@binkert.orghgdir = main.root.Dir(".hg") 2006121Snate@binkert.org 2014678Snate@binkert.orgmercurial_style_message = """ 2025871Snate@binkert.orgYou're missing the gem5 style hook, which automatically checks your code 2035871Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands. This 2045871Snate@binkert.orgscript will now install the hook in your .hg/hgrc file. 2055871Snate@binkert.orgPress enter to continue, or ctrl-c to abort: """ 2065871Snate@binkert.org 2075871Snate@binkert.orgmercurial_style_hook = """ 2085871Snate@binkert.org# The following lines were automatically added by gem5/SConstruct 2095871Snate@binkert.org# to provide the gem5 style-checking hooks 2105871Snate@binkert.org[extensions] 2115871Snate@binkert.orgstyle = %s/util/style.py 2125871Snate@binkert.org 2135871Snate@binkert.org[hooks] 2145871Snate@binkert.orgpretxncommit.style = python:style.check_style 2155990Ssaidi@eecs.umich.edupre-qrefresh.style = python:style.check_style 2165871Snate@binkert.org# End of SConstruct additions 2175871Snate@binkert.org 2185871Snate@binkert.org""" % (main.root.abspath) 2194678Snate@binkert.org 2206121Snate@binkert.orgmercurial_lib_not_found = """ 2215871Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook. If 2225871Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 2235871Snate@binkert.orghook. It is important. 2245871Snate@binkert.org""" 2255871Snate@binkert.org 2265871Snate@binkert.org# Check for style hook and prompt for installation if it's not there. 2275871Snate@binkert.org# Skip this if --ignore-style was specified, there's no .hg dir to 2285871Snate@binkert.org# install a hook in, or there's no interactive terminal to prompt. 2295871Snate@binkert.orgif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2304678Snate@binkert.org style_hook = True 2315871Snate@binkert.org try: 2324678Snate@binkert.org from mercurial import ui 2335871Snate@binkert.org ui = ui.ui() 2345871Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2355871Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2365871Snate@binkert.org ui.config('hooks', 'pre-qrefresh.style', None) 2375871Snate@binkert.org except ImportError: 2385871Snate@binkert.org print mercurial_lib_not_found 2395871Snate@binkert.org 2405871Snate@binkert.org if not style_hook: 2415871Snate@binkert.org print mercurial_style_message, 2426121Snate@binkert.org # continue unless user does ctrl-c/ctrl-d etc. 2436121Snate@binkert.org try: 2445863Snate@binkert.org raw_input() 245955SN/A except: 246955SN/A print "Input exception, exiting scons.\n" 2472632Sstever@eecs.umich.edu sys.exit(1) 2482632Sstever@eecs.umich.edu hgrc_path = '%s/.hg/hgrc' % main.root.abspath 249955SN/A print "Adding style hook to", hgrc_path, "\n" 250955SN/A try: 251955SN/A hgrc = open(hgrc_path, 'a') 252955SN/A hgrc.write(mercurial_style_hook) 2535863Snate@binkert.org hgrc.close() 254955SN/A except: 2552632Sstever@eecs.umich.edu print "Error updating", hgrc_path 2562632Sstever@eecs.umich.edu sys.exit(1) 2572632Sstever@eecs.umich.edu 2582632Sstever@eecs.umich.edu 2592632Sstever@eecs.umich.edu################################################### 2602632Sstever@eecs.umich.edu# 2612632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2622632Sstever@eecs.umich.edu# the target(s). 2632632Sstever@eecs.umich.edu# 2642632Sstever@eecs.umich.edu################################################### 2652632Sstever@eecs.umich.edu 2662632Sstever@eecs.umich.edu# Find default configuration & binary. 2672632Sstever@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2683718Sstever@eecs.umich.edu 2693718Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 2703718Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 2713718Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2723718Sstever@eecs.umich.edu if l[i] == elt: 2735863Snate@binkert.org return i 2745863Snate@binkert.org raise ValueError, "element not found" 2753718Sstever@eecs.umich.edu 2763718Sstever@eecs.umich.edu# Take a list of paths (or SCons Nodes) and return a list with all 2776121Snate@binkert.org# paths made absolute and ~-expanded. Paths will be interpreted 2785863Snate@binkert.org# relative to the launch directory unless a different root is provided 2793718Sstever@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 2803718Sstever@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 2812634Sstever@eecs.umich.edu for p in path_list] 2822634Sstever@eecs.umich.edu 2835863Snate@binkert.org# Each target must have 'build' in the interior of the path; the 2842638Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2852632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2862632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 2872632Sstever@eecs.umich.edu# follow 'build' in the build path. 2882632Sstever@eecs.umich.edu 2892632Sstever@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 2902632Sstever@eecs.umich.edu# in place rather than reassign the symbol to a new list, which 2911858SN/A# doesn't work (obviously!). 2923716Sstever@eecs.umich.eduBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 2932638Sstever@eecs.umich.edu 2942638Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 2952638Sstever@eecs.umich.edu# collected targets reference. 2962638Sstever@eecs.umich.eduvariant_paths = [] 2972638Sstever@eecs.umich.edubuild_root = None 2982638Sstever@eecs.umich.edufor t in BUILD_TARGETS: 2992638Sstever@eecs.umich.edu path_dirs = t.split('/') 3005863Snate@binkert.org try: 3015863Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 3025863Snate@binkert.org except: 303955SN/A print "Error: no non-leaf 'build' dir found on target path", t 3045341Sstever@gmail.com Exit(1) 3055341Sstever@gmail.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3065863Snate@binkert.org if not build_root: 3075341Sstever@gmail.com build_root = this_build_root 3086121Snate@binkert.org else: 3094494Ssaidi@eecs.umich.edu if this_build_root != build_root: 3106121Snate@binkert.org print "Error: build targets not under same build root\n"\ 3111105SN/A " %s\n %s" % (build_root, this_build_root) 3122667Sstever@eecs.umich.edu Exit(1) 3132667Sstever@eecs.umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 3142667Sstever@eecs.umich.edu if variant_path not in variant_paths: 3152667Sstever@eecs.umich.edu variant_paths.append(variant_path) 3166121Snate@binkert.org 3172667Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 3185341Sstever@gmail.comif not isdir(build_root): 3195863Snate@binkert.org mkdir(build_root) 3205341Sstever@gmail.commain['BUILDROOT'] = build_root 3215341Sstever@gmail.com 3225341Sstever@gmail.comExport('main') 3235863Snate@binkert.org 3245341Sstever@gmail.commain.SConsignFile(joinpath(build_root, "sconsign")) 3255341Sstever@gmail.com 3265341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up 3275863Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 3285341Sstever@gmail.com# file to file~ then copies to file, breaking the link. Symbolic 3295341Sstever@gmail.com# (soft) links work better. 3305341Sstever@gmail.commain.SetOption('duplicate', 'soft-copy') 3315341Sstever@gmail.com 3325341Sstever@gmail.com# 3335341Sstever@gmail.com# Set up global sticky variables... these are common to an entire build 3345341Sstever@gmail.com# tree (not specific to a particular build like ALPHA_SE) 3355341Sstever@gmail.com# 3365341Sstever@gmail.com 3375341Sstever@gmail.comglobal_vars_file = joinpath(build_root, 'variables.global') 3385863Snate@binkert.org 3395341Sstever@gmail.comglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3405863Snate@binkert.org 3415341Sstever@gmail.comglobal_vars.AddVariables( 3425863Snate@binkert.org ('CC', 'C compiler', environ.get('CC', main['CC'])), 3436121Snate@binkert.org ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3446121Snate@binkert.org ('BATCH', 'Use batch pool for build and tests', False), 3455397Ssaidi@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3465397Ssaidi@eecs.umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3475341Sstever@gmail.com ('EXTRAS', 'Add extra directories to the compilation', '') 3485341Sstever@gmail.com ) 3495341Sstever@gmail.com 3505341Sstever@gmail.com# Update main environment with values from ARGUMENTS & global_vars_file 3515341Sstever@gmail.comglobal_vars.Update(main) 3525341Sstever@gmail.comhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3535341Sstever@gmail.com 3545341Sstever@gmail.com# Save sticky variable settings back to current variables file 3555863Snate@binkert.orgglobal_vars.Save(global_vars_file, main) 3565341Sstever@gmail.com 3575341Sstever@gmail.com# Parse EXTRAS variable to build list of all directories where we're 3586121Snate@binkert.org# look for sources etc. This list is exported as extras_dir_list. 3595341Sstever@gmail.combase_dir = main.srcdir.abspath 3606121Snate@binkert.orgif main['EXTRAS']: 3616121Snate@binkert.org extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3625341Sstever@gmail.comelse: 3635863Snate@binkert.org extras_dir_list = [] 3646121Snate@binkert.org 3655341Sstever@gmail.comExport('base_dir') 3665863Snate@binkert.orgExport('extras_dir_list') 3675341Sstever@gmail.com 3686121Snate@binkert.org# the ext directory should be on the #includes path 3696121Snate@binkert.orgmain.Append(CPPPATH=[Dir('ext')]) 3706121Snate@binkert.org 3715742Snate@binkert.orgdef strip_build_path(path, env): 3725742Snate@binkert.org path = str(path) 3735341Sstever@gmail.com variant_base = env['BUILDROOT'] + os.path.sep 3745742Snate@binkert.org if path.startswith(variant_base): 3755742Snate@binkert.org path = path[len(variant_base):] 3765341Sstever@gmail.com elif path.startswith('build/'): 3776017Snate@binkert.org path = path[6:] 3786121Snate@binkert.org return path 3796017Snate@binkert.org 3802632Sstever@eecs.umich.edu# Generate a string of the form: 3816121Snate@binkert.org# common/path/prefix/src1, src2 -> tgt1, tgt2 3825871Snate@binkert.org# to print while building. 3836121Snate@binkert.orgclass Transform(object): 3846121Snate@binkert.org # all specific color settings should be here and nowhere else 3855871Snate@binkert.org tool_color = termcap.Normal 3866121Snate@binkert.org pfx_color = termcap.Yellow 3876121Snate@binkert.org srcs_color = termcap.Yellow + termcap.Bold 3886121Snate@binkert.org arrow_color = termcap.Blue + termcap.Bold 3896121Snate@binkert.org tgts_color = termcap.Yellow + termcap.Bold 3903940Ssaidi@eecs.umich.edu 3913918Ssaidi@eecs.umich.edu def __init__(self, tool, max_sources=99): 3923918Ssaidi@eecs.umich.edu self.format = self.tool_color + (" [%8s] " % tool) \ 3931858SN/A + self.pfx_color + "%s" \ 3946121Snate@binkert.org + self.srcs_color + "%s" \ 3956121Snate@binkert.org + self.arrow_color + " -> " \ 3966121Snate@binkert.org + self.tgts_color + "%s" \ 3976143Snate@binkert.org + termcap.Normal 3986121Snate@binkert.org self.max_sources = max_sources 3996121Snate@binkert.org 4003940Ssaidi@eecs.umich.edu def __call__(self, target, source, env, for_signature=None): 4016121Snate@binkert.org # truncate source list according to max_sources param 4026121Snate@binkert.org source = source[0:self.max_sources] 4036121Snate@binkert.org def strip(f): 4046121Snate@binkert.org return strip_build_path(str(f), env) 4056121Snate@binkert.org if len(source) > 0: 4066121Snate@binkert.org srcs = map(strip, source) 4076121Snate@binkert.org else: 4083918Ssaidi@eecs.umich.edu srcs = [''] 4093918Ssaidi@eecs.umich.edu tgts = map(strip, target) 4103940Ssaidi@eecs.umich.edu # surprisingly, os.path.commonprefix is a dumb char-by-char string 4113918Ssaidi@eecs.umich.edu # operation that has nothing to do with paths. 4123918Ssaidi@eecs.umich.edu com_pfx = os.path.commonprefix(srcs + tgts) 4136157Snate@binkert.org com_pfx_len = len(com_pfx) 4146157Snate@binkert.org if com_pfx: 4156157Snate@binkert.org # do some cleanup and sanity checking on common prefix 4166157Snate@binkert.org if com_pfx[-1] == ".": 4175397Ssaidi@eecs.umich.edu # prefix matches all but file extension: ok 4185397Ssaidi@eecs.umich.edu # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4196121Snate@binkert.org com_pfx = com_pfx[0:-1] 4206121Snate@binkert.org elif com_pfx[-1] == "/": 4216121Snate@binkert.org # common prefix is directory path: OK 4226121Snate@binkert.org pass 4236121Snate@binkert.org else: 4246121Snate@binkert.org src0_len = len(srcs[0]) 4255397Ssaidi@eecs.umich.edu tgt0_len = len(tgts[0]) 4261851SN/A if src0_len == com_pfx_len: 4271851SN/A # source is a substring of target, OK 4286121Snate@binkert.org pass 429955SN/A elif tgt0_len == com_pfx_len: 4303053Sstever@eecs.umich.edu # target is a substring of source, need to back up to 4316121Snate@binkert.org # avoid empty string on RHS of arrow 4323053Sstever@eecs.umich.edu sep_idx = com_pfx.rfind(".") 4333053Sstever@eecs.umich.edu if sep_idx != -1: 4343053Sstever@eecs.umich.edu com_pfx = com_pfx[0:sep_idx] 4353053Sstever@eecs.umich.edu else: 4363053Sstever@eecs.umich.edu com_pfx = '' 4375871Snate@binkert.org elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4383053Sstever@eecs.umich.edu # still splitting at file extension: ok 4394742Sstever@eecs.umich.edu pass 4404742Sstever@eecs.umich.edu else: 4413053Sstever@eecs.umich.edu # probably a fluke; ignore it 4423053Sstever@eecs.umich.edu com_pfx = '' 4433053Sstever@eecs.umich.edu # recalculate length in case com_pfx was modified 4443053Sstever@eecs.umich.edu com_pfx_len = len(com_pfx) 4453053Sstever@eecs.umich.edu def fmt(files): 4463053Sstever@eecs.umich.edu f = map(lambda s: s[com_pfx_len:], files) 4473053Sstever@eecs.umich.edu return ', '.join(f) 4483053Sstever@eecs.umich.edu return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4493053Sstever@eecs.umich.edu 4502667Sstever@eecs.umich.eduExport('Transform') 4514554Sbinkertn@umich.edu 4526121Snate@binkert.org 4532667Sstever@eecs.umich.eduif GetOption('verbose'): 4544554Sbinkertn@umich.edu def MakeAction(action, string, *args, **kwargs): 4554554Sbinkertn@umich.edu return Action(action, *args, **kwargs) 4564554Sbinkertn@umich.eduelse: 4576121Snate@binkert.org MakeAction = Action 4584554Sbinkertn@umich.edu main['CCCOMSTR'] = Transform("CC") 4594554Sbinkertn@umich.edu main['CXXCOMSTR'] = Transform("CXX") 4604554Sbinkertn@umich.edu main['ASCOMSTR'] = Transform("AS") 4614781Snate@binkert.org main['SWIGCOMSTR'] = Transform("SWIG") 4624554Sbinkertn@umich.edu main['ARCOMSTR'] = Transform("AR", 0) 4634554Sbinkertn@umich.edu main['LINKCOMSTR'] = Transform("LINK", 0) 4642667Sstever@eecs.umich.edu main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4654554Sbinkertn@umich.edu main['M4COMSTR'] = Transform("M4") 4664554Sbinkertn@umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 4674554Sbinkertn@umich.edu main['SHCXXCOMSTR'] = Transform("SHCXX") 4684554Sbinkertn@umich.eduExport('MakeAction') 4692667Sstever@eecs.umich.edu 4704554Sbinkertn@umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4712667Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 4724554Sbinkertn@umich.edu 4736121Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4742667Sstever@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4755522Snate@binkert.orgmain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4765522Snate@binkert.orgmain['CLANG'] = CXX_V and CXX_V.find('clang') >= 0 4775522Snate@binkert.orgif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: 4785522Snate@binkert.org print 'Error: How can we have two at the same time?' 4795522Snate@binkert.org Exit(1) 4805522Snate@binkert.org 4815522Snate@binkert.org# Set up default C++ compiler flags 4825522Snate@binkert.orgif main['GCC']: 4835522Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 4845522Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 4855522Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4865522Snate@binkert.org main.Append(CXXFLAGS=['-Wno-deprecated']) 4875522Snate@binkert.org # Read the GCC version to check for versions with bugs 4885522Snate@binkert.org # Note CCVERSION doesn't work here because it is run with the CC 4895522Snate@binkert.org # before we override it from the command line 4905522Snate@binkert.org gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4915522Snate@binkert.org main['GCC_VERSION'] = gcc_version 4925522Snate@binkert.org if not compareVersions(gcc_version, '4.4.1') or \ 4935522Snate@binkert.org not compareVersions(gcc_version, '4.4.2'): 4945522Snate@binkert.org print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 4955522Snate@binkert.org main.Append(CCFLAGS=['-fno-tree-vectorize']) 4965522Snate@binkert.orgelif main['ICC']: 4975522Snate@binkert.org pass #Fix me... add warning flags once we clean up icc warnings 4985522Snate@binkert.orgelif main['SUNCC']: 4995522Snate@binkert.org main.Append(CCFLAGS=['-Qoption ccfe']) 5005522Snate@binkert.org main.Append(CCFLAGS=['-features=gcc']) 5012638Sstever@eecs.umich.edu main.Append(CCFLAGS=['-features=extensions']) 5022638Sstever@eecs.umich.edu main.Append(CCFLAGS=['-library=stlport4']) 5036121Snate@binkert.org main.Append(CCFLAGS=['-xar']) 5043716Sstever@eecs.umich.edu #main.Append(CCFLAGS=['-instances=semiexplicit']) 5055522Snate@binkert.orgelif main['CLANG']: 5065522Snate@binkert.org clang_version_re = re.compile(".* version (\d+\.\d+)") 5075522Snate@binkert.org clang_version_match = clang_version_re.match(CXX_version) 5085522Snate@binkert.org if (clang_version_match): 5095522Snate@binkert.org clang_version = clang_version_match.groups()[0] 5105522Snate@binkert.org if compareVersions(clang_version, "2.9") < 0: 5111858SN/A print 'Error: clang version 2.9 or newer required.' 5125227Ssaidi@eecs.umich.edu print ' Installed version:', clang_version 5135227Ssaidi@eecs.umich.edu Exit(1) 5145227Ssaidi@eecs.umich.edu else: 5155227Ssaidi@eecs.umich.edu print 'Error: Unable to determine clang version.' 5165227Ssaidi@eecs.umich.edu Exit(1) 5175863Snate@binkert.org 5186121Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 5196121Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 5206121Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5216121Snate@binkert.org main.Append(CCFLAGS=['-Wno-tautological-compare']) 5225227Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Wno-self-assign']) 5235227Ssaidi@eecs.umich.eduelse: 5245227Ssaidi@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 5255204Sstever@gmail.com print ' Please fix SConstruct and src/SConscript and try again.' 5265204Sstever@gmail.com Exit(1) 5275204Sstever@gmail.com 5285204Sstever@gmail.com# Set up common yacc/bison flags (needed for Ruby) 5295204Sstever@gmail.commain['YACCFLAGS'] = '-d' 5305204Sstever@gmail.commain['YACCHXXFILESUFFIX'] = '.hh' 5315204Sstever@gmail.com 5325204Sstever@gmail.com# Do this after we save setting back, or else we'll tack on an 5335204Sstever@gmail.com# extra 'qdo' every time we run scons. 5345204Sstever@gmail.comif main['BATCH']: 5355204Sstever@gmail.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5365204Sstever@gmail.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5375204Sstever@gmail.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5385204Sstever@gmail.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5395204Sstever@gmail.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5405204Sstever@gmail.com 5415204Sstever@gmail.comif sys.platform == 'cygwin': 5426121Snate@binkert.org # cygwin has some header file issues... 5435204Sstever@gmail.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 5443118Sstever@eecs.umich.edu 5453118Sstever@eecs.umich.edu# Check for SWIG 5463118Sstever@eecs.umich.eduif not main.has_key('SWIG'): 5473118Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 5483118Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 5495863Snate@binkert.org Exit(1) 5503118Sstever@eecs.umich.edu 5515863Snate@binkert.org# Check for appropriate SWIG version 5523118Sstever@eecs.umich.eduswig_version = readCommand(('swig', '-version'), exception='').split() 5535863Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 5545863Snate@binkert.orgif len(swig_version) < 3 or \ 5555863Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5565863Snate@binkert.org print 'Error determining SWIG version.' 5575863Snate@binkert.org Exit(1) 5585863Snate@binkert.org 5595863Snate@binkert.orgmin_swig_version = '1.3.28' 5605863Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0: 5616003Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 5625863Snate@binkert.org print ' Installed version:', swig_version[2] 5635863Snate@binkert.org Exit(1) 5645863Snate@binkert.org 5656120Snate@binkert.org# Set up SWIG flags & scanner 5665863Snate@binkert.orgswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5675863Snate@binkert.orgmain.Append(SWIGFLAGS=swig_flags) 5685863Snate@binkert.org 5696120Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 5706120Snate@binkert.org# stuff for some reason 5715863Snate@binkert.orgscanners = [] 5725863Snate@binkert.orgfor scanner in main['SCANNERS']: 5736120Snate@binkert.org skeys = scanner.skeys 5745863Snate@binkert.org if skeys == '.i': 5756121Snate@binkert.org continue 5766121Snate@binkert.org 5775863Snate@binkert.org if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5785863Snate@binkert.org continue 5793118Sstever@eecs.umich.edu 5805863Snate@binkert.org scanners.append(scanner) 5813118Sstever@eecs.umich.edu 5823118Sstever@eecs.umich.edu# add the new swig scanner that we like better 5835863Snate@binkert.orgfrom SCons.Scanner import ClassicCPP as CPPScanner 5845863Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 5855863Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 5865863Snate@binkert.org 5873118Sstever@eecs.umich.edu# replace the scanners list that has what we want 5883483Ssaidi@eecs.umich.edumain['SCANNERS'] = scanners 5893494Ssaidi@eecs.umich.edu 5903494Ssaidi@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 5913483Ssaidi@eecs.umich.edu# figure out if the compiler adds leading underscores to global 5923483Ssaidi@eecs.umich.edu# variables. This is needed for the autogenerated asm files that we 5933483Ssaidi@eecs.umich.edu# use for embedding the python code. 5943053Sstever@eecs.umich.edudef CheckLeading(context): 5953053Sstever@eecs.umich.edu context.Message("Checking for leading underscore in global variables...") 5963918Ssaidi@eecs.umich.edu # 1) Define a global variable called x from asm so the C compiler 5973053Sstever@eecs.umich.edu # won't change the symbol at all. 5983053Sstever@eecs.umich.edu # 2) Declare that variable. 5993053Sstever@eecs.umich.edu # 3) Use the variable 6003053Sstever@eecs.umich.edu # 6013053Sstever@eecs.umich.edu # If the compiler prepends an underscore, this will successfully 6021858SN/A # link because the external symbol 'x' will be called '_x' which 6031858SN/A # was defined by the asm statement. If the compiler does not 6041858SN/A # prepend an underscore, this will not successfully link because 6051858SN/A # '_x' will have been defined by assembly, while the C portion of 6061858SN/A # the code will be trying to use 'x' 6071858SN/A ret = context.TryLink(''' 6085863Snate@binkert.org asm(".globl _x; _x: .byte 0"); 6095863Snate@binkert.org extern int x; 6101859SN/A int main() { return x; } 6115863Snate@binkert.org ''', extension=".c") 6121858SN/A context.env.Append(LEADING_UNDERSCORE=ret) 6135863Snate@binkert.org context.Result(ret) 6141858SN/A return ret 6151859SN/A 6161859SN/A# Platform-specific configuration. Note again that we assume that all 6175863Snate@binkert.org# builds under a given build root run on the same host platform. 6183053Sstever@eecs.umich.educonf = Configure(main, 6193053Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 6203053Sstever@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 6213053Sstever@eecs.umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 6221859SN/A 6231859SN/A# Check for leading underscores. Don't really need to worry either 6241859SN/A# way so don't need to check the return code. 6251859SN/Aconf.CheckLeading() 6261859SN/A 6271859SN/A# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6281859SN/Atry: 6291859SN/A import platform 6301862SN/A uname = platform.uname() 6311859SN/A if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6321859SN/A if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6331859SN/A main.Append(CCFLAGS=['-arch', 'x86_64']) 6345863Snate@binkert.org main.Append(CFLAGS=['-arch', 'x86_64']) 6355863Snate@binkert.org main.Append(LINKFLAGS=['-arch', 'x86_64']) 6365863Snate@binkert.org main.Append(ASFLAGS=['-arch', 'x86_64']) 6375863Snate@binkert.orgexcept: 6386121Snate@binkert.org pass 6391858SN/A 6405863Snate@binkert.org# Recent versions of scons substitute a "Null" object for Configure() 6415863Snate@binkert.org# when configuration isn't necessary, e.g., if the "--help" option is 6425863Snate@binkert.org# present. Unfortuantely this Null object always returns false, 6435863Snate@binkert.org# breaking all our configuration checks. We replace it with our own 6445863Snate@binkert.org# more optimistic null object that returns True instead. 6452139SN/Aif not conf: 6464202Sbinkertn@umich.edu def NullCheck(*args, **kwargs): 6474202Sbinkertn@umich.edu return True 6482139SN/A 6492155SN/A class NullConf: 6504202Sbinkertn@umich.edu def __init__(self, env): 6514202Sbinkertn@umich.edu self.env = env 6524202Sbinkertn@umich.edu def Finish(self): 6532155SN/A return self.env 6545863Snate@binkert.org def __getattr__(self, mname): 6551869SN/A return NullCheck 6561869SN/A 6575863Snate@binkert.org conf = NullConf(main) 6585863Snate@binkert.org 6594202Sbinkertn@umich.edu# Find Python include and library directories for embedding the 6606108Snate@binkert.org# interpreter. For consistency, we will use the same Python 6616108Snate@binkert.org# installation used to run scons (and thus this script). If you want 6626108Snate@binkert.org# to link in an alternate version, see above for instructions on how 6636108Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 6645863Snate@binkert.orgfrom distutils import sysconfig 6655863Snate@binkert.org 6665863Snate@binkert.orgpy_getvar = sysconfig.get_config_var 6674202Sbinkertn@umich.edu 6684202Sbinkertn@umich.edupy_debug = getattr(sys, 'pydebug', False) 6695863Snate@binkert.orgpy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6705742Snate@binkert.org 6715742Snate@binkert.orgpy_general_include = sysconfig.get_python_inc() 6725341Sstever@gmail.compy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6735342Sstever@gmail.compy_includes = [ py_general_include ] 6745342Sstever@gmail.comif py_platform_include != py_general_include: 6754202Sbinkertn@umich.edu py_includes.append(py_platform_include) 6764202Sbinkertn@umich.edu 6774202Sbinkertn@umich.edupy_lib_path = [ py_getvar('LIBDIR') ] 6784202Sbinkertn@umich.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6794202Sbinkertn@umich.edu# shared library in prefix/lib/. 6805863Snate@binkert.orgif not py_getvar('Py_ENABLE_SHARED'): 6815863Snate@binkert.org py_lib_path.append(py_getvar('LIBPL')) 6825863Snate@binkert.org 6835863Snate@binkert.orgpy_libs = [] 6845863Snate@binkert.orgfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 6855863Snate@binkert.org if not lib.startswith('-l'): 6865863Snate@binkert.org # Python requires some special flags to link (e.g. -framework 6875863Snate@binkert.org # common on OS X systems), assume appending preserves order 6885863Snate@binkert.org main.Append(LINKFLAGS=[lib]) 6895863Snate@binkert.org else: 6905863Snate@binkert.org lib = lib[2:] 6915863Snate@binkert.org if lib not in py_libs: 6925863Snate@binkert.org py_libs.append(lib) 6935863Snate@binkert.orgpy_libs.append(py_version) 6945863Snate@binkert.org 6955863Snate@binkert.orgmain.Append(CPPPATH=py_includes) 6965863Snate@binkert.orgmain.Append(LIBPATH=py_lib_path) 6975863Snate@binkert.org 6985863Snate@binkert.org# Cache build files in the supplied directory. 6995863Snate@binkert.orgif main['M5_BUILD_CACHE']: 7005952Ssaidi@eecs.umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 7011869SN/A CacheDir(main['M5_BUILD_CACHE']) 7021858SN/A 7035863Snate@binkert.org 7045863Snate@binkert.org# verify that this stuff works 7051869SN/Aif not conf.CheckHeader('Python.h', '<>'): 7061858SN/A print "Error: can't find Python.h header in", py_includes 7075863Snate@binkert.org Exit(1) 7086108Snate@binkert.org 7096108Snate@binkert.orgfor lib in py_libs: 7106108Snate@binkert.org if not conf.CheckLib(lib): 7111858SN/A print "Error: can't find library %s required by python" % lib 712955SN/A Exit(1) 713955SN/A 7141869SN/A# On Solaris you need to use libsocket for socket ops 7151869SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7161869SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7171869SN/A print "Can't find library with socket calls (e.g. accept())" 7181869SN/A Exit(1) 7195863Snate@binkert.org 7205863Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 7215863Snate@binkert.org# added to the LIBS environment variable. 7221869SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7235863Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 7241869SN/A 'and/or zlib.h header file.' 7255863Snate@binkert.org print ' Please install zlib and try again.' 7261869SN/A Exit(1) 7271869SN/A 7281869SN/A# Check for librt. 7291869SN/Ahave_posix_clock = \ 7301869SN/A conf.CheckLibWithHeader(None, 'time.h', 'C', 7315863Snate@binkert.org 'clock_nanosleep(0,0,NULL,NULL);') or \ 7325863Snate@binkert.org conf.CheckLibWithHeader('rt', 'time.h', 'C', 7331869SN/A 'clock_nanosleep(0,0,NULL,NULL);') 7341869SN/A 7351869SN/Aif not have_posix_clock: 7361869SN/A print "Can't find library for POSIX clocks." 7371869SN/A 7381869SN/A# Check for <fenv.h> (C99 FP environment control) 7391869SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 7405863Snate@binkert.orgif not have_fenv: 7415863Snate@binkert.org print "Warning: Header file <fenv.h> not found." 7421869SN/A print " This host has no IEEE FP rounding mode control." 7435863Snate@binkert.org 7445863Snate@binkert.org###################################################################### 7453356Sbinkertn@umich.edu# 7463356Sbinkertn@umich.edu# Finish the configuration 7473356Sbinkertn@umich.edu# 7483356Sbinkertn@umich.edumain = conf.Finish() 7493356Sbinkertn@umich.edu 7504781Snate@binkert.org###################################################################### 7515863Snate@binkert.org# 7525863Snate@binkert.org# Collect all non-global variables 7531869SN/A# 7541869SN/A 7551869SN/A# Define the universe of supported ISAs 7566121Snate@binkert.orgall_isa_list = [ ] 7571869SN/AExport('all_isa_list') 7582638Sstever@eecs.umich.edu 7596121Snate@binkert.orgclass CpuModel(object): 7606121Snate@binkert.org '''The CpuModel class encapsulates everything the ISA parser needs to 7612638Sstever@eecs.umich.edu know about a particular CPU model.''' 7625749Scws3k@cs.virginia.edu 7636121Snate@binkert.org # Dict of available CPU model objects. Accessible as CpuModel.dict. 7646121Snate@binkert.org dict = {} 7655749Scws3k@cs.virginia.edu list = [] 7661869SN/A defaults = [] 7671869SN/A 7683546Sgblack@eecs.umich.edu # Constructor. Automatically adds models to CpuModel.dict. 7693546Sgblack@eecs.umich.edu def __init__(self, name, filename, includes, strings, default=False): 7703546Sgblack@eecs.umich.edu self.name = name # name of model 7713546Sgblack@eecs.umich.edu self.filename = filename # filename for output exec code 7726121Snate@binkert.org self.includes = includes # include files needed in exec file 7735863Snate@binkert.org # The 'strings' dict holds all the per-CPU symbols we can 7743546Sgblack@eecs.umich.edu # substitute into templates etc. 7753546Sgblack@eecs.umich.edu self.strings = strings 7763546Sgblack@eecs.umich.edu 7773546Sgblack@eecs.umich.edu # This cpu is enabled by default 7784781Snate@binkert.org self.default = default 7795863Snate@binkert.org 7804781Snate@binkert.org # Add self to dict 7814781Snate@binkert.org if name in CpuModel.dict: 7824781Snate@binkert.org raise AttributeError, "CpuModel '%s' already registered" % name 7834781Snate@binkert.org CpuModel.dict[name] = self 7844781Snate@binkert.org CpuModel.list.append(name) 7855863Snate@binkert.org 7864781Snate@binkert.orgExport('CpuModel') 7874781Snate@binkert.org 7884781Snate@binkert.org# Sticky variables get saved in the variables file so they persist from 7894781Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 7903546Sgblack@eecs.umich.edu# value becomes sticky). 7913546Sgblack@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS) 7923546Sgblack@eecs.umich.eduExport('sticky_vars') 7934781Snate@binkert.org 7943546Sgblack@eecs.umich.edu# Sticky variables that should be exported 7953546Sgblack@eecs.umich.eduexport_vars = [] 7963546Sgblack@eecs.umich.eduExport('export_vars') 7973546Sgblack@eecs.umich.edu 7983546Sgblack@eecs.umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 7993546Sgblack@eecs.umich.edu# above variables 8003546Sgblack@eecs.umich.eduif not GetOption('verbose'): 8013546Sgblack@eecs.umich.edu print "Reading SConsopts" 8023546Sgblack@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list: 8033546Sgblack@eecs.umich.edu if not isdir(bdir): 8044202Sbinkertn@umich.edu print "Error: directory '%s' does not exist" % bdir 8053546Sgblack@eecs.umich.edu Exit(1) 8063546Sgblack@eecs.umich.edu for root, dirs, files in os.walk(bdir): 8073546Sgblack@eecs.umich.edu if 'SConsopts' in files: 808955SN/A if GetOption('verbose'): 809955SN/A print "Reading", joinpath(root, 'SConsopts') 810955SN/A SConscript(joinpath(root, 'SConsopts')) 811955SN/A 8125863Snate@binkert.orgall_isa_list.sort() 8135863Snate@binkert.org 8145343Sstever@gmail.comsticky_vars.AddVariables( 8155343Sstever@gmail.com EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 8166121Snate@binkert.org BoolVariable('FULL_SYSTEM', 'Full-system support', False), 8175863Snate@binkert.org ListVariable('CPU_MODELS', 'CPU models', 8184773Snate@binkert.org sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 8195863Snate@binkert.org sorted(CpuModel.list)), 8202632Sstever@eecs.umich.edu BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 8215863Snate@binkert.org BoolVariable('FORCE_FAST_ALLOC', 8222023SN/A 'Enable fast object allocator, even for m5.debug', False), 8235863Snate@binkert.org BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 8245863Snate@binkert.org False), 8255863Snate@binkert.org BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 8265863Snate@binkert.org False), 8275863Snate@binkert.org BoolVariable('SS_COMPATIBLE_FP', 8285863Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 8295863Snate@binkert.org False), 8305863Snate@binkert.org BoolVariable('USE_SSE2', 8315863Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 8322632Sstever@eecs.umich.edu False), 8335863Snate@binkert.org BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 8342023SN/A BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 8352632Sstever@eecs.umich.edu BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 8365863Snate@binkert.org BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 8375342Sstever@gmail.com ) 8385863Snate@binkert.org 8392632Sstever@eecs.umich.edu# These variables get exported to #defines in config/*.hh (see src/SConscript). 8405863Snate@binkert.orgexport_vars += ['FULL_SYSTEM', 'USE_FENV', 8415863Snate@binkert.org 'NO_FAST_ALLOC', 'FORCE_FAST_ALLOC', 'FAST_ALLOC_STATS', 8422632Sstever@eecs.umich.edu 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE', 8435863Snate@binkert.org 'USE_POSIX_CLOCK' ] 8445863Snate@binkert.org 8455863Snate@binkert.org################################################### 8465863Snate@binkert.org# 8475863Snate@binkert.org# Define a SCons builder for configuration flag headers. 8485863Snate@binkert.org# 8492632Sstever@eecs.umich.edu################################################### 8505863Snate@binkert.org 8515863Snate@binkert.org# This function generates a config header file that #defines the 8522632Sstever@eecs.umich.edu# variable symbol to the current variable setting (0 or 1). The source 8531888SN/A# operands are the name of the variable and a Value node containing the 8545863Snate@binkert.org# value of the variable. 8555863Snate@binkert.orgdef build_config_file(target, source, env): 8565863Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 8571858SN/A f = file(str(target[0]), 'w') 8585863Snate@binkert.org print >> f, '#define', variable, value 8595863Snate@binkert.org f.close() 8605863Snate@binkert.org return None 8615863Snate@binkert.org 8622598SN/A# Combine the two functions into a scons Action object. 8635863Snate@binkert.orgconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 8641858SN/A 8651858SN/A# The emitter munges the source & target node lists to reflect what 8661858SN/A# we're really doing. 8675863Snate@binkert.orgdef config_emitter(target, source, env): 8681858SN/A # extract variable name from Builder arg 8691858SN/A variable = str(target[0]) 8701858SN/A # True target is config header file 8715863Snate@binkert.org target = joinpath('config', variable.lower() + '.hh') 8721871SN/A val = env[variable] 8731858SN/A if isinstance(val, bool): 8741858SN/A # Force value to 0/1 8751858SN/A val = int(val) 8761858SN/A elif isinstance(val, str): 8771858SN/A val = '"' + val + '"' 8781858SN/A 8791858SN/A # Sources are variable name & value (packaged in SCons Value nodes) 8805863Snate@binkert.org return ([target], [Value(variable), Value(val)]) 8811858SN/A 8821858SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action) 8835863Snate@binkert.org 8841859SN/Amain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 8851859SN/A 8861869SN/A# libelf build is shared across all configs in the build root. 8875863Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 8885863Snate@binkert.org variant_dir = joinpath(build_root, 'libelf')) 8891869SN/A 8901965SN/A# gzstream build is shared across all configs in the build root. 8911965SN/Amain.SConscript('ext/gzstream/SConscript', 8921965SN/A variant_dir = joinpath(build_root, 'gzstream')) 8932761Sstever@eecs.umich.edu 8945863Snate@binkert.org################################################### 8951869SN/A# 8965863Snate@binkert.org# This function is used to set up a directory with switching headers 8972667Sstever@eecs.umich.edu# 8981869SN/A################################################### 8991869SN/A 9002929Sktlim@umich.edumain['ALL_ISA_LIST'] = all_isa_list 9012929Sktlim@umich.edudef make_switching_dir(dname, switch_headers, env): 9025863Snate@binkert.org # Generate the header. target[0] is the full path of the output 9032929Sktlim@umich.edu # header to generate. 'source' is a dummy variable, since we get the 904955SN/A # list of ISAs from env['ALL_ISA_LIST']. 9052598SN/A def gen_switch_hdr(target, source, env): 906 fname = str(target[0]) 907 f = open(fname, 'w') 908 isa = env['TARGET_ISA'].lower() 909 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 910 f.close() 911 912 # Build SCons Action object. 'varlist' specifies env vars that this 913 # action depends on; when env['ALL_ISA_LIST'] changes these actions 914 # should get re-executed. 915 switch_hdr_action = MakeAction(gen_switch_hdr, 916 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 917 918 # Instantiate actions for each header 919 for hdr in switch_headers: 920 env.Command(hdr, [], switch_hdr_action) 921Export('make_switching_dir') 922 923################################################### 924# 925# Define build environments for selected configurations. 926# 927################################################### 928 929for variant_path in variant_paths: 930 print "Building in", variant_path 931 932 # Make a copy of the build-root environment to use for this config. 933 env = main.Clone() 934 env['BUILDDIR'] = variant_path 935 936 # variant_dir is the tail component of build path, and is used to 937 # determine the build parameters (e.g., 'ALPHA_SE') 938 (build_root, variant_dir) = splitpath(variant_path) 939 940 # Set env variables according to the build directory config. 941 sticky_vars.files = [] 942 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 943 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 944 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 945 current_vars_file = joinpath(build_root, 'variables', variant_dir) 946 if isfile(current_vars_file): 947 sticky_vars.files.append(current_vars_file) 948 print "Using saved variables file %s" % current_vars_file 949 else: 950 # Build dir-specific variables file doesn't exist. 951 952 # Make sure the directory is there so we can create it later 953 opt_dir = dirname(current_vars_file) 954 if not isdir(opt_dir): 955 mkdir(opt_dir) 956 957 # Get default build variables from source tree. Variables are 958 # normally determined by name of $VARIANT_DIR, but can be 959 # overridden by '--default=' arg on command line. 960 default = GetOption('default') 961 opts_dir = joinpath(main.root.abspath, 'build_opts') 962 if default: 963 default_vars_files = [joinpath(build_root, 'variables', default), 964 joinpath(opts_dir, default)] 965 else: 966 default_vars_files = [joinpath(opts_dir, variant_dir)] 967 existing_files = filter(isfile, default_vars_files) 968 if existing_files: 969 default_vars_file = existing_files[0] 970 sticky_vars.files.append(default_vars_file) 971 print "Variables file %s not found,\n using defaults in %s" \ 972 % (current_vars_file, default_vars_file) 973 else: 974 print "Error: cannot find variables file %s or " \ 975 "default file(s) %s" \ 976 % (current_vars_file, ' or '.join(default_vars_files)) 977 Exit(1) 978 979 # Apply current variable settings to env 980 sticky_vars.Update(env) 981 982 help_texts["local_vars"] += \ 983 "Build variables for %s:\n" % variant_dir \ 984 + sticky_vars.GenerateHelpText(env) 985 986 # Process variable settings. 987 988 if not have_fenv and env['USE_FENV']: 989 print "Warning: <fenv.h> not available; " \ 990 "forcing USE_FENV to False in", variant_dir + "." 991 env['USE_FENV'] = False 992 993 if not env['USE_FENV']: 994 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 995 print " FP results may deviate slightly from other platforms." 996 997 if env['EFENCE']: 998 env.Append(LIBS=['efence']) 999 1000 # Save sticky variable settings back to current variables file 1001 sticky_vars.Save(current_vars_file, env) 1002 1003 if env['USE_SSE2']: 1004 env.Append(CCFLAGS=['-msse2']) 1005 1006 # The src/SConscript file sets up the build rules in 'env' according 1007 # to the configured variables. It returns a list of environments, 1008 # one for each variant build (debug, opt, etc.) 1009 envList = SConscript('src/SConscript', variant_dir = variant_path, 1010 exports = 'env') 1011 1012 # Set up the regression tests for each build. 1013 for e in envList: 1014 SConscript('tests/SConscript', 1015 variant_dir = joinpath(variant_path, 'tests', e.Label), 1016 exports = { 'env' : e }, duplicate = False) 1017 1018# base help text 1019Help(''' 1020Usage: scons [scons options] [build variables] [target(s)] 1021 1022Extra scons options: 1023%(options)s 1024 1025Global build variables: 1026%(global_vars)s 1027 1028%(local_vars)s 1029''' % help_texts) 1030