3 # Copyright (c) 2004-2005 The Regents of The University of Michigan
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met: redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer;
10 # redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution;
13 # neither the name of the copyright holders nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # Authors: Steve Reinhardt
31 ###################################################
33 # SCons top-level build description (SConstruct) file.
35 # While in this directory ('m5'), just type 'scons' to build the default
36 # configuration (see below), or type 'scons build/<CONFIG>/<binary>'
37 # to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
38 # the optimized full-system version).
40 # You can build M5 in a different directory as long as there is a
41 # 'build/<CONFIG>' somewhere along the target path. The build system
42 # expects that all configs under the same build directory are being
43 # built for the same host system.
47 # The following two commands are equivalent. The '-u' option tells
48 # scons to search up the directory tree for this SConstruct file.
49 # % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
50 # % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
52 # The following two commands are equivalent and demonstrate building
53 # in a directory outside of the source tree. The '-C' option tells
54 # scons to chdir to the specified directory to find this SConstruct
56 # % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
57 # % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
59 # You can use 'scons -H' to print scons options. If you're in this
60 # 'm5' directory (or use -u or -C to tell scons where to find this
61 # file), you can use 'scons -h' to print all the M5-specific build
64 ###################################################
69 from os
.path
import isdir
, join
as joinpath
73 # Check for recent-enough Python and SCons versions. If your system's
74 # default installation of Python is not recent enough, you can use a
75 # non-default installation of the Python interpreter by either (1)
76 # rearranging your PATH so that scons finds the non-default 'python'
77 # first or (2) explicitly invoking an alternative interpreter on the
78 # scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
79 EnsurePythonVersion(2,4)
81 # Import subprocess after we check the version since it doesn't exist in
85 # Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
86 # 3-element version number.
87 min_scons_version
= (0,96,91)
89 EnsureSConsVersion(*min_scons_version
)
91 print "Error checking current SCons version."
92 print "SCons", ".".join(map(str,min_scons_version
)), "or greater required."
96 # The absolute path to the current directory (where this file lives).
97 ROOT
= Dir('.').abspath
99 # Path to the M5 source tree.
100 SRCDIR
= joinpath(ROOT
, 'src')
102 # tell python where to find m5 python code
103 sys
.path
.append(joinpath(ROOT
, 'src/python'))
105 def check_style_hook(ui
):
106 ui
.readconfig(joinpath(ROOT
, '.hg', 'hgrc'))
107 style_hook
= ui
.config('hooks', 'pretxncommit.style', None)
111 You're missing the M5 style hook.
112 Please install the hook so we can ensure that all code fits a common style.
114 All you'd need to do is add the following lines to your repository .hg/hgrc
115 or your personal .hgrc
119 style = %s/util/style.py
122 pretxncommit.style = python:style.check_whitespace
126 if ARGUMENTS
.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT
, '.hg')):
128 from mercurial
import ui
129 check_style_hook(ui
.ui())
133 ###################################################
135 # Figure out which configurations to set up based on the path(s) of
138 ###################################################
140 # Find default configuration & binary.
141 Default(os
.environ
.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
143 # helper function: find last occurrence of element in list
144 def rfind(l
, elt
, offs
= -1):
145 for i
in range(len(l
)+offs
, 0, -1):
148 raise ValueError, "element not found"
150 # helper function: compare dotted version numbers.
151 # E.g., compare_version('1.3.25', '1.4.1')
152 # returns -1, 0, 1 if v1 is <, ==, > v2
153 def compare_versions(v1
, v2
):
154 # Convert dotted strings to lists
155 v1
= map(int, v1
.split('.'))
156 v2
= map(int, v2
.split('.'))
157 # Compare corresponding elements of lists
158 for n1
,n2
in zip(v1
, v2
):
159 if n1
< n2
: return -1
161 # all corresponding values are equal... see if one has extra values
162 if len(v1
) < len(v2
): return -1
163 if len(v1
) > len(v2
): return 1
166 # Each target must have 'build' in the interior of the path; the
167 # directory below this will determine the build parameters. For
168 # example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
169 # recognize that ALPHA_SE specifies the configuration because it
170 # follow 'build' in the bulid path.
172 # Generate absolute paths to targets so we can see where the build dir is
173 if COMMAND_LINE_TARGETS
:
174 # Ask SCons which directory it was invoked from
175 launch_dir
= GetLaunchDir()
176 # Make targets relative to invocation directory
177 abs_targets
= map(lambda x
: os
.path
.normpath(joinpath(launch_dir
, str(x
))),
178 COMMAND_LINE_TARGETS
)
180 # Default targets are relative to root of tree
181 abs_targets
= map(lambda x
: os
.path
.normpath(joinpath(ROOT
, str(x
))),
185 # Generate a list of the unique build roots and configs that the
186 # collected targets reference.
189 for t
in abs_targets
:
190 path_dirs
= t
.split('/')
192 build_top
= rfind(path_dirs
, 'build', -2)
194 print "Error: no non-leaf 'build' dir found on target path", t
196 this_build_root
= joinpath('/',*path_dirs
[:build_top
+1])
198 build_root
= this_build_root
200 if this_build_root
!= build_root
:
201 print "Error: build targets not under same build root\n"\
202 " %s\n %s" % (build_root
, this_build_root
)
204 build_path
= joinpath('/',*path_dirs
[:build_top
+2])
205 if build_path
not in build_paths
:
206 build_paths
.append(build_path
)
208 ###################################################
210 # Set up the default build environment. This environment is copied
211 # and modified according to each selected configuration.
213 ###################################################
215 env
= Environment(ENV
= os
.environ
, # inherit user's environment vars
219 #Parse CC/CXX early so that we use the correct compiler for
220 # to test for dependencies/versions/libraries/includes
221 if ARGUMENTS
.get('CC', None):
222 env
['CC'] = ARGUMENTS
.get('CC')
224 if ARGUMENTS
.get('CXX', None):
225 env
['CXX'] = ARGUMENTS
.get('CXX')
229 env
.SConsignFile(joinpath(build_root
,"sconsign"))
231 # Default duplicate option is to use hard links, but this messes up
232 # when you use emacs to edit a file in the target dir, as emacs moves
233 # file to file~ then copies to file, breaking the link. Symbolic
234 # (soft) links work better.
235 env
.SetOption('duplicate', 'soft-copy')
237 # I waffle on this setting... it does avoid a few painful but
238 # unnecessary builds, but it also seems to make trivial builds take
241 env
.TargetSignatures('content')
243 # M5_PLY is used by isa_parser.py to find the PLY package.
244 env
.Append(ENV
= { 'M5_PLY' : str(Dir('ext/ply')) })
248 env
['GCC'] = subprocess
.Popen(env
['CXX'] + ' --version', shell
=True,
249 stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
,
250 close_fds
=True).communicate()[0].find('GCC') >= 0
251 env
['SUNCC'] = subprocess
.Popen(env
['CXX'] + ' -V', shell
=True,
252 stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
,
253 close_fds
=True).communicate()[0].find('Sun C++') >= 0
254 env
['ICC'] = subprocess
.Popen(env
['CXX'] + ' -V', shell
=True,
255 stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
,
256 close_fds
=True).communicate()[0].find('Intel') >= 0
257 if env
['GCC'] + env
['SUNCC'] + env
['ICC'] > 1:
258 print 'Error: How can we have two at the same time?'
262 # Set up default C++ compiler flags
264 env
.Append(CCFLAGS
='-pipe')
265 env
.Append(CCFLAGS
='-fno-strict-aliasing')
266 env
.Append(CCFLAGS
=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
268 pass #Fix me... add warning flags once we clean up icc warnings
270 env
.Append(CCFLAGS
='-Qoption ccfe')
271 env
.Append(CCFLAGS
='-features=gcc')
272 env
.Append(CCFLAGS
='-features=extensions')
273 env
.Append(CCFLAGS
='-library=stlport4')
274 env
.Append(CCFLAGS
='-xar')
275 # env.Append(CCFLAGS='-instances=semiexplicit')
277 print 'Error: Don\'t know what compiler options to use for your compiler.'
278 print ' Please fix SConstruct and src/SConscript and try again.'
281 if sys
.platform
== 'cygwin':
282 # cygwin has some header file issues...
283 env
.Append(CCFLAGS
=Split("-Wno-uninitialized"))
284 env
.Append(CPPPATH
=[Dir('ext/dnet')])
287 if not env
.has_key('SWIG'):
288 print 'Error: SWIG utility not found.'
289 print ' Please install (see http://www.swig.org) and retry.'
292 # Check for appropriate SWIG version
293 swig_version
= os
.popen('swig -version').read().split()
294 # First 3 words should be "SWIG Version x.y.z"
295 if len(swig_version
) < 3 or \
296 swig_version
[0] != 'SWIG' or swig_version
[1] != 'Version':
297 print 'Error determining SWIG version.'
300 min_swig_version
= '1.3.28'
301 if compare_versions(swig_version
[2], min_swig_version
) < 0:
302 print 'Error: SWIG version', min_swig_version
, 'or newer required.'
303 print ' Installed version:', swig_version
[2]
306 # Set up SWIG flags & scanner
307 swig_flags
=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
308 env
.Append(SWIGFLAGS
=swig_flags
)
310 # filter out all existing swig scanners, they mess up the dependency
311 # stuff for some reason
313 for scanner
in env
['SCANNERS']:
314 skeys
= scanner
.skeys
318 if isinstance(skeys
, (list, tuple)) and '.i' in skeys
:
321 scanners
.append(scanner
)
323 # add the new swig scanner that we like better
324 from SCons
.Scanner
import ClassicCPP
as CPPScanner
325 swig_inc_re
= '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
326 scanners
.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re
))
328 # replace the scanners list that has what we want
329 env
['SCANNERS'] = scanners
331 # Platform-specific configuration. Note again that we assume that all
332 # builds under a given build root run on the same host platform.
333 conf
= Configure(env
,
334 conf_dir
= joinpath(build_root
, '.scons_config'),
335 log_file
= joinpath(build_root
, 'scons_config.log'))
337 # Check if we should compile a 64 bit binary on Mac OS X/Darwin
340 uname
= platform
.uname()
341 if uname
[0] == 'Darwin' and compare_versions(uname
[2], '9.0.0') >= 0:
342 if int(subprocess
.Popen('sysctl -n hw.cpu64bit_capable', shell
=True,
343 stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
,
344 close_fds
=True).communicate()[0][0]):
345 env
.Append(CCFLAGS
='-arch x86_64')
346 env
.Append(CFLAGS
='-arch x86_64')
347 env
.Append(LINKFLAGS
='-arch x86_64')
348 env
.Append(ASFLAGS
='-arch x86_64')
349 env
['OSX64bit'] = True
353 # Recent versions of scons substitute a "Null" object for Configure()
354 # when configuration isn't necessary, e.g., if the "--help" option is
355 # present. Unfortuantely this Null object always returns false,
356 # breaking all our configuration checks. We replace it with our own
357 # more optimistic null object that returns True instead.
359 def NullCheck(*args
, **kwargs
):
363 def __init__(self
, env
):
367 def __getattr__(self
, mname
):
372 # Find Python include and library directories for embedding the
373 # interpreter. For consistency, we will use the same Python
374 # installation used to run scons (and thus this script). If you want
375 # to link in an alternate version, see above for instructions on how
376 # to invoke scons with a different copy of the Python interpreter.
378 # Get brief Python version name (e.g., "python2.4") for locating
379 # include & library files
380 py_version_name
= 'python' + sys
.version
[:3]
382 # include path, e.g. /usr/local/include/python2.4
383 py_header_path
= joinpath(sys
.exec_prefix
, 'include', py_version_name
)
384 env
.Append(CPPPATH
= py_header_path
)
385 # verify that it works
386 if not conf
.CheckHeader('Python.h', '<>'):
387 print "Error: can't find Python.h header in", py_header_path
390 # add library path too if it's not in the default place
392 if sys
.exec_prefix
!= '/usr':
393 py_lib_path
= joinpath(sys
.exec_prefix
, 'lib')
394 elif sys
.platform
== 'cygwin':
395 # cygwin puts the .dll in /bin for some reason
398 env
.Append(LIBPATH
= py_lib_path
)
399 print 'Adding', py_lib_path
, 'to LIBPATH for', py_version_name
400 if not conf
.CheckLib(py_version_name
):
401 print "Error: can't find Python library", py_version_name
404 # On Solaris you need to use libsocket for socket ops
405 if not conf
.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
406 if not conf
.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
407 print "Can't find library with socket calls (e.g. accept())"
410 # Check for zlib. If the check passes, libz will be automatically
411 # added to the LIBS environment variable.
412 if not conf
.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
413 print 'Error: did not find needed zlib compression library '\
414 'and/or zlib.h header file.'
415 print ' Please install zlib and try again.'
418 # Check for <fenv.h> (C99 FP environment control)
419 have_fenv
= conf
.CheckHeader('fenv.h', '<>')
421 print "Warning: Header file <fenv.h> not found."
422 print " This host has no IEEE FP rounding mode control."
425 mysql_config
= WhereIs('mysql_config')
426 have_mysql
= mysql_config
!= None
428 # Check MySQL version.
430 mysql_version
= os
.popen(mysql_config
+ ' --version').read()
431 min_mysql_version
= '4.1'
432 if compare_versions(mysql_version
, min_mysql_version
) < 0:
433 print 'Warning: MySQL', min_mysql_version
, 'or newer required.'
434 print ' Version', mysql_version
, 'detected.'
437 # Set up mysql_config commands.
439 mysql_config_include
= mysql_config
+ ' --include'
440 if os
.system(mysql_config_include
+ ' > /dev/null') != 0:
441 # older mysql_config versions don't support --include, use
443 mysql_config_include
= mysql_config
+ ' --cflags | sed s/\\\'//g'
444 # This seems to work in all versions
445 mysql_config_libs
= mysql_config
+ ' --libs'
449 # Define the universe of supported ISAs
451 Export('all_isa_list')
453 # Define the universe of supported CPU models
456 Export('all_cpu_list', 'default_cpus')
458 # Sticky options get saved in the options file so they persist from
459 # one invocation to the next (unless overridden, in which case the new
460 # value becomes sticky).
461 sticky_opts
= Options(args
=ARGUMENTS
)
462 Export('sticky_opts')
464 # Non-sticky options only apply to the current build.
465 nonsticky_opts
= Options(args
=ARGUMENTS
)
466 Export('nonsticky_opts')
468 # Walk the tree and execute all SConsopts scripts that wil add to the
470 for root
, dirs
, files
in os
.walk('.'):
471 if 'SConsopts' in files
:
472 SConscript(os
.path
.join(root
, 'SConsopts'))
478 def PathListMakeAbsolute(val
):
481 f
= lambda p
: os
.path
.abspath(os
.path
.expanduser(p
))
482 return ':'.join(map(f
, val
.split(':')))
484 def PathListAllExist(key
, val
, env
):
487 paths
= val
.split(':')
490 raise SCons
.Errors
.UserError("Path does not exist: '%s'" % path
)
492 sticky_opts
.AddOptions(
493 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list
),
494 BoolOption('FULL_SYSTEM', 'Full-system support', False),
495 # There's a bug in scons 0.96.1 that causes ListOptions with list
496 # values (more than one value) not to be able to be restored from
497 # a saved option file. If this causes trouble then upgrade to
498 # scons 0.96.90 or later.
499 ListOption('CPU_MODELS', 'CPU models', default_cpus
, all_cpu_list
),
500 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
501 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
503 BoolOption('SS_COMPATIBLE_FP',
504 'Make floating-point results compatible with SimpleScalar',
506 BoolOption('USE_SSE2',
507 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
509 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql
),
510 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv
),
511 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
512 ('CC', 'C compiler', os
.environ
.get('CC', env
['CC'])),
513 ('CXX', 'C++ compiler', os
.environ
.get('CXX', env
['CXX'])),
514 BoolOption('BATCH', 'Use batch pool for build and tests', False),
515 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
517 'Override the default PYTHONHOME for this system (use with caution)',
518 '%s:%s' % (sys
.prefix
, sys
.exec_prefix
)),
519 ('EXTRAS', 'Add Extra directories to the compilation', '',
520 PathListAllExist
, PathListMakeAbsolute
)
523 nonsticky_opts
.AddOptions(
524 BoolOption('update_ref', 'Update test reference outputs', False)
527 # These options get exported to #defines in config/*.hh (see src/SConscript).
528 env
.ExportOptions
= ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
529 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
530 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA']
532 # Define a handy 'no-op' action
533 def no_action(target
, source
, env
):
536 env
.NoAction
= Action(no_action
, None)
538 ###################################################
540 # Define a SCons builder for configuration flag headers.
542 ###################################################
544 # This function generates a config header file that #defines the
545 # option symbol to the current option setting (0 or 1). The source
546 # operands are the name of the option and a Value node containing the
547 # value of the option.
548 def build_config_file(target
, source
, env
):
549 (option
, value
) = [s
.get_contents() for s
in source
]
550 f
= file(str(target
[0]), 'w')
551 print >> f
, '#define', option
, value
555 # Generate the message to be printed when building the config file.
556 def build_config_file_string(target
, source
, env
):
557 (option
, value
) = [s
.get_contents() for s
in source
]
558 return "Defining %s as %s in %s." % (option
, value
, target
[0])
560 # Combine the two functions into a scons Action object.
561 config_action
= Action(build_config_file
, build_config_file_string
)
563 # The emitter munges the source & target node lists to reflect what
564 # we're really doing.
565 def config_emitter(target
, source
, env
):
566 # extract option name from Builder arg
567 option
= str(target
[0])
568 # True target is config header file
569 target
= joinpath('config', option
.lower() + '.hh')
571 if isinstance(val
, bool):
574 elif isinstance(val
, str):
575 val
= '"' + val
+ '"'
577 # Sources are option name & value (packaged in SCons Value nodes)
578 return ([target
], [Value(option
), Value(val
)])
580 config_builder
= Builder(emitter
= config_emitter
, action
= config_action
)
582 env
.Append(BUILDERS
= { 'ConfigFile' : config_builder
})
584 ###################################################
586 # Define a SCons builder for copying files. This is used by the
587 # Python zipfile code in src/python/SConscript, but is placed up here
588 # since it's potentially more generally applicable.
590 ###################################################
592 copy_builder
= Builder(action
= Copy("$TARGET", "$SOURCE"))
594 env
.Append(BUILDERS
= { 'CopyFile' : copy_builder
})
596 ###################################################
598 # Define a simple SCons builder to concatenate files.
600 # Used to append the Python zip archive to the executable.
602 ###################################################
604 concat_builder
= Builder(action
= Action(['cat $SOURCES > $TARGET',
605 'chmod +x $TARGET']))
607 env
.Append(BUILDERS
= { 'Concat' : concat_builder
})
612 Usage: scons [scons options] [build options] [target(s)]
616 # libelf build is shared across all configs in the build root.
617 env
.SConscript('ext/libelf/SConscript',
618 build_dir
= joinpath(build_root
, 'libelf'),
621 ###################################################
623 # This function is used to set up a directory with switching headers
625 ###################################################
627 env
['ALL_ISA_LIST'] = all_isa_list
628 def make_switching_dir(dirname
, switch_headers
, env
):
629 # Generate the header. target[0] is the full path of the output
630 # header to generate. 'source' is a dummy variable, since we get the
631 # list of ISAs from env['ALL_ISA_LIST'].
632 def gen_switch_hdr(target
, source
, env
):
633 fname
= str(target
[0])
634 basename
= os
.path
.basename(fname
)
636 f
.write('#include "arch/isa_specific.hh"\n')
638 for isa
in all_isa_list
:
639 f
.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
640 % (cond
, isa
.upper(), dirname
, isa
, basename
))
642 f
.write('#else\n#error "THE_ISA not set"\n#endif\n')
646 # String to print when generating header
647 def gen_switch_hdr_string(target
, source
, env
):
648 return "Generating switch header " + str(target
[0])
650 # Build SCons Action object. 'varlist' specifies env vars that this
651 # action depends on; when env['ALL_ISA_LIST'] changes these actions
652 # should get re-executed.
653 switch_hdr_action
= Action(gen_switch_hdr
, gen_switch_hdr_string
,
654 varlist
=['ALL_ISA_LIST'])
656 # Instantiate actions for each header
657 for hdr
in switch_headers
:
658 env
.Command(hdr
, [], switch_hdr_action
)
659 Export('make_switching_dir')
661 ###################################################
663 # Define build environments for selected configurations.
665 ###################################################
670 for build_path
in build_paths
:
671 print "Building in", build_path
672 env
['BUILDDIR'] = build_path
674 # build_dir is the tail component of build path, and is used to
675 # determine the build parameters (e.g., 'ALPHA_SE')
676 (build_root
, build_dir
) = os
.path
.split(build_path
)
677 # Make a copy of the build-root environment to use for this config.
678 env
= base_env
.Copy()
680 # Set env options according to the build directory config.
681 sticky_opts
.files
= []
682 # Options for $BUILD_ROOT/$BUILD_DIR are stored in
683 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
684 # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
685 current_opts_file
= joinpath(build_root
, 'options', build_dir
)
686 if os
.path
.isfile(current_opts_file
):
687 sticky_opts
.files
.append(current_opts_file
)
688 print "Using saved options file %s" % current_opts_file
690 # Build dir-specific options file doesn't exist.
692 # Make sure the directory is there so we can create it later
693 opt_dir
= os
.path
.dirname(current_opts_file
)
694 if not os
.path
.isdir(opt_dir
):
697 # Get default build options from source tree. Options are
698 # normally determined by name of $BUILD_DIR, but can be
699 # overriden by 'default=' arg on command line.
700 default_opts_file
= joinpath('build_opts',
701 ARGUMENTS
.get('default', build_dir
))
702 if os
.path
.isfile(default_opts_file
):
703 sticky_opts
.files
.append(default_opts_file
)
704 print "Options file %s not found,\n using defaults in %s" \
705 % (current_opts_file
, default_opts_file
)
707 print "Error: cannot find options file %s or %s" \
708 % (current_opts_file
, default_opts_file
)
711 # Apply current option settings to env
712 sticky_opts
.Update(env
)
713 nonsticky_opts
.Update(env
)
715 help_text
+= "Sticky options for %s:\n" % build_dir \
716 + sticky_opts
.GenerateHelpText(env
) \
717 + "\nNon-sticky options for %s:\n" % build_dir \
718 + nonsticky_opts
.GenerateHelpText(env
)
720 # Process option settings.
722 if not have_fenv
and env
['USE_FENV']:
723 print "Warning: <fenv.h> not available; " \
724 "forcing USE_FENV to False in", build_dir
+ "."
725 env
['USE_FENV'] = False
727 if not env
['USE_FENV']:
728 print "Warning: No IEEE FP rounding mode control in", build_dir
+ "."
729 print " FP results may deviate slightly from other platforms."
732 env
.Append(LIBS
=['efence'])
736 print "Warning: MySQL not available; " \
737 "forcing USE_MYSQL to False in", build_dir
+ "."
738 env
['USE_MYSQL'] = False
740 print "Compiling in", build_dir
, "with MySQL support."
741 env
.ParseConfig(mysql_config_libs
)
742 env
.ParseConfig(mysql_config_include
)
744 # Save sticky option settings back to current options file
745 sticky_opts
.Save(current_opts_file
, env
)
747 # Do this after we save setting back, or else we'll tack on an
748 # extra 'qdo' every time we run scons.
750 env
['CC'] = env
['BATCH_CMD'] + ' ' + env
['CC']
751 env
['CXX'] = env
['BATCH_CMD'] + ' ' + env
['CXX']
754 env
.Append(CCFLAGS
='-msse2')
756 # The src/SConscript file sets up the build rules in 'env' according
757 # to the configured options. It returns a list of environments,
758 # one for each variant build (debug, opt, etc.)
759 envList
= SConscript('src/SConscript', build_dir
= build_path
,
762 # Set up the regression tests for each build.
764 SConscript('tests/SConscript',
765 build_dir
= joinpath(build_path
, 'tests', e
.Label
),
766 exports
= { 'env' : e
}, duplicate
= False)
771 ###################################################
773 # Let SCons do its thing. At this point SCons will use the defined
774 # build environments to build the requested targets.
776 ###################################################