SConstruct revision 7865
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2011 Advanced Micro Devices, Inc. 4955SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 5955SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 6955SN/A# All rights reserved. 7955SN/A# 8955SN/A# Redistribution and use in source and binary forms, with or without 9955SN/A# modification, are permitted provided that the following conditions are 10955SN/A# met: redistributions of source code must retain the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer; 12955SN/A# redistributions in binary form must reproduce the above copyright 13955SN/A# notice, this list of conditions and the following disclaimer in the 14955SN/A# documentation and/or other materials provided with the distribution; 15955SN/A# neither the name of the copyright holders nor the names of its 16955SN/A# contributors may be used to endorse or promote products derived from 17955SN/A# this software without specific prior written permission. 18955SN/A# 19955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 282665Ssaidi@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 292665Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30955SN/A# 31955SN/A# Authors: Steve Reinhardt 32955SN/A# Nathan Binkert 33955SN/A 34955SN/A################################################### 352632Sstever@eecs.umich.edu# 362632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 372632Sstever@eecs.umich.edu# 382632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 39955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 402632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 412632Sstever@eecs.umich.edu# the optimized full-system version). 422761Sstever@eecs.umich.edu# 432632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 442632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 452632Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 462761Sstever@eecs.umich.edu# built for the same host system. 472761Sstever@eecs.umich.edu# 482761Sstever@eecs.umich.edu# Examples: 492632Sstever@eecs.umich.edu# 502632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 512761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 522761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 532761Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 542761Sstever@eecs.umich.edu# 552761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 562632Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 572632Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 582632Sstever@eecs.umich.edu# file. 592632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 602632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 612632Sstever@eecs.umich.edu# 622632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 63955SN/A# 'm5' directory (or use -u or -C to tell scons where to find this 64955SN/A# file), you can use 'scons -h' to print all the M5-specific build 65955SN/A# options as well. 66955SN/A# 67955SN/A################################################### 684202Sbinkertn@umich.edu 695342Sstever@gmail.com# Check for recent-enough Python and SCons versions. 70955SN/Atry: 715273Sstever@gmail.com # Really old versions of scons only take two options for the 725273Sstever@gmail.com # function, so check once without the revision and once with the 732656Sstever@eecs.umich.edu # revision, the first instance will fail for stuff other than 742656Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 752656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 762656Sstever@eecs.umich.edu EnsureSConsVersion(0, 98, 1) 772656Sstever@eecs.umich.eduexcept SystemExit, e: 782656Sstever@eecs.umich.edu print """ 792656Sstever@eecs.umich.eduFor more details, see: 802653Sstever@eecs.umich.edu http://m5sim.org/wiki/index.php/Compiling_M5 815227Ssaidi@eecs.umich.edu""" 825227Ssaidi@eecs.umich.edu raise 835227Ssaidi@eecs.umich.edu 845227Ssaidi@eecs.umich.edu# We ensure the python version early because we have stuff that 852653Sstever@eecs.umich.edu# requires python 2.4 862653Sstever@eecs.umich.edutry: 872653Sstever@eecs.umich.edu EnsurePythonVersion(2, 4) 882653Sstever@eecs.umich.eduexcept SystemExit, e: 892653Sstever@eecs.umich.edu print """ 902653Sstever@eecs.umich.eduYou can use a non-default installation of the Python interpreter by 912653Sstever@eecs.umich.edueither (1) rearranging your PATH so that scons finds the non-default 922653Sstever@eecs.umich.edu'python' first or (2) explicitly invoking an alternative interpreter 932653Sstever@eecs.umich.eduon the scons script. 944781Snate@binkert.org 951852SN/AFor more details, see: 96955SN/A http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 97955SN/A""" 98955SN/A raise 993717Sstever@eecs.umich.edu 1003716Sstever@eecs.umich.edu# Global Python includes 101955SN/Aimport os 1021533SN/Aimport re 1033716Sstever@eecs.umich.eduimport subprocess 1041533SN/Aimport sys 1054678Snate@binkert.org 1064678Snate@binkert.orgfrom os import mkdir, environ 1074678Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1084678Snate@binkert.orgfrom os.path import exists, isdir, isfile 1094678Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1104678Snate@binkert.org 1114678Snate@binkert.org# SCons includes 1124678Snate@binkert.orgimport SCons 1134678Snate@binkert.orgimport SCons.Node 1144678Snate@binkert.org 1154678Snate@binkert.orgextra_python_paths = [ 1164678Snate@binkert.org Dir('src/python').srcnode().abspath, # M5 includes 1174678Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1184678Snate@binkert.org ] 1194678Snate@binkert.org 1204678Snate@binkert.orgsys.path[1:1] = extra_python_paths 1214678Snate@binkert.org 1224678Snate@binkert.orgfrom m5.util import compareVersions, readCommand 1234678Snate@binkert.org 1244678Snate@binkert.orgAddOption('--colors', dest='use_colors', action='store_true') 1254678Snate@binkert.orgAddOption('--no-colors', dest='use_colors', action='store_false') 1264973Ssaidi@eecs.umich.eduuse_colors = GetOption('use_colors') 1274678Snate@binkert.org 1284678Snate@binkert.orgif use_colors: 1294678Snate@binkert.org from m5.util.terminal import termcap 1304678Snate@binkert.orgelif use_colors is None: 1314678Snate@binkert.org # option unspecified; default behavior is to use colors iff isatty 1324678Snate@binkert.org from m5.util.terminal import tty_termcap as termcap 133955SN/Aelse: 134955SN/A from m5.util.terminal import no_termcap as termcap 1352632Sstever@eecs.umich.edu 1362632Sstever@eecs.umich.edu######################################################################## 137955SN/A# 138955SN/A# Set up the main build environment. 139955SN/A# 140955SN/A######################################################################## 1412632Sstever@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 142955SN/A 'PYTHONPATH', 'RANLIB' ]) 1432632Sstever@eecs.umich.edu 1442632Sstever@eecs.umich.eduuse_env = {} 1452632Sstever@eecs.umich.edufor key,val in os.environ.iteritems(): 1462632Sstever@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1472632Sstever@eecs.umich.edu use_env[key] = val 1482632Sstever@eecs.umich.edu 1492632Sstever@eecs.umich.edumain = Environment(ENV=use_env) 1503053Sstever@eecs.umich.edumain.root = Dir(".") # The current directory (where this file lives). 1513053Sstever@eecs.umich.edumain.srcdir = Dir("src") # The source directory 1523053Sstever@eecs.umich.edu 1533053Sstever@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 1543053Sstever@eecs.umich.edu# as well 1553053Sstever@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths) 1563053Sstever@eecs.umich.edu 1573053Sstever@eecs.umich.edu######################################################################## 1583053Sstever@eecs.umich.edu# 1593053Sstever@eecs.umich.edu# Mercurial Stuff. 1603053Sstever@eecs.umich.edu# 1613053Sstever@eecs.umich.edu# If the M5 directory is a mercurial repository, we should do some 1623053Sstever@eecs.umich.edu# extra things. 1633053Sstever@eecs.umich.edu# 1643053Sstever@eecs.umich.edu######################################################################## 1653053Sstever@eecs.umich.edu 1662632Sstever@eecs.umich.eduhgdir = main.root.Dir(".hg") 1672632Sstever@eecs.umich.edu 1682632Sstever@eecs.umich.edumercurial_style_message = """ 1692632Sstever@eecs.umich.eduYou're missing the M5 style hook. 1702632Sstever@eecs.umich.eduPlease install the hook so we can ensure that all code fits a common style. 1712632Sstever@eecs.umich.edu 1723718Sstever@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc 1733718Sstever@eecs.umich.eduor your personal .hgrc 1743718Sstever@eecs.umich.edu---------------- 1753718Sstever@eecs.umich.edu 1763718Sstever@eecs.umich.edu[extensions] 1773718Sstever@eecs.umich.edustyle = %s/util/style.py 1783718Sstever@eecs.umich.edu 1793718Sstever@eecs.umich.edu[hooks] 1803718Sstever@eecs.umich.edupretxncommit.style = python:style.check_style 1813718Sstever@eecs.umich.edupre-qrefresh.style = python:style.check_style 1823718Sstever@eecs.umich.edu""" % (main.root) 1833718Sstever@eecs.umich.edu 1843718Sstever@eecs.umich.edumercurial_bin_not_found = """ 1852634Sstever@eecs.umich.eduMercurial binary cannot be found, unfortunately this means that we 1862634Sstever@eecs.umich.educannot easily determine the version of M5 that you are running and 1872632Sstever@eecs.umich.eduthis makes error messages more difficult to collect. Please consider 1882638Sstever@eecs.umich.eduinstalling mercurial if you choose to post an error message 1892632Sstever@eecs.umich.edu""" 1902632Sstever@eecs.umich.edu 1912632Sstever@eecs.umich.edumercurial_lib_not_found = """ 1922632Sstever@eecs.umich.eduMercurial libraries cannot be found, ignoring style hook 1932632Sstever@eecs.umich.eduIf you are actually a M5 developer, please fix this and 1942632Sstever@eecs.umich.edurun the style hook. It is important. 1951858SN/A""" 1963716Sstever@eecs.umich.edu 1972638Sstever@eecs.umich.eduhg_info = "Unknown" 1982638Sstever@eecs.umich.eduif hgdir.exists(): 1992638Sstever@eecs.umich.edu # 1) Grab repository revision if we know it. 2002638Sstever@eecs.umich.edu cmd = "hg id -n -i -t -b" 2012638Sstever@eecs.umich.edu try: 2022638Sstever@eecs.umich.edu hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 2032638Sstever@eecs.umich.edu except OSError: 2043716Sstever@eecs.umich.edu print mercurial_bin_not_found 2052634Sstever@eecs.umich.edu 2062634Sstever@eecs.umich.edu # 2) Ensure that the style hook is in place. 207955SN/A try: 2085341Sstever@gmail.com ui = None 2095341Sstever@gmail.com if ARGUMENTS.get('IGNORE_STYLE') != 'True': 2105341Sstever@gmail.com from mercurial import ui 2115341Sstever@gmail.com ui = ui.ui() 212955SN/A except ImportError: 213955SN/A print mercurial_lib_not_found 214955SN/A 215955SN/A if ui is not None: 216955SN/A ui.readconfig(hgdir.File('hgrc').abspath) 217955SN/A style_hook = ui.config('hooks', 'pretxncommit.style', None) 218955SN/A 2191858SN/A if not style_hook: 2201858SN/A print mercurial_style_message 2212632Sstever@eecs.umich.edu sys.exit(1) 222955SN/Aelse: 2234494Ssaidi@eecs.umich.edu print ".hg directory not found" 2244494Ssaidi@eecs.umich.edu 2253716Sstever@eecs.umich.edumain['HG_INFO'] = hg_info 2261105SN/A 2272667Sstever@eecs.umich.edu################################################### 2282667Sstever@eecs.umich.edu# 2292667Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2302667Sstever@eecs.umich.edu# the target(s). 2312667Sstever@eecs.umich.edu# 2322667Sstever@eecs.umich.edu################################################### 2331869SN/A 2341869SN/A# Find default configuration & binary. 2351869SN/ADefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2361869SN/A 2371869SN/A# helper function: find last occurrence of element in list 2381065SN/Adef rfind(l, elt, offs = -1): 2395341Sstever@gmail.com for i in range(len(l)+offs, 0, -1): 2405341Sstever@gmail.com if l[i] == elt: 2415341Sstever@gmail.com return i 2425341Sstever@gmail.com raise ValueError, "element not found" 2435341Sstever@gmail.com 2445341Sstever@gmail.com# Each target must have 'build' in the interior of the path; the 2455341Sstever@gmail.com# directory below this will determine the build parameters. For 2465341Sstever@gmail.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2475341Sstever@gmail.com# recognize that ALPHA_SE specifies the configuration because it 2485341Sstever@gmail.com# follow 'build' in the bulid path. 2495341Sstever@gmail.com 2505341Sstever@gmail.com# Generate absolute paths to targets so we can see where the build dir is 2515341Sstever@gmail.comif COMMAND_LINE_TARGETS: 2525341Sstever@gmail.com # Ask SCons which directory it was invoked from 2535341Sstever@gmail.com launch_dir = GetLaunchDir() 2545341Sstever@gmail.com # Make targets relative to invocation directory 2555341Sstever@gmail.com abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2565341Sstever@gmail.com COMMAND_LINE_TARGETS] 2575341Sstever@gmail.comelse: 2585341Sstever@gmail.com # Default targets are relative to root of tree 2595341Sstever@gmail.com abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2605341Sstever@gmail.com DEFAULT_TARGETS] 2615341Sstever@gmail.com 2625341Sstever@gmail.com 2635341Sstever@gmail.com# Generate a list of the unique build roots and configs that the 2645341Sstever@gmail.com# collected targets reference. 2655341Sstever@gmail.comvariant_paths = [] 2665341Sstever@gmail.combuild_root = None 2675341Sstever@gmail.comfor t in abs_targets: 2685341Sstever@gmail.com path_dirs = t.split('/') 2695341Sstever@gmail.com try: 2705341Sstever@gmail.com build_top = rfind(path_dirs, 'build', -2) 2715341Sstever@gmail.com except: 2725341Sstever@gmail.com print "Error: no non-leaf 'build' dir found on target path", t 2735341Sstever@gmail.com Exit(1) 2745341Sstever@gmail.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2755341Sstever@gmail.com if not build_root: 2765341Sstever@gmail.com build_root = this_build_root 2775341Sstever@gmail.com else: 2785341Sstever@gmail.com if this_build_root != build_root: 2795341Sstever@gmail.com print "Error: build targets not under same build root\n"\ 2805341Sstever@gmail.com " %s\n %s" % (build_root, this_build_root) 2815341Sstever@gmail.com Exit(1) 2825341Sstever@gmail.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 2835341Sstever@gmail.com if variant_path not in variant_paths: 2845341Sstever@gmail.com variant_paths.append(variant_path) 2855341Sstever@gmail.com 2865341Sstever@gmail.com# Make sure build_root exists (might not if this is the first build there) 2875341Sstever@gmail.comif not isdir(build_root): 2885341Sstever@gmail.com mkdir(build_root) 2895341Sstever@gmail.commain['BUILDROOT'] = build_root 2905341Sstever@gmail.com 2915341Sstever@gmail.comExport('main') 2925341Sstever@gmail.com 2935341Sstever@gmail.commain.SConsignFile(joinpath(build_root, "sconsign")) 2942632Sstever@eecs.umich.edu 2955199Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up 2963918Ssaidi@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 2973918Ssaidi@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2983940Ssaidi@eecs.umich.edu# (soft) links work better. 2994781Snate@binkert.orgmain.SetOption('duplicate', 'soft-copy') 3004781Snate@binkert.org 3013918Ssaidi@eecs.umich.edu# 3024781Snate@binkert.org# Set up global sticky variables... these are common to an entire build 3034781Snate@binkert.org# tree (not specific to a particular build like ALPHA_SE) 3043918Ssaidi@eecs.umich.edu# 3054781Snate@binkert.org 3064781Snate@binkert.org# Variable validators & converters for global sticky variables 3073940Ssaidi@eecs.umich.edudef PathListMakeAbsolute(val): 3083942Ssaidi@eecs.umich.edu if not val: 3093940Ssaidi@eecs.umich.edu return val 3103918Ssaidi@eecs.umich.edu f = lambda p: abspath(expanduser(p)) 3113918Ssaidi@eecs.umich.edu return ':'.join(map(f, val.split(':'))) 312955SN/A 3131858SN/Adef PathListAllExist(key, val, env): 3143918Ssaidi@eecs.umich.edu if not val: 3153918Ssaidi@eecs.umich.edu return 3163918Ssaidi@eecs.umich.edu paths = val.split(':') 3173918Ssaidi@eecs.umich.edu for path in paths: 3183940Ssaidi@eecs.umich.edu if not isdir(path): 3193940Ssaidi@eecs.umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3203918Ssaidi@eecs.umich.edu 3213918Ssaidi@eecs.umich.eduglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3223918Ssaidi@eecs.umich.edu 3233918Ssaidi@eecs.umich.eduglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3243918Ssaidi@eecs.umich.eduglobal_nonsticky_vars = Variables(args=ARGUMENTS) 3253918Ssaidi@eecs.umich.edu 3263918Ssaidi@eecs.umich.eduglobal_sticky_vars.AddVariables( 3273918Ssaidi@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3283918Ssaidi@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3293940Ssaidi@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3303918Ssaidi@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3313918Ssaidi@eecs.umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3321851SN/A ('EXTRAS', 'Add Extra directories to the compilation', '', 3331851SN/A PathListAllExist, PathListMakeAbsolute), 3341858SN/A ) 3355200Sstever@gmail.com 336955SN/Aglobal_nonsticky_vars.AddVariables( 3373053Sstever@eecs.umich.edu ('VERBOSE', 'Print full tool command lines', False), 3383053Sstever@eecs.umich.edu ('update_ref', 'Update test reference outputs', False) 3393053Sstever@eecs.umich.edu ) 3403053Sstever@eecs.umich.edu 3413053Sstever@eecs.umich.edu 3423053Sstever@eecs.umich.edu# base help text 3433053Sstever@eecs.umich.eduhelp_text = ''' 3443053Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 3453053Sstever@eecs.umich.edu 3464742Sstever@eecs.umich.eduGlobal sticky options: 3474742Sstever@eecs.umich.edu''' 3483053Sstever@eecs.umich.edu 3493053Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3503053Sstever@eecs.umich.eduglobal_sticky_vars.Update(main) 3513053Sstever@eecs.umich.eduglobal_nonsticky_vars.Update(main) 3523053Sstever@eecs.umich.edu 3533053Sstever@eecs.umich.eduhelp_text += global_sticky_vars.GenerateHelpText(main) 3543053Sstever@eecs.umich.eduhelp_text += global_nonsticky_vars.GenerateHelpText(main) 3553053Sstever@eecs.umich.edu 3563053Sstever@eecs.umich.edu# Save sticky variable settings back to current variables file 3572667Sstever@eecs.umich.eduglobal_sticky_vars.Save(global_sticky_vars_file, main) 3584554Sbinkertn@umich.edu 3594554Sbinkertn@umich.edu# Parse EXTRAS variable to build list of all directories where we're 3602667Sstever@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3614554Sbinkertn@umich.edubase_dir = main.srcdir.abspath 3624554Sbinkertn@umich.eduif main['EXTRAS']: 3634554Sbinkertn@umich.edu extras_dir_list = main['EXTRAS'].split(':') 3644554Sbinkertn@umich.eduelse: 3654554Sbinkertn@umich.edu extras_dir_list = [] 3664554Sbinkertn@umich.edu 3674554Sbinkertn@umich.eduExport('base_dir') 3684781Snate@binkert.orgExport('extras_dir_list') 3694554Sbinkertn@umich.edu 3704554Sbinkertn@umich.edu# the ext directory should be on the #includes path 3712667Sstever@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3724554Sbinkertn@umich.edu 3734554Sbinkertn@umich.edudef strip_build_path(path, env): 3744554Sbinkertn@umich.edu path = str(path) 3754554Sbinkertn@umich.edu variant_base = env['BUILDROOT'] + os.path.sep 3762667Sstever@eecs.umich.edu if path.startswith(variant_base): 3774554Sbinkertn@umich.edu path = path[len(variant_base):] 3782667Sstever@eecs.umich.edu elif path.startswith('build/'): 3794554Sbinkertn@umich.edu path = path[6:] 3804554Sbinkertn@umich.edu return path 3812667Sstever@eecs.umich.edu 3822638Sstever@eecs.umich.edu# Generate a string of the form: 3832638Sstever@eecs.umich.edu# common/path/prefix/src1, src2 -> tgt1, tgt2 3842638Sstever@eecs.umich.edu# to print while building. 3853716Sstever@eecs.umich.educlass Transform(object): 3863716Sstever@eecs.umich.edu # all specific color settings should be here and nowhere else 3871858SN/A tool_color = termcap.Normal 3885227Ssaidi@eecs.umich.edu pfx_color = termcap.Yellow 3895227Ssaidi@eecs.umich.edu srcs_color = termcap.Yellow + termcap.Bold 3905227Ssaidi@eecs.umich.edu arrow_color = termcap.Blue + termcap.Bold 3915227Ssaidi@eecs.umich.edu tgts_color = termcap.Yellow + termcap.Bold 3925227Ssaidi@eecs.umich.edu 3935227Ssaidi@eecs.umich.edu def __init__(self, tool, max_sources=99): 3945227Ssaidi@eecs.umich.edu self.format = self.tool_color + (" [%8s] " % tool) \ 3955227Ssaidi@eecs.umich.edu + self.pfx_color + "%s" \ 3965227Ssaidi@eecs.umich.edu + self.srcs_color + "%s" \ 3975227Ssaidi@eecs.umich.edu + self.arrow_color + " -> " \ 3985227Ssaidi@eecs.umich.edu + self.tgts_color + "%s" \ 3995227Ssaidi@eecs.umich.edu + termcap.Normal 4005274Ssaidi@eecs.umich.edu self.max_sources = max_sources 4015227Ssaidi@eecs.umich.edu 4025227Ssaidi@eecs.umich.edu def __call__(self, target, source, env, for_signature=None): 4035227Ssaidi@eecs.umich.edu # truncate source list according to max_sources param 4045204Sstever@gmail.com source = source[0:self.max_sources] 4055204Sstever@gmail.com def strip(f): 4065204Sstever@gmail.com return strip_build_path(str(f), env) 4075204Sstever@gmail.com if len(source) > 0: 4085204Sstever@gmail.com srcs = map(strip, source) 4095204Sstever@gmail.com else: 4105204Sstever@gmail.com srcs = [''] 4115204Sstever@gmail.com tgts = map(strip, target) 4125204Sstever@gmail.com # surprisingly, os.path.commonprefix is a dumb char-by-char string 4135204Sstever@gmail.com # operation that has nothing to do with paths. 4145204Sstever@gmail.com com_pfx = os.path.commonprefix(srcs + tgts) 4155204Sstever@gmail.com com_pfx_len = len(com_pfx) 4165204Sstever@gmail.com if com_pfx: 4175204Sstever@gmail.com # do some cleanup and sanity checking on common prefix 4185204Sstever@gmail.com if com_pfx[-1] == ".": 4195204Sstever@gmail.com # prefix matches all but file extension: ok 4205204Sstever@gmail.com # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4215204Sstever@gmail.com com_pfx = com_pfx[0:-1] 4225204Sstever@gmail.com elif com_pfx[-1] == "/": 4233118Sstever@eecs.umich.edu # common prefix is directory path: OK 4243118Sstever@eecs.umich.edu pass 4253118Sstever@eecs.umich.edu else: 4263118Sstever@eecs.umich.edu src0_len = len(srcs[0]) 4273118Sstever@eecs.umich.edu tgt0_len = len(tgts[0]) 4283118Sstever@eecs.umich.edu if src0_len == com_pfx_len: 4293118Sstever@eecs.umich.edu # source is a substring of target, OK 4303118Sstever@eecs.umich.edu pass 4313118Sstever@eecs.umich.edu elif tgt0_len == com_pfx_len: 4323118Sstever@eecs.umich.edu # target is a substring of source, need to back up to 4333118Sstever@eecs.umich.edu # avoid empty string on RHS of arrow 4343716Sstever@eecs.umich.edu sep_idx = com_pfx.rfind(".") 4353118Sstever@eecs.umich.edu if sep_idx != -1: 4363118Sstever@eecs.umich.edu com_pfx = com_pfx[0:sep_idx] 4373118Sstever@eecs.umich.edu else: 4383118Sstever@eecs.umich.edu com_pfx = '' 4393118Sstever@eecs.umich.edu elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4403118Sstever@eecs.umich.edu # still splitting at file extension: ok 4413118Sstever@eecs.umich.edu pass 4423118Sstever@eecs.umich.edu else: 4433118Sstever@eecs.umich.edu # probably a fluke; ignore it 4443716Sstever@eecs.umich.edu com_pfx = '' 4453118Sstever@eecs.umich.edu # recalculate length in case com_pfx was modified 4463118Sstever@eecs.umich.edu com_pfx_len = len(com_pfx) 4473118Sstever@eecs.umich.edu def fmt(files): 4483118Sstever@eecs.umich.edu f = map(lambda s: s[com_pfx_len:], files) 4493118Sstever@eecs.umich.edu return ', '.join(f) 4503118Sstever@eecs.umich.edu return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4513118Sstever@eecs.umich.edu 4523118Sstever@eecs.umich.eduExport('Transform') 4533118Sstever@eecs.umich.edu 4543118Sstever@eecs.umich.edu 4553483Ssaidi@eecs.umich.eduif main['VERBOSE']: 4563494Ssaidi@eecs.umich.edu def MakeAction(action, string, *args, **kwargs): 4573494Ssaidi@eecs.umich.edu return Action(action, *args, **kwargs) 4583483Ssaidi@eecs.umich.eduelse: 4593483Ssaidi@eecs.umich.edu MakeAction = Action 4603483Ssaidi@eecs.umich.edu main['CCCOMSTR'] = Transform("CC") 4613053Sstever@eecs.umich.edu main['CXXCOMSTR'] = Transform("CXX") 4623053Sstever@eecs.umich.edu main['ASCOMSTR'] = Transform("AS") 4633918Ssaidi@eecs.umich.edu main['SWIGCOMSTR'] = Transform("SWIG") 4643053Sstever@eecs.umich.edu main['ARCOMSTR'] = Transform("AR", 0) 4653053Sstever@eecs.umich.edu main['LINKCOMSTR'] = Transform("LINK", 0) 4663053Sstever@eecs.umich.edu main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4673053Sstever@eecs.umich.edu main['M4COMSTR'] = Transform("M4") 4683053Sstever@eecs.umich.edu main['SHCCCOMSTR'] = Transform("SHCC") 4691858SN/A main['SHCXXCOMSTR'] = Transform("SHCXX") 4701858SN/AExport('MakeAction') 4711858SN/A 4721858SN/ACXX_version = readCommand([main['CXX'],'--version'], exception=False) 4731858SN/ACXX_V = readCommand([main['CXX'],'-V'], exception=False) 4741858SN/A 4751859SN/Amain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4761858SN/Amain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4771858SN/Amain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4781858SN/Aif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 4791859SN/A print 'Error: How can we have two at the same time?' 4801859SN/A Exit(1) 4811862SN/A 4823053Sstever@eecs.umich.edu# Set up default C++ compiler flags 4833053Sstever@eecs.umich.eduif main['GCC']: 4843053Sstever@eecs.umich.edu main.Append(CCFLAGS=['-pipe']) 4853053Sstever@eecs.umich.edu main.Append(CCFLAGS=['-fno-strict-aliasing']) 4861859SN/A main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 4871859SN/A main.Append(CXXFLAGS=['-Wno-deprecated']) 4881859SN/A # Read the GCC version to check for versions with bugs 4891859SN/A # Note CCVERSION doesn't work here because it is run with the CC 4901859SN/A # before we override it from the command line 4911859SN/A gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4921859SN/A if not compareVersions(gcc_version, '4.4.1') or \ 4931859SN/A not compareVersions(gcc_version, '4.4.2'): 4941862SN/A print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 4951859SN/A main.Append(CCFLAGS=['-fno-tree-vectorize']) 4961859SN/Aelif main['ICC']: 4971859SN/A pass #Fix me... add warning flags once we clean up icc warnings 4981858SN/Aelif main['SUNCC']: 4991858SN/A main.Append(CCFLAGS=['-Qoption ccfe']) 5002139SN/A main.Append(CCFLAGS=['-features=gcc']) 5014202Sbinkertn@umich.edu main.Append(CCFLAGS=['-features=extensions']) 5024202Sbinkertn@umich.edu main.Append(CCFLAGS=['-library=stlport4']) 5032139SN/A main.Append(CCFLAGS=['-xar']) 5042155SN/A #main.Append(CCFLAGS=['-instances=semiexplicit']) 5054202Sbinkertn@umich.eduelse: 5064202Sbinkertn@umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 5074202Sbinkertn@umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 5082155SN/A Exit(1) 5091869SN/A 5101869SN/A# Set up common yacc/bison flags (needed for Ruby) 5111869SN/Amain['YACCFLAGS'] = '-d' 5121869SN/Amain['YACCHXXFILESUFFIX'] = '.hh' 5134202Sbinkertn@umich.edu 5144202Sbinkertn@umich.edu# Do this after we save setting back, or else we'll tack on an 5154202Sbinkertn@umich.edu# extra 'qdo' every time we run scons. 5164202Sbinkertn@umich.eduif main['BATCH']: 5174202Sbinkertn@umich.edu main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5184202Sbinkertn@umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5194202Sbinkertn@umich.edu main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5204202Sbinkertn@umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5215341Sstever@gmail.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5225341Sstever@gmail.com 5235341Sstever@gmail.comif sys.platform == 'cygwin': 5245342Sstever@gmail.com # cygwin has some header file issues... 5255342Sstever@gmail.com main.Append(CCFLAGS=["-Wno-uninitialized"]) 5264202Sbinkertn@umich.edu 5274202Sbinkertn@umich.edu# Check for SWIG 5284202Sbinkertn@umich.eduif not main.has_key('SWIG'): 5294202Sbinkertn@umich.edu print 'Error: SWIG utility not found.' 5304202Sbinkertn@umich.edu print ' Please install (see http://www.swig.org) and retry.' 5311869SN/A Exit(1) 5324202Sbinkertn@umich.edu 5331869SN/A# Check for appropriate SWIG version 5342508SN/Aswig_version = readCommand(('swig', '-version'), exception='').split() 5352508SN/A# First 3 words should be "SWIG Version x.y.z" 5362508SN/Aif len(swig_version) < 3 or \ 5372508SN/A swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5384202Sbinkertn@umich.edu print 'Error determining SWIG version.' 5391869SN/A Exit(1) 5401869SN/A 5411869SN/Amin_swig_version = '1.3.28' 5421869SN/Aif compareVersions(swig_version[2], min_swig_version) < 0: 5431869SN/A print 'Error: SWIG version', min_swig_version, 'or newer required.' 5441869SN/A print ' Installed version:', swig_version[2] 5451965SN/A Exit(1) 5461965SN/A 5471965SN/A# Set up SWIG flags & scanner 5481869SN/Aswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5491869SN/Amain.Append(SWIGFLAGS=swig_flags) 5502733Sktlim@umich.edu 5511884SN/A# filter out all existing swig scanners, they mess up the dependency 5523356Sbinkertn@umich.edu# stuff for some reason 5533356Sbinkertn@umich.eduscanners = [] 5543356Sbinkertn@umich.edufor scanner in main['SCANNERS']: 5554773Snate@binkert.org skeys = scanner.skeys 5561869SN/A if skeys == '.i': 5571858SN/A continue 5581869SN/A 5591869SN/A if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5601869SN/A continue 5611858SN/A 5622761Sstever@eecs.umich.edu scanners.append(scanner) 5631869SN/A 5642733Sktlim@umich.edu# add the new swig scanner that we like better 5653584Ssaidi@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 5661869SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 5671869SN/Ascanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 5681869SN/A 5691869SN/A# replace the scanners list that has what we want 5701869SN/Amain['SCANNERS'] = scanners 5711869SN/A 5721858SN/A# Add a custom Check function to the Configure context so that we can 573955SN/A# figure out if the compiler adds leading underscores to global 574955SN/A# variables. This is needed for the autogenerated asm files that we 5751869SN/A# use for embedding the python code. 5761869SN/Adef CheckLeading(context): 5771869SN/A context.Message("Checking for leading underscore in global variables...") 5781869SN/A # 1) Define a global variable called x from asm so the C compiler 5791869SN/A # won't change the symbol at all. 5801869SN/A # 2) Declare that variable. 5811869SN/A # 3) Use the variable 5821869SN/A # 5831869SN/A # If the compiler prepends an underscore, this will successfully 5841869SN/A # link because the external symbol 'x' will be called '_x' which 5851869SN/A # was defined by the asm statement. If the compiler does not 5861869SN/A # prepend an underscore, this will not successfully link because 5871869SN/A # '_x' will have been defined by assembly, while the C portion of 5881869SN/A # the code will be trying to use 'x' 5891869SN/A ret = context.TryLink(''' 5901869SN/A asm(".globl _x; _x: .byte 0"); 5911869SN/A extern int x; 5921869SN/A int main() { return x; } 5931869SN/A ''', extension=".c") 5941869SN/A context.env.Append(LEADING_UNDERSCORE=ret) 5951869SN/A context.Result(ret) 5961869SN/A return ret 5971869SN/A 5981869SN/A# Platform-specific configuration. Note again that we assume that all 5991869SN/A# builds under a given build root run on the same host platform. 6001869SN/Aconf = Configure(main, 6011869SN/A conf_dir = joinpath(build_root, '.scons_config'), 6021869SN/A log_file = joinpath(build_root, 'scons_config.log'), 6031869SN/A custom_tests = { 'CheckLeading' : CheckLeading }) 6043716Sstever@eecs.umich.edu 6053356Sbinkertn@umich.edu# Check for leading underscores. Don't really need to worry either 6063356Sbinkertn@umich.edu# way so don't need to check the return code. 6073356Sbinkertn@umich.educonf.CheckLeading() 6083356Sbinkertn@umich.edu 6093356Sbinkertn@umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6103356Sbinkertn@umich.edutry: 6114781Snate@binkert.org import platform 6121869SN/A uname = platform.uname() 6131869SN/A if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 6141869SN/A if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 6151869SN/A main.Append(CCFLAGS=['-arch', 'x86_64']) 6161869SN/A main.Append(CFLAGS=['-arch', 'x86_64']) 6171869SN/A main.Append(LINKFLAGS=['-arch', 'x86_64']) 6181869SN/A main.Append(ASFLAGS=['-arch', 'x86_64']) 6192655Sstever@eecs.umich.eduexcept: 6202655Sstever@eecs.umich.edu pass 6212655Sstever@eecs.umich.edu 6222655Sstever@eecs.umich.edu# Recent versions of scons substitute a "Null" object for Configure() 6232655Sstever@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 6242655Sstever@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 6252655Sstever@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 6262655Sstever@eecs.umich.edu# more optimistic null object that returns True instead. 6272655Sstever@eecs.umich.eduif not conf: 6282655Sstever@eecs.umich.edu def NullCheck(*args, **kwargs): 6292655Sstever@eecs.umich.edu return True 6302655Sstever@eecs.umich.edu 6312655Sstever@eecs.umich.edu class NullConf: 6322655Sstever@eecs.umich.edu def __init__(self, env): 6332655Sstever@eecs.umich.edu self.env = env 6342655Sstever@eecs.umich.edu def Finish(self): 6352655Sstever@eecs.umich.edu return self.env 6362655Sstever@eecs.umich.edu def __getattr__(self, mname): 6372655Sstever@eecs.umich.edu return NullCheck 6382655Sstever@eecs.umich.edu 6392655Sstever@eecs.umich.edu conf = NullConf(main) 6402655Sstever@eecs.umich.edu 6412655Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 6422655Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 6432655Sstever@eecs.umich.edu# installation used to run scons (and thus this script). If you want 6442655Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how 6452638Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 6462638Sstever@eecs.umich.edufrom distutils import sysconfig 6473716Sstever@eecs.umich.edu 6482638Sstever@eecs.umich.edupy_getvar = sysconfig.get_config_var 6492638Sstever@eecs.umich.edu 6501869SN/Apy_debug = getattr(sys, 'pydebug', False) 6511869SN/Apy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6523546Sgblack@eecs.umich.edu 6533546Sgblack@eecs.umich.edupy_general_include = sysconfig.get_python_inc() 6543546Sgblack@eecs.umich.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6553546Sgblack@eecs.umich.edupy_includes = [ py_general_include ] 6564202Sbinkertn@umich.eduif py_platform_include != py_general_include: 6573546Sgblack@eecs.umich.edu py_includes.append(py_platform_include) 6583546Sgblack@eecs.umich.edu 6593546Sgblack@eecs.umich.edupy_lib_path = [ py_getvar('LIBDIR') ] 6603546Sgblack@eecs.umich.edu# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6613546Sgblack@eecs.umich.edu# shared library in prefix/lib/. 6624781Snate@binkert.orgif not py_getvar('Py_ENABLE_SHARED'): 6634781Snate@binkert.org py_lib_path.append(py_getvar('LIBPL')) 6644781Snate@binkert.org 6654781Snate@binkert.orgpy_libs = [] 6664781Snate@binkert.orgfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 6674781Snate@binkert.org assert lib.startswith('-l') 6684781Snate@binkert.org lib = lib[2:] 6694781Snate@binkert.org if lib not in py_libs: 6704781Snate@binkert.org py_libs.append(lib) 6714781Snate@binkert.orgpy_libs.append(py_version) 6724781Snate@binkert.org 6734781Snate@binkert.orgmain.Append(CPPPATH=py_includes) 6743546Sgblack@eecs.umich.edumain.Append(LIBPATH=py_lib_path) 6753546Sgblack@eecs.umich.edu 6763546Sgblack@eecs.umich.edu# Cache build files in the supplied directory. 6774781Snate@binkert.orgif main['M5_BUILD_CACHE']: 6783546Sgblack@eecs.umich.edu print 'Using build cache located at', main['M5_BUILD_CACHE'] 6793546Sgblack@eecs.umich.edu CacheDir(main['M5_BUILD_CACHE']) 6803546Sgblack@eecs.umich.edu 6813546Sgblack@eecs.umich.edu 6823546Sgblack@eecs.umich.edu# verify that this stuff works 6833546Sgblack@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 6843546Sgblack@eecs.umich.edu print "Error: can't find Python.h header in", py_includes 6853546Sgblack@eecs.umich.edu Exit(1) 6863546Sgblack@eecs.umich.edu 6873546Sgblack@eecs.umich.edufor lib in py_libs: 6884202Sbinkertn@umich.edu if not conf.CheckLib(lib): 6893546Sgblack@eecs.umich.edu print "Error: can't find library %s required by python" % lib 6903546Sgblack@eecs.umich.edu Exit(1) 6913546Sgblack@eecs.umich.edu 692955SN/A# On Solaris you need to use libsocket for socket ops 693955SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 694955SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 695955SN/A print "Can't find library with socket calls (e.g. accept())" 6961858SN/A Exit(1) 6971858SN/A 6981858SN/A# Check for zlib. If the check passes, libz will be automatically 6992632Sstever@eecs.umich.edu# added to the LIBS environment variable. 7002632Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7015343Sstever@gmail.com print 'Error: did not find needed zlib compression library '\ 7025343Sstever@gmail.com 'and/or zlib.h header file.' 7035343Sstever@gmail.com print ' Please install zlib and try again.' 7044773Snate@binkert.org Exit(1) 7054773Snate@binkert.org 7062632Sstever@eecs.umich.edu# Check for librt. 7072632Sstever@eecs.umich.eduhave_posix_clock = \ 7082632Sstever@eecs.umich.edu conf.CheckLibWithHeader(None, 'time.h', 'C', 7092023SN/A 'clock_nanosleep(0,0,NULL,NULL);') or \ 7102632Sstever@eecs.umich.edu conf.CheckLibWithHeader('rt', 'time.h', 'C', 7112632Sstever@eecs.umich.edu 'clock_nanosleep(0,0,NULL,NULL);') 7122632Sstever@eecs.umich.edu 7132632Sstever@eecs.umich.eduif not have_posix_clock: 7142632Sstever@eecs.umich.edu print "Can't find library for POSIX clocks." 7153716Sstever@eecs.umich.edu 7165342Sstever@gmail.com# Check for <fenv.h> (C99 FP environment control) 7172632Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 7182632Sstever@eecs.umich.eduif not have_fenv: 7192632Sstever@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 7202632Sstever@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 7212023SN/A 7222632Sstever@eecs.umich.edu###################################################################### 7232632Sstever@eecs.umich.edu# 7245342Sstever@gmail.com# Check for mysql. 7251889SN/A# 7262632Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config') 7272632Sstever@eecs.umich.eduhave_mysql = bool(mysql_config) 7282632Sstever@eecs.umich.edu 7292632Sstever@eecs.umich.edu# Check MySQL version. 7303716Sstever@eecs.umich.eduif have_mysql: 7313716Sstever@eecs.umich.edu mysql_version = readCommand(mysql_config + ' --version') 7325342Sstever@gmail.com min_mysql_version = '4.1' 7332632Sstever@eecs.umich.edu if compareVersions(mysql_version, min_mysql_version) < 0: 7342632Sstever@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 7352632Sstever@eecs.umich.edu print ' Version', mysql_version, 'detected.' 7362632Sstever@eecs.umich.edu have_mysql = False 7372632Sstever@eecs.umich.edu 7382632Sstever@eecs.umich.edu# Set up mysql_config commands. 7392632Sstever@eecs.umich.eduif have_mysql: 7401888SN/A mysql_config_include = mysql_config + ' --include' 7411888SN/A if os.system(mysql_config_include + ' > /dev/null') != 0: 7421869SN/A # older mysql_config versions don't support --include, use 7431869SN/A # --cflags instead 7441858SN/A mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 7455341Sstever@gmail.com # This seems to work in all versions 7462598SN/A mysql_config_libs = mysql_config + ' --libs' 7472598SN/A 7482598SN/A###################################################################### 7492598SN/A# 7501858SN/A# Finish the configuration 7511858SN/A# 7521858SN/Amain = conf.Finish() 7531858SN/A 7541858SN/A###################################################################### 7551858SN/A# 7561858SN/A# Collect all non-global variables 7571858SN/A# 7581858SN/A 7591871SN/A# Define the universe of supported ISAs 7601858SN/Aall_isa_list = [ ] 7611858SN/AExport('all_isa_list') 7621858SN/A 7631858SN/Aclass CpuModel(object): 7641858SN/A '''The CpuModel class encapsulates everything the ISA parser needs to 7651858SN/A know about a particular CPU model.''' 7661858SN/A 7671858SN/A # Dict of available CPU model objects. Accessible as CpuModel.dict. 7681858SN/A dict = {} 7691858SN/A list = [] 7701858SN/A defaults = [] 7711859SN/A 7721859SN/A # Constructor. Automatically adds models to CpuModel.dict. 7731869SN/A def __init__(self, name, filename, includes, strings, default=False): 7741888SN/A self.name = name # name of model 7752632Sstever@eecs.umich.edu self.filename = filename # filename for output exec code 7761869SN/A self.includes = includes # include files needed in exec file 7771884SN/A # The 'strings' dict holds all the per-CPU symbols we can 7781884SN/A # substitute into templates etc. 7791884SN/A self.strings = strings 7801884SN/A 7811884SN/A # This cpu is enabled by default 7821884SN/A self.default = default 7831965SN/A 7841965SN/A # Add self to dict 7851965SN/A if name in CpuModel.dict: 7862761Sstever@eecs.umich.edu raise AttributeError, "CpuModel '%s' already registered" % name 7871869SN/A CpuModel.dict[name] = self 7881869SN/A CpuModel.list.append(name) 7892632Sstever@eecs.umich.edu 7902667Sstever@eecs.umich.eduExport('CpuModel') 7911869SN/A 7921869SN/A# Sticky variables get saved in the variables file so they persist from 7932929Sktlim@umich.edu# one invocation to the next (unless overridden, in which case the new 7942929Sktlim@umich.edu# value becomes sticky). 7953716Sstever@eecs.umich.edusticky_vars = Variables(args=ARGUMENTS) 7962929Sktlim@umich.eduExport('sticky_vars') 797955SN/A 7982598SN/A# Sticky variables that should be exported 7992598SN/Aexport_vars = [] 8003546Sgblack@eecs.umich.eduExport('export_vars') 801955SN/A 802955SN/A# Walk the tree and execute all SConsopts scripts that wil add to the 803955SN/A# above variables 8041530SN/Afor bdir in [ base_dir ] + extras_dir_list: 805955SN/A for root, dirs, files in os.walk(bdir): 806955SN/A if 'SConsopts' in files: 807955SN/A print "Reading", joinpath(root, 'SConsopts') 808 SConscript(joinpath(root, 'SConsopts')) 809 810all_isa_list.sort() 811 812sticky_vars.AddVariables( 813 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 814 BoolVariable('FULL_SYSTEM', 'Full-system support', False), 815 ListVariable('CPU_MODELS', 'CPU models', 816 sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 817 sorted(CpuModel.list)), 818 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 819 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 820 False), 821 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 822 False), 823 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 824 False), 825 BoolVariable('SS_COMPATIBLE_FP', 826 'Make floating-point results compatible with SimpleScalar', 827 False), 828 BoolVariable('USE_SSE2', 829 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 830 False), 831 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 832 BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 833 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 834 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 835 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 836 BoolVariable('RUBY', 'Build with Ruby', False), 837 ) 838 839# These variables get exported to #defines in config/*.hh (see src/SConscript). 840export_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 841 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 842 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE', 843 'USE_POSIX_CLOCK' ] 844 845################################################### 846# 847# Define a SCons builder for configuration flag headers. 848# 849################################################### 850 851# This function generates a config header file that #defines the 852# variable symbol to the current variable setting (0 or 1). The source 853# operands are the name of the variable and a Value node containing the 854# value of the variable. 855def build_config_file(target, source, env): 856 (variable, value) = [s.get_contents() for s in source] 857 f = file(str(target[0]), 'w') 858 print >> f, '#define', variable, value 859 f.close() 860 return None 861 862# Generate the message to be printed when building the config file. 863def build_config_file_string(target, source, env): 864 (variable, value) = [s.get_contents() for s in source] 865 return "Defining %s as %s in %s." % (variable, value, target[0]) 866 867# Combine the two functions into a scons Action object. 868config_action = Action(build_config_file, build_config_file_string) 869 870# The emitter munges the source & target node lists to reflect what 871# we're really doing. 872def config_emitter(target, source, env): 873 # extract variable name from Builder arg 874 variable = str(target[0]) 875 # True target is config header file 876 target = joinpath('config', variable.lower() + '.hh') 877 val = env[variable] 878 if isinstance(val, bool): 879 # Force value to 0/1 880 val = int(val) 881 elif isinstance(val, str): 882 val = '"' + val + '"' 883 884 # Sources are variable name & value (packaged in SCons Value nodes) 885 return ([target], [Value(variable), Value(val)]) 886 887config_builder = Builder(emitter = config_emitter, action = config_action) 888 889main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 890 891# libelf build is shared across all configs in the build root. 892main.SConscript('ext/libelf/SConscript', 893 variant_dir = joinpath(build_root, 'libelf')) 894 895# gzstream build is shared across all configs in the build root. 896main.SConscript('ext/gzstream/SConscript', 897 variant_dir = joinpath(build_root, 'gzstream')) 898 899################################################### 900# 901# This function is used to set up a directory with switching headers 902# 903################################################### 904 905main['ALL_ISA_LIST'] = all_isa_list 906def make_switching_dir(dname, switch_headers, env): 907 # Generate the header. target[0] is the full path of the output 908 # header to generate. 'source' is a dummy variable, since we get the 909 # list of ISAs from env['ALL_ISA_LIST']. 910 def gen_switch_hdr(target, source, env): 911 fname = str(target[0]) 912 f = open(fname, 'w') 913 isa = env['TARGET_ISA'].lower() 914 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 915 f.close() 916 917 # Build SCons Action object. 'varlist' specifies env vars that this 918 # action depends on; when env['ALL_ISA_LIST'] changes these actions 919 # should get re-executed. 920 switch_hdr_action = MakeAction(gen_switch_hdr, 921 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 922 923 # Instantiate actions for each header 924 for hdr in switch_headers: 925 env.Command(hdr, [], switch_hdr_action) 926Export('make_switching_dir') 927 928################################################### 929# 930# Define build environments for selected configurations. 931# 932################################################### 933 934for variant_path in variant_paths: 935 print "Building in", variant_path 936 937 # Make a copy of the build-root environment to use for this config. 938 env = main.Clone() 939 env['BUILDDIR'] = variant_path 940 941 # variant_dir is the tail component of build path, and is used to 942 # determine the build parameters (e.g., 'ALPHA_SE') 943 (build_root, variant_dir) = splitpath(variant_path) 944 945 # Set env variables according to the build directory config. 946 sticky_vars.files = [] 947 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 948 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 949 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 950 current_vars_file = joinpath(build_root, 'variables', variant_dir) 951 if isfile(current_vars_file): 952 sticky_vars.files.append(current_vars_file) 953 print "Using saved variables file %s" % current_vars_file 954 else: 955 # Build dir-specific variables file doesn't exist. 956 957 # Make sure the directory is there so we can create it later 958 opt_dir = dirname(current_vars_file) 959 if not isdir(opt_dir): 960 mkdir(opt_dir) 961 962 # Get default build variables from source tree. Variables are 963 # normally determined by name of $VARIANT_DIR, but can be 964 # overriden by 'default=' arg on command line. 965 default_vars_file = joinpath('build_opts', 966 ARGUMENTS.get('default', variant_dir)) 967 if isfile(default_vars_file): 968 sticky_vars.files.append(default_vars_file) 969 print "Variables file %s not found,\n using defaults in %s" \ 970 % (current_vars_file, default_vars_file) 971 else: 972 print "Error: cannot find variables file %s or %s" \ 973 % (current_vars_file, default_vars_file) 974 Exit(1) 975 976 # Apply current variable settings to env 977 sticky_vars.Update(env) 978 979 help_text += "\nSticky variables for %s:\n" % variant_dir \ 980 + sticky_vars.GenerateHelpText(env) 981 982 # Process variable settings. 983 984 if not have_fenv and env['USE_FENV']: 985 print "Warning: <fenv.h> not available; " \ 986 "forcing USE_FENV to False in", variant_dir + "." 987 env['USE_FENV'] = False 988 989 if not env['USE_FENV']: 990 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 991 print " FP results may deviate slightly from other platforms." 992 993 if env['EFENCE']: 994 env.Append(LIBS=['efence']) 995 996 if env['USE_MYSQL']: 997 if not have_mysql: 998 print "Warning: MySQL not available; " \ 999 "forcing USE_MYSQL to False in", variant_dir + "." 1000 env['USE_MYSQL'] = False 1001 else: 1002 print "Compiling in", variant_dir, "with MySQL support." 1003 env.ParseConfig(mysql_config_libs) 1004 env.ParseConfig(mysql_config_include) 1005 1006 # Save sticky variable settings back to current variables file 1007 sticky_vars.Save(current_vars_file, env) 1008 1009 if env['USE_SSE2']: 1010 env.Append(CCFLAGS=['-msse2']) 1011 1012 # The src/SConscript file sets up the build rules in 'env' according 1013 # to the configured variables. It returns a list of environments, 1014 # one for each variant build (debug, opt, etc.) 1015 envList = SConscript('src/SConscript', variant_dir = variant_path, 1016 exports = 'env') 1017 1018 # Set up the regression tests for each build. 1019 for e in envList: 1020 SConscript('tests/SConscript', 1021 variant_dir = joinpath(variant_path, 'tests', e.Label), 1022 exports = { 'env' : e }, duplicate = False) 1023 1024Help(help_text) 1025