3 # Copyright (C) 2002-2008, 2010-2012 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 if test -d "$gnulib_dir"/CVS \
56 && (cvs
--version) >/dev
/null
2>/dev
/null
; then
57 # gnulib checked out from CVS.
58 sed_extract_first_date
='/^date: /{
59 s/^date: \([0-9][0-9][0-9][0-9]\).\([0-9][0-9]\).\([0-9][0-9]\) \([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*/\1-\2-\3 \4/p
62 date=`cd "$gnulib_dir" && cvs log -N ChangeLog 2>/dev/null | sed -n -e "$sed_extract_first_date"`
64 # gnulib copy without versioning information.
65 date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
69 year
=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
71 posix-modules (GNU $package $date)$version
72 Copyright (C) $year Free Software Foundation, Inc.
73 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
74 This is free software: you are free to change and redistribute it.
75 There is NO WARRANTY, to the extent permitted by law.
77 Written by" "Bruno Haible"
81 # exits with a given status.
82 # This function needs to be used, rather than 'exit', when a 'trap' handler is
83 # in effect that refers to $?.
90 # locates the directory where the gnulib repository lives
92 # - progname name of this program
94 # - self_abspathname absolute pathname of this program
95 # - gnulib_dir absolute pathname of gnulib repository
99 /*) self_abspathname
="$progname" ;;
100 */*) self_abspathname
=`pwd`/"$progname" ;;
103 # Iterate through the elements of $PATH.
104 # We use IFS=: instead of
105 # for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
106 # because the latter does not work when some PATH element contains spaces.
107 # We use a canonicalized $pathx instead of $PATH, because empty PATH
108 # elements are by definition equivalent to '.', however field splitting
109 # according to IFS=: loses empty fields in many shells:
110 # - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
111 # beginning, at the end, and in the middle),
112 # - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
113 # at the beginning and at the end,
114 # - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
115 # Solaris lose empty fields at the end.
116 # The 'case' statement is an optimization, to avoid evaluating the
117 # explicit canonicalization command when $PATH contains no empty fields.
119 if test "${PATH_SEPARATOR+set}" != set; then
120 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
121 # contains only /bin. Note that ksh looks also at the FPATH variable,
122 # so we have to set that as well for the test.
124 (PATH
='/bin;/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
125 && { (PATH
='/bin:/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
126 || PATH_SEPARATOR
=';'
129 if test "$PATH_SEPARATOR" = ";"; then
130 # On Windows, programs are searched in "." before $PATH.
133 # On Unix, we have to convert empty PATH elements to ".".
137 pathx
=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
142 IFS
="$PATH_SEPARATOR"
146 if test -x "$d/$progname" && test ! -d "$d/$progname"; then
147 self_abspathname
="$d/$progname"
152 if test -z "$self_abspathname"; then
153 func_fatal_error
"could not locate the posix-modules program - how did you invoke it?"
157 while test -h "$self_abspathname"; do
158 # Resolve symbolic link.
159 linkval
=`func_readlink "$self_abspathname"`
160 test -n "$linkval" ||
break
162 /* ) self_abspathname
="$linkval" ;;
163 * ) self_abspathname
=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
166 gnulib_dir
=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
170 # creates a temporary directory.
172 # - progname name of this program
174 # - tmp pathname of freshly created temporary directory
177 # Use the environment variable TMPDIR, falling back to /tmp. This allows
178 # users to specify a different temporary directory, for example, if their
179 # /tmp is filled up or too small.
182 # Use the mktemp program if available. If not available, hide the error
184 tmp
=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
185 test -n "$tmp" && test -d "$tmp"
188 # Use a simple mkdir command. It is guaranteed to fail if the directory
189 # already exists. $RANDOM is bash specific and expands to empty in shells
190 # other than bash, ksh and zsh. Its use does not increase security;
191 # rather, it minimizes the probability of failure in a very cluttered /tmp
193 tmp
=$TMPDIR/gl$$
-$RANDOM
194 (umask 077 && mkdir
"$tmp")
197 echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
202 # func_fatal_error message
203 # outputs to stderr a fatal error message, and terminates the program.
205 # - progname name of this program
208 echo "$progname: *** $1" 1>&2
209 echo "$progname: *** Stop." 1>&2
213 # func_readlink SYMLINK
214 # outputs the target of the given symlink.
215 if (type -p readlink
) > /dev
/null
2>&1; then
218 # Use the readlink program from GNU coreutils.
224 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
225 # would do the wrong thing if the link target contains " -> ".
226 LC_ALL
=C
ls -l "$1" |
sed -e 's, -> ,#%%#,' |
sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
230 # Command-line option processing.
231 while test $# -gt 0; do
233 --help |
--hel |
--he |
--h )
236 --version |
--versio |
--versi |
--vers |
--ver |
--ve |
--v )
240 echo "posix-modules: unknown option $1" 1>&2
241 echo "Try 'posix-modules --help' for more information." 1>&2
244 echo "posix-modules: too many arguments" 1>&2
245 echo "Try 'posix-modules --help' for more information." 1>&2
252 # Get the header modules.
253 LC_ALL
=C
grep -h '^Gnulib module: ' "$gnulib_dir"/doc
/posix-headers
/*.texi
2>/dev
/null \
254 |
sed -e 's,^Gnulib module: ,,'
255 # Get the function modules.
256 LC_ALL
=C
grep -h '^Gnulib module: ' "$gnulib_dir"/doc
/posix-functions
/*.texi
2>/dev
/null \
257 |
sed -e 's,^Gnulib module: ,,'
258 # Then filter out the words "---", ",", "and", "or" and remove *-gnu modules.
259 ) |
sed -e 's/,/ /g' | LC_ALL
=C
sort | LC_ALL
=C
uniq \
260 |
{ # Then filter out the words "---", "and", "or" and remove *-gnu modules.
261 tr ' ' '\012' |
sed -e '/^---$/d' -e '/^and$/d' -e '/^or$/d' -e '/-gnu$/d'
263 | LC_ALL
=C
sort | LC_ALL
=C
uniq
266 # indent-tabs-mode: nil
267 # whitespace-check-buffer-indent: nil