SConstruct revision 1851
19243SN/A# -*- mode:python -*-
210889Sandreas.hansson@arm.com
39243SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
49243SN/A# All rights reserved.
59243SN/A#
69243SN/A# Redistribution and use in source and binary forms, with or without
79243SN/A# modification, are permitted provided that the following conditions are
89243SN/A# met: redistributions of source code must retain the above copyright
99243SN/A# notice, this list of conditions and the following disclaimer;
109243SN/A# redistributions in binary form must reproduce the above copyright
119243SN/A# notice, this list of conditions and the following disclaimer in the
129243SN/A# documentation and/or other materials provided with the distribution;
139243SN/A# neither the name of the copyright holders nor the names of its
149831SN/A# contributors may be used to endorse or promote products derived from
159831SN/A# this software without specific prior written permission.
169831SN/A#
179243SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
189243SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
199243SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
209243SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
219243SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
229243SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
239243SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
249243SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
259243SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
269243SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
279243SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
289243SN/A
299243SN/A###################################################
309243SN/A#
319243SN/A# SCons top-level build description (SConstruct) file.
329243SN/A#
339243SN/A# To build M5, you need a directory with three things:
349243SN/A# 1. A copy of this file (named SConstruct).
359243SN/A# 2. A link named 'm5' to the top of the M5 simulator source tree.
369243SN/A# 3. A link named 'ext' to the top of the M5 external source tree.
379243SN/A#
389243SN/A# Then type 'scons' to build the default configuration (see below), or
399243SN/A# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
409243SN/A# 'ALPHA_FS/m5.opt' for the optimized full-system version).
419243SN/A#
429967SN/A###################################################
4310618SOmar.Naji@arm.com
449243SN/A# Python library imports
459243SN/Aimport sys
4610146Sandreas.hansson@arm.comimport os
479356SN/A
4810146Sandreas.hansson@arm.com# The absolute path to the current directory (where this file lives).
4910247Sandreas.hansson@arm.comROOT = Dir('.').abspath
5010208Sandreas.hansson@arm.com
519352SN/A# Paths to the M5 and external source trees (local symlinks).
5210146Sandreas.hansson@arm.comSRCDIR = os.path.join(ROOT, 'm5')
539814SN/AEXT_SRCDIR = os.path.join(ROOT, 'ext')
549243SN/A
559243SN/A# Check for 'm5' and 'ext' links, die if they don't exist.
5610432SOmar.Naji@arm.comif not os.path.isdir(SRCDIR):
579243SN/A    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
5810146Sandreas.hansson@arm.com    sys.exit(1)
599243SN/A
6010619Sandreas.hansson@arm.comif not os.path.isdir('ext'):
619243SN/A    print "Error: '%s' must be a link to the M5 external source tree." \
6210211Sandreas.hansson@arm.com          % EXT_SRCDIR
6310618SOmar.Naji@arm.com    sys.exit(1)
6410208Sandreas.hansson@arm.com
6510489SOmar.Naji@arm.com# tell python where to find m5 python code
669831SN/Asys.path.append(os.path.join(SRCDIR, 'python'))
679831SN/A
689831SN/A
699831SN/A###################################################
709831SN/A#
7110140SN/A# Define Configurations
7210646Sandreas.hansson@arm.com#
739243SN/A# The build system infers the build options from the subdirectory name
7410394Swendy.elsasser@arm.com# that the simulator is built under.  The subdirectory name must be of
7510394Swendy.elsasser@arm.com# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
769566SN/A# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL).  The
779243SN/A# following code defines the standard configurations and options.
789243SN/A# Additional local configurations and options are read from the file
7910140SN/A# 'local_configs' if it exists.
8010140SN/A#
8110147Sandreas.hansson@arm.com# Each base configuration or option is defined in two steps: a
8210147Sandreas.hansson@arm.com# function that takes an SCons build environment and modifies it
8310393Swendy.elsasser@arm.com# appropriately for that config or option, and an entry in the
8410394Swendy.elsasser@arm.com# 'configs_map' or 'options_map' dictionary that maps the directory
8510394Swendy.elsasser@arm.com# name string to the function.  (The directory names are all upper
8610394Swendy.elsasser@arm.com# case, by convention.)
879243SN/A#
889243SN/A###################################################
8910141SN/A
909726SN/A# Base non-full-system Alpha ISA configuration.
919726SN/Adef AlphaSyscallEmulConfig(env):
9210618SOmar.Naji@arm.com    env.Replace(TARGET_ISA = 'alpha')
9310618SOmar.Naji@arm.com    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
949243SN/A
9510620Sandreas.hansson@arm.com# Base full-system configuration.
9610620Sandreas.hansson@arm.comdef AlphaFullSysConfig(env):
9710620Sandreas.hansson@arm.com    env.Replace(TARGET_ISA = 'alpha')
9810620Sandreas.hansson@arm.com    env.Replace(FULL_SYSTEM = True)
9910620Sandreas.hansson@arm.com    env.Append(CPPDEFINES = ['FULL_SYSTEM'])
10010889Sandreas.hansson@arm.com
10110889Sandreas.hansson@arm.com# Base configurations map.
10210889Sandreas.hansson@arm.comconfigs_map = {
10310618SOmar.Naji@arm.com    'ALPHA_SE' : AlphaSyscallEmulConfig,
10410618SOmar.Naji@arm.com    'ALPHA_FS' : AlphaFullSysConfig
10510618SOmar.Naji@arm.com    }
10610432SOmar.Naji@arm.com
10710618SOmar.Naji@arm.com# Disable FastAlloc object allocation.
10810618SOmar.Naji@arm.comdef NoFastAllocOpt(env):
10910618SOmar.Naji@arm.com    env.Append(CPPDEFINES = 'NO_FAST_ALLOC')
11010432SOmar.Naji@arm.com
11110246Sandreas.hansson@arm.com# Enable efence
11210618SOmar.Naji@arm.comdef EfenceOpt(env):
11310561SOmar.Naji@arm.com    env.Append(LIBS=['efence'])
11410561SOmar.Naji@arm.com
11510561SOmar.Naji@arm.com# Configuration options map.
11610394Swendy.elsasser@arm.comoptions_map = {
11710394Swendy.elsasser@arm.com    'NO_FAST_ALLOC' : NoFastAllocOpt,
11810394Swendy.elsasser@arm.com    'EFENCE' : EfenceOpt
11910394Swendy.elsasser@arm.com    }
12010394Swendy.elsasser@arm.com
12110394Swendy.elsasser@arm.com# The 'local_configs' file can be used to define additional base
12210394Swendy.elsasser@arm.com# configurations and/or options without changing this file.
12310394Swendy.elsasser@arm.comif os.path.isfile('local_configs'):
12410618SOmar.Naji@arm.com    SConscript('local_configs', exports = ['configs_map', 'options_map'])
12510394Swendy.elsasser@arm.com
12610394Swendy.elsasser@arm.com# This function parses a directory name of the form <CONFIG>[.<OPT>]*
12710618SOmar.Naji@arm.com# and sets up the build environment appropriately.  Returns True if
12810394Swendy.elsasser@arm.com# successful, False if the base config or any of the options were not
12910246Sandreas.hansson@arm.com# defined.
13010246Sandreas.hansson@arm.comdef set_dir_options(dir, env):
13110246Sandreas.hansson@arm.com    parts = dir.split('.')
13210140SN/A    config = parts[0]
13310140SN/A    opts = parts[1:]
13410140SN/A    try:
13510140SN/A        configs_map[config](env)
13610140SN/A        map(lambda opt: options_map[opt](env), opts)
1379243SN/A        return True
1389243SN/A    except KeyError, key:
1399567SN/A        print "Config/option '%s' not found." % key
1409243SN/A        return False
14110489SOmar.Naji@arm.com
14210489SOmar.Naji@arm.com# Set the default configuration and binary.  The default target (if
14310489SOmar.Naji@arm.com# scons is invoked at the top level with no command-line targets) is
14410489SOmar.Naji@arm.com# 'ALPHA_SE/m5.debug'.  If scons is invoked in a subdirectory with no
14510489SOmar.Naji@arm.com# command-line targets, the configuration
14610489SOmar.Naji@arm.com
14710489SOmar.Naji@arm.com###################################################
14810489SOmar.Naji@arm.com#
14910489SOmar.Naji@arm.com# Figure out which configurations to set up.
15010489SOmar.Naji@arm.com#
1519243SN/A#
1529243SN/A# It's prohibitive to do all the combinations of base configurations
1539831SN/A# and options, so we have to infer which ones the user wants.
1549831SN/A#
1559831SN/A# 1. If there are command-line targets, the configuration(s) are inferred
1569831SN/A#    from the directories of those targets.  If scons was invoked from a
1579831SN/A#    subdirectory (using 'scons -u'), those targets have to be
1589243SN/A#    interpreted relative to that subdirectory.
15910207Sandreas.hansson@arm.com#
16010207Sandreas.hansson@arm.com# 2. If there are no command-line targets, and scons was invoked from a
16110207Sandreas.hansson@arm.com#    subdirectory (using 'scons -u'), the configuration is inferred from
16210207Sandreas.hansson@arm.com#    the name of the subdirectory.
16310207Sandreas.hansson@arm.com#
16410394Swendy.elsasser@arm.com# 3. If there are no command-line targets and scons was invoked from
16510394Swendy.elsasser@arm.com#    the root build directory, a default configuration is used.  The
16610394Swendy.elsasser@arm.com#    built-in default is ALPHA_SE, but this can be overridden by setting the
16710394Swendy.elsasser@arm.com#    M5_DEFAULT_CONFIG shell environment veriable.
16810394Swendy.elsasser@arm.com#
16910394Swendy.elsasser@arm.com# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
17010394Swendy.elsasser@arm.com# this can be overridden by setting the M5_DEFAULT_BINARY shell
17110394Swendy.elsasser@arm.com# environment veriable.
17210394Swendy.elsasser@arm.com#
17310394Swendy.elsasser@arm.com###################################################
17410394Swendy.elsasser@arm.com
17510394Swendy.elsasser@arm.com# Find default configuration & binary.
17610394Swendy.elsasser@arm.comdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
17710394Swendy.elsasser@arm.comdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
17810394Swendy.elsasser@arm.com
17910394Swendy.elsasser@arm.com# Ask SCons which directory it was invoked from.  If you invoke SCons
18010394Swendy.elsasser@arm.com# from a subdirectory you must use the '-u' flag.
18110394Swendy.elsasser@arm.comlaunch_dir = GetLaunchDir()
18210394Swendy.elsasser@arm.com
18310394Swendy.elsasser@arm.com# Build a list 'my_targets' of all the targets relative to ROOT.
18410394Swendy.elsasser@arm.comif launch_dir == ROOT:
18510394Swendy.elsasser@arm.com    # invoked from root build dir
18610561SOmar.Naji@arm.com    if len(COMMAND_LINE_TARGETS) != 0:
18710561SOmar.Naji@arm.com        # easy: use specified targets as is
18810394Swendy.elsasser@arm.com        my_targets = COMMAND_LINE_TARGETS
18910394Swendy.elsasser@arm.com    else:
19010394Swendy.elsasser@arm.com        # default target (ALPHA_SE/m5.debug, unless overridden)
19110394Swendy.elsasser@arm.com        target = os.path.join(default_config, default_binary)
19210394Swendy.elsasser@arm.com        my_targets = [target]
19310394Swendy.elsasser@arm.com        Default(target)
1949243SN/Aelse:
1959243SN/A    # invoked from subdirectory
1969243SN/A    if not launch_dir.startswith(ROOT):
19710146Sandreas.hansson@arm.com        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
19810140SN/A              (launch_dir, ROOT)
19910466Sandreas.hansson@arm.com        sys.exit(1)
20010466Sandreas.hansson@arm.com    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
20110466Sandreas.hansson@arm.com    launch_dir = launch_dir[len(ROOT)+1:]
20210146Sandreas.hansson@arm.com    if len(COMMAND_LINE_TARGETS) != 0:
20310140SN/A        # make specified targets relative to ROOT
20410140SN/A        my_targets = map(lambda x: os.path.join(launch_dir, x),
20510140SN/A                         COMMAND_LINE_TARGETS)
20610646Sandreas.hansson@arm.com    else:
20710646Sandreas.hansson@arm.com        # build default binary (m5.debug, unless overridden) using the
20810646Sandreas.hansson@arm.com        # config inferred by the invocation directory (the first
20910646Sandreas.hansson@arm.com        # subdirectory after ROOT)
21010646Sandreas.hansson@arm.com        target = os.path.join(launch_dir.split('/')[0], default_binary)
21110646Sandreas.hansson@arm.com        my_targets = [target]
21210646Sandreas.hansson@arm.com        Default(target)
21310646Sandreas.hansson@arm.com
21410646Sandreas.hansson@arm.com# Normalize target paths (gets rid of '..' in the middle, etc.)
21510646Sandreas.hansson@arm.commy_targets = map(os.path.normpath, my_targets)
21610646Sandreas.hansson@arm.com
21710646Sandreas.hansson@arm.com# Generate a list of the unique configs that the collected targets reference.
21810646Sandreas.hansson@arm.combuild_dirs = []
21910646Sandreas.hansson@arm.comfor t in my_targets:
22010646Sandreas.hansson@arm.com    dir = t.split('/')[0]
22110646Sandreas.hansson@arm.com    if dir not in build_dirs:
22210646Sandreas.hansson@arm.com        build_dirs.append(dir)
22310646Sandreas.hansson@arm.com
22410646Sandreas.hansson@arm.com###################################################
22510646Sandreas.hansson@arm.com#
22610646Sandreas.hansson@arm.com# Set up the default build environment.  This environment is copied
22710646Sandreas.hansson@arm.com# and modified according to each selected configuration.
22810646Sandreas.hansson@arm.com#
22910646Sandreas.hansson@arm.com###################################################
23010646Sandreas.hansson@arm.com
23110646Sandreas.hansson@arm.comdefault_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
23210646Sandreas.hansson@arm.com                          ROOT = ROOT,
23310646Sandreas.hansson@arm.com                          SRCDIR = SRCDIR,
23410646Sandreas.hansson@arm.com                          EXT_SRCDIR = EXT_SRCDIR,
23510646Sandreas.hansson@arm.com                          CPPDEFINES = [],
23610646Sandreas.hansson@arm.com                          FULL_SYSTEM = False,
23710646Sandreas.hansson@arm.com                          ALPHA_TLASER = False,
23810646Sandreas.hansson@arm.com                          USE_MYSQL = False)
23910646Sandreas.hansson@arm.com
24010646Sandreas.hansson@arm.comdefault_env.SConsignFile("sconsign")
24110646Sandreas.hansson@arm.com
24210646Sandreas.hansson@arm.com# For some reason, the CC and CXX variables don't get passed into the
24310646Sandreas.hansson@arm.com# environment correctly.  This is probably some sort of scons bug that
24410646Sandreas.hansson@arm.com# will eventually be fixed.
24510646Sandreas.hansson@arm.comif os.environ.has_key('CC'):
24610140SN/A    default_env.Replace(CC=os.environ['CC'])
24710140SN/A
24810140SN/Aif os.environ.has_key('CXX'):
24910146Sandreas.hansson@arm.com    default_env.Replace(CXX=os.environ['CXX'])
2509243SN/A
25110619Sandreas.hansson@arm.com# M5_EXT is used by isa_parser.py to find the PLY package.
25210619Sandreas.hansson@arm.comdefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
25310618SOmar.Naji@arm.com
25410619Sandreas.hansson@arm.comdefault_env.Append(CCFLAGS='-pipe')
25510619Sandreas.hansson@arm.comdefault_env.Append(CCFLAGS='-fno-strict-aliasing')
25610619Sandreas.hansson@arm.comdefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
25710619Sandreas.hansson@arm.comif sys.platform == 'cygwin':
25810619Sandreas.hansson@arm.com    # cygwin has some header file issues...
25910619Sandreas.hansson@arm.com    default_env.Append(CCFLAGS=Split("-Wno-uninitialized"))
26010619Sandreas.hansson@arm.comdefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
26110619Sandreas.hansson@arm.com
26210619Sandreas.hansson@arm.com# libelf build is described in its own SConscript file.  Using a
26310619Sandreas.hansson@arm.com# dictionary for exports lets us export "default_env" so the
26410619Sandreas.hansson@arm.com# SConscript will see it as "env".  SConscript-global is the build in
26510619Sandreas.hansson@arm.com# build/libelf shared among all configs.
26610619Sandreas.hansson@arm.comdefault_env.SConscript('m5/libelf/SConscript-global',
26710619Sandreas.hansson@arm.com                       exports={'env' : default_env})
26810619Sandreas.hansson@arm.com
26910618SOmar.Naji@arm.com###################################################
2709243SN/A#
2719243SN/A# Define build environments for selected configurations.
2729243SN/A#
27310146Sandreas.hansson@arm.com###################################################
2749243SN/A
2759243SN/Afor build_dir in build_dirs:
2769243SN/A    # Make a copy of the default environment to use for this config.
2779243SN/A    env = default_env.Copy()
2789243SN/A    # Modify 'env' according to the build directory config.
2799243SN/A    print "Configuring options for directory '%s'." % build_dir
2809243SN/A    if not set_dir_options(build_dir, env):
2819243SN/A        print "Skipping directory '%s'." % build_dir
2829243SN/A        continue
2839243SN/A
2849243SN/A    # The m5/SConscript file sets up the build rules in 'env' according
2859243SN/A    # to the configured options.
2869243SN/A    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
2879243SN/A               duplicate=0)
2889243SN/A
2899243SN/A
29010146Sandreas.hansson@arm.com###################################################
2919243SN/A#
2929831SN/A# Let SCons do its thing.  At this point SCons will use the defined
2939831SN/A# build environments to build the requested targets.
2949831SN/A#
2959243SN/A###################################################
2969831SN/A
2979831SN/A