SConstruct revision 5385
1955SN/A# -*- mode:python -*- 2955SN/A 37816Ssteve.reinhardt@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 45871Snate@binkert.org# All rights reserved. 51762SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28955SN/A# 29955SN/A# Authors: Steve Reinhardt 302665Ssaidi@eecs.umich.edu 312665Ssaidi@eecs.umich.edu################################################### 325863Snate@binkert.org# 33955SN/A# SCons top-level build description (SConstruct) file. 34955SN/A# 35955SN/A# While in this directory ('m5'), just type 'scons' to build the default 36955SN/A# configuration (see below), or type 'scons build/<CONFIG>/<binary>' 37955SN/A# to build some other configuration (e.g., 'build/ALPHA_FS/m5.opt' for 388878Ssteve.reinhardt@amd.com# the optimized full-system version). 392632Sstever@eecs.umich.edu# 408878Ssteve.reinhardt@amd.com# You can build M5 in a different directory as long as there is a 412632Sstever@eecs.umich.edu# 'build/<CONFIG>' somewhere along the target path. The build system 42955SN/A# expects that all configs under the same build directory are being 438878Ssteve.reinhardt@amd.com# built for the same host system. 442632Sstever@eecs.umich.edu# 452761Sstever@eecs.umich.edu# Examples: 462632Sstever@eecs.umich.edu# 472632Sstever@eecs.umich.edu# The following two commands are equivalent. The '-u' option tells 482632Sstever@eecs.umich.edu# scons to search up the directory tree for this SConstruct file. 492761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 502761Sstever@eecs.umich.edu# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512761Sstever@eecs.umich.edu# 528878Ssteve.reinhardt@amd.com# The following two commands are equivalent and demonstrate building 538878Ssteve.reinhardt@amd.com# in a directory outside of the source tree. The '-C' option tells 542761Sstever@eecs.umich.edu# scons to chdir to the specified directory to find this SConstruct 552761Sstever@eecs.umich.edu# file. 562761Sstever@eecs.umich.edu# % cd <path-to-src>/m5 ; scons /local/foo/build/ALPHA_FS/m5.debug 572761Sstever@eecs.umich.edu# % cd /local/foo/build/ALPHA_FS; scons -C <path-to-src>/m5 m5.debug 582761Sstever@eecs.umich.edu# 598878Ssteve.reinhardt@amd.com# You can use 'scons -H' to print scons options. If you're in this 608878Ssteve.reinhardt@amd.com# 'm5' directory (or use -u or -C to tell scons where to find this 612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 622632Sstever@eecs.umich.edu# options as well. 638878Ssteve.reinhardt@amd.com# 648878Ssteve.reinhardt@amd.com################################################### 652632Sstever@eecs.umich.edu 66955SN/Aimport sys 67955SN/Aimport os 68955SN/A 695863Snate@binkert.orgfrom os.path import isdir, isfile, join as joinpath 705863Snate@binkert.org 715863Snate@binkert.orgimport SCons 725863Snate@binkert.org 735863Snate@binkert.org# Check for recent-enough Python and SCons versions. If your system's 745863Snate@binkert.org# default installation of Python is not recent enough, you can use a 755863Snate@binkert.org# non-default installation of the Python interpreter by either (1) 765863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python' 775863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the 785863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 795863Snate@binkert.orgEnsurePythonVersion(2,4) 808878Ssteve.reinhardt@amd.com 815863Snate@binkert.org# Import subprocess after we check the version since it doesn't exist in 825863Snate@binkert.org# Python < 2.4. 835863Snate@binkert.orgimport subprocess 845863Snate@binkert.org 855863Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 865863Snate@binkert.org# 3-element version number. 875863Snate@binkert.orgmin_scons_version = (0,96,91) 885863Snate@binkert.orgtry: 895863Snate@binkert.org EnsureSConsVersion(*min_scons_version) 905863Snate@binkert.orgexcept: 915863Snate@binkert.org print "Error checking current SCons version." 925863Snate@binkert.org print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 935863Snate@binkert.org Exit(2) 945863Snate@binkert.org 955863Snate@binkert.org 968878Ssteve.reinhardt@amd.com# The absolute path to the current directory (where this file lives). 975863Snate@binkert.orgROOT = Dir('.').abspath 985863Snate@binkert.org 995863Snate@binkert.org# Path to the M5 source tree. 1006654Snate@binkert.orgSRCDIR = joinpath(ROOT, 'src') 101955SN/A 1025396Ssaidi@eecs.umich.edu# tell python where to find m5 python code 1035863Snate@binkert.orgsys.path.append(joinpath(ROOT, 'src/python')) 1045863Snate@binkert.org 1054202Sbinkertn@umich.edudef check_style_hook(ui): 1065863Snate@binkert.org ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 1075863Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) 1085863Snate@binkert.org 1095863Snate@binkert.org if not style_hook: 110955SN/A print """\ 1116654Snate@binkert.orgYou're missing the M5 style hook. 1125273Sstever@gmail.comPlease install the hook so we can ensure that all code fits a common style. 1135871Snate@binkert.org 1145273Sstever@gmail.comAll you'd need to do is add the following lines to your repository .hg/hgrc 1156655Snate@binkert.orgor your personal .hgrc 1168878Ssteve.reinhardt@amd.com---------------- 1176655Snate@binkert.org 1186655Snate@binkert.org[extensions] 1199219Spower.jg@gmail.comstyle = %s/util/style.py 1206655Snate@binkert.org 1215871Snate@binkert.org[hooks] 1226654Snate@binkert.orgpretxncommit.style = python:style.check_whitespace 1238947Sandreas.hansson@arm.com""" % (ROOT) 1245396Ssaidi@eecs.umich.edu sys.exit(1) 1258120Sgblack@eecs.umich.edu 1268120Sgblack@eecs.umich.eduif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1278120Sgblack@eecs.umich.edu try: 1288120Sgblack@eecs.umich.edu from mercurial import ui 1298120Sgblack@eecs.umich.edu check_style_hook(ui.ui()) 1308120Sgblack@eecs.umich.edu except ImportError: 1318120Sgblack@eecs.umich.edu pass 1328120Sgblack@eecs.umich.edu 1338879Ssteve.reinhardt@amd.com################################################### 1348879Ssteve.reinhardt@amd.com# 1358879Ssteve.reinhardt@amd.com# Figure out which configurations to set up based on the path(s) of 1368879Ssteve.reinhardt@amd.com# the target(s). 1378879Ssteve.reinhardt@amd.com# 1388879Ssteve.reinhardt@amd.com################################################### 1398879Ssteve.reinhardt@amd.com 1408879Ssteve.reinhardt@amd.com# Find default configuration & binary. 1418879Ssteve.reinhardt@amd.comDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1428879Ssteve.reinhardt@amd.com 1438879Ssteve.reinhardt@amd.com# helper function: find last occurrence of element in list 1448879Ssteve.reinhardt@amd.comdef rfind(l, elt, offs = -1): 1458879Ssteve.reinhardt@amd.com for i in range(len(l)+offs, 0, -1): 1468120Sgblack@eecs.umich.edu if l[i] == elt: 1478120Sgblack@eecs.umich.edu return i 1488120Sgblack@eecs.umich.edu raise ValueError, "element not found" 1498120Sgblack@eecs.umich.edu 1508120Sgblack@eecs.umich.edu# helper function: compare dotted version numbers. 1518120Sgblack@eecs.umich.edu# E.g., compare_version('1.3.25', '1.4.1') 1528120Sgblack@eecs.umich.edu# returns -1, 0, 1 if v1 is <, ==, > v2 1538120Sgblack@eecs.umich.edudef compare_versions(v1, v2): 1548120Sgblack@eecs.umich.edu # Convert dotted strings to lists 1558120Sgblack@eecs.umich.edu v1 = map(int, v1.split('.')) 1568120Sgblack@eecs.umich.edu v2 = map(int, v2.split('.')) 1578120Sgblack@eecs.umich.edu # Compare corresponding elements of lists 1588120Sgblack@eecs.umich.edu for n1,n2 in zip(v1, v2): 1598120Sgblack@eecs.umich.edu if n1 < n2: return -1 1608879Ssteve.reinhardt@amd.com if n1 > n2: return 1 1618879Ssteve.reinhardt@amd.com # all corresponding values are equal... see if one has extra values 1628879Ssteve.reinhardt@amd.com if len(v1) < len(v2): return -1 1638879Ssteve.reinhardt@amd.com if len(v1) > len(v2): return 1 1648879Ssteve.reinhardt@amd.com return 0 1658879Ssteve.reinhardt@amd.com 1668879Ssteve.reinhardt@amd.com# Each target must have 'build' in the interior of the path; the 1678879Ssteve.reinhardt@amd.com# directory below this will determine the build parameters. For 1689227Sandreas.hansson@arm.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1699227Sandreas.hansson@arm.com# recognize that ALPHA_SE specifies the configuration because it 1708879Ssteve.reinhardt@amd.com# follow 'build' in the bulid path. 1718879Ssteve.reinhardt@amd.com 1728879Ssteve.reinhardt@amd.com# Generate absolute paths to targets so we can see where the build dir is 1738879Ssteve.reinhardt@amd.comif COMMAND_LINE_TARGETS: 1748120Sgblack@eecs.umich.edu # Ask SCons which directory it was invoked from 1758947Sandreas.hansson@arm.com launch_dir = GetLaunchDir() 1767816Ssteve.reinhardt@amd.com # Make targets relative to invocation directory 1775871Snate@binkert.org abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 1785871Snate@binkert.org COMMAND_LINE_TARGETS) 1796121Snate@binkert.orgelse: 1805871Snate@binkert.org # Default targets are relative to root of tree 1815871Snate@binkert.org abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 1829119Sandreas.hansson@arm.com DEFAULT_TARGETS) 1839119Sandreas.hansson@arm.com 184955SN/A 1855871Snate@binkert.org# Generate a list of the unique build roots and configs that the 1865871Snate@binkert.org# collected targets reference. 1875871Snate@binkert.orgbuild_paths = [] 1885871Snate@binkert.orgbuild_root = None 189955SN/Afor t in abs_targets: 1906121Snate@binkert.org path_dirs = t.split('/') 1918881Smarc.orr@gmail.com try: 1926121Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 1936121Snate@binkert.org except: 1941533SN/A print "Error: no non-leaf 'build' dir found on target path", t 1959239Sandreas.hansson@arm.com Exit(1) 1969239Sandreas.hansson@arm.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 1979239Sandreas.hansson@arm.com if not build_root: 1989239Sandreas.hansson@arm.com build_root = this_build_root 1999239Sandreas.hansson@arm.com else: 2009239Sandreas.hansson@arm.com if this_build_root != build_root: 2019239Sandreas.hansson@arm.com print "Error: build targets not under same build root\n"\ 2029239Sandreas.hansson@arm.com " %s\n %s" % (build_root, this_build_root) 2039239Sandreas.hansson@arm.com Exit(1) 2049239Sandreas.hansson@arm.com build_path = joinpath('/',*path_dirs[:build_top+2]) 2059239Sandreas.hansson@arm.com if build_path not in build_paths: 2069239Sandreas.hansson@arm.com build_paths.append(build_path) 2076655Snate@binkert.org 2086655Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 2096655Snate@binkert.orgif not isdir(build_root): 2106655Snate@binkert.org os.mkdir(build_root) 2115871Snate@binkert.org 2125871Snate@binkert.org################################################### 2135863Snate@binkert.org# 2145871Snate@binkert.org# Set up the default build environment. This environment is copied 2158878Ssteve.reinhardt@amd.com# and modified according to each selected configuration. 2165871Snate@binkert.org# 2175871Snate@binkert.org################################################### 2185871Snate@binkert.org 2195863Snate@binkert.orgenv = Environment(ENV = os.environ, # inherit user's environment vars 2206121Snate@binkert.org ROOT = ROOT, 2215863Snate@binkert.org SRCDIR = SRCDIR) 2225871Snate@binkert.org 2238336Ssteve.reinhardt@amd.comExport('env') 2248336Ssteve.reinhardt@amd.com 2258336Ssteve.reinhardt@amd.comenv.SConsignFile(joinpath(build_root,"sconsign")) 2268336Ssteve.reinhardt@amd.com 2274678Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 2288336Ssteve.reinhardt@amd.com# when you use emacs to edit a file in the target dir, as emacs moves 2298336Ssteve.reinhardt@amd.com# file to file~ then copies to file, breaking the link. Symbolic 2308336Ssteve.reinhardt@amd.com# (soft) links work better. 2314678Snate@binkert.orgenv.SetOption('duplicate', 'soft-copy') 2324678Snate@binkert.org 2334678Snate@binkert.org# I waffle on this setting... it does avoid a few painful but 2344678Snate@binkert.org# unnecessary builds, but it also seems to make trivial builds take 2357827Snate@binkert.org# noticeably longer. 2367827Snate@binkert.orgif False: 2378336Ssteve.reinhardt@amd.com env.TargetSignatures('content') 2384678Snate@binkert.org 2398336Ssteve.reinhardt@amd.com# 2408336Ssteve.reinhardt@amd.com# Set up global sticky options... these are common to an entire build 2418336Ssteve.reinhardt@amd.com# tree (not specific to a particular build like ALPHA_SE) 2428336Ssteve.reinhardt@amd.com# 2438336Ssteve.reinhardt@amd.com 2448336Ssteve.reinhardt@amd.com# Option validators & converters for global sticky options 2455871Snate@binkert.orgdef PathListMakeAbsolute(val): 2465871Snate@binkert.org if not val: 2478336Ssteve.reinhardt@amd.com return val 2488336Ssteve.reinhardt@amd.com f = lambda p: os.path.abspath(os.path.expanduser(p)) 2498336Ssteve.reinhardt@amd.com return ':'.join(map(f, val.split(':'))) 2508336Ssteve.reinhardt@amd.com 2518336Ssteve.reinhardt@amd.comdef PathListAllExist(key, val, env): 2525871Snate@binkert.org if not val: 2538336Ssteve.reinhardt@amd.com return 2548336Ssteve.reinhardt@amd.com paths = val.split(':') 2558336Ssteve.reinhardt@amd.com for path in paths: 2568336Ssteve.reinhardt@amd.com if not isdir(path): 2578336Ssteve.reinhardt@amd.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 2584678Snate@binkert.org 2595871Snate@binkert.orgglobal_sticky_opts_file = joinpath(build_root, 'options.global') 2604678Snate@binkert.org 2618336Ssteve.reinhardt@amd.comglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS) 2628336Ssteve.reinhardt@amd.com 2638336Ssteve.reinhardt@amd.comglobal_sticky_opts.AddOptions( 2648336Ssteve.reinhardt@amd.com ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 2658336Ssteve.reinhardt@amd.com ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 2668336Ssteve.reinhardt@amd.com ('EXTRAS', 'Add Extra directories to the compilation', '', 2678336Ssteve.reinhardt@amd.com PathListAllExist, PathListMakeAbsolute) 2688336Ssteve.reinhardt@amd.com ) 2698336Ssteve.reinhardt@amd.com 2708336Ssteve.reinhardt@amd.com 2718336Ssteve.reinhardt@amd.com# base help text 2728336Ssteve.reinhardt@amd.comhelp_text = ''' 2738336Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)] 2748336Ssteve.reinhardt@amd.com 2758336Ssteve.reinhardt@amd.com''' 2768336Ssteve.reinhardt@amd.com 2778336Ssteve.reinhardt@amd.comhelp_text += "Global sticky options:\n" \ 2785871Snate@binkert.org + global_sticky_opts.GenerateHelpText(env) 2796121Snate@binkert.org 280955SN/A# Update env with values from ARGUMENTS & file global_sticky_opts_file 281955SN/Aglobal_sticky_opts.Update(env) 2822632Sstever@eecs.umich.edu 2832632Sstever@eecs.umich.edu# Save sticky option settings back to current options file 284955SN/Aglobal_sticky_opts.Save(global_sticky_opts_file, env) 285955SN/A 286955SN/A# Parse EXTRAS option to build list of all directories where we're 287955SN/A# look for sources etc. This list is exported as base_dir_list. 2888878Ssteve.reinhardt@amd.combase_dir_list = [joinpath(ROOT, 'src')] 289955SN/Aif env['EXTRAS']: 2902632Sstever@eecs.umich.edu base_dir_list += env['EXTRAS'].split(':') 2912632Sstever@eecs.umich.edu 2922632Sstever@eecs.umich.eduExport('base_dir_list') 2932632Sstever@eecs.umich.edu 2942632Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 2952632Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 2962632Sstever@eecs.umich.eduenv['GCC'] = False 2978268Ssteve.reinhardt@amd.comenv['SUNCC'] = False 2988268Ssteve.reinhardt@amd.comenv['ICC'] = False 2998268Ssteve.reinhardt@amd.comenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 3008268Ssteve.reinhardt@amd.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3018268Ssteve.reinhardt@amd.com close_fds=True).communicate()[0].find('GCC') >= 0 3028268Ssteve.reinhardt@amd.comenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3038268Ssteve.reinhardt@amd.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3042632Sstever@eecs.umich.edu close_fds=True).communicate()[0].find('Sun C++') >= 0 3052632Sstever@eecs.umich.eduenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3062632Sstever@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3072632Sstever@eecs.umich.edu close_fds=True).communicate()[0].find('Intel') >= 0 3088268Ssteve.reinhardt@amd.comif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3092632Sstever@eecs.umich.edu print 'Error: How can we have two at the same time?' 3108268Ssteve.reinhardt@amd.com Exit(1) 3118268Ssteve.reinhardt@amd.com 3128268Ssteve.reinhardt@amd.com 3138268Ssteve.reinhardt@amd.com# Set up default C++ compiler flags 3143718Sstever@eecs.umich.eduif env['GCC']: 3152634Sstever@eecs.umich.edu env.Append(CCFLAGS='-pipe') 3162634Sstever@eecs.umich.edu env.Append(CCFLAGS='-fno-strict-aliasing') 3175863Snate@binkert.org env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3182638Sstever@eecs.umich.eduelif env['ICC']: 3198268Ssteve.reinhardt@amd.com pass #Fix me... add warning flags once we clean up icc warnings 3202632Sstever@eecs.umich.eduelif env['SUNCC']: 3212632Sstever@eecs.umich.edu env.Append(CCFLAGS='-Qoption ccfe') 3222632Sstever@eecs.umich.edu env.Append(CCFLAGS='-features=gcc') 3232632Sstever@eecs.umich.edu env.Append(CCFLAGS='-features=extensions') 3242632Sstever@eecs.umich.edu env.Append(CCFLAGS='-library=stlport4') 3251858SN/A env.Append(CCFLAGS='-xar') 3263716Sstever@eecs.umich.edu# env.Append(CCFLAGS='-instances=semiexplicit') 3272638Sstever@eecs.umich.eduelse: 3282638Sstever@eecs.umich.edu print 'Error: Don\'t know what compiler options to use for your compiler.' 3292638Sstever@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 3302638Sstever@eecs.umich.edu Exit(1) 3312638Sstever@eecs.umich.edu 3322638Sstever@eecs.umich.eduif sys.platform == 'cygwin': 3332638Sstever@eecs.umich.edu # cygwin has some header file issues... 3345863Snate@binkert.org env.Append(CCFLAGS=Split("-Wno-uninitialized")) 3355863Snate@binkert.orgenv.Append(CPPPATH=[Dir('ext/dnet')]) 3365863Snate@binkert.org 337955SN/A# Check for SWIG 3385341Sstever@gmail.comif not env.has_key('SWIG'): 3395341Sstever@gmail.com print 'Error: SWIG utility not found.' 3405863Snate@binkert.org print ' Please install (see http://www.swig.org) and retry.' 3417756SAli.Saidi@ARM.com Exit(1) 3425341Sstever@gmail.com 3436121Snate@binkert.org# Check for appropriate SWIG version 3444494Ssaidi@eecs.umich.eduswig_version = os.popen('swig -version').read().split() 3456121Snate@binkert.org# First 3 words should be "SWIG Version x.y.z" 3461105SN/Aif len(swig_version) < 3 or \ 3472667Sstever@eecs.umich.edu swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 3482667Sstever@eecs.umich.edu print 'Error determining SWIG version.' 3492667Sstever@eecs.umich.edu Exit(1) 3502667Sstever@eecs.umich.edu 3516121Snate@binkert.orgmin_swig_version = '1.3.28' 3522667Sstever@eecs.umich.eduif compare_versions(swig_version[2], min_swig_version) < 0: 3535341Sstever@gmail.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 3545863Snate@binkert.org print ' Installed version:', swig_version[2] 3555341Sstever@gmail.com Exit(1) 3565341Sstever@gmail.com 3575341Sstever@gmail.com# Set up SWIG flags & scanner 3588120Sgblack@eecs.umich.eduswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 3595341Sstever@gmail.comenv.Append(SWIGFLAGS=swig_flags) 3608120Sgblack@eecs.umich.edu 3615341Sstever@gmail.com# filter out all existing swig scanners, they mess up the dependency 3628120Sgblack@eecs.umich.edu# stuff for some reason 3636121Snate@binkert.orgscanners = [] 3646121Snate@binkert.orgfor scanner in env['SCANNERS']: 3658980Ssteve.reinhardt@amd.com skeys = scanner.skeys 3665397Ssaidi@eecs.umich.edu if skeys == '.i': 3675397Ssaidi@eecs.umich.edu continue 3687727SAli.Saidi@ARM.com 3698268Ssteve.reinhardt@amd.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 3706168Snate@binkert.org continue 3715341Sstever@gmail.com 3728120Sgblack@eecs.umich.edu scanners.append(scanner) 3738120Sgblack@eecs.umich.edu 3748120Sgblack@eecs.umich.edu# add the new swig scanner that we like better 3756814Sgblack@eecs.umich.edufrom SCons.Scanner import ClassicCPP as CPPScanner 3765863Snate@binkert.orgswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 3778120Sgblack@eecs.umich.eduscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 3785341Sstever@gmail.com 3795863Snate@binkert.org# replace the scanners list that has what we want 3808268Ssteve.reinhardt@amd.comenv['SCANNERS'] = scanners 3816121Snate@binkert.org 3826121Snate@binkert.org# Platform-specific configuration. Note again that we assume that all 3838268Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform. 3845742Snate@binkert.orgconf = Configure(env, 3855742Snate@binkert.org conf_dir = joinpath(build_root, '.scons_config'), 3865341Sstever@gmail.com log_file = joinpath(build_root, 'scons_config.log')) 3875742Snate@binkert.org 3885742Snate@binkert.org# Check if we should compile a 64 bit binary on Mac OS X/Darwin 3895341Sstever@gmail.comtry: 3906017Snate@binkert.org import platform 3916121Snate@binkert.org uname = platform.uname() 3926017Snate@binkert.org if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 3937816Ssteve.reinhardt@amd.com if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 3947756SAli.Saidi@ARM.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3957756SAli.Saidi@ARM.com close_fds=True).communicate()[0][0]): 3967756SAli.Saidi@ARM.com env.Append(CCFLAGS='-arch x86_64') 3977756SAli.Saidi@ARM.com env.Append(CFLAGS='-arch x86_64') 3987756SAli.Saidi@ARM.com env.Append(LINKFLAGS='-arch x86_64') 3997756SAli.Saidi@ARM.com env.Append(ASFLAGS='-arch x86_64') 4007756SAli.Saidi@ARM.com env['OSX64bit'] = True 4017756SAli.Saidi@ARM.comexcept: 4027816Ssteve.reinhardt@amd.com pass 4037816Ssteve.reinhardt@amd.com 4047816Ssteve.reinhardt@amd.com# Recent versions of scons substitute a "Null" object for Configure() 4057816Ssteve.reinhardt@amd.com# when configuration isn't necessary, e.g., if the "--help" option is 4067816Ssteve.reinhardt@amd.com# present. Unfortuantely this Null object always returns false, 4077816Ssteve.reinhardt@amd.com# breaking all our configuration checks. We replace it with our own 4087816Ssteve.reinhardt@amd.com# more optimistic null object that returns True instead. 4097816Ssteve.reinhardt@amd.comif not conf: 4107816Ssteve.reinhardt@amd.com def NullCheck(*args, **kwargs): 4117816Ssteve.reinhardt@amd.com return True 4127756SAli.Saidi@ARM.com 4137816Ssteve.reinhardt@amd.com class NullConf: 4147816Ssteve.reinhardt@amd.com def __init__(self, env): 4157816Ssteve.reinhardt@amd.com self.env = env 4167816Ssteve.reinhardt@amd.com def Finish(self): 4177816Ssteve.reinhardt@amd.com return self.env 4187816Ssteve.reinhardt@amd.com def __getattr__(self, mname): 4197816Ssteve.reinhardt@amd.com return NullCheck 4207816Ssteve.reinhardt@amd.com 4217816Ssteve.reinhardt@amd.com conf = NullConf(env) 4227816Ssteve.reinhardt@amd.com 4237816Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the 4247816Ssteve.reinhardt@amd.com# interpreter. For consistency, we will use the same Python 4257816Ssteve.reinhardt@amd.com# installation used to run scons (and thus this script). If you want 4267816Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how 4277816Ssteve.reinhardt@amd.com# to invoke scons with a different copy of the Python interpreter. 4287816Ssteve.reinhardt@amd.com 4297816Ssteve.reinhardt@amd.com# Get brief Python version name (e.g., "python2.4") for locating 4307816Ssteve.reinhardt@amd.com# include & library files 4317816Ssteve.reinhardt@amd.compy_version_name = 'python' + sys.version[:3] 4327816Ssteve.reinhardt@amd.com 4337816Ssteve.reinhardt@amd.com# include path, e.g. /usr/local/include/python2.4 4347816Ssteve.reinhardt@amd.compy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 4357816Ssteve.reinhardt@amd.comenv.Append(CPPPATH = py_header_path) 4367816Ssteve.reinhardt@amd.com# verify that it works 4377816Ssteve.reinhardt@amd.comif not conf.CheckHeader('Python.h', '<>'): 4387816Ssteve.reinhardt@amd.com print "Error: can't find Python.h header in", py_header_path 4397816Ssteve.reinhardt@amd.com Exit(1) 4407816Ssteve.reinhardt@amd.com 4417816Ssteve.reinhardt@amd.com# add library path too if it's not in the default place 4427816Ssteve.reinhardt@amd.compy_lib_path = None 4437816Ssteve.reinhardt@amd.comif sys.exec_prefix != '/usr': 4447816Ssteve.reinhardt@amd.com py_lib_path = joinpath(sys.exec_prefix, 'lib') 4457816Ssteve.reinhardt@amd.comelif sys.platform == 'cygwin': 4467816Ssteve.reinhardt@amd.com # cygwin puts the .dll in /bin for some reason 4477816Ssteve.reinhardt@amd.com py_lib_path = '/bin' 4487816Ssteve.reinhardt@amd.comif py_lib_path: 4497816Ssteve.reinhardt@amd.com env.Append(LIBPATH = py_lib_path) 4507816Ssteve.reinhardt@amd.com print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 4517816Ssteve.reinhardt@amd.comif not conf.CheckLib(py_version_name): 4527816Ssteve.reinhardt@amd.com print "Error: can't find Python library", py_version_name 4537816Ssteve.reinhardt@amd.com Exit(1) 4547816Ssteve.reinhardt@amd.com 4557816Ssteve.reinhardt@amd.com# On Solaris you need to use libsocket for socket ops 4567816Ssteve.reinhardt@amd.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 4577816Ssteve.reinhardt@amd.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 4587816Ssteve.reinhardt@amd.com print "Can't find library with socket calls (e.g. accept())" 4597816Ssteve.reinhardt@amd.com Exit(1) 4607816Ssteve.reinhardt@amd.com 4617816Ssteve.reinhardt@amd.com# Check for zlib. If the check passes, libz will be automatically 4627816Ssteve.reinhardt@amd.com# added to the LIBS environment variable. 4637816Ssteve.reinhardt@amd.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 4647816Ssteve.reinhardt@amd.com print 'Error: did not find needed zlib compression library '\ 4657816Ssteve.reinhardt@amd.com 'and/or zlib.h header file.' 4667816Ssteve.reinhardt@amd.com print ' Please install zlib and try again.' 4677816Ssteve.reinhardt@amd.com Exit(1) 4687816Ssteve.reinhardt@amd.com 4697816Ssteve.reinhardt@amd.com# Check for <fenv.h> (C99 FP environment control) 4707816Ssteve.reinhardt@amd.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 4717816Ssteve.reinhardt@amd.comif not have_fenv: 4727816Ssteve.reinhardt@amd.com print "Warning: Header file <fenv.h> not found." 4737816Ssteve.reinhardt@amd.com print " This host has no IEEE FP rounding mode control." 4748947Sandreas.hansson@arm.com 4758947Sandreas.hansson@arm.com# Check for mysql. 4767756SAli.Saidi@ARM.commysql_config = WhereIs('mysql_config') 4778120Sgblack@eecs.umich.eduhave_mysql = mysql_config != None 4787756SAli.Saidi@ARM.com 4797756SAli.Saidi@ARM.com# Check MySQL version. 4807756SAli.Saidi@ARM.comif have_mysql: 4817756SAli.Saidi@ARM.com mysql_version = os.popen(mysql_config + ' --version').read() 4827816Ssteve.reinhardt@amd.com min_mysql_version = '4.1' 4837816Ssteve.reinhardt@amd.com if compare_versions(mysql_version, min_mysql_version) < 0: 4847816Ssteve.reinhardt@amd.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 4857816Ssteve.reinhardt@amd.com print ' Version', mysql_version, 'detected.' 4867816Ssteve.reinhardt@amd.com have_mysql = False 4877816Ssteve.reinhardt@amd.com 4887816Ssteve.reinhardt@amd.com# Set up mysql_config commands. 4897816Ssteve.reinhardt@amd.comif have_mysql: 4907816Ssteve.reinhardt@amd.com mysql_config_include = mysql_config + ' --include' 4917816Ssteve.reinhardt@amd.com if os.system(mysql_config_include + ' > /dev/null') != 0: 4927756SAli.Saidi@ARM.com # older mysql_config versions don't support --include, use 4937756SAli.Saidi@ARM.com # --cflags instead 4949227Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 4959227Sandreas.hansson@arm.com # This seems to work in all versions 4969227Sandreas.hansson@arm.com mysql_config_libs = mysql_config + ' --libs' 4979227Sandreas.hansson@arm.com 4986654Snate@binkert.orgenv = conf.Finish() 4996654Snate@binkert.org 5005871Snate@binkert.org# Define the universe of supported ISAs 5016121Snate@binkert.orgall_isa_list = [ ] 5026121Snate@binkert.orgExport('all_isa_list') 5036121Snate@binkert.org 5048946Sandreas.hansson@arm.com# Define the universe of supported CPU models 5058737Skoansin.tan@gmail.comall_cpu_list = [ ] 5063940Ssaidi@eecs.umich.edudefault_cpus = [ ] 5073918Ssaidi@eecs.umich.eduExport('all_cpu_list', 'default_cpus') 5083918Ssaidi@eecs.umich.edu 5091858SN/A# Sticky options get saved in the options file so they persist from 5106121Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 5117739Sgblack@eecs.umich.edu# value becomes sticky). 5127739Sgblack@eecs.umich.edusticky_opts = Options(args=ARGUMENTS) 5136143Snate@binkert.orgExport('sticky_opts') 5147618SAli.Saidi@arm.com 5157618SAli.Saidi@arm.com# Non-sticky options only apply to the current build. 5167618SAli.Saidi@arm.comnonsticky_opts = Options(args=ARGUMENTS) 5177618SAli.Saidi@arm.comExport('nonsticky_opts') 5188614Sgblack@eecs.umich.edu 5197618SAli.Saidi@arm.com# Walk the tree and execute all SConsopts scripts that wil add to the 5207618SAli.Saidi@arm.com# above options 5217618SAli.Saidi@arm.comfor base_dir in base_dir_list: 5227739Sgblack@eecs.umich.edu for root, dirs, files in os.walk(base_dir): 5239224Sandreas.hansson@arm.com if 'SConsopts' in files: 5249224Sandreas.hansson@arm.com print "Reading", joinpath(root, 'SConsopts') 5259224Sandreas.hansson@arm.com SConscript(joinpath(root, 'SConsopts')) 5268946Sandreas.hansson@arm.com 5279227Sandreas.hansson@arm.comall_isa_list.sort() 5289227Sandreas.hansson@arm.comall_cpu_list.sort() 5299227Sandreas.hansson@arm.comdefault_cpus.sort() 5309227Sandreas.hansson@arm.com 5319227Sandreas.hansson@arm.comsticky_opts.AddOptions( 5329227Sandreas.hansson@arm.com EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 5339227Sandreas.hansson@arm.com BoolOption('FULL_SYSTEM', 'Full-system support', False), 5349227Sandreas.hansson@arm.com # There's a bug in scons 0.96.1 that causes ListOptions with list 5359227Sandreas.hansson@arm.com # values (more than one value) not to be able to be restored from 5369227Sandreas.hansson@arm.com # a saved option file. If this causes trouble then upgrade to 5379227Sandreas.hansson@arm.com # scons 0.96.90 or later. 5389227Sandreas.hansson@arm.com ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 5399227Sandreas.hansson@arm.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 5409227Sandreas.hansson@arm.com BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 5419227Sandreas.hansson@arm.com False), 5429227Sandreas.hansson@arm.com BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 5439227Sandreas.hansson@arm.com False), 5449227Sandreas.hansson@arm.com BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 5456121Snate@binkert.org False), 5463940Ssaidi@eecs.umich.edu BoolOption('SS_COMPATIBLE_FP', 5476121Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 5487739Sgblack@eecs.umich.edu False), 5497739Sgblack@eecs.umich.edu BoolOption('USE_SSE2', 5507739Sgblack@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 5517739Sgblack@eecs.umich.edu False), 5527739Sgblack@eecs.umich.edu BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 5537739Sgblack@eecs.umich.edu BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 5548737Skoansin.tan@gmail.com BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 5558737Skoansin.tan@gmail.com BoolOption('BATCH', 'Use batch pool for build and tests', False), 5568737Skoansin.tan@gmail.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 5578737Skoansin.tan@gmail.com ('PYTHONHOME', 5588737Skoansin.tan@gmail.com 'Override the default PYTHONHOME for this system (use with caution)', 5598737Skoansin.tan@gmail.com '%s:%s' % (sys.prefix, sys.exec_prefix)), 5608737Skoansin.tan@gmail.com ) 5618737Skoansin.tan@gmail.com 5628737Skoansin.tan@gmail.comnonsticky_opts.AddOptions( 5638737Skoansin.tan@gmail.com BoolOption('update_ref', 'Update test reference outputs', False) 5648737Skoansin.tan@gmail.com ) 5658737Skoansin.tan@gmail.com 5668737Skoansin.tan@gmail.com# These options get exported to #defines in config/*.hh (see src/SConscript). 5678737Skoansin.tan@gmail.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 5688737Skoansin.tan@gmail.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 5698737Skoansin.tan@gmail.com 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 5708737Skoansin.tan@gmail.com 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 5718737Skoansin.tan@gmail.com 5728946Sandreas.hansson@arm.com# Define a handy 'no-op' action 5738946Sandreas.hansson@arm.comdef no_action(target, source, env): 5748946Sandreas.hansson@arm.com return 0 5758946Sandreas.hansson@arm.com 5769224Sandreas.hansson@arm.comenv.NoAction = Action(no_action, None) 5779224Sandreas.hansson@arm.com 5788946Sandreas.hansson@arm.com################################################### 5798946Sandreas.hansson@arm.com# 5803918Ssaidi@eecs.umich.edu# Define a SCons builder for configuration flag headers. 5819068SAli.Saidi@ARM.com# 5829068SAli.Saidi@ARM.com################################################### 5839068SAli.Saidi@ARM.com 5849068SAli.Saidi@ARM.com# This function generates a config header file that #defines the 5859068SAli.Saidi@ARM.com# option symbol to the current option setting (0 or 1). The source 5869068SAli.Saidi@ARM.com# operands are the name of the option and a Value node containing the 5879068SAli.Saidi@ARM.com# value of the option. 5889068SAli.Saidi@ARM.comdef build_config_file(target, source, env): 5899068SAli.Saidi@ARM.com (option, value) = [s.get_contents() for s in source] 5909068SAli.Saidi@ARM.com f = file(str(target[0]), 'w') 5919068SAli.Saidi@ARM.com print >> f, '#define', option, value 5929068SAli.Saidi@ARM.com f.close() 5939068SAli.Saidi@ARM.com return None 5949068SAli.Saidi@ARM.com 5959068SAli.Saidi@ARM.com# Generate the message to be printed when building the config file. 5969068SAli.Saidi@ARM.comdef build_config_file_string(target, source, env): 5973918Ssaidi@eecs.umich.edu (option, value) = [s.get_contents() for s in source] 5983918Ssaidi@eecs.umich.edu return "Defining %s as %s in %s." % (option, value, target[0]) 5996157Snate@binkert.org 6006157Snate@binkert.org# Combine the two functions into a scons Action object. 6016157Snate@binkert.orgconfig_action = Action(build_config_file, build_config_file_string) 6026157Snate@binkert.org 6035397Ssaidi@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 6045397Ssaidi@eecs.umich.edu# we're really doing. 6056121Snate@binkert.orgdef config_emitter(target, source, env): 6066121Snate@binkert.org # extract option name from Builder arg 6076121Snate@binkert.org option = str(target[0]) 6086121Snate@binkert.org # True target is config header file 6096121Snate@binkert.org target = joinpath('config', option.lower() + '.hh') 6106121Snate@binkert.org val = env[option] 6115397Ssaidi@eecs.umich.edu if isinstance(val, bool): 6121851SN/A # Force value to 0/1 6131851SN/A val = int(val) 6147739Sgblack@eecs.umich.edu elif isinstance(val, str): 615955SN/A val = '"' + val + '"' 6163053Sstever@eecs.umich.edu 6176121Snate@binkert.org # Sources are option name & value (packaged in SCons Value nodes) 6183053Sstever@eecs.umich.edu return ([target], [Value(option), Value(val)]) 6193053Sstever@eecs.umich.edu 6203053Sstever@eecs.umich.educonfig_builder = Builder(emitter = config_emitter, action = config_action) 6213053Sstever@eecs.umich.edu 6223053Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 6239072Sandreas.hansson@arm.com 6243053Sstever@eecs.umich.edu################################################### 6254742Sstever@eecs.umich.edu# 6264742Sstever@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 6273053Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here 6283053Sstever@eecs.umich.edu# since it's potentially more generally applicable. 6293053Sstever@eecs.umich.edu# 6308960Ssteve.reinhardt@amd.com################################################### 6316654Snate@binkert.org 6323053Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 6333053Sstever@eecs.umich.edu 6343053Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 6353053Sstever@eecs.umich.edu 6362667Sstever@eecs.umich.edu################################################### 6374554Sbinkertn@umich.edu# 6386121Snate@binkert.org# Define a simple SCons builder to concatenate files. 6392667Sstever@eecs.umich.edu# 6404554Sbinkertn@umich.edu# Used to append the Python zip archive to the executable. 6414554Sbinkertn@umich.edu# 6424554Sbinkertn@umich.edu################################################### 6436121Snate@binkert.org 6444554Sbinkertn@umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 6454554Sbinkertn@umich.edu 'chmod +x $TARGET'])) 6464554Sbinkertn@umich.edu 6474781Snate@binkert.orgenv.Append(BUILDERS = { 'Concat' : concat_builder }) 6484554Sbinkertn@umich.edu 6494554Sbinkertn@umich.edu 6502667Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root. 6514554Sbinkertn@umich.eduenv.SConscript('ext/libelf/SConscript', 6524554Sbinkertn@umich.edu build_dir = joinpath(build_root, 'libelf'), 6534554Sbinkertn@umich.edu exports = 'env') 6544554Sbinkertn@umich.edu 6552667Sstever@eecs.umich.edu################################################### 6564554Sbinkertn@umich.edu# 6572667Sstever@eecs.umich.edu# This function is used to set up a directory with switching headers 6584554Sbinkertn@umich.edu# 6596121Snate@binkert.org################################################### 6602667Sstever@eecs.umich.edu 6615522Snate@binkert.orgenv['ALL_ISA_LIST'] = all_isa_list 6625522Snate@binkert.orgdef make_switching_dir(dirname, switch_headers, env): 6635522Snate@binkert.org # Generate the header. target[0] is the full path of the output 6645522Snate@binkert.org # header to generate. 'source' is a dummy variable, since we get the 6655522Snate@binkert.org # list of ISAs from env['ALL_ISA_LIST']. 6665522Snate@binkert.org def gen_switch_hdr(target, source, env): 6675522Snate@binkert.org fname = str(target[0]) 6685522Snate@binkert.org basename = os.path.basename(fname) 6695522Snate@binkert.org f = open(fname, 'w') 6705522Snate@binkert.org f.write('#include "arch/isa_specific.hh"\n') 6715522Snate@binkert.org cond = '#if' 6725522Snate@binkert.org for isa in all_isa_list: 6735522Snate@binkert.org f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 6745522Snate@binkert.org % (cond, isa.upper(), dirname, isa, basename)) 6755522Snate@binkert.org cond = '#elif' 6765522Snate@binkert.org f.write('#else\n#error "THE_ISA not set"\n#endif\n') 6775522Snate@binkert.org f.close() 6785522Snate@binkert.org return 0 6795522Snate@binkert.org 6805522Snate@binkert.org # String to print when generating header 6815522Snate@binkert.org def gen_switch_hdr_string(target, source, env): 6825522Snate@binkert.org return "Generating switch header " + str(target[0]) 6835522Snate@binkert.org 6845522Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 6855522Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 6865522Snate@binkert.org # should get re-executed. 6879255SAndreas.Sandberg@arm.com switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 6889255SAndreas.Sandberg@arm.com varlist=['ALL_ISA_LIST']) 6899255SAndreas.Sandberg@arm.com 6909255SAndreas.Sandberg@arm.com # Instantiate actions for each header 6919255SAndreas.Sandberg@arm.com for hdr in switch_headers: 6929255SAndreas.Sandberg@arm.com env.Command(hdr, [], switch_hdr_action) 6939255SAndreas.Sandberg@arm.comExport('make_switching_dir') 6949255SAndreas.Sandberg@arm.com 6959255SAndreas.Sandberg@arm.com################################################### 6969255SAndreas.Sandberg@arm.com# 6979255SAndreas.Sandberg@arm.com# Define build environments for selected configurations. 6989255SAndreas.Sandberg@arm.com# 6992638Sstever@eecs.umich.edu################################################### 7002638Sstever@eecs.umich.edu 7016121Snate@binkert.org# rename base env 7023716Sstever@eecs.umich.edubase_env = env 7035522Snate@binkert.org 7049255SAndreas.Sandberg@arm.comfor build_path in build_paths: 7059255SAndreas.Sandberg@arm.com print "Building in", build_path 7069255SAndreas.Sandberg@arm.com 7075522Snate@binkert.org # Make a copy of the build-root environment to use for this config. 7085522Snate@binkert.org env = base_env.Copy() 7095522Snate@binkert.org env['BUILDDIR'] = build_path 7105522Snate@binkert.org 7111858SN/A # build_dir is the tail component of build path, and is used to 7129255SAndreas.Sandberg@arm.com # determine the build parameters (e.g., 'ALPHA_SE') 7139255SAndreas.Sandberg@arm.com (build_root, build_dir) = os.path.split(build_path) 7149255SAndreas.Sandberg@arm.com 7155227Ssaidi@eecs.umich.edu # Set env options according to the build directory config. 7165227Ssaidi@eecs.umich.edu sticky_opts.files = [] 7175227Ssaidi@eecs.umich.edu # Options for $BUILD_ROOT/$BUILD_DIR are stored in 7185227Ssaidi@eecs.umich.edu # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 7196654Snate@binkert.org # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 7206654Snate@binkert.org current_opts_file = joinpath(build_root, 'options', build_dir) 7217769SAli.Saidi@ARM.com if isfile(current_opts_file): 7227769SAli.Saidi@ARM.com sticky_opts.files.append(current_opts_file) 7237769SAli.Saidi@ARM.com print "Using saved options file %s" % current_opts_file 7247769SAli.Saidi@ARM.com else: 7255227Ssaidi@eecs.umich.edu # Build dir-specific options file doesn't exist. 7265227Ssaidi@eecs.umich.edu 7275227Ssaidi@eecs.umich.edu # Make sure the directory is there so we can create it later 7285204Sstever@gmail.com opt_dir = os.path.dirname(current_opts_file) 7295204Sstever@gmail.com if not isdir(opt_dir): 7305204Sstever@gmail.com os.mkdir(opt_dir) 7315204Sstever@gmail.com 7325204Sstever@gmail.com # Get default build options from source tree. Options are 7335204Sstever@gmail.com # normally determined by name of $BUILD_DIR, but can be 7345204Sstever@gmail.com # overriden by 'default=' arg on command line. 7355204Sstever@gmail.com default_opts_file = joinpath('build_opts', 7365204Sstever@gmail.com ARGUMENTS.get('default', build_dir)) 7375204Sstever@gmail.com if isfile(default_opts_file): 7385204Sstever@gmail.com sticky_opts.files.append(default_opts_file) 7395204Sstever@gmail.com print "Options file %s not found,\n using defaults in %s" \ 7405204Sstever@gmail.com % (current_opts_file, default_opts_file) 7415204Sstever@gmail.com else: 7425204Sstever@gmail.com print "Error: cannot find options file %s or %s" \ 7435204Sstever@gmail.com % (current_opts_file, default_opts_file) 7445204Sstever@gmail.com Exit(1) 7456121Snate@binkert.org 7465204Sstever@gmail.com # Apply current option settings to env 7473118Sstever@eecs.umich.edu sticky_opts.Update(env) 7483118Sstever@eecs.umich.edu nonsticky_opts.Update(env) 7493118Sstever@eecs.umich.edu 7503118Sstever@eecs.umich.edu help_text += "\nSticky options for %s:\n" % build_dir \ 7513118Sstever@eecs.umich.edu + sticky_opts.GenerateHelpText(env) \ 7525863Snate@binkert.org + "\nNon-sticky options for %s:\n" % build_dir \ 7533118Sstever@eecs.umich.edu + nonsticky_opts.GenerateHelpText(env) 7545863Snate@binkert.org 7553118Sstever@eecs.umich.edu # Process option settings. 7567457Snate@binkert.org 7577457Snate@binkert.org if not have_fenv and env['USE_FENV']: 7585863Snate@binkert.org print "Warning: <fenv.h> not available; " \ 7595863Snate@binkert.org "forcing USE_FENV to False in", build_dir + "." 7605863Snate@binkert.org env['USE_FENV'] = False 7615863Snate@binkert.org 7625863Snate@binkert.org if not env['USE_FENV']: 7635863Snate@binkert.org print "Warning: No IEEE FP rounding mode control in", build_dir + "." 7645863Snate@binkert.org print " FP results may deviate slightly from other platforms." 7656003Snate@binkert.org 7665863Snate@binkert.org if env['EFENCE']: 7675863Snate@binkert.org env.Append(LIBS=['efence']) 7685863Snate@binkert.org 7696120Snate@binkert.org if env['USE_MYSQL']: 7705863Snate@binkert.org if not have_mysql: 7715863Snate@binkert.org print "Warning: MySQL not available; " \ 7725863Snate@binkert.org "forcing USE_MYSQL to False in", build_dir + "." 7738655Sandreas.hansson@arm.com env['USE_MYSQL'] = False 7748655Sandreas.hansson@arm.com else: 7758655Sandreas.hansson@arm.com print "Compiling in", build_dir, "with MySQL support." 7768655Sandreas.hansson@arm.com env.ParseConfig(mysql_config_libs) 7778655Sandreas.hansson@arm.com env.ParseConfig(mysql_config_include) 7788655Sandreas.hansson@arm.com 7798655Sandreas.hansson@arm.com # Save sticky option settings back to current options file 7808655Sandreas.hansson@arm.com sticky_opts.Save(current_opts_file, env) 7816120Snate@binkert.org 7825863Snate@binkert.org # Do this after we save setting back, or else we'll tack on an 7836121Snate@binkert.org # extra 'qdo' every time we run scons. 7846121Snate@binkert.org if env['BATCH']: 7855863Snate@binkert.org env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 7867727SAli.Saidi@ARM.com env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 7877727SAli.Saidi@ARM.com 7887727SAli.Saidi@ARM.com if env['USE_SSE2']: 7897727SAli.Saidi@ARM.com env.Append(CCFLAGS='-msse2') 7907727SAli.Saidi@ARM.com 7917727SAli.Saidi@ARM.com # The src/SConscript file sets up the build rules in 'env' according 7925863Snate@binkert.org # to the configured options. It returns a list of environments, 7933118Sstever@eecs.umich.edu # one for each variant build (debug, opt, etc.) 7945863Snate@binkert.org envList = SConscript('src/SConscript', build_dir = build_path, 7959239Sandreas.hansson@arm.com exports = 'env') 7963118Sstever@eecs.umich.edu 7973118Sstever@eecs.umich.edu # Set up the regression tests for each build. 7985863Snate@binkert.org for e in envList: 7995863Snate@binkert.org SConscript('tests/SConscript', 8005863Snate@binkert.org build_dir = joinpath(build_path, 'tests', e.Label), 8015863Snate@binkert.org exports = { 'env' : e }, duplicate = False) 8023118Sstever@eecs.umich.edu 8033483Ssaidi@eecs.umich.eduHelp(help_text) 8043494Ssaidi@eecs.umich.edu 8053494Ssaidi@eecs.umich.edu 8063483Ssaidi@eecs.umich.edu################################################### 8073483Ssaidi@eecs.umich.edu# 8083483Ssaidi@eecs.umich.edu# Let SCons do its thing. At this point SCons will use the defined 8093053Sstever@eecs.umich.edu# build environments to build the requested targets. 8103053Sstever@eecs.umich.edu# 8113918Ssaidi@eecs.umich.edu################################################### 8123053Sstever@eecs.umich.edu 8133053Sstever@eecs.umich.edu