SConstruct revision 7807
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 28955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29955SN/A# 30955SN/A# Authors: Steve Reinhardt 31955SN/A# Nathan Binkert 32955SN/A 332632Sstever@eecs.umich.edu################################################### 342632Sstever@eecs.umich.edu# 352632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 362632Sstever@eecs.umich.edu# 37955SN/A# 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>' 392632Sstever@eecs.umich.edu# 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# 422632Sstever@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. 462632Sstever@eecs.umich.edu# 472632Sstever@eecs.umich.edu# Examples: 482632Sstever@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. 512632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 522632Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 532632Sstever@eecs.umich.edu# 542632Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 552632Sstever@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. 58955SN/A# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 59955SN/A# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 60955SN/A# 61955SN/A# You can use 'scons -H' to print scons options. If you're in this 62955SN/A# '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. 651858SN/A# 661858SN/A################################################### 672653Sstever@eecs.umich.edu 682653Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. 692653Sstever@eecs.umich.edutry: 702653Sstever@eecs.umich.edu # Really old versions of scons only take two options for the 712653Sstever@eecs.umich.edu # function, so check once without the revision and once with the 722653Sstever@eecs.umich.edu # revision, the first instance will fail for stuff other than 732653Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 742653Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 752653Sstever@eecs.umich.edu EnsureSConsVersion(0, 98, 1) 762653Sstever@eecs.umich.eduexcept SystemExit, e: 772653Sstever@eecs.umich.edu print """ 781852SN/AFor more details, see: 79955SN/A http://m5sim.org/wiki/index.php/Compiling_M5 80955SN/A""" 81955SN/A raise 822632Sstever@eecs.umich.edu 832632Sstever@eecs.umich.edu# We ensure the python version early because we have stuff that 84955SN/A# requires python 2.4 851533SN/Atry: 862632Sstever@eecs.umich.edu EnsurePythonVersion(2, 4) 871533SN/Aexcept SystemExit, e: 88955SN/A print """ 89955SN/AYou can use a non-default installation of the Python interpreter by 902632Sstever@eecs.umich.edueither (1) rearranging your PATH so that scons finds the non-default 912632Sstever@eecs.umich.edu'python' first or (2) explicitly invoking an alternative interpreter 92955SN/Aon the scons script. 93955SN/A 94955SN/AFor more details, see: 95955SN/A http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 962632Sstever@eecs.umich.edu""" 97955SN/A raise 982632Sstever@eecs.umich.edu 99955SN/A# Global Python includes 100955SN/Aimport os 1012632Sstever@eecs.umich.eduimport re 1022632Sstever@eecs.umich.eduimport subprocess 1032632Sstever@eecs.umich.eduimport sys 1042632Sstever@eecs.umich.edu 1052632Sstever@eecs.umich.edufrom os import mkdir, environ 1062632Sstever@eecs.umich.edufrom os.path import abspath, basename, dirname, expanduser, normpath 1072632Sstever@eecs.umich.edufrom os.path import exists, isdir, isfile 1082632Sstever@eecs.umich.edufrom os.path import join as joinpath, split as splitpath 1092632Sstever@eecs.umich.edu 1102632Sstever@eecs.umich.edu# SCons includes 1112632Sstever@eecs.umich.eduimport SCons 1122632Sstever@eecs.umich.eduimport SCons.Node 1132632Sstever@eecs.umich.edu 1142632Sstever@eecs.umich.eduextra_python_paths = [ 1152632Sstever@eecs.umich.edu Dir('src/python').srcnode().abspath, # M5 includes 1162632Sstever@eecs.umich.edu Dir('ext/ply').srcnode().abspath, # ply is used by several files 1172632Sstever@eecs.umich.edu ] 1182634Sstever@eecs.umich.edu 1192634Sstever@eecs.umich.edusys.path[1:1] = extra_python_paths 1202632Sstever@eecs.umich.edu 1212638Sstever@eecs.umich.edufrom m5.util import compareVersions, readCommand 1222632Sstever@eecs.umich.edu 1232632Sstever@eecs.umich.edu######################################################################## 1242632Sstever@eecs.umich.edu# 1252632Sstever@eecs.umich.edu# Set up the main build environment. 1262632Sstever@eecs.umich.edu# 1272632Sstever@eecs.umich.edu######################################################################## 1281858SN/Ause_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1292638Sstever@eecs.umich.edu 'PYTHONPATH', 'RANLIB' ]) 1302638Sstever@eecs.umich.edu 1312638Sstever@eecs.umich.eduuse_env = {} 1322638Sstever@eecs.umich.edufor key,val in os.environ.iteritems(): 1332638Sstever@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1342638Sstever@eecs.umich.edu use_env[key] = val 1352638Sstever@eecs.umich.edu 1362638Sstever@eecs.umich.edumain = Environment(ENV=use_env) 1372634Sstever@eecs.umich.edumain.root = Dir(".") # The current directory (where this file lives). 1382634Sstever@eecs.umich.edumain.srcdir = Dir("src") # The source directory 1392634Sstever@eecs.umich.edu 140955SN/A# add useful python code PYTHONPATH so it can be used by subprocesses 141955SN/A# as well 142955SN/Amain.AppendENVPath('PYTHONPATH', extra_python_paths) 143955SN/A 144955SN/A######################################################################## 145955SN/A# 146955SN/A# Mercurial Stuff. 147955SN/A# 1481858SN/A# If the M5 directory is a mercurial repository, we should do some 1491858SN/A# extra things. 1502632Sstever@eecs.umich.edu# 151955SN/A######################################################################## 1521858SN/A 1531105SN/Ahgdir = main.root.Dir(".hg") 1541869SN/A 1551869SN/Amercurial_style_message = """ 1561869SN/AYou're missing the M5 style hook. 1571869SN/APlease install the hook so we can ensure that all code fits a common style. 1581869SN/A 1591065SN/AAll you'd need to do is add the following lines to your repository .hg/hgrc 1602632Sstever@eecs.umich.eduor your personal .hgrc 1612632Sstever@eecs.umich.edu---------------- 162955SN/A 1631858SN/A[extensions] 1641858SN/Astyle = %s/util/style.py 1651858SN/A 1661858SN/A[hooks] 1671851SN/Apretxncommit.style = python:style.check_whitespace 1681851SN/Apre-qrefresh.style = python:style.check_whitespace 1691858SN/A""" % (main.root) 1702632Sstever@eecs.umich.edu 171955SN/Amercurial_bin_not_found = """ 1722655Sstever@eecs.umich.eduMercurial binary cannot be found, unfortunately this means that we 1732655Sstever@eecs.umich.educannot easily determine the version of M5 that you are running and 1742655Sstever@eecs.umich.eduthis makes error messages more difficult to collect. Please consider 1752655Sstever@eecs.umich.eduinstalling mercurial if you choose to post an error message 1762655Sstever@eecs.umich.edu""" 1772655Sstever@eecs.umich.edu 1782655Sstever@eecs.umich.edumercurial_lib_not_found = """ 1791858SN/AMercurial libraries cannot be found, ignoring style hook 1801858SN/AIf you are actually a M5 developer, please fix this and 1812638Sstever@eecs.umich.edurun the style hook. It is important. 1822638Sstever@eecs.umich.edu""" 1832638Sstever@eecs.umich.edu 1842638Sstever@eecs.umich.eduhg_info = "Unknown" 1852638Sstever@eecs.umich.eduif hgdir.exists(): 1861858SN/A # 1) Grab repository revision if we know it. 1871858SN/A cmd = "hg id -n -i -t -b" 1881858SN/A try: 1891858SN/A hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 1901858SN/A except OSError: 1911858SN/A print mercurial_bin_not_found 1921858SN/A 1931859SN/A # 2) Ensure that the style hook is in place. 1941858SN/A try: 1951858SN/A ui = None 1961858SN/A if ARGUMENTS.get('IGNORE_STYLE') != 'True': 1971859SN/A from mercurial import ui 1981859SN/A ui = ui.ui() 1991862SN/A except ImportError: 2001862SN/A print mercurial_lib_not_found 2011862SN/A 2021862SN/A if ui is not None: 2031859SN/A ui.readconfig(hgdir.File('hgrc').abspath) 2041859SN/A style_hook = ui.config('hooks', 'pretxncommit.style', None) 2051963SN/A 2061963SN/A if not style_hook: 2071859SN/A print mercurial_style_message 2081859SN/A sys.exit(1) 2091859SN/Aelse: 2101859SN/A print ".hg directory not found" 2111859SN/A 2121859SN/Amain['HG_INFO'] = hg_info 2131859SN/A 2141859SN/A################################################### 2151862SN/A# 2161859SN/A# Figure out which configurations to set up based on the path(s) of 2171859SN/A# the target(s). 2181859SN/A# 2191858SN/A################################################### 2201858SN/A 2212139SN/A# Find default configuration & binary. 2222139SN/ADefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2232139SN/A 2242155SN/A# helper function: find last occurrence of element in list 2252623SN/Adef rfind(l, elt, offs = -1): 2262637Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2272155SN/A if l[i] == elt: 2281869SN/A return i 2291869SN/A raise ValueError, "element not found" 2301869SN/A 2311869SN/A# Each target must have 'build' in the interior of the path; the 2321869SN/A# directory below this will determine the build parameters. For 2332139SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2341869SN/A# recognize that ALPHA_SE specifies the configuration because it 2352508SN/A# follow 'build' in the bulid path. 2362508SN/A 2372508SN/A# Generate absolute paths to targets so we can see where the build dir is 2382508SN/Aif COMMAND_LINE_TARGETS: 2392635Sstever@eecs.umich.edu # Ask SCons which directory it was invoked from 2402635Sstever@eecs.umich.edu launch_dir = GetLaunchDir() 2411869SN/A # Make targets relative to invocation directory 2421869SN/A abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2431869SN/A COMMAND_LINE_TARGETS] 2441869SN/Aelse: 2451869SN/A # Default targets are relative to root of tree 2461869SN/A abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2471869SN/A DEFAULT_TARGETS] 2481869SN/A 2491965SN/A 2501965SN/A# Generate a list of the unique build roots and configs that the 2511965SN/A# collected targets reference. 2521869SN/Avariant_paths = [] 2531869SN/Abuild_root = None 2541869SN/Afor t in abs_targets: 2551869SN/A path_dirs = t.split('/') 2561884SN/A try: 2571884SN/A build_top = rfind(path_dirs, 'build', -2) 2581884SN/A except: 2591869SN/A print "Error: no non-leaf 'build' dir found on target path", t 2601858SN/A Exit(1) 2611869SN/A this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2621869SN/A if not build_root: 2631869SN/A build_root = this_build_root 2641869SN/A else: 2651869SN/A if this_build_root != build_root: 2661858SN/A print "Error: build targets not under same build root\n"\ 2671869SN/A " %s\n %s" % (build_root, this_build_root) 2681869SN/A Exit(1) 2691869SN/A variant_path = joinpath('/',*path_dirs[:build_top+2]) 2701869SN/A if variant_path not in variant_paths: 2711869SN/A variant_paths.append(variant_path) 2721869SN/A 2731869SN/A# Make sure build_root exists (might not if this is the first build there) 2741869SN/Aif not isdir(build_root): 2751869SN/A mkdir(build_root) 2761869SN/Amain['BUILDROOT'] = build_root 2771858SN/A 278955SN/AExport('main') 279955SN/A 2801869SN/Amain.SConsignFile(joinpath(build_root, "sconsign")) 2811869SN/A 2821869SN/A# Default duplicate option is to use hard links, but this messes up 2831869SN/A# when you use emacs to edit a file in the target dir, as emacs moves 2841869SN/A# file to file~ then copies to file, breaking the link. Symbolic 2851869SN/A# (soft) links work better. 2861869SN/Amain.SetOption('duplicate', 'soft-copy') 2871869SN/A 2881869SN/A# 2891869SN/A# Set up global sticky variables... these are common to an entire build 2901869SN/A# tree (not specific to a particular build like ALPHA_SE) 2911869SN/A# 2921869SN/A 2931869SN/A# Variable validators & converters for global sticky variables 2941869SN/Adef PathListMakeAbsolute(val): 2951869SN/A if not val: 2961869SN/A return val 2971869SN/A f = lambda p: abspath(expanduser(p)) 2981869SN/A return ':'.join(map(f, val.split(':'))) 2991869SN/A 3001869SN/Adef PathListAllExist(key, val, env): 3011869SN/A if not val: 3021869SN/A return 3031869SN/A paths = val.split(':') 3041869SN/A for path in paths: 3051869SN/A if not isdir(path): 3061869SN/A raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3071869SN/A 3081869SN/Aglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3091869SN/A 3101869SN/Aglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3111869SN/Aglobal_nonsticky_vars = Variables(args=ARGUMENTS) 3121869SN/A 3131869SN/Aglobal_sticky_vars.AddVariables( 3141869SN/A ('CC', 'C compiler', environ.get('CC', main['CC'])), 3151869SN/A ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3161869SN/A ('BATCH', 'Use batch pool for build and tests', False), 3171869SN/A ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3181869SN/A ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3192655Sstever@eecs.umich.edu ('EXTRAS', 'Add Extra directories to the compilation', '', 3202655Sstever@eecs.umich.edu PathListAllExist, PathListMakeAbsolute), 3212655Sstever@eecs.umich.edu ) 3222655Sstever@eecs.umich.edu 3232655Sstever@eecs.umich.eduglobal_nonsticky_vars.AddVariables( 3242655Sstever@eecs.umich.edu ('VERBOSE', 'Print full tool command lines', False), 3252655Sstever@eecs.umich.edu ('update_ref', 'Update test reference outputs', False) 3262655Sstever@eecs.umich.edu ) 3272655Sstever@eecs.umich.edu 3282655Sstever@eecs.umich.edu 3292655Sstever@eecs.umich.edu# base help text 3302655Sstever@eecs.umich.eduhelp_text = ''' 3312655Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 3322655Sstever@eecs.umich.edu 3332655Sstever@eecs.umich.eduGlobal sticky options: 3342655Sstever@eecs.umich.edu''' 3352655Sstever@eecs.umich.edu 3362655Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3372655Sstever@eecs.umich.eduglobal_sticky_vars.Update(main) 3382655Sstever@eecs.umich.eduglobal_nonsticky_vars.Update(main) 3392655Sstever@eecs.umich.edu 3402655Sstever@eecs.umich.eduhelp_text += global_sticky_vars.GenerateHelpText(main) 3412655Sstever@eecs.umich.eduhelp_text += global_nonsticky_vars.GenerateHelpText(main) 3422655Sstever@eecs.umich.edu 3432655Sstever@eecs.umich.edu# Save sticky variable settings back to current variables file 3442655Sstever@eecs.umich.eduglobal_sticky_vars.Save(global_sticky_vars_file, main) 3452634Sstever@eecs.umich.edu 3462634Sstever@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3472634Sstever@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3482634Sstever@eecs.umich.edubase_dir = main.srcdir.abspath 3492634Sstever@eecs.umich.eduif main['EXTRAS']: 3502634Sstever@eecs.umich.edu extras_dir_list = main['EXTRAS'].split(':') 3512638Sstever@eecs.umich.eduelse: 3522638Sstever@eecs.umich.edu extras_dir_list = [] 3532638Sstever@eecs.umich.edu 3542638Sstever@eecs.umich.eduExport('base_dir') 3552638Sstever@eecs.umich.eduExport('extras_dir_list') 3561869SN/A 3571869SN/A# the ext directory should be on the #includes path 358955SN/Amain.Append(CPPPATH=[Dir('ext')]) 359955SN/A 360955SN/Adef _STRIP(path, env): 361955SN/A path = str(path) 3621858SN/A variant_base = env['BUILDROOT'] + os.path.sep 3631858SN/A if path.startswith(variant_base): 3641858SN/A path = path[len(variant_base):] 3652632Sstever@eecs.umich.edu elif path.startswith('build/'): 3662632Sstever@eecs.umich.edu path = path[6:] 3672632Sstever@eecs.umich.edu return path 3682632Sstever@eecs.umich.edu 3692632Sstever@eecs.umich.edudef _STRIP_SOURCE(target, source, env, for_signature): 3702634Sstever@eecs.umich.edu return _STRIP(source[0], env) 3712638Sstever@eecs.umich.edumain['STRIP_SOURCE'] = _STRIP_SOURCE 3722023SN/A 3732632Sstever@eecs.umich.edudef _STRIP_TARGET(target, source, env, for_signature): 3742632Sstever@eecs.umich.edu return _STRIP(target[0], env) 3752632Sstever@eecs.umich.edumain['STRIP_TARGET'] = _STRIP_TARGET 3762632Sstever@eecs.umich.edu 3772632Sstever@eecs.umich.eduif main['VERBOSE']: 3782632Sstever@eecs.umich.edu def MakeAction(action, string, *args, **kwargs): 3792632Sstever@eecs.umich.edu return Action(action, *args, **kwargs) 3802632Sstever@eecs.umich.eduelse: 3812632Sstever@eecs.umich.edu MakeAction = Action 3822632Sstever@eecs.umich.edu main['CCCOMSTR'] = ' [ CC] $STRIP_SOURCE' 3832632Sstever@eecs.umich.edu main['CXXCOMSTR'] = ' [ CXX] $STRIP_SOURCE' 3842023SN/A main['ASCOMSTR'] = ' [ AS] $STRIP_SOURCE' 3852632Sstever@eecs.umich.edu main['SWIGCOMSTR'] = ' [ SWIG] $STRIP_SOURCE' 3862632Sstever@eecs.umich.edu main['ARCOMSTR'] = ' [ AR] $STRIP_TARGET' 3871889SN/A main['LINKCOMSTR'] = ' [ LINK] $STRIP_TARGET' 3881889SN/A main['RANLIBCOMSTR'] = ' [ RANLIB] $STRIP_TARGET' 3892632Sstever@eecs.umich.edu main['M4COMSTR'] = ' [ M4] $STRIP_TARGET' 3902632Sstever@eecs.umich.edu main['SHCCCOMSTR'] = ' [ SHCC] $STRIP_TARGET' 3912632Sstever@eecs.umich.edu main['SHCXXCOMSTR'] = ' [ SHCXX] $STRIP_TARGET' 3922632Sstever@eecs.umich.eduExport('MakeAction') 3932632Sstever@eecs.umich.edu 3942632Sstever@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 3952632Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 3962632Sstever@eecs.umich.edu 3972632Sstever@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3982632Sstever@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3992632Sstever@eecs.umich.edumain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4002632Sstever@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 4012632Sstever@eecs.umich.edu print 'Error: How can we have two at the same time?' 4022632Sstever@eecs.umich.edu Exit(1) 4031888SN/A 4041888SN/A# Set up default C++ compiler flags 4051869SN/Aif main['GCC']: 4061869SN/A main.Append(CCFLAGS=['-pipe']) 4071858SN/A main.Append(CCFLAGS=['-fno-strict-aliasing']) 4082598SN/A main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4092598SN/A main.Append(CXXFLAGS=['-Wno-deprecated']) 4102598SN/A # Read the GCC version to check for versions with bugs 4112598SN/A # Note CCVERSION doesn't work here because it is run with the CC 4122598SN/A # before we override it from the command line 4131858SN/A gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4141858SN/A if not compareVersions(gcc_version, '4.4.1') or \ 4151858SN/A not compareVersions(gcc_version, '4.4.2'): 4161858SN/A print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 4171858SN/A main.Append(CCFLAGS=['-fno-tree-vectorize']) 4181858SN/Aelif main['ICC']: 4191858SN/A pass #Fix me... add warning flags once we clean up icc warnings 4201858SN/Aelif main['SUNCC']: 4211858SN/A main.Append(CCFLAGS=['-Qoption ccfe']) 4221871SN/A main.Append(CCFLAGS=['-features=gcc']) 4231858SN/A main.Append(CCFLAGS=['-features=extensions']) 4241858SN/A main.Append(CCFLAGS=['-library=stlport4']) 4251858SN/A main.Append(CCFLAGS=['-xar']) 4261858SN/A #main.Append(CCFLAGS=['-instances=semiexplicit']) 4271858SN/Aelse: 4281858SN/A print 'Error: Don\'t know what compiler options to use for your compiler.' 4291858SN/A print ' Please fix SConstruct and src/SConscript and try again.' 4301858SN/A Exit(1) 4311858SN/A 4321858SN/A# Set up common yacc/bison flags (needed for Ruby) 4331858SN/Amain['YACCFLAGS'] = '-d' 4341859SN/Amain['YACCHXXFILESUFFIX'] = '.hh' 4351859SN/A 4361869SN/A# Do this after we save setting back, or else we'll tack on an 4371888SN/A# extra 'qdo' every time we run scons. 4382632Sstever@eecs.umich.eduif main['BATCH']: 4391869SN/A main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 4401884SN/A main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 4411884SN/A main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 4421884SN/A main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 4431884SN/A main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 4441884SN/A 4451884SN/Aif sys.platform == 'cygwin': 4461965SN/A # cygwin has some header file issues... 4471965SN/A main.Append(CCFLAGS=["-Wno-uninitialized"]) 4481965SN/A 449955SN/A# Check for SWIG 4501869SN/Aif not main.has_key('SWIG'): 4511869SN/A print 'Error: SWIG utility not found.' 4522632Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 4531869SN/A Exit(1) 4541869SN/A 4551869SN/A# Check for appropriate SWIG version 4562632Sstever@eecs.umich.eduswig_version = readCommand(('swig', '-version'), exception='').split() 4572632Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 4582632Sstever@eecs.umich.eduif len(swig_version) < 3 or \ 4592632Sstever@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 460955SN/A print 'Error determining SWIG version.' 4612598SN/A Exit(1) 4622598SN/A 463955SN/Amin_swig_version = '1.3.28' 464955SN/Aif compareVersions(swig_version[2], min_swig_version) < 0: 465955SN/A print 'Error: SWIG version', min_swig_version, 'or newer required.' 4661530SN/A print ' Installed version:', swig_version[2] 467955SN/A Exit(1) 468955SN/A 469955SN/A# Set up SWIG flags & scanner 470swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 471main.Append(SWIGFLAGS=swig_flags) 472 473# filter out all existing swig scanners, they mess up the dependency 474# stuff for some reason 475scanners = [] 476for scanner in main['SCANNERS']: 477 skeys = scanner.skeys 478 if skeys == '.i': 479 continue 480 481 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 482 continue 483 484 scanners.append(scanner) 485 486# add the new swig scanner that we like better 487from SCons.Scanner import ClassicCPP as CPPScanner 488swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 489scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 490 491# replace the scanners list that has what we want 492main['SCANNERS'] = scanners 493 494# Add a custom Check function to the Configure context so that we can 495# figure out if the compiler adds leading underscores to global 496# variables. This is needed for the autogenerated asm files that we 497# use for embedding the python code. 498def CheckLeading(context): 499 context.Message("Checking for leading underscore in global variables...") 500 # 1) Define a global variable called x from asm so the C compiler 501 # won't change the symbol at all. 502 # 2) Declare that variable. 503 # 3) Use the variable 504 # 505 # If the compiler prepends an underscore, this will successfully 506 # link because the external symbol 'x' will be called '_x' which 507 # was defined by the asm statement. If the compiler does not 508 # prepend an underscore, this will not successfully link because 509 # '_x' will have been defined by assembly, while the C portion of 510 # the code will be trying to use 'x' 511 ret = context.TryLink(''' 512 asm(".globl _x; _x: .byte 0"); 513 extern int x; 514 int main() { return x; } 515 ''', extension=".c") 516 context.env.Append(LEADING_UNDERSCORE=ret) 517 context.Result(ret) 518 return ret 519 520# Platform-specific configuration. Note again that we assume that all 521# builds under a given build root run on the same host platform. 522conf = Configure(main, 523 conf_dir = joinpath(build_root, '.scons_config'), 524 log_file = joinpath(build_root, 'scons_config.log'), 525 custom_tests = { 'CheckLeading' : CheckLeading }) 526 527# Check for leading underscores. Don't really need to worry either 528# way so don't need to check the return code. 529conf.CheckLeading() 530 531# Check if we should compile a 64 bit binary on Mac OS X/Darwin 532try: 533 import platform 534 uname = platform.uname() 535 if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 536 if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 537 main.Append(CCFLAGS=['-arch', 'x86_64']) 538 main.Append(CFLAGS=['-arch', 'x86_64']) 539 main.Append(LINKFLAGS=['-arch', 'x86_64']) 540 main.Append(ASFLAGS=['-arch', 'x86_64']) 541except: 542 pass 543 544# Recent versions of scons substitute a "Null" object for Configure() 545# when configuration isn't necessary, e.g., if the "--help" option is 546# present. Unfortuantely this Null object always returns false, 547# breaking all our configuration checks. We replace it with our own 548# more optimistic null object that returns True instead. 549if not conf: 550 def NullCheck(*args, **kwargs): 551 return True 552 553 class NullConf: 554 def __init__(self, env): 555 self.env = env 556 def Finish(self): 557 return self.env 558 def __getattr__(self, mname): 559 return NullCheck 560 561 conf = NullConf(main) 562 563# Find Python include and library directories for embedding the 564# interpreter. For consistency, we will use the same Python 565# installation used to run scons (and thus this script). If you want 566# to link in an alternate version, see above for instructions on how 567# to invoke scons with a different copy of the Python interpreter. 568from distutils import sysconfig 569 570py_getvar = sysconfig.get_config_var 571 572py_debug = getattr(sys, 'pydebug', False) 573py_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 574 575py_general_include = sysconfig.get_python_inc() 576py_platform_include = sysconfig.get_python_inc(plat_specific=True) 577py_includes = [ py_general_include ] 578if py_platform_include != py_general_include: 579 py_includes.append(py_platform_include) 580 581py_lib_path = [ py_getvar('LIBDIR') ] 582# add the prefix/lib/pythonX.Y/config dir, but only if there is no 583# shared library in prefix/lib/. 584if not py_getvar('Py_ENABLE_SHARED'): 585 py_lib_path.append(py_getvar('LIBPL')) 586 587py_libs = [] 588for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 589 assert lib.startswith('-l') 590 lib = lib[2:] 591 if lib not in py_libs: 592 py_libs.append(lib) 593py_libs.append(py_version) 594 595main.Append(CPPPATH=py_includes) 596main.Append(LIBPATH=py_lib_path) 597 598# Cache build files in the supplied directory. 599if main['M5_BUILD_CACHE']: 600 print 'Using build cache located at', main['M5_BUILD_CACHE'] 601 CacheDir(main['M5_BUILD_CACHE']) 602 603 604# verify that this stuff works 605if not conf.CheckHeader('Python.h', '<>'): 606 print "Error: can't find Python.h header in", py_includes 607 Exit(1) 608 609for lib in py_libs: 610 if not conf.CheckLib(lib): 611 print "Error: can't find library %s required by python" % lib 612 Exit(1) 613 614# On Solaris you need to use libsocket for socket ops 615if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 616 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 617 print "Can't find library with socket calls (e.g. accept())" 618 Exit(1) 619 620# Check for zlib. If the check passes, libz will be automatically 621# added to the LIBS environment variable. 622if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 623 print 'Error: did not find needed zlib compression library '\ 624 'and/or zlib.h header file.' 625 print ' Please install zlib and try again.' 626 Exit(1) 627 628# Check for <fenv.h> (C99 FP environment control) 629have_fenv = conf.CheckHeader('fenv.h', '<>') 630if not have_fenv: 631 print "Warning: Header file <fenv.h> not found." 632 print " This host has no IEEE FP rounding mode control." 633 634###################################################################### 635# 636# Check for mysql. 637# 638mysql_config = WhereIs('mysql_config') 639have_mysql = bool(mysql_config) 640 641# Check MySQL version. 642if have_mysql: 643 mysql_version = readCommand(mysql_config + ' --version') 644 min_mysql_version = '4.1' 645 if compareVersions(mysql_version, min_mysql_version) < 0: 646 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 647 print ' Version', mysql_version, 'detected.' 648 have_mysql = False 649 650# Set up mysql_config commands. 651if have_mysql: 652 mysql_config_include = mysql_config + ' --include' 653 if os.system(mysql_config_include + ' > /dev/null') != 0: 654 # older mysql_config versions don't support --include, use 655 # --cflags instead 656 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 657 # This seems to work in all versions 658 mysql_config_libs = mysql_config + ' --libs' 659 660###################################################################### 661# 662# Finish the configuration 663# 664main = conf.Finish() 665 666###################################################################### 667# 668# Collect all non-global variables 669# 670 671# Define the universe of supported ISAs 672all_isa_list = [ ] 673Export('all_isa_list') 674 675class CpuModel(object): 676 '''The CpuModel class encapsulates everything the ISA parser needs to 677 know about a particular CPU model.''' 678 679 # Dict of available CPU model objects. Accessible as CpuModel.dict. 680 dict = {} 681 list = [] 682 defaults = [] 683 684 # Constructor. Automatically adds models to CpuModel.dict. 685 def __init__(self, name, filename, includes, strings, default=False): 686 self.name = name # name of model 687 self.filename = filename # filename for output exec code 688 self.includes = includes # include files needed in exec file 689 # The 'strings' dict holds all the per-CPU symbols we can 690 # substitute into templates etc. 691 self.strings = strings 692 693 # This cpu is enabled by default 694 self.default = default 695 696 # Add self to dict 697 if name in CpuModel.dict: 698 raise AttributeError, "CpuModel '%s' already registered" % name 699 CpuModel.dict[name] = self 700 CpuModel.list.append(name) 701 702Export('CpuModel') 703 704# Sticky variables get saved in the variables file so they persist from 705# one invocation to the next (unless overridden, in which case the new 706# value becomes sticky). 707sticky_vars = Variables(args=ARGUMENTS) 708Export('sticky_vars') 709 710# Sticky variables that should be exported 711export_vars = [] 712Export('export_vars') 713 714# Walk the tree and execute all SConsopts scripts that wil add to the 715# above variables 716for bdir in [ base_dir ] + extras_dir_list: 717 for root, dirs, files in os.walk(bdir): 718 if 'SConsopts' in files: 719 print "Reading", joinpath(root, 'SConsopts') 720 SConscript(joinpath(root, 'SConsopts')) 721 722all_isa_list.sort() 723 724sticky_vars.AddVariables( 725 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 726 BoolVariable('FULL_SYSTEM', 'Full-system support', False), 727 ListVariable('CPU_MODELS', 'CPU models', 728 sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 729 sorted(CpuModel.list)), 730 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 731 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 732 False), 733 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 734 False), 735 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 736 False), 737 BoolVariable('SS_COMPATIBLE_FP', 738 'Make floating-point results compatible with SimpleScalar', 739 False), 740 BoolVariable('USE_SSE2', 741 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 742 False), 743 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 744 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 745 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 746 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 747 BoolVariable('RUBY', 'Build with Ruby', False), 748 ) 749 750# These variables get exported to #defines in config/*.hh (see src/SConscript). 751export_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 752 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 753 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 754 755################################################### 756# 757# Define a SCons builder for configuration flag headers. 758# 759################################################### 760 761# This function generates a config header file that #defines the 762# variable symbol to the current variable setting (0 or 1). The source 763# operands are the name of the variable and a Value node containing the 764# value of the variable. 765def build_config_file(target, source, env): 766 (variable, value) = [s.get_contents() for s in source] 767 f = file(str(target[0]), 'w') 768 print >> f, '#define', variable, value 769 f.close() 770 return None 771 772# Generate the message to be printed when building the config file. 773def build_config_file_string(target, source, env): 774 (variable, value) = [s.get_contents() for s in source] 775 return "Defining %s as %s in %s." % (variable, value, target[0]) 776 777# Combine the two functions into a scons Action object. 778config_action = Action(build_config_file, build_config_file_string) 779 780# The emitter munges the source & target node lists to reflect what 781# we're really doing. 782def config_emitter(target, source, env): 783 # extract variable name from Builder arg 784 variable = str(target[0]) 785 # True target is config header file 786 target = joinpath('config', variable.lower() + '.hh') 787 val = env[variable] 788 if isinstance(val, bool): 789 # Force value to 0/1 790 val = int(val) 791 elif isinstance(val, str): 792 val = '"' + val + '"' 793 794 # Sources are variable name & value (packaged in SCons Value nodes) 795 return ([target], [Value(variable), Value(val)]) 796 797config_builder = Builder(emitter = config_emitter, action = config_action) 798 799main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 800 801# libelf build is shared across all configs in the build root. 802main.SConscript('ext/libelf/SConscript', 803 variant_dir = joinpath(build_root, 'libelf')) 804 805# gzstream build is shared across all configs in the build root. 806main.SConscript('ext/gzstream/SConscript', 807 variant_dir = joinpath(build_root, 'gzstream')) 808 809################################################### 810# 811# This function is used to set up a directory with switching headers 812# 813################################################### 814 815main['ALL_ISA_LIST'] = all_isa_list 816def make_switching_dir(dname, switch_headers, env): 817 # Generate the header. target[0] is the full path of the output 818 # header to generate. 'source' is a dummy variable, since we get the 819 # list of ISAs from env['ALL_ISA_LIST']. 820 def gen_switch_hdr(target, source, env): 821 fname = str(target[0]) 822 f = open(fname, 'w') 823 isa = env['TARGET_ISA'].lower() 824 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 825 f.close() 826 827 # Build SCons Action object. 'varlist' specifies env vars that this 828 # action depends on; when env['ALL_ISA_LIST'] changes these actions 829 # should get re-executed. 830 switch_hdr_action = MakeAction(gen_switch_hdr, 831 " [GENERATE] $STRIP_TARGET", varlist=['ALL_ISA_LIST']) 832 833 # Instantiate actions for each header 834 for hdr in switch_headers: 835 env.Command(hdr, [], switch_hdr_action) 836Export('make_switching_dir') 837 838################################################### 839# 840# Define build environments for selected configurations. 841# 842################################################### 843 844for variant_path in variant_paths: 845 print "Building in", variant_path 846 847 # Make a copy of the build-root environment to use for this config. 848 env = main.Clone() 849 env['BUILDDIR'] = variant_path 850 851 # variant_dir is the tail component of build path, and is used to 852 # determine the build parameters (e.g., 'ALPHA_SE') 853 (build_root, variant_dir) = splitpath(variant_path) 854 855 # Set env variables according to the build directory config. 856 sticky_vars.files = [] 857 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 858 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 859 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 860 current_vars_file = joinpath(build_root, 'variables', variant_dir) 861 if isfile(current_vars_file): 862 sticky_vars.files.append(current_vars_file) 863 print "Using saved variables file %s" % current_vars_file 864 else: 865 # Build dir-specific variables file doesn't exist. 866 867 # Make sure the directory is there so we can create it later 868 opt_dir = dirname(current_vars_file) 869 if not isdir(opt_dir): 870 mkdir(opt_dir) 871 872 # Get default build variables from source tree. Variables are 873 # normally determined by name of $VARIANT_DIR, but can be 874 # overriden by 'default=' arg on command line. 875 default_vars_file = joinpath('build_opts', 876 ARGUMENTS.get('default', variant_dir)) 877 if isfile(default_vars_file): 878 sticky_vars.files.append(default_vars_file) 879 print "Variables file %s not found,\n using defaults in %s" \ 880 % (current_vars_file, default_vars_file) 881 else: 882 print "Error: cannot find variables file %s or %s" \ 883 % (current_vars_file, default_vars_file) 884 Exit(1) 885 886 # Apply current variable settings to env 887 sticky_vars.Update(env) 888 889 help_text += "\nSticky variables for %s:\n" % variant_dir \ 890 + sticky_vars.GenerateHelpText(env) 891 892 # Process variable settings. 893 894 if not have_fenv and env['USE_FENV']: 895 print "Warning: <fenv.h> not available; " \ 896 "forcing USE_FENV to False in", variant_dir + "." 897 env['USE_FENV'] = False 898 899 if not env['USE_FENV']: 900 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 901 print " FP results may deviate slightly from other platforms." 902 903 if env['EFENCE']: 904 env.Append(LIBS=['efence']) 905 906 if env['USE_MYSQL']: 907 if not have_mysql: 908 print "Warning: MySQL not available; " \ 909 "forcing USE_MYSQL to False in", variant_dir + "." 910 env['USE_MYSQL'] = False 911 else: 912 print "Compiling in", variant_dir, "with MySQL support." 913 env.ParseConfig(mysql_config_libs) 914 env.ParseConfig(mysql_config_include) 915 916 # Save sticky variable settings back to current variables file 917 sticky_vars.Save(current_vars_file, env) 918 919 if env['USE_SSE2']: 920 env.Append(CCFLAGS=['-msse2']) 921 922 # The src/SConscript file sets up the build rules in 'env' according 923 # to the configured variables. It returns a list of environments, 924 # one for each variant build (debug, opt, etc.) 925 envList = SConscript('src/SConscript', variant_dir = variant_path, 926 exports = 'env') 927 928 # Set up the regression tests for each build. 929 for e in envList: 930 SConscript('tests/SConscript', 931 variant_dir = joinpath(variant_path, 'tests', e.Label), 932 exports = { 'env' : e }, duplicate = False) 933 934Help(help_text) 935