1275970Scy#! /bin/sh
2316722Sdelphij# Common wrapper for a few potentially missing GNU programs.
3275970Scy
4316722Sdelphijscriptversion=2013-10-28.13; # UTC
5275970Scy
6316722Sdelphij# Copyright (C) 1996-2014 Free Software Foundation, Inc.
7316722Sdelphij# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8275970Scy
9275970Scy# This program is free software; you can redistribute it and/or modify
10275970Scy# it under the terms of the GNU General Public License as published by
11275970Scy# the Free Software Foundation; either version 2, or (at your option)
12275970Scy# any later version.
13275970Scy
14275970Scy# This program is distributed in the hope that it will be useful,
15275970Scy# but WITHOUT ANY WARRANTY; without even the implied warranty of
16275970Scy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17275970Scy# GNU General Public License for more details.
18275970Scy
19275970Scy# You should have received a copy of the GNU General Public License
20275970Scy# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21275970Scy
22275970Scy# As a special exception to the GNU General Public License, if you
23275970Scy# distribute this file as part of a program that contains a
24275970Scy# configuration script generated by Autoconf, you may include it under
25275970Scy# the same distribution terms that you use for the rest of that program.
26275970Scy
27275970Scyif test $# -eq 0; then
28316722Sdelphij  echo 1>&2 "Try '$0 --help' for more information"
29275970Scy  exit 1
30275970Scyfi
31275970Scy
32316722Sdelphijcase $1 in
33275970Scy
34316722Sdelphij  --is-lightweight)
35316722Sdelphij    # Used by our autoconf macros to check whether the available missing
36316722Sdelphij    # script is modern enough.
37316722Sdelphij    exit 0
38316722Sdelphij    ;;
39275970Scy
40316722Sdelphij  --run)
41316722Sdelphij    # Back-compat with the calling convention used by older automake.
42316722Sdelphij    shift
43316722Sdelphij    ;;
44275970Scy
45275970Scy  -h|--h|--he|--hel|--help)
46275970Scy    echo "\
47275970Scy$0 [OPTION]... PROGRAM [ARGUMENT]...
48275970Scy
49316722SdelphijRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50316722Sdelphijto PROGRAM being missing or too old.
51275970Scy
52275970ScyOptions:
53275970Scy  -h, --help      display this help and exit
54275970Scy  -v, --version   output version information and exit
55275970Scy
56275970ScySupported PROGRAM values:
57316722Sdelphij  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58316722Sdelphij  bison     yacc      flex         lex       help2man
59275970Scy
60316722SdelphijVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61316722Sdelphij'g' are ignored when checking the name.
62275970Scy
63275970ScySend bug reports to <bug-automake@gnu.org>."
64275970Scy    exit $?
65275970Scy    ;;
66275970Scy
67275970Scy  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68275970Scy    echo "missing $scriptversion (GNU Automake)"
69275970Scy    exit $?
70275970Scy    ;;
71275970Scy
72275970Scy  -*)
73316722Sdelphij    echo 1>&2 "$0: unknown '$1' option"
74316722Sdelphij    echo 1>&2 "Try '$0 --help' for more information"
75275970Scy    exit 1
76275970Scy    ;;
77275970Scy
78275970Scyesac
79275970Scy
80316722Sdelphij# Run the given program, remember its exit status.
81316722Sdelphij"$@"; st=$?
82275970Scy
83316722Sdelphij# If it succeeded, we are done.
84316722Sdelphijtest $st -eq 0 && exit 0
85275970Scy
86316722Sdelphij# Also exit now if we it failed (or wasn't found), and '--version' was
87316722Sdelphij# passed; such an option is passed most likely to detect whether the
88316722Sdelphij# program is present and works.
89316722Sdelphijcase $2 in --version|--help) exit $st;; esac
90275970Scy
91316722Sdelphij# Exit code 63 means version mismatch.  This often happens when the user
92316722Sdelphij# tries to use an ancient version of a tool on a file that requires a
93316722Sdelphij# minimum version.
94316722Sdelphijif test $st -eq 63; then
95316722Sdelphij  msg="probably too old"
96316722Sdelphijelif test $st -eq 127; then
97316722Sdelphij  # Program was missing.
98316722Sdelphij  msg="missing on your system"
99316722Sdelphijelse
100316722Sdelphij  # Program was found and executed, but failed.  Give up.
101316722Sdelphij  exit $st
102316722Sdelphijfi
103275970Scy
104316722Sdelphijperl_URL=http://www.perl.org/
105316722Sdelphijflex_URL=http://flex.sourceforge.net/
106316722Sdelphijgnu_software_URL=http://www.gnu.org/software
107275970Scy
108316722Sdelphijprogram_details ()
109316722Sdelphij{
110316722Sdelphij  case $1 in
111316722Sdelphij    aclocal|automake)
112316722Sdelphij      echo "The '$1' program is part of the GNU Automake package:"
113316722Sdelphij      echo "<$gnu_software_URL/automake>"
114316722Sdelphij      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115316722Sdelphij      echo "<$gnu_software_URL/autoconf>"
116316722Sdelphij      echo "<$gnu_software_URL/m4/>"
117316722Sdelphij      echo "<$perl_URL>"
118316722Sdelphij      ;;
119316722Sdelphij    autoconf|autom4te|autoheader)
120316722Sdelphij      echo "The '$1' program is part of the GNU Autoconf package:"
121316722Sdelphij      echo "<$gnu_software_URL/autoconf/>"
122316722Sdelphij      echo "It also requires GNU m4 and Perl in order to run:"
123316722Sdelphij      echo "<$gnu_software_URL/m4/>"
124316722Sdelphij      echo "<$perl_URL>"
125316722Sdelphij      ;;
126316722Sdelphij  esac
127316722Sdelphij}
128275970Scy
129316722Sdelphijgive_advice ()
130316722Sdelphij{
131316722Sdelphij  # Normalize program name to check for.
132316722Sdelphij  normalized_program=`echo "$1" | sed '
133316722Sdelphij    s/^gnu-//; t
134316722Sdelphij    s/^gnu//; t
135316722Sdelphij    s/^g//; t'`
136275970Scy
137316722Sdelphij  printf '%s\n' "'$1' is $msg."
138275970Scy
139316722Sdelphij  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140316722Sdelphij  case $normalized_program in
141316722Sdelphij    autoconf*)
142316722Sdelphij      echo "You should only need it if you modified 'configure.ac',"
143316722Sdelphij      echo "or m4 files included by it."
144316722Sdelphij      program_details 'autoconf'
145316722Sdelphij      ;;
146316722Sdelphij    autoheader*)
147316722Sdelphij      echo "You should only need it if you modified 'acconfig.h' or"
148316722Sdelphij      echo "$configure_deps."
149316722Sdelphij      program_details 'autoheader'
150316722Sdelphij      ;;
151316722Sdelphij    automake*)
152316722Sdelphij      echo "You should only need it if you modified 'Makefile.am' or"
153316722Sdelphij      echo "$configure_deps."
154316722Sdelphij      program_details 'automake'
155316722Sdelphij      ;;
156316722Sdelphij    aclocal*)
157316722Sdelphij      echo "You should only need it if you modified 'acinclude.m4' or"
158316722Sdelphij      echo "$configure_deps."
159316722Sdelphij      program_details 'aclocal'
160316722Sdelphij      ;;
161316722Sdelphij   autom4te*)
162316722Sdelphij      echo "You might have modified some maintainer files that require"
163316722Sdelphij      echo "the 'autom4te' program to be rebuilt."
164316722Sdelphij      program_details 'autom4te'
165316722Sdelphij      ;;
166316722Sdelphij    bison*|yacc*)
167316722Sdelphij      echo "You should only need it if you modified a '.y' file."
168316722Sdelphij      echo "You may want to install the GNU Bison package:"
169316722Sdelphij      echo "<$gnu_software_URL/bison/>"
170316722Sdelphij      ;;
171316722Sdelphij    lex*|flex*)
172316722Sdelphij      echo "You should only need it if you modified a '.l' file."
173316722Sdelphij      echo "You may want to install the Fast Lexical Analyzer package:"
174316722Sdelphij      echo "<$flex_URL>"
175316722Sdelphij      ;;
176316722Sdelphij    help2man*)
177316722Sdelphij      echo "You should only need it if you modified a dependency" \
178316722Sdelphij           "of a man page."
179316722Sdelphij      echo "You may want to install the GNU Help2man package:"
180316722Sdelphij      echo "<$gnu_software_URL/help2man/>"
181275970Scy    ;;
182316722Sdelphij    makeinfo*)
183316722Sdelphij      echo "You should only need it if you modified a '.texi' file, or"
184316722Sdelphij      echo "any other file indirectly affecting the aspect of the manual."
185316722Sdelphij      echo "You might want to install the Texinfo package:"
186316722Sdelphij      echo "<$gnu_software_URL/texinfo/>"
187316722Sdelphij      echo "The spurious makeinfo call might also be the consequence of"
188316722Sdelphij      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189316722Sdelphij      echo "want to install GNU make:"
190316722Sdelphij      echo "<$gnu_software_URL/make/>"
191316722Sdelphij      ;;
192316722Sdelphij    *)
193316722Sdelphij      echo "You might have modified some files without having the proper"
194316722Sdelphij      echo "tools for further handling them.  Check the 'README' file, it"
195316722Sdelphij      echo "often tells you about the needed prerequisites for installing"
196316722Sdelphij      echo "this package.  You may also peek at any GNU archive site, in"
197316722Sdelphij      echo "case some other package contains this missing '$1' program."
198316722Sdelphij      ;;
199316722Sdelphij  esac
200316722Sdelphij}
201275970Scy
202316722Sdelphijgive_advice "$1" | sed -e '1s/^/WARNING: /' \
203316722Sdelphij                       -e '2,$s/^/         /' >&2
204275970Scy
205316722Sdelphij# Propagate the correct exit status (expected to be 127 for a program
206316722Sdelphij# not found, 63 for a program that failed due to version mismatch).
207316722Sdelphijexit $st
208275970Scy
209275970Scy# Local variables:
210275970Scy# eval: (add-hook 'write-file-hooks 'time-stamp)
211275970Scy# time-stamp-start: "scriptversion="
212275970Scy# time-stamp-format: "%:y-%02m-%02d.%02H"
213275970Scy# time-stamp-time-zone: "UTC"
214275970Scy# time-stamp-end: "; # UTC"
215275970Scy# End:
216