SConstruct revision 9255
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################################################### 684202Sbinkertn@umich.edu 695342Sstever@gmail.com# Check for recent-enough Python and SCons versions. 70955SN/Atry: 715273Sstever@gmail.com # Really old versions of scons only take two options for the 725273Sstever@gmail.com # 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 """ 792656Sstever@eecs.umich.eduFor more details, see: 802653Sstever@eecs.umich.edu http://gem5.org/Dependencies 815227Ssaidi@eecs.umich.edu""" 825227Ssaidi@eecs.umich.edu raise 835227Ssaidi@eecs.umich.edu 845227Ssaidi@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 """ 902653Sstever@eecs.umich.eduYou can use a non-default installation of the Python interpreter by 912653Sstever@eecs.umich.edueither (1) rearranging your PATH so that scons finds the non-default 922653Sstever@eecs.umich.edu'python' first or (2) explicitly invoking an alternative interpreter 932653Sstever@eecs.umich.eduon the scons script. 944781Snate@binkert.org 951852SN/AFor more details, see: 96955SN/A http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 97955SN/A""" 98955SN/A raise 993717Sstever@eecs.umich.edu 1003716Sstever@eecs.umich.edu# Global Python includes 101955SN/Aimport os 1021533SN/Aimport re 1033716Sstever@eecs.umich.eduimport subprocess 1041533SN/Aimport 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 = { 1264973Ssaidi@eecs.umich.edu "options" : "", 1274678Snate@binkert.org "global_vars" : "", 1284678Snate@binkert.org "local_vars" : "" 1294678Snate@binkert.org} 1304678Snate@binkert.org 1314678Snate@binkert.orgExport("help_texts") 1324678Snate@binkert.org 133955SN/A 134955SN/A# There's a bug in scons in that (1) by default, the help texts from 1352632Sstever@eecs.umich.edu# 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 138955SN/A# you've overridden the help text using Help(), there's no way to get 139955SN/A# at the help texts from AddOptions. See: 140955SN/A# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1412632Sstever@eecs.umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2611 142955SN/A# 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. 1452632Sstever@eecs.umich.edudef AddLocalOption(*args, **kwargs): 1462632Sstever@eecs.umich.edu col_width = 30 1472632Sstever@eecs.umich.edu 1482632Sstever@eecs.umich.edu help = " " + ", ".join(args) 1492632Sstever@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', 1613053Sstever@eecs.umich.edu help="Add color to abbreviated scons output") 1623053Sstever@eecs.umich.eduAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1633053Sstever@eecs.umich.edu help="Don't add color to abbreviated scons output") 1643053Sstever@eecs.umich.eduAddLocalOption('--default', dest='default', type='string', action='store', 1653053Sstever@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', 1672632Sstever@eecs.umich.edu help='Disable style checking hooks') 1682632Sstever@eecs.umich.eduAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1692632Sstever@eecs.umich.edu help='Disable Link-Time Optimization for fast') 1702632Sstever@eecs.umich.eduAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1712632Sstever@eecs.umich.edu help='Update test reference outputs') 1723718Sstever@eecs.umich.eduAddLocalOption('--verbose', dest='verbose', action='store_true', 1733718Sstever@eecs.umich.edu help='Print full tool command lines') 1743718Sstever@eecs.umich.edu 1753718Sstever@eecs.umich.edutermcap = get_termcap(GetOption('use_colors')) 1763718Sstever@eecs.umich.edu 1773718Sstever@eecs.umich.edu######################################################################## 1783718Sstever@eecs.umich.edu# 1793718Sstever@eecs.umich.edu# Set up the main build environment. 1803718Sstever@eecs.umich.edu# 1813718Sstever@eecs.umich.edu######################################################################## 1823718Sstever@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 1833718Sstever@eecs.umich.edu 'LIBRARY_PATH', 'PATH', 'PYTHONPATH', 'RANLIB', 'SWIG' ]) 1843718Sstever@eecs.umich.edu 1852634Sstever@eecs.umich.eduuse_env = {} 1862634Sstever@eecs.umich.edufor key,val in os.environ.iteritems(): 1872632Sstever@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1882638Sstever@eecs.umich.edu use_env[key] = val 1892632Sstever@eecs.umich.edu 1902632Sstever@eecs.umich.edumain = Environment(ENV=use_env) 1912632Sstever@eecs.umich.edumain.Decider('MD5-timestamp') 1922632Sstever@eecs.umich.edumain.root = Dir(".") # The current directory (where this file lives). 1932632Sstever@eecs.umich.edumain.srcdir = Dir("src") # The source directory 1942632Sstever@eecs.umich.edu 1951858SN/Amain_dict_keys = main.Dictionary().keys() 1963716Sstever@eecs.umich.edu 1972638Sstever@eecs.umich.edu# Check that we have a C/C++ compiler 1982638Sstever@eecs.umich.eduif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 1992638Sstever@eecs.umich.edu print "No C++ compiler installed (package g++ on Ubuntu and RedHat)" 2002638Sstever@eecs.umich.edu Exit(1) 2012638Sstever@eecs.umich.edu 2022638Sstever@eecs.umich.edu# Check that swig is present 2032638Sstever@eecs.umich.eduif not 'SWIG' in main_dict_keys: 2043716Sstever@eecs.umich.edu print "swig is not installed (package swig on Ubuntu and RedHat)" 2052634Sstever@eecs.umich.edu Exit(1) 2062634Sstever@eecs.umich.edu 207955SN/A# add useful python code PYTHONPATH so it can be used by subprocesses 2085341Sstever@gmail.com# as well 2095341Sstever@gmail.commain.AppendENVPath('PYTHONPATH', extra_python_paths) 2105341Sstever@gmail.com 2115341Sstever@gmail.com######################################################################## 212955SN/A# 213955SN/A# Mercurial Stuff. 214955SN/A# 215955SN/A# If the gem5 directory is a mercurial repository, we should do some 216955SN/A# extra things. 217955SN/A# 218955SN/A######################################################################## 2191858SN/A 2201858SN/Ahgdir = main.root.Dir(".hg") 2212632Sstever@eecs.umich.edu 222955SN/Amercurial_style_message = """ 2234494Ssaidi@eecs.umich.eduYou're missing the gem5 style hook, which automatically checks your code 2244494Ssaidi@eecs.umich.eduagainst the gem5 style rules on hg commit and qrefresh commands. This 2253716Sstever@eecs.umich.eduscript will now install the hook in your .hg/hgrc file. 2261105SN/APress enter to continue, or ctrl-c to abort: """ 2272667Sstever@eecs.umich.edu 2282667Sstever@eecs.umich.edumercurial_style_hook = """ 2292667Sstever@eecs.umich.edu# The following lines were automatically added by gem5/SConstruct 2302667Sstever@eecs.umich.edu# to provide the gem5 style-checking hooks 2312667Sstever@eecs.umich.edu[extensions] 2322667Sstever@eecs.umich.edustyle = %s/util/style.py 2331869SN/A 2341869SN/A[hooks] 2351869SN/Apretxncommit.style = python:style.check_style 2361869SN/Apre-qrefresh.style = python:style.check_style 2371869SN/A# End of SConstruct additions 2381065SN/A 2395341Sstever@gmail.com""" % (main.root.abspath) 2405341Sstever@gmail.com 2415341Sstever@gmail.commercurial_lib_not_found = """ 2425341Sstever@gmail.comMercurial libraries cannot be found, ignoring style hook. If 2435341Sstever@gmail.comyou are a gem5 developer, please fix this and run the style 2445341Sstever@gmail.comhook. It is important. 2455341Sstever@gmail.com""" 2465341Sstever@gmail.com 2475341Sstever@gmail.com# Check for style hook and prompt for installation if it's not there. 2485341Sstever@gmail.com# Skip this if --ignore-style was specified, there's no .hg dir to 2495341Sstever@gmail.com# install a hook in, or there's no interactive terminal to prompt. 2505341Sstever@gmail.comif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2515341Sstever@gmail.com style_hook = True 2525341Sstever@gmail.com try: 2535341Sstever@gmail.com from mercurial import ui 2545341Sstever@gmail.com ui = ui.ui() 2555341Sstever@gmail.com ui.readconfig(hgdir.File('hgrc').abspath) 2565341Sstever@gmail.com style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2575341Sstever@gmail.com ui.config('hooks', 'pre-qrefresh.style', None) 2585341Sstever@gmail.com except ImportError: 2595341Sstever@gmail.com print mercurial_lib_not_found 2605341Sstever@gmail.com 2615341Sstever@gmail.com if not style_hook: 2625341Sstever@gmail.com print mercurial_style_message, 2635341Sstever@gmail.com # continue unless user does ctrl-c/ctrl-d etc. 2645341Sstever@gmail.com try: 2655341Sstever@gmail.com raw_input() 2665341Sstever@gmail.com except: 2675341Sstever@gmail.com print "Input exception, exiting scons.\n" 2685341Sstever@gmail.com sys.exit(1) 2695341Sstever@gmail.com hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2705341Sstever@gmail.com print "Adding style hook to", hgrc_path, "\n" 2715341Sstever@gmail.com try: 2725341Sstever@gmail.com hgrc = open(hgrc_path, 'a') 2735341Sstever@gmail.com hgrc.write(mercurial_style_hook) 2745341Sstever@gmail.com hgrc.close() 2755341Sstever@gmail.com except: 2765341Sstever@gmail.com print "Error updating", hgrc_path 2775341Sstever@gmail.com sys.exit(1) 2785341Sstever@gmail.com 2795341Sstever@gmail.com 2805341Sstever@gmail.com################################################### 2815341Sstever@gmail.com# 2825341Sstever@gmail.com# Figure out which configurations to set up based on the path(s) of 2835341Sstever@gmail.com# the target(s). 2845341Sstever@gmail.com# 2855341Sstever@gmail.com################################################### 2865341Sstever@gmail.com 2875341Sstever@gmail.com# Find default configuration & binary. 2885344Sstever@gmail.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2895341Sstever@gmail.com 2905341Sstever@gmail.com# helper function: find last occurrence of element in list 2915341Sstever@gmail.comdef rfind(l, elt, offs = -1): 2925341Sstever@gmail.com for i in range(len(l)+offs, 0, -1): 2935341Sstever@gmail.com if l[i] == elt: 2942632Sstever@eecs.umich.edu return i 2955199Sstever@gmail.com raise ValueError, "element not found" 2963918Ssaidi@eecs.umich.edu 2973918Ssaidi@eecs.umich.edu# Take a list of paths (or SCons Nodes) and return a list with all 2983940Ssaidi@eecs.umich.edu# paths made absolute and ~-expanded. Paths will be interpreted 2994781Snate@binkert.org# relative to the launch directory unless a different root is provided 3004781Snate@binkert.orgdef makePathListAbsolute(path_list, root=GetLaunchDir()): 3013918Ssaidi@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 3024781Snate@binkert.org for p in path_list] 3034781Snate@binkert.org 3043918Ssaidi@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 3054781Snate@binkert.org# directory below this will determine the build parameters. For 3064781Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 3073940Ssaidi@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 3083942Ssaidi@eecs.umich.edu# follow 'build' in the build path. 3093940Ssaidi@eecs.umich.edu 3103918Ssaidi@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 3113918Ssaidi@eecs.umich.edu# in place rather than reassign the symbol to a new list, which 312955SN/A# doesn't work (obviously!). 3131858SN/ABUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 3143918Ssaidi@eecs.umich.edu 3153918Ssaidi@eecs.umich.edu# Generate a list of the unique build roots and configs that the 3163918Ssaidi@eecs.umich.edu# collected targets reference. 3173918Ssaidi@eecs.umich.eduvariant_paths = [] 3183940Ssaidi@eecs.umich.edubuild_root = None 3193940Ssaidi@eecs.umich.edufor t in BUILD_TARGETS: 3203918Ssaidi@eecs.umich.edu path_dirs = t.split('/') 3213918Ssaidi@eecs.umich.edu try: 3223918Ssaidi@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 3233918Ssaidi@eecs.umich.edu except: 3243918Ssaidi@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 3253918Ssaidi@eecs.umich.edu Exit(1) 3263918Ssaidi@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3273918Ssaidi@eecs.umich.edu if not build_root: 3283918Ssaidi@eecs.umich.edu build_root = this_build_root 3293940Ssaidi@eecs.umich.edu else: 3303918Ssaidi@eecs.umich.edu if this_build_root != build_root: 3313918Ssaidi@eecs.umich.edu print "Error: build targets not under same build root\n"\ 3321851SN/A " %s\n %s" % (build_root, this_build_root) 3331851SN/A Exit(1) 3341858SN/A variant_path = joinpath('/',*path_dirs[:build_top+2]) 3355200Sstever@gmail.com if variant_path not in variant_paths: 336955SN/A variant_paths.append(variant_path) 3373053Sstever@eecs.umich.edu 3383053Sstever@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 3393053Sstever@eecs.umich.eduif not isdir(build_root): 3403053Sstever@eecs.umich.edu mkdir(build_root) 3413053Sstever@eecs.umich.edumain['BUILDROOT'] = build_root 3423053Sstever@eecs.umich.edu 3433053Sstever@eecs.umich.eduExport('main') 3443053Sstever@eecs.umich.edu 3453053Sstever@eecs.umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 3464742Sstever@eecs.umich.edu 3474742Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 3483053Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 3493053Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 3503053Sstever@eecs.umich.edu# (soft) links work better. 3513053Sstever@eecs.umich.edumain.SetOption('duplicate', 'soft-copy') 3523053Sstever@eecs.umich.edu 3533053Sstever@eecs.umich.edu# 3543053Sstever@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 3553053Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 3563053Sstever@eecs.umich.edu# 3572667Sstever@eecs.umich.edu 3584554Sbinkertn@umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 3594554Sbinkertn@umich.edu 3602667Sstever@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3614554Sbinkertn@umich.edu 3624554Sbinkertn@umich.eduglobal_vars.AddVariables( 3634554Sbinkertn@umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3644554Sbinkertn@umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3654554Sbinkertn@umich.edu ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 3664554Sbinkertn@umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3674554Sbinkertn@umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3684781Snate@binkert.org ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3694554Sbinkertn@umich.edu ('EXTRAS', 'Add extra directories to the compilation', '') 3704554Sbinkertn@umich.edu ) 3712667Sstever@eecs.umich.edu 3724554Sbinkertn@umich.edu# Update main environment with values from ARGUMENTS & global_vars_file 3734554Sbinkertn@umich.eduglobal_vars.Update(main) 3744554Sbinkertn@umich.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3754554Sbinkertn@umich.edu 3762667Sstever@eecs.umich.edu# Save sticky variable settings back to current variables file 3774554Sbinkertn@umich.eduglobal_vars.Save(global_vars_file, main) 3782667Sstever@eecs.umich.edu 3794554Sbinkertn@umich.edu# Parse EXTRAS variable to build list of all directories where we're 3804554Sbinkertn@umich.edu# look for sources etc. This list is exported as extras_dir_list. 3812667Sstever@eecs.umich.edubase_dir = main.srcdir.abspath 3822638Sstever@eecs.umich.eduif main['EXTRAS']: 3832638Sstever@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3842638Sstever@eecs.umich.eduelse: 3853716Sstever@eecs.umich.edu extras_dir_list = [] 3863716Sstever@eecs.umich.edu 3871858SN/AExport('base_dir') 3885227Ssaidi@eecs.umich.eduExport('extras_dir_list') 3895227Ssaidi@eecs.umich.edu 3905227Ssaidi@eecs.umich.edu# the ext directory should be on the #includes path 3915227Ssaidi@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3925227Ssaidi@eecs.umich.edu 3935227Ssaidi@eecs.umich.edudef strip_build_path(path, env): 3945227Ssaidi@eecs.umich.edu path = str(path) 3955227Ssaidi@eecs.umich.edu variant_base = env['BUILDROOT'] + os.path.sep 3965227Ssaidi@eecs.umich.edu if path.startswith(variant_base): 3975227Ssaidi@eecs.umich.edu path = path[len(variant_base):] 3985227Ssaidi@eecs.umich.edu elif path.startswith('build/'): 3995227Ssaidi@eecs.umich.edu path = path[6:] 4005274Ssaidi@eecs.umich.edu return path 4015227Ssaidi@eecs.umich.edu 4025227Ssaidi@eecs.umich.edu# Generate a string of the form: 4035227Ssaidi@eecs.umich.edu# common/path/prefix/src1, src2 -> tgt1, tgt2 4045204Sstever@gmail.com# to print while building. 4055204Sstever@gmail.comclass Transform(object): 4065204Sstever@gmail.com # all specific color settings should be here and nowhere else 4075204Sstever@gmail.com tool_color = termcap.Normal 4085204Sstever@gmail.com pfx_color = termcap.Yellow 4095204Sstever@gmail.com srcs_color = termcap.Yellow + termcap.Bold 4105204Sstever@gmail.com arrow_color = termcap.Blue + termcap.Bold 4115204Sstever@gmail.com tgts_color = termcap.Yellow + termcap.Bold 4125204Sstever@gmail.com 4135204Sstever@gmail.com def __init__(self, tool, max_sources=99): 4145204Sstever@gmail.com self.format = self.tool_color + (" [%8s] " % tool) \ 4155204Sstever@gmail.com + self.pfx_color + "%s" \ 4165204Sstever@gmail.com + self.srcs_color + "%s" \ 4175204Sstever@gmail.com + self.arrow_color + " -> " \ 4185204Sstever@gmail.com + self.tgts_color + "%s" \ 4195204Sstever@gmail.com + termcap.Normal 4205204Sstever@gmail.com self.max_sources = max_sources 4215204Sstever@gmail.com 4225204Sstever@gmail.com def __call__(self, target, source, env, for_signature=None): 4233118Sstever@eecs.umich.edu # truncate source list according to max_sources param 4243118Sstever@eecs.umich.edu source = source[0:self.max_sources] 4253118Sstever@eecs.umich.edu def strip(f): 4263118Sstever@eecs.umich.edu return strip_build_path(str(f), env) 4273118Sstever@eecs.umich.edu if len(source) > 0: 4283118Sstever@eecs.umich.edu srcs = map(strip, source) 4293118Sstever@eecs.umich.edu else: 4303118Sstever@eecs.umich.edu srcs = [''] 4313118Sstever@eecs.umich.edu tgts = map(strip, target) 4323118Sstever@eecs.umich.edu # surprisingly, os.path.commonprefix is a dumb char-by-char string 4333118Sstever@eecs.umich.edu # operation that has nothing to do with paths. 4343716Sstever@eecs.umich.edu com_pfx = os.path.commonprefix(srcs + tgts) 4353118Sstever@eecs.umich.edu com_pfx_len = len(com_pfx) 4363118Sstever@eecs.umich.edu if com_pfx: 4373118Sstever@eecs.umich.edu # do some cleanup and sanity checking on common prefix 4383118Sstever@eecs.umich.edu if com_pfx[-1] == ".": 4393118Sstever@eecs.umich.edu # prefix matches all but file extension: ok 4403118Sstever@eecs.umich.edu # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4413118Sstever@eecs.umich.edu com_pfx = com_pfx[0:-1] 4423118Sstever@eecs.umich.edu elif com_pfx[-1] == "/": 4433118Sstever@eecs.umich.edu # common prefix is directory path: OK 4443716Sstever@eecs.umich.edu pass 4453118Sstever@eecs.umich.edu else: 4463118Sstever@eecs.umich.edu src0_len = len(srcs[0]) 4473118Sstever@eecs.umich.edu tgt0_len = len(tgts[0]) 4483118Sstever@eecs.umich.edu if src0_len == com_pfx_len: 4493118Sstever@eecs.umich.edu # source is a substring of target, OK 4503118Sstever@eecs.umich.edu pass 4513118Sstever@eecs.umich.edu elif tgt0_len == com_pfx_len: 4523118Sstever@eecs.umich.edu # target is a substring of source, need to back up to 4533118Sstever@eecs.umich.edu # avoid empty string on RHS of arrow 4543118Sstever@eecs.umich.edu sep_idx = com_pfx.rfind(".") 4553483Ssaidi@eecs.umich.edu if sep_idx != -1: 4563494Ssaidi@eecs.umich.edu com_pfx = com_pfx[0:sep_idx] 4573494Ssaidi@eecs.umich.edu else: 4583483Ssaidi@eecs.umich.edu com_pfx = '' 4593483Ssaidi@eecs.umich.edu elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4603483Ssaidi@eecs.umich.edu # still splitting at file extension: ok 4613053Sstever@eecs.umich.edu pass 4623053Sstever@eecs.umich.edu else: 4633918Ssaidi@eecs.umich.edu # probably a fluke; ignore it 4643053Sstever@eecs.umich.edu com_pfx = '' 4653053Sstever@eecs.umich.edu # recalculate length in case com_pfx was modified 4663053Sstever@eecs.umich.edu com_pfx_len = len(com_pfx) 4673053Sstever@eecs.umich.edu def fmt(files): 4683053Sstever@eecs.umich.edu f = map(lambda s: s[com_pfx_len:], files) 4691858SN/A return ', '.join(f) 4701858SN/A return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4711858SN/A 4721858SN/AExport('Transform') 4731858SN/A 4741858SN/A# enable the regression script to use the termcap 4751859SN/Amain['TERMCAP'] = termcap 4761858SN/A 4771858SN/Aif GetOption('verbose'): 4781858SN/A def MakeAction(action, string, *args, **kwargs): 4791859SN/A return Action(action, *args, **kwargs) 4801859SN/Aelse: 4811862SN/A MakeAction = Action 4823053Sstever@eecs.umich.edu main['CCCOMSTR'] = Transform("CC") 4833053Sstever@eecs.umich.edu main['CXXCOMSTR'] = Transform("CXX") 4843053Sstever@eecs.umich.edu main['ASCOMSTR'] = Transform("AS") 4853053Sstever@eecs.umich.edu main['SWIGCOMSTR'] = Transform("SWIG") 4861859SN/A main['ARCOMSTR'] = Transform("AR", 0) 4871859SN/A main['LINKCOMSTR'] = Transform("LINK", 0) 4881859SN/A main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4891859SN/A main['M4COMSTR'] = Transform("M4") 4901859SN/A main['SHCCCOMSTR'] = Transform("SHCC") 4911859SN/A main['SHCXXCOMSTR'] = Transform("SHCXX") 4921859SN/AExport('MakeAction') 4931859SN/A 4941862SN/A# Initialize the Link-Time Optimization (LTO) flags 4951859SN/Amain['LTO_CCFLAGS'] = [] 4961859SN/Amain['LTO_LDFLAGS'] = [] 4971859SN/A 4981858SN/ACXX_version = readCommand([main['CXX'],'--version'], exception=False) 4991858SN/ACXX_V = readCommand([main['CXX'],'-V'], exception=False) 5002139SN/A 5014202Sbinkertn@umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 5024202Sbinkertn@umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 5032139SN/Amain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 5042155SN/Amain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 5054202Sbinkertn@umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: 5064202Sbinkertn@umich.edu print 'Error: How can we have two at the same time?' 5074202Sbinkertn@umich.edu Exit(1) 5082155SN/A 5091869SN/A# Set up default C++ compiler flags 5101869SN/Aif main['GCC']: 5111869SN/A main.Append(CCFLAGS=['-pipe']) 5121869SN/A main.Append(CCFLAGS=['-fno-strict-aliasing']) 5134202Sbinkertn@umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5144202Sbinkertn@umich.edu # Read the GCC version to check for versions with bugs 5154202Sbinkertn@umich.edu # Note CCVERSION doesn't work here because it is run with the CC 5164202Sbinkertn@umich.edu # before we override it from the command line 5174202Sbinkertn@umich.edu gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5184202Sbinkertn@umich.edu main['GCC_VERSION'] = gcc_version 5194202Sbinkertn@umich.edu if not compareVersions(gcc_version, '4.4.1') or \ 5204202Sbinkertn@umich.edu not compareVersions(gcc_version, '4.4.2'): 5215341Sstever@gmail.com print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5225341Sstever@gmail.com main.Append(CCFLAGS=['-fno-tree-vectorize']) 5235341Sstever@gmail.com # c++0x support in gcc is useful already from 4.4, see 5245342Sstever@gmail.com # http://gcc.gnu.org/projects/cxx0x.html for details 5255342Sstever@gmail.com if compareVersions(gcc_version, '4.4') >= 0: 5264202Sbinkertn@umich.edu main.Append(CXXFLAGS=['-std=c++0x']) 5274202Sbinkertn@umich.edu 5284202Sbinkertn@umich.edu # LTO support is only really working properly from 4.6 and beyond 5294202Sbinkertn@umich.edu if compareVersions(gcc_version, '4.6') >= 0: 5304202Sbinkertn@umich.edu # Add the appropriate Link-Time Optimization (LTO) flags 5311869SN/A # unless LTO is explicitly turned off. Note that these flags 5324202Sbinkertn@umich.edu # are only used by the fast target. 5331869SN/A if not GetOption('no_lto'): 5342508SN/A # Pass the LTO flag when compiling to produce GIMPLE 5352508SN/A # output, we merely create the flags here and only append 5362508SN/A # them later/ 5372508SN/A main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 5384202Sbinkertn@umich.edu 5391869SN/A # Use the same amount of jobs for LTO as we are running 5405385Sstever@gmail.com # scons with, we hardcode the use of the linker plugin 5415385Sstever@gmail.com # which requires either gold or GNU ld >= 2.21 5425385Sstever@gmail.com main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'), 5435385Sstever@gmail.com '-fuse-linker-plugin'] 5441869SN/A 5451869SN/Aelif main['ICC']: 5461869SN/A pass #Fix me... add warning flags once we clean up icc warnings 5471869SN/Aelif main['SUNCC']: 5481869SN/A main.Append(CCFLAGS=['-Qoption ccfe']) 5491965SN/A main.Append(CCFLAGS=['-features=gcc']) 5501965SN/A main.Append(CCFLAGS=['-features=extensions']) 5511965SN/A main.Append(CCFLAGS=['-library=stlport4']) 5521869SN/A main.Append(CCFLAGS=['-xar']) 5531869SN/A #main.Append(CCFLAGS=['-instances=semiexplicit']) 5542733Sktlim@umich.eduelif main['CLANG']: 5551884SN/A clang_version_re = re.compile(".* version (\d+\.\d+)") 5563356Sbinkertn@umich.edu clang_version_match = clang_version_re.match(CXX_version) 5573356Sbinkertn@umich.edu if (clang_version_match): 5583356Sbinkertn@umich.edu clang_version = clang_version_match.groups()[0] 5594773Snate@binkert.org if compareVersions(clang_version, "2.9") < 0: 5601869SN/A print 'Error: clang version 2.9 or newer required.' 5611858SN/A print ' Installed version:', clang_version 5621869SN/A Exit(1) 5631869SN/A else: 5641869SN/A print 'Error: Unable to determine clang version.' 5651858SN/A Exit(1) 5662761Sstever@eecs.umich.edu 5671869SN/A main.Append(CCFLAGS=['-pipe']) 5685385Sstever@gmail.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 5695385Sstever@gmail.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5703584Ssaidi@eecs.umich.edu main.Append(CCFLAGS=['-Wno-tautological-compare']) 5711869SN/A main.Append(CCFLAGS=['-Wno-self-assign']) 5721869SN/A # Ruby makes frequent use of extraneous parantheses in the printing 5731869SN/A # of if-statements 5741869SN/A main.Append(CCFLAGS=['-Wno-parentheses']) 5751869SN/A 5761869SN/A # clang 2.9 does not play well with c++0x as it ships with C++ 5771858SN/A # headers that produce errors, this was fixed in 3.0 578955SN/A if compareVersions(clang_version, "3") >= 0: 579955SN/A main.Append(CXXFLAGS=['-std=c++0x']) 5801869SN/Aelse: 5811869SN/A print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 5821869SN/A print "Don't know what compiler options to use for your compiler." 5831869SN/A print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 5841869SN/A print termcap.Yellow + ' version:' + termcap.Normal, 5851869SN/A if not CXX_version: 5861869SN/A print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 5871869SN/A termcap.Normal 5881869SN/A else: 5891869SN/A print CXX_version.replace('\n', '<nl>') 5901869SN/A print " If you're trying to use a compiler other than GCC, ICC, SunCC," 5911869SN/A print " or clang, there appears to be something wrong with your" 5921869SN/A print " environment." 5931869SN/A print " " 5941869SN/A print " If you are trying to use a compiler other than those listed" 5951869SN/A print " above you will need to ease fix SConstruct and " 5961869SN/A print " src/SConscript to support that compiler." 5971869SN/A Exit(1) 5981869SN/A 5991869SN/A# Set up common yacc/bison flags (needed for Ruby) 6001869SN/Amain['YACCFLAGS'] = '-d' 6011869SN/Amain['YACCHXXFILESUFFIX'] = '.hh' 6021869SN/A 6031869SN/A# Do this after we save setting back, or else we'll tack on an 6041869SN/A# extra 'qdo' every time we run scons. 6051869SN/Aif main['BATCH']: 6061869SN/A main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 6071869SN/A main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 6081869SN/A main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 6093716Sstever@eecs.umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 6103356Sbinkertn@umich.edu main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 6113356Sbinkertn@umich.edu 6123356Sbinkertn@umich.eduif sys.platform == 'cygwin': 6133356Sbinkertn@umich.edu # cygwin has some header file issues... 6143356Sbinkertn@umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 6153356Sbinkertn@umich.edu 6164781Snate@binkert.org# Check for SWIG 6171869SN/Aif not main.has_key('SWIG'): 6181869SN/A print 'Error: SWIG utility not found.' 6191869SN/A print ' Please install (see http://www.swig.org) and retry.' 6201869SN/A Exit(1) 6211869SN/A 6221869SN/A# Check for appropriate SWIG version 6231869SN/Aswig_version = readCommand([main['SWIG'], '-version'], exception='').split() 6242655Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 6252655Sstever@eecs.umich.eduif len(swig_version) < 3 or \ 6262655Sstever@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 6272655Sstever@eecs.umich.edu print 'Error determining SWIG version.' 6282655Sstever@eecs.umich.edu Exit(1) 6292655Sstever@eecs.umich.edu 6302655Sstever@eecs.umich.edumin_swig_version = '1.3.34' 6312655Sstever@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0: 6322655Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 6332655Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 6342655Sstever@eecs.umich.edu Exit(1) 6352655Sstever@eecs.umich.edu 6362655Sstever@eecs.umich.edu# Set up SWIG flags & scanner 6372655Sstever@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 6382655Sstever@eecs.umich.edumain.Append(SWIGFLAGS=swig_flags) 6392655Sstever@eecs.umich.edu 6402655Sstever@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 6412655Sstever@eecs.umich.edu# stuff for some reason 6422655Sstever@eecs.umich.eduscanners = [] 6432655Sstever@eecs.umich.edufor scanner in main['SCANNERS']: 6442655Sstever@eecs.umich.edu skeys = scanner.skeys 6452655Sstever@eecs.umich.edu if skeys == '.i': 6462655Sstever@eecs.umich.edu continue 6472655Sstever@eecs.umich.edu 6482655Sstever@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 6492655Sstever@eecs.umich.edu continue 6502638Sstever@eecs.umich.edu 6512638Sstever@eecs.umich.edu scanners.append(scanner) 6523716Sstever@eecs.umich.edu 6532638Sstever@eecs.umich.edu# add the new swig scanner that we like better 6542638Sstever@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 6551869SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 6561869SN/Ascanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 6573546Sgblack@eecs.umich.edu 6583546Sgblack@eecs.umich.edu# replace the scanners list that has what we want 6593546Sgblack@eecs.umich.edumain['SCANNERS'] = scanners 6603546Sgblack@eecs.umich.edu 6614202Sbinkertn@umich.edu# Add a custom Check function to the Configure context so that we can 6623546Sgblack@eecs.umich.edu# figure out if the compiler adds leading underscores to global 6633546Sgblack@eecs.umich.edu# variables. This is needed for the autogenerated asm files that we 6643546Sgblack@eecs.umich.edu# use for embedding the python code. 6653546Sgblack@eecs.umich.edudef CheckLeading(context): 6663546Sgblack@eecs.umich.edu context.Message("Checking for leading underscore in global variables...") 6674781Snate@binkert.org # 1) Define a global variable called x from asm so the C compiler 6684781Snate@binkert.org # won't change the symbol at all. 6694781Snate@binkert.org # 2) Declare that variable. 6704781Snate@binkert.org # 3) Use the variable 6714781Snate@binkert.org # 6724781Snate@binkert.org # If the compiler prepends an underscore, this will successfully 6734781Snate@binkert.org # link because the external symbol 'x' will be called '_x' which 6744781Snate@binkert.org # was defined by the asm statement. If the compiler does not 6754781Snate@binkert.org # prepend an underscore, this will not successfully link because 6764781Snate@binkert.org # '_x' will have been defined by assembly, while the C portion of 6774781Snate@binkert.org # the code will be trying to use 'x' 6784781Snate@binkert.org ret = context.TryLink(''' 6793546Sgblack@eecs.umich.edu asm(".globl _x; _x: .byte 0"); 6803546Sgblack@eecs.umich.edu extern int x; 6813546Sgblack@eecs.umich.edu int main() { return x; } 6824781Snate@binkert.org ''', extension=".c") 6833546Sgblack@eecs.umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 6843546Sgblack@eecs.umich.edu context.Result(ret) 6853546Sgblack@eecs.umich.edu return ret 6863546Sgblack@eecs.umich.edu 6873546Sgblack@eecs.umich.edu# Test for the presence of C++11 static asserts. If the compiler lacks 6883546Sgblack@eecs.umich.edu# support for static asserts, base/compiler.hh enables a macro that 6893546Sgblack@eecs.umich.edu# removes any static asserts in the code. 6903546Sgblack@eecs.umich.edudef CheckStaticAssert(context): 6913546Sgblack@eecs.umich.edu context.Message("Checking for C++11 static_assert support...") 6923546Sgblack@eecs.umich.edu ret = context.TryCompile(''' 6934202Sbinkertn@umich.edu static_assert(1, "This assert is always true"); 6943546Sgblack@eecs.umich.edu ''', extension=".cc") 6953546Sgblack@eecs.umich.edu context.env.Append(HAVE_STATIC_ASSERT=ret) 6963546Sgblack@eecs.umich.edu context.Result(ret) 697955SN/A return ret 698955SN/A 699955SN/A# Platform-specific configuration. Note again that we assume that all 700955SN/A# builds under a given build root run on the same host platform. 7011858SN/Aconf = Configure(main, 7021858SN/A conf_dir = joinpath(build_root, '.scons_config'), 7031858SN/A log_file = joinpath(build_root, 'scons_config.log'), 7042632Sstever@eecs.umich.edu custom_tests = { 'CheckLeading' : CheckLeading, 7052632Sstever@eecs.umich.edu 'CheckStaticAssert' : CheckStaticAssert, 7065343Sstever@gmail.com }) 7075343Sstever@gmail.com 7085343Sstever@gmail.com# Check for leading underscores. Don't really need to worry either 7094773Snate@binkert.org# way so don't need to check the return code. 7104773Snate@binkert.orgconf.CheckLeading() 7112632Sstever@eecs.umich.edu 7122632Sstever@eecs.umich.edu# Check for C++11 features we want to use if they exist 7132632Sstever@eecs.umich.educonf.CheckStaticAssert() 7142023SN/A 7152632Sstever@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 7162632Sstever@eecs.umich.edutry: 7172632Sstever@eecs.umich.edu import platform 7182632Sstever@eecs.umich.edu uname = platform.uname() 7192632Sstever@eecs.umich.edu if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 7203716Sstever@eecs.umich.edu if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 7215342Sstever@gmail.com main.Append(CCFLAGS=['-arch', 'x86_64']) 7222632Sstever@eecs.umich.edu main.Append(CFLAGS=['-arch', 'x86_64']) 7232632Sstever@eecs.umich.edu main.Append(LINKFLAGS=['-arch', 'x86_64']) 7242632Sstever@eecs.umich.edu main.Append(ASFLAGS=['-arch', 'x86_64']) 7252632Sstever@eecs.umich.eduexcept: 7262023SN/A pass 7272632Sstever@eecs.umich.edu 7282632Sstever@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 7295342Sstever@gmail.com# when configuration isn't necessary, e.g., if the "--help" option is 7301889SN/A# present. Unfortuantely this Null object always returns false, 7312632Sstever@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 7322632Sstever@eecs.umich.edu# more optimistic null object that returns True instead. 7332632Sstever@eecs.umich.eduif not conf: 7342632Sstever@eecs.umich.edu def NullCheck(*args, **kwargs): 7353716Sstever@eecs.umich.edu return True 7363716Sstever@eecs.umich.edu 7375342Sstever@gmail.com class NullConf: 7382632Sstever@eecs.umich.edu def __init__(self, env): 7392632Sstever@eecs.umich.edu self.env = env 7402632Sstever@eecs.umich.edu def Finish(self): 7412632Sstever@eecs.umich.edu return self.env 7422632Sstever@eecs.umich.edu def __getattr__(self, mname): 7432632Sstever@eecs.umich.edu return NullCheck 7442632Sstever@eecs.umich.edu 7451888SN/A conf = NullConf(main) 7461888SN/A 7471869SN/A# Find Python include and library directories for embedding the 7481869SN/A# interpreter. For consistency, we will use the same Python 7491858SN/A# installation used to run scons (and thus this script). If you want 7505341Sstever@gmail.com# to link in an alternate version, see above for instructions on how 7512598SN/A# to invoke scons with a different copy of the Python interpreter. 7522598SN/Afrom distutils import sysconfig 7532598SN/A 7542598SN/Apy_getvar = sysconfig.get_config_var 7551858SN/A 7561858SN/Apy_debug = getattr(sys, 'pydebug', False) 7571858SN/Apy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 7581858SN/A 7591858SN/Apy_general_include = sysconfig.get_python_inc() 7601858SN/Apy_platform_include = sysconfig.get_python_inc(plat_specific=True) 7611858SN/Apy_includes = [ py_general_include ] 7621858SN/Aif py_platform_include != py_general_include: 7631858SN/A py_includes.append(py_platform_include) 7641871SN/A 7651858SN/Apy_lib_path = [ py_getvar('LIBDIR') ] 7661858SN/A# add the prefix/lib/pythonX.Y/config dir, but only if there is no 7671858SN/A# shared library in prefix/lib/. 7681858SN/Aif not py_getvar('Py_ENABLE_SHARED'): 7691858SN/A py_lib_path.append(py_getvar('LIBPL')) 7701858SN/A 7711858SN/Apy_libs = [] 7721858SN/Afor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 7731858SN/A if not lib.startswith('-l'): 7741858SN/A # Python requires some special flags to link (e.g. -framework 7751858SN/A # common on OS X systems), assume appending preserves order 7761859SN/A main.Append(LINKFLAGS=[lib]) 7771859SN/A else: 7781869SN/A lib = lib[2:] 7791888SN/A if lib not in py_libs: 7802632Sstever@eecs.umich.edu py_libs.append(lib) 7811869SN/Apy_libs.append(py_version) 7821884SN/A 7831884SN/Amain.Append(CPPPATH=py_includes) 7841884SN/Amain.Append(LIBPATH=py_lib_path) 7851884SN/A 7861884SN/A# Cache build files in the supplied directory. 7871884SN/Aif main['M5_BUILD_CACHE']: 7881965SN/A print 'Using build cache located at', main['M5_BUILD_CACHE'] 7891965SN/A CacheDir(main['M5_BUILD_CACHE']) 7901965SN/A 7912761Sstever@eecs.umich.edu 7921869SN/A# verify that this stuff works 7931869SN/Aif not conf.CheckHeader('Python.h', '<>'): 7942632Sstever@eecs.umich.edu print "Error: can't find Python.h header in", py_includes 7952667Sstever@eecs.umich.edu print "Install Python headers (package python-dev on Ubuntu and RedHat)" 7961869SN/A Exit(1) 7971869SN/A 7982929Sktlim@umich.edufor lib in py_libs: 7992929Sktlim@umich.edu if not conf.CheckLib(lib): 8003716Sstever@eecs.umich.edu print "Error: can't find library %s required by python" % lib 8012929Sktlim@umich.edu Exit(1) 802955SN/A 8032598SN/A# On Solaris you need to use libsocket for socket ops 8042598SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 8053546Sgblack@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 806955SN/A print "Can't find library with socket calls (e.g. accept())" 807955SN/A Exit(1) 808955SN/A 8091530SN/A# Check for zlib. If the check passes, libz will be automatically 810955SN/A# added to the LIBS environment variable. 811955SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 812955SN/A print 'Error: did not find needed zlib compression library '\ 813 'and/or zlib.h header file.' 814 print ' Please install zlib and try again.' 815 Exit(1) 816 817# Check for librt. 818have_posix_clock = \ 819 conf.CheckLibWithHeader(None, 'time.h', 'C', 820 'clock_nanosleep(0,0,NULL,NULL);') or \ 821 conf.CheckLibWithHeader('rt', 'time.h', 'C', 822 'clock_nanosleep(0,0,NULL,NULL);') 823 824if conf.CheckLib('tcmalloc_minimal'): 825 have_tcmalloc = True 826else: 827 have_tcmalloc = False 828 print termcap.Yellow + termcap.Bold + \ 829 "You can get a 12% performance improvement by installing tcmalloc "\ 830 "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \ 831 termcap.Normal 832 833if not have_posix_clock: 834 print "Can't find library for POSIX clocks." 835 836# Check for <fenv.h> (C99 FP environment control) 837have_fenv = conf.CheckHeader('fenv.h', '<>') 838if not have_fenv: 839 print "Warning: Header file <fenv.h> not found." 840 print " This host has no IEEE FP rounding mode control." 841 842###################################################################### 843# 844# Finish the configuration 845# 846main = conf.Finish() 847 848###################################################################### 849# 850# Collect all non-global variables 851# 852 853# Define the universe of supported ISAs 854all_isa_list = [ ] 855Export('all_isa_list') 856 857class CpuModel(object): 858 '''The CpuModel class encapsulates everything the ISA parser needs to 859 know about a particular CPU model.''' 860 861 # Dict of available CPU model objects. Accessible as CpuModel.dict. 862 dict = {} 863 list = [] 864 defaults = [] 865 866 # Constructor. Automatically adds models to CpuModel.dict. 867 def __init__(self, name, filename, includes, strings, default=False): 868 self.name = name # name of model 869 self.filename = filename # filename for output exec code 870 self.includes = includes # include files needed in exec file 871 # The 'strings' dict holds all the per-CPU symbols we can 872 # substitute into templates etc. 873 self.strings = strings 874 875 # This cpu is enabled by default 876 self.default = default 877 878 # Add self to dict 879 if name in CpuModel.dict: 880 raise AttributeError, "CpuModel '%s' already registered" % name 881 CpuModel.dict[name] = self 882 CpuModel.list.append(name) 883 884Export('CpuModel') 885 886# Sticky variables get saved in the variables file so they persist from 887# one invocation to the next (unless overridden, in which case the new 888# value becomes sticky). 889sticky_vars = Variables(args=ARGUMENTS) 890Export('sticky_vars') 891 892# Sticky variables that should be exported 893export_vars = [] 894Export('export_vars') 895 896# For Ruby 897all_protocols = [] 898Export('all_protocols') 899protocol_dirs = [] 900Export('protocol_dirs') 901slicc_includes = [] 902Export('slicc_includes') 903 904# Walk the tree and execute all SConsopts scripts that wil add to the 905# above variables 906if not GetOption('verbose'): 907 print "Reading SConsopts" 908for bdir in [ base_dir ] + extras_dir_list: 909 if not isdir(bdir): 910 print "Error: directory '%s' does not exist" % bdir 911 Exit(1) 912 for root, dirs, files in os.walk(bdir): 913 if 'SConsopts' in files: 914 if GetOption('verbose'): 915 print "Reading", joinpath(root, 'SConsopts') 916 SConscript(joinpath(root, 'SConsopts')) 917 918all_isa_list.sort() 919 920sticky_vars.AddVariables( 921 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 922 ListVariable('CPU_MODELS', 'CPU models', 923 sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 924 sorted(CpuModel.list)), 925 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 926 False), 927 BoolVariable('SS_COMPATIBLE_FP', 928 'Make floating-point results compatible with SimpleScalar', 929 False), 930 BoolVariable('USE_SSE2', 931 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 932 False), 933 BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 934 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 935 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 936 EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 937 all_protocols), 938 ) 939 940# These variables get exported to #defines in config/*.hh (see src/SConscript). 941export_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 942 'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'PROTOCOL', 943 'HAVE_STATIC_ASSERT'] 944 945################################################### 946# 947# Define a SCons builder for configuration flag headers. 948# 949################################################### 950 951# This function generates a config header file that #defines the 952# variable symbol to the current variable setting (0 or 1). The source 953# operands are the name of the variable and a Value node containing the 954# value of the variable. 955def build_config_file(target, source, env): 956 (variable, value) = [s.get_contents() for s in source] 957 f = file(str(target[0]), 'w') 958 print >> f, '#define', variable, value 959 f.close() 960 return None 961 962# Combine the two functions into a scons Action object. 963config_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 964 965# The emitter munges the source & target node lists to reflect what 966# we're really doing. 967def config_emitter(target, source, env): 968 # extract variable name from Builder arg 969 variable = str(target[0]) 970 # True target is config header file 971 target = joinpath('config', variable.lower() + '.hh') 972 val = env[variable] 973 if isinstance(val, bool): 974 # Force value to 0/1 975 val = int(val) 976 elif isinstance(val, str): 977 val = '"' + val + '"' 978 979 # Sources are variable name & value (packaged in SCons Value nodes) 980 return ([target], [Value(variable), Value(val)]) 981 982config_builder = Builder(emitter = config_emitter, action = config_action) 983 984main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 985 986# libelf build is shared across all configs in the build root. 987main.SConscript('ext/libelf/SConscript', 988 variant_dir = joinpath(build_root, 'libelf')) 989 990# gzstream build is shared across all configs in the build root. 991main.SConscript('ext/gzstream/SConscript', 992 variant_dir = joinpath(build_root, 'gzstream')) 993 994################################################### 995# 996# This function is used to set up a directory with switching headers 997# 998################################################### 999 1000main['ALL_ISA_LIST'] = all_isa_list 1001def make_switching_dir(dname, switch_headers, env): 1002 # Generate the header. target[0] is the full path of the output 1003 # header to generate. 'source' is a dummy variable, since we get the 1004 # list of ISAs from env['ALL_ISA_LIST']. 1005 def gen_switch_hdr(target, source, env): 1006 fname = str(target[0]) 1007 f = open(fname, 'w') 1008 isa = env['TARGET_ISA'].lower() 1009 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 1010 f.close() 1011 1012 # Build SCons Action object. 'varlist' specifies env vars that this 1013 # action depends on; when env['ALL_ISA_LIST'] changes these actions 1014 # should get re-executed. 1015 switch_hdr_action = MakeAction(gen_switch_hdr, 1016 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 1017 1018 # Instantiate actions for each header 1019 for hdr in switch_headers: 1020 env.Command(hdr, [], switch_hdr_action) 1021Export('make_switching_dir') 1022 1023################################################### 1024# 1025# Define build environments for selected configurations. 1026# 1027################################################### 1028 1029for variant_path in variant_paths: 1030 print "Building in", variant_path 1031 1032 # Make a copy of the build-root environment to use for this config. 1033 env = main.Clone() 1034 env['BUILDDIR'] = variant_path 1035 1036 # variant_dir is the tail component of build path, and is used to 1037 # determine the build parameters (e.g., 'ALPHA_SE') 1038 (build_root, variant_dir) = splitpath(variant_path) 1039 1040 # Set env variables according to the build directory config. 1041 sticky_vars.files = [] 1042 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 1043 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 1044 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 1045 current_vars_file = joinpath(build_root, 'variables', variant_dir) 1046 if isfile(current_vars_file): 1047 sticky_vars.files.append(current_vars_file) 1048 print "Using saved variables file %s" % current_vars_file 1049 else: 1050 # Build dir-specific variables file doesn't exist. 1051 1052 # Make sure the directory is there so we can create it later 1053 opt_dir = dirname(current_vars_file) 1054 if not isdir(opt_dir): 1055 mkdir(opt_dir) 1056 1057 # Get default build variables from source tree. Variables are 1058 # normally determined by name of $VARIANT_DIR, but can be 1059 # overridden by '--default=' arg on command line. 1060 default = GetOption('default') 1061 opts_dir = joinpath(main.root.abspath, 'build_opts') 1062 if default: 1063 default_vars_files = [joinpath(build_root, 'variables', default), 1064 joinpath(opts_dir, default)] 1065 else: 1066 default_vars_files = [joinpath(opts_dir, variant_dir)] 1067 existing_files = filter(isfile, default_vars_files) 1068 if existing_files: 1069 default_vars_file = existing_files[0] 1070 sticky_vars.files.append(default_vars_file) 1071 print "Variables file %s not found,\n using defaults in %s" \ 1072 % (current_vars_file, default_vars_file) 1073 else: 1074 print "Error: cannot find variables file %s or " \ 1075 "default file(s) %s" \ 1076 % (current_vars_file, ' or '.join(default_vars_files)) 1077 Exit(1) 1078 1079 # Apply current variable settings to env 1080 sticky_vars.Update(env) 1081 1082 help_texts["local_vars"] += \ 1083 "Build variables for %s:\n" % variant_dir \ 1084 + sticky_vars.GenerateHelpText(env) 1085 1086 # Process variable settings. 1087 1088 if not have_fenv and env['USE_FENV']: 1089 print "Warning: <fenv.h> not available; " \ 1090 "forcing USE_FENV to False in", variant_dir + "." 1091 env['USE_FENV'] = False 1092 1093 if not env['USE_FENV']: 1094 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 1095 print " FP results may deviate slightly from other platforms." 1096 1097 if env['EFENCE']: 1098 env.Append(LIBS=['efence']) 1099 1100 # Save sticky variable settings back to current variables file 1101 sticky_vars.Save(current_vars_file, env) 1102 1103 if env['USE_SSE2']: 1104 env.Append(CCFLAGS=['-msse2']) 1105 1106 if have_tcmalloc: 1107 env.Append(LIBS=['tcmalloc_minimal']) 1108 1109 # The src/SConscript file sets up the build rules in 'env' according 1110 # to the configured variables. It returns a list of environments, 1111 # one for each variant build (debug, opt, etc.) 1112 envList = SConscript('src/SConscript', variant_dir = variant_path, 1113 exports = 'env') 1114 1115 # Set up the regression tests for each build. 1116 for e in envList: 1117 SConscript('tests/SConscript', 1118 variant_dir = joinpath(variant_path, 'tests', e.Label), 1119 exports = { 'env' : e }, duplicate = False) 1120 1121# base help text 1122Help(''' 1123Usage: scons [scons options] [build variables] [target(s)] 1124 1125Extra scons options: 1126%(options)s 1127 1128Global build variables: 1129%(global_vars)s 1130 1131%(local_vars)s 1132''' % help_texts) 1133