3fac9eb2e4d1171de0c146aeaa1caca4c6b243a9
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 ###################################################
31 # SCons top-level build description (SConstruct) file.
33 # While in this directory ('m5'), just type 'scons' to build the default
34 # configuration (see below), or type 'scons build/<CONFIG>/<binary>'
35 # to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
36 # the optimized full-system version).
38 # You can build M5 in a different directory as long as there is a
39 # 'build/<CONFIG>' somewhere along the target path. The build system
40 # expdects that all configs under the same build directory are being
41 # built for the same host system.
44 # These two commands are equivalent. The '-u' option tells scons to
45 # search up the directory tree for this SConstruct file.
46 # % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
47 # % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
48 # These two commands are equivalent and demonstrate building in a
49 # directory outside of the source tree. The '-C' option tells scons
50 # to chdir to the specified directory to find this SConstruct file.
51 # % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
52 # % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
54 # You can use 'scons -H' to print scons options. If you're in this
55 # 'm5' directory (or use -u or -C to tell scons where to find this
56 # file), you can use 'scons -h' to print all the M5-specific build
59 ###################################################
61 # Python library imports
65 # Check for recent-enough Python and SCons versions
66 EnsurePythonVersion(2,3)
67 EnsureSConsVersion(0,96,91)
69 # The absolute path to the current directory (where this file lives).
70 ROOT
= Dir('.').abspath
72 # Paths to the M5 and external source trees.
73 SRCDIR
= os
.path
.join(ROOT
, 'src')
75 # tell python where to find m5 python code
76 sys
.path
.append(os
.path
.join(ROOT
, 'src/python'))
78 ###################################################
80 # Figure out which configurations to set up based on the path(s) of
83 ###################################################
85 # Find default configuration & binary.
86 Default(os
.environ
.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
88 # Ask SCons which directory it was invoked from.
89 launch_dir
= GetLaunchDir()
91 # Make targets relative to invocation directory
92 abs_targets
= map(lambda x
: os
.path
.normpath(os
.path
.join(launch_dir
, str(x
))),
95 # helper function: find last occurrence of element in list
96 def rfind(l
, elt
, offs
= -1):
97 for i
in range(len(l
)+offs
, 0, -1):
100 raise ValueError, "element not found"
102 # Each target must have 'build' in the interior of the path; the
103 # directory below this will determine the build parameters. For
104 # example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
105 # recognize that ALPHA_SE specifies the configuration because it
106 # follow 'build' in the bulid path.
108 # Generate a list of the unique build roots and configs that the
109 # collected targets reference.
112 for t
in abs_targets
:
113 path_dirs
= t
.split('/')
115 build_top
= rfind(path_dirs
, 'build', -2)
117 print "Error: no non-leaf 'build' dir found on target path", t
119 this_build_root
= os
.path
.join('/',*path_dirs
[:build_top
+1])
121 build_root
= this_build_root
123 if this_build_root
!= build_root
:
124 print "Error: build targets not under same build root\n"\
125 " %s\n %s" % (build_root
, this_build_root
)
127 build_path
= os
.path
.join('/',*path_dirs
[:build_top
+2])
128 if build_path
not in build_paths
:
129 build_paths
.append(build_path
)
131 ###################################################
133 # Set up the default build environment. This environment is copied
134 # and modified according to each selected configuration.
136 ###################################################
138 env
= Environment(ENV
= os
.environ
, # inherit user's environment vars
142 env
.SConsignFile("sconsign")
144 # I waffle on this setting... it does avoid a few painful but
145 # unnecessary builds, but it also seems to make trivial builds take
148 env
.TargetSignatures('content')
150 # M5_PLY is used by isa_parser.py to find the PLY package.
151 env
.Append(ENV
= { 'M5_PLY' : Dir('ext/ply') })
153 # Set up default C++ compiler flags
154 env
.Append(CCFLAGS
='-pipe')
155 env
.Append(CCFLAGS
='-fno-strict-aliasing')
156 env
.Append(CCFLAGS
=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
157 if sys
.platform
== 'cygwin':
158 # cygwin has some header file issues...
159 env
.Append(CCFLAGS
=Split("-Wno-uninitialized"))
160 env
.Append(CPPPATH
=[Dir('ext/dnet')])
163 env
.Append(LIBS
=['z'])
165 # Platform-specific configuration. Note again that we assume that all
166 # builds under a given build root run on the same host platform.
167 conf
= Configure(env
,
168 conf_dir
= os
.path
.join(build_root
, '.scons_config'),
169 log_file
= os
.path
.join(build_root
, 'scons_config.log'))
171 # Check for <fenv.h> (C99 FP environment control)
172 have_fenv
= conf
.CheckHeader('fenv.h', '<>')
174 print "Warning: Header file <fenv.h> not found."
175 print " This host has no IEEE FP rounding mode control."
178 mysql_config
= WhereIs('mysql_config')
179 have_mysql
= mysql_config
!= None
181 # Check MySQL version.
183 mysql_version
= os
.popen(mysql_config
+ ' --version').read()
184 mysql_version
= mysql_version
.split('.')
185 mysql_major
= int(mysql_version
[0])
186 mysql_minor
= int(mysql_version
[1])
187 # This version check is probably overly conservative, but it deals
188 # with the versions we have installed.
189 if mysql_major
< 4 or (mysql_major
== 4 and mysql_minor
< 1):
190 print "Warning: MySQL v4.1 or newer required."
193 # Set up mysql_config commands.
195 mysql_config_include
= mysql_config
+ ' --include'
196 if os
.system(mysql_config_include
+ ' > /dev/null') != 0:
197 # older mysql_config versions don't support --include, use
199 mysql_config_include
= mysql_config
+ ' --cflags | sed s/\\\'//g'
200 # This seems to work in all versions
201 mysql_config_libs
= mysql_config
+ ' --libs'
205 # Define the universe of supported ISAs
206 env
['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
208 # Define the universe of supported CPU models
209 env
['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
210 'FullCPU', 'AlphaFullCPU']
212 # Sticky options get saved in the options file so they persist from
213 # one invocation to the next (unless overridden, in which case the new
214 # value becomes sticky).
215 sticky_opts
= Options(args
=ARGUMENTS
)
216 sticky_opts
.AddOptions(
217 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env
['ALL_ISA_LIST']),
218 BoolOption('FULL_SYSTEM', 'Full-system support', False),
219 # There's a bug in scons 0.96.1 that causes ListOptions with list
220 # values (more than one value) not to be able to be restored from
221 # a saved option file. If this causes trouble then upgrade to
222 # scons 0.96.90 or later.
223 ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
224 env
['ALL_CPU_LIST']),
225 BoolOption('ALPHA_TLASER',
226 'Model Alpha TurboLaser platform (vs. Tsunami)', False),
227 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
228 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
230 BoolOption('SS_COMPATIBLE_FP',
231 'Make floating-point results compatible with SimpleScalar',
233 BoolOption('USE_SSE2',
234 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
236 BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql
),
237 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql
),
238 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv
),
239 ('CC', 'C compiler', os
.environ
.get('CC', env
['CC'])),
240 ('CXX', 'C++ compiler', os
.environ
.get('CXX', env
['CXX'])),
241 BoolOption('BATCH', 'Use batch pool for build and tests', False),
242 ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
245 # Non-sticky options only apply to the current build.
246 nonsticky_opts
= Options(args
=ARGUMENTS
)
247 nonsticky_opts
.AddOptions(
248 BoolOption('update_ref', 'Update test reference outputs', False)
251 # These options get exported to #defines in config/*.hh (see m5/SConscript).
252 env
.ExportOptions
= ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
253 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
256 # Define a handy 'no-op' action
257 def no_action(target
, source
, env
):
260 env
.NoAction
= Action(no_action
, None)
262 ###################################################
264 # Define a SCons builder for configuration flag headers.
266 ###################################################
268 # This function generates a config header file that #defines the
269 # option symbol to the current option setting (0 or 1). The source
270 # operands are the name of the option and a Value node containing the
271 # value of the option.
272 def build_config_file(target
, source
, env
):
273 (option
, value
) = [s
.get_contents() for s
in source
]
274 f
= file(str(target
[0]), 'w')
275 print >> f
, '#define', option
, value
279 # Generate the message to be printed when building the config file.
280 def build_config_file_string(target
, source
, env
):
281 (option
, value
) = [s
.get_contents() for s
in source
]
282 return "Defining %s as %s in %s." % (option
, value
, target
[0])
284 # Combine the two functions into a scons Action object.
285 config_action
= Action(build_config_file
, build_config_file_string
)
287 # The emitter munges the source & target node lists to reflect what
288 # we're really doing.
289 def config_emitter(target
, source
, env
):
290 # extract option name from Builder arg
291 option
= str(target
[0])
292 # True target is config header file
293 target
= os
.path
.join('config', option
.lower() + '.hh')
294 # Force value to 0/1 even if it's a Python bool
295 val
= int(eval(str(env
[option
])))
296 # Sources are option name & value (packaged in SCons Value nodes)
297 return ([target
], [Value(option
), Value(val
)])
299 config_builder
= Builder(emitter
= config_emitter
, action
= config_action
)
301 env
.Append(BUILDERS
= { 'ConfigFile' : config_builder
})
305 Usage: scons [scons options] [build options] [target(s)]
309 # libelf build is shared across all configs in the build root.
310 env
.SConscript('ext/libelf/SConscript',
311 build_dir
= os
.path
.join(build_root
, 'libelf'),
314 ###################################################
316 # Define build environments for selected configurations.
318 ###################################################
323 for build_path
in build_paths
:
324 print "Building in", build_path
325 # build_dir is the tail component of build path, and is used to
326 # determine the build parameters (e.g., 'ALPHA_SE')
327 (build_root
, build_dir
) = os
.path
.split(build_path
)
328 # Make a copy of the build-root environment to use for this config.
329 env
= base_env
.Copy()
331 # Set env options according to the build directory config.
332 sticky_opts
.files
= []
333 # Options for $BUILD_ROOT/$BUILD_DIR are stored in
334 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
335 # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
336 current_opts_file
= os
.path
.join(build_root
, 'options', build_dir
)
337 if os
.path
.isfile(current_opts_file
):
338 sticky_opts
.files
.append(current_opts_file
)
339 print "Using saved options file %s" % current_opts_file
341 # Build dir-specific options file doesn't exist.
343 # Make sure the directory is there so we can create it later
344 opt_dir
= os
.path
.dirname(current_opts_file
)
345 if not os
.path
.isdir(opt_dir
):
348 # Get default build options from source tree. Options are
349 # normally determined by name of $BUILD_DIR, but can be
350 # overriden by 'default=' arg on command line.
351 default_opts_file
= os
.path
.join('build_opts',
352 ARGUMENTS
.get('default', build_dir
))
353 if os
.path
.isfile(default_opts_file
):
354 sticky_opts
.files
.append(default_opts_file
)
355 print "Options file %s not found,\n using defaults in %s" \
356 % (current_opts_file
, default_opts_file
)
358 print "Error: cannot find options file %s or %s" \
359 % (current_opts_file
, default_opts_file
)
362 # Apply current option settings to env
363 sticky_opts
.Update(env
)
364 nonsticky_opts
.Update(env
)
366 help_text
+= "Sticky options for %s:\n" % build_dir \
367 + sticky_opts
.GenerateHelpText(env
) \
368 + "\nNon-sticky options for %s:\n" % build_dir \
369 + nonsticky_opts
.GenerateHelpText(env
)
371 # Process option settings.
373 if not have_fenv
and env
['USE_FENV']:
374 print "Warning: <fenv.h> not available; " \
375 "forcing USE_FENV to False in", build_dir
+ "."
376 env
['USE_FENV'] = False
378 if not env
['USE_FENV']:
379 print "Warning: No IEEE FP rounding mode control in", build_dir
+ "."
380 print " FP results may deviate slightly from other platforms."
383 env
.Append(LIBS
=['efence'])
387 print "Warning: MySQL not available; " \
388 "forcing USE_MYSQL to False in", build_dir
+ "."
389 env
['USE_MYSQL'] = False
391 print "Compiling in", build_dir
, "with MySQL support."
392 env
.ParseConfig(mysql_config_libs
)
393 env
.ParseConfig(mysql_config_include
)
395 # Save sticky option settings back to current options file
396 sticky_opts
.Save(current_opts_file
, env
)
398 # Do this after we save setting back, or else we'll tack on an
399 # extra 'qdo' every time we run scons.
401 env
['CC'] = env
['BATCH_CMD'] + ' ' + env
['CC']
402 env
['CXX'] = env
['BATCH_CMD'] + ' ' + env
['CXX']
405 env
.Append(CCFLAGS
='-msse2')
407 # The m5/SConscript file sets up the build rules in 'env' according
408 # to the configured options. It returns a list of environments,
409 # one for each variant build (debug, opt, etc.)
410 envList
= SConscript('src/SConscript', build_dir
= build_path
,
411 exports
= 'env', duplicate
= False)
413 # Set up the regression tests for each build.
415 # SConscript('m5-test/SConscript',
416 # build_dir = os.path.join(build_dir, 'test', e.Label),
417 # exports = { 'env' : e }, duplicate = False)
421 ###################################################
423 # Let SCons do its thing. At this point SCons will use the defined
424 # build environments to build the requested targets.
426 ###################################################