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 114extra_python_paths = [ 115 Dir('src/python').srcnode().abspath, # M5 includes 116 Dir('ext/ply').srcnode().abspath, # ply is used by several files 117 ] 118 119sys.path[1:1] = extra_python_paths 120 121from m5.util import compareVersions, readCommand 122 123######################################################################## 124# 125# Set up the main build environment. 126# 127######################################################################## 128use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 129 'PYTHONPATH', 'RANLIB' ]) 130 131use_env = {} 132for key,val in os.environ.iteritems(): 133 if key in use_vars or key.startswith("M5"): 134 use_env[key] = val 135 136main = Environment(ENV=use_env) 137main.root = Dir(".") # The current directory (where this file lives). 138main.srcdir = Dir("src") # The source directory 139 140# add useful python code PYTHONPATH so it can be used by subprocesses 141# as well 142main.AppendENVPath('PYTHONPATH', extra_python_paths) 143 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)
| 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 114extra_python_paths = [ 115 Dir('src/python').srcnode().abspath, # M5 includes 116 Dir('ext/ply').srcnode().abspath, # ply is used by several files 117 ] 118 119sys.path[1:1] = extra_python_paths 120 121from m5.util import compareVersions, readCommand 122 123######################################################################## 124# 125# Set up the main build environment. 126# 127######################################################################## 128use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 129 'PYTHONPATH', 'RANLIB' ]) 130 131use_env = {} 132for key,val in os.environ.iteritems(): 133 if key in use_vars or key.startswith("M5"): 134 use_env[key] = val 135 136main = Environment(ENV=use_env) 137main.root = Dir(".") # The current directory (where this file lives). 138main.srcdir = Dir("src") # The source directory 139 140# add useful python code PYTHONPATH so it can be used by subprocesses 141# as well 142main.AppendENVPath('PYTHONPATH', extra_python_paths) 143 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)
|
| 275main['BUILDROOT'] = 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)
| 276 277Export('main') 278 279main.SConsignFile(joinpath(build_root, "sconsign")) 280 281# Default duplicate option is to use hard links, but this messes up 282# when you use emacs to edit a file in the target dir, as emacs moves 283# file to file~ then copies to file, breaking the link. Symbolic 284# (soft) links work better. 285main.SetOption('duplicate', 'soft-copy') 286 287# 288# Set up global sticky variables... these are common to an entire build 289# tree (not specific to a particular build like ALPHA_SE) 290# 291 292# Variable validators & converters for global sticky variables 293def PathListMakeAbsolute(val): 294 if not val: 295 return val 296 f = lambda p: abspath(expanduser(p)) 297 return ':'.join(map(f, val.split(':'))) 298 299def PathListAllExist(key, val, env): 300 if not val: 301 return 302 paths = val.split(':') 303 for path in paths: 304 if not isdir(path): 305 raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 306 307global_sticky_vars_file = joinpath(build_root, 'variables.global') 308 309global_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS)
|
| 310global_nonsticky_vars = Variables(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 ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 316 ('EXTRAS', 'Add Extra directories to the compilation', '', 317 PathListAllExist, PathListMakeAbsolute), 318 ) 319
| 311 312global_sticky_vars.AddVariables( 313 ('CC', 'C compiler', environ.get('CC', main['CC'])), 314 ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 315 ('BATCH', 'Use batch pool for build and tests', False), 316 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 317 ('M5_BUILD_CACHE', 'Cache built objects in this directory', False), 318 ('EXTRAS', 'Add Extra directories to the compilation', '', 319 PathListAllExist, PathListMakeAbsolute), 320 ) 321
|
| 322global_nonsticky_vars.AddVariables( 323 ('VERBOSE', 'Print full tool command lines', False), 324 ('update_ref', 'Update test reference outputs', False) 325 ) 326 327
|
320# base help text 321help_text = ''' 322Usage: scons [scons options] [build options] [target(s)] 323 324Global sticky options: 325''' 326 327# Update main environment with values from ARGUMENTS & global_sticky_vars_file 328global_sticky_vars.Update(main)
| 328# base help text 329help_text = ''' 330Usage: scons [scons options] [build options] [target(s)] 331 332Global sticky options: 333''' 334 335# Update main environment with values from ARGUMENTS & global_sticky_vars_file 336global_sticky_vars.Update(main)
|
| 337global_nonsticky_vars.Update(main)
|
329 330help_text += global_sticky_vars.GenerateHelpText(main)
| 338 339help_text += global_sticky_vars.GenerateHelpText(main)
|
| 340help_text += global_nonsticky_vars.GenerateHelpText(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
| 341 342# Save sticky variable settings back to current variables file 343global_sticky_vars.Save(global_sticky_vars_file, main) 344 345# Parse EXTRAS variable to build list of all directories where we're 346# look for sources etc. This list is exported as base_dir_list. 347base_dir = main.srcdir.abspath 348if main['EXTRAS']: 349 extras_dir_list = main['EXTRAS'].split(':') 350else: 351 extras_dir_list = [] 352 353Export('base_dir') 354Export('extras_dir_list') 355 356# the ext directory should be on the #includes path 357main.Append(CPPPATH=[Dir('ext')]) 358
|
| 359def _STRIP(path, env): 360 path = str(path) 361 variant_base = env['BUILDROOT'] + os.path.sep 362 if path.startswith(variant_base): 363 path = path[len(variant_base):] 364 elif path.startswith('build/'): 365 path = path[6:] 366 return path 367 368def _STRIP_SOURCE(target, source, env, for_signature): 369 return _STRIP(source[0], env) 370main['STRIP_SOURCE'] = _STRIP_SOURCE 371 372def _STRIP_TARGET(target, source, env, for_signature): 373 return _STRIP(target[0], env) 374main['STRIP_TARGET'] = _STRIP_TARGET 375 376if main['VERBOSE']: 377 def MakeAction(action, string, *args, **kwargs): 378 return Action(action, *args, **kwargs) 379else: 380 MakeAction = Action 381 main['CCCOMSTR'] = ' [ CC] $STRIP_SOURCE' 382 main['CXXCOMSTR'] = ' [ CXX] $STRIP_SOURCE' 383 main['ASCOMSTR'] = ' [ AS] $STRIP_SOURCE' 384 main['SWIGCOMSTR'] = ' [ SWIG] $STRIP_SOURCE' 385 main['ARCOMSTR'] = ' [ AR] $STRIP_TARGET' 386 main['LINKCOMSTR'] = ' [ LINK] $STRIP_TARGET' 387 main['RANLIBCOMSTR'] = ' [ RANLIB] $STRIP_TARGET' 388 main['M4COMSTR'] = ' [ M4] $STRIP_TARGET' 389 main['SHCCCOMSTR'] = ' [ SHCC] $STRIP_TARGET' 390 main['SHCXXCOMSTR'] = ' [ SHCXX] $STRIP_TARGET' 391Export('MakeAction') 392
|
349CXX_version = readCommand([main['CXX'],'--version'], exception=False) 350CXX_V = readCommand([main['CXX'],'-V'], exception=False) 351 352main['GCC'] = CXX_version and CXX_version.find('g++') >= 0 353main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 354main['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 355if main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 356 print 'Error: How can we have two at the same time?' 357 Exit(1) 358 359# Set up default C++ compiler flags 360if main['GCC']: 361 main.Append(CCFLAGS=['-pipe']) 362 main.Append(CCFLAGS=['-fno-strict-aliasing']) 363 main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 364 main.Append(CXXFLAGS=['-Wno-deprecated']) 365 # Read the GCC version to check for versions with bugs 366 # Note CCVERSION doesn't work here because it is run with the CC 367 # before we override it from the command line 368 gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 369 if not compareVersions(gcc_version, '4.4.1') or \ 370 not compareVersions(gcc_version, '4.4.2'): 371 print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 372 main.Append(CCFLAGS=['-fno-tree-vectorize']) 373elif main['ICC']: 374 pass #Fix me... add warning flags once we clean up icc warnings 375elif main['SUNCC']: 376 main.Append(CCFLAGS=['-Qoption ccfe']) 377 main.Append(CCFLAGS=['-features=gcc']) 378 main.Append(CCFLAGS=['-features=extensions']) 379 main.Append(CCFLAGS=['-library=stlport4']) 380 main.Append(CCFLAGS=['-xar']) 381 #main.Append(CCFLAGS=['-instances=semiexplicit']) 382else: 383 print 'Error: Don\'t know what compiler options to use for your compiler.' 384 print ' Please fix SConstruct and src/SConscript and try again.' 385 Exit(1) 386 387# Set up common yacc/bison flags (needed for Ruby) 388main['YACCFLAGS'] = '-d' 389main['YACCHXXFILESUFFIX'] = '.hh' 390 391# Do this after we save setting back, or else we'll tack on an 392# extra 'qdo' every time we run scons. 393if main['BATCH']: 394 main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 395 main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 396 main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 397 main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 398 main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 399 400if sys.platform == 'cygwin': 401 # cygwin has some header file issues... 402 main.Append(CCFLAGS=["-Wno-uninitialized"]) 403 404# Check for SWIG 405if not main.has_key('SWIG'): 406 print 'Error: SWIG utility not found.' 407 print ' Please install (see http://www.swig.org) and retry.' 408 Exit(1) 409 410# Check for appropriate SWIG version 411swig_version = readCommand(('swig', '-version'), exception='').split() 412# First 3 words should be "SWIG Version x.y.z" 413if len(swig_version) < 3 or \ 414 swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 415 print 'Error determining SWIG version.' 416 Exit(1) 417 418min_swig_version = '1.3.28' 419if compareVersions(swig_version[2], min_swig_version) < 0: 420 print 'Error: SWIG version', min_swig_version, 'or newer required.' 421 print ' Installed version:', swig_version[2] 422 Exit(1) 423 424# Set up SWIG flags & scanner 425swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 426main.Append(SWIGFLAGS=swig_flags) 427 428# filter out all existing swig scanners, they mess up the dependency 429# stuff for some reason 430scanners = [] 431for scanner in main['SCANNERS']: 432 skeys = scanner.skeys 433 if skeys == '.i': 434 continue 435 436 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 437 continue 438 439 scanners.append(scanner) 440 441# add the new swig scanner that we like better 442from SCons.Scanner import ClassicCPP as CPPScanner 443swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 444scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 445 446# replace the scanners list that has what we want 447main['SCANNERS'] = scanners 448 449# Add a custom Check function to the Configure context so that we can 450# figure out if the compiler adds leading underscores to global 451# variables. This is needed for the autogenerated asm files that we 452# use for embedding the python code. 453def CheckLeading(context): 454 context.Message("Checking for leading underscore in global variables...") 455 # 1) Define a global variable called x from asm so the C compiler 456 # won't change the symbol at all. 457 # 2) Declare that variable. 458 # 3) Use the variable 459 # 460 # If the compiler prepends an underscore, this will successfully 461 # link because the external symbol 'x' will be called '_x' which 462 # was defined by the asm statement. If the compiler does not 463 # prepend an underscore, this will not successfully link because 464 # '_x' will have been defined by assembly, while the C portion of 465 # the code will be trying to use 'x' 466 ret = context.TryLink(''' 467 asm(".globl _x; _x: .byte 0"); 468 extern int x; 469 int main() { return x; } 470 ''', extension=".c") 471 context.env.Append(LEADING_UNDERSCORE=ret) 472 context.Result(ret) 473 return ret 474 475# Platform-specific configuration. Note again that we assume that all 476# builds under a given build root run on the same host platform. 477conf = Configure(main, 478 conf_dir = joinpath(build_root, '.scons_config'), 479 log_file = joinpath(build_root, 'scons_config.log'), 480 custom_tests = { 'CheckLeading' : CheckLeading }) 481 482# Check for leading underscores. Don't really need to worry either 483# way so don't need to check the return code. 484conf.CheckLeading() 485 486# Check if we should compile a 64 bit binary on Mac OS X/Darwin 487try: 488 import platform 489 uname = platform.uname() 490 if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 491 if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 492 main.Append(CCFLAGS=['-arch x86_64']) 493 main.Append(CFLAGS=['-arch x86_64']) 494 main.Append(LINKFLAGS=['-arch x86_64']) 495 main.Append(ASFLAGS=['-arch x86_64']) 496except: 497 pass 498 499# Recent versions of scons substitute a "Null" object for Configure() 500# when configuration isn't necessary, e.g., if the "--help" option is 501# present. Unfortuantely this Null object always returns false, 502# breaking all our configuration checks. We replace it with our own 503# more optimistic null object that returns True instead. 504if not conf: 505 def NullCheck(*args, **kwargs): 506 return True 507 508 class NullConf: 509 def __init__(self, env): 510 self.env = env 511 def Finish(self): 512 return self.env 513 def __getattr__(self, mname): 514 return NullCheck 515 516 conf = NullConf(main) 517 518# Find Python include and library directories for embedding the 519# interpreter. For consistency, we will use the same Python 520# installation used to run scons (and thus this script). If you want 521# to link in an alternate version, see above for instructions on how 522# to invoke scons with a different copy of the Python interpreter. 523from distutils import sysconfig 524 525py_getvar = sysconfig.get_config_var 526 527py_debug = getattr(sys, 'pydebug', False) 528py_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 529 530py_general_include = sysconfig.get_python_inc() 531py_platform_include = sysconfig.get_python_inc(plat_specific=True) 532py_includes = [ py_general_include ] 533if py_platform_include != py_general_include: 534 py_includes.append(py_platform_include) 535 536py_lib_path = [ py_getvar('LIBDIR') ] 537# add the prefix/lib/pythonX.Y/config dir, but only if there is no 538# shared library in prefix/lib/. 539if not py_getvar('Py_ENABLE_SHARED'): 540 py_lib_path.append(py_getvar('LIBPL')) 541 542py_libs = [] 543for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 544 assert lib.startswith('-l') 545 lib = lib[2:] 546 if lib not in py_libs: 547 py_libs.append(lib) 548py_libs.append(py_version) 549 550main.Append(CPPPATH=py_includes) 551main.Append(LIBPATH=py_lib_path) 552 553# Cache build files in the supplied directory. 554if main['M5_BUILD_CACHE']: 555 print 'Using build cache located at', main['M5_BUILD_CACHE'] 556 CacheDir(main['M5_BUILD_CACHE']) 557 558 559# verify that this stuff works 560if not conf.CheckHeader('Python.h', '<>'): 561 print "Error: can't find Python.h header in", py_includes 562 Exit(1) 563 564for lib in py_libs: 565 if not conf.CheckLib(lib): 566 print "Error: can't find library %s required by python" % lib 567 Exit(1) 568 569# On Solaris you need to use libsocket for socket ops 570if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 571 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 572 print "Can't find library with socket calls (e.g. accept())" 573 Exit(1) 574 575# Check for zlib. If the check passes, libz will be automatically 576# added to the LIBS environment variable. 577if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 578 print 'Error: did not find needed zlib compression library '\ 579 'and/or zlib.h header file.' 580 print ' Please install zlib and try again.' 581 Exit(1) 582 583# Check for <fenv.h> (C99 FP environment control) 584have_fenv = conf.CheckHeader('fenv.h', '<>') 585if not have_fenv: 586 print "Warning: Header file <fenv.h> not found." 587 print " This host has no IEEE FP rounding mode control." 588 589###################################################################### 590# 591# Check for mysql. 592# 593mysql_config = WhereIs('mysql_config') 594have_mysql = bool(mysql_config) 595 596# Check MySQL version. 597if have_mysql: 598 mysql_version = readCommand(mysql_config + ' --version') 599 min_mysql_version = '4.1' 600 if compareVersions(mysql_version, min_mysql_version) < 0: 601 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 602 print ' Version', mysql_version, 'detected.' 603 have_mysql = False 604 605# Set up mysql_config commands. 606if have_mysql: 607 mysql_config_include = mysql_config + ' --include' 608 if os.system(mysql_config_include + ' > /dev/null') != 0: 609 # older mysql_config versions don't support --include, use 610 # --cflags instead 611 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 612 # This seems to work in all versions 613 mysql_config_libs = mysql_config + ' --libs' 614 615###################################################################### 616# 617# Finish the configuration 618# 619main = conf.Finish() 620 621###################################################################### 622# 623# Collect all non-global variables 624# 625 626# Define the universe of supported ISAs 627all_isa_list = [ ] 628Export('all_isa_list') 629 630class CpuModel(object): 631 '''The CpuModel class encapsulates everything the ISA parser needs to 632 know about a particular CPU model.''' 633 634 # Dict of available CPU model objects. Accessible as CpuModel.dict. 635 dict = {} 636 list = [] 637 defaults = [] 638 639 # Constructor. Automatically adds models to CpuModel.dict. 640 def __init__(self, name, filename, includes, strings, default=False): 641 self.name = name # name of model 642 self.filename = filename # filename for output exec code 643 self.includes = includes # include files needed in exec file 644 # The 'strings' dict holds all the per-CPU symbols we can 645 # substitute into templates etc. 646 self.strings = strings 647 648 # This cpu is enabled by default 649 self.default = default 650 651 # Add self to dict 652 if name in CpuModel.dict: 653 raise AttributeError, "CpuModel '%s' already registered" % name 654 CpuModel.dict[name] = self 655 CpuModel.list.append(name) 656 657Export('CpuModel') 658 659# Sticky variables get saved in the variables file so they persist from 660# one invocation to the next (unless overridden, in which case the new 661# value becomes sticky). 662sticky_vars = Variables(args=ARGUMENTS) 663Export('sticky_vars') 664 665# Sticky variables that should be exported 666export_vars = [] 667Export('export_vars') 668
| 393CXX_version = readCommand([main['CXX'],'--version'], exception=False) 394CXX_V = readCommand([main['CXX'],'-V'], exception=False) 395 396main['GCC'] = CXX_version and CXX_version.find('g++') >= 0 397main['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 398main['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 399if main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 400 print 'Error: How can we have two at the same time?' 401 Exit(1) 402 403# Set up default C++ compiler flags 404if main['GCC']: 405 main.Append(CCFLAGS=['-pipe']) 406 main.Append(CCFLAGS=['-fno-strict-aliasing']) 407 main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 408 main.Append(CXXFLAGS=['-Wno-deprecated']) 409 # Read the GCC version to check for versions with bugs 410 # Note CCVERSION doesn't work here because it is run with the CC 411 # before we override it from the command line 412 gcc_version = readCommand([main['CXX'], '-dumpversion'], exception=False) 413 if not compareVersions(gcc_version, '4.4.1') or \ 414 not compareVersions(gcc_version, '4.4.2'): 415 print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.' 416 main.Append(CCFLAGS=['-fno-tree-vectorize']) 417elif main['ICC']: 418 pass #Fix me... add warning flags once we clean up icc warnings 419elif main['SUNCC']: 420 main.Append(CCFLAGS=['-Qoption ccfe']) 421 main.Append(CCFLAGS=['-features=gcc']) 422 main.Append(CCFLAGS=['-features=extensions']) 423 main.Append(CCFLAGS=['-library=stlport4']) 424 main.Append(CCFLAGS=['-xar']) 425 #main.Append(CCFLAGS=['-instances=semiexplicit']) 426else: 427 print 'Error: Don\'t know what compiler options to use for your compiler.' 428 print ' Please fix SConstruct and src/SConscript and try again.' 429 Exit(1) 430 431# Set up common yacc/bison flags (needed for Ruby) 432main['YACCFLAGS'] = '-d' 433main['YACCHXXFILESUFFIX'] = '.hh' 434 435# Do this after we save setting back, or else we'll tack on an 436# extra 'qdo' every time we run scons. 437if main['BATCH']: 438 main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 439 main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 440 main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 441 main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 442 main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 443 444if sys.platform == 'cygwin': 445 # cygwin has some header file issues... 446 main.Append(CCFLAGS=["-Wno-uninitialized"]) 447 448# Check for SWIG 449if not main.has_key('SWIG'): 450 print 'Error: SWIG utility not found.' 451 print ' Please install (see http://www.swig.org) and retry.' 452 Exit(1) 453 454# Check for appropriate SWIG version 455swig_version = readCommand(('swig', '-version'), exception='').split() 456# First 3 words should be "SWIG Version x.y.z" 457if len(swig_version) < 3 or \ 458 swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 459 print 'Error determining SWIG version.' 460 Exit(1) 461 462min_swig_version = '1.3.28' 463if compareVersions(swig_version[2], min_swig_version) < 0: 464 print 'Error: SWIG version', min_swig_version, 'or newer required.' 465 print ' Installed version:', swig_version[2] 466 Exit(1) 467 468# Set up SWIG flags & scanner 469swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 470main.Append(SWIGFLAGS=swig_flags) 471 472# filter out all existing swig scanners, they mess up the dependency 473# stuff for some reason 474scanners = [] 475for scanner in main['SCANNERS']: 476 skeys = scanner.skeys 477 if skeys == '.i': 478 continue 479 480 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 481 continue 482 483 scanners.append(scanner) 484 485# add the new swig scanner that we like better 486from SCons.Scanner import ClassicCPP as CPPScanner 487swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 488scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 489 490# replace the scanners list that has what we want 491main['SCANNERS'] = scanners 492 493# Add a custom Check function to the Configure context so that we can 494# figure out if the compiler adds leading underscores to global 495# variables. This is needed for the autogenerated asm files that we 496# use for embedding the python code. 497def CheckLeading(context): 498 context.Message("Checking for leading underscore in global variables...") 499 # 1) Define a global variable called x from asm so the C compiler 500 # won't change the symbol at all. 501 # 2) Declare that variable. 502 # 3) Use the variable 503 # 504 # If the compiler prepends an underscore, this will successfully 505 # link because the external symbol 'x' will be called '_x' which 506 # was defined by the asm statement. If the compiler does not 507 # prepend an underscore, this will not successfully link because 508 # '_x' will have been defined by assembly, while the C portion of 509 # the code will be trying to use 'x' 510 ret = context.TryLink(''' 511 asm(".globl _x; _x: .byte 0"); 512 extern int x; 513 int main() { return x; } 514 ''', extension=".c") 515 context.env.Append(LEADING_UNDERSCORE=ret) 516 context.Result(ret) 517 return ret 518 519# Platform-specific configuration. Note again that we assume that all 520# builds under a given build root run on the same host platform. 521conf = Configure(main, 522 conf_dir = joinpath(build_root, '.scons_config'), 523 log_file = joinpath(build_root, 'scons_config.log'), 524 custom_tests = { 'CheckLeading' : CheckLeading }) 525 526# Check for leading underscores. Don't really need to worry either 527# way so don't need to check the return code. 528conf.CheckLeading() 529 530# Check if we should compile a 64 bit binary on Mac OS X/Darwin 531try: 532 import platform 533 uname = platform.uname() 534 if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 535 if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 536 main.Append(CCFLAGS=['-arch x86_64']) 537 main.Append(CFLAGS=['-arch x86_64']) 538 main.Append(LINKFLAGS=['-arch x86_64']) 539 main.Append(ASFLAGS=['-arch x86_64']) 540except: 541 pass 542 543# Recent versions of scons substitute a "Null" object for Configure() 544# when configuration isn't necessary, e.g., if the "--help" option is 545# present. Unfortuantely this Null object always returns false, 546# breaking all our configuration checks. We replace it with our own 547# more optimistic null object that returns True instead. 548if not conf: 549 def NullCheck(*args, **kwargs): 550 return True 551 552 class NullConf: 553 def __init__(self, env): 554 self.env = env 555 def Finish(self): 556 return self.env 557 def __getattr__(self, mname): 558 return NullCheck 559 560 conf = NullConf(main) 561 562# Find Python include and library directories for embedding the 563# interpreter. For consistency, we will use the same Python 564# installation used to run scons (and thus this script). If you want 565# to link in an alternate version, see above for instructions on how 566# to invoke scons with a different copy of the Python interpreter. 567from distutils import sysconfig 568 569py_getvar = sysconfig.get_config_var 570 571py_debug = getattr(sys, 'pydebug', False) 572py_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 573 574py_general_include = sysconfig.get_python_inc() 575py_platform_include = sysconfig.get_python_inc(plat_specific=True) 576py_includes = [ py_general_include ] 577if py_platform_include != py_general_include: 578 py_includes.append(py_platform_include) 579 580py_lib_path = [ py_getvar('LIBDIR') ] 581# add the prefix/lib/pythonX.Y/config dir, but only if there is no 582# shared library in prefix/lib/. 583if not py_getvar('Py_ENABLE_SHARED'): 584 py_lib_path.append(py_getvar('LIBPL')) 585 586py_libs = [] 587for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 588 assert lib.startswith('-l') 589 lib = lib[2:] 590 if lib not in py_libs: 591 py_libs.append(lib) 592py_libs.append(py_version) 593 594main.Append(CPPPATH=py_includes) 595main.Append(LIBPATH=py_lib_path) 596 597# Cache build files in the supplied directory. 598if main['M5_BUILD_CACHE']: 599 print 'Using build cache located at', main['M5_BUILD_CACHE'] 600 CacheDir(main['M5_BUILD_CACHE']) 601 602 603# verify that this stuff works 604if not conf.CheckHeader('Python.h', '<>'): 605 print "Error: can't find Python.h header in", py_includes 606 Exit(1) 607 608for lib in py_libs: 609 if not conf.CheckLib(lib): 610 print "Error: can't find library %s required by python" % lib 611 Exit(1) 612 613# On Solaris you need to use libsocket for socket ops 614if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 615 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 616 print "Can't find library with socket calls (e.g. accept())" 617 Exit(1) 618 619# Check for zlib. If the check passes, libz will be automatically 620# added to the LIBS environment variable. 621if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 622 print 'Error: did not find needed zlib compression library '\ 623 'and/or zlib.h header file.' 624 print ' Please install zlib and try again.' 625 Exit(1) 626 627# Check for <fenv.h> (C99 FP environment control) 628have_fenv = conf.CheckHeader('fenv.h', '<>') 629if not have_fenv: 630 print "Warning: Header file <fenv.h> not found." 631 print " This host has no IEEE FP rounding mode control." 632 633###################################################################### 634# 635# Check for mysql. 636# 637mysql_config = WhereIs('mysql_config') 638have_mysql = bool(mysql_config) 639 640# Check MySQL version. 641if have_mysql: 642 mysql_version = readCommand(mysql_config + ' --version') 643 min_mysql_version = '4.1' 644 if compareVersions(mysql_version, min_mysql_version) < 0: 645 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 646 print ' Version', mysql_version, 'detected.' 647 have_mysql = False 648 649# Set up mysql_config commands. 650if have_mysql: 651 mysql_config_include = mysql_config + ' --include' 652 if os.system(mysql_config_include + ' > /dev/null') != 0: 653 # older mysql_config versions don't support --include, use 654 # --cflags instead 655 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 656 # This seems to work in all versions 657 mysql_config_libs = mysql_config + ' --libs' 658 659###################################################################### 660# 661# Finish the configuration 662# 663main = conf.Finish() 664 665###################################################################### 666# 667# Collect all non-global variables 668# 669 670# Define the universe of supported ISAs 671all_isa_list = [ ] 672Export('all_isa_list') 673 674class CpuModel(object): 675 '''The CpuModel class encapsulates everything the ISA parser needs to 676 know about a particular CPU model.''' 677 678 # Dict of available CPU model objects. Accessible as CpuModel.dict. 679 dict = {} 680 list = [] 681 defaults = [] 682 683 # Constructor. Automatically adds models to CpuModel.dict. 684 def __init__(self, name, filename, includes, strings, default=False): 685 self.name = name # name of model 686 self.filename = filename # filename for output exec code 687 self.includes = includes # include files needed in exec file 688 # The 'strings' dict holds all the per-CPU symbols we can 689 # substitute into templates etc. 690 self.strings = strings 691 692 # This cpu is enabled by default 693 self.default = default 694 695 # Add self to dict 696 if name in CpuModel.dict: 697 raise AttributeError, "CpuModel '%s' already registered" % name 698 CpuModel.dict[name] = self 699 CpuModel.list.append(name) 700 701Export('CpuModel') 702 703# Sticky variables get saved in the variables file so they persist from 704# one invocation to the next (unless overridden, in which case the new 705# value becomes sticky). 706sticky_vars = Variables(args=ARGUMENTS) 707Export('sticky_vars') 708 709# Sticky variables that should be exported 710export_vars = [] 711Export('export_vars') 712
|
669# Non-sticky variables only apply to the current build. 670nonsticky_vars = Variables(args=ARGUMENTS) 671Export('nonsticky_vars') 672
| |
673# Walk the tree and execute all SConsopts scripts that wil add to the 674# above variables 675for bdir in [ base_dir ] + extras_dir_list: 676 for root, dirs, files in os.walk(bdir): 677 if 'SConsopts' in files: 678 print "Reading", joinpath(root, 'SConsopts') 679 SConscript(joinpath(root, 'SConsopts')) 680 681all_isa_list.sort() 682 683sticky_vars.AddVariables( 684 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 685 BoolVariable('FULL_SYSTEM', 'Full-system support', False), 686 ListVariable('CPU_MODELS', 'CPU models', 687 sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 688 sorted(CpuModel.list)), 689 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 690 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 691 False), 692 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 693 False), 694 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 695 False), 696 BoolVariable('SS_COMPATIBLE_FP', 697 'Make floating-point results compatible with SimpleScalar', 698 False), 699 BoolVariable('USE_SSE2', 700 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 701 False), 702 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 703 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 704 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 705 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 706 BoolVariable('RUBY', 'Build with Ruby', False), 707 ) 708
| 713# Walk the tree and execute all SConsopts scripts that wil add to the 714# above variables 715for bdir in [ base_dir ] + extras_dir_list: 716 for root, dirs, files in os.walk(bdir): 717 if 'SConsopts' in files: 718 print "Reading", joinpath(root, 'SConsopts') 719 SConscript(joinpath(root, 'SConsopts')) 720 721all_isa_list.sort() 722 723sticky_vars.AddVariables( 724 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 725 BoolVariable('FULL_SYSTEM', 'Full-system support', False), 726 ListVariable('CPU_MODELS', 'CPU models', 727 sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 728 sorted(CpuModel.list)), 729 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 730 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 731 False), 732 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 733 False), 734 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 735 False), 736 BoolVariable('SS_COMPATIBLE_FP', 737 'Make floating-point results compatible with SimpleScalar', 738 False), 739 BoolVariable('USE_SSE2', 740 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 741 False), 742 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 743 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 744 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 745 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 746 BoolVariable('RUBY', 'Build with Ruby', False), 747 ) 748
|
709nonsticky_vars.AddVariables( 710 BoolVariable('update_ref', 'Update test reference outputs', False) 711 ) 712
| |
713# These variables get exported to #defines in config/*.hh (see src/SConscript). 714export_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 715 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 716 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 717 718################################################### 719# 720# Define a SCons builder for configuration flag headers. 721# 722################################################### 723 724# This function generates a config header file that #defines the 725# variable symbol to the current variable setting (0 or 1). The source 726# operands are the name of the variable and a Value node containing the 727# value of the variable. 728def build_config_file(target, source, env): 729 (variable, value) = [s.get_contents() for s in source] 730 f = file(str(target[0]), 'w') 731 print >> f, '#define', variable, value 732 f.close() 733 return None 734 735# Generate the message to be printed when building the config file. 736def build_config_file_string(target, source, env): 737 (variable, value) = [s.get_contents() for s in source] 738 return "Defining %s as %s in %s." % (variable, value, target[0]) 739 740# Combine the two functions into a scons Action object. 741config_action = Action(build_config_file, build_config_file_string) 742 743# The emitter munges the source & target node lists to reflect what 744# we're really doing. 745def config_emitter(target, source, env): 746 # extract variable name from Builder arg 747 variable = str(target[0]) 748 # True target is config header file 749 target = joinpath('config', variable.lower() + '.hh') 750 val = env[variable] 751 if isinstance(val, bool): 752 # Force value to 0/1 753 val = int(val) 754 elif isinstance(val, str): 755 val = '"' + val + '"' 756 757 # Sources are variable name & value (packaged in SCons Value nodes) 758 return ([target], [Value(variable), Value(val)]) 759 760config_builder = Builder(emitter = config_emitter, action = config_action) 761 762main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 763 764# libelf build is shared across all configs in the build root. 765main.SConscript('ext/libelf/SConscript', 766 variant_dir = joinpath(build_root, 'libelf')) 767 768# gzstream build is shared across all configs in the build root. 769main.SConscript('ext/gzstream/SConscript', 770 variant_dir = joinpath(build_root, 'gzstream')) 771 772################################################### 773# 774# This function is used to set up a directory with switching headers 775# 776################################################### 777 778main['ALL_ISA_LIST'] = all_isa_list 779def make_switching_dir(dname, switch_headers, env): 780 # Generate the header. target[0] is the full path of the output 781 # header to generate. 'source' is a dummy variable, since we get the 782 # list of ISAs from env['ALL_ISA_LIST']. 783 def gen_switch_hdr(target, source, env): 784 fname = str(target[0]) 785 f = open(fname, 'w') 786 isa = env['TARGET_ISA'].lower() 787 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 788 f.close() 789
| 749# These variables get exported to #defines in config/*.hh (see src/SConscript). 750export_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 751 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 752 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 753 754################################################### 755# 756# Define a SCons builder for configuration flag headers. 757# 758################################################### 759 760# This function generates a config header file that #defines the 761# variable symbol to the current variable setting (0 or 1). The source 762# operands are the name of the variable and a Value node containing the 763# value of the variable. 764def build_config_file(target, source, env): 765 (variable, value) = [s.get_contents() for s in source] 766 f = file(str(target[0]), 'w') 767 print >> f, '#define', variable, value 768 f.close() 769 return None 770 771# Generate the message to be printed when building the config file. 772def build_config_file_string(target, source, env): 773 (variable, value) = [s.get_contents() for s in source] 774 return "Defining %s as %s in %s." % (variable, value, target[0]) 775 776# Combine the two functions into a scons Action object. 777config_action = Action(build_config_file, build_config_file_string) 778 779# The emitter munges the source & target node lists to reflect what 780# we're really doing. 781def config_emitter(target, source, env): 782 # extract variable name from Builder arg 783 variable = str(target[0]) 784 # True target is config header file 785 target = joinpath('config', variable.lower() + '.hh') 786 val = env[variable] 787 if isinstance(val, bool): 788 # Force value to 0/1 789 val = int(val) 790 elif isinstance(val, str): 791 val = '"' + val + '"' 792 793 # Sources are variable name & value (packaged in SCons Value nodes) 794 return ([target], [Value(variable), Value(val)]) 795 796config_builder = Builder(emitter = config_emitter, action = config_action) 797 798main.Append(BUILDERS = { 'ConfigFile' : config_builder }) 799 800# libelf build is shared across all configs in the build root. 801main.SConscript('ext/libelf/SConscript', 802 variant_dir = joinpath(build_root, 'libelf')) 803 804# gzstream build is shared across all configs in the build root. 805main.SConscript('ext/gzstream/SConscript', 806 variant_dir = joinpath(build_root, 'gzstream')) 807 808################################################### 809# 810# This function is used to set up a directory with switching headers 811# 812################################################### 813 814main['ALL_ISA_LIST'] = all_isa_list 815def make_switching_dir(dname, switch_headers, env): 816 # Generate the header. target[0] is the full path of the output 817 # header to generate. 'source' is a dummy variable, since we get the 818 # list of ISAs from env['ALL_ISA_LIST']. 819 def gen_switch_hdr(target, source, env): 820 fname = str(target[0]) 821 f = open(fname, 'w') 822 isa = env['TARGET_ISA'].lower() 823 print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 824 f.close() 825
|
790 # String to print when generating header 791 def gen_switch_hdr_string(target, source, env): 792 return "Generating switch header " + str(target[0]) 793
| |
794 # Build SCons Action object. 'varlist' specifies env vars that this 795 # action depends on; when env['ALL_ISA_LIST'] changes these actions 796 # should get re-executed.
| 826 # Build SCons Action object. 'varlist' specifies env vars that this 827 # action depends on; when env['ALL_ISA_LIST'] changes these actions 828 # should get re-executed.
|
797 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 798 varlist=['ALL_ISA_LIST'])
| 829 switch_hdr_action = MakeAction(gen_switch_hdr, 830 " [GENERATE] $STRIP_TARGET", varlist=['ALL_ISA_LIST'])
|
799 800 # Instantiate actions for each header 801 for hdr in switch_headers: 802 env.Command(hdr, [], switch_hdr_action) 803Export('make_switching_dir') 804 805################################################### 806# 807# Define build environments for selected configurations. 808# 809################################################### 810 811for variant_path in variant_paths: 812 print "Building in", variant_path 813 814 # Make a copy of the build-root environment to use for this config. 815 env = main.Clone() 816 env['BUILDDIR'] = variant_path 817 818 # variant_dir is the tail component of build path, and is used to 819 # determine the build parameters (e.g., 'ALPHA_SE') 820 (build_root, variant_dir) = splitpath(variant_path) 821 822 # Set env variables according to the build directory config. 823 sticky_vars.files = [] 824 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 825 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 826 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 827 current_vars_file = joinpath(build_root, 'variables', variant_dir) 828 if isfile(current_vars_file): 829 sticky_vars.files.append(current_vars_file) 830 print "Using saved variables file %s" % current_vars_file 831 else: 832 # Build dir-specific variables file doesn't exist. 833 834 # Make sure the directory is there so we can create it later 835 opt_dir = dirname(current_vars_file) 836 if not isdir(opt_dir): 837 mkdir(opt_dir) 838 839 # Get default build variables from source tree. Variables are 840 # normally determined by name of $VARIANT_DIR, but can be 841 # overriden by 'default=' arg on command line. 842 default_vars_file = joinpath('build_opts', 843 ARGUMENTS.get('default', variant_dir)) 844 if isfile(default_vars_file): 845 sticky_vars.files.append(default_vars_file) 846 print "Variables file %s not found,\n using defaults in %s" \ 847 % (current_vars_file, default_vars_file) 848 else: 849 print "Error: cannot find variables file %s or %s" \ 850 % (current_vars_file, default_vars_file) 851 Exit(1) 852 853 # Apply current variable settings to env 854 sticky_vars.Update(env)
| 831 832 # Instantiate actions for each header 833 for hdr in switch_headers: 834 env.Command(hdr, [], switch_hdr_action) 835Export('make_switching_dir') 836 837################################################### 838# 839# Define build environments for selected configurations. 840# 841################################################### 842 843for variant_path in variant_paths: 844 print "Building in", variant_path 845 846 # Make a copy of the build-root environment to use for this config. 847 env = main.Clone() 848 env['BUILDDIR'] = variant_path 849 850 # variant_dir is the tail component of build path, and is used to 851 # determine the build parameters (e.g., 'ALPHA_SE') 852 (build_root, variant_dir) = splitpath(variant_path) 853 854 # Set env variables according to the build directory config. 855 sticky_vars.files = [] 856 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 857 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 858 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 859 current_vars_file = joinpath(build_root, 'variables', variant_dir) 860 if isfile(current_vars_file): 861 sticky_vars.files.append(current_vars_file) 862 print "Using saved variables file %s" % current_vars_file 863 else: 864 # Build dir-specific variables file doesn't exist. 865 866 # Make sure the directory is there so we can create it later 867 opt_dir = dirname(current_vars_file) 868 if not isdir(opt_dir): 869 mkdir(opt_dir) 870 871 # Get default build variables from source tree. Variables are 872 # normally determined by name of $VARIANT_DIR, but can be 873 # overriden by 'default=' arg on command line. 874 default_vars_file = joinpath('build_opts', 875 ARGUMENTS.get('default', variant_dir)) 876 if isfile(default_vars_file): 877 sticky_vars.files.append(default_vars_file) 878 print "Variables file %s not found,\n using defaults in %s" \ 879 % (current_vars_file, default_vars_file) 880 else: 881 print "Error: cannot find variables file %s or %s" \ 882 % (current_vars_file, default_vars_file) 883 Exit(1) 884 885 # Apply current variable settings to env 886 sticky_vars.Update(env)
|
855 nonsticky_vars.Update(env)
| |
856 857 help_text += "\nSticky variables for %s:\n" % variant_dir \
| 887 888 help_text += "\nSticky variables for %s:\n" % variant_dir \
|
858 + sticky_vars.GenerateHelpText(env) \ 859 + "\nNon-sticky variables for %s:\n" % variant_dir \ 860 + nonsticky_vars.GenerateHelpText(env)
| 889 + sticky_vars.GenerateHelpText(env)
|
861 862 # Process variable settings. 863 864 if not have_fenv and env['USE_FENV']: 865 print "Warning: <fenv.h> not available; " \ 866 "forcing USE_FENV to False in", variant_dir + "." 867 env['USE_FENV'] = False 868 869 if not env['USE_FENV']: 870 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 871 print " FP results may deviate slightly from other platforms." 872 873 if env['EFENCE']: 874 env.Append(LIBS=['efence']) 875 876 if env['USE_MYSQL']: 877 if not have_mysql: 878 print "Warning: MySQL not available; " \ 879 "forcing USE_MYSQL to False in", variant_dir + "." 880 env['USE_MYSQL'] = False 881 else: 882 print "Compiling in", variant_dir, "with MySQL support." 883 env.ParseConfig(mysql_config_libs) 884 env.ParseConfig(mysql_config_include) 885 886 # Save sticky variable settings back to current variables file 887 sticky_vars.Save(current_vars_file, env) 888 889 if env['USE_SSE2']: 890 env.Append(CCFLAGS=['-msse2']) 891 892 # The src/SConscript file sets up the build rules in 'env' according 893 # to the configured variables. It returns a list of environments, 894 # one for each variant build (debug, opt, etc.) 895 envList = SConscript('src/SConscript', variant_dir = variant_path, 896 exports = 'env') 897 898 # Set up the regression tests for each build. 899 for e in envList: 900 SConscript('tests/SConscript', 901 variant_dir = joinpath(variant_path, 'tests', e.Label), 902 exports = { 'env' : e }, duplicate = False) 903 904Help(help_text)
| 890 891 # Process variable settings. 892 893 if not have_fenv and env['USE_FENV']: 894 print "Warning: <fenv.h> not available; " \ 895 "forcing USE_FENV to False in", variant_dir + "." 896 env['USE_FENV'] = False 897 898 if not env['USE_FENV']: 899 print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 900 print " FP results may deviate slightly from other platforms." 901 902 if env['EFENCE']: 903 env.Append(LIBS=['efence']) 904 905 if env['USE_MYSQL']: 906 if not have_mysql: 907 print "Warning: MySQL not available; " \ 908 "forcing USE_MYSQL to False in", variant_dir + "." 909 env['USE_MYSQL'] = False 910 else: 911 print "Compiling in", variant_dir, "with MySQL support." 912 env.ParseConfig(mysql_config_libs) 913 env.ParseConfig(mysql_config_include) 914 915 # Save sticky variable settings back to current variables file 916 sticky_vars.Save(current_vars_file, env) 917 918 if env['USE_SSE2']: 919 env.Append(CCFLAGS=['-msse2']) 920 921 # The src/SConscript file sets up the build rules in 'env' according 922 # to the configured variables. It returns a list of environments, 923 # one for each variant build (debug, opt, etc.) 924 envList = SConscript('src/SConscript', variant_dir = variant_path, 925 exports = 'env') 926 927 # Set up the regression tests for each build. 928 for e in envList: 929 SConscript('tests/SConscript', 930 variant_dir = joinpath(variant_path, 'tests', e.Label), 931 exports = { 'env' : e }, duplicate = False) 932 933Help(help_text)
|