SConstruct revision 8897:1021e1f313d0
15409Sgblack@eecs.umich.edu# -*- mode:python -*- 24519Sgblack@eecs.umich.edu 34519Sgblack@eecs.umich.edu# Copyright (c) 2011 Advanced Micro Devices, Inc. 47087Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 57087Snate@binkert.org# Copyright (c) 2004-2005 The Regents of The University of Michigan 67087Snate@binkert.org# All rights reserved. 77087Snate@binkert.org# 87087Snate@binkert.org# Redistribution and use in source and binary forms, with or without 97087Snate@binkert.org# modification, are permitted provided that the following conditions are 107087Snate@binkert.org# met: redistributions of source code must retain the above copyright 117087Snate@binkert.org# notice, this list of conditions and the following disclaimer; 124519Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 137087Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 147087Snate@binkert.org# documentation and/or other materials provided with the distribution; 157087Snate@binkert.org# neither the name of the copyright holders nor the names of its 167087Snate@binkert.org# contributors may be used to endorse or promote products derived from 177087Snate@binkert.org# this software without specific prior written permission. 187087Snate@binkert.org# 197087Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 207087Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 214519Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 227087Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 234519Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 244519Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 254519Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 264519Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 274519Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 284519Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 294519Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 304519Sgblack@eecs.umich.edu# 314519Sgblack@eecs.umich.edu# Authors: Steve Reinhardt 324519Sgblack@eecs.umich.edu# Nathan Binkert 334519Sgblack@eecs.umich.edu 344519Sgblack@eecs.umich.edu################################################### 354519Sgblack@eecs.umich.edu# 364519Sgblack@eecs.umich.edu# SCons top-level build description (SConstruct) file. 374519Sgblack@eecs.umich.edu# 384519Sgblack@eecs.umich.edu# While in this directory ('gem5'), just type 'scons' to build the default 394519Sgblack@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 404519Sgblack@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA/gem5.opt' for 414519Sgblack@eecs.umich.edu# the optimized full-system version). 424519Sgblack@eecs.umich.edu# 434519Sgblack@eecs.umich.edu# You can build gem5 in a different directory as long as there is a 444519Sgblack@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 454519Sgblack@eecs.umich.edu# expects that all configs under the same build directory are being 464519Sgblack@eecs.umich.edu# built for the same host system. 474519Sgblack@eecs.umich.edu# 484519Sgblack@eecs.umich.edu# Examples: 494519Sgblack@eecs.umich.edu# 504809Sgblack@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 514519Sgblack@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 524519Sgblack@eecs.umich.edu# % cd <path-to-src>/gem5 ; scons build/ALPHA/gem5.debug 534688Sgblack@eecs.umich.edu# % cd <path-to-src>/gem5/build/ALPHA; scons -u gem5.debug 544688Sgblack@eecs.umich.edu# 554688Sgblack@eecs.umich.edu# The following two commands are equivalent and demonstrate building 564688Sgblack@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 574688Sgblack@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 584688Sgblack@eecs.umich.edu# file. 594708Sgblack@eecs.umich.edu# % cd <path-to-src>/gem5 ; scons /local/foo/build/ALPHA/gem5.debug 604708Sgblack@eecs.umich.edu# % cd /local/foo/build/ALPHA; scons -C <path-to-src>/gem5 gem5.debug 614708Sgblack@eecs.umich.edu# 624708Sgblack@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 634519Sgblack@eecs.umich.edu# 'gem5' directory (or use -u or -C to tell scons where to find this 644519Sgblack@eecs.umich.edu# file), you can use 'scons -h' to print all the gem5-specific build 654519Sgblack@eecs.umich.edu# options as well. 664519Sgblack@eecs.umich.edu# 674519Sgblack@eecs.umich.edu################################################### 684519Sgblack@eecs.umich.edu 694519Sgblack@eecs.umich.edu# Check for recent-enough Python and SCons versions. 704519Sgblack@eecs.umich.edutry: 714519Sgblack@eecs.umich.edu # Really old versions of scons only take two options for the 724519Sgblack@eecs.umich.edu # function, so check once without the revision and once with the 734519Sgblack@eecs.umich.edu # revision, the first instance will fail for stuff other than 744951Sgblack@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 754519Sgblack@eecs.umich.edu EnsureSConsVersion(0, 98) 764519Sgblack@eecs.umich.edu EnsureSConsVersion(0, 98, 1) 774519Sgblack@eecs.umich.eduexcept SystemExit, e: 784519Sgblack@eecs.umich.edu print """ 794519Sgblack@eecs.umich.eduFor more details, see: 804519Sgblack@eecs.umich.edu http://gem5.org/Dependencies 814688Sgblack@eecs.umich.edu""" 824688Sgblack@eecs.umich.edu raise 834688Sgblack@eecs.umich.edu 844688Sgblack@eecs.umich.edu# We ensure the python version early because we have stuff that 854688Sgblack@eecs.umich.edu# requires python 2.4 864688Sgblack@eecs.umich.edutry: 874708Sgblack@eecs.umich.edu EnsurePythonVersion(2, 4) 884708Sgblack@eecs.umich.eduexcept SystemExit, e: 894708Sgblack@eecs.umich.edu print """ 904708Sgblack@eecs.umich.eduYou can use a non-default installation of the Python interpreter by 914519Sgblack@eecs.umich.edueither (1) rearranging your PATH so that scons finds the non-default 924519Sgblack@eecs.umich.edu'python' first or (2) explicitly invoking an alternative interpreter 934519Sgblack@eecs.umich.eduon the scons script. 944519Sgblack@eecs.umich.edu 954519Sgblack@eecs.umich.eduFor more details, see: 964519Sgblack@eecs.umich.edu http://gem5.org/wiki/index.php/Using_a_non-default_Python_installation 974519Sgblack@eecs.umich.edu""" 984519Sgblack@eecs.umich.edu raise 994519Sgblack@eecs.umich.edu 1004519Sgblack@eecs.umich.edu# Global Python includes 1014519Sgblack@eecs.umich.eduimport os 1024519Sgblack@eecs.umich.eduimport re 1034519Sgblack@eecs.umich.eduimport subprocess 1044519Sgblack@eecs.umich.eduimport sys 1054519Sgblack@eecs.umich.edu 1064519Sgblack@eecs.umich.edufrom os import mkdir, environ 1074519Sgblack@eecs.umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath 1084519Sgblack@eecs.umich.edufrom os.path import exists, isdir, isfile 1097620Sgblack@eecs.umich.edufrom os.path import join as joinpath, split as splitpath 1106345Sgblack@eecs.umich.edu 1114712Sgblack@eecs.umich.edu# SCons includes 1124519Sgblack@eecs.umich.eduimport SCons 1134519Sgblack@eecs.umich.eduimport SCons.Node 1144519Sgblack@eecs.umich.edu 1156345Sgblack@eecs.umich.eduextra_python_paths = [ 1164712Sgblack@eecs.umich.edu Dir('src/python').srcnode().abspath, # gem5 includes 1174519Sgblack@eecs.umich.edu Dir('ext/ply').srcnode().abspath, # ply is used by several files 1184519Sgblack@eecs.umich.edu ] 1194519Sgblack@eecs.umich.edu 1204519Sgblack@eecs.umich.edusys.path[1:1] = extra_python_paths 1214519Sgblack@eecs.umich.edu 1224519Sgblack@eecs.umich.edufrom m5.util import compareVersions, readCommand 1234519Sgblack@eecs.umich.edu 1244951Sgblack@eecs.umich.eduhelp_texts = { 1254519Sgblack@eecs.umich.edu "options" : "", 1264519Sgblack@eecs.umich.edu "global_vars" : "", 1274519Sgblack@eecs.umich.edu "local_vars" : "" 1284519Sgblack@eecs.umich.edu} 1294519Sgblack@eecs.umich.edu 1304951Sgblack@eecs.umich.eduExport("help_texts") 1317620Sgblack@eecs.umich.edu 1326646Sgblack@eecs.umich.edu 1334712Sgblack@eecs.umich.edu# There's a bug in scons in that (1) by default, the help texts from 1344519Sgblack@eecs.umich.edu# AddOption() are supposed to be displayed when you type 'scons -h' 1354951Sgblack@eecs.umich.edu# and (2) you can override the help displayed by 'scons -h' using the 1364519Sgblack@eecs.umich.edu# Help() function, but these two features are incompatible: once 1376646Sgblack@eecs.umich.edu# you've overridden the help text using Help(), there's no way to get 1384712Sgblack@eecs.umich.edu# at the help texts from AddOptions. See: 1394519Sgblack@eecs.umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2356 1404519Sgblack@eecs.umich.edu# http://scons.tigris.org/issues/show_bug.cgi?id=2611 1414519Sgblack@eecs.umich.edu# This hack lets us extract the help text from AddOptions and 1424519Sgblack@eecs.umich.edu# re-inject it via Help(). Ideally someday this bug will be fixed and 1434519Sgblack@eecs.umich.edu# we can just use AddOption directly. 1444519Sgblack@eecs.umich.edudef AddLocalOption(*args, **kwargs): 1454519Sgblack@eecs.umich.edu col_width = 30 1464519Sgblack@eecs.umich.edu 1474519Sgblack@eecs.umich.edu help = " " + ", ".join(args) 1484519Sgblack@eecs.umich.edu if "help" in kwargs: 1494519Sgblack@eecs.umich.edu length = len(help) 1504519Sgblack@eecs.umich.edu if length >= col_width: 1514519Sgblack@eecs.umich.edu help += "\n" + " " * col_width 1524519Sgblack@eecs.umich.edu else: 1536345Sgblack@eecs.umich.edu help += " " * (col_width - length) 1544712Sgblack@eecs.umich.edu help += kwargs["help"] 1557620Sgblack@eecs.umich.edu help_texts["options"] += help + "\n" 1564688Sgblack@eecs.umich.edu 1574581Sgblack@eecs.umich.edu AddOption(*args, **kwargs) 1584519Sgblack@eecs.umich.edu 1594519Sgblack@eecs.umich.eduAddLocalOption('--colors', dest='use_colors', action='store_true', 1604519Sgblack@eecs.umich.edu help="Add color to abbreviated scons output") 1614519Sgblack@eecs.umich.eduAddLocalOption('--no-colors', dest='use_colors', action='store_false', 1624519Sgblack@eecs.umich.edu help="Don't add color to abbreviated scons output") 1637620Sgblack@eecs.umich.eduAddLocalOption('--default', dest='default', type='string', action='store', 1646345Sgblack@eecs.umich.edu help='Override which build_opts file to use for defaults') 1654712Sgblack@eecs.umich.eduAddLocalOption('--ignore-style', dest='ignore_style', action='store_true', 1667620Sgblack@eecs.umich.edu help='Disable style checking hooks') 1674688Sgblack@eecs.umich.eduAddLocalOption('--update-ref', dest='update_ref', action='store_true', 1684581Sgblack@eecs.umich.edu help='Update test reference outputs') 1694519Sgblack@eecs.umich.eduAddLocalOption('--verbose', dest='verbose', action='store_true', 1704519Sgblack@eecs.umich.edu help='Print full tool command lines') 1714519Sgblack@eecs.umich.edu 1724519Sgblack@eecs.umich.eduuse_colors = GetOption('use_colors') 1734519Sgblack@eecs.umich.eduif use_colors: 1744519Sgblack@eecs.umich.edu from m5.util.terminal import termcap 1754519Sgblack@eecs.umich.eduelif use_colors is None: 1764951Sgblack@eecs.umich.edu # option unspecified; default behavior is to use colors iff isatty 1774519Sgblack@eecs.umich.edu from m5.util.terminal import tty_termcap as termcap 1784519Sgblack@eecs.umich.eduelse: 1794519Sgblack@eecs.umich.edu from m5.util.terminal import no_termcap as termcap 1804519Sgblack@eecs.umich.edu 1814951Sgblack@eecs.umich.edu######################################################################## 1824519Sgblack@eecs.umich.edu# 1836646Sgblack@eecs.umich.edu# Set up the main build environment. 1844712Sgblack@eecs.umich.edu# 1857620Sgblack@eecs.umich.edu######################################################################## 1864688Sgblack@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1874581Sgblack@eecs.umich.edu 'PYTHONPATH', 'RANLIB' ]) 1884519Sgblack@eecs.umich.edu 1894519Sgblack@eecs.umich.eduuse_env = {} 1904519Sgblack@eecs.umich.edufor key,val in os.environ.iteritems(): 1914519Sgblack@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1924951Sgblack@eecs.umich.edu use_env[key] = val 1937620Sgblack@eecs.umich.edu 1946646Sgblack@eecs.umich.edumain = Environment(ENV=use_env) 1954712Sgblack@eecs.umich.edumain.Decider('MD5-timestamp') 1967620Sgblack@eecs.umich.edumain.root = Dir(".") # The current directory (where this file lives). 1974688Sgblack@eecs.umich.edumain.srcdir = Dir("src") # The source directory 1984581Sgblack@eecs.umich.edu 1994519Sgblack@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 2004519Sgblack@eecs.umich.edu# as well 2014519Sgblack@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths) 2024519Sgblack@eecs.umich.edu 2034519Sgblack@eecs.umich.edu######################################################################## 2045075Sgblack@eecs.umich.edu# 2055075Sgblack@eecs.umich.edu# Mercurial Stuff. 2065075Sgblack@eecs.umich.edu# 2075075Sgblack@eecs.umich.edu# If the gem5 directory is a mercurial repository, we should do some 2085428Sgblack@eecs.umich.edu# extra things. 2095428Sgblack@eecs.umich.edu# 2105674Sgblack@eecs.umich.edu######################################################################## 2115899Sgblack@eecs.umich.edu 2125936Sgblack@eecs.umich.eduhgdir = main.root.Dir(".hg") 2135428Sgblack@eecs.umich.edu 2145678Sgblack@eecs.umich.edumercurial_style_message = """ 2155678Sgblack@eecs.umich.eduYou're missing the gem5 style hook, which automatically checks your code 2165678Sgblack@eecs.umich.eduagainst the gem5 style rules on hg commit and qrefresh commands. This 2175678Sgblack@eecs.umich.eduscript will now install the hook in your .hg/hgrc file. 2185678Sgblack@eecs.umich.eduPress enter to continue, or ctrl-c to abort: """ 2195678Sgblack@eecs.umich.edu 2205678Sgblack@eecs.umich.edumercurial_style_hook = """ 2215678Sgblack@eecs.umich.edu# The following lines were automatically added by gem5/SConstruct 2225678Sgblack@eecs.umich.edu# to provide the gem5 style-checking hooks 2235075Sgblack@eecs.umich.edu[extensions] 2245075Sgblack@eecs.umich.edustyle = %s/util/style.py 2255075Sgblack@eecs.umich.edu 2265075Sgblack@eecs.umich.edu[hooks] 2275075Sgblack@eecs.umich.edupretxncommit.style = python:style.check_style 2285075Sgblack@eecs.umich.edupre-qrefresh.style = python:style.check_style 2295075Sgblack@eecs.umich.edu# End of SConstruct additions 2305075Sgblack@eecs.umich.edu 2315075Sgblack@eecs.umich.edu""" % (main.root.abspath) 2325075Sgblack@eecs.umich.edu 2335075Sgblack@eecs.umich.edumercurial_lib_not_found = """ 2345075Sgblack@eecs.umich.eduMercurial libraries cannot be found, ignoring style hook. If 2355075Sgblack@eecs.umich.eduyou are a gem5 developer, please fix this and run the style 2365075Sgblack@eecs.umich.eduhook. It is important. 2375075Sgblack@eecs.umich.edu""" 2385075Sgblack@eecs.umich.edu 2395075Sgblack@eecs.umich.edu# Check for style hook and prompt for installation if it's not there. 2405075Sgblack@eecs.umich.edu# Skip this if --ignore-style was specified, there's no .hg dir to 2415075Sgblack@eecs.umich.edu# install a hook in, or there's no interactive terminal to prompt. 2425075Sgblack@eecs.umich.eduif not GetOption('ignore_style') and hgdir.exists() and sys.stdin.isatty(): 2435075Sgblack@eecs.umich.edu style_hook = True 2445075Sgblack@eecs.umich.edu try: 2455075Sgblack@eecs.umich.edu from mercurial import ui 2465075Sgblack@eecs.umich.edu ui = ui.ui() 2475075Sgblack@eecs.umich.edu ui.readconfig(hgdir.File('hgrc').abspath) 2485075Sgblack@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) and \ 2495075Sgblack@eecs.umich.edu ui.config('hooks', 'pre-qrefresh.style', None) 2505075Sgblack@eecs.umich.edu except ImportError: 2515075Sgblack@eecs.umich.edu print mercurial_lib_not_found 2525075Sgblack@eecs.umich.edu 2535075Sgblack@eecs.umich.edu if not style_hook: 2545075Sgblack@eecs.umich.edu print mercurial_style_message, 2555075Sgblack@eecs.umich.edu # continue unless user does ctrl-c/ctrl-d etc. 2565075Sgblack@eecs.umich.edu try: 2575075Sgblack@eecs.umich.edu raw_input() 2584519Sgblack@eecs.umich.edu except: 2595040Sgblack@eecs.umich.edu print "Input exception, exiting scons.\n" 2605040Sgblack@eecs.umich.edu sys.exit(1) 2615040Sgblack@eecs.umich.edu hgrc_path = '%s/.hg/hgrc' % main.root.abspath 2625040Sgblack@eecs.umich.edu print "Adding style hook to", hgrc_path, "\n" 2635040Sgblack@eecs.umich.edu try: 2645040Sgblack@eecs.umich.edu hgrc = open(hgrc_path, 'a') 2655040Sgblack@eecs.umich.edu hgrc.write(mercurial_style_hook) 2665040Sgblack@eecs.umich.edu hgrc.close() 2675040Sgblack@eecs.umich.edu except: 2685040Sgblack@eecs.umich.edu print "Error updating", hgrc_path 2695040Sgblack@eecs.umich.edu sys.exit(1) 2705040Sgblack@eecs.umich.edu 2715040Sgblack@eecs.umich.edu 2725040Sgblack@eecs.umich.edu################################################### 2735040Sgblack@eecs.umich.edu# 2745040Sgblack@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2755040Sgblack@eecs.umich.edu# the target(s). 2765040Sgblack@eecs.umich.edu# 2775040Sgblack@eecs.umich.edu################################################### 2785040Sgblack@eecs.umich.edu 2795040Sgblack@eecs.umich.edu# Find default configuration & binary. 2805040Sgblack@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA/gem5.debug')) 2815040Sgblack@eecs.umich.edu 2825040Sgblack@eecs.umich.edu# helper function: find last occurrence of element in list 2835040Sgblack@eecs.umich.edudef rfind(l, elt, offs = -1): 2845040Sgblack@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2855040Sgblack@eecs.umich.edu if l[i] == elt: 2865040Sgblack@eecs.umich.edu return i 2875040Sgblack@eecs.umich.edu raise ValueError, "element not found" 2885040Sgblack@eecs.umich.edu 2895062Sgblack@eecs.umich.edu# Take a list of paths (or SCons Nodes) and return a list with all 2905062Sgblack@eecs.umich.edu# paths made absolute and ~-expanded. Paths will be interpreted 2915062Sgblack@eecs.umich.edu# relative to the launch directory unless a different root is provided 2925062Sgblack@eecs.umich.edudef makePathListAbsolute(path_list, root=GetLaunchDir()): 2935062Sgblack@eecs.umich.edu return [abspath(joinpath(root, expanduser(str(p)))) 2945062Sgblack@eecs.umich.edu for p in path_list] 2955062Sgblack@eecs.umich.edu 2965040Sgblack@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2975062Sgblack@eecs.umich.edu# directory below this will determine the build parameters. For 2985062Sgblack@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2995062Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 3005062Sgblack@eecs.umich.edu# follow 'build' in the build path. 3016647Sgblack@eecs.umich.edu 3025040Sgblack@eecs.umich.edu# The funky assignment to "[:]" is needed to replace the list contents 3036647Sgblack@eecs.umich.edu# in place rather than reassign the symbol to a new list, which 3046647Sgblack@eecs.umich.edu# doesn't work (obviously!). 3056647Sgblack@eecs.umich.eduBUILD_TARGETS[:] = makePathListAbsolute(BUILD_TARGETS) 3066647Sgblack@eecs.umich.edu 3075040Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the 3085040Sgblack@eecs.umich.edu# collected targets reference. 3095040Sgblack@eecs.umich.eduvariant_paths = [] 3105040Sgblack@eecs.umich.edubuild_root = None 3115239Sgblack@eecs.umich.edufor t in BUILD_TARGETS: 3125040Sgblack@eecs.umich.edu path_dirs = t.split('/') 3135040Sgblack@eecs.umich.edu try: 3145040Sgblack@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 3155040Sgblack@eecs.umich.edu except: 3165040Sgblack@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 3175040Sgblack@eecs.umich.edu Exit(1) 3185040Sgblack@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 3195040Sgblack@eecs.umich.edu if not build_root: 3205061Sgblack@eecs.umich.edu build_root = this_build_root 3215040Sgblack@eecs.umich.edu else: 3225040Sgblack@eecs.umich.edu if this_build_root != build_root: 3235061Sgblack@eecs.umich.edu print "Error: build targets not under same build root\n"\ 3245061Sgblack@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 3255061Sgblack@eecs.umich.edu Exit(1) 3265061Sgblack@eecs.umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 3275061Sgblack@eecs.umich.edu if variant_path not in variant_paths: 3285061Sgblack@eecs.umich.edu variant_paths.append(variant_path) 3295061Sgblack@eecs.umich.edu 3305061Sgblack@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 3316647Sgblack@eecs.umich.eduif not isdir(build_root): 3326647Sgblack@eecs.umich.edu mkdir(build_root) 3336647Sgblack@eecs.umich.edumain['BUILDROOT'] = build_root 3345040Sgblack@eecs.umich.edu 3355040Sgblack@eecs.umich.eduExport('main') 3365040Sgblack@eecs.umich.edu 3375040Sgblack@eecs.umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 3385040Sgblack@eecs.umich.edu 3395040Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 3406647Sgblack@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 3415040Sgblack@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 3425040Sgblack@eecs.umich.edu# (soft) links work better. 3435040Sgblack@eecs.umich.edumain.SetOption('duplicate', 'soft-copy') 3445040Sgblack@eecs.umich.edu 3455040Sgblack@eecs.umich.edu# 3465040Sgblack@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 3475040Sgblack@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 3485040Sgblack@eecs.umich.edu# 3495040Sgblack@eecs.umich.edu 3505040Sgblack@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 3515040Sgblack@eecs.umich.edu 3525040Sgblack@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3535040Sgblack@eecs.umich.edu 3545040Sgblack@eecs.umich.eduglobal_vars.AddVariables( 3555040Sgblack@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3565040Sgblack@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3575040Sgblack@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3585040Sgblack@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3594688Sgblack@eecs.umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3605040Sgblack@eecs.umich.edu ('EXTRAS', 'Add extra directories to the compilation', '') 3614688Sgblack@eecs.umich.edu ) 3624688Sgblack@eecs.umich.edu 3634688Sgblack@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_vars_file 3644688Sgblack@eecs.umich.eduglobal_vars.Update(main) 3655040Sgblack@eecs.umich.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3664688Sgblack@eecs.umich.edu 3675040Sgblack@eecs.umich.edu# Save sticky variable settings back to current variables file 3685040Sgblack@eecs.umich.eduglobal_vars.Save(global_vars_file, main) 3695040Sgblack@eecs.umich.edu 3705040Sgblack@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3715040Sgblack@eecs.umich.edu# look for sources etc. This list is exported as extras_dir_list. 3725040Sgblack@eecs.umich.edubase_dir = main.srcdir.abspath 3735040Sgblack@eecs.umich.eduif main['EXTRAS']: 3745040Sgblack@eecs.umich.edu extras_dir_list = makePathListAbsolute(main['EXTRAS'].split(':')) 3755040Sgblack@eecs.umich.eduelse: 3765040Sgblack@eecs.umich.edu extras_dir_list = [] 3775040Sgblack@eecs.umich.edu 3785040Sgblack@eecs.umich.eduExport('base_dir') 3795040Sgblack@eecs.umich.eduExport('extras_dir_list') 3805040Sgblack@eecs.umich.edu 3815040Sgblack@eecs.umich.edu# the ext directory should be on the #includes path 3825040Sgblack@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3835040Sgblack@eecs.umich.edu 3845040Sgblack@eecs.umich.edudef strip_build_path(path, env): 3855040Sgblack@eecs.umich.edu path = str(path) 3865040Sgblack@eecs.umich.edu variant_base = env['BUILDROOT'] + os.path.sep 3875040Sgblack@eecs.umich.edu if path.startswith(variant_base): 3885040Sgblack@eecs.umich.edu path = path[len(variant_base):] 3894688Sgblack@eecs.umich.edu elif path.startswith('build/'): 3904688Sgblack@eecs.umich.edu path = path[6:] 3915040Sgblack@eecs.umich.edu return path 3925040Sgblack@eecs.umich.edu 3935040Sgblack@eecs.umich.edu# Generate a string of the form: 3945040Sgblack@eecs.umich.edu# common/path/prefix/src1, src2 -> tgt1, tgt2 3954688Sgblack@eecs.umich.edu# to print while building. 3964688Sgblack@eecs.umich.educlass Transform(object): 3975040Sgblack@eecs.umich.edu # all specific color settings should be here and nowhere else 3985040Sgblack@eecs.umich.edu tool_color = termcap.Normal 3995040Sgblack@eecs.umich.edu pfx_color = termcap.Yellow 4005040Sgblack@eecs.umich.edu srcs_color = termcap.Yellow + termcap.Bold 4015040Sgblack@eecs.umich.edu arrow_color = termcap.Blue + termcap.Bold 4025040Sgblack@eecs.umich.edu tgts_color = termcap.Yellow + termcap.Bold 4034519Sgblack@eecs.umich.edu 4044519Sgblack@eecs.umich.edu def __init__(self, tool, max_sources=99): 4055040Sgblack@eecs.umich.edu self.format = self.tool_color + (" [%8s] " % tool) \ 4064688Sgblack@eecs.umich.edu + self.pfx_color + "%s" \ 4074701Sgblack@eecs.umich.edu + self.srcs_color + "%s" \ 4084688Sgblack@eecs.umich.edu + self.arrow_color + " -> " \ 4094688Sgblack@eecs.umich.edu + self.tgts_color + "%s" \ 4104688Sgblack@eecs.umich.edu + termcap.Normal 4114688Sgblack@eecs.umich.edu self.max_sources = max_sources 4124688Sgblack@eecs.umich.edu 4134688Sgblack@eecs.umich.edu def __call__(self, target, source, env, for_signature=None): 4144688Sgblack@eecs.umich.edu # truncate source list according to max_sources param 4154519Sgblack@eecs.umich.edu source = source[0:self.max_sources] 4167620Sgblack@eecs.umich.edu def strip(f): 4175040Sgblack@eecs.umich.edu return strip_build_path(str(f), env) 4185040Sgblack@eecs.umich.edu if len(source) > 0: 4195040Sgblack@eecs.umich.edu srcs = map(strip, source) 4207620Sgblack@eecs.umich.edu else: 4215040Sgblack@eecs.umich.edu srcs = [''] 4224688Sgblack@eecs.umich.edu tgts = map(strip, target) 4235040Sgblack@eecs.umich.edu # surprisingly, os.path.commonprefix is a dumb char-by-char string 4244519Sgblack@eecs.umich.edu # operation that has nothing to do with paths. 4255040Sgblack@eecs.umich.edu com_pfx = os.path.commonprefix(srcs + tgts) 4264519Sgblack@eecs.umich.edu com_pfx_len = len(com_pfx) 4274519Sgblack@eecs.umich.edu if com_pfx: 4284519Sgblack@eecs.umich.edu # do some cleanup and sanity checking on common prefix 4294539Sgblack@eecs.umich.edu if com_pfx[-1] == ".": 4304519Sgblack@eecs.umich.edu # prefix matches all but file extension: ok 4315040Sgblack@eecs.umich.edu # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4324688Sgblack@eecs.umich.edu com_pfx = com_pfx[0:-1] 4335040Sgblack@eecs.umich.edu elif com_pfx[-1] == "/": 4345040Sgblack@eecs.umich.edu # common prefix is directory path: OK 4355115Sgblack@eecs.umich.edu pass 4365040Sgblack@eecs.umich.edu else: 4375040Sgblack@eecs.umich.edu src0_len = len(srcs[0]) 4385040Sgblack@eecs.umich.edu tgt0_len = len(tgts[0]) 4395115Sgblack@eecs.umich.edu if src0_len == com_pfx_len: 4405040Sgblack@eecs.umich.edu # source is a substring of target, OK 4415040Sgblack@eecs.umich.edu pass 4424519Sgblack@eecs.umich.edu elif tgt0_len == com_pfx_len: 4435040Sgblack@eecs.umich.edu # target is a substring of source, need to back up to 4445040Sgblack@eecs.umich.edu # avoid empty string on RHS of arrow 4455040Sgblack@eecs.umich.edu sep_idx = com_pfx.rfind(".") 4465040Sgblack@eecs.umich.edu if sep_idx != -1: 4474519Sgblack@eecs.umich.edu com_pfx = com_pfx[0:sep_idx] 4485040Sgblack@eecs.umich.edu else: 4495040Sgblack@eecs.umich.edu com_pfx = '' 4505040Sgblack@eecs.umich.edu elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4515040Sgblack@eecs.umich.edu # still splitting at file extension: ok 4524519Sgblack@eecs.umich.edu pass 4535040Sgblack@eecs.umich.edu else: 4545040Sgblack@eecs.umich.edu # probably a fluke; ignore it 4555083Sgblack@eecs.umich.edu com_pfx = '' 4564519Sgblack@eecs.umich.edu # recalculate length in case com_pfx was modified 4575063Sgblack@eecs.umich.edu com_pfx_len = len(com_pfx) 4585063Sgblack@eecs.umich.edu def fmt(files): 4595063Sgblack@eecs.umich.edu f = map(lambda s: s[com_pfx_len:], files) 4605063Sgblack@eecs.umich.edu return ', '.join(f) 4615063Sgblack@eecs.umich.edu return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4626345Sgblack@eecs.umich.edu 4636345Sgblack@eecs.umich.eduExport('Transform') 4645063Sgblack@eecs.umich.edu 4655063Sgblack@eecs.umich.edu 4665063Sgblack@eecs.umich.eduif GetOption('verbose'): 4675063Sgblack@eecs.umich.edu def MakeAction(action, string, *args, **kwargs): 4686345Sgblack@eecs.umich.edu return Action(action, *args, **kwargs) 4696345Sgblack@eecs.umich.eduelse: 4705063Sgblack@eecs.umich.edu MakeAction = Action 4715040Sgblack@eecs.umich.edu main['CCCOMSTR'] = Transform("CC") 4725040Sgblack@eecs.umich.edu main['CXXCOMSTR'] = Transform("CXX") 4734595Sgblack@eecs.umich.edu main['ASCOMSTR'] = Transform("AS") 4745040Sgblack@eecs.umich.edu main['SWIGCOMSTR'] = Transform("SWIG") 4755040Sgblack@eecs.umich.edu main['ARCOMSTR'] = Transform("AR", 0) 4764595Sgblack@eecs.umich.edu main['LINKCOMSTR'] = Transform("LINK", 0) 4775040Sgblack@eecs.umich.edu main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4785040Sgblack@eecs.umich.edu main['M4COMSTR'] = Transform("M4") 4794732Sgblack@eecs.umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 4805138Sgblack@eecs.umich.edu main['SHCXXCOMSTR'] = Transform("SHCXX") 4815040Sgblack@eecs.umich.eduExport('MakeAction') 4825040Sgblack@eecs.umich.edu 4835040Sgblack@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 4845040Sgblack@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 4854732Sgblack@eecs.umich.edu 4865138Sgblack@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4875040Sgblack@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4885040Sgblack@eecs.umich.edumain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4895040Sgblack@eecs.umich.edumain['CLANG'] = CXX_V and CXX_V.find('clang') >= 0 4905040Sgblack@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] + main['CLANG'] > 1: 4915040Sgblack@eecs.umich.edu print 'Error: How can we have two at the same time?' 4925040Sgblack@eecs.umich.edu Exit(1) 4935040Sgblack@eecs.umich.edu 4945040Sgblack@eecs.umich.edu# Set up default C++ compiler flags 4955040Sgblack@eecs.umich.eduif main['GCC']: 4965040Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-pipe']) 4975040Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-fno-strict-aliasing']) 4985063Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4995040Sgblack@eecs.umich.edu main.Append(CXXFLAGS=['-Wno-deprecated']) 5005063Sgblack@eecs.umich.edu # Read the GCC version to check for versions with bugs 5015063Sgblack@eecs.umich.edu # Note CCVERSION doesn't work here because it is run with the CC 5026742Svince@csl.cornell.edu # before we override it from the command line 5036430Sgblack@eecs.umich.edu gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 5046430Sgblack@eecs.umich.edu main['GCC_VERSION'] = gcc_version 5056430Sgblack@eecs.umich.edu if not compareVersions(gcc_version, '4.4.1') or \ 5066461Sgblack@eecs.umich.edu not compareVersions(gcc_version, '4.4.2'): 5076430Sgblack@eecs.umich.edu print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5086430Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-fno-tree-vectorize']) 5096430Sgblack@eecs.umich.eduelif main['ICC']: 5106430Sgblack@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 5116462Sgblack@eecs.umich.eduelif main['SUNCC']: 5126430Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-Qoption ccfe']) 5136462Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-features=gcc']) 5146430Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-features=extensions']) 5156430Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-library=stlport4']) 5165040Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-xar']) 5176463Sgblack@eecs.umich.edu #main.Append(CCFLAGS=['-instances=semiexplicit']) 5186463Sgblack@eecs.umich.eduelif main['CLANG']: 5196463Sgblack@eecs.umich.edu clang_version_re = re.compile(".* version (\d+\.\d+)") 5206463Sgblack@eecs.umich.edu clang_version_match = clang_version_re.match(CXX_version) 5216463Sgblack@eecs.umich.edu if (clang_version_match): 5226463Sgblack@eecs.umich.edu clang_version = clang_version_match.groups()[0] 5236463Sgblack@eecs.umich.edu if compareVersions(clang_version, "2.9") < 0: 5246463Sgblack@eecs.umich.edu print 'Error: clang version 2.9 or newer required.' 5255040Sgblack@eecs.umich.edu print ' Installed version:', clang_version 5265063Sgblack@eecs.umich.edu Exit(1) 5275040Sgblack@eecs.umich.edu else: 5285063Sgblack@eecs.umich.edu print 'Error: Unable to determine clang version.' 5294809Sgblack@eecs.umich.edu Exit(1) 5306742Svince@csl.cornell.edu 5316430Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-pipe']) 5325063Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-fno-strict-aliasing']) 5336461Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 5345063Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-Wno-tautological-compare']) 5355063Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-Wno-self-assign']) 5366430Sgblack@eecs.umich.eduelse: 5375063Sgblack@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 5385040Sgblack@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 5396463Sgblack@eecs.umich.edu Exit(1) 5406463Sgblack@eecs.umich.edu 5416463Sgblack@eecs.umich.edu# Set up common yacc/bison flags (needed for Ruby) 5426463Sgblack@eecs.umich.edumain['YACCFLAGS'] = '-d' 5436463Sgblack@eecs.umich.edumain['YACCHXXFILESUFFIX'] = '.hh' 5446463Sgblack@eecs.umich.edu 5456463Sgblack@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 5465040Sgblack@eecs.umich.edu# extra 'qdo' every time we run scons. 5475063Sgblack@eecs.umich.eduif main['BATCH']: 5485063Sgblack@eecs.umich.edu main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5495040Sgblack@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5505063Sgblack@eecs.umich.edu main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5515063Sgblack@eecs.umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5525063Sgblack@eecs.umich.edu main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5535063Sgblack@eecs.umich.edu 5546345Sgblack@eecs.umich.eduif sys.platform == 'cygwin': 5556345Sgblack@eecs.umich.edu # cygwin has some header file issues... 5565063Sgblack@eecs.umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 5575062Sgblack@eecs.umich.edu 5585075Sgblack@eecs.umich.edu# Check for SWIG 5595075Sgblack@eecs.umich.eduif not main.has_key('SWIG'): 5605040Sgblack@eecs.umich.edu print 'Error: SWIG utility not found.' 5615075Sgblack@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 5625075Sgblack@eecs.umich.edu Exit(1) 5635075Sgblack@eecs.umich.edu 5645075Sgblack@eecs.umich.edu# Check for appropriate SWIG version 5655075Sgblack@eecs.umich.eduswig_version = readCommand(('swig', '-version'), exception='').split() 5665075Sgblack@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 5675075Sgblack@eecs.umich.eduif len(swig_version) < 3 or \ 5685075Sgblack@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5695075Sgblack@eecs.umich.edu print 'Error determining SWIG version.' 5705075Sgblack@eecs.umich.edu Exit(1) 5715075Sgblack@eecs.umich.edu 5725075Sgblack@eecs.umich.edumin_swig_version = '1.3.28' 5735075Sgblack@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0: 5745075Sgblack@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 5755075Sgblack@eecs.umich.edu print ' Installed version:', swig_version[2] 5765040Sgblack@eecs.umich.edu Exit(1) 5774823Sgblack@eecs.umich.edu 5785075Sgblack@eecs.umich.edu# Set up SWIG flags & scanner 5795075Sgblack@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5805075Sgblack@eecs.umich.edumain.Append(SWIGFLAGS=swig_flags) 5815075Sgblack@eecs.umich.edu 5825075Sgblack@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 5835075Sgblack@eecs.umich.edu# stuff for some reason 5845075Sgblack@eecs.umich.eduscanners = [] 5855075Sgblack@eecs.umich.edufor scanner in main['SCANNERS']: 5865075Sgblack@eecs.umich.edu skeys = scanner.skeys 5875075Sgblack@eecs.umich.edu if skeys == '.i': 5885075Sgblack@eecs.umich.edu continue 5897070Sgblack@eecs.umich.edu 5907070Sgblack@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5917070Sgblack@eecs.umich.edu continue 5927070Sgblack@eecs.umich.edu 5937070Sgblack@eecs.umich.edu scanners.append(scanner) 5947070Sgblack@eecs.umich.edu 5957070Sgblack@eecs.umich.edu# add the new swig scanner that we like better 5967070Sgblack@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 5977080Sgblack@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 5987070Sgblack@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 5997080Sgblack@eecs.umich.edu 6007070Sgblack@eecs.umich.edu# replace the scanners list that has what we want 6017070Sgblack@eecs.umich.edumain['SCANNERS'] = scanners 6027070Sgblack@eecs.umich.edu 6037070Sgblack@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 6047070Sgblack@eecs.umich.edu# figure out if the compiler adds leading underscores to global 6057080Sgblack@eecs.umich.edu# variables. This is needed for the autogenerated asm files that we 6067080Sgblack@eecs.umich.edu# use for embedding the python code. 6077080Sgblack@eecs.umich.edudef CheckLeading(context): 6087080Sgblack@eecs.umich.edu context.Message("Checking for leading underscore in global variables...") 6097070Sgblack@eecs.umich.edu # 1) Define a global variable called x from asm so the C compiler 6107070Sgblack@eecs.umich.edu # won't change the symbol at all. 6117070Sgblack@eecs.umich.edu # 2) Declare that variable. 6127070Sgblack@eecs.umich.edu # 3) Use the variable 6137070Sgblack@eecs.umich.edu # 6147070Sgblack@eecs.umich.edu # If the compiler prepends an underscore, this will successfully 6157070Sgblack@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 6167070Sgblack@eecs.umich.edu # was defined by the asm statement. If the compiler does not 6177070Sgblack@eecs.umich.edu # prepend an underscore, this will not successfully link because 6187070Sgblack@eecs.umich.edu # '_x' will have been defined by assembly, while the C portion of 6197070Sgblack@eecs.umich.edu # the code will be trying to use 'x' 6207070Sgblack@eecs.umich.edu ret = context.TryLink(''' 6217070Sgblack@eecs.umich.edu asm(".globl _x; _x: .byte 0"); 6225075Sgblack@eecs.umich.edu extern int x; 6235075Sgblack@eecs.umich.edu int main() { return x; } 6245075Sgblack@eecs.umich.edu ''', extension=".c") 6255075Sgblack@eecs.umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 6265075Sgblack@eecs.umich.edu context.Result(ret) 6275075Sgblack@eecs.umich.edu return ret 6285075Sgblack@eecs.umich.edu 6295075Sgblack@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 6305075Sgblack@eecs.umich.edu# builds under a given build root run on the same host platform. 6317480Sgblack@eecs.umich.educonf = Configure(main, 6325075Sgblack@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 6335075Sgblack@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 6345075Sgblack@eecs.umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 6355075Sgblack@eecs.umich.edu 6364732Sgblack@eecs.umich.edu# Check for leading underscores. Don't really need to worry either 6375075Sgblack@eecs.umich.edu# way so don't need to check the return code. 6385075Sgblack@eecs.umich.educonf.CheckLeading() 6395075Sgblack@eecs.umich.edu 6405075Sgblack@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6415075Sgblack@eecs.umich.edutry: 6425040Sgblack@eecs.umich.edu import platform 6435040Sgblack@eecs.umich.edu uname = platform.uname() 6445040Sgblack@eecs.umich.edu if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6456482Sgblack@eecs.umich.edu if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6465040Sgblack@eecs.umich.edu main.Append(CCFLAGS=['-arch', 'x86_64']) 6474732Sgblack@eecs.umich.edu main.Append(CFLAGS=['-arch', 'x86_64']) 6485040Sgblack@eecs.umich.edu main.Append(LINKFLAGS=['-arch', 'x86_64']) 6495076Sgblack@eecs.umich.edu main.Append(ASFLAGS=['-arch', 'x86_64']) 6505040Sgblack@eecs.umich.eduexcept: 6514756Sgblack@eecs.umich.edu pass 6524823Sgblack@eecs.umich.edu 6535040Sgblack@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 6545076Sgblack@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 6555076Sgblack@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 6565076Sgblack@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 6575076Sgblack@eecs.umich.edu# more optimistic null object that returns True instead. 6585076Sgblack@eecs.umich.eduif not conf: 6595076Sgblack@eecs.umich.edu def NullCheck(*args, **kwargs): 6605076Sgblack@eecs.umich.edu return True 6615076Sgblack@eecs.umich.edu 6626441Sgblack@eecs.umich.edu class NullConf: 6636441Sgblack@eecs.umich.edu def __init__(self, env): 6645076Sgblack@eecs.umich.edu self.env = env 6656441Sgblack@eecs.umich.edu def Finish(self): 6665076Sgblack@eecs.umich.edu return self.env 6675076Sgblack@eecs.umich.edu def __getattr__(self, mname): 6685076Sgblack@eecs.umich.edu return NullCheck 6695076Sgblack@eecs.umich.edu 6705076Sgblack@eecs.umich.edu conf = NullConf(main) 6715076Sgblack@eecs.umich.edu 6725076Sgblack@eecs.umich.edu# Find Python include and library directories for embedding the 6735076Sgblack@eecs.umich.edu# interpreter. For consistency, we will use the same Python 6745076Sgblack@eecs.umich.edu# installation used to run scons (and thus this script). If you want 6755076Sgblack@eecs.umich.edu# to link in an alternate version, see above for instructions on how 6765076Sgblack@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 6775040Sgblack@eecs.umich.edufrom distutils import sysconfig 6785076Sgblack@eecs.umich.edu 6795040Sgblack@eecs.umich.edupy_getvar = sysconfig.get_config_var 6804756Sgblack@eecs.umich.edu 6814732Sgblack@eecs.umich.edupy_debug = getattr(sys, 'pydebug', False) 6824732Sgblack@eecs.umich.edupy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6834732Sgblack@eecs.umich.edu 6844732Sgblack@eecs.umich.edupy_general_include = sysconfig.get_python_inc() 6854823Sgblack@eecs.umich.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6865040Sgblack@eecs.umich.edupy_includes = [ py_general_include ] 6875076Sgblack@eecs.umich.eduif py_platform_include != py_general_include: 6885076Sgblack@eecs.umich.edu py_includes.append(py_platform_include) 6895076Sgblack@eecs.umich.edu 6905076Sgblack@eecs.umich.edupy_lib_path = [ py_getvar('LIBDIR') ] 6915076Sgblack@eecs.umich.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6925076Sgblack@eecs.umich.edu# shared library in prefix/lib/. 6935076Sgblack@eecs.umich.eduif not py_getvar('Py_ENABLE_SHARED'): 6946442Sgblack@eecs.umich.edu py_lib_path.append(py_getvar('LIBPL')) 6956442Sgblack@eecs.umich.edu 6966442Sgblack@eecs.umich.edupy_libs = [] 6975076Sgblack@eecs.umich.edufor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 6986442Sgblack@eecs.umich.edu if not lib.startswith('-l'): 6995076Sgblack@eecs.umich.edu # Python requires some special flags to link (e.g. -framework 7005076Sgblack@eecs.umich.edu # common on OS X systems), assume appending preserves order 7015076Sgblack@eecs.umich.edu main.Append(LINKFLAGS=[lib]) 7025076Sgblack@eecs.umich.edu else: 7035076Sgblack@eecs.umich.edu lib = lib[2:] 7045076Sgblack@eecs.umich.edu if lib not in py_libs: 7055076Sgblack@eecs.umich.edu py_libs.append(lib) 7065076Sgblack@eecs.umich.edupy_libs.append(py_version) 7075040Sgblack@eecs.umich.edu 7085076Sgblack@eecs.umich.edumain.Append(CPPPATH=py_includes) 7095040Sgblack@eecs.umich.edumain.Append(LIBPATH=py_lib_path) 7104756Sgblack@eecs.umich.edu 7114732Sgblack@eecs.umich.edu# Cache build files in the supplied directory. 7124732Sgblack@eecs.umich.eduif main['M5_BUILD_CACHE']: 7134732Sgblack@eecs.umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 7146443Sgblack@eecs.umich.edu CacheDir(main['M5_BUILD_CACHE']) 7155032Sgblack@eecs.umich.edu 7164823Sgblack@eecs.umich.edu 7175040Sgblack@eecs.umich.edu# verify that this stuff works 7185076Sgblack@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 7195076Sgblack@eecs.umich.edu print "Error: can't find Python.h header in", py_includes 7205076Sgblack@eecs.umich.edu Exit(1) 7215076Sgblack@eecs.umich.edu 7225076Sgblack@eecs.umich.edufor lib in py_libs: 7235076Sgblack@eecs.umich.edu if not conf.CheckLib(lib): 7245076Sgblack@eecs.umich.edu print "Error: can't find library %s required by python" % lib 7256444Sgblack@eecs.umich.edu Exit(1) 7266444Sgblack@eecs.umich.edu 7276444Sgblack@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 7286444Sgblack@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7295076Sgblack@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7306444Sgblack@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 7315076Sgblack@eecs.umich.edu Exit(1) 7325076Sgblack@eecs.umich.edu 7335076Sgblack@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 7345076Sgblack@eecs.umich.edu# added to the LIBS environment variable. 7355076Sgblack@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7365040Sgblack@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 7375076Sgblack@eecs.umich.edu 'and/or zlib.h header file.' 7385040Sgblack@eecs.umich.edu print ' Please install zlib and try again.' 7394732Sgblack@eecs.umich.edu Exit(1) 7404756Sgblack@eecs.umich.edu 7416449Sgblack@eecs.umich.edu# Check for librt. 7426449Sgblack@eecs.umich.eduhave_posix_clock = \ 7434732Sgblack@eecs.umich.edu conf.CheckLibWithHeader(None, 'time.h', 'C', 7446449Sgblack@eecs.umich.edu 'clock_nanosleep(0,0,NULL,NULL);') or \ 7456449Sgblack@eecs.umich.edu conf.CheckLibWithHeader('rt', 'time.h', 'C', 7464732Sgblack@eecs.umich.edu 'clock_nanosleep(0,0,NULL,NULL);') 7474732Sgblack@eecs.umich.edu 7484732Sgblack@eecs.umich.eduif not have_posix_clock: 7496447Sgblack@eecs.umich.edu print "Can't find library for POSIX clocks." 7505040Sgblack@eecs.umich.edu 7515076Sgblack@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 7525076Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 7535076Sgblack@eecs.umich.eduif not have_fenv: 7545076Sgblack@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 7555076Sgblack@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 7565076Sgblack@eecs.umich.edu 7575076Sgblack@eecs.umich.edu###################################################################### 7585076Sgblack@eecs.umich.edu# 7595076Sgblack@eecs.umich.edu# Finish the configuration 7605076Sgblack@eecs.umich.edu# 7615076Sgblack@eecs.umich.edumain = conf.Finish() 7625076Sgblack@eecs.umich.edu 7635076Sgblack@eecs.umich.edu###################################################################### 7645076Sgblack@eecs.umich.edu# 7655076Sgblack@eecs.umich.edu# Collect all non-global variables 7665076Sgblack@eecs.umich.edu# 7675076Sgblack@eecs.umich.edu 7685076Sgblack@eecs.umich.edu# Define the universe of supported ISAs 7695076Sgblack@eecs.umich.eduall_isa_list = [ ] 7705076Sgblack@eecs.umich.eduExport('all_isa_list') 7715040Sgblack@eecs.umich.edu 7725076Sgblack@eecs.umich.educlass CpuModel(object): 7735040Sgblack@eecs.umich.edu '''The CpuModel class encapsulates everything the ISA parser needs to 7744733Sgblack@eecs.umich.edu know about a particular CPU model.''' 7754756Sgblack@eecs.umich.edu 7766454Sgblack@eecs.umich.edu # Dict of available CPU model objects. Accessible as CpuModel.dict. 7776454Sgblack@eecs.umich.edu dict = {} 7784733Sgblack@eecs.umich.edu list = [] 7794733Sgblack@eecs.umich.edu defaults = [] 7806454Sgblack@eecs.umich.edu 7816454Sgblack@eecs.umich.edu # Constructor. Automatically adds models to CpuModel.dict. 7826454Sgblack@eecs.umich.edu def __init__(self, name, filename, includes, strings, default=False): 7836454Sgblack@eecs.umich.edu self.name = name # name of model 7844733Sgblack@eecs.umich.edu self.filename = filename # filename for output exec code 7854733Sgblack@eecs.umich.edu self.includes = includes # include files needed in exec file 7864733Sgblack@eecs.umich.edu # The 'strings' dict holds all the per-CPU symbols we can 7876447Sgblack@eecs.umich.edu # substitute into templates etc. 7885040Sgblack@eecs.umich.edu self.strings = strings 7895076Sgblack@eecs.umich.edu 7905076Sgblack@eecs.umich.edu # This cpu is enabled by default 7915076Sgblack@eecs.umich.edu self.default = default 7926453Sgblack@eecs.umich.edu 7935076Sgblack@eecs.umich.edu # Add self to dict 7945076Sgblack@eecs.umich.edu if name in CpuModel.dict: 7955076Sgblack@eecs.umich.edu raise AttributeError, "CpuModel '%s' already registered" % name 7965076Sgblack@eecs.umich.edu CpuModel.dict[name] = self 7976453Sgblack@eecs.umich.edu CpuModel.list.append(name) 7986453Sgblack@eecs.umich.edu 7995076Sgblack@eecs.umich.eduExport('CpuModel') 8006453Sgblack@eecs.umich.edu 8015076Sgblack@eecs.umich.edu# Sticky variables get saved in the variables file so they persist from 8026454Sgblack@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 8036454Sgblack@eecs.umich.edu# value becomes sticky). 8046454Sgblack@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS) 8055076Sgblack@eecs.umich.eduExport('sticky_vars') 8066454Sgblack@eecs.umich.edu 8075076Sgblack@eecs.umich.edu# Sticky variables that should be exported 8085076Sgblack@eecs.umich.eduexport_vars = [] 8095076Sgblack@eecs.umich.eduExport('export_vars') 8105076Sgblack@eecs.umich.edu 8115076Sgblack@eecs.umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 8125040Sgblack@eecs.umich.edu# above variables 8135076Sgblack@eecs.umich.eduif not GetOption('verbose'): 8145040Sgblack@eecs.umich.edu print "Reading SConsopts" 8154732Sgblack@eecs.umich.edufor bdir in [ base_dir ] + extras_dir_list: 8164756Sgblack@eecs.umich.edu if not isdir(bdir): 8176446Sgblack@eecs.umich.edu print "Error: directory '%s' does not exist" % bdir 8186446Sgblack@eecs.umich.edu Exit(1) 8194732Sgblack@eecs.umich.edu for root, dirs, files in os.walk(bdir): 8206446Sgblack@eecs.umich.edu if 'SConsopts' in files: 8214732Sgblack@eecs.umich.edu if GetOption('verbose'): 8226446Sgblack@eecs.umich.edu print "Reading", joinpath(root, 'SConsopts') 8234732Sgblack@eecs.umich.edu SConscript(joinpath(root, 'SConsopts')) 8244732Sgblack@eecs.umich.edu 8254732Sgblack@eecs.umich.eduall_isa_list.sort() 8266447Sgblack@eecs.umich.edu 8275040Sgblack@eecs.umich.edusticky_vars.AddVariables( 8285076Sgblack@eecs.umich.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 8295076Sgblack@eecs.umich.edu ListVariable('CPU_MODELS', 'CPU models', 8305076Sgblack@eecs.umich.edu sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 8315076Sgblack@eecs.umich.edu sorted(CpuModel.list)), 8325076Sgblack@eecs.umich.edu BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 8335076Sgblack@eecs.umich.edu BoolVariable('FORCE_FAST_ALLOC', 8345076Sgblack@eecs.umich.edu 'Enable fast object allocator, even for gem5.debug', False), 8355076Sgblack@eecs.umich.edu BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 8365076Sgblack@eecs.umich.edu False), 8375076Sgblack@eecs.umich.edu BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 8385076Sgblack@eecs.umich.edu False), 8395076Sgblack@eecs.umich.edu BoolVariable('SS_COMPATIBLE_FP', 8405076Sgblack@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 8415076Sgblack@eecs.umich.edu False), 8425076Sgblack@eecs.umich.edu BoolVariable('USE_SSE2', 8435076Sgblack@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 8445076Sgblack@eecs.umich.edu False), 8455076Sgblack@eecs.umich.edu BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 8465076Sgblack@eecs.umich.edu BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 8475076Sgblack@eecs.umich.edu BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 8485040Sgblack@eecs.umich.edu ) 8495076Sgblack@eecs.umich.edu 8505040Sgblack@eecs.umich.edu# These variables get exported to #defines in config/*.hh (see src/SConscript). 8514733Sgblack@eecs.umich.eduexport_vars += ['USE_FENV', 'NO_FAST_ALLOC', 'FORCE_FAST_ALLOC', 8524756Sgblack@eecs.umich.edu 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', 8536456Sgblack@eecs.umich.edu 'TARGET_ISA', 'CP_ANNOTATE', 'USE_POSIX_CLOCK' ] 8546456Sgblack@eecs.umich.edu 8554733Sgblack@eecs.umich.edu################################################### 8564733Sgblack@eecs.umich.edu# 8576456Sgblack@eecs.umich.edu# Define a SCons builder for configuration flag headers. 8586456Sgblack@eecs.umich.edu# 8594733Sgblack@eecs.umich.edu################################################### 8604733Sgblack@eecs.umich.edu 8614823Sgblack@eecs.umich.edu# This function generates a config header file that #defines the 8626456Sgblack@eecs.umich.edu# variable symbol to the current variable setting (0 or 1). The source 8634733Sgblack@eecs.umich.edu# operands are the name of the variable and a Value node containing the 8644733Sgblack@eecs.umich.edu# value of the variable. 8654733Sgblack@eecs.umich.edudef build_config_file(target, source, env): 8666447Sgblack@eecs.umich.edu (variable, value) = [s.get_contents() for s in source] 8675040Sgblack@eecs.umich.edu f = file(str(target[0]), 'w') 8685076Sgblack@eecs.umich.edu print >> f, '#define', variable, value 8695076Sgblack@eecs.umich.edu f.close() 8705076Sgblack@eecs.umich.edu return None 8716456Sgblack@eecs.umich.edu 8725076Sgblack@eecs.umich.edu# Combine the two functions into a scons Action object. 8735076Sgblack@eecs.umich.educonfig_action = MakeAction(build_config_file, Transform("CONFIG H", 2)) 8745076Sgblack@eecs.umich.edu 8755076Sgblack@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 8766456Sgblack@eecs.umich.edu# we're really doing. 8775076Sgblack@eecs.umich.edudef config_emitter(target, source, env): 8786456Sgblack@eecs.umich.edu # extract variable name from Builder arg 8796456Sgblack@eecs.umich.edu variable = str(target[0]) 8805076Sgblack@eecs.umich.edu # True target is config header file 8815076Sgblack@eecs.umich.edu target = joinpath('config', variable.lower() + '.hh') 8825076Sgblack@eecs.umich.edu val = env[variable] 8835076Sgblack@eecs.umich.edu if isinstance(val, bool): 8845076Sgblack@eecs.umich.edu # Force value to 0/1 8855076Sgblack@eecs.umich.edu val = int(val) 8865076Sgblack@eecs.umich.edu elif isinstance(val, str): 8875076Sgblack@eecs.umich.edu val = '"' + val + '"' 8885076Sgblack@eecs.umich.edu 8894732Sgblack@eecs.umich.edu # Sources are variable name & value (packaged in SCons Value nodes) 8906479Sgblack@eecs.umich.edu return ([target], [Value(variable), Value(val)]) 8916479Sgblack@eecs.umich.edu 8926479Sgblack@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 8936479Sgblack@eecs.umich.edu 8946479Sgblack@eecs.umich.edumain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 8956479Sgblack@eecs.umich.edu 8966479Sgblack@eecs.umich.edu# libelf build is shared across all configs in the build root. 8976479Sgblack@eecs.umich.edumain.SConscript('ext/libelf/SConscript', 8986479Sgblack@eecs.umich.edu variant_dir = joinpath(build_root, 'libelf')) 8996479Sgblack@eecs.umich.edu 9006479Sgblack@eecs.umich.edu# gzstream build is shared across all configs in the build root. 9016479Sgblack@eecs.umich.edumain.SConscript('ext/gzstream/SConscript', 9026479Sgblack@eecs.umich.edu variant_dir = joinpath(build_root, 'gzstream')) 9036479Sgblack@eecs.umich.edu 9046479Sgblack@eecs.umich.edu################################################### 9056479Sgblack@eecs.umich.edu# 9066479Sgblack@eecs.umich.edu# This function is used to set up a directory with switching headers 9076479Sgblack@eecs.umich.edu# 9086479Sgblack@eecs.umich.edu################################################### 9096479Sgblack@eecs.umich.edu 9106479Sgblack@eecs.umich.edumain['ALL_ISA_LIST'] = all_isa_list 9116479Sgblack@eecs.umich.edudef make_switching_dir(dname, switch_headers, env): 9126479Sgblack@eecs.umich.edu # Generate the header. target[0] is the full path of the output 9136479Sgblack@eecs.umich.edu # header to generate. 'source' is a dummy variable, since we get the 9146479Sgblack@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 9156479Sgblack@eecs.umich.edu def gen_switch_hdr(target, source, env): 9166479Sgblack@eecs.umich.edu fname = str(target[0]) 9176479Sgblack@eecs.umich.edu f = open(fname, 'w') 9186479Sgblack@eecs.umich.edu isa = env['TARGET_ISA'].lower() 9196479Sgblack@eecs.umich.edu print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 9206479Sgblack@eecs.umich.edu f.close() 9216479Sgblack@eecs.umich.edu 9226479Sgblack@eecs.umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 9236479Sgblack@eecs.umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 9246479Sgblack@eecs.umich.edu # should get re-executed. 9256479Sgblack@eecs.umich.edu switch_hdr_action = MakeAction(gen_switch_hdr, 9266479Sgblack@eecs.umich.edu Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 9276479Sgblack@eecs.umich.edu 9286479Sgblack@eecs.umich.edu # Instantiate actions for each header 9296479Sgblack@eecs.umich.edu for hdr in switch_headers: 9306479Sgblack@eecs.umich.edu env.Command(hdr, [], switch_hdr_action) 9316479Sgblack@eecs.umich.eduExport('make_switching_dir') 9326479Sgblack@eecs.umich.edu 9336479Sgblack@eecs.umich.edu################################################### 9346479Sgblack@eecs.umich.edu# 9356479Sgblack@eecs.umich.edu# Define build environments for selected configurations. 9366479Sgblack@eecs.umich.edu# 9376479Sgblack@eecs.umich.edu################################################### 9386479Sgblack@eecs.umich.edu 9396479Sgblack@eecs.umich.edufor variant_path in variant_paths: 9406479Sgblack@eecs.umich.edu print "Building in", variant_path 9416479Sgblack@eecs.umich.edu 9426479Sgblack@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 9436479Sgblack@eecs.umich.edu env = main.Clone() 9446479Sgblack@eecs.umich.edu env['BUILDDIR'] = variant_path 9456479Sgblack@eecs.umich.edu 9466479Sgblack@eecs.umich.edu # variant_dir is the tail component of build path, and is used to 9476479Sgblack@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 9486479Sgblack@eecs.umich.edu (build_root, variant_dir) = splitpath(variant_path) 9496479Sgblack@eecs.umich.edu 9506479Sgblack@eecs.umich.edu # Set env variables according to the build directory config. 9516479Sgblack@eecs.umich.edu sticky_vars.files = [] 9526479Sgblack@eecs.umich.edu # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 9536479Sgblack@eecs.umich.edu # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 9546479Sgblack@eecs.umich.edu # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 9556479Sgblack@eecs.umich.edu current_vars_file = joinpath(build_root, 'variables', variant_dir) 9566479Sgblack@eecs.umich.edu if isfile(current_vars_file): 9576479Sgblack@eecs.umich.edu sticky_vars.files.append(current_vars_file) 9586479Sgblack@eecs.umich.edu print "Using saved variables file %s" % current_vars_file 9596479Sgblack@eecs.umich.edu else: 9606479Sgblack@eecs.umich.edu # Build dir-specific variables file doesn't exist. 9616479Sgblack@eecs.umich.edu 9626479Sgblack@eecs.umich.edu # Make sure the directory is there so we can create it later 9636479Sgblack@eecs.umich.edu opt_dir = dirname(current_vars_file) 9646479Sgblack@eecs.umich.edu if not isdir(opt_dir): 9656479Sgblack@eecs.umich.edu mkdir(opt_dir) 9666479Sgblack@eecs.umich.edu 9676479Sgblack@eecs.umich.edu # Get default build variables from source tree. Variables are 9686479Sgblack@eecs.umich.edu # normally determined by name of $VARIANT_DIR, but can be 9696479Sgblack@eecs.umich.edu # overridden by '--default=' arg on command line. 9706479Sgblack@eecs.umich.edu default = GetOption('default') 9716479Sgblack@eecs.umich.edu opts_dir = joinpath(main.root.abspath, 'build_opts') 9726479Sgblack@eecs.umich.edu if default: 9736479Sgblack@eecs.umich.edu default_vars_files = [joinpath(build_root, 'variables', default), 9746479Sgblack@eecs.umich.edu joinpath(opts_dir, default)] 9756479Sgblack@eecs.umich.edu else: 9766479Sgblack@eecs.umich.edu default_vars_files = [joinpath(opts_dir, variant_dir)] 9776479Sgblack@eecs.umich.edu existing_files = filter(isfile, default_vars_files) 9786479Sgblack@eecs.umich.edu if existing_files: 9796479Sgblack@eecs.umich.edu default_vars_file = existing_files[0] 9806479Sgblack@eecs.umich.edu sticky_vars.files.append(default_vars_file) 9816479Sgblack@eecs.umich.edu print "Variables file %s not found,\n using defaults in %s" \ 9826479Sgblack@eecs.umich.edu % (current_vars_file, default_vars_file) 9836479Sgblack@eecs.umich.edu else: 9846479Sgblack@eecs.umich.edu print "Error: cannot find variables file %s or " \ 9856479Sgblack@eecs.umich.edu "default file(s) %s" \ 9866479Sgblack@eecs.umich.edu % (current_vars_file, ' or '.join(default_vars_files)) 9876479Sgblack@eecs.umich.edu Exit(1) 9886479Sgblack@eecs.umich.edu 9896479Sgblack@eecs.umich.edu # Apply current variable settings to env 9906479Sgblack@eecs.umich.edu sticky_vars.Update(env) 9915040Sgblack@eecs.umich.edu 9925246Sgblack@eecs.umich.edu help_texts["local_vars"] += \ 9935040Sgblack@eecs.umich.edu "Build variables for %s:\n" % variant_dir \ 9945040Sgblack@eecs.umich.edu + sticky_vars.GenerateHelpText(env) 9955040Sgblack@eecs.umich.edu 9965040Sgblack@eecs.umich.edu # Process variable settings. 9975040Sgblack@eecs.umich.edu 9985426Sgblack@eecs.umich.edu if not have_fenv and env['USE_FENV']: 9995426Sgblack@eecs.umich.edu print "Warning: <fenv.h> not available; " \ 10005426Sgblack@eecs.umich.edu "forcing USE_FENV to False in", variant_dir + "." 10015426Sgblack@eecs.umich.edu env['USE_FENV'] = False 10025426Sgblack@eecs.umich.edu 10035426Sgblack@eecs.umich.edu if not env['USE_FENV']: 10045426Sgblack@eecs.umich.edu print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 10055426Sgblack@eecs.umich.edu print " FP results may deviate slightly from other platforms." 10065426Sgblack@eecs.umich.edu 10075426Sgblack@eecs.umich.edu if env['EFENCE']: 10085040Sgblack@eecs.umich.edu env.Append(LIBS=['efence']) 10095246Sgblack@eecs.umich.edu 10105040Sgblack@eecs.umich.edu # Save sticky variable settings back to current variables file 10115040Sgblack@eecs.umich.edu sticky_vars.Save(current_vars_file, env) 10125040Sgblack@eecs.umich.edu 10135040Sgblack@eecs.umich.edu if env['USE_SSE2']: 10145426Sgblack@eecs.umich.edu env.Append(CCFLAGS=['-msse2']) 10155426Sgblack@eecs.umich.edu 10165426Sgblack@eecs.umich.edu # The src/SConscript file sets up the build rules in 'env' according 10175040Sgblack@eecs.umich.edu # to the configured variables. It returns a list of environments, 10185040Sgblack@eecs.umich.edu # one for each variant build (debug, opt, etc.) 10195116Sgblack@eecs.umich.edu envList = SConscript('src/SConscript', variant_dir = variant_path, 10204951Sgblack@eecs.umich.edu exports = 'env') 10215011Sgblack@eecs.umich.edu 10225011Sgblack@eecs.umich.edu # Set up the regression tests for each build. 10235040Sgblack@eecs.umich.edu for e in envList: 10245040Sgblack@eecs.umich.edu SConscript('tests/SConscript', 10255040Sgblack@eecs.umich.edu variant_dir = joinpath(variant_path, 'tests', e.Label), 10265040Sgblack@eecs.umich.edu exports = { 'env' : e }, duplicate = False) 10276345Sgblack@eecs.umich.edu 10284732Sgblack@eecs.umich.edu# base help text 10295426Sgblack@eecs.umich.eduHelp(''' 10305426Sgblack@eecs.umich.eduUsage: scons [scons options] [build variables] [target(s)] 10315426Sgblack@eecs.umich.edu 10325426Sgblack@eecs.umich.eduExtra scons options: 10335426Sgblack@eecs.umich.edu%(options)s 10345426Sgblack@eecs.umich.edu 10355426Sgblack@eecs.umich.eduGlobal build variables: 10365426Sgblack@eecs.umich.edu%(global_vars)s 10375426Sgblack@eecs.umich.edu 10385426Sgblack@eecs.umich.edu%(local_vars)s 10395426Sgblack@eecs.umich.edu''' % help_texts) 10405426Sgblack@eecs.umich.edu