SConstruct revision 5273
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 68955SN/A 69955SN/Afrom os.path import isdir, join as joinpath 702656Sstever@eecs.umich.edu 712656Sstever@eecs.umich.eduimport SCons 722656Sstever@eecs.umich.edu 732656Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 742656Sstever@eecs.umich.edu# default installation of Python is not recent enough, you can use a 752656Sstever@eecs.umich.edu# non-default installation of the Python interpreter by either (1) 762656Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 772653Sstever@eecs.umich.edu# first or (2) explicitly invoking an alternative interpreter on the 782653Sstever@eecs.umich.edu# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 792653Sstever@eecs.umich.eduEnsurePythonVersion(2,4) 802653Sstever@eecs.umich.edu 812653Sstever@eecs.umich.edu# Import subprocess after we check the version since it doesn't exist in 822653Sstever@eecs.umich.edu# Python < 2.4. 832653Sstever@eecs.umich.eduimport subprocess 842653Sstever@eecs.umich.edu 852653Sstever@eecs.umich.edu# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 862653Sstever@eecs.umich.edu# 3-element version number. 872653Sstever@eecs.umich.edumin_scons_version = (0,96,91) 881852SN/Atry: 89955SN/A EnsureSConsVersion(*min_scons_version) 90955SN/Aexcept: 91955SN/A print "Error checking current SCons version." 922632Sstever@eecs.umich.edu print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 932632Sstever@eecs.umich.edu Exit(2) 94955SN/A 951533SN/A 962632Sstever@eecs.umich.edu# The absolute path to the current directory (where this file lives). 971533SN/AROOT = Dir('.').abspath 98955SN/A 99955SN/A# Path to the M5 source tree. 1002632Sstever@eecs.umich.eduSRCDIR = joinpath(ROOT, 'src') 1012632Sstever@eecs.umich.edu 102955SN/A# tell python where to find m5 python code 103955SN/Asys.path.append(joinpath(ROOT, 'src/python')) 104955SN/A 105955SN/Adef check_style_hook(ui): 1062632Sstever@eecs.umich.edu ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 107955SN/A style_hook = ui.config('hooks', 'pretxncommit.style', None) 1082632Sstever@eecs.umich.edu 109955SN/A if not style_hook: 110955SN/A print """\ 1112632Sstever@eecs.umich.eduYou're missing the M5 style hook. 1122632Sstever@eecs.umich.eduPlease install the hook so we can ensure that all code fits a common style. 1132632Sstever@eecs.umich.edu 1142632Sstever@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc 1152632Sstever@eecs.umich.eduor your personal .hgrc 1162632Sstever@eecs.umich.edu---------------- 1172632Sstever@eecs.umich.edu 1182632Sstever@eecs.umich.edu[extensions] 1192632Sstever@eecs.umich.edustyle = %s/util/style.py 1202632Sstever@eecs.umich.edu 1212632Sstever@eecs.umich.edu[hooks] 1223053Sstever@eecs.umich.edupretxncommit.style = python:style.check_whitespace 1233053Sstever@eecs.umich.edu""" % (ROOT) 1243053Sstever@eecs.umich.edu sys.exit(1) 1253053Sstever@eecs.umich.edu 1263053Sstever@eecs.umich.eduif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1273053Sstever@eecs.umich.edu try: 1283053Sstever@eecs.umich.edu from mercurial import ui 1293053Sstever@eecs.umich.edu check_style_hook(ui.ui()) 1303053Sstever@eecs.umich.edu except ImportError: 1313053Sstever@eecs.umich.edu pass 1323053Sstever@eecs.umich.edu 1333053Sstever@eecs.umich.edu################################################### 1343053Sstever@eecs.umich.edu# 1353053Sstever@eecs.umich.edu# Figure out which configurations to set up based on the path(s) of 1363053Sstever@eecs.umich.edu# the target(s). 1373053Sstever@eecs.umich.edu# 1382632Sstever@eecs.umich.edu################################################### 1392632Sstever@eecs.umich.edu 1402632Sstever@eecs.umich.edu# Find default configuration & binary. 1412632Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1422632Sstever@eecs.umich.edu 1432632Sstever@eecs.umich.edu# helper function: find last occurrence of element in list 1442634Sstever@eecs.umich.edudef rfind(l, elt, offs = -1): 1452634Sstever@eecs.umich.edu for i in range(len(l)+offs, 0, -1): 1462632Sstever@eecs.umich.edu if l[i] == elt: 1472638Sstever@eecs.umich.edu return i 1482632Sstever@eecs.umich.edu raise ValueError, "element not found" 1492632Sstever@eecs.umich.edu 1502632Sstever@eecs.umich.edu# helper function: compare dotted version numbers. 1512632Sstever@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1') 1522632Sstever@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1532632Sstever@eecs.umich.edudef compare_versions(v1, v2): 1541858SN/A # Convert dotted strings to lists 1552638Sstever@eecs.umich.edu v1 = map(int, v1.split('.')) 1562638Sstever@eecs.umich.edu v2 = map(int, v2.split('.')) 1572638Sstever@eecs.umich.edu # Compare corresponding elements of lists 1582638Sstever@eecs.umich.edu for n1,n2 in zip(v1, v2): 1592638Sstever@eecs.umich.edu if n1 < n2: return -1 1602638Sstever@eecs.umich.edu if n1 > n2: return 1 1612638Sstever@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1622638Sstever@eecs.umich.edu if len(v1) < len(v2): return -1 1632634Sstever@eecs.umich.edu if len(v1) > len(v2): return 1 1642634Sstever@eecs.umich.edu return 0 1652634Sstever@eecs.umich.edu 166955SN/A# Each target must have 'build' in the interior of the path; the 167955SN/A# directory below this will determine the build parameters. For 168955SN/A# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 169955SN/A# recognize that ALPHA_SE specifies the configuration because it 170955SN/A# follow 'build' in the bulid path. 171955SN/A 172955SN/A# Generate absolute paths to targets so we can see where the build dir is 173955SN/Aif COMMAND_LINE_TARGETS: 1741858SN/A # Ask SCons which directory it was invoked from 1751858SN/A launch_dir = GetLaunchDir() 1762632Sstever@eecs.umich.edu # Make targets relative to invocation directory 177955SN/A abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 1782776Sstever@eecs.umich.edu COMMAND_LINE_TARGETS) 1791105SN/Aelse: 1802667Sstever@eecs.umich.edu # Default targets are relative to root of tree 1812667Sstever@eecs.umich.edu abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 1822667Sstever@eecs.umich.edu DEFAULT_TARGETS) 1832667Sstever@eecs.umich.edu 1842667Sstever@eecs.umich.edu 1852667Sstever@eecs.umich.edu# Generate a list of the unique build roots and configs that the 1861869SN/A# collected targets reference. 1871869SN/Abuild_paths = [] 1881869SN/Abuild_root = None 1891869SN/Afor t in abs_targets: 1901869SN/A path_dirs = t.split('/') 1911065SN/A try: 1922632Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 1932632Sstever@eecs.umich.edu except: 194955SN/A print "Error: no non-leaf 'build' dir found on target path", t 1951858SN/A Exit(1) 1961858SN/A this_build_root = joinpath('/',*path_dirs[:build_top+1]) 1971858SN/A if not build_root: 1981858SN/A build_root = this_build_root 1991851SN/A else: 2001851SN/A if this_build_root != build_root: 2011858SN/A print "Error: build targets not under same build root\n"\ 2022632Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 203955SN/A Exit(1) 2043053Sstever@eecs.umich.edu build_path = joinpath('/',*path_dirs[:build_top+2]) 2053053Sstever@eecs.umich.edu if build_path not in build_paths: 2063053Sstever@eecs.umich.edu build_paths.append(build_path) 2073053Sstever@eecs.umich.edu 2083053Sstever@eecs.umich.edu################################################### 2093053Sstever@eecs.umich.edu# 2103053Sstever@eecs.umich.edu# Set up the default build environment. This environment is copied 2113053Sstever@eecs.umich.edu# and modified according to each selected configuration. 2123053Sstever@eecs.umich.edu# 2133053Sstever@eecs.umich.edu################################################### 2143053Sstever@eecs.umich.edu 2153053Sstever@eecs.umich.eduenv = Environment(ENV = os.environ, # inherit user's environment vars 2163053Sstever@eecs.umich.edu ROOT = ROOT, 2173053Sstever@eecs.umich.edu SRCDIR = SRCDIR) 2183053Sstever@eecs.umich.edu 2193053Sstever@eecs.umich.edu#Parse CC/CXX early so that we use the correct compiler for 2203053Sstever@eecs.umich.edu# to test for dependencies/versions/libraries/includes 2213053Sstever@eecs.umich.eduif ARGUMENTS.get('CC', None): 2223053Sstever@eecs.umich.edu env['CC'] = ARGUMENTS.get('CC') 2232667Sstever@eecs.umich.edu 2242667Sstever@eecs.umich.eduif ARGUMENTS.get('CXX', None): 2252667Sstever@eecs.umich.edu env['CXX'] = ARGUMENTS.get('CXX') 2262667Sstever@eecs.umich.edu 2272667Sstever@eecs.umich.eduExport('env') 2282667Sstever@eecs.umich.edu 2292667Sstever@eecs.umich.eduenv.SConsignFile(joinpath(build_root,"sconsign")) 2302667Sstever@eecs.umich.edu 2312667Sstever@eecs.umich.edu# Default duplicate option is to use hard links, but this messes up 2322667Sstever@eecs.umich.edu# when you use emacs to edit a file in the target dir, as emacs moves 2332667Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2342667Sstever@eecs.umich.edu# (soft) links work better. 2352638Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 2362638Sstever@eecs.umich.edu 2372638Sstever@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but 2382638Sstever@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 2392638Sstever@eecs.umich.edu# noticeably longer. 2401858SN/Aif False: 2413118Sstever@eecs.umich.edu env.TargetSignatures('content') 2423118Sstever@eecs.umich.edu 2433118Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 2443118Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 2453118Sstever@eecs.umich.eduenv['GCC'] = False 2463118Sstever@eecs.umich.eduenv['SUNCC'] = False 2473118Sstever@eecs.umich.eduenv['ICC'] = False 2483118Sstever@eecs.umich.eduenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 2493118Sstever@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2503118Sstever@eecs.umich.edu close_fds=True).communicate()[0].find('GCC') >= 0 2513118Sstever@eecs.umich.eduenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 2523118Sstever@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2533118Sstever@eecs.umich.edu close_fds=True).communicate()[0].find('Sun C++') >= 0 2543118Sstever@eecs.umich.eduenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 2553118Sstever@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 2563118Sstever@eecs.umich.edu close_fds=True).communicate()[0].find('Intel') >= 0 2573118Sstever@eecs.umich.eduif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 2583118Sstever@eecs.umich.edu print 'Error: How can we have two at the same time?' 2593118Sstever@eecs.umich.edu Exit(1) 2603118Sstever@eecs.umich.edu 2613118Sstever@eecs.umich.edu 2623118Sstever@eecs.umich.edu# Set up default C++ compiler flags 2633118Sstever@eecs.umich.eduif env['GCC']: 2643118Sstever@eecs.umich.edu env.Append(CCFLAGS='-pipe') 2653118Sstever@eecs.umich.edu env.Append(CCFLAGS='-fno-strict-aliasing') 2663118Sstever@eecs.umich.edu env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 2673118Sstever@eecs.umich.eduelif env['ICC']: 2683118Sstever@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 2693118Sstever@eecs.umich.eduelif env['SUNCC']: 2703118Sstever@eecs.umich.edu env.Append(CCFLAGS='-Qoption ccfe') 2713118Sstever@eecs.umich.edu env.Append(CCFLAGS='-features=gcc') 2723118Sstever@eecs.umich.edu env.Append(CCFLAGS='-features=extensions') 2733483Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-library=stlport4') 2743483Ssaidi@eecs.umich.edu env.Append(CCFLAGS='-xar') 2753483Ssaidi@eecs.umich.edu# env.Append(CCFLAGS='-instances=semiexplicit') 2763483Ssaidi@eecs.umich.eduelse: 2773483Ssaidi@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 2783483Ssaidi@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 2793053Sstever@eecs.umich.edu Exit(1) 2803053Sstever@eecs.umich.edu 2813053Sstever@eecs.umich.eduif sys.platform == 'cygwin': 2823053Sstever@eecs.umich.edu # cygwin has some header file issues... 2833053Sstever@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 2843053Sstever@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 2853053Sstever@eecs.umich.edu 2863053Sstever@eecs.umich.edu# Check for SWIG 2871858SN/Aif not env.has_key('SWIG'): 2881858SN/A print 'Error: SWIG utility not found.' 2891858SN/A print ' Please install (see http://www.swig.org) and retry.' 2901858SN/A Exit(1) 2911858SN/A 2921858SN/A# Check for appropriate SWIG version 2931859SN/Aswig_version = os.popen('swig -version').read().split() 2941858SN/A# First 3 words should be "SWIG Version x.y.z" 2951858SN/Aif len(swig_version) < 3 or \ 2961858SN/A swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 2971859SN/A print 'Error determining SWIG version.' 2981859SN/A Exit(1) 2991862SN/A 3003053Sstever@eecs.umich.edumin_swig_version = '1.3.28' 3013053Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 3023053Sstever@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 3033053Sstever@eecs.umich.edu print ' Installed version:', swig_version[2] 3041859SN/A Exit(1) 3051859SN/A 3061859SN/A# Set up SWIG flags & scanner 3071859SN/Aswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 3081859SN/Aenv.Append(SWIGFLAGS=swig_flags) 3091859SN/A 3101859SN/A# filter out all existing swig scanners, they mess up the dependency 3111859SN/A# stuff for some reason 3121862SN/Ascanners = [] 3131859SN/Afor scanner in env['SCANNERS']: 3141859SN/A skeys = scanner.skeys 3151859SN/A if skeys == '.i': 3161858SN/A continue 3171858SN/A 3182139SN/A if isinstance(skeys, (list, tuple)) and '.i' in skeys: 3192139SN/A continue 3202139SN/A 3212155SN/A scanners.append(scanner) 3222623SN/A 3232817Sksewell@umich.edu# add the new swig scanner that we like better 3242792Sktlim@umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 3252155SN/Aswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 3261869SN/Ascanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 3271869SN/A 3281869SN/A# replace the scanners list that has what we want 3291869SN/Aenv['SCANNERS'] = scanners 3301869SN/A 3312139SN/A# Platform-specific configuration. Note again that we assume that all 3321869SN/A# builds under a given build root run on the same host platform. 3332508SN/Aconf = Configure(env, 3342508SN/A conf_dir = joinpath(build_root, '.scons_config'), 3352508SN/A log_file = joinpath(build_root, 'scons_config.log')) 3362508SN/A 3372635Sstever@eecs.umich.edu# Check if we should compile a 64 bit binary on Mac OS X/Darwin 3382635Sstever@eecs.umich.edutry: 3391869SN/A import platform 3401869SN/A uname = platform.uname() 3411869SN/A if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 3421869SN/A if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 3431869SN/A stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3441869SN/A close_fds=True).communicate()[0][0]): 3451869SN/A env.Append(CCFLAGS='-arch x86_64') 3461869SN/A env.Append(CFLAGS='-arch x86_64') 3471965SN/A env.Append(LINKFLAGS='-arch x86_64') 3481965SN/A env.Append(ASFLAGS='-arch x86_64') 3491965SN/Aexcept: 3501869SN/A pass 3511869SN/A 3522733Sktlim@umich.edu# Recent versions of scons substitute a "Null" object for Configure() 3531869SN/A# when configuration isn't necessary, e.g., if the "--help" option is 3541884SN/A# present. Unfortuantely this Null object always returns false, 3551884SN/A# breaking all our configuration checks. We replace it with our own 3563356Sbinkertn@umich.edu# more optimistic null object that returns True instead. 3573356Sbinkertn@umich.eduif not conf: 3583356Sbinkertn@umich.edu def NullCheck(*args, **kwargs): 3593356Sbinkertn@umich.edu return True 3601869SN/A 3611858SN/A class NullConf: 3621869SN/A def __init__(self, env): 3631869SN/A self.env = env 3641869SN/A def Finish(self): 3651869SN/A return self.env 3661869SN/A def __getattr__(self, mname): 3671858SN/A return NullCheck 3682761Sstever@eecs.umich.edu 3691869SN/A conf = NullConf(env) 3702733Sktlim@umich.edu 3713356Sbinkertn@umich.edu# Find Python include and library directories for embedding the 3721869SN/A# interpreter. For consistency, we will use the same Python 3731869SN/A# installation used to run scons (and thus this script). If you want 3741869SN/A# to link in an alternate version, see above for instructions on how 3751869SN/A# to invoke scons with a different copy of the Python interpreter. 3761869SN/A 3771869SN/A# Get brief Python version name (e.g., "python2.4") for locating 3781858SN/A# include & library files 379955SN/Apy_version_name = 'python' + sys.version[:3] 380955SN/A 3811869SN/A# include path, e.g. /usr/local/include/python2.4 3821869SN/Apy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 3831869SN/Aenv.Append(CPPPATH = py_header_path) 3841869SN/A# verify that it works 3851869SN/Aif not conf.CheckHeader('Python.h', '<>'): 3861869SN/A print "Error: can't find Python.h header in", py_header_path 3871869SN/A Exit(1) 3881869SN/A 3891869SN/A# add library path too if it's not in the default place 3901869SN/Apy_lib_path = None 3911869SN/Aif sys.exec_prefix != '/usr': 3921869SN/A py_lib_path = joinpath(sys.exec_prefix, 'lib') 3931869SN/Aelif sys.platform == 'cygwin': 3941869SN/A # cygwin puts the .dll in /bin for some reason 3951869SN/A py_lib_path = '/bin' 3961869SN/Aif py_lib_path: 3971869SN/A env.Append(LIBPATH = py_lib_path) 3981869SN/A print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 3991869SN/Aif not conf.CheckLib(py_version_name): 4001869SN/A print "Error: can't find Python library", py_version_name 4011869SN/A Exit(1) 4021869SN/A 4031869SN/A# On Solaris you need to use libsocket for socket ops 4041869SN/Aif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 4051869SN/A if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 4061869SN/A print "Can't find library with socket calls (e.g. accept())" 4071869SN/A Exit(1) 4081869SN/A 4091869SN/A# Check for zlib. If the check passes, libz will be automatically 4101869SN/A# added to the LIBS environment variable. 4113356Sbinkertn@umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 4123356Sbinkertn@umich.edu print 'Error: did not find needed zlib compression library '\ 4133356Sbinkertn@umich.edu 'and/or zlib.h header file.' 4143356Sbinkertn@umich.edu print ' Please install zlib and try again.' 4153356Sbinkertn@umich.edu Exit(1) 4163356Sbinkertn@umich.edu 4173356Sbinkertn@umich.edu# Check for <fenv.h> (C99 FP environment control) 4181869SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 4191869SN/Aif not have_fenv: 4201869SN/A print "Warning: Header file <fenv.h> not found." 4211869SN/A print " This host has no IEEE FP rounding mode control." 4221869SN/A 4231869SN/A# Check for mysql. 4241869SN/Amysql_config = WhereIs('mysql_config') 4252655Sstever@eecs.umich.eduhave_mysql = mysql_config != None 4262655Sstever@eecs.umich.edu 4272655Sstever@eecs.umich.edu# Check MySQL version. 4282655Sstever@eecs.umich.eduif have_mysql: 4292655Sstever@eecs.umich.edu mysql_version = os.popen(mysql_config + ' --version').read() 4302655Sstever@eecs.umich.edu min_mysql_version = '4.1' 4312655Sstever@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 4322655Sstever@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 4332655Sstever@eecs.umich.edu print ' Version', mysql_version, 'detected.' 4342655Sstever@eecs.umich.edu have_mysql = False 4352655Sstever@eecs.umich.edu 4362655Sstever@eecs.umich.edu# Set up mysql_config commands. 4372655Sstever@eecs.umich.eduif have_mysql: 4382655Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 4392655Sstever@eecs.umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 4402655Sstever@eecs.umich.edu # older mysql_config versions don't support --include, use 4412655Sstever@eecs.umich.edu # --cflags instead 4422655Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 4432655Sstever@eecs.umich.edu # This seems to work in all versions 4442655Sstever@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 4452655Sstever@eecs.umich.edu 4462655Sstever@eecs.umich.eduenv = conf.Finish() 4472655Sstever@eecs.umich.edu 4482655Sstever@eecs.umich.edu# Define the universe of supported ISAs 4492655Sstever@eecs.umich.eduall_isa_list = [ ] 4502655Sstever@eecs.umich.eduExport('all_isa_list') 4512634Sstever@eecs.umich.edu 4522634Sstever@eecs.umich.edu# Define the universe of supported CPU models 4532634Sstever@eecs.umich.eduall_cpu_list = [ ] 4542634Sstever@eecs.umich.edudefault_cpus = [ ] 4552634Sstever@eecs.umich.eduExport('all_cpu_list', 'default_cpus') 4562634Sstever@eecs.umich.edu 4572638Sstever@eecs.umich.edu# Sticky options get saved in the options file so they persist from 4582638Sstever@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 4592638Sstever@eecs.umich.edu# value becomes sticky). 4602638Sstever@eecs.umich.edusticky_opts = Options(args=ARGUMENTS) 4612638Sstever@eecs.umich.eduExport('sticky_opts') 4621869SN/A 4631869SN/A# Non-sticky options only apply to the current build. 464955SN/Anonsticky_opts = Options(args=ARGUMENTS) 465955SN/AExport('nonsticky_opts') 466955SN/A 467955SN/A# Walk the tree and execute all SConsopts scripts that wil add to the 4681858SN/A# above options 4691858SN/Afor root, dirs, files in os.walk('.'): 4701858SN/A if 'SConsopts' in files: 4712632Sstever@eecs.umich.edu SConscript(os.path.join(root, 'SConsopts')) 4722632Sstever@eecs.umich.edu 4732632Sstever@eecs.umich.eduall_isa_list.sort() 4742632Sstever@eecs.umich.eduall_cpu_list.sort() 4752632Sstever@eecs.umich.edudefault_cpus.sort() 4762634Sstever@eecs.umich.edu 4772638Sstever@eecs.umich.edudef PathListMakeAbsolute(val): 4782023SN/A if not val: 4792632Sstever@eecs.umich.edu return val 4802632Sstever@eecs.umich.edu f = lambda p: os.path.abspath(os.path.expanduser(p)) 4812632Sstever@eecs.umich.edu return ':'.join(map(f, val.split(':'))) 4822632Sstever@eecs.umich.edu 4832632Sstever@eecs.umich.edudef PathListAllExist(key, val, env): 4842632Sstever@eecs.umich.edu if not val: 4852632Sstever@eecs.umich.edu return 4862632Sstever@eecs.umich.edu paths = val.split(':') 4872632Sstever@eecs.umich.edu for path in paths: 4882632Sstever@eecs.umich.edu if not isdir(path): 4892632Sstever@eecs.umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 4902023SN/A 4912632Sstever@eecs.umich.edusticky_opts.AddOptions( 4922632Sstever@eecs.umich.edu EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 4931889SN/A BoolOption('FULL_SYSTEM', 'Full-system support', False), 4941889SN/A # There's a bug in scons 0.96.1 that causes ListOptions with list 4952632Sstever@eecs.umich.edu # values (more than one value) not to be able to be restored from 4962632Sstever@eecs.umich.edu # a saved option file. If this causes trouble then upgrade to 4972632Sstever@eecs.umich.edu # scons 0.96.90 or later. 4982632Sstever@eecs.umich.edu ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 4992632Sstever@eecs.umich.edu BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 5002632Sstever@eecs.umich.edu BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 5012632Sstever@eecs.umich.edu False), 5022632Sstever@eecs.umich.edu BoolOption('SS_COMPATIBLE_FP', 5032632Sstever@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 5042632Sstever@eecs.umich.edu False), 5052632Sstever@eecs.umich.edu BoolOption('USE_SSE2', 5062632Sstever@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 5072632Sstever@eecs.umich.edu False), 5082632Sstever@eecs.umich.edu BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 5091888SN/A BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 5101888SN/A BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 5111869SN/A ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 5121869SN/A ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 5131858SN/A BoolOption('BATCH', 'Use batch pool for build and tests', False), 5142598SN/A ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 5152598SN/A ('PYTHONHOME', 5162598SN/A 'Override the default PYTHONHOME for this system (use with caution)', 5172598SN/A '%s:%s' % (sys.prefix, sys.exec_prefix)), 5182598SN/A ('EXTRAS', 'Add Extra directories to the compilation', '', 5191858SN/A PathListAllExist, PathListMakeAbsolute) 5201858SN/A ) 5211858SN/A 5221858SN/Anonsticky_opts.AddOptions( 5231858SN/A BoolOption('update_ref', 'Update test reference outputs', False) 5241858SN/A ) 5251858SN/A 5261858SN/A# These options get exported to #defines in config/*.hh (see src/SConscript). 5271858SN/Aenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 5281871SN/A 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 5291858SN/A 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 5301858SN/A 5311858SN/A# Define a handy 'no-op' action 5321858SN/Adef no_action(target, source, env): 5331858SN/A return 0 5341858SN/A 5351858SN/Aenv.NoAction = Action(no_action, None) 5361858SN/A 5371858SN/A################################################### 5381858SN/A# 5391858SN/A# Define a SCons builder for configuration flag headers. 5401859SN/A# 5411859SN/A################################################### 5421869SN/A 5431888SN/A# This function generates a config header file that #defines the 5442632Sstever@eecs.umich.edu# option symbol to the current option setting (0 or 1). The source 5451869SN/A# operands are the name of the option and a Value node containing the 5461884SN/A# value of the option. 5471884SN/Adef build_config_file(target, source, env): 5481884SN/A (option, value) = [s.get_contents() for s in source] 5491884SN/A f = file(str(target[0]), 'w') 5501884SN/A print >> f, '#define', option, value 5511884SN/A f.close() 5521965SN/A return None 5531965SN/A 5541965SN/A# Generate the message to be printed when building the config file. 5552761Sstever@eecs.umich.edudef build_config_file_string(target, source, env): 5561869SN/A (option, value) = [s.get_contents() for s in source] 5571869SN/A return "Defining %s as %s in %s." % (option, value, target[0]) 5582632Sstever@eecs.umich.edu 5592667Sstever@eecs.umich.edu# Combine the two functions into a scons Action object. 5601869SN/Aconfig_action = Action(build_config_file, build_config_file_string) 5611869SN/A 5622929Sktlim@umich.edu# The emitter munges the source & target node lists to reflect what 5632929Sktlim@umich.edu# we're really doing. 5643036Sstever@eecs.umich.edudef config_emitter(target, source, env): 5652929Sktlim@umich.edu # extract option name from Builder arg 566955SN/A option = str(target[0]) 5672598SN/A # True target is config header file 5682598SN/A target = joinpath('config', option.lower() + '.hh') 569955SN/A val = env[option] 570955SN/A if isinstance(val, bool): 571955SN/A # Force value to 0/1 5721530SN/A val = int(val) 573955SN/A elif isinstance(val, str): 574955SN/A val = '"' + val + '"' 575955SN/A 576 # Sources are option name & value (packaged in SCons Value nodes) 577 return ([target], [Value(option), Value(val)]) 578 579config_builder = Builder(emitter = config_emitter, action = config_action) 580 581env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 582 583################################################### 584# 585# Define a SCons builder for copying files. This is used by the 586# Python zipfile code in src/python/SConscript, but is placed up here 587# since it's potentially more generally applicable. 588# 589################################################### 590 591copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 592 593env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 594 595################################################### 596# 597# Define a simple SCons builder to concatenate files. 598# 599# Used to append the Python zip archive to the executable. 600# 601################################################### 602 603concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 604 'chmod +x $TARGET'])) 605 606env.Append(BUILDERS = { 'Concat' : concat_builder }) 607 608 609# base help text 610help_text = ''' 611Usage: scons [scons options] [build options] [target(s)] 612 613''' 614 615# libelf build is shared across all configs in the build root. 616env.SConscript('ext/libelf/SConscript', 617 build_dir = joinpath(build_root, 'libelf'), 618 exports = 'env') 619 620################################################### 621# 622# This function is used to set up a directory with switching headers 623# 624################################################### 625 626env['ALL_ISA_LIST'] = all_isa_list 627def make_switching_dir(dirname, switch_headers, env): 628 # Generate the header. target[0] is the full path of the output 629 # header to generate. 'source' is a dummy variable, since we get the 630 # list of ISAs from env['ALL_ISA_LIST']. 631 def gen_switch_hdr(target, source, env): 632 fname = str(target[0]) 633 basename = os.path.basename(fname) 634 f = open(fname, 'w') 635 f.write('#include "arch/isa_specific.hh"\n') 636 cond = '#if' 637 for isa in all_isa_list: 638 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 639 % (cond, isa.upper(), dirname, isa, basename)) 640 cond = '#elif' 641 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 642 f.close() 643 return 0 644 645 # String to print when generating header 646 def gen_switch_hdr_string(target, source, env): 647 return "Generating switch header " + str(target[0]) 648 649 # Build SCons Action object. 'varlist' specifies env vars that this 650 # action depends on; when env['ALL_ISA_LIST'] changes these actions 651 # should get re-executed. 652 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 653 varlist=['ALL_ISA_LIST']) 654 655 # Instantiate actions for each header 656 for hdr in switch_headers: 657 env.Command(hdr, [], switch_hdr_action) 658Export('make_switching_dir') 659 660################################################### 661# 662# Define build environments for selected configurations. 663# 664################################################### 665 666# rename base env 667base_env = env 668 669for build_path in build_paths: 670 print "Building in", build_path 671 env['BUILDDIR'] = build_path 672 673 # build_dir is the tail component of build path, and is used to 674 # determine the build parameters (e.g., 'ALPHA_SE') 675 (build_root, build_dir) = os.path.split(build_path) 676 # Make a copy of the build-root environment to use for this config. 677 env = base_env.Copy() 678 679 # Set env options according to the build directory config. 680 sticky_opts.files = [] 681 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 682 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 683 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 684 current_opts_file = joinpath(build_root, 'options', build_dir) 685 if os.path.isfile(current_opts_file): 686 sticky_opts.files.append(current_opts_file) 687 print "Using saved options file %s" % current_opts_file 688 else: 689 # Build dir-specific options file doesn't exist. 690 691 # Make sure the directory is there so we can create it later 692 opt_dir = os.path.dirname(current_opts_file) 693 if not os.path.isdir(opt_dir): 694 os.mkdir(opt_dir) 695 696 # Get default build options from source tree. Options are 697 # normally determined by name of $BUILD_DIR, but can be 698 # overriden by 'default=' arg on command line. 699 default_opts_file = joinpath('build_opts', 700 ARGUMENTS.get('default', build_dir)) 701 if os.path.isfile(default_opts_file): 702 sticky_opts.files.append(default_opts_file) 703 print "Options file %s not found,\n using defaults in %s" \ 704 % (current_opts_file, default_opts_file) 705 else: 706 print "Error: cannot find options file %s or %s" \ 707 % (current_opts_file, default_opts_file) 708 Exit(1) 709 710 # Apply current option settings to env 711 sticky_opts.Update(env) 712 nonsticky_opts.Update(env) 713 714 help_text += "Sticky options for %s:\n" % build_dir \ 715 + sticky_opts.GenerateHelpText(env) \ 716 + "\nNon-sticky options for %s:\n" % build_dir \ 717 + nonsticky_opts.GenerateHelpText(env) 718 719 # Process option settings. 720 721 if not have_fenv and env['USE_FENV']: 722 print "Warning: <fenv.h> not available; " \ 723 "forcing USE_FENV to False in", build_dir + "." 724 env['USE_FENV'] = False 725 726 if not env['USE_FENV']: 727 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 728 print " FP results may deviate slightly from other platforms." 729 730 if env['EFENCE']: 731 env.Append(LIBS=['efence']) 732 733 if env['USE_MYSQL']: 734 if not have_mysql: 735 print "Warning: MySQL not available; " \ 736 "forcing USE_MYSQL to False in", build_dir + "." 737 env['USE_MYSQL'] = False 738 else: 739 print "Compiling in", build_dir, "with MySQL support." 740 env.ParseConfig(mysql_config_libs) 741 env.ParseConfig(mysql_config_include) 742 743 # Save sticky option settings back to current options file 744 sticky_opts.Save(current_opts_file, env) 745 746 # Do this after we save setting back, or else we'll tack on an 747 # extra 'qdo' every time we run scons. 748 if env['BATCH']: 749 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 750 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 751 752 if env['USE_SSE2']: 753 env.Append(CCFLAGS='-msse2') 754 755 # The src/SConscript file sets up the build rules in 'env' according 756 # to the configured options. It returns a list of environments, 757 # one for each variant build (debug, opt, etc.) 758 envList = SConscript('src/SConscript', build_dir = build_path, 759 exports = 'env') 760 761 # Set up the regression tests for each build. 762 for e in envList: 763 SConscript('tests/SConscript', 764 build_dir = joinpath(build_path, 'tests', e.Label), 765 exports = { 'env' : e }, duplicate = False) 766 767Help(help_text) 768 769 770################################################### 771# 772# Let SCons do its thing. At this point SCons will use the defined 773# build environments to build the requested targets. 774# 775################################################### 776 777