3 # Copyright (C) 2002-2024 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 # This program invokes the Python rewrite of gnulib-tool.
20 # It is meant to behave identically to gnulib-tool, just faster.
25 # exits with a given status.
26 # This function needs to be used, rather than 'exit', when a 'trap' handler is
27 # in effect that refers to $?.
33 # func_fatal_error message
34 # outputs to stderr a fatal error message, and terminates the program.
36 # - progname name of this program
39 echo "$progname: *** $1" 1>&2
40 echo "$progname: *** Stop." 1>&2
44 # func_readlink SYMLINK
45 # outputs the target of the given symlink.
46 if (type readlink
) > /dev
/null
2>&1; then
49 # Use the readlink program from GNU coreutils.
55 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
56 # would do the wrong thing if the link target contains " -> ".
57 LC_ALL
=C
ls -l "$1" |
sed -e 's, -> ,#%%#,' |
sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
62 # locates the directory where the gnulib repository lives
64 # - progname name of this program
66 # - self_abspathname absolute pathname of gnulib-tool
67 # - gnulib_dir absolute pathname of gnulib repository
71 /* | ?
:*) self_abspathname
="$progname" ;;
72 */*) self_abspathname
=`pwd`/"$progname" ;;
75 # Iterate through the elements of $PATH.
76 # We use IFS=: instead of
77 # for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
78 # because the latter does not work when some PATH element contains spaces.
79 # We use a canonicalized $pathx instead of $PATH, because empty PATH
80 # elements are by definition equivalent to '.', however field splitting
81 # according to IFS=: loses empty fields in many shells:
82 # - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
83 # beginning, at the end, and in the middle),
84 # - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
85 # at the beginning and at the end,
86 # - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
87 # Solaris lose empty fields at the end.
88 # The 'case' statement is an optimization, to avoid evaluating the
89 # explicit canonicalization command when $PATH contains no empty fields.
91 if test "$PATH_SEPARATOR" = ";"; then
92 # On Windows, programs are searched in "." before $PATH.
95 # On Unix, we have to convert empty PATH elements to ".".
99 pathx
=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
104 IFS
="$PATH_SEPARATOR"
108 if test -x "$d/$progname" && test ! -d "$d/$progname"; then
109 self_abspathname
="$d/$progname"
114 if test -z "$self_abspathname"; then
115 func_fatal_error
"could not locate the gnulib-tool program - how did you invoke it?"
119 while test -h "$self_abspathname"; do
120 # Resolve symbolic link.
121 linkval
=`func_readlink "$self_abspathname"`
122 test -n "$linkval" ||
break
124 /* | ?
:* ) self_abspathname
="$linkval" ;;
125 * ) self_abspathname
=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
128 gnulib_dir
=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
133 # Check the Python version.
134 if (python3
--version) >/dev
/null
2>/dev
/null
; then
135 case `python3 --version 2>&1` in
136 Python\
3.
[0-6] | Python\
3.
[0-6].
*)
137 func_fatal_error
"python3 is too old (minimum required version is 3.7); try setting GNULIB_TOOL_IMPL=sh" ;;
141 func_fatal_error
"python3 version is unsupported" ;;
144 func_fatal_error
"python3 not found; try setting GNULIB_TOOL_IMPL=sh"
147 # Tell Python to store the compiled bytecode outside the gnulib directory.
148 if test -z "$PYTHONPYCACHEPREFIX"; then
149 PYTHONPYCACHEPREFIX
="${TMPDIR-/tmp}/gnulib-python-cache-${USER-$LOGNAME}"
150 export PYTHONPYCACHEPREFIX
154 # For profiling, cf. <https://docs.python.org/3/library/profile.html>.
155 #profiler_args="-m cProfile -s tottime"
156 exec python3
$profiler_args "$gnulib_dir/.gnulib-tool.py" "$@"