SConstruct revision 3483:edede8473667
11884Sstever@eecs.umich.edu# -*- mode:python -*- 21884Sstever@eecs.umich.edu 31884Sstever@eecs.umich.edu# Copyright (c) 2004-2005 The Regents of The University of Michigan 41884Sstever@eecs.umich.edu# All rights reserved. 51884Sstever@eecs.umich.edu# 61884Sstever@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 71884Sstever@eecs.umich.edu# modification, are permitted provided that the following conditions are 81884Sstever@eecs.umich.edu# met: redistributions of source code must retain the above copyright 91884Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 101884Sstever@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 111884Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 121884Sstever@eecs.umich.edu# documentation and/or other materials provided with the distribution; 131884Sstever@eecs.umich.edu# neither the name of the copyright holders nor the names of its 141884Sstever@eecs.umich.edu# contributors may be used to endorse or promote products derived from 151884Sstever@eecs.umich.edu# this software without specific prior written permission. 161884Sstever@eecs.umich.edu# 171884Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 181884Sstever@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 191884Sstever@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 201884Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 211884Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 221884Sstever@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 231884Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 241884Sstever@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 251884Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 261884Sstever@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 271884Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 281884Sstever@eecs.umich.edu# 291884Sstever@eecs.umich.edu# Authors: Steve Reinhardt 301884Sstever@eecs.umich.edu 311884Sstever@eecs.umich.edu################################################### 321884Sstever@eecs.umich.edu# 331884Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 341884Sstever@eecs.umich.edu# 351884Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 361884Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 371884Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 381884Sstever@eecs.umich.edu# the optimized full-system version). 391884Sstever@eecs.umich.edu# 401884Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 411884Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 421884Sstever@eecs.umich.edu# expects that all configs under the same build directory are being 431884Sstever@eecs.umich.edu# built for the same host system. 441884Sstever@eecs.umich.edu# 451884Sstever@eecs.umich.edu# Examples: 461884Sstever@eecs.umich.edu# 471884Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 481930Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 491930Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 501930Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 511930Sstever@eecs.umich.edu# 521930Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 531884Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 541884Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 551884Sstever@eecs.umich.edu# file. 561884Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 571884Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 581884Sstever@eecs.umich.edu# 591884Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 601884Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 611884Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 621884Sstever@eecs.umich.edu# options as well. 631930Sstever@eecs.umich.edu# 641930Sstever@eecs.umich.edu################################################### 651930Sstever@eecs.umich.edu 661884Sstever@eecs.umich.edu# Python library imports 671884Sstever@eecs.umich.eduimport sys 681884Sstever@eecs.umich.eduimport os 691884Sstever@eecs.umich.edu 701884Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 711884Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a 721884Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1) 731884Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 741884Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 751884Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 761884Sstever@eecs.umich.eduEnsurePythonVersion(2,4) 771884Sstever@eecs.umich.edu 781884Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 791884Sstever@eecs.umich.edu# 3-element version number. 801884Sstever@eecs.umich.edumin_scons_version = (0,96,91) 811884Sstever@eecs.umich.edutry: 821884Sstever@eecs.umich.edu EnsureSConsVersion(*min_scons_version) 831884Sstever@eecs.umich.eduexcept: 841884Sstever@eecs.umich.edu print "Error checking current SCons version." 851884Sstever@eecs.umich.edu print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 861884Sstever@eecs.umich.edu Exit(2) 871884Sstever@eecs.umich.edu 881884Sstever@eecs.umich.edu 891884Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives). 901884Sstever@eecs.umich.eduROOT = Dir('.').abspath 911884Sstever@eecs.umich.edu 921884Sstever@eecs.umich.edu# Paths to the M5 and external source trees. 931884Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'src') 941884Sstever@eecs.umich.edu 951884Sstever@eecs.umich.edu# tell python where to find m5 python code 961884Sstever@eecs.umich.edusys.path.append(os.path.join(ROOT, 'src/python')) 971884Sstever@eecs.umich.edu 981884Sstever@eecs.umich.edu################################################### 991884Sstever@eecs.umich.edu# 1001884Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 1011884Sstever@eecs.umich.edu# the target(s). 1021891Sstever@eecs.umich.edu# 1031884Sstever@eecs.umich.edu################################################### 1041884Sstever@eecs.umich.edu 1051884Sstever@eecs.umich.edu# Find default configuration & binary. 1061884Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1071884Sstever@eecs.umich.edu 1081884Sstever@eecs.umich.edu# Ask SCons which directory it was invoked from. 1091884Sstever@eecs.umich.edulaunch_dir = GetLaunchDir() 1101884Sstever@eecs.umich.edu 1111884Sstever@eecs.umich.edu# Make targets relative to invocation directory 1121884Sstever@eecs.umich.eduabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 1131884Sstever@eecs.umich.edu BUILD_TARGETS) 1141884Sstever@eecs.umich.edu 1151884Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 1161884Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 1171884Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 1181884Sstever@eecs.umich.edu if l[i] == elt: 1191884Sstever@eecs.umich.edu return i 1201884Sstever@eecs.umich.edu raise ValueError, "element not found" 1211884Sstever@eecs.umich.edu 1221884Sstever@eecs.umich.edu# helper function: compare dotted version numbers. 1231884Sstever@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1') 1241884Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1251884Sstever@eecs.umich.edudef compare_versions(v1, v2): 1261884Sstever@eecs.umich.edu # Convert dotted strings to lists 1271884Sstever@eecs.umich.edu v1 = map(int, v1.split('.')) 1281884Sstever@eecs.umich.edu v2 = map(int, v2.split('.')) 1291884Sstever@eecs.umich.edu # Compare corresponding elements of lists 1301884Sstever@eecs.umich.edu for n1,n2 in zip(v1, v2): 1311884Sstever@eecs.umich.edu if n1 < n2: return -1 1321884Sstever@eecs.umich.edu if n1 > n2: return 1 1331884Sstever@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1341884Sstever@eecs.umich.edu if len(v1) < len(v2): return -1 1351884Sstever@eecs.umich.edu if len(v1) > len(v2): return 1 1361884Sstever@eecs.umich.edu return 0 1371884Sstever@eecs.umich.edu 1381884Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 1391884Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 1401884Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1411884Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 1421884Sstever@eecs.umich.edu# follow 'build' in the bulid path. 1431884Sstever@eecs.umich.edu 1441884Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1451884Sstever@eecs.umich.edu# collected targets reference. 1461884Sstever@eecs.umich.edubuild_paths = [] 1471930Sstever@eecs.umich.edubuild_root = None 1481930Sstever@eecs.umich.edufor t in abs_targets: 1491930Sstever@eecs.umich.edu path_dirs = t.split('/') 1501884Sstever@eecs.umich.edu try: 1511884Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 1521884Sstever@eecs.umich.edu except: 1531884Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 1541884Sstever@eecs.umich.edu Exit(1) 1551884Sstever@eecs.umich.edu this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1561884Sstever@eecs.umich.edu if not build_root: 1571884Sstever@eecs.umich.edu build_root = this_build_root 1581884Sstever@eecs.umich.edu else: 1591884Sstever@eecs.umich.edu if this_build_root != build_root: 1601884Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 1611884Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1621884Sstever@eecs.umich.edu Exit(1) 1631884Sstever@eecs.umich.edu build_path = os.path.join('/',*path_dirs[:build_top+2]) 1641884Sstever@eecs.umich.edu if build_path not in build_paths: 1651884Sstever@eecs.umich.edu build_paths.append(build_path) 1661884Sstever@eecs.umich.edu 1671884Sstever@eecs.umich.edu################################################### 1681884Sstever@eecs.umich.edu# 1691884Sstever@eecs.umich.edu# Set up the default build environment. This environment is copied 1701884Sstever@eecs.umich.edu# and modified according to each selected configuration. 1711884Sstever@eecs.umich.edu# 1721884Sstever@eecs.umich.edu################################################### 1731884Sstever@eecs.umich.edu 1741884Sstever@eecs.umich.eduenv = Environment(ENV = os.environ, # inherit user's environment vars 1751884Sstever@eecs.umich.edu ROOT = ROOT, 1761884Sstever@eecs.umich.edu SRCDIR = SRCDIR) 1771884Sstever@eecs.umich.edu 1781884Sstever@eecs.umich.eduenv.SConsignFile(os.path.join(build_root,"sconsign")) 1791884Sstever@eecs.umich.edu 1801884Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 1811884Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 1821884Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 1831884Sstever@eecs.umich.edu# (soft) links work better. 1841884Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 1851884Sstever@eecs.umich.edu 1861884Sstever@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but 1871884Sstever@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 1881884Sstever@eecs.umich.edu# noticeably longer. 1891884Sstever@eecs.umich.eduif False: 1901884Sstever@eecs.umich.edu env.TargetSignatures('content') 1911884Sstever@eecs.umich.edu 1921884Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 1931884Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 1941884Sstever@eecs.umich.edu 1951884Sstever@eecs.umich.edu# Set up default C++ compiler flags 1961884Sstever@eecs.umich.eduenv.Append(CCFLAGS='-pipe') 1971884Sstever@eecs.umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing') 1981884Sstever@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1991884Sstever@eecs.umich.eduif sys.platform == 'cygwin': 2001884Sstever@eecs.umich.edu # cygwin has some header file issues... 2011884Sstever@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2021884Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 2031884Sstever@eecs.umich.edu 2041884Sstever@eecs.umich.edu# Check for SWIG 2051884Sstever@eecs.umich.eduif not env.has_key('SWIG'): 2061884Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 2071884Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 2081884Sstever@eecs.umich.edu Exit(1) 2091884Sstever@eecs.umich.edu 2101884Sstever@eecs.umich.edu# Check for appropriate SWIG version 2111884Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split() 2121884Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 2131884Sstever@eecs.umich.eduif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2141884Sstever@eecs.umich.edu print 'Error determining SWIG version.' 2151884Sstever@eecs.umich.edu Exit(1) 216 217min_swig_version = '1.3.28' 218if compare_versions(swig_version[2], min_swig_version) < 0: 219 print 'Error: SWIG version', min_swig_version, 'or newer required.' 220 print ' Installed version:', swig_version[2] 221 Exit(1) 222 223# Set up SWIG flags & scanner 224env.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 225 226import SCons.Scanner 227 228swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 229 230swig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 231 swig_inc_re) 232 233env.Append(SCANNERS = swig_scanner) 234 235# Platform-specific configuration. Note again that we assume that all 236# builds under a given build root run on the same host platform. 237conf = Configure(env, 238 conf_dir = os.path.join(build_root, '.scons_config'), 239 log_file = os.path.join(build_root, 'scons_config.log')) 240 241# Find Python include and library directories for embedding the 242# interpreter. For consistency, we will use the same Python 243# installation used to run scons (and thus this script). If you want 244# to link in an alternate version, see above for instructions on how 245# to invoke scons with a different copy of the Python interpreter. 246 247# Get brief Python version name (e.g., "python2.4") for locating 248# include & library files 249py_version_name = 'python' + sys.version[:3] 250 251# include path, e.g. /usr/local/include/python2.4 252py_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name) 253env.Append(CPPPATH = py_header_path) 254# verify that it works 255if not conf.CheckHeader('Python.h', '<>'): 256 print "Error: can't find Python.h header in", py_header_path 257 Exit(1) 258 259# add library path too if it's not in the default place 260py_lib_path = None 261if sys.exec_prefix != '/usr': 262 py_lib_path = os.path.join(sys.exec_prefix, 'lib') 263elif sys.platform == 'cygwin': 264 # cygwin puts the .dll in /bin for some reason 265 py_lib_path = '/bin' 266if py_lib_path: 267 env.Append(LIBPATH = py_lib_path) 268 print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 269if not conf.CheckLib(py_version_name): 270 print "Error: can't find Python library", py_version_name 271 Exit(1) 272 273# On Solaris you need to use libsocket for socket ops 274if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C', 'accept(0,NULL,NULL);'): 275 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C', 'accept(0,NULL,NULL);'): 276 print "Can't find library with socket calls (e.g. accept())" 277 Exit(1) 278 279# Check for zlib. If the check passes, libz will be automatically 280# added to the LIBS environment variable. 281if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 282 print 'Error: did not find needed zlib compression library '\ 283 'and/or zlib.h header file.' 284 print ' Please install zlib and try again.' 285 Exit(1) 286 287# Check for <fenv.h> (C99 FP environment control) 288have_fenv = conf.CheckHeader('fenv.h', '<>') 289if not have_fenv: 290 print "Warning: Header file <fenv.h> not found." 291 print " This host has no IEEE FP rounding mode control." 292 293# Check for mysql. 294mysql_config = WhereIs('mysql_config') 295have_mysql = mysql_config != None 296 297# Check MySQL version. 298if have_mysql: 299 mysql_version = os.popen(mysql_config + ' --version').read() 300 min_mysql_version = '4.1' 301 if compare_versions(mysql_version, min_mysql_version) < 0: 302 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 303 print ' Version', mysql_version, 'detected.' 304 have_mysql = False 305 306# Set up mysql_config commands. 307if have_mysql: 308 mysql_config_include = mysql_config + ' --include' 309 if os.system(mysql_config_include + ' > /dev/null') != 0: 310 # older mysql_config versions don't support --include, use 311 # --cflags instead 312 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 313 # This seems to work in all versions 314 mysql_config_libs = mysql_config + ' --libs' 315 316env = conf.Finish() 317 318# Define the universe of supported ISAs 319env['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 320 321# Define the universe of supported CPU models 322env['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 323 'FullCPU', 'O3CPU', 324 'OzoneCPU'] 325 326# Sticky options get saved in the options file so they persist from 327# one invocation to the next (unless overridden, in which case the new 328# value becomes sticky). 329sticky_opts = Options(args=ARGUMENTS) 330sticky_opts.AddOptions( 331 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 332 BoolOption('FULL_SYSTEM', 'Full-system support', False), 333 # There's a bug in scons 0.96.1 that causes ListOptions with list 334 # values (more than one value) not to be able to be restored from 335 # a saved option file. If this causes trouble then upgrade to 336 # scons 0.96.90 or later. 337 ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 338 env['ALL_CPU_LIST']), 339 BoolOption('ALPHA_TLASER', 340 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 341 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 342 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 343 False), 344 BoolOption('SS_COMPATIBLE_FP', 345 'Make floating-point results compatible with SimpleScalar', 346 False), 347 BoolOption('USE_SSE2', 348 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 349 False), 350 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 351 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 352 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 353 ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 354 ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 355 BoolOption('BATCH', 'Use batch pool for build and tests', False), 356 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 357 ('PYTHONHOME', 358 'Override the default PYTHONHOME for this system (use with caution)', 359 '%s:%s' % (sys.prefix, sys.exec_prefix)) 360 ) 361 362# Non-sticky options only apply to the current build. 363nonsticky_opts = Options(args=ARGUMENTS) 364nonsticky_opts.AddOptions( 365 BoolOption('update_ref', 'Update test reference outputs', False) 366 ) 367 368# These options get exported to #defines in config/*.hh (see src/SConscript). 369env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 370 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 371 'USE_CHECKER', 'PYTHONHOME'] 372 373# Define a handy 'no-op' action 374def no_action(target, source, env): 375 return 0 376 377env.NoAction = Action(no_action, None) 378 379################################################### 380# 381# Define a SCons builder for configuration flag headers. 382# 383################################################### 384 385# This function generates a config header file that #defines the 386# option symbol to the current option setting (0 or 1). The source 387# operands are the name of the option and a Value node containing the 388# value of the option. 389def build_config_file(target, source, env): 390 (option, value) = [s.get_contents() for s in source] 391 f = file(str(target[0]), 'w') 392 print >> f, '#define', option, value 393 f.close() 394 return None 395 396# Generate the message to be printed when building the config file. 397def build_config_file_string(target, source, env): 398 (option, value) = [s.get_contents() for s in source] 399 return "Defining %s as %s in %s." % (option, value, target[0]) 400 401# Combine the two functions into a scons Action object. 402config_action = Action(build_config_file, build_config_file_string) 403 404# The emitter munges the source & target node lists to reflect what 405# we're really doing. 406def config_emitter(target, source, env): 407 # extract option name from Builder arg 408 option = str(target[0]) 409 # True target is config header file 410 target = os.path.join('config', option.lower() + '.hh') 411 val = env[option] 412 if isinstance(val, bool): 413 # Force value to 0/1 414 val = int(val) 415 elif isinstance(val, str): 416 val = '"' + val + '"' 417 418 # Sources are option name & value (packaged in SCons Value nodes) 419 return ([target], [Value(option), Value(val)]) 420 421config_builder = Builder(emitter = config_emitter, action = config_action) 422 423env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 424 425################################################### 426# 427# Define a SCons builder for copying files. This is used by the 428# Python zipfile code in src/python/SConscript, but is placed up here 429# since it's potentially more generally applicable. 430# 431################################################### 432 433copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 434 435env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 436 437################################################### 438# 439# Define a simple SCons builder to concatenate files. 440# 441# Used to append the Python zip archive to the executable. 442# 443################################################### 444 445concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 446 'chmod +x $TARGET'])) 447 448env.Append(BUILDERS = { 'Concat' : concat_builder }) 449 450 451# base help text 452help_text = ''' 453Usage: scons [scons options] [build options] [target(s)] 454 455''' 456 457# libelf build is shared across all configs in the build root. 458env.SConscript('ext/libelf/SConscript', 459 build_dir = os.path.join(build_root, 'libelf'), 460 exports = 'env') 461 462################################################### 463# 464# Define build environments for selected configurations. 465# 466################################################### 467 468# rename base env 469base_env = env 470 471for build_path in build_paths: 472 print "Building in", build_path 473 # build_dir is the tail component of build path, and is used to 474 # determine the build parameters (e.g., 'ALPHA_SE') 475 (build_root, build_dir) = os.path.split(build_path) 476 # Make a copy of the build-root environment to use for this config. 477 env = base_env.Copy() 478 479 # Set env options according to the build directory config. 480 sticky_opts.files = [] 481 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 482 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 483 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 484 current_opts_file = os.path.join(build_root, 'options', build_dir) 485 if os.path.isfile(current_opts_file): 486 sticky_opts.files.append(current_opts_file) 487 print "Using saved options file %s" % current_opts_file 488 else: 489 # Build dir-specific options file doesn't exist. 490 491 # Make sure the directory is there so we can create it later 492 opt_dir = os.path.dirname(current_opts_file) 493 if not os.path.isdir(opt_dir): 494 os.mkdir(opt_dir) 495 496 # Get default build options from source tree. Options are 497 # normally determined by name of $BUILD_DIR, but can be 498 # overriden by 'default=' arg on command line. 499 default_opts_file = os.path.join('build_opts', 500 ARGUMENTS.get('default', build_dir)) 501 if os.path.isfile(default_opts_file): 502 sticky_opts.files.append(default_opts_file) 503 print "Options file %s not found,\n using defaults in %s" \ 504 % (current_opts_file, default_opts_file) 505 else: 506 print "Error: cannot find options file %s or %s" \ 507 % (current_opts_file, default_opts_file) 508 Exit(1) 509 510 # Apply current option settings to env 511 sticky_opts.Update(env) 512 nonsticky_opts.Update(env) 513 514 help_text += "Sticky options for %s:\n" % build_dir \ 515 + sticky_opts.GenerateHelpText(env) \ 516 + "\nNon-sticky options for %s:\n" % build_dir \ 517 + nonsticky_opts.GenerateHelpText(env) 518 519 # Process option settings. 520 521 if not have_fenv and env['USE_FENV']: 522 print "Warning: <fenv.h> not available; " \ 523 "forcing USE_FENV to False in", build_dir + "." 524 env['USE_FENV'] = False 525 526 if not env['USE_FENV']: 527 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 528 print " FP results may deviate slightly from other platforms." 529 530 if env['EFENCE']: 531 env.Append(LIBS=['efence']) 532 533 if env['USE_MYSQL']: 534 if not have_mysql: 535 print "Warning: MySQL not available; " \ 536 "forcing USE_MYSQL to False in", build_dir + "." 537 env['USE_MYSQL'] = False 538 else: 539 print "Compiling in", build_dir, "with MySQL support." 540 env.ParseConfig(mysql_config_libs) 541 env.ParseConfig(mysql_config_include) 542 543 # Save sticky option settings back to current options file 544 sticky_opts.Save(current_opts_file, env) 545 546 # Do this after we save setting back, or else we'll tack on an 547 # extra 'qdo' every time we run scons. 548 if env['BATCH']: 549 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 550 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 551 552 if env['USE_SSE2']: 553 env.Append(CCFLAGS='-msse2') 554 555 # The src/SConscript file sets up the build rules in 'env' according 556 # to the configured options. It returns a list of environments, 557 # one for each variant build (debug, opt, etc.) 558 envList = SConscript('src/SConscript', build_dir = build_path, 559 exports = 'env') 560 561 # Set up the regression tests for each build. 562 for e in envList: 563 SConscript('tests/SConscript', 564 build_dir = os.path.join(build_path, 'tests', e.Label), 565 exports = { 'env' : e }, duplicate = False) 566 567Help(help_text) 568 569################################################### 570# 571# Let SCons do its thing. At this point SCons will use the defined 572# build environments to build the requested targets. 573# 574################################################### 575 576