SConstruct revision 3049:2f90320192d3
16019Shines@cs.fsu.edu# -*- mode:python -*-
26019Shines@cs.fsu.edu
37119Sgblack@eecs.umich.edu# Copyright (c) 2004-2005 The Regents of The University of Michigan
47119Sgblack@eecs.umich.edu# All rights reserved.
57119Sgblack@eecs.umich.edu#
67119Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
77119Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
87119Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
97119Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
107119Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
117119Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
127119Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
137119Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
147119Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
156019Shines@cs.fsu.edu# this software without specific prior written permission.
166019Shines@cs.fsu.edu#
176019Shines@cs.fsu.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186019Shines@cs.fsu.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196019Shines@cs.fsu.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206019Shines@cs.fsu.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216019Shines@cs.fsu.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226019Shines@cs.fsu.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236019Shines@cs.fsu.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246019Shines@cs.fsu.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256019Shines@cs.fsu.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266019Shines@cs.fsu.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276019Shines@cs.fsu.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286019Shines@cs.fsu.edu#
296019Shines@cs.fsu.edu# Authors: Steve Reinhardt
306019Shines@cs.fsu.edu
316019Shines@cs.fsu.edu###################################################
326019Shines@cs.fsu.edu#
336019Shines@cs.fsu.edu# SCons top-level build description (SConstruct) file.
346019Shines@cs.fsu.edu#
356019Shines@cs.fsu.edu# While in this directory ('m5'), just type 'scons' to build the default
366019Shines@cs.fsu.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
376019Shines@cs.fsu.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
386019Shines@cs.fsu.edu# the optimized full-system version).
396019Shines@cs.fsu.edu#
406019Shines@cs.fsu.edu# You can build M5 in a different directory as long as there is a
417129Sgblack@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path.  The build system
426019Shines@cs.fsu.edu# expects that all configs under the same build directory are being
437120Sgblack@eecs.umich.edu# built for the same host system.
447119Sgblack@eecs.umich.edu#
457119Sgblack@eecs.umich.edu# Examples:
467119Sgblack@eecs.umich.edu#
477119Sgblack@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
487119Sgblack@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
497129Sgblack@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
507129Sgblack@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
517129Sgblack@eecs.umich.edu#
526303Sgblack@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
536303Sgblack@eecs.umich.edu#   in a directory outside of the source tree.  The '-C' option tells
546303Sgblack@eecs.umich.edu#   scons to chdir to the specified directory to find this SConstruct
556303Sgblack@eecs.umich.edu#   file.
566303Sgblack@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
576303Sgblack@eecs.umich.edu#   % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug
586303Sgblack@eecs.umich.edu#
596303Sgblack@eecs.umich.edu# You can use 'scons -H' to print scons options.  If you're in this
606303Sgblack@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this
617119Sgblack@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
627129Sgblack@eecs.umich.edu# options as well.
637119Sgblack@eecs.umich.edu#
647119Sgblack@eecs.umich.edu###################################################
657119Sgblack@eecs.umich.edu
667119Sgblack@eecs.umich.edu# Python library imports
677119Sgblack@eecs.umich.eduimport sys
687119Sgblack@eecs.umich.eduimport os
697119Sgblack@eecs.umich.edu
707119Sgblack@eecs.umich.edu# Check for recent-enough Python and SCons versions.  If your system's
717119Sgblack@eecs.umich.edu# default installation of Python is not recent enough, you can use a
727119Sgblack@eecs.umich.edu# non-default installation of the Python interpreter by either (1)
737119Sgblack@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python'
747119Sgblack@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the
757119Sgblack@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
767120Sgblack@eecs.umich.eduEnsurePythonVersion(2,4)
777119Sgblack@eecs.umich.edu
787120Sgblack@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
797120Sgblack@eecs.umich.edu# 3-element version number.
807120Sgblack@eecs.umich.edumin_scons_version = (0,96,91)
817120Sgblack@eecs.umich.edutry:
827119Sgblack@eecs.umich.edu    EnsureSConsVersion(*min_scons_version)
837119Sgblack@eecs.umich.eduexcept:
847119Sgblack@eecs.umich.edu    print "Error checking current SCons version."
857119Sgblack@eecs.umich.edu    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
867120Sgblack@eecs.umich.edu    Exit(2)
877119Sgblack@eecs.umich.edu    
887120Sgblack@eecs.umich.edu
897120Sgblack@eecs.umich.edu# The absolute path to the current directory (where this file lives).
907120Sgblack@eecs.umich.eduROOT = Dir('.').abspath
917120Sgblack@eecs.umich.edu
927120Sgblack@eecs.umich.edu# Paths to the M5 and external source trees.
937119Sgblack@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'src')
947119Sgblack@eecs.umich.edu
957119Sgblack@eecs.umich.edu# tell python where to find m5 python code
967120Sgblack@eecs.umich.edusys.path.append(os.path.join(ROOT, 'src/python'))
977120Sgblack@eecs.umich.edu
987120Sgblack@eecs.umich.edu###################################################
997120Sgblack@eecs.umich.edu#
1007120Sgblack@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
1016303Sgblack@eecs.umich.edu# the target(s).
1026303Sgblack@eecs.umich.edu#
1036303Sgblack@eecs.umich.edu###################################################
1046303Sgblack@eecs.umich.edu
1056303Sgblack@eecs.umich.edu# Find default configuration & binary.
1066303Sgblack@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1076303Sgblack@eecs.umich.edu
1087129Sgblack@eecs.umich.edu# Ask SCons which directory it was invoked from.
1097129Sgblack@eecs.umich.edulaunch_dir = GetLaunchDir()
1107129Sgblack@eecs.umich.edu
1117129Sgblack@eecs.umich.edu# Make targets relative to invocation directory
1127129Sgblack@eecs.umich.eduabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1137129Sgblack@eecs.umich.edu                  BUILD_TARGETS)
1147129Sgblack@eecs.umich.edu
1157129Sgblack@eecs.umich.edu# helper function: find last occurrence of element in list
1167129Sgblack@eecs.umich.edudef rfind(l, elt, offs = -1):
1177129Sgblack@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1187129Sgblack@eecs.umich.edu        if l[i] == elt:
1197129Sgblack@eecs.umich.edu            return i
1207129Sgblack@eecs.umich.edu    raise ValueError, "element not found"
1217129Sgblack@eecs.umich.edu
1227129Sgblack@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1237129Sgblack@eecs.umich.edu# directory below this will determine the build parameters.  For
1247129Sgblack@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1257129Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1267129Sgblack@eecs.umich.edu# follow 'build' in the bulid path.
1277129Sgblack@eecs.umich.edu
1287129Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the
1297129Sgblack@eecs.umich.edu# collected targets reference.
1307129Sgblack@eecs.umich.edubuild_paths = []
1317129Sgblack@eecs.umich.edubuild_root = None
1327129Sgblack@eecs.umich.edufor t in abs_targets:
1337129Sgblack@eecs.umich.edu    path_dirs = t.split('/')
1347129Sgblack@eecs.umich.edu    try:
1357129Sgblack@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1367129Sgblack@eecs.umich.edu    except:
1377129Sgblack@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1387129Sgblack@eecs.umich.edu        Exit(1)
1396301Sgblack@eecs.umich.edu    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1407129Sgblack@eecs.umich.edu    if not build_root:
1417129Sgblack@eecs.umich.edu        build_root = this_build_root
1427129Sgblack@eecs.umich.edu    else:
1437129Sgblack@eecs.umich.edu        if this_build_root != build_root:
1447129Sgblack@eecs.umich.edu            print "Error: build targets not under same build root\n"\
1457129Sgblack@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
1467129Sgblack@eecs.umich.edu            Exit(1)
1477129Sgblack@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1487129Sgblack@eecs.umich.edu    if build_path not in build_paths:
1497129Sgblack@eecs.umich.edu        build_paths.append(build_path)
1507129Sgblack@eecs.umich.edu
1517129Sgblack@eecs.umich.edu###################################################
1527129Sgblack@eecs.umich.edu#
1537129Sgblack@eecs.umich.edu# Set up the default build environment.  This environment is copied
1547129Sgblack@eecs.umich.edu# and modified according to each selected configuration.
1557129Sgblack@eecs.umich.edu#
1567129Sgblack@eecs.umich.edu###################################################
1577129Sgblack@eecs.umich.edu
1587129Sgblack@eecs.umich.eduenv = Environment(ENV = os.environ,  # inherit user's environment vars
1597129Sgblack@eecs.umich.edu                  ROOT = ROOT,
1607129Sgblack@eecs.umich.edu                  SRCDIR = SRCDIR)
1617129Sgblack@eecs.umich.edu
1627129Sgblack@eecs.umich.eduenv.SConsignFile(os.path.join(build_root,"sconsign"))
1637129Sgblack@eecs.umich.edu
1647129Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up
1657129Sgblack@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
1667129Sgblack@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
1677129Sgblack@eecs.umich.edu# (soft) links work better.
1687129Sgblack@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy')
1697129Sgblack@eecs.umich.edu
1707129Sgblack@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but
1717129Sgblack@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take
1727129Sgblack@eecs.umich.edu# noticeably longer.
1737129Sgblack@eecs.umich.eduif False:
1747129Sgblack@eecs.umich.edu    env.TargetSignatures('content')
1757129Sgblack@eecs.umich.edu
1767129Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
1777129Sgblack@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1787129Sgblack@eecs.umich.edu
1797129Sgblack@eecs.umich.edu# Set up default C++ compiler flags
1807129Sgblack@eecs.umich.eduenv.Append(CCFLAGS='-pipe')
1817129Sgblack@eecs.umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing')
1827129Sgblack@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1837129Sgblack@eecs.umich.eduif sys.platform == 'cygwin':
1847129Sgblack@eecs.umich.edu    # cygwin has some header file issues...
1857129Sgblack@eecs.umich.edu    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1867129Sgblack@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')])
1877129Sgblack@eecs.umich.edu
1886301Sgblack@eecs.umich.edu# Find Python include and library directories for embedding the
1897129Sgblack@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
1907129Sgblack@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
1917129Sgblack@eecs.umich.edu# to link in an alternate version, see above for instructions on how
1926301Sgblack@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
1936301Sgblack@eecs.umich.edu
1946301Sgblack@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating
1957129Sgblack@eecs.umich.edu# include & library files
1967129Sgblack@eecs.umich.edupy_version_name = 'python' + sys.version[:3]
1977129Sgblack@eecs.umich.edu
1987129Sgblack@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4
1997129Sgblack@eecs.umich.eduenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
2007129Sgblack@eecs.umich.eduenv.Append(LIBS = py_version_name)
2017129Sgblack@eecs.umich.edu# add library path too if it's not in the default place
2027129Sgblack@eecs.umich.eduif sys.exec_prefix != '/usr':
2037129Sgblack@eecs.umich.edu    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
2046301Sgblack@eecs.umich.edu
2057129Sgblack@eecs.umich.edu# Set up SWIG flags & scanner
2067129Sgblack@eecs.umich.edu
2077129Sgblack@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2087129Sgblack@eecs.umich.edu
2097129Sgblack@eecs.umich.eduimport SCons.Scanner
2107129Sgblack@eecs.umich.edu
2117129Sgblack@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2127129Sgblack@eecs.umich.edu
2137129Sgblack@eecs.umich.eduswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2146301Sgblack@eecs.umich.edu                                        swig_inc_re)
2156301Sgblack@eecs.umich.edu
2167206Sgblack@eecs.umich.eduenv.Append(SCANNERS = swig_scanner)
2177206Sgblack@eecs.umich.edu
2187206Sgblack@eecs.umich.edu# Other default libraries
2197206Sgblack@eecs.umich.eduenv.Append(LIBS=['z'])
2207206Sgblack@eecs.umich.edu
2217206Sgblack@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
2227206Sgblack@eecs.umich.edu# builds under a given build root run on the same host platform.
2237206Sgblack@eecs.umich.educonf = Configure(env,
2247206Sgblack@eecs.umich.edu                 conf_dir = os.path.join(build_root, '.scons_config'),
2257206Sgblack@eecs.umich.edu                 log_file = os.path.join(build_root, 'scons_config.log'))
2267206Sgblack@eecs.umich.edu
2277206Sgblack@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
2287206Sgblack@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
2297206Sgblack@eecs.umich.eduif not have_fenv:
2307206Sgblack@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
2317206Sgblack@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
2327206Sgblack@eecs.umich.edu
2337206Sgblack@eecs.umich.edu# Check for mysql.
2347206Sgblack@eecs.umich.edumysql_config = WhereIs('mysql_config')
2357206Sgblack@eecs.umich.eduhave_mysql = mysql_config != None
2367206Sgblack@eecs.umich.edu
2377206Sgblack@eecs.umich.edu# Check MySQL version.
2387245Sgblack@eecs.umich.eduif have_mysql:
2397245Sgblack@eecs.umich.edu    mysql_version = os.popen(mysql_config + ' --version').read()
2407245Sgblack@eecs.umich.edu    mysql_version = mysql_version.split('.')
2417245Sgblack@eecs.umich.edu    mysql_major = int(mysql_version[0])
2427245Sgblack@eecs.umich.edu    mysql_minor = int(mysql_version[1])
2437245Sgblack@eecs.umich.edu    # This version check is probably overly conservative, but it deals
2447245Sgblack@eecs.umich.edu    # with the versions we have installed.
2457245Sgblack@eecs.umich.edu    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2467245Sgblack@eecs.umich.edu        print "Warning: MySQL v4.1 or newer required."
2477245Sgblack@eecs.umich.edu        have_mysql = False
2487245Sgblack@eecs.umich.edu
2497245Sgblack@eecs.umich.edu# Set up mysql_config commands.
2507245Sgblack@eecs.umich.eduif have_mysql:
2517245Sgblack@eecs.umich.edu    mysql_config_include = mysql_config + ' --include'
2527245Sgblack@eecs.umich.edu    if os.system(mysql_config_include + ' > /dev/null') != 0:
2537245Sgblack@eecs.umich.edu        # older mysql_config versions don't support --include, use
2547245Sgblack@eecs.umich.edu        # --cflags instead
2557245Sgblack@eecs.umich.edu        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2567245Sgblack@eecs.umich.edu    # This seems to work in all versions
2577245Sgblack@eecs.umich.edu    mysql_config_libs = mysql_config + ' --libs'
2587245Sgblack@eecs.umich.edu
2597245Sgblack@eecs.umich.eduenv = conf.Finish()
2607245Sgblack@eecs.umich.edu
2617245Sgblack@eecs.umich.edu# Define the universe of supported ISAs
2627245Sgblack@eecs.umich.eduenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2637245Sgblack@eecs.umich.edu
2647245Sgblack@eecs.umich.edu# Define the universe of supported CPU models
2657245Sgblack@eecs.umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2667245Sgblack@eecs.umich.edu                       'FullCPU', 'O3CPU',
2677245Sgblack@eecs.umich.edu                       'OzoneCPU']
2687245Sgblack@eecs.umich.edu
2697245Sgblack@eecs.umich.edu# Sticky options get saved in the options file so they persist from
2707245Sgblack@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new
2717245Sgblack@eecs.umich.edu# value becomes sticky).
2727245Sgblack@eecs.umich.edusticky_opts = Options(args=ARGUMENTS)
2737245Sgblack@eecs.umich.edusticky_opts.AddOptions(
2747245Sgblack@eecs.umich.edu    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2757245Sgblack@eecs.umich.edu    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2767245Sgblack@eecs.umich.edu    # There's a bug in scons 0.96.1 that causes ListOptions with list
2777245Sgblack@eecs.umich.edu    # values (more than one value) not to be able to be restored from
2787245Sgblack@eecs.umich.edu    # a saved option file.  If this causes trouble then upgrade to
2797245Sgblack@eecs.umich.edu    # scons 0.96.90 or later.
2807245Sgblack@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2817245Sgblack@eecs.umich.edu               env['ALL_CPU_LIST']),
2827245Sgblack@eecs.umich.edu    BoolOption('ALPHA_TLASER',
2837245Sgblack@eecs.umich.edu               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2847245Sgblack@eecs.umich.edu    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2857245Sgblack@eecs.umich.edu    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2867245Sgblack@eecs.umich.edu               False),
2877245Sgblack@eecs.umich.edu    BoolOption('SS_COMPATIBLE_FP',
2887245Sgblack@eecs.umich.edu               'Make floating-point results compatible with SimpleScalar',
2897245Sgblack@eecs.umich.edu               False),
2907245Sgblack@eecs.umich.edu    BoolOption('USE_SSE2',
2917245Sgblack@eecs.umich.edu               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2927121Sgblack@eecs.umich.edu               False),
2937121Sgblack@eecs.umich.edu    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2947121Sgblack@eecs.umich.edu    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2957121Sgblack@eecs.umich.edu    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
2967121Sgblack@eecs.umich.edu    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2977121Sgblack@eecs.umich.edu    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2987121Sgblack@eecs.umich.edu    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2997121Sgblack@eecs.umich.edu    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
3007121Sgblack@eecs.umich.edu    )
3017121Sgblack@eecs.umich.edu
3027121Sgblack@eecs.umich.edu# Non-sticky options only apply to the current build.
3037121Sgblack@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS)
3047121Sgblack@eecs.umich.edunonsticky_opts.AddOptions(
3057121Sgblack@eecs.umich.edu    BoolOption('update_ref', 'Update test reference outputs', False)
3067121Sgblack@eecs.umich.edu    )
3077121Sgblack@eecs.umich.edu
3087121Sgblack@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript).
3097121Sgblack@eecs.umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3107121Sgblack@eecs.umich.edu                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3117121Sgblack@eecs.umich.edu                     'USE_CHECKER']
3127121Sgblack@eecs.umich.edu
3137121Sgblack@eecs.umich.edu# Define a handy 'no-op' action
3147121Sgblack@eecs.umich.edudef no_action(target, source, env):
3157121Sgblack@eecs.umich.edu    return 0
3167121Sgblack@eecs.umich.edu
3177121Sgblack@eecs.umich.eduenv.NoAction = Action(no_action, None)
3187121Sgblack@eecs.umich.edu
3197121Sgblack@eecs.umich.edu###################################################
3207121Sgblack@eecs.umich.edu#
3217121Sgblack@eecs.umich.edu# Define a SCons builder for configuration flag headers.
3227121Sgblack@eecs.umich.edu#
3237121Sgblack@eecs.umich.edu###################################################
3247121Sgblack@eecs.umich.edu
3257121Sgblack@eecs.umich.edu# This function generates a config header file that #defines the
3267121Sgblack@eecs.umich.edu# option symbol to the current option setting (0 or 1).  The source
3277121Sgblack@eecs.umich.edu# operands are the name of the option and a Value node containing the
3287121Sgblack@eecs.umich.edu# value of the option.
3297121Sgblack@eecs.umich.edudef build_config_file(target, source, env):
3307121Sgblack@eecs.umich.edu    (option, value) = [s.get_contents() for s in source]
3317121Sgblack@eecs.umich.edu    f = file(str(target[0]), 'w')
3327121Sgblack@eecs.umich.edu    print >> f, '#define', option, value
3337121Sgblack@eecs.umich.edu    f.close()
3347121Sgblack@eecs.umich.edu    return None
3357121Sgblack@eecs.umich.edu
3367121Sgblack@eecs.umich.edu# Generate the message to be printed when building the config file.
3377121Sgblack@eecs.umich.edudef build_config_file_string(target, source, env):
3387121Sgblack@eecs.umich.edu    (option, value) = [s.get_contents() for s in source]
3397121Sgblack@eecs.umich.edu    return "Defining %s as %s in %s." % (option, value, target[0])
3407121Sgblack@eecs.umich.edu
3417121Sgblack@eecs.umich.edu# Combine the two functions into a scons Action object.
3427121Sgblack@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string)
3437121Sgblack@eecs.umich.edu
3447121Sgblack@eecs.umich.edu# The emitter munges the source & target node lists to reflect what
3457121Sgblack@eecs.umich.edu# we're really doing.
3467121Sgblack@eecs.umich.edudef config_emitter(target, source, env):
3477121Sgblack@eecs.umich.edu    # extract option name from Builder arg
3487121Sgblack@eecs.umich.edu    option = str(target[0])
3497121Sgblack@eecs.umich.edu    # True target is config header file
3507121Sgblack@eecs.umich.edu    target = os.path.join('config', option.lower() + '.hh')
3517121Sgblack@eecs.umich.edu    # Force value to 0/1 even if it's a Python bool
3527121Sgblack@eecs.umich.edu    val = int(eval(str(env[option])))
3537121Sgblack@eecs.umich.edu    # Sources are option name & value (packaged in SCons Value nodes)
3547121Sgblack@eecs.umich.edu    return ([target], [Value(option), Value(val)])
3557121Sgblack@eecs.umich.edu
3567121Sgblack@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action)
3577123Sgblack@eecs.umich.edu
3587123Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3597123Sgblack@eecs.umich.edu
3607123Sgblack@eecs.umich.edu###################################################
3617123Sgblack@eecs.umich.edu#
3627123Sgblack@eecs.umich.edu# Define a SCons builder for copying files.  This is used by the
3637123Sgblack@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here
3647123Sgblack@eecs.umich.edu# since it's potentially more generally applicable.
3657123Sgblack@eecs.umich.edu#
3667123Sgblack@eecs.umich.edu###################################################
3677123Sgblack@eecs.umich.edu
3687123Sgblack@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3697123Sgblack@eecs.umich.edu
3707123Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3717123Sgblack@eecs.umich.edu
3727123Sgblack@eecs.umich.edu###################################################
3737123Sgblack@eecs.umich.edu#
3747123Sgblack@eecs.umich.edu# Define a simple SCons builder to concatenate files.
3757123Sgblack@eecs.umich.edu#
3767123Sgblack@eecs.umich.edu# Used to append the Python zip archive to the executable.
3777123Sgblack@eecs.umich.edu#
3787123Sgblack@eecs.umich.edu###################################################
3797123Sgblack@eecs.umich.edu
3807123Sgblack@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3817123Sgblack@eecs.umich.edu                                          'chmod +x $TARGET']))
3827123Sgblack@eecs.umich.edu
3837123Sgblack@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder })
3847123Sgblack@eecs.umich.edu
3857123Sgblack@eecs.umich.edu
3867123Sgblack@eecs.umich.edu# base help text
3877123Sgblack@eecs.umich.eduhelp_text = '''
3887123Sgblack@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)]
3897123Sgblack@eecs.umich.edu
3907123Sgblack@eecs.umich.edu'''
3917123Sgblack@eecs.umich.edu
3927123Sgblack@eecs.umich.edu# libelf build is shared across all configs in the build root.
3937123Sgblack@eecs.umich.eduenv.SConscript('ext/libelf/SConscript',
3947123Sgblack@eecs.umich.edu               build_dir = os.path.join(build_root, 'libelf'),
3957123Sgblack@eecs.umich.edu               exports = 'env')
3967123Sgblack@eecs.umich.edu
3977123Sgblack@eecs.umich.edu###################################################
3987123Sgblack@eecs.umich.edu#
3997123Sgblack@eecs.umich.edu# Define build environments for selected configurations.
4007123Sgblack@eecs.umich.edu#
4017123Sgblack@eecs.umich.edu###################################################
4027123Sgblack@eecs.umich.edu
4037123Sgblack@eecs.umich.edu# rename base env
4047123Sgblack@eecs.umich.edubase_env = env
4057123Sgblack@eecs.umich.edu
4067123Sgblack@eecs.umich.edufor build_path in build_paths:
4077123Sgblack@eecs.umich.edu    print "Building in", build_path
4087123Sgblack@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
4097123Sgblack@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
4107123Sgblack@eecs.umich.edu    (build_root, build_dir) = os.path.split(build_path)
4117123Sgblack@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
4127123Sgblack@eecs.umich.edu    env = base_env.Copy()
4137123Sgblack@eecs.umich.edu
4147123Sgblack@eecs.umich.edu    # Set env options according to the build directory config.
4157123Sgblack@eecs.umich.edu    sticky_opts.files = []
4167123Sgblack@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
4177123Sgblack@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
4187123Sgblack@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
4197123Sgblack@eecs.umich.edu    current_opts_file = os.path.join(build_root, 'options', build_dir)
4207123Sgblack@eecs.umich.edu    if os.path.isfile(current_opts_file):
4217123Sgblack@eecs.umich.edu        sticky_opts.files.append(current_opts_file)
4227123Sgblack@eecs.umich.edu        print "Using saved options file %s" % current_opts_file
4237123Sgblack@eecs.umich.edu    else:
4247123Sgblack@eecs.umich.edu        # Build dir-specific options file doesn't exist.
4257123Sgblack@eecs.umich.edu
4267123Sgblack@eecs.umich.edu        # Make sure the directory is there so we can create it later
4277123Sgblack@eecs.umich.edu        opt_dir = os.path.dirname(current_opts_file)
4287123Sgblack@eecs.umich.edu        if not os.path.isdir(opt_dir):
4297123Sgblack@eecs.umich.edu            os.mkdir(opt_dir)
4307123Sgblack@eecs.umich.edu
4317123Sgblack@eecs.umich.edu        # Get default build options from source tree.  Options are
4327123Sgblack@eecs.umich.edu        # normally determined by name of $BUILD_DIR, but can be
4337123Sgblack@eecs.umich.edu        # overriden by 'default=' arg on command line.
4347123Sgblack@eecs.umich.edu        default_opts_file = os.path.join('build_opts',
4357123Sgblack@eecs.umich.edu                                         ARGUMENTS.get('default', build_dir))
4367123Sgblack@eecs.umich.edu        if os.path.isfile(default_opts_file):
4377123Sgblack@eecs.umich.edu            sticky_opts.files.append(default_opts_file)
4387123Sgblack@eecs.umich.edu            print "Options file %s not found,\n  using defaults in %s" \
4397123Sgblack@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4407123Sgblack@eecs.umich.edu        else:
4417123Sgblack@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
4427123Sgblack@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4437123Sgblack@eecs.umich.edu            Exit(1)
4447123Sgblack@eecs.umich.edu
4457123Sgblack@eecs.umich.edu    # Apply current option settings to env
4467123Sgblack@eecs.umich.edu    sticky_opts.Update(env)
4477124Sgblack@eecs.umich.edu    nonsticky_opts.Update(env)
4487124Sgblack@eecs.umich.edu
4497124Sgblack@eecs.umich.edu    help_text += "Sticky options for %s:\n" % build_dir \
4507124Sgblack@eecs.umich.edu                 + sticky_opts.GenerateHelpText(env) \
4517124Sgblack@eecs.umich.edu                 + "\nNon-sticky options for %s:\n" % build_dir \
4527124Sgblack@eecs.umich.edu                 + nonsticky_opts.GenerateHelpText(env)
4537124Sgblack@eecs.umich.edu
4547124Sgblack@eecs.umich.edu    # Process option settings.
4557124Sgblack@eecs.umich.edu
4567124Sgblack@eecs.umich.edu    if not have_fenv and env['USE_FENV']:
4577124Sgblack@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
4587124Sgblack@eecs.umich.edu              "forcing USE_FENV to False in", build_dir + "."
4597124Sgblack@eecs.umich.edu        env['USE_FENV'] = False
4607124Sgblack@eecs.umich.edu
4617124Sgblack@eecs.umich.edu    if not env['USE_FENV']:
4627124Sgblack@eecs.umich.edu        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4637124Sgblack@eecs.umich.edu        print "         FP results may deviate slightly from other platforms."
4647124Sgblack@eecs.umich.edu
4657124Sgblack@eecs.umich.edu    if env['EFENCE']:
4667124Sgblack@eecs.umich.edu        env.Append(LIBS=['efence'])
4677124Sgblack@eecs.umich.edu
4687124Sgblack@eecs.umich.edu    if env['USE_MYSQL']:
4697124Sgblack@eecs.umich.edu        if not have_mysql:
4707124Sgblack@eecs.umich.edu            print "Warning: MySQL not available; " \
4717124Sgblack@eecs.umich.edu                  "forcing USE_MYSQL to False in", build_dir + "."
4727124Sgblack@eecs.umich.edu            env['USE_MYSQL'] = False
4737124Sgblack@eecs.umich.edu        else:
4747124Sgblack@eecs.umich.edu            print "Compiling in", build_dir, "with MySQL support."
4757124Sgblack@eecs.umich.edu            env.ParseConfig(mysql_config_libs)
4767124Sgblack@eecs.umich.edu            env.ParseConfig(mysql_config_include)
4777124Sgblack@eecs.umich.edu
4787124Sgblack@eecs.umich.edu    # Save sticky option settings back to current options file
4797124Sgblack@eecs.umich.edu    sticky_opts.Save(current_opts_file, env)
4807124Sgblack@eecs.umich.edu
4817124Sgblack@eecs.umich.edu    # Do this after we save setting back, or else we'll tack on an
4827124Sgblack@eecs.umich.edu    # extra 'qdo' every time we run scons.
4837124Sgblack@eecs.umich.edu    if env['BATCH']:
4847124Sgblack@eecs.umich.edu        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4857124Sgblack@eecs.umich.edu        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4867124Sgblack@eecs.umich.edu
4877125Sgblack@eecs.umich.edu    if env['USE_SSE2']:
4887125Sgblack@eecs.umich.edu        env.Append(CCFLAGS='-msse2')
4897125Sgblack@eecs.umich.edu
4907125Sgblack@eecs.umich.edu    # The src/SConscript file sets up the build rules in 'env' according
4917125Sgblack@eecs.umich.edu    # to the configured options.  It returns a list of environments,
4927125Sgblack@eecs.umich.edu    # one for each variant build (debug, opt, etc.)
4937125Sgblack@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
4947125Sgblack@eecs.umich.edu                         exports = 'env')
4957125Sgblack@eecs.umich.edu
4967125Sgblack@eecs.umich.edu    # Set up the regression tests for each build.
4977125Sgblack@eecs.umich.edu    for e in envList:
4987125Sgblack@eecs.umich.edu        SConscript('tests/SConscript',
4997125Sgblack@eecs.umich.edu                   build_dir = os.path.join(build_path, 'tests', e.Label),
5007125Sgblack@eecs.umich.edu                   exports = { 'env' : e }, duplicate = False)
5017125Sgblack@eecs.umich.edu
5027125Sgblack@eecs.umich.eduHelp(help_text)
5037125Sgblack@eecs.umich.edu
5047125Sgblack@eecs.umich.edu###################################################
5057125Sgblack@eecs.umich.edu#
5067125Sgblack@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
5077125Sgblack@eecs.umich.edu# build environments to build the requested targets.
5087125Sgblack@eecs.umich.edu#
5097125Sgblack@eecs.umich.edu###################################################
5107125Sgblack@eecs.umich.edu
5117125Sgblack@eecs.umich.edu