114c0a534Smrg#! /bin/sh
27015785aSmrg# Common wrapper for a few potentially missing GNU and other programs.
314c0a534Smrg
47015785aSmrgscriptversion=2024-06-07.14; # UTC
514c0a534Smrg
67015785aSmrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
77015785aSmrg
87015785aSmrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
924047306Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
1014c0a534Smrg
1114c0a534Smrg# This program is free software; you can redistribute it and/or modify
1214c0a534Smrg# it under the terms of the GNU General Public License as published by
1314c0a534Smrg# the Free Software Foundation; either version 2, or (at your option)
1414c0a534Smrg# any later version.
1514c0a534Smrg
1614c0a534Smrg# This program is distributed in the hope that it will be useful,
1714c0a534Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1814c0a534Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1914c0a534Smrg# GNU General Public License for more details.
2014c0a534Smrg
2114c0a534Smrg# You should have received a copy of the GNU General Public License
22bdc460c5Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2314c0a534Smrg
2414c0a534Smrg# As a special exception to the GNU General Public License, if you
2514c0a534Smrg# distribute this file as part of a program that contains a
2614c0a534Smrg# configuration script generated by Autoconf, you may include it under
2714c0a534Smrg# the same distribution terms that you use for the rest of that program.
2814c0a534Smrg
2914c0a534Smrgif test $# -eq 0; then
3024047306Smrg  echo 1>&2 "Try '$0 --help' for more information"
3114c0a534Smrg  exit 1
3214c0a534Smrgfi
3314c0a534Smrg
3424047306Smrgcase $1 in
3514c0a534Smrg
3624047306Smrg  --is-lightweight)
3724047306Smrg    # Used by our autoconf macros to check whether the available missing
3824047306Smrg    # script is modern enough.
3924047306Smrg    exit 0
4024047306Smrg    ;;
4114c0a534Smrg
4224047306Smrg  --run)
4324047306Smrg    # Back-compat with the calling convention used by older automake.
4424047306Smrg    shift
4524047306Smrg    ;;
4614c0a534Smrg
4714c0a534Smrg  -h|--h|--he|--hel|--help)
4814c0a534Smrg    echo "\
4914c0a534Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
5014c0a534Smrg
5124047306SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5224047306Smrgto PROGRAM being missing or too old.
5314c0a534Smrg
5414c0a534SmrgOptions:
5514c0a534Smrg  -h, --help      display this help and exit
5614c0a534Smrg  -v, --version   output version information and exit
5714c0a534Smrg
5814c0a534SmrgSupported PROGRAM values:
597015785aSmrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
607015785aSmrgbison   flex     help2man lex        makeinfo perl     yacc
6114c0a534Smrg
6224047306SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6324047306Smrg'g' are ignored when checking the name.
64bf2eeab3Smrg
657015785aSmrgReport bugs to <bug-automake@gnu.org>.
667015785aSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
677015785aSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
6814c0a534Smrg    exit $?
6914c0a534Smrg    ;;
7014c0a534Smrg
7114c0a534Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
727015785aSmrg    echo "missing (GNU Automake) $scriptversion"
7314c0a534Smrg    exit $?
7414c0a534Smrg    ;;
7514c0a534Smrg
7614c0a534Smrg  -*)
7724047306Smrg    echo 1>&2 "$0: unknown '$1' option"
7824047306Smrg    echo 1>&2 "Try '$0 --help' for more information"
7914c0a534Smrg    exit 1
8014c0a534Smrg    ;;
8114c0a534Smrg
8214c0a534Smrgesac
8314c0a534Smrg
8424047306Smrg# Run the given program, remember its exit status.
8524047306Smrg"$@"; st=$?
8624047306Smrg
8724047306Smrg# If it succeeded, we are done.
8824047306Smrgtest $st -eq 0 && exit 0
8924047306Smrg
9024047306Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
9124047306Smrg# passed; such an option is passed most likely to detect whether the
9224047306Smrg# program is present and works.
9324047306Smrgcase $2 in --version|--help) exit $st;; esac
9424047306Smrg
9524047306Smrg# Exit code 63 means version mismatch.  This often happens when the user
9624047306Smrg# tries to use an ancient version of a tool on a file that requires a
9724047306Smrg# minimum version.
9824047306Smrgif test $st -eq 63; then
9924047306Smrg  msg="probably too old"
10024047306Smrgelif test $st -eq 127; then
10124047306Smrg  # Program was missing.
10224047306Smrg  msg="missing on your system"
10324047306Smrgelse
10424047306Smrg  # Program was found and executed, but failed.  Give up.
10524047306Smrg  exit $st
10624047306Smrgfi
10714c0a534Smrg
108bdc460c5Smrgperl_URL=https://www.perl.org/
109bdc460c5Smrgflex_URL=https://github.com/westes/flex
110bdc460c5Smrggnu_software_URL=https://www.gnu.org/software
11124047306Smrg
11224047306Smrgprogram_details ()
11324047306Smrg{
11424047306Smrg  case $1 in
1157015785aSmrg    aclocal|automake|autoreconf)
11624047306Smrg      echo "The '$1' program is part of the GNU Automake package:"
11724047306Smrg      echo "<$gnu_software_URL/automake>"
11824047306Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11924047306Smrg      echo "<$gnu_software_URL/autoconf>"
12024047306Smrg      echo "<$gnu_software_URL/m4/>"
12124047306Smrg      echo "<$perl_URL>"
12224047306Smrg      ;;
12324047306Smrg    autoconf|autom4te|autoheader)
12424047306Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12524047306Smrg      echo "<$gnu_software_URL/autoconf/>"
12624047306Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12724047306Smrg      echo "<$gnu_software_URL/m4/>"
12824047306Smrg      echo "<$perl_URL>"
12924047306Smrg      ;;
1307015785aSmrg    *)
1317015785aSmrg      :
1327015785aSmrg      ;;
13324047306Smrg  esac
13424047306Smrg}
13524047306Smrg
13624047306Smrggive_advice ()
13724047306Smrg{
13824047306Smrg  # Normalize program name to check for.
13924047306Smrg  normalized_program=`echo "$1" | sed '
14024047306Smrg    s/^gnu-//; t
14124047306Smrg    s/^gnu//; t
14224047306Smrg    s/^g//; t'`
14324047306Smrg
14424047306Smrg  printf '%s\n' "'$1' is $msg."
14524047306Smrg
14624047306Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1477015785aSmrg  autoheader_deps="'acconfig.h'"
1487015785aSmrg  automake_deps="'Makefile.am'"
1497015785aSmrg  aclocal_deps="'acinclude.m4'"
15024047306Smrg  case $normalized_program in
1517015785aSmrg    aclocal*)
1527015785aSmrg      echo "You should only need it if you modified $aclocal_deps or"
1537015785aSmrg      echo "$configure_deps."
1547015785aSmrg      ;;
15524047306Smrg    autoconf*)
1567015785aSmrg      echo "You should only need it if you modified $configure_deps."
1577015785aSmrg      ;;
1587015785aSmrg    autogen*)
1597015785aSmrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
1607015785aSmrg      echo "You may want to install the GNU AutoGen package:"
1617015785aSmrg      echo "<$gnu_software_URL/autogen/>"
16224047306Smrg      ;;
16324047306Smrg    autoheader*)
1647015785aSmrg      echo "You should only need it if you modified $autoheader_deps or"
16524047306Smrg      echo "$configure_deps."
16624047306Smrg      ;;
16724047306Smrg    automake*)
1687015785aSmrg      echo "You should only need it if you modified $automake_deps or"
16924047306Smrg      echo "$configure_deps."
17024047306Smrg      ;;
1717015785aSmrg    autom4te*)
17224047306Smrg      echo "You might have modified some maintainer files that require"
17324047306Smrg      echo "the 'autom4te' program to be rebuilt."
1747015785aSmrg      ;;
1757015785aSmrg    autoreconf*)
1767015785aSmrg      echo "You should only need it if you modified $aclocal_deps or"
1777015785aSmrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
1787015785aSmrg      echo "$configure_deps."
17924047306Smrg      ;;
18024047306Smrg    bison*|yacc*)
18124047306Smrg      echo "You should only need it if you modified a '.y' file."
18224047306Smrg      echo "You may want to install the GNU Bison package:"
18324047306Smrg      echo "<$gnu_software_URL/bison/>"
18424047306Smrg      ;;
18524047306Smrg    help2man*)
18624047306Smrg      echo "You should only need it if you modified a dependency" \
18724047306Smrg           "of a man page."
18824047306Smrg      echo "You may want to install the GNU Help2man package:"
18924047306Smrg      echo "<$gnu_software_URL/help2man/>"
19024047306Smrg    ;;
1917015785aSmrg    lex*|flex*)
1927015785aSmrg      echo "You should only need it if you modified a '.l' file."
1937015785aSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1947015785aSmrg      echo "<$flex_URL>"
1957015785aSmrg      ;;
19624047306Smrg    makeinfo*)
19724047306Smrg      echo "You should only need it if you modified a '.texi' file, or"
19824047306Smrg      echo "any other file indirectly affecting the aspect of the manual."
19924047306Smrg      echo "You might want to install the Texinfo package:"
20024047306Smrg      echo "<$gnu_software_URL/texinfo/>"
20124047306Smrg      echo "The spurious makeinfo call might also be the consequence of"
20224047306Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
20324047306Smrg      echo "want to install GNU make:"
20424047306Smrg      echo "<$gnu_software_URL/make/>"
20524047306Smrg      ;;
2067015785aSmrg    perl*)
2077015785aSmrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
2087015785aSmrg      echo "  assorted other tools, or if you modified a Perl source file."
2097015785aSmrg      echo "You may want to install the Perl 5 language interpreter:"
2107015785aSmrg      echo "<$perl_URL>"
2117015785aSmrg      ;;
21224047306Smrg    *)
21324047306Smrg      echo "You might have modified some files without having the proper"
21424047306Smrg      echo "tools for further handling them.  Check the 'README' file, it"
21524047306Smrg      echo "often tells you about the needed prerequisites for installing"
21624047306Smrg      echo "this package.  You may also peek at any GNU archive site, in"
21724047306Smrg      echo "case some other package contains this missing '$1' program."
21824047306Smrg      ;;
21924047306Smrg  esac
2207015785aSmrg  program_details "$normalized_program"
22124047306Smrg}
22224047306Smrg
22324047306Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
22424047306Smrg                       -e '2,$s/^/         /' >&2
22524047306Smrg
22624047306Smrg# Propagate the correct exit status (expected to be 127 for a program
22724047306Smrg# not found, 63 for a program that failed due to version mismatch).
22824047306Smrgexit $st
22914c0a534Smrg
23014c0a534Smrg# Local variables:
231bdc460c5Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
23214c0a534Smrg# time-stamp-start: "scriptversion="
23314c0a534Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234bdc460c5Smrg# time-stamp-time-zone: "UTC0"
235bf2eeab3Smrg# time-stamp-end: "; # UTC"
23614c0a534Smrg# End:
237