SConstruct revision 3717
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 68955SN/Aimport os 693716Sstever@eecs.umich.edufrom os.path import join as joinpath 70955SN/A 712656Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 722656Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a 732656Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1) 742656Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 752656Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 762656Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 772656Sstever@eecs.umich.eduEnsurePythonVersion(2,4) 782653Sstever@eecs.umich.edu 792653Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 802653Sstever@eecs.umich.edu# 3-element version number. 812653Sstever@eecs.umich.edumin_scons_version = (0,96,91) 822653Sstever@eecs.umich.edutry: 832653Sstever@eecs.umich.edu EnsureSConsVersion(*min_scons_version) 842653Sstever@eecs.umich.eduexcept: 852653Sstever@eecs.umich.edu print "Error checking current SCons version." 862653Sstever@eecs.umich.edu print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 872653Sstever@eecs.umich.edu Exit(2) 882653Sstever@eecs.umich.edu 891852SN/A 90955SN/A# The absolute path to the current directory (where this file lives). 91955SN/AROOT = Dir('.').abspath 92955SN/A 933717Sstever@eecs.umich.edu# Path to the M5 source tree. 943716Sstever@eecs.umich.eduSRCDIR = joinpath(ROOT, 'src') 95955SN/A 961533SN/A# tell python where to find m5 python code 973716Sstever@eecs.umich.edusys.path.append(joinpath(ROOT, 'src/python')) 981533SN/A 99955SN/A################################################### 100955SN/A# 1012632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 1022632Sstever@eecs.umich.edu# the target(s). 103955SN/A# 104955SN/A################################################### 105955SN/A 106955SN/A# Find default configuration & binary. 1072632Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 108955SN/A 1092632Sstever@eecs.umich.edu# Ask SCons which directory it was invoked from. 110955SN/Alaunch_dir = GetLaunchDir() 111955SN/A 1122632Sstever@eecs.umich.edu# Make targets relative to invocation directory 1133716Sstever@eecs.umich.eduabs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 1142632Sstever@eecs.umich.edu BUILD_TARGETS) 1152632Sstever@eecs.umich.edu 1162632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 1172632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 1182632Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 1192632Sstever@eecs.umich.edu if l[i] == elt: 1202632Sstever@eecs.umich.edu return i 1212632Sstever@eecs.umich.edu raise ValueError, "element not found" 1222632Sstever@eecs.umich.edu 1233053Sstever@eecs.umich.edu# helper function: compare dotted version numbers. 1243053Sstever@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1') 1253053Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1263053Sstever@eecs.umich.edudef compare_versions(v1, v2): 1273053Sstever@eecs.umich.edu # Convert dotted strings to lists 1283053Sstever@eecs.umich.edu v1 = map(int, v1.split('.')) 1293053Sstever@eecs.umich.edu v2 = map(int, v2.split('.')) 1303053Sstever@eecs.umich.edu # Compare corresponding elements of lists 1313053Sstever@eecs.umich.edu for n1,n2 in zip(v1, v2): 1323053Sstever@eecs.umich.edu if n1 < n2: return -1 1333053Sstever@eecs.umich.edu if n1 > n2: return 1 1343053Sstever@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1353053Sstever@eecs.umich.edu if len(v1) < len(v2): return -1 1363053Sstever@eecs.umich.edu if len(v1) > len(v2): return 1 1373053Sstever@eecs.umich.edu return 0 1383053Sstever@eecs.umich.edu 1392632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 1402632Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 1412632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1422632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 1432632Sstever@eecs.umich.edu# follow 'build' in the bulid path. 1442632Sstever@eecs.umich.edu 1452634Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1462634Sstever@eecs.umich.edu# collected targets reference. 1472632Sstever@eecs.umich.edubuild_paths = [] 1482638Sstever@eecs.umich.edubuild_root = None 1492632Sstever@eecs.umich.edufor t in abs_targets: 1502632Sstever@eecs.umich.edu path_dirs = t.split('/') 1512632Sstever@eecs.umich.edu try: 1522632Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 1532632Sstever@eecs.umich.edu except: 1542632Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 1551858SN/A Exit(1) 1563716Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 1572638Sstever@eecs.umich.edu if not build_root: 1582638Sstever@eecs.umich.edu build_root = this_build_root 1592638Sstever@eecs.umich.edu else: 1602638Sstever@eecs.umich.edu if this_build_root != build_root: 1612638Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 1622638Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1632638Sstever@eecs.umich.edu Exit(1) 1643716Sstever@eecs.umich.edu build_path = joinpath('/',*path_dirs[:build_top+2]) 1652634Sstever@eecs.umich.edu if build_path not in build_paths: 1662634Sstever@eecs.umich.edu build_paths.append(build_path) 167955SN/A 168955SN/A################################################### 169955SN/A# 170955SN/A# Set up the default build environment. This environment is copied 171955SN/A# and modified according to each selected configuration. 172955SN/A# 173955SN/A################################################### 174955SN/A 1751858SN/Aenv = Environment(ENV = os.environ, # inherit user's environment vars 1761858SN/A ROOT = ROOT, 1772632Sstever@eecs.umich.edu SRCDIR = SRCDIR) 178955SN/A 1793643Ssaidi@eecs.umich.edu#Parse CC/CXX early so that we use the correct compiler for 1803643Ssaidi@eecs.umich.edu# to test for dependencies/versions/libraries/includes 1813643Ssaidi@eecs.umich.eduif ARGUMENTS.get('CC', None): 1823643Ssaidi@eecs.umich.edu env['CC'] = ARGUMENTS.get('CC') 1833643Ssaidi@eecs.umich.edu 1843643Ssaidi@eecs.umich.eduif ARGUMENTS.get('CXX', None): 1853643Ssaidi@eecs.umich.edu env['CXX'] = ARGUMENTS.get('CXX') 1863643Ssaidi@eecs.umich.edu 1873716Sstever@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign")) 1881105SN/A 1892667Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 1902667Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 1912667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 1922667Sstever@eecs.umich.edu# (soft) links work better. 1932667Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 1942667Sstever@eecs.umich.edu 1951869SN/A# I waffle on this setting... it does avoid a few painful but 1961869SN/A# unnecessary builds, but it also seems to make trivial builds take 1971869SN/A# noticeably longer. 1981869SN/Aif False: 1991869SN/A env.TargetSignatures('content') 2001065SN/A 2012632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 2022632Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 203955SN/A 2041858SN/A# Set up default C++ compiler flags 2051858SN/Aenv.Append(CCFLAGS='-pipe') 2061858SN/Aenv.Append(CCFLAGS='-fno-strict-aliasing') 2071858SN/Aenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2081851SN/Aif sys.platform == 'cygwin': 2091851SN/A # cygwin has some header file issues... 2101858SN/A env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2112632Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 212955SN/A 2133053Sstever@eecs.umich.edu# Check for SWIG 2143053Sstever@eecs.umich.eduif not env.has_key('SWIG'): 2153053Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 2163053Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 2173053Sstever@eecs.umich.edu Exit(1) 2183053Sstever@eecs.umich.edu 2193053Sstever@eecs.umich.edu# Check for appropriate SWIG version 2203053Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split() 2213053Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 2223053Sstever@eecs.umich.eduif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2233053Sstever@eecs.umich.edu print 'Error determining SWIG version.' 2243053Sstever@eecs.umich.edu Exit(1) 2253053Sstever@eecs.umich.edu 2263053Sstever@eecs.umich.edumin_swig_version = '1.3.28' 2273053Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 2283053Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 2293053Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 2303053Sstever@eecs.umich.edu Exit(1) 2313053Sstever@eecs.umich.edu 2322667Sstever@eecs.umich.edu# Set up SWIG flags & scanner 2332667Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2342667Sstever@eecs.umich.edu 2352667Sstever@eecs.umich.eduimport SCons.Scanner 2362667Sstever@eecs.umich.edu 2372667Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2382667Sstever@eecs.umich.edu 2392667Sstever@eecs.umich.eduswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2402667Sstever@eecs.umich.edu swig_inc_re) 2412667Sstever@eecs.umich.edu 2422667Sstever@eecs.umich.eduenv.Append(SCANNERS = swig_scanner) 2432667Sstever@eecs.umich.edu 2442638Sstever@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 2452638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 2462638Sstever@eecs.umich.educonf = Configure(env, 2473716Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 2483716Sstever@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log')) 2491858SN/A 2503118Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 2513118Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 2523118Sstever@eecs.umich.edu# installation used to run scons (and thus this script). If you want 2533118Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how 2543118Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 2553118Sstever@eecs.umich.edu 2563118Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating 2573118Sstever@eecs.umich.edu# include & library files 2583118Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3] 2593118Sstever@eecs.umich.edu 2603118Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4 2613716Sstever@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 2623118Sstever@eecs.umich.eduenv.Append(CPPPATH = py_header_path) 2633118Sstever@eecs.umich.edu# verify that it works 2643118Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 2653118Sstever@eecs.umich.edu print "Error: can't find Python.h header in", py_header_path 2663118Sstever@eecs.umich.edu Exit(1) 2673118Sstever@eecs.umich.edu 2683118Sstever@eecs.umich.edu# add library path too if it's not in the default place 2693118Sstever@eecs.umich.edupy_lib_path = None 2703118Sstever@eecs.umich.eduif sys.exec_prefix != '/usr': 2713716Sstever@eecs.umich.edu py_lib_path = joinpath(sys.exec_prefix, 'lib') 2723118Sstever@eecs.umich.eduelif sys.platform == 'cygwin': 2733118Sstever@eecs.umich.edu # cygwin puts the .dll in /bin for some reason 2743118Sstever@eecs.umich.edu py_lib_path = '/bin' 2753118Sstever@eecs.umich.eduif py_lib_path: 2763118Sstever@eecs.umich.edu env.Append(LIBPATH = py_lib_path) 2773118Sstever@eecs.umich.edu print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 2783118Sstever@eecs.umich.eduif not conf.CheckLib(py_version_name): 2793118Sstever@eecs.umich.edu print "Error: can't find Python library", py_version_name 2803118Sstever@eecs.umich.edu Exit(1) 2813118Sstever@eecs.umich.edu 2823483Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 2833494Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2843494Ssaidi@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2853483Ssaidi@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 2863483Ssaidi@eecs.umich.edu Exit(1) 2873483Ssaidi@eecs.umich.edu 2883053Sstever@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 2893053Sstever@eecs.umich.edu# added to the LIBS environment variable. 2903053Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 2913053Sstever@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 2923053Sstever@eecs.umich.edu 'and/or zlib.h header file.' 2933053Sstever@eecs.umich.edu print ' Please install zlib and try again.' 2943053Sstever@eecs.umich.edu Exit(1) 2953053Sstever@eecs.umich.edu 2961858SN/A# Check for <fenv.h> (C99 FP environment control) 2971858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 2981858SN/Aif not have_fenv: 2991858SN/A print "Warning: Header file <fenv.h> not found." 3001858SN/A print " This host has no IEEE FP rounding mode control." 3011858SN/A 3021859SN/A# Check for mysql. 3031858SN/Amysql_config = WhereIs('mysql_config') 3041858SN/Ahave_mysql = mysql_config != None 3051858SN/A 3061859SN/A# Check MySQL version. 3071859SN/Aif have_mysql: 3081862SN/A mysql_version = os.popen(mysql_config + ' --version').read() 3093053Sstever@eecs.umich.edu min_mysql_version = '4.1' 3103053Sstever@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 3113053Sstever@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3123053Sstever@eecs.umich.edu print ' Version', mysql_version, 'detected.' 3131859SN/A have_mysql = False 3141859SN/A 3151859SN/A# Set up mysql_config commands. 3161859SN/Aif have_mysql: 3171859SN/A mysql_config_include = mysql_config + ' --include' 3181859SN/A if os.system(mysql_config_include + ' > /dev/null') != 0: 3191859SN/A # older mysql_config versions don't support --include, use 3201859SN/A # --cflags instead 3211862SN/A mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 3221859SN/A # This seems to work in all versions 3231859SN/A mysql_config_libs = mysql_config + ' --libs' 3241859SN/A 3251858SN/Aenv = conf.Finish() 3261858SN/A 3272139SN/A# Define the universe of supported ISAs 3282139SN/Aenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 3292139SN/A 3302155SN/A# Define the universe of supported CPU models 3312623SN/Aenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 3323583Sbinkertn@umich.edu 'O3CPU', 'OzoneCPU'] 3333583Sbinkertn@umich.edu 3343717Sstever@eecs.umich.eduif os.path.isdir(joinpath(SRCDIR, 'encumbered/cpu/full')): 3353583Sbinkertn@umich.edu env['ALL_CPU_LIST'] += ['FullCPU'] 3362155SN/A 3371869SN/A# Sticky options get saved in the options file so they persist from 3381869SN/A# one invocation to the next (unless overridden, in which case the new 3391869SN/A# value becomes sticky). 3401869SN/Asticky_opts = Options(args=ARGUMENTS) 3411869SN/Asticky_opts.AddOptions( 3422139SN/A EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 3431869SN/A BoolOption('FULL_SYSTEM', 'Full-system support', False), 3442508SN/A # There's a bug in scons 0.96.1 that causes ListOptions with list 3452508SN/A # values (more than one value) not to be able to be restored from 3462508SN/A # a saved option file. If this causes trouble then upgrade to 3472508SN/A # scons 0.96.90 or later. 3483685Sktlim@umich.edu ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU,O3CPU', 3492635Sstever@eecs.umich.edu env['ALL_CPU_LIST']), 3501869SN/A BoolOption('ALPHA_TLASER', 3511869SN/A 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 3521869SN/A BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 3531869SN/A BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 3541869SN/A False), 3551869SN/A BoolOption('SS_COMPATIBLE_FP', 3561869SN/A 'Make floating-point results compatible with SimpleScalar', 3571869SN/A False), 3581965SN/A BoolOption('USE_SSE2', 3591965SN/A 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 3601965SN/A False), 3611869SN/A BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 3621869SN/A BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 3632733Sktlim@umich.edu BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 3641869SN/A ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3651884SN/A ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3661884SN/A BoolOption('BATCH', 'Use batch pool for build and tests', False), 3673356Sbinkertn@umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3683356Sbinkertn@umich.edu ('PYTHONHOME', 3693356Sbinkertn@umich.edu 'Override the default PYTHONHOME for this system (use with caution)', 3703356Sbinkertn@umich.edu '%s:%s' % (sys.prefix, sys.exec_prefix)) 3711869SN/A ) 3721858SN/A 3731869SN/A# Non-sticky options only apply to the current build. 3741869SN/Anonsticky_opts = Options(args=ARGUMENTS) 3751869SN/Anonsticky_opts.AddOptions( 3761869SN/A BoolOption('update_ref', 'Update test reference outputs', False) 3771869SN/A ) 3781858SN/A 3792761Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript). 3801869SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 3812733Sktlim@umich.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 3823584Ssaidi@eecs.umich.edu 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 3831869SN/A 3841869SN/A# Define a handy 'no-op' action 3851869SN/Adef no_action(target, source, env): 3861869SN/A return 0 3871869SN/A 3881869SN/Aenv.NoAction = Action(no_action, None) 3891858SN/A 390955SN/A################################################### 391955SN/A# 3921869SN/A# Define a SCons builder for configuration flag headers. 3931869SN/A# 3941869SN/A################################################### 3951869SN/A 3961869SN/A# This function generates a config header file that #defines the 3971869SN/A# option symbol to the current option setting (0 or 1). The source 3981869SN/A# operands are the name of the option and a Value node containing the 3991869SN/A# value of the option. 4001869SN/Adef build_config_file(target, source, env): 4011869SN/A (option, value) = [s.get_contents() for s in source] 4021869SN/A f = file(str(target[0]), 'w') 4031869SN/A print >> f, '#define', option, value 4041869SN/A f.close() 4051869SN/A return None 4061869SN/A 4071869SN/A# Generate the message to be printed when building the config file. 4081869SN/Adef build_config_file_string(target, source, env): 4091869SN/A (option, value) = [s.get_contents() for s in source] 4101869SN/A return "Defining %s as %s in %s." % (option, value, target[0]) 4111869SN/A 4121869SN/A# Combine the two functions into a scons Action object. 4131869SN/Aconfig_action = Action(build_config_file, build_config_file_string) 4141869SN/A 4151869SN/A# The emitter munges the source & target node lists to reflect what 4161869SN/A# we're really doing. 4171869SN/Adef config_emitter(target, source, env): 4181869SN/A # extract option name from Builder arg 4191869SN/A option = str(target[0]) 4201869SN/A # True target is config header file 4213716Sstever@eecs.umich.edu target = joinpath('config', option.lower() + '.hh') 4223356Sbinkertn@umich.edu val = env[option] 4233356Sbinkertn@umich.edu if isinstance(val, bool): 4243356Sbinkertn@umich.edu # Force value to 0/1 4253356Sbinkertn@umich.edu val = int(val) 4263356Sbinkertn@umich.edu elif isinstance(val, str): 4273356Sbinkertn@umich.edu val = '"' + val + '"' 4283356Sbinkertn@umich.edu 4291869SN/A # Sources are option name & value (packaged in SCons Value nodes) 4301869SN/A return ([target], [Value(option), Value(val)]) 4311869SN/A 4321869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action) 4331869SN/A 4341869SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 4351869SN/A 4362655Sstever@eecs.umich.edu################################################### 4372655Sstever@eecs.umich.edu# 4382655Sstever@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 4392655Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here 4402655Sstever@eecs.umich.edu# since it's potentially more generally applicable. 4412655Sstever@eecs.umich.edu# 4422655Sstever@eecs.umich.edu################################################### 4432655Sstever@eecs.umich.edu 4442655Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 4452655Sstever@eecs.umich.edu 4462655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 4472655Sstever@eecs.umich.edu 4482655Sstever@eecs.umich.edu################################################### 4492655Sstever@eecs.umich.edu# 4502655Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files. 4512655Sstever@eecs.umich.edu# 4522655Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable. 4532655Sstever@eecs.umich.edu# 4542655Sstever@eecs.umich.edu################################################### 4552655Sstever@eecs.umich.edu 4562655Sstever@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 4572655Sstever@eecs.umich.edu 'chmod +x $TARGET'])) 4582655Sstever@eecs.umich.edu 4592655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder }) 4602655Sstever@eecs.umich.edu 4612655Sstever@eecs.umich.edu 4622634Sstever@eecs.umich.edu# base help text 4632634Sstever@eecs.umich.eduhelp_text = ''' 4642634Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 4652634Sstever@eecs.umich.edu 4662634Sstever@eecs.umich.edu''' 4672634Sstever@eecs.umich.edu 4682638Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root. 4692638Sstever@eecs.umich.eduenv.SConscript('ext/libelf/SConscript', 4703716Sstever@eecs.umich.edu build_dir = joinpath(build_root, 'libelf'), 4712638Sstever@eecs.umich.edu exports = 'env') 4722638Sstever@eecs.umich.edu 4731869SN/A################################################### 4741869SN/A# 4753546Sgblack@eecs.umich.edu# This function is used to set up a directory with switching headers 4763546Sgblack@eecs.umich.edu# 4773546Sgblack@eecs.umich.edu################################################### 4783546Sgblack@eecs.umich.edu 4793546Sgblack@eecs.umich.edudef make_switching_dir(dirname, switch_headers, env): 4803546Sgblack@eecs.umich.edu # Generate the header. target[0] is the full path of the output 4813546Sgblack@eecs.umich.edu # header to generate. 'source' is a dummy variable, since we get the 4823546Sgblack@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 4833546Sgblack@eecs.umich.edu def gen_switch_hdr(target, source, env): 4843546Sgblack@eecs.umich.edu fname = str(target[0]) 4853546Sgblack@eecs.umich.edu basename = os.path.basename(fname) 4863546Sgblack@eecs.umich.edu f = open(fname, 'w') 4873546Sgblack@eecs.umich.edu f.write('#include "arch/isa_specific.hh"\n') 4883546Sgblack@eecs.umich.edu cond = '#if' 4893546Sgblack@eecs.umich.edu for isa in env['ALL_ISA_LIST']: 4903546Sgblack@eecs.umich.edu f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 4913546Sgblack@eecs.umich.edu % (cond, isa.upper(), dirname, isa, basename)) 4923546Sgblack@eecs.umich.edu cond = '#elif' 4933546Sgblack@eecs.umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 4943546Sgblack@eecs.umich.edu f.close() 4953546Sgblack@eecs.umich.edu return 0 4963546Sgblack@eecs.umich.edu 4973546Sgblack@eecs.umich.edu # String to print when generating header 4983546Sgblack@eecs.umich.edu def gen_switch_hdr_string(target, source, env): 4993546Sgblack@eecs.umich.edu return "Generating switch header " + str(target[0]) 5003546Sgblack@eecs.umich.edu 5013546Sgblack@eecs.umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 5023546Sgblack@eecs.umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 5033546Sgblack@eecs.umich.edu # should get re-executed. 5043546Sgblack@eecs.umich.edu switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 5053546Sgblack@eecs.umich.edu varlist=['ALL_ISA_LIST']) 5063546Sgblack@eecs.umich.edu 5073546Sgblack@eecs.umich.edu # Instantiate actions for each header 5083546Sgblack@eecs.umich.edu for hdr in switch_headers: 5093546Sgblack@eecs.umich.edu env.Command(hdr, [], switch_hdr_action) 5103546Sgblack@eecs.umich.edu 5113546Sgblack@eecs.umich.eduenv.make_switching_dir = make_switching_dir 5123546Sgblack@eecs.umich.edu 5133546Sgblack@eecs.umich.edu################################################### 5143546Sgblack@eecs.umich.edu# 515955SN/A# Define build environments for selected configurations. 516955SN/A# 517955SN/A################################################### 518955SN/A 5191858SN/A# rename base env 5201858SN/Abase_env = env 5211858SN/A 5222632Sstever@eecs.umich.edufor build_path in build_paths: 5232632Sstever@eecs.umich.edu print "Building in", build_path 5242632Sstever@eecs.umich.edu # build_dir is the tail component of build path, and is used to 5252632Sstever@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 5262632Sstever@eecs.umich.edu (build_root, build_dir) = os.path.split(build_path) 5272634Sstever@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 5282638Sstever@eecs.umich.edu env = base_env.Copy() 5292023SN/A 5302632Sstever@eecs.umich.edu # Set env options according to the build directory config. 5312632Sstever@eecs.umich.edu sticky_opts.files = [] 5322632Sstever@eecs.umich.edu # Options for $BUILD_ROOT/$BUILD_DIR are stored in 5332632Sstever@eecs.umich.edu # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 5342632Sstever@eecs.umich.edu # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 5353716Sstever@eecs.umich.edu current_opts_file = joinpath(build_root, 'options', build_dir) 5362632Sstever@eecs.umich.edu if os.path.isfile(current_opts_file): 5372632Sstever@eecs.umich.edu sticky_opts.files.append(current_opts_file) 5382632Sstever@eecs.umich.edu print "Using saved options file %s" % current_opts_file 5392632Sstever@eecs.umich.edu else: 5402632Sstever@eecs.umich.edu # Build dir-specific options file doesn't exist. 5412023SN/A 5422632Sstever@eecs.umich.edu # Make sure the directory is there so we can create it later 5432632Sstever@eecs.umich.edu opt_dir = os.path.dirname(current_opts_file) 5441889SN/A if not os.path.isdir(opt_dir): 5451889SN/A os.mkdir(opt_dir) 5462632Sstever@eecs.umich.edu 5472632Sstever@eecs.umich.edu # Get default build options from source tree. Options are 5482632Sstever@eecs.umich.edu # normally determined by name of $BUILD_DIR, but can be 5492632Sstever@eecs.umich.edu # overriden by 'default=' arg on command line. 5503716Sstever@eecs.umich.edu default_opts_file = joinpath('build_opts', 5513716Sstever@eecs.umich.edu ARGUMENTS.get('default', build_dir)) 5522632Sstever@eecs.umich.edu if os.path.isfile(default_opts_file): 5532632Sstever@eecs.umich.edu sticky_opts.files.append(default_opts_file) 5542632Sstever@eecs.umich.edu print "Options file %s not found,\n using defaults in %s" \ 5552632Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 5562632Sstever@eecs.umich.edu else: 5572632Sstever@eecs.umich.edu print "Error: cannot find options file %s or %s" \ 5582632Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 5592632Sstever@eecs.umich.edu Exit(1) 5601888SN/A 5611888SN/A # Apply current option settings to env 5621869SN/A sticky_opts.Update(env) 5631869SN/A nonsticky_opts.Update(env) 5641858SN/A 5652598SN/A help_text += "Sticky options for %s:\n" % build_dir \ 5662598SN/A + sticky_opts.GenerateHelpText(env) \ 5672598SN/A + "\nNon-sticky options for %s:\n" % build_dir \ 5682598SN/A + nonsticky_opts.GenerateHelpText(env) 5692598SN/A 5701858SN/A # Process option settings. 5711858SN/A 5721858SN/A if not have_fenv and env['USE_FENV']: 5731858SN/A print "Warning: <fenv.h> not available; " \ 5741858SN/A "forcing USE_FENV to False in", build_dir + "." 5751858SN/A env['USE_FENV'] = False 5761858SN/A 5771858SN/A if not env['USE_FENV']: 5781858SN/A print "Warning: No IEEE FP rounding mode control in", build_dir + "." 5791871SN/A print " FP results may deviate slightly from other platforms." 5801858SN/A 5811858SN/A if env['EFENCE']: 5821858SN/A env.Append(LIBS=['efence']) 5831858SN/A 5841858SN/A if env['USE_MYSQL']: 5851858SN/A if not have_mysql: 5861858SN/A print "Warning: MySQL not available; " \ 5871858SN/A "forcing USE_MYSQL to False in", build_dir + "." 5881858SN/A env['USE_MYSQL'] = False 5891858SN/A else: 5901858SN/A print "Compiling in", build_dir, "with MySQL support." 5911859SN/A env.ParseConfig(mysql_config_libs) 5921859SN/A env.ParseConfig(mysql_config_include) 5931869SN/A 5941888SN/A # Save sticky option settings back to current options file 5952632Sstever@eecs.umich.edu sticky_opts.Save(current_opts_file, env) 5961869SN/A 5971884SN/A # Do this after we save setting back, or else we'll tack on an 5981884SN/A # extra 'qdo' every time we run scons. 5991884SN/A if env['BATCH']: 6001884SN/A env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 6011884SN/A env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 6021884SN/A 6031965SN/A if env['USE_SSE2']: 6041965SN/A env.Append(CCFLAGS='-msse2') 6051965SN/A 6062761Sstever@eecs.umich.edu # The src/SConscript file sets up the build rules in 'env' according 6071869SN/A # to the configured options. It returns a list of environments, 6081869SN/A # one for each variant build (debug, opt, etc.) 6092632Sstever@eecs.umich.edu envList = SConscript('src/SConscript', build_dir = build_path, 6102667Sstever@eecs.umich.edu exports = 'env') 6111869SN/A 6121869SN/A # Set up the regression tests for each build. 6132929Sktlim@umich.edu for e in envList: 6142929Sktlim@umich.edu SConscript('tests/SConscript', 6153716Sstever@eecs.umich.edu build_dir = joinpath(build_path, 'tests', e.Label), 6162929Sktlim@umich.edu exports = { 'env' : e }, duplicate = False) 617955SN/A 6182598SN/AHelp(help_text) 6192598SN/A 6203546Sgblack@eecs.umich.edu 621955SN/A################################################### 622955SN/A# 623955SN/A# Let SCons do its thing. At this point SCons will use the defined 6241530SN/A# build environments to build the requested targets. 625955SN/A# 626955SN/A################################################### 627955SN/A 628