176910425Smrg#! /bin/sh
28bfe6addSmrg# Common wrapper for a few potentially missing GNU and other programs.
376910425Smrg
48bfe6addSmrgscriptversion=2024-06-07.14; # UTC
576910425Smrg
68bfe6addSmrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
78bfe6addSmrg
88bfe6addSmrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
99ff100acSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
1076910425Smrg
1176910425Smrg# This program is free software; you can redistribute it and/or modify
1276910425Smrg# it under the terms of the GNU General Public License as published by
1376910425Smrg# the Free Software Foundation; either version 2, or (at your option)
1476910425Smrg# any later version.
1576910425Smrg
1676910425Smrg# This program is distributed in the hope that it will be useful,
1776910425Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1876910425Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1976910425Smrg# GNU General Public License for more details.
2076910425Smrg
2176910425Smrg# You should have received a copy of the GNU General Public License
22a67f45c3Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2376910425Smrg
2476910425Smrg# As a special exception to the GNU General Public License, if you
2576910425Smrg# distribute this file as part of a program that contains a
2676910425Smrg# configuration script generated by Autoconf, you may include it under
2776910425Smrg# the same distribution terms that you use for the rest of that program.
2876910425Smrg
2976910425Smrgif test $# -eq 0; then
309ff100acSmrg  echo 1>&2 "Try '$0 --help' for more information"
3176910425Smrg  exit 1
3276910425Smrgfi
3376910425Smrg
349ff100acSmrgcase $1 in
3576910425Smrg
369ff100acSmrg  --is-lightweight)
379ff100acSmrg    # Used by our autoconf macros to check whether the available missing
389ff100acSmrg    # script is modern enough.
399ff100acSmrg    exit 0
409ff100acSmrg    ;;
4176910425Smrg
429ff100acSmrg  --run)
439ff100acSmrg    # Back-compat with the calling convention used by older automake.
449ff100acSmrg    shift
459ff100acSmrg    ;;
4676910425Smrg
4776910425Smrg  -h|--h|--he|--hel|--help)
4876910425Smrg    echo "\
4976910425Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
5076910425Smrg
519ff100acSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
529ff100acSmrgto PROGRAM being missing or too old.
5376910425Smrg
5476910425SmrgOptions:
5576910425Smrg  -h, --help      display this help and exit
5676910425Smrg  -v, --version   output version information and exit
5776910425Smrg
5876910425SmrgSupported PROGRAM values:
598bfe6addSmrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
608bfe6addSmrgbison   flex     help2man lex        makeinfo perl     yacc
6176910425Smrg
629ff100acSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
639ff100acSmrg'g' are ignored when checking the name.
64db17cd6dSmrg
658bfe6addSmrgReport bugs to <bug-automake@gnu.org>.
668bfe6addSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
678bfe6addSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
6876910425Smrg    exit $?
6976910425Smrg    ;;
7076910425Smrg
7176910425Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
728bfe6addSmrg    echo "missing (GNU Automake) $scriptversion"
7376910425Smrg    exit $?
7476910425Smrg    ;;
7576910425Smrg
7676910425Smrg  -*)
779ff100acSmrg    echo 1>&2 "$0: unknown '$1' option"
789ff100acSmrg    echo 1>&2 "Try '$0 --help' for more information"
7976910425Smrg    exit 1
8076910425Smrg    ;;
8176910425Smrg
8276910425Smrgesac
8376910425Smrg
849ff100acSmrg# Run the given program, remember its exit status.
859ff100acSmrg"$@"; st=$?
869ff100acSmrg
879ff100acSmrg# If it succeeded, we are done.
889ff100acSmrgtest $st -eq 0 && exit 0
899ff100acSmrg
909ff100acSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
919ff100acSmrg# passed; such an option is passed most likely to detect whether the
929ff100acSmrg# program is present and works.
939ff100acSmrgcase $2 in --version|--help) exit $st;; esac
949ff100acSmrg
959ff100acSmrg# Exit code 63 means version mismatch.  This often happens when the user
969ff100acSmrg# tries to use an ancient version of a tool on a file that requires a
979ff100acSmrg# minimum version.
989ff100acSmrgif test $st -eq 63; then
999ff100acSmrg  msg="probably too old"
1009ff100acSmrgelif test $st -eq 127; then
1019ff100acSmrg  # Program was missing.
1029ff100acSmrg  msg="missing on your system"
1039ff100acSmrgelse
1049ff100acSmrg  # Program was found and executed, but failed.  Give up.
1059ff100acSmrg  exit $st
1069ff100acSmrgfi
10776910425Smrg
108a67f45c3Smrgperl_URL=https://www.perl.org/
109a67f45c3Smrgflex_URL=https://github.com/westes/flex
110a67f45c3Smrggnu_software_URL=https://www.gnu.org/software
1119ff100acSmrg
1129ff100acSmrgprogram_details ()
1139ff100acSmrg{
1149ff100acSmrg  case $1 in
1158bfe6addSmrg    aclocal|automake|autoreconf)
1169ff100acSmrg      echo "The '$1' program is part of the GNU Automake package:"
1179ff100acSmrg      echo "<$gnu_software_URL/automake>"
1189ff100acSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1199ff100acSmrg      echo "<$gnu_software_URL/autoconf>"
1209ff100acSmrg      echo "<$gnu_software_URL/m4/>"
1219ff100acSmrg      echo "<$perl_URL>"
1229ff100acSmrg      ;;
1239ff100acSmrg    autoconf|autom4te|autoheader)
1249ff100acSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
1259ff100acSmrg      echo "<$gnu_software_URL/autoconf/>"
1269ff100acSmrg      echo "It also requires GNU m4 and Perl in order to run:"
1279ff100acSmrg      echo "<$gnu_software_URL/m4/>"
1289ff100acSmrg      echo "<$perl_URL>"
1299ff100acSmrg      ;;
1308bfe6addSmrg    *)
1318bfe6addSmrg      :
1328bfe6addSmrg      ;;
1339ff100acSmrg  esac
1349ff100acSmrg}
1359ff100acSmrg
1369ff100acSmrggive_advice ()
1379ff100acSmrg{
1389ff100acSmrg  # Normalize program name to check for.
1399ff100acSmrg  normalized_program=`echo "$1" | sed '
1409ff100acSmrg    s/^gnu-//; t
1419ff100acSmrg    s/^gnu//; t
1429ff100acSmrg    s/^g//; t'`
1439ff100acSmrg
1449ff100acSmrg  printf '%s\n' "'$1' is $msg."
1459ff100acSmrg
1469ff100acSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1478bfe6addSmrg  autoheader_deps="'acconfig.h'"
1488bfe6addSmrg  automake_deps="'Makefile.am'"
1498bfe6addSmrg  aclocal_deps="'acinclude.m4'"
1509ff100acSmrg  case $normalized_program in
1518bfe6addSmrg    aclocal*)
1528bfe6addSmrg      echo "You should only need it if you modified $aclocal_deps or"
1538bfe6addSmrg      echo "$configure_deps."
1548bfe6addSmrg      ;;
1559ff100acSmrg    autoconf*)
1568bfe6addSmrg      echo "You should only need it if you modified $configure_deps."
1578bfe6addSmrg      ;;
1588bfe6addSmrg    autogen*)
1598bfe6addSmrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
1608bfe6addSmrg      echo "You may want to install the GNU AutoGen package:"
1618bfe6addSmrg      echo "<$gnu_software_URL/autogen/>"
1629ff100acSmrg      ;;
1639ff100acSmrg    autoheader*)
1648bfe6addSmrg      echo "You should only need it if you modified $autoheader_deps or"
1659ff100acSmrg      echo "$configure_deps."
1669ff100acSmrg      ;;
1679ff100acSmrg    automake*)
1688bfe6addSmrg      echo "You should only need it if you modified $automake_deps or"
1699ff100acSmrg      echo "$configure_deps."
1709ff100acSmrg      ;;
1718bfe6addSmrg    autom4te*)
1729ff100acSmrg      echo "You might have modified some maintainer files that require"
1739ff100acSmrg      echo "the 'autom4te' program to be rebuilt."
1748bfe6addSmrg      ;;
1758bfe6addSmrg    autoreconf*)
1768bfe6addSmrg      echo "You should only need it if you modified $aclocal_deps or"
1778bfe6addSmrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
1788bfe6addSmrg      echo "$configure_deps."
1799ff100acSmrg      ;;
1809ff100acSmrg    bison*|yacc*)
1819ff100acSmrg      echo "You should only need it if you modified a '.y' file."
1829ff100acSmrg      echo "You may want to install the GNU Bison package:"
1839ff100acSmrg      echo "<$gnu_software_URL/bison/>"
1849ff100acSmrg      ;;
1859ff100acSmrg    help2man*)
1869ff100acSmrg      echo "You should only need it if you modified a dependency" \
1879ff100acSmrg           "of a man page."
1889ff100acSmrg      echo "You may want to install the GNU Help2man package:"
1899ff100acSmrg      echo "<$gnu_software_URL/help2man/>"
1909ff100acSmrg    ;;
1918bfe6addSmrg    lex*|flex*)
1928bfe6addSmrg      echo "You should only need it if you modified a '.l' file."
1938bfe6addSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1948bfe6addSmrg      echo "<$flex_URL>"
1958bfe6addSmrg      ;;
1969ff100acSmrg    makeinfo*)
1979ff100acSmrg      echo "You should only need it if you modified a '.texi' file, or"
1989ff100acSmrg      echo "any other file indirectly affecting the aspect of the manual."
1999ff100acSmrg      echo "You might want to install the Texinfo package:"
2009ff100acSmrg      echo "<$gnu_software_URL/texinfo/>"
2019ff100acSmrg      echo "The spurious makeinfo call might also be the consequence of"
2029ff100acSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
2039ff100acSmrg      echo "want to install GNU make:"
2049ff100acSmrg      echo "<$gnu_software_URL/make/>"
2059ff100acSmrg      ;;
2068bfe6addSmrg    perl*)
2078bfe6addSmrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
2088bfe6addSmrg      echo "  assorted other tools, or if you modified a Perl source file."
2098bfe6addSmrg      echo "You may want to install the Perl 5 language interpreter:"
2108bfe6addSmrg      echo "<$perl_URL>"
2118bfe6addSmrg      ;;
2129ff100acSmrg    *)
2139ff100acSmrg      echo "You might have modified some files without having the proper"
2149ff100acSmrg      echo "tools for further handling them.  Check the 'README' file, it"
2159ff100acSmrg      echo "often tells you about the needed prerequisites for installing"
2169ff100acSmrg      echo "this package.  You may also peek at any GNU archive site, in"
2179ff100acSmrg      echo "case some other package contains this missing '$1' program."
2189ff100acSmrg      ;;
2199ff100acSmrg  esac
2208bfe6addSmrg  program_details "$normalized_program"
2219ff100acSmrg}
2229ff100acSmrg
2239ff100acSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2249ff100acSmrg                       -e '2,$s/^/         /' >&2
2259ff100acSmrg
2269ff100acSmrg# Propagate the correct exit status (expected to be 127 for a program
2279ff100acSmrg# not found, 63 for a program that failed due to version mismatch).
2289ff100acSmrgexit $st
22976910425Smrg
23076910425Smrg# Local variables:
231a67f45c3Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
23276910425Smrg# time-stamp-start: "scriptversion="
23376910425Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234a67f45c3Smrg# time-stamp-time-zone: "UTC0"
235db17cd6dSmrg# time-stamp-end: "; # UTC"
23676910425Smrg# End:
237