SConstruct revision 5749
111308Santhony.gutierrez@amd.com# -*- mode:python -*- 211308Santhony.gutierrez@amd.com 311308Santhony.gutierrez@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 411308Santhony.gutierrez@amd.com# All rights reserved. 511308Santhony.gutierrez@amd.com# 611308Santhony.gutierrez@amd.com# Redistribution and use in source and binary forms, with or without 711308Santhony.gutierrez@amd.com# modification, are permitted provided that the following conditions are 811308Santhony.gutierrez@amd.com# met: redistributions of source code must retain the above copyright 911308Santhony.gutierrez@amd.com# notice, this list of conditions and the following disclaimer; 1011308Santhony.gutierrez@amd.com# redistributions in binary form must reproduce the above copyright 1111308Santhony.gutierrez@amd.com# notice, this list of conditions and the following disclaimer in the 1211308Santhony.gutierrez@amd.com# documentation and/or other materials provided with the distribution; 1311308Santhony.gutierrez@amd.com# neither the name of the copyright holders nor the names of its 1411308Santhony.gutierrez@amd.com# contributors may be used to endorse or promote products derived from 1511308Santhony.gutierrez@amd.com# this software without specific prior written permission. 1611308Santhony.gutierrez@amd.com# 1711308Santhony.gutierrez@amd.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1811308Santhony.gutierrez@amd.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1911308Santhony.gutierrez@amd.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2011308Santhony.gutierrez@amd.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2111308Santhony.gutierrez@amd.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2211308Santhony.gutierrez@amd.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2311308Santhony.gutierrez@amd.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2411308Santhony.gutierrez@amd.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2511308Santhony.gutierrez@amd.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2611308Santhony.gutierrez@amd.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2711308Santhony.gutierrez@amd.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2811308Santhony.gutierrez@amd.com# 2911308Santhony.gutierrez@amd.com# Authors: Steve Reinhardt 3011308Santhony.gutierrez@amd.com 3111308Santhony.gutierrez@amd.com################################################### 3211308Santhony.gutierrez@amd.com# 3311308Santhony.gutierrez@amd.com# SCons top-level build description (SConstruct) file. 3411308Santhony.gutierrez@amd.com# 3511308Santhony.gutierrez@amd.com# While in this directory ('m5'), just type 'scons' to build the default 3611308Santhony.gutierrez@amd.com# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 3711308Santhony.gutierrez@amd.com# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 3811308Santhony.gutierrez@amd.com# the optimized full-system version). 3911308Santhony.gutierrez@amd.com# 4011308Santhony.gutierrez@amd.com# You can build M5 in a different directory as long as there is a 4111308Santhony.gutierrez@amd.com# 'build/<CONFIG>' somewhere along the target path. The build system 4211308Santhony.gutierrez@amd.com# expects that all configs under the same build directory are being 4311308Santhony.gutierrez@amd.com# built for the same host system. 4411308Santhony.gutierrez@amd.com# 4511308Santhony.gutierrez@amd.com# Examples: 4611308Santhony.gutierrez@amd.com# 4711308Santhony.gutierrez@amd.com# The following two commands are equivalent. The '-u' option tells 4811308Santhony.gutierrez@amd.com# scons to search up the directory tree for this SConstruct file. 4911308Santhony.gutierrez@amd.com# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 5011308Santhony.gutierrez@amd.com# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 5111308Santhony.gutierrez@amd.com# 5211308Santhony.gutierrez@amd.com# The following two commands are equivalent and demonstrate building 5311308Santhony.gutierrez@amd.com# in a directory outside of the source tree. The '-C' option tells 5411308Santhony.gutierrez@amd.com# scons to chdir to the specified directory to find this SConstruct 5511308Santhony.gutierrez@amd.com# file. 5611308Santhony.gutierrez@amd.com# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 5711308Santhony.gutierrez@amd.com# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 5811308Santhony.gutierrez@amd.com# 5911308Santhony.gutierrez@amd.com# You can use 'scons -H' to print scons options. If you're in this 6011308Santhony.gutierrez@amd.com# 'm5' directory (or use -u or -C to tell scons where to find this 6111308Santhony.gutierrez@amd.com# file), you can use 'scons -h' to print all the M5-specific build 6211308Santhony.gutierrez@amd.com# options as well. 6311308Santhony.gutierrez@amd.com# 6411308Santhony.gutierrez@amd.com################################################### 6511308Santhony.gutierrez@amd.com 6611308Santhony.gutierrez@amd.comimport sys 6711308Santhony.gutierrez@amd.comimport os 6811308Santhony.gutierrez@amd.comimport re 6911308Santhony.gutierrez@amd.com 7011308Santhony.gutierrez@amd.comfrom os.path import isdir, isfile, join as joinpath 7111308Santhony.gutierrez@amd.com 7211308Santhony.gutierrez@amd.comimport SCons 7311308Santhony.gutierrez@amd.com 7411308Santhony.gutierrez@amd.com# Check for recent-enough Python and SCons versions. If your system's 7511308Santhony.gutierrez@amd.com# default installation of Python is not recent enough, you can use a 7611308Santhony.gutierrez@amd.com# non-default installation of the Python interpreter by either (1) 7711308Santhony.gutierrez@amd.com# rearranging your PATH so that scons finds the non-default 'python' 7811308Santhony.gutierrez@amd.com# first or (2) explicitly invoking an alternative interpreter on the 7911308Santhony.gutierrez@amd.com# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 8011308Santhony.gutierrez@amd.comEnsurePythonVersion(2,4) 8111308Santhony.gutierrez@amd.com 8211308Santhony.gutierrez@amd.com# Import subprocess after we check the version since it doesn't exist in 8311308Santhony.gutierrez@amd.com# Python < 2.4. 8411308Santhony.gutierrez@amd.comimport subprocess 8511308Santhony.gutierrez@amd.com 8611534Sjohn.kalamatianos@amd.com# helper function: compare arrays or strings of version numbers. 8711308Santhony.gutierrez@amd.com# E.g., compare_version((1,3,25), (1,4,1)') 8811308Santhony.gutierrez@amd.com# returns -1, 0, 1 if v1 is <, ==, > v2 8911308Santhony.gutierrez@amd.comdef compare_versions(v1, v2): 9011308Santhony.gutierrez@amd.com def make_version_list(v): 9111308Santhony.gutierrez@amd.com if isinstance(v, (list,tuple)): 9211308Santhony.gutierrez@amd.com return v 9311308Santhony.gutierrez@amd.com elif isinstance(v, str): 9411534Sjohn.kalamatianos@amd.com return map(lambda x: int(re.match('\d+', x).group()), v.split('.')) 9511308Santhony.gutierrez@amd.com else: 9611308Santhony.gutierrez@amd.com raise TypeError 9711534Sjohn.kalamatianos@amd.com 9811534Sjohn.kalamatianos@amd.com v1 = make_version_list(v1) 9911308Santhony.gutierrez@amd.com v2 = make_version_list(v2) 10011534Sjohn.kalamatianos@amd.com # Compare corresponding elements of lists 10111308Santhony.gutierrez@amd.com for n1,n2 in zip(v1, v2): 10211308Santhony.gutierrez@amd.com if n1 < n2: return -1 10311308Santhony.gutierrez@amd.com if n1 > n2: return 1 10411308Santhony.gutierrez@amd.com # all corresponding values are equal... see if one has extra values 10511308Santhony.gutierrez@amd.com if len(v1) < len(v2): return -1 10611308Santhony.gutierrez@amd.com if len(v1) > len(v2): return 1 10711308Santhony.gutierrez@amd.com return 0 10811308Santhony.gutierrez@amd.com 10911308Santhony.gutierrez@amd.com# SCons version numbers need special processing because they can have 11011308Santhony.gutierrez@amd.com# charecters and an release date embedded in them. This function does 11111308Santhony.gutierrez@amd.com# the magic to extract them in a similar way to the SCons internal function 11211308Santhony.gutierrez@amd.com# function does and then checks that the current version is not contained in 11311308Santhony.gutierrez@amd.com# a list of version tuples (bad_ver_strs) 11411308Santhony.gutierrez@amd.comdef CheckSCons(bad_ver_strs): 11511308Santhony.gutierrez@amd.com def scons_ver(v): 11611308Santhony.gutierrez@amd.com num_parts = v.split(' ')[0].split('.') 11711308Santhony.gutierrez@amd.com major = int(num_parts[0]) 11811308Santhony.gutierrez@amd.com minor = int(re.match('\d+', num_parts[1]).group()) 11911308Santhony.gutierrez@amd.com rev = 0 12011308Santhony.gutierrez@amd.com rdate = 0 12111308Santhony.gutierrez@amd.com if len(num_parts) > 2: 12211308Santhony.gutierrez@amd.com try: rev = int(re.match('\d+', num_parts[2]).group()) 12311308Santhony.gutierrez@amd.com except: pass 12411308Santhony.gutierrez@amd.com rev_parts = num_parts[2].split('d') 12511308Santhony.gutierrez@amd.com if len(rev_parts) > 1: 12611308Santhony.gutierrez@amd.com rdate = int(re.match('\d+', rev_parts[1]).group()) 12711308Santhony.gutierrez@amd.com 12811308Santhony.gutierrez@amd.com return (major, minor, rev, rdate) 12911308Santhony.gutierrez@amd.com 13011308Santhony.gutierrez@amd.com sc_ver = scons_ver(SCons.__version__) 13111308Santhony.gutierrez@amd.com for bad_ver in bad_ver_strs: 13211308Santhony.gutierrez@amd.com bv = (scons_ver(bad_ver[0]), scons_ver(bad_ver[1])) 13311308Santhony.gutierrez@amd.com if compare_versions(sc_ver, bv[0]) != -1 and\ 13411308Santhony.gutierrez@amd.com compare_versions(sc_ver, bv[1]) != 1: 13511308Santhony.gutierrez@amd.com print "The version of SCons that you have installed: ", SCons.__version__ 13611308Santhony.gutierrez@amd.com print "has a bug that prevents it from working correctly with M5." 13711308Santhony.gutierrez@amd.com print "Please install a version NOT contained within the following", 13811308Santhony.gutierrez@amd.com print "ranges (inclusive):" 13911308Santhony.gutierrez@amd.com for bad_ver in bad_ver_strs: 14011308Santhony.gutierrez@amd.com print " %s - %s" % bad_ver 14111308Santhony.gutierrez@amd.com Exit(2) 14211308Santhony.gutierrez@amd.com 14311308Santhony.gutierrez@amd.comCheckSCons(( 14411308Santhony.gutierrez@amd.com # We need a version that is 0.96.91 or newer 14511308Santhony.gutierrez@amd.com ('0.0.0', '0.96.90'), 14611308Santhony.gutierrez@amd.com )) 14711308Santhony.gutierrez@amd.com 14811308Santhony.gutierrez@amd.com 14911308Santhony.gutierrez@amd.com# The absolute path to the current directory (where this file lives). 15011308Santhony.gutierrez@amd.comROOT = Dir('.').abspath 15111308Santhony.gutierrez@amd.com 15211308Santhony.gutierrez@amd.com# Path to the M5 source tree. 15311308Santhony.gutierrez@amd.comSRCDIR = joinpath(ROOT, 'src') 15411308Santhony.gutierrez@amd.com 15511308Santhony.gutierrez@amd.com# tell python where to find m5 python code 15611308Santhony.gutierrez@amd.comsys.path.append(joinpath(ROOT, 'src/python')) 15711308Santhony.gutierrez@amd.com 15811639Salexandru.dutu@amd.comdef check_style_hook(ui): 15911308Santhony.gutierrez@amd.com ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 16011639Salexandru.dutu@amd.com style_hook = ui.config('hooks', 'pretxncommit.style', None) 16111639Salexandru.dutu@amd.com 16211639Salexandru.dutu@amd.com if not style_hook: 16311639Salexandru.dutu@amd.com print """\ 16411308Santhony.gutierrez@amd.comYou're missing the M5 style hook. 16511308Santhony.gutierrez@amd.comPlease install the hook so we can ensure that all code fits a common style. 16611308Santhony.gutierrez@amd.com 16711639Salexandru.dutu@amd.comAll you'd need to do is add the following lines to your repository .hg/hgrc 16811308Santhony.gutierrez@amd.comor your personal .hgrc 16911308Santhony.gutierrez@amd.com---------------- 17011308Santhony.gutierrez@amd.com 17111308Santhony.gutierrez@amd.com[extensions] 17211308Santhony.gutierrez@amd.comstyle = %s/util/style.py 17311308Santhony.gutierrez@amd.com 17411308Santhony.gutierrez@amd.com[hooks] 17511308Santhony.gutierrez@amd.compretxncommit.style = python:style.check_whitespace 17611308Santhony.gutierrez@amd.com""" % (ROOT) 17711308Santhony.gutierrez@amd.com sys.exit(1) 17811308Santhony.gutierrez@amd.com 17911308Santhony.gutierrez@amd.comif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 18011308Santhony.gutierrez@amd.com try: 18111308Santhony.gutierrez@amd.com from mercurial import ui 18211308Santhony.gutierrez@amd.com check_style_hook(ui.ui()) 18311308Santhony.gutierrez@amd.com except ImportError: 18411308Santhony.gutierrez@amd.com pass 18511308Santhony.gutierrez@amd.com 18611308Santhony.gutierrez@amd.com################################################### 18711308Santhony.gutierrez@amd.com# 18811308Santhony.gutierrez@amd.com# Figure out which configurations to set up based on the path(s) of 18911308Santhony.gutierrez@amd.com# the target(s). 19011308Santhony.gutierrez@amd.com# 19111308Santhony.gutierrez@amd.com################################################### 19211308Santhony.gutierrez@amd.com 19311308Santhony.gutierrez@amd.com# Find default configuration & binary. 19411308Santhony.gutierrez@amd.comDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 19511308Santhony.gutierrez@amd.com 19611639Salexandru.dutu@amd.com# helper function: find last occurrence of element in list 19711639Salexandru.dutu@amd.comdef rfind(l, elt, offs = -1): 19811639Salexandru.dutu@amd.com for i in range(len(l)+offs, 0, -1): 19911639Salexandru.dutu@amd.com if l[i] == elt: 20011639Salexandru.dutu@amd.com return i 20111639Salexandru.dutu@amd.com raise ValueError, "element not found" 20211639Salexandru.dutu@amd.com 20311639Salexandru.dutu@amd.com# Each target must have 'build' in the interior of the path; the 20411639Salexandru.dutu@amd.com# directory below this will determine the build parameters. For 20511639Salexandru.dutu@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 20611639Salexandru.dutu@amd.com# recognize that ALPHA_SE specifies the configuration because it 20711308Santhony.gutierrez@amd.com# follow 'build' in the bulid path. 20811639Salexandru.dutu@amd.com 20911308Santhony.gutierrez@amd.com# Generate absolute paths to targets so we can see where the build dir is 21011308Santhony.gutierrez@amd.comif COMMAND_LINE_TARGETS: 21111639Salexandru.dutu@amd.com # Ask SCons which directory it was invoked from 21211308Santhony.gutierrez@amd.com launch_dir = GetLaunchDir() 21311639Salexandru.dutu@amd.com # Make targets relative to invocation directory 21411308Santhony.gutierrez@amd.com abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 21511639Salexandru.dutu@amd.com COMMAND_LINE_TARGETS) 21611308Santhony.gutierrez@amd.comelse: 21711639Salexandru.dutu@amd.com # Default targets are relative to root of tree 21811308Santhony.gutierrez@amd.com abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 21911639Salexandru.dutu@amd.com DEFAULT_TARGETS) 22011639Salexandru.dutu@amd.com 22111639Salexandru.dutu@amd.com 22211639Salexandru.dutu@amd.com# Generate a list of the unique build roots and configs that the 22311639Salexandru.dutu@amd.com# collected targets reference. 22411308Santhony.gutierrez@amd.combuild_paths = [] 22511639Salexandru.dutu@amd.combuild_root = None 22611639Salexandru.dutu@amd.comfor t in abs_targets: 22711308Santhony.gutierrez@amd.com path_dirs = t.split('/') 22811308Santhony.gutierrez@amd.com try: 22911308Santhony.gutierrez@amd.com build_top = rfind(path_dirs, 'build', -2) 23011308Santhony.gutierrez@amd.com except: 23111308Santhony.gutierrez@amd.com print "Error: no non-leaf 'build' dir found on target path", t 23211308Santhony.gutierrez@amd.com Exit(1) 23311308Santhony.gutierrez@amd.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 23411639Salexandru.dutu@amd.com if not build_root: 23511308Santhony.gutierrez@amd.com build_root = this_build_root 23611639Salexandru.dutu@amd.com else: 23711308Santhony.gutierrez@amd.com if this_build_root != build_root: 23811639Salexandru.dutu@amd.com print "Error: build targets not under same build root\n"\ 23911308Santhony.gutierrez@amd.com " %s\n %s" % (build_root, this_build_root) 24011308Santhony.gutierrez@amd.com Exit(1) 24111639Salexandru.dutu@amd.com build_path = joinpath('/',*path_dirs[:build_top+2]) 24211308Santhony.gutierrez@amd.com if build_path not in build_paths: 24311639Salexandru.dutu@amd.com build_paths.append(build_path) 24411308Santhony.gutierrez@amd.com 24511639Salexandru.dutu@amd.com# Make sure build_root exists (might not if this is the first build there) 24611308Santhony.gutierrez@amd.comif not isdir(build_root): 24711308Santhony.gutierrez@amd.com os.mkdir(build_root) 24811639Salexandru.dutu@amd.com 24911308Santhony.gutierrez@amd.com################################################### 25011308Santhony.gutierrez@amd.com# 25111639Salexandru.dutu@amd.com# Set up the default build environment. This environment is copied 25211639Salexandru.dutu@amd.com# and modified according to each selected configuration. 25311308Santhony.gutierrez@amd.com# 25411308Santhony.gutierrez@amd.com################################################### 25511308Santhony.gutierrez@amd.com 25611308Santhony.gutierrez@amd.comenv = Environment(ENV = os.environ, # inherit user's environment vars 25711308Santhony.gutierrez@amd.com ROOT = ROOT, 25811308Santhony.gutierrez@amd.com SRCDIR = SRCDIR) 25911308Santhony.gutierrez@amd.com 26011308Santhony.gutierrez@amd.comExport('env') 26111308Santhony.gutierrez@amd.com 26211308Santhony.gutierrez@amd.comenv.SConsignFile(joinpath(build_root,"sconsign")) 26311308Santhony.gutierrez@amd.com 26411308Santhony.gutierrez@amd.com# Default duplicate option is to use hard links, but this messes up 26511308Santhony.gutierrez@amd.com# when you use emacs to edit a file in the target dir, as emacs moves 26611308Santhony.gutierrez@amd.com# file to file~ then copies to file, breaking the link. Symbolic 26711308Santhony.gutierrez@amd.com# (soft) links work better. 26811308Santhony.gutierrez@amd.comenv.SetOption('duplicate', 'soft-copy') 26911308Santhony.gutierrez@amd.com 27011308Santhony.gutierrez@amd.com# I waffle on this setting... it does avoid a few painful but 27111308Santhony.gutierrez@amd.com# unnecessary builds, but it also seems to make trivial builds take 27211308Santhony.gutierrez@amd.com# noticeably longer. 27311308Santhony.gutierrez@amd.comif False: 27411308Santhony.gutierrez@amd.com env.TargetSignatures('content') 27511308Santhony.gutierrez@amd.com 27611308Santhony.gutierrez@amd.com# 27711308Santhony.gutierrez@amd.com# Set up global sticky options... these are common to an entire build 27811308Santhony.gutierrez@amd.com# tree (not specific to a particular build like ALPHA_SE) 27911308Santhony.gutierrez@amd.com# 28011308Santhony.gutierrez@amd.com 28111308Santhony.gutierrez@amd.com# Option validators & converters for global sticky options 28211308Santhony.gutierrez@amd.comdef PathListMakeAbsolute(val): 28311308Santhony.gutierrez@amd.com if not val: 28411308Santhony.gutierrez@amd.com return val 28511308Santhony.gutierrez@amd.com f = lambda p: os.path.abspath(os.path.expanduser(p)) 28611308Santhony.gutierrez@amd.com return ':'.join(map(f, val.split(':'))) 28711308Santhony.gutierrez@amd.com 28811308Santhony.gutierrez@amd.comdef PathListAllExist(key, val, env): 28911308Santhony.gutierrez@amd.com if not val: 29011308Santhony.gutierrez@amd.com return 29111308Santhony.gutierrez@amd.com paths = val.split(':') 29211308Santhony.gutierrez@amd.com for path in paths: 29311308Santhony.gutierrez@amd.com if not isdir(path): 29411308Santhony.gutierrez@amd.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 29511308Santhony.gutierrez@amd.com 29611308Santhony.gutierrez@amd.comglobal_sticky_opts_file = joinpath(build_root, 'options.global') 29711308Santhony.gutierrez@amd.com 29811308Santhony.gutierrez@amd.comglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS) 29911308Santhony.gutierrez@amd.com 30011534Sjohn.kalamatianos@amd.comglobal_sticky_opts.AddOptions( 30111308Santhony.gutierrez@amd.com ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 30211534Sjohn.kalamatianos@amd.com ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 30311308Santhony.gutierrez@amd.com ('BATCH', 'Use batch pool for build and tests', False), 30411308Santhony.gutierrez@amd.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 30511308Santhony.gutierrez@amd.com ('EXTRAS', 'Add Extra directories to the compilation', '', 30611308Santhony.gutierrez@amd.com PathListAllExist, PathListMakeAbsolute) 30711308Santhony.gutierrez@amd.com ) 30811308Santhony.gutierrez@amd.com 30911308Santhony.gutierrez@amd.com 31011308Santhony.gutierrez@amd.com# base help text 31111308Santhony.gutierrez@amd.comhelp_text = ''' 31211308Santhony.gutierrez@amd.comUsage: scons [scons options] [build options] [target(s)] 31311308Santhony.gutierrez@amd.com 31411308Santhony.gutierrez@amd.com''' 31511308Santhony.gutierrez@amd.com 31611308Santhony.gutierrez@amd.comhelp_text += "Global sticky options:\n" \ 31711308Santhony.gutierrez@amd.com + global_sticky_opts.GenerateHelpText(env) 31811308Santhony.gutierrez@amd.com 31911308Santhony.gutierrez@amd.com# Update env with values from ARGUMENTS & file global_sticky_opts_file 32011308Santhony.gutierrez@amd.comglobal_sticky_opts.Update(env) 32111308Santhony.gutierrez@amd.com 32211308Santhony.gutierrez@amd.com# Save sticky option settings back to current options file 32311308Santhony.gutierrez@amd.comglobal_sticky_opts.Save(global_sticky_opts_file, env) 32411308Santhony.gutierrez@amd.com 32511308Santhony.gutierrez@amd.com# Parse EXTRAS option to build list of all directories where we're 32611308Santhony.gutierrez@amd.com# look for sources etc. This list is exported as base_dir_list. 32711308Santhony.gutierrez@amd.combase_dir = joinpath(ROOT, 'src') 32811308Santhony.gutierrez@amd.comif env['EXTRAS']: 32911308Santhony.gutierrez@amd.com extras_dir_list = env['EXTRAS'].split(':') 33011308Santhony.gutierrez@amd.comelse: 33111308Santhony.gutierrez@amd.com extras_dir_list = [] 33211308Santhony.gutierrez@amd.com 33311308Santhony.gutierrez@amd.comExport('base_dir') 33411308Santhony.gutierrez@amd.comExport('extras_dir_list') 33511308Santhony.gutierrez@amd.com 33611639Salexandru.dutu@amd.com# M5_PLY is used by isa_parser.py to find the PLY package. 33711308Santhony.gutierrez@amd.comenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 33811308Santhony.gutierrez@amd.comenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 33911308Santhony.gutierrez@amd.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 34011308Santhony.gutierrez@amd.com close_fds=True).communicate()[0].find('g++') >= 0 34111308Santhony.gutierrez@amd.comenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 34211308Santhony.gutierrez@amd.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 34311308Santhony.gutierrez@amd.com close_fds=True).communicate()[0].find('Sun C++') >= 0 34411308Santhony.gutierrez@amd.comenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 34511308Santhony.gutierrez@amd.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 34611308Santhony.gutierrez@amd.com close_fds=True).communicate()[0].find('Intel') >= 0 34711308Santhony.gutierrez@amd.comif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 34811308Santhony.gutierrez@amd.com print 'Error: How can we have two at the same time?' 34911308Santhony.gutierrez@amd.com Exit(1) 35011308Santhony.gutierrez@amd.com 35111308Santhony.gutierrez@amd.com 35211308Santhony.gutierrez@amd.com# Set up default C++ compiler flags 35311308Santhony.gutierrez@amd.comif env['GCC']: 35411308Santhony.gutierrez@amd.com env.Append(CCFLAGS='-pipe') 35511308Santhony.gutierrez@amd.com env.Append(CCFLAGS='-fno-strict-aliasing') 35611308Santhony.gutierrez@amd.com env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 35711308Santhony.gutierrez@amd.com env.Append(CXXFLAGS='-Wno-deprecated') 35811308Santhony.gutierrez@amd.comelif env['ICC']: 35911308Santhony.gutierrez@amd.com pass #Fix me... add warning flags once we clean up icc warnings 36011308Santhony.gutierrez@amd.comelif env['SUNCC']: 36111308Santhony.gutierrez@amd.com env.Append(CCFLAGS='-Qoption ccfe') 36211308Santhony.gutierrez@amd.com env.Append(CCFLAGS='-features=gcc') 36311308Santhony.gutierrez@amd.com env.Append(CCFLAGS='-features=extensions') 36411308Santhony.gutierrez@amd.com env.Append(CCFLAGS='-library=stlport4') 36511308Santhony.gutierrez@amd.com env.Append(CCFLAGS='-xar') 36611308Santhony.gutierrez@amd.com# env.Append(CCFLAGS='-instances=semiexplicit') 36711308Santhony.gutierrez@amd.comelse: 36811308Santhony.gutierrez@amd.com print 'Error: Don\'t know what compiler options to use for your compiler.' 369 print ' Please fix SConstruct and src/SConscript and try again.' 370 Exit(1) 371 372# Do this after we save setting back, or else we'll tack on an 373# extra 'qdo' every time we run scons. 374if env['BATCH']: 375 env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 376 env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 377 env['AS'] = env['BATCH_CMD'] + ' ' + env['AS'] 378 env['AR'] = env['BATCH_CMD'] + ' ' + env['AR'] 379 env['RANLIB'] = env['BATCH_CMD'] + ' ' + env['RANLIB'] 380 381if sys.platform == 'cygwin': 382 # cygwin has some header file issues... 383 env.Append(CCFLAGS=Split("-Wno-uninitialized")) 384env.Append(CPPPATH=[Dir('ext/dnet')]) 385 386# Check for SWIG 387if not env.has_key('SWIG'): 388 print 'Error: SWIG utility not found.' 389 print ' Please install (see http://www.swig.org) and retry.' 390 Exit(1) 391 392# Check for appropriate SWIG version 393swig_version = os.popen('swig -version').read().split() 394# First 3 words should be "SWIG Version x.y.z" 395if len(swig_version) < 3 or \ 396 swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 397 print 'Error determining SWIG version.' 398 Exit(1) 399 400min_swig_version = '1.3.28' 401if compare_versions(swig_version[2], min_swig_version) < 0: 402 print 'Error: SWIG version', min_swig_version, 'or newer required.' 403 print ' Installed version:', swig_version[2] 404 Exit(1) 405 406# Set up SWIG flags & scanner 407swig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 408env.Append(SWIGFLAGS=swig_flags) 409 410# filter out all existing swig scanners, they mess up the dependency 411# stuff for some reason 412scanners = [] 413for scanner in env['SCANNERS']: 414 skeys = scanner.skeys 415 if skeys == '.i': 416 continue 417 418 if isinstance(skeys, (list, tuple)) and '.i' in skeys: 419 continue 420 421 scanners.append(scanner) 422 423# add the new swig scanner that we like better 424from SCons.Scanner import ClassicCPP as CPPScanner 425swig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 426scanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 427 428# replace the scanners list that has what we want 429env['SCANNERS'] = scanners 430 431# Add a custom Check function to the Configure context so that we can 432# figure out if the compiler adds leading underscores to global 433# variables. This is needed for the autogenerated asm files that we 434# use for embedding the python code. 435def CheckLeading(context): 436 context.Message("Checking for leading underscore in global variables...") 437 # 1) Define a global variable called x from asm so the C compiler 438 # won't change the symbol at all. 439 # 2) Declare that variable. 440 # 3) Use the variable 441 # 442 # If the compiler prepends an underscore, this will successfully 443 # link because the external symbol 'x' will be called '_x' which 444 # was defined by the asm statement. If the compiler does not 445 # prepend an underscore, this will not successfully link because 446 # '_x' will have been defined by assembly, while the C portion of 447 # the code will be trying to use 'x' 448 ret = context.TryLink(''' 449 asm(".globl _x; _x: .byte 0"); 450 extern int x; 451 int main() { return x; } 452 ''', extension=".c") 453 context.env.Append(LEADING_UNDERSCORE=ret) 454 context.Result(ret) 455 return ret 456 457# Platform-specific configuration. Note again that we assume that all 458# builds under a given build root run on the same host platform. 459conf = Configure(env, 460 conf_dir = joinpath(build_root, '.scons_config'), 461 log_file = joinpath(build_root, 'scons_config.log'), 462 custom_tests = { 'CheckLeading' : CheckLeading }) 463 464# Check for leading underscores. Don't really need to worry either 465# way so don't need to check the return code. 466conf.CheckLeading() 467 468# Check if we should compile a 64 bit binary on Mac OS X/Darwin 469try: 470 import platform 471 uname = platform.uname() 472 if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 473 if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 474 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 475 close_fds=True).communicate()[0][0]): 476 env.Append(CCFLAGS='-arch x86_64') 477 env.Append(CFLAGS='-arch x86_64') 478 env.Append(LINKFLAGS='-arch x86_64') 479 env.Append(ASFLAGS='-arch x86_64') 480except: 481 pass 482 483# Recent versions of scons substitute a "Null" object for Configure() 484# when configuration isn't necessary, e.g., if the "--help" option is 485# present. Unfortuantely this Null object always returns false, 486# breaking all our configuration checks. We replace it with our own 487# more optimistic null object that returns True instead. 488if not conf: 489 def NullCheck(*args, **kwargs): 490 return True 491 492 class NullConf: 493 def __init__(self, env): 494 self.env = env 495 def Finish(self): 496 return self.env 497 def __getattr__(self, mname): 498 return NullCheck 499 500 conf = NullConf(env) 501 502# Find Python include and library directories for embedding the 503# interpreter. For consistency, we will use the same Python 504# installation used to run scons (and thus this script). If you want 505# to link in an alternate version, see above for instructions on how 506# to invoke scons with a different copy of the Python interpreter. 507 508# Get brief Python version name (e.g., "python2.4") for locating 509# include & library files 510py_version_name = 'python' + sys.version[:3] 511 512# include path, e.g. /usr/local/include/python2.4 513py_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 514env.Append(CPPPATH = py_header_path) 515# verify that it works 516if not conf.CheckHeader('Python.h', '<>'): 517 print "Error: can't find Python.h header in", py_header_path 518 Exit(1) 519 520# add library path too if it's not in the default place 521py_lib_path = None 522if sys.exec_prefix != '/usr': 523 py_lib_path = joinpath(sys.exec_prefix, 'lib') 524elif sys.platform == 'cygwin': 525 # cygwin puts the .dll in /bin for some reason 526 py_lib_path = '/bin' 527if py_lib_path: 528 env.Append(LIBPATH = py_lib_path) 529 print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 530if not conf.CheckLib(py_version_name): 531 print "Error: can't find Python library", py_version_name 532 Exit(1) 533 534# On Solaris you need to use libsocket for socket ops 535if not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 536 if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 537 print "Can't find library with socket calls (e.g. accept())" 538 Exit(1) 539 540# Check for zlib. If the check passes, libz will be automatically 541# added to the LIBS environment variable. 542if not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 543 print 'Error: did not find needed zlib compression library '\ 544 'and/or zlib.h header file.' 545 print ' Please install zlib and try again.' 546 Exit(1) 547 548# Check for <fenv.h> (C99 FP environment control) 549have_fenv = conf.CheckHeader('fenv.h', '<>') 550if not have_fenv: 551 print "Warning: Header file <fenv.h> not found." 552 print " This host has no IEEE FP rounding mode control." 553 554# Check for mysql. 555mysql_config = WhereIs('mysql_config') 556have_mysql = mysql_config != None 557 558# Check MySQL version. 559if have_mysql: 560 mysql_version = os.popen(mysql_config + ' --version').read() 561 min_mysql_version = '4.1' 562 if compare_versions(mysql_version, min_mysql_version) < 0: 563 print 'Warning: MySQL', min_mysql_version, 'or newer required.' 564 print ' Version', mysql_version, 'detected.' 565 have_mysql = False 566 567# Set up mysql_config commands. 568if have_mysql: 569 mysql_config_include = mysql_config + ' --include' 570 if os.system(mysql_config_include + ' > /dev/null') != 0: 571 # older mysql_config versions don't support --include, use 572 # --cflags instead 573 mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 574 # This seems to work in all versions 575 mysql_config_libs = mysql_config + ' --libs' 576 577env = conf.Finish() 578 579# Define the universe of supported ISAs 580all_isa_list = [ ] 581Export('all_isa_list') 582 583# Define the universe of supported CPU models 584all_cpu_list = [ ] 585default_cpus = [ ] 586Export('all_cpu_list', 'default_cpus') 587 588# Sticky options get saved in the options file so they persist from 589# one invocation to the next (unless overridden, in which case the new 590# value becomes sticky). 591sticky_opts = Options(args=ARGUMENTS) 592Export('sticky_opts') 593 594# Non-sticky options only apply to the current build. 595nonsticky_opts = Options(args=ARGUMENTS) 596Export('nonsticky_opts') 597 598# Walk the tree and execute all SConsopts scripts that wil add to the 599# above options 600for bdir in [ base_dir ] + extras_dir_list: 601 for root, dirs, files in os.walk(bdir): 602 if 'SConsopts' in files: 603 print "Reading", joinpath(root, 'SConsopts') 604 SConscript(joinpath(root, 'SConsopts')) 605 606all_isa_list.sort() 607all_cpu_list.sort() 608default_cpus.sort() 609 610sticky_opts.AddOptions( 611 EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 612 BoolOption('FULL_SYSTEM', 'Full-system support', False), 613 # There's a bug in scons 0.96.1 that causes ListOptions with list 614 # values (more than one value) not to be able to be restored from 615 # a saved option file. If this causes trouble then upgrade to 616 # scons 0.96.90 or later. 617 ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 618 BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 619 BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 620 False), 621 BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 622 False), 623 BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 624 False), 625 BoolOption('SS_COMPATIBLE_FP', 626 'Make floating-point results compatible with SimpleScalar', 627 False), 628 BoolOption('USE_SSE2', 629 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 630 False), 631 BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 632 BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 633 BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 634 ) 635 636nonsticky_opts.AddOptions( 637 BoolOption('update_ref', 'Update test reference outputs', False) 638 ) 639 640# These options get exported to #defines in config/*.hh (see src/SConscript). 641env.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 642 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 643 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 644 'USE_CHECKER', 'TARGET_ISA'] 645 646# Define a handy 'no-op' action 647def no_action(target, source, env): 648 return 0 649 650env.NoAction = Action(no_action, None) 651 652################################################### 653# 654# Define a SCons builder for configuration flag headers. 655# 656################################################### 657 658# This function generates a config header file that #defines the 659# option symbol to the current option setting (0 or 1). The source 660# operands are the name of the option and a Value node containing the 661# value of the option. 662def build_config_file(target, source, env): 663 (option, value) = [s.get_contents() for s in source] 664 f = file(str(target[0]), 'w') 665 print >> f, '#define', option, value 666 f.close() 667 return None 668 669# Generate the message to be printed when building the config file. 670def build_config_file_string(target, source, env): 671 (option, value) = [s.get_contents() for s in source] 672 return "Defining %s as %s in %s." % (option, value, target[0]) 673 674# Combine the two functions into a scons Action object. 675config_action = Action(build_config_file, build_config_file_string) 676 677# The emitter munges the source & target node lists to reflect what 678# we're really doing. 679def config_emitter(target, source, env): 680 # extract option name from Builder arg 681 option = str(target[0]) 682 # True target is config header file 683 target = joinpath('config', option.lower() + '.hh') 684 val = env[option] 685 if isinstance(val, bool): 686 # Force value to 0/1 687 val = int(val) 688 elif isinstance(val, str): 689 val = '"' + val + '"' 690 691 # Sources are option name & value (packaged in SCons Value nodes) 692 return ([target], [Value(option), Value(val)]) 693 694config_builder = Builder(emitter = config_emitter, action = config_action) 695 696env.Append(BUILDERS = { 'ConfigFile' : config_builder }) 697 698################################################### 699# 700# Define a SCons builder for copying files. This is used by the 701# Python zipfile code in src/python/SConscript, but is placed up here 702# since it's potentially more generally applicable. 703# 704################################################### 705 706copy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 707 708env.Append(BUILDERS = { 'CopyFile' : copy_builder }) 709 710################################################### 711# 712# Define a simple SCons builder to concatenate files. 713# 714# Used to append the Python zip archive to the executable. 715# 716################################################### 717 718concat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 719 'chmod +x $TARGET'])) 720 721env.Append(BUILDERS = { 'Concat' : concat_builder }) 722 723 724# libelf build is shared across all configs in the build root. 725env.SConscript('ext/libelf/SConscript', 726 build_dir = joinpath(build_root, 'libelf'), 727 exports = 'env') 728 729# gzstream build is shared across all configs in the build root. 730env.SConscript('ext/gzstream/SConscript', 731 build_dir = joinpath(build_root, 'gzstream'), 732 exports = 'env') 733 734################################################### 735# 736# This function is used to set up a directory with switching headers 737# 738################################################### 739 740env['ALL_ISA_LIST'] = all_isa_list 741def make_switching_dir(dirname, switch_headers, env): 742 # Generate the header. target[0] is the full path of the output 743 # header to generate. 'source' is a dummy variable, since we get the 744 # list of ISAs from env['ALL_ISA_LIST']. 745 def gen_switch_hdr(target, source, env): 746 fname = str(target[0]) 747 basename = os.path.basename(fname) 748 f = open(fname, 'w') 749 f.write('#include "arch/isa_specific.hh"\n') 750 cond = '#if' 751 for isa in all_isa_list: 752 f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 753 % (cond, isa.upper(), dirname, isa, basename)) 754 cond = '#elif' 755 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 756 f.close() 757 return 0 758 759 # String to print when generating header 760 def gen_switch_hdr_string(target, source, env): 761 return "Generating switch header " + str(target[0]) 762 763 # Build SCons Action object. 'varlist' specifies env vars that this 764 # action depends on; when env['ALL_ISA_LIST'] changes these actions 765 # should get re-executed. 766 switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 767 varlist=['ALL_ISA_LIST']) 768 769 # Instantiate actions for each header 770 for hdr in switch_headers: 771 env.Command(hdr, [], switch_hdr_action) 772Export('make_switching_dir') 773 774################################################### 775# 776# Define build environments for selected configurations. 777# 778################################################### 779 780# rename base env 781base_env = env 782 783for build_path in build_paths: 784 print "Building in", build_path 785 786 # Make a copy of the build-root environment to use for this config. 787 env = base_env.Copy() 788 env['BUILDDIR'] = build_path 789 790 # build_dir is the tail component of build path, and is used to 791 # determine the build parameters (e.g., 'ALPHA_SE') 792 (build_root, build_dir) = os.path.split(build_path) 793 794 # Set env options according to the build directory config. 795 sticky_opts.files = [] 796 # Options for $BUILD_ROOT/$BUILD_DIR are stored in 797 # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 798 # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 799 current_opts_file = joinpath(build_root, 'options', build_dir) 800 if isfile(current_opts_file): 801 sticky_opts.files.append(current_opts_file) 802 print "Using saved options file %s" % current_opts_file 803 else: 804 # Build dir-specific options file doesn't exist. 805 806 # Make sure the directory is there so we can create it later 807 opt_dir = os.path.dirname(current_opts_file) 808 if not isdir(opt_dir): 809 os.mkdir(opt_dir) 810 811 # Get default build options from source tree. Options are 812 # normally determined by name of $BUILD_DIR, but can be 813 # overriden by 'default=' arg on command line. 814 default_opts_file = joinpath('build_opts', 815 ARGUMENTS.get('default', build_dir)) 816 if isfile(default_opts_file): 817 sticky_opts.files.append(default_opts_file) 818 print "Options file %s not found,\n using defaults in %s" \ 819 % (current_opts_file, default_opts_file) 820 else: 821 print "Error: cannot find options file %s or %s" \ 822 % (current_opts_file, default_opts_file) 823 Exit(1) 824 825 # Apply current option settings to env 826 sticky_opts.Update(env) 827 nonsticky_opts.Update(env) 828 829 help_text += "\nSticky options for %s:\n" % build_dir \ 830 + sticky_opts.GenerateHelpText(env) \ 831 + "\nNon-sticky options for %s:\n" % build_dir \ 832 + nonsticky_opts.GenerateHelpText(env) 833 834 # Process option settings. 835 836 if not have_fenv and env['USE_FENV']: 837 print "Warning: <fenv.h> not available; " \ 838 "forcing USE_FENV to False in", build_dir + "." 839 env['USE_FENV'] = False 840 841 if not env['USE_FENV']: 842 print "Warning: No IEEE FP rounding mode control in", build_dir + "." 843 print " FP results may deviate slightly from other platforms." 844 845 if env['EFENCE']: 846 env.Append(LIBS=['efence']) 847 848 if env['USE_MYSQL']: 849 if not have_mysql: 850 print "Warning: MySQL not available; " \ 851 "forcing USE_MYSQL to False in", build_dir + "." 852 env['USE_MYSQL'] = False 853 else: 854 print "Compiling in", build_dir, "with MySQL support." 855 env.ParseConfig(mysql_config_libs) 856 env.ParseConfig(mysql_config_include) 857 858 # Save sticky option settings back to current options file 859 sticky_opts.Save(current_opts_file, env) 860 861 if env['USE_SSE2']: 862 env.Append(CCFLAGS='-msse2') 863 864 # The src/SConscript file sets up the build rules in 'env' according 865 # to the configured options. It returns a list of environments, 866 # one for each variant build (debug, opt, etc.) 867 envList = SConscript('src/SConscript', build_dir = build_path, 868 exports = 'env') 869 870 # Set up the regression tests for each build. 871 for e in envList: 872 SConscript('tests/SConscript', 873 build_dir = joinpath(build_path, 'tests', e.Label), 874 exports = { 'env' : e }, duplicate = False) 875 876Help(help_text) 877 878 879################################################### 880# 881# Let SCons do its thing. At this point SCons will use the defined 882# build environments to build the requested targets. 883# 884################################################### 885 886