1492e1cfeSmrg#! /bin/sh
21afad795Smrg# Common wrapper for a few potentially missing GNU programs.
39e0146f7Smrg
431e5d586Smrgscriptversion=2018-03-07.03; # UTC
59e0146f7Smrg
631e5d586Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
71afad795Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8492e1cfeSmrg
9492e1cfeSmrg# This program is free software; you can redistribute it and/or modify
10492e1cfeSmrg# it under the terms of the GNU General Public License as published by
11492e1cfeSmrg# the Free Software Foundation; either version 2, or (at your option)
12492e1cfeSmrg# any later version.
13492e1cfeSmrg
14492e1cfeSmrg# This program is distributed in the hope that it will be useful,
15492e1cfeSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16492e1cfeSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17492e1cfeSmrg# GNU General Public License for more details.
18492e1cfeSmrg
19492e1cfeSmrg# You should have received a copy of the GNU General Public License
2031e5d586Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21492e1cfeSmrg
22492e1cfeSmrg# As a special exception to the GNU General Public License, if you
23492e1cfeSmrg# distribute this file as part of a program that contains a
24492e1cfeSmrg# configuration script generated by Autoconf, you may include it under
25492e1cfeSmrg# the same distribution terms that you use for the rest of that program.
26492e1cfeSmrg
27492e1cfeSmrgif test $# -eq 0; then
281afad795Smrg  echo 1>&2 "Try '$0 --help' for more information"
29492e1cfeSmrg  exit 1
30492e1cfeSmrgfi
31492e1cfeSmrg
321afad795Smrgcase $1 in
33492e1cfeSmrg
341afad795Smrg  --is-lightweight)
351afad795Smrg    # Used by our autoconf macros to check whether the available missing
361afad795Smrg    # script is modern enough.
371afad795Smrg    exit 0
381afad795Smrg    ;;
399e0146f7Smrg
401afad795Smrg  --run)
411afad795Smrg    # Back-compat with the calling convention used by older automake.
421afad795Smrg    shift
431afad795Smrg    ;;
44492e1cfeSmrg
45492e1cfeSmrg  -h|--h|--he|--hel|--help)
46492e1cfeSmrg    echo "\
47492e1cfeSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48492e1cfeSmrg
491afad795SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
501afad795Smrgto PROGRAM being missing or too old.
51492e1cfeSmrg
52492e1cfeSmrgOptions:
53492e1cfeSmrg  -h, --help      display this help and exit
54492e1cfeSmrg  -v, --version   output version information and exit
55492e1cfeSmrg
56492e1cfeSmrgSupported PROGRAM values:
571afad795Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
581afad795Smrg  bison     yacc      flex         lex       help2man
599e0146f7Smrg
601afad795SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
611afad795Smrg'g' are ignored when checking the name.
629e0146f7Smrg
639e0146f7SmrgSend bug reports to <bug-automake@gnu.org>."
649e0146f7Smrg    exit $?
65492e1cfeSmrg    ;;
66492e1cfeSmrg
67492e1cfeSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
689e0146f7Smrg    echo "missing $scriptversion (GNU Automake)"
699e0146f7Smrg    exit $?
70492e1cfeSmrg    ;;
71492e1cfeSmrg
72492e1cfeSmrg  -*)
731afad795Smrg    echo 1>&2 "$0: unknown '$1' option"
741afad795Smrg    echo 1>&2 "Try '$0 --help' for more information"
75492e1cfeSmrg    exit 1
76492e1cfeSmrg    ;;
77492e1cfeSmrg
789e0146f7Smrgesac
799e0146f7Smrg
801afad795Smrg# Run the given program, remember its exit status.
811afad795Smrg"$@"; st=$?
821afad795Smrg
831afad795Smrg# If it succeeded, we are done.
841afad795Smrgtest $st -eq 0 && exit 0
851afad795Smrg
861afad795Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
871afad795Smrg# passed; such an option is passed most likely to detect whether the
881afad795Smrg# program is present and works.
891afad795Smrgcase $2 in --version|--help) exit $st;; esac
901afad795Smrg
911afad795Smrg# Exit code 63 means version mismatch.  This often happens when the user
921afad795Smrg# tries to use an ancient version of a tool on a file that requires a
931afad795Smrg# minimum version.
941afad795Smrgif test $st -eq 63; then
951afad795Smrg  msg="probably too old"
961afad795Smrgelif test $st -eq 127; then
971afad795Smrg  # Program was missing.
981afad795Smrg  msg="missing on your system"
991afad795Smrgelse
1001afad795Smrg  # Program was found and executed, but failed.  Give up.
1011afad795Smrg  exit $st
1021afad795Smrgfi
103492e1cfeSmrg
10431e5d586Smrgperl_URL=https://www.perl.org/
10531e5d586Smrgflex_URL=https://github.com/westes/flex
10631e5d586Smrggnu_software_URL=https://www.gnu.org/software
1071afad795Smrg
1081afad795Smrgprogram_details ()
1091afad795Smrg{
1101afad795Smrg  case $1 in
1111afad795Smrg    aclocal|automake)
1121afad795Smrg      echo "The '$1' program is part of the GNU Automake package:"
1131afad795Smrg      echo "<$gnu_software_URL/automake>"
1141afad795Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1151afad795Smrg      echo "<$gnu_software_URL/autoconf>"
1161afad795Smrg      echo "<$gnu_software_URL/m4/>"
1171afad795Smrg      echo "<$perl_URL>"
1181afad795Smrg      ;;
1191afad795Smrg    autoconf|autom4te|autoheader)
1201afad795Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1211afad795Smrg      echo "<$gnu_software_URL/autoconf/>"
1221afad795Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1231afad795Smrg      echo "<$gnu_software_URL/m4/>"
1241afad795Smrg      echo "<$perl_URL>"
1251afad795Smrg      ;;
1261afad795Smrg  esac
1271afad795Smrg}
1281afad795Smrg
1291afad795Smrggive_advice ()
1301afad795Smrg{
1311afad795Smrg  # Normalize program name to check for.
1321afad795Smrg  normalized_program=`echo "$1" | sed '
1331afad795Smrg    s/^gnu-//; t
1341afad795Smrg    s/^gnu//; t
1351afad795Smrg    s/^g//; t'`
1361afad795Smrg
1371afad795Smrg  printf '%s\n' "'$1' is $msg."
1381afad795Smrg
1391afad795Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1401afad795Smrg  case $normalized_program in
1411afad795Smrg    autoconf*)
1421afad795Smrg      echo "You should only need it if you modified 'configure.ac',"
1431afad795Smrg      echo "or m4 files included by it."
1441afad795Smrg      program_details 'autoconf'
1451afad795Smrg      ;;
1461afad795Smrg    autoheader*)
1471afad795Smrg      echo "You should only need it if you modified 'acconfig.h' or"
1481afad795Smrg      echo "$configure_deps."
1491afad795Smrg      program_details 'autoheader'
1501afad795Smrg      ;;
1511afad795Smrg    automake*)
1521afad795Smrg      echo "You should only need it if you modified 'Makefile.am' or"
1531afad795Smrg      echo "$configure_deps."
1541afad795Smrg      program_details 'automake'
1551afad795Smrg      ;;
1561afad795Smrg    aclocal*)
1571afad795Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
1581afad795Smrg      echo "$configure_deps."
1591afad795Smrg      program_details 'aclocal'
1601afad795Smrg      ;;
1611afad795Smrg   autom4te*)
1621afad795Smrg      echo "You might have modified some maintainer files that require"
163b78bb896Smrg      echo "the 'autom4te' program to be rebuilt."
1641afad795Smrg      program_details 'autom4te'
1651afad795Smrg      ;;
1661afad795Smrg    bison*|yacc*)
1671afad795Smrg      echo "You should only need it if you modified a '.y' file."
1681afad795Smrg      echo "You may want to install the GNU Bison package:"
1691afad795Smrg      echo "<$gnu_software_URL/bison/>"
1701afad795Smrg      ;;
1711afad795Smrg    lex*|flex*)
1721afad795Smrg      echo "You should only need it if you modified a '.l' file."
1731afad795Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1741afad795Smrg      echo "<$flex_URL>"
1751afad795Smrg      ;;
1761afad795Smrg    help2man*)
1771afad795Smrg      echo "You should only need it if you modified a dependency" \
1781afad795Smrg           "of a man page."
1791afad795Smrg      echo "You may want to install the GNU Help2man package:"
1801afad795Smrg      echo "<$gnu_software_URL/help2man/>"
1811afad795Smrg    ;;
1821afad795Smrg    makeinfo*)
1831afad795Smrg      echo "You should only need it if you modified a '.texi' file, or"
1841afad795Smrg      echo "any other file indirectly affecting the aspect of the manual."
1851afad795Smrg      echo "You might want to install the Texinfo package:"
1861afad795Smrg      echo "<$gnu_software_URL/texinfo/>"
1871afad795Smrg      echo "The spurious makeinfo call might also be the consequence of"
1881afad795Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1891afad795Smrg      echo "want to install GNU make:"
1901afad795Smrg      echo "<$gnu_software_URL/make/>"
1911afad795Smrg      ;;
1921afad795Smrg    *)
1931afad795Smrg      echo "You might have modified some files without having the proper"
1941afad795Smrg      echo "tools for further handling them.  Check the 'README' file, it"
1951afad795Smrg      echo "often tells you about the needed prerequisites for installing"
1961afad795Smrg      echo "this package.  You may also peek at any GNU archive site, in"
1971afad795Smrg      echo "case some other package contains this missing '$1' program."
1981afad795Smrg      ;;
1991afad795Smrg  esac
2001afad795Smrg}
2011afad795Smrg
2021afad795Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2031afad795Smrg                       -e '2,$s/^/         /' >&2
2041afad795Smrg
2051afad795Smrg# Propagate the correct exit status (expected to be 127 for a program
2061afad795Smrg# not found, 63 for a program that failed due to version mismatch).
2071afad795Smrgexit $st
2089e0146f7Smrg
2099e0146f7Smrg# Local variables:
21031e5d586Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2119e0146f7Smrg# time-stamp-start: "scriptversion="
2129e0146f7Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21331e5d586Smrg# time-stamp-time-zone: "UTC0"
2149e0146f7Smrg# time-stamp-end: "; # UTC"
2159e0146f7Smrg# End:
216