SConstruct revision 1530
14202Sbinkertn@umich.edu# -*- mode:python -*- 24202Sbinkertn@umich.edu 34202Sbinkertn@umich.edu# Copyright (c) 2004 The Regents of The University of Michigan 44202Sbinkertn@umich.edu# All rights reserved. 54202Sbinkertn@umich.edu# 64202Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 74202Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 84202Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 94202Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 104202Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 114202Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 124202Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 134202Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 144202Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 154202Sbinkertn@umich.edu# this software without specific prior written permission. 164202Sbinkertn@umich.edu# 174202Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 184202Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 194202Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 204202Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 214202Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 224202Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234202Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 244202Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 254202Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 264202Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 274202Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284202Sbinkertn@umich.edu 294202Sbinkertn@umich.edu################################################### 304202Sbinkertn@umich.edu# 314202Sbinkertn@umich.edu# SCons top-level build description (SConstruct) file. 324202Sbinkertn@umich.edu# 3310996Sandreas.sandberg@arm.com# To build M5, you need a directory with three things: 3410996Sandreas.sandberg@arm.com# 1. A copy of this file (named SConstruct). 359398Sandreas.hansson@arm.com# 2. A link named 'm5' to the top of the M5 simulator source tree. 369850Sandreas.hansson@arm.com# 3. A link named 'ext' to the top of the M5 external source tree. 379259SAli.Saidi@ARM.com# 384486Sbinkertn@umich.edu# Then type 'scons' to build the default configuration (see below), or 3910146Sandreas.hansson@arm.com# 'scons <CONFIG>/<binary>' to build some other configuration (e.g., 4010478SAndrew.Bardsley@arm.com# 'KERNEL/m5.opt' for the optimized full-system version). 4110478SAndrew.Bardsley@arm.com# 426165Ssanchezd@stanford.edu################################################### 439850Sandreas.hansson@arm.com 4410405Sandreas.hansson@arm.com# Python library imports 4511184Serfan.azarkhish@unibo.itimport sys 4611185Serfan.azarkhish@unibo.itimport os 476168Snate@binkert.org 489850Sandreas.hansson@arm.com# The absolute path to the current directory (where this file lives). 499259SAli.Saidi@ARM.comROOT = Dir('.').abspath 504202Sbinkertn@umich.edu 5110405Sandreas.hansson@arm.com# Paths to the M5 and external source trees (local symlinks). 5210431SOmar.Naji@arm.comSRCDIR = os.path.join(ROOT, 'm5') 5310146Sandreas.hansson@arm.comEXT_SRCDIR = os.path.join(ROOT, 'ext') 5410478SAndrew.Bardsley@arm.com 5510478SAndrew.Bardsley@arm.com# Check for 'm5' and 'ext' links, die if they don't exist. 564202Sbinkertn@umich.eduif not os.path.isdir(SRCDIR): 578761Sgblack@eecs.umich.edu print "Error: '%s' must be a link to the M5 source tree." % SRCDIR 5810405Sandreas.hansson@arm.com sys.exit(1) 594202Sbinkertn@umich.edu 604202Sbinkertn@umich.eduif not os.path.isdir('ext'): 618914Sandreas.hansson@arm.com print "Error: '%s' must be a link to the M5 external source tree." \ 6210405Sandreas.hansson@arm.com % EXT_SRCDIR 6310405Sandreas.hansson@arm.com sys.exit(1) 6410405Sandreas.hansson@arm.com 6510405Sandreas.hansson@arm.com 6610614Skanishk.sugand@arm.com################################################### 674202Sbinkertn@umich.edu# 6810405Sandreas.hansson@arm.com# Define Configurations 6911184Serfan.azarkhish@unibo.it# 7011185Serfan.azarkhish@unibo.it# The build system infers the build options from the subdirectory name 716168Snate@binkert.org# that the simulator is built under. The subdirectory name must be of 729850Sandreas.hansson@arm.com# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration 739850Sandreas.hansson@arm.com# (e.g., ALPHA or KERNEL) and OPT is an option (e.g., MYSQL). The 749850Sandreas.hansson@arm.com# following code defines the standard configurations and options. 758763Sgblack@eecs.umich.edu# Additional local configurations and options are read from the file 7610299Salexandru.dutu@amd.com# 'local_configs' if it exists. 7710299Salexandru.dutu@amd.com# 787768SAli.Saidi@ARM.com# Each base configuration or option is defined in two steps: a 7910131Sandreas.hansson@arm.com# function that takes an SCons build environment and modifies it 8010131Sandreas.hansson@arm.com# appropriately for that config or option, and an entry in the 8110131Sandreas.hansson@arm.com# 'configs_map' or 'options_map' dictionary that maps the directory 8210131Sandreas.hansson@arm.com# name string to the function. (The directory names are all upper 8310066Sandreas.hansson@arm.com# case, by convention.) 8410612SMarco.Elver@ARM.com# 8510612SMarco.Elver@ARM.com################################################### 8610612SMarco.Elver@ARM.com 8710612SMarco.Elver@ARM.com# Base non-full-system Alpha ISA configuration. 8810405Sandreas.hansson@arm.comdef AlphaConfig(env): 8910405Sandreas.hansson@arm.com env.Replace(TARGET_ISA = 'alpha') 9010405Sandreas.hansson@arm.com env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP') 9110405Sandreas.hansson@arm.com 9210399Sstephan.diestelhorst@arm.com# Base full-system configuration. 9310405Sandreas.hansson@arm.comdef KernelConfig(env): 9410405Sandreas.hansson@arm.com env.Replace(TARGET_ISA = 'alpha') 959036Sandreas.hansson@arm.com env.Replace(FULL_SYSTEM = True) 969164Sandreas.hansson@arm.com env.Append(CPPDEFINES = ['FULL_SYSTEM']) 978981Sandreas.hansson@arm.com 989243Sandreas.hansson@arm.com# Base configurations map. 9910247Sandreas.hansson@arm.comconfigs_map = { 10010208Sandreas.hansson@arm.com 'ALPHA' : AlphaConfig, 10110478SAndrew.Bardsley@arm.com 'KERNEL' : KernelConfig 1028335Snate@binkert.org } 1038335Snate@binkert.org 1048335Snate@binkert.org# Enable detailed full-system binning. 1058914Sandreas.hansson@arm.comdef MeasureOpt(env): 10610614Skanishk.sugand@arm.com env.Replace(USE_MYSQL = True) 10710066Sandreas.hansson@arm.com env.Append(CPPDEFINES = 'FS_MEASURE') 10811184Serfan.azarkhish@unibo.it 10911185Serfan.azarkhish@unibo.it# Enable MySql database output for stats. 11010612SMarco.Elver@ARM.comdef MySqlOpt(env): 11110612SMarco.Elver@ARM.com env.Replace(USE_MYSQL = True) 11210612SMarco.Elver@ARM.com 113# Disable FastAlloc object allocation. 114def NoFastAllocOpt(env): 115 env.Append(CPPDEFINES = 'NO_FAST_ALLOC') 116 117# Configuration options map. 118options_map = { 119 'MEASURE' : MeasureOpt, 120 'MYSQL' : MySqlOpt, 121 'NO_FAST_ALLOC' : NoFastAllocOpt 122 } 123 124# The 'local_configs' file can be used to define additional base 125# configurations and/or options without changing this file. 126if os.path.isfile('local_configs'): 127 SConscript('local_configs', exports = ['configs_map', 'options_map']) 128 129# This function parses a directory name of the form <CONFIG>[.<OPT>]* 130# and sets up the build environment appropriately. Returns True if 131# successful, False if the base config or any of the options were not 132# defined. 133def set_dir_options(dir, env): 134 parts = dir.split('.') 135 config = parts[0] 136 opts = parts[1:] 137 try: 138 configs_map[config](env) 139 map(lambda opt: options_map[opt](env), opts) 140 return True 141 except KeyError, key: 142 print "Config/option '%s' not found." % key 143 return False 144 145# Set the default configuration and binary. The default target (if 146# scons is invoked at the top level with no command-line targets) is 147# 'ALPHA/m5.debug'. If scons is invoked in a subdirectory with no 148# command-line targets, the configuration 149 150################################################### 151# 152# Figure out which configurations to set up. 153# 154# 155# It's prohibitive to do all the combinations of base configurations 156# and options, so we have to infer which ones the user wants. 157# 158# 1. If there are command-line targets, the configuration(s) are inferred 159# from the directories of those targets. If scons was invoked from a 160# subdirectory (using 'scons -u'), those targets have to be 161# interpreted relative to that subdirectory. 162# 163# 2. If there are no command-line targets, and scons was invoked from a 164# subdirectory (using 'scons -u'), the configuration is inferred from 165# the name of the subdirectory. 166# 167# 3. If there are no command-line targets and scons was invoked from 168# the root build directory, a default configuration is used. The 169# built-in default is ALPHA, but this can be overridden by setting the 170# M5_DEFAULT_CONFIG shell environment veriable. 171# 172# In cases 2 & 3, the specific file target defaults to 'm5.debug', but 173# this can be overridden by setting the M5_DEFAULT_BINARY shell 174# environment veriable. 175# 176################################################### 177 178# Find default configuration & binary. 179default_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA') 180default_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug') 181 182# Ask SCons which directory it was invoked from. If you invoke SCons 183# from a subdirectory you must use the '-u' flag. 184launch_dir = GetLaunchDir() 185 186# Build a list 'my_targets' of all the targets relative to ROOT. 187if launch_dir == ROOT: 188 # invoked from root build dir 189 if len(COMMAND_LINE_TARGETS) != 0: 190 # easy: use specified targets as is 191 my_targets = COMMAND_LINE_TARGETS 192 else: 193 # default target (ALPHA/m5.debug, unless overridden) 194 target = os.path.join(default_config, default_binary) 195 my_targets = [target] 196 Default(target) 197else: 198 # invoked from subdirectory 199 if not launch_dir.startswith(ROOT): 200 print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \ 201 (launch_dir, ROOT) 202 sys.exit(1) 203 # make launch_dir relative to ROOT (strip ROOT plus slash off front) 204 launch_dir = launch_dir[len(ROOT)+1:] 205 if len(COMMAND_LINE_TARGETS) != 0: 206 # make specified targets relative to ROOT 207 my_targets = map(lambda x: os.path.join(launch_dir, x), 208 COMMAND_LINE_TARGETS) 209 else: 210 # build default binary (m5.debug, unless overridden) using the 211 # config inferred by the invocation directory (the first 212 # subdirectory after ROOT) 213 target = os.path.join(launch_dir.split('/')[0], default_binary) 214 my_targets = [target] 215 Default(target) 216 217# Normalize target paths (gets rid of '..' in the middle, etc.) 218my_targets = map(os.path.normpath, my_targets) 219 220# Generate a list of the unique configs that the collected targets reference. 221build_dirs = [] 222for t in my_targets: 223 dir = t.split('/')[0] 224 if dir not in build_dirs: 225 build_dirs.append(dir) 226 227################################################### 228# 229# Set up the default build environment. This environment is copied 230# and modified according to each selected configuration. 231# 232################################################### 233 234default_env = Environment(ENV = os.environ, # inherit user's enviroment vars 235 ROOT = ROOT, 236 SRCDIR = SRCDIR, 237 EXT_SRCDIR = EXT_SRCDIR, 238 CPPDEFINES = [], 239 FULL_SYSTEM = False, 240 USE_MYSQL = False) 241 242default_env.SConsignFile("sconsign") 243 244# For some reason, the CC and CXX variables don't get passed into the 245# environment correctly. This is probably some sort of scons bug that 246# will eventually be fixed. 247if os.environ.has_key('CC'): 248 default_env.Replace(CC=os.environ['CC']) 249 250if os.environ.has_key('CXX'): 251 default_env.Replace(CXX=os.environ['CXX']) 252 253# M5_EXT is used by isa_parser.py to find the PLY package. 254default_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR }) 255 256default_env.Append(CCFLAGS='-pipe') 257default_env.Append(CCFLAGS='-fno-strict-aliasing') 258default_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 259default_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')]) 260 261# libelf build is described in its own SConscript file. Using a 262# dictionary for exports lets us export "default_env" so the 263# SConscript will see it as "env". SConscript-global is the build in 264# build/libelf shared among all configs. 265default_env.SConscript('m5/libelf/SConscript-global', 266 exports={'env' : default_env}) 267 268################################################### 269# 270# Define build environments for selected configurations. 271# 272################################################### 273 274for build_dir in build_dirs: 275 # Make a copy of the default environment to use for this config. 276 env = default_env.Copy() 277 # Modify 'env' according to the build directory config. 278 print "Configuring options for directory '%s'." % build_dir 279 if not set_dir_options(build_dir, env): 280 print "Skipping directory '%s'." % build_dir 281 continue 282 283 # The m5/SConscript file sets up the build rules in 'env' according 284 # to the configured options. 285 SConscript('m5/SConscript', build_dir = build_dir, exports = 'env', 286 duplicate=0) 287 288 289################################################### 290# 291# Let SCons do its thing. At this point SCons will use the defined 292# build environments to build the requested targets. 293# 294################################################### 295 296