SConstruct revision 5396
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 382632Sstever@eecs.umich.edu# the optimized full-system version). 392632Sstever@eecs.umich.edu# 402632Sstever@eecs.umich.edu# 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 432632Sstever@eecs.umich.edu# 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# 522632Sstever@eecs.umich.edu# 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 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# 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 612632Sstever@eecs.umich.edu# file), you can use 'scons -h' to print all the M5-specific build 622632Sstever@eecs.umich.edu# options as well. 632632Sstever@eecs.umich.edu# 642632Sstever@eecs.umich.edu################################################### 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]". 805863Snate@binkert.orgEnsurePythonVersion(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: 965863Snate@binkert.org 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): 1166655Snate@binkert.org 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()) 1196655Snate@binkert.org 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()) 1235396Ssaidi@eecs.umich.edu 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", 1388120Sgblack@eecs.umich.edu print "ranges (inclusive):" 1398120Sgblack@eecs.umich.edu for bad_ver in bad_ver_strs: 1408120Sgblack@eecs.umich.edu print " %s - %s" % bad_ver 1418120Sgblack@eecs.umich.edu Exit(2) 1428120Sgblack@eecs.umich.edu 1438120Sgblack@eecs.umich.eduCheckSCons(( 1448120Sgblack@eecs.umich.edu # We need a version that is 0.96.91 or newer 1458120Sgblack@eecs.umich.edu ('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')) 1607816Ssteve.reinhardt@amd.com 1617816Ssteve.reinhardt@amd.comdef check_style_hook(ui): 1627816Ssteve.reinhardt@amd.com ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 1637816Ssteve.reinhardt@amd.com style_hook = ui.config('hooks', 'pretxncommit.style', None) 1647816Ssteve.reinhardt@amd.com 1657816Ssteve.reinhardt@amd.com if not style_hook: 1667816Ssteve.reinhardt@amd.com print """\ 1677816Ssteve.reinhardt@amd.comYou're missing the M5 style hook. 1687816Ssteve.reinhardt@amd.comPlease install the hook so we can ensure that all code fits a common style. 1695871Snate@binkert.org 1705871Snate@binkert.orgAll you'd need to do is add the following lines to your repository .hg/hgrc 1716121Snate@binkert.orgor your personal .hgrc 1725871Snate@binkert.org---------------- 1735871Snate@binkert.org 1746003Snate@binkert.org[extensions] 1756655Snate@binkert.orgstyle = %s/util/style.py 176955SN/A 1775871Snate@binkert.org[hooks] 1785871Snate@binkert.orgpretxncommit.style = python:style.check_whitespace 1795871Snate@binkert.org""" % (ROOT) 1805871Snate@binkert.org sys.exit(1) 181955SN/A 1826121Snate@binkert.orgif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1836121Snate@binkert.org try: 1846121Snate@binkert.org from mercurial import ui 1851533SN/A check_style_hook(ui.ui()) 1866655Snate@binkert.org except ImportError: 1876655Snate@binkert.org pass 1886655Snate@binkert.org 1896655Snate@binkert.org################################################### 1905871Snate@binkert.org# 1915871Snate@binkert.org# Figure out which configurations to set up based on the path(s) of 1925863Snate@binkert.org# the target(s). 1935871Snate@binkert.org# 1945871Snate@binkert.org################################################### 1955871Snate@binkert.org 1965871Snate@binkert.org# Find default configuration & binary. 1975871Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1985863Snate@binkert.org 1996121Snate@binkert.org# helper function: find last occurrence of element in list 2005863Snate@binkert.orgdef rfind(l, elt, offs = -1): 2015871Snate@binkert.org for i in range(len(l)+offs, 0, -1): 2028336Ssteve.reinhardt@amd.com if l[i] == elt: 2038336Ssteve.reinhardt@amd.com return i 2048336Ssteve.reinhardt@amd.com raise ValueError, "element not found" 2058336Ssteve.reinhardt@amd.com 2064678Snate@binkert.org# Each target must have 'build' in the interior of the path; the 2078336Ssteve.reinhardt@amd.com# directory below this will determine the build parameters. For 2088336Ssteve.reinhardt@amd.com# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 2098336Ssteve.reinhardt@amd.com# recognize that ALPHA_SE specifies the configuration because it 2104678Snate@binkert.org# follow 'build' in the bulid path. 2114678Snate@binkert.org 2124678Snate@binkert.org# Generate absolute paths to targets so we can see where the build dir is 2134678Snate@binkert.orgif COMMAND_LINE_TARGETS: 2147827Snate@binkert.org # Ask SCons which directory it was invoked from 2157827Snate@binkert.org launch_dir = GetLaunchDir() 2168336Ssteve.reinhardt@amd.com # Make targets relative to invocation directory 2174678Snate@binkert.org abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 2188336Ssteve.reinhardt@amd.com COMMAND_LINE_TARGETS) 2198336Ssteve.reinhardt@amd.comelse: 2208336Ssteve.reinhardt@amd.com # Default targets are relative to root of tree 2218336Ssteve.reinhardt@amd.com abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 2228336Ssteve.reinhardt@amd.com DEFAULT_TARGETS) 2238336Ssteve.reinhardt@amd.com 2245871Snate@binkert.org 2255871Snate@binkert.org# Generate a list of the unique build roots and configs that the 2268336Ssteve.reinhardt@amd.com# collected targets reference. 2278336Ssteve.reinhardt@amd.combuild_paths = [] 2288336Ssteve.reinhardt@amd.combuild_root = None 2298336Ssteve.reinhardt@amd.comfor t in abs_targets: 2308336Ssteve.reinhardt@amd.com 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) 2368336Ssteve.reinhardt@amd.com this_build_root = joinpath('/',*path_dirs[:build_top+1]) 2374678Snate@binkert.org if not build_root: 2385871Snate@binkert.org build_root = this_build_root 2394678Snate@binkert.org else: 2408336Ssteve.reinhardt@amd.com if this_build_root != build_root: 2418336Ssteve.reinhardt@amd.com print "Error: build targets not under same build root\n"\ 2428336Ssteve.reinhardt@amd.com " %s\n %s" % (build_root, this_build_root) 2438336Ssteve.reinhardt@amd.com Exit(1) 2448336Ssteve.reinhardt@amd.com build_path = joinpath('/',*path_dirs[:build_top+2]) 2458336Ssteve.reinhardt@amd.com if build_path not in build_paths: 2468336Ssteve.reinhardt@amd.com build_paths.append(build_path) 2478336Ssteve.reinhardt@amd.com 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# 2548336Ssteve.reinhardt@amd.com# Set up the default build environment. This environment is copied 2558336Ssteve.reinhardt@amd.com# and modified according to each selected configuration. 2568336Ssteve.reinhardt@amd.com# 2575871Snate@binkert.org################################################### 2586121Snate@binkert.org 259955SN/Aenv = Environment(ENV = os.environ, # inherit user's environment vars 260955SN/A ROOT = ROOT, 2612632Sstever@eecs.umich.edu SRCDIR = SRCDIR) 2622632Sstever@eecs.umich.edu 263955SN/AExport('env') 264955SN/A 265955SN/Aenv.SConsignFile(joinpath(build_root,"sconsign")) 266955SN/A 2675863Snate@binkert.org# Default duplicate option is to use hard links, but this messes up 268955SN/A# when you use emacs to edit a file in the target dir, as emacs moves 2692632Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2702632Sstever@eecs.umich.edu# (soft) links work better. 2712632Sstever@eecs.umich.eduenv.SetOption('duplicate', 'soft-copy') 2722632Sstever@eecs.umich.edu 2732632Sstever@eecs.umich.edu# I waffle on this setting... it does avoid a few painful but 2742632Sstever@eecs.umich.edu# unnecessary builds, but it also seems to make trivial builds take 2752632Sstever@eecs.umich.edu# noticeably longer. 2768268Ssteve.reinhardt@amd.comif False: 2778268Ssteve.reinhardt@amd.com env.TargetSignatures('content') 2788268Ssteve.reinhardt@amd.com 2798268Ssteve.reinhardt@amd.com# 2808268Ssteve.reinhardt@amd.com# Set up global sticky options... these are common to an entire build 2818268Ssteve.reinhardt@amd.com# tree (not specific to a particular build like ALPHA_SE) 2828268Ssteve.reinhardt@amd.com# 2832632Sstever@eecs.umich.edu 2842632Sstever@eecs.umich.edu# Option validators & converters for global sticky options 2852632Sstever@eecs.umich.edudef PathListMakeAbsolute(val): 2862632Sstever@eecs.umich.edu if not val: 2878268Ssteve.reinhardt@amd.com return val 2882632Sstever@eecs.umich.edu f = lambda p: os.path.abspath(os.path.expanduser(p)) 2898268Ssteve.reinhardt@amd.com return ':'.join(map(f, val.split(':'))) 2908268Ssteve.reinhardt@amd.com 2918268Ssteve.reinhardt@amd.comdef PathListAllExist(key, val, env): 2928268Ssteve.reinhardt@amd.com if not val: 2933718Sstever@eecs.umich.edu return 2942634Sstever@eecs.umich.edu paths = val.split(':') 2952634Sstever@eecs.umich.edu for path in paths: 2965863Snate@binkert.org if not isdir(path): 2972638Sstever@eecs.umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 2988268Ssteve.reinhardt@amd.com 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( 3041858SN/A ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 3053716Sstever@eecs.umich.edu ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 3062638Sstever@eecs.umich.edu ('EXTRAS', 'Add Extra directories to the compilation', '', 3072638Sstever@eecs.umich.edu PathListAllExist, PathListMakeAbsolute) 3082638Sstever@eecs.umich.edu ) 3092638Sstever@eecs.umich.edu 3102638Sstever@eecs.umich.edu 3112638Sstever@eecs.umich.edu# base help text 3122638Sstever@eecs.umich.eduhelp_text = ''' 3135863Snate@binkert.orgUsage: scons [scons options] [build options] [target(s)] 3145863Snate@binkert.org 3155863Snate@binkert.org''' 316955SN/A 3175341Sstever@gmail.comhelp_text += "Global sticky options:\n" \ 3185341Sstever@gmail.com + global_sticky_opts.GenerateHelpText(env) 3195863Snate@binkert.org 3207756SAli.Saidi@ARM.com# Update env with values from ARGUMENTS & file global_sticky_opts_file 3215341Sstever@gmail.comglobal_sticky_opts.Update(env) 3226121Snate@binkert.org 3234494Ssaidi@eecs.umich.edu# Save sticky option settings back to current options file 3246121Snate@binkert.orgglobal_sticky_opts.Save(global_sticky_opts_file, env) 3251105SN/A 3262667Sstever@eecs.umich.edu# Parse EXTRAS option to build list of all directories where we're 3272667Sstever@eecs.umich.edu# look for sources etc. This list is exported as base_dir_list. 3282667Sstever@eecs.umich.edubase_dir_list = [joinpath(ROOT, 'src')] 3292667Sstever@eecs.umich.eduif env['EXTRAS']: 3306121Snate@binkert.org base_dir_list += env['EXTRAS'].split(':') 3312667Sstever@eecs.umich.edu 3325341Sstever@gmail.comExport('base_dir_list') 3335863Snate@binkert.org 3345341Sstever@gmail.com# M5_PLY is used by isa_parser.py to find the PLY package. 3355341Sstever@gmail.comenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 3365341Sstever@gmail.comenv['GCC'] = False 3378120Sgblack@eecs.umich.eduenv['SUNCC'] = False 3385341Sstever@gmail.comenv['ICC'] = False 3398120Sgblack@eecs.umich.eduenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 3405341Sstever@gmail.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3418120Sgblack@eecs.umich.edu close_fds=True).communicate()[0].find('GCC') >= 0 3426121Snate@binkert.orgenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3436121Snate@binkert.org stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3445397Ssaidi@eecs.umich.edu close_fds=True).communicate()[0].find('Sun C++') >= 0 3455397Ssaidi@eecs.umich.eduenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3467727SAli.Saidi@ARM.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3478268Ssteve.reinhardt@amd.com close_fds=True).communicate()[0].find('Intel') >= 0 3486168Snate@binkert.orgif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3495341Sstever@gmail.com print 'Error: How can we have two at the same time?' 3508120Sgblack@eecs.umich.edu Exit(1) 3518120Sgblack@eecs.umich.edu 3528120Sgblack@eecs.umich.edu 3536814Sgblack@eecs.umich.edu# Set up default C++ compiler flags 3545863Snate@binkert.orgif env['GCC']: 3558120Sgblack@eecs.umich.edu env.Append(CCFLAGS='-pipe') 3565341Sstever@gmail.com env.Append(CCFLAGS='-fno-strict-aliasing') 3575863Snate@binkert.org env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3588268Ssteve.reinhardt@amd.comelif env['ICC']: 3596121Snate@binkert.org pass #Fix me... add warning flags once we clean up icc warnings 3606121Snate@binkert.orgelif env['SUNCC']: 3618268Ssteve.reinhardt@amd.com env.Append(CCFLAGS='-Qoption ccfe') 3625742Snate@binkert.org env.Append(CCFLAGS='-features=gcc') 3635742Snate@binkert.org env.Append(CCFLAGS='-features=extensions') 3645341Sstever@gmail.com env.Append(CCFLAGS='-library=stlport4') 3655742Snate@binkert.org env.Append(CCFLAGS='-xar') 3665742Snate@binkert.org# env.Append(CCFLAGS='-instances=semiexplicit') 3675341Sstever@gmail.comelse: 3686017Snate@binkert.org print 'Error: Don\'t know what compiler options to use for your compiler.' 3696121Snate@binkert.org print ' Please fix SConstruct and src/SConscript and try again.' 3706017Snate@binkert.org Exit(1) 3717816Ssteve.reinhardt@amd.com 3727756SAli.Saidi@ARM.comif sys.platform == 'cygwin': 3737756SAli.Saidi@ARM.com # cygwin has some header file issues... 3747756SAli.Saidi@ARM.com env.Append(CCFLAGS=Split("-Wno-uninitialized")) 3757756SAli.Saidi@ARM.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 3767756SAli.Saidi@ARM.com 3777756SAli.Saidi@ARM.com# Check for SWIG 3787756SAli.Saidi@ARM.comif not env.has_key('SWIG'): 3797756SAli.Saidi@ARM.com print 'Error: SWIG utility not found.' 3807816Ssteve.reinhardt@amd.com print ' Please install (see http://www.swig.org) and retry.' 3817816Ssteve.reinhardt@amd.com Exit(1) 3827816Ssteve.reinhardt@amd.com 3837816Ssteve.reinhardt@amd.com# Check for appropriate SWIG version 3847816Ssteve.reinhardt@amd.comswig_version = os.popen('swig -version').read().split() 3857816Ssteve.reinhardt@amd.com# First 3 words should be "SWIG Version x.y.z" 3867816Ssteve.reinhardt@amd.comif len(swig_version) < 3 or \ 3877816Ssteve.reinhardt@amd.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 3887816Ssteve.reinhardt@amd.com print 'Error determining SWIG version.' 3897816Ssteve.reinhardt@amd.com Exit(1) 3907756SAli.Saidi@ARM.com 3917816Ssteve.reinhardt@amd.commin_swig_version = '1.3.28' 3927816Ssteve.reinhardt@amd.comif compare_versions(swig_version[2], min_swig_version) < 0: 3937816Ssteve.reinhardt@amd.com print 'Error: SWIG version', min_swig_version, 'or newer required.' 3947816Ssteve.reinhardt@amd.com print ' Installed version:', swig_version[2] 3957816Ssteve.reinhardt@amd.com Exit(1) 3967816Ssteve.reinhardt@amd.com 3977816Ssteve.reinhardt@amd.com# Set up SWIG flags & scanner 3987816Ssteve.reinhardt@amd.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 3997816Ssteve.reinhardt@amd.comenv.Append(SWIGFLAGS=swig_flags) 4007816Ssteve.reinhardt@amd.com 4017816Ssteve.reinhardt@amd.com# filter out all existing swig scanners, they mess up the dependency 4027816Ssteve.reinhardt@amd.com# stuff for some reason 4037816Ssteve.reinhardt@amd.comscanners = [] 4047816Ssteve.reinhardt@amd.comfor scanner in env['SCANNERS']: 4057816Ssteve.reinhardt@amd.com skeys = scanner.skeys 4067816Ssteve.reinhardt@amd.com if skeys == '.i': 4077816Ssteve.reinhardt@amd.com continue 4087816Ssteve.reinhardt@amd.com 4097816Ssteve.reinhardt@amd.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 4107816Ssteve.reinhardt@amd.com continue 4117816Ssteve.reinhardt@amd.com 4127816Ssteve.reinhardt@amd.com scanners.append(scanner) 4137816Ssteve.reinhardt@amd.com 4147816Ssteve.reinhardt@amd.com# add the new swig scanner that we like better 4157816Ssteve.reinhardt@amd.comfrom SCons.Scanner import ClassicCPP as CPPScanner 4167816Ssteve.reinhardt@amd.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 4177816Ssteve.reinhardt@amd.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 4187816Ssteve.reinhardt@amd.com 4197816Ssteve.reinhardt@amd.com# replace the scanners list that has what we want 4207816Ssteve.reinhardt@amd.comenv['SCANNERS'] = scanners 4217816Ssteve.reinhardt@amd.com 4227816Ssteve.reinhardt@amd.com# Platform-specific configuration. Note again that we assume that all 4237816Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform. 4247816Ssteve.reinhardt@amd.comconf = Configure(env, 4257816Ssteve.reinhardt@amd.com conf_dir = joinpath(build_root, '.scons_config'), 4267816Ssteve.reinhardt@amd.com log_file = joinpath(build_root, 'scons_config.log')) 4277816Ssteve.reinhardt@amd.com 4287816Ssteve.reinhardt@amd.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 4297816Ssteve.reinhardt@amd.comtry: 4307816Ssteve.reinhardt@amd.com import platform 4317816Ssteve.reinhardt@amd.com uname = platform.uname() 4327816Ssteve.reinhardt@amd.com if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 4337816Ssteve.reinhardt@amd.com if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 4347816Ssteve.reinhardt@amd.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 4357816Ssteve.reinhardt@amd.com close_fds=True).communicate()[0][0]): 4367816Ssteve.reinhardt@amd.com env.Append(CCFLAGS='-arch x86_64') 4377816Ssteve.reinhardt@amd.com env.Append(CFLAGS='-arch x86_64') 4387816Ssteve.reinhardt@amd.com env.Append(LINKFLAGS='-arch x86_64') 4397816Ssteve.reinhardt@amd.com env.Append(ASFLAGS='-arch x86_64') 4407816Ssteve.reinhardt@amd.com env['OSX64bit'] = True 4417816Ssteve.reinhardt@amd.comexcept: 4427816Ssteve.reinhardt@amd.com pass 4437816Ssteve.reinhardt@amd.com 4447816Ssteve.reinhardt@amd.com# Recent versions of scons substitute a "Null" object for Configure() 4457816Ssteve.reinhardt@amd.com# when configuration isn't necessary, e.g., if the "--help" option is 4467816Ssteve.reinhardt@amd.com# present. Unfortuantely this Null object always returns false, 4477816Ssteve.reinhardt@amd.com# breaking all our configuration checks. We replace it with our own 4487816Ssteve.reinhardt@amd.com# more optimistic null object that returns True instead. 4497816Ssteve.reinhardt@amd.comif not conf: 4507816Ssteve.reinhardt@amd.com def NullCheck(*args, **kwargs): 4517816Ssteve.reinhardt@amd.com return True 4527756SAli.Saidi@ARM.com 4538120Sgblack@eecs.umich.edu class NullConf: 4547756SAli.Saidi@ARM.com def __init__(self, env): 4557756SAli.Saidi@ARM.com self.env = env 4567756SAli.Saidi@ARM.com def Finish(self): 4577756SAli.Saidi@ARM.com return self.env 4587816Ssteve.reinhardt@amd.com def __getattr__(self, mname): 4597816Ssteve.reinhardt@amd.com return NullCheck 4607816Ssteve.reinhardt@amd.com 4617816Ssteve.reinhardt@amd.com conf = NullConf(env) 4627816Ssteve.reinhardt@amd.com 4637816Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the 4647816Ssteve.reinhardt@amd.com# interpreter. For consistency, we will use the same Python 4657816Ssteve.reinhardt@amd.com# installation used to run scons (and thus this script). If you want 4667816Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how 4677816Ssteve.reinhardt@amd.com# to invoke scons with a different copy of the Python interpreter. 4687756SAli.Saidi@ARM.com 4697756SAli.Saidi@ARM.com# Get brief Python version name (e.g., "python2.4") for locating 4706654Snate@binkert.org# include & library files 4716654Snate@binkert.orgpy_version_name = 'python' + sys.version[:3] 4725871Snate@binkert.org 4736121Snate@binkert.org# include path, e.g. /usr/local/include/python2.4 4746121Snate@binkert.orgpy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 4756121Snate@binkert.orgenv.Append(CPPPATH = py_header_path) 4766121Snate@binkert.org# verify that it works 4773940Ssaidi@eecs.umich.eduif not conf.CheckHeader('Python.h', '<>'): 4783918Ssaidi@eecs.umich.edu print "Error: can't find Python.h header in", py_header_path 4793918Ssaidi@eecs.umich.edu Exit(1) 4801858SN/A 4816121Snate@binkert.org# add library path too if it's not in the default place 4827739Sgblack@eecs.umich.edupy_lib_path = None 4837739Sgblack@eecs.umich.eduif sys.exec_prefix != '/usr': 4846143Snate@binkert.org py_lib_path = joinpath(sys.exec_prefix, 'lib') 4857739Sgblack@eecs.umich.eduelif sys.platform == 'cygwin': 4867618SAli.Saidi@arm.com # cygwin puts the .dll in /bin for some reason 4877618SAli.Saidi@arm.com py_lib_path = '/bin' 4887618SAli.Saidi@arm.comif py_lib_path: 4897618SAli.Saidi@arm.com env.Append(LIBPATH = py_lib_path) 4907618SAli.Saidi@arm.com print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 4917618SAli.Saidi@arm.comif not conf.CheckLib(py_version_name): 4927618SAli.Saidi@arm.com print "Error: can't find Python library", py_version_name 4937739Sgblack@eecs.umich.edu Exit(1) 4946121Snate@binkert.org 4953940Ssaidi@eecs.umich.edu# On Solaris you need to use libsocket for socket ops 4966121Snate@binkert.orgif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 4977739Sgblack@eecs.umich.edu if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 4987739Sgblack@eecs.umich.edu print "Can't find library with socket calls (e.g. accept())" 4997739Sgblack@eecs.umich.edu Exit(1) 5007739Sgblack@eecs.umich.edu 5017739Sgblack@eecs.umich.edu# Check for zlib. If the check passes, libz will be automatically 5027739Sgblack@eecs.umich.edu# added to the LIBS environment variable. 5033918Ssaidi@eecs.umich.eduif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 5043918Ssaidi@eecs.umich.edu print 'Error: did not find needed zlib compression library '\ 5053940Ssaidi@eecs.umich.edu 'and/or zlib.h header file.' 5063918Ssaidi@eecs.umich.edu print ' Please install zlib and try again.' 5073918Ssaidi@eecs.umich.edu Exit(1) 5086157Snate@binkert.org 5096157Snate@binkert.org# Check for <fenv.h> (C99 FP environment control) 5106157Snate@binkert.orghave_fenv = conf.CheckHeader('fenv.h', '<>') 5116157Snate@binkert.orgif not have_fenv: 5125397Ssaidi@eecs.umich.edu print "Warning: Header file <fenv.h> not found." 5135397Ssaidi@eecs.umich.edu print " This host has no IEEE FP rounding mode control." 5146121Snate@binkert.org 5156121Snate@binkert.org# Check for mysql. 5166121Snate@binkert.orgmysql_config = WhereIs('mysql_config') 5176121Snate@binkert.orghave_mysql = mysql_config != None 5186121Snate@binkert.org 5196121Snate@binkert.org# Check MySQL version. 5205397Ssaidi@eecs.umich.eduif have_mysql: 5211851SN/A mysql_version = os.popen(mysql_config + ' --version').read() 5221851SN/A min_mysql_version = '4.1' 5237739Sgblack@eecs.umich.edu if compare_versions(mysql_version, min_mysql_version) < 0: 524955SN/A print 'Warning: MySQL', min_mysql_version, 'or newer required.' 5253053Sstever@eecs.umich.edu print ' Version', mysql_version, 'detected.' 5266121Snate@binkert.org have_mysql = False 5273053Sstever@eecs.umich.edu 5283053Sstever@eecs.umich.edu# Set up mysql_config commands. 5293053Sstever@eecs.umich.eduif have_mysql: 5303053Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --include' 5313053Sstever@eecs.umich.edu if os.system(mysql_config_include + ' > /dev/null') != 0: 5326654Snate@binkert.org # older mysql_config versions don't support --include, use 5333053Sstever@eecs.umich.edu # --cflags instead 5344742Sstever@eecs.umich.edu mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 5354742Sstever@eecs.umich.edu # This seems to work in all versions 5363053Sstever@eecs.umich.edu mysql_config_libs = mysql_config + ' --libs' 5373053Sstever@eecs.umich.edu 5383053Sstever@eecs.umich.eduenv = conf.Finish() 5393053Sstever@eecs.umich.edu 5406654Snate@binkert.org# Define the universe of supported ISAs 5413053Sstever@eecs.umich.eduall_isa_list = [ ] 5423053Sstever@eecs.umich.eduExport('all_isa_list') 5433053Sstever@eecs.umich.edu 5443053Sstever@eecs.umich.edu# Define the universe of supported CPU models 5452667Sstever@eecs.umich.eduall_cpu_list = [ ] 5464554Sbinkertn@umich.edudefault_cpus = [ ] 5476121Snate@binkert.orgExport('all_cpu_list', 'default_cpus') 5482667Sstever@eecs.umich.edu 5494554Sbinkertn@umich.edu# Sticky options get saved in the options file so they persist from 5504554Sbinkertn@umich.edu# one invocation to the next (unless overridden, in which case the new 5514554Sbinkertn@umich.edu# value becomes sticky). 5526121Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS) 5534554Sbinkertn@umich.eduExport('sticky_opts') 5544554Sbinkertn@umich.edu 5554554Sbinkertn@umich.edu# Non-sticky options only apply to the current build. 5564781Snate@binkert.orgnonsticky_opts = Options(args=ARGUMENTS) 5574554Sbinkertn@umich.eduExport('nonsticky_opts') 5584554Sbinkertn@umich.edu 5592667Sstever@eecs.umich.edu# Walk the tree and execute all SConsopts scripts that wil add to the 5604554Sbinkertn@umich.edu# above options 5614554Sbinkertn@umich.edufor base_dir in base_dir_list: 5624554Sbinkertn@umich.edu for root, dirs, files in os.walk(base_dir): 5634554Sbinkertn@umich.edu if 'SConsopts' in files: 5642667Sstever@eecs.umich.edu print "Reading", joinpath(root, 'SConsopts') 5654554Sbinkertn@umich.edu SConscript(joinpath(root, 'SConsopts')) 5662667Sstever@eecs.umich.edu 5674554Sbinkertn@umich.eduall_isa_list.sort() 5686121Snate@binkert.orgall_cpu_list.sort() 5692667Sstever@eecs.umich.edudefault_cpus.sort() 5705522Snate@binkert.org 5715522Snate@binkert.orgsticky_opts.AddOptions( 5725522Snate@binkert.org EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 5735522Snate@binkert.org BoolOption('FULL_SYSTEM', 'Full-system support', False), 5745522Snate@binkert.org # There's a bug in scons 0.96.1 that causes ListOptions with list 5755522Snate@binkert.org # values (more than one value) not to be able to be restored from 5765522Snate@binkert.org # a saved option file. If this causes trouble then upgrade to 5775522Snate@binkert.org # scons 0.96.90 or later. 5785522Snate@binkert.org ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 5795522Snate@binkert.org BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 5805522Snate@binkert.org BoolOption('FAST_ALLOC_DEBUG', 'Enable fast object allocator debugging', 5815522Snate@binkert.org False), 5825522Snate@binkert.org BoolOption('FAST_ALLOC_STATS', 'Enable fast object allocator statistics', 5835522Snate@binkert.org False), 5845522Snate@binkert.org BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 5855522Snate@binkert.org False), 5865522Snate@binkert.org BoolOption('SS_COMPATIBLE_FP', 5875522Snate@binkert.org 'Make floating-point results compatible with SimpleScalar', 5885522Snate@binkert.org False), 5895522Snate@binkert.org BoolOption('USE_SSE2', 5905522Snate@binkert.org 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 5915522Snate@binkert.org False), 5925522Snate@binkert.org BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 5935522Snate@binkert.org BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 5945522Snate@binkert.org BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 5955522Snate@binkert.org BoolOption('BATCH', 'Use batch pool for build and tests', False), 5962638Sstever@eecs.umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 5972638Sstever@eecs.umich.edu ('PYTHONHOME', 5986121Snate@binkert.org 'Override the default PYTHONHOME for this system (use with caution)', 5993716Sstever@eecs.umich.edu '%s:%s' % (sys.prefix, sys.exec_prefix)), 6005522Snate@binkert.org ) 6015522Snate@binkert.org 6025522Snate@binkert.orgnonsticky_opts.AddOptions( 6035522Snate@binkert.org BoolOption('update_ref', 'Update test reference outputs', False) 6045522Snate@binkert.org ) 6055522Snate@binkert.org 6061858SN/A# These options get exported to #defines in config/*.hh (see src/SConscript). 6075227Ssaidi@eecs.umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 6085227Ssaidi@eecs.umich.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'FAST_ALLOC_DEBUG', \ 6095227Ssaidi@eecs.umich.edu 'FAST_ALLOC_STATS', 'SS_COMPATIBLE_FP', \ 6105227Ssaidi@eecs.umich.edu 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 6116654Snate@binkert.org 6126654Snate@binkert.org# Define a handy 'no-op' action 6137769SAli.Saidi@ARM.comdef no_action(target, source, env): 6147769SAli.Saidi@ARM.com return 0 6157769SAli.Saidi@ARM.com 6167769SAli.Saidi@ARM.comenv.NoAction = Action(no_action, None) 6175227Ssaidi@eecs.umich.edu 6185227Ssaidi@eecs.umich.edu################################################### 6195227Ssaidi@eecs.umich.edu# 6205204Sstever@gmail.com# Define a SCons builder for configuration flag headers. 6215204Sstever@gmail.com# 6225204Sstever@gmail.com################################################### 6235204Sstever@gmail.com 6245204Sstever@gmail.com# This function generates a config header file that #defines the 6255204Sstever@gmail.com# option symbol to the current option setting (0 or 1). The source 6265204Sstever@gmail.com# operands are the name of the option and a Value node containing the 6275204Sstever@gmail.com# value of the option. 6285204Sstever@gmail.comdef build_config_file(target, source, env): 6295204Sstever@gmail.com (option, value) = [s.get_contents() for s in source] 6305204Sstever@gmail.com f = file(str(target[0]), 'w') 6315204Sstever@gmail.com print >> f, '#define', option, value 6325204Sstever@gmail.com f.close() 6335204Sstever@gmail.com return None 6345204Sstever@gmail.com 6355204Sstever@gmail.com# Generate the message to be printed when building the config file. 6365204Sstever@gmail.comdef build_config_file_string(target, source, env): 6376121Snate@binkert.org (option, value) = [s.get_contents() for s in source] 6385204Sstever@gmail.com return "Defining %s as %s in %s." % (option, value, target[0]) 6393118Sstever@eecs.umich.edu 6403118Sstever@eecs.umich.edu# Combine the two functions into a scons Action object. 6413118Sstever@eecs.umich.educonfig_action = Action(build_config_file, build_config_file_string) 6423118Sstever@eecs.umich.edu 6433118Sstever@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 6445863Snate@binkert.org# we're really doing. 6453118Sstever@eecs.umich.edudef config_emitter(target, source, env): 6465863Snate@binkert.org # extract option name from Builder arg 6473118Sstever@eecs.umich.edu option = str(target[0]) 6487457Snate@binkert.org # True target is config header file 6497457Snate@binkert.org target = joinpath('config', option.lower() + '.hh') 6505863Snate@binkert.org val = env[option] 6515863Snate@binkert.org if isinstance(val, bool): 6525863Snate@binkert.org # Force value to 0/1 6535863Snate@binkert.org val = int(val) 6545863Snate@binkert.org elif isinstance(val, str): 6555863Snate@binkert.org val = '"' + val + '"' 6565863Snate@binkert.org 6576003Snate@binkert.org # Sources are option name & value (packaged in SCons Value nodes) 6585863Snate@binkert.org return ([target], [Value(option), Value(val)]) 6595863Snate@binkert.org 6605863Snate@binkert.orgconfig_builder = Builder(emitter = config_emitter, action = config_action) 6616120Snate@binkert.org 6625863Snate@binkert.orgenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 6635863Snate@binkert.org 6645863Snate@binkert.org################################################### 6656120Snate@binkert.org# 6666120Snate@binkert.org# Define a SCons builder for copying files. This is used by the 6675863Snate@binkert.org# Python zipfile code in src/python/SConscript, but is placed up here 6685863Snate@binkert.org# since it's potentially more generally applicable. 6696120Snate@binkert.org# 6705863Snate@binkert.org################################################### 6716121Snate@binkert.org 6726121Snate@binkert.orgcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 6735863Snate@binkert.org 6747727SAli.Saidi@ARM.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 6757727SAli.Saidi@ARM.com 6767727SAli.Saidi@ARM.com################################################### 6777727SAli.Saidi@ARM.com# 6787727SAli.Saidi@ARM.com# Define a simple SCons builder to concatenate files. 6797727SAli.Saidi@ARM.com# 6805863Snate@binkert.org# Used to append the Python zip archive to the executable. 6813118Sstever@eecs.umich.edu# 6825863Snate@binkert.org################################################### 6833118Sstever@eecs.umich.edu 6843118Sstever@eecs.umich.educoncat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 6855863Snate@binkert.org 'chmod +x $TARGET'])) 6865863Snate@binkert.org 6875863Snate@binkert.orgenv.Append(BUILDERS = { 'Concat' : concat_builder }) 6885863Snate@binkert.org 6893118Sstever@eecs.umich.edu 6903483Ssaidi@eecs.umich.edu# libelf build is shared across all configs in the build root. 6913494Ssaidi@eecs.umich.eduenv.SConscript('ext/libelf/SConscript', 6923494Ssaidi@eecs.umich.edu build_dir = joinpath(build_root, 'libelf'), 6933483Ssaidi@eecs.umich.edu exports = 'env') 6943483Ssaidi@eecs.umich.edu 6953483Ssaidi@eecs.umich.edu################################################### 6963053Sstever@eecs.umich.edu# 6973053Sstever@eecs.umich.edu# This function is used to set up a directory with switching headers 6983918Ssaidi@eecs.umich.edu# 6993053Sstever@eecs.umich.edu################################################### 7003053Sstever@eecs.umich.edu 7013053Sstever@eecs.umich.eduenv['ALL_ISA_LIST'] = all_isa_list 7023053Sstever@eecs.umich.edudef make_switching_dir(dirname, switch_headers, env): 7033053Sstever@eecs.umich.edu # Generate the header. target[0] is the full path of the output 7047840Snate@binkert.org # header to generate. 'source' is a dummy variable, since we get the 7057865Sgblack@eecs.umich.edu # list of ISAs from env['ALL_ISA_LIST']. 7067865Sgblack@eecs.umich.edu def gen_switch_hdr(target, source, env): 7077865Sgblack@eecs.umich.edu fname = str(target[0]) 7087865Sgblack@eecs.umich.edu basename = os.path.basename(fname) 7097865Sgblack@eecs.umich.edu f = open(fname, 'w') 7107840Snate@binkert.org f.write('#include "arch/isa_specific.hh"\n') 7117840Snate@binkert.org cond = '#if' 7127840Snate@binkert.org for isa in all_isa_list: 7137840Snate@binkert.org f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 7141858SN/A % (cond, isa.upper(), dirname, isa, basename)) 7151858SN/A cond = '#elif' 7161858SN/A f.write('#else\n#error "THE_ISA not set"\n#endif\n') 7171858SN/A f.close() 7181858SN/A return 0 7191858SN/A 7205863Snate@binkert.org # String to print when generating header 7215863Snate@binkert.org def gen_switch_hdr_string(target, source, env): 7225863Snate@binkert.org return "Generating switch header " + str(target[0]) 7235863Snate@binkert.org 7246121Snate@binkert.org # Build SCons Action object. 'varlist' specifies env vars that this 7251858SN/A # action depends on; when env['ALL_ISA_LIST'] changes these actions 7265863Snate@binkert.org # should get re-executed. 7275863Snate@binkert.org switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 7285863Snate@binkert.org varlist=['ALL_ISA_LIST']) 7295863Snate@binkert.org 7305863Snate@binkert.org # Instantiate actions for each header 7312139SN/A for hdr in switch_headers: 7324202Sbinkertn@umich.edu env.Command(hdr, [], switch_hdr_action) 7334202Sbinkertn@umich.eduExport('make_switching_dir') 7342139SN/A 7356994Snate@binkert.org################################################### 7366994Snate@binkert.org# 7376994Snate@binkert.org# Define build environments for selected configurations. 7386994Snate@binkert.org# 7396994Snate@binkert.org################################################### 7406994Snate@binkert.org 7416994Snate@binkert.org# rename base env 7426994Snate@binkert.orgbase_env = env 7436994Snate@binkert.org 7446994Snate@binkert.orgfor build_path in build_paths: 7456994Snate@binkert.org print "Building in", build_path 7466994Snate@binkert.org 7476994Snate@binkert.org # Make a copy of the build-root environment to use for this config. 7486994Snate@binkert.org env = base_env.Copy() 7496994Snate@binkert.org env['BUILDDIR'] = build_path 7506994Snate@binkert.org 7516994Snate@binkert.org # build_dir is the tail component of build path, and is used to 7526994Snate@binkert.org # determine the build parameters (e.g., 'ALPHA_SE') 7536994Snate@binkert.org (build_root, build_dir) = os.path.split(build_path) 7546994Snate@binkert.org 7556994Snate@binkert.org # Set env options according to the build directory config. 7566994Snate@binkert.org sticky_opts.files = [] 7576994Snate@binkert.org # Options for $BUILD_ROOT/$BUILD_DIR are stored in 7586994Snate@binkert.org # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 7596994Snate@binkert.org # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 7606994Snate@binkert.org current_opts_file = joinpath(build_root, 'options', build_dir) 7616994Snate@binkert.org if isfile(current_opts_file): 7626994Snate@binkert.org sticky_opts.files.append(current_opts_file) 7632155SN/A print "Using saved options file %s" % current_opts_file 7645863Snate@binkert.org else: 7651869SN/A # Build dir-specific options file doesn't exist. 7661869SN/A 7675863Snate@binkert.org # Make sure the directory is there so we can create it later 7685863Snate@binkert.org opt_dir = os.path.dirname(current_opts_file) 7694202Sbinkertn@umich.edu if not isdir(opt_dir): 7706108Snate@binkert.org os.mkdir(opt_dir) 7716108Snate@binkert.org 7726108Snate@binkert.org # Get default build options from source tree. Options are 7736108Snate@binkert.org # normally determined by name of $BUILD_DIR, but can be 7744202Sbinkertn@umich.edu # overriden by 'default=' arg on command line. 7755863Snate@binkert.org default_opts_file = joinpath('build_opts', 7768474Sgblack@eecs.umich.edu ARGUMENTS.get('default', build_dir)) 7778474Sgblack@eecs.umich.edu if isfile(default_opts_file): 7785742Snate@binkert.org sticky_opts.files.append(default_opts_file) 7798268Ssteve.reinhardt@amd.com print "Options file %s not found,\n using defaults in %s" \ 7808268Ssteve.reinhardt@amd.com % (current_opts_file, default_opts_file) 7818268Ssteve.reinhardt@amd.com else: 7825742Snate@binkert.org print "Error: cannot find options file %s or %s" \ 7835341Sstever@gmail.com % (current_opts_file, default_opts_file) 7848474Sgblack@eecs.umich.edu Exit(1) 7858474Sgblack@eecs.umich.edu 7865342Sstever@gmail.com # Apply current option settings to env 7874202Sbinkertn@umich.edu sticky_opts.Update(env) 7884202Sbinkertn@umich.edu nonsticky_opts.Update(env) 7894202Sbinkertn@umich.edu 7905863Snate@binkert.org help_text += "\nSticky options for %s:\n" % build_dir \ 7915863Snate@binkert.org + sticky_opts.GenerateHelpText(env) \ 7925863Snate@binkert.org + "\nNon-sticky options for %s:\n" % build_dir \ 7936994Snate@binkert.org + nonsticky_opts.GenerateHelpText(env) 7946994Snate@binkert.org 7956994Snate@binkert.org # Process option settings. 7965863Snate@binkert.org 7978152Ssteve.reinhardt@amd.com if not have_fenv and env['USE_FENV']: 7988152Ssteve.reinhardt@amd.com print "Warning: <fenv.h> not available; " \ 7995863Snate@binkert.org "forcing USE_FENV to False in", build_dir + "." 8005863Snate@binkert.org env['USE_FENV'] = False 8015863Snate@binkert.org 8025863Snate@binkert.org if not env['USE_FENV']: 8035863Snate@binkert.org print "Warning: No IEEE FP rounding mode control in", build_dir + "." 8045863Snate@binkert.org print " FP results may deviate slightly from other platforms." 8055863Snate@binkert.org 8065863Snate@binkert.org if env['EFENCE']: 8075863Snate@binkert.org env.Append(LIBS=['efence']) 8085863Snate@binkert.org 8097840Snate@binkert.org if env['USE_MYSQL']: 8105863Snate@binkert.org if not have_mysql: 8115863Snate@binkert.org print "Warning: MySQL not available; " \ 8125952Ssaidi@eecs.umich.edu "forcing USE_MYSQL to False in", build_dir + "." 8137450Sstever@gmail.com env['USE_MYSQL'] = False 8141869SN/A else: 8151858SN/A print "Compiling in", build_dir, "with MySQL support." 8165863Snate@binkert.org env.ParseConfig(mysql_config_libs) 8178297Snate@binkert.org env.ParseConfig(mysql_config_include) 8188152Ssteve.reinhardt@amd.com 8197840Snate@binkert.org # Save sticky option settings back to current options file 8207840Snate@binkert.org sticky_opts.Save(current_opts_file, env) 8211858SN/A 822955SN/A # Do this after we save setting back, or else we'll tack on an 823955SN/A # extra 'qdo' every time we run scons. 8241869SN/A if env['BATCH']: 8251869SN/A env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 8261869SN/A env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 8271869SN/A 8281869SN/A if env['USE_SSE2']: 8295863Snate@binkert.org env.Append(CCFLAGS='-msse2') 8305863Snate@binkert.org 8315863Snate@binkert.org # The src/SConscript file sets up the build rules in 'env' according 8321869SN/A # to the configured options. It returns a list of environments, 8335863Snate@binkert.org # one for each variant build (debug, opt, etc.) 8341869SN/A envList = SConscript('src/SConscript', build_dir = build_path, 8355863Snate@binkert.org exports = 'env') 8361869SN/A 8371869SN/A # Set up the regression tests for each build. 8381869SN/A for e in envList: 8391869SN/A SConscript('tests/SConscript', 8401869SN/A build_dir = joinpath(build_path, 'tests', e.Label), 8415863Snate@binkert.org exports = { 'env' : e }, duplicate = False) 8425863Snate@binkert.org 8431869SN/AHelp(help_text) 8441869SN/A 8451869SN/A 8461869SN/A################################################### 8471869SN/A# 8481869SN/A# Let SCons do its thing. At this point SCons will use the defined 8491869SN/A# build environments to build the requested targets. 8505863Snate@binkert.org# 8515863Snate@binkert.org################################################### 8521869SN/A 8535863Snate@binkert.org