SConstruct revision 5397
1955SN/A# -*- mode:python -*- 2955SN/A 312230Sgiacomo.travaglini@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan 49812Sandreas.hansson@arm.com# All rights reserved. 59812Sandreas.hansson@arm.com# 69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without 79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are 89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright 99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer; 109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright 119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the 129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution; 139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its 149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from 157816Ssteve.reinhardt@amd.com# this software without specific prior written permission. 165871Snate@binkert.org# 171762SN/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 30955SN/A 31955SN/A################################################### 32955SN/A# 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 38955SN/A# the optimized full-system version). 39955SN/A# 40955SN/A# You can build M5 in a different directory as long as there is a 41955SN/A# 'build/<CONFIG>' somewhere along the target path. The build system 422665Ssaidi@eecs.umich.edu# expects that all configs under the same build directory are being 432665Ssaidi@eecs.umich.edu# built for the same host system. 445863Snate@binkert.org# 45955SN/A# Examples: 46955SN/A# 47955SN/A# The following two commands are equivalent. The '-u' option tells 48955SN/A# scons to search up the directory tree for this SConstruct file. 49955SN/A# % cd <path-to-src>/m5 ; scons build/ALPHA_FS/m5.debug 508878Ssteve.reinhardt@amd.com# % cd <path-to-src>/m5/build/ALPHA_FS; scons -u m5.debug 512632Sstever@eecs.umich.edu# 528878Ssteve.reinhardt@amd.com# The following two commands are equivalent and demonstrate building 532632Sstever@eecs.umich.edu# in a directory outside of the source tree. The '-C' option tells 54955SN/A# scons to chdir to the specified directory to find this SConstruct 558878Ssteve.reinhardt@amd.com# file. 562632Sstever@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 582632Sstever@eecs.umich.edu# 592632Sstever@eecs.umich.edu# You can use 'scons -H' to print scons options. If you're in this 602632Sstever@eecs.umich.edu# 'm5' directory (or use -u or -C to tell scons where to find this 612761Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 622761Sstever@eecs.umich.edu# options as well. 632761Sstever@eecs.umich.edu# 648878Ssteve.reinhardt@amd.com################################################### 658878Ssteve.reinhardt@amd.com 662761Sstever@eecs.umich.eduimport sys 672761Sstever@eecs.umich.eduimport os 682761Sstever@eecs.umich.eduimport re 692761Sstever@eecs.umich.edu 702761Sstever@eecs.umich.edufrom os.path import isdir, isfile, join as joinpath 718878Ssteve.reinhardt@amd.com 728878Ssteve.reinhardt@amd.comimport SCons 732632Sstever@eecs.umich.edu 742632Sstever@eecs.umich.edu# Check for recent-enough Python and SCons versions. If your system's 758878Ssteve.reinhardt@amd.com# default installation of Python is not recent enough, you can use a 768878Ssteve.reinhardt@amd.com# non-default installation of the Python interpreter by either (1) 772632Sstever@eecs.umich.edu# rearranging your PATH so that scons finds the non-default 'python' 78955SN/A# first or (2) explicitly invoking an alternative interpreter on the 79955SN/A# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 80955SN/AEnsurePythonVersion(2,4) 8112563Sgabeblack@google.com 8212563Sgabeblack@google.com# Import subprocess after we check the version since it doesn't exist in 836654Snate@binkert.org# Python < 2.4. 8410196SCurtis.Dunham@arm.comimport subprocess 85955SN/A 865396Ssaidi@eecs.umich.edu# helper function: compare arrays or strings of version numbers. 8711401Sandreas.sandberg@arm.com# 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): 904202Sbinkertn@umich.edu 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('.')) 9513541Sandrea.mondelli@ucf.edu else: 96955SN/A raise TypeError 976654Snate@binkert.org 985273Sstever@gmail.com v1 = make_version_list(v1) 995871Snate@binkert.org v2 = make_version_list(v2) 1005273Sstever@gmail.com # Compare corresponding elements of lists 1016654Snate@binkert.org for n1,n2 in zip(v1, v2): 1025396Ssaidi@eecs.umich.edu if n1 < n2: return -1 1038120Sgblack@eecs.umich.edu if n1 > n2: return 1 1048120Sgblack@eecs.umich.edu # all corresponding values are equal... see if one has extra values 1058120Sgblack@eecs.umich.edu if len(v1) < len(v2): return -1 1068120Sgblack@eecs.umich.edu if len(v1) > len(v2): return 1 1078120Sgblack@eecs.umich.edu return 0 1088120Sgblack@eecs.umich.edu 1098120Sgblack@eecs.umich.edu# SCons version numbers need special processing because they can have 1108120Sgblack@eecs.umich.edu# charecters and an release date embedded in them. This function does 1118879Ssteve.reinhardt@amd.com# the magic to extract them in a similar way to the SCons internal function 1128879Ssteve.reinhardt@amd.com# function does and then checks that the current version is not contained in 1138879Ssteve.reinhardt@amd.com# a list of version tuples (bad_ver_strs) 1148879Ssteve.reinhardt@amd.comdef CheckSCons(bad_ver_strs): 1158879Ssteve.reinhardt@amd.com def scons_ver(v): 1168879Ssteve.reinhardt@amd.com num_parts = v.split(' ')[0].split('.') 1178879Ssteve.reinhardt@amd.com major = int(num_parts[0]) 1188879Ssteve.reinhardt@amd.com minor = int(re.match('\d+', num_parts[1]).group()) 1198879Ssteve.reinhardt@amd.com rev = 0 1208879Ssteve.reinhardt@amd.com rdate = 0 1218879Ssteve.reinhardt@amd.com if len(num_parts) > 2: 1228879Ssteve.reinhardt@amd.com try: rev = int(re.match('\d+', num_parts[2]).group()) 1238879Ssteve.reinhardt@amd.com except: pass 1248120Sgblack@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])) 1338120Sgblack@eecs.umich.edu if compare_versions(sc_ver, bv[0]) != -1 and\ 1348120Sgblack@eecs.umich.edu compare_versions(sc_ver, bv[1]) != 1: 1358120Sgblack@eecs.umich.edu print "The version of SCons that you have installed: ", SCons.__version__ 1368120Sgblack@eecs.umich.edu print "has a bug that prevents it from working correctly with M5." 1378120Sgblack@eecs.umich.edu 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) 14210458Sandreas.hansson@arm.com 14310458Sandreas.hansson@arm.comCheckSCons(( 14410458Sandreas.hansson@arm.com # We need a version that is 0.96.91 or newer 1458879Ssteve.reinhardt@amd.com ('0.0.0', '0.96.90'), 1468879Ssteve.reinhardt@amd.com # This range has a bug with linking directories into the build dir 1478879Ssteve.reinhardt@amd.com # that only have header files in them 1488879Ssteve.reinhardt@amd.com ('0.97.0d20071212', '0.98.0') 14913421Sciro.santilli@arm.com )) 15013421Sciro.santilli@arm.com 1519227Sandreas.hansson@arm.com 1529227Sandreas.hansson@arm.com# The absolute path to the current directory (where this file lives). 15312063Sgabeblack@google.comROOT = Dir('.').abspath 15412063Sgabeblack@google.com 15512063Sgabeblack@google.com# Path to the M5 source tree. 1568879Ssteve.reinhardt@amd.comSRCDIR = joinpath(ROOT, 'src') 1578879Ssteve.reinhardt@amd.com 1588879Ssteve.reinhardt@amd.com# tell python where to find m5 python code 1598879Ssteve.reinhardt@amd.comsys.path.append(joinpath(ROOT, 'src/python')) 16010453SAndrew.Bardsley@arm.com 16110453SAndrew.Bardsley@arm.comdef check_style_hook(ui): 16210453SAndrew.Bardsley@arm.com ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 16310456SCurtis.Dunham@arm.com style_hook = ui.config('hooks', 'pretxncommit.style', None) 16410456SCurtis.Dunham@arm.com 16510456SCurtis.Dunham@arm.com if not style_hook: 16610457Sandreas.hansson@arm.com print """\ 16710457Sandreas.hansson@arm.comYou're missing the M5 style hook. 16811342Sandreas.hansson@arm.comPlease install the hook so we can ensure that all code fits a common style. 16911342Sandreas.hansson@arm.com 1708120Sgblack@eecs.umich.eduAll you'd need to do is add the following lines to your repository .hg/hgrc 17112063Sgabeblack@google.comor your personal .hgrc 17212563Sgabeblack@google.com---------------- 17312063Sgabeblack@google.com 17412063Sgabeblack@google.com[extensions] 1755871Snate@binkert.orgstyle = %s/util/style.py 1765871Snate@binkert.org 1776121Snate@binkert.org[hooks] 1785871Snate@binkert.orgpretxncommit.style = python:style.check_whitespace 1795871Snate@binkert.org""" % (ROOT) 1809926Sstan.czerniawski@arm.com sys.exit(1) 18112243Sgabeblack@google.com 1821533SN/Aif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 18312246Sgabeblack@google.com try: 18412246Sgabeblack@google.com from mercurial import ui 18512246Sgabeblack@google.com check_style_hook(ui.ui()) 18612246Sgabeblack@google.com except ImportError: 1879239Sandreas.hansson@arm.com pass 1889239Sandreas.hansson@arm.com 1899239Sandreas.hansson@arm.com################################################### 1909239Sandreas.hansson@arm.com# 19112563Sgabeblack@google.com# Figure out which configurations to set up based on the path(s) of 1929239Sandreas.hansson@arm.com# the target(s). 1939239Sandreas.hansson@arm.com# 194955SN/A################################################### 195955SN/A 1962632Sstever@eecs.umich.edu# Find default configuration & binary. 1972632Sstever@eecs.umich.eduDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 198955SN/A 199955SN/A# helper function: find last occurrence of element in list 200955SN/Adef rfind(l, elt, offs = -1): 201955SN/A for i in range(len(l)+offs, 0, -1): 2028878Ssteve.reinhardt@amd.com if l[i] == elt: 203955SN/A return i 2042632Sstever@eecs.umich.edu raise ValueError, "element not found" 2052632Sstever@eecs.umich.edu 2062632Sstever@eecs.umich.edu# Each target must have 'build' in the interior of the path; the 2072632Sstever@eecs.umich.edu# directory below this will determine the build parameters. For 2082632Sstever@eecs.umich.edu# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2092632Sstever@eecs.umich.edu# recognize that ALPHA_SE specifies the configuration because it 2102632Sstever@eecs.umich.edu# follow 'build' in the bulid path. 2118268Ssteve.reinhardt@amd.com 2128268Ssteve.reinhardt@amd.com# Generate absolute paths to targets so we can see where the build dir is 2138268Ssteve.reinhardt@amd.comif COMMAND_LINE_TARGETS: 2148268Ssteve.reinhardt@amd.com # Ask SCons which directory it was invoked from 2158268Ssteve.reinhardt@amd.com launch_dir = GetLaunchDir() 2168268Ssteve.reinhardt@amd.com # Make targets relative to invocation directory 2178268Ssteve.reinhardt@amd.com abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 2182632Sstever@eecs.umich.edu COMMAND_LINE_TARGETS) 2192632Sstever@eecs.umich.eduelse: 2202632Sstever@eecs.umich.edu # Default targets are relative to root of tree 2212632Sstever@eecs.umich.edu abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 2228268Ssteve.reinhardt@amd.com DEFAULT_TARGETS) 2232632Sstever@eecs.umich.edu 2248268Ssteve.reinhardt@amd.com 2258268Ssteve.reinhardt@amd.com# Generate a list of the unique build roots and configs that the 2268268Ssteve.reinhardt@amd.com# collected targets reference. 2278268Ssteve.reinhardt@amd.combuild_paths = [] 2283718Sstever@eecs.umich.edubuild_root = None 2292634Sstever@eecs.umich.edufor t in abs_targets: 2302634Sstever@eecs.umich.edu path_dirs = t.split('/') 2315863Snate@binkert.org try: 2322638Sstever@eecs.umich.edu build_top = rfind(path_dirs, 'build', -2) 2338268Ssteve.reinhardt@amd.com except: 2342632Sstever@eecs.umich.edu print "Error: no non-leaf 'build' dir found on target path", t 2352632Sstever@eecs.umich.edu Exit(1) 2362632Sstever@eecs.umich.edu this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2372632Sstever@eecs.umich.edu if not build_root: 23812563Sgabeblack@google.com build_root = this_build_root 2391858SN/A else: 2403716Sstever@eecs.umich.edu if this_build_root != build_root: 2412638Sstever@eecs.umich.edu print "Error: build targets not under same build root\n"\ 2422638Sstever@eecs.umich.edu " %s\n %s" % (build_root, this_build_root) 2432638Sstever@eecs.umich.edu Exit(1) 2442638Sstever@eecs.umich.edu build_path = joinpath('/',*path_dirs[:build_top+2]) 24512563Sgabeblack@google.com if build_path not in build_paths: 24612563Sgabeblack@google.com build_paths.append(build_path) 2472638Sstever@eecs.umich.edu 2485863Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 2495863Snate@binkert.orgif not isdir(build_root): 2505863Snate@binkert.org os.mkdir(build_root) 251955SN/A 2525341Sstever@gmail.com################################################### 2535341Sstever@gmail.com# 2545863Snate@binkert.org# Set up the default build environment. This environment is copied 2557756SAli.Saidi@ARM.com# and modified according to each selected configuration. 2565341Sstever@gmail.com# 2576121Snate@binkert.org################################################### 2584494Ssaidi@eecs.umich.edu 2596121Snate@binkert.orgenv = Environment(ENV = os.environ, # inherit user's environment vars 2601105SN/A ROOT = ROOT, 2612667Sstever@eecs.umich.edu SRCDIR = SRCDIR) 2622667Sstever@eecs.umich.edu 2632667Sstever@eecs.umich.eduExport('env') 2642667Sstever@eecs.umich.edu 2656121Snate@binkert.orgenv.SConsignFile(joinpath(build_root,"sconsign")) 2662667Sstever@eecs.umich.edu 2675341Sstever@gmail.com# Default duplicate option is to use hard links, but this messes up 2685863Snate@binkert.org# when you use emacs to edit a file in the target dir, as emacs moves 2695341Sstever@gmail.com# file to file~ then copies to file, breaking the link. Symbolic 2705341Sstever@gmail.com# (soft) links work better. 2715341Sstever@gmail.comenv.SetOption('duplicate', 'soft-copy') 2728120Sgblack@eecs.umich.edu 2735341Sstever@gmail.com# I waffle on this setting... it does avoid a few painful but 2748120Sgblack@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 2755341Sstever@gmail.com# noticeably longer. 2768120Sgblack@eecs.umich.eduif False: 2776121Snate@binkert.org env.TargetSignatures('content') 2786121Snate@binkert.org 2799396Sandreas.hansson@arm.com# 2805397Ssaidi@eecs.umich.edu# Set up global sticky options... these are common to an entire build 2815397Ssaidi@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 2827727SAli.Saidi@ARM.com# 2838268Ssteve.reinhardt@amd.com 2846168Snate@binkert.org# Option validators & converters for global sticky options 2855341Sstever@gmail.comdef PathListMakeAbsolute(val): 2868120Sgblack@eecs.umich.edu if not val: 2878120Sgblack@eecs.umich.edu return val 2888120Sgblack@eecs.umich.edu f = lambda p: os.path.abspath(os.path.expanduser(p)) 2896814Sgblack@eecs.umich.edu return ':'.join(map(f, val.split(':'))) 2905863Snate@binkert.org 2918120Sgblack@eecs.umich.edudef PathListAllExist(key, val, env): 2925341Sstever@gmail.com if not val: 2935863Snate@binkert.org return 2948268Ssteve.reinhardt@amd.com paths = val.split(':') 2956121Snate@binkert.org for path in paths: 2966121Snate@binkert.org if not isdir(path): 2978268Ssteve.reinhardt@amd.com raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 2985742Snate@binkert.org 2995742Snate@binkert.orgglobal_sticky_opts_file = joinpath(build_root, 'options.global') 3005341Sstever@gmail.com 3015742Snate@binkert.orgglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS) 3025742Snate@binkert.org 3035341Sstever@gmail.comglobal_sticky_opts.AddOptions( 3046017Snate@binkert.org ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3056121Snate@binkert.org ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3066017Snate@binkert.org ('BATCH', 'Use batch pool for build and tests', False), 30712158Sandreas.sandberg@arm.com ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 30812158Sandreas.sandberg@arm.com ('EXTRAS', 'Add Extra directories to the compilation', '', 30912158Sandreas.sandberg@arm.com PathListAllExist, PathListMakeAbsolute) 3108120Sgblack@eecs.umich.edu ) 3117756SAli.Saidi@ARM.com 3127756SAli.Saidi@ARM.com 3137756SAli.Saidi@ARM.com# base help text 3147756SAli.Saidi@ARM.comhelp_text = ''' 3157816Ssteve.reinhardt@amd.comUsage: scons [scons options] [build options] [target(s)] 3167816Ssteve.reinhardt@amd.com 3177816Ssteve.reinhardt@amd.com''' 3187816Ssteve.reinhardt@amd.com 3197816Ssteve.reinhardt@amd.comhelp_text += "Global sticky options:\n" \ 32011979Sgabeblack@google.com + global_sticky_opts.GenerateHelpText(env) 3217816Ssteve.reinhardt@amd.com 3227816Ssteve.reinhardt@amd.com# Update env with values from ARGUMENTS & file global_sticky_opts_file 3237816Ssteve.reinhardt@amd.comglobal_sticky_opts.Update(env) 3247816Ssteve.reinhardt@amd.com 3257756SAli.Saidi@ARM.com# Save sticky option settings back to current options file 3267756SAli.Saidi@ARM.comglobal_sticky_opts.Save(global_sticky_opts_file, env) 3279227Sandreas.hansson@arm.com 3289227Sandreas.hansson@arm.com# Parse EXTRAS option to build list of all directories where we're 3299227Sandreas.hansson@arm.com# look for sources etc. This list is exported as base_dir_list. 3309227Sandreas.hansson@arm.combase_dir_list = [joinpath(ROOT, 'src')] 3319590Sandreas@sandberg.pp.seif env['EXTRAS']: 3329590Sandreas@sandberg.pp.se base_dir_list += env['EXTRAS'].split(':') 3339590Sandreas@sandberg.pp.se 3349590Sandreas@sandberg.pp.seExport('base_dir_list') 3359590Sandreas@sandberg.pp.se 3369590Sandreas@sandberg.pp.se# M5_PLY is used by isa_parser.py to find the PLY package. 3376654Snate@binkert.orgenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 3386654Snate@binkert.orgenv['GCC'] = False 3395871Snate@binkert.orgenv['SUNCC'] = False 3406121Snate@binkert.orgenv['ICC'] = False 3418946Sandreas.hansson@arm.comenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 3429419Sandreas.hansson@arm.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 34312563Sgabeblack@google.com close_fds=True).communicate()[0].find('GCC') >= 0 3443918Ssaidi@eecs.umich.eduenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3453918Ssaidi@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3461858SN/A close_fds=True).communicate()[0].find('Sun C++') >= 0 3479556Sandreas.hansson@arm.comenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3489556Sandreas.hansson@arm.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3499556Sandreas.hansson@arm.com close_fds=True).communicate()[0].find('Intel') >= 0 3509556Sandreas.hansson@arm.comif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 35111294Sandreas.hansson@arm.com print 'Error: How can we have two at the same time?' 35211294Sandreas.hansson@arm.com Exit(1) 35311294Sandreas.hansson@arm.com 35411294Sandreas.hansson@arm.com 35510878Sandreas.hansson@arm.com# Set up default C++ compiler flags 35610878Sandreas.hansson@arm.comif env['GCC']: 35711811Sbaz21@cam.ac.uk env.Append(CCFLAGS='-pipe') 35811811Sbaz21@cam.ac.uk env.Append(CCFLAGS='-fno-strict-aliasing') 35911811Sbaz21@cam.ac.uk env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 36011982Sgabeblack@google.comelif env['ICC']: 36111982Sgabeblack@google.com pass #Fix me... add warning flags once we clean up icc warnings 36211982Sgabeblack@google.comelif env['SUNCC']: 36313421Sciro.santilli@arm.com env.Append(CCFLAGS='-Qoption ccfe') 36413421Sciro.santilli@arm.com env.Append(CCFLAGS='-features=gcc') 36511982Sgabeblack@google.com env.Append(CCFLAGS='-features=extensions') 36611992Sgabeblack@google.com env.Append(CCFLAGS='-library=stlport4') 36711982Sgabeblack@google.com env.Append(CCFLAGS='-xar') 36811982Sgabeblack@google.com# env.Append(CCFLAGS='-instances=semiexplicit') 36912305Sgabeblack@google.comelse: 37012305Sgabeblack@google.com print 'Error: Don\'t know what compiler options to use for your compiler.' 37112305Sgabeblack@google.com print ' Please fix SConstruct and src/SConscript and try again.' 37212305Sgabeblack@google.com Exit(1) 37312305Sgabeblack@google.com 37412305Sgabeblack@google.com# Do this after we save setting back, or else we'll tack on an 37512305Sgabeblack@google.com# extra 'qdo' every time we run scons. 3769556Sandreas.hansson@arm.comif env['BATCH']: 37712563Sgabeblack@google.com env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 37812563Sgabeblack@google.com env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 37912563Sgabeblack@google.com 38012563Sgabeblack@google.comif sys.platform == 'cygwin': 3819556Sandreas.hansson@arm.com # cygwin has some header file issues... 38212563Sgabeblack@google.com env.Append(CCFLAGS=Split("-Wno-uninitialized")) 38312563Sgabeblack@google.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 3849556Sandreas.hansson@arm.com 38512563Sgabeblack@google.com# Check for SWIG 38612563Sgabeblack@google.comif not env.has_key('SWIG'): 38712563Sgabeblack@google.com print 'Error: SWIG utility not found.' 38812563Sgabeblack@google.com print ' Please install (see http://www.swig.org) and retry.' 38912563Sgabeblack@google.com Exit(1) 39012563Sgabeblack@google.com 39112563Sgabeblack@google.com# Check for appropriate SWIG version 39212563Sgabeblack@google.comswig_version = os.popen('swig -version').read().split() 3939556Sandreas.hansson@arm.com# First 3 words should be "SWIG Version x.y.z" 3949556Sandreas.hansson@arm.comif len(swig_version) < 3 or \ 3956121Snate@binkert.org swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 39611500Sandreas.hansson@arm.com print 'Error determining SWIG version.' 39710238Sandreas.hansson@arm.com Exit(1) 39810878Sandreas.hansson@arm.com 3999420Sandreas.hansson@arm.commin_swig_version = '1.3.28' 40011500Sandreas.hansson@arm.comif compare_versions(swig_version[2], min_swig_version) < 0: 40112563Sgabeblack@google.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 40212563Sgabeblack@google.com print ' Installed version:', swig_version[2] 4039420Sandreas.hansson@arm.com Exit(1) 4049420Sandreas.hansson@arm.com 4059420Sandreas.hansson@arm.com# Set up SWIG flags & scanner 4069420Sandreas.hansson@arm.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 40712063Sgabeblack@google.comenv.Append(SWIGFLAGS=swig_flags) 40812063Sgabeblack@google.com 40912063Sgabeblack@google.com# filter out all existing swig scanners, they mess up the dependency 41012063Sgabeblack@google.com# stuff for some reason 41112063Sgabeblack@google.comscanners = [] 41212063Sgabeblack@google.comfor scanner in env['SCANNERS']: 41312063Sgabeblack@google.com skeys = scanner.skeys 41412063Sgabeblack@google.com if skeys == '.i': 41512063Sgabeblack@google.com continue 41612063Sgabeblack@google.com 41712063Sgabeblack@google.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 41812063Sgabeblack@google.com continue 41912063Sgabeblack@google.com 42012063Sgabeblack@google.com scanners.append(scanner) 42112063Sgabeblack@google.com 42212063Sgabeblack@google.com# add the new swig scanner that we like better 42312063Sgabeblack@google.comfrom SCons.Scanner import ClassicCPP as CPPScanner 42412063Sgabeblack@google.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 42512063Sgabeblack@google.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 42612063Sgabeblack@google.com 42712063Sgabeblack@google.com# replace the scanners list that has what we want 42812063Sgabeblack@google.comenv['SCANNERS'] = scanners 42910457Sandreas.hansson@arm.com 43010457Sandreas.hansson@arm.com# Platform-specific configuration. Note again that we assume that all 43110457Sandreas.hansson@arm.com# builds under a given build root run on the same host platform. 43210457Sandreas.hansson@arm.comconf = Configure(env, 43310457Sandreas.hansson@arm.com conf_dir = joinpath(build_root, '.scons_config'), 43412563Sgabeblack@google.com log_file = joinpath(build_root, 'scons_config.log')) 43512563Sgabeblack@google.com 43612563Sgabeblack@google.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 43710457Sandreas.hansson@arm.comtry: 43812063Sgabeblack@google.com import platform 43912063Sgabeblack@google.com uname = platform.uname() 44012063Sgabeblack@google.com if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 44112563Sgabeblack@google.com if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 44212563Sgabeblack@google.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 44312563Sgabeblack@google.com close_fds=True).communicate()[0][0]): 44412563Sgabeblack@google.com env.Append(CCFLAGS='-arch x86_64') 44512563Sgabeblack@google.com env.Append(CFLAGS='-arch x86_64') 44612563Sgabeblack@google.com env.Append(LINKFLAGS='-arch x86_64') 44712063Sgabeblack@google.com env.Append(ASFLAGS='-arch x86_64') 44812063Sgabeblack@google.comexcept: 44910238Sandreas.hansson@arm.com pass 45010238Sandreas.hansson@arm.com 45110238Sandreas.hansson@arm.com# Recent versions of scons substitute a "Null" object for Configure() 45212063Sgabeblack@google.com# when configuration isn't necessary, e.g., if the "--help" option is 45310238Sandreas.hansson@arm.com# present. Unfortuantely this Null object always returns false, 45410238Sandreas.hansson@arm.com# breaking all our configuration checks. We replace it with our own 45510416Sandreas.hansson@arm.com# more optimistic null object that returns True instead. 45610238Sandreas.hansson@arm.comif not conf: 4579227Sandreas.hansson@arm.com def NullCheck(*args, **kwargs): 45810238Sandreas.hansson@arm.com return True 45910416Sandreas.hansson@arm.com 46010416Sandreas.hansson@arm.com class NullConf: 4619227Sandreas.hansson@arm.com def __init__(self, env): 4629590Sandreas@sandberg.pp.se self.env = env 4639590Sandreas@sandberg.pp.se def Finish(self): 4649590Sandreas@sandberg.pp.se return self.env 46512304Sgabeblack@google.com def __getattr__(self, mname): 46612304Sgabeblack@google.com return NullCheck 46712304Sgabeblack@google.com 46812688Sgiacomo.travaglini@arm.com conf = NullConf(env) 46912688Sgiacomo.travaglini@arm.com 47012688Sgiacomo.travaglini@arm.com# Find Python include and library directories for embedding the 47113020Sshunhsingou@google.com# interpreter. For consistency, we will use the same Python 47212304Sgabeblack@google.com# installation used to run scons (and thus this script). If you want 47312688Sgiacomo.travaglini@arm.com# to link in an alternate version, see above for instructions on how 47412688Sgiacomo.travaglini@arm.com# to invoke scons with a different copy of the Python interpreter. 47513020Sshunhsingou@google.com 47612304Sgabeblack@google.com# Get brief Python version name (e.g., "python2.4") for locating 47712304Sgabeblack@google.com# include & library files 47812304Sgabeblack@google.compy_version_name = 'python' + sys.version[:3] 47912304Sgabeblack@google.com 48012688Sgiacomo.travaglini@arm.com# include path, e.g. /usr/local/include/python2.4 48112688Sgiacomo.travaglini@arm.compy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 48212688Sgiacomo.travaglini@arm.comenv.Append(CPPPATH = py_header_path) 48312304Sgabeblack@google.com# verify that it works 4848737Skoansin.tan@gmail.comif not conf.CheckHeader('Python.h', '<>'): 48510878Sandreas.hansson@arm.com print "Error: can't find Python.h header in", py_header_path 48611500Sandreas.hansson@arm.com Exit(1) 4879420Sandreas.hansson@arm.com 4888737Skoansin.tan@gmail.com# add library path too if it's not in the default place 48910106SMitch.Hayenga@arm.compy_lib_path = None 4908737Skoansin.tan@gmail.comif sys.exec_prefix != '/usr': 4918737Skoansin.tan@gmail.com py_lib_path = joinpath(sys.exec_prefix, 'lib') 49210878Sandreas.hansson@arm.comelif sys.platform == 'cygwin': 49312563Sgabeblack@google.com # cygwin puts the .dll in /bin for some reason 49412563Sgabeblack@google.com py_lib_path = '/bin' 4958737Skoansin.tan@gmail.comif py_lib_path: 4968737Skoansin.tan@gmail.com env.Append(LIBPATH = py_lib_path) 49712563Sgabeblack@google.com print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 4988737Skoansin.tan@gmail.comif not conf.CheckLib(py_version_name): 4998737Skoansin.tan@gmail.com print "Error: can't find Python library", py_version_name 50011294Sandreas.hansson@arm.com Exit(1) 5019556Sandreas.hansson@arm.com 5029556Sandreas.hansson@arm.com# On Solaris you need to use libsocket for socket ops 5039556Sandreas.hansson@arm.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 50411294Sandreas.hansson@arm.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 50510278SAndreas.Sandberg@ARM.com print "Can't find library with socket calls (e.g. accept())" 50610278SAndreas.Sandberg@ARM.com Exit(1) 50710278SAndreas.Sandberg@ARM.com 50810278SAndreas.Sandberg@ARM.com# Check for zlib. If the check passes, libz will be automatically 50910278SAndreas.Sandberg@ARM.com# added to the LIBS environment variable. 51010278SAndreas.Sandberg@ARM.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5119556Sandreas.hansson@arm.com print 'Error: did not find needed zlib compression library '\ 5129590Sandreas@sandberg.pp.se 'and/or zlib.h header file.' 5139590Sandreas@sandberg.pp.se print ' Please install zlib and try again.' 5149420Sandreas.hansson@arm.com Exit(1) 5159846Sandreas.hansson@arm.com 5169846Sandreas.hansson@arm.com# Check for <fenv.h> (C99 FP environment control) 5179846Sandreas.hansson@arm.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 5189846Sandreas.hansson@arm.comif not have_fenv: 5198946Sandreas.hansson@arm.com print "Warning: Header file <fenv.h> not found." 52011811Sbaz21@cam.ac.uk print " This host has no IEEE FP rounding mode control." 52111811Sbaz21@cam.ac.uk 52211811Sbaz21@cam.ac.uk# Check for mysql. 52311811Sbaz21@cam.ac.ukmysql_config = WhereIs('mysql_config') 52412304Sgabeblack@google.comhave_mysql = mysql_config != None 52512304Sgabeblack@google.com 52612304Sgabeblack@google.com# Check MySQL version. 52712304Sgabeblack@google.comif have_mysql: 52813020Sshunhsingou@google.com mysql_version = os.popen(mysql_config + ' --version').read() 52913020Sshunhsingou@google.com min_mysql_version = '4.1' 53012304Sgabeblack@google.com if compare_versions(mysql_version, min_mysql_version) < 0: 53112304Sgabeblack@google.com print 'Warning: MySQL', min_mysql_version, 'or newer required.' 53213020Sshunhsingou@google.com print ' Version', mysql_version, 'detected.' 53313020Sshunhsingou@google.com have_mysql = False 53412304Sgabeblack@google.com 53512304Sgabeblack@google.com# Set up mysql_config commands. 53613020Sshunhsingou@google.comif have_mysql: 53713020Sshunhsingou@google.com mysql_config_include = mysql_config + ' --include' 53812304Sgabeblack@google.com if os.system(mysql_config_include + ' > /dev/null') != 0: 53912304Sgabeblack@google.com # older mysql_config versions don't support --include, use 5403918Ssaidi@eecs.umich.edu # --cflags instead 54112563Sgabeblack@google.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 54212563Sgabeblack@google.com # This seems to work in all versions 54312563Sgabeblack@google.com mysql_config_libs = mysql_config + ' --libs' 54412563Sgabeblack@google.com 5459068SAli.Saidi@ARM.comenv = conf.Finish() 54612563Sgabeblack@google.com 54712563Sgabeblack@google.com# Define the universe of supported ISAs 5489068SAli.Saidi@ARM.comall_isa_list = [ ] 54912563Sgabeblack@google.comExport('all_isa_list') 55012563Sgabeblack@google.com 55112563Sgabeblack@google.com# Define the universe of supported CPU models 55212563Sgabeblack@google.comall_cpu_list = [ ] 55312563Sgabeblack@google.comdefault_cpus = [ ] 55412563Sgabeblack@google.comExport('all_cpu_list', 'default_cpus') 55512563Sgabeblack@google.com 55612563Sgabeblack@google.com# Sticky options get saved in the options file so they persist from 5573918Ssaidi@eecs.umich.edu# one invocation to the next (unless overridden, in which case the new 5583918Ssaidi@eecs.umich.edu# value becomes sticky). 5596157Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS) 5606157Snate@binkert.orgExport('sticky_opts') 5616157Snate@binkert.org 5626157Snate@binkert.org# Non-sticky options only apply to the current build. 5635397Ssaidi@eecs.umich.edunonsticky_opts = Options(args=ARGUMENTS) 5645397Ssaidi@eecs.umich.eduExport('nonsticky_opts') 5656121Snate@binkert.org 5666121Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 5676121Snate@binkert.org# above options 5686121Snate@binkert.orgfor base_dir in base_dir_list: 5696121Snate@binkert.org for root, dirs, files in os.walk(base_dir): 5706121Snate@binkert.org if 'SConsopts' in files: 5715397Ssaidi@eecs.umich.edu print "Reading", joinpath(root, 'SConsopts') 5721851SN/A SConscript(joinpath(root, 'SConsopts')) 5731851SN/A 5747739Sgblack@eecs.umich.eduall_isa_list.sort() 575955SN/Aall_cpu_list.sort() 5769396Sandreas.hansson@arm.comdefault_cpus.sort() 5779396Sandreas.hansson@arm.com 5789396Sandreas.hansson@arm.comsticky_opts.AddOptions( 5799396Sandreas.hansson@arm.com EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 5809396Sandreas.hansson@arm.com BoolOption('FULL_SYSTEM', 'Full-system support', False), 5819396Sandreas.hansson@arm.com # There's a bug in scons 0.96.1 that causes ListOptions with list 58212563Sgabeblack@google.com # values (more than one value) not to be able to be restored from 58312563Sgabeblack@google.com # a saved option file. If this causes trouble then upgrade to 58412563Sgabeblack@google.com # scons 0.96.90 or later. 58512563Sgabeblack@google.com ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 5869396Sandreas.hansson@arm.com BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 5879396Sandreas.hansson@arm.com BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 5889396Sandreas.hansson@arm.com False), 5899396Sandreas.hansson@arm.com BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 5909396Sandreas.hansson@arm.com False), 5919396Sandreas.hansson@arm.com BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 59212563Sgabeblack@google.com False), 59312563Sgabeblack@google.com BoolOption('SS_COMPATIBLE_FP', 59412563Sgabeblack@google.com 'Make floating-point results compatible with SimpleScalar', 59512563Sgabeblack@google.com False), 59612563Sgabeblack@google.com BoolOption('USE_SSE2', 5979477Sandreas.hansson@arm.com 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 5989477Sandreas.hansson@arm.com False), 5999477Sandreas.hansson@arm.com BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 6009477Sandreas.hansson@arm.com BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 6019477Sandreas.hansson@arm.com BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 6029477Sandreas.hansson@arm.com ('PYTHONHOME', 6039477Sandreas.hansson@arm.com 'Override the default PYTHONHOME for this system (use with caution)', 6049477Sandreas.hansson@arm.com '%s:%s' % (sys.prefix, sys.exec_prefix)), 6059477Sandreas.hansson@arm.com ) 6069477Sandreas.hansson@arm.com 6079477Sandreas.hansson@arm.comnonsticky_opts.AddOptions( 6089477Sandreas.hansson@arm.com BoolOption('update_ref', 'Update test reference outputs', False) 6099477Sandreas.hansson@arm.com ) 6109477Sandreas.hansson@arm.com 61112563Sgabeblack@google.com# These options get exported to #defines in config/*.hh (see src/SConscript). 61212563Sgabeblack@google.comenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 61312563Sgabeblack@google.com 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 6149396Sandreas.hansson@arm.com 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 6152667Sstever@eecs.umich.edu 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 61610710Sandreas.hansson@arm.com 61710710Sandreas.hansson@arm.com# Define a handy 'no-op' action 61810710Sandreas.hansson@arm.comdef no_action(target, source, env): 61911811Sbaz21@cam.ac.uk return 0 62011811Sbaz21@cam.ac.uk 62111811Sbaz21@cam.ac.ukenv.NoAction = Action(no_action, None) 62211811Sbaz21@cam.ac.uk 62311811Sbaz21@cam.ac.uk################################################### 62411811Sbaz21@cam.ac.uk# 62510710Sandreas.hansson@arm.com# Define a SCons builder for configuration flag headers. 62610710Sandreas.hansson@arm.com# 62710710Sandreas.hansson@arm.com################################################### 62810710Sandreas.hansson@arm.com 62910384SCurtis.Dunham@arm.com# This function generates a config header file that #defines the 6309986Sandreas@sandberg.pp.se# option symbol to the current option setting (0 or 1). The source 6319986Sandreas@sandberg.pp.se# operands are the name of the option and a Value node containing the 6329986Sandreas@sandberg.pp.se# value of the option. 6339986Sandreas@sandberg.pp.sedef build_config_file(target, source, env): 6349986Sandreas@sandberg.pp.se (option, value) = [s.get_contents() for s in source] 6359986Sandreas@sandberg.pp.se f = file(str(target[0]), 'w') 6369986Sandreas@sandberg.pp.se print >> f, '#define', option, value 6379986Sandreas@sandberg.pp.se f.close() 6389986Sandreas@sandberg.pp.se return None 6399986Sandreas@sandberg.pp.se 6409986Sandreas@sandberg.pp.se# Generate the message to be printed when building the config file. 6419986Sandreas@sandberg.pp.sedef build_config_file_string(target, source, env): 6429986Sandreas@sandberg.pp.se (option, value) = [s.get_contents() for s in source] 6439986Sandreas@sandberg.pp.se return "Defining %s as %s in %s." % (option, value, target[0]) 6449986Sandreas@sandberg.pp.se 6459986Sandreas@sandberg.pp.se# Combine the two functions into a scons Action object. 6469986Sandreas@sandberg.pp.seconfig_action = Action(build_config_file, build_config_file_string) 6479986Sandreas@sandberg.pp.se 6489986Sandreas@sandberg.pp.se# The emitter munges the source & target node lists to reflect what 6499986Sandreas@sandberg.pp.se# we're really doing. 6502638Sstever@eecs.umich.edudef config_emitter(target, source, env): 6512638Sstever@eecs.umich.edu # extract option name from Builder arg 6526121Snate@binkert.org option = str(target[0]) 6533716Sstever@eecs.umich.edu # True target is config header file 6545522Snate@binkert.org target = joinpath('config', option.lower() + '.hh') 6559986Sandreas@sandberg.pp.se val = env[option] 6569986Sandreas@sandberg.pp.se if isinstance(val, bool): 6579986Sandreas@sandberg.pp.se # Force value to 0/1 6585522Snate@binkert.org val = int(val) 6595227Ssaidi@eecs.umich.edu elif isinstance(val, str): 6605227Ssaidi@eecs.umich.edu val = '"' + val + '"' 6615227Ssaidi@eecs.umich.edu 6625227Ssaidi@eecs.umich.edu # Sources are option name & value (packaged in SCons Value nodes) 6636654Snate@binkert.org return ([target], [Value(option), Value(val)]) 6646654Snate@binkert.org 6657769SAli.Saidi@ARM.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 6667769SAli.Saidi@ARM.com 6677769SAli.Saidi@ARM.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 6687769SAli.Saidi@ARM.com 6695227Ssaidi@eecs.umich.edu################################################### 6705227Ssaidi@eecs.umich.edu# 6715227Ssaidi@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 6725204Sstever@gmail.com# Python zipfile code in src/python/SConscript, but is placed up here 6735204Sstever@gmail.com# since it's potentially more generally applicable. 6745204Sstever@gmail.com# 6755204Sstever@gmail.com################################################### 6765204Sstever@gmail.com 6775204Sstever@gmail.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 6785204Sstever@gmail.com 6795204Sstever@gmail.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 6805204Sstever@gmail.com 6815204Sstever@gmail.com################################################### 6825204Sstever@gmail.com# 6835204Sstever@gmail.com# Define a simple SCons builder to concatenate files. 6845204Sstever@gmail.com# 6855204Sstever@gmail.com# Used to append the Python zip archive to the executable. 6865204Sstever@gmail.com# 6875204Sstever@gmail.com################################################### 6885204Sstever@gmail.com 6896121Snate@binkert.orgconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 6905204Sstever@gmail.com 'chmod +x $TARGET'])) 6917727SAli.Saidi@ARM.com 6927727SAli.Saidi@ARM.comenv.Append(BUILDERS = { 'Concat' : concat_builder }) 69312563Sgabeblack@google.com 6947727SAli.Saidi@ARM.com 6957727SAli.Saidi@ARM.com# libelf build is shared across all configs in the build root. 69611988Sandreas.sandberg@arm.comenv.SConscript('ext/libelf/SConscript', 69711988Sandreas.sandberg@arm.com build_dir = joinpath(build_root, 'libelf'), 69810453SAndrew.Bardsley@arm.com exports = 'env') 69910453SAndrew.Bardsley@arm.com 70010453SAndrew.Bardsley@arm.com################################################### 70110453SAndrew.Bardsley@arm.com# 70210453SAndrew.Bardsley@arm.com# This function is used to set up a directory with switching headers 70310453SAndrew.Bardsley@arm.com# 70410453SAndrew.Bardsley@arm.com################################################### 70510453SAndrew.Bardsley@arm.com 70610453SAndrew.Bardsley@arm.comenv['ALL_ISA_LIST'] = all_isa_list 70710453SAndrew.Bardsley@arm.comdef make_switching_dir(dirname, switch_headers, env): 70810160Sandreas.hansson@arm.com # Generate the header. target[0] is the full path of the output 70910453SAndrew.Bardsley@arm.com # header to generate. 'source' is a dummy variable, since we get the 71010453SAndrew.Bardsley@arm.com # list of ISAs from env['ALL_ISA_LIST']. 71110453SAndrew.Bardsley@arm.com def gen_switch_hdr(target, source, env): 71210453SAndrew.Bardsley@arm.com fname = str(target[0]) 71310453SAndrew.Bardsley@arm.com basename = os.path.basename(fname) 71413541Sandrea.mondelli@ucf.edu f = open(fname, 'w') 71510453SAndrew.Bardsley@arm.com f.write('#include "arch/isa_specific.hh"\n') 71610453SAndrew.Bardsley@arm.com cond = '#if' 71713541Sandrea.mondelli@ucf.edu for isa in all_isa_list: 71813541Sandrea.mondelli@ucf.edu f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 7199812Sandreas.hansson@arm.com % (cond, isa.upper(), dirname, isa, basename)) 72010453SAndrew.Bardsley@arm.com cond = '#elif' 72110453SAndrew.Bardsley@arm.com f.write('#else\n#error "THE_ISA not set"\n#endif\n') 72210453SAndrew.Bardsley@arm.com f.close() 72310453SAndrew.Bardsley@arm.com return 0 72410453SAndrew.Bardsley@arm.com 72510453SAndrew.Bardsley@arm.com # String to print when generating header 72610453SAndrew.Bardsley@arm.com def gen_switch_hdr_string(target, source, env): 72710453SAndrew.Bardsley@arm.com return "Generating switch header " + str(target[0]) 72810453SAndrew.Bardsley@arm.com 72910453SAndrew.Bardsley@arm.com # Build SCons Action object. 'varlist' specifies env vars that this 73010453SAndrew.Bardsley@arm.com # action depends on; when env['ALL_ISA_LIST'] changes these actions 73110453SAndrew.Bardsley@arm.com # should get re-executed. 7327727SAli.Saidi@ARM.com switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 73310453SAndrew.Bardsley@arm.com varlist=['ALL_ISA_LIST']) 73410453SAndrew.Bardsley@arm.com 73512790Smatteo.fusi@bsc.es # Instantiate actions for each header 73612790Smatteo.fusi@bsc.es for hdr in switch_headers: 73712790Smatteo.fusi@bsc.es env.Command(hdr, [], switch_hdr_action) 73812790Smatteo.fusi@bsc.esExport('make_switching_dir') 73912790Smatteo.fusi@bsc.es 74012790Smatteo.fusi@bsc.es################################################### 74112790Smatteo.fusi@bsc.es# 74210453SAndrew.Bardsley@arm.com# Define build environments for selected configurations. 7433118Sstever@eecs.umich.edu# 74410453SAndrew.Bardsley@arm.com################################################### 74510453SAndrew.Bardsley@arm.com 74612563Sgabeblack@google.com# rename base env 74710453SAndrew.Bardsley@arm.combase_env = env 7483118Sstever@eecs.umich.edu 7493483Ssaidi@eecs.umich.edufor build_path in build_paths: 7503494Ssaidi@eecs.umich.edu print "Building in", build_path 7513494Ssaidi@eecs.umich.edu 75212563Sgabeblack@google.com # Make a copy of the build-root environment to use for this config. 7533483Ssaidi@eecs.umich.edu env = base_env.Copy() 7543483Ssaidi@eecs.umich.edu env['BUILDDIR'] = build_path 7553053Sstever@eecs.umich.edu 7563053Sstever@eecs.umich.edu # build_dir is the tail component of build path, and is used to 7573918Ssaidi@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 75812563Sgabeblack@google.com (build_root, build_dir) = os.path.split(build_path) 75912563Sgabeblack@google.com 76012563Sgabeblack@google.com # Set env options according to the build directory config. 7613053Sstever@eecs.umich.edu sticky_opts.files = [] 7623053Sstever@eecs.umich.edu # Options for $BUILD_ROOT/$BUILD_DIR are stored in 7639396Sandreas.hansson@arm.com # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 7649396Sandreas.hansson@arm.com # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 7659396Sandreas.hansson@arm.com current_opts_file = joinpath(build_root, 'options', build_dir) 7669396Sandreas.hansson@arm.com if isfile(current_opts_file): 7679396Sandreas.hansson@arm.com sticky_opts.files.append(current_opts_file) 7689396Sandreas.hansson@arm.com print "Using saved options file %s" % current_opts_file 7699396Sandreas.hansson@arm.com else: 7709396Sandreas.hansson@arm.com # Build dir-specific options file doesn't exist. 7719396Sandreas.hansson@arm.com 77212920Sgabeblack@google.com # Make sure the directory is there so we can create it later 77312920Sgabeblack@google.com opt_dir = os.path.dirname(current_opts_file) 77412920Sgabeblack@google.com if not isdir(opt_dir): 77512920Sgabeblack@google.com os.mkdir(opt_dir) 7769477Sandreas.hansson@arm.com 7779396Sandreas.hansson@arm.com # Get default build options from source tree. Options are 77812563Sgabeblack@google.com # normally determined by name of $BUILD_DIR, but can be 77912563Sgabeblack@google.com # overriden by 'default=' arg on command line. 78012563Sgabeblack@google.com default_opts_file = joinpath('build_opts', 78112563Sgabeblack@google.com ARGUMENTS.get('default', build_dir)) 7829396Sandreas.hansson@arm.com if isfile(default_opts_file): 7837840Snate@binkert.org sticky_opts.files.append(default_opts_file) 7847865Sgblack@eecs.umich.edu print "Options file %s not found,\n using defaults in %s" \ 7857865Sgblack@eecs.umich.edu % (current_opts_file, default_opts_file) 7867865Sgblack@eecs.umich.edu else: 7877865Sgblack@eecs.umich.edu print "Error: cannot find options file %s or %s" \ 7887865Sgblack@eecs.umich.edu % (current_opts_file, default_opts_file) 7897840Snate@binkert.org Exit(1) 7909900Sandreas@sandberg.pp.se 7919900Sandreas@sandberg.pp.se # Apply current option settings to env 7929900Sandreas@sandberg.pp.se sticky_opts.Update(env) 7939900Sandreas@sandberg.pp.se nonsticky_opts.Update(env) 79410456SCurtis.Dunham@arm.com 79510456SCurtis.Dunham@arm.com help_text += "\nSticky options for %s:\n" % build_dir \ 79610456SCurtis.Dunham@arm.com + sticky_opts.GenerateHelpText(env) \ 79710456SCurtis.Dunham@arm.com + "\nNon-sticky options for %s:\n" % build_dir \ 79810456SCurtis.Dunham@arm.com + nonsticky_opts.GenerateHelpText(env) 79910456SCurtis.Dunham@arm.com 80012563Sgabeblack@google.com # Process option settings. 80112563Sgabeblack@google.com 80212563Sgabeblack@google.com if not have_fenv and env['USE_FENV']: 80312563Sgabeblack@google.com print "Warning: <fenv.h> not available; " \ 8049045SAli.Saidi@ARM.com "forcing USE_FENV to False in", build_dir + "." 80511235Sandreas.sandberg@arm.com env['USE_FENV'] = False 80611235Sandreas.sandberg@arm.com 80711235Sandreas.sandberg@arm.com if not env['USE_FENV']: 80811235Sandreas.sandberg@arm.com print "Warning: No IEEE FP rounding mode control in", build_dir + "." 80911235Sandreas.sandberg@arm.com print " FP results may deviate slightly from other platforms." 81012485Sjang.hanhwi@gmail.com 81112485Sjang.hanhwi@gmail.com if env['EFENCE']: 81212485Sjang.hanhwi@gmail.com env.Append(LIBS=['efence']) 81311235Sandreas.sandberg@arm.com 81411811Sbaz21@cam.ac.uk if env['USE_MYSQL']: 81512485Sjang.hanhwi@gmail.com if not have_mysql: 81611811Sbaz21@cam.ac.uk print "Warning: MySQL not available; " \ 81711811Sbaz21@cam.ac.uk "forcing USE_MYSQL to False in", build_dir + "." 81811811Sbaz21@cam.ac.uk env['USE_MYSQL'] = False 81911235Sandreas.sandberg@arm.com else: 82011235Sandreas.sandberg@arm.com print "Compiling in", build_dir, "with MySQL support." 82111235Sandreas.sandberg@arm.com env.ParseConfig(mysql_config_libs) 82212563Sgabeblack@google.com env.ParseConfig(mysql_config_include) 82312563Sgabeblack@google.com 82412563Sgabeblack@google.com # Save sticky option settings back to current options file 82511235Sandreas.sandberg@arm.com sticky_opts.Save(current_opts_file, env) 8267840Snate@binkert.org 82712563Sgabeblack@google.com if env['USE_SSE2']: 8287840Snate@binkert.org env.Append(CCFLAGS='-msse2') 8291858SN/A 8301858SN/A # The src/SConscript file sets up the build rules in 'env' according 8311858SN/A # to the configured options. It returns a list of environments, 83212563Sgabeblack@google.com # one for each variant build (debug, opt, etc.) 83312563Sgabeblack@google.com envList = SConscript('src/SConscript', build_dir = build_path, 8341858SN/A exports = 'env') 83512230Sgiacomo.travaglini@arm.com 83612230Sgiacomo.travaglini@arm.com # Set up the regression tests for each build. 83712230Sgiacomo.travaglini@arm.com for e in envList: 83812230Sgiacomo.travaglini@arm.com SConscript('tests/SConscript', 83912563Sgabeblack@google.com build_dir = joinpath(build_path, 'tests', e.Label), 84012563Sgabeblack@google.com exports = { 'env' : e }, duplicate = False) 84112563Sgabeblack@google.com 84212230Sgiacomo.travaglini@arm.comHelp(help_text) 8439903Sandreas.hansson@arm.com 8449903Sandreas.hansson@arm.com 8459903Sandreas.hansson@arm.com################################################### 8469903Sandreas.hansson@arm.com# 84710841Sandreas.sandberg@arm.com# Let SCons do its thing. At this point SCons will use the defined 8489651SAndreas.Sandberg@ARM.com# build environments to build the requested targets. 84912563Sgabeblack@google.com# 85012563Sgabeblack@google.com################################################### 8519651SAndreas.Sandberg@ARM.com 85212056Sgabeblack@google.com