SConstruct revision 955
1955SN/A# -*- mode:python -*- 2955SN/A 39812Sandreas.hansson@arm.com# Copyright (c) 2004 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# 'KERNEL/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 662761Sstever@eecs.umich.edu################################################### 672761Sstever@eecs.umich.edu# 682761Sstever@eecs.umich.edu# Define Configurations 692761Sstever@eecs.umich.edu# 702761Sstever@eecs.umich.edu# The build system infers the build options from the subdirectory name 718878Ssteve.reinhardt@amd.com# that the simulator is built under. The subdirectory name must be of 728878Ssteve.reinhardt@amd.com# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration 732632Sstever@eecs.umich.edu# (e.g., ALPHA or KERNEL) and OPT is an option (e.g., MYSQL). The 742632Sstever@eecs.umich.edu# following code defines the standard configurations and options. 758878Ssteve.reinhardt@amd.com# Additional local configurations and options are read from the file 768878Ssteve.reinhardt@amd.com# 'local_configs' if it exists. 772632Sstever@eecs.umich.edu# 78955SN/A# Each base configuration or option is defined in two steps: a 79955SN/A# function that takes an SCons build environment and modifies it 80955SN/A# 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 928878Ssteve.reinhardt@amd.com# 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) 969812Sandreas.hansson@arm.com env.Append(CPPDEFINES = ['FULL_SYSTEM', 'SYSTEM_EV5']) 979812Sandreas.hansson@arm.com 985863Snate@binkert.org# Base configurations map. 999812Sandreas.hansson@arm.comconfigs_map = { 1005863Snate@binkert.org 'ALPHA' : AlphaConfig, 1015863Snate@binkert.org 'KERNEL' : KernelConfig 1025863Snate@binkert.org } 1039812Sandreas.hansson@arm.com 1049812Sandreas.hansson@arm.com# Enable detailed full-system binning. 1055863Snate@binkert.orgdef MeasureOpt(env): 1065863Snate@binkert.org env.Replace(USE_MYSQL = True) 1078878Ssteve.reinhardt@amd.com env.Append(CPPDEFINES = 'FS_MEASURE') 1085863Snate@binkert.org 1095863Snate@binkert.org# Enable MySql database output for stats. 1105863Snate@binkert.orgdef MySqlOpt(env): 1116654Snate@binkert.org env.Replace(USE_MYSQL = True) 11210196SCurtis.Dunham@arm.com 113955SN/A# Disable FastAlloc object allocation. 1145396Ssaidi@eecs.umich.edudef NoFastAllocOpt(env): 1155863Snate@binkert.org env.Append(CPPDEFINES = 'NO_FAST_ALLOC') 1165863Snate@binkert.org 1174202Sbinkertn@umich.edu# Configuration options map. 1185863Snate@binkert.orgoptions_map = { 1195863Snate@binkert.org 'MEASURE' : MeasureOpt, 1205863Snate@binkert.org 'MYSQL' : MySqlOpt, 1215863Snate@binkert.org 'NO_FAST_ALLOC' : NoFastAllocOpt 122955SN/A } 1236654Snate@binkert.org 1245273Sstever@gmail.com# The 'local_configs' file can be used to define additional base 1255871Snate@binkert.org# configurations and/or options without changing this file. 1265273Sstever@gmail.comif os.path.isfile('local_configs'): 1276655Snate@binkert.org SConscript('local_configs', exports = ['configs_map', 'options_map']) 1288878Ssteve.reinhardt@amd.com 1296655Snate@binkert.org# This function parses a directory name of the form <CONFIG>[.<OPT>]* 1306655Snate@binkert.org# and sets up the build environment appropriately. Returns True if 1319219Spower.jg@gmail.com# successful, False if the base config or any of the options were not 1326655Snate@binkert.org# defined. 1335871Snate@binkert.orgdef set_dir_options(dir, env): 1346654Snate@binkert.org parts = dir.split('.') 1358947Sandreas.hansson@arm.com config = parts[0] 1365396Ssaidi@eecs.umich.edu opts = parts[1:] 1378120Sgblack@eecs.umich.edu try: 1388120Sgblack@eecs.umich.edu configs_map[config](env) 1398120Sgblack@eecs.umich.edu map(lambda opt: options_map[opt](env), opts) 1408120Sgblack@eecs.umich.edu return True 1418120Sgblack@eecs.umich.edu except KeyError, key: 1428120Sgblack@eecs.umich.edu print "Config/option '%s' not found." % key 1438120Sgblack@eecs.umich.edu return False 1448120Sgblack@eecs.umich.edu 1458879Ssteve.reinhardt@amd.com# Set the default configuration and binary. The default target (if 1468879Ssteve.reinhardt@amd.com# scons is invoked at the top level with no command-line targets) is 1478879Ssteve.reinhardt@amd.com# 'ALPHA/m5.debug'. If scons is invoked in a subdirectory with no 1488879Ssteve.reinhardt@amd.com# command-line targets, the configuration 1498879Ssteve.reinhardt@amd.com 1508879Ssteve.reinhardt@amd.com################################################### 1518879Ssteve.reinhardt@amd.com# 1528879Ssteve.reinhardt@amd.com# Figure out which configurations to set up. 1538879Ssteve.reinhardt@amd.com# 1548879Ssteve.reinhardt@amd.com# 1558879Ssteve.reinhardt@amd.com# It's prohibitive to do all the combinations of base configurations 1568879Ssteve.reinhardt@amd.com# and options, so we have to infer which ones the user wants. 1578879Ssteve.reinhardt@amd.com# 1588120Sgblack@eecs.umich.edu# 1. If there are command-line targets, the configuration(s) are inferred 1598120Sgblack@eecs.umich.edu# from the directories of those targets. If scons was invoked from a 1608120Sgblack@eecs.umich.edu# subdirectory (using 'scons -u'), those targets have to be 1618120Sgblack@eecs.umich.edu# interpreted relative to that subdirectory. 1628120Sgblack@eecs.umich.edu# 1638120Sgblack@eecs.umich.edu# 2. If there are no command-line targets, and scons was invoked from a 1648120Sgblack@eecs.umich.edu# subdirectory (using 'scons -u'), the configuration is inferred from 1658120Sgblack@eecs.umich.edu# the name of the subdirectory. 1668120Sgblack@eecs.umich.edu# 1678120Sgblack@eecs.umich.edu# 3. If there are no command-line targets and scons was invoked from 1688120Sgblack@eecs.umich.edu# the root build directory, a default configuration is used. The 1698120Sgblack@eecs.umich.edu# built-in default is ALPHA, but this can be overridden by setting the 1708120Sgblack@eecs.umich.edu# M5_DEFAULT_CONFIG shell environment veriable. 1718120Sgblack@eecs.umich.edu# 1728879Ssteve.reinhardt@amd.com# In cases 2 & 3, the specific file target defaults to 'm5.debug', but 1738879Ssteve.reinhardt@amd.com# this can be overridden by setting the M5_DEFAULT_BINARY shell 1748879Ssteve.reinhardt@amd.com# environment veriable. 1758879Ssteve.reinhardt@amd.com# 1768879Ssteve.reinhardt@amd.com################################################### 1778879Ssteve.reinhardt@amd.com 1788879Ssteve.reinhardt@amd.com# Find default configuration & binary. 1798879Ssteve.reinhardt@amd.comdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA') 1809227Sandreas.hansson@arm.comdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug') 1819227Sandreas.hansson@arm.com 1828879Ssteve.reinhardt@amd.com# Ask SCons which directory it was invoked from. If you invoke SCons 1838879Ssteve.reinhardt@amd.com# from a subdirectory you must use the '-u' flag. 1848879Ssteve.reinhardt@amd.comlaunch_dir = GetLaunchDir() 1858879Ssteve.reinhardt@amd.com 1868120Sgblack@eecs.umich.edu# Build a list 'my_targets' of all the targets relative to ROOT. 1878947Sandreas.hansson@arm.comif launch_dir == ROOT: 1887816Ssteve.reinhardt@amd.com # invoked from root build dir 1895871Snate@binkert.org if len(COMMAND_LINE_TARGETS) != 0: 1905871Snate@binkert.org # easy: use specified targets as is 1916121Snate@binkert.org my_targets = COMMAND_LINE_TARGETS 1925871Snate@binkert.org else: 1935871Snate@binkert.org # default target (ALPHA/m5.debug, unless overridden) 1949926Sstan.czerniawski@arm.com target = os.path.join(default_config, default_binary) 1959926Sstan.czerniawski@arm.com my_targets = [target] 1969119Sandreas.hansson@arm.com Default(target) 19710068Sandreas.hansson@arm.comelse: 19810068Sandreas.hansson@arm.com # invoked from subdirectory 199955SN/A if not launch_dir.startswith(ROOT): 2009416SAndreas.Sandberg@ARM.com print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \ 2019416SAndreas.Sandberg@ARM.com (launch_dir, ROOT) 2029416SAndreas.Sandberg@ARM.com sys.exit(1) 2039416SAndreas.Sandberg@ARM.com # make launch_dir relative to ROOT (strip ROOT plus slash off front) 2049416SAndreas.Sandberg@ARM.com launch_dir = launch_dir[len(ROOT)+1:] 2059416SAndreas.Sandberg@ARM.com if len(COMMAND_LINE_TARGETS) != 0: 2069416SAndreas.Sandberg@ARM.com # 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) 2099416SAndreas.Sandberg@ARM.com else: 2109416SAndreas.Sandberg@ARM.com # build default binary (m5.debug, unless overridden) using the 2115871Snate@binkert.org # config inferred by the invocation directory (the first 212955SN/A # subdirectory after ROOT) 2136121Snate@binkert.org target = os.path.join(launch_dir.split('/')[0], default_binary) 2148881Smarc.orr@gmail.com my_targets = [target] 2156121Snate@binkert.org Default(target) 2166121Snate@binkert.org 2171533SN/A# Normalize target paths (gets rid of '..' in the middle, etc.) 2189239Sandreas.hansson@arm.commy_targets = map(os.path.normpath, my_targets) 2199239Sandreas.hansson@arm.com 2209239Sandreas.hansson@arm.com# Generate a list of the unique configs that the collected targets reference. 2219239Sandreas.hansson@arm.combuild_dirs = [] 2229239Sandreas.hansson@arm.comfor t in my_targets: 2239239Sandreas.hansson@arm.com dir = t.split('/')[0] 2249239Sandreas.hansson@arm.com if dir not in build_dirs: 2259239Sandreas.hansson@arm.com build_dirs.append(dir) 2269239Sandreas.hansson@arm.com 2279239Sandreas.hansson@arm.com################################################### 2289239Sandreas.hansson@arm.com# 2299239Sandreas.hansson@arm.com# Set up the default build environment. This environment is copied 2306655Snate@binkert.org# and modified according to each selected configuration. 2316655Snate@binkert.org# 2326655Snate@binkert.org################################################### 2336655Snate@binkert.org 2345871Snate@binkert.orgdefault_env = Environment(ENV = os.environ, # inherit user's enviroment vars 2355871Snate@binkert.org ROOT = ROOT, 2365863Snate@binkert.org SRCDIR = SRCDIR, 2375871Snate@binkert.org EXT_SRCDIR = EXT_SRCDIR, 2388878Ssteve.reinhardt@amd.com CPPDEFINES = [], 2395871Snate@binkert.org FULL_SYSTEM = False, 2405871Snate@binkert.org USE_MYSQL = False) 2415871Snate@binkert.org 2425863Snate@binkert.org# M5_EXT is used by isa_parser.py to find the PLY package. 2436121Snate@binkert.orgdefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR }) 2445863Snate@binkert.org 2455871Snate@binkert.orgdefault_env.Append(CCFLAGS='-pipe') 2468336Ssteve.reinhardt@amd.comdefault_env.Append(CCFLAGS='-fno-strict-aliasing') 2478336Ssteve.reinhardt@amd.comdefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2488336Ssteve.reinhardt@amd.com 2498336Ssteve.reinhardt@amd.com# libelf build is described in its own SConscript file. Using a 2504678Snate@binkert.org# dictionary for exports lets us export "default_env" so the 2518336Ssteve.reinhardt@amd.com# SConscript will see it as "env". 2528336Ssteve.reinhardt@amd.comdefault_env.SConscript('m5/libelf/SConscript', exports={'env' : default_env}) 2538336Ssteve.reinhardt@amd.com 2544678Snate@binkert.org 2554678Snate@binkert.org################################################### 2564678Snate@binkert.org# 2574678Snate@binkert.org# Define build environments for selected configurations. 2587827Snate@binkert.org# 2597827Snate@binkert.org################################################### 2608336Ssteve.reinhardt@amd.com 2614678Snate@binkert.orgfor build_dir in build_dirs: 2628336Ssteve.reinhardt@amd.com # Make a copy of the default environment to use for this config. 2638336Ssteve.reinhardt@amd.com env = default_env.Copy() 2648336Ssteve.reinhardt@amd.com # Modify 'env' according to the build directory config. 2658336Ssteve.reinhardt@amd.com print "Configuring options for directory '%s'." % build_dir 2668336Ssteve.reinhardt@amd.com if not set_dir_options(build_dir, env): 2678336Ssteve.reinhardt@amd.com print "Skipping directory '%s'." % build_dir 2685871Snate@binkert.org continue 2695871Snate@binkert.org 2708336Ssteve.reinhardt@amd.com # The m5/SConscript file sets up the build rules in 'env' according 2718336Ssteve.reinhardt@amd.com # to the configured options. 2728336Ssteve.reinhardt@amd.com SConscript('m5/SConscript', build_dir = build_dir, exports = 'env', 2738336Ssteve.reinhardt@amd.com duplicate=0) 2748336Ssteve.reinhardt@amd.com 2755871Snate@binkert.org 2768336Ssteve.reinhardt@amd.com################################################### 2778336Ssteve.reinhardt@amd.com# 2788336Ssteve.reinhardt@amd.com# Let SCons do its thing. At this point SCons will use the defined 2798336Ssteve.reinhardt@amd.com# build enviornments to build the requested targets. 2808336Ssteve.reinhardt@amd.com# 2814678Snate@binkert.org################################################### 2825871Snate@binkert.org 2834678Snate@binkert.org