Tizen 2.1 base
[external/lzo2.git] / autoconf / py-compile
1 #!/bin/sh
2 # py-compile - Compile a Python program
3
4 scriptversion=2005-05-14.22
5
6 # Copyright (C) 2000, 2001, 2003, 2004, 2005  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 3, 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, see <http://www.gnu.org/licenses/>.
20
21 # As a special exception to the GNU General Public License, if you
22 # distribute this file as part of a program that contains a
23 # configuration script generated by Autoconf, you may include it under
24 # the same distribution terms that you use for the rest of that program.
25
26 # This file is maintained in Automake, please report
27 # bugs to <bug-automake@gnu.org> or send patches to
28 # <automake-patches@gnu.org>.
29
30 if [ -z "$PYTHON" ]; then
31   PYTHON=python
32 fi
33
34 basedir=
35 destdir=
36 files=
37 while test $# -ne 0; do
38   case "$1" in
39     --basedir)
40       basedir=$2
41       if test -z "$basedir"; then
42         echo "$0: Missing argument to --basedir." 1>&2
43         exit 1
44       fi
45       shift
46       ;;
47     --destdir)
48       destdir=$2
49       if test -z "$destdir"; then
50         echo "$0: Missing argument to --destdir." 1>&2
51         exit 1
52       fi
53       shift
54       ;;
55     -h|--h*)
56       cat <<\EOF
57 Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
58
59 Byte compile some python scripts FILES.  Use --destdir to specify any
60 leading directory path to the FILES that you don't want to include in the
61 byte compiled file.  Specify --basedir for any additional path information you
62 do want to be shown in the byte compiled file.
63
64 Example:
65   py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
66
67 Report bugs to <bug-automake@gnu.org>.
68 EOF
69       exit $?
70       ;;
71     -v|--v*)
72       echo "py-compile $scriptversion"
73       exit $?
74       ;;
75     *)
76       files="$files $1"
77       ;;
78   esac
79   shift
80 done
81
82 if test -z "$files"; then
83     echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
84     exit 1
85 fi
86
87 # if basedir was given, then it should be prepended to filenames before
88 # byte compilation.
89 if [ -z "$basedir" ]; then
90     pathtrans="path = file"
91 else
92     pathtrans="path = os.path.join('$basedir', file)"
93 fi
94
95 # if destdir was given, then it needs to be prepended to the filename to
96 # byte compile but not go into the compiled file.
97 if [ -z "$destdir" ]; then
98     filetrans="filepath = path"
99 else
100     filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
101 fi
102
103 $PYTHON -c "
104 import sys, os, string, py_compile
105
106 files = '''$files'''
107
108 print 'Byte-compiling python modules...'
109 for file in string.split(files):
110     $pathtrans
111     $filetrans
112     if not os.path.exists(filepath) or not (len(filepath) >= 3
113                                             and filepath[-3:] == '.py'):
114         continue
115     print file,
116     sys.stdout.flush()
117     py_compile.compile(filepath, filepath + 'c', path)
118 print" || exit $?
119
120 # this will fail for python < 1.5, but that doesn't matter ...
121 $PYTHON -O -c "
122 import sys, os, string, py_compile
123
124 files = '''$files'''
125 print 'Byte-compiling python modules (optimized versions) ...'
126 for file in string.split(files):
127     $pathtrans
128     $filetrans
129     if not os.path.exists(filepath) or not (len(filepath) >= 3
130                                             and filepath[-3:] == '.py'):
131         continue
132     print file,
133     sys.stdout.flush()
134     py_compile.compile(filepath, filepath + 'o', path)
135 print" 2>/dev/null || :
136
137 # Local Variables:
138 # mode: shell-script
139 # sh-indentation: 2
140 # eval: (add-hook 'write-file-hooks 'time-stamp)
141 # time-stamp-start: "scriptversion="
142 # time-stamp-format: "%:y-%02m-%02d.%02H"
143 # time-stamp-end: "$"
144 # End: