SConstruct (5863:f73e06bc8765) SConstruct (5871:8007803be77a)
1# -*- mode:python -*-
2
1# -*- mode:python -*-
2
3# Copyright (c) 2009 The Hewlett-Packard Development Company
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
30# Nathan Binkert
31
32###################################################
33#
34# SCons top-level build description (SConstruct) file.
35#
36# While in this directory ('m5'), just type 'scons' to build the default
37# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
38# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
39# the optimized full-system version).
40#
41# You can build M5 in a different directory as long as there is a
42# 'build/<CONFIG>' somewhere along the target path. The build system
43# expects that all configs under the same build directory are being
44# built for the same host system.
45#
46# Examples:
47#
48# The following two commands are equivalent. The '-u' option tells
49# scons to search up the directory tree for this SConstruct file.
50# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
51# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
52#
53# The following two commands are equivalent and demonstrate building
54# in a directory outside of the source tree. The '-C' option tells
55# scons to chdir to the specified directory to find this SConstruct
56# file.
57# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
58# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
59#
60# You can use 'scons -H' to print scons options. If you're in this
61# 'm5' directory (or use -u or -C to tell scons where to find this
62# file), you can use 'scons -h' to print all the M5-specific build
63# options as well.
64#
65###################################################
66
67# Check for recent-enough Python and SCons versions.
68try:
69 # Really old versions of scons only take two options for the
70 # function, so check once without the revision and once with the
71 # revision, the first instance will fail for stuff other than
72 # 0.98, and the second will fail for 0.98.0
73 EnsureSConsVersion(0, 98)
74 EnsureSConsVersion(0, 98, 1)
75except SystemExit, e:
76 print """
77For more details, see:
78 http://m5sim.org/wiki/index.php/Compiling_M5
79"""
80 raise
81
82# We ensure the python version early because we have stuff that
83# requires python 2.4
84try:
85 EnsurePythonVersion(2, 4)
86except SystemExit, e:
87 print """
88You can use a non-default installation of the Python interpreter by
89either (1) rearranging your PATH so that scons finds the non-default
90'python' first or (2) explicitly invoking an alternative interpreter
91on the scons script.
92
93For more details, see:
94 http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation
95"""
96 raise
97
98import os
99import re
100import subprocess
101import sys
102
103from os import mkdir, environ
104from os.path import abspath, basename, dirname, expanduser, normpath
105from os.path import exists, isdir, isfile
106from os.path import join as joinpath, split as splitpath
107
108import SCons
4# Copyright (c) 2004-2005 The Regents of The University of Michigan
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are
9# met: redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer;
11# redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution;
14# neither the name of the copyright holders nor the names of its
15# contributors may be used to endorse or promote products derived from
16# this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29#
30# Authors: Steve Reinhardt
31# Nathan Binkert
32
33###################################################
34#
35# SCons top-level build description (SConstruct) file.
36#
37# While in this directory ('m5'), just type 'scons' to build the default
38# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
39# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
40# the optimized full-system version).
41#
42# You can build M5 in a different directory as long as there is a
43# 'build/<CONFIG>' somewhere along the target path. The build system
44# expects that all configs under the same build directory are being
45# built for the same host system.
46#
47# Examples:
48#
49# The following two commands are equivalent. The '-u' option tells
50# scons to search up the directory tree for this SConstruct file.
51# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
52# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
53#
54# The following two commands are equivalent and demonstrate building
55# in a directory outside of the source tree. The '-C' option tells
56# scons to chdir to the specified directory to find this SConstruct
57# file.
58# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
59# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
60#
61# You can use 'scons -H' to print scons options. If you're in this
62# 'm5' directory (or use -u or -C to tell scons where to find this
63# file), you can use 'scons -h' to print all the M5-specific build
64# options as well.
65#
66###################################################
67
68# Check for recent-enough Python and SCons versions.
69try:
70 # Really old versions of scons only take two options for the
71 # function, so check once without the revision and once with the
72 # revision, the first instance will fail for stuff other than
73 # 0.98, and the second will fail for 0.98.0
74 EnsureSConsVersion(0, 98)
75 EnsureSConsVersion(0, 98, 1)
76except SystemExit, e:
77 print """
78For more details, see:
79 http://m5sim.org/wiki/index.php/Compiling_M5
80"""
81 raise
82
83# We ensure the python version early because we have stuff that
84# requires python 2.4
85try:
86 EnsurePythonVersion(2, 4)
87except SystemExit, e:
88 print """
89You can use a non-default installation of the Python interpreter by
90either (1) rearranging your PATH so that scons finds the non-default
91'python' first or (2) explicitly invoking an alternative interpreter
92on the scons script.
93
94For more details, see:
95 http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation
96"""
97 raise
98
99import os
100import re
101import subprocess
102import sys
103
104from os import mkdir, environ
105from os.path import abspath, basename, dirname, expanduser, normpath
106from os.path import exists, isdir, isfile
107from os.path import join as joinpath, split as splitpath
108
109import SCons
110import SCons.Node
109
111
110def read_command(cmd):
112def read_command(cmd, **kwargs):
111 """run the command cmd, read the results and return them
112 this is sorta like `cmd` in shell"""
113 from subprocess import Popen, PIPE, STDOUT
113 """run the command cmd, read the results and return them
114 this is sorta like `cmd` in shell"""
115 from subprocess import Popen, PIPE, STDOUT
114 subp = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT, close_fds=True)
116
117 no_exception = 'exception' in kwargs
118 exception = kwargs.pop('exception', None)
119
120 kwargs.setdefault('shell', False)
121 kwargs.setdefault('stdout', PIPE)
122 kwargs.setdefault('stderr', STDOUT)
123 kwargs.setdefault('close_fds', True)
124 try:
125 subp = Popen(cmd, **kwargs)
126 except Exception, e:
127 if no_exception:
128 return exception
129 raise
130
115 return subp.communicate()[0]
116
117# helper function: compare arrays or strings of version numbers.
118# E.g., compare_version((1,3,25), (1,4,1)')
119# returns -1, 0, 1 if v1 is <, ==, > v2
120def compare_versions(v1, v2):
121 def make_version_list(v):
122 if isinstance(v, (list,tuple)):
123 return v
124 elif isinstance(v, str):
125 return map(lambda x: int(re.match('\d+', x).group()), v.split('.'))
126 else:
127 raise TypeError
128
129 v1 = make_version_list(v1)
130 v2 = make_version_list(v2)
131 # Compare corresponding elements of lists
132 for n1,n2 in zip(v1, v2):
133 if n1 < n2: return -1
134 if n1 > n2: return 1
135 # all corresponding values are equal... see if one has extra values
136 if len(v1) < len(v2): return -1
137 if len(v1) > len(v2): return 1
138 return 0
139
131 return subp.communicate()[0]
132
133# helper function: compare arrays or strings of version numbers.
134# E.g., compare_version((1,3,25), (1,4,1)')
135# returns -1, 0, 1 if v1 is <, ==, > v2
136def compare_versions(v1, v2):
137 def make_version_list(v):
138 if isinstance(v, (list,tuple)):
139 return v
140 elif isinstance(v, str):
141 return map(lambda x: int(re.match('\d+', x).group()), v.split('.'))
142 else:
143 raise TypeError
144
145 v1 = make_version_list(v1)
146 v2 = make_version_list(v2)
147 # Compare corresponding elements of lists
148 for n1,n2 in zip(v1, v2):
149 if n1 < n2: return -1
150 if n1 > n2: return 1
151 # all corresponding values are equal... see if one has extra values
152 if len(v1) < len(v2): return -1
153 if len(v1) > len(v2): return 1
154 return 0
155
140# The absolute path to the current directory (where this file lives).
141ROOT = Dir('.').abspath
156########################################################################
157#
158# Set up the base build environment.
159#
160########################################################################
161use_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'PATH', 'RANLIB' ])
142
162
143# Path to the M5 source tree.
144SRCDIR = joinpath(ROOT, 'src')
163use_env = {}
164for key,val in os.environ.iteritems():
165 if key in use_vars or key.startswith("M5"):
166 use_env[key] = val
145
167
146# tell python where to find m5 python code
147sys.path.append(joinpath(ROOT, 'src/python'))
168env = Environment(ENV=use_env)
169env.root = Dir(".") # The current directory (where this file lives).
170env.srcdir = Dir("src") # The source directory
148
171
149###################################################
172########################################################################
173#
150# Mercurial Stuff.
174# Mercurial Stuff.
151# 1) Grab repository revision if we know it.
152# 2) Ensure that the style hook is in place.
153###################################################
175#
176# If the M5 directory is a mercurial repository, we should do some
177# extra things.
178#
179########################################################################
154
180
155hg_info = "Unknown"
156try:
157 if not exists(ROOT) or not isdir(ROOT) or \
158 not exists(joinpath(ROOT, ".hg")):
159 raise ValueError(".hg directory not found")
160 hg_info = read_command("cd %s; hg id -n -i -t -b" % ROOT).strip()
161except ImportError, e:
162 print "Mercurial not found"
163except ValueError, e:
164 print e
165except Exception, e:
166 print "Other mercurial exception: %s" % e
181hgdir = env.root.Dir(".hg")
167
182
168def check_style_hook(ui):
169 ui.readconfig(joinpath(ROOT, '.hg', 'hgrc'))
170 style_hook = ui.config('hooks', 'pretxncommit.style', None)
171
172 if not style_hook:
173 print """\
183mercurial_style_message = """
174You're missing the M5 style hook.
175Please install the hook so we can ensure that all code fits a common style.
176
177All you'd need to do is add the following lines to your repository .hg/hgrc
178or your personal .hgrc
179----------------
180
181[extensions]
182style = %s/util/style.py
183
184[hooks]
185pretxncommit.style = python:style.check_whitespace
184You're missing the M5 style hook.
185Please install the hook so we can ensure that all code fits a common style.
186
187All you'd need to do is add the following lines to your repository .hg/hgrc
188or your personal .hgrc
189----------------
190
191[extensions]
192style = %s/util/style.py
193
194[hooks]
195pretxncommit.style = python:style.check_whitespace
186""" % (ROOT)
187 sys.exit(1)
196""" % (env.root)
188
197
189if ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')):
198mercurial_bin_not_found = """
199Mercurial binary cannot be found, unfortunately this means that we
200cannot easily determine the version of M5 that you are running and
201this makes error messages more difficult to collect. Please consider
202installing mercurial if you choose to post an error message
203"""
204
205mercurial_lib_not_found = """
206Mercurial libraries cannot be found, ignoring style hook
207If you are actually a M5 developer, please fix this and
208run the style hook. It is important.
209"""
210
211if hgdir.exists():
212 # 1) Grab repository revision if we know it.
213 cmd = "hg id -n -i -t -b"
190 try:
214 try:
191 from mercurial import ui
192 check_style_hook(ui.ui())
215 hg_info = read_command(cmd, cwd=env.root.abspath).strip()
216 except OSError:
217 hg_info = "Unknown"
218 print mercurial_bin_not_found
219
220 env['HG_INFO'] = hg_info
221
222 # 2) Ensure that the style hook is in place.
223 try:
224 ui = None
225 if ARGUMENTS.get('IGNORE_STYLE') != 'True':
226 from mercurial import ui
227 ui = ui.ui()
193 except ImportError:
228 except ImportError:
194 pass
229 print mercurial_lib_not_found
195
230
231 if ui is not None:
232 ui.readconfig(hgdir.File('hgrc').abspath)
233 style_hook = ui.config('hooks', 'pretxncommit.style', None)
196
234
235 if not style_hook:
236 print mercurial_style_message
237 sys.exit(1)
238else:
239 print ".hg directory not found"
240
197###################################################
198#
199# Figure out which configurations to set up based on the path(s) of
200# the target(s).
201#
202###################################################
203
204# Find default configuration & binary.
205Default(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
206
207# helper function: find last occurrence of element in list
208def rfind(l, elt, offs = -1):
209 for i in range(len(l)+offs, 0, -1):
210 if l[i] == elt:
211 return i
212 raise ValueError, "element not found"
213
214# Each target must have 'build' in the interior of the path; the
215# directory below this will determine the build parameters. For
216# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
217# recognize that ALPHA_SE specifies the configuration because it
218# follow 'build' in the bulid path.
219
220# Generate absolute paths to targets so we can see where the build dir is
221if COMMAND_LINE_TARGETS:
222 # Ask SCons which directory it was invoked from
223 launch_dir = GetLaunchDir()
224 # Make targets relative to invocation directory
225 abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \
226 COMMAND_LINE_TARGETS]
227else:
228 # Default targets are relative to root of tree
229 abs_targets = [ normpath(joinpath(ROOT, str(x))) for x in \
230 DEFAULT_TARGETS]
231
232
233# Generate a list of the unique build roots and configs that the
234# collected targets reference.
235variant_paths = []
236build_root = None
237for t in abs_targets:
238 path_dirs = t.split('/')
239 try:
240 build_top = rfind(path_dirs, 'build', -2)
241 except:
242 print "Error: no non-leaf 'build' dir found on target path", t
243 Exit(1)
244 this_build_root = joinpath('/',*path_dirs[:build_top+1])
245 if not build_root:
246 build_root = this_build_root
247 else:
248 if this_build_root != build_root:
249 print "Error: build targets not under same build root\n"\
250 " %s\n %s" % (build_root, this_build_root)
251 Exit(1)
252 variant_path = joinpath('/',*path_dirs[:build_top+2])
253 if variant_path not in variant_paths:
254 variant_paths.append(variant_path)
255
256# Make sure build_root exists (might not if this is the first build there)
257if not isdir(build_root):
258 mkdir(build_root)
259
241###################################################
242#
243# Figure out which configurations to set up based on the path(s) of
244# the target(s).
245#
246###################################################
247
248# Find default configuration & binary.
249Default(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
250
251# helper function: find last occurrence of element in list
252def rfind(l, elt, offs = -1):
253 for i in range(len(l)+offs, 0, -1):
254 if l[i] == elt:
255 return i
256 raise ValueError, "element not found"
257
258# Each target must have 'build' in the interior of the path; the
259# directory below this will determine the build parameters. For
260# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
261# recognize that ALPHA_SE specifies the configuration because it
262# follow 'build' in the bulid path.
263
264# Generate absolute paths to targets so we can see where the build dir is
265if COMMAND_LINE_TARGETS:
266 # Ask SCons which directory it was invoked from
267 launch_dir = GetLaunchDir()
268 # Make targets relative to invocation directory
269 abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \
270 COMMAND_LINE_TARGETS]
271else:
272 # Default targets are relative to root of tree
273 abs_targets = [ normpath(joinpath(ROOT, str(x))) for x in \
274 DEFAULT_TARGETS]
275
276
277# Generate a list of the unique build roots and configs that the
278# collected targets reference.
279variant_paths = []
280build_root = None
281for t in abs_targets:
282 path_dirs = t.split('/')
283 try:
284 build_top = rfind(path_dirs, 'build', -2)
285 except:
286 print "Error: no non-leaf 'build' dir found on target path", t
287 Exit(1)
288 this_build_root = joinpath('/',*path_dirs[:build_top+1])
289 if not build_root:
290 build_root = this_build_root
291 else:
292 if this_build_root != build_root:
293 print "Error: build targets not under same build root\n"\
294 " %s\n %s" % (build_root, this_build_root)
295 Exit(1)
296 variant_path = joinpath('/',*path_dirs[:build_top+2])
297 if variant_path not in variant_paths:
298 variant_paths.append(variant_path)
299
300# Make sure build_root exists (might not if this is the first build there)
301if not isdir(build_root):
302 mkdir(build_root)
303
260###################################################
261#
262# Set up the default build environment. This environment is copied
263# and modified according to each selected configuration.
264#
265###################################################
266
267env = Environment(ENV = environ, # inherit user's environment vars
268 ROOT = ROOT,
269 SRCDIR = SRCDIR,
270 HG_INFO = hg_info)
271
272Export('env')
273
274env.SConsignFile(joinpath(build_root, "sconsign"))
275
276# Default duplicate option is to use hard links, but this messes up
277# when you use emacs to edit a file in the target dir, as emacs moves
278# file to file~ then copies to file, breaking the link. Symbolic
279# (soft) links work better.
280env.SetOption('duplicate', 'soft-copy')
281
282#
283# Set up global sticky variables... these are common to an entire build
284# tree (not specific to a particular build like ALPHA_SE)
285#
286
287# Variable validators & converters for global sticky variables
288def PathListMakeAbsolute(val):
289 if not val:
290 return val
291 f = lambda p: abspath(expanduser(p))
292 return ':'.join(map(f, val.split(':')))
293
294def PathListAllExist(key, val, env):
295 if not val:
296 return
297 paths = val.split(':')
298 for path in paths:
299 if not isdir(path):
300 raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
301
302global_sticky_vars_file = joinpath(build_root, 'variables.global')
303
304global_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS)
305
306global_sticky_vars.AddVariables(
307 ('CC', 'C compiler', environ.get('CC', env['CC'])),
308 ('CXX', 'C++ compiler', environ.get('CXX', env['CXX'])),
309 ('BATCH', 'Use batch pool for build and tests', False),
310 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
311 ('EXTRAS', 'Add Extra directories to the compilation', '',
312 PathListAllExist, PathListMakeAbsolute)
313 )
314
315# base help text
316help_text = '''
317Usage: scons [scons options] [build options] [target(s)]
318
319Global sticky options:
320'''
321
322help_text += global_sticky_vars.GenerateHelpText(env)
323
324# Update env with values from ARGUMENTS & file global_sticky_vars_file
325global_sticky_vars.Update(env)
326
327# Save sticky variable settings back to current variables file
328global_sticky_vars.Save(global_sticky_vars_file, env)
329
330# Parse EXTRAS variable to build list of all directories where we're
331# look for sources etc. This list is exported as base_dir_list.
304Export('env')
305
306env.SConsignFile(joinpath(build_root, "sconsign"))
307
308# Default duplicate option is to use hard links, but this messes up
309# when you use emacs to edit a file in the target dir, as emacs moves
310# file to file~ then copies to file, breaking the link. Symbolic
311# (soft) links work better.
312env.SetOption('duplicate', 'soft-copy')
313
314#
315# Set up global sticky variables... these are common to an entire build
316# tree (not specific to a particular build like ALPHA_SE)
317#
318
319# Variable validators & converters for global sticky variables
320def PathListMakeAbsolute(val):
321 if not val:
322 return val
323 f = lambda p: abspath(expanduser(p))
324 return ':'.join(map(f, val.split(':')))
325
326def PathListAllExist(key, val, env):
327 if not val:
328 return
329 paths = val.split(':')
330 for path in paths:
331 if not isdir(path):
332 raise SCons.Errors.UserError("Path does not exist: '%s'" % path)
333
334global_sticky_vars_file = joinpath(build_root, 'variables.global')
335
336global_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS)
337
338global_sticky_vars.AddVariables(
339 ('CC', 'C compiler', environ.get('CC', env['CC'])),
340 ('CXX', 'C++ compiler', environ.get('CXX', env['CXX'])),
341 ('BATCH', 'Use batch pool for build and tests', False),
342 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'),
343 ('EXTRAS', 'Add Extra directories to the compilation', '',
344 PathListAllExist, PathListMakeAbsolute)
345 )
346
347# base help text
348help_text = '''
349Usage: scons [scons options] [build options] [target(s)]
350
351Global sticky options:
352'''
353
354help_text += global_sticky_vars.GenerateHelpText(env)
355
356# Update env with values from ARGUMENTS & file global_sticky_vars_file
357global_sticky_vars.Update(env)
358
359# Save sticky variable settings back to current variables file
360global_sticky_vars.Save(global_sticky_vars_file, env)
361
362# Parse EXTRAS variable to build list of all directories where we're
363# look for sources etc. This list is exported as base_dir_list.
332base_dir = joinpath(ROOT, 'src')
364base_dir = env.srcdir.abspath
333if env['EXTRAS']:
334 extras_dir_list = env['EXTRAS'].split(':')
335else:
336 extras_dir_list = []
337
338Export('base_dir')
339Export('extras_dir_list')
340
341# M5_PLY is used by isa_parser.py to find the PLY package.
342env.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) })
365if env['EXTRAS']:
366 extras_dir_list = env['EXTRAS'].split(':')
367else:
368 extras_dir_list = []
369
370Export('base_dir')
371Export('extras_dir_list')
372
373# M5_PLY is used by isa_parser.py to find the PLY package.
374env.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) })
343env['GCC'] = read_command(env['CXX'] + ' --version').find('g++') >= 0
344env['SUNCC'] = read_command(env['CXX'] + ' -V').find('Sun C++') >= 0
345env['ICC'] = read_command(env['CXX'] + ' -V').find('Intel') >= 0
375
376CXX_version = read_command([env['CXX'],'--version'], exception=False)
377CXX_V = read_command([env['CXX'],'-V'], exception=False)
378
379env['GCC'] = CXX_version and CXX_version.find('g++') >= 0
380env['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0
381env['ICC'] = CXX_V and CXX_V.find('Intel') >= 0
346if env['GCC'] + env['SUNCC'] + env['ICC'] > 1:
347 print 'Error: How can we have two at the same time?'
348 Exit(1)
349
350# Set up default C++ compiler flags
351if env['GCC']:
352 env.Append(CCFLAGS='-pipe')
353 env.Append(CCFLAGS='-fno-strict-aliasing')
354 env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
355 env.Append(CXXFLAGS='-Wno-deprecated')
356elif env['ICC']:
357 pass #Fix me... add warning flags once we clean up icc warnings
358elif env['SUNCC']:
359 env.Append(CCFLAGS='-Qoption ccfe')
360 env.Append(CCFLAGS='-features=gcc')
361 env.Append(CCFLAGS='-features=extensions')
362 env.Append(CCFLAGS='-library=stlport4')
363 env.Append(CCFLAGS='-xar')
382if env['GCC'] + env['SUNCC'] + env['ICC'] > 1:
383 print 'Error: How can we have two at the same time?'
384 Exit(1)
385
386# Set up default C++ compiler flags
387if env['GCC']:
388 env.Append(CCFLAGS='-pipe')
389 env.Append(CCFLAGS='-fno-strict-aliasing')
390 env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
391 env.Append(CXXFLAGS='-Wno-deprecated')
392elif env['ICC']:
393 pass #Fix me... add warning flags once we clean up icc warnings
394elif env['SUNCC']:
395 env.Append(CCFLAGS='-Qoption ccfe')
396 env.Append(CCFLAGS='-features=gcc')
397 env.Append(CCFLAGS='-features=extensions')
398 env.Append(CCFLAGS='-library=stlport4')
399 env.Append(CCFLAGS='-xar')
364# env.Append(CCFLAGS='-instances=semiexplicit')
400 #env.Append(CCFLAGS='-instances=semiexplicit')
365else:
366 print 'Error: Don\'t know what compiler options to use for your compiler.'
367 print ' Please fix SConstruct and src/SConscript and try again.'
368 Exit(1)
369
370# Do this after we save setting back, or else we'll tack on an
371# extra 'qdo' every time we run scons.
372if env['BATCH']:
373 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC']
374 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
375 env['AS'] = env['BATCH_CMD'] + ' ' + env['AS']
376 env['AR'] = env['BATCH_CMD'] + ' ' + env['AR']
377 env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB']
378
379if sys.platform == 'cygwin':
380 # cygwin has some header file issues...
381 env.Append(CCFLAGS=Split("-Wno-uninitialized"))
382env.Append(CPPPATH=[Dir('ext/dnet')])
383
384# Check for SWIG
385if not env.has_key('SWIG'):
386 print 'Error: SWIG utility not found.'
387 print ' Please install (see http://www.swig.org) and retry.'
388 Exit(1)
389
390# Check for appropriate SWIG version
401else:
402 print 'Error: Don\'t know what compiler options to use for your compiler.'
403 print ' Please fix SConstruct and src/SConscript and try again.'
404 Exit(1)
405
406# Do this after we save setting back, or else we'll tack on an
407# extra 'qdo' every time we run scons.
408if env['BATCH']:
409 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC']
410 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
411 env['AS'] = env['BATCH_CMD'] + ' ' + env['AS']
412 env['AR'] = env['BATCH_CMD'] + ' ' + env['AR']
413 env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB']
414
415if sys.platform == 'cygwin':
416 # cygwin has some header file issues...
417 env.Append(CCFLAGS=Split("-Wno-uninitialized"))
418env.Append(CPPPATH=[Dir('ext/dnet')])
419
420# Check for SWIG
421if not env.has_key('SWIG'):
422 print 'Error: SWIG utility not found.'
423 print ' Please install (see http://www.swig.org) and retry.'
424 Exit(1)
425
426# Check for appropriate SWIG version
391swig_version = read_command('swig -version').split()
427swig_version = read_command(('swig', '-version'), exception='').split()
392# First 3 words should be "SWIG Version x.y.z"
393if len(swig_version) < 3 or \
394 swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
395 print 'Error determining SWIG version.'
396 Exit(1)
397
398min_swig_version = '1.3.28'
399if compare_versions(swig_version[2], min_swig_version) < 0:
400 print 'Error: SWIG version', min_swig_version, 'or newer required.'
401 print ' Installed version:', swig_version[2]
402 Exit(1)
403
404# Set up SWIG flags & scanner
405swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
406env.Append(SWIGFLAGS=swig_flags)
407
408# filter out all existing swig scanners, they mess up the dependency
409# stuff for some reason
410scanners = []
411for scanner in env['SCANNERS']:
412 skeys = scanner.skeys
413 if skeys == '.i':
414 continue
415
416 if isinstance(skeys, (list, tuple)) and '.i' in skeys:
417 continue
418
419 scanners.append(scanner)
420
421# add the new swig scanner that we like better
422from SCons.Scanner import ClassicCPP as CPPScanner
423swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
424scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
425
426# replace the scanners list that has what we want
427env['SCANNERS'] = scanners
428
429# Add a custom Check function to the Configure context so that we can
430# figure out if the compiler adds leading underscores to global
431# variables. This is needed for the autogenerated asm files that we
432# use for embedding the python code.
433def CheckLeading(context):
434 context.Message("Checking for leading underscore in global variables...")
435 # 1) Define a global variable called x from asm so the C compiler
436 # won't change the symbol at all.
437 # 2) Declare that variable.
438 # 3) Use the variable
439 #
440 # If the compiler prepends an underscore, this will successfully
441 # link because the external symbol 'x' will be called '_x' which
442 # was defined by the asm statement. If the compiler does not
443 # prepend an underscore, this will not successfully link because
444 # '_x' will have been defined by assembly, while the C portion of
445 # the code will be trying to use 'x'
446 ret = context.TryLink('''
447 asm(".globl _x; _x: .byte 0");
448 extern int x;
449 int main() { return x; }
450 ''', extension=".c")
451 context.env.Append(LEADING_UNDERSCORE=ret)
452 context.Result(ret)
453 return ret
454
455# Platform-specific configuration. Note again that we assume that all
456# builds under a given build root run on the same host platform.
457conf = Configure(env,
458 conf_dir = joinpath(build_root, '.scons_config'),
459 log_file = joinpath(build_root, 'scons_config.log'),
460 custom_tests = { 'CheckLeading' : CheckLeading })
461
462# Check for leading underscores. Don't really need to worry either
463# way so don't need to check the return code.
464conf.CheckLeading()
465
466# Check if we should compile a 64 bit binary on Mac OS X/Darwin
467try:
468 import platform
469 uname = platform.uname()
470 if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
471 if int(read_command('sysctl -n hw.cpu64bit_capable')[0]):
472 env.Append(CCFLAGS='-arch x86_64')
473 env.Append(CFLAGS='-arch x86_64')
474 env.Append(LINKFLAGS='-arch x86_64')
475 env.Append(ASFLAGS='-arch x86_64')
476except:
477 pass
478
479# Recent versions of scons substitute a "Null" object for Configure()
480# when configuration isn't necessary, e.g., if the "--help" option is
481# present. Unfortuantely this Null object always returns false,
482# breaking all our configuration checks. We replace it with our own
483# more optimistic null object that returns True instead.
484if not conf:
485 def NullCheck(*args, **kwargs):
486 return True
487
488 class NullConf:
489 def __init__(self, env):
490 self.env = env
491 def Finish(self):
492 return self.env
493 def __getattr__(self, mname):
494 return NullCheck
495
496 conf = NullConf(env)
497
498# Find Python include and library directories for embedding the
499# interpreter. For consistency, we will use the same Python
500# installation used to run scons (and thus this script). If you want
501# to link in an alternate version, see above for instructions on how
502# to invoke scons with a different copy of the Python interpreter.
503from distutils import sysconfig
504
505py_getvar = sysconfig.get_config_var
506
507py_version = 'python' + py_getvar('VERSION')
508
509py_general_include = sysconfig.get_python_inc()
510py_platform_include = sysconfig.get_python_inc(plat_specific=True)
511py_includes = [ py_general_include ]
512if py_platform_include != py_general_include:
513 py_includes.append(py_platform_include)
514
515py_lib_path = []
516# add the prefix/lib/pythonX.Y/config dir, but only if there is no
517# shared library in prefix/lib/.
518if not py_getvar('Py_ENABLE_SHARED'):
519 py_lib_path.append('-L' + py_getvar('LIBPL'))
520
521py_libs = []
522for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
523 if lib not in py_libs:
524 py_libs.append(lib)
525py_libs.append('-l' + py_version)
526
527env.Append(CPPPATH=py_includes)
528env.Append(LIBPATH=py_lib_path)
529#env.Append(LIBS=py_libs)
530
531# verify that this stuff works
532if not conf.CheckHeader('Python.h', '<>'):
533 print "Error: can't find Python.h header in", py_includes
534 Exit(1)
535
536for lib in py_libs:
537 assert lib.startswith('-l')
538 lib = lib[2:]
539 if not conf.CheckLib(lib):
540 print "Error: can't find library %s required by python" % lib
541 Exit(1)
542
543# On Solaris you need to use libsocket for socket ops
544if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
545 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
546 print "Can't find library with socket calls (e.g. accept())"
547 Exit(1)
548
549# Check for zlib. If the check passes, libz will be automatically
550# added to the LIBS environment variable.
551if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
552 print 'Error: did not find needed zlib compression library '\
553 'and/or zlib.h header file.'
554 print ' Please install zlib and try again.'
555 Exit(1)
556
557# Check for <fenv.h> (C99 FP environment control)
558have_fenv = conf.CheckHeader('fenv.h', '<>')
559if not have_fenv:
560 print "Warning: Header file <fenv.h> not found."
561 print " This host has no IEEE FP rounding mode control."
562
563######################################################################
564#
565# Check for mysql.
566#
567mysql_config = WhereIs('mysql_config')
568have_mysql = bool(mysql_config)
569
570# Check MySQL version.
571if have_mysql:
572 mysql_version = read_command(mysql_config + ' --version')
573 min_mysql_version = '4.1'
574 if compare_versions(mysql_version, min_mysql_version) < 0:
575 print 'Warning: MySQL', min_mysql_version, 'or newer required.'
576 print ' Version', mysql_version, 'detected.'
577 have_mysql = False
578
579# Set up mysql_config commands.
580if have_mysql:
581 mysql_config_include = mysql_config + ' --include'
582 if os.system(mysql_config_include + ' > /dev/null') != 0:
583 # older mysql_config versions don't support --include, use
584 # --cflags instead
585 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
586 # This seems to work in all versions
587 mysql_config_libs = mysql_config + ' --libs'
588
589######################################################################
590#
591# Finish the configuration
592#
593env = conf.Finish()
594
595######################################################################
596#
597# Collect all non-global variables
598#
599
428# First 3 words should be "SWIG Version x.y.z"
429if len(swig_version) < 3 or \
430 swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
431 print 'Error determining SWIG version.'
432 Exit(1)
433
434min_swig_version = '1.3.28'
435if compare_versions(swig_version[2], min_swig_version) < 0:
436 print 'Error: SWIG version', min_swig_version, 'or newer required.'
437 print ' Installed version:', swig_version[2]
438 Exit(1)
439
440# Set up SWIG flags & scanner
441swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS')
442env.Append(SWIGFLAGS=swig_flags)
443
444# filter out all existing swig scanners, they mess up the dependency
445# stuff for some reason
446scanners = []
447for scanner in env['SCANNERS']:
448 skeys = scanner.skeys
449 if skeys == '.i':
450 continue
451
452 if isinstance(skeys, (list, tuple)) and '.i' in skeys:
453 continue
454
455 scanners.append(scanner)
456
457# add the new swig scanner that we like better
458from SCons.Scanner import ClassicCPP as CPPScanner
459swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
460scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re))
461
462# replace the scanners list that has what we want
463env['SCANNERS'] = scanners
464
465# Add a custom Check function to the Configure context so that we can
466# figure out if the compiler adds leading underscores to global
467# variables. This is needed for the autogenerated asm files that we
468# use for embedding the python code.
469def CheckLeading(context):
470 context.Message("Checking for leading underscore in global variables...")
471 # 1) Define a global variable called x from asm so the C compiler
472 # won't change the symbol at all.
473 # 2) Declare that variable.
474 # 3) Use the variable
475 #
476 # If the compiler prepends an underscore, this will successfully
477 # link because the external symbol 'x' will be called '_x' which
478 # was defined by the asm statement. If the compiler does not
479 # prepend an underscore, this will not successfully link because
480 # '_x' will have been defined by assembly, while the C portion of
481 # the code will be trying to use 'x'
482 ret = context.TryLink('''
483 asm(".globl _x; _x: .byte 0");
484 extern int x;
485 int main() { return x; }
486 ''', extension=".c")
487 context.env.Append(LEADING_UNDERSCORE=ret)
488 context.Result(ret)
489 return ret
490
491# Platform-specific configuration. Note again that we assume that all
492# builds under a given build root run on the same host platform.
493conf = Configure(env,
494 conf_dir = joinpath(build_root, '.scons_config'),
495 log_file = joinpath(build_root, 'scons_config.log'),
496 custom_tests = { 'CheckLeading' : CheckLeading })
497
498# Check for leading underscores. Don't really need to worry either
499# way so don't need to check the return code.
500conf.CheckLeading()
501
502# Check if we should compile a 64 bit binary on Mac OS X/Darwin
503try:
504 import platform
505 uname = platform.uname()
506 if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0:
507 if int(read_command('sysctl -n hw.cpu64bit_capable')[0]):
508 env.Append(CCFLAGS='-arch x86_64')
509 env.Append(CFLAGS='-arch x86_64')
510 env.Append(LINKFLAGS='-arch x86_64')
511 env.Append(ASFLAGS='-arch x86_64')
512except:
513 pass
514
515# Recent versions of scons substitute a "Null" object for Configure()
516# when configuration isn't necessary, e.g., if the "--help" option is
517# present. Unfortuantely this Null object always returns false,
518# breaking all our configuration checks. We replace it with our own
519# more optimistic null object that returns True instead.
520if not conf:
521 def NullCheck(*args, **kwargs):
522 return True
523
524 class NullConf:
525 def __init__(self, env):
526 self.env = env
527 def Finish(self):
528 return self.env
529 def __getattr__(self, mname):
530 return NullCheck
531
532 conf = NullConf(env)
533
534# Find Python include and library directories for embedding the
535# interpreter. For consistency, we will use the same Python
536# installation used to run scons (and thus this script). If you want
537# to link in an alternate version, see above for instructions on how
538# to invoke scons with a different copy of the Python interpreter.
539from distutils import sysconfig
540
541py_getvar = sysconfig.get_config_var
542
543py_version = 'python' + py_getvar('VERSION')
544
545py_general_include = sysconfig.get_python_inc()
546py_platform_include = sysconfig.get_python_inc(plat_specific=True)
547py_includes = [ py_general_include ]
548if py_platform_include != py_general_include:
549 py_includes.append(py_platform_include)
550
551py_lib_path = []
552# add the prefix/lib/pythonX.Y/config dir, but only if there is no
553# shared library in prefix/lib/.
554if not py_getvar('Py_ENABLE_SHARED'):
555 py_lib_path.append('-L' + py_getvar('LIBPL'))
556
557py_libs = []
558for lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split():
559 if lib not in py_libs:
560 py_libs.append(lib)
561py_libs.append('-l' + py_version)
562
563env.Append(CPPPATH=py_includes)
564env.Append(LIBPATH=py_lib_path)
565#env.Append(LIBS=py_libs)
566
567# verify that this stuff works
568if not conf.CheckHeader('Python.h', '<>'):
569 print "Error: can't find Python.h header in", py_includes
570 Exit(1)
571
572for lib in py_libs:
573 assert lib.startswith('-l')
574 lib = lib[2:]
575 if not conf.CheckLib(lib):
576 print "Error: can't find library %s required by python" % lib
577 Exit(1)
578
579# On Solaris you need to use libsocket for socket ops
580if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'):
581 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'):
582 print "Can't find library with socket calls (e.g. accept())"
583 Exit(1)
584
585# Check for zlib. If the check passes, libz will be automatically
586# added to the LIBS environment variable.
587if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'):
588 print 'Error: did not find needed zlib compression library '\
589 'and/or zlib.h header file.'
590 print ' Please install zlib and try again.'
591 Exit(1)
592
593# Check for <fenv.h> (C99 FP environment control)
594have_fenv = conf.CheckHeader('fenv.h', '<>')
595if not have_fenv:
596 print "Warning: Header file <fenv.h> not found."
597 print " This host has no IEEE FP rounding mode control."
598
599######################################################################
600#
601# Check for mysql.
602#
603mysql_config = WhereIs('mysql_config')
604have_mysql = bool(mysql_config)
605
606# Check MySQL version.
607if have_mysql:
608 mysql_version = read_command(mysql_config + ' --version')
609 min_mysql_version = '4.1'
610 if compare_versions(mysql_version, min_mysql_version) < 0:
611 print 'Warning: MySQL', min_mysql_version, 'or newer required.'
612 print ' Version', mysql_version, 'detected.'
613 have_mysql = False
614
615# Set up mysql_config commands.
616if have_mysql:
617 mysql_config_include = mysql_config + ' --include'
618 if os.system(mysql_config_include + ' > /dev/null') != 0:
619 # older mysql_config versions don't support --include, use
620 # --cflags instead
621 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
622 # This seems to work in all versions
623 mysql_config_libs = mysql_config + ' --libs'
624
625######################################################################
626#
627# Finish the configuration
628#
629env = conf.Finish()
630
631######################################################################
632#
633# Collect all non-global variables
634#
635
636Export('env')
637
600# Define the universe of supported ISAs
601all_isa_list = [ ]
602Export('all_isa_list')
603
604# Define the universe of supported CPU models
605all_cpu_list = [ ]
606default_cpus = [ ]
607Export('all_cpu_list', 'default_cpus')
608
609# Sticky variables get saved in the variables file so they persist from
610# one invocation to the next (unless overridden, in which case the new
611# value becomes sticky).
612sticky_vars = Variables(args=ARGUMENTS)
613Export('sticky_vars')
614
615# Non-sticky variables only apply to the current build.
616nonsticky_vars = Variables(args=ARGUMENTS)
617Export('nonsticky_vars')
618
619# Walk the tree and execute all SConsopts scripts that wil add to the
620# above variables
621for bdir in [ base_dir ] + extras_dir_list:
622 for root, dirs, files in os.walk(bdir):
623 if 'SConsopts' in files:
624 print "Reading", joinpath(root, 'SConsopts')
625 SConscript(joinpath(root, 'SConsopts'))
626
627all_isa_list.sort()
628all_cpu_list.sort()
629default_cpus.sort()
630
631sticky_vars.AddVariables(
632 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
633 BoolVariable('FULL_SYSTEM', 'Full-system support', False),
634 ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
635 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
636 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
637 False),
638 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
639 False),
640 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
641 False),
642 BoolVariable('SS_COMPATIBLE_FP',
643 'Make floating-point results compatible with SimpleScalar',
644 False),
645 BoolVariable('USE_SSE2',
646 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
647 False),
648 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
649 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
650 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
651 )
652
653nonsticky_vars.AddVariables(
654 BoolVariable('update_ref', 'Update test reference outputs', False)
655 )
656
657# These variables get exported to #defines in config/*.hh (see src/SConscript).
658env.ExportVariables = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
659 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \
660 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \
661 'USE_CHECKER', 'TARGET_ISA']
662
663###################################################
664#
665# Define a SCons builder for configuration flag headers.
666#
667###################################################
668
669# This function generates a config header file that #defines the
670# variable symbol to the current variable setting (0 or 1). The source
671# operands are the name of the variable and a Value node containing the
672# value of the variable.
673def build_config_file(target, source, env):
674 (variable, value) = [s.get_contents() for s in source]
675 f = file(str(target[0]), 'w')
676 print >> f, '#define', variable, value
677 f.close()
678 return None
679
680# Generate the message to be printed when building the config file.
681def build_config_file_string(target, source, env):
682 (variable, value) = [s.get_contents() for s in source]
683 return "Defining %s as %s in %s." % (variable, value, target[0])
684
685# Combine the two functions into a scons Action object.
686config_action = Action(build_config_file, build_config_file_string)
687
688# The emitter munges the source & target node lists to reflect what
689# we're really doing.
690def config_emitter(target, source, env):
691 # extract variable name from Builder arg
692 variable = str(target[0])
693 # True target is config header file
694 target = joinpath('config', variable.lower() + '.hh')
695 val = env[variable]
696 if isinstance(val, bool):
697 # Force value to 0/1
698 val = int(val)
699 elif isinstance(val, str):
700 val = '"' + val + '"'
701
702 # Sources are variable name & value (packaged in SCons Value nodes)
703 return ([target], [Value(variable), Value(val)])
704
705config_builder = Builder(emitter = config_emitter, action = config_action)
706
707env.Append(BUILDERS = { 'ConfigFile' : config_builder })
708
709# libelf build is shared across all configs in the build root.
710env.SConscript('ext/libelf/SConscript',
638# Define the universe of supported ISAs
639all_isa_list = [ ]
640Export('all_isa_list')
641
642# Define the universe of supported CPU models
643all_cpu_list = [ ]
644default_cpus = [ ]
645Export('all_cpu_list', 'default_cpus')
646
647# Sticky variables get saved in the variables file so they persist from
648# one invocation to the next (unless overridden, in which case the new
649# value becomes sticky).
650sticky_vars = Variables(args=ARGUMENTS)
651Export('sticky_vars')
652
653# Non-sticky variables only apply to the current build.
654nonsticky_vars = Variables(args=ARGUMENTS)
655Export('nonsticky_vars')
656
657# Walk the tree and execute all SConsopts scripts that wil add to the
658# above variables
659for bdir in [ base_dir ] + extras_dir_list:
660 for root, dirs, files in os.walk(bdir):
661 if 'SConsopts' in files:
662 print "Reading", joinpath(root, 'SConsopts')
663 SConscript(joinpath(root, 'SConsopts'))
664
665all_isa_list.sort()
666all_cpu_list.sort()
667default_cpus.sort()
668
669sticky_vars.AddVariables(
670 EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list),
671 BoolVariable('FULL_SYSTEM', 'Full-system support', False),
672 ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list),
673 BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False),
674 BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging',
675 False),
676 BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics',
677 False),
678 BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger',
679 False),
680 BoolVariable('SS_COMPATIBLE_FP',
681 'Make floating-point results compatible with SimpleScalar',
682 False),
683 BoolVariable('USE_SSE2',
684 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
685 False),
686 BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
687 BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
688 BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False),
689 )
690
691nonsticky_vars.AddVariables(
692 BoolVariable('update_ref', 'Update test reference outputs', False)
693 )
694
695# These variables get exported to #defines in config/*.hh (see src/SConscript).
696env.ExportVariables = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
697 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \
698 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \
699 'USE_CHECKER', 'TARGET_ISA']
700
701###################################################
702#
703# Define a SCons builder for configuration flag headers.
704#
705###################################################
706
707# This function generates a config header file that #defines the
708# variable symbol to the current variable setting (0 or 1). The source
709# operands are the name of the variable and a Value node containing the
710# value of the variable.
711def build_config_file(target, source, env):
712 (variable, value) = [s.get_contents() for s in source]
713 f = file(str(target[0]), 'w')
714 print >> f, '#define', variable, value
715 f.close()
716 return None
717
718# Generate the message to be printed when building the config file.
719def build_config_file_string(target, source, env):
720 (variable, value) = [s.get_contents() for s in source]
721 return "Defining %s as %s in %s." % (variable, value, target[0])
722
723# Combine the two functions into a scons Action object.
724config_action = Action(build_config_file, build_config_file_string)
725
726# The emitter munges the source & target node lists to reflect what
727# we're really doing.
728def config_emitter(target, source, env):
729 # extract variable name from Builder arg
730 variable = str(target[0])
731 # True target is config header file
732 target = joinpath('config', variable.lower() + '.hh')
733 val = env[variable]
734 if isinstance(val, bool):
735 # Force value to 0/1
736 val = int(val)
737 elif isinstance(val, str):
738 val = '"' + val + '"'
739
740 # Sources are variable name & value (packaged in SCons Value nodes)
741 return ([target], [Value(variable), Value(val)])
742
743config_builder = Builder(emitter = config_emitter, action = config_action)
744
745env.Append(BUILDERS = { 'ConfigFile' : config_builder })
746
747# libelf build is shared across all configs in the build root.
748env.SConscript('ext/libelf/SConscript',
711 variant_dir = joinpath(build_root, 'libelf'),
712 exports = 'env')
749 variant_dir = joinpath(build_root, 'libelf'))
713
714# gzstream build is shared across all configs in the build root.
715env.SConscript('ext/gzstream/SConscript',
750
751# gzstream build is shared across all configs in the build root.
752env.SConscript('ext/gzstream/SConscript',
716 variant_dir = joinpath(build_root, 'gzstream'),
717 exports = 'env')
753 variant_dir = joinpath(build_root, 'gzstream'))
718
719###################################################
720#
721# This function is used to set up a directory with switching headers
722#
723###################################################
724
725env['ALL_ISA_LIST'] = all_isa_list
726def make_switching_dir(dname, switch_headers, env):
727 # Generate the header. target[0] is the full path of the output
728 # header to generate. 'source' is a dummy variable, since we get the
729 # list of ISAs from env['ALL_ISA_LIST'].
730 def gen_switch_hdr(target, source, env):
731 fname = str(target[0])
732 bname = basename(fname)
733 f = open(fname, 'w')
734 f.write('#include "arch/isa_specific.hh"\n')
735 cond = '#if'
736 for isa in all_isa_list:
737 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
738 % (cond, isa.upper(), dname, isa, bname))
739 cond = '#elif'
740 f.write('#else\n#error "THE_ISA not set"\n#endif\n')
741 f.close()
742 return 0
743
744 # String to print when generating header
745 def gen_switch_hdr_string(target, source, env):
746 return "Generating switch header " + str(target[0])
747
748 # Build SCons Action object. 'varlist' specifies env vars that this
749 # action depends on; when env['ALL_ISA_LIST'] changes these actions
750 # should get re-executed.
751 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
752 varlist=['ALL_ISA_LIST'])
753
754 # Instantiate actions for each header
755 for hdr in switch_headers:
756 env.Command(hdr, [], switch_hdr_action)
757Export('make_switching_dir')
758
759###################################################
760#
761# Define build environments for selected configurations.
762#
763###################################################
764
765# rename base env
766base_env = env
767
768for variant_path in variant_paths:
769 print "Building in", variant_path
770
771 # Make a copy of the build-root environment to use for this config.
772 env = base_env.Clone()
773 env['BUILDDIR'] = variant_path
774
775 # variant_dir is the tail component of build path, and is used to
776 # determine the build parameters (e.g., 'ALPHA_SE')
777 (build_root, variant_dir) = splitpath(variant_path)
778
779 # Set env variables according to the build directory config.
780 sticky_vars.files = []
781 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
782 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
783 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
784 current_vars_file = joinpath(build_root, 'variables', variant_dir)
785 if isfile(current_vars_file):
786 sticky_vars.files.append(current_vars_file)
787 print "Using saved variables file %s" % current_vars_file
788 else:
789 # Build dir-specific variables file doesn't exist.
790
791 # Make sure the directory is there so we can create it later
792 opt_dir = dirname(current_vars_file)
793 if not isdir(opt_dir):
794 mkdir(opt_dir)
795
796 # Get default build variables from source tree. Variables are
797 # normally determined by name of $VARIANT_DIR, but can be
798 # overriden by 'default=' arg on command line.
799 default_vars_file = joinpath('build_opts',
800 ARGUMENTS.get('default', variant_dir))
801 if isfile(default_vars_file):
802 sticky_vars.files.append(default_vars_file)
803 print "Variables file %s not found,\n using defaults in %s" \
804 % (current_vars_file, default_vars_file)
805 else:
806 print "Error: cannot find variables file %s or %s" \
807 % (current_vars_file, default_vars_file)
808 Exit(1)
809
810 # Apply current variable settings to env
811 sticky_vars.Update(env)
812 nonsticky_vars.Update(env)
813
814 help_text += "\nSticky variables for %s:\n" % variant_dir \
815 + sticky_vars.GenerateHelpText(env) \
816 + "\nNon-sticky variables for %s:\n" % variant_dir \
817 + nonsticky_vars.GenerateHelpText(env)
818
819 # Process variable settings.
820
821 if not have_fenv and env['USE_FENV']:
822 print "Warning: <fenv.h> not available; " \
823 "forcing USE_FENV to False in", variant_dir + "."
824 env['USE_FENV'] = False
825
826 if not env['USE_FENV']:
827 print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
828 print " FP results may deviate slightly from other platforms."
829
830 if env['EFENCE']:
831 env.Append(LIBS=['efence'])
832
833 if env['USE_MYSQL']:
834 if not have_mysql:
835 print "Warning: MySQL not available; " \
836 "forcing USE_MYSQL to False in", variant_dir + "."
837 env['USE_MYSQL'] = False
838 else:
839 print "Compiling in", variant_dir, "with MySQL support."
840 env.ParseConfig(mysql_config_libs)
841 env.ParseConfig(mysql_config_include)
842
843 # Save sticky variable settings back to current variables file
844 sticky_vars.Save(current_vars_file, env)
845
846 if env['USE_SSE2']:
847 env.Append(CCFLAGS='-msse2')
848
849 # The src/SConscript file sets up the build rules in 'env' according
850 # to the configured variables. It returns a list of environments,
851 # one for each variant build (debug, opt, etc.)
852 envList = SConscript('src/SConscript', variant_dir = variant_path,
853 exports = 'env')
854
855 # Set up the regression tests for each build.
856 for e in envList:
857 SConscript('tests/SConscript',
858 variant_dir = joinpath(variant_path, 'tests', e.Label),
859 exports = { 'env' : e }, duplicate = False)
860
861Help(help_text)
754
755###################################################
756#
757# This function is used to set up a directory with switching headers
758#
759###################################################
760
761env['ALL_ISA_LIST'] = all_isa_list
762def make_switching_dir(dname, switch_headers, env):
763 # Generate the header. target[0] is the full path of the output
764 # header to generate. 'source' is a dummy variable, since we get the
765 # list of ISAs from env['ALL_ISA_LIST'].
766 def gen_switch_hdr(target, source, env):
767 fname = str(target[0])
768 bname = basename(fname)
769 f = open(fname, 'w')
770 f.write('#include "arch/isa_specific.hh"\n')
771 cond = '#if'
772 for isa in all_isa_list:
773 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n'
774 % (cond, isa.upper(), dname, isa, bname))
775 cond = '#elif'
776 f.write('#else\n#error "THE_ISA not set"\n#endif\n')
777 f.close()
778 return 0
779
780 # String to print when generating header
781 def gen_switch_hdr_string(target, source, env):
782 return "Generating switch header " + str(target[0])
783
784 # Build SCons Action object. 'varlist' specifies env vars that this
785 # action depends on; when env['ALL_ISA_LIST'] changes these actions
786 # should get re-executed.
787 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
788 varlist=['ALL_ISA_LIST'])
789
790 # Instantiate actions for each header
791 for hdr in switch_headers:
792 env.Command(hdr, [], switch_hdr_action)
793Export('make_switching_dir')
794
795###################################################
796#
797# Define build environments for selected configurations.
798#
799###################################################
800
801# rename base env
802base_env = env
803
804for variant_path in variant_paths:
805 print "Building in", variant_path
806
807 # Make a copy of the build-root environment to use for this config.
808 env = base_env.Clone()
809 env['BUILDDIR'] = variant_path
810
811 # variant_dir is the tail component of build path, and is used to
812 # determine the build parameters (e.g., 'ALPHA_SE')
813 (build_root, variant_dir) = splitpath(variant_path)
814
815 # Set env variables according to the build directory config.
816 sticky_vars.files = []
817 # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in
818 # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke
819 # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings.
820 current_vars_file = joinpath(build_root, 'variables', variant_dir)
821 if isfile(current_vars_file):
822 sticky_vars.files.append(current_vars_file)
823 print "Using saved variables file %s" % current_vars_file
824 else:
825 # Build dir-specific variables file doesn't exist.
826
827 # Make sure the directory is there so we can create it later
828 opt_dir = dirname(current_vars_file)
829 if not isdir(opt_dir):
830 mkdir(opt_dir)
831
832 # Get default build variables from source tree. Variables are
833 # normally determined by name of $VARIANT_DIR, but can be
834 # overriden by 'default=' arg on command line.
835 default_vars_file = joinpath('build_opts',
836 ARGUMENTS.get('default', variant_dir))
837 if isfile(default_vars_file):
838 sticky_vars.files.append(default_vars_file)
839 print "Variables file %s not found,\n using defaults in %s" \
840 % (current_vars_file, default_vars_file)
841 else:
842 print "Error: cannot find variables file %s or %s" \
843 % (current_vars_file, default_vars_file)
844 Exit(1)
845
846 # Apply current variable settings to env
847 sticky_vars.Update(env)
848 nonsticky_vars.Update(env)
849
850 help_text += "\nSticky variables for %s:\n" % variant_dir \
851 + sticky_vars.GenerateHelpText(env) \
852 + "\nNon-sticky variables for %s:\n" % variant_dir \
853 + nonsticky_vars.GenerateHelpText(env)
854
855 # Process variable settings.
856
857 if not have_fenv and env['USE_FENV']:
858 print "Warning: <fenv.h> not available; " \
859 "forcing USE_FENV to False in", variant_dir + "."
860 env['USE_FENV'] = False
861
862 if not env['USE_FENV']:
863 print "Warning: No IEEE FP rounding mode control in", variant_dir + "."
864 print " FP results may deviate slightly from other platforms."
865
866 if env['EFENCE']:
867 env.Append(LIBS=['efence'])
868
869 if env['USE_MYSQL']:
870 if not have_mysql:
871 print "Warning: MySQL not available; " \
872 "forcing USE_MYSQL to False in", variant_dir + "."
873 env['USE_MYSQL'] = False
874 else:
875 print "Compiling in", variant_dir, "with MySQL support."
876 env.ParseConfig(mysql_config_libs)
877 env.ParseConfig(mysql_config_include)
878
879 # Save sticky variable settings back to current variables file
880 sticky_vars.Save(current_vars_file, env)
881
882 if env['USE_SSE2']:
883 env.Append(CCFLAGS='-msse2')
884
885 # The src/SConscript file sets up the build rules in 'env' according
886 # to the configured variables. It returns a list of environments,
887 # one for each variant build (debug, opt, etc.)
888 envList = SConscript('src/SConscript', variant_dir = variant_path,
889 exports = 'env')
890
891 # Set up the regression tests for each build.
892 for e in envList:
893 SConscript('tests/SConscript',
894 variant_dir = joinpath(variant_path, 'tests', e.Label),
895 exports = { 'env' : e }, duplicate = False)
896
897Help(help_text)
862
863
864###################################################
865#
866# Let SCons do its thing. At this point SCons will use the defined
867# build environments to build the requested targets.
868#
869###################################################
870