* lib/mkinstalldirs: Mention automake-patches@gnu.org and
[platform/upstream/automake.git] / lib / py-compile
1 #!/bin/sh
2 # py-compile - Compile a Python program
3
4 scriptversion=2003-11-09.01
5
6 # Copyright (C) 2000, 2001, 2003  Free Software Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # 02111-1307, USA.
22
23 # As a special exception to the GNU General Public License, if you
24 # distribute this file as part of a program that contains a
25 # configuration script generated by Autoconf, you may include it under
26 # the same distribution terms that you use for the rest of that program.
27
28 # This file is maintained in Automake, please report
29 # bugs to <bug-automake@gnu.org> or send patches to
30 # <automake-patches@gnu.org>.
31
32 if [ -z "$PYTHON" ]; then
33   PYTHON=python
34 fi
35
36 basedir=
37
38 case "$1" in
39   '')
40     echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
41     exit 1
42     ;;
43   --basedir)
44     basedir=$2
45     shift 2
46     ;;
47   -h|--h*)
48     cat <<\EOF
49 Usage: py-compile [--help] [--version] [--basedir DIR] FILES..."
50
51 Byte compile some python scripts FILES.  This should be performed
52 after they have been moved to the final installation location
53
54 Report bugs to <bug-automake@gnu.org>.
55 EOF
56     exit 0
57     ;;
58   -v|--v*)
59     echo "py-compile $scriptversion"
60     exit 0
61     ;;
62 esac
63
64 # if basedir was given, then it should be prepended to filenames before
65 # byte compilation.
66 if [ -z "$basedir" ]; then
67     trans="path = file"
68 else
69     trans="path = os.path.join('$basedir', file)"
70 fi
71
72 $PYTHON -c "
73 import sys, os, string, py_compile
74
75 files = '''$*'''
76 print 'Byte-compiling python modules...'
77 for file in string.split(files):
78     $trans
79     if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
80         continue
81     print file,
82     sys.stdout.flush()
83     py_compile.compile(path)
84 print" || exit $?
85
86 # this will fail for python < 1.5, but that doesn't matter ...
87 $PYTHON -O -c "
88 import sys, os, string, py_compile
89
90 files = '''$*'''
91 print 'Byte-compiling python modules (optimized versions) ...'
92 for file in string.split(files):
93     $trans
94     if not os.path.exists(path) or not (len(path) >= 3 and path[-3:] == '.py'):
95         continue
96     print file,
97     sys.stdout.flush()
98     py_compile.compile(path)
99 print" 2>/dev/null || :
100
101 # Local Variables:
102 # mode: shell-script
103 # sh-indentation: 2
104 # eval: (add-hook 'write-file-hooks 'time-stamp)
105 # time-stamp-start: "scriptversion="
106 # time-stamp-format: "%:y-%02m-%02d.%02H"
107 # time-stamp-end: "$"
108 # End: