1264fa531Smrg#! /bin/sh
2dfac8f13Smrg# Common wrapper for a few potentially missing GNU and other programs.
3c37a63b8Smrg
4dfac8f13Smrgscriptversion=2024-06-07.14; # UTC
5c37a63b8Smrg
6dfac8f13Smrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
7dfac8f13Smrg
8dfac8f13Smrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
9533545b5Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
10264fa531Smrg
11264fa531Smrg# This program is free software; you can redistribute it and/or modify
12264fa531Smrg# it under the terms of the GNU General Public License as published by
13264fa531Smrg# the Free Software Foundation; either version 2, or (at your option)
14264fa531Smrg# any later version.
15264fa531Smrg
16264fa531Smrg# This program is distributed in the hope that it will be useful,
17264fa531Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
18264fa531Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19264fa531Smrg# GNU General Public License for more details.
20264fa531Smrg
21264fa531Smrg# You should have received a copy of the GNU General Public License
22c9e4df9bSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
23264fa531Smrg
24264fa531Smrg# As a special exception to the GNU General Public License, if you
25264fa531Smrg# distribute this file as part of a program that contains a
26264fa531Smrg# configuration script generated by Autoconf, you may include it under
27264fa531Smrg# the same distribution terms that you use for the rest of that program.
28264fa531Smrg
29264fa531Smrgif test $# -eq 0; then
30533545b5Smrg  echo 1>&2 "Try '$0 --help' for more information"
31264fa531Smrg  exit 1
32264fa531Smrgfi
33264fa531Smrg
34533545b5Smrgcase $1 in
35264fa531Smrg
36533545b5Smrg  --is-lightweight)
37533545b5Smrg    # Used by our autoconf macros to check whether the available missing
38533545b5Smrg    # script is modern enough.
39533545b5Smrg    exit 0
40533545b5Smrg    ;;
41c37a63b8Smrg
42533545b5Smrg  --run)
43533545b5Smrg    # Back-compat with the calling convention used by older automake.
44533545b5Smrg    shift
45533545b5Smrg    ;;
46264fa531Smrg
47264fa531Smrg  -h|--h|--he|--hel|--help)
48264fa531Smrg    echo "\
49264fa531Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
50264fa531Smrg
51533545b5SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
52533545b5Smrgto PROGRAM being missing or too old.
53264fa531Smrg
54264fa531SmrgOptions:
55264fa531Smrg  -h, --help      display this help and exit
56264fa531Smrg  -v, --version   output version information and exit
57264fa531Smrg
58264fa531SmrgSupported PROGRAM values:
59dfac8f13Smrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
60dfac8f13Smrgbison   flex     help2man lex        makeinfo perl     yacc
61c37a63b8Smrg
62533545b5SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
63533545b5Smrg'g' are ignored when checking the name.
64c37a63b8Smrg
65dfac8f13SmrgReport bugs to <bug-automake@gnu.org>.
66dfac8f13SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
67dfac8f13SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
68c37a63b8Smrg    exit $?
69264fa531Smrg    ;;
70264fa531Smrg
71264fa531Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
72dfac8f13Smrg    echo "missing (GNU Automake) $scriptversion"
73c37a63b8Smrg    exit $?
74264fa531Smrg    ;;
75264fa531Smrg
76264fa531Smrg  -*)
77533545b5Smrg    echo 1>&2 "$0: unknown '$1' option"
78533545b5Smrg    echo 1>&2 "Try '$0 --help' for more information"
79264fa531Smrg    exit 1
80264fa531Smrg    ;;
81264fa531Smrg
82c37a63b8Smrgesac
83c37a63b8Smrg
84533545b5Smrg# Run the given program, remember its exit status.
85533545b5Smrg"$@"; st=$?
86533545b5Smrg
87533545b5Smrg# If it succeeded, we are done.
88533545b5Smrgtest $st -eq 0 && exit 0
89533545b5Smrg
90533545b5Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
91533545b5Smrg# passed; such an option is passed most likely to detect whether the
92533545b5Smrg# program is present and works.
93533545b5Smrgcase $2 in --version|--help) exit $st;; esac
94533545b5Smrg
95533545b5Smrg# Exit code 63 means version mismatch.  This often happens when the user
96533545b5Smrg# tries to use an ancient version of a tool on a file that requires a
97533545b5Smrg# minimum version.
98533545b5Smrgif test $st -eq 63; then
99533545b5Smrg  msg="probably too old"
100533545b5Smrgelif test $st -eq 127; then
101533545b5Smrg  # Program was missing.
102533545b5Smrg  msg="missing on your system"
103533545b5Smrgelse
104533545b5Smrg  # Program was found and executed, but failed.  Give up.
105533545b5Smrg  exit $st
106533545b5Smrgfi
107264fa531Smrg
108c9e4df9bSmrgperl_URL=https://www.perl.org/
109c9e4df9bSmrgflex_URL=https://github.com/westes/flex
110c9e4df9bSmrggnu_software_URL=https://www.gnu.org/software
111533545b5Smrg
112533545b5Smrgprogram_details ()
113533545b5Smrg{
114533545b5Smrg  case $1 in
115dfac8f13Smrg    aclocal|automake|autoreconf)
116533545b5Smrg      echo "The '$1' program is part of the GNU Automake package:"
117533545b5Smrg      echo "<$gnu_software_URL/automake>"
118533545b5Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
119533545b5Smrg      echo "<$gnu_software_URL/autoconf>"
120533545b5Smrg      echo "<$gnu_software_URL/m4/>"
121533545b5Smrg      echo "<$perl_URL>"
122533545b5Smrg      ;;
123533545b5Smrg    autoconf|autom4te|autoheader)
124533545b5Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
125533545b5Smrg      echo "<$gnu_software_URL/autoconf/>"
126533545b5Smrg      echo "It also requires GNU m4 and Perl in order to run:"
127533545b5Smrg      echo "<$gnu_software_URL/m4/>"
128533545b5Smrg      echo "<$perl_URL>"
129533545b5Smrg      ;;
130dfac8f13Smrg    *)
131dfac8f13Smrg      :
132dfac8f13Smrg      ;;
133533545b5Smrg  esac
134533545b5Smrg}
135533545b5Smrg
136533545b5Smrggive_advice ()
137533545b5Smrg{
138533545b5Smrg  # Normalize program name to check for.
139533545b5Smrg  normalized_program=`echo "$1" | sed '
140533545b5Smrg    s/^gnu-//; t
141533545b5Smrg    s/^gnu//; t
142533545b5Smrg    s/^g//; t'`
143533545b5Smrg
144533545b5Smrg  printf '%s\n' "'$1' is $msg."
145533545b5Smrg
146533545b5Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
147dfac8f13Smrg  autoheader_deps="'acconfig.h'"
148dfac8f13Smrg  automake_deps="'Makefile.am'"
149dfac8f13Smrg  aclocal_deps="'acinclude.m4'"
150533545b5Smrg  case $normalized_program in
151dfac8f13Smrg    aclocal*)
152dfac8f13Smrg      echo "You should only need it if you modified $aclocal_deps or"
153dfac8f13Smrg      echo "$configure_deps."
154dfac8f13Smrg      ;;
155533545b5Smrg    autoconf*)
156dfac8f13Smrg      echo "You should only need it if you modified $configure_deps."
157dfac8f13Smrg      ;;
158dfac8f13Smrg    autogen*)
159dfac8f13Smrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
160dfac8f13Smrg      echo "You may want to install the GNU AutoGen package:"
161dfac8f13Smrg      echo "<$gnu_software_URL/autogen/>"
162533545b5Smrg      ;;
163533545b5Smrg    autoheader*)
164dfac8f13Smrg      echo "You should only need it if you modified $autoheader_deps or"
165533545b5Smrg      echo "$configure_deps."
166533545b5Smrg      ;;
167533545b5Smrg    automake*)
168dfac8f13Smrg      echo "You should only need it if you modified $automake_deps or"
169533545b5Smrg      echo "$configure_deps."
170533545b5Smrg      ;;
171dfac8f13Smrg    autom4te*)
172533545b5Smrg      echo "You might have modified some maintainer files that require"
173533545b5Smrg      echo "the 'autom4te' program to be rebuilt."
174dfac8f13Smrg      ;;
175dfac8f13Smrg    autoreconf*)
176dfac8f13Smrg      echo "You should only need it if you modified $aclocal_deps or"
177dfac8f13Smrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
178dfac8f13Smrg      echo "$configure_deps."
179533545b5Smrg      ;;
180533545b5Smrg    bison*|yacc*)
181533545b5Smrg      echo "You should only need it if you modified a '.y' file."
182533545b5Smrg      echo "You may want to install the GNU Bison package:"
183533545b5Smrg      echo "<$gnu_software_URL/bison/>"
184533545b5Smrg      ;;
185533545b5Smrg    help2man*)
186533545b5Smrg      echo "You should only need it if you modified a dependency" \
187533545b5Smrg           "of a man page."
188533545b5Smrg      echo "You may want to install the GNU Help2man package:"
189533545b5Smrg      echo "<$gnu_software_URL/help2man/>"
190533545b5Smrg    ;;
191dfac8f13Smrg    lex*|flex*)
192dfac8f13Smrg      echo "You should only need it if you modified a '.l' file."
193dfac8f13Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
194dfac8f13Smrg      echo "<$flex_URL>"
195dfac8f13Smrg      ;;
196533545b5Smrg    makeinfo*)
197533545b5Smrg      echo "You should only need it if you modified a '.texi' file, or"
198533545b5Smrg      echo "any other file indirectly affecting the aspect of the manual."
199533545b5Smrg      echo "You might want to install the Texinfo package:"
200533545b5Smrg      echo "<$gnu_software_URL/texinfo/>"
201533545b5Smrg      echo "The spurious makeinfo call might also be the consequence of"
202533545b5Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
203533545b5Smrg      echo "want to install GNU make:"
204533545b5Smrg      echo "<$gnu_software_URL/make/>"
205533545b5Smrg      ;;
206dfac8f13Smrg    perl*)
207dfac8f13Smrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
208dfac8f13Smrg      echo "  assorted other tools, or if you modified a Perl source file."
209dfac8f13Smrg      echo "You may want to install the Perl 5 language interpreter:"
210dfac8f13Smrg      echo "<$perl_URL>"
211dfac8f13Smrg      ;;
212533545b5Smrg    *)
213533545b5Smrg      echo "You might have modified some files without having the proper"
214533545b5Smrg      echo "tools for further handling them.  Check the 'README' file, it"
215533545b5Smrg      echo "often tells you about the needed prerequisites for installing"
216533545b5Smrg      echo "this package.  You may also peek at any GNU archive site, in"
217533545b5Smrg      echo "case some other package contains this missing '$1' program."
218533545b5Smrg      ;;
219533545b5Smrg  esac
220dfac8f13Smrg  program_details "$normalized_program"
221533545b5Smrg}
222533545b5Smrg
223533545b5Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
224533545b5Smrg                       -e '2,$s/^/         /' >&2
225533545b5Smrg
226533545b5Smrg# Propagate the correct exit status (expected to be 127 for a program
227533545b5Smrg# not found, 63 for a program that failed due to version mismatch).
228533545b5Smrgexit $st
229c37a63b8Smrg
230c37a63b8Smrg# Local variables:
231c9e4df9bSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
232c37a63b8Smrg# time-stamp-start: "scriptversion="
233c37a63b8Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234c9e4df9bSmrg# time-stamp-time-zone: "UTC0"
235c37a63b8Smrg# time-stamp-end: "; # UTC"
236c37a63b8Smrg# End:
237