SConstruct revision 5200:9cfaa7c2f766
14680Sgblack@eecs.umich.edu# -*- mode:python -*- 25442Sgblack@eecs.umich.edu 34680Sgblack@eecs.umich.edu# Copyright (c) 2004-2005 The Regents of The University of Michigan 44680Sgblack@eecs.umich.edu# All rights reserved. 54680Sgblack@eecs.umich.edu# 64680Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 74680Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 84680Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 94680Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 104680Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 114680Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 124680Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 134680Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 144680Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 154680Sgblack@eecs.umich.edu# this software without specific prior written permission. 164680Sgblack@eecs.umich.edu# 174680Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 184680Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 194680Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 204680Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 214680Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 224680Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234680Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 244680Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 254680Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 264680Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 274680Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284680Sgblack@eecs.umich.edu# 294680Sgblack@eecs.umich.edu# Authors: Steve Reinhardt 304680Sgblack@eecs.umich.edu 314680Sgblack@eecs.umich.edu################################################### 324680Sgblack@eecs.umich.edu# 334680Sgblack@eecs.umich.edu# SCons top-level build description (SConstruct) file. 344680Sgblack@eecs.umich.edu# 354680Sgblack@eecs.umich.edu# While in this directory ('m5'), just type 'scons' to build the default 364680Sgblack@eecs.umich.edu# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 375543Ssaidi@eecs.umich.edu# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 384680Sgblack@eecs.umich.edu# the optimized full-system version). 394680Sgblack@eecs.umich.edu# 404680Sgblack@eecs.umich.edu# You can build M5 in a different directory as long as there is a 414680Sgblack@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 424680Sgblack@eecs.umich.edu# expects that all configs under the same build directory are being 434680Sgblack@eecs.umich.edu# built for the same host system. 444680Sgblack@eecs.umich.edu# 454680Sgblack@eecs.umich.edu# Examples: 464680Sgblack@eecs.umich.edu# 474680Sgblack@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 484680Sgblack@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 494680Sgblack@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 504680Sgblack@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 514680Sgblack@eecs.umich.edu# 524680Sgblack@eecs.umich.edu# The following two commands are equivalent and demonstrate building 534680Sgblack@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 544680Sgblack@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 554680Sgblack@eecs.umich.edu# file. 564680Sgblack@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 574680Sgblack@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 584680Sgblack@eecs.umich.edu# 594680Sgblack@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 604680Sgblack@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 614680Sgblack@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 624680Sgblack@eecs.umich.edu# options as well. 634680Sgblack@eecs.umich.edu# 644680Sgblack@eecs.umich.edu################################################### 654680Sgblack@eecs.umich.edu 664680Sgblack@eecs.umich.eduimport sys 674680Sgblack@eecs.umich.eduimport os 684680Sgblack@eecs.umich.eduimport subprocess 694680Sgblack@eecs.umich.edu 704680Sgblack@eecs.umich.edufrom os.path import isdir, join as joinpath 714680Sgblack@eecs.umich.edu 724680Sgblack@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 734680Sgblack@eecs.umich.edu# default installation of Python is not recent enough, you can use a 744680Sgblack@eecs.umich.edu# non-default installation of the Python interpreter by either (1) 754680Sgblack@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 764680Sgblack@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 774680Sgblack@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 784680Sgblack@eecs.umich.eduEnsurePythonVersion(2,4) 794680Sgblack@eecs.umich.edu 804680Sgblack@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 814680Sgblack@eecs.umich.edu# 3-element version number. 824680Sgblack@eecs.umich.edumin_scons_version = (0,96,91) 834680Sgblack@eecs.umich.edutry: 844680Sgblack@eecs.umich.edu EnsureSConsVersion(*min_scons_version) 854680Sgblack@eecs.umich.eduexcept: 864680Sgblack@eecs.umich.edu print "Error checking current SCons version." 874680Sgblack@eecs.umich.edu print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 884680Sgblack@eecs.umich.edu Exit(2) 894680Sgblack@eecs.umich.edu 904680Sgblack@eecs.umich.edu 914680Sgblack@eecs.umich.edu# The absolute path to the current directory (where this file lives). 924680Sgblack@eecs.umich.eduROOT = Dir('.').abspath 934680Sgblack@eecs.umich.edu 944680Sgblack@eecs.umich.edu# Path to the M5 source tree. 954680Sgblack@eecs.umich.eduSRCDIR = joinpath(ROOT, 'src') 964680Sgblack@eecs.umich.edu 974680Sgblack@eecs.umich.edu# tell python where to find m5 python code 984680Sgblack@eecs.umich.edusys.path.append(joinpath(ROOT, 'src/python')) 994680Sgblack@eecs.umich.edu 1004680Sgblack@eecs.umich.edudef check_style_hook(ui): 1014680Sgblack@eecs.umich.edu ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 1024680Sgblack@eecs.umich.edu style_hook = ui.config('hooks', 'pretxncommit.style', None) 1034680Sgblack@eecs.umich.edu 1044680Sgblack@eecs.umich.edu if not style_hook: 1054680Sgblack@eecs.umich.edu print """\ 1064680Sgblack@eecs.umich.eduYou're missing the M5 style hook. 1074680Sgblack@eecs.umich.eduPlease install the hook so we can ensure that all code fits a common style. 1084680Sgblack@eecs.umich.edu 1094680Sgblack@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc 1104680Sgblack@eecs.umich.eduor your personal .hgrc 1114680Sgblack@eecs.umich.edu---------------- 1124680Sgblack@eecs.umich.edu 1134680Sgblack@eecs.umich.edu[extensions] 1144680Sgblack@eecs.umich.edustyle = %s/util/style.py 1154680Sgblack@eecs.umich.edu 1164680Sgblack@eecs.umich.edu[hooks] 1174680Sgblack@eecs.umich.edupretxncommit.style = python:style.check_whitespace 1184680Sgblack@eecs.umich.edu""" % (ROOT) 1194680Sgblack@eecs.umich.edu sys.exit(1) 1204680Sgblack@eecs.umich.edu 1214680Sgblack@eecs.umich.eduif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1224680Sgblack@eecs.umich.edu try: 1234680Sgblack@eecs.umich.edu from mercurial import ui 1244680Sgblack@eecs.umich.edu check_style_hook(ui.ui()) 1254680Sgblack@eecs.umich.edu except ImportError: 1264680Sgblack@eecs.umich.edu pass 1274680Sgblack@eecs.umich.edu 1284680Sgblack@eecs.umich.edu################################################### 1294680Sgblack@eecs.umich.edu# 1304680Sgblack@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 1314680Sgblack@eecs.umich.edu# the target(s). 1324680Sgblack@eecs.umich.edu# 1334680Sgblack@eecs.umich.edu################################################### 1344680Sgblack@eecs.umich.edu 1354680Sgblack@eecs.umich.edu# Find default configuration & binary. 1364680Sgblack@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1374680Sgblack@eecs.umich.edu 1384680Sgblack@eecs.umich.edu# helper function: find last occurrence of element in list 1394680Sgblack@eecs.umich.edudef rfind(l, elt, offs = -1): 1404680Sgblack@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 1414680Sgblack@eecs.umich.edu if l[i] == elt: 1424680Sgblack@eecs.umich.edu return i 1434680Sgblack@eecs.umich.edu raise ValueError, "element not found" 1444680Sgblack@eecs.umich.edu 1454680Sgblack@eecs.umich.edu# helper function: compare dotted version numbers. 1464680Sgblack@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1') 1474680Sgblack@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1484680Sgblack@eecs.umich.edudef compare_versions(v1, v2): 1494680Sgblack@eecs.umich.edu # Convert dotted strings to lists 1504680Sgblack@eecs.umich.edu v1 = map(int, v1.split('.')) 1514680Sgblack@eecs.umich.edu v2 = map(int, v2.split('.')) 1524680Sgblack@eecs.umich.edu # Compare corresponding elements of lists 1534680Sgblack@eecs.umich.edu for n1,n2 in zip(v1, v2): 1544680Sgblack@eecs.umich.edu if n1 < n2: return -1 1554680Sgblack@eecs.umich.edu if n1 > n2: return 1 1564680Sgblack@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1574680Sgblack@eecs.umich.edu if len(v1) < len(v2): return -1 1584680Sgblack@eecs.umich.edu if len(v1) > len(v2): return 1 1594680Sgblack@eecs.umich.edu return 0 1604680Sgblack@eecs.umich.edu 1614680Sgblack@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 1624680Sgblack@eecs.umich.edu# directory below this will determine the build parameters. For 1634680Sgblack@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1644680Sgblack@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 1654680Sgblack@eecs.umich.edu# follow 'build' in the bulid path. 1664680Sgblack@eecs.umich.edu 1674680Sgblack@eecs.umich.edu# Generate absolute paths to targets so we can see where the build dir is 1684680Sgblack@eecs.umich.eduif COMMAND_LINE_TARGETS: 1694680Sgblack@eecs.umich.edu # Ask SCons which directory it was invoked from 1704680Sgblack@eecs.umich.edu launch_dir = GetLaunchDir() 1714680Sgblack@eecs.umich.edu # Make targets relative to invocation directory 1724680Sgblack@eecs.umich.edu abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 1734680Sgblack@eecs.umich.edu COMMAND_LINE_TARGETS) 1744680Sgblack@eecs.umich.eduelse: 1754680Sgblack@eecs.umich.edu # Default targets are relative to root of tree 1764680Sgblack@eecs.umich.edu abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 1774680Sgblack@eecs.umich.edu DEFAULT_TARGETS) 1784680Sgblack@eecs.umich.edu 1794680Sgblack@eecs.umich.edu 1804680Sgblack@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1814680Sgblack@eecs.umich.edu# collected targets reference. 1824680Sgblack@eecs.umich.edubuild_paths = [] 1834680Sgblack@eecs.umich.edubuild_root = None 1844680Sgblack@eecs.umich.edufor t in abs_targets: 1854680Sgblack@eecs.umich.edu path_dirs = t.split('/') 1864680Sgblack@eecs.umich.edu try: 1874680Sgblack@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 1884680Sgblack@eecs.umich.edu except: 1894680Sgblack@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 1904680Sgblack@eecs.umich.edu Exit(1) 1914680Sgblack@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 1924680Sgblack@eecs.umich.edu if not build_root: 1934680Sgblack@eecs.umich.edu build_root = this_build_root 1944680Sgblack@eecs.umich.edu else: 1954680Sgblack@eecs.umich.edu if this_build_root != build_root: 1965136Sgblack@eecs.umich.edu print "Error: build targets not under same build root\n"\ 1974681Sgblack@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 1984681Sgblack@eecs.umich.edu Exit(1) 1994681Sgblack@eecs.umich.edu build_path = joinpath('/',*path_dirs[:build_top+2]) 2004681Sgblack@eecs.umich.edu if build_path not in build_paths: 2014681Sgblack@eecs.umich.edu build_paths.append(build_path) 2024681Sgblack@eecs.umich.edu 2034680Sgblack@eecs.umich.edu################################################### 2044680Sgblack@eecs.umich.edu# 2054680Sgblack@eecs.umich.edu# Set up the default build environment. This environment is copied 2064680Sgblack@eecs.umich.edu# and modified according to each selected configuration. 2074680Sgblack@eecs.umich.edu# 2084680Sgblack@eecs.umich.edu################################################### 2095136Sgblack@eecs.umich.edu 2104680Sgblack@eecs.umich.eduenv = Environment(ENV = os.environ, # inherit user's environment vars 2114680Sgblack@eecs.umich.edu ROOT = ROOT, 2124680Sgblack@eecs.umich.edu SRCDIR = SRCDIR) 2134680Sgblack@eecs.umich.edu 2144680Sgblack@eecs.umich.edu#Parse CC/CXX early so that we use the correct compiler for 2154680Sgblack@eecs.umich.edu# to test for dependencies/versions/libraries/includes 2165136Sgblack@eecs.umich.eduif ARGUMENTS.get('CC', None): 2174680Sgblack@eecs.umich.edu env['CC'] = ARGUMENTS.get('CC') 2184680Sgblack@eecs.umich.edu 2194680Sgblack@eecs.umich.eduif ARGUMENTS.get('CXX', None): 2204680Sgblack@eecs.umich.edu env['CXX'] = ARGUMENTS.get('CXX') 2214680Sgblack@eecs.umich.edu 2225136Sgblack@eecs.umich.eduExport('env') 2234680Sgblack@eecs.umich.edu 2244680Sgblack@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign")) 2254680Sgblack@eecs.umich.edu 2264680Sgblack@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 2274680Sgblack@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 2284680Sgblack@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2294680Sgblack@eecs.umich.edu# (soft) links work better. 2304680Sgblack@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 2314680Sgblack@eecs.umich.edu 2324680Sgblack@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but 2334680Sgblack@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 2344680Sgblack@eecs.umich.edu# noticeably longer. 2354680Sgblack@eecs.umich.eduif False: 2364680Sgblack@eecs.umich.edu env.TargetSignatures('content') 2374680Sgblack@eecs.umich.edu 2384680Sgblack@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 2394680Sgblack@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 2404680Sgblack@eecs.umich.eduenv['GCC'] = False 2414680Sgblack@eecs.umich.eduenv['SUNCC'] = False 2424680Sgblack@eecs.umich.eduenv['ICC'] = False 2434680Sgblack@eecs.umich.eduenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 2444680Sgblack@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2455442Sgblack@eecs.umich.edu close_fds=True).communicate()[0].find('GCC') >= 0 2464680Sgblack@eecs.umich.eduenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 2474680Sgblack@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2484680Sgblack@eecs.umich.edu close_fds=True).communicate()[0].find('Sun C++') >= 0 2494680Sgblack@eecs.umich.eduenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 2504680Sgblack@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2514680Sgblack@eecs.umich.edu close_fds=True).communicate()[0].find('Intel') >= 0 2524680Sgblack@eecs.umich.eduif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 2534680Sgblack@eecs.umich.edu print 'Error: How can we have two at the same time?' 2544680Sgblack@eecs.umich.edu Exit(1) 2554680Sgblack@eecs.umich.edu 2564680Sgblack@eecs.umich.edu 2574680Sgblack@eecs.umich.edu# Set up default C++ compiler flags 2584680Sgblack@eecs.umich.eduif env['GCC']: 2594680Sgblack@eecs.umich.edu env.Append(CCFLAGS='-pipe') 2604680Sgblack@eecs.umich.edu env.Append(CCFLAGS='-fno-strict-aliasing') 2615442Sgblack@eecs.umich.edu env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2625442Sgblack@eecs.umich.eduelif env['ICC']: 2634680Sgblack@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 2644680Sgblack@eecs.umich.eduelif env['SUNCC']: 2654680Sgblack@eecs.umich.edu env.Append(CCFLAGS='-Qoption ccfe') 2664680Sgblack@eecs.umich.edu env.Append(CCFLAGS='-features=gcc') 2674680Sgblack@eecs.umich.edu env.Append(CCFLAGS='-features=extensions') 2684680Sgblack@eecs.umich.edu env.Append(CCFLAGS='-library=stlport4') 2694680Sgblack@eecs.umich.edu env.Append(CCFLAGS='-xar') 2704680Sgblack@eecs.umich.edu# env.Append(CCFLAGS='-instances=semiexplicit') 2714680Sgblack@eecs.umich.eduelse: 2724680Sgblack@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 2734680Sgblack@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 2744680Sgblack@eecs.umich.edu Exit(1) 2754680Sgblack@eecs.umich.edu 2764680Sgblack@eecs.umich.eduif sys.platform == 'cygwin': 2774680Sgblack@eecs.umich.edu # cygwin has some header file issues... 2784680Sgblack@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2794680Sgblack@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 2804680Sgblack@eecs.umich.edu 2814680Sgblack@eecs.umich.edu# Check for SWIG 2824680Sgblack@eecs.umich.eduif not env.has_key('SWIG'): 2834680Sgblack@eecs.umich.edu print 'Error: SWIG utility not found.' 2844680Sgblack@eecs.umich.edu print ' Please install (see http://www.swig.org) and retry.' 2854680Sgblack@eecs.umich.edu Exit(1) 2864680Sgblack@eecs.umich.edu 2874698Sgblack@eecs.umich.edu# Check for appropriate SWIG version 2884680Sgblack@eecs.umich.eduswig_version = os.popen('swig -version').read().split() 2894680Sgblack@eecs.umich.edu# First 3 words should be "SWIG Version x.y.z" 2904680Sgblack@eecs.umich.eduif len(swig_version) < 3 or \ 2914680Sgblack@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2924680Sgblack@eecs.umich.edu print 'Error determining SWIG version.' 2934680Sgblack@eecs.umich.edu Exit(1) 2944680Sgblack@eecs.umich.edu 2954680Sgblack@eecs.umich.edumin_swig_version = '1.3.28' 2964680Sgblack@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 2974680Sgblack@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 2984680Sgblack@eecs.umich.edu print ' Installed version:', swig_version[2] 2994680Sgblack@eecs.umich.edu Exit(1) 3004680Sgblack@eecs.umich.edu 3014680Sgblack@eecs.umich.edu# Set up SWIG flags & scanner 3024680Sgblack@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 3034680Sgblack@eecs.umich.eduenv.Append(SWIGFLAGS=swig_flags) 3044680Sgblack@eecs.umich.edu 3054680Sgblack@eecs.umich.edu# filter out all existing swig scanners, they mess up the dependency 3064680Sgblack@eecs.umich.edu# stuff for some reason 3074680Sgblack@eecs.umich.eduscanners = [] 3084680Sgblack@eecs.umich.edufor scanner in env['SCANNERS']: 3094680Sgblack@eecs.umich.edu skeys = scanner.skeys 310 if skeys == '.i': 311 continue 312 313 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 314 continue 315 316 scanners.append(scanner) 317 318# add the new swig scanner that we like better 319from SCons.Scanner import ClassicCPP as CPPScanner 320swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 321scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 322 323# replace the scanners list that has what we want 324env['SCANNERS'] = scanners 325 326# Platform-specific configuration. Note again that we assume that all 327# builds under a given build root run on the same host platform. 328conf = Configure(env, 329 conf_dir = joinpath(build_root, '.scons_config'), 330 log_file = joinpath(build_root, 'scons_config.log')) 331 332# Find Python include and library directories for embedding the 333# interpreter. For consistency, we will use the same Python 334# installation used to run scons (and thus this script). If you want 335# to link in an alternate version, see above for instructions on how 336# to invoke scons with a different copy of the Python interpreter. 337 338# Get brief Python version name (e.g., "python2.4") for locating 339# include & library files 340py_version_name = 'python' + sys.version[:3] 341 342# include path, e.g. /usr/local/include/python2.4 343py_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 344env.Append(CPPPATH = py_header_path) 345# verify that it works 346if not conf.CheckHeader('Python.h', '<>'): 347 print "Error: can't find Python.h header in", py_header_path 348 Exit(1) 349 350# add library path too if it's not in the default place 351py_lib_path = None 352if sys.exec_prefix != '/usr': 353 py_lib_path = joinpath(sys.exec_prefix, 'lib') 354elif sys.platform == 'cygwin': 355 # cygwin puts the .dll in /bin for some reason 356 py_lib_path = '/bin' 357if py_lib_path: 358 env.Append(LIBPATH = py_lib_path) 359 print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 360if not conf.CheckLib(py_version_name): 361 print "Error: can't find Python library", py_version_name 362 Exit(1) 363 364# On Solaris you need to use libsocket for socket ops 365if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 366 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 367 print "Can't find library with socket calls (e.g. accept())" 368 Exit(1) 369 370# Check for zlib. If the check passes, libz will be automatically 371# added to the LIBS environment variable. 372if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 373 print 'Error: did not find needed zlib compression library '\ 374 'and/or zlib.h header file.' 375 print ' Please install zlib and try again.' 376 Exit(1) 377 378# Check for <fenv.h> (C99 FP environment control) 379have_fenv = conf.CheckHeader('fenv.h', '<>') 380if not have_fenv: 381 print "Warning: Header file <fenv.h> not found." 382 print " This host has no IEEE FP rounding mode control." 383 384# Check for mysql. 385mysql_config = WhereIs('mysql_config') 386have_mysql = mysql_config != None 387 388# Check MySQL version. 389if have_mysql: 390 mysql_version = os.popen(mysql_config + ' --version').read() 391 min_mysql_version = '4.1' 392 if compare_versions(mysql_version, min_mysql_version) < 0: 393 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 394 print ' Version', mysql_version, 'detected.' 395 have_mysql = False 396 397# Set up mysql_config commands. 398if have_mysql: 399 mysql_config_include = mysql_config + ' --include' 400 if os.system(mysql_config_include + ' > /dev/null') != 0: 401 # older mysql_config versions don't support --include, use 402 # --cflags instead 403 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 404 # This seems to work in all versions 405 mysql_config_libs = mysql_config + ' --libs' 406 407env = conf.Finish() 408 409# Define the universe of supported ISAs 410all_isa_list = [ ] 411Export('all_isa_list') 412 413# Define the universe of supported CPU models 414all_cpu_list = [ ] 415default_cpus = [ ] 416Export('all_cpu_list', 'default_cpus') 417 418# Sticky options get saved in the options file so they persist from 419# one invocation to the next (unless overridden, in which case the new 420# value becomes sticky). 421sticky_opts = Options(args=ARGUMENTS) 422Export('sticky_opts') 423 424# Non-sticky options only apply to the current build. 425nonsticky_opts = Options(args=ARGUMENTS) 426Export('nonsticky_opts') 427 428# Walk the tree and execute all SConsopts scripts that wil add to the 429# above options 430for root, dirs, files in os.walk('.'): 431 if 'SConsopts' in files: 432 SConscript(os.path.join(root, 'SConsopts')) 433 434all_isa_list.sort() 435all_cpu_list.sort() 436default_cpus.sort() 437 438def ExtraPathValidator(key, val, env): 439 if not val: 440 return 441 paths = val.split(':') 442 for path in paths: 443 path = os.path.expanduser(path) 444 if not isdir(path): 445 raise AttributeError, "Invalid path: '%s'" % path 446 447sticky_opts.AddOptions( 448 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 449 BoolOption('FULL_SYSTEM', 'Full-system support', False), 450 # There's a bug in scons 0.96.1 that causes ListOptions with list 451 # values (more than one value) not to be able to be restored from 452 # a saved option file. If this causes trouble then upgrade to 453 # scons 0.96.90 or later. 454 ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 455 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 456 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 457 False), 458 BoolOption('SS_COMPATIBLE_FP', 459 'Make floating-point results compatible with SimpleScalar', 460 False), 461 BoolOption('USE_SSE2', 462 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 463 False), 464 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 465 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 466 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 467 ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 468 ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 469 BoolOption('BATCH', 'Use batch pool for build and tests', False), 470 ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 471 ('PYTHONHOME', 472 'Override the default PYTHONHOME for this system (use with caution)', 473 '%s:%s' % (sys.prefix, sys.exec_prefix)), 474 ('EXTRAS', 'Add Extra directories to the compilation', '', 475 ExtraPathValidator) 476 ) 477 478nonsticky_opts.AddOptions( 479 BoolOption('update_ref', 'Update test reference outputs', False) 480 ) 481 482# These options get exported to #defines in config/*.hh (see src/SConscript). 483env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 484 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 485 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 486 487# Define a handy 'no-op' action 488def no_action(target, source, env): 489 return 0 490 491env.NoAction = Action(no_action, None) 492 493################################################### 494# 495# Define a SCons builder for configuration flag headers. 496# 497################################################### 498 499# This function generates a config header file that #defines the 500# option symbol to the current option setting (0 or 1). The source 501# operands are the name of the option and a Value node containing the 502# value of the option. 503def build_config_file(target, source, env): 504 (option, value) = [s.get_contents() for s in source] 505 f = file(str(target[0]), 'w') 506 print >> f, '#define', option, value 507 f.close() 508 return None 509 510# Generate the message to be printed when building the config file. 511def build_config_file_string(target, source, env): 512 (option, value) = [s.get_contents() for s in source] 513 return "Defining %s as %s in %s." % (option, value, target[0]) 514 515# Combine the two functions into a scons Action object. 516config_action = Action(build_config_file, build_config_file_string) 517 518# The emitter munges the source & target node lists to reflect what 519# we're really doing. 520def config_emitter(target, source, env): 521 # extract option name from Builder arg 522 option = str(target[0]) 523 # True target is config header file 524 target = joinpath('config', option.lower() + '.hh') 525 val = env[option] 526 if isinstance(val, bool): 527 # Force value to 0/1 528 val = int(val) 529 elif isinstance(val, str): 530 val = '"' + val + '"' 531 532 # Sources are option name & value (packaged in SCons Value nodes) 533 return ([target], [Value(option), Value(val)]) 534 535config_builder = Builder(emitter = config_emitter, action = config_action) 536 537env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 538 539################################################### 540# 541# Define a SCons builder for copying files. This is used by the 542# Python zipfile code in src/python/SConscript, but is placed up here 543# since it's potentially more generally applicable. 544# 545################################################### 546 547copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 548 549env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 550 551################################################### 552# 553# Define a simple SCons builder to concatenate files. 554# 555# Used to append the Python zip archive to the executable. 556# 557################################################### 558 559concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 560 'chmod +x $TARGET'])) 561 562env.Append(BUILDERS = { 'Concat' : concat_builder }) 563 564 565# base help text 566help_text = ''' 567Usage: scons [scons options] [build options] [target(s)] 568 569''' 570 571# libelf build is shared across all configs in the build root. 572env.SConscript('ext/libelf/SConscript', 573 build_dir = joinpath(build_root, 'libelf'), 574 exports = 'env') 575 576################################################### 577# 578# This function is used to set up a directory with switching headers 579# 580################################################### 581 582env['ALL_ISA_LIST'] = all_isa_list 583def make_switching_dir(dirname, switch_headers, env): 584 # Generate the header. target[0] is the full path of the output 585 # header to generate. 'source' is a dummy variable, since we get the 586 # list of ISAs from env['ALL_ISA_LIST']. 587 def gen_switch_hdr(target, source, env): 588 fname = str(target[0]) 589 basename = os.path.basename(fname) 590 f = open(fname, 'w') 591 f.write('#include "arch/isa_specific.hh"\n') 592 cond = '#if' 593 for isa in all_isa_list: 594 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 595 % (cond, isa.upper(), dirname, isa, basename)) 596 cond = '#elif' 597 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 598 f.close() 599 return 0 600 601 # String to print when generating header 602 def gen_switch_hdr_string(target, source, env): 603 return "Generating switch header " + str(target[0]) 604 605 # Build SCons Action object. 'varlist' specifies env vars that this 606 # action depends on; when env['ALL_ISA_LIST'] changes these actions 607 # should get re-executed. 608 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 609 varlist=['ALL_ISA_LIST']) 610 611 # Instantiate actions for each header 612 for hdr in switch_headers: 613 env.Command(hdr, [], switch_hdr_action) 614Export('make_switching_dir') 615 616################################################### 617# 618# Define build environments for selected configurations. 619# 620################################################### 621 622# rename base env 623base_env = env 624 625for build_path in build_paths: 626 print "Building in", build_path 627 env['BUILDDIR'] = build_path 628 629 # build_dir is the tail component of build path, and is used to 630 # determine the build parameters (e.g., 'ALPHA_SE') 631 (build_root, build_dir) = os.path.split(build_path) 632 # Make a copy of the build-root environment to use for this config. 633 env = base_env.Copy() 634 635 # Set env options according to the build directory config. 636 sticky_opts.files = [] 637 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 638 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 639 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 640 current_opts_file = joinpath(build_root, 'options', build_dir) 641 if os.path.isfile(current_opts_file): 642 sticky_opts.files.append(current_opts_file) 643 print "Using saved options file %s" % current_opts_file 644 else: 645 # Build dir-specific options file doesn't exist. 646 647 # Make sure the directory is there so we can create it later 648 opt_dir = os.path.dirname(current_opts_file) 649 if not os.path.isdir(opt_dir): 650 os.mkdir(opt_dir) 651 652 # Get default build options from source tree. Options are 653 # normally determined by name of $BUILD_DIR, but can be 654 # overriden by 'default=' arg on command line. 655 default_opts_file = joinpath('build_opts', 656 ARGUMENTS.get('default', build_dir)) 657 if os.path.isfile(default_opts_file): 658 sticky_opts.files.append(default_opts_file) 659 print "Options file %s not found,\n using defaults in %s" \ 660 % (current_opts_file, default_opts_file) 661 else: 662 print "Error: cannot find options file %s or %s" \ 663 % (current_opts_file, default_opts_file) 664 Exit(1) 665 666 # Apply current option settings to env 667 sticky_opts.Update(env) 668 nonsticky_opts.Update(env) 669 670 help_text += "Sticky options for %s:\n" % build_dir \ 671 + sticky_opts.GenerateHelpText(env) \ 672 + "\nNon-sticky options for %s:\n" % build_dir \ 673 + nonsticky_opts.GenerateHelpText(env) 674 675 # Process option settings. 676 677 if not have_fenv and env['USE_FENV']: 678 print "Warning: <fenv.h> not available; " \ 679 "forcing USE_FENV to False in", build_dir + "." 680 env['USE_FENV'] = False 681 682 if not env['USE_FENV']: 683 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 684 print " FP results may deviate slightly from other platforms." 685 686 if env['EFENCE']: 687 env.Append(LIBS=['efence']) 688 689 if env['USE_MYSQL']: 690 if not have_mysql: 691 print "Warning: MySQL not available; " \ 692 "forcing USE_MYSQL to False in", build_dir + "." 693 env['USE_MYSQL'] = False 694 else: 695 print "Compiling in", build_dir, "with MySQL support." 696 env.ParseConfig(mysql_config_libs) 697 env.ParseConfig(mysql_config_include) 698 699 # Save sticky option settings back to current options file 700 sticky_opts.Save(current_opts_file, env) 701 702 # Do this after we save setting back, or else we'll tack on an 703 # extra 'qdo' every time we run scons. 704 if env['BATCH']: 705 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 706 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 707 708 if env['USE_SSE2']: 709 env.Append(CCFLAGS='-msse2') 710 711 # The src/SConscript file sets up the build rules in 'env' according 712 # to the configured options. It returns a list of environments, 713 # one for each variant build (debug, opt, etc.) 714 envList = SConscript('src/SConscript', build_dir = build_path, 715 exports = 'env') 716 717 # Set up the regression tests for each build. 718 for e in envList: 719 SConscript('tests/SConscript', 720 build_dir = joinpath(build_path, 'tests', e.Label), 721 exports = { 'env' : e }, duplicate = False) 722 723Help(help_text) 724 725 726################################################### 727# 728# Let SCons do its thing. At this point SCons will use the defined 729# build environments to build the requested targets. 730# 731################################################### 732 733