SConstruct revision 1105
1955SN/A# -*- mode:python -*-
2955SN/A
37816Ssteve.reinhardt@amd.com# Copyright (c) 2004 The Regents of The University of Michigan
45871Snate@binkert.org# All rights reserved.
51762SN/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.
28955SN/A
29955SN/A###################################################
302665Ssaidi@eecs.umich.edu#
312665Ssaidi@eecs.umich.edu# SCons top-level build description (SConstruct) file.
325863Snate@binkert.org#
33955SN/A# To build M5, you need a directory with three things:
34955SN/A# 1. A copy of this file (named SConstruct).
35955SN/A# 2. A link named 'm5' to the top of the M5 simulator source tree.
36955SN/A# 3. A link named 'ext' to the top of the M5 external source tree.
37955SN/A#
382632Sstever@eecs.umich.edu# Then type 'scons' to build the default configuration (see below), or
392632Sstever@eecs.umich.edu# '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#
42955SN/A###################################################
432632Sstever@eecs.umich.edu
442632Sstever@eecs.umich.edu# Python library imports
452761Sstever@eecs.umich.eduimport sys
462632Sstever@eecs.umich.eduimport os
472632Sstever@eecs.umich.edu
482632Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives).
492761Sstever@eecs.umich.eduROOT = Dir('.').abspath
502761Sstever@eecs.umich.edu
512761Sstever@eecs.umich.edu# Paths to the M5 and external source trees (local symlinks).
522632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'm5')
532632Sstever@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.
562761Sstever@eecs.umich.eduif not os.path.isdir(SRCDIR):
572761Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
582761Sstever@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
632632Sstever@eecs.umich.edu    sys.exit(1)
642632Sstever@eecs.umich.edu
652632Sstever@eecs.umich.edu
66955SN/A###################################################
67955SN/A#
68955SN/A# Define Configurations
695863Snate@binkert.org#
705863Snate@binkert.org# The build system infers the build options from the subdirectory name
715863Snate@binkert.org# that the simulator is built under.  The subdirectory name must be of
725863Snate@binkert.org# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
735863Snate@binkert.org# (e.g., ALPHA or KERNEL) and OPT is an option (e.g., MYSQL).  The
745863Snate@binkert.org# following code defines the standard configurations and options.
755863Snate@binkert.org# Additional local configurations and options are read from the file
765863Snate@binkert.org# 'local_configs' if it exists.
775863Snate@binkert.org#
785863Snate@binkert.org# Each base configuration or option is defined in two steps: a
795863Snate@binkert.org# function that takes an SCons build environment and modifies it
805863Snate@binkert.org# appropriately for that config or option, and an entry in the
815863Snate@binkert.org# 'configs_map' or 'options_map' dictionary that maps the directory
825863Snate@binkert.org# name string to the function.  (The directory names are all upper
835863Snate@binkert.org# case, by convention.)
845863Snate@binkert.org#
855863Snate@binkert.org###################################################
865863Snate@binkert.org
875863Snate@binkert.org# Base non-full-system Alpha ISA configuration.
885863Snate@binkert.orgdef AlphaConfig(env):
895863Snate@binkert.org    env.Replace(TARGET_ISA = 'alpha')
905863Snate@binkert.org    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
915863Snate@binkert.org
925863Snate@binkert.org# Base full-system configuration.
935863Snate@binkert.orgdef KernelConfig(env):
945863Snate@binkert.org    env.Replace(TARGET_ISA = 'alpha')
955863Snate@binkert.org    env.Replace(FULL_SYSTEM = True)
965863Snate@binkert.org    env.Append(CPPDEFINES = ['FULL_SYSTEM', 'SYSTEM_EV5'])
975863Snate@binkert.org
985863Snate@binkert.org# Base configurations map.
995863Snate@binkert.orgconfigs_map = {
1006654Snate@binkert.org    'ALPHA' : AlphaConfig,
101955SN/A    'KERNEL' : KernelConfig
1025396Ssaidi@eecs.umich.edu    }
1035863Snate@binkert.org
1045863Snate@binkert.org# Enable detailed full-system binning.
1054202Sbinkertn@umich.edudef MeasureOpt(env):
1065863Snate@binkert.org    env.Replace(USE_MYSQL = True)
1075863Snate@binkert.org    env.Append(CPPDEFINES = 'FS_MEASURE')
1085863Snate@binkert.org
1095863Snate@binkert.org# Enable MySql database output for stats.
110955SN/Adef MySqlOpt(env):
1116654Snate@binkert.org    env.Replace(USE_MYSQL = True)
1125273Sstever@gmail.com
1135871Snate@binkert.org# Disable FastAlloc object allocation.
1145273Sstever@gmail.comdef NoFastAllocOpt(env):
1156655Snate@binkert.org    env.Append(CPPDEFINES = 'NO_FAST_ALLOC')
1166655Snate@binkert.org
1176655Snate@binkert.org# Configuration options map.
1186655Snate@binkert.orgoptions_map = {
1196655Snate@binkert.org    'MEASURE' : MeasureOpt,
1206655Snate@binkert.org    'MYSQL' : MySqlOpt,
1215871Snate@binkert.org    'NO_FAST_ALLOC' : NoFastAllocOpt
1226654Snate@binkert.org    }
1235396Ssaidi@eecs.umich.edu
1247816Ssteve.reinhardt@amd.com# The 'local_configs' file can be used to define additional base
1257816Ssteve.reinhardt@amd.com# configurations and/or options without changing this file.
1267816Ssteve.reinhardt@amd.comif os.path.isfile('local_configs'):
1277816Ssteve.reinhardt@amd.com    SConscript('local_configs', exports = ['configs_map', 'options_map'])
1287816Ssteve.reinhardt@amd.com
1297816Ssteve.reinhardt@amd.com# This function parses a directory name of the form <CONFIG>[.<OPT>]*
1307816Ssteve.reinhardt@amd.com# and sets up the build environment appropriately.  Returns True if
1317816Ssteve.reinhardt@amd.com# successful, False if the base config or any of the options were not
1327816Ssteve.reinhardt@amd.com# defined.
1337816Ssteve.reinhardt@amd.comdef set_dir_options(dir, env):
1347816Ssteve.reinhardt@amd.com    parts = dir.split('.')
1357816Ssteve.reinhardt@amd.com    config = parts[0]
1365871Snate@binkert.org    opts = parts[1:]
1375871Snate@binkert.org    try:
1386121Snate@binkert.org        configs_map[config](env)
1395871Snate@binkert.org        map(lambda opt: options_map[opt](env), opts)
1405871Snate@binkert.org        return True
1416003Snate@binkert.org    except KeyError, key:
1426655Snate@binkert.org        print "Config/option '%s' not found." % key
143955SN/A        return False
1445871Snate@binkert.org
1455871Snate@binkert.org# Set the default configuration and binary.  The default target (if
1465871Snate@binkert.org# scons is invoked at the top level with no command-line targets) is
1475871Snate@binkert.org# 'ALPHA/m5.debug'.  If scons is invoked in a subdirectory with no
148955SN/A# command-line targets, the configuration
1496121Snate@binkert.org
1506121Snate@binkert.org###################################################
1516121Snate@binkert.org#
1521533SN/A# Figure out which configurations to set up.
1536655Snate@binkert.org#
1546655Snate@binkert.org#
1556655Snate@binkert.org# It's prohibitive to do all the combinations of base configurations
1566655Snate@binkert.org# and options, so we have to infer which ones the user wants.
1575871Snate@binkert.org#
1585871Snate@binkert.org# 1. If there are command-line targets, the configuration(s) are inferred
1595863Snate@binkert.org#    from the directories of those targets.  If scons was invoked from a
1605871Snate@binkert.org#    subdirectory (using 'scons -u'), those targets have to be
1615871Snate@binkert.org#    interpreted relative to that subdirectory.
1625871Snate@binkert.org#
1635871Snate@binkert.org# 2. If there are no command-line targets, and scons was invoked from a
1645871Snate@binkert.org#    subdirectory (using 'scons -u'), the configuration is inferred from
1655863Snate@binkert.org#    the name of the subdirectory.
1666121Snate@binkert.org#
1675863Snate@binkert.org# 3. If there are no command-line targets and scons was invoked from
1685871Snate@binkert.org#    the root build directory, a default configuration is used.  The
1694678Snate@binkert.org#    built-in default is ALPHA, but this can be overridden by setting the
1704678Snate@binkert.org#    M5_DEFAULT_CONFIG shell environment veriable.
1714678Snate@binkert.org#
1724678Snate@binkert.org# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
1734678Snate@binkert.org# this can be overridden by setting the M5_DEFAULT_BINARY shell
1744678Snate@binkert.org# environment veriable.
1754678Snate@binkert.org#
1764678Snate@binkert.org###################################################
1774678Snate@binkert.org
1784678Snate@binkert.org# Find default configuration & binary.
1794678Snate@binkert.orgdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA')
1807827Snate@binkert.orgdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1817827Snate@binkert.org
1826121Snate@binkert.org# Ask SCons which directory it was invoked from.  If you invoke SCons
1834678Snate@binkert.org# from a subdirectory you must use the '-u' flag.
1845871Snate@binkert.orglaunch_dir = GetLaunchDir()
1855871Snate@binkert.org
1865871Snate@binkert.org# Build a list 'my_targets' of all the targets relative to ROOT.
1875871Snate@binkert.orgif launch_dir == ROOT:
1885871Snate@binkert.org    # invoked from root build dir
1895871Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
1905871Snate@binkert.org        # easy: use specified targets as is
1915871Snate@binkert.org        my_targets = COMMAND_LINE_TARGETS
1925871Snate@binkert.org    else:
1935871Snate@binkert.org        # default target (ALPHA/m5.debug, unless overridden)
1945871Snate@binkert.org        target = os.path.join(default_config, default_binary)
1955871Snate@binkert.org        my_targets = [target]
1965871Snate@binkert.org        Default(target)
1975990Ssaidi@eecs.umich.eduelse:
1985871Snate@binkert.org    # invoked from subdirectory
1995871Snate@binkert.org    if not launch_dir.startswith(ROOT):
2005871Snate@binkert.org        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
2014678Snate@binkert.org              (launch_dir, ROOT)
2026654Snate@binkert.org        sys.exit(1)
2035871Snate@binkert.org    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
2045871Snate@binkert.org    launch_dir = launch_dir[len(ROOT)+1:]
2055871Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
2065871Snate@binkert.org        # make specified targets relative to ROOT
2075871Snate@binkert.org        my_targets = map(lambda x: os.path.join(launch_dir, x),
2085871Snate@binkert.org                         COMMAND_LINE_TARGETS)
2095871Snate@binkert.org    else:
2105871Snate@binkert.org        # build default binary (m5.debug, unless overridden) using the
2115871Snate@binkert.org        # config inferred by the invocation directory (the first
2124678Snate@binkert.org        # subdirectory after ROOT)
2135871Snate@binkert.org        target = os.path.join(launch_dir.split('/')[0], default_binary)
2144678Snate@binkert.org        my_targets = [target]
2155871Snate@binkert.org        Default(target)
2165871Snate@binkert.org
2175871Snate@binkert.org# Normalize target paths (gets rid of '..' in the middle, etc.)
2185871Snate@binkert.orgmy_targets = map(os.path.normpath, my_targets)
2195871Snate@binkert.org
2205871Snate@binkert.org# Generate a list of the unique configs that the collected targets reference.
2215871Snate@binkert.orgbuild_dirs = []
2225871Snate@binkert.orgfor t in my_targets:
2235871Snate@binkert.org    dir = t.split('/')[0]
2246121Snate@binkert.org    if dir not in build_dirs:
2256121Snate@binkert.org        build_dirs.append(dir)
2265863Snate@binkert.org
227955SN/A###################################################
228955SN/A#
2292632Sstever@eecs.umich.edu# Set up the default build environment.  This environment is copied
2302632Sstever@eecs.umich.edu# and modified according to each selected configuration.
231955SN/A#
232955SN/A###################################################
233955SN/A
234955SN/Adefault_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
2355863Snate@binkert.org                          ROOT = ROOT,
236955SN/A                          SRCDIR = SRCDIR,
2372632Sstever@eecs.umich.edu                          EXT_SRCDIR = EXT_SRCDIR,
2382632Sstever@eecs.umich.edu                          CPPDEFINES = [],
2392632Sstever@eecs.umich.edu                          FULL_SYSTEM = False,
2402632Sstever@eecs.umich.edu                          USE_MYSQL = False)
2412632Sstever@eecs.umich.edu
2422632Sstever@eecs.umich.edudefault_env.SConsignFile("sconsign")
2432632Sstever@eecs.umich.edu
2442632Sstever@eecs.umich.edu# For some reason, the CC and CXX variables don't get passed into the
2452632Sstever@eecs.umich.edu# environment correctly.  This is probably some sort of scons bug that
2462632Sstever@eecs.umich.edu# will eventually be fixed.
2472632Sstever@eecs.umich.eduif os.environ.has_key('CC'):
2482632Sstever@eecs.umich.edu    default_env.Replace(CC=os.environ['CC'])
2492632Sstever@eecs.umich.edu
2503718Sstever@eecs.umich.eduif os.environ.has_key('CXX'):
2513718Sstever@eecs.umich.edu    default_env.Replace(CXX=os.environ['CXX'])
2523718Sstever@eecs.umich.edu
2533718Sstever@eecs.umich.edu# M5_EXT is used by isa_parser.py to find the PLY package.
2543718Sstever@eecs.umich.edudefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
2555863Snate@binkert.org
2565863Snate@binkert.orgdefault_env.Append(CCFLAGS='-pipe')
2573718Sstever@eecs.umich.edudefault_env.Append(CCFLAGS='-fno-strict-aliasing')
2583718Sstever@eecs.umich.edudefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2596121Snate@binkert.orgdefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
2605863Snate@binkert.org
2613718Sstever@eecs.umich.edu# libelf build is described in its own SConscript file.  Using a
2623718Sstever@eecs.umich.edu# dictionary for exports lets us export "default_env" so the
2632634Sstever@eecs.umich.edu# SConscript will see it as "env".  SConscript-global is the build in
2642634Sstever@eecs.umich.edu# build/libelf shared among all configs.
2655863Snate@binkert.orgdefault_env.SConscript('m5/libelf/SConscript-global',
2662638Sstever@eecs.umich.edu                       exports={'env' : default_env})
2672632Sstever@eecs.umich.edu
2682632Sstever@eecs.umich.edu###################################################
2692632Sstever@eecs.umich.edu#
2702632Sstever@eecs.umich.edu# Define build environments for selected configurations.
2712632Sstever@eecs.umich.edu#
2722632Sstever@eecs.umich.edu###################################################
2731858SN/A
2743716Sstever@eecs.umich.edufor build_dir in build_dirs:
2752638Sstever@eecs.umich.edu    # Make a copy of the default environment to use for this config.
2762638Sstever@eecs.umich.edu    env = default_env.Copy()
2772638Sstever@eecs.umich.edu    # Modify 'env' according to the build directory config.
2782638Sstever@eecs.umich.edu    print "Configuring options for directory '%s'." % build_dir
2792638Sstever@eecs.umich.edu    if not set_dir_options(build_dir, env):
2802638Sstever@eecs.umich.edu        print "Skipping directory '%s'." % build_dir
2812638Sstever@eecs.umich.edu        continue
2825863Snate@binkert.org
2835863Snate@binkert.org    # The m5/SConscript file sets up the build rules in 'env' according
2845863Snate@binkert.org    # to the configured options.
285955SN/A    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2865341Sstever@gmail.com               duplicate=0)
2875341Sstever@gmail.com
2885863Snate@binkert.org
2897756SAli.Saidi@ARM.com###################################################
2905341Sstever@gmail.com#
2916121Snate@binkert.org# Let SCons do its thing.  At this point SCons will use the defined
2924494Ssaidi@eecs.umich.edu# build enviornments to build the requested targets.
2936121Snate@binkert.org#
2941105SN/A###################################################
2952667Sstever@eecs.umich.edu
2962667Sstever@eecs.umich.edu