SConstruct revision 2929
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
69955SN/A
702656Sstever@eecs.umich.edu# 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)
772653Sstever@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    
881852SN/A
89955SN/A# The absolute path to the current directory (where this file lives).
90955SN/AROOT = Dir('.').abspath
91955SN/A
922632Sstever@eecs.umich.edu# Paths to the M5 and external source trees.
932632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'src')
94955SN/A
951533SN/A# tell python where to find m5 python code
962632Sstever@eecs.umich.edusys.path.append(os.path.join(ROOT, 'src/python'))
971533SN/A
98955SN/A###################################################
99955SN/A#
1002632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of
1012632Sstever@eecs.umich.edu# the target(s).
102955SN/A#
103955SN/A###################################################
104955SN/A
105955SN/A# Find default configuration & binary.
1062632Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug'))
107955SN/A
1082632Sstever@eecs.umich.edu# Ask SCons which directory it was invoked from.
109955SN/Alaunch_dir = GetLaunchDir()
110955SN/A
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
1162632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1):
1172632Sstever@eecs.umich.edu    for i in range(len(l)+offs, 0, -1):
1182632Sstever@eecs.umich.edu        if l[i] == elt:
1192632Sstever@eecs.umich.edu            return i
1202632Sstever@eecs.umich.edu    raise ValueError, "element not found"
1212632Sstever@eecs.umich.edu
1222632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the
1232632Sstever@eecs.umich.edu# directory below this will determine the build parameters.  For
1242632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we
1252632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it
1262632Sstever@eecs.umich.edu# follow 'build' in the bulid path.
1272632Sstever@eecs.umich.edu
1282634Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the
1292634Sstever@eecs.umich.edu# collected targets reference.
1302632Sstever@eecs.umich.edubuild_paths = []
1312638Sstever@eecs.umich.edubuild_root = None
1322632Sstever@eecs.umich.edufor t in abs_targets:
1332632Sstever@eecs.umich.edu    path_dirs = t.split('/')
1342632Sstever@eecs.umich.edu    try:
1352632Sstever@eecs.umich.edu        build_top = rfind(path_dirs, 'build', -2)
1362632Sstever@eecs.umich.edu    except:
1372632Sstever@eecs.umich.edu        print "Error: no non-leaf 'build' dir found on target path", t
1381858SN/A        Exit(1)
1392638Sstever@eecs.umich.edu    this_build_root = os.path.join('/',*path_dirs[:build_top+1])
1402638Sstever@eecs.umich.edu    if not build_root:
1412638Sstever@eecs.umich.edu        build_root = this_build_root
1422638Sstever@eecs.umich.edu    else:
1432638Sstever@eecs.umich.edu        if this_build_root != build_root:
1442638Sstever@eecs.umich.edu            print "Error: build targets not under same build root\n"\
1452638Sstever@eecs.umich.edu                  "  %s\n  %s" % (build_root, this_build_root)
1462638Sstever@eecs.umich.edu            Exit(1)
1472634Sstever@eecs.umich.edu    build_path = os.path.join('/',*path_dirs[:build_top+2])
1482634Sstever@eecs.umich.edu    if build_path not in build_paths:
1492634Sstever@eecs.umich.edu        build_paths.append(build_path)
150955SN/A
151955SN/A###################################################
152955SN/A#
153955SN/A# Set up the default build environment.  This environment is copied
154955SN/A# and modified according to each selected configuration.
155955SN/A#
156955SN/A###################################################
157955SN/A
1581858SN/Aenv = Environment(ENV = os.environ,  # inherit user's environment vars
1591858SN/A                  ROOT = ROOT,
1602632Sstever@eecs.umich.edu                  SRCDIR = SRCDIR)
161955SN/A
1622776Sstever@eecs.umich.eduenv.SConsignFile(os.path.join(build_root,"sconsign"))
1631105SN/A
1642667Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up
1652667Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves
1662667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link.  Symbolic
1672667Sstever@eecs.umich.edu# (soft) links work better.
1682667Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy')
1692667Sstever@eecs.umich.edu
1701869SN/A# I waffle on this setting... it does avoid a few painful but
1711869SN/A# unnecessary builds, but it also seems to make trivial builds take
1721869SN/A# noticeably longer.
1731869SN/Aif False:
1741869SN/A    env.TargetSignatures('content')
1751065SN/A
1762632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package.
1772632Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') })
178955SN/A
1791858SN/A# Set up default C++ compiler flags
1801858SN/Aenv.Append(CCFLAGS='-pipe')
1811858SN/Aenv.Append(CCFLAGS='-fno-strict-aliasing')
1821858SN/Aenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1831851SN/Aif sys.platform == 'cygwin':
1841851SN/A    # cygwin has some header file issues...
1851858SN/A    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1862632Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')])
187955SN/A
1882656Sstever@eecs.umich.edu# Find Python include and library directories for embedding the
1892656Sstever@eecs.umich.edu# interpreter.  For consistency, we will use the same Python
1902656Sstever@eecs.umich.edu# installation used to run scons (and thus this script).  If you want
1912656Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how
1922656Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter.
1932656Sstever@eecs.umich.edu
1942656Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating
1952656Sstever@eecs.umich.edu# include & library files
1962656Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3]
1972656Sstever@eecs.umich.edu
1982656Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4
1992656Sstever@eecs.umich.eduenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name))
2002656Sstever@eecs.umich.eduenv.Append(LIBS = py_version_name)
2012656Sstever@eecs.umich.edu# add library path too if it's not in the default place
2022656Sstever@eecs.umich.eduif sys.exec_prefix != '/usr':
2032656Sstever@eecs.umich.edu    env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib'))
2042655Sstever@eecs.umich.edu
2052667Sstever@eecs.umich.edu# Set up SWIG flags & scanner
2062667Sstever@eecs.umich.edu
2072667Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS'))
2082667Sstever@eecs.umich.edu
2092667Sstever@eecs.umich.eduimport SCons.Scanner
2102667Sstever@eecs.umich.edu
2112667Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")'
2122667Sstever@eecs.umich.edu
2132667Sstever@eecs.umich.eduswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH",
2142667Sstever@eecs.umich.edu                                        swig_inc_re)
2152667Sstever@eecs.umich.edu
2162667Sstever@eecs.umich.eduenv.Append(SCANNERS = swig_scanner)
2172667Sstever@eecs.umich.edu
2182655Sstever@eecs.umich.edu# Other default libraries
2191858SN/Aenv.Append(LIBS=['z'])
2201858SN/A
2212638Sstever@eecs.umich.edu# Platform-specific configuration.  Note again that we assume that all
2222638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform.
2232638Sstever@eecs.umich.educonf = Configure(env,
2242638Sstever@eecs.umich.edu                 conf_dir = os.path.join(build_root, '.scons_config'),
2252638Sstever@eecs.umich.edu                 log_file = os.path.join(build_root, 'scons_config.log'))
2261858SN/A
2271858SN/A# Check for <fenv.h> (C99 FP environment control)
2281858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>')
2291858SN/Aif not have_fenv:
2301858SN/A    print "Warning: Header file <fenv.h> not found."
2311858SN/A    print "         This host has no IEEE FP rounding mode control."
2321858SN/A
2331859SN/A# Check for mysql.
2341858SN/Amysql_config = WhereIs('mysql_config')
2351858SN/Ahave_mysql = mysql_config != None
2361858SN/A
2371859SN/A# Check MySQL version.
2381859SN/Aif have_mysql:
2391862SN/A    mysql_version = os.popen(mysql_config + ' --version').read()
2401862SN/A    mysql_version = mysql_version.split('.')
2411862SN/A    mysql_major = int(mysql_version[0])
2421862SN/A    mysql_minor = int(mysql_version[1])
2431859SN/A    # This version check is probably overly conservative, but it deals
2441859SN/A    # with the versions we have installed.
2451963SN/A    if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1):
2461963SN/A        print "Warning: MySQL v4.1 or newer required."
2471859SN/A        have_mysql = False
2481859SN/A
2491859SN/A# Set up mysql_config commands.
2501859SN/Aif have_mysql:
2511859SN/A    mysql_config_include = mysql_config + ' --include'
2521859SN/A    if os.system(mysql_config_include + ' > /dev/null') != 0:
2531859SN/A        # older mysql_config versions don't support --include, use
2541859SN/A        # --cflags instead
2551862SN/A        mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g'
2561859SN/A    # This seems to work in all versions
2571859SN/A    mysql_config_libs = mysql_config + ' --libs'
2581859SN/A
2591858SN/Aenv = conf.Finish()
2601858SN/A
2612139SN/A# Define the universe of supported ISAs
2622139SN/Aenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips']
2632139SN/A
2642155SN/A# Define the universe of supported CPU models
2652623SN/Aenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU',
2662817Sksewell@umich.edu                       'FullCPU', 'O3CPU',
2672792Sktlim@umich.edu                       'OzoneCPU']
2682155SN/A
2691869SN/A# Sticky options get saved in the options file so they persist from
2701869SN/A# one invocation to the next (unless overridden, in which case the new
2711869SN/A# value becomes sticky).
2721869SN/Asticky_opts = Options(args=ARGUMENTS)
2731869SN/Asticky_opts.AddOptions(
2742139SN/A    EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']),
2751869SN/A    BoolOption('FULL_SYSTEM', 'Full-system support', False),
2762508SN/A    # There's a bug in scons 0.96.1 that causes ListOptions with list
2772508SN/A    # values (more than one value) not to be able to be restored from
2782508SN/A    # a saved option file.  If this causes trouble then upgrade to
2792508SN/A    # scons 0.96.90 or later.
2802635Sstever@eecs.umich.edu    ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU',
2812635Sstever@eecs.umich.edu               env['ALL_CPU_LIST']),
2821869SN/A    BoolOption('ALPHA_TLASER',
2831869SN/A               'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2841869SN/A    BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2851869SN/A    BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2861869SN/A               False),
2871869SN/A    BoolOption('SS_COMPATIBLE_FP',
2881869SN/A               'Make floating-point results compatible with SimpleScalar',
2891869SN/A               False),
2901965SN/A    BoolOption('USE_SSE2',
2911965SN/A               'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts',
2921965SN/A               False),
2931869SN/A    BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2941869SN/A    BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv),
2952733Sktlim@umich.edu    BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False),
2961869SN/A    ('CC', 'C compiler', os.environ.get('CC', env['CC'])),
2971884SN/A    ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])),
2981884SN/A    BoolOption('BATCH', 'Use batch pool for build and tests', False),
2991884SN/A    ('BATCH_CMD', 'Batch pool submission command name', 'qdo')
3001869SN/A    )
3011858SN/A
3021869SN/A# Non-sticky options only apply to the current build.
3031869SN/Anonsticky_opts = Options(args=ARGUMENTS)
3041869SN/Anonsticky_opts.AddOptions(
3051869SN/A    BoolOption('update_ref', 'Update test reference outputs', False)
3061869SN/A    )
3071858SN/A
3082761Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript).
3091869SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
3102733Sktlim@umich.edu                     'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
3112733Sktlim@umich.edu                     'USE_CHECKER']
3121869SN/A
3131869SN/A# Define a handy 'no-op' action
3141869SN/Adef no_action(target, source, env):
3151869SN/A    return 0
3161869SN/A
3171869SN/Aenv.NoAction = Action(no_action, None)
3181858SN/A
319955SN/A###################################################
320955SN/A#
3211869SN/A# Define a SCons builder for configuration flag headers.
3221869SN/A#
3231869SN/A###################################################
3241869SN/A
3251869SN/A# This function generates a config header file that #defines the
3261869SN/A# option symbol to the current option setting (0 or 1).  The source
3271869SN/A# operands are the name of the option and a Value node containing the
3281869SN/A# value of the option.
3291869SN/Adef build_config_file(target, source, env):
3301869SN/A    (option, value) = [s.get_contents() for s in source]
3311869SN/A    f = file(str(target[0]), 'w')
3321869SN/A    print >> f, '#define', option, value
3331869SN/A    f.close()
3341869SN/A    return None
3351869SN/A
3361869SN/A# Generate the message to be printed when building the config file.
3371869SN/Adef build_config_file_string(target, source, env):
3381869SN/A    (option, value) = [s.get_contents() for s in source]
3391869SN/A    return "Defining %s as %s in %s." % (option, value, target[0])
3401869SN/A
3411869SN/A# Combine the two functions into a scons Action object.
3421869SN/Aconfig_action = Action(build_config_file, build_config_file_string)
3431869SN/A
3441869SN/A# The emitter munges the source & target node lists to reflect what
3451869SN/A# we're really doing.
3461869SN/Adef config_emitter(target, source, env):
3471869SN/A    # extract option name from Builder arg
3481869SN/A    option = str(target[0])
3491869SN/A    # True target is config header file
3501869SN/A    target = os.path.join('config', option.lower() + '.hh')
3511869SN/A    # Force value to 0/1 even if it's a Python bool
3521869SN/A    val = int(eval(str(env[option])))
3531869SN/A    # Sources are option name & value (packaged in SCons Value nodes)
3541869SN/A    return ([target], [Value(option), Value(val)])
3551869SN/A
3561869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action)
3571869SN/A
3581869SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
3591869SN/A
3602655Sstever@eecs.umich.edu###################################################
3612655Sstever@eecs.umich.edu#
3622655Sstever@eecs.umich.edu# Define a SCons builder for copying files.  This is used by the
3632655Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here
3642655Sstever@eecs.umich.edu# since it's potentially more generally applicable.
3652655Sstever@eecs.umich.edu#
3662655Sstever@eecs.umich.edu###################################################
3672655Sstever@eecs.umich.edu
3682655Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE"))
3692655Sstever@eecs.umich.edu
3702655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder })
3712655Sstever@eecs.umich.edu
3722655Sstever@eecs.umich.edu###################################################
3732655Sstever@eecs.umich.edu#
3742655Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files.
3752655Sstever@eecs.umich.edu#
3762655Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable.
3772655Sstever@eecs.umich.edu#
3782655Sstever@eecs.umich.edu###################################################
3792655Sstever@eecs.umich.edu
3802655Sstever@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET',
3812655Sstever@eecs.umich.edu                                          'chmod +x $TARGET']))
3822655Sstever@eecs.umich.edu
3832655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder })
3842655Sstever@eecs.umich.edu
3852655Sstever@eecs.umich.edu
3862634Sstever@eecs.umich.edu# base help text
3872634Sstever@eecs.umich.eduhelp_text = '''
3882634Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)]
3892634Sstever@eecs.umich.edu
3902634Sstever@eecs.umich.edu'''
3912634Sstever@eecs.umich.edu
3922638Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root.
3932638Sstever@eecs.umich.eduenv.SConscript('ext/libelf/SConscript',
3942638Sstever@eecs.umich.edu               build_dir = os.path.join(build_root, 'libelf'),
3952638Sstever@eecs.umich.edu               exports = 'env')
3962638Sstever@eecs.umich.edu
3971869SN/A###################################################
3981869SN/A#
399955SN/A# Define build environments for selected configurations.
400955SN/A#
401955SN/A###################################################
402955SN/A
4031858SN/A# rename base env
4041858SN/Abase_env = env
4051858SN/A
4062632Sstever@eecs.umich.edufor build_path in build_paths:
4072632Sstever@eecs.umich.edu    print "Building in", build_path
4082632Sstever@eecs.umich.edu    # build_dir is the tail component of build path, and is used to
4092632Sstever@eecs.umich.edu    # determine the build parameters (e.g., 'ALPHA_SE')
4102632Sstever@eecs.umich.edu    (build_root, build_dir) = os.path.split(build_path)
4112634Sstever@eecs.umich.edu    # Make a copy of the build-root environment to use for this config.
4122638Sstever@eecs.umich.edu    env = base_env.Copy()
4132023SN/A
4142632Sstever@eecs.umich.edu    # Set env options according to the build directory config.
4152632Sstever@eecs.umich.edu    sticky_opts.files = []
4162632Sstever@eecs.umich.edu    # Options for $BUILD_ROOT/$BUILD_DIR are stored in
4172632Sstever@eecs.umich.edu    # $BUILD_ROOT/options/$BUILD_DIR so you can nuke
4182632Sstever@eecs.umich.edu    # $BUILD_ROOT/$BUILD_DIR without losing your options settings.
4192632Sstever@eecs.umich.edu    current_opts_file = os.path.join(build_root, 'options', build_dir)
4202632Sstever@eecs.umich.edu    if os.path.isfile(current_opts_file):
4212632Sstever@eecs.umich.edu        sticky_opts.files.append(current_opts_file)
4222632Sstever@eecs.umich.edu        print "Using saved options file %s" % current_opts_file
4232632Sstever@eecs.umich.edu    else:
4242632Sstever@eecs.umich.edu        # Build dir-specific options file doesn't exist.
4252023SN/A
4262632Sstever@eecs.umich.edu        # Make sure the directory is there so we can create it later
4272632Sstever@eecs.umich.edu        opt_dir = os.path.dirname(current_opts_file)
4281889SN/A        if not os.path.isdir(opt_dir):
4291889SN/A            os.mkdir(opt_dir)
4302632Sstever@eecs.umich.edu
4312632Sstever@eecs.umich.edu        # Get default build options from source tree.  Options are
4322632Sstever@eecs.umich.edu        # normally determined by name of $BUILD_DIR, but can be
4332632Sstever@eecs.umich.edu        # overriden by 'default=' arg on command line.
4342632Sstever@eecs.umich.edu        default_opts_file = os.path.join('build_opts',
4352632Sstever@eecs.umich.edu                                         ARGUMENTS.get('default', build_dir))
4362632Sstever@eecs.umich.edu        if os.path.isfile(default_opts_file):
4372632Sstever@eecs.umich.edu            sticky_opts.files.append(default_opts_file)
4382632Sstever@eecs.umich.edu            print "Options file %s not found,\n  using defaults in %s" \
4392632Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4402632Sstever@eecs.umich.edu        else:
4412632Sstever@eecs.umich.edu            print "Error: cannot find options file %s or %s" \
4422632Sstever@eecs.umich.edu                  % (current_opts_file, default_opts_file)
4432632Sstever@eecs.umich.edu            Exit(1)
4441888SN/A
4451888SN/A    # Apply current option settings to env
4461869SN/A    sticky_opts.Update(env)
4471869SN/A    nonsticky_opts.Update(env)
4481858SN/A
4492598SN/A    help_text += "Sticky options for %s:\n" % build_dir \
4502598SN/A                 + sticky_opts.GenerateHelpText(env) \
4512598SN/A                 + "\nNon-sticky options for %s:\n" % build_dir \
4522598SN/A                 + nonsticky_opts.GenerateHelpText(env)
4532598SN/A
4541858SN/A    # Process option settings.
4551858SN/A
4561858SN/A    if not have_fenv and env['USE_FENV']:
4571858SN/A        print "Warning: <fenv.h> not available; " \
4581858SN/A              "forcing USE_FENV to False in", build_dir + "."
4591858SN/A        env['USE_FENV'] = False
4601858SN/A
4611858SN/A    if not env['USE_FENV']:
4621858SN/A        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
4631871SN/A        print "         FP results may deviate slightly from other platforms."
4641858SN/A
4651858SN/A    if env['EFENCE']:
4661858SN/A        env.Append(LIBS=['efence'])
4671858SN/A
4681858SN/A    if env['USE_MYSQL']:
4691858SN/A        if not have_mysql:
4701858SN/A            print "Warning: MySQL not available; " \
4711858SN/A                  "forcing USE_MYSQL to False in", build_dir + "."
4721858SN/A            env['USE_MYSQL'] = False
4731858SN/A        else:
4741858SN/A            print "Compiling in", build_dir, "with MySQL support."
4751859SN/A            env.ParseConfig(mysql_config_libs)
4761859SN/A            env.ParseConfig(mysql_config_include)
4771869SN/A
4781888SN/A    # Save sticky option settings back to current options file
4792632Sstever@eecs.umich.edu    sticky_opts.Save(current_opts_file, env)
4801869SN/A
4811884SN/A    # Do this after we save setting back, or else we'll tack on an
4821884SN/A    # extra 'qdo' every time we run scons.
4831884SN/A    if env['BATCH']:
4841884SN/A        env['CC']  = env['BATCH_CMD'] + ' ' + env['CC']
4851884SN/A        env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX']
4861884SN/A
4871965SN/A    if env['USE_SSE2']:
4881965SN/A        env.Append(CCFLAGS='-msse2')
4891965SN/A
4902761Sstever@eecs.umich.edu    # The src/SConscript file sets up the build rules in 'env' according
4911869SN/A    # to the configured options.  It returns a list of environments,
4921869SN/A    # one for each variant build (debug, opt, etc.)
4932632Sstever@eecs.umich.edu    envList = SConscript('src/SConscript', build_dir = build_path,
4942667Sstever@eecs.umich.edu                         exports = 'env')
4951869SN/A
4961869SN/A    # Set up the regression tests for each build.
4972929Sktlim@umich.edu    for e in envList:
4982929Sktlim@umich.edu        SConscript('tests/SConscript',
4992929Sktlim@umich.edu                   build_dir = os.path.join(build_path, 'test', e.Label),
5002929Sktlim@umich.edu                   exports = { 'env' : e }, duplicate = False)
501955SN/A
5022598SN/AHelp(help_text)
5032598SN/A
504955SN/A###################################################
505955SN/A#
506955SN/A# Let SCons do its thing.  At this point SCons will use the defined
5071530SN/A# build environments to build the requested targets.
508955SN/A#
509955SN/A###################################################
510955SN/A
511