SConstruct revision 5397
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/Aimport re 695863Snate@binkert.org 705863Snate@binkert.orgfrom os.path import isdir, isfile, join as joinpath 715863Snate@binkert.org 725863Snate@binkert.orgimport SCons 735863Snate@binkert.org 745863Snate@binkert.org# Check for recent-enough Python and SCons versions. If your system's 755863Snate@binkert.org# default installation of Python is not recent enough, you can use a 765863Snate@binkert.org# non-default installation of the Python interpreter by either (1) 775863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python' 785863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the 795863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 808878Ssteve.reinhardt@amd.comEnsurePythonVersion(2,4) 815863Snate@binkert.org 825863Snate@binkert.org# Import subprocess after we check the version since it doesn't exist in 835863Snate@binkert.org# Python < 2.4. 845863Snate@binkert.orgimport subprocess 855863Snate@binkert.org 865863Snate@binkert.org# helper function: compare arrays or strings of version numbers. 875863Snate@binkert.org# E.g., compare_version((1,3,25), (1,4,1)') 885863Snate@binkert.org# returns -1, 0, 1 if v1 is <, ==, > v2 895863Snate@binkert.orgdef compare_versions(v1, v2): 905863Snate@binkert.org def make_version_list(v): 915863Snate@binkert.org if isinstance(v, (list,tuple)): 925863Snate@binkert.org return v 935863Snate@binkert.org elif isinstance(v, str): 945863Snate@binkert.org return map(int, v.split('.')) 955863Snate@binkert.org else: 968878Ssteve.reinhardt@amd.com raise TypeError 975863Snate@binkert.org 985863Snate@binkert.org v1 = make_version_list(v1) 995863Snate@binkert.org v2 = make_version_list(v2) 1006654Snate@binkert.org # Compare corresponding elements of lists 101955SN/A for n1,n2 in zip(v1, v2): 1025396Ssaidi@eecs.umich.edu if n1 < n2: return -1 1035863Snate@binkert.org if n1 > n2: return 1 1045863Snate@binkert.org # all corresponding values are equal... see if one has extra values 1054202Sbinkertn@umich.edu if len(v1) < len(v2): return -1 1065863Snate@binkert.org if len(v1) > len(v2): return 1 1075863Snate@binkert.org return 0 1085863Snate@binkert.org 1095863Snate@binkert.org# SCons version numbers need special processing because they can have 110955SN/A# charecters and an release date embedded in them. This function does 1116654Snate@binkert.org# the magic to extract them in a similar way to the SCons internal function 1125273Sstever@gmail.com# function does and then checks that the current version is not contained in 1135871Snate@binkert.org# a list of version tuples (bad_ver_strs) 1145273Sstever@gmail.comdef CheckSCons(bad_ver_strs): 1156655Snate@binkert.org def scons_ver(v): 1168878Ssteve.reinhardt@amd.com num_parts = v.split(' ')[0].split('.') 1176655Snate@binkert.org major = int(num_parts[0]) 1186655Snate@binkert.org minor = int(re.match('\d+', num_parts[1]).group()) 1199219Spower.jg@gmail.com rev = 0 1206655Snate@binkert.org rdate = 0 1215871Snate@binkert.org if len(num_parts) > 2: 1226654Snate@binkert.org try: rev = int(re.match('\d+', num_parts[2]).group()) 1238947Sandreas.hansson@arm.com except: pass 1245396Ssaidi@eecs.umich.edu rev_parts = num_parts[2].split('d') 1258120Sgblack@eecs.umich.edu if len(rev_parts) > 1: 1268120Sgblack@eecs.umich.edu rdate = int(re.match('\d+', rev_parts[1]).group()) 1278120Sgblack@eecs.umich.edu 1288120Sgblack@eecs.umich.edu return (major, minor, rev, rdate) 1298120Sgblack@eecs.umich.edu 1308120Sgblack@eecs.umich.edu sc_ver = scons_ver(SCons.__version__) 1318120Sgblack@eecs.umich.edu for bad_ver in bad_ver_strs: 1328120Sgblack@eecs.umich.edu bv = (scons_ver(bad_ver[0]), scons_ver(bad_ver[1])) 1338879Ssteve.reinhardt@amd.com if compare_versions(sc_ver, bv[0]) != -1 and\ 1348879Ssteve.reinhardt@amd.com compare_versions(sc_ver, bv[1]) != 1: 1358879Ssteve.reinhardt@amd.com print "The version of SCons that you have installed: ", SCons.__version__ 1368879Ssteve.reinhardt@amd.com print "has a bug that prevents it from working correctly with M5." 1378879Ssteve.reinhardt@amd.com print "Please install a version NOT contained within the following", 1388879Ssteve.reinhardt@amd.com print "ranges (inclusive):" 1398879Ssteve.reinhardt@amd.com for bad_ver in bad_ver_strs: 1408879Ssteve.reinhardt@amd.com print " %s - %s" % bad_ver 1418879Ssteve.reinhardt@amd.com Exit(2) 1428879Ssteve.reinhardt@amd.com 1438879Ssteve.reinhardt@amd.comCheckSCons(( 1448879Ssteve.reinhardt@amd.com # We need a version that is 0.96.91 or newer 1458879Ssteve.reinhardt@amd.com ('0.0.0', '0.96.90'), 1468120Sgblack@eecs.umich.edu # This range has a bug with linking directories into the build dir 1478120Sgblack@eecs.umich.edu # that only have header files in them 1488120Sgblack@eecs.umich.edu ('0.97.0d20071212', '0.98.0') 1498120Sgblack@eecs.umich.edu )) 1508120Sgblack@eecs.umich.edu 1518120Sgblack@eecs.umich.edu 1528120Sgblack@eecs.umich.edu# The absolute path to the current directory (where this file lives). 1538120Sgblack@eecs.umich.eduROOT = Dir('.').abspath 1548120Sgblack@eecs.umich.edu 1558120Sgblack@eecs.umich.edu# Path to the M5 source tree. 1568120Sgblack@eecs.umich.eduSRCDIR = joinpath(ROOT, 'src') 1578120Sgblack@eecs.umich.edu 1588120Sgblack@eecs.umich.edu# tell python where to find m5 python code 1598120Sgblack@eecs.umich.edusys.path.append(joinpath(ROOT, 'src/python')) 1608879Ssteve.reinhardt@amd.com 1618879Ssteve.reinhardt@amd.comdef check_style_hook(ui): 1628879Ssteve.reinhardt@amd.com ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 1638879Ssteve.reinhardt@amd.com style_hook = ui.config('hooks', 'pretxncommit.style', None) 1648879Ssteve.reinhardt@amd.com 1658879Ssteve.reinhardt@amd.com if not style_hook: 1668879Ssteve.reinhardt@amd.com print """\ 1678879Ssteve.reinhardt@amd.comYou're missing the M5 style hook. 1689227Sandreas.hansson@arm.comPlease install the hook so we can ensure that all code fits a common style. 1699227Sandreas.hansson@arm.com 1708879Ssteve.reinhardt@amd.comAll you'd need to do is add the following lines to your repository .hg/hgrc 1718879Ssteve.reinhardt@amd.comor your personal .hgrc 1728879Ssteve.reinhardt@amd.com---------------- 1738879Ssteve.reinhardt@amd.com 1748120Sgblack@eecs.umich.edu[extensions] 1758947Sandreas.hansson@arm.comstyle = %s/util/style.py 1767816Ssteve.reinhardt@amd.com 1775871Snate@binkert.org[hooks] 1785871Snate@binkert.orgpretxncommit.style = python:style.check_whitespace 1796121Snate@binkert.org""" % (ROOT) 1805871Snate@binkert.org sys.exit(1) 1815871Snate@binkert.org 1829119Sandreas.hansson@arm.comif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1839396Sandreas.hansson@arm.com try: 1849396Sandreas.hansson@arm.com from mercurial import ui 185955SN/A check_style_hook(ui.ui()) 1869416SAndreas.Sandberg@ARM.com except ImportError: 1879416SAndreas.Sandberg@ARM.com pass 1889416SAndreas.Sandberg@ARM.com 1899416SAndreas.Sandberg@ARM.com################################################### 1909416SAndreas.Sandberg@ARM.com# 1919416SAndreas.Sandberg@ARM.com# Figure out which configurations to set up based on the path(s) of 1929416SAndreas.Sandberg@ARM.com# the target(s). 1935871Snate@binkert.org# 1945871Snate@binkert.org################################################### 1959416SAndreas.Sandberg@ARM.com 1969416SAndreas.Sandberg@ARM.com# Find default configuration & binary. 1975871Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 198955SN/A 1996121Snate@binkert.org# helper function: find last occurrence of element in list 2008881Smarc.orr@gmail.comdef rfind(l, elt, offs = -1): 2016121Snate@binkert.org for i in range(len(l)+offs, 0, -1): 2026121Snate@binkert.org if l[i] == elt: 2031533SN/A return i 2049239Sandreas.hansson@arm.com raise ValueError, "element not found" 2059239Sandreas.hansson@arm.com 2069239Sandreas.hansson@arm.com# Each target must have 'build' in the interior of the path; the 2079239Sandreas.hansson@arm.com# directory below this will determine the build parameters. For 2089239Sandreas.hansson@arm.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2099239Sandreas.hansson@arm.com# recognize that ALPHA_SE specifies the configuration because it 2109239Sandreas.hansson@arm.com# follow 'build' in the bulid path. 2119239Sandreas.hansson@arm.com 2129239Sandreas.hansson@arm.com# Generate absolute paths to targets so we can see where the build dir is 2139239Sandreas.hansson@arm.comif COMMAND_LINE_TARGETS: 2149239Sandreas.hansson@arm.com # Ask SCons which directory it was invoked from 2159239Sandreas.hansson@arm.com launch_dir = GetLaunchDir() 2166655Snate@binkert.org # Make targets relative to invocation directory 2176655Snate@binkert.org abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 2186655Snate@binkert.org COMMAND_LINE_TARGETS) 2196655Snate@binkert.orgelse: 2205871Snate@binkert.org # Default targets are relative to root of tree 2215871Snate@binkert.org abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 2225863Snate@binkert.org DEFAULT_TARGETS) 2235871Snate@binkert.org 2248878Ssteve.reinhardt@amd.com 2255871Snate@binkert.org# Generate a list of the unique build roots and configs that the 2265871Snate@binkert.org# collected targets reference. 2275871Snate@binkert.orgbuild_paths = [] 2285863Snate@binkert.orgbuild_root = None 2296121Snate@binkert.orgfor t in abs_targets: 2305863Snate@binkert.org path_dirs = t.split('/') 2315871Snate@binkert.org try: 2328336Ssteve.reinhardt@amd.com build_top = rfind(path_dirs, 'build', -2) 2338336Ssteve.reinhardt@amd.com except: 2348336Ssteve.reinhardt@amd.com print "Error: no non-leaf 'build' dir found on target path", t 2358336Ssteve.reinhardt@amd.com Exit(1) 2364678Snate@binkert.org this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2378336Ssteve.reinhardt@amd.com if not build_root: 2388336Ssteve.reinhardt@amd.com build_root = this_build_root 2398336Ssteve.reinhardt@amd.com else: 2404678Snate@binkert.org if this_build_root != build_root: 2414678Snate@binkert.org print "Error: build targets not under same build root\n"\ 2424678Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 2434678Snate@binkert.org Exit(1) 2447827Snate@binkert.org build_path = joinpath('/',*path_dirs[:build_top+2]) 2457827Snate@binkert.org if build_path not in build_paths: 2468336Ssteve.reinhardt@amd.com build_paths.append(build_path) 2474678Snate@binkert.org 2488336Ssteve.reinhardt@amd.com# Make sure build_root exists (might not if this is the first build there) 2498336Ssteve.reinhardt@amd.comif not isdir(build_root): 2508336Ssteve.reinhardt@amd.com os.mkdir(build_root) 2518336Ssteve.reinhardt@amd.com 2528336Ssteve.reinhardt@amd.com################################################### 2538336Ssteve.reinhardt@amd.com# 2545871Snate@binkert.org# Set up the default build environment. This environment is copied 2555871Snate@binkert.org# and modified according to each selected configuration. 2568336Ssteve.reinhardt@amd.com# 2578336Ssteve.reinhardt@amd.com################################################### 2588336Ssteve.reinhardt@amd.com 2598336Ssteve.reinhardt@amd.comenv = Environment(ENV = os.environ, # inherit user's environment vars 2608336Ssteve.reinhardt@amd.com ROOT = ROOT, 2615871Snate@binkert.org SRCDIR = SRCDIR) 2628336Ssteve.reinhardt@amd.com 2638336Ssteve.reinhardt@amd.comExport('env') 2648336Ssteve.reinhardt@amd.com 2658336Ssteve.reinhardt@amd.comenv.SConsignFile(joinpath(build_root,"sconsign")) 2668336Ssteve.reinhardt@amd.com 2674678Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 2685871Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 2694678Snate@binkert.org# file to file~ then copies to file, breaking the link. Symbolic 2708336Ssteve.reinhardt@amd.com# (soft) links work better. 2718336Ssteve.reinhardt@amd.comenv.SetOption('duplicate', 'soft-copy') 2728336Ssteve.reinhardt@amd.com 2738336Ssteve.reinhardt@amd.com# I waffle on this setting... it does avoid a few painful but 2748336Ssteve.reinhardt@amd.com# unnecessary builds, but it also seems to make trivial builds take 2758336Ssteve.reinhardt@amd.com# noticeably longer. 2768336Ssteve.reinhardt@amd.comif False: 2778336Ssteve.reinhardt@amd.com env.TargetSignatures('content') 2788336Ssteve.reinhardt@amd.com 2798336Ssteve.reinhardt@amd.com# 2808336Ssteve.reinhardt@amd.com# Set up global sticky options... these are common to an entire build 2818336Ssteve.reinhardt@amd.com# tree (not specific to a particular build like ALPHA_SE) 2828336Ssteve.reinhardt@amd.com# 2838336Ssteve.reinhardt@amd.com 2848336Ssteve.reinhardt@amd.com# Option validators & converters for global sticky options 2858336Ssteve.reinhardt@amd.comdef PathListMakeAbsolute(val): 2868336Ssteve.reinhardt@amd.com if not val: 2875871Snate@binkert.org return val 2886121Snate@binkert.org f = lambda p: os.path.abspath(os.path.expanduser(p)) 289955SN/A return ':'.join(map(f, val.split(':'))) 290955SN/A 2912632Sstever@eecs.umich.edudef PathListAllExist(key, val, env): 2922632Sstever@eecs.umich.edu if not val: 293955SN/A return 294955SN/A paths = val.split(':') 295955SN/A for path in paths: 296955SN/A if not isdir(path): 2978878Ssteve.reinhardt@amd.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 298955SN/A 2992632Sstever@eecs.umich.eduglobal_sticky_opts_file = joinpath(build_root, 'options.global') 3002632Sstever@eecs.umich.edu 3012632Sstever@eecs.umich.eduglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS) 3022632Sstever@eecs.umich.edu 3032632Sstever@eecs.umich.eduglobal_sticky_opts.AddOptions( 3042632Sstever@eecs.umich.edu ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3052632Sstever@eecs.umich.edu ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3068268Ssteve.reinhardt@amd.com ('BATCH', 'Use batch pool for build and tests', False), 3078268Ssteve.reinhardt@amd.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 3088268Ssteve.reinhardt@amd.com ('EXTRAS', 'Add Extra directories to the compilation', '', 3098268Ssteve.reinhardt@amd.com PathListAllExist, PathListMakeAbsolute) 3108268Ssteve.reinhardt@amd.com ) 3118268Ssteve.reinhardt@amd.com 3128268Ssteve.reinhardt@amd.com 3132632Sstever@eecs.umich.edu# base help text 3142632Sstever@eecs.umich.eduhelp_text = ''' 3152632Sstever@eecs.umich.eduUsage: scons [scons options] [build options] [target(s)] 3162632Sstever@eecs.umich.edu 3178268Ssteve.reinhardt@amd.com''' 3182632Sstever@eecs.umich.edu 3198268Ssteve.reinhardt@amd.comhelp_text += "Global sticky options:\n" \ 3208268Ssteve.reinhardt@amd.com + global_sticky_opts.GenerateHelpText(env) 3218268Ssteve.reinhardt@amd.com 3228268Ssteve.reinhardt@amd.com# Update env with values from ARGUMENTS & file global_sticky_opts_file 3233718Sstever@eecs.umich.eduglobal_sticky_opts.Update(env) 3242634Sstever@eecs.umich.edu 3252634Sstever@eecs.umich.edu# Save sticky option settings back to current options file 3265863Snate@binkert.orgglobal_sticky_opts.Save(global_sticky_opts_file, env) 3272638Sstever@eecs.umich.edu 3288268Ssteve.reinhardt@amd.com# Parse EXTRAS option to build list of all directories where we're 3292632Sstever@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3302632Sstever@eecs.umich.edubase_dir_list = [joinpath(ROOT, 'src')] 3312632Sstever@eecs.umich.eduif env['EXTRAS']: 3322632Sstever@eecs.umich.edu base_dir_list += env['EXTRAS'].split(':') 3332632Sstever@eecs.umich.edu 3341858SN/AExport('base_dir_list') 3353716Sstever@eecs.umich.edu 3362638Sstever@eecs.umich.edu# M5_PLY is used by isa_parser.py to find the PLY package. 3372638Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 3382638Sstever@eecs.umich.eduenv['GCC'] = False 3392638Sstever@eecs.umich.eduenv['SUNCC'] = False 3402638Sstever@eecs.umich.eduenv['ICC'] = False 3412638Sstever@eecs.umich.eduenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 3422638Sstever@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3435863Snate@binkert.org close_fds=True).communicate()[0].find('GCC') >= 0 3445863Snate@binkert.orgenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3455863Snate@binkert.org stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 346955SN/A close_fds=True).communicate()[0].find('Sun C++') >= 0 3475341Sstever@gmail.comenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3485341Sstever@gmail.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3495863Snate@binkert.org close_fds=True).communicate()[0].find('Intel') >= 0 3507756SAli.Saidi@ARM.comif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3515341Sstever@gmail.com print 'Error: How can we have two at the same time?' 3526121Snate@binkert.org Exit(1) 3534494Ssaidi@eecs.umich.edu 3546121Snate@binkert.org 3551105SN/A# Set up default C++ compiler flags 3562667Sstever@eecs.umich.eduif env['GCC']: 3572667Sstever@eecs.umich.edu env.Append(CCFLAGS='-pipe') 3582667Sstever@eecs.umich.edu env.Append(CCFLAGS='-fno-strict-aliasing') 3592667Sstever@eecs.umich.edu env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3606121Snate@binkert.orgelif env['ICC']: 3612667Sstever@eecs.umich.edu pass #Fix me... add warning flags once we clean up icc warnings 3625341Sstever@gmail.comelif env['SUNCC']: 3635863Snate@binkert.org env.Append(CCFLAGS='-Qoption ccfe') 3645341Sstever@gmail.com env.Append(CCFLAGS='-features=gcc') 3655341Sstever@gmail.com env.Append(CCFLAGS='-features=extensions') 3665341Sstever@gmail.com env.Append(CCFLAGS='-library=stlport4') 3678120Sgblack@eecs.umich.edu env.Append(CCFLAGS='-xar') 3685341Sstever@gmail.com# env.Append(CCFLAGS='-instances=semiexplicit') 3698120Sgblack@eecs.umich.eduelse: 3705341Sstever@gmail.com print 'Error: Don\'t know what compiler options to use for your compiler.' 3718120Sgblack@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 3726121Snate@binkert.org Exit(1) 3736121Snate@binkert.org 3748980Ssteve.reinhardt@amd.com# Do this after we save setting back, or else we'll tack on an 3759396Sandreas.hansson@arm.com# extra 'qdo' every time we run scons. 3765397Ssaidi@eecs.umich.eduif env['BATCH']: 3775397Ssaidi@eecs.umich.edu env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 3787727SAli.Saidi@ARM.com env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 3798268Ssteve.reinhardt@amd.com 3806168Snate@binkert.orgif sys.platform == 'cygwin': 3815341Sstever@gmail.com # cygwin has some header file issues... 3828120Sgblack@eecs.umich.edu env.Append(CCFLAGS=Split("-Wno-uninitialized")) 3838120Sgblack@eecs.umich.eduenv.Append(CPPPATH=[Dir('ext/dnet')]) 3848120Sgblack@eecs.umich.edu 3856814Sgblack@eecs.umich.edu# Check for SWIG 3865863Snate@binkert.orgif not env.has_key('SWIG'): 3878120Sgblack@eecs.umich.edu print 'Error: SWIG utility not found.' 3885341Sstever@gmail.com print ' Please install (see http://www.swig.org) and retry.' 3895863Snate@binkert.org Exit(1) 3908268Ssteve.reinhardt@amd.com 3916121Snate@binkert.org# Check for appropriate SWIG version 3926121Snate@binkert.orgswig_version = os.popen('swig -version').read().split() 3938268Ssteve.reinhardt@amd.com# First 3 words should be "SWIG Version x.y.z" 3945742Snate@binkert.orgif len(swig_version) < 3 or \ 3955742Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 3965341Sstever@gmail.com print 'Error determining SWIG version.' 3975742Snate@binkert.org Exit(1) 3985742Snate@binkert.org 3995341Sstever@gmail.commin_swig_version = '1.3.28' 4006017Snate@binkert.orgif compare_versions(swig_version[2], min_swig_version) < 0: 4016121Snate@binkert.org print 'Error: SWIG version', min_swig_version, 'or newer required.' 4026017Snate@binkert.org print ' Installed version:', swig_version[2] 4037816Ssteve.reinhardt@amd.com Exit(1) 4047756SAli.Saidi@ARM.com 4057756SAli.Saidi@ARM.com# Set up SWIG flags & scanner 4067756SAli.Saidi@ARM.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 4077756SAli.Saidi@ARM.comenv.Append(SWIGFLAGS=swig_flags) 4087756SAli.Saidi@ARM.com 4097756SAli.Saidi@ARM.com# filter out all existing swig scanners, they mess up the dependency 4107756SAli.Saidi@ARM.com# stuff for some reason 4117756SAli.Saidi@ARM.comscanners = [] 4127816Ssteve.reinhardt@amd.comfor scanner in env['SCANNERS']: 4137816Ssteve.reinhardt@amd.com skeys = scanner.skeys 4147816Ssteve.reinhardt@amd.com if skeys == '.i': 4157816Ssteve.reinhardt@amd.com continue 4167816Ssteve.reinhardt@amd.com 4177816Ssteve.reinhardt@amd.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4187816Ssteve.reinhardt@amd.com continue 4197816Ssteve.reinhardt@amd.com 4207816Ssteve.reinhardt@amd.com scanners.append(scanner) 4217816Ssteve.reinhardt@amd.com 4227756SAli.Saidi@ARM.com# add the new swig scanner that we like better 4237816Ssteve.reinhardt@amd.comfrom SCons.Scanner import ClassicCPP as CPPScanner 4247816Ssteve.reinhardt@amd.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4257816Ssteve.reinhardt@amd.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4267816Ssteve.reinhardt@amd.com 4277816Ssteve.reinhardt@amd.com# replace the scanners list that has what we want 4287816Ssteve.reinhardt@amd.comenv['SCANNERS'] = scanners 4297816Ssteve.reinhardt@amd.com 4307816Ssteve.reinhardt@amd.com# Platform-specific configuration. Note again that we assume that all 4317816Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform. 4327816Ssteve.reinhardt@amd.comconf = Configure(env, 4337816Ssteve.reinhardt@amd.com conf_dir = joinpath(build_root, '.scons_config'), 4347816Ssteve.reinhardt@amd.com log_file = joinpath(build_root, 'scons_config.log')) 4357816Ssteve.reinhardt@amd.com 4367816Ssteve.reinhardt@amd.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 4377816Ssteve.reinhardt@amd.comtry: 4387816Ssteve.reinhardt@amd.com import platform 4397816Ssteve.reinhardt@amd.com uname = platform.uname() 4407816Ssteve.reinhardt@amd.com if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 4417816Ssteve.reinhardt@amd.com if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 4427816Ssteve.reinhardt@amd.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 4437816Ssteve.reinhardt@amd.com close_fds=True).communicate()[0][0]): 4447816Ssteve.reinhardt@amd.com env.Append(CCFLAGS='-arch x86_64') 4457816Ssteve.reinhardt@amd.com env.Append(CFLAGS='-arch x86_64') 4467816Ssteve.reinhardt@amd.com env.Append(LINKFLAGS='-arch x86_64') 4477816Ssteve.reinhardt@amd.com env.Append(ASFLAGS='-arch x86_64') 4487816Ssteve.reinhardt@amd.comexcept: 4497816Ssteve.reinhardt@amd.com pass 4507816Ssteve.reinhardt@amd.com 4517816Ssteve.reinhardt@amd.com# Recent versions of scons substitute a "Null" object for Configure() 4527816Ssteve.reinhardt@amd.com# when configuration isn't necessary, e.g., if the "--help" option is 4537816Ssteve.reinhardt@amd.com# present. Unfortuantely this Null object always returns false, 4547816Ssteve.reinhardt@amd.com# breaking all our configuration checks. We replace it with our own 4557816Ssteve.reinhardt@amd.com# more optimistic null object that returns True instead. 4567816Ssteve.reinhardt@amd.comif not conf: 4577816Ssteve.reinhardt@amd.com def NullCheck(*args, **kwargs): 4587816Ssteve.reinhardt@amd.com return True 4597816Ssteve.reinhardt@amd.com 4607816Ssteve.reinhardt@amd.com class NullConf: 4617816Ssteve.reinhardt@amd.com def __init__(self, env): 4627816Ssteve.reinhardt@amd.com self.env = env 4637816Ssteve.reinhardt@amd.com def Finish(self): 4647816Ssteve.reinhardt@amd.com return self.env 4657816Ssteve.reinhardt@amd.com def __getattr__(self, mname): 4667816Ssteve.reinhardt@amd.com return NullCheck 4677816Ssteve.reinhardt@amd.com 4687816Ssteve.reinhardt@amd.com conf = NullConf(env) 4697816Ssteve.reinhardt@amd.com 4707816Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the 4717816Ssteve.reinhardt@amd.com# interpreter. For consistency, we will use the same Python 4727816Ssteve.reinhardt@amd.com# installation used to run scons (and thus this script). If you want 4737816Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how 4747816Ssteve.reinhardt@amd.com# to invoke scons with a different copy of the Python interpreter. 4757816Ssteve.reinhardt@amd.com 4767816Ssteve.reinhardt@amd.com# Get brief Python version name (e.g., "python2.4") for locating 4777816Ssteve.reinhardt@amd.com# include & library files 4787816Ssteve.reinhardt@amd.compy_version_name = 'python' + sys.version[:3] 4797816Ssteve.reinhardt@amd.com 4807816Ssteve.reinhardt@amd.com# include path, e.g. /usr/local/include/python2.4 4817816Ssteve.reinhardt@amd.compy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 4827816Ssteve.reinhardt@amd.comenv.Append(CPPPATH = py_header_path) 4837816Ssteve.reinhardt@amd.com# verify that it works 4848947Sandreas.hansson@arm.comif not conf.CheckHeader('Python.h', '<>'): 4858947Sandreas.hansson@arm.com print "Error: can't find Python.h header in", py_header_path 4867756SAli.Saidi@ARM.com Exit(1) 4878120Sgblack@eecs.umich.edu 4887756SAli.Saidi@ARM.com# add library path too if it's not in the default place 4897756SAli.Saidi@ARM.compy_lib_path = None 4907756SAli.Saidi@ARM.comif sys.exec_prefix != '/usr': 4917756SAli.Saidi@ARM.com py_lib_path = joinpath(sys.exec_prefix, 'lib') 4927816Ssteve.reinhardt@amd.comelif sys.platform == 'cygwin': 4937816Ssteve.reinhardt@amd.com # cygwin puts the .dll in /bin for some reason 4947816Ssteve.reinhardt@amd.com py_lib_path = '/bin' 4957816Ssteve.reinhardt@amd.comif py_lib_path: 4967816Ssteve.reinhardt@amd.com env.Append(LIBPATH = py_lib_path) 4977816Ssteve.reinhardt@amd.com print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 4987816Ssteve.reinhardt@amd.comif not conf.CheckLib(py_version_name): 4997816Ssteve.reinhardt@amd.com print "Error: can't find Python library", py_version_name 5007816Ssteve.reinhardt@amd.com Exit(1) 5017816Ssteve.reinhardt@amd.com 5027756SAli.Saidi@ARM.com# On Solaris you need to use libsocket for socket ops 5037756SAli.Saidi@ARM.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5049227Sandreas.hansson@arm.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 5059227Sandreas.hansson@arm.com print "Can't find library with socket calls (e.g. accept())" 5069227Sandreas.hansson@arm.com Exit(1) 5079227Sandreas.hansson@arm.com 5086654Snate@binkert.org# Check for zlib. If the check passes, libz will be automatically 5096654Snate@binkert.org# added to the LIBS environment variable. 5105871Snate@binkert.orgif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5116121Snate@binkert.org print 'Error: did not find needed zlib compression library '\ 5128946Sandreas.hansson@arm.com 'and/or zlib.h header file.' 5139419Sandreas.hansson@arm.com print ' Please install zlib and try again.' 5143940Ssaidi@eecs.umich.edu Exit(1) 5153918Ssaidi@eecs.umich.edu 5163918Ssaidi@eecs.umich.edu# Check for <fenv.h> (C99 FP environment control) 5171858SN/Ahave_fenv = conf.CheckHeader('fenv.h', '<>') 5186121Snate@binkert.orgif not have_fenv: 5199420Sandreas.hansson@arm.com print "Warning: Header file <fenv.h> not found." 5209420Sandreas.hansson@arm.com print " This host has no IEEE FP rounding mode control." 5219420Sandreas.hansson@arm.com 5229420Sandreas.hansson@arm.com# Check for mysql. 5239420Sandreas.hansson@arm.commysql_config = WhereIs('mysql_config') 5249420Sandreas.hansson@arm.comhave_mysql = mysql_config != None 5259420Sandreas.hansson@arm.com 5269420Sandreas.hansson@arm.com# Check MySQL version. 5279420Sandreas.hansson@arm.comif have_mysql: 5287739Sgblack@eecs.umich.edu mysql_version = os.popen(mysql_config + ' --version').read() 5297739Sgblack@eecs.umich.edu min_mysql_version = '4.1' 5306143Snate@binkert.org if compare_versions(mysql_version, min_mysql_version) < 0: 5319420Sandreas.hansson@arm.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 5329420Sandreas.hansson@arm.com print ' Version', mysql_version, 'detected.' 5339420Sandreas.hansson@arm.com have_mysql = False 5347618SAli.Saidi@arm.com 5357618SAli.Saidi@arm.com# Set up mysql_config commands. 5367618SAli.Saidi@arm.comif have_mysql: 5377739Sgblack@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 5389227Sandreas.hansson@arm.com if os.system(mysql_config_include + ' > /dev/null') != 0: 5399227Sandreas.hansson@arm.com # older mysql_config versions don't support --include, use 5409227Sandreas.hansson@arm.com # --cflags instead 5419227Sandreas.hansson@arm.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 5429227Sandreas.hansson@arm.com # This seems to work in all versions 5439227Sandreas.hansson@arm.com mysql_config_libs = mysql_config + ' --libs' 5449227Sandreas.hansson@arm.com 5459227Sandreas.hansson@arm.comenv = conf.Finish() 5469227Sandreas.hansson@arm.com 5479227Sandreas.hansson@arm.com# Define the universe of supported ISAs 5489227Sandreas.hansson@arm.comall_isa_list = [ ] 5499227Sandreas.hansson@arm.comExport('all_isa_list') 5509227Sandreas.hansson@arm.com 5519227Sandreas.hansson@arm.com# Define the universe of supported CPU models 5529227Sandreas.hansson@arm.comall_cpu_list = [ ] 5539227Sandreas.hansson@arm.comdefault_cpus = [ ] 5549227Sandreas.hansson@arm.comExport('all_cpu_list', 'default_cpus') 5559227Sandreas.hansson@arm.com 5568737Skoansin.tan@gmail.com# Sticky options get saved in the options file so they persist from 5579420Sandreas.hansson@arm.com# one invocation to the next (unless overridden, in which case the new 5589420Sandreas.hansson@arm.com# value becomes sticky). 5599420Sandreas.hansson@arm.comsticky_opts = Options(args=ARGUMENTS) 5608737Skoansin.tan@gmail.comExport('sticky_opts') 5618737Skoansin.tan@gmail.com 5628737Skoansin.tan@gmail.com# Non-sticky options only apply to the current build. 5638737Skoansin.tan@gmail.comnonsticky_opts = Options(args=ARGUMENTS) 5648737Skoansin.tan@gmail.comExport('nonsticky_opts') 5658737Skoansin.tan@gmail.com 5668737Skoansin.tan@gmail.com# Walk the tree and execute all SConsopts scripts that wil add to the 5678737Skoansin.tan@gmail.com# above options 5688737Skoansin.tan@gmail.comfor base_dir in base_dir_list: 5698737Skoansin.tan@gmail.com for root, dirs, files in os.walk(base_dir): 5708737Skoansin.tan@gmail.com if 'SConsopts' in files: 5718737Skoansin.tan@gmail.com print "Reading", joinpath(root, 'SConsopts') 5728737Skoansin.tan@gmail.com SConscript(joinpath(root, 'SConsopts')) 5738737Skoansin.tan@gmail.com 5748737Skoansin.tan@gmail.comall_isa_list.sort() 5758737Skoansin.tan@gmail.comall_cpu_list.sort() 5768737Skoansin.tan@gmail.comdefault_cpus.sort() 5778946Sandreas.hansson@arm.com 5788946Sandreas.hansson@arm.comsticky_opts.AddOptions( 5798946Sandreas.hansson@arm.com EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 5809420Sandreas.hansson@arm.com BoolOption('FULL_SYSTEM', 'Full-system support', False), 5819420Sandreas.hansson@arm.com # There's a bug in scons 0.96.1 that causes ListOptions with list 5829420Sandreas.hansson@arm.com # values (more than one value) not to be able to be restored from 5839420Sandreas.hansson@arm.com # a saved option file. If this causes trouble then upgrade to 5849420Sandreas.hansson@arm.com # scons 0.96.90 or later. 5859420Sandreas.hansson@arm.com ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 5869420Sandreas.hansson@arm.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 5879420Sandreas.hansson@arm.com BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 5889420Sandreas.hansson@arm.com False), 5899420Sandreas.hansson@arm.com BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 5909420Sandreas.hansson@arm.com False), 5918946Sandreas.hansson@arm.com BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 5923918Ssaidi@eecs.umich.edu False), 5939068SAli.Saidi@ARM.com BoolOption('SS_COMPATIBLE_FP', 5949068SAli.Saidi@ARM.com 'Make floating-point results compatible with SimpleScalar', 5959068SAli.Saidi@ARM.com False), 5969068SAli.Saidi@ARM.com BoolOption('USE_SSE2', 5979068SAli.Saidi@ARM.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 5989068SAli.Saidi@ARM.com False), 5999068SAli.Saidi@ARM.com BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6009068SAli.Saidi@ARM.com BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6019068SAli.Saidi@ARM.com BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 6029419Sandreas.hansson@arm.com ('PYTHONHOME', 6039068SAli.Saidi@ARM.com 'Override the default PYTHONHOME for this system (use with caution)', 6049068SAli.Saidi@ARM.com '%s:%s' % (sys.prefix, sys.exec_prefix)), 6059068SAli.Saidi@ARM.com ) 6069068SAli.Saidi@ARM.com 6079068SAli.Saidi@ARM.comnonsticky_opts.AddOptions( 6089068SAli.Saidi@ARM.com BoolOption('update_ref', 'Update test reference outputs', False) 6093918Ssaidi@eecs.umich.edu ) 6103918Ssaidi@eecs.umich.edu 6116157Snate@binkert.org# These options get exported to #defines in config/*.hh (see src/SConscript). 6126157Snate@binkert.orgenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 6136157Snate@binkert.org 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 6146157Snate@binkert.org 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 6155397Ssaidi@eecs.umich.edu 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 6165397Ssaidi@eecs.umich.edu 6176121Snate@binkert.org# Define a handy 'no-op' action 6186121Snate@binkert.orgdef no_action(target, source, env): 6196121Snate@binkert.org return 0 6206121Snate@binkert.org 6216121Snate@binkert.orgenv.NoAction = Action(no_action, None) 6226121Snate@binkert.org 6235397Ssaidi@eecs.umich.edu################################################### 6241851SN/A# 6251851SN/A# Define a SCons builder for configuration flag headers. 6267739Sgblack@eecs.umich.edu# 627955SN/A################################################### 6289396Sandreas.hansson@arm.com 6299396Sandreas.hansson@arm.com# This function generates a config header file that #defines the 6309396Sandreas.hansson@arm.com# option symbol to the current option setting (0 or 1). The source 6319396Sandreas.hansson@arm.com# operands are the name of the option and a Value node containing the 6329396Sandreas.hansson@arm.com# value of the option. 6339396Sandreas.hansson@arm.comdef build_config_file(target, source, env): 6349396Sandreas.hansson@arm.com (option, value) = [s.get_contents() for s in source] 6359396Sandreas.hansson@arm.com f = file(str(target[0]), 'w') 6369396Sandreas.hansson@arm.com print >> f, '#define', option, value 6379396Sandreas.hansson@arm.com f.close() 6389396Sandreas.hansson@arm.com return None 6399396Sandreas.hansson@arm.com 6409396Sandreas.hansson@arm.com# Generate the message to be printed when building the config file. 6419396Sandreas.hansson@arm.comdef build_config_file_string(target, source, env): 6429396Sandreas.hansson@arm.com (option, value) = [s.get_contents() for s in source] 6439396Sandreas.hansson@arm.com return "Defining %s as %s in %s." % (option, value, target[0]) 6449477Sandreas.hansson@arm.com 6459477Sandreas.hansson@arm.com# Combine the two functions into a scons Action object. 6469477Sandreas.hansson@arm.comconfig_action = Action(build_config_file, build_config_file_string) 6479477Sandreas.hansson@arm.com 6489477Sandreas.hansson@arm.com# The emitter munges the source & target node lists to reflect what 6499477Sandreas.hansson@arm.com# we're really doing. 6509477Sandreas.hansson@arm.comdef config_emitter(target, source, env): 6519477Sandreas.hansson@arm.com # extract option name from Builder arg 6529477Sandreas.hansson@arm.com option = str(target[0]) 6539477Sandreas.hansson@arm.com # True target is config header file 6549477Sandreas.hansson@arm.com target = joinpath('config', option.lower() + '.hh') 6559477Sandreas.hansson@arm.com val = env[option] 6569477Sandreas.hansson@arm.com if isinstance(val, bool): 6579477Sandreas.hansson@arm.com # Force value to 0/1 6589477Sandreas.hansson@arm.com val = int(val) 6599477Sandreas.hansson@arm.com elif isinstance(val, str): 6609477Sandreas.hansson@arm.com val = '"' + val + '"' 6619477Sandreas.hansson@arm.com 6629477Sandreas.hansson@arm.com # Sources are option name & value (packaged in SCons Value nodes) 6639477Sandreas.hansson@arm.com return ([target], [Value(option), Value(val)]) 6649477Sandreas.hansson@arm.com 6659477Sandreas.hansson@arm.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 6669396Sandreas.hansson@arm.com 6673053Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 6686121Snate@binkert.org 6693053Sstever@eecs.umich.edu################################################### 6703053Sstever@eecs.umich.edu# 6713053Sstever@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 6723053Sstever@eecs.umich.edu# Python zipfile code in src/python/SConscript, but is placed up here 6733053Sstever@eecs.umich.edu# since it's potentially more generally applicable. 6749072Sandreas.hansson@arm.com# 6753053Sstever@eecs.umich.edu################################################### 6764742Sstever@eecs.umich.edu 6774742Sstever@eecs.umich.educopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 6783053Sstever@eecs.umich.edu 6793053Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 6803053Sstever@eecs.umich.edu 6818960Ssteve.reinhardt@amd.com################################################### 6826654Snate@binkert.org# 6833053Sstever@eecs.umich.edu# Define a simple SCons builder to concatenate files. 6843053Sstever@eecs.umich.edu# 6853053Sstever@eecs.umich.edu# Used to append the Python zip archive to the executable. 6863053Sstever@eecs.umich.edu# 6872667Sstever@eecs.umich.edu################################################### 6884554Sbinkertn@umich.edu 6896121Snate@binkert.orgconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 6902667Sstever@eecs.umich.edu 'chmod +x $TARGET'])) 6914554Sbinkertn@umich.edu 6924554Sbinkertn@umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder }) 6934554Sbinkertn@umich.edu 6946121Snate@binkert.org 6954554Sbinkertn@umich.edu# libelf build is shared across all configs in the build root. 6964554Sbinkertn@umich.eduenv.SConscript('ext/libelf/SConscript', 6974554Sbinkertn@umich.edu build_dir = joinpath(build_root, 'libelf'), 6984781Snate@binkert.org exports = 'env') 6994554Sbinkertn@umich.edu 7004554Sbinkertn@umich.edu################################################### 7012667Sstever@eecs.umich.edu# 7024554Sbinkertn@umich.edu# This function is used to set up a directory with switching headers 7034554Sbinkertn@umich.edu# 7044554Sbinkertn@umich.edu################################################### 7054554Sbinkertn@umich.edu 7062667Sstever@eecs.umich.eduenv['ALL_ISA_LIST'] = all_isa_list 7074554Sbinkertn@umich.edudef make_switching_dir(dirname, switch_headers, env): 7082667Sstever@eecs.umich.edu # Generate the header. target[0] is the full path of the output 7094554Sbinkertn@umich.edu # header to generate. 'source' is a dummy variable, since we get the 7106121Snate@binkert.org # list of ISAs from env['ALL_ISA_LIST']. 7112667Sstever@eecs.umich.edu def gen_switch_hdr(target, source, env): 7125522Snate@binkert.org fname = str(target[0]) 7135522Snate@binkert.org basename = os.path.basename(fname) 7145522Snate@binkert.org f = open(fname, 'w') 7155522Snate@binkert.org f.write('#include "arch/isa_specific.hh"\n') 7165522Snate@binkert.org cond = '#if' 7175522Snate@binkert.org for isa in all_isa_list: 7185522Snate@binkert.org f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 7195522Snate@binkert.org % (cond, isa.upper(), dirname, isa, basename)) 7205522Snate@binkert.org cond = '#elif' 7215522Snate@binkert.org f.write('#else\n#error "THE_ISA not set"\n#endif\n') 7225522Snate@binkert.org f.close() 7235522Snate@binkert.org return 0 7245522Snate@binkert.org 7255522Snate@binkert.org # String to print when generating header 7265522Snate@binkert.org def gen_switch_hdr_string(target, source, env): 7275522Snate@binkert.org return "Generating switch header " + str(target[0]) 7285522Snate@binkert.org 7295522Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 7305522Snate@binkert.org # action depends on; when env['ALL_ISA_LIST'] changes these actions 7315522Snate@binkert.org # should get re-executed. 7325522Snate@binkert.org switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 7335522Snate@binkert.org varlist=['ALL_ISA_LIST']) 7345522Snate@binkert.org 7355522Snate@binkert.org # Instantiate actions for each header 7365522Snate@binkert.org for hdr in switch_headers: 7375522Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 7382638Sstever@eecs.umich.eduExport('make_switching_dir') 7392638Sstever@eecs.umich.edu 7406121Snate@binkert.org################################################### 7413716Sstever@eecs.umich.edu# 7425522Snate@binkert.org# Define build environments for selected configurations. 7439420Sandreas.hansson@arm.com# 7445522Snate@binkert.org################################################### 7455522Snate@binkert.org 7465522Snate@binkert.org# rename base env 7475522Snate@binkert.orgbase_env = env 7481858SN/A 7495227Ssaidi@eecs.umich.edufor build_path in build_paths: 7505227Ssaidi@eecs.umich.edu print "Building in", build_path 7515227Ssaidi@eecs.umich.edu 7525227Ssaidi@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 7536654Snate@binkert.org env = base_env.Copy() 7546654Snate@binkert.org env['BUILDDIR'] = build_path 7557769SAli.Saidi@ARM.com 7567769SAli.Saidi@ARM.com # build_dir is the tail component of build path, and is used to 7577769SAli.Saidi@ARM.com # determine the build parameters (e.g., 'ALPHA_SE') 7587769SAli.Saidi@ARM.com (build_root, build_dir) = os.path.split(build_path) 7595227Ssaidi@eecs.umich.edu 7605227Ssaidi@eecs.umich.edu # Set env options according to the build directory config. 7615227Ssaidi@eecs.umich.edu sticky_opts.files = [] 7625204Sstever@gmail.com # Options for $BUILD_ROOT/$BUILD_DIR are stored in 7635204Sstever@gmail.com # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 7645204Sstever@gmail.com # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 7655204Sstever@gmail.com current_opts_file = joinpath(build_root, 'options', build_dir) 7665204Sstever@gmail.com if isfile(current_opts_file): 7675204Sstever@gmail.com sticky_opts.files.append(current_opts_file) 7685204Sstever@gmail.com print "Using saved options file %s" % current_opts_file 7695204Sstever@gmail.com else: 7705204Sstever@gmail.com # Build dir-specific options file doesn't exist. 7715204Sstever@gmail.com 7725204Sstever@gmail.com # Make sure the directory is there so we can create it later 7735204Sstever@gmail.com opt_dir = os.path.dirname(current_opts_file) 7745204Sstever@gmail.com if not isdir(opt_dir): 7755204Sstever@gmail.com os.mkdir(opt_dir) 7765204Sstever@gmail.com 7775204Sstever@gmail.com # Get default build options from source tree. Options are 7785204Sstever@gmail.com # normally determined by name of $BUILD_DIR, but can be 7796121Snate@binkert.org # overriden by 'default=' arg on command line. 7805204Sstever@gmail.com default_opts_file = joinpath('build_opts', 7813118Sstever@eecs.umich.edu ARGUMENTS.get('default', build_dir)) 7823118Sstever@eecs.umich.edu if isfile(default_opts_file): 7833118Sstever@eecs.umich.edu sticky_opts.files.append(default_opts_file) 7843118Sstever@eecs.umich.edu print "Options file %s not found,\n using defaults in %s" \ 7853118Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 7865863Snate@binkert.org else: 7873118Sstever@eecs.umich.edu print "Error: cannot find options file %s or %s" \ 7885863Snate@binkert.org % (current_opts_file, default_opts_file) 7893118Sstever@eecs.umich.edu Exit(1) 7907457Snate@binkert.org 7917457Snate@binkert.org # Apply current option settings to env 7925863Snate@binkert.org sticky_opts.Update(env) 7935863Snate@binkert.org nonsticky_opts.Update(env) 7945863Snate@binkert.org 7955863Snate@binkert.org help_text += "\nSticky options for %s:\n" % build_dir \ 7965863Snate@binkert.org + sticky_opts.GenerateHelpText(env) \ 7975863Snate@binkert.org + "\nNon-sticky options for %s:\n" % build_dir \ 7985863Snate@binkert.org + nonsticky_opts.GenerateHelpText(env) 7996003Snate@binkert.org 8005863Snate@binkert.org # Process option settings. 8015863Snate@binkert.org 8025863Snate@binkert.org if not have_fenv and env['USE_FENV']: 8036120Snate@binkert.org print "Warning: <fenv.h> not available; " \ 8045863Snate@binkert.org "forcing USE_FENV to False in", build_dir + "." 8055863Snate@binkert.org env['USE_FENV'] = False 8065863Snate@binkert.org 8078655Sandreas.hansson@arm.com if not env['USE_FENV']: 8088655Sandreas.hansson@arm.com print "Warning: No IEEE FP rounding mode control in", build_dir + "." 8098655Sandreas.hansson@arm.com print " FP results may deviate slightly from other platforms." 8108655Sandreas.hansson@arm.com 8118655Sandreas.hansson@arm.com if env['EFENCE']: 8128655Sandreas.hansson@arm.com env.Append(LIBS=['efence']) 8138655Sandreas.hansson@arm.com 8148655Sandreas.hansson@arm.com if env['USE_MYSQL']: 8156120Snate@binkert.org if not have_mysql: 8165863Snate@binkert.org print "Warning: MySQL not available; " \ 8176121Snate@binkert.org "forcing USE_MYSQL to False in", build_dir + "." 8186121Snate@binkert.org env['USE_MYSQL'] = False 8195863Snate@binkert.org else: 8207727SAli.Saidi@ARM.com print "Compiling in", build_dir, "with MySQL support." 8217727SAli.Saidi@ARM.com env.ParseConfig(mysql_config_libs) 8227727SAli.Saidi@ARM.com env.ParseConfig(mysql_config_include) 8237727SAli.Saidi@ARM.com 8247727SAli.Saidi@ARM.com # Save sticky option settings back to current options file 8257727SAli.Saidi@ARM.com sticky_opts.Save(current_opts_file, env) 8265863Snate@binkert.org 8273118Sstever@eecs.umich.edu if env['USE_SSE2']: 8285863Snate@binkert.org env.Append(CCFLAGS='-msse2') 8299239Sandreas.hansson@arm.com 8303118Sstever@eecs.umich.edu # The src/SConscript file sets up the build rules in 'env' according 8313118Sstever@eecs.umich.edu # to the configured options. It returns a list of environments, 8325863Snate@binkert.org # one for each variant build (debug, opt, etc.) 8335863Snate@binkert.org envList = SConscript('src/SConscript', build_dir = build_path, 8345863Snate@binkert.org exports = 'env') 8355863Snate@binkert.org 8363118Sstever@eecs.umich.edu # Set up the regression tests for each build. 8373483Ssaidi@eecs.umich.edu for e in envList: 8383494Ssaidi@eecs.umich.edu SConscript('tests/SConscript', 8393494Ssaidi@eecs.umich.edu build_dir = joinpath(build_path, 'tests', e.Label), 8403483Ssaidi@eecs.umich.edu exports = { 'env' : e }, duplicate = False) 8413483Ssaidi@eecs.umich.edu 8423483Ssaidi@eecs.umich.eduHelp(help_text) 8433053Sstever@eecs.umich.edu 8443053Sstever@eecs.umich.edu 8453918Ssaidi@eecs.umich.edu################################################### 8463053Sstever@eecs.umich.edu# 8473053Sstever@eecs.umich.edu# Let SCons do its thing. At this point SCons will use the defined 8483053Sstever@eecs.umich.edu# build environments to build the requested targets. 8493053Sstever@eecs.umich.edu# 8503053Sstever@eecs.umich.edu################################################### 8519396Sandreas.hansson@arm.com 8529396Sandreas.hansson@arm.com