SConstruct revision 4742
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/Aimport sys 67955SN/Aimport os 683918Ssaidi@eecs.umich.eduimport subprocess 694202Sbinkertn@umich.edu 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 1944494Ssaidi@eecs.umich.eduExport('env') 1954494Ssaidi@eecs.umich.edu 1963716Sstever@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign")) 1971105SN/A 1982667Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 1992667Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 2002667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2012667Sstever@eecs.umich.edu# (soft) links work better. 2022667Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 2032667Sstever@eecs.umich.edu 2041869SN/A# I waffle on this setting... it does avoid a few painful but 2051869SN/A# unnecessary builds, but it also seems to make trivial builds take 2061869SN/A# noticeably longer. 2071869SN/Aif False: 2081869SN/A env.TargetSignatures('content') 2091065SN/A 2102632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 2112632Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : Dir('ext/ply') }) 2123918Ssaidi@eecs.umich.eduenv['GCC'] = False 2133918Ssaidi@eecs.umich.eduenv['SUNCC'] = False 2143940Ssaidi@eecs.umich.eduenv['ICC'] = False 2153918Ssaidi@eecs.umich.eduenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 2163918Ssaidi@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2173918Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('GCC') >= 0 2183918Ssaidi@eecs.umich.eduenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 2193918Ssaidi@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2203918Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('Sun C++') >= 0 2213940Ssaidi@eecs.umich.eduenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 2223940Ssaidi@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2233940Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('Intel') >= 0 2243942Ssaidi@eecs.umich.eduif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 2253940Ssaidi@eecs.umich.edu print 'Error: How can we have two at the same time?' 2263918Ssaidi@eecs.umich.edu Exit(1) 2273918Ssaidi@eecs.umich.edu 228955SN/A 2291858SN/A# Set up default C++ compiler flags 2303918Ssaidi@eecs.umich.eduif env['GCC']: 2313918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-pipe') 2323918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-fno-strict-aliasing') 2333918Ssaidi@eecs.umich.edu env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2343940Ssaidi@eecs.umich.eduelif env['ICC']: 2353940Ssaidi@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 2363918Ssaidi@eecs.umich.eduelif env['SUNCC']: 2373918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-Qoption ccfe') 2383918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-features=gcc') 2393918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-features=extensions') 2403918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-library=stlport4') 2413918Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-xar') 2423918Ssaidi@eecs.umich.edu# env.Append(CCFLAGS='-instances=semiexplicit') 2433918Ssaidi@eecs.umich.eduelse: 2443918Ssaidi@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 2453940Ssaidi@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 2463918Ssaidi@eecs.umich.edu Exit(1) 2473918Ssaidi@eecs.umich.edu 2481851SN/Aif sys.platform == 'cygwin': 2491851SN/A # cygwin has some header file issues... 2501858SN/A env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2512632Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 252955SN/A 2533053Sstever@eecs.umich.edu# Check for SWIG 2543053Sstever@eecs.umich.eduif not env.has_key('SWIG'): 2553053Sstever@eecs.umich.edu print 'Error: SWIG utility not found.' 2563053Sstever@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 2573053Sstever@eecs.umich.edu Exit(1) 2583053Sstever@eecs.umich.edu 2593053Sstever@eecs.umich.edu# Check for appropriate SWIG version 2603053Sstever@eecs.umich.eduswig_version = os.popen('swig -version').read().split() 2613053Sstever@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 2624742Sstever@eecs.umich.eduif len(swig_version) < 3 or \ 2634742Sstever@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2643053Sstever@eecs.umich.edu print 'Error determining SWIG version.' 2653053Sstever@eecs.umich.edu Exit(1) 2663053Sstever@eecs.umich.edu 2673053Sstever@eecs.umich.edumin_swig_version = '1.3.28' 2683053Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 2693053Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 2703053Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 2713053Sstever@eecs.umich.edu Exit(1) 2723053Sstever@eecs.umich.edu 2732667Sstever@eecs.umich.edu# Set up SWIG flags & scanner 2744554Sbinkertn@umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 2754554Sbinkertn@umich.eduenv.Append(SWIGFLAGS=swig_flags) 2762667Sstever@eecs.umich.edu 2774554Sbinkertn@umich.edu# filter out all existing swig scanners, they mess up the dependency 2784554Sbinkertn@umich.edu# stuff for some reason 2794554Sbinkertn@umich.eduscanners = [] 2804554Sbinkertn@umich.edufor scanner in env['SCANNERS']: 2814554Sbinkertn@umich.edu skeys = scanner.skeys 2824554Sbinkertn@umich.edu if skeys == '.i': 2834554Sbinkertn@umich.edu continue 2844554Sbinkertn@umich.edu 2854554Sbinkertn@umich.edu if isinstance(skeys, (list, tuple)) and '.i' in skeys: 2864554Sbinkertn@umich.edu continue 2872667Sstever@eecs.umich.edu 2884554Sbinkertn@umich.edu scanners.append(scanner) 2894554Sbinkertn@umich.edu 2904554Sbinkertn@umich.edu# add the new swig scanner that we like better 2914554Sbinkertn@umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 2922667Sstever@eecs.umich.eduswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 2934554Sbinkertn@umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 2942667Sstever@eecs.umich.edu 2954554Sbinkertn@umich.edu# replace the scanners list that has what we want 2964554Sbinkertn@umich.eduenv['SCANNERS'] = scanners 2972667Sstever@eecs.umich.edu 2982638Sstever@eecs.umich.edu# Platform-specific configuration. Note again that we assume that all 2992638Sstever@eecs.umich.edu# builds under a given build root run on the same host platform. 3002638Sstever@eecs.umich.educonf = Configure(env, 3013716Sstever@eecs.umich.edu conf_dir = joinpath(build_root, '.scons_config'), 3023716Sstever@eecs.umich.edu log_file = joinpath(build_root, 'scons_config.log')) 3031858SN/A 3043118Sstever@eecs.umich.edu# Find Python include and library directories for embedding the 3053118Sstever@eecs.umich.edu# interpreter. For consistency, we will use the same Python 3063118Sstever@eecs.umich.edu# installation used to run scons (and thus this script). If you want 3073118Sstever@eecs.umich.edu# to link in an alternate version, see above for instructions on how 3083118Sstever@eecs.umich.edu# to invoke scons with a different copy of the Python interpreter. 3093118Sstever@eecs.umich.edu 3103118Sstever@eecs.umich.edu# Get brief Python version name (e.g., "python2.4") for locating 3113118Sstever@eecs.umich.edu# include & library files 3123118Sstever@eecs.umich.edupy_version_name = 'python' + sys.version[:3] 3133118Sstever@eecs.umich.edu 3143118Sstever@eecs.umich.edu# include path, e.g. /usr/local/include/python2.4 3153716Sstever@eecs.umich.edupy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 3163118Sstever@eecs.umich.eduenv.Append(CPPPATH = py_header_path) 3173118Sstever@eecs.umich.edu# verify that it works 3183118Sstever@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 3193118Sstever@eecs.umich.edu print "Error: can't find Python.h header in", py_header_path 3203118Sstever@eecs.umich.edu Exit(1) 3213118Sstever@eecs.umich.edu 3223118Sstever@eecs.umich.edu# add library path too if it's not in the default place 3233118Sstever@eecs.umich.edupy_lib_path = None 3243118Sstever@eecs.umich.eduif sys.exec_prefix != '/usr': 3253716Sstever@eecs.umich.edu py_lib_path = joinpath(sys.exec_prefix, 'lib') 3263118Sstever@eecs.umich.eduelif sys.platform == 'cygwin': 3273118Sstever@eecs.umich.edu # cygwin puts the .dll in /bin for some reason 3283118Sstever@eecs.umich.edu py_lib_path = '/bin' 3293118Sstever@eecs.umich.eduif py_lib_path: 3303118Sstever@eecs.umich.edu env.Append(LIBPATH = py_lib_path) 3313118Sstever@eecs.umich.edu print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 3323118Sstever@eecs.umich.eduif not conf.CheckLib(py_version_name): 3333118Sstever@eecs.umich.edu print "Error: can't find Python library", py_version_name 3343118Sstever@eecs.umich.edu Exit(1) 3353118Sstever@eecs.umich.edu 3363483Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 3373494Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 3383494Ssaidi@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 3393483Ssaidi@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 3403483Ssaidi@eecs.umich.edu Exit(1) 3413483Ssaidi@eecs.umich.edu 3423053Sstever@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 3433053Sstever@eecs.umich.edu# added to the LIBS environment variable. 3443918Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 3453053Sstever@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 3463053Sstever@eecs.umich.edu 'and/or zlib.h header file.' 3473053Sstever@eecs.umich.edu print ' Please install zlib and try again.' 3483053Sstever@eecs.umich.edu Exit(1) 3493053Sstever@eecs.umich.edu 3501858SN/A# Check for <fenv.h> (C99 FP environment control) 3511858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 3521858SN/Aif not have_fenv: 3531858SN/A print "Warning: Header file <fenv.h> not found." 3541858SN/A print " This host has no IEEE FP rounding mode control." 3551858SN/A 3561859SN/A# Check for mysql. 3571858SN/Amysql_config = WhereIs('mysql_config') 3581858SN/Ahave_mysql = mysql_config != None 3591858SN/A 3601859SN/A# Check MySQL version. 3611859SN/Aif have_mysql: 3621862SN/A mysql_version = os.popen(mysql_config + ' --version').read() 3633053Sstever@eecs.umich.edu min_mysql_version = '4.1' 3643053Sstever@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 3653053Sstever@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 3663053Sstever@eecs.umich.edu print ' Version', mysql_version, 'detected.' 3671859SN/A have_mysql = False 3681859SN/A 3691859SN/A# Set up mysql_config commands. 3701859SN/Aif have_mysql: 3711859SN/A mysql_config_include = mysql_config + ' --include' 3721859SN/A if os.system(mysql_config_include + ' > /dev/null') != 0: 3731859SN/A # older mysql_config versions don't support --include, use 3741859SN/A # --cflags instead 3751862SN/A mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 3761859SN/A # This seems to work in all versions 3771859SN/A mysql_config_libs = mysql_config + ' --libs' 3781859SN/A 3791858SN/Aenv = conf.Finish() 3801858SN/A 3812139SN/A# Define the universe of supported ISAs 3824202Sbinkertn@umich.eduall_isa_list = [ ] 3834202Sbinkertn@umich.eduExport('all_isa_list') 3842139SN/A 3852155SN/A# Define the universe of supported CPU models 3864202Sbinkertn@umich.eduall_cpu_list = [ ] 3874202Sbinkertn@umich.edudefault_cpus = [ ] 3884202Sbinkertn@umich.eduExport('all_cpu_list', 'default_cpus') 3892155SN/A 3901869SN/A# Sticky options get saved in the options file so they persist from 3911869SN/A# one invocation to the next (unless overridden, in which case the new 3921869SN/A# value becomes sticky). 3931869SN/Asticky_opts = Options(args=ARGUMENTS) 3944202Sbinkertn@umich.eduExport('sticky_opts') 3954202Sbinkertn@umich.edu 3964202Sbinkertn@umich.edu# Non-sticky options only apply to the current build. 3974202Sbinkertn@umich.edunonsticky_opts = Options(args=ARGUMENTS) 3984202Sbinkertn@umich.eduExport('nonsticky_opts') 3994202Sbinkertn@umich.edu 4004202Sbinkertn@umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 4014202Sbinkertn@umich.edu# above options 4024202Sbinkertn@umich.edufor root, dirs, files in os.walk('.'): 4034202Sbinkertn@umich.edu if 'SConsopts' in files: 4044202Sbinkertn@umich.edu SConscript(os.path.join(root, 'SConsopts')) 4054202Sbinkertn@umich.edu 4064202Sbinkertn@umich.eduall_isa_list.sort() 4074202Sbinkertn@umich.eduall_cpu_list.sort() 4084202Sbinkertn@umich.edudefault_cpus.sort() 4094202Sbinkertn@umich.edu 4101869SN/Asticky_opts.AddOptions( 4114202Sbinkertn@umich.edu EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 4121869SN/A BoolOption('FULL_SYSTEM', 'Full-system support', False), 4132508SN/A # There's a bug in scons 0.96.1 that causes ListOptions with list 4142508SN/A # values (more than one value) not to be able to be restored from 4152508SN/A # a saved option file. If this causes trouble then upgrade to 4162508SN/A # scons 0.96.90 or later. 4174202Sbinkertn@umich.edu ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 4181869SN/A BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 4191869SN/A BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 4201869SN/A False), 4211869SN/A BoolOption('SS_COMPATIBLE_FP', 4221869SN/A 'Make floating-point results compatible with SimpleScalar', 4231869SN/A False), 4241965SN/A BoolOption('USE_SSE2', 4251965SN/A 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 4261965SN/A False), 4271869SN/A BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 4281869SN/A BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 4292733Sktlim@umich.edu BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 4301869SN/A ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 4311884SN/A ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 4321884SN/A BoolOption('BATCH', 'Use batch pool for build and tests', False), 4333356Sbinkertn@umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 4343356Sbinkertn@umich.edu ('PYTHONHOME', 4353356Sbinkertn@umich.edu 'Override the default PYTHONHOME for this system (use with caution)', 4363356Sbinkertn@umich.edu '%s:%s' % (sys.prefix, sys.exec_prefix)) 4371869SN/A ) 4381858SN/A 4391869SN/Anonsticky_opts.AddOptions( 4401869SN/A BoolOption('update_ref', 'Update test reference outputs', False) 4411869SN/A ) 4421858SN/A 4432761Sstever@eecs.umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript). 4441869SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 4452733Sktlim@umich.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 4463584Ssaidi@eecs.umich.edu 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 4471869SN/A 4481869SN/A# Define a handy 'no-op' action 4491869SN/Adef no_action(target, source, env): 4501869SN/A return 0 4511869SN/A 4521869SN/Aenv.NoAction = Action(no_action, None) 4531858SN/A 454955SN/A################################################### 455955SN/A# 4561869SN/A# Define a SCons builder for configuration flag headers. 4571869SN/A# 4581869SN/A################################################### 4591869SN/A 4601869SN/A# This function generates a config header file that #defines the 4611869SN/A# option symbol to the current option setting (0 or 1). The source 4621869SN/A# operands are the name of the option and a Value node containing the 4631869SN/A# value of the option. 4641869SN/Adef build_config_file(target, source, env): 4651869SN/A (option, value) = [s.get_contents() for s in source] 4661869SN/A f = file(str(target[0]), 'w') 4671869SN/A print >> f, '#define', option, value 4681869SN/A f.close() 4691869SN/A return None 4701869SN/A 4711869SN/A# Generate the message to be printed when building the config file. 4721869SN/Adef build_config_file_string(target, source, env): 4731869SN/A (option, value) = [s.get_contents() for s in source] 4741869SN/A return "Defining %s as %s in %s." % (option, value, target[0]) 4751869SN/A 4761869SN/A# Combine the two functions into a scons Action object. 4771869SN/Aconfig_action = Action(build_config_file, build_config_file_string) 4781869SN/A 4791869SN/A# The emitter munges the source & target node lists to reflect what 4801869SN/A# we're really doing. 4811869SN/Adef config_emitter(target, source, env): 4821869SN/A # extract option name from Builder arg 4831869SN/A option = str(target[0]) 4841869SN/A # True target is config header file 4853716Sstever@eecs.umich.edu target = joinpath('config', option.lower() + '.hh') 4863356Sbinkertn@umich.edu val = env[option] 4873356Sbinkertn@umich.edu if isinstance(val, bool): 4883356Sbinkertn@umich.edu # Force value to 0/1 4893356Sbinkertn@umich.edu val = int(val) 4903356Sbinkertn@umich.edu elif isinstance(val, str): 4913356Sbinkertn@umich.edu val = '"' + val + '"' 4923356Sbinkertn@umich.edu 4931869SN/A # Sources are option name & value (packaged in SCons Value nodes) 4941869SN/A return ([target], [Value(option), Value(val)]) 4951869SN/A 4961869SN/Aconfig_builder = Builder(emitter = config_emitter, action = config_action) 4971869SN/A 4981869SN/Aenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 4991869SN/A 5002655Sstever@eecs.umich.edu################################################### 5012655Sstever@eecs.umich.edu# 5022655Sstever@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 5032655Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here 5042655Sstever@eecs.umich.edu# since it's potentially more generally applicable. 5052655Sstever@eecs.umich.edu# 5062655Sstever@eecs.umich.edu################################################### 5072655Sstever@eecs.umich.edu 5082655Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 5092655Sstever@eecs.umich.edu 5102655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 5112655Sstever@eecs.umich.edu 5122655Sstever@eecs.umich.edu################################################### 5132655Sstever@eecs.umich.edu# 5142655Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files. 5152655Sstever@eecs.umich.edu# 5162655Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable. 5172655Sstever@eecs.umich.edu# 5182655Sstever@eecs.umich.edu################################################### 5192655Sstever@eecs.umich.edu 5202655Sstever@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 5212655Sstever@eecs.umich.edu 'chmod +x $TARGET'])) 5222655Sstever@eecs.umich.edu 5232655Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder }) 5242655Sstever@eecs.umich.edu 5252655Sstever@eecs.umich.edu 5262634Sstever@eecs.umich.edu# base help text 5272634Sstever@eecs.umich.eduhelp_text = ''' 5282634Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 5292634Sstever@eecs.umich.edu 5302634Sstever@eecs.umich.edu''' 5312634Sstever@eecs.umich.edu 5322638Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root. 5332638Sstever@eecs.umich.eduenv.SConscript('ext/libelf/SConscript', 5343716Sstever@eecs.umich.edu build_dir = joinpath(build_root, 'libelf'), 5352638Sstever@eecs.umich.edu exports = 'env') 5362638Sstever@eecs.umich.edu 5371869SN/A################################################### 5381869SN/A# 5393546Sgblack@eecs.umich.edu# This function is used to set up a directory with switching headers 5403546Sgblack@eecs.umich.edu# 5413546Sgblack@eecs.umich.edu################################################### 5423546Sgblack@eecs.umich.edu 5434202Sbinkertn@umich.eduenv['ALL_ISA_LIST'] = all_isa_list 5443546Sgblack@eecs.umich.edudef make_switching_dir(dirname, switch_headers, env): 5453546Sgblack@eecs.umich.edu # Generate the header. target[0] is the full path of the output 5463546Sgblack@eecs.umich.edu # header to generate. 'source' is a dummy variable, since we get the 5473546Sgblack@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 5483546Sgblack@eecs.umich.edu def gen_switch_hdr(target, source, env): 5493546Sgblack@eecs.umich.edu fname = str(target[0]) 5503546Sgblack@eecs.umich.edu basename = os.path.basename(fname) 5513546Sgblack@eecs.umich.edu f = open(fname, 'w') 5523546Sgblack@eecs.umich.edu f.write('#include "arch/isa_specific.hh"\n') 5533546Sgblack@eecs.umich.edu cond = '#if' 5544202Sbinkertn@umich.edu for isa in all_isa_list: 5553546Sgblack@eecs.umich.edu f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 5563546Sgblack@eecs.umich.edu % (cond, isa.upper(), dirname, isa, basename)) 5573546Sgblack@eecs.umich.edu cond = '#elif' 5583546Sgblack@eecs.umich.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 5593546Sgblack@eecs.umich.edu f.close() 5603546Sgblack@eecs.umich.edu return 0 5613546Sgblack@eecs.umich.edu 5623546Sgblack@eecs.umich.edu # String to print when generating header 5633546Sgblack@eecs.umich.edu def gen_switch_hdr_string(target, source, env): 5643546Sgblack@eecs.umich.edu return "Generating switch header " + str(target[0]) 5653546Sgblack@eecs.umich.edu 5663546Sgblack@eecs.umich.edu # Build SCons Action object. 'varlist' specifies env vars that this 5673546Sgblack@eecs.umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 5683546Sgblack@eecs.umich.edu # should get re-executed. 5693546Sgblack@eecs.umich.edu switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 5703546Sgblack@eecs.umich.edu varlist=['ALL_ISA_LIST']) 5713546Sgblack@eecs.umich.edu 5723546Sgblack@eecs.umich.edu # Instantiate actions for each header 5733546Sgblack@eecs.umich.edu for hdr in switch_headers: 5743546Sgblack@eecs.umich.edu env.Command(hdr, [], switch_hdr_action) 5754202Sbinkertn@umich.eduExport('make_switching_dir') 5763546Sgblack@eecs.umich.edu 5773546Sgblack@eecs.umich.edu################################################### 5783546Sgblack@eecs.umich.edu# 579955SN/A# Define build environments for selected configurations. 580955SN/A# 581955SN/A################################################### 582955SN/A 5831858SN/A# rename base env 5841858SN/Abase_env = env 5851858SN/A 5862632Sstever@eecs.umich.edufor build_path in build_paths: 5872632Sstever@eecs.umich.edu print "Building in", build_path 5882632Sstever@eecs.umich.edu # build_dir is the tail component of build path, and is used to 5892632Sstever@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 5902632Sstever@eecs.umich.edu (build_root, build_dir) = os.path.split(build_path) 5912634Sstever@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 5922638Sstever@eecs.umich.edu env = base_env.Copy() 5932023SN/A 5942632Sstever@eecs.umich.edu # Set env options according to the build directory config. 5952632Sstever@eecs.umich.edu sticky_opts.files = [] 5962632Sstever@eecs.umich.edu # Options for $BUILD_ROOT/$BUILD_DIR are stored in 5972632Sstever@eecs.umich.edu # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 5982632Sstever@eecs.umich.edu # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 5993716Sstever@eecs.umich.edu current_opts_file = joinpath(build_root, 'options', build_dir) 6002632Sstever@eecs.umich.edu if os.path.isfile(current_opts_file): 6012632Sstever@eecs.umich.edu sticky_opts.files.append(current_opts_file) 6022632Sstever@eecs.umich.edu print "Using saved options file %s" % current_opts_file 6032632Sstever@eecs.umich.edu else: 6042632Sstever@eecs.umich.edu # Build dir-specific options file doesn't exist. 6052023SN/A 6062632Sstever@eecs.umich.edu # Make sure the directory is there so we can create it later 6072632Sstever@eecs.umich.edu opt_dir = os.path.dirname(current_opts_file) 6081889SN/A if not os.path.isdir(opt_dir): 6091889SN/A os.mkdir(opt_dir) 6102632Sstever@eecs.umich.edu 6112632Sstever@eecs.umich.edu # Get default build options from source tree. Options are 6122632Sstever@eecs.umich.edu # normally determined by name of $BUILD_DIR, but can be 6132632Sstever@eecs.umich.edu # overriden by 'default=' arg on command line. 6143716Sstever@eecs.umich.edu default_opts_file = joinpath('build_opts', 6153716Sstever@eecs.umich.edu ARGUMENTS.get('default', build_dir)) 6162632Sstever@eecs.umich.edu if os.path.isfile(default_opts_file): 6172632Sstever@eecs.umich.edu sticky_opts.files.append(default_opts_file) 6182632Sstever@eecs.umich.edu print "Options file %s not found,\n using defaults in %s" \ 6192632Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 6202632Sstever@eecs.umich.edu else: 6212632Sstever@eecs.umich.edu print "Error: cannot find options file %s or %s" \ 6222632Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 6232632Sstever@eecs.umich.edu Exit(1) 6241888SN/A 6251888SN/A # Apply current option settings to env 6261869SN/A sticky_opts.Update(env) 6271869SN/A nonsticky_opts.Update(env) 6281858SN/A 6292598SN/A help_text += "Sticky options for %s:\n" % build_dir \ 6302598SN/A + sticky_opts.GenerateHelpText(env) \ 6312598SN/A + "\nNon-sticky options for %s:\n" % build_dir \ 6322598SN/A + nonsticky_opts.GenerateHelpText(env) 6332598SN/A 6341858SN/A # Process option settings. 6351858SN/A 6361858SN/A if not have_fenv and env['USE_FENV']: 6371858SN/A print "Warning: <fenv.h> not available; " \ 6381858SN/A "forcing USE_FENV to False in", build_dir + "." 6391858SN/A env['USE_FENV'] = False 6401858SN/A 6411858SN/A if not env['USE_FENV']: 6421858SN/A print "Warning: No IEEE FP rounding mode control in", build_dir + "." 6431871SN/A print " FP results may deviate slightly from other platforms." 6441858SN/A 6451858SN/A if env['EFENCE']: 6461858SN/A env.Append(LIBS=['efence']) 6471858SN/A 6481858SN/A if env['USE_MYSQL']: 6491858SN/A if not have_mysql: 6501858SN/A print "Warning: MySQL not available; " \ 6511858SN/A "forcing USE_MYSQL to False in", build_dir + "." 6521858SN/A env['USE_MYSQL'] = False 6531858SN/A else: 6541858SN/A print "Compiling in", build_dir, "with MySQL support." 6551859SN/A env.ParseConfig(mysql_config_libs) 6561859SN/A env.ParseConfig(mysql_config_include) 6571869SN/A 6581888SN/A # Save sticky option settings back to current options file 6592632Sstever@eecs.umich.edu sticky_opts.Save(current_opts_file, env) 6601869SN/A 6611884SN/A # Do this after we save setting back, or else we'll tack on an 6621884SN/A # extra 'qdo' every time we run scons. 6631884SN/A if env['BATCH']: 6641884SN/A env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 6651884SN/A env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 6661884SN/A 6671965SN/A if env['USE_SSE2']: 6681965SN/A env.Append(CCFLAGS='-msse2') 6691965SN/A 6702761Sstever@eecs.umich.edu # The src/SConscript file sets up the build rules in 'env' according 6711869SN/A # to the configured options. It returns a list of environments, 6721869SN/A # one for each variant build (debug, opt, etc.) 6732632Sstever@eecs.umich.edu envList = SConscript('src/SConscript', build_dir = build_path, 6742667Sstever@eecs.umich.edu exports = 'env') 6751869SN/A 6761869SN/A # Set up the regression tests for each build. 6772929Sktlim@umich.edu for e in envList: 6782929Sktlim@umich.edu SConscript('tests/SConscript', 6793716Sstever@eecs.umich.edu build_dir = joinpath(build_path, 'tests', e.Label), 6802929Sktlim@umich.edu exports = { 'env' : e }, duplicate = False) 681955SN/A 6822598SN/AHelp(help_text) 6832598SN/A 6843546Sgblack@eecs.umich.edu 685955SN/A################################################### 686955SN/A# 687955SN/A# Let SCons do its thing. At this point SCons will use the defined 6881530SN/A# build environments to build the requested targets. 689955SN/A# 690955SN/A################################################### 691955SN/A 692