SConstruct revision 8980
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2011 Advanced Micro Devices, Inc. 4955SN/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 282665Ssaidi@eecs.umich.edu# (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. 30955SN/A# 31955SN/A# Authors: Steve Reinhardt 32955SN/A# Nathan Binkert 33955SN/A 34955SN/A################################################### 352632Sstever@eecs.umich.edu# 362632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 372632Sstever@eecs.umich.edu# 382632Sstever@eecs.umich.edu# While in this directory ('gem5'), just type 'scons' to build the default 39955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 402632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 412632Sstever@eecs.umich.edu# the optimized full-system version). 422761Sstever@eecs.umich.edu# 432632Sstever@eecs.umich.edu# You can build gem5 in a different directory as long as there is a 442632Sstever@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 462761Sstever@eecs.umich.edu# built for the same host system. 472761Sstever@eecs.umich.edu# 482761Sstever@eecs.umich.edu# Examples: 492632Sstever@eecs.umich.edu# 502632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 512761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 522761Sstever@eecs.umich.edu# % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug 532761Sstever@eecs.umich.edu# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug 542761Sstever@eecs.umich.edu# 552761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 562632Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 572632Sstever@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>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 602632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug 612632Sstever@eecs.umich.edu# 622632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 63955SN/A# 'gem5' directory (or use -u or -C to tell scons where to find this 64955SN/A# file), you can use 'scons -h' to print all the gem5-specific build 65955SN/A# options as well. 66955SN/A# 67955SN/A################################################### 683918Ssaidi@eecs.umich.edu 694202Sbinkertn@umich.edu# Check for recent-enough Python and SCons versions. 704678Snate@binkert.orgtry: 71955SN/A # Really old versions of scons only take two options for the 722656Sstever@eecs.umich.edu # function, so check once without the revision and once with the 732656Sstever@eecs.umich.edu # revision, the first instance will fail for stuff other than 742656Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 752656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 762656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98, 1) 772656Sstever@eecs.umich.eduexcept SystemExit, e: 782656Sstever@eecs.umich.edu print """ 792653Sstever@eecs.umich.eduFor more details, see: 802653Sstever@eecs.umich.edu http://gem5.org/Dependencies 812653Sstever@eecs.umich.edu""" 822653Sstever@eecs.umich.edu raise 832653Sstever@eecs.umich.edu 842653Sstever@eecs.umich.edu# We ensure the python version early because we have stuff that 852653Sstever@eecs.umich.edu# requires python 2.4 862653Sstever@eecs.umich.edutry: 872653Sstever@eecs.umich.edu EnsurePythonVersion(2, 4) 882653Sstever@eecs.umich.eduexcept SystemExit, e: 892653Sstever@eecs.umich.edu print """ 901852SN/AYou can use a non-default installation of the Python interpreter by 91955SN/Aeither (1) rearranging your PATH so that scons finds the non-default 92955SN/A'python' first or (2) explicitly invoking an alternative interpreter 93955SN/Aon the scons script. 943717Sstever@eecs.umich.edu 953716Sstever@eecs.umich.eduFor more details, see: 96955SN/A http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 971533SN/A""" 983716Sstever@eecs.umich.edu raise 991533SN/A 1004678Snate@binkert.org# Global Python includes 1014678Snate@binkert.orgimport os 1024678Snate@binkert.orgimport re 1034678Snate@binkert.orgimport subprocess 1044678Snate@binkert.orgimport sys 1054678Snate@binkert.org 1064678Snate@binkert.orgfrom os import mkdir, environ 1074678Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1084678Snate@binkert.orgfrom os.path import exists, isdir, isfile 1094678Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1104678Snate@binkert.org 1114678Snate@binkert.org# SCons includes 1124678Snate@binkert.orgimport SCons 1134678Snate@binkert.orgimport SCons.Node 1144678Snate@binkert.org 1154678Snate@binkert.orgextra_python_paths = [ 1164678Snate@binkert.org Dir('src/python').srcnode().abspath, # gem5 includes 1174678Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1184678Snate@binkert.org ] 1194678Snate@binkert.org 1204678Snate@binkert.orgsys.path[1:1] = extra_python_paths 1214678Snate@binkert.org 1224678Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1234678Snate@binkert.orgfrom m5.util.terminal import get_termcap 1244678Snate@binkert.org 1254678Snate@binkert.orghelp_texts = { 1264678Snate@binkert.org "options" : "", 1274678Snate@binkert.org "global_vars" : "", 128955SN/A "local_vars" : "" 129955SN/A} 1302632Sstever@eecs.umich.edu 1312632Sstever@eecs.umich.eduExport("help_texts") 132955SN/A 133955SN/A 134955SN/A# There's a bug in scons in that (1) by default, the help texts from 135955SN/A# AddOption() are supposed to be displayed when you type 'scons -h' 1362632Sstever@eecs.umich.edu# and (2) you can override the help displayed by 'scons -h' using the 137955SN/A# Help() function, but these two features are incompatible: once 1382632Sstever@eecs.umich.edu# you've overridden the help text using Help(), there's no way to get 1392632Sstever@eecs.umich.edu# at the help texts from AddOptions. See: 1402632Sstever@eecs.umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1412632Sstever@eecs.umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1422632Sstever@eecs.umich.edu# This hack lets us extract the help text from AddOptions and 1432632Sstever@eecs.umich.edu# re-inject it via Help(). Ideally someday this bug will be fixed and 1442632Sstever@eecs.umich.edu# we can just use AddOption directly. 1453053Sstever@eecs.umich.edudef AddLocalOption(*args, **kwargs): 1463053Sstever@eecs.umich.edu col_width = 30 1473053Sstever@eecs.umich.edu 1483053Sstever@eecs.umich.edu help = " " + ", ".join(args) 1493053Sstever@eecs.umich.edu if "help" in kwargs: 1503053Sstever@eecs.umich.edu length = len(help) 1513053Sstever@eecs.umich.edu if length >= col_width: 1523053Sstever@eecs.umich.edu help += "\n" + " " * col_width 1533053Sstever@eecs.umich.edu else: 1543053Sstever@eecs.umich.edu help += " " * (col_width - length) 1553053Sstever@eecs.umich.edu help += kwargs["help"] 1563053Sstever@eecs.umich.edu help_texts["options"] += help + "\n" 1573053Sstever@eecs.umich.edu 1583053Sstever@eecs.umich.edu AddOption(*args, **kwargs) 1593053Sstever@eecs.umich.edu 1603053Sstever@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true', 1612632Sstever@eecs.umich.edu help="Add color to abbreviated scons output") 1622632Sstever@eecs.umich.eduAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1632632Sstever@eecs.umich.edu help="Don't add color to abbreviated scons output") 1642632Sstever@eecs.umich.eduAddLocalOption('--default', dest='default', type='string', action='store', 1652632Sstever@eecs.umich.edu help='Override which build_opts file to use for defaults') 1662632Sstever@eecs.umich.eduAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1673718Sstever@eecs.umich.edu help='Disable style checking hooks') 1683718Sstever@eecs.umich.eduAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1693718Sstever@eecs.umich.edu help='Update test reference outputs') 1703718Sstever@eecs.umich.eduAddLocalOption('--verbose', dest='verbose', action='store_true', 1713718Sstever@eecs.umich.edu help='Print full tool command lines') 1723718Sstever@eecs.umich.edu 1733718Sstever@eecs.umich.edutermcap = get_termcap(GetOption('use_colors')) 1743718Sstever@eecs.umich.edu 1753718Sstever@eecs.umich.edu######################################################################## 1763718Sstever@eecs.umich.edu# 1773718Sstever@eecs.umich.edu# Set up the main build environment. 1783718Sstever@eecs.umich.edu# 1793718Sstever@eecs.umich.edu######################################################################## 1802634Sstever@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1812634Sstever@eecs.umich.edu 'PYTHONPATH', 'RANLIB', 'SWIG' ]) 1822632Sstever@eecs.umich.edu 1832638Sstever@eecs.umich.eduuse_env = {} 1842632Sstever@eecs.umich.edufor key,val in os.environ.iteritems(): 1852632Sstever@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1862632Sstever@eecs.umich.edu use_env[key] = val 1872632Sstever@eecs.umich.edu 1882632Sstever@eecs.umich.edumain = Environment(ENV=use_env) 1892632Sstever@eecs.umich.edumain.Decider('MD5-timestamp') 1901858SN/Amain.root = Dir(".") # The current directory (where this file lives). 1913716Sstever@eecs.umich.edumain.srcdir = Dir("src") # The source directory 1922638Sstever@eecs.umich.edu 1932638Sstever@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 1942638Sstever@eecs.umich.edu# as well 1952638Sstever@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths) 1962638Sstever@eecs.umich.edu 1972638Sstever@eecs.umich.edu######################################################################## 1982638Sstever@eecs.umich.edu# 1993716Sstever@eecs.umich.edu# Mercurial Stuff. 2002634Sstever@eecs.umich.edu# 2012634Sstever@eecs.umich.edu# If the gem5 directory is a mercurial repository, we should do some 202955SN/A# extra things. 203955SN/A# 204955SN/A######################################################################## 205955SN/A 206955SN/Ahgdir = main.root.Dir(".hg") 207955SN/A 208955SN/Amercurial_style_message = """ 209955SN/AYou're missing the gem5 style hook, which automatically checks your code 2101858SN/Aagainst the gem5 style rules on hg commit and qrefresh commands. This 2111858SN/Ascript will now install the hook in your .hg/hgrc file. 2122632Sstever@eecs.umich.eduPress enter to continue, or ctrl-c to abort: """ 213955SN/A 2143643Ssaidi@eecs.umich.edumercurial_style_hook = """ 2153643Ssaidi@eecs.umich.edu# The following lines were automatically added by gem5/SConstruct 2163643Ssaidi@eecs.umich.edu# to provide the gem5 style-checking hooks 2173643Ssaidi@eecs.umich.edu[extensions] 2183643Ssaidi@eecs.umich.edustyle = %s/util/style.py 2193643Ssaidi@eecs.umich.edu 2203643Ssaidi@eecs.umich.edu[hooks] 2213643Ssaidi@eecs.umich.edupretxncommit.style = python:style.check_style 2224494Ssaidi@eecs.umich.edupre-qrefresh.style = python:style.check_style 2234494Ssaidi@eecs.umich.edu# End of SConstruct additions 2243716Sstever@eecs.umich.edu 2251105SN/A""" % (main.root.abspath) 2262667Sstever@eecs.umich.edu 2272667Sstever@eecs.umich.edumercurial_lib_not_found = """ 2282667Sstever@eecs.umich.eduMercurial libraries cannot be found, ignoring style hook. If 2292667Sstever@eecs.umich.eduyou are a gem5 developer, please fix this and run the style 2302667Sstever@eecs.umich.eduhook. It is important. 2312667Sstever@eecs.umich.edu""" 2321869SN/A 2331869SN/A# Check for style hook and prompt for installation if it's not there. 2341869SN/A# Skip this if --ignore-style was specified, there's no .hg dir to 2351869SN/A# install a hook in, or there's no interactive terminal to prompt. 2361869SN/Aif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2371065SN/A style_hook = True 2382632Sstever@eecs.umich.edu try: 2392632Sstever@eecs.umich.edu from mercurial import ui 2403918Ssaidi@eecs.umich.edu ui = ui.ui() 2413918Ssaidi@eecs.umich.edu ui.readconfig(hgdir.File('hgrc').abspath) 2423940Ssaidi@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2433918Ssaidi@eecs.umich.edu ui.config('hooks', 'pre-qrefresh.style', None) 2443918Ssaidi@eecs.umich.edu except ImportError: 2453918Ssaidi@eecs.umich.edu print mercurial_lib_not_found 2463918Ssaidi@eecs.umich.edu 2473918Ssaidi@eecs.umich.edu if not style_hook: 2483918Ssaidi@eecs.umich.edu print mercurial_style_message, 2493940Ssaidi@eecs.umich.edu # continue unless user does ctrl-c/ctrl-d etc. 2503940Ssaidi@eecs.umich.edu try: 2513940Ssaidi@eecs.umich.edu raw_input() 2523942Ssaidi@eecs.umich.edu except: 2533940Ssaidi@eecs.umich.edu print "Input exception, exiting scons.\n" 2543918Ssaidi@eecs.umich.edu sys.exit(1) 2553918Ssaidi@eecs.umich.edu hgrc_path = '%s/.hg/hgrc' % main.root.abspath 256955SN/A print "Adding style hook to", hgrc_path, "\n" 2571858SN/A try: 2583918Ssaidi@eecs.umich.edu hgrc = open(hgrc_path, 'a') 2593918Ssaidi@eecs.umich.edu hgrc.write(mercurial_style_hook) 2603918Ssaidi@eecs.umich.edu hgrc.close() 2613918Ssaidi@eecs.umich.edu except: 2623940Ssaidi@eecs.umich.edu print "Error updating", hgrc_path 2633940Ssaidi@eecs.umich.edu sys.exit(1) 2643918Ssaidi@eecs.umich.edu 2653918Ssaidi@eecs.umich.edu 2663918Ssaidi@eecs.umich.edu################################################### 2673918Ssaidi@eecs.umich.edu# 2683918Ssaidi@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2693918Ssaidi@eecs.umich.edu# the target(s). 2703918Ssaidi@eecs.umich.edu# 2713918Ssaidi@eecs.umich.edu################################################### 2723918Ssaidi@eecs.umich.edu 2733940Ssaidi@eecs.umich.edu# Find default configuration & binary. 2743918Ssaidi@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2753918Ssaidi@eecs.umich.edu 2761851SN/A# helper function: find last occurrence of element in list 2771851SN/Adef rfind(l, elt, offs = -1): 2781858SN/A for i in range(len(l)+offs, 0, -1): 2792632Sstever@eecs.umich.edu if l[i] == elt: 280955SN/A return i 2813053Sstever@eecs.umich.edu raise ValueError, "element not found" 2823053Sstever@eecs.umich.edu 2833053Sstever@eecs.umich.edu# Take a list of paths (or SCons Nodes) and return a list with all 2843053Sstever@eecs.umich.edu# paths made absolute and ~-expanded. Paths will be interpreted 2853053Sstever@eecs.umich.edu# relative to the launch directory unless a different root is provided 2863053Sstever@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 2873053Sstever@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 2883053Sstever@eecs.umich.edu for p in path_list] 2893053Sstever@eecs.umich.edu 2904742Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2914742Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2923053Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2933053Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 2943053Sstever@eecs.umich.edu# follow 'build' in the build path. 2953053Sstever@eecs.umich.edu 2963053Sstever@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 2973053Sstever@eecs.umich.edu# in place rather than reassign the symbol to a new list, which 2983053Sstever@eecs.umich.edu# doesn't work (obviously!). 2993053Sstever@eecs.umich.eduBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 3003053Sstever@eecs.umich.edu 3012667Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 3024554Sbinkertn@umich.edu# collected targets reference. 3034554Sbinkertn@umich.eduvariant_paths = [] 3042667Sstever@eecs.umich.edubuild_root = None 3054554Sbinkertn@umich.edufor t in BUILD_TARGETS: 3064554Sbinkertn@umich.edu path_dirs = t.split('/') 3074554Sbinkertn@umich.edu try: 3084554Sbinkertn@umich.edu build_top = rfind(path_dirs, 'build', -2) 3094554Sbinkertn@umich.edu except: 3104554Sbinkertn@umich.edu print "Error: no non-leaf 'build' dir found on target path", t 3114554Sbinkertn@umich.edu Exit(1) 3124554Sbinkertn@umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3134554Sbinkertn@umich.edu if not build_root: 3144554Sbinkertn@umich.edu build_root = this_build_root 3152667Sstever@eecs.umich.edu else: 3164554Sbinkertn@umich.edu if this_build_root != build_root: 3174554Sbinkertn@umich.edu print "Error: build targets not under same build root\n"\ 3184554Sbinkertn@umich.edu " %s\n %s" % (build_root, this_build_root) 3194554Sbinkertn@umich.edu Exit(1) 3202667Sstever@eecs.umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 3214554Sbinkertn@umich.edu if variant_path not in variant_paths: 3222667Sstever@eecs.umich.edu variant_paths.append(variant_path) 3234554Sbinkertn@umich.edu 3244554Sbinkertn@umich.edu# Make sure build_root exists (might not if this is the first build there) 3252667Sstever@eecs.umich.eduif not isdir(build_root): 3262638Sstever@eecs.umich.edu mkdir(build_root) 3272638Sstever@eecs.umich.edumain['BUILDROOT'] = build_root 3282638Sstever@eecs.umich.edu 3293716Sstever@eecs.umich.eduExport('main') 3303716Sstever@eecs.umich.edu 3311858SN/Amain.SConsignFile(joinpath(build_root, "sconsign")) 3323118Sstever@eecs.umich.edu 3333118Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 3343118Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 3353118Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 3363118Sstever@eecs.umich.edu# (soft) links work better. 3373118Sstever@eecs.umich.edumain.SetOption('duplicate', 'soft-copy') 3383118Sstever@eecs.umich.edu 3393118Sstever@eecs.umich.edu# 3403118Sstever@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 3413118Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 3423118Sstever@eecs.umich.edu# 3433716Sstever@eecs.umich.edu 3443118Sstever@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 3453118Sstever@eecs.umich.edu 3463118Sstever@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3473118Sstever@eecs.umich.edu 3483118Sstever@eecs.umich.eduglobal_vars.AddVariables( 3493118Sstever@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3503118Sstever@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3513118Sstever@eecs.umich.edu ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 3523118Sstever@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3533716Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3543118Sstever@eecs.umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3553118Sstever@eecs.umich.edu ('EXTRAS', 'Add extra directories to the compilation', '') 3563118Sstever@eecs.umich.edu ) 3573118Sstever@eecs.umich.edu 3583118Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_vars_file 3593118Sstever@eecs.umich.eduglobal_vars.Update(main) 3603118Sstever@eecs.umich.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3613118Sstever@eecs.umich.edu 3623118Sstever@eecs.umich.edu# Save sticky variable settings back to current variables file 3633118Sstever@eecs.umich.eduglobal_vars.Save(global_vars_file, main) 3643483Ssaidi@eecs.umich.edu 3653494Ssaidi@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3663494Ssaidi@eecs.umich.edu# look for sources etc. This list is exported as extras_dir_list. 3673483Ssaidi@eecs.umich.edubase_dir = main.srcdir.abspath 3683483Ssaidi@eecs.umich.eduif main['EXTRAS']: 3693483Ssaidi@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3703053Sstever@eecs.umich.eduelse: 3713053Sstever@eecs.umich.edu extras_dir_list = [] 3723918Ssaidi@eecs.umich.edu 3733053Sstever@eecs.umich.eduExport('base_dir') 3743053Sstever@eecs.umich.eduExport('extras_dir_list') 3753053Sstever@eecs.umich.edu 3763053Sstever@eecs.umich.edu# the ext directory should be on the #includes path 3773053Sstever@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3781858SN/A 3791858SN/Adef strip_build_path(path, env): 3801858SN/A path = str(path) 3811858SN/A variant_base = env['BUILDROOT'] + os.path.sep 3821858SN/A if path.startswith(variant_base): 3831858SN/A path = path[len(variant_base):] 3841859SN/A elif path.startswith('build/'): 3851858SN/A path = path[6:] 3861858SN/A return path 3871858SN/A 3881859SN/A# Generate a string of the form: 3891859SN/A# common/path/prefix/src1, src2 -> tgt1, tgt2 3901862SN/A# to print while building. 3913053Sstever@eecs.umich.educlass Transform(object): 3923053Sstever@eecs.umich.edu # all specific color settings should be here and nowhere else 3933053Sstever@eecs.umich.edu tool_color = termcap.Normal 3943053Sstever@eecs.umich.edu pfx_color = termcap.Yellow 3951859SN/A srcs_color = termcap.Yellow + termcap.Bold 3961859SN/A arrow_color = termcap.Blue + termcap.Bold 3971859SN/A tgts_color = termcap.Yellow + termcap.Bold 3981859SN/A 3991859SN/A def __init__(self, tool, max_sources=99): 4001859SN/A self.format = self.tool_color + (" [%8s] " % tool) \ 4011859SN/A + self.pfx_color + "%s" \ 4021859SN/A + self.srcs_color + "%s" \ 4031862SN/A + self.arrow_color + " -> " \ 4041859SN/A + self.tgts_color + "%s" \ 4051859SN/A + termcap.Normal 4061859SN/A self.max_sources = max_sources 4071858SN/A 4081858SN/A def __call__(self, target, source, env, for_signature=None): 4092139SN/A # truncate source list according to max_sources param 4104202Sbinkertn@umich.edu source = source[0:self.max_sources] 4114202Sbinkertn@umich.edu def strip(f): 4122139SN/A return strip_build_path(str(f), env) 4132155SN/A if len(source) > 0: 4144202Sbinkertn@umich.edu srcs = map(strip, source) 4154202Sbinkertn@umich.edu else: 4164202Sbinkertn@umich.edu srcs = [''] 4172155SN/A tgts = map(strip, target) 4181869SN/A # surprisingly, os.path.commonprefix is a dumb char-by-char string 4191869SN/A # operation that has nothing to do with paths. 4201869SN/A com_pfx = os.path.commonprefix(srcs + tgts) 4211869SN/A com_pfx_len = len(com_pfx) 4224202Sbinkertn@umich.edu if com_pfx: 4234202Sbinkertn@umich.edu # do some cleanup and sanity checking on common prefix 4244202Sbinkertn@umich.edu if com_pfx[-1] == ".": 4254202Sbinkertn@umich.edu # prefix matches all but file extension: ok 4264202Sbinkertn@umich.edu # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4274202Sbinkertn@umich.edu com_pfx = com_pfx[0:-1] 4284202Sbinkertn@umich.edu elif com_pfx[-1] == "/": 4294202Sbinkertn@umich.edu # common prefix is directory path: OK 4304202Sbinkertn@umich.edu pass 4314202Sbinkertn@umich.edu else: 4324202Sbinkertn@umich.edu src0_len = len(srcs[0]) 4334202Sbinkertn@umich.edu tgt0_len = len(tgts[0]) 4344202Sbinkertn@umich.edu if src0_len == com_pfx_len: 4354202Sbinkertn@umich.edu # source is a substring of target, OK 4364202Sbinkertn@umich.edu pass 4374202Sbinkertn@umich.edu elif tgt0_len == com_pfx_len: 4384773Snate@binkert.org # target is a substring of source, need to back up to 4394773Snate@binkert.org # avoid empty string on RHS of arrow 4404773Snate@binkert.org sep_idx = com_pfx.rfind(".") 4414773Snate@binkert.org if sep_idx != -1: 4424773Snate@binkert.org com_pfx = com_pfx[0:sep_idx] 4434773Snate@binkert.org else: 4444773Snate@binkert.org com_pfx = '' 4451869SN/A elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4464202Sbinkertn@umich.edu # still splitting at file extension: ok 4471869SN/A pass 4482508SN/A else: 4492508SN/A # probably a fluke; ignore it 4502508SN/A com_pfx = '' 4512508SN/A # recalculate length in case com_pfx was modified 4524202Sbinkertn@umich.edu com_pfx_len = len(com_pfx) 4531869SN/A def fmt(files): 4541869SN/A f = map(lambda s: s[com_pfx_len:], files) 4551869SN/A return ', '.join(f) 4561869SN/A return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4571869SN/A 4581869SN/AExport('Transform') 4591965SN/A 4601965SN/A# enable the regression script to use the termcap 4611965SN/Amain['TERMCAP'] = termcap 4621869SN/A 4631869SN/Aif GetOption('verbose'): 4642733Sktlim@umich.edu def MakeAction(action, string, *args, **kwargs): 4651869SN/A return Action(action, *args, **kwargs) 4661884SN/Aelse: 4671884SN/A MakeAction = Action 4683356Sbinkertn@umich.edu main['CCCOMSTR'] = Transform("CC") 4693356Sbinkertn@umich.edu main['CXXCOMSTR'] = Transform("CXX") 4703356Sbinkertn@umich.edu main['ASCOMSTR'] = Transform("AS") 4714773Snate@binkert.org main['SWIGCOMSTR'] = Transform("SWIG") 4724773Snate@binkert.org main['ARCOMSTR'] = Transform("AR", 0) 4734773Snate@binkert.org main['LINKCOMSTR'] = Transform("LINK", 0) 4741869SN/A main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4751858SN/A main['M4COMSTR'] = Transform("M4") 4761869SN/A main['SHCCCOMSTR'] = Transform("SHCC") 4771869SN/A main['SHCXXCOMSTR'] = Transform("SHCXX") 4781869SN/AExport('MakeAction') 4791858SN/A 4802761Sstever@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4811869SN/ACXX_V = readCommand([main['CXX'],'-V'], exception=False) 4822733Sktlim@umich.edu 4833584Ssaidi@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4841869SN/Amain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4851869SN/Amain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4861869SN/Amain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 4871869SN/Aif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: 4881869SN/A print 'Error: How can we have two at the same time?' 4891869SN/A Exit(1) 4901858SN/A 491955SN/A# Set up default C++ compiler flags 492955SN/Aif main['GCC']: 4931869SN/A main.Append(CCFLAGS=['-pipe']) 4941869SN/A main.Append(CCFLAGS=['-fno-strict-aliasing']) 4951869SN/A main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4961869SN/A # Read the GCC version to check for versions with bugs 4971869SN/A # Note CCVERSION doesn't work here because it is run with the CC 4981869SN/A # before we override it from the command line 4991869SN/A gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5001869SN/A main['GCC_VERSION'] = gcc_version 5011869SN/A if not compareVersions(gcc_version, '4.4.1') or \ 5021869SN/A not compareVersions(gcc_version, '4.4.2'): 5031869SN/A print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5041869SN/A main.Append(CCFLAGS=['-fno-tree-vectorize']) 5051869SN/A if compareVersions(gcc_version, '4.6') >= 0: 5061869SN/A main.Append(CXXFLAGS=['-std=c++0x']) 5071869SN/Aelif main['ICC']: 5081869SN/A pass #Fix me... add warning flags once we clean up icc warnings 5091869SN/Aelif main['SUNCC']: 5101869SN/A main.Append(CCFLAGS=['-Qoption ccfe']) 5111869SN/A main.Append(CCFLAGS=['-features=gcc']) 5121869SN/A main.Append(CCFLAGS=['-features=extensions']) 5131869SN/A main.Append(CCFLAGS=['-library=stlport4']) 5141869SN/A main.Append(CCFLAGS=['-xar']) 5151869SN/A #main.Append(CCFLAGS=['-instances=semiexplicit']) 5161869SN/Aelif main['CLANG']: 5171869SN/A clang_version_re = re.compile(".* version (\d+\.\d+)") 5181869SN/A clang_version_match = clang_version_re.match(CXX_version) 5191869SN/A if (clang_version_match): 5201869SN/A clang_version = clang_version_match.groups()[0] 5211869SN/A if compareVersions(clang_version, "2.9") < 0: 5223716Sstever@eecs.umich.edu print 'Error: clang version 2.9 or newer required.' 5233356Sbinkertn@umich.edu print ' Installed version:', clang_version 5243356Sbinkertn@umich.edu Exit(1) 5253356Sbinkertn@umich.edu else: 5263356Sbinkertn@umich.edu print 'Error: Unable to determine clang version.' 5273356Sbinkertn@umich.edu Exit(1) 5283356Sbinkertn@umich.edu 5293356Sbinkertn@umich.edu main.Append(CCFLAGS=['-pipe']) 5301869SN/A main.Append(CCFLAGS=['-fno-strict-aliasing']) 5311869SN/A main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5321869SN/A main.Append(CCFLAGS=['-Wno-tautological-compare']) 5331869SN/A main.Append(CCFLAGS=['-Wno-self-assign']) 5341869SN/A # Ruby makes frequent use of extraneous parantheses in the printing 5351869SN/A # of if-statements 5361869SN/A main.Append(CCFLAGS=['-Wno-parentheses']) 5372655Sstever@eecs.umich.edu 5382655Sstever@eecs.umich.edu if compareVersions(clang_version, "3") >= 0: 5392655Sstever@eecs.umich.edu main.Append(CXXFLAGS=['-std=c++0x']) 5402655Sstever@eecs.umich.eduelse: 5412655Sstever@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 5422655Sstever@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 5432655Sstever@eecs.umich.edu Exit(1) 5442655Sstever@eecs.umich.edu 5452655Sstever@eecs.umich.edu# Set up common yacc/bison flags (needed for Ruby) 5462655Sstever@eecs.umich.edumain['YACCFLAGS'] = '-d' 5472655Sstever@eecs.umich.edumain['YACCHXXFILESUFFIX'] = '.hh' 5482655Sstever@eecs.umich.edu 5492655Sstever@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 5502655Sstever@eecs.umich.edu# extra 'qdo' every time we run scons. 5512655Sstever@eecs.umich.eduif main['BATCH']: 5522655Sstever@eecs.umich.edu main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5532655Sstever@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5542655Sstever@eecs.umich.edu main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5552655Sstever@eecs.umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5562655Sstever@eecs.umich.edu main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5572655Sstever@eecs.umich.edu 5582655Sstever@eecs.umich.eduif sys.platform == 'cygwin': 5592655Sstever@eecs.umich.edu # cygwin has some header file issues... 5602655Sstever@eecs.umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 5612655Sstever@eecs.umich.edu 5622655Sstever@eecs.umich.edu# Check for SWIG 5632634Sstever@eecs.umich.eduif not main.has_key('SWIG'): 5642634Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 5652634Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 5662634Sstever@eecs.umich.edu Exit(1) 5672634Sstever@eecs.umich.edu 5682634Sstever@eecs.umich.edu# Check for appropriate SWIG version 5692638Sstever@eecs.umich.eduswig_version = readCommand(('swig', '-version'), exception='').split() 5702638Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 5713716Sstever@eecs.umich.eduif len(swig_version) < 3 or \ 5722638Sstever@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5732638Sstever@eecs.umich.edu print 'Error determining SWIG version.' 5741869SN/A Exit(1) 5751869SN/A 5763546Sgblack@eecs.umich.edumin_swig_version = '1.3.34' 5773546Sgblack@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0: 5783546Sgblack@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 5793546Sgblack@eecs.umich.edu print ' Installed version:', swig_version[2] 5804202Sbinkertn@umich.edu Exit(1) 5813546Sgblack@eecs.umich.edu 5823546Sgblack@eecs.umich.edu# Set up SWIG flags & scanner 5833546Sgblack@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5843546Sgblack@eecs.umich.edumain.Append(SWIGFLAGS=swig_flags) 5853546Sgblack@eecs.umich.edu 5863546Sgblack@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 5873546Sgblack@eecs.umich.edu# stuff for some reason 5883546Sgblack@eecs.umich.eduscanners = [] 5893546Sgblack@eecs.umich.edufor scanner in main['SCANNERS']: 5903546Sgblack@eecs.umich.edu skeys = scanner.skeys 5914202Sbinkertn@umich.edu if skeys == '.i': 5923546Sgblack@eecs.umich.edu continue 5933546Sgblack@eecs.umich.edu 5943546Sgblack@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5953546Sgblack@eecs.umich.edu continue 5963546Sgblack@eecs.umich.edu 5973546Sgblack@eecs.umich.edu scanners.append(scanner) 5983546Sgblack@eecs.umich.edu 5993546Sgblack@eecs.umich.edu# add the new swig scanner that we like better 6003546Sgblack@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 6013546Sgblack@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 6023546Sgblack@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 6033546Sgblack@eecs.umich.edu 6043546Sgblack@eecs.umich.edu# replace the scanners list that has what we want 6053546Sgblack@eecs.umich.edumain['SCANNERS'] = scanners 6063546Sgblack@eecs.umich.edu 6073546Sgblack@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 6083546Sgblack@eecs.umich.edu# figure out if the compiler adds leading underscores to global 6093546Sgblack@eecs.umich.edu# variables. This is needed for the autogenerated asm files that we 6103546Sgblack@eecs.umich.edu# use for embedding the python code. 6113546Sgblack@eecs.umich.edudef CheckLeading(context): 6124202Sbinkertn@umich.edu context.Message("Checking for leading underscore in global variables...") 6133546Sgblack@eecs.umich.edu # 1) Define a global variable called x from asm so the C compiler 6143546Sgblack@eecs.umich.edu # won't change the symbol at all. 6153546Sgblack@eecs.umich.edu # 2) Declare that variable. 616955SN/A # 3) Use the variable 617955SN/A # 618955SN/A # If the compiler prepends an underscore, this will successfully 619955SN/A # link because the external symbol 'x' will be called '_x' which 6201858SN/A # was defined by the asm statement. If the compiler does not 6211858SN/A # prepend an underscore, this will not successfully link because 6221858SN/A # '_x' will have been defined by assembly, while the C portion of 6232632Sstever@eecs.umich.edu # the code will be trying to use 'x' 6242632Sstever@eecs.umich.edu ret = context.TryLink(''' 6254773Snate@binkert.org asm(".globl _x; _x: .byte 0"); 6264773Snate@binkert.org extern int x; 6272632Sstever@eecs.umich.edu int main() { return x; } 6282632Sstever@eecs.umich.edu ''', extension=".c") 6292632Sstever@eecs.umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 6302634Sstever@eecs.umich.edu context.Result(ret) 6312638Sstever@eecs.umich.edu return ret 6322023SN/A 6332632Sstever@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 6342632Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 6352632Sstever@eecs.umich.educonf = Configure(main, 6362632Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 6372632Sstever@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 6383716Sstever@eecs.umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 6392632Sstever@eecs.umich.edu 6402632Sstever@eecs.umich.edu# Check for leading underscores. Don't really need to worry either 6412632Sstever@eecs.umich.edu# way so don't need to check the return code. 6422632Sstever@eecs.umich.educonf.CheckLeading() 6432632Sstever@eecs.umich.edu 6442023SN/A# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6452632Sstever@eecs.umich.edutry: 6462632Sstever@eecs.umich.edu import platform 6471889SN/A uname = platform.uname() 6481889SN/A if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6492632Sstever@eecs.umich.edu if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6502632Sstever@eecs.umich.edu main.Append(CCFLAGS=['-arch', 'x86_64']) 6512632Sstever@eecs.umich.edu main.Append(CFLAGS=['-arch', 'x86_64']) 6522632Sstever@eecs.umich.edu main.Append(LINKFLAGS=['-arch', 'x86_64']) 6533716Sstever@eecs.umich.edu main.Append(ASFLAGS=['-arch', 'x86_64']) 6543716Sstever@eecs.umich.eduexcept: 6552632Sstever@eecs.umich.edu pass 6562632Sstever@eecs.umich.edu 6572632Sstever@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 6582632Sstever@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 6592632Sstever@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 6602632Sstever@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 6612632Sstever@eecs.umich.edu# more optimistic null object that returns True instead. 6622632Sstever@eecs.umich.eduif not conf: 6631888SN/A def NullCheck(*args, **kwargs): 6641888SN/A return True 6651869SN/A 6661869SN/A class NullConf: 6671858SN/A def __init__(self, env): 6682598SN/A self.env = env 6692598SN/A def Finish(self): 6702598SN/A return self.env 6712598SN/A def __getattr__(self, mname): 6722598SN/A return NullCheck 6731858SN/A 6741858SN/A conf = NullConf(main) 6751858SN/A 6761858SN/A# Find Python include and library directories for embedding the 6771858SN/A# interpreter. For consistency, we will use the same Python 6781858SN/A# installation used to run scons (and thus this script). If you want 6791858SN/A# to link in an alternate version, see above for instructions on how 6801858SN/A# to invoke scons with a different copy of the Python interpreter. 6811858SN/Afrom distutils import sysconfig 6821871SN/A 6831858SN/Apy_getvar = sysconfig.get_config_var 6841858SN/A 6851858SN/Apy_debug = getattr(sys, 'pydebug', False) 6861858SN/Apy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6871858SN/A 6881858SN/Apy_general_include = sysconfig.get_python_inc() 6891858SN/Apy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6901858SN/Apy_includes = [ py_general_include ] 6911858SN/Aif py_platform_include != py_general_include: 6921858SN/A py_includes.append(py_platform_include) 6931858SN/A 6941859SN/Apy_lib_path = [ py_getvar('LIBDIR') ] 6951859SN/A# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6961869SN/A# shared library in prefix/lib/. 6971888SN/Aif not py_getvar('Py_ENABLE_SHARED'): 6982632Sstever@eecs.umich.edu py_lib_path.append(py_getvar('LIBPL')) 6991869SN/A 7001884SN/Apy_libs = [] 7011884SN/Afor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 7021884SN/A if not lib.startswith('-l'): 7031884SN/A # Python requires some special flags to link (e.g. -framework 7041884SN/A # common on OS X systems), assume appending preserves order 7051884SN/A main.Append(LINKFLAGS=[lib]) 7061965SN/A else: 7071965SN/A lib = lib[2:] 7081965SN/A if lib not in py_libs: 7092761Sstever@eecs.umich.edu py_libs.append(lib) 7101869SN/Apy_libs.append(py_version) 7111869SN/A 7122632Sstever@eecs.umich.edumain.Append(CPPPATH=py_includes) 7132667Sstever@eecs.umich.edumain.Append(LIBPATH=py_lib_path) 7141869SN/A 7151869SN/A# Cache build files in the supplied directory. 7162929Sktlim@umich.eduif main['M5_BUILD_CACHE']: 7172929Sktlim@umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 7183716Sstever@eecs.umich.edu CacheDir(main['M5_BUILD_CACHE']) 7192929Sktlim@umich.edu 720955SN/A 7212598SN/A# verify that this stuff works 7222598SN/Aif not conf.CheckHeader('Python.h', '<>'): 7233546Sgblack@eecs.umich.edu print "Error: can't find Python.h header in", py_includes 724955SN/A Exit(1) 725955SN/A 726955SN/Afor lib in py_libs: 7271530SN/A if not conf.CheckLib(lib): 728955SN/A print "Error: can't find library %s required by python" % lib 729955SN/A Exit(1) 730955SN/A 731# On Solaris you need to use libsocket for socket ops 732if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 733 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 734 print "Can't find library with socket calls (e.g. accept())" 735 Exit(1) 736 737# Check for zlib. If the check passes, libz will be automatically 738# added to the LIBS environment variable. 739if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 740 print 'Error: did not find needed zlib compression library '\ 741 'and/or zlib.h header file.' 742 print ' Please install zlib and try again.' 743 Exit(1) 744 745# Check for librt. 746have_posix_clock = \ 747 conf.CheckLibWithHeader(None, 'time.h', 'C', 748 'clock_nanosleep(0,0,NULL,NULL);') or \ 749 conf.CheckLibWithHeader('rt', 'time.h', 'C', 750 'clock_nanosleep(0,0,NULL,NULL);') 751 752if not have_posix_clock: 753 print "Can't find library for POSIX clocks." 754 755# Check for <fenv.h> (C99 FP environment control) 756have_fenv = conf.CheckHeader('fenv.h', '<>') 757if not have_fenv: 758 print "Warning: Header file <fenv.h> not found." 759 print " This host has no IEEE FP rounding mode control." 760 761###################################################################### 762# 763# Finish the configuration 764# 765main = conf.Finish() 766 767###################################################################### 768# 769# Collect all non-global variables 770# 771 772# Define the universe of supported ISAs 773all_isa_list = [ ] 774Export('all_isa_list') 775 776class CpuModel(object): 777 '''The CpuModel class encapsulates everything the ISA parser needs to 778 know about a particular CPU model.''' 779 780 # Dict of available CPU model objects. Accessible as CpuModel.dict. 781 dict = {} 782 list = [] 783 defaults = [] 784 785 # Constructor. Automatically adds models to CpuModel.dict. 786 def __init__(self, name, filename, includes, strings, default=False): 787 self.name = name # name of model 788 self.filename = filename # filename for output exec code 789 self.includes = includes # include files needed in exec file 790 # The 'strings' dict holds all the per-CPU symbols we can 791 # substitute into templates etc. 792 self.strings = strings 793 794 # This cpu is enabled by default 795 self.default = default 796 797 # Add self to dict 798 if name in CpuModel.dict: 799 raise AttributeError, "CpuModel '%s' already registered" % name 800 CpuModel.dict[name] = self 801 CpuModel.list.append(name) 802 803Export('CpuModel') 804 805# Sticky variables get saved in the variables file so they persist from 806# one invocation to the next (unless overridden, in which case the new 807# value becomes sticky). 808sticky_vars = Variables(args=ARGUMENTS) 809Export('sticky_vars') 810 811# Sticky variables that should be exported 812export_vars = [] 813Export('export_vars') 814 815# Walk the tree and execute all SConsopts scripts that wil add to the 816# above variables 817if not GetOption('verbose'): 818 print "Reading SConsopts" 819for bdir in [ base_dir ] + extras_dir_list: 820 if not isdir(bdir): 821 print "Error: directory '%s' does not exist" % bdir 822 Exit(1) 823 for root, dirs, files in os.walk(bdir): 824 if 'SConsopts' in files: 825 if GetOption('verbose'): 826 print "Reading", joinpath(root, 'SConsopts') 827 SConscript(joinpath(root, 'SConsopts')) 828 829all_isa_list.sort() 830 831sticky_vars.AddVariables( 832 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 833 ListVariable('CPU_MODELS', 'CPU models', 834 sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 835 sorted(CpuModel.list)), 836 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 837 BoolVariable('FORCE_FAST_ALLOC', 838 'Enable fast object allocator, even for gem5.debug', False), 839 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 840 False), 841 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 842 False), 843 BoolVariable('SS_COMPATIBLE_FP', 844 'Make floating-point results compatible with SimpleScalar', 845 False), 846 BoolVariable('USE_SSE2', 847 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 848 False), 849 BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 850 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 851 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 852 ) 853 854# These variables get exported to #defines in config/*.hh (see src/SConscript). 855export_vars += ['USE_FENV', 'NO_FAST_ALLOC', 'FORCE_FAST_ALLOC', 856 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', 857 'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK' ] 858 859################################################### 860# 861# Define a SCons builder for configuration flag headers. 862# 863################################################### 864 865# This function generates a config header file that #defines the 866# variable symbol to the current variable setting (0 or 1). The source 867# operands are the name of the variable and a Value node containing the 868# value of the variable. 869def build_config_file(target, source, env): 870 (variable, value) = [s.get_contents() for s in source] 871 f = file(str(target[0]), 'w') 872 print >> f, '#define', variable, value 873 f.close() 874 return None 875 876# Combine the two functions into a scons Action object. 877config_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 878 879# The emitter munges the source & target node lists to reflect what 880# we're really doing. 881def config_emitter(target, source, env): 882 # extract variable name from Builder arg 883 variable = str(target[0]) 884 # True target is config header file 885 target = joinpath('config', variable.lower() + '.hh') 886 val = env[variable] 887 if isinstance(val, bool): 888 # Force value to 0/1 889 val = int(val) 890 elif isinstance(val, str): 891 val = '"' + val + '"' 892 893 # Sources are variable name & value (packaged in SCons Value nodes) 894 return ([target], [Value(variable), Value(val)]) 895 896config_builder = Builder(emitter = config_emitter, action = config_action) 897 898main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 899 900# libelf build is shared across all configs in the build root. 901main.SConscript('ext/libelf/SConscript', 902 variant_dir = joinpath(build_root, 'libelf')) 903 904# gzstream build is shared across all configs in the build root. 905main.SConscript('ext/gzstream/SConscript', 906 variant_dir = joinpath(build_root, 'gzstream')) 907 908################################################### 909# 910# This function is used to set up a directory with switching headers 911# 912################################################### 913 914main['ALL_ISA_LIST'] = all_isa_list 915def make_switching_dir(dname, switch_headers, env): 916 # Generate the header. target[0] is the full path of the output 917 # header to generate. 'source' is a dummy variable, since we get the 918 # list of ISAs from env['ALL_ISA_LIST']. 919 def gen_switch_hdr(target, source, env): 920 fname = str(target[0]) 921 f = open(fname, 'w') 922 isa = env['TARGET_ISA'].lower() 923 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 924 f.close() 925 926 # Build SCons Action object. 'varlist' specifies env vars that this 927 # action depends on; when env['ALL_ISA_LIST'] changes these actions 928 # should get re-executed. 929 switch_hdr_action = MakeAction(gen_switch_hdr, 930 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 931 932 # Instantiate actions for each header 933 for hdr in switch_headers: 934 env.Command(hdr, [], switch_hdr_action) 935Export('make_switching_dir') 936 937################################################### 938# 939# Define build environments for selected configurations. 940# 941################################################### 942 943for variant_path in variant_paths: 944 print "Building in", variant_path 945 946 # Make a copy of the build-root environment to use for this config. 947 env = main.Clone() 948 env['BUILDDIR'] = variant_path 949 950 # variant_dir is the tail component of build path, and is used to 951 # determine the build parameters (e.g., 'ALPHA_SE') 952 (build_root, variant_dir) = splitpath(variant_path) 953 954 # Set env variables according to the build directory config. 955 sticky_vars.files = [] 956 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 957 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 958 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 959 current_vars_file = joinpath(build_root, 'variables', variant_dir) 960 if isfile(current_vars_file): 961 sticky_vars.files.append(current_vars_file) 962 print "Using saved variables file %s" % current_vars_file 963 else: 964 # Build dir-specific variables file doesn't exist. 965 966 # Make sure the directory is there so we can create it later 967 opt_dir = dirname(current_vars_file) 968 if not isdir(opt_dir): 969 mkdir(opt_dir) 970 971 # Get default build variables from source tree. Variables are 972 # normally determined by name of $VARIANT_DIR, but can be 973 # overridden by '--default=' arg on command line. 974 default = GetOption('default') 975 opts_dir = joinpath(main.root.abspath, 'build_opts') 976 if default: 977 default_vars_files = [joinpath(build_root, 'variables', default), 978 joinpath(opts_dir, default)] 979 else: 980 default_vars_files = [joinpath(opts_dir, variant_dir)] 981 existing_files = filter(isfile, default_vars_files) 982 if existing_files: 983 default_vars_file = existing_files[0] 984 sticky_vars.files.append(default_vars_file) 985 print "Variables file %s not found,\n using defaults in %s" \ 986 % (current_vars_file, default_vars_file) 987 else: 988 print "Error: cannot find variables file %s or " \ 989 "default file(s) %s" \ 990 % (current_vars_file, ' or '.join(default_vars_files)) 991 Exit(1) 992 993 # Apply current variable settings to env 994 sticky_vars.Update(env) 995 996 help_texts["local_vars"] += \ 997 "Build variables for %s:\n" % variant_dir \ 998 + sticky_vars.GenerateHelpText(env) 999 1000 # Process variable settings. 1001 1002 if not have_fenv and env['USE_FENV']: 1003 print "Warning: <fenv.h> not available; " \ 1004 "forcing USE_FENV to False in", variant_dir + "." 1005 env['USE_FENV'] = False 1006 1007 if not env['USE_FENV']: 1008 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 1009 print " FP results may deviate slightly from other platforms." 1010 1011 if env['EFENCE']: 1012 env.Append(LIBS=['efence']) 1013 1014 # Save sticky variable settings back to current variables file 1015 sticky_vars.Save(current_vars_file, env) 1016 1017 if env['USE_SSE2']: 1018 env.Append(CCFLAGS=['-msse2']) 1019 1020 # The src/SConscript file sets up the build rules in 'env' according 1021 # to the configured variables. It returns a list of environments, 1022 # one for each variant build (debug, opt, etc.) 1023 envList = SConscript('src/SConscript', variant_dir = variant_path, 1024 exports = 'env') 1025 1026 # Set up the regression tests for each build. 1027 for e in envList: 1028 SConscript('tests/SConscript', 1029 variant_dir = joinpath(variant_path, 'tests', e.Label), 1030 exports = { 'env' : e }, duplicate = False) 1031 1032# base help text 1033Help(''' 1034Usage: scons [scons options] [build variables] [target(s)] 1035 1036Extra scons options: 1037%(options)s 1038 1039Global build variables: 1040%(global_vars)s 1041 1042%(local_vars)s 1043''' % help_texts) 1044