SConstruct revision 3053
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
4955SN/A# All rights reserved.
5955SN/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.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
30955SN/A
31955SN/A###################################################
32955SN/A#
33955SN/A# SCons top-level build description (SConstruct) file.
34955SN/A#
352632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default
362632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>'
372632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for
382632Sstever@eecs.umich.edu# the optimized full-system version).
39955SN/A#
402632Sstever@eecs.umich.edu# 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
422761Sstever@eecs.umich.edu# expects that all configs under the same build directory are being
432632Sstever@eecs.umich.edu# built for the same host system.
442632Sstever@eecs.umich.edu#
452632Sstever@eecs.umich.edu# Examples:
462761Sstever@eecs.umich.edu#
472761Sstever@eecs.umich.edu#   The following two commands are equivalent.  The '-u' option tells
482761Sstever@eecs.umich.edu#   scons to search up the directory tree for this SConstruct file.
492632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug
502632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug
512761Sstever@eecs.umich.edu#
522761Sstever@eecs.umich.edu#   The following two commands are equivalent and demonstrate building
532761Sstever@eecs.umich.edu#   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.
562632Sstever@eecs.umich.edu#   % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug
572632Sstever@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
612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build
622632Sstever@eecs.umich.edu# options as well.
63955SN/A#
64955SN/A###################################################
65955SN/A
66955SN/A# Python library imports
67955SN/Aimport sys
68955SN/Aimport os
693716Sstever@eecs.umich.edu
70955SN/A# Check for recent-enough Python and SCons versions.  If your system's
712656Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a
722656Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1)
732656Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python'
742656Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the
752656Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]".
762656Sstever@eecs.umich.eduEnsurePythonVersion(2,4)
772656Sstever@eecs.umich.edu
782653Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a
792653Sstever@eecs.umich.edu# 3-element version number.
802653Sstever@eecs.umich.edumin_scons_version = (0,96,91)
812653Sstever@eecs.umich.edutry:
822653Sstever@eecs.umich.edu    EnsureSConsVersion(*min_scons_version)
832653Sstever@eecs.umich.eduexcept:
842653Sstever@eecs.umich.edu    print "Error checking current SCons version."
852653Sstever@eecs.umich.edu    print "SCons", ".".join(map(str,min_scons_version)), "or greater required."
862653Sstever@eecs.umich.edu    Exit(2)
872653Sstever@eecs.umich.edu    
882653Sstever@eecs.umich.edu
891852SN/A# The absolute path to the current directory (where this file lives).
90955SN/AROOT = Dir('.').abspath
91955SN/A
92955SN/A# Paths to the M5 and external source trees.
933717Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'src')
943716Sstever@eecs.umich.edu
95955SN/A# tell python where to find m5 python code
961533SN/Asys.path.append(os.path.join(ROOT, 'src/python'))
973716Sstever@eecs.umich.edu
981533SN/A###################################################
99955SN/A#
100955SN/A# Figure out which configurations to set up based on the path(s) of
1012632Sstever@eecs.umich.edu# the target(s).
1022632Sstever@eecs.umich.edu#
103955SN/A###################################################
104955SN/A
105955SN/A# Find default configuration & binary.
106955SN/ADefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
1072632Sstever@eecs.umich.edu
108955SN/A# Ask SCons which directory it was invoked from.
1092632Sstever@eecs.umich.edulaunch_dir = GetLaunchDir()
1102632Sstever@eecs.umich.edu
1112632Sstever@eecs.umich.edu# Make targets relative to invocation directory
1122632Sstever@eecs.umich.eduabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))),
1132632Sstever@eecs.umich.edu                  BUILD_TARGETS)
1142632Sstever@eecs.umich.edu
1152632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list
1163053Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
1173053Sstever@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1183053Sstever@eecs.umich.edu        if l[i] == elt:
1193053Sstever@eecs.umich.edu            return i
1203053Sstever@eecs.umich.edu    raise ValueError, "element not found"
1213053Sstever@eecs.umich.edu
1223053Sstever@eecs.umich.edu# helper function: compare dotted version numbers.
1233053Sstever@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1')
1243053Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2
1253053Sstever@eecs.umich.edudef compare_versions(v1, v2):
1263053Sstever@eecs.umich.edu    # Convert dotted strings to lists
1273053Sstever@eecs.umich.edu    v1 = map(int, v1.split('.'))
1283053Sstever@eecs.umich.edu    v2 = map(int, v2.split('.'))
1293053Sstever@eecs.umich.edu    # Compare corresponding elements of lists
1303053Sstever@eecs.umich.edu    for n1,n2 in zip(v1, v2):
1313053Sstever@eecs.umich.edu        if n1 < n2: return -1
1322632Sstever@eecs.umich.edu        if n1 > n2: return  1
1332632Sstever@eecs.umich.edu    # all corresponding values are equal... see if one has extra values
1342632Sstever@eecs.umich.edu    if len(v1) < len(v2): return -1
1352632Sstever@eecs.umich.edu    if len(v1) > len(v2): return  1
1362632Sstever@eecs.umich.edu    return 0
1372632Sstever@eecs.umich.edu
1383718Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1393718Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
1403718Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1413718Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1423718Sstever@eecs.umich.edu# follow 'build' in the bulid path.
1433718Sstever@eecs.umich.edu
1443718Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the
1453718Sstever@eecs.umich.edu# collected targets reference.
1463718Sstever@eecs.umich.edubuild_paths = []
1473718Sstever@eecs.umich.edubuild_root = None
1483718Sstever@eecs.umich.edufor t in abs_targets:
1493718Sstever@eecs.umich.edu    path_dirs = t.split('/')
1503718Sstever@eecs.umich.edu    try:
1512634Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1522634Sstever@eecs.umich.edu    except:
1532632Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1542638Sstever@eecs.umich.edu        Exit(1)
1552632Sstever@eecs.umich.edu    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1562632Sstever@eecs.umich.edu    if not build_root:
1572632Sstever@eecs.umich.edu        build_root = this_build_root
1582632Sstever@eecs.umich.edu    else:
1592632Sstever@eecs.umich.edu        if this_build_root != build_root:
1602632Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
1611858SN/A                  "  %s\n  %s" % (build_root, this_build_root)
1623716Sstever@eecs.umich.edu            Exit(1)
1632638Sstever@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1642638Sstever@eecs.umich.edu    if build_path not in build_paths:
1652638Sstever@eecs.umich.edu        build_paths.append(build_path)
1662638Sstever@eecs.umich.edu
1672638Sstever@eecs.umich.edu###################################################
1682638Sstever@eecs.umich.edu#
1692638Sstever@eecs.umich.edu# Set up the default build environment.  This environment is copied
1703716Sstever@eecs.umich.edu# and modified according to each selected configuration.
1712634Sstever@eecs.umich.edu#
1722634Sstever@eecs.umich.edu###################################################
173955SN/A
174955SN/Aenv = Environment(ENV = os.environ,  # inherit user's environment vars
175955SN/A                  ROOT = ROOT,
176955SN/A                  SRCDIR = SRCDIR)
177955SN/A
178955SN/Aenv.SConsignFile(os.path.join(build_root,"sconsign"))
179955SN/A
180955SN/A# Default duplicate option is to use hard links, but this messes up
1811858SN/A# when you use emacs to edit a file in the target dir, as emacs moves
1821858SN/A# file to file~ then copies to file, breaking the link.  Symbolic
1832632Sstever@eecs.umich.edu# (soft) links work better.
184955SN/Aenv.SetOption('duplicate', 'soft-copy')
1853643Ssaidi@eecs.umich.edu
1863643Ssaidi@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but
1873643Ssaidi@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take
1883643Ssaidi@eecs.umich.edu# noticeably longer.
1893643Ssaidi@eecs.umich.eduif False:
1903643Ssaidi@eecs.umich.edu    env.TargetSignatures('content')
1913643Ssaidi@eecs.umich.edu
1923643Ssaidi@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
1933716Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
1941105SN/A
1952667Sstever@eecs.umich.edu# Set up default C++ compiler flags
1962667Sstever@eecs.umich.eduenv.Append(CCFLAGS='-pipe')
1972667Sstever@eecs.umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing')
1982667Sstever@eecs.umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1992667Sstever@eecs.umich.eduif sys.platform == 'cygwin':
2002667Sstever@eecs.umich.edu    # cygwin has some header file issues...
2011869SN/A    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
2021869SN/Aenv.Append(CPPPATH=[Dir('ext/dnet')])
2031869SN/A
2041869SN/A# Find Python include and library directories for embedding the
2051869SN/A# interpreter.  For consistency, we will use the same Python
2061065SN/A# installation used to run scons (and thus this script).  If you want
2072632Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
2082632Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
209955SN/A
2101858SN/A# Get brief Python version name (e.g., "python2.4") for locating
2111858SN/A# include & library files
2121858SN/Apy_version_name = 'python' + sys.version[:3]
2131858SN/A
2141851SN/A# include path, e.g. /usr/local/include/python2.4
2151851SN/Aenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
2161858SN/Aenv.Append(LIBS = py_version_name)
2172632Sstever@eecs.umich.edu# add library path too if it's not in the default place
218955SN/Aif sys.exec_prefix != '/usr':
2193053Sstever@eecs.umich.edu    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
2203053Sstever@eecs.umich.edu
2213053Sstever@eecs.umich.edu# Check for SWIG
2223053Sstever@eecs.umich.eduif not env.has_key('SWIG'):
2233053Sstever@eecs.umich.edu    print 'Error: SWIG utility not found.'
2243053Sstever@eecs.umich.edu    print '       Please install (see http://www.swig.org) and retry.'
2253053Sstever@eecs.umich.edu    Exit(1)
2263053Sstever@eecs.umich.edu
2273053Sstever@eecs.umich.edu# Check for appropriate SWIG version
2283053Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split()
2293053Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z"
2303053Sstever@eecs.umich.eduif swig_version[0] != 'SWIG' or swig_version[1] != 'Version':
2313053Sstever@eecs.umich.edu    print 'Error determining SWIG version.'
2323053Sstever@eecs.umich.edu    Exit(1)
2333053Sstever@eecs.umich.edu
2343053Sstever@eecs.umich.edumin_swig_version = '1.3.28'
2353053Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0:
2363053Sstever@eecs.umich.edu    print 'Error: SWIG version', min_swig_version, 'or newer required.'
2373053Sstever@eecs.umich.edu    print '       Installed version:', swig_version[2]
2382667Sstever@eecs.umich.edu    Exit(1)
2392667Sstever@eecs.umich.edu
2402667Sstever@eecs.umich.edu# Set up SWIG flags & scanner
2412667Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2422667Sstever@eecs.umich.edu
2432667Sstever@eecs.umich.eduimport SCons.Scanner
2442667Sstever@eecs.umich.edu
2452667Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2462667Sstever@eecs.umich.edu
2472667Sstever@eecs.umich.eduswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2482667Sstever@eecs.umich.edu                                        swig_inc_re)
2492667Sstever@eecs.umich.edu
2502638Sstever@eecs.umich.eduenv.Append(SCANNERS = swig_scanner)
2512638Sstever@eecs.umich.edu
2522638Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
2533716Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
2543716Sstever@eecs.umich.educonf = Configure(env,
2551858SN/A                 conf_dir = os.path.join(build_root, '.scons_config'),
2563118Sstever@eecs.umich.edu                 log_file = os.path.join(build_root, 'scons_config.log'))
2573118Sstever@eecs.umich.edu
2583118Sstever@eecs.umich.edu# Check for zlib.  If the check passes, libz will be automatically
2593118Sstever@eecs.umich.edu# added to the LIBS environment variable.
2603118Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'):
2613118Sstever@eecs.umich.edu    print 'Error: did not find needed zlib compression library '\
2623118Sstever@eecs.umich.edu          'and/or zlib.h header file.'
2633118Sstever@eecs.umich.edu    print '       Please install zlib and try again.'
2643118Sstever@eecs.umich.edu    Exit(1)
2653118Sstever@eecs.umich.edu
2663118Sstever@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control)
2673716Sstever@eecs.umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>')
2683118Sstever@eecs.umich.eduif not have_fenv:
2693118Sstever@eecs.umich.edu    print "Warning: Header file <fenv.h> not found."
2703118Sstever@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
2713118Sstever@eecs.umich.edu
2723118Sstever@eecs.umich.edu# Check for mysql.
2733118Sstever@eecs.umich.edumysql_config = WhereIs('mysql_config')
2743118Sstever@eecs.umich.eduhave_mysql = mysql_config != None
2753118Sstever@eecs.umich.edu
2763118Sstever@eecs.umich.edu# Check MySQL version.
2773716Sstever@eecs.umich.eduif have_mysql:
2783118Sstever@eecs.umich.edu    mysql_version = os.popen(mysql_config + ' --version').read()
2793118Sstever@eecs.umich.edu    min_mysql_version = '4.1'
2803118Sstever@eecs.umich.edu    if compare_versions(mysql_version, min_mysql_version) < 0:
2813118Sstever@eecs.umich.edu        print 'Warning: MySQL', min_mysql_version, 'or newer required.'
2823118Sstever@eecs.umich.edu        print '         Version', mysql_version, 'detected.'
2833118Sstever@eecs.umich.edu        have_mysql = False
2843118Sstever@eecs.umich.edu
2853118Sstever@eecs.umich.edu# Set up mysql_config commands.
2863118Sstever@eecs.umich.eduif have_mysql:
2873118Sstever@eecs.umich.edu    mysql_config_include = mysql_config + ' --include'
2883483Ssaidi@eecs.umich.edu    if os.system(mysql_config_include + ' > /dev/null') != 0:
2893494Ssaidi@eecs.umich.edu        # older mysql_config versions don't support --include, use
2903494Ssaidi@eecs.umich.edu        # --cflags instead
2913483Ssaidi@eecs.umich.edu        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2923483Ssaidi@eecs.umich.edu    # This seems to work in all versions
2933483Ssaidi@eecs.umich.edu    mysql_config_libs = mysql_config + ' --libs'
2943053Sstever@eecs.umich.edu
2953053Sstever@eecs.umich.eduenv = conf.Finish()
2963053Sstever@eecs.umich.edu
2973053Sstever@eecs.umich.edu# Define the universe of supported ISAs
2983053Sstever@eecs.umich.eduenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2993053Sstever@eecs.umich.edu
3003053Sstever@eecs.umich.edu# Define the universe of supported CPU models
3013053Sstever@eecs.umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
3021858SN/A                       'FullCPU', 'O3CPU',
3031858SN/A                       'OzoneCPU']
3041858SN/A
3051858SN/A# Sticky options get saved in the options file so they persist from
3061858SN/A# one invocation to the next (unless overridden, in which case the new
3071858SN/A# value becomes sticky).
3081859SN/Asticky_opts = Options(args=ARGUMENTS)
3091858SN/Asticky_opts.AddOptions(
3101858SN/A    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
3111858SN/A    BoolOption('FULL_SYSTEM', 'Full-system support', False),
3121859SN/A    # There's a bug in scons 0.96.1 that causes ListOptions with list
3131859SN/A    # values (more than one value) not to be able to be restored from
3141862SN/A    # a saved option file.  If this causes trouble then upgrade to
3153053Sstever@eecs.umich.edu    # scons 0.96.90 or later.
3163053Sstever@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
3173053Sstever@eecs.umich.edu               env['ALL_CPU_LIST']),
3183053Sstever@eecs.umich.edu    BoolOption('ALPHA_TLASER',
3191859SN/A               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
3201859SN/A    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
3211859SN/A    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
3221859SN/A               False),
3231859SN/A    BoolOption('SS_COMPATIBLE_FP',
3241859SN/A               'Make floating-point results compatible with SimpleScalar',
3251859SN/A               False),
3261859SN/A    BoolOption('USE_SSE2',
3271862SN/A               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
3281859SN/A               False),
3291859SN/A    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
3301859SN/A    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
3311858SN/A    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
3321858SN/A    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
3332139SN/A    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
3342139SN/A    BoolOption('BATCH', 'Use batch pool for build and tests', False),
3352139SN/A    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
3362155SN/A    )
3372623SN/A
3383583Sbinkertn@umich.edu# Non-sticky options only apply to the current build.
3393583Sbinkertn@umich.edunonsticky_opts = Options(args=ARGUMENTS)
3403717Sstever@eecs.umich.edunonsticky_opts.AddOptions(
3413583Sbinkertn@umich.edu    BoolOption('update_ref', 'Update test reference outputs', False)
3422155SN/A    )
3431869SN/A
3441869SN/A# These options get exported to #defines in config/*.hh (see src/SConscript).
3451869SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3461869SN/A                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3471869SN/A                     'USE_CHECKER']
3482139SN/A
3491869SN/A# Define a handy 'no-op' action
3502508SN/Adef no_action(target, source, env):
3512508SN/A    return 0
3522508SN/A
3532508SN/Aenv.NoAction = Action(no_action, None)
3543685Sktlim@umich.edu
3552635Sstever@eecs.umich.edu###################################################
3561869SN/A#
3571869SN/A# Define a SCons builder for configuration flag headers.
3581869SN/A#
3591869SN/A###################################################
3601869SN/A
3611869SN/A# This function generates a config header file that #defines the
3621869SN/A# option symbol to the current option setting (0 or 1).  The source
3631869SN/A# operands are the name of the option and a Value node containing the
3641965SN/A# value of the option.
3651965SN/Adef build_config_file(target, source, env):
3661965SN/A    (option, value) = [s.get_contents() for s in source]
3671869SN/A    f = file(str(target[0]), 'w')
3681869SN/A    print >> f, '#define', option, value
3692733Sktlim@umich.edu    f.close()
3701869SN/A    return None
3711884SN/A
3721884SN/A# Generate the message to be printed when building the config file.
3733356Sbinkertn@umich.edudef build_config_file_string(target, source, env):
3743356Sbinkertn@umich.edu    (option, value) = [s.get_contents() for s in source]
3753356Sbinkertn@umich.edu    return "Defining %s as %s in %s." % (option, value, target[0])
3763356Sbinkertn@umich.edu
3771869SN/A# Combine the two functions into a scons Action object.
3781858SN/Aconfig_action = Action(build_config_file, build_config_file_string)
3791869SN/A
3801869SN/A# The emitter munges the source & target node lists to reflect what
3811869SN/A# we're really doing.
3821869SN/Adef config_emitter(target, source, env):
3831869SN/A    # extract option name from Builder arg
3841858SN/A    option = str(target[0])
3852761Sstever@eecs.umich.edu    # True target is config header file
3861869SN/A    target = os.path.join('config', option.lower() + '.hh')
3872733Sktlim@umich.edu    # Force value to 0/1 even if it's a Python bool
3883584Ssaidi@eecs.umich.edu    val = int(eval(str(env[option])))
3891869SN/A    # Sources are option name & value (packaged in SCons Value nodes)
3901869SN/A    return ([target], [Value(option), Value(val)])
3911869SN/A
3921869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
3931869SN/A
3941869SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3951858SN/A
396955SN/A###################################################
397955SN/A#
3981869SN/A# Define a SCons builder for copying files.  This is used by the
3991869SN/A# Python zipfile code in src/python/SConscript, but is placed up here
4001869SN/A# since it's potentially more generally applicable.
4011869SN/A#
4021869SN/A###################################################
4031869SN/A
4041869SN/Acopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
4051869SN/A
4061869SN/Aenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
4071869SN/A
4081869SN/A###################################################
4091869SN/A#
4101869SN/A# Define a simple SCons builder to concatenate files.
4111869SN/A#
4121869SN/A# Used to append the Python zip archive to the executable.
4131869SN/A#
4141869SN/A###################################################
4151869SN/A
4161869SN/Aconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
4171869SN/A                                          'chmod +x $TARGET']))
4181869SN/A
4191869SN/Aenv.Append(BUILDERS = { 'Concat' : concat_builder })
4201869SN/A
4211869SN/A
4221869SN/A# base help text
4231869SN/Ahelp_text = '''
4241869SN/AUsage: scons [scons options] [build options] [target(s)]
4251869SN/A
4261869SN/A'''
4273716Sstever@eecs.umich.edu
4283356Sbinkertn@umich.edu# libelf build is shared across all configs in the build root.
4293356Sbinkertn@umich.eduenv.SConscript('ext/libelf/SConscript',
4303356Sbinkertn@umich.edu               build_dir = os.path.join(build_root, 'libelf'),
4313356Sbinkertn@umich.edu               exports = 'env')
4323356Sbinkertn@umich.edu
4333356Sbinkertn@umich.edu###################################################
4343356Sbinkertn@umich.edu#
4351869SN/A# Define build environments for selected configurations.
4361869SN/A#
4371869SN/A###################################################
4381869SN/A
4391869SN/A# rename base env
4401869SN/Abase_env = env
4411869SN/A
4422655Sstever@eecs.umich.edufor build_path in build_paths:
4432655Sstever@eecs.umich.edu    print "Building in", build_path
4442655Sstever@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
4452655Sstever@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
4462655Sstever@eecs.umich.edu    (build_root, build_dir) = os.path.split(build_path)
4472655Sstever@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
4482655Sstever@eecs.umich.edu    env = base_env.Copy()
4492655Sstever@eecs.umich.edu
4502655Sstever@eecs.umich.edu    # Set env options according to the build directory config.
4512655Sstever@eecs.umich.edu    sticky_opts.files = []
4522655Sstever@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
4532655Sstever@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
4542655Sstever@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
4552655Sstever@eecs.umich.edu    current_opts_file = os.path.join(build_root, 'options', build_dir)
4562655Sstever@eecs.umich.edu    if os.path.isfile(current_opts_file):
4572655Sstever@eecs.umich.edu        sticky_opts.files.append(current_opts_file)
4582655Sstever@eecs.umich.edu        print "Using saved options file %s" % current_opts_file
4592655Sstever@eecs.umich.edu    else:
4602655Sstever@eecs.umich.edu        # Build dir-specific options file doesn't exist.
4612655Sstever@eecs.umich.edu
4622655Sstever@eecs.umich.edu        # Make sure the directory is there so we can create it later
4632655Sstever@eecs.umich.edu        opt_dir = os.path.dirname(current_opts_file)
4642655Sstever@eecs.umich.edu        if not os.path.isdir(opt_dir):
4652655Sstever@eecs.umich.edu            os.mkdir(opt_dir)
4662655Sstever@eecs.umich.edu
4672655Sstever@eecs.umich.edu        # Get default build options from source tree.  Options are
4682634Sstever@eecs.umich.edu        # normally determined by name of $BUILD_DIR, but can be
4692634Sstever@eecs.umich.edu        # overriden by 'default=' arg on command line.
4702634Sstever@eecs.umich.edu        default_opts_file = os.path.join('build_opts',
4712634Sstever@eecs.umich.edu                                         ARGUMENTS.get('default', build_dir))
4722634Sstever@eecs.umich.edu        if os.path.isfile(default_opts_file):
4732634Sstever@eecs.umich.edu            sticky_opts.files.append(default_opts_file)
4742638Sstever@eecs.umich.edu            print "Options file %s not found,\n  using defaults in %s" \
4752638Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4763716Sstever@eecs.umich.edu        else:
4772638Sstever@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
4782638Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4791869SN/A            Exit(1)
4801869SN/A
4813546Sgblack@eecs.umich.edu    # Apply current option settings to env
4823546Sgblack@eecs.umich.edu    sticky_opts.Update(env)
4833546Sgblack@eecs.umich.edu    nonsticky_opts.Update(env)
4843546Sgblack@eecs.umich.edu
4853546Sgblack@eecs.umich.edu    help_text += "Sticky options for %s:\n" % build_dir \
4863546Sgblack@eecs.umich.edu                 + sticky_opts.GenerateHelpText(env) \
4873546Sgblack@eecs.umich.edu                 + "\nNon-sticky options for %s:\n" % build_dir \
4883546Sgblack@eecs.umich.edu                 + nonsticky_opts.GenerateHelpText(env)
4893546Sgblack@eecs.umich.edu
4903546Sgblack@eecs.umich.edu    # Process option settings.
4913546Sgblack@eecs.umich.edu
4923546Sgblack@eecs.umich.edu    if not have_fenv and env['USE_FENV']:
4933546Sgblack@eecs.umich.edu        print "Warning: <fenv.h> not available; " \
4943546Sgblack@eecs.umich.edu              "forcing USE_FENV to False in", build_dir + "."
4953546Sgblack@eecs.umich.edu        env['USE_FENV'] = False
4963546Sgblack@eecs.umich.edu
4973546Sgblack@eecs.umich.edu    if not env['USE_FENV']:
4983546Sgblack@eecs.umich.edu        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4993546Sgblack@eecs.umich.edu        print "         FP results may deviate slightly from other platforms."
5003546Sgblack@eecs.umich.edu
5013546Sgblack@eecs.umich.edu    if env['EFENCE']:
5023546Sgblack@eecs.umich.edu        env.Append(LIBS=['efence'])
5033546Sgblack@eecs.umich.edu
5043546Sgblack@eecs.umich.edu    if env['USE_MYSQL']:
5053546Sgblack@eecs.umich.edu        if not have_mysql:
5063546Sgblack@eecs.umich.edu            print "Warning: MySQL not available; " \
5073546Sgblack@eecs.umich.edu                  "forcing USE_MYSQL to False in", build_dir + "."
5083546Sgblack@eecs.umich.edu            env['USE_MYSQL'] = False
5093546Sgblack@eecs.umich.edu        else:
5103546Sgblack@eecs.umich.edu            print "Compiling in", build_dir, "with MySQL support."
5113546Sgblack@eecs.umich.edu            env.ParseConfig(mysql_config_libs)
5123546Sgblack@eecs.umich.edu            env.ParseConfig(mysql_config_include)
5133546Sgblack@eecs.umich.edu
5143546Sgblack@eecs.umich.edu    # Save sticky option settings back to current options file
5153546Sgblack@eecs.umich.edu    sticky_opts.Save(current_opts_file, env)
5163546Sgblack@eecs.umich.edu
5173546Sgblack@eecs.umich.edu    # Do this after we save setting back, or else we'll tack on an
5183546Sgblack@eecs.umich.edu    # extra 'qdo' every time we run scons.
5193546Sgblack@eecs.umich.edu    if env['BATCH']:
5203546Sgblack@eecs.umich.edu        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
521955SN/A        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
522955SN/A
523955SN/A    if env['USE_SSE2']:
524955SN/A        env.Append(CCFLAGS='-msse2')
5251858SN/A
5261858SN/A    # The src/SConscript file sets up the build rules in 'env' according
5271858SN/A    # to the configured options.  It returns a list of environments,
5282632Sstever@eecs.umich.edu    # one for each variant build (debug, opt, etc.)
5292632Sstever@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
5302632Sstever@eecs.umich.edu                         exports = 'env')
5312632Sstever@eecs.umich.edu
5322632Sstever@eecs.umich.edu    # Set up the regression tests for each build.
5332634Sstever@eecs.umich.edu    for e in envList:
5342638Sstever@eecs.umich.edu        SConscript('tests/SConscript',
5352023SN/A                   build_dir = os.path.join(build_path, 'tests', e.Label),
5362632Sstever@eecs.umich.edu                   exports = { 'env' : e }, duplicate = False)
5372632Sstever@eecs.umich.edu
5382632Sstever@eecs.umich.eduHelp(help_text)
5392632Sstever@eecs.umich.edu
5402632Sstever@eecs.umich.edu###################################################
5413716Sstever@eecs.umich.edu#
5422632Sstever@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
5432632Sstever@eecs.umich.edu# build environments to build the requested targets.
5442632Sstever@eecs.umich.edu#
5452632Sstever@eecs.umich.edu###################################################
5462632Sstever@eecs.umich.edu
5472023SN/A