missing: better tips about missing tools
[platform/upstream/automake.git] / lib / missing
1 #! /bin/sh
2 # Common wrapper for a few potentially missing GNU programs.
3
4 scriptversion=2012-06-23.01; # UTC
5
6 # Copyright (C) 1996-2012 Free Software Foundation, Inc.
7 # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
12 # any later version.
13
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22 # As a special exception to the GNU General Public License, if you
23 # distribute this file as part of a program that contains a
24 # configuration script generated by Autoconf, you may include it under
25 # the same distribution terms that you use for the rest of that program.
26
27 if test $# -eq 0; then
28   echo 1>&2 "Try '$0 --help' for more information"
29   exit 1
30 fi
31
32 # In the cases where this matters, 'missing' is being run in the
33 # srcdir already.
34 if test -f configure.ac; then
35   configure_ac=configure.ac
36 else
37   configure_ac=configure.in
38 fi
39
40 case $1 in
41
42   --is-lightweight)
43     # Used by our autoconf macros to check whether the available missing
44     # script is modern enough.
45     exit 0
46     ;;
47
48   -h|--h|--he|--hel|--help)
49     echo "\
50 $0 [OPTION]... PROGRAM [ARGUMENT]...
51
52 Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
53 to PROGRAM being missing or too old.
54
55 Options:
56   -h, --help      display this help and exit
57   -v, --version   output version information and exit
58
59 Supported PROGRAM values:
60   aclocal   autoconf  autoheader   autom4te  automake  makeinfo
61   bison     yacc      flex         lex       help2man
62
63 Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
64 'g' are ignored when checking the name.
65
66 Send bug reports to <bug-automake@gnu.org>."
67     exit $?
68     ;;
69
70   -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
71     echo "missing $scriptversion (GNU Automake)"
72     exit $?
73     ;;
74
75   -*)
76     echo 1>&2 "$0: unknown '$1' option"
77     echo 1>&2 "Try '$0 --help' for more information"
78     exit 1
79     ;;
80
81 esac
82
83 # Run the given program, remember its exit status.
84 "$@"; st=$?
85
86 # If it succeeded, we are done.
87 test $st -eq 0 && exit 0
88
89 # Also exit now if we it failed (or wasn't found), and '--version' was
90 # passed; such an option is passed most likely to detect whether the
91 # program is present and works.
92 case $2 in --version|--help) exit $st;; esac
93
94 # Exit code 63 means version mismatch.  This often happens when the user
95 # tries to use an ancient version of a tool on a file that requires a
96 # minimum version.
97 if test $st -eq 63; then
98   msg="probably too old"
99 elif test $st -eq 127; then
100   # Program was missing.
101   msg="missing on your system"
102 else
103   # Program was found and executed, but failed.  Give up.
104   exit $st
105 fi
106
107 perl_URL=http://www.perl.org/
108 flex_URL=http://flex.sourceforge.net/
109 gnu_software_URL=http://www.gnu.org/software
110
111 program_details ()
112 {
113   case $1 in
114     aclocal|automake)
115       echo "The '$1' program is part of the GNU Automake package:"
116       echo "<$gnu_software_URL/automake>"
117       echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
118       echo "<$gnu_software_URL/autoconf>"
119       echo "<$gnu_software_URL/m4/>"
120       echo "<$perl_URL>"
121       ;;
122     autoconf|autom4te|autoheader)
123       echo "The '$1' program is part of the GNU Autoconf package:"
124       echo "<$gnu_software_URL/autoconf/>"
125       echo "It also requires GNU m4 and Perl in order to run:"
126       echo "<$gnu_software_URL/m4/>"
127       echo "<$perl_URL>"
128       ;;
129   esac
130 }
131
132 give_advice ()
133 {
134   # Normalize program name to check for.
135   normalized_program=`echo "$1" | sed '
136     s/^gnu-//; t
137     s/^gnu//; t
138     s/^g//; t'`
139
140   printf '%s\n' "'$1' is $msg."
141  
142   configure_deps="'${configure_ac}' or m4 files included by '${configure_ac}'"
143   case $normalized_program in
144     autoconf*)
145       echo "You should only need it if you modified '${configure_ac}',"
146       echo "or m4 files included by it."
147       program_details 'autoconf'
148       ;;
149     autoheader*)
150       echo "You should only need it if you modified 'acconfig.h' or"
151       echo "$configure_deps."
152       program_details 'autoheader'
153       ;;
154     automake*)
155       echo "You should only need it if you modified 'Makefile.am' or"
156       echo "$configure_deps."
157       program_details 'automake'
158       ;;
159     aclocal*)
160       echo "You should only need it if you modified 'acinclude.m4' or"
161       echo "$configure_deps."
162       program_details 'aclocal'
163       ;;
164    autom4te*)
165       echo "You might have modified some maintainer files that require"
166       echo "the 'automa4te' program to be rebuilt."
167       program_details 'autom4te'
168       ;;
169     bison*|yacc*)
170       echo "You should only need it if you modified a '.y' file."
171       echo "You may want to install the GNU Bison package:"
172       echo "<$gnu_software_URL/bison/>"
173       ;;
174     lex*|flex*)
175       echo "You should only need it if you modified a '.l' file."
176       echo "You may want to install the Fast Lexical Analyzer package:"
177       echo "<$flex_URL>"
178       ;;
179     help2man*)
180       echo "You should only need it if you modified a dependency" \
181            "of a man page."
182       echo "You may want to install the GNU Help2man package:"
183       echo "<$gnu_software_URL/help2man/>"
184     ;;
185     makeinfo*)
186       echo "You should only need it if you modified a '.texi' file, or"
187       echo "any other file indirectly affecting the aspect of the manual."
188       echo "You might want to install the Texinfo package:"
189       echo "<$gnu_software_URL/texinfo/>"
190       echo "The spurious makeinfo call might also be the consequence of"
191       echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
192       echo "want to install GNU make:"
193       echo "<$gnu_software_URL/make/>"
194       ;;
195     *)
196       echo "You might have modified some files without having the proper"
197       echo "tools for further handling them.  Check the 'README' file, it"
198       echo "often tells you about the needed prerequisites for installing"
199       echo "this package.  You may also peek at any GNU archive site, in"
200       echo "case some other package contains this missing '$1' program."
201       ;;
202   esac
203 }
204
205 give_advice "$1" | sed -e '1s/^/WARNING: /' \
206                        -e '2,$s/^/         /' >&2
207
208 # Propagate the correct exit status (expected to be 127 for a program
209 # not found, 63 for a program that failed due to version mismatch).
210 exit $st
211
212 # Local variables:
213 # eval: (add-hook 'write-file-hooks 'time-stamp)
214 # time-stamp-start: "scriptversion="
215 # time-stamp-format: "%:y-%02m-%02d.%02H"
216 # time-stamp-time-zone: "UTC"
217 # time-stamp-end: "; # UTC"
218 # End: