SConstruct revision 955
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
294762Snate@binkert.org###################################################
30955SN/A#
315522Snate@binkert.org# SCons top-level build description (SConstruct) file.
326143Snate@binkert.org#
334762Snate@binkert.org# To build M5, you need a directory with three things:
345522Snate@binkert.org# 1. A copy of this file (named SConstruct).
35955SN/A# 2. A link named 'm5' to the top of the M5 simulator source tree.
365522Snate@binkert.org# 3. A link named 'ext' to the top of the M5 external source tree.
37955SN/A#
385522Snate@binkert.org# Then type 'scons' to build the default configuration (see below), or
394202Sbinkertn@umich.edu# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
405742Snate@binkert.org# 'KERNEL/m5.opt' for the optimized full-system version).
41955SN/A#
424381Sbinkertn@umich.edu###################################################
434381Sbinkertn@umich.edu
44955SN/A# Python library imports
45955SN/Aimport sys
46955SN/Aimport os
474202Sbinkertn@umich.edu
48955SN/A# The absolute path to the current directory (where this file lives).
494382Sbinkertn@umich.eduROOT = Dir('.').abspath
504382Sbinkertn@umich.edu
514382Sbinkertn@umich.edu# Paths to the M5 and external source trees (local symlinks).
526654Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'm5')
535517Snate@binkert.orgEXT_SRCDIR = os.path.join(ROOT, 'ext')
547674Snate@binkert.org
557674Snate@binkert.org# Check for 'm5' and 'ext' links, die if they don't exist.
566143Snate@binkert.orgif not os.path.isdir(SRCDIR):
576143Snate@binkert.org    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
586143Snate@binkert.org    sys.exit(1)
598233Snate@binkert.org
608233Snate@binkert.orgif not os.path.isdir('ext'):
618233Snate@binkert.org    print "Error: '%s' must be a link to the M5 external source tree." \
628233Snate@binkert.org          % EXT_SRCDIR
638233Snate@binkert.org    sys.exit(1)
648233Snate@binkert.org
658233Snate@binkert.org
668233Snate@binkert.org###################################################
678233Snate@binkert.org#
688233Snate@binkert.org# Define Configurations
698233Snate@binkert.org#
708233Snate@binkert.org# The build system infers the build options from the subdirectory name
718233Snate@binkert.org# that the simulator is built under.  The subdirectory name must be of
726143Snate@binkert.org# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
738233Snate@binkert.org# (e.g., ALPHA or KERNEL) and OPT is an option (e.g., MYSQL).  The
748233Snate@binkert.org# following code defines the standard configurations and options.
758233Snate@binkert.org# Additional local configurations and options are read from the file
766143Snate@binkert.org# 'local_configs' if it exists.
776143Snate@binkert.org#
786143Snate@binkert.org# Each base configuration or option is defined in two steps: a
796143Snate@binkert.org# function that takes an SCons build environment and modifies it
808233Snate@binkert.org# appropriately for that config or option, and an entry in the
818233Snate@binkert.org# 'configs_map' or 'options_map' dictionary that maps the directory
828233Snate@binkert.org# name string to the function.  (The directory names are all upper
836143Snate@binkert.org# case, by convention.)
848233Snate@binkert.org#
858233Snate@binkert.org###################################################
868233Snate@binkert.org
878233Snate@binkert.org# Base non-full-system Alpha ISA configuration.
886143Snate@binkert.orgdef AlphaConfig(env):
896143Snate@binkert.org    env.Replace(TARGET_ISA = 'alpha')
906143Snate@binkert.org    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
914762Snate@binkert.org
926143Snate@binkert.org# Base full-system configuration.
938233Snate@binkert.orgdef KernelConfig(env):
948233Snate@binkert.org    env.Replace(TARGET_ISA = 'alpha')
958233Snate@binkert.org    env.Replace(FULL_SYSTEM = True)
968233Snate@binkert.org    env.Append(CPPDEFINES = ['FULL_SYSTEM', 'SYSTEM_EV5'])
978233Snate@binkert.org
986143Snate@binkert.org# Base configurations map.
998233Snate@binkert.orgconfigs_map = {
1008233Snate@binkert.org    'ALPHA' : AlphaConfig,
1018233Snate@binkert.org    'KERNEL' : KernelConfig
1028233Snate@binkert.org    }
1036143Snate@binkert.org
1046143Snate@binkert.org# Enable detailed full-system binning.
1056143Snate@binkert.orgdef MeasureOpt(env):
1066143Snate@binkert.org    env.Replace(USE_MYSQL = True)
1076143Snate@binkert.org    env.Append(CPPDEFINES = 'FS_MEASURE')
1086143Snate@binkert.org
1096143Snate@binkert.org# Enable MySql database output for stats.
1106143Snate@binkert.orgdef MySqlOpt(env):
1116143Snate@binkert.org    env.Replace(USE_MYSQL = True)
1127065Snate@binkert.org
1136143Snate@binkert.org# Disable FastAlloc object allocation.
1148233Snate@binkert.orgdef NoFastAllocOpt(env):
1158233Snate@binkert.org    env.Append(CPPDEFINES = 'NO_FAST_ALLOC')
1168233Snate@binkert.org
1178233Snate@binkert.org# Configuration options map.
1188233Snate@binkert.orgoptions_map = {
1198233Snate@binkert.org    'MEASURE' : MeasureOpt,
1208233Snate@binkert.org    'MYSQL' : MySqlOpt,
1218233Snate@binkert.org    'NO_FAST_ALLOC' : NoFastAllocOpt
1228233Snate@binkert.org    }
1238233Snate@binkert.org
1248233Snate@binkert.org# The 'local_configs' file can be used to define additional base
1258233Snate@binkert.org# configurations and/or options without changing this file.
1268233Snate@binkert.orgif os.path.isfile('local_configs'):
1278233Snate@binkert.org    SConscript('local_configs', exports = ['configs_map', 'options_map'])
1288233Snate@binkert.org
1298233Snate@binkert.org# This function parses a directory name of the form <CONFIG>[.<OPT>]*
1308233Snate@binkert.org# and sets up the build environment appropriately.  Returns True if
1318233Snate@binkert.org# successful, False if the base config or any of the options were not
1328233Snate@binkert.org# defined.
1338233Snate@binkert.orgdef set_dir_options(dir, env):
1348233Snate@binkert.org    parts = dir.split('.')
1358233Snate@binkert.org    config = parts[0]
1368233Snate@binkert.org    opts = parts[1:]
1378233Snate@binkert.org    try:
1388233Snate@binkert.org        configs_map[config](env)
1398233Snate@binkert.org        map(lambda opt: options_map[opt](env), opts)
1408233Snate@binkert.org        return True
1418233Snate@binkert.org    except KeyError, key:
1428233Snate@binkert.org        print "Config/option '%s' not found." % key
1438233Snate@binkert.org        return False
1448233Snate@binkert.org
1456143Snate@binkert.org# Set the default configuration and binary.  The default target (if
1466143Snate@binkert.org# scons is invoked at the top level with no command-line targets) is
1476143Snate@binkert.org# 'ALPHA/m5.debug'.  If scons is invoked in a subdirectory with no
1486143Snate@binkert.org# command-line targets, the configuration
1496143Snate@binkert.org
1506143Snate@binkert.org###################################################
1516143Snate@binkert.org#
1526143Snate@binkert.org# Figure out which configurations to set up.
1536143Snate@binkert.org#
1548233Snate@binkert.org#
1558233Snate@binkert.org# It's prohibitive to do all the combinations of base configurations
1568233Snate@binkert.org# and options, so we have to infer which ones the user wants.
1576143Snate@binkert.org#
1586143Snate@binkert.org# 1. If there are command-line targets, the configuration(s) are inferred
1596143Snate@binkert.org#    from the directories of those targets.  If scons was invoked from a
1606143Snate@binkert.org#    subdirectory (using 'scons -u'), those targets have to be
1616143Snate@binkert.org#    interpreted relative to that subdirectory.
1626143Snate@binkert.org#
1635522Snate@binkert.org# 2. If there are no command-line targets, and scons was invoked from a
1646143Snate@binkert.org#    subdirectory (using 'scons -u'), the configuration is inferred from
1656143Snate@binkert.org#    the name of the subdirectory.
1666143Snate@binkert.org#
1676143Snate@binkert.org# 3. If there are no command-line targets and scons was invoked from
1688233Snate@binkert.org#    the root build directory, a default configuration is used.  The
1698233Snate@binkert.org#    built-in default is ALPHA, but this can be overridden by setting the
1708233Snate@binkert.org#    M5_DEFAULT_CONFIG shell environment veriable.
1716143Snate@binkert.org#
1726143Snate@binkert.org# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
1736143Snate@binkert.org# this can be overridden by setting the M5_DEFAULT_BINARY shell
1746143Snate@binkert.org# environment veriable.
1755522Snate@binkert.org#
1765522Snate@binkert.org###################################################
1775522Snate@binkert.org
1785522Snate@binkert.org# Find default configuration & binary.
1795604Snate@binkert.orgdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA')
1805604Snate@binkert.orgdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1816143Snate@binkert.org
1826143Snate@binkert.org# Ask SCons which directory it was invoked from.  If you invoke SCons
1834762Snate@binkert.org# from a subdirectory you must use the '-u' flag.
1844762Snate@binkert.orglaunch_dir = GetLaunchDir()
1856143Snate@binkert.org
1866727Ssteve.reinhardt@amd.com# Build a list 'my_targets' of all the targets relative to ROOT.
1876727Ssteve.reinhardt@amd.comif launch_dir == ROOT:
1886727Ssteve.reinhardt@amd.com    # invoked from root build dir
1894762Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
1906143Snate@binkert.org        # easy: use specified targets as is
1916143Snate@binkert.org        my_targets = COMMAND_LINE_TARGETS
1926143Snate@binkert.org    else:
1936143Snate@binkert.org        # default target (ALPHA/m5.debug, unless overridden)
1946727Ssteve.reinhardt@amd.com        target = os.path.join(default_config, default_binary)
1956143Snate@binkert.org        my_targets = [target]
1967674Snate@binkert.org        Default(target)
1977674Snate@binkert.orgelse:
1985604Snate@binkert.org    # invoked from subdirectory
1996143Snate@binkert.org    if not launch_dir.startswith(ROOT):
2006143Snate@binkert.org        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
2016143Snate@binkert.org              (launch_dir, ROOT)
2024762Snate@binkert.org        sys.exit(1)
2036143Snate@binkert.org    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
2044762Snate@binkert.org    launch_dir = launch_dir[len(ROOT)+1:]
2054762Snate@binkert.org    if len(COMMAND_LINE_TARGETS) != 0:
2064762Snate@binkert.org        # make specified targets relative to ROOT
2076143Snate@binkert.org        my_targets = map(lambda x: os.path.join(launch_dir, x),
2086143Snate@binkert.org                         COMMAND_LINE_TARGETS)
2094762Snate@binkert.org    else:
2108233Snate@binkert.org        # build default binary (m5.debug, unless overridden) using the
2118233Snate@binkert.org        # config inferred by the invocation directory (the first
2128233Snate@binkert.org        # subdirectory after ROOT)
2138233Snate@binkert.org        target = os.path.join(launch_dir.split('/')[0], default_binary)
2146143Snate@binkert.org        my_targets = [target]
2156143Snate@binkert.org        Default(target)
2164762Snate@binkert.org
2176143Snate@binkert.org# Normalize target paths (gets rid of '..' in the middle, etc.)
2184762Snate@binkert.orgmy_targets = map(os.path.normpath, my_targets)
2196143Snate@binkert.org
2204762Snate@binkert.org# Generate a list of the unique configs that the collected targets reference.
2216143Snate@binkert.orgbuild_dirs = []
2228233Snate@binkert.orgfor t in my_targets:
2238233Snate@binkert.org    dir = t.split('/')[0]
2248233Snate@binkert.org    if dir not in build_dirs:
2256143Snate@binkert.org        build_dirs.append(dir)
2266143Snate@binkert.org
2276143Snate@binkert.org###################################################
2286143Snate@binkert.org#
2296143Snate@binkert.org# Set up the default build environment.  This environment is copied
2306143Snate@binkert.org# and modified according to each selected configuration.
2316143Snate@binkert.org#
2326143Snate@binkert.org###################################################
2338233Snate@binkert.org
2348233Snate@binkert.orgdefault_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
235955SN/A                          ROOT = ROOT,
2368235Snate@binkert.org                          SRCDIR = SRCDIR,
2378235Snate@binkert.org                          EXT_SRCDIR = EXT_SRCDIR,
2386143Snate@binkert.org                          CPPDEFINES = [],
2398235Snate@binkert.org                          FULL_SYSTEM = False,
2408235Snate@binkert.org                          USE_MYSQL = False)
2418235Snate@binkert.org
2428235Snate@binkert.org# M5_EXT is used by isa_parser.py to find the PLY package.
2438235Snate@binkert.orgdefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
2448235Snate@binkert.org
2458235Snate@binkert.orgdefault_env.Append(CCFLAGS='-pipe')
2468235Snate@binkert.orgdefault_env.Append(CCFLAGS='-fno-strict-aliasing')
2478235Snate@binkert.orgdefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
2488235Snate@binkert.org
2498235Snate@binkert.org# libelf build is described in its own SConscript file.  Using a
2508235Snate@binkert.org# dictionary for exports lets us export "default_env" so the
2518235Snate@binkert.org# SConscript will see it as "env".
2528235Snate@binkert.orgdefault_env.SConscript('m5/libelf/SConscript', exports={'env' : default_env})
2538235Snate@binkert.org
2548235Snate@binkert.org
2558235Snate@binkert.org###################################################
2565584Snate@binkert.org#
2574382Sbinkertn@umich.edu# Define build environments for selected configurations.
2584202Sbinkertn@umich.edu#
2594382Sbinkertn@umich.edu###################################################
2604382Sbinkertn@umich.edu
2614382Sbinkertn@umich.edufor build_dir in build_dirs:
2625584Snate@binkert.org    # Make a copy of the default environment to use for this config.
2634382Sbinkertn@umich.edu    env = default_env.Copy()
2644382Sbinkertn@umich.edu    # Modify 'env' according to the build directory config.
2654382Sbinkertn@umich.edu    print "Configuring options for directory '%s'." % build_dir
2668232Snate@binkert.org    if not set_dir_options(build_dir, env):
2675192Ssaidi@eecs.umich.edu        print "Skipping directory '%s'." % build_dir
2688232Snate@binkert.org        continue
2698232Snate@binkert.org
2708232Snate@binkert.org    # The m5/SConscript file sets up the build rules in 'env' according
2715192Ssaidi@eecs.umich.edu    # to the configured options.
2728232Snate@binkert.org    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2738232Snate@binkert.org               duplicate=0)
2745192Ssaidi@eecs.umich.edu
2755799Snate@binkert.org
2768232Snate@binkert.org###################################################
2775192Ssaidi@eecs.umich.edu#
2785192Ssaidi@eecs.umich.edu# Let SCons do its thing.  At this point SCons will use the defined
2795192Ssaidi@eecs.umich.edu# build enviornments to build the requested targets.
2808232Snate@binkert.org#
2815192Ssaidi@eecs.umich.edu###################################################
2828232Snate@binkert.org
2835192Ssaidi@eecs.umich.edu