1# -*- mode:python -*- 2 3# Copyright (c) 2009 The Hewlett-Packard Development Company 4# Copyright (c) 2004-2005 The Regents of The University of Michigan 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are 9# met: redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer; 11# redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution; 14# neither the name of the copyright holders nor the names of its 15# contributors may be used to endorse or promote products derived from 16# this software without specific prior written permission. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29# 30# Authors: Steve Reinhardt 31# Nathan Binkert 32 33################################################### 34# 35# SCons top-level build description (SConstruct) file. 36# 37# While in this directory ('m5'), just type 'scons' to build the default 38# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 39# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 40# the optimized full-system version). 41# 42# You can build M5 in a different directory as long as there is a 43# 'build/<CONFIG>' somewhere along the target path. The build system 44# expects that all configs under the same build directory are being 45# built for the same host system. 46# 47# Examples: 48# 49# The following two commands are equivalent. The '-u' option tells 50# scons to search up the directory tree for this SConstruct file. 51# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 52# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 53# 54# The following two commands are equivalent and demonstrate building 55# in a directory outside of the source tree. The '-C' option tells 56# scons to chdir to the specified directory to find this SConstruct 57# file. 58# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 59# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 60# 61# You can use 'scons -H' to print scons options. If you're in this 62# 'm5' directory (or use -u or -C to tell scons where to find this 63# file), you can use 'scons -h' to print all the M5-specific build 64# options as well. 65# 66################################################### 67 68# Check for recent-enough Python and SCons versions. 69try: 70 # Really old versions of scons only take two options for the 71 # function, so check once without the revision and once with the 72 # revision, the first instance will fail for stuff other than 73 # 0.98, and the second will fail for 0.98.0 74 EnsureSConsVersion(0, 98) 75 EnsureSConsVersion(0, 98, 1) 76except SystemExit, e: 77 print """ 78For more details, see: 79 http://m5sim.org/wiki/index.php/Compiling_M5 80""" 81 raise 82 83# We ensure the python version early because we have stuff that 84# requires python 2.4 85try: 86 EnsurePythonVersion(2, 4) 87except SystemExit, e: 88 print """ 89You can use a non-default installation of the Python interpreter by 90either (1) rearranging your PATH so that scons finds the non-default 91'python' first or (2) explicitly invoking an alternative interpreter 92on the scons script. 93 94For more details, see: 95 http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 96""" 97 raise 98 99# Global Python includes 100import os 101import re 102import subprocess 103import sys 104 105from os import mkdir, environ 106from os.path import abspath, basename, dirname, expanduser, normpath 107from os.path import exists, isdir, isfile 108from os.path import join as joinpath, split as splitpath 109 110# SCons includes 111import SCons 112import SCons.Node 113
| 1# -*- mode:python -*- 2 3# Copyright (c) 2009 The Hewlett-Packard Development Company 4# Copyright (c) 2004-2005 The Regents of The University of Michigan 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are 9# met: redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer; 11# redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution; 14# neither the name of the copyright holders nor the names of its 15# contributors may be used to endorse or promote products derived from 16# this software without specific prior written permission. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29# 30# Authors: Steve Reinhardt 31# Nathan Binkert 32 33################################################### 34# 35# SCons top-level build description (SConstruct) file. 36# 37# While in this directory ('m5'), just type 'scons' to build the default 38# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 39# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 40# the optimized full-system version). 41# 42# You can build M5 in a different directory as long as there is a 43# 'build/<CONFIG>' somewhere along the target path. The build system 44# expects that all configs under the same build directory are being 45# built for the same host system. 46# 47# Examples: 48# 49# The following two commands are equivalent. The '-u' option tells 50# scons to search up the directory tree for this SConstruct file. 51# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 52# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 53# 54# The following two commands are equivalent and demonstrate building 55# in a directory outside of the source tree. The '-C' option tells 56# scons to chdir to the specified directory to find this SConstruct 57# file. 58# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 59# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 60# 61# You can use 'scons -H' to print scons options. If you're in this 62# 'm5' directory (or use -u or -C to tell scons where to find this 63# file), you can use 'scons -h' to print all the M5-specific build 64# options as well. 65# 66################################################### 67 68# Check for recent-enough Python and SCons versions. 69try: 70 # Really old versions of scons only take two options for the 71 # function, so check once without the revision and once with the 72 # revision, the first instance will fail for stuff other than 73 # 0.98, and the second will fail for 0.98.0 74 EnsureSConsVersion(0, 98) 75 EnsureSConsVersion(0, 98, 1) 76except SystemExit, e: 77 print """ 78For more details, see: 79 http://m5sim.org/wiki/index.php/Compiling_M5 80""" 81 raise 82 83# We ensure the python version early because we have stuff that 84# requires python 2.4 85try: 86 EnsurePythonVersion(2, 4) 87except SystemExit, e: 88 print """ 89You can use a non-default installation of the Python interpreter by 90either (1) rearranging your PATH so that scons finds the non-default 91'python' first or (2) explicitly invoking an alternative interpreter 92on the scons script. 93 94For more details, see: 95 http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 96""" 97 raise 98 99# Global Python includes 100import os 101import re 102import subprocess 103import sys 104 105from os import mkdir, environ 106from os.path import abspath, basename, dirname, expanduser, normpath 107from os.path import exists, isdir, isfile 108from os.path import join as joinpath, split as splitpath 109 110# SCons includes 111import SCons 112import SCons.Node 113
|
136######################################################################## 137# 138# Mercurial Stuff. 139# 140# If the M5 directory is a mercurial repository, we should do some 141# extra things. 142# 143######################################################################## 144 145hgdir = main.root.Dir(".hg") 146 147mercurial_style_message = """ 148You're missing the M5 style hook. 149Please install the hook so we can ensure that all code fits a common style. 150 151All you'd need to do is add the following lines to your repository .hg/hgrc 152or your personal .hgrc 153---------------- 154 155[extensions] 156style = %s/util/style.py 157 158[hooks] 159pretxncommit.style = python:style.check_whitespace 160""" % (main.root) 161 162mercurial_bin_not_found = """ 163Mercurial binary cannot be found, unfortunately this means that we 164cannot easily determine the version of M5 that you are running and 165this makes error messages more difficult to collect. Please consider 166installing mercurial if you choose to post an error message 167""" 168 169mercurial_lib_not_found = """ 170Mercurial libraries cannot be found, ignoring style hook 171If you are actually a M5 developer, please fix this and 172run the style hook. It is important. 173""" 174 175hg_info = "Unknown" 176if hgdir.exists(): 177 # 1) Grab repository revision if we know it. 178 cmd = "hg id -n -i -t -b" 179 try: 180 hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 181 except OSError: 182 print mercurial_bin_not_found 183 184 # 2) Ensure that the style hook is in place. 185 try: 186 ui = None 187 if ARGUMENTS.get('IGNORE_STYLE') != 'True': 188 from mercurial import ui 189 ui = ui.ui() 190 except ImportError: 191 print mercurial_lib_not_found 192 193 if ui is not None: 194 ui.readconfig(hgdir.File('hgrc').abspath) 195 style_hook = ui.config('hooks', 'pretxncommit.style', None) 196 197 if not style_hook: 198 print mercurial_style_message 199 sys.exit(1) 200else: 201 print ".hg directory not found" 202 203main['HG_INFO'] = hg_info 204 205################################################### 206# 207# Figure out which configurations to set up based on the path(s) of 208# the target(s). 209# 210################################################### 211 212# Find default configuration & binary. 213Default(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 214 215# helper function: find last occurrence of element in list 216def rfind(l, elt, offs = -1): 217 for i in range(len(l)+offs, 0, -1): 218 if l[i] == elt: 219 return i 220 raise ValueError, "element not found" 221 222# Each target must have 'build' in the interior of the path; the 223# directory below this will determine the build parameters. For 224# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 225# recognize that ALPHA_SE specifies the configuration because it 226# follow 'build' in the bulid path. 227 228# Generate absolute paths to targets so we can see where the build dir is 229if COMMAND_LINE_TARGETS: 230 # Ask SCons which directory it was invoked from 231 launch_dir = GetLaunchDir() 232 # Make targets relative to invocation directory 233 abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 234 COMMAND_LINE_TARGETS] 235else: 236 # Default targets are relative to root of tree 237 abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 238 DEFAULT_TARGETS] 239 240 241# Generate a list of the unique build roots and configs that the 242# collected targets reference. 243variant_paths = [] 244build_root = None 245for t in abs_targets: 246 path_dirs = t.split('/') 247 try: 248 build_top = rfind(path_dirs, 'build', -2) 249 except: 250 print "Error: no non-leaf 'build' dir found on target path", t 251 Exit(1) 252 this_build_root = joinpath('/',*path_dirs[:build_top+1]) 253 if not build_root: 254 build_root = this_build_root 255 else: 256 if this_build_root != build_root: 257 print "Error: build targets not under same build root\n"\ 258 " %s\n %s" % (build_root, this_build_root) 259 Exit(1) 260 variant_path = joinpath('/',*path_dirs[:build_top+2]) 261 if variant_path not in variant_paths: 262 variant_paths.append(variant_path) 263 264# Make sure build_root exists (might not if this is the first build there) 265if not isdir(build_root): 266 mkdir(build_root) 267 268Export('main') 269 270main.SConsignFile(joinpath(build_root, "sconsign")) 271 272# Default duplicate option is to use hard links, but this messes up 273# when you use emacs to edit a file in the target dir, as emacs moves 274# file to file~ then copies to file, breaking the link. Symbolic 275# (soft) links work better. 276main.SetOption('duplicate', 'soft-copy') 277 278# 279# Set up global sticky variables... these are common to an entire build 280# tree (not specific to a particular build like ALPHA_SE) 281# 282 283# Variable validators & converters for global sticky variables 284def PathListMakeAbsolute(val): 285 if not val: 286 return val 287 f = lambda p: abspath(expanduser(p)) 288 return ':'.join(map(f, val.split(':'))) 289 290def PathListAllExist(key, val, env): 291 if not val: 292 return 293 paths = val.split(':') 294 for path in paths: 295 if not isdir(path): 296 raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 297 298global_sticky_vars_file = joinpath(build_root, 'variables.global') 299 300global_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 301 302global_sticky_vars.AddVariables( 303 ('CC', 'C compiler', environ.get('CC', main['CC'])), 304 ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 305 ('BATCH', 'Use batch pool for build and tests', False), 306 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 307 ('EXTRAS', 'Add Extra directories to the compilation', '', 308 PathListAllExist, PathListMakeAbsolute), 309 BoolVariable('RUBY', 'Build with Ruby', False), 310 ) 311 312# base help text 313help_text = ''' 314Usage: scons [scons options] [build options] [target(s)] 315 316Global sticky options: 317''' 318 319help_text += global_sticky_vars.GenerateHelpText(main) 320 321# Update main environment with values from ARGUMENTS & global_sticky_vars_file 322global_sticky_vars.Update(main) 323 324# Save sticky variable settings back to current variables file 325global_sticky_vars.Save(global_sticky_vars_file, main) 326 327# Parse EXTRAS variable to build list of all directories where we're 328# look for sources etc. This list is exported as base_dir_list. 329base_dir = main.srcdir.abspath 330if main['EXTRAS']: 331 extras_dir_list = main['EXTRAS'].split(':') 332else: 333 extras_dir_list = [] 334 335Export('base_dir') 336Export('extras_dir_list') 337 338# the ext directory should be on the #includes path 339main.Append(CPPPATH=[Dir('ext')]) 340
| 144######################################################################## 145# 146# Mercurial Stuff. 147# 148# If the M5 directory is a mercurial repository, we should do some 149# extra things. 150# 151######################################################################## 152 153hgdir = main.root.Dir(".hg") 154 155mercurial_style_message = """ 156You're missing the M5 style hook. 157Please install the hook so we can ensure that all code fits a common style. 158 159All you'd need to do is add the following lines to your repository .hg/hgrc 160or your personal .hgrc 161---------------- 162 163[extensions] 164style = %s/util/style.py 165 166[hooks] 167pretxncommit.style = python:style.check_whitespace 168""" % (main.root) 169 170mercurial_bin_not_found = """ 171Mercurial binary cannot be found, unfortunately this means that we 172cannot easily determine the version of M5 that you are running and 173this makes error messages more difficult to collect. Please consider 174installing mercurial if you choose to post an error message 175""" 176 177mercurial_lib_not_found = """ 178Mercurial libraries cannot be found, ignoring style hook 179If you are actually a M5 developer, please fix this and 180run the style hook. It is important. 181""" 182 183hg_info = "Unknown" 184if hgdir.exists(): 185 # 1) Grab repository revision if we know it. 186 cmd = "hg id -n -i -t -b" 187 try: 188 hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 189 except OSError: 190 print mercurial_bin_not_found 191 192 # 2) Ensure that the style hook is in place. 193 try: 194 ui = None 195 if ARGUMENTS.get('IGNORE_STYLE') != 'True': 196 from mercurial import ui 197 ui = ui.ui() 198 except ImportError: 199 print mercurial_lib_not_found 200 201 if ui is not None: 202 ui.readconfig(hgdir.File('hgrc').abspath) 203 style_hook = ui.config('hooks', 'pretxncommit.style', None) 204 205 if not style_hook: 206 print mercurial_style_message 207 sys.exit(1) 208else: 209 print ".hg directory not found" 210 211main['HG_INFO'] = hg_info 212 213################################################### 214# 215# Figure out which configurations to set up based on the path(s) of 216# the target(s). 217# 218################################################### 219 220# Find default configuration & binary. 221Default(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 222 223# helper function: find last occurrence of element in list 224def rfind(l, elt, offs = -1): 225 for i in range(len(l)+offs, 0, -1): 226 if l[i] == elt: 227 return i 228 raise ValueError, "element not found" 229 230# Each target must have 'build' in the interior of the path; the 231# directory below this will determine the build parameters. For 232# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 233# recognize that ALPHA_SE specifies the configuration because it 234# follow 'build' in the bulid path. 235 236# Generate absolute paths to targets so we can see where the build dir is 237if COMMAND_LINE_TARGETS: 238 # Ask SCons which directory it was invoked from 239 launch_dir = GetLaunchDir() 240 # Make targets relative to invocation directory 241 abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 242 COMMAND_LINE_TARGETS] 243else: 244 # Default targets are relative to root of tree 245 abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 246 DEFAULT_TARGETS] 247 248 249# Generate a list of the unique build roots and configs that the 250# collected targets reference. 251variant_paths = [] 252build_root = None 253for t in abs_targets: 254 path_dirs = t.split('/') 255 try: 256 build_top = rfind(path_dirs, 'build', -2) 257 except: 258 print "Error: no non-leaf 'build' dir found on target path", t 259 Exit(1) 260 this_build_root = joinpath('/',*path_dirs[:build_top+1]) 261 if not build_root: 262 build_root = this_build_root 263 else: 264 if this_build_root != build_root: 265 print "Error: build targets not under same build root\n"\ 266 " %s\n %s" % (build_root, this_build_root) 267 Exit(1) 268 variant_path = joinpath('/',*path_dirs[:build_top+2]) 269 if variant_path not in variant_paths: 270 variant_paths.append(variant_path) 271 272# Make sure build_root exists (might not if this is the first build there) 273if not isdir(build_root): 274 mkdir(build_root) 275 276Export('main') 277 278main.SConsignFile(joinpath(build_root, "sconsign")) 279 280# Default duplicate option is to use hard links, but this messes up 281# when you use emacs to edit a file in the target dir, as emacs moves 282# file to file~ then copies to file, breaking the link. Symbolic 283# (soft) links work better. 284main.SetOption('duplicate', 'soft-copy') 285 286# 287# Set up global sticky variables... these are common to an entire build 288# tree (not specific to a particular build like ALPHA_SE) 289# 290 291# Variable validators & converters for global sticky variables 292def PathListMakeAbsolute(val): 293 if not val: 294 return val 295 f = lambda p: abspath(expanduser(p)) 296 return ':'.join(map(f, val.split(':'))) 297 298def PathListAllExist(key, val, env): 299 if not val: 300 return 301 paths = val.split(':') 302 for path in paths: 303 if not isdir(path): 304 raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 305 306global_sticky_vars_file = joinpath(build_root, 'variables.global') 307 308global_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 309 310global_sticky_vars.AddVariables( 311 ('CC', 'C compiler', environ.get('CC', main['CC'])), 312 ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 313 ('BATCH', 'Use batch pool for build and tests', False), 314 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 315 ('EXTRAS', 'Add Extra directories to the compilation', '', 316 PathListAllExist, PathListMakeAbsolute), 317 BoolVariable('RUBY', 'Build with Ruby', False), 318 ) 319 320# base help text 321help_text = ''' 322Usage: scons [scons options] [build options] [target(s)] 323 324Global sticky options: 325''' 326 327help_text += global_sticky_vars.GenerateHelpText(main) 328 329# Update main environment with values from ARGUMENTS & global_sticky_vars_file 330global_sticky_vars.Update(main) 331 332# Save sticky variable settings back to current variables file 333global_sticky_vars.Save(global_sticky_vars_file, main) 334 335# Parse EXTRAS variable to build list of all directories where we're 336# look for sources etc. This list is exported as base_dir_list. 337base_dir = main.srcdir.abspath 338if main['EXTRAS']: 339 extras_dir_list = main['EXTRAS'].split(':') 340else: 341 extras_dir_list = [] 342 343Export('base_dir') 344Export('extras_dir_list') 345 346# the ext directory should be on the #includes path 347main.Append(CPPPATH=[Dir('ext')]) 348
|
390 391# Check for SWIG 392if not main.has_key('SWIG'): 393 print 'Error: SWIG utility not found.' 394 print ' Please install (see http://www.swig.org) and retry.' 395 Exit(1) 396 397# Check for appropriate SWIG version 398swig_version = readCommand(('swig', '-version'), exception='').split() 399# First 3 words should be "SWIG Version x.y.z" 400if len(swig_version) < 3 or \ 401 swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 402 print 'Error determining SWIG version.' 403 Exit(1) 404 405min_swig_version = '1.3.28' 406if compareVersions(swig_version[2], min_swig_version) < 0: 407 print 'Error: SWIG version', min_swig_version, 'or newer required.' 408 print ' Installed version:', swig_version[2] 409 Exit(1) 410 411# Set up SWIG flags & scanner 412swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 413main.Append(SWIGFLAGS=swig_flags) 414 415# filter out all existing swig scanners, they mess up the dependency 416# stuff for some reason 417scanners = [] 418for scanner in main['SCANNERS']: 419 skeys = scanner.skeys 420 if skeys == '.i': 421 continue 422 423 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 424 continue 425 426 scanners.append(scanner) 427 428# add the new swig scanner that we like better 429from SCons.Scanner import ClassicCPP as CPPScanner 430swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 431scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 432 433# replace the scanners list that has what we want 434main['SCANNERS'] = scanners 435 436# Add a custom Check function to the Configure context so that we can 437# figure out if the compiler adds leading underscores to global 438# variables. This is needed for the autogenerated asm files that we 439# use for embedding the python code. 440def CheckLeading(context): 441 context.Message("Checking for leading underscore in global variables...") 442 # 1) Define a global variable called x from asm so the C compiler 443 # won't change the symbol at all. 444 # 2) Declare that variable. 445 # 3) Use the variable 446 # 447 # If the compiler prepends an underscore, this will successfully 448 # link because the external symbol 'x' will be called '_x' which 449 # was defined by the asm statement. If the compiler does not 450 # prepend an underscore, this will not successfully link because 451 # '_x' will have been defined by assembly, while the C portion of 452 # the code will be trying to use 'x' 453 ret = context.TryLink(''' 454 asm(".globl _x; _x: .byte 0"); 455 extern int x; 456 int main() { return x; } 457 ''', extension=".c") 458 context.env.Append(LEADING_UNDERSCORE=ret) 459 context.Result(ret) 460 return ret 461 462# Platform-specific configuration. Note again that we assume that all 463# builds under a given build root run on the same host platform. 464conf = Configure(main, 465 conf_dir = joinpath(build_root, '.scons_config'), 466 log_file = joinpath(build_root, 'scons_config.log'), 467 custom_tests = { 'CheckLeading' : CheckLeading }) 468 469# Check for leading underscores. Don't really need to worry either 470# way so don't need to check the return code. 471conf.CheckLeading() 472 473# Check if we should compile a 64 bit binary on Mac OS X/Darwin 474try: 475 import platform 476 uname = platform.uname() 477 if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 478 if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 479 main.Append(CCFLAGS='-arch x86_64') 480 main.Append(CFLAGS='-arch x86_64') 481 main.Append(LINKFLAGS='-arch x86_64') 482 main.Append(ASFLAGS='-arch x86_64') 483except: 484 pass 485 486# Recent versions of scons substitute a "Null" object for Configure() 487# when configuration isn't necessary, e.g., if the "--help" option is 488# present. Unfortuantely this Null object always returns false, 489# breaking all our configuration checks. We replace it with our own 490# more optimistic null object that returns True instead. 491if not conf: 492 def NullCheck(*args, **kwargs): 493 return True 494 495 class NullConf: 496 def __init__(self, env): 497 self.env = env 498 def Finish(self): 499 return self.env 500 def __getattr__(self, mname): 501 return NullCheck 502 503 conf = NullConf(main) 504 505# Find Python include and library directories for embedding the 506# interpreter. For consistency, we will use the same Python 507# installation used to run scons (and thus this script). If you want 508# to link in an alternate version, see above for instructions on how 509# to invoke scons with a different copy of the Python interpreter. 510from distutils import sysconfig 511 512py_getvar = sysconfig.get_config_var 513 514py_version = 'python' + py_getvar('VERSION') 515 516py_general_include = sysconfig.get_python_inc() 517py_platform_include = sysconfig.get_python_inc(plat_specific=True) 518py_includes = [ py_general_include ] 519if py_platform_include != py_general_include: 520 py_includes.append(py_platform_include) 521 522py_lib_path = [ py_getvar('LIBDIR') ] 523# add the prefix/lib/pythonX.Y/config dir, but only if there is no 524# shared library in prefix/lib/. 525if not py_getvar('Py_ENABLE_SHARED'): 526 py_lib_path.append(py_getvar('LIBPL')) 527 528py_libs = [] 529for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 530 assert lib.startswith('-l') 531 lib = lib[2:] 532 if lib not in py_libs: 533 py_libs.append(lib) 534py_libs.append(py_version) 535 536main.Append(CPPPATH=py_includes) 537main.Append(LIBPATH=py_lib_path) 538 539# verify that this stuff works 540if not conf.CheckHeader('Python.h', '<>'): 541 print "Error: can't find Python.h header in", py_includes 542 Exit(1) 543 544for lib in py_libs: 545 if not conf.CheckLib(lib): 546 print "Error: can't find library %s required by python" % lib 547 Exit(1) 548 549# On Solaris you need to use libsocket for socket ops 550if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 551 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 552 print "Can't find library with socket calls (e.g. accept())" 553 Exit(1) 554 555# Check for zlib. If the check passes, libz will be automatically 556# added to the LIBS environment variable. 557if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 558 print 'Error: did not find needed zlib compression library '\ 559 'and/or zlib.h header file.' 560 print ' Please install zlib and try again.' 561 Exit(1) 562 563# Check for <fenv.h> (C99 FP environment control) 564have_fenv = conf.CheckHeader('fenv.h', '<>') 565if not have_fenv: 566 print "Warning: Header file <fenv.h> not found." 567 print " This host has no IEEE FP rounding mode control." 568 569###################################################################### 570# 571# Check for mysql. 572# 573mysql_config = WhereIs('mysql_config') 574have_mysql = bool(mysql_config) 575 576# Check MySQL version. 577if have_mysql: 578 mysql_version = readCommand(mysql_config + ' --version') 579 min_mysql_version = '4.1' 580 if compareVersions(mysql_version, min_mysql_version) < 0: 581 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 582 print ' Version', mysql_version, 'detected.' 583 have_mysql = False 584 585# Set up mysql_config commands. 586if have_mysql: 587 mysql_config_include = mysql_config + ' --include' 588 if os.system(mysql_config_include + ' > /dev/null') != 0: 589 # older mysql_config versions don't support --include, use 590 # --cflags instead 591 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 592 # This seems to work in all versions 593 mysql_config_libs = mysql_config + ' --libs' 594 595###################################################################### 596# 597# Finish the configuration 598# 599main = conf.Finish() 600 601###################################################################### 602# 603# Collect all non-global variables 604# 605 606# Define the universe of supported ISAs 607all_isa_list = [ ] 608Export('all_isa_list') 609 610# Define the universe of supported CPU models 611all_cpu_list = [ ] 612default_cpus = [ ] 613Export('all_cpu_list', 'default_cpus') 614 615# Sticky variables get saved in the variables file so they persist from 616# one invocation to the next (unless overridden, in which case the new 617# value becomes sticky). 618sticky_vars = Variables(args=ARGUMENTS) 619Export('sticky_vars') 620 621# Sticky variables that should be exported 622export_vars = [] 623Export('export_vars') 624 625# Non-sticky variables only apply to the current build. 626nonsticky_vars = Variables(args=ARGUMENTS) 627Export('nonsticky_vars') 628 629# Walk the tree and execute all SConsopts scripts that wil add to the 630# above variables 631for bdir in [ base_dir ] + extras_dir_list: 632 for root, dirs, files in os.walk(bdir): 633 if 'SConsopts' in files: 634 print "Reading", joinpath(root, 'SConsopts') 635 SConscript(joinpath(root, 'SConsopts')) 636 637all_isa_list.sort() 638all_cpu_list.sort() 639default_cpus.sort() 640 641sticky_vars.AddVariables( 642 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 643 BoolVariable('FULL_SYSTEM', 'Full-system support', False), 644 ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 645 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 646 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 647 False), 648 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 649 False), 650 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 651 False), 652 BoolVariable('SS_COMPATIBLE_FP', 653 'Make floating-point results compatible with SimpleScalar', 654 False), 655 BoolVariable('USE_SSE2', 656 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 657 False), 658 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 659 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 660 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 661 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 662 ) 663 664nonsticky_vars.AddVariables( 665 BoolVariable('update_ref', 'Update test reference outputs', False) 666 ) 667 668# These variables get exported to #defines in config/*.hh (see src/SConscript). 669export_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 670 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 671 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 672 673################################################### 674# 675# Define a SCons builder for configuration flag headers. 676# 677################################################### 678 679# This function generates a config header file that #defines the 680# variable symbol to the current variable setting (0 or 1). The source 681# operands are the name of the variable and a Value node containing the 682# value of the variable. 683def build_config_file(target, source, env): 684 (variable, value) = [s.get_contents() for s in source] 685 f = file(str(target[0]), 'w') 686 print >> f, '#define', variable, value 687 f.close() 688 return None 689 690# Generate the message to be printed when building the config file. 691def build_config_file_string(target, source, env): 692 (variable, value) = [s.get_contents() for s in source] 693 return "Defining %s as %s in %s." % (variable, value, target[0]) 694 695# Combine the two functions into a scons Action object. 696config_action = Action(build_config_file, build_config_file_string) 697 698# The emitter munges the source & target node lists to reflect what 699# we're really doing. 700def config_emitter(target, source, env): 701 # extract variable name from Builder arg 702 variable = str(target[0]) 703 # True target is config header file 704 target = joinpath('config', variable.lower() + '.hh') 705 val = env[variable] 706 if isinstance(val, bool): 707 # Force value to 0/1 708 val = int(val) 709 elif isinstance(val, str): 710 val = '"' + val + '"' 711 712 # Sources are variable name & value (packaged in SCons Value nodes) 713 return ([target], [Value(variable), Value(val)]) 714 715config_builder = Builder(emitter = config_emitter, action = config_action) 716 717main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 718 719# libelf build is shared across all configs in the build root. 720main.SConscript('ext/libelf/SConscript', 721 variant_dir = joinpath(build_root, 'libelf')) 722 723# gzstream build is shared across all configs in the build root. 724main.SConscript('ext/gzstream/SConscript', 725 variant_dir = joinpath(build_root, 'gzstream')) 726 727################################################### 728# 729# This function is used to set up a directory with switching headers 730# 731################################################### 732 733main['ALL_ISA_LIST'] = all_isa_list 734def make_switching_dir(dname, switch_headers, env): 735 # Generate the header. target[0] is the full path of the output 736 # header to generate. 'source' is a dummy variable, since we get the 737 # list of ISAs from env['ALL_ISA_LIST']. 738 def gen_switch_hdr(target, source, env): 739 fname = str(target[0]) 740 bname = basename(fname) 741 f = open(fname, 'w') 742 f.write('#include "arch/isa_specific.hh"\n') 743 cond = '#if' 744 for isa in all_isa_list: 745 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 746 % (cond, isa.upper(), dname, isa, bname)) 747 cond = '#elif' 748 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 749 f.close() 750 return 0 751 752 # String to print when generating header 753 def gen_switch_hdr_string(target, source, env): 754 return "Generating switch header " + str(target[0]) 755 756 # Build SCons Action object. 'varlist' specifies env vars that this 757 # action depends on; when env['ALL_ISA_LIST'] changes these actions 758 # should get re-executed. 759 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 760 varlist=['ALL_ISA_LIST']) 761 762 # Instantiate actions for each header 763 for hdr in switch_headers: 764 env.Command(hdr, [], switch_hdr_action) 765Export('make_switching_dir') 766 767################################################### 768# 769# Define build environments for selected configurations. 770# 771################################################### 772 773for variant_path in variant_paths: 774 print "Building in", variant_path 775 776 # Make a copy of the build-root environment to use for this config. 777 env = main.Clone() 778 env['BUILDDIR'] = variant_path 779 780 # variant_dir is the tail component of build path, and is used to 781 # determine the build parameters (e.g., 'ALPHA_SE') 782 (build_root, variant_dir) = splitpath(variant_path) 783 784 # Set env variables according to the build directory config. 785 sticky_vars.files = [] 786 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 787 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 788 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 789 current_vars_file = joinpath(build_root, 'variables', variant_dir) 790 if isfile(current_vars_file): 791 sticky_vars.files.append(current_vars_file) 792 print "Using saved variables file %s" % current_vars_file 793 else: 794 # Build dir-specific variables file doesn't exist. 795 796 # Make sure the directory is there so we can create it later 797 opt_dir = dirname(current_vars_file) 798 if not isdir(opt_dir): 799 mkdir(opt_dir) 800 801 # Get default build variables from source tree. Variables are 802 # normally determined by name of $VARIANT_DIR, but can be 803 # overriden by 'default=' arg on command line. 804 default_vars_file = joinpath('build_opts', 805 ARGUMENTS.get('default', variant_dir)) 806 if isfile(default_vars_file): 807 sticky_vars.files.append(default_vars_file) 808 print "Variables file %s not found,\n using defaults in %s" \ 809 % (current_vars_file, default_vars_file) 810 else: 811 print "Error: cannot find variables file %s or %s" \ 812 % (current_vars_file, default_vars_file) 813 Exit(1) 814 815 # Apply current variable settings to env 816 sticky_vars.Update(env) 817 nonsticky_vars.Update(env) 818 819 help_text += "\nSticky variables for %s:\n" % variant_dir \ 820 + sticky_vars.GenerateHelpText(env) \ 821 + "\nNon-sticky variables for %s:\n" % variant_dir \ 822 + nonsticky_vars.GenerateHelpText(env) 823 824 # Process variable settings. 825 826 if not have_fenv and env['USE_FENV']: 827 print "Warning: <fenv.h> not available; " \ 828 "forcing USE_FENV to False in", variant_dir + "." 829 env['USE_FENV'] = False 830 831 if not env['USE_FENV']: 832 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 833 print " FP results may deviate slightly from other platforms." 834 835 if env['EFENCE']: 836 env.Append(LIBS=['efence']) 837 838 if env['USE_MYSQL']: 839 if not have_mysql: 840 print "Warning: MySQL not available; " \ 841 "forcing USE_MYSQL to False in", variant_dir + "." 842 env['USE_MYSQL'] = False 843 else: 844 print "Compiling in", variant_dir, "with MySQL support." 845 env.ParseConfig(mysql_config_libs) 846 env.ParseConfig(mysql_config_include) 847 848 # Save sticky variable settings back to current variables file 849 sticky_vars.Save(current_vars_file, env) 850 851 if env['USE_SSE2']: 852 env.Append(CCFLAGS='-msse2') 853 854 # The src/SConscript file sets up the build rules in 'env' according 855 # to the configured variables. It returns a list of environments, 856 # one for each variant build (debug, opt, etc.) 857 envList = SConscript('src/SConscript', variant_dir = variant_path, 858 exports = 'env') 859 860 # Set up the regression tests for each build. 861 for e in envList: 862 SConscript('tests/SConscript', 863 variant_dir = joinpath(variant_path, 'tests', e.Label), 864 exports = { 'env' : e }, duplicate = False) 865 866Help(help_text)
| 395 396# Check for SWIG 397if not main.has_key('SWIG'): 398 print 'Error: SWIG utility not found.' 399 print ' Please install (see http://www.swig.org) and retry.' 400 Exit(1) 401 402# Check for appropriate SWIG version 403swig_version = readCommand(('swig', '-version'), exception='').split() 404# First 3 words should be "SWIG Version x.y.z" 405if len(swig_version) < 3 or \ 406 swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 407 print 'Error determining SWIG version.' 408 Exit(1) 409 410min_swig_version = '1.3.28' 411if compareVersions(swig_version[2], min_swig_version) < 0: 412 print 'Error: SWIG version', min_swig_version, 'or newer required.' 413 print ' Installed version:', swig_version[2] 414 Exit(1) 415 416# Set up SWIG flags & scanner 417swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 418main.Append(SWIGFLAGS=swig_flags) 419 420# filter out all existing swig scanners, they mess up the dependency 421# stuff for some reason 422scanners = [] 423for scanner in main['SCANNERS']: 424 skeys = scanner.skeys 425 if skeys == '.i': 426 continue 427 428 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 429 continue 430 431 scanners.append(scanner) 432 433# add the new swig scanner that we like better 434from SCons.Scanner import ClassicCPP as CPPScanner 435swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 436scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 437 438# replace the scanners list that has what we want 439main['SCANNERS'] = scanners 440 441# Add a custom Check function to the Configure context so that we can 442# figure out if the compiler adds leading underscores to global 443# variables. This is needed for the autogenerated asm files that we 444# use for embedding the python code. 445def CheckLeading(context): 446 context.Message("Checking for leading underscore in global variables...") 447 # 1) Define a global variable called x from asm so the C compiler 448 # won't change the symbol at all. 449 # 2) Declare that variable. 450 # 3) Use the variable 451 # 452 # If the compiler prepends an underscore, this will successfully 453 # link because the external symbol 'x' will be called '_x' which 454 # was defined by the asm statement. If the compiler does not 455 # prepend an underscore, this will not successfully link because 456 # '_x' will have been defined by assembly, while the C portion of 457 # the code will be trying to use 'x' 458 ret = context.TryLink(''' 459 asm(".globl _x; _x: .byte 0"); 460 extern int x; 461 int main() { return x; } 462 ''', extension=".c") 463 context.env.Append(LEADING_UNDERSCORE=ret) 464 context.Result(ret) 465 return ret 466 467# Platform-specific configuration. Note again that we assume that all 468# builds under a given build root run on the same host platform. 469conf = Configure(main, 470 conf_dir = joinpath(build_root, '.scons_config'), 471 log_file = joinpath(build_root, 'scons_config.log'), 472 custom_tests = { 'CheckLeading' : CheckLeading }) 473 474# Check for leading underscores. Don't really need to worry either 475# way so don't need to check the return code. 476conf.CheckLeading() 477 478# Check if we should compile a 64 bit binary on Mac OS X/Darwin 479try: 480 import platform 481 uname = platform.uname() 482 if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 483 if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 484 main.Append(CCFLAGS='-arch x86_64') 485 main.Append(CFLAGS='-arch x86_64') 486 main.Append(LINKFLAGS='-arch x86_64') 487 main.Append(ASFLAGS='-arch x86_64') 488except: 489 pass 490 491# Recent versions of scons substitute a "Null" object for Configure() 492# when configuration isn't necessary, e.g., if the "--help" option is 493# present. Unfortuantely this Null object always returns false, 494# breaking all our configuration checks. We replace it with our own 495# more optimistic null object that returns True instead. 496if not conf: 497 def NullCheck(*args, **kwargs): 498 return True 499 500 class NullConf: 501 def __init__(self, env): 502 self.env = env 503 def Finish(self): 504 return self.env 505 def __getattr__(self, mname): 506 return NullCheck 507 508 conf = NullConf(main) 509 510# Find Python include and library directories for embedding the 511# interpreter. For consistency, we will use the same Python 512# installation used to run scons (and thus this script). If you want 513# to link in an alternate version, see above for instructions on how 514# to invoke scons with a different copy of the Python interpreter. 515from distutils import sysconfig 516 517py_getvar = sysconfig.get_config_var 518 519py_version = 'python' + py_getvar('VERSION') 520 521py_general_include = sysconfig.get_python_inc() 522py_platform_include = sysconfig.get_python_inc(plat_specific=True) 523py_includes = [ py_general_include ] 524if py_platform_include != py_general_include: 525 py_includes.append(py_platform_include) 526 527py_lib_path = [ py_getvar('LIBDIR') ] 528# add the prefix/lib/pythonX.Y/config dir, but only if there is no 529# shared library in prefix/lib/. 530if not py_getvar('Py_ENABLE_SHARED'): 531 py_lib_path.append(py_getvar('LIBPL')) 532 533py_libs = [] 534for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 535 assert lib.startswith('-l') 536 lib = lib[2:] 537 if lib not in py_libs: 538 py_libs.append(lib) 539py_libs.append(py_version) 540 541main.Append(CPPPATH=py_includes) 542main.Append(LIBPATH=py_lib_path) 543 544# verify that this stuff works 545if not conf.CheckHeader('Python.h', '<>'): 546 print "Error: can't find Python.h header in", py_includes 547 Exit(1) 548 549for lib in py_libs: 550 if not conf.CheckLib(lib): 551 print "Error: can't find library %s required by python" % lib 552 Exit(1) 553 554# On Solaris you need to use libsocket for socket ops 555if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 556 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 557 print "Can't find library with socket calls (e.g. accept())" 558 Exit(1) 559 560# Check for zlib. If the check passes, libz will be automatically 561# added to the LIBS environment variable. 562if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 563 print 'Error: did not find needed zlib compression library '\ 564 'and/or zlib.h header file.' 565 print ' Please install zlib and try again.' 566 Exit(1) 567 568# Check for <fenv.h> (C99 FP environment control) 569have_fenv = conf.CheckHeader('fenv.h', '<>') 570if not have_fenv: 571 print "Warning: Header file <fenv.h> not found." 572 print " This host has no IEEE FP rounding mode control." 573 574###################################################################### 575# 576# Check for mysql. 577# 578mysql_config = WhereIs('mysql_config') 579have_mysql = bool(mysql_config) 580 581# Check MySQL version. 582if have_mysql: 583 mysql_version = readCommand(mysql_config + ' --version') 584 min_mysql_version = '4.1' 585 if compareVersions(mysql_version, min_mysql_version) < 0: 586 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 587 print ' Version', mysql_version, 'detected.' 588 have_mysql = False 589 590# Set up mysql_config commands. 591if have_mysql: 592 mysql_config_include = mysql_config + ' --include' 593 if os.system(mysql_config_include + ' > /dev/null') != 0: 594 # older mysql_config versions don't support --include, use 595 # --cflags instead 596 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 597 # This seems to work in all versions 598 mysql_config_libs = mysql_config + ' --libs' 599 600###################################################################### 601# 602# Finish the configuration 603# 604main = conf.Finish() 605 606###################################################################### 607# 608# Collect all non-global variables 609# 610 611# Define the universe of supported ISAs 612all_isa_list = [ ] 613Export('all_isa_list') 614 615# Define the universe of supported CPU models 616all_cpu_list = [ ] 617default_cpus = [ ] 618Export('all_cpu_list', 'default_cpus') 619 620# Sticky variables get saved in the variables file so they persist from 621# one invocation to the next (unless overridden, in which case the new 622# value becomes sticky). 623sticky_vars = Variables(args=ARGUMENTS) 624Export('sticky_vars') 625 626# Sticky variables that should be exported 627export_vars = [] 628Export('export_vars') 629 630# Non-sticky variables only apply to the current build. 631nonsticky_vars = Variables(args=ARGUMENTS) 632Export('nonsticky_vars') 633 634# Walk the tree and execute all SConsopts scripts that wil add to the 635# above variables 636for bdir in [ base_dir ] + extras_dir_list: 637 for root, dirs, files in os.walk(bdir): 638 if 'SConsopts' in files: 639 print "Reading", joinpath(root, 'SConsopts') 640 SConscript(joinpath(root, 'SConsopts')) 641 642all_isa_list.sort() 643all_cpu_list.sort() 644default_cpus.sort() 645 646sticky_vars.AddVariables( 647 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 648 BoolVariable('FULL_SYSTEM', 'Full-system support', False), 649 ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 650 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 651 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 652 False), 653 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 654 False), 655 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 656 False), 657 BoolVariable('SS_COMPATIBLE_FP', 658 'Make floating-point results compatible with SimpleScalar', 659 False), 660 BoolVariable('USE_SSE2', 661 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 662 False), 663 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 664 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 665 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 666 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 667 ) 668 669nonsticky_vars.AddVariables( 670 BoolVariable('update_ref', 'Update test reference outputs', False) 671 ) 672 673# These variables get exported to #defines in config/*.hh (see src/SConscript). 674export_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 675 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 676 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 677 678################################################### 679# 680# Define a SCons builder for configuration flag headers. 681# 682################################################### 683 684# This function generates a config header file that #defines the 685# variable symbol to the current variable setting (0 or 1). The source 686# operands are the name of the variable and a Value node containing the 687# value of the variable. 688def build_config_file(target, source, env): 689 (variable, value) = [s.get_contents() for s in source] 690 f = file(str(target[0]), 'w') 691 print >> f, '#define', variable, value 692 f.close() 693 return None 694 695# Generate the message to be printed when building the config file. 696def build_config_file_string(target, source, env): 697 (variable, value) = [s.get_contents() for s in source] 698 return "Defining %s as %s in %s." % (variable, value, target[0]) 699 700# Combine the two functions into a scons Action object. 701config_action = Action(build_config_file, build_config_file_string) 702 703# The emitter munges the source & target node lists to reflect what 704# we're really doing. 705def config_emitter(target, source, env): 706 # extract variable name from Builder arg 707 variable = str(target[0]) 708 # True target is config header file 709 target = joinpath('config', variable.lower() + '.hh') 710 val = env[variable] 711 if isinstance(val, bool): 712 # Force value to 0/1 713 val = int(val) 714 elif isinstance(val, str): 715 val = '"' + val + '"' 716 717 # Sources are variable name & value (packaged in SCons Value nodes) 718 return ([target], [Value(variable), Value(val)]) 719 720config_builder = Builder(emitter = config_emitter, action = config_action) 721 722main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 723 724# libelf build is shared across all configs in the build root. 725main.SConscript('ext/libelf/SConscript', 726 variant_dir = joinpath(build_root, 'libelf')) 727 728# gzstream build is shared across all configs in the build root. 729main.SConscript('ext/gzstream/SConscript', 730 variant_dir = joinpath(build_root, 'gzstream')) 731 732################################################### 733# 734# This function is used to set up a directory with switching headers 735# 736################################################### 737 738main['ALL_ISA_LIST'] = all_isa_list 739def make_switching_dir(dname, switch_headers, env): 740 # Generate the header. target[0] is the full path of the output 741 # header to generate. 'source' is a dummy variable, since we get the 742 # list of ISAs from env['ALL_ISA_LIST']. 743 def gen_switch_hdr(target, source, env): 744 fname = str(target[0]) 745 bname = basename(fname) 746 f = open(fname, 'w') 747 f.write('#include "arch/isa_specific.hh"\n') 748 cond = '#if' 749 for isa in all_isa_list: 750 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 751 % (cond, isa.upper(), dname, isa, bname)) 752 cond = '#elif' 753 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 754 f.close() 755 return 0 756 757 # String to print when generating header 758 def gen_switch_hdr_string(target, source, env): 759 return "Generating switch header " + str(target[0]) 760 761 # Build SCons Action object. 'varlist' specifies env vars that this 762 # action depends on; when env['ALL_ISA_LIST'] changes these actions 763 # should get re-executed. 764 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 765 varlist=['ALL_ISA_LIST']) 766 767 # Instantiate actions for each header 768 for hdr in switch_headers: 769 env.Command(hdr, [], switch_hdr_action) 770Export('make_switching_dir') 771 772################################################### 773# 774# Define build environments for selected configurations. 775# 776################################################### 777 778for variant_path in variant_paths: 779 print "Building in", variant_path 780 781 # Make a copy of the build-root environment to use for this config. 782 env = main.Clone() 783 env['BUILDDIR'] = variant_path 784 785 # variant_dir is the tail component of build path, and is used to 786 # determine the build parameters (e.g., 'ALPHA_SE') 787 (build_root, variant_dir) = splitpath(variant_path) 788 789 # Set env variables according to the build directory config. 790 sticky_vars.files = [] 791 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 792 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 793 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 794 current_vars_file = joinpath(build_root, 'variables', variant_dir) 795 if isfile(current_vars_file): 796 sticky_vars.files.append(current_vars_file) 797 print "Using saved variables file %s" % current_vars_file 798 else: 799 # Build dir-specific variables file doesn't exist. 800 801 # Make sure the directory is there so we can create it later 802 opt_dir = dirname(current_vars_file) 803 if not isdir(opt_dir): 804 mkdir(opt_dir) 805 806 # Get default build variables from source tree. Variables are 807 # normally determined by name of $VARIANT_DIR, but can be 808 # overriden by 'default=' arg on command line. 809 default_vars_file = joinpath('build_opts', 810 ARGUMENTS.get('default', variant_dir)) 811 if isfile(default_vars_file): 812 sticky_vars.files.append(default_vars_file) 813 print "Variables file %s not found,\n using defaults in %s" \ 814 % (current_vars_file, default_vars_file) 815 else: 816 print "Error: cannot find variables file %s or %s" \ 817 % (current_vars_file, default_vars_file) 818 Exit(1) 819 820 # Apply current variable settings to env 821 sticky_vars.Update(env) 822 nonsticky_vars.Update(env) 823 824 help_text += "\nSticky variables for %s:\n" % variant_dir \ 825 + sticky_vars.GenerateHelpText(env) \ 826 + "\nNon-sticky variables for %s:\n" % variant_dir \ 827 + nonsticky_vars.GenerateHelpText(env) 828 829 # Process variable settings. 830 831 if not have_fenv and env['USE_FENV']: 832 print "Warning: <fenv.h> not available; " \ 833 "forcing USE_FENV to False in", variant_dir + "." 834 env['USE_FENV'] = False 835 836 if not env['USE_FENV']: 837 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 838 print " FP results may deviate slightly from other platforms." 839 840 if env['EFENCE']: 841 env.Append(LIBS=['efence']) 842 843 if env['USE_MYSQL']: 844 if not have_mysql: 845 print "Warning: MySQL not available; " \ 846 "forcing USE_MYSQL to False in", variant_dir + "." 847 env['USE_MYSQL'] = False 848 else: 849 print "Compiling in", variant_dir, "with MySQL support." 850 env.ParseConfig(mysql_config_libs) 851 env.ParseConfig(mysql_config_include) 852 853 # Save sticky variable settings back to current variables file 854 sticky_vars.Save(current_vars_file, env) 855 856 if env['USE_SSE2']: 857 env.Append(CCFLAGS='-msse2') 858 859 # The src/SConscript file sets up the build rules in 'env' according 860 # to the configured variables. It returns a list of environments, 861 # one for each variant build (debug, opt, etc.) 862 envList = SConscript('src/SConscript', variant_dir = variant_path, 863 exports = 'env') 864 865 # Set up the regression tests for each build. 866 for e in envList: 867 SConscript('tests/SConscript', 868 variant_dir = joinpath(variant_path, 'tests', e.Label), 869 exports = { 'env' : e }, duplicate = False) 870 871Help(help_text)
|