SConstruct revision 8152
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################################################### 683918Ssaidi@eecs.umich.edu 694202Sbinkertn@umich.edu# Check for recent-enough Python and SCons versions. 704678Snate@binkert.orgtry: 71955SN/A # Really old versions of scons only take two options for the 722656Sstever@eecs.umich.edu # 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 """ 792653Sstever@eecs.umich.eduFor more details, see: 802653Sstever@eecs.umich.edu http://m5sim.org/wiki/index.php/Compiling_M5 812653Sstever@eecs.umich.edu""" 822653Sstever@eecs.umich.edu raise 832653Sstever@eecs.umich.edu 842653Sstever@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 """ 901852SN/AYou can use a non-default installation of the Python interpreter by 91955SN/Aeither (1) rearranging your PATH so that scons finds the non-default 92955SN/A'python' first or (2) explicitly invoking an alternative interpreter 93955SN/Aon the scons script. 943717Sstever@eecs.umich.edu 953716Sstever@eecs.umich.eduFor more details, see: 96955SN/A http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 971533SN/A""" 983716Sstever@eecs.umich.edu raise 991533SN/A 1004678Snate@binkert.org# Global Python includes 1014678Snate@binkert.orgimport os 1024678Snate@binkert.orgimport re 1034678Snate@binkert.orgimport subprocess 1044678Snate@binkert.orgimport 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.orghelp_texts = { 1254678Snate@binkert.org "options" : "", 1264678Snate@binkert.org "global_vars" : "", 1274678Snate@binkert.org "local_vars" : "" 128955SN/A} 129955SN/A 1302632Sstever@eecs.umich.eduExport("help_texts") 1312632Sstever@eecs.umich.edu 132955SN/Adef AddM5Option(*args, **kwargs): 133955SN/A col_width = 30 134955SN/A 135955SN/A help = " " + ", ".join(args) 1362632Sstever@eecs.umich.edu if "help" in kwargs: 137955SN/A length = len(help) 1382632Sstever@eecs.umich.edu if length >= col_width: 1392632Sstever@eecs.umich.edu help += "\n" + " " * col_width 1402632Sstever@eecs.umich.edu else: 1412632Sstever@eecs.umich.edu help += " " * (col_width - length) 1422632Sstever@eecs.umich.edu help += kwargs["help"] 1432632Sstever@eecs.umich.edu help_texts["options"] += help + "\n" 1442632Sstever@eecs.umich.edu 1453053Sstever@eecs.umich.edu AddOption(*args, **kwargs) 1463053Sstever@eecs.umich.edu 1473053Sstever@eecs.umich.eduAddM5Option('--colors', dest='use_colors', action='store_true', 1483053Sstever@eecs.umich.edu help="Add color to abbreviated scons output") 1493053Sstever@eecs.umich.eduAddM5Option('--no-colors', dest='use_colors', action='store_false', 1503053Sstever@eecs.umich.edu help="Don't add color to abbreviated scons output") 1513053Sstever@eecs.umich.eduAddM5Option('--default', dest='default', type='string', action='store', 1523053Sstever@eecs.umich.edu help='Override which build_opts file to use for defaults') 1533053Sstever@eecs.umich.eduAddM5Option('--ignore-style', dest='ignore_style', action='store_true', 1543053Sstever@eecs.umich.edu help='Disable style checking hooks') 1553053Sstever@eecs.umich.eduAddM5Option('--update-ref', dest='update_ref', action='store_true', 1563053Sstever@eecs.umich.edu help='Update test reference outputs') 1573053Sstever@eecs.umich.eduAddM5Option('--verbose', dest='verbose', action='store_true', 1583053Sstever@eecs.umich.edu help='Print full tool command lines') 1593053Sstever@eecs.umich.edu 1603053Sstever@eecs.umich.eduuse_colors = GetOption('use_colors') 1612632Sstever@eecs.umich.eduif use_colors: 1622632Sstever@eecs.umich.edu from m5.util.terminal import termcap 1632632Sstever@eecs.umich.eduelif use_colors is None: 1642632Sstever@eecs.umich.edu # option unspecified; default behavior is to use colors iff isatty 1652632Sstever@eecs.umich.edu from m5.util.terminal import tty_termcap as termcap 1662632Sstever@eecs.umich.eduelse: 1673718Sstever@eecs.umich.edu from m5.util.terminal import no_termcap as termcap 1683718Sstever@eecs.umich.edu 1693718Sstever@eecs.umich.edu######################################################################## 1703718Sstever@eecs.umich.edu# 1713718Sstever@eecs.umich.edu# Set up the main build environment. 1723718Sstever@eecs.umich.edu# 1733718Sstever@eecs.umich.edu######################################################################## 1743718Sstever@eecs.umich.eduuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1753718Sstever@eecs.umich.edu 'PYTHONPATH', 'RANLIB' ]) 1763718Sstever@eecs.umich.edu 1773718Sstever@eecs.umich.eduuse_env = {} 1783718Sstever@eecs.umich.edufor key,val in os.environ.iteritems(): 1793718Sstever@eecs.umich.edu if key in use_vars or key.startswith("M5"): 1802634Sstever@eecs.umich.edu use_env[key] = val 1812634Sstever@eecs.umich.edu 1822632Sstever@eecs.umich.edumain = Environment(ENV=use_env) 1832638Sstever@eecs.umich.edumain.root = Dir(".") # The current directory (where this file lives). 1842632Sstever@eecs.umich.edumain.srcdir = Dir("src") # The source directory 1852632Sstever@eecs.umich.edu 1862632Sstever@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 1872632Sstever@eecs.umich.edu# as well 1882632Sstever@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths) 1892632Sstever@eecs.umich.edu 1901858SN/A######################################################################## 1913716Sstever@eecs.umich.edu# 1922638Sstever@eecs.umich.edu# Mercurial Stuff. 1932638Sstever@eecs.umich.edu# 1942638Sstever@eecs.umich.edu# If the M5 directory is a mercurial repository, we should do some 1952638Sstever@eecs.umich.edu# extra things. 1962638Sstever@eecs.umich.edu# 1972638Sstever@eecs.umich.edu######################################################################## 1982638Sstever@eecs.umich.edu 1993716Sstever@eecs.umich.eduhgdir = main.root.Dir(".hg") 2002634Sstever@eecs.umich.edu 2012634Sstever@eecs.umich.edumercurial_style_message = """ 202955SN/AYou're missing the M5 style hook. 203955SN/APlease install the hook so we can ensure that all code fits a common style. 204955SN/A 205955SN/AAll you'd need to do is add the following lines to your repository .hg/hgrc 206955SN/Aor your personal .hgrc 207955SN/A---------------- 208955SN/A 209955SN/A[extensions] 2101858SN/Astyle = %s/util/style.py 2111858SN/A 2122632Sstever@eecs.umich.edu[hooks] 213955SN/Apretxncommit.style = python:style.check_style 2143643Ssaidi@eecs.umich.edupre-qrefresh.style = python:style.check_style 2153643Ssaidi@eecs.umich.edu""" % (main.root) 2163643Ssaidi@eecs.umich.edu 2173643Ssaidi@eecs.umich.edumercurial_bin_not_found = """ 2183643Ssaidi@eecs.umich.eduMercurial binary cannot be found, unfortunately this means that we 2193643Ssaidi@eecs.umich.educannot easily determine the version of M5 that you are running and 2203643Ssaidi@eecs.umich.eduthis makes error messages more difficult to collect. Please consider 2213643Ssaidi@eecs.umich.eduinstalling mercurial if you choose to post an error message 2224494Ssaidi@eecs.umich.edu""" 2234494Ssaidi@eecs.umich.edu 2243716Sstever@eecs.umich.edumercurial_lib_not_found = """ 2251105SN/AMercurial libraries cannot be found, ignoring style hook 2262667Sstever@eecs.umich.eduIf you are actually a M5 developer, please fix this and 2272667Sstever@eecs.umich.edurun the style hook. It is important. 2282667Sstever@eecs.umich.edu""" 2292667Sstever@eecs.umich.edu 2302667Sstever@eecs.umich.eduif hgdir.exists(): 2312667Sstever@eecs.umich.edu # Ensure that the style hook is in place. 2321869SN/A try: 2331869SN/A ui = None 2341869SN/A if not GetOption('ignore_style'): 2351869SN/A from mercurial import ui 2361869SN/A ui = ui.ui() 2371065SN/A except ImportError: 2382632Sstever@eecs.umich.edu print mercurial_lib_not_found 2392632Sstever@eecs.umich.edu 2403918Ssaidi@eecs.umich.edu if ui is not None: 2413918Ssaidi@eecs.umich.edu ui.readconfig(hgdir.File('hgrc').abspath) 2423940Ssaidi@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) 2433918Ssaidi@eecs.umich.edu 2443918Ssaidi@eecs.umich.edu if not style_hook: 2453918Ssaidi@eecs.umich.edu print mercurial_style_message 2463918Ssaidi@eecs.umich.edu sys.exit(1) 2473918Ssaidi@eecs.umich.eduelse: 2483918Ssaidi@eecs.umich.edu print ".hg directory not found" 2493940Ssaidi@eecs.umich.edu 2503940Ssaidi@eecs.umich.edu################################################### 2513940Ssaidi@eecs.umich.edu# 2523942Ssaidi@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 2533940Ssaidi@eecs.umich.edu# the target(s). 2543918Ssaidi@eecs.umich.edu# 2553918Ssaidi@eecs.umich.edu################################################### 256955SN/A 2571858SN/A# Find default configuration & binary. 2583918Ssaidi@eecs.umich.eduDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2593918Ssaidi@eecs.umich.edu 2603918Ssaidi@eecs.umich.edu# helper function: find last occurrence of element in list 2613918Ssaidi@eecs.umich.edudef rfind(l, elt, offs = -1): 2623940Ssaidi@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 2633940Ssaidi@eecs.umich.edu if l[i] == elt: 2643918Ssaidi@eecs.umich.edu return i 2653918Ssaidi@eecs.umich.edu raise ValueError, "element not found" 2663918Ssaidi@eecs.umich.edu 2673918Ssaidi@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2683918Ssaidi@eecs.umich.edu# directory below this will determine the build parameters. For 2693918Ssaidi@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2703918Ssaidi@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 2713918Ssaidi@eecs.umich.edu# follow 'build' in the bulid path. 2723918Ssaidi@eecs.umich.edu 2733940Ssaidi@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is 2743918Ssaidi@eecs.umich.eduif COMMAND_LINE_TARGETS: 2753918Ssaidi@eecs.umich.edu # Ask SCons which directory it was invoked from 2761851SN/A launch_dir = GetLaunchDir() 2771851SN/A # Make targets relative to invocation directory 2781858SN/A abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2792632Sstever@eecs.umich.edu COMMAND_LINE_TARGETS] 280955SN/Aelse: 2813053Sstever@eecs.umich.edu # Default targets are relative to root of tree 2823053Sstever@eecs.umich.edu abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2833053Sstever@eecs.umich.edu DEFAULT_TARGETS] 2843053Sstever@eecs.umich.edu 2853053Sstever@eecs.umich.edu 2863053Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 2873053Sstever@eecs.umich.edu# collected targets reference. 2883053Sstever@eecs.umich.eduvariant_paths = [] 2893053Sstever@eecs.umich.edubuild_root = None 2904742Sstever@eecs.umich.edufor t in abs_targets: 2914742Sstever@eecs.umich.edu path_dirs = t.split('/') 2923053Sstever@eecs.umich.edu try: 2933053Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 2943053Sstever@eecs.umich.edu except: 2953053Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 2963053Sstever@eecs.umich.edu Exit(1) 2973053Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2983053Sstever@eecs.umich.edu if not build_root: 2993053Sstever@eecs.umich.edu build_root = this_build_root 3003053Sstever@eecs.umich.edu else: 3012667Sstever@eecs.umich.edu if this_build_root != build_root: 3024554Sbinkertn@umich.edu print "Error: build targets not under same build root\n"\ 3034554Sbinkertn@umich.edu " %s\n %s" % (build_root, this_build_root) 3042667Sstever@eecs.umich.edu Exit(1) 3054554Sbinkertn@umich.edu variant_path = joinpath('/',*path_dirs[:build_top+2]) 3064554Sbinkertn@umich.edu if variant_path not in variant_paths: 3074554Sbinkertn@umich.edu variant_paths.append(variant_path) 3084554Sbinkertn@umich.edu 3094554Sbinkertn@umich.edu# Make sure build_root exists (might not if this is the first build there) 3104554Sbinkertn@umich.eduif not isdir(build_root): 3114554Sbinkertn@umich.edu mkdir(build_root) 3124554Sbinkertn@umich.edumain['BUILDROOT'] = build_root 3134554Sbinkertn@umich.edu 3144554Sbinkertn@umich.eduExport('main') 3152667Sstever@eecs.umich.edu 3164554Sbinkertn@umich.edumain.SConsignFile(joinpath(build_root, "sconsign")) 3174554Sbinkertn@umich.edu 3184554Sbinkertn@umich.edu# Default duplicate option is to use hard links, but this messes up 3194554Sbinkertn@umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 3202667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 3214554Sbinkertn@umich.edu# (soft) links work better. 3222667Sstever@eecs.umich.edumain.SetOption('duplicate', 'soft-copy') 3234554Sbinkertn@umich.edu 3244554Sbinkertn@umich.edu# 3252667Sstever@eecs.umich.edu# Set up global sticky variables... these are common to an entire build 3262638Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 3272638Sstever@eecs.umich.edu# 3282638Sstever@eecs.umich.edu 3293716Sstever@eecs.umich.edu# Variable validators & converters for global sticky variables 3303716Sstever@eecs.umich.edudef PathListMakeAbsolute(val): 3311858SN/A if not val: 3323118Sstever@eecs.umich.edu return val 3333118Sstever@eecs.umich.edu f = lambda p: abspath(expanduser(p)) 3343118Sstever@eecs.umich.edu return ':'.join(map(f, val.split(':'))) 3353118Sstever@eecs.umich.edu 3363118Sstever@eecs.umich.edudef PathListAllExist(key, val, env): 3373118Sstever@eecs.umich.edu if not val: 3383118Sstever@eecs.umich.edu return 3393118Sstever@eecs.umich.edu paths = val.split(':') 3403118Sstever@eecs.umich.edu for path in paths: 3413118Sstever@eecs.umich.edu if not isdir(path): 3423118Sstever@eecs.umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3433716Sstever@eecs.umich.edu 3443118Sstever@eecs.umich.eduglobal_vars_file = joinpath(build_root, 'variables.global') 3453118Sstever@eecs.umich.edu 3463118Sstever@eecs.umich.eduglobal_vars = Variables(global_vars_file, args=ARGUMENTS) 3473118Sstever@eecs.umich.edu 3483118Sstever@eecs.umich.eduglobal_vars.AddVariables( 3493118Sstever@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3503118Sstever@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3513118Sstever@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3523118Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3533716Sstever@eecs.umich.edu ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 3543118Sstever@eecs.umich.edu ('EXTRAS', 'Add extra directories to the compilation', '', 3553118Sstever@eecs.umich.edu PathListAllExist, PathListMakeAbsolute), 3563118Sstever@eecs.umich.edu ) 3573118Sstever@eecs.umich.edu 3583118Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_vars_file 3593118Sstever@eecs.umich.eduglobal_vars.Update(main) 3603118Sstever@eecs.umich.eduhelp_texts["global_vars"] += global_vars.GenerateHelpText(main) 3613118Sstever@eecs.umich.edu 3623118Sstever@eecs.umich.edu# Save sticky variable settings back to current variables file 3633118Sstever@eecs.umich.eduglobal_vars.Save(global_vars_file, main) 3643483Ssaidi@eecs.umich.edu 3653494Ssaidi@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3663494Ssaidi@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3673483Ssaidi@eecs.umich.edubase_dir = main.srcdir.abspath 3683483Ssaidi@eecs.umich.eduif main['EXTRAS']: 3693483Ssaidi@eecs.umich.edu extras_dir_list = main['EXTRAS'].split(':') 3703053Sstever@eecs.umich.eduelse: 3713053Sstever@eecs.umich.edu extras_dir_list = [] 3723918Ssaidi@eecs.umich.edu 3733053Sstever@eecs.umich.eduExport('base_dir') 3743053Sstever@eecs.umich.eduExport('extras_dir_list') 3753053Sstever@eecs.umich.edu 3763053Sstever@eecs.umich.edu# the ext directory should be on the #includes path 3773053Sstever@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3781858SN/A 3791858SN/Adef strip_build_path(path, env): 3801858SN/A path = str(path) 3811858SN/A variant_base = env['BUILDROOT'] + os.path.sep 3821858SN/A if path.startswith(variant_base): 3831858SN/A path = path[len(variant_base):] 3841859SN/A elif path.startswith('build/'): 3851858SN/A path = path[6:] 3861858SN/A return path 3871858SN/A 3881859SN/A# Generate a string of the form: 3891859SN/A# common/path/prefix/src1, src2 -> tgt1, tgt2 3901862SN/A# to print while building. 3913053Sstever@eecs.umich.educlass Transform(object): 3923053Sstever@eecs.umich.edu # all specific color settings should be here and nowhere else 3933053Sstever@eecs.umich.edu tool_color = termcap.Normal 3943053Sstever@eecs.umich.edu pfx_color = termcap.Yellow 3951859SN/A srcs_color = termcap.Yellow + termcap.Bold 3961859SN/A arrow_color = termcap.Blue + termcap.Bold 3971859SN/A tgts_color = termcap.Yellow + termcap.Bold 3981859SN/A 3991859SN/A def __init__(self, tool, max_sources=99): 4001859SN/A self.format = self.tool_color + (" [%8s] " % tool) \ 4011859SN/A + self.pfx_color + "%s" \ 4021859SN/A + self.srcs_color + "%s" \ 4031862SN/A + self.arrow_color + " -> " \ 4041859SN/A + self.tgts_color + "%s" \ 4051859SN/A + termcap.Normal 4061859SN/A self.max_sources = max_sources 4071858SN/A 4081858SN/A def __call__(self, target, source, env, for_signature=None): 4092139SN/A # truncate source list according to max_sources param 4104202Sbinkertn@umich.edu source = source[0:self.max_sources] 4114202Sbinkertn@umich.edu def strip(f): 4122139SN/A return strip_build_path(str(f), env) 4132155SN/A if len(source) > 0: 4144202Sbinkertn@umich.edu srcs = map(strip, source) 4154202Sbinkertn@umich.edu else: 4164202Sbinkertn@umich.edu srcs = [''] 4172155SN/A tgts = map(strip, target) 4181869SN/A # surprisingly, os.path.commonprefix is a dumb char-by-char string 4191869SN/A # operation that has nothing to do with paths. 4201869SN/A com_pfx = os.path.commonprefix(srcs + tgts) 4211869SN/A com_pfx_len = len(com_pfx) 4224202Sbinkertn@umich.edu if com_pfx: 4234202Sbinkertn@umich.edu # do some cleanup and sanity checking on common prefix 4244202Sbinkertn@umich.edu if com_pfx[-1] == ".": 4254202Sbinkertn@umich.edu # prefix matches all but file extension: ok 4264202Sbinkertn@umich.edu # back up one to change 'foo.cc -> o' to 'foo.cc -> .o' 4274202Sbinkertn@umich.edu com_pfx = com_pfx[0:-1] 4284202Sbinkertn@umich.edu elif com_pfx[-1] == "/": 4294202Sbinkertn@umich.edu # common prefix is directory path: OK 4304202Sbinkertn@umich.edu pass 4314202Sbinkertn@umich.edu else: 4324202Sbinkertn@umich.edu src0_len = len(srcs[0]) 4334202Sbinkertn@umich.edu tgt0_len = len(tgts[0]) 4344202Sbinkertn@umich.edu if src0_len == com_pfx_len: 4354202Sbinkertn@umich.edu # source is a substring of target, OK 4364202Sbinkertn@umich.edu pass 4374202Sbinkertn@umich.edu elif tgt0_len == com_pfx_len: 4384773Snate@binkert.org # target is a substring of source, need to back up to 4394775Snate@binkert.org # avoid empty string on RHS of arrow 4404775Snate@binkert.org sep_idx = com_pfx.rfind(".") 4414773Snate@binkert.org if sep_idx != -1: 4424773Snate@binkert.org com_pfx = com_pfx[0:sep_idx] 4434773Snate@binkert.org else: 4444773Snate@binkert.org com_pfx = '' 4454773Snate@binkert.org elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".": 4464773Snate@binkert.org # still splitting at file extension: ok 4471869SN/A pass 4484202Sbinkertn@umich.edu else: 4491869SN/A # probably a fluke; ignore it 4502508SN/A com_pfx = '' 4512508SN/A # recalculate length in case com_pfx was modified 4522508SN/A com_pfx_len = len(com_pfx) 4532508SN/A def fmt(files): 4544202Sbinkertn@umich.edu f = map(lambda s: s[com_pfx_len:], files) 4551869SN/A return ', '.join(f) 4561869SN/A return self.format % (com_pfx, fmt(srcs), fmt(tgts)) 4571869SN/A 4581869SN/AExport('Transform') 4591869SN/A 4601869SN/A 4611965SN/Aif GetOption('verbose'): 4621965SN/A def MakeAction(action, string, *args, **kwargs): 4631965SN/A return Action(action, *args, **kwargs) 4641869SN/Aelse: 4651869SN/A MakeAction = Action 4662733Sktlim@umich.edu main['CCCOMSTR'] = Transform("CC") 4671869SN/A main['CXXCOMSTR'] = Transform("CXX") 4681884SN/A main['ASCOMSTR'] = Transform("AS") 4691884SN/A main['SWIGCOMSTR'] = Transform("SWIG") 4703356Sbinkertn@umich.edu main['ARCOMSTR'] = Transform("AR", 0) 4713356Sbinkertn@umich.edu main['LINKCOMSTR'] = Transform("LINK", 0) 4723356Sbinkertn@umich.edu main['RANLIBCOMSTR'] = Transform("RANLIB", 0) 4734773Snate@binkert.org main['M4COMSTR'] = Transform("M4") 4744773Snate@binkert.org main['SHCCCOMSTR'] = Transform("SHCC") 4754773Snate@binkert.org main['SHCXXCOMSTR'] = Transform("SHCXX") 4761869SN/AExport('MakeAction') 4771858SN/A 4781869SN/ACXX_version = readCommand([main['CXX'],'--version'], exception=False) 4791869SN/ACXX_V = readCommand([main['CXX'],'-V'], exception=False) 4801869SN/A 4811858SN/Amain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 4822761Sstever@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 4831869SN/Amain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 4842733Sktlim@umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 4853584Ssaidi@eecs.umich.edu print 'Error: How can we have two at the same time?' 4861869SN/A Exit(1) 4871869SN/A 4881869SN/A# Set up default C++ compiler flags 4891869SN/Aif main['GCC']: 4901869SN/A main.Append(CCFLAGS=['-pipe']) 4911869SN/A main.Append(CCFLAGS=['-fno-strict-aliasing']) 4921858SN/A main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 493955SN/A main.Append(CXXFLAGS=['-Wno-deprecated']) 494955SN/A # Read the GCC version to check for versions with bugs 4951869SN/A # Note CCVERSION doesn't work here because it is run with the CC 4961869SN/A # before we override it from the command line 4971869SN/A gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 4981869SN/A if not compareVersions(gcc_version, '4.4.1') or \ 4991869SN/A not compareVersions(gcc_version, '4.4.2'): 5001869SN/A print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 5011869SN/A main.Append(CCFLAGS=['-fno-tree-vectorize']) 5021869SN/Aelif main['ICC']: 5031869SN/A pass #Fix me... add warning flags once we clean up icc warnings 5041869SN/Aelif main['SUNCC']: 5051869SN/A main.Append(CCFLAGS=['-Qoption ccfe']) 5061869SN/A main.Append(CCFLAGS=['-features=gcc']) 5071869SN/A main.Append(CCFLAGS=['-features=extensions']) 5081869SN/A main.Append(CCFLAGS=['-library=stlport4']) 5091869SN/A main.Append(CCFLAGS=['-xar']) 5101869SN/A #main.Append(CCFLAGS=['-instances=semiexplicit']) 5111869SN/Aelse: 5121869SN/A print 'Error: Don\'t know what compiler options to use for your compiler.' 5131869SN/A print ' Please fix SConstruct and src/SConscript and try again.' 5141869SN/A Exit(1) 5151869SN/A 5161869SN/A# Set up common yacc/bison flags (needed for Ruby) 5171869SN/Amain['YACCFLAGS'] = '-d' 5181869SN/Amain['YACCHXXFILESUFFIX'] = '.hh' 5191869SN/A 5201869SN/A# Do this after we save setting back, or else we'll tack on an 5211869SN/A# extra 'qdo' every time we run scons. 5221869SN/Aif main['BATCH']: 5231869SN/A main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 5243716Sstever@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 5253356Sbinkertn@umich.edu main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 5263356Sbinkertn@umich.edu main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 5273356Sbinkertn@umich.edu main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 5283356Sbinkertn@umich.edu 5293356Sbinkertn@umich.eduif sys.platform == 'cygwin': 5303356Sbinkertn@umich.edu # cygwin has some header file issues... 5313356Sbinkertn@umich.edu main.Append(CCFLAGS=["-Wno-uninitialized"]) 5321869SN/A 5331869SN/A# Check for SWIG 5341869SN/Aif not main.has_key('SWIG'): 5351869SN/A print 'Error: SWIG utility not found.' 5361869SN/A print ' Please install (see http://www.swig.org) and retry.' 5371869SN/A Exit(1) 5381869SN/A 5392655Sstever@eecs.umich.edu# Check for appropriate SWIG version 5402655Sstever@eecs.umich.eduswig_version = readCommand(('swig', '-version'), exception='').split() 5412655Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 5422655Sstever@eecs.umich.eduif len(swig_version) < 3 or \ 5432655Sstever@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 5442655Sstever@eecs.umich.edu print 'Error determining SWIG version.' 5452655Sstever@eecs.umich.edu Exit(1) 5462655Sstever@eecs.umich.edu 5472655Sstever@eecs.umich.edumin_swig_version = '1.3.28' 5482655Sstever@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0: 5492655Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 5502655Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 5512655Sstever@eecs.umich.edu Exit(1) 5522655Sstever@eecs.umich.edu 5532655Sstever@eecs.umich.edu# Set up SWIG flags & scanner 5542655Sstever@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 5552655Sstever@eecs.umich.edumain.Append(SWIGFLAGS=swig_flags) 5562655Sstever@eecs.umich.edu 5572655Sstever@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 5582655Sstever@eecs.umich.edu# stuff for some reason 5592655Sstever@eecs.umich.eduscanners = [] 5602655Sstever@eecs.umich.edufor scanner in main['SCANNERS']: 5612655Sstever@eecs.umich.edu skeys = scanner.skeys 5622655Sstever@eecs.umich.edu if skeys == '.i': 5632655Sstever@eecs.umich.edu continue 5642655Sstever@eecs.umich.edu 5652634Sstever@eecs.umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 5662634Sstever@eecs.umich.edu continue 5672634Sstever@eecs.umich.edu 5682634Sstever@eecs.umich.edu scanners.append(scanner) 5692634Sstever@eecs.umich.edu 5702634Sstever@eecs.umich.edu# add the new swig scanner that we like better 5712638Sstever@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 5722638Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 5733716Sstever@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 5742638Sstever@eecs.umich.edu 5752638Sstever@eecs.umich.edu# replace the scanners list that has what we want 5761869SN/Amain['SCANNERS'] = scanners 5771869SN/A 5783546Sgblack@eecs.umich.edu# Add a custom Check function to the Configure context so that we can 5793546Sgblack@eecs.umich.edu# figure out if the compiler adds leading underscores to global 5803546Sgblack@eecs.umich.edu# variables. This is needed for the autogenerated asm files that we 5813546Sgblack@eecs.umich.edu# use for embedding the python code. 5824202Sbinkertn@umich.edudef CheckLeading(context): 5833546Sgblack@eecs.umich.edu context.Message("Checking for leading underscore in global variables...") 5843546Sgblack@eecs.umich.edu # 1) Define a global variable called x from asm so the C compiler 5853546Sgblack@eecs.umich.edu # won't change the symbol at all. 5863546Sgblack@eecs.umich.edu # 2) Declare that variable. 5873546Sgblack@eecs.umich.edu # 3) Use the variable 5883546Sgblack@eecs.umich.edu # 5893546Sgblack@eecs.umich.edu # If the compiler prepends an underscore, this will successfully 5903546Sgblack@eecs.umich.edu # link because the external symbol 'x' will be called '_x' which 5913546Sgblack@eecs.umich.edu # was defined by the asm statement. If the compiler does not 5923546Sgblack@eecs.umich.edu # prepend an underscore, this will not successfully link because 5934202Sbinkertn@umich.edu # '_x' will have been defined by assembly, while the C portion of 5943546Sgblack@eecs.umich.edu # the code will be trying to use 'x' 5953546Sgblack@eecs.umich.edu ret = context.TryLink(''' 5963546Sgblack@eecs.umich.edu asm(".globl _x; _x: .byte 0"); 5973546Sgblack@eecs.umich.edu extern int x; 5983546Sgblack@eecs.umich.edu int main() { return x; } 5993546Sgblack@eecs.umich.edu ''', extension=".c") 6003546Sgblack@eecs.umich.edu context.env.Append(LEADING_UNDERSCORE=ret) 6013546Sgblack@eecs.umich.edu context.Result(ret) 6023546Sgblack@eecs.umich.edu return ret 6033546Sgblack@eecs.umich.edu 6043546Sgblack@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 6053546Sgblack@eecs.umich.edu# builds under a given build root run on the same host platform. 6063546Sgblack@eecs.umich.educonf = Configure(main, 6073546Sgblack@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 6083546Sgblack@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log'), 6093546Sgblack@eecs.umich.edu custom_tests = { 'CheckLeading' : CheckLeading }) 6103546Sgblack@eecs.umich.edu 6113546Sgblack@eecs.umich.edu# Check for leading underscores. Don't really need to worry either 6123546Sgblack@eecs.umich.edu# way so don't need to check the return code. 6133546Sgblack@eecs.umich.educonf.CheckLeading() 6144202Sbinkertn@umich.edu 6153546Sgblack@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 6163546Sgblack@eecs.umich.edutry: 6173546Sgblack@eecs.umich.edu import platform 618955SN/A uname = platform.uname() 619955SN/A if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 620955SN/A if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 621955SN/A main.Append(CCFLAGS=['-arch', 'x86_64']) 6221858SN/A main.Append(CFLAGS=['-arch', 'x86_64']) 6231858SN/A main.Append(LINKFLAGS=['-arch', 'x86_64']) 6241858SN/A main.Append(ASFLAGS=['-arch', 'x86_64']) 6252632Sstever@eecs.umich.eduexcept: 6262632Sstever@eecs.umich.edu pass 6274773Snate@binkert.org 6284773Snate@binkert.org# Recent versions of scons substitute a "Null" object for Configure() 6292632Sstever@eecs.umich.edu# when configuration isn't necessary, e.g., if the "--help" option is 6302632Sstever@eecs.umich.edu# present. Unfortuantely this Null object always returns false, 6312632Sstever@eecs.umich.edu# breaking all our configuration checks. We replace it with our own 6322634Sstever@eecs.umich.edu# more optimistic null object that returns True instead. 6332638Sstever@eecs.umich.eduif not conf: 6342023SN/A def NullCheck(*args, **kwargs): 6352632Sstever@eecs.umich.edu return True 6362632Sstever@eecs.umich.edu 6372632Sstever@eecs.umich.edu class NullConf: 6382632Sstever@eecs.umich.edu def __init__(self, env): 6392632Sstever@eecs.umich.edu self.env = env 6403716Sstever@eecs.umich.edu def Finish(self): 6412632Sstever@eecs.umich.edu return self.env 6422632Sstever@eecs.umich.edu def __getattr__(self, mname): 6432632Sstever@eecs.umich.edu return NullCheck 6442632Sstever@eecs.umich.edu 6452632Sstever@eecs.umich.edu conf = NullConf(main) 6462023SN/A 6472632Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 6482632Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 6491889SN/A# installation used to run scons (and thus this script). If you want 6501889SN/A# to link in an alternate version, see above for instructions on how 6512632Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 6522632Sstever@eecs.umich.edufrom distutils import sysconfig 6532632Sstever@eecs.umich.edu 6542632Sstever@eecs.umich.edupy_getvar = sysconfig.get_config_var 6553716Sstever@eecs.umich.edu 6563716Sstever@eecs.umich.edupy_debug = getattr(sys, 'pydebug', False) 6572632Sstever@eecs.umich.edupy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 6582632Sstever@eecs.umich.edu 6592632Sstever@eecs.umich.edupy_general_include = sysconfig.get_python_inc() 6602632Sstever@eecs.umich.edupy_platform_include = sysconfig.get_python_inc(plat_specific=True) 6612632Sstever@eecs.umich.edupy_includes = [ py_general_include ] 6622632Sstever@eecs.umich.eduif py_platform_include != py_general_include: 6632632Sstever@eecs.umich.edu py_includes.append(py_platform_include) 6642632Sstever@eecs.umich.edu 6651888SN/Apy_lib_path = [ py_getvar('LIBDIR') ] 6661888SN/A# add the prefix/lib/pythonX.Y/config dir, but only if there is no 6671869SN/A# shared library in prefix/lib/. 6681869SN/Aif not py_getvar('Py_ENABLE_SHARED'): 6691858SN/A py_lib_path.append(py_getvar('LIBPL')) 6702598SN/A 6712598SN/Apy_libs = [] 6722598SN/Afor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 6732598SN/A assert lib.startswith('-l') 6742598SN/A lib = lib[2:] 6751858SN/A if lib not in py_libs: 6761858SN/A py_libs.append(lib) 6771858SN/Apy_libs.append(py_version) 6781858SN/A 6791858SN/Amain.Append(CPPPATH=py_includes) 6801858SN/Amain.Append(LIBPATH=py_lib_path) 6811858SN/A 6821858SN/A# Cache build files in the supplied directory. 6831858SN/Aif main['M5_BUILD_CACHE']: 6841871SN/A print 'Using build cache located at', main['M5_BUILD_CACHE'] 6851858SN/A CacheDir(main['M5_BUILD_CACHE']) 6861858SN/A 6871858SN/A 6881858SN/A# verify that this stuff works 6891858SN/Aif not conf.CheckHeader('Python.h', '<>'): 6901858SN/A print "Error: can't find Python.h header in", py_includes 6911858SN/A Exit(1) 6921858SN/A 6931858SN/Afor lib in py_libs: 6941858SN/A if not conf.CheckLib(lib): 6951858SN/A print "Error: can't find library %s required by python" % lib 6961859SN/A Exit(1) 6971859SN/A 6981869SN/A# On Solaris you need to use libsocket for socket ops 6991888SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7002632Sstever@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 7011869SN/A print "Can't find library with socket calls (e.g. accept())" 7021884SN/A Exit(1) 7031884SN/A 7041884SN/A# Check for zlib. If the check passes, libz will be automatically 7051884SN/A# added to the LIBS environment variable. 7061884SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 7071884SN/A print 'Error: did not find needed zlib compression library '\ 7081965SN/A 'and/or zlib.h header file.' 7091965SN/A print ' Please install zlib and try again.' 7101965SN/A Exit(1) 7112761Sstever@eecs.umich.edu 7121869SN/A# Check for librt. 7131869SN/Ahave_posix_clock = \ 7142632Sstever@eecs.umich.edu conf.CheckLibWithHeader(None, 'time.h', 'C', 7152667Sstever@eecs.umich.edu 'clock_nanosleep(0,0,NULL,NULL);') or \ 7161869SN/A conf.CheckLibWithHeader('rt', 'time.h', 'C', 7171869SN/A 'clock_nanosleep(0,0,NULL,NULL);') 7182929Sktlim@umich.edu 7192929Sktlim@umich.eduif not have_posix_clock: 7203716Sstever@eecs.umich.edu print "Can't find library for POSIX clocks." 7212929Sktlim@umich.edu 722955SN/A# Check for <fenv.h> (C99 FP environment control) 7232598SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 7242598SN/Aif not have_fenv: 7253546Sgblack@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 726955SN/A print " This host has no IEEE FP rounding mode control." 727955SN/A 728955SN/A###################################################################### 7291530SN/A# 730955SN/A# Check for mysql. 731955SN/A# 732955SN/Amysql_config = WhereIs('mysql_config') 733have_mysql = bool(mysql_config) 734 735# Check MySQL version. 736if have_mysql: 737 mysql_version = readCommand(mysql_config + ' --version') 738 min_mysql_version = '4.1' 739 if compareVersions(mysql_version, min_mysql_version) < 0: 740 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 741 print ' Version', mysql_version, 'detected.' 742 have_mysql = False 743 744# Set up mysql_config commands. 745if have_mysql: 746 mysql_config_include = mysql_config + ' --include' 747 if os.system(mysql_config_include + ' > /dev/null') != 0: 748 # older mysql_config versions don't support --include, use 749 # --cflags instead 750 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 751 # This seems to work in all versions 752 mysql_config_libs = mysql_config + ' --libs' 753 754###################################################################### 755# 756# Finish the configuration 757# 758main = conf.Finish() 759 760###################################################################### 761# 762# Collect all non-global variables 763# 764 765# Define the universe of supported ISAs 766all_isa_list = [ ] 767Export('all_isa_list') 768 769class CpuModel(object): 770 '''The CpuModel class encapsulates everything the ISA parser needs to 771 know about a particular CPU model.''' 772 773 # Dict of available CPU model objects. Accessible as CpuModel.dict. 774 dict = {} 775 list = [] 776 defaults = [] 777 778 # Constructor. Automatically adds models to CpuModel.dict. 779 def __init__(self, name, filename, includes, strings, default=False): 780 self.name = name # name of model 781 self.filename = filename # filename for output exec code 782 self.includes = includes # include files needed in exec file 783 # The 'strings' dict holds all the per-CPU symbols we can 784 # substitute into templates etc. 785 self.strings = strings 786 787 # This cpu is enabled by default 788 self.default = default 789 790 # Add self to dict 791 if name in CpuModel.dict: 792 raise AttributeError, "CpuModel '%s' already registered" % name 793 CpuModel.dict[name] = self 794 CpuModel.list.append(name) 795 796Export('CpuModel') 797 798# Sticky variables get saved in the variables file so they persist from 799# one invocation to the next (unless overridden, in which case the new 800# value becomes sticky). 801sticky_vars = Variables(args=ARGUMENTS) 802Export('sticky_vars') 803 804# Sticky variables that should be exported 805export_vars = [] 806Export('export_vars') 807 808# Walk the tree and execute all SConsopts scripts that wil add to the 809# above variables 810for bdir in [ base_dir ] + extras_dir_list: 811 for root, dirs, files in os.walk(bdir): 812 if 'SConsopts' in files: 813 print "Reading", joinpath(root, 'SConsopts') 814 SConscript(joinpath(root, 'SConsopts')) 815 816all_isa_list.sort() 817 818sticky_vars.AddVariables( 819 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 820 BoolVariable('FULL_SYSTEM', 'Full-system support', False), 821 ListVariable('CPU_MODELS', 'CPU models', 822 sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 823 sorted(CpuModel.list)), 824 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 825 BoolVariable('FORCE_FAST_ALLOC', 826 'Enable fast object allocator, even for m5.debug', False), 827 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 828 False), 829 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 830 False), 831 BoolVariable('SS_COMPATIBLE_FP', 832 'Make floating-point results compatible with SimpleScalar', 833 False), 834 BoolVariable('USE_SSE2', 835 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 836 False), 837 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 838 BoolVariable('USE_POSIX_CLOCK', 'Use POSIX Clocks', have_posix_clock), 839 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 840 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 841 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 842 BoolVariable('RUBY', 'Build with Ruby', False), 843 ) 844 845# These variables get exported to #defines in config/*.hh (see src/SConscript). 846export_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 847 'NO_FAST_ALLOC', 'FORCE_FAST_ALLOC', 'FAST_ALLOC_STATS', 848 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE', 849 'USE_POSIX_CLOCK' ] 850 851################################################### 852# 853# Define a SCons builder for configuration flag headers. 854# 855################################################### 856 857# This function generates a config header file that #defines the 858# variable symbol to the current variable setting (0 or 1). The source 859# operands are the name of the variable and a Value node containing the 860# value of the variable. 861def build_config_file(target, source, env): 862 (variable, value) = [s.get_contents() for s in source] 863 f = file(str(target[0]), 'w') 864 print >> f, '#define', variable, value 865 f.close() 866 return None 867 868# Generate the message to be printed when building the config file. 869def build_config_file_string(target, source, env): 870 (variable, value) = [s.get_contents() for s in source] 871 return "Defining %s as %s in %s." % (variable, value, target[0]) 872 873# Combine the two functions into a scons Action object. 874config_action = Action(build_config_file, build_config_file_string) 875 876# The emitter munges the source & target node lists to reflect what 877# we're really doing. 878def config_emitter(target, source, env): 879 # extract variable name from Builder arg 880 variable = str(target[0]) 881 # True target is config header file 882 target = joinpath('config', variable.lower() + '.hh') 883 val = env[variable] 884 if isinstance(val, bool): 885 # Force value to 0/1 886 val = int(val) 887 elif isinstance(val, str): 888 val = '"' + val + '"' 889 890 # Sources are variable name & value (packaged in SCons Value nodes) 891 return ([target], [Value(variable), Value(val)]) 892 893config_builder = Builder(emitter = config_emitter, action = config_action) 894 895main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 896 897# libelf build is shared across all configs in the build root. 898main.SConscript('ext/libelf/SConscript', 899 variant_dir = joinpath(build_root, 'libelf')) 900 901# gzstream build is shared across all configs in the build root. 902main.SConscript('ext/gzstream/SConscript', 903 variant_dir = joinpath(build_root, 'gzstream')) 904 905################################################### 906# 907# This function is used to set up a directory with switching headers 908# 909################################################### 910 911main['ALL_ISA_LIST'] = all_isa_list 912def make_switching_dir(dname, switch_headers, env): 913 # Generate the header. target[0] is the full path of the output 914 # header to generate. 'source' is a dummy variable, since we get the 915 # list of ISAs from env['ALL_ISA_LIST']. 916 def gen_switch_hdr(target, source, env): 917 fname = str(target[0]) 918 f = open(fname, 'w') 919 isa = env['TARGET_ISA'].lower() 920 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 921 f.close() 922 923 # Build SCons Action object. 'varlist' specifies env vars that this 924 # action depends on; when env['ALL_ISA_LIST'] changes these actions 925 # should get re-executed. 926 switch_hdr_action = MakeAction(gen_switch_hdr, 927 Transform("GENERATE"), varlist=['ALL_ISA_LIST']) 928 929 # Instantiate actions for each header 930 for hdr in switch_headers: 931 env.Command(hdr, [], switch_hdr_action) 932Export('make_switching_dir') 933 934################################################### 935# 936# Define build environments for selected configurations. 937# 938################################################### 939 940for variant_path in variant_paths: 941 print "Building in", variant_path 942 943 # Make a copy of the build-root environment to use for this config. 944 env = main.Clone() 945 env['BUILDDIR'] = variant_path 946 947 # variant_dir is the tail component of build path, and is used to 948 # determine the build parameters (e.g., 'ALPHA_SE') 949 (build_root, variant_dir) = splitpath(variant_path) 950 951 # Set env variables according to the build directory config. 952 sticky_vars.files = [] 953 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 954 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 955 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 956 current_vars_file = joinpath(build_root, 'variables', variant_dir) 957 if isfile(current_vars_file): 958 sticky_vars.files.append(current_vars_file) 959 print "Using saved variables file %s" % current_vars_file 960 else: 961 # Build dir-specific variables file doesn't exist. 962 963 # Make sure the directory is there so we can create it later 964 opt_dir = dirname(current_vars_file) 965 if not isdir(opt_dir): 966 mkdir(opt_dir) 967 968 # Get default build variables from source tree. Variables are 969 # normally determined by name of $VARIANT_DIR, but can be 970 # overriden by 'default=' arg on command line. 971 default = GetOption('default') 972 if not default: 973 default = variant_dir 974 default_vars_file = joinpath('build_opts', default) 975 if isfile(default_vars_file): 976 sticky_vars.files.append(default_vars_file) 977 print "Variables file %s not found,\n using defaults in %s" \ 978 % (current_vars_file, default_vars_file) 979 else: 980 print "Error: cannot find variables file %s or %s" \ 981 % (current_vars_file, default_vars_file) 982 Exit(1) 983 984 # Apply current variable settings to env 985 sticky_vars.Update(env) 986 987 help_texts["local_vars"] += \ 988 "Build variables for %s:\n" % variant_dir \ 989 + sticky_vars.GenerateHelpText(env) 990 991 # Process variable settings. 992 993 if not have_fenv and env['USE_FENV']: 994 print "Warning: <fenv.h> not available; " \ 995 "forcing USE_FENV to False in", variant_dir + "." 996 env['USE_FENV'] = False 997 998 if not env['USE_FENV']: 999 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 1000 print " FP results may deviate slightly from other platforms." 1001 1002 if env['EFENCE']: 1003 env.Append(LIBS=['efence']) 1004 1005 if env['USE_MYSQL']: 1006 if not have_mysql: 1007 print "Warning: MySQL not available; " \ 1008 "forcing USE_MYSQL to False in", variant_dir + "." 1009 env['USE_MYSQL'] = False 1010 else: 1011 print "Compiling in", variant_dir, "with MySQL support." 1012 env.ParseConfig(mysql_config_libs) 1013 env.ParseConfig(mysql_config_include) 1014 1015 # Save sticky variable settings back to current variables file 1016 sticky_vars.Save(current_vars_file, env) 1017 1018 if env['USE_SSE2']: 1019 env.Append(CCFLAGS=['-msse2']) 1020 1021 # The src/SConscript file sets up the build rules in 'env' according 1022 # to the configured variables. It returns a list of environments, 1023 # one for each variant build (debug, opt, etc.) 1024 envList = SConscript('src/SConscript', variant_dir = variant_path, 1025 exports = 'env') 1026 1027 # Set up the regression tests for each build. 1028 for e in envList: 1029 SConscript('tests/SConscript', 1030 variant_dir = joinpath(variant_path, 'tests', e.Label), 1031 exports = { 'env' : e }, duplicate = False) 1032 1033# base help text 1034Help(''' 1035Usage: scons [scons options] [build variables] [target(s)] 1036 1037Extra scons options: 1038%(options)s 1039 1040Global build variables: 1041%(global_vars)s 1042 1043%(local_vars)s 1044''' % help_texts) 1045