SConscript revision 5192
1955SN/A# -*- mode:python -*-
2955SN/A
310841Sandreas.sandberg@arm.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
49812Sandreas.hansson@arm.com# All rights reserved.
59812Sandreas.hansson@arm.com#
69812Sandreas.hansson@arm.com# Redistribution and use in source and binary forms, with or without
79812Sandreas.hansson@arm.com# modification, are permitted provided that the following conditions are
89812Sandreas.hansson@arm.com# met: redistributions of source code must retain the above copyright
99812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer;
109812Sandreas.hansson@arm.com# redistributions in binary form must reproduce the above copyright
119812Sandreas.hansson@arm.com# notice, this list of conditions and the following disclaimer in the
129812Sandreas.hansson@arm.com# documentation and/or other materials provided with the distribution;
139812Sandreas.hansson@arm.com# neither the name of the copyright holders nor the names of its
149812Sandreas.hansson@arm.com# contributors may be used to endorse or promote products derived from
157816Ssteve.reinhardt@amd.com# this software without specific prior written permission.
165871Snate@binkert.org#
171762SN/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.
28955SN/A#
29955SN/A# Authors: Nathan Binkert
30955SN/A
31955SN/Aimport imp
32955SN/Aimport os
33955SN/Aimport sys
34955SN/A
35955SN/Afrom os.path import basename
36955SN/Afrom os.path import join as joinpath
37955SN/Afrom os.path import exists
38955SN/Afrom os.path import isdir
39955SN/Afrom os.path import isfile
40955SN/A
41955SN/Aimport SCons
422665Ssaidi@eecs.umich.edu
432665Ssaidi@eecs.umich.edu# This file defines how to build a particular configuration of M5
445863Snate@binkert.org# based on variable settings in the 'env' build environment.
45955SN/A
46955SN/AImport('*')
47955SN/A
48955SN/A# Children need to see the environment
49955SN/AExport('env')
508878Ssteve.reinhardt@amd.com
512632Sstever@eecs.umich.edudef sort_list(_list):
528878Ssteve.reinhardt@amd.com    """return a sorted copy of '_list'"""
532632Sstever@eecs.umich.edu    if isinstance(_list, list):
54955SN/A        _list = _list[:]
558878Ssteve.reinhardt@amd.com    else:
562632Sstever@eecs.umich.edu        _list = list(_list)
572761Sstever@eecs.umich.edu    _list.sort()
582632Sstever@eecs.umich.edu    return _list
592632Sstever@eecs.umich.edu
602632Sstever@eecs.umich.educlass PySourceFile(object):
612761Sstever@eecs.umich.edu    def __init__(self, package, source):
622761Sstever@eecs.umich.edu        filename = str(source)
632761Sstever@eecs.umich.edu        pyname = basename(filename)
648878Ssteve.reinhardt@amd.com        assert pyname.endswith('.py')
658878Ssteve.reinhardt@amd.com        name = pyname[:-3]
662761Sstever@eecs.umich.edu        path = package.split('.')
672761Sstever@eecs.umich.edu        modpath = path
682761Sstever@eecs.umich.edu        if name != '__init__':
692761Sstever@eecs.umich.edu            modpath += [name]
702761Sstever@eecs.umich.edu        modpath = '.'.join(modpath)
718878Ssteve.reinhardt@amd.com
728878Ssteve.reinhardt@amd.com        arcpath = package.split('.') + [ pyname + 'c' ]
732632Sstever@eecs.umich.edu        arcname = joinpath(*arcpath)
742632Sstever@eecs.umich.edu
758878Ssteve.reinhardt@amd.com        self.source = source
768878Ssteve.reinhardt@amd.com        self.pyname = pyname
772632Sstever@eecs.umich.edu        self.srcpath = source.srcnode().abspath
78955SN/A        self.package = package
79955SN/A        self.modpath = modpath
80955SN/A        self.arcname = arcname
815863Snate@binkert.org        self.filename = filename
825863Snate@binkert.org        self.compiled = File(filename + 'c')
835863Snate@binkert.org
845863Snate@binkert.org########################################################################
855863Snate@binkert.org# Code for adding source files of various types
865863Snate@binkert.org#
875863Snate@binkert.orgcc_sources = []
885863Snate@binkert.orgdef Source(source):
895863Snate@binkert.org    '''Add a C/C++ source file to the build'''
905863Snate@binkert.org    if not isinstance(source, SCons.Node.FS.File):
915863Snate@binkert.org        source = File(source)
928878Ssteve.reinhardt@amd.com
935863Snate@binkert.org    cc_sources.append(source)
945863Snate@binkert.org
955863Snate@binkert.orgpy_sources = []
969812Sandreas.hansson@arm.comdef PySource(package, source):
979812Sandreas.hansson@arm.com    '''Add a python source file to the named package'''
985863Snate@binkert.org    if not isinstance(source, SCons.Node.FS.File):
999812Sandreas.hansson@arm.com        source = File(source)
1005863Snate@binkert.org
1015863Snate@binkert.org    source = PySourceFile(package, source)
1025863Snate@binkert.org    py_sources.append(source)
1039812Sandreas.hansson@arm.com
1049812Sandreas.hansson@arm.comsim_objects_fixed = False
1055863Snate@binkert.orgsim_object_modfiles = set()
1065863Snate@binkert.orgdef SimObject(source):
1078878Ssteve.reinhardt@amd.com    '''Add a SimObject python file as a python source object and add
1085863Snate@binkert.org    it to a list of sim object modules'''
1095863Snate@binkert.org
1105863Snate@binkert.org    if sim_objects_fixed:
1116654Snate@binkert.org        raise AttributeError, "Too late to call SimObject now."
11210196SCurtis.Dunham@arm.com
113955SN/A    if not isinstance(source, SCons.Node.FS.File):
1145396Ssaidi@eecs.umich.edu        source = File(source)
1155863Snate@binkert.org
1165863Snate@binkert.org    PySource('m5.objects', source)
1174202Sbinkertn@umich.edu    modfile = basename(str(source))
1185863Snate@binkert.org    assert modfile.endswith('.py')
1195863Snate@binkert.org    modname = modfile[:-3]
1205863Snate@binkert.org    sim_object_modfiles.add(modname)
1215863Snate@binkert.org
122955SN/Aswig_sources = []
1236654Snate@binkert.orgdef SwigSource(package, source):
1245273Sstever@gmail.com    '''Add a swig file to build'''
1255871Snate@binkert.org    if not isinstance(source, SCons.Node.FS.File):
1265273Sstever@gmail.com        source = File(source)
1276655Snate@binkert.org    val = source,package
1288878Ssteve.reinhardt@amd.com    swig_sources.append(val)
1296655Snate@binkert.org
1306655Snate@binkert.org# Children should have access
1319219Spower.jg@gmail.comExport('Source')
1326655Snate@binkert.orgExport('PySource')
1335871Snate@binkert.orgExport('SimObject')
1346654Snate@binkert.orgExport('SwigSource')
1358947Sandreas.hansson@arm.com
1365396Ssaidi@eecs.umich.edu########################################################################
1378120Sgblack@eecs.umich.edu#
1388120Sgblack@eecs.umich.edu# Trace Flags
1398120Sgblack@eecs.umich.edu#
1408120Sgblack@eecs.umich.eduall_flags = {}
1418120Sgblack@eecs.umich.edutrace_flags = []
1428120Sgblack@eecs.umich.edudef TraceFlag(name, desc=''):
1438120Sgblack@eecs.umich.edu    if name in all_flags:
1448120Sgblack@eecs.umich.edu        raise AttributeError, "Flag %s already specified" % name
1458879Ssteve.reinhardt@amd.com    flag = (name, (), desc)
1468879Ssteve.reinhardt@amd.com    trace_flags.append(flag)
1478879Ssteve.reinhardt@amd.com    all_flags[name] = ()
1488879Ssteve.reinhardt@amd.com
1498879Ssteve.reinhardt@amd.comdef CompoundFlag(name, flags, desc=''):
1508879Ssteve.reinhardt@amd.com    if name in all_flags:
1518879Ssteve.reinhardt@amd.com        raise AttributeError, "Flag %s already specified" % name
1528879Ssteve.reinhardt@amd.com
1538879Ssteve.reinhardt@amd.com    compound = tuple(flags)
1548879Ssteve.reinhardt@amd.com    for flag in compound:
1558879Ssteve.reinhardt@amd.com        if flag not in all_flags:
1568879Ssteve.reinhardt@amd.com            raise AttributeError, "Trace flag %s not found" % flag
1578879Ssteve.reinhardt@amd.com        if all_flags[flag]:
1588120Sgblack@eecs.umich.edu            raise AttributeError, \
1598120Sgblack@eecs.umich.edu                "Compound flag can't point to another compound flag"
1608120Sgblack@eecs.umich.edu
1618120Sgblack@eecs.umich.edu    flag = (name, compound, desc)
1628120Sgblack@eecs.umich.edu    trace_flags.append(flag)
1638120Sgblack@eecs.umich.edu    all_flags[name] = compound
1648120Sgblack@eecs.umich.edu
1658120Sgblack@eecs.umich.eduExport('TraceFlag')
1668120Sgblack@eecs.umich.eduExport('CompoundFlag')
1678120Sgblack@eecs.umich.edu
1688120Sgblack@eecs.umich.edu########################################################################
1698120Sgblack@eecs.umich.edu#
1708120Sgblack@eecs.umich.edu# Set some compiler variables
1718120Sgblack@eecs.umich.edu#
1728879Ssteve.reinhardt@amd.com
1738879Ssteve.reinhardt@amd.com# Include file paths are rooted in this directory.  SCons will
1748879Ssteve.reinhardt@amd.com# automatically expand '.' to refer to both the source directory and
1758879Ssteve.reinhardt@amd.com# the corresponding build directory to pick up generated include
17610458Sandreas.hansson@arm.com# files.
17710458Sandreas.hansson@arm.comenv.Append(CPPPATH=Dir('.'))
17810458Sandreas.hansson@arm.com
1798879Ssteve.reinhardt@amd.com# Add a flag defining what THE_ISA should be for all compilation
1808879Ssteve.reinhardt@amd.comenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
1818879Ssteve.reinhardt@amd.com
1828879Ssteve.reinhardt@amd.com########################################################################
1839227Sandreas.hansson@arm.com#
1849227Sandreas.hansson@arm.com# Walk the tree and execute all SConscripts
1858879Ssteve.reinhardt@amd.com#
1868879Ssteve.reinhardt@amd.comsrcdir = env['SRCDIR']
1878879Ssteve.reinhardt@amd.comfor root, dirs, files in os.walk(srcdir, topdown=True):
1888879Ssteve.reinhardt@amd.com    if root == srcdir:
18910453SAndrew.Bardsley@arm.com        # we don't want to recurse back into this SConscript
19010453SAndrew.Bardsley@arm.com        continue
19110453SAndrew.Bardsley@arm.com
19210456SCurtis.Dunham@arm.com    if 'SConscript' in files:
19310456SCurtis.Dunham@arm.com        # strip off the srcdir part since scons will try to find the
19410456SCurtis.Dunham@arm.com        # script in the build directory
19510457Sandreas.hansson@arm.com        base = root[len(srcdir) + 1:]
19610457Sandreas.hansson@arm.com        SConscript(joinpath(base, 'SConscript'))
1978120Sgblack@eecs.umich.edu
1988947Sandreas.hansson@arm.comextra_string = env['EXTRAS']
1997816Ssteve.reinhardt@amd.comif extra_string and extra_string != '' and not extra_string.isspace():
2005871Snate@binkert.org    for extra in extra_string.split(':'):
2015871Snate@binkert.org        extra = os.path.expanduser(extra)
2026121Snate@binkert.org        extra = os.path.normpath(extra)
2035871Snate@binkert.org        env.Append(CPPPATH=[Dir(extra)])
2045871Snate@binkert.org        for root, dirs, files in os.walk(extra, topdown=True):
2059926Sstan.czerniawski@arm.com            if 'SConscript' in files:
2069926Sstan.czerniawski@arm.com                subdir = root[len(os.path.dirname(extra))+1:]
2079119Sandreas.hansson@arm.com                build_dir = joinpath(env['BUILDDIR'], subdir)
20810068Sandreas.hansson@arm.com                SConscript(joinpath(root, 'SConscript'), build_dir=build_dir)
20910068Sandreas.hansson@arm.com
210955SN/Afor opt in env.ExportOptions:
2119416SAndreas.Sandberg@ARM.com    env.ConfigFile(opt)
21211212Sjoseph.gross@amd.com
21311212Sjoseph.gross@amd.com########################################################################
21411212Sjoseph.gross@amd.com#
21511212Sjoseph.gross@amd.com# Prevent any SimObjects from being added after this point, they
21611212Sjoseph.gross@amd.com# should all have been added in the SConscripts above
2179416SAndreas.Sandberg@ARM.com#
2189416SAndreas.Sandberg@ARM.comsim_objects_fixed = True
2195871Snate@binkert.org
22010584Sandreas.hansson@arm.com########################################################################
2219416SAndreas.Sandberg@ARM.com#
2229416SAndreas.Sandberg@ARM.com# Manually turn python/generate.py into a python module and import it
2235871Snate@binkert.org#
224955SN/Agenerate_file = File('python/generate.py')
22510671Sandreas.hansson@arm.comgenerate_module = imp.new_module('generate')
22610671Sandreas.hansson@arm.comsys.modules['generate'] = generate_module
22710671Sandreas.hansson@arm.comexec file(generate_file.srcnode().abspath, 'r') in generate_module.__dict__
22810671Sandreas.hansson@arm.com
2298881Smarc.orr@gmail.com########################################################################
2306121Snate@binkert.org#
2316121Snate@binkert.org# build a generate
2321533SN/A#
2339239Sandreas.hansson@arm.comfrom generate import Generate
2349239Sandreas.hansson@arm.comoptionDict = dict([(opt, env[opt]) for opt in env.ExportOptions])
2359239Sandreas.hansson@arm.comgenerate = Generate(py_sources, sim_object_modfiles, optionDict)
2369239Sandreas.hansson@arm.comm5 = generate.m5
2379239Sandreas.hansson@arm.com
2389239Sandreas.hansson@arm.com########################################################################
2399239Sandreas.hansson@arm.com#
2409239Sandreas.hansson@arm.com# calculate extra dependencies
2419239Sandreas.hansson@arm.com#
2429239Sandreas.hansson@arm.commodule_depends = ["m5", "m5.SimObject", "m5.params"]
2439239Sandreas.hansson@arm.commodule_depends = [ File(generate.py_modules[dep]) for dep in module_depends ]
2449239Sandreas.hansson@arm.comfile_depends = [ generate_file ]
2456655Snate@binkert.orgdepends = module_depends + file_depends
2466655Snate@binkert.org
2476655Snate@binkert.org########################################################################
2486655Snate@binkert.org#
2495871Snate@binkert.org# Commands for the basic automatically generated python files
2505871Snate@binkert.org#
2515863Snate@binkert.org
2525871Snate@binkert.org# Generate a file with all of the compile options in it
2538878Ssteve.reinhardt@amd.comenv.Command('python/m5/defines.py', Value(optionDict),
2545871Snate@binkert.org            generate.makeDefinesPyFile)
2555871Snate@binkert.orgPySource('m5', 'python/m5/defines.py')
2565871Snate@binkert.org
2575863Snate@binkert.org# Generate a file that wraps the basic top level files
2586121Snate@binkert.orgenv.Command('python/m5/info.py',
2595863Snate@binkert.org            [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ],
2605871Snate@binkert.org            generate.makeInfoPyFile)
2618336Ssteve.reinhardt@amd.comPySource('m5', 'python/m5/info.py')
2628336Ssteve.reinhardt@amd.com
2638336Ssteve.reinhardt@amd.com# Generate an __init__.py file for the objects package
2648336Ssteve.reinhardt@amd.comenv.Command('python/m5/objects/__init__.py',
2654678Snate@binkert.org            [ Value(o) for o in sort_list(sim_object_modfiles) ],
2668336Ssteve.reinhardt@amd.com            generate.makeObjectsInitFile)
2678336Ssteve.reinhardt@amd.comPySource('m5.objects', 'python/m5/objects/__init__.py')
2688336Ssteve.reinhardt@amd.com
2694678Snate@binkert.org########################################################################
2704678Snate@binkert.org#
2714678Snate@binkert.org# Create all of the SimObject param headers and enum headers
2724678Snate@binkert.org#
2737827Snate@binkert.org
2747827Snate@binkert.org# Generate all of the SimObject param struct header files
2758336Ssteve.reinhardt@amd.comparams_hh_files = []
2764678Snate@binkert.orgfor name,simobj in generate.sim_objects.iteritems():
2778336Ssteve.reinhardt@amd.com    extra_deps = [ File(generate.py_modules[simobj.__module__]) ]
2788336Ssteve.reinhardt@amd.com
2798336Ssteve.reinhardt@amd.com    hh_file = File('params/%s.hh' % name)
2808336Ssteve.reinhardt@amd.com    params_hh_files.append(hh_file)
2818336Ssteve.reinhardt@amd.com    env.Command(hh_file, Value(name), generate.createSimObjectParam)
2828336Ssteve.reinhardt@amd.com    env.Depends(hh_file, depends + extra_deps)
2835871Snate@binkert.org
2845871Snate@binkert.org# Generate any parameter header files needed
2858336Ssteve.reinhardt@amd.comfor name,param in generate.params.iteritems():
2868336Ssteve.reinhardt@amd.com    if isinstance(param, m5.params.VectorParamDesc):
2878336Ssteve.reinhardt@amd.com        ext = 'vptype'
2888336Ssteve.reinhardt@amd.com    else:
2898336Ssteve.reinhardt@amd.com        ext = 'ptype'
2905871Snate@binkert.org
2918336Ssteve.reinhardt@amd.com    i_file = File('params/%s_%s.i' % (name, ext))
2928336Ssteve.reinhardt@amd.com    env.Command(i_file, Value(name), generate.createSwigParam)
2938336Ssteve.reinhardt@amd.com    env.Depends(i_file, depends)
2948336Ssteve.reinhardt@amd.com
2958336Ssteve.reinhardt@amd.com# Generate all enum header files
2964678Snate@binkert.orgfor name,enum in generate.enums.iteritems():
2975871Snate@binkert.org    extra_deps = [ File(generate.py_modules[enum.__module__]) ]
2984678Snate@binkert.org
2998336Ssteve.reinhardt@amd.com    cc_file = File('enums/%s.cc' % name)
3008336Ssteve.reinhardt@amd.com    env.Command(cc_file, Value(name), generate.createEnumStrings)
3018336Ssteve.reinhardt@amd.com    env.Depends(cc_file, depends + extra_deps)
3028336Ssteve.reinhardt@amd.com    Source(cc_file)
3038336Ssteve.reinhardt@amd.com
3048336Ssteve.reinhardt@amd.com    hh_file = File('enums/%s.hh' % name)
3058336Ssteve.reinhardt@amd.com    env.Command(hh_file, Value(name), generate.createEnumParam)
3068336Ssteve.reinhardt@amd.com    env.Depends(hh_file, depends + extra_deps)
3078336Ssteve.reinhardt@amd.com
3088336Ssteve.reinhardt@amd.com# Build the big monolithic swigged params module (wraps all SimObject
3098336Ssteve.reinhardt@amd.com# param structs and enum structs)
3108336Ssteve.reinhardt@amd.comparams_file = File('params/params.i')
3118336Ssteve.reinhardt@amd.comnames = sort_list(generate.sim_objects.keys())
3128336Ssteve.reinhardt@amd.comenv.Command(params_file, [ Value(v) for v in names ],
3138336Ssteve.reinhardt@amd.com            generate.buildParams)
3148336Ssteve.reinhardt@amd.comenv.Depends(params_file, params_hh_files + depends)
3158336Ssteve.reinhardt@amd.comSwigSource('m5.objects', params_file)
3165871Snate@binkert.org
3176121Snate@binkert.org# Build all swig modules
318955SN/Aswig_modules = []
319955SN/Afor source,package in swig_sources:
3202632Sstever@eecs.umich.edu    filename = str(source)
3212632Sstever@eecs.umich.edu    assert filename.endswith('.i')
322955SN/A
323955SN/A    base = '.'.join(filename.split('.')[:-1])
324955SN/A    module = basename(base)
325955SN/A    cc_file = base + '_wrap.cc'
3268878Ssteve.reinhardt@amd.com    py_file = base + '.py'
327955SN/A
3282632Sstever@eecs.umich.edu    env.Command([cc_file, py_file], source,
3292632Sstever@eecs.umich.edu                '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
3302632Sstever@eecs.umich.edu                '-o ${TARGETS[0]} $SOURCES')
3312632Sstever@eecs.umich.edu    env.Depends(py_file, source)
3322632Sstever@eecs.umich.edu    env.Depends(cc_file, source)
3332632Sstever@eecs.umich.edu
3342632Sstever@eecs.umich.edu    swig_modules.append(Value(module))
3358268Ssteve.reinhardt@amd.com    Source(cc_file)
3368268Ssteve.reinhardt@amd.com    PySource(package, py_file)
3378268Ssteve.reinhardt@amd.com
3388268Ssteve.reinhardt@amd.com# Generate the main swig init file
3398268Ssteve.reinhardt@amd.comenv.Command('swig/init.cc', swig_modules, generate.makeSwigInit)
3408268Ssteve.reinhardt@amd.comSource('swig/init.cc')
3418268Ssteve.reinhardt@amd.com
3422632Sstever@eecs.umich.edu# Generate traceflags.py
3432632Sstever@eecs.umich.eduflags = [ Value(f) for f in trace_flags ]
3442632Sstever@eecs.umich.eduenv.Command('base/traceflags.py', flags, generate.traceFlagsPy)
3452632Sstever@eecs.umich.eduPySource('m5', 'base/traceflags.py')
3468268Ssteve.reinhardt@amd.com
3472632Sstever@eecs.umich.eduenv.Command('base/traceflags.hh', flags, generate.traceFlagsHH)
3488268Ssteve.reinhardt@amd.comenv.Command('base/traceflags.cc', flags, generate.traceFlagsCC)
3498268Ssteve.reinhardt@amd.comSource('base/traceflags.cc')
3508268Ssteve.reinhardt@amd.com
3518268Ssteve.reinhardt@amd.com# Build the zip file
3523718Sstever@eecs.umich.edupy_compiled = []
3532634Sstever@eecs.umich.edupy_zip_depends = []
3542634Sstever@eecs.umich.edufor source in py_sources:
3555863Snate@binkert.org    env.Command(source.compiled, source.source, generate.compilePyFile)
3562638Sstever@eecs.umich.edu    py_compiled.append(source.compiled)
3578268Ssteve.reinhardt@amd.com
3582632Sstever@eecs.umich.edu    # make the zipfile depend on the archive name so that the archive
3592632Sstever@eecs.umich.edu    # is rebuilt if the name changes
3602632Sstever@eecs.umich.edu    py_zip_depends.append(Value(source.arcname))
3612632Sstever@eecs.umich.edu
3622632Sstever@eecs.umich.edu# Add the zip file target to the environment.
3631858SN/Am5zip = File('m5py.zip')
3643716Sstever@eecs.umich.eduenv.Command(m5zip, py_compiled, generate.buildPyZip)
3652638Sstever@eecs.umich.eduenv.Depends(m5zip, py_zip_depends)
3662638Sstever@eecs.umich.edu
3672638Sstever@eecs.umich.edu########################################################################
3682638Sstever@eecs.umich.edu#
3692638Sstever@eecs.umich.edu# Define binaries.  Each different build type (debug, opt, etc.) gets
3702638Sstever@eecs.umich.edu# a slightly different build environment.
3712638Sstever@eecs.umich.edu#
3725863Snate@binkert.org
3735863Snate@binkert.org# List of constructed environments to pass back to SConstruct
3745863Snate@binkert.orgenvList = []
375955SN/A
3765341Sstever@gmail.com# This function adds the specified sources to the given build
3775341Sstever@gmail.com# environment, and returns a list of all the corresponding SCons
3785863Snate@binkert.org# Object nodes (including an extra one for date.cc).  We explicitly
3797756SAli.Saidi@ARM.com# add the Object nodes so we can set up special dependencies for
3805341Sstever@gmail.com# date.cc.
3816121Snate@binkert.orgdef make_objs(sources, env):
3824494Ssaidi@eecs.umich.edu    objs = [env.Object(s) for s in sources]
3836121Snate@binkert.org    # make date.cc depend on all other objects so it always gets
3841105SN/A    # recompiled whenever anything else does
3852667Sstever@eecs.umich.edu    date_obj = env.Object('base/date.cc')
3862667Sstever@eecs.umich.edu    env.Depends(date_obj, objs)
3872667Sstever@eecs.umich.edu    objs.append(date_obj)
3882667Sstever@eecs.umich.edu    return objs
3896121Snate@binkert.org
3902667Sstever@eecs.umich.edu# Function to create a new build environment as clone of current
3915341Sstever@gmail.com# environment 'env' with modified object suffix and optional stripped
3925863Snate@binkert.org# binary.  Additional keyword arguments are appended to corresponding
3935341Sstever@gmail.com# build environment vars.
3945341Sstever@gmail.comdef makeEnv(label, objsfx, strip = False, **kwargs):
3955341Sstever@gmail.com    newEnv = env.Copy(OBJSUFFIX=objsfx)
3968120Sgblack@eecs.umich.edu    newEnv.Label = label
3975341Sstever@gmail.com    newEnv.Append(**kwargs)
3988120Sgblack@eecs.umich.edu    exe = 'm5.' + label  # final executable
3995341Sstever@gmail.com    bin = exe + '.bin'   # executable w/o appended Python zip archive
4008120Sgblack@eecs.umich.edu    newEnv.Program(bin, make_objs(cc_sources, newEnv))
4016121Snate@binkert.org    if strip:
4026121Snate@binkert.org        stripped_bin = bin + '.stripped'
4038980Ssteve.reinhardt@amd.com        if sys.platform == 'sunos5':
4049396Sandreas.hansson@arm.com            cmd = 'cp $SOURCE $TARGET; strip $TARGET'
4055397Ssaidi@eecs.umich.edu        else:
4065397Ssaidi@eecs.umich.edu            cmd = 'strip $SOURCE -o $TARGET'
4077727SAli.Saidi@ARM.com        newEnv.Command(stripped_bin, bin, cmd)
4088268Ssteve.reinhardt@amd.com        bin = stripped_bin
4096168Snate@binkert.org    targets = newEnv.Concat(exe, [bin, 'm5py.zip'])
4105341Sstever@gmail.com    newEnv.M5Binary = targets[0]
4118120Sgblack@eecs.umich.edu    envList.append(newEnv)
4128120Sgblack@eecs.umich.edu
4138120Sgblack@eecs.umich.edu# Debug binary
4146814Sgblack@eecs.umich.educcflags = {}
4155863Snate@binkert.orgif env['GCC']:
4168120Sgblack@eecs.umich.edu    if sys.platform == 'sunos5':
4175341Sstever@gmail.com        ccflags['debug'] = '-gstabs+'
4185863Snate@binkert.org    else:
4198268Ssteve.reinhardt@amd.com        ccflags['debug'] = '-ggdb3'
4206121Snate@binkert.org    ccflags['opt'] = '-g -O3'
4216121Snate@binkert.org    ccflags['fast'] = '-O3'
4228268Ssteve.reinhardt@amd.com    ccflags['prof'] = '-O3 -g -pg'
4235742Snate@binkert.orgelif env['SUNCC']:
4245742Snate@binkert.org    ccflags['debug'] = '-g0'
4255341Sstever@gmail.com    ccflags['opt'] = '-g -O'
4265742Snate@binkert.org    ccflags['fast'] = '-fast'
4275742Snate@binkert.org    ccflags['prof'] = '-fast -g -pg'
4285341Sstever@gmail.comelif env['ICC']:
4296017Snate@binkert.org    ccflags['debug'] = '-g -O0'
4306121Snate@binkert.org    ccflags['opt'] = '-g -O'
4316017Snate@binkert.org    ccflags['fast'] = '-fast'
4327816Ssteve.reinhardt@amd.com    ccflags['prof'] = '-fast -g -pg'
4337756SAli.Saidi@ARM.comelse:
4347756SAli.Saidi@ARM.com    print 'Unknown compiler, please fix compiler options'
4357756SAli.Saidi@ARM.com    Exit(1)
4367756SAli.Saidi@ARM.com
4377756SAli.Saidi@ARM.commakeEnv('debug', '.do',
4387756SAli.Saidi@ARM.com        CCFLAGS = Split(ccflags['debug']),
4397756SAli.Saidi@ARM.com        CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
4407756SAli.Saidi@ARM.com
4417816Ssteve.reinhardt@amd.com# Optimized binary
4427816Ssteve.reinhardt@amd.commakeEnv('opt', '.o',
4437816Ssteve.reinhardt@amd.com        CCFLAGS = Split(ccflags['opt']),
4447816Ssteve.reinhardt@amd.com        CPPDEFINES = ['TRACING_ON=1'])
4457816Ssteve.reinhardt@amd.com
4467816Ssteve.reinhardt@amd.com# "Fast" binary
4477816Ssteve.reinhardt@amd.commakeEnv('fast', '.fo', strip = True,
4487816Ssteve.reinhardt@amd.com        CCFLAGS = Split(ccflags['fast']),
4497816Ssteve.reinhardt@amd.com        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
4507816Ssteve.reinhardt@amd.com
4517756SAli.Saidi@ARM.com# Profiled binary
4527816Ssteve.reinhardt@amd.commakeEnv('prof', '.po',
4537816Ssteve.reinhardt@amd.com        CCFLAGS = Split(ccflags['prof']),
4547816Ssteve.reinhardt@amd.com        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
4557816Ssteve.reinhardt@amd.com        LINKFLAGS = '-pg')
4567816Ssteve.reinhardt@amd.com
4577816Ssteve.reinhardt@amd.comReturn('envList')
4587816Ssteve.reinhardt@amd.com