SConstruct revision 3940
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt 30955SN/A 31955SN/A################################################### 32955SN/A# 33955SN/A# SCons top-level build description (SConstruct) file. 34955SN/A# 352632Sstever@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 362632Sstever@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 372632Sstever@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 382632Sstever@eecs.umich.edu# the optimized full-system version). 39955SN/A# 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 422761Sstever@eecs.umich.edu# 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# 452632Sstever@eecs.umich.edu# Examples: 462761Sstever@eecs.umich.edu# 472761Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 482761Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 492632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 502632Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512761Sstever@eecs.umich.edu# 522761Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 532761Sstever@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. 562632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 572632Sstever@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 612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 622632Sstever@eecs.umich.edu# options as well. 63955SN/A# 64955SN/A################################################### 65955SN/A 66955SN/A# Python library imports 67955SN/Aimport sys 68955SN/Aimport os 693918Ssaidi@eecs.umich.eduimport subprocess 703716Sstever@eecs.umich.edufrom os.path import join as joinpath 71955SN/A 722656Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 732656Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a 742656Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1) 752656Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 762656Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 772656Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 782656Sstever@eecs.umich.eduEnsurePythonVersion(2,4) 792653Sstever@eecs.umich.edu 802653Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 812653Sstever@eecs.umich.edu# 3-element version number. 822653Sstever@eecs.umich.edumin_scons_version = (0,96,91) 832653Sstever@eecs.umich.edutry: 842653Sstever@eecs.umich.edu EnsureSConsVersion(*min_scons_version) 852653Sstever@eecs.umich.eduexcept: 862653Sstever@eecs.umich.edu print "Error checking current SCons version." 872653Sstever@eecs.umich.edu print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 882653Sstever@eecs.umich.edu Exit(2) 892653Sstever@eecs.umich.edu 901852SN/A 91955SN/A# The absolute path to the current directory (where this file lives). 92955SN/AROOT = Dir('.').abspath 93955SN/A 943717Sstever@eecs.umich.edu# Path to the M5 source tree. 953716Sstever@eecs.umich.eduSRCDIR = joinpath(ROOT, 'src') 96955SN/A 971533SN/A# tell python where to find m5 python code 983716Sstever@eecs.umich.edusys.path.append(joinpath(ROOT, 'src/python')) 991533SN/A 100955SN/A################################################### 101955SN/A# 1022632Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 1032632Sstever@eecs.umich.edu# the target(s). 104955SN/A# 105955SN/A################################################### 106955SN/A 107955SN/A# Find default configuration & binary. 1082632Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 109955SN/A 1102632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 1112632Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 1122632Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 1132632Sstever@eecs.umich.edu if l[i] == elt: 1142632Sstever@eecs.umich.edu return i 1152632Sstever@eecs.umich.edu raise ValueError, "element not found" 1162632Sstever@eecs.umich.edu 1173053Sstever@eecs.umich.edu# helper function: compare dotted version numbers. 1183053Sstever@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1') 1193053Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1203053Sstever@eecs.umich.edudef compare_versions(v1, v2): 1213053Sstever@eecs.umich.edu # Convert dotted strings to lists 1223053Sstever@eecs.umich.edu v1 = map(int, v1.split('.')) 1233053Sstever@eecs.umich.edu v2 = map(int, v2.split('.')) 1243053Sstever@eecs.umich.edu # Compare corresponding elements of lists 1253053Sstever@eecs.umich.edu for n1,n2 in zip(v1, v2): 1263053Sstever@eecs.umich.edu if n1 < n2: return -1 1273053Sstever@eecs.umich.edu if n1 > n2: return 1 1283053Sstever@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1293053Sstever@eecs.umich.edu if len(v1) < len(v2): return -1 1303053Sstever@eecs.umich.edu if len(v1) > len(v2): return 1 1313053Sstever@eecs.umich.edu return 0 1323053Sstever@eecs.umich.edu 1332632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 1342632Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 1352632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1362632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 1372632Sstever@eecs.umich.edu# follow 'build' in the bulid path. 1382632Sstever@eecs.umich.edu 1393718Sstever@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is 1403718Sstever@eecs.umich.eduif COMMAND_LINE_TARGETS: 1413718Sstever@eecs.umich.edu # Ask SCons which directory it was invoked from 1423718Sstever@eecs.umich.edu launch_dir = GetLaunchDir() 1433718Sstever@eecs.umich.edu # Make targets relative to invocation directory 1443718Sstever@eecs.umich.edu abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 1453718Sstever@eecs.umich.edu COMMAND_LINE_TARGETS) 1463718Sstever@eecs.umich.eduelse: 1473718Sstever@eecs.umich.edu # Default targets are relative to root of tree 1483718Sstever@eecs.umich.edu abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 1493718Sstever@eecs.umich.edu DEFAULT_TARGETS) 1503718Sstever@eecs.umich.edu 1513718Sstever@eecs.umich.edu 1522634Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1532634Sstever@eecs.umich.edu# collected targets reference. 1542632Sstever@eecs.umich.edubuild_paths = [] 1552638Sstever@eecs.umich.edubuild_root = None 1562632Sstever@eecs.umich.edufor t in abs_targets: 1572632Sstever@eecs.umich.edu path_dirs = t.split('/') 1582632Sstever@eecs.umich.edu try: 1592632Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 1602632Sstever@eecs.umich.edu except: 1612632Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 1621858SN/A Exit(1) 1633716Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 1642638Sstever@eecs.umich.edu if not build_root: 1652638Sstever@eecs.umich.edu build_root = this_build_root 1662638Sstever@eecs.umich.edu else: 1672638Sstever@eecs.umich.edu if this_build_root != build_root: 1682638Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 1692638Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1702638Sstever@eecs.umich.edu Exit(1) 1713716Sstever@eecs.umich.edu build_path = joinpath('/',*path_dirs[:build_top+2]) 1722634Sstever@eecs.umich.edu if build_path not in build_paths: 1732634Sstever@eecs.umich.edu build_paths.append(build_path) 174955SN/A 175955SN/A################################################### 176955SN/A# 177955SN/A# Set up the default build environment. This environment is copied 178955SN/A# and modified according to each selected configuration. 179955SN/A# 180955SN/A################################################### 181955SN/A 1821858SN/Aenv = Environment(ENV = os.environ, # inherit user's environment vars 1831858SN/A ROOT = ROOT, 1842632Sstever@eecs.umich.edu SRCDIR = SRCDIR) 185955SN/A 1863643Ssaidi@eecs.umich.edu#Parse CC/CXX early so that we use the correct compiler for 1873643Ssaidi@eecs.umich.edu# to test for dependencies/versions/libraries/includes 1883643Ssaidi@eecs.umich.eduif ARGUMENTS.get('CC', None): 1893643Ssaidi@eecs.umich.edu env['CC'] = ARGUMENTS.get('CC') 1903643Ssaidi@eecs.umich.edu 1913643Ssaidi@eecs.umich.eduif ARGUMENTS.get('CXX', None): 1923643Ssaidi@eecs.umich.edu env['CXX'] = ARGUMENTS.get('CXX') 1933643Ssaidi@eecs.umich.edu 1943716Sstever@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign")) 1951105SN/A 1962667Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 1972667Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 1982667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 1992667Sstever@eecs.umich.edu# (soft) links work better. 2002667Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 2012667Sstever@eecs.umich.edu 2021869SN/A# I waffle on this setting... it does avoid a few painful but 2031869SN/A# unnecessary builds, but it also seems to make trivial builds take 2041869SN/A# noticeably longer. 2051869SN/Aif False: 2061869SN/A env.TargetSignatures('content') 2071065SN/A 2082632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 2092632Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 2103918Ssaidi@eecs.umich.eduenv['GCC'] = False 2113918Ssaidi@eecs.umich.eduenv['SUNCC'] = False 2123940Ssaidi@eecs.umich.eduenv['ICC'] = False 2133918Ssaidi@eecs.umich.eduenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 2143918Ssaidi@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2153918Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('GCC') >= 0 2163918Ssaidi@eecs.umich.eduenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 2173918Ssaidi@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2183918Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('Sun C++') >= 0 2193940Ssaidi@eecs.umich.eduenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 2203940Ssaidi@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2213940Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('Intel') >= 0 2223940Ssaidi@eecs.umich.eduif env['GCC'] + env['SUNCC'] env['ICC'] > 1: 2233940Ssaidi@eecs.umich.edu print 'Error: How can we have two at the same time?' 2243918Ssaidi@eecs.umich.edu Exit(1) 2253918Ssaidi@eecs.umich.edu 226955SN/A 2271858SN/A# Set up default C++ compiler flags 2283918Ssaidi@eecs.umich.eduif env['GCC']: 2293918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-pipe') 2303918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-fno-strict-aliasing') 2313918Ssaidi@eecs.umich.edu env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2323940Ssaidi@eecs.umich.eduelif env['ICC']: 2333940Ssaidi@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 2343918Ssaidi@eecs.umich.eduelif env['SUNCC']: 2353918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-Qoption ccfe') 2363918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-features=gcc') 2373918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-features=extensions') 2383918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-library=stlport4') 2393918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-xar') 2403918Ssaidi@eecs.umich.edu# env.Append(CCFLAGS='-instances=semiexplicit') 2413918Ssaidi@eecs.umich.eduelse: 2423918Ssaidi@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 2433940Ssaidi@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 2443918Ssaidi@eecs.umich.edu Exit(1) 2453918Ssaidi@eecs.umich.edu 2461851SN/Aif sys.platform == 'cygwin': 2471851SN/A # cygwin has some header file issues... 2481858SN/A env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2492632Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 250955SN/A 2513053Sstever@eecs.umich.edu# Check for SWIG 2523053Sstever@eecs.umich.eduif not env.has_key('SWIG'): 2533053Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 2543053Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 2553053Sstever@eecs.umich.edu Exit(1) 2563053Sstever@eecs.umich.edu 2573053Sstever@eecs.umich.edu# Check for appropriate SWIG version 2583053Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split() 2593053Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 2603053Sstever@eecs.umich.eduif swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2613053Sstever@eecs.umich.edu print 'Error determining SWIG version.' 2623053Sstever@eecs.umich.edu Exit(1) 2633053Sstever@eecs.umich.edu 2643053Sstever@eecs.umich.edumin_swig_version = '1.3.28' 2653053Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 2663053Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 2673053Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 2683053Sstever@eecs.umich.edu Exit(1) 2693053Sstever@eecs.umich.edu 2702667Sstever@eecs.umich.edu# Set up SWIG flags & scanner 2712667Sstever@eecs.umich.eduenv.Append(SWIGFLAGS=Split('-c++ -python -modern $_CPPINCFLAGS')) 2722667Sstever@eecs.umich.edu 2732667Sstever@eecs.umich.eduimport SCons.Scanner 2742667Sstever@eecs.umich.edu 2752667Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2762667Sstever@eecs.umich.edu 2772667Sstever@eecs.umich.eduswig_scanner = SCons.Scanner.ClassicCPP("SwigScan", ".i", "CPPPATH", 2782667Sstever@eecs.umich.edu swig_inc_re) 2792667Sstever@eecs.umich.edu 2802667Sstever@eecs.umich.eduenv.Append(SCANNERS = swig_scanner) 2812667Sstever@eecs.umich.edu 2822638Sstever@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 2832638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 2842638Sstever@eecs.umich.educonf = Configure(env, 2853716Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 2863716Sstever@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log')) 2871858SN/A 2883118Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 2893118Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 2903118Sstever@eecs.umich.edu# installation used to run scons (and thus this script). If you want 2913118Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how 2923118Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 2933118Sstever@eecs.umich.edu 2943118Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating 2953118Sstever@eecs.umich.edu# include & library files 2963118Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3] 2973118Sstever@eecs.umich.edu 2983118Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4 2993716Sstever@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 3003118Sstever@eecs.umich.eduenv.Append(CPPPATH = py_header_path) 3013118Sstever@eecs.umich.edu# verify that it works 3023118Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 3033118Sstever@eecs.umich.edu print "Error: can't find Python.h header in", py_header_path 3043118Sstever@eecs.umich.edu Exit(1) 3053118Sstever@eecs.umich.edu 3063118Sstever@eecs.umich.edu# add library path too if it's not in the default place 3073118Sstever@eecs.umich.edupy_lib_path = None 3083118Sstever@eecs.umich.eduif sys.exec_prefix != '/usr': 3093716Sstever@eecs.umich.edu py_lib_path = joinpath(sys.exec_prefix, 'lib') 3103118Sstever@eecs.umich.eduelif sys.platform == 'cygwin': 3113118Sstever@eecs.umich.edu # cygwin puts the .dll in /bin for some reason 3123118Sstever@eecs.umich.edu py_lib_path = '/bin' 3133118Sstever@eecs.umich.eduif py_lib_path: 3143118Sstever@eecs.umich.edu env.Append(LIBPATH = py_lib_path) 3153118Sstever@eecs.umich.edu print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 3163118Sstever@eecs.umich.eduif not conf.CheckLib(py_version_name): 3173118Sstever@eecs.umich.edu print "Error: can't find Python library", py_version_name 3183118Sstever@eecs.umich.edu Exit(1) 3193118Sstever@eecs.umich.edu 3203483Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 3213494Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 3223494Ssaidi@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 3233483Ssaidi@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 3243483Ssaidi@eecs.umich.edu Exit(1) 3253483Ssaidi@eecs.umich.edu 3263053Sstever@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 3273053Sstever@eecs.umich.edu# added to the LIBS environment variable. 3283918Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 3293053Sstever@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 3303053Sstever@eecs.umich.edu 'and/or zlib.h header file.' 3313053Sstever@eecs.umich.edu print ' Please install zlib and try again.' 3323053Sstever@eecs.umich.edu Exit(1) 3333053Sstever@eecs.umich.edu 3341858SN/A# Check for <fenv.h> (C99 FP environment control) 3351858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 3361858SN/Aif not have_fenv: 3371858SN/A print "Warning: Header file <fenv.h> not found." 3381858SN/A print " This host has no IEEE FP rounding mode control." 3391858SN/A 3401859SN/A# Check for mysql. 3411858SN/Amysql_config = WhereIs('mysql_config') 3421858SN/Ahave_mysql = mysql_config != None 3431858SN/A 3441859SN/A# Check MySQL version. 3451859SN/Aif have_mysql: 3461862SN/A mysql_version = os.popen(mysql_config + ' --version').read() 3473053Sstever@eecs.umich.edu min_mysql_version = '4.1' 3483053Sstever@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 3493053Sstever@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3503053Sstever@eecs.umich.edu print ' Version', mysql_version, 'detected.' 3511859SN/A have_mysql = False 3521859SN/A 3531859SN/A# Set up mysql_config commands. 3541859SN/Aif have_mysql: 3551859SN/A mysql_config_include = mysql_config + ' --include' 3561859SN/A if os.system(mysql_config_include + ' > /dev/null') != 0: 3571859SN/A # older mysql_config versions don't support --include, use 3581859SN/A # --cflags instead 3591862SN/A mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 3601859SN/A # This seems to work in all versions 3611859SN/A mysql_config_libs = mysql_config + ' --libs' 3621859SN/A 3631858SN/Aenv = conf.Finish() 3641858SN/A 3652139SN/A# Define the universe of supported ISAs 3662139SN/Aenv['ALL_ISA_LIST'] = ['alpha', 'sparc', 'mips'] 3672139SN/A 3682155SN/A# Define the universe of supported CPU models 3692623SN/Aenv['ALL_CPU_LIST'] = ['AtomicSimpleCPU', 'TimingSimpleCPU', 3703583Sbinkertn@umich.edu 'O3CPU', 'OzoneCPU'] 3713583Sbinkertn@umich.edu 3723717Sstever@eecs.umich.eduif os.path.isdir(joinpath(SRCDIR, 'encumbered/cpu/full')): 3733583Sbinkertn@umich.edu env['ALL_CPU_LIST'] += ['FullCPU'] 3742155SN/A 3751869SN/A# Sticky options get saved in the options file so they persist from 3761869SN/A# one invocation to the next (unless overridden, in which case the new 3771869SN/A# value becomes sticky). 3781869SN/Asticky_opts = Options(args=ARGUMENTS) 3791869SN/Asticky_opts.AddOptions( 3802139SN/A EnumOption('TARGET_ISA', 'Target ISA', 'alpha', env['ALL_ISA_LIST']), 3811869SN/A BoolOption('FULL_SYSTEM', 'Full-system support', False), 3822508SN/A # There's a bug in scons 0.96.1 that causes ListOptions with list 3832508SN/A # values (more than one value) not to be able to be restored from 3842508SN/A # a saved option file. If this causes trouble then upgrade to 3852508SN/A # scons 0.96.90 or later. 3863685Sktlim@umich.edu ListOption('CPU_MODELS', 'CPU models', 'AtomicSimpleCPU,TimingSimpleCPU,O3CPU', 3872635Sstever@eecs.umich.edu env['ALL_CPU_LIST']), 3881869SN/A BoolOption('ALPHA_TLASER', 3891869SN/A 'Model Alpha TurboLaser platform (vs. Tsunami)', False), 3901869SN/A BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 3911869SN/A BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 3921869SN/A False), 3931869SN/A BoolOption('SS_COMPATIBLE_FP', 3941869SN/A 'Make floating-point results compatible with SimpleScalar', 3951869SN/A False), 3961965SN/A BoolOption('USE_SSE2', 3971965SN/A 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 3981965SN/A False), 3991869SN/A BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 4001869SN/A BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 4012733Sktlim@umich.edu BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 4021869SN/A ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 4031884SN/A ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 4041884SN/A BoolOption('BATCH', 'Use batch pool for build and tests', False), 4053356Sbinkertn@umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 4063356Sbinkertn@umich.edu ('PYTHONHOME', 4073356Sbinkertn@umich.edu 'Override the default PYTHONHOME for this system (use with caution)', 4083356Sbinkertn@umich.edu '%s:%s' % (sys.prefix, sys.exec_prefix)) 4091869SN/A ) 4101858SN/A 4111869SN/A# Non-sticky options only apply to the current build. 4121869SN/Anonsticky_opts = Options(args=ARGUMENTS) 4131869SN/Anonsticky_opts.AddOptions( 4141869SN/A BoolOption('update_ref', 'Update test reference outputs', False) 4151869SN/A ) 4161858SN/A 4172761Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript). 4181869SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 4192733Sktlim@umich.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 4203584Ssaidi@eecs.umich.edu 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 4211869SN/A 4221869SN/A# Define a handy 'no-op' action 4231869SN/Adef no_action(target, source, env): 4241869SN/A return 0 4251869SN/A 4261869SN/Aenv.NoAction = Action(no_action, None) 4271858SN/A 428955SN/A################################################### 429955SN/A# 4301869SN/A# Define a SCons builder for configuration flag headers. 4311869SN/A# 4321869SN/A################################################### 4331869SN/A 4341869SN/A# This function generates a config header file that #defines the 4351869SN/A# option symbol to the current option setting (0 or 1). The source 4361869SN/A# operands are the name of the option and a Value node containing the 4371869SN/A# value of the option. 4381869SN/Adef build_config_file(target, source, env): 4391869SN/A (option, value) = [s.get_contents() for s in source] 4401869SN/A f = file(str(target[0]), 'w') 4411869SN/A print >> f, '#define', option, value 4421869SN/A f.close() 4431869SN/A return None 4441869SN/A 4451869SN/A# Generate the message to be printed when building the config file. 4461869SN/Adef build_config_file_string(target, source, env): 4471869SN/A (option, value) = [s.get_contents() for s in source] 4481869SN/A return "Defining %s as %s in %s." % (option, value, target[0]) 4491869SN/A 4501869SN/A# Combine the two functions into a scons Action object. 4511869SN/Aconfig_action = Action(build_config_file, build_config_file_string) 4521869SN/A 4531869SN/A# The emitter munges the source & target node lists to reflect what 4541869SN/A# we're really doing. 4551869SN/Adef config_emitter(target, source, env): 4561869SN/A # extract option name from Builder arg 4571869SN/A option = str(target[0]) 4581869SN/A # True target is config header file 4593716Sstever@eecs.umich.edu target = joinpath('config', option.lower() + '.hh') 4603356Sbinkertn@umich.edu val = env[option] 4613356Sbinkertn@umich.edu if isinstance(val, bool): 4623356Sbinkertn@umich.edu # Force value to 0/1 4633356Sbinkertn@umich.edu val = int(val) 4643356Sbinkertn@umich.edu elif isinstance(val, str): 4653356Sbinkertn@umich.edu val = '"' + val + '"' 4663356Sbinkertn@umich.edu 4671869SN/A # Sources are option name & value (packaged in SCons Value nodes) 4681869SN/A return ([target], [Value(option), Value(val)]) 4691869SN/A 4701869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action) 4711869SN/A 4721869SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 4731869SN/A 4742655Sstever@eecs.umich.edu################################################### 4752655Sstever@eecs.umich.edu# 4762655Sstever@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 4772655Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here 4782655Sstever@eecs.umich.edu# since it's potentially more generally applicable. 4792655Sstever@eecs.umich.edu# 4802655Sstever@eecs.umich.edu################################################### 4812655Sstever@eecs.umich.edu 4822655Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 4832655Sstever@eecs.umich.edu 4842655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 4852655Sstever@eecs.umich.edu 4862655Sstever@eecs.umich.edu################################################### 4872655Sstever@eecs.umich.edu# 4882655Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files. 4892655Sstever@eecs.umich.edu# 4902655Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable. 4912655Sstever@eecs.umich.edu# 4922655Sstever@eecs.umich.edu################################################### 4932655Sstever@eecs.umich.edu 4942655Sstever@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 4952655Sstever@eecs.umich.edu 'chmod +x $TARGET'])) 4962655Sstever@eecs.umich.edu 4972655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder }) 4982655Sstever@eecs.umich.edu 4992655Sstever@eecs.umich.edu 5002634Sstever@eecs.umich.edu# base help text 5012634Sstever@eecs.umich.eduhelp_text = ''' 5022634Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 5032634Sstever@eecs.umich.edu 5042634Sstever@eecs.umich.edu''' 5052634Sstever@eecs.umich.edu 5062638Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root. 5072638Sstever@eecs.umich.eduenv.SConscript('ext/libelf/SConscript', 5083716Sstever@eecs.umich.edu build_dir = joinpath(build_root, 'libelf'), 5092638Sstever@eecs.umich.edu exports = 'env') 5102638Sstever@eecs.umich.edu 5111869SN/A################################################### 5121869SN/A# 5133546Sgblack@eecs.umich.edu# This function is used to set up a directory with switching headers 5143546Sgblack@eecs.umich.edu# 5153546Sgblack@eecs.umich.edu################################################### 5163546Sgblack@eecs.umich.edu 5173546Sgblack@eecs.umich.edudef make_switching_dir(dirname, switch_headers, env): 5183546Sgblack@eecs.umich.edu # Generate the header. target[0] is the full path of the output 5193546Sgblack@eecs.umich.edu # header to generate. 'source' is a dummy variable, since we get the 5203546Sgblack@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 5213546Sgblack@eecs.umich.edu def gen_switch_hdr(target, source, env): 5223546Sgblack@eecs.umich.edu fname = str(target[0]) 5233546Sgblack@eecs.umich.edu basename = os.path.basename(fname) 5243546Sgblack@eecs.umich.edu f = open(fname, 'w') 5253546Sgblack@eecs.umich.edu f.write('#include "arch/isa_specific.hh"\n') 5263546Sgblack@eecs.umich.edu cond = '#if' 5273546Sgblack@eecs.umich.edu for isa in env['ALL_ISA_LIST']: 5283546Sgblack@eecs.umich.edu f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 5293546Sgblack@eecs.umich.edu % (cond, isa.upper(), dirname, isa, basename)) 5303546Sgblack@eecs.umich.edu cond = '#elif' 5313546Sgblack@eecs.umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 5323546Sgblack@eecs.umich.edu f.close() 5333546Sgblack@eecs.umich.edu return 0 5343546Sgblack@eecs.umich.edu 5353546Sgblack@eecs.umich.edu # String to print when generating header 5363546Sgblack@eecs.umich.edu def gen_switch_hdr_string(target, source, env): 5373546Sgblack@eecs.umich.edu return "Generating switch header " + str(target[0]) 5383546Sgblack@eecs.umich.edu 5393546Sgblack@eecs.umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 5403546Sgblack@eecs.umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 5413546Sgblack@eecs.umich.edu # should get re-executed. 5423546Sgblack@eecs.umich.edu switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 5433546Sgblack@eecs.umich.edu varlist=['ALL_ISA_LIST']) 5443546Sgblack@eecs.umich.edu 5453546Sgblack@eecs.umich.edu # Instantiate actions for each header 5463546Sgblack@eecs.umich.edu for hdr in switch_headers: 5473546Sgblack@eecs.umich.edu env.Command(hdr, [], switch_hdr_action) 5483546Sgblack@eecs.umich.edu 5493546Sgblack@eecs.umich.eduenv.make_switching_dir = make_switching_dir 5503546Sgblack@eecs.umich.edu 5513546Sgblack@eecs.umich.edu################################################### 5523546Sgblack@eecs.umich.edu# 553955SN/A# Define build environments for selected configurations. 554955SN/A# 555955SN/A################################################### 556955SN/A 5571858SN/A# rename base env 5581858SN/Abase_env = env 5591858SN/A 5602632Sstever@eecs.umich.edufor build_path in build_paths: 5612632Sstever@eecs.umich.edu print "Building in", build_path 5622632Sstever@eecs.umich.edu # build_dir is the tail component of build path, and is used to 5632632Sstever@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 5642632Sstever@eecs.umich.edu (build_root, build_dir) = os.path.split(build_path) 5652634Sstever@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 5662638Sstever@eecs.umich.edu env = base_env.Copy() 5672023SN/A 5682632Sstever@eecs.umich.edu # Set env options according to the build directory config. 5692632Sstever@eecs.umich.edu sticky_opts.files = [] 5702632Sstever@eecs.umich.edu # Options for $BUILD_ROOT/$BUILD_DIR are stored in 5712632Sstever@eecs.umich.edu # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 5722632Sstever@eecs.umich.edu # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 5733716Sstever@eecs.umich.edu current_opts_file = joinpath(build_root, 'options', build_dir) 5742632Sstever@eecs.umich.edu if os.path.isfile(current_opts_file): 5752632Sstever@eecs.umich.edu sticky_opts.files.append(current_opts_file) 5762632Sstever@eecs.umich.edu print "Using saved options file %s" % current_opts_file 5772632Sstever@eecs.umich.edu else: 5782632Sstever@eecs.umich.edu # Build dir-specific options file doesn't exist. 5792023SN/A 5802632Sstever@eecs.umich.edu # Make sure the directory is there so we can create it later 5812632Sstever@eecs.umich.edu opt_dir = os.path.dirname(current_opts_file) 5821889SN/A if not os.path.isdir(opt_dir): 5831889SN/A os.mkdir(opt_dir) 5842632Sstever@eecs.umich.edu 5852632Sstever@eecs.umich.edu # Get default build options from source tree. Options are 5862632Sstever@eecs.umich.edu # normally determined by name of $BUILD_DIR, but can be 5872632Sstever@eecs.umich.edu # overriden by 'default=' arg on command line. 5883716Sstever@eecs.umich.edu default_opts_file = joinpath('build_opts', 5893716Sstever@eecs.umich.edu ARGUMENTS.get('default', build_dir)) 5902632Sstever@eecs.umich.edu if os.path.isfile(default_opts_file): 5912632Sstever@eecs.umich.edu sticky_opts.files.append(default_opts_file) 5922632Sstever@eecs.umich.edu print "Options file %s not found,\n using defaults in %s" \ 5932632Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 5942632Sstever@eecs.umich.edu else: 5952632Sstever@eecs.umich.edu print "Error: cannot find options file %s or %s" \ 5962632Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 5972632Sstever@eecs.umich.edu Exit(1) 5981888SN/A 5991888SN/A # Apply current option settings to env 6001869SN/A sticky_opts.Update(env) 6011869SN/A nonsticky_opts.Update(env) 6021858SN/A 6032598SN/A help_text += "Sticky options for %s:\n" % build_dir \ 6042598SN/A + sticky_opts.GenerateHelpText(env) \ 6052598SN/A + "\nNon-sticky options for %s:\n" % build_dir \ 6062598SN/A + nonsticky_opts.GenerateHelpText(env) 6072598SN/A 6081858SN/A # Process option settings. 6091858SN/A 6101858SN/A if not have_fenv and env['USE_FENV']: 6111858SN/A print "Warning: <fenv.h> not available; " \ 6121858SN/A "forcing USE_FENV to False in", build_dir + "." 6131858SN/A env['USE_FENV'] = False 6141858SN/A 6151858SN/A if not env['USE_FENV']: 6161858SN/A print "Warning: No IEEE FP rounding mode control in", build_dir + "." 6171871SN/A print " FP results may deviate slightly from other platforms." 6181858SN/A 6191858SN/A if env['EFENCE']: 6201858SN/A env.Append(LIBS=['efence']) 6211858SN/A 6221858SN/A if env['USE_MYSQL']: 6231858SN/A if not have_mysql: 6241858SN/A print "Warning: MySQL not available; " \ 6251858SN/A "forcing USE_MYSQL to False in", build_dir + "." 6261858SN/A env['USE_MYSQL'] = False 6271858SN/A else: 6281858SN/A print "Compiling in", build_dir, "with MySQL support." 6291859SN/A env.ParseConfig(mysql_config_libs) 6301859SN/A env.ParseConfig(mysql_config_include) 6311869SN/A 6321888SN/A # Save sticky option settings back to current options file 6332632Sstever@eecs.umich.edu sticky_opts.Save(current_opts_file, env) 6341869SN/A 6351884SN/A # Do this after we save setting back, or else we'll tack on an 6361884SN/A # extra 'qdo' every time we run scons. 6371884SN/A if env['BATCH']: 6381884SN/A env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 6391884SN/A env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 6401884SN/A 6411965SN/A if env['USE_SSE2']: 6421965SN/A env.Append(CCFLAGS='-msse2') 6431965SN/A 6442761Sstever@eecs.umich.edu # The src/SConscript file sets up the build rules in 'env' according 6451869SN/A # to the configured options. It returns a list of environments, 6461869SN/A # one for each variant build (debug, opt, etc.) 6472632Sstever@eecs.umich.edu envList = SConscript('src/SConscript', build_dir = build_path, 6482667Sstever@eecs.umich.edu exports = 'env') 6491869SN/A 6501869SN/A # Set up the regression tests for each build. 6512929Sktlim@umich.edu for e in envList: 6522929Sktlim@umich.edu SConscript('tests/SConscript', 6533716Sstever@eecs.umich.edu build_dir = joinpath(build_path, 'tests', e.Label), 6542929Sktlim@umich.edu exports = { 'env' : e }, duplicate = False) 655955SN/A 6562598SN/AHelp(help_text) 6572598SN/A 6583546Sgblack@eecs.umich.edu 659955SN/A################################################### 660955SN/A# 661955SN/A# Let SCons do its thing. At this point SCons will use the defined 6621530SN/A# build environments to build the requested targets. 663955SN/A# 664955SN/A################################################### 665955SN/A 666