SConstruct revision 2776
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# Authors: Steve Reinhardt 30955SN/A 315522Snate@binkert.org################################################### 326143Snate@binkert.org# 334762Snate@binkert.org# SCons top-level build description (SConstruct) file. 345522Snate@binkert.org# 35955SN/A# While in this directory ('m5'), just type 'scons' to build the default 365522Snate@binkert.org# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 385522Snate@binkert.org# the optimized full-system version). 394202Sbinkertn@umich.edu# 405742Snate@binkert.org# You can build M5 in a different directory as long as there is a 41955SN/A# 'build/<CONFIG>' somewhere along the target path. The build system 424381Sbinkertn@umich.edu# expects that all configs under the same build directory are being 434381Sbinkertn@umich.edu# built for the same host system. 448334Snate@binkert.org# 45955SN/A# Examples: 46955SN/A# 474202Sbinkertn@umich.edu# The following two commands are equivalent. The '-u' option tells 48955SN/A# scons to search up the directory tree for this SConstruct file. 494382Sbinkertn@umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 504382Sbinkertn@umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 514382Sbinkertn@umich.edu# 526654Snate@binkert.org# The following two commands are equivalent and demonstrate building 535517Snate@binkert.org# in a directory outside of the source tree. The '-C' option tells 547674Snate@binkert.org# scons to chdir to the specified directory to find this SConstruct 557674Snate@binkert.org# file. 566143Snate@binkert.org# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 576143Snate@binkert.org# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 586143Snate@binkert.org# 598233Snate@binkert.org# You can use 'scons -H' to print scons options. If you're in this 608233Snate@binkert.org# 'm5' directory (or use -u or -C to tell scons where to find this 618233Snate@binkert.org# file), you can use 'scons -h' to print all the M5-specific build 628233Snate@binkert.org# options as well. 638233Snate@binkert.org# 648334Snate@binkert.org################################################### 658334Snate@binkert.org 668233Snate@binkert.org# Python library imports 678233Snate@binkert.orgimport sys 688233Snate@binkert.orgimport os 698233Snate@binkert.org 708233Snate@binkert.org# Check for recent-enough Python and SCons versions. If your system's 718233Snate@binkert.org# default installation of Python is not recent enough, you can use a 726143Snate@binkert.org# non-default installation of the Python interpreter by either (1) 738233Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python' 748233Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the 758233Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 766143Snate@binkert.orgEnsurePythonVersion(2,4) 776143Snate@binkert.org 786143Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 796143Snate@binkert.org# 3-element version number. 808233Snate@binkert.orgmin_scons_version = (0,96,91) 818233Snate@binkert.orgtry: 828233Snate@binkert.org EnsureSConsVersion(*min_scons_version) 836143Snate@binkert.orgexcept: 848233Snate@binkert.org print "Error checking current SCons version." 858233Snate@binkert.org print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 868233Snate@binkert.org Exit(2) 878233Snate@binkert.org 886143Snate@binkert.org 896143Snate@binkert.org# The absolute path to the current directory (where this file lives). 906143Snate@binkert.orgROOT = Dir('.').abspath 914762Snate@binkert.org 926143Snate@binkert.org# Paths to the M5 and external source trees. 938233Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src') 948233Snate@binkert.org 958233Snate@binkert.org# tell python where to find m5 python code 968233Snate@binkert.orgsys.path.append(os.path.join(ROOT, 'src/python')) 978233Snate@binkert.org 986143Snate@binkert.org################################################### 998233Snate@binkert.org# 1008233Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 1018233Snate@binkert.org# the target(s). 1028233Snate@binkert.org# 1036143Snate@binkert.org################################################### 1046143Snate@binkert.org 1056143Snate@binkert.org# Find default configuration & binary. 1066143Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1076143Snate@binkert.org 1086143Snate@binkert.org# Ask SCons which directory it was invoked from. 1096143Snate@binkert.orglaunch_dir = GetLaunchDir() 1106143Snate@binkert.org 1116143Snate@binkert.org# Make targets relative to invocation directory 1127065Snate@binkert.orgabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 1136143Snate@binkert.org BUILD_TARGETS) 1148233Snate@binkert.org 1158233Snate@binkert.org# helper function: find last occurrence of element in list 1168233Snate@binkert.orgdef rfind(l, elt, offs = -1): 1178233Snate@binkert.org for i in range(len(l)+offs, 0, -1): 1188233Snate@binkert.org if l[i] == elt: 1198233Snate@binkert.org return i 1208233Snate@binkert.org raise ValueError, "element not found" 1218233Snate@binkert.org 1228233Snate@binkert.org# Each target must have 'build' in the interior of the path; the 1238233Snate@binkert.org# directory below this will determine the build parameters. For 1248233Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1258233Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 1268233Snate@binkert.org# follow 'build' in the bulid path. 1278233Snate@binkert.org 1288233Snate@binkert.org# Generate a list of the unique build roots and configs that the 1298233Snate@binkert.org# collected targets reference. 1308233Snate@binkert.orgbuild_paths = [] 1318233Snate@binkert.orgbuild_root = None 1328233Snate@binkert.orgfor t in abs_targets: 1338233Snate@binkert.org path_dirs = t.split('/') 1348233Snate@binkert.org try: 1358233Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 1368233Snate@binkert.org except: 1378233Snate@binkert.org print "Error: no non-leaf 'build' dir found on target path", t 1388233Snate@binkert.org Exit(1) 1398233Snate@binkert.org this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1408233Snate@binkert.org if not build_root: 1418233Snate@binkert.org build_root = this_build_root 1428233Snate@binkert.org else: 1438233Snate@binkert.org if this_build_root != build_root: 1448233Snate@binkert.org print "Error: build targets not under same build root\n"\ 1456143Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 1466143Snate@binkert.org Exit(1) 1476143Snate@binkert.org build_path = os.path.join('/',*path_dirs[:build_top+2]) 1486143Snate@binkert.org if build_path not in build_paths: 1496143Snate@binkert.org build_paths.append(build_path) 1506143Snate@binkert.org 1516143Snate@binkert.org################################################### 1526143Snate@binkert.org# 1536143Snate@binkert.org# Set up the default build environment. This environment is copied 1548233Snate@binkert.org# and modified according to each selected configuration. 1558233Snate@binkert.org# 1568233Snate@binkert.org################################################### 1576143Snate@binkert.org 1586143Snate@binkert.orgenv = Environment(ENV = os.environ, # inherit user's environment vars 1596143Snate@binkert.org ROOT = ROOT, 1606143Snate@binkert.org SRCDIR = SRCDIR) 1616143Snate@binkert.org 1626143Snate@binkert.orgenv.SConsignFile(os.path.join(build_root,"sconsign")) 1635522Snate@binkert.org 1646143Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 1656143Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 1666143Snate@binkert.org# file to file~ then copies to file, breaking the link. Symbolic 1676143Snate@binkert.org# (soft) links work better. 1688233Snate@binkert.orgenv.SetOption('duplicate', 'soft-copy') 1698233Snate@binkert.org 1708233Snate@binkert.org# I waffle on this setting... it does avoid a few painful but 1716143Snate@binkert.org# unnecessary builds, but it also seems to make trivial builds take 1726143Snate@binkert.org# noticeably longer. 1736143Snate@binkert.orgif False: 1746143Snate@binkert.org env.TargetSignatures('content') 1755522Snate@binkert.org 1765522Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package. 1775522Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 1785522Snate@binkert.org 1795604Snate@binkert.org# Set up default C++ compiler flags 1805604Snate@binkert.orgenv.Append(CCFLAGS='-pipe') 1816143Snate@binkert.orgenv.Append(CCFLAGS='-fno-strict-aliasing') 1826143Snate@binkert.orgenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1834762Snate@binkert.orgif sys.platform == 'cygwin': 1844762Snate@binkert.org # cygwin has some header file issues... 1856143Snate@binkert.org env.Append(CCFLAGS=Split("-Wno-uninitialized")) 1866727Ssteve.reinhardt@amd.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 1876727Ssteve.reinhardt@amd.com 1886727Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the 1894762Snate@binkert.org# interpreter. For consistency, we will use the same Python 1906143Snate@binkert.org# installation used to run scons (and thus this script). If you want 1916143Snate@binkert.org# to link in an alternate version, see above for instructions on how 1926143Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 1936143Snate@binkert.org 1946727Ssteve.reinhardt@amd.com# Get brief Python version name (e.g., "python2.4") for locating 1956143Snate@binkert.org# include & library files 1967674Snate@binkert.orgpy_version_name = 'python' + sys.version[:3] 1977674Snate@binkert.org 1985604Snate@binkert.org# include path, e.g. /usr/local/include/python2.4 1996143Snate@binkert.orgenv.Append(CPPPATH = os.path.join(sys.exec_prefix, 'include', py_version_name)) 2006143Snate@binkert.orgenv.Append(LIBS = py_version_name) 2016143Snate@binkert.org# add library path too if it's not in the default place 2024762Snate@binkert.orgif sys.exec_prefix != '/usr': 2036143Snate@binkert.org env.Append(LIBPATH = os.path.join(sys.exec_prefix, 'lib')) 2044762Snate@binkert.org 2054762Snate@binkert.org# Set up SWIG flags & scanner 2064762Snate@binkert.org 2076143Snate@binkert.orgenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2086143Snate@binkert.org 2094762Snate@binkert.orgimport SCons.Scanner 2108233Snate@binkert.org 2118233Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2128233Snate@binkert.org 2138233Snate@binkert.orgswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2146143Snate@binkert.org swig_inc_re) 2156143Snate@binkert.org 2164762Snate@binkert.orgenv.Append(SCANNERS = swig_scanner) 2176143Snate@binkert.org 2184762Snate@binkert.org# Other default libraries 2196143Snate@binkert.orgenv.Append(LIBS=['z']) 2204762Snate@binkert.org 2216143Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 2228233Snate@binkert.org# builds under a given build root run on the same host platform. 2238233Snate@binkert.orgconf = Configure(env, 2248233Snate@binkert.org conf_dir = os.path.join(build_root, '.scons_config'), 2256143Snate@binkert.org log_file = os.path.join(build_root, 'scons_config.log')) 2266143Snate@binkert.org 2276143Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 2286143Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>') 2296143Snate@binkert.orgif not have_fenv: 2306143Snate@binkert.org print "Warning: Header file <fenv.h> not found." 2316143Snate@binkert.org print " This host has no IEEE FP rounding mode control." 2326143Snate@binkert.org 2338233Snate@binkert.org# Check for mysql. 2348233Snate@binkert.orgmysql_config = WhereIs('mysql_config') 235955SN/Ahave_mysql = mysql_config != None 2368235Snate@binkert.org 2378235Snate@binkert.org# Check MySQL version. 2386143Snate@binkert.orgif have_mysql: 2398235Snate@binkert.org mysql_version = os.popen(mysql_config + ' --version').read() 2408235Snate@binkert.org mysql_version = mysql_version.split('.') 2418235Snate@binkert.org mysql_major = int(mysql_version[0]) 2428235Snate@binkert.org mysql_minor = int(mysql_version[1]) 2438235Snate@binkert.org # This version check is probably overly conservative, but it deals 2448235Snate@binkert.org # with the versions we have installed. 2458235Snate@binkert.org if mysql_major < 4 or (mysql_major == 4 and mysql_minor < 1): 2468235Snate@binkert.org print "Warning: MySQL v4.1 or newer required." 2478235Snate@binkert.org have_mysql = False 2488235Snate@binkert.org 2498235Snate@binkert.org# Set up mysql_config commands. 2508235Snate@binkert.orgif have_mysql: 2518235Snate@binkert.org mysql_config_include = mysql_config + ' --include' 2528235Snate@binkert.org if os.system(mysql_config_include + ' > /dev/null') != 0: 2538235Snate@binkert.org # older mysql_config versions don't support --include, use 2548235Snate@binkert.org # --cflags instead 2558235Snate@binkert.org mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 2565584Snate@binkert.org # This seems to work in all versions 2574382Sbinkertn@umich.edu mysql_config_libs = mysql_config + ' --libs' 2584202Sbinkertn@umich.edu 2594382Sbinkertn@umich.eduenv = conf.Finish() 2604382Sbinkertn@umich.edu 2614382Sbinkertn@umich.edu# Define the universe of supported ISAs 2625584Snate@binkert.orgenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 2634382Sbinkertn@umich.edu 2644382Sbinkertn@umich.edu# Define the universe of supported CPU models 2654382Sbinkertn@umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 2668232Snate@binkert.org 'FullCPU', 'AlphaO3CPU', 2675192Ssaidi@eecs.umich.edu 'OzoneSimpleCPU', 'OzoneCPU'] 2688232Snate@binkert.org 2698232Snate@binkert.org# Sticky options get saved in the options file so they persist from 2708232Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 2715192Ssaidi@eecs.umich.edu# value becomes sticky). 2728232Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS) 2735192Ssaidi@eecs.umich.edusticky_opts.AddOptions( 2745799Snate@binkert.org EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 2758232Snate@binkert.org BoolOption('FULL_SYSTEM', 'Full-system support', False), 2765192Ssaidi@eecs.umich.edu # There's a bug in scons 0.96.1 that causes ListOptions with list 2775192Ssaidi@eecs.umich.edu # values (more than one value) not to be able to be restored from 2785192Ssaidi@eecs.umich.edu # a saved option file. If this causes trouble then upgrade to 2798232Snate@binkert.org # scons 0.96.90 or later. 2805192Ssaidi@eecs.umich.edu ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 2818232Snate@binkert.org env['ALL_CPU_LIST']), 2825192Ssaidi@eecs.umich.edu BoolOption('ALPHA_TLASER', 2835192Ssaidi@eecs.umich.edu 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 2845192Ssaidi@eecs.umich.edu BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 2855192Ssaidi@eecs.umich.edu BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 2864382Sbinkertn@umich.edu False), 2874382Sbinkertn@umich.edu BoolOption('SS_COMPATIBLE_FP', 2884382Sbinkertn@umich.edu 'Make floating-point results compatible with SimpleScalar', 2892667Sstever@eecs.umich.edu False), 2902667Sstever@eecs.umich.edu BoolOption('USE_SSE2', 2912667Sstever@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 2922667Sstever@eecs.umich.edu False), 2932667Sstever@eecs.umich.edu BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 2942667Sstever@eecs.umich.edu BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 2955742Snate@binkert.org BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 2965742Snate@binkert.org ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 2975742Snate@binkert.org ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 2985793Snate@binkert.org BoolOption('BATCH', 'Use batch pool for build and tests', False), 2998334Snate@binkert.org ('BATCH_CMD', 'Batch pool submission command name', 'qdo') 3005793Snate@binkert.org ) 3015793Snate@binkert.org 3025793Snate@binkert.org# Non-sticky options only apply to the current build. 3034382Sbinkertn@umich.edunonsticky_opts = Options(args=ARGUMENTS) 3044762Snate@binkert.orgnonsticky_opts.AddOptions( 3055344Sstever@gmail.com BoolOption('update_ref', 'Update test reference outputs', False) 3064382Sbinkertn@umich.edu ) 3075341Sstever@gmail.com 3085742Snate@binkert.org# These options get exported to #defines in config/*.hh (see src/SConscript). 3095742Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 3105742Snate@binkert.org 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 3115742Snate@binkert.org 'USE_CHECKER'] 3125742Snate@binkert.org 3134762Snate@binkert.org# Define a handy 'no-op' action 3145742Snate@binkert.orgdef no_action(target, source, env): 3155742Snate@binkert.org return 0 3167722Sgblack@eecs.umich.edu 3175742Snate@binkert.orgenv.NoAction = Action(no_action, None) 3185742Snate@binkert.org 3195742Snate@binkert.org################################################### 3205742Snate@binkert.org# 3218242Sbradley.danofsky@amd.com# Define a SCons builder for configuration flag headers. 3228242Sbradley.danofsky@amd.com# 3238242Sbradley.danofsky@amd.com################################################### 3248242Sbradley.danofsky@amd.com 3255341Sstever@gmail.com# This function generates a config header file that #defines the 3265742Snate@binkert.org# option symbol to the current option setting (0 or 1). The source 3277722Sgblack@eecs.umich.edu# operands are the name of the option and a Value node containing the 3284773Snate@binkert.org# value of the option. 3296108Snate@binkert.orgdef build_config_file(target, source, env): 3301858SN/A (option, value) = [s.get_contents() for s in source] 3311085SN/A f = file(str(target[0]), 'w') 3326658Snate@binkert.org print >> f, '#define', option, value 3336658Snate@binkert.org f.close() 3347673Snate@binkert.org return None 3356658Snate@binkert.org 3366658Snate@binkert.org# Generate the message to be printed when building the config file. 3376658Snate@binkert.orgdef build_config_file_string(target, source, env): 3386658Snate@binkert.org (option, value) = [s.get_contents() for s in source] 3396658Snate@binkert.org return "Defining %s as %s in %s." % (option, value, target[0]) 3406658Snate@binkert.org 3416658Snate@binkert.org# Combine the two functions into a scons Action object. 3427673Snate@binkert.orgconfig_action = Action(build_config_file, build_config_file_string) 3437673Snate@binkert.org 3447673Snate@binkert.org# The emitter munges the source & target node lists to reflect what 3457673Snate@binkert.org# we're really doing. 3467673Snate@binkert.orgdef config_emitter(target, source, env): 3477673Snate@binkert.org # extract option name from Builder arg 3487673Snate@binkert.org option = str(target[0]) 3496658Snate@binkert.org # True target is config header file 3507673Snate@binkert.org target = os.path.join('config', option.lower() + '.hh') 3517673Snate@binkert.org # Force value to 0/1 even if it's a Python bool 3527673Snate@binkert.org val = int(eval(str(env[option]))) 3537673Snate@binkert.org # Sources are option name & value (packaged in SCons Value nodes) 3547673Snate@binkert.org return ([target], [Value(option), Value(val)]) 3557673Snate@binkert.org 3567673Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 3577673Snate@binkert.org 3587673Snate@binkert.orgenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 3597673Snate@binkert.org 3606658Snate@binkert.org################################################### 3617756SAli.Saidi@ARM.com# 3627816Ssteve.reinhardt@amd.com# Define a SCons builder for copying files. This is used by the 3636658Snate@binkert.org# Python zipfile code in src/python/SConscript, but is placed up here 3644382Sbinkertn@umich.edu# since it's potentially more generally applicable. 3654382Sbinkertn@umich.edu# 3664762Snate@binkert.org################################################### 3674762Snate@binkert.org 3684762Snate@binkert.orgcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 3696654Snate@binkert.org 3706654Snate@binkert.orgenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 3715517Snate@binkert.org 3725517Snate@binkert.org################################################### 3735517Snate@binkert.org# 3745517Snate@binkert.org# Define a simple SCons builder to concatenate files. 3755517Snate@binkert.org# 3765517Snate@binkert.org# Used to append the Python zip archive to the executable. 3775517Snate@binkert.org# 3785517Snate@binkert.org################################################### 3795517Snate@binkert.org 3805517Snate@binkert.orgconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 3815517Snate@binkert.org 'chmod +x $TARGET'])) 3825517Snate@binkert.org 3835517Snate@binkert.orgenv.Append(BUILDERS = { 'Concat' : concat_builder }) 3845517Snate@binkert.org 3855517Snate@binkert.org 3865517Snate@binkert.org# base help text 3875517Snate@binkert.orghelp_text = ''' 3886654Snate@binkert.orgUsage: scons [scons options] [build options] [target(s)] 3895517Snate@binkert.org 3905517Snate@binkert.org''' 3915517Snate@binkert.org 3925517Snate@binkert.org# libelf build is shared across all configs in the build root. 3935517Snate@binkert.orgenv.SConscript('ext/libelf/SConscript', 3945517Snate@binkert.org build_dir = os.path.join(build_root, 'libelf'), 3955517Snate@binkert.org exports = 'env') 3965517Snate@binkert.org 3976143Snate@binkert.org################################################### 3986654Snate@binkert.org# 3995517Snate@binkert.org# Define build environments for selected configurations. 4005517Snate@binkert.org# 4015517Snate@binkert.org################################################### 4025517Snate@binkert.org 4035517Snate@binkert.org# rename base env 4045517Snate@binkert.orgbase_env = env 4055517Snate@binkert.org 4065517Snate@binkert.orgfor build_path in build_paths: 4075517Snate@binkert.org print "Building in", build_path 4085517Snate@binkert.org # build_dir is the tail component of build path, and is used to 4095517Snate@binkert.org # determine the build parameters (e.g., 'ALPHA_SE') 4105517Snate@binkert.org (build_root, build_dir) = os.path.split(build_path) 4115517Snate@binkert.org # Make a copy of the build-root environment to use for this config. 4125517Snate@binkert.org env = base_env.Copy() 4136654Snate@binkert.org 4146654Snate@binkert.org # Set env options according to the build directory config. 4155517Snate@binkert.org sticky_opts.files = [] 4165517Snate@binkert.org # Options for $BUILD_ROOT/$BUILD_DIR are stored in 4176143Snate@binkert.org # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 4186143Snate@binkert.org # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 4196143Snate@binkert.org current_opts_file = os.path.join(build_root, 'options', build_dir) 4206727Ssteve.reinhardt@amd.com if os.path.isfile(current_opts_file): 4215517Snate@binkert.org sticky_opts.files.append(current_opts_file) 4226727Ssteve.reinhardt@amd.com print "Using saved options file %s" % current_opts_file 4235517Snate@binkert.org else: 4245517Snate@binkert.org # Build dir-specific options file doesn't exist. 4255517Snate@binkert.org 4266654Snate@binkert.org # Make sure the directory is there so we can create it later 4276654Snate@binkert.org opt_dir = os.path.dirname(current_opts_file) 4287673Snate@binkert.org if not os.path.isdir(opt_dir): 4296654Snate@binkert.org os.mkdir(opt_dir) 4306654Snate@binkert.org 4316654Snate@binkert.org # Get default build options from source tree. Options are 4326654Snate@binkert.org # normally determined by name of $BUILD_DIR, but can be 4335517Snate@binkert.org # overriden by 'default=' arg on command line. 4345517Snate@binkert.org default_opts_file = os.path.join('build_opts', 4355517Snate@binkert.org ARGUMENTS.get('default', build_dir)) 4366143Snate@binkert.org if os.path.isfile(default_opts_file): 4375517Snate@binkert.org sticky_opts.files.append(default_opts_file) 4384762Snate@binkert.org print "Options file %s not found,\n using defaults in %s" \ 4395517Snate@binkert.org % (current_opts_file, default_opts_file) 4405517Snate@binkert.org else: 4416143Snate@binkert.org print "Error: cannot find options file %s or %s" \ 4426143Snate@binkert.org % (current_opts_file, default_opts_file) 4435517Snate@binkert.org Exit(1) 4445517Snate@binkert.org 4455517Snate@binkert.org # Apply current option settings to env 4465517Snate@binkert.org sticky_opts.Update(env) 4475517Snate@binkert.org nonsticky_opts.Update(env) 4485517Snate@binkert.org 4495517Snate@binkert.org help_text += "Sticky options for %s:\n" % build_dir \ 4505517Snate@binkert.org + sticky_opts.GenerateHelpText(env) \ 4515517Snate@binkert.org + "\nNon-sticky options for %s:\n" % build_dir \ 4525517Snate@binkert.org + nonsticky_opts.GenerateHelpText(env) 4536143Snate@binkert.org 4545517Snate@binkert.org # Process option settings. 4556654Snate@binkert.org 4566654Snate@binkert.org if not have_fenv and env['USE_FENV']: 4576654Snate@binkert.org print "Warning: <fenv.h> not available; " \ 4586654Snate@binkert.org "forcing USE_FENV to False in", build_dir + "." 4596654Snate@binkert.org env['USE_FENV'] = False 4606654Snate@binkert.org 4615517Snate@binkert.org if not env['USE_FENV']: 4625517Snate@binkert.org print "Warning: No IEEE FP rounding mode control in", build_dir + "." 4635517Snate@binkert.org print " FP results may deviate slightly from other platforms." 4645517Snate@binkert.org 4655517Snate@binkert.org if env['EFENCE']: 4664762Snate@binkert.org env.Append(LIBS=['efence']) 4674762Snate@binkert.org 4684762Snate@binkert.org if env['USE_MYSQL']: 4694762Snate@binkert.org if not have_mysql: 4704762Snate@binkert.org print "Warning: MySQL not available; " \ 4714762Snate@binkert.org "forcing USE_MYSQL to False in", build_dir + "." 4727675Snate@binkert.org env['USE_MYSQL'] = False 4734762Snate@binkert.org else: 4744762Snate@binkert.org print "Compiling in", build_dir, "with MySQL support." 4754762Snate@binkert.org env.ParseConfig(mysql_config_libs) 4764762Snate@binkert.org env.ParseConfig(mysql_config_include) 4774382Sbinkertn@umich.edu 4784382Sbinkertn@umich.edu # Check if the Checker is being used. If so append it to env['CPU_MODELS'] 4795517Snate@binkert.org if env['USE_CHECKER']: 4806654Snate@binkert.org env['CPU_MODELS'].append('CheckerCPU') 4815517Snate@binkert.org 4828126Sgblack@eecs.umich.edu # Save sticky option settings back to current options file 4836654Snate@binkert.org sticky_opts.Save(current_opts_file, env) 4847673Snate@binkert.org 4856654Snate@binkert.org # Do this after we save setting back, or else we'll tack on an 4866654Snate@binkert.org # extra 'qdo' every time we run scons. 4876654Snate@binkert.org if env['BATCH']: 4886654Snate@binkert.org env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 4896654Snate@binkert.org env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 4906654Snate@binkert.org 4916654Snate@binkert.org if env['USE_SSE2']: 4926669Snate@binkert.org env.Append(CCFLAGS='-msse2') 4936669Snate@binkert.org 4946669Snate@binkert.org # The src/SConscript file sets up the build rules in 'env' according 4956669Snate@binkert.org # to the configured options. It returns a list of environments, 4966669Snate@binkert.org # one for each variant build (debug, opt, etc.) 4976669Snate@binkert.org envList = SConscript('src/SConscript', build_dir = build_path, 4986654Snate@binkert.org exports = 'env') 4997673Snate@binkert.org 5005517Snate@binkert.org # Set up the regression tests for each build. 5018126Sgblack@eecs.umich.edu# for e in envList: 5025798Snate@binkert.org# SConscript('m5-test/SConscript', 5037756SAli.Saidi@ARM.com# build_dir = os.path.join(build_dir, 'test', e.Label), 5047816Ssteve.reinhardt@amd.com# exports = { 'env' : e }, duplicate = False) 5055798Snate@binkert.org 5065798Snate@binkert.orgHelp(help_text) 5075517Snate@binkert.org 5085517Snate@binkert.org################################################### 5097673Snate@binkert.org# 5105517Snate@binkert.org# Let SCons do its thing. At this point SCons will use the defined 5115517Snate@binkert.org# build environments to build the requested targets. 5127673Snate@binkert.org# 5137673Snate@binkert.org################################################### 5145517Snate@binkert.org 5155798Snate@binkert.org