SConscript revision 5344
14661Sksewell@umich.edu# -*- mode:python -*-
25268Sksewell@umich.edu
35268Sksewell@umich.edu# Copyright (c) 2004-2005 The Regents of The University of Michigan
44661Sksewell@umich.edu# All rights reserved.
55268Sksewell@umich.edu#
65268Sksewell@umich.edu# Redistribution and use in source and binary forms, with or without
75268Sksewell@umich.edu# modification, are permitted provided that the following conditions are
85268Sksewell@umich.edu# met: redistributions of source code must retain the above copyright
95268Sksewell@umich.edu# notice, this list of conditions and the following disclaimer;
105268Sksewell@umich.edu# redistributions in binary form must reproduce the above copyright
115268Sksewell@umich.edu# notice, this list of conditions and the following disclaimer in the
125268Sksewell@umich.edu# documentation and/or other materials provided with the distribution;
135268Sksewell@umich.edu# neither the name of the copyright holders nor the names of its
145268Sksewell@umich.edu# contributors may be used to endorse or promote products derived from
154661Sksewell@umich.edu# this software without specific prior written permission.
165268Sksewell@umich.edu#
175268Sksewell@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
185268Sksewell@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
195268Sksewell@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
205268Sksewell@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
215268Sksewell@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
225268Sksewell@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
235268Sksewell@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
245268Sksewell@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
255268Sksewell@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
265268Sksewell@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
275222Sksewell@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
285254Sksewell@umich.edu#
294661Sksewell@umich.edu# Authors: Nathan Binkert
304661Sksewell@umich.edu
314661Sksewell@umich.eduimport imp
324661Sksewell@umich.eduimport os
334661Sksewell@umich.eduimport sys
344661Sksewell@umich.edu
354661Sksewell@umich.edufrom os.path import basename, exists, isdir, isfile, join as joinpath
364661Sksewell@umich.edu
374661Sksewell@umich.eduimport SCons
384661Sksewell@umich.edu
394661Sksewell@umich.edu# This file defines how to build a particular configuration of M5
408229Snate@binkert.org# based on variable settings in the 'env' build environment.
418229Snate@binkert.org
424661Sksewell@umich.eduImport('*')
436329Sgblack@eecs.umich.edu
444661Sksewell@umich.edu# Children need to see the environment
456376Sgblack@eecs.umich.eduExport('env')
466329Sgblack@eecs.umich.edu
474661Sksewell@umich.edudef sort_list(_list):
4812334Sgabeblack@google.com    """return a sorted copy of '_list'"""
494661Sksewell@umich.edu    if isinstance(_list, list):
5013899Sgabeblack@google.com        _list = _list[:]
514661Sksewell@umich.edu    else:
524661Sksewell@umich.edu        _list = list(_list)
534661Sksewell@umich.edu    _list.sort()
544661Sksewell@umich.edu    return _list
5513899Sgabeblack@google.com
5613899Sgabeblack@google.comclass PySourceFile(object):
5713899Sgabeblack@google.com    def __init__(self, package, source):
5813899Sgabeblack@google.com        filename = str(source)
5913899Sgabeblack@google.com        pyname = basename(filename)
6013899Sgabeblack@google.com        assert pyname.endswith('.py')
6113899Sgabeblack@google.com        name = pyname[:-3]
6213899Sgabeblack@google.com        path = package.split('.')
6313899Sgabeblack@google.com        modpath = path
6413899Sgabeblack@google.com        if name != '__init__':
6513899Sgabeblack@google.com            modpath += [name]
6613899Sgabeblack@google.com        modpath = '.'.join(modpath)
6713899Sgabeblack@google.com
6813899Sgabeblack@google.com        arcpath = package.split('.') + [ pyname + 'c' ]
6913899Sgabeblack@google.com        arcname = joinpath(*arcpath)
7013899Sgabeblack@google.com
7113899Sgabeblack@google.com        self.source = source
7213899Sgabeblack@google.com        self.pyname = pyname
7313899Sgabeblack@google.com        self.srcpath = source.srcnode().abspath
7413899Sgabeblack@google.com        self.package = package
7513899Sgabeblack@google.com        self.modpath = modpath
7613899Sgabeblack@google.com        self.arcname = arcname
7713899Sgabeblack@google.com        self.filename = filename
7813899Sgabeblack@google.com        self.compiled = File(filename + 'c')
7913899Sgabeblack@google.com
8013899Sgabeblack@google.com########################################################################
8113899Sgabeblack@google.com# Code for adding source files of various types
8213899Sgabeblack@google.com#
8313899Sgabeblack@google.comcc_sources = []
8413899Sgabeblack@google.comdef Source(source):
8513899Sgabeblack@google.com    '''Add a C/C++ source file to the build'''
8613899Sgabeblack@google.com    if not isinstance(source, SCons.Node.FS.File):
8713899Sgabeblack@google.com        source = File(source)
8813899Sgabeblack@google.com
8913899Sgabeblack@google.com    cc_sources.append(source)
9013899Sgabeblack@google.com
9113899Sgabeblack@google.compy_sources = []
9213899Sgabeblack@google.comdef PySource(package, source):
9313899Sgabeblack@google.com    '''Add a python source file to the named package'''
9413899Sgabeblack@google.com    if not isinstance(source, SCons.Node.FS.File):
9513899Sgabeblack@google.com        source = File(source)
9613899Sgabeblack@google.com
9713899Sgabeblack@google.com    source = PySourceFile(package, source)
9813899Sgabeblack@google.com    py_sources.append(source)
9913899Sgabeblack@google.com
10013899Sgabeblack@google.comsim_objects_fixed = False
10113899Sgabeblack@google.comsim_object_modfiles = set()
10213899Sgabeblack@google.comdef SimObject(source):
10313899Sgabeblack@google.com    '''Add a SimObject python file as a python source object and add
10413899Sgabeblack@google.com    it to a list of sim object modules'''
10513899Sgabeblack@google.com
10613899Sgabeblack@google.com    if sim_objects_fixed:
10713899Sgabeblack@google.com        raise AttributeError, "Too late to call SimObject now."
10813899Sgabeblack@google.com
10913899Sgabeblack@google.com    if not isinstance(source, SCons.Node.FS.File):
11013899Sgabeblack@google.com        source = File(source)
11113899Sgabeblack@google.com
11213899Sgabeblack@google.com    PySource('m5.objects', source)
11313899Sgabeblack@google.com    modfile = basename(str(source))
11413899Sgabeblack@google.com    assert modfile.endswith('.py')
11513899Sgabeblack@google.com    modname = modfile[:-3]
11613899Sgabeblack@google.com    sim_object_modfiles.add(modname)
1174661Sksewell@umich.edu
1184661Sksewell@umich.eduswig_sources = []
1194661Sksewell@umich.edudef SwigSource(package, source):
1204661Sksewell@umich.edu    '''Add a swig file to build'''
1216383Sgblack@eecs.umich.edu    if not isinstance(source, SCons.Node.FS.File):
1226376Sgblack@eecs.umich.edu        source = File(source)
1234661Sksewell@umich.edu    val = source,package
1244661Sksewell@umich.edu    swig_sources.append(val)
1254661Sksewell@umich.edu
1264661Sksewell@umich.edu# Children should have access
1274661Sksewell@umich.eduExport('Source')
1284661Sksewell@umich.eduExport('PySource')
1296383Sgblack@eecs.umich.eduExport('SimObject')
1306376Sgblack@eecs.umich.eduExport('SwigSource')
1314661Sksewell@umich.edu
1324661Sksewell@umich.edu########################################################################
1334661Sksewell@umich.edu#
1344661Sksewell@umich.edu# Trace Flags
1354661Sksewell@umich.edu#
1364661Sksewell@umich.eduall_flags = {}
1374661Sksewell@umich.edutrace_flags = []
1384661Sksewell@umich.edudef TraceFlag(name, desc=''):
1394661Sksewell@umich.edu    if name in all_flags:
1404661Sksewell@umich.edu        raise AttributeError, "Flag %s already specified" % name
1416378Sgblack@eecs.umich.edu    flag = (name, (), desc)
1426378Sgblack@eecs.umich.edu    trace_flags.append(flag)
1437720Sgblack@eecs.umich.edu    all_flags[name] = ()
1447720Sgblack@eecs.umich.edu
1454661Sksewell@umich.edudef CompoundFlag(name, flags, desc=''):
1466378Sgblack@eecs.umich.edu    if name in all_flags:
1477823Ssteve.reinhardt@amd.com        raise AttributeError, "Flag %s already specified" % name
1487720Sgblack@eecs.umich.edu
1494661Sksewell@umich.edu    compound = tuple(flags)
1504661Sksewell@umich.edu    for flag in compound:
1514661Sksewell@umich.edu        if flag not in all_flags:
1524661Sksewell@umich.edu            raise AttributeError, "Trace flag %s not found" % flag
1534661Sksewell@umich.edu        if all_flags[flag]:
1544661Sksewell@umich.edu            raise AttributeError, \
1554661Sksewell@umich.edu                "Compound flag can't point to another compound flag"
1564661Sksewell@umich.edu
1574661Sksewell@umich.edu    flag = (name, compound, desc)
1587720Sgblack@eecs.umich.edu    trace_flags.append(flag)
1594661Sksewell@umich.edu    all_flags[name] = compound
1604661Sksewell@umich.edu
1617720Sgblack@eecs.umich.eduExport('TraceFlag')
16210407Smitch.hayenga@arm.comExport('CompoundFlag')
1634661Sksewell@umich.edu
1646378Sgblack@eecs.umich.edu########################################################################
1657823Ssteve.reinhardt@amd.com#
1664661Sksewell@umich.edu# Set some compiler variables
1674661Sksewell@umich.edu#
1684661Sksewell@umich.edu
1694661Sksewell@umich.edu# Include file paths are rooted in this directory.  SCons will
1704661Sksewell@umich.edu# automatically expand '.' to refer to both the source directory and
1714661Sksewell@umich.edu# the corresponding build directory to pick up generated include
1724661Sksewell@umich.edu# files.
1736383Sgblack@eecs.umich.eduenv.Append(CPPPATH=Dir('.'))
1746376Sgblack@eecs.umich.edu
1754661Sksewell@umich.edu# Add a flag defining what THE_ISA should be for all compilation
1764661Sksewell@umich.eduenv.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
1776221Snate@binkert.org
1786376Sgblack@eecs.umich.edu########################################################################
17913899Sgabeblack@google.com#
1806383Sgblack@eecs.umich.edu# Walk the tree and execute all SConscripts in subdirectories
1814661Sksewell@umich.edu#
1826424Snate@binkert.org
1834661Sksewell@umich.edufor base_dir in base_dir_list:
1846376Sgblack@eecs.umich.edu    here = Dir('.').srcnode().abspath
18513899Sgabeblack@google.com    for root, dirs, files in os.walk(base_dir, topdown=True):
18612104Snathanael.premillieu@arm.com        if root == here:
1874661Sksewell@umich.edu            # we don't want to recurse back into this SConscript
1886376Sgblack@eecs.umich.edu            continue
18913899Sgabeblack@google.com
19012104Snathanael.premillieu@arm.com        if 'SConscript' in files:
1914661Sksewell@umich.edu            build_dir = joinpath(env['BUILDDIR'], root[len(base_dir) + 1:])
1926376Sgblack@eecs.umich.edu            SConscript(joinpath(root, 'SConscript'), build_dir=build_dir)
1936376Sgblack@eecs.umich.edu
1944661Sksewell@umich.edufor opt in env.ExportOptions:
19513899Sgabeblack@google.com    env.ConfigFile(opt)
19612104Snathanael.premillieu@arm.com
19713899Sgabeblack@google.com########################################################################
1984661Sksewell@umich.edu#
1996383Sgblack@eecs.umich.edu# Prevent any SimObjects from being added after this point, they
2006383Sgblack@eecs.umich.edu# should all have been added in the SConscripts above
2014661Sksewell@umich.edu#
2024661Sksewell@umich.edusim_objects_fixed = True
2036376Sgblack@eecs.umich.edu
2044661Sksewell@umich.edu########################################################################
2056376Sgblack@eecs.umich.edu#
2064661Sksewell@umich.edu# Manually turn python/generate.py into a python module and import it
2076376Sgblack@eecs.umich.edu#
2084661Sksewell@umich.edugenerate_file = File('python/generate.py')
2096376Sgblack@eecs.umich.edugenerate_module = imp.new_module('generate')
2104661Sksewell@umich.edusys.modules['generate'] = generate_module
2116376Sgblack@eecs.umich.eduexec file(generate_file.srcnode().abspath, 'r') in generate_module.__dict__
2124661Sksewell@umich.edu
2136376Sgblack@eecs.umich.edu########################################################################
2144661Sksewell@umich.edu#
2154661Sksewell@umich.edu# build a generate
21613899Sgabeblack@google.com#
2176376Sgblack@eecs.umich.edufrom generate import Generate
2184661Sksewell@umich.eduoptionDict = dict([(opt, env[opt]) for opt in env.ExportOptions])
2194661Sksewell@umich.edugenerate = Generate(py_sources, sim_object_modfiles, optionDict)
2204661Sksewell@umich.edum5 = generate.m5
2214661Sksewell@umich.edu
2224661Sksewell@umich.edu########################################################################
2235991Ssteve.reinhardt@amd.com#
2244661Sksewell@umich.edu# calculate extra dependencies
2254661Sksewell@umich.edu#
2264661Sksewell@umich.edumodule_depends = ["m5", "m5.SimObject", "m5.params"]
2274661Sksewell@umich.edumodule_depends = [ File(generate.py_modules[dep]) for dep in module_depends ]
2286383Sgblack@eecs.umich.edufile_depends = [ generate_file ]
2296383Sgblack@eecs.umich.edudepends = module_depends + file_depends
2306376Sgblack@eecs.umich.edu
2316383Sgblack@eecs.umich.edu########################################################################
23210474Sandreas.hansson@arm.com#
2334661Sksewell@umich.edu# Commands for the basic automatically generated python files
2344661Sksewell@umich.edu#
2354661Sksewell@umich.edu
2364661Sksewell@umich.edu# Generate a file with all of the compile options in it
2374661Sksewell@umich.eduenv.Command('python/m5/defines.py', Value(optionDict),
2384661Sksewell@umich.edu            generate.makeDefinesPyFile)
2394661Sksewell@umich.eduPySource('m5', 'python/m5/defines.py')
2404661Sksewell@umich.edu
2414661Sksewell@umich.edu# Generate a file that wraps the basic top level files
2426383Sgblack@eecs.umich.eduenv.Command('python/m5/info.py',
2436376Sgblack@eecs.umich.edu            [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ],
2444661Sksewell@umich.edu            generate.makeInfoPyFile)
2454661Sksewell@umich.eduPySource('m5', 'python/m5/info.py')
2464661Sksewell@umich.edu
2474661Sksewell@umich.edu# Generate an __init__.py file for the objects package
2486383Sgblack@eecs.umich.eduenv.Command('python/m5/objects/__init__.py',
2494661Sksewell@umich.edu            [ Value(o) for o in sort_list(sim_object_modfiles) ],
2506221Snate@binkert.org            generate.makeObjectsInitFile)
2516376Sgblack@eecs.umich.eduPySource('m5.objects', 'python/m5/objects/__init__.py')
25213899Sgabeblack@google.com
2536383Sgblack@eecs.umich.edu########################################################################
2546376Sgblack@eecs.umich.edu#
25513899Sgabeblack@google.com# Create all of the SimObject param headers and enum headers
2566383Sgblack@eecs.umich.edu#
2576376Sgblack@eecs.umich.edu
25813899Sgabeblack@google.com# Generate all of the SimObject param struct header files
2596383Sgblack@eecs.umich.eduparams_hh_files = []
2604661Sksewell@umich.edufor name,simobj in generate.sim_objects.iteritems():
2616376Sgblack@eecs.umich.edu    extra_deps = [ File(generate.py_modules[simobj.__module__]) ]
2626376Sgblack@eecs.umich.edu
2636376Sgblack@eecs.umich.edu    hh_file = File('params/%s.hh' % name)
2646376Sgblack@eecs.umich.edu    params_hh_files.append(hh_file)
2656376Sgblack@eecs.umich.edu    env.Command(hh_file, Value(name), generate.createSimObjectParam)
2664661Sksewell@umich.edu    env.Depends(hh_file, depends + extra_deps)
2674661Sksewell@umich.edu
2684661Sksewell@umich.edu# Generate any parameter header files needed
2694661Sksewell@umich.edufor name,param in generate.params.iteritems():
2704661Sksewell@umich.edu    if isinstance(param, m5.params.VectorParamDesc):
2716383Sgblack@eecs.umich.edu        ext = 'vptype'
2726376Sgblack@eecs.umich.edu    else:
2736383Sgblack@eecs.umich.edu        ext = 'ptype'
2746376Sgblack@eecs.umich.edu
2757823Ssteve.reinhardt@amd.com    i_file = File('params/%s_%s.i' % (name, ext))
2764661Sksewell@umich.edu    env.Command(i_file, Value(name), generate.createSwigParam)
2774661Sksewell@umich.edu    env.Depends(i_file, depends)
2785561Snate@binkert.org
2796383Sgblack@eecs.umich.edu# Generate all enum header files
2806376Sgblack@eecs.umich.edufor name,enum in generate.enums.iteritems():
2816383Sgblack@eecs.umich.edu    extra_deps = [ File(generate.py_modules[enum.__module__]) ]
28210474Sandreas.hansson@arm.com
2834661Sksewell@umich.edu    cc_file = File('enums/%s.cc' % name)
2844661Sksewell@umich.edu    env.Command(cc_file, Value(name), generate.createEnumStrings)
2854661Sksewell@umich.edu    env.Depends(cc_file, depends + extra_deps)
2866383Sgblack@eecs.umich.edu    Source(cc_file)
2876383Sgblack@eecs.umich.edu
2886383Sgblack@eecs.umich.edu    hh_file = File('enums/%s.hh' % name)
2894661Sksewell@umich.edu    env.Command(hh_file, Value(name), generate.createEnumParam)
2906376Sgblack@eecs.umich.edu    env.Depends(hh_file, depends + extra_deps)
2916376Sgblack@eecs.umich.edu
29210474Sandreas.hansson@arm.com# Build the big monolithic swigged params module (wraps all SimObject
2934661Sksewell@umich.edu# param structs and enum structs)
2944661Sksewell@umich.eduparams_file = File('params/params.i')
2954661Sksewell@umich.edunames = sort_list(generate.sim_objects.keys())
2964661Sksewell@umich.eduenv.Command(params_file, [ Value(v) for v in names ],
2974661Sksewell@umich.edu            generate.buildParams)
2984661Sksewell@umich.eduenv.Depends(params_file, params_hh_files + depends)
2994661Sksewell@umich.eduSwigSource('m5.objects', params_file)
3004661Sksewell@umich.edu
3014661Sksewell@umich.edu# Build all swig modules
3024661Sksewell@umich.eduswig_modules = []
3034661Sksewell@umich.edufor source,package in swig_sources:
3044661Sksewell@umich.edu    filename = str(source)
3054661Sksewell@umich.edu    assert filename.endswith('.i')
3064661Sksewell@umich.edu
3074661Sksewell@umich.edu    base = '.'.join(filename.split('.')[:-1])
3084661Sksewell@umich.edu    module = basename(base)
3096383Sgblack@eecs.umich.edu    cc_file = base + '_wrap.cc'
3106383Sgblack@eecs.umich.edu    py_file = base + '.py'
3114661Sksewell@umich.edu
3126376Sgblack@eecs.umich.edu    env.Command([cc_file, py_file], source,
3136376Sgblack@eecs.umich.edu                '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
3146376Sgblack@eecs.umich.edu                '-o ${TARGETS[0]} $SOURCES')
3154661Sksewell@umich.edu    env.Depends(py_file, source)
3166383Sgblack@eecs.umich.edu    env.Depends(cc_file, source)
3174661Sksewell@umich.edu
3184661Sksewell@umich.edu    swig_modules.append(Value(module))
3194661Sksewell@umich.edu    Source(cc_file)
3204661Sksewell@umich.edu    PySource(package, py_file)
3214661Sksewell@umich.edu
3224661Sksewell@umich.edu# Generate the main swig init file
3234661Sksewell@umich.eduenv.Command('swig/init.cc', swig_modules, generate.makeSwigInit)
3244661Sksewell@umich.eduSource('swig/init.cc')
3254661Sksewell@umich.edu
3264661Sksewell@umich.edu# Generate traceflags.py
3276383Sgblack@eecs.umich.eduflags = [ Value(f) for f in trace_flags ]
3286383Sgblack@eecs.umich.eduenv.Command('base/traceflags.py', flags, generate.traceFlagsPy)
3294661Sksewell@umich.eduPySource('m5', 'base/traceflags.py')
3306376Sgblack@eecs.umich.edu
3316376Sgblack@eecs.umich.eduenv.Command('base/traceflags.hh', flags, generate.traceFlagsHH)
3326376Sgblack@eecs.umich.eduenv.Command('base/traceflags.cc', flags, generate.traceFlagsCC)
3334661Sksewell@umich.eduSource('base/traceflags.cc')
3346383Sgblack@eecs.umich.edu
3354661Sksewell@umich.edu# Build the zip file
3364661Sksewell@umich.edupy_compiled = []
3374661Sksewell@umich.edupy_zip_depends = []
3384661Sksewell@umich.edufor source in py_sources:
3394661Sksewell@umich.edu    env.Command(source.compiled, source.source, generate.compilePyFile)
3404661Sksewell@umich.edu    py_compiled.append(source.compiled)
341
342    # make the zipfile depend on the archive name so that the archive
343    # is rebuilt if the name changes
344    py_zip_depends.append(Value(source.arcname))
345
346# Add the zip file target to the environment.
347m5zip = File('m5py.zip')
348env.Command(m5zip, py_compiled, generate.buildPyZip)
349env.Depends(m5zip, py_zip_depends)
350
351########################################################################
352#
353# Define binaries.  Each different build type (debug, opt, etc.) gets
354# a slightly different build environment.
355#
356
357# List of constructed environments to pass back to SConstruct
358envList = []
359
360# This function adds the specified sources to the given build
361# environment, and returns a list of all the corresponding SCons
362# Object nodes (including an extra one for date.cc).  We explicitly
363# add the Object nodes so we can set up special dependencies for
364# date.cc.
365def make_objs(sources, env):
366    objs = [env.Object(s) for s in sources]
367    # make date.cc depend on all other objects so it always gets
368    # recompiled whenever anything else does
369    date_obj = env.Object('base/date.cc')
370    env.Depends(date_obj, objs)
371    objs.append(date_obj)
372    return objs
373
374# Function to create a new build environment as clone of current
375# environment 'env' with modified object suffix and optional stripped
376# binary.  Additional keyword arguments are appended to corresponding
377# build environment vars.
378def makeEnv(label, objsfx, strip = False, **kwargs):
379    newEnv = env.Copy(OBJSUFFIX=objsfx)
380    newEnv.Label = label
381    newEnv.Append(**kwargs)
382    exe = 'm5.' + label  # final executable
383    bin = exe + '.bin'   # executable w/o appended Python zip archive
384    newEnv.Program(bin, make_objs(cc_sources, newEnv))
385    if strip:
386        stripped_bin = bin + '.stripped'
387        if sys.platform == 'sunos5':
388            cmd = 'cp $SOURCE $TARGET; strip $TARGET'
389        else:
390            cmd = 'strip $SOURCE -o $TARGET'
391        newEnv.Command(stripped_bin, bin, cmd)
392        bin = stripped_bin
393    targets = newEnv.Concat(exe, [bin, 'm5py.zip'])
394    newEnv.M5Binary = targets[0]
395    envList.append(newEnv)
396
397# Debug binary
398ccflags = {}
399if env['GCC']:
400    if sys.platform == 'sunos5':
401        ccflags['debug'] = '-gstabs+'
402    else:
403        ccflags['debug'] = '-ggdb3'
404    ccflags['opt'] = '-g -O3'
405    ccflags['fast'] = '-O3'
406    ccflags['prof'] = '-O3 -g -pg'
407elif env['SUNCC']:
408    ccflags['debug'] = '-g0'
409    ccflags['opt'] = '-g -O'
410    ccflags['fast'] = '-fast'
411    ccflags['prof'] = '-fast -g -pg'
412elif env['ICC']:
413    ccflags['debug'] = '-g -O0'
414    ccflags['opt'] = '-g -O'
415    ccflags['fast'] = '-fast'
416    ccflags['prof'] = '-fast -g -pg'
417else:
418    print 'Unknown compiler, please fix compiler options'
419    Exit(1)
420
421makeEnv('debug', '.do',
422        CCFLAGS = Split(ccflags['debug']),
423        CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
424
425# Optimized binary
426makeEnv('opt', '.o',
427        CCFLAGS = Split(ccflags['opt']),
428        CPPDEFINES = ['TRACING_ON=1'])
429
430# "Fast" binary
431makeEnv('fast', '.fo', strip = True,
432        CCFLAGS = Split(ccflags['fast']),
433        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
434
435# Profiled binary
436makeEnv('prof', '.po',
437        CCFLAGS = Split(ccflags['prof']),
438        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
439        LINKFLAGS = '-pg')
440
441Return('envList')
442