SConstruct revision 2817
1955SN/A# -*- mode:python -*-
2955SN/A
312230Sgiacomo.travaglini@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from
157816Ssteve.reinhardt@amd.com# this software without specific prior written permission.
165871Snate@binkert.org#
171762SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28955SN/A#
29955SN/A# Authors: Steve Reinhardt
30955SN/A
31955SN/A###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
35955SN/A# While in this directory ('m5'), just type 'scons' to build the default
36955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
38955SN/A# the optimized full-system version).
39955SN/A#
40955SN/A# You can build M5 in a different directory as long as there is a
41955SN/A# 'build/<CONFIG>' somewhere along the target path.  The build system
422665Ssaidi@eecs.umich.edu# expects that all configs under the same build directory are being
432665Ssaidi@eecs.umich.edu# built for the same host system.
445863Snate@binkert.org#
45955SN/A# Examples:
46955SN/A#
47955SN/A#   The following two commands are equivalent.  The '-u' option tells
48955SN/A#   scons to search up the directory tree for this SConstruct file.
49955SN/A#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
508878Ssteve.reinhardt@amd.com#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512632Sstever@eecs.umich.edu#
528878Ssteve.reinhardt@amd.com#   The following two commands are equivalent and demonstrate building
532632Sstever@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
54955SN/A#   scons to chdir to the specified directory to find this SConstruct
558878Ssteve.reinhardt@amd.com#   file.
562632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
572761Sstever@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
582632Sstever@eecs.umich.edu#
592632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
602632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
612761Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
622761Sstever@eecs.umich.edu# options as well.
632761Sstever@eecs.umich.edu#
648878Ssteve.reinhardt@amd.com###################################################
658878Ssteve.reinhardt@amd.com
662761Sstever@eecs.umich.edu# Python library imports
672761Sstever@eecs.umich.eduimport sys
682761Sstever@eecs.umich.eduimport os
692761Sstever@eecs.umich.edu
702761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions.  If your system's
718878Ssteve.reinhardt@amd.com# default installation of Python is not recent enough, you can use a
728878Ssteve.reinhardt@amd.com# non-default installation of the Python interpreter by either (1)
732632Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python'
742632Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the
758878Ssteve.reinhardt@amd.com# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
768878Ssteve.reinhardt@amd.comEnsurePythonVersion(2,4)
772632Sstever@eecs.umich.edu
78955SN/A# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
79955SN/A# 3-element version number.
80955SN/Amin_scons_version = (0,96,91)
8112563Sgabeblack@google.comtry:
8212563Sgabeblack@google.com    EnsureSConsVersion(*min_scons_version)
836654Snate@binkert.orgexcept:
8410196SCurtis.Dunham@arm.com    print "Error checking current SCons version."
85955SN/A    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
865396Ssaidi@eecs.umich.edu    Exit(2)
8711401Sandreas.sandberg@arm.com    
885863Snate@binkert.org
895863Snate@binkert.org# The absolute path to the current directory (where this file lives).
904202Sbinkertn@umich.eduROOT = Dir('.').abspath
915863Snate@binkert.org
925863Snate@binkert.org# Paths to the M5 and external source trees.
935863Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src')
945863Snate@binkert.org
95955SN/A# tell python where to find m5 python code
966654Snate@binkert.orgsys.path.append(os.path.join(ROOT, 'src/python'))
975273Sstever@gmail.com
985871Snate@binkert.org###################################################
995273Sstever@gmail.com#
1006654Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
1015396Ssaidi@eecs.umich.edu# the target(s).
1028120Sgblack@eecs.umich.edu#
1038120Sgblack@eecs.umich.edu###################################################
1048120Sgblack@eecs.umich.edu
1058120Sgblack@eecs.umich.edu# Find default configuration & binary.
1068120Sgblack@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1078120Sgblack@eecs.umich.edu
1088120Sgblack@eecs.umich.edu# Ask SCons which directory it was invoked from.
1098120Sgblack@eecs.umich.edulaunch_dir = GetLaunchDir()
1108879Ssteve.reinhardt@amd.com
1118879Ssteve.reinhardt@amd.com# Make targets relative to invocation directory
1128879Ssteve.reinhardt@amd.comabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1138879Ssteve.reinhardt@amd.com                  BUILD_TARGETS)
1148879Ssteve.reinhardt@amd.com
1158879Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list
1168879Ssteve.reinhardt@amd.comdef rfind(l, elt, offs = -1):
1178879Ssteve.reinhardt@amd.com    for i in range(len(l)+offs, 0, -1):
1188879Ssteve.reinhardt@amd.com        if l[i] == elt:
1198879Ssteve.reinhardt@amd.com            return i
1208879Ssteve.reinhardt@amd.com    raise ValueError, "element not found"
1218879Ssteve.reinhardt@amd.com
1228879Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the
1238120Sgblack@eecs.umich.edu# directory below this will determine the build parameters.  For
1248120Sgblack@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1258120Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1268120Sgblack@eecs.umich.edu# follow 'build' in the bulid path.
1278120Sgblack@eecs.umich.edu
1288120Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the
1298120Sgblack@eecs.umich.edu# collected targets reference.
1308120Sgblack@eecs.umich.edubuild_paths = []
1318120Sgblack@eecs.umich.edubuild_root = None
1328120Sgblack@eecs.umich.edufor t in abs_targets:
1338120Sgblack@eecs.umich.edu    path_dirs = t.split('/')
1348120Sgblack@eecs.umich.edu    try:
1358120Sgblack@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1368120Sgblack@eecs.umich.edu    except:
1378879Ssteve.reinhardt@amd.com        print "Error: no non-leaf 'build' dir found on target path", t
1388879Ssteve.reinhardt@amd.com        Exit(1)
1398879Ssteve.reinhardt@amd.com    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1408879Ssteve.reinhardt@amd.com    if not build_root:
14110458Sandreas.hansson@arm.com        build_root = this_build_root
14210458Sandreas.hansson@arm.com    else:
14310458Sandreas.hansson@arm.com        if this_build_root != build_root:
1448879Ssteve.reinhardt@amd.com            print "Error: build targets not under same build root\n"\
1458879Ssteve.reinhardt@amd.com                  "  %s\n  %s" % (build_root, this_build_root)
1468879Ssteve.reinhardt@amd.com            Exit(1)
1478879Ssteve.reinhardt@amd.com    build_path = os.path.join('/',*path_dirs[:build_top+2])
14813421Sciro.santilli@arm.com    if build_path not in build_paths:
14913421Sciro.santilli@arm.com        build_paths.append(build_path)
1509227Sandreas.hansson@arm.com
1519227Sandreas.hansson@arm.com###################################################
15212063Sgabeblack@google.com#
15312063Sgabeblack@google.com# Set up the default build environment.  This environment is copied
15412063Sgabeblack@google.com# and modified according to each selected configuration.
1558879Ssteve.reinhardt@amd.com#
1568879Ssteve.reinhardt@amd.com###################################################
1578879Ssteve.reinhardt@amd.com
1588879Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
15910453SAndrew.Bardsley@arm.com                  ROOT = ROOT,
16010453SAndrew.Bardsley@arm.com                  SRCDIR = SRCDIR)
16110453SAndrew.Bardsley@arm.com
16210456SCurtis.Dunham@arm.comenv.SConsignFile(os.path.join(build_root,"sconsign"))
16310456SCurtis.Dunham@arm.com
16410456SCurtis.Dunham@arm.com# Default duplicate option is to use hard links, but this messes up
16510457Sandreas.hansson@arm.com# when you use emacs to edit a file in the target dir, as emacs moves
16610457Sandreas.hansson@arm.com# file to file~ then copies to file, breaking the link.  Symbolic
16711342Sandreas.hansson@arm.com# (soft) links work better.
16811342Sandreas.hansson@arm.comenv.SetOption('duplicate', 'soft-copy')
1698120Sgblack@eecs.umich.edu
17012063Sgabeblack@google.com# I waffle on this setting... it does avoid a few painful but
17112563Sgabeblack@google.com# unnecessary builds, but it also seems to make trivial builds take
17212063Sgabeblack@google.com# noticeably longer.
17312063Sgabeblack@google.comif False:
1745871Snate@binkert.org    env.TargetSignatures('content')
1755871Snate@binkert.org
1766121Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package.
1775871Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1785871Snate@binkert.org
1799926Sstan.czerniawski@arm.com# Set up default C++ compiler flags
18012243Sgabeblack@google.comenv.Append(CCFLAGS='-pipe')
1811533SN/Aenv.Append(CCFLAGS='-fno-strict-aliasing')
18212246Sgabeblack@google.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
18312246Sgabeblack@google.comif sys.platform == 'cygwin':
18412246Sgabeblack@google.com    # cygwin has some header file issues...
18512246Sgabeblack@google.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1869239Sandreas.hansson@arm.comenv.Append(CPPPATH=[Dir('ext/dnet')])
1879239Sandreas.hansson@arm.com
1889239Sandreas.hansson@arm.com# Find Python include and library directories for embedding the
1899239Sandreas.hansson@arm.com# interpreter.  For consistency, we will use the same Python
19012563Sgabeblack@google.com# installation used to run scons (and thus this script).  If you want
1919239Sandreas.hansson@arm.com# to link in an alternate version, see above for instructions on how
1929239Sandreas.hansson@arm.com# to invoke scons with a different copy of the Python interpreter.
193955SN/A
194955SN/A# Get brief Python version name (e.g., "python2.4") for locating
1952632Sstever@eecs.umich.edu# include & library files
1962632Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3]
197955SN/A
198955SN/A# include path, e.g. /usr/local/include/python2.4
199955SN/Aenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
200955SN/Aenv.Append(LIBS = py_version_name)
2018878Ssteve.reinhardt@amd.com# add library path too if it's not in the default place
202955SN/Aif sys.exec_prefix != '/usr':
2032632Sstever@eecs.umich.edu    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
2042632Sstever@eecs.umich.edu
2052632Sstever@eecs.umich.edu# Set up SWIG flags & scanner
2062632Sstever@eecs.umich.edu
2072632Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2082632Sstever@eecs.umich.edu
2092632Sstever@eecs.umich.eduimport SCons.Scanner
2108268Ssteve.reinhardt@amd.com
2118268Ssteve.reinhardt@amd.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2128268Ssteve.reinhardt@amd.com
2138268Ssteve.reinhardt@amd.comswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2148268Ssteve.reinhardt@amd.com                                        swig_inc_re)
2158268Ssteve.reinhardt@amd.com
2168268Ssteve.reinhardt@amd.comenv.Append(SCANNERS = swig_scanner)
2172632Sstever@eecs.umich.edu
2182632Sstever@eecs.umich.edu# Other default libraries
2192632Sstever@eecs.umich.eduenv.Append(LIBS=['z'])
2202632Sstever@eecs.umich.edu
2218268Ssteve.reinhardt@amd.com# Platform-specific configuration.  Note again that we assume that all
2222632Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
2238268Ssteve.reinhardt@amd.comconf = Configure(env,
2248268Ssteve.reinhardt@amd.com                 conf_dir = os.path.join(build_root, '.scons_config'),
2258268Ssteve.reinhardt@amd.com                 log_file = os.path.join(build_root, 'scons_config.log'))
2268268Ssteve.reinhardt@amd.com
2273718Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
2282634Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
2292634Sstever@eecs.umich.eduif not have_fenv:
2305863Snate@binkert.org    print "Warning: Header file <fenv.h> not found."
2312638Sstever@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
2328268Ssteve.reinhardt@amd.com
2332632Sstever@eecs.umich.edu# Check for mysql.
2342632Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config')
2352632Sstever@eecs.umich.eduhave_mysql = mysql_config != None
2362632Sstever@eecs.umich.edu
23712563Sgabeblack@google.com# Check MySQL version.
2381858SN/Aif have_mysql:
2393716Sstever@eecs.umich.edu    mysql_version = os.popen(mysql_config + ' --version').read()
2402638Sstever@eecs.umich.edu    mysql_version = mysql_version.split('.')
2412638Sstever@eecs.umich.edu    mysql_major = int(mysql_version[0])
2422638Sstever@eecs.umich.edu    mysql_minor = int(mysql_version[1])
2432638Sstever@eecs.umich.edu    # This version check is probably overly conservative, but it deals
24412563Sgabeblack@google.com    # with the versions we have installed.
24512563Sgabeblack@google.com    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2462638Sstever@eecs.umich.edu        print "Warning: MySQL v4.1 or newer required."
2475863Snate@binkert.org        have_mysql = False
2485863Snate@binkert.org
2495863Snate@binkert.org# Set up mysql_config commands.
250955SN/Aif have_mysql:
2515341Sstever@gmail.com    mysql_config_include = mysql_config + ' --include'
2525341Sstever@gmail.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
2535863Snate@binkert.org        # older mysql_config versions don't support --include, use
2547756SAli.Saidi@ARM.com        # --cflags instead
2555341Sstever@gmail.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2566121Snate@binkert.org    # This seems to work in all versions
2574494Ssaidi@eecs.umich.edu    mysql_config_libs = mysql_config + ' --libs'
2586121Snate@binkert.org
2591105SN/Aenv = conf.Finish()
2602667Sstever@eecs.umich.edu
2612667Sstever@eecs.umich.edu# Define the universe of supported ISAs
2622667Sstever@eecs.umich.eduenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2632667Sstever@eecs.umich.edu
2646121Snate@binkert.org# Define the universe of supported CPU models
2652667Sstever@eecs.umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2665341Sstever@gmail.com                       'FullCPU', 'O3CPU',
2675863Snate@binkert.org                       'OzoneCPU']
2685341Sstever@gmail.com
2695341Sstever@gmail.com# Sticky options get saved in the options file so they persist from
2705341Sstever@gmail.com# one invocation to the next (unless overridden, in which case the new
2718120Sgblack@eecs.umich.edu# value becomes sticky).
2725341Sstever@gmail.comsticky_opts = Options(args=ARGUMENTS)
2738120Sgblack@eecs.umich.edusticky_opts.AddOptions(
2745341Sstever@gmail.com    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2758120Sgblack@eecs.umich.edu    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2766121Snate@binkert.org    # There's a bug in scons 0.96.1 that causes ListOptions with list
2776121Snate@binkert.org    # values (more than one value) not to be able to be restored from
2789396Sandreas.hansson@arm.com    # a saved option file.  If this causes trouble then upgrade to
2795397Ssaidi@eecs.umich.edu    # scons 0.96.90 or later.
2805397Ssaidi@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2817727SAli.Saidi@ARM.com               env['ALL_CPU_LIST']),
2828268Ssteve.reinhardt@amd.com    BoolOption('ALPHA_TLASER',
2836168Snate@binkert.org               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2845341Sstever@gmail.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2858120Sgblack@eecs.umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2868120Sgblack@eecs.umich.edu               False),
2878120Sgblack@eecs.umich.edu    BoolOption('SS_COMPATIBLE_FP',
2886814Sgblack@eecs.umich.edu               'Make floating-point results compatible with SimpleScalar',
2895863Snate@binkert.org               False),
2908120Sgblack@eecs.umich.edu    BoolOption('USE_SSE2',
2915341Sstever@gmail.com               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2925863Snate@binkert.org               False),
2938268Ssteve.reinhardt@amd.com    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2946121Snate@binkert.org    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2956121Snate@binkert.org    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
2968268Ssteve.reinhardt@amd.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2975742Snate@binkert.org    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2985742Snate@binkert.org    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2995341Sstever@gmail.com    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
3005742Snate@binkert.org    )
3015742Snate@binkert.org
3025341Sstever@gmail.com# Non-sticky options only apply to the current build.
3036017Snate@binkert.orgnonsticky_opts = Options(args=ARGUMENTS)
3046121Snate@binkert.orgnonsticky_opts.AddOptions(
3056017Snate@binkert.org    BoolOption('update_ref', 'Update test reference outputs', False)
30612158Sandreas.sandberg@arm.com    )
30712158Sandreas.sandberg@arm.com
30812158Sandreas.sandberg@arm.com# These options get exported to #defines in config/*.hh (see src/SConscript).
3098120Sgblack@eecs.umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3107756SAli.Saidi@ARM.com                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3117756SAli.Saidi@ARM.com                     'USE_CHECKER']
3127756SAli.Saidi@ARM.com
3137756SAli.Saidi@ARM.com# Define a handy 'no-op' action
3147816Ssteve.reinhardt@amd.comdef no_action(target, source, env):
3157816Ssteve.reinhardt@amd.com    return 0
3167816Ssteve.reinhardt@amd.com
3177816Ssteve.reinhardt@amd.comenv.NoAction = Action(no_action, None)
3187816Ssteve.reinhardt@amd.com
31911979Sgabeblack@google.com###################################################
3207816Ssteve.reinhardt@amd.com#
3217816Ssteve.reinhardt@amd.com# Define a SCons builder for configuration flag headers.
3227816Ssteve.reinhardt@amd.com#
3237816Ssteve.reinhardt@amd.com###################################################
3247756SAli.Saidi@ARM.com
3257756SAli.Saidi@ARM.com# This function generates a config header file that #defines the
3269227Sandreas.hansson@arm.com# option symbol to the current option setting (0 or 1).  The source
3279227Sandreas.hansson@arm.com# operands are the name of the option and a Value node containing the
3289227Sandreas.hansson@arm.com# value of the option.
3299227Sandreas.hansson@arm.comdef build_config_file(target, source, env):
3309590Sandreas@sandberg.pp.se    (option, value) = [s.get_contents() for s in source]
3319590Sandreas@sandberg.pp.se    f = file(str(target[0]), 'w')
3329590Sandreas@sandberg.pp.se    print >> f, '#define', option, value
3339590Sandreas@sandberg.pp.se    f.close()
3349590Sandreas@sandberg.pp.se    return None
3359590Sandreas@sandberg.pp.se
3366654Snate@binkert.org# Generate the message to be printed when building the config file.
3376654Snate@binkert.orgdef build_config_file_string(target, source, env):
3385871Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
3396121Snate@binkert.org    return "Defining %s as %s in %s." % (option, value, target[0])
3408946Sandreas.hansson@arm.com
3419419Sandreas.hansson@arm.com# Combine the two functions into a scons Action object.
34212563Sgabeblack@google.comconfig_action = Action(build_config_file, build_config_file_string)
3433918Ssaidi@eecs.umich.edu
3443918Ssaidi@eecs.umich.edu# The emitter munges the source & target node lists to reflect what
3451858SN/A# we're really doing.
3469556Sandreas.hansson@arm.comdef config_emitter(target, source, env):
3479556Sandreas.hansson@arm.com    # extract option name from Builder arg
3489556Sandreas.hansson@arm.com    option = str(target[0])
3499556Sandreas.hansson@arm.com    # True target is config header file
35011294Sandreas.hansson@arm.com    target = os.path.join('config', option.lower() + '.hh')
35111294Sandreas.hansson@arm.com    # Force value to 0/1 even if it's a Python bool
35211294Sandreas.hansson@arm.com    val = int(eval(str(env[option])))
35311294Sandreas.hansson@arm.com    # Sources are option name & value (packaged in SCons Value nodes)
35410878Sandreas.hansson@arm.com    return ([target], [Value(option), Value(val)])
35510878Sandreas.hansson@arm.com
35611811Sbaz21@cam.ac.ukconfig_builder = Builder(emitter = config_emitter, action = config_action)
35711811Sbaz21@cam.ac.uk
35811811Sbaz21@cam.ac.ukenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
35911982Sgabeblack@google.com
36011982Sgabeblack@google.com###################################################
36111982Sgabeblack@google.com#
36213421Sciro.santilli@arm.com# Define a SCons builder for copying files.  This is used by the
36313421Sciro.santilli@arm.com# Python zipfile code in src/python/SConscript, but is placed up here
36411982Sgabeblack@google.com# since it's potentially more generally applicable.
36511992Sgabeblack@google.com#
36611982Sgabeblack@google.com###################################################
36711982Sgabeblack@google.com
36812305Sgabeblack@google.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
36912305Sgabeblack@google.com
37012305Sgabeblack@google.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
37112305Sgabeblack@google.com
37212305Sgabeblack@google.com###################################################
37312305Sgabeblack@google.com#
37412305Sgabeblack@google.com# Define a simple SCons builder to concatenate files.
3759556Sandreas.hansson@arm.com#
37612563Sgabeblack@google.com# Used to append the Python zip archive to the executable.
37712563Sgabeblack@google.com#
37812563Sgabeblack@google.com###################################################
37912563Sgabeblack@google.com
3809556Sandreas.hansson@arm.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
38112563Sgabeblack@google.com                                          'chmod +x $TARGET']))
38212563Sgabeblack@google.com
3839556Sandreas.hansson@arm.comenv.Append(BUILDERS = { 'Concat' : concat_builder })
38412563Sgabeblack@google.com
38512563Sgabeblack@google.com
38612563Sgabeblack@google.com# base help text
38712563Sgabeblack@google.comhelp_text = '''
38812563Sgabeblack@google.comUsage: scons [scons options] [build options] [target(s)]
38912563Sgabeblack@google.com
39012563Sgabeblack@google.com'''
39112563Sgabeblack@google.com
3929556Sandreas.hansson@arm.com# libelf build is shared across all configs in the build root.
3939556Sandreas.hansson@arm.comenv.SConscript('ext/libelf/SConscript',
3946121Snate@binkert.org               build_dir = os.path.join(build_root, 'libelf'),
39511500Sandreas.hansson@arm.com               exports = 'env')
39610238Sandreas.hansson@arm.com
39710878Sandreas.hansson@arm.com###################################################
3989420Sandreas.hansson@arm.com#
39911500Sandreas.hansson@arm.com# Define build environments for selected configurations.
40012563Sgabeblack@google.com#
40112563Sgabeblack@google.com###################################################
4029420Sandreas.hansson@arm.com
4039420Sandreas.hansson@arm.com# rename base env
4049420Sandreas.hansson@arm.combase_env = env
4059420Sandreas.hansson@arm.com
40612063Sgabeblack@google.comfor build_path in build_paths:
40712063Sgabeblack@google.com    print "Building in", build_path
40812063Sgabeblack@google.com    # build_dir is the tail component of build path, and is used to
40912063Sgabeblack@google.com    # determine the build parameters (e.g., 'ALPHA_SE')
41012063Sgabeblack@google.com    (build_root, build_dir) = os.path.split(build_path)
41112063Sgabeblack@google.com    # Make a copy of the build-root environment to use for this config.
41212063Sgabeblack@google.com    env = base_env.Copy()
41312063Sgabeblack@google.com
41412063Sgabeblack@google.com    # Set env options according to the build directory config.
41512063Sgabeblack@google.com    sticky_opts.files = []
41612063Sgabeblack@google.com    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
41712063Sgabeblack@google.com    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
41812063Sgabeblack@google.com    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
41912063Sgabeblack@google.com    current_opts_file = os.path.join(build_root, 'options', build_dir)
42012063Sgabeblack@google.com    if os.path.isfile(current_opts_file):
42112063Sgabeblack@google.com        sticky_opts.files.append(current_opts_file)
42212063Sgabeblack@google.com        print "Using saved options file %s" % current_opts_file
42312063Sgabeblack@google.com    else:
42412063Sgabeblack@google.com        # Build dir-specific options file doesn't exist.
42512063Sgabeblack@google.com
42612063Sgabeblack@google.com        # Make sure the directory is there so we can create it later
42712063Sgabeblack@google.com        opt_dir = os.path.dirname(current_opts_file)
42810457Sandreas.hansson@arm.com        if not os.path.isdir(opt_dir):
42910457Sandreas.hansson@arm.com            os.mkdir(opt_dir)
43010457Sandreas.hansson@arm.com
43110457Sandreas.hansson@arm.com        # Get default build options from source tree.  Options are
43210457Sandreas.hansson@arm.com        # normally determined by name of $BUILD_DIR, but can be
43312563Sgabeblack@google.com        # overriden by 'default=' arg on command line.
43412563Sgabeblack@google.com        default_opts_file = os.path.join('build_opts',
43512563Sgabeblack@google.com                                         ARGUMENTS.get('default', build_dir))
43610457Sandreas.hansson@arm.com        if os.path.isfile(default_opts_file):
43712063Sgabeblack@google.com            sticky_opts.files.append(default_opts_file)
43812063Sgabeblack@google.com            print "Options file %s not found,\n  using defaults in %s" \
43912063Sgabeblack@google.com                  % (current_opts_file, default_opts_file)
44012563Sgabeblack@google.com        else:
44112563Sgabeblack@google.com            print "Error: cannot find options file %s or %s" \
44212563Sgabeblack@google.com                  % (current_opts_file, default_opts_file)
44312563Sgabeblack@google.com            Exit(1)
44412563Sgabeblack@google.com
44512563Sgabeblack@google.com    # Apply current option settings to env
44612063Sgabeblack@google.com    sticky_opts.Update(env)
44712063Sgabeblack@google.com    nonsticky_opts.Update(env)
44810238Sandreas.hansson@arm.com
44910238Sandreas.hansson@arm.com    help_text += "Sticky options for %s:\n" % build_dir \
45010238Sandreas.hansson@arm.com                 + sticky_opts.GenerateHelpText(env) \
45112063Sgabeblack@google.com                 + "\nNon-sticky options for %s:\n" % build_dir \
45210238Sandreas.hansson@arm.com                 + nonsticky_opts.GenerateHelpText(env)
45310238Sandreas.hansson@arm.com
45410416Sandreas.hansson@arm.com    # Process option settings.
45510238Sandreas.hansson@arm.com
4569227Sandreas.hansson@arm.com    if not have_fenv and env['USE_FENV']:
45710238Sandreas.hansson@arm.com        print "Warning: <fenv.h> not available; " \
45810416Sandreas.hansson@arm.com              "forcing USE_FENV to False in", build_dir + "."
45910416Sandreas.hansson@arm.com        env['USE_FENV'] = False
4609227Sandreas.hansson@arm.com
4619590Sandreas@sandberg.pp.se    if not env['USE_FENV']:
4629590Sandreas@sandberg.pp.se        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4639590Sandreas@sandberg.pp.se        print "         FP results may deviate slightly from other platforms."
46412304Sgabeblack@google.com
46512304Sgabeblack@google.com    if env['EFENCE']:
46612304Sgabeblack@google.com        env.Append(LIBS=['efence'])
46712688Sgiacomo.travaglini@arm.com
46812688Sgiacomo.travaglini@arm.com    if env['USE_MYSQL']:
46912688Sgiacomo.travaglini@arm.com        if not have_mysql:
47013020Sshunhsingou@google.com            print "Warning: MySQL not available; " \
47112304Sgabeblack@google.com                  "forcing USE_MYSQL to False in", build_dir + "."
47212688Sgiacomo.travaglini@arm.com            env['USE_MYSQL'] = False
47312688Sgiacomo.travaglini@arm.com        else:
47413020Sshunhsingou@google.com            print "Compiling in", build_dir, "with MySQL support."
47512304Sgabeblack@google.com            env.ParseConfig(mysql_config_libs)
47612304Sgabeblack@google.com            env.ParseConfig(mysql_config_include)
47712304Sgabeblack@google.com
47812304Sgabeblack@google.com    # Save sticky option settings back to current options file
47912688Sgiacomo.travaglini@arm.com    sticky_opts.Save(current_opts_file, env)
48012688Sgiacomo.travaglini@arm.com
48112688Sgiacomo.travaglini@arm.com    # Do this after we save setting back, or else we'll tack on an
48212304Sgabeblack@google.com    # extra 'qdo' every time we run scons.
4838737Skoansin.tan@gmail.com    if env['BATCH']:
48410878Sandreas.hansson@arm.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
48511500Sandreas.hansson@arm.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4869420Sandreas.hansson@arm.com
4878737Skoansin.tan@gmail.com    if env['USE_SSE2']:
48810106SMitch.Hayenga@arm.com        env.Append(CCFLAGS='-msse2')
4898737Skoansin.tan@gmail.com
4908737Skoansin.tan@gmail.com    # The src/SConscript file sets up the build rules in 'env' according
49110878Sandreas.hansson@arm.com    # to the configured options.  It returns a list of environments,
49212563Sgabeblack@google.com    # one for each variant build (debug, opt, etc.)
49312563Sgabeblack@google.com    envList = SConscript('src/SConscript', build_dir = build_path,
4948737Skoansin.tan@gmail.com                         exports = 'env')
4958737Skoansin.tan@gmail.com
49612563Sgabeblack@google.com    # Set up the regression tests for each build.
4978737Skoansin.tan@gmail.com#    for e in envList:
4988737Skoansin.tan@gmail.com#        SConscript('m5-test/SConscript',
49911294Sandreas.hansson@arm.com#                   build_dir = os.path.join(build_dir, 'test', e.Label),
5009556Sandreas.hansson@arm.com#                   exports = { 'env' : e }, duplicate = False)
5019556Sandreas.hansson@arm.com
5029556Sandreas.hansson@arm.comHelp(help_text)
50311294Sandreas.hansson@arm.com
50410278SAndreas.Sandberg@ARM.com###################################################
50510278SAndreas.Sandberg@ARM.com#
50610278SAndreas.Sandberg@ARM.com# Let SCons do its thing.  At this point SCons will use the defined
50710278SAndreas.Sandberg@ARM.com# build environments to build the requested targets.
50810278SAndreas.Sandberg@ARM.com#
50910278SAndreas.Sandberg@ARM.com###################################################
5109556Sandreas.hansson@arm.com
5119590Sandreas@sandberg.pp.se