SConscript revision 12305
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#
6212302Sgabeblack@google.com# When specifying a source file of some type, a set of tags can be
6312302Sgabeblack@google.com# specified for that file.
6412302Sgabeblack@google.com
6512302Sgabeblack@google.comclass SourceList(list):
6612302Sgabeblack@google.com    def with_tags_that(self, predicate):
6712302Sgabeblack@google.com        '''Return a list of sources with tags that satisfy a predicate.'''
6812302Sgabeblack@google.com        def match(source):
6912302Sgabeblack@google.com            return predicate(source.tags)
7012302Sgabeblack@google.com        return SourceList(filter(match, self))
7112302Sgabeblack@google.com
7212302Sgabeblack@google.com    def with_any_tags(self, *tags):
7312302Sgabeblack@google.com        '''Return a list of sources with any of the supplied tags.'''
7412302Sgabeblack@google.com        return self.with_tags_that(lambda stags: len(tags & stags) > 0)
7512302Sgabeblack@google.com
7612302Sgabeblack@google.com    def with_all_tags(self, *tags):
7712302Sgabeblack@google.com        '''Return a list of sources with all of the supplied tags.'''
7812302Sgabeblack@google.com        return self.with_tags_that(lambda stags: tags <= stags)
7912302Sgabeblack@google.com
8012302Sgabeblack@google.com    def with_tag(self, tag):
8112302Sgabeblack@google.com        '''Return a list of sources with the supplied tag.'''
8212302Sgabeblack@google.com        return self.with_tags_that(lambda stags: tag in stags)
8312302Sgabeblack@google.com
8412302Sgabeblack@google.com    def without_tags(self, *tags):
8512302Sgabeblack@google.com        '''Return a list of sources without any of the supplied tags.'''
8612302Sgabeblack@google.com        return self.with_tags_that(lambda stags: len(tags & stags) == 0)
8712302Sgabeblack@google.com
8812302Sgabeblack@google.com    def without_tag(self, tag):
8912302Sgabeblack@google.com        '''Return a list of sources with the supplied tag.'''
9012302Sgabeblack@google.com        return self.with_tags_that(lambda stags: tag not in stags)
9111983Sgabeblack@google.com
926143Snate@binkert.orgclass SourceMeta(type):
938233Snate@binkert.org    '''Meta class for source files that keeps track of all files of a
9412302Sgabeblack@google.com    particular type.'''
956143Snate@binkert.org    def __init__(cls, name, bases, dict):
966143Snate@binkert.org        super(SourceMeta, cls).__init__(name, bases, dict)
9712302Sgabeblack@google.com        cls.all = SourceList()
984762Snate@binkert.org
996143Snate@binkert.orgclass SourceFile(object):
1008233Snate@binkert.org    '''Base object that encapsulates the notion of a source file.
1018233Snate@binkert.org    This includes, the source node, target node, various manipulations
10212302Sgabeblack@google.com    of those.  A source file also specifies a set of tags which
10312302Sgabeblack@google.com    describing arbitrary properties of the source file.'''
1046143Snate@binkert.org    __metaclass__ = SourceMeta
10512302Sgabeblack@google.com    def __init__(self, source, tags=None, add_tags=None):
10612302Sgabeblack@google.com        if tags is None:
10712302Sgabeblack@google.com            tags='gem5 lib'
10812302Sgabeblack@google.com        if isinstance(tags, basestring):
10912302Sgabeblack@google.com            tags = set([tags])
11012302Sgabeblack@google.com        if isinstance(add_tags, basestring):
11112302Sgabeblack@google.com            add_tags = set([add_tags])
11212302Sgabeblack@google.com        if add_tags:
11312302Sgabeblack@google.com            tags = tags | add_tags
11412302Sgabeblack@google.com        self.tags = set(tags)
1158233Snate@binkert.org
1166143Snate@binkert.org        tnode = source
1176143Snate@binkert.org        if not isinstance(source, SCons.Node.FS.File):
1186143Snate@binkert.org            tnode = File(source)
1196143Snate@binkert.org
1206143Snate@binkert.org        self.tnode = tnode
1216143Snate@binkert.org        self.snode = tnode.srcnode()
1226143Snate@binkert.org
1236143Snate@binkert.org        for base in type(self).__mro__:
1246143Snate@binkert.org            if issubclass(base, SourceFile):
1257065Snate@binkert.org                base.all.append(self)
1266143Snate@binkert.org
1278233Snate@binkert.org    @property
1288233Snate@binkert.org    def filename(self):
1298233Snate@binkert.org        return str(self.tnode)
1308233Snate@binkert.org
1318233Snate@binkert.org    @property
1328233Snate@binkert.org    def dirname(self):
1338233Snate@binkert.org        return dirname(self.filename)
1348233Snate@binkert.org
1358233Snate@binkert.org    @property
1368233Snate@binkert.org    def basename(self):
1378233Snate@binkert.org        return basename(self.filename)
1388233Snate@binkert.org
1398233Snate@binkert.org    @property
1408233Snate@binkert.org    def extname(self):
1418233Snate@binkert.org        index = self.basename.rfind('.')
1428233Snate@binkert.org        if index <= 0:
1438233Snate@binkert.org            # dot files aren't extensions
1448233Snate@binkert.org            return self.basename, None
1458233Snate@binkert.org
1468233Snate@binkert.org        return self.basename[:index], self.basename[index+1:]
1478233Snate@binkert.org
1486143Snate@binkert.org    def __lt__(self, other): return self.filename < other.filename
1496143Snate@binkert.org    def __le__(self, other): return self.filename <= other.filename
1506143Snate@binkert.org    def __gt__(self, other): return self.filename > other.filename
1516143Snate@binkert.org    def __ge__(self, other): return self.filename >= other.filename
1526143Snate@binkert.org    def __eq__(self, other): return self.filename == other.filename
1536143Snate@binkert.org    def __ne__(self, other): return self.filename != other.filename
1549982Satgutier@umich.edu
1556143Snate@binkert.orgclass Source(SourceFile):
15612302Sgabeblack@google.com    ungrouped_tag = 'No link group'
15712302Sgabeblack@google.com    source_groups = set()
15812302Sgabeblack@google.com
15912302Sgabeblack@google.com    _current_group_tag = ungrouped_tag
16012302Sgabeblack@google.com
16112302Sgabeblack@google.com    @staticmethod
16212302Sgabeblack@google.com    def link_group_tag(group):
16312302Sgabeblack@google.com        return 'link group: %s' % group
16411983Sgabeblack@google.com
16511983Sgabeblack@google.com    @classmethod
16611983Sgabeblack@google.com    def set_group(cls, group):
16712302Sgabeblack@google.com        new_tag = Source.link_group_tag(group)
16812302Sgabeblack@google.com        Source._current_group_tag = new_tag
16912302Sgabeblack@google.com        Source.source_groups.add(group)
17012302Sgabeblack@google.com
17112302Sgabeblack@google.com    def _add_link_group_tag(self):
17212302Sgabeblack@google.com        self.tags.add(Source._current_group_tag)
17311983Sgabeblack@google.com
1746143Snate@binkert.org    '''Add a c/c++ source file to the build'''
17512305Sgabeblack@google.com    def __init__(self, source, tags=None, add_tags=None):
17612302Sgabeblack@google.com        '''specify the source file, and any tags'''
17712302Sgabeblack@google.com        super(Source, self).__init__(source, tags, add_tags)
17812302Sgabeblack@google.com        self._add_link_group_tag()
1796143Snate@binkert.org
1806143Snate@binkert.orgclass PySource(SourceFile):
1816143Snate@binkert.org    '''Add a python source file to the named package'''
1825522Snate@binkert.org    invalid_sym_char = re.compile('[^A-z0-9_]')
1836143Snate@binkert.org    modules = {}
1846143Snate@binkert.org    tnodes = {}
1856143Snate@binkert.org    symnames = {}
1869982Satgutier@umich.edu
18712302Sgabeblack@google.com    def __init__(self, package, source, tags=None, add_tags=None):
18812302Sgabeblack@google.com        '''specify the python package, the source file, and any tags'''
18912302Sgabeblack@google.com        super(PySource, self).__init__(source, tags, add_tags)
1906143Snate@binkert.org
1916143Snate@binkert.org        modname,ext = self.extname
1926143Snate@binkert.org        assert ext == 'py'
1936143Snate@binkert.org
1945522Snate@binkert.org        if package:
1955522Snate@binkert.org            path = package.split('.')
1965522Snate@binkert.org        else:
1975522Snate@binkert.org            path = []
1985604Snate@binkert.org
1995604Snate@binkert.org        modpath = path[:]
2006143Snate@binkert.org        if modname != '__init__':
2016143Snate@binkert.org            modpath += [ modname ]
2024762Snate@binkert.org        modpath = '.'.join(modpath)
2034762Snate@binkert.org
2046143Snate@binkert.org        arcpath = path + [ self.basename ]
2056727Ssteve.reinhardt@amd.com        abspath = self.snode.abspath
2066727Ssteve.reinhardt@amd.com        if not exists(abspath):
2076727Ssteve.reinhardt@amd.com            abspath = self.tnode.abspath
2084762Snate@binkert.org
2096143Snate@binkert.org        self.package = package
2106143Snate@binkert.org        self.modname = modname
2116143Snate@binkert.org        self.modpath = modpath
2126143Snate@binkert.org        self.arcname = joinpath(*arcpath)
2136727Ssteve.reinhardt@amd.com        self.abspath = abspath
2146143Snate@binkert.org        self.compiled = File(self.filename + 'c')
2157674Snate@binkert.org        self.cpp = File(self.filename + '.cc')
2167674Snate@binkert.org        self.symname = PySource.invalid_sym_char.sub('_', modpath)
2175604Snate@binkert.org
2186143Snate@binkert.org        PySource.modules[modpath] = self
2196143Snate@binkert.org        PySource.tnodes[self.tnode] = self
2206143Snate@binkert.org        PySource.symnames[self.symname] = self
2214762Snate@binkert.org
2226143Snate@binkert.orgclass SimObject(PySource):
2234762Snate@binkert.org    '''Add a SimObject python file as a python source object and add
2244762Snate@binkert.org    it to a list of sim object modules'''
2254762Snate@binkert.org
2266143Snate@binkert.org    fixed = False
2276143Snate@binkert.org    modnames = []
2284762Snate@binkert.org
22912302Sgabeblack@google.com    def __init__(self, source, tags=None, add_tags=None):
23012302Sgabeblack@google.com        '''Specify the source file and any tags (automatically in
2318233Snate@binkert.org        the m5.objects package)'''
23212302Sgabeblack@google.com        super(SimObject, self).__init__('m5.objects', source, tags, add_tags)
2336143Snate@binkert.org        if self.fixed:
2346143Snate@binkert.org            raise AttributeError, "Too late to call SimObject now."
2354762Snate@binkert.org
2366143Snate@binkert.org        bisect.insort_right(SimObject.modnames, self.modname)
2374762Snate@binkert.org
2389396Sandreas.hansson@arm.comclass ProtoBuf(SourceFile):
2399396Sandreas.hansson@arm.com    '''Add a Protocol Buffer to build'''
2409396Sandreas.hansson@arm.com
24112302Sgabeblack@google.com    def __init__(self, source, tags=None, add_tags=None):
24212302Sgabeblack@google.com        '''Specify the source file, and any tags'''
24312302Sgabeblack@google.com        super(ProtoBuf, self).__init__(source, tags, add_tags)
2449396Sandreas.hansson@arm.com
2459396Sandreas.hansson@arm.com        # Get the file name and the extension
2469396Sandreas.hansson@arm.com        modname,ext = self.extname
2479396Sandreas.hansson@arm.com        assert ext == 'proto'
2489396Sandreas.hansson@arm.com
2499396Sandreas.hansson@arm.com        # Currently, we stick to generating the C++ headers, so we
2509396Sandreas.hansson@arm.com        # only need to track the source and header.
2519930Sandreas.hansson@arm.com        self.cc_file = File(modname + '.pb.cc')
2529930Sandreas.hansson@arm.com        self.hh_file = File(modname + '.pb.h')
2539396Sandreas.hansson@arm.com
2548235Snate@binkert.orgclass UnitTest(object):
2558235Snate@binkert.org    '''Create a UnitTest'''
2566143Snate@binkert.org
2578235Snate@binkert.org    all = []
2589003SAli.Saidi@ARM.com    def __init__(self, target, *sources, **kwargs):
2598235Snate@binkert.org        '''Specify the target name and any sources.  Sources that are
2608235Snate@binkert.org        not SourceFiles are evalued with Source().  All files are
26112302Sgabeblack@google.com        tagged with the name of the UnitTest target.'''
2628235Snate@binkert.org
26312302Sgabeblack@google.com        srcs = SourceList()
2648235Snate@binkert.org        for src in sources:
2658235Snate@binkert.org            if not isinstance(src, SourceFile):
26612302Sgabeblack@google.com                src = Source(src, tags=str(target))
2678235Snate@binkert.org            srcs.append(src)
2688235Snate@binkert.org
2698235Snate@binkert.org        self.sources = srcs
2708235Snate@binkert.org        self.target = target
2719003SAli.Saidi@ARM.com        self.main = kwargs.get('main', False)
2728235Snate@binkert.org        UnitTest.all.append(self)
2735584Snate@binkert.org
2744382Sbinkertn@umich.edu# Children should have access
2754202Sbinkertn@umich.eduExport('Source')
2764382Sbinkertn@umich.eduExport('PySource')
2774382Sbinkertn@umich.eduExport('SimObject')
2789396Sandreas.hansson@arm.comExport('ProtoBuf')
2795584Snate@binkert.orgExport('UnitTest')
2804382Sbinkertn@umich.edu
2814382Sbinkertn@umich.edu########################################################################
2824382Sbinkertn@umich.edu#
2838232Snate@binkert.org# Debug Flags
2845192Ssaidi@eecs.umich.edu#
2858232Snate@binkert.orgdebug_flags = {}
2868232Snate@binkert.orgdef DebugFlag(name, desc=None):
2878232Snate@binkert.org    if name in debug_flags:
2885192Ssaidi@eecs.umich.edu        raise AttributeError, "Flag %s already specified" % name
2898232Snate@binkert.org    debug_flags[name] = (name, (), desc)
2905192Ssaidi@eecs.umich.edu
2915799Snate@binkert.orgdef CompoundFlag(name, flags, desc=None):
2928232Snate@binkert.org    if name in debug_flags:
2935192Ssaidi@eecs.umich.edu        raise AttributeError, "Flag %s already specified" % name
2945192Ssaidi@eecs.umich.edu
2955192Ssaidi@eecs.umich.edu    compound = tuple(flags)
2968232Snate@binkert.org    debug_flags[name] = (name, compound, desc)
2975192Ssaidi@eecs.umich.edu
2988232Snate@binkert.orgExport('DebugFlag')
2995192Ssaidi@eecs.umich.eduExport('CompoundFlag')
3005192Ssaidi@eecs.umich.edu
3015192Ssaidi@eecs.umich.edu########################################################################
3025192Ssaidi@eecs.umich.edu#
3034382Sbinkertn@umich.edu# Set some compiler variables
3044382Sbinkertn@umich.edu#
3054382Sbinkertn@umich.edu
3062667Sstever@eecs.umich.edu# Include file paths are rooted in this directory.  SCons will
3072667Sstever@eecs.umich.edu# automatically expand '.' to refer to both the source directory and
3082667Sstever@eecs.umich.edu# the corresponding build directory to pick up generated include
3092667Sstever@eecs.umich.edu# files.
3102667Sstever@eecs.umich.eduenv.Append(CPPPATH=Dir('.'))
3112667Sstever@eecs.umich.edu
3125742Snate@binkert.orgfor extra_dir in extras_dir_list:
3135742Snate@binkert.org    env.Append(CPPPATH=Dir(extra_dir))
3145742Snate@binkert.org
3155793Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212
3168334Snate@binkert.org# Scons bug id: 2006 gem5 Bug id: 308
3175793Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True):
3185793Snate@binkert.org    Dir(root[len(base_dir) + 1:])
3195793Snate@binkert.org
3204382Sbinkertn@umich.edu########################################################################
3214762Snate@binkert.org#
3225344Sstever@gmail.com# Walk the tree and execute all SConscripts in subdirectories
3234382Sbinkertn@umich.edu#
3245341Sstever@gmail.com
3255742Snate@binkert.orghere = Dir('.').srcnode().abspath
3265742Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True):
3275742Snate@binkert.org    if root == here:
3285742Snate@binkert.org        # we don't want to recurse back into this SConscript
3295742Snate@binkert.org        continue
3304762Snate@binkert.org
3315742Snate@binkert.org    if 'SConscript' in files:
3325742Snate@binkert.org        build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:])
33311984Sgabeblack@google.com        Source.set_group(build_dir)
3347722Sgblack@eecs.umich.edu        SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
3355742Snate@binkert.org
3365742Snate@binkert.orgfor extra_dir in extras_dir_list:
3375742Snate@binkert.org    prefix_len = len(dirname(extra_dir)) + 1
3389930Sandreas.hansson@arm.com
3399930Sandreas.hansson@arm.com    # Also add the corresponding build directory to pick up generated
3409930Sandreas.hansson@arm.com    # include files.
3419930Sandreas.hansson@arm.com    env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:])))
3429930Sandreas.hansson@arm.com
3435742Snate@binkert.org    for root, dirs, files in os.walk(extra_dir, topdown=True):
3448242Sbradley.danofsky@amd.com        # if build lives in the extras directory, don't walk down it
3458242Sbradley.danofsky@amd.com        if 'build' in dirs:
3468242Sbradley.danofsky@amd.com            dirs.remove('build')
3478242Sbradley.danofsky@amd.com
3485341Sstever@gmail.com        if 'SConscript' in files:
3495742Snate@binkert.org            build_dir = joinpath(env['BUILDDIR'], root[prefix_len:])
3507722Sgblack@eecs.umich.edu            SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
3514773Snate@binkert.org
3526108Snate@binkert.orgfor opt in export_vars:
3531858SN/A    env.ConfigFile(opt)
3541085SN/A
3556658Snate@binkert.orgdef makeTheISA(source, target, env):
3566658Snate@binkert.org    isas = [ src.get_contents() for src in source ]
3577673Snate@binkert.org    target_isa = env['TARGET_ISA']
3586658Snate@binkert.org    def define(isa):
3596658Snate@binkert.org        return isa.upper() + '_ISA'
36011308Santhony.gutierrez@amd.com
3616658Snate@binkert.org    def namespace(isa):
36211308Santhony.gutierrez@amd.com        return isa[0].upper() + isa[1:].lower() + 'ISA'
3636658Snate@binkert.org
3646658Snate@binkert.org
3657673Snate@binkert.org    code = code_formatter()
3667673Snate@binkert.org    code('''\
3677673Snate@binkert.org#ifndef __CONFIG_THE_ISA_HH__
3687673Snate@binkert.org#define __CONFIG_THE_ISA_HH__
3697673Snate@binkert.org
3707673Snate@binkert.org''')
3717673Snate@binkert.org
37210467Sandreas.hansson@arm.com    # create defines for the preprocessing and compile-time determination
3736658Snate@binkert.org    for i,isa in enumerate(isas):
3747673Snate@binkert.org        code('#define $0 $1', define(isa), i + 1)
37510467Sandreas.hansson@arm.com    code()
37610467Sandreas.hansson@arm.com
37710467Sandreas.hansson@arm.com    # create an enum for any run-time determination of the ISA, we
37810467Sandreas.hansson@arm.com    # reuse the same name as the namespaces
37910467Sandreas.hansson@arm.com    code('enum class Arch {')
38010467Sandreas.hansson@arm.com    for i,isa in enumerate(isas):
38110467Sandreas.hansson@arm.com        if i + 1 == len(isas):
38210467Sandreas.hansson@arm.com            code('  $0 = $1', namespace(isa), define(isa))
38310467Sandreas.hansson@arm.com        else:
38410467Sandreas.hansson@arm.com            code('  $0 = $1,', namespace(isa), define(isa))
38510467Sandreas.hansson@arm.com    code('};')
3867673Snate@binkert.org
3877673Snate@binkert.org    code('''
3887673Snate@binkert.org
3897673Snate@binkert.org#define THE_ISA ${{define(target_isa)}}
3907673Snate@binkert.org#define TheISA ${{namespace(target_isa)}}
3919048SAli.Saidi@ARM.com#define THE_ISA_STR "${{target_isa}}"
3927673Snate@binkert.org
3937673Snate@binkert.org#endif // __CONFIG_THE_ISA_HH__''')
3947673Snate@binkert.org
3957673Snate@binkert.org    code.write(str(target[0]))
3966658Snate@binkert.org
3977756SAli.Saidi@ARM.comenv.Command('config/the_isa.hh', map(Value, all_isa_list),
3987816Ssteve.reinhardt@amd.com            MakeAction(makeTheISA, Transform("CFG ISA", 0)))
3996658Snate@binkert.org
40011308Santhony.gutierrez@amd.comdef makeTheGPUISA(source, target, env):
40111308Santhony.gutierrez@amd.com    isas = [ src.get_contents() for src in source ]
40211308Santhony.gutierrez@amd.com    target_gpu_isa = env['TARGET_GPU_ISA']
40311308Santhony.gutierrez@amd.com    def define(isa):
40411308Santhony.gutierrez@amd.com        return isa.upper() + '_ISA'
40511308Santhony.gutierrez@amd.com
40611308Santhony.gutierrez@amd.com    def namespace(isa):
40711308Santhony.gutierrez@amd.com        return isa[0].upper() + isa[1:].lower() + 'ISA'
40811308Santhony.gutierrez@amd.com
40911308Santhony.gutierrez@amd.com
41011308Santhony.gutierrez@amd.com    code = code_formatter()
41111308Santhony.gutierrez@amd.com    code('''\
41211308Santhony.gutierrez@amd.com#ifndef __CONFIG_THE_GPU_ISA_HH__
41311308Santhony.gutierrez@amd.com#define __CONFIG_THE_GPU_ISA_HH__
41411308Santhony.gutierrez@amd.com
41511308Santhony.gutierrez@amd.com''')
41611308Santhony.gutierrez@amd.com
41711308Santhony.gutierrez@amd.com    # create defines for the preprocessing and compile-time determination
41811308Santhony.gutierrez@amd.com    for i,isa in enumerate(isas):
41911308Santhony.gutierrez@amd.com        code('#define $0 $1', define(isa), i + 1)
42011308Santhony.gutierrez@amd.com    code()
42111308Santhony.gutierrez@amd.com
42211308Santhony.gutierrez@amd.com    # create an enum for any run-time determination of the ISA, we
42311308Santhony.gutierrez@amd.com    # reuse the same name as the namespaces
42411308Santhony.gutierrez@amd.com    code('enum class GPUArch {')
42511308Santhony.gutierrez@amd.com    for i,isa in enumerate(isas):
42611308Santhony.gutierrez@amd.com        if i + 1 == len(isas):
42711308Santhony.gutierrez@amd.com            code('  $0 = $1', namespace(isa), define(isa))
42811308Santhony.gutierrez@amd.com        else:
42911308Santhony.gutierrez@amd.com            code('  $0 = $1,', namespace(isa), define(isa))
43011308Santhony.gutierrez@amd.com    code('};')
43111308Santhony.gutierrez@amd.com
43211308Santhony.gutierrez@amd.com    code('''
43311308Santhony.gutierrez@amd.com
43411308Santhony.gutierrez@amd.com#define THE_GPU_ISA ${{define(target_gpu_isa)}}
43511308Santhony.gutierrez@amd.com#define TheGpuISA ${{namespace(target_gpu_isa)}}
43611308Santhony.gutierrez@amd.com#define THE_GPU_ISA_STR "${{target_gpu_isa}}"
43711308Santhony.gutierrez@amd.com
43811308Santhony.gutierrez@amd.com#endif // __CONFIG_THE_GPU_ISA_HH__''')
43911308Santhony.gutierrez@amd.com
44011308Santhony.gutierrez@amd.com    code.write(str(target[0]))
44111308Santhony.gutierrez@amd.com
44211308Santhony.gutierrez@amd.comenv.Command('config/the_gpu_isa.hh', map(Value, all_gpu_isa_list),
44311308Santhony.gutierrez@amd.com            MakeAction(makeTheGPUISA, Transform("CFG ISA", 0)))
44411308Santhony.gutierrez@amd.com
4454382Sbinkertn@umich.edu########################################################################
4464382Sbinkertn@umich.edu#
4474762Snate@binkert.org# Prevent any SimObjects from being added after this point, they
4484762Snate@binkert.org# should all have been added in the SConscripts above
4494762Snate@binkert.org#
4506654Snate@binkert.orgSimObject.fixed = True
4516654Snate@binkert.org
4525517Snate@binkert.orgclass DictImporter(object):
4535517Snate@binkert.org    '''This importer takes a dictionary of arbitrary module names that
4545517Snate@binkert.org    map to arbitrary filenames.'''
4555517Snate@binkert.org    def __init__(self, modules):
4565517Snate@binkert.org        self.modules = modules
4575517Snate@binkert.org        self.installed = set()
4585517Snate@binkert.org
4595517Snate@binkert.org    def __del__(self):
4605517Snate@binkert.org        self.unload()
4615517Snate@binkert.org
4625517Snate@binkert.org    def unload(self):
4635517Snate@binkert.org        import sys
4645517Snate@binkert.org        for module in self.installed:
4655517Snate@binkert.org            del sys.modules[module]
4665517Snate@binkert.org        self.installed = set()
4675517Snate@binkert.org
4685517Snate@binkert.org    def find_module(self, fullname, path):
4696654Snate@binkert.org        if fullname == 'm5.defines':
4705517Snate@binkert.org            return self
4715517Snate@binkert.org
4725517Snate@binkert.org        if fullname == 'm5.objects':
4735517Snate@binkert.org            return self
4745517Snate@binkert.org
47511802Sandreas.sandberg@arm.com        if fullname.startswith('_m5'):
4765517Snate@binkert.org            return None
4775517Snate@binkert.org
4786143Snate@binkert.org        source = self.modules.get(fullname, None)
4796654Snate@binkert.org        if source is not None and fullname.startswith('m5.objects'):
4805517Snate@binkert.org            return self
4815517Snate@binkert.org
4825517Snate@binkert.org        return None
4835517Snate@binkert.org
4845517Snate@binkert.org    def load_module(self, fullname):
4855517Snate@binkert.org        mod = imp.new_module(fullname)
4865517Snate@binkert.org        sys.modules[fullname] = mod
4875517Snate@binkert.org        self.installed.add(fullname)
4885517Snate@binkert.org
4895517Snate@binkert.org        mod.__loader__ = self
4905517Snate@binkert.org        if fullname == 'm5.objects':
4915517Snate@binkert.org            mod.__path__ = fullname.split('.')
4925517Snate@binkert.org            return mod
4935517Snate@binkert.org
4946654Snate@binkert.org        if fullname == 'm5.defines':
4956654Snate@binkert.org            mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env)
4965517Snate@binkert.org            return mod
4975517Snate@binkert.org
4986143Snate@binkert.org        source = self.modules[fullname]
4996143Snate@binkert.org        if source.modname == '__init__':
5006143Snate@binkert.org            mod.__path__ = source.modpath
5016727Ssteve.reinhardt@amd.com        mod.__file__ = source.abspath
5025517Snate@binkert.org
5036727Ssteve.reinhardt@amd.com        exec file(source.abspath, 'r') in mod.__dict__
5045517Snate@binkert.org
5055517Snate@binkert.org        return mod
5065517Snate@binkert.org
5076654Snate@binkert.orgimport m5.SimObject
5086654Snate@binkert.orgimport m5.params
5097673Snate@binkert.orgfrom m5.util import code_formatter
5106654Snate@binkert.org
5116654Snate@binkert.orgm5.SimObject.clear()
5126654Snate@binkert.orgm5.params.clear()
5136654Snate@binkert.org
5145517Snate@binkert.org# install the python importer so we can grab stuff from the source
5155517Snate@binkert.org# tree itself.  We can't have SimObjects added after this point or
5165517Snate@binkert.org# else we won't know about them for the rest of the stuff.
5176143Snate@binkert.orgimporter = DictImporter(PySource.modules)
5185517Snate@binkert.orgsys.meta_path[0:0] = [ importer ]
5194762Snate@binkert.org
5205517Snate@binkert.org# import all sim objects so we can populate the all_objects list
5215517Snate@binkert.org# make sure that we're working with a list, then let's sort it
5226143Snate@binkert.orgfor modname in SimObject.modnames:
5236143Snate@binkert.org    exec('from m5.objects import %s' % modname)
5245517Snate@binkert.org
5255517Snate@binkert.org# we need to unload all of the currently imported modules so that they
5265517Snate@binkert.org# will be re-imported the next time the sconscript is run
5275517Snate@binkert.orgimporter.unload()
5285517Snate@binkert.orgsys.meta_path.remove(importer)
5295517Snate@binkert.org
5305517Snate@binkert.orgsim_objects = m5.SimObject.allClasses
5315517Snate@binkert.orgall_enums = m5.params.allEnums
5325517Snate@binkert.org
5336143Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()):
5345517Snate@binkert.org    for param in obj._params.local.values():
5356654Snate@binkert.org        # load the ptype attribute now because it depends on the
5366654Snate@binkert.org        # current version of SimObject.allClasses, but when scons
5376654Snate@binkert.org        # actually uses the value, all versions of
5386654Snate@binkert.org        # SimObject.allClasses will have been loaded
5396654Snate@binkert.org        param.ptype
5406654Snate@binkert.org
5414762Snate@binkert.org########################################################################
5424762Snate@binkert.org#
5434762Snate@binkert.org# calculate extra dependencies
5444762Snate@binkert.org#
5454762Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"]
5467675Snate@binkert.orgdepends = [ PySource.modules[dep].snode for dep in module_depends ]
54710584Sandreas.hansson@arm.comdepends.sort(key = lambda x: x.name)
5484762Snate@binkert.org
5494762Snate@binkert.org########################################################################
5504762Snate@binkert.org#
5514762Snate@binkert.org# Commands for the basic automatically generated python files
5524382Sbinkertn@umich.edu#
5534382Sbinkertn@umich.edu
5545517Snate@binkert.org# Generate Python file containing a dict specifying the current
5556654Snate@binkert.org# buildEnv flags.
5565517Snate@binkert.orgdef makeDefinesPyFile(target, source, env):
5578126Sgblack@eecs.umich.edu    build_env = source[0].get_contents()
5586654Snate@binkert.org
5597673Snate@binkert.org    code = code_formatter()
5606654Snate@binkert.org    code("""
56111802Sandreas.sandberg@arm.comimport _m5.core
5626654Snate@binkert.orgimport m5.util
5636654Snate@binkert.org
5646654Snate@binkert.orgbuildEnv = m5.util.SmartDict($build_env)
5656654Snate@binkert.org
56611802Sandreas.sandberg@arm.comcompileDate = _m5.core.compileDate
5676669Snate@binkert.org_globals = globals()
56811802Sandreas.sandberg@arm.comfor key,val in _m5.core.__dict__.iteritems():
5696669Snate@binkert.org    if key.startswith('flag_'):
5706669Snate@binkert.org        flag = key[5:]
5716669Snate@binkert.org        _globals[flag] = val
5726669Snate@binkert.orgdel _globals
5736654Snate@binkert.org""")
5747673Snate@binkert.org    code.write(target[0].abspath)
5755517Snate@binkert.org
5768126Sgblack@eecs.umich.edudefines_info = Value(build_env)
5775798Snate@binkert.org# Generate a file with all of the compile options in it
5787756SAli.Saidi@ARM.comenv.Command('python/m5/defines.py', defines_info,
5797816Ssteve.reinhardt@amd.com            MakeAction(makeDefinesPyFile, Transform("DEFINES", 0)))
5805798Snate@binkert.orgPySource('m5', 'python/m5/defines.py')
5815798Snate@binkert.org
5825517Snate@binkert.org# Generate python file containing info about the M5 source code
5835517Snate@binkert.orgdef makeInfoPyFile(target, source, env):
5847673Snate@binkert.org    code = code_formatter()
5855517Snate@binkert.org    for src in source:
5865517Snate@binkert.org        data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
5877673Snate@binkert.org        code('$src = ${{repr(data)}}')
5887673Snate@binkert.org    code.write(str(target[0]))
5895517Snate@binkert.org
5905798Snate@binkert.org# Generate a file that wraps the basic top level files
5915798Snate@binkert.orgenv.Command('python/m5/info.py',
5928333Snate@binkert.org            [ '#/COPYING', '#/LICENSE', '#/README', ],
5937816Ssteve.reinhardt@amd.com            MakeAction(makeInfoPyFile, Transform("INFO")))
5945798Snate@binkert.orgPySource('m5', 'python/m5/info.py')
5955798Snate@binkert.org
5964762Snate@binkert.org########################################################################
5974762Snate@binkert.org#
5984762Snate@binkert.org# Create all of the SimObject param headers and enum headers
5994762Snate@binkert.org#
6004762Snate@binkert.org
6018596Ssteve.reinhardt@amd.comdef createSimObjectParamStruct(target, source, env):
6025517Snate@binkert.org    assert len(target) == 1 and len(source) == 1
6035517Snate@binkert.org
60411997Sgabeblack@google.com    name = source[0].get_text_contents()
6055517Snate@binkert.org    obj = sim_objects[name]
6065517Snate@binkert.org
6077673Snate@binkert.org    code = code_formatter()
6088596Ssteve.reinhardt@amd.com    obj.cxx_param_decl(code)
6097673Snate@binkert.org    code.write(target[0].abspath)
6105517Snate@binkert.org
61110458Sandreas.hansson@arm.comdef createSimObjectCxxConfig(is_header):
61210458Sandreas.hansson@arm.com    def body(target, source, env):
61310458Sandreas.hansson@arm.com        assert len(target) == 1 and len(source) == 1
61410458Sandreas.hansson@arm.com
61510458Sandreas.hansson@arm.com        name = str(source[0].get_contents())
61610458Sandreas.hansson@arm.com        obj = sim_objects[name]
61710458Sandreas.hansson@arm.com
61810458Sandreas.hansson@arm.com        code = code_formatter()
61910458Sandreas.hansson@arm.com        obj.cxx_config_param_file(code, is_header)
62010458Sandreas.hansson@arm.com        code.write(target[0].abspath)
62110458Sandreas.hansson@arm.com    return body
62210458Sandreas.hansson@arm.com
6235517Snate@binkert.orgdef createEnumStrings(target, source, env):
62411996Sgabeblack@google.com    assert len(target) == 1 and len(source) == 2
6255517Snate@binkert.org
62611997Sgabeblack@google.com    name = source[0].get_text_contents()
62711996Sgabeblack@google.com    use_python = source[1].read()
6285517Snate@binkert.org    obj = all_enums[name]
6295517Snate@binkert.org
6307673Snate@binkert.org    code = code_formatter()
6317673Snate@binkert.org    obj.cxx_def(code)
63211996Sgabeblack@google.com    if use_python:
63311988Sandreas.sandberg@arm.com        obj.pybind_def(code)
6347673Snate@binkert.org    code.write(target[0].abspath)
6355517Snate@binkert.org
6368596Ssteve.reinhardt@amd.comdef createEnumDecls(target, source, env):
6375517Snate@binkert.org    assert len(target) == 1 and len(source) == 1
6385517Snate@binkert.org
63911997Sgabeblack@google.com    name = source[0].get_text_contents()
6405517Snate@binkert.org    obj = all_enums[name]
6415517Snate@binkert.org
6427673Snate@binkert.org    code = code_formatter()
6437673Snate@binkert.org    obj.cxx_decl(code)
6447673Snate@binkert.org    code.write(target[0].abspath)
6455517Snate@binkert.org
64611988Sandreas.sandberg@arm.comdef createSimObjectPyBindWrapper(target, source, env):
64711997Sgabeblack@google.com    name = source[0].get_text_contents()
6488596Ssteve.reinhardt@amd.com    obj = sim_objects[name]
6498596Ssteve.reinhardt@amd.com
6508596Ssteve.reinhardt@amd.com    code = code_formatter()
65111988Sandreas.sandberg@arm.com    obj.pybind_decl(code)
6528596Ssteve.reinhardt@amd.com    code.write(target[0].abspath)
6538596Ssteve.reinhardt@amd.com
6548596Ssteve.reinhardt@amd.com# Generate all of the SimObject param C++ struct header files
6554762Snate@binkert.orgparams_hh_files = []
6566143Snate@binkert.orgfor name,simobj in sorted(sim_objects.iteritems()):
6576143Snate@binkert.org    py_source = PySource.modules[simobj.__module__]
6586143Snate@binkert.org    extra_deps = [ py_source.tnode ]
6594762Snate@binkert.org
6604762Snate@binkert.org    hh_file = File('params/%s.hh' % name)
6614762Snate@binkert.org    params_hh_files.append(hh_file)
6627756SAli.Saidi@ARM.com    env.Command(hh_file, Value(name),
6638596Ssteve.reinhardt@amd.com                MakeAction(createSimObjectParamStruct, Transform("SO PARAM")))
6644762Snate@binkert.org    env.Depends(hh_file, depends + extra_deps)
6654762Snate@binkert.org
66610458Sandreas.hansson@arm.com# C++ parameter description files
66710458Sandreas.hansson@arm.comif GetOption('with_cxx_config'):
66810458Sandreas.hansson@arm.com    for name,simobj in sorted(sim_objects.iteritems()):
66910458Sandreas.hansson@arm.com        py_source = PySource.modules[simobj.__module__]
67010458Sandreas.hansson@arm.com        extra_deps = [ py_source.tnode ]
67110458Sandreas.hansson@arm.com
67210458Sandreas.hansson@arm.com        cxx_config_hh_file = File('cxx_config/%s.hh' % name)
67310458Sandreas.hansson@arm.com        cxx_config_cc_file = File('cxx_config/%s.cc' % name)
67410458Sandreas.hansson@arm.com        env.Command(cxx_config_hh_file, Value(name),
67510458Sandreas.hansson@arm.com                    MakeAction(createSimObjectCxxConfig(True),
67610458Sandreas.hansson@arm.com                    Transform("CXXCPRHH")))
67710458Sandreas.hansson@arm.com        env.Command(cxx_config_cc_file, Value(name),
67810458Sandreas.hansson@arm.com                    MakeAction(createSimObjectCxxConfig(False),
67910458Sandreas.hansson@arm.com                    Transform("CXXCPRCC")))
68010458Sandreas.hansson@arm.com        env.Depends(cxx_config_hh_file, depends + extra_deps +
68110458Sandreas.hansson@arm.com                    [File('params/%s.hh' % name), File('sim/cxx_config.hh')])
68210458Sandreas.hansson@arm.com        env.Depends(cxx_config_cc_file, depends + extra_deps +
68310458Sandreas.hansson@arm.com                    [cxx_config_hh_file])
68410458Sandreas.hansson@arm.com        Source(cxx_config_cc_file)
68510458Sandreas.hansson@arm.com
68610458Sandreas.hansson@arm.com    cxx_config_init_cc_file = File('cxx_config/init.cc')
68710458Sandreas.hansson@arm.com
68810458Sandreas.hansson@arm.com    def createCxxConfigInitCC(target, source, env):
68910458Sandreas.hansson@arm.com        assert len(target) == 1 and len(source) == 1
69010458Sandreas.hansson@arm.com
69110458Sandreas.hansson@arm.com        code = code_formatter()
69210458Sandreas.hansson@arm.com
69310458Sandreas.hansson@arm.com        for name,simobj in sorted(sim_objects.iteritems()):
69410458Sandreas.hansson@arm.com            if not hasattr(simobj, 'abstract') or not simobj.abstract:
69510458Sandreas.hansson@arm.com                code('#include "cxx_config/${name}.hh"')
69610458Sandreas.hansson@arm.com        code()
69710458Sandreas.hansson@arm.com        code('void cxxConfigInit()')
69810458Sandreas.hansson@arm.com        code('{')
69910458Sandreas.hansson@arm.com        code.indent()
70010458Sandreas.hansson@arm.com        for name,simobj in sorted(sim_objects.iteritems()):
70110458Sandreas.hansson@arm.com            not_abstract = not hasattr(simobj, 'abstract') or \
70210458Sandreas.hansson@arm.com                not simobj.abstract
70310458Sandreas.hansson@arm.com            if not_abstract and 'type' in simobj.__dict__:
70410458Sandreas.hansson@arm.com                code('cxx_config_directory["${name}"] = '
70510458Sandreas.hansson@arm.com                     '${name}CxxConfigParams::makeDirectoryEntry();')
70610458Sandreas.hansson@arm.com        code.dedent()
70710458Sandreas.hansson@arm.com        code('}')
70810458Sandreas.hansson@arm.com        code.write(target[0].abspath)
70910458Sandreas.hansson@arm.com
71010458Sandreas.hansson@arm.com    py_source = PySource.modules[simobj.__module__]
71110458Sandreas.hansson@arm.com    extra_deps = [ py_source.tnode ]
71210458Sandreas.hansson@arm.com    env.Command(cxx_config_init_cc_file, Value(name),
71310458Sandreas.hansson@arm.com        MakeAction(createCxxConfigInitCC, Transform("CXXCINIT")))
71410458Sandreas.hansson@arm.com    cxx_param_hh_files = ["cxx_config/%s.hh" % simobj
71510584Sandreas.hansson@arm.com        for name,simobj in sorted(sim_objects.iteritems())
71610458Sandreas.hansson@arm.com        if not hasattr(simobj, 'abstract') or not simobj.abstract]
71710458Sandreas.hansson@arm.com    Depends(cxx_config_init_cc_file, cxx_param_hh_files +
71810458Sandreas.hansson@arm.com            [File('sim/cxx_config.hh')])
71910458Sandreas.hansson@arm.com    Source(cxx_config_init_cc_file)
72010458Sandreas.hansson@arm.com
7214762Snate@binkert.org# Generate all enum header files
7226143Snate@binkert.orgfor name,enum in sorted(all_enums.iteritems()):
7236143Snate@binkert.org    py_source = PySource.modules[enum.__module__]
7246143Snate@binkert.org    extra_deps = [ py_source.tnode ]
7254762Snate@binkert.org
7264762Snate@binkert.org    cc_file = File('enums/%s.cc' % name)
72711996Sgabeblack@google.com    env.Command(cc_file, [Value(name), Value(env['USE_PYTHON'])],
7287816Ssteve.reinhardt@amd.com                MakeAction(createEnumStrings, Transform("ENUM STR")))
7294762Snate@binkert.org    env.Depends(cc_file, depends + extra_deps)
7304762Snate@binkert.org    Source(cc_file)
7314762Snate@binkert.org
7324762Snate@binkert.org    hh_file = File('enums/%s.hh' % name)
7337756SAli.Saidi@ARM.com    env.Command(hh_file, Value(name),
7348596Ssteve.reinhardt@amd.com                MakeAction(createEnumDecls, Transform("ENUMDECL")))
7354762Snate@binkert.org    env.Depends(hh_file, depends + extra_deps)
7364762Snate@binkert.org
73711988Sandreas.sandberg@arm.com# Generate SimObject Python bindings wrapper files
73811988Sandreas.sandberg@arm.comif env['USE_PYTHON']:
73911988Sandreas.sandberg@arm.com    for name,simobj in sorted(sim_objects.iteritems()):
74011988Sandreas.sandberg@arm.com        py_source = PySource.modules[simobj.__module__]
74111988Sandreas.sandberg@arm.com        extra_deps = [ py_source.tnode ]
74211988Sandreas.sandberg@arm.com        cc_file = File('python/_m5/param_%s.cc' % name)
74311988Sandreas.sandberg@arm.com        env.Command(cc_file, Value(name),
74411988Sandreas.sandberg@arm.com                    MakeAction(createSimObjectPyBindWrapper,
74511988Sandreas.sandberg@arm.com                               Transform("SO PyBind")))
74611988Sandreas.sandberg@arm.com        env.Depends(cc_file, depends + extra_deps)
74711988Sandreas.sandberg@arm.com        Source(cc_file)
7484382Sbinkertn@umich.edu
7499396Sandreas.hansson@arm.com# Build all protocol buffers if we have got protoc and protobuf available
7509396Sandreas.hansson@arm.comif env['HAVE_PROTOBUF']:
7519396Sandreas.hansson@arm.com    for proto in ProtoBuf.all:
7529396Sandreas.hansson@arm.com        # Use both the source and header as the target, and the .proto
7539396Sandreas.hansson@arm.com        # file as the source. When executing the protoc compiler, also
7549396Sandreas.hansson@arm.com        # specify the proto_path to avoid having the generated files
7559396Sandreas.hansson@arm.com        # include the path.
7569396Sandreas.hansson@arm.com        env.Command([proto.cc_file, proto.hh_file], proto.tnode,
7579396Sandreas.hansson@arm.com                    MakeAction('$PROTOC --cpp_out ${TARGET.dir} '
7589396Sandreas.hansson@arm.com                               '--proto_path ${SOURCE.dir} $SOURCE',
7599396Sandreas.hansson@arm.com                               Transform("PROTOC")))
7609396Sandreas.hansson@arm.com
7619396Sandreas.hansson@arm.com        # Add the C++ source file
76212302Sgabeblack@google.com        Source(proto.cc_file, tags=proto.tags)
7639396Sandreas.hansson@arm.comelif ProtoBuf.all:
7649396Sandreas.hansson@arm.com    print 'Got protobuf to build, but lacks support!'
7659396Sandreas.hansson@arm.com    Exit(1)
7669396Sandreas.hansson@arm.com
7678232Snate@binkert.org#
7688232Snate@binkert.org# Handle debug flags
7698232Snate@binkert.org#
7708232Snate@binkert.orgdef makeDebugFlagCC(target, source, env):
7718232Snate@binkert.org    assert(len(target) == 1 and len(source) == 1)
7726229Snate@binkert.org
77310455SCurtis.Dunham@arm.com    code = code_formatter()
7746229Snate@binkert.org
77510455SCurtis.Dunham@arm.com    # delay definition of CompoundFlags until after all the definition
77610455SCurtis.Dunham@arm.com    # of all constituent SimpleFlags
77710455SCurtis.Dunham@arm.com    comp_code = code_formatter()
7785517Snate@binkert.org
7795517Snate@binkert.org    # file header
7807673Snate@binkert.org    code('''
7815517Snate@binkert.org/*
78210455SCurtis.Dunham@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons.
7835517Snate@binkert.org */
7845517Snate@binkert.org
7858232Snate@binkert.org#include "base/debug.hh"
78610455SCurtis.Dunham@arm.com
78710455SCurtis.Dunham@arm.comnamespace Debug {
78810455SCurtis.Dunham@arm.com
7897673Snate@binkert.org''')
7907673Snate@binkert.org
79110455SCurtis.Dunham@arm.com    for name, flag in sorted(source[0].read().iteritems()):
79210455SCurtis.Dunham@arm.com        n, compound, desc = flag
79310455SCurtis.Dunham@arm.com        assert n == name
7945517Snate@binkert.org
79510455SCurtis.Dunham@arm.com        if not compound:
79610455SCurtis.Dunham@arm.com            code('SimpleFlag $name("$name", "$desc");')
79710455SCurtis.Dunham@arm.com        else:
79810455SCurtis.Dunham@arm.com            comp_code('CompoundFlag $name("$name", "$desc",')
79910455SCurtis.Dunham@arm.com            comp_code.indent()
80010455SCurtis.Dunham@arm.com            last = len(compound) - 1
80110455SCurtis.Dunham@arm.com            for i,flag in enumerate(compound):
80210455SCurtis.Dunham@arm.com                if i != last:
80310685Sandreas.hansson@arm.com                    comp_code('&$flag,')
80410455SCurtis.Dunham@arm.com                else:
80510685Sandreas.hansson@arm.com                    comp_code('&$flag);')
80610455SCurtis.Dunham@arm.com            comp_code.dedent()
8075517Snate@binkert.org
80810455SCurtis.Dunham@arm.com    code.append(comp_code)
8098232Snate@binkert.org    code()
8108232Snate@binkert.org    code('} // namespace Debug')
8115517Snate@binkert.org
8127673Snate@binkert.org    code.write(str(target[0]))
8135517Snate@binkert.org
8148232Snate@binkert.orgdef makeDebugFlagHH(target, source, env):
8158232Snate@binkert.org    assert(len(target) == 1 and len(source) == 1)
8165517Snate@binkert.org
8178232Snate@binkert.org    val = eval(source[0].get_contents())
8188232Snate@binkert.org    name, compound, desc = val
8198232Snate@binkert.org
8207673Snate@binkert.org    code = code_formatter()
8215517Snate@binkert.org
8225517Snate@binkert.org    # file header boilerplate
8237673Snate@binkert.org    code('''\
8245517Snate@binkert.org/*
82510455SCurtis.Dunham@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons.
8265517Snate@binkert.org */
8275517Snate@binkert.org
8288232Snate@binkert.org#ifndef __DEBUG_${name}_HH__
8298232Snate@binkert.org#define __DEBUG_${name}_HH__
8305517Snate@binkert.org
8318232Snate@binkert.orgnamespace Debug {
8328232Snate@binkert.org''')
8335517Snate@binkert.org
8348232Snate@binkert.org    if compound:
8358232Snate@binkert.org        code('class CompoundFlag;')
8368232Snate@binkert.org    code('class SimpleFlag;')
8375517Snate@binkert.org
8388232Snate@binkert.org    if compound:
8398232Snate@binkert.org        code('extern CompoundFlag $name;')
8408232Snate@binkert.org        for flag in compound:
8418232Snate@binkert.org            code('extern SimpleFlag $flag;')
8428232Snate@binkert.org    else:
8438232Snate@binkert.org        code('extern SimpleFlag $name;')
8445517Snate@binkert.org
8458232Snate@binkert.org    code('''
8468232Snate@binkert.org}
8475517Snate@binkert.org
8488232Snate@binkert.org#endif // __DEBUG_${name}_HH__
8497673Snate@binkert.org''')
8505517Snate@binkert.org
8517673Snate@binkert.org    code.write(str(target[0]))
8525517Snate@binkert.org
8538232Snate@binkert.orgfor name,flag in sorted(debug_flags.iteritems()):
8548232Snate@binkert.org    n, compound, desc = flag
8558232Snate@binkert.org    assert n == name
8565192Ssaidi@eecs.umich.edu
85710454SCurtis.Dunham@arm.com    hh_file = 'debug/%s.hh' % name
85810454SCurtis.Dunham@arm.com    env.Command(hh_file, Value(flag),
8598232Snate@binkert.org                MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
86010455SCurtis.Dunham@arm.com
86110455SCurtis.Dunham@arm.comenv.Command('debug/flags.cc', Value(debug_flags),
86210455SCurtis.Dunham@arm.com            MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
86310455SCurtis.Dunham@arm.comSource('debug/flags.cc')
8645192Ssaidi@eecs.umich.edu
86511077SCurtis.Dunham@arm.com# version tags
86611330SCurtis.Dunham@arm.comtags = \
86711077SCurtis.Dunham@arm.comenv.Command('sim/tags.cc', None,
86811077SCurtis.Dunham@arm.com            MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET',
86911077SCurtis.Dunham@arm.com                       Transform("VER TAGS")))
87011330SCurtis.Dunham@arm.comenv.AlwaysBuild(tags)
87111077SCurtis.Dunham@arm.com
8727674Snate@binkert.org# Embed python files.  All .py files that have been indicated by a
8735522Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5
8745522Snate@binkert.org# library.  To do that, we compile the file to byte code, marshal the
8757674Snate@binkert.org# byte code, compress it, and then generate a c++ file that
8767674Snate@binkert.org# inserts the result into an array.
8777674Snate@binkert.orgdef embedPyFile(target, source, env):
8787674Snate@binkert.org    def c_str(string):
8797674Snate@binkert.org        if string is None:
8807674Snate@binkert.org            return "0"
8817674Snate@binkert.org        return '"%s"' % string
8827674Snate@binkert.org
8835522Snate@binkert.org    '''Action function to compile a .py into a code object, marshal
8845522Snate@binkert.org    it, compress it, and stick it into an asm file so the code appears
8855522Snate@binkert.org    as just bytes with a label in the data section'''
8865517Snate@binkert.org
8875522Snate@binkert.org    src = file(str(source[0]), 'r').read()
8885517Snate@binkert.org
8896143Snate@binkert.org    pysource = PySource.tnodes[source[0]]
8906727Ssteve.reinhardt@amd.com    compiled = compile(src, pysource.abspath, 'exec')
8915522Snate@binkert.org    marshalled = marshal.dumps(compiled)
8925522Snate@binkert.org    compressed = zlib.compress(marshalled)
8935522Snate@binkert.org    data = compressed
8947674Snate@binkert.org    sym = pysource.symname
8955517Snate@binkert.org
8967673Snate@binkert.org    code = code_formatter()
8977673Snate@binkert.org    code('''\
8987674Snate@binkert.org#include "sim/init.hh"
8997673Snate@binkert.org
9007674Snate@binkert.orgnamespace {
9017674Snate@binkert.org
9028946Sandreas.hansson@arm.comconst uint8_t data_${sym}[] = {
9037674Snate@binkert.org''')
9047674Snate@binkert.org    code.indent()
9057674Snate@binkert.org    step = 16
9065522Snate@binkert.org    for i in xrange(0, len(data), step):
9075522Snate@binkert.org        x = array.array('B', data[i:i+step])
9087674Snate@binkert.org        code(''.join('%d,' % d for d in x))
9097674Snate@binkert.org    code.dedent()
91011308Santhony.gutierrez@amd.com
9117674Snate@binkert.org    code('''};
9127673Snate@binkert.org
9137674Snate@binkert.orgEmbeddedPython embedded_${sym}(
9147674Snate@binkert.org    ${{c_str(pysource.arcname)}},
9157674Snate@binkert.org    ${{c_str(pysource.abspath)}},
9167674Snate@binkert.org    ${{c_str(pysource.modpath)}},
9177674Snate@binkert.org    data_${sym},
9187674Snate@binkert.org    ${{len(data)}},
9197674Snate@binkert.org    ${{len(marshalled)}});
9207674Snate@binkert.org
9217811Ssteve.reinhardt@amd.com} // anonymous namespace
9227674Snate@binkert.org''')
9237673Snate@binkert.org    code.write(str(target[0]))
9245522Snate@binkert.org
9256143Snate@binkert.orgfor source in PySource.all:
92610453SAndrew.Bardsley@arm.com    env.Command(source.cpp, source.tnode,
9277816Ssteve.reinhardt@amd.com                MakeAction(embedPyFile, Transform("EMBED PY")))
92812302Sgabeblack@google.com    Source(source.cpp, tags=source.tags, add_tags='python')
9294382Sbinkertn@umich.edu
9304382Sbinkertn@umich.edu########################################################################
9314382Sbinkertn@umich.edu#
9324382Sbinkertn@umich.edu# Define binaries.  Each different build type (debug, opt, etc.) gets
9334382Sbinkertn@umich.edu# a slightly different build environment.
9344382Sbinkertn@umich.edu#
9354382Sbinkertn@umich.edu
9364382Sbinkertn@umich.edu# List of constructed environments to pass back to SConstruct
93712302Sgabeblack@google.comdate_source = Source('base/date.cc', tags=[])
9384382Sbinkertn@umich.edu
9392655Sstever@eecs.umich.edu# Function to create a new build environment as clone of current
9402655Sstever@eecs.umich.edu# environment 'env' with modified object suffix and optional stripped
9412655Sstever@eecs.umich.edu# binary.  Additional keyword arguments are appended to corresponding
9422655Sstever@eecs.umich.edu# build environment vars.
94312063Sgabeblack@google.comdef makeEnv(env, label, objsfx, strip=False, disable_partial=False, **kwargs):
9445601Snate@binkert.org    # SCons doesn't know to append a library suffix when there is a '.' in the
9455601Snate@binkert.org    # name.  Use '_' instead.
94612222Sgabeblack@google.com    libname = 'gem5_' + label
94712222Sgabeblack@google.com    exename = 'gem5.' + label
94812222Sgabeblack@google.com    secondary_exename = 'm5.' + label
9495522Snate@binkert.org
9505863Snate@binkert.org    new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
9515601Snate@binkert.org    new_env.Label = label
9525601Snate@binkert.org    new_env.Append(**kwargs)
9535601Snate@binkert.org
95412305Sgabeblack@google.com    def make_obj(source, static, extra_deps=None):
95512305Sgabeblack@google.com        '''This function creates a scons node of the requested type, and sets
95612305Sgabeblack@google.com        up any additional dependencies.'''
9576143Snate@binkert.org
9586143Snate@binkert.org        if static:
95912305Sgabeblack@google.com            obj = new_env.StaticObject(source.tnode)
9606143Snate@binkert.org        else:
96112305Sgabeblack@google.com            obj = new_env.SharedObject(source.tnode)
9626143Snate@binkert.org
9636143Snate@binkert.org        if extra_deps:
96412305Sgabeblack@google.com            new_env.Depends(obj, extra_deps)
9656143Snate@binkert.org
9666143Snate@binkert.org        return obj
9676143Snate@binkert.org
96812302Sgabeblack@google.com    lib_sources = Source.all.with_tag('gem5 lib')
96910453SAndrew.Bardsley@arm.com
97011988Sandreas.sandberg@arm.com    # Without Python, leave out all Python content from the library
97111988Sandreas.sandberg@arm.com    # builds.  The option doesn't affect gem5 built as a program
97210453SAndrew.Bardsley@arm.com    if GetOption('without_python'):
97312302Sgabeblack@google.com        lib_sources = lib_sources.without_tag('python')
97410453SAndrew.Bardsley@arm.com
97511983Sgabeblack@google.com    static_objs = []
97611983Sgabeblack@google.com    shared_objs = []
97712302Sgabeblack@google.com
97812302Sgabeblack@google.com    for s in lib_sources.with_tag(Source.ungrouped_tag):
97911983Sgabeblack@google.com        static_objs.append(make_obj(s, True))
98011983Sgabeblack@google.com        shared_objs.append(make_obj(s, False))
98111983Sgabeblack@google.com
98211983Sgabeblack@google.com    partial_objs = []
98311983Sgabeblack@google.com
98412302Sgabeblack@google.com    for group in Source.source_groups:
98512302Sgabeblack@google.com        srcs = lib_sources.with_tag(Source.link_group_tag(group))
98611983Sgabeblack@google.com        if not srcs:
98711983Sgabeblack@google.com            continue
98811983Sgabeblack@google.com
98912063Sgabeblack@google.com        # If partial linking is disabled, add these sources to the build
99012063Sgabeblack@google.com        # directly, and short circuit this loop.
99112063Sgabeblack@google.com        if disable_partial:
99212063Sgabeblack@google.com            for s in srcs:
99312063Sgabeblack@google.com                static_objs.append(make_obj(s, True))
99412063Sgabeblack@google.com                shared_objs.append(make_obj(s, False))
99512063Sgabeblack@google.com            continue
99612063Sgabeblack@google.com
99711983Sgabeblack@google.com        # Set up the static partially linked objects.
99811983Sgabeblack@google.com        source_objs = [ make_obj(s, True) for s in srcs ]
99911983Sgabeblack@google.com        file_name = new_env.subst("${OBJPREFIX}lib${OBJSUFFIX}.partial")
100011983Sgabeblack@google.com        target = File(joinpath(group, file_name))
100111983Sgabeblack@google.com        partial = env.PartialStatic(target=target, source=source_objs)
100211983Sgabeblack@google.com        static_objs.append(partial)
100311983Sgabeblack@google.com
100411983Sgabeblack@google.com        # Set up the shared partially linked objects.
100511983Sgabeblack@google.com        source_objs = [ make_obj(s, False) for s in srcs ]
100611983Sgabeblack@google.com        file_name = new_env.subst("${SHOBJPREFIX}lib${SHOBJSUFFIX}.partial")
100711983Sgabeblack@google.com        target = File(joinpath(group, file_name))
100811983Sgabeblack@google.com        partial = env.PartialShared(target=target, source=source_objs)
100911983Sgabeblack@google.com        shared_objs.append(partial)
10106143Snate@binkert.org
10116143Snate@binkert.org    static_date = make_obj(date_source, static=True, extra_deps=static_objs)
10126143Snate@binkert.org    static_objs.append(static_date)
101310453SAndrew.Bardsley@arm.com
10146143Snate@binkert.org    shared_date = make_obj(date_source, static=False, extra_deps=shared_objs)
10156240Snate@binkert.org    shared_objs.append(shared_date)
10165554Snate@binkert.org
10175522Snate@binkert.org    # First make a library of everything but main() so other programs can
10185522Snate@binkert.org    # link against m5.
10195797Snate@binkert.org    static_lib = new_env.StaticLibrary(libname, static_objs)
10205797Snate@binkert.org    shared_lib = new_env.SharedLibrary(libname, shared_objs)
10215522Snate@binkert.org
10225601Snate@binkert.org    # Now link a stub with main() and the static library.
102312302Sgabeblack@google.com    main_objs = [ make_obj(s, True) for s in Source.all.with_tag('main') ]
10248233Snate@binkert.org
10258235Snate@binkert.org    for test in UnitTest.all:
102612302Sgabeblack@google.com        test_sources = Source.all.with_tag(str(test.target))
10278235Snate@binkert.org        test_objs = [ make_obj(s, static=True) for s in test_sources ]
10289003SAli.Saidi@ARM.com        if test.main:
10299003SAli.Saidi@ARM.com            test_objs += main_objs
103012222Sgabeblack@google.com        path = 'unittest/%s.%s' % (test.target, label)
103110196SCurtis.Dunham@arm.com        new_env.Program(path, test_objs + static_objs)
10328235Snate@binkert.org
10336143Snate@binkert.org    progname = exename
10342655Sstever@eecs.umich.edu    if strip:
10356143Snate@binkert.org        progname += '.unstripped'
10366143Snate@binkert.org
103711985Sgabeblack@google.com    targets = new_env.Program(progname, main_objs + static_objs)
10386143Snate@binkert.org
10396143Snate@binkert.org    if strip:
10404007Ssaidi@eecs.umich.edu        if sys.platform == 'sunos5':
10414596Sbinkertn@umich.edu            cmd = 'cp $SOURCE $TARGET; strip $TARGET'
10424007Ssaidi@eecs.umich.edu        else:
10434596Sbinkertn@umich.edu            cmd = 'strip $SOURCE -o $TARGET'
10447756SAli.Saidi@ARM.com        targets = new_env.Command(exename, progname,
10457816Ssteve.reinhardt@amd.com                    MakeAction(cmd, Transform("STRIP")))
10468334Snate@binkert.org
10478334Snate@binkert.org    new_env.Command(secondary_exename, exename,
10488334Snate@binkert.org            MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
10498334Snate@binkert.org
10505601Snate@binkert.org    new_env.M5Binary = targets[0]
105111993Sgabeblack@google.com
105211993Sgabeblack@google.com    # Set up regression tests.
105311993Sgabeblack@google.com    SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'),
105412223Sgabeblack@google.com               variant_dir=Dir('tests').Dir(new_env.Label),
105511993Sgabeblack@google.com               exports={ 'env' : new_env }, duplicate=False)
10562655Sstever@eecs.umich.edu
10579225Sandreas.hansson@arm.com# Start out with the compiler flags common to all compilers,
10589225Sandreas.hansson@arm.com# i.e. they all use -g for opt and -g -pg for prof
10599226Sandreas.hansson@arm.comccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],
10609226Sandreas.hansson@arm.com           'perf' : ['-g']}
10619225Sandreas.hansson@arm.com
10629226Sandreas.hansson@arm.com# Start out with the linker flags common to all linkers, i.e. -pg for
10639226Sandreas.hansson@arm.com# prof, and -lprofiler for perf. The -lprofile flag is surrounded by
10649226Sandreas.hansson@arm.com# no-as-needed and as-needed as the binutils linker is too clever and
10659226Sandreas.hansson@arm.com# simply doesn't link to the library otherwise.
10669226Sandreas.hansson@arm.comldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'],
10679226Sandreas.hansson@arm.com           'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']}
10689225Sandreas.hansson@arm.com
10699227Sandreas.hansson@arm.com# For Link Time Optimization, the optimisation flags used to compile
10709227Sandreas.hansson@arm.com# individual files are decoupled from those used at link time
10719227Sandreas.hansson@arm.com# (i.e. you can compile with -O3 and perform LTO with -O0), so we need
10729227Sandreas.hansson@arm.com# to also update the linker flags based on the target.
10738946Sandreas.hansson@arm.comif env['GCC']:
10743918Ssaidi@eecs.umich.edu    if sys.platform == 'sunos5':
10759225Sandreas.hansson@arm.com        ccflags['debug'] += ['-gstabs+']
10763918Ssaidi@eecs.umich.edu    else:
10779225Sandreas.hansson@arm.com        ccflags['debug'] += ['-ggdb3']
10789225Sandreas.hansson@arm.com    ldflags['debug'] += ['-O0']
10799227Sandreas.hansson@arm.com    # opt, fast, prof and perf all share the same cc flags, also add
10809227Sandreas.hansson@arm.com    # the optimization to the ldflags as LTO defers the optimization
10819227Sandreas.hansson@arm.com    # to link time
10829226Sandreas.hansson@arm.com    for target in ['opt', 'fast', 'prof', 'perf']:
10839225Sandreas.hansson@arm.com        ccflags[target] += ['-O3']
10849227Sandreas.hansson@arm.com        ldflags[target] += ['-O3']
10859227Sandreas.hansson@arm.com
10869227Sandreas.hansson@arm.com    ccflags['fast'] += env['LTO_CCFLAGS']
10879227Sandreas.hansson@arm.com    ldflags['fast'] += env['LTO_LDFLAGS']
10888946Sandreas.hansson@arm.comelif env['CLANG']:
10899225Sandreas.hansson@arm.com    ccflags['debug'] += ['-g', '-O0']
10909226Sandreas.hansson@arm.com    # opt, fast, prof and perf all share the same cc flags
10919226Sandreas.hansson@arm.com    for target in ['opt', 'fast', 'prof', 'perf']:
10929226Sandreas.hansson@arm.com        ccflags[target] += ['-O3']
10933515Ssaidi@eecs.umich.eduelse:
10943918Ssaidi@eecs.umich.edu    print 'Unknown compiler, please fix compiler options'
10954762Snate@binkert.org    Exit(1)
10963515Ssaidi@eecs.umich.edu
10978881Smarc.orr@gmail.com
10988881Smarc.orr@gmail.com# To speed things up, we only instantiate the build environments we
10998881Smarc.orr@gmail.com# need.  We try to identify the needed environment for each target; if
11008881Smarc.orr@gmail.com# we can't, we fall back on instantiating all the environments just to
11018881Smarc.orr@gmail.com# be safe.
11029226Sandreas.hansson@arm.comtarget_types = ['debug', 'opt', 'fast', 'prof', 'perf']
11039226Sandreas.hansson@arm.comobj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof',
11049226Sandreas.hansson@arm.com              'gpo' : 'perf'}
11058881Smarc.orr@gmail.com
11068881Smarc.orr@gmail.comdef identifyTarget(t):
11078881Smarc.orr@gmail.com    ext = t.split('.')[-1]
11088881Smarc.orr@gmail.com    if ext in target_types:
11098881Smarc.orr@gmail.com        return ext
11108881Smarc.orr@gmail.com    if obj2target.has_key(ext):
11118881Smarc.orr@gmail.com        return obj2target[ext]
11128881Smarc.orr@gmail.com    match = re.search(r'/tests/([^/]+)/', t)
11138881Smarc.orr@gmail.com    if match and match.group(1) in target_types:
11148881Smarc.orr@gmail.com        return match.group(1)
11158881Smarc.orr@gmail.com    return 'all'
11168881Smarc.orr@gmail.com
11178881Smarc.orr@gmail.comneeded_envs = [identifyTarget(target) for target in BUILD_TARGETS]
11188881Smarc.orr@gmail.comif 'all' in needed_envs:
11198881Smarc.orr@gmail.com    needed_envs += target_types
11208881Smarc.orr@gmail.com
112112222Sgabeblack@google.com# Debug binary
112212222Sgabeblack@google.comif 'debug' in needed_envs:
112312222Sgabeblack@google.com    makeEnv(env, 'debug', '.do',
112412222Sgabeblack@google.com            CCFLAGS = Split(ccflags['debug']),
112512222Sgabeblack@google.com            CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
112612222Sgabeblack@google.com            LINKFLAGS = Split(ldflags['debug']))
1127955SN/A
112812222Sgabeblack@google.com# Optimized binary
112912222Sgabeblack@google.comif 'opt' in needed_envs:
113012222Sgabeblack@google.com    makeEnv(env, 'opt', '.o',
113112222Sgabeblack@google.com            CCFLAGS = Split(ccflags['opt']),
113212222Sgabeblack@google.com            CPPDEFINES = ['TRACING_ON=1'],
113312222Sgabeblack@google.com            LINKFLAGS = Split(ldflags['opt']))
1134955SN/A
113512222Sgabeblack@google.com# "Fast" binary
113612222Sgabeblack@google.comif 'fast' in needed_envs:
113712222Sgabeblack@google.com    disable_partial = \
113812222Sgabeblack@google.com            env.get('BROKEN_INCREMENTAL_LTO', False) and \
113912222Sgabeblack@google.com            GetOption('force_lto')
114012222Sgabeblack@google.com    makeEnv(env, 'fast', '.fo', strip = True,
114112222Sgabeblack@google.com            CCFLAGS = Split(ccflags['fast']),
114212222Sgabeblack@google.com            CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
114312222Sgabeblack@google.com            LINKFLAGS = Split(ldflags['fast']),
114412222Sgabeblack@google.com            disable_partial=disable_partial)
11451869SN/A
114612222Sgabeblack@google.com# Profiled binary using gprof
114712222Sgabeblack@google.comif 'prof' in needed_envs:
114812222Sgabeblack@google.com    makeEnv(env, 'prof', '.po',
114912222Sgabeblack@google.com            CCFLAGS = Split(ccflags['prof']),
115012222Sgabeblack@google.com            CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
115112222Sgabeblack@google.com            LINKFLAGS = Split(ldflags['prof']))
11529226Sandreas.hansson@arm.com
115312222Sgabeblack@google.com# Profiled binary using google-pprof
115412222Sgabeblack@google.comif 'perf' in needed_envs:
115512222Sgabeblack@google.com    makeEnv(env, 'perf', '.gpo',
115612222Sgabeblack@google.com            CCFLAGS = Split(ccflags['perf']),
115712222Sgabeblack@google.com            CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
115812222Sgabeblack@google.com            LINKFLAGS = Split(ldflags['perf']))
1159