SConstruct revision 2761
1955SN/A# -*- mode:python -*- 2955SN/A 314044Sciro.santilli@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) 8112563Sgabeblack@google.comtry: 8212563Sgabeblack@google.com EnsureSConsVersion(*min_scons_version) 836654Snate@binkert.orgexcept: 8410196SCurtis.Dunham@arm.com print "Error checking current SCons version." 85955SN/A print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 865396Ssaidi@eecs.umich.edu Exit(2) 8711401Sandreas.sandberg@arm.com 885863Snate@binkert.org 895863Snate@binkert.org# The absolute path to the current directory (where this file lives). 904202Sbinkertn@umich.eduROOT = Dir('.').abspath 915863Snate@binkert.org 925863Snate@binkert.org# Paths to the M5 and external source trees. 935863Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src') 945863Snate@binkert.org 9513541Sandrea.mondelli@ucf.edu# tell python where to find m5 python code 96955SN/Asys.path.append(os.path.join(ROOT, 'src/python')) 976654Snate@binkert.org 985273Sstever@gmail.com################################################### 995871Snate@binkert.org# 10013758Sgabeblack@google.com# Figure out which configurations to set up based on the path(s) of 1015273Sstever@gmail.com# the target(s). 1026654Snate@binkert.org# 1035396Ssaidi@eecs.umich.edu################################################### 1048120Sgblack@eecs.umich.edu 1058120Sgblack@eecs.umich.edu# Find default configuration & binary. 1068120Sgblack@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1078120Sgblack@eecs.umich.edu 1088120Sgblack@eecs.umich.edu# Ask SCons which directory it was invoked from. 1098120Sgblack@eecs.umich.edulaunch_dir = GetLaunchDir() 1108120Sgblack@eecs.umich.edu 1118120Sgblack@eecs.umich.edu# Make targets relative to invocation directory 1128879Ssteve.reinhardt@amd.comabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 1138879Ssteve.reinhardt@amd.com BUILD_TARGETS) 1148879Ssteve.reinhardt@amd.com 1158879Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list 1168879Ssteve.reinhardt@amd.comdef rfind(l, elt, offs = -1): 1178879Ssteve.reinhardt@amd.com for i in range(len(l)+offs, 0, -1): 1188879Ssteve.reinhardt@amd.com if l[i] == elt: 1198879Ssteve.reinhardt@amd.com return i 1208879Ssteve.reinhardt@amd.com raise ValueError, "element not found" 1218879Ssteve.reinhardt@amd.com 1228879Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the 1238879Ssteve.reinhardt@amd.com# directory below this will determine the build parameters. For 1248879Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1258120Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 1268120Sgblack@eecs.umich.edu# follow 'build' in the bulid path. 1278120Sgblack@eecs.umich.edu 1288120Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1298120Sgblack@eecs.umich.edu# collected targets reference. 1308120Sgblack@eecs.umich.edubuild_paths = [] 1318120Sgblack@eecs.umich.edubuild_root = None 1328120Sgblack@eecs.umich.edufor t in abs_targets: 1338120Sgblack@eecs.umich.edu path_dirs = t.split('/') 1348120Sgblack@eecs.umich.edu try: 1358120Sgblack@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 1368120Sgblack@eecs.umich.edu except: 1378120Sgblack@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 1388120Sgblack@eecs.umich.edu Exit(1) 1398879Ssteve.reinhardt@amd.com this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1408879Ssteve.reinhardt@amd.com if not build_root: 1418879Ssteve.reinhardt@amd.com build_root = this_build_root 1428879Ssteve.reinhardt@amd.com else: 14310458Sandreas.hansson@arm.com if this_build_root != build_root: 14410458Sandreas.hansson@arm.com print "Error: build targets not under same build root\n"\ 14510458Sandreas.hansson@arm.com " %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) 15013421Sciro.santilli@arm.com 15113421Sciro.santilli@arm.com################################################### 1529227Sandreas.hansson@arm.com# 1539227Sandreas.hansson@arm.com# Set up the default build environment. This environment is copied 15412063Sgabeblack@google.com# and modified according to each selected configuration. 15512063Sgabeblack@google.com# 15612063Sgabeblack@google.com################################################### 1578879Ssteve.reinhardt@amd.com 1588879Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ, # inherit user's environment vars 1598879Ssteve.reinhardt@amd.com ROOT = ROOT, 1608879Ssteve.reinhardt@amd.com SRCDIR = SRCDIR) 16110453SAndrew.Bardsley@arm.com 16210453SAndrew.Bardsley@arm.comenv.SConsignFile("sconsign") 16310453SAndrew.Bardsley@arm.com 16410456SCurtis.Dunham@arm.com# Default duplicate option is to use hard links, but this messes up 16510456SCurtis.Dunham@arm.com# when you use emacs to edit a file in the target dir, as emacs moves 16610456SCurtis.Dunham@arm.com# file to file~ then copies to file, breaking the link. Symbolic 16710457Sandreas.hansson@arm.com# (soft) links work better. 16810457Sandreas.hansson@arm.comenv.SetOption('duplicate', 'soft-copy') 16911342Sandreas.hansson@arm.com 17011342Sandreas.hansson@arm.com# 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 17212063Sgabeblack@google.com# noticeably longer. 17312563Sgabeblack@google.comif False: 17412063Sgabeblack@google.com env.TargetSignatures('content') 17512063Sgabeblack@google.com 1765871Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package. 1775871Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 1786121Snate@binkert.org 1795871Snate@binkert.org# Set up default C++ compiler flags 1805871Snate@binkert.orgenv.Append(CCFLAGS='-pipe') 1819926Sstan.czerniawski@arm.comenv.Append(CCFLAGS='-fno-strict-aliasing') 18212243Sgabeblack@google.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1831533SN/Aif sys.platform == 'cygwin': 18412246Sgabeblack@google.com # cygwin has some header file issues... 18512246Sgabeblack@google.com env.Append(CCFLAGS=Split("-Wno-uninitialized")) 18612246Sgabeblack@google.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 18712246Sgabeblack@google.com 1889239Sandreas.hansson@arm.com# Find Python include and library directories for embedding the 1899239Sandreas.hansson@arm.com# interpreter. For consistency, we will use the same Python 1909239Sandreas.hansson@arm.com# installation used to run scons (and thus this script). If you want 1919239Sandreas.hansson@arm.com# to link in an alternate version, see above for instructions on how 19212563Sgabeblack@google.com# to invoke scons with a different copy of the Python interpreter. 1939239Sandreas.hansson@arm.com 1949239Sandreas.hansson@arm.com# Get brief Python version name (e.g., "python2.4") for locating 195955SN/A# include & library files 196955SN/Apy_version_name = 'python' + sys.version[:3] 1972632Sstever@eecs.umich.edu 1982632Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4 199955SN/Aenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name)) 200955SN/Aenv.Append(LIBS = py_version_name) 201955SN/A# add library path too if it's not in the default place 202955SN/Aif sys.exec_prefix != '/usr': 2038878Ssteve.reinhardt@amd.com env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib')) 204955SN/A 2052632Sstever@eecs.umich.edu# Set up SWIG flags & scanner 2062632Sstever@eecs.umich.edu 2072632Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2082632Sstever@eecs.umich.edu 2092632Sstever@eecs.umich.eduimport SCons.Scanner 2102632Sstever@eecs.umich.edu 2112632Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2128268Ssteve.reinhardt@amd.com 2138268Ssteve.reinhardt@amd.comswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2148268Ssteve.reinhardt@amd.com swig_inc_re) 2158268Ssteve.reinhardt@amd.com 2168268Ssteve.reinhardt@amd.comenv.Append(SCANNERS = swig_scanner) 2178268Ssteve.reinhardt@amd.com 2188268Ssteve.reinhardt@amd.com# Other default libraries 21913715Sandreas.sandberg@arm.comenv.Append(LIBS=['z']) 22013715Sandreas.sandberg@arm.com 22113715Sandreas.sandberg@arm.com# Platform-specific configuration. Note again that we assume that all 22213715Sandreas.sandberg@arm.com# builds under a given build root run on the same host platform. 22313715Sandreas.sandberg@arm.comconf = Configure(env, 22413715Sandreas.sandberg@arm.com conf_dir = os.path.join(build_root, '.scons_config'), 22513715Sandreas.sandberg@arm.com log_file = os.path.join(build_root, 'scons_config.log')) 22613715Sandreas.sandberg@arm.com 22713715Sandreas.sandberg@arm.com# Check for <fenv.h> (C99 FP environment control) 22813715Sandreas.sandberg@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 22913715Sandreas.sandberg@arm.comif not have_fenv: 23013715Sandreas.sandberg@arm.com print "Warning: Header file <fenv.h> not found." 23113715Sandreas.sandberg@arm.com print " This host has no IEEE FP rounding mode control." 2322632Sstever@eecs.umich.edu 2332632Sstever@eecs.umich.edu# Check for mysql. 2342632Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config') 2352632Sstever@eecs.umich.eduhave_mysql = mysql_config != None 2368268Ssteve.reinhardt@amd.com 2372632Sstever@eecs.umich.edu# Check MySQL version. 2388268Ssteve.reinhardt@amd.comif have_mysql: 2398268Ssteve.reinhardt@amd.com mysql_version = os.popen(mysql_config + ' --version').read() 2408268Ssteve.reinhardt@amd.com mysql_version = mysql_version.split('.') 2418268Ssteve.reinhardt@amd.com mysql_major = int(mysql_version[0]) 2423718Sstever@eecs.umich.edu mysql_minor = int(mysql_version[1]) 2432634Sstever@eecs.umich.edu # This version check is probably overly conservative, but it deals 2442634Sstever@eecs.umich.edu # with the versions we have installed. 2455863Snate@binkert.org if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1): 2462638Sstever@eecs.umich.edu print "Warning: MySQL v4.1 or newer required." 2478268Ssteve.reinhardt@amd.com have_mysql = False 2482632Sstever@eecs.umich.edu 2492632Sstever@eecs.umich.edu# Set up mysql_config commands. 2502632Sstever@eecs.umich.eduif have_mysql: 2512632Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 25212563Sgabeblack@google.com if os.system(mysql_config_include + ' > /dev/null') != 0: 2531858SN/A # older mysql_config versions don't support --include, use 2543716Sstever@eecs.umich.edu # --cflags instead 2552638Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 2562638Sstever@eecs.umich.edu # This seems to work in all versions 2572638Sstever@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 2582638Sstever@eecs.umich.edu 25912563Sgabeblack@google.comenv = conf.Finish() 26012563Sgabeblack@google.com 2612638Sstever@eecs.umich.edu# Define the universe of supported ISAs 2625863Snate@binkert.orgenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 2635863Snate@binkert.org 2645863Snate@binkert.org# Define the universe of supported CPU models 265955SN/Aenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 2665341Sstever@gmail.com 'FullCPU', 'AlphaO3CPU', 2675341Sstever@gmail.com 'OzoneSimpleCPU', 'OzoneCPU'] 2685863Snate@binkert.org 2697756SAli.Saidi@ARM.com# Sticky options get saved in the options file so they persist from 2705341Sstever@gmail.com# one invocation to the next (unless overridden, in which case the new 2716121Snate@binkert.org# value becomes sticky). 2724494Ssaidi@eecs.umich.edusticky_opts = Options(args=ARGUMENTS) 2736121Snate@binkert.orgsticky_opts.AddOptions( 2741105SN/A EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 2752667Sstever@eecs.umich.edu BoolOption('FULL_SYSTEM', 'Full-system support', False), 2762667Sstever@eecs.umich.edu # There's a bug in scons 0.96.1 that causes ListOptions with list 2772667Sstever@eecs.umich.edu # values (more than one value) not to be able to be restored from 2782667Sstever@eecs.umich.edu # a saved option file. If this causes trouble then upgrade to 2796121Snate@binkert.org # scons 0.96.90 or later. 2802667Sstever@eecs.umich.edu ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 2815341Sstever@gmail.com env['ALL_CPU_LIST']), 2825863Snate@binkert.org BoolOption('ALPHA_TLASER', 2835341Sstever@gmail.com 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 2845341Sstever@gmail.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 2855341Sstever@gmail.com BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 2868120Sgblack@eecs.umich.edu False), 2875341Sstever@gmail.com BoolOption('SS_COMPATIBLE_FP', 2888120Sgblack@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 2895341Sstever@gmail.com False), 2908120Sgblack@eecs.umich.edu BoolOption('USE_SSE2', 2916121Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 2926121Snate@binkert.org False), 29314044Sciro.santilli@arm.com BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 29414044Sciro.santilli@arm.com BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 29513715Sandreas.sandberg@arm.com BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 29613715Sandreas.sandberg@arm.com ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 2979396Sandreas.hansson@arm.com ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 2985397Ssaidi@eecs.umich.edu BoolOption('BATCH', 'Use batch pool for build and tests', False), 2995397Ssaidi@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo') 3007727SAli.Saidi@ARM.com ) 3018268Ssteve.reinhardt@amd.com 3026168Snate@binkert.org# Non-sticky options only apply to the current build. 3035341Sstever@gmail.comnonsticky_opts = Options(args=ARGUMENTS) 3048120Sgblack@eecs.umich.edunonsticky_opts.AddOptions( 3058120Sgblack@eecs.umich.edu BoolOption('update_ref', 'Update test reference outputs', False) 3068120Sgblack@eecs.umich.edu ) 3076814Sgblack@eecs.umich.edu 3085863Snate@binkert.org# These options get exported to #defines in config/*.hh (see src/SConscript). 3098120Sgblack@eecs.umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 3105341Sstever@gmail.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 3115863Snate@binkert.org 'USE_CHECKER'] 3128268Ssteve.reinhardt@amd.com 3136121Snate@binkert.org# Define a handy 'no-op' action 3146121Snate@binkert.orgdef no_action(target, source, env): 3158268Ssteve.reinhardt@amd.com return 0 3165742Snate@binkert.org 3175742Snate@binkert.orgenv.NoAction = Action(no_action, None) 3185341Sstever@gmail.com 3195742Snate@binkert.org################################################### 3205742Snate@binkert.org# 3215341Sstever@gmail.com# Define a SCons builder for configuration flag headers. 3226017Snate@binkert.org# 3236121Snate@binkert.org################################################### 3246017Snate@binkert.org 32512158Sandreas.sandberg@arm.com# This function generates a config header file that #defines the 32612158Sandreas.sandberg@arm.com# option symbol to the current option setting (0 or 1). The source 32712158Sandreas.sandberg@arm.com# operands are the name of the option and a Value node containing the 3288120Sgblack@eecs.umich.edu# value of the option. 3297756SAli.Saidi@ARM.comdef build_config_file(target, source, env): 3307756SAli.Saidi@ARM.com (option, value) = [s.get_contents() for s in source] 3317756SAli.Saidi@ARM.com f = file(str(target[0]), 'w') 3327756SAli.Saidi@ARM.com print >> f, '#define', option, value 3337816Ssteve.reinhardt@amd.com f.close() 3347816Ssteve.reinhardt@amd.com return None 3357816Ssteve.reinhardt@amd.com 3367816Ssteve.reinhardt@amd.com# Generate the message to be printed when building the config file. 3377816Ssteve.reinhardt@amd.comdef build_config_file_string(target, source, env): 33811979Sgabeblack@google.com (option, value) = [s.get_contents() for s in source] 3397816Ssteve.reinhardt@amd.com return "Defining %s as %s in %s." % (option, value, target[0]) 3407816Ssteve.reinhardt@amd.com 3417816Ssteve.reinhardt@amd.com# Combine the two functions into a scons Action object. 3427816Ssteve.reinhardt@amd.comconfig_action = Action(build_config_file, build_config_file_string) 3437756SAli.Saidi@ARM.com 3447756SAli.Saidi@ARM.com# The emitter munges the source & target node lists to reflect what 3459227Sandreas.hansson@arm.com# we're really doing. 3469227Sandreas.hansson@arm.comdef config_emitter(target, source, env): 3479227Sandreas.hansson@arm.com # extract option name from Builder arg 3489227Sandreas.hansson@arm.com option = str(target[0]) 3499590Sandreas@sandberg.pp.se # True target is config header file 3509590Sandreas@sandberg.pp.se target = os.path.join('config', option.lower() + '.hh') 3519590Sandreas@sandberg.pp.se # Force value to 0/1 even if it's a Python bool 3529590Sandreas@sandberg.pp.se val = int(eval(str(env[option]))) 3539590Sandreas@sandberg.pp.se # Sources are option name & value (packaged in SCons Value nodes) 3549590Sandreas@sandberg.pp.se return ([target], [Value(option), Value(val)]) 3556654Snate@binkert.org 3566654Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 3575871Snate@binkert.org 3586121Snate@binkert.orgenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 3598946Sandreas.hansson@arm.com 3609419Sandreas.hansson@arm.com################################################### 36112563Sgabeblack@google.com# 3623918Ssaidi@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 3633918Ssaidi@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here 3641858SN/A# since it's potentially more generally applicable. 3659556Sandreas.hansson@arm.com# 3669556Sandreas.hansson@arm.com################################################### 3679556Sandreas.hansson@arm.com 3689556Sandreas.hansson@arm.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 36911294Sandreas.hansson@arm.com 37011294Sandreas.hansson@arm.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 37111294Sandreas.hansson@arm.com 37211294Sandreas.hansson@arm.com################################################### 37310878Sandreas.hansson@arm.com# 37410878Sandreas.hansson@arm.com# Define a simple SCons builder to concatenate files. 37511811Sbaz21@cam.ac.uk# 37611811Sbaz21@cam.ac.uk# Used to append the Python zip archive to the executable. 37711811Sbaz21@cam.ac.uk# 37811982Sgabeblack@google.com################################################### 37911982Sgabeblack@google.com 38011982Sgabeblack@google.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 38113421Sciro.santilli@arm.com 'chmod +x $TARGET'])) 38213421Sciro.santilli@arm.com 38311982Sgabeblack@google.comenv.Append(BUILDERS = { 'Concat' : concat_builder }) 38411992Sgabeblack@google.com 38511982Sgabeblack@google.com 38611982Sgabeblack@google.com# base help text 38712305Sgabeblack@google.comhelp_text = ''' 38812305Sgabeblack@google.comUsage: scons [scons options] [build options] [target(s)] 38912305Sgabeblack@google.com 39012305Sgabeblack@google.com''' 39112305Sgabeblack@google.com 39212305Sgabeblack@google.com# libelf build is shared across all configs in the build root. 39312305Sgabeblack@google.comenv.SConscript('ext/libelf/SConscript', 3949556Sandreas.hansson@arm.com build_dir = os.path.join(build_root, 'libelf'), 39512563Sgabeblack@google.com exports = 'env') 39612563Sgabeblack@google.com 39712563Sgabeblack@google.com################################################### 39812563Sgabeblack@google.com# 3999556Sandreas.hansson@arm.com# Define build environments for selected configurations. 40012563Sgabeblack@google.com# 40112563Sgabeblack@google.com################################################### 4029556Sandreas.hansson@arm.com 40312563Sgabeblack@google.com# rename base env 40412563Sgabeblack@google.combase_env = env 40512563Sgabeblack@google.com 40612563Sgabeblack@google.comfor build_path in build_paths: 40712563Sgabeblack@google.com print "Building in", build_path 40812563Sgabeblack@google.com # build_dir is the tail component of build path, and is used to 40912563Sgabeblack@google.com # determine the build parameters (e.g., 'ALPHA_SE') 41012563Sgabeblack@google.com (build_root, build_dir) = os.path.split(build_path) 4119556Sandreas.hansson@arm.com # Make a copy of the build-root environment to use for this config. 4129556Sandreas.hansson@arm.com env = base_env.Copy() 4136121Snate@binkert.org 41411500Sandreas.hansson@arm.com # Set env options according to the build directory config. 41510238Sandreas.hansson@arm.com sticky_opts.files = [] 41610878Sandreas.hansson@arm.com # Options for $BUILD_ROOT/$BUILD_DIR are stored in 4179420Sandreas.hansson@arm.com # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 41811500Sandreas.hansson@arm.com # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 41912563Sgabeblack@google.com current_opts_file = os.path.join(build_root, 'options', build_dir) 42012563Sgabeblack@google.com if os.path.isfile(current_opts_file): 4219420Sandreas.hansson@arm.com sticky_opts.files.append(current_opts_file) 4229420Sandreas.hansson@arm.com print "Using saved options file %s" % current_opts_file 4239420Sandreas.hansson@arm.com else: 4249420Sandreas.hansson@arm.com # Build dir-specific options file doesn't exist. 42512063Sgabeblack@google.com 42612063Sgabeblack@google.com # Make sure the directory is there so we can create it later 42712063Sgabeblack@google.com opt_dir = os.path.dirname(current_opts_file) 42812063Sgabeblack@google.com if not os.path.isdir(opt_dir): 42912063Sgabeblack@google.com os.mkdir(opt_dir) 43012063Sgabeblack@google.com 43112063Sgabeblack@google.com # Get default build options from source tree. Options are 43212063Sgabeblack@google.com # normally determined by name of $BUILD_DIR, but can be 43312063Sgabeblack@google.com # overriden by 'default=' arg on command line. 43412063Sgabeblack@google.com default_opts_file = os.path.join('build_opts', 43512063Sgabeblack@google.com ARGUMENTS.get('default', build_dir)) 43612063Sgabeblack@google.com if os.path.isfile(default_opts_file): 43712063Sgabeblack@google.com sticky_opts.files.append(default_opts_file) 43812063Sgabeblack@google.com print "Options file %s not found,\n using defaults in %s" \ 43912063Sgabeblack@google.com % (current_opts_file, default_opts_file) 44012063Sgabeblack@google.com else: 44112063Sgabeblack@google.com print "Error: cannot find options file %s or %s" \ 44212063Sgabeblack@google.com % (current_opts_file, default_opts_file) 44312063Sgabeblack@google.com Exit(1) 44412063Sgabeblack@google.com 44512063Sgabeblack@google.com # Apply current option settings to env 44612063Sgabeblack@google.com sticky_opts.Update(env) 44710457Sandreas.hansson@arm.com nonsticky_opts.Update(env) 44810457Sandreas.hansson@arm.com 44910457Sandreas.hansson@arm.com help_text += "Sticky options for %s:\n" % build_dir \ 45010457Sandreas.hansson@arm.com + sticky_opts.GenerateHelpText(env) \ 45110457Sandreas.hansson@arm.com + "\nNon-sticky options for %s:\n" % build_dir \ 45212563Sgabeblack@google.com + nonsticky_opts.GenerateHelpText(env) 45312563Sgabeblack@google.com 45412563Sgabeblack@google.com # Process option settings. 45510457Sandreas.hansson@arm.com 45612063Sgabeblack@google.com if not have_fenv and env['USE_FENV']: 45712063Sgabeblack@google.com print "Warning: <fenv.h> not available; " \ 45812063Sgabeblack@google.com "forcing USE_FENV to False in", build_dir + "." 45912563Sgabeblack@google.com env['USE_FENV'] = False 46012563Sgabeblack@google.com 46112563Sgabeblack@google.com if not env['USE_FENV']: 46212563Sgabeblack@google.com print "Warning: No IEEE FP rounding mode control in", build_dir + "." 46312563Sgabeblack@google.com print " FP results may deviate slightly from other platforms." 46412563Sgabeblack@google.com 46512063Sgabeblack@google.com if env['EFENCE']: 46612063Sgabeblack@google.com env.Append(LIBS=['efence']) 46710238Sandreas.hansson@arm.com 46810238Sandreas.hansson@arm.com if env['USE_MYSQL']: 46910238Sandreas.hansson@arm.com if not have_mysql: 47012063Sgabeblack@google.com print "Warning: MySQL not available; " \ 47110238Sandreas.hansson@arm.com "forcing USE_MYSQL to False in", build_dir + "." 47210238Sandreas.hansson@arm.com env['USE_MYSQL'] = False 47310416Sandreas.hansson@arm.com else: 47410238Sandreas.hansson@arm.com print "Compiling in", build_dir, "with MySQL support." 4759227Sandreas.hansson@arm.com env.ParseConfig(mysql_config_libs) 47610238Sandreas.hansson@arm.com env.ParseConfig(mysql_config_include) 47710416Sandreas.hansson@arm.com 47810416Sandreas.hansson@arm.com # Check if the Checker is being used. If so append it to env['CPU_MODELS'] 4799227Sandreas.hansson@arm.com if env['USE_CHECKER']: 4809590Sandreas@sandberg.pp.se env['CPU_MODELS'].append('CheckerCPU') 4819590Sandreas@sandberg.pp.se 4829590Sandreas@sandberg.pp.se # Save sticky option settings back to current options file 48312304Sgabeblack@google.com sticky_opts.Save(current_opts_file, env) 48412304Sgabeblack@google.com 48512304Sgabeblack@google.com # Do this after we save setting back, or else we'll tack on an 48612688Sgiacomo.travaglini@arm.com # extra 'qdo' every time we run scons. 48712688Sgiacomo.travaglini@arm.com if env['BATCH']: 48812688Sgiacomo.travaglini@arm.com env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 48913020Sshunhsingou@google.com env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 49012304Sgabeblack@google.com 49112688Sgiacomo.travaglini@arm.com if env['USE_SSE2']: 49212688Sgiacomo.travaglini@arm.com env.Append(CCFLAGS='-msse2') 49313020Sshunhsingou@google.com 49412304Sgabeblack@google.com # The src/SConscript file sets up the build rules in 'env' according 49512304Sgabeblack@google.com # to the configured options. It returns a list of environments, 49612304Sgabeblack@google.com # one for each variant build (debug, opt, etc.) 49712304Sgabeblack@google.com envList = SConscript('src/SConscript', build_dir = build_path, 49812688Sgiacomo.travaglini@arm.com exports = 'env') 49912688Sgiacomo.travaglini@arm.com 50012688Sgiacomo.travaglini@arm.com # Set up the regression tests for each build. 50112304Sgabeblack@google.com# for e in envList: 5028737Skoansin.tan@gmail.com# SConscript('m5-test/SConscript', 50310878Sandreas.hansson@arm.com# build_dir = os.path.join(build_dir, 'test', e.Label), 50411500Sandreas.hansson@arm.com# exports = { 'env' : e }, duplicate = False) 5059420Sandreas.hansson@arm.com 5068737Skoansin.tan@gmail.comHelp(help_text) 50710106SMitch.Hayenga@arm.com 5088737Skoansin.tan@gmail.com################################################### 5098737Skoansin.tan@gmail.com# 51010878Sandreas.hansson@arm.com# Let SCons do its thing. At this point SCons will use the defined 51112563Sgabeblack@google.com# build environments to build the requested targets. 51212563Sgabeblack@google.com# 5138737Skoansin.tan@gmail.com################################################### 5148737Skoansin.tan@gmail.com 51512563Sgabeblack@google.com