SConstruct revision 5397:58e5b68f7095
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. 28955SN/A# 29955SN/A# Authors: Steve Reinhardt 30955SN/A 31955SN/A################################################### 32955SN/A# 332632Sstever@eecs.umich.edu# SCons top-level build description (SConstruct) file. 342632Sstever@eecs.umich.edu# 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>' 37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 382632Sstever@eecs.umich.edu# the optimized full-system version). 392632Sstever@eecs.umich.edu# 402632Sstever@eecs.umich.edu# You can build M5 in a different directory as long as there is a 412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 422632Sstever@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: 462632Sstever@eecs.umich.edu# 472632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 482632Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 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 512632Sstever@eecs.umich.edu# 522632Sstever@eecs.umich.edu# The following two commands are equivalent and demonstrate building 532632Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 542632Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 552632Sstever@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 58955SN/A# 59955SN/A# You can use 'scons -H' to print scons options. If you're in this 60955SN/A# 'm5' directory (or use -u or -C to tell scons where to find this 61955SN/A# file), you can use 'scons -h' to print all the M5-specific build 62955SN/A# options as well. 63955SN/A# 64955SN/A################################################### 651858SN/A 661858SN/Aimport sys 672632Sstever@eecs.umich.eduimport os 681852SN/Aimport re 69955SN/A 70955SN/Afrom os.path import isdir, isfile, join as joinpath 71955SN/A 722632Sstever@eecs.umich.eduimport SCons 732632Sstever@eecs.umich.edu 74955SN/A# Check for recent-enough Python and SCons versions. If your system's 751533SN/A# default installation of Python is not recent enough, you can use a 762632Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1) 771533SN/A# rearranging your PATH so that scons finds the non-default 'python' 78955SN/A# first or (2) explicitly invoking an alternative interpreter on the 79955SN/A# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 802632Sstever@eecs.umich.eduEnsurePythonVersion(2,4) 812632Sstever@eecs.umich.edu 82955SN/A# Import subprocess after we check the version since it doesn't exist in 83955SN/A# Python < 2.4. 84955SN/Aimport subprocess 85955SN/A 862632Sstever@eecs.umich.edu# helper function: compare arrays or strings of version numbers. 87955SN/A# E.g., compare_version((1,3,25), (1,4,1)') 882632Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 89955SN/Adef compare_versions(v1, v2): 90955SN/A def make_version_list(v): 912632Sstever@eecs.umich.edu if isinstance(v, (list,tuple)): 922632Sstever@eecs.umich.edu return v 932632Sstever@eecs.umich.edu elif isinstance(v, str): 942632Sstever@eecs.umich.edu return map(int, v.split('.')) 952632Sstever@eecs.umich.edu else: 962632Sstever@eecs.umich.edu raise TypeError 972632Sstever@eecs.umich.edu 982632Sstever@eecs.umich.edu v1 = make_version_list(v1) 992632Sstever@eecs.umich.edu v2 = make_version_list(v2) 1002632Sstever@eecs.umich.edu # Compare corresponding elements of lists 1012632Sstever@eecs.umich.edu for n1,n2 in zip(v1, v2): 1022632Sstever@eecs.umich.edu if n1 < n2: return -1 1032632Sstever@eecs.umich.edu if n1 > n2: return 1 1042632Sstever@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1052632Sstever@eecs.umich.edu if len(v1) < len(v2): return -1 1062632Sstever@eecs.umich.edu if len(v1) > len(v2): return 1 1072632Sstever@eecs.umich.edu return 0 1082632Sstever@eecs.umich.edu 1092632Sstever@eecs.umich.edu# SCons version numbers need special processing because they can have 1102632Sstever@eecs.umich.edu# charecters and an release date embedded in them. This function does 1112632Sstever@eecs.umich.edu# the magic to extract them in a similar way to the SCons internal function 1122632Sstever@eecs.umich.edu# function does and then checks that the current version is not contained in 1132632Sstever@eecs.umich.edu# a list of version tuples (bad_ver_strs) 1142632Sstever@eecs.umich.edudef CheckSCons(bad_ver_strs): 1152632Sstever@eecs.umich.edu def scons_ver(v): 1162632Sstever@eecs.umich.edu num_parts = v.split(' ')[0].split('.') 1171858SN/A major = int(num_parts[0]) 1182632Sstever@eecs.umich.edu minor = int(re.match('\d+', num_parts[1]).group()) 1192632Sstever@eecs.umich.edu rev = 0 1202632Sstever@eecs.umich.edu rdate = 0 121955SN/A if len(num_parts) > 2: 122955SN/A try: rev = int(re.match('\d+', num_parts[2]).group()) 123955SN/A except: pass 124955SN/A rev_parts = num_parts[2].split('d') 125955SN/A if len(rev_parts) > 1: 126955SN/A rdate = int(re.match('\d+', rev_parts[1]).group()) 127955SN/A 128955SN/A return (major, minor, rev, rdate) 1291858SN/A 1301858SN/A sc_ver = scons_ver(SCons.__version__) 1312632Sstever@eecs.umich.edu for bad_ver in bad_ver_strs: 132955SN/A bv = (scons_ver(bad_ver[0]), scons_ver(bad_ver[1])) 1331858SN/A if compare_versions(sc_ver, bv[0]) != -1 and\ 1341105SN/A compare_versions(sc_ver, bv[1]) != 1: 1351869SN/A print "The version of SCons that you have installed: ", SCons.__version__ 1361869SN/A print "has a bug that prevents it from working correctly with M5." 1371869SN/A print "Please install a version NOT contained within the following", 1381869SN/A print "ranges (inclusive):" 1391869SN/A for bad_ver in bad_ver_strs: 1401065SN/A print " %s - %s" % bad_ver 1412632Sstever@eecs.umich.edu Exit(2) 1422632Sstever@eecs.umich.edu 143955SN/ACheckSCons(( 1441858SN/A # We need a version that is 0.96.91 or newer 1451858SN/A ('0.0.0', '0.96.90'), 1461858SN/A # This range has a bug with linking directories into the build dir 1471858SN/A # that only have header files in them 1481851SN/A ('0.97.0d20071212', '0.98.0') 1491851SN/A )) 1501858SN/A 1512632Sstever@eecs.umich.edu 152955SN/A# The absolute path to the current directory (where this file lives). 1531858SN/AROOT = Dir('.').abspath 1541858SN/A 1551858SN/A# Path to the M5 source tree. 1561858SN/ASRCDIR = joinpath(ROOT, 'src') 1571858SN/A 1581858SN/A# tell python where to find m5 python code 1591858SN/Asys.path.append(joinpath(ROOT, 'src/python')) 1601858SN/A 1611858SN/Adef check_style_hook(ui): 1621858SN/A ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 1631858SN/A style_hook = ui.config('hooks', 'pretxncommit.style', None) 1641858SN/A 1651859SN/A if not style_hook: 1661858SN/A print """\ 1671858SN/AYou're missing the M5 style hook. 1681858SN/APlease install the hook so we can ensure that all code fits a common style. 1691859SN/A 1701859SN/AAll you'd need to do is add the following lines to your repository .hg/hgrc 1711862SN/Aor your personal .hgrc 1721862SN/A---------------- 1731862SN/A 1741862SN/A[extensions] 1751859SN/Astyle = %s/util/style.py 1761859SN/A 1771963SN/A[hooks] 1781963SN/Apretxncommit.style = python:style.check_whitespace 1791859SN/A""" % (ROOT) 1801859SN/A sys.exit(1) 1811859SN/A 1821859SN/Aif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1831859SN/A try: 1841859SN/A from mercurial import ui 1851859SN/A check_style_hook(ui.ui()) 1861859SN/A except ImportError: 1871862SN/A pass 1881859SN/A 1891859SN/A################################################### 1901859SN/A# 1911858SN/A# Figure out which configurations to set up based on the path(s) of 1921858SN/A# the target(s). 1932139SN/A# 1942139SN/A################################################### 1952139SN/A 1962155SN/A# Find default configuration & binary. 1972623SN/ADefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1982623SN/A 1992155SN/A# helper function: find last occurrence of element in list 2001869SN/Adef rfind(l, elt, offs = -1): 2011869SN/A for i in range(len(l)+offs, 0, -1): 2021869SN/A if l[i] == elt: 2031869SN/A return i 2041869SN/A raise ValueError, "element not found" 2052139SN/A 2061869SN/A# Each target must have 'build' in the interior of the path; the 2072508SN/A# directory below this will determine the build parameters. For 2082508SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2092508SN/A# recognize that ALPHA_SE specifies the configuration because it 2102508SN/A# follow 'build' in the bulid path. 2112508SN/A 2121869SN/A# Generate absolute paths to targets so we can see where the build dir is 2131869SN/Aif COMMAND_LINE_TARGETS: 2141869SN/A # Ask SCons which directory it was invoked from 2151869SN/A launch_dir = GetLaunchDir() 2161869SN/A # Make targets relative to invocation directory 2171869SN/A abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 2181869SN/A COMMAND_LINE_TARGETS) 2191869SN/Aelse: 2201965SN/A # Default targets are relative to root of tree 2211965SN/A abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 2221965SN/A DEFAULT_TARGETS) 2231869SN/A 2241869SN/A 2251869SN/A# Generate a list of the unique build roots and configs that the 2261869SN/A# collected targets reference. 2271884SN/Abuild_paths = [] 2281884SN/Abuild_root = None 2291884SN/Afor t in abs_targets: 2301869SN/A path_dirs = t.split('/') 2311858SN/A try: 2321869SN/A build_top = rfind(path_dirs, 'build', -2) 2331869SN/A except: 2341869SN/A print "Error: no non-leaf 'build' dir found on target path", t 2351869SN/A Exit(1) 2361869SN/A this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2371858SN/A if not build_root: 2381869SN/A build_root = this_build_root 2391869SN/A else: 2401869SN/A if this_build_root != build_root: 2411869SN/A print "Error: build targets not under same build root\n"\ 2421869SN/A " %s\n %s" % (build_root, this_build_root) 2431869SN/A Exit(1) 2441869SN/A build_path = joinpath('/',*path_dirs[:build_top+2]) 2451869SN/A if build_path not in build_paths: 2461869SN/A build_paths.append(build_path) 2471869SN/A 2481858SN/A# Make sure build_root exists (might not if this is the first build there) 2491858SN/Aif not isdir(build_root): 2501858SN/A os.mkdir(build_root) 2511858SN/A 2522632Sstever@eecs.umich.edu################################################### 2531048SN/A# 254955SN/A# Set up the default build environment. This environment is copied 255955SN/A# and modified according to each selected configuration. 2561869SN/A# 2571869SN/A################################################### 2581869SN/A 2591869SN/Aenv = Environment(ENV = os.environ, # inherit user's environment vars 2601869SN/A ROOT = ROOT, 2611869SN/A SRCDIR = SRCDIR) 2621869SN/A 2631869SN/AExport('env') 2641869SN/A 2651869SN/Aenv.SConsignFile(joinpath(build_root,"sconsign")) 2661869SN/A 2671869SN/A# Default duplicate option is to use hard links, but this messes up 2681869SN/A# when you use emacs to edit a file in the target dir, as emacs moves 2691869SN/A# file to file~ then copies to file, breaking the link. Symbolic 2701869SN/A# (soft) links work better. 2711869SN/Aenv.SetOption('duplicate', 'soft-copy') 2721869SN/A 2731869SN/A# I waffle on this setting... it does avoid a few painful but 2741869SN/A# unnecessary builds, but it also seems to make trivial builds take 2751869SN/A# noticeably longer. 2761869SN/Aif False: 2771869SN/A env.TargetSignatures('content') 2781869SN/A 2791869SN/A# 2801869SN/A# Set up global sticky options... these are common to an entire build 2811869SN/A# tree (not specific to a particular build like ALPHA_SE) 2821869SN/A# 2831869SN/A 2841869SN/A# Option validators & converters for global sticky options 2851869SN/Adef PathListMakeAbsolute(val): 2861869SN/A if not val: 2871869SN/A return val 2881869SN/A f = lambda p: os.path.abspath(os.path.expanduser(p)) 2891869SN/A return ':'.join(map(f, val.split(':'))) 2901869SN/A 2911869SN/Adef PathListAllExist(key, val, env): 2921869SN/A if not val: 2931869SN/A return 2941869SN/A paths = val.split(':') 2951869SN/A for path in paths: 2961869SN/A if not isdir(path): 297955SN/A raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 298955SN/A 299955SN/Aglobal_sticky_opts_file = joinpath(build_root, 'options.global') 300955SN/A 3011858SN/Aglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS) 3021858SN/A 3031858SN/Aglobal_sticky_opts.AddOptions( 3042598SN/A ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3052598SN/A ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3062598SN/A ('BATCH', 'Use batch pool for build and tests', False), 3072598SN/A ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3082598SN/A ('EXTRAS', 'Add Extra directories to the compilation', '', 3092632Sstever@eecs.umich.edu PathListAllExist, PathListMakeAbsolute) 3102632Sstever@eecs.umich.edu ) 3112632Sstever@eecs.umich.edu 3122632Sstever@eecs.umich.edu 3132632Sstever@eecs.umich.edu# base help text 314955SN/Ahelp_text = ''' 3151858SN/AUsage: scons [scons options] [build options] [target(s)] 3162023SN/A 3172632Sstever@eecs.umich.edu''' 3182632Sstever@eecs.umich.edu 3192632Sstever@eecs.umich.eduhelp_text += "Global sticky options:\n" \ 3202632Sstever@eecs.umich.edu + global_sticky_opts.GenerateHelpText(env) 3212632Sstever@eecs.umich.edu 3222632Sstever@eecs.umich.edu# Update env with values from ARGUMENTS & file global_sticky_opts_file 3232632Sstever@eecs.umich.eduglobal_sticky_opts.Update(env) 3242632Sstever@eecs.umich.edu 3252632Sstever@eecs.umich.edu# Save sticky option settings back to current options file 3262632Sstever@eecs.umich.eduglobal_sticky_opts.Save(global_sticky_opts_file, env) 3272632Sstever@eecs.umich.edu 3282023SN/A# Parse EXTRAS option to build list of all directories where we're 3292632Sstever@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3302632Sstever@eecs.umich.edubase_dir_list = [joinpath(ROOT, 'src')] 3311889SN/Aif env['EXTRAS']: 3321889SN/A base_dir_list += env['EXTRAS'].split(':') 3332632Sstever@eecs.umich.edu 3342632Sstever@eecs.umich.eduExport('base_dir_list') 3352632Sstever@eecs.umich.edu 3362632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 3372632Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 3382632Sstever@eecs.umich.eduenv['GCC'] = False 3392632Sstever@eecs.umich.eduenv['SUNCC'] = False 3402632Sstever@eecs.umich.eduenv['ICC'] = False 3412632Sstever@eecs.umich.eduenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 3422632Sstever@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3432632Sstever@eecs.umich.edu close_fds=True).communicate()[0].find('GCC') >= 0 3442632Sstever@eecs.umich.eduenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3452632Sstever@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3462632Sstever@eecs.umich.edu close_fds=True).communicate()[0].find('Sun C++') >= 0 3471888SN/Aenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3481888SN/A stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3491869SN/A close_fds=True).communicate()[0].find('Intel') >= 0 3501869SN/Aif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3511858SN/A print 'Error: How can we have two at the same time?' 3522598SN/A Exit(1) 3532598SN/A 3542598SN/A 3552598SN/A# Set up default C++ compiler flags 3562598SN/Aif env['GCC']: 3571858SN/A env.Append(CCFLAGS='-pipe') 3581858SN/A env.Append(CCFLAGS='-fno-strict-aliasing') 3591858SN/A env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3601858SN/Aelif env['ICC']: 3611858SN/A pass #Fix me... add warning flags once we clean up icc warnings 3621858SN/Aelif env['SUNCC']: 3631858SN/A env.Append(CCFLAGS='-Qoption ccfe') 3641858SN/A env.Append(CCFLAGS='-features=gcc') 3651858SN/A env.Append(CCFLAGS='-features=extensions') 3661871SN/A env.Append(CCFLAGS='-library=stlport4') 3671858SN/A env.Append(CCFLAGS='-xar') 3681858SN/A# env.Append(CCFLAGS='-instances=semiexplicit') 3691858SN/Aelse: 3701858SN/A print 'Error: Don\'t know what compiler options to use for your compiler.' 3711858SN/A print ' Please fix SConstruct and src/SConscript and try again.' 3721858SN/A Exit(1) 3731858SN/A 3741858SN/A# Do this after we save setting back, or else we'll tack on an 3751858SN/A# extra 'qdo' every time we run scons. 3761858SN/Aif env['BATCH']: 3771858SN/A env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 3781859SN/A env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 3791859SN/A 3801869SN/Aif sys.platform == 'cygwin': 3811888SN/A # cygwin has some header file issues... 3822632Sstever@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 3831869SN/Aenv.Append(CPPPATH=[Dir('ext/dnet')]) 3841884SN/A 3851884SN/A# Check for SWIG 3861884SN/Aif not env.has_key('SWIG'): 3871884SN/A print 'Error: SWIG utility not found.' 3881884SN/A print ' Please install (see http://www.swig.org) and retry.' 3891884SN/A Exit(1) 3901965SN/A 3911965SN/A# Check for appropriate SWIG version 3921965SN/Aswig_version = os.popen('swig -version').read().split() 393955SN/A# First 3 words should be "SWIG Version x.y.z" 3941869SN/Aif len(swig_version) < 3 or \ 3951869SN/A swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 3962632Sstever@eecs.umich.edu print 'Error determining SWIG version.' 3971869SN/A Exit(1) 3981869SN/A 3991869SN/Amin_swig_version = '1.3.28' 4002632Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 4012632Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 4022632Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 4032632Sstever@eecs.umich.edu Exit(1) 404955SN/A 4052598SN/A# Set up SWIG flags & scanner 4062598SN/Aswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 407955SN/Aenv.Append(SWIGFLAGS=swig_flags) 408955SN/A 409955SN/A# filter out all existing swig scanners, they mess up the dependency 4101530SN/A# stuff for some reason 411955SN/Ascanners = [] 412955SN/Afor scanner in env['SCANNERS']: 413955SN/A skeys = scanner.skeys 414 if skeys == '.i': 415 continue 416 417 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 418 continue 419 420 scanners.append(scanner) 421 422# add the new swig scanner that we like better 423from SCons.Scanner import ClassicCPP as CPPScanner 424swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 425scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 426 427# replace the scanners list that has what we want 428env['SCANNERS'] = scanners 429 430# Platform-specific configuration. Note again that we assume that all 431# builds under a given build root run on the same host platform. 432conf = Configure(env, 433 conf_dir = joinpath(build_root, '.scons_config'), 434 log_file = joinpath(build_root, 'scons_config.log')) 435 436# Check if we should compile a 64 bit binary on Mac OS X/Darwin 437try: 438 import platform 439 uname = platform.uname() 440 if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 441 if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 442 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 443 close_fds=True).communicate()[0][0]): 444 env.Append(CCFLAGS='-arch x86_64') 445 env.Append(CFLAGS='-arch x86_64') 446 env.Append(LINKFLAGS='-arch x86_64') 447 env.Append(ASFLAGS='-arch x86_64') 448except: 449 pass 450 451# Recent versions of scons substitute a "Null" object for Configure() 452# when configuration isn't necessary, e.g., if the "--help" option is 453# present. Unfortuantely this Null object always returns false, 454# breaking all our configuration checks. We replace it with our own 455# more optimistic null object that returns True instead. 456if not conf: 457 def NullCheck(*args, **kwargs): 458 return True 459 460 class NullConf: 461 def __init__(self, env): 462 self.env = env 463 def Finish(self): 464 return self.env 465 def __getattr__(self, mname): 466 return NullCheck 467 468 conf = NullConf(env) 469 470# Find Python include and library directories for embedding the 471# interpreter. For consistency, we will use the same Python 472# installation used to run scons (and thus this script). If you want 473# to link in an alternate version, see above for instructions on how 474# to invoke scons with a different copy of the Python interpreter. 475 476# Get brief Python version name (e.g., "python2.4") for locating 477# include & library files 478py_version_name = 'python' + sys.version[:3] 479 480# include path, e.g. /usr/local/include/python2.4 481py_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 482env.Append(CPPPATH = py_header_path) 483# verify that it works 484if not conf.CheckHeader('Python.h', '<>'): 485 print "Error: can't find Python.h header in", py_header_path 486 Exit(1) 487 488# add library path too if it's not in the default place 489py_lib_path = None 490if sys.exec_prefix != '/usr': 491 py_lib_path = joinpath(sys.exec_prefix, 'lib') 492elif sys.platform == 'cygwin': 493 # cygwin puts the .dll in /bin for some reason 494 py_lib_path = '/bin' 495if py_lib_path: 496 env.Append(LIBPATH = py_lib_path) 497 print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 498if not conf.CheckLib(py_version_name): 499 print "Error: can't find Python library", py_version_name 500 Exit(1) 501 502# On Solaris you need to use libsocket for socket ops 503if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 504 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 505 print "Can't find library with socket calls (e.g. accept())" 506 Exit(1) 507 508# Check for zlib. If the check passes, libz will be automatically 509# added to the LIBS environment variable. 510if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 511 print 'Error: did not find needed zlib compression library '\ 512 'and/or zlib.h header file.' 513 print ' Please install zlib and try again.' 514 Exit(1) 515 516# Check for <fenv.h> (C99 FP environment control) 517have_fenv = conf.CheckHeader('fenv.h', '<>') 518if not have_fenv: 519 print "Warning: Header file <fenv.h> not found." 520 print " This host has no IEEE FP rounding mode control." 521 522# Check for mysql. 523mysql_config = WhereIs('mysql_config') 524have_mysql = mysql_config != None 525 526# Check MySQL version. 527if have_mysql: 528 mysql_version = os.popen(mysql_config + ' --version').read() 529 min_mysql_version = '4.1' 530 if compare_versions(mysql_version, min_mysql_version) < 0: 531 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 532 print ' Version', mysql_version, 'detected.' 533 have_mysql = False 534 535# Set up mysql_config commands. 536if have_mysql: 537 mysql_config_include = mysql_config + ' --include' 538 if os.system(mysql_config_include + ' > /dev/null') != 0: 539 # older mysql_config versions don't support --include, use 540 # --cflags instead 541 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 542 # This seems to work in all versions 543 mysql_config_libs = mysql_config + ' --libs' 544 545env = conf.Finish() 546 547# Define the universe of supported ISAs 548all_isa_list = [ ] 549Export('all_isa_list') 550 551# Define the universe of supported CPU models 552all_cpu_list = [ ] 553default_cpus = [ ] 554Export('all_cpu_list', 'default_cpus') 555 556# Sticky options get saved in the options file so they persist from 557# one invocation to the next (unless overridden, in which case the new 558# value becomes sticky). 559sticky_opts = Options(args=ARGUMENTS) 560Export('sticky_opts') 561 562# Non-sticky options only apply to the current build. 563nonsticky_opts = Options(args=ARGUMENTS) 564Export('nonsticky_opts') 565 566# Walk the tree and execute all SConsopts scripts that wil add to the 567# above options 568for base_dir in base_dir_list: 569 for root, dirs, files in os.walk(base_dir): 570 if 'SConsopts' in files: 571 print "Reading", joinpath(root, 'SConsopts') 572 SConscript(joinpath(root, 'SConsopts')) 573 574all_isa_list.sort() 575all_cpu_list.sort() 576default_cpus.sort() 577 578sticky_opts.AddOptions( 579 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 580 BoolOption('FULL_SYSTEM', 'Full-system support', False), 581 # There's a bug in scons 0.96.1 that causes ListOptions with list 582 # values (more than one value) not to be able to be restored from 583 # a saved option file. If this causes trouble then upgrade to 584 # scons 0.96.90 or later. 585 ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 586 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 587 BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 588 False), 589 BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 590 False), 591 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 592 False), 593 BoolOption('SS_COMPATIBLE_FP', 594 'Make floating-point results compatible with SimpleScalar', 595 False), 596 BoolOption('USE_SSE2', 597 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 598 False), 599 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 600 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 601 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 602 ('PYTHONHOME', 603 'Override the default PYTHONHOME for this system (use with caution)', 604 '%s:%s' % (sys.prefix, sys.exec_prefix)), 605 ) 606 607nonsticky_opts.AddOptions( 608 BoolOption('update_ref', 'Update test reference outputs', False) 609 ) 610 611# These options get exported to #defines in config/*.hh (see src/SConscript). 612env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 613 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 614 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 615 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 616 617# Define a handy 'no-op' action 618def no_action(target, source, env): 619 return 0 620 621env.NoAction = Action(no_action, None) 622 623################################################### 624# 625# Define a SCons builder for configuration flag headers. 626# 627################################################### 628 629# This function generates a config header file that #defines the 630# option symbol to the current option setting (0 or 1). The source 631# operands are the name of the option and a Value node containing the 632# value of the option. 633def build_config_file(target, source, env): 634 (option, value) = [s.get_contents() for s in source] 635 f = file(str(target[0]), 'w') 636 print >> f, '#define', option, value 637 f.close() 638 return None 639 640# Generate the message to be printed when building the config file. 641def build_config_file_string(target, source, env): 642 (option, value) = [s.get_contents() for s in source] 643 return "Defining %s as %s in %s." % (option, value, target[0]) 644 645# Combine the two functions into a scons Action object. 646config_action = Action(build_config_file, build_config_file_string) 647 648# The emitter munges the source & target node lists to reflect what 649# we're really doing. 650def config_emitter(target, source, env): 651 # extract option name from Builder arg 652 option = str(target[0]) 653 # True target is config header file 654 target = joinpath('config', option.lower() + '.hh') 655 val = env[option] 656 if isinstance(val, bool): 657 # Force value to 0/1 658 val = int(val) 659 elif isinstance(val, str): 660 val = '"' + val + '"' 661 662 # Sources are option name & value (packaged in SCons Value nodes) 663 return ([target], [Value(option), Value(val)]) 664 665config_builder = Builder(emitter = config_emitter, action = config_action) 666 667env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 668 669################################################### 670# 671# Define a SCons builder for copying files. This is used by the 672# Python zipfile code in src/python/SConscript, but is placed up here 673# since it's potentially more generally applicable. 674# 675################################################### 676 677copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 678 679env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 680 681################################################### 682# 683# Define a simple SCons builder to concatenate files. 684# 685# Used to append the Python zip archive to the executable. 686# 687################################################### 688 689concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 690 'chmod +x $TARGET'])) 691 692env.Append(BUILDERS = { 'Concat' : concat_builder }) 693 694 695# libelf build is shared across all configs in the build root. 696env.SConscript('ext/libelf/SConscript', 697 build_dir = joinpath(build_root, 'libelf'), 698 exports = 'env') 699 700################################################### 701# 702# This function is used to set up a directory with switching headers 703# 704################################################### 705 706env['ALL_ISA_LIST'] = all_isa_list 707def make_switching_dir(dirname, switch_headers, env): 708 # Generate the header. target[0] is the full path of the output 709 # header to generate. 'source' is a dummy variable, since we get the 710 # list of ISAs from env['ALL_ISA_LIST']. 711 def gen_switch_hdr(target, source, env): 712 fname = str(target[0]) 713 basename = os.path.basename(fname) 714 f = open(fname, 'w') 715 f.write('#include "arch/isa_specific.hh"\n') 716 cond = '#if' 717 for isa in all_isa_list: 718 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 719 % (cond, isa.upper(), dirname, isa, basename)) 720 cond = '#elif' 721 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 722 f.close() 723 return 0 724 725 # String to print when generating header 726 def gen_switch_hdr_string(target, source, env): 727 return "Generating switch header " + str(target[0]) 728 729 # Build SCons Action object. 'varlist' specifies env vars that this 730 # action depends on; when env['ALL_ISA_LIST'] changes these actions 731 # should get re-executed. 732 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 733 varlist=['ALL_ISA_LIST']) 734 735 # Instantiate actions for each header 736 for hdr in switch_headers: 737 env.Command(hdr, [], switch_hdr_action) 738Export('make_switching_dir') 739 740################################################### 741# 742# Define build environments for selected configurations. 743# 744################################################### 745 746# rename base env 747base_env = env 748 749for build_path in build_paths: 750 print "Building in", build_path 751 752 # Make a copy of the build-root environment to use for this config. 753 env = base_env.Copy() 754 env['BUILDDIR'] = build_path 755 756 # build_dir is the tail component of build path, and is used to 757 # determine the build parameters (e.g., 'ALPHA_SE') 758 (build_root, build_dir) = os.path.split(build_path) 759 760 # Set env options according to the build directory config. 761 sticky_opts.files = [] 762 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 763 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 764 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 765 current_opts_file = joinpath(build_root, 'options', build_dir) 766 if isfile(current_opts_file): 767 sticky_opts.files.append(current_opts_file) 768 print "Using saved options file %s" % current_opts_file 769 else: 770 # Build dir-specific options file doesn't exist. 771 772 # Make sure the directory is there so we can create it later 773 opt_dir = os.path.dirname(current_opts_file) 774 if not isdir(opt_dir): 775 os.mkdir(opt_dir) 776 777 # Get default build options from source tree. Options are 778 # normally determined by name of $BUILD_DIR, but can be 779 # overriden by 'default=' arg on command line. 780 default_opts_file = joinpath('build_opts', 781 ARGUMENTS.get('default', build_dir)) 782 if isfile(default_opts_file): 783 sticky_opts.files.append(default_opts_file) 784 print "Options file %s not found,\n using defaults in %s" \ 785 % (current_opts_file, default_opts_file) 786 else: 787 print "Error: cannot find options file %s or %s" \ 788 % (current_opts_file, default_opts_file) 789 Exit(1) 790 791 # Apply current option settings to env 792 sticky_opts.Update(env) 793 nonsticky_opts.Update(env) 794 795 help_text += "\nSticky options for %s:\n" % build_dir \ 796 + sticky_opts.GenerateHelpText(env) \ 797 + "\nNon-sticky options for %s:\n" % build_dir \ 798 + nonsticky_opts.GenerateHelpText(env) 799 800 # Process option settings. 801 802 if not have_fenv and env['USE_FENV']: 803 print "Warning: <fenv.h> not available; " \ 804 "forcing USE_FENV to False in", build_dir + "." 805 env['USE_FENV'] = False 806 807 if not env['USE_FENV']: 808 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 809 print " FP results may deviate slightly from other platforms." 810 811 if env['EFENCE']: 812 env.Append(LIBS=['efence']) 813 814 if env['USE_MYSQL']: 815 if not have_mysql: 816 print "Warning: MySQL not available; " \ 817 "forcing USE_MYSQL to False in", build_dir + "." 818 env['USE_MYSQL'] = False 819 else: 820 print "Compiling in", build_dir, "with MySQL support." 821 env.ParseConfig(mysql_config_libs) 822 env.ParseConfig(mysql_config_include) 823 824 # Save sticky option settings back to current options file 825 sticky_opts.Save(current_opts_file, env) 826 827 if env['USE_SSE2']: 828 env.Append(CCFLAGS='-msse2') 829 830 # The src/SConscript file sets up the build rules in 'env' according 831 # to the configured options. It returns a list of environments, 832 # one for each variant build (debug, opt, etc.) 833 envList = SConscript('src/SConscript', build_dir = build_path, 834 exports = 'env') 835 836 # Set up the regression tests for each build. 837 for e in envList: 838 SConscript('tests/SConscript', 839 build_dir = joinpath(build_path, 'tests', e.Label), 840 exports = { 'env' : e }, duplicate = False) 841 842Help(help_text) 843 844 845################################################### 846# 847# Let SCons do its thing. At this point SCons will use the defined 848# build environments to build the requested targets. 849# 850################################################### 851 852