SConscript revision 12246
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 315522Snate@binkert.orgimport array 326143Snate@binkert.orgimport bisect 334762Snate@binkert.orgimport imp 345522Snate@binkert.orgimport marshal 35955SN/Aimport os 365522Snate@binkert.orgimport re 3711974Sgabeblack@google.comimport subprocess 38955SN/Aimport sys 395522Snate@binkert.orgimport zlib 404202Sbinkertn@umich.edu 415742Snate@binkert.orgfrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath 42955SN/A 434381Sbinkertn@umich.eduimport SCons 444381Sbinkertn@umich.edu 4512246Sgabeblack@google.comfrom gem5_scons import Transform 4612246Sgabeblack@google.com 478334Snate@binkert.org# This file defines how to build a particular configuration of gem5 48955SN/A# based on variable settings in the 'env' build environment. 49955SN/A 504202Sbinkertn@umich.eduImport('*') 51955SN/A 524382Sbinkertn@umich.edu# Children need to see the environment 534382Sbinkertn@umich.eduExport('env') 544382Sbinkertn@umich.edu 556654Snate@binkert.orgbuild_env = [(opt, env[opt]) for opt in export_vars] 565517Snate@binkert.org 578614Sgblack@eecs.umich.edufrom m5.util import code_formatter, compareVersions 587674Snate@binkert.org 596143Snate@binkert.org######################################################################## 606143Snate@binkert.org# Code for adding source files of various types 616143Snate@binkert.org# 628233Snate@binkert.org# When specifying a source file of some type, a set of guards can be 638233Snate@binkert.org# specified for that file. When get() is used to find the files, if 648233Snate@binkert.org# get specifies a set of filters, only files that match those filters 658233Snate@binkert.org# will be accepted (unspecified filters on files are assumed to be 668233Snate@binkert.org# false). Current filters are: 678334Snate@binkert.org# main -- specifies the gem5 main() function 688334Snate@binkert.org# skip_lib -- do not put this file into the gem5 library 6910453SAndrew.Bardsley@arm.com# skip_no_python -- do not put this file into a no_python library 7010453SAndrew.Bardsley@arm.com# as it embeds compiled Python 718233Snate@binkert.org# <unittest> -- unit tests use filters based on the unit test name 728233Snate@binkert.org# 738233Snate@binkert.org# A parent can now be specified for a source file and default filter 748233Snate@binkert.org# values will be retrieved recursively from parents (children override 758233Snate@binkert.org# parents). 768233Snate@binkert.org# 7711983Sgabeblack@google.comdef guarded_source_iterator(sources, **guards): 7811983Sgabeblack@google.com '''Iterate over a set of sources, gated by a set of guards.''' 7911983Sgabeblack@google.com for src in sources: 8011983Sgabeblack@google.com for flag,value in guards.iteritems(): 8111983Sgabeblack@google.com # if the flag is found and has a different value, skip 8211983Sgabeblack@google.com # this file 8311983Sgabeblack@google.com if src.all_guards.get(flag, False) != value: 8411983Sgabeblack@google.com break 8511983Sgabeblack@google.com else: 8611983Sgabeblack@google.com yield src 8711983Sgabeblack@google.com 886143Snate@binkert.orgclass SourceMeta(type): 898233Snate@binkert.org '''Meta class for source files that keeps track of all files of a 908233Snate@binkert.org particular type and has a get function for finding all functions 918233Snate@binkert.org of a certain type that match a set of guards''' 926143Snate@binkert.org def __init__(cls, name, bases, dict): 936143Snate@binkert.org super(SourceMeta, cls).__init__(name, bases, dict) 946143Snate@binkert.org cls.all = [] 9511308Santhony.gutierrez@amd.com 968233Snate@binkert.org def get(cls, **guards): 978233Snate@binkert.org '''Find all files that match the specified guards. If a source 988233Snate@binkert.org file does not specify a flag, the default is False''' 9911983Sgabeblack@google.com for s in guarded_source_iterator(cls.all, **guards): 10011983Sgabeblack@google.com yield s 1014762Snate@binkert.org 1026143Snate@binkert.orgclass SourceFile(object): 1038233Snate@binkert.org '''Base object that encapsulates the notion of a source file. 1048233Snate@binkert.org This includes, the source node, target node, various manipulations 1058233Snate@binkert.org of those. A source file also specifies a set of guards which 1068233Snate@binkert.org describing which builds the source file applies to. A parent can 1078233Snate@binkert.org also be specified to get default guards from''' 1086143Snate@binkert.org __metaclass__ = SourceMeta 1098233Snate@binkert.org def __init__(self, source, parent=None, **guards): 1108233Snate@binkert.org self.guards = guards 1118233Snate@binkert.org self.parent = parent 1128233Snate@binkert.org 1136143Snate@binkert.org tnode = source 1146143Snate@binkert.org if not isinstance(source, SCons.Node.FS.File): 1156143Snate@binkert.org tnode = File(source) 1166143Snate@binkert.org 1176143Snate@binkert.org self.tnode = tnode 1186143Snate@binkert.org self.snode = tnode.srcnode() 1196143Snate@binkert.org 1206143Snate@binkert.org for base in type(self).__mro__: 1216143Snate@binkert.org if issubclass(base, SourceFile): 1227065Snate@binkert.org base.all.append(self) 1236143Snate@binkert.org 1248233Snate@binkert.org @property 1258233Snate@binkert.org def filename(self): 1268233Snate@binkert.org return str(self.tnode) 1278233Snate@binkert.org 1288233Snate@binkert.org @property 1298233Snate@binkert.org def dirname(self): 1308233Snate@binkert.org return dirname(self.filename) 1318233Snate@binkert.org 1328233Snate@binkert.org @property 1338233Snate@binkert.org def basename(self): 1348233Snate@binkert.org return basename(self.filename) 1358233Snate@binkert.org 1368233Snate@binkert.org @property 1378233Snate@binkert.org def extname(self): 1388233Snate@binkert.org index = self.basename.rfind('.') 1398233Snate@binkert.org if index <= 0: 1408233Snate@binkert.org # dot files aren't extensions 1418233Snate@binkert.org return self.basename, None 1428233Snate@binkert.org 1438233Snate@binkert.org return self.basename[:index], self.basename[index+1:] 1448233Snate@binkert.org 1458233Snate@binkert.org @property 1468233Snate@binkert.org def all_guards(self): 1478233Snate@binkert.org '''find all guards for this object getting default values 1488233Snate@binkert.org recursively from its parents''' 1498233Snate@binkert.org guards = {} 1508233Snate@binkert.org if self.parent: 1518233Snate@binkert.org guards.update(self.parent.guards) 1528233Snate@binkert.org guards.update(self.guards) 1538233Snate@binkert.org return guards 1548233Snate@binkert.org 1556143Snate@binkert.org def __lt__(self, other): return self.filename < other.filename 1566143Snate@binkert.org def __le__(self, other): return self.filename <= other.filename 1576143Snate@binkert.org def __gt__(self, other): return self.filename > other.filename 1586143Snate@binkert.org def __ge__(self, other): return self.filename >= other.filename 1596143Snate@binkert.org def __eq__(self, other): return self.filename == other.filename 1606143Snate@binkert.org def __ne__(self, other): return self.filename != other.filename 1619982Satgutier@umich.edu 16210196SCurtis.Dunham@arm.com @staticmethod 16310196SCurtis.Dunham@arm.com def done(): 16410196SCurtis.Dunham@arm.com def disabled(cls, name, *ignored): 16510196SCurtis.Dunham@arm.com raise RuntimeError("Additional SourceFile '%s'" % name,\ 16610196SCurtis.Dunham@arm.com "declared, but targets deps are already fixed.") 16710196SCurtis.Dunham@arm.com SourceFile.__init__ = disabled 16810196SCurtis.Dunham@arm.com 16910196SCurtis.Dunham@arm.com 1706143Snate@binkert.orgclass Source(SourceFile): 17111983Sgabeblack@google.com current_group = None 17211983Sgabeblack@google.com source_groups = { None : [] } 17311983Sgabeblack@google.com 17411983Sgabeblack@google.com @classmethod 17511983Sgabeblack@google.com def set_group(cls, group): 17611983Sgabeblack@google.com if not group in Source.source_groups: 17711983Sgabeblack@google.com Source.source_groups[group] = [] 17811983Sgabeblack@google.com Source.current_group = group 17911983Sgabeblack@google.com 1806143Snate@binkert.org '''Add a c/c++ source file to the build''' 18111988Sandreas.sandberg@arm.com def __init__(self, source, Werror=True, **guards): 1828233Snate@binkert.org '''specify the source file, and any guards''' 1838233Snate@binkert.org super(Source, self).__init__(source, **guards) 1846143Snate@binkert.org 1858945Ssteve.reinhardt@amd.com self.Werror = Werror 1866143Snate@binkert.org 18711983Sgabeblack@google.com Source.source_groups[Source.current_group].append(self) 18811983Sgabeblack@google.com 1896143Snate@binkert.orgclass PySource(SourceFile): 1906143Snate@binkert.org '''Add a python source file to the named package''' 1915522Snate@binkert.org invalid_sym_char = re.compile('[^A-z0-9_]') 1926143Snate@binkert.org modules = {} 1936143Snate@binkert.org tnodes = {} 1946143Snate@binkert.org symnames = {} 1959982Satgutier@umich.edu 1968233Snate@binkert.org def __init__(self, package, source, **guards): 1978233Snate@binkert.org '''specify the python package, the source file, and any guards''' 1988233Snate@binkert.org super(PySource, self).__init__(source, **guards) 1996143Snate@binkert.org 2006143Snate@binkert.org modname,ext = self.extname 2016143Snate@binkert.org assert ext == 'py' 2026143Snate@binkert.org 2035522Snate@binkert.org if package: 2045522Snate@binkert.org path = package.split('.') 2055522Snate@binkert.org else: 2065522Snate@binkert.org path = [] 2075604Snate@binkert.org 2085604Snate@binkert.org modpath = path[:] 2096143Snate@binkert.org if modname != '__init__': 2106143Snate@binkert.org modpath += [ modname ] 2114762Snate@binkert.org modpath = '.'.join(modpath) 2124762Snate@binkert.org 2136143Snate@binkert.org arcpath = path + [ self.basename ] 2146727Ssteve.reinhardt@amd.com abspath = self.snode.abspath 2156727Ssteve.reinhardt@amd.com if not exists(abspath): 2166727Ssteve.reinhardt@amd.com abspath = self.tnode.abspath 2174762Snate@binkert.org 2186143Snate@binkert.org self.package = package 2196143Snate@binkert.org self.modname = modname 2206143Snate@binkert.org self.modpath = modpath 2216143Snate@binkert.org self.arcname = joinpath(*arcpath) 2226727Ssteve.reinhardt@amd.com self.abspath = abspath 2236143Snate@binkert.org self.compiled = File(self.filename + 'c') 2247674Snate@binkert.org self.cpp = File(self.filename + '.cc') 2257674Snate@binkert.org self.symname = PySource.invalid_sym_char.sub('_', modpath) 2265604Snate@binkert.org 2276143Snate@binkert.org PySource.modules[modpath] = self 2286143Snate@binkert.org PySource.tnodes[self.tnode] = self 2296143Snate@binkert.org PySource.symnames[self.symname] = self 2304762Snate@binkert.org 2316143Snate@binkert.orgclass SimObject(PySource): 2324762Snate@binkert.org '''Add a SimObject python file as a python source object and add 2334762Snate@binkert.org it to a list of sim object modules''' 2344762Snate@binkert.org 2356143Snate@binkert.org fixed = False 2366143Snate@binkert.org modnames = [] 2374762Snate@binkert.org 2388233Snate@binkert.org def __init__(self, source, **guards): 2398233Snate@binkert.org '''Specify the source file and any guards (automatically in 2408233Snate@binkert.org the m5.objects package)''' 2418233Snate@binkert.org super(SimObject, self).__init__('m5.objects', source, **guards) 2426143Snate@binkert.org if self.fixed: 2436143Snate@binkert.org raise AttributeError, "Too late to call SimObject now." 2444762Snate@binkert.org 2456143Snate@binkert.org bisect.insort_right(SimObject.modnames, self.modname) 2464762Snate@binkert.org 2479396Sandreas.hansson@arm.comclass ProtoBuf(SourceFile): 2489396Sandreas.hansson@arm.com '''Add a Protocol Buffer to build''' 2499396Sandreas.hansson@arm.com 2509396Sandreas.hansson@arm.com def __init__(self, source, **guards): 2519396Sandreas.hansson@arm.com '''Specify the source file, and any guards''' 2529396Sandreas.hansson@arm.com super(ProtoBuf, self).__init__(source, **guards) 2539396Sandreas.hansson@arm.com 2549396Sandreas.hansson@arm.com # Get the file name and the extension 2559396Sandreas.hansson@arm.com modname,ext = self.extname 2569396Sandreas.hansson@arm.com assert ext == 'proto' 2579396Sandreas.hansson@arm.com 2589396Sandreas.hansson@arm.com # Currently, we stick to generating the C++ headers, so we 2599396Sandreas.hansson@arm.com # only need to track the source and header. 2609930Sandreas.hansson@arm.com self.cc_file = File(modname + '.pb.cc') 2619930Sandreas.hansson@arm.com self.hh_file = File(modname + '.pb.h') 2629396Sandreas.hansson@arm.com 2638235Snate@binkert.orgclass UnitTest(object): 2648235Snate@binkert.org '''Create a UnitTest''' 2656143Snate@binkert.org 2668235Snate@binkert.org all = [] 2679003SAli.Saidi@ARM.com def __init__(self, target, *sources, **kwargs): 2688235Snate@binkert.org '''Specify the target name and any sources. Sources that are 2698235Snate@binkert.org not SourceFiles are evalued with Source(). All files are 2708235Snate@binkert.org guarded with a guard of the same name as the UnitTest 2718235Snate@binkert.org target.''' 2728235Snate@binkert.org 2738235Snate@binkert.org srcs = [] 2748235Snate@binkert.org for src in sources: 2758235Snate@binkert.org if not isinstance(src, SourceFile): 2768235Snate@binkert.org src = Source(src, skip_lib=True) 2778235Snate@binkert.org src.guards[target] = True 2788235Snate@binkert.org srcs.append(src) 2798235Snate@binkert.org 2808235Snate@binkert.org self.sources = srcs 2818235Snate@binkert.org self.target = target 2829003SAli.Saidi@ARM.com self.main = kwargs.get('main', False) 2838235Snate@binkert.org UnitTest.all.append(self) 2845584Snate@binkert.org 2854382Sbinkertn@umich.edu# Children should have access 2864202Sbinkertn@umich.eduExport('Source') 2874382Sbinkertn@umich.eduExport('PySource') 2884382Sbinkertn@umich.eduExport('SimObject') 2899396Sandreas.hansson@arm.comExport('ProtoBuf') 2905584Snate@binkert.orgExport('UnitTest') 2914382Sbinkertn@umich.edu 2924382Sbinkertn@umich.edu######################################################################## 2934382Sbinkertn@umich.edu# 2948232Snate@binkert.org# Debug Flags 2955192Ssaidi@eecs.umich.edu# 2968232Snate@binkert.orgdebug_flags = {} 2978232Snate@binkert.orgdef DebugFlag(name, desc=None): 2988232Snate@binkert.org if name in debug_flags: 2995192Ssaidi@eecs.umich.edu raise AttributeError, "Flag %s already specified" % name 3008232Snate@binkert.org debug_flags[name] = (name, (), desc) 3015192Ssaidi@eecs.umich.edu 3025799Snate@binkert.orgdef CompoundFlag(name, flags, desc=None): 3038232Snate@binkert.org if name in debug_flags: 3045192Ssaidi@eecs.umich.edu raise AttributeError, "Flag %s already specified" % name 3055192Ssaidi@eecs.umich.edu 3065192Ssaidi@eecs.umich.edu compound = tuple(flags) 3078232Snate@binkert.org debug_flags[name] = (name, compound, desc) 3085192Ssaidi@eecs.umich.edu 3098232Snate@binkert.orgExport('DebugFlag') 3105192Ssaidi@eecs.umich.eduExport('CompoundFlag') 3115192Ssaidi@eecs.umich.edu 3125192Ssaidi@eecs.umich.edu######################################################################## 3135192Ssaidi@eecs.umich.edu# 3144382Sbinkertn@umich.edu# Set some compiler variables 3154382Sbinkertn@umich.edu# 3164382Sbinkertn@umich.edu 3172667Sstever@eecs.umich.edu# Include file paths are rooted in this directory. SCons will 3182667Sstever@eecs.umich.edu# automatically expand '.' to refer to both the source directory and 3192667Sstever@eecs.umich.edu# the corresponding build directory to pick up generated include 3202667Sstever@eecs.umich.edu# files. 3212667Sstever@eecs.umich.eduenv.Append(CPPPATH=Dir('.')) 3222667Sstever@eecs.umich.edu 3235742Snate@binkert.orgfor extra_dir in extras_dir_list: 3245742Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 3255742Snate@binkert.org 3265793Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212 3278334Snate@binkert.org# Scons bug id: 2006 gem5 Bug id: 308 3285793Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 3295793Snate@binkert.org Dir(root[len(base_dir) + 1:]) 3305793Snate@binkert.org 3314382Sbinkertn@umich.edu######################################################################## 3324762Snate@binkert.org# 3335344Sstever@gmail.com# Walk the tree and execute all SConscripts in subdirectories 3344382Sbinkertn@umich.edu# 3355341Sstever@gmail.com 3365742Snate@binkert.orghere = Dir('.').srcnode().abspath 3375742Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 3385742Snate@binkert.org if root == here: 3395742Snate@binkert.org # we don't want to recurse back into this SConscript 3405742Snate@binkert.org continue 3414762Snate@binkert.org 3425742Snate@binkert.org if 'SConscript' in files: 3435742Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 34411984Sgabeblack@google.com Source.set_group(build_dir) 3457722Sgblack@eecs.umich.edu SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3465742Snate@binkert.org 3475742Snate@binkert.orgfor extra_dir in extras_dir_list: 3485742Snate@binkert.org prefix_len = len(dirname(extra_dir)) + 1 3499930Sandreas.hansson@arm.com 3509930Sandreas.hansson@arm.com # Also add the corresponding build directory to pick up generated 3519930Sandreas.hansson@arm.com # include files. 3529930Sandreas.hansson@arm.com env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:]))) 3539930Sandreas.hansson@arm.com 3545742Snate@binkert.org for root, dirs, files in os.walk(extra_dir, topdown=True): 3558242Sbradley.danofsky@amd.com # if build lives in the extras directory, don't walk down it 3568242Sbradley.danofsky@amd.com if 'build' in dirs: 3578242Sbradley.danofsky@amd.com dirs.remove('build') 3588242Sbradley.danofsky@amd.com 3595341Sstever@gmail.com if 'SConscript' in files: 3605742Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 3617722Sgblack@eecs.umich.edu SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3624773Snate@binkert.org 3636108Snate@binkert.orgfor opt in export_vars: 3641858SN/A env.ConfigFile(opt) 3651085SN/A 3666658Snate@binkert.orgdef makeTheISA(source, target, env): 3676658Snate@binkert.org isas = [ src.get_contents() for src in source ] 3687673Snate@binkert.org target_isa = env['TARGET_ISA'] 3696658Snate@binkert.org def define(isa): 3706658Snate@binkert.org return isa.upper() + '_ISA' 37111308Santhony.gutierrez@amd.com 3726658Snate@binkert.org def namespace(isa): 37311308Santhony.gutierrez@amd.com return isa[0].upper() + isa[1:].lower() + 'ISA' 3746658Snate@binkert.org 3756658Snate@binkert.org 3767673Snate@binkert.org code = code_formatter() 3777673Snate@binkert.org code('''\ 3787673Snate@binkert.org#ifndef __CONFIG_THE_ISA_HH__ 3797673Snate@binkert.org#define __CONFIG_THE_ISA_HH__ 3807673Snate@binkert.org 3817673Snate@binkert.org''') 3827673Snate@binkert.org 38310467Sandreas.hansson@arm.com # create defines for the preprocessing and compile-time determination 3846658Snate@binkert.org for i,isa in enumerate(isas): 3857673Snate@binkert.org code('#define $0 $1', define(isa), i + 1) 38610467Sandreas.hansson@arm.com code() 38710467Sandreas.hansson@arm.com 38810467Sandreas.hansson@arm.com # create an enum for any run-time determination of the ISA, we 38910467Sandreas.hansson@arm.com # reuse the same name as the namespaces 39010467Sandreas.hansson@arm.com code('enum class Arch {') 39110467Sandreas.hansson@arm.com for i,isa in enumerate(isas): 39210467Sandreas.hansson@arm.com if i + 1 == len(isas): 39310467Sandreas.hansson@arm.com code(' $0 = $1', namespace(isa), define(isa)) 39410467Sandreas.hansson@arm.com else: 39510467Sandreas.hansson@arm.com code(' $0 = $1,', namespace(isa), define(isa)) 39610467Sandreas.hansson@arm.com code('};') 3977673Snate@binkert.org 3987673Snate@binkert.org code(''' 3997673Snate@binkert.org 4007673Snate@binkert.org#define THE_ISA ${{define(target_isa)}} 4017673Snate@binkert.org#define TheISA ${{namespace(target_isa)}} 4029048SAli.Saidi@ARM.com#define THE_ISA_STR "${{target_isa}}" 4037673Snate@binkert.org 4047673Snate@binkert.org#endif // __CONFIG_THE_ISA_HH__''') 4057673Snate@binkert.org 4067673Snate@binkert.org code.write(str(target[0])) 4076658Snate@binkert.org 4087756SAli.Saidi@ARM.comenv.Command('config/the_isa.hh', map(Value, all_isa_list), 4097816Ssteve.reinhardt@amd.com MakeAction(makeTheISA, Transform("CFG ISA", 0))) 4106658Snate@binkert.org 41111308Santhony.gutierrez@amd.comdef makeTheGPUISA(source, target, env): 41211308Santhony.gutierrez@amd.com isas = [ src.get_contents() for src in source ] 41311308Santhony.gutierrez@amd.com target_gpu_isa = env['TARGET_GPU_ISA'] 41411308Santhony.gutierrez@amd.com def define(isa): 41511308Santhony.gutierrez@amd.com return isa.upper() + '_ISA' 41611308Santhony.gutierrez@amd.com 41711308Santhony.gutierrez@amd.com def namespace(isa): 41811308Santhony.gutierrez@amd.com return isa[0].upper() + isa[1:].lower() + 'ISA' 41911308Santhony.gutierrez@amd.com 42011308Santhony.gutierrez@amd.com 42111308Santhony.gutierrez@amd.com code = code_formatter() 42211308Santhony.gutierrez@amd.com code('''\ 42311308Santhony.gutierrez@amd.com#ifndef __CONFIG_THE_GPU_ISA_HH__ 42411308Santhony.gutierrez@amd.com#define __CONFIG_THE_GPU_ISA_HH__ 42511308Santhony.gutierrez@amd.com 42611308Santhony.gutierrez@amd.com''') 42711308Santhony.gutierrez@amd.com 42811308Santhony.gutierrez@amd.com # create defines for the preprocessing and compile-time determination 42911308Santhony.gutierrez@amd.com for i,isa in enumerate(isas): 43011308Santhony.gutierrez@amd.com code('#define $0 $1', define(isa), i + 1) 43111308Santhony.gutierrez@amd.com code() 43211308Santhony.gutierrez@amd.com 43311308Santhony.gutierrez@amd.com # create an enum for any run-time determination of the ISA, we 43411308Santhony.gutierrez@amd.com # reuse the same name as the namespaces 43511308Santhony.gutierrez@amd.com code('enum class GPUArch {') 43611308Santhony.gutierrez@amd.com for i,isa in enumerate(isas): 43711308Santhony.gutierrez@amd.com if i + 1 == len(isas): 43811308Santhony.gutierrez@amd.com code(' $0 = $1', namespace(isa), define(isa)) 43911308Santhony.gutierrez@amd.com else: 44011308Santhony.gutierrez@amd.com code(' $0 = $1,', namespace(isa), define(isa)) 44111308Santhony.gutierrez@amd.com code('};') 44211308Santhony.gutierrez@amd.com 44311308Santhony.gutierrez@amd.com code(''' 44411308Santhony.gutierrez@amd.com 44511308Santhony.gutierrez@amd.com#define THE_GPU_ISA ${{define(target_gpu_isa)}} 44611308Santhony.gutierrez@amd.com#define TheGpuISA ${{namespace(target_gpu_isa)}} 44711308Santhony.gutierrez@amd.com#define THE_GPU_ISA_STR "${{target_gpu_isa}}" 44811308Santhony.gutierrez@amd.com 44911308Santhony.gutierrez@amd.com#endif // __CONFIG_THE_GPU_ISA_HH__''') 45011308Santhony.gutierrez@amd.com 45111308Santhony.gutierrez@amd.com code.write(str(target[0])) 45211308Santhony.gutierrez@amd.com 45311308Santhony.gutierrez@amd.comenv.Command('config/the_gpu_isa.hh', map(Value, all_gpu_isa_list), 45411308Santhony.gutierrez@amd.com MakeAction(makeTheGPUISA, Transform("CFG ISA", 0))) 45511308Santhony.gutierrez@amd.com 4564382Sbinkertn@umich.edu######################################################################## 4574382Sbinkertn@umich.edu# 4584762Snate@binkert.org# Prevent any SimObjects from being added after this point, they 4594762Snate@binkert.org# should all have been added in the SConscripts above 4604762Snate@binkert.org# 4616654Snate@binkert.orgSimObject.fixed = True 4626654Snate@binkert.org 4635517Snate@binkert.orgclass DictImporter(object): 4645517Snate@binkert.org '''This importer takes a dictionary of arbitrary module names that 4655517Snate@binkert.org map to arbitrary filenames.''' 4665517Snate@binkert.org def __init__(self, modules): 4675517Snate@binkert.org self.modules = modules 4685517Snate@binkert.org self.installed = set() 4695517Snate@binkert.org 4705517Snate@binkert.org def __del__(self): 4715517Snate@binkert.org self.unload() 4725517Snate@binkert.org 4735517Snate@binkert.org def unload(self): 4745517Snate@binkert.org import sys 4755517Snate@binkert.org for module in self.installed: 4765517Snate@binkert.org del sys.modules[module] 4775517Snate@binkert.org self.installed = set() 4785517Snate@binkert.org 4795517Snate@binkert.org def find_module(self, fullname, path): 4806654Snate@binkert.org if fullname == 'm5.defines': 4815517Snate@binkert.org return self 4825517Snate@binkert.org 4835517Snate@binkert.org if fullname == 'm5.objects': 4845517Snate@binkert.org return self 4855517Snate@binkert.org 48611802Sandreas.sandberg@arm.com if fullname.startswith('_m5'): 4875517Snate@binkert.org return None 4885517Snate@binkert.org 4896143Snate@binkert.org source = self.modules.get(fullname, None) 4906654Snate@binkert.org if source is not None and fullname.startswith('m5.objects'): 4915517Snate@binkert.org return self 4925517Snate@binkert.org 4935517Snate@binkert.org return None 4945517Snate@binkert.org 4955517Snate@binkert.org def load_module(self, fullname): 4965517Snate@binkert.org mod = imp.new_module(fullname) 4975517Snate@binkert.org sys.modules[fullname] = mod 4985517Snate@binkert.org self.installed.add(fullname) 4995517Snate@binkert.org 5005517Snate@binkert.org mod.__loader__ = self 5015517Snate@binkert.org if fullname == 'm5.objects': 5025517Snate@binkert.org mod.__path__ = fullname.split('.') 5035517Snate@binkert.org return mod 5045517Snate@binkert.org 5056654Snate@binkert.org if fullname == 'm5.defines': 5066654Snate@binkert.org mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 5075517Snate@binkert.org return mod 5085517Snate@binkert.org 5096143Snate@binkert.org source = self.modules[fullname] 5106143Snate@binkert.org if source.modname == '__init__': 5116143Snate@binkert.org mod.__path__ = source.modpath 5126727Ssteve.reinhardt@amd.com mod.__file__ = source.abspath 5135517Snate@binkert.org 5146727Ssteve.reinhardt@amd.com exec file(source.abspath, 'r') in mod.__dict__ 5155517Snate@binkert.org 5165517Snate@binkert.org return mod 5175517Snate@binkert.org 5186654Snate@binkert.orgimport m5.SimObject 5196654Snate@binkert.orgimport m5.params 5207673Snate@binkert.orgfrom m5.util import code_formatter 5216654Snate@binkert.org 5226654Snate@binkert.orgm5.SimObject.clear() 5236654Snate@binkert.orgm5.params.clear() 5246654Snate@binkert.org 5255517Snate@binkert.org# install the python importer so we can grab stuff from the source 5265517Snate@binkert.org# tree itself. We can't have SimObjects added after this point or 5275517Snate@binkert.org# else we won't know about them for the rest of the stuff. 5286143Snate@binkert.orgimporter = DictImporter(PySource.modules) 5295517Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 5304762Snate@binkert.org 5315517Snate@binkert.org# import all sim objects so we can populate the all_objects list 5325517Snate@binkert.org# make sure that we're working with a list, then let's sort it 5336143Snate@binkert.orgfor modname in SimObject.modnames: 5346143Snate@binkert.org exec('from m5.objects import %s' % modname) 5355517Snate@binkert.org 5365517Snate@binkert.org# we need to unload all of the currently imported modules so that they 5375517Snate@binkert.org# will be re-imported the next time the sconscript is run 5385517Snate@binkert.orgimporter.unload() 5395517Snate@binkert.orgsys.meta_path.remove(importer) 5405517Snate@binkert.org 5415517Snate@binkert.orgsim_objects = m5.SimObject.allClasses 5425517Snate@binkert.orgall_enums = m5.params.allEnums 5435517Snate@binkert.org 5446143Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()): 5455517Snate@binkert.org for param in obj._params.local.values(): 5466654Snate@binkert.org # load the ptype attribute now because it depends on the 5476654Snate@binkert.org # current version of SimObject.allClasses, but when scons 5486654Snate@binkert.org # actually uses the value, all versions of 5496654Snate@binkert.org # SimObject.allClasses will have been loaded 5506654Snate@binkert.org param.ptype 5516654Snate@binkert.org 5524762Snate@binkert.org######################################################################## 5534762Snate@binkert.org# 5544762Snate@binkert.org# calculate extra dependencies 5554762Snate@binkert.org# 5564762Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 5577675Snate@binkert.orgdepends = [ PySource.modules[dep].snode for dep in module_depends ] 55810584Sandreas.hansson@arm.comdepends.sort(key = lambda x: x.name) 5594762Snate@binkert.org 5604762Snate@binkert.org######################################################################## 5614762Snate@binkert.org# 5624762Snate@binkert.org# Commands for the basic automatically generated python files 5634382Sbinkertn@umich.edu# 5644382Sbinkertn@umich.edu 5655517Snate@binkert.org# Generate Python file containing a dict specifying the current 5666654Snate@binkert.org# buildEnv flags. 5675517Snate@binkert.orgdef makeDefinesPyFile(target, source, env): 5688126Sgblack@eecs.umich.edu build_env = source[0].get_contents() 5696654Snate@binkert.org 5707673Snate@binkert.org code = code_formatter() 5716654Snate@binkert.org code(""" 57211802Sandreas.sandberg@arm.comimport _m5.core 5736654Snate@binkert.orgimport m5.util 5746654Snate@binkert.org 5756654Snate@binkert.orgbuildEnv = m5.util.SmartDict($build_env) 5766654Snate@binkert.org 57711802Sandreas.sandberg@arm.comcompileDate = _m5.core.compileDate 5786669Snate@binkert.org_globals = globals() 57911802Sandreas.sandberg@arm.comfor key,val in _m5.core.__dict__.iteritems(): 5806669Snate@binkert.org if key.startswith('flag_'): 5816669Snate@binkert.org flag = key[5:] 5826669Snate@binkert.org _globals[flag] = val 5836669Snate@binkert.orgdel _globals 5846654Snate@binkert.org""") 5857673Snate@binkert.org code.write(target[0].abspath) 5865517Snate@binkert.org 5878126Sgblack@eecs.umich.edudefines_info = Value(build_env) 5885798Snate@binkert.org# Generate a file with all of the compile options in it 5897756SAli.Saidi@ARM.comenv.Command('python/m5/defines.py', defines_info, 5907816Ssteve.reinhardt@amd.com MakeAction(makeDefinesPyFile, Transform("DEFINES", 0))) 5915798Snate@binkert.orgPySource('m5', 'python/m5/defines.py') 5925798Snate@binkert.org 5935517Snate@binkert.org# Generate python file containing info about the M5 source code 5945517Snate@binkert.orgdef makeInfoPyFile(target, source, env): 5957673Snate@binkert.org code = code_formatter() 5965517Snate@binkert.org for src in source: 5975517Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 5987673Snate@binkert.org code('$src = ${{repr(data)}}') 5997673Snate@binkert.org code.write(str(target[0])) 6005517Snate@binkert.org 6015798Snate@binkert.org# Generate a file that wraps the basic top level files 6025798Snate@binkert.orgenv.Command('python/m5/info.py', 6038333Snate@binkert.org [ '#/COPYING', '#/LICENSE', '#/README', ], 6047816Ssteve.reinhardt@amd.com MakeAction(makeInfoPyFile, Transform("INFO"))) 6055798Snate@binkert.orgPySource('m5', 'python/m5/info.py') 6065798Snate@binkert.org 6074762Snate@binkert.org######################################################################## 6084762Snate@binkert.org# 6094762Snate@binkert.org# Create all of the SimObject param headers and enum headers 6104762Snate@binkert.org# 6114762Snate@binkert.org 6128596Ssteve.reinhardt@amd.comdef createSimObjectParamStruct(target, source, env): 6135517Snate@binkert.org assert len(target) == 1 and len(source) == 1 6145517Snate@binkert.org 61511997Sgabeblack@google.com name = source[0].get_text_contents() 6165517Snate@binkert.org obj = sim_objects[name] 6175517Snate@binkert.org 6187673Snate@binkert.org code = code_formatter() 6198596Ssteve.reinhardt@amd.com obj.cxx_param_decl(code) 6207673Snate@binkert.org code.write(target[0].abspath) 6215517Snate@binkert.org 62210458Sandreas.hansson@arm.comdef createSimObjectCxxConfig(is_header): 62310458Sandreas.hansson@arm.com def body(target, source, env): 62410458Sandreas.hansson@arm.com assert len(target) == 1 and len(source) == 1 62510458Sandreas.hansson@arm.com 62610458Sandreas.hansson@arm.com name = str(source[0].get_contents()) 62710458Sandreas.hansson@arm.com obj = sim_objects[name] 62810458Sandreas.hansson@arm.com 62910458Sandreas.hansson@arm.com code = code_formatter() 63010458Sandreas.hansson@arm.com obj.cxx_config_param_file(code, is_header) 63110458Sandreas.hansson@arm.com code.write(target[0].abspath) 63210458Sandreas.hansson@arm.com return body 63310458Sandreas.hansson@arm.com 6345517Snate@binkert.orgdef createEnumStrings(target, source, env): 63511996Sgabeblack@google.com assert len(target) == 1 and len(source) == 2 6365517Snate@binkert.org 63711997Sgabeblack@google.com name = source[0].get_text_contents() 63811996Sgabeblack@google.com use_python = source[1].read() 6395517Snate@binkert.org obj = all_enums[name] 6405517Snate@binkert.org 6417673Snate@binkert.org code = code_formatter() 6427673Snate@binkert.org obj.cxx_def(code) 64311996Sgabeblack@google.com if use_python: 64411988Sandreas.sandberg@arm.com obj.pybind_def(code) 6457673Snate@binkert.org code.write(target[0].abspath) 6465517Snate@binkert.org 6478596Ssteve.reinhardt@amd.comdef createEnumDecls(target, source, env): 6485517Snate@binkert.org assert len(target) == 1 and len(source) == 1 6495517Snate@binkert.org 65011997Sgabeblack@google.com name = source[0].get_text_contents() 6515517Snate@binkert.org obj = all_enums[name] 6525517Snate@binkert.org 6537673Snate@binkert.org code = code_formatter() 6547673Snate@binkert.org obj.cxx_decl(code) 6557673Snate@binkert.org code.write(target[0].abspath) 6565517Snate@binkert.org 65711988Sandreas.sandberg@arm.comdef createSimObjectPyBindWrapper(target, source, env): 65811997Sgabeblack@google.com name = source[0].get_text_contents() 6598596Ssteve.reinhardt@amd.com obj = sim_objects[name] 6608596Ssteve.reinhardt@amd.com 6618596Ssteve.reinhardt@amd.com code = code_formatter() 66211988Sandreas.sandberg@arm.com obj.pybind_decl(code) 6638596Ssteve.reinhardt@amd.com code.write(target[0].abspath) 6648596Ssteve.reinhardt@amd.com 6658596Ssteve.reinhardt@amd.com# Generate all of the SimObject param C++ struct header files 6664762Snate@binkert.orgparams_hh_files = [] 6676143Snate@binkert.orgfor name,simobj in sorted(sim_objects.iteritems()): 6686143Snate@binkert.org py_source = PySource.modules[simobj.__module__] 6696143Snate@binkert.org extra_deps = [ py_source.tnode ] 6704762Snate@binkert.org 6714762Snate@binkert.org hh_file = File('params/%s.hh' % name) 6724762Snate@binkert.org params_hh_files.append(hh_file) 6737756SAli.Saidi@ARM.com env.Command(hh_file, Value(name), 6748596Ssteve.reinhardt@amd.com MakeAction(createSimObjectParamStruct, Transform("SO PARAM"))) 6754762Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 6764762Snate@binkert.org 67710458Sandreas.hansson@arm.com# C++ parameter description files 67810458Sandreas.hansson@arm.comif GetOption('with_cxx_config'): 67910458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 68010458Sandreas.hansson@arm.com py_source = PySource.modules[simobj.__module__] 68110458Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 68210458Sandreas.hansson@arm.com 68310458Sandreas.hansson@arm.com cxx_config_hh_file = File('cxx_config/%s.hh' % name) 68410458Sandreas.hansson@arm.com cxx_config_cc_file = File('cxx_config/%s.cc' % name) 68510458Sandreas.hansson@arm.com env.Command(cxx_config_hh_file, Value(name), 68610458Sandreas.hansson@arm.com MakeAction(createSimObjectCxxConfig(True), 68710458Sandreas.hansson@arm.com Transform("CXXCPRHH"))) 68810458Sandreas.hansson@arm.com env.Command(cxx_config_cc_file, Value(name), 68910458Sandreas.hansson@arm.com MakeAction(createSimObjectCxxConfig(False), 69010458Sandreas.hansson@arm.com Transform("CXXCPRCC"))) 69110458Sandreas.hansson@arm.com env.Depends(cxx_config_hh_file, depends + extra_deps + 69210458Sandreas.hansson@arm.com [File('params/%s.hh' % name), File('sim/cxx_config.hh')]) 69310458Sandreas.hansson@arm.com env.Depends(cxx_config_cc_file, depends + extra_deps + 69410458Sandreas.hansson@arm.com [cxx_config_hh_file]) 69510458Sandreas.hansson@arm.com Source(cxx_config_cc_file) 69610458Sandreas.hansson@arm.com 69710458Sandreas.hansson@arm.com cxx_config_init_cc_file = File('cxx_config/init.cc') 69810458Sandreas.hansson@arm.com 69910458Sandreas.hansson@arm.com def createCxxConfigInitCC(target, source, env): 70010458Sandreas.hansson@arm.com assert len(target) == 1 and len(source) == 1 70110458Sandreas.hansson@arm.com 70210458Sandreas.hansson@arm.com code = code_formatter() 70310458Sandreas.hansson@arm.com 70410458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 70510458Sandreas.hansson@arm.com if not hasattr(simobj, 'abstract') or not simobj.abstract: 70610458Sandreas.hansson@arm.com code('#include "cxx_config/${name}.hh"') 70710458Sandreas.hansson@arm.com code() 70810458Sandreas.hansson@arm.com code('void cxxConfigInit()') 70910458Sandreas.hansson@arm.com code('{') 71010458Sandreas.hansson@arm.com code.indent() 71110458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 71210458Sandreas.hansson@arm.com not_abstract = not hasattr(simobj, 'abstract') or \ 71310458Sandreas.hansson@arm.com not simobj.abstract 71410458Sandreas.hansson@arm.com if not_abstract and 'type' in simobj.__dict__: 71510458Sandreas.hansson@arm.com code('cxx_config_directory["${name}"] = ' 71610458Sandreas.hansson@arm.com '${name}CxxConfigParams::makeDirectoryEntry();') 71710458Sandreas.hansson@arm.com code.dedent() 71810458Sandreas.hansson@arm.com code('}') 71910458Sandreas.hansson@arm.com code.write(target[0].abspath) 72010458Sandreas.hansson@arm.com 72110458Sandreas.hansson@arm.com py_source = PySource.modules[simobj.__module__] 72210458Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 72310458Sandreas.hansson@arm.com env.Command(cxx_config_init_cc_file, Value(name), 72410458Sandreas.hansson@arm.com MakeAction(createCxxConfigInitCC, Transform("CXXCINIT"))) 72510458Sandreas.hansson@arm.com cxx_param_hh_files = ["cxx_config/%s.hh" % simobj 72610584Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()) 72710458Sandreas.hansson@arm.com if not hasattr(simobj, 'abstract') or not simobj.abstract] 72810458Sandreas.hansson@arm.com Depends(cxx_config_init_cc_file, cxx_param_hh_files + 72910458Sandreas.hansson@arm.com [File('sim/cxx_config.hh')]) 73010458Sandreas.hansson@arm.com Source(cxx_config_init_cc_file) 73110458Sandreas.hansson@arm.com 7324762Snate@binkert.org# Generate all enum header files 7336143Snate@binkert.orgfor name,enum in sorted(all_enums.iteritems()): 7346143Snate@binkert.org py_source = PySource.modules[enum.__module__] 7356143Snate@binkert.org extra_deps = [ py_source.tnode ] 7364762Snate@binkert.org 7374762Snate@binkert.org cc_file = File('enums/%s.cc' % name) 73811996Sgabeblack@google.com env.Command(cc_file, [Value(name), Value(env['USE_PYTHON'])], 7397816Ssteve.reinhardt@amd.com MakeAction(createEnumStrings, Transform("ENUM STR"))) 7404762Snate@binkert.org env.Depends(cc_file, depends + extra_deps) 7414762Snate@binkert.org Source(cc_file) 7424762Snate@binkert.org 7434762Snate@binkert.org hh_file = File('enums/%s.hh' % name) 7447756SAli.Saidi@ARM.com env.Command(hh_file, Value(name), 7458596Ssteve.reinhardt@amd.com MakeAction(createEnumDecls, Transform("ENUMDECL"))) 7464762Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 7474762Snate@binkert.org 74811988Sandreas.sandberg@arm.com# Generate SimObject Python bindings wrapper files 74911988Sandreas.sandberg@arm.comif env['USE_PYTHON']: 75011988Sandreas.sandberg@arm.com for name,simobj in sorted(sim_objects.iteritems()): 75111988Sandreas.sandberg@arm.com py_source = PySource.modules[simobj.__module__] 75211988Sandreas.sandberg@arm.com extra_deps = [ py_source.tnode ] 75311988Sandreas.sandberg@arm.com cc_file = File('python/_m5/param_%s.cc' % name) 75411988Sandreas.sandberg@arm.com env.Command(cc_file, Value(name), 75511988Sandreas.sandberg@arm.com MakeAction(createSimObjectPyBindWrapper, 75611988Sandreas.sandberg@arm.com Transform("SO PyBind"))) 75711988Sandreas.sandberg@arm.com env.Depends(cc_file, depends + extra_deps) 75811988Sandreas.sandberg@arm.com Source(cc_file) 7594382Sbinkertn@umich.edu 7609396Sandreas.hansson@arm.com# Build all protocol buffers if we have got protoc and protobuf available 7619396Sandreas.hansson@arm.comif env['HAVE_PROTOBUF']: 7629396Sandreas.hansson@arm.com for proto in ProtoBuf.all: 7639396Sandreas.hansson@arm.com # Use both the source and header as the target, and the .proto 7649396Sandreas.hansson@arm.com # file as the source. When executing the protoc compiler, also 7659396Sandreas.hansson@arm.com # specify the proto_path to avoid having the generated files 7669396Sandreas.hansson@arm.com # include the path. 7679396Sandreas.hansson@arm.com env.Command([proto.cc_file, proto.hh_file], proto.tnode, 7689396Sandreas.hansson@arm.com MakeAction('$PROTOC --cpp_out ${TARGET.dir} ' 7699396Sandreas.hansson@arm.com '--proto_path ${SOURCE.dir} $SOURCE', 7709396Sandreas.hansson@arm.com Transform("PROTOC"))) 7719396Sandreas.hansson@arm.com 7729396Sandreas.hansson@arm.com # Add the C++ source file 7739396Sandreas.hansson@arm.com Source(proto.cc_file, **proto.guards) 7749396Sandreas.hansson@arm.comelif ProtoBuf.all: 7759396Sandreas.hansson@arm.com print 'Got protobuf to build, but lacks support!' 7769396Sandreas.hansson@arm.com Exit(1) 7779396Sandreas.hansson@arm.com 7788232Snate@binkert.org# 7798232Snate@binkert.org# Handle debug flags 7808232Snate@binkert.org# 7818232Snate@binkert.orgdef makeDebugFlagCC(target, source, env): 7828232Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 7836229Snate@binkert.org 78410455SCurtis.Dunham@arm.com code = code_formatter() 7856229Snate@binkert.org 78610455SCurtis.Dunham@arm.com # delay definition of CompoundFlags until after all the definition 78710455SCurtis.Dunham@arm.com # of all constituent SimpleFlags 78810455SCurtis.Dunham@arm.com comp_code = code_formatter() 7895517Snate@binkert.org 7905517Snate@binkert.org # file header 7917673Snate@binkert.org code(''' 7925517Snate@binkert.org/* 79310455SCurtis.Dunham@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons. 7945517Snate@binkert.org */ 7955517Snate@binkert.org 7968232Snate@binkert.org#include "base/debug.hh" 79710455SCurtis.Dunham@arm.com 79810455SCurtis.Dunham@arm.comnamespace Debug { 79910455SCurtis.Dunham@arm.com 8007673Snate@binkert.org''') 8017673Snate@binkert.org 80210455SCurtis.Dunham@arm.com for name, flag in sorted(source[0].read().iteritems()): 80310455SCurtis.Dunham@arm.com n, compound, desc = flag 80410455SCurtis.Dunham@arm.com assert n == name 8055517Snate@binkert.org 80610455SCurtis.Dunham@arm.com if not compound: 80710455SCurtis.Dunham@arm.com code('SimpleFlag $name("$name", "$desc");') 80810455SCurtis.Dunham@arm.com else: 80910455SCurtis.Dunham@arm.com comp_code('CompoundFlag $name("$name", "$desc",') 81010455SCurtis.Dunham@arm.com comp_code.indent() 81110455SCurtis.Dunham@arm.com last = len(compound) - 1 81210455SCurtis.Dunham@arm.com for i,flag in enumerate(compound): 81310455SCurtis.Dunham@arm.com if i != last: 81410685Sandreas.hansson@arm.com comp_code('&$flag,') 81510455SCurtis.Dunham@arm.com else: 81610685Sandreas.hansson@arm.com comp_code('&$flag);') 81710455SCurtis.Dunham@arm.com comp_code.dedent() 8185517Snate@binkert.org 81910455SCurtis.Dunham@arm.com code.append(comp_code) 8208232Snate@binkert.org code() 8218232Snate@binkert.org code('} // namespace Debug') 8225517Snate@binkert.org 8237673Snate@binkert.org code.write(str(target[0])) 8245517Snate@binkert.org 8258232Snate@binkert.orgdef makeDebugFlagHH(target, source, env): 8268232Snate@binkert.org assert(len(target) == 1 and len(source) == 1) 8275517Snate@binkert.org 8288232Snate@binkert.org val = eval(source[0].get_contents()) 8298232Snate@binkert.org name, compound, desc = val 8308232Snate@binkert.org 8317673Snate@binkert.org code = code_formatter() 8325517Snate@binkert.org 8335517Snate@binkert.org # file header boilerplate 8347673Snate@binkert.org code('''\ 8355517Snate@binkert.org/* 83610455SCurtis.Dunham@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons. 8375517Snate@binkert.org */ 8385517Snate@binkert.org 8398232Snate@binkert.org#ifndef __DEBUG_${name}_HH__ 8408232Snate@binkert.org#define __DEBUG_${name}_HH__ 8415517Snate@binkert.org 8428232Snate@binkert.orgnamespace Debug { 8438232Snate@binkert.org''') 8445517Snate@binkert.org 8458232Snate@binkert.org if compound: 8468232Snate@binkert.org code('class CompoundFlag;') 8478232Snate@binkert.org code('class SimpleFlag;') 8485517Snate@binkert.org 8498232Snate@binkert.org if compound: 8508232Snate@binkert.org code('extern CompoundFlag $name;') 8518232Snate@binkert.org for flag in compound: 8528232Snate@binkert.org code('extern SimpleFlag $flag;') 8538232Snate@binkert.org else: 8548232Snate@binkert.org code('extern SimpleFlag $name;') 8555517Snate@binkert.org 8568232Snate@binkert.org code(''' 8578232Snate@binkert.org} 8585517Snate@binkert.org 8598232Snate@binkert.org#endif // __DEBUG_${name}_HH__ 8607673Snate@binkert.org''') 8615517Snate@binkert.org 8627673Snate@binkert.org code.write(str(target[0])) 8635517Snate@binkert.org 8648232Snate@binkert.orgfor name,flag in sorted(debug_flags.iteritems()): 8658232Snate@binkert.org n, compound, desc = flag 8668232Snate@binkert.org assert n == name 8675192Ssaidi@eecs.umich.edu 86810454SCurtis.Dunham@arm.com hh_file = 'debug/%s.hh' % name 86910454SCurtis.Dunham@arm.com env.Command(hh_file, Value(flag), 8708232Snate@binkert.org MakeAction(makeDebugFlagHH, Transform("TRACING", 0))) 87110455SCurtis.Dunham@arm.com 87210455SCurtis.Dunham@arm.comenv.Command('debug/flags.cc', Value(debug_flags), 87310455SCurtis.Dunham@arm.com MakeAction(makeDebugFlagCC, Transform("TRACING", 0))) 87410455SCurtis.Dunham@arm.comSource('debug/flags.cc') 8755192Ssaidi@eecs.umich.edu 87611077SCurtis.Dunham@arm.com# version tags 87711330SCurtis.Dunham@arm.comtags = \ 87811077SCurtis.Dunham@arm.comenv.Command('sim/tags.cc', None, 87911077SCurtis.Dunham@arm.com MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET', 88011077SCurtis.Dunham@arm.com Transform("VER TAGS"))) 88111330SCurtis.Dunham@arm.comenv.AlwaysBuild(tags) 88211077SCurtis.Dunham@arm.com 8837674Snate@binkert.org# Embed python files. All .py files that have been indicated by a 8845522Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5 8855522Snate@binkert.org# library. To do that, we compile the file to byte code, marshal the 8867674Snate@binkert.org# byte code, compress it, and then generate a c++ file that 8877674Snate@binkert.org# inserts the result into an array. 8887674Snate@binkert.orgdef embedPyFile(target, source, env): 8897674Snate@binkert.org def c_str(string): 8907674Snate@binkert.org if string is None: 8917674Snate@binkert.org return "0" 8927674Snate@binkert.org return '"%s"' % string 8937674Snate@binkert.org 8945522Snate@binkert.org '''Action function to compile a .py into a code object, marshal 8955522Snate@binkert.org it, compress it, and stick it into an asm file so the code appears 8965522Snate@binkert.org as just bytes with a label in the data section''' 8975517Snate@binkert.org 8985522Snate@binkert.org src = file(str(source[0]), 'r').read() 8995517Snate@binkert.org 9006143Snate@binkert.org pysource = PySource.tnodes[source[0]] 9016727Ssteve.reinhardt@amd.com compiled = compile(src, pysource.abspath, 'exec') 9025522Snate@binkert.org marshalled = marshal.dumps(compiled) 9035522Snate@binkert.org compressed = zlib.compress(marshalled) 9045522Snate@binkert.org data = compressed 9057674Snate@binkert.org sym = pysource.symname 9065517Snate@binkert.org 9077673Snate@binkert.org code = code_formatter() 9087673Snate@binkert.org code('''\ 9097674Snate@binkert.org#include "sim/init.hh" 9107673Snate@binkert.org 9117674Snate@binkert.orgnamespace { 9127674Snate@binkert.org 9138946Sandreas.hansson@arm.comconst uint8_t data_${sym}[] = { 9147674Snate@binkert.org''') 9157674Snate@binkert.org code.indent() 9167674Snate@binkert.org step = 16 9175522Snate@binkert.org for i in xrange(0, len(data), step): 9185522Snate@binkert.org x = array.array('B', data[i:i+step]) 9197674Snate@binkert.org code(''.join('%d,' % d for d in x)) 9207674Snate@binkert.org code.dedent() 92111308Santhony.gutierrez@amd.com 9227674Snate@binkert.org code('''}; 9237673Snate@binkert.org 9247674Snate@binkert.orgEmbeddedPython embedded_${sym}( 9257674Snate@binkert.org ${{c_str(pysource.arcname)}}, 9267674Snate@binkert.org ${{c_str(pysource.abspath)}}, 9277674Snate@binkert.org ${{c_str(pysource.modpath)}}, 9287674Snate@binkert.org data_${sym}, 9297674Snate@binkert.org ${{len(data)}}, 9307674Snate@binkert.org ${{len(marshalled)}}); 9317674Snate@binkert.org 9327811Ssteve.reinhardt@amd.com} // anonymous namespace 9337674Snate@binkert.org''') 9347673Snate@binkert.org code.write(str(target[0])) 9355522Snate@binkert.org 9366143Snate@binkert.orgfor source in PySource.all: 93710453SAndrew.Bardsley@arm.com env.Command(source.cpp, source.tnode, 9387816Ssteve.reinhardt@amd.com MakeAction(embedPyFile, Transform("EMBED PY"))) 93910453SAndrew.Bardsley@arm.com Source(source.cpp, skip_no_python=True) 9404382Sbinkertn@umich.edu 9414382Sbinkertn@umich.edu######################################################################## 9424382Sbinkertn@umich.edu# 9434382Sbinkertn@umich.edu# Define binaries. Each different build type (debug, opt, etc.) gets 9444382Sbinkertn@umich.edu# a slightly different build environment. 9454382Sbinkertn@umich.edu# 9464382Sbinkertn@umich.edu 9474382Sbinkertn@umich.edu# List of constructed environments to pass back to SConstruct 94810196SCurtis.Dunham@arm.comdate_source = Source('base/date.cc', skip_lib=True) 9494382Sbinkertn@umich.edu 9502655Sstever@eecs.umich.edu# Function to create a new build environment as clone of current 9512655Sstever@eecs.umich.edu# environment 'env' with modified object suffix and optional stripped 9522655Sstever@eecs.umich.edu# binary. Additional keyword arguments are appended to corresponding 9532655Sstever@eecs.umich.edu# build environment vars. 95412063Sgabeblack@google.comdef makeEnv(env, label, objsfx, strip=False, disable_partial=False, **kwargs): 9555601Snate@binkert.org # SCons doesn't know to append a library suffix when there is a '.' in the 9565601Snate@binkert.org # name. Use '_' instead. 95712222Sgabeblack@google.com libname = 'gem5_' + label 95812222Sgabeblack@google.com exename = 'gem5.' + label 95912222Sgabeblack@google.com secondary_exename = 'm5.' + label 9605522Snate@binkert.org 9615863Snate@binkert.org new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 9625601Snate@binkert.org new_env.Label = label 9635601Snate@binkert.org new_env.Append(**kwargs) 9645601Snate@binkert.org 9655559Snate@binkert.org if env['GCC']: 96611718Sjoseph.gross@amd.com # The address sanitizer is available for gcc >= 4.8 96711718Sjoseph.gross@amd.com if GetOption('with_asan'): 96811718Sjoseph.gross@amd.com if GetOption('with_ubsan') and \ 96911718Sjoseph.gross@amd.com compareVersions(env['GCC_VERSION'], '4.9') >= 0: 97011718Sjoseph.gross@amd.com new_env.Append(CCFLAGS=['-fsanitize=address,undefined', 97111718Sjoseph.gross@amd.com '-fno-omit-frame-pointer']) 97211718Sjoseph.gross@amd.com new_env.Append(LINKFLAGS='-fsanitize=address,undefined') 97311718Sjoseph.gross@amd.com else: 97411718Sjoseph.gross@amd.com new_env.Append(CCFLAGS=['-fsanitize=address', 97511718Sjoseph.gross@amd.com '-fno-omit-frame-pointer']) 97611718Sjoseph.gross@amd.com new_env.Append(LINKFLAGS='-fsanitize=address') 97710457Sandreas.hansson@arm.com # Only gcc >= 4.9 supports UBSan, so check both the version 97810457Sandreas.hansson@arm.com # and the command-line option before adding the compiler and 97910457Sandreas.hansson@arm.com # linker flags. 98011718Sjoseph.gross@amd.com elif GetOption('with_ubsan') and \ 98110457Sandreas.hansson@arm.com compareVersions(env['GCC_VERSION'], '4.9') >= 0: 98210457Sandreas.hansson@arm.com new_env.Append(CCFLAGS='-fsanitize=undefined') 98310457Sandreas.hansson@arm.com new_env.Append(LINKFLAGS='-fsanitize=undefined') 98410457Sandreas.hansson@arm.com 98511342Sandreas.hansson@arm.com 9868737Skoansin.tan@gmail.com if env['CLANG']: 98711342Sandreas.hansson@arm.com # We require clang >= 3.1, so there is no need to check any 98811342Sandreas.hansson@arm.com # versions here. 98910457Sandreas.hansson@arm.com if GetOption('with_ubsan'): 99011718Sjoseph.gross@amd.com if GetOption('with_asan'): 99111718Sjoseph.gross@amd.com new_env.Append(CCFLAGS=['-fsanitize=address,undefined', 99211718Sjoseph.gross@amd.com '-fno-omit-frame-pointer']) 99311718Sjoseph.gross@amd.com new_env.Append(LINKFLAGS='-fsanitize=address,undefined') 99411718Sjoseph.gross@amd.com else: 99511718Sjoseph.gross@amd.com new_env.Append(CCFLAGS='-fsanitize=undefined') 99611718Sjoseph.gross@amd.com new_env.Append(LINKFLAGS='-fsanitize=undefined') 99710457Sandreas.hansson@arm.com 99811718Sjoseph.gross@amd.com elif GetOption('with_asan'): 99911500Sandreas.hansson@arm.com new_env.Append(CCFLAGS=['-fsanitize=address', 100011500Sandreas.hansson@arm.com '-fno-omit-frame-pointer']) 100111342Sandreas.hansson@arm.com new_env.Append(LINKFLAGS='-fsanitize=address') 100211342Sandreas.hansson@arm.com 10038945Ssteve.reinhardt@amd.com werror_env = new_env.Clone() 100410686SAndreas.Sandberg@ARM.com # Treat warnings as errors but white list some warnings that we 100510686SAndreas.Sandberg@ARM.com # want to allow (e.g., deprecation warnings). 100610686SAndreas.Sandberg@ARM.com werror_env.Append(CCFLAGS=['-Werror', 100710686SAndreas.Sandberg@ARM.com '-Wno-error=deprecated-declarations', 100810686SAndreas.Sandberg@ARM.com '-Wno-error=deprecated', 100910686SAndreas.Sandberg@ARM.com ]) 10108945Ssteve.reinhardt@amd.com 10116143Snate@binkert.org def make_obj(source, static, extra_deps = None): 10126143Snate@binkert.org '''This function adds the specified source to the correct 10136143Snate@binkert.org build environment, and returns the corresponding SCons Object 10146143Snate@binkert.org nodes''' 10156143Snate@binkert.org 101611988Sandreas.sandberg@arm.com if source.Werror: 10178945Ssteve.reinhardt@amd.com env = werror_env 10186143Snate@binkert.org else: 10196143Snate@binkert.org env = new_env 10206143Snate@binkert.org 10216143Snate@binkert.org if static: 10226143Snate@binkert.org obj = env.StaticObject(source.tnode) 10236143Snate@binkert.org else: 10246143Snate@binkert.org obj = env.SharedObject(source.tnode) 10256143Snate@binkert.org 10266143Snate@binkert.org if extra_deps: 10276143Snate@binkert.org env.Depends(obj, extra_deps) 10286143Snate@binkert.org 10296143Snate@binkert.org return obj 10306143Snate@binkert.org 103110453SAndrew.Bardsley@arm.com lib_guards = {'main': False, 'skip_lib': False} 103210453SAndrew.Bardsley@arm.com 103311988Sandreas.sandberg@arm.com # Without Python, leave out all Python content from the library 103411988Sandreas.sandberg@arm.com # builds. The option doesn't affect gem5 built as a program 103510453SAndrew.Bardsley@arm.com if GetOption('without_python'): 103610453SAndrew.Bardsley@arm.com lib_guards['skip_no_python'] = False 103710453SAndrew.Bardsley@arm.com 103811983Sgabeblack@google.com static_objs = [] 103911983Sgabeblack@google.com shared_objs = [] 104011983Sgabeblack@google.com for s in guarded_source_iterator(Source.source_groups[None], **lib_guards): 104111983Sgabeblack@google.com static_objs.append(make_obj(s, True)) 104211983Sgabeblack@google.com shared_objs.append(make_obj(s, False)) 104311983Sgabeblack@google.com 104411983Sgabeblack@google.com partial_objs = [] 104511983Sgabeblack@google.com for group, all_srcs in Source.source_groups.iteritems(): 104611983Sgabeblack@google.com # If these are the ungrouped source files, skip them. 104711983Sgabeblack@google.com if not group: 104811983Sgabeblack@google.com continue 104911983Sgabeblack@google.com 105011983Sgabeblack@google.com # Get a list of the source files compatible with the current guards. 105111983Sgabeblack@google.com srcs = [ s for s in guarded_source_iterator(all_srcs, **lib_guards) ] 105211983Sgabeblack@google.com # If there aren't any left, skip this group. 105311983Sgabeblack@google.com if not srcs: 105411983Sgabeblack@google.com continue 105511983Sgabeblack@google.com 105612063Sgabeblack@google.com # If partial linking is disabled, add these sources to the build 105712063Sgabeblack@google.com # directly, and short circuit this loop. 105812063Sgabeblack@google.com if disable_partial: 105912063Sgabeblack@google.com for s in srcs: 106012063Sgabeblack@google.com static_objs.append(make_obj(s, True)) 106112063Sgabeblack@google.com shared_objs.append(make_obj(s, False)) 106212063Sgabeblack@google.com continue 106312063Sgabeblack@google.com 106411983Sgabeblack@google.com # Set up the static partially linked objects. 106511983Sgabeblack@google.com source_objs = [ make_obj(s, True) for s in srcs ] 106611983Sgabeblack@google.com file_name = new_env.subst("${OBJPREFIX}lib${OBJSUFFIX}.partial") 106711983Sgabeblack@google.com target = File(joinpath(group, file_name)) 106811983Sgabeblack@google.com partial = env.PartialStatic(target=target, source=source_objs) 106911983Sgabeblack@google.com static_objs.append(partial) 107011983Sgabeblack@google.com 107111983Sgabeblack@google.com # Set up the shared partially linked objects. 107211983Sgabeblack@google.com source_objs = [ make_obj(s, False) for s in srcs ] 107311983Sgabeblack@google.com file_name = new_env.subst("${SHOBJPREFIX}lib${SHOBJSUFFIX}.partial") 107411983Sgabeblack@google.com target = File(joinpath(group, file_name)) 107511983Sgabeblack@google.com partial = env.PartialShared(target=target, source=source_objs) 107611983Sgabeblack@google.com shared_objs.append(partial) 10776143Snate@binkert.org 10786143Snate@binkert.org static_date = make_obj(date_source, static=True, extra_deps=static_objs) 10796143Snate@binkert.org static_objs.append(static_date) 108010453SAndrew.Bardsley@arm.com 10816143Snate@binkert.org shared_date = make_obj(date_source, static=False, extra_deps=shared_objs) 10826240Snate@binkert.org shared_objs.append(shared_date) 10835554Snate@binkert.org 10845522Snate@binkert.org # First make a library of everything but main() so other programs can 10855522Snate@binkert.org # link against m5. 10865797Snate@binkert.org static_lib = new_env.StaticLibrary(libname, static_objs) 10875797Snate@binkert.org shared_lib = new_env.SharedLibrary(libname, shared_objs) 10885522Snate@binkert.org 10895601Snate@binkert.org # Now link a stub with main() and the static library. 10908233Snate@binkert.org main_objs = [ make_obj(s, True) for s in Source.get(main=True) ] 10918233Snate@binkert.org 10928235Snate@binkert.org for test in UnitTest.all: 10938235Snate@binkert.org flags = { test.target : True } 10948235Snate@binkert.org test_sources = Source.get(**flags) 10958235Snate@binkert.org test_objs = [ make_obj(s, static=True) for s in test_sources ] 10969003SAli.Saidi@ARM.com if test.main: 10979003SAli.Saidi@ARM.com test_objs += main_objs 109812222Sgabeblack@google.com path = 'unittest/%s.%s' % (test.target, label) 109910196SCurtis.Dunham@arm.com new_env.Program(path, test_objs + static_objs) 11008235Snate@binkert.org 11016143Snate@binkert.org progname = exename 11022655Sstever@eecs.umich.edu if strip: 11036143Snate@binkert.org progname += '.unstripped' 11046143Snate@binkert.org 110511985Sgabeblack@google.com targets = new_env.Program(progname, main_objs + static_objs) 11066143Snate@binkert.org 11076143Snate@binkert.org if strip: 11084007Ssaidi@eecs.umich.edu if sys.platform == 'sunos5': 11094596Sbinkertn@umich.edu cmd = 'cp $SOURCE $TARGET; strip $TARGET' 11104007Ssaidi@eecs.umich.edu else: 11114596Sbinkertn@umich.edu cmd = 'strip $SOURCE -o $TARGET' 11127756SAli.Saidi@ARM.com targets = new_env.Command(exename, progname, 11137816Ssteve.reinhardt@amd.com MakeAction(cmd, Transform("STRIP"))) 11148334Snate@binkert.org 11158334Snate@binkert.org new_env.Command(secondary_exename, exename, 11168334Snate@binkert.org MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK"))) 11178334Snate@binkert.org 11185601Snate@binkert.org new_env.M5Binary = targets[0] 111911993Sgabeblack@google.com 112011993Sgabeblack@google.com # Set up regression tests. 112111993Sgabeblack@google.com SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'), 112212223Sgabeblack@google.com variant_dir=Dir('tests').Dir(new_env.Label), 112311993Sgabeblack@google.com exports={ 'env' : new_env }, duplicate=False) 11242655Sstever@eecs.umich.edu 11259225Sandreas.hansson@arm.com# Start out with the compiler flags common to all compilers, 11269225Sandreas.hansson@arm.com# i.e. they all use -g for opt and -g -pg for prof 11279226Sandreas.hansson@arm.comccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'], 11289226Sandreas.hansson@arm.com 'perf' : ['-g']} 11299225Sandreas.hansson@arm.com 11309226Sandreas.hansson@arm.com# Start out with the linker flags common to all linkers, i.e. -pg for 11319226Sandreas.hansson@arm.com# prof, and -lprofiler for perf. The -lprofile flag is surrounded by 11329226Sandreas.hansson@arm.com# no-as-needed and as-needed as the binutils linker is too clever and 11339226Sandreas.hansson@arm.com# simply doesn't link to the library otherwise. 11349226Sandreas.hansson@arm.comldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'], 11359226Sandreas.hansson@arm.com 'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']} 11369225Sandreas.hansson@arm.com 11379227Sandreas.hansson@arm.com# For Link Time Optimization, the optimisation flags used to compile 11389227Sandreas.hansson@arm.com# individual files are decoupled from those used at link time 11399227Sandreas.hansson@arm.com# (i.e. you can compile with -O3 and perform LTO with -O0), so we need 11409227Sandreas.hansson@arm.com# to also update the linker flags based on the target. 11418946Sandreas.hansson@arm.comif env['GCC']: 11423918Ssaidi@eecs.umich.edu if sys.platform == 'sunos5': 11439225Sandreas.hansson@arm.com ccflags['debug'] += ['-gstabs+'] 11443918Ssaidi@eecs.umich.edu else: 11459225Sandreas.hansson@arm.com ccflags['debug'] += ['-ggdb3'] 11469225Sandreas.hansson@arm.com ldflags['debug'] += ['-O0'] 11479227Sandreas.hansson@arm.com # opt, fast, prof and perf all share the same cc flags, also add 11489227Sandreas.hansson@arm.com # the optimization to the ldflags as LTO defers the optimization 11499227Sandreas.hansson@arm.com # to link time 11509226Sandreas.hansson@arm.com for target in ['opt', 'fast', 'prof', 'perf']: 11519225Sandreas.hansson@arm.com ccflags[target] += ['-O3'] 11529227Sandreas.hansson@arm.com ldflags[target] += ['-O3'] 11539227Sandreas.hansson@arm.com 11549227Sandreas.hansson@arm.com ccflags['fast'] += env['LTO_CCFLAGS'] 11559227Sandreas.hansson@arm.com ldflags['fast'] += env['LTO_LDFLAGS'] 11568946Sandreas.hansson@arm.comelif env['CLANG']: 11579225Sandreas.hansson@arm.com ccflags['debug'] += ['-g', '-O0'] 11589226Sandreas.hansson@arm.com # opt, fast, prof and perf all share the same cc flags 11599226Sandreas.hansson@arm.com for target in ['opt', 'fast', 'prof', 'perf']: 11609226Sandreas.hansson@arm.com ccflags[target] += ['-O3'] 11613515Ssaidi@eecs.umich.eduelse: 11623918Ssaidi@eecs.umich.edu print 'Unknown compiler, please fix compiler options' 11634762Snate@binkert.org Exit(1) 11643515Ssaidi@eecs.umich.edu 11658881Smarc.orr@gmail.com 11668881Smarc.orr@gmail.com# To speed things up, we only instantiate the build environments we 11678881Smarc.orr@gmail.com# need. We try to identify the needed environment for each target; if 11688881Smarc.orr@gmail.com# we can't, we fall back on instantiating all the environments just to 11698881Smarc.orr@gmail.com# be safe. 11709226Sandreas.hansson@arm.comtarget_types = ['debug', 'opt', 'fast', 'prof', 'perf'] 11719226Sandreas.hansson@arm.comobj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof', 11729226Sandreas.hansson@arm.com 'gpo' : 'perf'} 11738881Smarc.orr@gmail.com 11748881Smarc.orr@gmail.comdef identifyTarget(t): 11758881Smarc.orr@gmail.com ext = t.split('.')[-1] 11768881Smarc.orr@gmail.com if ext in target_types: 11778881Smarc.orr@gmail.com return ext 11788881Smarc.orr@gmail.com if obj2target.has_key(ext): 11798881Smarc.orr@gmail.com return obj2target[ext] 11808881Smarc.orr@gmail.com match = re.search(r'/tests/([^/]+)/', t) 11818881Smarc.orr@gmail.com if match and match.group(1) in target_types: 11828881Smarc.orr@gmail.com return match.group(1) 11838881Smarc.orr@gmail.com return 'all' 11848881Smarc.orr@gmail.com 11858881Smarc.orr@gmail.comneeded_envs = [identifyTarget(target) for target in BUILD_TARGETS] 11868881Smarc.orr@gmail.comif 'all' in needed_envs: 11878881Smarc.orr@gmail.com needed_envs += target_types 11888881Smarc.orr@gmail.com 118912222Sgabeblack@google.com# Debug binary 119012222Sgabeblack@google.comif 'debug' in needed_envs: 119112222Sgabeblack@google.com makeEnv(env, 'debug', '.do', 119212222Sgabeblack@google.com CCFLAGS = Split(ccflags['debug']), 119312222Sgabeblack@google.com CPPDEFINES = ['DEBUG', 'TRACING_ON=1'], 119412222Sgabeblack@google.com LINKFLAGS = Split(ldflags['debug'])) 1195955SN/A 119612222Sgabeblack@google.com# Optimized binary 119712222Sgabeblack@google.comif 'opt' in needed_envs: 119812222Sgabeblack@google.com makeEnv(env, 'opt', '.o', 119912222Sgabeblack@google.com CCFLAGS = Split(ccflags['opt']), 120012222Sgabeblack@google.com CPPDEFINES = ['TRACING_ON=1'], 120112222Sgabeblack@google.com LINKFLAGS = Split(ldflags['opt'])) 1202955SN/A 120312222Sgabeblack@google.com# "Fast" binary 120412222Sgabeblack@google.comif 'fast' in needed_envs: 120512222Sgabeblack@google.com disable_partial = \ 120612222Sgabeblack@google.com env.get('BROKEN_INCREMENTAL_LTO', False) and \ 120712222Sgabeblack@google.com GetOption('force_lto') 120812222Sgabeblack@google.com makeEnv(env, 'fast', '.fo', strip = True, 120912222Sgabeblack@google.com CCFLAGS = Split(ccflags['fast']), 121012222Sgabeblack@google.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 121112222Sgabeblack@google.com LINKFLAGS = Split(ldflags['fast']), 121212222Sgabeblack@google.com disable_partial=disable_partial) 12131869SN/A 121412222Sgabeblack@google.com# Profiled binary using gprof 121512222Sgabeblack@google.comif 'prof' in needed_envs: 121612222Sgabeblack@google.com makeEnv(env, 'prof', '.po', 121712222Sgabeblack@google.com CCFLAGS = Split(ccflags['prof']), 121812222Sgabeblack@google.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 121912222Sgabeblack@google.com LINKFLAGS = Split(ldflags['prof'])) 12209226Sandreas.hansson@arm.com 122112222Sgabeblack@google.com# Profiled binary using google-pprof 122212222Sgabeblack@google.comif 'perf' in needed_envs: 122312222Sgabeblack@google.com makeEnv(env, 'perf', '.gpo', 122412222Sgabeblack@google.com CCFLAGS = Split(ccflags['perf']), 122512222Sgabeblack@google.com CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 122612222Sgabeblack@google.com LINKFLAGS = Split(ldflags['perf'])) 1227