10e20ee16Smrg#! /bin/sh
28b648e79Smrg# Common wrapper for a few potentially missing GNU and other programs.
33e6697d4Smrg
48b648e79Smrgscriptversion=2024-06-07.14; # UTC
53e6697d4Smrg
68b648e79Smrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
78b648e79Smrg
88b648e79Smrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
92f167a42Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
100e20ee16Smrg
110e20ee16Smrg# This program is free software; you can redistribute it and/or modify
120e20ee16Smrg# it under the terms of the GNU General Public License as published by
130e20ee16Smrg# the Free Software Foundation; either version 2, or (at your option)
140e20ee16Smrg# any later version.
150e20ee16Smrg
160e20ee16Smrg# This program is distributed in the hope that it will be useful,
170e20ee16Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
180e20ee16Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
190e20ee16Smrg# GNU General Public License for more details.
200e20ee16Smrg
210e20ee16Smrg# You should have received a copy of the GNU General Public License
22fc34a306Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
230e20ee16Smrg
240e20ee16Smrg# As a special exception to the GNU General Public License, if you
250e20ee16Smrg# distribute this file as part of a program that contains a
260e20ee16Smrg# configuration script generated by Autoconf, you may include it under
270e20ee16Smrg# the same distribution terms that you use for the rest of that program.
280e20ee16Smrg
290e20ee16Smrgif test $# -eq 0; then
302f167a42Smrg  echo 1>&2 "Try '$0 --help' for more information"
310e20ee16Smrg  exit 1
320e20ee16Smrgfi
330e20ee16Smrg
342f167a42Smrgcase $1 in
350e20ee16Smrg
362f167a42Smrg  --is-lightweight)
372f167a42Smrg    # Used by our autoconf macros to check whether the available missing
382f167a42Smrg    # script is modern enough.
392f167a42Smrg    exit 0
402f167a42Smrg    ;;
413e6697d4Smrg
422f167a42Smrg  --run)
432f167a42Smrg    # Back-compat with the calling convention used by older automake.
442f167a42Smrg    shift
452f167a42Smrg    ;;
460e20ee16Smrg
470e20ee16Smrg  -h|--h|--he|--hel|--help)
480e20ee16Smrg    echo "\
490e20ee16Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
500e20ee16Smrg
512f167a42SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
522f167a42Smrgto PROGRAM being missing or too old.
530e20ee16Smrg
540e20ee16SmrgOptions:
550e20ee16Smrg  -h, --help      display this help and exit
560e20ee16Smrg  -v, --version   output version information and exit
570e20ee16Smrg
580e20ee16SmrgSupported PROGRAM values:
598b648e79Smrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
608b648e79Smrgbison   flex     help2man lex        makeinfo perl     yacc
613e6697d4Smrg
622f167a42SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
632f167a42Smrg'g' are ignored when checking the name.
643e6697d4Smrg
658b648e79SmrgReport bugs to <bug-automake@gnu.org>.
668b648e79SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
678b648e79SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
683e6697d4Smrg    exit $?
690e20ee16Smrg    ;;
700e20ee16Smrg
710e20ee16Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
728b648e79Smrg    echo "missing (GNU Automake) $scriptversion"
733e6697d4Smrg    exit $?
740e20ee16Smrg    ;;
750e20ee16Smrg
760e20ee16Smrg  -*)
772f167a42Smrg    echo 1>&2 "$0: unknown '$1' option"
782f167a42Smrg    echo 1>&2 "Try '$0 --help' for more information"
790e20ee16Smrg    exit 1
800e20ee16Smrg    ;;
810e20ee16Smrg
823e6697d4Smrgesac
833e6697d4Smrg
842f167a42Smrg# Run the given program, remember its exit status.
852f167a42Smrg"$@"; st=$?
862f167a42Smrg
872f167a42Smrg# If it succeeded, we are done.
882f167a42Smrgtest $st -eq 0 && exit 0
892f167a42Smrg
902f167a42Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
912f167a42Smrg# passed; such an option is passed most likely to detect whether the
922f167a42Smrg# program is present and works.
932f167a42Smrgcase $2 in --version|--help) exit $st;; esac
942f167a42Smrg
952f167a42Smrg# Exit code 63 means version mismatch.  This often happens when the user
962f167a42Smrg# tries to use an ancient version of a tool on a file that requires a
972f167a42Smrg# minimum version.
982f167a42Smrgif test $st -eq 63; then
992f167a42Smrg  msg="probably too old"
1002f167a42Smrgelif test $st -eq 127; then
1012f167a42Smrg  # Program was missing.
1022f167a42Smrg  msg="missing on your system"
1032f167a42Smrgelse
1042f167a42Smrg  # Program was found and executed, but failed.  Give up.
1052f167a42Smrg  exit $st
1062f167a42Smrgfi
1070e20ee16Smrg
108fc34a306Smrgperl_URL=https://www.perl.org/
109fc34a306Smrgflex_URL=https://github.com/westes/flex
110fc34a306Smrggnu_software_URL=https://www.gnu.org/software
1112f167a42Smrg
1122f167a42Smrgprogram_details ()
1132f167a42Smrg{
1142f167a42Smrg  case $1 in
1158b648e79Smrg    aclocal|automake|autoreconf)
1162f167a42Smrg      echo "The '$1' program is part of the GNU Automake package:"
1172f167a42Smrg      echo "<$gnu_software_URL/automake>"
1182f167a42Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1192f167a42Smrg      echo "<$gnu_software_URL/autoconf>"
1202f167a42Smrg      echo "<$gnu_software_URL/m4/>"
1212f167a42Smrg      echo "<$perl_URL>"
1222f167a42Smrg      ;;
1232f167a42Smrg    autoconf|autom4te|autoheader)
1242f167a42Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1252f167a42Smrg      echo "<$gnu_software_URL/autoconf/>"
1262f167a42Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1272f167a42Smrg      echo "<$gnu_software_URL/m4/>"
1282f167a42Smrg      echo "<$perl_URL>"
1292f167a42Smrg      ;;
1308b648e79Smrg    *)
1318b648e79Smrg      :
1328b648e79Smrg      ;;
1332f167a42Smrg  esac
1342f167a42Smrg}
1352f167a42Smrg
1362f167a42Smrggive_advice ()
1372f167a42Smrg{
1382f167a42Smrg  # Normalize program name to check for.
1392f167a42Smrg  normalized_program=`echo "$1" | sed '
1402f167a42Smrg    s/^gnu-//; t
1412f167a42Smrg    s/^gnu//; t
1422f167a42Smrg    s/^g//; t'`
1432f167a42Smrg
1442f167a42Smrg  printf '%s\n' "'$1' is $msg."
1452f167a42Smrg
1462f167a42Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1478b648e79Smrg  autoheader_deps="'acconfig.h'"
1488b648e79Smrg  automake_deps="'Makefile.am'"
1498b648e79Smrg  aclocal_deps="'acinclude.m4'"
1502f167a42Smrg  case $normalized_program in
1518b648e79Smrg    aclocal*)
1528b648e79Smrg      echo "You should only need it if you modified $aclocal_deps or"
1538b648e79Smrg      echo "$configure_deps."
1548b648e79Smrg      ;;
1552f167a42Smrg    autoconf*)
1568b648e79Smrg      echo "You should only need it if you modified $configure_deps."
1578b648e79Smrg      ;;
1588b648e79Smrg    autogen*)
1598b648e79Smrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
1608b648e79Smrg      echo "You may want to install the GNU AutoGen package:"
1618b648e79Smrg      echo "<$gnu_software_URL/autogen/>"
1622f167a42Smrg      ;;
1632f167a42Smrg    autoheader*)
1648b648e79Smrg      echo "You should only need it if you modified $autoheader_deps or"
1652f167a42Smrg      echo "$configure_deps."
1662f167a42Smrg      ;;
1672f167a42Smrg    automake*)
1688b648e79Smrg      echo "You should only need it if you modified $automake_deps or"
1692f167a42Smrg      echo "$configure_deps."
1702f167a42Smrg      ;;
1718b648e79Smrg    autom4te*)
1722f167a42Smrg      echo "You might have modified some maintainer files that require"
1732f167a42Smrg      echo "the 'autom4te' program to be rebuilt."
1748b648e79Smrg      ;;
1758b648e79Smrg    autoreconf*)
1768b648e79Smrg      echo "You should only need it if you modified $aclocal_deps or"
1778b648e79Smrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
1788b648e79Smrg      echo "$configure_deps."
1792f167a42Smrg      ;;
1802f167a42Smrg    bison*|yacc*)
1812f167a42Smrg      echo "You should only need it if you modified a '.y' file."
1822f167a42Smrg      echo "You may want to install the GNU Bison package:"
1832f167a42Smrg      echo "<$gnu_software_URL/bison/>"
1842f167a42Smrg      ;;
1852f167a42Smrg    help2man*)
1862f167a42Smrg      echo "You should only need it if you modified a dependency" \
1872f167a42Smrg           "of a man page."
1882f167a42Smrg      echo "You may want to install the GNU Help2man package:"
1892f167a42Smrg      echo "<$gnu_software_URL/help2man/>"
1902f167a42Smrg    ;;
1918b648e79Smrg    lex*|flex*)
1928b648e79Smrg      echo "You should only need it if you modified a '.l' file."
1938b648e79Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1948b648e79Smrg      echo "<$flex_URL>"
1958b648e79Smrg      ;;
1962f167a42Smrg    makeinfo*)
1972f167a42Smrg      echo "You should only need it if you modified a '.texi' file, or"
1982f167a42Smrg      echo "any other file indirectly affecting the aspect of the manual."
1992f167a42Smrg      echo "You might want to install the Texinfo package:"
2002f167a42Smrg      echo "<$gnu_software_URL/texinfo/>"
2012f167a42Smrg      echo "The spurious makeinfo call might also be the consequence of"
2022f167a42Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
2032f167a42Smrg      echo "want to install GNU make:"
2042f167a42Smrg      echo "<$gnu_software_URL/make/>"
2052f167a42Smrg      ;;
2068b648e79Smrg    perl*)
2078b648e79Smrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
2088b648e79Smrg      echo "  assorted other tools, or if you modified a Perl source file."
2098b648e79Smrg      echo "You may want to install the Perl 5 language interpreter:"
2108b648e79Smrg      echo "<$perl_URL>"
2118b648e79Smrg      ;;
2122f167a42Smrg    *)
2132f167a42Smrg      echo "You might have modified some files without having the proper"
2142f167a42Smrg      echo "tools for further handling them.  Check the 'README' file, it"
2152f167a42Smrg      echo "often tells you about the needed prerequisites for installing"
2162f167a42Smrg      echo "this package.  You may also peek at any GNU archive site, in"
2172f167a42Smrg      echo "case some other package contains this missing '$1' program."
2182f167a42Smrg      ;;
2192f167a42Smrg  esac
2208b648e79Smrg  program_details "$normalized_program"
2212f167a42Smrg}
2222f167a42Smrg
2232f167a42Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2242f167a42Smrg                       -e '2,$s/^/         /' >&2
2252f167a42Smrg
2262f167a42Smrg# Propagate the correct exit status (expected to be 127 for a program
2272f167a42Smrg# not found, 63 for a program that failed due to version mismatch).
2282f167a42Smrgexit $st
2293e6697d4Smrg
2303e6697d4Smrg# Local variables:
231fc34a306Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2323e6697d4Smrg# time-stamp-start: "scriptversion="
2333e6697d4Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234fc34a306Smrg# time-stamp-time-zone: "UTC0"
2353e6697d4Smrg# time-stamp-end: "; # UTC"
2363e6697d4Smrg# End:
237