SConstruct revision 1851
18926Sandreas.hansson@arm.com# -*- mode:python -*-
27586SAli.Saidi@arm.com
37586SAli.Saidi@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
47586SAli.Saidi@arm.com# All rights reserved.
57586SAli.Saidi@arm.com#
67586SAli.Saidi@arm.com# Redistribution and use in source and binary forms, with or without
77586SAli.Saidi@arm.com# modification, are permitted provided that the following conditions are
87586SAli.Saidi@arm.com# met: redistributions of source code must retain the above copyright
97586SAli.Saidi@arm.com# notice, this list of conditions and the following disclaimer;
107586SAli.Saidi@arm.com# redistributions in binary form must reproduce the above copyright
117586SAli.Saidi@arm.com# notice, this list of conditions and the following disclaimer in the
127586SAli.Saidi@arm.com# documentation and/or other materials provided with the distribution;
133970Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
143005Sstever@eecs.umich.edu# contributors may be used to endorse or promote products derived from
153005Sstever@eecs.umich.edu# this software without specific prior written permission.
163005Sstever@eecs.umich.edu#
173005Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
183005Sstever@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
193005Sstever@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
203005Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
213005Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
223005Sstever@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
233005Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
243005Sstever@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
253005Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
263005Sstever@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
273005Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
283005Sstever@eecs.umich.edu
293005Sstever@eecs.umich.edu###################################################
303005Sstever@eecs.umich.edu#
313005Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file.
323005Sstever@eecs.umich.edu#
333005Sstever@eecs.umich.edu# To build M5, you need a directory with three things:
343005Sstever@eecs.umich.edu# 1. A copy of this file (named SConstruct).
353005Sstever@eecs.umich.edu# 2. A link named 'm5' to the top of the M5 simulator source tree.
363005Sstever@eecs.umich.edu# 3. A link named 'ext' to the top of the M5 external source tree.
373005Sstever@eecs.umich.edu#
383005Sstever@eecs.umich.edu# Then type 'scons' to build the default configuration (see below), or
393005Sstever@eecs.umich.edu# 'scons <CONFIG>/<binary>' to build some other configuration (e.g.,
403005Sstever@eecs.umich.edu# 'ALPHA_FS/m5.opt' for the optimized full-system version).
416654Snate@binkert.org#
426654Snate@binkert.org###################################################
432889SN/A
442710SN/A# Python library imports
456654Snate@binkert.orgimport sys
466654Snate@binkert.orgimport os
476654Snate@binkert.org
485457Ssaidi@eecs.umich.edu# The absolute path to the current directory (where this file lives).
496654Snate@binkert.orgROOT = Dir('.').abspath
506654Snate@binkert.org
512934SN/A# Paths to the M5 and external source trees (local symlinks).
522549SN/ASRCDIR = os.path.join(ROOT, 'm5')
532995SN/AEXT_SRCDIR = os.path.join(ROOT, 'ext')
543395Shsul@eecs.umich.edu
556981SLisa.Hsu@amd.com# Check for 'm5' and 'ext' links, die if they don't exist.
563448Shsul@eecs.umich.eduif not os.path.isdir(SRCDIR):
578920Snilay@cs.wisc.edu    print "Error: '%s' must be a link to the M5 source tree." % SRCDIR
583444Sktlim@umich.edu    sys.exit(1)
592889SN/A
608920Snilay@cs.wisc.eduif not os.path.isdir('ext'):
618920Snilay@cs.wisc.edu    print "Error: '%s' must be a link to the M5 external source tree." \
623322Shsul@eecs.umich.edu          % EXT_SRCDIR
632710SN/A    sys.exit(1)
642710SN/A
652710SN/A# tell python where to find m5 python code
662710SN/Asys.path.append(os.path.join(SRCDIR, 'python'))
672710SN/A
682710SN/A
693322Shsul@eecs.umich.edu###################################################
703304Sstever@eecs.umich.edu#
713322Shsul@eecs.umich.edu# Define Configurations
723322Shsul@eecs.umich.edu#
733304Sstever@eecs.umich.edu# The build system infers the build options from the subdirectory name
743481Shsul@eecs.umich.edu# that the simulator is built under.  The subdirectory name must be of
753481Shsul@eecs.umich.edu# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration
762566SN/A# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL).  The
779129Sandreas.hansson@arm.com# following code defines the standard configurations and options.
789129Sandreas.hansson@arm.com# Additional local configurations and options are read from the file
792995SN/A# 'local_configs' if it exists.
802995SN/A#
813304Sstever@eecs.umich.edu# Each base configuration or option is defined in two steps: a
823304Sstever@eecs.umich.edu# function that takes an SCons build environment and modifies it
833304Sstever@eecs.umich.edu# appropriately for that config or option, and an entry in the
842995SN/A# 'configs_map' or 'options_map' dictionary that maps the directory
852995SN/A# name string to the function.  (The directory names are all upper
862995SN/A# case, by convention.)
872917SN/A#
882995SN/A###################################################
898956Sjayneel@cs.wisc.edu
902995SN/A# Base non-full-system Alpha ISA configuration.
918956Sjayneel@cs.wisc.edudef AlphaSyscallEmulConfig(env):
923304Sstever@eecs.umich.edu    env.Replace(TARGET_ISA = 'alpha')
936135Sgblack@eecs.umich.edu    env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP')
946135Sgblack@eecs.umich.edu
956654Snate@binkert.org# Base full-system configuration.
963819Shsul@eecs.umich.edudef AlphaFullSysConfig(env):
976654Snate@binkert.org    env.Replace(TARGET_ISA = 'alpha')
985222Sksewell@umich.edu    env.Replace(FULL_SYSTEM = True)
996654Snate@binkert.org    env.Append(CPPDEFINES = ['FULL_SYSTEM'])
1003819Shsul@eecs.umich.edu
1016654Snate@binkert.org# Base configurations map.
1027925Sgblack@eecs.umich.educonfigs_map = {
1037586SAli.Saidi@arm.com    'ALPHA_SE' : AlphaSyscallEmulConfig,
1048061SAli.Saidi@ARM.com    'ALPHA_FS' : AlphaFullSysConfig
1058061SAli.Saidi@ARM.com    }
1068061SAli.Saidi@ARM.com
1073819Shsul@eecs.umich.edu# Disable FastAlloc object allocation.
1089059Snilay@cs.wisc.edudef NoFastAllocOpt(env):
1093819Shsul@eecs.umich.edu    env.Append(CPPDEFINES = 'NO_FAST_ALLOC')
1103873Sbinkertn@umich.edu
1113873Sbinkertn@umich.edu# Enable efence
1123873Sbinkertn@umich.edudef EfenceOpt(env):
1133873Sbinkertn@umich.edu    env.Append(LIBS=['efence'])
1143873Sbinkertn@umich.edu
1153873Sbinkertn@umich.edu# Configuration options map.
1168659SAli.Saidi@ARM.comoptions_map = {
1178659SAli.Saidi@ARM.com    'NO_FAST_ALLOC' : NoFastAllocOpt,
1186995Sgblack@eecs.umich.edu    'EFENCE' : EfenceOpt
1193668Srdreslin@umich.edu    }
1206636Ssteve.reinhardt@amd.com
1219288Sandreas.hansson@arm.com# The 'local_configs' file can be used to define additional base
1229408Sandreas.hansson@arm.com# configurations and/or options without changing this file.
1238839Sandreas.hansson@arm.comif os.path.isfile('local_configs'):
1248839Sandreas.hansson@arm.com    SConscript('local_configs', exports = ['configs_map', 'options_map'])
1258713Sandreas.hansson@arm.com
1269408Sandreas.hansson@arm.com# This function parses a directory name of the form <CONFIG>[.<OPT>]*
1278839Sandreas.hansson@arm.com# and sets up the build environment appropriately.  Returns True if
1288839Sandreas.hansson@arm.com# successful, False if the base config or any of the options were not
1295142Ssaidi@eecs.umich.edu# defined.
1308926Sandreas.hansson@arm.comdef set_dir_options(dir, env):
1319317Sandreas.hansson@arm.com    parts = dir.split('.')
1329317Sandreas.hansson@arm.com    config = parts[0]
1339317Sandreas.hansson@arm.com    opts = parts[1:]
1349317Sandreas.hansson@arm.com    try:
1359317Sandreas.hansson@arm.com        configs_map[config](env)
1368926Sandreas.hansson@arm.com        map(lambda opt: options_map[opt](env), opts)
1373312Sstever@eecs.umich.edu        return True
1384968Sacolyte@umich.edu    except KeyError, key:
1398926Sandreas.hansson@arm.com        print "Config/option '%s' not found." % key
1408887Sgeoffrey.blake@arm.com        return False
1418887Sgeoffrey.blake@arm.com
1429384SAndreas.Sandberg@arm.com# Set the default configuration and binary.  The default target (if
1438887Sgeoffrey.blake@arm.com# scons is invoked at the top level with no command-line targets) is
1448887Sgeoffrey.blake@arm.com# 'ALPHA_SE/m5.debug'.  If scons is invoked in a subdirectory with no
1454968Sacolyte@umich.edu# command-line targets, the configuration
1463005Sstever@eecs.umich.edu
1476654Snate@binkert.org###################################################
1483819Shsul@eecs.umich.edu#
1496654Snate@binkert.org# Figure out which configurations to set up.
1505222Sksewell@umich.edu#
1516654Snate@binkert.org#
1523819Shsul@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations
1536654Snate@binkert.org# and options, so we have to infer which ones the user wants.
1546135Sgblack@eecs.umich.edu#
1557586SAli.Saidi@arm.com# 1. If there are command-line targets, the configuration(s) are inferred
1568661SAli.Saidi@ARM.com#    from the directories of those targets.  If scons was invoked from a
1578661SAli.Saidi@ARM.com#    subdirectory (using 'scons -u'), those targets have to be
1583322Shsul@eecs.umich.edu#    interpreted relative to that subdirectory.
1599384SAndreas.Sandberg@arm.com#
1608863Snilay@cs.wisc.edu# 2. If there are no command-line targets, and scons was invoked from a
1617876Sgblack@eecs.umich.edu#    subdirectory (using 'scons -u'), the configuration is inferred from
1624968Sacolyte@umich.edu#    the name of the subdirectory.
1638926Sandreas.hansson@arm.com#
1644837Ssaidi@eecs.umich.edu# 3. If there are no command-line targets and scons was invoked from
1654837Ssaidi@eecs.umich.edu#    the root build directory, a default configuration is used.  The
1669408Sandreas.hansson@arm.com#    built-in default is ALPHA_SE, but this can be overridden by setting the
1679164Sandreas.hansson@arm.com#    M5_DEFAULT_CONFIG shell environment veriable.
1689408Sandreas.hansson@arm.com#
1698845Sandreas.hansson@arm.com# In cases 2 & 3, the specific file target defaults to 'm5.debug', but
1708845Sandreas.hansson@arm.com# this can be overridden by setting the M5_DEFAULT_BINARY shell
1714837Ssaidi@eecs.umich.edu# environment veriable.
1728659SAli.Saidi@ARM.com#
1738801Sgblack@eecs.umich.edu###################################################
1743005Sstever@eecs.umich.edu
1758801Sgblack@eecs.umich.edu# Find default configuration & binary.
1763005Sstever@eecs.umich.edudefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE')
1773005Sstever@eecs.umich.edudefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug')
1783005Sstever@eecs.umich.edu
1792566SN/A# Ask SCons which directory it was invoked from.  If you invoke SCons
1807861Sgblack@eecs.umich.edu# from a subdirectory you must use the '-u' flag.
1817861Sgblack@eecs.umich.edulaunch_dir = GetLaunchDir()
1827861Sgblack@eecs.umich.edu
1838635Schris.emmons@arm.com# Build a list 'my_targets' of all the targets relative to ROOT.
1848635Schris.emmons@arm.comif launch_dir == ROOT:
1858635Schris.emmons@arm.com    # invoked from root build dir
1869061Snilay@cs.wisc.edu    if len(COMMAND_LINE_TARGETS) != 0:
1873481Shsul@eecs.umich.edu        # easy: use specified targets as is
188        my_targets = COMMAND_LINE_TARGETS
189    else:
190        # default target (ALPHA_SE/m5.debug, unless overridden)
191        target = os.path.join(default_config, default_binary)
192        my_targets = [target]
193        Default(target)
194else:
195    # invoked from subdirectory
196    if not launch_dir.startswith(ROOT):
197        print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \
198              (launch_dir, ROOT)
199        sys.exit(1)
200    # make launch_dir relative to ROOT (strip ROOT plus slash off front)
201    launch_dir = launch_dir[len(ROOT)+1:]
202    if len(COMMAND_LINE_TARGETS) != 0:
203        # make specified targets relative to ROOT
204        my_targets = map(lambda x: os.path.join(launch_dir, x),
205                         COMMAND_LINE_TARGETS)
206    else:
207        # build default binary (m5.debug, unless overridden) using the
208        # config inferred by the invocation directory (the first
209        # subdirectory after ROOT)
210        target = os.path.join(launch_dir.split('/')[0], default_binary)
211        my_targets = [target]
212        Default(target)
213
214# Normalize target paths (gets rid of '..' in the middle, etc.)
215my_targets = map(os.path.normpath, my_targets)
216
217# Generate a list of the unique configs that the collected targets reference.
218build_dirs = []
219for t in my_targets:
220    dir = t.split('/')[0]
221    if dir not in build_dirs:
222        build_dirs.append(dir)
223
224###################################################
225#
226# Set up the default build environment.  This environment is copied
227# and modified according to each selected configuration.
228#
229###################################################
230
231default_env = Environment(ENV = os.environ,  # inherit user's enviroment vars
232                          ROOT = ROOT,
233                          SRCDIR = SRCDIR,
234                          EXT_SRCDIR = EXT_SRCDIR,
235                          CPPDEFINES = [],
236                          FULL_SYSTEM = False,
237                          ALPHA_TLASER = False,
238                          USE_MYSQL = False)
239
240default_env.SConsignFile("sconsign")
241
242# For some reason, the CC and CXX variables don't get passed into the
243# environment correctly.  This is probably some sort of scons bug that
244# will eventually be fixed.
245if os.environ.has_key('CC'):
246    default_env.Replace(CC=os.environ['CC'])
247
248if os.environ.has_key('CXX'):
249    default_env.Replace(CXX=os.environ['CXX'])
250
251# M5_EXT is used by isa_parser.py to find the PLY package.
252default_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR })
253
254default_env.Append(CCFLAGS='-pipe')
255default_env.Append(CCFLAGS='-fno-strict-aliasing')
256default_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef'))
257if sys.platform == 'cygwin':
258    # cygwin has some header file issues...
259    default_env.Append(CCFLAGS=Split("-Wno-uninitialized"))
260default_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')])
261
262# libelf build is described in its own SConscript file.  Using a
263# dictionary for exports lets us export "default_env" so the
264# SConscript will see it as "env".  SConscript-global is the build in
265# build/libelf shared among all configs.
266default_env.SConscript('m5/libelf/SConscript-global',
267                       exports={'env' : default_env})
268
269###################################################
270#
271# Define build environments for selected configurations.
272#
273###################################################
274
275for build_dir in build_dirs:
276    # Make a copy of the default environment to use for this config.
277    env = default_env.Copy()
278    # Modify 'env' according to the build directory config.
279    print "Configuring options for directory '%s'." % build_dir
280    if not set_dir_options(build_dir, env):
281        print "Skipping directory '%s'." % build_dir
282        continue
283
284    # The m5/SConscript file sets up the build rules in 'env' according
285    # to the configured options.
286    SConscript('m5/SConscript', build_dir = build_dir, exports = 'env',
287               duplicate=0)
288
289
290###################################################
291#
292# Let SCons do its thing.  At this point SCons will use the defined
293# build environments to build the requested targets.
294#
295###################################################
296
297