SConstruct revision 1852
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# Check for recent-enough Python version
492632Sstever@eecs.umich.edu(major, minor) = sys.version_info[:2]
502632Sstever@eecs.umich.eduif major < 2 or (major == 2 and minor < 3):
512761Sstever@eecs.umich.edu    print "Error: M5 requires Python 2.3 or later."
522761Sstever@eecs.umich.edu    sys.exit(1)
532761Sstever@eecs.umich.edu
542761Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives).
552761Sstever@eecs.umich.eduROOT = Dir('.').abspath
562632Sstever@eecs.umich.edu
572632Sstever@eecs.umich.edu# Paths to the M5 and external source trees (local symlinks).
582632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'm5')
592632Sstever@eecs.umich.eduEXT_SRCDIR = os.path.join(ROOT, 'ext')
602632Sstever@eecs.umich.edu
612632Sstever@eecs.umich.edu# Check for 'm5' and 'ext' links, die if they don't exist.
622632Sstever@eecs.umich.eduif not os.path.isdir(SRCDIR):
63955SN/A    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
64955SN/A    sys.exit(1)
65955SN/A
66955SN/Aif not os.path.isdir('ext'):
67955SN/A    print "Error: '%s' must be a link to the M5 external source tree." \
68955SN/A          % EXT_SRCDIR
69955SN/A    sys.exit(1)
702656Sstever@eecs.umich.edu
712656Sstever@eecs.umich.edu# tell python where to find m5 python code
722656Sstever@eecs.umich.edusys.path.append(os.path.join(SRCDIR, 'python'))
732656Sstever@eecs.umich.edu
742656Sstever@eecs.umich.edu
752656Sstever@eecs.umich.edu###################################################
762656Sstever@eecs.umich.edu#
772653Sstever@eecs.umich.edu# Define Configurations
782653Sstever@eecs.umich.edu#
792653Sstever@eecs.umich.edu# The build system infers the build options from the subdirectory name
802653Sstever@eecs.umich.edu# that the simulator is built under.  The subdirectory name must be of
812653Sstever@eecs.umich.edu# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
822653Sstever@eecs.umich.edu# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL).  The
832653Sstever@eecs.umich.edu# following code defines the standard configurations and options.
842653Sstever@eecs.umich.edu# Additional local configurations and options are read from the file
852653Sstever@eecs.umich.edu# 'local_configs' if it exists.
862653Sstever@eecs.umich.edu#
872653Sstever@eecs.umich.edu# Each base configuration or option is defined in two steps: a
881852SN/A# function that takes an SCons build environment and modifies it
89955SN/A# appropriately for that config or option, and an entry in the
90955SN/A# 'configs_map' or 'options_map' dictionary that maps the directory
91955SN/A# name string to the function.  (The directory names are all upper
922632Sstever@eecs.umich.edu# case, by convention.)
932632Sstever@eecs.umich.edu#
94955SN/A###################################################
951533SN/A
962632Sstever@eecs.umich.edu# Base non-full-system Alpha ISA configuration.
971533SN/Adef AlphaSyscallEmulConfig(env):
98955SN/A    env.Replace(TARGET_ISA = 'alpha')
99955SN/A    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
1002632Sstever@eecs.umich.edu
1012632Sstever@eecs.umich.edu# Base full-system configuration.
102955SN/Adef AlphaFullSysConfig(env):
103955SN/A    env.Replace(TARGET_ISA = 'alpha')
104955SN/A    env.Replace(FULL_SYSTEM = True)
105955SN/A    env.Append(CPPDEFINES = ['FULL_SYSTEM'])
1062632Sstever@eecs.umich.edu
107955SN/A# Base configurations map.
1082632Sstever@eecs.umich.educonfigs_map = {
109955SN/A    'ALPHA_SE' : AlphaSyscallEmulConfig,
110955SN/A    'ALPHA_FS' : AlphaFullSysConfig
1112632Sstever@eecs.umich.edu    }
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
1172632Sstever@eecs.umich.edu# Enable efence
1182632Sstever@eecs.umich.edudef EfenceOpt(env):
1192632Sstever@eecs.umich.edu    env.Append(LIBS=['efence'])
1202632Sstever@eecs.umich.edu
1212632Sstever@eecs.umich.edu# Configuration options map.
1223053Sstever@eecs.umich.eduoptions_map = {
1233053Sstever@eecs.umich.edu    'NO_FAST_ALLOC' : NoFastAllocOpt,
1243053Sstever@eecs.umich.edu    'EFENCE' : EfenceOpt
1253053Sstever@eecs.umich.edu    }
1263053Sstever@eecs.umich.edu
1273053Sstever@eecs.umich.edu# The 'local_configs' file can be used to define additional base
1283053Sstever@eecs.umich.edu# configurations and/or options without changing this file.
1293053Sstever@eecs.umich.eduif os.path.isfile('local_configs'):
1303053Sstever@eecs.umich.edu    SConscript('local_configs', exports = ['configs_map', 'options_map'])
1313053Sstever@eecs.umich.edu
1323053Sstever@eecs.umich.edu# This function parses a directory name of the form <CONFIG>[.<OPT>]*
1333053Sstever@eecs.umich.edu# and sets up the build environment appropriately.  Returns True if
1343053Sstever@eecs.umich.edu# successful, False if the base config or any of the options were not
1353053Sstever@eecs.umich.edu# defined.
1363053Sstever@eecs.umich.edudef set_dir_options(dir, env):
1373053Sstever@eecs.umich.edu    parts = dir.split('.')
1382632Sstever@eecs.umich.edu    config = parts[0]
1392632Sstever@eecs.umich.edu    opts = parts[1:]
1402632Sstever@eecs.umich.edu    try:
1412632Sstever@eecs.umich.edu        configs_map[config](env)
1422632Sstever@eecs.umich.edu        map(lambda opt: options_map[opt](env), opts)
1432632Sstever@eecs.umich.edu        return True
1442634Sstever@eecs.umich.edu    except KeyError, key:
1452634Sstever@eecs.umich.edu        print "Config/option '%s' not found." % key
1462632Sstever@eecs.umich.edu        return False
1472638Sstever@eecs.umich.edu
1482632Sstever@eecs.umich.edu# Set the default configuration and binary.  The default target (if
1492632Sstever@eecs.umich.edu# scons is invoked at the top level with no command-line targets) is
1502632Sstever@eecs.umich.edu# 'ALPHA_SE/m5.debug'.  If scons is invoked in a subdirectory with no
1512632Sstever@eecs.umich.edu# command-line targets, the configuration
1522632Sstever@eecs.umich.edu
1532632Sstever@eecs.umich.edu###################################################
1541858SN/A#
1552638Sstever@eecs.umich.edu# Figure out which configurations to set up.
1562638Sstever@eecs.umich.edu#
1572638Sstever@eecs.umich.edu#
1582638Sstever@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations
1592638Sstever@eecs.umich.edu# and options, so we have to infer which ones the user wants.
1602638Sstever@eecs.umich.edu#
1612638Sstever@eecs.umich.edu# 1. If there are command-line targets, the configuration(s) are inferred
1622638Sstever@eecs.umich.edu#    from the directories of those targets.  If scons was invoked from a
1632634Sstever@eecs.umich.edu#    subdirectory (using 'scons -u'), those targets have to be
1642634Sstever@eecs.umich.edu#    interpreted relative to that subdirectory.
1652634Sstever@eecs.umich.edu#
166955SN/A# 2. If there are no command-line targets, and scons was invoked from a
167955SN/A#    subdirectory (using 'scons -u'), the configuration is inferred from
168955SN/A#    the name of the subdirectory.
169955SN/A#
170955SN/A# 3. If there are no command-line targets and scons was invoked from
171955SN/A#    the root build directory, a default configuration is used.  The
172955SN/A#    built-in default is ALPHA_SE, but this can be overridden by setting the
173955SN/A#    M5_DEFAULT_CONFIG shell environment veriable.
1741858SN/A#
1751858SN/A# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
1762632Sstever@eecs.umich.edu# this can be overridden by setting the M5_DEFAULT_BINARY shell
177955SN/A# environment veriable.
1782776Sstever@eecs.umich.edu#
1791105SN/A###################################################
1802667Sstever@eecs.umich.edu
1812667Sstever@eecs.umich.edu# Find default configuration & binary.
1822667Sstever@eecs.umich.edudefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
1832667Sstever@eecs.umich.edudefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1842667Sstever@eecs.umich.edu
1852667Sstever@eecs.umich.edu# Ask SCons which directory it was invoked from.  If you invoke SCons
1861869SN/A# from a subdirectory you must use the '-u' flag.
1871869SN/Alaunch_dir = GetLaunchDir()
1881869SN/A
1891869SN/A# Build a list 'my_targets' of all the targets relative to ROOT.
1901869SN/Aif launch_dir == ROOT:
1911065SN/A    # invoked from root build dir
1922632Sstever@eecs.umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
1932632Sstever@eecs.umich.edu        # easy: use specified targets as is
194955SN/A        my_targets = COMMAND_LINE_TARGETS
1951858SN/A    else:
1961858SN/A        # default target (ALPHA_SE/m5.debug, unless overridden)
1971858SN/A        target = os.path.join(default_config, default_binary)
1981858SN/A        my_targets = [target]
1991851SN/A        Default(target)
2001851SN/Aelse:
2011858SN/A    # invoked from subdirectory
2022632Sstever@eecs.umich.edu    if not launch_dir.startswith(ROOT):
203955SN/A        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
2043053Sstever@eecs.umich.edu              (launch_dir, ROOT)
2053053Sstever@eecs.umich.edu        sys.exit(1)
2063053Sstever@eecs.umich.edu    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
2073053Sstever@eecs.umich.edu    launch_dir = launch_dir[len(ROOT)+1:]
2083053Sstever@eecs.umich.edu    if len(COMMAND_LINE_TARGETS) != 0:
2093053Sstever@eecs.umich.edu        # make specified targets relative to ROOT
2103053Sstever@eecs.umich.edu        my_targets = map(lambda x: os.path.join(launch_dir, x),
2113053Sstever@eecs.umich.edu                         COMMAND_LINE_TARGETS)
2123053Sstever@eecs.umich.edu    else:
2133053Sstever@eecs.umich.edu        # build default binary (m5.debug, unless overridden) using the
2143053Sstever@eecs.umich.edu        # config inferred by the invocation directory (the first
2153053Sstever@eecs.umich.edu        # subdirectory after ROOT)
2163053Sstever@eecs.umich.edu        target = os.path.join(launch_dir.split('/')[0], default_binary)
2173053Sstever@eecs.umich.edu        my_targets = [target]
2183053Sstever@eecs.umich.edu        Default(target)
2193053Sstever@eecs.umich.edu
2203053Sstever@eecs.umich.edu# Normalize target paths (gets rid of '..' in the middle, etc.)
2213053Sstever@eecs.umich.edumy_targets = map(os.path.normpath, my_targets)
2223053Sstever@eecs.umich.edu
2232667Sstever@eecs.umich.edu# Generate a list of the unique configs that the collected targets reference.
2242667Sstever@eecs.umich.edubuild_dirs = []
2252667Sstever@eecs.umich.edufor t in my_targets:
2262667Sstever@eecs.umich.edu    dir = t.split('/')[0]
2272667Sstever@eecs.umich.edu    if dir not in build_dirs:
2282667Sstever@eecs.umich.edu        build_dirs.append(dir)
2292667Sstever@eecs.umich.edu
2302667Sstever@eecs.umich.edu###################################################
2312667Sstever@eecs.umich.edu#
2322667Sstever@eecs.umich.edu# Set up the default build environment.  This environment is copied
2332667Sstever@eecs.umich.edu# and modified according to each selected configuration.
2342667Sstever@eecs.umich.edu#
2352638Sstever@eecs.umich.edu###################################################
2362638Sstever@eecs.umich.edu
2372638Sstever@eecs.umich.edudefault_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
2382638Sstever@eecs.umich.edu                          ROOT = ROOT,
2392638Sstever@eecs.umich.edu                          SRCDIR = SRCDIR,
2401858SN/A                          EXT_SRCDIR = EXT_SRCDIR,
2413118Sstever@eecs.umich.edu                          CPPDEFINES = [],
2423118Sstever@eecs.umich.edu                          FULL_SYSTEM = False,
2433118Sstever@eecs.umich.edu                          ALPHA_TLASER = False,
2443118Sstever@eecs.umich.edu                          USE_MYSQL = False)
2453118Sstever@eecs.umich.edu
2463118Sstever@eecs.umich.edudefault_env.SConsignFile("sconsign")
2473118Sstever@eecs.umich.edu
2483118Sstever@eecs.umich.edu# For some reason, the CC and CXX variables don't get passed into the
2493118Sstever@eecs.umich.edu# environment correctly.  This is probably some sort of scons bug that
2503118Sstever@eecs.umich.edu# will eventually be fixed.
2513118Sstever@eecs.umich.eduif os.environ.has_key('CC'):
2523118Sstever@eecs.umich.edu    default_env.Replace(CC=os.environ['CC'])
2533118Sstever@eecs.umich.edu
2543118Sstever@eecs.umich.eduif os.environ.has_key('CXX'):
2553118Sstever@eecs.umich.edu    default_env.Replace(CXX=os.environ['CXX'])
2563118Sstever@eecs.umich.edu
2573118Sstever@eecs.umich.edu# M5_EXT is used by isa_parser.py to find the PLY package.
2583118Sstever@eecs.umich.edudefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
2593118Sstever@eecs.umich.edu
2603118Sstever@eecs.umich.edudefault_env.Append(CCFLAGS='-pipe')
2613118Sstever@eecs.umich.edudefault_env.Append(CCFLAGS='-fno-strict-aliasing')
2623118Sstever@eecs.umich.edudefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2633118Sstever@eecs.umich.eduif sys.platform == 'cygwin':
2643118Sstever@eecs.umich.edu    # cygwin has some header file issues...
2653118Sstever@eecs.umich.edu    default_env.Append(CCFLAGS=Split("-Wno-uninitialized"))
2663118Sstever@eecs.umich.edudefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
2673118Sstever@eecs.umich.edu
2683118Sstever@eecs.umich.edu# libelf build is described in its own SConscript file.  Using a
2693118Sstever@eecs.umich.edu# dictionary for exports lets us export "default_env" so the
2703118Sstever@eecs.umich.edu# SConscript will see it as "env".  SConscript-global is the build in
2713118Sstever@eecs.umich.edu# build/libelf shared among all configs.
2723118Sstever@eecs.umich.edudefault_env.SConscript('m5/libelf/SConscript-global',
2733483Ssaidi@eecs.umich.edu                       exports={'env' : default_env})
2743494Ssaidi@eecs.umich.edu
2753494Ssaidi@eecs.umich.edu###################################################
2763483Ssaidi@eecs.umich.edu#
2773483Ssaidi@eecs.umich.edu# Define build environments for selected configurations.
2783483Ssaidi@eecs.umich.edu#
2793053Sstever@eecs.umich.edu###################################################
2803053Sstever@eecs.umich.edu
2813053Sstever@eecs.umich.edufor build_dir in build_dirs:
2823053Sstever@eecs.umich.edu    # Make a copy of the default environment to use for this config.
2833053Sstever@eecs.umich.edu    env = default_env.Copy()
2843053Sstever@eecs.umich.edu    # Modify 'env' according to the build directory config.
2853053Sstever@eecs.umich.edu    print "Configuring options for directory '%s'." % build_dir
2863053Sstever@eecs.umich.edu    if not set_dir_options(build_dir, env):
2871858SN/A        print "Skipping directory '%s'." % build_dir
2881858SN/A        continue
2891858SN/A
2901858SN/A    # The m5/SConscript file sets up the build rules in 'env' according
2911858SN/A    # to the configured options.
2921858SN/A    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2931859SN/A               duplicate=0)
2941858SN/A
2951858SN/A
2961858SN/A###################################################
2971859SN/A#
2981859SN/A# Let SCons do its thing.  At this point SCons will use the defined
2991862SN/A# build environments to build the requested targets.
3003053Sstever@eecs.umich.edu#
3013053Sstever@eecs.umich.edu###################################################
3023053Sstever@eecs.umich.edu
3033053Sstever@eecs.umich.edu