Salome HOME
Copyright update 2021
[modules/yacs.git] / src / wrappergen / src / HXX2SALOME_GENERIC_CLASS_NAME_SRC / py-compile
1 #!/bin/sh
2 # py-compile - Compile a Python program
3
4 scriptversion=2005-05-14.22
5
6 # Copyright (C) 2000-2021  CEA/DEN, EDF R&D
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library 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 GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #
24
25 # This program is free software; you can redistribute it and/or modify
26 # it under the terms of the GNU General Public License as published by
27 # the Free Software Foundation; either version 2, or (at your option)
28 # any later version.
29
30 # This program is distributed in the hope that it will be useful,
31 # but WITHOUT ANY WARRANTY; without even the implied warranty of
32 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 # GNU General Public License for more details.
34
35 # You should have received a copy of the GNU General Public License
36 # along with this program; if not, write to the Free Software
37 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
38 # 02110-1301, USA.
39
40 # As a special exception to the GNU General Public License, if you
41 # distribute this file as part of a program that contains a
42 # configuration script generated by Autoconf, you may include it under
43 # the same distribution terms that you use for the rest of that program.
44
45 # This file is maintained in Automake, please report
46 # bugs to <bug-automake@gnu.org> or send patches to
47 # <automake-patches@gnu.org>.
48
49 if [ -z "$PYTHON" ]; then
50   PYTHON=python
51 fi
52
53 basedir=
54 destdir=
55 files=
56 while test $# -ne 0; do
57   case "$1" in
58     --basedir)
59       basedir=$2
60       if test -z "$basedir"; then
61         echo "$0: Missing argument to --basedir." 1>&2
62         exit 1
63       fi
64       shift
65       ;;
66     --destdir)
67       destdir=$2
68       if test -z "$destdir"; then
69         echo "$0: Missing argument to --destdir." 1>&2
70         exit 1
71       fi
72       shift
73       ;;
74     -h|--h*)
75       cat <<\EOF
76 Usage: py-compile [--help] [--version] [--basedir DIR] [--destdir DIR] FILES..."
77
78 Byte compile some python scripts FILES.  Use --destdir to specify any
79 leading directory path to the FILES that you don't want to include in the
80 byte compiled file.  Specify --basedir for any additional path information you
81 do want to be shown in the byte compiled file.
82
83 Example:
84   py-compile --destdir /tmp/pkg-root --basedir /usr/share/test test.py test2.py
85
86 Report bugs to <bug-automake@gnu.org>.
87 EOF
88       exit $?
89       ;;
90     -v|--v*)
91       echo "py-compile $scriptversion"
92       exit $?
93       ;;
94     *)
95       files="$files $1"
96       ;;
97   esac
98   shift
99 done
100
101 if test -z "$files"; then
102     echo "$0: No files given.  Try \`$0 --help' for more information." 1>&2
103     exit 1
104 fi
105
106 # if basedir was given, then it should be prepended to filenames before
107 # byte compilation.
108 if [ -z "$basedir" ]; then
109     pathtrans="path = file"
110 else
111     pathtrans="path = os.path.join('$basedir', file)"
112 fi
113
114 # if destdir was given, then it needs to be prepended to the filename to
115 # byte compile but not go into the compiled file.
116 if [ -z "$destdir" ]; then
117     filetrans="filepath = path"
118 else
119     filetrans="filepath = os.path.normpath('$destdir' + os.sep + path)"
120 fi
121
122 $PYTHON -c "
123 import sys, os, string, py_compile
124
125 files = '''$files'''
126
127 print('Byte-compiling python modules...')
128 for file in string.split(files):
129     $pathtrans
130     $filetrans
131     if not os.path.exists(filepath) or not (len(filepath) >= 3
132                                             and filepath[-3:] == '.py'):
133         continue
134     print(file, end='')
135     sys.stdout.flush()
136     py_compile.compile(filepath, filepath + 'c', path)
137 print()" || exit $?
138
139 # this will fail for python < 1.5, but that doesn't matter ...
140 $PYTHON -O -c "
141 import sys, os, string, py_compile
142
143 files = '''$files'''
144 print('Byte-compiling python modules (optimized versions) ...')
145 for file in string.split(files):
146     $pathtrans
147     $filetrans
148     if not os.path.exists(filepath) or not (len(filepath) >= 3
149                                             and filepath[-3:] == '.py'):
150         continue
151     print(file, end='')
152     sys.stdout.flush()
153     py_compile.compile(filepath, filepath + 'o', path)
154 print()" 2>/dev/null || :
155