SConstruct revision 6143
110260SAndrew.Bardsley@arm.com# -*- mode:python -*- 210260SAndrew.Bardsley@arm.com 310260SAndrew.Bardsley@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company 410260SAndrew.Bardsley@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 510260SAndrew.Bardsley@arm.com# All rights reserved. 610260SAndrew.Bardsley@arm.com# 710260SAndrew.Bardsley@arm.com# Redistribution and use in source and binary forms, with or without 810260SAndrew.Bardsley@arm.com# modification, are permitted provided that the following conditions are 910260SAndrew.Bardsley@arm.com# met: redistributions of source code must retain the above copyright 1010260SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer; 1110260SAndrew.Bardsley@arm.com# redistributions in binary form must reproduce the above copyright 1210260SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer in the 1310315Snilay@cs.wisc.edu# documentation and/or other materials provided with the distribution; 1410260SAndrew.Bardsley@arm.com# neither the name of the copyright holders nor the names of its 1510260SAndrew.Bardsley@arm.com# contributors may be used to endorse or promote products derived from 1610260SAndrew.Bardsley@arm.com# this software without specific prior written permission. 1710260SAndrew.Bardsley@arm.com# 1810260SAndrew.Bardsley@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1910260SAndrew.Bardsley@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2010315Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2110260SAndrew.Bardsley@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2210260SAndrew.Bardsley@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2310260SAndrew.Bardsley@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2410260SAndrew.Bardsley@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2510260SAndrew.Bardsley@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2610753Sstever@gmail.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2710260SAndrew.Bardsley@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2810260SAndrew.Bardsley@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2910260SAndrew.Bardsley@arm.com# 3010260SAndrew.Bardsley@arm.com# Authors: Steve Reinhardt 3110260SAndrew.Bardsley@arm.com# Nathan Binkert 3210260SAndrew.Bardsley@arm.com 3310260SAndrew.Bardsley@arm.com################################################### 3410260SAndrew.Bardsley@arm.com# 3510260SAndrew.Bardsley@arm.com# SCons top-level build description (SConstruct) file. 3610260SAndrew.Bardsley@arm.com# 3710260SAndrew.Bardsley@arm.com# While in this directory ('m5'), just type 'scons' to build the default 3810260SAndrew.Bardsley@arm.com# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 3910260SAndrew.Bardsley@arm.com# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 4010260SAndrew.Bardsley@arm.com# the optimized full-system version). 4110260SAndrew.Bardsley@arm.com# 4210315Snilay@cs.wisc.edu# You can build M5 in a different directory as long as there is a 4310260SAndrew.Bardsley@arm.com# 'build/<CONFIG>' somewhere along the target path. The build system 4410315Snilay@cs.wisc.edu# expects that all configs under the same build directory are being 4510260SAndrew.Bardsley@arm.com# built for the same host system. 4610260SAndrew.Bardsley@arm.com# 4710260SAndrew.Bardsley@arm.com# Examples: 4810260SAndrew.Bardsley@arm.com# 4910260SAndrew.Bardsley@arm.com# The following two commands are equivalent. The '-u' option tells 5010260SAndrew.Bardsley@arm.com# scons to search up the directory tree for this SConstruct file. 5110260SAndrew.Bardsley@arm.com# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 5210260SAndrew.Bardsley@arm.com# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 5310260SAndrew.Bardsley@arm.com# 5410260SAndrew.Bardsley@arm.com# The following two commands are equivalent and demonstrate building 5510260SAndrew.Bardsley@arm.com# in a directory outside of the source tree. The '-C' option tells 5610260SAndrew.Bardsley@arm.com# scons to chdir to the specified directory to find this SConstruct 5710260SAndrew.Bardsley@arm.com# file. 5810260SAndrew.Bardsley@arm.com# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 5910260SAndrew.Bardsley@arm.com# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 6010260SAndrew.Bardsley@arm.com# 6110260SAndrew.Bardsley@arm.com# You can use 'scons -H' to print scons options. If you're in this 6210260SAndrew.Bardsley@arm.com# 'm5' directory (or use -u or -C to tell scons where to find this 6310260SAndrew.Bardsley@arm.com# file), you can use 'scons -h' to print all the M5-specific build 6410260SAndrew.Bardsley@arm.com# options as well. 6510260SAndrew.Bardsley@arm.com# 6610260SAndrew.Bardsley@arm.com################################################### 6710260SAndrew.Bardsley@arm.com 6810260SAndrew.Bardsley@arm.com# Check for recent-enough Python and SCons versions. 6910260SAndrew.Bardsley@arm.comtry: 7010260SAndrew.Bardsley@arm.com # Really old versions of scons only take two options for the 7110260SAndrew.Bardsley@arm.com # function, so check once without the revision and once with the 7210260SAndrew.Bardsley@arm.com # revision, the first instance will fail for stuff other than 7310260SAndrew.Bardsley@arm.com # 0.98, and the second will fail for 0.98.0 7410260SAndrew.Bardsley@arm.com EnsureSConsVersion(0, 98) 7510260SAndrew.Bardsley@arm.com EnsureSConsVersion(0, 98, 1) 7610260SAndrew.Bardsley@arm.comexcept SystemExit, e: 7710260SAndrew.Bardsley@arm.com print """ 7810260SAndrew.Bardsley@arm.comFor more details, see: 7910260SAndrew.Bardsley@arm.com http://m5sim.org/wiki/index.php/Compiling_M5 8010260SAndrew.Bardsley@arm.com""" 8110260SAndrew.Bardsley@arm.com raise 8210260SAndrew.Bardsley@arm.com 8310260SAndrew.Bardsley@arm.com# We ensure the python version early because we have stuff that 8410260SAndrew.Bardsley@arm.com# requires python 2.4 8510260SAndrew.Bardsley@arm.comtry: 8610260SAndrew.Bardsley@arm.com EnsurePythonVersion(2, 4) 8710260SAndrew.Bardsley@arm.comexcept SystemExit, e: 8810260SAndrew.Bardsley@arm.com print """ 8910260SAndrew.Bardsley@arm.comYou can use a non-default installation of the Python interpreter by 9010260SAndrew.Bardsley@arm.comeither (1) rearranging your PATH so that scons finds the non-default 9110260SAndrew.Bardsley@arm.com'python' first or (2) explicitly invoking an alternative interpreter 9210260SAndrew.Bardsley@arm.comon the scons script. 9310260SAndrew.Bardsley@arm.com 9410260SAndrew.Bardsley@arm.comFor more details, see: 9510260SAndrew.Bardsley@arm.com http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 9610260SAndrew.Bardsley@arm.com""" 9710260SAndrew.Bardsley@arm.com raise 9810260SAndrew.Bardsley@arm.com 9910260SAndrew.Bardsley@arm.comimport os 10010260SAndrew.Bardsley@arm.comimport re 10110260SAndrew.Bardsley@arm.comimport subprocess 10210260SAndrew.Bardsley@arm.comimport sys 10310260SAndrew.Bardsley@arm.com 10410260SAndrew.Bardsley@arm.comfrom os import mkdir, environ 10510315Snilay@cs.wisc.edufrom os.path import abspath, basename, dirname, expanduser, normpath 10610260SAndrew.Bardsley@arm.comfrom os.path import exists, isdir, isfile 10710260SAndrew.Bardsley@arm.comfrom os.path import join as joinpath, split as splitpath 10810260SAndrew.Bardsley@arm.com 10910260SAndrew.Bardsley@arm.comimport SCons 11010260SAndrew.Bardsley@arm.comimport SCons.Node 11110260SAndrew.Bardsley@arm.com 11210260SAndrew.Bardsley@arm.comdef read_command(cmd, **kwargs): 11310260SAndrew.Bardsley@arm.com """run the command cmd, read the results and return them 11410900Snilay@cs.wisc.edu this is sorta like `cmd` in shell""" 11510260SAndrew.Bardsley@arm.com from subprocess import Popen, PIPE, STDOUT 11610260SAndrew.Bardsley@arm.com 11710260SAndrew.Bardsley@arm.com if isinstance(cmd, str): 11810260SAndrew.Bardsley@arm.com cmd = cmd.split() 11910260SAndrew.Bardsley@arm.com 12010260SAndrew.Bardsley@arm.com no_exception = 'exception' in kwargs 12110260SAndrew.Bardsley@arm.com exception = kwargs.pop('exception', None) 12210260SAndrew.Bardsley@arm.com 12310260SAndrew.Bardsley@arm.com kwargs.setdefault('shell', False) 12410260SAndrew.Bardsley@arm.com kwargs.setdefault('stdout', PIPE) 12510260SAndrew.Bardsley@arm.com kwargs.setdefault('stderr', STDOUT) 12610260SAndrew.Bardsley@arm.com kwargs.setdefault('close_fds', True) 12710260SAndrew.Bardsley@arm.com try: 12810260SAndrew.Bardsley@arm.com subp = Popen(cmd, **kwargs) 12910260SAndrew.Bardsley@arm.com except Exception, e: 13011103Snilay@cs.wisc.edu if no_exception: 13110260SAndrew.Bardsley@arm.com return exception 13210260SAndrew.Bardsley@arm.com raise 13310260SAndrew.Bardsley@arm.com 13410260SAndrew.Bardsley@arm.com return subp.communicate()[0] 13510753Sstever@gmail.com 13610260SAndrew.Bardsley@arm.com# helper function: compare arrays or strings of version numbers. 13710260SAndrew.Bardsley@arm.com# E.g., compare_version((1,3,25), (1,4,1)') 13810260SAndrew.Bardsley@arm.com# returns -1, 0, 1 if v1 is <, ==, > v2 13910900Snilay@cs.wisc.edudef compare_versions(v1, v2): 14010260SAndrew.Bardsley@arm.com def make_version_list(v): 14110260SAndrew.Bardsley@arm.com if isinstance(v, (list,tuple)): 14210260SAndrew.Bardsley@arm.com return v 14310260SAndrew.Bardsley@arm.com elif isinstance(v, str): 14410260SAndrew.Bardsley@arm.com return map(lambda x: int(re.match('\d+', x).group()), v.split('.')) 14510260SAndrew.Bardsley@arm.com else: 14610260SAndrew.Bardsley@arm.com raise TypeError 14710260SAndrew.Bardsley@arm.com 14810260SAndrew.Bardsley@arm.com v1 = make_version_list(v1) 14910260SAndrew.Bardsley@arm.com v2 = make_version_list(v2) 15010260SAndrew.Bardsley@arm.com # Compare corresponding elements of lists 15110260SAndrew.Bardsley@arm.com for n1,n2 in zip(v1, v2): 15210260SAndrew.Bardsley@arm.com if n1 < n2: return -1 15310260SAndrew.Bardsley@arm.com if n1 > n2: return 1 15410260SAndrew.Bardsley@arm.com # all corresponding values are equal... see if one has extra values 15510260SAndrew.Bardsley@arm.com if len(v1) < len(v2): return -1 15610260SAndrew.Bardsley@arm.com if len(v1) > len(v2): return 1 15710260SAndrew.Bardsley@arm.com return 0 15810260SAndrew.Bardsley@arm.com 15910260SAndrew.Bardsley@arm.com######################################################################## 16010260SAndrew.Bardsley@arm.com# 16110260SAndrew.Bardsley@arm.com# Set up the main build environment. 16210260SAndrew.Bardsley@arm.com# 16310260SAndrew.Bardsley@arm.com######################################################################## 16410260SAndrew.Bardsley@arm.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 16510260SAndrew.Bardsley@arm.com 'RANLIB' ]) 16610260SAndrew.Bardsley@arm.com 16710260SAndrew.Bardsley@arm.comuse_env = {} 16810260SAndrew.Bardsley@arm.comfor key,val in os.environ.iteritems(): 16910753Sstever@gmail.com if key in use_vars or key.startswith("M5"): 17010260SAndrew.Bardsley@arm.com use_env[key] = val 17110260SAndrew.Bardsley@arm.com 17210260SAndrew.Bardsley@arm.commain = Environment(ENV=use_env) 17310260SAndrew.Bardsley@arm.commain.root = Dir(".") # The current directory (where this file lives). 17410260SAndrew.Bardsley@arm.commain.srcdir = Dir("src") # The source directory 17510260SAndrew.Bardsley@arm.com 17610260SAndrew.Bardsley@arm.com######################################################################## 17710260SAndrew.Bardsley@arm.com# 17810260SAndrew.Bardsley@arm.com# Mercurial Stuff. 17910260SAndrew.Bardsley@arm.com# 18010260SAndrew.Bardsley@arm.com# If the M5 directory is a mercurial repository, we should do some 18110260SAndrew.Bardsley@arm.com# extra things. 18210260SAndrew.Bardsley@arm.com# 18310260SAndrew.Bardsley@arm.com######################################################################## 18410260SAndrew.Bardsley@arm.com 18510260SAndrew.Bardsley@arm.comhgdir = main.root.Dir(".hg") 18610260SAndrew.Bardsley@arm.com 18710260SAndrew.Bardsley@arm.commercurial_style_message = """ 18810260SAndrew.Bardsley@arm.comYou're missing the M5 style hook. 18910260SAndrew.Bardsley@arm.comPlease install the hook so we can ensure that all code fits a common style. 19010260SAndrew.Bardsley@arm.com 19110260SAndrew.Bardsley@arm.comAll you'd need to do is add the following lines to your repository .hg/hgrc 19210260SAndrew.Bardsley@arm.comor your personal .hgrc 19310260SAndrew.Bardsley@arm.com---------------- 19410260SAndrew.Bardsley@arm.com 19510260SAndrew.Bardsley@arm.com[extensions] 19610260SAndrew.Bardsley@arm.comstyle = %s/util/style.py 19710260SAndrew.Bardsley@arm.com 19810260SAndrew.Bardsley@arm.com[hooks] 19910260SAndrew.Bardsley@arm.compretxncommit.style = python:style.check_whitespace 20010260SAndrew.Bardsley@arm.com""" % (main.root) 20110260SAndrew.Bardsley@arm.com 20210260SAndrew.Bardsley@arm.commercurial_bin_not_found = """ 20310260SAndrew.Bardsley@arm.comMercurial binary cannot be found, unfortunately this means that we 20410260SAndrew.Bardsley@arm.comcannot easily determine the version of M5 that you are running and 20510260SAndrew.Bardsley@arm.comthis makes error messages more difficult to collect. Please consider 20610260SAndrew.Bardsley@arm.cominstalling mercurial if you choose to post an error message 20710260SAndrew.Bardsley@arm.com""" 20810260SAndrew.Bardsley@arm.com 20910260SAndrew.Bardsley@arm.commercurial_lib_not_found = """ 21010260SAndrew.Bardsley@arm.comMercurial libraries cannot be found, ignoring style hook 21110260SAndrew.Bardsley@arm.comIf you are actually a M5 developer, please fix this and 21210260SAndrew.Bardsley@arm.comrun the style hook. It is important. 21310260SAndrew.Bardsley@arm.com""" 21410315Snilay@cs.wisc.edu 21510260SAndrew.Bardsley@arm.comhg_info = "Unknown" 21610260SAndrew.Bardsley@arm.comif hgdir.exists(): 21710260SAndrew.Bardsley@arm.com # 1) Grab repository revision if we know it. 21810260SAndrew.Bardsley@arm.com cmd = "hg id -n -i -t -b" 21910260SAndrew.Bardsley@arm.com try: 22010260SAndrew.Bardsley@arm.com hg_info = read_command(cmd, cwd=main.root.abspath).strip() 22110260SAndrew.Bardsley@arm.com except OSError: 22210260SAndrew.Bardsley@arm.com print mercurial_bin_not_found 22310260SAndrew.Bardsley@arm.com 22410260SAndrew.Bardsley@arm.com # 2) Ensure that the style hook is in place. 22510260SAndrew.Bardsley@arm.com try: 22610260SAndrew.Bardsley@arm.com ui = None 22710260SAndrew.Bardsley@arm.com if ARGUMENTS.get('IGNORE_STYLE') != 'True': 22810260SAndrew.Bardsley@arm.com from mercurial import ui 22910260SAndrew.Bardsley@arm.com ui = ui.ui() 23010260SAndrew.Bardsley@arm.com except ImportError: 23110260SAndrew.Bardsley@arm.com print mercurial_lib_not_found 23210260SAndrew.Bardsley@arm.com 23310260SAndrew.Bardsley@arm.com if ui is not None: 23410260SAndrew.Bardsley@arm.com ui.readconfig(hgdir.File('hgrc').abspath) 23510260SAndrew.Bardsley@arm.com style_hook = ui.config('hooks', 'pretxncommit.style', None) 23610260SAndrew.Bardsley@arm.com 23710260SAndrew.Bardsley@arm.com if not style_hook: 23810260SAndrew.Bardsley@arm.com print mercurial_style_message 23910260SAndrew.Bardsley@arm.com sys.exit(1) 24010260SAndrew.Bardsley@arm.comelse: 24110260SAndrew.Bardsley@arm.com print ".hg directory not found" 24210260SAndrew.Bardsley@arm.com 24310260SAndrew.Bardsley@arm.commain['HG_INFO'] = hg_info 24410260SAndrew.Bardsley@arm.com 24510260SAndrew.Bardsley@arm.com################################################### 24610260SAndrew.Bardsley@arm.com# 24710260SAndrew.Bardsley@arm.com# Figure out which configurations to set up based on the path(s) of 24810260SAndrew.Bardsley@arm.com# the target(s). 24910260SAndrew.Bardsley@arm.com# 25010260SAndrew.Bardsley@arm.com################################################### 25110260SAndrew.Bardsley@arm.com 25210260SAndrew.Bardsley@arm.com# Find default configuration & binary. 25310260SAndrew.Bardsley@arm.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 25410315Snilay@cs.wisc.edu 25510260SAndrew.Bardsley@arm.com# helper function: find last occurrence of element in list 25610260SAndrew.Bardsley@arm.comdef rfind(l, elt, offs = -1): 25710260SAndrew.Bardsley@arm.com for i in range(len(l)+offs, 0, -1): 25810260SAndrew.Bardsley@arm.com if l[i] == elt: 25910260SAndrew.Bardsley@arm.com return i 26010260SAndrew.Bardsley@arm.com raise ValueError, "element not found" 26110260SAndrew.Bardsley@arm.com 26210260SAndrew.Bardsley@arm.com# Each target must have 'build' in the interior of the path; the 26310260SAndrew.Bardsley@arm.com# directory below this will determine the build parameters. For 26410260SAndrew.Bardsley@arm.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 26510260SAndrew.Bardsley@arm.com# recognize that ALPHA_SE specifies the configuration because it 26610260SAndrew.Bardsley@arm.com# follow 'build' in the bulid path. 26710260SAndrew.Bardsley@arm.com 26810260SAndrew.Bardsley@arm.com# Generate absolute paths to targets so we can see where the build dir is 26910260SAndrew.Bardsley@arm.comif COMMAND_LINE_TARGETS: 27010260SAndrew.Bardsley@arm.com # Ask SCons which directory it was invoked from 27110260SAndrew.Bardsley@arm.com launch_dir = GetLaunchDir() 27210260SAndrew.Bardsley@arm.com # Make targets relative to invocation directory 27310260SAndrew.Bardsley@arm.com abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 27410260SAndrew.Bardsley@arm.com COMMAND_LINE_TARGETS] 27510260SAndrew.Bardsley@arm.comelse: 27610260SAndrew.Bardsley@arm.com # Default targets are relative to root of tree 27710260SAndrew.Bardsley@arm.com abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 27810260SAndrew.Bardsley@arm.com DEFAULT_TARGETS] 27910260SAndrew.Bardsley@arm.com 28010260SAndrew.Bardsley@arm.com 28110260SAndrew.Bardsley@arm.com# Generate a list of the unique build roots and configs that the 28210260SAndrew.Bardsley@arm.com# collected targets reference. 28310260SAndrew.Bardsley@arm.comvariant_paths = [] 28410260SAndrew.Bardsley@arm.combuild_root = None 28510260SAndrew.Bardsley@arm.comfor t in abs_targets: 28610260SAndrew.Bardsley@arm.com path_dirs = t.split('/') 28710260SAndrew.Bardsley@arm.com try: 28810260SAndrew.Bardsley@arm.com build_top = rfind(path_dirs, 'build', -2) 28910260SAndrew.Bardsley@arm.com except: 29010260SAndrew.Bardsley@arm.com print "Error: no non-leaf 'build' dir found on target path", t 29110260SAndrew.Bardsley@arm.com Exit(1) 29210260SAndrew.Bardsley@arm.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 29310260SAndrew.Bardsley@arm.com if not build_root: 29410315Snilay@cs.wisc.edu build_root = this_build_root 29510260SAndrew.Bardsley@arm.com else: 29610260SAndrew.Bardsley@arm.com if this_build_root != build_root: 29710260SAndrew.Bardsley@arm.com print "Error: build targets not under same build root\n"\ 29810260SAndrew.Bardsley@arm.com " %s\n %s" % (build_root, this_build_root) 29910260SAndrew.Bardsley@arm.com Exit(1) 30010260SAndrew.Bardsley@arm.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 30110260SAndrew.Bardsley@arm.com if variant_path not in variant_paths: 30210260SAndrew.Bardsley@arm.com variant_paths.append(variant_path) 30310260SAndrew.Bardsley@arm.com 30410260SAndrew.Bardsley@arm.com# Make sure build_root exists (might not if this is the first build there) 30510260SAndrew.Bardsley@arm.comif not isdir(build_root): 30610260SAndrew.Bardsley@arm.com mkdir(build_root) 30710260SAndrew.Bardsley@arm.com 30810260SAndrew.Bardsley@arm.comExport('main') 30910260SAndrew.Bardsley@arm.com 31010260SAndrew.Bardsley@arm.commain.SConsignFile(joinpath(build_root, "sconsign")) 31110260SAndrew.Bardsley@arm.com 31210260SAndrew.Bardsley@arm.com# Default duplicate option is to use hard links, but this messes up 31310260SAndrew.Bardsley@arm.com# when you use emacs to edit a file in the target dir, as emacs moves 31410260SAndrew.Bardsley@arm.com# file to file~ then copies to file, breaking the link. Symbolic 31510260SAndrew.Bardsley@arm.com# (soft) links work better. 31610260SAndrew.Bardsley@arm.commain.SetOption('duplicate', 'soft-copy') 31710260SAndrew.Bardsley@arm.com 31810260SAndrew.Bardsley@arm.com# 31910260SAndrew.Bardsley@arm.com# Set up global sticky variables... these are common to an entire build 32010260SAndrew.Bardsley@arm.com# tree (not specific to a particular build like ALPHA_SE) 32110260SAndrew.Bardsley@arm.com# 32210260SAndrew.Bardsley@arm.com 32310260SAndrew.Bardsley@arm.com# Variable validators & converters for global sticky variables 32410260SAndrew.Bardsley@arm.comdef PathListMakeAbsolute(val): 32510260SAndrew.Bardsley@arm.com if not val: 32610260SAndrew.Bardsley@arm.com return val 32710260SAndrew.Bardsley@arm.com f = lambda p: abspath(expanduser(p)) 32810260SAndrew.Bardsley@arm.com return ':'.join(map(f, val.split(':'))) 32910260SAndrew.Bardsley@arm.com 33010260SAndrew.Bardsley@arm.comdef PathListAllExist(key, val, env): 33110260SAndrew.Bardsley@arm.com if not val: 33210260SAndrew.Bardsley@arm.com return 33310260SAndrew.Bardsley@arm.com paths = val.split(':') 33410315Snilay@cs.wisc.edu for path in paths: 33510260SAndrew.Bardsley@arm.com if not isdir(path): 33610260SAndrew.Bardsley@arm.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 33710260SAndrew.Bardsley@arm.com 33810260SAndrew.Bardsley@arm.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 33910260SAndrew.Bardsley@arm.com 34010260SAndrew.Bardsley@arm.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 34110260SAndrew.Bardsley@arm.com 34210260SAndrew.Bardsley@arm.comglobal_sticky_vars.AddVariables( 34310260SAndrew.Bardsley@arm.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 34410260SAndrew.Bardsley@arm.com ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 34510260SAndrew.Bardsley@arm.com ('BATCH', 'Use batch pool for build and tests', False), 34610260SAndrew.Bardsley@arm.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 34710260SAndrew.Bardsley@arm.com ('EXTRAS', 'Add Extra directories to the compilation', '', 34810260SAndrew.Bardsley@arm.com PathListAllExist, PathListMakeAbsolute) 34910260SAndrew.Bardsley@arm.com ) 35010260SAndrew.Bardsley@arm.com 35110260SAndrew.Bardsley@arm.com# base help text 35210260SAndrew.Bardsley@arm.comhelp_text = ''' 35310260SAndrew.Bardsley@arm.comUsage: scons [scons options] [build options] [target(s)] 35410260SAndrew.Bardsley@arm.com 35510315Snilay@cs.wisc.eduGlobal sticky options: 35610260SAndrew.Bardsley@arm.com''' 35710260SAndrew.Bardsley@arm.com 35810260SAndrew.Bardsley@arm.comhelp_text += global_sticky_vars.GenerateHelpText(main) 35910260SAndrew.Bardsley@arm.com 36010260SAndrew.Bardsley@arm.com# Update main environment with values from ARGUMENTS & global_sticky_vars_file 36110260SAndrew.Bardsley@arm.comglobal_sticky_vars.Update(main) 36210260SAndrew.Bardsley@arm.com 36310260SAndrew.Bardsley@arm.com# Save sticky variable settings back to current variables file 36410260SAndrew.Bardsley@arm.comglobal_sticky_vars.Save(global_sticky_vars_file, main) 36510260SAndrew.Bardsley@arm.com 36610260SAndrew.Bardsley@arm.com# Parse EXTRAS variable to build list of all directories where we're 36710260SAndrew.Bardsley@arm.com# look for sources etc. This list is exported as base_dir_list. 36810260SAndrew.Bardsley@arm.combase_dir = main.srcdir.abspath 36910260SAndrew.Bardsley@arm.comif main['EXTRAS']: 37010260SAndrew.Bardsley@arm.com extras_dir_list = main['EXTRAS'].split(':') 37110260SAndrew.Bardsley@arm.comelse: 37210260SAndrew.Bardsley@arm.com extras_dir_list = [] 37310260SAndrew.Bardsley@arm.com 37410260SAndrew.Bardsley@arm.comExport('base_dir') 37510260SAndrew.Bardsley@arm.comExport('extras_dir_list') 37610260SAndrew.Bardsley@arm.com 37710260SAndrew.Bardsley@arm.com# the ext directory should be on the #includes path 37810260SAndrew.Bardsley@arm.commain.Append(CPPPATH=[Dir('ext')]) 37910260SAndrew.Bardsley@arm.com 38010260SAndrew.Bardsley@arm.com# M5_PLY is used by isa_parser.py to find the PLY package. 38110260SAndrew.Bardsley@arm.commain.Append(ENV = { 'M5_PLY' : Dir('ext/ply').abspath }) 38210260SAndrew.Bardsley@arm.com 38310260SAndrew.Bardsley@arm.comCXX_version = read_command([main['CXX'],'--version'], exception=False) 38410260SAndrew.Bardsley@arm.comCXX_V = read_command([main['CXX'],'-V'], exception=False) 38510260SAndrew.Bardsley@arm.com 38610260SAndrew.Bardsley@arm.commain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 38710260SAndrew.Bardsley@arm.commain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 38810260SAndrew.Bardsley@arm.commain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 38910260SAndrew.Bardsley@arm.comif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 39010260SAndrew.Bardsley@arm.com print 'Error: How can we have two at the same time?' 39110260SAndrew.Bardsley@arm.com Exit(1) 39210260SAndrew.Bardsley@arm.com 39310260SAndrew.Bardsley@arm.com# Set up default C++ compiler flags 39410260SAndrew.Bardsley@arm.comif main['GCC']: 39510260SAndrew.Bardsley@arm.com main.Append(CCFLAGS='-pipe') 39610260SAndrew.Bardsley@arm.com main.Append(CCFLAGS='-fno-strict-aliasing') 39710260SAndrew.Bardsley@arm.com main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 39810260SAndrew.Bardsley@arm.com main.Append(CXXFLAGS='-Wno-deprecated') 39910260SAndrew.Bardsley@arm.comelif main['ICC']: 40010260SAndrew.Bardsley@arm.com pass #Fix me... add warning flags once we clean up icc warnings 40110260SAndrew.Bardsley@arm.comelif main['SUNCC']: 40210260SAndrew.Bardsley@arm.com main.Append(CCFLAGS='-Qoption ccfe') 40310260SAndrew.Bardsley@arm.com main.Append(CCFLAGS='-features=gcc') 40410260SAndrew.Bardsley@arm.com main.Append(CCFLAGS='-features=extensions') 40510260SAndrew.Bardsley@arm.com main.Append(CCFLAGS='-library=stlport4') 40610260SAndrew.Bardsley@arm.com main.Append(CCFLAGS='-xar') 40710260SAndrew.Bardsley@arm.com #main.Append(CCFLAGS='-instances=semiexplicit') 40810260SAndrew.Bardsley@arm.comelse: 40910260SAndrew.Bardsley@arm.com print 'Error: Don\'t know what compiler options to use for your compiler.' 41010260SAndrew.Bardsley@arm.com print ' Please fix SConstruct and src/SConscript and try again.' 41110260SAndrew.Bardsley@arm.com Exit(1) 41210260SAndrew.Bardsley@arm.com 41310260SAndrew.Bardsley@arm.com# Do this after we save setting back, or else we'll tack on an 41410260SAndrew.Bardsley@arm.com# extra 'qdo' every time we run scons. 41510260SAndrew.Bardsley@arm.comif main['BATCH']: 41610260SAndrew.Bardsley@arm.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 41710260SAndrew.Bardsley@arm.com main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 41810260SAndrew.Bardsley@arm.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 41910260SAndrew.Bardsley@arm.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 42010260SAndrew.Bardsley@arm.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 42110260SAndrew.Bardsley@arm.com 42210260SAndrew.Bardsley@arm.comif sys.platform == 'cygwin': 42310260SAndrew.Bardsley@arm.com # cygwin has some header file issues... 42410260SAndrew.Bardsley@arm.com main.Append(CCFLAGS=Split("-Wno-uninitialized")) 42510260SAndrew.Bardsley@arm.com 42610260SAndrew.Bardsley@arm.com# Check for SWIG 42710260SAndrew.Bardsley@arm.comif not main.has_key('SWIG'): 42810260SAndrew.Bardsley@arm.com print 'Error: SWIG utility not found.' 42910260SAndrew.Bardsley@arm.com print ' Please install (see http://www.swig.org) and retry.' 43010260SAndrew.Bardsley@arm.com Exit(1) 43110260SAndrew.Bardsley@arm.com 43210260SAndrew.Bardsley@arm.com# Check for appropriate SWIG version 43310260SAndrew.Bardsley@arm.comswig_version = read_command(('swig', '-version'), exception='').split() 43410260SAndrew.Bardsley@arm.com# First 3 words should be "SWIG Version x.y.z" 43510260SAndrew.Bardsley@arm.comif len(swig_version) < 3 or \ 43610260SAndrew.Bardsley@arm.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 43710260SAndrew.Bardsley@arm.com print 'Error determining SWIG version.' 43810260SAndrew.Bardsley@arm.com Exit(1) 43910260SAndrew.Bardsley@arm.com 44010260SAndrew.Bardsley@arm.commin_swig_version = '1.3.28' 44110260SAndrew.Bardsley@arm.comif compare_versions(swig_version[2], min_swig_version) < 0: 44210260SAndrew.Bardsley@arm.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 44310260SAndrew.Bardsley@arm.com print ' Installed version:', swig_version[2] 44410260SAndrew.Bardsley@arm.com Exit(1) 44510260SAndrew.Bardsley@arm.com 44610260SAndrew.Bardsley@arm.com# Set up SWIG flags & scanner 44710260SAndrew.Bardsley@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 44810260SAndrew.Bardsley@arm.commain.Append(SWIGFLAGS=swig_flags) 44910260SAndrew.Bardsley@arm.com 45010260SAndrew.Bardsley@arm.com# filter out all existing swig scanners, they mess up the dependency 45110260SAndrew.Bardsley@arm.com# stuff for some reason 45210260SAndrew.Bardsley@arm.comscanners = [] 45310260SAndrew.Bardsley@arm.comfor scanner in main['SCANNERS']: 45410260SAndrew.Bardsley@arm.com skeys = scanner.skeys 45510260SAndrew.Bardsley@arm.com if skeys == '.i': 45610260SAndrew.Bardsley@arm.com continue 45710260SAndrew.Bardsley@arm.com 45810260SAndrew.Bardsley@arm.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 45910260SAndrew.Bardsley@arm.com continue 46010260SAndrew.Bardsley@arm.com 46110260SAndrew.Bardsley@arm.com scanners.append(scanner) 46210260SAndrew.Bardsley@arm.com 46310260SAndrew.Bardsley@arm.com# add the new swig scanner that we like better 46410260SAndrew.Bardsley@arm.comfrom SCons.Scanner import ClassicCPP as CPPScanner 46510260SAndrew.Bardsley@arm.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 46610260SAndrew.Bardsley@arm.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 46710260SAndrew.Bardsley@arm.com 46810260SAndrew.Bardsley@arm.com# replace the scanners list that has what we want 46910260SAndrew.Bardsley@arm.commain['SCANNERS'] = scanners 47010260SAndrew.Bardsley@arm.com 47110260SAndrew.Bardsley@arm.com# Add a custom Check function to the Configure context so that we can 47210260SAndrew.Bardsley@arm.com# figure out if the compiler adds leading underscores to global 47310260SAndrew.Bardsley@arm.com# variables. This is needed for the autogenerated asm files that we 47410260SAndrew.Bardsley@arm.com# use for embedding the python code. 47510260SAndrew.Bardsley@arm.comdef CheckLeading(context): 47610260SAndrew.Bardsley@arm.com context.Message("Checking for leading underscore in global variables...") 47710260SAndrew.Bardsley@arm.com # 1) Define a global variable called x from asm so the C compiler 47810260SAndrew.Bardsley@arm.com # won't change the symbol at all. 47910260SAndrew.Bardsley@arm.com # 2) Declare that variable. 48010260SAndrew.Bardsley@arm.com # 3) Use the variable 48110260SAndrew.Bardsley@arm.com # 48210260SAndrew.Bardsley@arm.com # If the compiler prepends an underscore, this will successfully 48310260SAndrew.Bardsley@arm.com # link because the external symbol 'x' will be called '_x' which 48410260SAndrew.Bardsley@arm.com # was defined by the asm statement. If the compiler does not 48510260SAndrew.Bardsley@arm.com # prepend an underscore, this will not successfully link because 48610260SAndrew.Bardsley@arm.com # '_x' will have been defined by assembly, while the C portion of 48710260SAndrew.Bardsley@arm.com # the code will be trying to use 'x' 48810260SAndrew.Bardsley@arm.com ret = context.TryLink(''' 48910260SAndrew.Bardsley@arm.com asm(".globl _x; _x: .byte 0"); 49010260SAndrew.Bardsley@arm.com extern int x; 49110260SAndrew.Bardsley@arm.com int main() { return x; } 49210260SAndrew.Bardsley@arm.com ''', extension=".c") 49310260SAndrew.Bardsley@arm.com context.env.Append(LEADING_UNDERSCORE=ret) 49410260SAndrew.Bardsley@arm.com context.Result(ret) 49510260SAndrew.Bardsley@arm.com return ret 49610260SAndrew.Bardsley@arm.com 49710260SAndrew.Bardsley@arm.com# Platform-specific configuration. Note again that we assume that all 49810260SAndrew.Bardsley@arm.com# builds under a given build root run on the same host platform. 49910260SAndrew.Bardsley@arm.comconf = Configure(main, 50010260SAndrew.Bardsley@arm.com conf_dir = joinpath(build_root, '.scons_config'), 50110260SAndrew.Bardsley@arm.com log_file = joinpath(build_root, 'scons_config.log'), 50210260SAndrew.Bardsley@arm.com custom_tests = { 'CheckLeading' : CheckLeading }) 50310260SAndrew.Bardsley@arm.com 50410260SAndrew.Bardsley@arm.com# Check for leading underscores. Don't really need to worry either 50510260SAndrew.Bardsley@arm.com# way so don't need to check the return code. 50610260SAndrew.Bardsley@arm.comconf.CheckLeading() 50710260SAndrew.Bardsley@arm.com 50810260SAndrew.Bardsley@arm.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 50910260SAndrew.Bardsley@arm.comtry: 51010260SAndrew.Bardsley@arm.com import platform 51110260SAndrew.Bardsley@arm.com uname = platform.uname() 51210260SAndrew.Bardsley@arm.com if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 51310260SAndrew.Bardsley@arm.com if int(read_command('sysctl -n hw.cpu64bit_capable')[0]): 51410260SAndrew.Bardsley@arm.com main.Append(CCFLAGS='-arch x86_64') 51510260SAndrew.Bardsley@arm.com main.Append(CFLAGS='-arch x86_64') 51610260SAndrew.Bardsley@arm.com main.Append(LINKFLAGS='-arch x86_64') 51710260SAndrew.Bardsley@arm.com main.Append(ASFLAGS='-arch x86_64') 51810260SAndrew.Bardsley@arm.comexcept: 51910260SAndrew.Bardsley@arm.com pass 52010315Snilay@cs.wisc.edu 52110260SAndrew.Bardsley@arm.com# Recent versions of scons substitute a "Null" object for Configure() 52210260SAndrew.Bardsley@arm.com# when configuration isn't necessary, e.g., if the "--help" option is 52310260SAndrew.Bardsley@arm.com# present. Unfortuantely this Null object always returns false, 52410260SAndrew.Bardsley@arm.com# breaking all our configuration checks. We replace it with our own 52510260SAndrew.Bardsley@arm.com# more optimistic null object that returns True instead. 52610260SAndrew.Bardsley@arm.comif not conf: 52710260SAndrew.Bardsley@arm.com def NullCheck(*args, **kwargs): 52810260SAndrew.Bardsley@arm.com return True 52910260SAndrew.Bardsley@arm.com 53010260SAndrew.Bardsley@arm.com class NullConf: 53110260SAndrew.Bardsley@arm.com def __init__(self, env): 53210260SAndrew.Bardsley@arm.com self.env = env 53310260SAndrew.Bardsley@arm.com def Finish(self): 53410260SAndrew.Bardsley@arm.com return self.env 53510260SAndrew.Bardsley@arm.com def __getattr__(self, mname): 53610260SAndrew.Bardsley@arm.com return NullCheck 53710260SAndrew.Bardsley@arm.com 53810260SAndrew.Bardsley@arm.com conf = NullConf(main) 53910260SAndrew.Bardsley@arm.com 54010260SAndrew.Bardsley@arm.com# Find Python include and library directories for embedding the 54110260SAndrew.Bardsley@arm.com# interpreter. For consistency, we will use the same Python 54210260SAndrew.Bardsley@arm.com# installation used to run scons (and thus this script). If you want 54310260SAndrew.Bardsley@arm.com# to link in an alternate version, see above for instructions on how 54410260SAndrew.Bardsley@arm.com# to invoke scons with a different copy of the Python interpreter. 54510260SAndrew.Bardsley@arm.comfrom distutils import sysconfig 54610260SAndrew.Bardsley@arm.com 54710260SAndrew.Bardsley@arm.compy_getvar = sysconfig.get_config_var 54810260SAndrew.Bardsley@arm.com 54910260SAndrew.Bardsley@arm.compy_version = 'python' + py_getvar('VERSION') 55010260SAndrew.Bardsley@arm.com 55110260SAndrew.Bardsley@arm.compy_general_include = sysconfig.get_python_inc() 55210260SAndrew.Bardsley@arm.compy_platform_include = sysconfig.get_python_inc(plat_specific=True) 55310260SAndrew.Bardsley@arm.compy_includes = [ py_general_include ] 55410260SAndrew.Bardsley@arm.comif py_platform_include != py_general_include: 55510260SAndrew.Bardsley@arm.com py_includes.append(py_platform_include) 55610260SAndrew.Bardsley@arm.com 55710260SAndrew.Bardsley@arm.compy_lib_path = [ py_getvar('LIBDIR') ] 55810260SAndrew.Bardsley@arm.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no 55910260SAndrew.Bardsley@arm.com# shared library in prefix/lib/. 56010260SAndrew.Bardsley@arm.comif not py_getvar('Py_ENABLE_SHARED'): 56110260SAndrew.Bardsley@arm.com py_lib_path.append(py_getvar('LIBPL')) 56210260SAndrew.Bardsley@arm.com 56310260SAndrew.Bardsley@arm.compy_libs = [] 56410260SAndrew.Bardsley@arm.comfor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 56510315Snilay@cs.wisc.edu assert lib.startswith('-l') 56610260SAndrew.Bardsley@arm.com lib = lib[2:] 56710260SAndrew.Bardsley@arm.com if lib not in py_libs: 56810260SAndrew.Bardsley@arm.com py_libs.append(lib) 56910260SAndrew.Bardsley@arm.compy_libs.append(py_version) 57010260SAndrew.Bardsley@arm.com 57110260SAndrew.Bardsley@arm.commain.Append(CPPPATH=py_includes) 57210260SAndrew.Bardsley@arm.commain.Append(LIBPATH=py_lib_path) 57310260SAndrew.Bardsley@arm.com 57410260SAndrew.Bardsley@arm.com# verify that this stuff works 57510260SAndrew.Bardsley@arm.comif not conf.CheckHeader('Python.h', '<>'): 57610260SAndrew.Bardsley@arm.com print "Error: can't find Python.h header in", py_includes 57710260SAndrew.Bardsley@arm.com Exit(1) 57810260SAndrew.Bardsley@arm.com 57910260SAndrew.Bardsley@arm.comfor lib in py_libs: 58010260SAndrew.Bardsley@arm.com if not conf.CheckLib(lib): 58110260SAndrew.Bardsley@arm.com print "Error: can't find library %s required by python" % lib 58210260SAndrew.Bardsley@arm.com Exit(1) 58310260SAndrew.Bardsley@arm.com 58410260SAndrew.Bardsley@arm.com# On Solaris you need to use libsocket for socket ops 58510260SAndrew.Bardsley@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 58610260SAndrew.Bardsley@arm.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 58710260SAndrew.Bardsley@arm.com print "Can't find library with socket calls (e.g. accept())" 58810260SAndrew.Bardsley@arm.com Exit(1) 58911103Snilay@cs.wisc.edu 59010260SAndrew.Bardsley@arm.com# Check for zlib. If the check passes, libz will be automatically 59110260SAndrew.Bardsley@arm.com# added to the LIBS environment variable. 59210260SAndrew.Bardsley@arm.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 59310260SAndrew.Bardsley@arm.com print 'Error: did not find needed zlib compression library '\ 59410753Sstever@gmail.com 'and/or zlib.h header file.' 59510260SAndrew.Bardsley@arm.com print ' Please install zlib and try again.' 59610260SAndrew.Bardsley@arm.com Exit(1) 59710260SAndrew.Bardsley@arm.com 59810900Snilay@cs.wisc.edu# Check for <fenv.h> (C99 FP environment control) 59910260SAndrew.Bardsley@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 60010260SAndrew.Bardsley@arm.comif not have_fenv: 60110260SAndrew.Bardsley@arm.com print "Warning: Header file <fenv.h> not found." 60210260SAndrew.Bardsley@arm.com print " This host has no IEEE FP rounding mode control." 60310260SAndrew.Bardsley@arm.com 60410260SAndrew.Bardsley@arm.com###################################################################### 60510260SAndrew.Bardsley@arm.com# 60610260SAndrew.Bardsley@arm.com# Check for mysql. 60710260SAndrew.Bardsley@arm.com# 60810260SAndrew.Bardsley@arm.commysql_config = WhereIs('mysql_config') 60910260SAndrew.Bardsley@arm.comhave_mysql = bool(mysql_config) 61010260SAndrew.Bardsley@arm.com 61110260SAndrew.Bardsley@arm.com# Check MySQL version. 61210260SAndrew.Bardsley@arm.comif have_mysql: 61310260SAndrew.Bardsley@arm.com mysql_version = read_command(mysql_config + ' --version') 61410260SAndrew.Bardsley@arm.com min_mysql_version = '4.1' 61510260SAndrew.Bardsley@arm.com if compare_versions(mysql_version, min_mysql_version) < 0: 61610260SAndrew.Bardsley@arm.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 61710260SAndrew.Bardsley@arm.com print ' Version', mysql_version, 'detected.' 61810260SAndrew.Bardsley@arm.com have_mysql = False 61910260SAndrew.Bardsley@arm.com 62010260SAndrew.Bardsley@arm.com# Set up mysql_config commands. 62110260SAndrew.Bardsley@arm.comif have_mysql: 62210260SAndrew.Bardsley@arm.com mysql_config_include = mysql_config + ' --include' 62310260SAndrew.Bardsley@arm.com if os.system(mysql_config_include + ' > /dev/null') != 0: 62410260SAndrew.Bardsley@arm.com # older mysql_config versions don't support --include, use 62510260SAndrew.Bardsley@arm.com # --cflags instead 62610260SAndrew.Bardsley@arm.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 62710260SAndrew.Bardsley@arm.com # This seems to work in all versions 62810260SAndrew.Bardsley@arm.com mysql_config_libs = mysql_config + ' --libs' 62910260SAndrew.Bardsley@arm.com 63010260SAndrew.Bardsley@arm.com###################################################################### 63110260SAndrew.Bardsley@arm.com# 63210260SAndrew.Bardsley@arm.com# Finish the configuration 63310260SAndrew.Bardsley@arm.com# 63410260SAndrew.Bardsley@arm.commain = conf.Finish() 63510260SAndrew.Bardsley@arm.com 63610260SAndrew.Bardsley@arm.com###################################################################### 63710260SAndrew.Bardsley@arm.com# 63810260SAndrew.Bardsley@arm.com# Collect all non-global variables 63910260SAndrew.Bardsley@arm.com# 64010260SAndrew.Bardsley@arm.com 64110260SAndrew.Bardsley@arm.com# Define the universe of supported ISAs 64210260SAndrew.Bardsley@arm.comall_isa_list = [ ] 64310260SAndrew.Bardsley@arm.comExport('all_isa_list') 64410260SAndrew.Bardsley@arm.com 64510260SAndrew.Bardsley@arm.com# Define the universe of supported CPU models 64610260SAndrew.Bardsley@arm.comall_cpu_list = [ ] 64710260SAndrew.Bardsley@arm.comdefault_cpus = [ ] 64810260SAndrew.Bardsley@arm.comExport('all_cpu_list', 'default_cpus') 64910260SAndrew.Bardsley@arm.com 65010260SAndrew.Bardsley@arm.com# Sticky variables get saved in the variables file so they persist from 65110260SAndrew.Bardsley@arm.com# one invocation to the next (unless overridden, in which case the new 65210260SAndrew.Bardsley@arm.com# value becomes sticky). 65310260SAndrew.Bardsley@arm.comsticky_vars = Variables(args=ARGUMENTS) 65410753Sstever@gmail.comExport('sticky_vars') 65510260SAndrew.Bardsley@arm.com 65610260SAndrew.Bardsley@arm.com# Sticky variables that should be exported 65710260SAndrew.Bardsley@arm.comexport_vars = [] 65810260SAndrew.Bardsley@arm.comExport('export_vars') 65910260SAndrew.Bardsley@arm.com 66010260SAndrew.Bardsley@arm.com# Non-sticky variables only apply to the current build. 66110260SAndrew.Bardsley@arm.comnonsticky_vars = Variables(args=ARGUMENTS) 66210753Sstever@gmail.comExport('nonsticky_vars') 66310260SAndrew.Bardsley@arm.com 66410260SAndrew.Bardsley@arm.com# Walk the tree and execute all SConsopts scripts that wil add to the 66510260SAndrew.Bardsley@arm.com# above variables 66610260SAndrew.Bardsley@arm.comfor bdir in [ base_dir ] + extras_dir_list: 66710260SAndrew.Bardsley@arm.com for root, dirs, files in os.walk(bdir): 66810260SAndrew.Bardsley@arm.com if 'SConsopts' in files: 66910260SAndrew.Bardsley@arm.com print "Reading", joinpath(root, 'SConsopts') 67010260SAndrew.Bardsley@arm.com SConscript(joinpath(root, 'SConsopts')) 67110260SAndrew.Bardsley@arm.com 67210260SAndrew.Bardsley@arm.comall_isa_list.sort() 67310260SAndrew.Bardsley@arm.comall_cpu_list.sort() 67410260SAndrew.Bardsley@arm.comdefault_cpus.sort() 67510260SAndrew.Bardsley@arm.com 67610260SAndrew.Bardsley@arm.comsticky_vars.AddVariables( 67710260SAndrew.Bardsley@arm.com EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 67810260SAndrew.Bardsley@arm.com BoolVariable('FULL_SYSTEM', 'Full-system support', False), 67910260SAndrew.Bardsley@arm.com ListVariable('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 68010260SAndrew.Bardsley@arm.com BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 68110260SAndrew.Bardsley@arm.com BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 68210260SAndrew.Bardsley@arm.com False), 68310260SAndrew.Bardsley@arm.com BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 68410260SAndrew.Bardsley@arm.com False), 68510260SAndrew.Bardsley@arm.com BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 68610260SAndrew.Bardsley@arm.com False), 68710260SAndrew.Bardsley@arm.com BoolVariable('SS_COMPATIBLE_FP', 68810260SAndrew.Bardsley@arm.com 'Make floating-point results compatible with SimpleScalar', 68910260SAndrew.Bardsley@arm.com False), 69010260SAndrew.Bardsley@arm.com BoolVariable('USE_SSE2', 69110260SAndrew.Bardsley@arm.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 69210260SAndrew.Bardsley@arm.com False), 69310260SAndrew.Bardsley@arm.com BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 69410260SAndrew.Bardsley@arm.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 69510260SAndrew.Bardsley@arm.com BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 69610260SAndrew.Bardsley@arm.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 69710260SAndrew.Bardsley@arm.com ) 69810260SAndrew.Bardsley@arm.com 69911103Snilay@cs.wisc.edunonsticky_vars.AddVariables( 70010260SAndrew.Bardsley@arm.com BoolVariable('update_ref', 'Update test reference outputs', False) 70110260SAndrew.Bardsley@arm.com ) 70210260SAndrew.Bardsley@arm.com 70310260SAndrew.Bardsley@arm.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 70410753Sstever@gmail.comexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 70510260SAndrew.Bardsley@arm.com 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 70610260SAndrew.Bardsley@arm.com 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 70710260SAndrew.Bardsley@arm.com 70810900Snilay@cs.wisc.edu################################################### 70910260SAndrew.Bardsley@arm.com# 71010260SAndrew.Bardsley@arm.com# Define a SCons builder for configuration flag headers. 71110260SAndrew.Bardsley@arm.com# 71210260SAndrew.Bardsley@arm.com################################################### 71310260SAndrew.Bardsley@arm.com 71410260SAndrew.Bardsley@arm.com# This function generates a config header file that #defines the 71510260SAndrew.Bardsley@arm.com# variable symbol to the current variable setting (0 or 1). The source 71610260SAndrew.Bardsley@arm.com# operands are the name of the variable and a Value node containing the 71710260SAndrew.Bardsley@arm.com# value of the variable. 71810260SAndrew.Bardsley@arm.comdef build_config_file(target, source, env): 71910260SAndrew.Bardsley@arm.com (variable, value) = [s.get_contents() for s in source] 72010260SAndrew.Bardsley@arm.com f = file(str(target[0]), 'w') 72110260SAndrew.Bardsley@arm.com print >> f, '#define', variable, value 72210260SAndrew.Bardsley@arm.com f.close() 72310260SAndrew.Bardsley@arm.com return None 72410260SAndrew.Bardsley@arm.com 72510260SAndrew.Bardsley@arm.com# Generate the message to be printed when building the config file. 72610260SAndrew.Bardsley@arm.comdef build_config_file_string(target, source, env): 72710260SAndrew.Bardsley@arm.com (variable, value) = [s.get_contents() for s in source] 72810260SAndrew.Bardsley@arm.com return "Defining %s as %s in %s." % (variable, value, target[0]) 72910260SAndrew.Bardsley@arm.com 73010260SAndrew.Bardsley@arm.com# Combine the two functions into a scons Action object. 73110260SAndrew.Bardsley@arm.comconfig_action = Action(build_config_file, build_config_file_string) 73210260SAndrew.Bardsley@arm.com 73310260SAndrew.Bardsley@arm.com# The emitter munges the source & target node lists to reflect what 73410451Snilay@cs.wisc.edu# we're really doing. 73510260SAndrew.Bardsley@arm.comdef config_emitter(target, source, env): 73610260SAndrew.Bardsley@arm.com # extract variable name from Builder arg 73710753Sstever@gmail.com variable = str(target[0]) 73810753Sstever@gmail.com # True target is config header file 73910753Sstever@gmail.com target = joinpath('config', variable.lower() + '.hh') 74010451Snilay@cs.wisc.edu val = env[variable] 74110753Sstever@gmail.com if isinstance(val, bool): 74210260SAndrew.Bardsley@arm.com # Force value to 0/1 74310260SAndrew.Bardsley@arm.com val = int(val) 74410260SAndrew.Bardsley@arm.com elif isinstance(val, str): 74510260SAndrew.Bardsley@arm.com val = '"' + val + '"' 74610753Sstever@gmail.com 74710260SAndrew.Bardsley@arm.com # Sources are variable name & value (packaged in SCons Value nodes) 74810260SAndrew.Bardsley@arm.com return ([target], [Value(variable), Value(val)]) 74910260SAndrew.Bardsley@arm.com 75010260SAndrew.Bardsley@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 75110260SAndrew.Bardsley@arm.com 75210260SAndrew.Bardsley@arm.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 75310260SAndrew.Bardsley@arm.com 75410260SAndrew.Bardsley@arm.com# libelf build is shared across all configs in the build root. 75510260SAndrew.Bardsley@arm.commain.SConscript('ext/libelf/SConscript', 75610753Sstever@gmail.com variant_dir = joinpath(build_root, 'libelf')) 75710260SAndrew.Bardsley@arm.com 75810260SAndrew.Bardsley@arm.com# gzstream build is shared across all configs in the build root. 75910260SAndrew.Bardsley@arm.commain.SConscript('ext/gzstream/SConscript', 76010260SAndrew.Bardsley@arm.com variant_dir = joinpath(build_root, 'gzstream')) 76110260SAndrew.Bardsley@arm.com 76211103Snilay@cs.wisc.edu################################################### 76310260SAndrew.Bardsley@arm.com# 76410260SAndrew.Bardsley@arm.com# This function is used to set up a directory with switching headers 76510753Sstever@gmail.com# 76610260SAndrew.Bardsley@arm.com################################################### 76710260SAndrew.Bardsley@arm.com 76810260SAndrew.Bardsley@arm.commain['ALL_ISA_LIST'] = all_isa_list 76910260SAndrew.Bardsley@arm.comdef make_switching_dir(dname, switch_headers, env): 77010260SAndrew.Bardsley@arm.com # Generate the header. target[0] is the full path of the output 77110260SAndrew.Bardsley@arm.com # header to generate. 'source' is a dummy variable, since we get the 77210260SAndrew.Bardsley@arm.com # list of ISAs from env['ALL_ISA_LIST']. 77310451Snilay@cs.wisc.edu def gen_switch_hdr(target, source, env): 77410260SAndrew.Bardsley@arm.com fname = str(target[0]) 77510260SAndrew.Bardsley@arm.com bname = basename(fname) 77610260SAndrew.Bardsley@arm.com f = open(fname, 'w') 77710260SAndrew.Bardsley@arm.com f.write('#include "arch/isa_specific.hh"\n') 77810315Snilay@cs.wisc.edu cond = '#if' 77910260SAndrew.Bardsley@arm.com for isa in all_isa_list: 78010315Snilay@cs.wisc.edu f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 78110260SAndrew.Bardsley@arm.com % (cond, isa.upper(), dname, isa, bname)) 78210260SAndrew.Bardsley@arm.com cond = '#elif' 78310315Snilay@cs.wisc.edu f.write('#else\n#error "THE_ISA not set"\n#endif\n') 78410315Snilay@cs.wisc.edu f.close() 78510315Snilay@cs.wisc.edu return 0 78610315Snilay@cs.wisc.edu 78710315Snilay@cs.wisc.edu # String to print when generating header 78810315Snilay@cs.wisc.edu def gen_switch_hdr_string(target, source, env): 78910315Snilay@cs.wisc.edu return "Generating switch header " + str(target[0]) 79010315Snilay@cs.wisc.edu 79110260SAndrew.Bardsley@arm.com # Build SCons Action object. 'varlist' specifies env vars that this 79210451Snilay@cs.wisc.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 79310260SAndrew.Bardsley@arm.com # should get re-executed. 79410260SAndrew.Bardsley@arm.com switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 79510753Sstever@gmail.com varlist=['ALL_ISA_LIST']) 79610753Sstever@gmail.com 79710753Sstever@gmail.com # Instantiate actions for each header 79810451Snilay@cs.wisc.edu for hdr in switch_headers: 79910753Sstever@gmail.com env.Command(hdr, [], switch_hdr_action) 80010260SAndrew.Bardsley@arm.comExport('make_switching_dir') 80110260SAndrew.Bardsley@arm.com 80210753Sstever@gmail.com################################################### 80310260SAndrew.Bardsley@arm.com# 80410260SAndrew.Bardsley@arm.com# Define build environments for selected configurations. 80510260SAndrew.Bardsley@arm.com# 80610260SAndrew.Bardsley@arm.com################################################### 80710260SAndrew.Bardsley@arm.com 80810451Snilay@cs.wisc.edufor variant_path in variant_paths: 80910451Snilay@cs.wisc.edu print "Building in", variant_path 81010451Snilay@cs.wisc.edu 81110451Snilay@cs.wisc.edu # Make a copy of the build-root environment to use for this config. 81210451Snilay@cs.wisc.edu env = main.Clone() 81310451Snilay@cs.wisc.edu env['BUILDDIR'] = variant_path 81410451Snilay@cs.wisc.edu 81510451Snilay@cs.wisc.edu # variant_dir is the tail component of build path, and is used to 81610451Snilay@cs.wisc.edu # determine the build parameters (e.g., 'ALPHA_SE') 81710451Snilay@cs.wisc.edu (build_root, variant_dir) = splitpath(variant_path) 81810451Snilay@cs.wisc.edu 81910451Snilay@cs.wisc.edu # Set env variables according to the build directory config. 82010451Snilay@cs.wisc.edu sticky_vars.files = [] 82110451Snilay@cs.wisc.edu # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 82210451Snilay@cs.wisc.edu # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 82310451Snilay@cs.wisc.edu # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 82410451Snilay@cs.wisc.edu current_vars_file = joinpath(build_root, 'variables', variant_dir) 82510451Snilay@cs.wisc.edu if isfile(current_vars_file): 82610451Snilay@cs.wisc.edu sticky_vars.files.append(current_vars_file) 82710451Snilay@cs.wisc.edu print "Using saved variables file %s" % current_vars_file 82810451Snilay@cs.wisc.edu else: 82910451Snilay@cs.wisc.edu # Build dir-specific variables file doesn't exist. 83010451Snilay@cs.wisc.edu 83110451Snilay@cs.wisc.edu # Make sure the directory is there so we can create it later 83210260SAndrew.Bardsley@arm.com opt_dir = dirname(current_vars_file) 83310753Sstever@gmail.com if not isdir(opt_dir): 83410451Snilay@cs.wisc.edu mkdir(opt_dir) 83510260SAndrew.Bardsley@arm.com 83610260SAndrew.Bardsley@arm.com # Get default build variables from source tree. Variables are 83710260SAndrew.Bardsley@arm.com # normally determined by name of $VARIANT_DIR, but can be 83810260SAndrew.Bardsley@arm.com # overriden by 'default=' arg on command line. 83910260SAndrew.Bardsley@arm.com default_vars_file = joinpath('build_opts', 84010260SAndrew.Bardsley@arm.com ARGUMENTS.get('default', variant_dir)) 84110260SAndrew.Bardsley@arm.com if isfile(default_vars_file): 84210753Sstever@gmail.com sticky_vars.files.append(default_vars_file) 84310260SAndrew.Bardsley@arm.com print "Variables file %s not found,\n using defaults in %s" \ 84410451Snilay@cs.wisc.edu % (current_vars_file, default_vars_file) 84510260SAndrew.Bardsley@arm.com else: 84610260SAndrew.Bardsley@arm.com print "Error: cannot find variables file %s or %s" \ 84710260SAndrew.Bardsley@arm.com % (current_vars_file, default_vars_file) 84810260SAndrew.Bardsley@arm.com Exit(1) 84910260SAndrew.Bardsley@arm.com 85010260SAndrew.Bardsley@arm.com # Apply current variable settings to env 85110260SAndrew.Bardsley@arm.com sticky_vars.Update(env) 85210260SAndrew.Bardsley@arm.com nonsticky_vars.Update(env) 85310260SAndrew.Bardsley@arm.com 85410260SAndrew.Bardsley@arm.com help_text += "\nSticky variables for %s:\n" % variant_dir \ 85510260SAndrew.Bardsley@arm.com + sticky_vars.GenerateHelpText(env) \ 85610260SAndrew.Bardsley@arm.com + "\nNon-sticky variables for %s:\n" % variant_dir \ 85710260SAndrew.Bardsley@arm.com + nonsticky_vars.GenerateHelpText(env) 85810451Snilay@cs.wisc.edu 85910315Snilay@cs.wisc.edu # Process variable settings. 86010260SAndrew.Bardsley@arm.com 86110451Snilay@cs.wisc.edu if not have_fenv and env['USE_FENV']: 86210260SAndrew.Bardsley@arm.com print "Warning: <fenv.h> not available; " \ 86310260SAndrew.Bardsley@arm.com "forcing USE_FENV to False in", variant_dir + "." 86410260SAndrew.Bardsley@arm.com env['USE_FENV'] = False 86510315Snilay@cs.wisc.edu 86610260SAndrew.Bardsley@arm.com if not env['USE_FENV']: 86710315Snilay@cs.wisc.edu print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 86810451Snilay@cs.wisc.edu print " FP results may deviate slightly from other platforms." 86910315Snilay@cs.wisc.edu 87010315Snilay@cs.wisc.edu if env['EFENCE']: 87110315Snilay@cs.wisc.edu env.Append(LIBS=['efence']) 87210260SAndrew.Bardsley@arm.com 87310315Snilay@cs.wisc.edu if env['USE_MYSQL']: 87410451Snilay@cs.wisc.edu if not have_mysql: 87510451Snilay@cs.wisc.edu print "Warning: MySQL not available; " \ 87610451Snilay@cs.wisc.edu "forcing USE_MYSQL to False in", variant_dir + "." 87710451Snilay@cs.wisc.edu env['USE_MYSQL'] = False 87810260SAndrew.Bardsley@arm.com else: 87910260SAndrew.Bardsley@arm.com print "Compiling in", variant_dir, "with MySQL support." 88010260SAndrew.Bardsley@arm.com env.ParseConfig(mysql_config_libs) 88110260SAndrew.Bardsley@arm.com env.ParseConfig(mysql_config_include) 88210260SAndrew.Bardsley@arm.com 88310260SAndrew.Bardsley@arm.com # Save sticky variable settings back to current variables file 88410260SAndrew.Bardsley@arm.com sticky_vars.Save(current_vars_file, env) 88510260SAndrew.Bardsley@arm.com 88610260SAndrew.Bardsley@arm.com if env['USE_SSE2']: 88710260SAndrew.Bardsley@arm.com env.Append(CCFLAGS='-msse2') 888 889 # The src/SConscript file sets up the build rules in 'env' according 890 # to the configured variables. It returns a list of environments, 891 # one for each variant build (debug, opt, etc.) 892 envList = SConscript('src/SConscript', variant_dir = variant_path, 893 exports = 'env') 894 895 # Set up the regression tests for each build. 896 for e in envList: 897 SConscript('tests/SConscript', 898 variant_dir = joinpath(variant_path, 'tests', e.Label), 899 exports = { 'env' : e }, duplicate = False) 900 901Help(help_text) 902