SConstruct revision 1762
1955SN/A# -*- mode:python -*- 2955SN/A 37816Ssteve.reinhardt@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 45871Snate@binkert.org# All rights reserved. 51762SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/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################################################### 302665Ssaidi@eecs.umich.edu# 312665Ssaidi@eecs.umich.edu# SCons top-level build description (SConstruct) file. 325863Snate@binkert.org# 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# 388878Ssteve.reinhardt@amd.com# Then type 'scons' to build the default configuration (see below), or 392632Sstever@eecs.umich.edu# 'scons <CONFIG>/<binary>' to build some other configuration (e.g., 408878Ssteve.reinhardt@amd.com# 'ALPHA_FS/m5.opt' for the optimized full-system version). 412632Sstever@eecs.umich.edu# 42955SN/A################################################### 438878Ssteve.reinhardt@amd.com 442632Sstever@eecs.umich.edu# Python library imports 452761Sstever@eecs.umich.eduimport sys 462632Sstever@eecs.umich.eduimport os 472632Sstever@eecs.umich.edu 482632Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives). 492761Sstever@eecs.umich.eduROOT = Dir('.').abspath 502761Sstever@eecs.umich.edu 512761Sstever@eecs.umich.edu# Paths to the M5 and external source trees (local symlinks). 528878Ssteve.reinhardt@amd.comSRCDIR = os.path.join(ROOT, 'm5') 538878Ssteve.reinhardt@amd.comEXT_SRCDIR = os.path.join(ROOT, 'ext') 542761Sstever@eecs.umich.edu 552761Sstever@eecs.umich.edu# Check for 'm5' and 'ext' links, die if they don't exist. 562761Sstever@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 582761Sstever@eecs.umich.edu sys.exit(1) 598878Ssteve.reinhardt@amd.com 608878Ssteve.reinhardt@amd.comif not os.path.isdir('ext'): 612632Sstever@eecs.umich.edu print "Error: '%s' must be a link to the M5 external source tree." \ 622632Sstever@eecs.umich.edu % EXT_SRCDIR 638878Ssteve.reinhardt@amd.com sys.exit(1) 648878Ssteve.reinhardt@amd.com 652632Sstever@eecs.umich.edu# tell python where to find m5 python code 66955SN/Asys.path.append(os.path.join(SRCDIR, 'python')) 67955SN/A 68955SN/A 695863Snate@binkert.org################################################### 705863Snate@binkert.org# 715863Snate@binkert.org# Define Configurations 725863Snate@binkert.org# 735863Snate@binkert.org# The build system infers the build options from the subdirectory name 745863Snate@binkert.org# that the simulator is built under. The subdirectory name must be of 755863Snate@binkert.org# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration 765863Snate@binkert.org# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL). The 775863Snate@binkert.org# following code defines the standard configurations and options. 785863Snate@binkert.org# Additional local configurations and options are read from the file 795863Snate@binkert.org# 'local_configs' if it exists. 808878Ssteve.reinhardt@amd.com# 815863Snate@binkert.org# Each base configuration or option is defined in two steps: a 825863Snate@binkert.org# function that takes an SCons build environment and modifies it 835863Snate@binkert.org# appropriately for that config or option, and an entry in the 845863Snate@binkert.org# 'configs_map' or 'options_map' dictionary that maps the directory 855863Snate@binkert.org# name string to the function. (The directory names are all upper 865863Snate@binkert.org# case, by convention.) 875863Snate@binkert.org# 885863Snate@binkert.org################################################### 895863Snate@binkert.org 905863Snate@binkert.org# Base non-full-system Alpha ISA configuration. 915863Snate@binkert.orgdef AlphaSyscallEmulConfig(env): 925863Snate@binkert.org env.Replace(TARGET_ISA = 'alpha') 935863Snate@binkert.org env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP') 945863Snate@binkert.org 955863Snate@binkert.org# Base full-system configuration. 968878Ssteve.reinhardt@amd.comdef AlphaFullSysConfig(env): 975863Snate@binkert.org env.Replace(TARGET_ISA = 'alpha') 985863Snate@binkert.org env.Replace(FULL_SYSTEM = True) 995863Snate@binkert.org env.Append(CPPDEFINES = ['FULL_SYSTEM']) 1006654Snate@binkert.org 101955SN/A# Base configurations map. 1025396Ssaidi@eecs.umich.educonfigs_map = { 1035863Snate@binkert.org 'ALPHA_SE' : AlphaSyscallEmulConfig, 1045863Snate@binkert.org 'ALPHA_FS' : AlphaFullSysConfig 1054202Sbinkertn@umich.edu } 1065863Snate@binkert.org 1075863Snate@binkert.org# Disable FastAlloc object allocation. 1085863Snate@binkert.orgdef NoFastAllocOpt(env): 1095863Snate@binkert.org env.Append(CPPDEFINES = 'NO_FAST_ALLOC') 110955SN/A 1116654Snate@binkert.org# Enable efence 1125273Sstever@gmail.comdef EfenceOpt(env): 1135871Snate@binkert.org env.Append(LIBS=['efence']) 1145273Sstever@gmail.com 1156655Snate@binkert.org# Configuration options map. 1168878Ssteve.reinhardt@amd.comoptions_map = { 1176655Snate@binkert.org 'NO_FAST_ALLOC' : NoFastAllocOpt, 1186655Snate@binkert.org 'EFENCE' : EfenceOpt 1199219Spower.jg@gmail.com } 1206655Snate@binkert.org 1215871Snate@binkert.org# The 'local_configs' file can be used to define additional base 1226654Snate@binkert.org# configurations and/or options without changing this file. 1238947Sandreas.hansson@arm.comif os.path.isfile('local_configs'): 1245396Ssaidi@eecs.umich.edu SConscript('local_configs', exports = ['configs_map', 'options_map']) 1258120Sgblack@eecs.umich.edu 1268120Sgblack@eecs.umich.edu# This function parses a directory name of the form <CONFIG>[.<OPT>]* 1278120Sgblack@eecs.umich.edu# and sets up the build environment appropriately. Returns True if 1288120Sgblack@eecs.umich.edu# successful, False if the base config or any of the options were not 1298120Sgblack@eecs.umich.edu# defined. 1308120Sgblack@eecs.umich.edudef set_dir_options(dir, env): 1318120Sgblack@eecs.umich.edu parts = dir.split('.') 1328120Sgblack@eecs.umich.edu config = parts[0] 1338879Ssteve.reinhardt@amd.com opts = parts[1:] 1348879Ssteve.reinhardt@amd.com try: 1358879Ssteve.reinhardt@amd.com configs_map[config](env) 1368879Ssteve.reinhardt@amd.com map(lambda opt: options_map[opt](env), opts) 1378879Ssteve.reinhardt@amd.com return True 1388879Ssteve.reinhardt@amd.com except KeyError, key: 1398879Ssteve.reinhardt@amd.com print "Config/option '%s' not found." % key 1408879Ssteve.reinhardt@amd.com return False 1418879Ssteve.reinhardt@amd.com 1428879Ssteve.reinhardt@amd.com# Set the default configuration and binary. The default target (if 1438879Ssteve.reinhardt@amd.com# scons is invoked at the top level with no command-line targets) is 1448879Ssteve.reinhardt@amd.com# 'ALPHA_SE/m5.debug'. If scons is invoked in a subdirectory with no 1458879Ssteve.reinhardt@amd.com# command-line targets, the configuration 1468120Sgblack@eecs.umich.edu 1478120Sgblack@eecs.umich.edu################################################### 1488120Sgblack@eecs.umich.edu# 1498120Sgblack@eecs.umich.edu# Figure out which configurations to set up. 1508120Sgblack@eecs.umich.edu# 1518120Sgblack@eecs.umich.edu# 1528120Sgblack@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations 1538120Sgblack@eecs.umich.edu# and options, so we have to infer which ones the user wants. 1548120Sgblack@eecs.umich.edu# 1558120Sgblack@eecs.umich.edu# 1. If there are command-line targets, the configuration(s) are inferred 1568120Sgblack@eecs.umich.edu# from the directories of those targets. If scons was invoked from a 1578120Sgblack@eecs.umich.edu# subdirectory (using 'scons -u'), those targets have to be 1588120Sgblack@eecs.umich.edu# interpreted relative to that subdirectory. 1598120Sgblack@eecs.umich.edu# 1608879Ssteve.reinhardt@amd.com# 2. If there are no command-line targets, and scons was invoked from a 1618879Ssteve.reinhardt@amd.com# subdirectory (using 'scons -u'), the configuration is inferred from 1628879Ssteve.reinhardt@amd.com# the name of the subdirectory. 1638879Ssteve.reinhardt@amd.com# 1648879Ssteve.reinhardt@amd.com# 3. If there are no command-line targets and scons was invoked from 1658879Ssteve.reinhardt@amd.com# the root build directory, a default configuration is used. The 1668879Ssteve.reinhardt@amd.com# built-in default is ALPHA_SE, but this can be overridden by setting the 1678879Ssteve.reinhardt@amd.com# M5_DEFAULT_CONFIG shell environment veriable. 1689227Sandreas.hansson@arm.com# 1699227Sandreas.hansson@arm.com# In cases 2 & 3, the specific file target defaults to 'm5.debug', but 1708879Ssteve.reinhardt@amd.com# this can be overridden by setting the M5_DEFAULT_BINARY shell 1718879Ssteve.reinhardt@amd.com# environment veriable. 1728879Ssteve.reinhardt@amd.com# 1738879Ssteve.reinhardt@amd.com################################################### 1748120Sgblack@eecs.umich.edu 1758947Sandreas.hansson@arm.com# Find default configuration & binary. 1767816Ssteve.reinhardt@amd.comdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE') 1775871Snate@binkert.orgdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug') 1785871Snate@binkert.org 1796121Snate@binkert.org# Ask SCons which directory it was invoked from. If you invoke SCons 1805871Snate@binkert.org# from a subdirectory you must use the '-u' flag. 1815871Snate@binkert.orglaunch_dir = GetLaunchDir() 1829119Sandreas.hansson@arm.com 1839396Sandreas.hansson@arm.com# Build a list 'my_targets' of all the targets relative to ROOT. 1849396Sandreas.hansson@arm.comif launch_dir == ROOT: 185955SN/A # invoked from root build dir 1869416SAndreas.Sandberg@ARM.com if len(COMMAND_LINE_TARGETS) != 0: 1879416SAndreas.Sandberg@ARM.com # easy: use specified targets as is 1889416SAndreas.Sandberg@ARM.com my_targets = COMMAND_LINE_TARGETS 1899416SAndreas.Sandberg@ARM.com else: 1909416SAndreas.Sandberg@ARM.com # default target (ALPHA_SE/m5.debug, unless overridden) 1919416SAndreas.Sandberg@ARM.com target = os.path.join(default_config, default_binary) 1929416SAndreas.Sandberg@ARM.com my_targets = [target] 1935871Snate@binkert.org Default(target) 1945871Snate@binkert.orgelse: 1959416SAndreas.Sandberg@ARM.com # invoked from subdirectory 1969416SAndreas.Sandberg@ARM.com if not launch_dir.startswith(ROOT): 1975871Snate@binkert.org print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \ 198955SN/A (launch_dir, ROOT) 1996121Snate@binkert.org sys.exit(1) 2008881Smarc.orr@gmail.com # make launch_dir relative to ROOT (strip ROOT plus slash off front) 2016121Snate@binkert.org launch_dir = launch_dir[len(ROOT)+1:] 2026121Snate@binkert.org if len(COMMAND_LINE_TARGETS) != 0: 2031533SN/A # make specified targets relative to ROOT 2049239Sandreas.hansson@arm.com my_targets = map(lambda x: os.path.join(launch_dir, x), 2059239Sandreas.hansson@arm.com COMMAND_LINE_TARGETS) 2069239Sandreas.hansson@arm.com else: 2079239Sandreas.hansson@arm.com # build default binary (m5.debug, unless overridden) using the 2089239Sandreas.hansson@arm.com # config inferred by the invocation directory (the first 2099239Sandreas.hansson@arm.com # subdirectory after ROOT) 2109239Sandreas.hansson@arm.com target = os.path.join(launch_dir.split('/')[0], default_binary) 2119239Sandreas.hansson@arm.com my_targets = [target] 2129239Sandreas.hansson@arm.com Default(target) 2139239Sandreas.hansson@arm.com 2149239Sandreas.hansson@arm.com# Normalize target paths (gets rid of '..' in the middle, etc.) 2159239Sandreas.hansson@arm.commy_targets = map(os.path.normpath, my_targets) 2166655Snate@binkert.org 2176655Snate@binkert.org# Generate a list of the unique configs that the collected targets reference. 2186655Snate@binkert.orgbuild_dirs = [] 2196655Snate@binkert.orgfor t in my_targets: 2205871Snate@binkert.org dir = t.split('/')[0] 2215871Snate@binkert.org if dir not in build_dirs: 2225863Snate@binkert.org build_dirs.append(dir) 2235871Snate@binkert.org 2248878Ssteve.reinhardt@amd.com################################################### 2255871Snate@binkert.org# 2265871Snate@binkert.org# Set up the default build environment. This environment is copied 2275871Snate@binkert.org# and modified according to each selected configuration. 2285863Snate@binkert.org# 2296121Snate@binkert.org################################################### 2305863Snate@binkert.org 2315871Snate@binkert.orgdefault_env = Environment(ENV = os.environ, # inherit user's enviroment vars 2328336Ssteve.reinhardt@amd.com ROOT = ROOT, 2338336Ssteve.reinhardt@amd.com SRCDIR = SRCDIR, 2348336Ssteve.reinhardt@amd.com EXT_SRCDIR = EXT_SRCDIR, 2358336Ssteve.reinhardt@amd.com CPPDEFINES = [], 2364678Snate@binkert.org FULL_SYSTEM = False, 2378336Ssteve.reinhardt@amd.com ALPHA_TLASER = False, 2388336Ssteve.reinhardt@amd.com USE_MYSQL = False) 2398336Ssteve.reinhardt@amd.com 2404678Snate@binkert.orgdefault_env.SConsignFile("sconsign") 2414678Snate@binkert.org 2424678Snate@binkert.org# For some reason, the CC and CXX variables don't get passed into the 2434678Snate@binkert.org# environment correctly. This is probably some sort of scons bug that 2447827Snate@binkert.org# will eventually be fixed. 2457827Snate@binkert.orgif os.environ.has_key('CC'): 2468336Ssteve.reinhardt@amd.com default_env.Replace(CC=os.environ['CC']) 2474678Snate@binkert.org 2488336Ssteve.reinhardt@amd.comif os.environ.has_key('CXX'): 2498336Ssteve.reinhardt@amd.com default_env.Replace(CXX=os.environ['CXX']) 2508336Ssteve.reinhardt@amd.com 2518336Ssteve.reinhardt@amd.com# M5_EXT is used by isa_parser.py to find the PLY package. 2528336Ssteve.reinhardt@amd.comdefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR }) 2538336Ssteve.reinhardt@amd.com 2545871Snate@binkert.orgdefault_env.Append(CCFLAGS='-pipe') 2555871Snate@binkert.orgdefault_env.Append(CCFLAGS='-fno-strict-aliasing') 2568336Ssteve.reinhardt@amd.comdefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2578336Ssteve.reinhardt@amd.comdefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')]) 2588336Ssteve.reinhardt@amd.com 2598336Ssteve.reinhardt@amd.com# libelf build is described in its own SConscript file. Using a 2608336Ssteve.reinhardt@amd.com# dictionary for exports lets us export "default_env" so the 2615871Snate@binkert.org# SConscript will see it as "env". SConscript-global is the build in 2628336Ssteve.reinhardt@amd.com# build/libelf shared among all configs. 2638336Ssteve.reinhardt@amd.comdefault_env.SConscript('m5/libelf/SConscript-global', 2648336Ssteve.reinhardt@amd.com exports={'env' : default_env}) 2658336Ssteve.reinhardt@amd.com 2668336Ssteve.reinhardt@amd.com################################################### 2674678Snate@binkert.org# 2685871Snate@binkert.org# Define build environments for selected configurations. 2694678Snate@binkert.org# 2708336Ssteve.reinhardt@amd.com################################################### 2718336Ssteve.reinhardt@amd.com 2728336Ssteve.reinhardt@amd.comfor build_dir in build_dirs: 2738336Ssteve.reinhardt@amd.com # Make a copy of the default environment to use for this config. 2748336Ssteve.reinhardt@amd.com env = default_env.Copy() 2758336Ssteve.reinhardt@amd.com # Modify 'env' according to the build directory config. 2768336Ssteve.reinhardt@amd.com print "Configuring options for directory '%s'." % build_dir 2778336Ssteve.reinhardt@amd.com if not set_dir_options(build_dir, env): 2788336Ssteve.reinhardt@amd.com print "Skipping directory '%s'." % build_dir 2798336Ssteve.reinhardt@amd.com continue 2808336Ssteve.reinhardt@amd.com 2818336Ssteve.reinhardt@amd.com # The m5/SConscript file sets up the build rules in 'env' according 2828336Ssteve.reinhardt@amd.com # to the configured options. 2838336Ssteve.reinhardt@amd.com SConscript('m5/SConscript', build_dir = build_dir, exports = 'env', 2848336Ssteve.reinhardt@amd.com duplicate=0) 2858336Ssteve.reinhardt@amd.com 2868336Ssteve.reinhardt@amd.com 2875871Snate@binkert.org################################################### 2886121Snate@binkert.org# 289955SN/A# Let SCons do its thing. At this point SCons will use the defined 290955SN/A# build environments to build the requested targets. 2912632Sstever@eecs.umich.edu# 2922632Sstever@eecs.umich.edu################################################### 293955SN/A 294955SN/A