e65c2da39a2257704f282e1c70b62564565dc7d2
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
104 from os
import mkdir
, environ
105 from os
.path
import abspath
, basename
, dirname
, expanduser
, normpath
106 from os
.path
import exists
, isdir
, isfile
107 from os
.path
import join
as joinpath
, split
as splitpath
112 def read_command(cmd
, **kwargs
):
113 """run the command cmd, read the results and return them
114 this is sorta like `cmd` in shell"""
115 from subprocess
import Popen
, PIPE
, STDOUT
117 no_exception
= 'exception' in kwargs
118 exception
= kwargs
.pop('exception', None)
120 kwargs
.setdefault('shell', False)
121 kwargs
.setdefault('stdout', PIPE
)
122 kwargs
.setdefault('stderr', STDOUT
)
123 kwargs
.setdefault('close_fds', True)
125 subp
= Popen(cmd
, **kwargs
)
131 return subp
.communicate()[0]
133 # helper function: compare arrays or strings of version numbers.
134 # E.g., compare_version((1,3,25), (1,4,1)')
135 # returns -1, 0, 1 if v1 is <, ==, > v2
136 def compare_versions(v1
, v2
):
137 def make_version_list(v
):
138 if isinstance(v
, (list,tuple)):
140 elif isinstance(v
, str):
141 return map(lambda x
: int(re
.match('\d+', x
).group()), v
.split('.'))
145 v1
= make_version_list(v1
)
146 v2
= make_version_list(v2
)
147 # Compare corresponding elements of lists
148 for n1
,n2
in zip(v1
, v2
):
149 if n1
< n2
: return -1
151 # all corresponding values are equal... see if one has extra values
152 if len(v1
) < len(v2
): return -1
153 if len(v1
) > len(v2
): return 1
156 ########################################################################
158 # Set up the base build environment.
160 ########################################################################
161 use_vars
= set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'PATH', 'RANLIB' ])
164 for key
,val
in os
.environ
.iteritems():
165 if key
in use_vars
or key
.startswith("M5"):
168 env
= Environment(ENV
=use_env
)
169 env
.root
= Dir(".") # The current directory (where this file lives).
170 env
.srcdir
= Dir("src") # The source directory
172 ########################################################################
176 # If the M5 directory is a mercurial repository, we should do some
179 ########################################################################
181 hgdir
= env
.root
.Dir(".hg")
183 mercurial_style_message
= """
184 You're missing the M5 style hook.
185 Please install the hook so we can ensure that all code fits a common style.
187 All you'd need to do is add the following lines to your repository .hg/hgrc
188 or your personal .hgrc
192 style = %s/util/style.py
195 pretxncommit.style = python:style.check_whitespace
198 mercurial_bin_not_found
= """
199 Mercurial binary cannot be found, unfortunately this means that we
200 cannot easily determine the version of M5 that you are running and
201 this makes error messages more difficult to collect. Please consider
202 installing mercurial if you choose to post an error message
205 mercurial_lib_not_found
= """
206 Mercurial libraries cannot be found, ignoring style hook
207 If you are actually a M5 developer, please fix this and
208 run the style hook. It is important.
212 # 1) Grab repository revision if we know it.
213 cmd
= "hg id -n -i -t -b"
215 hg_info
= read_command(cmd
, cwd
=env
.root
.abspath
).strip()
218 print mercurial_bin_not_found
220 env
['HG_INFO'] = hg_info
222 # 2) Ensure that the style hook is in place.
225 if ARGUMENTS
.get('IGNORE_STYLE') != 'True':
226 from mercurial
import ui
229 print mercurial_lib_not_found
232 ui
.readconfig(hgdir
.File('hgrc').abspath
)
233 style_hook
= ui
.config('hooks', 'pretxncommit.style', None)
236 print mercurial_style_message
239 print ".hg directory not found"
241 ###################################################
243 # Figure out which configurations to set up based on the path(s) of
246 ###################################################
248 # Find default configuration & binary.
249 Default(environ
.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
251 # helper function: find last occurrence of element in list
252 def rfind(l
, elt
, offs
= -1):
253 for i
in range(len(l
)+offs
, 0, -1):
256 raise ValueError, "element not found"
258 # Each target must have 'build' in the interior of the path; the
259 # directory below this will determine the build parameters. For
260 # example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
261 # recognize that ALPHA_SE specifies the configuration because it
262 # follow 'build' in the bulid path.
264 # Generate absolute paths to targets so we can see where the build dir is
265 if COMMAND_LINE_TARGETS
:
266 # Ask SCons which directory it was invoked from
267 launch_dir
= GetLaunchDir()
268 # Make targets relative to invocation directory
269 abs_targets
= [ normpath(joinpath(launch_dir
, str(x
))) for x
in \
270 COMMAND_LINE_TARGETS
]
272 # Default targets are relative to root of tree
273 abs_targets
= [ normpath(joinpath(ROOT
, str(x
))) for x
in \
277 # Generate a list of the unique build roots and configs that the
278 # collected targets reference.
281 for t
in abs_targets
:
282 path_dirs
= t
.split('/')
284 build_top
= rfind(path_dirs
, 'build', -2)
286 print "Error: no non-leaf 'build' dir found on target path", t
288 this_build_root
= joinpath('/',*path_dirs
[:build_top
+1])
290 build_root
= this_build_root
292 if this_build_root
!= build_root
:
293 print "Error: build targets not under same build root\n"\
294 " %s\n %s" % (build_root
, this_build_root
)
296 variant_path
= joinpath('/',*path_dirs
[:build_top
+2])
297 if variant_path
not in variant_paths
:
298 variant_paths
.append(variant_path
)
300 # Make sure build_root exists (might not if this is the first build there)
301 if not isdir(build_root
):
306 env
.SConsignFile(joinpath(build_root
, "sconsign"))
308 # Default duplicate option is to use hard links, but this messes up
309 # when you use emacs to edit a file in the target dir, as emacs moves
310 # file to file~ then copies to file, breaking the link. Symbolic
311 # (soft) links work better.
312 env
.SetOption('duplicate', 'soft-copy')
315 # Set up global sticky variables... these are common to an entire build
316 # tree (not specific to a particular build like ALPHA_SE)
319 # Variable validators & converters for global sticky variables
320 def PathListMakeAbsolute(val
):
323 f
= lambda p
: abspath(expanduser(p
))
324 return ':'.join(map(f
, val
.split(':')))
326 def PathListAllExist(key
, val
, env
):
329 paths
= val
.split(':')
332 raise SCons
.Errors
.UserError("Path does not exist: '%s'" % path
)
334 global_sticky_vars_file
= joinpath(build_root
, 'variables.global')
336 global_sticky_vars
= Variables(global_sticky_vars_file
, args
=ARGUMENTS
)
338 global_sticky_vars
.AddVariables(
339 ('CC', 'C compiler', environ
.get('CC', env
['CC'])),
340 ('CXX', 'C++ compiler', environ
.get('CXX', env
['CXX'])),
341 ('BATCH', 'Use batch pool for build and tests', False),
342 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
343 ('EXTRAS', 'Add Extra directories to the compilation', '',
344 PathListAllExist
, PathListMakeAbsolute
)
349 Usage: scons [scons options] [build options] [target(s)]
351 Global sticky options:
354 help_text
+= global_sticky_vars
.GenerateHelpText(env
)
356 # Update env with values from ARGUMENTS & file global_sticky_vars_file
357 global_sticky_vars
.Update(env
)
359 # Save sticky variable settings back to current variables file
360 global_sticky_vars
.Save(global_sticky_vars_file
, env
)
362 # Parse EXTRAS variable to build list of all directories where we're
363 # look for sources etc. This list is exported as base_dir_list.
364 base_dir
= env
.srcdir
.abspath
366 extras_dir_list
= env
['EXTRAS'].split(':')
371 Export('extras_dir_list')
373 # M5_PLY is used by isa_parser.py to find the PLY package.
374 env
.Append(ENV
= { 'M5_PLY' : str(Dir('ext/ply')) })
376 CXX_version
= read_command([env
['CXX'],'--version'], exception
=False)
377 CXX_V
= read_command([env
['CXX'],'-V'], exception
=False)
379 env
['GCC'] = CXX_version
and CXX_version
.find('g++') >= 0
380 env
['SUNCC'] = CXX_V
and CXX_V
.find('Sun C++') >= 0
381 env
['ICC'] = CXX_V
and CXX_V
.find('Intel') >= 0
382 if env
['GCC'] + env
['SUNCC'] + env
['ICC'] > 1:
383 print 'Error: How can we have two at the same time?'
386 # Set up default C++ compiler flags
388 env
.Append(CCFLAGS
='-pipe')
389 env
.Append(CCFLAGS
='-fno-strict-aliasing')
390 env
.Append(CCFLAGS
=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
391 env
.Append(CXXFLAGS
='-Wno-deprecated')
393 pass #Fix me... add warning flags once we clean up icc warnings
395 env
.Append(CCFLAGS
='-Qoption ccfe')
396 env
.Append(CCFLAGS
='-features=gcc')
397 env
.Append(CCFLAGS
='-features=extensions')
398 env
.Append(CCFLAGS
='-library=stlport4')
399 env
.Append(CCFLAGS
='-xar')
400 #env.Append(CCFLAGS='-instances=semiexplicit')
402 print 'Error: Don\'t know what compiler options to use for your compiler.'
403 print ' Please fix SConstruct and src/SConscript and try again.'
406 # Do this after we save setting back, or else we'll tack on an
407 # extra 'qdo' every time we run scons.
409 env
['CC'] = env
['BATCH_CMD'] + ' ' + env
['CC']
410 env
['CXX'] = env
['BATCH_CMD'] + ' ' + env
['CXX']
411 env
['AS'] = env
['BATCH_CMD'] + ' ' + env
['AS']
412 env
['AR'] = env
['BATCH_CMD'] + ' ' + env
['AR']
413 env
['RANLIB'] = env
['BATCH_CMD'] + ' ' + env
['RANLIB']
415 if sys
.platform
== 'cygwin':
416 # cygwin has some header file issues...
417 env
.Append(CCFLAGS
=Split("-Wno-uninitialized"))
418 env
.Append(CPPPATH
=[Dir('ext/dnet')])
421 if not env
.has_key('SWIG'):
422 print 'Error: SWIG utility not found.'
423 print ' Please install (see http://www.swig.org) and retry.'
426 # Check for appropriate SWIG version
427 swig_version
= read_command(('swig', '-version'), exception
='').split()
428 # First 3 words should be "SWIG Version x.y.z"
429 if len(swig_version
) < 3 or \
430 swig_version
[0] != 'SWIG' or swig_version
[1] != 'Version':
431 print 'Error determining SWIG version.'
434 min_swig_version
= '1.3.28'
435 if compare_versions(swig_version
[2], min_swig_version
) < 0:
436 print 'Error: SWIG version', min_swig_version
, 'or newer required.'
437 print ' Installed version:', swig_version
[2]
440 # Set up SWIG flags & scanner
441 swig_flags
=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
442 env
.Append(SWIGFLAGS
=swig_flags
)
444 # filter out all existing swig scanners, they mess up the dependency
445 # stuff for some reason
447 for scanner
in env
['SCANNERS']:
448 skeys
= scanner
.skeys
452 if isinstance(skeys
, (list, tuple)) and '.i' in skeys
:
455 scanners
.append(scanner
)
457 # add the new swig scanner that we like better
458 from SCons
.Scanner
import ClassicCPP
as CPPScanner
459 swig_inc_re
= '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
460 scanners
.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re
))
462 # replace the scanners list that has what we want
463 env
['SCANNERS'] = scanners
465 # Add a custom Check function to the Configure context so that we can
466 # figure out if the compiler adds leading underscores to global
467 # variables. This is needed for the autogenerated asm files that we
468 # use for embedding the python code.
469 def CheckLeading(context
):
470 context
.Message("Checking for leading underscore in global variables...")
471 # 1) Define a global variable called x from asm so the C compiler
472 # won't change the symbol at all.
473 # 2) Declare that variable.
474 # 3) Use the variable
476 # If the compiler prepends an underscore, this will successfully
477 # link because the external symbol 'x' will be called '_x' which
478 # was defined by the asm statement. If the compiler does not
479 # prepend an underscore, this will not successfully link because
480 # '_x' will have been defined by assembly, while the C portion of
481 # the code will be trying to use 'x'
482 ret
= context
.TryLink('''
483 asm(".globl _x; _x: .byte 0");
485 int main() { return x; }
487 context
.env
.Append(LEADING_UNDERSCORE
=ret
)
491 # Platform-specific configuration. Note again that we assume that all
492 # builds under a given build root run on the same host platform.
493 conf
= Configure(env
,
494 conf_dir
= joinpath(build_root
, '.scons_config'),
495 log_file
= joinpath(build_root
, 'scons_config.log'),
496 custom_tests
= { 'CheckLeading' : CheckLeading
})
498 # Check for leading underscores. Don't really need to worry either
499 # way so don't need to check the return code.
502 # Check if we should compile a 64 bit binary on Mac OS X/Darwin
505 uname
= platform
.uname()
506 if uname
[0] == 'Darwin' and compare_versions(uname
[2], '9.0.0') >= 0:
507 if int(read_command('sysctl -n hw.cpu64bit_capable')[0]):
508 env
.Append(CCFLAGS
='-arch x86_64')
509 env
.Append(CFLAGS
='-arch x86_64')
510 env
.Append(LINKFLAGS
='-arch x86_64')
511 env
.Append(ASFLAGS
='-arch x86_64')
515 # Recent versions of scons substitute a "Null" object for Configure()
516 # when configuration isn't necessary, e.g., if the "--help" option is
517 # present. Unfortuantely this Null object always returns false,
518 # breaking all our configuration checks. We replace it with our own
519 # more optimistic null object that returns True instead.
521 def NullCheck(*args
, **kwargs
):
525 def __init__(self
, env
):
529 def __getattr__(self
, mname
):
534 # Find Python include and library directories for embedding the
535 # interpreter. For consistency, we will use the same Python
536 # installation used to run scons (and thus this script). If you want
537 # to link in an alternate version, see above for instructions on how
538 # to invoke scons with a different copy of the Python interpreter.
539 from distutils
import sysconfig
541 py_getvar
= sysconfig
.get_config_var
543 py_version
= 'python' + py_getvar('VERSION')
545 py_general_include
= sysconfig
.get_python_inc()
546 py_platform_include
= sysconfig
.get_python_inc(plat_specific
=True)
547 py_includes
= [ py_general_include
]
548 if py_platform_include
!= py_general_include
:
549 py_includes
.append(py_platform_include
)
552 # add the prefix/lib/pythonX.Y/config dir, but only if there is no
553 # shared library in prefix/lib/.
554 if not py_getvar('Py_ENABLE_SHARED'):
555 py_lib_path
.append('-L' + py_getvar('LIBPL'))
558 for lib
in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
559 if lib
not in py_libs
:
561 py_libs
.append('-l' + py_version
)
563 env
.Append(CPPPATH
=py_includes
)
564 env
.Append(LIBPATH
=py_lib_path
)
565 #env.Append(LIBS=py_libs)
567 # verify that this stuff works
568 if not conf
.CheckHeader('Python.h', '<>'):
569 print "Error: can't find Python.h header in", py_includes
573 assert lib
.startswith('-l')
575 if not conf
.CheckLib(lib
):
576 print "Error: can't find library %s required by python" % lib
579 # On Solaris you need to use libsocket for socket ops
580 if not conf
.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
581 if not conf
.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
582 print "Can't find library with socket calls (e.g. accept())"
585 # Check for zlib. If the check passes, libz will be automatically
586 # added to the LIBS environment variable.
587 if not conf
.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
588 print 'Error: did not find needed zlib compression library '\
589 'and/or zlib.h header file.'
590 print ' Please install zlib and try again.'
593 # Check for <fenv.h> (C99 FP environment control)
594 have_fenv
= conf
.CheckHeader('fenv.h', '<>')
596 print "Warning: Header file <fenv.h> not found."
597 print " This host has no IEEE FP rounding mode control."
599 ######################################################################
603 mysql_config
= WhereIs('mysql_config')
604 have_mysql
= bool(mysql_config
)
606 # Check MySQL version.
608 mysql_version
= read_command(mysql_config
+ ' --version')
609 min_mysql_version
= '4.1'
610 if compare_versions(mysql_version
, min_mysql_version
) < 0:
611 print 'Warning: MySQL', min_mysql_version
, 'or newer required.'
612 print ' Version', mysql_version
, 'detected.'
615 # Set up mysql_config commands.
617 mysql_config_include
= mysql_config
+ ' --include'
618 if os
.system(mysql_config_include
+ ' > /dev/null') != 0:
619 # older mysql_config versions don't support --include, use
621 mysql_config_include
= mysql_config
+ ' --cflags | sed s/\\\'//g'
622 # This seems to work in all versions
623 mysql_config_libs
= mysql_config
+ ' --libs'
625 ######################################################################
627 # Finish the configuration
631 ######################################################################
633 # Collect all non-global variables
638 # Define the universe of supported ISAs
640 Export('all_isa_list')
642 # Define the universe of supported CPU models
645 Export('all_cpu_list', 'default_cpus')
647 # Sticky variables get saved in the variables file so they persist from
648 # one invocation to the next (unless overridden, in which case the new
649 # value becomes sticky).
650 sticky_vars
= Variables(args
=ARGUMENTS
)
651 Export('sticky_vars')
653 # Non-sticky variables only apply to the current build.
654 nonsticky_vars
= Variables(args
=ARGUMENTS
)
655 Export('nonsticky_vars')
657 # Walk the tree and execute all SConsopts scripts that wil add to the
659 for bdir
in [ base_dir
] + extras_dir_list
:
660 for root
, dirs
, files
in os
.walk(bdir
):
661 if 'SConsopts' in files
:
662 print "Reading", joinpath(root
, 'SConsopts')
663 SConscript(joinpath(root
, 'SConsopts'))
669 sticky_vars
.AddVariables(
670 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list
),
671 BoolVariable('FULL_SYSTEM', 'Full-system support', False),
672 ListVariable('CPU_MODELS', 'CPU models', default_cpus
, all_cpu_list
),
673 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
674 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
676 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
678 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
680 BoolVariable('SS_COMPATIBLE_FP',
681 'Make floating-point results compatible with SimpleScalar',
683 BoolVariable('USE_SSE2',
684 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
686 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql
),
687 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv
),
688 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
691 nonsticky_vars
.AddVariables(
692 BoolVariable('update_ref', 'Update test reference outputs', False)
695 # These variables get exported to #defines in config/*.hh (see src/SConscript).
696 env
.ExportVariables
= ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
697 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \
698 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \
699 'USE_CHECKER', 'TARGET_ISA']
701 ###################################################
703 # Define a SCons builder for configuration flag headers.
705 ###################################################
707 # This function generates a config header file that #defines the
708 # variable symbol to the current variable setting (0 or 1). The source
709 # operands are the name of the variable and a Value node containing the
710 # value of the variable.
711 def build_config_file(target
, source
, env
):
712 (variable
, value
) = [s
.get_contents() for s
in source
]
713 f
= file(str(target
[0]), 'w')
714 print >> f
, '#define', variable
, value
718 # Generate the message to be printed when building the config file.
719 def build_config_file_string(target
, source
, env
):
720 (variable
, value
) = [s
.get_contents() for s
in source
]
721 return "Defining %s as %s in %s." % (variable
, value
, target
[0])
723 # Combine the two functions into a scons Action object.
724 config_action
= Action(build_config_file
, build_config_file_string
)
726 # The emitter munges the source & target node lists to reflect what
727 # we're really doing.
728 def config_emitter(target
, source
, env
):
729 # extract variable name from Builder arg
730 variable
= str(target
[0])
731 # True target is config header file
732 target
= joinpath('config', variable
.lower() + '.hh')
734 if isinstance(val
, bool):
737 elif isinstance(val
, str):
738 val
= '"' + val
+ '"'
740 # Sources are variable name & value (packaged in SCons Value nodes)
741 return ([target
], [Value(variable
), Value(val
)])
743 config_builder
= Builder(emitter
= config_emitter
, action
= config_action
)
745 env
.Append(BUILDERS
= { 'ConfigFile' : config_builder
})
747 # libelf build is shared across all configs in the build root.
748 env
.SConscript('ext/libelf/SConscript',
749 variant_dir
= joinpath(build_root
, 'libelf'))
751 # gzstream build is shared across all configs in the build root.
752 env
.SConscript('ext/gzstream/SConscript',
753 variant_dir
= joinpath(build_root
, 'gzstream'))
755 ###################################################
757 # This function is used to set up a directory with switching headers
759 ###################################################
761 env
['ALL_ISA_LIST'] = all_isa_list
762 def make_switching_dir(dname
, switch_headers
, env
):
763 # Generate the header. target[0] is the full path of the output
764 # header to generate. 'source' is a dummy variable, since we get the
765 # list of ISAs from env['ALL_ISA_LIST'].
766 def gen_switch_hdr(target
, source
, env
):
767 fname
= str(target
[0])
768 bname
= basename(fname
)
770 f
.write('#include "arch/isa_specific.hh"\n')
772 for isa
in all_isa_list
:
773 f
.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
774 % (cond
, isa
.upper(), dname
, isa
, bname
))
776 f
.write('#else\n#error "THE_ISA not set"\n#endif\n')
780 # String to print when generating header
781 def gen_switch_hdr_string(target
, source
, env
):
782 return "Generating switch header " + str(target
[0])
784 # Build SCons Action object. 'varlist' specifies env vars that this
785 # action depends on; when env['ALL_ISA_LIST'] changes these actions
786 # should get re-executed.
787 switch_hdr_action
= Action(gen_switch_hdr
, gen_switch_hdr_string
,
788 varlist
=['ALL_ISA_LIST'])
790 # Instantiate actions for each header
791 for hdr
in switch_headers
:
792 env
.Command(hdr
, [], switch_hdr_action
)
793 Export('make_switching_dir')
795 ###################################################
797 # Define build environments for selected configurations.
799 ###################################################
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.
808 env
= base_env
.Clone()
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)