SConstruct revision 1762
12929Sktlim@umich.edu# -*- mode:python -*-
22929Sktlim@umich.edu
32932Sktlim@umich.edu# Copyright (c) 2004-2005 The Regents of The University of Michigan
42929Sktlim@umich.edu# All rights reserved.
52929Sktlim@umich.edu#
62929Sktlim@umich.edu# Redistribution and use in source and binary forms, with or without
72929Sktlim@umich.edu# modification, are permitted provided that the following conditions are
82929Sktlim@umich.edu# met: redistributions of source code must retain the above copyright
92929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer;
102929Sktlim@umich.edu# redistributions in binary form must reproduce the above copyright
112929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer in the
122929Sktlim@umich.edu# documentation and/or other materials provided with the distribution;
132929Sktlim@umich.edu# neither the name of the copyright holders nor the names of its
142929Sktlim@umich.edu# contributors may be used to endorse or promote products derived from
152929Sktlim@umich.edu# this software without specific prior written permission.
162929Sktlim@umich.edu#
172929Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182929Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192929Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202929Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212929Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222929Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232929Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242929Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252929Sktlim@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262929Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272929Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282932Sktlim@umich.edu
292932Sktlim@umich.edu###################################################
302932Sktlim@umich.edu#
312929Sktlim@umich.edu# SCons top-level build description (SConstruct) file.
326007Ssteve.reinhardt@amd.com#
332929Sktlim@umich.edu# To build M5, you need a directory with three things:
342929Sktlim@umich.edu# 1. A copy of this file (named SConstruct).
352929Sktlim@umich.edu# 2. A link named 'm5' to the top of the M5 simulator source tree.
362929Sktlim@umich.edu# 3. A link named 'ext' to the top of the M5 external source tree.
372929Sktlim@umich.edu#
382929Sktlim@umich.edu# Then type 'scons' to build the default configuration (see below), or
392929Sktlim@umich.edu# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
402929Sktlim@umich.edu# 'ALPHA_FS/m5.opt' for the optimized full-system version).
412929Sktlim@umich.edu#
422929Sktlim@umich.edu###################################################
432929Sktlim@umich.edu
442929Sktlim@umich.edu# Python library imports
452929Sktlim@umich.eduimport sys
462929Sktlim@umich.eduimport os
476007Ssteve.reinhardt@amd.com
486007Ssteve.reinhardt@amd.com# The absolute path to the current directory (where this file lives).
496007Ssteve.reinhardt@amd.comROOT = Dir('.').abspath
506007Ssteve.reinhardt@amd.com
516007Ssteve.reinhardt@amd.com# Paths to the M5 and external source trees (local symlinks).
526007Ssteve.reinhardt@amd.comSRCDIR = os.path.join(ROOT, 'm5')
536007Ssteve.reinhardt@amd.comEXT_SRCDIR = os.path.join(ROOT, 'ext')
546007Ssteve.reinhardt@amd.com
556007Ssteve.reinhardt@amd.com# Check for 'm5' and 'ext' links, die if they don't exist.
566007Ssteve.reinhardt@amd.comif not os.path.isdir(SRCDIR):
576007Ssteve.reinhardt@amd.com    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
586007Ssteve.reinhardt@amd.com    sys.exit(1)
596007Ssteve.reinhardt@amd.com
606007Ssteve.reinhardt@amd.comif not os.path.isdir('ext'):
616007Ssteve.reinhardt@amd.com    print "Error: '%s' must be a link to the M5 external source tree." \
626007Ssteve.reinhardt@amd.com          % EXT_SRCDIR
636007Ssteve.reinhardt@amd.com    sys.exit(1)
646007Ssteve.reinhardt@amd.com
656007Ssteve.reinhardt@amd.com# tell python where to find m5 python code
666007Ssteve.reinhardt@amd.comsys.path.append(os.path.join(SRCDIR, 'python'))
676007Ssteve.reinhardt@amd.com
686007Ssteve.reinhardt@amd.com
696007Ssteve.reinhardt@amd.com###################################################
706007Ssteve.reinhardt@amd.com#
716007Ssteve.reinhardt@amd.com# Define Configurations
726007Ssteve.reinhardt@amd.com#
736007Ssteve.reinhardt@amd.com# The build system infers the build options from the subdirectory name
746007Ssteve.reinhardt@amd.com# that the simulator is built under.  The subdirectory name must be of
756007Ssteve.reinhardt@amd.com# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
762929Sktlim@umich.edu# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL).  The
772929Sktlim@umich.edu# following code defines the standard configurations and options.
782929Sktlim@umich.edu# Additional local configurations and options are read from the file
796007Ssteve.reinhardt@amd.com# 'local_configs' if it exists.
806007Ssteve.reinhardt@amd.com#
816007Ssteve.reinhardt@amd.com# Each base configuration or option is defined in two steps: a
826007Ssteve.reinhardt@amd.com# function that takes an SCons build environment and modifies it
836007Ssteve.reinhardt@amd.com# appropriately for that config or option, and an entry in the
846007Ssteve.reinhardt@amd.com# 'configs_map' or 'options_map' dictionary that maps the directory
852929Sktlim@umich.edu# name string to the function.  (The directory names are all upper
862929Sktlim@umich.edu# case, by convention.)
872929Sktlim@umich.edu#
882929Sktlim@umich.edu###################################################
892929Sktlim@umich.edu
906011Ssteve.reinhardt@amd.com# Base non-full-system Alpha ISA configuration.
916007Ssteve.reinhardt@amd.comdef AlphaSyscallEmulConfig(env):
926007Ssteve.reinhardt@amd.com    env.Replace(TARGET_ISA = 'alpha')
936007Ssteve.reinhardt@amd.com    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
946007Ssteve.reinhardt@amd.com
956007Ssteve.reinhardt@amd.com# Base full-system configuration.
966007Ssteve.reinhardt@amd.comdef AlphaFullSysConfig(env):
976007Ssteve.reinhardt@amd.com    env.Replace(TARGET_ISA = 'alpha')
986007Ssteve.reinhardt@amd.com    env.Replace(FULL_SYSTEM = True)
996007Ssteve.reinhardt@amd.com    env.Append(CPPDEFINES = ['FULL_SYSTEM'])
1006007Ssteve.reinhardt@amd.com
1016007Ssteve.reinhardt@amd.com# Base configurations map.
1026007Ssteve.reinhardt@amd.comconfigs_map = {
1036007Ssteve.reinhardt@amd.com    'ALPHA_SE' : AlphaSyscallEmulConfig,
1046007Ssteve.reinhardt@amd.com    'ALPHA_FS' : AlphaFullSysConfig
1056011Ssteve.reinhardt@amd.com    }
1066007Ssteve.reinhardt@amd.com
1076007Ssteve.reinhardt@amd.com# Disable FastAlloc object allocation.
1086007Ssteve.reinhardt@amd.comdef NoFastAllocOpt(env):
1096007Ssteve.reinhardt@amd.com    env.Append(CPPDEFINES = 'NO_FAST_ALLOC')
1106007Ssteve.reinhardt@amd.com
1116007Ssteve.reinhardt@amd.com# Enable efence
1126007Ssteve.reinhardt@amd.comdef EfenceOpt(env):
1136011Ssteve.reinhardt@amd.com    env.Append(LIBS=['efence'])
1146007Ssteve.reinhardt@amd.com
1156007Ssteve.reinhardt@amd.com# Configuration options map.
1166007Ssteve.reinhardt@amd.comoptions_map = {
1176007Ssteve.reinhardt@amd.com    'NO_FAST_ALLOC' : NoFastAllocOpt,
1186007Ssteve.reinhardt@amd.com    'EFENCE' : EfenceOpt
1196007Ssteve.reinhardt@amd.com    }
1206007Ssteve.reinhardt@amd.com
1216011Ssteve.reinhardt@amd.com# The 'local_configs' file can be used to define additional base
1226007Ssteve.reinhardt@amd.com# configurations and/or options without changing this file.
1236007Ssteve.reinhardt@amd.comif os.path.isfile('local_configs'):
1246007Ssteve.reinhardt@amd.com    SConscript('local_configs', exports = ['configs_map', 'options_map'])
1256007Ssteve.reinhardt@amd.com
1266007Ssteve.reinhardt@amd.com# This function parses a directory name of the form <CONFIG>[.<OPT>]*
1276008Ssteve.reinhardt@amd.com# and sets up the build environment appropriately.  Returns True if
1286007Ssteve.reinhardt@amd.com# successful, False if the base config or any of the options were not
1296008Ssteve.reinhardt@amd.com# defined.
1306008Ssteve.reinhardt@amd.comdef set_dir_options(dir, env):
1316008Ssteve.reinhardt@amd.com    parts = dir.split('.')
1326008Ssteve.reinhardt@amd.com    config = parts[0]
1336008Ssteve.reinhardt@amd.com    opts = parts[1:]
1346008Ssteve.reinhardt@amd.com    try:
1356008Ssteve.reinhardt@amd.com        configs_map[config](env)
1366007Ssteve.reinhardt@amd.com        map(lambda opt: options_map[opt](env), opts)
1376007Ssteve.reinhardt@amd.com        return True
1386007Ssteve.reinhardt@amd.com    except KeyError, key:
1396007Ssteve.reinhardt@amd.com        print "Config/option '%s' not found." % key
1406007Ssteve.reinhardt@amd.com        return False
1412929Sktlim@umich.edu
1422929Sktlim@umich.edu# Set the default configuration and binary.  The default target (if
1432929Sktlim@umich.edu# scons is invoked at the top level with no command-line targets) is
1442929Sktlim@umich.edu# 'ALPHA_SE/m5.debug'.  If scons is invoked in a subdirectory with no
1456007Ssteve.reinhardt@amd.com# command-line targets, the configuration
1466007Ssteve.reinhardt@amd.com
1472929Sktlim@umich.edu###################################################
1482929Sktlim@umich.edu#
1492929Sktlim@umich.edu# Figure out which configurations to set up.
1502929Sktlim@umich.edu#
1516007Ssteve.reinhardt@amd.com#
1526007Ssteve.reinhardt@amd.com# It's prohibitive to do all the combinations of base configurations
1532929Sktlim@umich.edu# and options, so we have to infer which ones the user wants.
1542929Sktlim@umich.edu#
1556007Ssteve.reinhardt@amd.com# 1. If there are command-line targets, the configuration(s) are inferred
1562929Sktlim@umich.edu#    from the directories of those targets.  If scons was invoked from a
1572929Sktlim@umich.edu#    subdirectory (using 'scons -u'), those targets have to be
1582929Sktlim@umich.edu#    interpreted relative to that subdirectory.
1592929Sktlim@umich.edu#
1602929Sktlim@umich.edu# 2. If there are no command-line targets, and scons was invoked from a
1612929Sktlim@umich.edu#    subdirectory (using 'scons -u'), the configuration is inferred from
1622929Sktlim@umich.edu#    the name of the subdirectory.
1634937Sstever@gmail.com#
1644937Sstever@gmail.com# 3. If there are no command-line targets and scons was invoked from
1654937Sstever@gmail.com#    the root build directory, a default configuration is used.  The
1664937Sstever@gmail.com#    built-in default is ALPHA_SE, but this can be overridden by setting the
1674937Sstever@gmail.com#    M5_DEFAULT_CONFIG shell environment veriable.
1684937Sstever@gmail.com#
1694937Sstever@gmail.com# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
1704937Sstever@gmail.com# this can be overridden by setting the M5_DEFAULT_BINARY shell
1714937Sstever@gmail.com# environment veriable.
1725773Snate@binkert.org#
1734937Sstever@gmail.com###################################################
1744937Sstever@gmail.com
1754937Sstever@gmail.com# Find default configuration & binary.
1762929Sktlim@umich.edudefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
1772929Sktlim@umich.edudefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1782929Sktlim@umich.edu
1795773Snate@binkert.org# Ask SCons which directory it was invoked from.  If you invoke SCons
1802929Sktlim@umich.edu# from a subdirectory you must use the '-u' flag.
1812929Sktlim@umich.edulaunch_dir = GetLaunchDir()
1822929Sktlim@umich.edu
1832929Sktlim@umich.edu# Build a list 'my_targets' of all the targets relative to ROOT.
1842929Sktlim@umich.eduif launch_dir == ROOT:
1852929Sktlim@umich.edu    # invoked from root build dir
1864937Sstever@gmail.com    if len(COMMAND_LINE_TARGETS) != 0:
1874937Sstever@gmail.com        # easy: use specified targets as is
1884937Sstever@gmail.com        my_targets = COMMAND_LINE_TARGETS
1894937Sstever@gmail.com    else:
1904937Sstever@gmail.com        # default target (ALPHA_SE/m5.debug, unless overridden)
1914937Sstever@gmail.com        target = os.path.join(default_config, default_binary)
1924937Sstever@gmail.com        my_targets = [target]
1934937Sstever@gmail.com        Default(target)
1944937Sstever@gmail.comelse:
1954937Sstever@gmail.com    # invoked from subdirectory
1964937Sstever@gmail.com    if not launch_dir.startswith(ROOT):
1974937Sstever@gmail.com        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
1984937Sstever@gmail.com              (launch_dir, ROOT)
1994937Sstever@gmail.com        sys.exit(1)
2004937Sstever@gmail.com    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
2012929Sktlim@umich.edu    launch_dir = launch_dir[len(ROOT)+1:]
2022929Sktlim@umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
2032929Sktlim@umich.edu        # make specified targets relative to ROOT
2042929Sktlim@umich.edu        my_targets = map(lambda x: os.path.join(launch_dir, x),
2052929Sktlim@umich.edu                         COMMAND_LINE_TARGETS)
2062929Sktlim@umich.edu    else:
2072929Sktlim@umich.edu        # build default binary (m5.debug, unless overridden) using the
2086011Ssteve.reinhardt@amd.com        # config inferred by the invocation directory (the first
2092929Sktlim@umich.edu        # subdirectory after ROOT)
2102929Sktlim@umich.edu        target = os.path.join(launch_dir.split('/')[0], default_binary)
2112929Sktlim@umich.edu        my_targets = [target]
2122929Sktlim@umich.edu        Default(target)
2132929Sktlim@umich.edu
2142929Sktlim@umich.edu# Normalize target paths (gets rid of '..' in the middle, etc.)
2152929Sktlim@umich.edumy_targets = map(os.path.normpath, my_targets)
2162929Sktlim@umich.edu
2172997Sstever@eecs.umich.edu# Generate a list of the unique configs that the collected targets reference.
2182997Sstever@eecs.umich.edubuild_dirs = []
2192929Sktlim@umich.edufor t in my_targets:
2202997Sstever@eecs.umich.edu    dir = t.split('/')[0]
2212997Sstever@eecs.umich.edu    if dir not in build_dirs:
2222929Sktlim@umich.edu        build_dirs.append(dir)
2232997Sstever@eecs.umich.edu
2242997Sstever@eecs.umich.edu###################################################
2252997Sstever@eecs.umich.edu#
2262929Sktlim@umich.edu# Set up the default build environment.  This environment is copied
2272997Sstever@eecs.umich.edu# and modified according to each selected configuration.
2282997Sstever@eecs.umich.edu#
2292997Sstever@eecs.umich.edu###################################################
2302997Sstever@eecs.umich.edu
2315773Snate@binkert.orgdefault_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
2325773Snate@binkert.org                          ROOT = ROOT,
2332997Sstever@eecs.umich.edu                          SRCDIR = SRCDIR,
2342997Sstever@eecs.umich.edu                          EXT_SRCDIR = EXT_SRCDIR,
2356007Ssteve.reinhardt@amd.com                          CPPDEFINES = [],
2366007Ssteve.reinhardt@amd.com                          FULL_SYSTEM = False,
2372997Sstever@eecs.umich.edu                          ALPHA_TLASER = False,
2382929Sktlim@umich.edu                          USE_MYSQL = False)
2392997Sstever@eecs.umich.edu
2402997Sstever@eecs.umich.edudefault_env.SConsignFile("sconsign")
2412997Sstever@eecs.umich.edu
2422997Sstever@eecs.umich.edu# For some reason, the CC and CXX variables don't get passed into the
2432997Sstever@eecs.umich.edu# environment correctly.  This is probably some sort of scons bug that
2442997Sstever@eecs.umich.edu# will eventually be fixed.
2452997Sstever@eecs.umich.eduif os.environ.has_key('CC'):
2462929Sktlim@umich.edu    default_env.Replace(CC=os.environ['CC'])
2472997Sstever@eecs.umich.edu
2482929Sktlim@umich.eduif os.environ.has_key('CXX'):
2492929Sktlim@umich.edu    default_env.Replace(CXX=os.environ['CXX'])
2503005Sstever@eecs.umich.edu
2513005Sstever@eecs.umich.edu# M5_EXT is used by isa_parser.py to find the PLY package.
2523005Sstever@eecs.umich.edudefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
2533005Sstever@eecs.umich.edu
2546025Snate@binkert.orgdefault_env.Append(CCFLAGS='-pipe')
2556025Snate@binkert.orgdefault_env.Append(CCFLAGS='-fno-strict-aliasing')
2566025Snate@binkert.orgdefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2576025Snate@binkert.orgdefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
2586025Snate@binkert.org
2596025Snate@binkert.org# libelf build is described in its own SConscript file.  Using a
2604130Ssaidi@eecs.umich.edu# dictionary for exports lets us export "default_env" so the
2614130Ssaidi@eecs.umich.edu# SConscript will see it as "env".  SConscript-global is the build in
2624130Ssaidi@eecs.umich.edu# build/libelf shared among all configs.
2633691Shsul@eecs.umich.edudefault_env.SConscript('m5/libelf/SConscript-global',
2643005Sstever@eecs.umich.edu                       exports={'env' : default_env})
2655721Shsul@eecs.umich.edu
2666112Ssteve.reinhardt@amd.com###################################################
2673005Sstever@eecs.umich.edu#
2686166Ssteve.reinhardt@amd.com# Define build environments for selected configurations.
2696166Ssteve.reinhardt@amd.com#
2706166Ssteve.reinhardt@amd.com###################################################
2712929Sktlim@umich.edu
2722929Sktlim@umich.edufor build_dir in build_dirs:
2733005Sstever@eecs.umich.edu    # Make a copy of the default environment to use for this config.
2742997Sstever@eecs.umich.edu    env = default_env.Copy()
2752997Sstever@eecs.umich.edu    # Modify 'env' according to the build directory config.
2762997Sstever@eecs.umich.edu    print "Configuring options for directory '%s'." % build_dir
2772929Sktlim@umich.edu    if not set_dir_options(build_dir, env):
278        print "Skipping directory '%s'." % build_dir
279        continue
280
281    # The m5/SConscript file sets up the build rules in 'env' according
282    # to the configured options.
283    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
284               duplicate=0)
285
286
287###################################################
288#
289# Let SCons do its thing.  At this point SCons will use the defined
290# build environments to build the requested targets.
291#
292###################################################
293
294