SConstruct revision 2776
1955SN/A# -*- mode:python -*- 2955SN/A 311408Sandreas.sandberg@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 49812Sandreas.hansson@arm.com# All rights reserved. 59812Sandreas.hansson@arm.com# 69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from 157816Ssteve.reinhardt@amd.com# this software without specific prior written permission. 165871Snate@binkert.org# 171762SN/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. 28955SN/A# 29955SN/A# Authors: Steve Reinhardt 30955SN/A 31955SN/A################################################### 32955SN/A# 33955SN/A# SCons top-level build description (SConstruct) file. 34955SN/A# 35955SN/A# While in this directory ('m5'), just type 'scons' to build the default 36955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 38955SN/A# the optimized full-system version). 39955SN/A# 40955SN/A# You can build M5 in a different directory as long as there is a 41955SN/A# 'build/<CONFIG>' somewhere along the target path. The build system 422665Ssaidi@eecs.umich.edu# expects that all configs under the same build directory are being 432665Ssaidi@eecs.umich.edu# built for the same host system. 445863Snate@binkert.org# 45955SN/A# Examples: 46955SN/A# 47955SN/A# The following two commands are equivalent. The '-u' option tells 48955SN/A# scons to search up the directory tree for this SConstruct file. 49955SN/A# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 508878Ssteve.reinhardt@amd.com# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512632Sstever@eecs.umich.edu# 528878Ssteve.reinhardt@amd.com# 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 54955SN/A# scons to chdir to the specified directory to find this SConstruct 558878Ssteve.reinhardt@amd.com# file. 562632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 572761Sstever@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 612761Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 622761Sstever@eecs.umich.edu# options as well. 632761Sstever@eecs.umich.edu# 648878Ssteve.reinhardt@amd.com################################################### 658878Ssteve.reinhardt@amd.com 662761Sstever@eecs.umich.edu# Python library imports 672761Sstever@eecs.umich.eduimport sys 682761Sstever@eecs.umich.eduimport os 692761Sstever@eecs.umich.edu 702761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 718878Ssteve.reinhardt@amd.com# default installation of Python is not recent enough, you can use a 728878Ssteve.reinhardt@amd.com# non-default installation of the Python interpreter by either (1) 732632Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 742632Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 758878Ssteve.reinhardt@amd.com# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 768878Ssteve.reinhardt@amd.comEnsurePythonVersion(2,4) 772632Sstever@eecs.umich.edu 78955SN/A# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 79955SN/A# 3-element version number. 80955SN/Amin_scons_version = (0,96,91) 815863Snate@binkert.orgtry: 825863Snate@binkert.org EnsureSConsVersion(*min_scons_version) 835863Snate@binkert.orgexcept: 845863Snate@binkert.org print "Error checking current SCons version." 855863Snate@binkert.org print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 865863Snate@binkert.org Exit(2) 875863Snate@binkert.org 885863Snate@binkert.org 895863Snate@binkert.org# The absolute path to the current directory (where this file lives). 905863Snate@binkert.orgROOT = Dir('.').abspath 915863Snate@binkert.org 928878Ssteve.reinhardt@amd.com# Paths to the M5 and external source trees. 935863Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src') 945863Snate@binkert.org 955863Snate@binkert.org# tell python where to find m5 python code 969812Sandreas.hansson@arm.comsys.path.append(os.path.join(ROOT, 'src/python')) 979812Sandreas.hansson@arm.com 985863Snate@binkert.org################################################### 999812Sandreas.hansson@arm.com# 1005863Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 1015863Snate@binkert.org# the target(s). 1025863Snate@binkert.org# 1039812Sandreas.hansson@arm.com################################################### 1049812Sandreas.hansson@arm.com 1055863Snate@binkert.org# Find default configuration & binary. 1065863Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1078878Ssteve.reinhardt@amd.com 1085863Snate@binkert.org# Ask SCons which directory it was invoked from. 1095863Snate@binkert.orglaunch_dir = GetLaunchDir() 1105863Snate@binkert.org 1116654Snate@binkert.org# Make targets relative to invocation directory 11210196SCurtis.Dunham@arm.comabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 113955SN/A BUILD_TARGETS) 1145396Ssaidi@eecs.umich.edu 11511401Sandreas.sandberg@arm.com# helper function: find last occurrence of element in list 1165863Snate@binkert.orgdef rfind(l, elt, offs = -1): 1175863Snate@binkert.org for i in range(len(l)+offs, 0, -1): 1184202Sbinkertn@umich.edu if l[i] == elt: 1195863Snate@binkert.org return i 1205863Snate@binkert.org raise ValueError, "element not found" 1215863Snate@binkert.org 1225863Snate@binkert.org# Each target must have 'build' in the interior of the path; the 123955SN/A# directory below this will determine the build parameters. For 1246654Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1255273Sstever@gmail.com# recognize that ALPHA_SE specifies the configuration because it 1265871Snate@binkert.org# follow 'build' in the bulid path. 1275273Sstever@gmail.com 1286655Snate@binkert.org# Generate a list of the unique build roots and configs that the 1298878Ssteve.reinhardt@amd.com# collected targets reference. 1306655Snate@binkert.orgbuild_paths = [] 1316655Snate@binkert.orgbuild_root = None 1329219Spower.jg@gmail.comfor t in abs_targets: 1336655Snate@binkert.org path_dirs = t.split('/') 1345871Snate@binkert.org try: 1356654Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 1368947Sandreas.hansson@arm.com except: 1375396Ssaidi@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 1388120Sgblack@eecs.umich.edu Exit(1) 1398120Sgblack@eecs.umich.edu this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1408120Sgblack@eecs.umich.edu if not build_root: 1418120Sgblack@eecs.umich.edu build_root = this_build_root 1428120Sgblack@eecs.umich.edu else: 1438120Sgblack@eecs.umich.edu if this_build_root != build_root: 1448120Sgblack@eecs.umich.edu print "Error: build targets not under same build root\n"\ 1458120Sgblack@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1468879Ssteve.reinhardt@amd.com Exit(1) 1478879Ssteve.reinhardt@amd.com build_path = os.path.join('/',*path_dirs[:build_top+2]) 1488879Ssteve.reinhardt@amd.com if build_path not in build_paths: 1498879Ssteve.reinhardt@amd.com build_paths.append(build_path) 1508879Ssteve.reinhardt@amd.com 1518879Ssteve.reinhardt@amd.com################################################### 1528879Ssteve.reinhardt@amd.com# 1538879Ssteve.reinhardt@amd.com# Set up the default build environment. This environment is copied 1548879Ssteve.reinhardt@amd.com# and modified according to each selected configuration. 1558879Ssteve.reinhardt@amd.com# 1568879Ssteve.reinhardt@amd.com################################################### 1578879Ssteve.reinhardt@amd.com 1588879Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ, # inherit user's environment vars 1598120Sgblack@eecs.umich.edu ROOT = ROOT, 1608120Sgblack@eecs.umich.edu SRCDIR = SRCDIR) 1618120Sgblack@eecs.umich.edu 1628120Sgblack@eecs.umich.eduenv.SConsignFile(os.path.join(build_root,"sconsign")) 1638120Sgblack@eecs.umich.edu 1648120Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 1658120Sgblack@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 1668120Sgblack@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 1678120Sgblack@eecs.umich.edu# (soft) links work better. 1688120Sgblack@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 1698120Sgblack@eecs.umich.edu 1708120Sgblack@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but 1718120Sgblack@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 1728120Sgblack@eecs.umich.edu# noticeably longer. 1738879Ssteve.reinhardt@amd.comif False: 1748879Ssteve.reinhardt@amd.com env.TargetSignatures('content') 1758879Ssteve.reinhardt@amd.com 1768879Ssteve.reinhardt@amd.com# M5_PLY is used by isa_parser.py to find the PLY package. 17710458Sandreas.hansson@arm.comenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 17810458Sandreas.hansson@arm.com 17910458Sandreas.hansson@arm.com# Set up default C++ compiler flags 1808879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-pipe') 1818879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-fno-strict-aliasing') 1828879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1838879Ssteve.reinhardt@amd.comif sys.platform == 'cygwin': 1849227Sandreas.hansson@arm.com # cygwin has some header file issues... 1859227Sandreas.hansson@arm.com env.Append(CCFLAGS=Split("-Wno-uninitialized")) 1868879Ssteve.reinhardt@amd.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 1878879Ssteve.reinhardt@amd.com 1888879Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the 1898879Ssteve.reinhardt@amd.com# interpreter. For consistency, we will use the same Python 19010453SAndrew.Bardsley@arm.com# installation used to run scons (and thus this script). If you want 19110453SAndrew.Bardsley@arm.com# to link in an alternate version, see above for instructions on how 19210453SAndrew.Bardsley@arm.com# to invoke scons with a different copy of the Python interpreter. 19310456SCurtis.Dunham@arm.com 19410456SCurtis.Dunham@arm.com# Get brief Python version name (e.g., "python2.4") for locating 19510456SCurtis.Dunham@arm.com# include & library files 19610457Sandreas.hansson@arm.compy_version_name = 'python' + sys.version[:3] 19710457Sandreas.hansson@arm.com 19811342Sandreas.hansson@arm.com# include path, e.g. /usr/local/include/python2.4 19911342Sandreas.hansson@arm.comenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name)) 2008120Sgblack@eecs.umich.eduenv.Append(LIBS = py_version_name) 2018947Sandreas.hansson@arm.com# add library path too if it's not in the default place 2027816Ssteve.reinhardt@amd.comif sys.exec_prefix != '/usr': 2035871Snate@binkert.org env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib')) 2045871Snate@binkert.org 2056121Snate@binkert.org# Set up SWIG flags & scanner 2065871Snate@binkert.org 2075871Snate@binkert.orgenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2089926Sstan.czerniawski@arm.com 2099926Sstan.czerniawski@arm.comimport SCons.Scanner 2109119Sandreas.hansson@arm.com 21110068Sandreas.hansson@arm.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 21211989Sandreas.sandberg@arm.com 213955SN/Aswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2149416SAndreas.Sandberg@ARM.com swig_inc_re) 21511342Sandreas.hansson@arm.com 21611212Sjoseph.gross@amd.comenv.Append(SCANNERS = swig_scanner) 21711212Sjoseph.gross@amd.com 21811212Sjoseph.gross@amd.com# Other default libraries 21911212Sjoseph.gross@amd.comenv.Append(LIBS=['z']) 22011212Sjoseph.gross@amd.com 2219416SAndreas.Sandberg@ARM.com# Platform-specific configuration. Note again that we assume that all 2229416SAndreas.Sandberg@ARM.com# builds under a given build root run on the same host platform. 2235871Snate@binkert.orgconf = Configure(env, 22410584Sandreas.hansson@arm.com conf_dir = os.path.join(build_root, '.scons_config'), 2259416SAndreas.Sandberg@ARM.com log_file = os.path.join(build_root, 'scons_config.log')) 2269416SAndreas.Sandberg@ARM.com 2275871Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 228955SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 22910671Sandreas.hansson@arm.comif not have_fenv: 23010671Sandreas.hansson@arm.com print "Warning: Header file <fenv.h> not found." 23110671Sandreas.hansson@arm.com print " This host has no IEEE FP rounding mode control." 23210671Sandreas.hansson@arm.com 2338881Smarc.orr@gmail.com# Check for mysql. 2346121Snate@binkert.orgmysql_config = WhereIs('mysql_config') 2356121Snate@binkert.orghave_mysql = mysql_config != None 2361533SN/A 2379239Sandreas.hansson@arm.com# Check MySQL version. 2389239Sandreas.hansson@arm.comif have_mysql: 2399239Sandreas.hansson@arm.com mysql_version = os.popen(mysql_config + ' --version').read() 2409239Sandreas.hansson@arm.com mysql_version = mysql_version.split('.') 2419239Sandreas.hansson@arm.com mysql_major = int(mysql_version[0]) 2429239Sandreas.hansson@arm.com mysql_minor = int(mysql_version[1]) 2439239Sandreas.hansson@arm.com # This version check is probably overly conservative, but it deals 2446655Snate@binkert.org # with the versions we have installed. 2456655Snate@binkert.org if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1): 2466655Snate@binkert.org print "Warning: MySQL v4.1 or newer required." 2476655Snate@binkert.org have_mysql = False 2485871Snate@binkert.org 2495871Snate@binkert.org# Set up mysql_config commands. 2505863Snate@binkert.orgif have_mysql: 2515871Snate@binkert.org mysql_config_include = mysql_config + ' --include' 2528878Ssteve.reinhardt@amd.com if os.system(mysql_config_include + ' > /dev/null') != 0: 2535871Snate@binkert.org # older mysql_config versions don't support --include, use 2545871Snate@binkert.org # --cflags instead 2555871Snate@binkert.org mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 2565863Snate@binkert.org # This seems to work in all versions 2576121Snate@binkert.org mysql_config_libs = mysql_config + ' --libs' 2585863Snate@binkert.org 25911408Sandreas.sandberg@arm.comenv = conf.Finish() 26011408Sandreas.sandberg@arm.com 2618336Ssteve.reinhardt@amd.com# Define the universe of supported ISAs 26211469SCurtis.Dunham@arm.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 26311469SCurtis.Dunham@arm.com 2648336Ssteve.reinhardt@amd.com# Define the universe of supported CPU models 2654678Snate@binkert.orgenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 26611887Sandreas.sandberg@arm.com 'FullCPU', 'AlphaO3CPU', 26711887Sandreas.sandberg@arm.com 'OzoneSimpleCPU', 'OzoneCPU'] 26811887Sandreas.sandberg@arm.com 26911887Sandreas.sandberg@arm.com# Sticky options get saved in the options file so they persist from 27011887Sandreas.sandberg@arm.com# one invocation to the next (unless overridden, in which case the new 27111887Sandreas.sandberg@arm.com# value becomes sticky). 27211887Sandreas.sandberg@arm.comsticky_opts = Options(args=ARGUMENTS) 27311887Sandreas.sandberg@arm.comsticky_opts.AddOptions( 27411887Sandreas.sandberg@arm.com EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 27511887Sandreas.sandberg@arm.com BoolOption('FULL_SYSTEM', 'Full-system support', False), 27611887Sandreas.sandberg@arm.com # There's a bug in scons 0.96.1 that causes ListOptions with list 27711408Sandreas.sandberg@arm.com # values (more than one value) not to be able to be restored from 27811401Sandreas.sandberg@arm.com # a saved option file. If this causes trouble then upgrade to 27911401Sandreas.sandberg@arm.com # scons 0.96.90 or later. 28011401Sandreas.sandberg@arm.com ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 28111401Sandreas.sandberg@arm.com env['ALL_CPU_LIST']), 28211401Sandreas.sandberg@arm.com BoolOption('ALPHA_TLASER', 28311401Sandreas.sandberg@arm.com 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 2848336Ssteve.reinhardt@amd.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 2858336Ssteve.reinhardt@amd.com BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 2868336Ssteve.reinhardt@amd.com False), 2874678Snate@binkert.org BoolOption('SS_COMPATIBLE_FP', 28811401Sandreas.sandberg@arm.com 'Make floating-point results compatible with SimpleScalar', 2894678Snate@binkert.org False), 2904678Snate@binkert.org BoolOption('USE_SSE2', 29111401Sandreas.sandberg@arm.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 29211401Sandreas.sandberg@arm.com False), 2938336Ssteve.reinhardt@amd.com BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 2944678Snate@binkert.org BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 2958336Ssteve.reinhardt@amd.com BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 2968336Ssteve.reinhardt@amd.com ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 2978336Ssteve.reinhardt@amd.com ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 2988336Ssteve.reinhardt@amd.com BoolOption('BATCH', 'Use batch pool for build and tests', False), 2998336Ssteve.reinhardt@amd.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo') 3008336Ssteve.reinhardt@amd.com ) 3015871Snate@binkert.org 3025871Snate@binkert.org# Non-sticky options only apply to the current build. 3038336Ssteve.reinhardt@amd.comnonsticky_opts = Options(args=ARGUMENTS) 30411408Sandreas.sandberg@arm.comnonsticky_opts.AddOptions( 30511408Sandreas.sandberg@arm.com BoolOption('update_ref', 'Update test reference outputs', False) 30611408Sandreas.sandberg@arm.com ) 30711408Sandreas.sandberg@arm.com 30811408Sandreas.sandberg@arm.com# These options get exported to #defines in config/*.hh (see src/SConscript). 30911408Sandreas.sandberg@arm.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 31011408Sandreas.sandberg@arm.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 3118336Ssteve.reinhardt@amd.com 'USE_CHECKER'] 31211401Sandreas.sandberg@arm.com 31311401Sandreas.sandberg@arm.com# Define a handy 'no-op' action 31411401Sandreas.sandberg@arm.comdef no_action(target, source, env): 3155871Snate@binkert.org return 0 3168336Ssteve.reinhardt@amd.com 3178336Ssteve.reinhardt@amd.comenv.NoAction = Action(no_action, None) 31811401Sandreas.sandberg@arm.com 31911401Sandreas.sandberg@arm.com################################################### 32011401Sandreas.sandberg@arm.com# 32111401Sandreas.sandberg@arm.com# Define a SCons builder for configuration flag headers. 32211401Sandreas.sandberg@arm.com# 3234678Snate@binkert.org################################################### 3245871Snate@binkert.org 3254678Snate@binkert.org# This function generates a config header file that #defines the 32611401Sandreas.sandberg@arm.com# option symbol to the current option setting (0 or 1). The source 32711401Sandreas.sandberg@arm.com# operands are the name of the option and a Value node containing the 32811401Sandreas.sandberg@arm.com# value of the option. 32911401Sandreas.sandberg@arm.comdef build_config_file(target, source, env): 33011401Sandreas.sandberg@arm.com (option, value) = [s.get_contents() for s in source] 33111401Sandreas.sandberg@arm.com f = file(str(target[0]), 'w') 33211401Sandreas.sandberg@arm.com print >> f, '#define', option, value 33311401Sandreas.sandberg@arm.com f.close() 33411401Sandreas.sandberg@arm.com return None 33511401Sandreas.sandberg@arm.com 33611401Sandreas.sandberg@arm.com# Generate the message to be printed when building the config file. 33711401Sandreas.sandberg@arm.comdef build_config_file_string(target, source, env): 33811450Sandreas.sandberg@arm.com (option, value) = [s.get_contents() for s in source] 33911450Sandreas.sandberg@arm.com return "Defining %s as %s in %s." % (option, value, target[0]) 34011450Sandreas.sandberg@arm.com 34111450Sandreas.sandberg@arm.com# Combine the two functions into a scons Action object. 34211450Sandreas.sandberg@arm.comconfig_action = Action(build_config_file, build_config_file_string) 34311450Sandreas.sandberg@arm.com 34411450Sandreas.sandberg@arm.com# The emitter munges the source & target node lists to reflect what 34511450Sandreas.sandberg@arm.com# we're really doing. 34611450Sandreas.sandberg@arm.comdef config_emitter(target, source, env): 34711450Sandreas.sandberg@arm.com # extract option name from Builder arg 34811450Sandreas.sandberg@arm.com option = str(target[0]) 34911401Sandreas.sandberg@arm.com # True target is config header file 35011450Sandreas.sandberg@arm.com target = os.path.join('config', option.lower() + '.hh') 35111450Sandreas.sandberg@arm.com # Force value to 0/1 even if it's a Python bool 35211450Sandreas.sandberg@arm.com val = int(eval(str(env[option]))) 35311401Sandreas.sandberg@arm.com # Sources are option name & value (packaged in SCons Value nodes) 35411450Sandreas.sandberg@arm.com return ([target], [Value(option), Value(val)]) 35511401Sandreas.sandberg@arm.com 3568336Ssteve.reinhardt@amd.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 3578336Ssteve.reinhardt@amd.com 3588336Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 3598336Ssteve.reinhardt@amd.com 3608336Ssteve.reinhardt@amd.com################################################### 3618336Ssteve.reinhardt@amd.com# 3628336Ssteve.reinhardt@amd.com# Define a SCons builder for copying files. This is used by the 3638336Ssteve.reinhardt@amd.com# Python zipfile code in src/python/SConscript, but is placed up here 3648336Ssteve.reinhardt@amd.com# since it's potentially more generally applicable. 3658336Ssteve.reinhardt@amd.com# 36611401Sandreas.sandberg@arm.com################################################### 36711401Sandreas.sandberg@arm.com 3688336Ssteve.reinhardt@amd.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 3698336Ssteve.reinhardt@amd.com 3708336Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 3715871Snate@binkert.org 37211476Sandreas.sandberg@arm.com################################################### 37311476Sandreas.sandberg@arm.com# 37411476Sandreas.sandberg@arm.com# Define a simple SCons builder to concatenate files. 37511476Sandreas.sandberg@arm.com# 37611476Sandreas.sandberg@arm.com# Used to append the Python zip archive to the executable. 37711476Sandreas.sandberg@arm.com# 37811476Sandreas.sandberg@arm.com################################################### 37911476Sandreas.sandberg@arm.com 38011476Sandreas.sandberg@arm.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 38111887Sandreas.sandberg@arm.com 'chmod +x $TARGET'])) 38211887Sandreas.sandberg@arm.com 38311887Sandreas.sandberg@arm.comenv.Append(BUILDERS = { 'Concat' : concat_builder }) 38411408Sandreas.sandberg@arm.com 38511887Sandreas.sandberg@arm.com 38611887Sandreas.sandberg@arm.com# base help text 38711887Sandreas.sandberg@arm.comhelp_text = ''' 38811887Sandreas.sandberg@arm.comUsage: scons [scons options] [build options] [target(s)] 38911887Sandreas.sandberg@arm.com 39011887Sandreas.sandberg@arm.com''' 39111926Sgabeblack@google.com 39211926Sgabeblack@google.com# libelf build is shared across all configs in the build root. 39311926Sgabeblack@google.comenv.SConscript('ext/libelf/SConscript', 39411926Sgabeblack@google.com build_dir = os.path.join(build_root, 'libelf'), 39511887Sandreas.sandberg@arm.com exports = 'env') 39611887Sandreas.sandberg@arm.com 39711944Sandreas.sandberg@arm.com################################################### 39811887Sandreas.sandberg@arm.com# 39911927Sgabeblack@google.com# Define build environments for selected configurations. 40011927Sgabeblack@google.com# 40111927Sgabeblack@google.com################################################### 40211927Sgabeblack@google.com 40311927Sgabeblack@google.com# rename base env 40411927Sgabeblack@google.combase_env = env 40511887Sandreas.sandberg@arm.com 40611928Sgabeblack@google.comfor build_path in build_paths: 40711928Sgabeblack@google.com print "Building in", build_path 40811887Sandreas.sandberg@arm.com # build_dir is the tail component of build path, and is used to 40911887Sandreas.sandberg@arm.com # determine the build parameters (e.g., 'ALPHA_SE') 41011887Sandreas.sandberg@arm.com (build_root, build_dir) = os.path.split(build_path) 41111887Sandreas.sandberg@arm.com # Make a copy of the build-root environment to use for this config. 41211887Sandreas.sandberg@arm.com env = base_env.Copy() 41311887Sandreas.sandberg@arm.com 41411887Sandreas.sandberg@arm.com # Set env options according to the build directory config. 41511887Sandreas.sandberg@arm.com sticky_opts.files = [] 41611887Sandreas.sandberg@arm.com # Options for $BUILD_ROOT/$BUILD_DIR are stored in 41711887Sandreas.sandberg@arm.com # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 41811476Sandreas.sandberg@arm.com # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 41911476Sandreas.sandberg@arm.com current_opts_file = os.path.join(build_root, 'options', build_dir) 42011408Sandreas.sandberg@arm.com if os.path.isfile(current_opts_file): 42111408Sandreas.sandberg@arm.com sticky_opts.files.append(current_opts_file) 42211408Sandreas.sandberg@arm.com print "Using saved options file %s" % current_opts_file 42311408Sandreas.sandberg@arm.com else: 42411408Sandreas.sandberg@arm.com # Build dir-specific options file doesn't exist. 42511408Sandreas.sandberg@arm.com 42611408Sandreas.sandberg@arm.com # Make sure the directory is there so we can create it later 42711887Sandreas.sandberg@arm.com opt_dir = os.path.dirname(current_opts_file) 42811887Sandreas.sandberg@arm.com if not os.path.isdir(opt_dir): 42911476Sandreas.sandberg@arm.com os.mkdir(opt_dir) 43011887Sandreas.sandberg@arm.com 43111887Sandreas.sandberg@arm.com # Get default build options from source tree. Options are 43211476Sandreas.sandberg@arm.com # normally determined by name of $BUILD_DIR, but can be 43311476Sandreas.sandberg@arm.com # overriden by 'default=' arg on command line. 43411476Sandreas.sandberg@arm.com default_opts_file = os.path.join('build_opts', 43511476Sandreas.sandberg@arm.com ARGUMENTS.get('default', build_dir)) 4366121Snate@binkert.org if os.path.isfile(default_opts_file): 437955SN/A sticky_opts.files.append(default_opts_file) 438955SN/A print "Options file %s not found,\n using defaults in %s" \ 4392632Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 4402632Sstever@eecs.umich.edu else: 441955SN/A print "Error: cannot find options file %s or %s" \ 442955SN/A % (current_opts_file, default_opts_file) 443955SN/A Exit(1) 444955SN/A 4458878Ssteve.reinhardt@amd.com # Apply current option settings to env 446955SN/A sticky_opts.Update(env) 4472632Sstever@eecs.umich.edu nonsticky_opts.Update(env) 4482632Sstever@eecs.umich.edu 4492632Sstever@eecs.umich.edu help_text += "Sticky options for %s:\n" % build_dir \ 4502632Sstever@eecs.umich.edu + sticky_opts.GenerateHelpText(env) \ 4512632Sstever@eecs.umich.edu + "\nNon-sticky options for %s:\n" % build_dir \ 4522632Sstever@eecs.umich.edu + nonsticky_opts.GenerateHelpText(env) 4532632Sstever@eecs.umich.edu 4548268Ssteve.reinhardt@amd.com # Process option settings. 4558268Ssteve.reinhardt@amd.com 4568268Ssteve.reinhardt@amd.com if not have_fenv and env['USE_FENV']: 4578268Ssteve.reinhardt@amd.com print "Warning: <fenv.h> not available; " \ 4588268Ssteve.reinhardt@amd.com "forcing USE_FENV to False in", build_dir + "." 4598268Ssteve.reinhardt@amd.com env['USE_FENV'] = False 4608268Ssteve.reinhardt@amd.com 4612632Sstever@eecs.umich.edu if not env['USE_FENV']: 4622632Sstever@eecs.umich.edu print "Warning: No IEEE FP rounding mode control in", build_dir + "." 4632632Sstever@eecs.umich.edu print " FP results may deviate slightly from other platforms." 4642632Sstever@eecs.umich.edu 4658268Ssteve.reinhardt@amd.com if env['EFENCE']: 4662632Sstever@eecs.umich.edu env.Append(LIBS=['efence']) 4678268Ssteve.reinhardt@amd.com 4688268Ssteve.reinhardt@amd.com if env['USE_MYSQL']: 4698268Ssteve.reinhardt@amd.com if not have_mysql: 4708268Ssteve.reinhardt@amd.com print "Warning: MySQL not available; " \ 4713718Sstever@eecs.umich.edu "forcing USE_MYSQL to False in", build_dir + "." 4722634Sstever@eecs.umich.edu env['USE_MYSQL'] = False 4732634Sstever@eecs.umich.edu else: 4745863Snate@binkert.org print "Compiling in", build_dir, "with MySQL support." 4752638Sstever@eecs.umich.edu env.ParseConfig(mysql_config_libs) 4768268Ssteve.reinhardt@amd.com env.ParseConfig(mysql_config_include) 4772632Sstever@eecs.umich.edu 4782632Sstever@eecs.umich.edu # Check if the Checker is being used. If so append it to env['CPU_MODELS'] 4792632Sstever@eecs.umich.edu if env['USE_CHECKER']: 4802632Sstever@eecs.umich.edu env['CPU_MODELS'].append('CheckerCPU') 4812632Sstever@eecs.umich.edu 4821858SN/A # Save sticky option settings back to current options file 4833716Sstever@eecs.umich.edu sticky_opts.Save(current_opts_file, env) 4842638Sstever@eecs.umich.edu 4852638Sstever@eecs.umich.edu # Do this after we save setting back, or else we'll tack on an 4862638Sstever@eecs.umich.edu # extra 'qdo' every time we run scons. 4872638Sstever@eecs.umich.edu if env['BATCH']: 4882638Sstever@eecs.umich.edu env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 4892638Sstever@eecs.umich.edu env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 4902638Sstever@eecs.umich.edu 4915863Snate@binkert.org if env['USE_SSE2']: 4925863Snate@binkert.org env.Append(CCFLAGS='-msse2') 4935863Snate@binkert.org 494955SN/A # The src/SConscript file sets up the build rules in 'env' according 4955341Sstever@gmail.com # to the configured options. It returns a list of environments, 4965341Sstever@gmail.com # one for each variant build (debug, opt, etc.) 4975863Snate@binkert.org envList = SConscript('src/SConscript', build_dir = build_path, 4987756SAli.Saidi@ARM.com exports = 'env') 4995341Sstever@gmail.com 5006121Snate@binkert.org # Set up the regression tests for each build. 5014494Ssaidi@eecs.umich.edu# for e in envList: 5026121Snate@binkert.org# SConscript('m5-test/SConscript', 5031105SN/A# build_dir = os.path.join(build_dir, 'test', e.Label), 5042667Sstever@eecs.umich.edu# exports = { 'env' : e }, duplicate = False) 5052667Sstever@eecs.umich.edu 5062667Sstever@eecs.umich.eduHelp(help_text) 5072667Sstever@eecs.umich.edu 5086121Snate@binkert.org################################################### 5092667Sstever@eecs.umich.edu# 5105341Sstever@gmail.com# Let SCons do its thing. At this point SCons will use the defined 5115863Snate@binkert.org# build environments to build the requested targets. 5125341Sstever@gmail.com# 5135341Sstever@gmail.com################################################### 5145341Sstever@gmail.com 5158120Sgblack@eecs.umich.edu