SConstruct revision 1858
1955SN/A# -*- mode:python -*-
2955SN/A
39812Sandreas.hansson@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from
157816Ssteve.reinhardt@amd.com# this software without specific prior written permission.
165871Snate@binkert.org#
171762SN/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###################################################
30955SN/A#
31955SN/A# SCons top-level build description (SConstruct) file.
32955SN/A#
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#
38955SN/A# Then type 'scons' to build the default configuration (see below), or
39955SN/A# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
40955SN/A# 'ALPHA_FS/m5.opt' for the optimized full-system version).
41955SN/A#
422665Ssaidi@eecs.umich.edu###################################################
432665Ssaidi@eecs.umich.edu
445863Snate@binkert.org# Python library imports
45955SN/Aimport sys
46955SN/Aimport os
47955SN/A
48955SN/A# Check for recent-enough Python and SCons versions
49955SN/AEnsurePythonVersion(2,3)
508878Ssteve.reinhardt@amd.comEnsureSConsVersion(0,96)
512632Sstever@eecs.umich.edu
528878Ssteve.reinhardt@amd.com# The absolute path to the current directory (where this file lives).
532632Sstever@eecs.umich.eduROOT = Dir('.').abspath
54955SN/A
558878Ssteve.reinhardt@amd.com# Paths to the M5 and external source trees (local symlinks).
562632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'm5')
572761Sstever@eecs.umich.eduEXT_SRCDIR = os.path.join(ROOT, 'ext')
582632Sstever@eecs.umich.edu
592632Sstever@eecs.umich.edu# Check for 'm5' and 'ext' links, die if they don't exist.
602632Sstever@eecs.umich.eduif not os.path.isdir(SRCDIR):
612761Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
622761Sstever@eecs.umich.edu    Exit(1)
632761Sstever@eecs.umich.edu
648878Ssteve.reinhardt@amd.comif not os.path.isdir('ext'):
658878Ssteve.reinhardt@amd.com    print "Error: '%s' must be a link to the M5 external source tree." \
662761Sstever@eecs.umich.edu          % EXT_SRCDIR
672761Sstever@eecs.umich.edu    Exit(1)
682761Sstever@eecs.umich.edu
692761Sstever@eecs.umich.edu# tell python where to find m5 python code
702761Sstever@eecs.umich.edusys.path.append(os.path.join(SRCDIR, 'python'))
718878Ssteve.reinhardt@amd.com
728878Ssteve.reinhardt@amd.com###################################################
732632Sstever@eecs.umich.edu#
742632Sstever@eecs.umich.edu# Figure out which configurations to set up.
758878Ssteve.reinhardt@amd.com#
768878Ssteve.reinhardt@amd.com#
772632Sstever@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations
78955SN/A# and options, so we have to infer which ones the user wants.
79955SN/A#
80955SN/A# 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
928878Ssteve.reinhardt@amd.com#    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
969812Sandreas.hansson@arm.com# environment veriable.
979812Sandreas.hansson@arm.com#
985863Snate@binkert.org###################################################
999812Sandreas.hansson@arm.com
1005863Snate@binkert.org# Find default configuration & binary.
1015863Snate@binkert.orgdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
1025863Snate@binkert.orgdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1039812Sandreas.hansson@arm.com
1049812Sandreas.hansson@arm.com# Ask SCons which directory it was invoked from.  If you invoke SCons
1055863Snate@binkert.org# from a subdirectory you must use the '-u' flag.
1065863Snate@binkert.orglaunch_dir = GetLaunchDir()
1078878Ssteve.reinhardt@amd.com
1085863Snate@binkert.org# Build a list 'my_targets' of all the targets relative to ROOT.
1095863Snate@binkert.orgif launch_dir == ROOT:
1105863Snate@binkert.org    # invoked from root build dir
1116654Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
11210196SCurtis.Dunham@arm.com        # easy: use specified targets as is
113955SN/A        my_targets = COMMAND_LINE_TARGETS
1145396Ssaidi@eecs.umich.edu    else:
1155863Snate@binkert.org        # default target (ALPHA_SE/m5.debug, unless overridden)
1165863Snate@binkert.org        target = os.path.join(default_config, default_binary)
1174202Sbinkertn@umich.edu        my_targets = [target]
1185863Snate@binkert.org        Default(target)
1195863Snate@binkert.orgelse:
1205863Snate@binkert.org    # invoked from subdirectory
1215863Snate@binkert.org    if not launch_dir.startswith(ROOT):
122955SN/A        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
1236654Snate@binkert.org              (launch_dir, ROOT)
1245273Sstever@gmail.com        Exit(1)
1255871Snate@binkert.org    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
1265273Sstever@gmail.com    launch_dir = launch_dir[len(ROOT)+1:]
1276655Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
1288878Ssteve.reinhardt@amd.com        # make specified targets relative to ROOT
1296655Snate@binkert.org        my_targets = map(lambda x: os.path.join(launch_dir, x),
1306655Snate@binkert.org                         COMMAND_LINE_TARGETS)
1319219Spower.jg@gmail.com    else:
1326655Snate@binkert.org        # build default binary (m5.debug, unless overridden) using the
1335871Snate@binkert.org        # config inferred by the invocation directory (the first
1346654Snate@binkert.org        # subdirectory after ROOT)
1358947Sandreas.hansson@arm.com        target = os.path.join(launch_dir.split('/')[0], default_binary)
1365396Ssaidi@eecs.umich.edu        my_targets = [target]
1378120Sgblack@eecs.umich.edu        Default(target)
1388120Sgblack@eecs.umich.edu
1398120Sgblack@eecs.umich.edu# Normalize target paths (gets rid of '..' in the middle, etc.)
1408120Sgblack@eecs.umich.edumy_targets = map(os.path.normpath, my_targets)
1418120Sgblack@eecs.umich.edu
1428120Sgblack@eecs.umich.edu# Generate a list of the unique configs that the collected targets reference.
1438120Sgblack@eecs.umich.edubuild_dirs = []
1448120Sgblack@eecs.umich.edufor t in my_targets:
1458879Ssteve.reinhardt@amd.com    dir = t.split('/')[0]
1468879Ssteve.reinhardt@amd.com    if dir not in build_dirs:
1478879Ssteve.reinhardt@amd.com        build_dirs.append(dir)
1488879Ssteve.reinhardt@amd.com
1498879Ssteve.reinhardt@amd.com# Make a first pass to verify that build dirs are valid
1508879Ssteve.reinhardt@amd.comfor build_dir in build_dirs:
1518879Ssteve.reinhardt@amd.com    if not os.path.isdir(build_dir):
1528879Ssteve.reinhardt@amd.com        print "Error: build directory", build_dir, "does not exist."
1538879Ssteve.reinhardt@amd.com        Exit(1)
1548879Ssteve.reinhardt@amd.com
1558879Ssteve.reinhardt@amd.com###################################################
1568879Ssteve.reinhardt@amd.com#
1578879Ssteve.reinhardt@amd.com# 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#
1608120Sgblack@eecs.umich.edu###################################################
1618120Sgblack@eecs.umich.edu
1628120Sgblack@eecs.umich.eduenv = Environment(ENV = os.environ,  # inherit user's environment vars
1638120Sgblack@eecs.umich.edu                  ROOT = ROOT,
1648120Sgblack@eecs.umich.edu                  SRCDIR = SRCDIR,
1658120Sgblack@eecs.umich.edu                  EXT_SRCDIR = EXT_SRCDIR)
1668120Sgblack@eecs.umich.edu
1678120Sgblack@eecs.umich.eduenv.SConsignFile("sconsign")
1688120Sgblack@eecs.umich.edu
1698120Sgblack@eecs.umich.eduif os.environ.has_key('CC'):
1708120Sgblack@eecs.umich.edu    env.Replace(CC=os.environ['CC'])
1718120Sgblack@eecs.umich.edu
1728879Ssteve.reinhardt@amd.comif os.environ.has_key('CXX'):
1738879Ssteve.reinhardt@amd.com    env.Replace(CXX=os.environ['CXX'])
1748879Ssteve.reinhardt@amd.com
1758879Ssteve.reinhardt@amd.com# M5_EXT is used by isa_parser.py to find the PLY package.
17610458Sandreas.hansson@arm.comenv.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
17710458Sandreas.hansson@arm.com
17810458Sandreas.hansson@arm.com# Set up default C++ compiler flags
1798879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-pipe')
1808879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS='-fno-strict-aliasing')
1818879Ssteve.reinhardt@amd.comenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
1828879Ssteve.reinhardt@amd.comif sys.platform == 'cygwin':
1839227Sandreas.hansson@arm.com    # cygwin has some header file issues...
1849227Sandreas.hansson@arm.com    env.Append(CCFLAGS=Split("-Wno-uninitialized"))
1858879Ssteve.reinhardt@amd.comenv.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
1868879Ssteve.reinhardt@amd.com
1878879Ssteve.reinhardt@amd.com# Default libraries
1888879Ssteve.reinhardt@amd.comenv.Append(LIBS=['z'])
18910453SAndrew.Bardsley@arm.com
19010453SAndrew.Bardsley@arm.com# Platform-specific configuration
19110453SAndrew.Bardsley@arm.comconf = Configure(env)
19210456SCurtis.Dunham@arm.com
19310456SCurtis.Dunham@arm.com# Check for <fenv.h> (C99 FP environment control)
19410456SCurtis.Dunham@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>')
19510457Sandreas.hansson@arm.comif not have_fenv:
19610457Sandreas.hansson@arm.com    print "Warning: Header file <fenv.h> not found."
1978120Sgblack@eecs.umich.edu    print "         This host has no IEEE FP rounding mode control."
1988947Sandreas.hansson@arm.com
1997816Ssteve.reinhardt@amd.com# Check for mysql
2005871Snate@binkert.orgmysql_config = WhereIs('mysql_config')
2015871Snate@binkert.orghave_mysql = mysql_config != None
2026121Snate@binkert.org
2035871Snate@binkert.orgenv = conf.Finish()
2045871Snate@binkert.org
2059926Sstan.czerniawski@arm.com# The source operand is a Value node containing the value of the option.
2069926Sstan.czerniawski@arm.comdef build_config_file(target, source, env, option):
2079119Sandreas.hansson@arm.com    f = file(str(target[0]), 'w')
20810068Sandreas.hansson@arm.com    print >> f, '#define', option, source[0]
20910068Sandreas.hansson@arm.com    f.close()
210955SN/A    return None
2119416SAndreas.Sandberg@ARM.com
2129416SAndreas.Sandberg@ARM.comdef config_builder(env, option):
2139416SAndreas.Sandberg@ARM.com    target = os.path.join('config', option.lower() + '.hh')
2149416SAndreas.Sandberg@ARM.com    source = Value(env[option])
2159416SAndreas.Sandberg@ARM.com    def my_build_config_file(target, source, env):
2169416SAndreas.Sandberg@ARM.com        build_config_file(target, source, env, option)
2179416SAndreas.Sandberg@ARM.com    env.Command(target, source, my_build_config_file)
2185871Snate@binkert.org
21910584Sandreas.hansson@arm.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder })
2209416SAndreas.Sandberg@ARM.com
2219416SAndreas.Sandberg@ARM.com# libelf build is described in its own SConscript file.
2225871Snate@binkert.org# SConscript-global is the build in build/libelf shared among all
223955SN/A# configs.
2246121Snate@binkert.orgenv.SConscript('m5/libelf/SConscript-global', exports = 'env')
2258881Smarc.orr@gmail.com
2266121Snate@binkert.org###################################################
2276121Snate@binkert.org#
2281533SN/A# Define build environments for selected configurations.
2299239Sandreas.hansson@arm.com#
2309239Sandreas.hansson@arm.com###################################################
2319239Sandreas.hansson@arm.com
2329239Sandreas.hansson@arm.com# rename base env
2339239Sandreas.hansson@arm.combase_env = env
2349239Sandreas.hansson@arm.com
2359239Sandreas.hansson@arm.comfor build_dir in build_dirs:
2369239Sandreas.hansson@arm.com    # Make a copy of the default environment to use for this config.
2379239Sandreas.hansson@arm.com    env = base_env.Copy()
2389239Sandreas.hansson@arm.com    # Set env according to the build directory config.
2399239Sandreas.hansson@arm.com    options_file = os.path.join(build_dir, 'build_options')
2409239Sandreas.hansson@arm.com    opts = Options(options_file, ARGUMENTS)
2416655Snate@binkert.org    opts.AddOptions(
2426655Snate@binkert.org        EnumOption('TARGET_ISA', 'Target ISA', 'alpha', ('alpha')),
2436655Snate@binkert.org        BoolOption('FULL_SYSTEM', 'Full-system support', False),
2446655Snate@binkert.org        BoolOption('ALPHA_TLASER',
2455871Snate@binkert.org                   'Model Alpha TurboLaser platform (vs. Tsunami)', False),
2465871Snate@binkert.org        BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False),
2475863Snate@binkert.org        BoolOption('EFENCE', 'Link with Electric Fence malloc debugger',
2485871Snate@binkert.org                   False),
2498878Ssteve.reinhardt@amd.com        BoolOption('SS_COMPATIBLE_FP',
2505871Snate@binkert.org                   'Make floating-point results compatible with SimpleScalar',
2515871Snate@binkert.org                   False),
2525871Snate@binkert.org        BoolOption('STATS_BINNING', 'Bin statistics by CPU mode', have_mysql),
2535863Snate@binkert.org        BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql),
2546121Snate@binkert.org        BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv)
2555863Snate@binkert.org        )
2565871Snate@binkert.org
2578336Ssteve.reinhardt@amd.com    opts.Update(env)
2588336Ssteve.reinhardt@amd.com    opts.Save(options_file, env)
2598336Ssteve.reinhardt@amd.com
2608336Ssteve.reinhardt@amd.com    env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \
2614678Snate@binkert.org                         'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \
2628336Ssteve.reinhardt@amd.com                         'STATS_BINNING']
2638336Ssteve.reinhardt@amd.com
2648336Ssteve.reinhardt@amd.com    # Process option settings.
2654678Snate@binkert.org
2664678Snate@binkert.org    if not have_fenv and env['USE_FENV']:
2674678Snate@binkert.org        print "Warning: <fenv.h> not available; " \
2684678Snate@binkert.org              "forcing USE_FENV to False in", build_dir + "."
2697827Snate@binkert.org        env['USE_FENV'] = False
2707827Snate@binkert.org
2718336Ssteve.reinhardt@amd.com    if not env['USE_FENV']:
2724678Snate@binkert.org        print "Warning: No IEEE FP rounding mode control in", build_dir + "."
2738336Ssteve.reinhardt@amd.com        print "         FP results may deviate slightly", \
2748336Ssteve.reinhardt@amd.com              "and some regression tests may fail."
2758336Ssteve.reinhardt@amd.com
2768336Ssteve.reinhardt@amd.com    if env['EFENCE']:
2778336Ssteve.reinhardt@amd.com        env.Append(LIBS=['efence'])
2788336Ssteve.reinhardt@amd.com
2795871Snate@binkert.org    if env['USE_MYSQL']:
2805871Snate@binkert.org        if not have_mysql:
2818336Ssteve.reinhardt@amd.com            print "Warning: MySQL not available; " \
2828336Ssteve.reinhardt@amd.com                  "forcing USE_MYSQL to False in", build_dir + "."
2838336Ssteve.reinhardt@amd.com            env['USE_MYSQL'] = False
2848336Ssteve.reinhardt@amd.com        else:
2858336Ssteve.reinhardt@amd.com            print "Compiling in", build_dir, "with MySQL support."
2865871Snate@binkert.org            env.ParseConfig(mysql_config + ' --libs')
2878336Ssteve.reinhardt@amd.com            env.ParseConfig(mysql_config + ' --include')
2888336Ssteve.reinhardt@amd.com    
2898336Ssteve.reinhardt@amd.com    # The m5/SConscript file sets up the build rules in 'env' according
2908336Ssteve.reinhardt@amd.com    # to the configured options.
2918336Ssteve.reinhardt@amd.com    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2924678Snate@binkert.org               duplicate=0)
2935871Snate@binkert.org
2944678Snate@binkert.org###################################################
2958336Ssteve.reinhardt@amd.com#
2968336Ssteve.reinhardt@amd.com# Let SCons do its thing.  At this point SCons will use the defined
2978336Ssteve.reinhardt@amd.com# build environments to build the requested targets.
2988336Ssteve.reinhardt@amd.com#
2998336Ssteve.reinhardt@amd.com###################################################
3008336Ssteve.reinhardt@amd.com
3018336Ssteve.reinhardt@amd.com