SConstruct revision 3483
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 30955SN/A 31955SN/A################################################### 32955SN/A# 33955SN/A# SCons top-level build description (SConstruct) file. 34955SN/A# 352632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 362632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 372632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 382632Sstever@eecs.umich.edu# the optimized full-system version). 39955SN/A# 402632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 422761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 432632Sstever@eecs.umich.edu# built for the same host system. 442632Sstever@eecs.umich.edu# 452632Sstever@eecs.umich.edu# Examples: 462761Sstever@eecs.umich.edu# 472761Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 482761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 492632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 502632Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512761Sstever@eecs.umich.edu# 522761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 532761Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 542761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 552761Sstever@eecs.umich.edu# file. 562632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 572632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 582632Sstever@eecs.umich.edu# 592632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 602632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 622632Sstever@eecs.umich.edu# options as well. 63955SN/A# 64955SN/A################################################### 65955SN/A 66955SN/A# Python library imports 67955SN/Aimport sys 684202Sbinkertn@umich.eduimport os 694678Snate@binkert.org 70955SN/A# Check for recent-enough Python and SCons versions. If your system's 715273Sstever@gmail.com# default installation of Python is not recent enough, you can use a 725273Sstever@gmail.com# non-default installation of the Python interpreter by either (1) 732656Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 742656Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 752656Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 762656Sstever@eecs.umich.eduEnsurePythonVersion(2,4) 772656Sstever@eecs.umich.edu 782656Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 792656Sstever@eecs.umich.edu# 3-element version number. 802653Sstever@eecs.umich.edumin_scons_version = (0,96,91) 815227Ssaidi@eecs.umich.edutry: 825227Ssaidi@eecs.umich.edu EnsureSConsVersion(*min_scons_version) 835227Ssaidi@eecs.umich.eduexcept: 845227Ssaidi@eecs.umich.edu print "Error checking current SCons version." 852653Sstever@eecs.umich.edu print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 862653Sstever@eecs.umich.edu Exit(2) 872653Sstever@eecs.umich.edu 882653Sstever@eecs.umich.edu 892653Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives). 902653Sstever@eecs.umich.eduROOT = Dir('.').abspath 912653Sstever@eecs.umich.edu 922653Sstever@eecs.umich.edu# Paths to the M5 and external source trees. 932653Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'src') 944781Snate@binkert.org 951852SN/A# tell python where to find m5 python code 96955SN/Asys.path.append(os.path.join(ROOT, 'src/python')) 97955SN/A 98955SN/A################################################### 993717Sstever@eecs.umich.edu# 1003716Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 101955SN/A# the target(s). 1021533SN/A# 1033716Sstever@eecs.umich.edu################################################### 1041533SN/A 1054678Snate@binkert.org# Find default configuration & binary. 1064678Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1074678Snate@binkert.org 1084678Snate@binkert.org# Ask SCons which directory it was invoked from. 1094678Snate@binkert.orglaunch_dir = GetLaunchDir() 1104678Snate@binkert.org 1114678Snate@binkert.org# Make targets relative to invocation directory 1124678Snate@binkert.orgabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 1134678Snate@binkert.org BUILD_TARGETS) 1144678Snate@binkert.org 1154678Snate@binkert.org# helper function: find last occurrence of element in list 1164678Snate@binkert.orgdef rfind(l, elt, offs = -1): 1174678Snate@binkert.org for i in range(len(l)+offs, 0, -1): 1184678Snate@binkert.org if l[i] == elt: 1194678Snate@binkert.org return i 1204678Snate@binkert.org raise ValueError, "element not found" 1214678Snate@binkert.org 1224678Snate@binkert.org# helper function: compare dotted version numbers. 1234678Snate@binkert.org# E.g., compare_version('1.3.25', '1.4.1') 1244678Snate@binkert.org# returns -1, 0, 1 if v1 is <, ==, > v2 1254678Snate@binkert.orgdef compare_versions(v1, v2): 1264973Ssaidi@eecs.umich.edu # Convert dotted strings to lists 1274678Snate@binkert.org v1 = map(int, v1.split('.')) 1284678Snate@binkert.org v2 = map(int, v2.split('.')) 1294678Snate@binkert.org # Compare corresponding elements of lists 1304678Snate@binkert.org for n1,n2 in zip(v1, v2): 1314678Snate@binkert.org if n1 < n2: return -1 1324678Snate@binkert.org if n1 > n2: return 1 133955SN/A # all corresponding values are equal... see if one has extra values 134955SN/A if len(v1) < len(v2): return -1 1352632Sstever@eecs.umich.edu if len(v1) > len(v2): return 1 1362632Sstever@eecs.umich.edu return 0 137955SN/A 138955SN/A# Each target must have 'build' in the interior of the path; the 139955SN/A# directory below this will determine the build parameters. For 140955SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1412632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 142955SN/A# follow 'build' in the bulid path. 1432632Sstever@eecs.umich.edu 1442632Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1452632Sstever@eecs.umich.edu# collected targets reference. 1462632Sstever@eecs.umich.edubuild_paths = [] 1472632Sstever@eecs.umich.edubuild_root = None 1482632Sstever@eecs.umich.edufor t in abs_targets: 1492632Sstever@eecs.umich.edu path_dirs = t.split('/') 1503053Sstever@eecs.umich.edu try: 1513053Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 1523053Sstever@eecs.umich.edu except: 1533053Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 1543053Sstever@eecs.umich.edu Exit(1) 1553053Sstever@eecs.umich.edu this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1563053Sstever@eecs.umich.edu if not build_root: 1573053Sstever@eecs.umich.edu build_root = this_build_root 1583053Sstever@eecs.umich.edu else: 1593053Sstever@eecs.umich.edu if this_build_root != build_root: 1603053Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 1613053Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1623053Sstever@eecs.umich.edu Exit(1) 1633053Sstever@eecs.umich.edu build_path = os.path.join('/',*path_dirs[:build_top+2]) 1643053Sstever@eecs.umich.edu if build_path not in build_paths: 1653053Sstever@eecs.umich.edu build_paths.append(build_path) 1662632Sstever@eecs.umich.edu 1672632Sstever@eecs.umich.edu################################################### 1682632Sstever@eecs.umich.edu# 1692632Sstever@eecs.umich.edu# Set up the default build environment. This environment is copied 1702632Sstever@eecs.umich.edu# and modified according to each selected configuration. 1712632Sstever@eecs.umich.edu# 1723718Sstever@eecs.umich.edu################################################### 1733718Sstever@eecs.umich.edu 1743718Sstever@eecs.umich.eduenv = Environment(ENV = os.environ, # inherit user's environment vars 1753718Sstever@eecs.umich.edu ROOT = ROOT, 1763718Sstever@eecs.umich.edu SRCDIR = SRCDIR) 1773718Sstever@eecs.umich.edu 1783718Sstever@eecs.umich.eduenv.SConsignFile(os.path.join(build_root,"sconsign")) 1793718Sstever@eecs.umich.edu 1803718Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 1813718Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 1823718Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 1833718Sstever@eecs.umich.edu# (soft) links work better. 1843718Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 1852634Sstever@eecs.umich.edu 1862634Sstever@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but 1872632Sstever@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 1882638Sstever@eecs.umich.edu# noticeably longer. 1892632Sstever@eecs.umich.eduif False: 1902632Sstever@eecs.umich.edu env.TargetSignatures('content') 1912632Sstever@eecs.umich.edu 1922632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 1932632Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 1942632Sstever@eecs.umich.edu 1951858SN/A# Set up default C++ compiler flags 1963716Sstever@eecs.umich.eduenv.Append(CCFLAGS='-pipe') 1972638Sstever@eecs.umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing') 1982638Sstever@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1992638Sstever@eecs.umich.eduif sys.platform == 'cygwin': 2002638Sstever@eecs.umich.edu # cygwin has some header file issues... 2012638Sstever@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2022638Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 2032638Sstever@eecs.umich.edu 2043716Sstever@eecs.umich.edu# Check for SWIG 2052634Sstever@eecs.umich.eduif not env.has_key('SWIG'): 2062634Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 207955SN/A print ' Please install (see http://www.swig.org) and retry.' 208955SN/A Exit(1) 209955SN/A 210955SN/A# Check for appropriate SWIG version 211955SN/Aswig_version = os.popen('swig -version').read().split() 212955SN/A# First 3 words should be "SWIG Version x.y.z" 213955SN/Aif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 214955SN/A print 'Error determining SWIG version.' 2151858SN/A Exit(1) 2161858SN/A 2172632Sstever@eecs.umich.edumin_swig_version = '1.3.28' 218955SN/Aif compare_versions(swig_version[2], min_swig_version) < 0: 2194781Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 2203643Ssaidi@eecs.umich.edu print ' Installed version:', swig_version[2] 2213643Ssaidi@eecs.umich.edu Exit(1) 2223643Ssaidi@eecs.umich.edu 2233643Ssaidi@eecs.umich.edu# Set up SWIG flags & scanner 2243643Ssaidi@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2253643Ssaidi@eecs.umich.edu 2263643Ssaidi@eecs.umich.eduimport SCons.Scanner 2274494Ssaidi@eecs.umich.edu 2284494Ssaidi@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2293716Sstever@eecs.umich.edu 2301105SN/Aswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2312667Sstever@eecs.umich.edu swig_inc_re) 2322667Sstever@eecs.umich.edu 2332667Sstever@eecs.umich.eduenv.Append(SCANNERS = swig_scanner) 2342667Sstever@eecs.umich.edu 2352667Sstever@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 2362667Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 2371869SN/Aconf = Configure(env, 2381869SN/A conf_dir = os.path.join(build_root, '.scons_config'), 2391869SN/A log_file = os.path.join(build_root, 'scons_config.log')) 2401869SN/A 2411869SN/A# Find Python include and library directories for embedding the 2421065SN/A# interpreter. For consistency, we will use the same Python 2432632Sstever@eecs.umich.edu# installation used to run scons (and thus this script). If you want 2445199Sstever@gmail.com# to link in an alternate version, see above for instructions on how 2453918Ssaidi@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 2463918Ssaidi@eecs.umich.edu 2473940Ssaidi@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating 2484781Snate@binkert.org# include & library files 2494781Snate@binkert.orgpy_version_name = 'python' + sys.version[:3] 2503918Ssaidi@eecs.umich.edu 2514781Snate@binkert.org# include path, e.g. /usr/local/include/python2.4 2524781Snate@binkert.orgpy_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name) 2533918Ssaidi@eecs.umich.eduenv.Append(CPPPATH = py_header_path) 2544781Snate@binkert.org# verify that it works 2554781Snate@binkert.orgif not conf.CheckHeader('Python.h', '<>'): 2563940Ssaidi@eecs.umich.edu print "Error: can't find Python.h header in", py_header_path 2573942Ssaidi@eecs.umich.edu Exit(1) 2583940Ssaidi@eecs.umich.edu 2593918Ssaidi@eecs.umich.edu# add library path too if it's not in the default place 2603918Ssaidi@eecs.umich.edupy_lib_path = None 261955SN/Aif sys.exec_prefix != '/usr': 2621858SN/A py_lib_path = os.path.join(sys.exec_prefix, 'lib') 2633918Ssaidi@eecs.umich.eduelif sys.platform == 'cygwin': 2643918Ssaidi@eecs.umich.edu # cygwin puts the .dll in /bin for some reason 2653918Ssaidi@eecs.umich.edu py_lib_path = '/bin' 2663918Ssaidi@eecs.umich.eduif py_lib_path: 2673940Ssaidi@eecs.umich.edu env.Append(LIBPATH = py_lib_path) 2683940Ssaidi@eecs.umich.edu print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 2693918Ssaidi@eecs.umich.eduif not conf.CheckLib(py_version_name): 2703918Ssaidi@eecs.umich.edu print "Error: can't find Python library", py_version_name 2713918Ssaidi@eecs.umich.edu Exit(1) 2723918Ssaidi@eecs.umich.edu 2733918Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 2743918Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C', 'accept(0,NULL,NULL);'): 2753918Ssaidi@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C', 'accept(0,NULL,NULL);'): 2763918Ssaidi@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 2773918Ssaidi@eecs.umich.edu Exit(1) 2783940Ssaidi@eecs.umich.edu 2793918Ssaidi@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 2803918Ssaidi@eecs.umich.edu# added to the LIBS environment variable. 2811851SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 2821851SN/A print 'Error: did not find needed zlib compression library '\ 2831858SN/A 'and/or zlib.h header file.' 2845200Sstever@gmail.com print ' Please install zlib and try again.' 285955SN/A Exit(1) 2863053Sstever@eecs.umich.edu 2873053Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 2883053Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 2893053Sstever@eecs.umich.eduif not have_fenv: 2903053Sstever@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 2913053Sstever@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 2923053Sstever@eecs.umich.edu 2933053Sstever@eecs.umich.edu# Check for mysql. 2943053Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config') 2954742Sstever@eecs.umich.eduhave_mysql = mysql_config != None 2964742Sstever@eecs.umich.edu 2973053Sstever@eecs.umich.edu# Check MySQL version. 2983053Sstever@eecs.umich.eduif have_mysql: 2993053Sstever@eecs.umich.edu mysql_version = os.popen(mysql_config + ' --version').read() 3003053Sstever@eecs.umich.edu min_mysql_version = '4.1' 3013053Sstever@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 3023053Sstever@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3033053Sstever@eecs.umich.edu print ' Version', mysql_version, 'detected.' 3043053Sstever@eecs.umich.edu have_mysql = False 3053053Sstever@eecs.umich.edu 3062667Sstever@eecs.umich.edu# Set up mysql_config commands. 3074554Sbinkertn@umich.eduif have_mysql: 3084554Sbinkertn@umich.edu mysql_config_include = mysql_config + ' --include' 3092667Sstever@eecs.umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 3104554Sbinkertn@umich.edu # older mysql_config versions don't support --include, use 3114554Sbinkertn@umich.edu # --cflags instead 3124554Sbinkertn@umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 3134554Sbinkertn@umich.edu # This seems to work in all versions 3144554Sbinkertn@umich.edu mysql_config_libs = mysql_config + ' --libs' 3154554Sbinkertn@umich.edu 3164554Sbinkertn@umich.eduenv = conf.Finish() 3174781Snate@binkert.org 3184554Sbinkertn@umich.edu# Define the universe of supported ISAs 3194554Sbinkertn@umich.eduenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 3202667Sstever@eecs.umich.edu 3214554Sbinkertn@umich.edu# Define the universe of supported CPU models 3224554Sbinkertn@umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 3234554Sbinkertn@umich.edu 'FullCPU', 'O3CPU', 3244554Sbinkertn@umich.edu 'OzoneCPU'] 3252667Sstever@eecs.umich.edu 3264554Sbinkertn@umich.edu# Sticky options get saved in the options file so they persist from 3272667Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 3284554Sbinkertn@umich.edu# value becomes sticky). 3294554Sbinkertn@umich.edusticky_opts = Options(args=ARGUMENTS) 3302667Sstever@eecs.umich.edusticky_opts.AddOptions( 3312638Sstever@eecs.umich.edu EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 3322638Sstever@eecs.umich.edu BoolOption('FULL_SYSTEM', 'Full-system support', False), 3332638Sstever@eecs.umich.edu # There's a bug in scons 0.96.1 that causes ListOptions with list 3343716Sstever@eecs.umich.edu # values (more than one value) not to be able to be restored from 3353716Sstever@eecs.umich.edu # a saved option file. If this causes trouble then upgrade to 3361858SN/A # scons 0.96.90 or later. 3375227Ssaidi@eecs.umich.edu ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 3385227Ssaidi@eecs.umich.edu env['ALL_CPU_LIST']), 3395227Ssaidi@eecs.umich.edu BoolOption('ALPHA_TLASER', 3405227Ssaidi@eecs.umich.edu 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 3415227Ssaidi@eecs.umich.edu BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 3425227Ssaidi@eecs.umich.edu BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 3435227Ssaidi@eecs.umich.edu False), 3445227Ssaidi@eecs.umich.edu BoolOption('SS_COMPATIBLE_FP', 3455227Ssaidi@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 3465227Ssaidi@eecs.umich.edu False), 3475227Ssaidi@eecs.umich.edu BoolOption('USE_SSE2', 3485227Ssaidi@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 3495227Ssaidi@eecs.umich.edu False), 3505227Ssaidi@eecs.umich.edu BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 3515227Ssaidi@eecs.umich.edu BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 3525204Sstever@gmail.com BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 3535204Sstever@gmail.com ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3545204Sstever@gmail.com ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3555204Sstever@gmail.com BoolOption('BATCH', 'Use batch pool for build and tests', False), 3565204Sstever@gmail.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3575204Sstever@gmail.com ('PYTHONHOME', 3585204Sstever@gmail.com 'Override the default PYTHONHOME for this system (use with caution)', 3595204Sstever@gmail.com '%s:%s' % (sys.prefix, sys.exec_prefix)) 3605204Sstever@gmail.com ) 3615204Sstever@gmail.com 3625204Sstever@gmail.com# Non-sticky options only apply to the current build. 3635204Sstever@gmail.comnonsticky_opts = Options(args=ARGUMENTS) 3645204Sstever@gmail.comnonsticky_opts.AddOptions( 3655204Sstever@gmail.com BoolOption('update_ref', 'Update test reference outputs', False) 3665204Sstever@gmail.com ) 3675204Sstever@gmail.com 3685204Sstever@gmail.com# These options get exported to #defines in config/*.hh (see src/SConscript). 3695204Sstever@gmail.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 3705204Sstever@gmail.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 3713118Sstever@eecs.umich.edu 'USE_CHECKER', 'PYTHONHOME'] 3723118Sstever@eecs.umich.edu 3733118Sstever@eecs.umich.edu# Define a handy 'no-op' action 3743118Sstever@eecs.umich.edudef no_action(target, source, env): 3753118Sstever@eecs.umich.edu return 0 3763118Sstever@eecs.umich.edu 3773118Sstever@eecs.umich.eduenv.NoAction = Action(no_action, None) 3783118Sstever@eecs.umich.edu 3793118Sstever@eecs.umich.edu################################################### 3803118Sstever@eecs.umich.edu# 3813118Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers. 3823716Sstever@eecs.umich.edu# 3833118Sstever@eecs.umich.edu################################################### 3843118Sstever@eecs.umich.edu 3853118Sstever@eecs.umich.edu# This function generates a config header file that #defines the 3863118Sstever@eecs.umich.edu# option symbol to the current option setting (0 or 1). The source 3873118Sstever@eecs.umich.edu# operands are the name of the option and a Value node containing the 3883118Sstever@eecs.umich.edu# value of the option. 3893118Sstever@eecs.umich.edudef build_config_file(target, source, env): 3903118Sstever@eecs.umich.edu (option, value) = [s.get_contents() for s in source] 3913118Sstever@eecs.umich.edu f = file(str(target[0]), 'w') 3923716Sstever@eecs.umich.edu print >> f, '#define', option, value 3933118Sstever@eecs.umich.edu f.close() 3943118Sstever@eecs.umich.edu return None 3953118Sstever@eecs.umich.edu 3963118Sstever@eecs.umich.edu# Generate the message to be printed when building the config file. 3973118Sstever@eecs.umich.edudef build_config_file_string(target, source, env): 3983118Sstever@eecs.umich.edu (option, value) = [s.get_contents() for s in source] 3993118Sstever@eecs.umich.edu return "Defining %s as %s in %s." % (option, value, target[0]) 4003118Sstever@eecs.umich.edu 4013118Sstever@eecs.umich.edu# Combine the two functions into a scons Action object. 4023118Sstever@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string) 4033483Ssaidi@eecs.umich.edu 4043494Ssaidi@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 4053494Ssaidi@eecs.umich.edu# we're really doing. 4063483Ssaidi@eecs.umich.edudef config_emitter(target, source, env): 4073483Ssaidi@eecs.umich.edu # extract option name from Builder arg 4083483Ssaidi@eecs.umich.edu option = str(target[0]) 4093053Sstever@eecs.umich.edu # True target is config header file 4103053Sstever@eecs.umich.edu target = os.path.join('config', option.lower() + '.hh') 4113918Ssaidi@eecs.umich.edu val = env[option] 4123053Sstever@eecs.umich.edu if isinstance(val, bool): 4133053Sstever@eecs.umich.edu # Force value to 0/1 4143053Sstever@eecs.umich.edu val = int(val) 4153053Sstever@eecs.umich.edu elif isinstance(val, str): 4163053Sstever@eecs.umich.edu val = '"' + val + '"' 4171858SN/A 4181858SN/A # Sources are option name & value (packaged in SCons Value nodes) 4191858SN/A return ([target], [Value(option), Value(val)]) 4201858SN/A 4211858SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action) 4221858SN/A 4231859SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 4241858SN/A 4251858SN/A################################################### 4261858SN/A# 4271859SN/A# Define a SCons builder for copying files. This is used by the 4281859SN/A# Python zipfile code in src/python/SConscript, but is placed up here 4291862SN/A# since it's potentially more generally applicable. 4303053Sstever@eecs.umich.edu# 4313053Sstever@eecs.umich.edu################################################### 4323053Sstever@eecs.umich.edu 4333053Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 4341859SN/A 4351859SN/Aenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 4361859SN/A 4371859SN/A################################################### 4381859SN/A# 4391859SN/A# Define a simple SCons builder to concatenate files. 4401859SN/A# 4411859SN/A# Used to append the Python zip archive to the executable. 4421862SN/A# 4431859SN/A################################################### 4441859SN/A 4451859SN/Aconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 4461858SN/A 'chmod +x $TARGET'])) 4471858SN/A 4482139SN/Aenv.Append(BUILDERS = { 'Concat' : concat_builder }) 4494202Sbinkertn@umich.edu 4504202Sbinkertn@umich.edu 4512139SN/A# base help text 4522155SN/Ahelp_text = ''' 4534202Sbinkertn@umich.eduUsage: scons [scons options] [build options] [target(s)] 4544202Sbinkertn@umich.edu 4554202Sbinkertn@umich.edu''' 4562155SN/A 4571869SN/A# libelf build is shared across all configs in the build root. 4581869SN/Aenv.SConscript('ext/libelf/SConscript', 4591869SN/A build_dir = os.path.join(build_root, 'libelf'), 4601869SN/A exports = 'env') 4614202Sbinkertn@umich.edu 4624202Sbinkertn@umich.edu################################################### 4634202Sbinkertn@umich.edu# 4644202Sbinkertn@umich.edu# Define build environments for selected configurations. 4654202Sbinkertn@umich.edu# 4664202Sbinkertn@umich.edu################################################### 4674202Sbinkertn@umich.edu 4684202Sbinkertn@umich.edu# rename base env 4694202Sbinkertn@umich.edubase_env = env 4704202Sbinkertn@umich.edu 4714202Sbinkertn@umich.edufor build_path in build_paths: 4724202Sbinkertn@umich.edu print "Building in", build_path 4734202Sbinkertn@umich.edu # build_dir is the tail component of build path, and is used to 4744202Sbinkertn@umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 4754202Sbinkertn@umich.edu (build_root, build_dir) = os.path.split(build_path) 4764202Sbinkertn@umich.edu # Make a copy of the build-root environment to use for this config. 4775273Sstever@gmail.com env = base_env.Copy() 4785273Sstever@gmail.com 4795273Sstever@gmail.com # Set env options according to the build directory config. 4805273Sstever@gmail.com sticky_opts.files = [] 4815273Sstever@gmail.com # Options for $BUILD_ROOT/$BUILD_DIR are stored in 4825273Sstever@gmail.com # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 4835273Sstever@gmail.com # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 4844775Snate@binkert.org current_opts_file = os.path.join(build_root, 'options', build_dir) 4854775Snate@binkert.org if os.path.isfile(current_opts_file): 4864773Snate@binkert.org sticky_opts.files.append(current_opts_file) 4874773Snate@binkert.org print "Using saved options file %s" % current_opts_file 4884773Snate@binkert.org else: 4895273Sstever@gmail.com # Build dir-specific options file doesn't exist. 4904773Snate@binkert.org 4911869SN/A # Make sure the directory is there so we can create it later 4924202Sbinkertn@umich.edu opt_dir = os.path.dirname(current_opts_file) 4931869SN/A if not os.path.isdir(opt_dir): 4942508SN/A os.mkdir(opt_dir) 4952508SN/A 4962508SN/A # Get default build options from source tree. Options are 4972508SN/A # normally determined by name of $BUILD_DIR, but can be 4984202Sbinkertn@umich.edu # overriden by 'default=' arg on command line. 4991869SN/A default_opts_file = os.path.join('build_opts', 5001869SN/A ARGUMENTS.get('default', build_dir)) 5011869SN/A if os.path.isfile(default_opts_file): 5021869SN/A sticky_opts.files.append(default_opts_file) 5031869SN/A print "Options file %s not found,\n using defaults in %s" \ 5041869SN/A % (current_opts_file, default_opts_file) 5051965SN/A else: 5061965SN/A print "Error: cannot find options file %s or %s" \ 5071965SN/A % (current_opts_file, default_opts_file) 5081869SN/A Exit(1) 5091869SN/A 5102733Sktlim@umich.edu # Apply current option settings to env 5111869SN/A sticky_opts.Update(env) 5121884SN/A nonsticky_opts.Update(env) 5131884SN/A 5143356Sbinkertn@umich.edu help_text += "Sticky options for %s:\n" % build_dir \ 5153356Sbinkertn@umich.edu + sticky_opts.GenerateHelpText(env) \ 5163356Sbinkertn@umich.edu + "\nNon-sticky options for %s:\n" % build_dir \ 5174773Snate@binkert.org + nonsticky_opts.GenerateHelpText(env) 5184773Snate@binkert.org 5195273Sstever@gmail.com # Process option settings. 5201869SN/A 5211858SN/A if not have_fenv and env['USE_FENV']: 5221869SN/A print "Warning: <fenv.h> not available; " \ 5231869SN/A "forcing USE_FENV to False in", build_dir + "." 5241869SN/A env['USE_FENV'] = False 5251858SN/A 5262761Sstever@eecs.umich.edu if not env['USE_FENV']: 5271869SN/A print "Warning: No IEEE FP rounding mode control in", build_dir + "." 5282733Sktlim@umich.edu print " FP results may deviate slightly from other platforms." 5293584Ssaidi@eecs.umich.edu 5301869SN/A if env['EFENCE']: 5311869SN/A env.Append(LIBS=['efence']) 5321869SN/A 5331869SN/A if env['USE_MYSQL']: 5341869SN/A if not have_mysql: 5351869SN/A print "Warning: MySQL not available; " \ 5361858SN/A "forcing USE_MYSQL to False in", build_dir + "." 537955SN/A env['USE_MYSQL'] = False 538955SN/A else: 5391869SN/A print "Compiling in", build_dir, "with MySQL support." 5401869SN/A env.ParseConfig(mysql_config_libs) 5411869SN/A env.ParseConfig(mysql_config_include) 5421869SN/A 5431869SN/A # Save sticky option settings back to current options file 5441869SN/A sticky_opts.Save(current_opts_file, env) 5451869SN/A 5461869SN/A # Do this after we save setting back, or else we'll tack on an 5471869SN/A # extra 'qdo' every time we run scons. 5481869SN/A if env['BATCH']: 5491869SN/A env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 5501869SN/A env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 5511869SN/A 5521869SN/A if env['USE_SSE2']: 5531869SN/A env.Append(CCFLAGS='-msse2') 5541869SN/A 5551869SN/A # The src/SConscript file sets up the build rules in 'env' according 5561869SN/A # to the configured options. It returns a list of environments, 5571869SN/A # one for each variant build (debug, opt, etc.) 5581869SN/A envList = SConscript('src/SConscript', build_dir = build_path, 5591869SN/A exports = 'env') 5601869SN/A 5611869SN/A # Set up the regression tests for each build. 5621869SN/A for e in envList: 5631869SN/A SConscript('tests/SConscript', 5641869SN/A build_dir = os.path.join(build_path, 'tests', e.Label), 5651869SN/A exports = { 'env' : e }, duplicate = False) 5661869SN/A 5671869SN/AHelp(help_text) 5683716Sstever@eecs.umich.edu 5693356Sbinkertn@umich.edu################################################### 5703356Sbinkertn@umich.edu# 5713356Sbinkertn@umich.edu# Let SCons do its thing. At this point SCons will use the defined 5723356Sbinkertn@umich.edu# build environments to build the requested targets. 5733356Sbinkertn@umich.edu# 5743356Sbinkertn@umich.edu################################################### 5754781Snate@binkert.org 5761869SN/A