SConstruct revision 5343
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/A 695863Snate@binkert.orgfrom os.path import isdir, isfile, join as joinpath 705863Snate@binkert.org 715863Snate@binkert.orgimport SCons 725863Snate@binkert.org 735863Snate@binkert.org# Check for recent-enough Python and SCons versions. If your system's 745863Snate@binkert.org# default installation of Python is not recent enough, you can use a 755863Snate@binkert.org# non-default installation of the Python interpreter by either (1) 765863Snate@binkert.org# rearranging your PATH so that scons finds the non-default 'python' 775863Snate@binkert.org# first or (2) explicitly invoking an alternative interpreter on the 785863Snate@binkert.org# scons script, e.g., "/usr/local/bin/python2.4 `which scons` [args]". 795863Snate@binkert.orgEnsurePythonVersion(2,4) 805863Snate@binkert.org 815863Snate@binkert.org# Import subprocess after we check the version since it doesn't exist in 825863Snate@binkert.org# Python < 2.4. 835863Snate@binkert.orgimport subprocess 845863Snate@binkert.org 855863Snate@binkert.org# Ironically, SCons 0.96 dies if you give EnsureSconsVersion a 865863Snate@binkert.org# 3-element version number. 875863Snate@binkert.orgmin_scons_version = (0,96,91) 885863Snate@binkert.orgtry: 895863Snate@binkert.org EnsureSConsVersion(*min_scons_version) 905863Snate@binkert.orgexcept: 915863Snate@binkert.org print "Error checking current SCons version." 925863Snate@binkert.org print "SCons", ".".join(map(str,min_scons_version)), "or greater required." 935863Snate@binkert.org Exit(2) 945863Snate@binkert.org 955863Snate@binkert.org 965863Snate@binkert.org# The absolute path to the current directory (where this file lives). 975863Snate@binkert.orgROOT = Dir('.').abspath 985863Snate@binkert.org 995863Snate@binkert.org# Path to the M5 source tree. 1006654Snate@binkert.orgSRCDIR = joinpath(ROOT, 'src') 101955SN/A 1025396Ssaidi@eecs.umich.edu# tell python where to find m5 python code 1035863Snate@binkert.orgsys.path.append(joinpath(ROOT, 'src/python')) 1045863Snate@binkert.org 1054202Sbinkertn@umich.edudef check_style_hook(ui): 1065863Snate@binkert.org ui.readconfig(joinpath(ROOT, '.hg', 'hgrc')) 1075863Snate@binkert.org style_hook = ui.config('hooks', 'pretxncommit.style', None) 1085863Snate@binkert.org 1095863Snate@binkert.org if not style_hook: 110955SN/A print """\ 1116654Snate@binkert.orgYou're missing the M5 style hook. 1125273Sstever@gmail.comPlease install the hook so we can ensure that all code fits a common style. 1135871Snate@binkert.org 1145273Sstever@gmail.comAll you'd need to do is add the following lines to your repository .hg/hgrc 1156655Snate@binkert.orgor your personal .hgrc 1166655Snate@binkert.org---------------- 1176655Snate@binkert.org 1186655Snate@binkert.org[extensions] 1196655Snate@binkert.orgstyle = %s/util/style.py 1206655Snate@binkert.org 1215871Snate@binkert.org[hooks] 1226654Snate@binkert.orgpretxncommit.style = python:style.check_whitespace 1235396Ssaidi@eecs.umich.edu""" % (ROOT) 1247816Ssteve.reinhardt@amd.com sys.exit(1) 1257816Ssteve.reinhardt@amd.com 1267816Ssteve.reinhardt@amd.comif ARGUMENTS.get('IGNORE_STYLE') != 'True' and isdir(joinpath(ROOT, '.hg')): 1277816Ssteve.reinhardt@amd.com try: 1287816Ssteve.reinhardt@amd.com from mercurial import ui 1297816Ssteve.reinhardt@amd.com check_style_hook(ui.ui()) 1307816Ssteve.reinhardt@amd.com except ImportError: 1317816Ssteve.reinhardt@amd.com pass 1327816Ssteve.reinhardt@amd.com 1337816Ssteve.reinhardt@amd.com################################################### 1347816Ssteve.reinhardt@amd.com# 1357816Ssteve.reinhardt@amd.com# Figure out which configurations to set up based on the path(s) of 1365871Snate@binkert.org# the target(s). 1375871Snate@binkert.org# 1386121Snate@binkert.org################################################### 1395871Snate@binkert.org 1405871Snate@binkert.org# Find default configuration & binary. 1416003Snate@binkert.orgDefault(os.environ.get('M5_DEFAULT_BINARY', 'build/ALPHA_SE/m5.debug')) 1426655Snate@binkert.org 143955SN/A# helper function: find last occurrence of element in list 1445871Snate@binkert.orgdef rfind(l, elt, offs = -1): 1455871Snate@binkert.org for i in range(len(l)+offs, 0, -1): 1465871Snate@binkert.org if l[i] == elt: 1475871Snate@binkert.org return i 148955SN/A raise ValueError, "element not found" 1496121Snate@binkert.org 1506121Snate@binkert.org# helper function: compare dotted version numbers. 1516121Snate@binkert.org# E.g., compare_version('1.3.25', '1.4.1') 1521533SN/A# returns -1, 0, 1 if v1 is <, ==, > v2 1536655Snate@binkert.orgdef compare_versions(v1, v2): 1546655Snate@binkert.org # Convert dotted strings to lists 1556655Snate@binkert.org v1 = map(int, v1.split('.')) 1566655Snate@binkert.org v2 = map(int, v2.split('.')) 1575871Snate@binkert.org # Compare corresponding elements of lists 1585871Snate@binkert.org for n1,n2 in zip(v1, v2): 1595863Snate@binkert.org if n1 < n2: return -1 1605871Snate@binkert.org if n1 > n2: return 1 1615871Snate@binkert.org # all corresponding values are equal... see if one has extra values 1625871Snate@binkert.org if len(v1) < len(v2): return -1 1635871Snate@binkert.org if len(v1) > len(v2): return 1 1645871Snate@binkert.org return 0 1655863Snate@binkert.org 1666121Snate@binkert.org# Each target must have 'build' in the interior of the path; the 1675863Snate@binkert.org# directory below this will determine the build parameters. For 1685871Snate@binkert.org# example, for target 'foo/bar/build/ALPHA_SE/arch/alpha/blah.do' we 1694678Snate@binkert.org# recognize that ALPHA_SE specifies the configuration because it 1704678Snate@binkert.org# follow 'build' in the bulid path. 1714678Snate@binkert.org 1724678Snate@binkert.org# Generate absolute paths to targets so we can see where the build dir is 1734678Snate@binkert.orgif COMMAND_LINE_TARGETS: 1744678Snate@binkert.org # Ask SCons which directory it was invoked from 1754678Snate@binkert.org launch_dir = GetLaunchDir() 1764678Snate@binkert.org # Make targets relative to invocation directory 1774678Snate@binkert.org abs_targets = map(lambda x: os.path.normpath(joinpath(launch_dir, str(x))), 1784678Snate@binkert.org COMMAND_LINE_TARGETS) 1794678Snate@binkert.orgelse: 1807827Snate@binkert.org # Default targets are relative to root of tree 1817827Snate@binkert.org abs_targets = map(lambda x: os.path.normpath(joinpath(ROOT, str(x))), 1826121Snate@binkert.org DEFAULT_TARGETS) 1834678Snate@binkert.org 1845871Snate@binkert.org 1855871Snate@binkert.org# Generate a list of the unique build roots and configs that the 1865871Snate@binkert.org# collected targets reference. 1875871Snate@binkert.orgbuild_paths = [] 1885871Snate@binkert.orgbuild_root = None 1895871Snate@binkert.orgfor t in abs_targets: 1905871Snate@binkert.org path_dirs = t.split('/') 1915871Snate@binkert.org try: 1925871Snate@binkert.org build_top = rfind(path_dirs, 'build', -2) 1935871Snate@binkert.org except: 1945871Snate@binkert.org print "Error: no non-leaf 'build' dir found on target path", t 1955871Snate@binkert.org Exit(1) 1965871Snate@binkert.org this_build_root = joinpath('/',*path_dirs[:build_top+1]) 1975990Ssaidi@eecs.umich.edu if not build_root: 1985871Snate@binkert.org build_root = this_build_root 1995871Snate@binkert.org else: 2005871Snate@binkert.org if this_build_root != build_root: 2014678Snate@binkert.org print "Error: build targets not under same build root\n"\ 2026654Snate@binkert.org " %s\n %s" % (build_root, this_build_root) 2035871Snate@binkert.org Exit(1) 2045871Snate@binkert.org build_path = joinpath('/',*path_dirs[:build_top+2]) 2055871Snate@binkert.org if build_path not in build_paths: 2065871Snate@binkert.org build_paths.append(build_path) 2075871Snate@binkert.org 2085871Snate@binkert.org# Make sure build_root exists (might not if this is the first build there) 2095871Snate@binkert.orgif not isdir(build_root): 2105871Snate@binkert.org os.mkdir(build_root) 2115871Snate@binkert.org 2124678Snate@binkert.org################################################### 2135871Snate@binkert.org# 2144678Snate@binkert.org# Set up the default build environment. This environment is copied 2155871Snate@binkert.org# and modified according to each selected configuration. 2165871Snate@binkert.org# 2175871Snate@binkert.org################################################### 2185871Snate@binkert.org 2195871Snate@binkert.orgenv = Environment(ENV = os.environ, # inherit user's environment vars 2205871Snate@binkert.org ROOT = ROOT, 2215871Snate@binkert.org SRCDIR = SRCDIR) 2225871Snate@binkert.org 2235871Snate@binkert.orgExport('env') 2246121Snate@binkert.org 2256121Snate@binkert.orgenv.SConsignFile(joinpath(build_root,"sconsign")) 2265863Snate@binkert.org 227955SN/A# Default duplicate option is to use hard links, but this messes up 228955SN/A# when you use emacs to edit a file in the target dir, as emacs moves 2292632Sstever@eecs.umich.edu# file to file~ then copies to file, breaking the link. Symbolic 2302632Sstever@eecs.umich.edu# (soft) links work better. 231955SN/Aenv.SetOption('duplicate', 'soft-copy') 232955SN/A 233955SN/A# I waffle on this setting... it does avoid a few painful but 234955SN/A# unnecessary builds, but it also seems to make trivial builds take 2355863Snate@binkert.org# noticeably longer. 236955SN/Aif False: 2372632Sstever@eecs.umich.edu env.TargetSignatures('content') 2382632Sstever@eecs.umich.edu 2392632Sstever@eecs.umich.edu# 2402632Sstever@eecs.umich.edu# Set up global sticky options... these are common to an entire build 2412632Sstever@eecs.umich.edu# tree (not specific to a particular build like ALPHA_SE) 2422632Sstever@eecs.umich.edu# 2432632Sstever@eecs.umich.edu 2442632Sstever@eecs.umich.edu# Option validators & converters for global sticky options 2452632Sstever@eecs.umich.edudef PathListMakeAbsolute(val): 2462632Sstever@eecs.umich.edu if not val: 2472632Sstever@eecs.umich.edu return val 2482632Sstever@eecs.umich.edu f = lambda p: os.path.abspath(os.path.expanduser(p)) 2492632Sstever@eecs.umich.edu return ':'.join(map(f, val.split(':'))) 2503718Sstever@eecs.umich.edu 2513718Sstever@eecs.umich.edudef PathListAllExist(key, val, env): 2523718Sstever@eecs.umich.edu if not val: 2533718Sstever@eecs.umich.edu return 2543718Sstever@eecs.umich.edu paths = val.split(':') 2555863Snate@binkert.org for path in paths: 2565863Snate@binkert.org if not isdir(path): 2573718Sstever@eecs.umich.edu raise SCons.Errors.UserError("Path does not exist: '%s'" % path) 2583718Sstever@eecs.umich.edu 2596121Snate@binkert.orgglobal_sticky_opts_file = joinpath(build_root, 'options.global') 2605863Snate@binkert.org 2613718Sstever@eecs.umich.eduglobal_sticky_opts = Options(global_sticky_opts_file, args=ARGUMENTS) 2623718Sstever@eecs.umich.edu 2632634Sstever@eecs.umich.eduglobal_sticky_opts.AddOptions( 2642634Sstever@eecs.umich.edu ('CC', 'C compiler', os.environ.get('CC', env['CC'])), 2655863Snate@binkert.org ('CXX', 'C++ compiler', os.environ.get('CXX', env['CXX'])), 2662638Sstever@eecs.umich.edu ('EXTRAS', 'Add Extra directories to the compilation', '', 2672632Sstever@eecs.umich.edu PathListAllExist, PathListMakeAbsolute) 2682632Sstever@eecs.umich.edu ) 2692632Sstever@eecs.umich.edu 2702632Sstever@eecs.umich.edu 2712632Sstever@eecs.umich.edu# base help text 2722632Sstever@eecs.umich.eduhelp_text = ''' 2731858SN/AUsage: scons [scons options] [build options] [target(s)] 2743716Sstever@eecs.umich.edu 2752638Sstever@eecs.umich.edu''' 2762638Sstever@eecs.umich.edu 2772638Sstever@eecs.umich.eduhelp_text += "Global sticky options:\n" \ 2782638Sstever@eecs.umich.edu + global_sticky_opts.GenerateHelpText(env) 2792638Sstever@eecs.umich.edu 2802638Sstever@eecs.umich.edu# Update env with values from ARGUMENTS & file global_sticky_opts_file 2812638Sstever@eecs.umich.eduglobal_sticky_opts.Update(env) 2825863Snate@binkert.org 2835863Snate@binkert.org# Save sticky option settings back to current options file 2845863Snate@binkert.orgglobal_sticky_opts.Save(global_sticky_opts_file, env) 285955SN/A 2865341Sstever@gmail.com# Parse EXTRAS option to build list of all directories where we're 2875341Sstever@gmail.com# look for sources etc. This list is exported as base_dir_list. 2885863Snate@binkert.orgbase_dir_list = [ROOT] 2897756SAli.Saidi@ARM.comif env['EXTRAS']: 2905341Sstever@gmail.com base_dir_list += env['EXTRAS'].split(':') 2916121Snate@binkert.org 2924494Ssaidi@eecs.umich.eduExport('base_dir_list') 2936121Snate@binkert.org 2941105SN/A# M5_PLY is used by isa_parser.py to find the PLY package. 2952667Sstever@eecs.umich.eduenv.Append(ENV = { 'M5_PLY' : str(Dir('ext/ply')) }) 2962667Sstever@eecs.umich.eduenv['GCC'] = False 2972667Sstever@eecs.umich.eduenv['SUNCC'] = False 2982667Sstever@eecs.umich.eduenv['ICC'] = False 2996121Snate@binkert.orgenv['GCC'] = subprocess.Popen(env['CXX'] + ' --version', shell=True, 3002667Sstever@eecs.umich.edu stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3015341Sstever@gmail.com close_fds=True).communicate()[0].find('GCC') >= 0 3025863Snate@binkert.orgenv['SUNCC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3035341Sstever@gmail.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3045341Sstever@gmail.com close_fds=True).communicate()[0].find('Sun C++') >= 0 3055341Sstever@gmail.comenv['ICC'] = subprocess.Popen(env['CXX'] + ' -V', shell=True, 3065863Snate@binkert.org stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3075341Sstever@gmail.com close_fds=True).communicate()[0].find('Intel') >= 0 3085341Sstever@gmail.comif env['GCC'] + env['SUNCC'] + env['ICC'] > 1: 3095341Sstever@gmail.com print 'Error: How can we have two at the same time?' 3105863Snate@binkert.org Exit(1) 3115341Sstever@gmail.com 3125341Sstever@gmail.com 3135341Sstever@gmail.com# Set up default C++ compiler flags 3145341Sstever@gmail.comif env['GCC']: 3155341Sstever@gmail.com env.Append(CCFLAGS='-pipe') 3165341Sstever@gmail.com env.Append(CCFLAGS='-fno-strict-aliasing') 3175341Sstever@gmail.com env.Append(CCFLAGS=Split('-Wall -Wno-sign-compare -Werror -Wundef')) 3185341Sstever@gmail.comelif env['ICC']: 3195341Sstever@gmail.com pass #Fix me... add warning flags once we clean up icc warnings 3205341Sstever@gmail.comelif env['SUNCC']: 3215863Snate@binkert.org env.Append(CCFLAGS='-Qoption ccfe') 3225341Sstever@gmail.com env.Append(CCFLAGS='-features=gcc') 3235863Snate@binkert.org env.Append(CCFLAGS='-features=extensions') 3247756SAli.Saidi@ARM.com env.Append(CCFLAGS='-library=stlport4') 3255341Sstever@gmail.com env.Append(CCFLAGS='-xar') 3265863Snate@binkert.org# env.Append(CCFLAGS='-instances=semiexplicit') 3276121Snate@binkert.orgelse: 3286121Snate@binkert.org print 'Error: Don\'t know what compiler options to use for your compiler.' 3295397Ssaidi@eecs.umich.edu print ' Please fix SConstruct and src/SConscript and try again.' 3305397Ssaidi@eecs.umich.edu Exit(1) 3317727SAli.Saidi@ARM.com 3325341Sstever@gmail.comif sys.platform == 'cygwin': 3336168Snate@binkert.org # cygwin has some header file issues... 3346168Snate@binkert.org env.Append(CCFLAGS=Split("-Wno-uninitialized")) 3355341Sstever@gmail.comenv.Append(CPPPATH=[Dir('ext/dnet')]) 3367756SAli.Saidi@ARM.com 3377756SAli.Saidi@ARM.com# Check for SWIG 3387756SAli.Saidi@ARM.comif not env.has_key('SWIG'): 3397756SAli.Saidi@ARM.com print 'Error: SWIG utility not found.' 3407756SAli.Saidi@ARM.com print ' Please install (see http://www.swig.org) and retry.' 3417756SAli.Saidi@ARM.com Exit(1) 3425341Sstever@gmail.com 3435341Sstever@gmail.com# Check for appropriate SWIG version 3445341Sstever@gmail.comswig_version = os.popen('swig -version').read().split() 3455341Sstever@gmail.com# First 3 words should be "SWIG Version x.y.z" 3465863Snate@binkert.orgif len(swig_version) < 3 or \ 3475341Sstever@gmail.com swig_version[0] != 'SWIG' or swig_version[1] != 'Version': 3485341Sstever@gmail.com print 'Error determining SWIG version.' 3496121Snate@binkert.org Exit(1) 3506121Snate@binkert.org 3517756SAli.Saidi@ARM.commin_swig_version = '1.3.28' 3525341Sstever@gmail.comif compare_versions(swig_version[2], min_swig_version) < 0: 3536814Sgblack@eecs.umich.edu print 'Error: SWIG version', min_swig_version, 'or newer required.' 3547756SAli.Saidi@ARM.com print ' Installed version:', swig_version[2] 3556814Sgblack@eecs.umich.edu Exit(1) 3565863Snate@binkert.org 3576121Snate@binkert.org# Set up SWIG flags & scanner 3585341Sstever@gmail.comswig_flags=Split('-c++ -python -modern -templatereduce $_CPPINCFLAGS') 3595863Snate@binkert.orgenv.Append(SWIGFLAGS=swig_flags) 3605341Sstever@gmail.com 3616121Snate@binkert.org# filter out all existing swig scanners, they mess up the dependency 3626121Snate@binkert.org# stuff for some reason 3636121Snate@binkert.orgscanners = [] 3645742Snate@binkert.orgfor scanner in env['SCANNERS']: 3655742Snate@binkert.org skeys = scanner.skeys 3665341Sstever@gmail.com if skeys == '.i': 3675742Snate@binkert.org continue 3685742Snate@binkert.org 3695341Sstever@gmail.com if isinstance(skeys, (list, tuple)) and '.i' in skeys: 3706017Snate@binkert.org continue 3716121Snate@binkert.org 3726017Snate@binkert.org scanners.append(scanner) 3737816Ssteve.reinhardt@amd.com 3747756SAli.Saidi@ARM.com# add the new swig scanner that we like better 3757756SAli.Saidi@ARM.comfrom SCons.Scanner import ClassicCPP as CPPScanner 3767756SAli.Saidi@ARM.comswig_inc_re = '^[ \t]*[%,#][ \t]*(?:include|import)[ \t]*(<|")([^>"]+)(>|")' 3777756SAli.Saidi@ARM.comscanners.append(CPPScanner("SwigScan", [ ".i" ], "CPPPATH", swig_inc_re)) 3787756SAli.Saidi@ARM.com 3797756SAli.Saidi@ARM.com# replace the scanners list that has what we want 3807756SAli.Saidi@ARM.comenv['SCANNERS'] = scanners 3817756SAli.Saidi@ARM.com 3827816Ssteve.reinhardt@amd.com# Platform-specific configuration. Note again that we assume that all 3837816Ssteve.reinhardt@amd.com# builds under a given build root run on the same host platform. 3847816Ssteve.reinhardt@amd.comconf = Configure(env, 3857816Ssteve.reinhardt@amd.com conf_dir = joinpath(build_root, '.scons_config'), 3867816Ssteve.reinhardt@amd.com log_file = joinpath(build_root, 'scons_config.log')) 3877816Ssteve.reinhardt@amd.com 3887816Ssteve.reinhardt@amd.com# Check if we should compile a 64 bit binary on Mac OS X/Darwin 3897816Ssteve.reinhardt@amd.comtry: 3907816Ssteve.reinhardt@amd.com import platform 3917816Ssteve.reinhardt@amd.com uname = platform.uname() 3927756SAli.Saidi@ARM.com if uname[0] == 'Darwin' and compare_versions(uname[2], '9.0.0') >= 0: 3937816Ssteve.reinhardt@amd.com if int(subprocess.Popen('sysctl -n hw.cpu64bit_capable', shell=True, 3947816Ssteve.reinhardt@amd.com stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 3957816Ssteve.reinhardt@amd.com close_fds=True).communicate()[0][0]): 3967816Ssteve.reinhardt@amd.com env.Append(CCFLAGS='-arch x86_64') 3977816Ssteve.reinhardt@amd.com env.Append(CFLAGS='-arch x86_64') 3987816Ssteve.reinhardt@amd.com env.Append(LINKFLAGS='-arch x86_64') 3997816Ssteve.reinhardt@amd.com env.Append(ASFLAGS='-arch x86_64') 4007816Ssteve.reinhardt@amd.com env['OSX64bit'] = True 4017816Ssteve.reinhardt@amd.comexcept: 4027816Ssteve.reinhardt@amd.com pass 4037816Ssteve.reinhardt@amd.com 4047816Ssteve.reinhardt@amd.com# Recent versions of scons substitute a "Null" object for Configure() 4057816Ssteve.reinhardt@amd.com# when configuration isn't necessary, e.g., if the "--help" option is 4067816Ssteve.reinhardt@amd.com# present. Unfortuantely this Null object always returns false, 4077816Ssteve.reinhardt@amd.com# breaking all our configuration checks. We replace it with our own 4087816Ssteve.reinhardt@amd.com# more optimistic null object that returns True instead. 4097816Ssteve.reinhardt@amd.comif not conf: 4107816Ssteve.reinhardt@amd.com def NullCheck(*args, **kwargs): 4117816Ssteve.reinhardt@amd.com return True 4127816Ssteve.reinhardt@amd.com 4137816Ssteve.reinhardt@amd.com class NullConf: 4147816Ssteve.reinhardt@amd.com def __init__(self, env): 4157816Ssteve.reinhardt@amd.com self.env = env 4167816Ssteve.reinhardt@amd.com def Finish(self): 4177816Ssteve.reinhardt@amd.com return self.env 4187816Ssteve.reinhardt@amd.com def __getattr__(self, mname): 4197816Ssteve.reinhardt@amd.com return NullCheck 4207816Ssteve.reinhardt@amd.com 4217816Ssteve.reinhardt@amd.com conf = NullConf(env) 4227816Ssteve.reinhardt@amd.com 4237816Ssteve.reinhardt@amd.com# Find Python include and library directories for embedding the 4247816Ssteve.reinhardt@amd.com# interpreter. For consistency, we will use the same Python 4257816Ssteve.reinhardt@amd.com# installation used to run scons (and thus this script). If you want 4267816Ssteve.reinhardt@amd.com# to link in an alternate version, see above for instructions on how 4277816Ssteve.reinhardt@amd.com# to invoke scons with a different copy of the Python interpreter. 4287816Ssteve.reinhardt@amd.com 4297816Ssteve.reinhardt@amd.com# Get brief Python version name (e.g., "python2.4") for locating 4307816Ssteve.reinhardt@amd.com# include & library files 4317816Ssteve.reinhardt@amd.compy_version_name = 'python' + sys.version[:3] 4327816Ssteve.reinhardt@amd.com 4337816Ssteve.reinhardt@amd.com# include path, e.g. /usr/local/include/python2.4 4347816Ssteve.reinhardt@amd.compy_header_path = joinpath(sys.exec_prefix, 'include', py_version_name) 4357816Ssteve.reinhardt@amd.comenv.Append(CPPPATH = py_header_path) 4367816Ssteve.reinhardt@amd.com# verify that it works 4377816Ssteve.reinhardt@amd.comif not conf.CheckHeader('Python.h', '<>'): 4387816Ssteve.reinhardt@amd.com print "Error: can't find Python.h header in", py_header_path 4397816Ssteve.reinhardt@amd.com Exit(1) 4407816Ssteve.reinhardt@amd.com 4417816Ssteve.reinhardt@amd.com# add library path too if it's not in the default place 4427816Ssteve.reinhardt@amd.compy_lib_path = None 4437816Ssteve.reinhardt@amd.comif sys.exec_prefix != '/usr': 4447816Ssteve.reinhardt@amd.com py_lib_path = joinpath(sys.exec_prefix, 'lib') 4457816Ssteve.reinhardt@amd.comelif sys.platform == 'cygwin': 4467816Ssteve.reinhardt@amd.com # cygwin puts the .dll in /bin for some reason 4477816Ssteve.reinhardt@amd.com py_lib_path = '/bin' 4487816Ssteve.reinhardt@amd.comif py_lib_path: 4497816Ssteve.reinhardt@amd.com env.Append(LIBPATH = py_lib_path) 4507816Ssteve.reinhardt@amd.com print 'Adding', py_lib_path, 'to LIBPATH for', py_version_name 4517816Ssteve.reinhardt@amd.comif not conf.CheckLib(py_version_name): 4527816Ssteve.reinhardt@amd.com print "Error: can't find Python library", py_version_name 4537816Ssteve.reinhardt@amd.com Exit(1) 4547756SAli.Saidi@ARM.com 4557756SAli.Saidi@ARM.com# On Solaris you need to use libsocket for socket ops 4567756SAli.Saidi@ARM.comif not conf.CheckLibWithHeader(None, 'sys/socket.h', 'C++', 'accept(0,0,0);'): 4577756SAli.Saidi@ARM.com if not conf.CheckLibWithHeader('socket', 'sys/socket.h', 'C++', 'accept(0,0,0);'): 4587756SAli.Saidi@ARM.com print "Can't find library with socket calls (e.g. accept())" 4597756SAli.Saidi@ARM.com Exit(1) 4607816Ssteve.reinhardt@amd.com 4617816Ssteve.reinhardt@amd.com# Check for zlib. If the check passes, libz will be automatically 4627816Ssteve.reinhardt@amd.com# added to the LIBS environment variable. 4637816Ssteve.reinhardt@amd.comif not conf.CheckLibWithHeader('z', 'zlib.h', 'C++','zlibVersion();'): 4647816Ssteve.reinhardt@amd.com print 'Error: did not find needed zlib compression library '\ 4657816Ssteve.reinhardt@amd.com 'and/or zlib.h header file.' 4667816Ssteve.reinhardt@amd.com print ' Please install zlib and try again.' 4677816Ssteve.reinhardt@amd.com Exit(1) 4687816Ssteve.reinhardt@amd.com 4697816Ssteve.reinhardt@amd.com# Check for <fenv.h> (C99 FP environment control) 4707756SAli.Saidi@ARM.comhave_fenv = conf.CheckHeader('fenv.h', '<>') 4717756SAli.Saidi@ARM.comif not have_fenv: 4726654Snate@binkert.org print "Warning: Header file <fenv.h> not found." 4736654Snate@binkert.org print " This host has no IEEE FP rounding mode control." 4745871Snate@binkert.org 4756121Snate@binkert.org# Check for mysql. 4766121Snate@binkert.orgmysql_config = WhereIs('mysql_config') 4776121Snate@binkert.orghave_mysql = mysql_config != None 4786121Snate@binkert.org 4793940Ssaidi@eecs.umich.edu# Check MySQL version. 4803918Ssaidi@eecs.umich.eduif have_mysql: 4813918Ssaidi@eecs.umich.edu mysql_version = os.popen(mysql_config + ' --version').read() 4821858SN/A min_mysql_version = '4.1' 4836121Snate@binkert.org if compare_versions(mysql_version, min_mysql_version) < 0: 4847739Sgblack@eecs.umich.edu print 'Warning: MySQL', min_mysql_version, 'or newer required.' 4857739Sgblack@eecs.umich.edu print ' Version', mysql_version, 'detected.' 4866143Snate@binkert.org have_mysql = False 4877739Sgblack@eecs.umich.edu 4887618SAli.Saidi@arm.com# Set up mysql_config commands. 4897618SAli.Saidi@arm.comif have_mysql: 4907618SAli.Saidi@arm.com mysql_config_include = mysql_config + ' --include' 4917618SAli.Saidi@arm.com if os.system(mysql_config_include + ' > /dev/null') != 0: 4927618SAli.Saidi@arm.com # older mysql_config versions don't support --include, use 4937618SAli.Saidi@arm.com # --cflags instead 4947618SAli.Saidi@arm.com mysql_config_include = mysql_config + ' --cflags | sed s/\\\'//g' 4957739Sgblack@eecs.umich.edu # This seems to work in all versions 4966121Snate@binkert.org mysql_config_libs = mysql_config + ' --libs' 4973940Ssaidi@eecs.umich.edu 4986121Snate@binkert.orgenv = conf.Finish() 4997739Sgblack@eecs.umich.edu 5007739Sgblack@eecs.umich.edu# Define the universe of supported ISAs 5017739Sgblack@eecs.umich.eduall_isa_list = [ ] 5027739Sgblack@eecs.umich.eduExport('all_isa_list') 5037739Sgblack@eecs.umich.edu 5047739Sgblack@eecs.umich.edu# Define the universe of supported CPU models 5053918Ssaidi@eecs.umich.eduall_cpu_list = [ ] 5063918Ssaidi@eecs.umich.edudefault_cpus = [ ] 5073940Ssaidi@eecs.umich.eduExport('all_cpu_list', 'default_cpus') 5083918Ssaidi@eecs.umich.edu 5093918Ssaidi@eecs.umich.edu# Sticky options get saved in the options file so they persist from 5106157Snate@binkert.org# one invocation to the next (unless overridden, in which case the new 5116157Snate@binkert.org# value becomes sticky). 5126157Snate@binkert.orgsticky_opts = Options(args=ARGUMENTS) 5136157Snate@binkert.orgExport('sticky_opts') 5145397Ssaidi@eecs.umich.edu 5155397Ssaidi@eecs.umich.edu# Non-sticky options only apply to the current build. 5166121Snate@binkert.orgnonsticky_opts = Options(args=ARGUMENTS) 5176121Snate@binkert.orgExport('nonsticky_opts') 5186121Snate@binkert.org 5196121Snate@binkert.org# Walk the tree and execute all SConsopts scripts that wil add to the 5206121Snate@binkert.org# above options 5216121Snate@binkert.orgfor base_dir in base_dir_list: 5225397Ssaidi@eecs.umich.edu for root, dirs, files in os.walk(base_dir): 5231851SN/A if 'SConsopts' in files: 5241851SN/A print "Reading", joinpath(root, 'SConsopts') 5257739Sgblack@eecs.umich.edu SConscript(joinpath(root, 'SConsopts')) 526955SN/A 5273053Sstever@eecs.umich.eduall_isa_list.sort() 5286121Snate@binkert.orgall_cpu_list.sort() 5293053Sstever@eecs.umich.edudefault_cpus.sort() 5303053Sstever@eecs.umich.edu 5313053Sstever@eecs.umich.edusticky_opts.AddOptions( 5323053Sstever@eecs.umich.edu EnumOption('TARGET_ISA', 'Target ISA', 'alpha', all_isa_list), 5333053Sstever@eecs.umich.edu BoolOption('FULL_SYSTEM', 'Full-system support', False), 5346654Snate@binkert.org # There's a bug in scons 0.96.1 that causes ListOptions with list 5353053Sstever@eecs.umich.edu # values (more than one value) not to be able to be restored from 5364742Sstever@eecs.umich.edu # a saved option file. If this causes trouble then upgrade to 5374742Sstever@eecs.umich.edu # scons 0.96.90 or later. 5383053Sstever@eecs.umich.edu ListOption('CPU_MODELS', 'CPU models', default_cpus, all_cpu_list), 5393053Sstever@eecs.umich.edu BoolOption('NO_FAST_ALLOC', 'Disable fast object allocator', False), 5403053Sstever@eecs.umich.edu BoolOption('EFENCE', 'Link with Electric Fence malloc debugger', 5413053Sstever@eecs.umich.edu False), 5426654Snate@binkert.org BoolOption('SS_COMPATIBLE_FP', 5433053Sstever@eecs.umich.edu 'Make floating-point results compatible with SimpleScalar', 5443053Sstever@eecs.umich.edu False), 5453053Sstever@eecs.umich.edu BoolOption('USE_SSE2', 5463053Sstever@eecs.umich.edu 'Compile for SSE2 (-msse2) to get IEEE FP on x86 hosts', 5472667Sstever@eecs.umich.edu False), 5484554Sbinkertn@umich.edu BoolOption('USE_MYSQL', 'Use MySQL for stats output', have_mysql), 5496121Snate@binkert.org BoolOption('USE_FENV', 'Use <fenv.h> IEEE mode control', have_fenv), 5502667Sstever@eecs.umich.edu BoolOption('USE_CHECKER', 'Use checker for detailed CPU models', False), 5514554Sbinkertn@umich.edu BoolOption('BATCH', 'Use batch pool for build and tests', False), 5524554Sbinkertn@umich.edu ('BATCH_CMD', 'Batch pool submission command name', 'qdo'), 5534554Sbinkertn@umich.edu ('PYTHONHOME', 5546121Snate@binkert.org 'Override the default PYTHONHOME for this system (use with caution)', 5554554Sbinkertn@umich.edu '%s:%s' % (sys.prefix, sys.exec_prefix)), 5564554Sbinkertn@umich.edu ) 5574554Sbinkertn@umich.edu 5584781Snate@binkert.orgnonsticky_opts.AddOptions( 5594554Sbinkertn@umich.edu BoolOption('update_ref', 'Update test reference outputs', False) 5604554Sbinkertn@umich.edu ) 5612667Sstever@eecs.umich.edu 5624554Sbinkertn@umich.edu# These options get exported to #defines in config/*.hh (see src/SConscript). 5634554Sbinkertn@umich.eduenv.ExportOptions = ['FULL_SYSTEM', 'ALPHA_TLASER', 'USE_FENV', \ 5644554Sbinkertn@umich.edu 'USE_MYSQL', 'NO_FAST_ALLOC', 'SS_COMPATIBLE_FP', \ 5654554Sbinkertn@umich.edu 'USE_CHECKER', 'PYTHONHOME', 'TARGET_ISA'] 5662667Sstever@eecs.umich.edu 5674554Sbinkertn@umich.edu# Define a handy 'no-op' action 5682667Sstever@eecs.umich.edudef no_action(target, source, env): 5694554Sbinkertn@umich.edu return 0 5706121Snate@binkert.org 5712667Sstever@eecs.umich.eduenv.NoAction = Action(no_action, None) 5725522Snate@binkert.org 5735522Snate@binkert.org################################################### 5745522Snate@binkert.org# 5755522Snate@binkert.org# Define a SCons builder for configuration flag headers. 5765522Snate@binkert.org# 5775522Snate@binkert.org################################################### 5785522Snate@binkert.org 5795522Snate@binkert.org# This function generates a config header file that #defines the 5805522Snate@binkert.org# option symbol to the current option setting (0 or 1). The source 5815522Snate@binkert.org# operands are the name of the option and a Value node containing the 5825522Snate@binkert.org# value of the option. 5835522Snate@binkert.orgdef build_config_file(target, source, env): 5845522Snate@binkert.org (option, value) = [s.get_contents() for s in source] 5855522Snate@binkert.org f = file(str(target[0]), 'w') 5865522Snate@binkert.org print >> f, '#define', option, value 5875522Snate@binkert.org f.close() 5885522Snate@binkert.org return None 5895522Snate@binkert.org 5905522Snate@binkert.org# Generate the message to be printed when building the config file. 5915522Snate@binkert.orgdef build_config_file_string(target, source, env): 5925522Snate@binkert.org (option, value) = [s.get_contents() for s in source] 5935522Snate@binkert.org return "Defining %s as %s in %s." % (option, value, target[0]) 5945522Snate@binkert.org 5955522Snate@binkert.org# Combine the two functions into a scons Action object. 5965522Snate@binkert.orgconfig_action = Action(build_config_file, build_config_file_string) 5975522Snate@binkert.org 5982638Sstever@eecs.umich.edu# The emitter munges the source & target node lists to reflect what 5992638Sstever@eecs.umich.edu# we're really doing. 6006121Snate@binkert.orgdef config_emitter(target, source, env): 6013716Sstever@eecs.umich.edu # extract option name from Builder arg 6025522Snate@binkert.org option = str(target[0]) 6035522Snate@binkert.org # True target is config header file 6045522Snate@binkert.org target = joinpath('config', option.lower() + '.hh') 6055522Snate@binkert.org val = env[option] 6065522Snate@binkert.org if isinstance(val, bool): 6075522Snate@binkert.org # Force value to 0/1 6081858SN/A val = int(val) 6095227Ssaidi@eecs.umich.edu elif isinstance(val, str): 6105227Ssaidi@eecs.umich.edu val = '"' + val + '"' 6115227Ssaidi@eecs.umich.edu 6125227Ssaidi@eecs.umich.edu # Sources are option name & value (packaged in SCons Value nodes) 6136654Snate@binkert.org return ([target], [Value(option), Value(val)]) 6146654Snate@binkert.org 6157769SAli.Saidi@ARM.comconfig_builder = Builder(emitter = config_emitter, action = config_action) 6167769SAli.Saidi@ARM.com 6177769SAli.Saidi@ARM.comenv.Append(BUILDERS = { 'ConfigFile' : config_builder }) 6187769SAli.Saidi@ARM.com 6195227Ssaidi@eecs.umich.edu################################################### 6205227Ssaidi@eecs.umich.edu# 6215227Ssaidi@eecs.umich.edu# Define a SCons builder for copying files. This is used by the 6225204Sstever@gmail.com# Python zipfile code in src/python/SConscript, but is placed up here 6235204Sstever@gmail.com# since it's potentially more generally applicable. 6245204Sstever@gmail.com# 6255204Sstever@gmail.com################################################### 6265204Sstever@gmail.com 6275204Sstever@gmail.comcopy_builder = Builder(action = Copy("$TARGET", "$SOURCE")) 6285204Sstever@gmail.com 6295204Sstever@gmail.comenv.Append(BUILDERS = { 'CopyFile' : copy_builder }) 6305204Sstever@gmail.com 6315204Sstever@gmail.com################################################### 6325204Sstever@gmail.com# 6335204Sstever@gmail.com# Define a simple SCons builder to concatenate files. 6345204Sstever@gmail.com# 6355204Sstever@gmail.com# Used to append the Python zip archive to the executable. 6365204Sstever@gmail.com# 6375204Sstever@gmail.com################################################### 6385204Sstever@gmail.com 6396121Snate@binkert.orgconcat_builder = Builder(action = Action(['cat $SOURCES > $TARGET', 6405204Sstever@gmail.com 'chmod +x $TARGET'])) 6413118Sstever@eecs.umich.edu 6423118Sstever@eecs.umich.eduenv.Append(BUILDERS = { 'Concat' : concat_builder }) 6433118Sstever@eecs.umich.edu 6443118Sstever@eecs.umich.edu 6453118Sstever@eecs.umich.edu# libelf build is shared across all configs in the build root. 6465863Snate@binkert.orgenv.SConscript('ext/libelf/SConscript', 6473118Sstever@eecs.umich.edu build_dir = joinpath(build_root, 'libelf'), 6485863Snate@binkert.org exports = 'env') 6493118Sstever@eecs.umich.edu 6507457Snate@binkert.org################################################### 6517457Snate@binkert.org# 6525863Snate@binkert.org# This function is used to set up a directory with switching headers 6535863Snate@binkert.org# 6545863Snate@binkert.org################################################### 6555863Snate@binkert.org 6565863Snate@binkert.orgenv['ALL_ISA_LIST'] = all_isa_list 6575863Snate@binkert.orgdef make_switching_dir(dirname, switch_headers, env): 6585863Snate@binkert.org # Generate the header. target[0] is the full path of the output 6596003Snate@binkert.org # header to generate. 'source' is a dummy variable, since we get the 6605863Snate@binkert.org # list of ISAs from env['ALL_ISA_LIST']. 6615863Snate@binkert.org def gen_switch_hdr(target, source, env): 6625863Snate@binkert.org fname = str(target[0]) 6636120Snate@binkert.org basename = os.path.basename(fname) 6645863Snate@binkert.org f = open(fname, 'w') 6655863Snate@binkert.org f.write('#include "arch/isa_specific.hh"\n') 6665863Snate@binkert.org cond = '#if' 6676120Snate@binkert.org for isa in all_isa_list: 6686120Snate@binkert.org f.write('%s THE_ISA == %s_ISA\n#include "%s/%s/%s"\n' 6695863Snate@binkert.org % (cond, isa.upper(), dirname, isa, basename)) 6705863Snate@binkert.org cond = '#elif' 6716120Snate@binkert.org f.write('#else\n#error "THE_ISA not set"\n#endif\n') 6725863Snate@binkert.org f.close() 6736121Snate@binkert.org return 0 6746121Snate@binkert.org 6755863Snate@binkert.org # String to print when generating header 6767727SAli.Saidi@ARM.com def gen_switch_hdr_string(target, source, env): 6777727SAli.Saidi@ARM.com return "Generating switch header " + str(target[0]) 6787727SAli.Saidi@ARM.com 6797727SAli.Saidi@ARM.com # Build SCons Action object. 'varlist' specifies env vars that this 6807727SAli.Saidi@ARM.com # action depends on; when env['ALL_ISA_LIST'] changes these actions 6817727SAli.Saidi@ARM.com # should get re-executed. 6825863Snate@binkert.org switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 6833118Sstever@eecs.umich.edu varlist=['ALL_ISA_LIST']) 6845863Snate@binkert.org 6853118Sstever@eecs.umich.edu # Instantiate actions for each header 6863118Sstever@eecs.umich.edu for hdr in switch_headers: 6875863Snate@binkert.org env.Command(hdr, [], switch_hdr_action) 6885863Snate@binkert.orgExport('make_switching_dir') 6895863Snate@binkert.org 6905863Snate@binkert.org################################################### 6913118Sstever@eecs.umich.edu# 6923483Ssaidi@eecs.umich.edu# Define build environments for selected configurations. 6933494Ssaidi@eecs.umich.edu# 6943494Ssaidi@eecs.umich.edu################################################### 6953483Ssaidi@eecs.umich.edu 6963483Ssaidi@eecs.umich.edu# rename base env 6973483Ssaidi@eecs.umich.edubase_env = env 6983053Sstever@eecs.umich.edu 6993053Sstever@eecs.umich.edufor build_path in build_paths: 7003918Ssaidi@eecs.umich.edu print "Building in", build_path 7013053Sstever@eecs.umich.edu 7023053Sstever@eecs.umich.edu # Make a copy of the build-root environment to use for this config. 7033053Sstever@eecs.umich.edu env = base_env.Copy() 7043053Sstever@eecs.umich.edu env['BUILDDIR'] = build_path 7053053Sstever@eecs.umich.edu 7067840Snate@binkert.org # build_dir is the tail component of build path, and is used to 7077865Sgblack@eecs.umich.edu # determine the build parameters (e.g., 'ALPHA_SE') 7087865Sgblack@eecs.umich.edu (build_root, build_dir) = os.path.split(build_path) 7097865Sgblack@eecs.umich.edu 7107865Sgblack@eecs.umich.edu # Set env options according to the build directory config. 7117865Sgblack@eecs.umich.edu sticky_opts.files = [] 7127840Snate@binkert.org # Options for $BUILD_ROOT/$BUILD_DIR are stored in 7137840Snate@binkert.org # $BUILD_ROOT/options/$BUILD_DIR so you can nuke 7147840Snate@binkert.org # $BUILD_ROOT/$BUILD_DIR without losing your options settings. 7157840Snate@binkert.org current_opts_file = joinpath(build_root, 'options', build_dir) 7161858SN/A if isfile(current_opts_file): 7171858SN/A sticky_opts.files.append(current_opts_file) 7181858SN/A print "Using saved options file %s" % current_opts_file 7191858SN/A else: 7201858SN/A # Build dir-specific options file doesn't exist. 7211858SN/A 7225863Snate@binkert.org # Make sure the directory is there so we can create it later 7235863Snate@binkert.org opt_dir = os.path.dirname(current_opts_file) 7241859SN/A if not isdir(opt_dir): 7255863Snate@binkert.org os.mkdir(opt_dir) 7261858SN/A 7275863Snate@binkert.org # Get default build options from source tree. Options are 7281858SN/A # normally determined by name of $BUILD_DIR, but can be 7291859SN/A # overriden by 'default=' arg on command line. 7301859SN/A default_opts_file = joinpath('build_opts', 7316654Snate@binkert.org ARGUMENTS.get('default', build_dir)) 7323053Sstever@eecs.umich.edu if isfile(default_opts_file): 7336654Snate@binkert.org sticky_opts.files.append(default_opts_file) 7343053Sstever@eecs.umich.edu print "Options file %s not found,\n using defaults in %s" \ 7353053Sstever@eecs.umich.edu % (current_opts_file, default_opts_file) 7361859SN/A else: 7371859SN/A print "Error: cannot find options file %s or %s" \ 7381859SN/A % (current_opts_file, default_opts_file) 7391859SN/A Exit(1) 7401859SN/A 7411859SN/A # Apply current option settings to env 7421859SN/A sticky_opts.Update(env) 7431859SN/A nonsticky_opts.Update(env) 7441862SN/A 7451859SN/A help_text += "\nSticky options for %s:\n" % build_dir \ 7461859SN/A + sticky_opts.GenerateHelpText(env) \ 7471859SN/A + "\nNon-sticky options for %s:\n" % build_dir \ 7485863Snate@binkert.org + nonsticky_opts.GenerateHelpText(env) 7495863Snate@binkert.org 7505863Snate@binkert.org # Process option settings. 7515863Snate@binkert.org 7526121Snate@binkert.org if not have_fenv and env['USE_FENV']: 7531858SN/A print "Warning: <fenv.h> not available; " \ 7545863Snate@binkert.org "forcing USE_FENV to False in", build_dir + "." 7555863Snate@binkert.org env['USE_FENV'] = False 7565863Snate@binkert.org 7575863Snate@binkert.org if not env['USE_FENV']: 7585863Snate@binkert.org print "Warning: No IEEE FP rounding mode control in", build_dir + "." 7592139SN/A print " FP results may deviate slightly from other platforms." 7604202Sbinkertn@umich.edu 7614202Sbinkertn@umich.edu if env['EFENCE']: 7622139SN/A env.Append(LIBS=['efence']) 7636994Snate@binkert.org 7646994Snate@binkert.org if env['USE_MYSQL']: 7656994Snate@binkert.org if not have_mysql: 7666994Snate@binkert.org print "Warning: MySQL not available; " \ 7676994Snate@binkert.org "forcing USE_MYSQL to False in", build_dir + "." 7686994Snate@binkert.org env['USE_MYSQL'] = False 7696994Snate@binkert.org else: 7706994Snate@binkert.org print "Compiling in", build_dir, "with MySQL support." 7716994Snate@binkert.org env.ParseConfig(mysql_config_libs) 7726994Snate@binkert.org env.ParseConfig(mysql_config_include) 7736994Snate@binkert.org 7746994Snate@binkert.org # Save sticky option settings back to current options file 7756994Snate@binkert.org sticky_opts.Save(current_opts_file, env) 7766994Snate@binkert.org 7776994Snate@binkert.org # Do this after we save setting back, or else we'll tack on an 7786994Snate@binkert.org # extra 'qdo' every time we run scons. 7796994Snate@binkert.org if env['BATCH']: 7806994Snate@binkert.org env['CC'] = env['BATCH_CMD'] + ' ' + env['CC'] 7816994Snate@binkert.org env['CXX'] = env['BATCH_CMD'] + ' ' + env['CXX'] 7826994Snate@binkert.org 7836994Snate@binkert.org if env['USE_SSE2']: 7846994Snate@binkert.org env.Append(CCFLAGS='-msse2') 7856994Snate@binkert.org 7866994Snate@binkert.org # The src/SConscript file sets up the build rules in 'env' according 7876994Snate@binkert.org # to the configured options. It returns a list of environments, 7886994Snate@binkert.org # one for each variant build (debug, opt, etc.) 7896994Snate@binkert.org envList = SConscript('src/SConscript', build_dir = build_path, 7906994Snate@binkert.org exports = 'env') 7912155SN/A 7925863Snate@binkert.org # Set up the regression tests for each build. 7931869SN/A for e in envList: 7941869SN/A SConscript('tests/SConscript', 7955863Snate@binkert.org build_dir = joinpath(build_path, 'tests', e.Label), 7965863Snate@binkert.org exports = { 'env' : e }, duplicate = False) 7974202Sbinkertn@umich.edu 7986108Snate@binkert.orgHelp(help_text) 7996108Snate@binkert.org 8006108Snate@binkert.org 8016108Snate@binkert.org################################################### 8024202Sbinkertn@umich.edu# 8035863Snate@binkert.org# Let SCons do its thing. At this point SCons will use the defined 8045742Snate@binkert.org# build environments to build the requested targets. 8055742Snate@binkert.org# 8065341Sstever@gmail.com################################################### 8075342Sstever@gmail.com 8085342Sstever@gmail.com