1191cded7Smrg#! /bin/sh
28f9fac4aSmrg# Common wrapper for a few potentially missing GNU and other programs.
3191cded7Smrg
48f9fac4aSmrgscriptversion=2024-06-07.14; # UTC
5191cded7Smrg
68f9fac4aSmrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
78f9fac4aSmrg
88f9fac4aSmrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
9d9dcd5aeSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
10191cded7Smrg
11191cded7Smrg# This program is free software; you can redistribute it and/or modify
12191cded7Smrg# it under the terms of the GNU General Public License as published by
13191cded7Smrg# the Free Software Foundation; either version 2, or (at your option)
14191cded7Smrg# any later version.
15191cded7Smrg
16191cded7Smrg# This program is distributed in the hope that it will be useful,
17191cded7Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
18191cded7Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19191cded7Smrg# GNU General Public License for more details.
20191cded7Smrg
21191cded7Smrg# You should have received a copy of the GNU General Public License
22ee3e8c14Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
23191cded7Smrg
24191cded7Smrg# As a special exception to the GNU General Public License, if you
25191cded7Smrg# distribute this file as part of a program that contains a
26191cded7Smrg# configuration script generated by Autoconf, you may include it under
27191cded7Smrg# the same distribution terms that you use for the rest of that program.
28191cded7Smrg
29191cded7Smrgif test $# -eq 0; then
30d9dcd5aeSmrg  echo 1>&2 "Try '$0 --help' for more information"
31191cded7Smrg  exit 1
32191cded7Smrgfi
33191cded7Smrg
34d9dcd5aeSmrgcase $1 in
35191cded7Smrg
36d9dcd5aeSmrg  --is-lightweight)
37d9dcd5aeSmrg    # Used by our autoconf macros to check whether the available missing
38d9dcd5aeSmrg    # script is modern enough.
39d9dcd5aeSmrg    exit 0
40d9dcd5aeSmrg    ;;
41191cded7Smrg
42d9dcd5aeSmrg  --run)
43d9dcd5aeSmrg    # Back-compat with the calling convention used by older automake.
44d9dcd5aeSmrg    shift
45d9dcd5aeSmrg    ;;
46191cded7Smrg
47191cded7Smrg  -h|--h|--he|--hel|--help)
48191cded7Smrg    echo "\
49191cded7Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
50191cded7Smrg
51d9dcd5aeSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
52d9dcd5aeSmrgto PROGRAM being missing or too old.
53191cded7Smrg
54191cded7SmrgOptions:
55191cded7Smrg  -h, --help      display this help and exit
56191cded7Smrg  -v, --version   output version information and exit
57191cded7Smrg
58191cded7SmrgSupported PROGRAM values:
598f9fac4aSmrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
608f9fac4aSmrgbison   flex     help2man lex        makeinfo perl     yacc
61191cded7Smrg
62d9dcd5aeSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
63d9dcd5aeSmrg'g' are ignored when checking the name.
64ba064abeSmrg
658f9fac4aSmrgReport bugs to <bug-automake@gnu.org>.
668f9fac4aSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
678f9fac4aSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
68191cded7Smrg    exit $?
69191cded7Smrg    ;;
70191cded7Smrg
71191cded7Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
728f9fac4aSmrg    echo "missing (GNU Automake) $scriptversion"
73191cded7Smrg    exit $?
74191cded7Smrg    ;;
75191cded7Smrg
76191cded7Smrg  -*)
77d9dcd5aeSmrg    echo 1>&2 "$0: unknown '$1' option"
78d9dcd5aeSmrg    echo 1>&2 "Try '$0 --help' for more information"
79191cded7Smrg    exit 1
80191cded7Smrg    ;;
81191cded7Smrg
82191cded7Smrgesac
83191cded7Smrg
84d9dcd5aeSmrg# Run the given program, remember its exit status.
85d9dcd5aeSmrg"$@"; st=$?
86d9dcd5aeSmrg
87d9dcd5aeSmrg# If it succeeded, we are done.
88d9dcd5aeSmrgtest $st -eq 0 && exit 0
89d9dcd5aeSmrg
90d9dcd5aeSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
91d9dcd5aeSmrg# passed; such an option is passed most likely to detect whether the
92d9dcd5aeSmrg# program is present and works.
93d9dcd5aeSmrgcase $2 in --version|--help) exit $st;; esac
94d9dcd5aeSmrg
95d9dcd5aeSmrg# Exit code 63 means version mismatch.  This often happens when the user
96d9dcd5aeSmrg# tries to use an ancient version of a tool on a file that requires a
97d9dcd5aeSmrg# minimum version.
98d9dcd5aeSmrgif test $st -eq 63; then
99d9dcd5aeSmrg  msg="probably too old"
100d9dcd5aeSmrgelif test $st -eq 127; then
101d9dcd5aeSmrg  # Program was missing.
102d9dcd5aeSmrg  msg="missing on your system"
103d9dcd5aeSmrgelse
104d9dcd5aeSmrg  # Program was found and executed, but failed.  Give up.
105d9dcd5aeSmrg  exit $st
106d9dcd5aeSmrgfi
107191cded7Smrg
108ee3e8c14Smrgperl_URL=https://www.perl.org/
109ee3e8c14Smrgflex_URL=https://github.com/westes/flex
110ee3e8c14Smrggnu_software_URL=https://www.gnu.org/software
111d9dcd5aeSmrg
112d9dcd5aeSmrgprogram_details ()
113d9dcd5aeSmrg{
114d9dcd5aeSmrg  case $1 in
1158f9fac4aSmrg    aclocal|automake|autoreconf)
116d9dcd5aeSmrg      echo "The '$1' program is part of the GNU Automake package:"
117d9dcd5aeSmrg      echo "<$gnu_software_URL/automake>"
118d9dcd5aeSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
119d9dcd5aeSmrg      echo "<$gnu_software_URL/autoconf>"
120d9dcd5aeSmrg      echo "<$gnu_software_URL/m4/>"
121d9dcd5aeSmrg      echo "<$perl_URL>"
122d9dcd5aeSmrg      ;;
123d9dcd5aeSmrg    autoconf|autom4te|autoheader)
124d9dcd5aeSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
125d9dcd5aeSmrg      echo "<$gnu_software_URL/autoconf/>"
126d9dcd5aeSmrg      echo "It also requires GNU m4 and Perl in order to run:"
127d9dcd5aeSmrg      echo "<$gnu_software_URL/m4/>"
128d9dcd5aeSmrg      echo "<$perl_URL>"
129d9dcd5aeSmrg      ;;
1308f9fac4aSmrg    *)
1318f9fac4aSmrg      :
1328f9fac4aSmrg      ;;
133d9dcd5aeSmrg  esac
134d9dcd5aeSmrg}
135d9dcd5aeSmrg
136d9dcd5aeSmrggive_advice ()
137d9dcd5aeSmrg{
138d9dcd5aeSmrg  # Normalize program name to check for.
139d9dcd5aeSmrg  normalized_program=`echo "$1" | sed '
140d9dcd5aeSmrg    s/^gnu-//; t
141d9dcd5aeSmrg    s/^gnu//; t
142d9dcd5aeSmrg    s/^g//; t'`
143d9dcd5aeSmrg
144d9dcd5aeSmrg  printf '%s\n' "'$1' is $msg."
145d9dcd5aeSmrg
146d9dcd5aeSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1478f9fac4aSmrg  autoheader_deps="'acconfig.h'"
1488f9fac4aSmrg  automake_deps="'Makefile.am'"
1498f9fac4aSmrg  aclocal_deps="'acinclude.m4'"
150d9dcd5aeSmrg  case $normalized_program in
1518f9fac4aSmrg    aclocal*)
1528f9fac4aSmrg      echo "You should only need it if you modified $aclocal_deps or"
1538f9fac4aSmrg      echo "$configure_deps."
1548f9fac4aSmrg      ;;
155d9dcd5aeSmrg    autoconf*)
1568f9fac4aSmrg      echo "You should only need it if you modified $configure_deps."
1578f9fac4aSmrg      ;;
1588f9fac4aSmrg    autogen*)
1598f9fac4aSmrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
1608f9fac4aSmrg      echo "You may want to install the GNU AutoGen package:"
1618f9fac4aSmrg      echo "<$gnu_software_URL/autogen/>"
162d9dcd5aeSmrg      ;;
163d9dcd5aeSmrg    autoheader*)
1648f9fac4aSmrg      echo "You should only need it if you modified $autoheader_deps or"
165d9dcd5aeSmrg      echo "$configure_deps."
166d9dcd5aeSmrg      ;;
167d9dcd5aeSmrg    automake*)
1688f9fac4aSmrg      echo "You should only need it if you modified $automake_deps or"
169d9dcd5aeSmrg      echo "$configure_deps."
170d9dcd5aeSmrg      ;;
1718f9fac4aSmrg    autom4te*)
172d9dcd5aeSmrg      echo "You might have modified some maintainer files that require"
17358deefebSmrg      echo "the 'autom4te' program to be rebuilt."
1748f9fac4aSmrg      ;;
1758f9fac4aSmrg    autoreconf*)
1768f9fac4aSmrg      echo "You should only need it if you modified $aclocal_deps or"
1778f9fac4aSmrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
1788f9fac4aSmrg      echo "$configure_deps."
179d9dcd5aeSmrg      ;;
180d9dcd5aeSmrg    bison*|yacc*)
181d9dcd5aeSmrg      echo "You should only need it if you modified a '.y' file."
182d9dcd5aeSmrg      echo "You may want to install the GNU Bison package:"
183d9dcd5aeSmrg      echo "<$gnu_software_URL/bison/>"
184d9dcd5aeSmrg      ;;
185d9dcd5aeSmrg    help2man*)
186d9dcd5aeSmrg      echo "You should only need it if you modified a dependency" \
187d9dcd5aeSmrg           "of a man page."
188d9dcd5aeSmrg      echo "You may want to install the GNU Help2man package:"
189d9dcd5aeSmrg      echo "<$gnu_software_URL/help2man/>"
190d9dcd5aeSmrg    ;;
1918f9fac4aSmrg    lex*|flex*)
1928f9fac4aSmrg      echo "You should only need it if you modified a '.l' file."
1938f9fac4aSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1948f9fac4aSmrg      echo "<$flex_URL>"
1958f9fac4aSmrg      ;;
196d9dcd5aeSmrg    makeinfo*)
197d9dcd5aeSmrg      echo "You should only need it if you modified a '.texi' file, or"
198d9dcd5aeSmrg      echo "any other file indirectly affecting the aspect of the manual."
199d9dcd5aeSmrg      echo "You might want to install the Texinfo package:"
200d9dcd5aeSmrg      echo "<$gnu_software_URL/texinfo/>"
201d9dcd5aeSmrg      echo "The spurious makeinfo call might also be the consequence of"
202d9dcd5aeSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
203d9dcd5aeSmrg      echo "want to install GNU make:"
204d9dcd5aeSmrg      echo "<$gnu_software_URL/make/>"
205d9dcd5aeSmrg      ;;
2068f9fac4aSmrg    perl*)
2078f9fac4aSmrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
2088f9fac4aSmrg      echo "  assorted other tools, or if you modified a Perl source file."
2098f9fac4aSmrg      echo "You may want to install the Perl 5 language interpreter:"
2108f9fac4aSmrg      echo "<$perl_URL>"
2118f9fac4aSmrg      ;;
212d9dcd5aeSmrg    *)
213d9dcd5aeSmrg      echo "You might have modified some files without having the proper"
214d9dcd5aeSmrg      echo "tools for further handling them.  Check the 'README' file, it"
215d9dcd5aeSmrg      echo "often tells you about the needed prerequisites for installing"
216d9dcd5aeSmrg      echo "this package.  You may also peek at any GNU archive site, in"
217d9dcd5aeSmrg      echo "case some other package contains this missing '$1' program."
218d9dcd5aeSmrg      ;;
219d9dcd5aeSmrg  esac
2208f9fac4aSmrg  program_details "$normalized_program"
221d9dcd5aeSmrg}
222d9dcd5aeSmrg
223d9dcd5aeSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
224d9dcd5aeSmrg                       -e '2,$s/^/         /' >&2
225d9dcd5aeSmrg
226d9dcd5aeSmrg# Propagate the correct exit status (expected to be 127 for a program
227d9dcd5aeSmrg# not found, 63 for a program that failed due to version mismatch).
228d9dcd5aeSmrgexit $st
229191cded7Smrg
230191cded7Smrg# Local variables:
231ee3e8c14Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
232191cded7Smrg# time-stamp-start: "scriptversion="
233191cded7Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234ee3e8c14Smrg# time-stamp-time-zone: "UTC0"
235ba064abeSmrg# time-stamp-end: "; # UTC"
236191cded7Smrg# End:
237