SConstruct revision 1533
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004 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 294762Snate@binkert.org################################################### 30955SN/A# 315522Snate@binkert.org# SCons top-level build description (SConstruct) file. 326143Snate@binkert.org# 334762Snate@binkert.org# To build M5, you need a directory with three things: 345522Snate@binkert.org# 1. A copy of this file (named SConstruct). 35955SN/A# 2. A link named 'm5' to the top of the M5 simulator source tree. 365522Snate@binkert.org# 3. A link named 'ext' to the top of the M5 external source tree. 37955SN/A# 385522Snate@binkert.org# Then type 'scons' to build the default configuration (see below), or 394202Sbinkertn@umich.edu# 'scons <CONFIG>/<binary>' to build some other configuration (e.g., 405742Snate@binkert.org# 'KERNEL/m5.opt' for the optimized full-system version). 41955SN/A# 424381Sbinkertn@umich.edu################################################### 434381Sbinkertn@umich.edu 448334Snate@binkert.org# Python library imports 45955SN/Aimport sys 46955SN/Aimport os 474202Sbinkertn@umich.edu 48955SN/A# The absolute path to the current directory (where this file lives). 494382Sbinkertn@umich.eduROOT = Dir('.').abspath 504382Sbinkertn@umich.edu 514382Sbinkertn@umich.edu# Paths to the M5 and external source trees (local symlinks). 526654Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'm5') 535517Snate@binkert.orgEXT_SRCDIR = os.path.join(ROOT, 'ext') 548614Sgblack@eecs.umich.edu 557674Snate@binkert.org# Check for 'm5' and 'ext' links, die if they don't exist. 566143Snate@binkert.orgif not os.path.isdir(SRCDIR): 576143Snate@binkert.org print "Error: '%s' must be a link to the M5 source tree." % SRCDIR 586143Snate@binkert.org sys.exit(1) 598233Snate@binkert.org 608233Snate@binkert.orgif not os.path.isdir('ext'): 618233Snate@binkert.org print "Error: '%s' must be a link to the M5 external source tree." \ 628233Snate@binkert.org % EXT_SRCDIR 638233Snate@binkert.org sys.exit(1) 648334Snate@binkert.org 658334Snate@binkert.org# tell python where to find m5 python code 668233Snate@binkert.orgsys.path.append(os.path.join(SRCDIR, 'python')) 678233Snate@binkert.org 688233Snate@binkert.org 698233Snate@binkert.org################################################### 708233Snate@binkert.org# 718233Snate@binkert.org# Define Configurations 726143Snate@binkert.org# 738233Snate@binkert.org# The build system infers the build options from the subdirectory name 748233Snate@binkert.org# that the simulator is built under. The subdirectory name must be of 758233Snate@binkert.org# the form <CONFIG>[.<OPT>]*, where <CONFIG> is a base configuration 766143Snate@binkert.org# (e.g., ALPHA or KERNEL) and OPT is an option (e.g., MYSQL). The 776143Snate@binkert.org# following code defines the standard configurations and options. 786143Snate@binkert.org# Additional local configurations and options are read from the file 796143Snate@binkert.org# 'local_configs' if it exists. 808233Snate@binkert.org# 818233Snate@binkert.org# Each base configuration or option is defined in two steps: a 828233Snate@binkert.org# function that takes an SCons build environment and modifies it 836143Snate@binkert.org# appropriately for that config or option, and an entry in the 848233Snate@binkert.org# 'configs_map' or 'options_map' dictionary that maps the directory 858233Snate@binkert.org# name string to the function. (The directory names are all upper 868233Snate@binkert.org# case, by convention.) 878233Snate@binkert.org# 886143Snate@binkert.org################################################### 896143Snate@binkert.org 906143Snate@binkert.org# Base non-full-system Alpha ISA configuration. 914762Snate@binkert.orgdef AlphaConfig(env): 926143Snate@binkert.org env.Replace(TARGET_ISA = 'alpha') 938233Snate@binkert.org env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP') 948233Snate@binkert.org 958233Snate@binkert.org# Base full-system configuration. 968233Snate@binkert.orgdef KernelConfig(env): 978233Snate@binkert.org env.Replace(TARGET_ISA = 'alpha') 986143Snate@binkert.org env.Replace(FULL_SYSTEM = True) 998233Snate@binkert.org env.Append(CPPDEFINES = ['FULL_SYSTEM']) 1008233Snate@binkert.org 1018233Snate@binkert.org# Base configurations map. 1028233Snate@binkert.orgconfigs_map = { 1036143Snate@binkert.org 'ALPHA' : AlphaConfig, 1046143Snate@binkert.org 'KERNEL' : KernelConfig 1056143Snate@binkert.org } 1066143Snate@binkert.org 1076143Snate@binkert.org# Enable detailed full-system binning. 1086143Snate@binkert.orgdef MeasureOpt(env): 1096143Snate@binkert.org env.Replace(USE_MYSQL = True) 1106143Snate@binkert.org env.Append(CPPDEFINES = 'FS_MEASURE') 1116143Snate@binkert.org 1127065Snate@binkert.org# Enable MySql database output for stats. 1136143Snate@binkert.orgdef MySqlOpt(env): 1148233Snate@binkert.org env.Replace(USE_MYSQL = True) 1158233Snate@binkert.org 1168233Snate@binkert.org# Disable FastAlloc object allocation. 1178233Snate@binkert.orgdef NoFastAllocOpt(env): 1188233Snate@binkert.org env.Append(CPPDEFINES = 'NO_FAST_ALLOC') 1198233Snate@binkert.org 1208233Snate@binkert.org# Configuration options map. 1218233Snate@binkert.orgoptions_map = { 1228233Snate@binkert.org 'MEASURE' : MeasureOpt, 1238233Snate@binkert.org 'MYSQL' : MySqlOpt, 1248233Snate@binkert.org 'NO_FAST_ALLOC' : NoFastAllocOpt 1258233Snate@binkert.org } 1268233Snate@binkert.org 1278233Snate@binkert.org# The 'local_configs' file can be used to define additional base 1288233Snate@binkert.org# configurations and/or options without changing this file. 1298233Snate@binkert.orgif os.path.isfile('local_configs'): 1308233Snate@binkert.org SConscript('local_configs', exports = ['configs_map', 'options_map']) 1318233Snate@binkert.org 1328233Snate@binkert.org# This function parses a directory name of the form <CONFIG>[.<OPT>]* 1338233Snate@binkert.org# and sets up the build environment appropriately. Returns True if 1348233Snate@binkert.org# successful, False if the base config or any of the options were not 1358233Snate@binkert.org# defined. 1368233Snate@binkert.orgdef set_dir_options(dir, env): 1378233Snate@binkert.org parts = dir.split('.') 1388233Snate@binkert.org config = parts[0] 1398233Snate@binkert.org opts = parts[1:] 1408233Snate@binkert.org try: 1418233Snate@binkert.org configs_map[config](env) 1428233Snate@binkert.org map(lambda opt: options_map[opt](env), opts) 1438233Snate@binkert.org return True 1448233Snate@binkert.org except KeyError, key: 1456143Snate@binkert.org print "Config/option '%s' not found." % key 1466143Snate@binkert.org return False 1476143Snate@binkert.org 1486143Snate@binkert.org# Set the default configuration and binary. The default target (if 1496143Snate@binkert.org# scons is invoked at the top level with no command-line targets) is 1506143Snate@binkert.org# 'ALPHA/m5.debug'. If scons is invoked in a subdirectory with no 1516143Snate@binkert.org# command-line targets, the configuration 1526143Snate@binkert.org 1536143Snate@binkert.org################################################### 1548945Ssteve.reinhardt@amd.com# 1558233Snate@binkert.org# Figure out which configurations to set up. 1568233Snate@binkert.org# 1576143Snate@binkert.org# 1588945Ssteve.reinhardt@amd.com# It's prohibitive to do all the combinations of base configurations 1596143Snate@binkert.org# and options, so we have to infer which ones the user wants. 1606143Snate@binkert.org# 1616143Snate@binkert.org# 1. If there are command-line targets, the configuration(s) are inferred 1626143Snate@binkert.org# from the directories of those targets. If scons was invoked from a 1635522Snate@binkert.org# subdirectory (using 'scons -u'), those targets have to be 1646143Snate@binkert.org# interpreted relative to that subdirectory. 1656143Snate@binkert.org# 1666143Snate@binkert.org# 2. If there are no command-line targets, and scons was invoked from a 1676143Snate@binkert.org# subdirectory (using 'scons -u'), the configuration is inferred from 1688233Snate@binkert.org# the name of the subdirectory. 1698233Snate@binkert.org# 1708233Snate@binkert.org# 3. If there are no command-line targets and scons was invoked from 1716143Snate@binkert.org# the root build directory, a default configuration is used. The 1726143Snate@binkert.org# built-in default is ALPHA, but this can be overridden by setting the 1736143Snate@binkert.org# M5_DEFAULT_CONFIG shell environment veriable. 1746143Snate@binkert.org# 1755522Snate@binkert.org# In cases 2 & 3, the specific file target defaults to 'm5.debug', but 1765522Snate@binkert.org# this can be overridden by setting the M5_DEFAULT_BINARY shell 1775522Snate@binkert.org# environment veriable. 1785522Snate@binkert.org# 1795604Snate@binkert.org################################################### 1805604Snate@binkert.org 1816143Snate@binkert.org# Find default configuration & binary. 1826143Snate@binkert.orgdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA') 1834762Snate@binkert.orgdefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug') 1844762Snate@binkert.org 1856143Snate@binkert.org# Ask SCons which directory it was invoked from. If you invoke SCons 1866727Ssteve.reinhardt@amd.com# from a subdirectory you must use the '-u' flag. 1876727Ssteve.reinhardt@amd.comlaunch_dir = GetLaunchDir() 1886727Ssteve.reinhardt@amd.com 1894762Snate@binkert.org# Build a list 'my_targets' of all the targets relative to ROOT. 1906143Snate@binkert.orgif launch_dir == ROOT: 1916143Snate@binkert.org # invoked from root build dir 1926143Snate@binkert.org if len(COMMAND_LINE_TARGETS) != 0: 1936143Snate@binkert.org # easy: use specified targets as is 1946727Ssteve.reinhardt@amd.com my_targets = COMMAND_LINE_TARGETS 1956143Snate@binkert.org else: 1967674Snate@binkert.org # default target (ALPHA/m5.debug, unless overridden) 1977674Snate@binkert.org target = os.path.join(default_config, default_binary) 1985604Snate@binkert.org my_targets = [target] 1996143Snate@binkert.org Default(target) 2006143Snate@binkert.orgelse: 2016143Snate@binkert.org # invoked from subdirectory 2024762Snate@binkert.org if not launch_dir.startswith(ROOT): 2036143Snate@binkert.org print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \ 2044762Snate@binkert.org (launch_dir, ROOT) 2054762Snate@binkert.org sys.exit(1) 2064762Snate@binkert.org # make launch_dir relative to ROOT (strip ROOT plus slash off front) 2076143Snate@binkert.org launch_dir = launch_dir[len(ROOT)+1:] 2086143Snate@binkert.org if len(COMMAND_LINE_TARGETS) != 0: 2094762Snate@binkert.org # make specified targets relative to ROOT 2108233Snate@binkert.org my_targets = map(lambda x: os.path.join(launch_dir, x), 2118233Snate@binkert.org COMMAND_LINE_TARGETS) 2128233Snate@binkert.org else: 2138233Snate@binkert.org # build default binary (m5.debug, unless overridden) using the 2146143Snate@binkert.org # config inferred by the invocation directory (the first 2156143Snate@binkert.org # subdirectory after ROOT) 2164762Snate@binkert.org target = os.path.join(launch_dir.split('/')[0], default_binary) 2176143Snate@binkert.org my_targets = [target] 2184762Snate@binkert.org Default(target) 2196143Snate@binkert.org 2204762Snate@binkert.org# Normalize target paths (gets rid of '..' in the middle, etc.) 2216143Snate@binkert.orgmy_targets = map(os.path.normpath, my_targets) 2228233Snate@binkert.org 2238233Snate@binkert.org# Generate a list of the unique configs that the collected targets reference. 2248233Snate@binkert.orgbuild_dirs = [] 2256143Snate@binkert.orgfor t in my_targets: 2266143Snate@binkert.org dir = t.split('/')[0] 2276143Snate@binkert.org if dir not in build_dirs: 2286143Snate@binkert.org build_dirs.append(dir) 2296143Snate@binkert.org 2306143Snate@binkert.org################################################### 2316143Snate@binkert.org# 2326143Snate@binkert.org# Set up the default build environment. This environment is copied 2338233Snate@binkert.org# and modified according to each selected configuration. 2348233Snate@binkert.org# 235955SN/A################################################### 2368235Snate@binkert.org 2378235Snate@binkert.orgdefault_env = Environment(ENV = os.environ, # inherit user's enviroment vars 2386143Snate@binkert.org ROOT = ROOT, 2398235Snate@binkert.org SRCDIR = SRCDIR, 2409003SAli.Saidi@ARM.com EXT_SRCDIR = EXT_SRCDIR, 2418235Snate@binkert.org CPPDEFINES = [], 2428235Snate@binkert.org FULL_SYSTEM = False, 2438235Snate@binkert.org USE_MYSQL = False) 2448235Snate@binkert.org 2458235Snate@binkert.orgdefault_env.SConsignFile("sconsign") 2468235Snate@binkert.org 2478235Snate@binkert.org# For some reason, the CC and CXX variables don't get passed into the 2488235Snate@binkert.org# environment correctly. This is probably some sort of scons bug that 2498235Snate@binkert.org# will eventually be fixed. 2508235Snate@binkert.orgif os.environ.has_key('CC'): 2518235Snate@binkert.org default_env.Replace(CC=os.environ['CC']) 2528235Snate@binkert.org 2538235Snate@binkert.orgif os.environ.has_key('CXX'): 2548235Snate@binkert.org default_env.Replace(CXX=os.environ['CXX']) 2559003SAli.Saidi@ARM.com 2568235Snate@binkert.org# M5_EXT is used by isa_parser.py to find the PLY package. 2575584Snate@binkert.orgdefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR }) 2584382Sbinkertn@umich.edu 2594202Sbinkertn@umich.edudefault_env.Append(CCFLAGS='-pipe') 2604382Sbinkertn@umich.edudefault_env.Append(CCFLAGS='-fno-strict-aliasing') 2614382Sbinkertn@umich.edudefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2624382Sbinkertn@umich.edudefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')]) 2635584Snate@binkert.org 2644382Sbinkertn@umich.edu# libelf build is described in its own SConscript file. Using a 2654382Sbinkertn@umich.edu# dictionary for exports lets us export "default_env" so the 2664382Sbinkertn@umich.edu# SConscript will see it as "env". SConscript-global is the build in 2678232Snate@binkert.org# build/libelf shared among all configs. 2685192Ssaidi@eecs.umich.edudefault_env.SConscript('m5/libelf/SConscript-global', 2698232Snate@binkert.org exports={'env' : default_env}) 2708232Snate@binkert.org 2718232Snate@binkert.org################################################### 2725192Ssaidi@eecs.umich.edu# 2738232Snate@binkert.org# Define build environments for selected configurations. 2745192Ssaidi@eecs.umich.edu# 2755799Snate@binkert.org################################################### 2768232Snate@binkert.org 2775192Ssaidi@eecs.umich.edufor build_dir in build_dirs: 2785192Ssaidi@eecs.umich.edu # Make a copy of the default environment to use for this config. 2795192Ssaidi@eecs.umich.edu env = default_env.Copy() 2808232Snate@binkert.org # Modify 'env' according to the build directory config. 2815192Ssaidi@eecs.umich.edu print "Configuring options for directory '%s'." % build_dir 2828232Snate@binkert.org if not set_dir_options(build_dir, env): 2835192Ssaidi@eecs.umich.edu print "Skipping directory '%s'." % build_dir 2845192Ssaidi@eecs.umich.edu continue 2855192Ssaidi@eecs.umich.edu 2865192Ssaidi@eecs.umich.edu # The m5/SConscript file sets up the build rules in 'env' according 2874382Sbinkertn@umich.edu # to the configured options. 2884382Sbinkertn@umich.edu SConscript('m5/SConscript', build_dir = build_dir, exports = 'env', 2894382Sbinkertn@umich.edu duplicate=0) 2902667Sstever@eecs.umich.edu 2912667Sstever@eecs.umich.edu 2922667Sstever@eecs.umich.edu################################################### 2932667Sstever@eecs.umich.edu# 2942667Sstever@eecs.umich.edu# Let SCons do its thing. At this point SCons will use the defined 2952667Sstever@eecs.umich.edu# build environments to build the requested targets. 2965742Snate@binkert.org# 2975742Snate@binkert.org################################################### 2985742Snate@binkert.org 2995793Snate@binkert.org