SConstruct revision 1851
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 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# 'ALPHA_FS/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 6610453SAndrew.Bardsley@arm.comsys.path.append(os.path.join(SRCDIR, 'python')) 6710453SAndrew.Bardsley@arm.com 688233Snate@binkert.org 698233Snate@binkert.org################################################### 708233Snate@binkert.org# 718233Snate@binkert.org# Define Configurations 728233Snate@binkert.org# 738233Snate@binkert.org# The build system infers the build options from the subdirectory name 746143Snate@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 768233Snate@binkert.org# (e.g., ALPHA_SE or ALPHA_FS) and OPT is an option (e.g., MYSQL). The 778233Snate@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. 806143Snate@binkert.org# 816143Snate@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 838233Snate@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 856143Snate@binkert.org# name string to the function. (The directory names are all upper 868233Snate@binkert.org# case, by convention.) 878233Snate@binkert.org# 888233Snate@binkert.org################################################### 898233Snate@binkert.org 906143Snate@binkert.org# Base non-full-system Alpha ISA configuration. 916143Snate@binkert.orgdef AlphaSyscallEmulConfig(env): 926143Snate@binkert.org env.Replace(TARGET_ISA = 'alpha') 934762Snate@binkert.org env.Append(CPPDEFINES = 'SS_COMPATIBLE_FP') 946143Snate@binkert.org 958233Snate@binkert.org# Base full-system configuration. 968233Snate@binkert.orgdef AlphaFullSysConfig(env): 978233Snate@binkert.org env.Replace(TARGET_ISA = 'alpha') 988233Snate@binkert.org env.Replace(FULL_SYSTEM = True) 998233Snate@binkert.org env.Append(CPPDEFINES = ['FULL_SYSTEM']) 1006143Snate@binkert.org 1018233Snate@binkert.org# Base configurations map. 1028233Snate@binkert.orgconfigs_map = { 1038233Snate@binkert.org 'ALPHA_SE' : AlphaSyscallEmulConfig, 1048233Snate@binkert.org 'ALPHA_FS' : AlphaFullSysConfig 1056143Snate@binkert.org } 1066143Snate@binkert.org 1076143Snate@binkert.org# Disable FastAlloc object allocation. 1086143Snate@binkert.orgdef NoFastAllocOpt(env): 1096143Snate@binkert.org env.Append(CPPDEFINES = 'NO_FAST_ALLOC') 1106143Snate@binkert.org 1116143Snate@binkert.org# Enable efence 1126143Snate@binkert.orgdef EfenceOpt(env): 1136143Snate@binkert.org env.Append(LIBS=['efence']) 1147065Snate@binkert.org 1156143Snate@binkert.org# Configuration options map. 1168233Snate@binkert.orgoptions_map = { 1178233Snate@binkert.org 'NO_FAST_ALLOC' : NoFastAllocOpt, 1188233Snate@binkert.org 'EFENCE' : EfenceOpt 1198233Snate@binkert.org } 1208233Snate@binkert.org 1218233Snate@binkert.org# The 'local_configs' file can be used to define additional base 1228233Snate@binkert.org# configurations and/or options without changing this file. 1238233Snate@binkert.orgif os.path.isfile('local_configs'): 1248233Snate@binkert.org SConscript('local_configs', exports = ['configs_map', 'options_map']) 1258233Snate@binkert.org 1268233Snate@binkert.org# This function parses a directory name of the form <CONFIG>[.<OPT>]* 1278233Snate@binkert.org# and sets up the build environment appropriately. Returns True if 1288233Snate@binkert.org# successful, False if the base config or any of the options were not 1298233Snate@binkert.org# defined. 1308233Snate@binkert.orgdef set_dir_options(dir, env): 1318233Snate@binkert.org parts = dir.split('.') 1328233Snate@binkert.org config = parts[0] 1338233Snate@binkert.org opts = parts[1:] 1348233Snate@binkert.org try: 1358233Snate@binkert.org configs_map[config](env) 1368233Snate@binkert.org map(lambda opt: options_map[opt](env), opts) 1378233Snate@binkert.org return True 1388233Snate@binkert.org except KeyError, key: 1398233Snate@binkert.org print "Config/option '%s' not found." % key 1408233Snate@binkert.org return False 1418233Snate@binkert.org 1428233Snate@binkert.org# Set the default configuration and binary. The default target (if 1438233Snate@binkert.org# scons is invoked at the top level with no command-line targets) is 1448233Snate@binkert.org# 'ALPHA_SE/m5.debug'. If scons is invoked in a subdirectory with no 1458233Snate@binkert.org# command-line targets, the configuration 1468233Snate@binkert.org 1476143Snate@binkert.org################################################### 1486143Snate@binkert.org# 1496143Snate@binkert.org# Figure out which configurations to set up. 1506143Snate@binkert.org# 1516143Snate@binkert.org# 1526143Snate@binkert.org# It's prohibitive to do all the combinations of base configurations 1539982Satgutier@umich.edu# and options, so we have to infer which ones the user wants. 15410196SCurtis.Dunham@arm.com# 15510196SCurtis.Dunham@arm.com# 1. If there are command-line targets, the configuration(s) are inferred 15610196SCurtis.Dunham@arm.com# from the directories of those targets. If scons was invoked from a 15710196SCurtis.Dunham@arm.com# subdirectory (using 'scons -u'), those targets have to be 15810196SCurtis.Dunham@arm.com# interpreted relative to that subdirectory. 15910196SCurtis.Dunham@arm.com# 16010196SCurtis.Dunham@arm.com# 2. If there are no command-line targets, and scons was invoked from a 16110196SCurtis.Dunham@arm.com# subdirectory (using 'scons -u'), the configuration is inferred from 1626143Snate@binkert.org# the name of the subdirectory. 1636143Snate@binkert.org# 1648945Ssteve.reinhardt@amd.com# 3. If there are no command-line targets and scons was invoked from 1658233Snate@binkert.org# the root build directory, a default configuration is used. The 1668233Snate@binkert.org# built-in default is ALPHA_SE, but this can be overridden by setting the 1676143Snate@binkert.org# M5_DEFAULT_CONFIG shell environment veriable. 1688945Ssteve.reinhardt@amd.com# 1696143Snate@binkert.org# In cases 2 & 3, the specific file target defaults to 'm5.debug', but 1706143Snate@binkert.org# this can be overridden by setting the M5_DEFAULT_BINARY shell 1716143Snate@binkert.org# environment veriable. 1726143Snate@binkert.org# 1735522Snate@binkert.org################################################### 1746143Snate@binkert.org 1756143Snate@binkert.org# Find default configuration & binary. 1766143Snate@binkert.orgdefault_config = os.environ.get('M5_DEFAULT_CONFIG', 'ALPHA_SE') 1779982Satgutier@umich.edudefault_binary = os.environ.get('M5_DEFAULT_BINARY', 'm5.debug') 1788233Snate@binkert.org 1798233Snate@binkert.org# Ask SCons which directory it was invoked from. If you invoke SCons 1808233Snate@binkert.org# from a subdirectory you must use the '-u' flag. 1816143Snate@binkert.orglaunch_dir = GetLaunchDir() 1826143Snate@binkert.org 1836143Snate@binkert.org# Build a list 'my_targets' of all the targets relative to ROOT. 1846143Snate@binkert.orgif launch_dir == ROOT: 1855522Snate@binkert.org # invoked from root build dir 1865522Snate@binkert.org if len(COMMAND_LINE_TARGETS) != 0: 1875522Snate@binkert.org # easy: use specified targets as is 1885522Snate@binkert.org my_targets = COMMAND_LINE_TARGETS 1895604Snate@binkert.org else: 1905604Snate@binkert.org # default target (ALPHA_SE/m5.debug, unless overridden) 1916143Snate@binkert.org target = os.path.join(default_config, default_binary) 1926143Snate@binkert.org my_targets = [target] 1934762Snate@binkert.org Default(target) 1944762Snate@binkert.orgelse: 1956143Snate@binkert.org # invoked from subdirectory 1966727Ssteve.reinhardt@amd.com if not launch_dir.startswith(ROOT): 1976727Ssteve.reinhardt@amd.com print "Error: launch dir (%s) not a subdirectory of ROOT (%s)!" \ 1986727Ssteve.reinhardt@amd.com (launch_dir, ROOT) 1994762Snate@binkert.org sys.exit(1) 2006143Snate@binkert.org # make launch_dir relative to ROOT (strip ROOT plus slash off front) 2016143Snate@binkert.org launch_dir = launch_dir[len(ROOT)+1:] 2026143Snate@binkert.org if len(COMMAND_LINE_TARGETS) != 0: 2036143Snate@binkert.org # make specified targets relative to ROOT 2046727Ssteve.reinhardt@amd.com my_targets = map(lambda x: os.path.join(launch_dir, x), 2056143Snate@binkert.org COMMAND_LINE_TARGETS) 2067674Snate@binkert.org else: 2077674Snate@binkert.org # build default binary (m5.debug, unless overridden) using the 2085604Snate@binkert.org # config inferred by the invocation directory (the first 2096143Snate@binkert.org # subdirectory after ROOT) 2106143Snate@binkert.org target = os.path.join(launch_dir.split('/')[0], default_binary) 2116143Snate@binkert.org my_targets = [target] 2124762Snate@binkert.org Default(target) 2136143Snate@binkert.org 2144762Snate@binkert.org# Normalize target paths (gets rid of '..' in the middle, etc.) 2154762Snate@binkert.orgmy_targets = map(os.path.normpath, my_targets) 2164762Snate@binkert.org 2176143Snate@binkert.org# Generate a list of the unique configs that the collected targets reference. 2186143Snate@binkert.orgbuild_dirs = [] 2194762Snate@binkert.orgfor t in my_targets: 2208233Snate@binkert.org dir = t.split('/')[0] 2218233Snate@binkert.org if dir not in build_dirs: 2228233Snate@binkert.org build_dirs.append(dir) 2238233Snate@binkert.org 2246143Snate@binkert.org################################################### 2256143Snate@binkert.org# 2264762Snate@binkert.org# Set up the default build environment. This environment is copied 2276143Snate@binkert.org# and modified according to each selected configuration. 2284762Snate@binkert.org# 2296143Snate@binkert.org################################################### 2304762Snate@binkert.org 2316143Snate@binkert.orgdefault_env = Environment(ENV = os.environ, # inherit user's enviroment vars 2328233Snate@binkert.org ROOT = ROOT, 2338233Snate@binkert.org SRCDIR = SRCDIR, 23410453SAndrew.Bardsley@arm.com EXT_SRCDIR = EXT_SRCDIR, 2356143Snate@binkert.org CPPDEFINES = [], 2366143Snate@binkert.org FULL_SYSTEM = False, 2376143Snate@binkert.org ALPHA_TLASER = False, 2386143Snate@binkert.org USE_MYSQL = False) 2396143Snate@binkert.org 2406143Snate@binkert.orgdefault_env.SConsignFile("sconsign") 2416143Snate@binkert.org 2426143Snate@binkert.org# For some reason, the CC and CXX variables don't get passed into the 24310453SAndrew.Bardsley@arm.com# environment correctly. This is probably some sort of scons bug that 24410453SAndrew.Bardsley@arm.com# will eventually be fixed. 245955SN/Aif os.environ.has_key('CC'): 2469396Sandreas.hansson@arm.com default_env.Replace(CC=os.environ['CC']) 2479396Sandreas.hansson@arm.com 2489396Sandreas.hansson@arm.comif os.environ.has_key('CXX'): 2499396Sandreas.hansson@arm.com default_env.Replace(CXX=os.environ['CXX']) 2509396Sandreas.hansson@arm.com 2519396Sandreas.hansson@arm.com# M5_EXT is used by isa_parser.py to find the PLY package. 2529396Sandreas.hansson@arm.comdefault_env.Append(ENV = { 'M5_EXT' : EXT_SRCDIR }) 2539396Sandreas.hansson@arm.com 2549396Sandreas.hansson@arm.comdefault_env.Append(CCFLAGS='-pipe') 2559396Sandreas.hansson@arm.comdefault_env.Append(CCFLAGS='-fno-strict-aliasing') 2569396Sandreas.hansson@arm.comdefault_env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2579396Sandreas.hansson@arm.comif sys.platform == 'cygwin': 2589396Sandreas.hansson@arm.com # cygwin has some header file issues... 2599930Sandreas.hansson@arm.com default_env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2609930Sandreas.hansson@arm.comdefault_env.Append(CPPPATH=[os.path.join(EXT_SRCDIR + '/dnet')]) 2619396Sandreas.hansson@arm.com 2628235Snate@binkert.org# libelf build is described in its own SConscript file. Using a 2638235Snate@binkert.org# dictionary for exports lets us export "default_env" so the 2646143Snate@binkert.org# SConscript will see it as "env". SConscript-global is the build in 2658235Snate@binkert.org# build/libelf shared among all configs. 2669003SAli.Saidi@ARM.comdefault_env.SConscript('m5/libelf/SConscript-global', 2678235Snate@binkert.org exports={'env' : default_env}) 2688235Snate@binkert.org 2698235Snate@binkert.org################################################### 2708235Snate@binkert.org# 2718235Snate@binkert.org# Define build environments for selected configurations. 2728235Snate@binkert.org# 2738235Snate@binkert.org################################################### 2748235Snate@binkert.org 2758235Snate@binkert.orgfor build_dir in build_dirs: 2768235Snate@binkert.org # Make a copy of the default environment to use for this config. 2778235Snate@binkert.org env = default_env.Copy() 2788235Snate@binkert.org # Modify 'env' according to the build directory config. 2798235Snate@binkert.org print "Configuring options for directory '%s'." % build_dir 2808235Snate@binkert.org if not set_dir_options(build_dir, env): 2819003SAli.Saidi@ARM.com print "Skipping directory '%s'." % build_dir 2828235Snate@binkert.org continue 2835584Snate@binkert.org 2844382Sbinkertn@umich.edu # The m5/SConscript file sets up the build rules in 'env' according 2854202Sbinkertn@umich.edu # to the configured options. 2864382Sbinkertn@umich.edu SConscript('m5/SConscript', build_dir = build_dir, exports = 'env', 2874382Sbinkertn@umich.edu duplicate=0) 2884382Sbinkertn@umich.edu 2899396Sandreas.hansson@arm.com 2905584Snate@binkert.org################################################### 2914382Sbinkertn@umich.edu# 2924382Sbinkertn@umich.edu# Let SCons do its thing. At this point SCons will use the defined 2934382Sbinkertn@umich.edu# build environments to build the requested targets. 2948232Snate@binkert.org# 2955192Ssaidi@eecs.umich.edu################################################### 2968232Snate@binkert.org 2978232Snate@binkert.org