3 # Copyright (C) 2002-2008, 2010-2014 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 <http://www.gnu.org/licenses/>.
23 # outputs to stdout the --help usage message.
29 Lists the gnulib modules that implement POSIX interfaces.
31 Report bugs to <bug-gnulib@gnu.org>."
35 # outputs to stdout the --version message.
39 if test -d "$gnulib_dir"/.git \
40 && (git --version) >/dev/null 2>/dev/null \
41 && (date --version) >/dev/null 2>/dev/null; then
42 # gnulib checked out from git.
43 sed_extract_first_date='/^Date/{
47 date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"`
48 # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
49 sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
50 date=`echo "$date" | sed -e "$sed_year_before_time"`
51 # Use GNU date to compute the time in GMT.
52 date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
53 version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
55 # gnulib copy without versioning information.
56 date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
59 year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
61 posix-modules (GNU $package $date)$version
62 Copyright (C) $year Free Software Foundation, Inc.
63 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
64 This is free software: you are free to change and redistribute it.
65 There is NO WARRANTY, to the extent permitted by law.
67 Written by" "Bruno Haible"
71 # exits with a given status.
72 # This function needs to be used, rather than 'exit', when a 'trap' handler is
73 # in effect that refers to $?.
80 # locates the directory where the gnulib repository lives
82 # - progname name of this program
84 # - self_abspathname absolute pathname of this program
85 # - gnulib_dir absolute pathname of gnulib repository
89 /*) self_abspathname="$progname" ;;
90 */*) self_abspathname=`pwd`/"$progname" ;;
93 # Iterate through the elements of $PATH.
94 # We use IFS=: instead of
95 # for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
96 # because the latter does not work when some PATH element contains spaces.
97 # We use a canonicalized $pathx instead of $PATH, because empty PATH
98 # elements are by definition equivalent to '.', however field splitting
99 # according to IFS=: loses empty fields in many shells:
100 # - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
101 # beginning, at the end, and in the middle),
102 # - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
103 # at the beginning and at the end,
104 # - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
105 # Solaris lose empty fields at the end.
106 # The 'case' statement is an optimization, to avoid evaluating the
107 # explicit canonicalization command when $PATH contains no empty fields.
109 if test "${PATH_SEPARATOR+set}" != set; then
110 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
111 # contains only /bin. Note that ksh looks also at the FPATH variable,
112 # so we have to set that as well for the test.
114 (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
115 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
116 || PATH_SEPARATOR=';'
119 if test "$PATH_SEPARATOR" = ";"; then
120 # On Windows, programs are searched in "." before $PATH.
123 # On Unix, we have to convert empty PATH elements to ".".
127 pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
132 IFS="$PATH_SEPARATOR"
136 if test -x "$d/$progname" && test ! -d "$d/$progname"; then
137 self_abspathname="$d/$progname"
142 if test -z "$self_abspathname"; then
143 func_fatal_error "could not locate the posix-modules program - how did you invoke it?"
147 while test -h "$self_abspathname"; do
148 # Resolve symbolic link.
149 linkval=`func_readlink "$self_abspathname"`
150 test -n "$linkval" || break
152 /* ) self_abspathname="$linkval" ;;
153 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
156 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
160 # creates a temporary directory.
162 # - progname name of this program
164 # - tmp pathname of freshly created temporary directory
167 # Use the environment variable TMPDIR, falling back to /tmp. This allows
168 # users to specify a different temporary directory, for example, if their
169 # /tmp is filled up or too small.
172 # Use the mktemp program if available. If not available, hide the error
174 tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
175 test -n "$tmp" && test -d "$tmp"
178 # Use a simple mkdir command. It is guaranteed to fail if the directory
179 # already exists. $RANDOM is bash specific and expands to empty in shells
180 # other than bash, ksh and zsh. Its use does not increase security;
181 # rather, it minimizes the probability of failure in a very cluttered /tmp
183 tmp=$TMPDIR/gl$$-$RANDOM
184 (umask 077 && mkdir "$tmp")
187 echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
192 # func_fatal_error message
193 # outputs to stderr a fatal error message, and terminates the program.
195 # - progname name of this program
198 echo "$progname: *** $1" 1>&2
199 echo "$progname: *** Stop." 1>&2
203 # func_readlink SYMLINK
204 # outputs the target of the given symlink.
205 if (type -p readlink) > /dev/null 2>&1; then
208 # Use the readlink program from GNU coreutils.
214 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
215 # would do the wrong thing if the link target contains " -> ".
216 LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
220 # Command-line option processing.
221 while test $# -gt 0; do
223 --help | --hel | --he | --h )
226 --version | --versio | --versi | --vers | --ver | --ve | --v )
230 echo "posix-modules: unknown option $1" 1>&2
231 echo "Try 'posix-modules --help' for more information." 1>&2
234 echo "posix-modules: too many arguments" 1>&2
235 echo "Try 'posix-modules --help' for more information." 1>&2
242 # Get the header modules.
243 LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/posix-headers/*.texi 2>/dev/null \
244 | sed -e 's,^Gnulib module: ,,'
245 # Get the function modules.
246 LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/posix-functions/*.texi 2>/dev/null \
247 | sed -e 's,^Gnulib module: ,,'
248 # Then filter out the words "---", ",", "and", "or" and remove *-gnu modules.
249 ) | sed -e 's/,/ /g' | LC_ALL=C sort | LC_ALL=C uniq \
250 | { # Then filter out the words "---", "and", "or" and remove *-gnu modules.
251 tr ' ' '\012' | sed -e '/^---$/d' -e '/^and$/d' -e '/^or$/d' -e '/-gnu$/d'
253 | LC_ALL=C sort | LC_ALL=C uniq
256 # indent-tabs-mode: nil
257 # whitespace-check-buffer-indent: nil