SConstruct revision 2776:1b766ee324d5
16019Shines@cs.fsu.edu# -*- mode:python -*- 27093Sgblack@eecs.umich.edu 37093Sgblack@eecs.umich.edu# Copyright (c) 2004-2005 The Regents of The University of Michigan 47093Sgblack@eecs.umich.edu# All rights reserved. 57093Sgblack@eecs.umich.edu# 67093Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 77093Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 87093Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 97093Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 107093Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 117093Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 127093Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 137093Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 146019Shines@cs.fsu.edu# contributors may be used to endorse or promote products derived from 156019Shines@cs.fsu.edu# this software without specific prior written permission. 166019Shines@cs.fsu.edu# 176019Shines@cs.fsu.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 186019Shines@cs.fsu.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 196019Shines@cs.fsu.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 206019Shines@cs.fsu.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 216019Shines@cs.fsu.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 226019Shines@cs.fsu.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 236019Shines@cs.fsu.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246019Shines@cs.fsu.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256019Shines@cs.fsu.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266019Shines@cs.fsu.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 276019Shines@cs.fsu.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286019Shines@cs.fsu.edu# 296019Shines@cs.fsu.edu# Authors: Steve Reinhardt 306019Shines@cs.fsu.edu 316019Shines@cs.fsu.edu################################################### 326019Shines@cs.fsu.edu# 336019Shines@cs.fsu.edu# SCons top-level build description (SConstruct) file. 346019Shines@cs.fsu.edu# 356019Shines@cs.fsu.edu# While in this directory ('m5'), just type 'scons' to build the default 366019Shines@cs.fsu.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 376019Shines@cs.fsu.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 386019Shines@cs.fsu.edu# the optimized full-system version). 396019Shines@cs.fsu.edu# 406019Shines@cs.fsu.edu# You can build M5 in a different directory as long as there is a 416735Sgblack@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 426735Sgblack@eecs.umich.edu# expects that all configs under the same build directory are being 436019Shines@cs.fsu.edu# built for the same host system. 446019Shines@cs.fsu.edu# 456019Shines@cs.fsu.edu# Examples: 468229Snate@binkert.org# 478229Snate@binkert.org# The following two commands are equivalent. The '-u' option tells 486019Shines@cs.fsu.edu# scons to search up the directory tree for this SConstruct file. 498232Snate@binkert.org# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 506019Shines@cs.fsu.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 516019Shines@cs.fsu.edu# 526019Shines@cs.fsu.edu# The following two commands are equivalent and demonstrate building 536019Shines@cs.fsu.edu# in a directory outside of the source tree. The '-C' option tells 547362Sgblack@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 556735Sgblack@eecs.umich.edu# file. 566019Shines@cs.fsu.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 577362Sgblack@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 586735Sgblack@eecs.umich.edu# 596019Shines@cs.fsu.edu# You can use 'scons -H' to print scons options. If you're in this 607362Sgblack@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 616735Sgblack@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 626019Shines@cs.fsu.edu# options as well. 637362Sgblack@eecs.umich.edu# 646735Sgblack@eecs.umich.edu################################################### 656019Shines@cs.fsu.edu 667362Sgblack@eecs.umich.edu# Python library imports 676735Sgblack@eecs.umich.eduimport sys 686019Shines@cs.fsu.eduimport os 697362Sgblack@eecs.umich.edu 706735Sgblack@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 716019Shines@cs.fsu.edu# default installation of Python is not recent enough, you can use a 727362Sgblack@eecs.umich.edu# non-default installation of the Python interpreter by either (1) 736735Sgblack@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 746019Shines@cs.fsu.edu# first or (2) explicitly invoking an alternative interpreter on the 757652Sminkyu.jeong@arm.com# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 767652Sminkyu.jeong@arm.comEnsurePythonVersion(2,4) 777652Sminkyu.jeong@arm.com 788202SAli.Saidi@ARM.com# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 798202SAli.Saidi@ARM.com# 3-element version number. 808202SAli.Saidi@ARM.commin_scons_version = (0,96,91) 818518Sgeoffrey.blake@arm.comtry: 828518Sgeoffrey.blake@arm.com EnsureSConsVersion(*min_scons_version) 836735Sgblack@eecs.umich.eduexcept: 847362Sgblack@eecs.umich.edu print "Error checking current SCons version." 856735Sgblack@eecs.umich.edu print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 866735Sgblack@eecs.umich.edu Exit(2) 876019Shines@cs.fsu.edu 886735Sgblack@eecs.umich.edu 897400SAli.Saidi@ARM.com# The absolute path to the current directory (where this file lives). 906735Sgblack@eecs.umich.eduROOT = Dir('.').abspath 916735Sgblack@eecs.umich.edu 926735Sgblack@eecs.umich.edu# Paths to the M5 and external source trees. 937400SAli.Saidi@ARM.comSRCDIR = os.path.join(ROOT, 'src') 946735Sgblack@eecs.umich.edu 956735Sgblack@eecs.umich.edu# tell python where to find m5 python code 966735Sgblack@eecs.umich.edusys.path.append(os.path.join(ROOT, 'src/python')) 976019Shines@cs.fsu.edu 986019Shines@cs.fsu.edu################################################### 996019Shines@cs.fsu.edu# 1006735Sgblack@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 1016735Sgblack@eecs.umich.edu# the target(s). 1026735Sgblack@eecs.umich.edu# 1037678Sgblack@eecs.umich.edu################################################### 1046019Shines@cs.fsu.edu 1056735Sgblack@eecs.umich.edu# Find default configuration & binary. 1066735Sgblack@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1076735Sgblack@eecs.umich.edu 1086019Shines@cs.fsu.edu# Ask SCons which directory it was invoked from. 1096735Sgblack@eecs.umich.edulaunch_dir = GetLaunchDir() 1106735Sgblack@eecs.umich.edu 1118303SAli.Saidi@ARM.com# Make targets relative to invocation directory 1128303SAli.Saidi@ARM.comabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 1138303SAli.Saidi@ARM.com BUILD_TARGETS) 1148303SAli.Saidi@ARM.com 1158303SAli.Saidi@ARM.com# helper function: find last occurrence of element in list 1168303SAli.Saidi@ARM.comdef rfind(l, elt, offs = -1): 1177720Sgblack@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 1188205SAli.Saidi@ARM.com if l[i] == elt: 1198205SAli.Saidi@ARM.com return i 1208205SAli.Saidi@ARM.com raise ValueError, "element not found" 1216735Sgblack@eecs.umich.edu 1226735Sgblack@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 1236735Sgblack@eecs.umich.edu# directory below this will determine the build parameters. For 1246735Sgblack@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1256735Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 1267093Sgblack@eecs.umich.edu# follow 'build' in the bulid path. 1276735Sgblack@eecs.umich.edu 1286735Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1296735Sgblack@eecs.umich.edu# collected targets reference. 1307302Sgblack@eecs.umich.edubuild_paths = [] 1316735Sgblack@eecs.umich.edubuild_root = None 1328518Sgeoffrey.blake@arm.comfor t in abs_targets: 1338518Sgeoffrey.blake@arm.com path_dirs = t.split('/') 1347720Sgblack@eecs.umich.edu try: 1356735Sgblack@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 1366735Sgblack@eecs.umich.edu except: 1376735Sgblack@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 1386735Sgblack@eecs.umich.edu Exit(1) 1396735Sgblack@eecs.umich.edu this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1406735Sgblack@eecs.umich.edu if not build_root: 1416735Sgblack@eecs.umich.edu build_root = this_build_root 1426735Sgblack@eecs.umich.edu else: 1436735Sgblack@eecs.umich.edu if this_build_root != build_root: 1446735Sgblack@eecs.umich.edu print "Error: build targets not under same build root\n"\ 1456735Sgblack@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1466735Sgblack@eecs.umich.edu Exit(1) 1476735Sgblack@eecs.umich.edu build_path = os.path.join('/',*path_dirs[:build_top+2]) 1486735Sgblack@eecs.umich.edu if build_path not in build_paths: 1496735Sgblack@eecs.umich.edu build_paths.append(build_path) 1506735Sgblack@eecs.umich.edu 1516735Sgblack@eecs.umich.edu################################################### 1526735Sgblack@eecs.umich.edu# 1536735Sgblack@eecs.umich.edu# Set up the default build environment. This environment is copied 1546735Sgblack@eecs.umich.edu# and modified according to each selected configuration. 1557093Sgblack@eecs.umich.edu# 1567093Sgblack@eecs.umich.edu################################################### 1577720Sgblack@eecs.umich.edu 1587585SAli.Saidi@arm.comenv = Environment(ENV = os.environ, # inherit user's environment vars 1597720Sgblack@eecs.umich.edu ROOT = ROOT, 1607720Sgblack@eecs.umich.edu SRCDIR = SRCDIR) 1617720Sgblack@eecs.umich.edu 1627720Sgblack@eecs.umich.eduenv.SConsignFile(os.path.join(build_root,"sconsign")) 1637720Sgblack@eecs.umich.edu 1647720Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 1657720Sgblack@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 1666019Shines@cs.fsu.edu# file to file~ then copies to file, breaking the link. Symbolic 1677189Sgblack@eecs.umich.edu# (soft) links work better. 1687400SAli.Saidi@ARM.comenv.SetOption('duplicate', 'soft-copy') 1697678Sgblack@eecs.umich.edu 1707400SAli.Saidi@ARM.com# I waffle on this setting... it does avoid a few painful but 1717400SAli.Saidi@ARM.com# unnecessary builds, but it also seems to make trivial builds take 1727400SAli.Saidi@ARM.com# noticeably longer. 1738205SAli.Saidi@ARM.comif False: 1747400SAli.Saidi@ARM.com env.TargetSignatures('content') 1757400SAli.Saidi@ARM.com 1767189Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 1777189Sgblack@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 1787189Sgblack@eecs.umich.edu 1797678Sgblack@eecs.umich.edu# Set up default C++ compiler flags 1807189Sgblack@eecs.umich.eduenv.Append(CCFLAGS='-pipe') 1817640Sgblack@eecs.umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing') 1827189Sgblack@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1837640Sgblack@eecs.umich.eduif sys.platform == 'cygwin': 1847640Sgblack@eecs.umich.edu # cygwin has some header file issues... 1857640Sgblack@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 1867640Sgblack@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 1877426Sgblack@eecs.umich.edu 1887426Sgblack@eecs.umich.edu# Find Python include and library directories for embedding the 1897189Sgblack@eecs.umich.edu# interpreter. For consistency, we will use the same Python 1907426Sgblack@eecs.umich.edu# installation used to run scons (and thus this script). If you want 1917426Sgblack@eecs.umich.edu# to link in an alternate version, see above for instructions on how 1927189Sgblack@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 1937189Sgblack@eecs.umich.edu 1947189Sgblack@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating 1957197Sgblack@eecs.umich.edu# include & library files 1967678Sgblack@eecs.umich.edupy_version_name = 'python' + sys.version[:3] 1977197Sgblack@eecs.umich.edu 1987197Sgblack@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4 1997197Sgblack@eecs.umich.eduenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name)) 2007197Sgblack@eecs.umich.eduenv.Append(LIBS = py_version_name) 2018063SAli.Saidi@ARM.com# add library path too if it's not in the default place 2027197Sgblack@eecs.umich.eduif sys.exec_prefix != '/usr': 2037197Sgblack@eecs.umich.edu env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib')) 2047197Sgblack@eecs.umich.edu 2057720Sgblack@eecs.umich.edu# Set up SWIG flags & scanner 2067720Sgblack@eecs.umich.edu 2077720Sgblack@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2087720Sgblack@eecs.umich.edu 2097197Sgblack@eecs.umich.eduimport SCons.Scanner 2107197Sgblack@eecs.umich.edu 2116019Shines@cs.fsu.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2126019Shines@cs.fsu.edu 2137362Sgblack@eecs.umich.eduswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2147362Sgblack@eecs.umich.edu swig_inc_re) 2157678Sgblack@eecs.umich.edu 2167362Sgblack@eecs.umich.eduenv.Append(SCANNERS = swig_scanner) 2178205SAli.Saidi@ARM.com 2187362Sgblack@eecs.umich.edu# Other default libraries 2197362Sgblack@eecs.umich.eduenv.Append(LIBS=['z']) 2207362Sgblack@eecs.umich.edu 2217362Sgblack@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 2227362Sgblack@eecs.umich.edu# builds under a given build root run on the same host platform. 2237362Sgblack@eecs.umich.educonf = Configure(env, 2247362Sgblack@eecs.umich.edu conf_dir = os.path.join(build_root, '.scons_config'), 2257362Sgblack@eecs.umich.edu log_file = os.path.join(build_root, 'scons_config.log')) 2268314Sgeoffrey.blake@arm.com 2278314Sgeoffrey.blake@arm.com# Check for <fenv.h> (C99 FP environment control) 2287362Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 2297362Sgblack@eecs.umich.eduif not have_fenv: 2307652Sminkyu.jeong@arm.com print "Warning: Header file <fenv.h> not found." 2317678Sgblack@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 2327652Sminkyu.jeong@arm.com 2337652Sminkyu.jeong@arm.com# Check for mysql. 2347652Sminkyu.jeong@arm.commysql_config = WhereIs('mysql_config') 2357652Sminkyu.jeong@arm.comhave_mysql = mysql_config != None 2367652Sminkyu.jeong@arm.com 2377720Sgblack@eecs.umich.edu# Check MySQL version. 2387720Sgblack@eecs.umich.eduif have_mysql: 2397720Sgblack@eecs.umich.edu mysql_version = os.popen(mysql_config + ' --version').read() 2407720Sgblack@eecs.umich.edu mysql_version = mysql_version.split('.') 2417652Sminkyu.jeong@arm.com mysql_major = int(mysql_version[0]) 2427652Sminkyu.jeong@arm.com mysql_minor = int(mysql_version[1]) 2438202SAli.Saidi@ARM.com # This version check is probably overly conservative, but it deals 2448202SAli.Saidi@ARM.com # with the versions we have installed. 2458202SAli.Saidi@ARM.com if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1): 2468202SAli.Saidi@ARM.com print "Warning: MySQL v4.1 or newer required." 2478202SAli.Saidi@ARM.com have_mysql = False 2488202SAli.Saidi@ARM.com 2498202SAli.Saidi@ARM.com# Set up mysql_config commands. 2508202SAli.Saidi@ARM.comif have_mysql: 2518202SAli.Saidi@ARM.com mysql_config_include = mysql_config + ' --include' 2528202SAli.Saidi@ARM.com if os.system(mysql_config_include + ' > /dev/null') != 0: 2538202SAli.Saidi@ARM.com # older mysql_config versions don't support --include, use 2547678Sgblack@eecs.umich.edu # --cflags instead 2557678Sgblack@eecs.umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 2567678Sgblack@eecs.umich.edu # This seems to work in all versions 2577678Sgblack@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 2587362Sgblack@eecs.umich.edu 2598518Sgeoffrey.blake@arm.comenv = conf.Finish() 2608518Sgeoffrey.blake@arm.com 2618518Sgeoffrey.blake@arm.com# Define the universe of supported ISAs 2628518Sgeoffrey.blake@arm.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 2638518Sgeoffrey.blake@arm.com 2648518Sgeoffrey.blake@arm.com# Define the universe of supported CPU models 2658518Sgeoffrey.blake@arm.comenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 2668518Sgeoffrey.blake@arm.com 'FullCPU', 'AlphaO3CPU', 2678518Sgeoffrey.blake@arm.com 'OzoneSimpleCPU', 'OzoneCPU'] 2688518Sgeoffrey.blake@arm.com 2698518Sgeoffrey.blake@arm.com# Sticky options get saved in the options file so they persist from 2708518Sgeoffrey.blake@arm.com# one invocation to the next (unless overridden, in which case the new 2716735Sgblack@eecs.umich.edu# value becomes sticky). 2726019Shines@cs.fsu.edusticky_opts = Options(args=ARGUMENTS) 2736019Shines@cs.fsu.edusticky_opts.AddOptions( 274 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 275 BoolOption('FULL_SYSTEM', 'Full-system support', False), 276 # There's a bug in scons 0.96.1 that causes ListOptions with list 277 # values (more than one value) not to be able to be restored from 278 # a saved option file. If this causes trouble then upgrade to 279 # scons 0.96.90 or later. 280 ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 281 env['ALL_CPU_LIST']), 282 BoolOption('ALPHA_TLASER', 283 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 284 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 285 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 286 False), 287 BoolOption('SS_COMPATIBLE_FP', 288 'Make floating-point results compatible with SimpleScalar', 289 False), 290 BoolOption('USE_SSE2', 291 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 292 False), 293 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 294 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 295 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 296 ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 297 ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 298 BoolOption('BATCH', 'Use batch pool for build and tests', False), 299 ('BATCH_CMD', 'Batch pool submission command name', 'qdo') 300 ) 301 302# Non-sticky options only apply to the current build. 303nonsticky_opts = Options(args=ARGUMENTS) 304nonsticky_opts.AddOptions( 305 BoolOption('update_ref', 'Update test reference outputs', False) 306 ) 307 308# These options get exported to #defines in config/*.hh (see src/SConscript). 309env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 310 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 311 'USE_CHECKER'] 312 313# Define a handy 'no-op' action 314def no_action(target, source, env): 315 return 0 316 317env.NoAction = Action(no_action, None) 318 319################################################### 320# 321# Define a SCons builder for configuration flag headers. 322# 323################################################### 324 325# This function generates a config header file that #defines the 326# option symbol to the current option setting (0 or 1). The source 327# operands are the name of the option and a Value node containing the 328# value of the option. 329def build_config_file(target, source, env): 330 (option, value) = [s.get_contents() for s in source] 331 f = file(str(target[0]), 'w') 332 print >> f, '#define', option, value 333 f.close() 334 return None 335 336# Generate the message to be printed when building the config file. 337def build_config_file_string(target, source, env): 338 (option, value) = [s.get_contents() for s in source] 339 return "Defining %s as %s in %s." % (option, value, target[0]) 340 341# Combine the two functions into a scons Action object. 342config_action = Action(build_config_file, build_config_file_string) 343 344# The emitter munges the source & target node lists to reflect what 345# we're really doing. 346def config_emitter(target, source, env): 347 # extract option name from Builder arg 348 option = str(target[0]) 349 # True target is config header file 350 target = os.path.join('config', option.lower() + '.hh') 351 # Force value to 0/1 even if it's a Python bool 352 val = int(eval(str(env[option]))) 353 # Sources are option name & value (packaged in SCons Value nodes) 354 return ([target], [Value(option), Value(val)]) 355 356config_builder = Builder(emitter = config_emitter, action = config_action) 357 358env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 359 360################################################### 361# 362# Define a SCons builder for copying files. This is used by the 363# Python zipfile code in src/python/SConscript, but is placed up here 364# since it's potentially more generally applicable. 365# 366################################################### 367 368copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 369 370env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 371 372################################################### 373# 374# Define a simple SCons builder to concatenate files. 375# 376# Used to append the Python zip archive to the executable. 377# 378################################################### 379 380concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 381 'chmod +x $TARGET'])) 382 383env.Append(BUILDERS = { 'Concat' : concat_builder }) 384 385 386# base help text 387help_text = ''' 388Usage: scons [scons options] [build options] [target(s)] 389 390''' 391 392# libelf build is shared across all configs in the build root. 393env.SConscript('ext/libelf/SConscript', 394 build_dir = os.path.join(build_root, 'libelf'), 395 exports = 'env') 396 397################################################### 398# 399# Define build environments for selected configurations. 400# 401################################################### 402 403# rename base env 404base_env = env 405 406for build_path in build_paths: 407 print "Building in", build_path 408 # build_dir is the tail component of build path, and is used to 409 # determine the build parameters (e.g., 'ALPHA_SE') 410 (build_root, build_dir) = os.path.split(build_path) 411 # Make a copy of the build-root environment to use for this config. 412 env = base_env.Copy() 413 414 # Set env options according to the build directory config. 415 sticky_opts.files = [] 416 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 417 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 418 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 419 current_opts_file = os.path.join(build_root, 'options', build_dir) 420 if os.path.isfile(current_opts_file): 421 sticky_opts.files.append(current_opts_file) 422 print "Using saved options file %s" % current_opts_file 423 else: 424 # Build dir-specific options file doesn't exist. 425 426 # Make sure the directory is there so we can create it later 427 opt_dir = os.path.dirname(current_opts_file) 428 if not os.path.isdir(opt_dir): 429 os.mkdir(opt_dir) 430 431 # Get default build options from source tree. Options are 432 # normally determined by name of $BUILD_DIR, but can be 433 # overriden by 'default=' arg on command line. 434 default_opts_file = os.path.join('build_opts', 435 ARGUMENTS.get('default', build_dir)) 436 if os.path.isfile(default_opts_file): 437 sticky_opts.files.append(default_opts_file) 438 print "Options file %s not found,\n using defaults in %s" \ 439 % (current_opts_file, default_opts_file) 440 else: 441 print "Error: cannot find options file %s or %s" \ 442 % (current_opts_file, default_opts_file) 443 Exit(1) 444 445 # Apply current option settings to env 446 sticky_opts.Update(env) 447 nonsticky_opts.Update(env) 448 449 help_text += "Sticky options for %s:\n" % build_dir \ 450 + sticky_opts.GenerateHelpText(env) \ 451 + "\nNon-sticky options for %s:\n" % build_dir \ 452 + nonsticky_opts.GenerateHelpText(env) 453 454 # Process option settings. 455 456 if not have_fenv and env['USE_FENV']: 457 print "Warning: <fenv.h> not available; " \ 458 "forcing USE_FENV to False in", build_dir + "." 459 env['USE_FENV'] = False 460 461 if not env['USE_FENV']: 462 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 463 print " FP results may deviate slightly from other platforms." 464 465 if env['EFENCE']: 466 env.Append(LIBS=['efence']) 467 468 if env['USE_MYSQL']: 469 if not have_mysql: 470 print "Warning: MySQL not available; " \ 471 "forcing USE_MYSQL to False in", build_dir + "." 472 env['USE_MYSQL'] = False 473 else: 474 print "Compiling in", build_dir, "with MySQL support." 475 env.ParseConfig(mysql_config_libs) 476 env.ParseConfig(mysql_config_include) 477 478 # Check if the Checker is being used. If so append it to env['CPU_MODELS'] 479 if env['USE_CHECKER']: 480 env['CPU_MODELS'].append('CheckerCPU') 481 482 # Save sticky option settings back to current options file 483 sticky_opts.Save(current_opts_file, env) 484 485 # Do this after we save setting back, or else we'll tack on an 486 # extra 'qdo' every time we run scons. 487 if env['BATCH']: 488 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 489 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 490 491 if env['USE_SSE2']: 492 env.Append(CCFLAGS='-msse2') 493 494 # The src/SConscript file sets up the build rules in 'env' according 495 # to the configured options. It returns a list of environments, 496 # one for each variant build (debug, opt, etc.) 497 envList = SConscript('src/SConscript', build_dir = build_path, 498 exports = 'env') 499 500 # Set up the regression tests for each build. 501# for e in envList: 502# SConscript('m5-test/SConscript', 503# build_dir = os.path.join(build_dir, 'test', e.Label), 504# exports = { 'env' : e }, duplicate = False) 505 506Help(help_text) 507 508################################################### 509# 510# Let SCons do its thing. At this point SCons will use the defined 511# build environments to build the requested targets. 512# 513################################################### 514 515