SConstruct revision 3583
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 69955SN/A 702656Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 712656Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a 722656Sstever@eecs.umich.edu# 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) 772653Sstever@eecs.umich.edu 782653Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 792653Sstever@eecs.umich.edu# 3-element version number. 802653Sstever@eecs.umich.edumin_scons_version = (0,96,91) 812653Sstever@eecs.umich.edutry: 822653Sstever@eecs.umich.edu EnsureSConsVersion(*min_scons_version) 832653Sstever@eecs.umich.eduexcept: 842653Sstever@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 881852SN/A 89955SN/A# The absolute path to the current directory (where this file lives). 90955SN/AROOT = Dir('.').abspath 91955SN/A 922632Sstever@eecs.umich.edu# Paths to the M5 and external source trees. 932632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'src') 94955SN/A 951533SN/A# tell python where to find m5 python code 962632Sstever@eecs.umich.edusys.path.append(os.path.join(ROOT, 'src/python')) 971533SN/A 98955SN/A################################################### 99955SN/A# 1002632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 1012632Sstever@eecs.umich.edu# the target(s). 102955SN/A# 103955SN/A################################################### 104955SN/A 105955SN/A# Find default configuration & binary. 1062632Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 107955SN/A 1082632Sstever@eecs.umich.edu# Ask SCons which directory it was invoked from. 109955SN/Alaunch_dir = GetLaunchDir() 110955SN/A 1112632Sstever@eecs.umich.edu# Make targets relative to invocation directory 1122632Sstever@eecs.umich.eduabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 1132632Sstever@eecs.umich.edu BUILD_TARGETS) 1142632Sstever@eecs.umich.edu 1152632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 1162632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 1172632Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 1182632Sstever@eecs.umich.edu if l[i] == elt: 1192632Sstever@eecs.umich.edu return i 1202632Sstever@eecs.umich.edu raise ValueError, "element not found" 1212632Sstever@eecs.umich.edu 1222632Sstever@eecs.umich.edu# helper function: compare dotted version numbers. 1232632Sstever@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1') 1242632Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1252632Sstever@eecs.umich.edudef compare_versions(v1, v2): 1262632Sstever@eecs.umich.edu # Convert dotted strings to lists 1272632Sstever@eecs.umich.edu v1 = map(int, v1.split('.')) 1282634Sstever@eecs.umich.edu v2 = map(int, v2.split('.')) 1292634Sstever@eecs.umich.edu # Compare corresponding elements of lists 1302632Sstever@eecs.umich.edu for n1,n2 in zip(v1, v2): 1312638Sstever@eecs.umich.edu if n1 < n2: return -1 1322632Sstever@eecs.umich.edu if n1 > n2: return 1 1332632Sstever@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1342632Sstever@eecs.umich.edu if len(v1) < len(v2): return -1 1352632Sstever@eecs.umich.edu if len(v1) > len(v2): return 1 1362632Sstever@eecs.umich.edu return 0 1372632Sstever@eecs.umich.edu 1381858SN/A# Each target must have 'build' in the interior of the path; the 1392638Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 1402638Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1412638Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 1422638Sstever@eecs.umich.edu# follow 'build' in the bulid path. 1432638Sstever@eecs.umich.edu 1442638Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1452638Sstever@eecs.umich.edu# collected targets reference. 1462638Sstever@eecs.umich.edubuild_paths = [] 1472634Sstever@eecs.umich.edubuild_root = None 1482634Sstever@eecs.umich.edufor t in abs_targets: 1492634Sstever@eecs.umich.edu path_dirs = t.split('/') 150955SN/A try: 151955SN/A build_top = rfind(path_dirs, 'build', -2) 152955SN/A except: 153955SN/A print "Error: no non-leaf 'build' dir found on target path", t 154955SN/A Exit(1) 155955SN/A this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 156955SN/A if not build_root: 157955SN/A build_root = this_build_root 1581858SN/A else: 1591858SN/A if this_build_root != build_root: 1602632Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 161955SN/A " %s\n %s" % (build_root, this_build_root) 1622776Sstever@eecs.umich.edu Exit(1) 1631105SN/A build_path = os.path.join('/',*path_dirs[:build_top+2]) 1642667Sstever@eecs.umich.edu if build_path not in build_paths: 1652667Sstever@eecs.umich.edu build_paths.append(build_path) 1662667Sstever@eecs.umich.edu 1672667Sstever@eecs.umich.edu################################################### 1682667Sstever@eecs.umich.edu# 1692667Sstever@eecs.umich.edu# Set up the default build environment. This environment is copied 1701869SN/A# and modified according to each selected configuration. 1711869SN/A# 1721869SN/A################################################### 1731869SN/A 1741869SN/Aenv = Environment(ENV = os.environ, # inherit user's environment vars 1751065SN/A ROOT = ROOT, 1762632Sstever@eecs.umich.edu SRCDIR = SRCDIR) 1772632Sstever@eecs.umich.edu 178955SN/Aenv.SConsignFile(os.path.join(build_root,"sconsign")) 1791858SN/A 1801858SN/A# Default duplicate option is to use hard links, but this messes up 1811858SN/A# when you use emacs to edit a file in the target dir, as emacs moves 1821858SN/A# file to file~ then copies to file, breaking the link. Symbolic 1831851SN/A# (soft) links work better. 1841851SN/Aenv.SetOption('duplicate', 'soft-copy') 1851858SN/A 1862632Sstever@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but 187955SN/A# unnecessary builds, but it also seems to make trivial builds take 1882656Sstever@eecs.umich.edu# noticeably longer. 1892656Sstever@eecs.umich.eduif False: 1902656Sstever@eecs.umich.edu env.TargetSignatures('content') 1912656Sstever@eecs.umich.edu 1922656Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 1932656Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 1942656Sstever@eecs.umich.edu 1952656Sstever@eecs.umich.edu# Set up default C++ compiler flags 1962656Sstever@eecs.umich.eduenv.Append(CCFLAGS='-pipe') 1972656Sstever@eecs.umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing') 1982656Sstever@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1992656Sstever@eecs.umich.eduif sys.platform == 'cygwin': 2002656Sstever@eecs.umich.edu # cygwin has some header file issues... 2012656Sstever@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2022656Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 2032656Sstever@eecs.umich.edu 2042655Sstever@eecs.umich.edu# Check for SWIG 2052667Sstever@eecs.umich.eduif not env.has_key('SWIG'): 2062667Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 2072667Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 2082667Sstever@eecs.umich.edu Exit(1) 2092667Sstever@eecs.umich.edu 2102667Sstever@eecs.umich.edu# Check for appropriate SWIG version 2112667Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split() 2122667Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 2132667Sstever@eecs.umich.eduif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2142667Sstever@eecs.umich.edu print 'Error determining SWIG version.' 2152667Sstever@eecs.umich.edu Exit(1) 2162667Sstever@eecs.umich.edu 2172667Sstever@eecs.umich.edumin_swig_version = '1.3.28' 2182655Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 2191858SN/A print 'Error: SWIG version', min_swig_version, 'or newer required.' 2201858SN/A print ' Installed version:', swig_version[2] 2212638Sstever@eecs.umich.edu Exit(1) 2222638Sstever@eecs.umich.edu 2232638Sstever@eecs.umich.edu# Set up SWIG flags & scanner 2242638Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2252638Sstever@eecs.umich.edu 2261858SN/Aimport SCons.Scanner 2271858SN/A 2281858SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2291858SN/A 2301858SN/Aswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2311858SN/A swig_inc_re) 2321858SN/A 2331859SN/Aenv.Append(SCANNERS = swig_scanner) 2341858SN/A 2351858SN/A# Platform-specific configuration. Note again that we assume that all 2361858SN/A# builds under a given build root run on the same host platform. 2371859SN/Aconf = Configure(env, 2381859SN/A conf_dir = os.path.join(build_root, '.scons_config'), 2391862SN/A log_file = os.path.join(build_root, 'scons_config.log')) 2401862SN/A 2411862SN/A# Find Python include and library directories for embedding the 2421862SN/A# interpreter. For consistency, we will use the same Python 2431859SN/A# installation used to run scons (and thus this script). If you want 2441859SN/A# to link in an alternate version, see above for instructions on how 2451963SN/A# to invoke scons with a different copy of the Python interpreter. 2461963SN/A 2471859SN/A# Get brief Python version name (e.g., "python2.4") for locating 2481859SN/A# include & library files 2491859SN/Apy_version_name = 'python' + sys.version[:3] 2501859SN/A 2511859SN/A# include path, e.g. /usr/local/include/python2.4 2521859SN/Apy_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name) 2531859SN/Aenv.Append(CPPPATH = py_header_path) 2541859SN/A# verify that it works 2551862SN/Aif not conf.CheckHeader('Python.h', '<>'): 2561859SN/A print "Error: can't find Python.h header in", py_header_path 2571859SN/A Exit(1) 2581859SN/A 2591858SN/A# add library path too if it's not in the default place 2601858SN/Apy_lib_path = None 2612139SN/Aif sys.exec_prefix != '/usr': 2622139SN/A py_lib_path = os.path.join(sys.exec_prefix, 'lib') 2632139SN/Aelif sys.platform == 'cygwin': 2642155SN/A # cygwin puts the .dll in /bin for some reason 2652623SN/A py_lib_path = '/bin' 2662733Sktlim@umich.eduif py_lib_path: 2672733Sktlim@umich.edu env.Append(LIBPATH = py_lib_path) 2682155SN/A print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 2691869SN/Aif not conf.CheckLib(py_version_name): 2701869SN/A print "Error: can't find Python library", py_version_name 2711869SN/A Exit(1) 2721869SN/A 2731869SN/A# On Solaris you need to use libsocket for socket ops 2742139SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2751869SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2762508SN/A print "Can't find library with socket calls (e.g. accept())" 2772508SN/A Exit(1) 2782508SN/A 2792508SN/A# Check for zlib. If the check passes, libz will be automatically 2802635Sstever@eecs.umich.edu# added to the LIBS environment variable. 2812635Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 2821869SN/A print 'Error: did not find needed zlib compression library '\ 2831869SN/A 'and/or zlib.h header file.' 2841869SN/A print ' Please install zlib and try again.' 2851869SN/A Exit(1) 2861869SN/A 2871869SN/A# Check for <fenv.h> (C99 FP environment control) 2881869SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 2891869SN/Aif not have_fenv: 2901965SN/A print "Warning: Header file <fenv.h> not found." 2911965SN/A print " This host has no IEEE FP rounding mode control." 2921965SN/A 2931869SN/A# Check for mysql. 2941869SN/Amysql_config = WhereIs('mysql_config') 2952733Sktlim@umich.eduhave_mysql = mysql_config != None 2961869SN/A 2971884SN/A# Check MySQL version. 2981884SN/Aif have_mysql: 2991884SN/A mysql_version = os.popen(mysql_config + ' --version').read() 3001869SN/A min_mysql_version = '4.1' 3011858SN/A if compare_versions(mysql_version, min_mysql_version) < 0: 3021869SN/A print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3031869SN/A print ' Version', mysql_version, 'detected.' 3041869SN/A have_mysql = False 3051869SN/A 3061869SN/A# Set up mysql_config commands. 3071858SN/Aif have_mysql: 3082761Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 3091869SN/A if os.system(mysql_config_include + ' > /dev/null') != 0: 3102733Sktlim@umich.edu # older mysql_config versions don't support --include, use 3112733Sktlim@umich.edu # --cflags instead 3121869SN/A mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 3131869SN/A # This seems to work in all versions 3141869SN/A mysql_config_libs = mysql_config + ' --libs' 3151869SN/A 3161869SN/Aenv = conf.Finish() 3171869SN/A 3181858SN/A# Define the universe of supported ISAs 319955SN/Aenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 320955SN/A 3211869SN/A# Define the universe of supported CPU models 3221869SN/Aenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 3231869SN/A 'O3CPU', 'OzoneCPU'] 3241869SN/A 3251869SN/Aif os.path.isdir(os.path.join(SRCDIR, 'src/encumbered/cpu/full')): 3261869SN/A env['ALL_CPU_LIST'] += ['FullCPU'] 3271869SN/A 3281869SN/A# Sticky options get saved in the options file so they persist from 3291869SN/A# one invocation to the next (unless overridden, in which case the new 3301869SN/A# value becomes sticky). 3311869SN/Asticky_opts = Options(args=ARGUMENTS) 3321869SN/Asticky_opts.AddOptions( 3331869SN/A EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 3341869SN/A BoolOption('FULL_SYSTEM', 'Full-system support', False), 3351869SN/A # There's a bug in scons 0.96.1 that causes ListOptions with list 3361869SN/A # values (more than one value) not to be able to be restored from 3371869SN/A # a saved option file. If this causes trouble then upgrade to 3381869SN/A # scons 0.96.90 or later. 3391869SN/A ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 3401869SN/A env['ALL_CPU_LIST']), 3411869SN/A BoolOption('ALPHA_TLASER', 3421869SN/A 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 3431869SN/A BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 3441869SN/A BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 3451869SN/A False), 3461869SN/A BoolOption('SS_COMPATIBLE_FP', 3471869SN/A 'Make floating-point results compatible with SimpleScalar', 3481869SN/A False), 3491869SN/A BoolOption('USE_SSE2', 3501869SN/A 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 3511869SN/A False), 3521869SN/A BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 3531869SN/A BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 3541869SN/A BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 3551869SN/A ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3561869SN/A ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3571869SN/A BoolOption('BATCH', 'Use batch pool for build and tests', False), 3581869SN/A ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3591869SN/A ('PYTHONHOME', 3602655Sstever@eecs.umich.edu 'Override the default PYTHONHOME for this system (use with caution)', 3612655Sstever@eecs.umich.edu '%s:%s' % (sys.prefix, sys.exec_prefix)) 3622655Sstever@eecs.umich.edu ) 3632655Sstever@eecs.umich.edu 3642655Sstever@eecs.umich.edu# Non-sticky options only apply to the current build. 3652655Sstever@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS) 3662655Sstever@eecs.umich.edunonsticky_opts.AddOptions( 3672655Sstever@eecs.umich.edu BoolOption('update_ref', 'Update test reference outputs', False) 3682655Sstever@eecs.umich.edu ) 3692655Sstever@eecs.umich.edu 3702655Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript). 3712655Sstever@eecs.umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 3722655Sstever@eecs.umich.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 3732655Sstever@eecs.umich.edu 'USE_CHECKER', 'PYTHONHOME'] 3742655Sstever@eecs.umich.edu 3752655Sstever@eecs.umich.edu# Define a handy 'no-op' action 3762655Sstever@eecs.umich.edudef no_action(target, source, env): 3772655Sstever@eecs.umich.edu return 0 3782655Sstever@eecs.umich.edu 3792655Sstever@eecs.umich.eduenv.NoAction = Action(no_action, None) 3802655Sstever@eecs.umich.edu 3812655Sstever@eecs.umich.edu################################################### 3822655Sstever@eecs.umich.edu# 3832655Sstever@eecs.umich.edu# Define a SCons builder for configuration flag headers. 3842655Sstever@eecs.umich.edu# 3852655Sstever@eecs.umich.edu################################################### 3862634Sstever@eecs.umich.edu 3872634Sstever@eecs.umich.edu# This function generates a config header file that #defines the 3882634Sstever@eecs.umich.edu# option symbol to the current option setting (0 or 1). The source 3892634Sstever@eecs.umich.edu# operands are the name of the option and a Value node containing the 3902634Sstever@eecs.umich.edu# value of the option. 3912634Sstever@eecs.umich.edudef build_config_file(target, source, env): 3922638Sstever@eecs.umich.edu (option, value) = [s.get_contents() for s in source] 3932638Sstever@eecs.umich.edu f = file(str(target[0]), 'w') 3942638Sstever@eecs.umich.edu print >> f, '#define', option, value 3952638Sstever@eecs.umich.edu f.close() 3962638Sstever@eecs.umich.edu return None 3971869SN/A 3981869SN/A# Generate the message to be printed when building the config file. 399955SN/Adef build_config_file_string(target, source, env): 400955SN/A (option, value) = [s.get_contents() for s in source] 401955SN/A return "Defining %s as %s in %s." % (option, value, target[0]) 402955SN/A 4031858SN/A# Combine the two functions into a scons Action object. 4041858SN/Aconfig_action = Action(build_config_file, build_config_file_string) 4051858SN/A 4062632Sstever@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 4072632Sstever@eecs.umich.edu# we're really doing. 4082632Sstever@eecs.umich.edudef config_emitter(target, source, env): 4092632Sstever@eecs.umich.edu # extract option name from Builder arg 4102632Sstever@eecs.umich.edu option = str(target[0]) 4112634Sstever@eecs.umich.edu # True target is config header file 4122638Sstever@eecs.umich.edu target = os.path.join('config', option.lower() + '.hh') 4132023SN/A val = env[option] 4142632Sstever@eecs.umich.edu if isinstance(val, bool): 4152632Sstever@eecs.umich.edu # Force value to 0/1 4162632Sstever@eecs.umich.edu val = int(val) 4172632Sstever@eecs.umich.edu elif isinstance(val, str): 4182632Sstever@eecs.umich.edu val = '"' + val + '"' 4192632Sstever@eecs.umich.edu 4202632Sstever@eecs.umich.edu # Sources are option name & value (packaged in SCons Value nodes) 4212632Sstever@eecs.umich.edu return ([target], [Value(option), Value(val)]) 4222632Sstever@eecs.umich.edu 4232632Sstever@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 4242632Sstever@eecs.umich.edu 4252023SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 4262632Sstever@eecs.umich.edu 4272632Sstever@eecs.umich.edu################################################### 4281889SN/A# 4291889SN/A# Define a SCons builder for copying files. This is used by the 4302632Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here 4312632Sstever@eecs.umich.edu# since it's potentially more generally applicable. 4322632Sstever@eecs.umich.edu# 4332632Sstever@eecs.umich.edu################################################### 4342632Sstever@eecs.umich.edu 4352632Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 4362632Sstever@eecs.umich.edu 4372632Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 4382632Sstever@eecs.umich.edu 4392632Sstever@eecs.umich.edu################################################### 4402632Sstever@eecs.umich.edu# 4412632Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files. 4422632Sstever@eecs.umich.edu# 4432632Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable. 4441888SN/A# 4451888SN/A################################################### 4461869SN/A 4471869SN/Aconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 4481858SN/A 'chmod +x $TARGET'])) 4492598SN/A 4502598SN/Aenv.Append(BUILDERS = { 'Concat' : concat_builder }) 4512598SN/A 4522598SN/A 4532598SN/A# base help text 4541858SN/Ahelp_text = ''' 4551858SN/AUsage: scons [scons options] [build options] [target(s)] 4561858SN/A 4571858SN/A''' 4581858SN/A 4591858SN/A# libelf build is shared across all configs in the build root. 4601858SN/Aenv.SConscript('ext/libelf/SConscript', 4611858SN/A build_dir = os.path.join(build_root, 'libelf'), 4621858SN/A exports = 'env') 4631871SN/A 4641858SN/A################################################### 4651858SN/A# 4661858SN/A# This function is used to set up a directory with switching headers 4671858SN/A# 4681858SN/A################################################### 4691858SN/A 4701858SN/Adef make_switching_dir(dirname, switch_headers, env): 4711858SN/A # Generate the header. target[0] is the full path of the output 4721858SN/A # header to generate. 'source' is a dummy variable, since we get the 4731858SN/A # list of ISAs from env['ALL_ISA_LIST']. 4741858SN/A def gen_switch_hdr(target, source, env): 4751859SN/A fname = str(target[0]) 4761859SN/A basename = os.path.basename(fname) 4771869SN/A f = open(fname, 'w') 4782733Sktlim@umich.edu f.write('#include "arch/isa_specific.hh"\n') 4792733Sktlim@umich.edu cond = '#if' 4802733Sktlim@umich.edu for isa in env['ALL_ISA_LIST']: 4812733Sktlim@umich.edu f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 4821888SN/A % (cond, isa.upper(), dirname, isa, basename)) 4832632Sstever@eecs.umich.edu cond = '#elif' 4841869SN/A f.write('#else\n#error "THE_ISA not set"\n#endif\n') 4851884SN/A f.close() 4861884SN/A return 0 4871884SN/A 4881884SN/A # String to print when generating header 4891884SN/A def gen_switch_hdr_string(target, source, env): 4901884SN/A return "Generating switch header " + str(target[0]) 4911965SN/A 4921965SN/A # Build SCons Action object. 'varlist' specifies env vars that this 4931965SN/A # action depends on; when env['ALL_ISA_LIST'] changes these actions 4942761Sstever@eecs.umich.edu # should get re-executed. 4951869SN/A switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 4961869SN/A varlist=['ALL_ISA_LIST']) 4972632Sstever@eecs.umich.edu 4982667Sstever@eecs.umich.edu # Instantiate actions for each header 4991869SN/A for hdr in switch_headers: 5001869SN/A env.Command(hdr, [], switch_hdr_action) 5012632Sstever@eecs.umich.edu 5022632Sstever@eecs.umich.eduenv.make_switching_dir = make_switching_dir 5032632Sstever@eecs.umich.edu 5042632Sstever@eecs.umich.edu################################################### 505955SN/A# 5062598SN/A# Define build environments for selected configurations. 5072598SN/A# 508955SN/A################################################### 509955SN/A 510955SN/A# rename base env 5111530SN/Abase_env = env 512955SN/A 513955SN/Afor build_path in build_paths: 514955SN/A print "Building in", build_path 515 # build_dir is the tail component of build path, and is used to 516 # determine the build parameters (e.g., 'ALPHA_SE') 517 (build_root, build_dir) = os.path.split(build_path) 518 # Make a copy of the build-root environment to use for this config. 519 env = base_env.Copy() 520 521 # Set env options according to the build directory config. 522 sticky_opts.files = [] 523 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 524 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 525 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 526 current_opts_file = os.path.join(build_root, 'options', build_dir) 527 if os.path.isfile(current_opts_file): 528 sticky_opts.files.append(current_opts_file) 529 print "Using saved options file %s" % current_opts_file 530 else: 531 # Build dir-specific options file doesn't exist. 532 533 # Make sure the directory is there so we can create it later 534 opt_dir = os.path.dirname(current_opts_file) 535 if not os.path.isdir(opt_dir): 536 os.mkdir(opt_dir) 537 538 # Get default build options from source tree. Options are 539 # normally determined by name of $BUILD_DIR, but can be 540 # overriden by 'default=' arg on command line. 541 default_opts_file = os.path.join('build_opts', 542 ARGUMENTS.get('default', build_dir)) 543 if os.path.isfile(default_opts_file): 544 sticky_opts.files.append(default_opts_file) 545 print "Options file %s not found,\n using defaults in %s" \ 546 % (current_opts_file, default_opts_file) 547 else: 548 print "Error: cannot find options file %s or %s" \ 549 % (current_opts_file, default_opts_file) 550 Exit(1) 551 552 # Apply current option settings to env 553 sticky_opts.Update(env) 554 nonsticky_opts.Update(env) 555 556 help_text += "Sticky options for %s:\n" % build_dir \ 557 + sticky_opts.GenerateHelpText(env) \ 558 + "\nNon-sticky options for %s:\n" % build_dir \ 559 + nonsticky_opts.GenerateHelpText(env) 560 561 # Process option settings. 562 563 if not have_fenv and env['USE_FENV']: 564 print "Warning: <fenv.h> not available; " \ 565 "forcing USE_FENV to False in", build_dir + "." 566 env['USE_FENV'] = False 567 568 if not env['USE_FENV']: 569 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 570 print " FP results may deviate slightly from other platforms." 571 572 if env['EFENCE']: 573 env.Append(LIBS=['efence']) 574 575 if env['USE_MYSQL']: 576 if not have_mysql: 577 print "Warning: MySQL not available; " \ 578 "forcing USE_MYSQL to False in", build_dir + "." 579 env['USE_MYSQL'] = False 580 else: 581 print "Compiling in", build_dir, "with MySQL support." 582 env.ParseConfig(mysql_config_libs) 583 env.ParseConfig(mysql_config_include) 584 585 # Save sticky option settings back to current options file 586 sticky_opts.Save(current_opts_file, env) 587 588 # Do this after we save setting back, or else we'll tack on an 589 # extra 'qdo' every time we run scons. 590 if env['BATCH']: 591 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 592 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 593 594 if env['USE_SSE2']: 595 env.Append(CCFLAGS='-msse2') 596 597 # The src/SConscript file sets up the build rules in 'env' according 598 # to the configured options. It returns a list of environments, 599 # one for each variant build (debug, opt, etc.) 600 envList = SConscript('src/SConscript', build_dir = build_path, 601 exports = 'env') 602 603 # Set up the regression tests for each build. 604 for e in envList: 605 SConscript('tests/SConscript', 606 build_dir = os.path.join(build_path, 'tests', e.Label), 607 exports = { 'env' : e }, duplicate = False) 608 609Help(help_text) 610 611 612################################################### 613# 614# Let SCons do its thing. At this point SCons will use the defined 615# build environments to build the requested targets. 616# 617################################################### 618 619