1428d7b3dSmrg#! /bin/sh
2428d7b3dSmrg# Common wrapper for a few potentially missing GNU programs.
3428d7b3dSmrg
4428d7b3dSmrgscriptversion=2013-10-28.13; # UTC
5428d7b3dSmrg
6428d7b3dSmrg# Copyright (C) 1996-2013 Free Software Foundation, Inc.
7428d7b3dSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8428d7b3dSmrg
9428d7b3dSmrg# This program is free software; you can redistribute it and/or modify
10428d7b3dSmrg# it under the terms of the GNU General Public License as published by
11428d7b3dSmrg# the Free Software Foundation; either version 2, or (at your option)
12428d7b3dSmrg# any later version.
13428d7b3dSmrg
14428d7b3dSmrg# This program is distributed in the hope that it will be useful,
15428d7b3dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16428d7b3dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17428d7b3dSmrg# GNU General Public License for more details.
18428d7b3dSmrg
19428d7b3dSmrg# You should have received a copy of the GNU General Public License
20428d7b3dSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21428d7b3dSmrg
22428d7b3dSmrg# As a special exception to the GNU General Public License, if you
23428d7b3dSmrg# distribute this file as part of a program that contains a
24428d7b3dSmrg# configuration script generated by Autoconf, you may include it under
25428d7b3dSmrg# the same distribution terms that you use for the rest of that program.
26428d7b3dSmrg
27428d7b3dSmrgif test $# -eq 0; then
28428d7b3dSmrg  echo 1>&2 "Try '$0 --help' for more information"
29428d7b3dSmrg  exit 1
30428d7b3dSmrgfi
31428d7b3dSmrg
32428d7b3dSmrgcase $1 in
33428d7b3dSmrg
34428d7b3dSmrg  --is-lightweight)
35428d7b3dSmrg    # Used by our autoconf macros to check whether the available missing
36428d7b3dSmrg    # script is modern enough.
37428d7b3dSmrg    exit 0
38428d7b3dSmrg    ;;
39428d7b3dSmrg
40428d7b3dSmrg  --run)
41428d7b3dSmrg    # Back-compat with the calling convention used by older automake.
42428d7b3dSmrg    shift
43428d7b3dSmrg    ;;
44428d7b3dSmrg
45428d7b3dSmrg  -h|--h|--he|--hel|--help)
46428d7b3dSmrg    echo "\
47428d7b3dSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48428d7b3dSmrg
49428d7b3dSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50428d7b3dSmrgto PROGRAM being missing or too old.
51428d7b3dSmrg
52428d7b3dSmrgOptions:
53428d7b3dSmrg  -h, --help      display this help and exit
54428d7b3dSmrg  -v, --version   output version information and exit
55428d7b3dSmrg
56428d7b3dSmrgSupported PROGRAM values:
57428d7b3dSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58428d7b3dSmrg  bison     yacc      flex         lex       help2man
59428d7b3dSmrg
60428d7b3dSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61428d7b3dSmrg'g' are ignored when checking the name.
62428d7b3dSmrg
63428d7b3dSmrgSend bug reports to <bug-automake@gnu.org>."
64428d7b3dSmrg    exit $?
65428d7b3dSmrg    ;;
66428d7b3dSmrg
67428d7b3dSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68428d7b3dSmrg    echo "missing $scriptversion (GNU Automake)"
69428d7b3dSmrg    exit $?
70428d7b3dSmrg    ;;
71428d7b3dSmrg
72428d7b3dSmrg  -*)
73428d7b3dSmrg    echo 1>&2 "$0: unknown '$1' option"
74428d7b3dSmrg    echo 1>&2 "Try '$0 --help' for more information"
75428d7b3dSmrg    exit 1
76428d7b3dSmrg    ;;
77428d7b3dSmrg
78428d7b3dSmrgesac
79428d7b3dSmrg
80428d7b3dSmrg# Run the given program, remember its exit status.
81428d7b3dSmrg"$@"; st=$?
82428d7b3dSmrg
83428d7b3dSmrg# If it succeeded, we are done.
84428d7b3dSmrgtest $st -eq 0 && exit 0
85428d7b3dSmrg
86428d7b3dSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
87428d7b3dSmrg# passed; such an option is passed most likely to detect whether the
88428d7b3dSmrg# program is present and works.
89428d7b3dSmrgcase $2 in --version|--help) exit $st;; esac
90428d7b3dSmrg
91428d7b3dSmrg# Exit code 63 means version mismatch.  This often happens when the user
92428d7b3dSmrg# tries to use an ancient version of a tool on a file that requires a
93428d7b3dSmrg# minimum version.
94428d7b3dSmrgif test $st -eq 63; then
95428d7b3dSmrg  msg="probably too old"
96428d7b3dSmrgelif test $st -eq 127; then
97428d7b3dSmrg  # Program was missing.
98428d7b3dSmrg  msg="missing on your system"
99428d7b3dSmrgelse
100428d7b3dSmrg  # Program was found and executed, but failed.  Give up.
101428d7b3dSmrg  exit $st
102428d7b3dSmrgfi
103428d7b3dSmrg
104428d7b3dSmrgperl_URL=http://www.perl.org/
105428d7b3dSmrgflex_URL=http://flex.sourceforge.net/
106428d7b3dSmrggnu_software_URL=http://www.gnu.org/software
107428d7b3dSmrg
108428d7b3dSmrgprogram_details ()
109428d7b3dSmrg{
110428d7b3dSmrg  case $1 in
111428d7b3dSmrg    aclocal|automake)
112428d7b3dSmrg      echo "The '$1' program is part of the GNU Automake package:"
113428d7b3dSmrg      echo "<$gnu_software_URL/automake>"
114428d7b3dSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115428d7b3dSmrg      echo "<$gnu_software_URL/autoconf>"
116428d7b3dSmrg      echo "<$gnu_software_URL/m4/>"
117428d7b3dSmrg      echo "<$perl_URL>"
118428d7b3dSmrg      ;;
119428d7b3dSmrg    autoconf|autom4te|autoheader)
120428d7b3dSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
121428d7b3dSmrg      echo "<$gnu_software_URL/autoconf/>"
122428d7b3dSmrg      echo "It also requires GNU m4 and Perl in order to run:"
123428d7b3dSmrg      echo "<$gnu_software_URL/m4/>"
124428d7b3dSmrg      echo "<$perl_URL>"
125428d7b3dSmrg      ;;
126428d7b3dSmrg  esac
127428d7b3dSmrg}
128428d7b3dSmrg
129428d7b3dSmrggive_advice ()
130428d7b3dSmrg{
131428d7b3dSmrg  # Normalize program name to check for.
132428d7b3dSmrg  normalized_program=`echo "$1" | sed '
133428d7b3dSmrg    s/^gnu-//; t
134428d7b3dSmrg    s/^gnu//; t
135428d7b3dSmrg    s/^g//; t'`
136428d7b3dSmrg
137428d7b3dSmrg  printf '%s\n' "'$1' is $msg."
138428d7b3dSmrg
139428d7b3dSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140428d7b3dSmrg  case $normalized_program in
141428d7b3dSmrg    autoconf*)
142428d7b3dSmrg      echo "You should only need it if you modified 'configure.ac',"
143428d7b3dSmrg      echo "or m4 files included by it."
144428d7b3dSmrg      program_details 'autoconf'
145428d7b3dSmrg      ;;
146428d7b3dSmrg    autoheader*)
147428d7b3dSmrg      echo "You should only need it if you modified 'acconfig.h' or"
148428d7b3dSmrg      echo "$configure_deps."
149428d7b3dSmrg      program_details 'autoheader'
150428d7b3dSmrg      ;;
151428d7b3dSmrg    automake*)
152428d7b3dSmrg      echo "You should only need it if you modified 'Makefile.am' or"
153428d7b3dSmrg      echo "$configure_deps."
154428d7b3dSmrg      program_details 'automake'
155428d7b3dSmrg      ;;
156428d7b3dSmrg    aclocal*)
157428d7b3dSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
158428d7b3dSmrg      echo "$configure_deps."
159428d7b3dSmrg      program_details 'aclocal'
160428d7b3dSmrg      ;;
161428d7b3dSmrg   autom4te*)
162428d7b3dSmrg      echo "You might have modified some maintainer files that require"
163428d7b3dSmrg      echo "the 'autom4te' program to be rebuilt."
164428d7b3dSmrg      program_details 'autom4te'
165428d7b3dSmrg      ;;
166428d7b3dSmrg    bison*|yacc*)
167428d7b3dSmrg      echo "You should only need it if you modified a '.y' file."
168428d7b3dSmrg      echo "You may want to install the GNU Bison package:"
169428d7b3dSmrg      echo "<$gnu_software_URL/bison/>"
170428d7b3dSmrg      ;;
171428d7b3dSmrg    lex*|flex*)
172428d7b3dSmrg      echo "You should only need it if you modified a '.l' file."
173428d7b3dSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
174428d7b3dSmrg      echo "<$flex_URL>"
175428d7b3dSmrg      ;;
176428d7b3dSmrg    help2man*)
177428d7b3dSmrg      echo "You should only need it if you modified a dependency" \
178428d7b3dSmrg           "of a man page."
179428d7b3dSmrg      echo "You may want to install the GNU Help2man package:"
180428d7b3dSmrg      echo "<$gnu_software_URL/help2man/>"
181428d7b3dSmrg    ;;
182428d7b3dSmrg    makeinfo*)
183428d7b3dSmrg      echo "You should only need it if you modified a '.texi' file, or"
184428d7b3dSmrg      echo "any other file indirectly affecting the aspect of the manual."
185428d7b3dSmrg      echo "You might want to install the Texinfo package:"
186428d7b3dSmrg      echo "<$gnu_software_URL/texinfo/>"
187428d7b3dSmrg      echo "The spurious makeinfo call might also be the consequence of"
188428d7b3dSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189428d7b3dSmrg      echo "want to install GNU make:"
190428d7b3dSmrg      echo "<$gnu_software_URL/make/>"
191428d7b3dSmrg      ;;
192428d7b3dSmrg    *)
193428d7b3dSmrg      echo "You might have modified some files without having the proper"
194428d7b3dSmrg      echo "tools for further handling them.  Check the 'README' file, it"
195428d7b3dSmrg      echo "often tells you about the needed prerequisites for installing"
196428d7b3dSmrg      echo "this package.  You may also peek at any GNU archive site, in"
197428d7b3dSmrg      echo "case some other package contains this missing '$1' program."
198428d7b3dSmrg      ;;
199428d7b3dSmrg  esac
200428d7b3dSmrg}
201428d7b3dSmrg
202428d7b3dSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203428d7b3dSmrg                       -e '2,$s/^/         /' >&2
204428d7b3dSmrg
205428d7b3dSmrg# Propagate the correct exit status (expected to be 127 for a program
206428d7b3dSmrg# not found, 63 for a program that failed due to version mismatch).
207428d7b3dSmrgexit $st
208428d7b3dSmrg
209428d7b3dSmrg# Local variables:
210428d7b3dSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
211428d7b3dSmrg# time-stamp-start: "scriptversion="
212428d7b3dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213428d7b3dSmrg# time-stamp-time-zone: "UTC"
214428d7b3dSmrg# time-stamp-end: "; # UTC"
215428d7b3dSmrg# End:
216