Script to print the POSIX substitutes modules.
[gnulib.git] / posix-modules
1 #!/bin/sh
2 #
3 # Copyright (C) 2002-2007 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 2, or (at your option)
8 # 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, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19
20 progname=$0
21 package=gnulib
22 cvsdatestamp='$Date: 2007-09-08 22:27:19 $'
23 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
24 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
25
26 # func_usage
27 # outputs to stdout the --help usage message.
28 func_usage ()
29 {
30   echo "\
31 Usage: posix-modules
32
33 Report bugs to <bug-gnulib@gnu.org>."
34 }
35
36 # func_version
37 # outputs to stdout the --version message.
38 func_version ()
39 {
40   year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
41   echo "\
42 $progname (GNU $package) $version
43 Copyright (C) $year Free Software Foundation, Inc.
44 This is free software; see the source for copying conditions.  There is NO
45 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
46 Written by" "Bruno Haible"
47 }
48
49 case "$0" in
50   /*) self_abspathname="$0" ;;
51   */*) self_abspathname=`pwd`/"$0" ;;
52   *)
53     # Look in $PATH.
54     # Iterate through the elements of $PATH.
55     # We use IFS=: instead of
56     #   for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
57     # because the latter does not work when some PATH element contains spaces.
58     # We use a canonicalized $pathx instead of $PATH, because empty PATH
59     # elements are by definition equivalent to '.', however field splitting
60     # according to IFS=: loses empty fields in many shells:
61     #   - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
62     #     beginning, at the end, and in the middle),
63     #   - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
64     #     at the beginning and at the end,
65     #   - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
66     #     Solaris lose empty fields at the end.
67     # The 'case' statement is an optimization, to avoid evaluating the
68     # explicit canonicalization command when $PATH contains no empty fields.
69     self_abspathname=
70     if test "${PATH_SEPARATOR+set}" != set; then
71       func_tmpdir
72       { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
73       chmod +x "$tmp"/conf.sh
74       if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
75         PATH_SEPARATOR=';'
76       else
77         PATH_SEPARATOR=:
78       fi
79       rm -rf "$tmp"
80     fi
81     if test "$PATH_SEPARATOR" = ";"; then
82       # On Windows, programs are searched in "." before $PATH.
83       pathx=".;$PATH"
84     else
85       # On Unix, we have to convert empty PATH elements to ".".
86       pathx="$PATH"
87       case :$PATH: in
88         *::*)
89           pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 's/:\$//'`
90           ;;
91       esac
92     fi
93     save_IFS="$IFS"
94     IFS="$PATH_SEPARATOR"
95     for d in $pathx; do
96       IFS="$save_IFS"
97       test -z "$d" && d=.
98       if test -x "$d/$0" && test ! -d "$d/$0"; then
99         self_abspathname="$d/$0"
100         break
101       fi
102     done
103     IFS="$save_IFS"
104     if test -z "$self_abspathname"; then
105       func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
106     fi
107     ;;
108 esac
109 while test -h "$self_abspathname"; do
110   # Resolve symbolic link.
111   linkval=`func_readlink "$self_abspathname"`
112   test -n "$linkval" || break
113   case "$linkval" in
114     /* ) self_abspathname="$linkval" ;;
115     * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
116   esac
117 done
118 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
119
120 (
121   # Get the header modules.
122   LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/headers/* 2>/dev/null \
123     | sed -e 's,^Gnulib module: ,,'
124   # Get the function modules.
125   LC_ALL=C grep -h '^Gnulib module: ' "$gnulib_dir"/doc/functions/* 2>/dev/null \
126     | sed -e 's,^Gnulib module: ,,'
127   # Then filter out the words "---", "and", "or" and remove *-gnu modules.
128 ) | LC_ALL=C sort | LC_ALL=C uniq \
129   | { # Then filter out the words "---", "and", "or" and remove *-gnu modules.
130       tr ' ' '\012' | sed -e '/^---$/d' -e '/^and$/d' -e '/^or$/d' -e '/-gnu$/d'
131     } \
132   | LC_ALL=C sort | LC_ALL=C uniq \
133   | { # Except ftruncate, which aborts the configuration on mingw. FiXME
134       sed -e '/^ftruncate$/d'
135     }