SConstruct revision 1065
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2004 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###################################################
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).
352632Sstever@eecs.umich.edu# 2. A link named 'm5' to the top of the M5 simulator source tree.
362632Sstever@eecs.umich.edu# 3. A link named 'ext' to the top of the M5 external source tree.
372632Sstever@eecs.umich.edu#
382632Sstever@eecs.umich.edu# Then type 'scons' to build the default configuration (see below), or
39955SN/A# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
402632Sstever@eecs.umich.edu# 'KERNEL/m5.opt' for the optimized full-system version).
412632Sstever@eecs.umich.edu#
422761Sstever@eecs.umich.edu###################################################
432632Sstever@eecs.umich.edu
442632Sstever@eecs.umich.edu# Python library imports
452632Sstever@eecs.umich.eduimport sys
462761Sstever@eecs.umich.eduimport os
472761Sstever@eecs.umich.edu
482761Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives).
492632Sstever@eecs.umich.eduROOT = Dir('.').abspath
502632Sstever@eecs.umich.edu
512761Sstever@eecs.umich.edu# Paths to the M5 and external source trees (local symlinks).
522761Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'm5')
532761Sstever@eecs.umich.eduEXT_SRCDIR = os.path.join(ROOT, 'ext')
542761Sstever@eecs.umich.edu
552761Sstever@eecs.umich.edu# Check for 'm5' and 'ext' links, die if they don't exist.
562632Sstever@eecs.umich.eduif not os.path.isdir(SRCDIR):
572632Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
582632Sstever@eecs.umich.edu    sys.exit(1)
592632Sstever@eecs.umich.edu
602632Sstever@eecs.umich.eduif not os.path.isdir('ext'):
612632Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 external source tree." \
622632Sstever@eecs.umich.edu          % EXT_SRCDIR
63955SN/A    sys.exit(1)
64955SN/A
65955SN/A
66955SN/A###################################################
67955SN/A#
68955SN/A# Define Configurations
693716Sstever@eecs.umich.edu#
70955SN/A# The build system infers the build options from the subdirectory name
712656Sstever@eecs.umich.edu# that the simulator is built under.  The subdirectory name must be of
722656Sstever@eecs.umich.edu# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
732656Sstever@eecs.umich.edu# (e.g., ALPHA or KERNEL) and OPT is an option (e.g., MYSQL).  The
742656Sstever@eecs.umich.edu# following code defines the standard configurations and options.
752656Sstever@eecs.umich.edu# Additional local configurations and options are read from the file
762656Sstever@eecs.umich.edu# 'local_configs' if it exists.
772656Sstever@eecs.umich.edu#
782653Sstever@eecs.umich.edu# Each base configuration or option is defined in two steps: a
792653Sstever@eecs.umich.edu# function that takes an SCons build environment and modifies it
802653Sstever@eecs.umich.edu# appropriately for that config or option, and an entry in the
812653Sstever@eecs.umich.edu# 'configs_map' or 'options_map' dictionary that maps the directory
822653Sstever@eecs.umich.edu# name string to the function.  (The directory names are all upper
832653Sstever@eecs.umich.edu# case, by convention.)
842653Sstever@eecs.umich.edu#
852653Sstever@eecs.umich.edu###################################################
862653Sstever@eecs.umich.edu
872653Sstever@eecs.umich.edu# Base non-full-system Alpha ISA configuration.
882653Sstever@eecs.umich.edudef AlphaConfig(env):
891852SN/A    env.Replace(TARGET_ISA = 'alpha')
90955SN/A    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
91955SN/A
92955SN/A# Base full-system configuration.
933717Sstever@eecs.umich.edudef KernelConfig(env):
943716Sstever@eecs.umich.edu    env.Replace(TARGET_ISA = 'alpha')
95955SN/A    env.Replace(FULL_SYSTEM = True)
961533SN/A    env.Append(CPPDEFINES = ['FULL_SYSTEM', 'SYSTEM_EV5'])
973716Sstever@eecs.umich.edu
981533SN/A# Base configurations map.
99955SN/Aconfigs_map = {
100955SN/A    'ALPHA' : AlphaConfig,
1012632Sstever@eecs.umich.edu    'KERNEL' : KernelConfig
1022632Sstever@eecs.umich.edu    }
103955SN/A
104955SN/A# Enable detailed full-system binning.
105955SN/Adef MeasureOpt(env):
106955SN/A    env.Replace(USE_MYSQL = True)
1072632Sstever@eecs.umich.edu    env.Append(CPPDEFINES = 'FS_MEASURE')
108955SN/A
1092632Sstever@eecs.umich.edu# Enable MySql database output for stats.
110955SN/Adef MySqlOpt(env):
111955SN/A    env.Replace(USE_MYSQL = True)
1122632Sstever@eecs.umich.edu
1133716Sstever@eecs.umich.edu# Disable FastAlloc object allocation.
1142632Sstever@eecs.umich.edudef NoFastAllocOpt(env):
1152632Sstever@eecs.umich.edu    env.Append(CPPDEFINES = 'NO_FAST_ALLOC')
1162632Sstever@eecs.umich.edu
1172632Sstever@eecs.umich.edu# Configuration options map.
1182632Sstever@eecs.umich.eduoptions_map = {
1192632Sstever@eecs.umich.edu    'MEASURE' : MeasureOpt,
1202632Sstever@eecs.umich.edu    'MYSQL' : MySqlOpt,
1212632Sstever@eecs.umich.edu    'NO_FAST_ALLOC' : NoFastAllocOpt
1222632Sstever@eecs.umich.edu    }
1233053Sstever@eecs.umich.edu
1243053Sstever@eecs.umich.edu# The 'local_configs' file can be used to define additional base
1253053Sstever@eecs.umich.edu# configurations and/or options without changing this file.
1263053Sstever@eecs.umich.eduif os.path.isfile('local_configs'):
1273053Sstever@eecs.umich.edu    SConscript('local_configs', exports = ['configs_map', 'options_map'])
1283053Sstever@eecs.umich.edu
1293053Sstever@eecs.umich.edu# This function parses a directory name of the form <CONFIG>[.<OPT>]*
1303053Sstever@eecs.umich.edu# and sets up the build environment appropriately.  Returns True if
1313053Sstever@eecs.umich.edu# successful, False if the base config or any of the options were not
1323053Sstever@eecs.umich.edu# defined.
1333053Sstever@eecs.umich.edudef set_dir_options(dir, env):
1343053Sstever@eecs.umich.edu    parts = dir.split('.')
1353053Sstever@eecs.umich.edu    config = parts[0]
1363053Sstever@eecs.umich.edu    opts = parts[1:]
1373053Sstever@eecs.umich.edu    try:
1383053Sstever@eecs.umich.edu        configs_map[config](env)
1392632Sstever@eecs.umich.edu        map(lambda opt: options_map[opt](env), opts)
1402632Sstever@eecs.umich.edu        return True
1412632Sstever@eecs.umich.edu    except KeyError, key:
1422632Sstever@eecs.umich.edu        print "Config/option '%s' not found." % key
1432632Sstever@eecs.umich.edu        return False
1442632Sstever@eecs.umich.edu
1452634Sstever@eecs.umich.edu# Set the default configuration and binary.  The default target (if
1462634Sstever@eecs.umich.edu# scons is invoked at the top level with no command-line targets) is
1472632Sstever@eecs.umich.edu# 'ALPHA/m5.debug'.  If scons is invoked in a subdirectory with no
1482638Sstever@eecs.umich.edu# command-line targets, the configuration
1492632Sstever@eecs.umich.edu
1502632Sstever@eecs.umich.edu###################################################
1512632Sstever@eecs.umich.edu#
1522632Sstever@eecs.umich.edu# Figure out which configurations to set up.
1532632Sstever@eecs.umich.edu#
1542632Sstever@eecs.umich.edu#
1551858SN/A# It's prohibitive to do all the combinations of base configurations
1563716Sstever@eecs.umich.edu# and options, so we have to infer which ones the user wants.
1572638Sstever@eecs.umich.edu#
1582638Sstever@eecs.umich.edu# 1. If there are command-line targets, the configuration(s) are inferred
1592638Sstever@eecs.umich.edu#    from the directories of those targets.  If scons was invoked from a
1602638Sstever@eecs.umich.edu#    subdirectory (using 'scons -u'), those targets have to be
1612638Sstever@eecs.umich.edu#    interpreted relative to that subdirectory.
1622638Sstever@eecs.umich.edu#
1632638Sstever@eecs.umich.edu# 2. If there are no command-line targets, and scons was invoked from a
1643716Sstever@eecs.umich.edu#    subdirectory (using 'scons -u'), the configuration is inferred from
1652634Sstever@eecs.umich.edu#    the name of the subdirectory.
1662634Sstever@eecs.umich.edu#
167955SN/A# 3. If there are no command-line targets and scons was invoked from
168955SN/A#    the root build directory, a default configuration is used.  The
169955SN/A#    built-in default is ALPHA, but this can be overridden by setting the
170955SN/A#    M5_DEFAULT_CONFIG shell environment veriable.
171955SN/A#
172955SN/A# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
173955SN/A# this can be overridden by setting the M5_DEFAULT_BINARY shell
174955SN/A# environment veriable.
1751858SN/A#
1761858SN/A###################################################
1772632Sstever@eecs.umich.edu
178955SN/A# Find default configuration & binary.
1793643Ssaidi@eecs.umich.edudefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA')
1803643Ssaidi@eecs.umich.edudefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1813643Ssaidi@eecs.umich.edu
1823643Ssaidi@eecs.umich.edu# Ask SCons which directory it was invoked from.  If you invoke SCons
1833643Ssaidi@eecs.umich.edu# from a subdirectory you must use the '-u' flag.
1843643Ssaidi@eecs.umich.edulaunch_dir = GetLaunchDir()
1853643Ssaidi@eecs.umich.edu
1863643Ssaidi@eecs.umich.edu# Build a list 'my_targets' of all the targets relative to ROOT.
1873716Sstever@eecs.umich.eduif launch_dir == ROOT:
1881105SN/A    # invoked from root build dir
1892667Sstever@eecs.umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
1902667Sstever@eecs.umich.edu        # easy: use specified targets as is
1912667Sstever@eecs.umich.edu        my_targets = COMMAND_LINE_TARGETS
1922667Sstever@eecs.umich.edu    else:
1932667Sstever@eecs.umich.edu        # default target (ALPHA/m5.debug, unless overridden)
1942667Sstever@eecs.umich.edu        target = os.path.join(default_config, default_binary)
1951869SN/A        my_targets = [target]
1961869SN/A        Default(target)
1971869SN/Aelse:
1981869SN/A    # invoked from subdirectory
1991869SN/A    if not launch_dir.startswith(ROOT):
2001065SN/A        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
2012632Sstever@eecs.umich.edu              (launch_dir, ROOT)
2022632Sstever@eecs.umich.edu        sys.exit(1)
203955SN/A    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
2041858SN/A    launch_dir = launch_dir[len(ROOT)+1:]
2051858SN/A    if len(COMMAND_LINE_TARGETS) != 0:
2061858SN/A        # make specified targets relative to ROOT
2071858SN/A        my_targets = map(lambda x: os.path.join(launch_dir, x),
2081851SN/A                         COMMAND_LINE_TARGETS)
2091851SN/A    else:
2101858SN/A        # build default binary (m5.debug, unless overridden) using the
2112632Sstever@eecs.umich.edu        # config inferred by the invocation directory (the first
212955SN/A        # subdirectory after ROOT)
2133053Sstever@eecs.umich.edu        target = os.path.join(launch_dir.split('/')[0], default_binary)
2143053Sstever@eecs.umich.edu        my_targets = [target]
2153053Sstever@eecs.umich.edu        Default(target)
2163053Sstever@eecs.umich.edu
2173053Sstever@eecs.umich.edu# Normalize target paths (gets rid of '..' in the middle, etc.)
2183053Sstever@eecs.umich.edumy_targets = map(os.path.normpath, my_targets)
2193053Sstever@eecs.umich.edu
2203053Sstever@eecs.umich.edu# Generate a list of the unique configs that the collected targets reference.
2213053Sstever@eecs.umich.edubuild_dirs = []
2223053Sstever@eecs.umich.edufor t in my_targets:
2233053Sstever@eecs.umich.edu    dir = t.split('/')[0]
2243053Sstever@eecs.umich.edu    if dir not in build_dirs:
2253053Sstever@eecs.umich.edu        build_dirs.append(dir)
2263053Sstever@eecs.umich.edu
2273053Sstever@eecs.umich.edu###################################################
2283053Sstever@eecs.umich.edu#
2293053Sstever@eecs.umich.edu# Set up the default build environment.  This environment is copied
2303053Sstever@eecs.umich.edu# and modified according to each selected configuration.
2313053Sstever@eecs.umich.edu#
2322667Sstever@eecs.umich.edu###################################################
2332667Sstever@eecs.umich.edu
2342667Sstever@eecs.umich.edudefault_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
2352667Sstever@eecs.umich.edu                          ROOT = ROOT,
2362667Sstever@eecs.umich.edu                          SRCDIR = SRCDIR,
2372667Sstever@eecs.umich.edu                          EXT_SRCDIR = EXT_SRCDIR,
2382667Sstever@eecs.umich.edu                          CPPDEFINES = [],
2392667Sstever@eecs.umich.edu                          FULL_SYSTEM = False,
2402667Sstever@eecs.umich.edu                          USE_MYSQL = False)
2412667Sstever@eecs.umich.edu
2422667Sstever@eecs.umich.edu# For some reason, the CC and CXX variables don't get passed into the
2432667Sstever@eecs.umich.edu# environment correctly.  This is probably some sort of scons bug that
2442638Sstever@eecs.umich.edu# will eventually be fixed.
2452638Sstever@eecs.umich.eduif os.environ.has_key('CC'):
2462638Sstever@eecs.umich.edu    default_env.Replace(CC=os.environ['CC'])
2473716Sstever@eecs.umich.edu
2483716Sstever@eecs.umich.eduif os.environ.has_key('CXX'):
2491858SN/A    default_env.Replace(CXX=os.environ['CXX'])
2503118Sstever@eecs.umich.edu
2513118Sstever@eecs.umich.edu# M5_EXT is used by isa_parser.py to find the PLY package.
2523118Sstever@eecs.umich.edudefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
2533118Sstever@eecs.umich.edu
2543118Sstever@eecs.umich.edudefault_env.Append(CCFLAGS='-pipe')
2553118Sstever@eecs.umich.edudefault_env.Append(CCFLAGS='-fno-strict-aliasing')
2563118Sstever@eecs.umich.edudefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2573118Sstever@eecs.umich.edu
2583118Sstever@eecs.umich.edu# libelf build is described in its own SConscript file.  Using a
2593118Sstever@eecs.umich.edu# dictionary for exports lets us export "default_env" so the
2603118Sstever@eecs.umich.edu# SConscript will see it as "env".  SConscript-global is the build in
2613716Sstever@eecs.umich.edu# build/libelf shared among all configs.
2623118Sstever@eecs.umich.edudefault_env.SConscript('m5/libelf/SConscript-global',
2633118Sstever@eecs.umich.edu                       exports={'env' : default_env})
2643118Sstever@eecs.umich.edu
2653118Sstever@eecs.umich.edu###################################################
2663118Sstever@eecs.umich.edu#
2673118Sstever@eecs.umich.edu# Define build environments for selected configurations.
2683118Sstever@eecs.umich.edu#
2693118Sstever@eecs.umich.edu###################################################
2703118Sstever@eecs.umich.edu
2713716Sstever@eecs.umich.edufor build_dir in build_dirs:
2723118Sstever@eecs.umich.edu    # Make a copy of the default environment to use for this config.
2733118Sstever@eecs.umich.edu    env = default_env.Copy()
2743118Sstever@eecs.umich.edu    # Modify 'env' according to the build directory config.
2753118Sstever@eecs.umich.edu    print "Configuring options for directory '%s'." % build_dir
2763118Sstever@eecs.umich.edu    if not set_dir_options(build_dir, env):
2773118Sstever@eecs.umich.edu        print "Skipping directory '%s'." % build_dir
2783118Sstever@eecs.umich.edu        continue
2793118Sstever@eecs.umich.edu
2803118Sstever@eecs.umich.edu    # The m5/SConscript file sets up the build rules in 'env' according
2813118Sstever@eecs.umich.edu    # to the configured options.
2823483Ssaidi@eecs.umich.edu    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2833494Ssaidi@eecs.umich.edu               duplicate=0)
2843494Ssaidi@eecs.umich.edu
2853483Ssaidi@eecs.umich.edu
2863483Ssaidi@eecs.umich.edu###################################################
2873483Ssaidi@eecs.umich.edu#
2883053Sstever@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
2893053Sstever@eecs.umich.edu# build enviornments to build the requested targets.
2903053Sstever@eecs.umich.edu#
2913053Sstever@eecs.umich.edu###################################################
2923053Sstever@eecs.umich.edu
2933053Sstever@eecs.umich.edu