md5, sha1, sha256, sha512: add gl_SET_CRYPTO_CHECK_DEFAULT
[gnulib.git] / posix-modules
1 #!/bin/sh
2 #
3 # Copyright (C) 2002-2008, 2010-2013 Free Software Foundation, Inc.
4 #
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.
9 #
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.
14 #
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/>.
17 #
18
19 progname=$0
20 package=gnulib
21
22 # func_usage
23 # outputs to stdout the --help usage message.
24 func_usage ()
25 {
26   echo "\
27 Usage: posix-modules
28
29 Lists the gnulib modules that implement POSIX interfaces.
30
31 Report bugs to <bug-gnulib@gnu.org>."
32 }
33
34 # func_version
35 # outputs to stdout the --version message.
36 func_version ()
37 {
38   func_gnulib_dir
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/{
44 s/^Date:[        ]*//p
45 q
46 }'
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/'`
54   else
55     # gnulib copy without versioning information.
56     date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
57     version=
58   fi
59   year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
60   echo "\
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.
66
67 Written by" "Bruno Haible"
68 }
69
70 # func_exit STATUS
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 $?.
74 func_exit ()
75 {
76   (exit $1); exit $1
77 }
78
79 # func_gnulib_dir
80 # locates the directory where the gnulib repository lives
81 # Input:
82 # - progname                 name of this program
83 # Sets variables
84 # - self_abspathname         absolute pathname of this program
85 # - gnulib_dir               absolute pathname of gnulib repository
86 func_gnulib_dir ()
87 {
88   case "$progname" in
89     /*) self_abspathname="$progname" ;;
90     */*) self_abspathname=`pwd`/"$progname" ;;
91     *)
92       # Look in $PATH.
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.
108       self_abspathname=
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.
113         PATH_SEPARATOR=:
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=';'
117              }
118       fi
119       if test "$PATH_SEPARATOR" = ";"; then
120         # On Windows, programs are searched in "." before $PATH.
121         pathx=".;$PATH"
122       else
123         # On Unix, we have to convert empty PATH elements to ".".
124         pathx="$PATH"
125         case :$PATH: in
126           *::*)
127             pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
128             ;;
129         esac
130       fi
131       save_IFS="$IFS"
132       IFS="$PATH_SEPARATOR"
133       for d in $pathx; do
134         IFS="$save_IFS"
135         test -z "$d" && d=.
136         if test -x "$d/$progname" && test ! -d "$d/$progname"; then
137           self_abspathname="$d/$progname"
138           break
139         fi
140       done
141       IFS="$save_IFS"
142       if test -z "$self_abspathname"; then
143         func_fatal_error "could not locate the posix-modules program - how did you invoke it?"
144       fi
145       ;;
146   esac
147   while test -h "$self_abspathname"; do
148     # Resolve symbolic link.
149     linkval=`func_readlink "$self_abspathname"`
150     test -n "$linkval" || break
151     case "$linkval" in
152       /* ) self_abspathname="$linkval" ;;
153       * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
154     esac
155   done
156   gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
157 }
158
159 # func_tmpdir
160 # creates a temporary directory.
161 # Input:
162 # - progname                 name of this program
163 # Sets variable
164 # - tmp             pathname of freshly created temporary directory
165 func_tmpdir ()
166 {
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.
170   : ${TMPDIR=/tmp}
171   {
172     # Use the mktemp program if available. If not available, hide the error
173     # message.
174     tmp=`(umask 077 && mktemp -d "$TMPDIR/glXXXXXX") 2>/dev/null` &&
175     test -n "$tmp" && test -d "$tmp"
176   } ||
177   {
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
182     # directory.
183     tmp=$TMPDIR/gl$$-$RANDOM
184     (umask 077 && mkdir "$tmp")
185   } ||
186   {
187     echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
188     func_exit 1
189   }
190 }
191
192 # func_fatal_error message
193 # outputs to stderr a fatal error message, and terminates the program.
194 # Input:
195 # - progname                 name of this program
196 func_fatal_error ()
197 {
198   echo "$progname: *** $1" 1>&2
199   echo "$progname: *** Stop." 1>&2
200   func_exit 1
201 }
202
203 # func_readlink SYMLINK
204 # outputs the target of the given symlink.
205 if (type -p readlink) > /dev/null 2>&1; then
206   func_readlink ()
207   {
208     # Use the readlink program from GNU coreutils.
209     readlink "$1"
210   }
211 else
212   func_readlink ()
213   {
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'
217   }
218 fi
219
220 # Command-line option processing.
221 while test $# -gt 0; do
222   case "$1" in
223     --help | --hel | --he | --h )
224       func_usage
225       exit $? ;;
226     --version | --versio | --versi | --vers | --ver | --ve | --v )
227       func_version
228       exit $? ;;
229     -* )
230       echo "posix-modules: unknown option $1" 1>&2
231       echo "Try 'posix-modules --help' for more information." 1>&2
232       exit 1 ;;
233     * )
234       echo "posix-modules: too many arguments" 1>&2
235       echo "Try 'posix-modules --help' for more information." 1>&2
236       exit 1 ;;
237   esac
238 done
239
240 func_gnulib_dir
241 (
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'
252     } \
253   | LC_ALL=C sort | LC_ALL=C uniq
254
255 # Local Variables:
256 # indent-tabs-mode: nil
257 # whitespace-check-buffer-indent: nil
258 # End: