1010cdda0Smrg#! /bin/sh
2945aa7e3Smrg# Common wrapper for a few potentially missing GNU programs.
3b3eb03f3Smrg
4945aa7e3Smrgscriptversion=2018-03-07.03; # UTC
5b3eb03f3Smrg
6945aa7e3Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7945aa7e3Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8010cdda0Smrg
9010cdda0Smrg# This program is free software; you can redistribute it and/or modify
10010cdda0Smrg# it under the terms of the GNU General Public License as published by
11010cdda0Smrg# the Free Software Foundation; either version 2, or (at your option)
12010cdda0Smrg# any later version.
13010cdda0Smrg
14010cdda0Smrg# This program is distributed in the hope that it will be useful,
15010cdda0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16010cdda0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17010cdda0Smrg# GNU General Public License for more details.
18010cdda0Smrg
19010cdda0Smrg# You should have received a copy of the GNU General Public License
20945aa7e3Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21010cdda0Smrg
22010cdda0Smrg# As a special exception to the GNU General Public License, if you
23010cdda0Smrg# distribute this file as part of a program that contains a
24010cdda0Smrg# configuration script generated by Autoconf, you may include it under
25010cdda0Smrg# the same distribution terms that you use for the rest of that program.
26010cdda0Smrg
27010cdda0Smrgif test $# -eq 0; then
28945aa7e3Smrg  echo 1>&2 "Try '$0 --help' for more information"
29010cdda0Smrg  exit 1
30010cdda0Smrgfi
31010cdda0Smrg
32945aa7e3Smrgcase $1 in
33010cdda0Smrg
34945aa7e3Smrg  --is-lightweight)
35945aa7e3Smrg    # Used by our autoconf macros to check whether the available missing
36945aa7e3Smrg    # script is modern enough.
37945aa7e3Smrg    exit 0
38945aa7e3Smrg    ;;
39b3eb03f3Smrg
40945aa7e3Smrg  --run)
41945aa7e3Smrg    # Back-compat with the calling convention used by older automake.
42945aa7e3Smrg    shift
43945aa7e3Smrg    ;;
44010cdda0Smrg
45010cdda0Smrg  -h|--h|--he|--hel|--help)
46010cdda0Smrg    echo "\
47010cdda0Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48010cdda0Smrg
49945aa7e3SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50945aa7e3Smrgto PROGRAM being missing or too old.
51010cdda0Smrg
52010cdda0SmrgOptions:
53010cdda0Smrg  -h, --help      display this help and exit
54010cdda0Smrg  -v, --version   output version information and exit
55010cdda0Smrg
56010cdda0SmrgSupported PROGRAM values:
57945aa7e3Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58945aa7e3Smrg  bison     yacc      flex         lex       help2man
59b3eb03f3Smrg
60945aa7e3SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61945aa7e3Smrg'g' are ignored when checking the name.
62b3eb03f3Smrg
63b3eb03f3SmrgSend bug reports to <bug-automake@gnu.org>."
64b3eb03f3Smrg    exit $?
65010cdda0Smrg    ;;
66010cdda0Smrg
67010cdda0Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68b3eb03f3Smrg    echo "missing $scriptversion (GNU Automake)"
69b3eb03f3Smrg    exit $?
70010cdda0Smrg    ;;
71010cdda0Smrg
72010cdda0Smrg  -*)
73945aa7e3Smrg    echo 1>&2 "$0: unknown '$1' option"
74945aa7e3Smrg    echo 1>&2 "Try '$0 --help' for more information"
75010cdda0Smrg    exit 1
76010cdda0Smrg    ;;
77010cdda0Smrg
78b3eb03f3Smrgesac
79b3eb03f3Smrg
80945aa7e3Smrg# Run the given program, remember its exit status.
81945aa7e3Smrg"$@"; st=$?
82945aa7e3Smrg
83945aa7e3Smrg# If it succeeded, we are done.
84945aa7e3Smrgtest $st -eq 0 && exit 0
85945aa7e3Smrg
86945aa7e3Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
87945aa7e3Smrg# passed; such an option is passed most likely to detect whether the
88945aa7e3Smrg# program is present and works.
89945aa7e3Smrgcase $2 in --version|--help) exit $st;; esac
90945aa7e3Smrg
91945aa7e3Smrg# Exit code 63 means version mismatch.  This often happens when the user
92945aa7e3Smrg# tries to use an ancient version of a tool on a file that requires a
93945aa7e3Smrg# minimum version.
94945aa7e3Smrgif test $st -eq 63; then
95945aa7e3Smrg  msg="probably too old"
96945aa7e3Smrgelif test $st -eq 127; then
97945aa7e3Smrg  # Program was missing.
98945aa7e3Smrg  msg="missing on your system"
99945aa7e3Smrgelse
100945aa7e3Smrg  # Program was found and executed, but failed.  Give up.
101945aa7e3Smrg  exit $st
102945aa7e3Smrgfi
103010cdda0Smrg
104945aa7e3Smrgperl_URL=https://www.perl.org/
105945aa7e3Smrgflex_URL=https://github.com/westes/flex
106945aa7e3Smrggnu_software_URL=https://www.gnu.org/software
107945aa7e3Smrg
108945aa7e3Smrgprogram_details ()
109945aa7e3Smrg{
110945aa7e3Smrg  case $1 in
111945aa7e3Smrg    aclocal|automake)
112945aa7e3Smrg      echo "The '$1' program is part of the GNU Automake package:"
113945aa7e3Smrg      echo "<$gnu_software_URL/automake>"
114945aa7e3Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115945aa7e3Smrg      echo "<$gnu_software_URL/autoconf>"
116945aa7e3Smrg      echo "<$gnu_software_URL/m4/>"
117945aa7e3Smrg      echo "<$perl_URL>"
118945aa7e3Smrg      ;;
119945aa7e3Smrg    autoconf|autom4te|autoheader)
120945aa7e3Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
121945aa7e3Smrg      echo "<$gnu_software_URL/autoconf/>"
122945aa7e3Smrg      echo "It also requires GNU m4 and Perl in order to run:"
123945aa7e3Smrg      echo "<$gnu_software_URL/m4/>"
124945aa7e3Smrg      echo "<$perl_URL>"
125945aa7e3Smrg      ;;
126945aa7e3Smrg  esac
127945aa7e3Smrg}
128945aa7e3Smrg
129945aa7e3Smrggive_advice ()
130945aa7e3Smrg{
131945aa7e3Smrg  # Normalize program name to check for.
132945aa7e3Smrg  normalized_program=`echo "$1" | sed '
133945aa7e3Smrg    s/^gnu-//; t
134945aa7e3Smrg    s/^gnu//; t
135945aa7e3Smrg    s/^g//; t'`
136945aa7e3Smrg
137945aa7e3Smrg  printf '%s\n' "'$1' is $msg."
138945aa7e3Smrg
139945aa7e3Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140945aa7e3Smrg  case $normalized_program in
141945aa7e3Smrg    autoconf*)
142945aa7e3Smrg      echo "You should only need it if you modified 'configure.ac',"
143945aa7e3Smrg      echo "or m4 files included by it."
144945aa7e3Smrg      program_details 'autoconf'
145945aa7e3Smrg      ;;
146945aa7e3Smrg    autoheader*)
147945aa7e3Smrg      echo "You should only need it if you modified 'acconfig.h' or"
148945aa7e3Smrg      echo "$configure_deps."
149945aa7e3Smrg      program_details 'autoheader'
150945aa7e3Smrg      ;;
151945aa7e3Smrg    automake*)
152945aa7e3Smrg      echo "You should only need it if you modified 'Makefile.am' or"
153945aa7e3Smrg      echo "$configure_deps."
154945aa7e3Smrg      program_details 'automake'
155945aa7e3Smrg      ;;
156945aa7e3Smrg    aclocal*)
157945aa7e3Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
158945aa7e3Smrg      echo "$configure_deps."
159945aa7e3Smrg      program_details 'aclocal'
160945aa7e3Smrg      ;;
161945aa7e3Smrg   autom4te*)
162945aa7e3Smrg      echo "You might have modified some maintainer files that require"
163945aa7e3Smrg      echo "the 'autom4te' program to be rebuilt."
164945aa7e3Smrg      program_details 'autom4te'
165945aa7e3Smrg      ;;
166945aa7e3Smrg    bison*|yacc*)
167945aa7e3Smrg      echo "You should only need it if you modified a '.y' file."
168945aa7e3Smrg      echo "You may want to install the GNU Bison package:"
169945aa7e3Smrg      echo "<$gnu_software_URL/bison/>"
170945aa7e3Smrg      ;;
171945aa7e3Smrg    lex*|flex*)
172945aa7e3Smrg      echo "You should only need it if you modified a '.l' file."
173945aa7e3Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
174945aa7e3Smrg      echo "<$flex_URL>"
175945aa7e3Smrg      ;;
176945aa7e3Smrg    help2man*)
177945aa7e3Smrg      echo "You should only need it if you modified a dependency" \
178945aa7e3Smrg           "of a man page."
179945aa7e3Smrg      echo "You may want to install the GNU Help2man package:"
180945aa7e3Smrg      echo "<$gnu_software_URL/help2man/>"
181945aa7e3Smrg    ;;
182945aa7e3Smrg    makeinfo*)
183945aa7e3Smrg      echo "You should only need it if you modified a '.texi' file, or"
184945aa7e3Smrg      echo "any other file indirectly affecting the aspect of the manual."
185945aa7e3Smrg      echo "You might want to install the Texinfo package:"
186945aa7e3Smrg      echo "<$gnu_software_URL/texinfo/>"
187945aa7e3Smrg      echo "The spurious makeinfo call might also be the consequence of"
188945aa7e3Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189945aa7e3Smrg      echo "want to install GNU make:"
190945aa7e3Smrg      echo "<$gnu_software_URL/make/>"
191945aa7e3Smrg      ;;
192945aa7e3Smrg    *)
193945aa7e3Smrg      echo "You might have modified some files without having the proper"
194945aa7e3Smrg      echo "tools for further handling them.  Check the 'README' file, it"
195945aa7e3Smrg      echo "often tells you about the needed prerequisites for installing"
196945aa7e3Smrg      echo "this package.  You may also peek at any GNU archive site, in"
197945aa7e3Smrg      echo "case some other package contains this missing '$1' program."
198945aa7e3Smrg      ;;
199945aa7e3Smrg  esac
200945aa7e3Smrg}
201945aa7e3Smrg
202945aa7e3Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203945aa7e3Smrg                       -e '2,$s/^/         /' >&2
204945aa7e3Smrg
205945aa7e3Smrg# Propagate the correct exit status (expected to be 127 for a program
206945aa7e3Smrg# not found, 63 for a program that failed due to version mismatch).
207945aa7e3Smrgexit $st
208b3eb03f3Smrg
209b3eb03f3Smrg# Local variables:
210945aa7e3Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
211b3eb03f3Smrg# time-stamp-start: "scriptversion="
212b3eb03f3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213945aa7e3Smrg# time-stamp-time-zone: "UTC0"
214b3eb03f3Smrg# time-stamp-end: "; # UTC"
215b3eb03f3Smrg# End:
216