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