1bbe1b32bSmrg#! /bin/sh
2e1db7cd1Smrg# Common wrapper for a few potentially missing GNU and other programs.
3bbe1b32bSmrg
4e1db7cd1Smrgscriptversion=2024-06-07.14; # UTC
5bbe1b32bSmrg
6e1db7cd1Smrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
7e1db7cd1Smrg
8e1db7cd1Smrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
98f34cbf9Ssnj# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
10bbe1b32bSmrg
11bbe1b32bSmrg# This program is free software; you can redistribute it and/or modify
12bbe1b32bSmrg# it under the terms of the GNU General Public License as published by
13bbe1b32bSmrg# the Free Software Foundation; either version 2, or (at your option)
14bbe1b32bSmrg# any later version.
15bbe1b32bSmrg
16bbe1b32bSmrg# This program is distributed in the hope that it will be useful,
17bbe1b32bSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
18bbe1b32bSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19bbe1b32bSmrg# GNU General Public License for more details.
20bbe1b32bSmrg
21bbe1b32bSmrg# You should have received a copy of the GNU General Public License
2276028eb6Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
23bbe1b32bSmrg
24bbe1b32bSmrg# As a special exception to the GNU General Public License, if you
25bbe1b32bSmrg# distribute this file as part of a program that contains a
26bbe1b32bSmrg# configuration script generated by Autoconf, you may include it under
27bbe1b32bSmrg# the same distribution terms that you use for the rest of that program.
28bbe1b32bSmrg
29bbe1b32bSmrgif test $# -eq 0; then
308f34cbf9Ssnj  echo 1>&2 "Try '$0 --help' for more information"
31bbe1b32bSmrg  exit 1
32bbe1b32bSmrgfi
33bbe1b32bSmrg
348f34cbf9Ssnjcase $1 in
35bbe1b32bSmrg
368f34cbf9Ssnj  --is-lightweight)
378f34cbf9Ssnj    # Used by our autoconf macros to check whether the available missing
388f34cbf9Ssnj    # script is modern enough.
398f34cbf9Ssnj    exit 0
408f34cbf9Ssnj    ;;
41bbe1b32bSmrg
428f34cbf9Ssnj  --run)
438f34cbf9Ssnj    # Back-compat with the calling convention used by older automake.
448f34cbf9Ssnj    shift
458f34cbf9Ssnj    ;;
46bbe1b32bSmrg
47bbe1b32bSmrg  -h|--h|--he|--hel|--help)
48bbe1b32bSmrg    echo "\
49bbe1b32bSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
50bbe1b32bSmrg
518f34cbf9SsnjRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
528f34cbf9Ssnjto PROGRAM being missing or too old.
53bbe1b32bSmrg
54bbe1b32bSmrgOptions:
55bbe1b32bSmrg  -h, --help      display this help and exit
56bbe1b32bSmrg  -v, --version   output version information and exit
57bbe1b32bSmrg
58bbe1b32bSmrgSupported PROGRAM values:
59e1db7cd1Smrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
60e1db7cd1Smrgbison   flex     help2man lex        makeinfo perl     yacc
61bbe1b32bSmrg
628f34cbf9SsnjVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
638f34cbf9Ssnj'g' are ignored when checking the name.
6430f8ce46Smrg
65e1db7cd1SmrgReport bugs to <bug-automake@gnu.org>.
66e1db7cd1SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
67e1db7cd1SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
68bbe1b32bSmrg    exit $?
69bbe1b32bSmrg    ;;
70bbe1b32bSmrg
71bbe1b32bSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
72e1db7cd1Smrg    echo "missing (GNU Automake) $scriptversion"
73bbe1b32bSmrg    exit $?
74bbe1b32bSmrg    ;;
75bbe1b32bSmrg
76bbe1b32bSmrg  -*)
778f34cbf9Ssnj    echo 1>&2 "$0: unknown '$1' option"
788f34cbf9Ssnj    echo 1>&2 "Try '$0 --help' for more information"
79bbe1b32bSmrg    exit 1
80bbe1b32bSmrg    ;;
81bbe1b32bSmrg
82bbe1b32bSmrgesac
83bbe1b32bSmrg
848f34cbf9Ssnj# Run the given program, remember its exit status.
858f34cbf9Ssnj"$@"; st=$?
868f34cbf9Ssnj
878f34cbf9Ssnj# If it succeeded, we are done.
888f34cbf9Ssnjtest $st -eq 0 && exit 0
898f34cbf9Ssnj
908f34cbf9Ssnj# Also exit now if we it failed (or wasn't found), and '--version' was
918f34cbf9Ssnj# passed; such an option is passed most likely to detect whether the
928f34cbf9Ssnj# program is present and works.
938f34cbf9Ssnjcase $2 in --version|--help) exit $st;; esac
948f34cbf9Ssnj
958f34cbf9Ssnj# Exit code 63 means version mismatch.  This often happens when the user
968f34cbf9Ssnj# tries to use an ancient version of a tool on a file that requires a
978f34cbf9Ssnj# minimum version.
988f34cbf9Ssnjif test $st -eq 63; then
998f34cbf9Ssnj  msg="probably too old"
1008f34cbf9Ssnjelif test $st -eq 127; then
1018f34cbf9Ssnj  # Program was missing.
1028f34cbf9Ssnj  msg="missing on your system"
1038f34cbf9Ssnjelse
1048f34cbf9Ssnj  # Program was found and executed, but failed.  Give up.
1058f34cbf9Ssnj  exit $st
1068f34cbf9Ssnjfi
107bbe1b32bSmrg
10876028eb6Smrgperl_URL=https://www.perl.org/
10976028eb6Smrgflex_URL=https://github.com/westes/flex
11076028eb6Smrggnu_software_URL=https://www.gnu.org/software
1118f34cbf9Ssnj
1128f34cbf9Ssnjprogram_details ()
1138f34cbf9Ssnj{
1148f34cbf9Ssnj  case $1 in
115e1db7cd1Smrg    aclocal|automake|autoreconf)
1168f34cbf9Ssnj      echo "The '$1' program is part of the GNU Automake package:"
1178f34cbf9Ssnj      echo "<$gnu_software_URL/automake>"
1188f34cbf9Ssnj      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1198f34cbf9Ssnj      echo "<$gnu_software_URL/autoconf>"
1208f34cbf9Ssnj      echo "<$gnu_software_URL/m4/>"
1218f34cbf9Ssnj      echo "<$perl_URL>"
1228f34cbf9Ssnj      ;;
1238f34cbf9Ssnj    autoconf|autom4te|autoheader)
1248f34cbf9Ssnj      echo "The '$1' program is part of the GNU Autoconf package:"
1258f34cbf9Ssnj      echo "<$gnu_software_URL/autoconf/>"
1268f34cbf9Ssnj      echo "It also requires GNU m4 and Perl in order to run:"
1278f34cbf9Ssnj      echo "<$gnu_software_URL/m4/>"
1288f34cbf9Ssnj      echo "<$perl_URL>"
1298f34cbf9Ssnj      ;;
130e1db7cd1Smrg    *)
131e1db7cd1Smrg      :
132e1db7cd1Smrg      ;;
1338f34cbf9Ssnj  esac
1348f34cbf9Ssnj}
1358f34cbf9Ssnj
1368f34cbf9Ssnjgive_advice ()
1378f34cbf9Ssnj{
1388f34cbf9Ssnj  # Normalize program name to check for.
1398f34cbf9Ssnj  normalized_program=`echo "$1" | sed '
1408f34cbf9Ssnj    s/^gnu-//; t
1418f34cbf9Ssnj    s/^gnu//; t
1428f34cbf9Ssnj    s/^g//; t'`
1438f34cbf9Ssnj
1448f34cbf9Ssnj  printf '%s\n' "'$1' is $msg."
1458f34cbf9Ssnj
1468f34cbf9Ssnj  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
147e1db7cd1Smrg  autoheader_deps="'acconfig.h'"
148e1db7cd1Smrg  automake_deps="'Makefile.am'"
149e1db7cd1Smrg  aclocal_deps="'acinclude.m4'"
1508f34cbf9Ssnj  case $normalized_program in
151e1db7cd1Smrg    aclocal*)
152e1db7cd1Smrg      echo "You should only need it if you modified $aclocal_deps or"
153e1db7cd1Smrg      echo "$configure_deps."
154e1db7cd1Smrg      ;;
1558f34cbf9Ssnj    autoconf*)
156e1db7cd1Smrg      echo "You should only need it if you modified $configure_deps."
157e1db7cd1Smrg      ;;
158e1db7cd1Smrg    autogen*)
159e1db7cd1Smrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
160e1db7cd1Smrg      echo "You may want to install the GNU AutoGen package:"
161e1db7cd1Smrg      echo "<$gnu_software_URL/autogen/>"
1628f34cbf9Ssnj      ;;
1638f34cbf9Ssnj    autoheader*)
164e1db7cd1Smrg      echo "You should only need it if you modified $autoheader_deps or"
1658f34cbf9Ssnj      echo "$configure_deps."
1668f34cbf9Ssnj      ;;
1678f34cbf9Ssnj    automake*)
168e1db7cd1Smrg      echo "You should only need it if you modified $automake_deps or"
1698f34cbf9Ssnj      echo "$configure_deps."
1708f34cbf9Ssnj      ;;
171e1db7cd1Smrg    autom4te*)
1728f34cbf9Ssnj      echo "You might have modified some maintainer files that require"
1738f34cbf9Ssnj      echo "the 'autom4te' program to be rebuilt."
174e1db7cd1Smrg      ;;
175e1db7cd1Smrg    autoreconf*)
176e1db7cd1Smrg      echo "You should only need it if you modified $aclocal_deps or"
177e1db7cd1Smrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
178e1db7cd1Smrg      echo "$configure_deps."
1798f34cbf9Ssnj      ;;
1808f34cbf9Ssnj    bison*|yacc*)
1818f34cbf9Ssnj      echo "You should only need it if you modified a '.y' file."
1828f34cbf9Ssnj      echo "You may want to install the GNU Bison package:"
1838f34cbf9Ssnj      echo "<$gnu_software_URL/bison/>"
1848f34cbf9Ssnj      ;;
1858f34cbf9Ssnj    help2man*)
1868f34cbf9Ssnj      echo "You should only need it if you modified a dependency" \
1878f34cbf9Ssnj           "of a man page."
1888f34cbf9Ssnj      echo "You may want to install the GNU Help2man package:"
1898f34cbf9Ssnj      echo "<$gnu_software_URL/help2man/>"
1908f34cbf9Ssnj    ;;
191e1db7cd1Smrg    lex*|flex*)
192e1db7cd1Smrg      echo "You should only need it if you modified a '.l' file."
193e1db7cd1Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
194e1db7cd1Smrg      echo "<$flex_URL>"
195e1db7cd1Smrg      ;;
1968f34cbf9Ssnj    makeinfo*)
1978f34cbf9Ssnj      echo "You should only need it if you modified a '.texi' file, or"
1988f34cbf9Ssnj      echo "any other file indirectly affecting the aspect of the manual."
1998f34cbf9Ssnj      echo "You might want to install the Texinfo package:"
2008f34cbf9Ssnj      echo "<$gnu_software_URL/texinfo/>"
2018f34cbf9Ssnj      echo "The spurious makeinfo call might also be the consequence of"
2028f34cbf9Ssnj      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
2038f34cbf9Ssnj      echo "want to install GNU make:"
2048f34cbf9Ssnj      echo "<$gnu_software_URL/make/>"
2058f34cbf9Ssnj      ;;
206e1db7cd1Smrg    perl*)
207e1db7cd1Smrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
208e1db7cd1Smrg      echo "  assorted other tools, or if you modified a Perl source file."
209e1db7cd1Smrg      echo "You may want to install the Perl 5 language interpreter:"
210e1db7cd1Smrg      echo "<$perl_URL>"
211e1db7cd1Smrg      ;;
2128f34cbf9Ssnj    *)
2138f34cbf9Ssnj      echo "You might have modified some files without having the proper"
2148f34cbf9Ssnj      echo "tools for further handling them.  Check the 'README' file, it"
2158f34cbf9Ssnj      echo "often tells you about the needed prerequisites for installing"
2168f34cbf9Ssnj      echo "this package.  You may also peek at any GNU archive site, in"
2178f34cbf9Ssnj      echo "case some other package contains this missing '$1' program."
2188f34cbf9Ssnj      ;;
2198f34cbf9Ssnj  esac
220e1db7cd1Smrg  program_details "$normalized_program"
2218f34cbf9Ssnj}
2228f34cbf9Ssnj
2238f34cbf9Ssnjgive_advice "$1" | sed -e '1s/^/WARNING: /' \
2248f34cbf9Ssnj                       -e '2,$s/^/         /' >&2
2258f34cbf9Ssnj
2268f34cbf9Ssnj# Propagate the correct exit status (expected to be 127 for a program
2278f34cbf9Ssnj# not found, 63 for a program that failed due to version mismatch).
2288f34cbf9Ssnjexit $st
229bbe1b32bSmrg
230bbe1b32bSmrg# Local variables:
23176028eb6Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
232bbe1b32bSmrg# time-stamp-start: "scriptversion="
233bbe1b32bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
23440c5823bSmrg# time-stamp-time-zone: "UTC0"
23530f8ce46Smrg# time-stamp-end: "; # UTC"
236bbe1b32bSmrg# End:
237