1fdb3d228Smrg#! /bin/sh
2585aa3f7Smrg# Common wrapper for a few potentially missing GNU programs.
39b41ff1aSmrg
474b35aa8Smrgscriptversion=2018-03-07.03; # UTC
59b41ff1aSmrg
674b35aa8Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7585aa3f7Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8fdb3d228Smrg
9fdb3d228Smrg# This program is free software; you can redistribute it and/or modify
10fdb3d228Smrg# it under the terms of the GNU General Public License as published by
11fdb3d228Smrg# the Free Software Foundation; either version 2, or (at your option)
12fdb3d228Smrg# any later version.
13fdb3d228Smrg
14fdb3d228Smrg# This program is distributed in the hope that it will be useful,
15fdb3d228Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16fdb3d228Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17fdb3d228Smrg# GNU General Public License for more details.
18fdb3d228Smrg
19fdb3d228Smrg# You should have received a copy of the GNU General Public License
2074b35aa8Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21fdb3d228Smrg
22fdb3d228Smrg# As a special exception to the GNU General Public License, if you
23fdb3d228Smrg# distribute this file as part of a program that contains a
24fdb3d228Smrg# configuration script generated by Autoconf, you may include it under
25fdb3d228Smrg# the same distribution terms that you use for the rest of that program.
26fdb3d228Smrg
27fdb3d228Smrgif test $# -eq 0; then
28585aa3f7Smrg  echo 1>&2 "Try '$0 --help' for more information"
29fdb3d228Smrg  exit 1
30fdb3d228Smrgfi
31fdb3d228Smrg
32585aa3f7Smrgcase $1 in
33fdb3d228Smrg
34585aa3f7Smrg  --is-lightweight)
35585aa3f7Smrg    # Used by our autoconf macros to check whether the available missing
36585aa3f7Smrg    # script is modern enough.
37585aa3f7Smrg    exit 0
38585aa3f7Smrg    ;;
399b41ff1aSmrg
40585aa3f7Smrg  --run)
41585aa3f7Smrg    # Back-compat with the calling convention used by older automake.
42585aa3f7Smrg    shift
43585aa3f7Smrg    ;;
44fdb3d228Smrg
45fdb3d228Smrg  -h|--h|--he|--hel|--help)
46fdb3d228Smrg    echo "\
47fdb3d228Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48fdb3d228Smrg
49585aa3f7SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50585aa3f7Smrgto PROGRAM being missing or too old.
51fdb3d228Smrg
52fdb3d228SmrgOptions:
53fdb3d228Smrg  -h, --help      display this help and exit
54fdb3d228Smrg  -v, --version   output version information and exit
55fdb3d228Smrg
56fdb3d228SmrgSupported PROGRAM values:
57585aa3f7Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58585aa3f7Smrg  bison     yacc      flex         lex       help2man
599b41ff1aSmrg
60585aa3f7SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61585aa3f7Smrg'g' are ignored when checking the name.
629b41ff1aSmrg
639b41ff1aSmrgSend bug reports to <bug-automake@gnu.org>."
649b41ff1aSmrg    exit $?
65fdb3d228Smrg    ;;
66fdb3d228Smrg
67fdb3d228Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
689b41ff1aSmrg    echo "missing $scriptversion (GNU Automake)"
699b41ff1aSmrg    exit $?
70fdb3d228Smrg    ;;
71fdb3d228Smrg
72fdb3d228Smrg  -*)
73585aa3f7Smrg    echo 1>&2 "$0: unknown '$1' option"
74585aa3f7Smrg    echo 1>&2 "Try '$0 --help' for more information"
75fdb3d228Smrg    exit 1
76fdb3d228Smrg    ;;
77fdb3d228Smrg
789b41ff1aSmrgesac
799b41ff1aSmrg
80585aa3f7Smrg# Run the given program, remember its exit status.
81585aa3f7Smrg"$@"; st=$?
82585aa3f7Smrg
83585aa3f7Smrg# If it succeeded, we are done.
84585aa3f7Smrgtest $st -eq 0 && exit 0
85585aa3f7Smrg
86585aa3f7Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
87585aa3f7Smrg# passed; such an option is passed most likely to detect whether the
88585aa3f7Smrg# program is present and works.
89585aa3f7Smrgcase $2 in --version|--help) exit $st;; esac
90585aa3f7Smrg
91585aa3f7Smrg# Exit code 63 means version mismatch.  This often happens when the user
92585aa3f7Smrg# tries to use an ancient version of a tool on a file that requires a
93585aa3f7Smrg# minimum version.
94585aa3f7Smrgif test $st -eq 63; then
95585aa3f7Smrg  msg="probably too old"
96585aa3f7Smrgelif test $st -eq 127; then
97585aa3f7Smrg  # Program was missing.
98585aa3f7Smrg  msg="missing on your system"
99585aa3f7Smrgelse
100585aa3f7Smrg  # Program was found and executed, but failed.  Give up.
101585aa3f7Smrg  exit $st
102585aa3f7Smrgfi
103fdb3d228Smrg
10474b35aa8Smrgperl_URL=https://www.perl.org/
10574b35aa8Smrgflex_URL=https://github.com/westes/flex
10674b35aa8Smrggnu_software_URL=https://www.gnu.org/software
107585aa3f7Smrg
108585aa3f7Smrgprogram_details ()
109585aa3f7Smrg{
110585aa3f7Smrg  case $1 in
111585aa3f7Smrg    aclocal|automake)
112585aa3f7Smrg      echo "The '$1' program is part of the GNU Automake package:"
113585aa3f7Smrg      echo "<$gnu_software_URL/automake>"
114585aa3f7Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115585aa3f7Smrg      echo "<$gnu_software_URL/autoconf>"
116585aa3f7Smrg      echo "<$gnu_software_URL/m4/>"
117585aa3f7Smrg      echo "<$perl_URL>"
118585aa3f7Smrg      ;;
119585aa3f7Smrg    autoconf|autom4te|autoheader)
120585aa3f7Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
121585aa3f7Smrg      echo "<$gnu_software_URL/autoconf/>"
122585aa3f7Smrg      echo "It also requires GNU m4 and Perl in order to run:"
123585aa3f7Smrg      echo "<$gnu_software_URL/m4/>"
124585aa3f7Smrg      echo "<$perl_URL>"
125585aa3f7Smrg      ;;
126585aa3f7Smrg  esac
127585aa3f7Smrg}
128585aa3f7Smrg
129585aa3f7Smrggive_advice ()
130585aa3f7Smrg{
131585aa3f7Smrg  # Normalize program name to check for.
132585aa3f7Smrg  normalized_program=`echo "$1" | sed '
133585aa3f7Smrg    s/^gnu-//; t
134585aa3f7Smrg    s/^gnu//; t
135585aa3f7Smrg    s/^g//; t'`
136585aa3f7Smrg
137585aa3f7Smrg  printf '%s\n' "'$1' is $msg."
138585aa3f7Smrg
139585aa3f7Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140585aa3f7Smrg  case $normalized_program in
141585aa3f7Smrg    autoconf*)
142585aa3f7Smrg      echo "You should only need it if you modified 'configure.ac',"
143585aa3f7Smrg      echo "or m4 files included by it."
144585aa3f7Smrg      program_details 'autoconf'
145585aa3f7Smrg      ;;
146585aa3f7Smrg    autoheader*)
147585aa3f7Smrg      echo "You should only need it if you modified 'acconfig.h' or"
148585aa3f7Smrg      echo "$configure_deps."
149585aa3f7Smrg      program_details 'autoheader'
150585aa3f7Smrg      ;;
151585aa3f7Smrg    automake*)
152585aa3f7Smrg      echo "You should only need it if you modified 'Makefile.am' or"
153585aa3f7Smrg      echo "$configure_deps."
154585aa3f7Smrg      program_details 'automake'
155585aa3f7Smrg      ;;
156585aa3f7Smrg    aclocal*)
157585aa3f7Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
158585aa3f7Smrg      echo "$configure_deps."
159585aa3f7Smrg      program_details 'aclocal'
160585aa3f7Smrg      ;;
161585aa3f7Smrg   autom4te*)
162585aa3f7Smrg      echo "You might have modified some maintainer files that require"
163585aa3f7Smrg      echo "the 'autom4te' program to be rebuilt."
164585aa3f7Smrg      program_details 'autom4te'
165585aa3f7Smrg      ;;
166585aa3f7Smrg    bison*|yacc*)
167585aa3f7Smrg      echo "You should only need it if you modified a '.y' file."
168585aa3f7Smrg      echo "You may want to install the GNU Bison package:"
169585aa3f7Smrg      echo "<$gnu_software_URL/bison/>"
170585aa3f7Smrg      ;;
171585aa3f7Smrg    lex*|flex*)
172585aa3f7Smrg      echo "You should only need it if you modified a '.l' file."
173585aa3f7Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
174585aa3f7Smrg      echo "<$flex_URL>"
175585aa3f7Smrg      ;;
176585aa3f7Smrg    help2man*)
177585aa3f7Smrg      echo "You should only need it if you modified a dependency" \
178585aa3f7Smrg           "of a man page."
179585aa3f7Smrg      echo "You may want to install the GNU Help2man package:"
180585aa3f7Smrg      echo "<$gnu_software_URL/help2man/>"
181585aa3f7Smrg    ;;
182585aa3f7Smrg    makeinfo*)
183585aa3f7Smrg      echo "You should only need it if you modified a '.texi' file, or"
184585aa3f7Smrg      echo "any other file indirectly affecting the aspect of the manual."
185585aa3f7Smrg      echo "You might want to install the Texinfo package:"
186585aa3f7Smrg      echo "<$gnu_software_URL/texinfo/>"
187585aa3f7Smrg      echo "The spurious makeinfo call might also be the consequence of"
188585aa3f7Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189585aa3f7Smrg      echo "want to install GNU make:"
190585aa3f7Smrg      echo "<$gnu_software_URL/make/>"
191585aa3f7Smrg      ;;
192585aa3f7Smrg    *)
193585aa3f7Smrg      echo "You might have modified some files without having the proper"
194585aa3f7Smrg      echo "tools for further handling them.  Check the 'README' file, it"
195585aa3f7Smrg      echo "often tells you about the needed prerequisites for installing"
196585aa3f7Smrg      echo "this package.  You may also peek at any GNU archive site, in"
197585aa3f7Smrg      echo "case some other package contains this missing '$1' program."
198585aa3f7Smrg      ;;
199585aa3f7Smrg  esac
200585aa3f7Smrg}
201585aa3f7Smrg
202585aa3f7Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203585aa3f7Smrg                       -e '2,$s/^/         /' >&2
204585aa3f7Smrg
205585aa3f7Smrg# Propagate the correct exit status (expected to be 127 for a program
206585aa3f7Smrg# not found, 63 for a program that failed due to version mismatch).
207585aa3f7Smrgexit $st
2089b41ff1aSmrg
2099b41ff1aSmrg# Local variables:
21074b35aa8Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2119b41ff1aSmrg# time-stamp-start: "scriptversion="
2129b41ff1aSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21374b35aa8Smrg# time-stamp-time-zone: "UTC0"
2149b41ff1aSmrg# time-stamp-end: "; # UTC"
2159b41ff1aSmrg# End:
216