SConstruct revision 955
1955SN/A# -*- mode:python -*- 2955SN/A 313576Sciro.santilli@arm.com# Copyright (c) 2004 The Regents of The University of Michigan 413576Sciro.santilli@arm.com# All rights reserved. 513576Sciro.santilli@arm.com# 613576Sciro.santilli@arm.com# Redistribution and use in source and binary forms, with or without 713576Sciro.santilli@arm.com# modification, are permitted provided that the following conditions are 813576Sciro.santilli@arm.com# met: redistributions of source code must retain the above copyright 913576Sciro.santilli@arm.com# notice, this list of conditions and the following disclaimer; 1013576Sciro.santilli@arm.com# redistributions in binary form must reproduce the above copyright 1113576Sciro.santilli@arm.com# notice, this list of conditions and the following disclaimer in the 1213576Sciro.santilli@arm.com# documentation and/or other materials provided with the distribution; 1313576Sciro.santilli@arm.com# neither the name of the copyright holders nor the names of its 141762SN/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. 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 392665Ssaidi@eecs.umich.edu# 'scons <CONFIG>/<binary>' to build some other configuration (e.g., 404762Snate@binkert.org# 'KERNEL/m5.opt' for the optimized full-system version). 41955SN/A# 4212563Sgabeblack@google.com################################################### 4312563Sgabeblack@google.com 445522Snate@binkert.org# Python library imports 456143Snate@binkert.orgimport sys 4612371Sgabeblack@google.comimport os 474762Snate@binkert.org 485522Snate@binkert.org# The absolute path to the current directory (where this file lives). 49955SN/AROOT = Dir('.').abspath 505522Snate@binkert.org 5111974Sgabeblack@google.com# Paths to the M5 and external source trees (local symlinks). 52955SN/ASRCDIR = os.path.join(ROOT, 'm5') 535522Snate@binkert.orgEXT_SRCDIR = os.path.join(ROOT, 'ext') 544202Sbinkertn@umich.edu 555742Snate@binkert.org# Check for 'm5' and 'ext' links, die if they don't exist. 56955SN/Aif not os.path.isdir(SRCDIR): 574381Sbinkertn@umich.edu print "Error: '%s' must be a link to the M5 source tree." % SRCDIR 584381Sbinkertn@umich.edu sys.exit(1) 5912246Sgabeblack@google.com 6012246Sgabeblack@google.comif not os.path.isdir('ext'): 618334Snate@binkert.org print "Error: '%s' must be a link to the M5 external source tree." \ 62955SN/A % EXT_SRCDIR 63955SN/A sys.exit(1) 644202Sbinkertn@umich.edu 65955SN/A 664382Sbinkertn@umich.edu################################################### 674382Sbinkertn@umich.edu# 684382Sbinkertn@umich.edu# Define Configurations 696654Snate@binkert.org# 705517Snate@binkert.org# The build system infers the build options from the subdirectory name 718614Sgblack@eecs.umich.edu# that the simulator is built under. The subdirectory name must be of 727674Snate@binkert.org# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration 736143Snate@binkert.org# (e.g., ALPHA or KERNEL) and OPT is an option (e.g., MYSQL). The 746143Snate@binkert.org# following code defines the standard configurations and options. 756143Snate@binkert.org# Additional local configurations and options are read from the file 7612302Sgabeblack@google.com# 'local_configs' if it exists. 7712302Sgabeblack@google.com# 7812302Sgabeblack@google.com# Each base configuration or option is defined in two steps: a 7912371Sgabeblack@google.com# function that takes an SCons build environment and modifies it 8012371Sgabeblack@google.com# appropriately for that config or option, and an entry in the 8112371Sgabeblack@google.com# 'configs_map' or 'options_map' dictionary that maps the directory 8212371Sgabeblack@google.com# name string to the function. (The directory names are all upper 8312371Sgabeblack@google.com# case, by convention.) 8412371Sgabeblack@google.com# 8512371Sgabeblack@google.com################################################### 8612371Sgabeblack@google.com 8712371Sgabeblack@google.com# Base non-full-system Alpha ISA configuration. 8812371Sgabeblack@google.comdef AlphaConfig(env): 8912371Sgabeblack@google.com env.Replace(TARGET_ISA = 'alpha') 9012371Sgabeblack@google.com env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP') 9112371Sgabeblack@google.com 9212371Sgabeblack@google.com# Base full-system configuration. 9312371Sgabeblack@google.comdef KernelConfig(env): 9412371Sgabeblack@google.com env.Replace(TARGET_ISA = 'alpha') 9512371Sgabeblack@google.com env.Replace(FULL_SYSTEM = True) 9612371Sgabeblack@google.com env.Append(CPPDEFINES = ['FULL_SYSTEM', 'SYSTEM_EV5']) 9712371Sgabeblack@google.com 9812371Sgabeblack@google.com# Base configurations map. 9912371Sgabeblack@google.comconfigs_map = { 10012371Sgabeblack@google.com 'ALPHA' : AlphaConfig, 10112371Sgabeblack@google.com 'KERNEL' : KernelConfig 10212371Sgabeblack@google.com } 10312371Sgabeblack@google.com 10412371Sgabeblack@google.com# Enable detailed full-system binning. 10512371Sgabeblack@google.comdef MeasureOpt(env): 10612371Sgabeblack@google.com env.Replace(USE_MYSQL = True) 10712371Sgabeblack@google.com env.Append(CPPDEFINES = 'FS_MEASURE') 10812371Sgabeblack@google.com 10912371Sgabeblack@google.com# Enable MySql database output for stats. 11012371Sgabeblack@google.comdef MySqlOpt(env): 11112371Sgabeblack@google.com env.Replace(USE_MYSQL = True) 11212371Sgabeblack@google.com 11312371Sgabeblack@google.com# Disable FastAlloc object allocation. 11412371Sgabeblack@google.comdef NoFastAllocOpt(env): 11512371Sgabeblack@google.com env.Append(CPPDEFINES = 'NO_FAST_ALLOC') 11612371Sgabeblack@google.com 11712371Sgabeblack@google.com# Configuration options map. 11812371Sgabeblack@google.comoptions_map = { 11912371Sgabeblack@google.com 'MEASURE' : MeasureOpt, 12012371Sgabeblack@google.com 'MYSQL' : MySqlOpt, 12112371Sgabeblack@google.com 'NO_FAST_ALLOC' : NoFastAllocOpt 12212371Sgabeblack@google.com } 12312371Sgabeblack@google.com 12412371Sgabeblack@google.com# The 'local_configs' file can be used to define additional base 12512371Sgabeblack@google.com# configurations and/or options without changing this file. 12612302Sgabeblack@google.comif os.path.isfile('local_configs'): 12712371Sgabeblack@google.com SConscript('local_configs', exports = ['configs_map', 'options_map']) 12812302Sgabeblack@google.com 12912371Sgabeblack@google.com# This function parses a directory name of the form <CONFIG>[.<OPT>]* 13012302Sgabeblack@google.com# and sets up the build environment appropriately. Returns True if 13112302Sgabeblack@google.com# successful, False if the base config or any of the options were not 13212371Sgabeblack@google.com# defined. 13312371Sgabeblack@google.comdef set_dir_options(dir, env): 13412371Sgabeblack@google.com parts = dir.split('.') 13512371Sgabeblack@google.com config = parts[0] 13612302Sgabeblack@google.com opts = parts[1:] 13712371Sgabeblack@google.com try: 13812371Sgabeblack@google.com configs_map[config](env) 13912371Sgabeblack@google.com map(lambda opt: options_map[opt](env), opts) 14012371Sgabeblack@google.com return True 14111983Sgabeblack@google.com except KeyError, key: 1426143Snate@binkert.org print "Config/option '%s' not found." % key 1438233Snate@binkert.org return False 14412302Sgabeblack@google.com 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 14712302Sgabeblack@google.com# 'ALPHA/m5.debug'. If scons is invoked in a subdirectory with no 1484762Snate@binkert.org# command-line targets, the configuration 1496143Snate@binkert.org 1508233Snate@binkert.org################################################### 1518233Snate@binkert.org# 15212302Sgabeblack@google.com# Figure out which configurations to set up. 15312302Sgabeblack@google.com# 1546143Snate@binkert.org# 15512362Sgabeblack@google.com# It's prohibitive to do all the combinations of base configurations 15612362Sgabeblack@google.com# and options, so we have to infer which ones the user wants. 15712362Sgabeblack@google.com# 15812362Sgabeblack@google.com# 1. If there are command-line targets, the configuration(s) are inferred 15912302Sgabeblack@google.com# from the directories of those targets. If scons was invoked from a 16012302Sgabeblack@google.com# subdirectory (using 'scons -u'), those targets have to be 16112302Sgabeblack@google.com# interpreted relative to that subdirectory. 16212302Sgabeblack@google.com# 16312302Sgabeblack@google.com# 2. If there are no command-line targets, and scons was invoked from a 16412363Sgabeblack@google.com# subdirectory (using 'scons -u'), the configuration is inferred from 16512363Sgabeblack@google.com# the name of the subdirectory. 16612363Sgabeblack@google.com# 16712363Sgabeblack@google.com# 3. If there are no command-line targets and scons was invoked from 16812302Sgabeblack@google.com# the root build directory, a default configuration is used. The 16912363Sgabeblack@google.com# built-in default is ALPHA, but this can be overridden by setting the 17012363Sgabeblack@google.com# M5_DEFAULT_CONFIG shell environment veriable. 17112363Sgabeblack@google.com# 17212363Sgabeblack@google.com# In cases 2 & 3, the specific file target defaults to 'm5.debug', but 17312363Sgabeblack@google.com# this can be overridden by setting the M5_DEFAULT_BINARY shell 1748233Snate@binkert.org# environment veriable. 1756143Snate@binkert.org# 1766143Snate@binkert.org################################################### 1776143Snate@binkert.org 1786143Snate@binkert.org# Find default configuration & binary. 1796143Snate@binkert.orgdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA') 1806143Snate@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 1836143Snate@binkert.org# from a subdirectory you must use the '-u' flag. 1847065Snate@binkert.orglaunch_dir = GetLaunchDir() 1856143Snate@binkert.org 18612362Sgabeblack@google.com# Build a list 'my_targets' of all the targets relative to ROOT. 18712362Sgabeblack@google.comif launch_dir == ROOT: 18812362Sgabeblack@google.com # invoked from root build dir 18912362Sgabeblack@google.com if len(COMMAND_LINE_TARGETS) != 0: 19012362Sgabeblack@google.com # easy: use specified targets as is 19112362Sgabeblack@google.com my_targets = COMMAND_LINE_TARGETS 19212362Sgabeblack@google.com else: 19312362Sgabeblack@google.com # default target (ALPHA/m5.debug, unless overridden) 19412362Sgabeblack@google.com target = os.path.join(default_config, default_binary) 19512362Sgabeblack@google.com my_targets = [target] 19612362Sgabeblack@google.com Default(target) 19712362Sgabeblack@google.comelse: 1988233Snate@binkert.org # invoked from subdirectory 1998233Snate@binkert.org if not launch_dir.startswith(ROOT): 2008233Snate@binkert.org print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \ 2018233Snate@binkert.org (launch_dir, ROOT) 2028233Snate@binkert.org sys.exit(1) 2038233Snate@binkert.org # make launch_dir relative to ROOT (strip ROOT plus slash off front) 2048233Snate@binkert.org launch_dir = launch_dir[len(ROOT)+1:] 2058233Snate@binkert.org if len(COMMAND_LINE_TARGETS) != 0: 2068233Snate@binkert.org # make specified targets relative to ROOT 2078233Snate@binkert.org my_targets = map(lambda x: os.path.join(launch_dir, x), 2088233Snate@binkert.org COMMAND_LINE_TARGETS) 2098233Snate@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) 2148233Snate@binkert.org my_targets = [target] 2158233Snate@binkert.org Default(target) 2168233Snate@binkert.org 2178233Snate@binkert.org# Normalize target paths (gets rid of '..' in the middle, etc.) 2188233Snate@binkert.orgmy_targets = map(os.path.normpath, my_targets) 2196143Snate@binkert.org 2206143Snate@binkert.org# Generate a list of the unique configs that the collected targets reference. 2216143Snate@binkert.orgbuild_dirs = [] 2226143Snate@binkert.orgfor t in my_targets: 2236143Snate@binkert.org dir = t.split('/')[0] 2246143Snate@binkert.org if dir not in build_dirs: 2259982Satgutier@umich.edu build_dirs.append(dir) 22613576Sciro.santilli@arm.com 22713576Sciro.santilli@arm.com################################################### 22813576Sciro.santilli@arm.com# 22913576Sciro.santilli@arm.com# Set up the default build environment. This environment is copied 23013576Sciro.santilli@arm.com# and modified according to each selected configuration. 23113576Sciro.santilli@arm.com# 23213576Sciro.santilli@arm.com################################################### 23313576Sciro.santilli@arm.com 23413576Sciro.santilli@arm.comdefault_env = Environment(ENV = os.environ, # inherit user's enviroment vars 23513576Sciro.santilli@arm.com ROOT = ROOT, 23613576Sciro.santilli@arm.com SRCDIR = SRCDIR, 23713576Sciro.santilli@arm.com EXT_SRCDIR = EXT_SRCDIR, 23813576Sciro.santilli@arm.com CPPDEFINES = [], 23913576Sciro.santilli@arm.com FULL_SYSTEM = False, 24013576Sciro.santilli@arm.com USE_MYSQL = False) 24113576Sciro.santilli@arm.com 24213576Sciro.santilli@arm.com# M5_EXT is used by isa_parser.py to find the PLY package. 24313576Sciro.santilli@arm.comdefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR }) 24413576Sciro.santilli@arm.com 24513576Sciro.santilli@arm.comdefault_env.Append(CCFLAGS='-pipe') 24613576Sciro.santilli@arm.comdefault_env.Append(CCFLAGS='-fno-strict-aliasing') 24713576Sciro.santilli@arm.comdefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 24813576Sciro.santilli@arm.com 24913576Sciro.santilli@arm.com# libelf build is described in its own SConscript file. Using a 25013576Sciro.santilli@arm.com# dictionary for exports lets us export "default_env" so the 25113576Sciro.santilli@arm.com# SConscript will see it as "env". 25213576Sciro.santilli@arm.comdefault_env.SConscript('m5/libelf/SConscript', exports={'env' : default_env}) 25313576Sciro.santilli@arm.com 25413576Sciro.santilli@arm.com 25513576Sciro.santilli@arm.com################################################### 25613576Sciro.santilli@arm.com# 25713576Sciro.santilli@arm.com# Define build environments for selected configurations. 25813630Sciro.santilli@arm.com# 25913630Sciro.santilli@arm.com################################################### 26013576Sciro.santilli@arm.com 26113576Sciro.santilli@arm.comfor build_dir in build_dirs: 26213576Sciro.santilli@arm.com # Make a copy of the default environment to use for this config. 26313576Sciro.santilli@arm.com env = default_env.Copy() 26413576Sciro.santilli@arm.com # Modify 'env' according to the build directory config. 26513576Sciro.santilli@arm.com print "Configuring options for directory '%s'." % build_dir 26613576Sciro.santilli@arm.com if not set_dir_options(build_dir, env): 26713576Sciro.santilli@arm.com print "Skipping directory '%s'." % build_dir 26813576Sciro.santilli@arm.com continue 26913576Sciro.santilli@arm.com 27013576Sciro.santilli@arm.com # The m5/SConscript file sets up the build rules in 'env' according 27113576Sciro.santilli@arm.com # to the configured options. 27213576Sciro.santilli@arm.com SConscript('m5/SConscript', build_dir = build_dir, exports = 'env', 27313576Sciro.santilli@arm.com duplicate=0) 27413576Sciro.santilli@arm.com 27513576Sciro.santilli@arm.com 27613576Sciro.santilli@arm.com################################################### 27713576Sciro.santilli@arm.com# 27813576Sciro.santilli@arm.com# Let SCons do its thing. At this point SCons will use the defined 27913576Sciro.santilli@arm.com# build enviornments to build the requested targets. 28013576Sciro.santilli@arm.com# 28113576Sciro.santilli@arm.com################################################### 28213576Sciro.santilli@arm.com 28313576Sciro.santilli@arm.com