SConstruct revision 3685
1955SN/A# -*- mode:python -*- 2955SN/A 311408Sandreas.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# Authors: Steve Reinhardt 30955SN/A 31955SN/A################################################### 32955SN/A# 33955SN/A# SCons top-level build description (SConstruct) file. 34955SN/A# 35955SN/A# While in this directory ('m5'), just type 'scons' to build the default 36955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 38955SN/A# the optimized full-system version). 39955SN/A# 40955SN/A# 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 422665Ssaidi@eecs.umich.edu# expects that all configs under the same build directory are being 432665Ssaidi@eecs.umich.edu# built for the same host system. 445863Snate@binkert.org# 45955SN/A# Examples: 46955SN/A# 47955SN/A# The following two commands are equivalent. The '-u' option tells 48955SN/A# scons to search up the directory tree for this SConstruct file. 49955SN/A# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 508878Ssteve.reinhardt@amd.com# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512632Sstever@eecs.umich.edu# 528878Ssteve.reinhardt@amd.com# The following two commands are equivalent and demonstrate building 532632Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 54955SN/A# scons to chdir to the specified directory to find this SConstruct 558878Ssteve.reinhardt@amd.com# file. 562632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 572761Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 582632Sstever@eecs.umich.edu# 592632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 602632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 612761Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 622761Sstever@eecs.umich.edu# options as well. 632761Sstever@eecs.umich.edu# 648878Ssteve.reinhardt@amd.com################################################### 658878Ssteve.reinhardt@amd.com 662761Sstever@eecs.umich.edu# Python library imports 672761Sstever@eecs.umich.eduimport sys 682761Sstever@eecs.umich.eduimport os 692761Sstever@eecs.umich.edu 702761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 718878Ssteve.reinhardt@amd.com# default installation of Python is not recent enough, you can use a 728878Ssteve.reinhardt@amd.com# non-default installation of the Python interpreter by either (1) 732632Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 742632Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 758878Ssteve.reinhardt@amd.com# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 768878Ssteve.reinhardt@amd.comEnsurePythonVersion(2,4) 772632Sstever@eecs.umich.edu 78955SN/A# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 79955SN/A# 3-element version number. 80955SN/Amin_scons_version = (0,96,91) 815863Snate@binkert.orgtry: 825863Snate@binkert.org EnsureSConsVersion(*min_scons_version) 835863Snate@binkert.orgexcept: 845863Snate@binkert.org print "Error checking current SCons version." 855863Snate@binkert.org print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 865863Snate@binkert.org Exit(2) 875863Snate@binkert.org 885863Snate@binkert.org 895863Snate@binkert.org# The absolute path to the current directory (where this file lives). 905863Snate@binkert.orgROOT = Dir('.').abspath 915863Snate@binkert.org 928878Ssteve.reinhardt@amd.com# Paths to the M5 and external source trees. 935863Snate@binkert.orgSRCDIR = os.path.join(ROOT, 'src') 945863Snate@binkert.org 955863Snate@binkert.org# tell python where to find m5 python code 969812Sandreas.hansson@arm.comsys.path.append(os.path.join(ROOT, 'src/python')) 979812Sandreas.hansson@arm.com 985863Snate@binkert.org################################################### 999812Sandreas.hansson@arm.com# 1005863Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 1015863Snate@binkert.org# the target(s). 1025863Snate@binkert.org# 1039812Sandreas.hansson@arm.com################################################### 1049812Sandreas.hansson@arm.com 1055863Snate@binkert.org# Find default configuration & binary. 1065863Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1078878Ssteve.reinhardt@amd.com 1085863Snate@binkert.org# Ask SCons which directory it was invoked from. 1095863Snate@binkert.orglaunch_dir = GetLaunchDir() 1105863Snate@binkert.org 1116654Snate@binkert.org# Make targets relative to invocation directory 11210196SCurtis.Dunham@arm.comabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 113955SN/A BUILD_TARGETS) 1145396Ssaidi@eecs.umich.edu 11511401Sandreas.sandberg@arm.com# helper function: find last occurrence of element in list 1165863Snate@binkert.orgdef rfind(l, elt, offs = -1): 1175863Snate@binkert.org for i in range(len(l)+offs, 0, -1): 1184202Sbinkertn@umich.edu if l[i] == elt: 1195863Snate@binkert.org return i 1205863Snate@binkert.org raise ValueError, "element not found" 1215863Snate@binkert.org 1225863Snate@binkert.org# helper function: compare dotted version numbers. 123955SN/A# E.g., compare_version('1.3.25', '1.4.1') 1246654Snate@binkert.org# returns -1, 0, 1 if v1 is <, ==, > v2 1255273Sstever@gmail.comdef compare_versions(v1, v2): 1265871Snate@binkert.org # Convert dotted strings to lists 1275273Sstever@gmail.com v1 = map(int, v1.split('.')) 1286655Snate@binkert.org v2 = map(int, v2.split('.')) 1298878Ssteve.reinhardt@amd.com # Compare corresponding elements of lists 1306655Snate@binkert.org for n1,n2 in zip(v1, v2): 1316655Snate@binkert.org if n1 < n2: return -1 1329219Spower.jg@gmail.com if n1 > n2: return 1 1336655Snate@binkert.org # all corresponding values are equal... see if one has extra values 1345871Snate@binkert.org if len(v1) < len(v2): return -1 1356654Snate@binkert.org if len(v1) > len(v2): return 1 1368947Sandreas.hansson@arm.com return 0 1375396Ssaidi@eecs.umich.edu 1388120Sgblack@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 1398120Sgblack@eecs.umich.edu# directory below this will determine the build parameters. For 1408120Sgblack@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1418120Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 1428120Sgblack@eecs.umich.edu# follow 'build' in the bulid path. 1438120Sgblack@eecs.umich.edu 1448120Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1458120Sgblack@eecs.umich.edu# collected targets reference. 1468879Ssteve.reinhardt@amd.combuild_paths = [] 1478879Ssteve.reinhardt@amd.combuild_root = None 1488879Ssteve.reinhardt@amd.comfor t in abs_targets: 1498879Ssteve.reinhardt@amd.com path_dirs = t.split('/') 1508879Ssteve.reinhardt@amd.com try: 1518879Ssteve.reinhardt@amd.com build_top = rfind(path_dirs, 'build', -2) 1528879Ssteve.reinhardt@amd.com except: 1538879Ssteve.reinhardt@amd.com print "Error: no non-leaf 'build' dir found on target path", t 1548879Ssteve.reinhardt@amd.com Exit(1) 1558879Ssteve.reinhardt@amd.com this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1568879Ssteve.reinhardt@amd.com if not build_root: 1578879Ssteve.reinhardt@amd.com build_root = this_build_root 1588879Ssteve.reinhardt@amd.com else: 1598120Sgblack@eecs.umich.edu if this_build_root != build_root: 1608120Sgblack@eecs.umich.edu print "Error: build targets not under same build root\n"\ 1618120Sgblack@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1628120Sgblack@eecs.umich.edu Exit(1) 1638120Sgblack@eecs.umich.edu build_path = os.path.join('/',*path_dirs[:build_top+2]) 1648120Sgblack@eecs.umich.edu if build_path not in build_paths: 1658120Sgblack@eecs.umich.edu build_paths.append(build_path) 1668120Sgblack@eecs.umich.edu 1678120Sgblack@eecs.umich.edu################################################### 1688120Sgblack@eecs.umich.edu# 1698120Sgblack@eecs.umich.edu# Set up the default build environment. This environment is copied 1708120Sgblack@eecs.umich.edu# and modified according to each selected configuration. 1718120Sgblack@eecs.umich.edu# 1728120Sgblack@eecs.umich.edu################################################### 1738879Ssteve.reinhardt@amd.com 1748879Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ, # inherit user's environment vars 1758879Ssteve.reinhardt@amd.com ROOT = ROOT, 1768879Ssteve.reinhardt@amd.com SRCDIR = SRCDIR) 17710458Sandreas.hansson@arm.com 17810458Sandreas.hansson@arm.com#Parse CC/CXX early so that we use the correct compiler for 17910458Sandreas.hansson@arm.com# to test for dependencies/versions/libraries/includes 1808879Ssteve.reinhardt@amd.comif ARGUMENTS.get('CC', None): 1818879Ssteve.reinhardt@amd.com env['CC'] = ARGUMENTS.get('CC') 1828879Ssteve.reinhardt@amd.com 1838879Ssteve.reinhardt@amd.comif ARGUMENTS.get('CXX', None): 1849227Sandreas.hansson@arm.com env['CXX'] = ARGUMENTS.get('CXX') 1859227Sandreas.hansson@arm.com 1868879Ssteve.reinhardt@amd.comenv.SConsignFile(os.path.join(build_root,"sconsign")) 1878879Ssteve.reinhardt@amd.com 1888879Ssteve.reinhardt@amd.com# Default duplicate option is to use hard links, but this messes up 1898879Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves 19010453SAndrew.Bardsley@arm.com# file to file~ then copies to file, breaking the link. Symbolic 19110453SAndrew.Bardsley@arm.com# (soft) links work better. 19210453SAndrew.Bardsley@arm.comenv.SetOption('duplicate', 'soft-copy') 19310456SCurtis.Dunham@arm.com 19410456SCurtis.Dunham@arm.com# I waffle on this setting... it does avoid a few painful but 19510456SCurtis.Dunham@arm.com# unnecessary builds, but it also seems to make trivial builds take 19610457Sandreas.hansson@arm.com# noticeably longer. 19710457Sandreas.hansson@arm.comif False: 19811342Sandreas.hansson@arm.com env.TargetSignatures('content') 19911342Sandreas.hansson@arm.com 2008120Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 2018947Sandreas.hansson@arm.comenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 2027816Ssteve.reinhardt@amd.com 2035871Snate@binkert.org# Set up default C++ compiler flags 2045871Snate@binkert.orgenv.Append(CCFLAGS='-pipe') 2056121Snate@binkert.orgenv.Append(CCFLAGS='-fno-strict-aliasing') 2065871Snate@binkert.orgenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2075871Snate@binkert.orgif sys.platform == 'cygwin': 2089926Sstan.czerniawski@arm.com # cygwin has some header file issues... 2099926Sstan.czerniawski@arm.com env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2109119Sandreas.hansson@arm.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 21110068Sandreas.hansson@arm.com 21211989Sandreas.sandberg@arm.com# Check for SWIG 213955SN/Aif not env.has_key('SWIG'): 2149416SAndreas.Sandberg@ARM.com print 'Error: SWIG utility not found.' 21511342Sandreas.hansson@arm.com print ' Please install (see http://www.swig.org) and retry.' 21611212Sjoseph.gross@amd.com Exit(1) 21711212Sjoseph.gross@amd.com 21811212Sjoseph.gross@amd.com# Check for appropriate SWIG version 21911212Sjoseph.gross@amd.comswig_version = os.popen('swig -version').read().split() 22011212Sjoseph.gross@amd.com# First 3 words should be "SWIG Version x.y.z" 2219416SAndreas.Sandberg@ARM.comif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2229416SAndreas.Sandberg@ARM.com print 'Error determining SWIG version.' 2235871Snate@binkert.org Exit(1) 22410584Sandreas.hansson@arm.com 2259416SAndreas.Sandberg@ARM.commin_swig_version = '1.3.28' 2269416SAndreas.Sandberg@ARM.comif compare_versions(swig_version[2], min_swig_version) < 0: 2275871Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 228955SN/A print ' Installed version:', swig_version[2] 22910671Sandreas.hansson@arm.com Exit(1) 23010671Sandreas.hansson@arm.com 23110671Sandreas.hansson@arm.com# Set up SWIG flags & scanner 23210671Sandreas.hansson@arm.comenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2338881Smarc.orr@gmail.com 2346121Snate@binkert.orgimport SCons.Scanner 2356121Snate@binkert.org 2361533SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2379239Sandreas.hansson@arm.com 2389239Sandreas.hansson@arm.comswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2399239Sandreas.hansson@arm.com swig_inc_re) 2409239Sandreas.hansson@arm.com 2419239Sandreas.hansson@arm.comenv.Append(SCANNERS = swig_scanner) 2429239Sandreas.hansson@arm.com 2439239Sandreas.hansson@arm.com# Platform-specific configuration. Note again that we assume that all 2446655Snate@binkert.org# builds under a given build root run on the same host platform. 2456655Snate@binkert.orgconf = Configure(env, 2466655Snate@binkert.org conf_dir = os.path.join(build_root, '.scons_config'), 2476655Snate@binkert.org log_file = os.path.join(build_root, 'scons_config.log')) 2485871Snate@binkert.org 2495871Snate@binkert.org# Find Python include and library directories for embedding the 2505863Snate@binkert.org# interpreter. For consistency, we will use the same Python 2515871Snate@binkert.org# installation used to run scons (and thus this script). If you want 2528878Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how 2535871Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 2545871Snate@binkert.org 2555871Snate@binkert.org# Get brief Python version name (e.g., "python2.4") for locating 2565863Snate@binkert.org# include & library files 2576121Snate@binkert.orgpy_version_name = 'python' + sys.version[:3] 2585863Snate@binkert.org 25911408Sandreas.sandberg@arm.com# include path, e.g. /usr/local/include/python2.4 26011408Sandreas.sandberg@arm.compy_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name) 2618336Ssteve.reinhardt@amd.comenv.Append(CPPPATH = py_header_path) 26211469SCurtis.Dunham@arm.com# verify that it works 26311469SCurtis.Dunham@arm.comif not conf.CheckHeader('Python.h', '<>'): 2648336Ssteve.reinhardt@amd.com print "Error: can't find Python.h header in", py_header_path 2654678Snate@binkert.org Exit(1) 26611887Sandreas.sandberg@arm.com 26711887Sandreas.sandberg@arm.com# add library path too if it's not in the default place 26811887Sandreas.sandberg@arm.compy_lib_path = None 26911887Sandreas.sandberg@arm.comif sys.exec_prefix != '/usr': 27011887Sandreas.sandberg@arm.com py_lib_path = os.path.join(sys.exec_prefix, 'lib') 27111887Sandreas.sandberg@arm.comelif sys.platform == 'cygwin': 27211887Sandreas.sandberg@arm.com # cygwin puts the .dll in /bin for some reason 27311887Sandreas.sandberg@arm.com py_lib_path = '/bin' 27411887Sandreas.sandberg@arm.comif py_lib_path: 27511887Sandreas.sandberg@arm.com env.Append(LIBPATH = py_lib_path) 27611887Sandreas.sandberg@arm.com print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 27711408Sandreas.sandberg@arm.comif not conf.CheckLib(py_version_name): 27811401Sandreas.sandberg@arm.com print "Error: can't find Python library", py_version_name 27911401Sandreas.sandberg@arm.com Exit(1) 28011401Sandreas.sandberg@arm.com 28111401Sandreas.sandberg@arm.com# On Solaris you need to use libsocket for socket ops 28211401Sandreas.sandberg@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 28311401Sandreas.sandberg@arm.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2848336Ssteve.reinhardt@amd.com print "Can't find library with socket calls (e.g. accept())" 2858336Ssteve.reinhardt@amd.com Exit(1) 2868336Ssteve.reinhardt@amd.com 2874678Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 28811401Sandreas.sandberg@arm.com# added to the LIBS environment variable. 2894678Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 2904678Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 29111401Sandreas.sandberg@arm.com 'and/or zlib.h header file.' 29211401Sandreas.sandberg@arm.com print ' Please install zlib and try again.' 2938336Ssteve.reinhardt@amd.com Exit(1) 2944678Snate@binkert.org 2958336Ssteve.reinhardt@amd.com# Check for <fenv.h> (C99 FP environment control) 2968336Ssteve.reinhardt@amd.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 2978336Ssteve.reinhardt@amd.comif not have_fenv: 2988336Ssteve.reinhardt@amd.com print "Warning: Header file <fenv.h> not found." 2998336Ssteve.reinhardt@amd.com print " This host has no IEEE FP rounding mode control." 3008336Ssteve.reinhardt@amd.com 3015871Snate@binkert.org# Check for mysql. 3025871Snate@binkert.orgmysql_config = WhereIs('mysql_config') 3038336Ssteve.reinhardt@amd.comhave_mysql = mysql_config != None 30411408Sandreas.sandberg@arm.com 30511408Sandreas.sandberg@arm.com# Check MySQL version. 30611408Sandreas.sandberg@arm.comif have_mysql: 30711408Sandreas.sandberg@arm.com mysql_version = os.popen(mysql_config + ' --version').read() 30811408Sandreas.sandberg@arm.com min_mysql_version = '4.1' 30911408Sandreas.sandberg@arm.com if compare_versions(mysql_version, min_mysql_version) < 0: 31011408Sandreas.sandberg@arm.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3118336Ssteve.reinhardt@amd.com print ' Version', mysql_version, 'detected.' 31211401Sandreas.sandberg@arm.com have_mysql = False 31311401Sandreas.sandberg@arm.com 31411401Sandreas.sandberg@arm.com# Set up mysql_config commands. 3155871Snate@binkert.orgif have_mysql: 3168336Ssteve.reinhardt@amd.com mysql_config_include = mysql_config + ' --include' 3178336Ssteve.reinhardt@amd.com if os.system(mysql_config_include + ' > /dev/null') != 0: 31811401Sandreas.sandberg@arm.com # older mysql_config versions don't support --include, use 31911401Sandreas.sandberg@arm.com # --cflags instead 32011401Sandreas.sandberg@arm.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 32111401Sandreas.sandberg@arm.com # This seems to work in all versions 32211401Sandreas.sandberg@arm.com mysql_config_libs = mysql_config + ' --libs' 3234678Snate@binkert.org 3245871Snate@binkert.orgenv = conf.Finish() 3254678Snate@binkert.org 32611401Sandreas.sandberg@arm.com# Define the universe of supported ISAs 32711401Sandreas.sandberg@arm.comenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 32811401Sandreas.sandberg@arm.com 32911401Sandreas.sandberg@arm.com# Define the universe of supported CPU models 33011401Sandreas.sandberg@arm.comenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 33111401Sandreas.sandberg@arm.com 'O3CPU', 'OzoneCPU'] 33211401Sandreas.sandberg@arm.com 33311401Sandreas.sandberg@arm.comif os.path.isdir(os.path.join(SRCDIR, 'src/encumbered/cpu/full')): 33411401Sandreas.sandberg@arm.com env['ALL_CPU_LIST'] += ['FullCPU'] 33511401Sandreas.sandberg@arm.com 33611401Sandreas.sandberg@arm.com# Sticky options get saved in the options file so they persist from 33711401Sandreas.sandberg@arm.com# one invocation to the next (unless overridden, in which case the new 33811450Sandreas.sandberg@arm.com# value becomes sticky). 33911450Sandreas.sandberg@arm.comsticky_opts = Options(args=ARGUMENTS) 34011450Sandreas.sandberg@arm.comsticky_opts.AddOptions( 34111450Sandreas.sandberg@arm.com EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 34211450Sandreas.sandberg@arm.com BoolOption('FULL_SYSTEM', 'Full-system support', False), 34311450Sandreas.sandberg@arm.com # There's a bug in scons 0.96.1 that causes ListOptions with list 34411450Sandreas.sandberg@arm.com # values (more than one value) not to be able to be restored from 34511450Sandreas.sandberg@arm.com # a saved option file. If this causes trouble then upgrade to 34611450Sandreas.sandberg@arm.com # scons 0.96.90 or later. 34711450Sandreas.sandberg@arm.com ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU,O3CPU', 34811450Sandreas.sandberg@arm.com env['ALL_CPU_LIST']), 34911401Sandreas.sandberg@arm.com BoolOption('ALPHA_TLASER', 35011450Sandreas.sandberg@arm.com 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 35111450Sandreas.sandberg@arm.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 35211450Sandreas.sandberg@arm.com BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 35311401Sandreas.sandberg@arm.com False), 35411450Sandreas.sandberg@arm.com BoolOption('SS_COMPATIBLE_FP', 35511401Sandreas.sandberg@arm.com 'Make floating-point results compatible with SimpleScalar', 3568336Ssteve.reinhardt@amd.com False), 3578336Ssteve.reinhardt@amd.com BoolOption('USE_SSE2', 3588336Ssteve.reinhardt@amd.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 3598336Ssteve.reinhardt@amd.com False), 3608336Ssteve.reinhardt@amd.com BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 3618336Ssteve.reinhardt@amd.com BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 3628336Ssteve.reinhardt@amd.com BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 3638336Ssteve.reinhardt@amd.com ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3648336Ssteve.reinhardt@amd.com ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3658336Ssteve.reinhardt@amd.com BoolOption('BATCH', 'Use batch pool for build and tests', False), 36611401Sandreas.sandberg@arm.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 36711401Sandreas.sandberg@arm.com ('PYTHONHOME', 3688336Ssteve.reinhardt@amd.com 'Override the default PYTHONHOME for this system (use with caution)', 3698336Ssteve.reinhardt@amd.com '%s:%s' % (sys.prefix, sys.exec_prefix)) 3708336Ssteve.reinhardt@amd.com ) 3715871Snate@binkert.org 37211476Sandreas.sandberg@arm.com# Non-sticky options only apply to the current build. 37311476Sandreas.sandberg@arm.comnonsticky_opts = Options(args=ARGUMENTS) 37411476Sandreas.sandberg@arm.comnonsticky_opts.AddOptions( 37511476Sandreas.sandberg@arm.com BoolOption('update_ref', 'Update test reference outputs', False) 37611476Sandreas.sandberg@arm.com ) 37711476Sandreas.sandberg@arm.com 37811476Sandreas.sandberg@arm.com# These options get exported to #defines in config/*.hh (see src/SConscript). 37911476Sandreas.sandberg@arm.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 38011476Sandreas.sandberg@arm.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 38111887Sandreas.sandberg@arm.com 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 38211887Sandreas.sandberg@arm.com 38311887Sandreas.sandberg@arm.com# Define a handy 'no-op' action 38411408Sandreas.sandberg@arm.comdef no_action(target, source, env): 38511887Sandreas.sandberg@arm.com return 0 38611887Sandreas.sandberg@arm.com 38711887Sandreas.sandberg@arm.comenv.NoAction = Action(no_action, None) 38811887Sandreas.sandberg@arm.com 38911887Sandreas.sandberg@arm.com################################################### 39011887Sandreas.sandberg@arm.com# 39111926Sgabeblack@google.com# Define a SCons builder for configuration flag headers. 39211926Sgabeblack@google.com# 39311926Sgabeblack@google.com################################################### 39411926Sgabeblack@google.com 39511887Sandreas.sandberg@arm.com# This function generates a config header file that #defines the 39611887Sandreas.sandberg@arm.com# option symbol to the current option setting (0 or 1). The source 39711944Sandreas.sandberg@arm.com# operands are the name of the option and a Value node containing the 39811887Sandreas.sandberg@arm.com# value of the option. 39911927Sgabeblack@google.comdef build_config_file(target, source, env): 40011927Sgabeblack@google.com (option, value) = [s.get_contents() for s in source] 40111927Sgabeblack@google.com f = file(str(target[0]), 'w') 40211927Sgabeblack@google.com print >> f, '#define', option, value 40311927Sgabeblack@google.com f.close() 40411927Sgabeblack@google.com return None 40511887Sandreas.sandberg@arm.com 40611928Sgabeblack@google.com# Generate the message to be printed when building the config file. 40711928Sgabeblack@google.comdef build_config_file_string(target, source, env): 40811887Sandreas.sandberg@arm.com (option, value) = [s.get_contents() for s in source] 40911887Sandreas.sandberg@arm.com return "Defining %s as %s in %s." % (option, value, target[0]) 41011887Sandreas.sandberg@arm.com 41111887Sandreas.sandberg@arm.com# Combine the two functions into a scons Action object. 41211887Sandreas.sandberg@arm.comconfig_action = Action(build_config_file, build_config_file_string) 41311887Sandreas.sandberg@arm.com 41411887Sandreas.sandberg@arm.com# The emitter munges the source & target node lists to reflect what 41511887Sandreas.sandberg@arm.com# we're really doing. 41611887Sandreas.sandberg@arm.comdef config_emitter(target, source, env): 41711887Sandreas.sandberg@arm.com # extract option name from Builder arg 41811476Sandreas.sandberg@arm.com option = str(target[0]) 41911476Sandreas.sandberg@arm.com # True target is config header file 42011408Sandreas.sandberg@arm.com target = os.path.join('config', option.lower() + '.hh') 42111408Sandreas.sandberg@arm.com val = env[option] 42211408Sandreas.sandberg@arm.com if isinstance(val, bool): 42311408Sandreas.sandberg@arm.com # Force value to 0/1 42411408Sandreas.sandberg@arm.com val = int(val) 42511408Sandreas.sandberg@arm.com elif isinstance(val, str): 42611408Sandreas.sandberg@arm.com val = '"' + val + '"' 42711887Sandreas.sandberg@arm.com 42811887Sandreas.sandberg@arm.com # Sources are option name & value (packaged in SCons Value nodes) 42911476Sandreas.sandberg@arm.com return ([target], [Value(option), Value(val)]) 43011887Sandreas.sandberg@arm.com 43111887Sandreas.sandberg@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 43211476Sandreas.sandberg@arm.com 43311476Sandreas.sandberg@arm.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 43411476Sandreas.sandberg@arm.com 43511476Sandreas.sandberg@arm.com################################################### 4366121Snate@binkert.org# 437955SN/A# Define a SCons builder for copying files. This is used by the 438955SN/A# Python zipfile code in src/python/SConscript, but is placed up here 4392632Sstever@eecs.umich.edu# since it's potentially more generally applicable. 4402632Sstever@eecs.umich.edu# 441955SN/A################################################### 442955SN/A 443955SN/Acopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 444955SN/A 4458878Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 446955SN/A 4472632Sstever@eecs.umich.edu################################################### 4482632Sstever@eecs.umich.edu# 4492632Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files. 4502632Sstever@eecs.umich.edu# 4512632Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable. 4522632Sstever@eecs.umich.edu# 4532632Sstever@eecs.umich.edu################################################### 4548268Ssteve.reinhardt@amd.com 4558268Ssteve.reinhardt@amd.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 4568268Ssteve.reinhardt@amd.com 'chmod +x $TARGET'])) 4578268Ssteve.reinhardt@amd.com 4588268Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'Concat' : concat_builder }) 4598268Ssteve.reinhardt@amd.com 4608268Ssteve.reinhardt@amd.com 4612632Sstever@eecs.umich.edu# base help text 4622632Sstever@eecs.umich.eduhelp_text = ''' 4632632Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 4642632Sstever@eecs.umich.edu 4658268Ssteve.reinhardt@amd.com''' 4662632Sstever@eecs.umich.edu 4678268Ssteve.reinhardt@amd.com# libelf build is shared across all configs in the build root. 4688268Ssteve.reinhardt@amd.comenv.SConscript('ext/libelf/SConscript', 4698268Ssteve.reinhardt@amd.com build_dir = os.path.join(build_root, 'libelf'), 4708268Ssteve.reinhardt@amd.com exports = 'env') 4713718Sstever@eecs.umich.edu 4722634Sstever@eecs.umich.edu################################################### 4732634Sstever@eecs.umich.edu# 4745863Snate@binkert.org# This function is used to set up a directory with switching headers 4752638Sstever@eecs.umich.edu# 4768268Ssteve.reinhardt@amd.com################################################### 4772632Sstever@eecs.umich.edu 4782632Sstever@eecs.umich.edudef make_switching_dir(dirname, switch_headers, env): 4792632Sstever@eecs.umich.edu # Generate the header. target[0] is the full path of the output 4802632Sstever@eecs.umich.edu # header to generate. 'source' is a dummy variable, since we get the 4812632Sstever@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 4821858SN/A def gen_switch_hdr(target, source, env): 4833716Sstever@eecs.umich.edu fname = str(target[0]) 4842638Sstever@eecs.umich.edu basename = os.path.basename(fname) 4852638Sstever@eecs.umich.edu f = open(fname, 'w') 4862638Sstever@eecs.umich.edu f.write('#include "arch/isa_specific.hh"\n') 4872638Sstever@eecs.umich.edu cond = '#if' 4882638Sstever@eecs.umich.edu for isa in env['ALL_ISA_LIST']: 4892638Sstever@eecs.umich.edu f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 4902638Sstever@eecs.umich.edu % (cond, isa.upper(), dirname, isa, basename)) 4915863Snate@binkert.org cond = '#elif' 4925863Snate@binkert.org f.write('#else\n#error "THE_ISA not set"\n#endif\n') 4935863Snate@binkert.org f.close() 494955SN/A return 0 4955341Sstever@gmail.com 4965341Sstever@gmail.com # String to print when generating header 4975863Snate@binkert.org def gen_switch_hdr_string(target, source, env): 4987756SAli.Saidi@ARM.com return "Generating switch header " + str(target[0]) 4995341Sstever@gmail.com 5006121Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 5014494Ssaidi@eecs.umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 5026121Snate@binkert.org # should get re-executed. 5031105SN/A switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 5042667Sstever@eecs.umich.edu varlist=['ALL_ISA_LIST']) 5052667Sstever@eecs.umich.edu 5062667Sstever@eecs.umich.edu # Instantiate actions for each header 5072667Sstever@eecs.umich.edu for hdr in switch_headers: 5086121Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 5092667Sstever@eecs.umich.edu 5105341Sstever@gmail.comenv.make_switching_dir = make_switching_dir 5115863Snate@binkert.org 5125341Sstever@gmail.com################################################### 5135341Sstever@gmail.com# 5145341Sstever@gmail.com# Define build environments for selected configurations. 5158120Sgblack@eecs.umich.edu# 5165341Sstever@gmail.com################################################### 5178120Sgblack@eecs.umich.edu 5185341Sstever@gmail.com# rename base env 5198120Sgblack@eecs.umich.edubase_env = env 5206121Snate@binkert.org 5216121Snate@binkert.orgfor build_path in build_paths: 5229396Sandreas.hansson@arm.com print "Building in", build_path 5235397Ssaidi@eecs.umich.edu # build_dir is the tail component of build path, and is used to 5245397Ssaidi@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 5257727SAli.Saidi@ARM.com (build_root, build_dir) = os.path.split(build_path) 5268268Ssteve.reinhardt@amd.com # Make a copy of the build-root environment to use for this config. 5276168Snate@binkert.org env = base_env.Copy() 5285341Sstever@gmail.com 5298120Sgblack@eecs.umich.edu # Set env options according to the build directory config. 5308120Sgblack@eecs.umich.edu sticky_opts.files = [] 5318120Sgblack@eecs.umich.edu # Options for $BUILD_ROOT/$BUILD_DIR are stored in 5326814Sgblack@eecs.umich.edu # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 5335863Snate@binkert.org # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 5348120Sgblack@eecs.umich.edu current_opts_file = os.path.join(build_root, 'options', build_dir) 5355341Sstever@gmail.com if os.path.isfile(current_opts_file): 5365863Snate@binkert.org sticky_opts.files.append(current_opts_file) 5378268Ssteve.reinhardt@amd.com print "Using saved options file %s" % current_opts_file 5386121Snate@binkert.org else: 5396121Snate@binkert.org # Build dir-specific options file doesn't exist. 5408268Ssteve.reinhardt@amd.com 5415742Snate@binkert.org # Make sure the directory is there so we can create it later 5425742Snate@binkert.org opt_dir = os.path.dirname(current_opts_file) 5435341Sstever@gmail.com if not os.path.isdir(opt_dir): 5445742Snate@binkert.org os.mkdir(opt_dir) 5455742Snate@binkert.org 5465341Sstever@gmail.com # Get default build options from source tree. Options are 5476017Snate@binkert.org # normally determined by name of $BUILD_DIR, but can be 5486121Snate@binkert.org # overriden by 'default=' arg on command line. 5496017Snate@binkert.org default_opts_file = os.path.join('build_opts', 5507816Ssteve.reinhardt@amd.com ARGUMENTS.get('default', build_dir)) 5517756SAli.Saidi@ARM.com if os.path.isfile(default_opts_file): 5527756SAli.Saidi@ARM.com sticky_opts.files.append(default_opts_file) 5537756SAli.Saidi@ARM.com print "Options file %s not found,\n using defaults in %s" \ 5547756SAli.Saidi@ARM.com % (current_opts_file, default_opts_file) 5557756SAli.Saidi@ARM.com else: 5567756SAli.Saidi@ARM.com print "Error: cannot find options file %s or %s" \ 5577756SAli.Saidi@ARM.com % (current_opts_file, default_opts_file) 5587756SAli.Saidi@ARM.com Exit(1) 5597816Ssteve.reinhardt@amd.com 5607816Ssteve.reinhardt@amd.com # Apply current option settings to env 5617816Ssteve.reinhardt@amd.com sticky_opts.Update(env) 5627816Ssteve.reinhardt@amd.com nonsticky_opts.Update(env) 5637816Ssteve.reinhardt@amd.com 5647816Ssteve.reinhardt@amd.com help_text += "Sticky options for %s:\n" % build_dir \ 5657816Ssteve.reinhardt@amd.com + sticky_opts.GenerateHelpText(env) \ 5667816Ssteve.reinhardt@amd.com + "\nNon-sticky options for %s:\n" % build_dir \ 5677816Ssteve.reinhardt@amd.com + nonsticky_opts.GenerateHelpText(env) 5687816Ssteve.reinhardt@amd.com 5697756SAli.Saidi@ARM.com # Process option settings. 5707816Ssteve.reinhardt@amd.com 5717816Ssteve.reinhardt@amd.com if not have_fenv and env['USE_FENV']: 5727816Ssteve.reinhardt@amd.com print "Warning: <fenv.h> not available; " \ 5737816Ssteve.reinhardt@amd.com "forcing USE_FENV to False in", build_dir + "." 5747816Ssteve.reinhardt@amd.com env['USE_FENV'] = False 5757816Ssteve.reinhardt@amd.com 5767816Ssteve.reinhardt@amd.com if not env['USE_FENV']: 5777816Ssteve.reinhardt@amd.com print "Warning: No IEEE FP rounding mode control in", build_dir + "." 5787816Ssteve.reinhardt@amd.com print " FP results may deviate slightly from other platforms." 5797816Ssteve.reinhardt@amd.com 5807816Ssteve.reinhardt@amd.com if env['EFENCE']: 5817816Ssteve.reinhardt@amd.com env.Append(LIBS=['efence']) 5827816Ssteve.reinhardt@amd.com 5837816Ssteve.reinhardt@amd.com if env['USE_MYSQL']: 5847816Ssteve.reinhardt@amd.com if not have_mysql: 5857816Ssteve.reinhardt@amd.com print "Warning: MySQL not available; " \ 5867816Ssteve.reinhardt@amd.com "forcing USE_MYSQL to False in", build_dir + "." 5877816Ssteve.reinhardt@amd.com env['USE_MYSQL'] = False 5887816Ssteve.reinhardt@amd.com else: 5897816Ssteve.reinhardt@amd.com print "Compiling in", build_dir, "with MySQL support." 5907816Ssteve.reinhardt@amd.com env.ParseConfig(mysql_config_libs) 5917816Ssteve.reinhardt@amd.com env.ParseConfig(mysql_config_include) 5927816Ssteve.reinhardt@amd.com 5937816Ssteve.reinhardt@amd.com # Save sticky option settings back to current options file 5947816Ssteve.reinhardt@amd.com sticky_opts.Save(current_opts_file, env) 5957816Ssteve.reinhardt@amd.com 5967816Ssteve.reinhardt@amd.com # Do this after we save setting back, or else we'll tack on an 5977816Ssteve.reinhardt@amd.com # extra 'qdo' every time we run scons. 5987816Ssteve.reinhardt@amd.com if env['BATCH']: 5997816Ssteve.reinhardt@amd.com env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 6007816Ssteve.reinhardt@amd.com env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 6017816Ssteve.reinhardt@amd.com 6027816Ssteve.reinhardt@amd.com if env['USE_SSE2']: 6037816Ssteve.reinhardt@amd.com env.Append(CCFLAGS='-msse2') 6047816Ssteve.reinhardt@amd.com 6057816Ssteve.reinhardt@amd.com # The src/SConscript file sets up the build rules in 'env' according 6067816Ssteve.reinhardt@amd.com # to the configured options. It returns a list of environments, 6077816Ssteve.reinhardt@amd.com # one for each variant build (debug, opt, etc.) 6087816Ssteve.reinhardt@amd.com envList = SConscript('src/SConscript', build_dir = build_path, 6097816Ssteve.reinhardt@amd.com exports = 'env') 6107816Ssteve.reinhardt@amd.com 6117816Ssteve.reinhardt@amd.com # Set up the regression tests for each build. 6127816Ssteve.reinhardt@amd.com for e in envList: 6137816Ssteve.reinhardt@amd.com SConscript('tests/SConscript', 6147816Ssteve.reinhardt@amd.com build_dir = os.path.join(build_path, 'tests', e.Label), 6157816Ssteve.reinhardt@amd.com exports = { 'env' : e }, duplicate = False) 6167816Ssteve.reinhardt@amd.com 6177816Ssteve.reinhardt@amd.comHelp(help_text) 6187816Ssteve.reinhardt@amd.com 6197816Ssteve.reinhardt@amd.com 6207816Ssteve.reinhardt@amd.com################################################### 6217816Ssteve.reinhardt@amd.com# 6227816Ssteve.reinhardt@amd.com# Let SCons do its thing. At this point SCons will use the defined 6237816Ssteve.reinhardt@amd.com# build environments to build the requested targets. 6247816Ssteve.reinhardt@amd.com# 6257816Ssteve.reinhardt@amd.com################################################### 6267816Ssteve.reinhardt@amd.com 6277816Ssteve.reinhardt@amd.com