SConstruct revision 1851
1955SN/A# -*- mode:python -*- 2955SN/A 310841Sandreas.sandberg@arm.com# Copyright (c) 2004-2005 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# 'ALPHA_FS/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# tell python where to find m5 python code 662761Sstever@eecs.umich.edusys.path.append(os.path.join(SRCDIR, 'python')) 672761Sstever@eecs.umich.edu 682761Sstever@eecs.umich.edu 692761Sstever@eecs.umich.edu################################################### 702761Sstever@eecs.umich.edu# 718878Ssteve.reinhardt@amd.com# Define Configurations 728878Ssteve.reinhardt@amd.com# 732632Sstever@eecs.umich.edu# The build system infers the build options from the subdirectory name 742632Sstever@eecs.umich.edu# that the simulator is built under. The subdirectory name must be of 758878Ssteve.reinhardt@amd.com# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration 768878Ssteve.reinhardt@amd.com# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL). The 772632Sstever@eecs.umich.edu# following code defines the standard configurations and options. 78955SN/A# Additional local configurations and options are read from the file 79955SN/A# 'local_configs' if it exists. 80955SN/A# 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): 928878Ssteve.reinhardt@amd.com env.Replace(TARGET_ISA = 'alpha') 935863Snate@binkert.org env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP') 945863Snate@binkert.org 955863Snate@binkert.org# Base full-system configuration. 969812Sandreas.hansson@arm.comdef AlphaFullSysConfig(env): 979812Sandreas.hansson@arm.com env.Replace(TARGET_ISA = 'alpha') 985863Snate@binkert.org env.Replace(FULL_SYSTEM = True) 999812Sandreas.hansson@arm.com env.Append(CPPDEFINES = ['FULL_SYSTEM']) 1005863Snate@binkert.org 1015863Snate@binkert.org# Base configurations map. 1025863Snate@binkert.orgconfigs_map = { 1039812Sandreas.hansson@arm.com 'ALPHA_SE' : AlphaSyscallEmulConfig, 1049812Sandreas.hansson@arm.com 'ALPHA_FS' : AlphaFullSysConfig 1055863Snate@binkert.org } 1065863Snate@binkert.org 1078878Ssteve.reinhardt@amd.com# Disable FastAlloc object allocation. 1085863Snate@binkert.orgdef NoFastAllocOpt(env): 1095863Snate@binkert.org env.Append(CPPDEFINES = 'NO_FAST_ALLOC') 1105863Snate@binkert.org 1116654Snate@binkert.org# Enable efence 11210196SCurtis.Dunham@arm.comdef EfenceOpt(env): 113955SN/A env.Append(LIBS=['efence']) 1145396Ssaidi@eecs.umich.edu 1155863Snate@binkert.org# Configuration options map. 1165863Snate@binkert.orgoptions_map = { 1174202Sbinkertn@umich.edu 'NO_FAST_ALLOC' : NoFastAllocOpt, 1185863Snate@binkert.org 'EFENCE' : EfenceOpt 1195863Snate@binkert.org } 1205863Snate@binkert.org 1215863Snate@binkert.org# The 'local_configs' file can be used to define additional base 122955SN/A# configurations and/or options without changing this file. 1236654Snate@binkert.orgif os.path.isfile('local_configs'): 1245273Sstever@gmail.com SConscript('local_configs', exports = ['configs_map', 'options_map']) 1255871Snate@binkert.org 1265273Sstever@gmail.com# This function parses a directory name of the form <CONFIG>[.<OPT>]* 1276655Snate@binkert.org# and sets up the build environment appropriately. Returns True if 1288878Ssteve.reinhardt@amd.com# successful, False if the base config or any of the options were not 1296655Snate@binkert.org# defined. 1306655Snate@binkert.orgdef set_dir_options(dir, env): 1319219Spower.jg@gmail.com parts = dir.split('.') 1326655Snate@binkert.org config = parts[0] 1335871Snate@binkert.org opts = parts[1:] 1346654Snate@binkert.org try: 1358947Sandreas.hansson@arm.com configs_map[config](env) 1365396Ssaidi@eecs.umich.edu map(lambda opt: options_map[opt](env), opts) 1378120Sgblack@eecs.umich.edu return True 1388120Sgblack@eecs.umich.edu except KeyError, key: 1398120Sgblack@eecs.umich.edu print "Config/option '%s' not found." % key 1408120Sgblack@eecs.umich.edu return False 1418120Sgblack@eecs.umich.edu 1428120Sgblack@eecs.umich.edu# Set the default configuration and binary. The default target (if 1438120Sgblack@eecs.umich.edu# scons is invoked at the top level with no command-line targets) is 1448120Sgblack@eecs.umich.edu# 'ALPHA_SE/m5.debug'. If scons is invoked in a subdirectory with no 1458879Ssteve.reinhardt@amd.com# command-line targets, the configuration 1468879Ssteve.reinhardt@amd.com 1478879Ssteve.reinhardt@amd.com################################################### 1488879Ssteve.reinhardt@amd.com# 1498879Ssteve.reinhardt@amd.com# Figure out which configurations to set up. 1508879Ssteve.reinhardt@amd.com# 1518879Ssteve.reinhardt@amd.com# 1528879Ssteve.reinhardt@amd.com# It's prohibitive to do all the combinations of base configurations 1538879Ssteve.reinhardt@amd.com# and options, so we have to infer which ones the user wants. 1548879Ssteve.reinhardt@amd.com# 1558879Ssteve.reinhardt@amd.com# 1. If there are command-line targets, the configuration(s) are inferred 1568879Ssteve.reinhardt@amd.com# from the directories of those targets. If scons was invoked from a 1578879Ssteve.reinhardt@amd.com# subdirectory (using 'scons -u'), those targets have to be 1588120Sgblack@eecs.umich.edu# interpreted relative to that subdirectory. 1598120Sgblack@eecs.umich.edu# 1608120Sgblack@eecs.umich.edu# 2. If there are no command-line targets, and scons was invoked from a 1618120Sgblack@eecs.umich.edu# subdirectory (using 'scons -u'), the configuration is inferred from 1628120Sgblack@eecs.umich.edu# the name of the subdirectory. 1638120Sgblack@eecs.umich.edu# 1648120Sgblack@eecs.umich.edu# 3. If there are no command-line targets and scons was invoked from 1658120Sgblack@eecs.umich.edu# the root build directory, a default configuration is used. The 1668120Sgblack@eecs.umich.edu# built-in default is ALPHA_SE, but this can be overridden by setting the 1678120Sgblack@eecs.umich.edu# M5_DEFAULT_CONFIG shell environment veriable. 1688120Sgblack@eecs.umich.edu# 1698120Sgblack@eecs.umich.edu# In cases 2 & 3, the specific file target defaults to 'm5.debug', but 1708120Sgblack@eecs.umich.edu# this can be overridden by setting the M5_DEFAULT_BINARY shell 1718120Sgblack@eecs.umich.edu# environment veriable. 1728879Ssteve.reinhardt@amd.com# 1738879Ssteve.reinhardt@amd.com################################################### 1748879Ssteve.reinhardt@amd.com 1758879Ssteve.reinhardt@amd.com# Find default configuration & binary. 17610458Sandreas.hansson@arm.comdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE') 17710458Sandreas.hansson@arm.comdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug') 17810458Sandreas.hansson@arm.com 1798879Ssteve.reinhardt@amd.com# Ask SCons which directory it was invoked from. If you invoke SCons 1808879Ssteve.reinhardt@amd.com# from a subdirectory you must use the '-u' flag. 1818879Ssteve.reinhardt@amd.comlaunch_dir = GetLaunchDir() 1828879Ssteve.reinhardt@amd.com 1839227Sandreas.hansson@arm.com# Build a list 'my_targets' of all the targets relative to ROOT. 1849227Sandreas.hansson@arm.comif launch_dir == ROOT: 1858879Ssteve.reinhardt@amd.com # invoked from root build dir 1868879Ssteve.reinhardt@amd.com if len(COMMAND_LINE_TARGETS) != 0: 1878879Ssteve.reinhardt@amd.com # easy: use specified targets as is 1888879Ssteve.reinhardt@amd.com my_targets = COMMAND_LINE_TARGETS 18910453SAndrew.Bardsley@arm.com else: 19010453SAndrew.Bardsley@arm.com # default target (ALPHA_SE/m5.debug, unless overridden) 19110453SAndrew.Bardsley@arm.com target = os.path.join(default_config, default_binary) 19210456SCurtis.Dunham@arm.com my_targets = [target] 19310456SCurtis.Dunham@arm.com Default(target) 19410456SCurtis.Dunham@arm.comelse: 19510457Sandreas.hansson@arm.com # invoked from subdirectory 19610457Sandreas.hansson@arm.com if not launch_dir.startswith(ROOT): 1978120Sgblack@eecs.umich.edu print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \ 1988947Sandreas.hansson@arm.com (launch_dir, ROOT) 1997816Ssteve.reinhardt@amd.com sys.exit(1) 2005871Snate@binkert.org # make launch_dir relative to ROOT (strip ROOT plus slash off front) 2015871Snate@binkert.org launch_dir = launch_dir[len(ROOT)+1:] 2026121Snate@binkert.org if len(COMMAND_LINE_TARGETS) != 0: 2035871Snate@binkert.org # make specified targets relative to ROOT 2045871Snate@binkert.org my_targets = map(lambda x: os.path.join(launch_dir, x), 2059926Sstan.czerniawski@arm.com COMMAND_LINE_TARGETS) 2069926Sstan.czerniawski@arm.com else: 2079119Sandreas.hansson@arm.com # build default binary (m5.debug, unless overridden) using the 20810068Sandreas.hansson@arm.com # config inferred by the invocation directory (the first 20910068Sandreas.hansson@arm.com # subdirectory after ROOT) 210955SN/A target = os.path.join(launch_dir.split('/')[0], default_binary) 2119416SAndreas.Sandberg@ARM.com my_targets = [target] 21211212Sjoseph.gross@amd.com Default(target) 21311212Sjoseph.gross@amd.com 21411212Sjoseph.gross@amd.com# Normalize target paths (gets rid of '..' in the middle, etc.) 21511212Sjoseph.gross@amd.commy_targets = map(os.path.normpath, my_targets) 21611212Sjoseph.gross@amd.com 2179416SAndreas.Sandberg@ARM.com# Generate a list of the unique configs that the collected targets reference. 2189416SAndreas.Sandberg@ARM.combuild_dirs = [] 2195871Snate@binkert.orgfor t in my_targets: 22010584Sandreas.hansson@arm.com dir = t.split('/')[0] 2219416SAndreas.Sandberg@ARM.com if dir not in build_dirs: 2229416SAndreas.Sandberg@ARM.com build_dirs.append(dir) 2235871Snate@binkert.org 224955SN/A################################################### 22510671Sandreas.hansson@arm.com# 22610671Sandreas.hansson@arm.com# Set up the default build environment. This environment is copied 22710671Sandreas.hansson@arm.com# and modified according to each selected configuration. 22810671Sandreas.hansson@arm.com# 2298881Smarc.orr@gmail.com################################################### 2306121Snate@binkert.org 2316121Snate@binkert.orgdefault_env = Environment(ENV = os.environ, # inherit user's enviroment vars 2321533SN/A ROOT = ROOT, 2339239Sandreas.hansson@arm.com SRCDIR = SRCDIR, 2349239Sandreas.hansson@arm.com EXT_SRCDIR = EXT_SRCDIR, 2359239Sandreas.hansson@arm.com CPPDEFINES = [], 2369239Sandreas.hansson@arm.com FULL_SYSTEM = False, 2379239Sandreas.hansson@arm.com ALPHA_TLASER = False, 2389239Sandreas.hansson@arm.com USE_MYSQL = False) 2399239Sandreas.hansson@arm.com 2409239Sandreas.hansson@arm.comdefault_env.SConsignFile("sconsign") 2419239Sandreas.hansson@arm.com 2429239Sandreas.hansson@arm.com# For some reason, the CC and CXX variables don't get passed into the 2439239Sandreas.hansson@arm.com# environment correctly. This is probably some sort of scons bug that 2449239Sandreas.hansson@arm.com# will eventually be fixed. 2456655Snate@binkert.orgif os.environ.has_key('CC'): 2466655Snate@binkert.org default_env.Replace(CC=os.environ['CC']) 2476655Snate@binkert.org 2486655Snate@binkert.orgif os.environ.has_key('CXX'): 2495871Snate@binkert.org default_env.Replace(CXX=os.environ['CXX']) 2505871Snate@binkert.org 2515863Snate@binkert.org# M5_EXT is used by isa_parser.py to find the PLY package. 2525871Snate@binkert.orgdefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR }) 2538878Ssteve.reinhardt@amd.com 2545871Snate@binkert.orgdefault_env.Append(CCFLAGS='-pipe') 2555871Snate@binkert.orgdefault_env.Append(CCFLAGS='-fno-strict-aliasing') 2565871Snate@binkert.orgdefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2575863Snate@binkert.orgif sys.platform == 'cygwin': 2586121Snate@binkert.org # cygwin has some header file issues... 2595863Snate@binkert.org default_env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2605871Snate@binkert.orgdefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')]) 2618336Ssteve.reinhardt@amd.com 2628336Ssteve.reinhardt@amd.com# libelf build is described in its own SConscript file. Using a 2638336Ssteve.reinhardt@amd.com# dictionary for exports lets us export "default_env" so the 2648336Ssteve.reinhardt@amd.com# SConscript will see it as "env". SConscript-global is the build in 2654678Snate@binkert.org# build/libelf shared among all configs. 2668336Ssteve.reinhardt@amd.comdefault_env.SConscript('m5/libelf/SConscript-global', 2678336Ssteve.reinhardt@amd.com exports={'env' : default_env}) 2688336Ssteve.reinhardt@amd.com 2694678Snate@binkert.org################################################### 2704678Snate@binkert.org# 2714678Snate@binkert.org# Define build environments for selected configurations. 2724678Snate@binkert.org# 2737827Snate@binkert.org################################################### 2747827Snate@binkert.org 2758336Ssteve.reinhardt@amd.comfor build_dir in build_dirs: 2764678Snate@binkert.org # Make a copy of the default environment to use for this config. 2778336Ssteve.reinhardt@amd.com env = default_env.Copy() 2788336Ssteve.reinhardt@amd.com # Modify 'env' according to the build directory config. 2798336Ssteve.reinhardt@amd.com print "Configuring options for directory '%s'." % build_dir 2808336Ssteve.reinhardt@amd.com if not set_dir_options(build_dir, env): 2818336Ssteve.reinhardt@amd.com print "Skipping directory '%s'." % build_dir 2828336Ssteve.reinhardt@amd.com continue 2835871Snate@binkert.org 2845871Snate@binkert.org # The m5/SConscript file sets up the build rules in 'env' according 2858336Ssteve.reinhardt@amd.com # to the configured options. 2868336Ssteve.reinhardt@amd.com SConscript('m5/SConscript', build_dir = build_dir, exports = 'env', 2878336Ssteve.reinhardt@amd.com duplicate=0) 2888336Ssteve.reinhardt@amd.com 2898336Ssteve.reinhardt@amd.com 2905871Snate@binkert.org################################################### 2918336Ssteve.reinhardt@amd.com# 2928336Ssteve.reinhardt@amd.com# Let SCons do its thing. At this point SCons will use the defined 2938336Ssteve.reinhardt@amd.com# build environments to build the requested targets. 2948336Ssteve.reinhardt@amd.com# 2958336Ssteve.reinhardt@amd.com################################################### 2964678Snate@binkert.org 2975871Snate@binkert.org