3 # Copyright (C) 2002-2008, 2010 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 Report bugs to <bug-gnulib@gnu.org>."
33 # outputs to stdout the --version message.
37 if test -d "$gnulib_dir"/.git \
38 && (git
--version) >/dev
/null
2>/dev
/null \
39 && (date --version) >/dev
/null
2>/dev
/null
; then
40 # gnulib checked out from git.
41 sed_extract_first_date
='/^Date/{
45 date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"`
46 # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600".
47 sed_year_before_time
='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /'
48 date=`echo "$date" | sed -e "$sed_year_before_time"`
49 # Use GNU date to compute the time in GMT.
50 date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
51 version
=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
53 if test -d "$gnulib_dir"/CVS \
54 && (cvs
--version) >/dev
/null
2>/dev
/null
; then
55 # gnulib checked out from CVS.
56 sed_extract_first_date
='/^date: /{
57 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
60 date=`cd "$gnulib_dir" && cvs log -N ChangeLog 2>/dev/null | sed -n -e "$sed_extract_first_date"`
62 # gnulib copy without versioning information.
63 date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
67 year
=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
69 posix-modules (GNU $package $date)$version
70 Copyright (C) $year Free Software Foundation, Inc.
71 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
72 This is free software: you are free to change and redistribute it.
73 There is NO WARRANTY, to the extent permitted by law.
75 Written by" "Bruno Haible"
79 # exits with a given status.
80 # This function needs to be used, rather than 'exit', when a 'trap' handler is
81 # in effect that refers to $?.
88 # locates the directory where the gnulib repository lives
90 # - progname name of this program
92 # - self_abspathname absolute pathname of this program
93 # - gnulib_dir absolute pathname of gnulib repository
97 /*) self_abspathname
="$progname" ;;
98 */*) self_abspathname
=`pwd`/"$progname" ;;
101 # Iterate through the elements of $PATH.
102 # We use IFS=: instead of
103 # for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
104 # because the latter does not work when some PATH element contains spaces.
105 # We use a canonicalized $pathx instead of $PATH, because empty PATH
106 # elements are by definition equivalent to '.', however field splitting
107 # according to IFS=: loses empty fields in many shells:
108 # - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
109 # beginning, at the end, and in the middle),
110 # - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
111 # at the beginning and at the end,
112 # - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
113 # Solaris lose empty fields at the end.
114 # The 'case' statement is an optimization, to avoid evaluating the
115 # explicit canonicalization command when $PATH contains no empty fields.
117 if test "${PATH_SEPARATOR+set}" != set; then
118 # Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
119 # contains only /bin. Note that ksh looks also at the FPATH variable,
120 # so we have to set that as well for the test.
122 (PATH
='/bin;/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
123 && { (PATH
='/bin:/bin'; FPATH
=$PATH; sh
-c :) >/dev
/null
2>&1 \
124 || PATH_SEPARATOR
=';'
127 if test "$PATH_SEPARATOR" = ";"; then
128 # On Windows, programs are searched in "." before $PATH.
131 # On Unix, we have to convert empty PATH elements to ".".
135 pathx
=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
140 IFS
="$PATH_SEPARATOR"
144 if test -x "$d/$progname" && test ! -d "$d/$progname"; then
145 self_abspathname
="$d/$progname"
150 if test -z "$self_abspathname"; then
151 func_fatal_error
"could not locate the posix-modules program - how did you invoke it?"
155 while test -h "$self_abspathname"; do
156 # Resolve symbolic link.
157 linkval
=`func_readlink "$self_abspathname"`
158 test -n "$linkval" ||
break
160 /* ) self_abspathname
="$linkval" ;;
161 * ) self_abspathname
=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
164 gnulib_dir
=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
168 # creates a temporary directory.
170 # - progname name of this program
172 # - tmp pathname of freshly created temporary directory
175 # Use the environment variable TMPDIR, falling back to /tmp. This allows
176 # users to specify a different temporary directory, for example, if their
177 # /tmp is filled up or too small.
180 # Use the mktemp program if available. If not available, hide the error
182 tmp
=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
183 test -n "$tmp" && test -d "$tmp"
186 # Use a simple mkdir command. It is guaranteed to fail if the directory
187 # already exists. $RANDOM is bash specific and expands to empty in shells
188 # other than bash, ksh and zsh. Its use does not increase security;
189 # rather, it minimizes the probability of failure in a very cluttered /tmp
191 tmp
=$TMPDIR/gl$$
-$RANDOM
192 (umask 077 && mkdir
"$tmp")
195 echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
200 # func_fatal_error message
201 # outputs to stderr a fatal error message, and terminates the program.
203 # - progname name of this program
206 echo "$progname: *** $1" 1>&2
207 echo "$progname: *** Stop." 1>&2
211 # func_readlink SYMLINK
212 # outputs the target of the given symlink.
213 if (type -p readlink
) > /dev
/null
2>&1; then
216 # Use the readlink program from GNU coreutils.
222 # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p'
223 # would do the wrong thing if the link target contains " -> ".
224 LC_ALL
=C
ls -l "$1" |
sed -e 's, -> ,#%%#,' |
sed -n -e 's,^.*#%%#\(.*\)$,\1,p'
228 # Command-line option processing.
229 while test $# -gt 0; do
231 --help |
--hel |
--he |
--h )
234 --version |
--versio |
--versi |
--vers |
--ver |
--ve |
--v )
238 echo "posix-modules: unknown option $1" 1>&2
239 echo "Try 'posix-modules --help' for more information." 1>&2
242 echo "posix-modules: too many arguments" 1>&2
243 echo "Try 'posix-modules --help' for more information." 1>&2
250 # Get the header modules.
251 LC_ALL
=C
grep -h '^Gnulib module: ' "$gnulib_dir"/doc
/posix-headers
/*.texi
2>/dev
/null \
252 |
sed -e 's,^Gnulib module: ,,'
253 # Get the function modules.
254 LC_ALL
=C
grep -h '^Gnulib module: ' "$gnulib_dir"/doc
/posix-functions
/*.texi
2>/dev
/null \
255 |
sed -e 's,^Gnulib module: ,,'
256 # Then filter out the words "---", ",", "and", "or" and remove *-gnu modules.
257 ) |
sed -e 's/,/ /g' | LC_ALL
=C
sort | LC_ALL
=C
uniq \
258 |
{ # Then filter out the words "---", "and", "or" and remove *-gnu modules.
259 tr ' ' '\012' |
sed -e '/^---$/d' -e '/^and$/d' -e '/^or$/d' -e '/-gnu$/d'
261 | LC_ALL
=C
sort | LC_ALL
=C
uniq
264 # indent-tabs-mode: nil
265 # whitespace-check-buffer-indent: nil