SConstruct revision 1859
1955SN/A# -*- mode:python -*-
2955SN/A
37816Ssteve.reinhardt@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
45871Snate@binkert.org# All rights reserved.
51762SN/A#
6955SN/A# Redistribution and use in source and binary forms, with or without
7955SN/A# modification, are permitted provided that the following conditions are
8955SN/A# met: redistributions of source code must retain the above copyright
9955SN/A# notice, this list of conditions and the following disclaimer;
10955SN/A# redistributions in binary form must reproduce the above copyright
11955SN/A# notice, this list of conditions and the following disclaimer in the
12955SN/A# documentation and/or other materials provided with the distribution;
13955SN/A# neither the name of the copyright holders nor the names of its
14955SN/A# contributors may be used to endorse or promote products derived from
15955SN/A# this software without specific prior written permission.
16955SN/A#
17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28955SN/A
29955SN/A###################################################
302665Ssaidi@eecs.umich.edu#
312665Ssaidi@eecs.umich.edu# SCons top-level build description (SConstruct) file.
325863Snate@binkert.org#
33955SN/A# To build M5, you need a directory with three things:
34955SN/A# 1. A copy of this file (named SConstruct).
35955SN/A# 2. A link named 'm5' to the top of the M5 simulator source tree.
36955SN/A# 3. A link named 'ext' to the top of the M5 external source tree.
37955SN/A#
388878Ssteve.reinhardt@amd.com# Then type 'scons' to build the default configuration (see below), or
392632Sstever@eecs.umich.edu# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
408878Ssteve.reinhardt@amd.com# 'ALPHA_FS/m5.opt' for the optimized full-system version).
412632Sstever@eecs.umich.edu#
42955SN/A###################################################
438878Ssteve.reinhardt@amd.com
442632Sstever@eecs.umich.edu# Python library imports
452761Sstever@eecs.umich.eduimport sys
462632Sstever@eecs.umich.eduimport os
472632Sstever@eecs.umich.edu
482632Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions
492761Sstever@eecs.umich.eduEnsurePythonVersion(2,3)
502761Sstever@eecs.umich.eduEnsureSConsVersion(0,96)
512761Sstever@eecs.umich.edu
528878Ssteve.reinhardt@amd.com# The absolute path to the current directory (where this file lives).
538878Ssteve.reinhardt@amd.comROOT = Dir('.').abspath
542761Sstever@eecs.umich.edu
552761Sstever@eecs.umich.edu# Paths to the M5 and external source trees (local symlinks).
562761Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'm5')
572761Sstever@eecs.umich.eduEXT_SRCDIR = os.path.join(ROOT, 'ext')
582761Sstever@eecs.umich.edu
598878Ssteve.reinhardt@amd.com# Check for 'm5' and 'ext' links, die if they don't exist.
608878Ssteve.reinhardt@amd.comif not os.path.isdir(SRCDIR):
612632Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
622632Sstever@eecs.umich.edu    Exit(1)
638878Ssteve.reinhardt@amd.com
648878Ssteve.reinhardt@amd.comif not os.path.isdir('ext'):
652632Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 external source tree." \
66955SN/A          % EXT_SRCDIR
67955SN/A    Exit(1)
68955SN/A
695863Snate@binkert.org# tell python where to find m5 python code
705863Snate@binkert.orgsys.path.append(os.path.join(SRCDIR, 'python'))
715863Snate@binkert.org
725863Snate@binkert.org###################################################
735863Snate@binkert.org#
745863Snate@binkert.org# Figure out which configurations to set up.
755863Snate@binkert.org#
765863Snate@binkert.org#
775863Snate@binkert.org# It's prohibitive to do all the combinations of base configurations
785863Snate@binkert.org# and options, so we have to infer which ones the user wants.
795863Snate@binkert.org#
808878Ssteve.reinhardt@amd.com# 1. If there are command-line targets, the configuration(s) are inferred
815863Snate@binkert.org#    from the directories of those targets.  If scons was invoked from a
825863Snate@binkert.org#    subdirectory (using 'scons -u'), those targets have to be
835863Snate@binkert.org#    interpreted relative to that subdirectory.
845863Snate@binkert.org#
855863Snate@binkert.org# 2. If there are no command-line targets, and scons was invoked from a
865863Snate@binkert.org#    subdirectory (using 'scons -u'), the configuration is inferred from
875863Snate@binkert.org#    the name of the subdirectory.
885863Snate@binkert.org#
895863Snate@binkert.org# 3. If there are no command-line targets and scons was invoked from
905863Snate@binkert.org#    the root build directory, a default configuration is used.  The
915863Snate@binkert.org#    built-in default is ALPHA_SE, but this can be overridden by setting the
925863Snate@binkert.org#    M5_DEFAULT_CONFIG shell environment veriable.
935863Snate@binkert.org#
945863Snate@binkert.org# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
955863Snate@binkert.org# this can be overridden by setting the M5_DEFAULT_BINARY shell
968878Ssteve.reinhardt@amd.com# environment veriable.
975863Snate@binkert.org#
985863Snate@binkert.org###################################################
995863Snate@binkert.org
1006654Snate@binkert.org# Find default configuration & binary.
101955SN/Adefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
1025396Ssaidi@eecs.umich.edudefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1035863Snate@binkert.org
1045863Snate@binkert.org# Ask SCons which directory it was invoked from.  If you invoke SCons
1054202Sbinkertn@umich.edu# from a subdirectory you must use the '-u' flag.
1065863Snate@binkert.orglaunch_dir = GetLaunchDir()
1075863Snate@binkert.org
1085863Snate@binkert.org# Build a list 'my_targets' of all the targets relative to ROOT.
1095863Snate@binkert.orgif launch_dir == ROOT:
110955SN/A    # invoked from root build dir
1116654Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
1125273Sstever@gmail.com        # easy: use specified targets as is
1135871Snate@binkert.org        my_targets = COMMAND_LINE_TARGETS
1145273Sstever@gmail.com    else:
1156655Snate@binkert.org        # default target (ALPHA_SE/m5.debug, unless overridden)
1168878Ssteve.reinhardt@amd.com        target = os.path.join(default_config, default_binary)
1176655Snate@binkert.org        my_targets = [target]
1186655Snate@binkert.org        Default(target)
1199219Spower.jg@gmail.comelse:
1206655Snate@binkert.org    # invoked from subdirectory
1215871Snate@binkert.org    if not launch_dir.startswith(ROOT):
1226654Snate@binkert.org        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
1238947Sandreas.hansson@arm.com              (launch_dir, ROOT)
1245396Ssaidi@eecs.umich.edu        Exit(1)
1258120Sgblack@eecs.umich.edu    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
1268120Sgblack@eecs.umich.edu    launch_dir = launch_dir[len(ROOT)+1:]
1278120Sgblack@eecs.umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
1288120Sgblack@eecs.umich.edu        # make specified targets relative to ROOT
1298120Sgblack@eecs.umich.edu        my_targets = map(lambda x: os.path.join(launch_dir, x),
1308120Sgblack@eecs.umich.edu                         COMMAND_LINE_TARGETS)
1318120Sgblack@eecs.umich.edu    else:
1328120Sgblack@eecs.umich.edu        # build default binary (m5.debug, unless overridden) using the
1338879Ssteve.reinhardt@amd.com        # config inferred by the invocation directory (the first
1348879Ssteve.reinhardt@amd.com        # subdirectory after ROOT)
1358879Ssteve.reinhardt@amd.com        target = os.path.join(launch_dir.split('/')[0], default_binary)
1368879Ssteve.reinhardt@amd.com        my_targets = [target]
1378879Ssteve.reinhardt@amd.com        Default(target)
1388879Ssteve.reinhardt@amd.com
1398879Ssteve.reinhardt@amd.com# Normalize target paths (gets rid of '..' in the middle, etc.)
1408879Ssteve.reinhardt@amd.commy_targets = map(os.path.normpath, my_targets)
1418879Ssteve.reinhardt@amd.com
1428879Ssteve.reinhardt@amd.com# Generate a list of the unique configs that the collected targets reference.
1438879Ssteve.reinhardt@amd.combuild_dirs = []
1448879Ssteve.reinhardt@amd.comfor t in my_targets:
1458879Ssteve.reinhardt@amd.com    dir = t.split('/')[0]
1468120Sgblack@eecs.umich.edu    if dir not in build_dirs:
1478120Sgblack@eecs.umich.edu        build_dirs.append(dir)
1488120Sgblack@eecs.umich.edu
1498120Sgblack@eecs.umich.edu# Make a first pass to verify that build dirs are valid
1508120Sgblack@eecs.umich.edufor build_dir in build_dirs:
1518120Sgblack@eecs.umich.edu    if not os.path.isdir(build_dir):
1528120Sgblack@eecs.umich.edu        print "Error: build directory", build_dir, "does not exist."
1538120Sgblack@eecs.umich.edu        Exit(1)
1548120Sgblack@eecs.umich.edu
1558120Sgblack@eecs.umich.edu###################################################
1568120Sgblack@eecs.umich.edu#
1578120Sgblack@eecs.umich.edu# Set up the default build environment.  This environment is copied
1588120Sgblack@eecs.umich.edu# and modified according to each selected configuration.
1598120Sgblack@eecs.umich.edu#
1608879Ssteve.reinhardt@amd.com###################################################
1618879Ssteve.reinhardt@amd.com
1628879Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ,  # inherit user's environment vars
1638879Ssteve.reinhardt@amd.com                  ROOT = ROOT,
1648879Ssteve.reinhardt@amd.com                  SRCDIR = SRCDIR,
1658879Ssteve.reinhardt@amd.com                  EXT_SRCDIR = EXT_SRCDIR)
1668879Ssteve.reinhardt@amd.com
1678879Ssteve.reinhardt@amd.comenv.SConsignFile("sconsign")
1689227Sandreas.hansson@arm.com
1699227Sandreas.hansson@arm.comif os.environ.has_key('CC'):
1708879Ssteve.reinhardt@amd.com    env.Replace(CC=os.environ['CC'])
1718879Ssteve.reinhardt@amd.com
1728879Ssteve.reinhardt@amd.comif os.environ.has_key('CXX'):
1738879Ssteve.reinhardt@amd.com    env.Replace(CXX=os.environ['CXX'])
1748120Sgblack@eecs.umich.edu
1758947Sandreas.hansson@arm.com# M5_EXT is used by isa_parser.py to find the PLY package.
1767816Ssteve.reinhardt@amd.comenv.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
1775871Snate@binkert.org
1785871Snate@binkert.org# Set up default C++ compiler flags
1796121Snate@binkert.orgenv.Append(CCFLAGS='-pipe')
1805871Snate@binkert.orgenv.Append(CCFLAGS='-fno-strict-aliasing')
1815871Snate@binkert.orgenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1829119Sandreas.hansson@arm.comif sys.platform == 'cygwin':
1839396Sandreas.hansson@arm.com    # cygwin has some header file issues...
1849396Sandreas.hansson@arm.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
185955SN/Aenv.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
1865871Snate@binkert.org
1875871Snate@binkert.org# Default libraries
1885871Snate@binkert.orgenv.Append(LIBS=['z'])
1895871Snate@binkert.org
190955SN/A# Platform-specific configuration
1916121Snate@binkert.orgconf = Configure(env)
1928881Smarc.orr@gmail.com
1936121Snate@binkert.org# Check for <fenv.h> (C99 FP environment control)
1946121Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>')
1951533SN/Aif not have_fenv:
1969239Sandreas.hansson@arm.com    print "Warning: Header file <fenv.h> not found."
1979239Sandreas.hansson@arm.com    print "         This host has no IEEE FP rounding mode control."
1989239Sandreas.hansson@arm.com
1999239Sandreas.hansson@arm.com# Check for mysql.
2009239Sandreas.hansson@arm.commysql_config = WhereIs('mysql_config')
2019239Sandreas.hansson@arm.comhave_mysql = mysql_config != None
2029239Sandreas.hansson@arm.com
2039239Sandreas.hansson@arm.com# Check MySQL version.
2049239Sandreas.hansson@arm.comif have_mysql:
2059239Sandreas.hansson@arm.com    mysql_vers = os.popen(mysql_config + ' --version').read()
2069239Sandreas.hansson@arm.com    mv = [int(v) for v in mysql_vers.split('.')]
2079239Sandreas.hansson@arm.com    # This version check is probably overly conservative, but it deals
2086655Snate@binkert.org    # with the versions we have installed.
2096655Snate@binkert.org    if mv[0] < 3 or (mv[0] == 3 and mv[1] < 23) or (mv[0] == 4 and mv[1] < 1):
2106655Snate@binkert.org        print "Warning: MySQL v3.23 or v4.1 or newer required."
2116655Snate@binkert.org        have_mysql = False
2125871Snate@binkert.org
2135871Snate@binkert.org# Set up mysql_config commands.
2145863Snate@binkert.orgif have_mysql:
2155871Snate@binkert.org    mysql_config_include = mysql_config + ' --include'
2168878Ssteve.reinhardt@amd.com    if os.system(mysql_config_include + ' > /dev/null') != 0:
2175871Snate@binkert.org        # older mysql_config versions don't support --include, use
2185871Snate@binkert.org        # --cflags instead
2195871Snate@binkert.org        mysql_config_include = mysql_config + ' --cflags'
2205863Snate@binkert.org    # This seems to work in all versions
2216121Snate@binkert.org    mysql_config_libs = mysql_config + ' --libs'
2225863Snate@binkert.org
2235871Snate@binkert.orgenv = conf.Finish()
2248336Ssteve.reinhardt@amd.com
2258336Ssteve.reinhardt@amd.com# The source operand is a Value node containing the value of the option.
2268336Ssteve.reinhardt@amd.comdef build_config_file(target, source, env, option):
2278336Ssteve.reinhardt@amd.com    f = file(str(target[0]), 'w')
2284678Snate@binkert.org    print >> f, '#define', option, source[0]
2298336Ssteve.reinhardt@amd.com    f.close()
2308336Ssteve.reinhardt@amd.com    return None
2318336Ssteve.reinhardt@amd.com
2324678Snate@binkert.orgdef config_builder(env, option):
2334678Snate@binkert.org    target = os.path.join('config', option.lower() + '.hh')
2344678Snate@binkert.org    source = Value(env[option])
2354678Snate@binkert.org    def my_build_config_file(target, source, env):
2367827Snate@binkert.org        build_config_file(target, source, env, option)
2377827Snate@binkert.org    env.Command(target, source, my_build_config_file)
2388336Ssteve.reinhardt@amd.com
2394678Snate@binkert.orgenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
2408336Ssteve.reinhardt@amd.com
2418336Ssteve.reinhardt@amd.com# libelf build is described in its own SConscript file.
2428336Ssteve.reinhardt@amd.com# SConscript-global is the build in build/libelf shared among all
2438336Ssteve.reinhardt@amd.com# configs.
2448336Ssteve.reinhardt@amd.comenv.SConscript('m5/libelf/SConscript-global', exports = 'env')
2458336Ssteve.reinhardt@amd.com
2465871Snate@binkert.org###################################################
2475871Snate@binkert.org#
2488336Ssteve.reinhardt@amd.com# Define build environments for selected configurations.
2498336Ssteve.reinhardt@amd.com#
2508336Ssteve.reinhardt@amd.com###################################################
2518336Ssteve.reinhardt@amd.com
2528336Ssteve.reinhardt@amd.com# rename base env
2535871Snate@binkert.orgbase_env = env
2548336Ssteve.reinhardt@amd.com
2558336Ssteve.reinhardt@amd.comfor build_dir in build_dirs:
2568336Ssteve.reinhardt@amd.com    # Make a copy of the default environment to use for this config.
2578336Ssteve.reinhardt@amd.com    env = base_env.Copy()
2588336Ssteve.reinhardt@amd.com    # Set env according to the build directory config.
2594678Snate@binkert.org    options_file = os.path.join(build_dir, 'build_options')
2605871Snate@binkert.org    opts = Options(options_file, ARGUMENTS)
2614678Snate@binkert.org    opts.AddOptions(
2628336Ssteve.reinhardt@amd.com        EnumOption('TARGET_ISA', 'Target ISA', 'alpha', ('alpha')),
2638336Ssteve.reinhardt@amd.com        BoolOption('FULL_SYSTEM', 'Full-system support', False),
2648336Ssteve.reinhardt@amd.com        BoolOption('ALPHA_TLASER',
2658336Ssteve.reinhardt@amd.com                   'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2668336Ssteve.reinhardt@amd.com        BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2678336Ssteve.reinhardt@amd.com        BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2688336Ssteve.reinhardt@amd.com                   False),
2698336Ssteve.reinhardt@amd.com        BoolOption('SS_COMPATIBLE_FP',
2708336Ssteve.reinhardt@amd.com                   'Make floating-point results compatible with SimpleScalar',
2718336Ssteve.reinhardt@amd.com                   False),
2728336Ssteve.reinhardt@amd.com        BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2738336Ssteve.reinhardt@amd.com        BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2748336Ssteve.reinhardt@amd.com        BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv)
2758336Ssteve.reinhardt@amd.com        )
2768336Ssteve.reinhardt@amd.com
2778336Ssteve.reinhardt@amd.com    opts.Update(env)
2788336Ssteve.reinhardt@amd.com    opts.Save(options_file, env)
2795871Snate@binkert.org
2806121Snate@binkert.org    env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
281955SN/A                         'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
282955SN/A                         'STATS_BINNING']
2832632Sstever@eecs.umich.edu
2842632Sstever@eecs.umich.edu    # Process option settings.
285955SN/A
286955SN/A    if not have_fenv and env['USE_FENV']:
287955SN/A        print "Warning: <fenv.h> not available; " \
288955SN/A              "forcing USE_FENV to False in", build_dir + "."
2898878Ssteve.reinhardt@amd.com        env['USE_FENV'] = False
290955SN/A
2912632Sstever@eecs.umich.edu    if not env['USE_FENV']:
2922632Sstever@eecs.umich.edu        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
2932632Sstever@eecs.umich.edu        print "         FP results may deviate slightly", \
2942632Sstever@eecs.umich.edu              "and some regression tests may fail."
2952632Sstever@eecs.umich.edu
2962632Sstever@eecs.umich.edu    if env['EFENCE']:
2972632Sstever@eecs.umich.edu        env.Append(LIBS=['efence'])
2988268Ssteve.reinhardt@amd.com
2998268Ssteve.reinhardt@amd.com    if env['USE_MYSQL']:
3008268Ssteve.reinhardt@amd.com        if not have_mysql:
3018268Ssteve.reinhardt@amd.com            print "Warning: MySQL not available; " \
3028268Ssteve.reinhardt@amd.com                  "forcing USE_MYSQL to False in", build_dir + "."
3038268Ssteve.reinhardt@amd.com            env['USE_MYSQL'] = False
3048268Ssteve.reinhardt@amd.com        else:
3052632Sstever@eecs.umich.edu            print "Compiling in", build_dir, "with MySQL support."
3062632Sstever@eecs.umich.edu            env.ParseConfig(mysql_config_libs)
3072632Sstever@eecs.umich.edu            env.ParseConfig(mysql_config_include)
3082632Sstever@eecs.umich.edu    
3098268Ssteve.reinhardt@amd.com    # The m5/SConscript file sets up the build rules in 'env' according
3102632Sstever@eecs.umich.edu    # to the configured options.
3118268Ssteve.reinhardt@amd.com    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
3128268Ssteve.reinhardt@amd.com               duplicate=0)
3138268Ssteve.reinhardt@amd.com
3148268Ssteve.reinhardt@amd.com###################################################
3153718Sstever@eecs.umich.edu#
3162634Sstever@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
3172634Sstever@eecs.umich.edu# build environments to build the requested targets.
3185863Snate@binkert.org#
3192638Sstever@eecs.umich.edu###################################################
3208268Ssteve.reinhardt@amd.com
3212632Sstever@eecs.umich.edu