SConstruct revision 5273
1# -*- mode:python -*- 2 3# Copyright (c) 2004-2005 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer; 10# redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution; 13# neither the name of the copyright holders nor the names of its 14# contributors may be used to endorse or promote products derived from 15# this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28# 29# Authors: Steve Reinhardt 30 31################################################### 32# 33# SCons top-level build description (SConstruct) file. 34# 35# While in this directory ('m5'), just type 'scons' to build the default 36# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 37# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 38# the optimized full-system version). 39# 40# You can build M5 in a different directory as long as there is a 41# 'build/<CONFIG>' somewhere along the target path. The build system 42# expects that all configs under the same build directory are being 43# built for the same host system. 44# 45# Examples: 46# 47# The following two commands are equivalent. The '-u' option tells 48# scons to search up the directory tree for this SConstruct file. 49# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 50# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 51# 52# The following two commands are equivalent and demonstrate building 53# in a directory outside of the source tree. The '-C' option tells 54# scons to chdir to the specified directory to find this SConstruct 55# file. 56# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 57# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 58# 59# You can use 'scons -H' to print scons options. If you're in this 60# 'm5' directory (or use -u or -C to tell scons where to find this 61# file), you can use 'scons -h' to print all the M5-specific build 62# options as well. 63# 64################################################### 65 66import sys 67import os 68 69from os.path import isdir, join as joinpath 70 71import SCons 72 73# Check for recent-enough Python and SCons versions. If your system's 74# default installation of Python is not recent enough, you can use a 75# non-default installation of the Python interpreter by either (1) 76# rearranging your PATH so that scons finds the non-default 'python' 77# first or (2) explicitly invoking an alternative interpreter on the 78# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 79EnsurePythonVersion(2,4) 80 81# Import subprocess after we check the version since it doesn't exist in 82# Python < 2.4. 83import subprocess 84 85# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 86# 3-element version number. 87min_scons_version = (0,96,91) 88try: 89 EnsureSConsVersion(*min_scons_version) 90except: 91 print "Error checking current SCons version." 92 print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 93 Exit(2) 94 95 96# The absolute path to the current directory (where this file lives). 97ROOT = Dir('.').abspath 98 99# Path to the M5 source tree. 100SRCDIR = joinpath(ROOT, 'src') 101 102# tell python where to find m5 python code 103sys.path.append(joinpath(ROOT, 'src/python')) 104 105def check_style_hook(ui): 106 ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 107 style_hook = ui.config('hooks', 'pretxncommit.style', None) 108 109 if not style_hook: 110 print """\ 111You're missing the M5 style hook. 112Please install the hook so we can ensure that all code fits a common style. 113 114All you'd need to do is add the following lines to your repository .hg/hgrc 115or your personal .hgrc 116---------------- 117 118[extensions] 119style = %s/util/style.py 120 121[hooks] 122pretxncommit.style = python:style.check_whitespace 123""" % (ROOT) 124 sys.exit(1) 125 126if ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 127 try: 128 from mercurial import ui 129 check_style_hook(ui.ui()) 130 except ImportError: 131 pass 132 133################################################### 134# 135# Figure out which configurations to set up based on the path(s) of 136# the target(s). 137# 138################################################### 139 140# Find default configuration & binary. 141Default(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 142 143# helper function: find last occurrence of element in list 144def rfind(l, elt, offs = -1): 145 for i in range(len(l)+offs, 0, -1): 146 if l[i] == elt: 147 return i 148 raise ValueError, "element not found" 149 150# helper function: compare dotted version numbers. 151# E.g., compare_version('1.3.25', '1.4.1') 152# returns -1, 0, 1 if v1 is <, ==, > v2 153def compare_versions(v1, v2): 154 # Convert dotted strings to lists 155 v1 = map(int, v1.split('.')) 156 v2 = map(int, v2.split('.')) 157 # Compare corresponding elements of lists 158 for n1,n2 in zip(v1, v2): 159 if n1 < n2: return -1 160 if n1 > n2: return 1 161 # all corresponding values are equal... see if one has extra values 162 if len(v1) < len(v2): return -1 163 if len(v1) > len(v2): return 1 164 return 0 165 166# Each target must have 'build' in the interior of the path; the 167# directory below this will determine the build parameters. For 168# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 169# recognize that ALPHA_SE specifies the configuration because it 170# follow 'build' in the bulid path. 171 172# Generate absolute paths to targets so we can see where the build dir is 173if COMMAND_LINE_TARGETS: 174 # Ask SCons which directory it was invoked from 175 launch_dir = GetLaunchDir() 176 # Make targets relative to invocation directory 177 abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 178 COMMAND_LINE_TARGETS) 179else: 180 # Default targets are relative to root of tree 181 abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 182 DEFAULT_TARGETS) 183 184 185# Generate a list of the unique build roots and configs that the 186# collected targets reference. 187build_paths = [] 188build_root = None 189for t in abs_targets: 190 path_dirs = t.split('/') 191 try: 192 build_top = rfind(path_dirs, 'build', -2) 193 except: 194 print "Error: no non-leaf 'build' dir found on target path", t 195 Exit(1) 196 this_build_root = joinpath('/',*path_dirs[:build_top+1]) 197 if not build_root: 198 build_root = this_build_root 199 else: 200 if this_build_root != build_root: 201 print "Error: build targets not under same build root\n"\ 202 " %s\n %s" % (build_root, this_build_root) 203 Exit(1) 204 build_path = joinpath('/',*path_dirs[:build_top+2]) 205 if build_path not in build_paths: 206 build_paths.append(build_path) 207 208################################################### 209# 210# Set up the default build environment. This environment is copied 211# and modified according to each selected configuration. 212# 213################################################### 214 215env = Environment(ENV = os.environ, # inherit user's environment vars 216 ROOT = ROOT, 217 SRCDIR = SRCDIR) 218 219#Parse CC/CXX early so that we use the correct compiler for 220# to test for dependencies/versions/libraries/includes 221if ARGUMENTS.get('CC', None): 222 env['CC'] = ARGUMENTS.get('CC') 223 224if ARGUMENTS.get('CXX', None): 225 env['CXX'] = ARGUMENTS.get('CXX') 226 227Export('env') 228 229env.SConsignFile(joinpath(build_root,"sconsign")) 230 231# Default duplicate option is to use hard links, but this messes up 232# when you use emacs to edit a file in the target dir, as emacs moves 233# file to file~ then copies to file, breaking the link. Symbolic 234# (soft) links work better. 235env.SetOption('duplicate', 'soft-copy') 236 237# I waffle on this setting... it does avoid a few painful but 238# unnecessary builds, but it also seems to make trivial builds take 239# noticeably longer. 240if False: 241 env.TargetSignatures('content') 242 243# M5_PLY is used by isa_parser.py to find the PLY package. 244env.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 245env['GCC'] = False 246env['SUNCC'] = False 247env['ICC'] = False 248env['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 249 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 250 close_fds=True).communicate()[0].find('GCC') >= 0 251env['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 252 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 253 close_fds=True).communicate()[0].find('Sun C++') >= 0 254env['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 255 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 256 close_fds=True).communicate()[0].find('Intel') >= 0 257if env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 258 print 'Error: How can we have two at the same time?' 259 Exit(1) 260 261 262# Set up default C++ compiler flags 263if env['GCC']: 264 env.Append(CCFLAGS='-pipe') 265 env.Append(CCFLAGS='-fno-strict-aliasing') 266 env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 267elif env['ICC']: 268 pass #Fix me... add warning flags once we clean up icc warnings 269elif env['SUNCC']: 270 env.Append(CCFLAGS='-Qoption ccfe') 271 env.Append(CCFLAGS='-features=gcc') 272 env.Append(CCFLAGS='-features=extensions') 273 env.Append(CCFLAGS='-library=stlport4') 274 env.Append(CCFLAGS='-xar') 275# env.Append(CCFLAGS='-instances=semiexplicit') 276else: 277 print 'Error: Don\'t know what compiler options to use for your compiler.' 278 print ' Please fix SConstruct and src/SConscript and try again.' 279 Exit(1) 280 281if sys.platform == 'cygwin': 282 # cygwin has some header file issues... 283 env.Append(CCFLAGS=Split("-Wno-uninitialized")) 284env.Append(CPPPATH=[Dir('ext/dnet')]) 285 286# Check for SWIG 287if not env.has_key('SWIG'): 288 print 'Error: SWIG utility not found.' 289 print ' Please install (see http://www.swig.org) and retry.' 290 Exit(1) 291 292# Check for appropriate SWIG version 293swig_version = os.popen('swig -version').read().split() 294# First 3 words should be "SWIG Version x.y.z" 295if len(swig_version) < 3 or \ 296 swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 297 print 'Error determining SWIG version.' 298 Exit(1) 299 300min_swig_version = '1.3.28' 301if compare_versions(swig_version[2], min_swig_version) < 0: 302 print 'Error: SWIG version', min_swig_version, 'or newer required.' 303 print ' Installed version:', swig_version[2] 304 Exit(1) 305 306# Set up SWIG flags & scanner 307swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 308env.Append(SWIGFLAGS=swig_flags) 309 310# filter out all existing swig scanners, they mess up the dependency 311# stuff for some reason 312scanners = [] 313for scanner in env['SCANNERS']: 314 skeys = scanner.skeys 315 if skeys == '.i': 316 continue 317 318 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 319 continue 320 321 scanners.append(scanner) 322 323# add the new swig scanner that we like better 324from SCons.Scanner import ClassicCPP as CPPScanner 325swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 326scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 327 328# replace the scanners list that has what we want 329env['SCANNERS'] = scanners 330 331# Platform-specific configuration. Note again that we assume that all 332# builds under a given build root run on the same host platform. 333conf = Configure(env, 334 conf_dir = joinpath(build_root, '.scons_config'), 335 log_file = joinpath(build_root, 'scons_config.log')) 336 337# Check if we should compile a 64 bit binary on Mac OS X/Darwin 338try: 339 import platform 340 uname = platform.uname() 341 if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 342 if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 343 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 344 close_fds=True).communicate()[0][0]): 345 env.Append(CCFLAGS='-arch x86_64') 346 env.Append(CFLAGS='-arch x86_64') 347 env.Append(LINKFLAGS='-arch x86_64') 348 env.Append(ASFLAGS='-arch x86_64') 349except: 350 pass 351 352# Recent versions of scons substitute a "Null" object for Configure() 353# when configuration isn't necessary, e.g., if the "--help" option is 354# present. Unfortuantely this Null object always returns false, 355# breaking all our configuration checks. We replace it with our own 356# more optimistic null object that returns True instead. 357if not conf: 358 def NullCheck(*args, **kwargs): 359 return True 360 361 class NullConf: 362 def __init__(self, env): 363 self.env = env 364 def Finish(self): 365 return self.env 366 def __getattr__(self, mname): 367 return NullCheck 368 369 conf = NullConf(env) 370 371# Find Python include and library directories for embedding the 372# interpreter. For consistency, we will use the same Python 373# installation used to run scons (and thus this script). If you want 374# to link in an alternate version, see above for instructions on how 375# to invoke scons with a different copy of the Python interpreter. 376 377# Get brief Python version name (e.g., "python2.4") for locating 378# include & library files 379py_version_name = 'python' + sys.version[:3] 380 381# include path, e.g. /usr/local/include/python2.4 382py_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 383env.Append(CPPPATH = py_header_path) 384# verify that it works 385if not conf.CheckHeader('Python.h', '<>'): 386 print "Error: can't find Python.h header in", py_header_path 387 Exit(1) 388 389# add library path too if it's not in the default place 390py_lib_path = None 391if sys.exec_prefix != '/usr': 392 py_lib_path = joinpath(sys.exec_prefix, 'lib') 393elif sys.platform == 'cygwin': 394 # cygwin puts the .dll in /bin for some reason 395 py_lib_path = '/bin' 396if py_lib_path: 397 env.Append(LIBPATH = py_lib_path) 398 print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 399if not conf.CheckLib(py_version_name): 400 print "Error: can't find Python library", py_version_name 401 Exit(1) 402 403# On Solaris you need to use libsocket for socket ops 404if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 405 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 406 print "Can't find library with socket calls (e.g. accept())" 407 Exit(1) 408 409# Check for zlib. If the check passes, libz will be automatically 410# added to the LIBS environment variable. 411if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 412 print 'Error: did not find needed zlib compression library '\ 413 'and/or zlib.h header file.' 414 print ' Please install zlib and try again.' 415 Exit(1) 416 417# Check for <fenv.h> (C99 FP environment control) 418have_fenv = conf.CheckHeader('fenv.h', '<>') 419if not have_fenv: 420 print "Warning: Header file <fenv.h> not found." 421 print " This host has no IEEE FP rounding mode control." 422 423# Check for mysql. 424mysql_config = WhereIs('mysql_config') 425have_mysql = mysql_config != None 426 427# Check MySQL version. 428if have_mysql: 429 mysql_version = os.popen(mysql_config + ' --version').read() 430 min_mysql_version = '4.1' 431 if compare_versions(mysql_version, min_mysql_version) < 0: 432 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 433 print ' Version', mysql_version, 'detected.' 434 have_mysql = False 435 436# Set up mysql_config commands. 437if have_mysql: 438 mysql_config_include = mysql_config + ' --include' 439 if os.system(mysql_config_include + ' > /dev/null') != 0: 440 # older mysql_config versions don't support --include, use 441 # --cflags instead 442 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 443 # This seems to work in all versions 444 mysql_config_libs = mysql_config + ' --libs' 445 446env = conf.Finish() 447 448# Define the universe of supported ISAs 449all_isa_list = [ ] 450Export('all_isa_list') 451 452# Define the universe of supported CPU models 453all_cpu_list = [ ] 454default_cpus = [ ] 455Export('all_cpu_list', 'default_cpus') 456 457# Sticky options get saved in the options file so they persist from 458# one invocation to the next (unless overridden, in which case the new 459# value becomes sticky). 460sticky_opts = Options(args=ARGUMENTS) 461Export('sticky_opts') 462 463# Non-sticky options only apply to the current build. 464nonsticky_opts = Options(args=ARGUMENTS) 465Export('nonsticky_opts') 466 467# Walk the tree and execute all SConsopts scripts that wil add to the 468# above options 469for root, dirs, files in os.walk('.'): 470 if 'SConsopts' in files: 471 SConscript(os.path.join(root, 'SConsopts')) 472 473all_isa_list.sort() 474all_cpu_list.sort() 475default_cpus.sort() 476 477def PathListMakeAbsolute(val): 478 if not val: 479 return val 480 f = lambda p: os.path.abspath(os.path.expanduser(p)) 481 return ':'.join(map(f, val.split(':'))) 482 483def PathListAllExist(key, val, env): 484 if not val: 485 return 486 paths = val.split(':') 487 for path in paths: 488 if not isdir(path): 489 raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 490 491sticky_opts.AddOptions( 492 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 493 BoolOption('FULL_SYSTEM', 'Full-system support', False), 494 # There's a bug in scons 0.96.1 that causes ListOptions with list 495 # values (more than one value) not to be able to be restored from 496 # a saved option file. If this causes trouble then upgrade to 497 # scons 0.96.90 or later. 498 ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 499 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 500 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 501 False), 502 BoolOption('SS_COMPATIBLE_FP', 503 'Make floating-point results compatible with SimpleScalar', 504 False), 505 BoolOption('USE_SSE2', 506 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 507 False), 508 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 509 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 510 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 511 ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 512 ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 513 BoolOption('BATCH', 'Use batch pool for build and tests', False), 514 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 515 ('PYTHONHOME', 516 'Override the default PYTHONHOME for this system (use with caution)', 517 '%s:%s' % (sys.prefix, sys.exec_prefix)), 518 ('EXTRAS', 'Add Extra directories to the compilation', '', 519 PathListAllExist, PathListMakeAbsolute) 520 ) 521 522nonsticky_opts.AddOptions( 523 BoolOption('update_ref', 'Update test reference outputs', False) 524 ) 525 526# These options get exported to #defines in config/*.hh (see src/SConscript). 527env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 528 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 529 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 530 531# Define a handy 'no-op' action 532def no_action(target, source, env): 533 return 0 534 535env.NoAction = Action(no_action, None) 536 537################################################### 538# 539# Define a SCons builder for configuration flag headers. 540# 541################################################### 542 543# This function generates a config header file that #defines the 544# option symbol to the current option setting (0 or 1). The source 545# operands are the name of the option and a Value node containing the 546# value of the option. 547def build_config_file(target, source, env): 548 (option, value) = [s.get_contents() for s in source] 549 f = file(str(target[0]), 'w') 550 print >> f, '#define', option, value 551 f.close() 552 return None 553 554# Generate the message to be printed when building the config file. 555def build_config_file_string(target, source, env): 556 (option, value) = [s.get_contents() for s in source] 557 return "Defining %s as %s in %s." % (option, value, target[0]) 558 559# Combine the two functions into a scons Action object. 560config_action = Action(build_config_file, build_config_file_string) 561 562# The emitter munges the source & target node lists to reflect what 563# we're really doing. 564def config_emitter(target, source, env): 565 # extract option name from Builder arg 566 option = str(target[0]) 567 # True target is config header file 568 target = joinpath('config', option.lower() + '.hh') 569 val = env[option] 570 if isinstance(val, bool): 571 # Force value to 0/1 572 val = int(val) 573 elif isinstance(val, str): 574 val = '"' + val + '"' 575 576 # Sources are option name & value (packaged in SCons Value nodes) 577 return ([target], [Value(option), Value(val)]) 578 579config_builder = Builder(emitter = config_emitter, action = config_action) 580 581env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 582 583################################################### 584# 585# Define a SCons builder for copying files. This is used by the 586# Python zipfile code in src/python/SConscript, but is placed up here 587# since it's potentially more generally applicable. 588# 589################################################### 590 591copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 592 593env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 594 595################################################### 596# 597# Define a simple SCons builder to concatenate files. 598# 599# Used to append the Python zip archive to the executable. 600# 601################################################### 602 603concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 604 'chmod +x $TARGET'])) 605 606env.Append(BUILDERS = { 'Concat' : concat_builder }) 607 608 609# base help text 610help_text = ''' 611Usage: scons [scons options] [build options] [target(s)] 612 613''' 614 615# libelf build is shared across all configs in the build root. 616env.SConscript('ext/libelf/SConscript', 617 build_dir = joinpath(build_root, 'libelf'), 618 exports = 'env') 619 620################################################### 621# 622# This function is used to set up a directory with switching headers 623# 624################################################### 625 626env['ALL_ISA_LIST'] = all_isa_list 627def make_switching_dir(dirname, switch_headers, env): 628 # Generate the header. target[0] is the full path of the output 629 # header to generate. 'source' is a dummy variable, since we get the 630 # list of ISAs from env['ALL_ISA_LIST']. 631 def gen_switch_hdr(target, source, env): 632 fname = str(target[0]) 633 basename = os.path.basename(fname) 634 f = open(fname, 'w') 635 f.write('#include "arch/isa_specific.hh"\n') 636 cond = '#if' 637 for isa in all_isa_list: 638 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 639 % (cond, isa.upper(), dirname, isa, basename)) 640 cond = '#elif' 641 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 642 f.close() 643 return 0 644 645 # String to print when generating header 646 def gen_switch_hdr_string(target, source, env): 647 return "Generating switch header " + str(target[0]) 648 649 # Build SCons Action object. 'varlist' specifies env vars that this 650 # action depends on; when env['ALL_ISA_LIST'] changes these actions 651 # should get re-executed. 652 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 653 varlist=['ALL_ISA_LIST']) 654 655 # Instantiate actions for each header 656 for hdr in switch_headers: 657 env.Command(hdr, [], switch_hdr_action) 658Export('make_switching_dir') 659 660################################################### 661# 662# Define build environments for selected configurations. 663# 664################################################### 665 666# rename base env 667base_env = env 668 669for build_path in build_paths: 670 print "Building in", build_path 671 env['BUILDDIR'] = build_path 672 673 # build_dir is the tail component of build path, and is used to 674 # determine the build parameters (e.g., 'ALPHA_SE') 675 (build_root, build_dir) = os.path.split(build_path) 676 # Make a copy of the build-root environment to use for this config. 677 env = base_env.Copy() 678 679 # Set env options according to the build directory config. 680 sticky_opts.files = [] 681 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 682 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 683 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 684 current_opts_file = joinpath(build_root, 'options', build_dir) 685 if os.path.isfile(current_opts_file): 686 sticky_opts.files.append(current_opts_file) 687 print "Using saved options file %s" % current_opts_file 688 else: 689 # Build dir-specific options file doesn't exist. 690 691 # Make sure the directory is there so we can create it later 692 opt_dir = os.path.dirname(current_opts_file) 693 if not os.path.isdir(opt_dir): 694 os.mkdir(opt_dir) 695 696 # Get default build options from source tree. Options are 697 # normally determined by name of $BUILD_DIR, but can be 698 # overriden by 'default=' arg on command line. 699 default_opts_file = joinpath('build_opts', 700 ARGUMENTS.get('default', build_dir)) 701 if os.path.isfile(default_opts_file): 702 sticky_opts.files.append(default_opts_file) 703 print "Options file %s not found,\n using defaults in %s" \ 704 % (current_opts_file, default_opts_file) 705 else: 706 print "Error: cannot find options file %s or %s" \ 707 % (current_opts_file, default_opts_file) 708 Exit(1) 709 710 # Apply current option settings to env 711 sticky_opts.Update(env) 712 nonsticky_opts.Update(env) 713 714 help_text += "Sticky options for %s:\n" % build_dir \ 715 + sticky_opts.GenerateHelpText(env) \ 716 + "\nNon-sticky options for %s:\n" % build_dir \ 717 + nonsticky_opts.GenerateHelpText(env) 718 719 # Process option settings. 720 721 if not have_fenv and env['USE_FENV']: 722 print "Warning: <fenv.h> not available; " \ 723 "forcing USE_FENV to False in", build_dir + "." 724 env['USE_FENV'] = False 725 726 if not env['USE_FENV']: 727 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 728 print " FP results may deviate slightly from other platforms." 729 730 if env['EFENCE']: 731 env.Append(LIBS=['efence']) 732 733 if env['USE_MYSQL']: 734 if not have_mysql: 735 print "Warning: MySQL not available; " \ 736 "forcing USE_MYSQL to False in", build_dir + "." 737 env['USE_MYSQL'] = False 738 else: 739 print "Compiling in", build_dir, "with MySQL support." 740 env.ParseConfig(mysql_config_libs) 741 env.ParseConfig(mysql_config_include) 742 743 # Save sticky option settings back to current options file 744 sticky_opts.Save(current_opts_file, env) 745 746 # Do this after we save setting back, or else we'll tack on an 747 # extra 'qdo' every time we run scons. 748 if env['BATCH']: 749 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 750 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 751 752 if env['USE_SSE2']: 753 env.Append(CCFLAGS='-msse2') 754 755 # The src/SConscript file sets up the build rules in 'env' according 756 # to the configured options. It returns a list of environments, 757 # one for each variant build (debug, opt, etc.) 758 envList = SConscript('src/SConscript', build_dir = build_path, 759 exports = 'env') 760 761 # Set up the regression tests for each build. 762 for e in envList: 763 SConscript('tests/SConscript', 764 build_dir = joinpath(build_path, 'tests', e.Label), 765 exports = { 'env' : e }, duplicate = False) 766 767Help(help_text) 768 769 770################################################### 771# 772# Let SCons do its thing. At this point SCons will use the defined 773# build environments to build the requested targets. 774# 775################################################### 776 777