SConstruct revision 2932:eba74420a01c
1955SN/A# -*- mode:python -*-
2955SN/A
37816Ssteve.reinhardt@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
45871Snate@binkert.org# All rights reserved.
51762SN/A#
6955SN/A# Redistribution and use in source and binary forms, with or without
7955SN/A# modification, are permitted provided that the following conditions are
8955SN/A# met: redistributions of source code must retain the above copyright
9955SN/A# notice, this list of conditions and the following disclaimer;
10955SN/A# redistributions in binary form must reproduce the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer in the
12955SN/A# documentation and/or other materials provided with the distribution;
13955SN/A# neither the name of the copyright holders nor the names of its
14955SN/A# contributors may be used to endorse or promote products derived from
15955SN/A# this software without specific prior written permission.
16955SN/A#
17955SN/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
302665Ssaidi@eecs.umich.edu
312665Ssaidi@eecs.umich.edu###################################################
325863Snate@binkert.org#
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
388878Ssteve.reinhardt@amd.com# the optimized full-system version).
392632Sstever@eecs.umich.edu#
408878Ssteve.reinhardt@amd.com# You can build M5 in a different directory as long as there is a
412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
42955SN/A# expects that all configs under the same build directory are being
438878Ssteve.reinhardt@amd.com# built for the same host system.
442632Sstever@eecs.umich.edu#
452761Sstever@eecs.umich.edu# Examples:
462632Sstever@eecs.umich.edu#
472632Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
482632Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
492761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
502761Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512761Sstever@eecs.umich.edu#
528878Ssteve.reinhardt@amd.com#   The following two commands are equivalent and demonstrate building
538878Ssteve.reinhardt@amd.com#   in a directory outside of the source tree.  The '-C' option tells
542761Sstever@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
552761Sstever@eecs.umich.edu#   file.
562761Sstever@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
582761Sstever@eecs.umich.edu#
598878Ssteve.reinhardt@amd.com# You can use 'scons -H' to print scons options.  If you're in this
608878Ssteve.reinhardt@amd.com# 'm5' directory (or use -u or -C to tell scons where to find this
612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
622632Sstever@eecs.umich.edu# options as well.
638878Ssteve.reinhardt@amd.com#
648878Ssteve.reinhardt@amd.com###################################################
652632Sstever@eecs.umich.edu
66955SN/A# Python library imports
67955SN/Aimport sys
68955SN/Aimport os
695863Snate@binkert.org
705863Snate@binkert.org# Check for recent-enough Python and SCons versions.  If your system's
715863Snate@binkert.org# default installation of Python is not recent enough, you can use a
725863Snate@binkert.org# non-default installation of the Python interpreter by either (1)
735863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python'
745863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the
755863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
765863Snate@binkert.orgEnsurePythonVersion(2,4)
775863Snate@binkert.org
785863Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
795863Snate@binkert.org# 3-element version number.
808878Ssteve.reinhardt@amd.commin_scons_version = (0,96,91)
815863Snate@binkert.orgtry:
825863Snate@binkert.org    EnsureSConsVersion(*min_scons_version)
835863Snate@binkert.orgexcept:
845863Snate@binkert.org    print "Error checking current SCons version."
855863Snate@binkert.org    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
865863Snate@binkert.org    Exit(2)
875863Snate@binkert.org    
885863Snate@binkert.org
895863Snate@binkert.org# The absolute path to the current directory (where this file lives).
905863Snate@binkert.orgROOT = 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
955863Snate@binkert.org# tell python where to find m5 python code
968878Ssteve.reinhardt@amd.comsys.path.append(os.path.join(ROOT, 'src/python'))
975863Snate@binkert.org
985863Snate@binkert.org###################################################
995863Snate@binkert.org#
1006654Snate@binkert.org# Figure out which configurations to set up based on the path(s) of
101955SN/A# the target(s).
1025396Ssaidi@eecs.umich.edu#
1035863Snate@binkert.org###################################################
1045863Snate@binkert.org
1054202Sbinkertn@umich.edu# Find default configuration & binary.
1065863Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1075863Snate@binkert.org
1085863Snate@binkert.org# Ask SCons which directory it was invoked from.
1095863Snate@binkert.orglaunch_dir = GetLaunchDir()
110955SN/A
1116654Snate@binkert.org# Make targets relative to invocation directory
1125273Sstever@gmail.comabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1135871Snate@binkert.org                  BUILD_TARGETS)
1145273Sstever@gmail.com
1156655Snate@binkert.org# helper function: find last occurrence of element in list
1168878Ssteve.reinhardt@amd.comdef rfind(l, elt, offs = -1):
1176655Snate@binkert.org    for i in range(len(l)+offs, 0, -1):
1186655Snate@binkert.org        if l[i] == elt:
1196655Snate@binkert.org            return i
1206655Snate@binkert.org    raise ValueError, "element not found"
1215871Snate@binkert.org
1226654Snate@binkert.org# Each target must have 'build' in the interior of the path; the
1238947Sandreas.hansson@arm.com# directory below this will determine the build parameters.  For
1245396Ssaidi@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:
1338879Ssteve.reinhardt@amd.com    path_dirs = t.split('/')
1348879Ssteve.reinhardt@amd.com    try:
1358879Ssteve.reinhardt@amd.com        build_top = rfind(path_dirs, 'build', -2)
1368879Ssteve.reinhardt@amd.com    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:
1418879Ssteve.reinhardt@amd.com        build_root = this_build_root
1428879Ssteve.reinhardt@amd.com    else:
1438879Ssteve.reinhardt@amd.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)
1468120Sgblack@eecs.umich.edu            Exit(1)
1478120Sgblack@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1488120Sgblack@eecs.umich.edu    if build_path not in build_paths:
1498120Sgblack@eecs.umich.edu        build_paths.append(build_path)
1508120Sgblack@eecs.umich.edu
1518120Sgblack@eecs.umich.edu###################################################
1528120Sgblack@eecs.umich.edu#
1538120Sgblack@eecs.umich.edu# Set up the default build environment.  This environment is copied
1548120Sgblack@eecs.umich.edu# and modified according to each selected configuration.
1558120Sgblack@eecs.umich.edu#
1568120Sgblack@eecs.umich.edu###################################################
1578120Sgblack@eecs.umich.edu
1588120Sgblack@eecs.umich.eduenv = Environment(ENV = os.environ,  # inherit user's environment vars
1598120Sgblack@eecs.umich.edu                  ROOT = ROOT,
1608879Ssteve.reinhardt@amd.com                  SRCDIR = SRCDIR)
1618879Ssteve.reinhardt@amd.com
1628879Ssteve.reinhardt@amd.comenv.SConsignFile(os.path.join(build_root,"sconsign"))
1638879Ssteve.reinhardt@amd.com
1648879Ssteve.reinhardt@amd.com# Default duplicate option is to use hard links, but this messes up
1658879Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves
1668879Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link.  Symbolic
1678879Ssteve.reinhardt@amd.com# (soft) links work better.
1688879Ssteve.reinhardt@amd.comenv.SetOption('duplicate', 'soft-copy')
1698879Ssteve.reinhardt@amd.com
1708879Ssteve.reinhardt@amd.com# I waffle on this setting... it does avoid a few painful but
1718879Ssteve.reinhardt@amd.com# unnecessary builds, but it also seems to make trivial builds take
1728120Sgblack@eecs.umich.edu# noticeably longer.
1738947Sandreas.hansson@arm.comif False:
1747816Ssteve.reinhardt@amd.com    env.TargetSignatures('content')
1755871Snate@binkert.org
1765871Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package.
1776121Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1785871Snate@binkert.org
1795871Snate@binkert.org# Set up default C++ compiler flags
1806003Snate@binkert.orgenv.Append(CCFLAGS='-pipe')
1818980Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-fno-strict-aliasing')
182955SN/Aenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1835871Snate@binkert.orgif sys.platform == 'cygwin':
1845871Snate@binkert.org    # cygwin has some header file issues...
1855871Snate@binkert.org    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1865871Snate@binkert.orgenv.Append(CPPPATH=[Dir('ext/dnet')])
187955SN/A
1886121Snate@binkert.org# Find Python include and library directories for embedding the
1898881Smarc.orr@gmail.com# interpreter.  For consistency, we will use the same Python
1906121Snate@binkert.org# installation used to run scons (and thus this script).  If you want
1916121Snate@binkert.org# to link in an alternate version, see above for instructions on how
1921533SN/A# to invoke scons with a different copy of the Python interpreter.
1936655Snate@binkert.org
1946655Snate@binkert.org# Get brief Python version name (e.g., "python2.4") for locating
1956655Snate@binkert.org# include & library files
1966655Snate@binkert.orgpy_version_name = 'python' + sys.version[:3]
1975871Snate@binkert.org
1985871Snate@binkert.org# include path, e.g. /usr/local/include/python2.4
1995863Snate@binkert.orgenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
2005871Snate@binkert.orgenv.Append(LIBS = py_version_name)
2018878Ssteve.reinhardt@amd.com# add library path too if it's not in the default place
2025871Snate@binkert.orgif sys.exec_prefix != '/usr':
2035871Snate@binkert.org    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
2045871Snate@binkert.org
2055863Snate@binkert.org# Set up SWIG flags & scanner
2066121Snate@binkert.org
2075863Snate@binkert.orgenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2085871Snate@binkert.org
2098336Ssteve.reinhardt@amd.comimport SCons.Scanner
2108336Ssteve.reinhardt@amd.com
2118336Ssteve.reinhardt@amd.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2128336Ssteve.reinhardt@amd.com
2134678Snate@binkert.orgswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2148336Ssteve.reinhardt@amd.com                                        swig_inc_re)
2158336Ssteve.reinhardt@amd.com
2168336Ssteve.reinhardt@amd.comenv.Append(SCANNERS = swig_scanner)
2174678Snate@binkert.org
2184678Snate@binkert.org# Other default libraries
2194678Snate@binkert.orgenv.Append(LIBS=['z'])
2204678Snate@binkert.org
2217827Snate@binkert.org# Platform-specific configuration.  Note again that we assume that all
2227827Snate@binkert.org# builds under a given build root run on the same host platform.
2238336Ssteve.reinhardt@amd.comconf = Configure(env,
2244678Snate@binkert.org                 conf_dir = os.path.join(build_root, '.scons_config'),
2258336Ssteve.reinhardt@amd.com                 log_file = os.path.join(build_root, 'scons_config.log'))
2268336Ssteve.reinhardt@amd.com
2278336Ssteve.reinhardt@amd.com# Check for <fenv.h> (C99 FP environment control)
2288336Ssteve.reinhardt@amd.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
2298336Ssteve.reinhardt@amd.comif not have_fenv:
2308336Ssteve.reinhardt@amd.com    print "Warning: Header file <fenv.h> not found."
2315871Snate@binkert.org    print "         This host has no IEEE FP rounding mode control."
2325871Snate@binkert.org
2338336Ssteve.reinhardt@amd.com# Check for mysql.
2348336Ssteve.reinhardt@amd.commysql_config = WhereIs('mysql_config')
2358336Ssteve.reinhardt@amd.comhave_mysql = mysql_config != None
2368336Ssteve.reinhardt@amd.com
2378336Ssteve.reinhardt@amd.com# Check MySQL version.
2385871Snate@binkert.orgif have_mysql:
2398336Ssteve.reinhardt@amd.com    mysql_version = os.popen(mysql_config + ' --version').read()
2408336Ssteve.reinhardt@amd.com    mysql_version = mysql_version.split('.')
2418336Ssteve.reinhardt@amd.com    mysql_major = int(mysql_version[0])
2428336Ssteve.reinhardt@amd.com    mysql_minor = int(mysql_version[1])
2438336Ssteve.reinhardt@amd.com    # This version check is probably overly conservative, but it deals
2444678Snate@binkert.org    # with the versions we have installed.
2455871Snate@binkert.org    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2464678Snate@binkert.org        print "Warning: MySQL v4.1 or newer required."
2478336Ssteve.reinhardt@amd.com        have_mysql = False
2488336Ssteve.reinhardt@amd.com
2498336Ssteve.reinhardt@amd.com# Set up mysql_config commands.
2508336Ssteve.reinhardt@amd.comif have_mysql:
2518336Ssteve.reinhardt@amd.com    mysql_config_include = mysql_config + ' --include'
2528336Ssteve.reinhardt@amd.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
2538336Ssteve.reinhardt@amd.com        # older mysql_config versions don't support --include, use
2548336Ssteve.reinhardt@amd.com        # --cflags instead
2558336Ssteve.reinhardt@amd.com        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2568336Ssteve.reinhardt@amd.com    # This seems to work in all versions
2578336Ssteve.reinhardt@amd.com    mysql_config_libs = mysql_config + ' --libs'
2588336Ssteve.reinhardt@amd.com
2598336Ssteve.reinhardt@amd.comenv = conf.Finish()
2608336Ssteve.reinhardt@amd.com
2618336Ssteve.reinhardt@amd.com# Define the universe of supported ISAs
2628336Ssteve.reinhardt@amd.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2638336Ssteve.reinhardt@amd.com
2645871Snate@binkert.org# Define the universe of supported CPU models
2656121Snate@binkert.orgenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
266955SN/A                       'FullCPU', 'O3CPU',
267955SN/A                       'OzoneCPU']
2682632Sstever@eecs.umich.edu
2692632Sstever@eecs.umich.edu# Sticky options get saved in the options file so they persist from
270955SN/A# one invocation to the next (unless overridden, in which case the new
271955SN/A# value becomes sticky).
272955SN/Asticky_opts = Options(args=ARGUMENTS)
273955SN/Asticky_opts.AddOptions(
2748878Ssteve.reinhardt@amd.com    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
275955SN/A    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2762632Sstever@eecs.umich.edu    # There's a bug in scons 0.96.1 that causes ListOptions with list
2772632Sstever@eecs.umich.edu    # values (more than one value) not to be able to be restored from
2782632Sstever@eecs.umich.edu    # a saved option file.  If this causes trouble then upgrade to
2792632Sstever@eecs.umich.edu    # scons 0.96.90 or later.
2802632Sstever@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2812632Sstever@eecs.umich.edu               env['ALL_CPU_LIST']),
2822632Sstever@eecs.umich.edu    ListOption('TEST_CPU_MODELS', 'CPU models to test if regression is being run', '',
2838268Ssteve.reinhardt@amd.com               env['ALL_CPU_LIST']),
2848268Ssteve.reinhardt@amd.com    BoolOption('ALPHA_TLASER',
2858268Ssteve.reinhardt@amd.com               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2868268Ssteve.reinhardt@amd.com    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2878268Ssteve.reinhardt@amd.com    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2888268Ssteve.reinhardt@amd.com               False),
2898268Ssteve.reinhardt@amd.com    BoolOption('SS_COMPATIBLE_FP',
2902632Sstever@eecs.umich.edu               'Make floating-point results compatible with SimpleScalar',
2912632Sstever@eecs.umich.edu               False),
2922632Sstever@eecs.umich.edu    BoolOption('USE_SSE2',
2932632Sstever@eecs.umich.edu               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2948268Ssteve.reinhardt@amd.com               False),
2952632Sstever@eecs.umich.edu    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2968268Ssteve.reinhardt@amd.com    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2978268Ssteve.reinhardt@amd.com    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
2988268Ssteve.reinhardt@amd.com    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2998268Ssteve.reinhardt@amd.com    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
3003718Sstever@eecs.umich.edu    BoolOption('BATCH', 'Use batch pool for build and tests', False),
3012634Sstever@eecs.umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
3022634Sstever@eecs.umich.edu    )
3035863Snate@binkert.org
3042638Sstever@eecs.umich.edu# Non-sticky options only apply to the current build.
3058268Ssteve.reinhardt@amd.comnonsticky_opts = Options(args=ARGUMENTS)
3062632Sstever@eecs.umich.edunonsticky_opts.AddOptions(
3072632Sstever@eecs.umich.edu    BoolOption('update_ref', 'Update test reference outputs', False)
3082632Sstever@eecs.umich.edu    )
3092632Sstever@eecs.umich.edu
3102632Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript).
3111858SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3123716Sstever@eecs.umich.edu                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3132638Sstever@eecs.umich.edu                     'USE_CHECKER']
3142638Sstever@eecs.umich.edu
3152638Sstever@eecs.umich.edu# Define a handy 'no-op' action
3162638Sstever@eecs.umich.edudef no_action(target, source, env):
3172638Sstever@eecs.umich.edu    return 0
3182638Sstever@eecs.umich.edu
3192638Sstever@eecs.umich.eduenv.NoAction = Action(no_action, None)
3205863Snate@binkert.org
3215863Snate@binkert.org###################################################
3225863Snate@binkert.org#
323955SN/A# Define a SCons builder for configuration flag headers.
3245341Sstever@gmail.com#
3255341Sstever@gmail.com###################################################
3265863Snate@binkert.org
3277756SAli.Saidi@ARM.com# This function generates a config header file that #defines the
3285341Sstever@gmail.com# option symbol to the current option setting (0 or 1).  The source
3296121Snate@binkert.org# operands are the name of the option and a Value node containing the
3304494Ssaidi@eecs.umich.edu# value of the option.
3316121Snate@binkert.orgdef build_config_file(target, source, env):
3321105SN/A    (option, value) = [s.get_contents() for s in source]
3332667Sstever@eecs.umich.edu    f = file(str(target[0]), 'w')
3342667Sstever@eecs.umich.edu    print >> f, '#define', option, value
3352667Sstever@eecs.umich.edu    f.close()
3362667Sstever@eecs.umich.edu    return None
3376121Snate@binkert.org
3382667Sstever@eecs.umich.edu# Generate the message to be printed when building the config file.
3395341Sstever@gmail.comdef build_config_file_string(target, source, env):
3405863Snate@binkert.org    (option, value) = [s.get_contents() for s in source]
3415341Sstever@gmail.com    return "Defining %s as %s in %s." % (option, value, target[0])
3425341Sstever@gmail.com
3435341Sstever@gmail.com# Combine the two functions into a scons Action object.
3448120Sgblack@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string)
3455341Sstever@gmail.com
3468120Sgblack@eecs.umich.edu# The emitter munges the source & target node lists to reflect what
3475341Sstever@gmail.com# we're really doing.
3488120Sgblack@eecs.umich.edudef config_emitter(target, source, env):
3496121Snate@binkert.org    # extract option name from Builder arg
3506121Snate@binkert.org    option = str(target[0])
3518980Ssteve.reinhardt@amd.com    # True target is config header file
3525397Ssaidi@eecs.umich.edu    target = os.path.join('config', option.lower() + '.hh')
3535397Ssaidi@eecs.umich.edu    # Force value to 0/1 even if it's a Python bool
3547727SAli.Saidi@ARM.com    val = int(eval(str(env[option])))
3558268Ssteve.reinhardt@amd.com    # Sources are option name & value (packaged in SCons Value nodes)
3566168Snate@binkert.org    return ([target], [Value(option), Value(val)])
3575341Sstever@gmail.com
3588120Sgblack@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action)
3598120Sgblack@eecs.umich.edu
3608120Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3616814Sgblack@eecs.umich.edu
3625863Snate@binkert.org###################################################
3638120Sgblack@eecs.umich.edu#
3645341Sstever@gmail.com# Define a SCons builder for copying files.  This is used by the
3655863Snate@binkert.org# Python zipfile code in src/python/SConscript, but is placed up here
3668268Ssteve.reinhardt@amd.com# since it's potentially more generally applicable.
3676121Snate@binkert.org#
3686121Snate@binkert.org###################################################
3698268Ssteve.reinhardt@amd.com
3705742Snate@binkert.orgcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3715742Snate@binkert.org
3725341Sstever@gmail.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3735742Snate@binkert.org
3745742Snate@binkert.org###################################################
3755341Sstever@gmail.com#
3766017Snate@binkert.org# Define a simple SCons builder to concatenate files.
3776121Snate@binkert.org#
3786017Snate@binkert.org# Used to append the Python zip archive to the executable.
3797816Ssteve.reinhardt@amd.com#
3807756SAli.Saidi@ARM.com###################################################
3817756SAli.Saidi@ARM.com
3827756SAli.Saidi@ARM.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3837756SAli.Saidi@ARM.com                                          'chmod +x $TARGET']))
3847756SAli.Saidi@ARM.com
3857756SAli.Saidi@ARM.comenv.Append(BUILDERS = { 'Concat' : concat_builder })
3867756SAli.Saidi@ARM.com
3877756SAli.Saidi@ARM.com
3887816Ssteve.reinhardt@amd.com# base help text
3897816Ssteve.reinhardt@amd.comhelp_text = '''
3907816Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)]
3917816Ssteve.reinhardt@amd.com
3927816Ssteve.reinhardt@amd.com'''
3937816Ssteve.reinhardt@amd.com
3947816Ssteve.reinhardt@amd.com# libelf build is shared across all configs in the build root.
3957816Ssteve.reinhardt@amd.comenv.SConscript('ext/libelf/SConscript',
3967816Ssteve.reinhardt@amd.com               build_dir = os.path.join(build_root, 'libelf'),
3977816Ssteve.reinhardt@amd.com               exports = 'env')
3987756SAli.Saidi@ARM.com
3997816Ssteve.reinhardt@amd.com###################################################
4007816Ssteve.reinhardt@amd.com#
4017816Ssteve.reinhardt@amd.com# Define build environments for selected configurations.
4027816Ssteve.reinhardt@amd.com#
4037816Ssteve.reinhardt@amd.com###################################################
4047816Ssteve.reinhardt@amd.com
4057816Ssteve.reinhardt@amd.com# rename base env
4067816Ssteve.reinhardt@amd.combase_env = env
4077816Ssteve.reinhardt@amd.com
4087816Ssteve.reinhardt@amd.comfor build_path in build_paths:
4097816Ssteve.reinhardt@amd.com    print "Building in", build_path
4107816Ssteve.reinhardt@amd.com    # build_dir is the tail component of build path, and is used to
4117816Ssteve.reinhardt@amd.com    # determine the build parameters (e.g., 'ALPHA_SE')
4127816Ssteve.reinhardt@amd.com    (build_root, build_dir) = os.path.split(build_path)
4137816Ssteve.reinhardt@amd.com    # Make a copy of the build-root environment to use for this config.
4147816Ssteve.reinhardt@amd.com    env = base_env.Copy()
4157816Ssteve.reinhardt@amd.com
4167816Ssteve.reinhardt@amd.com    # Set env options according to the build directory config.
4177816Ssteve.reinhardt@amd.com    sticky_opts.files = []
4187816Ssteve.reinhardt@amd.com    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
4197816Ssteve.reinhardt@amd.com    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
4207816Ssteve.reinhardt@amd.com    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
4217816Ssteve.reinhardt@amd.com    current_opts_file = os.path.join(build_root, 'options', build_dir)
4227816Ssteve.reinhardt@amd.com    if os.path.isfile(current_opts_file):
4237816Ssteve.reinhardt@amd.com        sticky_opts.files.append(current_opts_file)
4247816Ssteve.reinhardt@amd.com        print "Using saved options file %s" % current_opts_file
4257816Ssteve.reinhardt@amd.com    else:
4267816Ssteve.reinhardt@amd.com        # Build dir-specific options file doesn't exist.
4277816Ssteve.reinhardt@amd.com
4287816Ssteve.reinhardt@amd.com        # Make sure the directory is there so we can create it later
4297816Ssteve.reinhardt@amd.com        opt_dir = os.path.dirname(current_opts_file)
4307816Ssteve.reinhardt@amd.com        if not os.path.isdir(opt_dir):
4317816Ssteve.reinhardt@amd.com            os.mkdir(opt_dir)
4327816Ssteve.reinhardt@amd.com
4337816Ssteve.reinhardt@amd.com        # Get default build options from source tree.  Options are
4347816Ssteve.reinhardt@amd.com        # normally determined by name of $BUILD_DIR, but can be
4357816Ssteve.reinhardt@amd.com        # overriden by 'default=' arg on command line.
4367816Ssteve.reinhardt@amd.com        default_opts_file = os.path.join('build_opts',
4377816Ssteve.reinhardt@amd.com                                         ARGUMENTS.get('default', build_dir))
4387816Ssteve.reinhardt@amd.com        if os.path.isfile(default_opts_file):
4397816Ssteve.reinhardt@amd.com            sticky_opts.files.append(default_opts_file)
4407816Ssteve.reinhardt@amd.com            print "Options file %s not found,\n  using defaults in %s" \
4417816Ssteve.reinhardt@amd.com                  % (current_opts_file, default_opts_file)
4427816Ssteve.reinhardt@amd.com        else:
4437816Ssteve.reinhardt@amd.com            print "Error: cannot find options file %s or %s" \
4447816Ssteve.reinhardt@amd.com                  % (current_opts_file, default_opts_file)
4457816Ssteve.reinhardt@amd.com            Exit(1)
4467816Ssteve.reinhardt@amd.com
4477816Ssteve.reinhardt@amd.com    # Apply current option settings to env
4487816Ssteve.reinhardt@amd.com    sticky_opts.Update(env)
4497816Ssteve.reinhardt@amd.com    nonsticky_opts.Update(env)
4507816Ssteve.reinhardt@amd.com
4517816Ssteve.reinhardt@amd.com    help_text += "Sticky options for %s:\n" % build_dir \
4527816Ssteve.reinhardt@amd.com                 + sticky_opts.GenerateHelpText(env) \
4537816Ssteve.reinhardt@amd.com                 + "\nNon-sticky options for %s:\n" % build_dir \
4547816Ssteve.reinhardt@amd.com                 + nonsticky_opts.GenerateHelpText(env)
4557816Ssteve.reinhardt@amd.com
4567816Ssteve.reinhardt@amd.com    # Process option settings.
4577816Ssteve.reinhardt@amd.com
4587816Ssteve.reinhardt@amd.com    if not have_fenv and env['USE_FENV']:
4597816Ssteve.reinhardt@amd.com        print "Warning: <fenv.h> not available; " \
4608947Sandreas.hansson@arm.com              "forcing USE_FENV to False in", build_dir + "."
4618947Sandreas.hansson@arm.com        env['USE_FENV'] = False
4627756SAli.Saidi@ARM.com
4638120Sgblack@eecs.umich.edu    if not env['USE_FENV']:
4647756SAli.Saidi@ARM.com        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4657756SAli.Saidi@ARM.com        print "         FP results may deviate slightly from other platforms."
4667756SAli.Saidi@ARM.com
4677756SAli.Saidi@ARM.com    if env['EFENCE']:
4687816Ssteve.reinhardt@amd.com        env.Append(LIBS=['efence'])
4697816Ssteve.reinhardt@amd.com
4707816Ssteve.reinhardt@amd.com    if env['USE_MYSQL']:
4717816Ssteve.reinhardt@amd.com        if not have_mysql:
4727816Ssteve.reinhardt@amd.com            print "Warning: MySQL not available; " \
4737816Ssteve.reinhardt@amd.com                  "forcing USE_MYSQL to False in", build_dir + "."
4747816Ssteve.reinhardt@amd.com            env['USE_MYSQL'] = False
4757816Ssteve.reinhardt@amd.com        else:
4767816Ssteve.reinhardt@amd.com            print "Compiling in", build_dir, "with MySQL support."
4777816Ssteve.reinhardt@amd.com            env.ParseConfig(mysql_config_libs)
4787756SAli.Saidi@ARM.com            env.ParseConfig(mysql_config_include)
4797756SAli.Saidi@ARM.com
4806654Snate@binkert.org    # Save sticky option settings back to current options file
4816654Snate@binkert.org    sticky_opts.Save(current_opts_file, env)
4825871Snate@binkert.org
4836121Snate@binkert.org    # Do this after we save setting back, or else we'll tack on an
4846121Snate@binkert.org    # extra 'qdo' every time we run scons.
4856121Snate@binkert.org    if env['BATCH']:
4868946Sandreas.hansson@arm.com        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4878737Skoansin.tan@gmail.com        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4883940Ssaidi@eecs.umich.edu
4893918Ssaidi@eecs.umich.edu    if env['USE_SSE2']:
4903918Ssaidi@eecs.umich.edu        env.Append(CCFLAGS='-msse2')
4911858SN/A
4926121Snate@binkert.org    # The src/SConscript file sets up the build rules in 'env' according
4937739Sgblack@eecs.umich.edu    # to the configured options.  It returns a list of environments,
4947739Sgblack@eecs.umich.edu    # one for each variant build (debug, opt, etc.)
4956143Snate@binkert.org    envList = SConscript('src/SConscript', build_dir = build_path,
4967618SAli.Saidi@arm.com                         exports = 'env')
4977618SAli.Saidi@arm.com
4987618SAli.Saidi@arm.com    # Set up the regression tests for each build.
4997618SAli.Saidi@arm.com    for e in envList:
5008614Sgblack@eecs.umich.edu        SConscript('tests/SConscript',
5017618SAli.Saidi@arm.com                   build_dir = os.path.join(build_path, 'test', e.Label),
5027618SAli.Saidi@arm.com                   exports = { 'env' : e }, duplicate = False)
5037618SAli.Saidi@arm.com
5047739Sgblack@eecs.umich.eduHelp(help_text)
5058946Sandreas.hansson@arm.com
5068946Sandreas.hansson@arm.com###################################################
5076121Snate@binkert.org#
5083940Ssaidi@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
5096121Snate@binkert.org# build environments to build the requested targets.
5107739Sgblack@eecs.umich.edu#
5117739Sgblack@eecs.umich.edu###################################################
5127739Sgblack@eecs.umich.edu
5137739Sgblack@eecs.umich.edu