SConstruct revision 6994:c6951099a1cb
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 112955SN/Aimport SCons.Node 1135396Ssaidi@eecs.umich.edu 1145863Snate@binkert.orgextra_python_paths = [ 1155863Snate@binkert.org Dir('src/python').srcnode().abspath, # M5 includes 1164202Sbinkertn@umich.edu Dir('ext/ply').srcnode().abspath, # ply is used by several files 1175863Snate@binkert.org ] 1185863Snate@binkert.org 1195863Snate@binkert.orgsys.path[1:1] = extra_python_paths 1205863Snate@binkert.org 121955SN/Afrom m5.util import compareVersions, readCommand 1226654Snate@binkert.org 1235273Sstever@gmail.com######################################################################## 1245871Snate@binkert.org# 1255273Sstever@gmail.com# Set up the main build environment. 1266655Snate@binkert.org# 1278878Ssteve.reinhardt@amd.com######################################################################## 1286655Snate@binkert.orguse_vars = set([ 'AS', 'AR', 'CC', 'CXX', 'HOME', 'LD_LIBRARY_PATH', 'PATH', 1296655Snate@binkert.org 'PYTHONPATH', 'RANLIB' ]) 1309219Spower.jg@gmail.com 1316655Snate@binkert.orguse_env = {} 1325871Snate@binkert.orgfor key,val in os.environ.iteritems(): 1336654Snate@binkert.org if key in use_vars or key.startswith("M5"): 1348947Sandreas.hansson@arm.com use_env[key] = val 1355396Ssaidi@eecs.umich.edu 1368120Sgblack@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 1448879Ssteve.reinhardt@amd.com######################################################################## 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. 1578120Sgblack@eecs.umich.eduPlease 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 = """ 1718879Ssteve.reinhardt@amd.comMercurial 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""" 1768879Ssteve.reinhardt@amd.com 1778879Ssteve.reinhardt@amd.commercurial_lib_not_found = """ 1788879Ssteve.reinhardt@amd.comMercurial libraries cannot be found, ignoring style hook 1799227Sandreas.hansson@arm.comIf you are actually a M5 developer, please fix this and 1809227Sandreas.hansson@arm.comrun the style hook. It is important. 1818879Ssteve.reinhardt@amd.com""" 1828879Ssteve.reinhardt@amd.com 1838879Ssteve.reinhardt@amd.comhg_info = "Unknown" 1848879Ssteve.reinhardt@amd.comif hgdir.exists(): 1858120Sgblack@eecs.umich.edu # 1) Grab repository revision if we know it. 1868947Sandreas.hansson@arm.com cmd = "hg id -n -i -t -b" 1877816Ssteve.reinhardt@amd.com try: 1885871Snate@binkert.org hg_info = readCommand(cmd, cwd=main.root.abspath).strip() 1895871Snate@binkert.org except OSError: 1906121Snate@binkert.org print mercurial_bin_not_found 1915871Snate@binkert.org 1925871Snate@binkert.org # 2) Ensure that the style hook is in place. 1939119Sandreas.hansson@arm.com try: 1949396Sandreas.hansson@arm.com ui = None 1959396Sandreas.hansson@arm.com if ARGUMENTS.get('IGNORE_STYLE') != 'True': 196955SN/A from mercurial import ui 1979416SAndreas.Sandberg@ARM.com ui = ui.ui() 1989416SAndreas.Sandberg@ARM.com except ImportError: 1999416SAndreas.Sandberg@ARM.com print mercurial_lib_not_found 2009416SAndreas.Sandberg@ARM.com 2019416SAndreas.Sandberg@ARM.com if ui is not None: 2029416SAndreas.Sandberg@ARM.com ui.readconfig(hgdir.File('hgrc').abspath) 2039416SAndreas.Sandberg@ARM.com style_hook = ui.config('hooks', 'pretxncommit.style', None) 2045871Snate@binkert.org 2055871Snate@binkert.org if not style_hook: 2069416SAndreas.Sandberg@ARM.com print mercurial_style_message 2079416SAndreas.Sandberg@ARM.com sys.exit(1) 2085871Snate@binkert.orgelse: 209955SN/A print ".hg directory not found" 2106121Snate@binkert.org 2118881Smarc.orr@gmail.commain['HG_INFO'] = hg_info 2126121Snate@binkert.org 2136121Snate@binkert.org################################################### 2141533SN/A# 2159239Sandreas.hansson@arm.com# Figure out which configurations to set up based on the path(s) of 2169239Sandreas.hansson@arm.com# the target(s). 2179239Sandreas.hansson@arm.com# 2189239Sandreas.hansson@arm.com################################################### 2199239Sandreas.hansson@arm.com 2209239Sandreas.hansson@arm.com# Find default configuration & binary. 2219239Sandreas.hansson@arm.comDefault(environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 2229239Sandreas.hansson@arm.com 2239239Sandreas.hansson@arm.com# helper function: find last occurrence of element in list 2249239Sandreas.hansson@arm.comdef rfind(l, elt, offs = -1): 2259239Sandreas.hansson@arm.com for i in range(len(l)+offs, 0, -1): 2269239Sandreas.hansson@arm.com if l[i] == elt: 2276655Snate@binkert.org return i 2286655Snate@binkert.org raise ValueError, "element not found" 2296655Snate@binkert.org 2306655Snate@binkert.org# Each target must have 'build' in the interior of the path; the 2315871Snate@binkert.org# directory below this will determine the build parameters. For 2325871Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2335863Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 2345871Snate@binkert.org# follow 'build' in the bulid path. 2358878Ssteve.reinhardt@amd.com 2365871Snate@binkert.org# Generate absolute paths to targets so we can see where the build dir is 2375871Snate@binkert.orgif COMMAND_LINE_TARGETS: 2385871Snate@binkert.org # Ask SCons which directory it was invoked from 2395863Snate@binkert.org launch_dir = GetLaunchDir() 2406121Snate@binkert.org # Make targets relative to invocation directory 2415863Snate@binkert.org abs_targets = [ normpath(joinpath(launch_dir, str(x))) for x in \ 2425871Snate@binkert.org COMMAND_LINE_TARGETS] 2438336Ssteve.reinhardt@amd.comelse: 2448336Ssteve.reinhardt@amd.com # Default targets are relative to root of tree 2458336Ssteve.reinhardt@amd.com abs_targets = [ normpath(joinpath(main.root.abspath, str(x))) for x in \ 2468336Ssteve.reinhardt@amd.com DEFAULT_TARGETS] 2474678Snate@binkert.org 2488336Ssteve.reinhardt@amd.com 2498336Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the 2508336Ssteve.reinhardt@amd.com# collected targets reference. 2514678Snate@binkert.orgvariant_paths = [] 2524678Snate@binkert.orgbuild_root = None 2534678Snate@binkert.orgfor t in abs_targets: 2544678Snate@binkert.org path_dirs = t.split('/') 2557827Snate@binkert.org try: 2567827Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 2578336Ssteve.reinhardt@amd.com except: 2584678Snate@binkert.org 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]) 2618336Ssteve.reinhardt@amd.com 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: 2655871Snate@binkert.org print "Error: build targets not under same build root\n"\ 2665871Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 2678336Ssteve.reinhardt@amd.com Exit(1) 2688336Ssteve.reinhardt@amd.com variant_path = joinpath('/',*path_dirs[:build_top+2]) 2698336Ssteve.reinhardt@amd.com if variant_path not in variant_paths: 2708336Ssteve.reinhardt@amd.com variant_paths.append(variant_path) 2718336Ssteve.reinhardt@amd.com 2725871Snate@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 2784678Snate@binkert.orgmain.SConsignFile(joinpath(build_root, "sconsign")) 2795871Snate@binkert.org 2804678Snate@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 2868336Ssteve.reinhardt@amd.com# 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 2928336Ssteve.reinhardt@amd.comdef PathListMakeAbsolute(val): 2938336Ssteve.reinhardt@amd.com if not val: 2948336Ssteve.reinhardt@amd.com 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 2985871Snate@binkert.orgdef PathListAllExist(key, val, env): 2996121Snate@binkert.org if not val: 300955SN/A return 301955SN/A paths = val.split(':') 3022632Sstever@eecs.umich.edu for path in paths: 3032632Sstever@eecs.umich.edu if not isdir(path): 304955SN/A raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 305955SN/A 306955SN/Aglobal_sticky_vars_file = joinpath(build_root, 'variables.global') 307955SN/A 3088878Ssteve.reinhardt@amd.comglobal_sticky_vars = Variables(global_sticky_vars_file, args=ARGUMENTS) 309955SN/A 3102632Sstever@eecs.umich.eduglobal_sticky_vars.AddVariables( 3112632Sstever@eecs.umich.edu ('CC', 'C compiler', environ.get('CC', main['CC'])), 3122632Sstever@eecs.umich.edu ('CXX', 'C++ compiler', environ.get('CXX', main['CXX'])), 3132632Sstever@eecs.umich.edu ('BATCH', 'Use batch pool for build and tests', False), 3142632Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3152632Sstever@eecs.umich.edu ('EXTRAS', 'Add Extra directories to the compilation', '', 3162632Sstever@eecs.umich.edu PathListAllExist, PathListMakeAbsolute), 3178268Ssteve.reinhardt@amd.com BoolVariable('RUBY', 'Build with Ruby', False), 3188268Ssteve.reinhardt@amd.com ) 3198268Ssteve.reinhardt@amd.com 3208268Ssteve.reinhardt@amd.com# base help text 3218268Ssteve.reinhardt@amd.comhelp_text = ''' 3228268Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)] 3238268Ssteve.reinhardt@amd.com 3242632Sstever@eecs.umich.eduGlobal sticky options: 3252632Sstever@eecs.umich.edu''' 3262632Sstever@eecs.umich.edu 3272632Sstever@eecs.umich.edu# Update main environment with values from ARGUMENTS & global_sticky_vars_file 3288268Ssteve.reinhardt@amd.comglobal_sticky_vars.Update(main) 3292632Sstever@eecs.umich.edu 3308268Ssteve.reinhardt@amd.comhelp_text += global_sticky_vars.GenerateHelpText(main) 3318268Ssteve.reinhardt@amd.com 3328268Ssteve.reinhardt@amd.com# Save sticky variable settings back to current variables file 3338268Ssteve.reinhardt@amd.comglobal_sticky_vars.Save(global_sticky_vars_file, main) 3343718Sstever@eecs.umich.edu 3352634Sstever@eecs.umich.edu# Parse EXTRAS variable to build list of all directories where we're 3362634Sstever@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3375863Snate@binkert.orgbase_dir = main.srcdir.abspath 3382638Sstever@eecs.umich.eduif main['EXTRAS']: 3398268Ssteve.reinhardt@amd.com extras_dir_list = main['EXTRAS'].split(':') 3402632Sstever@eecs.umich.eduelse: 3412632Sstever@eecs.umich.edu extras_dir_list = [] 3422632Sstever@eecs.umich.edu 3432632Sstever@eecs.umich.eduExport('base_dir') 3442632Sstever@eecs.umich.eduExport('extras_dir_list') 3451858SN/A 3463716Sstever@eecs.umich.edu# the ext directory should be on the #includes path 3472638Sstever@eecs.umich.edumain.Append(CPPPATH=[Dir('ext')]) 3482638Sstever@eecs.umich.edu 3492638Sstever@eecs.umich.eduCXX_version = readCommand([main['CXX'],'--version'], exception=False) 3502638Sstever@eecs.umich.eduCXX_V = readCommand([main['CXX'],'-V'], exception=False) 3512638Sstever@eecs.umich.edu 3522638Sstever@eecs.umich.edumain['GCC'] = CXX_version and CXX_version.find('g++') >= 0 3532638Sstever@eecs.umich.edumain['SUNCC'] = CXX_V and CXX_V.find('Sun C++') >= 0 3545863Snate@binkert.orgmain['ICC'] = CXX_V and CXX_V.find('Intel') >= 0 3555863Snate@binkert.orgif main['GCC'] + main['SUNCC'] + main['ICC'] > 1: 3565863Snate@binkert.org print 'Error: How can we have two at the same time?' 357955SN/A Exit(1) 3585341Sstever@gmail.com 3595341Sstever@gmail.com# Set up default C++ compiler flags 3605863Snate@binkert.orgif main['GCC']: 3617756SAli.Saidi@ARM.com main.Append(CCFLAGS='-pipe') 3625341Sstever@gmail.com main.Append(CCFLAGS='-fno-strict-aliasing') 3636121Snate@binkert.org main.Append(CCFLAGS=['-Wall', '-Wno-sign-compare', '-Wundef']) 3644494Ssaidi@eecs.umich.edu main.Append(CXXFLAGS='-Wno-deprecated') 3656121Snate@binkert.orgelif main['ICC']: 3661105SN/A pass #Fix me... add warning flags once we clean up icc warnings 3672667Sstever@eecs.umich.eduelif main['SUNCC']: 3682667Sstever@eecs.umich.edu main.Append(CCFLAGS='-Qoption ccfe') 3692667Sstever@eecs.umich.edu main.Append(CCFLAGS='-features=gcc') 3702667Sstever@eecs.umich.edu main.Append(CCFLAGS='-features=extensions') 3716121Snate@binkert.org main.Append(CCFLAGS='-library=stlport4') 3722667Sstever@eecs.umich.edu main.Append(CCFLAGS='-xar') 3735341Sstever@gmail.com #main.Append(CCFLAGS='-instances=semiexplicit') 3745863Snate@binkert.orgelse: 3755341Sstever@gmail.com print 'Error: Don\'t know what compiler options to use for your compiler.' 3765341Sstever@gmail.com print ' Please fix SConstruct and src/SConscript and try again.' 3775341Sstever@gmail.com Exit(1) 3788120Sgblack@eecs.umich.edu 3795341Sstever@gmail.com# Set up common yacc/bison flags (needed for Ruby) 3808120Sgblack@eecs.umich.edumain['YACCFLAGS'] = '-d' 3815341Sstever@gmail.commain['YACCHXXFILESUFFIX'] = '.hh' 3828120Sgblack@eecs.umich.edu 3836121Snate@binkert.org# Do this after we save setting back, or else we'll tack on an 3846121Snate@binkert.org# extra 'qdo' every time we run scons. 3858980Ssteve.reinhardt@amd.comif main['BATCH']: 3869396Sandreas.hansson@arm.com main['CC'] = main['BATCH_CMD'] + ' ' + main['CC'] 3875397Ssaidi@eecs.umich.edu main['CXX'] = main['BATCH_CMD'] + ' ' + main['CXX'] 3885397Ssaidi@eecs.umich.edu main['AS'] = main['BATCH_CMD'] + ' ' + main['AS'] 3897727SAli.Saidi@ARM.com main['AR'] = main['BATCH_CMD'] + ' ' + main['AR'] 3908268Ssteve.reinhardt@amd.com main['RANLIB'] = main['BATCH_CMD'] + ' ' + main['RANLIB'] 3916168Snate@binkert.org 3925341Sstever@gmail.comif sys.platform == 'cygwin': 3938120Sgblack@eecs.umich.edu # cygwin has some header file issues... 3948120Sgblack@eecs.umich.edu main.Append(CCFLAGS="-Wno-uninitialized") 3958120Sgblack@eecs.umich.edu 3966814Sgblack@eecs.umich.edu# Check for SWIG 3975863Snate@binkert.orgif not main.has_key('SWIG'): 3988120Sgblack@eecs.umich.edu print 'Error: SWIG utility not found.' 3995341Sstever@gmail.com print ' Please install (see http://www.swig.org) and retry.' 4005863Snate@binkert.org Exit(1) 4018268Ssteve.reinhardt@amd.com 4026121Snate@binkert.org# Check for appropriate SWIG version 4036121Snate@binkert.orgswig_version = readCommand(('swig', '-version'), exception='').split() 4048268Ssteve.reinhardt@amd.com# First 3 words should be "SWIG Version x.y.z" 4055742Snate@binkert.orgif len(swig_version) < 3 or \ 4065742Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 4075341Sstever@gmail.com print 'Error determining SWIG version.' 4085742Snate@binkert.org Exit(1) 4095742Snate@binkert.org 4105341Sstever@gmail.commin_swig_version = '1.3.28' 4116017Snate@binkert.orgif compareVersions(swig_version[2], min_swig_version) < 0: 4126121Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 4136017Snate@binkert.org print ' Installed version:', swig_version[2] 4147816Ssteve.reinhardt@amd.com Exit(1) 4157756SAli.Saidi@ARM.com 4167756SAli.Saidi@ARM.com# Set up SWIG flags & scanner 4177756SAli.Saidi@ARM.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4187756SAli.Saidi@ARM.commain.Append(SWIGFLAGS=swig_flags) 4197756SAli.Saidi@ARM.com 4207756SAli.Saidi@ARM.com# filter out all existing swig scanners, they mess up the dependency 4217756SAli.Saidi@ARM.com# stuff for some reason 4227756SAli.Saidi@ARM.comscanners = [] 4237816Ssteve.reinhardt@amd.comfor scanner in main['SCANNERS']: 4247816Ssteve.reinhardt@amd.com skeys = scanner.skeys 4257816Ssteve.reinhardt@amd.com if skeys == '.i': 4267816Ssteve.reinhardt@amd.com continue 4277816Ssteve.reinhardt@amd.com 4287816Ssteve.reinhardt@amd.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4297816Ssteve.reinhardt@amd.com continue 4307816Ssteve.reinhardt@amd.com 4317816Ssteve.reinhardt@amd.com scanners.append(scanner) 4327816Ssteve.reinhardt@amd.com 4337756SAli.Saidi@ARM.com# add the new swig scanner that we like better 4347816Ssteve.reinhardt@amd.comfrom SCons.Scanner import ClassicCPP as CPPScanner 4357816Ssteve.reinhardt@amd.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4367816Ssteve.reinhardt@amd.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4377816Ssteve.reinhardt@amd.com 4387816Ssteve.reinhardt@amd.com# replace the scanners list that has what we want 4397816Ssteve.reinhardt@amd.commain['SCANNERS'] = scanners 4407816Ssteve.reinhardt@amd.com 4417816Ssteve.reinhardt@amd.com# Add a custom Check function to the Configure context so that we can 4427816Ssteve.reinhardt@amd.com# figure out if the compiler adds leading underscores to global 4437816Ssteve.reinhardt@amd.com# variables. This is needed for the autogenerated asm files that we 4447816Ssteve.reinhardt@amd.com# use for embedding the python code. 4457816Ssteve.reinhardt@amd.comdef CheckLeading(context): 4467816Ssteve.reinhardt@amd.com context.Message("Checking for leading underscore in global variables...") 4477816Ssteve.reinhardt@amd.com # 1) Define a global variable called x from asm so the C compiler 4487816Ssteve.reinhardt@amd.com # won't change the symbol at all. 4497816Ssteve.reinhardt@amd.com # 2) Declare that variable. 4507816Ssteve.reinhardt@amd.com # 3) Use the variable 4517816Ssteve.reinhardt@amd.com # 4527816Ssteve.reinhardt@amd.com # If the compiler prepends an underscore, this will successfully 4537816Ssteve.reinhardt@amd.com # link because the external symbol 'x' will be called '_x' which 4547816Ssteve.reinhardt@amd.com # was defined by the asm statement. If the compiler does not 4557816Ssteve.reinhardt@amd.com # prepend an underscore, this will not successfully link because 4567816Ssteve.reinhardt@amd.com # '_x' will have been defined by assembly, while the C portion of 4577816Ssteve.reinhardt@amd.com # the code will be trying to use 'x' 4587816Ssteve.reinhardt@amd.com ret = context.TryLink(''' 4597816Ssteve.reinhardt@amd.com asm(".globl _x; _x: .byte 0"); 4607816Ssteve.reinhardt@amd.com extern int x; 4617816Ssteve.reinhardt@amd.com int main() { return x; } 4627816Ssteve.reinhardt@amd.com ''', extension=".c") 4637816Ssteve.reinhardt@amd.com context.env.Append(LEADING_UNDERSCORE=ret) 4647816Ssteve.reinhardt@amd.com context.Result(ret) 4657816Ssteve.reinhardt@amd.com return ret 4667816Ssteve.reinhardt@amd.com 4677816Ssteve.reinhardt@amd.com# Platform-specific configuration. Note again that we assume that all 4687816Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform. 4697816Ssteve.reinhardt@amd.comconf = Configure(main, 4707816Ssteve.reinhardt@amd.com conf_dir = joinpath(build_root, '.scons_config'), 4717816Ssteve.reinhardt@amd.com log_file = joinpath(build_root, 'scons_config.log'), 4727816Ssteve.reinhardt@amd.com custom_tests = { 'CheckLeading' : CheckLeading }) 4737816Ssteve.reinhardt@amd.com 4747816Ssteve.reinhardt@amd.com# Check for leading underscores. Don't really need to worry either 4757816Ssteve.reinhardt@amd.com# way so don't need to check the return code. 4767816Ssteve.reinhardt@amd.comconf.CheckLeading() 4777816Ssteve.reinhardt@amd.com 4787816Ssteve.reinhardt@amd.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 4797816Ssteve.reinhardt@amd.comtry: 4807816Ssteve.reinhardt@amd.com import platform 4817816Ssteve.reinhardt@amd.com uname = platform.uname() 4827816Ssteve.reinhardt@amd.com if uname[0] == 'Darwin' and compareVersions(uname[2], '9.0.0') >= 0: 4837816Ssteve.reinhardt@amd.com if int(readCommand('sysctl -n hw.cpu64bit_capable')[0]): 4847816Ssteve.reinhardt@amd.com main.Append(CCFLAGS='-arch x86_64') 4857816Ssteve.reinhardt@amd.com main.Append(CFLAGS='-arch x86_64') 4867816Ssteve.reinhardt@amd.com main.Append(LINKFLAGS='-arch x86_64') 4877816Ssteve.reinhardt@amd.com main.Append(ASFLAGS='-arch x86_64') 4887816Ssteve.reinhardt@amd.comexcept: 4897816Ssteve.reinhardt@amd.com pass 4907816Ssteve.reinhardt@amd.com 4917816Ssteve.reinhardt@amd.com# Recent versions of scons substitute a "Null" object for Configure() 4927816Ssteve.reinhardt@amd.com# when configuration isn't necessary, e.g., if the "--help" option is 4937816Ssteve.reinhardt@amd.com# present. Unfortuantely this Null object always returns false, 4947816Ssteve.reinhardt@amd.com# breaking all our configuration checks. We replace it with our own 4958947Sandreas.hansson@arm.com# more optimistic null object that returns True instead. 4968947Sandreas.hansson@arm.comif not conf: 4977756SAli.Saidi@ARM.com def NullCheck(*args, **kwargs): 4988120Sgblack@eecs.umich.edu return True 4997756SAli.Saidi@ARM.com 5007756SAli.Saidi@ARM.com class NullConf: 5017756SAli.Saidi@ARM.com def __init__(self, env): 5027756SAli.Saidi@ARM.com self.env = env 5037816Ssteve.reinhardt@amd.com def Finish(self): 5047816Ssteve.reinhardt@amd.com return self.env 5057816Ssteve.reinhardt@amd.com def __getattr__(self, mname): 5067816Ssteve.reinhardt@amd.com return NullCheck 5077816Ssteve.reinhardt@amd.com 5087816Ssteve.reinhardt@amd.com conf = NullConf(main) 5097816Ssteve.reinhardt@amd.com 5107816Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the 5117816Ssteve.reinhardt@amd.com# interpreter. For consistency, we will use the same Python 5127816Ssteve.reinhardt@amd.com# installation used to run scons (and thus this script). If you want 5137756SAli.Saidi@ARM.com# to link in an alternate version, see above for instructions on how 5147756SAli.Saidi@ARM.com# to invoke scons with a different copy of the Python interpreter. 5159227Sandreas.hansson@arm.comfrom distutils import sysconfig 5169227Sandreas.hansson@arm.com 5179227Sandreas.hansson@arm.compy_getvar = sysconfig.get_config_var 5189227Sandreas.hansson@arm.com 5199590Sandreas@sandberg.pp.sepy_version = 'python' + py_getvar('VERSION') 5209590Sandreas@sandberg.pp.se 5219590Sandreas@sandberg.pp.sepy_general_include = sysconfig.get_python_inc() 5229590Sandreas@sandberg.pp.sepy_platform_include = sysconfig.get_python_inc(plat_specific=True) 5239590Sandreas@sandberg.pp.sepy_includes = [ py_general_include ] 5249590Sandreas@sandberg.pp.seif py_platform_include != py_general_include: 5256654Snate@binkert.org py_includes.append(py_platform_include) 5266654Snate@binkert.org 5275871Snate@binkert.orgpy_lib_path = [ py_getvar('LIBDIR') ] 5286121Snate@binkert.org# add the prefix/lib/pythonX.Y/config dir, but only if there is no 5298946Sandreas.hansson@arm.com# shared library in prefix/lib/. 5309419Sandreas.hansson@arm.comif not py_getvar('Py_ENABLE_SHARED'): 5313940Ssaidi@eecs.umich.edu py_lib_path.append(py_getvar('LIBPL')) 5323918Ssaidi@eecs.umich.edu 5333918Ssaidi@eecs.umich.edupy_libs = [] 5341858SN/Afor lib in py_getvar('LIBS').split() + py_getvar('SYSLIBS').split(): 5359556Sandreas.hansson@arm.com assert lib.startswith('-l') 5369556Sandreas.hansson@arm.com lib = lib[2:] 5379556Sandreas.hansson@arm.com if lib not in py_libs: 5389556Sandreas.hansson@arm.com py_libs.append(lib) 5399556Sandreas.hansson@arm.compy_libs.append(py_version) 5409556Sandreas.hansson@arm.com 5419556Sandreas.hansson@arm.commain.Append(CPPPATH=py_includes) 5429556Sandreas.hansson@arm.commain.Append(LIBPATH=py_lib_path) 5439556Sandreas.hansson@arm.com 5449556Sandreas.hansson@arm.com# verify that this stuff works 5459556Sandreas.hansson@arm.comif not conf.CheckHeader('Python.h', '<>'): 5469556Sandreas.hansson@arm.com print "Error: can't find Python.h header in", py_includes 5479556Sandreas.hansson@arm.com Exit(1) 5489556Sandreas.hansson@arm.com 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) 5676121Snate@binkert.org 5689420Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control) 5699420Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 5709420Sandreas.hansson@arm.comif not have_fenv: 5719420Sandreas.hansson@arm.com print "Warning: Header file <fenv.h> not found." 5729420Sandreas.hansson@arm.com print " This host has no IEEE FP rounding mode control." 5739420Sandreas.hansson@arm.com 5749420Sandreas.hansson@arm.com###################################################################### 5759420Sandreas.hansson@arm.com# 5769420Sandreas.hansson@arm.com# Check for mysql. 5779420Sandreas.hansson@arm.com# 5789420Sandreas.hansson@arm.commysql_config = WhereIs('mysql_config') 5797618SAli.Saidi@arm.comhave_mysql = bool(mysql_config) 5807618SAli.Saidi@arm.com 5817618SAli.Saidi@arm.com# Check MySQL version. 5827739Sgblack@eecs.umich.eduif have_mysql: 5839227Sandreas.hansson@arm.com mysql_version = readCommand(mysql_config + ' --version') 5849227Sandreas.hansson@arm.com min_mysql_version = '4.1' 5859227Sandreas.hansson@arm.com if compareVersions(mysql_version, min_mysql_version) < 0: 5869227Sandreas.hansson@arm.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 5879227Sandreas.hansson@arm.com print ' Version', mysql_version, 'detected.' 5889227Sandreas.hansson@arm.com have_mysql = False 5899227Sandreas.hansson@arm.com 5909227Sandreas.hansson@arm.com# Set up mysql_config commands. 5919227Sandreas.hansson@arm.comif have_mysql: 5929227Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --include' 5939227Sandreas.hansson@arm.com if os.system(mysql_config_include + ' > /dev/null') != 0: 5949227Sandreas.hansson@arm.com # older mysql_config versions don't support --include, use 5959227Sandreas.hansson@arm.com # --cflags instead 5969227Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 5979227Sandreas.hansson@arm.com # This seems to work in all versions 5989227Sandreas.hansson@arm.com mysql_config_libs = mysql_config + ' --libs' 5999227Sandreas.hansson@arm.com 6009227Sandreas.hansson@arm.com###################################################################### 6019590Sandreas@sandberg.pp.se# 6029590Sandreas@sandberg.pp.se# Finish the configuration 6039590Sandreas@sandberg.pp.se# 6048737Skoansin.tan@gmail.commain = conf.Finish() 6059420Sandreas.hansson@arm.com 6069420Sandreas.hansson@arm.com###################################################################### 6079420Sandreas.hansson@arm.com# 6088737Skoansin.tan@gmail.com# Collect all non-global variables 6098737Skoansin.tan@gmail.com# 6108737Skoansin.tan@gmail.com 6118737Skoansin.tan@gmail.com# Define the universe of supported ISAs 6128737Skoansin.tan@gmail.comall_isa_list = [ ] 6138737Skoansin.tan@gmail.comExport('all_isa_list') 6148737Skoansin.tan@gmail.com 6158737Skoansin.tan@gmail.comclass CpuModel(object): 6168737Skoansin.tan@gmail.com '''The CpuModel class encapsulates everything the ISA parser needs to 6178737Skoansin.tan@gmail.com know about a particular CPU model.''' 6188737Skoansin.tan@gmail.com 6198737Skoansin.tan@gmail.com # Dict of available CPU model objects. Accessible as CpuModel.dict. 6209556Sandreas.hansson@arm.com dict = {} 6219556Sandreas.hansson@arm.com list = [] 6229556Sandreas.hansson@arm.com defaults = [] 6239556Sandreas.hansson@arm.com 6249556Sandreas.hansson@arm.com # Constructor. Automatically adds models to CpuModel.dict. 6259556Sandreas.hansson@arm.com def __init__(self, name, filename, includes, strings, default=False): 6269556Sandreas.hansson@arm.com self.name = name # name of model 6279556Sandreas.hansson@arm.com self.filename = filename # filename for output exec code 6289556Sandreas.hansson@arm.com self.includes = includes # include files needed in exec file 6299556Sandreas.hansson@arm.com # The 'strings' dict holds all the per-CPU symbols we can 6309590Sandreas@sandberg.pp.se # substitute into templates etc. 6319590Sandreas@sandberg.pp.se self.strings = strings 6329420Sandreas.hansson@arm.com 6339846Sandreas.hansson@arm.com # This cpu is enabled by default 6349846Sandreas.hansson@arm.com self.default = default 6359846Sandreas.hansson@arm.com 6369846Sandreas.hansson@arm.com # Add self to dict 6378946Sandreas.hansson@arm.com if name in CpuModel.dict: 6383918Ssaidi@eecs.umich.edu raise AttributeError, "CpuModel '%s' already registered" % name 6399068SAli.Saidi@ARM.com CpuModel.dict[name] = self 6409068SAli.Saidi@ARM.com CpuModel.list.append(name) 6419068SAli.Saidi@ARM.com 6429068SAli.Saidi@ARM.comExport('CpuModel') 6439068SAli.Saidi@ARM.com 6449068SAli.Saidi@ARM.com# Sticky variables get saved in the variables file so they persist from 6459068SAli.Saidi@ARM.com# one invocation to the next (unless overridden, in which case the new 6469068SAli.Saidi@ARM.com# value becomes sticky). 6479068SAli.Saidi@ARM.comsticky_vars = Variables(args=ARGUMENTS) 6489419Sandreas.hansson@arm.comExport('sticky_vars') 6499068SAli.Saidi@ARM.com 6509068SAli.Saidi@ARM.com# Sticky variables that should be exported 6519068SAli.Saidi@ARM.comexport_vars = [] 6529068SAli.Saidi@ARM.comExport('export_vars') 6539068SAli.Saidi@ARM.com 6549068SAli.Saidi@ARM.com# Non-sticky variables only apply to the current build. 6553918Ssaidi@eecs.umich.edunonsticky_vars = Variables(args=ARGUMENTS) 6563918Ssaidi@eecs.umich.eduExport('nonsticky_vars') 6576157Snate@binkert.org 6586157Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 6596157Snate@binkert.org# above variables 6606157Snate@binkert.orgfor bdir in [ base_dir ] + extras_dir_list: 6615397Ssaidi@eecs.umich.edu for root, dirs, files in os.walk(bdir): 6625397Ssaidi@eecs.umich.edu if 'SConsopts' in files: 6636121Snate@binkert.org print "Reading", joinpath(root, 'SConsopts') 6646121Snate@binkert.org SConscript(joinpath(root, 'SConsopts')) 6656121Snate@binkert.org 6666121Snate@binkert.orgall_isa_list.sort() 6676121Snate@binkert.org 6686121Snate@binkert.orgsticky_vars.AddVariables( 6695397Ssaidi@eecs.umich.edu EnumVariable('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 6701851SN/A BoolVariable('FULL_SYSTEM', 'Full-system support', False), 6711851SN/A ListVariable('CPU_MODELS', 'CPU models', 6727739Sgblack@eecs.umich.edu sorted(n for n,m in CpuModel.dict.iteritems() if m.default), 673955SN/A sorted(CpuModel.list)), 6749396Sandreas.hansson@arm.com BoolVariable('NO_FAST_ALLOC', 'Disable fast object allocator', False), 6759396Sandreas.hansson@arm.com BoolVariable('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 6769396Sandreas.hansson@arm.com False), 6779396Sandreas.hansson@arm.com BoolVariable('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 6789396Sandreas.hansson@arm.com False), 6799396Sandreas.hansson@arm.com BoolVariable('EFENCE', 'Link with Electric Fence malloc debugger', 6809396Sandreas.hansson@arm.com False), 6819396Sandreas.hansson@arm.com BoolVariable('SS_COMPATIBLE_FP', 6829396Sandreas.hansson@arm.com 'Make floating-point results compatible with SimpleScalar', 6839396Sandreas.hansson@arm.com False), 6849396Sandreas.hansson@arm.com BoolVariable('USE_SSE2', 6859396Sandreas.hansson@arm.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 6869396Sandreas.hansson@arm.com False), 6879396Sandreas.hansson@arm.com BoolVariable('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6889396Sandreas.hansson@arm.com BoolVariable('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6899396Sandreas.hansson@arm.com BoolVariable('USE_CHECKER', 'Use checker for detailed CPU models', False), 6909477Sandreas.hansson@arm.com BoolVariable('CP_ANNOTATE', 'Enable critical path annotation capability', False), 6919477Sandreas.hansson@arm.com ) 6929477Sandreas.hansson@arm.com 6939477Sandreas.hansson@arm.comnonsticky_vars.AddVariables( 6949477Sandreas.hansson@arm.com BoolVariable('update_ref', 'Update test reference outputs', False) 6959477Sandreas.hansson@arm.com ) 6969477Sandreas.hansson@arm.com 6979477Sandreas.hansson@arm.com# These variables get exported to #defines in config/*.hh (see src/SConscript). 6989477Sandreas.hansson@arm.comexport_vars += ['FULL_SYSTEM', 'USE_FENV', 'USE_MYSQL', 6999477Sandreas.hansson@arm.com 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', 'FAST_ALLOC_STATS', 7009477Sandreas.hansson@arm.com 'SS_COMPATIBLE_FP', 'USE_CHECKER', 'TARGET_ISA', 'CP_ANNOTATE'] 7019477Sandreas.hansson@arm.com 7029477Sandreas.hansson@arm.com################################################### 7039477Sandreas.hansson@arm.com# 7049477Sandreas.hansson@arm.com# Define a SCons builder for configuration flag headers. 7059477Sandreas.hansson@arm.com# 7069477Sandreas.hansson@arm.com################################################### 7079477Sandreas.hansson@arm.com 7089477Sandreas.hansson@arm.com# This function generates a config header file that #defines the 7099477Sandreas.hansson@arm.com# variable symbol to the current variable setting (0 or 1). The source 7109477Sandreas.hansson@arm.com# operands are the name of the variable and a Value node containing the 7119477Sandreas.hansson@arm.com# value of the variable. 7129396Sandreas.hansson@arm.comdef build_config_file(target, source, env): 7133053Sstever@eecs.umich.edu (variable, value) = [s.get_contents() for s in source] 7146121Snate@binkert.org f = file(str(target[0]), 'w') 7153053Sstever@eecs.umich.edu print >> f, '#define', variable, value 7163053Sstever@eecs.umich.edu f.close() 7173053Sstever@eecs.umich.edu return None 7183053Sstever@eecs.umich.edu 7193053Sstever@eecs.umich.edu# Generate the message to be printed when building the config file. 7209072Sandreas.hansson@arm.comdef build_config_file_string(target, source, env): 7213053Sstever@eecs.umich.edu (variable, value) = [s.get_contents() for s in source] 7224742Sstever@eecs.umich.edu return "Defining %s as %s in %s." % (variable, value, target[0]) 7234742Sstever@eecs.umich.edu 7243053Sstever@eecs.umich.edu# Combine the two functions into a scons Action object. 7253053Sstever@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string) 7263053Sstever@eecs.umich.edu 7278960Ssteve.reinhardt@amd.com# The emitter munges the source & target node lists to reflect what 7286654Snate@binkert.org# we're really doing. 7293053Sstever@eecs.umich.edudef config_emitter(target, source, env): 7303053Sstever@eecs.umich.edu # extract variable name from Builder arg 7313053Sstever@eecs.umich.edu variable = str(target[0]) 7323053Sstever@eecs.umich.edu # True target is config header file 7339740SAli.Saidi@ARM.com target = joinpath('config', variable.lower() + '.hh') 7349585Sandreas@sandberg.pp.se val = env[variable] 7359740SAli.Saidi@ARM.com if isinstance(val, bool): 7369585Sandreas@sandberg.pp.se # Force value to 0/1 7379585Sandreas@sandberg.pp.se val = int(val) 7389585Sandreas@sandberg.pp.se elif isinstance(val, str): 7399585Sandreas@sandberg.pp.se val = '"' + val + '"' 7409585Sandreas@sandberg.pp.se 7419585Sandreas@sandberg.pp.se # Sources are variable name & value (packaged in SCons Value nodes) 7422667Sstever@eecs.umich.edu return ([target], [Value(variable), Value(val)]) 7434554Sbinkertn@umich.edu 7446121Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 7452667Sstever@eecs.umich.edu 7464554Sbinkertn@umich.edumain.Append(BUILDERS = { 'ConfigFile' : config_builder }) 7474554Sbinkertn@umich.edu 7484554Sbinkertn@umich.edu# libelf build is shared across all configs in the build root. 7496121Snate@binkert.orgmain.SConscript('ext/libelf/SConscript', 7504554Sbinkertn@umich.edu variant_dir = joinpath(build_root, 'libelf')) 7514554Sbinkertn@umich.edu 7524554Sbinkertn@umich.edu# gzstream build is shared across all configs in the build root. 7534781Snate@binkert.orgmain.SConscript('ext/gzstream/SConscript', 7544554Sbinkertn@umich.edu variant_dir = joinpath(build_root, 'gzstream')) 7554554Sbinkertn@umich.edu 7562667Sstever@eecs.umich.edu################################################### 7574554Sbinkertn@umich.edu# 7584554Sbinkertn@umich.edu# This function is used to set up a directory with switching headers 7594554Sbinkertn@umich.edu# 7604554Sbinkertn@umich.edu################################################### 7612667Sstever@eecs.umich.edu 7624554Sbinkertn@umich.edumain['ALL_ISA_LIST'] = all_isa_list 7632667Sstever@eecs.umich.edudef make_switching_dir(dname, switch_headers, env): 7644554Sbinkertn@umich.edu # Generate the header. target[0] is the full path of the output 7656121Snate@binkert.org # header to generate. 'source' is a dummy variable, since we get the 7662667Sstever@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 7675522Snate@binkert.org def gen_switch_hdr(target, source, env): 7685522Snate@binkert.org fname = str(target[0]) 7695522Snate@binkert.org f = open(fname, 'w') 7705522Snate@binkert.org isa = env['TARGET_ISA'].lower() 7715522Snate@binkert.org print >>f, '#include "%s/%s/%s"' % (dname, isa, basename(fname)) 7725522Snate@binkert.org f.close() 7735522Snate@binkert.org 7745522Snate@binkert.org # String to print when generating header 7755522Snate@binkert.org def gen_switch_hdr_string(target, source, env): 7765522Snate@binkert.org return "Generating switch header " + str(target[0]) 7775522Snate@binkert.org 7785522Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 7795522Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 7805522Snate@binkert.org # should get re-executed. 7815522Snate@binkert.org switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 7825522Snate@binkert.org varlist=['ALL_ISA_LIST']) 7835522Snate@binkert.org 7845522Snate@binkert.org # Instantiate actions for each header 7855522Snate@binkert.org for hdr in switch_headers: 7865522Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 7875522Snate@binkert.orgExport('make_switching_dir') 7885522Snate@binkert.org 7895522Snate@binkert.org################################################### 7905522Snate@binkert.org# 7915522Snate@binkert.org# Define build environments for selected configurations. 7925522Snate@binkert.org# 7932638Sstever@eecs.umich.edu################################################### 7942638Sstever@eecs.umich.edu 7956121Snate@binkert.orgfor variant_path in variant_paths: 7963716Sstever@eecs.umich.edu print "Building in", variant_path 7975522Snate@binkert.org 7989420Sandreas.hansson@arm.com # Make a copy of the build-root environment to use for this config. 7995522Snate@binkert.org env = main.Clone() 8005522Snate@binkert.org env['BUILDDIR'] = variant_path 8015522Snate@binkert.org 8025522Snate@binkert.org # variant_dir is the tail component of build path, and is used to 8031858SN/A # determine the build parameters (e.g., 'ALPHA_SE') 8045227Ssaidi@eecs.umich.edu (build_root, variant_dir) = splitpath(variant_path) 8055227Ssaidi@eecs.umich.edu 8065227Ssaidi@eecs.umich.edu # Set env variables according to the build directory config. 8075227Ssaidi@eecs.umich.edu sticky_vars.files = [] 8086654Snate@binkert.org # Variables for $BUILD_ROOT/$VARIANT_DIR are stored in 8096654Snate@binkert.org # $BUILD_ROOT/variables/$VARIANT_DIR so you can nuke 8107769SAli.Saidi@ARM.com # $BUILD_ROOT/$VARIANT_DIR without losing your variables settings. 8117769SAli.Saidi@ARM.com current_vars_file = joinpath(build_root, 'variables', variant_dir) 8127769SAli.Saidi@ARM.com if isfile(current_vars_file): 8137769SAli.Saidi@ARM.com sticky_vars.files.append(current_vars_file) 8145227Ssaidi@eecs.umich.edu print "Using saved variables file %s" % current_vars_file 8155227Ssaidi@eecs.umich.edu else: 8165227Ssaidi@eecs.umich.edu # Build dir-specific variables file doesn't exist. 8175204Sstever@gmail.com 8185204Sstever@gmail.com # Make sure the directory is there so we can create it later 8195204Sstever@gmail.com opt_dir = dirname(current_vars_file) 8205204Sstever@gmail.com if not isdir(opt_dir): 8215204Sstever@gmail.com mkdir(opt_dir) 8225204Sstever@gmail.com 8235204Sstever@gmail.com # Get default build variables from source tree. Variables are 8245204Sstever@gmail.com # normally determined by name of $VARIANT_DIR, but can be 8255204Sstever@gmail.com # overriden by 'default=' arg on command line. 8265204Sstever@gmail.com default_vars_file = joinpath('build_opts', 8275204Sstever@gmail.com ARGUMENTS.get('default', variant_dir)) 8285204Sstever@gmail.com if isfile(default_vars_file): 8295204Sstever@gmail.com sticky_vars.files.append(default_vars_file) 8305204Sstever@gmail.com print "Variables file %s not found,\n using defaults in %s" \ 8315204Sstever@gmail.com % (current_vars_file, default_vars_file) 8325204Sstever@gmail.com else: 8335204Sstever@gmail.com print "Error: cannot find variables file %s or %s" \ 8346121Snate@binkert.org % (current_vars_file, default_vars_file) 8355204Sstever@gmail.com Exit(1) 8367727SAli.Saidi@ARM.com 8377727SAli.Saidi@ARM.com # Apply current variable settings to env 8387727SAli.Saidi@ARM.com sticky_vars.Update(env) 8397727SAli.Saidi@ARM.com nonsticky_vars.Update(env) 8407727SAli.Saidi@ARM.com 8419812Sandreas.hansson@arm.com help_text += "\nSticky variables for %s:\n" % variant_dir \ 8429812Sandreas.hansson@arm.com + sticky_vars.GenerateHelpText(env) \ 8439812Sandreas.hansson@arm.com + "\nNon-sticky variables for %s:\n" % variant_dir \ 8449812Sandreas.hansson@arm.com + nonsticky_vars.GenerateHelpText(env) 8459812Sandreas.hansson@arm.com 8469812Sandreas.hansson@arm.com # Process variable settings. 8479812Sandreas.hansson@arm.com 8489812Sandreas.hansson@arm.com if not have_fenv and env['USE_FENV']: 8499812Sandreas.hansson@arm.com print "Warning: <fenv.h> not available; " \ 8509812Sandreas.hansson@arm.com "forcing USE_FENV to False in", variant_dir + "." 8519812Sandreas.hansson@arm.com env['USE_FENV'] = False 8529812Sandreas.hansson@arm.com 8539812Sandreas.hansson@arm.com if not env['USE_FENV']: 8549812Sandreas.hansson@arm.com print "Warning: No IEEE FP rounding mode control in", variant_dir + "." 8559812Sandreas.hansson@arm.com print " FP results may deviate slightly from other platforms." 8569812Sandreas.hansson@arm.com 8579812Sandreas.hansson@arm.com if env['EFENCE']: 8589812Sandreas.hansson@arm.com env.Append(LIBS=['efence']) 8599812Sandreas.hansson@arm.com 8609812Sandreas.hansson@arm.com if env['USE_MYSQL']: 8619812Sandreas.hansson@arm.com if not have_mysql: 8629812Sandreas.hansson@arm.com print "Warning: MySQL not available; " \ 8639812Sandreas.hansson@arm.com "forcing USE_MYSQL to False in", variant_dir + "." 8649812Sandreas.hansson@arm.com env['USE_MYSQL'] = False 8657727SAli.Saidi@ARM.com else: 8665863Snate@binkert.org print "Compiling in", variant_dir, "with MySQL support." 8673118Sstever@eecs.umich.edu env.ParseConfig(mysql_config_libs) 8685863Snate@binkert.org env.ParseConfig(mysql_config_include) 8699239Sandreas.hansson@arm.com 8703118Sstever@eecs.umich.edu # Save sticky variable settings back to current variables file 8713118Sstever@eecs.umich.edu sticky_vars.Save(current_vars_file, env) 8725863Snate@binkert.org 8735863Snate@binkert.org if env['USE_SSE2']: 8745863Snate@binkert.org env.Append(CCFLAGS='-msse2') 8755863Snate@binkert.org 8763118Sstever@eecs.umich.edu # The src/SConscript file sets up the build rules in 'env' according 8773483Ssaidi@eecs.umich.edu # to the configured variables. It returns a list of environments, 8783494Ssaidi@eecs.umich.edu # one for each variant build (debug, opt, etc.) 8793494Ssaidi@eecs.umich.edu envList = SConscript('src/SConscript', variant_dir = variant_path, 8803483Ssaidi@eecs.umich.edu exports = 'env') 8813483Ssaidi@eecs.umich.edu 8823483Ssaidi@eecs.umich.edu # Set up the regression tests for each build. 8833053Sstever@eecs.umich.edu for e in envList: 8843053Sstever@eecs.umich.edu SConscript('tests/SConscript', 8853918Ssaidi@eecs.umich.edu variant_dir = joinpath(variant_path, 'tests', e.Label), 8863053Sstever@eecs.umich.edu exports = { 'env' : e }, duplicate = False) 8873053Sstever@eecs.umich.edu 8883053Sstever@eecs.umich.eduHelp(help_text) 8893053Sstever@eecs.umich.edu