SConstruct revision 1762
1955SN/A# -*- mode:python -*-
2955SN/A
311408Sandreas.sandberg@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from
157816Ssteve.reinhardt@amd.com# this software without specific prior written permission.
165871Snate@binkert.org#
171762SN/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###################################################
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).
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#
38955SN/A# Then type 'scons' to build the default configuration (see below), or
39955SN/A# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
40955SN/A# 'ALPHA_FS/m5.opt' for the optimized full-system version).
41955SN/A#
422665Ssaidi@eecs.umich.edu###################################################
432665Ssaidi@eecs.umich.edu
445863Snate@binkert.org# Python library imports
45955SN/Aimport sys
46955SN/Aimport os
47955SN/A
48955SN/A# The absolute path to the current directory (where this file lives).
49955SN/AROOT = Dir('.').abspath
508878Ssteve.reinhardt@amd.com
512632Sstever@eecs.umich.edu# Paths to the M5 and external source trees (local symlinks).
528878Ssteve.reinhardt@amd.comSRCDIR = os.path.join(ROOT, 'm5')
532632Sstever@eecs.umich.eduEXT_SRCDIR = os.path.join(ROOT, 'ext')
54955SN/A
558878Ssteve.reinhardt@amd.com# Check for 'm5' and 'ext' links, die if they don't exist.
562632Sstever@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
582632Sstever@eecs.umich.edu    sys.exit(1)
592632Sstever@eecs.umich.edu
602632Sstever@eecs.umich.eduif not os.path.isdir('ext'):
612761Sstever@eecs.umich.edu    print "Error: '%s' must be a link to the M5 external source tree." \
622761Sstever@eecs.umich.edu          % EXT_SRCDIR
632761Sstever@eecs.umich.edu    sys.exit(1)
648878Ssteve.reinhardt@amd.com
658878Ssteve.reinhardt@amd.com# tell python where to find m5 python code
662761Sstever@eecs.umich.edusys.path.append(os.path.join(SRCDIR, 'python'))
672761Sstever@eecs.umich.edu
682761Sstever@eecs.umich.edu
692761Sstever@eecs.umich.edu###################################################
702761Sstever@eecs.umich.edu#
718878Ssteve.reinhardt@amd.com# Define Configurations
728878Ssteve.reinhardt@amd.com#
732632Sstever@eecs.umich.edu# The build system infers the build options from the subdirectory name
742632Sstever@eecs.umich.edu# that the simulator is built under.  The subdirectory name must be of
758878Ssteve.reinhardt@amd.com# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
768878Ssteve.reinhardt@amd.com# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL).  The
772632Sstever@eecs.umich.edu# following code defines the standard configurations and options.
78955SN/A# Additional local configurations and options are read from the file
79955SN/A# 'local_configs' if it exists.
80955SN/A#
815863Snate@binkert.org# Each base configuration or option is defined in two steps: a
825863Snate@binkert.org# function that takes an SCons build environment and modifies it
835863Snate@binkert.org# appropriately for that config or option, and an entry in the
845863Snate@binkert.org# 'configs_map' or 'options_map' dictionary that maps the directory
855863Snate@binkert.org# name string to the function.  (The directory names are all upper
865863Snate@binkert.org# case, by convention.)
875863Snate@binkert.org#
885863Snate@binkert.org###################################################
895863Snate@binkert.org
905863Snate@binkert.org# Base non-full-system Alpha ISA configuration.
915863Snate@binkert.orgdef AlphaSyscallEmulConfig(env):
928878Ssteve.reinhardt@amd.com    env.Replace(TARGET_ISA = 'alpha')
935863Snate@binkert.org    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
945863Snate@binkert.org
955863Snate@binkert.org# Base full-system configuration.
969812Sandreas.hansson@arm.comdef AlphaFullSysConfig(env):
979812Sandreas.hansson@arm.com    env.Replace(TARGET_ISA = 'alpha')
985863Snate@binkert.org    env.Replace(FULL_SYSTEM = True)
999812Sandreas.hansson@arm.com    env.Append(CPPDEFINES = ['FULL_SYSTEM'])
1005863Snate@binkert.org
1015863Snate@binkert.org# Base configurations map.
1025863Snate@binkert.orgconfigs_map = {
1039812Sandreas.hansson@arm.com    'ALPHA_SE' : AlphaSyscallEmulConfig,
1049812Sandreas.hansson@arm.com    'ALPHA_FS' : AlphaFullSysConfig
1055863Snate@binkert.org    }
1065863Snate@binkert.org
1078878Ssteve.reinhardt@amd.com# Disable FastAlloc object allocation.
1085863Snate@binkert.orgdef NoFastAllocOpt(env):
1095863Snate@binkert.org    env.Append(CPPDEFINES = 'NO_FAST_ALLOC')
1105863Snate@binkert.org
1116654Snate@binkert.org# Enable efence
11210196SCurtis.Dunham@arm.comdef EfenceOpt(env):
113955SN/A    env.Append(LIBS=['efence'])
1145396Ssaidi@eecs.umich.edu
11511401Sandreas.sandberg@arm.com# Configuration options map.
1165863Snate@binkert.orgoptions_map = {
1175863Snate@binkert.org    'NO_FAST_ALLOC' : NoFastAllocOpt,
1184202Sbinkertn@umich.edu    'EFENCE' : EfenceOpt
1195863Snate@binkert.org    }
1205863Snate@binkert.org
1215863Snate@binkert.org# The 'local_configs' file can be used to define additional base
1225863Snate@binkert.org# configurations and/or options without changing this file.
123955SN/Aif os.path.isfile('local_configs'):
1246654Snate@binkert.org    SConscript('local_configs', exports = ['configs_map', 'options_map'])
1255273Sstever@gmail.com
1265871Snate@binkert.org# This function parses a directory name of the form <CONFIG>[.<OPT>]*
1275273Sstever@gmail.com# and sets up the build environment appropriately.  Returns True if
1286655Snate@binkert.org# successful, False if the base config or any of the options were not
1298878Ssteve.reinhardt@amd.com# defined.
1306655Snate@binkert.orgdef set_dir_options(dir, env):
1316655Snate@binkert.org    parts = dir.split('.')
1329219Spower.jg@gmail.com    config = parts[0]
1336655Snate@binkert.org    opts = parts[1:]
1345871Snate@binkert.org    try:
1356654Snate@binkert.org        configs_map[config](env)
1368947Sandreas.hansson@arm.com        map(lambda opt: options_map[opt](env), opts)
1375396Ssaidi@eecs.umich.edu        return True
1388120Sgblack@eecs.umich.edu    except KeyError, key:
1398120Sgblack@eecs.umich.edu        print "Config/option '%s' not found." % key
1408120Sgblack@eecs.umich.edu        return False
1418120Sgblack@eecs.umich.edu
1428120Sgblack@eecs.umich.edu# Set the default configuration and binary.  The default target (if
1438120Sgblack@eecs.umich.edu# scons is invoked at the top level with no command-line targets) is
1448120Sgblack@eecs.umich.edu# 'ALPHA_SE/m5.debug'.  If scons is invoked in a subdirectory with no
1458120Sgblack@eecs.umich.edu# command-line targets, the configuration
1468879Ssteve.reinhardt@amd.com
1478879Ssteve.reinhardt@amd.com###################################################
1488879Ssteve.reinhardt@amd.com#
1498879Ssteve.reinhardt@amd.com# Figure out which configurations to set up.
1508879Ssteve.reinhardt@amd.com#
1518879Ssteve.reinhardt@amd.com#
1528879Ssteve.reinhardt@amd.com# It's prohibitive to do all the combinations of base configurations
1538879Ssteve.reinhardt@amd.com# and options, so we have to infer which ones the user wants.
1548879Ssteve.reinhardt@amd.com#
1558879Ssteve.reinhardt@amd.com# 1. If there are command-line targets, the configuration(s) are inferred
1568879Ssteve.reinhardt@amd.com#    from the directories of those targets.  If scons was invoked from a
1578879Ssteve.reinhardt@amd.com#    subdirectory (using 'scons -u'), those targets have to be
1588879Ssteve.reinhardt@amd.com#    interpreted relative to that subdirectory.
1598120Sgblack@eecs.umich.edu#
1608120Sgblack@eecs.umich.edu# 2. If there are no command-line targets, and scons was invoked from a
1618120Sgblack@eecs.umich.edu#    subdirectory (using 'scons -u'), the configuration is inferred from
1628120Sgblack@eecs.umich.edu#    the name of the subdirectory.
1638120Sgblack@eecs.umich.edu#
1648120Sgblack@eecs.umich.edu# 3. If there are no command-line targets and scons was invoked from
1658120Sgblack@eecs.umich.edu#    the root build directory, a default configuration is used.  The
1668120Sgblack@eecs.umich.edu#    built-in default is ALPHA_SE, but this can be overridden by setting the
1678120Sgblack@eecs.umich.edu#    M5_DEFAULT_CONFIG shell environment veriable.
1688120Sgblack@eecs.umich.edu#
1698120Sgblack@eecs.umich.edu# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
1708120Sgblack@eecs.umich.edu# this can be overridden by setting the M5_DEFAULT_BINARY shell
1718120Sgblack@eecs.umich.edu# environment veriable.
1728120Sgblack@eecs.umich.edu#
1738879Ssteve.reinhardt@amd.com###################################################
1748879Ssteve.reinhardt@amd.com
1758879Ssteve.reinhardt@amd.com# Find default configuration & binary.
1768879Ssteve.reinhardt@amd.comdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
17710458Sandreas.hansson@arm.comdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
17810458Sandreas.hansson@arm.com
17910458Sandreas.hansson@arm.com# Ask SCons which directory it was invoked from.  If you invoke SCons
1808879Ssteve.reinhardt@amd.com# from a subdirectory you must use the '-u' flag.
1818879Ssteve.reinhardt@amd.comlaunch_dir = GetLaunchDir()
1828879Ssteve.reinhardt@amd.com
1838879Ssteve.reinhardt@amd.com# Build a list 'my_targets' of all the targets relative to ROOT.
1849227Sandreas.hansson@arm.comif launch_dir == ROOT:
1859227Sandreas.hansson@arm.com    # invoked from root build dir
1868879Ssteve.reinhardt@amd.com    if len(COMMAND_LINE_TARGETS) != 0:
1878879Ssteve.reinhardt@amd.com        # easy: use specified targets as is
1888879Ssteve.reinhardt@amd.com        my_targets = COMMAND_LINE_TARGETS
1898879Ssteve.reinhardt@amd.com    else:
19010453SAndrew.Bardsley@arm.com        # default target (ALPHA_SE/m5.debug, unless overridden)
19110453SAndrew.Bardsley@arm.com        target = os.path.join(default_config, default_binary)
19210453SAndrew.Bardsley@arm.com        my_targets = [target]
19310456SCurtis.Dunham@arm.com        Default(target)
19410456SCurtis.Dunham@arm.comelse:
19510456SCurtis.Dunham@arm.com    # invoked from subdirectory
19610457Sandreas.hansson@arm.com    if not launch_dir.startswith(ROOT):
19710457Sandreas.hansson@arm.com        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
19811342Sandreas.hansson@arm.com              (launch_dir, ROOT)
19911342Sandreas.hansson@arm.com        sys.exit(1)
2008120Sgblack@eecs.umich.edu    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
2018947Sandreas.hansson@arm.com    launch_dir = launch_dir[len(ROOT)+1:]
2027816Ssteve.reinhardt@amd.com    if len(COMMAND_LINE_TARGETS) != 0:
2035871Snate@binkert.org        # make specified targets relative to ROOT
2045871Snate@binkert.org        my_targets = map(lambda x: os.path.join(launch_dir, x),
2056121Snate@binkert.org                         COMMAND_LINE_TARGETS)
2065871Snate@binkert.org    else:
2075871Snate@binkert.org        # build default binary (m5.debug, unless overridden) using the
2089926Sstan.czerniawski@arm.com        # config inferred by the invocation directory (the first
2099926Sstan.czerniawski@arm.com        # subdirectory after ROOT)
2109119Sandreas.hansson@arm.com        target = os.path.join(launch_dir.split('/')[0], default_binary)
21110068Sandreas.hansson@arm.com        my_targets = [target]
21211989Sandreas.sandberg@arm.com        Default(target)
213955SN/A
2149416SAndreas.Sandberg@ARM.com# Normalize target paths (gets rid of '..' in the middle, etc.)
21511342Sandreas.hansson@arm.commy_targets = map(os.path.normpath, my_targets)
21611212Sjoseph.gross@amd.com
21711212Sjoseph.gross@amd.com# Generate a list of the unique configs that the collected targets reference.
21811212Sjoseph.gross@amd.combuild_dirs = []
21911212Sjoseph.gross@amd.comfor t in my_targets:
22011212Sjoseph.gross@amd.com    dir = t.split('/')[0]
2219416SAndreas.Sandberg@ARM.com    if dir not in build_dirs:
2229416SAndreas.Sandberg@ARM.com        build_dirs.append(dir)
2235871Snate@binkert.org
22410584Sandreas.hansson@arm.com###################################################
2259416SAndreas.Sandberg@ARM.com#
2269416SAndreas.Sandberg@ARM.com# Set up the default build environment.  This environment is copied
2275871Snate@binkert.org# and modified according to each selected configuration.
228955SN/A#
22910671Sandreas.hansson@arm.com###################################################
23010671Sandreas.hansson@arm.com
23110671Sandreas.hansson@arm.comdefault_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
23210671Sandreas.hansson@arm.com                          ROOT = ROOT,
2338881Smarc.orr@gmail.com                          SRCDIR = SRCDIR,
2346121Snate@binkert.org                          EXT_SRCDIR = EXT_SRCDIR,
2356121Snate@binkert.org                          CPPDEFINES = [],
2361533SN/A                          FULL_SYSTEM = False,
2379239Sandreas.hansson@arm.com                          ALPHA_TLASER = False,
2389239Sandreas.hansson@arm.com                          USE_MYSQL = False)
2399239Sandreas.hansson@arm.com
2409239Sandreas.hansson@arm.comdefault_env.SConsignFile("sconsign")
2419239Sandreas.hansson@arm.com
2429239Sandreas.hansson@arm.com# For some reason, the CC and CXX variables don't get passed into the
2439239Sandreas.hansson@arm.com# environment correctly.  This is probably some sort of scons bug that
2446655Snate@binkert.org# will eventually be fixed.
2456655Snate@binkert.orgif os.environ.has_key('CC'):
2466655Snate@binkert.org    default_env.Replace(CC=os.environ['CC'])
2476655Snate@binkert.org
2485871Snate@binkert.orgif os.environ.has_key('CXX'):
2495871Snate@binkert.org    default_env.Replace(CXX=os.environ['CXX'])
2505863Snate@binkert.org
2515871Snate@binkert.org# M5_EXT is used by isa_parser.py to find the PLY package.
2528878Ssteve.reinhardt@amd.comdefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
2535871Snate@binkert.org
2545871Snate@binkert.orgdefault_env.Append(CCFLAGS='-pipe')
2555871Snate@binkert.orgdefault_env.Append(CCFLAGS='-fno-strict-aliasing')
2565863Snate@binkert.orgdefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2576121Snate@binkert.orgdefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
2585863Snate@binkert.org
25911408Sandreas.sandberg@arm.com# libelf build is described in its own SConscript file.  Using a
26011408Sandreas.sandberg@arm.com# dictionary for exports lets us export "default_env" so the
2618336Ssteve.reinhardt@amd.com# SConscript will see it as "env".  SConscript-global is the build in
26211469SCurtis.Dunham@arm.com# build/libelf shared among all configs.
26311469SCurtis.Dunham@arm.comdefault_env.SConscript('m5/libelf/SConscript-global',
2648336Ssteve.reinhardt@amd.com                       exports={'env' : default_env})
2654678Snate@binkert.org
26611887Sandreas.sandberg@arm.com###################################################
26711887Sandreas.sandberg@arm.com#
26811887Sandreas.sandberg@arm.com# Define build environments for selected configurations.
26911887Sandreas.sandberg@arm.com#
27011887Sandreas.sandberg@arm.com###################################################
27111887Sandreas.sandberg@arm.com
27211887Sandreas.sandberg@arm.comfor build_dir in build_dirs:
27311887Sandreas.sandberg@arm.com    # Make a copy of the default environment to use for this config.
27411887Sandreas.sandberg@arm.com    env = default_env.Copy()
27511887Sandreas.sandberg@arm.com    # Modify 'env' according to the build directory config.
27611887Sandreas.sandberg@arm.com    print "Configuring options for directory '%s'." % build_dir
27711408Sandreas.sandberg@arm.com    if not set_dir_options(build_dir, env):
27811401Sandreas.sandberg@arm.com        print "Skipping directory '%s'." % build_dir
27911401Sandreas.sandberg@arm.com        continue
28011401Sandreas.sandberg@arm.com
28111401Sandreas.sandberg@arm.com    # The m5/SConscript file sets up the build rules in 'env' according
28211401Sandreas.sandberg@arm.com    # to the configured options.
28311401Sandreas.sandberg@arm.com    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2848336Ssteve.reinhardt@amd.com               duplicate=0)
2858336Ssteve.reinhardt@amd.com
2868336Ssteve.reinhardt@amd.com
2874678Snate@binkert.org###################################################
28811401Sandreas.sandberg@arm.com#
2894678Snate@binkert.org# Let SCons do its thing.  At this point SCons will use the defined
2904678Snate@binkert.org# build environments to build the requested targets.
29111401Sandreas.sandberg@arm.com#
29211401Sandreas.sandberg@arm.com###################################################
2938336Ssteve.reinhardt@amd.com
2944678Snate@binkert.org