1145b7b3cSmrg#! /bin/sh
21d778f8eSmrg# Common wrapper for a few potentially missing GNU and other programs.
3145b7b3cSmrg
41d778f8eSmrgscriptversion=2024-06-07.14; # UTC
5145b7b3cSmrg
61d778f8eSmrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
71d778f8eSmrg
81d778f8eSmrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
9b7d26471Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
10145b7b3cSmrg
11145b7b3cSmrg# This program is free software; you can redistribute it and/or modify
12145b7b3cSmrg# it under the terms of the GNU General Public License as published by
13145b7b3cSmrg# the Free Software Foundation; either version 2, or (at your option)
14145b7b3cSmrg# any later version.
15145b7b3cSmrg
16145b7b3cSmrg# This program is distributed in the hope that it will be useful,
17145b7b3cSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
18145b7b3cSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19145b7b3cSmrg# GNU General Public License for more details.
20145b7b3cSmrg
21145b7b3cSmrg# You should have received a copy of the GNU General Public License
22da2e2ef6Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
23145b7b3cSmrg
24145b7b3cSmrg# As a special exception to the GNU General Public License, if you
25145b7b3cSmrg# distribute this file as part of a program that contains a
26145b7b3cSmrg# configuration script generated by Autoconf, you may include it under
27145b7b3cSmrg# the same distribution terms that you use for the rest of that program.
28145b7b3cSmrg
29145b7b3cSmrgif test $# -eq 0; then
30b7d26471Smrg  echo 1>&2 "Try '$0 --help' for more information"
31145b7b3cSmrg  exit 1
32145b7b3cSmrgfi
33145b7b3cSmrg
34b7d26471Smrgcase $1 in
35145b7b3cSmrg
36b7d26471Smrg  --is-lightweight)
37b7d26471Smrg    # Used by our autoconf macros to check whether the available missing
38b7d26471Smrg    # script is modern enough.
39b7d26471Smrg    exit 0
40b7d26471Smrg    ;;
41145b7b3cSmrg
42b7d26471Smrg  --run)
43b7d26471Smrg    # Back-compat with the calling convention used by older automake.
44b7d26471Smrg    shift
45b7d26471Smrg    ;;
46145b7b3cSmrg
47145b7b3cSmrg  -h|--h|--he|--hel|--help)
48145b7b3cSmrg    echo "\
49145b7b3cSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
50145b7b3cSmrg
51b7d26471SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
52b7d26471Smrgto PROGRAM being missing or too old.
53145b7b3cSmrg
54145b7b3cSmrgOptions:
55145b7b3cSmrg  -h, --help      display this help and exit
56145b7b3cSmrg  -v, --version   output version information and exit
57145b7b3cSmrg
58145b7b3cSmrgSupported PROGRAM values:
591d778f8eSmrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
601d778f8eSmrgbison   flex     help2man lex        makeinfo perl     yacc
61145b7b3cSmrg
62b7d26471SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
63b7d26471Smrg'g' are ignored when checking the name.
64578741aaSmrg
651d778f8eSmrgReport bugs to <bug-automake@gnu.org>.
661d778f8eSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
671d778f8eSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
68145b7b3cSmrg    exit $?
69145b7b3cSmrg    ;;
70145b7b3cSmrg
71145b7b3cSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
721d778f8eSmrg    echo "missing (GNU Automake) $scriptversion"
73145b7b3cSmrg    exit $?
74145b7b3cSmrg    ;;
75145b7b3cSmrg
76145b7b3cSmrg  -*)
77b7d26471Smrg    echo 1>&2 "$0: unknown '$1' option"
78b7d26471Smrg    echo 1>&2 "Try '$0 --help' for more information"
79145b7b3cSmrg    exit 1
80145b7b3cSmrg    ;;
81145b7b3cSmrg
82145b7b3cSmrgesac
83145b7b3cSmrg
84b7d26471Smrg# Run the given program, remember its exit status.
85b7d26471Smrg"$@"; st=$?
86b7d26471Smrg
87b7d26471Smrg# If it succeeded, we are done.
88b7d26471Smrgtest $st -eq 0 && exit 0
89b7d26471Smrg
90b7d26471Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
91b7d26471Smrg# passed; such an option is passed most likely to detect whether the
92b7d26471Smrg# program is present and works.
93b7d26471Smrgcase $2 in --version|--help) exit $st;; esac
94b7d26471Smrg
95b7d26471Smrg# Exit code 63 means version mismatch.  This often happens when the user
96b7d26471Smrg# tries to use an ancient version of a tool on a file that requires a
97b7d26471Smrg# minimum version.
98b7d26471Smrgif test $st -eq 63; then
99b7d26471Smrg  msg="probably too old"
100b7d26471Smrgelif test $st -eq 127; then
101b7d26471Smrg  # Program was missing.
102b7d26471Smrg  msg="missing on your system"
103b7d26471Smrgelse
104b7d26471Smrg  # Program was found and executed, but failed.  Give up.
105b7d26471Smrg  exit $st
106b7d26471Smrgfi
107145b7b3cSmrg
108da2e2ef6Smrgperl_URL=https://www.perl.org/
109da2e2ef6Smrgflex_URL=https://github.com/westes/flex
110da2e2ef6Smrggnu_software_URL=https://www.gnu.org/software
111b7d26471Smrg
112b7d26471Smrgprogram_details ()
113b7d26471Smrg{
114b7d26471Smrg  case $1 in
1151d778f8eSmrg    aclocal|automake|autoreconf)
116b7d26471Smrg      echo "The '$1' program is part of the GNU Automake package:"
117b7d26471Smrg      echo "<$gnu_software_URL/automake>"
118b7d26471Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
119b7d26471Smrg      echo "<$gnu_software_URL/autoconf>"
120b7d26471Smrg      echo "<$gnu_software_URL/m4/>"
121b7d26471Smrg      echo "<$perl_URL>"
122b7d26471Smrg      ;;
123b7d26471Smrg    autoconf|autom4te|autoheader)
124b7d26471Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
125b7d26471Smrg      echo "<$gnu_software_URL/autoconf/>"
126b7d26471Smrg      echo "It also requires GNU m4 and Perl in order to run:"
127b7d26471Smrg      echo "<$gnu_software_URL/m4/>"
128b7d26471Smrg      echo "<$perl_URL>"
129b7d26471Smrg      ;;
1301d778f8eSmrg    *)
1311d778f8eSmrg      :
1321d778f8eSmrg      ;;
133b7d26471Smrg  esac
134b7d26471Smrg}
135b7d26471Smrg
136b7d26471Smrggive_advice ()
137b7d26471Smrg{
138b7d26471Smrg  # Normalize program name to check for.
139b7d26471Smrg  normalized_program=`echo "$1" | sed '
140b7d26471Smrg    s/^gnu-//; t
141b7d26471Smrg    s/^gnu//; t
142b7d26471Smrg    s/^g//; t'`
143b7d26471Smrg
144b7d26471Smrg  printf '%s\n' "'$1' is $msg."
145b7d26471Smrg
146b7d26471Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1471d778f8eSmrg  autoheader_deps="'acconfig.h'"
1481d778f8eSmrg  automake_deps="'Makefile.am'"
1491d778f8eSmrg  aclocal_deps="'acinclude.m4'"
150b7d26471Smrg  case $normalized_program in
1511d778f8eSmrg    aclocal*)
1521d778f8eSmrg      echo "You should only need it if you modified $aclocal_deps or"
1531d778f8eSmrg      echo "$configure_deps."
1541d778f8eSmrg      ;;
155b7d26471Smrg    autoconf*)
1561d778f8eSmrg      echo "You should only need it if you modified $configure_deps."
1571d778f8eSmrg      ;;
1581d778f8eSmrg    autogen*)
1591d778f8eSmrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
1601d778f8eSmrg      echo "You may want to install the GNU AutoGen package:"
1611d778f8eSmrg      echo "<$gnu_software_URL/autogen/>"
162b7d26471Smrg      ;;
163b7d26471Smrg    autoheader*)
1641d778f8eSmrg      echo "You should only need it if you modified $autoheader_deps or"
165b7d26471Smrg      echo "$configure_deps."
166b7d26471Smrg      ;;
167b7d26471Smrg    automake*)
1681d778f8eSmrg      echo "You should only need it if you modified $automake_deps or"
169b7d26471Smrg      echo "$configure_deps."
170b7d26471Smrg      ;;
1711d778f8eSmrg    autom4te*)
172b7d26471Smrg      echo "You might have modified some maintainer files that require"
173b7d26471Smrg      echo "the 'autom4te' program to be rebuilt."
1741d778f8eSmrg      ;;
1751d778f8eSmrg    autoreconf*)
1761d778f8eSmrg      echo "You should only need it if you modified $aclocal_deps or"
1771d778f8eSmrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
1781d778f8eSmrg      echo "$configure_deps."
179b7d26471Smrg      ;;
180b7d26471Smrg    bison*|yacc*)
181b7d26471Smrg      echo "You should only need it if you modified a '.y' file."
182b7d26471Smrg      echo "You may want to install the GNU Bison package:"
183b7d26471Smrg      echo "<$gnu_software_URL/bison/>"
184b7d26471Smrg      ;;
185b7d26471Smrg    help2man*)
186b7d26471Smrg      echo "You should only need it if you modified a dependency" \
187b7d26471Smrg           "of a man page."
188b7d26471Smrg      echo "You may want to install the GNU Help2man package:"
189b7d26471Smrg      echo "<$gnu_software_URL/help2man/>"
190b7d26471Smrg    ;;
1911d778f8eSmrg    lex*|flex*)
1921d778f8eSmrg      echo "You should only need it if you modified a '.l' file."
1931d778f8eSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1941d778f8eSmrg      echo "<$flex_URL>"
1951d778f8eSmrg      ;;
196b7d26471Smrg    makeinfo*)
197b7d26471Smrg      echo "You should only need it if you modified a '.texi' file, or"
198b7d26471Smrg      echo "any other file indirectly affecting the aspect of the manual."
199b7d26471Smrg      echo "You might want to install the Texinfo package:"
200b7d26471Smrg      echo "<$gnu_software_URL/texinfo/>"
201b7d26471Smrg      echo "The spurious makeinfo call might also be the consequence of"
202b7d26471Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
203b7d26471Smrg      echo "want to install GNU make:"
204b7d26471Smrg      echo "<$gnu_software_URL/make/>"
205b7d26471Smrg      ;;
2061d778f8eSmrg    perl*)
2071d778f8eSmrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
2081d778f8eSmrg      echo "  assorted other tools, or if you modified a Perl source file."
2091d778f8eSmrg      echo "You may want to install the Perl 5 language interpreter:"
2101d778f8eSmrg      echo "<$perl_URL>"
2111d778f8eSmrg      ;;
212b7d26471Smrg    *)
213b7d26471Smrg      echo "You might have modified some files without having the proper"
214b7d26471Smrg      echo "tools for further handling them.  Check the 'README' file, it"
215b7d26471Smrg      echo "often tells you about the needed prerequisites for installing"
216b7d26471Smrg      echo "this package.  You may also peek at any GNU archive site, in"
217b7d26471Smrg      echo "case some other package contains this missing '$1' program."
218b7d26471Smrg      ;;
219b7d26471Smrg  esac
2201d778f8eSmrg  program_details "$normalized_program"
221b7d26471Smrg}
222b7d26471Smrg
223b7d26471Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
224b7d26471Smrg                       -e '2,$s/^/         /' >&2
225b7d26471Smrg
226b7d26471Smrg# Propagate the correct exit status (expected to be 127 for a program
227b7d26471Smrg# not found, 63 for a program that failed due to version mismatch).
228b7d26471Smrgexit $st
229145b7b3cSmrg
230145b7b3cSmrg# Local variables:
231da2e2ef6Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
232145b7b3cSmrg# time-stamp-start: "scriptversion="
233145b7b3cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234da2e2ef6Smrg# time-stamp-time-zone: "UTC0"
235578741aaSmrg# time-stamp-end: "; # UTC"
236145b7b3cSmrg# End:
237