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 422632Sstever@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: 462632Sstever@eecs.umich.edu# 472632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 482632Sstever@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 512632Sstever@eecs.umich.edu# 522632Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 532632Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 542632Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 552632Sstever@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 60955SN/A# 'm5' directory (or use -u or -C to tell scons where to find this 61955SN/A# file), you can use 'scons -h' to print all the M5-specific build 62955SN/A# options as well. 63955SN/A# 64955SN/A################################################### 65955SN/A 66955SN/A# Python library imports 672656Sstever@eecs.umich.eduimport sys 682656Sstever@eecs.umich.eduimport os 692656Sstever@eecs.umich.edufrom os.path import join as joinpath 702656Sstever@eecs.umich.edu 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) 742653Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 752653Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 762653Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 772653Sstever@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: 851852SN/A print "Error checking current SCons version." 86955SN/A print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 87955SN/A Exit(2) 88955SN/A 892632Sstever@eecs.umich.edu 902632Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives). 91955SN/AROOT = Dir('.').abspath 921533SN/A 932632Sstever@eecs.umich.edu# Path to the M5 source tree. 941533SN/ASRCDIR = joinpath(ROOT, 'src') 95955SN/A 96955SN/A# tell python where to find m5 python code 972632Sstever@eecs.umich.edusys.path.append(joinpath(ROOT, 'src/python')) 982632Sstever@eecs.umich.edu 99955SN/A################################################### 100955SN/A# 101955SN/A# Figure out which configurations to set up based on the path(s) of 102955SN/A# the target(s). 1032632Sstever@eecs.umich.edu# 104955SN/A################################################### 1052632Sstever@eecs.umich.edu 106955SN/A# Find default configuration & binary. 107955SN/ADefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1082632Sstever@eecs.umich.edu 1092632Sstever@eecs.umich.edu# Ask SCons which directory it was invoked from. 1102632Sstever@eecs.umich.edulaunch_dir = GetLaunchDir() 1112632Sstever@eecs.umich.edu 1122632Sstever@eecs.umich.edu# Make targets relative to invocation directory 1132632Sstever@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 1232632Sstever@eecs.umich.edu# helper function: compare dotted version numbers. 1242632Sstever@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1') 1252634Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1262634Sstever@eecs.umich.edudef compare_versions(v1, v2): 1272632Sstever@eecs.umich.edu # Convert dotted strings to lists 1282638Sstever@eecs.umich.edu v1 = map(int, v1.split('.')) 1292632Sstever@eecs.umich.edu v2 = map(int, v2.split('.')) 1302632Sstever@eecs.umich.edu # Compare corresponding elements of lists 1312632Sstever@eecs.umich.edu for n1,n2 in zip(v1, v2): 1322632Sstever@eecs.umich.edu if n1 < n2: return -1 1332632Sstever@eecs.umich.edu if n1 > n2: return 1 1342632Sstever@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1351858SN/A if len(v1) < len(v2): return -1 1362638Sstever@eecs.umich.edu if len(v1) > len(v2): return 1 1372638Sstever@eecs.umich.edu return 0 1382638Sstever@eecs.umich.edu 1392638Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 1402638Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 1412638Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1422638Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 1432638Sstever@eecs.umich.edu# follow 'build' in the bulid path. 1442634Sstever@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. 147955SN/Abuild_paths = [] 148955SN/Abuild_root = None 149955SN/Afor t in abs_targets: 150955SN/A path_dirs = t.split('/') 151955SN/A try: 152955SN/A build_top = rfind(path_dirs, 'build', -2) 153955SN/A except: 154955SN/A print "Error: no non-leaf 'build' dir found on target path", t 1551858SN/A Exit(1) 1561858SN/A this_build_root = joinpath('/',*path_dirs[:build_top+1]) 1572632Sstever@eecs.umich.edu if not build_root: 158955SN/A build_root = this_build_root 1591858SN/A else: 1601105SN/A if this_build_root != build_root: 1612667Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 1622667Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1632667Sstever@eecs.umich.edu Exit(1) 1642667Sstever@eecs.umich.edu build_path = joinpath('/',*path_dirs[:build_top+2]) 1652667Sstever@eecs.umich.edu if build_path not in build_paths: 1662667Sstever@eecs.umich.edu build_paths.append(build_path) 1671869SN/A 1681869SN/A################################################### 1691869SN/A# 1701869SN/A# Set up the default build environment. This environment is copied 1711869SN/A# and modified according to each selected configuration. 1721065SN/A# 1732632Sstever@eecs.umich.edu################################################### 1742632Sstever@eecs.umich.edu 175955SN/Aenv = Environment(ENV = os.environ, # inherit user's environment vars 1761858SN/A ROOT = ROOT, 1771858SN/A SRCDIR = SRCDIR) 1781858SN/A 1791858SN/A#Parse CC/CXX early so that we use the correct compiler for 1801851SN/A# to test for dependencies/versions/libraries/includes 1811851SN/Aif ARGUMENTS.get('CC', None): 1821858SN/A env['CC'] = ARGUMENTS.get('CC') 1832632Sstever@eecs.umich.edu 184955SN/Aif ARGUMENTS.get('CXX', None): 1852656Sstever@eecs.umich.edu env['CXX'] = ARGUMENTS.get('CXX') 1862656Sstever@eecs.umich.edu 1872656Sstever@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign")) 1882656Sstever@eecs.umich.edu 1892656Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 1902656Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 1912656Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 1922656Sstever@eecs.umich.edu# (soft) links work better. 1932656Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 1942656Sstever@eecs.umich.edu 1952656Sstever@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but 1962656Sstever@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 1972656Sstever@eecs.umich.edu# noticeably longer. 1982656Sstever@eecs.umich.eduif False: 1992656Sstever@eecs.umich.edu env.TargetSignatures('content') 2002656Sstever@eecs.umich.edu 2012655Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 2022667Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 2032667Sstever@eecs.umich.edu 2042667Sstever@eecs.umich.edu# Set up default C++ compiler flags 2052667Sstever@eecs.umich.eduenv.Append(CCFLAGS='-pipe') 2062667Sstever@eecs.umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing') 2072667Sstever@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2082667Sstever@eecs.umich.eduif sys.platform == 'cygwin': 2092667Sstever@eecs.umich.edu # cygwin has some header file issues... 2102667Sstever@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2112667Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 2122667Sstever@eecs.umich.edu 2132667Sstever@eecs.umich.edu# Check for SWIG 2142667Sstever@eecs.umich.eduif not env.has_key('SWIG'): 2152655Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 2161858SN/A print ' Please install (see http://www.swig.org) and retry.' 2171858SN/A Exit(1) 2182638Sstever@eecs.umich.edu 2192638Sstever@eecs.umich.edu# Check for appropriate SWIG version 2202638Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split() 2212638Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 2222638Sstever@eecs.umich.eduif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2231858SN/A print 'Error determining SWIG version.' 2241858SN/A Exit(1) 2251858SN/A 2261858SN/Amin_swig_version = '1.3.28' 2271858SN/Aif compare_versions(swig_version[2], min_swig_version) < 0: 2281858SN/A print 'Error: SWIG version', min_swig_version, 'or newer required.' 2291858SN/A print ' Installed version:', swig_version[2] 2301859SN/A Exit(1) 2311858SN/A 2321858SN/A# Set up SWIG flags & scanner 2331858SN/Aenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2341859SN/A 2351859SN/Aimport SCons.Scanner 2361862SN/A 2371862SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2381862SN/A 2391862SN/Aswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2401859SN/A swig_inc_re) 2411859SN/A 2421963SN/Aenv.Append(SCANNERS = swig_scanner) 2431963SN/A 2441859SN/A# Platform-specific configuration. Note again that we assume that all 2451859SN/A# builds under a given build root run on the same host platform. 2461859SN/Aconf = Configure(env, 2471859SN/A conf_dir = joinpath(build_root, '.scons_config'), 2481859SN/A log_file = joinpath(build_root, 'scons_config.log')) 2491859SN/A 2501859SN/A# Find Python include and library directories for embedding the 2511859SN/A# interpreter. For consistency, we will use the same Python 2521862SN/A# installation used to run scons (and thus this script). If you want 2531859SN/A# to link in an alternate version, see above for instructions on how 2541859SN/A# to invoke scons with a different copy of the Python interpreter. 2551859SN/A 2561858SN/A# Get brief Python version name (e.g., "python2.4") for locating 2571858SN/A# include & library files 2582139SN/Apy_version_name = 'python' + sys.version[:3] 2592139SN/A 2602139SN/A# include path, e.g. /usr/local/include/python2.4 2612155SN/Apy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 2622623SN/Aenv.Append(CPPPATH = py_header_path) 2632733Sktlim@umich.edu# verify that it works 2642733Sktlim@umich.eduif not conf.CheckHeader('Python.h', '<>'): 2652155SN/A print "Error: can't find Python.h header in", py_header_path 2661869SN/A Exit(1) 2671869SN/A 2681869SN/A# add library path too if it's not in the default place 2691869SN/Apy_lib_path = None 2701869SN/Aif sys.exec_prefix != '/usr': 2712139SN/A py_lib_path = joinpath(sys.exec_prefix, 'lib') 2721869SN/Aelif sys.platform == 'cygwin': 2732508SN/A # cygwin puts the .dll in /bin for some reason 2742508SN/A py_lib_path = '/bin' 2752508SN/Aif py_lib_path: 2762508SN/A env.Append(LIBPATH = py_lib_path) 2772635Sstever@eecs.umich.edu print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 2782635Sstever@eecs.umich.eduif not conf.CheckLib(py_version_name): 2791869SN/A print "Error: can't find Python library", py_version_name 2801869SN/A Exit(1) 2811869SN/A 2821869SN/A# On Solaris you need to use libsocket for socket ops 2831869SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2841869SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2851869SN/A print "Can't find library with socket calls (e.g. accept())" 2861869SN/A Exit(1) 2871965SN/A 2881965SN/A# Check for zlib. If the check passes, libz will be automatically 2891965SN/A# added to the LIBS environment variable. 2901869SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 2911869SN/A print 'Error: did not find needed zlib compression library '\ 2922733Sktlim@umich.edu 'and/or zlib.h header file.' 2931869SN/A print ' Please install zlib and try again.' 2941884SN/A Exit(1) 2951884SN/A 2961884SN/A# Check for <fenv.h> (C99 FP environment control) 2971869SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 2981858SN/Aif not have_fenv: 2991869SN/A print "Warning: Header file <fenv.h> not found." 3001869SN/A print " This host has no IEEE FP rounding mode control." 3011869SN/A 3021869SN/A# Check for mysql. 3031869SN/Amysql_config = WhereIs('mysql_config') 3041858SN/Ahave_mysql = mysql_config != None 3051869SN/A 3061869SN/A# Check MySQL version. 3072733Sktlim@umich.eduif have_mysql: 3082733Sktlim@umich.edu mysql_version = os.popen(mysql_config + ' --version').read() 3091869SN/A min_mysql_version = '4.1' 3101869SN/A if compare_versions(mysql_version, min_mysql_version) < 0: 3111869SN/A print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3121869SN/A print ' Version', mysql_version, 'detected.' 3131869SN/A have_mysql = False 3141869SN/A 3151858SN/A# Set up mysql_config commands. 316955SN/Aif have_mysql: 317955SN/A mysql_config_include = mysql_config + ' --include' 3181869SN/A if os.system(mysql_config_include + ' > /dev/null') != 0: 3191869SN/A # older mysql_config versions don't support --include, use 3201869SN/A # --cflags instead 3211869SN/A mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 3221869SN/A # This seems to work in all versions 3231869SN/A mysql_config_libs = mysql_config + ' --libs' 3241869SN/A 3251869SN/Aenv = conf.Finish() 3261869SN/A 3271869SN/A# Define the universe of supported ISAs 3281869SN/Aenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 3291869SN/A 3301869SN/A# Define the universe of supported CPU models 3311869SN/Aenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 3321869SN/A 'O3CPU', 'OzoneCPU'] 3331869SN/A 3341869SN/Aif os.path.isdir(joinpath(SRCDIR, 'encumbered/cpu/full')): 3351869SN/A env['ALL_CPU_LIST'] += ['FullCPU'] 3361869SN/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( 3421869SN/A EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 3431869SN/A BoolOption('FULL_SYSTEM', 'Full-system support', False), 3441869SN/A # There's a bug in scons 0.96.1 that causes ListOptions with list 3451869SN/A # values (more than one value) not to be able to be restored from 3461869SN/A # a saved option file. If this causes trouble then upgrade to 3471869SN/A # scons 0.96.90 or later. 3481869SN/A ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU,O3CPU', 3491869SN/A 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', 3572655Sstever@eecs.umich.edu False), 3582655Sstever@eecs.umich.edu BoolOption('USE_SSE2', 3592655Sstever@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 3602655Sstever@eecs.umich.edu False), 3612655Sstever@eecs.umich.edu BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 3622655Sstever@eecs.umich.edu BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 3632655Sstever@eecs.umich.edu BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 3642655Sstever@eecs.umich.edu ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3652655Sstever@eecs.umich.edu ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3662655Sstever@eecs.umich.edu BoolOption('BATCH', 'Use batch pool for build and tests', False), 3672655Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3682655Sstever@eecs.umich.edu ('PYTHONHOME', 3692655Sstever@eecs.umich.edu 'Override the default PYTHONHOME for this system (use with caution)', 3702655Sstever@eecs.umich.edu '%s:%s' % (sys.prefix, sys.exec_prefix)) 3712655Sstever@eecs.umich.edu ) 3722655Sstever@eecs.umich.edu 3732655Sstever@eecs.umich.edu# Non-sticky options only apply to the current build. 3742655Sstever@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS) 3752655Sstever@eecs.umich.edunonsticky_opts.AddOptions( 3762655Sstever@eecs.umich.edu BoolOption('update_ref', 'Update test reference outputs', False) 3772655Sstever@eecs.umich.edu ) 3782655Sstever@eecs.umich.edu 3792655Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript). 3802655Sstever@eecs.umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 3812655Sstever@eecs.umich.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 3822655Sstever@eecs.umich.edu 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 3832634Sstever@eecs.umich.edu 3842634Sstever@eecs.umich.edu# Define a handy 'no-op' action 3852634Sstever@eecs.umich.edudef no_action(target, source, env): 3862634Sstever@eecs.umich.edu return 0 3872634Sstever@eecs.umich.edu 3882634Sstever@eecs.umich.eduenv.NoAction = Action(no_action, None) 3892638Sstever@eecs.umich.edu 3902638Sstever@eecs.umich.edu################################################### 3912638Sstever@eecs.umich.edu# 3922638Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers. 3932638Sstever@eecs.umich.edu# 3941869SN/A################################################### 3951869SN/A 396955SN/A# This function generates a config header file that #defines the 397955SN/A# option symbol to the current option setting (0 or 1). The source 398955SN/A# operands are the name of the option and a Value node containing the 399955SN/A# value of the option. 4001858SN/Adef build_config_file(target, source, env): 4011858SN/A (option, value) = [s.get_contents() for s in source] 4021858SN/A f = file(str(target[0]), 'w') 4032632Sstever@eecs.umich.edu print >> f, '#define', option, value 4042632Sstever@eecs.umich.edu f.close() 4052632Sstever@eecs.umich.edu return None 4062632Sstever@eecs.umich.edu 4072632Sstever@eecs.umich.edu# Generate the message to be printed when building the config file. 4082634Sstever@eecs.umich.edudef build_config_file_string(target, source, env): 4092638Sstever@eecs.umich.edu (option, value) = [s.get_contents() for s in source] 4102023SN/A return "Defining %s as %s in %s." % (option, value, target[0]) 4112632Sstever@eecs.umich.edu 4122632Sstever@eecs.umich.edu# Combine the two functions into a scons Action object. 4132632Sstever@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string) 4142632Sstever@eecs.umich.edu 4152632Sstever@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 4162632Sstever@eecs.umich.edu# we're really doing. 4172632Sstever@eecs.umich.edudef config_emitter(target, source, env): 4182632Sstever@eecs.umich.edu # extract option name from Builder arg 4192632Sstever@eecs.umich.edu option = str(target[0]) 4202632Sstever@eecs.umich.edu # True target is config header file 4212632Sstever@eecs.umich.edu target = joinpath('config', option.lower() + '.hh') 4222023SN/A val = env[option] 4232632Sstever@eecs.umich.edu if isinstance(val, bool): 4242632Sstever@eecs.umich.edu # Force value to 0/1 4251889SN/A val = int(val) 4261889SN/A elif isinstance(val, str): 4272632Sstever@eecs.umich.edu val = '"' + val + '"' 4282632Sstever@eecs.umich.edu 4292632Sstever@eecs.umich.edu # Sources are option name & value (packaged in SCons Value nodes) 4302632Sstever@eecs.umich.edu return ([target], [Value(option), Value(val)]) 4312632Sstever@eecs.umich.edu 4322632Sstever@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 4332632Sstever@eecs.umich.edu 4342632Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 4352632Sstever@eecs.umich.edu 4362632Sstever@eecs.umich.edu################################################### 4372632Sstever@eecs.umich.edu# 4382632Sstever@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 4392632Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here 4402632Sstever@eecs.umich.edu# since it's potentially more generally applicable. 4411888SN/A# 4421888SN/A################################################### 4431869SN/A 4441869SN/Acopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 4451858SN/A 4462598SN/Aenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 4472598SN/A 4482598SN/A################################################### 4492598SN/A# 4502598SN/A# Define a simple SCons builder to concatenate files. 4511858SN/A# 4521858SN/A# Used to append the Python zip archive to the executable. 4531858SN/A# 4541858SN/A################################################### 4551858SN/A 4561858SN/Aconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 4571858SN/A 'chmod +x $TARGET'])) 4581858SN/A 4591858SN/Aenv.Append(BUILDERS = { 'Concat' : concat_builder }) 4601871SN/A 4611858SN/A 4621858SN/A# base help text 4631858SN/Ahelp_text = ''' 4641858SN/AUsage: scons [scons options] [build options] [target(s)] 4651858SN/A 4661858SN/A''' 4671858SN/A 4681858SN/A# libelf build is shared across all configs in the build root. 4691858SN/Aenv.SConscript('ext/libelf/SConscript', 4701858SN/A build_dir = joinpath(build_root, 'libelf'), 4711858SN/A exports = 'env') 4721859SN/A 4731859SN/A################################################### 4741869SN/A# 4752733Sktlim@umich.edu# This function is used to set up a directory with switching headers 4762733Sktlim@umich.edu# 4772733Sktlim@umich.edu################################################### 4782733Sktlim@umich.edu 4791888SN/Adef make_switching_dir(dirname, switch_headers, env): 4802632Sstever@eecs.umich.edu # Generate the header. target[0] is the full path of the output 4811869SN/A # header to generate. 'source' is a dummy variable, since we get the 4821884SN/A # list of ISAs from env['ALL_ISA_LIST']. 4831884SN/A def gen_switch_hdr(target, source, env): 4841884SN/A fname = str(target[0]) 4851884SN/A basename = os.path.basename(fname) 4861884SN/A f = open(fname, 'w') 4871884SN/A f.write('#include "arch/isa_specific.hh"\n') 4881965SN/A cond = '#if' 4891965SN/A for isa in env['ALL_ISA_LIST']: 4901965SN/A f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 491955SN/A % (cond, isa.upper(), dirname, isa, basename)) 4921869SN/A cond = '#elif' 4931869SN/A f.write('#else\n#error "THE_ISA not set"\n#endif\n') 4942632Sstever@eecs.umich.edu f.close() 4952667Sstever@eecs.umich.edu return 0 4961869SN/A 4971869SN/A # String to print when generating header 4982632Sstever@eecs.umich.edu def gen_switch_hdr_string(target, source, env): 4992632Sstever@eecs.umich.edu return "Generating switch header " + str(target[0]) 5002632Sstever@eecs.umich.edu 5012632Sstever@eecs.umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 502955SN/A # action depends on; when env['ALL_ISA_LIST'] changes these actions 5032598SN/A # should get re-executed. 5042598SN/A switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 505955SN/A varlist=['ALL_ISA_LIST']) 506955SN/A 507955SN/A # Instantiate actions for each header 5081530SN/A for hdr in switch_headers: 509955SN/A env.Command(hdr, [], switch_hdr_action) 510955SN/A 511955SN/Aenv.make_switching_dir = make_switching_dir 512 513################################################### 514# 515# Define build environments for selected configurations. 516# 517################################################### 518 519# rename base env 520base_env = env 521 522for build_path in build_paths: 523 print "Building in", build_path 524 # build_dir is the tail component of build path, and is used to 525 # determine the build parameters (e.g., 'ALPHA_SE') 526 (build_root, build_dir) = os.path.split(build_path) 527 # Make a copy of the build-root environment to use for this config. 528 env = base_env.Copy() 529 530 # Set env options according to the build directory config. 531 sticky_opts.files = [] 532 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 533 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 534 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 535 current_opts_file = joinpath(build_root, 'options', build_dir) 536 if os.path.isfile(current_opts_file): 537 sticky_opts.files.append(current_opts_file) 538 print "Using saved options file %s" % current_opts_file 539 else: 540 # Build dir-specific options file doesn't exist. 541 542 # Make sure the directory is there so we can create it later 543 opt_dir = os.path.dirname(current_opts_file) 544 if not os.path.isdir(opt_dir): 545 os.mkdir(opt_dir) 546 547 # Get default build options from source tree. Options are 548 # normally determined by name of $BUILD_DIR, but can be 549 # overriden by 'default=' arg on command line. 550 default_opts_file = joinpath('build_opts', 551 ARGUMENTS.get('default', build_dir)) 552 if os.path.isfile(default_opts_file): 553 sticky_opts.files.append(default_opts_file) 554 print "Options file %s not found,\n using defaults in %s" \ 555 % (current_opts_file, default_opts_file) 556 else: 557 print "Error: cannot find options file %s or %s" \ 558 % (current_opts_file, default_opts_file) 559 Exit(1) 560 561 # Apply current option settings to env 562 sticky_opts.Update(env) 563 nonsticky_opts.Update(env) 564 565 help_text += "Sticky options for %s:\n" % build_dir \ 566 + sticky_opts.GenerateHelpText(env) \ 567 + "\nNon-sticky options for %s:\n" % build_dir \ 568 + nonsticky_opts.GenerateHelpText(env) 569 570 # Process option settings. 571 572 if not have_fenv and env['USE_FENV']: 573 print "Warning: <fenv.h> not available; " \ 574 "forcing USE_FENV to False in", build_dir + "." 575 env['USE_FENV'] = False 576 577 if not env['USE_FENV']: 578 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 579 print " FP results may deviate slightly from other platforms." 580 581 if env['EFENCE']: 582 env.Append(LIBS=['efence']) 583 584 if env['USE_MYSQL']: 585 if not have_mysql: 586 print "Warning: MySQL not available; " \ 587 "forcing USE_MYSQL to False in", build_dir + "." 588 env['USE_MYSQL'] = False 589 else: 590 print "Compiling in", build_dir, "with MySQL support." 591 env.ParseConfig(mysql_config_libs) 592 env.ParseConfig(mysql_config_include) 593 594 # Save sticky option settings back to current options file 595 sticky_opts.Save(current_opts_file, env) 596 597 # Do this after we save setting back, or else we'll tack on an 598 # extra 'qdo' every time we run scons. 599 if env['BATCH']: 600 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 601 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 602 603 if env['USE_SSE2']: 604 env.Append(CCFLAGS='-msse2') 605 606 # The src/SConscript file sets up the build rules in 'env' according 607 # to the configured options. It returns a list of environments, 608 # one for each variant build (debug, opt, etc.) 609 envList = SConscript('src/SConscript', build_dir = build_path, 610 exports = 'env') 611 612 # Set up the regression tests for each build. 613 for e in envList: 614 SConscript('tests/SConscript', 615 build_dir = joinpath(build_path, 'tests', e.Label), 616 exports = { 'env' : e }, duplicate = False) 617 618Help(help_text) 619 620 621################################################### 622# 623# Let SCons do its thing. At this point SCons will use the defined 624# build environments to build the requested targets. 625# 626################################################### 627 628