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
693918Ssaidi@eecs.umich.edu#
703716Sstever@eecs.umich.edu# The build system infers the build options from the subdirectory name
71955SN/A# 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#
782656Sstever@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):
892653Sstever@eecs.umich.edu    env.Replace(TARGET_ISA = 'alpha')
901852SN/A    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
91955SN/A
92955SN/A# Base full-system configuration.
93955SN/Adef KernelConfig(env):
943717Sstever@eecs.umich.edu    env.Replace(TARGET_ISA = 'alpha')
953716Sstever@eecs.umich.edu    env.Replace(FULL_SYSTEM = True)
96955SN/A    env.Append(CPPDEFINES = ['FULL_SYSTEM', 'SYSTEM_EV5'])
971533SN/A
983716Sstever@eecs.umich.edu# Base configurations map.
991533SN/Aconfigs_map = {
100955SN/A    'ALPHA' : AlphaConfig,
101955SN/A    'KERNEL' : KernelConfig
1022632Sstever@eecs.umich.edu    }
1032632Sstever@eecs.umich.edu
104955SN/A# Enable detailed full-system binning.
105955SN/Adef MeasureOpt(env):
106955SN/A    env.Replace(USE_MYSQL = True)
107955SN/A    env.Append(CPPDEFINES = 'FS_MEASURE')
1082632Sstever@eecs.umich.edu
109955SN/A# Enable MySql database output for stats.
1102632Sstever@eecs.umich.edudef MySqlOpt(env):
1112632Sstever@eecs.umich.edu    env.Replace(USE_MYSQL = True)
1122632Sstever@eecs.umich.edu
1132632Sstever@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
1173053Sstever@eecs.umich.edu# Configuration options map.
1183053Sstever@eecs.umich.eduoptions_map = {
1193053Sstever@eecs.umich.edu    'MEASURE' : MeasureOpt,
1203053Sstever@eecs.umich.edu    'MYSQL' : MySqlOpt,
1213053Sstever@eecs.umich.edu    'NO_FAST_ALLOC' : NoFastAllocOpt
1223053Sstever@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.
1332632Sstever@eecs.umich.edudef set_dir_options(dir, env):
1342632Sstever@eecs.umich.edu    parts = dir.split('.')
1352632Sstever@eecs.umich.edu    config = parts[0]
1362632Sstever@eecs.umich.edu    opts = parts[1:]
1372632Sstever@eecs.umich.edu    try:
1382632Sstever@eecs.umich.edu        configs_map[config](env)
1393718Sstever@eecs.umich.edu        map(lambda opt: options_map[opt](env), opts)
1403718Sstever@eecs.umich.edu        return True
1413718Sstever@eecs.umich.edu    except KeyError, key:
1423718Sstever@eecs.umich.edu        print "Config/option '%s' not found." % key
1433718Sstever@eecs.umich.edu        return False
1443718Sstever@eecs.umich.edu
1453718Sstever@eecs.umich.edu# Set the default configuration and binary.  The default target (if
1463718Sstever@eecs.umich.edu# scons is invoked at the top level with no command-line targets) is
1473718Sstever@eecs.umich.edu# 'ALPHA/m5.debug'.  If scons is invoked in a subdirectory with no
1483718Sstever@eecs.umich.edu# command-line targets, the configuration
1493718Sstever@eecs.umich.edu
1503718Sstever@eecs.umich.edu###################################################
1513718Sstever@eecs.umich.edu#
1522634Sstever@eecs.umich.edu# Figure out which configurations to set up.
1532634Sstever@eecs.umich.edu#
1542632Sstever@eecs.umich.edu#
1552638Sstever@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations
1562632Sstever@eecs.umich.edu# and options, so we have to infer which ones the user wants.
1572632Sstever@eecs.umich.edu#
1582632Sstever@eecs.umich.edu# 1. If there are command-line targets, the configuration(s) are inferred
1592632Sstever@eecs.umich.edu#    from the directories of those targets.  If scons was invoked from a
1602632Sstever@eecs.umich.edu#    subdirectory (using 'scons -u'), those targets have to be
1612632Sstever@eecs.umich.edu#    interpreted relative to that subdirectory.
1621858SN/A#
1633716Sstever@eecs.umich.edu# 2. If there are no command-line targets, and scons was invoked from a
1642638Sstever@eecs.umich.edu#    subdirectory (using 'scons -u'), the configuration is inferred from
1652638Sstever@eecs.umich.edu#    the name of the subdirectory.
1662638Sstever@eecs.umich.edu#
1672638Sstever@eecs.umich.edu# 3. If there are no command-line targets and scons was invoked from
1682638Sstever@eecs.umich.edu#    the root build directory, a default configuration is used.  The
1692638Sstever@eecs.umich.edu#    built-in default is ALPHA, but this can be overridden by setting the
1702638Sstever@eecs.umich.edu#    M5_DEFAULT_CONFIG shell environment veriable.
1713716Sstever@eecs.umich.edu#
1722634Sstever@eecs.umich.edu# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
1732634Sstever@eecs.umich.edu# this can be overridden by setting the M5_DEFAULT_BINARY shell
174955SN/A# environment veriable.
175955SN/A#
176955SN/A###################################################
177955SN/A
178955SN/A# Find default configuration & binary.
179955SN/Adefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA')
180955SN/Adefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
181955SN/A
1821858SN/A# Ask SCons which directory it was invoked from.  If you invoke SCons
1831858SN/A# from a subdirectory you must use the '-u' flag.
1842632Sstever@eecs.umich.edulaunch_dir = GetLaunchDir()
185955SN/A
1863643Ssaidi@eecs.umich.edu# Build a list 'my_targets' of all the targets relative to ROOT.
1873643Ssaidi@eecs.umich.eduif launch_dir == ROOT:
1883643Ssaidi@eecs.umich.edu    # invoked from root build dir
1893643Ssaidi@eecs.umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
1903643Ssaidi@eecs.umich.edu        # easy: use specified targets as is
1913643Ssaidi@eecs.umich.edu        my_targets = COMMAND_LINE_TARGETS
1923643Ssaidi@eecs.umich.edu    else:
1933643Ssaidi@eecs.umich.edu        # default target (ALPHA/m5.debug, unless overridden)
1943716Sstever@eecs.umich.edu        target = os.path.join(default_config, default_binary)
1951105SN/A        my_targets = [target]
1962667Sstever@eecs.umich.edu        Default(target)
1972667Sstever@eecs.umich.eduelse:
1982667Sstever@eecs.umich.edu    # invoked from subdirectory
1992667Sstever@eecs.umich.edu    if not launch_dir.startswith(ROOT):
2002667Sstever@eecs.umich.edu        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
2012667Sstever@eecs.umich.edu              (launch_dir, ROOT)
2021869SN/A        sys.exit(1)
2031869SN/A    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
2041869SN/A    launch_dir = launch_dir[len(ROOT)+1:]
2051869SN/A    if len(COMMAND_LINE_TARGETS) != 0:
2061869SN/A        # make specified targets relative to ROOT
2071065SN/A        my_targets = map(lambda x: os.path.join(launch_dir, x),
2082632Sstever@eecs.umich.edu                         COMMAND_LINE_TARGETS)
2092632Sstever@eecs.umich.edu    else:
2103918Ssaidi@eecs.umich.edu        # build default binary (m5.debug, unless overridden) using the
2113918Ssaidi@eecs.umich.edu        # config inferred by the invocation directory (the first
2123940Ssaidi@eecs.umich.edu        # subdirectory after ROOT)
2133918Ssaidi@eecs.umich.edu        target = os.path.join(launch_dir.split('/')[0], default_binary)
2143918Ssaidi@eecs.umich.edu        my_targets = [target]
2153918Ssaidi@eecs.umich.edu        Default(target)
2163918Ssaidi@eecs.umich.edu
2173918Ssaidi@eecs.umich.edu# Normalize target paths (gets rid of '..' in the middle, etc.)
2183918Ssaidi@eecs.umich.edumy_targets = map(os.path.normpath, my_targets)
2193940Ssaidi@eecs.umich.edu
2203940Ssaidi@eecs.umich.edu# Generate a list of the unique configs that the collected targets reference.
2213940Ssaidi@eecs.umich.edubuild_dirs = []
2223942Ssaidi@eecs.umich.edufor t in my_targets:
2233940Ssaidi@eecs.umich.edu    dir = t.split('/')[0]
2243918Ssaidi@eecs.umich.edu    if dir not in build_dirs:
2253918Ssaidi@eecs.umich.edu        build_dirs.append(dir)
226955SN/A
2271858SN/A###################################################
2283918Ssaidi@eecs.umich.edu#
2293918Ssaidi@eecs.umich.edu# Set up the default build environment.  This environment is copied
2303918Ssaidi@eecs.umich.edu# and modified according to each selected configuration.
2313918Ssaidi@eecs.umich.edu#
2323940Ssaidi@eecs.umich.edu###################################################
2333940Ssaidi@eecs.umich.edu
2343918Ssaidi@eecs.umich.edudefault_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
2353918Ssaidi@eecs.umich.edu                          ROOT = ROOT,
2363918Ssaidi@eecs.umich.edu                          SRCDIR = SRCDIR,
2373918Ssaidi@eecs.umich.edu                          EXT_SRCDIR = EXT_SRCDIR,
2383918Ssaidi@eecs.umich.edu                          CPPDEFINES = [],
2393918Ssaidi@eecs.umich.edu                          FULL_SYSTEM = False,
2403918Ssaidi@eecs.umich.edu                          USE_MYSQL = False)
2413918Ssaidi@eecs.umich.edu
2423918Ssaidi@eecs.umich.edu# For some reason, the CC and CXX variables don't get passed into the
2433940Ssaidi@eecs.umich.edu# environment correctly.  This is probably some sort of scons bug that
2443918Ssaidi@eecs.umich.edu# will eventually be fixed.
2453918Ssaidi@eecs.umich.eduif os.environ.has_key('CC'):
2461851SN/A    default_env.Replace(CC=os.environ['CC'])
2471851SN/A
2481858SN/Aif os.environ.has_key('CXX'):
2492632Sstever@eecs.umich.edu    default_env.Replace(CXX=os.environ['CXX'])
250955SN/A
2513053Sstever@eecs.umich.edu# M5_EXT is used by isa_parser.py to find the PLY package.
2523053Sstever@eecs.umich.edudefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
2533053Sstever@eecs.umich.edu
2543053Sstever@eecs.umich.edudefault_env.Append(CCFLAGS='-pipe')
2553053Sstever@eecs.umich.edudefault_env.Append(CCFLAGS='-fno-strict-aliasing')
2563053Sstever@eecs.umich.edudefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2573053Sstever@eecs.umich.edu
2583053Sstever@eecs.umich.edu# libelf build is described in its own SConscript file.  Using a
2593053Sstever@eecs.umich.edu# dictionary for exports lets us export "default_env" so the
2603053Sstever@eecs.umich.edu# SConscript will see it as "env".  SConscript-global is the build in
2613053Sstever@eecs.umich.edu# build/libelf shared among all configs.
2623053Sstever@eecs.umich.edudefault_env.SConscript('m5/libelf/SConscript-global',
2633053Sstever@eecs.umich.edu                       exports={'env' : default_env})
2643053Sstever@eecs.umich.edu
2653053Sstever@eecs.umich.edu###################################################
2663053Sstever@eecs.umich.edu#
2673053Sstever@eecs.umich.edu# Define build environments for selected configurations.
2683053Sstever@eecs.umich.edu#
2693053Sstever@eecs.umich.edu###################################################
2702667Sstever@eecs.umich.edu
2712667Sstever@eecs.umich.edufor build_dir in build_dirs:
2722667Sstever@eecs.umich.edu    # Make a copy of the default environment to use for this config.
2732667Sstever@eecs.umich.edu    env = default_env.Copy()
2742667Sstever@eecs.umich.edu    # Modify 'env' according to the build directory config.
2752667Sstever@eecs.umich.edu    print "Configuring options for directory '%s'." % build_dir
2762667Sstever@eecs.umich.edu    if not set_dir_options(build_dir, env):
2772667Sstever@eecs.umich.edu        print "Skipping directory '%s'." % build_dir
2782667Sstever@eecs.umich.edu        continue
2792667Sstever@eecs.umich.edu
2802667Sstever@eecs.umich.edu    # The m5/SConscript file sets up the build rules in 'env' according
2812667Sstever@eecs.umich.edu    # to the configured options.
2822638Sstever@eecs.umich.edu    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2832638Sstever@eecs.umich.edu               duplicate=0)
2842638Sstever@eecs.umich.edu
2853716Sstever@eecs.umich.edu
2863716Sstever@eecs.umich.edu###################################################
2871858SN/A#
2883118Sstever@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
2893118Sstever@eecs.umich.edu# build enviornments to build the requested targets.
2903118Sstever@eecs.umich.edu#
2913118Sstever@eecs.umich.edu###################################################
2923118Sstever@eecs.umich.edu
2933118Sstever@eecs.umich.edu