SConstruct revision 3483
12968SN/A# -*- mode:python -*- 22968SN/A 32968SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 49988Snilay@cs.wisc.edu# All rights reserved. 58835SAli.Saidi@ARM.com# 69988Snilay@cs.wisc.edu# Redistribution and use in source and binary forms, with or without 77935SN/A# modification, are permitted provided that the following conditions are 87935SN/A# met: redistributions of source code must retain the above copyright 97935SN/A# notice, this list of conditions and the following disclaimer; 102968SN/A# redistributions in binary form must reproduce the above copyright 112968SN/A# notice, this list of conditions and the following disclaimer in the 122968SN/A# documentation and/or other materials provided with the distribution; 139885Sstever@gmail.com# neither the name of the copyright holders nor the names of its 144463SN/A# contributors may be used to endorse or promote products derived from 152968SN/A# this software without specific prior written permission. 169885Sstever@gmail.com# 179885Sstever@gmail.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1810036SAli.Saidi@ARM.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 199988Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202968SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2110036SAli.Saidi@ARM.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 227670SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232968SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 249481Snilay@cs.wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 258721SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 268721SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2710036SAli.Saidi@ARM.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 283006SN/A# 293140SN/A# Authors: Steve Reinhardt 302968SN/A 312968SN/A################################################### 327935SN/A# 337935SN/A# SCons top-level build description (SConstruct) file. 347935SN/A# 357935SN/A# While in this directory ('m5'), just type 'scons' to build the default 367935SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 377935SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 387935SN/A# the optimized full-system version). 398983Snate@binkert.org# 402968SN/A# You can build M5 in a different directory as long as there is a 412968SN/A# 'build/<CONFIG>' somewhere along the target path. The build system 422968SN/A# expects that all configs under the same build directory are being 439885Sstever@gmail.com# built for the same host system. 444463SN/A# 459988Snilay@cs.wisc.edu# Examples: 468721SN/A# 478721SN/A# The following two commands are equivalent. The '-u' option tells 488721SN/A# scons to search up the directory tree for this SConstruct file. 498983Snate@binkert.org# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 508983Snate@binkert.org# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512968SN/A# 529885Sstever@gmail.com# The following two commands are equivalent and demonstrate building 539885Sstever@gmail.com# in a directory outside of the source tree. The '-C' option tells 549885Sstever@gmail.com# scons to chdir to the specified directory to find this SConstruct 559988Snilay@cs.wisc.edu# file. 569885Sstever@gmail.com# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 579885Sstever@gmail.com# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 582968SN/A# 592968SN/A# You can use 'scons -H' to print scons options. If you're in this 609481Snilay@cs.wisc.edu# 'm5' directory (or use -u or -C to tell scons where to find this 615876SN/A# file), you can use 'scons -h' to print all the M5-specific build 629885Sstever@gmail.com# options as well. 633171SN/A# 643638SN/A################################################### 653638SN/A 663638SN/A# Python library imports 672968SN/Aimport sys 689988Snilay@cs.wisc.eduimport os 698983Snate@binkert.org 702968SN/A# Check for recent-enough Python and SCons versions. If your system's 712968SN/A# default installation of Python is not recent enough, you can use a 725723SN/A# non-default installation of the Python interpreter by either (1) 739481Snilay@cs.wisc.edu# rearranging your PATH so that scons finds the non-default 'python' 742968SN/A# first or (2) explicitly invoking an alternative interpreter on the 752968SN/A# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 762968SN/AEnsurePythonVersion(2,4) 772968SN/A 782968SN/A# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 795575SN/A# 3-element version number. 802968SN/Amin_scons_version = (0,96,91) 813140SN/Atry: 829885Sstever@gmail.com EnsureSConsVersion(*min_scons_version) 839885Sstever@gmail.comexcept: 849885Sstever@gmail.com print "Error checking current SCons version." 859885Sstever@gmail.com print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 865509SN/A Exit(2) 875509SN/A 889481Snilay@cs.wisc.edu 892968SN/A# The absolute path to the current directory (where this file lives). 904938SN/AROOT = Dir('.').abspath 912968SN/A 928835SAli.Saidi@ARM.com# Paths to the M5 and external source trees. 934463SN/ASRCDIR = os.path.join(ROOT, 'src') 944463SN/A 954463SN/A# tell python where to find m5 python code 964463SN/Asys.path.append(os.path.join(ROOT, 'src/python')) 974463SN/A 989885Sstever@gmail.com################################################### 998983Snate@binkert.org# 1004463SN/A# Figure out which configurations to set up based on the path(s) of 1019885Sstever@gmail.com# the target(s). 1029988Snilay@cs.wisc.edu# 1036123SN/A################################################### 1049481Snilay@cs.wisc.edu 1058241SN/A# Find default configuration & binary. 1064463SN/ADefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1074463SN/A 1085876SN/A# Ask SCons which directory it was invoked from. 1098835SAli.Saidi@ARM.comlaunch_dir = GetLaunchDir() 1109481Snilay@cs.wisc.edu 11110036SAli.Saidi@ARM.com# Make targets relative to invocation directory 1124463SN/Aabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 1138835SAli.Saidi@ARM.com BUILD_TARGETS) 1149885Sstever@gmail.com 1159481Snilay@cs.wisc.edu# helper function: find last occurrence of element in list 1164463SN/Adef rfind(l, elt, offs = -1): 1174463SN/A for i in range(len(l)+offs, 0, -1): 1184463SN/A if l[i] == elt: 1199481Snilay@cs.wisc.edu return i 1204463SN/A raise ValueError, "element not found" 1219885Sstever@gmail.com 1229885Sstever@gmail.com# helper function: compare dotted version numbers. 1239885Sstever@gmail.com# E.g., compare_version('1.3.25', '1.4.1') 1249885Sstever@gmail.com# returns -1, 0, 1 if v1 is <, ==, > v2 1259885Sstever@gmail.comdef compare_versions(v1, v2): 1269988Snilay@cs.wisc.edu # Convert dotted strings to lists 1279885Sstever@gmail.com v1 = map(int, v1.split('.')) 12810036SAli.Saidi@ARM.com v2 = map(int, v2.split('.')) 1299885Sstever@gmail.com # Compare corresponding elements of lists 1309885Sstever@gmail.com for n1,n2 in zip(v1, v2): 1312968SN/A if n1 < n2: return -1 1326024SN/A if n1 > n2: return 1 1339988Snilay@cs.wisc.edu # all corresponding values are equal... see if one has extra values 1342968SN/A if len(v1) < len(v2): return -1 1352968SN/A if len(v1) > len(v2): return 1 1364463SN/A return 0 1374463SN/A 1389885Sstever@gmail.com# Each target must have 'build' in the interior of the path; the 1398983Snate@binkert.org# directory below this will determine the build parameters. For 1404463SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1419885Sstever@gmail.com# recognize that ALPHA_SE specifies the configuration because it 1429988Snilay@cs.wisc.edu# follow 'build' in the bulid path. 1436123SN/A 1449481Snilay@cs.wisc.edu# Generate a list of the unique build roots and configs that the 1458241SN/A# collected targets reference. 1464463SN/Abuild_paths = [] 1474463SN/Abuild_root = None 1485876SN/Afor t in abs_targets: 1498835SAli.Saidi@ARM.com path_dirs = t.split('/') 1509481Snilay@cs.wisc.edu try: 15110036SAli.Saidi@ARM.com build_top = rfind(path_dirs, 'build', -2) 1524463SN/A except: 1538835SAli.Saidi@ARM.com print "Error: no non-leaf 'build' dir found on target path", t 1549885Sstever@gmail.com Exit(1) 1559481Snilay@cs.wisc.edu this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1564463SN/A if not build_root: 1574463SN/A build_root = this_build_root 1584463SN/A else: 1599481Snilay@cs.wisc.edu if this_build_root != build_root: 1604463SN/A print "Error: build targets not under same build root\n"\ 1619885Sstever@gmail.com " %s\n %s" % (build_root, this_build_root) 1629885Sstever@gmail.com Exit(1) 1639885Sstever@gmail.com build_path = os.path.join('/',*path_dirs[:build_top+2]) 1649885Sstever@gmail.com if build_path not in build_paths: 1659885Sstever@gmail.com build_paths.append(build_path) 1669988Snilay@cs.wisc.edu 1679885Sstever@gmail.com################################################### 16810036SAli.Saidi@ARM.com# 1699885Sstever@gmail.com# Set up the default build environment. This environment is copied 1709885Sstever@gmail.com# and modified according to each selected configuration. 1715723SN/A# 1725723SN/A################################################### 1739988Snilay@cs.wisc.edu 1745723SN/Aenv = Environment(ENV = os.environ, # inherit user's environment vars 1759481Snilay@cs.wisc.edu ROOT = ROOT, 1769481Snilay@cs.wisc.edu SRCDIR = SRCDIR) 1779988Snilay@cs.wisc.edu 17810036SAli.Saidi@ARM.comenv.SConsignFile(os.path.join(build_root,"sconsign")) 1799481Snilay@cs.wisc.edu 1802968SN/A# Default duplicate option is to use hard links, but this messes up 1816024SN/A# when you use emacs to edit a file in the target dir, as emacs moves 1829988Snilay@cs.wisc.edu# file to file~ then copies to file, breaking the link. Symbolic 1832968SN/A# (soft) links work better. 1842968SN/Aenv.SetOption('duplicate', 'soft-copy') 1859481Snilay@cs.wisc.edu 1869481Snilay@cs.wisc.edu# I waffle on this setting... it does avoid a few painful but 1879885Sstever@gmail.com# unnecessary builds, but it also seems to make trivial builds take 1889481Snilay@cs.wisc.edu# noticeably longer. 1899481Snilay@cs.wisc.eduif False: 1909885Sstever@gmail.com env.TargetSignatures('content') 1919988Snilay@cs.wisc.edu 1929481Snilay@cs.wisc.edu# M5_PLY is used by isa_parser.py to find the PLY package. 1939481Snilay@cs.wisc.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 1949481Snilay@cs.wisc.edu 1959481Snilay@cs.wisc.edu# Set up default C++ compiler flags 1969481Snilay@cs.wisc.eduenv.Append(CCFLAGS='-pipe') 1979481Snilay@cs.wisc.eduenv.Append(CCFLAGS='-fno-strict-aliasing') 1989481Snilay@cs.wisc.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1999481Snilay@cs.wisc.eduif sys.platform == 'cygwin': 20010036SAli.Saidi@ARM.com # cygwin has some header file issues... 2019481Snilay@cs.wisc.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2029481Snilay@cs.wisc.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 2039885Sstever@gmail.com 2049481Snilay@cs.wisc.edu# Check for SWIG 2059481Snilay@cs.wisc.eduif not env.has_key('SWIG'): 2069481Snilay@cs.wisc.edu print 'Error: SWIG utility not found.' 2079481Snilay@cs.wisc.edu print ' Please install (see http://www.swig.org) and retry.' 2089481Snilay@cs.wisc.edu Exit(1) 2099481Snilay@cs.wisc.edu 2109885Sstever@gmail.com# Check for appropriate SWIG version 2119885Sstever@gmail.comswig_version = os.popen('swig -version').read().split() 2129885Sstever@gmail.com# First 3 words should be "SWIG Version x.y.z" 2139885Sstever@gmail.comif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2149885Sstever@gmail.com print 'Error determining SWIG version.' 2159988Snilay@cs.wisc.edu Exit(1) 2169885Sstever@gmail.com 21710036SAli.Saidi@ARM.commin_swig_version = '1.3.28' 2189885Sstever@gmail.comif compare_versions(swig_version[2], min_swig_version) < 0: 2199885Sstever@gmail.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 2209481Snilay@cs.wisc.edu print ' Installed version:', swig_version[2] 2219481Snilay@cs.wisc.edu Exit(1) 2229885Sstever@gmail.com 2239988Snilay@cs.wisc.edu# Set up SWIG flags & scanner 2249481Snilay@cs.wisc.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2259885Sstever@gmail.com 2269481Snilay@cs.wisc.eduimport SCons.Scanner 2279481Snilay@cs.wisc.edu 2289481Snilay@cs.wisc.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2299481Snilay@cs.wisc.edu 2309481Snilay@cs.wisc.eduswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2314938SN/A swig_inc_re) 2324938SN/A 2339988Snilay@cs.wisc.eduenv.Append(SCANNERS = swig_scanner) 2344938SN/A 2359885Sstever@gmail.com# Platform-specific configuration. Note again that we assume that all 2369885Sstever@gmail.com# builds under a given build root run on the same host platform. 2379885Sstever@gmail.comconf = Configure(env, 2389988Snilay@cs.wisc.edu conf_dir = os.path.join(build_root, '.scons_config'), 2399885Sstever@gmail.com log_file = os.path.join(build_root, 'scons_config.log')) 2409885Sstever@gmail.com 2412968SN/A# Find Python include and library directories for embedding the 2422968SN/A# interpreter. For consistency, we will use the same Python 2432968SN/A# installation used to run scons (and thus this script). If you want 2444463SN/A# to link in an alternate version, see above for instructions on how 2452968SN/A# to invoke scons with a different copy of the Python interpreter. 2469988Snilay@cs.wisc.edu 2472968SN/A# Get brief Python version name (e.g., "python2.4") for locating 2482968SN/A# include & library files 2492968SN/Apy_version_name = 'python' + sys.version[:3] 2502968SN/A 2512968SN/A# include path, e.g. /usr/local/include/python2.4 2522968SN/Apy_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name) 2539988Snilay@cs.wisc.eduenv.Append(CPPPATH = py_header_path) 2545876SN/A# verify that it works 2552968SN/Aif not conf.CheckHeader('Python.h', '<>'): 2562968SN/A print "Error: can't find Python.h header in", py_header_path 2572968SN/A Exit(1) 2582968SN/A 2592968SN/A# add library path too if it's not in the default place 2609988Snilay@cs.wisc.edupy_lib_path = None 26110036SAli.Saidi@ARM.comif sys.exec_prefix != '/usr': 2622968SN/A py_lib_path = os.path.join(sys.exec_prefix, 'lib') 2632968SN/Aelif sys.platform == 'cygwin': 2642968SN/A # cygwin puts the .dll in /bin for some reason 2652968SN/A py_lib_path = '/bin' 2662968SN/Aif py_lib_path: 2674463SN/A env.Append(LIBPATH = py_lib_path) 2682968SN/A print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 2699988Snilay@cs.wisc.eduif not conf.CheckLib(py_version_name): 2702968SN/A print "Error: can't find Python library", py_version_name 2712968SN/A Exit(1) 2722968SN/A 2732968SN/A# On Solaris you need to use libsocket for socket ops 2742968SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C', 'accept(0,NULL,NULL);'): 2752968SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C', 'accept(0,NULL,NULL);'): 2769988Snilay@cs.wisc.edu print "Can't find library with socket calls (e.g. accept())" 2775876SN/A Exit(1) 2782968SN/A 2792968SN/A# Check for zlib. If the check passes, libz will be automatically 2802968SN/A# added to the LIBS environment variable. 2812968SN/Aif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 2822968SN/A print 'Error: did not find needed zlib compression library '\ 2839988Snilay@cs.wisc.edu 'and/or zlib.h header file.' 28410036SAli.Saidi@ARM.com print ' Please install zlib and try again.' 2852968SN/A Exit(1) 2862968SN/A 2872968SN/A# Check for <fenv.h> (C99 FP environment control) 2882968SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 2899988Snilay@cs.wisc.eduif not have_fenv: 2904103SN/A print "Warning: Header file <fenv.h> not found." 2912968SN/A print " This host has no IEEE FP rounding mode control." 2922968SN/A 2939055Ssaidi@eecs.umich.edu# Check for mysql. 2949885Sstever@gmail.commysql_config = WhereIs('mysql_config') 2959988Snilay@cs.wisc.eduhave_mysql = mysql_config != None 2965509SN/A 2977524SN/A# Check MySQL version. 2989134Ssaidi@eecs.umich.eduif have_mysql: 2993104SN/A mysql_version = os.popen(mysql_config + ' --version').read() 3008983Snate@binkert.org min_mysql_version = '4.1' 3018983Snate@binkert.org if compare_versions(mysql_version, min_mysql_version) < 0: 3024966SN/A print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3034966SN/A print ' Version', mysql_version, 'detected.' 3044966SN/A have_mysql = False 3059885Sstever@gmail.com 3069481Snilay@cs.wisc.edu# Set up mysql_config commands. 3074966SN/Aif have_mysql: 3089885Sstever@gmail.com mysql_config_include = mysql_config + ' --include' 3099988Snilay@cs.wisc.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 3106123SN/A # older mysql_config versions don't support --include, use 3119481Snilay@cs.wisc.edu # --cflags instead 3128241SN/A mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 3134966SN/A # This seems to work in all versions 3144966SN/A mysql_config_libs = mysql_config + ' --libs' 3155876SN/A 3168835SAli.Saidi@ARM.comenv = conf.Finish() 3179481Snilay@cs.wisc.edu 31810036SAli.Saidi@ARM.com# Define the universe of supported ISAs 3194966SN/Aenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 3208835SAli.Saidi@ARM.com 3219885Sstever@gmail.com# Define the universe of supported CPU models 3224966SN/Aenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 3234966SN/A 'FullCPU', 'O3CPU', 3244966SN/A 'OzoneCPU'] 3258983Snate@binkert.org 3268983Snate@binkert.org# Sticky options get saved in the options file so they persist from 3274463SN/A# one invocation to the next (unless overridden, in which case the new 3289885Sstever@gmail.com# value becomes sticky). 3299885Sstever@gmail.comsticky_opts = Options(args=ARGUMENTS) 3309885Sstever@gmail.comsticky_opts.AddOptions( 3319885Sstever@gmail.com EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 3329885Sstever@gmail.com BoolOption('FULL_SYSTEM', 'Full-system support', False), 3339988Snilay@cs.wisc.edu # There's a bug in scons 0.96.1 that causes ListOptions with list 3349885Sstever@gmail.com # values (more than one value) not to be able to be restored from 33510036SAli.Saidi@ARM.com # a saved option file. If this causes trouble then upgrade to 3369885Sstever@gmail.com # scons 0.96.90 or later. 3379885Sstever@gmail.com ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 3382968SN/A env['ALL_CPU_LIST']), 3399055Ssaidi@eecs.umich.edu BoolOption('ALPHA_TLASER', 3406123SN/A 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 3419885Sstever@gmail.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 3429988Snilay@cs.wisc.edu BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 3435509SN/A False), 3449885Sstever@gmail.com BoolOption('SS_COMPATIBLE_FP', 3457524SN/A 'Make floating-point results compatible with SimpleScalar', 3469134Ssaidi@eecs.umich.edu False), 3476123SN/A BoolOption('USE_SSE2', 3489134Ssaidi@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 3499481Snilay@cs.wisc.edu False), 3502968SN/A BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 3516123SN/A BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 3523505SN/A BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 3539885Sstever@gmail.com ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3549988Snilay@cs.wisc.edu ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3558721SN/A BoolOption('BATCH', 'Use batch pool for build and tests', False), 3563493SN/A ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3579481Snilay@cs.wisc.edu ('PYTHONHOME', 3583505SN/A 'Override the default PYTHONHOME for this system (use with caution)', 3593505SN/A '%s:%s' % (sys.prefix, sys.exec_prefix)) 3603934SN/A ) 3613934SN/A 3623934SN/A# Non-sticky options only apply to the current build. 3633934SN/Anonsticky_opts = Options(args=ARGUMENTS) 3643493SN/Anonsticky_opts.AddOptions( 3653934SN/A BoolOption('update_ref', 'Update test reference outputs', False) 3663934SN/A ) 3673493SN/A 3683493SN/A# These options get exported to #defines in config/*.hh (see src/SConscript). 3692968SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 3709988Snilay@cs.wisc.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 3719988Snilay@cs.wisc.edu 'USE_CHECKER', 'PYTHONHOME'] 3729885Sstever@gmail.com 3739885Sstever@gmail.com# Define a handy 'no-op' action 3749988Snilay@cs.wisc.edudef no_action(target, source, env): 3758983Snate@binkert.org return 0 3769988Snilay@cs.wisc.edu 3779988Snilay@cs.wisc.eduenv.NoAction = Action(no_action, None) 3785509SN/A 3792968SN/A################################################### 3808983Snate@binkert.org# 3812968SN/A# Define a SCons builder for configuration flag headers. 3822968SN/A# 3832968SN/A################################################### 3842968SN/A 3852968SN/A# This function generates a config header file that #defines the 3869988Snilay@cs.wisc.edu# option symbol to the current option setting (0 or 1). The source 3872968SN/A# operands are the name of the option and a Value node containing the 3882968SN/A# value of the option. 3892968SN/Adef build_config_file(target, source, env): 3902968SN/A (option, value) = [s.get_contents() for s in source] 3919988Snilay@cs.wisc.edu f = file(str(target[0]), 'w') 39210036SAli.Saidi@ARM.com print >> f, '#define', option, value 3932968SN/A f.close() 3942968SN/A return None 3955509SN/A 3965509SN/A# Generate the message to be printed when building the config file. 3979988Snilay@cs.wisc.edudef build_config_file_string(target, source, env): 3985509SN/A (option, value) = [s.get_contents() for s in source] 3995509SN/A return "Defining %s as %s in %s." % (option, value, target[0]) 4005509SN/A 4015509SN/A# Combine the two functions into a scons Action object. 4025509SN/Aconfig_action = Action(build_config_file, build_config_file_string) 4032968SN/A 4042968SN/A# The emitter munges the source & target node lists to reflect what 4055509SN/A# we're really doing. 4069988Snilay@cs.wisc.edudef config_emitter(target, source, env): 4072968SN/A # extract option name from Builder arg 4082968SN/A option = str(target[0]) 4092968SN/A # True target is config header file 4105509SN/A target = os.path.join('config', option.lower() + '.hh') 4115509SN/A val = env[option] 4129885Sstever@gmail.com if isinstance(val, bool): 4135509SN/A # Force value to 0/1 4145509SN/A val = int(val) 4159988Snilay@cs.wisc.edu elif isinstance(val, str): 4165509SN/A val = '"' + val + '"' 4179481Snilay@cs.wisc.edu 4185509SN/A # Sources are option name & value (packaged in SCons Value nodes) 4195509SN/A return ([target], [Value(option), Value(val)]) 4205509SN/A 4218983Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 4225509SN/A 4232968SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 4242968SN/A 4259885Sstever@gmail.com################################################### 4269988Snilay@cs.wisc.edu# 4272968SN/A# Define a SCons builder for copying files. This is used by the 4289481Snilay@cs.wisc.edu# Python zipfile code in src/python/SConscript, but is placed up here 4292968SN/A# since it's potentially more generally applicable. 4302968SN/A# 4318983Snate@binkert.org################################################### 4322968SN/A 4332968SN/Acopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 4342968SN/A 4352968SN/Aenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 4365876SN/A 4372968SN/A################################################### 4382968SN/A# 4395876SN/A# Define a simple SCons builder to concatenate files. 4402968SN/A# 4412968SN/A# Used to append the Python zip archive to the executable. 4425876SN/A# 4432968SN/A################################################### 4442968SN/A 4455876SN/Aconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 4462968SN/A 'chmod +x $TARGET'])) 4472968SN/A 4485876SN/Aenv.Append(BUILDERS = { 'Concat' : concat_builder }) 4492968SN/A 4502968SN/A 4515876SN/A# base help text 4522968SN/Ahelp_text = ''' 4532968SN/AUsage: scons [scons options] [build options] [target(s)] 4542968SN/A 4559988Snilay@cs.wisc.edu''' 4562968SN/A 4572968SN/A# libelf build is shared across all configs in the build root. 4582968SN/Aenv.SConscript('ext/libelf/SConscript', 4592968SN/A build_dir = os.path.join(build_root, 'libelf'), 4602968SN/A exports = 'env') 4612968SN/A 4622968SN/A################################################### 4632968SN/A# 4642968SN/A# Define build environments for selected configurations. 4659988Snilay@cs.wisc.edu# 4669988Snilay@cs.wisc.edu################################################### 4679988Snilay@cs.wisc.edu 4689988Snilay@cs.wisc.edu# rename base env 4699988Snilay@cs.wisc.edubase_env = env 4709988Snilay@cs.wisc.edu 4719988Snilay@cs.wisc.edufor build_path in build_paths: 4729988Snilay@cs.wisc.edu print "Building in", build_path 4739988Snilay@cs.wisc.edu # build_dir is the tail component of build path, and is used to 4749988Snilay@cs.wisc.edu # determine the build parameters (e.g., 'ALPHA_SE') 4759988Snilay@cs.wisc.edu (build_root, build_dir) = os.path.split(build_path) 4769988Snilay@cs.wisc.edu # Make a copy of the build-root environment to use for this config. 4779988Snilay@cs.wisc.edu env = base_env.Copy() 4789988Snilay@cs.wisc.edu 4799988Snilay@cs.wisc.edu # Set env options according to the build directory config. 4802968SN/A sticky_opts.files = [] 4812968SN/A # Options for $BUILD_ROOT/$BUILD_DIR are stored in 4829988Snilay@cs.wisc.edu # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 4839988Snilay@cs.wisc.edu # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 4849988Snilay@cs.wisc.edu current_opts_file = os.path.join(build_root, 'options', build_dir) 4859988Snilay@cs.wisc.edu if os.path.isfile(current_opts_file): 4869988Snilay@cs.wisc.edu sticky_opts.files.append(current_opts_file) 4879988Snilay@cs.wisc.edu print "Using saved options file %s" % current_opts_file 4889988Snilay@cs.wisc.edu else: 4899988Snilay@cs.wisc.edu # Build dir-specific options file doesn't exist. 4909988Snilay@cs.wisc.edu 4919988Snilay@cs.wisc.edu # Make sure the directory is there so we can create it later 4929988Snilay@cs.wisc.edu opt_dir = os.path.dirname(current_opts_file) 4939988Snilay@cs.wisc.edu if not os.path.isdir(opt_dir): 4949988Snilay@cs.wisc.edu os.mkdir(opt_dir) 4959988Snilay@cs.wisc.edu 4969988Snilay@cs.wisc.edu # Get default build options from source tree. Options are 4979988Snilay@cs.wisc.edu # normally determined by name of $BUILD_DIR, but can be 4989988Snilay@cs.wisc.edu # overriden by 'default=' arg on command line. 4992968SN/A default_opts_file = os.path.join('build_opts', 5002968SN/A ARGUMENTS.get('default', build_dir)) 5012968SN/A if os.path.isfile(default_opts_file): 5022968SN/A sticky_opts.files.append(default_opts_file) 5032968SN/A print "Options file %s not found,\n using defaults in %s" \ 5042968SN/A % (current_opts_file, default_opts_file) 5052968SN/A else: 5069885Sstever@gmail.com print "Error: cannot find options file %s or %s" \ 5075102SN/A % (current_opts_file, default_opts_file) 5085102SN/A Exit(1) 5095102SN/A 5105102SN/A # Apply current option settings to env 5115102SN/A sticky_opts.Update(env) 5125102SN/A nonsticky_opts.Update(env) 5135102SN/A 5145102SN/A help_text += "Sticky options for %s:\n" % build_dir \ 5159988Snilay@cs.wisc.edu + sticky_opts.GenerateHelpText(env) \ 5165102SN/A + "\nNon-sticky options for %s:\n" % build_dir \ 5175102SN/A + nonsticky_opts.GenerateHelpText(env) 5185102SN/A 5195102SN/A # Process option settings. 5205102SN/A 5219481Snilay@cs.wisc.edu if not have_fenv and env['USE_FENV']: 5225102SN/A print "Warning: <fenv.h> not available; " \ 5235102SN/A "forcing USE_FENV to False in", build_dir + "." 5245102SN/A env['USE_FENV'] = False 5255102SN/A 5265102SN/A if not env['USE_FENV']: 5275102SN/A print "Warning: No IEEE FP rounding mode control in", build_dir + "." 5285102SN/A print " FP results may deviate slightly from other platforms." 5295102SN/A 5305102SN/A if env['EFENCE']: 5315102SN/A env.Append(LIBS=['efence']) 5328983Snate@binkert.org 5338983Snate@binkert.org if env['USE_MYSQL']: 5348983Snate@binkert.org if not have_mysql: 5352968SN/A print "Warning: MySQL not available; " \ 5362968SN/A "forcing USE_MYSQL to False in", build_dir + "." 5372968SN/A env['USE_MYSQL'] = False 5389885Sstever@gmail.com else: 5399988Snilay@cs.wisc.edu print "Compiling in", build_dir, "with MySQL support." 5408721SN/A env.ParseConfig(mysql_config_libs) 5412968SN/A env.ParseConfig(mysql_config_include) 5429481Snilay@cs.wisc.edu 5432968SN/A # Save sticky option settings back to current options file 5443505SN/A sticky_opts.Save(current_opts_file, env) 5453934SN/A 5463934SN/A # Do this after we save setting back, or else we'll tack on an 5473934SN/A # extra 'qdo' every time we run scons. 5483934SN/A if env['BATCH']: 5492968SN/A env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 5503934SN/A env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 5513934SN/A 5528983Snate@binkert.org if env['USE_SSE2']: 5532968SN/A env.Append(CCFLAGS='-msse2') 5542968SN/A 5552968SN/A # The src/SConscript file sets up the build rules in 'env' according 5569885Sstever@gmail.com # to the configured options. It returns a list of environments, 5579988Snilay@cs.wisc.edu # one for each variant build (debug, opt, etc.) 5588721SN/A envList = SConscript('src/SConscript', build_dir = build_path, 5592968SN/A exports = 'env') 5609481Snilay@cs.wisc.edu 5612968SN/A # Set up the regression tests for each build. 5623505SN/A for e in envList: 5633934SN/A SConscript('tests/SConscript', 5643934SN/A build_dir = os.path.join(build_path, 'tests', e.Label), 5653934SN/A exports = { 'env' : e }, duplicate = False) 5663934SN/A 5672968SN/AHelp(help_text) 5683934SN/A 5693934SN/A################################################### 5708983Snate@binkert.org# 5712968SN/A# Let SCons do its thing. At this point SCons will use the defined 5722968SN/A# build environments to build the requested targets. 5732968SN/A# 5749885Sstever@gmail.com################################################### 5759988Snilay@cs.wisc.edu 5768721SN/A