SConstruct revision 7769
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 4955SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 5955SN/A# All rights reserved. 6955SN/A# 7955SN/A# Redistribution and use in source and binary forms, with or without 8955SN/A# modification, are permitted provided that the following conditions are 9955SN/A# met: redistributions of source code must retain the above copyright 10955SN/A# notice, this list of conditions and the following disclaimer; 11955SN/A# redistributions in binary form must reproduce the above copyright 12955SN/A# notice, this list of conditions and the following disclaimer in the 13955SN/A# documentation and/or other materials provided with the distribution; 14955SN/A# neither the name of the copyright holders nor the names of its 15955SN/A# contributors may be used to endorse or promote products derived from 16955SN/A# this software without specific prior written permission. 17955SN/A# 18955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 282665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 292665Ssaidi@eecs.umich.edu# 30955SN/A# Authors: Steve Reinhardt 31955SN/A# Nathan Binkert 32955SN/A 33955SN/A################################################### 34955SN/A# 352632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 362632Sstever@eecs.umich.edu# 372632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 382632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 39955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 402632Sstever@eecs.umich.edu# the optimized full-system version). 412632Sstever@eecs.umich.edu# 422761Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 432632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 442632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 452632Sstever@eecs.umich.edu# built for the same host system. 462761Sstever@eecs.umich.edu# 472761Sstever@eecs.umich.edu# Examples: 482761Sstever@eecs.umich.edu# 492632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 502632Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 512761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 522761Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 532761Sstever@eecs.umich.edu# 542761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 552761Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 562632Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 572632Sstever@eecs.umich.edu# file. 582632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 592632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 602632Sstever@eecs.umich.edu# 612632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 622632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 63955SN/A# file), you can use 'scons -h' to print all the M5-specific build 64955SN/A# options as well. 65955SN/A# 66955SN/A################################################### 67955SN/A 683918Ssaidi@eecs.umich.edu# Check for recent-enough Python and SCons versions. 694202Sbinkertn@umich.edutry: 704678Snate@binkert.org # Really old versions of scons only take two options for the 71955SN/A # function, so check once without the revision and once with the 722656Sstever@eecs.umich.edu # revision, the first instance will fail for stuff other than 732656Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 742656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 752656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98, 1) 762656Sstever@eecs.umich.eduexcept SystemExit, e: 772656Sstever@eecs.umich.edu print """ 782656Sstever@eecs.umich.eduFor more details, see: 792653Sstever@eecs.umich.edu http://m5sim.org/wiki/index.php/Compiling_M5 802653Sstever@eecs.umich.edu""" 812653Sstever@eecs.umich.edu raise 822653Sstever@eecs.umich.edu 832653Sstever@eecs.umich.edu# We ensure the python version early because we have stuff that 842653Sstever@eecs.umich.edu# requires python 2.4 852653Sstever@eecs.umich.edutry: 862653Sstever@eecs.umich.edu EnsurePythonVersion(2, 4) 872653Sstever@eecs.umich.eduexcept SystemExit, e: 882653Sstever@eecs.umich.edu print """ 892653Sstever@eecs.umich.eduYou can use a non-default installation of the Python interpreter by 901852SN/Aeither (1) rearranging your PATH so that scons finds the non-default 91955SN/A'python' first or (2) explicitly invoking an alternative interpreter 92955SN/Aon the scons script. 93955SN/A 943717Sstever@eecs.umich.eduFor more details, see: 953716Sstever@eecs.umich.edu http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 96955SN/A""" 971533SN/A raise 983716Sstever@eecs.umich.edu 991533SN/A# Global Python includes 1004678Snate@binkert.orgimport os 1014678Snate@binkert.orgimport re 1024678Snate@binkert.orgimport subprocess 1034678Snate@binkert.orgimport sys 1044678Snate@binkert.org 1054678Snate@binkert.orgfrom os import mkdir, environ 1064678Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1074678Snate@binkert.orgfrom os.path import exists, isdir, isfile 1084678Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1094678Snate@binkert.org 1104678Snate@binkert.org# SCons includes 1114678Snate@binkert.orgimport SCons 1124678Snate@binkert.orgimport SCons.Node 1134678Snate@binkert.org 1144678Snate@binkert.orgextra_python_paths = [ 1154678Snate@binkert.org Dir('src/python').srcnode().abspath, # M5 includes 1164678Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1174678Snate@binkert.org ] 1184678Snate@binkert.org 1194678Snate@binkert.orgsys.path[1:1] = extra_python_paths 1204678Snate@binkert.org 1214678Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1224678Snate@binkert.org 1234678Snate@binkert.org######################################################################## 1244678Snate@binkert.org# 1254678Snate@binkert.org# Set up the main build environment. 1264678Snate@binkert.org# 1274678Snate@binkert.org######################################################################## 128955SN/Ause_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 129955SN/A 'PYTHONPATH', 'RANLIB' ]) 1302632Sstever@eecs.umich.edu 1312632Sstever@eecs.umich.eduuse_env = {} 132955SN/Afor key,val in os.environ.iteritems(): 133955SN/A if key in use_vars or key.startswith("M5"): 134955SN/A use_env[key] = val 135955SN/A 1362632Sstever@eecs.umich.edumain = Environment(ENV=use_env) 137955SN/Amain.root = Dir(".") # The current directory (where this file lives). 1382632Sstever@eecs.umich.edumain.srcdir = Dir("src") # The source directory 1392632Sstever@eecs.umich.edu 1402632Sstever@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 1412632Sstever@eecs.umich.edu# as well 1422632Sstever@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths) 1432632Sstever@eecs.umich.edu 1442632Sstever@eecs.umich.edu######################################################################## 1453053Sstever@eecs.umich.edu# 1463053Sstever@eecs.umich.edu# Mercurial Stuff. 1473053Sstever@eecs.umich.edu# 1483053Sstever@eecs.umich.edu# If the M5 directory is a mercurial repository, we should do some 1493053Sstever@eecs.umich.edu# extra things. 1503053Sstever@eecs.umich.edu# 1513053Sstever@eecs.umich.edu######################################################################## 1523053Sstever@eecs.umich.edu 1533053Sstever@eecs.umich.eduhgdir = main.root.Dir(".hg") 1543053Sstever@eecs.umich.edu 1553053Sstever@eecs.umich.edumercurial_style_message = """ 1563053Sstever@eecs.umich.eduYou're missing the M5 style hook. 1573053Sstever@eecs.umich.eduPlease install the hook so we can ensure that all code fits a common style. 1583053Sstever@eecs.umich.edu 1593053Sstever@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc 1603053Sstever@eecs.umich.eduor your personal .hgrc 1612632Sstever@eecs.umich.edu---------------- 1622632Sstever@eecs.umich.edu 1632632Sstever@eecs.umich.edu[extensions] 1642632Sstever@eecs.umich.edustyle = %s/util/style.py 1652632Sstever@eecs.umich.edu 1662632Sstever@eecs.umich.edu[hooks] 1673718Sstever@eecs.umich.edupretxncommit.style = python:style.check_whitespace 1683718Sstever@eecs.umich.edu""" % (main.root) 1693718Sstever@eecs.umich.edu 1703718Sstever@eecs.umich.edumercurial_bin_not_found = """ 1713718Sstever@eecs.umich.eduMercurial binary cannot be found, unfortunately this means that we 1723718Sstever@eecs.umich.educannot easily determine the version of M5 that you are running and 1733718Sstever@eecs.umich.eduthis makes error messages more difficult to collect. Please consider 1743718Sstever@eecs.umich.eduinstalling mercurial if you choose to post an error message 1753718Sstever@eecs.umich.edu""" 1763718Sstever@eecs.umich.edu 1773718Sstever@eecs.umich.edumercurial_lib_not_found = """ 1783718Sstever@eecs.umich.eduMercurial libraries cannot be found, ignoring style hook 1793718Sstever@eecs.umich.eduIf you are actually a M5 developer, please fix this and 1802634Sstever@eecs.umich.edurun the style hook. It is important. 1812634Sstever@eecs.umich.edu""" 1822632Sstever@eecs.umich.edu 1832638Sstever@eecs.umich.eduhg_info = "Unknown" 1842632Sstever@eecs.umich.eduif hgdir.exists(): 1852632Sstever@eecs.umich.edu # 1) Grab repository revision if we know it. 1862632Sstever@eecs.umich.edu cmd = "hg id -n -i -t -b" 1872632Sstever@eecs.umich.edu try: 1882632Sstever@eecs.umich.edu hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 1892632Sstever@eecs.umich.edu except OSError: 1901858SN/A print mercurial_bin_not_found 1913716Sstever@eecs.umich.edu 1922638Sstever@eecs.umich.edu # 2) Ensure that the style hook is in place. 1932638Sstever@eecs.umich.edu try: 1942638Sstever@eecs.umich.edu ui = None 1952638Sstever@eecs.umich.edu if ARGUMENTS.get('IGNORE_STYLE') != 'True': 1962638Sstever@eecs.umich.edu from mercurial import ui 1972638Sstever@eecs.umich.edu ui = ui.ui() 1982638Sstever@eecs.umich.edu except ImportError: 1993716Sstever@eecs.umich.edu print mercurial_lib_not_found 2002634Sstever@eecs.umich.edu 2012634Sstever@eecs.umich.edu if ui is not None: 202955SN/A ui.readconfig(hgdir.File('hgrc').abspath) 203955SN/A style_hook = ui.config('hooks', 'pretxncommit.style', None) 204955SN/A 205955SN/A if not style_hook: 206955SN/A print mercurial_style_message 207955SN/A sys.exit(1) 208955SN/Aelse: 209955SN/A print ".hg directory not found" 2101858SN/A 2111858SN/Amain['HG_INFO'] = hg_info 2122632Sstever@eecs.umich.edu 213955SN/A################################################### 2143643Ssaidi@eecs.umich.edu# 2153643Ssaidi@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2163643Ssaidi@eecs.umich.edu# the target(s). 2173643Ssaidi@eecs.umich.edu# 2183643Ssaidi@eecs.umich.edu################################################### 2193643Ssaidi@eecs.umich.edu 2203643Ssaidi@eecs.umich.edu# Find default configuration & binary. 2213643Ssaidi@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2224494Ssaidi@eecs.umich.edu 2234494Ssaidi@eecs.umich.edu# helper function: find last occurrence of element in list 2243716Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 2251105SN/A for i in range(len(l)+offs, 0, -1): 2262667Sstever@eecs.umich.edu if l[i] == elt: 2272667Sstever@eecs.umich.edu return i 2282667Sstever@eecs.umich.edu raise ValueError, "element not found" 2292667Sstever@eecs.umich.edu 2302667Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2312667Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2321869SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2331869SN/A# recognize that ALPHA_SE specifies the configuration because it 2341869SN/A# follow 'build' in the bulid path. 2351869SN/A 2361869SN/A# Generate absolute paths to targets so we can see where the build dir is 2371065SN/Aif COMMAND_LINE_TARGETS: 2382632Sstever@eecs.umich.edu # Ask SCons which directory it was invoked from 2392632Sstever@eecs.umich.edu launch_dir = GetLaunchDir() 2403918Ssaidi@eecs.umich.edu # Make targets relative to invocation directory 2413918Ssaidi@eecs.umich.edu abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2423940Ssaidi@eecs.umich.edu COMMAND_LINE_TARGETS] 2433918Ssaidi@eecs.umich.eduelse: 2443918Ssaidi@eecs.umich.edu # Default targets are relative to root of tree 2453918Ssaidi@eecs.umich.edu abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2463918Ssaidi@eecs.umich.edu DEFAULT_TARGETS] 2473918Ssaidi@eecs.umich.edu 2483918Ssaidi@eecs.umich.edu 2493940Ssaidi@eecs.umich.edu# Generate a list of the unique build roots and configs that the 2503940Ssaidi@eecs.umich.edu# collected targets reference. 2513940Ssaidi@eecs.umich.eduvariant_paths = [] 2523942Ssaidi@eecs.umich.edubuild_root = None 2533940Ssaidi@eecs.umich.edufor t in abs_targets: 2543918Ssaidi@eecs.umich.edu path_dirs = t.split('/') 2553918Ssaidi@eecs.umich.edu try: 256955SN/A build_top = rfind(path_dirs, 'build', -2) 2571858SN/A except: 2583918Ssaidi@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 2593918Ssaidi@eecs.umich.edu Exit(1) 2603918Ssaidi@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2613918Ssaidi@eecs.umich.edu if not build_root: 2623940Ssaidi@eecs.umich.edu build_root = this_build_root 2633940Ssaidi@eecs.umich.edu else: 2643918Ssaidi@eecs.umich.edu if this_build_root != build_root: 2653918Ssaidi@eecs.umich.edu print "Error: build targets not under same build root\n"\ 2663918Ssaidi@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 2673918Ssaidi@eecs.umich.edu Exit(1) 2683918Ssaidi@eecs.umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 2693918Ssaidi@eecs.umich.edu if variant_path not in variant_paths: 2703918Ssaidi@eecs.umich.edu variant_paths.append(variant_path) 2713918Ssaidi@eecs.umich.edu 2723918Ssaidi@eecs.umich.edu# Make sure build_root exists (might not if this is the first build there) 2733940Ssaidi@eecs.umich.eduif not isdir(build_root): 2743918Ssaidi@eecs.umich.edu mkdir(build_root) 2753918Ssaidi@eecs.umich.edumain['BUILDROOT'] = build_root 2761851SN/A 2771851SN/AExport('main') 2781858SN/A 2792632Sstever@eecs.umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 280955SN/A 2813053Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 2823053Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 2833053Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2843053Sstever@eecs.umich.edu# (soft) links work better. 2853053Sstever@eecs.umich.edumain.SetOption('duplicate', 'soft-copy') 2863053Sstever@eecs.umich.edu 2873053Sstever@eecs.umich.edu# 2883053Sstever@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 2893053Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 2904742Sstever@eecs.umich.edu# 2914742Sstever@eecs.umich.edu 2923053Sstever@eecs.umich.edu# Variable validators & converters for global sticky variables 2933053Sstever@eecs.umich.edudef PathListMakeAbsolute(val): 2943053Sstever@eecs.umich.edu if not val: 2953053Sstever@eecs.umich.edu return val 2963053Sstever@eecs.umich.edu f = lambda p: abspath(expanduser(p)) 2973053Sstever@eecs.umich.edu return ':'.join(map(f, val.split(':'))) 2983053Sstever@eecs.umich.edu 2993053Sstever@eecs.umich.edudef PathListAllExist(key, val, env): 3003053Sstever@eecs.umich.edu if not val: 3012667Sstever@eecs.umich.edu return 3024554Sbinkertn@umich.edu paths = val.split(':') 3034554Sbinkertn@umich.edu for path in paths: 3042667Sstever@eecs.umich.edu if not isdir(path): 3054554Sbinkertn@umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3064554Sbinkertn@umich.edu 3074554Sbinkertn@umich.eduglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3084554Sbinkertn@umich.edu 3094554Sbinkertn@umich.eduglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3104554Sbinkertn@umich.eduglobal_nonsticky_vars = Variables(args=ARGUMENTS) 3114554Sbinkertn@umich.edu 3124554Sbinkertn@umich.eduglobal_sticky_vars.AddVariables( 3134554Sbinkertn@umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3144554Sbinkertn@umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3152667Sstever@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3164554Sbinkertn@umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3174554Sbinkertn@umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3184554Sbinkertn@umich.edu ('EXTRAS', 'Add Extra directories to the compilation', '', 3194554Sbinkertn@umich.edu PathListAllExist, PathListMakeAbsolute), 3202667Sstever@eecs.umich.edu ) 3214554Sbinkertn@umich.edu 3222667Sstever@eecs.umich.eduglobal_nonsticky_vars.AddVariables( 3234554Sbinkertn@umich.edu ('VERBOSE', 'Print full tool command lines', False), 3244554Sbinkertn@umich.edu ('update_ref', 'Update test reference outputs', False) 3252667Sstever@eecs.umich.edu ) 3262638Sstever@eecs.umich.edu 3272638Sstever@eecs.umich.edu 3282638Sstever@eecs.umich.edu# base help text 3293716Sstever@eecs.umich.eduhelp_text = ''' 3303716Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 3311858SN/A 3323118Sstever@eecs.umich.eduGlobal sticky options: 3333118Sstever@eecs.umich.edu''' 3343118Sstever@eecs.umich.edu 3353118Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3363118Sstever@eecs.umich.eduglobal_sticky_vars.Update(main) 3373118Sstever@eecs.umich.eduglobal_nonsticky_vars.Update(main) 3383118Sstever@eecs.umich.edu 3393118Sstever@eecs.umich.eduhelp_text += global_sticky_vars.GenerateHelpText(main) 3403118Sstever@eecs.umich.eduhelp_text += global_nonsticky_vars.GenerateHelpText(main) 3413118Sstever@eecs.umich.edu 3423118Sstever@eecs.umich.edu# Save sticky variable settings back to current variables file 3433716Sstever@eecs.umich.eduglobal_sticky_vars.Save(global_sticky_vars_file, main) 3443118Sstever@eecs.umich.edu 3453118Sstever@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3463118Sstever@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3473118Sstever@eecs.umich.edubase_dir = main.srcdir.abspath 3483118Sstever@eecs.umich.eduif main['EXTRAS']: 3493118Sstever@eecs.umich.edu extras_dir_list = main['EXTRAS'].split(':') 3503118Sstever@eecs.umich.eduelse: 3513118Sstever@eecs.umich.edu extras_dir_list = [] 3523118Sstever@eecs.umich.edu 3533716Sstever@eecs.umich.eduExport('base_dir') 3543118Sstever@eecs.umich.eduExport('extras_dir_list') 3553118Sstever@eecs.umich.edu 3563118Sstever@eecs.umich.edu# the ext directory should be on the #includes path 3573118Sstever@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3583118Sstever@eecs.umich.edu 3593118Sstever@eecs.umich.edudef _STRIP(path, env): 3603118Sstever@eecs.umich.edu path = str(path) 3613118Sstever@eecs.umich.edu variant_base = env['BUILDROOT'] + os.path.sep 3623118Sstever@eecs.umich.edu if path.startswith(variant_base): 3633118Sstever@eecs.umich.edu path = path[len(variant_base):] 3643483Ssaidi@eecs.umich.edu elif path.startswith('build/'): 3653494Ssaidi@eecs.umich.edu path = path[6:] 3663494Ssaidi@eecs.umich.edu return path 3673483Ssaidi@eecs.umich.edu 3683483Ssaidi@eecs.umich.edudef _STRIP_SOURCE(target, source, env, for_signature): 3693483Ssaidi@eecs.umich.edu return _STRIP(source[0], env) 3703053Sstever@eecs.umich.edumain['STRIP_SOURCE'] = _STRIP_SOURCE 3713053Sstever@eecs.umich.edu 3723918Ssaidi@eecs.umich.edudef _STRIP_TARGET(target, source, env, for_signature): 3733053Sstever@eecs.umich.edu return _STRIP(target[0], env) 3743053Sstever@eecs.umich.edumain['STRIP_TARGET'] = _STRIP_TARGET 3753053Sstever@eecs.umich.edu 3763053Sstever@eecs.umich.eduif main['VERBOSE']: 3773053Sstever@eecs.umich.edu def MakeAction(action, string, *args, **kwargs): 3781858SN/A return Action(action, *args, **kwargs) 3791858SN/Aelse: 3801858SN/A MakeAction = Action 3811858SN/A main['CCCOMSTR'] = ' [ CC] $STRIP_SOURCE' 3821858SN/A main['CXXCOMSTR'] = ' [ CXX] $STRIP_SOURCE' 3831858SN/A main['ASCOMSTR'] = ' [ AS] $STRIP_SOURCE' 3841859SN/A main['SWIGCOMSTR'] = ' [ SWIG] $STRIP_SOURCE' 3851858SN/A main['ARCOMSTR'] = ' [ AR] $STRIP_TARGET' 3861858SN/A main['LINKCOMSTR'] = ' [ LINK] $STRIP_TARGET' 3871858SN/A main['RANLIBCOMSTR'] = ' [ RANLIB] $STRIP_TARGET' 3881859SN/A main['M4COMSTR'] = ' [ M4] $STRIP_TARGET' 3891859SN/A main['SHCCCOMSTR'] = ' [ SHCC] $STRIP_TARGET' 3901862SN/A main['SHCXXCOMSTR'] = ' [ SHCXX] $STRIP_TARGET' 3913053Sstever@eecs.umich.eduExport('MakeAction') 3923053Sstever@eecs.umich.edu 3933053Sstever@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 3943053Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 3951859SN/A 3961859SN/Amain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3971859SN/Amain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3981859SN/Amain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 3991859SN/Aif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 4001859SN/A print 'Error: How can we have two at the same time?' 4011859SN/A Exit(1) 4021859SN/A 4031862SN/A# Set up default C++ compiler flags 4041859SN/Aif main['GCC']: 4051859SN/A main.Append(CCFLAGS=['-pipe']) 4061859SN/A main.Append(CCFLAGS=['-fno-strict-aliasing']) 4071858SN/A main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4081858SN/A main.Append(CXXFLAGS=['-Wno-deprecated']) 4092139SN/A # Read the GCC version to check for versions with bugs 4104202Sbinkertn@umich.edu # Note CCVERSION doesn't work here because it is run with the CC 4114202Sbinkertn@umich.edu # before we override it from the command line 4122139SN/A gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4132155SN/A if not compareVersions(gcc_version, '4.4.1') or \ 4144202Sbinkertn@umich.edu not compareVersions(gcc_version, '4.4.2'): 4154202Sbinkertn@umich.edu print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 4164202Sbinkertn@umich.edu main.Append(CCFLAGS=['-fno-tree-vectorize']) 4172155SN/Aelif main['ICC']: 4181869SN/A pass #Fix me... add warning flags once we clean up icc warnings 4191869SN/Aelif main['SUNCC']: 4201869SN/A main.Append(CCFLAGS=['-Qoption ccfe']) 4211869SN/A main.Append(CCFLAGS=['-features=gcc']) 4224202Sbinkertn@umich.edu main.Append(CCFLAGS=['-features=extensions']) 4234202Sbinkertn@umich.edu main.Append(CCFLAGS=['-library=stlport4']) 4244202Sbinkertn@umich.edu main.Append(CCFLAGS=['-xar']) 4254202Sbinkertn@umich.edu #main.Append(CCFLAGS=['-instances=semiexplicit']) 4264202Sbinkertn@umich.eduelse: 4274202Sbinkertn@umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 4284202Sbinkertn@umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 4294202Sbinkertn@umich.edu Exit(1) 4304202Sbinkertn@umich.edu 4314202Sbinkertn@umich.edu# Set up common yacc/bison flags (needed for Ruby) 4324202Sbinkertn@umich.edumain['YACCFLAGS'] = '-d' 4334202Sbinkertn@umich.edumain['YACCHXXFILESUFFIX'] = '.hh' 4344202Sbinkertn@umich.edu 4354202Sbinkertn@umich.edu# Do this after we save setting back, or else we'll tack on an 4364202Sbinkertn@umich.edu# extra 'qdo' every time we run scons. 4374202Sbinkertn@umich.eduif main['BATCH']: 4384773Snate@binkert.org main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 4394773Snate@binkert.org main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 4404773Snate@binkert.org main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 4414773Snate@binkert.org main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 4424773Snate@binkert.org main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 4434773Snate@binkert.org 4444773Snate@binkert.orgif sys.platform == 'cygwin': 4451869SN/A # cygwin has some header file issues... 4464202Sbinkertn@umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 4471869SN/A 4482508SN/A# Check for SWIG 4492508SN/Aif not main.has_key('SWIG'): 4502508SN/A print 'Error: SWIG utility not found.' 4512508SN/A print ' Please install (see http://www.swig.org) and retry.' 4524202Sbinkertn@umich.edu Exit(1) 4531869SN/A 4541869SN/A# Check for appropriate SWIG version 4551869SN/Aswig_version = readCommand(('swig', '-version'), exception='').split() 4561869SN/A# First 3 words should be "SWIG Version x.y.z" 4571869SN/Aif len(swig_version) < 3 or \ 4581869SN/A swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 4591965SN/A print 'Error determining SWIG version.' 4601965SN/A Exit(1) 4611965SN/A 4621869SN/Amin_swig_version = '1.3.28' 4631869SN/Aif compareVersions(swig_version[2], min_swig_version) < 0: 4642733Sktlim@umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 4651869SN/A print ' Installed version:', swig_version[2] 4661884SN/A Exit(1) 4671884SN/A 4683356Sbinkertn@umich.edu# Set up SWIG flags & scanner 4693356Sbinkertn@umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4703356Sbinkertn@umich.edumain.Append(SWIGFLAGS=swig_flags) 4714773Snate@binkert.org 4724773Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 4734773Snate@binkert.org# stuff for some reason 4741869SN/Ascanners = [] 4751858SN/Afor scanner in main['SCANNERS']: 4761869SN/A skeys = scanner.skeys 4771869SN/A if skeys == '.i': 4781869SN/A continue 4791858SN/A 4802761Sstever@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4811869SN/A continue 4822733Sktlim@umich.edu 4833584Ssaidi@eecs.umich.edu scanners.append(scanner) 4841869SN/A 4851869SN/A# add the new swig scanner that we like better 4861869SN/Afrom SCons.Scanner import ClassicCPP as CPPScanner 4871869SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4881869SN/Ascanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4891869SN/A 4901858SN/A# replace the scanners list that has what we want 491955SN/Amain['SCANNERS'] = scanners 492955SN/A 4931869SN/A# Add a custom Check function to the Configure context so that we can 4941869SN/A# figure out if the compiler adds leading underscores to global 4951869SN/A# variables. This is needed for the autogenerated asm files that we 4961869SN/A# use for embedding the python code. 4971869SN/Adef CheckLeading(context): 4981869SN/A context.Message("Checking for leading underscore in global variables...") 4991869SN/A # 1) Define a global variable called x from asm so the C compiler 5001869SN/A # won't change the symbol at all. 5011869SN/A # 2) Declare that variable. 5021869SN/A # 3) Use the variable 5031869SN/A # 5041869SN/A # If the compiler prepends an underscore, this will successfully 5051869SN/A # link because the external symbol 'x' will be called '_x' which 5061869SN/A # was defined by the asm statement. If the compiler does not 5071869SN/A # prepend an underscore, this will not successfully link because 5081869SN/A # '_x' will have been defined by assembly, while the C portion of 5091869SN/A # the code will be trying to use 'x' 5101869SN/A ret = context.TryLink(''' 5111869SN/A asm(".globl _x; _x: .byte 0"); 5121869SN/A extern int x; 5131869SN/A int main() { return x; } 5141869SN/A ''', extension=".c") 5151869SN/A context.env.Append(LEADING_UNDERSCORE=ret) 5161869SN/A context.Result(ret) 5171869SN/A return ret 5181869SN/A 5191869SN/A# Platform-specific configuration. Note again that we assume that all 5201869SN/A# builds under a given build root run on the same host platform. 5211869SN/Aconf = Configure(main, 5223716Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 5233356Sbinkertn@umich.edu log_file = joinpath(build_root, 'scons_config.log'), 5243356Sbinkertn@umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 5253356Sbinkertn@umich.edu 5263356Sbinkertn@umich.edu# Check for leading underscores. Don't really need to worry either 5273356Sbinkertn@umich.edu# way so don't need to check the return code. 5283356Sbinkertn@umich.educonf.CheckLeading() 5293356Sbinkertn@umich.edu 5301869SN/A# Check if we should compile a 64 bit binary on Mac OS X/Darwin 5311869SN/Atry: 5321869SN/A import platform 5331869SN/A uname = platform.uname() 5341869SN/A if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 5351869SN/A if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 5361869SN/A main.Append(CCFLAGS=['-arch', 'x86_64']) 5372655Sstever@eecs.umich.edu main.Append(CFLAGS=['-arch', 'x86_64']) 5382655Sstever@eecs.umich.edu main.Append(LINKFLAGS=['-arch', 'x86_64']) 5392655Sstever@eecs.umich.edu main.Append(ASFLAGS=['-arch', 'x86_64']) 5402655Sstever@eecs.umich.eduexcept: 5412655Sstever@eecs.umich.edu pass 5422655Sstever@eecs.umich.edu 5432655Sstever@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 5442655Sstever@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 5452655Sstever@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 5462655Sstever@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 5472655Sstever@eecs.umich.edu# more optimistic null object that returns True instead. 5482655Sstever@eecs.umich.eduif not conf: 5492655Sstever@eecs.umich.edu def NullCheck(*args, **kwargs): 5502655Sstever@eecs.umich.edu return True 5512655Sstever@eecs.umich.edu 5522655Sstever@eecs.umich.edu class NullConf: 5532655Sstever@eecs.umich.edu def __init__(self, env): 5542655Sstever@eecs.umich.edu self.env = env 5552655Sstever@eecs.umich.edu def Finish(self): 5562655Sstever@eecs.umich.edu return self.env 5572655Sstever@eecs.umich.edu def __getattr__(self, mname): 5582655Sstever@eecs.umich.edu return NullCheck 5592655Sstever@eecs.umich.edu 5602655Sstever@eecs.umich.edu conf = NullConf(main) 5612655Sstever@eecs.umich.edu 5622655Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 5632634Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 5642634Sstever@eecs.umich.edu# installation used to run scons (and thus this script). If you want 5652634Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how 5662634Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 5672634Sstever@eecs.umich.edufrom distutils import sysconfig 5682634Sstever@eecs.umich.edu 5692638Sstever@eecs.umich.edupy_getvar = sysconfig.get_config_var 5702638Sstever@eecs.umich.edu 5713716Sstever@eecs.umich.edupy_debug = getattr(sys, 'pydebug', False) 5722638Sstever@eecs.umich.edupy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 5732638Sstever@eecs.umich.edu 5741869SN/Apy_general_include = sysconfig.get_python_inc() 5751869SN/Apy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5763546Sgblack@eecs.umich.edupy_includes = [ py_general_include ] 5773546Sgblack@eecs.umich.eduif py_platform_include != py_general_include: 5783546Sgblack@eecs.umich.edu py_includes.append(py_platform_include) 5793546Sgblack@eecs.umich.edu 5804202Sbinkertn@umich.edupy_lib_path = [ py_getvar('LIBDIR') ] 5813546Sgblack@eecs.umich.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5823546Sgblack@eecs.umich.edu# shared library in prefix/lib/. 5833546Sgblack@eecs.umich.eduif not py_getvar('Py_ENABLE_SHARED'): 5843546Sgblack@eecs.umich.edu py_lib_path.append(py_getvar('LIBPL')) 5853546Sgblack@eecs.umich.edu 5863546Sgblack@eecs.umich.edupy_libs = [] 5873546Sgblack@eecs.umich.edufor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 5883546Sgblack@eecs.umich.edu assert lib.startswith('-l') 5893546Sgblack@eecs.umich.edu lib = lib[2:] 5903546Sgblack@eecs.umich.edu if lib not in py_libs: 5914202Sbinkertn@umich.edu py_libs.append(lib) 5923546Sgblack@eecs.umich.edupy_libs.append(py_version) 5933546Sgblack@eecs.umich.edu 5943546Sgblack@eecs.umich.edumain.Append(CPPPATH=py_includes) 5953546Sgblack@eecs.umich.edumain.Append(LIBPATH=py_lib_path) 5963546Sgblack@eecs.umich.edu 5973546Sgblack@eecs.umich.edu# Cache build files in the supplied directory. 5983546Sgblack@eecs.umich.eduif main['M5_BUILD_CACHE']: 5993546Sgblack@eecs.umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 6003546Sgblack@eecs.umich.edu CacheDir(main['M5_BUILD_CACHE']) 6013546Sgblack@eecs.umich.edu 6023546Sgblack@eecs.umich.edu 6033546Sgblack@eecs.umich.edu# verify that this stuff works 6043546Sgblack@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 6053546Sgblack@eecs.umich.edu print "Error: can't find Python.h header in", py_includes 6063546Sgblack@eecs.umich.edu Exit(1) 6073546Sgblack@eecs.umich.edu 6083546Sgblack@eecs.umich.edufor lib in py_libs: 6093546Sgblack@eecs.umich.edu if not conf.CheckLib(lib): 6103546Sgblack@eecs.umich.edu print "Error: can't find library %s required by python" % lib 6113546Sgblack@eecs.umich.edu Exit(1) 6124202Sbinkertn@umich.edu 6133546Sgblack@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 6143546Sgblack@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 6153546Sgblack@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 616955SN/A print "Can't find library with socket calls (e.g. accept())" 617955SN/A Exit(1) 618955SN/A 619955SN/A# Check for zlib. If the check passes, libz will be automatically 6201858SN/A# added to the LIBS environment variable. 6211858SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 6221858SN/A print 'Error: did not find needed zlib compression library '\ 6232632Sstever@eecs.umich.edu 'and/or zlib.h header file.' 6242632Sstever@eecs.umich.edu print ' Please install zlib and try again.' 6254773Snate@binkert.org Exit(1) 6264773Snate@binkert.org 6272632Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 6282632Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 6292632Sstever@eecs.umich.eduif not have_fenv: 6302634Sstever@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 6312638Sstever@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 6322023SN/A 6332632Sstever@eecs.umich.edu###################################################################### 6342632Sstever@eecs.umich.edu# 6352632Sstever@eecs.umich.edu# Check for mysql. 6362632Sstever@eecs.umich.edu# 6372632Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config') 6383716Sstever@eecs.umich.eduhave_mysql = bool(mysql_config) 6392632Sstever@eecs.umich.edu 6402632Sstever@eecs.umich.edu# Check MySQL version. 6412632Sstever@eecs.umich.eduif have_mysql: 6422632Sstever@eecs.umich.edu mysql_version = readCommand(mysql_config + ' --version') 6432632Sstever@eecs.umich.edu min_mysql_version = '4.1' 6442023SN/A if compareVersions(mysql_version, min_mysql_version) < 0: 6452632Sstever@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 6462632Sstever@eecs.umich.edu print ' Version', mysql_version, 'detected.' 6471889SN/A have_mysql = False 6481889SN/A 6492632Sstever@eecs.umich.edu# Set up mysql_config commands. 6502632Sstever@eecs.umich.eduif have_mysql: 6512632Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 6522632Sstever@eecs.umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 6533716Sstever@eecs.umich.edu # older mysql_config versions don't support --include, use 6543716Sstever@eecs.umich.edu # --cflags instead 6552632Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 6562632Sstever@eecs.umich.edu # This seems to work in all versions 6572632Sstever@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 6582632Sstever@eecs.umich.edu 6592632Sstever@eecs.umich.edu###################################################################### 6602632Sstever@eecs.umich.edu# 6612632Sstever@eecs.umich.edu# Finish the configuration 6622632Sstever@eecs.umich.edu# 6631888SN/Amain = conf.Finish() 6641888SN/A 6651869SN/A###################################################################### 6661869SN/A# 6671858SN/A# Collect all non-global variables 6682598SN/A# 6692598SN/A 6702598SN/A# Define the universe of supported ISAs 6712598SN/Aall_isa_list = [ ] 6722598SN/AExport('all_isa_list') 6731858SN/A 6741858SN/Aclass CpuModel(object): 6751858SN/A '''The CpuModel class encapsulates everything the ISA parser needs to 6761858SN/A know about a particular CPU model.''' 6771858SN/A 6781858SN/A # Dict of available CPU model objects. Accessible as CpuModel.dict. 6791858SN/A dict = {} 6801858SN/A list = [] 6811858SN/A defaults = [] 6821871SN/A 6831858SN/A # Constructor. Automatically adds models to CpuModel.dict. 6841858SN/A def __init__(self, name, filename, includes, strings, default=False): 6851858SN/A self.name = name # name of model 6861858SN/A self.filename = filename # filename for output exec code 6871858SN/A self.includes = includes # include files needed in exec file 6881858SN/A # The 'strings' dict holds all the per-CPU symbols we can 6891858SN/A # substitute into templates etc. 6901858SN/A self.strings = strings 6911858SN/A 6921858SN/A # This cpu is enabled by default 6931858SN/A self.default = default 6941859SN/A 6951859SN/A # Add self to dict 6961869SN/A if name in CpuModel.dict: 6971888SN/A raise AttributeError, "CpuModel '%s' already registered" % name 6982632Sstever@eecs.umich.edu CpuModel.dict[name] = self 6991869SN/A CpuModel.list.append(name) 7001884SN/A 7011884SN/AExport('CpuModel') 7021884SN/A 7031884SN/A# Sticky variables get saved in the variables file so they persist from 7041884SN/A# one invocation to the next (unless overridden, in which case the new 7051884SN/A# value becomes sticky). 7061965SN/Asticky_vars = Variables(args=ARGUMENTS) 7071965SN/AExport('sticky_vars') 7081965SN/A 7092761Sstever@eecs.umich.edu# Sticky variables that should be exported 7101869SN/Aexport_vars = [] 7111869SN/AExport('export_vars') 7122632Sstever@eecs.umich.edu 7132667Sstever@eecs.umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 7141869SN/A# above variables 7151869SN/Afor bdir in [ base_dir ] + extras_dir_list: 7162929Sktlim@umich.edu for root, dirs, files in os.walk(bdir): 7172929Sktlim@umich.edu if 'SConsopts' in files: 7183716Sstever@eecs.umich.edu print "Reading", joinpath(root, 'SConsopts') 7192929Sktlim@umich.edu SConscript(joinpath(root, 'SConsopts')) 720955SN/A 7212598SN/Aall_isa_list.sort() 7222598SN/A 7233546Sgblack@eecs.umich.edusticky_vars.AddVariables( 724955SN/A EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 725955SN/A BoolVariable('FULL_SYSTEM', 'Full-system support', False), 726955SN/A ListVariable('CPU_MODELS', 'CPU models', 7271530SN/A sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 728955SN/A sorted(CpuModel.list)), 729955SN/A BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 730955SN/A BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 731 False), 732 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 733 False), 734 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 735 False), 736 BoolVariable('SS_COMPATIBLE_FP', 737 'Make floating-point results compatible with SimpleScalar', 738 False), 739 BoolVariable('USE_SSE2', 740 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 741 False), 742 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 743 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 744 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 745 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 746 BoolVariable('RUBY', 'Build with Ruby', False), 747 ) 748 749# These variables get exported to #defines in config/*.hh (see src/SConscript). 750export_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 751 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 752 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 753 754################################################### 755# 756# Define a SCons builder for configuration flag headers. 757# 758################################################### 759 760# This function generates a config header file that #defines the 761# variable symbol to the current variable setting (0 or 1). The source 762# operands are the name of the variable and a Value node containing the 763# value of the variable. 764def build_config_file(target, source, env): 765 (variable, value) = [s.get_contents() for s in source] 766 f = file(str(target[0]), 'w') 767 print >> f, '#define', variable, value 768 f.close() 769 return None 770 771# Generate the message to be printed when building the config file. 772def build_config_file_string(target, source, env): 773 (variable, value) = [s.get_contents() for s in source] 774 return "Defining %s as %s in %s." % (variable, value, target[0]) 775 776# Combine the two functions into a scons Action object. 777config_action = Action(build_config_file, build_config_file_string) 778 779# The emitter munges the source & target node lists to reflect what 780# we're really doing. 781def config_emitter(target, source, env): 782 # extract variable name from Builder arg 783 variable = str(target[0]) 784 # True target is config header file 785 target = joinpath('config', variable.lower() + '.hh') 786 val = env[variable] 787 if isinstance(val, bool): 788 # Force value to 0/1 789 val = int(val) 790 elif isinstance(val, str): 791 val = '"' + val + '"' 792 793 # Sources are variable name & value (packaged in SCons Value nodes) 794 return ([target], [Value(variable), Value(val)]) 795 796config_builder = Builder(emitter = config_emitter, action = config_action) 797 798main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 799 800# libelf build is shared across all configs in the build root. 801main.SConscript('ext/libelf/SConscript', 802 variant_dir = joinpath(build_root, 'libelf')) 803 804# gzstream build is shared across all configs in the build root. 805main.SConscript('ext/gzstream/SConscript', 806 variant_dir = joinpath(build_root, 'gzstream')) 807 808################################################### 809# 810# This function is used to set up a directory with switching headers 811# 812################################################### 813 814main['ALL_ISA_LIST'] = all_isa_list 815def make_switching_dir(dname, switch_headers, env): 816 # Generate the header. target[0] is the full path of the output 817 # header to generate. 'source' is a dummy variable, since we get the 818 # list of ISAs from env['ALL_ISA_LIST']. 819 def gen_switch_hdr(target, source, env): 820 fname = str(target[0]) 821 f = open(fname, 'w') 822 isa = env['TARGET_ISA'].lower() 823 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 824 f.close() 825 826 # Build SCons Action object. 'varlist' specifies env vars that this 827 # action depends on; when env['ALL_ISA_LIST'] changes these actions 828 # should get re-executed. 829 switch_hdr_action = MakeAction(gen_switch_hdr, 830 " [GENERATE] $STRIP_TARGET", varlist=['ALL_ISA_LIST']) 831 832 # Instantiate actions for each header 833 for hdr in switch_headers: 834 env.Command(hdr, [], switch_hdr_action) 835Export('make_switching_dir') 836 837################################################### 838# 839# Define build environments for selected configurations. 840# 841################################################### 842 843for variant_path in variant_paths: 844 print "Building in", variant_path 845 846 # Make a copy of the build-root environment to use for this config. 847 env = main.Clone() 848 env['BUILDDIR'] = variant_path 849 850 # variant_dir is the tail component of build path, and is used to 851 # determine the build parameters (e.g., 'ALPHA_SE') 852 (build_root, variant_dir) = splitpath(variant_path) 853 854 # Set env variables according to the build directory config. 855 sticky_vars.files = [] 856 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 857 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 858 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 859 current_vars_file = joinpath(build_root, 'variables', variant_dir) 860 if isfile(current_vars_file): 861 sticky_vars.files.append(current_vars_file) 862 print "Using saved variables file %s" % current_vars_file 863 else: 864 # Build dir-specific variables file doesn't exist. 865 866 # Make sure the directory is there so we can create it later 867 opt_dir = dirname(current_vars_file) 868 if not isdir(opt_dir): 869 mkdir(opt_dir) 870 871 # Get default build variables from source tree. Variables are 872 # normally determined by name of $VARIANT_DIR, but can be 873 # overriden by 'default=' arg on command line. 874 default_vars_file = joinpath('build_opts', 875 ARGUMENTS.get('default', variant_dir)) 876 if isfile(default_vars_file): 877 sticky_vars.files.append(default_vars_file) 878 print "Variables file %s not found,\n using defaults in %s" \ 879 % (current_vars_file, default_vars_file) 880 else: 881 print "Error: cannot find variables file %s or %s" \ 882 % (current_vars_file, default_vars_file) 883 Exit(1) 884 885 # Apply current variable settings to env 886 sticky_vars.Update(env) 887 888 help_text += "\nSticky variables for %s:\n" % variant_dir \ 889 + sticky_vars.GenerateHelpText(env) 890 891 # Process variable settings. 892 893 if not have_fenv and env['USE_FENV']: 894 print "Warning: <fenv.h> not available; " \ 895 "forcing USE_FENV to False in", variant_dir + "." 896 env['USE_FENV'] = False 897 898 if not env['USE_FENV']: 899 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 900 print " FP results may deviate slightly from other platforms." 901 902 if env['EFENCE']: 903 env.Append(LIBS=['efence']) 904 905 if env['USE_MYSQL']: 906 if not have_mysql: 907 print "Warning: MySQL not available; " \ 908 "forcing USE_MYSQL to False in", variant_dir + "." 909 env['USE_MYSQL'] = False 910 else: 911 print "Compiling in", variant_dir, "with MySQL support." 912 env.ParseConfig(mysql_config_libs) 913 env.ParseConfig(mysql_config_include) 914 915 # Save sticky variable settings back to current variables file 916 sticky_vars.Save(current_vars_file, env) 917 918 if env['USE_SSE2']: 919 env.Append(CCFLAGS=['-msse2']) 920 921 # The src/SConscript file sets up the build rules in 'env' according 922 # to the configured variables. It returns a list of environments, 923 # one for each variant build (debug, opt, etc.) 924 envList = SConscript('src/SConscript', variant_dir = variant_path, 925 exports = 'env') 926 927 # Set up the regression tests for each build. 928 for e in envList: 929 SConscript('tests/SConscript', 930 variant_dir = joinpath(variant_path, 'tests', e.Label), 931 exports = { 'env' : e }, duplicate = False) 932 933Help(help_text) 934