19fe995a9Smrg#! /bin/sh
29d794632Smrg# Common wrapper for a few potentially missing GNU programs.
39fe995a9Smrg
4c048b52eSmrgscriptversion=2018-03-07.03; # UTC
59fe995a9Smrg
6c048b52eSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
79d794632Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
89fe995a9Smrg
99fe995a9Smrg# This program is free software; you can redistribute it and/or modify
109fe995a9Smrg# it under the terms of the GNU General Public License as published by
119fe995a9Smrg# the Free Software Foundation; either version 2, or (at your option)
129fe995a9Smrg# any later version.
139fe995a9Smrg
149fe995a9Smrg# This program is distributed in the hope that it will be useful,
159fe995a9Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
169fe995a9Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
179fe995a9Smrg# GNU General Public License for more details.
189fe995a9Smrg
199fe995a9Smrg# You should have received a copy of the GNU General Public License
20c048b52eSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
219fe995a9Smrg
229fe995a9Smrg# As a special exception to the GNU General Public License, if you
239fe995a9Smrg# distribute this file as part of a program that contains a
249fe995a9Smrg# configuration script generated by Autoconf, you may include it under
259fe995a9Smrg# the same distribution terms that you use for the rest of that program.
269fe995a9Smrg
279fe995a9Smrgif test $# -eq 0; then
289d794632Smrg  echo 1>&2 "Try '$0 --help' for more information"
299fe995a9Smrg  exit 1
309fe995a9Smrgfi
319fe995a9Smrg
329d794632Smrgcase $1 in
339fe995a9Smrg
349d794632Smrg  --is-lightweight)
359d794632Smrg    # Used by our autoconf macros to check whether the available missing
369d794632Smrg    # script is modern enough.
379d794632Smrg    exit 0
389d794632Smrg    ;;
399fe995a9Smrg
409d794632Smrg  --run)
419d794632Smrg    # Back-compat with the calling convention used by older automake.
429d794632Smrg    shift
439d794632Smrg    ;;
449fe995a9Smrg
459fe995a9Smrg  -h|--h|--he|--hel|--help)
469fe995a9Smrg    echo "\
479fe995a9Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
489fe995a9Smrg
499d794632SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
509d794632Smrgto PROGRAM being missing or too old.
519fe995a9Smrg
529fe995a9SmrgOptions:
539fe995a9Smrg  -h, --help      display this help and exit
549fe995a9Smrg  -v, --version   output version information and exit
559fe995a9Smrg
569fe995a9SmrgSupported PROGRAM values:
579d794632Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
589d794632Smrg  bison     yacc      flex         lex       help2man
599fe995a9Smrg
609d794632SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
619d794632Smrg'g' are ignored when checking the name.
62b62cc08cSmrg
639fe995a9SmrgSend bug reports to <bug-automake@gnu.org>."
649fe995a9Smrg    exit $?
659fe995a9Smrg    ;;
669fe995a9Smrg
679fe995a9Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
689fe995a9Smrg    echo "missing $scriptversion (GNU Automake)"
699fe995a9Smrg    exit $?
709fe995a9Smrg    ;;
719fe995a9Smrg
729fe995a9Smrg  -*)
739d794632Smrg    echo 1>&2 "$0: unknown '$1' option"
749d794632Smrg    echo 1>&2 "Try '$0 --help' for more information"
759fe995a9Smrg    exit 1
769fe995a9Smrg    ;;
779fe995a9Smrg
789fe995a9Smrgesac
799fe995a9Smrg
809d794632Smrg# Run the given program, remember its exit status.
819d794632Smrg"$@"; st=$?
829d794632Smrg
839d794632Smrg# If it succeeded, we are done.
849d794632Smrgtest $st -eq 0 && exit 0
859d794632Smrg
869d794632Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
879d794632Smrg# passed; such an option is passed most likely to detect whether the
889d794632Smrg# program is present and works.
899d794632Smrgcase $2 in --version|--help) exit $st;; esac
909d794632Smrg
919d794632Smrg# Exit code 63 means version mismatch.  This often happens when the user
929d794632Smrg# tries to use an ancient version of a tool on a file that requires a
939d794632Smrg# minimum version.
949d794632Smrgif test $st -eq 63; then
959d794632Smrg  msg="probably too old"
969d794632Smrgelif test $st -eq 127; then
979d794632Smrg  # Program was missing.
989d794632Smrg  msg="missing on your system"
999d794632Smrgelse
1009d794632Smrg  # Program was found and executed, but failed.  Give up.
1019d794632Smrg  exit $st
1029d794632Smrgfi
1039fe995a9Smrg
104c048b52eSmrgperl_URL=https://www.perl.org/
105c048b52eSmrgflex_URL=https://github.com/westes/flex
106c048b52eSmrggnu_software_URL=https://www.gnu.org/software
1079d794632Smrg
1089d794632Smrgprogram_details ()
1099d794632Smrg{
1109d794632Smrg  case $1 in
1119d794632Smrg    aclocal|automake)
1129d794632Smrg      echo "The '$1' program is part of the GNU Automake package:"
1139d794632Smrg      echo "<$gnu_software_URL/automake>"
1149d794632Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1159d794632Smrg      echo "<$gnu_software_URL/autoconf>"
1169d794632Smrg      echo "<$gnu_software_URL/m4/>"
1179d794632Smrg      echo "<$perl_URL>"
1189d794632Smrg      ;;
1199d794632Smrg    autoconf|autom4te|autoheader)
1209d794632Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1219d794632Smrg      echo "<$gnu_software_URL/autoconf/>"
1229d794632Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1239d794632Smrg      echo "<$gnu_software_URL/m4/>"
1249d794632Smrg      echo "<$perl_URL>"
1259d794632Smrg      ;;
1269d794632Smrg  esac
1279d794632Smrg}
1289d794632Smrg
1299d794632Smrggive_advice ()
1309d794632Smrg{
1319d794632Smrg  # Normalize program name to check for.
1329d794632Smrg  normalized_program=`echo "$1" | sed '
1339d794632Smrg    s/^gnu-//; t
1349d794632Smrg    s/^gnu//; t
1359d794632Smrg    s/^g//; t'`
1369d794632Smrg
1379d794632Smrg  printf '%s\n' "'$1' is $msg."
1389d794632Smrg
1399d794632Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1409d794632Smrg  case $normalized_program in
1419d794632Smrg    autoconf*)
1429d794632Smrg      echo "You should only need it if you modified 'configure.ac',"
1439d794632Smrg      echo "or m4 files included by it."
1449d794632Smrg      program_details 'autoconf'
1459d794632Smrg      ;;
1469d794632Smrg    autoheader*)
1479d794632Smrg      echo "You should only need it if you modified 'acconfig.h' or"
1489d794632Smrg      echo "$configure_deps."
1499d794632Smrg      program_details 'autoheader'
1509d794632Smrg      ;;
1519d794632Smrg    automake*)
1529d794632Smrg      echo "You should only need it if you modified 'Makefile.am' or"
1539d794632Smrg      echo "$configure_deps."
1549d794632Smrg      program_details 'automake'
1559d794632Smrg      ;;
1569d794632Smrg    aclocal*)
1579d794632Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
1589d794632Smrg      echo "$configure_deps."
1599d794632Smrg      program_details 'aclocal'
1609d794632Smrg      ;;
1619d794632Smrg   autom4te*)
1629d794632Smrg      echo "You might have modified some maintainer files that require"
163e8ac26b0Smrg      echo "the 'autom4te' program to be rebuilt."
1649d794632Smrg      program_details 'autom4te'
1659d794632Smrg      ;;
1669d794632Smrg    bison*|yacc*)
1679d794632Smrg      echo "You should only need it if you modified a '.y' file."
1689d794632Smrg      echo "You may want to install the GNU Bison package:"
1699d794632Smrg      echo "<$gnu_software_URL/bison/>"
1709d794632Smrg      ;;
1719d794632Smrg    lex*|flex*)
1729d794632Smrg      echo "You should only need it if you modified a '.l' file."
1739d794632Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1749d794632Smrg      echo "<$flex_URL>"
1759d794632Smrg      ;;
1769d794632Smrg    help2man*)
1779d794632Smrg      echo "You should only need it if you modified a dependency" \
1789d794632Smrg           "of a man page."
1799d794632Smrg      echo "You may want to install the GNU Help2man package:"
1809d794632Smrg      echo "<$gnu_software_URL/help2man/>"
1819d794632Smrg    ;;
1829d794632Smrg    makeinfo*)
1839d794632Smrg      echo "You should only need it if you modified a '.texi' file, or"
1849d794632Smrg      echo "any other file indirectly affecting the aspect of the manual."
1859d794632Smrg      echo "You might want to install the Texinfo package:"
1869d794632Smrg      echo "<$gnu_software_URL/texinfo/>"
1879d794632Smrg      echo "The spurious makeinfo call might also be the consequence of"
1889d794632Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1899d794632Smrg      echo "want to install GNU make:"
1909d794632Smrg      echo "<$gnu_software_URL/make/>"
1919d794632Smrg      ;;
1929d794632Smrg    *)
1939d794632Smrg      echo "You might have modified some files without having the proper"
1949d794632Smrg      echo "tools for further handling them.  Check the 'README' file, it"
1959d794632Smrg      echo "often tells you about the needed prerequisites for installing"
1969d794632Smrg      echo "this package.  You may also peek at any GNU archive site, in"
1979d794632Smrg      echo "case some other package contains this missing '$1' program."
1989d794632Smrg      ;;
1999d794632Smrg  esac
2009d794632Smrg}
2019d794632Smrg
2029d794632Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2039d794632Smrg                       -e '2,$s/^/         /' >&2
2049d794632Smrg
2059d794632Smrg# Propagate the correct exit status (expected to be 127 for a program
2069d794632Smrg# not found, 63 for a program that failed due to version mismatch).
2079d794632Smrgexit $st
2089fe995a9Smrg
2099fe995a9Smrg# Local variables:
210c048b52eSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2119fe995a9Smrg# time-stamp-start: "scriptversion="
2129fe995a9Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213c048b52eSmrg# time-stamp-time-zone: "UTC0"
214b62cc08cSmrg# time-stamp-end: "; # UTC"
2159fe995a9Smrg# End:
216