SConstruct revision 2653:c27948389a6e
19651SAndreas.Sandberg@ARM.com# -*- mode:python -*- 29651SAndreas.Sandberg@ARM.com 39651SAndreas.Sandberg@ARM.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 49651SAndreas.Sandberg@ARM.com# All rights reserved. 59651SAndreas.Sandberg@ARM.com# 69651SAndreas.Sandberg@ARM.com# Redistribution and use in source and binary forms, with or without 79651SAndreas.Sandberg@ARM.com# modification, are permitted provided that the following conditions are 89651SAndreas.Sandberg@ARM.com# met: redistributions of source code must retain the above copyright 99651SAndreas.Sandberg@ARM.com# notice, this list of conditions and the following disclaimer; 109651SAndreas.Sandberg@ARM.com# redistributions in binary form must reproduce the above copyright 119651SAndreas.Sandberg@ARM.com# notice, this list of conditions and the following disclaimer in the 129651SAndreas.Sandberg@ARM.com# documentation and/or other materials provided with the distribution; 139651SAndreas.Sandberg@ARM.com# neither the name of the copyright holders nor the names of its 149651SAndreas.Sandberg@ARM.com# contributors may be used to endorse or promote products derived from 159651SAndreas.Sandberg@ARM.com# this software without specific prior written permission. 169651SAndreas.Sandberg@ARM.com# 179651SAndreas.Sandberg@ARM.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 189651SAndreas.Sandberg@ARM.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 199651SAndreas.Sandberg@ARM.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 209651SAndreas.Sandberg@ARM.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 219651SAndreas.Sandberg@ARM.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 229651SAndreas.Sandberg@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 239651SAndreas.Sandberg@ARM.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 249651SAndreas.Sandberg@ARM.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 259651SAndreas.Sandberg@ARM.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 269651SAndreas.Sandberg@ARM.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 279651SAndreas.Sandberg@ARM.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 289651SAndreas.Sandberg@ARM.com 299651SAndreas.Sandberg@ARM.com################################################### 309651SAndreas.Sandberg@ARM.com# 319651SAndreas.Sandberg@ARM.com# SCons top-level build description (SConstruct) file. 329651SAndreas.Sandberg@ARM.com# 339651SAndreas.Sandberg@ARM.com# While in this directory ('m5'), just type 'scons' to build the default 349651SAndreas.Sandberg@ARM.com# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 359651SAndreas.Sandberg@ARM.com# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 369651SAndreas.Sandberg@ARM.com# the optimized full-system version). 379651SAndreas.Sandberg@ARM.com# 389651SAndreas.Sandberg@ARM.com# You can build M5 in a different directory as long as there is a 399651SAndreas.Sandberg@ARM.com# 'build/<CONFIG>' somewhere along the target path. The build system 409651SAndreas.Sandberg@ARM.com# expdects that all configs under the same build directory are being 419651SAndreas.Sandberg@ARM.com# built for the same host system. 429651SAndreas.Sandberg@ARM.com# 439651SAndreas.Sandberg@ARM.com# Examples: 449651SAndreas.Sandberg@ARM.com# These two commands are equivalent. The '-u' option tells scons to 459651SAndreas.Sandberg@ARM.com# search up the directory tree for this SConstruct file. 469651SAndreas.Sandberg@ARM.com# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 479651SAndreas.Sandberg@ARM.com# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 489651SAndreas.Sandberg@ARM.com# These two commands are equivalent and demonstrate building in a 499651SAndreas.Sandberg@ARM.com# directory outside of the source tree. The '-C' option tells scons 509651SAndreas.Sandberg@ARM.com# to chdir to the specified directory to find this SConstruct file. 519651SAndreas.Sandberg@ARM.com# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 529651SAndreas.Sandberg@ARM.com# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 539651SAndreas.Sandberg@ARM.com# 549651SAndreas.Sandberg@ARM.com# You can use 'scons -H' to print scons options. If you're in this 559651SAndreas.Sandberg@ARM.com# 'm5' directory (or use -u or -C to tell scons where to find this 569651SAndreas.Sandberg@ARM.com# file), you can use 'scons -h' to print all the M5-specific build 579651SAndreas.Sandberg@ARM.com# options as well. 589651SAndreas.Sandberg@ARM.com# 599651SAndreas.Sandberg@ARM.com################################################### 609651SAndreas.Sandberg@ARM.com 619651SAndreas.Sandberg@ARM.com# Python library imports 629651SAndreas.Sandberg@ARM.comimport sys 639651SAndreas.Sandberg@ARM.comimport os 649651SAndreas.Sandberg@ARM.com 659651SAndreas.Sandberg@ARM.com# Check for recent-enough Python and SCons versions 669651SAndreas.Sandberg@ARM.comEnsurePythonVersion(2,3) 679651SAndreas.Sandberg@ARM.com 689651SAndreas.Sandberg@ARM.com# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 699651SAndreas.Sandberg@ARM.com# 3-element version number. 709651SAndreas.Sandberg@ARM.commin_scons_version = (0,96,91) 719651SAndreas.Sandberg@ARM.comtry: 729651SAndreas.Sandberg@ARM.com EnsureSConsVersion(*min_scons_version) 739651SAndreas.Sandberg@ARM.comexcept: 749651SAndreas.Sandberg@ARM.com print "Error checking current SCons version." 759651SAndreas.Sandberg@ARM.com print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 769651SAndreas.Sandberg@ARM.com Exit(2) 779651SAndreas.Sandberg@ARM.com 789651SAndreas.Sandberg@ARM.com 799651SAndreas.Sandberg@ARM.com# The absolute path to the current directory (where this file lives). 809651SAndreas.Sandberg@ARM.comROOT = Dir('.').abspath 819651SAndreas.Sandberg@ARM.com 829651SAndreas.Sandberg@ARM.com# Paths to the M5 and external source trees. 839651SAndreas.Sandberg@ARM.comSRCDIR = os.path.join(ROOT, 'src') 849651SAndreas.Sandberg@ARM.com 859651SAndreas.Sandberg@ARM.com# tell python where to find m5 python code 869651SAndreas.Sandberg@ARM.comsys.path.append(os.path.join(ROOT, 'src/python')) 879651SAndreas.Sandberg@ARM.com 889651SAndreas.Sandberg@ARM.com################################################### 899651SAndreas.Sandberg@ARM.com# 909651SAndreas.Sandberg@ARM.com# Figure out which configurations to set up based on the path(s) of 919651SAndreas.Sandberg@ARM.com# the target(s). 929651SAndreas.Sandberg@ARM.com# 939651SAndreas.Sandberg@ARM.com################################################### 949651SAndreas.Sandberg@ARM.com 959651SAndreas.Sandberg@ARM.com# Find default configuration & binary. 969651SAndreas.Sandberg@ARM.comDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 979651SAndreas.Sandberg@ARM.com 989651SAndreas.Sandberg@ARM.com# Ask SCons which directory it was invoked from. 999651SAndreas.Sandberg@ARM.comlaunch_dir = GetLaunchDir() 1009651SAndreas.Sandberg@ARM.com 1019651SAndreas.Sandberg@ARM.com# Make targets relative to invocation directory 1029651SAndreas.Sandberg@ARM.comabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 1039651SAndreas.Sandberg@ARM.com BUILD_TARGETS) 1049651SAndreas.Sandberg@ARM.com 1059651SAndreas.Sandberg@ARM.com# helper function: find last occurrence of element in list 1069651SAndreas.Sandberg@ARM.comdef rfind(l, elt, offs = -1): 1079651SAndreas.Sandberg@ARM.com for i in range(len(l)+offs, 0, -1): 1089651SAndreas.Sandberg@ARM.com if l[i] == elt: 1099651SAndreas.Sandberg@ARM.com return i 1109651SAndreas.Sandberg@ARM.com raise ValueError, "element not found" 1119651SAndreas.Sandberg@ARM.com 1129651SAndreas.Sandberg@ARM.com# Each target must have 'build' in the interior of the path; the 1139651SAndreas.Sandberg@ARM.com# directory below this will determine the build parameters. For 1149651SAndreas.Sandberg@ARM.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1159651SAndreas.Sandberg@ARM.com# recognize that ALPHA_SE specifies the configuration because it 1169651SAndreas.Sandberg@ARM.com# follow 'build' in the bulid path. 1179651SAndreas.Sandberg@ARM.com 1189651SAndreas.Sandberg@ARM.com# Generate a list of the unique build roots and configs that the 1199651SAndreas.Sandberg@ARM.com# collected targets reference. 1209651SAndreas.Sandberg@ARM.combuild_paths = [] 1219651SAndreas.Sandberg@ARM.combuild_root = None 1229651SAndreas.Sandberg@ARM.comfor t in abs_targets: 1239651SAndreas.Sandberg@ARM.com path_dirs = t.split('/') 1249651SAndreas.Sandberg@ARM.com try: 1259651SAndreas.Sandberg@ARM.com build_top = rfind(path_dirs, 'build', -2) 1269651SAndreas.Sandberg@ARM.com except: 1279651SAndreas.Sandberg@ARM.com print "Error: no non-leaf 'build' dir found on target path", t 1289651SAndreas.Sandberg@ARM.com Exit(1) 1299651SAndreas.Sandberg@ARM.com this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1309651SAndreas.Sandberg@ARM.com if not build_root: 1319651SAndreas.Sandberg@ARM.com build_root = this_build_root 1329651SAndreas.Sandberg@ARM.com else: 1339651SAndreas.Sandberg@ARM.com if this_build_root != build_root: 1349651SAndreas.Sandberg@ARM.com print "Error: build targets not under same build root\n"\ 1359651SAndreas.Sandberg@ARM.com " %s\n %s" % (build_root, this_build_root) 1369651SAndreas.Sandberg@ARM.com Exit(1) 1379651SAndreas.Sandberg@ARM.com build_path = os.path.join('/',*path_dirs[:build_top+2]) 1389651SAndreas.Sandberg@ARM.com if build_path not in build_paths: 1399651SAndreas.Sandberg@ARM.com build_paths.append(build_path) 1409651SAndreas.Sandberg@ARM.com 1419651SAndreas.Sandberg@ARM.com################################################### 1429651SAndreas.Sandberg@ARM.com# 1439651SAndreas.Sandberg@ARM.com# Set up the default build environment. This environment is copied 1449651SAndreas.Sandberg@ARM.com# and modified according to each selected configuration. 1459651SAndreas.Sandberg@ARM.com# 1469651SAndreas.Sandberg@ARM.com################################################### 1479651SAndreas.Sandberg@ARM.com 1489651SAndreas.Sandberg@ARM.comenv = Environment(ENV = os.environ, # inherit user's environment vars 1499651SAndreas.Sandberg@ARM.com ROOT = ROOT, 1509651SAndreas.Sandberg@ARM.com SRCDIR = SRCDIR) 1519651SAndreas.Sandberg@ARM.com 1529651SAndreas.Sandberg@ARM.comenv.SConsignFile("sconsign") 1539651SAndreas.Sandberg@ARM.com 1549651SAndreas.Sandberg@ARM.com# I waffle on this setting... it does avoid a few painful but 1559651SAndreas.Sandberg@ARM.com# unnecessary builds, but it also seems to make trivial builds take 1569651SAndreas.Sandberg@ARM.com# noticeably longer. 1579651SAndreas.Sandberg@ARM.comif False: 1589651SAndreas.Sandberg@ARM.com env.TargetSignatures('content') 1599651SAndreas.Sandberg@ARM.com 1609651SAndreas.Sandberg@ARM.com# M5_PLY is used by isa_parser.py to find the PLY package. 1619651SAndreas.Sandberg@ARM.comenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 1629651SAndreas.Sandberg@ARM.com 1639651SAndreas.Sandberg@ARM.com# Set up default C++ compiler flags 1649651SAndreas.Sandberg@ARM.comenv.Append(CCFLAGS='-pipe') 1659651SAndreas.Sandberg@ARM.comenv.Append(CCFLAGS='-fno-strict-aliasing') 1669651SAndreas.Sandberg@ARM.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1679651SAndreas.Sandberg@ARM.comif sys.platform == 'cygwin': 1689651SAndreas.Sandberg@ARM.com # cygwin has some header file issues... 1699651SAndreas.Sandberg@ARM.com env.Append(CCFLAGS=Split("-Wno-uninitialized")) 1709651SAndreas.Sandberg@ARM.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 1719651SAndreas.Sandberg@ARM.com 1729651SAndreas.Sandberg@ARM.com# Default libraries 1739651SAndreas.Sandberg@ARM.comenv.Append(LIBS=['z']) 1749651SAndreas.Sandberg@ARM.com 1759651SAndreas.Sandberg@ARM.com# Platform-specific configuration. Note again that we assume that all 1769651SAndreas.Sandberg@ARM.com# builds under a given build root run on the same host platform. 1779651SAndreas.Sandberg@ARM.comconf = Configure(env, 1789651SAndreas.Sandberg@ARM.com conf_dir = os.path.join(build_root, '.scons_config'), 1799651SAndreas.Sandberg@ARM.com log_file = os.path.join(build_root, 'scons_config.log')) 1809651SAndreas.Sandberg@ARM.com 1819651SAndreas.Sandberg@ARM.com# Check for <fenv.h> (C99 FP environment control) 1829651SAndreas.Sandberg@ARM.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 1839651SAndreas.Sandberg@ARM.comif not have_fenv: 1849651SAndreas.Sandberg@ARM.com print "Warning: Header file <fenv.h> not found." 1859651SAndreas.Sandberg@ARM.com print " This host has no IEEE FP rounding mode control." 1869651SAndreas.Sandberg@ARM.com 1879651SAndreas.Sandberg@ARM.com# Check for mysql. 1889651SAndreas.Sandberg@ARM.commysql_config = WhereIs('mysql_config') 1899651SAndreas.Sandberg@ARM.comhave_mysql = mysql_config != None 1909651SAndreas.Sandberg@ARM.com 1919651SAndreas.Sandberg@ARM.com# Check MySQL version. 1929651SAndreas.Sandberg@ARM.comif have_mysql: 1939651SAndreas.Sandberg@ARM.com mysql_version = os.popen(mysql_config + ' --version').read() 1949651SAndreas.Sandberg@ARM.com mysql_version = mysql_version.split('.') 1959651SAndreas.Sandberg@ARM.com mysql_major = int(mysql_version[0]) 1969651SAndreas.Sandberg@ARM.com mysql_minor = int(mysql_version[1]) 1979651SAndreas.Sandberg@ARM.com # This version check is probably overly conservative, but it deals 1989651SAndreas.Sandberg@ARM.com # with the versions we have installed. 1999651SAndreas.Sandberg@ARM.com if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1): 2009651SAndreas.Sandberg@ARM.com print "Warning: MySQL v4.1 or newer required." 2019651SAndreas.Sandberg@ARM.com have_mysql = False 2029651SAndreas.Sandberg@ARM.com 2039651SAndreas.Sandberg@ARM.com# Set up mysql_config commands. 2049651SAndreas.Sandberg@ARM.comif have_mysql: 2059651SAndreas.Sandberg@ARM.com mysql_config_include = mysql_config + ' --include' 2069651SAndreas.Sandberg@ARM.com if os.system(mysql_config_include + ' > /dev/null') != 0: 2079651SAndreas.Sandberg@ARM.com # older mysql_config versions don't support --include, use 2089651SAndreas.Sandberg@ARM.com # --cflags instead 2099651SAndreas.Sandberg@ARM.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 2109651SAndreas.Sandberg@ARM.com # This seems to work in all versions 2119651SAndreas.Sandberg@ARM.com mysql_config_libs = mysql_config + ' --libs' 2129651SAndreas.Sandberg@ARM.com 2139651SAndreas.Sandberg@ARM.comenv = conf.Finish() 2149651SAndreas.Sandberg@ARM.com 2159651SAndreas.Sandberg@ARM.com# Define the universe of supported ISAs 2169651SAndreas.Sandberg@ARM.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 2179651SAndreas.Sandberg@ARM.com 2189651SAndreas.Sandberg@ARM.com# Define the universe of supported CPU models 2199651SAndreas.Sandberg@ARM.comenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 2209651SAndreas.Sandberg@ARM.com 'FullCPU', 'AlphaFullCPU'] 2219651SAndreas.Sandberg@ARM.com 2229651SAndreas.Sandberg@ARM.com# Sticky options get saved in the options file so they persist from 2239651SAndreas.Sandberg@ARM.com# one invocation to the next (unless overridden, in which case the new 2249651SAndreas.Sandberg@ARM.com# value becomes sticky). 2259651SAndreas.Sandberg@ARM.comsticky_opts = Options(args=ARGUMENTS) 2269651SAndreas.Sandberg@ARM.comsticky_opts.AddOptions( 2279651SAndreas.Sandberg@ARM.com EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 2289651SAndreas.Sandberg@ARM.com BoolOption('FULL_SYSTEM', 'Full-system support', False), 2299651SAndreas.Sandberg@ARM.com # There's a bug in scons 0.96.1 that causes ListOptions with list 2309651SAndreas.Sandberg@ARM.com # values (more than one value) not to be able to be restored from 2319651SAndreas.Sandberg@ARM.com # a saved option file. If this causes trouble then upgrade to 2329651SAndreas.Sandberg@ARM.com # scons 0.96.90 or later. 2339651SAndreas.Sandberg@ARM.com ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 2349651SAndreas.Sandberg@ARM.com env['ALL_CPU_LIST']), 2359651SAndreas.Sandberg@ARM.com BoolOption('ALPHA_TLASER', 2369651SAndreas.Sandberg@ARM.com 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 2379651SAndreas.Sandberg@ARM.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 2389651SAndreas.Sandberg@ARM.com BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 2399651SAndreas.Sandberg@ARM.com False), 2409651SAndreas.Sandberg@ARM.com BoolOption('SS_COMPATIBLE_FP', 2419651SAndreas.Sandberg@ARM.com 'Make floating-point results compatible with SimpleScalar', 2429651SAndreas.Sandberg@ARM.com False), 2439651SAndreas.Sandberg@ARM.com BoolOption('USE_SSE2', 2449651SAndreas.Sandberg@ARM.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 2459651SAndreas.Sandberg@ARM.com False), 2469651SAndreas.Sandberg@ARM.com BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql), 2479651SAndreas.Sandberg@ARM.com BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 2489651SAndreas.Sandberg@ARM.com BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 2499651SAndreas.Sandberg@ARM.com ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 2509651SAndreas.Sandberg@ARM.com ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 2519651SAndreas.Sandberg@ARM.com BoolOption('BATCH', 'Use batch pool for build and tests', False), 2529651SAndreas.Sandberg@ARM.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo') 2539651SAndreas.Sandberg@ARM.com ) 2549651SAndreas.Sandberg@ARM.com 2559651SAndreas.Sandberg@ARM.com# Non-sticky options only apply to the current build. 2569651SAndreas.Sandberg@ARM.comnonsticky_opts = Options(args=ARGUMENTS) 2579651SAndreas.Sandberg@ARM.comnonsticky_opts.AddOptions( 2589651SAndreas.Sandberg@ARM.com BoolOption('update_ref', 'Update test reference outputs', False) 2599651SAndreas.Sandberg@ARM.com ) 2609651SAndreas.Sandberg@ARM.com 2619651SAndreas.Sandberg@ARM.com# These options get exported to #defines in config/*.hh (see m5/SConscript). 2629651SAndreas.Sandberg@ARM.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 2639651SAndreas.Sandberg@ARM.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 2649651SAndreas.Sandberg@ARM.com 'STATS_BINNING'] 2659651SAndreas.Sandberg@ARM.com 2669651SAndreas.Sandberg@ARM.com# Define a handy 'no-op' action 2679651SAndreas.Sandberg@ARM.comdef no_action(target, source, env): 2689651SAndreas.Sandberg@ARM.com return 0 2699651SAndreas.Sandberg@ARM.com 2709651SAndreas.Sandberg@ARM.comenv.NoAction = Action(no_action, None) 2719651SAndreas.Sandberg@ARM.com 2729651SAndreas.Sandberg@ARM.com################################################### 2739651SAndreas.Sandberg@ARM.com# 2749651SAndreas.Sandberg@ARM.com# Define a SCons builder for configuration flag headers. 2759651SAndreas.Sandberg@ARM.com# 2769651SAndreas.Sandberg@ARM.com################################################### 2779651SAndreas.Sandberg@ARM.com 2789651SAndreas.Sandberg@ARM.com# This function generates a config header file that #defines the 2799651SAndreas.Sandberg@ARM.com# option symbol to the current option setting (0 or 1). The source 2809651SAndreas.Sandberg@ARM.com# operands are the name of the option and a Value node containing the 2819651SAndreas.Sandberg@ARM.com# value of the option. 2829651SAndreas.Sandberg@ARM.comdef build_config_file(target, source, env): 2839651SAndreas.Sandberg@ARM.com (option, value) = [s.get_contents() for s in source] 2849651SAndreas.Sandberg@ARM.com f = file(str(target[0]), 'w') 2859651SAndreas.Sandberg@ARM.com print >> f, '#define', option, value 2869651SAndreas.Sandberg@ARM.com f.close() 2879651SAndreas.Sandberg@ARM.com return None 2889651SAndreas.Sandberg@ARM.com 2899651SAndreas.Sandberg@ARM.com# Generate the message to be printed when building the config file. 2909651SAndreas.Sandberg@ARM.comdef build_config_file_string(target, source, env): 2919651SAndreas.Sandberg@ARM.com (option, value) = [s.get_contents() for s in source] 2929651SAndreas.Sandberg@ARM.com return "Defining %s as %s in %s." % (option, value, target[0]) 2939651SAndreas.Sandberg@ARM.com 2949651SAndreas.Sandberg@ARM.com# Combine the two functions into a scons Action object. 2959651SAndreas.Sandberg@ARM.comconfig_action = Action(build_config_file, build_config_file_string) 2969651SAndreas.Sandberg@ARM.com 2979651SAndreas.Sandberg@ARM.com# The emitter munges the source & target node lists to reflect what 2989651SAndreas.Sandberg@ARM.com# we're really doing. 2999651SAndreas.Sandberg@ARM.comdef config_emitter(target, source, env): 3009651SAndreas.Sandberg@ARM.com # extract option name from Builder arg 3019651SAndreas.Sandberg@ARM.com option = str(target[0]) 3029651SAndreas.Sandberg@ARM.com # True target is config header file 3039651SAndreas.Sandberg@ARM.com target = os.path.join('config', option.lower() + '.hh') 3049651SAndreas.Sandberg@ARM.com # Force value to 0/1 even if it's a Python bool 3059651SAndreas.Sandberg@ARM.com val = int(eval(str(env[option]))) 3069651SAndreas.Sandberg@ARM.com # Sources are option name & value (packaged in SCons Value nodes) 3079651SAndreas.Sandberg@ARM.com return ([target], [Value(option), Value(val)]) 3089651SAndreas.Sandberg@ARM.com 3099651SAndreas.Sandberg@ARM.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 3109651SAndreas.Sandberg@ARM.com 3119651SAndreas.Sandberg@ARM.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 3129651SAndreas.Sandberg@ARM.com 3139651SAndreas.Sandberg@ARM.com# base help text 3149651SAndreas.Sandberg@ARM.comhelp_text = ''' 3159651SAndreas.Sandberg@ARM.comUsage: scons [scons options] [build options] [target(s)] 3169651SAndreas.Sandberg@ARM.com 3179651SAndreas.Sandberg@ARM.com''' 3189651SAndreas.Sandberg@ARM.com 3199651SAndreas.Sandberg@ARM.com# libelf build is shared across all configs in the build root. 3209651SAndreas.Sandberg@ARM.comenv.SConscript('ext/libelf/SConscript', 3219651SAndreas.Sandberg@ARM.com build_dir = os.path.join(build_root, 'libelf'), 3229651SAndreas.Sandberg@ARM.com exports = 'env') 3239651SAndreas.Sandberg@ARM.com 3249651SAndreas.Sandberg@ARM.com################################################### 3259651SAndreas.Sandberg@ARM.com# 3269651SAndreas.Sandberg@ARM.com# Define build environments for selected configurations. 3279651SAndreas.Sandberg@ARM.com# 3289651SAndreas.Sandberg@ARM.com################################################### 3299651SAndreas.Sandberg@ARM.com 3309651SAndreas.Sandberg@ARM.com# rename base env 3319651SAndreas.Sandberg@ARM.combase_env = env 3329651SAndreas.Sandberg@ARM.com 3339651SAndreas.Sandberg@ARM.comfor build_path in build_paths: 3349651SAndreas.Sandberg@ARM.com print "Building in", build_path 3359651SAndreas.Sandberg@ARM.com # build_dir is the tail component of build path, and is used to 3369651SAndreas.Sandberg@ARM.com # determine the build parameters (e.g., 'ALPHA_SE') 3379651SAndreas.Sandberg@ARM.com (build_root, build_dir) = os.path.split(build_path) 3389651SAndreas.Sandberg@ARM.com # Make a copy of the build-root environment to use for this config. 3399651SAndreas.Sandberg@ARM.com env = base_env.Copy() 3409651SAndreas.Sandberg@ARM.com 3419651SAndreas.Sandberg@ARM.com # Set env options according to the build directory config. 3429651SAndreas.Sandberg@ARM.com sticky_opts.files = [] 3439651SAndreas.Sandberg@ARM.com # Options for $BUILD_ROOT/$BUILD_DIR are stored in 3449651SAndreas.Sandberg@ARM.com # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 3459651SAndreas.Sandberg@ARM.com # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 3469651SAndreas.Sandberg@ARM.com current_opts_file = os.path.join(build_root, 'options', build_dir) 3479651SAndreas.Sandberg@ARM.com if os.path.isfile(current_opts_file): 3489651SAndreas.Sandberg@ARM.com sticky_opts.files.append(current_opts_file) 3499651SAndreas.Sandberg@ARM.com print "Using saved options file %s" % current_opts_file 3509651SAndreas.Sandberg@ARM.com else: 3519651SAndreas.Sandberg@ARM.com # Build dir-specific options file doesn't exist. 3529651SAndreas.Sandberg@ARM.com 3539651SAndreas.Sandberg@ARM.com # Make sure the directory is there so we can create it later 3549651SAndreas.Sandberg@ARM.com opt_dir = os.path.dirname(current_opts_file) 3559651SAndreas.Sandberg@ARM.com if not os.path.isdir(opt_dir): 3569651SAndreas.Sandberg@ARM.com os.mkdir(opt_dir) 3579651SAndreas.Sandberg@ARM.com 3589651SAndreas.Sandberg@ARM.com # Get default build options from source tree. Options are 3599651SAndreas.Sandberg@ARM.com # normally determined by name of $BUILD_DIR, but can be 3609651SAndreas.Sandberg@ARM.com # overriden by 'default=' arg on command line. 3619651SAndreas.Sandberg@ARM.com default_opts_file = os.path.join('build_opts', 3629651SAndreas.Sandberg@ARM.com ARGUMENTS.get('default', build_dir)) 3639651SAndreas.Sandberg@ARM.com if os.path.isfile(default_opts_file): 3649651SAndreas.Sandberg@ARM.com sticky_opts.files.append(default_opts_file) 3659651SAndreas.Sandberg@ARM.com print "Options file %s not found,\n using defaults in %s" \ 3669651SAndreas.Sandberg@ARM.com % (current_opts_file, default_opts_file) 3679651SAndreas.Sandberg@ARM.com else: 3689651SAndreas.Sandberg@ARM.com print "Error: cannot find options file %s or %s" \ 3699651SAndreas.Sandberg@ARM.com % (current_opts_file, default_opts_file) 3709651SAndreas.Sandberg@ARM.com Exit(1) 3719651SAndreas.Sandberg@ARM.com 3729651SAndreas.Sandberg@ARM.com # Apply current option settings to env 3739651SAndreas.Sandberg@ARM.com sticky_opts.Update(env) 3749651SAndreas.Sandberg@ARM.com nonsticky_opts.Update(env) 3759651SAndreas.Sandberg@ARM.com 3769651SAndreas.Sandberg@ARM.com help_text += "Sticky options for %s:\n" % build_dir \ 3779651SAndreas.Sandberg@ARM.com + sticky_opts.GenerateHelpText(env) \ 3789651SAndreas.Sandberg@ARM.com + "\nNon-sticky options for %s:\n" % build_dir \ 3799651SAndreas.Sandberg@ARM.com + nonsticky_opts.GenerateHelpText(env) 3809651SAndreas.Sandberg@ARM.com 3819651SAndreas.Sandberg@ARM.com # Process option settings. 3829651SAndreas.Sandberg@ARM.com 3839651SAndreas.Sandberg@ARM.com if not have_fenv and env['USE_FENV']: 3849651SAndreas.Sandberg@ARM.com print "Warning: <fenv.h> not available; " \ 3859651SAndreas.Sandberg@ARM.com "forcing USE_FENV to False in", build_dir + "." 3869651SAndreas.Sandberg@ARM.com env['USE_FENV'] = False 3879651SAndreas.Sandberg@ARM.com 3889651SAndreas.Sandberg@ARM.com if not env['USE_FENV']: 3899651SAndreas.Sandberg@ARM.com print "Warning: No IEEE FP rounding mode control in", build_dir + "." 3909651SAndreas.Sandberg@ARM.com print " FP results may deviate slightly from other platforms." 3919651SAndreas.Sandberg@ARM.com 3929651SAndreas.Sandberg@ARM.com if env['EFENCE']: 3939651SAndreas.Sandberg@ARM.com env.Append(LIBS=['efence']) 3949651SAndreas.Sandberg@ARM.com 3959651SAndreas.Sandberg@ARM.com if env['USE_MYSQL']: 3969651SAndreas.Sandberg@ARM.com if not have_mysql: 3979651SAndreas.Sandberg@ARM.com print "Warning: MySQL not available; " \ 3989651SAndreas.Sandberg@ARM.com "forcing USE_MYSQL to False in", build_dir + "." 3999651SAndreas.Sandberg@ARM.com env['USE_MYSQL'] = False 4009651SAndreas.Sandberg@ARM.com else: 4019651SAndreas.Sandberg@ARM.com print "Compiling in", build_dir, "with MySQL support." 4029651SAndreas.Sandberg@ARM.com env.ParseConfig(mysql_config_libs) 4039651SAndreas.Sandberg@ARM.com env.ParseConfig(mysql_config_include) 4049651SAndreas.Sandberg@ARM.com 4059651SAndreas.Sandberg@ARM.com # Save sticky option settings back to current options file 4069651SAndreas.Sandberg@ARM.com sticky_opts.Save(current_opts_file, env) 4079651SAndreas.Sandberg@ARM.com 4089651SAndreas.Sandberg@ARM.com # Do this after we save setting back, or else we'll tack on an 4099651SAndreas.Sandberg@ARM.com # extra 'qdo' every time we run scons. 4109651SAndreas.Sandberg@ARM.com if env['BATCH']: 4119651SAndreas.Sandberg@ARM.com env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 4129651SAndreas.Sandberg@ARM.com env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 4139651SAndreas.Sandberg@ARM.com 4149651SAndreas.Sandberg@ARM.com if env['USE_SSE2']: 4159651SAndreas.Sandberg@ARM.com env.Append(CCFLAGS='-msse2') 4169651SAndreas.Sandberg@ARM.com 4179651SAndreas.Sandberg@ARM.com # The m5/SConscript file sets up the build rules in 'env' according 4189651SAndreas.Sandberg@ARM.com # to the configured options. It returns a list of environments, 4199651SAndreas.Sandberg@ARM.com # one for each variant build (debug, opt, etc.) 4209651SAndreas.Sandberg@ARM.com envList = SConscript('src/SConscript', build_dir = build_path, 4219651SAndreas.Sandberg@ARM.com exports = 'env', duplicate = False) 4229651SAndreas.Sandberg@ARM.com 4239651SAndreas.Sandberg@ARM.com # Set up the regression tests for each build. 4249651SAndreas.Sandberg@ARM.com# for e in envList: 4259651SAndreas.Sandberg@ARM.com# SConscript('m5-test/SConscript', 4269651SAndreas.Sandberg@ARM.com# build_dir = os.path.join(build_dir, 'test', e.Label), 4279651SAndreas.Sandberg@ARM.com# exports = { 'env' : e }, duplicate = False) 4289651SAndreas.Sandberg@ARM.com 4299651SAndreas.Sandberg@ARM.comHelp(help_text) 4309651SAndreas.Sandberg@ARM.com 4319651SAndreas.Sandberg@ARM.com################################################### 4329651SAndreas.Sandberg@ARM.com# 4339651SAndreas.Sandberg@ARM.com# Let SCons do its thing. At this point SCons will use the defined 4349651SAndreas.Sandberg@ARM.com# build environments to build the requested targets. 4359651SAndreas.Sandberg@ARM.com# 4369651SAndreas.Sandberg@ARM.com################################################### 4379651SAndreas.Sandberg@ARM.com 4389651SAndreas.Sandberg@ARM.com