145# Generate a list of the unique build roots and configs that the 146# collected targets reference. 147build_paths = [] 148build_root = None 149for t in abs_targets: 150 path_dirs = t.split('/') 151 try: 152 build_top = rfind(path_dirs, 'build', -2) 153 except: 154 print "Error: no non-leaf 'build' dir found on target path", t 155 Exit(1) 156 this_build_root = joinpath('/',*path_dirs[:build_top+1]) 157 if not build_root: 158 build_root = this_build_root 159 else: 160 if this_build_root != build_root: 161 print "Error: build targets not under same build root\n"\ 162 " %s\n %s" % (build_root, this_build_root) 163 Exit(1) 164 build_path = joinpath('/',*path_dirs[:build_top+2]) 165 if build_path not in build_paths: 166 build_paths.append(build_path) 167 168################################################### 169# 170# Set up the default build environment. This environment is copied 171# and modified according to each selected configuration. 172# 173################################################### 174 175env = Environment(ENV = os.environ, # inherit user's environment vars 176 ROOT = ROOT, 177 SRCDIR = SRCDIR) 178 179#Parse CC/CXX early so that we use the correct compiler for 180# to test for dependencies/versions/libraries/includes 181if ARGUMENTS.get('CC', None): 182 env['CC'] = ARGUMENTS.get('CC') 183 184if ARGUMENTS.get('CXX', None): 185 env['CXX'] = ARGUMENTS.get('CXX') 186 187env.SConsignFile(joinpath(build_root,"sconsign")) 188 189# Default duplicate option is to use hard links, but this messes up 190# when you use emacs to edit a file in the target dir, as emacs moves 191# file to file~ then copies to file, breaking the link. Symbolic 192# (soft) links work better. 193env.SetOption('duplicate', 'soft-copy') 194 195# I waffle on this setting... it does avoid a few painful but 196# unnecessary builds, but it also seems to make trivial builds take 197# noticeably longer. 198if False: 199 env.TargetSignatures('content') 200 201# M5_PLY is used by isa_parser.py to find the PLY package. 202env.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 203 204# Set up default C++ compiler flags 205env.Append(CCFLAGS='-pipe') 206env.Append(CCFLAGS='-fno-strict-aliasing') 207env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 208if sys.platform == 'cygwin': 209 # cygwin has some header file issues... 210 env.Append(CCFLAGS=Split("-Wno-uninitialized")) 211env.Append(CPPPATH=[Dir('ext/dnet')]) 212 213# Check for SWIG 214if not env.has_key('SWIG'): 215 print 'Error: SWIG utility not found.' 216 print ' Please install (see http://www.swig.org) and retry.' 217 Exit(1) 218 219# Check for appropriate SWIG version 220swig_version = os.popen('swig -version').read().split() 221# First 3 words should be "SWIG Version x.y.z" 222if swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 223 print 'Error determining SWIG version.' 224 Exit(1) 225 226min_swig_version = '1.3.28' 227if compare_versions(swig_version[2], min_swig_version) < 0: 228 print 'Error: SWIG version', min_swig_version, 'or newer required.' 229 print ' Installed version:', swig_version[2] 230 Exit(1) 231 232# Set up SWIG flags & scanner 233env.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 234 235import SCons.Scanner 236 237swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 238 239swig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 240 swig_inc_re) 241 242env.Append(SCANNERS = swig_scanner) 243 244# Platform-specific configuration. Note again that we assume that all 245# builds under a given build root run on the same host platform. 246conf = Configure(env, 247 conf_dir = joinpath(build_root, '.scons_config'), 248 log_file = joinpath(build_root, 'scons_config.log')) 249 250# Find Python include and library directories for embedding the 251# interpreter. For consistency, we will use the same Python 252# installation used to run scons (and thus this script). If you want 253# to link in an alternate version, see above for instructions on how 254# to invoke scons with a different copy of the Python interpreter. 255 256# Get brief Python version name (e.g., "python2.4") for locating 257# include & library files 258py_version_name = 'python' + sys.version[:3] 259 260# include path, e.g. /usr/local/include/python2.4 261py_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 262env.Append(CPPPATH = py_header_path) 263# verify that it works 264if not conf.CheckHeader('Python.h', '<>'): 265 print "Error: can't find Python.h header in", py_header_path 266 Exit(1) 267 268# add library path too if it's not in the default place 269py_lib_path = None 270if sys.exec_prefix != '/usr': 271 py_lib_path = joinpath(sys.exec_prefix, 'lib') 272elif sys.platform == 'cygwin': 273 # cygwin puts the .dll in /bin for some reason 274 py_lib_path = '/bin' 275if py_lib_path: 276 env.Append(LIBPATH = py_lib_path) 277 print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 278if not conf.CheckLib(py_version_name): 279 print "Error: can't find Python library", py_version_name 280 Exit(1) 281 282# On Solaris you need to use libsocket for socket ops 283if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 284 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 285 print "Can't find library with socket calls (e.g. accept())" 286 Exit(1) 287 288# Check for zlib. If the check passes, libz will be automatically 289# added to the LIBS environment variable. 290if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 291 print 'Error: did not find needed zlib compression library '\ 292 'and/or zlib.h header file.' 293 print ' Please install zlib and try again.' 294 Exit(1) 295 296# Check for <fenv.h> (C99 FP environment control) 297have_fenv = conf.CheckHeader('fenv.h', '<>') 298if not have_fenv: 299 print "Warning: Header file <fenv.h> not found." 300 print " This host has no IEEE FP rounding mode control." 301 302# Check for mysql. 303mysql_config = WhereIs('mysql_config') 304have_mysql = mysql_config != None 305 306# Check MySQL version. 307if have_mysql: 308 mysql_version = os.popen(mysql_config + ' --version').read() 309 min_mysql_version = '4.1' 310 if compare_versions(mysql_version, min_mysql_version) < 0: 311 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 312 print ' Version', mysql_version, 'detected.' 313 have_mysql = False 314 315# Set up mysql_config commands. 316if have_mysql: 317 mysql_config_include = mysql_config + ' --include' 318 if os.system(mysql_config_include + ' > /dev/null') != 0: 319 # older mysql_config versions don't support --include, use 320 # --cflags instead 321 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 322 # This seems to work in all versions 323 mysql_config_libs = mysql_config + ' --libs' 324 325env = conf.Finish() 326 327# Define the universe of supported ISAs 328env['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 329 330# Define the universe of supported CPU models 331env['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 332 'O3CPU', 'OzoneCPU'] 333 334if os.path.isdir(joinpath(SRCDIR, 'encumbered/cpu/full')): 335 env['ALL_CPU_LIST'] += ['FullCPU'] 336 337# Sticky options get saved in the options file so they persist from 338# one invocation to the next (unless overridden, in which case the new 339# value becomes sticky). 340sticky_opts = Options(args=ARGUMENTS) 341sticky_opts.AddOptions( 342 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 343 BoolOption('FULL_SYSTEM', 'Full-system support', False), 344 # There's a bug in scons 0.96.1 that causes ListOptions with list 345 # values (more than one value) not to be able to be restored from 346 # a saved option file. If this causes trouble then upgrade to 347 # scons 0.96.90 or later. 348 ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU,O3CPU', 349 env['ALL_CPU_LIST']), 350 BoolOption('ALPHA_TLASER', 351 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 352 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 353 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 354 False), 355 BoolOption('SS_COMPATIBLE_FP', 356 'Make floating-point results compatible with SimpleScalar', 357 False), 358 BoolOption('USE_SSE2', 359 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 360 False), 361 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 362 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 363 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 364 ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 365 ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 366 BoolOption('BATCH', 'Use batch pool for build and tests', False), 367 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 368 ('PYTHONHOME', 369 'Override the default PYTHONHOME for this system (use with caution)', 370 '%s:%s' % (sys.prefix, sys.exec_prefix)) 371 ) 372 373# Non-sticky options only apply to the current build. 374nonsticky_opts = Options(args=ARGUMENTS) 375nonsticky_opts.AddOptions( 376 BoolOption('update_ref', 'Update test reference outputs', False) 377 ) 378 379# These options get exported to #defines in config/*.hh (see src/SConscript). 380env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 381 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 382 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 383 384# Define a handy 'no-op' action 385def no_action(target, source, env): 386 return 0 387 388env.NoAction = Action(no_action, None) 389 390################################################### 391# 392# Define a SCons builder for configuration flag headers. 393# 394################################################### 395 396# This function generates a config header file that #defines the 397# option symbol to the current option setting (0 or 1). The source 398# operands are the name of the option and a Value node containing the 399# value of the option. 400def build_config_file(target, source, env): 401 (option, value) = [s.get_contents() for s in source] 402 f = file(str(target[0]), 'w') 403 print >> f, '#define', option, value 404 f.close() 405 return None 406 407# Generate the message to be printed when building the config file. 408def build_config_file_string(target, source, env): 409 (option, value) = [s.get_contents() for s in source] 410 return "Defining %s as %s in %s." % (option, value, target[0]) 411 412# Combine the two functions into a scons Action object. 413config_action = Action(build_config_file, build_config_file_string) 414 415# The emitter munges the source & target node lists to reflect what 416# we're really doing. 417def config_emitter(target, source, env): 418 # extract option name from Builder arg 419 option = str(target[0]) 420 # True target is config header file 421 target = joinpath('config', option.lower() + '.hh') 422 val = env[option] 423 if isinstance(val, bool): 424 # Force value to 0/1 425 val = int(val) 426 elif isinstance(val, str): 427 val = '"' + val + '"' 428 429 # Sources are option name & value (packaged in SCons Value nodes) 430 return ([target], [Value(option), Value(val)]) 431 432config_builder = Builder(emitter = config_emitter, action = config_action) 433 434env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 435 436################################################### 437# 438# Define a SCons builder for copying files. This is used by the 439# Python zipfile code in src/python/SConscript, but is placed up here 440# since it's potentially more generally applicable. 441# 442################################################### 443 444copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 445 446env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 447 448################################################### 449# 450# Define a simple SCons builder to concatenate files. 451# 452# Used to append the Python zip archive to the executable. 453# 454################################################### 455 456concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 457 'chmod +x $TARGET'])) 458 459env.Append(BUILDERS = { 'Concat' : concat_builder }) 460 461 462# base help text 463help_text = ''' 464Usage: scons [scons options] [build options] [target(s)] 465 466''' 467 468# libelf build is shared across all configs in the build root. 469env.SConscript('ext/libelf/SConscript', 470 build_dir = joinpath(build_root, 'libelf'), 471 exports = 'env') 472 473################################################### 474# 475# This function is used to set up a directory with switching headers 476# 477################################################### 478 479def make_switching_dir(dirname, switch_headers, env): 480 # Generate the header. target[0] is the full path of the output 481 # header to generate. 'source' is a dummy variable, since we get the 482 # list of ISAs from env['ALL_ISA_LIST']. 483 def gen_switch_hdr(target, source, env): 484 fname = str(target[0]) 485 basename = os.path.basename(fname) 486 f = open(fname, 'w') 487 f.write('#include "arch/isa_specific.hh"\n') 488 cond = '#if' 489 for isa in env['ALL_ISA_LIST']: 490 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 491 % (cond, isa.upper(), dirname, isa, basename)) 492 cond = '#elif' 493 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 494 f.close() 495 return 0 496 497 # String to print when generating header 498 def gen_switch_hdr_string(target, source, env): 499 return "Generating switch header " + str(target[0]) 500 501 # Build SCons Action object. 'varlist' specifies env vars that this 502 # action depends on; when env['ALL_ISA_LIST'] changes these actions 503 # should get re-executed. 504 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 505 varlist=['ALL_ISA_LIST']) 506 507 # Instantiate actions for each header 508 for hdr in switch_headers: 509 env.Command(hdr, [], switch_hdr_action) 510 511env.make_switching_dir = make_switching_dir 512 513################################################### 514# 515# Define build environments for selected configurations. 516# 517################################################### 518 519# rename base env 520base_env = env 521 522for build_path in build_paths: 523 print "Building in", build_path 524 # build_dir is the tail component of build path, and is used to 525 # determine the build parameters (e.g., 'ALPHA_SE') 526 (build_root, build_dir) = os.path.split(build_path) 527 # Make a copy of the build-root environment to use for this config. 528 env = base_env.Copy() 529 530 # Set env options according to the build directory config. 531 sticky_opts.files = [] 532 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 533 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 534 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 535 current_opts_file = joinpath(build_root, 'options', build_dir) 536 if os.path.isfile(current_opts_file): 537 sticky_opts.files.append(current_opts_file) 538 print "Using saved options file %s" % current_opts_file 539 else: 540 # Build dir-specific options file doesn't exist. 541 542 # Make sure the directory is there so we can create it later 543 opt_dir = os.path.dirname(current_opts_file) 544 if not os.path.isdir(opt_dir): 545 os.mkdir(opt_dir) 546 547 # Get default build options from source tree. Options are 548 # normally determined by name of $BUILD_DIR, but can be 549 # overriden by 'default=' arg on command line. 550 default_opts_file = joinpath('build_opts', 551 ARGUMENTS.get('default', build_dir)) 552 if os.path.isfile(default_opts_file): 553 sticky_opts.files.append(default_opts_file) 554 print "Options file %s not found,\n using defaults in %s" \ 555 % (current_opts_file, default_opts_file) 556 else: 557 print "Error: cannot find options file %s or %s" \ 558 % (current_opts_file, default_opts_file) 559 Exit(1) 560 561 # Apply current option settings to env 562 sticky_opts.Update(env) 563 nonsticky_opts.Update(env) 564 565 help_text += "Sticky options for %s:\n" % build_dir \ 566 + sticky_opts.GenerateHelpText(env) \ 567 + "\nNon-sticky options for %s:\n" % build_dir \ 568 + nonsticky_opts.GenerateHelpText(env) 569 570 # Process option settings. 571 572 if not have_fenv and env['USE_FENV']: 573 print "Warning: <fenv.h> not available; " \ 574 "forcing USE_FENV to False in", build_dir + "." 575 env['USE_FENV'] = False 576 577 if not env['USE_FENV']: 578 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 579 print " FP results may deviate slightly from other platforms." 580 581 if env['EFENCE']: 582 env.Append(LIBS=['efence']) 583 584 if env['USE_MYSQL']: 585 if not have_mysql: 586 print "Warning: MySQL not available; " \ 587 "forcing USE_MYSQL to False in", build_dir + "." 588 env['USE_MYSQL'] = False 589 else: 590 print "Compiling in", build_dir, "with MySQL support." 591 env.ParseConfig(mysql_config_libs) 592 env.ParseConfig(mysql_config_include) 593 594 # Save sticky option settings back to current options file 595 sticky_opts.Save(current_opts_file, env) 596 597 # Do this after we save setting back, or else we'll tack on an 598 # extra 'qdo' every time we run scons. 599 if env['BATCH']: 600 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 601 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 602 603 if env['USE_SSE2']: 604 env.Append(CCFLAGS='-msse2') 605 606 # The src/SConscript file sets up the build rules in 'env' according 607 # to the configured options. It returns a list of environments, 608 # one for each variant build (debug, opt, etc.) 609 envList = SConscript('src/SConscript', build_dir = build_path, 610 exports = 'env') 611 612 # Set up the regression tests for each build. 613 for e in envList: 614 SConscript('tests/SConscript', 615 build_dir = joinpath(build_path, 'tests', e.Label), 616 exports = { 'env' : e }, duplicate = False) 617 618Help(help_text) 619 620 621################################################### 622# 623# Let SCons do its thing. At this point SCons will use the defined 624# build environments to build the requested targets. 625# 626################################################### 627
| 151# Generate a list of the unique build roots and configs that the 152# collected targets reference. 153build_paths = [] 154build_root = None 155for t in abs_targets: 156 path_dirs = t.split('/') 157 try: 158 build_top = rfind(path_dirs, 'build', -2) 159 except: 160 print "Error: no non-leaf 'build' dir found on target path", t 161 Exit(1) 162 this_build_root = joinpath('/',*path_dirs[:build_top+1]) 163 if not build_root: 164 build_root = this_build_root 165 else: 166 if this_build_root != build_root: 167 print "Error: build targets not under same build root\n"\ 168 " %s\n %s" % (build_root, this_build_root) 169 Exit(1) 170 build_path = joinpath('/',*path_dirs[:build_top+2]) 171 if build_path not in build_paths: 172 build_paths.append(build_path) 173 174################################################### 175# 176# Set up the default build environment. This environment is copied 177# and modified according to each selected configuration. 178# 179################################################### 180 181env = Environment(ENV = os.environ, # inherit user's environment vars 182 ROOT = ROOT, 183 SRCDIR = SRCDIR) 184 185#Parse CC/CXX early so that we use the correct compiler for 186# to test for dependencies/versions/libraries/includes 187if ARGUMENTS.get('CC', None): 188 env['CC'] = ARGUMENTS.get('CC') 189 190if ARGUMENTS.get('CXX', None): 191 env['CXX'] = ARGUMENTS.get('CXX') 192 193env.SConsignFile(joinpath(build_root,"sconsign")) 194 195# Default duplicate option is to use hard links, but this messes up 196# when you use emacs to edit a file in the target dir, as emacs moves 197# file to file~ then copies to file, breaking the link. Symbolic 198# (soft) links work better. 199env.SetOption('duplicate', 'soft-copy') 200 201# I waffle on this setting... it does avoid a few painful but 202# unnecessary builds, but it also seems to make trivial builds take 203# noticeably longer. 204if False: 205 env.TargetSignatures('content') 206 207# M5_PLY is used by isa_parser.py to find the PLY package. 208env.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 209 210# Set up default C++ compiler flags 211env.Append(CCFLAGS='-pipe') 212env.Append(CCFLAGS='-fno-strict-aliasing') 213env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 214if sys.platform == 'cygwin': 215 # cygwin has some header file issues... 216 env.Append(CCFLAGS=Split("-Wno-uninitialized")) 217env.Append(CPPPATH=[Dir('ext/dnet')]) 218 219# Check for SWIG 220if not env.has_key('SWIG'): 221 print 'Error: SWIG utility not found.' 222 print ' Please install (see http://www.swig.org) and retry.' 223 Exit(1) 224 225# Check for appropriate SWIG version 226swig_version = os.popen('swig -version').read().split() 227# First 3 words should be "SWIG Version x.y.z" 228if swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 229 print 'Error determining SWIG version.' 230 Exit(1) 231 232min_swig_version = '1.3.28' 233if compare_versions(swig_version[2], min_swig_version) < 0: 234 print 'Error: SWIG version', min_swig_version, 'or newer required.' 235 print ' Installed version:', swig_version[2] 236 Exit(1) 237 238# Set up SWIG flags & scanner 239env.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 240 241import SCons.Scanner 242 243swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 244 245swig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 246 swig_inc_re) 247 248env.Append(SCANNERS = swig_scanner) 249 250# Platform-specific configuration. Note again that we assume that all 251# builds under a given build root run on the same host platform. 252conf = Configure(env, 253 conf_dir = joinpath(build_root, '.scons_config'), 254 log_file = joinpath(build_root, 'scons_config.log')) 255 256# Find Python include and library directories for embedding the 257# interpreter. For consistency, we will use the same Python 258# installation used to run scons (and thus this script). If you want 259# to link in an alternate version, see above for instructions on how 260# to invoke scons with a different copy of the Python interpreter. 261 262# Get brief Python version name (e.g., "python2.4") for locating 263# include & library files 264py_version_name = 'python' + sys.version[:3] 265 266# include path, e.g. /usr/local/include/python2.4 267py_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 268env.Append(CPPPATH = py_header_path) 269# verify that it works 270if not conf.CheckHeader('Python.h', '<>'): 271 print "Error: can't find Python.h header in", py_header_path 272 Exit(1) 273 274# add library path too if it's not in the default place 275py_lib_path = None 276if sys.exec_prefix != '/usr': 277 py_lib_path = joinpath(sys.exec_prefix, 'lib') 278elif sys.platform == 'cygwin': 279 # cygwin puts the .dll in /bin for some reason 280 py_lib_path = '/bin' 281if py_lib_path: 282 env.Append(LIBPATH = py_lib_path) 283 print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 284if not conf.CheckLib(py_version_name): 285 print "Error: can't find Python library", py_version_name 286 Exit(1) 287 288# On Solaris you need to use libsocket for socket ops 289if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 290 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 291 print "Can't find library with socket calls (e.g. accept())" 292 Exit(1) 293 294# Check for zlib. If the check passes, libz will be automatically 295# added to the LIBS environment variable. 296if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 297 print 'Error: did not find needed zlib compression library '\ 298 'and/or zlib.h header file.' 299 print ' Please install zlib and try again.' 300 Exit(1) 301 302# Check for <fenv.h> (C99 FP environment control) 303have_fenv = conf.CheckHeader('fenv.h', '<>') 304if not have_fenv: 305 print "Warning: Header file <fenv.h> not found." 306 print " This host has no IEEE FP rounding mode control." 307 308# Check for mysql. 309mysql_config = WhereIs('mysql_config') 310have_mysql = mysql_config != None 311 312# Check MySQL version. 313if have_mysql: 314 mysql_version = os.popen(mysql_config + ' --version').read() 315 min_mysql_version = '4.1' 316 if compare_versions(mysql_version, min_mysql_version) < 0: 317 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 318 print ' Version', mysql_version, 'detected.' 319 have_mysql = False 320 321# Set up mysql_config commands. 322if have_mysql: 323 mysql_config_include = mysql_config + ' --include' 324 if os.system(mysql_config_include + ' > /dev/null') != 0: 325 # older mysql_config versions don't support --include, use 326 # --cflags instead 327 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 328 # This seems to work in all versions 329 mysql_config_libs = mysql_config + ' --libs' 330 331env = conf.Finish() 332 333# Define the universe of supported ISAs 334env['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 335 336# Define the universe of supported CPU models 337env['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 338 'O3CPU', 'OzoneCPU'] 339 340if os.path.isdir(joinpath(SRCDIR, 'encumbered/cpu/full')): 341 env['ALL_CPU_LIST'] += ['FullCPU'] 342 343# Sticky options get saved in the options file so they persist from 344# one invocation to the next (unless overridden, in which case the new 345# value becomes sticky). 346sticky_opts = Options(args=ARGUMENTS) 347sticky_opts.AddOptions( 348 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 349 BoolOption('FULL_SYSTEM', 'Full-system support', False), 350 # There's a bug in scons 0.96.1 that causes ListOptions with list 351 # values (more than one value) not to be able to be restored from 352 # a saved option file. If this causes trouble then upgrade to 353 # scons 0.96.90 or later. 354 ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU,O3CPU', 355 env['ALL_CPU_LIST']), 356 BoolOption('ALPHA_TLASER', 357 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 358 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 359 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 360 False), 361 BoolOption('SS_COMPATIBLE_FP', 362 'Make floating-point results compatible with SimpleScalar', 363 False), 364 BoolOption('USE_SSE2', 365 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 366 False), 367 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 368 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 369 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 370 ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 371 ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 372 BoolOption('BATCH', 'Use batch pool for build and tests', False), 373 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 374 ('PYTHONHOME', 375 'Override the default PYTHONHOME for this system (use with caution)', 376 '%s:%s' % (sys.prefix, sys.exec_prefix)) 377 ) 378 379# Non-sticky options only apply to the current build. 380nonsticky_opts = Options(args=ARGUMENTS) 381nonsticky_opts.AddOptions( 382 BoolOption('update_ref', 'Update test reference outputs', False) 383 ) 384 385# These options get exported to #defines in config/*.hh (see src/SConscript). 386env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 387 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 388 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 389 390# Define a handy 'no-op' action 391def no_action(target, source, env): 392 return 0 393 394env.NoAction = Action(no_action, None) 395 396################################################### 397# 398# Define a SCons builder for configuration flag headers. 399# 400################################################### 401 402# This function generates a config header file that #defines the 403# option symbol to the current option setting (0 or 1). The source 404# operands are the name of the option and a Value node containing the 405# value of the option. 406def build_config_file(target, source, env): 407 (option, value) = [s.get_contents() for s in source] 408 f = file(str(target[0]), 'w') 409 print >> f, '#define', option, value 410 f.close() 411 return None 412 413# Generate the message to be printed when building the config file. 414def build_config_file_string(target, source, env): 415 (option, value) = [s.get_contents() for s in source] 416 return "Defining %s as %s in %s." % (option, value, target[0]) 417 418# Combine the two functions into a scons Action object. 419config_action = Action(build_config_file, build_config_file_string) 420 421# The emitter munges the source & target node lists to reflect what 422# we're really doing. 423def config_emitter(target, source, env): 424 # extract option name from Builder arg 425 option = str(target[0]) 426 # True target is config header file 427 target = joinpath('config', option.lower() + '.hh') 428 val = env[option] 429 if isinstance(val, bool): 430 # Force value to 0/1 431 val = int(val) 432 elif isinstance(val, str): 433 val = '"' + val + '"' 434 435 # Sources are option name & value (packaged in SCons Value nodes) 436 return ([target], [Value(option), Value(val)]) 437 438config_builder = Builder(emitter = config_emitter, action = config_action) 439 440env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 441 442################################################### 443# 444# Define a SCons builder for copying files. This is used by the 445# Python zipfile code in src/python/SConscript, but is placed up here 446# since it's potentially more generally applicable. 447# 448################################################### 449 450copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 451 452env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 453 454################################################### 455# 456# Define a simple SCons builder to concatenate files. 457# 458# Used to append the Python zip archive to the executable. 459# 460################################################### 461 462concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 463 'chmod +x $TARGET'])) 464 465env.Append(BUILDERS = { 'Concat' : concat_builder }) 466 467 468# base help text 469help_text = ''' 470Usage: scons [scons options] [build options] [target(s)] 471 472''' 473 474# libelf build is shared across all configs in the build root. 475env.SConscript('ext/libelf/SConscript', 476 build_dir = joinpath(build_root, 'libelf'), 477 exports = 'env') 478 479################################################### 480# 481# This function is used to set up a directory with switching headers 482# 483################################################### 484 485def make_switching_dir(dirname, switch_headers, env): 486 # Generate the header. target[0] is the full path of the output 487 # header to generate. 'source' is a dummy variable, since we get the 488 # list of ISAs from env['ALL_ISA_LIST']. 489 def gen_switch_hdr(target, source, env): 490 fname = str(target[0]) 491 basename = os.path.basename(fname) 492 f = open(fname, 'w') 493 f.write('#include "arch/isa_specific.hh"\n') 494 cond = '#if' 495 for isa in env['ALL_ISA_LIST']: 496 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 497 % (cond, isa.upper(), dirname, isa, basename)) 498 cond = '#elif' 499 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 500 f.close() 501 return 0 502 503 # String to print when generating header 504 def gen_switch_hdr_string(target, source, env): 505 return "Generating switch header " + str(target[0]) 506 507 # Build SCons Action object. 'varlist' specifies env vars that this 508 # action depends on; when env['ALL_ISA_LIST'] changes these actions 509 # should get re-executed. 510 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 511 varlist=['ALL_ISA_LIST']) 512 513 # Instantiate actions for each header 514 for hdr in switch_headers: 515 env.Command(hdr, [], switch_hdr_action) 516 517env.make_switching_dir = make_switching_dir 518 519################################################### 520# 521# Define build environments for selected configurations. 522# 523################################################### 524 525# rename base env 526base_env = env 527 528for build_path in build_paths: 529 print "Building in", build_path 530 # build_dir is the tail component of build path, and is used to 531 # determine the build parameters (e.g., 'ALPHA_SE') 532 (build_root, build_dir) = os.path.split(build_path) 533 # Make a copy of the build-root environment to use for this config. 534 env = base_env.Copy() 535 536 # Set env options according to the build directory config. 537 sticky_opts.files = [] 538 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 539 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 540 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 541 current_opts_file = joinpath(build_root, 'options', build_dir) 542 if os.path.isfile(current_opts_file): 543 sticky_opts.files.append(current_opts_file) 544 print "Using saved options file %s" % current_opts_file 545 else: 546 # Build dir-specific options file doesn't exist. 547 548 # Make sure the directory is there so we can create it later 549 opt_dir = os.path.dirname(current_opts_file) 550 if not os.path.isdir(opt_dir): 551 os.mkdir(opt_dir) 552 553 # Get default build options from source tree. Options are 554 # normally determined by name of $BUILD_DIR, but can be 555 # overriden by 'default=' arg on command line. 556 default_opts_file = joinpath('build_opts', 557 ARGUMENTS.get('default', build_dir)) 558 if os.path.isfile(default_opts_file): 559 sticky_opts.files.append(default_opts_file) 560 print "Options file %s not found,\n using defaults in %s" \ 561 % (current_opts_file, default_opts_file) 562 else: 563 print "Error: cannot find options file %s or %s" \ 564 % (current_opts_file, default_opts_file) 565 Exit(1) 566 567 # Apply current option settings to env 568 sticky_opts.Update(env) 569 nonsticky_opts.Update(env) 570 571 help_text += "Sticky options for %s:\n" % build_dir \ 572 + sticky_opts.GenerateHelpText(env) \ 573 + "\nNon-sticky options for %s:\n" % build_dir \ 574 + nonsticky_opts.GenerateHelpText(env) 575 576 # Process option settings. 577 578 if not have_fenv and env['USE_FENV']: 579 print "Warning: <fenv.h> not available; " \ 580 "forcing USE_FENV to False in", build_dir + "." 581 env['USE_FENV'] = False 582 583 if not env['USE_FENV']: 584 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 585 print " FP results may deviate slightly from other platforms." 586 587 if env['EFENCE']: 588 env.Append(LIBS=['efence']) 589 590 if env['USE_MYSQL']: 591 if not have_mysql: 592 print "Warning: MySQL not available; " \ 593 "forcing USE_MYSQL to False in", build_dir + "." 594 env['USE_MYSQL'] = False 595 else: 596 print "Compiling in", build_dir, "with MySQL support." 597 env.ParseConfig(mysql_config_libs) 598 env.ParseConfig(mysql_config_include) 599 600 # Save sticky option settings back to current options file 601 sticky_opts.Save(current_opts_file, env) 602 603 # Do this after we save setting back, or else we'll tack on an 604 # extra 'qdo' every time we run scons. 605 if env['BATCH']: 606 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 607 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 608 609 if env['USE_SSE2']: 610 env.Append(CCFLAGS='-msse2') 611 612 # The src/SConscript file sets up the build rules in 'env' according 613 # to the configured options. It returns a list of environments, 614 # one for each variant build (debug, opt, etc.) 615 envList = SConscript('src/SConscript', build_dir = build_path, 616 exports = 'env') 617 618 # Set up the regression tests for each build. 619 for e in envList: 620 SConscript('tests/SConscript', 621 build_dir = joinpath(build_path, 'tests', e.Label), 622 exports = { 'env' : e }, duplicate = False) 623 624Help(help_text) 625 626 627################################################### 628# 629# Let SCons do its thing. At this point SCons will use the defined 630# build environments to build the requested targets. 631# 632################################################### 633
|