3 # Copyright (c) 2009 The Hewlett-Packard Development Company
4 # Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
30 # Authors: Steve Reinhardt
33 ###################################################
35 # SCons top-level build description (SConstruct) file.
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).
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.
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
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
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
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
66 ###################################################
68 # Check for recent-enough Python and SCons versions.
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)
78 For more details, see:
79 http://m5sim.org/wiki/index.php/Compiling_M5
83 # We ensure the python version early because we have stuff that
86 EnsurePythonVersion(2, 4)
89 You can use a non-default installation of the Python interpreter by
90 either (1) rearranging your PATH so that scons finds the non-default
91 'python' first or (2) explicitly invoking an alternative interpreter
94 For more details, see:
95 http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation
99 # Global Python includes
105 from os
import mkdir
, environ
106 from os
.path
import abspath
, basename
, dirname
, expanduser
, normpath
107 from os
.path
import exists
, isdir
, isfile
108 from os
.path
import join
as joinpath
, split
as splitpath
114 extra_python_paths
= [
115 Dir('src/python').srcnode().abspath
, # M5 includes
116 Dir('ext/ply').srcnode().abspath
, # ply is used by several files
119 sys
.path
[1:1] = extra_python_paths
121 from m5
.util
import compareVersions
, readCommand
123 ########################################################################
125 # Set up the main build environment.
127 ########################################################################
128 use_vars
= set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH',
129 'PYTHONPATH', 'RANLIB' ])
132 for key
,val
in os
.environ
.iteritems():
133 if key
in use_vars
or key
.startswith("M5"):
136 main
= Environment(ENV
=use_env
)
137 main
.root
= Dir(".") # The current directory (where this file lives).
138 main
.srcdir
= Dir("src") # The source directory
140 # add useful python code PYTHONPATH so it can be used by subprocesses
142 main
.AppendENVPath('PYTHONPATH', extra_python_paths
)
144 ########################################################################
148 # If the M5 directory is a mercurial repository, we should do some
151 ########################################################################
153 hgdir
= main
.root
.Dir(".hg")
155 mercurial_style_message
= """
156 You're missing the M5 style hook.
157 Please install the hook so we can ensure that all code fits a common style.
159 All you'd need to do is add the following lines to your repository .hg/hgrc
160 or your personal .hgrc
164 style = %s/util/style.py
167 pretxncommit.style = python:style.check_whitespace
170 mercurial_bin_not_found
= """
171 Mercurial binary cannot be found, unfortunately this means that we
172 cannot easily determine the version of M5 that you are running and
173 this makes error messages more difficult to collect. Please consider
174 installing mercurial if you choose to post an error message
177 mercurial_lib_not_found
= """
178 Mercurial libraries cannot be found, ignoring style hook
179 If you are actually a M5 developer, please fix this and
180 run the style hook. It is important.
185 # 1) Grab repository revision if we know it.
186 cmd
= "hg id -n -i -t -b"
188 hg_info
= readCommand(cmd
, cwd
=main
.root
.abspath
).strip()
190 print mercurial_bin_not_found
192 # 2) Ensure that the style hook is in place.
195 if ARGUMENTS
.get('IGNORE_STYLE') != 'True':
196 from mercurial
import ui
199 print mercurial_lib_not_found
202 ui
.readconfig(hgdir
.File('hgrc').abspath
)
203 style_hook
= ui
.config('hooks', 'pretxncommit.style', None)
206 print mercurial_style_message
209 print ".hg directory not found"
211 main
['HG_INFO'] = hg_info
213 ###################################################
215 # Figure out which configurations to set up based on the path(s) of
218 ###################################################
220 # Find default configuration & binary.
221 Default(environ
.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
223 # helper function: find last occurrence of element in list
224 def rfind(l
, elt
, offs
= -1):
225 for i
in range(len(l
)+offs
, 0, -1):
228 raise ValueError, "element not found"
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.
236 # Generate absolute paths to targets so we can see where the build dir is
237 if 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
]
244 # Default targets are relative to root of tree
245 abs_targets
= [ normpath(joinpath(main
.root
.abspath
, str(x
))) for x
in \
249 # Generate a list of the unique build roots and configs that the
250 # collected targets reference.
253 for t
in abs_targets
:
254 path_dirs
= t
.split('/')
256 build_top
= rfind(path_dirs
, 'build', -2)
258 print "Error: no non-leaf 'build' dir found on target path", t
260 this_build_root
= joinpath('/',*path_dirs
[:build_top
+1])
262 build_root
= this_build_root
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
)
268 variant_path
= joinpath('/',*path_dirs
[:build_top
+2])
269 if variant_path
not in variant_paths
:
270 variant_paths
.append(variant_path
)
272 # Make sure build_root exists (might not if this is the first build there)
273 if not isdir(build_root
):
275 main
['BUILDROOT'] = build_root
279 main
.SConsignFile(joinpath(build_root
, "sconsign"))
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.
285 main
.SetOption('duplicate', 'soft-copy')
288 # Set up global sticky variables... these are common to an entire build
289 # tree (not specific to a particular build like ALPHA_SE)
292 # Variable validators & converters for global sticky variables
293 def PathListMakeAbsolute(val
):
296 f
= lambda p
: abspath(expanduser(p
))
297 return ':'.join(map(f
, val
.split(':')))
299 def PathListAllExist(key
, val
, env
):
302 paths
= val
.split(':')
305 raise SCons
.Errors
.UserError("Path does not exist: '%s'" % path
)
307 global_sticky_vars_file
= joinpath(build_root
, 'variables.global')
309 global_sticky_vars
= Variables(global_sticky_vars_file
, args
=ARGUMENTS
)
310 global_nonsticky_vars
= Variables(args
=ARGUMENTS
)
312 global_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
),
322 global_nonsticky_vars
.AddVariables(
323 ('VERBOSE', 'Print full tool command lines', False),
324 ('update_ref', 'Update test reference outputs', False)
330 Usage: scons [scons options] [build options] [target(s)]
332 Global sticky options:
335 # Update main environment with values from ARGUMENTS & global_sticky_vars_file
336 global_sticky_vars
.Update(main
)
337 global_nonsticky_vars
.Update(main
)
339 help_text
+= global_sticky_vars
.GenerateHelpText(main
)
340 help_text
+= global_nonsticky_vars
.GenerateHelpText(main
)
342 # Save sticky variable settings back to current variables file
343 global_sticky_vars
.Save(global_sticky_vars_file
, main
)
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.
347 base_dir
= main
.srcdir
.abspath
349 extras_dir_list
= main
['EXTRAS'].split(':')
354 Export('extras_dir_list')
356 # the ext directory should be on the #includes path
357 main
.Append(CPPPATH
=[Dir('ext')])
359 def _STRIP(path
, env
):
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/'):
368 def _STRIP_SOURCE(target
, source
, env
, for_signature
):
369 return _STRIP(source
[0], env
)
370 main
['STRIP_SOURCE'] = _STRIP_SOURCE
372 def _STRIP_TARGET(target
, source
, env
, for_signature
):
373 return _STRIP(target
[0], env
)
374 main
['STRIP_TARGET'] = _STRIP_TARGET
377 def MakeAction(action
, string
, *args
, **kwargs
):
378 return Action(action
, *args
, **kwargs
)
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'
393 CXX_version
= readCommand([main
['CXX'],'--version'], exception
=False)
394 CXX_V
= readCommand([main
['CXX'],'-V'], exception
=False)
396 main
['GCC'] = CXX_version
and CXX_version
.find('g++') >= 0
397 main
['SUNCC'] = CXX_V
and CXX_V
.find('Sun C++') >= 0
398 main
['ICC'] = CXX_V
and CXX_V
.find('Intel') >= 0
399 if main
['GCC'] + main
['SUNCC'] + main
['ICC'] > 1:
400 print 'Error: How can we have two at the same time?'
403 # Set up default C++ compiler flags
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'])
418 pass #Fix me... add warning flags once we clean up icc warnings
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'])
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.'
431 # Set up common yacc/bison flags (needed for Ruby)
432 main
['YACCFLAGS'] = '-d'
433 main
['YACCHXXFILESUFFIX'] = '.hh'
435 # Do this after we save setting back, or else we'll tack on an
436 # extra 'qdo' every time we run scons.
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']
444 if sys
.platform
== 'cygwin':
445 # cygwin has some header file issues...
446 main
.Append(CCFLAGS
=["-Wno-uninitialized"])
449 if not main
.has_key('SWIG'):
450 print 'Error: SWIG utility not found.'
451 print ' Please install (see http://www.swig.org) and retry.'
454 # Check for appropriate SWIG version
455 swig_version
= readCommand(('swig', '-version'), exception
='').split()
456 # First 3 words should be "SWIG Version x.y.z"
457 if len(swig_version
) < 3 or \
458 swig_version
[0] != 'SWIG' or swig_version
[1] != 'Version':
459 print 'Error determining SWIG version.'
462 min_swig_version
= '1.3.28'
463 if 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]
468 # Set up SWIG flags & scanner
469 swig_flags
=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
470 main
.Append(SWIGFLAGS
=swig_flags
)
472 # filter out all existing swig scanners, they mess up the dependency
473 # stuff for some reason
475 for scanner
in main
['SCANNERS']:
476 skeys
= scanner
.skeys
480 if isinstance(skeys
, (list, tuple)) and '.i' in skeys
:
483 scanners
.append(scanner
)
485 # add the new swig scanner that we like better
486 from SCons
.Scanner
import ClassicCPP
as CPPScanner
487 swig_inc_re
= '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
488 scanners
.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re
))
490 # replace the scanners list that has what we want
491 main
['SCANNERS'] = scanners
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.
497 def 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
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");
513 int main() { return x; }
515 context
.env
.Append(LEADING_UNDERSCORE
=ret
)
519 # Platform-specific configuration. Note again that we assume that all
520 # builds under a given build root run on the same host platform.
521 conf
= Configure(main
,
522 conf_dir
= joinpath(build_root
, '.scons_config'),
523 log_file
= joinpath(build_root
, 'scons_config.log'),
524 custom_tests
= { 'CheckLeading' : CheckLeading
})
526 # Check for leading underscores. Don't really need to worry either
527 # way so don't need to check the return code.
530 # Check if we should compile a 64 bit binary on Mac OS X/Darwin
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'])
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.
549 def NullCheck(*args
, **kwargs
):
553 def __init__(self
, env
):
557 def __getattr__(self
, mname
):
560 conf
= NullConf(main
)
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.
567 from distutils
import sysconfig
569 py_getvar
= sysconfig
.get_config_var
571 py_debug
= getattr(sys
, 'pydebug', False)
572 py_version
= 'python' + py_getvar('VERSION') + (py_debug
and "_d" or "")
574 py_general_include
= sysconfig
.get_python_inc()
575 py_platform_include
= sysconfig
.get_python_inc(plat_specific
=True)
576 py_includes
= [ py_general_include
]
577 if py_platform_include
!= py_general_include
:
578 py_includes
.append(py_platform_include
)
580 py_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/.
583 if not py_getvar('Py_ENABLE_SHARED'):
584 py_lib_path
.append(py_getvar('LIBPL'))
587 for lib
in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
588 assert lib
.startswith('-l')
590 if lib
not in py_libs
:
592 py_libs
.append(py_version
)
594 main
.Append(CPPPATH
=py_includes
)
595 main
.Append(LIBPATH
=py_lib_path
)
597 # Cache build files in the supplied directory.
598 if main
['M5_BUILD_CACHE']:
599 print 'Using build cache located at', main
['M5_BUILD_CACHE']
600 CacheDir(main
['M5_BUILD_CACHE'])
603 # verify that this stuff works
604 if not conf
.CheckHeader('Python.h', '<>'):
605 print "Error: can't find Python.h header in", py_includes
609 if not conf
.CheckLib(lib
):
610 print "Error: can't find library %s required by python" % lib
613 # On Solaris you need to use libsocket for socket ops
614 if 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())"
619 # Check for zlib. If the check passes, libz will be automatically
620 # added to the LIBS environment variable.
621 if 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.'
627 # Check for <fenv.h> (C99 FP environment control)
628 have_fenv
= conf
.CheckHeader('fenv.h', '<>')
630 print "Warning: Header file <fenv.h> not found."
631 print " This host has no IEEE FP rounding mode control."
633 ######################################################################
637 mysql_config
= WhereIs('mysql_config')
638 have_mysql
= bool(mysql_config
)
640 # Check MySQL version.
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.'
649 # Set up mysql_config commands.
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
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'
659 ######################################################################
661 # Finish the configuration
665 ######################################################################
667 # Collect all non-global variables
670 # Define the universe of supported ISAs
672 Export('all_isa_list')
674 class CpuModel(object):
675 '''The CpuModel class encapsulates everything the ISA parser needs to
676 know about a particular CPU model.'''
678 # Dict of available CPU model objects. Accessible as CpuModel.dict.
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
692 # This cpu is enabled by default
693 self
.default
= default
696 if name
in CpuModel
.dict:
697 raise AttributeError, "CpuModel '%s' already registered" % name
698 CpuModel
.dict[name
] = self
699 CpuModel
.list.append(name
)
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).
706 sticky_vars
= Variables(args
=ARGUMENTS
)
707 Export('sticky_vars')
709 # Sticky variables that should be exported
711 Export('export_vars')
713 # Walk the tree and execute all SConsopts scripts that wil add to the
715 for 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'))
723 sticky_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',
732 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
734 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
736 BoolVariable('SS_COMPATIBLE_FP',
737 'Make floating-point results compatible with SimpleScalar',
739 BoolVariable('USE_SSE2',
740 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
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),
749 # These variables get exported to #defines in config/*.hh (see src/SConscript).
750 export_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']
754 ###################################################
756 # Define a SCons builder for configuration flag headers.
758 ###################################################
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.
764 def 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
771 # Generate the message to be printed when building the config file.
772 def 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])
776 # Combine the two functions into a scons Action object.
777 config_action
= Action(build_config_file
, build_config_file_string
)
779 # The emitter munges the source & target node lists to reflect what
780 # we're really doing.
781 def 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')
787 if isinstance(val
, bool):
790 elif isinstance(val
, str):
791 val
= '"' + val
+ '"'
793 # Sources are variable name & value (packaged in SCons Value nodes)
794 return ([target
], [Value(variable
), Value(val
)])
796 config_builder
= Builder(emitter
= config_emitter
, action
= config_action
)
798 main
.Append(BUILDERS
= { 'ConfigFile' : config_builder
})
800 # libelf build is shared across all configs in the build root.
801 main
.SConscript('ext/libelf/SConscript',
802 variant_dir
= joinpath(build_root
, 'libelf'))
804 # gzstream build is shared across all configs in the build root.
805 main
.SConscript('ext/gzstream/SConscript',
806 variant_dir
= joinpath(build_root
, 'gzstream'))
808 ###################################################
810 # This function is used to set up a directory with switching headers
812 ###################################################
814 main
['ALL_ISA_LIST'] = all_isa_list
815 def 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])
822 isa
= env
['TARGET_ISA'].lower()
823 print >>f
, '#include "%s/%s/%s"' % (dname
, isa
, basename(fname
))
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.
829 switch_hdr_action
= MakeAction(gen_switch_hdr
,
830 " [GENERATE] $STRIP_TARGET", varlist
=['ALL_ISA_LIST'])
832 # Instantiate actions for each header
833 for hdr
in switch_headers
:
834 env
.Command(hdr
, [], switch_hdr_action
)
835 Export('make_switching_dir')
837 ###################################################
839 # Define build environments for selected configurations.
841 ###################################################
843 for variant_path
in variant_paths
:
844 print "Building in", variant_path
846 # Make a copy of the build-root environment to use for this config.
848 env
['BUILDDIR'] = variant_path
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
)
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
864 # Build dir-specific variables file doesn't exist.
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
):
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
)
881 print "Error: cannot find variables file %s or %s" \
882 % (current_vars_file
, default_vars_file
)
885 # Apply current variable settings to env
886 sticky_vars
.Update(env
)
888 help_text
+= "\nSticky variables for %s:\n" % variant_dir \
889 + sticky_vars
.GenerateHelpText(env
)
891 # Process variable settings.
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
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."
903 env
.Append(LIBS
=['efence'])
907 print "Warning: MySQL not available; " \
908 "forcing USE_MYSQL to False in", variant_dir
+ "."
909 env
['USE_MYSQL'] = False
911 print "Compiling in", variant_dir
, "with MySQL support."
912 env
.ParseConfig(mysql_config_libs
)
913 env
.ParseConfig(mysql_config_include
)
915 # Save sticky variable settings back to current variables file
916 sticky_vars
.Save(current_vars_file
, env
)
919 env
.Append(CCFLAGS
=['-msse2'])
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
,
927 # Set up the regression tests for each build.
929 SConscript('tests/SConscript',
930 variant_dir
= joinpath(variant_path
, 'tests', e
.Label
),
931 exports
= { 'env' : e
}, duplicate
= False)