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
458334Snate@binkert.orgfrom gem5_scons import Transform
46955SN/A
47955SN/A# This file defines how to build a particular configuration of gem5
484202Sbinkertn@umich.edu# based on variable settings in the 'env' build environment.
49955SN/A
504382Sbinkertn@umich.eduImport('*')
514382Sbinkertn@umich.edu
524382Sbinkertn@umich.edu# Children need to see the environment
536654Snate@binkert.orgExport('env')
545517Snate@binkert.org
558614Sgblack@eecs.umich.edubuild_env = [(opt, env[opt]) for opt in export_vars]
567674Snate@binkert.org
576143Snate@binkert.orgfrom m5.util import code_formatter, compareVersions
586143Snate@binkert.org
596143Snate@binkert.org########################################################################
608233Snate@binkert.org# Code for adding source files of various types
618233Snate@binkert.org#
628233Snate@binkert.org# When specifying a source file of some type, a set of tags can be
638233Snate@binkert.org# specified for that file.
648233Snate@binkert.org
658334Snate@binkert.orgclass SourceList(list):
668334Snate@binkert.org    def with_tags_that(self, predicate):
6710453SAndrew.Bardsley@arm.com        '''Return a list of sources with tags that satisfy a predicate.'''
6810453SAndrew.Bardsley@arm.com        def match(source):
698233Snate@binkert.org            return predicate(source.tags)
708233Snate@binkert.org        return SourceList(filter(match, self))
718233Snate@binkert.org
728233Snate@binkert.org    def with_any_tags(self, *tags):
738233Snate@binkert.org        '''Return a list of sources with any of the supplied tags.'''
748233Snate@binkert.org        return self.with_tags_that(lambda stags: len(set(tags) & stags) > 0)
7511983Sgabeblack@google.com
7611983Sgabeblack@google.com    def with_all_tags(self, *tags):
7711983Sgabeblack@google.com        '''Return a list of sources with all of the supplied tags.'''
7811983Sgabeblack@google.com        return self.with_tags_that(lambda stags: set(tags) <= stags)
7911983Sgabeblack@google.com
8011983Sgabeblack@google.com    def with_tag(self, tag):
8111983Sgabeblack@google.com        '''Return a list of sources with the supplied tag.'''
8211983Sgabeblack@google.com        return self.with_tags_that(lambda stags: tag in stags)
8311983Sgabeblack@google.com
8411983Sgabeblack@google.com    def without_tags(self, *tags):
8511983Sgabeblack@google.com        '''Return a list of sources without any of the supplied tags.'''
866143Snate@binkert.org        return self.with_tags_that(lambda stags: len(set(tags) & stags) == 0)
878233Snate@binkert.org
888233Snate@binkert.org    def without_tag(self, tag):
898233Snate@binkert.org        '''Return a list of sources with the supplied tag.'''
906143Snate@binkert.org        return self.with_tags_that(lambda stags: tag not in stags)
916143Snate@binkert.org
926143Snate@binkert.orgclass SourceMeta(type):
9311308Santhony.gutierrez@amd.com    '''Meta class for source files that keeps track of all files of a
948233Snate@binkert.org    particular type.'''
958233Snate@binkert.org    def __init__(cls, name, bases, dict):
968233Snate@binkert.org        super(SourceMeta, cls).__init__(name, bases, dict)
9711983Sgabeblack@google.com        cls.all = SourceList()
9811983Sgabeblack@google.com
994762Snate@binkert.orgclass SourceFile(object):
1006143Snate@binkert.org    '''Base object that encapsulates the notion of a source file.
1018233Snate@binkert.org    This includes, the source node, target node, various manipulations
1028233Snate@binkert.org    of those.  A source file also specifies a set of tags which
1038233Snate@binkert.org    describing arbitrary properties of the source file.'''
1048233Snate@binkert.org    __metaclass__ = SourceMeta
1058233Snate@binkert.org
1066143Snate@binkert.org    static_objs = {}
1078233Snate@binkert.org    shared_objs = {}
1088233Snate@binkert.org
1098233Snate@binkert.org    def __init__(self, source, tags=None, add_tags=None):
1108233Snate@binkert.org        if tags is None:
1116143Snate@binkert.org            tags='gem5 lib'
1126143Snate@binkert.org        if isinstance(tags, basestring):
1136143Snate@binkert.org            tags = set([tags])
1146143Snate@binkert.org        if not isinstance(tags, set):
1156143Snate@binkert.org            tags = set(tags)
1166143Snate@binkert.org        self.tags = tags
1176143Snate@binkert.org
1186143Snate@binkert.org        if add_tags:
1196143Snate@binkert.org            if isinstance(add_tags, basestring):
1207065Snate@binkert.org                add_tags = set([add_tags])
1216143Snate@binkert.org            if not isinstance(add_tags, set):
1228233Snate@binkert.org                add_tags = set(add_tags)
1238233Snate@binkert.org            self.tags |= add_tags
1248233Snate@binkert.org
1258233Snate@binkert.org        tnode = source
1268233Snate@binkert.org        if not isinstance(source, SCons.Node.FS.File):
1278233Snate@binkert.org            tnode = File(source)
1288233Snate@binkert.org
1298233Snate@binkert.org        self.tnode = tnode
1308233Snate@binkert.org        self.snode = tnode.srcnode()
1318233Snate@binkert.org
1328233Snate@binkert.org        for base in type(self).__mro__:
1338233Snate@binkert.org            if issubclass(base, SourceFile):
1348233Snate@binkert.org                base.all.append(self)
1358233Snate@binkert.org
1368233Snate@binkert.org    def static(self, env):
1378233Snate@binkert.org        key = (self.tnode, env['OBJSUFFIX'])
1388233Snate@binkert.org        if not key in self.static_objs:
1398233Snate@binkert.org            self.static_objs[key] = env.StaticObject(self.tnode)
1408233Snate@binkert.org        return self.static_objs[key]
1418233Snate@binkert.org
1428233Snate@binkert.org    def shared(self, env):
1438233Snate@binkert.org        key = (self.tnode, env['OBJSUFFIX'])
1448233Snate@binkert.org        if not key in self.shared_objs:
1458233Snate@binkert.org            self.shared_objs[key] = env.SharedObject(self.tnode)
1468233Snate@binkert.org        return self.shared_objs[key]
1478233Snate@binkert.org
1488233Snate@binkert.org    @property
1498233Snate@binkert.org    def filename(self):
1508233Snate@binkert.org        return str(self.tnode)
1518233Snate@binkert.org
1528233Snate@binkert.org    @property
1536143Snate@binkert.org    def dirname(self):
1546143Snate@binkert.org        return dirname(self.filename)
1556143Snate@binkert.org
1566143Snate@binkert.org    @property
1576143Snate@binkert.org    def basename(self):
1586143Snate@binkert.org        return basename(self.filename)
1599982Satgutier@umich.edu
16010196SCurtis.Dunham@arm.com    @property
16110196SCurtis.Dunham@arm.com    def extname(self):
16210196SCurtis.Dunham@arm.com        index = self.basename.rfind('.')
16310196SCurtis.Dunham@arm.com        if index <= 0:
16410196SCurtis.Dunham@arm.com            # dot files aren't extensions
16510196SCurtis.Dunham@arm.com            return self.basename, None
16610196SCurtis.Dunham@arm.com
16710196SCurtis.Dunham@arm.com        return self.basename[:index], self.basename[index+1:]
1686143Snate@binkert.org
16911983Sgabeblack@google.com    def __lt__(self, other): return self.filename < other.filename
17011983Sgabeblack@google.com    def __le__(self, other): return self.filename <= other.filename
17111983Sgabeblack@google.com    def __gt__(self, other): return self.filename > other.filename
17211983Sgabeblack@google.com    def __ge__(self, other): return self.filename >= other.filename
17311983Sgabeblack@google.com    def __eq__(self, other): return self.filename == other.filename
17411983Sgabeblack@google.com    def __ne__(self, other): return self.filename != other.filename
17511983Sgabeblack@google.com
17611983Sgabeblack@google.comclass Source(SourceFile):
17711983Sgabeblack@google.com    ungrouped_tag = 'No link group'
1786143Snate@binkert.org    source_groups = set()
17911988Sandreas.sandberg@arm.com
1808233Snate@binkert.org    _current_group_tag = ungrouped_tag
1818233Snate@binkert.org
1826143Snate@binkert.org    @staticmethod
1838945Ssteve.reinhardt@amd.com    def link_group_tag(group):
1846143Snate@binkert.org        return 'link group: %s' % group
18511983Sgabeblack@google.com
18611983Sgabeblack@google.com    @classmethod
1876143Snate@binkert.org    def set_group(cls, group):
1886143Snate@binkert.org        new_tag = Source.link_group_tag(group)
1895522Snate@binkert.org        Source._current_group_tag = new_tag
1906143Snate@binkert.org        Source.source_groups.add(group)
1916143Snate@binkert.org
1926143Snate@binkert.org    def _add_link_group_tag(self):
1939982Satgutier@umich.edu        self.tags.add(Source._current_group_tag)
1948233Snate@binkert.org
1958233Snate@binkert.org    '''Add a c/c++ source file to the build'''
1968233Snate@binkert.org    def __init__(self, source, tags=None, add_tags=None):
1976143Snate@binkert.org        '''specify the source file, and any tags'''
1986143Snate@binkert.org        super(Source, self).__init__(source, tags, add_tags)
1996143Snate@binkert.org        self._add_link_group_tag()
2006143Snate@binkert.org
2015522Snate@binkert.orgclass PySource(SourceFile):
2025522Snate@binkert.org    '''Add a python source file to the named package'''
2035522Snate@binkert.org    invalid_sym_char = re.compile('[^A-z0-9_]')
2045522Snate@binkert.org    modules = {}
2055604Snate@binkert.org    tnodes = {}
2065604Snate@binkert.org    symnames = {}
2076143Snate@binkert.org
2086143Snate@binkert.org    def __init__(self, package, source, tags=None, add_tags=None):
2094762Snate@binkert.org        '''specify the python package, the source file, and any tags'''
2104762Snate@binkert.org        super(PySource, self).__init__(source, tags, add_tags)
2116143Snate@binkert.org
2126727Ssteve.reinhardt@amd.com        modname,ext = self.extname
2136727Ssteve.reinhardt@amd.com        assert ext == 'py'
2146727Ssteve.reinhardt@amd.com
2154762Snate@binkert.org        if package:
2166143Snate@binkert.org            path = package.split('.')
2176143Snate@binkert.org        else:
2186143Snate@binkert.org            path = []
2196143Snate@binkert.org
2206727Ssteve.reinhardt@amd.com        modpath = path[:]
2216143Snate@binkert.org        if modname != '__init__':
2227674Snate@binkert.org            modpath += [ modname ]
2237674Snate@binkert.org        modpath = '.'.join(modpath)
2245604Snate@binkert.org
2256143Snate@binkert.org        arcpath = path + [ self.basename ]
2266143Snate@binkert.org        abspath = self.snode.abspath
2276143Snate@binkert.org        if not exists(abspath):
2284762Snate@binkert.org            abspath = self.tnode.abspath
2296143Snate@binkert.org
2304762Snate@binkert.org        self.package = package
2314762Snate@binkert.org        self.modname = modname
2324762Snate@binkert.org        self.modpath = modpath
2336143Snate@binkert.org        self.arcname = joinpath(*arcpath)
2346143Snate@binkert.org        self.abspath = abspath
2354762Snate@binkert.org        self.compiled = File(self.filename + 'c')
2368233Snate@binkert.org        self.cpp = File(self.filename + '.cc')
2378233Snate@binkert.org        self.symname = PySource.invalid_sym_char.sub('_', modpath)
2388233Snate@binkert.org
2398233Snate@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
2459396Sandreas.hansson@arm.com    it to a list of sim object modules'''
2469396Sandreas.hansson@arm.com
2479396Sandreas.hansson@arm.com    fixed = False
2489396Sandreas.hansson@arm.com    modnames = []
2499396Sandreas.hansson@arm.com
2509396Sandreas.hansson@arm.com    def __init__(self, source, tags=None, add_tags=None):
2519396Sandreas.hansson@arm.com        '''Specify the source file and any tags (automatically in
2529396Sandreas.hansson@arm.com        the m5.objects package)'''
2539396Sandreas.hansson@arm.com        super(SimObject, self).__init__('m5.objects', source, tags, add_tags)
2549396Sandreas.hansson@arm.com        if self.fixed:
2559396Sandreas.hansson@arm.com            raise AttributeError, "Too late to call SimObject now."
2569396Sandreas.hansson@arm.com
2579396Sandreas.hansson@arm.com        bisect.insort_right(SimObject.modnames, self.modname)
2589930Sandreas.hansson@arm.com
2599930Sandreas.hansson@arm.comclass ProtoBuf(SourceFile):
2609396Sandreas.hansson@arm.com    '''Add a Protocol Buffer to build'''
2618235Snate@binkert.org
2628235Snate@binkert.org    def __init__(self, source, tags=None, add_tags=None):
2636143Snate@binkert.org        '''Specify the source file, and any tags'''
2648235Snate@binkert.org        super(ProtoBuf, self).__init__(source, tags, add_tags)
2659003SAli.Saidi@ARM.com
2668235Snate@binkert.org        # Get the file name and the extension
2678235Snate@binkert.org        modname,ext = self.extname
2688235Snate@binkert.org        assert ext == 'proto'
2698235Snate@binkert.org
2708235Snate@binkert.org        # Currently, we stick to generating the C++ headers, so we
2718235Snate@binkert.org        # only need to track the source and header.
2728235Snate@binkert.org        self.cc_file = File(modname + '.pb.cc')
2738235Snate@binkert.org        self.hh_file = File(modname + '.pb.h')
2748235Snate@binkert.org
2758235Snate@binkert.orgclass UnitTest(object):
2768235Snate@binkert.org    '''Create a UnitTest'''
2778235Snate@binkert.org
2788235Snate@binkert.org    all = []
2798235Snate@binkert.org    def __init__(self, target, *sources, **kwargs):
2809003SAli.Saidi@ARM.com        '''Specify the target name and any sources.  Sources that are
2818235Snate@binkert.org        not SourceFiles are evalued with Source().  All files are
2825584Snate@binkert.org        tagged with the name of the UnitTest target.'''
2834382Sbinkertn@umich.edu
2844202Sbinkertn@umich.edu        srcs = SourceList()
2854382Sbinkertn@umich.edu        for src in sources:
2864382Sbinkertn@umich.edu            if not isinstance(src, SourceFile):
2879396Sandreas.hansson@arm.com                src = Source(src, tags=str(target))
2885584Snate@binkert.org            srcs.append(src)
2894382Sbinkertn@umich.edu
2904382Sbinkertn@umich.edu        self.sources = srcs
2914382Sbinkertn@umich.edu        self.target = target
2928232Snate@binkert.org        self.main = kwargs.get('main', False)
2935192Ssaidi@eecs.umich.edu        self.all.append(self)
2948232Snate@binkert.org
2958232Snate@binkert.orgclass GTest(UnitTest):
2968232Snate@binkert.org    '''Create a unit test based on the google test framework.'''
2975192Ssaidi@eecs.umich.edu
2988232Snate@binkert.org    all = []
2995192Ssaidi@eecs.umich.edu    def __init__(self, *args, **kwargs):
3005799Snate@binkert.org        super(GTest, self).__init__(*args, **kwargs)
3018232Snate@binkert.org        self.dir = Dir('.')
3025192Ssaidi@eecs.umich.edu
3035192Ssaidi@eecs.umich.edu# Children should have access
3045192Ssaidi@eecs.umich.eduExport('Source')
3058232Snate@binkert.orgExport('PySource')
3065192Ssaidi@eecs.umich.eduExport('SimObject')
3078232Snate@binkert.orgExport('ProtoBuf')
3085192Ssaidi@eecs.umich.eduExport('UnitTest')
3095192Ssaidi@eecs.umich.eduExport('GTest')
3105192Ssaidi@eecs.umich.edu
3115192Ssaidi@eecs.umich.edu########################################################################
3124382Sbinkertn@umich.edu#
3134382Sbinkertn@umich.edu# Debug Flags
3144382Sbinkertn@umich.edu#
3152667Sstever@eecs.umich.edudebug_flags = {}
3162667Sstever@eecs.umich.edudef DebugFlag(name, desc=None):
3172667Sstever@eecs.umich.edu    if name in debug_flags:
3182667Sstever@eecs.umich.edu        raise AttributeError, "Flag %s already specified" % name
3192667Sstever@eecs.umich.edu    debug_flags[name] = (name, (), desc)
3202667Sstever@eecs.umich.edu
3215742Snate@binkert.orgdef CompoundFlag(name, flags, desc=None):
3225742Snate@binkert.org    if name in debug_flags:
3235742Snate@binkert.org        raise AttributeError, "Flag %s already specified" % name
3245793Snate@binkert.org
3258334Snate@binkert.org    compound = tuple(flags)
3265793Snate@binkert.org    debug_flags[name] = (name, compound, desc)
3275793Snate@binkert.org
3285793Snate@binkert.orgExport('DebugFlag')
3294382Sbinkertn@umich.eduExport('CompoundFlag')
3304762Snate@binkert.org
3315344Sstever@gmail.com########################################################################
3324382Sbinkertn@umich.edu#
3335341Sstever@gmail.com# Set some compiler variables
3345742Snate@binkert.org#
3355742Snate@binkert.org
3365742Snate@binkert.org# Include file paths are rooted in this directory.  SCons will
3375742Snate@binkert.org# automatically expand '.' to refer to both the source directory and
3385742Snate@binkert.org# the corresponding build directory to pick up generated include
3394762Snate@binkert.org# files.
3405742Snate@binkert.orgenv.Append(CPPPATH=Dir('.'))
3415742Snate@binkert.org
34211984Sgabeblack@google.comfor extra_dir in extras_dir_list:
3437722Sgblack@eecs.umich.edu    env.Append(CPPPATH=Dir(extra_dir))
3445742Snate@binkert.org
3455742Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212
3465742Snate@binkert.org# Scons bug id: 2006 gem5 Bug id: 308
3479930Sandreas.hansson@arm.comfor root, dirs, files in os.walk(base_dir, topdown=True):
3489930Sandreas.hansson@arm.com    Dir(root[len(base_dir) + 1:])
3499930Sandreas.hansson@arm.com
3509930Sandreas.hansson@arm.com########################################################################
3519930Sandreas.hansson@arm.com#
3525742Snate@binkert.org# Walk the tree and execute all SConscripts in subdirectories
3538242Sbradley.danofsky@amd.com#
3548242Sbradley.danofsky@amd.com
3558242Sbradley.danofsky@amd.comhere = Dir('.').srcnode().abspath
3568242Sbradley.danofsky@amd.comfor root, dirs, files in os.walk(base_dir, topdown=True):
3575341Sstever@gmail.com    if root == here:
3585742Snate@binkert.org        # we don't want to recurse back into this SConscript
3597722Sgblack@eecs.umich.edu        continue
3604773Snate@binkert.org
3616108Snate@binkert.org    if 'SConscript' in files:
3621858SN/A        build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:])
3631085SN/A        Source.set_group(build_dir)
3646658Snate@binkert.org        SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
3656658Snate@binkert.org
3667673Snate@binkert.orgfor extra_dir in extras_dir_list:
3676658Snate@binkert.org    prefix_len = len(dirname(extra_dir)) + 1
3686658Snate@binkert.org
36911308Santhony.gutierrez@amd.com    # Also add the corresponding build directory to pick up generated
3706658Snate@binkert.org    # include files.
37111308Santhony.gutierrez@amd.com    env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:])))
3726658Snate@binkert.org
3736658Snate@binkert.org    for root, dirs, files in os.walk(extra_dir, topdown=True):
3747673Snate@binkert.org        # if build lives in the extras directory, don't walk down it
3757673Snate@binkert.org        if 'build' in dirs:
3767673Snate@binkert.org            dirs.remove('build')
3777673Snate@binkert.org
3787673Snate@binkert.org        if 'SConscript' in files:
3797673Snate@binkert.org            build_dir = joinpath(env['BUILDDIR'], root[prefix_len:])
3807673Snate@binkert.org            SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
38110467Sandreas.hansson@arm.com
3826658Snate@binkert.orgfor opt in export_vars:
3837673Snate@binkert.org    env.ConfigFile(opt)
38410467Sandreas.hansson@arm.com
38510467Sandreas.hansson@arm.comdef makeTheISA(source, target, env):
38610467Sandreas.hansson@arm.com    isas = [ src.get_contents() for src in source ]
38710467Sandreas.hansson@arm.com    target_isa = env['TARGET_ISA']
38810467Sandreas.hansson@arm.com    def define(isa):
38910467Sandreas.hansson@arm.com        return isa.upper() + '_ISA'
39010467Sandreas.hansson@arm.com
39110467Sandreas.hansson@arm.com    def namespace(isa):
39210467Sandreas.hansson@arm.com        return isa[0].upper() + isa[1:].lower() + 'ISA'
39310467Sandreas.hansson@arm.com
39410467Sandreas.hansson@arm.com
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
4009048SAli.Saidi@ARM.com''')
4017673Snate@binkert.org
4027673Snate@binkert.org    # create defines for the preprocessing and compile-time determination
4037673Snate@binkert.org    for i,isa in enumerate(isas):
4047673Snate@binkert.org        code('#define $0 $1', define(isa), i + 1)
4056658Snate@binkert.org    code()
4067756SAli.Saidi@ARM.com
4077816Ssteve.reinhardt@amd.com    # create an enum for any run-time determination of the ISA, we
4086658Snate@binkert.org    # reuse the same name as the namespaces
40911308Santhony.gutierrez@amd.com    code('enum class Arch {')
41011308Santhony.gutierrez@amd.com    for i,isa in enumerate(isas):
41111308Santhony.gutierrez@amd.com        if i + 1 == len(isas):
41211308Santhony.gutierrez@amd.com            code('  $0 = $1', namespace(isa), define(isa))
41311308Santhony.gutierrez@amd.com        else:
41411308Santhony.gutierrez@amd.com            code('  $0 = $1,', namespace(isa), define(isa))
41511308Santhony.gutierrez@amd.com    code('};')
41611308Santhony.gutierrez@amd.com
41711308Santhony.gutierrez@amd.com    code('''
41811308Santhony.gutierrez@amd.com
41911308Santhony.gutierrez@amd.com#define THE_ISA ${{define(target_isa)}}
42011308Santhony.gutierrez@amd.com#define TheISA ${{namespace(target_isa)}}
42111308Santhony.gutierrez@amd.com#define THE_ISA_STR "${{target_isa}}"
42211308Santhony.gutierrez@amd.com
42311308Santhony.gutierrez@amd.com#endif // __CONFIG_THE_ISA_HH__''')
42411308Santhony.gutierrez@amd.com
42511308Santhony.gutierrez@amd.com    code.write(str(target[0]))
42611308Santhony.gutierrez@amd.com
42711308Santhony.gutierrez@amd.comenv.Command('config/the_isa.hh', map(Value, all_isa_list),
42811308Santhony.gutierrez@amd.com            MakeAction(makeTheISA, Transform("CFG ISA", 0)))
42911308Santhony.gutierrez@amd.com
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
4544382Sbinkertn@umich.edu    code('enum class GPUArch {')
4554382Sbinkertn@umich.edu    for i,isa in enumerate(isas):
4564762Snate@binkert.org        if i + 1 == len(isas):
4574762Snate@binkert.org            code('  $0 = $1', namespace(isa), define(isa))
4584762Snate@binkert.org        else:
4596654Snate@binkert.org            code('  $0 = $1,', namespace(isa), define(isa))
4606654Snate@binkert.org    code('};')
4615517Snate@binkert.org
4625517Snate@binkert.org    code('''
4635517Snate@binkert.org
4645517Snate@binkert.org#define THE_GPU_ISA ${{define(target_gpu_isa)}}
4655517Snate@binkert.org#define TheGpuISA ${{namespace(target_gpu_isa)}}
4665517Snate@binkert.org#define THE_GPU_ISA_STR "${{target_gpu_isa}}"
4675517Snate@binkert.org
4685517Snate@binkert.org#endif // __CONFIG_THE_GPU_ISA_HH__''')
4695517Snate@binkert.org
4705517Snate@binkert.org    code.write(str(target[0]))
4715517Snate@binkert.org
4725517Snate@binkert.orgenv.Command('config/the_gpu_isa.hh', map(Value, all_gpu_isa_list),
4735517Snate@binkert.org            MakeAction(makeTheGPUISA, Transform("CFG ISA", 0)))
4745517Snate@binkert.org
4755517Snate@binkert.org########################################################################
4765517Snate@binkert.org#
4775517Snate@binkert.org# Prevent any SimObjects from being added after this point, they
4786654Snate@binkert.org# should all have been added in the SConscripts above
4795517Snate@binkert.org#
4805517Snate@binkert.orgSimObject.fixed = True
4815517Snate@binkert.org
4825517Snate@binkert.orgclass DictImporter(object):
4835517Snate@binkert.org    '''This importer takes a dictionary of arbitrary module names that
48411802Sandreas.sandberg@arm.com    map to arbitrary filenames.'''
4855517Snate@binkert.org    def __init__(self, modules):
4865517Snate@binkert.org        self.modules = modules
4876143Snate@binkert.org        self.installed = set()
4886654Snate@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):
4995517Snate@binkert.org        if fullname == 'm5.defines':
5005517Snate@binkert.org            return self
5015517Snate@binkert.org
5025517Snate@binkert.org        if fullname == 'm5.objects':
5036654Snate@binkert.org            return self
5046654Snate@binkert.org
5055517Snate@binkert.org        if fullname.startswith('_m5'):
5065517Snate@binkert.org            return None
5076143Snate@binkert.org
5086143Snate@binkert.org        source = self.modules.get(fullname, None)
5096143Snate@binkert.org        if source is not None and fullname.startswith('m5.objects'):
5106727Ssteve.reinhardt@amd.com            return self
5115517Snate@binkert.org
5126727Ssteve.reinhardt@amd.com        return None
5135517Snate@binkert.org
5145517Snate@binkert.org    def load_module(self, fullname):
5155517Snate@binkert.org        mod = imp.new_module(fullname)
5166654Snate@binkert.org        sys.modules[fullname] = mod
5176654Snate@binkert.org        self.installed.add(fullname)
5187673Snate@binkert.org
5196654Snate@binkert.org        mod.__loader__ = self
5206654Snate@binkert.org        if fullname == 'm5.objects':
5216654Snate@binkert.org            mod.__path__ = fullname.split('.')
5226654Snate@binkert.org            return mod
5235517Snate@binkert.org
5245517Snate@binkert.org        if fullname == 'm5.defines':
5255517Snate@binkert.org            mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env)
5266143Snate@binkert.org            return mod
5275517Snate@binkert.org
5284762Snate@binkert.org        source = self.modules[fullname]
5295517Snate@binkert.org        if source.modname == '__init__':
5305517Snate@binkert.org            mod.__path__ = source.modpath
5316143Snate@binkert.org        mod.__file__ = source.abspath
5326143Snate@binkert.org
5335517Snate@binkert.org        exec file(source.abspath, 'r') in mod.__dict__
5345517Snate@binkert.org
5355517Snate@binkert.org        return mod
5365517Snate@binkert.org
5375517Snate@binkert.orgimport m5.SimObject
5385517Snate@binkert.orgimport m5.params
5395517Snate@binkert.orgfrom m5.util import code_formatter
5405517Snate@binkert.org
5415517Snate@binkert.orgm5.SimObject.clear()
5426143Snate@binkert.orgm5.params.clear()
5435517Snate@binkert.org
5446654Snate@binkert.org# install the python importer so we can grab stuff from the source
5456654Snate@binkert.org# tree itself.  We can't have SimObjects added after this point or
5466654Snate@binkert.org# else we won't know about them for the rest of the stuff.
5476654Snate@binkert.orgimporter = DictImporter(PySource.modules)
5486654Snate@binkert.orgsys.meta_path[0:0] = [ importer ]
5496654Snate@binkert.org
5504762Snate@binkert.org# import all sim objects so we can populate the all_objects list
5514762Snate@binkert.org# make sure that we're working with a list, then let's sort it
5524762Snate@binkert.orgfor modname in SimObject.modnames:
5534762Snate@binkert.org    exec('from m5.objects import %s' % modname)
5544762Snate@binkert.org
5557675Snate@binkert.org# we need to unload all of the currently imported modules so that they
55610584Sandreas.hansson@arm.com# will be re-imported the next time the sconscript is run
5574762Snate@binkert.orgimporter.unload()
5584762Snate@binkert.orgsys.meta_path.remove(importer)
5594762Snate@binkert.org
5604762Snate@binkert.orgsim_objects = m5.SimObject.allClasses
5614382Sbinkertn@umich.eduall_enums = m5.params.allEnums
5624382Sbinkertn@umich.edu
5635517Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()):
5646654Snate@binkert.org    for param in obj._params.local.values():
5655517Snate@binkert.org        # load the ptype attribute now because it depends on the
5668126Sgblack@eecs.umich.edu        # current version of SimObject.allClasses, but when scons
5676654Snate@binkert.org        # actually uses the value, all versions of
5687673Snate@binkert.org        # SimObject.allClasses will have been loaded
5696654Snate@binkert.org        param.ptype
57011802Sandreas.sandberg@arm.com
5716654Snate@binkert.org########################################################################
5726654Snate@binkert.org#
5736654Snate@binkert.org# calculate extra dependencies
5746654Snate@binkert.org#
57511802Sandreas.sandberg@arm.commodule_depends = ["m5", "m5.SimObject", "m5.params"]
5766669Snate@binkert.orgdepends = [ PySource.modules[dep].snode for dep in module_depends ]
57711802Sandreas.sandberg@arm.comdepends.sort(key = lambda x: x.name)
5786669Snate@binkert.org
5796669Snate@binkert.org########################################################################
5806669Snate@binkert.org#
5816669Snate@binkert.org# Commands for the basic automatically generated python files
5826654Snate@binkert.org#
5837673Snate@binkert.org
5845517Snate@binkert.org# Generate Python file containing a dict specifying the current
5858126Sgblack@eecs.umich.edu# buildEnv flags.
5865798Snate@binkert.orgdef makeDefinesPyFile(target, source, env):
5877756SAli.Saidi@ARM.com    build_env = source[0].get_contents()
5887816Ssteve.reinhardt@amd.com
5895798Snate@binkert.org    code = code_formatter()
5905798Snate@binkert.org    code("""
5915517Snate@binkert.orgimport _m5.core
5925517Snate@binkert.orgimport m5.util
5937673Snate@binkert.org
5945517Snate@binkert.orgbuildEnv = m5.util.SmartDict($build_env)
5955517Snate@binkert.org
5967673Snate@binkert.orgcompileDate = _m5.core.compileDate
5977673Snate@binkert.org_globals = globals()
5985517Snate@binkert.orgfor key,val in _m5.core.__dict__.iteritems():
5995798Snate@binkert.org    if key.startswith('flag_'):
6005798Snate@binkert.org        flag = key[5:]
6018333Snate@binkert.org        _globals[flag] = val
6027816Ssteve.reinhardt@amd.comdel _globals
6035798Snate@binkert.org""")
6045798Snate@binkert.org    code.write(target[0].abspath)
6054762Snate@binkert.org
6064762Snate@binkert.orgdefines_info = Value(build_env)
6074762Snate@binkert.org# Generate a file with all of the compile options in it
6084762Snate@binkert.orgenv.Command('python/m5/defines.py', defines_info,
6094762Snate@binkert.org            MakeAction(makeDefinesPyFile, Transform("DEFINES", 0)))
6108596Ssteve.reinhardt@amd.comPySource('m5', 'python/m5/defines.py')
6115517Snate@binkert.org
6125517Snate@binkert.org# Generate python file containing info about the M5 source code
6135517Snate@binkert.orgdef makeInfoPyFile(target, source, env):
6145517Snate@binkert.org    code = code_formatter()
6155517Snate@binkert.org    for src in source:
6167673Snate@binkert.org        data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
6178596Ssteve.reinhardt@amd.com        code('$src = ${{repr(data)}}')
6187673Snate@binkert.org    code.write(str(target[0]))
6195517Snate@binkert.org
62010458Sandreas.hansson@arm.com# Generate a file that wraps the basic top level files
62110458Sandreas.hansson@arm.comenv.Command('python/m5/info.py',
62210458Sandreas.hansson@arm.com            [ '#/COPYING', '#/LICENSE', '#/README', ],
62310458Sandreas.hansson@arm.com            MakeAction(makeInfoPyFile, Transform("INFO")))
62410458Sandreas.hansson@arm.comPySource('m5', 'python/m5/info.py')
62510458Sandreas.hansson@arm.com
62610458Sandreas.hansson@arm.com########################################################################
62710458Sandreas.hansson@arm.com#
62810458Sandreas.hansson@arm.com# Create all of the SimObject param headers and enum headers
62910458Sandreas.hansson@arm.com#
63010458Sandreas.hansson@arm.com
63110458Sandreas.hansson@arm.comdef createSimObjectParamStruct(target, source, env):
6325517Snate@binkert.org    assert len(target) == 1 and len(source) == 1
6335517Snate@binkert.org
6345517Snate@binkert.org    name = source[0].get_text_contents()
6355517Snate@binkert.org    obj = sim_objects[name]
6365517Snate@binkert.org
6375517Snate@binkert.org    code = code_formatter()
6387673Snate@binkert.org    obj.cxx_param_decl(code)
6397673Snate@binkert.org    code.write(target[0].abspath)
64011988Sandreas.sandberg@arm.com
64111988Sandreas.sandberg@arm.comdef createSimObjectCxxConfig(is_header):
6427673Snate@binkert.org    def body(target, source, env):
6435517Snate@binkert.org        assert len(target) == 1 and len(source) == 1
6448596Ssteve.reinhardt@amd.com
6455517Snate@binkert.org        name = str(source[0].get_contents())
6465517Snate@binkert.org        obj = sim_objects[name]
6475517Snate@binkert.org
6485517Snate@binkert.org        code = code_formatter()
6495517Snate@binkert.org        obj.cxx_config_param_file(code, is_header)
6507673Snate@binkert.org        code.write(target[0].abspath)
6517673Snate@binkert.org    return body
6527673Snate@binkert.org
6535517Snate@binkert.orgdef createEnumStrings(target, source, env):
65411988Sandreas.sandberg@arm.com    assert len(target) == 1 and len(source) == 2
6558596Ssteve.reinhardt@amd.com
6568596Ssteve.reinhardt@amd.com    name = source[0].get_text_contents()
6578596Ssteve.reinhardt@amd.com    use_python = source[1].read()
6588596Ssteve.reinhardt@amd.com    obj = all_enums[name]
65911988Sandreas.sandberg@arm.com
6608596Ssteve.reinhardt@amd.com    code = code_formatter()
6618596Ssteve.reinhardt@amd.com    obj.cxx_def(code)
6628596Ssteve.reinhardt@amd.com    if use_python:
6634762Snate@binkert.org        obj.pybind_def(code)
6646143Snate@binkert.org    code.write(target[0].abspath)
6656143Snate@binkert.org
6666143Snate@binkert.orgdef createEnumDecls(target, source, env):
6674762Snate@binkert.org    assert len(target) == 1 and len(source) == 1
6684762Snate@binkert.org
6694762Snate@binkert.org    name = source[0].get_text_contents()
6707756SAli.Saidi@ARM.com    obj = all_enums[name]
6718596Ssteve.reinhardt@amd.com
6724762Snate@binkert.org    code = code_formatter()
6734762Snate@binkert.org    obj.cxx_decl(code)
67410458Sandreas.hansson@arm.com    code.write(target[0].abspath)
67510458Sandreas.hansson@arm.com
67610458Sandreas.hansson@arm.comdef createSimObjectPyBindWrapper(target, source, env):
67710458Sandreas.hansson@arm.com    name = source[0].get_text_contents()
67810458Sandreas.hansson@arm.com    obj = sim_objects[name]
67910458Sandreas.hansson@arm.com
68010458Sandreas.hansson@arm.com    code = code_formatter()
68110458Sandreas.hansson@arm.com    obj.pybind_decl(code)
68210458Sandreas.hansson@arm.com    code.write(target[0].abspath)
68310458Sandreas.hansson@arm.com
68410458Sandreas.hansson@arm.com# Generate all of the SimObject param C++ struct header files
68510458Sandreas.hansson@arm.comparams_hh_files = []
68610458Sandreas.hansson@arm.comfor name,simobj in sorted(sim_objects.iteritems()):
68710458Sandreas.hansson@arm.com    py_source = PySource.modules[simobj.__module__]
68810458Sandreas.hansson@arm.com    extra_deps = [ py_source.tnode ]
68910458Sandreas.hansson@arm.com
69010458Sandreas.hansson@arm.com    hh_file = File('params/%s.hh' % name)
69110458Sandreas.hansson@arm.com    params_hh_files.append(hh_file)
69210458Sandreas.hansson@arm.com    env.Command(hh_file, Value(name),
69310458Sandreas.hansson@arm.com                MakeAction(createSimObjectParamStruct, Transform("SO PARAM")))
69410458Sandreas.hansson@arm.com    env.Depends(hh_file, depends + extra_deps)
69510458Sandreas.hansson@arm.com
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
72310584Sandreas.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('{')
7294762Snate@binkert.org        code.indent()
7306143Snate@binkert.org        for name,simobj in sorted(sim_objects.iteritems()):
7316143Snate@binkert.org            not_abstract = not hasattr(simobj, 'abstract') or \
7326143Snate@binkert.org                not simobj.abstract
7334762Snate@binkert.org            if not_abstract and 'type' in simobj.__dict__:
7344762Snate@binkert.org                code('cxx_config_directory["${name}"] = '
7357756SAli.Saidi@ARM.com                     '${name}CxxConfigParams::makeDirectoryEntry();')
7367816Ssteve.reinhardt@amd.com        code.dedent()
7374762Snate@binkert.org        code('}')
7384762Snate@binkert.org        code.write(target[0].abspath)
7394762Snate@binkert.org
7404762Snate@binkert.org    py_source = PySource.modules[simobj.__module__]
7417756SAli.Saidi@ARM.com    extra_deps = [ py_source.tnode ]
7428596Ssteve.reinhardt@amd.com    env.Command(cxx_config_init_cc_file, Value(name),
7434762Snate@binkert.org        MakeAction(createCxxConfigInitCC, Transform("CXXCINIT")))
7444762Snate@binkert.org    cxx_param_hh_files = ["cxx_config/%s.hh" % simobj
74511988Sandreas.sandberg@arm.com        for name,simobj in sorted(sim_objects.iteritems())
74611988Sandreas.sandberg@arm.com        if not hasattr(simobj, 'abstract') or not simobj.abstract]
74711988Sandreas.sandberg@arm.com    Depends(cxx_config_init_cc_file, cxx_param_hh_files +
74811988Sandreas.sandberg@arm.com            [File('sim/cxx_config.hh')])
74911988Sandreas.sandberg@arm.com    Source(cxx_config_init_cc_file)
75011988Sandreas.sandberg@arm.com
75111988Sandreas.sandberg@arm.com# Generate all enum header files
75211988Sandreas.sandberg@arm.comfor name,enum in sorted(all_enums.iteritems()):
75311988Sandreas.sandberg@arm.com    py_source = PySource.modules[enum.__module__]
75411988Sandreas.sandberg@arm.com    extra_deps = [ py_source.tnode ]
75511988Sandreas.sandberg@arm.com
7564382Sbinkertn@umich.edu    cc_file = File('enums/%s.cc' % name)
7579396Sandreas.hansson@arm.com    env.Command(cc_file, [Value(name), Value(env['USE_PYTHON'])],
7589396Sandreas.hansson@arm.com                MakeAction(createEnumStrings, Transform("ENUM STR")))
7599396Sandreas.hansson@arm.com    env.Depends(cc_file, depends + extra_deps)
7609396Sandreas.hansson@arm.com    Source(cc_file)
7619396Sandreas.hansson@arm.com
7629396Sandreas.hansson@arm.com    hh_file = File('enums/%s.hh' % name)
7639396Sandreas.hansson@arm.com    env.Command(hh_file, Value(name),
7649396Sandreas.hansson@arm.com                MakeAction(createEnumDecls, Transform("ENUMDECL")))
7659396Sandreas.hansson@arm.com    env.Depends(hh_file, depends + extra_deps)
7669396Sandreas.hansson@arm.com
7679396Sandreas.hansson@arm.com# Generate SimObject Python bindings wrapper files
7689396Sandreas.hansson@arm.comif env['USE_PYTHON']:
7699396Sandreas.hansson@arm.com    for name,simobj in sorted(sim_objects.iteritems()):
7709396Sandreas.hansson@arm.com        py_source = PySource.modules[simobj.__module__]
7719396Sandreas.hansson@arm.com        extra_deps = [ py_source.tnode ]
7729396Sandreas.hansson@arm.com        cc_file = File('python/_m5/param_%s.cc' % name)
7739396Sandreas.hansson@arm.com        env.Command(cc_file, Value(name),
7749396Sandreas.hansson@arm.com                    MakeAction(createSimObjectPyBindWrapper,
7758232Snate@binkert.org                               Transform("SO PyBind")))
7768232Snate@binkert.org        env.Depends(cc_file, depends + extra_deps)
7778232Snate@binkert.org        Source(cc_file)
7788232Snate@binkert.org
7798232Snate@binkert.org# Build all protocol buffers if we have got protoc and protobuf available
7806229Snate@binkert.orgif env['HAVE_PROTOBUF']:
78110455SCurtis.Dunham@arm.com    for proto in ProtoBuf.all:
7826229Snate@binkert.org        # Use both the source and header as the target, and the .proto
78310455SCurtis.Dunham@arm.com        # file as the source. When executing the protoc compiler, also
78410455SCurtis.Dunham@arm.com        # specify the proto_path to avoid having the generated files
78510455SCurtis.Dunham@arm.com        # include the path.
7865517Snate@binkert.org        env.Command([proto.cc_file, proto.hh_file], proto.tnode,
7875517Snate@binkert.org                    MakeAction('$PROTOC --cpp_out ${TARGET.dir} '
7887673Snate@binkert.org                               '--proto_path ${SOURCE.dir} $SOURCE',
7895517Snate@binkert.org                               Transform("PROTOC")))
79010455SCurtis.Dunham@arm.com
7915517Snate@binkert.org        # Add the C++ source file
7925517Snate@binkert.org        Source(proto.cc_file, tags=proto.tags)
7938232Snate@binkert.orgelif ProtoBuf.all:
79410455SCurtis.Dunham@arm.com    print 'Got protobuf to build, but lacks support!'
79510455SCurtis.Dunham@arm.com    Exit(1)
79610455SCurtis.Dunham@arm.com
7977673Snate@binkert.org#
7987673Snate@binkert.org# Handle debug flags
79910455SCurtis.Dunham@arm.com#
80010455SCurtis.Dunham@arm.comdef makeDebugFlagCC(target, source, env):
80110455SCurtis.Dunham@arm.com    assert(len(target) == 1 and len(source) == 1)
8025517Snate@binkert.org
80310455SCurtis.Dunham@arm.com    code = code_formatter()
80410455SCurtis.Dunham@arm.com
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()
80810455SCurtis.Dunham@arm.com
80910455SCurtis.Dunham@arm.com    # file header
81010455SCurtis.Dunham@arm.com    code('''
81110685Sandreas.hansson@arm.com/*
81210455SCurtis.Dunham@arm.com * DO NOT EDIT THIS FILE! Automatically generated by SCons.
81310685Sandreas.hansson@arm.com */
81410455SCurtis.Dunham@arm.com
8155517Snate@binkert.org#include "base/debug.hh"
81610455SCurtis.Dunham@arm.com
8178232Snate@binkert.orgnamespace Debug {
8188232Snate@binkert.org
8195517Snate@binkert.org''')
8207673Snate@binkert.org
8215517Snate@binkert.org    for name, flag in sorted(source[0].read().iteritems()):
8228232Snate@binkert.org        n, compound, desc = flag
8238232Snate@binkert.org        assert n == name
8245517Snate@binkert.org
8258232Snate@binkert.org        if not compound:
8268232Snate@binkert.org            code('SimpleFlag $name("$name", "$desc");')
8278232Snate@binkert.org        else:
8287673Snate@binkert.org            comp_code('CompoundFlag $name("$name", "$desc",')
8295517Snate@binkert.org            comp_code.indent()
8305517Snate@binkert.org            last = len(compound) - 1
8317673Snate@binkert.org            for i,flag in enumerate(compound):
8325517Snate@binkert.org                if i != last:
83310455SCurtis.Dunham@arm.com                    comp_code('&$flag,')
8345517Snate@binkert.org                else:
8355517Snate@binkert.org                    comp_code('&$flag);')
8368232Snate@binkert.org            comp_code.dedent()
8378232Snate@binkert.org
8385517Snate@binkert.org    code.append(comp_code)
8398232Snate@binkert.org    code()
8408232Snate@binkert.org    code('} // namespace Debug')
8415517Snate@binkert.org
8428232Snate@binkert.org    code.write(str(target[0]))
8438232Snate@binkert.org
8448232Snate@binkert.orgdef makeDebugFlagHH(target, source, env):
8455517Snate@binkert.org    assert(len(target) == 1 and len(source) == 1)
8468232Snate@binkert.org
8478232Snate@binkert.org    val = eval(source[0].get_contents())
8488232Snate@binkert.org    name, compound, desc = val
8498232Snate@binkert.org
8508232Snate@binkert.org    code = code_formatter()
8518232Snate@binkert.org
8525517Snate@binkert.org    # file header boilerplate
8538232Snate@binkert.org    code('''\
8548232Snate@binkert.org/*
8555517Snate@binkert.org * DO NOT EDIT THIS FILE! Automatically generated by SCons.
8568232Snate@binkert.org */
8577673Snate@binkert.org
8585517Snate@binkert.org#ifndef __DEBUG_${name}_HH__
8597673Snate@binkert.org#define __DEBUG_${name}_HH__
8605517Snate@binkert.org
8618232Snate@binkert.orgnamespace Debug {
8628232Snate@binkert.org''')
8638232Snate@binkert.org
8645192Ssaidi@eecs.umich.edu    if compound:
86510454SCurtis.Dunham@arm.com        code('class CompoundFlag;')
86610454SCurtis.Dunham@arm.com    code('class SimpleFlag;')
8678232Snate@binkert.org
86810455SCurtis.Dunham@arm.com    if compound:
86910455SCurtis.Dunham@arm.com        code('extern CompoundFlag $name;')
87010455SCurtis.Dunham@arm.com        for flag in compound:
87110455SCurtis.Dunham@arm.com            code('extern SimpleFlag $flag;')
8725192Ssaidi@eecs.umich.edu    else:
87311077SCurtis.Dunham@arm.com        code('extern SimpleFlag $name;')
87411330SCurtis.Dunham@arm.com
87511077SCurtis.Dunham@arm.com    code('''
87611077SCurtis.Dunham@arm.com}
87711077SCurtis.Dunham@arm.com
87811330SCurtis.Dunham@arm.com#endif // __DEBUG_${name}_HH__
87911077SCurtis.Dunham@arm.com''')
8807674Snate@binkert.org
8815522Snate@binkert.org    code.write(str(target[0]))
8825522Snate@binkert.org
8837674Snate@binkert.orgfor name,flag in sorted(debug_flags.iteritems()):
8847674Snate@binkert.org    n, compound, desc = flag
8857674Snate@binkert.org    assert n == name
8867674Snate@binkert.org
8877674Snate@binkert.org    hh_file = 'debug/%s.hh' % name
8887674Snate@binkert.org    env.Command(hh_file, Value(flag),
8897674Snate@binkert.org                MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
8907674Snate@binkert.org
8915522Snate@binkert.orgenv.Command('debug/flags.cc', Value(debug_flags),
8925522Snate@binkert.org            MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
8935522Snate@binkert.orgSource('debug/flags.cc')
8945517Snate@binkert.org
8955522Snate@binkert.org# version tags
8965517Snate@binkert.orgtags = \
8976143Snate@binkert.orgenv.Command('sim/tags.cc', None,
8986727Ssteve.reinhardt@amd.com            MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET',
8995522Snate@binkert.org                       Transform("VER TAGS")))
9005522Snate@binkert.orgenv.AlwaysBuild(tags)
9015522Snate@binkert.org
9027674Snate@binkert.org# Embed python files.  All .py files that have been indicated by a
9035517Snate@binkert.org# PySource() call in a SConscript need to be embedded into the M5
9047673Snate@binkert.org# library.  To do that, we compile the file to byte code, marshal the
9057673Snate@binkert.org# byte code, compress it, and then generate a c++ file that
9067674Snate@binkert.org# inserts the result into an array.
9077673Snate@binkert.orgdef embedPyFile(target, source, env):
9087674Snate@binkert.org    def c_str(string):
9097674Snate@binkert.org        if string is None:
9108946Sandreas.hansson@arm.com            return "0"
9117674Snate@binkert.org        return '"%s"' % string
9127674Snate@binkert.org
9137674Snate@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'''
9167674Snate@binkert.org
9177674Snate@binkert.org    src = file(str(source[0]), 'r').read()
91811308Santhony.gutierrez@amd.com
9197674Snate@binkert.org    pysource = PySource.tnodes[source[0]]
9207673Snate@binkert.org    compiled = compile(src, pysource.abspath, 'exec')
9217674Snate@binkert.org    marshalled = marshal.dumps(compiled)
9227674Snate@binkert.org    compressed = zlib.compress(marshalled)
9237674Snate@binkert.org    data = compressed
9247674Snate@binkert.org    sym = pysource.symname
9257674Snate@binkert.org
9267674Snate@binkert.org    code = code_formatter()
9277674Snate@binkert.org    code('''\
9287674Snate@binkert.org#include "sim/init.hh"
9297811Ssteve.reinhardt@amd.com
9307674Snate@binkert.orgnamespace {
9317673Snate@binkert.org
9325522Snate@binkert.orgconst uint8_t data_${sym}[] = {
9336143Snate@binkert.org''')
93410453SAndrew.Bardsley@arm.com    code.indent()
9357816Ssteve.reinhardt@amd.com    step = 16
93610453SAndrew.Bardsley@arm.com    for i in xrange(0, len(data), step):
9374382Sbinkertn@umich.edu        x = array.array('B', data[i:i+step])
9384382Sbinkertn@umich.edu        code(''.join('%d,' % d for d in x))
9394382Sbinkertn@umich.edu    code.dedent()
9404382Sbinkertn@umich.edu
9414382Sbinkertn@umich.edu    code('''};
9424382Sbinkertn@umich.edu
9434382Sbinkertn@umich.eduEmbeddedPython embedded_${sym}(
9444382Sbinkertn@umich.edu    ${{c_str(pysource.arcname)}},
94510196SCurtis.Dunham@arm.com    ${{c_str(pysource.abspath)}},
9464382Sbinkertn@umich.edu    ${{c_str(pysource.modpath)}},
94710196SCurtis.Dunham@arm.com    data_${sym},
94810196SCurtis.Dunham@arm.com    ${{len(data)}},
94910196SCurtis.Dunham@arm.com    ${{len(marshalled)}});
95010196SCurtis.Dunham@arm.com
95110196SCurtis.Dunham@arm.com} // anonymous namespace
95210196SCurtis.Dunham@arm.com''')
95310196SCurtis.Dunham@arm.com    code.write(str(target[0]))
954955SN/A
9552655Sstever@eecs.umich.edufor source in PySource.all:
9562655Sstever@eecs.umich.edu    env.Command(source.cpp, source.tnode,
9572655Sstever@eecs.umich.edu                MakeAction(embedPyFile, Transform("EMBED PY")))
9582655Sstever@eecs.umich.edu    Source(source.cpp, tags=source.tags, add_tags='python')
95910196SCurtis.Dunham@arm.com
9605601Snate@binkert.org########################################################################
9615601Snate@binkert.org#
96210196SCurtis.Dunham@arm.com# Define binaries.  Each different build type (debug, opt, etc.) gets
96310196SCurtis.Dunham@arm.com# a slightly different build environment.
96410196SCurtis.Dunham@arm.com#
9655522Snate@binkert.org
9665863Snate@binkert.org# List of constructed environments to pass back to SConstruct
9675601Snate@binkert.orgdate_source = Source('base/date.cc', tags=[])
9685601Snate@binkert.org
9695601Snate@binkert.org# Function to create a new build environment as clone of current
9705559Snate@binkert.org# environment 'env' with modified object suffix and optional stripped
97111718Sjoseph.gross@amd.com# binary.  Additional keyword arguments are appended to corresponding
97211718Sjoseph.gross@amd.com# build environment vars.
97311718Sjoseph.gross@amd.comdef makeEnv(env, label, objsfx, strip=False, disable_partial=False, **kwargs):
97411718Sjoseph.gross@amd.com    # SCons doesn't know to append a library suffix when there is a '.' in the
97511718Sjoseph.gross@amd.com    # name.  Use '_' instead.
97611718Sjoseph.gross@amd.com    libname = 'gem5_' + label
97711718Sjoseph.gross@amd.com    exename = 'gem5.' + label
97811718Sjoseph.gross@amd.com    secondary_exename = 'm5.' + label
97911718Sjoseph.gross@amd.com
98011718Sjoseph.gross@amd.com    new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
98111718Sjoseph.gross@amd.com    new_env.Label = label
98210457Sandreas.hansson@arm.com    new_env.Append(**kwargs)
98310457Sandreas.hansson@arm.com
98410457Sandreas.hansson@arm.com    lib_sources = Source.all.with_tag('gem5 lib')
98511718Sjoseph.gross@amd.com
98610457Sandreas.hansson@arm.com    # Without Python, leave out all Python content from the library
98710457Sandreas.hansson@arm.com    # builds.  The option doesn't affect gem5 built as a program
98810457Sandreas.hansson@arm.com    if GetOption('without_python'):
98910457Sandreas.hansson@arm.com        lib_sources = lib_sources.without_tag('python')
99011342Sandreas.hansson@arm.com
9918737Skoansin.tan@gmail.com    static_objs = []
99211342Sandreas.hansson@arm.com    shared_objs = []
99311342Sandreas.hansson@arm.com
99410457Sandreas.hansson@arm.com    for s in lib_sources.with_tag(Source.ungrouped_tag):
99511718Sjoseph.gross@amd.com        static_objs.append(s.static(new_env))
99611718Sjoseph.gross@amd.com        shared_objs.append(s.shared(new_env))
99711718Sjoseph.gross@amd.com
99811718Sjoseph.gross@amd.com    for group in Source.source_groups:
99911718Sjoseph.gross@amd.com        srcs = lib_sources.with_tag(Source.link_group_tag(group))
100011718Sjoseph.gross@amd.com        if not srcs:
100111718Sjoseph.gross@amd.com            continue
100210457Sandreas.hansson@arm.com
100311718Sjoseph.gross@amd.com        group_static = [ s.static(new_env) for s in srcs ]
100411500Sandreas.hansson@arm.com        group_shared = [ s.shared(new_env) for s in srcs ]
100511500Sandreas.hansson@arm.com
100611342Sandreas.hansson@arm.com        # If partial linking is disabled, add these sources to the build
100711342Sandreas.hansson@arm.com        # directly, and short circuit this loop.
10088945Ssteve.reinhardt@amd.com        if disable_partial:
100910686SAndreas.Sandberg@ARM.com            static_objs.extend(group_static)
101010686SAndreas.Sandberg@ARM.com            shared_objs.extend(group_shared)
101110686SAndreas.Sandberg@ARM.com            continue
101210686SAndreas.Sandberg@ARM.com
101310686SAndreas.Sandberg@ARM.com        # Set up the static partially linked objects.
101410686SAndreas.Sandberg@ARM.com        file_name = new_env.subst("${OBJPREFIX}lib${OBJSUFFIX}.partial")
10158945Ssteve.reinhardt@amd.com        target = File(joinpath(group, file_name))
10166143Snate@binkert.org        partial = env.PartialStatic(target=target, source=group_static)
10176143Snate@binkert.org        static_objs.extend(partial)
10186143Snate@binkert.org
10196143Snate@binkert.org        # Set up the shared partially linked objects.
10206143Snate@binkert.org        file_name = new_env.subst("${SHOBJPREFIX}lib${SHOBJSUFFIX}.partial")
102111988Sandreas.sandberg@arm.com        target = File(joinpath(group, file_name))
10228945Ssteve.reinhardt@amd.com        partial = env.PartialShared(target=target, source=group_shared)
10236143Snate@binkert.org        shared_objs.extend(partial)
10246143Snate@binkert.org
10256143Snate@binkert.org    static_date = date_source.static(new_env)
10266143Snate@binkert.org    new_env.Depends(static_date, static_objs)
10276143Snate@binkert.org    static_objs.extend(static_date)
10286143Snate@binkert.org
10296143Snate@binkert.org    shared_date = date_source.shared(new_env)
10306143Snate@binkert.org    new_env.Depends(shared_date, shared_objs)
10316143Snate@binkert.org    shared_objs.extend(shared_date)
10326143Snate@binkert.org
10336143Snate@binkert.org    # First make a library of everything but main() so other programs can
10346143Snate@binkert.org    # link against m5.
10356143Snate@binkert.org    static_lib = new_env.StaticLibrary(libname, static_objs)
103610453SAndrew.Bardsley@arm.com    shared_lib = new_env.SharedLibrary(libname, shared_objs)
103710453SAndrew.Bardsley@arm.com
103811988Sandreas.sandberg@arm.com    # Now link a stub with main() and the static library.
103911988Sandreas.sandberg@arm.com    main_objs = [ s.static(new_env) for s in Source.all.with_tag('main') ]
104010453SAndrew.Bardsley@arm.com
104110453SAndrew.Bardsley@arm.com    for test in UnitTest.all:
104210453SAndrew.Bardsley@arm.com        test_sources = Source.all.with_tag(str(test.target))
104311983Sgabeblack@google.com        test_objs = [ s.static(new_env) for s in test_sources ]
104411983Sgabeblack@google.com        if test.main:
104511983Sgabeblack@google.com            test_objs += main_objs
104611983Sgabeblack@google.com        path = 'unittest/%s.%s' % (test.target, label)
104711983Sgabeblack@google.com        new_env.Program(path, test_objs + static_objs)
104811983Sgabeblack@google.com
104911983Sgabeblack@google.com    gtest_env = new_env.Clone()
105011983Sgabeblack@google.com    gtest_env.Append(LIBS=gtest_env['GTEST_LIBS'])
105111983Sgabeblack@google.com    gtest_env.Append(CPPFLAGS=gtest_env['GTEST_CPPFLAGS'])
105211983Sgabeblack@google.com    gtests = []
105311983Sgabeblack@google.com    for test in GTest.all:
105411983Sgabeblack@google.com        test_sources = Source.all.with_tag(str(test.target))
105511983Sgabeblack@google.com        test_objs = [ s.static(gtest_env) for s in test_sources ]
105611983Sgabeblack@google.com        gtests.append(gtest_env.Program(
105711983Sgabeblack@google.com            test.dir.File('%s.%s' % (test.target, label)), test_objs))
105811983Sgabeblack@google.com
105911983Sgabeblack@google.com    gtest_target = Dir(new_env['BUILDDIR']).File('unittests.%s' % label)
106011983Sgabeblack@google.com    AlwaysBuild(Command(gtest_target, gtests, gtests))
106111983Sgabeblack@google.com
106211983Sgabeblack@google.com    progname = exename
106311983Sgabeblack@google.com    if strip:
106411983Sgabeblack@google.com        progname += '.unstripped'
106511983Sgabeblack@google.com
106611983Sgabeblack@google.com    targets = new_env.Program(progname, main_objs + static_objs)
106711983Sgabeblack@google.com
106811983Sgabeblack@google.com    if strip:
106911983Sgabeblack@google.com        if sys.platform == 'sunos5':
107011983Sgabeblack@google.com            cmd = 'cp $SOURCE $TARGET; strip $TARGET'
107111983Sgabeblack@google.com        else:
107211983Sgabeblack@google.com            cmd = 'strip $SOURCE -o $TARGET'
107311983Sgabeblack@google.com        targets = new_env.Command(exename, progname,
10746143Snate@binkert.org                    MakeAction(cmd, Transform("STRIP")))
10756143Snate@binkert.org
10766143Snate@binkert.org    new_env.Command(secondary_exename, exename,
107710453SAndrew.Bardsley@arm.com            MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
10786143Snate@binkert.org
10796240Snate@binkert.org    new_env.M5Binary = targets[0]
10805554Snate@binkert.org
10815522Snate@binkert.org    # Set up regression tests.
10825522Snate@binkert.org    SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'),
10835797Snate@binkert.org               variant_dir=Dir('tests').Dir(new_env.Label),
10845797Snate@binkert.org               exports={ 'env' : new_env }, duplicate=False)
10855522Snate@binkert.org
10865601Snate@binkert.org# Start out with the compiler flags common to all compilers,
10878233Snate@binkert.org# i.e. they all use -g for opt and -g -pg for prof
10888233Snate@binkert.orgccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],
10898235Snate@binkert.org           'perf' : ['-g']}
10908235Snate@binkert.org
10918235Snate@binkert.org# Start out with the linker flags common to all linkers, i.e. -pg for
10928235Snate@binkert.org# prof, and -lprofiler for perf. The -lprofile flag is surrounded by
10939003SAli.Saidi@ARM.com# no-as-needed and as-needed as the binutils linker is too clever and
10949003SAli.Saidi@ARM.com# simply doesn't link to the library otherwise.
109510196SCurtis.Dunham@arm.comldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'],
109610196SCurtis.Dunham@arm.com           'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']}
10978235Snate@binkert.org
10986143Snate@binkert.org# For Link Time Optimization, the optimisation flags used to compile
10992655Sstever@eecs.umich.edu# individual files are decoupled from those used at link time
11006143Snate@binkert.org# (i.e. you can compile with -O3 and perform LTO with -O0), so we need
11016143Snate@binkert.org# to also update the linker flags based on the target.
110211985Sgabeblack@google.comif env['GCC']:
11036143Snate@binkert.org    if sys.platform == 'sunos5':
11046143Snate@binkert.org        ccflags['debug'] += ['-gstabs+']
11054007Ssaidi@eecs.umich.edu    else:
11064596Sbinkertn@umich.edu        ccflags['debug'] += ['-ggdb3']
11074007Ssaidi@eecs.umich.edu    ldflags['debug'] += ['-O0']
11084596Sbinkertn@umich.edu    # opt, fast, prof and perf all share the same cc flags, also add
11097756SAli.Saidi@ARM.com    # the optimization to the ldflags as LTO defers the optimization
11107816Ssteve.reinhardt@amd.com    # to link time
11118334Snate@binkert.org    for target in ['opt', 'fast', 'prof', 'perf']:
11128334Snate@binkert.org        ccflags[target] += ['-O3']
11138334Snate@binkert.org        ldflags[target] += ['-O3']
11148334Snate@binkert.org
11155601Snate@binkert.org    ccflags['fast'] += env['LTO_CCFLAGS']
111610196SCurtis.Dunham@arm.com    ldflags['fast'] += env['LTO_LDFLAGS']
11172655Sstever@eecs.umich.eduelif env['CLANG']:
11189225Sandreas.hansson@arm.com    ccflags['debug'] += ['-g', '-O0']
11199225Sandreas.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']
11229225Sandreas.hansson@arm.comelse:
11239226Sandreas.hansson@arm.com    print 'Unknown compiler, please fix compiler options'
11249226Sandreas.hansson@arm.com    Exit(1)
11259226Sandreas.hansson@arm.com
11269226Sandreas.hansson@arm.com
11279226Sandreas.hansson@arm.com# To speed things up, we only instantiate the build environments we
11289226Sandreas.hansson@arm.com# need.  We try to identify the needed environment for each target; if
11299225Sandreas.hansson@arm.com# we can't, we fall back on instantiating all the environments just to
11309227Sandreas.hansson@arm.com# be safe.
11319227Sandreas.hansson@arm.comtarget_types = ['debug', 'opt', 'fast', 'prof', 'perf']
11329227Sandreas.hansson@arm.comobj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof',
11339227Sandreas.hansson@arm.com              'gpo' : 'perf'}
11348946Sandreas.hansson@arm.com
11353918Ssaidi@eecs.umich.edudef identifyTarget(t):
11369225Sandreas.hansson@arm.com    ext = t.split('.')[-1]
11373918Ssaidi@eecs.umich.edu    if ext in target_types:
11389225Sandreas.hansson@arm.com        return ext
11399225Sandreas.hansson@arm.com    if obj2target.has_key(ext):
11409227Sandreas.hansson@arm.com        return obj2target[ext]
11419227Sandreas.hansson@arm.com    match = re.search(r'/tests/([^/]+)/', t)
11429227Sandreas.hansson@arm.com    if match and match.group(1) in target_types:
11439226Sandreas.hansson@arm.com        return match.group(1)
11449225Sandreas.hansson@arm.com    return 'all'
11459227Sandreas.hansson@arm.com
11469227Sandreas.hansson@arm.comneeded_envs = [identifyTarget(target) for target in BUILD_TARGETS]
11479227Sandreas.hansson@arm.comif 'all' in needed_envs:
11489227Sandreas.hansson@arm.com    needed_envs += target_types
11498946Sandreas.hansson@arm.com
11509225Sandreas.hansson@arm.com# Debug binary
11519226Sandreas.hansson@arm.comif 'debug' in needed_envs:
11529226Sandreas.hansson@arm.com    makeEnv(env, 'debug', '.do',
11539226Sandreas.hansson@arm.com            CCFLAGS = Split(ccflags['debug']),
11543515Ssaidi@eecs.umich.edu            CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
11553918Ssaidi@eecs.umich.edu            LINKFLAGS = Split(ldflags['debug']))
11564762Snate@binkert.org
11573515Ssaidi@eecs.umich.edu# Optimized binary
11588881Smarc.orr@gmail.comif 'opt' in needed_envs:
11598881Smarc.orr@gmail.com    makeEnv(env, 'opt', '.o',
11608881Smarc.orr@gmail.com            CCFLAGS = Split(ccflags['opt']),
11618881Smarc.orr@gmail.com            CPPDEFINES = ['TRACING_ON=1'],
11628881Smarc.orr@gmail.com            LINKFLAGS = Split(ldflags['opt']))
11639226Sandreas.hansson@arm.com
11649226Sandreas.hansson@arm.com# "Fast" binary
11659226Sandreas.hansson@arm.comif 'fast' in needed_envs:
11668881Smarc.orr@gmail.com    disable_partial = \
11678881Smarc.orr@gmail.com            env.get('BROKEN_INCREMENTAL_LTO', False) and \
11688881Smarc.orr@gmail.com            GetOption('force_lto')
11698881Smarc.orr@gmail.com    makeEnv(env, 'fast', '.fo', strip = True,
11708881Smarc.orr@gmail.com            CCFLAGS = Split(ccflags['fast']),
11718881Smarc.orr@gmail.com            CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
11728881Smarc.orr@gmail.com            LINKFLAGS = Split(ldflags['fast']),
11738881Smarc.orr@gmail.com            disable_partial=disable_partial)
11748881Smarc.orr@gmail.com
11758881Smarc.orr@gmail.com# Profiled binary using gprof
11768881Smarc.orr@gmail.comif 'prof' in needed_envs:
11778881Smarc.orr@gmail.com    makeEnv(env, 'prof', '.po',
11788881Smarc.orr@gmail.com            CCFLAGS = Split(ccflags['prof']),
11798881Smarc.orr@gmail.com            CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
11808881Smarc.orr@gmail.com            LINKFLAGS = Split(ldflags['prof']))
11818881Smarc.orr@gmail.com
118210196SCurtis.Dunham@arm.com# Profiled binary using google-pprof
118310196SCurtis.Dunham@arm.comif 'perf' in needed_envs:
118410196SCurtis.Dunham@arm.com    makeEnv(env, 'perf', '.gpo',
1185955SN/A            CCFLAGS = Split(ccflags['perf']),
118610196SCurtis.Dunham@arm.com            CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1187955SN/A            LINKFLAGS = Split(ldflags['perf']))
118810196SCurtis.Dunham@arm.com