SConstruct revision 9255
16657Snate@binkert.org# -*- mode:python -*- 26657Snate@binkert.org 36657Snate@binkert.org# Copyright (c) 2011 Advanced Micro Devices, Inc. 46657Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 56657Snate@binkert.org# Copyright (c) 2004-2005 The Regents of The University of Michigan 66657Snate@binkert.org# All rights reserved. 76657Snate@binkert.org# 86657Snate@binkert.org# Redistribution and use in source and binary forms, with or without 96657Snate@binkert.org# modification, are permitted provided that the following conditions are 106657Snate@binkert.org# met: redistributions of source code must retain the above copyright 116657Snate@binkert.org# notice, this list of conditions and the following disclaimer; 126657Snate@binkert.org# redistributions in binary form must reproduce the above copyright 136657Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 146657Snate@binkert.org# documentation and/or other materials provided with the distribution; 156657Snate@binkert.org# neither the name of the copyright holders nor the names of its 166657Snate@binkert.org# contributors may be used to endorse or promote products derived from 176657Snate@binkert.org# this software without specific prior written permission. 186657Snate@binkert.org# 196657Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 206657Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 216657Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 226657Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 236657Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 246657Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 256657Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 266657Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 276657Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 286999Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 296657Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 306657Snate@binkert.org# 316657Snate@binkert.org# Authors: Steve Reinhardt 326657Snate@binkert.org# Nathan Binkert 338189SLisa.Hsu@amd.com 346657Snate@binkert.org################################################### 356882SBrad.Beckmann@amd.com# 367055Snate@binkert.org# SCons top-level build description (SConstruct) file. 376882SBrad.Beckmann@amd.com# 386882SBrad.Beckmann@amd.com# While in this directory ('gem5'), just type 'scons' to build the default 398191SLisa.Hsu@amd.com# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 406882SBrad.Beckmann@amd.com# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 416882SBrad.Beckmann@amd.com# the optimized full-system version). 426882SBrad.Beckmann@amd.com# 436888SBrad.Beckmann@amd.com# You can build gem5 in a different directory as long as there is a 446882SBrad.Beckmann@amd.com# 'build/<CONFIG>' somewhere along the target path. The build system 456882SBrad.Beckmann@amd.com# expects that all configs under the same build directory are being 466657Snate@binkert.org# built for the same host system. 476657Snate@binkert.org# 486657Snate@binkert.org# Examples: 496657Snate@binkert.org# 506657Snate@binkert.org# The following two commands are equivalent. The '-u' option tells 517839Snilay@cs.wisc.edu# scons to search up the directory tree for this SConstruct file. 526657Snate@binkert.org# % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug 536882SBrad.Beckmann@amd.com# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug 546882SBrad.Beckmann@amd.com# 556882SBrad.Beckmann@amd.com# The following two commands are equivalent and demonstrate building 566882SBrad.Beckmann@amd.com# in a directory outside of the source tree. The '-C' option tells 576882SBrad.Beckmann@amd.com# scons to chdir to the specified directory to find this SConstruct 586882SBrad.Beckmann@amd.com# file. 596657Snate@binkert.org# % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 606657Snate@binkert.org# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug 616657Snate@binkert.org# 626657Snate@binkert.org# You can use 'scons -H' to print scons options. If you're in this 636657Snate@binkert.org# 'gem5' directory (or use -u or -C to tell scons where to find this 646657Snate@binkert.org# file), you can use 'scons -h' to print all the gem5-specific build 656657Snate@binkert.org# options as well. 666657Snate@binkert.org# 676657Snate@binkert.org################################################### 687839Snilay@cs.wisc.edu 697839Snilay@cs.wisc.edu# Check for recent-enough Python and SCons versions. 706657Snate@binkert.orgtry: 716657Snate@binkert.org # Really old versions of scons only take two options for the 726657Snate@binkert.org # function, so check once without the revision and once with the 736657Snate@binkert.org # revision, the first instance will fail for stuff other than 746657Snate@binkert.org # 0.98, and the second will fail for 0.98.0 756657Snate@binkert.org EnsureSConsVersion(0, 98) 766657Snate@binkert.org EnsureSConsVersion(0, 98, 1) 776657Snate@binkert.orgexcept SystemExit, e: 786657Snate@binkert.org print """ 796657Snate@binkert.orgFor more details, see: 806657Snate@binkert.org http://gem5.org/Dependencies 816657Snate@binkert.org""" 826657Snate@binkert.org raise 836657Snate@binkert.org 846657Snate@binkert.org# We ensure the python version early because we have stuff that 856657Snate@binkert.org# requires python 2.4 866657Snate@binkert.orgtry: 876657Snate@binkert.org EnsurePythonVersion(2, 4) 886657Snate@binkert.orgexcept SystemExit, e: 896657Snate@binkert.org print """ 906779SBrad.Beckmann@amd.comYou can use a non-default installation of the Python interpreter by 916657Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 926657Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter 936657Snate@binkert.orgon the scons script. 946657Snate@binkert.org 956657Snate@binkert.orgFor more details, see: 966657Snate@binkert.org http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 976657Snate@binkert.org""" 986657Snate@binkert.org raise 996657Snate@binkert.org 1006657Snate@binkert.org# Global Python includes 1016657Snate@binkert.orgimport os 1026657Snate@binkert.orgimport re 1036657Snate@binkert.orgimport subprocess 1046657Snate@binkert.orgimport sys 1056657Snate@binkert.org 1066657Snate@binkert.orgfrom os import mkdir, environ 1076657Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1086657Snate@binkert.orgfrom os.path import exists, isdir, isfile 1096657Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1106657Snate@binkert.org 1116657Snate@binkert.org# SCons includes 1126657Snate@binkert.orgimport SCons 1136657Snate@binkert.orgimport SCons.Node 1146657Snate@binkert.org 1157839Snilay@cs.wisc.eduextra_python_paths = [ 1167839Snilay@cs.wisc.edu Dir('src/python').srcnode().abspath, # gem5 includes 1177839Snilay@cs.wisc.edu Dir('ext/ply').srcnode().abspath, # ply is used by several files 1187839Snilay@cs.wisc.edu ] 1197839Snilay@cs.wisc.edu 1207839Snilay@cs.wisc.edusys.path[1:1] = extra_python_paths 1217839Snilay@cs.wisc.edu 1227839Snilay@cs.wisc.edufrom m5.util import compareVersions, readCommand 1237839Snilay@cs.wisc.edufrom m5.util.terminal import get_termcap 1247839Snilay@cs.wisc.edu 1257839Snilay@cs.wisc.eduhelp_texts = { 1267839Snilay@cs.wisc.edu "options" : "", 1277839Snilay@cs.wisc.edu "global_vars" : "", 1287839Snilay@cs.wisc.edu "local_vars" : "" 1297839Snilay@cs.wisc.edu} 1306657Snate@binkert.org 1316657Snate@binkert.orgExport("help_texts") 1326657Snate@binkert.org 1336657Snate@binkert.org 1346657Snate@binkert.org# There's a bug in scons in that (1) by default, the help texts from 1356657Snate@binkert.org# AddOption() are supposed to be displayed when you type 'scons -h' 1366657Snate@binkert.org# and (2) you can override the help displayed by 'scons -h' using the 1376657Snate@binkert.org# Help() function, but these two features are incompatible: once 1386657Snate@binkert.org# you've overridden the help text using Help(), there's no way to get 1396657Snate@binkert.org# at the help texts from AddOptions. See: 1406657Snate@binkert.org# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1416657Snate@binkert.org# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1426657Snate@binkert.org# This hack lets us extract the help text from AddOptions and 1436657Snate@binkert.org# re-inject it via Help(). Ideally someday this bug will be fixed and 1446657Snate@binkert.org# we can just use AddOption directly. 1456657Snate@binkert.orgdef AddLocalOption(*args, **kwargs): 1466657Snate@binkert.org col_width = 30 1476657Snate@binkert.org 1486657Snate@binkert.org help = " " + ", ".join(args) 1496657Snate@binkert.org if "help" in kwargs: 1506657Snate@binkert.org length = len(help) 1516657Snate@binkert.org if length >= col_width: 1526657Snate@binkert.org help += "\n" + " " * col_width 1536657Snate@binkert.org else: 1546657Snate@binkert.org help += " " * (col_width - length) 1556657Snate@binkert.org help += kwargs["help"] 1566657Snate@binkert.org help_texts["options"] += help + "\n" 1576657Snate@binkert.org 1586657Snate@binkert.org AddOption(*args, **kwargs) 1596657Snate@binkert.org 1606657Snate@binkert.orgAddLocalOption('--colors', dest='use_colors', action='store_true', 1616877Ssteve.reinhardt@amd.com help="Add color to abbreviated scons output") 1626657Snate@binkert.orgAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1636657Snate@binkert.org help="Don't add color to abbreviated scons output") 1646657Snate@binkert.orgAddLocalOption('--default', dest='default', type='string', action='store', 1656657Snate@binkert.org help='Override which build_opts file to use for defaults') 1666657Snate@binkert.orgAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1676657Snate@binkert.org help='Disable style checking hooks') 1687542SBrad.Beckmann@amd.comAddLocalOption('--no-lto', dest='no_lto', action='store_true', 1697542SBrad.Beckmann@amd.com help='Disable Link-Time Optimization for fast') 1706657Snate@binkert.orgAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1716877Ssteve.reinhardt@amd.com help='Update test reference outputs') 1726999Snate@binkert.orgAddLocalOption('--verbose', dest='verbose', action='store_true', 1736877Ssteve.reinhardt@amd.com help='Print full tool command lines') 1746877Ssteve.reinhardt@amd.com 1756877Ssteve.reinhardt@amd.comtermcap = get_termcap(GetOption('use_colors')) 1766877Ssteve.reinhardt@amd.com 1776877Ssteve.reinhardt@amd.com######################################################################## 1786877Ssteve.reinhardt@amd.com# 1796877Ssteve.reinhardt@amd.com# Set up the main build environment. 1806877Ssteve.reinhardt@amd.com# 1816877Ssteve.reinhardt@amd.com######################################################################## 1826877Ssteve.reinhardt@amd.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 1836877Ssteve.reinhardt@amd.com 'LIBRARY_PATH', 'PATH', 'PYTHONPATH', 'RANLIB', 'SWIG' ]) 1846877Ssteve.reinhardt@amd.com 1856877Ssteve.reinhardt@amd.comuse_env = {} 1866877Ssteve.reinhardt@amd.comfor key,val in os.environ.iteritems(): 1876877Ssteve.reinhardt@amd.com if key in use_vars or key.startswith("M5"): 1886877Ssteve.reinhardt@amd.com use_env[key] = val 1896882SBrad.Beckmann@amd.com 1906882SBrad.Beckmann@amd.commain = Environment(ENV=use_env) 1916882SBrad.Beckmann@amd.commain.Decider('MD5-timestamp') 1926882SBrad.Beckmann@amd.commain.root = Dir(".") # The current directory (where this file lives). 1936882SBrad.Beckmann@amd.commain.srcdir = Dir("src") # The source directory 1946882SBrad.Beckmann@amd.com 1956882SBrad.Beckmann@amd.commain_dict_keys = main.Dictionary().keys() 1966877Ssteve.reinhardt@amd.com 1976877Ssteve.reinhardt@amd.com# Check that we have a C/C++ compiler 1986877Ssteve.reinhardt@amd.comif not ('CC' in main_dict_keys and 'CXX' in main_dict_keys): 1996877Ssteve.reinhardt@amd.com print "No C++ compiler installed (package g++ on Ubuntu and RedHat)" 2006657Snate@binkert.org Exit(1) 2016657Snate@binkert.org 2026999Snate@binkert.org# Check that swig is present 2036657Snate@binkert.orgif not 'SWIG' in main_dict_keys: 2046657Snate@binkert.org print "swig is not installed (package swig on Ubuntu and RedHat)" 2056657Snate@binkert.org Exit(1) 2066657Snate@binkert.org 2076657Snate@binkert.org# add useful python code PYTHONPATH so it can be used by subprocesses 2086657Snate@binkert.org# as well 2097007Snate@binkert.orgmain.AppendENVPath('PYTHONPATH', extra_python_paths) 2106657Snate@binkert.org 2116657Snate@binkert.org######################################################################## 2126657Snate@binkert.org# 2136657Snate@binkert.org# Mercurial Stuff. 2146657Snate@binkert.org# 2157007Snate@binkert.org# If the gem5 directory is a mercurial repository, we should do some 2167007Snate@binkert.org# extra things. 2176657Snate@binkert.org# 2187002Snate@binkert.org######################################################################## 2197002Snate@binkert.org 2207002Snate@binkert.orghgdir = main.root.Dir(".hg") 2217002Snate@binkert.org 2228229Snate@binkert.orgmercurial_style_message = """ 2238229Snate@binkert.orgYou're missing the gem5 style hook, which automatically checks your code 2246657Snate@binkert.orgagainst the gem5 style rules on hg commit and qrefresh commands. This 2256657Snate@binkert.orgscript will now install the hook in your .hg/hgrc file. 2268229Snate@binkert.orgPress enter to continue, or ctrl-c to abort: """ 2278229Snate@binkert.org 2288229Snate@binkert.orgmercurial_style_hook = """ 2298229Snate@binkert.org# The following lines were automatically added by gem5/SConstruct 2306657Snate@binkert.org# to provide the gem5 style-checking hooks 2316657Snate@binkert.org[extensions] 2326657Snate@binkert.orgstyle = %s/util/style.py 2336657Snate@binkert.org 2346793SBrad.Beckmann@amd.com[hooks] 2356657Snate@binkert.orgpretxncommit.style = python:style.check_style 2366657Snate@binkert.orgpre-qrefresh.style = python:style.check_style 2376657Snate@binkert.org# End of SConstruct additions 2386657Snate@binkert.org 2396657Snate@binkert.org""" % (main.root.abspath) 2407002Snate@binkert.org 2416657Snate@binkert.orgmercurial_lib_not_found = """ 2427007Snate@binkert.orgMercurial libraries cannot be found, ignoring style hook. If 2437007Snate@binkert.orgyou are a gem5 developer, please fix this and run the style 2447007Snate@binkert.orghook. It is important. 2457007Snate@binkert.org""" 2467007Snate@binkert.org 2476657Snate@binkert.org# Check for style hook and prompt for installation if it's not there. 2486877Ssteve.reinhardt@amd.com# Skip this if --ignore-style was specified, there's no .hg dir to 2496877Ssteve.reinhardt@amd.com# install a hook in, or there's no interactive terminal to prompt. 2506657Snate@binkert.orgif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2516877Ssteve.reinhardt@amd.com style_hook = True 2526657Snate@binkert.org try: 2536657Snate@binkert.org from mercurial import ui 2547002Snate@binkert.org ui = ui.ui() 2557002Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2566657Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2577567SBrad.Beckmann@amd.com ui.config('hooks', 'pre-qrefresh.style', None) 2587567SBrad.Beckmann@amd.com except ImportError: 2597922SBrad.Beckmann@amd.com print mercurial_lib_not_found 2606881SBrad.Beckmann@amd.com 2617002Snate@binkert.org if not style_hook: 2627002Snate@binkert.org print mercurial_style_message, 2636657Snate@binkert.org # continue unless user does ctrl-c/ctrl-d etc. 2647002Snate@binkert.org try: 2656902SBrad.Beckmann@amd.com raw_input() 2666863Sdrh5@cs.wisc.edu except: 2676863Sdrh5@cs.wisc.edu print "Input exception, exiting scons.\n" 2687007Snate@binkert.org sys.exit(1) 2696657Snate@binkert.org hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2706657Snate@binkert.org print "Adding style hook to", hgrc_path, "\n" 2716657Snate@binkert.org try: 2726657Snate@binkert.org hgrc = open(hgrc_path, 'a') 2736657Snate@binkert.org hgrc.write(mercurial_style_hook) 2746657Snate@binkert.org hgrc.close() 2756882SBrad.Beckmann@amd.com except: 2766882SBrad.Beckmann@amd.com print "Error updating", hgrc_path 2776882SBrad.Beckmann@amd.com sys.exit(1) 2786882SBrad.Beckmann@amd.com 2796657Snate@binkert.org 2806657Snate@binkert.org################################################### 2816657Snate@binkert.org# 2826657Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 2837007Snate@binkert.org# the target(s). 2847839Snilay@cs.wisc.edu# 2857839Snilay@cs.wisc.edu################################################### 2867839Snilay@cs.wisc.edu 2877839Snilay@cs.wisc.edu# Find default configuration & binary. 2887839Snilay@cs.wisc.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2897839Snilay@cs.wisc.edu 2907839Snilay@cs.wisc.edu# helper function: find last occurrence of element in list 2917839Snilay@cs.wisc.edudef rfind(l, elt, offs = -1): 2927839Snilay@cs.wisc.edu for i in range(len(l)+offs, 0, -1): 2937839Snilay@cs.wisc.edu if l[i] == elt: 2947839Snilay@cs.wisc.edu return i 2957839Snilay@cs.wisc.edu raise ValueError, "element not found" 2967007Snate@binkert.org 2977007Snate@binkert.org# Take a list of paths (or SCons Nodes) and return a list with all 2987007Snate@binkert.org# paths made absolute and ~-expanded. Paths will be interpreted 2997007Snate@binkert.org# relative to the launch directory unless a different root is provided 3007007Snate@binkert.orgdef makePathListAbsolute(path_list, root=GetLaunchDir()): 3017839Snilay@cs.wisc.edu return [abspath(joinpath(root, expanduser(str(p)))) 3027839Snilay@cs.wisc.edu for p in path_list] 3037839Snilay@cs.wisc.edu 3047839Snilay@cs.wisc.edu# Each target must have 'build' in the interior of the path; the 3057839Snilay@cs.wisc.edu# directory below this will determine the build parameters. For 3067839Snilay@cs.wisc.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 3077839Snilay@cs.wisc.edu# recognize that ALPHA_SE specifies the configuration because it 3087839Snilay@cs.wisc.edu# follow 'build' in the build path. 3097839Snilay@cs.wisc.edu 3107839Snilay@cs.wisc.edu# The funky assignment to "[:]" is needed to replace the list contents 3117839Snilay@cs.wisc.edu# in place rather than reassign the symbol to a new list, which 3127839Snilay@cs.wisc.edu# doesn't work (obviously!). 3137007Snate@binkert.orgBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 3147007Snate@binkert.org 3157002Snate@binkert.org# Generate a list of the unique build roots and configs that the 3166657Snate@binkert.org# collected targets reference. 3176657Snate@binkert.orgvariant_paths = [] 3186657Snate@binkert.orgbuild_root = None 3197055Snate@binkert.orgfor t in BUILD_TARGETS: 3206657Snate@binkert.org path_dirs = t.split('/') 3216657Snate@binkert.org try: 3226657Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 3236863Sdrh5@cs.wisc.edu except: 3247055Snate@binkert.org print "Error: no non-leaf 'build' dir found on target path", t 3257567SBrad.Beckmann@amd.com Exit(1) 3267567SBrad.Beckmann@amd.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3277567SBrad.Beckmann@amd.com if not build_root: 3287567SBrad.Beckmann@amd.com build_root = this_build_root 3297567SBrad.Beckmann@amd.com else: 3307542SBrad.Beckmann@amd.com if this_build_root != build_root: 3317542SBrad.Beckmann@amd.com print "Error: build targets not under same build root\n"\ 3326657Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 3337007Snate@binkert.org Exit(1) 3346657Snate@binkert.org variant_path = joinpath('/',*path_dirs[:build_top+2]) 3356657Snate@binkert.org if variant_path not in variant_paths: 3366657Snate@binkert.org variant_paths.append(variant_path) 3376657Snate@binkert.org 3386657Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 3396657Snate@binkert.orgif not isdir(build_root): 3406657Snate@binkert.org mkdir(build_root) 3416657Snate@binkert.orgmain['BUILDROOT'] = build_root 3427839Snilay@cs.wisc.edu 3437839Snilay@cs.wisc.eduExport('main') 3447839Snilay@cs.wisc.edu 3457839Snilay@cs.wisc.edumain.SConsignFile(joinpath(build_root, "sconsign")) 3467839Snilay@cs.wisc.edu 3477839Snilay@cs.wisc.edu# Default duplicate option is to use hard links, but this messes up 3487839Snilay@cs.wisc.edu# when you use emacs to edit a file in the target dir, as emacs moves 3497839Snilay@cs.wisc.edu# file to file~ then copies to file, breaking the link. Symbolic 3507839Snilay@cs.wisc.edu# (soft) links work better. 3517839Snilay@cs.wisc.edumain.SetOption('duplicate', 'soft-copy') 3527839Snilay@cs.wisc.edu 3537839Snilay@cs.wisc.edu# 3547839Snilay@cs.wisc.edu# Set up global sticky variables... these are common to an entire build 3557839Snilay@cs.wisc.edu# tree (not specific to a particular build like ALPHA_SE) 3567839Snilay@cs.wisc.edu# 3577839Snilay@cs.wisc.edu 3586657Snate@binkert.orgglobal_vars_file = joinpath(build_root, 'variables.global') 3596657Snate@binkert.org 3606657Snate@binkert.orgglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3616657Snate@binkert.org 3627839Snilay@cs.wisc.eduglobal_vars.AddVariables( 3637839Snilay@cs.wisc.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3647839Snilay@cs.wisc.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3657839Snilay@cs.wisc.edu ('SWIG', 'SWIG tool', environ.get('SWIG', main['SWIG'])), 3667839Snilay@cs.wisc.edu ('BATCH', 'Use batch pool for build and tests', False), 3677839Snilay@cs.wisc.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3687839Snilay@cs.wisc.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3697839Snilay@cs.wisc.edu ('EXTRAS', 'Add extra directories to the compilation', '') 3707839Snilay@cs.wisc.edu ) 3717839Snilay@cs.wisc.edu 3727839Snilay@cs.wisc.edu# Update main environment with values from ARGUMENTS & global_vars_file 3737839Snilay@cs.wisc.eduglobal_vars.Update(main) 3747839Snilay@cs.wisc.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3757839Snilay@cs.wisc.edu 3767839Snilay@cs.wisc.edu# Save sticky variable settings back to current variables file 3777839Snilay@cs.wisc.eduglobal_vars.Save(global_vars_file, main) 3786657Snate@binkert.org 3796657Snate@binkert.org# Parse EXTRAS variable to build list of all directories where we're 3806657Snate@binkert.org# look for sources etc. This list is exported as extras_dir_list. 3816657Snate@binkert.orgbase_dir = main.srcdir.abspath 3827007Snate@binkert.orgif main['EXTRAS']: 3836657Snate@binkert.org extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3846657Snate@binkert.orgelse: 3856657Snate@binkert.org extras_dir_list = [] 3866657Snate@binkert.org 3876657Snate@binkert.orgExport('base_dir') 3886657Snate@binkert.orgExport('extras_dir_list') 3896657Snate@binkert.org 3906657Snate@binkert.org# the ext directory should be on the #includes path 3916657Snate@binkert.orgmain.Append(CPPPATH=[Dir('ext')]) 3926657Snate@binkert.org 3937007Snate@binkert.orgdef strip_build_path(path, env): 3946657Snate@binkert.org path = str(path) 3956657Snate@binkert.org variant_base = env['BUILDROOT'] + os.path.sep 3966657Snate@binkert.org if path.startswith(variant_base): 3976657Snate@binkert.org path = path[len(variant_base):] 3986657Snate@binkert.org elif path.startswith('build/'): 3996999Snate@binkert.org path = path[6:] 4006657Snate@binkert.org return path 4016657Snate@binkert.org 4026657Snate@binkert.org# Generate a string of the form: 4036657Snate@binkert.org# common/path/prefix/src1, src2 -> tgt1, tgt2 4047007Snate@binkert.org# to print while building. 4056657Snate@binkert.orgclass Transform(object): 4066657Snate@binkert.org # all specific color settings should be here and nowhere else 4076657Snate@binkert.org tool_color = termcap.Normal 4086657Snate@binkert.org pfx_color = termcap.Yellow 4096657Snate@binkert.org srcs_color = termcap.Yellow + termcap.Bold 4107832Snate@binkert.org arrow_color = termcap.Blue + termcap.Bold 4117002Snate@binkert.org tgts_color = termcap.Yellow + termcap.Bold 4127002Snate@binkert.org 4137002Snate@binkert.org def __init__(self, tool, max_sources=99): 4148641Snate@binkert.org self.format = self.tool_color + (" [%8s] " % tool) \ 4157056Snate@binkert.org + self.pfx_color + "%s" \ 4168232Snate@binkert.org + self.srcs_color + "%s" \ 4178232Snate@binkert.org + self.arrow_color + " -> " \ 4186657Snate@binkert.org + self.tgts_color + "%s" \ 4198229Snate@binkert.org + termcap.Normal 4206657Snate@binkert.org self.max_sources = max_sources 4216657Snate@binkert.org 4227056Snate@binkert.org def __call__(self, target, source, env, for_signature=None): 4237056Snate@binkert.org # truncate source list according to max_sources param 4246657Snate@binkert.org source = source[0:self.max_sources] 4257002Snate@binkert.org def strip(f): 4267002Snate@binkert.org return strip_build_path(str(f), env) 4276657Snate@binkert.org if len(source) > 0: 4286657Snate@binkert.org srcs = map(strip, source) 4296657Snate@binkert.org else: 4306657Snate@binkert.org srcs = [''] 4316657Snate@binkert.org tgts = map(strip, target) 4326793SBrad.Beckmann@amd.com # surprisingly, os.path.commonprefix is a dumb char-by-char string 4336657Snate@binkert.org # operation that has nothing to do with paths. 4346657Snate@binkert.org com_pfx = os.path.commonprefix(srcs + tgts) 4356657Snate@binkert.org com_pfx_len = len(com_pfx) 4366657Snate@binkert.org if com_pfx: 4376877Ssteve.reinhardt@amd.com # do some cleanup and sanity checking on common prefix 4386877Ssteve.reinhardt@amd.com if com_pfx[-1] == ".": 4396877Ssteve.reinhardt@amd.com # prefix matches all but file extension: ok 4406877Ssteve.reinhardt@amd.com # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4416877Ssteve.reinhardt@amd.com com_pfx = com_pfx[0:-1] 4426877Ssteve.reinhardt@amd.com elif com_pfx[-1] == "/": 4436657Snate@binkert.org # common prefix is directory path: OK 4447542SBrad.Beckmann@amd.com pass 4456657Snate@binkert.org else: 4467007Snate@binkert.org src0_len = len(srcs[0]) 4476657Snate@binkert.org tgt0_len = len(tgts[0]) 4486657Snate@binkert.org if src0_len == com_pfx_len: 4497007Snate@binkert.org # source is a substring of target, OK 4506657Snate@binkert.org pass 4516877Ssteve.reinhardt@amd.com elif tgt0_len == com_pfx_len: 4526877Ssteve.reinhardt@amd.com # target is a substring of source, need to back up to 4536657Snate@binkert.org # avoid empty string on RHS of arrow 4546877Ssteve.reinhardt@amd.com sep_idx = com_pfx.rfind(".") 4556877Ssteve.reinhardt@amd.com if sep_idx != -1: 4566877Ssteve.reinhardt@amd.com com_pfx = com_pfx[0:sep_idx] 4576877Ssteve.reinhardt@amd.com else: 4586877Ssteve.reinhardt@amd.com com_pfx = '' 4596969SBrad.Beckmann@amd.com elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4608532SLisa.Hsu@amd.com # still splitting at file extension: ok 4616657Snate@binkert.org pass 4627567SBrad.Beckmann@amd.com else: 4637567SBrad.Beckmann@amd.com # probably a fluke; ignore it 4647567SBrad.Beckmann@amd.com com_pfx = '' 4657567SBrad.Beckmann@amd.com # recalculate length in case com_pfx was modified 4667567SBrad.Beckmann@amd.com com_pfx_len = len(com_pfx) 4677567SBrad.Beckmann@amd.com def fmt(files): 4686657Snate@binkert.org f = map(lambda s: s[com_pfx_len:], files) 4696882SBrad.Beckmann@amd.com return ', '.join(f) 4706882SBrad.Beckmann@amd.com return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4716882SBrad.Beckmann@amd.com 4726882SBrad.Beckmann@amd.comExport('Transform') 4736882SBrad.Beckmann@amd.com 4746882SBrad.Beckmann@amd.com# enable the regression script to use the termcap 4756882SBrad.Beckmann@amd.commain['TERMCAP'] = termcap 4768189SLisa.Hsu@amd.com 4778189SLisa.Hsu@amd.comif GetOption('verbose'): 4786877Ssteve.reinhardt@amd.com def MakeAction(action, string, *args, **kwargs): 4798189SLisa.Hsu@amd.com return Action(action, *args, **kwargs) 4808189SLisa.Hsu@amd.comelse: 4818189SLisa.Hsu@amd.com MakeAction = Action 4828189SLisa.Hsu@amd.com main['CCCOMSTR'] = Transform("CC") 4836882SBrad.Beckmann@amd.com main['CXXCOMSTR'] = Transform("CXX") 4846882SBrad.Beckmann@amd.com main['ASCOMSTR'] = Transform("AS") 4856882SBrad.Beckmann@amd.com main['SWIGCOMSTR'] = Transform("SWIG") 4866882SBrad.Beckmann@amd.com main['ARCOMSTR'] = Transform("AR", 0) 4876882SBrad.Beckmann@amd.com main['LINKCOMSTR'] = Transform("LINK", 0) 4886882SBrad.Beckmann@amd.com main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4896882SBrad.Beckmann@amd.com main['M4COMSTR'] = Transform("M4") 4906882SBrad.Beckmann@amd.com main['SHCCCOMSTR'] = Transform("SHCC") 4916882SBrad.Beckmann@amd.com main['SHCXXCOMSTR'] = Transform("SHCXX") 4926882SBrad.Beckmann@amd.comExport('MakeAction') 4938189SLisa.Hsu@amd.com 4946882SBrad.Beckmann@amd.com# Initialize the Link-Time Optimization (LTO) flags 4956882SBrad.Beckmann@amd.commain['LTO_CCFLAGS'] = [] 4966882SBrad.Beckmann@amd.commain['LTO_LDFLAGS'] = [] 4978189SLisa.Hsu@amd.com 4988189SLisa.Hsu@amd.comCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4998189SLisa.Hsu@amd.comCXX_V = readCommand([main['CXX'],'-V'], exception=False) 5008189SLisa.Hsu@amd.com 5016888SBrad.Beckmann@amd.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 5026888SBrad.Beckmann@amd.commain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 5036888SBrad.Beckmann@amd.commain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 5046888SBrad.Beckmann@amd.commain['CLANG'] = CXX_version and CXX_version.find('clang') >= 0 5056888SBrad.Beckmann@amd.comif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: 5068189SLisa.Hsu@amd.com print 'Error: How can we have two at the same time?' 5076888SBrad.Beckmann@amd.com Exit(1) 5086888SBrad.Beckmann@amd.com 5096657Snate@binkert.org# Set up default C++ compiler flags 5106888SBrad.Beckmann@amd.comif main['GCC']: 5116888SBrad.Beckmann@amd.com main.Append(CCFLAGS=['-pipe']) 5126888SBrad.Beckmann@amd.com main.Append(CCFLAGS=['-fno-strict-aliasing']) 5136888SBrad.Beckmann@amd.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5146657Snate@binkert.org # Read the GCC version to check for versions with bugs 5156657Snate@binkert.org # Note CCVERSION doesn't work here because it is run with the CC 5166657Snate@binkert.org # before we override it from the command line 5176657Snate@binkert.org gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5186657Snate@binkert.org main['GCC_VERSION'] = gcc_version 5196657Snate@binkert.org if not compareVersions(gcc_version, '4.4.1') or \ 5206657Snate@binkert.org not compareVersions(gcc_version, '4.4.2'): 5216657Snate@binkert.org print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5226657Snate@binkert.org main.Append(CCFLAGS=['-fno-tree-vectorize']) 5237007Snate@binkert.org # c++0x support in gcc is useful already from 4.4, see 5247007Snate@binkert.org # http://gcc.gnu.org/projects/cxx0x.html for details 5256657Snate@binkert.org if compareVersions(gcc_version, '4.4') >= 0: 5267007Snate@binkert.org main.Append(CXXFLAGS=['-std=c++0x']) 5277007Snate@binkert.org 5287007Snate@binkert.org # LTO support is only really working properly from 4.6 and beyond 5296657Snate@binkert.org if compareVersions(gcc_version, '4.6') >= 0: 5306657Snate@binkert.org # Add the appropriate Link-Time Optimization (LTO) flags 5316657Snate@binkert.org # unless LTO is explicitly turned off. Note that these flags 5327007Snate@binkert.org # are only used by the fast target. 5337542SBrad.Beckmann@amd.com if not GetOption('no_lto'): 5347542SBrad.Beckmann@amd.com # Pass the LTO flag when compiling to produce GIMPLE 5357007Snate@binkert.org # output, we merely create the flags here and only append 5366657Snate@binkert.org # them later/ 5376657Snate@binkert.org main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] 5386657Snate@binkert.org 5396657Snate@binkert.org # Use the same amount of jobs for LTO as we are running 5406657Snate@binkert.org # scons with, we hardcode the use of the linker plugin 5416657Snate@binkert.org # which requires either gold or GNU ld >= 2.21 5426657Snate@binkert.org main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'), 5436657Snate@binkert.org '-fuse-linker-plugin'] 5446657Snate@binkert.org 5456657Snate@binkert.orgelif main['ICC']: 5466657Snate@binkert.org pass #Fix me... add warning flags once we clean up icc warnings 5476657Snate@binkert.orgelif main['SUNCC']: 5486657Snate@binkert.org main.Append(CCFLAGS=['-Qoption ccfe']) 5496657Snate@binkert.org main.Append(CCFLAGS=['-features=gcc']) 5506657Snate@binkert.org main.Append(CCFLAGS=['-features=extensions']) 5516657Snate@binkert.org main.Append(CCFLAGS=['-library=stlport4']) 5526657Snate@binkert.org main.Append(CCFLAGS=['-xar']) 5536657Snate@binkert.org #main.Append(CCFLAGS=['-instances=semiexplicit']) 5546657Snate@binkert.orgelif main['CLANG']: 5556657Snate@binkert.org clang_version_re = re.compile(".* version (\d+\.\d+)") 5566657Snate@binkert.org clang_version_match = clang_version_re.match(CXX_version) 5576657Snate@binkert.org if (clang_version_match): 5586657Snate@binkert.org clang_version = clang_version_match.groups()[0] 5596657Snate@binkert.org if compareVersions(clang_version, "2.9") < 0: 5606657Snate@binkert.org print 'Error: clang version 2.9 or newer required.' 5616657Snate@binkert.org print ' Installed version:', clang_version 5626657Snate@binkert.org Exit(1) 5636657Snate@binkert.org else: 5647007Snate@binkert.org print 'Error: Unable to determine clang version.' 5656657Snate@binkert.org Exit(1) 5666657Snate@binkert.org 5676657Snate@binkert.org main.Append(CCFLAGS=['-pipe']) 5686657Snate@binkert.org main.Append(CCFLAGS=['-fno-strict-aliasing']) 5697007Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5706657Snate@binkert.org main.Append(CCFLAGS=['-Wno-tautological-compare']) 5717007Snate@binkert.org main.Append(CCFLAGS=['-Wno-self-assign']) 5727007Snate@binkert.org # Ruby makes frequent use of extraneous parantheses in the printing 5736657Snate@binkert.org # of if-statements 5746657Snate@binkert.org main.Append(CCFLAGS=['-Wno-parentheses']) 5756657Snate@binkert.org 5766657Snate@binkert.org # clang 2.9 does not play well with c++0x as it ships with C++ 5776657Snate@binkert.org # headers that produce errors, this was fixed in 3.0 5786657Snate@binkert.org if compareVersions(clang_version, "3") >= 0: 5796657Snate@binkert.org main.Append(CXXFLAGS=['-std=c++0x']) 5806657Snate@binkert.orgelse: 5816657Snate@binkert.org print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal, 5826657Snate@binkert.org print "Don't know what compiler options to use for your compiler." 5836657Snate@binkert.org print termcap.Yellow + ' compiler:' + termcap.Normal, main['CXX'] 5846657Snate@binkert.org print termcap.Yellow + ' version:' + termcap.Normal, 5856657Snate@binkert.org if not CXX_version: 5866657Snate@binkert.org print termcap.Yellow + termcap.Bold + "COMMAND NOT FOUND!" +\ 5876657Snate@binkert.org termcap.Normal 5887566SBrad.Beckmann@amd.com else: 5896657Snate@binkert.org print CXX_version.replace('\n', '<nl>') 5906657Snate@binkert.org print " If you're trying to use a compiler other than GCC, ICC, SunCC," 5916657Snate@binkert.org print " or clang, there appears to be something wrong with your" 5926657Snate@binkert.org print " environment." 5936657Snate@binkert.org print " " 5948308Stushar@csail.mit.edu print " If you are trying to use a compiler other than those listed" 5956657Snate@binkert.org print " above you will need to ease fix SConstruct and " 5966657Snate@binkert.org print " src/SConscript to support that compiler." 5976657Snate@binkert.org Exit(1) 5987007Snate@binkert.org 5997007Snate@binkert.org# Set up common yacc/bison flags (needed for Ruby) 6008308Stushar@csail.mit.edumain['YACCFLAGS'] = '-d' 6016657Snate@binkert.orgmain['YACCHXXFILESUFFIX'] = '.hh' 6026657Snate@binkert.org 6036657Snate@binkert.org# Do this after we save setting back, or else we'll tack on an 6046657Snate@binkert.org# extra 'qdo' every time we run scons. 6056657Snate@binkert.orgif main['BATCH']: 6066657Snate@binkert.org main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 6076657Snate@binkert.org main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 6086657Snate@binkert.org main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 6096657Snate@binkert.org main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 6106657Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 6116657Snate@binkert.org 6126657Snate@binkert.orgif sys.platform == 'cygwin': 6138187SLisa.Hsu@amd.com # cygwin has some header file issues... 6146657Snate@binkert.org main.Append(CCFLAGS=["-Wno-uninitialized"]) 6156657Snate@binkert.org 6166657Snate@binkert.org# Check for SWIG 6176657Snate@binkert.orgif not main.has_key('SWIG'): 6186657Snate@binkert.org print 'Error: SWIG utility not found.' 6196657Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 6206657Snate@binkert.org Exit(1) 6216657Snate@binkert.org 6226657Snate@binkert.org# Check for appropriate SWIG version 6237454Snate@binkert.orgswig_version = readCommand([main['SWIG'], '-version'], exception='').split() 6246657Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 6256657Snate@binkert.orgif len(swig_version) < 3 or \ 6266657Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 6276657Snate@binkert.org print 'Error determining SWIG version.' 6287007Snate@binkert.org Exit(1) 6297056Snate@binkert.org 6307007Snate@binkert.orgmin_swig_version = '1.3.34' 6317007Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0: 6326657Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 6337566SBrad.Beckmann@amd.com print ' Installed version:', swig_version[2] 6347566SBrad.Beckmann@amd.com Exit(1) 6357566SBrad.Beckmann@amd.com 6367566SBrad.Beckmann@amd.com# Set up SWIG flags & scanner 6377566SBrad.Beckmann@amd.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 6387566SBrad.Beckmann@amd.commain.Append(SWIGFLAGS=swig_flags) 6397566SBrad.Beckmann@amd.com 6406657Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 6417672Snate@binkert.org# stuff for some reason 6426657Snate@binkert.orgscanners = [] 6436657Snate@binkert.orgfor scanner in main['SCANNERS']: 6446657Snate@binkert.org skeys = scanner.skeys 6456657Snate@binkert.org if skeys == '.i': 6467672Snate@binkert.org continue 6476657Snate@binkert.org 6487056Snate@binkert.org if isinstance(skeys, (list, tuple)) and '.i' in skeys: 6496657Snate@binkert.org continue 6506657Snate@binkert.org 6517672Snate@binkert.org scanners.append(scanner) 6526657Snate@binkert.org 6536657Snate@binkert.org# add the new swig scanner that we like better 6546657Snate@binkert.orgfrom SCons.Scanner import ClassicCPP as CPPScanner 6556657Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 6566657Snate@binkert.orgscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 6576657Snate@binkert.org 6586657Snate@binkert.org# replace the scanners list that has what we want 6596657Snate@binkert.orgmain['SCANNERS'] = scanners 6606657Snate@binkert.org 6616657Snate@binkert.org# Add a custom Check function to the Configure context so that we can 6626657Snate@binkert.org# figure out if the compiler adds leading underscores to global 6637542SBrad.Beckmann@amd.com# variables. This is needed for the autogenerated asm files that we 6646657Snate@binkert.org# use for embedding the python code. 6656657Snate@binkert.orgdef CheckLeading(context): 6666657Snate@binkert.org context.Message("Checking for leading underscore in global variables...") 6676657Snate@binkert.org # 1) Define a global variable called x from asm so the C compiler 6686657Snate@binkert.org # won't change the symbol at all. 6696657Snate@binkert.org # 2) Declare that variable. 6706657Snate@binkert.org # 3) Use the variable 6716657Snate@binkert.org # 6726657Snate@binkert.org # If the compiler prepends an underscore, this will successfully 6736657Snate@binkert.org # link because the external symbol 'x' will be called '_x' which 6746657Snate@binkert.org # was defined by the asm statement. If the compiler does not 6756657Snate@binkert.org # prepend an underscore, this will not successfully link because 6766657Snate@binkert.org # '_x' will have been defined by assembly, while the C portion of 6776657Snate@binkert.org # the code will be trying to use 'x' 6786657Snate@binkert.org ret = context.TryLink(''' 6797007Snate@binkert.org asm(".globl _x; _x: .byte 0"); 6807007Snate@binkert.org extern int x; 6817007Snate@binkert.org int main() { return x; } 6826657Snate@binkert.org ''', extension=".c") 6836657Snate@binkert.org context.env.Append(LEADING_UNDERSCORE=ret) 6846657Snate@binkert.org context.Result(ret) 6857007Snate@binkert.org return ret 6867007Snate@binkert.org 6877007Snate@binkert.org# Test for the presence of C++11 static asserts. If the compiler lacks 6886657Snate@binkert.org# support for static asserts, base/compiler.hh enables a macro that 6896657Snate@binkert.org# removes any static asserts in the code. 6906657Snate@binkert.orgdef CheckStaticAssert(context): 6917007Snate@binkert.org context.Message("Checking for C++11 static_assert support...") 6927007Snate@binkert.org ret = context.TryCompile(''' 6937007Snate@binkert.org static_assert(1, "This assert is always true"); 6946657Snate@binkert.org ''', extension=".cc") 6956657Snate@binkert.org context.env.Append(HAVE_STATIC_ASSERT=ret) 6966657Snate@binkert.org context.Result(ret) 6977007Snate@binkert.org return ret 6987007Snate@binkert.org 6997007Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 7006657Snate@binkert.org# builds under a given build root run on the same host platform. 7016657Snate@binkert.orgconf = Configure(main, 7026657Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 7037007Snate@binkert.org log_file = joinpath(build_root, 'scons_config.log'), 7047007Snate@binkert.org custom_tests = { 'CheckLeading' : CheckLeading, 7057007Snate@binkert.org 'CheckStaticAssert' : CheckStaticAssert, 7066657Snate@binkert.org }) 7076657Snate@binkert.org 7087007Snate@binkert.org# Check for leading underscores. Don't really need to worry either 7097007Snate@binkert.org# way so don't need to check the return code. 7107007Snate@binkert.orgconf.CheckLeading() 7117007Snate@binkert.org 7126657Snate@binkert.org# Check for C++11 features we want to use if they exist 7136657Snate@binkert.orgconf.CheckStaticAssert() 7146657Snate@binkert.org 7157007Snate@binkert.org# Check if we should compile a 64 bit binary on Mac OS X/Darwin 7167567SBrad.Beckmann@amd.comtry: 7177567SBrad.Beckmann@amd.com import platform 7187567SBrad.Beckmann@amd.com uname = platform.uname() 7197567SBrad.Beckmann@amd.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 7207567SBrad.Beckmann@amd.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 7217567SBrad.Beckmann@amd.com main.Append(CCFLAGS=['-arch', 'x86_64']) 7227567SBrad.Beckmann@amd.com main.Append(CFLAGS=['-arch', 'x86_64']) 7237567SBrad.Beckmann@amd.com main.Append(LINKFLAGS=['-arch', 'x86_64']) 7247567SBrad.Beckmann@amd.com main.Append(ASFLAGS=['-arch', 'x86_64']) 7257567SBrad.Beckmann@amd.comexcept: 7267567SBrad.Beckmann@amd.com pass 7277567SBrad.Beckmann@amd.com 7287567SBrad.Beckmann@amd.com# Recent versions of scons substitute a "Null" object for Configure() 7298155Snilay@cs.wisc.edu# when configuration isn't necessary, e.g., if the "--help" option is 7308155Snilay@cs.wisc.edu# present. Unfortuantely this Null object always returns false, 7318155Snilay@cs.wisc.edu# breaking all our configuration checks. We replace it with our own 7328155Snilay@cs.wisc.edu# more optimistic null object that returns True instead. 7338155Snilay@cs.wisc.eduif not conf: 7348155Snilay@cs.wisc.edu def NullCheck(*args, **kwargs): 7358155Snilay@cs.wisc.edu return True 7368155Snilay@cs.wisc.edu 7378155Snilay@cs.wisc.edu class NullConf: 7388155Snilay@cs.wisc.edu def __init__(self, env): 7398155Snilay@cs.wisc.edu self.env = env 7407567SBrad.Beckmann@amd.com def Finish(self): 7418155Snilay@cs.wisc.edu return self.env 7428155Snilay@cs.wisc.edu def __getattr__(self, mname): 7437567SBrad.Beckmann@amd.com return NullCheck 7447567SBrad.Beckmann@amd.com 7457567SBrad.Beckmann@amd.com conf = NullConf(main) 7467567SBrad.Beckmann@amd.com 7477922SBrad.Beckmann@amd.com# Find Python include and library directories for embedding the 7487922SBrad.Beckmann@amd.com# interpreter. For consistency, we will use the same Python 7497922SBrad.Beckmann@amd.com# installation used to run scons (and thus this script). If you want 7507922SBrad.Beckmann@amd.com# to link in an alternate version, see above for instructions on how 7517922SBrad.Beckmann@amd.com# to invoke scons with a different copy of the Python interpreter. 7527922SBrad.Beckmann@amd.comfrom distutils import sysconfig 7537922SBrad.Beckmann@amd.com 7547922SBrad.Beckmann@amd.compy_getvar = sysconfig.get_config_var 7558154Snilay@cs.wisc.edu 7568154Snilay@cs.wisc.edupy_debug = getattr(sys, 'pydebug', False) 7578154Snilay@cs.wisc.edupy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 7588154Snilay@cs.wisc.edu 7598154Snilay@cs.wisc.edupy_general_include = sysconfig.get_python_inc() 7608154Snilay@cs.wisc.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True) 7618154Snilay@cs.wisc.edupy_includes = [ py_general_include ] 7628154Snilay@cs.wisc.eduif py_platform_include != py_general_include: 7638154Snilay@cs.wisc.edu py_includes.append(py_platform_include) 7648154Snilay@cs.wisc.edu 7658154Snilay@cs.wisc.edupy_lib_path = [ py_getvar('LIBDIR') ] 7668154Snilay@cs.wisc.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no 7678154Snilay@cs.wisc.edu# shared library in prefix/lib/. 7688154Snilay@cs.wisc.eduif not py_getvar('Py_ENABLE_SHARED'): 7698154Snilay@cs.wisc.edu py_lib_path.append(py_getvar('LIBPL')) 7708154Snilay@cs.wisc.edu 7718154Snilay@cs.wisc.edupy_libs = [] 7728154Snilay@cs.wisc.edufor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 7738154Snilay@cs.wisc.edu if not lib.startswith('-l'): 7748154Snilay@cs.wisc.edu # Python requires some special flags to link (e.g. -framework 7758154Snilay@cs.wisc.edu # common on OS X systems), assume appending preserves order 7767922SBrad.Beckmann@amd.com main.Append(LINKFLAGS=[lib]) 7777922SBrad.Beckmann@amd.com else: 7787922SBrad.Beckmann@amd.com lib = lib[2:] 7797922SBrad.Beckmann@amd.com if lib not in py_libs: 7807007Snate@binkert.org py_libs.append(lib) 7817007Snate@binkert.orgpy_libs.append(py_version) 7826863Sdrh5@cs.wisc.edu 7836863Sdrh5@cs.wisc.edumain.Append(CPPPATH=py_includes) 7846863Sdrh5@cs.wisc.edumain.Append(LIBPATH=py_lib_path) 7857007Snate@binkert.org 7867007Snate@binkert.org# Cache build files in the supplied directory. 7877007Snate@binkert.orgif main['M5_BUILD_CACHE']: 7887007Snate@binkert.org print 'Using build cache located at', main['M5_BUILD_CACHE'] 7896863Sdrh5@cs.wisc.edu CacheDir(main['M5_BUILD_CACHE']) 7906863Sdrh5@cs.wisc.edu 7916863Sdrh5@cs.wisc.edu 7926863Sdrh5@cs.wisc.edu# verify that this stuff works 7936863Sdrh5@cs.wisc.eduif not conf.CheckHeader('Python.h', '<>'): 7946863Sdrh5@cs.wisc.edu print "Error: can't find Python.h header in", py_includes 7957007Snate@binkert.org print "Install Python headers (package python-dev on Ubuntu and RedHat)" 7967007Snate@binkert.org Exit(1) 7977007Snate@binkert.org 7987007Snate@binkert.orgfor lib in py_libs: 7997007Snate@binkert.org if not conf.CheckLib(lib): 8006657Snate@binkert.org print "Error: can't find library %s required by python" % lib 8017007Snate@binkert.org Exit(1) 8027007Snate@binkert.org 8037007Snate@binkert.org# On Solaris you need to use libsocket for socket ops 8046657Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 8056657Snate@binkert.org if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 8067007Snate@binkert.org print "Can't find library with socket calls (e.g. accept())" 8077007Snate@binkert.org Exit(1) 8087007Snate@binkert.org 8096657Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 8106657Snate@binkert.org# added to the LIBS environment variable. 8117007Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 8127007Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 8137007Snate@binkert.org 'and/or zlib.h header file.' 8146902SBrad.Beckmann@amd.com print ' Please install zlib and try again.' 8156902SBrad.Beckmann@amd.com Exit(1) 8166902SBrad.Beckmann@amd.com 8176902SBrad.Beckmann@amd.com# Check for librt. 8186902SBrad.Beckmann@amd.comhave_posix_clock = \ 8196902SBrad.Beckmann@amd.com conf.CheckLibWithHeader(None, 'time.h', 'C', 8206902SBrad.Beckmann@amd.com 'clock_nanosleep(0,0,NULL,NULL);') or \ 8217025SBrad.Beckmann@amd.com conf.CheckLibWithHeader('rt', 'time.h', 'C', 8226902SBrad.Beckmann@amd.com 'clock_nanosleep(0,0,NULL,NULL);') 8236902SBrad.Beckmann@amd.com 8246902SBrad.Beckmann@amd.comif conf.CheckLib('tcmalloc_minimal'): 8256902SBrad.Beckmann@amd.com have_tcmalloc = True 8266902SBrad.Beckmann@amd.comelse: 8277542SBrad.Beckmann@amd.com have_tcmalloc = False 8287542SBrad.Beckmann@amd.com print termcap.Yellow + termcap.Bold + \ 8297542SBrad.Beckmann@amd.com "You can get a 12% performance improvement by installing tcmalloc "\ 8306902SBrad.Beckmann@amd.com "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \ 8316902SBrad.Beckmann@amd.com termcap.Normal 8326902SBrad.Beckmann@amd.com 8336902SBrad.Beckmann@amd.comif not have_posix_clock: 8346902SBrad.Beckmann@amd.com print "Can't find library for POSIX clocks." 8356902SBrad.Beckmann@amd.com 8366902SBrad.Beckmann@amd.com# Check for <fenv.h> (C99 FP environment control) 8376902SBrad.Beckmann@amd.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 8386902SBrad.Beckmann@amd.comif not have_fenv: 8396902SBrad.Beckmann@amd.com print "Warning: Header file <fenv.h> not found." 8406902SBrad.Beckmann@amd.com print " This host has no IEEE FP rounding mode control." 8416902SBrad.Beckmann@amd.com 8426902SBrad.Beckmann@amd.com###################################################################### 8436902SBrad.Beckmann@amd.com# 8446902SBrad.Beckmann@amd.com# Finish the configuration 8457542SBrad.Beckmann@amd.com# 8466902SBrad.Beckmann@amd.commain = conf.Finish() 8477839Snilay@cs.wisc.edu 8487839Snilay@cs.wisc.edu###################################################################### 8497839Snilay@cs.wisc.edu# 8507839Snilay@cs.wisc.edu# Collect all non-global variables 8517839Snilay@cs.wisc.edu# 8527839Snilay@cs.wisc.edu 8537839Snilay@cs.wisc.edu# Define the universe of supported ISAs 8547839Snilay@cs.wisc.eduall_isa_list = [ ] 8557839Snilay@cs.wisc.eduExport('all_isa_list') 8567839Snilay@cs.wisc.edu 8577839Snilay@cs.wisc.educlass CpuModel(object): 8587839Snilay@cs.wisc.edu '''The CpuModel class encapsulates everything the ISA parser needs to 8597839Snilay@cs.wisc.edu know about a particular CPU model.''' 8607839Snilay@cs.wisc.edu 8617839Snilay@cs.wisc.edu # Dict of available CPU model objects. Accessible as CpuModel.dict. 8627839Snilay@cs.wisc.edu dict = {} 8637839Snilay@cs.wisc.edu list = [] 8647839Snilay@cs.wisc.edu defaults = [] 8657839Snilay@cs.wisc.edu 8667839Snilay@cs.wisc.edu # Constructor. Automatically adds models to CpuModel.dict. 8677839Snilay@cs.wisc.edu def __init__(self, name, filename, includes, strings, default=False): 8687839Snilay@cs.wisc.edu self.name = name # name of model 8697839Snilay@cs.wisc.edu self.filename = filename # filename for output exec code 8707839Snilay@cs.wisc.edu self.includes = includes # include files needed in exec file 8717839Snilay@cs.wisc.edu # The 'strings' dict holds all the per-CPU symbols we can 8727839Snilay@cs.wisc.edu # substitute into templates etc. 8737839Snilay@cs.wisc.edu self.strings = strings 8747839Snilay@cs.wisc.edu 8757839Snilay@cs.wisc.edu # This cpu is enabled by default 8767839Snilay@cs.wisc.edu self.default = default 8777839Snilay@cs.wisc.edu 8787839Snilay@cs.wisc.edu # Add self to dict 8797839Snilay@cs.wisc.edu if name in CpuModel.dict: 8807839Snilay@cs.wisc.edu raise AttributeError, "CpuModel '%s' already registered" % name 8817839Snilay@cs.wisc.edu CpuModel.dict[name] = self 8827839Snilay@cs.wisc.edu CpuModel.list.append(name) 8837839Snilay@cs.wisc.edu 8846902SBrad.Beckmann@amd.comExport('CpuModel') 8856657Snate@binkert.org 8866657Snate@binkert.org# Sticky variables get saved in the variables file so they persist from 8877839Snilay@cs.wisc.edu# one invocation to the next (unless overridden, in which case the new 8887839Snilay@cs.wisc.edu# value becomes sticky). 8897839Snilay@cs.wisc.edusticky_vars = Variables(args=ARGUMENTS) 8907839Snilay@cs.wisc.eduExport('sticky_vars') 8916657Snate@binkert.org 8927839Snilay@cs.wisc.edu# Sticky variables that should be exported 8937839Snilay@cs.wisc.eduexport_vars = [] 8947839Snilay@cs.wisc.eduExport('export_vars') 8957839Snilay@cs.wisc.edu 8967839Snilay@cs.wisc.edu# For Ruby 8978055Sksewell@umich.eduall_protocols = [] 8987839Snilay@cs.wisc.eduExport('all_protocols') 8997839Snilay@cs.wisc.eduprotocol_dirs = [] 9006657Snate@binkert.orgExport('protocol_dirs') 9017839Snilay@cs.wisc.eduslicc_includes = [] 9027839Snilay@cs.wisc.eduExport('slicc_includes') 9037839Snilay@cs.wisc.edu 9047839Snilay@cs.wisc.edu# Walk the tree and execute all SConsopts scripts that wil add to the 9057839Snilay@cs.wisc.edu# above variables 9067839Snilay@cs.wisc.eduif not GetOption('verbose'): 9077839Snilay@cs.wisc.edu print "Reading SConsopts" 9087839Snilay@cs.wisc.edufor bdir in [ base_dir ] + extras_dir_list: 9097839Snilay@cs.wisc.edu if not isdir(bdir): 9107839Snilay@cs.wisc.edu print "Error: directory '%s' does not exist" % bdir 9117839Snilay@cs.wisc.edu Exit(1) 9128055Sksewell@umich.edu for root, dirs, files in os.walk(bdir): 9137839Snilay@cs.wisc.edu if 'SConsopts' in files: 9147839Snilay@cs.wisc.edu if GetOption('verbose'): 9157839Snilay@cs.wisc.edu print "Reading", joinpath(root, 'SConsopts') 9167839Snilay@cs.wisc.edu SConscript(joinpath(root, 'SConsopts')) 9177839Snilay@cs.wisc.edu 9187839Snilay@cs.wisc.eduall_isa_list.sort() 9197839Snilay@cs.wisc.edu 9207839Snilay@cs.wisc.edusticky_vars.AddVariables( 9217839Snilay@cs.wisc.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 9227839Snilay@cs.wisc.edu ListVariable('CPU_MODELS', 'CPU models', 9237839Snilay@cs.wisc.edu sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 9247839Snilay@cs.wisc.edu sorted(CpuModel.list)), 9257839Snilay@cs.wisc.edu BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 9267839Snilay@cs.wisc.edu False), 9278055Sksewell@umich.edu BoolVariable('SS_COMPATIBLE_FP', 9287839Snilay@cs.wisc.edu 'Make floating-point results compatible with SimpleScalar', 9297839Snilay@cs.wisc.edu False), 9307839Snilay@cs.wisc.edu BoolVariable('USE_SSE2', 9317839Snilay@cs.wisc.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 9327839Snilay@cs.wisc.edu False), 9337839Snilay@cs.wisc.edu BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 9347839Snilay@cs.wisc.edu BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 9357839Snilay@cs.wisc.edu BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 9367839Snilay@cs.wisc.edu EnumVariable('PROTOCOL', 'Coherence protocol for Ruby', 'None', 9377839Snilay@cs.wisc.edu all_protocols), 9386657Snate@binkert.org ) 9397007Snate@binkert.org 9407007Snate@binkert.org# These variables get exported to #defines in config/*.hh (see src/SConscript). 9416657Snate@binkert.orgexport_vars += ['USE_FENV', 'SS_COMPATIBLE_FP', 9428055Sksewell@umich.edu 'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'PROTOCOL', 9436657Snate@binkert.org 'HAVE_STATIC_ASSERT'] 9446657Snate@binkert.org 9456657Snate@binkert.org################################################### 9466657Snate@binkert.org# 9478478Snilay@cs.wisc.edu# Define a SCons builder for configuration flag headers. 9488478Snilay@cs.wisc.edu# 9498478Snilay@cs.wisc.edu################################################### 9506657Snate@binkert.org 9516657Snate@binkert.org# This function generates a config header file that #defines the 9526657Snate@binkert.org# variable symbol to the current variable setting (0 or 1). The source 9536657Snate@binkert.org# operands are the name of the variable and a Value node containing the 9546657Snate@binkert.org# value of the variable. 9556999Snate@binkert.orgdef build_config_file(target, source, env): 9566657Snate@binkert.org (variable, value) = [s.get_contents() for s in source] 9576657Snate@binkert.org f = file(str(target[0]), 'w') 9586657Snate@binkert.org print >> f, '#define', variable, value 9596657Snate@binkert.org f.close() 9606657Snate@binkert.org return None 9616657Snate@binkert.org 9627832Snate@binkert.org# Combine the two functions into a scons Action object. 9637832Snate@binkert.orgconfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 9647007Snate@binkert.org 9658232Snate@binkert.org# The emitter munges the source & target node lists to reflect what 9668229Snate@binkert.org# we're really doing. 9678229Snate@binkert.orgdef config_emitter(target, source, env): 9688229Snate@binkert.org # extract variable name from Builder arg 9698229Snate@binkert.org variable = str(target[0]) 9706657Snate@binkert.org # True target is config header file 9716657Snate@binkert.org target = joinpath('config', variable.lower() + '.hh') 9726657Snate@binkert.org val = env[variable] 9736657Snate@binkert.org if isinstance(val, bool): 9747055Snate@binkert.org # Force value to 0/1 9757055Snate@binkert.org val = int(val) 9767007Snate@binkert.org elif isinstance(val, str): 9777007Snate@binkert.org val = '"' + val + '"' 9786657Snate@binkert.org 9796657Snate@binkert.org # Sources are variable name & value (packaged in SCons Value nodes) 9806657Snate@binkert.org return ([target], [Value(variable), Value(val)]) 9816657Snate@binkert.org 9826657Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 9836657Snate@binkert.org 9847007Snate@binkert.orgmain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 9857007Snate@binkert.org 9867007Snate@binkert.org# libelf build is shared across all configs in the build root. 9877007Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 9887007Snate@binkert.org variant_dir = joinpath(build_root, 'libelf')) 9896657Snate@binkert.org 9906657Snate@binkert.org# gzstream build is shared across all configs in the build root. 9916657Snate@binkert.orgmain.SConscript('ext/gzstream/SConscript', 9926657Snate@binkert.org variant_dir = joinpath(build_root, 'gzstream')) 9936657Snate@binkert.org 9946657Snate@binkert.org################################################### 9956657Snate@binkert.org# 9966657Snate@binkert.org# This function is used to set up a directory with switching headers 9976657Snate@binkert.org# 9986657Snate@binkert.org################################################### 9996657Snate@binkert.org 10006657Snate@binkert.orgmain['ALL_ISA_LIST'] = all_isa_list 10017567SBrad.Beckmann@amd.comdef make_switching_dir(dname, switch_headers, env): 10027567SBrad.Beckmann@amd.com # Generate the header. target[0] is the full path of the output 10037567SBrad.Beckmann@amd.com # header to generate. 'source' is a dummy variable, since we get the 10047567SBrad.Beckmann@amd.com # list of ISAs from env['ALL_ISA_LIST']. 10056657Snate@binkert.org def gen_switch_hdr(target, source, env): 10066657Snate@binkert.org fname = str(target[0]) 10076657Snate@binkert.org f = open(fname, 'w') 10086657Snate@binkert.org isa = env['TARGET_ISA'].lower() 10096657Snate@binkert.org print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 10106657Snate@binkert.org f.close() 10116657Snate@binkert.org 10126657Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 10136657Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 10146657Snate@binkert.org # should get re-executed. 10157007Snate@binkert.org switch_hdr_action = MakeAction(gen_switch_hdr, 10166657Snate@binkert.org Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 10176657Snate@binkert.org 10186657Snate@binkert.org # Instantiate actions for each header 10196657Snate@binkert.org for hdr in switch_headers: 10206657Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 10216657Snate@binkert.orgExport('make_switching_dir') 10226657Snate@binkert.org 10236657Snate@binkert.org################################################### 10246999Snate@binkert.org# 10256657Snate@binkert.org# Define build environments for selected configurations. 10266657Snate@binkert.org# 10276657Snate@binkert.org################################################### 10286657Snate@binkert.org 10296657Snate@binkert.orgfor variant_path in variant_paths: 10306657Snate@binkert.org print "Building in", variant_path 10317832Snate@binkert.org 10327832Snate@binkert.org # Make a copy of the build-root environment to use for this config. 10337805Snilay@cs.wisc.edu env = main.Clone() 10347832Snate@binkert.org env['BUILDDIR'] = variant_path 10358232Snate@binkert.org 10368232Snate@binkert.org # variant_dir is the tail component of build path, and is used to 10378229Snate@binkert.org # determine the build parameters (e.g., 'ALPHA_SE') 10388229Snate@binkert.org (build_root, variant_dir) = splitpath(variant_path) 10398229Snate@binkert.org 10408229Snate@binkert.org # Set env variables according to the build directory config. 10416657Snate@binkert.org sticky_vars.files = [] 10426657Snate@binkert.org # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 10436657Snate@binkert.org # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 10446657Snate@binkert.org # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 10456657Snate@binkert.org current_vars_file = joinpath(build_root, 'variables', variant_dir) 10466657Snate@binkert.org if isfile(current_vars_file): 10476657Snate@binkert.org sticky_vars.files.append(current_vars_file) 10486657Snate@binkert.org print "Using saved variables file %s" % current_vars_file 10497007Snate@binkert.org else: 10507007Snate@binkert.org # Build dir-specific variables file doesn't exist. 10517839Snilay@cs.wisc.edu 10527839Snilay@cs.wisc.edu # Make sure the directory is there so we can create it later 10537839Snilay@cs.wisc.edu opt_dir = dirname(current_vars_file) 10547839Snilay@cs.wisc.edu if not isdir(opt_dir): 10557839Snilay@cs.wisc.edu mkdir(opt_dir) 10567839Snilay@cs.wisc.edu 10577839Snilay@cs.wisc.edu # Get default build variables from source tree. Variables are 10587839Snilay@cs.wisc.edu # normally determined by name of $VARIANT_DIR, but can be 10597839Snilay@cs.wisc.edu # overridden by '--default=' arg on command line. 10607839Snilay@cs.wisc.edu default = GetOption('default') 10617007Snate@binkert.org opts_dir = joinpath(main.root.abspath, 'build_opts') 10626657Snate@binkert.org if default: 10637839Snilay@cs.wisc.edu default_vars_files = [joinpath(build_root, 'variables', default), 10647839Snilay@cs.wisc.edu joinpath(opts_dir, default)] 10658337Snilay@cs.wisc.edu else: 10667839Snilay@cs.wisc.edu default_vars_files = [joinpath(opts_dir, variant_dir)] 10678337Snilay@cs.wisc.edu existing_files = filter(isfile, default_vars_files) 10687839Snilay@cs.wisc.edu if existing_files: 10698337Snilay@cs.wisc.edu default_vars_file = existing_files[0] 10707839Snilay@cs.wisc.edu sticky_vars.files.append(default_vars_file) 10718337Snilay@cs.wisc.edu print "Variables file %s not found,\n using defaults in %s" \ 10727839Snilay@cs.wisc.edu % (current_vars_file, default_vars_file) 10737839Snilay@cs.wisc.edu else: 10746657Snate@binkert.org print "Error: cannot find variables file %s or " \ 10756657Snate@binkert.org "default file(s) %s" \ 10767780Snilay@cs.wisc.edu % (current_vars_file, ' or '.join(default_vars_files)) 10777780Snilay@cs.wisc.edu Exit(1) 10787780Snilay@cs.wisc.edu 10797780Snilay@cs.wisc.edu # Apply current variable settings to env 10807780Snilay@cs.wisc.edu sticky_vars.Update(env) 10817780Snilay@cs.wisc.edu 10826657Snate@binkert.org help_texts["local_vars"] += \ 10837007Snate@binkert.org "Build variables for %s:\n" % variant_dir \ 10847839Snilay@cs.wisc.edu + sticky_vars.GenerateHelpText(env) 10857839Snilay@cs.wisc.edu 10867839Snilay@cs.wisc.edu # Process variable settings. 10877839Snilay@cs.wisc.edu 10887839Snilay@cs.wisc.edu if not have_fenv and env['USE_FENV']: 10897839Snilay@cs.wisc.edu print "Warning: <fenv.h> not available; " \ 10907839Snilay@cs.wisc.edu "forcing USE_FENV to False in", variant_dir + "." 10917839Snilay@cs.wisc.edu env['USE_FENV'] = False 10927839Snilay@cs.wisc.edu 10936657Snate@binkert.org if not env['USE_FENV']: 10947839Snilay@cs.wisc.edu print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 10956657Snate@binkert.org print " FP results may deviate slightly from other platforms." 10967780Snilay@cs.wisc.edu 10977780Snilay@cs.wisc.edu if env['EFENCE']: 10987542SBrad.Beckmann@amd.com env.Append(LIBS=['efence']) 10998266Sksewell@umich.edu 11008266Sksewell@umich.edu # Save sticky variable settings back to current variables file 11018266Sksewell@umich.edu sticky_vars.Save(current_vars_file, env) 11028266Sksewell@umich.edu 11038266Sksewell@umich.edu if env['USE_SSE2']: 11048266Sksewell@umich.edu env.Append(CCFLAGS=['-msse2']) 11056657Snate@binkert.org 11067832Snate@binkert.org if have_tcmalloc: 11077839Snilay@cs.wisc.edu env.Append(LIBS=['tcmalloc_minimal']) 11087839Snilay@cs.wisc.edu 11098337Snilay@cs.wisc.edu # The src/SConscript file sets up the build rules in 'env' according 11108341Snilay@cs.wisc.edu # to the configured variables. It returns a list of environments, 11117839Snilay@cs.wisc.edu # one for each variant build (debug, opt, etc.) 11128337Snilay@cs.wisc.edu envList = SConscript('src/SConscript', variant_dir = variant_path, 11138341Snilay@cs.wisc.edu exports = 'env') 11147839Snilay@cs.wisc.edu 11158337Snilay@cs.wisc.edu # Set up the regression tests for each build. 11168341Snilay@cs.wisc.edu for e in envList: 11177839Snilay@cs.wisc.edu SConscript('tests/SConscript', 11188337Snilay@cs.wisc.edu variant_dir = joinpath(variant_path, 'tests', e.Label), 11198341Snilay@cs.wisc.edu exports = { 'env' : e }, duplicate = False) 11207839Snilay@cs.wisc.edu 11217839Snilay@cs.wisc.edu# base help text 11226657Snate@binkert.orgHelp(''' 11238266Sksewell@umich.eduUsage: scons [scons options] [build variables] [target(s)] 11248266Sksewell@umich.edu 11258266Sksewell@umich.eduExtra scons options: 11268266Sksewell@umich.edu%(options)s 11278266Sksewell@umich.edu 11288266Sksewell@umich.eduGlobal build variables: 11296657Snate@binkert.org%(global_vars)s 11307780Snilay@cs.wisc.edu 11318266Sksewell@umich.edu%(local_vars)s 11328266Sksewell@umich.edu''' % help_texts) 11338266Sksewell@umich.edu