|
kusano |
7d535a |
#!/bin/sh
|
|
kusano |
7d535a |
# py-compile - Compile a Python program
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
scriptversion=2005-05-14.22
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# Copyright (C) 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# This program is free software; you can redistribute it and/or modify
|
|
kusano |
7d535a |
# it under the terms of the GNU General Public License as published by
|
|
kusano |
7d535a |
# the Free Software Foundation; either version 3, or (at your option)
|
|
kusano |
7d535a |
# any later version.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# This program is distributed in the hope that it will be useful,
|
|
kusano |
7d535a |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
kusano |
7d535a |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
kusano |
7d535a |
# GNU General Public License for more details.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# You should have received a copy of the GNU General Public License
|
|
kusano |
7d535a |
# along with this program. If not, see <http: licenses="" www.gnu.org="">.</http:>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# As a special exception to the GNU General Public License, if you
|
|
kusano |
7d535a |
# distribute this file as part of a program that contains a
|
|
kusano |
7d535a |
# configuration script generated by Autoconf, you may include it under
|
|
kusano |
7d535a |
# the same distribution terms that you use for the rest of that program.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# This file is maintained in Automake, please report
|
|
kusano |
7d535a |
# bugs to <bug-automake@gnu.org> or send patches to</bug-automake@gnu.org>
|
|
kusano |
7d535a |
# <automake-patches@gnu.org>.</automake-patches@gnu.org>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if [ -z "$PYTHON" ]; then
|
|
kusano |
7d535a |
PYTHON=python
|
|
kusano |
7d535a |
fi
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
basedir=
|
|
kusano |
7d535a |
destdir=
|
|
kusano |
7d535a |
files=
|
|
kusano |
7d535a |
while test $# -ne 0; do
|
|
kusano |
7d535a |
case "$1" in
|
|
kusano |
7d535a |
--basedir)
|
|
kusano |
7d535a |
basedir=$2
|
|
kusano |
7d535a |
if test -z "$basedir"; then
|
|
kusano |
7d535a |
echo "$0: Missing argument to --basedir." 1>&2
|
|
kusano |
7d535a |
exit 1
|
|
kusano |
7d535a |
fi
|
|
kusano |
7d535a |
shift
|
|
kusano |
7d535a |
;;
|
|
kusano |
7d535a |
--destdir)
|
|
kusano |
7d535a |
destdir=$2
|
|
kusano |
7d535a |
if test -z "$destdir"; then
|
|
kusano |
7d535a |
echo "$0: Missing argument to --destdir." 1>&2
|
|
kusano |
7d535a |
exit 1
|
|
kusano |
7d535a |
fi
|
|
kusano |
7d535a |
shift
|
|
kusano |
7d535a |
;;
|
|
kusano |
7d535a |
-h|--h*)
|
|
kusano |
7d535a |
cat <<\EOF
|
|
kusano |
7d535a |
Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Byte compile some python scripts FILES. Use --destdir to specify any
|
|
kusano |
7d535a |
leading directory path to the FILES that you don't want to include in the
|
|
kusano |
7d535a |
byte compiled file. Specify --basedir for any additional path information you
|
|
kusano |
7d535a |
do want to be shown in the byte compiled file.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Example:
|
|
kusano |
7d535a |
py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Report bugs to <bug-automake@gnu.org>.</bug-automake@gnu.org>
|
|
kusano |
7d535a |
EOF
|
|
kusano |
7d535a |
exit $?
|
|
kusano |
7d535a |
;;
|
|
kusano |
7d535a |
-v|--v*)
|
|
kusano |
7d535a |
echo "py-compile $scriptversion"
|
|
kusano |
7d535a |
exit $?
|
|
kusano |
7d535a |
;;
|
|
kusano |
7d535a |
*)
|
|
kusano |
7d535a |
files="$files $1"
|
|
kusano |
7d535a |
;;
|
|
kusano |
7d535a |
esac
|
|
kusano |
7d535a |
shift
|
|
kusano |
7d535a |
done
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if test -z "$files"; then
|
|
kusano |
7d535a |
echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
|
|
kusano |
7d535a |
exit 1
|
|
kusano |
7d535a |
fi
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# if basedir was given, then it should be prepended to filenames before
|
|
kusano |
7d535a |
# byte compilation.
|
|
kusano |
7d535a |
if [ -z "$basedir" ]; then
|
|
kusano |
7d535a |
pathtrans="path = file"
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
pathtrans="path = os.path.join('$basedir', file)"
|
|
kusano |
7d535a |
fi
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# if destdir was given, then it needs to be prepended to the filename to
|
|
kusano |
7d535a |
# byte compile but not go into the compiled file.
|
|
kusano |
7d535a |
if [ -z "$destdir" ]; then
|
|
kusano |
7d535a |
filetrans="filepath = path"
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
|
|
kusano |
7d535a |
fi
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
$PYTHON -c "
|
|
kusano |
7d535a |
import sys, os, string, py_compile
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
files = '''$files'''
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
print 'Byte-compiling python modules...'
|
|
kusano |
7d535a |
for file in string.split(files):
|
|
kusano |
7d535a |
$pathtrans
|
|
kusano |
7d535a |
$filetrans
|
|
kusano |
7d535a |
if not os.path.exists(filepath) or not (len(filepath) >= 3
|
|
kusano |
7d535a |
and filepath[-3:] == '.py'):
|
|
kusano |
7d535a |
continue
|
|
kusano |
7d535a |
print file,
|
|
kusano |
7d535a |
sys.stdout.flush()
|
|
kusano |
7d535a |
py_compile.compile(filepath, filepath + 'c', path)
|
|
kusano |
7d535a |
print" || exit $?
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# this will fail for python < 1.5, but that doesn't matter ...
|
|
kusano |
7d535a |
$PYTHON -O -c "
|
|
kusano |
7d535a |
import sys, os, string, py_compile
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
files = '''$files'''
|
|
kusano |
7d535a |
print 'Byte-compiling python modules (optimized versions) ...'
|
|
kusano |
7d535a |
for file in string.split(files):
|
|
kusano |
7d535a |
$pathtrans
|
|
kusano |
7d535a |
$filetrans
|
|
kusano |
7d535a |
if not os.path.exists(filepath) or not (len(filepath) >= 3
|
|
kusano |
7d535a |
and filepath[-3:] == '.py'):
|
|
kusano |
7d535a |
continue
|
|
kusano |
7d535a |
print file,
|
|
kusano |
7d535a |
sys.stdout.flush()
|
|
kusano |
7d535a |
py_compile.compile(filepath, filepath + 'o', path)
|
|
kusano |
7d535a |
print" 2>/dev/null || :
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
# Local Variables:
|
|
kusano |
7d535a |
# mode: shell-script
|
|
kusano |
7d535a |
# sh-indentation: 2
|
|
kusano |
7d535a |
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
|
kusano |
7d535a |
# time-stamp-start: "scriptversion="
|
|
kusano |
7d535a |
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
|
kusano |
7d535a |
# time-stamp-end: "$"
|
|
kusano |
7d535a |
# End:
|