SConstruct revision 7457
1955SN/A# -*- mode:python -*- 2955SN/A 39812Sandreas.hansson@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company 49812Sandreas.hansson@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 59812Sandreas.hansson@arm.com# All rights reserved. 69812Sandreas.hansson@arm.com# 79812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 89812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 99812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 109812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 119812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 129812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 139812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 149812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 157816Ssteve.reinhardt@amd.com# contributors may be used to endorse or promote products derived from 165871Snate@binkert.org# this software without specific prior written permission. 171762SN/A# 18955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29955SN/A# 30955SN/A# Authors: Steve Reinhardt 31955SN/A# Nathan Binkert 32955SN/A 33955SN/A################################################### 34955SN/A# 35955SN/A# SCons top-level build description (SConstruct) file. 36955SN/A# 37955SN/A# While in this directory ('m5'), just type 'scons' to build the default 38955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 39955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 40955SN/A# the optimized full-system version). 41955SN/A# 422665Ssaidi@eecs.umich.edu# You can build M5 in a different directory as long as there is a 432665Ssaidi@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 445863Snate@binkert.org# expects that all configs under the same build directory are being 45955SN/A# built for the same host system. 46955SN/A# 47955SN/A# Examples: 48955SN/A# 49955SN/A# The following two commands are equivalent. The '-u' option tells 508878Ssteve.reinhardt@amd.com# scons to search up the directory tree for this SConstruct file. 512632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 528878Ssteve.reinhardt@amd.com# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 532632Sstever@eecs.umich.edu# 54955SN/A# The following two commands are equivalent and demonstrate building 558878Ssteve.reinhardt@amd.com# in a directory outside of the source tree. The '-C' option tells 562632Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 572761Sstever@eecs.umich.edu# file. 582632Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 592632Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 602632Sstever@eecs.umich.edu# 612761Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 622761Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 632761Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 648878Ssteve.reinhardt@amd.com# options as well. 658878Ssteve.reinhardt@amd.com# 662761Sstever@eecs.umich.edu################################################### 672761Sstever@eecs.umich.edu 682761Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. 692761Sstever@eecs.umich.edutry: 702761Sstever@eecs.umich.edu # Really old versions of scons only take two options for the 718878Ssteve.reinhardt@amd.com # function, so check once without the revision and once with the 728878Ssteve.reinhardt@amd.com # revision, the first instance will fail for stuff other than 732632Sstever@eecs.umich.edu # 0.98, and the second will fail for 0.98.0 742632Sstever@eecs.umich.edu EnsureSConsVersion(0, 98) 758878Ssteve.reinhardt@amd.com EnsureSConsVersion(0, 98, 1) 768878Ssteve.reinhardt@amd.comexcept SystemExit, e: 772632Sstever@eecs.umich.edu print """ 78955SN/AFor more details, see: 79955SN/A http://m5sim.org/wiki/index.php/Compiling_M5 80955SN/A""" 815863Snate@binkert.org raise 825863Snate@binkert.org 835863Snate@binkert.org# We ensure the python version early because we have stuff that 845863Snate@binkert.org# requires python 2.4 855863Snate@binkert.orgtry: 865863Snate@binkert.org EnsurePythonVersion(2, 4) 875863Snate@binkert.orgexcept SystemExit, e: 885863Snate@binkert.org print """ 895863Snate@binkert.orgYou can use a non-default installation of the Python interpreter by 905863Snate@binkert.orgeither (1) rearranging your PATH so that scons finds the non-default 915863Snate@binkert.org'python' first or (2) explicitly invoking an alternative interpreter 928878Ssteve.reinhardt@amd.comon the scons script. 935863Snate@binkert.org 945863Snate@binkert.orgFor more details, see: 955863Snate@binkert.org http://m5sim.org/wiki/index.php/Using_a_non-default_Python_installation 969812Sandreas.hansson@arm.com""" 979812Sandreas.hansson@arm.com raise 985863Snate@binkert.org 999812Sandreas.hansson@arm.com# Global Python includes 1005863Snate@binkert.orgimport os 1015863Snate@binkert.orgimport re 1025863Snate@binkert.orgimport subprocess 1039812Sandreas.hansson@arm.comimport sys 1049812Sandreas.hansson@arm.com 1055863Snate@binkert.orgfrom os import mkdir, environ 1065863Snate@binkert.orgfrom os.path import abspath, basename, dirname, expanduser, normpath 1078878Ssteve.reinhardt@amd.comfrom os.path import exists, isdir, isfile 1085863Snate@binkert.orgfrom os.path import join as joinpath, split as splitpath 1095863Snate@binkert.org 1105863Snate@binkert.org# SCons includes 1116654Snate@binkert.orgimport SCons 11210196SCurtis.Dunham@arm.comimport SCons.Node 113955SN/A 1145396Ssaidi@eecs.umich.eduextra_python_paths = [ 1155863Snate@binkert.org Dir('src/python').srcnode().abspath, # M5 includes 1165863Snate@binkert.org Dir('ext/ply').srcnode().abspath, # ply is used by several files 1174202Sbinkertn@umich.edu ] 1185863Snate@binkert.org 1195863Snate@binkert.orgsys.path[1:1] = extra_python_paths 1205863Snate@binkert.org 1215863Snate@binkert.orgfrom m5.util import compareVersions, readCommand 122955SN/A 1236654Snate@binkert.org######################################################################## 1245273Sstever@gmail.com# 1255871Snate@binkert.org# Set up the main build environment. 1265273Sstever@gmail.com# 1276655Snate@binkert.org######################################################################## 1288878Ssteve.reinhardt@amd.comuse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1296655Snate@binkert.org 'PYTHONPATH', 'RANLIB' ]) 1306655Snate@binkert.org 1319219Spower.jg@gmail.comuse_env = {} 1326655Snate@binkert.orgfor key,val in os.environ.iteritems(): 1335871Snate@binkert.org if key in use_vars or key.startswith("M5"): 1346654Snate@binkert.org use_env[key] = val 1358947Sandreas.hansson@arm.com 1365396Ssaidi@eecs.umich.edumain = Environment(ENV=use_env) 1378120Sgblack@eecs.umich.edumain.root = Dir(".") # The current directory (where this file lives). 1388120Sgblack@eecs.umich.edumain.srcdir = Dir("src") # The source directory 1398120Sgblack@eecs.umich.edu 1408120Sgblack@eecs.umich.edu# add useful python code PYTHONPATH so it can be used by subprocesses 1418120Sgblack@eecs.umich.edu# as well 1428120Sgblack@eecs.umich.edumain.AppendENVPath('PYTHONPATH', extra_python_paths) 1438120Sgblack@eecs.umich.edu 1448120Sgblack@eecs.umich.edu######################################################################## 1458879Ssteve.reinhardt@amd.com# 1468879Ssteve.reinhardt@amd.com# Mercurial Stuff. 1478879Ssteve.reinhardt@amd.com# 1488879Ssteve.reinhardt@amd.com# If the M5 directory is a mercurial repository, we should do some 1498879Ssteve.reinhardt@amd.com# extra things. 1508879Ssteve.reinhardt@amd.com# 1518879Ssteve.reinhardt@amd.com######################################################################## 1528879Ssteve.reinhardt@amd.com 1538879Ssteve.reinhardt@amd.comhgdir = main.root.Dir(".hg") 1548879Ssteve.reinhardt@amd.com 1558879Ssteve.reinhardt@amd.commercurial_style_message = """ 1568879Ssteve.reinhardt@amd.comYou're missing the M5 style hook. 1578879Ssteve.reinhardt@amd.comPlease install the hook so we can ensure that all code fits a common style. 1588120Sgblack@eecs.umich.edu 1598120Sgblack@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc 1608120Sgblack@eecs.umich.eduor your personal .hgrc 1618120Sgblack@eecs.umich.edu---------------- 1628120Sgblack@eecs.umich.edu 1638120Sgblack@eecs.umich.edu[extensions] 1648120Sgblack@eecs.umich.edustyle = %s/util/style.py 1658120Sgblack@eecs.umich.edu 1668120Sgblack@eecs.umich.edu[hooks] 1678120Sgblack@eecs.umich.edupretxncommit.style = python:style.check_whitespace 1688120Sgblack@eecs.umich.edu""" % (main.root) 1698120Sgblack@eecs.umich.edu 1708120Sgblack@eecs.umich.edumercurial_bin_not_found = """ 1718120Sgblack@eecs.umich.eduMercurial binary cannot be found, unfortunately this means that we 1728879Ssteve.reinhardt@amd.comcannot easily determine the version of M5 that you are running and 1738879Ssteve.reinhardt@amd.comthis makes error messages more difficult to collect. Please consider 1748879Ssteve.reinhardt@amd.cominstalling mercurial if you choose to post an error message 1758879Ssteve.reinhardt@amd.com""" 17610458Sandreas.hansson@arm.com 17710458Sandreas.hansson@arm.commercurial_lib_not_found = """ 17810458Sandreas.hansson@arm.comMercurial libraries cannot be found, ignoring style hook 1798879Ssteve.reinhardt@amd.comIf you are actually a M5 developer, please fix this and 1808879Ssteve.reinhardt@amd.comrun the style hook. It is important. 1818879Ssteve.reinhardt@amd.com""" 1828879Ssteve.reinhardt@amd.com 1839227Sandreas.hansson@arm.comhg_info = "Unknown" 1849227Sandreas.hansson@arm.comif hgdir.exists(): 1858879Ssteve.reinhardt@amd.com # 1) Grab repository revision if we know it. 1868879Ssteve.reinhardt@amd.com cmd = "hg id -n -i -t -b" 1878879Ssteve.reinhardt@amd.com try: 1888879Ssteve.reinhardt@amd.com hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 18910453SAndrew.Bardsley@arm.com except OSError: 19010453SAndrew.Bardsley@arm.com print mercurial_bin_not_found 19110453SAndrew.Bardsley@arm.com 19210456SCurtis.Dunham@arm.com # 2) Ensure that the style hook is in place. 19310456SCurtis.Dunham@arm.com try: 19410456SCurtis.Dunham@arm.com ui = None 19510457Sandreas.hansson@arm.com if ARGUMENTS.get('IGNORE_STYLE') != 'True': 19610457Sandreas.hansson@arm.com from mercurial import ui 1978120Sgblack@eecs.umich.edu ui = ui.ui() 1988947Sandreas.hansson@arm.com except ImportError: 1997816Ssteve.reinhardt@amd.com print mercurial_lib_not_found 2005871Snate@binkert.org 2015871Snate@binkert.org if ui is not None: 2026121Snate@binkert.org ui.readconfig(hgdir.File('hgrc').abspath) 2035871Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) 2045871Snate@binkert.org 2059926Sstan.czerniawski@arm.com if not style_hook: 2069926Sstan.czerniawski@arm.com print mercurial_style_message 2079119Sandreas.hansson@arm.com sys.exit(1) 20810068Sandreas.hansson@arm.comelse: 20910068Sandreas.hansson@arm.com print ".hg directory not found" 210955SN/A 2119416SAndreas.Sandberg@ARM.commain['HG_INFO'] = hg_info 2129416SAndreas.Sandberg@ARM.com 2139416SAndreas.Sandberg@ARM.com################################################### 2149416SAndreas.Sandberg@ARM.com# 2159416SAndreas.Sandberg@ARM.com# Figure out which configurations to set up based on the path(s) of 2169416SAndreas.Sandberg@ARM.com# the target(s). 2179416SAndreas.Sandberg@ARM.com# 2185871Snate@binkert.org################################################### 21910584Sandreas.hansson@arm.com 2209416SAndreas.Sandberg@ARM.com# Find default configuration & binary. 2219416SAndreas.Sandberg@ARM.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2225871Snate@binkert.org 223955SN/A# helper function: find last occurrence of element in list 2246121Snate@binkert.orgdef rfind(l, elt, offs = -1): 2258881Smarc.orr@gmail.com for i in range(len(l)+offs, 0, -1): 2266121Snate@binkert.org if l[i] == elt: 2276121Snate@binkert.org return i 2281533SN/A raise ValueError, "element not found" 2299239Sandreas.hansson@arm.com 2309239Sandreas.hansson@arm.com# Each target must have 'build' in the interior of the path; the 2319239Sandreas.hansson@arm.com# directory below this will determine the build parameters. For 2329239Sandreas.hansson@arm.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2339239Sandreas.hansson@arm.com# recognize that ALPHA_SE specifies the configuration because it 2349239Sandreas.hansson@arm.com# follow 'build' in the bulid path. 2359239Sandreas.hansson@arm.com 2369239Sandreas.hansson@arm.com# Generate absolute paths to targets so we can see where the build dir is 2379239Sandreas.hansson@arm.comif COMMAND_LINE_TARGETS: 2389239Sandreas.hansson@arm.com # Ask SCons which directory it was invoked from 2399239Sandreas.hansson@arm.com launch_dir = GetLaunchDir() 2409239Sandreas.hansson@arm.com # Make targets relative to invocation directory 2416655Snate@binkert.org abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2426655Snate@binkert.org COMMAND_LINE_TARGETS] 2436655Snate@binkert.orgelse: 2446655Snate@binkert.org # Default targets are relative to root of tree 2455871Snate@binkert.org abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2465871Snate@binkert.org DEFAULT_TARGETS] 2475863Snate@binkert.org 2485871Snate@binkert.org 2498878Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the 2505871Snate@binkert.org# collected targets reference. 2515871Snate@binkert.orgvariant_paths = [] 2525871Snate@binkert.orgbuild_root = None 2535863Snate@binkert.orgfor t in abs_targets: 2546121Snate@binkert.org path_dirs = t.split('/') 2555863Snate@binkert.org try: 2565871Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 2578336Ssteve.reinhardt@amd.com except: 2588336Ssteve.reinhardt@amd.com print "Error: no non-leaf 'build' dir found on target path", t 2598336Ssteve.reinhardt@amd.com Exit(1) 2608336Ssteve.reinhardt@amd.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2614678Snate@binkert.org if not build_root: 2628336Ssteve.reinhardt@amd.com build_root = this_build_root 2638336Ssteve.reinhardt@amd.com else: 2648336Ssteve.reinhardt@amd.com if this_build_root != build_root: 2654678Snate@binkert.org print "Error: build targets not under same build root\n"\ 2664678Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 2674678Snate@binkert.org Exit(1) 2684678Snate@binkert.org variant_path = joinpath('/',*path_dirs[:build_top+2]) 2697827Snate@binkert.org if variant_path not in variant_paths: 2707827Snate@binkert.org variant_paths.append(variant_path) 2718336Ssteve.reinhardt@amd.com 2724678Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 2738336Ssteve.reinhardt@amd.comif not isdir(build_root): 2748336Ssteve.reinhardt@amd.com mkdir(build_root) 2758336Ssteve.reinhardt@amd.com 2768336Ssteve.reinhardt@amd.comExport('main') 2778336Ssteve.reinhardt@amd.com 2788336Ssteve.reinhardt@amd.commain.SConsignFile(joinpath(build_root, "sconsign")) 2795871Snate@binkert.org 2805871Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 2818336Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves 2828336Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link. Symbolic 2838336Ssteve.reinhardt@amd.com# (soft) links work better. 2848336Ssteve.reinhardt@amd.commain.SetOption('duplicate', 'soft-copy') 2858336Ssteve.reinhardt@amd.com 2865871Snate@binkert.org# 2878336Ssteve.reinhardt@amd.com# Set up global sticky variables... these are common to an entire build 2888336Ssteve.reinhardt@amd.com# tree (not specific to a particular build like ALPHA_SE) 2898336Ssteve.reinhardt@amd.com# 2908336Ssteve.reinhardt@amd.com 2918336Ssteve.reinhardt@amd.com# Variable validators & converters for global sticky variables 2924678Snate@binkert.orgdef PathListMakeAbsolute(val): 2935871Snate@binkert.org if not val: 2944678Snate@binkert.org return val 2958336Ssteve.reinhardt@amd.com f = lambda p: abspath(expanduser(p)) 2968336Ssteve.reinhardt@amd.com return ':'.join(map(f, val.split(':'))) 2978336Ssteve.reinhardt@amd.com 2988336Ssteve.reinhardt@amd.comdef PathListAllExist(key, val, env): 2998336Ssteve.reinhardt@amd.com if not val: 3008336Ssteve.reinhardt@amd.com return 3018336Ssteve.reinhardt@amd.com paths = val.split(':') 3028336Ssteve.reinhardt@amd.com for path in paths: 3038336Ssteve.reinhardt@amd.com if not isdir(path): 3048336Ssteve.reinhardt@amd.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 3058336Ssteve.reinhardt@amd.com 3068336Ssteve.reinhardt@amd.comglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 3078336Ssteve.reinhardt@amd.com 3088336Ssteve.reinhardt@amd.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 3098336Ssteve.reinhardt@amd.com 3108336Ssteve.reinhardt@amd.comglobal_sticky_vars.AddVariables( 3118336Ssteve.reinhardt@amd.com ('CC', 'C compiler', environ.get('CC', main['CC'])), 3125871Snate@binkert.org ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3136121Snate@binkert.org ('BATCH', 'Use batch pool for build and tests', False), 314955SN/A ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 315955SN/A ('EXTRAS', 'Add Extra directories to the compilation', '', 3162632Sstever@eecs.umich.edu PathListAllExist, PathListMakeAbsolute), 3172632Sstever@eecs.umich.edu ) 318955SN/A 319955SN/A# base help text 320955SN/Ahelp_text = ''' 321955SN/AUsage: scons [scons options] [build options] [target(s)] 3228878Ssteve.reinhardt@amd.com 323955SN/AGlobal sticky options: 3242632Sstever@eecs.umich.edu''' 3252632Sstever@eecs.umich.edu 3262632Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3272632Sstever@eecs.umich.eduglobal_sticky_vars.Update(main) 3282632Sstever@eecs.umich.edu 3292632Sstever@eecs.umich.eduhelp_text += global_sticky_vars.GenerateHelpText(main) 3302632Sstever@eecs.umich.edu 3318268Ssteve.reinhardt@amd.com# Save sticky variable settings back to current variables file 3328268Ssteve.reinhardt@amd.comglobal_sticky_vars.Save(global_sticky_vars_file, main) 3338268Ssteve.reinhardt@amd.com 3348268Ssteve.reinhardt@amd.com# Parse EXTRAS variable to build list of all directories where we're 3358268Ssteve.reinhardt@amd.com# look for sources etc. This list is exported as base_dir_list. 3368268Ssteve.reinhardt@amd.combase_dir = main.srcdir.abspath 3378268Ssteve.reinhardt@amd.comif main['EXTRAS']: 3382632Sstever@eecs.umich.edu extras_dir_list = main['EXTRAS'].split(':') 3392632Sstever@eecs.umich.eduelse: 3402632Sstever@eecs.umich.edu extras_dir_list = [] 3412632Sstever@eecs.umich.edu 3428268Ssteve.reinhardt@amd.comExport('base_dir') 3432632Sstever@eecs.umich.eduExport('extras_dir_list') 3448268Ssteve.reinhardt@amd.com 3458268Ssteve.reinhardt@amd.com# the ext directory should be on the #includes path 3468268Ssteve.reinhardt@amd.commain.Append(CPPPATH=[Dir('ext')]) 3478268Ssteve.reinhardt@amd.com 3483718Sstever@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 3492634Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 3502634Sstever@eecs.umich.edu 3515863Snate@binkert.orgmain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3522638Sstever@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3538268Ssteve.reinhardt@amd.commain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 3542632Sstever@eecs.umich.eduif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 3552632Sstever@eecs.umich.edu print 'Error: How can we have two at the same time?' 3562632Sstever@eecs.umich.edu Exit(1) 3572632Sstever@eecs.umich.edu 3582632Sstever@eecs.umich.edu# Set up default C++ compiler flags 3591858SN/Aif main['GCC']: 3603716Sstever@eecs.umich.edu main.Append(CCFLAGS='-pipe') 3612638Sstever@eecs.umich.edu main.Append(CCFLAGS='-fno-strict-aliasing') 3622638Sstever@eecs.umich.edu main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 3632638Sstever@eecs.umich.edu main.Append(CXXFLAGS='-Wno-deprecated') 3642638Sstever@eecs.umich.eduelif main['ICC']: 3652638Sstever@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 3662638Sstever@eecs.umich.eduelif main['SUNCC']: 3672638Sstever@eecs.umich.edu main.Append(CCFLAGS='-Qoption ccfe') 3685863Snate@binkert.org main.Append(CCFLAGS='-features=gcc') 3695863Snate@binkert.org main.Append(CCFLAGS='-features=extensions') 3705863Snate@binkert.org main.Append(CCFLAGS='-library=stlport4') 371955SN/A main.Append(CCFLAGS='-xar') 3725341Sstever@gmail.com #main.Append(CCFLAGS='-instances=semiexplicit') 3735341Sstever@gmail.comelse: 3745863Snate@binkert.org print 'Error: Don\'t know what compiler options to use for your compiler.' 3757756SAli.Saidi@ARM.com print ' Please fix SConstruct and src/SConscript and try again.' 3765341Sstever@gmail.com Exit(1) 3776121Snate@binkert.org 3784494Ssaidi@eecs.umich.edu# Set up common yacc/bison flags (needed for Ruby) 3796121Snate@binkert.orgmain['YACCFLAGS'] = '-d' 3801105SN/Amain['YACCHXXFILESUFFIX'] = '.hh' 3812667Sstever@eecs.umich.edu 3822667Sstever@eecs.umich.edu# Do this after we save setting back, or else we'll tack on an 3832667Sstever@eecs.umich.edu# extra 'qdo' every time we run scons. 3842667Sstever@eecs.umich.eduif main['BATCH']: 3856121Snate@binkert.org main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 3862667Sstever@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 3875341Sstever@gmail.com main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 3885863Snate@binkert.org main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 3895341Sstever@gmail.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 3905341Sstever@gmail.com 3915341Sstever@gmail.comif sys.platform == 'cygwin': 3928120Sgblack@eecs.umich.edu # cygwin has some header file issues... 3935341Sstever@gmail.com main.Append(CCFLAGS="-Wno-uninitialized") 3948120Sgblack@eecs.umich.edu 3955341Sstever@gmail.com# Check for SWIG 3968120Sgblack@eecs.umich.eduif not main.has_key('SWIG'): 3976121Snate@binkert.org print 'Error: SWIG utility not found.' 3986121Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 3998980Ssteve.reinhardt@amd.com Exit(1) 4009396Sandreas.hansson@arm.com 4015397Ssaidi@eecs.umich.edu# Check for appropriate SWIG version 4025397Ssaidi@eecs.umich.eduswig_version = readCommand(('swig', '-version'), exception='').split() 4037727SAli.Saidi@ARM.com# First 3 words should be "SWIG Version x.y.z" 4048268Ssteve.reinhardt@amd.comif len(swig_version) < 3 or \ 4056168Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 4065341Sstever@gmail.com print 'Error determining SWIG version.' 4078120Sgblack@eecs.umich.edu Exit(1) 4088120Sgblack@eecs.umich.edu 4098120Sgblack@eecs.umich.edumin_swig_version = '1.3.28' 4106814Sgblack@eecs.umich.eduif compareVersions(swig_version[2], min_swig_version) < 0: 4115863Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 4128120Sgblack@eecs.umich.edu print ' Installed version:', swig_version[2] 4135341Sstever@gmail.com Exit(1) 4145863Snate@binkert.org 4158268Ssteve.reinhardt@amd.com# Set up SWIG flags & scanner 4166121Snate@binkert.orgswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4176121Snate@binkert.orgmain.Append(SWIGFLAGS=swig_flags) 4188268Ssteve.reinhardt@amd.com 4195742Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 4205742Snate@binkert.org# stuff for some reason 4215341Sstever@gmail.comscanners = [] 4225742Snate@binkert.orgfor scanner in main['SCANNERS']: 4235742Snate@binkert.org skeys = scanner.skeys 4245341Sstever@gmail.com if skeys == '.i': 4256017Snate@binkert.org continue 4266121Snate@binkert.org 4276017Snate@binkert.org if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4287816Ssteve.reinhardt@amd.com continue 4297756SAli.Saidi@ARM.com 4307756SAli.Saidi@ARM.com scanners.append(scanner) 4317756SAli.Saidi@ARM.com 4327756SAli.Saidi@ARM.com# add the new swig scanner that we like better 4337756SAli.Saidi@ARM.comfrom SCons.Scanner import ClassicCPP as CPPScanner 4347756SAli.Saidi@ARM.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4357756SAli.Saidi@ARM.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4367756SAli.Saidi@ARM.com 4377816Ssteve.reinhardt@amd.com# replace the scanners list that has what we want 4387816Ssteve.reinhardt@amd.commain['SCANNERS'] = scanners 4397816Ssteve.reinhardt@amd.com 4407816Ssteve.reinhardt@amd.com# Add a custom Check function to the Configure context so that we can 4417816Ssteve.reinhardt@amd.com# figure out if the compiler adds leading underscores to global 4427816Ssteve.reinhardt@amd.com# variables. This is needed for the autogenerated asm files that we 4437816Ssteve.reinhardt@amd.com# use for embedding the python code. 4447816Ssteve.reinhardt@amd.comdef CheckLeading(context): 4457816Ssteve.reinhardt@amd.com context.Message("Checking for leading underscore in global variables...") 4467816Ssteve.reinhardt@amd.com # 1) Define a global variable called x from asm so the C compiler 4477756SAli.Saidi@ARM.com # won't change the symbol at all. 4487816Ssteve.reinhardt@amd.com # 2) Declare that variable. 4497816Ssteve.reinhardt@amd.com # 3) Use the variable 4507816Ssteve.reinhardt@amd.com # 4517816Ssteve.reinhardt@amd.com # If the compiler prepends an underscore, this will successfully 4527816Ssteve.reinhardt@amd.com # link because the external symbol 'x' will be called '_x' which 4537816Ssteve.reinhardt@amd.com # was defined by the asm statement. If the compiler does not 4547816Ssteve.reinhardt@amd.com # prepend an underscore, this will not successfully link because 4557816Ssteve.reinhardt@amd.com # '_x' will have been defined by assembly, while the C portion of 4567816Ssteve.reinhardt@amd.com # the code will be trying to use 'x' 4577816Ssteve.reinhardt@amd.com ret = context.TryLink(''' 4587816Ssteve.reinhardt@amd.com asm(".globl _x; _x: .byte 0"); 4597816Ssteve.reinhardt@amd.com extern int x; 4607816Ssteve.reinhardt@amd.com int main() { return x; } 4617816Ssteve.reinhardt@amd.com ''', extension=".c") 4627816Ssteve.reinhardt@amd.com context.env.Append(LEADING_UNDERSCORE=ret) 4637816Ssteve.reinhardt@amd.com context.Result(ret) 4647816Ssteve.reinhardt@amd.com return ret 4657816Ssteve.reinhardt@amd.com 4667816Ssteve.reinhardt@amd.com# Platform-specific configuration. Note again that we assume that all 4677816Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform. 4687816Ssteve.reinhardt@amd.comconf = Configure(main, 4697816Ssteve.reinhardt@amd.com conf_dir = joinpath(build_root, '.scons_config'), 4707816Ssteve.reinhardt@amd.com log_file = joinpath(build_root, 'scons_config.log'), 4717816Ssteve.reinhardt@amd.com custom_tests = { 'CheckLeading' : CheckLeading }) 4727816Ssteve.reinhardt@amd.com 4737816Ssteve.reinhardt@amd.com# Check for leading underscores. Don't really need to worry either 4747816Ssteve.reinhardt@amd.com# way so don't need to check the return code. 4757816Ssteve.reinhardt@amd.comconf.CheckLeading() 4767816Ssteve.reinhardt@amd.com 4777816Ssteve.reinhardt@amd.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 4787816Ssteve.reinhardt@amd.comtry: 4797816Ssteve.reinhardt@amd.com import platform 4807816Ssteve.reinhardt@amd.com uname = platform.uname() 4817816Ssteve.reinhardt@amd.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 4827816Ssteve.reinhardt@amd.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 4837816Ssteve.reinhardt@amd.com main.Append(CCFLAGS='-arch x86_64') 4847816Ssteve.reinhardt@amd.com main.Append(CFLAGS='-arch x86_64') 4857816Ssteve.reinhardt@amd.com main.Append(LINKFLAGS='-arch x86_64') 4867816Ssteve.reinhardt@amd.com main.Append(ASFLAGS='-arch x86_64') 4877816Ssteve.reinhardt@amd.comexcept: 4887816Ssteve.reinhardt@amd.com pass 4897816Ssteve.reinhardt@amd.com 4907816Ssteve.reinhardt@amd.com# Recent versions of scons substitute a "Null" object for Configure() 4917816Ssteve.reinhardt@amd.com# when configuration isn't necessary, e.g., if the "--help" option is 4927816Ssteve.reinhardt@amd.com# present. Unfortuantely this Null object always returns false, 4937816Ssteve.reinhardt@amd.com# breaking all our configuration checks. We replace it with our own 4947816Ssteve.reinhardt@amd.com# more optimistic null object that returns True instead. 4957816Ssteve.reinhardt@amd.comif not conf: 4967816Ssteve.reinhardt@amd.com def NullCheck(*args, **kwargs): 4977816Ssteve.reinhardt@amd.com return True 4987816Ssteve.reinhardt@amd.com 4997816Ssteve.reinhardt@amd.com class NullConf: 5007816Ssteve.reinhardt@amd.com def __init__(self, env): 5017816Ssteve.reinhardt@amd.com self.env = env 5027816Ssteve.reinhardt@amd.com def Finish(self): 5037816Ssteve.reinhardt@amd.com return self.env 5047816Ssteve.reinhardt@amd.com def __getattr__(self, mname): 5057816Ssteve.reinhardt@amd.com return NullCheck 5067816Ssteve.reinhardt@amd.com 5077816Ssteve.reinhardt@amd.com conf = NullConf(main) 5087816Ssteve.reinhardt@amd.com 5098947Sandreas.hansson@arm.com# Find Python include and library directories for embedding the 5108947Sandreas.hansson@arm.com# interpreter. For consistency, we will use the same Python 5117756SAli.Saidi@ARM.com# installation used to run scons (and thus this script). If you want 5128120Sgblack@eecs.umich.edu# to link in an alternate version, see above for instructions on how 5137756SAli.Saidi@ARM.com# to invoke scons with a different copy of the Python interpreter. 5147756SAli.Saidi@ARM.comfrom distutils import sysconfig 5157756SAli.Saidi@ARM.com 5167756SAli.Saidi@ARM.compy_getvar = sysconfig.get_config_var 5177816Ssteve.reinhardt@amd.com 5187816Ssteve.reinhardt@amd.compy_debug = getattr(sys, 'pydebug', False) 5197816Ssteve.reinhardt@amd.compy_version = 'python' + py_getvar('VERSION') + (py_debug and "_d" or "") 5207816Ssteve.reinhardt@amd.com 5217816Ssteve.reinhardt@amd.compy_general_include = sysconfig.get_python_inc() 5227816Ssteve.reinhardt@amd.compy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5237816Ssteve.reinhardt@amd.compy_includes = [ py_general_include ] 5247816Ssteve.reinhardt@amd.comif py_platform_include != py_general_include: 5257816Ssteve.reinhardt@amd.com py_includes.append(py_platform_include) 5267816Ssteve.reinhardt@amd.com 5277756SAli.Saidi@ARM.compy_lib_path = [ py_getvar('LIBDIR') ] 5287756SAli.Saidi@ARM.com# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5299227Sandreas.hansson@arm.com# shared library in prefix/lib/. 5309227Sandreas.hansson@arm.comif not py_getvar('Py_ENABLE_SHARED'): 5319227Sandreas.hansson@arm.com py_lib_path.append(py_getvar('LIBPL')) 5329227Sandreas.hansson@arm.com 5339590Sandreas@sandberg.pp.sepy_libs = [] 5349590Sandreas@sandberg.pp.sefor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 5359590Sandreas@sandberg.pp.se assert lib.startswith('-l') 5369590Sandreas@sandberg.pp.se lib = lib[2:] 5379590Sandreas@sandberg.pp.se if lib not in py_libs: 5389590Sandreas@sandberg.pp.se py_libs.append(lib) 5396654Snate@binkert.orgpy_libs.append(py_version) 5406654Snate@binkert.org 5415871Snate@binkert.orgmain.Append(CPPPATH=py_includes) 5426121Snate@binkert.orgmain.Append(LIBPATH=py_lib_path) 5438946Sandreas.hansson@arm.com 5449419Sandreas.hansson@arm.com# verify that this stuff works 5453940Ssaidi@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 5463918Ssaidi@eecs.umich.edu print "Error: can't find Python.h header in", py_includes 5473918Ssaidi@eecs.umich.edu Exit(1) 5481858SN/A 5499556Sandreas.hansson@arm.comfor lib in py_libs: 5509556Sandreas.hansson@arm.com if not conf.CheckLib(lib): 5519556Sandreas.hansson@arm.com print "Error: can't find library %s required by python" % lib 5529556Sandreas.hansson@arm.com Exit(1) 5539556Sandreas.hansson@arm.com 5549556Sandreas.hansson@arm.com# On Solaris you need to use libsocket for socket ops 5559556Sandreas.hansson@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5569556Sandreas.hansson@arm.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5579556Sandreas.hansson@arm.com print "Can't find library with socket calls (e.g. accept())" 5589556Sandreas.hansson@arm.com Exit(1) 5599556Sandreas.hansson@arm.com 5609556Sandreas.hansson@arm.com# Check for zlib. If the check passes, libz will be automatically 5619556Sandreas.hansson@arm.com# added to the LIBS environment variable. 5629556Sandreas.hansson@arm.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5639556Sandreas.hansson@arm.com print 'Error: did not find needed zlib compression library '\ 5649556Sandreas.hansson@arm.com 'and/or zlib.h header file.' 5659556Sandreas.hansson@arm.com print ' Please install zlib and try again.' 5669556Sandreas.hansson@arm.com Exit(1) 5679556Sandreas.hansson@arm.com 5689556Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control) 5699556Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 5709556Sandreas.hansson@arm.comif not have_fenv: 5719556Sandreas.hansson@arm.com print "Warning: Header file <fenv.h> not found." 5729556Sandreas.hansson@arm.com print " This host has no IEEE FP rounding mode control." 5739556Sandreas.hansson@arm.com 5749556Sandreas.hansson@arm.com###################################################################### 5759556Sandreas.hansson@arm.com# 5769556Sandreas.hansson@arm.com# Check for mysql. 5779556Sandreas.hansson@arm.com# 5789556Sandreas.hansson@arm.commysql_config = WhereIs('mysql_config') 5799556Sandreas.hansson@arm.comhave_mysql = bool(mysql_config) 5809556Sandreas.hansson@arm.com 5816121Snate@binkert.org# Check MySQL version. 58210238Sandreas.hansson@arm.comif have_mysql: 58310238Sandreas.hansson@arm.com mysql_version = readCommand(mysql_config + ' --version') 58410238Sandreas.hansson@arm.com min_mysql_version = '4.1' 58510238Sandreas.hansson@arm.com if compareVersions(mysql_version, min_mysql_version) < 0: 5869420Sandreas.hansson@arm.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 58710238Sandreas.hansson@arm.com print ' Version', mysql_version, 'detected.' 58810238Sandreas.hansson@arm.com have_mysql = False 5899420Sandreas.hansson@arm.com 5909420Sandreas.hansson@arm.com# Set up mysql_config commands. 5919420Sandreas.hansson@arm.comif have_mysql: 5929420Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --include' 5939420Sandreas.hansson@arm.com if os.system(mysql_config_include + ' > /dev/null') != 0: 59410264Sandreas.hansson@arm.com # older mysql_config versions don't support --include, use 59510264Sandreas.hansson@arm.com # --cflags instead 59610264Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 59710264Sandreas.hansson@arm.com # This seems to work in all versions 59810264Sandreas.hansson@arm.com mysql_config_libs = mysql_config + ' --libs' 59910264Sandreas.hansson@arm.com 60010264Sandreas.hansson@arm.com###################################################################### 60110264Sandreas.hansson@arm.com# 60210264Sandreas.hansson@arm.com# Finish the configuration 60310264Sandreas.hansson@arm.com# 60410264Sandreas.hansson@arm.commain = conf.Finish() 60510264Sandreas.hansson@arm.com 60610264Sandreas.hansson@arm.com###################################################################### 60710264Sandreas.hansson@arm.com# 60810264Sandreas.hansson@arm.com# Collect all non-global variables 60910264Sandreas.hansson@arm.com# 61010457Sandreas.hansson@arm.com 61110457Sandreas.hansson@arm.com# Define the universe of supported ISAs 61210457Sandreas.hansson@arm.comall_isa_list = [ ] 61310457Sandreas.hansson@arm.comExport('all_isa_list') 61410457Sandreas.hansson@arm.com 61510457Sandreas.hansson@arm.comclass CpuModel(object): 61610457Sandreas.hansson@arm.com '''The CpuModel class encapsulates everything the ISA parser needs to 61710457Sandreas.hansson@arm.com know about a particular CPU model.''' 61810457Sandreas.hansson@arm.com 61910238Sandreas.hansson@arm.com # Dict of available CPU model objects. Accessible as CpuModel.dict. 62010238Sandreas.hansson@arm.com dict = {} 62110238Sandreas.hansson@arm.com list = [] 62210238Sandreas.hansson@arm.com defaults = [] 62310238Sandreas.hansson@arm.com 62410238Sandreas.hansson@arm.com # Constructor. Automatically adds models to CpuModel.dict. 62510416Sandreas.hansson@arm.com def __init__(self, name, filename, includes, strings, default=False): 62610238Sandreas.hansson@arm.com self.name = name # name of model 6279227Sandreas.hansson@arm.com self.filename = filename # filename for output exec code 62810238Sandreas.hansson@arm.com self.includes = includes # include files needed in exec file 62910416Sandreas.hansson@arm.com # The 'strings' dict holds all the per-CPU symbols we can 63010416Sandreas.hansson@arm.com # substitute into templates etc. 6319227Sandreas.hansson@arm.com self.strings = strings 6329590Sandreas@sandberg.pp.se 6339590Sandreas@sandberg.pp.se # This cpu is enabled by default 6349590Sandreas@sandberg.pp.se self.default = default 6358737Skoansin.tan@gmail.com 63610238Sandreas.hansson@arm.com # Add self to dict 63710238Sandreas.hansson@arm.com if name in CpuModel.dict: 6389420Sandreas.hansson@arm.com raise AttributeError, "CpuModel '%s' already registered" % name 6398737Skoansin.tan@gmail.com CpuModel.dict[name] = self 64010106SMitch.Hayenga@arm.com CpuModel.list.append(name) 6418737Skoansin.tan@gmail.com 6428737Skoansin.tan@gmail.comExport('CpuModel') 64310238Sandreas.hansson@arm.com 64410238Sandreas.hansson@arm.com# Sticky variables get saved in the variables file so they persist from 6458737Skoansin.tan@gmail.com# one invocation to the next (unless overridden, in which case the new 6468737Skoansin.tan@gmail.com# value becomes sticky). 6478737Skoansin.tan@gmail.comsticky_vars = Variables(args=ARGUMENTS) 6488737Skoansin.tan@gmail.comExport('sticky_vars') 6498737Skoansin.tan@gmail.com 6508737Skoansin.tan@gmail.com# Sticky variables that should be exported 6519556Sandreas.hansson@arm.comexport_vars = [] 6529556Sandreas.hansson@arm.comExport('export_vars') 6539556Sandreas.hansson@arm.com 6549556Sandreas.hansson@arm.com# Non-sticky variables only apply to the current build. 6559556Sandreas.hansson@arm.comnonsticky_vars = Variables(args=ARGUMENTS) 6569556Sandreas.hansson@arm.comExport('nonsticky_vars') 6579556Sandreas.hansson@arm.com 6589556Sandreas.hansson@arm.com# Walk the tree and execute all SConsopts scripts that wil add to the 65910278SAndreas.Sandberg@ARM.com# above variables 66010278SAndreas.Sandberg@ARM.comfor bdir in [ base_dir ] + extras_dir_list: 66110278SAndreas.Sandberg@ARM.com for root, dirs, files in os.walk(bdir): 66210278SAndreas.Sandberg@ARM.com if 'SConsopts' in files: 66310278SAndreas.Sandberg@ARM.com print "Reading", joinpath(root, 'SConsopts') 66410278SAndreas.Sandberg@ARM.com SConscript(joinpath(root, 'SConsopts')) 6659556Sandreas.hansson@arm.com 6669590Sandreas@sandberg.pp.seall_isa_list.sort() 6679590Sandreas@sandberg.pp.se 6689420Sandreas.hansson@arm.comsticky_vars.AddVariables( 6699846Sandreas.hansson@arm.com EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6709846Sandreas.hansson@arm.com BoolVariable('FULL_SYSTEM', 'Full-system support', False), 6719846Sandreas.hansson@arm.com ListVariable('CPU_MODELS', 'CPU models', 6729846Sandreas.hansson@arm.com sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 6738946Sandreas.hansson@arm.com sorted(CpuModel.list)), 6743918Ssaidi@eecs.umich.edu BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6759068SAli.Saidi@ARM.com BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6769068SAli.Saidi@ARM.com False), 6779068SAli.Saidi@ARM.com BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6789068SAli.Saidi@ARM.com False), 6799068SAli.Saidi@ARM.com BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 6809068SAli.Saidi@ARM.com False), 6819068SAli.Saidi@ARM.com BoolVariable('SS_COMPATIBLE_FP', 6829068SAli.Saidi@ARM.com 'Make floating-point results compatible with SimpleScalar', 6839068SAli.Saidi@ARM.com False), 6849419Sandreas.hansson@arm.com BoolVariable('USE_SSE2', 6859068SAli.Saidi@ARM.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 6869068SAli.Saidi@ARM.com False), 6879068SAli.Saidi@ARM.com BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6889068SAli.Saidi@ARM.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6899068SAli.Saidi@ARM.com BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 6909068SAli.Saidi@ARM.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 6913918Ssaidi@eecs.umich.edu BoolVariable('RUBY', 'Build with Ruby', False), 6923918Ssaidi@eecs.umich.edu ) 6936157Snate@binkert.org 6946157Snate@binkert.orgnonsticky_vars.AddVariables( 6956157Snate@binkert.org BoolVariable('update_ref', 'Update test reference outputs', False) 6966157Snate@binkert.org ) 6975397Ssaidi@eecs.umich.edu 6985397Ssaidi@eecs.umich.edu# These variables get exported to #defines in config/*.hh (see src/SConscript). 6996121Snate@binkert.orgexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 7006121Snate@binkert.org 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 7016121Snate@binkert.org 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 7026121Snate@binkert.org 7036121Snate@binkert.org################################################### 7046121Snate@binkert.org# 7055397Ssaidi@eecs.umich.edu# Define a SCons builder for configuration flag headers. 7061851SN/A# 7071851SN/A################################################### 7087739Sgblack@eecs.umich.edu 709955SN/A# This function generates a config header file that #defines the 7109396Sandreas.hansson@arm.com# variable symbol to the current variable setting (0 or 1). The source 7119396Sandreas.hansson@arm.com# operands are the name of the variable and a Value node containing the 7129396Sandreas.hansson@arm.com# value of the variable. 7139396Sandreas.hansson@arm.comdef build_config_file(target, source, env): 7149396Sandreas.hansson@arm.com (variable, value) = [s.get_contents() for s in source] 7159396Sandreas.hansson@arm.com f = file(str(target[0]), 'w') 7169396Sandreas.hansson@arm.com print >> f, '#define', variable, value 7179396Sandreas.hansson@arm.com f.close() 7189396Sandreas.hansson@arm.com return None 7199396Sandreas.hansson@arm.com 7209396Sandreas.hansson@arm.com# Generate the message to be printed when building the config file. 7219396Sandreas.hansson@arm.comdef build_config_file_string(target, source, env): 7229396Sandreas.hansson@arm.com (variable, value) = [s.get_contents() for s in source] 7239396Sandreas.hansson@arm.com return "Defining %s as %s in %s." % (variable, value, target[0]) 7249396Sandreas.hansson@arm.com 7259396Sandreas.hansson@arm.com# Combine the two functions into a scons Action object. 7269477Sandreas.hansson@arm.comconfig_action = Action(build_config_file, build_config_file_string) 7279477Sandreas.hansson@arm.com 7289477Sandreas.hansson@arm.com# The emitter munges the source & target node lists to reflect what 7299477Sandreas.hansson@arm.com# we're really doing. 7309477Sandreas.hansson@arm.comdef config_emitter(target, source, env): 7319477Sandreas.hansson@arm.com # extract variable name from Builder arg 7329477Sandreas.hansson@arm.com variable = str(target[0]) 7339477Sandreas.hansson@arm.com # True target is config header file 7349477Sandreas.hansson@arm.com target = joinpath('config', variable.lower() + '.hh') 7359477Sandreas.hansson@arm.com val = env[variable] 7369477Sandreas.hansson@arm.com if isinstance(val, bool): 7379477Sandreas.hansson@arm.com # Force value to 0/1 7389477Sandreas.hansson@arm.com val = int(val) 7399477Sandreas.hansson@arm.com elif isinstance(val, str): 7409477Sandreas.hansson@arm.com val = '"' + val + '"' 7419477Sandreas.hansson@arm.com 7429477Sandreas.hansson@arm.com # Sources are variable name & value (packaged in SCons Value nodes) 7439477Sandreas.hansson@arm.com return ([target], [Value(variable), Value(val)]) 7449477Sandreas.hansson@arm.com 7459477Sandreas.hansson@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 7469477Sandreas.hansson@arm.com 7479477Sandreas.hansson@arm.commain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 7489396Sandreas.hansson@arm.com 7493053Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root. 7506121Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 7513053Sstever@eecs.umich.edu variant_dir = joinpath(build_root, 'libelf')) 7523053Sstever@eecs.umich.edu 7533053Sstever@eecs.umich.edu# gzstream build is shared across all configs in the build root. 7543053Sstever@eecs.umich.edumain.SConscript('ext/gzstream/SConscript', 7553053Sstever@eecs.umich.edu variant_dir = joinpath(build_root, 'gzstream')) 7569072Sandreas.hansson@arm.com 7573053Sstever@eecs.umich.edu################################################### 7584742Sstever@eecs.umich.edu# 7594742Sstever@eecs.umich.edu# This function is used to set up a directory with switching headers 7603053Sstever@eecs.umich.edu# 7613053Sstever@eecs.umich.edu################################################### 7623053Sstever@eecs.umich.edu 76310181SCurtis.Dunham@arm.commain['ALL_ISA_LIST'] = all_isa_list 7646654Snate@binkert.orgdef make_switching_dir(dname, switch_headers, env): 7653053Sstever@eecs.umich.edu # Generate the header. target[0] is the full path of the output 7663053Sstever@eecs.umich.edu # header to generate. 'source' is a dummy variable, since we get the 7673053Sstever@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 7683053Sstever@eecs.umich.edu def gen_switch_hdr(target, source, env): 76910425Sandreas.hansson@arm.com fname = str(target[0]) 77010425Sandreas.hansson@arm.com f = open(fname, 'w') 77110425Sandreas.hansson@arm.com isa = env['TARGET_ISA'].lower() 77210425Sandreas.hansson@arm.com print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 77310425Sandreas.hansson@arm.com f.close() 77410425Sandreas.hansson@arm.com 77510425Sandreas.hansson@arm.com # String to print when generating header 77610425Sandreas.hansson@arm.com def gen_switch_hdr_string(target, source, env): 77710425Sandreas.hansson@arm.com return "Generating switch header " + str(target[0]) 77810425Sandreas.hansson@arm.com 77910425Sandreas.hansson@arm.com # Build SCons Action object. 'varlist' specifies env vars that this 7802667Sstever@eecs.umich.edu # action depends on; when env['ALL_ISA_LIST'] changes these actions 7814554Sbinkertn@umich.edu # should get re-executed. 7826121Snate@binkert.org switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 7832667Sstever@eecs.umich.edu varlist=['ALL_ISA_LIST']) 78410384SCurtis.Dunham@arm.com 78510384SCurtis.Dunham@arm.com # Instantiate actions for each header 78610384SCurtis.Dunham@arm.com for hdr in switch_headers: 78710384SCurtis.Dunham@arm.com env.Command(hdr, [], switch_hdr_action) 78810384SCurtis.Dunham@arm.comExport('make_switching_dir') 7894554Sbinkertn@umich.edu 7904554Sbinkertn@umich.edu################################################### 7914554Sbinkertn@umich.edu# 7926121Snate@binkert.org# Define build environments for selected configurations. 7934554Sbinkertn@umich.edu# 7944554Sbinkertn@umich.edu################################################### 7954554Sbinkertn@umich.edu 7964781Snate@binkert.orgfor variant_path in variant_paths: 7974554Sbinkertn@umich.edu print "Building in", variant_path 7984554Sbinkertn@umich.edu 7992667Sstever@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 8004554Sbinkertn@umich.edu env = main.Clone() 8014554Sbinkertn@umich.edu env['BUILDDIR'] = variant_path 8024554Sbinkertn@umich.edu 8034554Sbinkertn@umich.edu # variant_dir is the tail component of build path, and is used to 8042667Sstever@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 8054554Sbinkertn@umich.edu (build_root, variant_dir) = splitpath(variant_path) 8062667Sstever@eecs.umich.edu 8074554Sbinkertn@umich.edu # Set env variables according to the build directory config. 8086121Snate@binkert.org sticky_vars.files = [] 8092667Sstever@eecs.umich.edu # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 8105522Snate@binkert.org # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 8115522Snate@binkert.org # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 8125522Snate@binkert.org current_vars_file = joinpath(build_root, 'variables', variant_dir) 8135522Snate@binkert.org if isfile(current_vars_file): 8145522Snate@binkert.org sticky_vars.files.append(current_vars_file) 8155522Snate@binkert.org print "Using saved variables file %s" % current_vars_file 8165522Snate@binkert.org else: 8175522Snate@binkert.org # Build dir-specific variables file doesn't exist. 8185522Snate@binkert.org 8195522Snate@binkert.org # Make sure the directory is there so we can create it later 8205522Snate@binkert.org opt_dir = dirname(current_vars_file) 8215522Snate@binkert.org if not isdir(opt_dir): 8225522Snate@binkert.org mkdir(opt_dir) 8235522Snate@binkert.org 8245522Snate@binkert.org # Get default build variables from source tree. Variables are 8255522Snate@binkert.org # normally determined by name of $VARIANT_DIR, but can be 8265522Snate@binkert.org # overriden by 'default=' arg on command line. 8275522Snate@binkert.org default_vars_file = joinpath('build_opts', 8285522Snate@binkert.org ARGUMENTS.get('default', variant_dir)) 8295522Snate@binkert.org if isfile(default_vars_file): 8305522Snate@binkert.org sticky_vars.files.append(default_vars_file) 8315522Snate@binkert.org print "Variables file %s not found,\n using defaults in %s" \ 8325522Snate@binkert.org % (current_vars_file, default_vars_file) 8335522Snate@binkert.org else: 8345522Snate@binkert.org print "Error: cannot find variables file %s or %s" \ 8355522Snate@binkert.org % (current_vars_file, default_vars_file) 8369986Sandreas@sandberg.pp.se Exit(1) 8379986Sandreas@sandberg.pp.se 8389986Sandreas@sandberg.pp.se # Apply current variable settings to env 8399986Sandreas@sandberg.pp.se sticky_vars.Update(env) 8409986Sandreas@sandberg.pp.se nonsticky_vars.Update(env) 8419986Sandreas@sandberg.pp.se 8429986Sandreas@sandberg.pp.se help_text += "\nSticky variables for %s:\n" % variant_dir \ 8439986Sandreas@sandberg.pp.se + sticky_vars.GenerateHelpText(env) \ 8449986Sandreas@sandberg.pp.se + "\nNon-sticky variables for %s:\n" % variant_dir \ 8459986Sandreas@sandberg.pp.se + nonsticky_vars.GenerateHelpText(env) 8469986Sandreas@sandberg.pp.se 8479986Sandreas@sandberg.pp.se # Process variable settings. 8489986Sandreas@sandberg.pp.se 8499986Sandreas@sandberg.pp.se if not have_fenv and env['USE_FENV']: 8509986Sandreas@sandberg.pp.se print "Warning: <fenv.h> not available; " \ 8519986Sandreas@sandberg.pp.se "forcing USE_FENV to False in", variant_dir + "." 8529986Sandreas@sandberg.pp.se env['USE_FENV'] = False 8539986Sandreas@sandberg.pp.se 8549986Sandreas@sandberg.pp.se if not env['USE_FENV']: 8559986Sandreas@sandberg.pp.se print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 8562638Sstever@eecs.umich.edu print " FP results may deviate slightly from other platforms." 8572638Sstever@eecs.umich.edu 8586121Snate@binkert.org if env['EFENCE']: 8593716Sstever@eecs.umich.edu env.Append(LIBS=['efence']) 8605522Snate@binkert.org 8619986Sandreas@sandberg.pp.se if env['USE_MYSQL']: 8629986Sandreas@sandberg.pp.se if not have_mysql: 8639986Sandreas@sandberg.pp.se print "Warning: MySQL not available; " \ 8649986Sandreas@sandberg.pp.se "forcing USE_MYSQL to False in", variant_dir + "." 8655522Snate@binkert.org env['USE_MYSQL'] = False 8665522Snate@binkert.org else: 8675522Snate@binkert.org print "Compiling in", variant_dir, "with MySQL support." 8685522Snate@binkert.org env.ParseConfig(mysql_config_libs) 8691858SN/A env.ParseConfig(mysql_config_include) 8705227Ssaidi@eecs.umich.edu 8715227Ssaidi@eecs.umich.edu # Save sticky variable settings back to current variables file 8725227Ssaidi@eecs.umich.edu sticky_vars.Save(current_vars_file, env) 8735227Ssaidi@eecs.umich.edu 8746654Snate@binkert.org if env['USE_SSE2']: 8756654Snate@binkert.org env.Append(CCFLAGS='-msse2') 8767769SAli.Saidi@ARM.com 8777769SAli.Saidi@ARM.com # The src/SConscript file sets up the build rules in 'env' according 8787769SAli.Saidi@ARM.com # to the configured variables. It returns a list of environments, 8797769SAli.Saidi@ARM.com # one for each variant build (debug, opt, etc.) 8805227Ssaidi@eecs.umich.edu envList = SConscript('src/SConscript', variant_dir = variant_path, 8815227Ssaidi@eecs.umich.edu exports = 'env') 8825227Ssaidi@eecs.umich.edu 8835204Sstever@gmail.com # Set up the regression tests for each build. 8845204Sstever@gmail.com for e in envList: 8855204Sstever@gmail.com SConscript('tests/SConscript', 8865204Sstever@gmail.com variant_dir = joinpath(variant_path, 'tests', e.Label), 8875204Sstever@gmail.com exports = { 'env' : e }, duplicate = False) 8885204Sstever@gmail.com 8895204Sstever@gmail.comHelp(help_text) 8905204Sstever@gmail.com