SConstruct revision 3583
14997Sgblack@eecs.umich.edu# -*- mode:python -*- 25268Sksewell@umich.edu 35254Sksewell@umich.edu# Copyright (c) 2004-2005 The Regents of The University of Michigan 45254Sksewell@umich.edu# All rights reserved. 54997Sgblack@eecs.umich.edu# 65254Sksewell@umich.edu# Redistribution and use in source and binary forms, with or without 75254Sksewell@umich.edu# modification, are permitted provided that the following conditions are 85254Sksewell@umich.edu# met: redistributions of source code must retain the above copyright 95254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer; 105254Sksewell@umich.edu# redistributions in binary form must reproduce the above copyright 115254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer in the 125254Sksewell@umich.edu# documentation and/or other materials provided with the distribution; 135254Sksewell@umich.edu# neither the name of the copyright holders nor the names of its 145254Sksewell@umich.edu# contributors may be used to endorse or promote products derived from 155254Sksewell@umich.edu# this software without specific prior written permission. 164997Sgblack@eecs.umich.edu# 175254Sksewell@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 185254Sksewell@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 195254Sksewell@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 205254Sksewell@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 215254Sksewell@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 225254Sksewell@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 235254Sksewell@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 245254Sksewell@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 255254Sksewell@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 265254Sksewell@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 275254Sksewell@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284997Sgblack@eecs.umich.edu# 295268Sksewell@umich.edu# Authors: Steve Reinhardt 305268Sksewell@umich.edu 315268Sksewell@umich.edu################################################### 328696Sguodeyuan@tsinghua.org.cn# 338696Sguodeyuan@tsinghua.org.cn# SCons top-level build description (SConstruct) file. 344997Sgblack@eecs.umich.edu# 354997Sgblack@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 365222Sksewell@umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 375222Sksewell@umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 384997Sgblack@eecs.umich.edu# the optimized full-system version). 398229Snate@binkert.org# 408229Snate@binkert.org# You can build M5 in a different directory as long as there is a 415222Sksewell@umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 424997Sgblack@eecs.umich.edu# expects that all configs under the same build directory are being 435222Sksewell@umich.edu# built for the same host system. 445222Sksewell@umich.edu# 455222Sksewell@umich.edu# Examples: 465222Sksewell@umich.edu# 475222Sksewell@umich.edu# The following two commands are equivalent. The '-u' option tells 488232Snate@binkert.org# scons to search up the directory tree for this SConstruct file. 498232Snate@binkert.org# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 505224Sksewell@umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 515222Sksewell@umich.edu# 528229Snate@binkert.org# The following two commands are equivalent and demonstrate building 534997Sgblack@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 545222Sksewell@umich.edu# scons to chdir to the specified directory to find this SConstruct 555222Sksewell@umich.edu# file. 565019Sgblack@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 575222Sksewell@umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 585222Sksewell@umich.edu# 595222Sksewell@umich.edu# You can use 'scons -H' to print scons options. If you're in this 605222Sksewell@umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 615019Sgblack@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 626329Sgblack@eecs.umich.edu# options as well. 636329Sgblack@eecs.umich.edu# 646329Sgblack@eecs.umich.edu################################################### 656378Sgblack@eecs.umich.edu 666329Sgblack@eecs.umich.edu# Python library imports 676378Sgblack@eecs.umich.eduimport sys 686329Sgblack@eecs.umich.eduimport os 696378Sgblack@eecs.umich.edu 706329Sgblack@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 716329Sgblack@eecs.umich.edu# default installation of Python is not recent enough, you can use a 726329Sgblack@eecs.umich.edu# non-default installation of the Python interpreter by either (1) 736329Sgblack@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 746329Sgblack@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 756329Sgblack@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 766329Sgblack@eecs.umich.eduEnsurePythonVersion(2,4) 775222Sksewell@umich.edu 785358Sgblack@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 795222Sksewell@umich.edu# 3-element version number. 806378Sgblack@eecs.umich.edumin_scons_version = (0,96,91) 816378Sgblack@eecs.umich.edutry: 826378Sgblack@eecs.umich.edu EnsureSConsVersion(*min_scons_version) 835222Sksewell@umich.eduexcept: 845222Sksewell@umich.edu print "Error checking current SCons version." 855222Sksewell@umich.edu print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 865222Sksewell@umich.edu Exit(2) 875222Sksewell@umich.edu 885222Sksewell@umich.edu 895222Sksewell@umich.edu# The absolute path to the current directory (where this file lives). 905222Sksewell@umich.eduROOT = Dir('.').abspath 915222Sksewell@umich.edu 925222Sksewell@umich.edu# Paths to the M5 and external source trees. 935222Sksewell@umich.eduSRCDIR = os.path.join(ROOT, 'src') 945222Sksewell@umich.edu 955222Sksewell@umich.edu# tell python where to find m5 python code 966378Sgblack@eecs.umich.edusys.path.append(os.path.join(ROOT, 'src/python')) 975222Sksewell@umich.edu 985222Sksewell@umich.edu################################################### 995222Sksewell@umich.edu# 1005222Sksewell@umich.edu# Figure out which configurations to set up based on the path(s) of 1016378Sgblack@eecs.umich.edu# the target(s). 1025222Sksewell@umich.edu# 1035222Sksewell@umich.edu################################################### 1045222Sksewell@umich.edu 1055222Sksewell@umich.edu# Find default configuration & binary. 1065222Sksewell@umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1076378Sgblack@eecs.umich.edu 1086378Sgblack@eecs.umich.edu# Ask SCons which directory it was invoked from. 1096378Sgblack@eecs.umich.edulaunch_dir = GetLaunchDir() 1105222Sksewell@umich.edu 1115222Sksewell@umich.edu# Make targets relative to invocation directory 1126378Sgblack@eecs.umich.eduabs_targets = map(lambda x: os.path.normpath(os.path.join(launch_dir, str(x))), 1135222Sksewell@umich.edu BUILD_TARGETS) 1145222Sksewell@umich.edu 1155019Sgblack@eecs.umich.edu# helper function: find last occurrence of element in list 1165019Sgblack@eecs.umich.edudef rfind(l, elt, offs = -1): 1175222Sksewell@umich.edu for i in range(len(l)+offs, 0, -1): 1185222Sksewell@umich.edu if l[i] == elt: 1195222Sksewell@umich.edu return i 1205222Sksewell@umich.edu raise ValueError, "element not found" 1215222Sksewell@umich.edu 1226378Sgblack@eecs.umich.edu# helper function: compare dotted version numbers. 1236378Sgblack@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1') 1245222Sksewell@umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1255222Sksewell@umich.edudef compare_versions(v1, v2): 1265222Sksewell@umich.edu # Convert dotted strings to lists 1275222Sksewell@umich.edu v1 = map(int, v1.split('.')) 1285222Sksewell@umich.edu v2 = map(int, v2.split('.')) 1295222Sksewell@umich.edu # Compare corresponding elements of lists 1306378Sgblack@eecs.umich.edu for n1,n2 in zip(v1, v2): 1316378Sgblack@eecs.umich.edu if n1 < n2: return -1 1325222Sksewell@umich.edu if n1 > n2: return 1 1335222Sksewell@umich.edu # all corresponding values are equal... see if one has extra values 1346378Sgblack@eecs.umich.edu if len(v1) < len(v2): return -1 1355222Sksewell@umich.edu if len(v1) > len(v2): return 1 1365222Sksewell@umich.edu return 0 1375222Sksewell@umich.edu 1385222Sksewell@umich.edu# Each target must have 'build' in the interior of the path; the 1396378Sgblack@eecs.umich.edu# directory below this will determine the build parameters. For 1405222Sksewell@umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1415222Sksewell@umich.edu# recognize that ALPHA_SE specifies the configuration because it 1425222Sksewell@umich.edu# follow 'build' in the bulid path. 1435222Sksewell@umich.edu 1446378Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1456378Sgblack@eecs.umich.edu# collected targets reference. 1466378Sgblack@eecs.umich.edubuild_paths = [] 1476378Sgblack@eecs.umich.edubuild_root = None 1485222Sksewell@umich.edufor t in abs_targets: 1495222Sksewell@umich.edu path_dirs = t.split('/') 1506378Sgblack@eecs.umich.edu try: 1515222Sksewell@umich.edu build_top = rfind(path_dirs, 'build', -2) 1525222Sksewell@umich.edu except: 1535222Sksewell@umich.edu print "Error: no non-leaf 'build' dir found on target path", t 1545222Sksewell@umich.edu Exit(1) 1555222Sksewell@umich.edu this_build_root = os.path.join('/',*path_dirs[:build_top+1]) 1565222Sksewell@umich.edu if not build_root: 1576378Sgblack@eecs.umich.edu build_root = this_build_root 1586378Sgblack@eecs.umich.edu else: 1595222Sksewell@umich.edu if this_build_root != build_root: 1605222Sksewell@umich.edu print "Error: build targets not under same build root\n"\ 1616378Sgblack@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1626378Sgblack@eecs.umich.edu Exit(1) 1636378Sgblack@eecs.umich.edu build_path = os.path.join('/',*path_dirs[:build_top+2]) 1646378Sgblack@eecs.umich.edu if build_path not in build_paths: 1656378Sgblack@eecs.umich.edu build_paths.append(build_path) 1666378Sgblack@eecs.umich.edu 1676378Sgblack@eecs.umich.edu################################################### 1686378Sgblack@eecs.umich.edu# 1695222Sksewell@umich.edu# Set up the default build environment. This environment is copied 1706378Sgblack@eecs.umich.edu# and modified according to each selected configuration. 1716378Sgblack@eecs.umich.edu# 1726378Sgblack@eecs.umich.edu################################################### 1735222Sksewell@umich.edu 1746378Sgblack@eecs.umich.eduenv = Environment(ENV = os.environ, # inherit user's environment vars 1756378Sgblack@eecs.umich.edu ROOT = ROOT, 1766378Sgblack@eecs.umich.edu SRCDIR = SRCDIR) 1776378Sgblack@eecs.umich.edu 1786378Sgblack@eecs.umich.eduenv.SConsignFile(os.path.join(build_root,"sconsign")) 1796378Sgblack@eecs.umich.edu 1806378Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 1816378Sgblack@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 1826378Sgblack@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 1836378Sgblack@eecs.umich.edu# (soft) links work better. 1846378Sgblack@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 1856378Sgblack@eecs.umich.edu 1866378Sgblack@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but 1876378Sgblack@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 1886378Sgblack@eecs.umich.edu# noticeably longer. 1896378Sgblack@eecs.umich.eduif False: 1906378Sgblack@eecs.umich.edu env.TargetSignatures('content') 1916378Sgblack@eecs.umich.edu 1926378Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 1936378Sgblack@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 1946378Sgblack@eecs.umich.edu 1955222Sksewell@umich.edu# Set up default C++ compiler flags 1965222Sksewell@umich.eduenv.Append(CCFLAGS='-pipe') 1975222Sksewell@umich.eduenv.Append(CCFLAGS='-fno-strict-aliasing') 1985222Sksewell@umich.eduenv.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 1995222Sksewell@umich.eduif sys.platform == 'cygwin': 2006378Sgblack@eecs.umich.edu # cygwin has some header file issues... 2015222Sksewell@umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2026378Sgblack@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 2035222Sksewell@umich.edu 2045222Sksewell@umich.edu# Check for SWIG 2055222Sksewell@umich.eduif not env.has_key('SWIG'): 2065222Sksewell@umich.edu print 'Error: SWIG utility not found.' 2075222Sksewell@umich.edu print ' Please install (see http://www.swig.org) and retry.' 2085222Sksewell@umich.edu Exit(1) 2096378Sgblack@eecs.umich.edu 2105222Sksewell@umich.edu# Check for appropriate SWIG version 2115222Sksewell@umich.eduswig_version = os.popen('swig -version').read().split() 2125222Sksewell@umich.edu# First 3 words should be "SWIG Version x.y.z" 2135222Sksewell@umich.eduif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2145222Sksewell@umich.edu print 'Error determining SWIG version.' 2155222Sksewell@umich.edu Exit(1) 2165222Sksewell@umich.edu 2175222Sksewell@umich.edumin_swig_version = '1.3.28' 2185222Sksewell@umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 2195222Sksewell@umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 2205222Sksewell@umich.edu print ' Installed version:', swig_version[2] 2215222Sksewell@umich.edu Exit(1) 2225222Sksewell@umich.edu 2235222Sksewell@umich.edu# Set up SWIG flags & scanner 2245222Sksewell@umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2255222Sksewell@umich.edu 2265222Sksewell@umich.eduimport SCons.Scanner 2275222Sksewell@umich.edu 2285222Sksewell@umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2295222Sksewell@umich.edu 2305222Sksewell@umich.eduswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2315222Sksewell@umich.edu swig_inc_re) 2325222Sksewell@umich.edu 2335222Sksewell@umich.eduenv.Append(SCANNERS = swig_scanner) 2345222Sksewell@umich.edu 2355222Sksewell@umich.edu# Platform-specific configuration. Note again that we assume that all 2365222Sksewell@umich.edu# builds under a given build root run on the same host platform. 2375222Sksewell@umich.educonf = Configure(env, 2385222Sksewell@umich.edu conf_dir = os.path.join(build_root, '.scons_config'), 2395222Sksewell@umich.edu log_file = os.path.join(build_root, 'scons_config.log')) 2405222Sksewell@umich.edu 2415222Sksewell@umich.edu# Find Python include and library directories for embedding the 2425222Sksewell@umich.edu# interpreter. For consistency, we will use the same Python 2435222Sksewell@umich.edu# installation used to run scons (and thus this script). If you want 2445222Sksewell@umich.edu# to link in an alternate version, see above for instructions on how 2455222Sksewell@umich.edu# to invoke scons with a different copy of the Python interpreter. 2465222Sksewell@umich.edu 2475222Sksewell@umich.edu# Get brief Python version name (e.g., "python2.4") for locating 2485222Sksewell@umich.edu# include & library files 2495222Sksewell@umich.edupy_version_name = 'python' + sys.version[:3] 2505222Sksewell@umich.edu 2515222Sksewell@umich.edu# include path, e.g. /usr/local/include/python2.4 2525222Sksewell@umich.edupy_header_path = os.path.join(sys.exec_prefix, 'include', py_version_name) 2535222Sksewell@umich.eduenv.Append(CPPPATH = py_header_path) 2545222Sksewell@umich.edu# verify that it works 2555222Sksewell@umich.eduif not conf.CheckHeader('Python.h', '<>'): 2565222Sksewell@umich.edu print "Error: can't find Python.h header in", py_header_path 2575222Sksewell@umich.edu Exit(1) 2585222Sksewell@umich.edu 2595222Sksewell@umich.edu# add library path too if it's not in the default place 2605222Sksewell@umich.edupy_lib_path = None 2615222Sksewell@umich.eduif sys.exec_prefix != '/usr': 2625222Sksewell@umich.edu py_lib_path = os.path.join(sys.exec_prefix, 'lib') 2635222Sksewell@umich.eduelif sys.platform == 'cygwin': 2645222Sksewell@umich.edu # cygwin puts the .dll in /bin for some reason 2655222Sksewell@umich.edu py_lib_path = '/bin' 2665222Sksewell@umich.eduif py_lib_path: 2675222Sksewell@umich.edu env.Append(LIBPATH = py_lib_path) 2685222Sksewell@umich.edu print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 2695222Sksewell@umich.eduif not conf.CheckLib(py_version_name): 2705222Sksewell@umich.edu print "Error: can't find Python library", py_version_name 2715222Sksewell@umich.edu Exit(1) 2725222Sksewell@umich.edu 2735222Sksewell@umich.edu# On Solaris you need to use libsocket for socket ops 2745222Sksewell@umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2755222Sksewell@umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 2765222Sksewell@umich.edu print "Can't find library with socket calls (e.g. accept())" 2775222Sksewell@umich.edu Exit(1) 2785222Sksewell@umich.edu 2795222Sksewell@umich.edu# Check for zlib. If the check passes, libz will be automatically 2805222Sksewell@umich.edu# added to the LIBS environment variable. 2815222Sksewell@umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++'): 2825222Sksewell@umich.edu print 'Error: did not find needed zlib compression library '\ 2835222Sksewell@umich.edu 'and/or zlib.h header file.' 2845222Sksewell@umich.edu print ' Please install zlib and try again.' 2855222Sksewell@umich.edu Exit(1) 2865222Sksewell@umich.edu 2875222Sksewell@umich.edu# Check for <fenv.h> (C99 FP environment control) 2885222Sksewell@umich.eduhave_fenv = conf.CheckHeader('fenv.h', '<>') 2895222Sksewell@umich.eduif not have_fenv: 2905222Sksewell@umich.edu print "Warning: Header file <fenv.h> not found." 2915222Sksewell@umich.edu print " This host has no IEEE FP rounding mode control." 2925222Sksewell@umich.edu 2935222Sksewell@umich.edu# Check for mysql. 2945222Sksewell@umich.edumysql_config = WhereIs('mysql_config') 2955222Sksewell@umich.eduhave_mysql = mysql_config != None 2966022Sgblack@eecs.umich.edu 2975222Sksewell@umich.edu# Check MySQL version. 2988806Sgblack@eecs.umich.eduif have_mysql: 2998806Sgblack@eecs.umich.edu mysql_version = os.popen(mysql_config + ' --version').read() 3005224Sksewell@umich.edu min_mysql_version = '4.1' 3018806Sgblack@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 3025224Sksewell@umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3038806Sgblack@eecs.umich.edu print ' Version', mysql_version, 'detected.' 3048806Sgblack@eecs.umich.edu have_mysql = False 3058806Sgblack@eecs.umich.edu 3068806Sgblack@eecs.umich.edu# Set up mysql_config commands. 3078806Sgblack@eecs.umich.eduif have_mysql: 3085222Sksewell@umich.edu mysql_config_include = mysql_config + ' --include' 3095222Sksewell@umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 3105222Sksewell@umich.edu # older mysql_config versions don't support --include, use 3116022Sgblack@eecs.umich.edu # --cflags instead 3125222Sksewell@umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 3138806Sgblack@eecs.umich.edu # This seems to work in all versions 3148806Sgblack@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 3158767Sgblack@eecs.umich.edu 3168806Sgblack@eecs.umich.eduenv = conf.Finish() 3178767Sgblack@eecs.umich.edu 3188806Sgblack@eecs.umich.edu# Define the universe of supported ISAs 3198806Sgblack@eecs.umich.eduenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 3208806Sgblack@eecs.umich.edu 3218806Sgblack@eecs.umich.edu# Define the universe of supported CPU models 3228806Sgblack@eecs.umich.eduenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 3235222Sksewell@umich.edu 'O3CPU', 'OzoneCPU'] 3245222Sksewell@umich.edu 3256022Sgblack@eecs.umich.eduif os.path.isdir(os.path.join(SRCDIR, 'src/encumbered/cpu/full')): 3266023Snate@binkert.org env['ALL_CPU_LIST'] += ['FullCPU'] 3276022Sgblack@eecs.umich.edu 3286023Snate@binkert.org# Sticky options get saved in the options file so they persist from 3296022Sgblack@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 3306022Sgblack@eecs.umich.edu# value becomes sticky). 3316023Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS) 3326022Sgblack@eecs.umich.edusticky_opts.AddOptions( 3336022Sgblack@eecs.umich.edu EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 3345894Sgblack@eecs.umich.edu BoolOption('FULL_SYSTEM', 'Full-system support', False), 3356022Sgblack@eecs.umich.edu # There's a bug in scons 0.96.1 that causes ListOptions with list 3366023Snate@binkert.org # values (more than one value) not to be able to be restored from 3375894Sgblack@eecs.umich.edu # a saved option file. If this causes trouble then upgrade to 3385894Sgblack@eecs.umich.edu # scons 0.96.90 or later. 3396023Snate@binkert.org ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU', 3405894Sgblack@eecs.umich.edu env['ALL_CPU_LIST']), 3415894Sgblack@eecs.umich.edu BoolOption('ALPHA_TLASER', 3428888Sgeoffrey.blake@arm.com 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 3438888Sgeoffrey.blake@arm.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 3448888Sgeoffrey.blake@arm.com BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 3458888Sgeoffrey.blake@arm.com False), 3468888Sgeoffrey.blake@arm.com BoolOption('SS_COMPATIBLE_FP', 3478888Sgeoffrey.blake@arm.com 'Make floating-point results compatible with SimpleScalar', 3488888Sgeoffrey.blake@arm.com False), 3499738Sandreas@sandberg.pp.se BoolOption('USE_SSE2', 3509738Sandreas@sandberg.pp.se 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 3519738Sandreas@sandberg.pp.se False), 3529738Sandreas@sandberg.pp.se BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 3539738Sandreas@sandberg.pp.se BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 3549738Sandreas@sandberg.pp.se BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 3555222Sksewell@umich.edu ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3565222Sksewell@umich.edu ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3575222Sksewell@umich.edu BoolOption('BATCH', 'Use batch pool for build and tests', False), 3585222Sksewell@umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3596378Sgblack@eecs.umich.edu ('PYTHONHOME', 3605222Sksewell@umich.edu 'Override the default PYTHONHOME for this system (use with caution)', 3615222Sksewell@umich.edu '%s:%s' % (sys.prefix, sys.exec_prefix)) 3625222Sksewell@umich.edu ) 3635222Sksewell@umich.edu 3645222Sksewell@umich.edu# Non-sticky options only apply to the current build. 3655222Sksewell@umich.edunonsticky_opts = Options(args=ARGUMENTS) 3664997Sgblack@eecs.umich.edunonsticky_opts.AddOptions( 3676022Sgblack@eecs.umich.edu BoolOption('update_ref', 'Update test reference outputs', False) 3686022Sgblack@eecs.umich.edu ) 3694997Sgblack@eecs.umich.edu 3706378Sgblack@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript). 3714997Sgblack@eecs.umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 372 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 373 'USE_CHECKER', 'PYTHONHOME'] 374 375# Define a handy 'no-op' action 376def no_action(target, source, env): 377 return 0 378 379env.NoAction = Action(no_action, None) 380 381################################################### 382# 383# Define a SCons builder for configuration flag headers. 384# 385################################################### 386 387# This function generates a config header file that #defines the 388# option symbol to the current option setting (0 or 1). The source 389# operands are the name of the option and a Value node containing the 390# value of the option. 391def build_config_file(target, source, env): 392 (option, value) = [s.get_contents() for s in source] 393 f = file(str(target[0]), 'w') 394 print >> f, '#define', option, value 395 f.close() 396 return None 397 398# Generate the message to be printed when building the config file. 399def build_config_file_string(target, source, env): 400 (option, value) = [s.get_contents() for s in source] 401 return "Defining %s as %s in %s." % (option, value, target[0]) 402 403# Combine the two functions into a scons Action object. 404config_action = Action(build_config_file, build_config_file_string) 405 406# The emitter munges the source & target node lists to reflect what 407# we're really doing. 408def config_emitter(target, source, env): 409 # extract option name from Builder arg 410 option = str(target[0]) 411 # True target is config header file 412 target = os.path.join('config', option.lower() + '.hh') 413 val = env[option] 414 if isinstance(val, bool): 415 # Force value to 0/1 416 val = int(val) 417 elif isinstance(val, str): 418 val = '"' + val + '"' 419 420 # Sources are option name & value (packaged in SCons Value nodes) 421 return ([target], [Value(option), Value(val)]) 422 423config_builder = Builder(emitter = config_emitter, action = config_action) 424 425env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 426 427################################################### 428# 429# Define a SCons builder for copying files. This is used by the 430# Python zipfile code in src/python/SConscript, but is placed up here 431# since it's potentially more generally applicable. 432# 433################################################### 434 435copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 436 437env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 438 439################################################### 440# 441# Define a simple SCons builder to concatenate files. 442# 443# Used to append the Python zip archive to the executable. 444# 445################################################### 446 447concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 448 'chmod +x $TARGET'])) 449 450env.Append(BUILDERS = { 'Concat' : concat_builder }) 451 452 453# base help text 454help_text = ''' 455Usage: scons [scons options] [build options] [target(s)] 456 457''' 458 459# libelf build is shared across all configs in the build root. 460env.SConscript('ext/libelf/SConscript', 461 build_dir = os.path.join(build_root, 'libelf'), 462 exports = 'env') 463 464################################################### 465# 466# This function is used to set up a directory with switching headers 467# 468################################################### 469 470def make_switching_dir(dirname, switch_headers, env): 471 # Generate the header. target[0] is the full path of the output 472 # header to generate. 'source' is a dummy variable, since we get the 473 # list of ISAs from env['ALL_ISA_LIST']. 474 def gen_switch_hdr(target, source, env): 475 fname = str(target[0]) 476 basename = os.path.basename(fname) 477 f = open(fname, 'w') 478 f.write('#include "arch/isa_specific.hh"\n') 479 cond = '#if' 480 for isa in env['ALL_ISA_LIST']: 481 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 482 % (cond, isa.upper(), dirname, isa, basename)) 483 cond = '#elif' 484 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 485 f.close() 486 return 0 487 488 # String to print when generating header 489 def gen_switch_hdr_string(target, source, env): 490 return "Generating switch header " + str(target[0]) 491 492 # Build SCons Action object. 'varlist' specifies env vars that this 493 # action depends on; when env['ALL_ISA_LIST'] changes these actions 494 # should get re-executed. 495 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 496 varlist=['ALL_ISA_LIST']) 497 498 # Instantiate actions for each header 499 for hdr in switch_headers: 500 env.Command(hdr, [], switch_hdr_action) 501 502env.make_switching_dir = make_switching_dir 503 504################################################### 505# 506# Define build environments for selected configurations. 507# 508################################################### 509 510# rename base env 511base_env = env 512 513for build_path in build_paths: 514 print "Building in", build_path 515 # build_dir is the tail component of build path, and is used to 516 # determine the build parameters (e.g., 'ALPHA_SE') 517 (build_root, build_dir) = os.path.split(build_path) 518 # Make a copy of the build-root environment to use for this config. 519 env = base_env.Copy() 520 521 # Set env options according to the build directory config. 522 sticky_opts.files = [] 523 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 524 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 525 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 526 current_opts_file = os.path.join(build_root, 'options', build_dir) 527 if os.path.isfile(current_opts_file): 528 sticky_opts.files.append(current_opts_file) 529 print "Using saved options file %s" % current_opts_file 530 else: 531 # Build dir-specific options file doesn't exist. 532 533 # Make sure the directory is there so we can create it later 534 opt_dir = os.path.dirname(current_opts_file) 535 if not os.path.isdir(opt_dir): 536 os.mkdir(opt_dir) 537 538 # Get default build options from source tree. Options are 539 # normally determined by name of $BUILD_DIR, but can be 540 # overriden by 'default=' arg on command line. 541 default_opts_file = os.path.join('build_opts', 542 ARGUMENTS.get('default', build_dir)) 543 if os.path.isfile(default_opts_file): 544 sticky_opts.files.append(default_opts_file) 545 print "Options file %s not found,\n using defaults in %s" \ 546 % (current_opts_file, default_opts_file) 547 else: 548 print "Error: cannot find options file %s or %s" \ 549 % (current_opts_file, default_opts_file) 550 Exit(1) 551 552 # Apply current option settings to env 553 sticky_opts.Update(env) 554 nonsticky_opts.Update(env) 555 556 help_text += "Sticky options for %s:\n" % build_dir \ 557 + sticky_opts.GenerateHelpText(env) \ 558 + "\nNon-sticky options for %s:\n" % build_dir \ 559 + nonsticky_opts.GenerateHelpText(env) 560 561 # Process option settings. 562 563 if not have_fenv and env['USE_FENV']: 564 print "Warning: <fenv.h> not available; " \ 565 "forcing USE_FENV to False in", build_dir + "." 566 env['USE_FENV'] = False 567 568 if not env['USE_FENV']: 569 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 570 print " FP results may deviate slightly from other platforms." 571 572 if env['EFENCE']: 573 env.Append(LIBS=['efence']) 574 575 if env['USE_MYSQL']: 576 if not have_mysql: 577 print "Warning: MySQL not available; " \ 578 "forcing USE_MYSQL to False in", build_dir + "." 579 env['USE_MYSQL'] = False 580 else: 581 print "Compiling in", build_dir, "with MySQL support." 582 env.ParseConfig(mysql_config_libs) 583 env.ParseConfig(mysql_config_include) 584 585 # Save sticky option settings back to current options file 586 sticky_opts.Save(current_opts_file, env) 587 588 # Do this after we save setting back, or else we'll tack on an 589 # extra 'qdo' every time we run scons. 590 if env['BATCH']: 591 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 592 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 593 594 if env['USE_SSE2']: 595 env.Append(CCFLAGS='-msse2') 596 597 # The src/SConscript file sets up the build rules in 'env' according 598 # to the configured options. It returns a list of environments, 599 # one for each variant build (debug, opt, etc.) 600 envList = SConscript('src/SConscript', build_dir = build_path, 601 exports = 'env') 602 603 # Set up the regression tests for each build. 604 for e in envList: 605 SConscript('tests/SConscript', 606 build_dir = os.path.join(build_path, 'tests', e.Label), 607 exports = { 'env' : e }, duplicate = False) 608 609Help(help_text) 610 611 612################################################### 613# 614# Let SCons do its thing. At this point SCons will use the defined 615# build environments to build the requested targets. 616# 617################################################### 618 619