SConscript revision 4202
11046SN/A# -*- mode:python -*-
21046SN/A
31762SN/A# Copyright (c) 2004-2005 The Regents of The University of Michigan
41046SN/A# All rights reserved.
51046SN/A#
61046SN/A# Redistribution and use in source and binary forms, with or without
71046SN/A# modification, are permitted provided that the following conditions are
81046SN/A# met: redistributions of source code must retain the above copyright
91046SN/A# notice, this list of conditions and the following disclaimer;
101046SN/A# redistributions in binary form must reproduce the above copyright
111046SN/A# notice, this list of conditions and the following disclaimer in the
121046SN/A# documentation and/or other materials provided with the distribution;
131046SN/A# neither the name of the copyright holders nor the names of its
141046SN/A# contributors may be used to endorse or promote products derived from
151046SN/A# this software without specific prior written permission.
161046SN/A#
171046SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181046SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191046SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
201046SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211046SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221046SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
231046SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241046SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251046SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261046SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
271046SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu#
292665Ssaidi@eecs.umich.edu# Authors: Steve Reinhardt
302665Ssaidi@eecs.umich.edu#          Nathan Binkert
311046SN/A
324202Sbinkertn@umich.eduimport os
334202Sbinkertn@umich.eduimport zipfile
342655Sstever@eecs.umich.edu
352655Sstever@eecs.umich.edu# handy function for path joins
362655Sstever@eecs.umich.edudef join(*args):
372655Sstever@eecs.umich.edu    return os.path.normpath(os.path.join(*args))
381530SN/A
394202Sbinkertn@umich.eduImport('*')
401530SN/A
412667Sstever@eecs.umich.edu# This SConscript is in charge of collecting .py files and generating
422667Sstever@eecs.umich.edu# a zip archive that is appended to the m5 binary.
431046SN/A
442655Sstever@eecs.umich.edu# List of files & directories to include in the zip file.  To include
452655Sstever@eecs.umich.edu# a package, list only the root directory of the package, not any
462655Sstever@eecs.umich.edu# internal .py files (else they will get the path stripped off when
472655Sstever@eecs.umich.edu# they are imported into the zip file).
482655Sstever@eecs.umich.edupyzip_files = []
491046SN/A
502655Sstever@eecs.umich.edu# List of additional files on which the zip archive depends, but which
512655Sstever@eecs.umich.edu# are not included in pyzip_files... i.e. individual .py files within
522655Sstever@eecs.umich.edu# a package.
532655Sstever@eecs.umich.edupyzip_dep_files = []
541046SN/A
552655Sstever@eecs.umich.edu# Add the specified package to the zip archive.  Adds the directory to
562655Sstever@eecs.umich.edu# pyzip_files and all included .py files to pyzip_dep_files.
572655Sstever@eecs.umich.edudef addPkg(pkgdir):
582667Sstever@eecs.umich.edu    pyzip_files.append(pkgdir)
592655Sstever@eecs.umich.edu    origdir = os.getcwd()
602655Sstever@eecs.umich.edu    srcdir = join(Dir('.').srcnode().abspath, pkgdir)
612655Sstever@eecs.umich.edu    os.chdir(srcdir)
622655Sstever@eecs.umich.edu    for path, dirs, files in os.walk('.'):
632655Sstever@eecs.umich.edu        for i,dir in enumerate(dirs):
642655Sstever@eecs.umich.edu            if dir == 'SCCS':
652655Sstever@eecs.umich.edu                del dirs[i]
662655Sstever@eecs.umich.edu                break
671046SN/A
682655Sstever@eecs.umich.edu        for f in files:
692655Sstever@eecs.umich.edu            if f.endswith('.py'):
702667Sstever@eecs.umich.edu                pyzip_dep_files.append(join(pkgdir, path, f))
711046SN/A
722655Sstever@eecs.umich.edu    os.chdir(origdir)
731046SN/A
742655Sstever@eecs.umich.edu# Generate Python file that contains a dict specifying the current
752655Sstever@eecs.umich.edu# build_env flags.
761439SN/Adef MakeDefinesPyFile(target, source, env):
771530SN/A    f = file(str(target[0]), 'w')
782889Sbinkertn@umich.edu    print >>f, "m5_build_env = ", source[0]
791530SN/A    f.close()
801439SN/A
811858SN/AoptionDict = dict([(opt, env[opt]) for opt in env.ExportOptions])
822667Sstever@eecs.umich.eduenv.Command('m5/defines.py', Value(optionDict), MakeDefinesPyFile)
831858SN/A
842889Sbinkertn@umich.edudef MakeInfoPyFile(target, source, env):
852889Sbinkertn@umich.edu    f = file(str(target[0]), 'w')
862889Sbinkertn@umich.edu    for src in source:
872889Sbinkertn@umich.edu        data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
882889Sbinkertn@umich.edu        print >>f, "%s = %s" % (src, repr(data))
892889Sbinkertn@umich.edu    f.close()
902889Sbinkertn@umich.edu
912889Sbinkertn@umich.eduenv.Command('m5/info.py',
922889Sbinkertn@umich.edu            [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ],
932889Sbinkertn@umich.edu            MakeInfoPyFile)
942889Sbinkertn@umich.edu
952655Sstever@eecs.umich.edu# Now specify the packages & files for the zip archive.
962655Sstever@eecs.umich.eduaddPkg('m5')
972667Sstever@eecs.umich.edupyzip_files.append('m5/defines.py')
982889Sbinkertn@umich.edupyzip_files.append('m5/info.py')
992655Sstever@eecs.umich.edupyzip_files.append(join(env['ROOT'], 'util/pbs/jobfile.py'))
1004053Sbinkertn@umich.edupyzip_files.append(join(env['ROOT'], 'src/base/traceflags.py'))
1012655Sstever@eecs.umich.edu
1024086Sbinkertn@umich.eduswig_modules = []
1034086Sbinkertn@umich.edudef swig_it(module):
1044086Sbinkertn@umich.edu    env.Command(['swig/%s_wrap.cc' % module, 'm5/internal/%s.py' % module],
1054086Sbinkertn@umich.edu                'swig/%s.i' % module,
1063869Sbinkertn@umich.edu                '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
1073869Sbinkertn@umich.edu                '-o ${TARGETS[0]} $SOURCES')
1084086Sbinkertn@umich.edu    swig_modules.append(module)
1094202Sbinkertn@umich.edu    Source('swig/%s_wrap.cc' % module)
1104202Sbinkertn@umich.edu
1114202Sbinkertn@umich.eduSource('swig/init.cc')
1124202Sbinkertn@umich.eduSource('swig/pyevent.cc')
1134202Sbinkertn@umich.eduSource('swig/pyobject.cc')
1143645Sbinkertn@umich.edu
1154123Sbinkertn@umich.eduswig_it('core')
1163869Sbinkertn@umich.eduswig_it('debug')
1173871Sbinkertn@umich.eduswig_it('event')
1184045Sbinkertn@umich.eduswig_it('random')
1194123Sbinkertn@umich.eduswig_it('sim_object')
1204078Sbinkertn@umich.eduswig_it('stats')
1214042Sbinkertn@umich.eduswig_it('trace')
1222667Sstever@eecs.umich.edu
1234086Sbinkertn@umich.edu# Automatically generate m5/internals/__init__.py
1244086Sbinkertn@umich.edudef MakeInternalsInit(target, source, env):
1254086Sbinkertn@umich.edu    f = file(str(target[0]), 'w')
1264086Sbinkertn@umich.edu    for m in swig_modules:
1274086Sbinkertn@umich.edu        print >>f, 'import %s' % m
1284086Sbinkertn@umich.edu    f.close()
1294086Sbinkertn@umich.edu
1304086Sbinkertn@umich.eduswig_py_files = [ 'm5/internal/%s.py' % m for m in swig_modules ]
1314086Sbinkertn@umich.eduenv.Command('m5/internal/__init__.py', swig_py_files, MakeInternalsInit)
1324086Sbinkertn@umich.edupyzip_dep_files.append('m5/internal/__init__.py')
1334086Sbinkertn@umich.edu
1344086Sbinkertn@umich.edudef MakeSwigInit(target, source, env):
1354086Sbinkertn@umich.edu    f = file(str(target[0]), 'w')
1364086Sbinkertn@umich.edu    print >>f, 'extern "C" {'
1374086Sbinkertn@umich.edu    for m in swig_modules:
1384086Sbinkertn@umich.edu        print >>f, '    void init_%s();' % m
1394086Sbinkertn@umich.edu    print >>f, '}'
1404086Sbinkertn@umich.edu    print >>f, 'void init_swig() {'
1414086Sbinkertn@umich.edu    for m in swig_modules:
1424086Sbinkertn@umich.edu        print >>f, '    init_%s();' % m
1434086Sbinkertn@umich.edu    print >>f, '}'
1444086Sbinkertn@umich.edu    f.close()
1454086Sbinkertn@umich.edu
1464086Sbinkertn@umich.eduswig_cc_files = [ 'swig/%s_wrap.cc' % m for m in swig_modules ]
1474086Sbinkertn@umich.eduenv.Command('swig/init.cc', swig_cc_files, MakeSwigInit)
1484086Sbinkertn@umich.edu
1492655Sstever@eecs.umich.edu# Action function to build the zip archive.  Uses the PyZipFile module
1502655Sstever@eecs.umich.edu# included in the standard Python library.
1512655Sstever@eecs.umich.edudef buildPyZip(target, source, env):
1524202Sbinkertn@umich.edu    pzf = zipfile.PyZipFile(str(target[0]), 'w')
1532655Sstever@eecs.umich.edu    for s in source:
1542655Sstever@eecs.umich.edu        pzf.writepy(str(s))
1552655Sstever@eecs.umich.edu
1562655Sstever@eecs.umich.edu# Add the zip file target to the environment.
1572655Sstever@eecs.umich.eduenv.Command('m5py.zip', pyzip_files, buildPyZip)
1582655Sstever@eecs.umich.eduenv.Depends('m5py.zip', pyzip_dep_files)
159