SConscript revision 12797:fc61ae2a54bd
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.orgfrom __future__ import print_function
324762Snate@binkert.org
335522Snate@binkert.orgimport array
34955SN/Aimport bisect
355522Snate@binkert.orgimport functools
36955SN/Aimport imp
375522Snate@binkert.orgimport marshal
384202Sbinkertn@umich.eduimport os
395342Sstever@gmail.comimport re
40955SN/Aimport subprocess
414381Sbinkertn@umich.eduimport sys
424381Sbinkertn@umich.eduimport zlib
43955SN/A
44955SN/Afrom os.path import basename, dirname, exists, isdir, isfile, join as joinpath
45955SN/A
464202Sbinkertn@umich.eduimport SCons
47955SN/A
484382Sbinkertn@umich.edufrom gem5_scons import Transform
494382Sbinkertn@umich.edu
504382Sbinkertn@umich.edu# This file defines how to build a particular configuration of gem5
515517Snate@binkert.org# based on variable settings in the 'env' build environment.
525517Snate@binkert.org
534762Snate@binkert.orgImport('*')
544762Snate@binkert.org
554762Snate@binkert.org# Children need to see the environment
564762Snate@binkert.orgExport('env')
574762Snate@binkert.org
584762Snate@binkert.orgbuild_env = [(opt, env[opt]) for opt in export_vars]
594762Snate@binkert.org
604762Snate@binkert.orgfrom m5.util import code_formatter, compareVersions
614762Snate@binkert.org
624762Snate@binkert.org########################################################################
635522Snate@binkert.org# Code for adding source files of various types
644762Snate@binkert.org#
654762Snate@binkert.org# When specifying a source file of some type, a set of tags can be
664762Snate@binkert.org# specified for that file.
674762Snate@binkert.org
684762Snate@binkert.orgclass SourceFilter(object):
695522Snate@binkert.org    def __init__(self, predicate):
705522Snate@binkert.org        self.predicate = predicate
715522Snate@binkert.org
725522Snate@binkert.org    def __or__(self, other):
734762Snate@binkert.org        return SourceFilter(lambda tags: self.predicate(tags) or
744762Snate@binkert.org                                         other.predicate(tags))
754762Snate@binkert.org
764762Snate@binkert.org    def __and__(self, other):
774762Snate@binkert.org        return SourceFilter(lambda tags: self.predicate(tags) and
785522Snate@binkert.org                                         other.predicate(tags))
794762Snate@binkert.org
804762Snate@binkert.orgdef with_tags_that(predicate):
815522Snate@binkert.org    '''Return a list of sources with tags that satisfy a predicate.'''
825522Snate@binkert.org    return SourceFilter(predicate)
834762Snate@binkert.org
844762Snate@binkert.orgdef with_any_tags(*tags):
854762Snate@binkert.org    '''Return a list of sources with any of the supplied tags.'''
864762Snate@binkert.org    return SourceFilter(lambda stags: len(set(tags) & stags) > 0)
874762Snate@binkert.org
884762Snate@binkert.orgdef with_all_tags(*tags):
895522Snate@binkert.org    '''Return a list of sources with all of the supplied tags.'''
905522Snate@binkert.org    return SourceFilter(lambda stags: set(tags) <= stags)
915522Snate@binkert.org
924762Snate@binkert.orgdef with_tag(tag):
934382Sbinkertn@umich.edu    '''Return a list of sources with the supplied tag.'''
944762Snate@binkert.org    return SourceFilter(lambda stags: tag in stags)
954382Sbinkertn@umich.edu
965522Snate@binkert.orgdef without_tags(*tags):
974381Sbinkertn@umich.edu    '''Return a list of sources without any of the supplied tags.'''
985522Snate@binkert.org    return SourceFilter(lambda stags: len(set(tags) & stags) == 0)
994762Snate@binkert.org
1004762Snate@binkert.orgdef without_tag(tag):
1014762Snate@binkert.org    '''Return a list of sources with the supplied tag.'''
1025522Snate@binkert.org    return SourceFilter(lambda stags: tag not in stags)
1035522Snate@binkert.org
1045522Snate@binkert.orgsource_filter_factories = {
1055522Snate@binkert.org    'with_tags_that': with_tags_that,
1065522Snate@binkert.org    'with_any_tags': with_any_tags,
1075522Snate@binkert.org    'with_all_tags': with_all_tags,
1085522Snate@binkert.org    'with_tag': with_tag,
1095522Snate@binkert.org    'without_tags': without_tags,
1105522Snate@binkert.org    'without_tag': without_tag,
1114762Snate@binkert.org}
1124762Snate@binkert.org
1134762Snate@binkert.orgExport(source_filter_factories)
1144762Snate@binkert.org
1154762Snate@binkert.orgclass SourceList(list):
1164762Snate@binkert.org    def apply_filter(self, f):
1174762Snate@binkert.org        def match(source):
1184762Snate@binkert.org            return f.predicate(source.tags)
1194762Snate@binkert.org        return SourceList(filter(match, self))
1204762Snate@binkert.org
1214762Snate@binkert.org    def __getattr__(self, name):
1224762Snate@binkert.org        func = source_filter_factories.get(name, None)
1234762Snate@binkert.org        if not func:
1244762Snate@binkert.org            raise AttributeError
1254762Snate@binkert.org
1264762Snate@binkert.org        @functools.wraps(func)
1274762Snate@binkert.org        def wrapper(*args, **kwargs):
1284762Snate@binkert.org            return self.apply_filter(func(*args, **kwargs))
1294762Snate@binkert.org        return wrapper
1304762Snate@binkert.org
1314762Snate@binkert.orgclass SourceMeta(type):
1324762Snate@binkert.org    '''Meta class for source files that keeps track of all files of a
1334762Snate@binkert.org    particular type.'''
1344762Snate@binkert.org    def __init__(cls, name, bases, dict):
1354762Snate@binkert.org        super(SourceMeta, cls).__init__(name, bases, dict)
1364762Snate@binkert.org        cls.all = SourceList()
1374762Snate@binkert.org
1384762Snate@binkert.orgclass SourceFile(object):
1394762Snate@binkert.org    '''Base object that encapsulates the notion of a source file.
1404762Snate@binkert.org    This includes, the source node, target node, various manipulations
1414762Snate@binkert.org    of those.  A source file also specifies a set of tags which
1424762Snate@binkert.org    describing arbitrary properties of the source file.'''
1434762Snate@binkert.org    __metaclass__ = SourceMeta
1444762Snate@binkert.org
1454762Snate@binkert.org    static_objs = {}
146955SN/A    shared_objs = {}
1475584Snate@binkert.org
1485584Snate@binkert.org    def __init__(self, source, tags=None, add_tags=None):
1495584Snate@binkert.org        if tags is None:
1505584Snate@binkert.org            tags='gem5 lib'
1515584Snate@binkert.org        if isinstance(tags, basestring):
1525584Snate@binkert.org            tags = set([tags])
1535584Snate@binkert.org        if not isinstance(tags, set):
1545584Snate@binkert.org            tags = set(tags)
1555584Snate@binkert.org        self.tags = tags
1565584Snate@binkert.org
1575584Snate@binkert.org        if add_tags:
1585584Snate@binkert.org            if isinstance(add_tags, basestring):
1595584Snate@binkert.org                add_tags = set([add_tags])
1604382Sbinkertn@umich.edu            if not isinstance(add_tags, set):
1614202Sbinkertn@umich.edu                add_tags = set(add_tags)
1625522Snate@binkert.org            self.tags |= add_tags
1634382Sbinkertn@umich.edu
1644382Sbinkertn@umich.edu        tnode = source
1654382Sbinkertn@umich.edu        if not isinstance(source, SCons.Node.FS.File):
1665584Snate@binkert.org            tnode = File(source)
1674382Sbinkertn@umich.edu
1684382Sbinkertn@umich.edu        self.tnode = tnode
1694382Sbinkertn@umich.edu        self.snode = tnode.srcnode()
1705192Ssaidi@eecs.umich.edu
1715192Ssaidi@eecs.umich.edu        for base in type(self).__mro__:
1725192Ssaidi@eecs.umich.edu            if issubclass(base, SourceFile):
1735192Ssaidi@eecs.umich.edu                base.all.append(self)
1745192Ssaidi@eecs.umich.edu
1755192Ssaidi@eecs.umich.edu    def static(self, env):
1765192Ssaidi@eecs.umich.edu        key = (self.tnode, env['OBJSUFFIX'])
1775192Ssaidi@eecs.umich.edu        if not key in self.static_objs:
1785192Ssaidi@eecs.umich.edu            self.static_objs[key] = env.StaticObject(self.tnode)
1795192Ssaidi@eecs.umich.edu        return self.static_objs[key]
1805192Ssaidi@eecs.umich.edu
1815192Ssaidi@eecs.umich.edu    def shared(self, env):
1825192Ssaidi@eecs.umich.edu        key = (self.tnode, env['OBJSUFFIX'])
1835192Ssaidi@eecs.umich.edu        if not key in self.shared_objs:
1845192Ssaidi@eecs.umich.edu            self.shared_objs[key] = env.SharedObject(self.tnode)
1855192Ssaidi@eecs.umich.edu        return self.shared_objs[key]
1865192Ssaidi@eecs.umich.edu
1875192Ssaidi@eecs.umich.edu    @property
1885192Ssaidi@eecs.umich.edu    def filename(self):
1895192Ssaidi@eecs.umich.edu        return str(self.tnode)
1905192Ssaidi@eecs.umich.edu
1915192Ssaidi@eecs.umich.edu    @property
1925192Ssaidi@eecs.umich.edu    def dirname(self):
1935192Ssaidi@eecs.umich.edu        return dirname(self.filename)
1945192Ssaidi@eecs.umich.edu
1955192Ssaidi@eecs.umich.edu    @property
1965192Ssaidi@eecs.umich.edu    def basename(self):
1975192Ssaidi@eecs.umich.edu        return basename(self.filename)
1985192Ssaidi@eecs.umich.edu
1995192Ssaidi@eecs.umich.edu    @property
2005192Ssaidi@eecs.umich.edu    def extname(self):
2015192Ssaidi@eecs.umich.edu        index = self.basename.rfind('.')
2024382Sbinkertn@umich.edu        if index <= 0:
2034382Sbinkertn@umich.edu            # dot files aren't extensions
2044382Sbinkertn@umich.edu            return self.basename, None
2052667Sstever@eecs.umich.edu
2062667Sstever@eecs.umich.edu        return self.basename[:index], self.basename[index+1:]
2072667Sstever@eecs.umich.edu
2082667Sstever@eecs.umich.edu    def __lt__(self, other): return self.filename < other.filename
2092667Sstever@eecs.umich.edu    def __le__(self, other): return self.filename <= other.filename
2102667Sstever@eecs.umich.edu    def __gt__(self, other): return self.filename > other.filename
2112037SN/A    def __ge__(self, other): return self.filename >= other.filename
2122037SN/A    def __eq__(self, other): return self.filename == other.filename
2132037SN/A    def __ne__(self, other): return self.filename != other.filename
2144382Sbinkertn@umich.edu
2154762Snate@binkert.orgclass Source(SourceFile):
2165344Sstever@gmail.com    ungrouped_tag = 'No link group'
2174382Sbinkertn@umich.edu    source_groups = set()
2185341Sstever@gmail.com
2195341Sstever@gmail.com    _current_group_tag = ungrouped_tag
2205341Sstever@gmail.com
2215344Sstever@gmail.com    @staticmethod
2225341Sstever@gmail.com    def link_group_tag(group):
2235341Sstever@gmail.com        return 'link group: %s' % group
2245341Sstever@gmail.com
2254762Snate@binkert.org    @classmethod
2265341Sstever@gmail.com    def set_group(cls, group):
2275344Sstever@gmail.com        new_tag = Source.link_group_tag(group)
2285341Sstever@gmail.com        Source._current_group_tag = new_tag
2294773Snate@binkert.org        Source.source_groups.add(group)
2301858SN/A
2311858SN/A    def _add_link_group_tag(self):
2321085SN/A        self.tags.add(Source._current_group_tag)
2334382Sbinkertn@umich.edu
2344382Sbinkertn@umich.edu    '''Add a c/c++ source file to the build'''
2354762Snate@binkert.org    def __init__(self, source, tags=None, add_tags=None):
2364762Snate@binkert.org        '''specify the source file, and any tags'''
2374762Snate@binkert.org        super(Source, self).__init__(source, tags, add_tags)
2385517Snate@binkert.org        self._add_link_group_tag()
2395517Snate@binkert.org
2405517Snate@binkert.orgclass PySource(SourceFile):
2415517Snate@binkert.org    '''Add a python source file to the named package'''
2425517Snate@binkert.org    invalid_sym_char = re.compile('[^A-z0-9_]')
2435517Snate@binkert.org    modules = {}
2445517Snate@binkert.org    tnodes = {}
2455517Snate@binkert.org    symnames = {}
2465517Snate@binkert.org
2475517Snate@binkert.org    def __init__(self, package, source, tags=None, add_tags=None):
2485517Snate@binkert.org        '''specify the python package, the source file, and any tags'''
2495517Snate@binkert.org        super(PySource, self).__init__(source, tags, add_tags)
2505517Snate@binkert.org
2515517Snate@binkert.org        modname,ext = self.extname
2525517Snate@binkert.org        assert ext == 'py'
2535517Snate@binkert.org
2545517Snate@binkert.org        if package:
2555517Snate@binkert.org            path = package.split('.')
2565517Snate@binkert.org        else:
2575517Snate@binkert.org            path = []
2585517Snate@binkert.org
2595517Snate@binkert.org        modpath = path[:]
2605517Snate@binkert.org        if modname != '__init__':
2615517Snate@binkert.org            modpath += [ modname ]
2625517Snate@binkert.org        modpath = '.'.join(modpath)
2635517Snate@binkert.org
2645517Snate@binkert.org        arcpath = path + [ self.basename ]
2655517Snate@binkert.org        abspath = self.snode.abspath
2665517Snate@binkert.org        if not exists(abspath):
2675517Snate@binkert.org            abspath = self.tnode.abspath
2685517Snate@binkert.org
2695517Snate@binkert.org        self.package = package
2705517Snate@binkert.org        self.modname = modname
2715517Snate@binkert.org        self.modpath = modpath
2725517Snate@binkert.org        self.arcname = joinpath(*arcpath)
2735517Snate@binkert.org        self.abspath = abspath
2745517Snate@binkert.org        self.compiled = File(self.filename + 'c')
2755517Snate@binkert.org        self.cpp = File(self.filename + '.cc')
2765517Snate@binkert.org        self.symname = PySource.invalid_sym_char.sub('_', modpath)
2775517Snate@binkert.org
2785517Snate@binkert.org        PySource.modules[modpath] = self
2795517Snate@binkert.org        PySource.tnodes[self.tnode] = self
2805517Snate@binkert.org        PySource.symnames[self.symname] = self
2815517Snate@binkert.org
2825517Snate@binkert.orgclass SimObject(PySource):
2835517Snate@binkert.org    '''Add a SimObject python file as a python source object and add
2845517Snate@binkert.org    it to a list of sim object modules'''
2855517Snate@binkert.org
2865517Snate@binkert.org    fixed = False
2875517Snate@binkert.org    modnames = []
2885517Snate@binkert.org
2895517Snate@binkert.org    def __init__(self, source, tags=None, add_tags=None):
2905517Snate@binkert.org        '''Specify the source file and any tags (automatically in
2915517Snate@binkert.org        the m5.objects package)'''
2925517Snate@binkert.org        super(SimObject, self).__init__('m5.objects', source, tags, add_tags)
2935517Snate@binkert.org        if self.fixed:
2945522Snate@binkert.org            raise AttributeError, "Too late to call SimObject now."
2955517Snate@binkert.org
2965517Snate@binkert.org        bisect.insort_right(SimObject.modnames, self.modname)
2975517Snate@binkert.org
2985517Snate@binkert.orgclass ProtoBuf(SourceFile):
2994762Snate@binkert.org    '''Add a Protocol Buffer to build'''
3005517Snate@binkert.org
3015517Snate@binkert.org    def __init__(self, source, tags=None, add_tags=None):
3024762Snate@binkert.org        '''Specify the source file, and any tags'''
3035517Snate@binkert.org        super(ProtoBuf, self).__init__(source, tags, add_tags)
3044762Snate@binkert.org
3055517Snate@binkert.org        # Get the file name and the extension
3065517Snate@binkert.org        modname,ext = self.extname
3075517Snate@binkert.org        assert ext == 'proto'
3085517Snate@binkert.org
3095517Snate@binkert.org        # Currently, we stick to generating the C++ headers, so we
3105517Snate@binkert.org        # only need to track the source and header.
3115517Snate@binkert.org        self.cc_file = File(modname + '.pb.cc')
3125517Snate@binkert.org        self.hh_file = File(modname + '.pb.h')
3135517Snate@binkert.org
3145517Snate@binkert.org
3155517Snate@binkert.orgexectuable_classes = []
3165517Snate@binkert.orgclass ExecutableMeta(type):
3175517Snate@binkert.org    '''Meta class for Executables.'''
3185517Snate@binkert.org    all = []
3195517Snate@binkert.org
3205517Snate@binkert.org    def __init__(cls, name, bases, d):
3215517Snate@binkert.org        if not d.pop('abstract', False):
3225517Snate@binkert.org            ExecutableMeta.all.append(cls)
3235517Snate@binkert.org        super(ExecutableMeta, cls).__init__(name, bases, d)
3245517Snate@binkert.org
3255517Snate@binkert.org        cls.all = []
3265517Snate@binkert.org
3275517Snate@binkert.orgclass Executable(object):
3284762Snate@binkert.org    '''Base class for creating an executable from sources.'''
3294762Snate@binkert.org    __metaclass__ = ExecutableMeta
3304762Snate@binkert.org
3314762Snate@binkert.org    abstract = True
3324762Snate@binkert.org
3334762Snate@binkert.org    def __init__(self, target, *srcs_and_filts):
3345517Snate@binkert.org        '''Specify the target name and any sources. Sources that are
3354762Snate@binkert.org        not SourceFiles are evalued with Source().'''
3364762Snate@binkert.org        super(Executable, self).__init__()
3374762Snate@binkert.org        self.all.append(self)
3384762Snate@binkert.org        self.target = target
3394382Sbinkertn@umich.edu
3404382Sbinkertn@umich.edu        isFilter = lambda arg: isinstance(arg, SourceFilter)
3415517Snate@binkert.org        self.filters = filter(isFilter, srcs_and_filts)
3425517Snate@binkert.org        sources = filter(lambda a: not isFilter(a), srcs_and_filts)
3435517Snate@binkert.org
3445517Snate@binkert.org        srcs = SourceList()
3455517Snate@binkert.org        for src in sources:
3465517Snate@binkert.org            if not isinstance(src, SourceFile):
3475517Snate@binkert.org                src = Source(src, tags=[])
3485517Snate@binkert.org            srcs.append(src)
3495517Snate@binkert.org
3505517Snate@binkert.org        self.sources = srcs
3515517Snate@binkert.org        self.dir = Dir('.')
3525517Snate@binkert.org
3535517Snate@binkert.org    def path(self, env):
3545517Snate@binkert.org        return self.dir.File(self.target + '.' + env['EXE_SUFFIX'])
3555517Snate@binkert.org
3565517Snate@binkert.org    def srcs_to_objs(self, env, sources):
3575517Snate@binkert.org        return list([ s.static(env) for s in sources ])
3585517Snate@binkert.org
3595517Snate@binkert.org    @classmethod
3605517Snate@binkert.org    def declare_all(cls, env):
3615517Snate@binkert.org        return list([ instance.declare(env) for instance in cls.all ])
3625517Snate@binkert.org
3635517Snate@binkert.org    def declare(self, env, objs=None):
3645517Snate@binkert.org        if objs is None:
3654762Snate@binkert.org            objs = self.srcs_to_objs(env, self.sources)
3665517Snate@binkert.org
3674382Sbinkertn@umich.edu        if env['STRIP_EXES']:
3684382Sbinkertn@umich.edu            stripped = self.path(env)
3694762Snate@binkert.org            unstripped = env.File(str(stripped) + '.unstripped')
3704382Sbinkertn@umich.edu            if sys.platform == 'sunos5':
3714382Sbinkertn@umich.edu                cmd = 'cp $SOURCE $TARGET; strip $TARGET'
3725517Snate@binkert.org            else:
3734382Sbinkertn@umich.edu                cmd = 'strip $SOURCE -o $TARGET'
3744382Sbinkertn@umich.edu            env.Program(unstripped, objs)
3754762Snate@binkert.org            return env.Command(stripped, unstripped,
3764382Sbinkertn@umich.edu                               MakeAction(cmd, Transform("STRIP")))
3774762Snate@binkert.org        else:
3785517Snate@binkert.org            return env.Program(self.path(env), objs)
3794382Sbinkertn@umich.edu
3804382Sbinkertn@umich.educlass UnitTest(Executable):
3814762Snate@binkert.org    '''Create a UnitTest'''
3824762Snate@binkert.org    def __init__(self, target, *srcs_and_filts, **kwargs):
3834762Snate@binkert.org        super(UnitTest, self).__init__(target, *srcs_and_filts)
3844762Snate@binkert.org
3854762Snate@binkert.org        self.main = kwargs.get('main', False)
3865517Snate@binkert.org
3875517Snate@binkert.org    def declare(self, env):
3885517Snate@binkert.org        sources = list(self.sources)
3895517Snate@binkert.org        for f in self.filters:
3905517Snate@binkert.org            sources = Source.all.apply_filter(f)
3915517Snate@binkert.org        objs = self.srcs_to_objs(env, sources) + env['STATIC_OBJS']
3925517Snate@binkert.org        if self.main:
3935517Snate@binkert.org            objs += env['MAIN_OBJS']
3945517Snate@binkert.org        return super(UnitTest, self).declare(env, objs)
3955517Snate@binkert.org
3965517Snate@binkert.orgclass GTest(Executable):
3975517Snate@binkert.org    '''Create a unit test based on the google test framework.'''
3985517Snate@binkert.org    all = []
3995517Snate@binkert.org    def __init__(self, *srcs_and_filts, **kwargs):
4005517Snate@binkert.org        super(GTest, self).__init__(*srcs_and_filts)
4015517Snate@binkert.org
4025517Snate@binkert.org        self.skip_lib = kwargs.pop('skip_lib', False)
4035517Snate@binkert.org
4045517Snate@binkert.org    @classmethod
4055517Snate@binkert.org    def declare_all(cls, env):
4065517Snate@binkert.org        env = env.Clone()
4075517Snate@binkert.org        env.Append(LIBS=env['GTEST_LIBS'])
4085517Snate@binkert.org        env.Append(CPPFLAGS=env['GTEST_CPPFLAGS'])
4095517Snate@binkert.org        env['GTEST_LIB_SOURCES'] = Source.all.with_tag('gtest lib')
4105517Snate@binkert.org        env['GTEST_OUT_DIR'] = \
4115517Snate@binkert.org            Dir(env['BUILDDIR']).Dir('unittests.' + env['EXE_SUFFIX'])
4125517Snate@binkert.org        return super(GTest, cls).declare_all(env)
4135517Snate@binkert.org
4145517Snate@binkert.org    def declare(self, env):
4155517Snate@binkert.org        sources = list(self.sources)
4165517Snate@binkert.org        if not self.skip_lib:
4175517Snate@binkert.org            sources += env['GTEST_LIB_SOURCES']
4185517Snate@binkert.org        for f in self.filters:
4195517Snate@binkert.org            sources += Source.all.apply_filter(f)
4205517Snate@binkert.org        objs = self.srcs_to_objs(env, sources)
4215517Snate@binkert.org
4225517Snate@binkert.org        binary = super(GTest, self).declare(env, objs)
4235517Snate@binkert.org
4244762Snate@binkert.org        out_dir = env['GTEST_OUT_DIR']
4254762Snate@binkert.org        xml_file = out_dir.Dir(str(self.dir)).File(self.target + '.xml')
4265517Snate@binkert.org        AlwaysBuild(env.Command(xml_file, binary,
4275517Snate@binkert.org            "${SOURCES[0]} --gtest_output=xml:${TARGETS[0]}"))
4284762Snate@binkert.org
4294762Snate@binkert.org        return binary
4304762Snate@binkert.org
4315517Snate@binkert.orgclass Gem5(Executable):
4324762Snate@binkert.org    '''Create a gem5 executable.'''
4334762Snate@binkert.org
4344762Snate@binkert.org    def __init__(self, target):
4355463Snate@binkert.org        super(Gem5, self).__init__(target)
4365517Snate@binkert.org
4374762Snate@binkert.org    def declare(self, env):
4384762Snate@binkert.org        objs = env['MAIN_OBJS'] + env['STATIC_OBJS']
4394762Snate@binkert.org        return super(Gem5, self).declare(env, objs)
4404762Snate@binkert.org
4414762Snate@binkert.org
4424762Snate@binkert.org# Children should have access
4435463Snate@binkert.orgExport('Source')
4445517Snate@binkert.orgExport('PySource')
4454762Snate@binkert.orgExport('SimObject')
4464762Snate@binkert.orgExport('ProtoBuf')
4474762Snate@binkert.orgExport('Executable')
4485517Snate@binkert.orgExport('UnitTest')
4495517Snate@binkert.orgExport('GTest')
4504762Snate@binkert.org
4514762Snate@binkert.org########################################################################
4525517Snate@binkert.org#
4534762Snate@binkert.org# Debug Flags
4544762Snate@binkert.org#
4554762Snate@binkert.orgdebug_flags = {}
4564762Snate@binkert.orgdef DebugFlag(name, desc=None):
4575517Snate@binkert.org    if name in debug_flags:
4584762Snate@binkert.org        raise AttributeError, "Flag %s already specified" % name
4594762Snate@binkert.org    debug_flags[name] = (name, (), desc)
4604762Snate@binkert.org
4614762Snate@binkert.orgdef CompoundFlag(name, flags, desc=None):
4625517Snate@binkert.org    if name in debug_flags:
4635517Snate@binkert.org        raise AttributeError, "Flag %s already specified" % name
4645517Snate@binkert.org
4655517Snate@binkert.org    compound = tuple(flags)
4665517Snate@binkert.org    debug_flags[name] = (name, compound, desc)
4675517Snate@binkert.org
4685517Snate@binkert.orgExport('DebugFlag')
4695517Snate@binkert.orgExport('CompoundFlag')
4705517Snate@binkert.org
4715517Snate@binkert.org########################################################################
4725517Snate@binkert.org#
4735517Snate@binkert.org# Set some compiler variables
4745517Snate@binkert.org#
4755517Snate@binkert.org
4765517Snate@binkert.org# Include file paths are rooted in this directory.  SCons will
4775517Snate@binkert.org# automatically expand '.' to refer to both the source directory and
4785517Snate@binkert.org# the corresponding build directory to pick up generated include
4795517Snate@binkert.org# files.
4805517Snate@binkert.orgenv.Append(CPPPATH=Dir('.'))
4815517Snate@binkert.org
4825517Snate@binkert.orgfor extra_dir in extras_dir_list:
4835517Snate@binkert.org    env.Append(CPPPATH=Dir(extra_dir))
4845517Snate@binkert.org
4855517Snate@binkert.org# Workaround for bug in SCons version > 0.97d20071212
4865517Snate@binkert.org# Scons bug id: 2006 gem5 Bug id: 308
4875517Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True):
4885517Snate@binkert.org    Dir(root[len(base_dir) + 1:])
4895517Snate@binkert.org
4905517Snate@binkert.org########################################################################
4915517Snate@binkert.org#
4925517Snate@binkert.org# Walk the tree and execute all SConscripts in subdirectories
4935517Snate@binkert.org#
4945517Snate@binkert.org
4955517Snate@binkert.orghere = Dir('.').srcnode().abspath
4965517Snate@binkert.orgfor root, dirs, files in os.walk(base_dir, topdown=True):
4975517Snate@binkert.org    if root == here:
4985517Snate@binkert.org        # we don't want to recurse back into this SConscript
4995517Snate@binkert.org        continue
5005517Snate@binkert.org
5015517Snate@binkert.org    if 'SConscript' in files:
5025517Snate@binkert.org        build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:])
5035517Snate@binkert.org        Source.set_group(build_dir)
5045517Snate@binkert.org        SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
5055517Snate@binkert.org
5065517Snate@binkert.orgfor extra_dir in extras_dir_list:
5075517Snate@binkert.org    prefix_len = len(dirname(extra_dir)) + 1
5085517Snate@binkert.org
5095517Snate@binkert.org    # Also add the corresponding build directory to pick up generated
5105517Snate@binkert.org    # include files.
5115517Snate@binkert.org    env.Append(CPPPATH=Dir(joinpath(env['BUILDDIR'], extra_dir[prefix_len:])))
5125517Snate@binkert.org
5135517Snate@binkert.org    for root, dirs, files in os.walk(extra_dir, topdown=True):
5145517Snate@binkert.org        # if build lives in the extras directory, don't walk down it
5155517Snate@binkert.org        if 'build' in dirs:
5165517Snate@binkert.org            dirs.remove('build')
5175517Snate@binkert.org
5185517Snate@binkert.org        if 'SConscript' in files:
5195517Snate@binkert.org            build_dir = joinpath(env['BUILDDIR'], root[prefix_len:])
5205517Snate@binkert.org            SConscript(joinpath(root, 'SConscript'), variant_dir=build_dir)
5215517Snate@binkert.org
5225517Snate@binkert.orgfor opt in export_vars:
5235517Snate@binkert.org    env.ConfigFile(opt)
5245517Snate@binkert.org
5255517Snate@binkert.orgdef makeTheISA(source, target, env):
5265517Snate@binkert.org    isas = [ src.get_contents() for src in source ]
5275517Snate@binkert.org    target_isa = env['TARGET_ISA']
5285517Snate@binkert.org    def define(isa):
5295517Snate@binkert.org        return isa.upper() + '_ISA'
5305517Snate@binkert.org
5315517Snate@binkert.org    def namespace(isa):
5325517Snate@binkert.org        return isa[0].upper() + isa[1:].lower() + 'ISA'
5335517Snate@binkert.org
5345517Snate@binkert.org
5355517Snate@binkert.org    code = code_formatter()
5365517Snate@binkert.org    code('''\
5375517Snate@binkert.org#ifndef __CONFIG_THE_ISA_HH__
5385517Snate@binkert.org#define __CONFIG_THE_ISA_HH__
5395517Snate@binkert.org
5405517Snate@binkert.org''')
5415517Snate@binkert.org
5425517Snate@binkert.org    # create defines for the preprocessing and compile-time determination
5435517Snate@binkert.org    for i,isa in enumerate(isas):
5445517Snate@binkert.org        code('#define $0 $1', define(isa), i + 1)
5455517Snate@binkert.org    code()
5465517Snate@binkert.org
5475517Snate@binkert.org    # create an enum for any run-time determination of the ISA, we
5485517Snate@binkert.org    # reuse the same name as the namespaces
5495517Snate@binkert.org    code('enum class Arch {')
5505517Snate@binkert.org    for i,isa in enumerate(isas):
5515517Snate@binkert.org        if i + 1 == len(isas):
5524762Snate@binkert.org            code('  $0 = $1', namespace(isa), define(isa))
5535517Snate@binkert.org        else:
5545517Snate@binkert.org            code('  $0 = $1,', namespace(isa), define(isa))
5555463Snate@binkert.org    code('};')
5564762Snate@binkert.org
5574762Snate@binkert.org    code('''
5584762Snate@binkert.org
5594382Sbinkertn@umich.edu#define THE_ISA ${{define(target_isa)}}
5605554Snate@binkert.org#define TheISA ${{namespace(target_isa)}}
5614762Snate@binkert.org#define THE_ISA_STR "${{target_isa}}"
5624382Sbinkertn@umich.edu
5634762Snate@binkert.org#endif // __CONFIG_THE_ISA_HH__''')
5644382Sbinkertn@umich.edu
5654762Snate@binkert.org    code.write(str(target[0]))
5664762Snate@binkert.org
5674762Snate@binkert.orgenv.Command('config/the_isa.hh', map(Value, all_isa_list),
5684762Snate@binkert.org            MakeAction(makeTheISA, Transform("CFG ISA", 0)))
5694382Sbinkertn@umich.edu
5704382Sbinkertn@umich.edudef makeTheGPUISA(source, target, env):
5714382Sbinkertn@umich.edu    isas = [ src.get_contents() for src in source ]
5724382Sbinkertn@umich.edu    target_gpu_isa = env['TARGET_GPU_ISA']
5734382Sbinkertn@umich.edu    def define(isa):
5744382Sbinkertn@umich.edu        return isa.upper() + '_ISA'
5754762Snate@binkert.org
5764382Sbinkertn@umich.edu    def namespace(isa):
5775554Snate@binkert.org        return isa[0].upper() + isa[1:].lower() + 'ISA'
5784382Sbinkertn@umich.edu
5794382Sbinkertn@umich.edu
5804762Snate@binkert.org    code = code_formatter()
5815517Snate@binkert.org    code('''\
5825517Snate@binkert.org#ifndef __CONFIG_THE_GPU_ISA_HH__
5835517Snate@binkert.org#define __CONFIG_THE_GPU_ISA_HH__
5845517Snate@binkert.org
5855517Snate@binkert.org''')
5865517Snate@binkert.org
5875522Snate@binkert.org    # create defines for the preprocessing and compile-time determination
5885517Snate@binkert.org    for i,isa in enumerate(isas):
5895517Snate@binkert.org        code('#define $0 $1', define(isa), i + 1)
5905517Snate@binkert.org    code()
5915517Snate@binkert.org
5925517Snate@binkert.org    # create an enum for any run-time determination of the ISA, we
5935522Snate@binkert.org    # reuse the same name as the namespaces
5945522Snate@binkert.org    code('enum class GPUArch {')
5954382Sbinkertn@umich.edu    for i,isa in enumerate(isas):
5965192Ssaidi@eecs.umich.edu        if i + 1 == len(isas):
5975517Snate@binkert.org            code('  $0 = $1', namespace(isa), define(isa))
5985517Snate@binkert.org        else:
5995517Snate@binkert.org            code('  $0 = $1,', namespace(isa), define(isa))
6005517Snate@binkert.org    code('};')
6015517Snate@binkert.org
6025517Snate@binkert.org    code('''
6035517Snate@binkert.org
6045517Snate@binkert.org#define THE_GPU_ISA ${{define(target_gpu_isa)}}
6055517Snate@binkert.org#define TheGpuISA ${{namespace(target_gpu_isa)}}
6065517Snate@binkert.org#define THE_GPU_ISA_STR "${{target_gpu_isa}}"
6075517Snate@binkert.org
6085517Snate@binkert.org#endif // __CONFIG_THE_GPU_ISA_HH__''')
6095517Snate@binkert.org
6105517Snate@binkert.org    code.write(str(target[0]))
6115517Snate@binkert.org
6125517Snate@binkert.orgenv.Command('config/the_gpu_isa.hh', map(Value, all_gpu_isa_list),
6135517Snate@binkert.org            MakeAction(makeTheGPUISA, Transform("CFG ISA", 0)))
6145517Snate@binkert.org
6155517Snate@binkert.org########################################################################
6165517Snate@binkert.org#
6175517Snate@binkert.org# Prevent any SimObjects from being added after this point, they
6185517Snate@binkert.org# should all have been added in the SConscripts above
6195517Snate@binkert.org#
6205517Snate@binkert.orgSimObject.fixed = True
6215517Snate@binkert.org
6225517Snate@binkert.orgclass DictImporter(object):
6235517Snate@binkert.org    '''This importer takes a dictionary of arbitrary module names that
6245517Snate@binkert.org    map to arbitrary filenames.'''
6255517Snate@binkert.org    def __init__(self, modules):
6265517Snate@binkert.org        self.modules = modules
6275517Snate@binkert.org        self.installed = set()
6285517Snate@binkert.org
6295517Snate@binkert.org    def __del__(self):
6305517Snate@binkert.org        self.unload()
6315517Snate@binkert.org
6325517Snate@binkert.org    def unload(self):
6335517Snate@binkert.org        import sys
6345517Snate@binkert.org        for module in self.installed:
6355517Snate@binkert.org            del sys.modules[module]
6365517Snate@binkert.org        self.installed = set()
6375517Snate@binkert.org
6385517Snate@binkert.org    def find_module(self, fullname, path):
6395517Snate@binkert.org        if fullname == 'm5.defines':
6405517Snate@binkert.org            return self
6415517Snate@binkert.org
6425517Snate@binkert.org        if fullname == 'm5.objects':
6435517Snate@binkert.org            return self
6445517Snate@binkert.org
6455517Snate@binkert.org        if fullname.startswith('_m5'):
6465517Snate@binkert.org            return None
6475517Snate@binkert.org
6485517Snate@binkert.org        source = self.modules.get(fullname, None)
6495517Snate@binkert.org        if source is not None and fullname.startswith('m5.objects'):
6505517Snate@binkert.org            return self
6515517Snate@binkert.org
6525517Snate@binkert.org        return None
6535517Snate@binkert.org
6545517Snate@binkert.org    def load_module(self, fullname):
6555517Snate@binkert.org        mod = imp.new_module(fullname)
6565517Snate@binkert.org        sys.modules[fullname] = mod
6575517Snate@binkert.org        self.installed.add(fullname)
6585517Snate@binkert.org
6595517Snate@binkert.org        mod.__loader__ = self
6605517Snate@binkert.org        if fullname == 'm5.objects':
6615517Snate@binkert.org            mod.__path__ = fullname.split('.')
6625517Snate@binkert.org            return mod
6635517Snate@binkert.org
6645517Snate@binkert.org        if fullname == 'm5.defines':
6655517Snate@binkert.org            mod.__dict__['buildEnv'] = m5.util.SmartDict(build_env)
6665517Snate@binkert.org            return mod
6675517Snate@binkert.org
6685517Snate@binkert.org        source = self.modules[fullname]
6695517Snate@binkert.org        if source.modname == '__init__':
6705517Snate@binkert.org            mod.__path__ = source.modpath
6715517Snate@binkert.org        mod.__file__ = source.abspath
6725517Snate@binkert.org
6735517Snate@binkert.org        exec file(source.abspath, 'r') in mod.__dict__
6745517Snate@binkert.org
6755517Snate@binkert.org        return mod
6765517Snate@binkert.org
6775517Snate@binkert.orgimport m5.SimObject
6785517Snate@binkert.orgimport m5.params
6795517Snate@binkert.orgfrom m5.util import code_formatter
6805517Snate@binkert.org
6815517Snate@binkert.orgm5.SimObject.clear()
6825517Snate@binkert.orgm5.params.clear()
6835517Snate@binkert.org
6845517Snate@binkert.org# install the python importer so we can grab stuff from the source
6855517Snate@binkert.org# tree itself.  We can't have SimObjects added after this point or
6865517Snate@binkert.org# else we won't know about them for the rest of the stuff.
6875517Snate@binkert.orgimporter = DictImporter(PySource.modules)
6885517Snate@binkert.orgsys.meta_path[0:0] = [ importer ]
6895517Snate@binkert.org
6905517Snate@binkert.org# import all sim objects so we can populate the all_objects list
6915517Snate@binkert.org# make sure that we're working with a list, then let's sort it
6925517Snate@binkert.orgfor modname in SimObject.modnames:
6935517Snate@binkert.org    exec('from m5.objects import %s' % modname)
6945517Snate@binkert.org
6955517Snate@binkert.org# we need to unload all of the currently imported modules so that they
6965517Snate@binkert.org# will be re-imported the next time the sconscript is run
6975517Snate@binkert.orgimporter.unload()
6985517Snate@binkert.orgsys.meta_path.remove(importer)
6995517Snate@binkert.org
7005517Snate@binkert.orgsim_objects = m5.SimObject.allClasses
7015517Snate@binkert.orgall_enums = m5.params.allEnums
7025517Snate@binkert.org
7035517Snate@binkert.orgfor name,obj in sorted(sim_objects.iteritems()):
7045517Snate@binkert.org    for param in obj._params.local.values():
7055517Snate@binkert.org        # load the ptype attribute now because it depends on the
7065517Snate@binkert.org        # current version of SimObject.allClasses, but when scons
7075517Snate@binkert.org        # actually uses the value, all versions of
7085517Snate@binkert.org        # SimObject.allClasses will have been loaded
7095517Snate@binkert.org        param.ptype
7105517Snate@binkert.org
7115517Snate@binkert.org########################################################################
7125517Snate@binkert.org#
7135517Snate@binkert.org# calculate extra dependencies
7145517Snate@binkert.org#
7155517Snate@binkert.orgmodule_depends = ["m5", "m5.SimObject", "m5.params"]
7165517Snate@binkert.orgdepends = [ PySource.modules[dep].snode for dep in module_depends ]
7175517Snate@binkert.orgdepends.sort(key = lambda x: x.name)
7185517Snate@binkert.org
7195517Snate@binkert.org########################################################################
7205517Snate@binkert.org#
7215517Snate@binkert.org# Commands for the basic automatically generated python files
7225517Snate@binkert.org#
7235517Snate@binkert.org
7245517Snate@binkert.org# Generate Python file containing a dict specifying the current
7255517Snate@binkert.org# buildEnv flags.
7265517Snate@binkert.orgdef makeDefinesPyFile(target, source, env):
7275517Snate@binkert.org    build_env = source[0].get_contents()
7285517Snate@binkert.org
7295517Snate@binkert.org    code = code_formatter()
7305517Snate@binkert.org    code("""
7315517Snate@binkert.orgimport _m5.core
7325517Snate@binkert.orgimport m5.util
7335517Snate@binkert.org
7345517Snate@binkert.orgbuildEnv = m5.util.SmartDict($build_env)
7355517Snate@binkert.org
7365517Snate@binkert.orgcompileDate = _m5.core.compileDate
7375517Snate@binkert.org_globals = globals()
7385517Snate@binkert.orgfor key,val in _m5.core.__dict__.iteritems():
7395517Snate@binkert.org    if key.startswith('flag_'):
7405517Snate@binkert.org        flag = key[5:]
7415517Snate@binkert.org        _globals[flag] = val
7425517Snate@binkert.orgdel _globals
7435517Snate@binkert.org""")
7445517Snate@binkert.org    code.write(target[0].abspath)
7455517Snate@binkert.org
7465517Snate@binkert.orgdefines_info = Value(build_env)
7475517Snate@binkert.org# Generate a file with all of the compile options in it
7485517Snate@binkert.orgenv.Command('python/m5/defines.py', defines_info,
7495517Snate@binkert.org            MakeAction(makeDefinesPyFile, Transform("DEFINES", 0)))
7505517Snate@binkert.orgPySource('m5', 'python/m5/defines.py')
7515517Snate@binkert.org
7525517Snate@binkert.org# Generate python file containing info about the M5 source code
7535517Snate@binkert.orgdef makeInfoPyFile(target, source, env):
7545517Snate@binkert.org    code = code_formatter()
7555517Snate@binkert.org    for src in source:
7565517Snate@binkert.org        data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
7575517Snate@binkert.org        code('$src = ${{repr(data)}}')
7585517Snate@binkert.org    code.write(str(target[0]))
7595517Snate@binkert.org
7605517Snate@binkert.org# Generate a file that wraps the basic top level files
7615517Snate@binkert.orgenv.Command('python/m5/info.py',
7625517Snate@binkert.org            [ '#/COPYING', '#/LICENSE', '#/README', ],
7635517Snate@binkert.org            MakeAction(makeInfoPyFile, Transform("INFO")))
7645517Snate@binkert.orgPySource('m5', 'python/m5/info.py')
7655517Snate@binkert.org
7665517Snate@binkert.org########################################################################
7675517Snate@binkert.org#
7685517Snate@binkert.org# Create all of the SimObject param headers and enum headers
7695517Snate@binkert.org#
7705517Snate@binkert.org
7715517Snate@binkert.orgdef createSimObjectParamStruct(target, source, env):
7725517Snate@binkert.org    assert len(target) == 1 and len(source) == 1
7735517Snate@binkert.org
7745517Snate@binkert.org    name = source[0].get_text_contents()
7755517Snate@binkert.org    obj = sim_objects[name]
7765517Snate@binkert.org
7775517Snate@binkert.org    code = code_formatter()
7785517Snate@binkert.org    obj.cxx_param_decl(code)
7795517Snate@binkert.org    code.write(target[0].abspath)
7805517Snate@binkert.org
7815517Snate@binkert.orgdef createSimObjectCxxConfig(is_header):
7825517Snate@binkert.org    def body(target, source, env):
7835517Snate@binkert.org        assert len(target) == 1 and len(source) == 1
7845517Snate@binkert.org
7855517Snate@binkert.org        name = str(source[0].get_contents())
7865517Snate@binkert.org        obj = sim_objects[name]
7875517Snate@binkert.org
7885192Ssaidi@eecs.umich.edu        code = code_formatter()
7895517Snate@binkert.org        obj.cxx_config_param_file(code, is_header)
7905192Ssaidi@eecs.umich.edu        code.write(target[0].abspath)
7915192Ssaidi@eecs.umich.edu    return body
7925517Snate@binkert.org
7935517Snate@binkert.orgdef createEnumStrings(target, source, env):
7945192Ssaidi@eecs.umich.edu    assert len(target) == 1 and len(source) == 2
7955192Ssaidi@eecs.umich.edu
7965456Ssaidi@eecs.umich.edu    name = source[0].get_text_contents()
7975517Snate@binkert.org    use_python = source[1].read()
7985517Snate@binkert.org    obj = all_enums[name]
7995517Snate@binkert.org
8005517Snate@binkert.org    code = code_formatter()
8015517Snate@binkert.org    obj.cxx_def(code)
8025517Snate@binkert.org    if use_python:
8035517Snate@binkert.org        obj.pybind_def(code)
8045517Snate@binkert.org    code.write(target[0].abspath)
8055517Snate@binkert.org
8065517Snate@binkert.orgdef createEnumDecls(target, source, env):
8075517Snate@binkert.org    assert len(target) == 1 and len(source) == 1
8085517Snate@binkert.org
8095517Snate@binkert.org    name = source[0].get_text_contents()
8105517Snate@binkert.org    obj = all_enums[name]
8115517Snate@binkert.org
8125517Snate@binkert.org    code = code_formatter()
8135517Snate@binkert.org    obj.cxx_decl(code)
8145517Snate@binkert.org    code.write(target[0].abspath)
8155517Snate@binkert.org
8165517Snate@binkert.orgdef createSimObjectPyBindWrapper(target, source, env):
8175517Snate@binkert.org    name = source[0].get_text_contents()
8185517Snate@binkert.org    obj = sim_objects[name]
8195517Snate@binkert.org
8205517Snate@binkert.org    code = code_formatter()
8215517Snate@binkert.org    obj.pybind_decl(code)
8225517Snate@binkert.org    code.write(target[0].abspath)
8235517Snate@binkert.org
8245517Snate@binkert.org# Generate all of the SimObject param C++ struct header files
8255517Snate@binkert.orgparams_hh_files = []
8265517Snate@binkert.orgfor name,simobj in sorted(sim_objects.iteritems()):
8275517Snate@binkert.org    py_source = PySource.modules[simobj.__module__]
8285517Snate@binkert.org    extra_deps = [ py_source.tnode ]
8295456Ssaidi@eecs.umich.edu
8305461Snate@binkert.org    hh_file = File('params/%s.hh' % name)
8315517Snate@binkert.org    params_hh_files.append(hh_file)
8325456Ssaidi@eecs.umich.edu    env.Command(hh_file, Value(name),
8335522Snate@binkert.org                MakeAction(createSimObjectParamStruct, Transform("SO PARAM")))
8345522Snate@binkert.org    env.Depends(hh_file, depends + extra_deps)
8355522Snate@binkert.org
8365522Snate@binkert.org# C++ parameter description files
8375522Snate@binkert.orgif GetOption('with_cxx_config'):
8385522Snate@binkert.org    for name,simobj in sorted(sim_objects.iteritems()):
8395522Snate@binkert.org        py_source = PySource.modules[simobj.__module__]
8405522Snate@binkert.org        extra_deps = [ py_source.tnode ]
8415522Snate@binkert.org
8425517Snate@binkert.org        cxx_config_hh_file = File('cxx_config/%s.hh' % name)
8435522Snate@binkert.org        cxx_config_cc_file = File('cxx_config/%s.cc' % name)
8445522Snate@binkert.org        env.Command(cxx_config_hh_file, Value(name),
8455522Snate@binkert.org                    MakeAction(createSimObjectCxxConfig(True),
8465522Snate@binkert.org                    Transform("CXXCPRHH")))
8475517Snate@binkert.org        env.Command(cxx_config_cc_file, Value(name),
8485522Snate@binkert.org                    MakeAction(createSimObjectCxxConfig(False),
8495522Snate@binkert.org                    Transform("CXXCPRCC")))
8505517Snate@binkert.org        env.Depends(cxx_config_hh_file, depends + extra_deps +
8515522Snate@binkert.org                    [File('params/%s.hh' % name), File('sim/cxx_config.hh')])
8525522Snate@binkert.org        env.Depends(cxx_config_cc_file, depends + extra_deps +
8535522Snate@binkert.org                    [cxx_config_hh_file])
8545522Snate@binkert.org        Source(cxx_config_cc_file)
8555522Snate@binkert.org
8565517Snate@binkert.org    cxx_config_init_cc_file = File('cxx_config/init.cc')
8575522Snate@binkert.org
8585522Snate@binkert.org    def createCxxConfigInitCC(target, source, env):
8595522Snate@binkert.org        assert len(target) == 1 and len(source) == 1
8605522Snate@binkert.org
8615522Snate@binkert.org        code = code_formatter()
8625522Snate@binkert.org
8635522Snate@binkert.org        for name,simobj in sorted(sim_objects.iteritems()):
8645522Snate@binkert.org            if not hasattr(simobj, 'abstract') or not simobj.abstract:
8655522Snate@binkert.org                code('#include "cxx_config/${name}.hh"')
8665522Snate@binkert.org        code()
8675522Snate@binkert.org        code('void cxxConfigInit()')
8685522Snate@binkert.org        code('{')
8695522Snate@binkert.org        code.indent()
8705522Snate@binkert.org        for name,simobj in sorted(sim_objects.iteritems()):
8715522Snate@binkert.org            not_abstract = not hasattr(simobj, 'abstract') or \
8725522Snate@binkert.org                not simobj.abstract
8735522Snate@binkert.org            if not_abstract and 'type' in simobj.__dict__:
8745522Snate@binkert.org                code('cxx_config_directory["${name}"] = '
8755522Snate@binkert.org                     '${name}CxxConfigParams::makeDirectoryEntry();')
8764382Sbinkertn@umich.edu        code.dedent()
8775522Snate@binkert.org        code('}')
8785522Snate@binkert.org        code.write(target[0].abspath)
8794382Sbinkertn@umich.edu
8805522Snate@binkert.org    py_source = PySource.modules[simobj.__module__]
8815522Snate@binkert.org    extra_deps = [ py_source.tnode ]
8825522Snate@binkert.org    env.Command(cxx_config_init_cc_file, Value(name),
8835522Snate@binkert.org        MakeAction(createCxxConfigInitCC, Transform("CXXCINIT")))
8845522Snate@binkert.org    cxx_param_hh_files = ["cxx_config/%s.hh" % simobj
8855522Snate@binkert.org        for name,simobj in sorted(sim_objects.iteritems())
8865522Snate@binkert.org        if not hasattr(simobj, 'abstract') or not simobj.abstract]
8875522Snate@binkert.org    Depends(cxx_config_init_cc_file, cxx_param_hh_files +
8885522Snate@binkert.org            [File('sim/cxx_config.hh')])
8895522Snate@binkert.org    Source(cxx_config_init_cc_file)
8904382Sbinkertn@umich.edu
8915522Snate@binkert.org# Generate all enum header files
8925522Snate@binkert.orgfor name,enum in sorted(all_enums.iteritems()):
8935522Snate@binkert.org    py_source = PySource.modules[enum.__module__]
8945522Snate@binkert.org    extra_deps = [ py_source.tnode ]
8955522Snate@binkert.org
8965522Snate@binkert.org    cc_file = File('enums/%s.cc' % name)
8975522Snate@binkert.org    env.Command(cc_file, [Value(name), Value(env['USE_PYTHON'])],
8985522Snate@binkert.org                MakeAction(createEnumStrings, Transform("ENUM STR")))
8995522Snate@binkert.org    env.Depends(cc_file, depends + extra_deps)
9005522Snate@binkert.org    Source(cc_file)
9015522Snate@binkert.org
9025522Snate@binkert.org    hh_file = File('enums/%s.hh' % name)
9035522Snate@binkert.org    env.Command(hh_file, Value(name),
9045522Snate@binkert.org                MakeAction(createEnumDecls, Transform("ENUMDECL")))
9055522Snate@binkert.org    env.Depends(hh_file, depends + extra_deps)
9065522Snate@binkert.org
9075522Snate@binkert.org# Generate SimObject Python bindings wrapper files
9085522Snate@binkert.orgif env['USE_PYTHON']:
9095522Snate@binkert.org    for name,simobj in sorted(sim_objects.iteritems()):
9105522Snate@binkert.org        py_source = PySource.modules[simobj.__module__]
9115522Snate@binkert.org        extra_deps = [ py_source.tnode ]
9125522Snate@binkert.org        cc_file = File('python/_m5/param_%s.cc' % name)
9135522Snate@binkert.org        env.Command(cc_file, Value(name),
9145522Snate@binkert.org                    MakeAction(createSimObjectPyBindWrapper,
9155522Snate@binkert.org                               Transform("SO PyBind")))
9165522Snate@binkert.org        env.Depends(cc_file, depends + extra_deps)
9175522Snate@binkert.org        Source(cc_file)
9185522Snate@binkert.org
9195522Snate@binkert.org# Build all protocol buffers if we have got protoc and protobuf available
9205522Snate@binkert.orgif env['HAVE_PROTOBUF']:
9215522Snate@binkert.org    for proto in ProtoBuf.all:
9224382Sbinkertn@umich.edu        # Use both the source and header as the target, and the .proto
9234382Sbinkertn@umich.edu        # file as the source. When executing the protoc compiler, also
9244382Sbinkertn@umich.edu        # specify the proto_path to avoid having the generated files
9254382Sbinkertn@umich.edu        # include the path.
9264382Sbinkertn@umich.edu        env.Command([proto.cc_file, proto.hh_file], proto.tnode,
9274382Sbinkertn@umich.edu                    MakeAction('$PROTOC --cpp_out ${TARGET.dir} '
9284382Sbinkertn@umich.edu                               '--proto_path ${SOURCE.dir} $SOURCE',
9294382Sbinkertn@umich.edu                               Transform("PROTOC")))
9304382Sbinkertn@umich.edu
9314382Sbinkertn@umich.edu        # Add the C++ source file
932955SN/A        Source(proto.cc_file, tags=proto.tags)
933955SN/Aelif ProtoBuf.all:
934955SN/A    print('Got protobuf to build, but lacks support!')
935955SN/A    Exit(1)
9361108SN/A
9375601Snate@binkert.org#
9385601Snate@binkert.org# Handle debug flags
9395601Snate@binkert.org#
9405601Snate@binkert.orgdef makeDebugFlagCC(target, source, env):
9415601Snate@binkert.org    assert(len(target) == 1 and len(source) == 1)
9425601Snate@binkert.org
9435601Snate@binkert.org    code = code_formatter()
9445456Ssaidi@eecs.umich.edu
945955SN/A    # delay definition of CompoundFlags until after all the definition
946955SN/A    # of all constituent SimpleFlags
9475601Snate@binkert.org    comp_code = code_formatter()
9485456Ssaidi@eecs.umich.edu
9495456Ssaidi@eecs.umich.edu    # file header
9505456Ssaidi@eecs.umich.edu    code('''
9515456Ssaidi@eecs.umich.edu/*
9525601Snate@binkert.org * DO NOT EDIT THIS FILE! Automatically generated by SCons.
9535456Ssaidi@eecs.umich.edu */
954955SN/A
9555456Ssaidi@eecs.umich.edu#include "base/debug.hh"
9565601Snate@binkert.org
957955SN/Anamespace Debug {
958955SN/A
9592655Sstever@eecs.umich.edu''')
9602655Sstever@eecs.umich.edu
9612655Sstever@eecs.umich.edu    for name, flag in sorted(source[0].read().iteritems()):
9622655Sstever@eecs.umich.edu        n, compound, desc = flag
9632655Sstever@eecs.umich.edu        assert n == name
9645601Snate@binkert.org
9655601Snate@binkert.org        if not compound:
9665601Snate@binkert.org            code('SimpleFlag $name("$name", "$desc");')
9675601Snate@binkert.org        else:
9685522Snate@binkert.org            comp_code('CompoundFlag $name("$name", "$desc",')
9695601Snate@binkert.org            comp_code.indent()
9705601Snate@binkert.org            last = len(compound) - 1
9715601Snate@binkert.org            for i,flag in enumerate(compound):
9725601Snate@binkert.org                if i != last:
9735601Snate@binkert.org                    comp_code('&$flag,')
9745559Snate@binkert.org                else:
9755559Snate@binkert.org                    comp_code('&$flag);')
9765559Snate@binkert.org            comp_code.dedent()
9775559Snate@binkert.org
9785601Snate@binkert.org    code.append(comp_code)
9795601Snate@binkert.org    code()
9805601Snate@binkert.org    code('} // namespace Debug')
9815601Snate@binkert.org
9825601Snate@binkert.org    code.write(str(target[0]))
9835554Snate@binkert.org
9845522Snate@binkert.orgdef makeDebugFlagHH(target, source, env):
9855522Snate@binkert.org    assert(len(target) == 1 and len(source) == 1)
9865601Snate@binkert.org
9875601Snate@binkert.org    val = eval(source[0].get_contents())
9885522Snate@binkert.org    name, compound, desc = val
9895584Snate@binkert.org
9905601Snate@binkert.org    code = code_formatter()
9915601Snate@binkert.org
9925584Snate@binkert.org    # file header boilerplate
9935601Snate@binkert.org    code('''\
9945601Snate@binkert.org/*
9952655Sstever@eecs.umich.edu * DO NOT EDIT THIS FILE! Automatically generated by SCons.
9965601Snate@binkert.org */
9975601Snate@binkert.org
9984007Ssaidi@eecs.umich.edu#ifndef __DEBUG_${name}_HH__
9994596Sbinkertn@umich.edu#define __DEBUG_${name}_HH__
10004007Ssaidi@eecs.umich.edu
10014596Sbinkertn@umich.edunamespace Debug {
10025601Snate@binkert.org''')
10035522Snate@binkert.org
10045601Snate@binkert.org    if compound:
10055522Snate@binkert.org        code('class CompoundFlag;')
10065601Snate@binkert.org    code('class SimpleFlag;')
10075601Snate@binkert.org
10082655Sstever@eecs.umich.edu    if compound:
1009955SN/A        code('extern CompoundFlag $name;')
10103918Ssaidi@eecs.umich.edu        for flag in compound:
10113918Ssaidi@eecs.umich.edu            code('extern SimpleFlag $flag;')
10123918Ssaidi@eecs.umich.edu    else:
10133918Ssaidi@eecs.umich.edu        code('extern SimpleFlag $name;')
10143918Ssaidi@eecs.umich.edu
10153918Ssaidi@eecs.umich.edu    code('''
10163918Ssaidi@eecs.umich.edu}
10173918Ssaidi@eecs.umich.edu
10183918Ssaidi@eecs.umich.edu#endif // __DEBUG_${name}_HH__
10193918Ssaidi@eecs.umich.edu''')
10203918Ssaidi@eecs.umich.edu
10213918Ssaidi@eecs.umich.edu    code.write(str(target[0]))
10223918Ssaidi@eecs.umich.edu
10233918Ssaidi@eecs.umich.edufor name,flag in sorted(debug_flags.iteritems()):
10243940Ssaidi@eecs.umich.edu    n, compound, desc = flag
10253940Ssaidi@eecs.umich.edu    assert n == name
10263940Ssaidi@eecs.umich.edu
10273942Ssaidi@eecs.umich.edu    hh_file = 'debug/%s.hh' % name
10283940Ssaidi@eecs.umich.edu    env.Command(hh_file, Value(flag),
10293515Ssaidi@eecs.umich.edu                MakeAction(makeDebugFlagHH, Transform("TRACING", 0)))
10303918Ssaidi@eecs.umich.edu
10314762Snate@binkert.orgenv.Command('debug/flags.cc', Value(debug_flags),
10323515Ssaidi@eecs.umich.edu            MakeAction(makeDebugFlagCC, Transform("TRACING", 0)))
10332655Sstever@eecs.umich.eduSource('debug/flags.cc')
10343918Ssaidi@eecs.umich.edu
10353619Sbinkertn@umich.edu# version tags
1036955SN/Atags = \
1037955SN/Aenv.Command('sim/tags.cc', None,
10382655Sstever@eecs.umich.edu            MakeAction('util/cpt_upgrader.py --get-cc-file > $TARGET',
10393918Ssaidi@eecs.umich.edu                       Transform("VER TAGS")))
10403619Sbinkertn@umich.eduenv.AlwaysBuild(tags)
1041955SN/A
1042955SN/A# Embed python files.  All .py files that have been indicated by a
10432655Sstever@eecs.umich.edu# PySource() call in a SConscript need to be embedded into the M5
10443918Ssaidi@eecs.umich.edu# library.  To do that, we compile the file to byte code, marshal the
10453619Sbinkertn@umich.edu# byte code, compress it, and then generate a c++ file that
1046955SN/A# inserts the result into an array.
1047955SN/Adef embedPyFile(target, source, env):
10482655Sstever@eecs.umich.edu    def c_str(string):
10493918Ssaidi@eecs.umich.edu        if string is None:
10503683Sstever@eecs.umich.edu            return "0"
10512655Sstever@eecs.umich.edu        return '"%s"' % string
10521869SN/A
10531869SN/A    '''Action function to compile a .py into a code object, marshal
1054    it, compress it, and stick it into an asm file so the code appears
1055    as just bytes with a label in the data section'''
1056
1057    src = file(str(source[0]), 'r').read()
1058
1059    pysource = PySource.tnodes[source[0]]
1060    compiled = compile(src, pysource.abspath, 'exec')
1061    marshalled = marshal.dumps(compiled)
1062    compressed = zlib.compress(marshalled)
1063    data = compressed
1064    sym = pysource.symname
1065
1066    code = code_formatter()
1067    code('''\
1068#include "sim/init.hh"
1069
1070namespace {
1071
1072const uint8_t data_${sym}[] = {
1073''')
1074    code.indent()
1075    step = 16
1076    for i in xrange(0, len(data), step):
1077        x = array.array('B', data[i:i+step])
1078        code(''.join('%d,' % d for d in x))
1079    code.dedent()
1080
1081    code('''};
1082
1083EmbeddedPython embedded_${sym}(
1084    ${{c_str(pysource.arcname)}},
1085    ${{c_str(pysource.abspath)}},
1086    ${{c_str(pysource.modpath)}},
1087    data_${sym},
1088    ${{len(data)}},
1089    ${{len(marshalled)}});
1090
1091} // anonymous namespace
1092''')
1093    code.write(str(target[0]))
1094
1095for source in PySource.all:
1096    env.Command(source.cpp, source.tnode,
1097                MakeAction(embedPyFile, Transform("EMBED PY")))
1098    Source(source.cpp, tags=source.tags, add_tags='python')
1099
1100########################################################################
1101#
1102# Define binaries.  Each different build type (debug, opt, etc.) gets
1103# a slightly different build environment.
1104#
1105
1106# List of constructed environments to pass back to SConstruct
1107date_source = Source('base/date.cc', tags=[])
1108
1109gem5_binary = Gem5('gem5')
1110
1111# Function to create a new build environment as clone of current
1112# environment 'env' with modified object suffix and optional stripped
1113# binary.  Additional keyword arguments are appended to corresponding
1114# build environment vars.
1115def makeEnv(env, label, objsfx, strip=False, disable_partial=False, **kwargs):
1116    # SCons doesn't know to append a library suffix when there is a '.' in the
1117    # name.  Use '_' instead.
1118    libname = 'gem5_' + label
1119    secondary_exename = 'm5.' + label
1120
1121    new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
1122    new_env.Label = label
1123    new_env.Append(**kwargs)
1124
1125    lib_sources = Source.all.with_tag('gem5 lib')
1126
1127    # Without Python, leave out all Python content from the library
1128    # builds.  The option doesn't affect gem5 built as a program
1129    if GetOption('without_python'):
1130        lib_sources = lib_sources.without_tag('python')
1131
1132    static_objs = []
1133    shared_objs = []
1134
1135    for s in lib_sources.with_tag(Source.ungrouped_tag):
1136        static_objs.append(s.static(new_env))
1137        shared_objs.append(s.shared(new_env))
1138
1139    for group in Source.source_groups:
1140        srcs = lib_sources.with_tag(Source.link_group_tag(group))
1141        if not srcs:
1142            continue
1143
1144        group_static = [ s.static(new_env) for s in srcs ]
1145        group_shared = [ s.shared(new_env) for s in srcs ]
1146
1147        # If partial linking is disabled, add these sources to the build
1148        # directly, and short circuit this loop.
1149        if disable_partial:
1150            static_objs.extend(group_static)
1151            shared_objs.extend(group_shared)
1152            continue
1153
1154        # Set up the static partially linked objects.
1155        file_name = new_env.subst("${OBJPREFIX}lib${OBJSUFFIX}.partial")
1156        target = File(joinpath(group, file_name))
1157        partial = env.PartialStatic(target=target, source=group_static)
1158        static_objs.extend(partial)
1159
1160        # Set up the shared partially linked objects.
1161        file_name = new_env.subst("${SHOBJPREFIX}lib${SHOBJSUFFIX}.partial")
1162        target = File(joinpath(group, file_name))
1163        partial = env.PartialShared(target=target, source=group_shared)
1164        shared_objs.extend(partial)
1165
1166    static_date = date_source.static(new_env)
1167    new_env.Depends(static_date, static_objs)
1168    static_objs.extend(static_date)
1169
1170    shared_date = date_source.shared(new_env)
1171    new_env.Depends(shared_date, shared_objs)
1172    shared_objs.extend(shared_date)
1173
1174    main_objs = [ s.static(new_env) for s in Source.all.with_tag('main') ]
1175
1176    # First make a library of everything but main() so other programs can
1177    # link against m5.
1178    static_lib = new_env.StaticLibrary(libname, static_objs)
1179    shared_lib = new_env.SharedLibrary(libname, shared_objs)
1180
1181    # Keep track of the object files generated so far so Executables can
1182    # include them.
1183    new_env['STATIC_OBJS'] = static_objs
1184    new_env['SHARED_OBJS'] = shared_objs
1185    new_env['MAIN_OBJS'] = main_objs
1186
1187    new_env['STATIC_LIB'] = static_lib
1188    new_env['SHARED_LIB'] = shared_lib
1189
1190    # Record some settings for building Executables.
1191    new_env['EXE_SUFFIX'] = label
1192    new_env['STRIP_EXES'] = strip
1193
1194    for cls in ExecutableMeta.all:
1195        cls.declare_all(new_env)
1196
1197    new_env.M5Binary = File(gem5_binary.path(new_env))
1198
1199    new_env.Command(secondary_exename, new_env.M5Binary,
1200            MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
1201
1202    # Set up regression tests.
1203    SConscript(os.path.join(env.root.abspath, 'tests', 'SConscript'),
1204               variant_dir=Dir('tests').Dir(new_env.Label),
1205               exports={ 'env' : new_env }, duplicate=False)
1206
1207# Start out with the compiler flags common to all compilers,
1208# i.e. they all use -g for opt and -g -pg for prof
1209ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],
1210           'perf' : ['-g']}
1211
1212# Start out with the linker flags common to all linkers, i.e. -pg for
1213# prof, and -lprofiler for perf. The -lprofile flag is surrounded by
1214# no-as-needed and as-needed as the binutils linker is too clever and
1215# simply doesn't link to the library otherwise.
1216ldflags = {'debug' : [], 'opt' : [], 'fast' : [], 'prof' : ['-pg'],
1217           'perf' : ['-Wl,--no-as-needed', '-lprofiler', '-Wl,--as-needed']}
1218
1219# For Link Time Optimization, the optimisation flags used to compile
1220# individual files are decoupled from those used at link time
1221# (i.e. you can compile with -O3 and perform LTO with -O0), so we need
1222# to also update the linker flags based on the target.
1223if env['GCC']:
1224    if sys.platform == 'sunos5':
1225        ccflags['debug'] += ['-gstabs+']
1226    else:
1227        ccflags['debug'] += ['-ggdb3']
1228    ldflags['debug'] += ['-O0']
1229    # opt, fast, prof and perf all share the same cc flags, also add
1230    # the optimization to the ldflags as LTO defers the optimization
1231    # to link time
1232    for target in ['opt', 'fast', 'prof', 'perf']:
1233        ccflags[target] += ['-O3']
1234        ldflags[target] += ['-O3']
1235
1236    ccflags['fast'] += env['LTO_CCFLAGS']
1237    ldflags['fast'] += env['LTO_LDFLAGS']
1238elif env['CLANG']:
1239    ccflags['debug'] += ['-g', '-O0']
1240    # opt, fast, prof and perf all share the same cc flags
1241    for target in ['opt', 'fast', 'prof', 'perf']:
1242        ccflags[target] += ['-O3']
1243else:
1244    print('Unknown compiler, please fix compiler options')
1245    Exit(1)
1246
1247
1248# To speed things up, we only instantiate the build environments we
1249# need.  We try to identify the needed environment for each target; if
1250# we can't, we fall back on instantiating all the environments just to
1251# be safe.
1252target_types = ['debug', 'opt', 'fast', 'prof', 'perf']
1253obj2target = {'do': 'debug', 'o': 'opt', 'fo': 'fast', 'po': 'prof',
1254              'gpo' : 'perf'}
1255
1256def identifyTarget(t):
1257    ext = t.split('.')[-1]
1258    if ext in target_types:
1259        return ext
1260    if obj2target.has_key(ext):
1261        return obj2target[ext]
1262    match = re.search(r'/tests/([^/]+)/', t)
1263    if match and match.group(1) in target_types:
1264        return match.group(1)
1265    return 'all'
1266
1267needed_envs = [identifyTarget(target) for target in BUILD_TARGETS]
1268if 'all' in needed_envs:
1269    needed_envs += target_types
1270
1271# Debug binary
1272if 'debug' in needed_envs:
1273    makeEnv(env, 'debug', '.do',
1274            CCFLAGS = Split(ccflags['debug']),
1275            CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
1276            LINKFLAGS = Split(ldflags['debug']))
1277
1278# Optimized binary
1279if 'opt' in needed_envs:
1280    makeEnv(env, 'opt', '.o',
1281            CCFLAGS = Split(ccflags['opt']),
1282            CPPDEFINES = ['TRACING_ON=1'],
1283            LINKFLAGS = Split(ldflags['opt']))
1284
1285# "Fast" binary
1286if 'fast' in needed_envs:
1287    disable_partial = \
1288            env.get('BROKEN_INCREMENTAL_LTO', False) and \
1289            GetOption('force_lto')
1290    makeEnv(env, 'fast', '.fo', strip = True,
1291            CCFLAGS = Split(ccflags['fast']),
1292            CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1293            LINKFLAGS = Split(ldflags['fast']),
1294            disable_partial=disable_partial)
1295
1296# Profiled binary using gprof
1297if 'prof' in needed_envs:
1298    makeEnv(env, 'prof', '.po',
1299            CCFLAGS = Split(ccflags['prof']),
1300            CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1301            LINKFLAGS = Split(ldflags['prof']))
1302
1303# Profiled binary using google-pprof
1304if 'perf' in needed_envs:
1305    makeEnv(env, 'perf', '.gpo',
1306            CCFLAGS = Split(ccflags['perf']),
1307            CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1308            LINKFLAGS = Split(ldflags['perf']))
1309