132b578d3Smrg#! /bin/sh
25a81ca49Smrg# Common wrapper for a few potentially missing GNU programs.
332b578d3Smrg
40b0ce0bfSmrgscriptversion=2018-03-07.03; # UTC
532b578d3Smrg
60b0ce0bfSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
75a81ca49Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
832b578d3Smrg
932b578d3Smrg# This program is free software; you can redistribute it and/or modify
1032b578d3Smrg# it under the terms of the GNU General Public License as published by
1132b578d3Smrg# the Free Software Foundation; either version 2, or (at your option)
1232b578d3Smrg# any later version.
1332b578d3Smrg
1432b578d3Smrg# This program is distributed in the hope that it will be useful,
1532b578d3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1632b578d3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1732b578d3Smrg# GNU General Public License for more details.
1832b578d3Smrg
1932b578d3Smrg# You should have received a copy of the GNU General Public License
200b0ce0bfSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2132b578d3Smrg
2232b578d3Smrg# As a special exception to the GNU General Public License, if you
2332b578d3Smrg# distribute this file as part of a program that contains a
2432b578d3Smrg# configuration script generated by Autoconf, you may include it under
2532b578d3Smrg# the same distribution terms that you use for the rest of that program.
2632b578d3Smrg
2732b578d3Smrgif test $# -eq 0; then
285a81ca49Smrg  echo 1>&2 "Try '$0 --help' for more information"
2932b578d3Smrg  exit 1
3032b578d3Smrgfi
3132b578d3Smrg
325a81ca49Smrgcase $1 in
3332b578d3Smrg
345a81ca49Smrg  --is-lightweight)
355a81ca49Smrg    # Used by our autoconf macros to check whether the available missing
365a81ca49Smrg    # script is modern enough.
375a81ca49Smrg    exit 0
385a81ca49Smrg    ;;
3932b578d3Smrg
405a81ca49Smrg  --run)
415a81ca49Smrg    # Back-compat with the calling convention used by older automake.
425a81ca49Smrg    shift
435a81ca49Smrg    ;;
4432b578d3Smrg
4532b578d3Smrg  -h|--h|--he|--hel|--help)
4632b578d3Smrg    echo "\
4732b578d3Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4832b578d3Smrg
495a81ca49SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
505a81ca49Smrgto PROGRAM being missing or too old.
5132b578d3Smrg
5232b578d3SmrgOptions:
5332b578d3Smrg  -h, --help      display this help and exit
5432b578d3Smrg  -v, --version   output version information and exit
5532b578d3Smrg
5632b578d3SmrgSupported PROGRAM values:
575a81ca49Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
585a81ca49Smrg  bison     yacc      flex         lex       help2man
5932b578d3Smrg
605a81ca49SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
615a81ca49Smrg'g' are ignored when checking the name.
622a51b5beSmrg
6332b578d3SmrgSend bug reports to <bug-automake@gnu.org>."
6432b578d3Smrg    exit $?
6532b578d3Smrg    ;;
6632b578d3Smrg
6732b578d3Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6832b578d3Smrg    echo "missing $scriptversion (GNU Automake)"
6932b578d3Smrg    exit $?
7032b578d3Smrg    ;;
7132b578d3Smrg
7232b578d3Smrg  -*)
735a81ca49Smrg    echo 1>&2 "$0: unknown '$1' option"
745a81ca49Smrg    echo 1>&2 "Try '$0 --help' for more information"
7532b578d3Smrg    exit 1
7632b578d3Smrg    ;;
7732b578d3Smrg
7832b578d3Smrgesac
7932b578d3Smrg
805a81ca49Smrg# Run the given program, remember its exit status.
815a81ca49Smrg"$@"; st=$?
825a81ca49Smrg
835a81ca49Smrg# If it succeeded, we are done.
845a81ca49Smrgtest $st -eq 0 && exit 0
855a81ca49Smrg
865a81ca49Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
875a81ca49Smrg# passed; such an option is passed most likely to detect whether the
885a81ca49Smrg# program is present and works.
895a81ca49Smrgcase $2 in --version|--help) exit $st;; esac
905a81ca49Smrg
915a81ca49Smrg# Exit code 63 means version mismatch.  This often happens when the user
925a81ca49Smrg# tries to use an ancient version of a tool on a file that requires a
935a81ca49Smrg# minimum version.
945a81ca49Smrgif test $st -eq 63; then
955a81ca49Smrg  msg="probably too old"
965a81ca49Smrgelif test $st -eq 127; then
975a81ca49Smrg  # Program was missing.
985a81ca49Smrg  msg="missing on your system"
995a81ca49Smrgelse
1005a81ca49Smrg  # Program was found and executed, but failed.  Give up.
1015a81ca49Smrg  exit $st
1025a81ca49Smrgfi
10332b578d3Smrg
1040b0ce0bfSmrgperl_URL=https://www.perl.org/
1050b0ce0bfSmrgflex_URL=https://github.com/westes/flex
1060b0ce0bfSmrggnu_software_URL=https://www.gnu.org/software
1075a81ca49Smrg
1085a81ca49Smrgprogram_details ()
1095a81ca49Smrg{
1105a81ca49Smrg  case $1 in
1115a81ca49Smrg    aclocal|automake)
1125a81ca49Smrg      echo "The '$1' program is part of the GNU Automake package:"
1135a81ca49Smrg      echo "<$gnu_software_URL/automake>"
1145a81ca49Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1155a81ca49Smrg      echo "<$gnu_software_URL/autoconf>"
1165a81ca49Smrg      echo "<$gnu_software_URL/m4/>"
1175a81ca49Smrg      echo "<$perl_URL>"
1185a81ca49Smrg      ;;
1195a81ca49Smrg    autoconf|autom4te|autoheader)
1205a81ca49Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1215a81ca49Smrg      echo "<$gnu_software_URL/autoconf/>"
1225a81ca49Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1235a81ca49Smrg      echo "<$gnu_software_URL/m4/>"
1245a81ca49Smrg      echo "<$perl_URL>"
1255a81ca49Smrg      ;;
1265a81ca49Smrg  esac
1275a81ca49Smrg}
1285a81ca49Smrg
1295a81ca49Smrggive_advice ()
1305a81ca49Smrg{
1315a81ca49Smrg  # Normalize program name to check for.
1325a81ca49Smrg  normalized_program=`echo "$1" | sed '
1335a81ca49Smrg    s/^gnu-//; t
1345a81ca49Smrg    s/^gnu//; t
1355a81ca49Smrg    s/^g//; t'`
1365a81ca49Smrg
1375a81ca49Smrg  printf '%s\n' "'$1' is $msg."
1385a81ca49Smrg
1395a81ca49Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1405a81ca49Smrg  case $normalized_program in
1415a81ca49Smrg    autoconf*)
1425a81ca49Smrg      echo "You should only need it if you modified 'configure.ac',"
1435a81ca49Smrg      echo "or m4 files included by it."
1445a81ca49Smrg      program_details 'autoconf'
1455a81ca49Smrg      ;;
1465a81ca49Smrg    autoheader*)
1475a81ca49Smrg      echo "You should only need it if you modified 'acconfig.h' or"
1485a81ca49Smrg      echo "$configure_deps."
1495a81ca49Smrg      program_details 'autoheader'
1505a81ca49Smrg      ;;
1515a81ca49Smrg    automake*)
1525a81ca49Smrg      echo "You should only need it if you modified 'Makefile.am' or"
1535a81ca49Smrg      echo "$configure_deps."
1545a81ca49Smrg      program_details 'automake'
1555a81ca49Smrg      ;;
1565a81ca49Smrg    aclocal*)
1575a81ca49Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
1585a81ca49Smrg      echo "$configure_deps."
1595a81ca49Smrg      program_details 'aclocal'
1605a81ca49Smrg      ;;
1615a81ca49Smrg   autom4te*)
1625a81ca49Smrg      echo "You might have modified some maintainer files that require"
1635a81ca49Smrg      echo "the 'autom4te' program to be rebuilt."
1645a81ca49Smrg      program_details 'autom4te'
1655a81ca49Smrg      ;;
1665a81ca49Smrg    bison*|yacc*)
1675a81ca49Smrg      echo "You should only need it if you modified a '.y' file."
1685a81ca49Smrg      echo "You may want to install the GNU Bison package:"
1695a81ca49Smrg      echo "<$gnu_software_URL/bison/>"
1705a81ca49Smrg      ;;
1715a81ca49Smrg    lex*|flex*)
1725a81ca49Smrg      echo "You should only need it if you modified a '.l' file."
1735a81ca49Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1745a81ca49Smrg      echo "<$flex_URL>"
1755a81ca49Smrg      ;;
1765a81ca49Smrg    help2man*)
1775a81ca49Smrg      echo "You should only need it if you modified a dependency" \
1785a81ca49Smrg           "of a man page."
1795a81ca49Smrg      echo "You may want to install the GNU Help2man package:"
1805a81ca49Smrg      echo "<$gnu_software_URL/help2man/>"
1815a81ca49Smrg    ;;
1825a81ca49Smrg    makeinfo*)
1835a81ca49Smrg      echo "You should only need it if you modified a '.texi' file, or"
1845a81ca49Smrg      echo "any other file indirectly affecting the aspect of the manual."
1855a81ca49Smrg      echo "You might want to install the Texinfo package:"
1865a81ca49Smrg      echo "<$gnu_software_URL/texinfo/>"
1875a81ca49Smrg      echo "The spurious makeinfo call might also be the consequence of"
1885a81ca49Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1895a81ca49Smrg      echo "want to install GNU make:"
1905a81ca49Smrg      echo "<$gnu_software_URL/make/>"
1915a81ca49Smrg      ;;
1925a81ca49Smrg    *)
1935a81ca49Smrg      echo "You might have modified some files without having the proper"
1945a81ca49Smrg      echo "tools for further handling them.  Check the 'README' file, it"
1955a81ca49Smrg      echo "often tells you about the needed prerequisites for installing"
1965a81ca49Smrg      echo "this package.  You may also peek at any GNU archive site, in"
1975a81ca49Smrg      echo "case some other package contains this missing '$1' program."
1985a81ca49Smrg      ;;
1995a81ca49Smrg  esac
2005a81ca49Smrg}
2015a81ca49Smrg
2025a81ca49Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2035a81ca49Smrg                       -e '2,$s/^/         /' >&2
2045a81ca49Smrg
2055a81ca49Smrg# Propagate the correct exit status (expected to be 127 for a program
2065a81ca49Smrg# not found, 63 for a program that failed due to version mismatch).
2075a81ca49Smrgexit $st
20832b578d3Smrg
20932b578d3Smrg# Local variables:
2100b0ce0bfSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
21132b578d3Smrg# time-stamp-start: "scriptversion="
21232b578d3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2130b0ce0bfSmrg# time-stamp-time-zone: "UTC0"
2142a51b5beSmrg# time-stamp-end: "; # UTC"
21532b578d3Smrg# End:
216