SConstruct revision 1888
14166Sgblack@eecs.umich.edu# -*- mode:python -*-
24166Sgblack@eecs.umich.edu
34166Sgblack@eecs.umich.edu# Copyright (c) 2004-2005 The Regents of The University of Michigan
44166Sgblack@eecs.umich.edu# All rights reserved.
57087Snate@binkert.org#
67087Snate@binkert.org# Redistribution and use in source and binary forms, with or without
77087Snate@binkert.org# modification, are permitted provided that the following conditions are
87087Snate@binkert.org# met: redistributions of source code must retain the above copyright
97087Snate@binkert.org# notice, this list of conditions and the following disclaimer;
107087Snate@binkert.org# redistributions in binary form must reproduce the above copyright
117087Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
127087Snate@binkert.org# documentation and/or other materials provided with the distribution;
134166Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
147087Snate@binkert.org# contributors may be used to endorse or promote products derived from
157087Snate@binkert.org# this software without specific prior written permission.
167087Snate@binkert.org#
177087Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
187087Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
197087Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
207087Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
217087Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
224166Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
237087Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
244166Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
254166Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
264166Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
274166Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
284166Sgblack@eecs.umich.edu
294166Sgblack@eecs.umich.edu###################################################
304166Sgblack@eecs.umich.edu#
314166Sgblack@eecs.umich.edu# SCons top-level build description (SConstruct) file.
324166Sgblack@eecs.umich.edu#
334166Sgblack@eecs.umich.edu# To build M5, you need a directory with three things:
344166Sgblack@eecs.umich.edu# 1. A copy of this file (named SConstruct).
354166Sgblack@eecs.umich.edu# 2. A link named 'm5' to the top of the M5 simulator source tree.
364166Sgblack@eecs.umich.edu# 3. A link named 'ext' to the top of the M5 external source tree.
374166Sgblack@eecs.umich.edu#
384166Sgblack@eecs.umich.edu# Then type 'scons' to build the default configuration (see below), or
394166Sgblack@eecs.umich.edu# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
4011793Sbrandon.potter@amd.com# 'ALPHA_FS/m5.opt' for the optimized full-system version).
4111793Sbrandon.potter@amd.com#
4211793Sbrandon.potter@amd.com###################################################
4310494Sandreas.hansson@arm.com
446329Sgblack@eecs.umich.edu# Python library imports
454166Sgblack@eecs.umich.eduimport sys
464166Sgblack@eecs.umich.eduimport os
474166Sgblack@eecs.umich.edu
484166Sgblack@eecs.umich.edu# Check for recent-enough Python and SCons versions
4911794Sbrandon.potter@amd.comEnsurePythonVersion(2,3)
5010494Sandreas.hansson@arm.comEnsureSConsVersion(0,96)
514166Sgblack@eecs.umich.edu
524166Sgblack@eecs.umich.edu# The absolute path to the current directory (where this file lives).
534166Sgblack@eecs.umich.eduROOT = Dir('.').abspath
544166Sgblack@eecs.umich.edu
5510494Sandreas.hansson@arm.com# Paths to the M5 and external source trees (local symlinks).
5610494Sandreas.hansson@arm.comSRCDIR = os.path.join(ROOT, 'm5')
5711851Sbrandon.potter@amd.comEXT_SRCDIR = os.path.join(ROOT, 'ext')
5810494Sandreas.hansson@arm.com
5910494Sandreas.hansson@arm.com# Check for 'm5' and 'ext' links, die if they don't exist.
6010494Sandreas.hansson@arm.comif not os.path.isdir(SRCDIR):
6110494Sandreas.hansson@arm.com    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
6210494Sandreas.hansson@arm.com    Exit(1)
6310494Sandreas.hansson@arm.com
6410494Sandreas.hansson@arm.comif not os.path.isdir('ext'):
6510494Sandreas.hansson@arm.com    print "Error: '%s' must be a link to the M5 external source tree." \
6610494Sandreas.hansson@arm.com          % EXT_SRCDIR
6710494Sandreas.hansson@arm.com    Exit(1)
6810494Sandreas.hansson@arm.com
6910494Sandreas.hansson@arm.com# tell python where to find m5 python code
7010494Sandreas.hansson@arm.comsys.path.append(os.path.join(SRCDIR, 'python'))
7110494Sandreas.hansson@arm.com
7210494Sandreas.hansson@arm.com###################################################
7310494Sandreas.hansson@arm.com#
7410494Sandreas.hansson@arm.com# Figure out which configurations to set up.
7511851Sbrandon.potter@amd.com#
7610494Sandreas.hansson@arm.com#
7710494Sandreas.hansson@arm.com# It's prohibitive to do all the combinations of base configurations
7810494Sandreas.hansson@arm.com# and options, so we have to infer which ones the user wants.
7910494Sandreas.hansson@arm.com#
8010494Sandreas.hansson@arm.com# 1. If there are command-line targets, the configuration(s) are inferred
8110494Sandreas.hansson@arm.com#    from the directories of those targets.  If scons was invoked from a
8210494Sandreas.hansson@arm.com#    subdirectory (using 'scons -u'), those targets have to be
8310494Sandreas.hansson@arm.com#    interpreted relative to that subdirectory.
8410494Sandreas.hansson@arm.com#
8510494Sandreas.hansson@arm.com# 2. If there are no command-line targets, and scons was invoked from a
8610494Sandreas.hansson@arm.com#    subdirectory (using 'scons -u'), the configuration is inferred from
8710494Sandreas.hansson@arm.com#    the name of the subdirectory.
8810494Sandreas.hansson@arm.com#
8910494Sandreas.hansson@arm.com# 3. If there are no command-line targets and scons was invoked from
9010494Sandreas.hansson@arm.com#    the root build directory, a default configuration is used.  The
9110494Sandreas.hansson@arm.com#    built-in default is ALPHA_SE, but this can be overridden by setting the
9210494Sandreas.hansson@arm.com#    M5_DEFAULT_CONFIG shell environment veriable.
9310494Sandreas.hansson@arm.com#
9410494Sandreas.hansson@arm.com# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
9510494Sandreas.hansson@arm.com# this can be overridden by setting the M5_DEFAULT_BINARY shell
9610494Sandreas.hansson@arm.com# environment veriable.
9710494Sandreas.hansson@arm.com#
9810494Sandreas.hansson@arm.com###################################################
9910494Sandreas.hansson@arm.com
10010494Sandreas.hansson@arm.com# Find default configuration & binary.
10110494Sandreas.hansson@arm.comdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
10210494Sandreas.hansson@arm.comdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
10310494Sandreas.hansson@arm.com
10410494Sandreas.hansson@arm.com# Ask SCons which directory it was invoked from.  If you invoke SCons
10510494Sandreas.hansson@arm.com# from a subdirectory you must use the '-u' flag.
10610494Sandreas.hansson@arm.comlaunch_dir = GetLaunchDir()
10710494Sandreas.hansson@arm.com
10810494Sandreas.hansson@arm.com# Build a list 'my_targets' of all the targets relative to ROOT.
10910494Sandreas.hansson@arm.comif launch_dir == ROOT:
11010494Sandreas.hansson@arm.com    # invoked from root build dir
11110494Sandreas.hansson@arm.com    if len(COMMAND_LINE_TARGETS) != 0:
11210494Sandreas.hansson@arm.com        # easy: use specified targets as is
11310494Sandreas.hansson@arm.com        my_targets = COMMAND_LINE_TARGETS
11410494Sandreas.hansson@arm.com    else:
11510494Sandreas.hansson@arm.com        # default target (ALPHA_SE/m5.debug, unless overridden)
11610494Sandreas.hansson@arm.com        target = os.path.join(default_config, default_binary)
11710494Sandreas.hansson@arm.com        my_targets = [target]
11810494Sandreas.hansson@arm.com        Default(target)
11910494Sandreas.hansson@arm.comelse:
12010494Sandreas.hansson@arm.com    # invoked from subdirectory
12110494Sandreas.hansson@arm.com    if not launch_dir.startswith(ROOT):
12210494Sandreas.hansson@arm.com        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
12310494Sandreas.hansson@arm.com              (launch_dir, ROOT)
12410494Sandreas.hansson@arm.com        Exit(1)
12510494Sandreas.hansson@arm.com    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
12610494Sandreas.hansson@arm.com    launch_dir = launch_dir[len(ROOT)+1:]
12710494Sandreas.hansson@arm.com    if len(COMMAND_LINE_TARGETS) != 0:
12810494Sandreas.hansson@arm.com        # make specified targets relative to ROOT
12910494Sandreas.hansson@arm.com        my_targets = map(lambda x: os.path.join(launch_dir, x),
13010494Sandreas.hansson@arm.com                         COMMAND_LINE_TARGETS)
13110494Sandreas.hansson@arm.com    else:
13210494Sandreas.hansson@arm.com        # build default binary (m5.debug, unless overridden) using the
13310494Sandreas.hansson@arm.com        # config inferred by the invocation directory (the first
13410494Sandreas.hansson@arm.com        # subdirectory after ROOT)
13510494Sandreas.hansson@arm.com        target = os.path.join(launch_dir.split('/')[0], default_binary)
13610494Sandreas.hansson@arm.com        my_targets = [target]
13710494Sandreas.hansson@arm.com        Default(target)
13810494Sandreas.hansson@arm.com
13910494Sandreas.hansson@arm.com# Normalize target paths (gets rid of '..' in the middle, etc.)
14010494Sandreas.hansson@arm.commy_targets = map(os.path.normpath, my_targets)
14110494Sandreas.hansson@arm.com
14211851Sbrandon.potter@amd.com# Generate a list of the unique configs that the collected targets reference.
14310494Sandreas.hansson@arm.combuild_dirs = []
14410494Sandreas.hansson@arm.comfor t in my_targets:
14510494Sandreas.hansson@arm.com    dir = t.split('/')[0]
14610494Sandreas.hansson@arm.com    if dir not in build_dirs:
14710494Sandreas.hansson@arm.com        build_dirs.append(dir)
14811851Sbrandon.potter@amd.com
14911851Sbrandon.potter@amd.com###################################################
15010494Sandreas.hansson@arm.com#
15111851Sbrandon.potter@amd.com# Set up the default build environment.  This environment is copied
15210494Sandreas.hansson@arm.com# and modified according to each selected configuration.
15310494Sandreas.hansson@arm.com#
15410494Sandreas.hansson@arm.com###################################################
15510494Sandreas.hansson@arm.com
15611851Sbrandon.potter@amd.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
15711851Sbrandon.potter@amd.com                  ROOT = ROOT,
15810494Sandreas.hansson@arm.com                  SRCDIR = SRCDIR,
15910494Sandreas.hansson@arm.com                  EXT_SRCDIR = EXT_SRCDIR)
16010494Sandreas.hansson@arm.com
16110494Sandreas.hansson@arm.comenv.SConsignFile("sconsign")
16210494Sandreas.hansson@arm.com
16311794Sbrandon.potter@amd.com# I waffle on this setting... it does avoid a few painful but
16410494Sandreas.hansson@arm.com# unnecessary builds, but it also seems to make trivial builds take
16510494Sandreas.hansson@arm.com# noticeably longer.
16610494Sandreas.hansson@arm.comif False:
16710494Sandreas.hansson@arm.com    env.TargetSignatures('content')
16810494Sandreas.hansson@arm.com
16910494Sandreas.hansson@arm.com# M5_EXT is used by isa_parser.py to find the PLY package.
17010494Sandreas.hansson@arm.comenv.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
17110494Sandreas.hansson@arm.com
17210494Sandreas.hansson@arm.com# Set up default C++ compiler flags
17310494Sandreas.hansson@arm.comenv.Append(CCFLAGS='-pipe')
17410494Sandreas.hansson@arm.comenv.Append(CCFLAGS='-fno-strict-aliasing')
17510494Sandreas.hansson@arm.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
17610494Sandreas.hansson@arm.comif sys.platform == 'cygwin':
17710494Sandreas.hansson@arm.com    # cygwin has some header file issues...
17810494Sandreas.hansson@arm.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
17910494Sandreas.hansson@arm.comenv.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
18010494Sandreas.hansson@arm.com
18110494Sandreas.hansson@arm.com# Default libraries
18210494Sandreas.hansson@arm.comenv.Append(LIBS=['z'])
18310494Sandreas.hansson@arm.com
18410494Sandreas.hansson@arm.com# Platform-specific configuration
18510494Sandreas.hansson@arm.comconf = Configure(env)
18610494Sandreas.hansson@arm.com
18710494Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control)
18810494Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
18910494Sandreas.hansson@arm.comif not have_fenv:
19010494Sandreas.hansson@arm.com    print "Warning: Header file <fenv.h> not found."
19110494Sandreas.hansson@arm.com    print "         This host has no IEEE FP rounding mode control."
19210494Sandreas.hansson@arm.com
19310494Sandreas.hansson@arm.com# Check for mysql.
19410494Sandreas.hansson@arm.commysql_config = WhereIs('mysql_config')
19510494Sandreas.hansson@arm.comhave_mysql = mysql_config != None
19610494Sandreas.hansson@arm.com
19710494Sandreas.hansson@arm.com# Check MySQL version.
19810494Sandreas.hansson@arm.comif have_mysql:
19910494Sandreas.hansson@arm.com    mysql_version = os.popen(mysql_config + ' --version').read()
20010494Sandreas.hansson@arm.com    mysql_version = mysql_version.split('.')
20110494Sandreas.hansson@arm.com    mysql_major = int(mysql_version[0])
20210494Sandreas.hansson@arm.com    mysql_minor = int(mysql_version[1])
20310494Sandreas.hansson@arm.com    # This version check is probably overly conservative, but it deals
20410494Sandreas.hansson@arm.com    # with the versions we have installed.
20510494Sandreas.hansson@arm.com    if mysql_major < 3 or \
20610494Sandreas.hansson@arm.com           mysql_major == 3 and mysql_minor < 23 or \
20710494Sandreas.hansson@arm.com           mysql_major == 4 and mysql_minor < 1:
20810494Sandreas.hansson@arm.com        print "Warning: MySQL v3.23 or v4.1 or newer required."
20910494Sandreas.hansson@arm.com        have_mysql = False
21010494Sandreas.hansson@arm.com
21110494Sandreas.hansson@arm.com# Set up mysql_config commands.
21210494Sandreas.hansson@arm.comif have_mysql:
21310494Sandreas.hansson@arm.com    mysql_config_include = mysql_config + ' --include'
21410494Sandreas.hansson@arm.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
21510494Sandreas.hansson@arm.com        # older mysql_config versions don't support --include, use
21610494Sandreas.hansson@arm.com        # --cflags instead
21711794Sbrandon.potter@amd.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
21810494Sandreas.hansson@arm.com    # This seems to work in all versions
21910494Sandreas.hansson@arm.com    mysql_config_libs = mysql_config + ' --libs'
22010494Sandreas.hansson@arm.com
22110494Sandreas.hansson@arm.comenv = conf.Finish()
22210494Sandreas.hansson@arm.com
22310494Sandreas.hansson@arm.com# Sticky options get saved in the options file so they persist from
22410494Sandreas.hansson@arm.com# one invocation to the next (unless overridden, in which case the new
22510494Sandreas.hansson@arm.com# value becomes sticky).
22610494Sandreas.hansson@arm.comsticky_opts = Options(args=ARGUMENTS)
22710494Sandreas.hansson@arm.comsticky_opts.AddOptions(
22810494Sandreas.hansson@arm.com    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', ('alpha')),
22910494Sandreas.hansson@arm.com    BoolOption('FULL_SYSTEM', 'Full-system support', False),
23010494Sandreas.hansson@arm.com    BoolOption('ALPHA_TLASER',
23110494Sandreas.hansson@arm.com               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
23210494Sandreas.hansson@arm.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
23310494Sandreas.hansson@arm.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
23410494Sandreas.hansson@arm.com               False),
23510494Sandreas.hansson@arm.com    BoolOption('SS_COMPATIBLE_FP',
23610831Ssteve.reinhardt@amd.com               'Make floating-point results compatible with SimpleScalar',
23710831Ssteve.reinhardt@amd.com               False),
23810494Sandreas.hansson@arm.com    BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
23910494Sandreas.hansson@arm.com    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
24010494Sandreas.hansson@arm.com    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
24111593Santhony.gutierrez@amd.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
24210494Sandreas.hansson@arm.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
24310494Sandreas.hansson@arm.com    BoolOption('BATCH', 'Use batch pool for build and tests', False),
24410494Sandreas.hansson@arm.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
24510494Sandreas.hansson@arm.com    )
24610494Sandreas.hansson@arm.com
24710494Sandreas.hansson@arm.com# Non-sticky options only apply to the current build.
24810494Sandreas.hansson@arm.comnonsticky_opts = Options(args=ARGUMENTS)
24910494Sandreas.hansson@arm.comnonsticky_opts.AddOptions(
25010494Sandreas.hansson@arm.com    BoolOption('update_ref', 'Update test reference outputs', False)
25110494Sandreas.hansson@arm.com    )
25210494Sandreas.hansson@arm.com
25310494Sandreas.hansson@arm.com# These options get exported to #defines in config/*.hh (see m5/SConscript).
25410494Sandreas.hansson@arm.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
25510494Sandreas.hansson@arm.com                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
25610494Sandreas.hansson@arm.com                     'STATS_BINNING']
25710494Sandreas.hansson@arm.com
25810831Ssteve.reinhardt@amd.com# Define a handy 'no-op' action
25910494Sandreas.hansson@arm.comdef no_action(target, source, env):
26010494Sandreas.hansson@arm.com    return 0
26110494Sandreas.hansson@arm.com
26210494Sandreas.hansson@arm.comenv.NoAction = Action(no_action, None)
26310494Sandreas.hansson@arm.com
26410494Sandreas.hansson@arm.com# libelf build is described in its own SConscript file.
26510494Sandreas.hansson@arm.com# SConscript-global is the build in build/libelf shared among all
26610494Sandreas.hansson@arm.com# configs.
26710494Sandreas.hansson@arm.comenv.SConscript('m5/libelf/SConscript-global', exports = 'env')
26810494Sandreas.hansson@arm.com
26910494Sandreas.hansson@arm.com###################################################
27010494Sandreas.hansson@arm.com#
27110494Sandreas.hansson@arm.com# Define a SCons builder for configuration flag headers.
27210494Sandreas.hansson@arm.com#
27310494Sandreas.hansson@arm.com###################################################
27410494Sandreas.hansson@arm.com
27510494Sandreas.hansson@arm.com# This function generates a config header file that #defines the
27610494Sandreas.hansson@arm.com# option symbol to the current option setting (0 or 1).  The source
27710494Sandreas.hansson@arm.com# operands are the name of the option and a Value node containing the
27810494Sandreas.hansson@arm.com# value of the option.
27911886Sbrandon.potter@amd.comdef build_config_file(target, source, env):
28010494Sandreas.hansson@arm.com    (option, value) = [s.get_contents() for s in source]
28110494Sandreas.hansson@arm.com    f = file(str(target[0]), 'w')
28211886Sbrandon.potter@amd.com    print >> f, '#define', option, value
28310494Sandreas.hansson@arm.com    f.close()
28410494Sandreas.hansson@arm.com    return None
28510494Sandreas.hansson@arm.com
28610494Sandreas.hansson@arm.com# Generate the message to be printed when building the config file.
28710494Sandreas.hansson@arm.comdef build_config_file_string(target, source, env):
28810494Sandreas.hansson@arm.com    (option, value) = [s.get_contents() for s in source]
28910494Sandreas.hansson@arm.com    return "Defining %s as %s in %s." % (option, value, target[0])
29010494Sandreas.hansson@arm.com
29110494Sandreas.hansson@arm.com# Combine the two functions into a scons Action object.
29210494Sandreas.hansson@arm.comconfig_action = Action(build_config_file, build_config_file_string)
29310494Sandreas.hansson@arm.com
29410494Sandreas.hansson@arm.com# The emitter munges the source & target node lists to reflect what
29510494Sandreas.hansson@arm.com# we're really doing.
29610494Sandreas.hansson@arm.comdef config_emitter(target, source, env):
29710494Sandreas.hansson@arm.com    # extract option name from Builder arg
29810494Sandreas.hansson@arm.com    option = str(target[0])
29910494Sandreas.hansson@arm.com    # True target is config header file
30010494Sandreas.hansson@arm.com    target = os.path.join('config', option.lower() + '.hh')
30110495Snilay@cs.wisc.edu    # Force value to 0/1 even if it's a Python bool
30210494Sandreas.hansson@arm.com    val = int(eval(str(env[option])))
30310494Sandreas.hansson@arm.com    # Sources are option name & value (packaged in SCons Value nodes)
30410494Sandreas.hansson@arm.com    return ([target], [Value(option), Value(val)])
30510494Sandreas.hansson@arm.com
30610494Sandreas.hansson@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action)
30710494Sandreas.hansson@arm.com
30810494Sandreas.hansson@arm.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
30910494Sandreas.hansson@arm.com
31010494Sandreas.hansson@arm.com###################################################
31110494Sandreas.hansson@arm.com#
31210494Sandreas.hansson@arm.com# Define build environments for selected configurations.
31310494Sandreas.hansson@arm.com#
31410494Sandreas.hansson@arm.com###################################################
31510494Sandreas.hansson@arm.com
31610494Sandreas.hansson@arm.com# rename base env
31710494Sandreas.hansson@arm.combase_env = env
31810494Sandreas.hansson@arm.com
31910494Sandreas.hansson@arm.comfor build_dir in build_dirs:
32010494Sandreas.hansson@arm.com    # Make a copy of the default environment to use for this config.
32110494Sandreas.hansson@arm.com    env = base_env.Copy()
32210494Sandreas.hansson@arm.com    # Set env according to the build directory config.
32310494Sandreas.hansson@arm.com
32410494Sandreas.hansson@arm.com    sticky_opts.files = []
32510494Sandreas.hansson@arm.com    default_options_file = os.path.join('build_options', 'default', build_dir)
32610494Sandreas.hansson@arm.com    if os.path.isfile(default_options_file):
32710494Sandreas.hansson@arm.com        sticky_opts.files.append(default_options_file)
32810494Sandreas.hansson@arm.com    current_options_file = os.path.join('build_options', 'current', build_dir)
32910494Sandreas.hansson@arm.com    if os.path.isfile(current_options_file):
33010494Sandreas.hansson@arm.com        sticky_opts.files.append(current_options_file)
33110494Sandreas.hansson@arm.com    if not sticky_opts.files:
33211885Sbrandon.potter@amd.com        print "%s: No options file found in build_options, using defaults." \
33310494Sandreas.hansson@arm.com              % build_dir
33410494Sandreas.hansson@arm.com
33510494Sandreas.hansson@arm.com    # Apply current option settings to env
33610494Sandreas.hansson@arm.com    sticky_opts.Update(env)
33710494Sandreas.hansson@arm.com    nonsticky_opts.Update(env)
33810494Sandreas.hansson@arm.com
33910494Sandreas.hansson@arm.com    # Process option settings.
34010494Sandreas.hansson@arm.com
34110494Sandreas.hansson@arm.com    if not have_fenv and env['USE_FENV']:
34210494Sandreas.hansson@arm.com        print "Warning: <fenv.h> not available; " \
34310494Sandreas.hansson@arm.com              "forcing USE_FENV to False in", build_dir + "."
34410494Sandreas.hansson@arm.com        env['USE_FENV'] = False
34510494Sandreas.hansson@arm.com
34610494Sandreas.hansson@arm.com    if not env['USE_FENV']:
34710494Sandreas.hansson@arm.com        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
34810494Sandreas.hansson@arm.com        print "         FP results may deviate slightly from other platforms."
34910494Sandreas.hansson@arm.com
35010494Sandreas.hansson@arm.com    if env['EFENCE']:
35110494Sandreas.hansson@arm.com        env.Append(LIBS=['efence'])
35210494Sandreas.hansson@arm.com
35310494Sandreas.hansson@arm.com    if env['USE_MYSQL']:
35410494Sandreas.hansson@arm.com        if not have_mysql:
35510494Sandreas.hansson@arm.com            print "Warning: MySQL not available; " \
35610494Sandreas.hansson@arm.com                  "forcing USE_MYSQL to False in", build_dir + "."
35710494Sandreas.hansson@arm.com            env['USE_MYSQL'] = False
35810494Sandreas.hansson@arm.com        else:
35910494Sandreas.hansson@arm.com            print "Compiling in", build_dir, "with MySQL support."
36011759Sbrandon.potter@amd.com            env.ParseConfig(mysql_config_libs)
36111594Santhony.gutierrez@amd.com            env.ParseConfig(mysql_config_include)
36210494Sandreas.hansson@arm.com
36310494Sandreas.hansson@arm.com    # Save sticky option settings back to current options file
36410494Sandreas.hansson@arm.com    sticky_opts.Save(current_options_file, env)
36510494Sandreas.hansson@arm.com
36610494Sandreas.hansson@arm.com    # Do this after we save setting back, or else we'll tack on an
36710494Sandreas.hansson@arm.com    # extra 'qdo' every time we run scons.
36810494Sandreas.hansson@arm.com    if env['BATCH']:
36910494Sandreas.hansson@arm.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
37010494Sandreas.hansson@arm.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
37110494Sandreas.hansson@arm.com
37210494Sandreas.hansson@arm.com    # The m5/SConscript file sets up the build rules in 'env' according
37310494Sandreas.hansson@arm.com    # to the configured options.  It returns a list of environments,
37410494Sandreas.hansson@arm.com    # one for each variant build (debug, opt, etc.)
37510494Sandreas.hansson@arm.com    envList = SConscript('m5/SConscript', build_dir = build_dir,
37610494Sandreas.hansson@arm.com                         exports = 'env', duplicate = False)
37710494Sandreas.hansson@arm.com
37810494Sandreas.hansson@arm.com    # Set up the regression tests for each build.
37910494Sandreas.hansson@arm.com    for e in envList:
38010494Sandreas.hansson@arm.com        SConscript('m5-test/SConscript',
38110494Sandreas.hansson@arm.com                   build_dir = os.path.join(build_dir, 'test', e.Label),
38210494Sandreas.hansson@arm.com                   exports = { 'env' : e }, duplicate = False)
38310494Sandreas.hansson@arm.com
38410494Sandreas.hansson@arm.com###################################################
38510494Sandreas.hansson@arm.com#
38610494Sandreas.hansson@arm.com# Let SCons do its thing.  At this point SCons will use the defined
38710494Sandreas.hansson@arm.com# build environments to build the requested targets.
38810494Sandreas.hansson@arm.com#
38910494Sandreas.hansson@arm.com###################################################
39010494Sandreas.hansson@arm.com
39110494Sandreas.hansson@arm.com