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 ###################################################
66 # Python library imports
70 # Check for recent-enough Python and SCons versions. If your system's
71 # default installation of Python is not recent enough, you can use a
72 # non-default installation of the Python interpreter by either (1)
73 # rearranging your PATH so that scons finds the non-default 'python'
74 # first or (2) explicitly invoking an alternative interpreter on the
75 # scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
76 EnsurePythonVersion(2,4)
78 # Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
79 # 3-element version number.
80 min_scons_version
= (0,96,91)
82 EnsureSConsVersion(*min_scons_version
)
84 print "Error checking current SCons version."
85 print "SCons", ".".join(map(str,min_scons_version
)), "or greater required."
89 # The absolute path to the current directory (where this file lives).
90 ROOT
= Dir('.').abspath
92 # Paths to the M5 and external source trees.
93 SRCDIR
= os
.path
.join(ROOT
, 'src')
95 # tell python where to find m5 python code
96 sys
.path
.append(os
.path
.join(ROOT
, 'src/python'))
98 ###################################################
100 # Figure out which configurations to set up based on the path(s) of
103 ###################################################
105 # Find default configuration & binary.
106 Default(os
.environ
.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
108 # Ask SCons which directory it was invoked from.
109 launch_dir
= GetLaunchDir()
111 # Make targets relative to invocation directory
112 abs_targets
= map(lambda x
: os
.path
.normpath(os
.path
.join(launch_dir
, str(x
))),
115 # helper function: find last occurrence of element in list
116 def rfind(l
, elt
, offs
= -1):
117 for i
in range(len(l
)+offs
, 0, -1):
120 raise ValueError, "element not found"
122 # Each target must have 'build' in the interior of the path; the
123 # directory below this will determine the build parameters. For
124 # example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
125 # recognize that ALPHA_SE specifies the configuration because it
126 # follow 'build' in the bulid path.
128 # Generate a list of the unique build roots and configs that the
129 # collected targets reference.
132 for t
in abs_targets
:
133 path_dirs
= t
.split('/')
135 build_top
= rfind(path_dirs
, 'build', -2)
137 print "Error: no non-leaf 'build' dir found on target path", t
139 this_build_root
= os
.path
.join('/',*path_dirs
[:build_top
+1])
141 build_root
= this_build_root
143 if this_build_root
!= build_root
:
144 print "Error: build targets not under same build root\n"\
145 " %s\n %s" % (build_root
, this_build_root
)
147 build_path
= os
.path
.join('/',*path_dirs
[:build_top
+2])
148 if build_path
not in build_paths
:
149 build_paths
.append(build_path
)
151 ###################################################
153 # Set up the default build environment. This environment is copied
154 # and modified according to each selected configuration.
156 ###################################################
158 env
= Environment(ENV
= os
.environ
, # inherit user's environment vars
162 env
.SConsignFile(os
.path
.join(build_root
,"sconsign"))
164 # Default duplicate option is to use hard links, but this messes up
165 # when you use emacs to edit a file in the target dir, as emacs moves
166 # file to file~ then copies to file, breaking the link. Symbolic
167 # (soft) links work better.
168 env
.SetOption('duplicate', 'soft-copy')
170 # I waffle on this setting... it does avoid a few painful but
171 # unnecessary builds, but it also seems to make trivial builds take
174 env
.TargetSignatures('content')
176 # M5_PLY is used by isa_parser.py to find the PLY package.
177 env
.Append(ENV
= { 'M5_PLY' : Dir('ext/ply') })
179 # Set up default C++ compiler flags
180 env
.Append(CCFLAGS
='-pipe')
181 env
.Append(CCFLAGS
='-fno-strict-aliasing')
182 env
.Append(CCFLAGS
=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
183 if sys
.platform
== 'cygwin':
184 # cygwin has some header file issues...
185 env
.Append(CCFLAGS
=Split("-Wno-uninitialized"))
186 env
.Append(CPPPATH
=[Dir('ext/dnet')])
188 # Find Python include and library directories for embedding the
189 # interpreter. For consistency, we will use the same Python
190 # installation used to run scons (and thus this script). If you want
191 # to link in an alternate version, see above for instructions on how
192 # to invoke scons with a different copy of the Python interpreter.
194 # Get brief Python version name (e.g., "python2.4") for locating
195 # include & library files
196 py_version_name
= 'python' + sys
.version
[:3]
198 # include path, e.g. /usr/local/include/python2.4
199 env
.Append(CPPPATH
= os
.path
.join(sys
.exec_prefix
, 'include', py_version_name
))
200 env
.Append(LIBS
= py_version_name
)
201 # add library path too if it's not in the default place
202 if sys
.exec_prefix
!= '/usr':
203 env
.Append(LIBPATH
= os
.path
.join(sys
.exec_prefix
, 'lib'))
205 # Set up SWIG flags & scanner
207 env
.Append(SWIGFLAGS
=Split('-c++ -python -modern $_CPPINCFLAGS'))
211 swig_inc_re
= '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
213 swig_scanner
= SCons
.Scanner
.ClassicCPP("SwigScan", ".i", "CPPPATH",
216 env
.Append(SCANNERS
= swig_scanner
)
218 # Other default libraries
219 env
.Append(LIBS
=['z'])
221 # Platform-specific configuration. Note again that we assume that all
222 # builds under a given build root run on the same host platform.
223 conf
= Configure(env
,
224 conf_dir
= os
.path
.join(build_root
, '.scons_config'),
225 log_file
= os
.path
.join(build_root
, 'scons_config.log'))
227 # Check for <fenv.h> (C99 FP environment control)
228 have_fenv
= conf
.CheckHeader('fenv.h', '<>')
230 print "Warning: Header file <fenv.h> not found."
231 print " This host has no IEEE FP rounding mode control."
234 mysql_config
= WhereIs('mysql_config')
235 have_mysql
= mysql_config
!= None
237 # Check MySQL version.
239 mysql_version
= os
.popen(mysql_config
+ ' --version').read()
240 mysql_version
= mysql_version
.split('.')
241 mysql_major
= int(mysql_version
[0])
242 mysql_minor
= int(mysql_version
[1])
243 # This version check is probably overly conservative, but it deals
244 # with the versions we have installed.
245 if mysql_major
< 4 or (mysql_major
== 4 and mysql_minor
< 1):
246 print "Warning: MySQL v4.1 or newer required."
249 # Set up mysql_config commands.
251 mysql_config_include
= mysql_config
+ ' --include'
252 if os
.system(mysql_config_include
+ ' > /dev/null') != 0:
253 # older mysql_config versions don't support --include, use
255 mysql_config_include
= mysql_config
+ ' --cflags | sed s/\\\'//g'
256 # This seems to work in all versions
257 mysql_config_libs
= mysql_config
+ ' --libs'
261 # Define the universe of supported ISAs
262 env
['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
264 # Define the universe of supported CPU models
265 env
['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
269 # Sticky options get saved in the options file so they persist from
270 # one invocation to the next (unless overridden, in which case the new
271 # value becomes sticky).
272 sticky_opts
= Options(args
=ARGUMENTS
)
273 sticky_opts
.AddOptions(
274 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env
['ALL_ISA_LIST']),
275 BoolOption('FULL_SYSTEM', 'Full-system support', False),
276 # There's a bug in scons 0.96.1 that causes ListOptions with list
277 # values (more than one value) not to be able to be restored from
278 # a saved option file. If this causes trouble then upgrade to
279 # scons 0.96.90 or later.
280 ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
281 env
['ALL_CPU_LIST']),
282 BoolOption('ALPHA_TLASER',
283 'Model Alpha TurboLaser platform (vs. Tsunami)', False),
284 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
285 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
287 BoolOption('SS_COMPATIBLE_FP',
288 'Make floating-point results compatible with SimpleScalar',
290 BoolOption('USE_SSE2',
291 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
293 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql
),
294 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv
),
295 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
296 ('CC', 'C compiler', os
.environ
.get('CC', env
['CC'])),
297 ('CXX', 'C++ compiler', os
.environ
.get('CXX', env
['CXX'])),
298 BoolOption('BATCH', 'Use batch pool for build and tests', False),
299 ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
302 # Non-sticky options only apply to the current build.
303 nonsticky_opts
= Options(args
=ARGUMENTS
)
304 nonsticky_opts
.AddOptions(
305 BoolOption('update_ref', 'Update test reference outputs', False)
308 # These options get exported to #defines in config/*.hh (see src/SConscript).
309 env
.ExportOptions
= ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
310 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
313 # Define a handy 'no-op' action
314 def no_action(target
, source
, env
):
317 env
.NoAction
= Action(no_action
, None)
319 ###################################################
321 # Define a SCons builder for configuration flag headers.
323 ###################################################
325 # This function generates a config header file that #defines the
326 # option symbol to the current option setting (0 or 1). The source
327 # operands are the name of the option and a Value node containing the
328 # value of the option.
329 def build_config_file(target
, source
, env
):
330 (option
, value
) = [s
.get_contents() for s
in source
]
331 f
= file(str(target
[0]), 'w')
332 print >> f
, '#define', option
, value
336 # Generate the message to be printed when building the config file.
337 def build_config_file_string(target
, source
, env
):
338 (option
, value
) = [s
.get_contents() for s
in source
]
339 return "Defining %s as %s in %s." % (option
, value
, target
[0])
341 # Combine the two functions into a scons Action object.
342 config_action
= Action(build_config_file
, build_config_file_string
)
344 # The emitter munges the source & target node lists to reflect what
345 # we're really doing.
346 def config_emitter(target
, source
, env
):
347 # extract option name from Builder arg
348 option
= str(target
[0])
349 # True target is config header file
350 target
= os
.path
.join('config', option
.lower() + '.hh')
351 # Force value to 0/1 even if it's a Python bool
352 val
= int(eval(str(env
[option
])))
353 # Sources are option name & value (packaged in SCons Value nodes)
354 return ([target
], [Value(option
), Value(val
)])
356 config_builder
= Builder(emitter
= config_emitter
, action
= config_action
)
358 env
.Append(BUILDERS
= { 'ConfigFile' : config_builder
})
360 ###################################################
362 # Define a SCons builder for copying files. This is used by the
363 # Python zipfile code in src/python/SConscript, but is placed up here
364 # since it's potentially more generally applicable.
366 ###################################################
368 copy_builder
= Builder(action
= Copy("$TARGET", "$SOURCE"))
370 env
.Append(BUILDERS
= { 'CopyFile' : copy_builder
})
372 ###################################################
374 # Define a simple SCons builder to concatenate files.
376 # Used to append the Python zip archive to the executable.
378 ###################################################
380 concat_builder
= Builder(action
= Action(['cat $SOURCES > $TARGET',
381 'chmod +x $TARGET']))
383 env
.Append(BUILDERS
= { 'Concat' : concat_builder
})
388 Usage: scons [scons options] [build options] [target(s)]
392 # libelf build is shared across all configs in the build root.
393 env
.SConscript('ext/libelf/SConscript',
394 build_dir
= os
.path
.join(build_root
, 'libelf'),
397 ###################################################
399 # Define build environments for selected configurations.
401 ###################################################
406 for build_path
in build_paths
:
407 print "Building in", build_path
408 # build_dir is the tail component of build path, and is used to
409 # determine the build parameters (e.g., 'ALPHA_SE')
410 (build_root
, build_dir
) = os
.path
.split(build_path
)
411 # Make a copy of the build-root environment to use for this config.
412 env
= base_env
.Copy()
414 # Set env options according to the build directory config.
415 sticky_opts
.files
= []
416 # Options for $BUILD_ROOT/$BUILD_DIR are stored in
417 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
418 # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
419 current_opts_file
= os
.path
.join(build_root
, 'options', build_dir
)
420 if os
.path
.isfile(current_opts_file
):
421 sticky_opts
.files
.append(current_opts_file
)
422 print "Using saved options file %s" % current_opts_file
424 # Build dir-specific options file doesn't exist.
426 # Make sure the directory is there so we can create it later
427 opt_dir
= os
.path
.dirname(current_opts_file
)
428 if not os
.path
.isdir(opt_dir
):
431 # Get default build options from source tree. Options are
432 # normally determined by name of $BUILD_DIR, but can be
433 # overriden by 'default=' arg on command line.
434 default_opts_file
= os
.path
.join('build_opts',
435 ARGUMENTS
.get('default', build_dir
))
436 if os
.path
.isfile(default_opts_file
):
437 sticky_opts
.files
.append(default_opts_file
)
438 print "Options file %s not found,\n using defaults in %s" \
439 % (current_opts_file
, default_opts_file
)
441 print "Error: cannot find options file %s or %s" \
442 % (current_opts_file
, default_opts_file
)
445 # Apply current option settings to env
446 sticky_opts
.Update(env
)
447 nonsticky_opts
.Update(env
)
449 help_text
+= "Sticky options for %s:\n" % build_dir \
450 + sticky_opts
.GenerateHelpText(env
) \
451 + "\nNon-sticky options for %s:\n" % build_dir \
452 + nonsticky_opts
.GenerateHelpText(env
)
454 # Process option settings.
456 if not have_fenv
and env
['USE_FENV']:
457 print "Warning: <fenv.h> not available; " \
458 "forcing USE_FENV to False in", build_dir
+ "."
459 env
['USE_FENV'] = False
461 if not env
['USE_FENV']:
462 print "Warning: No IEEE FP rounding mode control in", build_dir
+ "."
463 print " FP results may deviate slightly from other platforms."
466 env
.Append(LIBS
=['efence'])
470 print "Warning: MySQL not available; " \
471 "forcing USE_MYSQL to False in", build_dir
+ "."
472 env
['USE_MYSQL'] = False
474 print "Compiling in", build_dir
, "with MySQL support."
475 env
.ParseConfig(mysql_config_libs
)
476 env
.ParseConfig(mysql_config_include
)
478 # Save sticky option settings back to current options file
479 sticky_opts
.Save(current_opts_file
, env
)
481 # Do this after we save setting back, or else we'll tack on an
482 # extra 'qdo' every time we run scons.
484 env
['CC'] = env
['BATCH_CMD'] + ' ' + env
['CC']
485 env
['CXX'] = env
['BATCH_CMD'] + ' ' + env
['CXX']
488 env
.Append(CCFLAGS
='-msse2')
490 # The src/SConscript file sets up the build rules in 'env' according
491 # to the configured options. It returns a list of environments,
492 # one for each variant build (debug, opt, etc.)
493 envList
= SConscript('src/SConscript', build_dir
= build_path
,
496 # Set up the regression tests for each build.
498 SConscript('tests/SConscript',
499 build_dir
= os
.path
.join(build_path
, 'test', e
.Label
),
500 exports
= { 'env' : e
}, duplicate
= False)
504 ###################################################
506 # Let SCons do its thing. At this point SCons will use the defined
507 # build environments to build the requested targets.
509 ###################################################