SConstruct revision 3718
1955SN/A# -*- mode:python -*- 2955SN/A 37816Ssteve.reinhardt@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 45871Snate@binkert.org# All rights reserved. 51762SN/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. 28955SN/A# 29955SN/A# Authors: Steve Reinhardt 302665Ssaidi@eecs.umich.edu 312665Ssaidi@eecs.umich.edu################################################### 325863Snate@binkert.org# 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 382632Sstever@eecs.umich.edu# the optimized full-system version). 392632Sstever@eecs.umich.edu# 402632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 42955SN/A# expects that all configs under the same build directory are being 432632Sstever@eecs.umich.edu# built for the same host system. 442632Sstever@eecs.umich.edu# 452761Sstever@eecs.umich.edu# Examples: 462632Sstever@eecs.umich.edu# 472632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 482632Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 492761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 502761Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512761Sstever@eecs.umich.edu# 522632Sstever@eecs.umich.edu# 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 542761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 552761Sstever@eecs.umich.edu# file. 562761Sstever@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 582761Sstever@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 612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 622632Sstever@eecs.umich.edu# options as well. 632632Sstever@eecs.umich.edu# 642632Sstever@eecs.umich.edu################################################### 652632Sstever@eecs.umich.edu 66955SN/A# Python library imports 67955SN/Aimport sys 68955SN/Aimport os 695863Snate@binkert.orgfrom os.path import join as joinpath 705863Snate@binkert.org 715863Snate@binkert.org# Check for recent-enough Python and SCons versions. If your system's 725863Snate@binkert.org# default installation of Python is not recent enough, you can use a 735863Snate@binkert.org# non-default installation of the Python interpreter by either (1) 745863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python' 755863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the 765863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 775863Snate@binkert.orgEnsurePythonVersion(2,4) 785863Snate@binkert.org 795863Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 805863Snate@binkert.org# 3-element version number. 815863Snate@binkert.orgmin_scons_version = (0,96,91) 825863Snate@binkert.orgtry: 835863Snate@binkert.org EnsureSConsVersion(*min_scons_version) 845863Snate@binkert.orgexcept: 855863Snate@binkert.org print "Error checking current SCons version." 865863Snate@binkert.org print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 875863Snate@binkert.org Exit(2) 885863Snate@binkert.org 895863Snate@binkert.org 905863Snate@binkert.org# The absolute path to the current directory (where this file lives). 915863Snate@binkert.orgROOT = Dir('.').abspath 925863Snate@binkert.org 935863Snate@binkert.org# Path to the M5 source tree. 945863Snate@binkert.orgSRCDIR = joinpath(ROOT, 'src') 955863Snate@binkert.org 965863Snate@binkert.org# tell python where to find m5 python code 975863Snate@binkert.orgsys.path.append(joinpath(ROOT, 'src/python')) 985863Snate@binkert.org 995863Snate@binkert.org################################################### 1006654Snate@binkert.org# 101955SN/A# Figure out which configurations to set up based on the path(s) of 1025396Ssaidi@eecs.umich.edu# the target(s). 1035863Snate@binkert.org# 1045863Snate@binkert.org################################################### 1054202Sbinkertn@umich.edu 1065863Snate@binkert.org# Find default configuration & binary. 1075863Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1085863Snate@binkert.org 1095863Snate@binkert.org# helper function: find last occurrence of element in list 110955SN/Adef rfind(l, elt, offs = -1): 1116654Snate@binkert.org for i in range(len(l)+offs, 0, -1): 1125273Sstever@gmail.com if l[i] == elt: 1135871Snate@binkert.org return i 1145273Sstever@gmail.com raise ValueError, "element not found" 1156655Snate@binkert.org 1166655Snate@binkert.org# helper function: compare dotted version numbers. 1176655Snate@binkert.org# E.g., compare_version('1.3.25', '1.4.1') 1186655Snate@binkert.org# returns -1, 0, 1 if v1 is <, ==, > v2 1196655Snate@binkert.orgdef compare_versions(v1, v2): 1206655Snate@binkert.org # Convert dotted strings to lists 1215871Snate@binkert.org v1 = map(int, v1.split('.')) 1226654Snate@binkert.org v2 = map(int, v2.split('.')) 1235396Ssaidi@eecs.umich.edu # Compare corresponding elements of lists 1247816Ssteve.reinhardt@amd.com for n1,n2 in zip(v1, v2): 1257816Ssteve.reinhardt@amd.com if n1 < n2: return -1 1267816Ssteve.reinhardt@amd.com if n1 > n2: return 1 1277816Ssteve.reinhardt@amd.com # all corresponding values are equal... see if one has extra values 1287816Ssteve.reinhardt@amd.com if len(v1) < len(v2): return -1 1297816Ssteve.reinhardt@amd.com if len(v1) > len(v2): return 1 1307816Ssteve.reinhardt@amd.com return 0 1317816Ssteve.reinhardt@amd.com 1327816Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the 1337816Ssteve.reinhardt@amd.com# directory below this will determine the build parameters. For 1347816Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1357816Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it 1365871Snate@binkert.org# follow 'build' in the bulid path. 1375871Snate@binkert.org 1386121Snate@binkert.org# Generate absolute paths to targets so we can see where the build dir is 1395871Snate@binkert.orgif COMMAND_LINE_TARGETS: 1405871Snate@binkert.org # Ask SCons which directory it was invoked from 1416003Snate@binkert.org launch_dir = GetLaunchDir() 1426655Snate@binkert.org # Make targets relative to invocation directory 143955SN/A abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 1445871Snate@binkert.org COMMAND_LINE_TARGETS) 1455871Snate@binkert.orgelse: 1465871Snate@binkert.org # Default targets are relative to root of tree 1475871Snate@binkert.org abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 148955SN/A DEFAULT_TARGETS) 1496121Snate@binkert.org 1506121Snate@binkert.org 1516121Snate@binkert.org# Generate a list of the unique build roots and configs that the 1521533SN/A# collected targets reference. 1536655Snate@binkert.orgbuild_paths = [] 1546655Snate@binkert.orgbuild_root = None 1556655Snate@binkert.orgfor t in abs_targets: 1566655Snate@binkert.org path_dirs = t.split('/') 1575871Snate@binkert.org try: 1585871Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 1595863Snate@binkert.org except: 1605871Snate@binkert.org print "Error: no non-leaf 'build' dir found on target path", t 1615871Snate@binkert.org Exit(1) 1625871Snate@binkert.org this_build_root = joinpath('/',*path_dirs[:build_top+1]) 1635871Snate@binkert.org if not build_root: 1645871Snate@binkert.org build_root = this_build_root 1655863Snate@binkert.org else: 1666121Snate@binkert.org if this_build_root != build_root: 1675863Snate@binkert.org print "Error: build targets not under same build root\n"\ 1685871Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 1694678Snate@binkert.org Exit(1) 1704678Snate@binkert.org build_path = joinpath('/',*path_dirs[:build_top+2]) 1714678Snate@binkert.org if build_path not in build_paths: 1724678Snate@binkert.org build_paths.append(build_path) 1734678Snate@binkert.org 1744678Snate@binkert.org################################################### 1754678Snate@binkert.org# 1764678Snate@binkert.org# Set up the default build environment. This environment is copied 1774678Snate@binkert.org# and modified according to each selected configuration. 1784678Snate@binkert.org# 1794678Snate@binkert.org################################################### 1807827Snate@binkert.org 1817827Snate@binkert.orgenv = Environment(ENV = os.environ, # inherit user's environment vars 1826121Snate@binkert.org ROOT = ROOT, 1834678Snate@binkert.org SRCDIR = SRCDIR) 1845871Snate@binkert.org 1855871Snate@binkert.org#Parse CC/CXX early so that we use the correct compiler for 1865871Snate@binkert.org# to test for dependencies/versions/libraries/includes 1875871Snate@binkert.orgif ARGUMENTS.get('CC', None): 1885871Snate@binkert.org env['CC'] = ARGUMENTS.get('CC') 1895871Snate@binkert.org 1905871Snate@binkert.orgif ARGUMENTS.get('CXX', None): 1915871Snate@binkert.org env['CXX'] = ARGUMENTS.get('CXX') 1925871Snate@binkert.org 1935871Snate@binkert.orgenv.SConsignFile(joinpath(build_root,"sconsign")) 1945871Snate@binkert.org 1955871Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 1965871Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 1975990Ssaidi@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 1985871Snate@binkert.org# (soft) links work better. 1995871Snate@binkert.orgenv.SetOption('duplicate', 'soft-copy') 2005871Snate@binkert.org 2014678Snate@binkert.org# I waffle on this setting... it does avoid a few painful but 2026654Snate@binkert.org# unnecessary builds, but it also seems to make trivial builds take 2035871Snate@binkert.org# noticeably longer. 2045871Snate@binkert.orgif False: 2055871Snate@binkert.org env.TargetSignatures('content') 2065871Snate@binkert.org 2075871Snate@binkert.org# M5_PLY is used by isa_parser.py to find the PLY package. 2085871Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 2095871Snate@binkert.org 2105871Snate@binkert.org# Set up default C++ compiler flags 2115871Snate@binkert.orgenv.Append(CCFLAGS='-pipe') 2124678Snate@binkert.orgenv.Append(CCFLAGS='-fno-strict-aliasing') 2135871Snate@binkert.orgenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2144678Snate@binkert.orgif sys.platform == 'cygwin': 2155871Snate@binkert.org # cygwin has some header file issues... 2165871Snate@binkert.org env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2175871Snate@binkert.orgenv.Append(CPPPATH=[Dir('ext/dnet')]) 2185871Snate@binkert.org 2195871Snate@binkert.org# Check for SWIG 2205871Snate@binkert.orgif not env.has_key('SWIG'): 2215871Snate@binkert.org print 'Error: SWIG utility not found.' 2225871Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 2235871Snate@binkert.org Exit(1) 2246121Snate@binkert.org 2256121Snate@binkert.org# Check for appropriate SWIG version 2265863Snate@binkert.orgswig_version = os.popen('swig -version').read().split() 227955SN/A# First 3 words should be "SWIG Version x.y.z" 228955SN/Aif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2292632Sstever@eecs.umich.edu print 'Error determining SWIG version.' 2302632Sstever@eecs.umich.edu Exit(1) 231955SN/A 232955SN/Amin_swig_version = '1.3.28' 233955SN/Aif compare_versions(swig_version[2], min_swig_version) < 0: 234955SN/A print 'Error: SWIG version', min_swig_version, 'or newer required.' 2355863Snate@binkert.org print ' Installed version:', swig_version[2] 236955SN/A Exit(1) 2372632Sstever@eecs.umich.edu 2382632Sstever@eecs.umich.edu# Set up SWIG flags & scanner 2392632Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2402632Sstever@eecs.umich.edu 2412632Sstever@eecs.umich.eduimport SCons.Scanner 2422632Sstever@eecs.umich.edu 2432632Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2442632Sstever@eecs.umich.edu 2452632Sstever@eecs.umich.eduswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2462632Sstever@eecs.umich.edu swig_inc_re) 2472632Sstever@eecs.umich.edu 2482632Sstever@eecs.umich.eduenv.Append(SCANNERS = swig_scanner) 2492632Sstever@eecs.umich.edu 2503718Sstever@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 2513718Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 2523718Sstever@eecs.umich.educonf = Configure(env, 2533718Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 2543718Sstever@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log')) 2555863Snate@binkert.org 2565863Snate@binkert.org# Find Python include and library directories for embedding the 2573718Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 2583718Sstever@eecs.umich.edu# installation used to run scons (and thus this script). If you want 2596121Snate@binkert.org# to link in an alternate version, see above for instructions on how 2605863Snate@binkert.org# to invoke scons with a different copy of the Python interpreter. 2613718Sstever@eecs.umich.edu 2623718Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating 2632634Sstever@eecs.umich.edu# include & library files 2642634Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3] 2655863Snate@binkert.org 2662638Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4 2672632Sstever@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 2682632Sstever@eecs.umich.eduenv.Append(CPPPATH = py_header_path) 2692632Sstever@eecs.umich.edu# verify that it works 2702632Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 2712632Sstever@eecs.umich.edu print "Error: can't find Python.h header in", py_header_path 2722632Sstever@eecs.umich.edu Exit(1) 2731858SN/A 2743716Sstever@eecs.umich.edu# add library path too if it's not in the default place 2752638Sstever@eecs.umich.edupy_lib_path = None 2762638Sstever@eecs.umich.eduif sys.exec_prefix != '/usr': 2772638Sstever@eecs.umich.edu py_lib_path = joinpath(sys.exec_prefix, 'lib') 2782638Sstever@eecs.umich.eduelif sys.platform == 'cygwin': 2792638Sstever@eecs.umich.edu # cygwin puts the .dll in /bin for some reason 2802638Sstever@eecs.umich.edu py_lib_path = '/bin' 2812638Sstever@eecs.umich.eduif py_lib_path: 2825863Snate@binkert.org env.Append(LIBPATH = py_lib_path) 2835863Snate@binkert.org print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 2845863Snate@binkert.orgif not conf.CheckLib(py_version_name): 285955SN/A print "Error: can't find Python library", py_version_name 2865341Sstever@gmail.com Exit(1) 2875341Sstever@gmail.com 2885863Snate@binkert.org# On Solaris you need to use libsocket for socket ops 2897756SAli.Saidi@ARM.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2905341Sstever@gmail.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2916121Snate@binkert.org print "Can't find library with socket calls (e.g. accept())" 2924494Ssaidi@eecs.umich.edu Exit(1) 2936121Snate@binkert.org 2941105SN/A# Check for zlib. If the check passes, libz will be automatically 2952667Sstever@eecs.umich.edu# added to the LIBS environment variable. 2962667Sstever@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 2972667Sstever@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 2982667Sstever@eecs.umich.edu 'and/or zlib.h header file.' 2996121Snate@binkert.org print ' Please install zlib and try again.' 3002667Sstever@eecs.umich.edu Exit(1) 3015341Sstever@gmail.com 3025863Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 3035341Sstever@gmail.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 3045341Sstever@gmail.comif not have_fenv: 3055341Sstever@gmail.com print "Warning: Header file <fenv.h> not found." 3065863Snate@binkert.org print " This host has no IEEE FP rounding mode control." 3075341Sstever@gmail.com 3085341Sstever@gmail.com# Check for mysql. 3095341Sstever@gmail.commysql_config = WhereIs('mysql_config') 3105863Snate@binkert.orghave_mysql = mysql_config != None 3115341Sstever@gmail.com 3125341Sstever@gmail.com# Check MySQL version. 3135341Sstever@gmail.comif have_mysql: 3145341Sstever@gmail.com mysql_version = os.popen(mysql_config + ' --version').read() 3155341Sstever@gmail.com min_mysql_version = '4.1' 3165341Sstever@gmail.com if compare_versions(mysql_version, min_mysql_version) < 0: 3175341Sstever@gmail.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3185341Sstever@gmail.com print ' Version', mysql_version, 'detected.' 3195341Sstever@gmail.com have_mysql = False 3205341Sstever@gmail.com 3215863Snate@binkert.org# Set up mysql_config commands. 3225341Sstever@gmail.comif have_mysql: 3235863Snate@binkert.org mysql_config_include = mysql_config + ' --include' 3247756SAli.Saidi@ARM.com if os.system(mysql_config_include + ' > /dev/null') != 0: 3255341Sstever@gmail.com # older mysql_config versions don't support --include, use 3265863Snate@binkert.org # --cflags instead 3276121Snate@binkert.org mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 3286121Snate@binkert.org # This seems to work in all versions 3295397Ssaidi@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 3305397Ssaidi@eecs.umich.edu 3317727SAli.Saidi@ARM.comenv = conf.Finish() 3325341Sstever@gmail.com 3336168Snate@binkert.org# Define the universe of supported ISAs 3346168Snate@binkert.orgenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 3355341Sstever@gmail.com 3367756SAli.Saidi@ARM.com# Define the universe of supported CPU models 3377756SAli.Saidi@ARM.comenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 3387756SAli.Saidi@ARM.com 'O3CPU', 'OzoneCPU'] 3397756SAli.Saidi@ARM.com 3407756SAli.Saidi@ARM.comif os.path.isdir(joinpath(SRCDIR, 'encumbered/cpu/full')): 3417756SAli.Saidi@ARM.com env['ALL_CPU_LIST'] += ['FullCPU'] 3425341Sstever@gmail.com 3435341Sstever@gmail.com# Sticky options get saved in the options file so they persist from 3445341Sstever@gmail.com# one invocation to the next (unless overridden, in which case the new 3455341Sstever@gmail.com# value becomes sticky). 3465863Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS) 3475341Sstever@gmail.comsticky_opts.AddOptions( 3485341Sstever@gmail.com EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 3496121Snate@binkert.org BoolOption('FULL_SYSTEM', 'Full-system support', False), 3506121Snate@binkert.org # There's a bug in scons 0.96.1 that causes ListOptions with list 3517756SAli.Saidi@ARM.com # values (more than one value) not to be able to be restored from 3525341Sstever@gmail.com # a saved option file. If this causes trouble then upgrade to 3536814Sgblack@eecs.umich.edu # scons 0.96.90 or later. 3547756SAli.Saidi@ARM.com ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU,O3CPU', 3556814Sgblack@eecs.umich.edu env['ALL_CPU_LIST']), 3565863Snate@binkert.org BoolOption('ALPHA_TLASER', 3576121Snate@binkert.org 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 3585341Sstever@gmail.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 3595863Snate@binkert.org BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 3605341Sstever@gmail.com False), 3616121Snate@binkert.org BoolOption('SS_COMPATIBLE_FP', 3626121Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 3636121Snate@binkert.org False), 3645742Snate@binkert.org BoolOption('USE_SSE2', 3655742Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 3665341Sstever@gmail.com False), 3675742Snate@binkert.org BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 3685742Snate@binkert.org BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 3695341Sstever@gmail.com BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 3706017Snate@binkert.org ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3716121Snate@binkert.org ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3726017Snate@binkert.org BoolOption('BATCH', 'Use batch pool for build and tests', False), 3737816Ssteve.reinhardt@amd.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3747756SAli.Saidi@ARM.com ('PYTHONHOME', 3757756SAli.Saidi@ARM.com 'Override the default PYTHONHOME for this system (use with caution)', 3767756SAli.Saidi@ARM.com '%s:%s' % (sys.prefix, sys.exec_prefix)) 3777756SAli.Saidi@ARM.com ) 3787756SAli.Saidi@ARM.com 3797756SAli.Saidi@ARM.com# Non-sticky options only apply to the current build. 3807756SAli.Saidi@ARM.comnonsticky_opts = Options(args=ARGUMENTS) 3817756SAli.Saidi@ARM.comnonsticky_opts.AddOptions( 3827816Ssteve.reinhardt@amd.com BoolOption('update_ref', 'Update test reference outputs', False) 3837816Ssteve.reinhardt@amd.com ) 3847816Ssteve.reinhardt@amd.com 3857816Ssteve.reinhardt@amd.com# These options get exported to #defines in config/*.hh (see src/SConscript). 3867816Ssteve.reinhardt@amd.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 3877816Ssteve.reinhardt@amd.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 3887816Ssteve.reinhardt@amd.com 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 3897816Ssteve.reinhardt@amd.com 3907816Ssteve.reinhardt@amd.com# Define a handy 'no-op' action 3917816Ssteve.reinhardt@amd.comdef no_action(target, source, env): 3927756SAli.Saidi@ARM.com return 0 3937816Ssteve.reinhardt@amd.com 3947816Ssteve.reinhardt@amd.comenv.NoAction = Action(no_action, None) 3957816Ssteve.reinhardt@amd.com 3967816Ssteve.reinhardt@amd.com################################################### 3977816Ssteve.reinhardt@amd.com# 3987816Ssteve.reinhardt@amd.com# Define a SCons builder for configuration flag headers. 3997816Ssteve.reinhardt@amd.com# 4007816Ssteve.reinhardt@amd.com################################################### 4017816Ssteve.reinhardt@amd.com 4027816Ssteve.reinhardt@amd.com# This function generates a config header file that #defines the 4037816Ssteve.reinhardt@amd.com# option symbol to the current option setting (0 or 1). The source 4047816Ssteve.reinhardt@amd.com# operands are the name of the option and a Value node containing the 4057816Ssteve.reinhardt@amd.com# value of the option. 4067816Ssteve.reinhardt@amd.comdef build_config_file(target, source, env): 4077816Ssteve.reinhardt@amd.com (option, value) = [s.get_contents() for s in source] 4087816Ssteve.reinhardt@amd.com f = file(str(target[0]), 'w') 4097816Ssteve.reinhardt@amd.com print >> f, '#define', option, value 4107816Ssteve.reinhardt@amd.com f.close() 4117816Ssteve.reinhardt@amd.com return None 4127816Ssteve.reinhardt@amd.com 4137816Ssteve.reinhardt@amd.com# Generate the message to be printed when building the config file. 4147816Ssteve.reinhardt@amd.comdef build_config_file_string(target, source, env): 4157816Ssteve.reinhardt@amd.com (option, value) = [s.get_contents() for s in source] 4167816Ssteve.reinhardt@amd.com return "Defining %s as %s in %s." % (option, value, target[0]) 4177816Ssteve.reinhardt@amd.com 4187816Ssteve.reinhardt@amd.com# Combine the two functions into a scons Action object. 4197816Ssteve.reinhardt@amd.comconfig_action = Action(build_config_file, build_config_file_string) 4207816Ssteve.reinhardt@amd.com 4217816Ssteve.reinhardt@amd.com# The emitter munges the source & target node lists to reflect what 4227816Ssteve.reinhardt@amd.com# we're really doing. 4237816Ssteve.reinhardt@amd.comdef config_emitter(target, source, env): 4247816Ssteve.reinhardt@amd.com # extract option name from Builder arg 4257816Ssteve.reinhardt@amd.com option = str(target[0]) 4267816Ssteve.reinhardt@amd.com # True target is config header file 4277816Ssteve.reinhardt@amd.com target = joinpath('config', option.lower() + '.hh') 4287816Ssteve.reinhardt@amd.com val = env[option] 4297816Ssteve.reinhardt@amd.com if isinstance(val, bool): 4307816Ssteve.reinhardt@amd.com # Force value to 0/1 4317816Ssteve.reinhardt@amd.com val = int(val) 4327816Ssteve.reinhardt@amd.com elif isinstance(val, str): 4337816Ssteve.reinhardt@amd.com val = '"' + val + '"' 4347816Ssteve.reinhardt@amd.com 4357816Ssteve.reinhardt@amd.com # Sources are option name & value (packaged in SCons Value nodes) 4367816Ssteve.reinhardt@amd.com return ([target], [Value(option), Value(val)]) 4377816Ssteve.reinhardt@amd.com 4387816Ssteve.reinhardt@amd.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 4397816Ssteve.reinhardt@amd.com 4407816Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 4417816Ssteve.reinhardt@amd.com 4427816Ssteve.reinhardt@amd.com################################################### 4437816Ssteve.reinhardt@amd.com# 4447816Ssteve.reinhardt@amd.com# Define a SCons builder for copying files. This is used by the 4457816Ssteve.reinhardt@amd.com# Python zipfile code in src/python/SConscript, but is placed up here 4467816Ssteve.reinhardt@amd.com# since it's potentially more generally applicable. 4477816Ssteve.reinhardt@amd.com# 4487816Ssteve.reinhardt@amd.com################################################### 4497816Ssteve.reinhardt@amd.com 4507816Ssteve.reinhardt@amd.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 4517816Ssteve.reinhardt@amd.com 4527816Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 4537816Ssteve.reinhardt@amd.com 4547756SAli.Saidi@ARM.com################################################### 4557756SAli.Saidi@ARM.com# 4567756SAli.Saidi@ARM.com# Define a simple SCons builder to concatenate files. 4577756SAli.Saidi@ARM.com# 4587756SAli.Saidi@ARM.com# Used to append the Python zip archive to the executable. 4597756SAli.Saidi@ARM.com# 4607816Ssteve.reinhardt@amd.com################################################### 4617816Ssteve.reinhardt@amd.com 4627816Ssteve.reinhardt@amd.comconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 4637816Ssteve.reinhardt@amd.com 'chmod +x $TARGET'])) 4647816Ssteve.reinhardt@amd.com 4657816Ssteve.reinhardt@amd.comenv.Append(BUILDERS = { 'Concat' : concat_builder }) 4667816Ssteve.reinhardt@amd.com 4677816Ssteve.reinhardt@amd.com 4687816Ssteve.reinhardt@amd.com# base help text 4697816Ssteve.reinhardt@amd.comhelp_text = ''' 4707756SAli.Saidi@ARM.comUsage: scons [scons options] [build options] [target(s)] 4717756SAli.Saidi@ARM.com 4726654Snate@binkert.org''' 4736654Snate@binkert.org 4745871Snate@binkert.org# libelf build is shared across all configs in the build root. 4756121Snate@binkert.orgenv.SConscript('ext/libelf/SConscript', 4766121Snate@binkert.org build_dir = joinpath(build_root, 'libelf'), 4776121Snate@binkert.org exports = 'env') 4786121Snate@binkert.org 4793940Ssaidi@eecs.umich.edu################################################### 4803918Ssaidi@eecs.umich.edu# 4813918Ssaidi@eecs.umich.edu# This function is used to set up a directory with switching headers 4821858SN/A# 4836121Snate@binkert.org################################################### 4847739Sgblack@eecs.umich.edu 4857739Sgblack@eecs.umich.edudef make_switching_dir(dirname, switch_headers, env): 4866143Snate@binkert.org # Generate the header. target[0] is the full path of the output 4877739Sgblack@eecs.umich.edu # header to generate. 'source' is a dummy variable, since we get the 4887618SAli.Saidi@arm.com # list of ISAs from env['ALL_ISA_LIST']. 4897618SAli.Saidi@arm.com def gen_switch_hdr(target, source, env): 4907618SAli.Saidi@arm.com fname = str(target[0]) 4917618SAli.Saidi@arm.com basename = os.path.basename(fname) 4927618SAli.Saidi@arm.com f = open(fname, 'w') 4937618SAli.Saidi@arm.com f.write('#include "arch/isa_specific.hh"\n') 4947618SAli.Saidi@arm.com cond = '#if' 4957739Sgblack@eecs.umich.edu for isa in env['ALL_ISA_LIST']: 4966121Snate@binkert.org f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 4973940Ssaidi@eecs.umich.edu % (cond, isa.upper(), dirname, isa, basename)) 4986121Snate@binkert.org cond = '#elif' 4997739Sgblack@eecs.umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 5007739Sgblack@eecs.umich.edu f.close() 5017739Sgblack@eecs.umich.edu return 0 5027739Sgblack@eecs.umich.edu 5037739Sgblack@eecs.umich.edu # String to print when generating header 5047739Sgblack@eecs.umich.edu def gen_switch_hdr_string(target, source, env): 5053918Ssaidi@eecs.umich.edu return "Generating switch header " + str(target[0]) 5063918Ssaidi@eecs.umich.edu 5073940Ssaidi@eecs.umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 5083918Ssaidi@eecs.umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 5093918Ssaidi@eecs.umich.edu # should get re-executed. 5106157Snate@binkert.org switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 5116157Snate@binkert.org varlist=['ALL_ISA_LIST']) 5126157Snate@binkert.org 5136157Snate@binkert.org # Instantiate actions for each header 5145397Ssaidi@eecs.umich.edu for hdr in switch_headers: 5155397Ssaidi@eecs.umich.edu env.Command(hdr, [], switch_hdr_action) 5166121Snate@binkert.org 5176121Snate@binkert.orgenv.make_switching_dir = make_switching_dir 5186121Snate@binkert.org 5196121Snate@binkert.org################################################### 5206121Snate@binkert.org# 5216121Snate@binkert.org# Define build environments for selected configurations. 5225397Ssaidi@eecs.umich.edu# 5231851SN/A################################################### 5241851SN/A 5257739Sgblack@eecs.umich.edu# rename base env 526955SN/Abase_env = env 5273053Sstever@eecs.umich.edu 5286121Snate@binkert.orgfor build_path in build_paths: 5293053Sstever@eecs.umich.edu print "Building in", build_path 5303053Sstever@eecs.umich.edu # build_dir is the tail component of build path, and is used to 5313053Sstever@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 5323053Sstever@eecs.umich.edu (build_root, build_dir) = os.path.split(build_path) 5333053Sstever@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 5346654Snate@binkert.org env = base_env.Copy() 5353053Sstever@eecs.umich.edu 5364742Sstever@eecs.umich.edu # Set env options according to the build directory config. 5374742Sstever@eecs.umich.edu sticky_opts.files = [] 5383053Sstever@eecs.umich.edu # Options for $BUILD_ROOT/$BUILD_DIR are stored in 5393053Sstever@eecs.umich.edu # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 5403053Sstever@eecs.umich.edu # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 5413053Sstever@eecs.umich.edu current_opts_file = joinpath(build_root, 'options', build_dir) 5426654Snate@binkert.org if os.path.isfile(current_opts_file): 5433053Sstever@eecs.umich.edu sticky_opts.files.append(current_opts_file) 5443053Sstever@eecs.umich.edu print "Using saved options file %s" % current_opts_file 5453053Sstever@eecs.umich.edu else: 5463053Sstever@eecs.umich.edu # Build dir-specific options file doesn't exist. 5472667Sstever@eecs.umich.edu 5484554Sbinkertn@umich.edu # Make sure the directory is there so we can create it later 5496121Snate@binkert.org opt_dir = os.path.dirname(current_opts_file) 5502667Sstever@eecs.umich.edu if not os.path.isdir(opt_dir): 5514554Sbinkertn@umich.edu os.mkdir(opt_dir) 5524554Sbinkertn@umich.edu 5534554Sbinkertn@umich.edu # Get default build options from source tree. Options are 5546121Snate@binkert.org # normally determined by name of $BUILD_DIR, but can be 5554554Sbinkertn@umich.edu # overriden by 'default=' arg on command line. 5564554Sbinkertn@umich.edu default_opts_file = joinpath('build_opts', 5574554Sbinkertn@umich.edu ARGUMENTS.get('default', build_dir)) 5584781Snate@binkert.org if os.path.isfile(default_opts_file): 5594554Sbinkertn@umich.edu sticky_opts.files.append(default_opts_file) 5604554Sbinkertn@umich.edu print "Options file %s not found,\n using defaults in %s" \ 5612667Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 5624554Sbinkertn@umich.edu else: 5634554Sbinkertn@umich.edu print "Error: cannot find options file %s or %s" \ 5644554Sbinkertn@umich.edu % (current_opts_file, default_opts_file) 5654554Sbinkertn@umich.edu Exit(1) 5662667Sstever@eecs.umich.edu 5674554Sbinkertn@umich.edu # Apply current option settings to env 5682667Sstever@eecs.umich.edu sticky_opts.Update(env) 5694554Sbinkertn@umich.edu nonsticky_opts.Update(env) 5706121Snate@binkert.org 5712667Sstever@eecs.umich.edu help_text += "Sticky options for %s:\n" % build_dir \ 5725522Snate@binkert.org + sticky_opts.GenerateHelpText(env) \ 5735522Snate@binkert.org + "\nNon-sticky options for %s:\n" % build_dir \ 5745522Snate@binkert.org + nonsticky_opts.GenerateHelpText(env) 5755522Snate@binkert.org 5765522Snate@binkert.org # Process option settings. 5775522Snate@binkert.org 5785522Snate@binkert.org if not have_fenv and env['USE_FENV']: 5795522Snate@binkert.org print "Warning: <fenv.h> not available; " \ 5805522Snate@binkert.org "forcing USE_FENV to False in", build_dir + "." 5815522Snate@binkert.org env['USE_FENV'] = False 5825522Snate@binkert.org 5835522Snate@binkert.org if not env['USE_FENV']: 5845522Snate@binkert.org print "Warning: No IEEE FP rounding mode control in", build_dir + "." 5855522Snate@binkert.org print " FP results may deviate slightly from other platforms." 5865522Snate@binkert.org 5875522Snate@binkert.org if env['EFENCE']: 5885522Snate@binkert.org env.Append(LIBS=['efence']) 5895522Snate@binkert.org 5905522Snate@binkert.org if env['USE_MYSQL']: 5915522Snate@binkert.org if not have_mysql: 5925522Snate@binkert.org print "Warning: MySQL not available; " \ 5935522Snate@binkert.org "forcing USE_MYSQL to False in", build_dir + "." 5945522Snate@binkert.org env['USE_MYSQL'] = False 5955522Snate@binkert.org else: 5965522Snate@binkert.org print "Compiling in", build_dir, "with MySQL support." 5975522Snate@binkert.org env.ParseConfig(mysql_config_libs) 5982638Sstever@eecs.umich.edu env.ParseConfig(mysql_config_include) 5992638Sstever@eecs.umich.edu 6006121Snate@binkert.org # Save sticky option settings back to current options file 6013716Sstever@eecs.umich.edu sticky_opts.Save(current_opts_file, env) 6025522Snate@binkert.org 6035522Snate@binkert.org # Do this after we save setting back, or else we'll tack on an 6045522Snate@binkert.org # extra 'qdo' every time we run scons. 6055522Snate@binkert.org if env['BATCH']: 6065522Snate@binkert.org env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 6075522Snate@binkert.org env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 6081858SN/A 6095227Ssaidi@eecs.umich.edu if env['USE_SSE2']: 6105227Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-msse2') 6115227Ssaidi@eecs.umich.edu 6125227Ssaidi@eecs.umich.edu # The src/SConscript file sets up the build rules in 'env' according 6136654Snate@binkert.org # to the configured options. It returns a list of environments, 6146654Snate@binkert.org # one for each variant build (debug, opt, etc.) 6157769SAli.Saidi@ARM.com envList = SConscript('src/SConscript', build_dir = build_path, 6167769SAli.Saidi@ARM.com exports = 'env') 6177769SAli.Saidi@ARM.com 6187769SAli.Saidi@ARM.com # Set up the regression tests for each build. 6195227Ssaidi@eecs.umich.edu for e in envList: 6205227Ssaidi@eecs.umich.edu SConscript('tests/SConscript', 6215227Ssaidi@eecs.umich.edu build_dir = joinpath(build_path, 'tests', e.Label), 6225204Sstever@gmail.com exports = { 'env' : e }, duplicate = False) 6235204Sstever@gmail.com 6245204Sstever@gmail.comHelp(help_text) 6255204Sstever@gmail.com 6265204Sstever@gmail.com 6275204Sstever@gmail.com################################################### 6285204Sstever@gmail.com# 6295204Sstever@gmail.com# Let SCons do its thing. At this point SCons will use the defined 6305204Sstever@gmail.com# build environments to build the requested targets. 6315204Sstever@gmail.com# 6325204Sstever@gmail.com################################################### 6335204Sstever@gmail.com 6345204Sstever@gmail.com