SConstruct revision 1852
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/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. 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu################################################### 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). 352632Sstever@eecs.umich.edu# 2. A link named 'm5' to the top of the M5 simulator source tree. 362632Sstever@eecs.umich.edu# 3. A link named 'ext' to the top of the M5 external source tree. 372632Sstever@eecs.umich.edu# 382632Sstever@eecs.umich.edu# Then type 'scons' to build the default configuration (see below), or 39955SN/A# 'scons <CONFIG>/<binary>' to build some other configuration (e.g., 402632Sstever@eecs.umich.edu# 'ALPHA_FS/m5.opt' for the optimized full-system version). 412632Sstever@eecs.umich.edu# 422761Sstever@eecs.umich.edu################################################### 432632Sstever@eecs.umich.edu 442632Sstever@eecs.umich.edu# Python library imports 452632Sstever@eecs.umich.eduimport sys 462761Sstever@eecs.umich.eduimport os 472761Sstever@eecs.umich.edu 482761Sstever@eecs.umich.edu# Check for recent-enough Python version 492632Sstever@eecs.umich.edu(major, minor) = sys.version_info[:2] 502632Sstever@eecs.umich.eduif major < 2 or (major == 2 and minor < 3): 512761Sstever@eecs.umich.edu print "Error: M5 requires Python 2.3 or later." 522761Sstever@eecs.umich.edu sys.exit(1) 532761Sstever@eecs.umich.edu 542761Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives). 552761Sstever@eecs.umich.eduROOT = Dir('.').abspath 562632Sstever@eecs.umich.edu 572632Sstever@eecs.umich.edu# Paths to the M5 and external source trees (local symlinks). 582632Sstever@eecs.umich.eduSRCDIR = os.path.join(ROOT, 'm5') 592632Sstever@eecs.umich.eduEXT_SRCDIR = os.path.join(ROOT, 'ext') 602632Sstever@eecs.umich.edu 612632Sstever@eecs.umich.edu# Check for 'm5' and 'ext' links, die if they don't exist. 622632Sstever@eecs.umich.eduif not os.path.isdir(SRCDIR): 63955SN/A print "Error: '%s' must be a link to the M5 source tree." % SRCDIR 64955SN/A sys.exit(1) 65955SN/A 66955SN/Aif not os.path.isdir('ext'): 67955SN/A print "Error: '%s' must be a link to the M5 external source tree." \ 683918Ssaidi@eecs.umich.edu % EXT_SRCDIR 694202Sbinkertn@umich.edu sys.exit(1) 704678Snate@binkert.org 71955SN/A# tell python where to find m5 python code 722656Sstever@eecs.umich.edusys.path.append(os.path.join(SRCDIR, 'python')) 732656Sstever@eecs.umich.edu 742656Sstever@eecs.umich.edu 752656Sstever@eecs.umich.edu################################################### 762656Sstever@eecs.umich.edu# 772656Sstever@eecs.umich.edu# Define Configurations 782656Sstever@eecs.umich.edu# 792653Sstever@eecs.umich.edu# The build system infers the build options from the subdirectory name 802653Sstever@eecs.umich.edu# that the simulator is built under. The subdirectory name must be of 812653Sstever@eecs.umich.edu# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration 822653Sstever@eecs.umich.edu# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL). The 832653Sstever@eecs.umich.edu# following code defines the standard configurations and options. 842653Sstever@eecs.umich.edu# Additional local configurations and options are read from the file 852653Sstever@eecs.umich.edu# 'local_configs' if it exists. 862653Sstever@eecs.umich.edu# 872653Sstever@eecs.umich.edu# Each base configuration or option is defined in two steps: a 882653Sstever@eecs.umich.edu# function that takes an SCons build environment and modifies it 892653Sstever@eecs.umich.edu# appropriately for that config or option, and an entry in the 901852SN/A# 'configs_map' or 'options_map' dictionary that maps the directory 91955SN/A# name string to the function. (The directory names are all upper 92955SN/A# case, by convention.) 93955SN/A# 943717Sstever@eecs.umich.edu################################################### 953716Sstever@eecs.umich.edu 96955SN/A# Base non-full-system Alpha ISA configuration. 971533SN/Adef AlphaSyscallEmulConfig(env): 983716Sstever@eecs.umich.edu env.Replace(TARGET_ISA = 'alpha') 991533SN/A env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP') 1004678Snate@binkert.org 1014678Snate@binkert.org# Base full-system configuration. 1024678Snate@binkert.orgdef AlphaFullSysConfig(env): 1034678Snate@binkert.org env.Replace(TARGET_ISA = 'alpha') 1044678Snate@binkert.org env.Replace(FULL_SYSTEM = True) 1054678Snate@binkert.org env.Append(CPPDEFINES = ['FULL_SYSTEM']) 1064678Snate@binkert.org 1074678Snate@binkert.org# Base configurations map. 1084678Snate@binkert.orgconfigs_map = { 1094678Snate@binkert.org 'ALPHA_SE' : AlphaSyscallEmulConfig, 1104678Snate@binkert.org 'ALPHA_FS' : AlphaFullSysConfig 1114678Snate@binkert.org } 1124678Snate@binkert.org 1134678Snate@binkert.org# Disable FastAlloc object allocation. 1144678Snate@binkert.orgdef NoFastAllocOpt(env): 1154678Snate@binkert.org env.Append(CPPDEFINES = 'NO_FAST_ALLOC') 1164678Snate@binkert.org 1174678Snate@binkert.org# Enable efence 1184678Snate@binkert.orgdef EfenceOpt(env): 1194678Snate@binkert.org env.Append(LIBS=['efence']) 1204678Snate@binkert.org 1214678Snate@binkert.org# Configuration options map. 1224678Snate@binkert.orgoptions_map = { 1234678Snate@binkert.org 'NO_FAST_ALLOC' : NoFastAllocOpt, 1244678Snate@binkert.org 'EFENCE' : EfenceOpt 1254678Snate@binkert.org } 1264678Snate@binkert.org 1274678Snate@binkert.org# The 'local_configs' file can be used to define additional base 128955SN/A# configurations and/or options without changing this file. 129955SN/Aif os.path.isfile('local_configs'): 1302632Sstever@eecs.umich.edu SConscript('local_configs', exports = ['configs_map', 'options_map']) 1312632Sstever@eecs.umich.edu 132955SN/A# This function parses a directory name of the form <CONFIG>[.<OPT>]* 133955SN/A# and sets up the build environment appropriately. Returns True if 134955SN/A# successful, False if the base config or any of the options were not 135955SN/A# defined. 1362632Sstever@eecs.umich.edudef set_dir_options(dir, env): 137955SN/A parts = dir.split('.') 1382632Sstever@eecs.umich.edu config = parts[0] 1392632Sstever@eecs.umich.edu opts = parts[1:] 1402632Sstever@eecs.umich.edu try: 1412632Sstever@eecs.umich.edu configs_map[config](env) 1422632Sstever@eecs.umich.edu map(lambda opt: options_map[opt](env), opts) 1432632Sstever@eecs.umich.edu return True 1442632Sstever@eecs.umich.edu except KeyError, key: 1453053Sstever@eecs.umich.edu print "Config/option '%s' not found." % key 1463053Sstever@eecs.umich.edu return False 1473053Sstever@eecs.umich.edu 1483053Sstever@eecs.umich.edu# Set the default configuration and binary. The default target (if 1493053Sstever@eecs.umich.edu# scons is invoked at the top level with no command-line targets) is 1503053Sstever@eecs.umich.edu# 'ALPHA_SE/m5.debug'. If scons is invoked in a subdirectory with no 1513053Sstever@eecs.umich.edu# command-line targets, the configuration 1523053Sstever@eecs.umich.edu 1533053Sstever@eecs.umich.edu################################################### 1543053Sstever@eecs.umich.edu# 1553053Sstever@eecs.umich.edu# Figure out which configurations to set up. 1563053Sstever@eecs.umich.edu# 1573053Sstever@eecs.umich.edu# 1583053Sstever@eecs.umich.edu# It's prohibitive to do all the combinations of base configurations 1593053Sstever@eecs.umich.edu# and options, so we have to infer which ones the user wants. 1603053Sstever@eecs.umich.edu# 1612632Sstever@eecs.umich.edu# 1. If there are command-line targets, the configuration(s) are inferred 1622632Sstever@eecs.umich.edu# from the directories of those targets. If scons was invoked from a 1632632Sstever@eecs.umich.edu# subdirectory (using 'scons -u'), those targets have to be 1642632Sstever@eecs.umich.edu# interpreted relative to that subdirectory. 1652632Sstever@eecs.umich.edu# 1662632Sstever@eecs.umich.edu# 2. If there are no command-line targets, and scons was invoked from a 1673718Sstever@eecs.umich.edu# subdirectory (using 'scons -u'), the configuration is inferred from 1683718Sstever@eecs.umich.edu# the name of the subdirectory. 1693718Sstever@eecs.umich.edu# 1703718Sstever@eecs.umich.edu# 3. If there are no command-line targets and scons was invoked from 1713718Sstever@eecs.umich.edu# the root build directory, a default configuration is used. The 1723718Sstever@eecs.umich.edu# built-in default is ALPHA_SE, but this can be overridden by setting the 1733718Sstever@eecs.umich.edu# M5_DEFAULT_CONFIG shell environment veriable. 1743718Sstever@eecs.umich.edu# 1753718Sstever@eecs.umich.edu# In cases 2 & 3, the specific file target defaults to 'm5.debug', but 1763718Sstever@eecs.umich.edu# this can be overridden by setting the M5_DEFAULT_BINARY shell 1773718Sstever@eecs.umich.edu# environment veriable. 1783718Sstever@eecs.umich.edu# 1793718Sstever@eecs.umich.edu################################################### 1802634Sstever@eecs.umich.edu 1812634Sstever@eecs.umich.edu# Find default configuration & binary. 1822632Sstever@eecs.umich.edudefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE') 1832638Sstever@eecs.umich.edudefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug') 1842632Sstever@eecs.umich.edu 1852632Sstever@eecs.umich.edu# Ask SCons which directory it was invoked from. If you invoke SCons 1862632Sstever@eecs.umich.edu# from a subdirectory you must use the '-u' flag. 1872632Sstever@eecs.umich.edulaunch_dir = GetLaunchDir() 1882632Sstever@eecs.umich.edu 1892632Sstever@eecs.umich.edu# Build a list 'my_targets' of all the targets relative to ROOT. 1901858SN/Aif launch_dir == ROOT: 1913716Sstever@eecs.umich.edu # invoked from root build dir 1922638Sstever@eecs.umich.edu if len(COMMAND_LINE_TARGETS) != 0: 1932638Sstever@eecs.umich.edu # easy: use specified targets as is 1942638Sstever@eecs.umich.edu my_targets = COMMAND_LINE_TARGETS 1952638Sstever@eecs.umich.edu else: 1962638Sstever@eecs.umich.edu # default target (ALPHA_SE/m5.debug, unless overridden) 1972638Sstever@eecs.umich.edu target = os.path.join(default_config, default_binary) 1982638Sstever@eecs.umich.edu my_targets = [target] 1993716Sstever@eecs.umich.edu Default(target) 2002634Sstever@eecs.umich.eduelse: 2012634Sstever@eecs.umich.edu # invoked from subdirectory 202955SN/A if not launch_dir.startswith(ROOT): 203955SN/A print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \ 204955SN/A (launch_dir, ROOT) 205955SN/A sys.exit(1) 206955SN/A # make launch_dir relative to ROOT (strip ROOT plus slash off front) 207955SN/A launch_dir = launch_dir[len(ROOT)+1:] 208955SN/A if len(COMMAND_LINE_TARGETS) != 0: 209955SN/A # make specified targets relative to ROOT 2101858SN/A my_targets = map(lambda x: os.path.join(launch_dir, x), 2111858SN/A COMMAND_LINE_TARGETS) 2122632Sstever@eecs.umich.edu else: 213955SN/A # build default binary (m5.debug, unless overridden) using the 2143643Ssaidi@eecs.umich.edu # config inferred by the invocation directory (the first 2153643Ssaidi@eecs.umich.edu # subdirectory after ROOT) 2163643Ssaidi@eecs.umich.edu target = os.path.join(launch_dir.split('/')[0], default_binary) 2173643Ssaidi@eecs.umich.edu my_targets = [target] 2183643Ssaidi@eecs.umich.edu Default(target) 2193643Ssaidi@eecs.umich.edu 2203643Ssaidi@eecs.umich.edu# Normalize target paths (gets rid of '..' in the middle, etc.) 2213643Ssaidi@eecs.umich.edumy_targets = map(os.path.normpath, my_targets) 2224494Ssaidi@eecs.umich.edu 2234494Ssaidi@eecs.umich.edu# Generate a list of the unique configs that the collected targets reference. 2243716Sstever@eecs.umich.edubuild_dirs = [] 2251105SN/Afor t in my_targets: 2262667Sstever@eecs.umich.edu dir = t.split('/')[0] 2272667Sstever@eecs.umich.edu if dir not in build_dirs: 2282667Sstever@eecs.umich.edu build_dirs.append(dir) 2292667Sstever@eecs.umich.edu 2302667Sstever@eecs.umich.edu################################################### 2312667Sstever@eecs.umich.edu# 2321869SN/A# Set up the default build environment. This environment is copied 2331869SN/A# and modified according to each selected configuration. 2341869SN/A# 2351869SN/A################################################### 2361869SN/A 2371065SN/Adefault_env = Environment(ENV = os.environ, # inherit user's enviroment vars 2382632Sstever@eecs.umich.edu ROOT = ROOT, 2392632Sstever@eecs.umich.edu SRCDIR = SRCDIR, 2403918Ssaidi@eecs.umich.edu EXT_SRCDIR = EXT_SRCDIR, 2413918Ssaidi@eecs.umich.edu CPPDEFINES = [], 2423940Ssaidi@eecs.umich.edu FULL_SYSTEM = False, 2433918Ssaidi@eecs.umich.edu ALPHA_TLASER = False, 2443918Ssaidi@eecs.umich.edu USE_MYSQL = False) 2453918Ssaidi@eecs.umich.edu 2463918Ssaidi@eecs.umich.edudefault_env.SConsignFile("sconsign") 2473918Ssaidi@eecs.umich.edu 2483918Ssaidi@eecs.umich.edu# For some reason, the CC and CXX variables don't get passed into the 2493940Ssaidi@eecs.umich.edu# environment correctly. This is probably some sort of scons bug that 2503940Ssaidi@eecs.umich.edu# will eventually be fixed. 2513940Ssaidi@eecs.umich.eduif os.environ.has_key('CC'): 2523942Ssaidi@eecs.umich.edu default_env.Replace(CC=os.environ['CC']) 2533940Ssaidi@eecs.umich.edu 2543918Ssaidi@eecs.umich.eduif os.environ.has_key('CXX'): 2553918Ssaidi@eecs.umich.edu default_env.Replace(CXX=os.environ['CXX']) 256955SN/A 2571858SN/A# M5_EXT is used by isa_parser.py to find the PLY package. 2583918Ssaidi@eecs.umich.edudefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR }) 2593918Ssaidi@eecs.umich.edu 2603918Ssaidi@eecs.umich.edudefault_env.Append(CCFLAGS='-pipe') 2613918Ssaidi@eecs.umich.edudefault_env.Append(CCFLAGS='-fno-strict-aliasing') 2623940Ssaidi@eecs.umich.edudefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2633940Ssaidi@eecs.umich.eduif sys.platform == 'cygwin': 2643918Ssaidi@eecs.umich.edu # cygwin has some header file issues... 2653918Ssaidi@eecs.umich.edu default_env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2663918Ssaidi@eecs.umich.edudefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')]) 2673918Ssaidi@eecs.umich.edu 2683918Ssaidi@eecs.umich.edu# libelf build is described in its own SConscript file. Using a 2693918Ssaidi@eecs.umich.edu# dictionary for exports lets us export "default_env" so the 2703918Ssaidi@eecs.umich.edu# SConscript will see it as "env". SConscript-global is the build in 2713918Ssaidi@eecs.umich.edu# build/libelf shared among all configs. 2723918Ssaidi@eecs.umich.edudefault_env.SConscript('m5/libelf/SConscript-global', 2733940Ssaidi@eecs.umich.edu exports={'env' : default_env}) 2743918Ssaidi@eecs.umich.edu 2753918Ssaidi@eecs.umich.edu################################################### 2761851SN/A# 2771851SN/A# Define build environments for selected configurations. 2781858SN/A# 2792632Sstever@eecs.umich.edu################################################### 280955SN/A 2813053Sstever@eecs.umich.edufor build_dir in build_dirs: 2823053Sstever@eecs.umich.edu # Make a copy of the default environment to use for this config. 2833053Sstever@eecs.umich.edu env = default_env.Copy() 2843053Sstever@eecs.umich.edu # Modify 'env' according to the build directory config. 2853053Sstever@eecs.umich.edu print "Configuring options for directory '%s'." % build_dir 2863053Sstever@eecs.umich.edu if not set_dir_options(build_dir, env): 2873053Sstever@eecs.umich.edu print "Skipping directory '%s'." % build_dir 2883053Sstever@eecs.umich.edu continue 2893053Sstever@eecs.umich.edu 2904742Sstever@eecs.umich.edu # The m5/SConscript file sets up the build rules in 'env' according 2914742Sstever@eecs.umich.edu # to the configured options. 2923053Sstever@eecs.umich.edu SConscript('m5/SConscript', build_dir = build_dir, exports = 'env', 2933053Sstever@eecs.umich.edu duplicate=0) 2943053Sstever@eecs.umich.edu 2953053Sstever@eecs.umich.edu 2963053Sstever@eecs.umich.edu################################################### 2973053Sstever@eecs.umich.edu# 2983053Sstever@eecs.umich.edu# Let SCons do its thing. At this point SCons will use the defined 2993053Sstever@eecs.umich.edu# build environments to build the requested targets. 3003053Sstever@eecs.umich.edu# 3012667Sstever@eecs.umich.edu################################################### 3024554Sbinkertn@umich.edu 3034554Sbinkertn@umich.edu