SConstruct (2656:320826b719a8) SConstruct (2665:a124942bacb8)
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
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.
16#
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.
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
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.
16#
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.
28#
29# Authors: Steve Reinhardt
28
29###################################################
30#
31# SCons top-level build description (SConstruct) file.
32#
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).
37#
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.
42#
43# Examples:
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
53#
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
57# options as well.
58#
59###################################################
60
61# Python library imports
62import sys
63import os
64
65# Check for recent-enough Python and SCons versions. If your system's
66# default installation of Python is not recent enough, you can use a
67# non-default installation of the Python interpreter by either (1)
68# rearranging your PATH so that scons finds the non-default 'python'
69# first or (2) explicitly invoking an alternative interpreter on the
70# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
71EnsurePythonVersion(2,4)
72
73# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
74# 3-element version number.
75min_scons_version = (0,96,91)
76try:
77 EnsureSConsVersion(*min_scons_version)
78except:
79 print "Error checking current SCons version."
80 print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
81 Exit(2)
82
83
84# The absolute path to the current directory (where this file lives).
85ROOT = Dir('.').abspath
86
87# Paths to the M5 and external source trees.
88SRCDIR = os.path.join(ROOT, 'src')
89
90# tell python where to find m5 python code
91sys.path.append(os.path.join(ROOT, 'src/python'))
92
93###################################################
94#
95# Figure out which configurations to set up based on the path(s) of
96# the target(s).
97#
98###################################################
99
100# Find default configuration & binary.
101Default(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
102
103# Ask SCons which directory it was invoked from.
104launch_dir = GetLaunchDir()
105
106# Make targets relative to invocation directory
107abs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
108 BUILD_TARGETS)
109
110# helper function: find last occurrence of element in list
111def rfind(l, elt, offs = -1):
112 for i in range(len(l)+offs, 0, -1):
113 if l[i] == elt:
114 return i
115 raise ValueError, "element not found"
116
117# Each target must have 'build' in the interior of the path; the
118# directory below this will determine the build parameters. For
119# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
120# recognize that ALPHA_SE specifies the configuration because it
121# follow 'build' in the bulid path.
122
123# Generate a list of the unique build roots and configs that the
124# collected targets reference.
125build_paths = []
126build_root = None
127for t in abs_targets:
128 path_dirs = t.split('/')
129 try:
130 build_top = rfind(path_dirs, 'build', -2)
131 except:
132 print "Error: no non-leaf 'build' dir found on target path", t
133 Exit(1)
134 this_build_root = os.path.join('/',*path_dirs[:build_top+1])
135 if not build_root:
136 build_root = this_build_root
137 else:
138 if this_build_root != build_root:
139 print "Error: build targets not under same build root\n"\
140 " %s\n %s" % (build_root, this_build_root)
141 Exit(1)
142 build_path = os.path.join('/',*path_dirs[:build_top+2])
143 if build_path not in build_paths:
144 build_paths.append(build_path)
145
146###################################################
147#
148# Set up the default build environment. This environment is copied
149# and modified according to each selected configuration.
150#
151###################################################
152
153env = Environment(ENV = os.environ, # inherit user's environment vars
154 ROOT = ROOT,
155 SRCDIR = SRCDIR)
156
157env.SConsignFile("sconsign")
158
159# I waffle on this setting... it does avoid a few painful but
160# unnecessary builds, but it also seems to make trivial builds take
161# noticeably longer.
162if False:
163 env.TargetSignatures('content')
164
165# M5_PLY is used by isa_parser.py to find the PLY package.
166env.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
167
168# Set up default C++ compiler flags
169env.Append(CCFLAGS='-pipe')
170env.Append(CCFLAGS='-fno-strict-aliasing')
171env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
172if sys.platform == 'cygwin':
173 # cygwin has some header file issues...
174 env.Append(CCFLAGS=Split("-Wno-uninitialized"))
175env.Append(CPPPATH=[Dir('ext/dnet')])
176
177# Find Python include and library directories for embedding the
178# interpreter. For consistency, we will use the same Python
179# installation used to run scons (and thus this script). If you want
180# to link in an alternate version, see above for instructions on how
181# to invoke scons with a different copy of the Python interpreter.
182
183# Get brief Python version name (e.g., "python2.4") for locating
184# include & library files
185py_version_name = 'python' + sys.version[:3]
186
187# include path, e.g. /usr/local/include/python2.4
188env.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
189env.Append(LIBS = py_version_name)
190# add library path too if it's not in the default place
191if sys.exec_prefix != '/usr':
192 env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
193
194# Other default libraries
195env.Append(LIBS=['z'])
196
197# Platform-specific configuration. Note again that we assume that all
198# builds under a given build root run on the same host platform.
199conf = Configure(env,
200 conf_dir = os.path.join(build_root, '.scons_config'),
201 log_file = os.path.join(build_root, 'scons_config.log'))
202
203# Check for <fenv.h> (C99 FP environment control)
204have_fenv = conf.CheckHeader('fenv.h', '<>')
205if not have_fenv:
206 print "Warning: Header file <fenv.h> not found."
207 print " This host has no IEEE FP rounding mode control."
208
209# Check for mysql.
210mysql_config = WhereIs('mysql_config')
211have_mysql = mysql_config != None
212
213# Check MySQL version.
214if have_mysql:
215 mysql_version = os.popen(mysql_config + ' --version').read()
216 mysql_version = mysql_version.split('.')
217 mysql_major = int(mysql_version[0])
218 mysql_minor = int(mysql_version[1])
219 # This version check is probably overly conservative, but it deals
220 # with the versions we have installed.
221 if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
222 print "Warning: MySQL v4.1 or newer required."
223 have_mysql = False
224
225# Set up mysql_config commands.
226if have_mysql:
227 mysql_config_include = mysql_config + ' --include'
228 if os.system(mysql_config_include + ' > /dev/null') != 0:
229 # older mysql_config versions don't support --include, use
230 # --cflags instead
231 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
232 # This seems to work in all versions
233 mysql_config_libs = mysql_config + ' --libs'
234
235env = conf.Finish()
236
237# Define the universe of supported ISAs
238env['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
239
240# Define the universe of supported CPU models
241env['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
242 'FullCPU', 'AlphaFullCPU']
243
244# Sticky options get saved in the options file so they persist from
245# one invocation to the next (unless overridden, in which case the new
246# value becomes sticky).
247sticky_opts = Options(args=ARGUMENTS)
248sticky_opts.AddOptions(
249 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
250 BoolOption('FULL_SYSTEM', 'Full-system support', False),
251 # There's a bug in scons 0.96.1 that causes ListOptions with list
252 # values (more than one value) not to be able to be restored from
253 # a saved option file. If this causes trouble then upgrade to
254 # scons 0.96.90 or later.
255 ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
256 env['ALL_CPU_LIST']),
257 BoolOption('ALPHA_TLASER',
258 'Model Alpha TurboLaser platform (vs. Tsunami)', False),
259 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
260 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
261 False),
262 BoolOption('SS_COMPATIBLE_FP',
263 'Make floating-point results compatible with SimpleScalar',
264 False),
265 BoolOption('USE_SSE2',
266 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
267 False),
268 BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
269 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
270 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
271 ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
272 ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
273 BoolOption('BATCH', 'Use batch pool for build and tests', False),
274 ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
275 )
276
277# Non-sticky options only apply to the current build.
278nonsticky_opts = Options(args=ARGUMENTS)
279nonsticky_opts.AddOptions(
280 BoolOption('update_ref', 'Update test reference outputs', False)
281 )
282
283# These options get exported to #defines in config/*.hh (see m5/SConscript).
284env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
285 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
286 'STATS_BINNING']
287
288# Define a handy 'no-op' action
289def no_action(target, source, env):
290 return 0
291
292env.NoAction = Action(no_action, None)
293
294###################################################
295#
296# Define a SCons builder for configuration flag headers.
297#
298###################################################
299
300# This function generates a config header file that #defines the
301# option symbol to the current option setting (0 or 1). The source
302# operands are the name of the option and a Value node containing the
303# value of the option.
304def build_config_file(target, source, env):
305 (option, value) = [s.get_contents() for s in source]
306 f = file(str(target[0]), 'w')
307 print >> f, '#define', option, value
308 f.close()
309 return None
310
311# Generate the message to be printed when building the config file.
312def build_config_file_string(target, source, env):
313 (option, value) = [s.get_contents() for s in source]
314 return "Defining %s as %s in %s." % (option, value, target[0])
315
316# Combine the two functions into a scons Action object.
317config_action = Action(build_config_file, build_config_file_string)
318
319# The emitter munges the source & target node lists to reflect what
320# we're really doing.
321def config_emitter(target, source, env):
322 # extract option name from Builder arg
323 option = str(target[0])
324 # True target is config header file
325 target = os.path.join('config', option.lower() + '.hh')
326 # Force value to 0/1 even if it's a Python bool
327 val = int(eval(str(env[option])))
328 # Sources are option name & value (packaged in SCons Value nodes)
329 return ([target], [Value(option), Value(val)])
330
331config_builder = Builder(emitter = config_emitter, action = config_action)
332
333env.Append(BUILDERS = { 'ConfigFile' : config_builder })
334
335###################################################
336#
337# Define a SCons builder for copying files. This is used by the
338# Python zipfile code in src/python/SConscript, but is placed up here
339# since it's potentially more generally applicable.
340#
341###################################################
342
343copy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
344
345env.Append(BUILDERS = { 'CopyFile' : copy_builder })
346
347###################################################
348#
349# Define a simple SCons builder to concatenate files.
350#
351# Used to append the Python zip archive to the executable.
352#
353###################################################
354
355concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
356 'chmod +x $TARGET']))
357
358env.Append(BUILDERS = { 'Concat' : concat_builder })
359
360
361# base help text
362help_text = '''
363Usage: scons [scons options] [build options] [target(s)]
364
365'''
366
367# libelf build is shared across all configs in the build root.
368env.SConscript('ext/libelf/SConscript',
369 build_dir = os.path.join(build_root, 'libelf'),
370 exports = 'env')
371
372###################################################
373#
374# Define build environments for selected configurations.
375#
376###################################################
377
378# rename base env
379base_env = env
380
381for build_path in build_paths:
382 print "Building in", build_path
383 # build_dir is the tail component of build path, and is used to
384 # determine the build parameters (e.g., 'ALPHA_SE')
385 (build_root, build_dir) = os.path.split(build_path)
386 # Make a copy of the build-root environment to use for this config.
387 env = base_env.Copy()
388
389 # Set env options according to the build directory config.
390 sticky_opts.files = []
391 # Options for $BUILD_ROOT/$BUILD_DIR are stored in
392 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
393 # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
394 current_opts_file = os.path.join(build_root, 'options', build_dir)
395 if os.path.isfile(current_opts_file):
396 sticky_opts.files.append(current_opts_file)
397 print "Using saved options file %s" % current_opts_file
398 else:
399 # Build dir-specific options file doesn't exist.
400
401 # Make sure the directory is there so we can create it later
402 opt_dir = os.path.dirname(current_opts_file)
403 if not os.path.isdir(opt_dir):
404 os.mkdir(opt_dir)
405
406 # Get default build options from source tree. Options are
407 # normally determined by name of $BUILD_DIR, but can be
408 # overriden by 'default=' arg on command line.
409 default_opts_file = os.path.join('build_opts',
410 ARGUMENTS.get('default', build_dir))
411 if os.path.isfile(default_opts_file):
412 sticky_opts.files.append(default_opts_file)
413 print "Options file %s not found,\n using defaults in %s" \
414 % (current_opts_file, default_opts_file)
415 else:
416 print "Error: cannot find options file %s or %s" \
417 % (current_opts_file, default_opts_file)
418 Exit(1)
419
420 # Apply current option settings to env
421 sticky_opts.Update(env)
422 nonsticky_opts.Update(env)
423
424 help_text += "Sticky options for %s:\n" % build_dir \
425 + sticky_opts.GenerateHelpText(env) \
426 + "\nNon-sticky options for %s:\n" % build_dir \
427 + nonsticky_opts.GenerateHelpText(env)
428
429 # Process option settings.
430
431 if not have_fenv and env['USE_FENV']:
432 print "Warning: <fenv.h> not available; " \
433 "forcing USE_FENV to False in", build_dir + "."
434 env['USE_FENV'] = False
435
436 if not env['USE_FENV']:
437 print "Warning: No IEEE FP rounding mode control in", build_dir + "."
438 print " FP results may deviate slightly from other platforms."
439
440 if env['EFENCE']:
441 env.Append(LIBS=['efence'])
442
443 if env['USE_MYSQL']:
444 if not have_mysql:
445 print "Warning: MySQL not available; " \
446 "forcing USE_MYSQL to False in", build_dir + "."
447 env['USE_MYSQL'] = False
448 else:
449 print "Compiling in", build_dir, "with MySQL support."
450 env.ParseConfig(mysql_config_libs)
451 env.ParseConfig(mysql_config_include)
452
453 # Save sticky option settings back to current options file
454 sticky_opts.Save(current_opts_file, env)
455
456 # Do this after we save setting back, or else we'll tack on an
457 # extra 'qdo' every time we run scons.
458 if env['BATCH']:
459 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC']
460 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
461
462 if env['USE_SSE2']:
463 env.Append(CCFLAGS='-msse2')
464
465 # The m5/SConscript file sets up the build rules in 'env' according
466 # to the configured options. It returns a list of environments,
467 # one for each variant build (debug, opt, etc.)
468 envList = SConscript('src/SConscript', build_dir = build_path,
469 exports = 'env', duplicate = False)
470
471 # Set up the regression tests for each build.
472# for e in envList:
473# SConscript('m5-test/SConscript',
474# build_dir = os.path.join(build_dir, 'test', e.Label),
475# exports = { 'env' : e }, duplicate = False)
476
477Help(help_text)
478
479###################################################
480#
481# Let SCons do its thing. At this point SCons will use the defined
482# build environments to build the requested targets.
483#
484###################################################
485
30
31###################################################
32#
33# SCons top-level build description (SConstruct) file.
34#
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).
39#
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# expdects that all configs under the same build directory are being
43# built for the same host system.
44#
45# Examples:
46# These two commands are equivalent. The '-u' option tells scons to
47# search up the directory tree for this SConstruct file.
48# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
49# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
50# These two commands are equivalent and demonstrate building in a
51# directory outside of the source tree. The '-C' option tells scons
52# to chdir to the specified directory to find this SConstruct file.
53# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
54# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
55#
56# You can use 'scons -H' to print scons options. If you're in this
57# 'm5' directory (or use -u or -C to tell scons where to find this
58# file), you can use 'scons -h' to print all the M5-specific build
59# options as well.
60#
61###################################################
62
63# Python library imports
64import sys
65import os
66
67# Check for recent-enough Python and SCons versions. If your system's
68# default installation of Python is not recent enough, you can use a
69# non-default installation of the Python interpreter by either (1)
70# rearranging your PATH so that scons finds the non-default 'python'
71# first or (2) explicitly invoking an alternative interpreter on the
72# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
73EnsurePythonVersion(2,4)
74
75# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
76# 3-element version number.
77min_scons_version = (0,96,91)
78try:
79 EnsureSConsVersion(*min_scons_version)
80except:
81 print "Error checking current SCons version."
82 print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
83 Exit(2)
84
85
86# The absolute path to the current directory (where this file lives).
87ROOT = Dir('.').abspath
88
89# Paths to the M5 and external source trees.
90SRCDIR = os.path.join(ROOT, 'src')
91
92# tell python where to find m5 python code
93sys.path.append(os.path.join(ROOT, 'src/python'))
94
95###################################################
96#
97# Figure out which configurations to set up based on the path(s) of
98# the target(s).
99#
100###################################################
101
102# Find default configuration & binary.
103Default(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
104
105# Ask SCons which directory it was invoked from.
106launch_dir = GetLaunchDir()
107
108# Make targets relative to invocation directory
109abs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
110 BUILD_TARGETS)
111
112# helper function: find last occurrence of element in list
113def rfind(l, elt, offs = -1):
114 for i in range(len(l)+offs, 0, -1):
115 if l[i] == elt:
116 return i
117 raise ValueError, "element not found"
118
119# Each target must have 'build' in the interior of the path; the
120# directory below this will determine the build parameters. For
121# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
122# recognize that ALPHA_SE specifies the configuration because it
123# follow 'build' in the bulid path.
124
125# Generate a list of the unique build roots and configs that the
126# collected targets reference.
127build_paths = []
128build_root = None
129for t in abs_targets:
130 path_dirs = t.split('/')
131 try:
132 build_top = rfind(path_dirs, 'build', -2)
133 except:
134 print "Error: no non-leaf 'build' dir found on target path", t
135 Exit(1)
136 this_build_root = os.path.join('/',*path_dirs[:build_top+1])
137 if not build_root:
138 build_root = this_build_root
139 else:
140 if this_build_root != build_root:
141 print "Error: build targets not under same build root\n"\
142 " %s\n %s" % (build_root, this_build_root)
143 Exit(1)
144 build_path = os.path.join('/',*path_dirs[:build_top+2])
145 if build_path not in build_paths:
146 build_paths.append(build_path)
147
148###################################################
149#
150# Set up the default build environment. This environment is copied
151# and modified according to each selected configuration.
152#
153###################################################
154
155env = Environment(ENV = os.environ, # inherit user's environment vars
156 ROOT = ROOT,
157 SRCDIR = SRCDIR)
158
159env.SConsignFile("sconsign")
160
161# I waffle on this setting... it does avoid a few painful but
162# unnecessary builds, but it also seems to make trivial builds take
163# noticeably longer.
164if False:
165 env.TargetSignatures('content')
166
167# M5_PLY is used by isa_parser.py to find the PLY package.
168env.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
169
170# Set up default C++ compiler flags
171env.Append(CCFLAGS='-pipe')
172env.Append(CCFLAGS='-fno-strict-aliasing')
173env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
174if sys.platform == 'cygwin':
175 # cygwin has some header file issues...
176 env.Append(CCFLAGS=Split("-Wno-uninitialized"))
177env.Append(CPPPATH=[Dir('ext/dnet')])
178
179# Find Python include and library directories for embedding the
180# interpreter. For consistency, we will use the same Python
181# installation used to run scons (and thus this script). If you want
182# to link in an alternate version, see above for instructions on how
183# to invoke scons with a different copy of the Python interpreter.
184
185# Get brief Python version name (e.g., "python2.4") for locating
186# include & library files
187py_version_name = 'python' + sys.version[:3]
188
189# include path, e.g. /usr/local/include/python2.4
190env.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
191env.Append(LIBS = py_version_name)
192# add library path too if it's not in the default place
193if sys.exec_prefix != '/usr':
194 env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
195
196# Other default libraries
197env.Append(LIBS=['z'])
198
199# Platform-specific configuration. Note again that we assume that all
200# builds under a given build root run on the same host platform.
201conf = Configure(env,
202 conf_dir = os.path.join(build_root, '.scons_config'),
203 log_file = os.path.join(build_root, 'scons_config.log'))
204
205# Check for <fenv.h> (C99 FP environment control)
206have_fenv = conf.CheckHeader('fenv.h', '<>')
207if not have_fenv:
208 print "Warning: Header file <fenv.h> not found."
209 print " This host has no IEEE FP rounding mode control."
210
211# Check for mysql.
212mysql_config = WhereIs('mysql_config')
213have_mysql = mysql_config != None
214
215# Check MySQL version.
216if have_mysql:
217 mysql_version = os.popen(mysql_config + ' --version').read()
218 mysql_version = mysql_version.split('.')
219 mysql_major = int(mysql_version[0])
220 mysql_minor = int(mysql_version[1])
221 # This version check is probably overly conservative, but it deals
222 # with the versions we have installed.
223 if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
224 print "Warning: MySQL v4.1 or newer required."
225 have_mysql = False
226
227# Set up mysql_config commands.
228if have_mysql:
229 mysql_config_include = mysql_config + ' --include'
230 if os.system(mysql_config_include + ' > /dev/null') != 0:
231 # older mysql_config versions don't support --include, use
232 # --cflags instead
233 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
234 # This seems to work in all versions
235 mysql_config_libs = mysql_config + ' --libs'
236
237env = conf.Finish()
238
239# Define the universe of supported ISAs
240env['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
241
242# Define the universe of supported CPU models
243env['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
244 'FullCPU', 'AlphaFullCPU']
245
246# Sticky options get saved in the options file so they persist from
247# one invocation to the next (unless overridden, in which case the new
248# value becomes sticky).
249sticky_opts = Options(args=ARGUMENTS)
250sticky_opts.AddOptions(
251 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
252 BoolOption('FULL_SYSTEM', 'Full-system support', False),
253 # There's a bug in scons 0.96.1 that causes ListOptions with list
254 # values (more than one value) not to be able to be restored from
255 # a saved option file. If this causes trouble then upgrade to
256 # scons 0.96.90 or later.
257 ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
258 env['ALL_CPU_LIST']),
259 BoolOption('ALPHA_TLASER',
260 'Model Alpha TurboLaser platform (vs. Tsunami)', False),
261 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
262 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
263 False),
264 BoolOption('SS_COMPATIBLE_FP',
265 'Make floating-point results compatible with SimpleScalar',
266 False),
267 BoolOption('USE_SSE2',
268 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
269 False),
270 BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
271 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
272 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
273 ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
274 ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
275 BoolOption('BATCH', 'Use batch pool for build and tests', False),
276 ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
277 )
278
279# Non-sticky options only apply to the current build.
280nonsticky_opts = Options(args=ARGUMENTS)
281nonsticky_opts.AddOptions(
282 BoolOption('update_ref', 'Update test reference outputs', False)
283 )
284
285# These options get exported to #defines in config/*.hh (see m5/SConscript).
286env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
287 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
288 'STATS_BINNING']
289
290# Define a handy 'no-op' action
291def no_action(target, source, env):
292 return 0
293
294env.NoAction = Action(no_action, None)
295
296###################################################
297#
298# Define a SCons builder for configuration flag headers.
299#
300###################################################
301
302# This function generates a config header file that #defines the
303# option symbol to the current option setting (0 or 1). The source
304# operands are the name of the option and a Value node containing the
305# value of the option.
306def build_config_file(target, source, env):
307 (option, value) = [s.get_contents() for s in source]
308 f = file(str(target[0]), 'w')
309 print >> f, '#define', option, value
310 f.close()
311 return None
312
313# Generate the message to be printed when building the config file.
314def build_config_file_string(target, source, env):
315 (option, value) = [s.get_contents() for s in source]
316 return "Defining %s as %s in %s." % (option, value, target[0])
317
318# Combine the two functions into a scons Action object.
319config_action = Action(build_config_file, build_config_file_string)
320
321# The emitter munges the source & target node lists to reflect what
322# we're really doing.
323def config_emitter(target, source, env):
324 # extract option name from Builder arg
325 option = str(target[0])
326 # True target is config header file
327 target = os.path.join('config', option.lower() + '.hh')
328 # Force value to 0/1 even if it's a Python bool
329 val = int(eval(str(env[option])))
330 # Sources are option name & value (packaged in SCons Value nodes)
331 return ([target], [Value(option), Value(val)])
332
333config_builder = Builder(emitter = config_emitter, action = config_action)
334
335env.Append(BUILDERS = { 'ConfigFile' : config_builder })
336
337###################################################
338#
339# Define a SCons builder for copying files. This is used by the
340# Python zipfile code in src/python/SConscript, but is placed up here
341# since it's potentially more generally applicable.
342#
343###################################################
344
345copy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
346
347env.Append(BUILDERS = { 'CopyFile' : copy_builder })
348
349###################################################
350#
351# Define a simple SCons builder to concatenate files.
352#
353# Used to append the Python zip archive to the executable.
354#
355###################################################
356
357concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
358 'chmod +x $TARGET']))
359
360env.Append(BUILDERS = { 'Concat' : concat_builder })
361
362
363# base help text
364help_text = '''
365Usage: scons [scons options] [build options] [target(s)]
366
367'''
368
369# libelf build is shared across all configs in the build root.
370env.SConscript('ext/libelf/SConscript',
371 build_dir = os.path.join(build_root, 'libelf'),
372 exports = 'env')
373
374###################################################
375#
376# Define build environments for selected configurations.
377#
378###################################################
379
380# rename base env
381base_env = env
382
383for build_path in build_paths:
384 print "Building in", build_path
385 # build_dir is the tail component of build path, and is used to
386 # determine the build parameters (e.g., 'ALPHA_SE')
387 (build_root, build_dir) = os.path.split(build_path)
388 # Make a copy of the build-root environment to use for this config.
389 env = base_env.Copy()
390
391 # Set env options according to the build directory config.
392 sticky_opts.files = []
393 # Options for $BUILD_ROOT/$BUILD_DIR are stored in
394 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
395 # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
396 current_opts_file = os.path.join(build_root, 'options', build_dir)
397 if os.path.isfile(current_opts_file):
398 sticky_opts.files.append(current_opts_file)
399 print "Using saved options file %s" % current_opts_file
400 else:
401 # Build dir-specific options file doesn't exist.
402
403 # Make sure the directory is there so we can create it later
404 opt_dir = os.path.dirname(current_opts_file)
405 if not os.path.isdir(opt_dir):
406 os.mkdir(opt_dir)
407
408 # Get default build options from source tree. Options are
409 # normally determined by name of $BUILD_DIR, but can be
410 # overriden by 'default=' arg on command line.
411 default_opts_file = os.path.join('build_opts',
412 ARGUMENTS.get('default', build_dir))
413 if os.path.isfile(default_opts_file):
414 sticky_opts.files.append(default_opts_file)
415 print "Options file %s not found,\n using defaults in %s" \
416 % (current_opts_file, default_opts_file)
417 else:
418 print "Error: cannot find options file %s or %s" \
419 % (current_opts_file, default_opts_file)
420 Exit(1)
421
422 # Apply current option settings to env
423 sticky_opts.Update(env)
424 nonsticky_opts.Update(env)
425
426 help_text += "Sticky options for %s:\n" % build_dir \
427 + sticky_opts.GenerateHelpText(env) \
428 + "\nNon-sticky options for %s:\n" % build_dir \
429 + nonsticky_opts.GenerateHelpText(env)
430
431 # Process option settings.
432
433 if not have_fenv and env['USE_FENV']:
434 print "Warning: <fenv.h> not available; " \
435 "forcing USE_FENV to False in", build_dir + "."
436 env['USE_FENV'] = False
437
438 if not env['USE_FENV']:
439 print "Warning: No IEEE FP rounding mode control in", build_dir + "."
440 print " FP results may deviate slightly from other platforms."
441
442 if env['EFENCE']:
443 env.Append(LIBS=['efence'])
444
445 if env['USE_MYSQL']:
446 if not have_mysql:
447 print "Warning: MySQL not available; " \
448 "forcing USE_MYSQL to False in", build_dir + "."
449 env['USE_MYSQL'] = False
450 else:
451 print "Compiling in", build_dir, "with MySQL support."
452 env.ParseConfig(mysql_config_libs)
453 env.ParseConfig(mysql_config_include)
454
455 # Save sticky option settings back to current options file
456 sticky_opts.Save(current_opts_file, env)
457
458 # Do this after we save setting back, or else we'll tack on an
459 # extra 'qdo' every time we run scons.
460 if env['BATCH']:
461 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC']
462 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
463
464 if env['USE_SSE2']:
465 env.Append(CCFLAGS='-msse2')
466
467 # The m5/SConscript file sets up the build rules in 'env' according
468 # to the configured options. It returns a list of environments,
469 # one for each variant build (debug, opt, etc.)
470 envList = SConscript('src/SConscript', build_dir = build_path,
471 exports = 'env', duplicate = False)
472
473 # Set up the regression tests for each build.
474# for e in envList:
475# SConscript('m5-test/SConscript',
476# build_dir = os.path.join(build_dir, 'test', e.Label),
477# exports = { 'env' : e }, duplicate = False)
478
479Help(help_text)
480
481###################################################
482#
483# Let SCons do its thing. At this point SCons will use the defined
484# build environments to build the requested targets.
485#
486###################################################
487