SConscript revision 10301
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan 4955SN/A# All rights reserved. 5955SN/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. 282665Ssaidi@eecs.umich.edu# 294762Snate@binkert.org# Authors: Nathan Binkert 30955SN/A 314762Snate@binkert.orgimport array 32955SN/Aimport bisect 33955SN/Aimport imp 344202Sbinkertn@umich.eduimport marshal 355342Sstever@gmail.comimport os 36955SN/Aimport re 374381Sbinkertn@umich.eduimport sys 384381Sbinkertn@umich.eduimport zlib 39955SN/A 40955SN/Afrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 41955SN/A 424202Sbinkertn@umich.eduimport SCons 43955SN/A 444382Sbinkertn@umich.edu# This file defines how to build a particular configuration of gem5 454382Sbinkertn@umich.edu# based on variable settings in the 'env' build environment. 464382Sbinkertn@umich.edu 474762Snate@binkert.orgImport('*') 484762Snate@binkert.org 494762Snate@binkert.org# Children need to see the environment 504762Snate@binkert.orgExport('env') 514762Snate@binkert.org 524762Snate@binkert.orgbuild_env = [(opt, env[opt]) for opt in export_vars] 534762Snate@binkert.org 544762Snate@binkert.orgfrom m5.util import code_formatter, compareVersions 554762Snate@binkert.org 564762Snate@binkert.org######################################################################## 574762Snate@binkert.org# Code for adding source files of various types 584762Snate@binkert.org# 594762Snate@binkert.org# When specifying a source file of some type, a set of guards can be 604762Snate@binkert.org# specified for that file. When get() is used to find the files, if 614762Snate@binkert.org# get specifies a set of filters, only files that match those filters 624762Snate@binkert.org# will be accepted (unspecified filters on files are assumed to be 634762Snate@binkert.org# false). Current filters are: 644762Snate@binkert.org# main -- specifies the gem5 main() function 654762Snate@binkert.org# skip_lib -- do not put this file into the gem5 library 664762Snate@binkert.org# <unittest> -- unit tests use filters based on the unit test name 674762Snate@binkert.org# 684762Snate@binkert.org# A parent can now be specified for a source file and default filter 694762Snate@binkert.org# values will be retrieved recursively from parents (children override 704762Snate@binkert.org# parents). 714762Snate@binkert.org# 724762Snate@binkert.orgclass SourceMeta(type): 734762Snate@binkert.org '''Meta class for source files that keeps track of all files of a 744762Snate@binkert.org particular type and has a get function for finding all functions 754762Snate@binkert.org of a certain type that match a set of guards''' 764762Snate@binkert.org def __init__(cls, name, bases, dict): 774762Snate@binkert.org super(SourceMeta, cls).__init__(name, bases, dict) 784762Snate@binkert.org cls.all = [] 794762Snate@binkert.org 804382Sbinkertn@umich.edu def get(cls, **guards): 814762Snate@binkert.org '''Find all files that match the specified guards. If a source 824382Sbinkertn@umich.edu file does not specify a flag, the default is False''' 834762Snate@binkert.org for src in cls.all: 844381Sbinkertn@umich.edu for flag,value in guards.iteritems(): 854762Snate@binkert.org # if the flag is found and has a different value, skip 864762Snate@binkert.org # this file 874762Snate@binkert.org if src.all_guards.get(flag, False) != value: 884762Snate@binkert.org break 894762Snate@binkert.org else: 904762Snate@binkert.org yield src 914762Snate@binkert.org 924762Snate@binkert.orgclass SourceFile(object): 934762Snate@binkert.org '''Base object that encapsulates the notion of a source file. 944762Snate@binkert.org This includes, the source node, target node, various manipulations 954762Snate@binkert.org of those. A source file also specifies a set of guards which 964762Snate@binkert.org describing which builds the source file applies to. A parent can 974762Snate@binkert.org also be specified to get default guards from''' 984762Snate@binkert.org __metaclass__ = SourceMeta 994762Snate@binkert.org def __init__(self, source, parent=None, **guards): 1004762Snate@binkert.org self.guards = guards 1014762Snate@binkert.org self.parent = parent 1024762Snate@binkert.org 1034762Snate@binkert.org tnode = source 1044762Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1054762Snate@binkert.org tnode = File(source) 1064762Snate@binkert.org 1074762Snate@binkert.org self.tnode = tnode 1084762Snate@binkert.org self.snode = tnode.srcnode() 1094762Snate@binkert.org 1104762Snate@binkert.org for base in type(self).__mro__: 1114762Snate@binkert.org if issubclass(base, SourceFile): 1124762Snate@binkert.org base.all.append(self) 1134762Snate@binkert.org 1144762Snate@binkert.org @property 1154762Snate@binkert.org def filename(self): 1164762Snate@binkert.org return str(self.tnode) 1174762Snate@binkert.org 1184762Snate@binkert.org @property 1194762Snate@binkert.org def dirname(self): 1204762Snate@binkert.org return dirname(self.filename) 1214762Snate@binkert.org 1224762Snate@binkert.org @property 1234762Snate@binkert.org def basename(self): 1244762Snate@binkert.org return basename(self.filename) 125955SN/A 1264382Sbinkertn@umich.edu @property 1274202Sbinkertn@umich.edu def extname(self): 1284382Sbinkertn@umich.edu index = self.basename.rfind('.') 1294382Sbinkertn@umich.edu if index <= 0: 1304382Sbinkertn@umich.edu # dot files aren't extensions 1314382Sbinkertn@umich.edu return self.basename, None 1324382Sbinkertn@umich.edu 1334382Sbinkertn@umich.edu return self.basename[:index], self.basename[index+1:] 1345192Ssaidi@eecs.umich.edu 1355192Ssaidi@eecs.umich.edu @property 1365192Ssaidi@eecs.umich.edu def all_guards(self): 1375192Ssaidi@eecs.umich.edu '''find all guards for this object getting default values 1385192Ssaidi@eecs.umich.edu recursively from its parents''' 1395192Ssaidi@eecs.umich.edu guards = {} 1405192Ssaidi@eecs.umich.edu if self.parent: 1415192Ssaidi@eecs.umich.edu guards.update(self.parent.guards) 1425192Ssaidi@eecs.umich.edu guards.update(self.guards) 1435192Ssaidi@eecs.umich.edu return guards 1445192Ssaidi@eecs.umich.edu 1455192Ssaidi@eecs.umich.edu def __lt__(self, other): return self.filename < other.filename 1465192Ssaidi@eecs.umich.edu def __le__(self, other): return self.filename <= other.filename 1475192Ssaidi@eecs.umich.edu def __gt__(self, other): return self.filename > other.filename 1485192Ssaidi@eecs.umich.edu def __ge__(self, other): return self.filename >= other.filename 1495192Ssaidi@eecs.umich.edu def __eq__(self, other): return self.filename == other.filename 1505192Ssaidi@eecs.umich.edu def __ne__(self, other): return self.filename != other.filename 1515192Ssaidi@eecs.umich.edu 1525192Ssaidi@eecs.umich.edu @staticmethod 1535192Ssaidi@eecs.umich.edu def done(): 1545192Ssaidi@eecs.umich.edu def disabled(cls, name, *ignored): 1555192Ssaidi@eecs.umich.edu raise RuntimeError("Additional SourceFile '%s'" % name,\ 1565192Ssaidi@eecs.umich.edu "declared, but targets deps are already fixed.") 1575192Ssaidi@eecs.umich.edu SourceFile.__init__ = disabled 1585192Ssaidi@eecs.umich.edu 1595192Ssaidi@eecs.umich.edu 1605192Ssaidi@eecs.umich.educlass Source(SourceFile): 1615192Ssaidi@eecs.umich.edu '''Add a c/c++ source file to the build''' 1625192Ssaidi@eecs.umich.edu def __init__(self, source, Werror=True, swig=False, **guards): 1635192Ssaidi@eecs.umich.edu '''specify the source file, and any guards''' 1645192Ssaidi@eecs.umich.edu super(Source, self).__init__(source, **guards) 1655192Ssaidi@eecs.umich.edu 1664382Sbinkertn@umich.edu self.Werror = Werror 1674382Sbinkertn@umich.edu self.swig = swig 1684382Sbinkertn@umich.edu 1692667Sstever@eecs.umich.educlass PySource(SourceFile): 1702667Sstever@eecs.umich.edu '''Add a python source file to the named package''' 1712667Sstever@eecs.umich.edu invalid_sym_char = re.compile('[^A-z0-9_]') 1722667Sstever@eecs.umich.edu modules = {} 1732667Sstever@eecs.umich.edu tnodes = {} 1742667Sstever@eecs.umich.edu symnames = {} 1752037SN/A 1762037SN/A def __init__(self, package, source, **guards): 1772037SN/A '''specify the python package, the source file, and any guards''' 1784382Sbinkertn@umich.edu super(PySource, self).__init__(source, **guards) 1794762Snate@binkert.org 1805344Sstever@gmail.com modname,ext = self.extname 1814382Sbinkertn@umich.edu assert ext == 'py' 1825341Sstever@gmail.com 1835341Sstever@gmail.com if package: 1845341Sstever@gmail.com path = package.split('.') 1855344Sstever@gmail.com else: 1865341Sstever@gmail.com path = [] 1875341Sstever@gmail.com 1885341Sstever@gmail.com modpath = path[:] 1894762Snate@binkert.org if modname != '__init__': 1905341Sstever@gmail.com modpath += [ modname ] 1915344Sstever@gmail.com modpath = '.'.join(modpath) 1925341Sstever@gmail.com 1934773Snate@binkert.org arcpath = path + [ self.basename ] 1941858SN/A abspath = self.snode.abspath 1951858SN/A if not exists(abspath): 1961085SN/A abspath = self.tnode.abspath 1974382Sbinkertn@umich.edu 1984382Sbinkertn@umich.edu self.package = package 1994762Snate@binkert.org self.modname = modname 2004762Snate@binkert.org self.modpath = modpath 2014762Snate@binkert.org self.arcname = joinpath(*arcpath) 2024762Snate@binkert.org self.abspath = abspath 2034762Snate@binkert.org self.compiled = File(self.filename + 'c') 2044762Snate@binkert.org self.cpp = File(self.filename + '.cc') 2054762Snate@binkert.org self.symname = PySource.invalid_sym_char.sub('_', modpath) 2064762Snate@binkert.org 2074762Snate@binkert.org PySource.modules[modpath] = self 2084762Snate@binkert.org PySource.tnodes[self.tnode] = self 2094762Snate@binkert.org PySource.symnames[self.symname] = self 2104762Snate@binkert.org 2114762Snate@binkert.orgclass SimObject(PySource): 2124762Snate@binkert.org '''Add a SimObject python file as a python source object and add 2134762Snate@binkert.org it to a list of sim object modules''' 2144762Snate@binkert.org 2154762Snate@binkert.org fixed = False 2164762Snate@binkert.org modnames = [] 2174762Snate@binkert.org 2184762Snate@binkert.org def __init__(self, source, **guards): 2194762Snate@binkert.org '''Specify the source file and any guards (automatically in 2204762Snate@binkert.org the m5.objects package)''' 2214762Snate@binkert.org super(SimObject, self).__init__('m5.objects', source, **guards) 2224762Snate@binkert.org if self.fixed: 2234762Snate@binkert.org raise AttributeError, "Too late to call SimObject now." 2244762Snate@binkert.org 2254762Snate@binkert.org bisect.insort_right(SimObject.modnames, self.modname) 2264762Snate@binkert.org 2274762Snate@binkert.orgclass SwigSource(SourceFile): 2284762Snate@binkert.org '''Add a swig file to build''' 2294762Snate@binkert.org 2304762Snate@binkert.org def __init__(self, package, source, **guards): 2314762Snate@binkert.org '''Specify the python package, the source file, and any guards''' 2324762Snate@binkert.org super(SwigSource, self).__init__(source, **guards) 2334762Snate@binkert.org 2344382Sbinkertn@umich.edu modname,ext = self.extname 2354382Sbinkertn@umich.edu assert ext == 'i' 2364762Snate@binkert.org 2374762Snate@binkert.org self.module = modname 2384762Snate@binkert.org cc_file = joinpath(self.dirname, modname + '_wrap.cc') 2394382Sbinkertn@umich.edu py_file = joinpath(self.dirname, modname + '.py') 2404382Sbinkertn@umich.edu 2414762Snate@binkert.org self.cc_source = Source(cc_file, swig=True, parent=self) 2424382Sbinkertn@umich.edu self.py_source = PySource(package, py_file, parent=self) 2434382Sbinkertn@umich.edu 2444762Snate@binkert.orgclass ProtoBuf(SourceFile): 2454382Sbinkertn@umich.edu '''Add a Protocol Buffer to build''' 2464382Sbinkertn@umich.edu 2474762Snate@binkert.org def __init__(self, source, **guards): 2484382Sbinkertn@umich.edu '''Specify the source file, and any guards''' 2494762Snate@binkert.org super(ProtoBuf, self).__init__(source, **guards) 2504762Snate@binkert.org 2514382Sbinkertn@umich.edu # Get the file name and the extension 2524382Sbinkertn@umich.edu modname,ext = self.extname 2534762Snate@binkert.org assert ext == 'proto' 2544762Snate@binkert.org 2554762Snate@binkert.org # Currently, we stick to generating the C++ headers, so we 2564762Snate@binkert.org # only need to track the source and header. 2574762Snate@binkert.org self.cc_file = File(modname + '.pb.cc') 2584762Snate@binkert.org self.hh_file = File(modname + '.pb.h') 2594762Snate@binkert.org 2604762Snate@binkert.orgclass UnitTest(object): 2614762Snate@binkert.org '''Create a UnitTest''' 2624762Snate@binkert.org 2634762Snate@binkert.org all = [] 2644762Snate@binkert.org def __init__(self, target, *sources, **kwargs): 2654762Snate@binkert.org '''Specify the target name and any sources. Sources that are 2664762Snate@binkert.org not SourceFiles are evalued with Source(). All files are 2674762Snate@binkert.org guarded with a guard of the same name as the UnitTest 2684762Snate@binkert.org target.''' 2694762Snate@binkert.org 2704762Snate@binkert.org srcs = [] 2714762Snate@binkert.org for src in sources: 2724762Snate@binkert.org if not isinstance(src, SourceFile): 2734762Snate@binkert.org src = Source(src, skip_lib=True) 2744762Snate@binkert.org src.guards[target] = True 2754762Snate@binkert.org srcs.append(src) 2764762Snate@binkert.org 2774762Snate@binkert.org self.sources = srcs 2784762Snate@binkert.org self.target = target 2794762Snate@binkert.org self.main = kwargs.get('main', False) 2804762Snate@binkert.org UnitTest.all.append(self) 2814762Snate@binkert.org 2824762Snate@binkert.org# Children should have access 2834762Snate@binkert.orgExport('Source') 2844762Snate@binkert.orgExport('PySource') 2854762Snate@binkert.orgExport('SimObject') 2864762Snate@binkert.orgExport('SwigSource') 2874762Snate@binkert.orgExport('ProtoBuf') 2884762Snate@binkert.orgExport('UnitTest') 2894762Snate@binkert.org 2904762Snate@binkert.org######################################################################## 2914762Snate@binkert.org# 2924762Snate@binkert.org# Debug Flags 2934762Snate@binkert.org# 2944762Snate@binkert.orgdebug_flags = {} 2954762Snate@binkert.orgdef DebugFlag(name, desc=None): 2964762Snate@binkert.org if name in debug_flags: 2974762Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 2984762Snate@binkert.org debug_flags[name] = (name, (), desc) 2994762Snate@binkert.org 3004762Snate@binkert.orgdef CompoundFlag(name, flags, desc=None): 3014762Snate@binkert.org if name in debug_flags: 3024382Sbinkertn@umich.edu raise AttributeError, "Flag %s already specified" % name 3034762Snate@binkert.org 3044382Sbinkertn@umich.edu compound = tuple(flags) 3054762Snate@binkert.org debug_flags[name] = (name, compound, desc) 3064382Sbinkertn@umich.edu 3074762Snate@binkert.orgExport('DebugFlag') 3084762Snate@binkert.orgExport('CompoundFlag') 3094762Snate@binkert.org 3104762Snate@binkert.org######################################################################## 3114382Sbinkertn@umich.edu# 3124382Sbinkertn@umich.edu# Set some compiler variables 3134382Sbinkertn@umich.edu# 3144382Sbinkertn@umich.edu 3154382Sbinkertn@umich.edu# Include file paths are rooted in this directory. SCons will 3164382Sbinkertn@umich.edu# automatically expand '.' to refer to both the source directory and 3174762Snate@binkert.org# the corresponding build directory to pick up generated include 3184382Sbinkertn@umich.edu# files. 3194382Sbinkertn@umich.eduenv.Append(CPPPATH=Dir('.')) 3204382Sbinkertn@umich.edu 3214382Sbinkertn@umich.edufor extra_dir in extras_dir_list: 3224762Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 3234762Snate@binkert.org 3244762Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 3254382Sbinkertn@umich.edu# Scons bug id: 2006 gem5 Bug id: 308 3265192Ssaidi@eecs.umich.edufor root, dirs, files in os.walk(base_dir, topdown=True): 3275192Ssaidi@eecs.umich.edu Dir(root[len(base_dir) + 1:]) 3285192Ssaidi@eecs.umich.edu 3295192Ssaidi@eecs.umich.edu######################################################################## 3305192Ssaidi@eecs.umich.edu# 3315192Ssaidi@eecs.umich.edu# Walk the tree and execute all SConscripts in subdirectories 3325192Ssaidi@eecs.umich.edu# 3335192Ssaidi@eecs.umich.edu 3345192Ssaidi@eecs.umich.eduhere = Dir('.').srcnode().abspath 3354762Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 3364382Sbinkertn@umich.edu if root == here: 3374382Sbinkertn@umich.edu # we don't want to recurse back into this SConscript 3384382Sbinkertn@umich.edu continue 3394762Snate@binkert.org 3404762Snate@binkert.org if 'SConscript' in files: 3414382Sbinkertn@umich.edu build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 3424382Sbinkertn@umich.edu SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3434382Sbinkertn@umich.edu 3444762Snate@binkert.orgfor extra_dir in extras_dir_list: 3454382Sbinkertn@umich.edu prefix_len = len(dirname(extra_dir)) + 1 3464382Sbinkertn@umich.edu 3474762Snate@binkert.org # Also add the corresponding build directory to pick up generated 3484762Snate@binkert.org # include files. 3494762Snate@binkert.org env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:]))) 3504382Sbinkertn@umich.edu 3514382Sbinkertn@umich.edu for root, dirs, files in os.walk(extra_dir, topdown=True): 3524382Sbinkertn@umich.edu # if build lives in the extras directory, don't walk down it 3534382Sbinkertn@umich.edu if 'build' in dirs: 3544382Sbinkertn@umich.edu dirs.remove('build') 3554382Sbinkertn@umich.edu 3564382Sbinkertn@umich.edu if 'SConscript' in files: 3574382Sbinkertn@umich.edu build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 3584382Sbinkertn@umich.edu SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3594382Sbinkertn@umich.edu 360955SN/Afor opt in export_vars: 361955SN/A env.ConfigFile(opt) 362955SN/A 363955SN/Adef makeTheISA(source, target, env): 3641108SN/A isas = [ src.get_contents() for src in source ] 365955SN/A target_isa = env['TARGET_ISA'] 366955SN/A def define(isa): 367955SN/A return isa.upper() + '_ISA' 368955SN/A 369955SN/A def namespace(isa): 370955SN/A return isa[0].upper() + isa[1:].lower() + 'ISA' 371955SN/A 372955SN/A 373955SN/A code = code_formatter() 3742655Sstever@eecs.umich.edu code('''\ 3752655Sstever@eecs.umich.edu#ifndef __CONFIG_THE_ISA_HH__ 3762655Sstever@eecs.umich.edu#define __CONFIG_THE_ISA_HH__ 3772655Sstever@eecs.umich.edu 3782655Sstever@eecs.umich.edu''') 3792655Sstever@eecs.umich.edu 3802655Sstever@eecs.umich.edu for i,isa in enumerate(isas): 3812655Sstever@eecs.umich.edu code('#define $0 $1', define(isa), i + 1) 3822655Sstever@eecs.umich.edu 3832655Sstever@eecs.umich.edu code(''' 3844762Snate@binkert.org 3852655Sstever@eecs.umich.edu#define THE_ISA ${{define(target_isa)}} 3862655Sstever@eecs.umich.edu#define TheISA ${{namespace(target_isa)}} 3874007Ssaidi@eecs.umich.edu#define THE_ISA_STR "${{target_isa}}" 3884596Sbinkertn@umich.edu 3894007Ssaidi@eecs.umich.edu#endif // __CONFIG_THE_ISA_HH__''') 3904596Sbinkertn@umich.edu 3914596Sbinkertn@umich.edu code.write(str(target[0])) 3922655Sstever@eecs.umich.edu 3934382Sbinkertn@umich.eduenv.Command('config/the_isa.hh', map(Value, all_isa_list), 3942655Sstever@eecs.umich.edu MakeAction(makeTheISA, Transform("CFG ISA", 0))) 3952655Sstever@eecs.umich.edu 3962655Sstever@eecs.umich.edu######################################################################## 397955SN/A# 3983918Ssaidi@eecs.umich.edu# Prevent any SimObjects from being added after this point, they 3993918Ssaidi@eecs.umich.edu# should all have been added in the SConscripts above 4003918Ssaidi@eecs.umich.edu# 4013918Ssaidi@eecs.umich.eduSimObject.fixed = True 4023918Ssaidi@eecs.umich.edu 4033918Ssaidi@eecs.umich.educlass DictImporter(object): 4043918Ssaidi@eecs.umich.edu '''This importer takes a dictionary of arbitrary module names that 4053918Ssaidi@eecs.umich.edu map to arbitrary filenames.''' 4063918Ssaidi@eecs.umich.edu def __init__(self, modules): 4073918Ssaidi@eecs.umich.edu self.modules = modules 4083918Ssaidi@eecs.umich.edu self.installed = set() 4093918Ssaidi@eecs.umich.edu 4103918Ssaidi@eecs.umich.edu def __del__(self): 4113918Ssaidi@eecs.umich.edu self.unload() 4123940Ssaidi@eecs.umich.edu 4133940Ssaidi@eecs.umich.edu def unload(self): 4143940Ssaidi@eecs.umich.edu import sys 4153942Ssaidi@eecs.umich.edu for module in self.installed: 4163940Ssaidi@eecs.umich.edu del sys.modules[module] 4173515Ssaidi@eecs.umich.edu self.installed = set() 4183918Ssaidi@eecs.umich.edu 4194762Snate@binkert.org def find_module(self, fullname, path): 4203515Ssaidi@eecs.umich.edu if fullname == 'm5.defines': 4212655Sstever@eecs.umich.edu return self 4223918Ssaidi@eecs.umich.edu 4233619Sbinkertn@umich.edu if fullname == 'm5.objects': 424955SN/A return self 425955SN/A 4262655Sstever@eecs.umich.edu if fullname.startswith('m5.internal'): 4273918Ssaidi@eecs.umich.edu return None 4283619Sbinkertn@umich.edu 429955SN/A source = self.modules.get(fullname, None) 430955SN/A if source is not None and fullname.startswith('m5.objects'): 4312655Sstever@eecs.umich.edu return self 4323918Ssaidi@eecs.umich.edu 4333619Sbinkertn@umich.edu return None 434955SN/A 435955SN/A def load_module(self, fullname): 4362655Sstever@eecs.umich.edu mod = imp.new_module(fullname) 4373918Ssaidi@eecs.umich.edu sys.modules[fullname] = mod 4383683Sstever@eecs.umich.edu self.installed.add(fullname) 4392655Sstever@eecs.umich.edu 4401869SN/A mod.__loader__ = self 4411869SN/A if fullname == 'm5.objects': 442 mod.__path__ = fullname.split('.') 443 return mod 444 445 if fullname == 'm5.defines': 446 mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 447 return mod 448 449 source = self.modules[fullname] 450 if source.modname == '__init__': 451 mod.__path__ = source.modpath 452 mod.__file__ = source.abspath 453 454 exec file(source.abspath, 'r') in mod.__dict__ 455 456 return mod 457 458import m5.SimObject 459import m5.params 460from m5.util import code_formatter 461 462m5.SimObject.clear() 463m5.params.clear() 464 465# install the python importer so we can grab stuff from the source 466# tree itself. We can't have SimObjects added after this point or 467# else we won't know about them for the rest of the stuff. 468importer = DictImporter(PySource.modules) 469sys.meta_path[0:0] = [ importer ] 470 471# import all sim objects so we can populate the all_objects list 472# make sure that we're working with a list, then let's sort it 473for modname in SimObject.modnames: 474 exec('from m5.objects import %s' % modname) 475 476# we need to unload all of the currently imported modules so that they 477# will be re-imported the next time the sconscript is run 478importer.unload() 479sys.meta_path.remove(importer) 480 481sim_objects = m5.SimObject.allClasses 482all_enums = m5.params.allEnums 483 484if m5.SimObject.noCxxHeader: 485 print >> sys.stderr, \ 486 "warning: At least one SimObject lacks a header specification. " \ 487 "This can cause unexpected results in the generated SWIG " \ 488 "wrappers." 489 490# Find param types that need to be explicitly wrapped with swig. 491# These will be recognized because the ParamDesc will have a 492# swig_decl() method. Most param types are based on types that don't 493# need this, either because they're based on native types (like Int) 494# or because they're SimObjects (which get swigged independently). 495# For now the only things handled here are VectorParam types. 496params_to_swig = {} 497for name,obj in sorted(sim_objects.iteritems()): 498 for param in obj._params.local.values(): 499 # load the ptype attribute now because it depends on the 500 # current version of SimObject.allClasses, but when scons 501 # actually uses the value, all versions of 502 # SimObject.allClasses will have been loaded 503 param.ptype 504 505 if not hasattr(param, 'swig_decl'): 506 continue 507 pname = param.ptype_str 508 if pname not in params_to_swig: 509 params_to_swig[pname] = param 510 511######################################################################## 512# 513# calculate extra dependencies 514# 515module_depends = ["m5", "m5.SimObject", "m5.params"] 516depends = [ PySource.modules[dep].snode for dep in module_depends ] 517 518######################################################################## 519# 520# Commands for the basic automatically generated python files 521# 522 523# Generate Python file containing a dict specifying the current 524# buildEnv flags. 525def makeDefinesPyFile(target, source, env): 526 build_env = source[0].get_contents() 527 528 code = code_formatter() 529 code(""" 530import m5.internal 531import m5.util 532 533buildEnv = m5.util.SmartDict($build_env) 534 535compileDate = m5.internal.core.compileDate 536_globals = globals() 537for key,val in m5.internal.core.__dict__.iteritems(): 538 if key.startswith('flag_'): 539 flag = key[5:] 540 _globals[flag] = val 541del _globals 542""") 543 code.write(target[0].abspath) 544 545defines_info = Value(build_env) 546# Generate a file with all of the compile options in it 547env.Command('python/m5/defines.py', defines_info, 548 MakeAction(makeDefinesPyFile, Transform("DEFINES", 0))) 549PySource('m5', 'python/m5/defines.py') 550 551# Generate python file containing info about the M5 source code 552def makeInfoPyFile(target, source, env): 553 code = code_formatter() 554 for src in source: 555 data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 556 code('$src = ${{repr(data)}}') 557 code.write(str(target[0])) 558 559# Generate a file that wraps the basic top level files 560env.Command('python/m5/info.py', 561 [ '#/COPYING', '#/LICENSE', '#/README', ], 562 MakeAction(makeInfoPyFile, Transform("INFO"))) 563PySource('m5', 'python/m5/info.py') 564 565######################################################################## 566# 567# Create all of the SimObject param headers and enum headers 568# 569 570def createSimObjectParamStruct(target, source, env): 571 assert len(target) == 1 and len(source) == 1 572 573 name = str(source[0].get_contents()) 574 obj = sim_objects[name] 575 576 code = code_formatter() 577 obj.cxx_param_decl(code) 578 code.write(target[0].abspath) 579 580def createParamSwigWrapper(target, source, env): 581 assert len(target) == 1 and len(source) == 1 582 583 name = str(source[0].get_contents()) 584 param = params_to_swig[name] 585 586 code = code_formatter() 587 param.swig_decl(code) 588 code.write(target[0].abspath) 589 590def createEnumStrings(target, source, env): 591 assert len(target) == 1 and len(source) == 1 592 593 name = str(source[0].get_contents()) 594 obj = all_enums[name] 595 596 code = code_formatter() 597 obj.cxx_def(code) 598 code.write(target[0].abspath) 599 600def createEnumDecls(target, source, env): 601 assert len(target) == 1 and len(source) == 1 602 603 name = str(source[0].get_contents()) 604 obj = all_enums[name] 605 606 code = code_formatter() 607 obj.cxx_decl(code) 608 code.write(target[0].abspath) 609 610def createEnumSwigWrapper(target, source, env): 611 assert len(target) == 1 and len(source) == 1 612 613 name = str(source[0].get_contents()) 614 obj = all_enums[name] 615 616 code = code_formatter() 617 obj.swig_decl(code) 618 code.write(target[0].abspath) 619 620def createSimObjectSwigWrapper(target, source, env): 621 name = source[0].get_contents() 622 obj = sim_objects[name] 623 624 code = code_formatter() 625 obj.swig_decl(code) 626 code.write(target[0].abspath) 627 628# Generate all of the SimObject param C++ struct header files 629params_hh_files = [] 630for name,simobj in sorted(sim_objects.iteritems()): 631 py_source = PySource.modules[simobj.__module__] 632 extra_deps = [ py_source.tnode ] 633 634 hh_file = File('params/%s.hh' % name) 635 params_hh_files.append(hh_file) 636 env.Command(hh_file, Value(name), 637 MakeAction(createSimObjectParamStruct, Transform("SO PARAM"))) 638 env.Depends(hh_file, depends + extra_deps) 639 640# Generate any needed param SWIG wrapper files 641params_i_files = [] 642for name,param in params_to_swig.iteritems(): 643 i_file = File('python/m5/internal/%s.i' % (param.swig_module_name())) 644 params_i_files.append(i_file) 645 env.Command(i_file, Value(name), 646 MakeAction(createParamSwigWrapper, Transform("SW PARAM"))) 647 env.Depends(i_file, depends) 648 SwigSource('m5.internal', i_file) 649 650# Generate all enum header files 651for name,enum in sorted(all_enums.iteritems()): 652 py_source = PySource.modules[enum.__module__] 653 extra_deps = [ py_source.tnode ] 654 655 cc_file = File('enums/%s.cc' % name) 656 env.Command(cc_file, Value(name), 657 MakeAction(createEnumStrings, Transform("ENUM STR"))) 658 env.Depends(cc_file, depends + extra_deps) 659 Source(cc_file) 660 661 hh_file = File('enums/%s.hh' % name) 662 env.Command(hh_file, Value(name), 663 MakeAction(createEnumDecls, Transform("ENUMDECL"))) 664 env.Depends(hh_file, depends + extra_deps) 665 666 i_file = File('python/m5/internal/enum_%s.i' % name) 667 env.Command(i_file, Value(name), 668 MakeAction(createEnumSwigWrapper, Transform("ENUMSWIG"))) 669 env.Depends(i_file, depends + extra_deps) 670 SwigSource('m5.internal', i_file) 671 672# Generate SimObject SWIG wrapper files 673for name,simobj in sim_objects.iteritems(): 674 py_source = PySource.modules[simobj.__module__] 675 extra_deps = [ py_source.tnode ] 676 677 i_file = File('python/m5/internal/param_%s.i' % name) 678 env.Command(i_file, Value(name), 679 MakeAction(createSimObjectSwigWrapper, Transform("SO SWIG"))) 680 env.Depends(i_file, depends + extra_deps) 681 SwigSource('m5.internal', i_file) 682 683# Generate the main swig init file 684def makeEmbeddedSwigInit(target, source, env): 685 code = code_formatter() 686 module = source[0].get_contents() 687 code('''\ 688#include "sim/init.hh" 689 690extern "C" { 691 void init_${module}(); 692} 693 694EmbeddedSwig embed_swig_${module}(init_${module}); 695''') 696 code.write(str(target[0])) 697 698# Build all swig modules 699for swig in SwigSource.all: 700 env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode, 701 MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' 702 '-o ${TARGETS[0]} $SOURCES', Transform("SWIG"))) 703 cc_file = str(swig.tnode) 704 init_file = '%s/%s_init.cc' % (dirname(cc_file), basename(cc_file)) 705 env.Command(init_file, Value(swig.module), 706 MakeAction(makeEmbeddedSwigInit, Transform("EMBED SW"))) 707 Source(init_file, **swig.guards) 708 709# Build all protocol buffers if we have got protoc and protobuf available 710if env['HAVE_PROTOBUF']: 711 for proto in ProtoBuf.all: 712 # Use both the source and header as the target, and the .proto 713 # file as the source. When executing the protoc compiler, also 714 # specify the proto_path to avoid having the generated files 715 # include the path. 716 env.Command([proto.cc_file, proto.hh_file], proto.tnode, 717 MakeAction('$PROTOC --cpp_out ${TARGET.dir} ' 718 '--proto_path ${SOURCE.dir} $SOURCE', 719 Transform("PROTOC"))) 720 721 # Add the C++ source file 722 Source(proto.cc_file, **proto.guards) 723elif ProtoBuf.all: 724 print 'Got protobuf to build, but lacks support!' 725 Exit(1) 726 727# 728# Handle debug flags 729# 730def makeDebugFlagCC(target, source, env): 731 assert(len(target) == 1 and len(source) == 1) 732 733 val = eval(source[0].get_contents()) 734 name, compound, desc = val 735 compound = list(sorted(compound)) 736 737 code = code_formatter() 738 739 # file header 740 code(''' 741/* 742 * DO NOT EDIT THIS FILE! Automatically generated 743 */ 744 745#include "base/debug.hh" 746''') 747 748 for flag in compound: 749 code('#include "debug/$flag.hh"') 750 code() 751 code('namespace Debug {') 752 code() 753 754 if not compound: 755 code('SimpleFlag $name("$name", "$desc");') 756 else: 757 code('CompoundFlag $name("$name", "$desc",') 758 code.indent() 759 last = len(compound) - 1 760 for i,flag in enumerate(compound): 761 if i != last: 762 code('$flag,') 763 else: 764 code('$flag);') 765 code.dedent() 766 767 code() 768 code('} // namespace Debug') 769 770 code.write(str(target[0])) 771 772def makeDebugFlagHH(target, source, env): 773 assert(len(target) == 1 and len(source) == 1) 774 775 val = eval(source[0].get_contents()) 776 name, compound, desc = val 777 778 code = code_formatter() 779 780 # file header boilerplate 781 code('''\ 782/* 783 * DO NOT EDIT THIS FILE! 784 * 785 * Automatically generated by SCons 786 */ 787 788#ifndef __DEBUG_${name}_HH__ 789#define __DEBUG_${name}_HH__ 790 791namespace Debug { 792''') 793 794 if compound: 795 code('class CompoundFlag;') 796 code('class SimpleFlag;') 797 798 if compound: 799 code('extern CompoundFlag $name;') 800 for flag in compound: 801 code('extern SimpleFlag $flag;') 802 else: 803 code('extern SimpleFlag $name;') 804 805 code(''' 806} 807 808#endif // __DEBUG_${name}_HH__ 809''') 810 811 code.write(str(target[0])) 812 813for name,flag in sorted(debug_flags.iteritems()): 814 n, compound, desc = flag 815 assert n == name 816 817 env.Command('debug/%s.hh' % name, Value(flag), 818 MakeAction(makeDebugFlagHH, Transform("TRACING", 0))) 819 env.Command('debug/%s.cc' % name, Value(flag), 820 MakeAction(makeDebugFlagCC, Transform("TRACING", 0))) 821 Source('debug/%s.cc' % name) 822 823# Embed python files. All .py files that have been indicated by a 824# PySource() call in a SConscript need to be embedded into the M5 825# library. To do that, we compile the file to byte code, marshal the 826# byte code, compress it, and then generate a c++ file that 827# inserts the result into an array. 828def embedPyFile(target, source, env): 829 def c_str(string): 830 if string is None: 831 return "0" 832 return '"%s"' % string 833 834 '''Action function to compile a .py into a code object, marshal 835 it, compress it, and stick it into an asm file so the code appears 836 as just bytes with a label in the data section''' 837 838 src = file(str(source[0]), 'r').read() 839 840 pysource = PySource.tnodes[source[0]] 841 compiled = compile(src, pysource.abspath, 'exec') 842 marshalled = marshal.dumps(compiled) 843 compressed = zlib.compress(marshalled) 844 data = compressed 845 sym = pysource.symname 846 847 code = code_formatter() 848 code('''\ 849#include "sim/init.hh" 850 851namespace { 852 853const uint8_t data_${sym}[] = { 854''') 855 code.indent() 856 step = 16 857 for i in xrange(0, len(data), step): 858 x = array.array('B', data[i:i+step]) 859 code(''.join('%d,' % d for d in x)) 860 code.dedent() 861 862 code('''}; 863 864EmbeddedPython embedded_${sym}( 865 ${{c_str(pysource.arcname)}}, 866 ${{c_str(pysource.abspath)}}, 867 ${{c_str(pysource.modpath)}}, 868 data_${sym}, 869 ${{len(data)}}, 870 ${{len(marshalled)}}); 871 872} // anonymous namespace 873''') 874 code.write(str(target[0])) 875 876for source in PySource.all: 877 env.Command(source.cpp, source.tnode, 878 MakeAction(embedPyFile, Transform("EMBED PY"))) 879 Source(source.cpp) 880 881######################################################################## 882# 883# Define binaries. Each different build type (debug, opt, etc.) gets 884# a slightly different build environment. 885# 886 887# List of constructed environments to pass back to SConstruct 888date_source = Source('base/date.cc', skip_lib=True) 889 890# Capture this directory for the closure makeEnv, otherwise when it is 891# called, it won't know what directory it should use. 892variant_dir = Dir('.').path 893def variant(*path): 894 return os.path.join(variant_dir, *path) 895def variantd(*path): 896 return variant(*path)+'/' 897 898# Function to create a new build environment as clone of current 899# environment 'env' with modified object suffix and optional stripped 900# binary. Additional keyword arguments are appended to corresponding 901# build environment vars. 902def makeEnv(env, label, objsfx, strip = False, **kwargs): 903 # SCons doesn't know to append a library suffix when there is a '.' in the 904 # name. Use '_' instead. 905 libname = variant('gem5_' + label) 906 exename = variant('gem5.' + label) 907 secondary_exename = variant('m5.' + label) 908 909 new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 910 new_env.Label = label 911 new_env.Append(**kwargs) 912 913 swig_env = new_env.Clone() 914 915 # Both gcc and clang have issues with unused labels and values in 916 # the SWIG generated code 917 swig_env.Append(CCFLAGS=['-Wno-unused-label', '-Wno-unused-value']) 918 919 # Add additional warnings here that should not be applied to 920 # the SWIG generated code 921 new_env.Append(CXXFLAGS='-Wmissing-declarations') 922 923 if env['GCC']: 924 # Depending on the SWIG version, we also need to supress 925 # warnings about uninitialized variables and missing field 926 # initializers. 927 swig_env.Append(CCFLAGS=['-Wno-uninitialized', 928 '-Wno-missing-field-initializers', 929 '-Wno-unused-but-set-variable']) 930 931 # If gcc supports it, also warn for deletion of derived 932 # classes with non-virtual desctructors. For gcc >= 4.7 we 933 # also have to disable warnings about the SWIG code having 934 # potentially uninitialized variables. 935 if compareVersions(env['GCC_VERSION'], '4.7') >= 0: 936 new_env.Append(CXXFLAGS='-Wdelete-non-virtual-dtor') 937 swig_env.Append(CCFLAGS='-Wno-maybe-uninitialized') 938 if env['CLANG']: 939 # Always enable the warning for deletion of derived classes 940 # with non-virtual destructors 941 new_env.Append(CXXFLAGS=['-Wdelete-non-virtual-dtor']) 942 943 swig_env.Append(CCFLAGS=[ 944 # Some versions of SWIG can return uninitialized values 945 '-Wno-sometimes-uninitialized', 946 # Register storage is requested in a lot of places in 947 # SWIG-generated code. 948 '-Wno-deprecated-register', 949 ]) 950 951 werror_env = new_env.Clone() 952 werror_env.Append(CCFLAGS='-Werror') 953 954 def make_obj(source, static, extra_deps = None): 955 '''This function adds the specified source to the correct 956 build environment, and returns the corresponding SCons Object 957 nodes''' 958 959 if source.swig: 960 env = swig_env 961 elif source.Werror: 962 env = werror_env 963 else: 964 env = new_env 965 966 if static: 967 obj = env.StaticObject(source.tnode) 968 else: 969 obj = env.SharedObject(source.tnode) 970 971 if extra_deps: 972 env.Depends(obj, extra_deps) 973 974 return obj 975 976 static_objs = \ 977 [ make_obj(s, True) for s in Source.get(main=False, skip_lib=False) ] 978 shared_objs = \ 979 [ make_obj(s, False) for s in Source.get(main=False, skip_lib=False) ] 980 981 static_date = make_obj(date_source, static=True, extra_deps=static_objs) 982 static_objs.append(static_date) 983 984 shared_date = make_obj(date_source, static=False, extra_deps=shared_objs) 985 shared_objs.append(shared_date) 986 987 # First make a library of everything but main() so other programs can 988 # link against m5. 989 static_lib = new_env.StaticLibrary(libname, static_objs) 990 shared_lib = new_env.SharedLibrary(libname, shared_objs) 991 992 # Now link a stub with main() and the static library. 993 main_objs = [ make_obj(s, True) for s in Source.get(main=True) ] 994 995 for test in UnitTest.all: 996 flags = { test.target : True } 997 test_sources = Source.get(**flags) 998 test_objs = [ make_obj(s, static=True) for s in test_sources ] 999 if test.main: 1000 test_objs += main_objs 1001 path = variant('unittest/%s.%s' % (test.target, label)) 1002 new_env.Program(path, test_objs + static_objs) 1003 1004 progname = exename 1005 if strip: 1006 progname += '.unstripped' 1007 1008 targets = new_env.Program(progname, main_objs + static_objs) 1009 1010 if strip: 1011 if sys.platform == 'sunos5': 1012 cmd = 'cp $SOURCE $TARGET; strip $TARGET' 1013 else: 1014 cmd = 'strip $SOURCE -o $TARGET' 1015 targets = new_env.Command(exename, progname, 1016 MakeAction(cmd, Transform("STRIP"))) 1017 1018 new_env.Command(secondary_exename, exename, 1019 MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK"))) 1020 1021 new_env.M5Binary = targets[0] 1022 return new_env 1023 1024# Start out with the compiler flags common to all compilers, 1025# i.e. they all use -g for opt and -g -pg for prof 1026ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'], 1027 'perf' : ['-g']} 1028 1029# Start out with the linker flags common to all linkers, i.e. -pg for 1030# prof, and -lprofiler for perf. The -lprofile flag is surrounded by 1031# no-as-needed and as-needed as the binutils linker is too clever and 1032# simply doesn't link to the library otherwise. 1033ldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'], 1034 'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']} 1035 1036# For Link Time Optimization, the optimisation flags used to compile 1037# individual files are decoupled from those used at link time 1038# (i.e. you can compile with -O3 and perform LTO with -O0), so we need 1039# to also update the linker flags based on the target. 1040if env['GCC']: 1041 if sys.platform == 'sunos5': 1042 ccflags['debug'] += ['-gstabs+'] 1043 else: 1044 ccflags['debug'] += ['-ggdb3'] 1045 ldflags['debug'] += ['-O0'] 1046 # opt, fast, prof and perf all share the same cc flags, also add 1047 # the optimization to the ldflags as LTO defers the optimization 1048 # to link time 1049 for target in ['opt', 'fast', 'prof', 'perf']: 1050 ccflags[target] += ['-O3'] 1051 ldflags[target] += ['-O3'] 1052 1053 ccflags['fast'] += env['LTO_CCFLAGS'] 1054 ldflags['fast'] += env['LTO_LDFLAGS'] 1055elif env['CLANG']: 1056 ccflags['debug'] += ['-g', '-O0'] 1057 # opt, fast, prof and perf all share the same cc flags 1058 for target in ['opt', 'fast', 'prof', 'perf']: 1059 ccflags[target] += ['-O3'] 1060else: 1061 print 'Unknown compiler, please fix compiler options' 1062 Exit(1) 1063 1064 1065# To speed things up, we only instantiate the build environments we 1066# need. We try to identify the needed environment for each target; if 1067# we can't, we fall back on instantiating all the environments just to 1068# be safe. 1069target_types = ['debug', 'opt', 'fast', 'prof', 'perf'] 1070obj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof', 1071 'gpo' : 'perf'} 1072 1073def identifyTarget(t): 1074 ext = t.split('.')[-1] 1075 if ext in target_types: 1076 return ext 1077 if obj2target.has_key(ext): 1078 return obj2target[ext] 1079 match = re.search(r'/tests/([^/]+)/', t) 1080 if match and match.group(1) in target_types: 1081 return match.group(1) 1082 return 'all' 1083 1084needed_envs = [identifyTarget(target) for target in BUILD_TARGETS] 1085if 'all' in needed_envs: 1086 needed_envs += target_types 1087 1088gem5_root = Dir('.').up().up().abspath 1089def makeEnvirons(target, source, env): 1090 # cause any later Source() calls to be fatal, as a diagnostic. 1091 Source.done() 1092 1093 envList = [] 1094 1095 # Debug binary 1096 if 'debug' in needed_envs: 1097 envList.append( 1098 makeEnv(env, 'debug', '.do', 1099 CCFLAGS = Split(ccflags['debug']), 1100 CPPDEFINES = ['DEBUG', 'TRACING_ON=1'], 1101 LINKFLAGS = Split(ldflags['debug']))) 1102 1103 # Optimized binary 1104 if 'opt' in needed_envs: 1105 envList.append( 1106 makeEnv(env, 'opt', '.o', 1107 CCFLAGS = Split(ccflags['opt']), 1108 CPPDEFINES = ['TRACING_ON=1'], 1109 LINKFLAGS = Split(ldflags['opt']))) 1110 1111 # "Fast" binary 1112 if 'fast' in needed_envs: 1113 envList.append( 1114 makeEnv(env, 'fast', '.fo', strip = True, 1115 CCFLAGS = Split(ccflags['fast']), 1116 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 1117 LINKFLAGS = Split(ldflags['fast']))) 1118 1119 # Profiled binary using gprof 1120 if 'prof' in needed_envs: 1121 envList.append( 1122 makeEnv(env, 'prof', '.po', 1123 CCFLAGS = Split(ccflags['prof']), 1124 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 1125 LINKFLAGS = Split(ldflags['prof']))) 1126 1127 # Profiled binary using google-pprof 1128 if 'perf' in needed_envs: 1129 envList.append( 1130 makeEnv(env, 'perf', '.gpo', 1131 CCFLAGS = Split(ccflags['perf']), 1132 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 1133 LINKFLAGS = Split(ldflags['perf']))) 1134 1135 # Set up the regression tests for each build. 1136 for e in envList: 1137 SConscript(os.path.join(gem5_root, 'tests', 'SConscript'), 1138 variant_dir = variantd('tests', e.Label), 1139 exports = { 'env' : e }, duplicate = False) 1140 1141# The MakeEnvirons Builder defers the full dependency collection until 1142# after processing the ISA definition (due to dynamically generated 1143# source files). Add this dependency to all targets so they will wait 1144# until the environments are completely set up. Otherwise, a second 1145# process (e.g. -j2 or higher) will try to compile the requested target, 1146# not know how, and fail. 1147env.Append(BUILDERS = {'MakeEnvirons' : 1148 Builder(action=MakeAction(makeEnvirons, 1149 Transform("ENVIRONS", 1)))}) 1150 1151isa_target = env['PHONY_BASE'] + '-deps' 1152environs = env['PHONY_BASE'] + '-environs' 1153env.Depends('#all-deps', isa_target) 1154env.Depends('#all-environs', environs) 1155env.ScanISA(isa_target, File('arch/%s/generated/inc.d' % env['TARGET_ISA'])) 1156envSetup = env.MakeEnvirons(environs, isa_target) 1157 1158# make sure no -deps targets occur before all ISAs are complete 1159env.Depends(isa_target, '#all-isas') 1160# likewise for -environs targets and all the -deps targets 1161env.Depends(environs, '#all-deps') 1162