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
):
278 main
.SConsignFile(joinpath(build_root
, "sconsign"))
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.
284 main
.SetOption('duplicate', 'soft-copy')
287 # Set up global sticky variables... these are common to an entire build
288 # tree (not specific to a particular build like ALPHA_SE)
291 # Variable validators & converters for global sticky variables
292 def PathListMakeAbsolute(val
):
295 f
= lambda p
: abspath(expanduser(p
))
296 return ':'.join(map(f
, val
.split(':')))
298 def PathListAllExist(key
, val
, env
):
301 paths
= val
.split(':')
304 raise SCons
.Errors
.UserError("Path does not exist: '%s'" % path
)
306 global_sticky_vars_file
= joinpath(build_root
, 'variables.global')
308 global_sticky_vars
= Variables(global_sticky_vars_file
, args
=ARGUMENTS
)
310 global_sticky_vars
.AddVariables(
311 ('CC', 'C compiler', environ
.get('CC', main
['CC'])),
312 ('CXX', 'C++ compiler', environ
.get('CXX', main
['CXX'])),
313 ('BATCH', 'Use batch pool for build and tests', False),
314 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
315 ('EXTRAS', 'Add Extra directories to the compilation', '',
316 PathListAllExist
, PathListMakeAbsolute
),
321 Usage: scons [scons options] [build options] [target(s)]
323 Global sticky options:
326 # Update main environment with values from ARGUMENTS & global_sticky_vars_file
327 global_sticky_vars
.Update(main
)
329 help_text
+= global_sticky_vars
.GenerateHelpText(main
)
331 # Save sticky variable settings back to current variables file
332 global_sticky_vars
.Save(global_sticky_vars_file
, main
)
334 # Parse EXTRAS variable to build list of all directories where we're
335 # look for sources etc. This list is exported as base_dir_list.
336 base_dir
= main
.srcdir
.abspath
338 extras_dir_list
= main
['EXTRAS'].split(':')
343 Export('extras_dir_list')
345 # the ext directory should be on the #includes path
346 main
.Append(CPPPATH
=[Dir('ext')])
348 CXX_version
= readCommand([main
['CXX'],'--version'], exception
=False)
349 CXX_V
= readCommand([main
['CXX'],'-V'], exception
=False)
351 main
['GCC'] = CXX_version
and CXX_version
.find('g++') >= 0
352 main
['SUNCC'] = CXX_V
and CXX_V
.find('Sun C++') >= 0
353 main
['ICC'] = CXX_V
and CXX_V
.find('Intel') >= 0
354 if main
['GCC'] + main
['SUNCC'] + main
['ICC'] > 1:
355 print 'Error: How can we have two at the same time?'
358 # Set up default C++ compiler flags
360 main
.Append(CCFLAGS
='-pipe')
361 main
.Append(CCFLAGS
='-fno-strict-aliasing')
362 main
.Append(CCFLAGS
=['-Wall', '-Wno-sign-compare', '-Wundef'])
363 main
.Append(CXXFLAGS
='-Wno-deprecated')
364 # Read the GCC version to check for versions with bugs
365 # Note CCVERSION doesn't work here because it is run with the CC
366 # before we override it from the command line
367 gcc_version
= readCommand([main
['CXX'], '-dumpversion'], exception
=False)
368 if not compareVersions(gcc_version
, '4.4.1') or \
369 not compareVersions(gcc_version
, '4.4.2'):
370 print 'Info: Tree vectorizer in GCC 4.4.1 & 4.4.2 is buggy, disabling.'
371 main
.Append(CCFLAGS
='-fno-tree-vectorize')
373 pass #Fix me... add warning flags once we clean up icc warnings
375 main
.Append(CCFLAGS
='-Qoption ccfe')
376 main
.Append(CCFLAGS
='-features=gcc')
377 main
.Append(CCFLAGS
='-features=extensions')
378 main
.Append(CCFLAGS
='-library=stlport4')
379 main
.Append(CCFLAGS
='-xar')
380 #main.Append(CCFLAGS='-instances=semiexplicit')
382 print 'Error: Don\'t know what compiler options to use for your compiler.'
383 print ' Please fix SConstruct and src/SConscript and try again.'
386 # Set up common yacc/bison flags (needed for Ruby)
387 main
['YACCFLAGS'] = '-d'
388 main
['YACCHXXFILESUFFIX'] = '.hh'
390 # Do this after we save setting back, or else we'll tack on an
391 # extra 'qdo' every time we run scons.
393 main
['CC'] = main
['BATCH_CMD'] + ' ' + main
['CC']
394 main
['CXX'] = main
['BATCH_CMD'] + ' ' + main
['CXX']
395 main
['AS'] = main
['BATCH_CMD'] + ' ' + main
['AS']
396 main
['AR'] = main
['BATCH_CMD'] + ' ' + main
['AR']
397 main
['RANLIB'] = main
['BATCH_CMD'] + ' ' + main
['RANLIB']
399 if sys
.platform
== 'cygwin':
400 # cygwin has some header file issues...
401 main
.Append(CCFLAGS
="-Wno-uninitialized")
404 if not main
.has_key('SWIG'):
405 print 'Error: SWIG utility not found.'
406 print ' Please install (see http://www.swig.org) and retry.'
409 # Check for appropriate SWIG version
410 swig_version
= readCommand(('swig', '-version'), exception
='').split()
411 # First 3 words should be "SWIG Version x.y.z"
412 if len(swig_version
) < 3 or \
413 swig_version
[0] != 'SWIG' or swig_version
[1] != 'Version':
414 print 'Error determining SWIG version.'
417 min_swig_version
= '1.3.28'
418 if compareVersions(swig_version
[2], min_swig_version
) < 0:
419 print 'Error: SWIG version', min_swig_version
, 'or newer required.'
420 print ' Installed version:', swig_version
[2]
423 # Set up SWIG flags & scanner
424 swig_flags
=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
425 main
.Append(SWIGFLAGS
=swig_flags
)
427 # filter out all existing swig scanners, they mess up the dependency
428 # stuff for some reason
430 for scanner
in main
['SCANNERS']:
431 skeys
= scanner
.skeys
435 if isinstance(skeys
, (list, tuple)) and '.i' in skeys
:
438 scanners
.append(scanner
)
440 # add the new swig scanner that we like better
441 from SCons
.Scanner
import ClassicCPP
as CPPScanner
442 swig_inc_re
= '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
443 scanners
.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re
))
445 # replace the scanners list that has what we want
446 main
['SCANNERS'] = scanners
448 # Add a custom Check function to the Configure context so that we can
449 # figure out if the compiler adds leading underscores to global
450 # variables. This is needed for the autogenerated asm files that we
451 # use for embedding the python code.
452 def CheckLeading(context
):
453 context
.Message("Checking for leading underscore in global variables...")
454 # 1) Define a global variable called x from asm so the C compiler
455 # won't change the symbol at all.
456 # 2) Declare that variable.
457 # 3) Use the variable
459 # If the compiler prepends an underscore, this will successfully
460 # link because the external symbol 'x' will be called '_x' which
461 # was defined by the asm statement. If the compiler does not
462 # prepend an underscore, this will not successfully link because
463 # '_x' will have been defined by assembly, while the C portion of
464 # the code will be trying to use 'x'
465 ret
= context
.TryLink('''
466 asm(".globl _x; _x: .byte 0");
468 int main() { return x; }
470 context
.env
.Append(LEADING_UNDERSCORE
=ret
)
474 # Platform-specific configuration. Note again that we assume that all
475 # builds under a given build root run on the same host platform.
476 conf
= Configure(main
,
477 conf_dir
= joinpath(build_root
, '.scons_config'),
478 log_file
= joinpath(build_root
, 'scons_config.log'),
479 custom_tests
= { 'CheckLeading' : CheckLeading
})
481 # Check for leading underscores. Don't really need to worry either
482 # way so don't need to check the return code.
485 # Check if we should compile a 64 bit binary on Mac OS X/Darwin
488 uname
= platform
.uname()
489 if uname
[0] == 'Darwin' and compareVersions(uname
[2], '9.0.0') >= 0:
490 if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]):
491 main
.Append(CCFLAGS
='-arch x86_64')
492 main
.Append(CFLAGS
='-arch x86_64')
493 main
.Append(LINKFLAGS
='-arch x86_64')
494 main
.Append(ASFLAGS
='-arch x86_64')
498 # Recent versions of scons substitute a "Null" object for Configure()
499 # when configuration isn't necessary, e.g., if the "--help" option is
500 # present. Unfortuantely this Null object always returns false,
501 # breaking all our configuration checks. We replace it with our own
502 # more optimistic null object that returns True instead.
504 def NullCheck(*args
, **kwargs
):
508 def __init__(self
, env
):
512 def __getattr__(self
, mname
):
515 conf
= NullConf(main
)
517 # Find Python include and library directories for embedding the
518 # interpreter. For consistency, we will use the same Python
519 # installation used to run scons (and thus this script). If you want
520 # to link in an alternate version, see above for instructions on how
521 # to invoke scons with a different copy of the Python interpreter.
522 from distutils
import sysconfig
524 py_getvar
= sysconfig
.get_config_var
526 py_debug
= getattr(sys
, 'pydebug', False)
527 py_version
= 'python' + py_getvar('VERSION') + (py_debug
and "_d" or "")
529 py_general_include
= sysconfig
.get_python_inc()
530 py_platform_include
= sysconfig
.get_python_inc(plat_specific
=True)
531 py_includes
= [ py_general_include
]
532 if py_platform_include
!= py_general_include
:
533 py_includes
.append(py_platform_include
)
535 py_lib_path
= [ py_getvar('LIBDIR') ]
536 # add the prefix/lib/pythonX.Y/config dir, but only if there is no
537 # shared library in prefix/lib/.
538 if not py_getvar('Py_ENABLE_SHARED'):
539 py_lib_path
.append(py_getvar('LIBPL'))
542 for lib
in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
543 assert lib
.startswith('-l')
545 if lib
not in py_libs
:
547 py_libs
.append(py_version
)
549 main
.Append(CPPPATH
=py_includes
)
550 main
.Append(LIBPATH
=py_lib_path
)
552 # verify that this stuff works
553 if not conf
.CheckHeader('Python.h', '<>'):
554 print "Error: can't find Python.h header in", py_includes
558 if not conf
.CheckLib(lib
):
559 print "Error: can't find library %s required by python" % lib
562 # On Solaris you need to use libsocket for socket ops
563 if not conf
.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
564 if not conf
.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
565 print "Can't find library with socket calls (e.g. accept())"
568 # Check for zlib. If the check passes, libz will be automatically
569 # added to the LIBS environment variable.
570 if not conf
.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
571 print 'Error: did not find needed zlib compression library '\
572 'and/or zlib.h header file.'
573 print ' Please install zlib and try again.'
576 # Check for <fenv.h> (C99 FP environment control)
577 have_fenv
= conf
.CheckHeader('fenv.h', '<>')
579 print "Warning: Header file <fenv.h> not found."
580 print " This host has no IEEE FP rounding mode control."
582 ######################################################################
586 mysql_config
= WhereIs('mysql_config')
587 have_mysql
= bool(mysql_config
)
589 # Check MySQL version.
591 mysql_version
= readCommand(mysql_config
+ ' --version')
592 min_mysql_version
= '4.1'
593 if compareVersions(mysql_version
, min_mysql_version
) < 0:
594 print 'Warning: MySQL', min_mysql_version
, 'or newer required.'
595 print ' Version', mysql_version
, 'detected.'
598 # Set up mysql_config commands.
600 mysql_config_include
= mysql_config
+ ' --include'
601 if os
.system(mysql_config_include
+ ' > /dev/null') != 0:
602 # older mysql_config versions don't support --include, use
604 mysql_config_include
= mysql_config
+ ' --cflags | sed s/\\\'//g'
605 # This seems to work in all versions
606 mysql_config_libs
= mysql_config
+ ' --libs'
608 ######################################################################
610 # Finish the configuration
614 ######################################################################
616 # Collect all non-global variables
619 # Define the universe of supported ISAs
621 Export('all_isa_list')
623 class CpuModel(object):
624 '''The CpuModel class encapsulates everything the ISA parser needs to
625 know about a particular CPU model.'''
627 # Dict of available CPU model objects. Accessible as CpuModel.dict.
632 # Constructor. Automatically adds models to CpuModel.dict.
633 def __init__(self
, name
, filename
, includes
, strings
, default
=False):
634 self
.name
= name
# name of model
635 self
.filename
= filename
# filename for output exec code
636 self
.includes
= includes
# include files needed in exec file
637 # The 'strings' dict holds all the per-CPU symbols we can
638 # substitute into templates etc.
639 self
.strings
= strings
641 # This cpu is enabled by default
642 self
.default
= default
645 if name
in CpuModel
.dict:
646 raise AttributeError, "CpuModel '%s' already registered" % name
647 CpuModel
.dict[name
] = self
648 CpuModel
.list.append(name
)
652 # Sticky variables get saved in the variables file so they persist from
653 # one invocation to the next (unless overridden, in which case the new
654 # value becomes sticky).
655 sticky_vars
= Variables(args
=ARGUMENTS
)
656 Export('sticky_vars')
658 # Sticky variables that should be exported
660 Export('export_vars')
662 # Non-sticky variables only apply to the current build.
663 nonsticky_vars
= Variables(args
=ARGUMENTS
)
664 Export('nonsticky_vars')
666 # Walk the tree and execute all SConsopts scripts that wil add to the
668 for bdir
in [ base_dir
] + extras_dir_list
:
669 for root
, dirs
, files
in os
.walk(bdir
):
670 if 'SConsopts' in files
:
671 print "Reading", joinpath(root
, 'SConsopts')
672 SConscript(joinpath(root
, 'SConsopts'))
676 sticky_vars
.AddVariables(
677 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list
),
678 BoolVariable('FULL_SYSTEM', 'Full-system support', False),
679 ListVariable('CPU_MODELS', 'CPU models',
680 sorted(n
for n
,m
in CpuModel
.dict.iteritems() if m
.default
),
681 sorted(CpuModel
.list)),
682 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
683 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
685 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
687 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
689 BoolVariable('SS_COMPATIBLE_FP',
690 'Make floating-point results compatible with SimpleScalar',
692 BoolVariable('USE_SSE2',
693 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
695 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql
),
696 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv
),
697 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
698 BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False),
699 BoolVariable('RUBY', 'Build with Ruby', False),
702 nonsticky_vars
.AddVariables(
703 BoolVariable('update_ref', 'Update test reference outputs', False)
706 # These variables get exported to #defines in config/*.hh (see src/SConscript).
707 export_vars
+= ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL',
708 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS',
709 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE']
711 ###################################################
713 # Define a SCons builder for configuration flag headers.
715 ###################################################
717 # This function generates a config header file that #defines the
718 # variable symbol to the current variable setting (0 or 1). The source
719 # operands are the name of the variable and a Value node containing the
720 # value of the variable.
721 def build_config_file(target
, source
, env
):
722 (variable
, value
) = [s
.get_contents() for s
in source
]
723 f
= file(str(target
[0]), 'w')
724 print >> f
, '#define', variable
, value
728 # Generate the message to be printed when building the config file.
729 def build_config_file_string(target
, source
, env
):
730 (variable
, value
) = [s
.get_contents() for s
in source
]
731 return "Defining %s as %s in %s." % (variable
, value
, target
[0])
733 # Combine the two functions into a scons Action object.
734 config_action
= Action(build_config_file
, build_config_file_string
)
736 # The emitter munges the source & target node lists to reflect what
737 # we're really doing.
738 def config_emitter(target
, source
, env
):
739 # extract variable name from Builder arg
740 variable
= str(target
[0])
741 # True target is config header file
742 target
= joinpath('config', variable
.lower() + '.hh')
744 if isinstance(val
, bool):
747 elif isinstance(val
, str):
748 val
= '"' + val
+ '"'
750 # Sources are variable name & value (packaged in SCons Value nodes)
751 return ([target
], [Value(variable
), Value(val
)])
753 config_builder
= Builder(emitter
= config_emitter
, action
= config_action
)
755 main
.Append(BUILDERS
= { 'ConfigFile' : config_builder
})
757 # libelf build is shared across all configs in the build root.
758 main
.SConscript('ext/libelf/SConscript',
759 variant_dir
= joinpath(build_root
, 'libelf'))
761 # gzstream build is shared across all configs in the build root.
762 main
.SConscript('ext/gzstream/SConscript',
763 variant_dir
= joinpath(build_root
, 'gzstream'))
765 ###################################################
767 # This function is used to set up a directory with switching headers
769 ###################################################
771 main
['ALL_ISA_LIST'] = all_isa_list
772 def make_switching_dir(dname
, switch_headers
, env
):
773 # Generate the header. target[0] is the full path of the output
774 # header to generate. 'source' is a dummy variable, since we get the
775 # list of ISAs from env['ALL_ISA_LIST'].
776 def gen_switch_hdr(target
, source
, env
):
777 fname
= str(target
[0])
779 isa
= env
['TARGET_ISA'].lower()
780 print >>f
, '#include "%s/%s/%s"' % (dname
, isa
, basename(fname
))
783 # String to print when generating header
784 def gen_switch_hdr_string(target
, source
, env
):
785 return "Generating switch header " + str(target
[0])
787 # Build SCons Action object. 'varlist' specifies env vars that this
788 # action depends on; when env['ALL_ISA_LIST'] changes these actions
789 # should get re-executed.
790 switch_hdr_action
= Action(gen_switch_hdr
, gen_switch_hdr_string
,
791 varlist
=['ALL_ISA_LIST'])
793 # Instantiate actions for each header
794 for hdr
in switch_headers
:
795 env
.Command(hdr
, [], switch_hdr_action
)
796 Export('make_switching_dir')
798 ###################################################
800 # Define build environments for selected configurations.
802 ###################################################
804 for variant_path
in variant_paths
:
805 print "Building in", variant_path
807 # Make a copy of the build-root environment to use for this config.
809 env
['BUILDDIR'] = variant_path
811 # variant_dir is the tail component of build path, and is used to
812 # determine the build parameters (e.g., 'ALPHA_SE')
813 (build_root
, variant_dir
) = splitpath(variant_path
)
815 # Set env variables according to the build directory config.
816 sticky_vars
.files
= []
817 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
818 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
819 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
820 current_vars_file
= joinpath(build_root
, 'variables', variant_dir
)
821 if isfile(current_vars_file
):
822 sticky_vars
.files
.append(current_vars_file
)
823 print "Using saved variables file %s" % current_vars_file
825 # Build dir-specific variables file doesn't exist.
827 # Make sure the directory is there so we can create it later
828 opt_dir
= dirname(current_vars_file
)
829 if not isdir(opt_dir
):
832 # Get default build variables from source tree. Variables are
833 # normally determined by name of $VARIANT_DIR, but can be
834 # overriden by 'default=' arg on command line.
835 default_vars_file
= joinpath('build_opts',
836 ARGUMENTS
.get('default', variant_dir
))
837 if isfile(default_vars_file
):
838 sticky_vars
.files
.append(default_vars_file
)
839 print "Variables file %s not found,\n using defaults in %s" \
840 % (current_vars_file
, default_vars_file
)
842 print "Error: cannot find variables file %s or %s" \
843 % (current_vars_file
, default_vars_file
)
846 # Apply current variable settings to env
847 sticky_vars
.Update(env
)
848 nonsticky_vars
.Update(env
)
850 help_text
+= "\nSticky variables for %s:\n" % variant_dir \
851 + sticky_vars
.GenerateHelpText(env
) \
852 + "\nNon-sticky variables for %s:\n" % variant_dir \
853 + nonsticky_vars
.GenerateHelpText(env
)
855 # Process variable settings.
857 if not have_fenv
and env
['USE_FENV']:
858 print "Warning: <fenv.h> not available; " \
859 "forcing USE_FENV to False in", variant_dir
+ "."
860 env
['USE_FENV'] = False
862 if not env
['USE_FENV']:
863 print "Warning: No IEEE FP rounding mode control in", variant_dir
+ "."
864 print " FP results may deviate slightly from other platforms."
867 env
.Append(LIBS
=['efence'])
871 print "Warning: MySQL not available; " \
872 "forcing USE_MYSQL to False in", variant_dir
+ "."
873 env
['USE_MYSQL'] = False
875 print "Compiling in", variant_dir
, "with MySQL support."
876 env
.ParseConfig(mysql_config_libs
)
877 env
.ParseConfig(mysql_config_include
)
879 # Save sticky variable settings back to current variables file
880 sticky_vars
.Save(current_vars_file
, env
)
883 env
.Append(CCFLAGS
='-msse2')
885 # The src/SConscript file sets up the build rules in 'env' according
886 # to the configured variables. It returns a list of environments,
887 # one for each variant build (debug, opt, etc.)
888 envList
= SConscript('src/SConscript', variant_dir
= variant_path
,
891 # Set up the regression tests for each build.
893 SConscript('tests/SConscript',
894 variant_dir
= joinpath(variant_path
, 'tests', e
.Label
),
895 exports
= { 'env' : e
}, duplicate
= False)