SConscript revision 11988
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.com# This file defines how to build a particular configuration of gem5 4612246Sgabeblack@google.com# based on variable settings in the 'env' build environment. 478334Snate@binkert.org 48955SN/AImport('*') 49955SN/A 504202Sbinkertn@umich.edu# Children need to see the environment 51955SN/AExport('env') 524382Sbinkertn@umich.edu 534382Sbinkertn@umich.edubuild_env = [(opt, env[opt]) for opt in export_vars] 544382Sbinkertn@umich.edu 556654Snate@binkert.orgfrom m5.util import code_formatter, compareVersions 565517Snate@binkert.org 578614Sgblack@eecs.umich.edu######################################################################## 587674Snate@binkert.org# Code for adding source files of various types 596143Snate@binkert.org# 606143Snate@binkert.org# When specifying a source file of some type, a set of guards can be 616143Snate@binkert.org# specified for that file. When get() is used to find the files, if 6212302Sgabeblack@google.com# get specifies a set of filters, only files that match those filters 6312302Sgabeblack@google.com# will be accepted (unspecified filters on files are assumed to be 6412302Sgabeblack@google.com# false). Current filters are: 6512302Sgabeblack@google.com# main -- specifies the gem5 main() function 6612302Sgabeblack@google.com# skip_lib -- do not put this file into the gem5 library 6712302Sgabeblack@google.com# skip_no_python -- do not put this file into a no_python library 6812302Sgabeblack@google.com# as it embeds compiled Python 6912302Sgabeblack@google.com# <unittest> -- unit tests use filters based on the unit test name 7012302Sgabeblack@google.com# 7112302Sgabeblack@google.com# A parent can now be specified for a source file and default filter 7212302Sgabeblack@google.com# values will be retrieved recursively from parents (children override 7312302Sgabeblack@google.com# parents). 7412363Sgabeblack@google.com# 7512302Sgabeblack@google.comdef guarded_source_iterator(sources, **guards): 7612302Sgabeblack@google.com '''Iterate over a set of sources, gated by a set of guards.''' 7712302Sgabeblack@google.com for src in sources: 7812363Sgabeblack@google.com for flag,value in guards.iteritems(): 7912302Sgabeblack@google.com # if the flag is found and has a different value, skip 8012302Sgabeblack@google.com # this file 8112302Sgabeblack@google.com if src.all_guards.get(flag, False) != value: 8212302Sgabeblack@google.com break 8312302Sgabeblack@google.com else: 8412302Sgabeblack@google.com yield src 8512302Sgabeblack@google.com 8612363Sgabeblack@google.comclass SourceMeta(type): 8712302Sgabeblack@google.com '''Meta class for source files that keeps track of all files of a 8812302Sgabeblack@google.com particular type and has a get function for finding all functions 8912302Sgabeblack@google.com of a certain type that match a set of guards''' 9012302Sgabeblack@google.com def __init__(cls, name, bases, dict): 9111983Sgabeblack@google.com super(SourceMeta, cls).__init__(name, bases, dict) 926143Snate@binkert.org cls.all = [] 938233Snate@binkert.org 9412302Sgabeblack@google.com def get(cls, **guards): 956143Snate@binkert.org '''Find all files that match the specified guards. If a source 966143Snate@binkert.org file does not specify a flag, the default is False''' 9712302Sgabeblack@google.com for s in guarded_source_iterator(cls.all, **guards): 984762Snate@binkert.org yield s 996143Snate@binkert.org 1008233Snate@binkert.orgclass SourceFile(object): 1018233Snate@binkert.org '''Base object that encapsulates the notion of a source file. 10212302Sgabeblack@google.com This includes, the source node, target node, various manipulations 10312302Sgabeblack@google.com of those. A source file also specifies a set of guards which 1046143Snate@binkert.org describing which builds the source file applies to. A parent can 10512362Sgabeblack@google.com also be specified to get default guards from''' 10612362Sgabeblack@google.com __metaclass__ = SourceMeta 10712362Sgabeblack@google.com def __init__(self, source, parent=None, **guards): 10812362Sgabeblack@google.com self.guards = guards 10912302Sgabeblack@google.com self.parent = parent 11012302Sgabeblack@google.com 11112302Sgabeblack@google.com tnode = source 11212302Sgabeblack@google.com if not isinstance(source, SCons.Node.FS.File): 11312302Sgabeblack@google.com tnode = File(source) 11412363Sgabeblack@google.com 11512363Sgabeblack@google.com self.tnode = tnode 11612363Sgabeblack@google.com self.snode = tnode.srcnode() 11712363Sgabeblack@google.com 11812302Sgabeblack@google.com for base in type(self).__mro__: 11912363Sgabeblack@google.com if issubclass(base, SourceFile): 12012363Sgabeblack@google.com base.all.append(self) 12112363Sgabeblack@google.com 12212363Sgabeblack@google.com @property 12312363Sgabeblack@google.com def filename(self): 1248233Snate@binkert.org return str(self.tnode) 1256143Snate@binkert.org 1266143Snate@binkert.org @property 1276143Snate@binkert.org def dirname(self): 1286143Snate@binkert.org return dirname(self.filename) 1296143Snate@binkert.org 1306143Snate@binkert.org @property 1316143Snate@binkert.org def basename(self): 1326143Snate@binkert.org return basename(self.filename) 1336143Snate@binkert.org 1347065Snate@binkert.org @property 1356143Snate@binkert.org def extname(self): 13612362Sgabeblack@google.com index = self.basename.rfind('.') 13712362Sgabeblack@google.com if index <= 0: 13812362Sgabeblack@google.com # dot files aren't extensions 13912362Sgabeblack@google.com return self.basename, None 14012362Sgabeblack@google.com 14112362Sgabeblack@google.com return self.basename[:index], self.basename[index+1:] 14212362Sgabeblack@google.com 14312362Sgabeblack@google.com @property 14412362Sgabeblack@google.com def all_guards(self): 14512362Sgabeblack@google.com '''find all guards for this object getting default values 14612362Sgabeblack@google.com recursively from its parents''' 14712362Sgabeblack@google.com guards = {} 1488233Snate@binkert.org if self.parent: 1498233Snate@binkert.org guards.update(self.parent.guards) 1508233Snate@binkert.org guards.update(self.guards) 1518233Snate@binkert.org return guards 1528233Snate@binkert.org 1538233Snate@binkert.org def __lt__(self, other): return self.filename < other.filename 1548233Snate@binkert.org def __le__(self, other): return self.filename <= other.filename 1558233Snate@binkert.org def __gt__(self, other): return self.filename > other.filename 1568233Snate@binkert.org def __ge__(self, other): return self.filename >= other.filename 1578233Snate@binkert.org def __eq__(self, other): return self.filename == other.filename 1588233Snate@binkert.org def __ne__(self, other): return self.filename != other.filename 1598233Snate@binkert.org 1608233Snate@binkert.org @staticmethod 1618233Snate@binkert.org def done(): 1628233Snate@binkert.org def disabled(cls, name, *ignored): 1638233Snate@binkert.org raise RuntimeError("Additional SourceFile '%s'" % name,\ 1648233Snate@binkert.org "declared, but targets deps are already fixed.") 1658233Snate@binkert.org SourceFile.__init__ = disabled 1668233Snate@binkert.org 1678233Snate@binkert.org 1688233Snate@binkert.orgclass Source(SourceFile): 1696143Snate@binkert.org current_group = None 1706143Snate@binkert.org source_groups = { None : [] } 1716143Snate@binkert.org 1726143Snate@binkert.org @classmethod 1736143Snate@binkert.org def set_group(cls, group): 1746143Snate@binkert.org if not group in Source.source_groups: 1759982Satgutier@umich.edu Source.source_groups[group] = [] 1766143Snate@binkert.org Source.current_group = group 17712302Sgabeblack@google.com 17812302Sgabeblack@google.com '''Add a c/c++ source file to the build''' 17912302Sgabeblack@google.com def __init__(self, source, Werror=True, **guards): 18012302Sgabeblack@google.com '''specify the source file, and any guards''' 18112302Sgabeblack@google.com super(Source, self).__init__(source, **guards) 18212302Sgabeblack@google.com 18312302Sgabeblack@google.com self.Werror = Werror 18412302Sgabeblack@google.com 18511983Sgabeblack@google.com Source.source_groups[Source.current_group].append(self) 18611983Sgabeblack@google.com 18711983Sgabeblack@google.comclass PySource(SourceFile): 18812302Sgabeblack@google.com '''Add a python source file to the named package''' 18912302Sgabeblack@google.com invalid_sym_char = re.compile('[^A-z0-9_]') 19012302Sgabeblack@google.com modules = {} 19112302Sgabeblack@google.com tnodes = {} 19212302Sgabeblack@google.com symnames = {} 19312302Sgabeblack@google.com 19411983Sgabeblack@google.com def __init__(self, package, source, **guards): 1956143Snate@binkert.org '''specify the python package, the source file, and any guards''' 19612305Sgabeblack@google.com super(PySource, self).__init__(source, **guards) 19712302Sgabeblack@google.com 19812302Sgabeblack@google.com modname,ext = self.extname 19912302Sgabeblack@google.com assert ext == 'py' 2006143Snate@binkert.org 2016143Snate@binkert.org if package: 2026143Snate@binkert.org path = package.split('.') 2035522Snate@binkert.org else: 2046143Snate@binkert.org path = [] 2056143Snate@binkert.org 2066143Snate@binkert.org modpath = path[:] 2079982Satgutier@umich.edu if modname != '__init__': 20812302Sgabeblack@google.com modpath += [ modname ] 20912302Sgabeblack@google.com modpath = '.'.join(modpath) 21012302Sgabeblack@google.com 2116143Snate@binkert.org arcpath = path + [ self.basename ] 2126143Snate@binkert.org abspath = self.snode.abspath 2136143Snate@binkert.org if not exists(abspath): 2146143Snate@binkert.org abspath = self.tnode.abspath 2155522Snate@binkert.org 2165522Snate@binkert.org self.package = package 2175522Snate@binkert.org self.modname = modname 2185522Snate@binkert.org self.modpath = modpath 2195604Snate@binkert.org self.arcname = joinpath(*arcpath) 2205604Snate@binkert.org self.abspath = abspath 2216143Snate@binkert.org self.compiled = File(self.filename + 'c') 2226143Snate@binkert.org self.cpp = File(self.filename + '.cc') 2234762Snate@binkert.org self.symname = PySource.invalid_sym_char.sub('_', modpath) 2244762Snate@binkert.org 2256143Snate@binkert.org PySource.modules[modpath] = self 2266727Ssteve.reinhardt@amd.com PySource.tnodes[self.tnode] = self 2276727Ssteve.reinhardt@amd.com PySource.symnames[self.symname] = self 2286727Ssteve.reinhardt@amd.com 2294762Snate@binkert.orgclass SimObject(PySource): 2306143Snate@binkert.org '''Add a SimObject python file as a python source object and add 2316143Snate@binkert.org it to a list of sim object modules''' 2326143Snate@binkert.org 2336143Snate@binkert.org fixed = False 2346727Ssteve.reinhardt@amd.com modnames = [] 2356143Snate@binkert.org 2367674Snate@binkert.org def __init__(self, source, **guards): 2377674Snate@binkert.org '''Specify the source file and any guards (automatically in 2385604Snate@binkert.org the m5.objects package)''' 2396143Snate@binkert.org super(SimObject, self).__init__('m5.objects', source, **guards) 2406143Snate@binkert.org if self.fixed: 2416143Snate@binkert.org raise AttributeError, "Too late to call SimObject now." 2424762Snate@binkert.org 2436143Snate@binkert.org bisect.insort_right(SimObject.modnames, self.modname) 2444762Snate@binkert.org 2454762Snate@binkert.orgclass ProtoBuf(SourceFile): 2464762Snate@binkert.org '''Add a Protocol Buffer to build''' 2476143Snate@binkert.org 2486143Snate@binkert.org def __init__(self, source, **guards): 2494762Snate@binkert.org '''Specify the source file, and any guards''' 25012302Sgabeblack@google.com super(ProtoBuf, self).__init__(source, **guards) 25112302Sgabeblack@google.com 2528233Snate@binkert.org # Get the file name and the extension 25312302Sgabeblack@google.com modname,ext = self.extname 2546143Snate@binkert.org assert ext == 'proto' 2556143Snate@binkert.org 2564762Snate@binkert.org # Currently, we stick to generating the C++ headers, so we 2576143Snate@binkert.org # only need to track the source and header. 2584762Snate@binkert.org self.cc_file = File(modname + '.pb.cc') 2599396Sandreas.hansson@arm.com self.hh_file = File(modname + '.pb.h') 2609396Sandreas.hansson@arm.com 2619396Sandreas.hansson@arm.comclass UnitTest(object): 26212302Sgabeblack@google.com '''Create a UnitTest''' 26312302Sgabeblack@google.com 26412302Sgabeblack@google.com all = [] 2659396Sandreas.hansson@arm.com def __init__(self, target, *sources, **kwargs): 2669396Sandreas.hansson@arm.com '''Specify the target name and any sources. Sources that are 2679396Sandreas.hansson@arm.com not SourceFiles are evalued with Source(). All files are 2689396Sandreas.hansson@arm.com guarded with a guard of the same name as the UnitTest 2699396Sandreas.hansson@arm.com target.''' 2709396Sandreas.hansson@arm.com 2719396Sandreas.hansson@arm.com srcs = [] 2729930Sandreas.hansson@arm.com for src in sources: 2739930Sandreas.hansson@arm.com if not isinstance(src, SourceFile): 2749396Sandreas.hansson@arm.com src = Source(src, skip_lib=True) 2758235Snate@binkert.org src.guards[target] = True 2768235Snate@binkert.org srcs.append(src) 2776143Snate@binkert.org 2788235Snate@binkert.org self.sources = srcs 2799003SAli.Saidi@ARM.com self.target = target 2808235Snate@binkert.org self.main = kwargs.get('main', False) 2818235Snate@binkert.org UnitTest.all.append(self) 28212302Sgabeblack@google.com 2838235Snate@binkert.org# Children should have access 28412302Sgabeblack@google.comExport('Source') 2858235Snate@binkert.orgExport('PySource') 2868235Snate@binkert.orgExport('SimObject') 28712302Sgabeblack@google.comExport('ProtoBuf') 2888235Snate@binkert.orgExport('UnitTest') 2898235Snate@binkert.org 2908235Snate@binkert.org######################################################################## 2918235Snate@binkert.org# 2929003SAli.Saidi@ARM.com# Debug Flags 29312313Sgabeblack@google.com# 29412313Sgabeblack@google.comdebug_flags = {} 29512313Sgabeblack@google.comdef DebugFlag(name, desc=None): 29612313Sgabeblack@google.com if name in debug_flags: 29712313Sgabeblack@google.com raise AttributeError, "Flag %s already specified" % name 29812313Sgabeblack@google.com debug_flags[name] = (name, (), desc) 29912315Sgabeblack@google.com 30012315Sgabeblack@google.comdef CompoundFlag(name, flags, desc=None): 30112315Sgabeblack@google.com if name in debug_flags: 3025584Snate@binkert.org raise AttributeError, "Flag %s already specified" % name 3034382Sbinkertn@umich.edu 3044202Sbinkertn@umich.edu compound = tuple(flags) 3054382Sbinkertn@umich.edu debug_flags[name] = (name, compound, desc) 3064382Sbinkertn@umich.edu 3079396Sandreas.hansson@arm.comExport('DebugFlag') 3085584Snate@binkert.orgExport('CompoundFlag') 30912313Sgabeblack@google.com 3104382Sbinkertn@umich.edu######################################################################## 3114382Sbinkertn@umich.edu# 3124382Sbinkertn@umich.edu# Set some compiler variables 3138232Snate@binkert.org# 3145192Ssaidi@eecs.umich.edu 3158232Snate@binkert.org# Include file paths are rooted in this directory. SCons will 3168232Snate@binkert.org# automatically expand '.' to refer to both the source directory and 3178232Snate@binkert.org# the corresponding build directory to pick up generated include 3185192Ssaidi@eecs.umich.edu# files. 3198232Snate@binkert.orgenv.Append(CPPPATH=Dir('.')) 3205192Ssaidi@eecs.umich.edu 3215799Snate@binkert.orgfor extra_dir in extras_dir_list: 3228232Snate@binkert.org env.Append(CPPPATH=Dir(extra_dir)) 3235192Ssaidi@eecs.umich.edu 3245192Ssaidi@eecs.umich.edu# Workaround for bug in SCons version > 0.97d20071212 3255192Ssaidi@eecs.umich.edu# Scons bug id: 2006 gem5 Bug id: 308 3268232Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True): 3275192Ssaidi@eecs.umich.edu Dir(root[len(base_dir) + 1:]) 3288232Snate@binkert.org 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# 3334382Sbinkertn@umich.edu 3344382Sbinkertn@umich.eduhere = Dir('.').srcnode().abspath 3354382Sbinkertn@umich.edufor root, dirs, files in os.walk(base_dir, topdown=True): 3362667Sstever@eecs.umich.edu if root == here: 3372667Sstever@eecs.umich.edu # we don't want to recurse back into this SConscript 3382667Sstever@eecs.umich.edu continue 3392667Sstever@eecs.umich.edu 3402667Sstever@eecs.umich.edu if 'SConscript' in files: 3412667Sstever@eecs.umich.edu build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:]) 3425742Snate@binkert.org Source.set_group(build_dir) 3435742Snate@binkert.org SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3445742Snate@binkert.org 3455793Snate@binkert.orgfor extra_dir in extras_dir_list: 3468334Snate@binkert.org prefix_len = len(dirname(extra_dir)) + 1 3475793Snate@binkert.org 3485793Snate@binkert.org # Also add the corresponding build directory to pick up generated 3495793Snate@binkert.org # include files. 3504382Sbinkertn@umich.edu env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:]))) 3514762Snate@binkert.org 3525344Sstever@gmail.com for root, dirs, files in os.walk(extra_dir, topdown=True): 3534382Sbinkertn@umich.edu # if build lives in the extras directory, don't walk down it 3545341Sstever@gmail.com if 'build' in dirs: 3555742Snate@binkert.org dirs.remove('build') 3565742Snate@binkert.org 3575742Snate@binkert.org if 'SConscript' in files: 3585742Snate@binkert.org build_dir = joinpath(env['BUILDDIR'], root[prefix_len:]) 3595742Snate@binkert.org SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir) 3604762Snate@binkert.org 3615742Snate@binkert.orgfor opt in export_vars: 3625742Snate@binkert.org env.ConfigFile(opt) 36311984Sgabeblack@google.com 3647722Sgblack@eecs.umich.edudef makeTheISA(source, target, env): 3655742Snate@binkert.org isas = [ src.get_contents() for src in source ] 3665742Snate@binkert.org target_isa = env['TARGET_ISA'] 3675742Snate@binkert.org def define(isa): 3689930Sandreas.hansson@arm.com return isa.upper() + '_ISA' 3699930Sandreas.hansson@arm.com 3709930Sandreas.hansson@arm.com def namespace(isa): 3719930Sandreas.hansson@arm.com return isa[0].upper() + isa[1:].lower() + 'ISA' 3729930Sandreas.hansson@arm.com 3735742Snate@binkert.org 3748242Sbradley.danofsky@amd.com code = code_formatter() 3758242Sbradley.danofsky@amd.com code('''\ 3768242Sbradley.danofsky@amd.com#ifndef __CONFIG_THE_ISA_HH__ 3778242Sbradley.danofsky@amd.com#define __CONFIG_THE_ISA_HH__ 3785341Sstever@gmail.com 3795742Snate@binkert.org''') 3807722Sgblack@eecs.umich.edu 3814773Snate@binkert.org # create defines for the preprocessing and compile-time determination 3826108Snate@binkert.org for i,isa in enumerate(isas): 3831858SN/A code('#define $0 $1', define(isa), i + 1) 3841085SN/A code() 3856658Snate@binkert.org 3866658Snate@binkert.org # create an enum for any run-time determination of the ISA, we 3877673Snate@binkert.org # reuse the same name as the namespaces 3886658Snate@binkert.org code('enum class Arch {') 3896658Snate@binkert.org for i,isa in enumerate(isas): 39011308Santhony.gutierrez@amd.com if i + 1 == len(isas): 3916658Snate@binkert.org code(' $0 = $1', namespace(isa), define(isa)) 39211308Santhony.gutierrez@amd.com else: 3936658Snate@binkert.org code(' $0 = $1,', namespace(isa), define(isa)) 3946658Snate@binkert.org code('};') 3957673Snate@binkert.org 3967673Snate@binkert.org code(''' 3977673Snate@binkert.org 3987673Snate@binkert.org#define THE_ISA ${{define(target_isa)}} 3997673Snate@binkert.org#define TheISA ${{namespace(target_isa)}} 4007673Snate@binkert.org#define THE_ISA_STR "${{target_isa}}" 4017673Snate@binkert.org 40210467Sandreas.hansson@arm.com#endif // __CONFIG_THE_ISA_HH__''') 4036658Snate@binkert.org 4047673Snate@binkert.org code.write(str(target[0])) 40510467Sandreas.hansson@arm.com 40610467Sandreas.hansson@arm.comenv.Command('config/the_isa.hh', map(Value, all_isa_list), 40710467Sandreas.hansson@arm.com MakeAction(makeTheISA, Transform("CFG ISA", 0))) 40810467Sandreas.hansson@arm.com 40910467Sandreas.hansson@arm.comdef makeTheGPUISA(source, target, env): 41010467Sandreas.hansson@arm.com isas = [ src.get_contents() for src in source ] 41110467Sandreas.hansson@arm.com target_gpu_isa = env['TARGET_GPU_ISA'] 41210467Sandreas.hansson@arm.com def define(isa): 41310467Sandreas.hansson@arm.com return isa.upper() + '_ISA' 41410467Sandreas.hansson@arm.com 41510467Sandreas.hansson@arm.com def namespace(isa): 4167673Snate@binkert.org return isa[0].upper() + isa[1:].lower() + 'ISA' 4177673Snate@binkert.org 4187673Snate@binkert.org 4197673Snate@binkert.org code = code_formatter() 4207673Snate@binkert.org code('''\ 4219048SAli.Saidi@ARM.com#ifndef __CONFIG_THE_GPU_ISA_HH__ 4227673Snate@binkert.org#define __CONFIG_THE_GPU_ISA_HH__ 4237673Snate@binkert.org 4247673Snate@binkert.org''') 4257673Snate@binkert.org 4266658Snate@binkert.org # create defines for the preprocessing and compile-time determination 4277756SAli.Saidi@ARM.com for i,isa in enumerate(isas): 4287816Ssteve.reinhardt@amd.com code('#define $0 $1', define(isa), i + 1) 4296658Snate@binkert.org code() 43011308Santhony.gutierrez@amd.com 43111308Santhony.gutierrez@amd.com # create an enum for any run-time determination of the ISA, we 43211308Santhony.gutierrez@amd.com # reuse the same name as the namespaces 43311308Santhony.gutierrez@amd.com code('enum class GPUArch {') 43411308Santhony.gutierrez@amd.com for i,isa in enumerate(isas): 43511308Santhony.gutierrez@amd.com if i + 1 == len(isas): 43611308Santhony.gutierrez@amd.com code(' $0 = $1', namespace(isa), define(isa)) 43711308Santhony.gutierrez@amd.com else: 43811308Santhony.gutierrez@amd.com code(' $0 = $1,', namespace(isa), define(isa)) 43911308Santhony.gutierrez@amd.com code('};') 44011308Santhony.gutierrez@amd.com 44111308Santhony.gutierrez@amd.com code(''' 44211308Santhony.gutierrez@amd.com 44311308Santhony.gutierrez@amd.com#define THE_GPU_ISA ${{define(target_gpu_isa)}} 44411308Santhony.gutierrez@amd.com#define TheGpuISA ${{namespace(target_gpu_isa)}} 44511308Santhony.gutierrez@amd.com#define THE_GPU_ISA_STR "${{target_gpu_isa}}" 44611308Santhony.gutierrez@amd.com 44711308Santhony.gutierrez@amd.com#endif // __CONFIG_THE_GPU_ISA_HH__''') 44811308Santhony.gutierrez@amd.com 44911308Santhony.gutierrez@amd.com code.write(str(target[0])) 45011308Santhony.gutierrez@amd.com 45111308Santhony.gutierrez@amd.comenv.Command('config/the_gpu_isa.hh', map(Value, all_gpu_isa_list), 45211308Santhony.gutierrez@amd.com MakeAction(makeTheGPUISA, Transform("CFG ISA", 0))) 45311308Santhony.gutierrez@amd.com 45411308Santhony.gutierrez@amd.com######################################################################## 45511308Santhony.gutierrez@amd.com# 45611308Santhony.gutierrez@amd.com# Prevent any SimObjects from being added after this point, they 45711308Santhony.gutierrez@amd.com# should all have been added in the SConscripts above 45811308Santhony.gutierrez@amd.com# 45911308Santhony.gutierrez@amd.comSimObject.fixed = True 46011308Santhony.gutierrez@amd.com 46111308Santhony.gutierrez@amd.comclass DictImporter(object): 46211308Santhony.gutierrez@amd.com '''This importer takes a dictionary of arbitrary module names that 46311308Santhony.gutierrez@amd.com map to arbitrary filenames.''' 46411308Santhony.gutierrez@amd.com def __init__(self, modules): 46511308Santhony.gutierrez@amd.com self.modules = modules 46611308Santhony.gutierrez@amd.com self.installed = set() 46711308Santhony.gutierrez@amd.com 46811308Santhony.gutierrez@amd.com def __del__(self): 46911308Santhony.gutierrez@amd.com self.unload() 47011308Santhony.gutierrez@amd.com 47111308Santhony.gutierrez@amd.com def unload(self): 47211308Santhony.gutierrez@amd.com import sys 47311308Santhony.gutierrez@amd.com for module in self.installed: 47411308Santhony.gutierrez@amd.com del sys.modules[module] 4754382Sbinkertn@umich.edu self.installed = set() 4764382Sbinkertn@umich.edu 4774762Snate@binkert.org def find_module(self, fullname, path): 4784762Snate@binkert.org if fullname == 'm5.defines': 4794762Snate@binkert.org return self 4806654Snate@binkert.org 4816654Snate@binkert.org if fullname == 'm5.objects': 4825517Snate@binkert.org return self 4835517Snate@binkert.org 4845517Snate@binkert.org if fullname.startswith('_m5'): 4855517Snate@binkert.org return None 4865517Snate@binkert.org 4875517Snate@binkert.org source = self.modules.get(fullname, None) 4885517Snate@binkert.org if source is not None and fullname.startswith('m5.objects'): 4895517Snate@binkert.org return self 4905517Snate@binkert.org 4915517Snate@binkert.org return None 4925517Snate@binkert.org 4935517Snate@binkert.org def load_module(self, fullname): 4945517Snate@binkert.org mod = imp.new_module(fullname) 4955517Snate@binkert.org sys.modules[fullname] = mod 4965517Snate@binkert.org self.installed.add(fullname) 4975517Snate@binkert.org 4985517Snate@binkert.org mod.__loader__ = self 4996654Snate@binkert.org if fullname == 'm5.objects': 5005517Snate@binkert.org mod.__path__ = fullname.split('.') 5015517Snate@binkert.org return mod 5025517Snate@binkert.org 5035517Snate@binkert.org if fullname == 'm5.defines': 5045517Snate@binkert.org mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env) 50511802Sandreas.sandberg@arm.com return mod 5065517Snate@binkert.org 5075517Snate@binkert.org source = self.modules[fullname] 5086143Snate@binkert.org if source.modname == '__init__': 5096654Snate@binkert.org mod.__path__ = source.modpath 5105517Snate@binkert.org mod.__file__ = source.abspath 5115517Snate@binkert.org 5125517Snate@binkert.org exec file(source.abspath, 'r') in mod.__dict__ 5135517Snate@binkert.org 5145517Snate@binkert.org return mod 5155517Snate@binkert.org 5165517Snate@binkert.orgimport m5.SimObject 5175517Snate@binkert.orgimport m5.params 5185517Snate@binkert.orgfrom m5.util import code_formatter 5195517Snate@binkert.org 5205517Snate@binkert.orgm5.SimObject.clear() 5215517Snate@binkert.orgm5.params.clear() 5225517Snate@binkert.org 5235517Snate@binkert.org# install the python importer so we can grab stuff from the source 5246654Snate@binkert.org# tree itself. We can't have SimObjects added after this point or 5256654Snate@binkert.org# else we won't know about them for the rest of the stuff. 5265517Snate@binkert.orgimporter = DictImporter(PySource.modules) 5275517Snate@binkert.orgsys.meta_path[0:0] = [ importer ] 5286143Snate@binkert.org 5296143Snate@binkert.org# import all sim objects so we can populate the all_objects list 5306143Snate@binkert.org# make sure that we're working with a list, then let's sort it 5316727Ssteve.reinhardt@amd.comfor modname in SimObject.modnames: 5325517Snate@binkert.org exec('from m5.objects import %s' % modname) 5336727Ssteve.reinhardt@amd.com 5345517Snate@binkert.org# we need to unload all of the currently imported modules so that they 5355517Snate@binkert.org# will be re-imported the next time the sconscript is run 5365517Snate@binkert.orgimporter.unload() 5376654Snate@binkert.orgsys.meta_path.remove(importer) 5386654Snate@binkert.org 5397673Snate@binkert.orgsim_objects = m5.SimObject.allClasses 5406654Snate@binkert.orgall_enums = m5.params.allEnums 5416654Snate@binkert.org 5426654Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()): 5436654Snate@binkert.org for param in obj._params.local.values(): 5445517Snate@binkert.org # load the ptype attribute now because it depends on the 5455517Snate@binkert.org # current version of SimObject.allClasses, but when scons 5465517Snate@binkert.org # actually uses the value, all versions of 5476143Snate@binkert.org # SimObject.allClasses will have been loaded 5485517Snate@binkert.org param.ptype 5494762Snate@binkert.org 5505517Snate@binkert.org######################################################################## 5515517Snate@binkert.org# 5526143Snate@binkert.org# calculate extra dependencies 5536143Snate@binkert.org# 5545517Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"] 5555517Snate@binkert.orgdepends = [ PySource.modules[dep].snode for dep in module_depends ] 5565517Snate@binkert.orgdepends.sort(key = lambda x: x.name) 5575517Snate@binkert.org 5585517Snate@binkert.org######################################################################## 5595517Snate@binkert.org# 5605517Snate@binkert.org# Commands for the basic automatically generated python files 5615517Snate@binkert.org# 5625517Snate@binkert.org 5636143Snate@binkert.org# Generate Python file containing a dict specifying the current 5645517Snate@binkert.org# buildEnv flags. 5656654Snate@binkert.orgdef makeDefinesPyFile(target, source, env): 5666654Snate@binkert.org build_env = source[0].get_contents() 5676654Snate@binkert.org 5686654Snate@binkert.org code = code_formatter() 5696654Snate@binkert.org code(""" 5706654Snate@binkert.orgimport _m5.core 5714762Snate@binkert.orgimport m5.util 5724762Snate@binkert.org 5734762Snate@binkert.orgbuildEnv = m5.util.SmartDict($build_env) 5744762Snate@binkert.org 5754762Snate@binkert.orgcompileDate = _m5.core.compileDate 5767675Snate@binkert.org_globals = globals() 57710584Sandreas.hansson@arm.comfor key,val in _m5.core.__dict__.iteritems(): 5784762Snate@binkert.org if key.startswith('flag_'): 5794762Snate@binkert.org flag = key[5:] 5804762Snate@binkert.org _globals[flag] = val 5814762Snate@binkert.orgdel _globals 5824382Sbinkertn@umich.edu""") 5834382Sbinkertn@umich.edu code.write(target[0].abspath) 5845517Snate@binkert.org 5856654Snate@binkert.orgdefines_info = Value(build_env) 5865517Snate@binkert.org# Generate a file with all of the compile options in it 5878126Sgblack@eecs.umich.eduenv.Command('python/m5/defines.py', defines_info, 5886654Snate@binkert.org MakeAction(makeDefinesPyFile, Transform("DEFINES", 0))) 5897673Snate@binkert.orgPySource('m5', 'python/m5/defines.py') 5906654Snate@binkert.org 59111802Sandreas.sandberg@arm.com# Generate python file containing info about the M5 source code 5926654Snate@binkert.orgdef makeInfoPyFile(target, source, env): 5936654Snate@binkert.org code = code_formatter() 5946654Snate@binkert.org for src in source: 5956654Snate@binkert.org data = ''.join(file(src.srcnode().abspath, 'r').xreadlines()) 59611802Sandreas.sandberg@arm.com code('$src = ${{repr(data)}}') 5976669Snate@binkert.org code.write(str(target[0])) 59811802Sandreas.sandberg@arm.com 5996669Snate@binkert.org# Generate a file that wraps the basic top level files 6006669Snate@binkert.orgenv.Command('python/m5/info.py', 6016669Snate@binkert.org [ '#/COPYING', '#/LICENSE', '#/README', ], 6026669Snate@binkert.org MakeAction(makeInfoPyFile, Transform("INFO"))) 6036654Snate@binkert.orgPySource('m5', 'python/m5/info.py') 6047673Snate@binkert.org 6055517Snate@binkert.org######################################################################## 6068126Sgblack@eecs.umich.edu# 6075798Snate@binkert.org# Create all of the SimObject param headers and enum headers 6087756SAli.Saidi@ARM.com# 6097816Ssteve.reinhardt@amd.com 6105798Snate@binkert.orgdef createSimObjectParamStruct(target, source, env): 6115798Snate@binkert.org assert len(target) == 1 and len(source) == 1 6125517Snate@binkert.org 6135517Snate@binkert.org name = str(source[0].get_contents()) 6147673Snate@binkert.org obj = sim_objects[name] 6155517Snate@binkert.org 6165517Snate@binkert.org code = code_formatter() 6177673Snate@binkert.org obj.cxx_param_decl(code) 6187673Snate@binkert.org code.write(target[0].abspath) 6195517Snate@binkert.org 6205798Snate@binkert.orgdef createSimObjectCxxConfig(is_header): 6215798Snate@binkert.org def body(target, source, env): 6228333Snate@binkert.org assert len(target) == 1 and len(source) == 1 6237816Ssteve.reinhardt@amd.com 6245798Snate@binkert.org name = str(source[0].get_contents()) 6255798Snate@binkert.org obj = sim_objects[name] 6264762Snate@binkert.org 6274762Snate@binkert.org code = code_formatter() 6284762Snate@binkert.org obj.cxx_config_param_file(code, is_header) 6294762Snate@binkert.org code.write(target[0].abspath) 6304762Snate@binkert.org return body 6318596Ssteve.reinhardt@amd.com 6325517Snate@binkert.orgdef createEnumStrings(target, source, env): 6335517Snate@binkert.org assert len(target) == 1 and len(source) == 1 63411997Sgabeblack@google.com 6355517Snate@binkert.org name = str(source[0].get_contents()) 6365517Snate@binkert.org obj = all_enums[name] 6377673Snate@binkert.org 6388596Ssteve.reinhardt@amd.com code = code_formatter() 6397673Snate@binkert.org obj.cxx_def(code) 6405517Snate@binkert.org if env['USE_PYTHON']: 64110458Sandreas.hansson@arm.com obj.pybind_def(code) 64210458Sandreas.hansson@arm.com code.write(target[0].abspath) 64310458Sandreas.hansson@arm.com 64410458Sandreas.hansson@arm.comdef createEnumDecls(target, source, env): 64510458Sandreas.hansson@arm.com assert len(target) == 1 and len(source) == 1 64610458Sandreas.hansson@arm.com 64710458Sandreas.hansson@arm.com name = str(source[0].get_contents()) 64810458Sandreas.hansson@arm.com obj = all_enums[name] 64910458Sandreas.hansson@arm.com 65010458Sandreas.hansson@arm.com code = code_formatter() 65110458Sandreas.hansson@arm.com obj.cxx_decl(code) 65210458Sandreas.hansson@arm.com code.write(target[0].abspath) 6535517Snate@binkert.org 65411996Sgabeblack@google.comdef createSimObjectPyBindWrapper(target, source, env): 6555517Snate@binkert.org name = source[0].get_contents() 65611997Sgabeblack@google.com obj = sim_objects[name] 65711996Sgabeblack@google.com 6585517Snate@binkert.org code = code_formatter() 6595517Snate@binkert.org obj.pybind_decl(code) 6607673Snate@binkert.org code.write(target[0].abspath) 6617673Snate@binkert.org 66211996Sgabeblack@google.com# Generate all of the SimObject param C++ struct header files 66311988Sandreas.sandberg@arm.comparams_hh_files = [] 6647673Snate@binkert.orgfor name,simobj in sorted(sim_objects.iteritems()): 6655517Snate@binkert.org py_source = PySource.modules[simobj.__module__] 6668596Ssteve.reinhardt@amd.com extra_deps = [ py_source.tnode ] 6675517Snate@binkert.org 6685517Snate@binkert.org hh_file = File('params/%s.hh' % name) 66911997Sgabeblack@google.com params_hh_files.append(hh_file) 6705517Snate@binkert.org env.Command(hh_file, Value(name), 6715517Snate@binkert.org MakeAction(createSimObjectParamStruct, Transform("SO PARAM"))) 6727673Snate@binkert.org env.Depends(hh_file, depends + extra_deps) 6737673Snate@binkert.org 6747673Snate@binkert.org# C++ parameter description files 6755517Snate@binkert.orgif GetOption('with_cxx_config'): 67611988Sandreas.sandberg@arm.com for name,simobj in sorted(sim_objects.iteritems()): 67711997Sgabeblack@google.com py_source = PySource.modules[simobj.__module__] 6788596Ssteve.reinhardt@amd.com extra_deps = [ py_source.tnode ] 6798596Ssteve.reinhardt@amd.com 6808596Ssteve.reinhardt@amd.com cxx_config_hh_file = File('cxx_config/%s.hh' % name) 68111988Sandreas.sandberg@arm.com cxx_config_cc_file = File('cxx_config/%s.cc' % name) 6828596Ssteve.reinhardt@amd.com env.Command(cxx_config_hh_file, Value(name), 6838596Ssteve.reinhardt@amd.com MakeAction(createSimObjectCxxConfig(True), 6848596Ssteve.reinhardt@amd.com Transform("CXXCPRHH"))) 6854762Snate@binkert.org env.Command(cxx_config_cc_file, Value(name), 6866143Snate@binkert.org MakeAction(createSimObjectCxxConfig(False), 6876143Snate@binkert.org Transform("CXXCPRCC"))) 6886143Snate@binkert.org env.Depends(cxx_config_hh_file, depends + extra_deps + 6894762Snate@binkert.org [File('params/%s.hh' % name), File('sim/cxx_config.hh')]) 6904762Snate@binkert.org env.Depends(cxx_config_cc_file, depends + extra_deps + 6914762Snate@binkert.org [cxx_config_hh_file]) 6927756SAli.Saidi@ARM.com Source(cxx_config_cc_file) 6938596Ssteve.reinhardt@amd.com 6944762Snate@binkert.org cxx_config_init_cc_file = File('cxx_config/init.cc') 6954762Snate@binkert.org 69610458Sandreas.hansson@arm.com def createCxxConfigInitCC(target, source, env): 69710458Sandreas.hansson@arm.com assert len(target) == 1 and len(source) == 1 69810458Sandreas.hansson@arm.com 69910458Sandreas.hansson@arm.com code = code_formatter() 70010458Sandreas.hansson@arm.com 70110458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 70210458Sandreas.hansson@arm.com if not hasattr(simobj, 'abstract') or not simobj.abstract: 70310458Sandreas.hansson@arm.com code('#include "cxx_config/${name}.hh"') 70410458Sandreas.hansson@arm.com code() 70510458Sandreas.hansson@arm.com code('void cxxConfigInit()') 70610458Sandreas.hansson@arm.com code('{') 70710458Sandreas.hansson@arm.com code.indent() 70810458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 70910458Sandreas.hansson@arm.com not_abstract = not hasattr(simobj, 'abstract') or \ 71010458Sandreas.hansson@arm.com not simobj.abstract 71110458Sandreas.hansson@arm.com if not_abstract and 'type' in simobj.__dict__: 71210458Sandreas.hansson@arm.com code('cxx_config_directory["${name}"] = ' 71310458Sandreas.hansson@arm.com '${name}CxxConfigParams::makeDirectoryEntry();') 71410458Sandreas.hansson@arm.com code.dedent() 71510458Sandreas.hansson@arm.com code('}') 71610458Sandreas.hansson@arm.com code.write(target[0].abspath) 71710458Sandreas.hansson@arm.com 71810458Sandreas.hansson@arm.com py_source = PySource.modules[simobj.__module__] 71910458Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 72010458Sandreas.hansson@arm.com env.Command(cxx_config_init_cc_file, Value(name), 72110458Sandreas.hansson@arm.com MakeAction(createCxxConfigInitCC, Transform("CXXCINIT"))) 72210458Sandreas.hansson@arm.com cxx_param_hh_files = ["cxx_config/%s.hh" % simobj 72310458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()) 72410458Sandreas.hansson@arm.com if not hasattr(simobj, 'abstract') or not simobj.abstract] 72510458Sandreas.hansson@arm.com Depends(cxx_config_init_cc_file, cxx_param_hh_files + 72610458Sandreas.hansson@arm.com [File('sim/cxx_config.hh')]) 72710458Sandreas.hansson@arm.com Source(cxx_config_init_cc_file) 72810458Sandreas.hansson@arm.com 72910458Sandreas.hansson@arm.com# Generate all enum header files 73010458Sandreas.hansson@arm.comfor name,enum in sorted(all_enums.iteritems()): 73110458Sandreas.hansson@arm.com py_source = PySource.modules[enum.__module__] 73210458Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 73310458Sandreas.hansson@arm.com 73410458Sandreas.hansson@arm.com cc_file = File('enums/%s.cc' % name) 73510458Sandreas.hansson@arm.com env.Command(cc_file, Value(name), 73610458Sandreas.hansson@arm.com MakeAction(createEnumStrings, Transform("ENUM STR"))) 73710458Sandreas.hansson@arm.com env.Depends(cc_file, depends + extra_deps) 73810458Sandreas.hansson@arm.com Source(cc_file) 73910458Sandreas.hansson@arm.com 74010458Sandreas.hansson@arm.com hh_file = File('enums/%s.hh' % name) 74110458Sandreas.hansson@arm.com env.Command(hh_file, Value(name), 74210458Sandreas.hansson@arm.com MakeAction(createEnumDecls, Transform("ENUMDECL"))) 74310458Sandreas.hansson@arm.com env.Depends(hh_file, depends + extra_deps) 74410458Sandreas.hansson@arm.com 74510584Sandreas.hansson@arm.com# Generate SimObject Python bindings wrapper files 74610458Sandreas.hansson@arm.comif env['USE_PYTHON']: 74710458Sandreas.hansson@arm.com for name,simobj in sorted(sim_objects.iteritems()): 74810458Sandreas.hansson@arm.com py_source = PySource.modules[simobj.__module__] 74910458Sandreas.hansson@arm.com extra_deps = [ py_source.tnode ] 75010458Sandreas.hansson@arm.com cc_file = File('python/_m5/param_%s.cc' % name) 7514762Snate@binkert.org env.Command(cc_file, Value(name), 7526143Snate@binkert.org MakeAction(createSimObjectPyBindWrapper, 7536143Snate@binkert.org Transform("SO PyBind"))) 7546143Snate@binkert.org env.Depends(cc_file, depends + extra_deps) 7554762Snate@binkert.org Source(cc_file) 7564762Snate@binkert.org 75711996Sgabeblack@google.com# Build all protocol buffers if we have got protoc and protobuf available 7587816Ssteve.reinhardt@amd.comif env['HAVE_PROTOBUF']: 7594762Snate@binkert.org for proto in ProtoBuf.all: 7604762Snate@binkert.org # Use both the source and header as the target, and the .proto 7614762Snate@binkert.org # file as the source. When executing the protoc compiler, also 7624762Snate@binkert.org # specify the proto_path to avoid having the generated files 7637756SAli.Saidi@ARM.com # include the path. 7648596Ssteve.reinhardt@amd.com env.Command([proto.cc_file, proto.hh_file], proto.tnode, 7654762Snate@binkert.org MakeAction('$PROTOC --cpp_out ${TARGET.dir} ' 7664762Snate@binkert.org '--proto_path ${SOURCE.dir} $SOURCE', 76711988Sandreas.sandberg@arm.com Transform("PROTOC"))) 76811988Sandreas.sandberg@arm.com 76911988Sandreas.sandberg@arm.com # Add the C++ source file 77011988Sandreas.sandberg@arm.com Source(proto.cc_file, **proto.guards) 77111988Sandreas.sandberg@arm.comelif ProtoBuf.all: 77211988Sandreas.sandberg@arm.com print 'Got protobuf to build, but lacks support!' 77311988Sandreas.sandberg@arm.com Exit(1) 77411988Sandreas.sandberg@arm.com 77511988Sandreas.sandberg@arm.com# 77611988Sandreas.sandberg@arm.com# Handle debug flags 77711988Sandreas.sandberg@arm.com# 7784382Sbinkertn@umich.edudef makeDebugFlagCC(target, source, env): 7799396Sandreas.hansson@arm.com assert(len(target) == 1 and len(source) == 1) 7809396Sandreas.hansson@arm.com 7819396Sandreas.hansson@arm.com code = code_formatter() 7829396Sandreas.hansson@arm.com 7839396Sandreas.hansson@arm.com # delay definition of CompoundFlags until after all the definition 7849396Sandreas.hansson@arm.com # of all constituent SimpleFlags 7859396Sandreas.hansson@arm.com comp_code = code_formatter() 7869396Sandreas.hansson@arm.com 7879396Sandreas.hansson@arm.com # file header 7889396Sandreas.hansson@arm.com code(''' 7899396Sandreas.hansson@arm.com/* 7909396Sandreas.hansson@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons. 7919396Sandreas.hansson@arm.com */ 79212302Sgabeblack@google.com 7939396Sandreas.hansson@arm.com#include "base/debug.hh" 7949396Sandreas.hansson@arm.com 7959396Sandreas.hansson@arm.comnamespace Debug { 7969396Sandreas.hansson@arm.com 7978232Snate@binkert.org''') 7988232Snate@binkert.org 7998232Snate@binkert.org for name, flag in sorted(source[0].read().iteritems()): 8008232Snate@binkert.org n, compound, desc = flag 8018232Snate@binkert.org assert n == name 8026229Snate@binkert.org 80310455SCurtis.Dunham@arm.com if not compound: 8046229Snate@binkert.org code('SimpleFlag $name("$name", "$desc");') 80510455SCurtis.Dunham@arm.com else: 80610455SCurtis.Dunham@arm.com comp_code('CompoundFlag $name("$name", "$desc",') 80710455SCurtis.Dunham@arm.com comp_code.indent() 8085517Snate@binkert.org last = len(compound) - 1 8095517Snate@binkert.org for i,flag in enumerate(compound): 8107673Snate@binkert.org if i != last: 8115517Snate@binkert.org comp_code('&$flag,') 81210455SCurtis.Dunham@arm.com else: 8135517Snate@binkert.org comp_code('&$flag);') 8145517Snate@binkert.org comp_code.dedent() 8158232Snate@binkert.org 81610455SCurtis.Dunham@arm.com code.append(comp_code) 81710455SCurtis.Dunham@arm.com code() 81810455SCurtis.Dunham@arm.com code('} // namespace Debug') 8197673Snate@binkert.org 8207673Snate@binkert.org code.write(str(target[0])) 82110455SCurtis.Dunham@arm.com 82210455SCurtis.Dunham@arm.comdef makeDebugFlagHH(target, source, env): 82310455SCurtis.Dunham@arm.com assert(len(target) == 1 and len(source) == 1) 8245517Snate@binkert.org 82510455SCurtis.Dunham@arm.com val = eval(source[0].get_contents()) 82610455SCurtis.Dunham@arm.com name, compound, desc = val 82710455SCurtis.Dunham@arm.com 82810455SCurtis.Dunham@arm.com code = code_formatter() 82910455SCurtis.Dunham@arm.com 83010455SCurtis.Dunham@arm.com # file header boilerplate 83110455SCurtis.Dunham@arm.com code('''\ 83210455SCurtis.Dunham@arm.com/* 83310685Sandreas.hansson@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons. 83410455SCurtis.Dunham@arm.com */ 83510685Sandreas.hansson@arm.com 83610455SCurtis.Dunham@arm.com#ifndef __DEBUG_${name}_HH__ 8375517Snate@binkert.org#define __DEBUG_${name}_HH__ 83810455SCurtis.Dunham@arm.com 8398232Snate@binkert.orgnamespace Debug { 8408232Snate@binkert.org''') 8415517Snate@binkert.org 8427673Snate@binkert.org if compound: 8435517Snate@binkert.org code('class CompoundFlag;') 8448232Snate@binkert.org code('class SimpleFlag;') 8458232Snate@binkert.org 8465517Snate@binkert.org if compound: 8478232Snate@binkert.org code('extern CompoundFlag $name;') 8488232Snate@binkert.org for flag in compound: 8498232Snate@binkert.org code('extern SimpleFlag $flag;') 8507673Snate@binkert.org else: 8515517Snate@binkert.org code('extern SimpleFlag $name;') 8525517Snate@binkert.org 8537673Snate@binkert.org code(''' 8545517Snate@binkert.org} 85510455SCurtis.Dunham@arm.com 8565517Snate@binkert.org#endif // __DEBUG_${name}_HH__ 8575517Snate@binkert.org''') 8588232Snate@binkert.org 8598232Snate@binkert.org code.write(str(target[0])) 8605517Snate@binkert.org 8618232Snate@binkert.orgfor name,flag in sorted(debug_flags.iteritems()): 8628232Snate@binkert.org n, compound, desc = flag 8635517Snate@binkert.org assert n == name 8648232Snate@binkert.org 8658232Snate@binkert.org hh_file = 'debug/%s.hh' % name 8668232Snate@binkert.org env.Command(hh_file, Value(flag), 8675517Snate@binkert.org MakeAction(makeDebugFlagHH, Transform("TRACING", 0))) 8688232Snate@binkert.org 8698232Snate@binkert.orgenv.Command('debug/flags.cc', Value(debug_flags), 8708232Snate@binkert.org MakeAction(makeDebugFlagCC, Transform("TRACING", 0))) 8718232Snate@binkert.orgSource('debug/flags.cc') 8728232Snate@binkert.org 8738232Snate@binkert.org# version tags 8745517Snate@binkert.orgtags = \ 8758232Snate@binkert.orgenv.Command('sim/tags.cc', None, 8768232Snate@binkert.org MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET', 8775517Snate@binkert.org Transform("VER TAGS"))) 8788232Snate@binkert.orgenv.AlwaysBuild(tags) 8797673Snate@binkert.org 8805517Snate@binkert.org# Embed python files. All .py files that have been indicated by a 8817673Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5 8825517Snate@binkert.org# library. To do that, we compile the file to byte code, marshal the 8838232Snate@binkert.org# byte code, compress it, and then generate a c++ file that 8848232Snate@binkert.org# inserts the result into an array. 8858232Snate@binkert.orgdef embedPyFile(target, source, env): 8865192Ssaidi@eecs.umich.edu def c_str(string): 88710454SCurtis.Dunham@arm.com if string is None: 88810454SCurtis.Dunham@arm.com return "0" 8898232Snate@binkert.org return '"%s"' % string 89010455SCurtis.Dunham@arm.com 89110455SCurtis.Dunham@arm.com '''Action function to compile a .py into a code object, marshal 89210455SCurtis.Dunham@arm.com it, compress it, and stick it into an asm file so the code appears 89310455SCurtis.Dunham@arm.com as just bytes with a label in the data section''' 8945192Ssaidi@eecs.umich.edu 89511077SCurtis.Dunham@arm.com src = file(str(source[0]), 'r').read() 89611330SCurtis.Dunham@arm.com 89711077SCurtis.Dunham@arm.com pysource = PySource.tnodes[source[0]] 89811077SCurtis.Dunham@arm.com compiled = compile(src, pysource.abspath, 'exec') 89911077SCurtis.Dunham@arm.com marshalled = marshal.dumps(compiled) 90011330SCurtis.Dunham@arm.com compressed = zlib.compress(marshalled) 90111077SCurtis.Dunham@arm.com data = compressed 9027674Snate@binkert.org sym = pysource.symname 9035522Snate@binkert.org 9045522Snate@binkert.org code = code_formatter() 9057674Snate@binkert.org code('''\ 9067674Snate@binkert.org#include "sim/init.hh" 9077674Snate@binkert.org 9087674Snate@binkert.orgnamespace { 9097674Snate@binkert.org 9107674Snate@binkert.orgconst uint8_t data_${sym}[] = { 9117674Snate@binkert.org''') 9127674Snate@binkert.org code.indent() 9135522Snate@binkert.org step = 16 9145522Snate@binkert.org for i in xrange(0, len(data), step): 9155522Snate@binkert.org x = array.array('B', data[i:i+step]) 9165517Snate@binkert.org code(''.join('%d,' % d for d in x)) 9175522Snate@binkert.org code.dedent() 9185517Snate@binkert.org 9196143Snate@binkert.org code('''}; 9206727Ssteve.reinhardt@amd.com 9215522Snate@binkert.orgEmbeddedPython embedded_${sym}( 9225522Snate@binkert.org ${{c_str(pysource.arcname)}}, 9235522Snate@binkert.org ${{c_str(pysource.abspath)}}, 9247674Snate@binkert.org ${{c_str(pysource.modpath)}}, 9255517Snate@binkert.org data_${sym}, 9267673Snate@binkert.org ${{len(data)}}, 9277673Snate@binkert.org ${{len(marshalled)}}); 9287674Snate@binkert.org 9297673Snate@binkert.org} // anonymous namespace 9307674Snate@binkert.org''') 9317674Snate@binkert.org code.write(str(target[0])) 9328946Sandreas.hansson@arm.com 9337674Snate@binkert.orgfor source in PySource.all: 9347674Snate@binkert.org env.Command(source.cpp, source.tnode, 9357674Snate@binkert.org MakeAction(embedPyFile, Transform("EMBED PY"))) 9365522Snate@binkert.org Source(source.cpp, skip_no_python=True) 9375522Snate@binkert.org 9387674Snate@binkert.org######################################################################## 9397674Snate@binkert.org# 94011308Santhony.gutierrez@amd.com# Define binaries. Each different build type (debug, opt, etc.) gets 9417674Snate@binkert.org# a slightly different build environment. 9427673Snate@binkert.org# 9437674Snate@binkert.org 9447674Snate@binkert.org# List of constructed environments to pass back to SConstruct 9457674Snate@binkert.orgdate_source = Source('base/date.cc', skip_lib=True) 9467674Snate@binkert.org 9477674Snate@binkert.org# Capture this directory for the closure makeEnv, otherwise when it is 9487674Snate@binkert.org# called, it won't know what directory it should use. 9497674Snate@binkert.orgvariant_dir = Dir('.').path 9507674Snate@binkert.orgdef variant(*path): 9517811Ssteve.reinhardt@amd.com return os.path.join(variant_dir, *path) 9527674Snate@binkert.orgdef variantd(*path): 9537673Snate@binkert.org return variant(*path)+'/' 9545522Snate@binkert.org 9556143Snate@binkert.org# Function to create a new build environment as clone of current 95610453SAndrew.Bardsley@arm.com# environment 'env' with modified object suffix and optional stripped 9577816Ssteve.reinhardt@amd.com# binary. Additional keyword arguments are appended to corresponding 95812302Sgabeblack@google.com# build environment vars. 9594382Sbinkertn@umich.edudef makeEnv(env, label, objsfx, strip = False, **kwargs): 9604382Sbinkertn@umich.edu # SCons doesn't know to append a library suffix when there is a '.' in the 9614382Sbinkertn@umich.edu # name. Use '_' instead. 9624382Sbinkertn@umich.edu libname = variant('gem5_' + label) 9634382Sbinkertn@umich.edu exename = variant('gem5.' + label) 9644382Sbinkertn@umich.edu secondary_exename = variant('m5.' + label) 9654382Sbinkertn@umich.edu 9664382Sbinkertn@umich.edu new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's') 96712302Sgabeblack@google.com new_env.Label = label 9684382Sbinkertn@umich.edu new_env.Append(**kwargs) 9692655Sstever@eecs.umich.edu 9702655Sstever@eecs.umich.edu if env['GCC']: 9712655Sstever@eecs.umich.edu # The address sanitizer is available for gcc >= 4.8 9722655Sstever@eecs.umich.edu if GetOption('with_asan'): 97312063Sgabeblack@google.com if GetOption('with_ubsan') and \ 9745601Snate@binkert.org compareVersions(env['GCC_VERSION'], '4.9') >= 0: 9755601Snate@binkert.org new_env.Append(CCFLAGS=['-fsanitize=address,undefined', 97612222Sgabeblack@google.com '-fno-omit-frame-pointer']) 97712222Sgabeblack@google.com new_env.Append(LINKFLAGS='-fsanitize=address,undefined') 97812222Sgabeblack@google.com else: 9795522Snate@binkert.org new_env.Append(CCFLAGS=['-fsanitize=address', 9805863Snate@binkert.org '-fno-omit-frame-pointer']) 9815601Snate@binkert.org new_env.Append(LINKFLAGS='-fsanitize=address') 9825601Snate@binkert.org # Only gcc >= 4.9 supports UBSan, so check both the version 9835601Snate@binkert.org # and the command-line option before adding the compiler and 98412302Sgabeblack@google.com # linker flags. 98510453SAndrew.Bardsley@arm.com elif GetOption('with_ubsan') and \ 98611988Sandreas.sandberg@arm.com compareVersions(env['GCC_VERSION'], '4.9') >= 0: 98711988Sandreas.sandberg@arm.com new_env.Append(CCFLAGS='-fsanitize=undefined') 98810453SAndrew.Bardsley@arm.com new_env.Append(LINKFLAGS='-fsanitize=undefined') 98912302Sgabeblack@google.com 99010453SAndrew.Bardsley@arm.com 99111983Sgabeblack@google.com if env['CLANG']: 99211983Sgabeblack@google.com # We require clang >= 3.1, so there is no need to check any 99312302Sgabeblack@google.com # versions here. 99412302Sgabeblack@google.com if GetOption('with_ubsan'): 99512362Sgabeblack@google.com if GetOption('with_asan'): 99612362Sgabeblack@google.com new_env.Append(CCFLAGS=['-fsanitize=address,undefined', 99711983Sgabeblack@google.com '-fno-omit-frame-pointer']) 99812302Sgabeblack@google.com new_env.Append(LINKFLAGS='-fsanitize=address,undefined') 99912302Sgabeblack@google.com else: 100011983Sgabeblack@google.com new_env.Append(CCFLAGS='-fsanitize=undefined') 100111983Sgabeblack@google.com new_env.Append(LINKFLAGS='-fsanitize=undefined') 100211983Sgabeblack@google.com 100312362Sgabeblack@google.com elif GetOption('with_asan'): 100412362Sgabeblack@google.com new_env.Append(CCFLAGS=['-fsanitize=address', 100512310Sgabeblack@google.com '-fno-omit-frame-pointer']) 100612063Sgabeblack@google.com new_env.Append(LINKFLAGS='-fsanitize=address') 100712063Sgabeblack@google.com 100812063Sgabeblack@google.com werror_env = new_env.Clone() 100912310Sgabeblack@google.com # Treat warnings as errors but white list some warnings that we 101012310Sgabeblack@google.com # want to allow (e.g., deprecation warnings). 101112063Sgabeblack@google.com werror_env.Append(CCFLAGS=['-Werror', 101212063Sgabeblack@google.com '-Wno-error=deprecated-declarations', 101311983Sgabeblack@google.com '-Wno-error=deprecated', 101411983Sgabeblack@google.com ]) 101511983Sgabeblack@google.com 101612310Sgabeblack@google.com def make_obj(source, static, extra_deps = None): 101712310Sgabeblack@google.com '''This function adds the specified source to the correct 101811983Sgabeblack@google.com build environment, and returns the corresponding SCons Object 101911983Sgabeblack@google.com nodes''' 102011983Sgabeblack@google.com 102111983Sgabeblack@google.com if source.Werror: 102212310Sgabeblack@google.com env = werror_env 102312310Sgabeblack@google.com else: 10246143Snate@binkert.org env = new_env 102512362Sgabeblack@google.com 102612306Sgabeblack@google.com if static: 102712310Sgabeblack@google.com obj = env.StaticObject(source.tnode) 102810453SAndrew.Bardsley@arm.com else: 102912362Sgabeblack@google.com obj = env.SharedObject(source.tnode) 103012306Sgabeblack@google.com 103112310Sgabeblack@google.com if extra_deps: 10325554Snate@binkert.org env.Depends(obj, extra_deps) 10335522Snate@binkert.org 10345522Snate@binkert.org return obj 10355797Snate@binkert.org 10365797Snate@binkert.org lib_guards = {'main': False, 'skip_lib': False} 10375522Snate@binkert.org 10385601Snate@binkert.org # Without Python, leave out all Python content from the library 103912362Sgabeblack@google.com # builds. The option doesn't affect gem5 built as a program 10408233Snate@binkert.org if GetOption('without_python'): 10418235Snate@binkert.org lib_guards['skip_no_python'] = False 104212302Sgabeblack@google.com 104312362Sgabeblack@google.com static_objs = [] 10449003SAli.Saidi@ARM.com shared_objs = [] 10459003SAli.Saidi@ARM.com for s in guarded_source_iterator(Source.source_groups[None], **lib_guards): 104612222Sgabeblack@google.com static_objs.append(make_obj(s, True)) 104710196SCurtis.Dunham@arm.com shared_objs.append(make_obj(s, False)) 10488235Snate@binkert.org 104912313Sgabeblack@google.com partial_objs = [] 105012313Sgabeblack@google.com for group, all_srcs in Source.source_groups.iteritems(): 105112313Sgabeblack@google.com # If these are the ungrouped source files, skip them. 105212370Sgabeblack@google.com if not group: 105312313Sgabeblack@google.com continue 105412313Sgabeblack@google.com 105512362Sgabeblack@google.com # Get a list of the source files compatible with the current guards. 105612370Sgabeblack@google.com srcs = [ s for s in guarded_source_iterator(all_srcs, **lib_guards) ] 105712370Sgabeblack@google.com # If there aren't any left, skip this group. 105812370Sgabeblack@google.com if not srcs: 105912370Sgabeblack@google.com continue 106012370Sgabeblack@google.com 106112313Sgabeblack@google.com # Set up the static partially linked objects. 10626143Snate@binkert.org source_objs = [ make_obj(s, True) for s in srcs ] 10632655Sstever@eecs.umich.edu file_name = new_env.subst("${OBJPREFIX}lib${OBJSUFFIX}.partial") 10646143Snate@binkert.org target = File(joinpath(group, file_name)) 10656143Snate@binkert.org partial = env.PartialStatic(target=target, source=source_objs) 106611985Sgabeblack@google.com static_objs.append(partial) 10676143Snate@binkert.org 10686143Snate@binkert.org # Set up the shared partially linked objects. 10694007Ssaidi@eecs.umich.edu source_objs = [ make_obj(s, False) for s in srcs ] 10704596Sbinkertn@umich.edu file_name = new_env.subst("${SHOBJPREFIX}lib${SHOBJSUFFIX}.partial") 10714007Ssaidi@eecs.umich.edu target = File(joinpath(group, file_name)) 10724596Sbinkertn@umich.edu partial = env.PartialShared(target=target, source=source_objs) 10737756SAli.Saidi@ARM.com shared_objs.append(partial) 10747816Ssteve.reinhardt@amd.com 10758334Snate@binkert.org static_date = make_obj(date_source, static=True, extra_deps=static_objs) 10768334Snate@binkert.org static_objs.append(static_date) 10778334Snate@binkert.org 10788334Snate@binkert.org shared_date = make_obj(date_source, static=False, extra_deps=shared_objs) 10795601Snate@binkert.org shared_objs.append(shared_date) 108011993Sgabeblack@google.com 108111993Sgabeblack@google.com # First make a library of everything but main() so other programs can 108211993Sgabeblack@google.com # link against m5. 108312223Sgabeblack@google.com static_lib = new_env.StaticLibrary(libname, static_objs) 108411993Sgabeblack@google.com shared_lib = new_env.SharedLibrary(libname, shared_objs) 10852655Sstever@eecs.umich.edu 10869225Sandreas.hansson@arm.com # Now link a stub with main() and the static library. 10879225Sandreas.hansson@arm.com main_objs = [ make_obj(s, True) for s in Source.get(main=True) ] 10889226Sandreas.hansson@arm.com 10899226Sandreas.hansson@arm.com for test in UnitTest.all: 10909225Sandreas.hansson@arm.com flags = { test.target : True } 10919226Sandreas.hansson@arm.com test_sources = Source.get(**flags) 10929226Sandreas.hansson@arm.com test_objs = [ make_obj(s, static=True) for s in test_sources ] 10939226Sandreas.hansson@arm.com if test.main: 10949226Sandreas.hansson@arm.com test_objs += main_objs 10959226Sandreas.hansson@arm.com path = variant('unittest/%s.%s' % (test.target, label)) 10969226Sandreas.hansson@arm.com new_env.Program(path, test_objs + static_objs) 10979225Sandreas.hansson@arm.com 10989227Sandreas.hansson@arm.com progname = exename 10999227Sandreas.hansson@arm.com if strip: 11009227Sandreas.hansson@arm.com progname += '.unstripped' 11019227Sandreas.hansson@arm.com 11028946Sandreas.hansson@arm.com targets = new_env.Program(progname, main_objs + static_objs) 11033918Ssaidi@eecs.umich.edu 11049225Sandreas.hansson@arm.com if strip: 11053918Ssaidi@eecs.umich.edu if sys.platform == 'sunos5': 11069225Sandreas.hansson@arm.com cmd = 'cp $SOURCE $TARGET; strip $TARGET' 11079225Sandreas.hansson@arm.com else: 11089227Sandreas.hansson@arm.com cmd = 'strip $SOURCE -o $TARGET' 11099227Sandreas.hansson@arm.com targets = new_env.Command(exename, progname, 11109227Sandreas.hansson@arm.com MakeAction(cmd, Transform("STRIP"))) 11119226Sandreas.hansson@arm.com 11129225Sandreas.hansson@arm.com new_env.Command(secondary_exename, exename, 11139227Sandreas.hansson@arm.com MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK"))) 11149227Sandreas.hansson@arm.com 11159227Sandreas.hansson@arm.com new_env.M5Binary = targets[0] 11169227Sandreas.hansson@arm.com return new_env 11178946Sandreas.hansson@arm.com 11189225Sandreas.hansson@arm.com# Start out with the compiler flags common to all compilers, 11199226Sandreas.hansson@arm.com# i.e. they all use -g for opt and -g -pg for prof 11209226Sandreas.hansson@arm.comccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'], 11219226Sandreas.hansson@arm.com 'perf' : ['-g']} 11223515Ssaidi@eecs.umich.edu 11233918Ssaidi@eecs.umich.edu# Start out with the linker flags common to all linkers, i.e. -pg for 11244762Snate@binkert.org# prof, and -lprofiler for perf. The -lprofile flag is surrounded by 11253515Ssaidi@eecs.umich.edu# no-as-needed and as-needed as the binutils linker is too clever and 11268881Smarc.orr@gmail.com# simply doesn't link to the library otherwise. 11278881Smarc.orr@gmail.comldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'], 11288881Smarc.orr@gmail.com 'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']} 11298881Smarc.orr@gmail.com 11308881Smarc.orr@gmail.com# For Link Time Optimization, the optimisation flags used to compile 11319226Sandreas.hansson@arm.com# individual files are decoupled from those used at link time 11329226Sandreas.hansson@arm.com# (i.e. you can compile with -O3 and perform LTO with -O0), so we need 11339226Sandreas.hansson@arm.com# to also update the linker flags based on the target. 11348881Smarc.orr@gmail.comif env['GCC']: 11358881Smarc.orr@gmail.com if sys.platform == 'sunos5': 11368881Smarc.orr@gmail.com ccflags['debug'] += ['-gstabs+'] 11378881Smarc.orr@gmail.com else: 11388881Smarc.orr@gmail.com ccflags['debug'] += ['-ggdb3'] 11398881Smarc.orr@gmail.com ldflags['debug'] += ['-O0'] 11408881Smarc.orr@gmail.com # opt, fast, prof and perf all share the same cc flags, also add 11418881Smarc.orr@gmail.com # the optimization to the ldflags as LTO defers the optimization 11428881Smarc.orr@gmail.com # to link time 11438881Smarc.orr@gmail.com for target in ['opt', 'fast', 'prof', 'perf']: 11448881Smarc.orr@gmail.com ccflags[target] += ['-O3'] 11458881Smarc.orr@gmail.com ldflags[target] += ['-O3'] 11468881Smarc.orr@gmail.com 11478881Smarc.orr@gmail.com ccflags['fast'] += env['LTO_CCFLAGS'] 11488881Smarc.orr@gmail.com ldflags['fast'] += env['LTO_LDFLAGS'] 11498881Smarc.orr@gmail.comelif env['CLANG']: 115012222Sgabeblack@google.com ccflags['debug'] += ['-g', '-O0'] 115112222Sgabeblack@google.com # opt, fast, prof and perf all share the same cc flags 115212222Sgabeblack@google.com for target in ['opt', 'fast', 'prof', 'perf']: 115312222Sgabeblack@google.com ccflags[target] += ['-O3'] 115412222Sgabeblack@google.comelse: 115512222Sgabeblack@google.com print 'Unknown compiler, please fix compiler options' 1156955SN/A Exit(1) 115712222Sgabeblack@google.com 115812222Sgabeblack@google.com 115912222Sgabeblack@google.com# To speed things up, we only instantiate the build environments we 116012222Sgabeblack@google.com# need. We try to identify the needed environment for each target; if 116112222Sgabeblack@google.com# we can't, we fall back on instantiating all the environments just to 116212222Sgabeblack@google.com# be safe. 1163955SN/Atarget_types = ['debug', 'opt', 'fast', 'prof', 'perf'] 116412222Sgabeblack@google.comobj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof', 116512222Sgabeblack@google.com 'gpo' : 'perf'} 116612222Sgabeblack@google.com 116712222Sgabeblack@google.comdef identifyTarget(t): 116812222Sgabeblack@google.com ext = t.split('.')[-1] 116912222Sgabeblack@google.com if ext in target_types: 117012222Sgabeblack@google.com return ext 117112222Sgabeblack@google.com if obj2target.has_key(ext): 117212222Sgabeblack@google.com return obj2target[ext] 117312222Sgabeblack@google.com match = re.search(r'/tests/([^/]+)/', t) 11741869SN/A if match and match.group(1) in target_types: 117512222Sgabeblack@google.com return match.group(1) 117612222Sgabeblack@google.com return 'all' 117712222Sgabeblack@google.com 117812222Sgabeblack@google.comneeded_envs = [identifyTarget(target) for target in BUILD_TARGETS] 117912222Sgabeblack@google.comif 'all' in needed_envs: 118012222Sgabeblack@google.com needed_envs += target_types 11819226Sandreas.hansson@arm.com 118212222Sgabeblack@google.comdef makeEnvirons(target, source, env): 118312222Sgabeblack@google.com # cause any later Source() calls to be fatal, as a diagnostic. 118412222Sgabeblack@google.com Source.done() 118512222Sgabeblack@google.com 118612222Sgabeblack@google.com envList = [] 118712222Sgabeblack@google.com 1188 # Debug binary 1189 if 'debug' in needed_envs: 1190 envList.append( 1191 makeEnv(env, 'debug', '.do', 1192 CCFLAGS = Split(ccflags['debug']), 1193 CPPDEFINES = ['DEBUG', 'TRACING_ON=1'], 1194 LINKFLAGS = Split(ldflags['debug']))) 1195 1196 # Optimized binary 1197 if 'opt' in needed_envs: 1198 envList.append( 1199 makeEnv(env, 'opt', '.o', 1200 CCFLAGS = Split(ccflags['opt']), 1201 CPPDEFINES = ['TRACING_ON=1'], 1202 LINKFLAGS = Split(ldflags['opt']))) 1203 1204 # "Fast" binary 1205 if 'fast' in needed_envs: 1206 envList.append( 1207 makeEnv(env, 'fast', '.fo', strip = True, 1208 CCFLAGS = Split(ccflags['fast']), 1209 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 1210 LINKFLAGS = Split(ldflags['fast']))) 1211 1212 # Profiled binary using gprof 1213 if 'prof' in needed_envs: 1214 envList.append( 1215 makeEnv(env, 'prof', '.po', 1216 CCFLAGS = Split(ccflags['prof']), 1217 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 1218 LINKFLAGS = Split(ldflags['prof']))) 1219 1220 # Profiled binary using google-pprof 1221 if 'perf' in needed_envs: 1222 envList.append( 1223 makeEnv(env, 'perf', '.gpo', 1224 CCFLAGS = Split(ccflags['perf']), 1225 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'], 1226 LINKFLAGS = Split(ldflags['perf']))) 1227 1228 # Set up the regression tests for each build. 1229 for e in envList: 1230 SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'), 1231 variant_dir = variantd('tests', e.Label), 1232 exports = { 'env' : e }, duplicate = False) 1233 1234# The MakeEnvirons Builder defers the full dependency collection until 1235# after processing the ISA definition (due to dynamically generated 1236# source files). Add this dependency to all targets so they will wait 1237# until the environments are completely set up. Otherwise, a second 1238# process (e.g. -j2 or higher) will try to compile the requested target, 1239# not know how, and fail. 1240env.Append(BUILDERS = {'MakeEnvirons' : 1241 Builder(action=MakeAction(makeEnvirons, 1242 Transform("ENVIRONS", 1)))}) 1243 1244isa_target = env['PHONY_BASE'] + '-deps' 1245environs = env['PHONY_BASE'] + '-environs' 1246env.Depends('#all-deps', isa_target) 1247env.Depends('#all-environs', environs) 1248env.ScanISA(isa_target, File('arch/%s/generated/inc.d' % env['TARGET_ISA'])) 1249envSetup = env.MakeEnvirons(environs, isa_target) 1250 1251# make sure no -deps targets occur before all ISAs are complete 1252env.Depends(isa_target, '#all-isas') 1253# likewise for -environs targets and all the -deps targets 1254env.Depends(environs, '#all-deps') 1255