SConstruct (3685:c60391e0f767) | SConstruct (3716:70d75ce167a3) |
---|---|
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 --- 52 unchanged lines hidden (view full) --- 61# file), you can use 'scons -h' to print all the M5-specific build 62# options as well. 63# 64################################################### 65 66# Python library imports 67import sys 68import os | 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 --- 52 unchanged lines hidden (view full) --- 61# file), you can use 'scons -h' to print all the M5-specific build 62# options as well. 63# 64################################################### 65 66# Python library imports 67import sys 68import os |
69from os.path import join as joinpath |
|
69 70# Check for recent-enough Python and SCons versions. If your system's 71# default installation of Python is not recent enough, you can use a 72# non-default installation of the Python interpreter by either (1) 73# rearranging your PATH so that scons finds the non-default 'python' 74# first or (2) explicitly invoking an alternative interpreter on the 75# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 76EnsurePythonVersion(2,4) --- 8 unchanged lines hidden (view full) --- 85 print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 86 Exit(2) 87 88 89# The absolute path to the current directory (where this file lives). 90ROOT = Dir('.').abspath 91 92# Paths to the M5 and external source trees. | 70 71# Check for recent-enough Python and SCons versions. If your system's 72# default installation of Python is not recent enough, you can use a 73# non-default installation of the Python interpreter by either (1) 74# rearranging your PATH so that scons finds the non-default 'python' 75# first or (2) explicitly invoking an alternative interpreter on the 76# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 77EnsurePythonVersion(2,4) --- 8 unchanged lines hidden (view full) --- 86 print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 87 Exit(2) 88 89 90# The absolute path to the current directory (where this file lives). 91ROOT = Dir('.').abspath 92 93# Paths to the M5 and external source trees. |
93SRCDIR = os.path.join(ROOT, 'src') | 94SRCDIR = joinpath(ROOT, 'src') |
94 95# tell python where to find m5 python code | 95 96# tell python where to find m5 python code |
96sys.path.append(os.path.join(ROOT, 'src/python')) | 97sys.path.append(joinpath(ROOT, 'src/python')) |
97 98################################################### 99# 100# Figure out which configurations to set up based on the path(s) of 101# the target(s). 102# 103################################################### 104 105# Find default configuration & binary. 106Default(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 107 108# Ask SCons which directory it was invoked from. 109launch_dir = GetLaunchDir() 110 111# Make targets relative to invocation directory | 98 99################################################### 100# 101# Figure out which configurations to set up based on the path(s) of 102# the target(s). 103# 104################################################### 105 106# Find default configuration & binary. 107Default(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 108 109# Ask SCons which directory it was invoked from. 110launch_dir = GetLaunchDir() 111 112# Make targets relative to invocation directory |
112abs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), | 113abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), |
113 BUILD_TARGETS) 114 115# helper function: find last occurrence of element in list 116def rfind(l, elt, offs = -1): 117 for i in range(len(l)+offs, 0, -1): 118 if l[i] == elt: 119 return i 120 raise ValueError, "element not found" --- 26 unchanged lines hidden (view full) --- 147build_root = None 148for t in abs_targets: 149 path_dirs = t.split('/') 150 try: 151 build_top = rfind(path_dirs, 'build', -2) 152 except: 153 print "Error: no non-leaf 'build' dir found on target path", t 154 Exit(1) | 114 BUILD_TARGETS) 115 116# helper function: find last occurrence of element in list 117def rfind(l, elt, offs = -1): 118 for i in range(len(l)+offs, 0, -1): 119 if l[i] == elt: 120 return i 121 raise ValueError, "element not found" --- 26 unchanged lines hidden (view full) --- 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) |
155 this_build_root = os.path.join('/',*path_dirs[:build_top+1]) | 156 this_build_root = joinpath('/',*path_dirs[:build_top+1]) |
156 if not build_root: 157 build_root = this_build_root 158 else: 159 if this_build_root != build_root: 160 print "Error: build targets not under same build root\n"\ 161 " %s\n %s" % (build_root, this_build_root) 162 Exit(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) |
163 build_path = os.path.join('/',*path_dirs[:build_top+2]) | 164 build_path = joinpath('/',*path_dirs[:build_top+2]) |
164 if build_path not in build_paths: 165 build_paths.append(build_path) 166 167################################################### 168# 169# Set up the default build environment. This environment is copied 170# and modified according to each selected configuration. 171# --- 6 unchanged lines hidden (view full) --- 178#Parse CC/CXX early so that we use the correct compiler for 179# to test for dependencies/versions/libraries/includes 180if ARGUMENTS.get('CC', None): 181 env['CC'] = ARGUMENTS.get('CC') 182 183if ARGUMENTS.get('CXX', None): 184 env['CXX'] = ARGUMENTS.get('CXX') 185 | 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# --- 6 unchanged lines hidden (view full) --- 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 |
186env.SConsignFile(os.path.join(build_root,"sconsign")) | 187env.SConsignFile(joinpath(build_root,"sconsign")) |
187 188# Default duplicate option is to use hard links, but this messes up 189# when you use emacs to edit a file in the target dir, as emacs moves 190# file to file~ then copies to file, breaking the link. Symbolic 191# (soft) links work better. 192env.SetOption('duplicate', 'soft-copy') 193 194# I waffle on this setting... it does avoid a few painful but --- 43 unchanged lines hidden (view full) --- 238swig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 239 swig_inc_re) 240 241env.Append(SCANNERS = swig_scanner) 242 243# Platform-specific configuration. Note again that we assume that all 244# builds under a given build root run on the same host platform. 245conf = Configure(env, | 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 --- 43 unchanged lines hidden (view full) --- 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, |
246 conf_dir = os.path.join(build_root, '.scons_config'), 247 log_file = os.path.join(build_root, 'scons_config.log')) | 247 conf_dir = joinpath(build_root, '.scons_config'), 248 log_file = joinpath(build_root, 'scons_config.log')) |
248 249# Find Python include and library directories for embedding the 250# interpreter. For consistency, we will use the same Python 251# installation used to run scons (and thus this script). If you want 252# to link in an alternate version, see above for instructions on how 253# to invoke scons with a different copy of the Python interpreter. 254 255# Get brief Python version name (e.g., "python2.4") for locating 256# include & library files 257py_version_name = 'python' + sys.version[:3] 258 259# include path, e.g. /usr/local/include/python2.4 | 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 |
260py_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name) | 261py_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) |
261env.Append(CPPPATH = py_header_path) 262# verify that it works 263if not conf.CheckHeader('Python.h', '<>'): 264 print "Error: can't find Python.h header in", py_header_path 265 Exit(1) 266 267# add library path too if it's not in the default place 268py_lib_path = None 269if sys.exec_prefix != '/usr': | 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': |
270 py_lib_path = os.path.join(sys.exec_prefix, 'lib') | 271 py_lib_path = joinpath(sys.exec_prefix, 'lib') |
271elif sys.platform == 'cygwin': 272 # cygwin puts the .dll in /bin for some reason 273 py_lib_path = '/bin' 274if py_lib_path: 275 env.Append(LIBPATH = py_lib_path) 276 print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 277if not conf.CheckLib(py_version_name): 278 print "Error: can't find Python library", py_version_name --- 46 unchanged lines hidden (view full) --- 325 326# Define the universe of supported ISAs 327env['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 328 329# Define the universe of supported CPU models 330env['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 331 'O3CPU', 'OzoneCPU'] 332 | 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 --- 46 unchanged lines hidden (view full) --- 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 |
333if os.path.isdir(os.path.join(SRCDIR, 'src/encumbered/cpu/full')): | 334if os.path.isdir(joinpath(SRCDIR, 'src/encumbered/cpu/full')): |
334 env['ALL_CPU_LIST'] += ['FullCPU'] 335 336# Sticky options get saved in the options file so they persist from 337# one invocation to the next (unless overridden, in which case the new 338# value becomes sticky). 339sticky_opts = Options(args=ARGUMENTS) 340sticky_opts.AddOptions( 341 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), --- 70 unchanged lines hidden (view full) --- 412config_action = Action(build_config_file, build_config_file_string) 413 414# The emitter munges the source & target node lists to reflect what 415# we're really doing. 416def config_emitter(target, source, env): 417 # extract option name from Builder arg 418 option = str(target[0]) 419 # True target is config header file | 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']), --- 70 unchanged lines hidden (view full) --- 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 |
420 target = os.path.join('config', option.lower() + '.hh') | 421 target = joinpath('config', option.lower() + '.hh') |
421 val = env[option] 422 if isinstance(val, bool): 423 # Force value to 0/1 424 val = int(val) 425 elif isinstance(val, str): 426 val = '"' + val + '"' 427 428 # Sources are option name & value (packaged in SCons Value nodes) --- 32 unchanged lines hidden (view full) --- 461# base help text 462help_text = ''' 463Usage: scons [scons options] [build options] [target(s)] 464 465''' 466 467# libelf build is shared across all configs in the build root. 468env.SConscript('ext/libelf/SConscript', | 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) --- 32 unchanged lines hidden (view full) --- 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', |
469 build_dir = os.path.join(build_root, 'libelf'), | 470 build_dir = joinpath(build_root, 'libelf'), |
470 exports = 'env') 471 472################################################### 473# 474# This function is used to set up a directory with switching headers 475# 476################################################### 477 --- 48 unchanged lines hidden (view full) --- 526 # Make a copy of the build-root environment to use for this config. 527 env = base_env.Copy() 528 529 # Set env options according to the build directory config. 530 sticky_opts.files = [] 531 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 532 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 533 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. | 471 exports = 'env') 472 473################################################### 474# 475# This function is used to set up a directory with switching headers 476# 477################################################### 478 --- 48 unchanged lines hidden (view full) --- 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. |
534 current_opts_file = os.path.join(build_root, 'options', build_dir) | 535 current_opts_file = joinpath(build_root, 'options', build_dir) |
535 if os.path.isfile(current_opts_file): 536 sticky_opts.files.append(current_opts_file) 537 print "Using saved options file %s" % current_opts_file 538 else: 539 # Build dir-specific options file doesn't exist. 540 541 # Make sure the directory is there so we can create it later 542 opt_dir = os.path.dirname(current_opts_file) 543 if not os.path.isdir(opt_dir): 544 os.mkdir(opt_dir) 545 546 # Get default build options from source tree. Options are 547 # normally determined by name of $BUILD_DIR, but can be 548 # overriden by 'default=' arg on command line. | 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. |
549 default_opts_file = os.path.join('build_opts', 550 ARGUMENTS.get('default', build_dir)) | 550 default_opts_file = joinpath('build_opts', 551 ARGUMENTS.get('default', build_dir)) |
551 if os.path.isfile(default_opts_file): 552 sticky_opts.files.append(default_opts_file) 553 print "Options file %s not found,\n using defaults in %s" \ 554 % (current_opts_file, default_opts_file) 555 else: 556 print "Error: cannot find options file %s or %s" \ 557 % (current_opts_file, default_opts_file) 558 Exit(1) --- 47 unchanged lines hidden (view full) --- 606 # to the configured options. It returns a list of environments, 607 # one for each variant build (debug, opt, etc.) 608 envList = SConscript('src/SConscript', build_dir = build_path, 609 exports = 'env') 610 611 # Set up the regression tests for each build. 612 for e in envList: 613 SConscript('tests/SConscript', | 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) --- 47 unchanged lines hidden (view full) --- 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', |
614 build_dir = os.path.join(build_path, 'tests', e.Label), | 615 build_dir = joinpath(build_path, 'tests', e.Label), |
615 exports = { 'env' : e }, duplicate = False) 616 617Help(help_text) 618 619 620################################################### 621# 622# Let SCons do its thing. At this point SCons will use the defined 623# build environments to build the requested targets. 624# 625################################################### 626 | 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 |