3 # Copyright (C) 2002-2008, 2010-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/>.
23 # exits with a given status.
24 # This function needs to be used, rather than 'exit', when a 'trap' handler is
25 # in effect that refers to $?.
31 # func_fatal_error message
32 # outputs to stderr a fatal error message, and terminates the program.
34 # - progname name of this program
37 echo "$progname: *** $1" 1>&2
38 echo "$progname: *** Stop." 1>&2
42 # func_readlink SYMLINK
43 # outputs the target of the given symlink.
44 if (type readlink
) > /dev
/null
2>&1; then
47 # Use the readlink program from GNU coreutils.
53 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
54 # would do the wrong thing if the link target contains " -> ".
55 LC_ALL
=C
ls -l "$1" |
sed -e 's, -> ,#%%#,' |
sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
60 # locates the directory where the gnulib repository lives
62 # - progname name of this program
64 # - self_abspathname absolute pathname of this program
65 # - gnulib_dir absolute pathname of gnulib repository
69 /* | ?
:*) self_abspathname
="$progname" ;;
70 */*) self_abspathname
=`pwd`/"$progname" ;;
73 # Iterate through the elements of $PATH.
74 # We use IFS=: instead of
75 # for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
76 # because the latter does not work when some PATH element contains spaces.
77 # We use a canonicalized $pathx instead of $PATH, because empty PATH
78 # elements are by definition equivalent to '.', however field splitting
79 # according to IFS=: loses empty fields in many shells:
80 # - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
81 # beginning, at the end, and in the middle),
82 # - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
83 # at the beginning and at the end,
84 # - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
85 # Solaris lose empty fields at the end.
86 # The 'case' statement is an optimization, to avoid evaluating the
87 # explicit canonicalization command when $PATH contains no empty fields.
89 if test "${PATH_SEPARATOR+set}" != set; then
90 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
91 # contains only /bin. Note that ksh looks also at the FPATH variable,
92 # so we have to set that as well for the test.
94 (PATH
='/bin;/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
95 && { (PATH
='/bin:/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
99 if test "${PATH_SEPARATOR+set}" != set; then
100 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
101 # contains only /bin. Note that ksh looks also at the FPATH variable,
102 # so we have to set that as well for the test.
104 (PATH
='/bin;/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
105 && { (PATH
='/bin:/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
106 || PATH_SEPARATOR
=';'
109 if test "$PATH_SEPARATOR" = ";"; then
110 # On Windows, programs are searched in "." before $PATH.
113 # On Unix, we have to convert empty PATH elements to ".".
117 pathx
=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
122 IFS
="$PATH_SEPARATOR"
126 if test -x "$d/$progname" && test ! -d "$d/$progname"; then
127 self_abspathname
="$d/$progname"
132 if test -z "$self_abspathname"; then
133 func_fatal_error
"could not locate the posix-modules program - how did you invoke it?"
137 while test -h "$self_abspathname"; do
138 # Resolve symbolic link.
139 linkval
=`func_readlink "$self_abspathname"`
140 test -n "$linkval" ||
break
142 /* | ?
:* ) self_abspathname
="$linkval" ;;
143 * ) self_abspathname
=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
146 gnulib_dir
=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
150 # creates a temporary directory.
152 # - progname name of this program
154 # - tmp pathname of freshly created temporary directory
157 # Use the environment variable TMPDIR, falling back to /tmp. This allows
158 # users to specify a different temporary directory, for example, if their
159 # /tmp is filled up or too small.
162 # Use the mktemp program if available. If not available, hide the error
164 tmp
=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
165 test -n "$tmp" && test -d "$tmp"
168 # Use a simple mkdir command. It is guaranteed to fail if the directory
169 # already exists. $RANDOM is bash specific and expands to empty in shells
170 # other than bash, ksh and zsh. Its use does not increase security;
171 # rather, it minimizes the probability of failure in a very cluttered /tmp
173 tmp
=$TMPDIR/gl$$
-$RANDOM
174 (umask 077 && mkdir
"$tmp")
177 echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
183 # outputs to stdout the --help usage message.
187 Usage: posix-modules [option]
189 Lists the gnulib modules that implement POSIX interfaces.
193 --for-mingw list only modules that work on mingw
194 --for-msvc list only modules that work on MSVC
196 Report bugs to <bug-gnulib@gnu.org>."
200 # outputs to stdout the --version message.
204 if test -d "$gnulib_dir"/.git \
205 && (git
--version) >/dev
/null
2>/dev
/null \
206 && (date --version) >/dev
/null
2>/dev
/null
; then
207 # gnulib checked out from git.
208 sed_extract_first_date
='/^Date/{
212 date=`cd "$gnulib_dir" && git log -n 1 --format=medium --date=iso ChangeLog | sed -n -e "$sed_extract_first_date"`
213 # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
214 sed_year_before_time
='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
215 date=`echo "$date" | sed -e "$sed_year_before_time"`
216 # Use GNU date to compute the time in GMT.
217 date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
218 version
=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
220 # gnulib copy without versioning information.
221 date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
224 year
=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
226 posix-modules (GNU $package $date)$version
227 Copyright (C) $year Free Software Foundation, Inc.
228 License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
229 This is free software: you are free to change and redistribute it.
230 There is NO WARRANTY, to the extent permitted by law.
232 Written by" "Bruno Haible"
235 # Excludes for mingw.
237 # <grp.h> does not exist.
238 exclude_for_mingw
="$exclude_for_mingw pt_chown grantpt posix_openpt-tests posix_openpt"
239 # The functions getuid, getgid, geteuid, getegid don't exist.
240 exclude_for_mingw
="$exclude_for_mingw faccessat"
241 exclude_for_mingw
="$exclude_for_mingw fchownat-tests fchownat"
244 exclude_for_msvc
="$exclude_for_mingw"
246 # Command-line option processing.
248 while test $# -gt 0; do
250 --for-mingw |
--for-ming |
--for-min |
--for-mi )
251 exclude
="$exclude $exclude_for_mingw"
253 --for-msvc |
--for-msv |
--for-ms )
254 exclude
="$exclude $exclude_for_msvc"
256 --help |
--hel |
--he |
--h )
259 --version |
--versio |
--versi |
--vers |
--ver |
--ve |
--v )
263 echo "posix-modules: unknown option $1" 1>&2
264 echo "Try 'posix-modules --help' for more information." 1>&2
267 echo "posix-modules: too many arguments" 1>&2
268 echo "Try 'posix-modules --help' for more information." 1>&2
276 if test "$signal" != EXIT; then
277 echo "caught signal SIG$signal" >&2
280 exit $exit_status' EXIT
281 for signal
in HUP INT QUIT PIPE TERM
; do
282 trap '{ signal='$signal'; func_exit 1; }' $signal
287 # Get the header modules.
288 LC_ALL
=C
grep -h '^Gnulib module: ' "$gnulib_dir"/doc
/posix-headers
/*.texi
2>/dev
/null \
289 |
sed -e 's,^Gnulib module: ,,'
290 # Get the function modules.
291 LC_ALL
=C
grep -h '^Gnulib module: ' "$gnulib_dir"/doc
/posix-functions
/*.texi
2>/dev
/null \
292 |
sed -e 's,^Gnulib module: ,,'
293 # Then filter out the words "---", ",", "and", "or" and remove *-gnu modules.
294 ) |
sed -e 's/,/ /g' | LC_ALL
=C
sort | LC_ALL
=C
uniq \
295 |
{ # Then filter out the words "---", "and", "or" and remove *-gnu modules.
296 tr ' ' '\012' |
sed -e '/^---$/d' -e '/^and$/d' -e '/^or$/d' -e '/-gnu$/d'
298 | LC_ALL
=C
sort | LC_ALL
=C
uniq \
299 |
{ # Then filter out the excludes.
300 if test -n "$exclude"; then
301 for m
in $exclude; do echo $m; done | LC_ALL
=C
sort -u > "$tmp"/excludes
302 LC_ALL
=C
join -v 1 - "$tmp"/excludes
303 rm -f "$tmp"/excludes
310 # indent-tabs-mode: nil
311 # whitespace-check-buffer-indent: nil