1117610Sdes#! /bin/sh
2255376Sdes# Common wrapper for a few potentially missing GNU programs.
3141098Sdes
4255376Sdesscriptversion=2012-06-26.16; # UTC
5141098Sdes
6255376Sdes# Copyright (C) 1996-2013 Free Software Foundation, Inc.
7255376Sdes# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8117610Sdes
9117610Sdes# This program is free software; you can redistribute it and/or modify
10117610Sdes# it under the terms of the GNU General Public License as published by
11117610Sdes# the Free Software Foundation; either version 2, or (at your option)
12117610Sdes# any later version.
13117610Sdes
14117610Sdes# This program is distributed in the hope that it will be useful,
15117610Sdes# but WITHOUT ANY WARRANTY; without even the implied warranty of
16117610Sdes# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17117610Sdes# GNU General Public License for more details.
18117610Sdes
19117610Sdes# You should have received a copy of the GNU General Public License
20228692Sdes# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21117610Sdes
22117610Sdes# As a special exception to the GNU General Public License, if you
23117610Sdes# distribute this file as part of a program that contains a
24117610Sdes# configuration script generated by Autoconf, you may include it under
25117610Sdes# the same distribution terms that you use for the rest of that program.
26117610Sdes
27117610Sdesif test $# -eq 0; then
28255376Sdes  echo 1>&2 "Try '$0 --help' for more information"
29117610Sdes  exit 1
30117610Sdesfi
31117610Sdes
32255376Sdescase $1 in
33117610Sdes
34255376Sdes  --is-lightweight)
35255376Sdes    # Used by our autoconf macros to check whether the available missing
36255376Sdes    # script is modern enough.
37255376Sdes    exit 0
38255376Sdes    ;;
39117610Sdes
40255376Sdes  --run)
41255376Sdes    # Back-compat with the calling convention used by older automake.
42255376Sdes    shift
43255376Sdes    ;;
44141098Sdes
45117610Sdes  -h|--h|--he|--hel|--help)
46117610Sdes    echo "\
47117610Sdes$0 [OPTION]... PROGRAM [ARGUMENT]...
48117610Sdes
49255376SdesRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50255376Sdesto PROGRAM being missing or too old.
51117610Sdes
52117610SdesOptions:
53117610Sdes  -h, --help      display this help and exit
54117610Sdes  -v, --version   output version information and exit
55117610Sdes
56117610SdesSupported PROGRAM values:
57255376Sdes  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58255376Sdes  bison     yacc      flex         lex       help2man
59141098Sdes
60255376SdesVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61255376Sdes'g' are ignored when checking the name.
62228692Sdes
63141098SdesSend bug reports to <bug-automake@gnu.org>."
64174832Sdes    exit $?
65117610Sdes    ;;
66117610Sdes
67117610Sdes  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68141098Sdes    echo "missing $scriptversion (GNU Automake)"
69174832Sdes    exit $?
70117610Sdes    ;;
71117610Sdes
72117610Sdes  -*)
73255376Sdes    echo 1>&2 "$0: unknown '$1' option"
74255376Sdes    echo 1>&2 "Try '$0 --help' for more information"
75117610Sdes    exit 1
76117610Sdes    ;;
77117610Sdes
78174832Sdesesac
79174832Sdes
80255376Sdes# Run the given program, remember its exit status.
81255376Sdes"$@"; st=$?
82228692Sdes
83255376Sdes# If it succeeded, we are done.
84255376Sdestest $st -eq 0 && exit 0
85174832Sdes
86255376Sdes# Also exit now if we it failed (or wasn't found), and '--version' was
87255376Sdes# passed; such an option is passed most likely to detect whether the
88255376Sdes# program is present and works.
89255376Sdescase $2 in --version|--help) exit $st;; esac
90174832Sdes
91255376Sdes# Exit code 63 means version mismatch.  This often happens when the user
92255376Sdes# tries to use an ancient version of a tool on a file that requires a
93255376Sdes# minimum version.
94255376Sdesif test $st -eq 63; then
95255376Sdes  msg="probably too old"
96255376Sdeselif test $st -eq 127; then
97255376Sdes  # Program was missing.
98255376Sdes  msg="missing on your system"
99255376Sdeselse
100255376Sdes  # Program was found and executed, but failed.  Give up.
101255376Sdes  exit $st
102255376Sdesfi
103141098Sdes
104255376Sdesperl_URL=http://www.perl.org/
105255376Sdesflex_URL=http://flex.sourceforge.net/
106255376Sdesgnu_software_URL=http://www.gnu.org/software
107117610Sdes
108255376Sdesprogram_details ()
109255376Sdes{
110255376Sdes  case $1 in
111255376Sdes    aclocal|automake)
112255376Sdes      echo "The '$1' program is part of the GNU Automake package:"
113255376Sdes      echo "<$gnu_software_URL/automake>"
114255376Sdes      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115255376Sdes      echo "<$gnu_software_URL/autoconf>"
116255376Sdes      echo "<$gnu_software_URL/m4/>"
117255376Sdes      echo "<$perl_URL>"
118255376Sdes      ;;
119255376Sdes    autoconf|autom4te|autoheader)
120255376Sdes      echo "The '$1' program is part of the GNU Autoconf package:"
121255376Sdes      echo "<$gnu_software_URL/autoconf/>"
122255376Sdes      echo "It also requires GNU m4 and Perl in order to run:"
123255376Sdes      echo "<$gnu_software_URL/m4/>"
124255376Sdes      echo "<$perl_URL>"
125255376Sdes      ;;
126255376Sdes  esac
127255376Sdes}
128117610Sdes
129255376Sdesgive_advice ()
130255376Sdes{
131255376Sdes  # Normalize program name to check for.
132255376Sdes  normalized_program=`echo "$1" | sed '
133255376Sdes    s/^gnu-//; t
134255376Sdes    s/^gnu//; t
135255376Sdes    s/^g//; t'`
136117610Sdes
137255376Sdes  printf '%s\n' "'$1' is $msg."
138117610Sdes
139255376Sdes  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140255376Sdes  case $normalized_program in
141255376Sdes    autoconf*)
142255376Sdes      echo "You should only need it if you modified 'configure.ac',"
143255376Sdes      echo "or m4 files included by it."
144255376Sdes      program_details 'autoconf'
145255376Sdes      ;;
146255376Sdes    autoheader*)
147255376Sdes      echo "You should only need it if you modified 'acconfig.h' or"
148255376Sdes      echo "$configure_deps."
149255376Sdes      program_details 'autoheader'
150255376Sdes      ;;
151255376Sdes    automake*)
152255376Sdes      echo "You should only need it if you modified 'Makefile.am' or"
153255376Sdes      echo "$configure_deps."
154255376Sdes      program_details 'automake'
155255376Sdes      ;;
156255376Sdes    aclocal*)
157255376Sdes      echo "You should only need it if you modified 'acinclude.m4' or"
158255376Sdes      echo "$configure_deps."
159255376Sdes      program_details 'aclocal'
160255376Sdes      ;;
161255376Sdes   autom4te*)
162255376Sdes      echo "You might have modified some maintainer files that require"
163255376Sdes      echo "the 'automa4te' program to be rebuilt."
164255376Sdes      program_details 'autom4te'
165255376Sdes      ;;
166255376Sdes    bison*|yacc*)
167255376Sdes      echo "You should only need it if you modified a '.y' file."
168255376Sdes      echo "You may want to install the GNU Bison package:"
169255376Sdes      echo "<$gnu_software_URL/bison/>"
170255376Sdes      ;;
171255376Sdes    lex*|flex*)
172255376Sdes      echo "You should only need it if you modified a '.l' file."
173255376Sdes      echo "You may want to install the Fast Lexical Analyzer package:"
174255376Sdes      echo "<$flex_URL>"
175255376Sdes      ;;
176255376Sdes    help2man*)
177255376Sdes      echo "You should only need it if you modified a dependency" \
178255376Sdes           "of a man page."
179255376Sdes      echo "You may want to install the GNU Help2man package:"
180255376Sdes      echo "<$gnu_software_URL/help2man/>"
181141098Sdes    ;;
182255376Sdes    makeinfo*)
183255376Sdes      echo "You should only need it if you modified a '.texi' file, or"
184255376Sdes      echo "any other file indirectly affecting the aspect of the manual."
185255376Sdes      echo "You might want to install the Texinfo package:"
186255376Sdes      echo "<$gnu_software_URL/texinfo/>"
187255376Sdes      echo "The spurious makeinfo call might also be the consequence of"
188255376Sdes      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189255376Sdes      echo "want to install GNU make:"
190255376Sdes      echo "<$gnu_software_URL/make/>"
191255376Sdes      ;;
192255376Sdes    *)
193255376Sdes      echo "You might have modified some files without having the proper"
194255376Sdes      echo "tools for further handling them.  Check the 'README' file, it"
195255376Sdes      echo "often tells you about the needed prerequisites for installing"
196255376Sdes      echo "this package.  You may also peek at any GNU archive site, in"
197255376Sdes      echo "case some other package contains this missing '$1' program."
198255376Sdes      ;;
199255376Sdes  esac
200255376Sdes}
201141098Sdes
202255376Sdesgive_advice "$1" | sed -e '1s/^/WARNING: /' \
203255376Sdes                       -e '2,$s/^/         /' >&2
204117610Sdes
205255376Sdes# Propagate the correct exit status (expected to be 127 for a program
206255376Sdes# not found, 63 for a program that failed due to version mismatch).
207255376Sdesexit $st
208117610Sdes
209141098Sdes# Local variables:
210141098Sdes# eval: (add-hook 'write-file-hooks 'time-stamp)
211141098Sdes# time-stamp-start: "scriptversion="
212141098Sdes# time-stamp-format: "%:y-%02m-%02d.%02H"
213228692Sdes# time-stamp-time-zone: "UTC"
214228692Sdes# time-stamp-end: "; # UTC"
215141098Sdes# End:
216