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