SConstruct revision 1762
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2004-2005 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# 'ALPHA_FS/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# tell python where to find m5 python code
66955SN/Asys.path.append(os.path.join(SRCDIR, 'python'))
67955SN/A
683918Ssaidi@eecs.umich.edu
694202Sbinkertn@umich.edu###################################################
703716Sstever@eecs.umich.edu#
71955SN/A# Define Configurations
722656Sstever@eecs.umich.edu#
732656Sstever@eecs.umich.edu# The build system infers the build options from the subdirectory name
742656Sstever@eecs.umich.edu# that the simulator is built under.  The subdirectory name must be of
752656Sstever@eecs.umich.edu# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
762656Sstever@eecs.umich.edu# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL).  The
772656Sstever@eecs.umich.edu# following code defines the standard configurations and options.
782656Sstever@eecs.umich.edu# Additional local configurations and options are read from the file
792653Sstever@eecs.umich.edu# 'local_configs' if it exists.
802653Sstever@eecs.umich.edu#
812653Sstever@eecs.umich.edu# Each base configuration or option is defined in two steps: a
822653Sstever@eecs.umich.edu# function that takes an SCons build environment and modifies it
832653Sstever@eecs.umich.edu# appropriately for that config or option, and an entry in the
842653Sstever@eecs.umich.edu# 'configs_map' or 'options_map' dictionary that maps the directory
852653Sstever@eecs.umich.edu# name string to the function.  (The directory names are all upper
862653Sstever@eecs.umich.edu# case, by convention.)
872653Sstever@eecs.umich.edu#
882653Sstever@eecs.umich.edu###################################################
892653Sstever@eecs.umich.edu
901852SN/A# Base non-full-system Alpha ISA configuration.
91955SN/Adef AlphaSyscallEmulConfig(env):
92955SN/A    env.Replace(TARGET_ISA = 'alpha')
93955SN/A    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
943717Sstever@eecs.umich.edu
953716Sstever@eecs.umich.edu# Base full-system configuration.
96955SN/Adef AlphaFullSysConfig(env):
971533SN/A    env.Replace(TARGET_ISA = 'alpha')
983716Sstever@eecs.umich.edu    env.Replace(FULL_SYSTEM = True)
991533SN/A    env.Append(CPPDEFINES = ['FULL_SYSTEM'])
100955SN/A
101955SN/A# Base configurations map.
1022632Sstever@eecs.umich.educonfigs_map = {
1032632Sstever@eecs.umich.edu    'ALPHA_SE' : AlphaSyscallEmulConfig,
104955SN/A    'ALPHA_FS' : AlphaFullSysConfig
105955SN/A    }
106955SN/A
107955SN/A# Disable FastAlloc object allocation.
1082632Sstever@eecs.umich.edudef NoFastAllocOpt(env):
109955SN/A    env.Append(CPPDEFINES = 'NO_FAST_ALLOC')
1102632Sstever@eecs.umich.edu
1112632Sstever@eecs.umich.edu# Enable efence
1122632Sstever@eecs.umich.edudef EfenceOpt(env):
1132632Sstever@eecs.umich.edu    env.Append(LIBS=['efence'])
1142632Sstever@eecs.umich.edu
1152632Sstever@eecs.umich.edu# Configuration options map.
1162632Sstever@eecs.umich.eduoptions_map = {
1173053Sstever@eecs.umich.edu    'NO_FAST_ALLOC' : NoFastAllocOpt,
1183053Sstever@eecs.umich.edu    'EFENCE' : EfenceOpt
1193053Sstever@eecs.umich.edu    }
1203053Sstever@eecs.umich.edu
1213053Sstever@eecs.umich.edu# The 'local_configs' file can be used to define additional base
1223053Sstever@eecs.umich.edu# configurations and/or options without changing this file.
1233053Sstever@eecs.umich.eduif os.path.isfile('local_configs'):
1243053Sstever@eecs.umich.edu    SConscript('local_configs', exports = ['configs_map', 'options_map'])
1253053Sstever@eecs.umich.edu
1263053Sstever@eecs.umich.edu# This function parses a directory name of the form <CONFIG>[.<OPT>]*
1273053Sstever@eecs.umich.edu# and sets up the build environment appropriately.  Returns True if
1283053Sstever@eecs.umich.edu# successful, False if the base config or any of the options were not
1293053Sstever@eecs.umich.edu# defined.
1303053Sstever@eecs.umich.edudef set_dir_options(dir, env):
1313053Sstever@eecs.umich.edu    parts = dir.split('.')
1323053Sstever@eecs.umich.edu    config = parts[0]
1332632Sstever@eecs.umich.edu    opts = parts[1:]
1342632Sstever@eecs.umich.edu    try:
1352632Sstever@eecs.umich.edu        configs_map[config](env)
1362632Sstever@eecs.umich.edu        map(lambda opt: options_map[opt](env), opts)
1372632Sstever@eecs.umich.edu        return True
1382632Sstever@eecs.umich.edu    except KeyError, key:
1393718Sstever@eecs.umich.edu        print "Config/option '%s' not found." % key
1403718Sstever@eecs.umich.edu        return False
1413718Sstever@eecs.umich.edu
1423718Sstever@eecs.umich.edu# Set the default configuration and binary.  The default target (if
1433718Sstever@eecs.umich.edu# scons is invoked at the top level with no command-line targets) is
1443718Sstever@eecs.umich.edu# 'ALPHA_SE/m5.debug'.  If scons is invoked in a subdirectory with no
1453718Sstever@eecs.umich.edu# command-line targets, the configuration
1463718Sstever@eecs.umich.edu
1473718Sstever@eecs.umich.edu###################################################
1483718Sstever@eecs.umich.edu#
1493718Sstever@eecs.umich.edu# Figure out which configurations to set up.
1503718Sstever@eecs.umich.edu#
1513718Sstever@eecs.umich.edu#
1522634Sstever@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations
1532634Sstever@eecs.umich.edu# and options, so we have to infer which ones the user wants.
1542632Sstever@eecs.umich.edu#
1552638Sstever@eecs.umich.edu# 1. If there are command-line targets, the configuration(s) are inferred
1562632Sstever@eecs.umich.edu#    from the directories of those targets.  If scons was invoked from a
1572632Sstever@eecs.umich.edu#    subdirectory (using 'scons -u'), those targets have to be
1582632Sstever@eecs.umich.edu#    interpreted relative to that subdirectory.
1592632Sstever@eecs.umich.edu#
1602632Sstever@eecs.umich.edu# 2. If there are no command-line targets, and scons was invoked from a
1612632Sstever@eecs.umich.edu#    subdirectory (using 'scons -u'), the configuration is inferred from
1621858SN/A#    the name of the subdirectory.
1633716Sstever@eecs.umich.edu#
1642638Sstever@eecs.umich.edu# 3. If there are no command-line targets and scons was invoked from
1652638Sstever@eecs.umich.edu#    the root build directory, a default configuration is used.  The
1662638Sstever@eecs.umich.edu#    built-in default is ALPHA_SE, but this can be overridden by setting the
1672638Sstever@eecs.umich.edu#    M5_DEFAULT_CONFIG shell environment veriable.
1682638Sstever@eecs.umich.edu#
1692638Sstever@eecs.umich.edu# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
1702638Sstever@eecs.umich.edu# this can be overridden by setting the M5_DEFAULT_BINARY shell
1713716Sstever@eecs.umich.edu# environment veriable.
1722634Sstever@eecs.umich.edu#
1732634Sstever@eecs.umich.edu###################################################
174955SN/A
175955SN/A# Find default configuration & binary.
176955SN/Adefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
177955SN/Adefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
178955SN/A
179955SN/A# Ask SCons which directory it was invoked from.  If you invoke SCons
180955SN/A# from a subdirectory you must use the '-u' flag.
181955SN/Alaunch_dir = GetLaunchDir()
1821858SN/A
1831858SN/A# Build a list 'my_targets' of all the targets relative to ROOT.
1842632Sstever@eecs.umich.eduif launch_dir == ROOT:
185955SN/A    # invoked from root build dir
1863643Ssaidi@eecs.umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
1873643Ssaidi@eecs.umich.edu        # easy: use specified targets as is
1883643Ssaidi@eecs.umich.edu        my_targets = COMMAND_LINE_TARGETS
1893643Ssaidi@eecs.umich.edu    else:
1903643Ssaidi@eecs.umich.edu        # default target (ALPHA_SE/m5.debug, unless overridden)
1913643Ssaidi@eecs.umich.edu        target = os.path.join(default_config, default_binary)
1923643Ssaidi@eecs.umich.edu        my_targets = [target]
1933643Ssaidi@eecs.umich.edu        Default(target)
1944494Ssaidi@eecs.umich.eduelse:
1954494Ssaidi@eecs.umich.edu    # invoked from subdirectory
1963716Sstever@eecs.umich.edu    if not launch_dir.startswith(ROOT):
1971105SN/A        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
1982667Sstever@eecs.umich.edu              (launch_dir, ROOT)
1992667Sstever@eecs.umich.edu        sys.exit(1)
2002667Sstever@eecs.umich.edu    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
2012667Sstever@eecs.umich.edu    launch_dir = launch_dir[len(ROOT)+1:]
2022667Sstever@eecs.umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
2032667Sstever@eecs.umich.edu        # make specified targets relative to ROOT
2041869SN/A        my_targets = map(lambda x: os.path.join(launch_dir, x),
2051869SN/A                         COMMAND_LINE_TARGETS)
2061869SN/A    else:
2071869SN/A        # build default binary (m5.debug, unless overridden) using the
2081869SN/A        # config inferred by the invocation directory (the first
2091065SN/A        # subdirectory after ROOT)
2102632Sstever@eecs.umich.edu        target = os.path.join(launch_dir.split('/')[0], default_binary)
2112632Sstever@eecs.umich.edu        my_targets = [target]
2123918Ssaidi@eecs.umich.edu        Default(target)
2133918Ssaidi@eecs.umich.edu
2143940Ssaidi@eecs.umich.edu# Normalize target paths (gets rid of '..' in the middle, etc.)
2153918Ssaidi@eecs.umich.edumy_targets = map(os.path.normpath, my_targets)
2163918Ssaidi@eecs.umich.edu
2173918Ssaidi@eecs.umich.edu# Generate a list of the unique configs that the collected targets reference.
2183918Ssaidi@eecs.umich.edubuild_dirs = []
2193918Ssaidi@eecs.umich.edufor t in my_targets:
2203918Ssaidi@eecs.umich.edu    dir = t.split('/')[0]
2213940Ssaidi@eecs.umich.edu    if dir not in build_dirs:
2223940Ssaidi@eecs.umich.edu        build_dirs.append(dir)
2233940Ssaidi@eecs.umich.edu
2243942Ssaidi@eecs.umich.edu###################################################
2253940Ssaidi@eecs.umich.edu#
2263918Ssaidi@eecs.umich.edu# Set up the default build environment.  This environment is copied
2273918Ssaidi@eecs.umich.edu# and modified according to each selected configuration.
228955SN/A#
2291858SN/A###################################################
2303918Ssaidi@eecs.umich.edu
2313918Ssaidi@eecs.umich.edudefault_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
2323918Ssaidi@eecs.umich.edu                          ROOT = ROOT,
2333918Ssaidi@eecs.umich.edu                          SRCDIR = SRCDIR,
2343940Ssaidi@eecs.umich.edu                          EXT_SRCDIR = EXT_SRCDIR,
2353940Ssaidi@eecs.umich.edu                          CPPDEFINES = [],
2363918Ssaidi@eecs.umich.edu                          FULL_SYSTEM = False,
2373918Ssaidi@eecs.umich.edu                          ALPHA_TLASER = False,
2383918Ssaidi@eecs.umich.edu                          USE_MYSQL = False)
2393918Ssaidi@eecs.umich.edu
2403918Ssaidi@eecs.umich.edudefault_env.SConsignFile("sconsign")
2413918Ssaidi@eecs.umich.edu
2423918Ssaidi@eecs.umich.edu# For some reason, the CC and CXX variables don't get passed into the
2433918Ssaidi@eecs.umich.edu# environment correctly.  This is probably some sort of scons bug that
2443918Ssaidi@eecs.umich.edu# will eventually be fixed.
2453940Ssaidi@eecs.umich.eduif os.environ.has_key('CC'):
2463918Ssaidi@eecs.umich.edu    default_env.Replace(CC=os.environ['CC'])
2473918Ssaidi@eecs.umich.edu
2481851SN/Aif os.environ.has_key('CXX'):
2491851SN/A    default_env.Replace(CXX=os.environ['CXX'])
2501858SN/A
2512632Sstever@eecs.umich.edu# M5_EXT is used by isa_parser.py to find the PLY package.
252955SN/Adefault_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.edudefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
2583053Sstever@eecs.umich.edu
2593053Sstever@eecs.umich.edu# libelf build is described in its own SConscript file.  Using a
2603053Sstever@eecs.umich.edu# dictionary for exports lets us export "default_env" so the
2613053Sstever@eecs.umich.edu# SConscript will see it as "env".  SConscript-global is the build in
2623053Sstever@eecs.umich.edu# build/libelf shared among all configs.
2633053Sstever@eecs.umich.edudefault_env.SConscript('m5/libelf/SConscript-global',
2643053Sstever@eecs.umich.edu                       exports={'env' : default_env})
2653053Sstever@eecs.umich.edu
2663053Sstever@eecs.umich.edu###################################################
2673053Sstever@eecs.umich.edu#
2683053Sstever@eecs.umich.edu# Define build environments for selected configurations.
2693053Sstever@eecs.umich.edu#
2703053Sstever@eecs.umich.edu###################################################
2713053Sstever@eecs.umich.edu
2722667Sstever@eecs.umich.edufor build_dir in build_dirs:
2734554Sbinkertn@umich.edu    # Make a copy of the default environment to use for this config.
2744554Sbinkertn@umich.edu    env = default_env.Copy()
2752667Sstever@eecs.umich.edu    # Modify 'env' according to the build directory config.
2764554Sbinkertn@umich.edu    print "Configuring options for directory '%s'." % build_dir
2774554Sbinkertn@umich.edu    if not set_dir_options(build_dir, env):
2784554Sbinkertn@umich.edu        print "Skipping directory '%s'." % build_dir
2794554Sbinkertn@umich.edu        continue
2804554Sbinkertn@umich.edu
2814554Sbinkertn@umich.edu    # The m5/SConscript file sets up the build rules in 'env' according
2824554Sbinkertn@umich.edu    # to the configured options.
2834554Sbinkertn@umich.edu    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2844554Sbinkertn@umich.edu               duplicate=0)
2854554Sbinkertn@umich.edu
2862667Sstever@eecs.umich.edu
2874554Sbinkertn@umich.edu###################################################
2884554Sbinkertn@umich.edu#
2894554Sbinkertn@umich.edu# Let SCons do its thing.  At this point SCons will use the defined
2904554Sbinkertn@umich.edu# build environments to build the requested targets.
2912667Sstever@eecs.umich.edu#
2924554Sbinkertn@umich.edu###################################################
2932667Sstever@eecs.umich.edu
2944554Sbinkertn@umich.edu