11abf7346Smrg#! /bin/sh
26d36ef34Smrg# Common wrapper for a few potentially missing GNU programs.
31abf7346Smrg
4a5a2a776Smrgscriptversion=2018-03-07.03; # UTC
51abf7346Smrg
6a5a2a776Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
76d36ef34Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
81abf7346Smrg
91abf7346Smrg# This program is free software; you can redistribute it and/or modify
101abf7346Smrg# it under the terms of the GNU General Public License as published by
111abf7346Smrg# the Free Software Foundation; either version 2, or (at your option)
121abf7346Smrg# any later version.
131abf7346Smrg
141abf7346Smrg# This program is distributed in the hope that it will be useful,
151abf7346Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
161abf7346Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
171abf7346Smrg# GNU General Public License for more details.
181abf7346Smrg
191abf7346Smrg# You should have received a copy of the GNU General Public License
20a5a2a776Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
211abf7346Smrg
221abf7346Smrg# As a special exception to the GNU General Public License, if you
231abf7346Smrg# distribute this file as part of a program that contains a
241abf7346Smrg# configuration script generated by Autoconf, you may include it under
251abf7346Smrg# the same distribution terms that you use for the rest of that program.
261abf7346Smrg
271abf7346Smrgif test $# -eq 0; then
286d36ef34Smrg  echo 1>&2 "Try '$0 --help' for more information"
291abf7346Smrg  exit 1
301abf7346Smrgfi
311abf7346Smrg
326d36ef34Smrgcase $1 in
331abf7346Smrg
346d36ef34Smrg  --is-lightweight)
356d36ef34Smrg    # Used by our autoconf macros to check whether the available missing
366d36ef34Smrg    # script is modern enough.
376d36ef34Smrg    exit 0
386d36ef34Smrg    ;;
391abf7346Smrg
406d36ef34Smrg  --run)
416d36ef34Smrg    # Back-compat with the calling convention used by older automake.
426d36ef34Smrg    shift
436d36ef34Smrg    ;;
441abf7346Smrg
451abf7346Smrg  -h|--h|--he|--hel|--help)
461abf7346Smrg    echo "\
471abf7346Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
481abf7346Smrg
496d36ef34SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
506d36ef34Smrgto PROGRAM being missing or too old.
511abf7346Smrg
521abf7346SmrgOptions:
531abf7346Smrg  -h, --help      display this help and exit
541abf7346Smrg  -v, --version   output version information and exit
551abf7346Smrg
561abf7346SmrgSupported PROGRAM values:
576d36ef34Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
586d36ef34Smrg  bison     yacc      flex         lex       help2man
591abf7346Smrg
606d36ef34SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
616d36ef34Smrg'g' are ignored when checking the name.
628b6d6341Smrg
631abf7346SmrgSend bug reports to <bug-automake@gnu.org>."
641abf7346Smrg    exit $?
651abf7346Smrg    ;;
661abf7346Smrg
671abf7346Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
681abf7346Smrg    echo "missing $scriptversion (GNU Automake)"
691abf7346Smrg    exit $?
701abf7346Smrg    ;;
711abf7346Smrg
721abf7346Smrg  -*)
736d36ef34Smrg    echo 1>&2 "$0: unknown '$1' option"
746d36ef34Smrg    echo 1>&2 "Try '$0 --help' for more information"
751abf7346Smrg    exit 1
761abf7346Smrg    ;;
771abf7346Smrg
781abf7346Smrgesac
791abf7346Smrg
806d36ef34Smrg# Run the given program, remember its exit status.
816d36ef34Smrg"$@"; st=$?
826d36ef34Smrg
836d36ef34Smrg# If it succeeded, we are done.
846d36ef34Smrgtest $st -eq 0 && exit 0
856d36ef34Smrg
866d36ef34Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
876d36ef34Smrg# passed; such an option is passed most likely to detect whether the
886d36ef34Smrg# program is present and works.
896d36ef34Smrgcase $2 in --version|--help) exit $st;; esac
906d36ef34Smrg
916d36ef34Smrg# Exit code 63 means version mismatch.  This often happens when the user
926d36ef34Smrg# tries to use an ancient version of a tool on a file that requires a
936d36ef34Smrg# minimum version.
946d36ef34Smrgif test $st -eq 63; then
956d36ef34Smrg  msg="probably too old"
966d36ef34Smrgelif test $st -eq 127; then
976d36ef34Smrg  # Program was missing.
986d36ef34Smrg  msg="missing on your system"
996d36ef34Smrgelse
1006d36ef34Smrg  # Program was found and executed, but failed.  Give up.
1016d36ef34Smrg  exit $st
1026d36ef34Smrgfi
1031abf7346Smrg
104a5a2a776Smrgperl_URL=https://www.perl.org/
105a5a2a776Smrgflex_URL=https://github.com/westes/flex
106a5a2a776Smrggnu_software_URL=https://www.gnu.org/software
1076d36ef34Smrg
1086d36ef34Smrgprogram_details ()
1096d36ef34Smrg{
1106d36ef34Smrg  case $1 in
1116d36ef34Smrg    aclocal|automake)
1126d36ef34Smrg      echo "The '$1' program is part of the GNU Automake package:"
1136d36ef34Smrg      echo "<$gnu_software_URL/automake>"
1146d36ef34Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1156d36ef34Smrg      echo "<$gnu_software_URL/autoconf>"
1166d36ef34Smrg      echo "<$gnu_software_URL/m4/>"
1176d36ef34Smrg      echo "<$perl_URL>"
1186d36ef34Smrg      ;;
1196d36ef34Smrg    autoconf|autom4te|autoheader)
1206d36ef34Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1216d36ef34Smrg      echo "<$gnu_software_URL/autoconf/>"
1226d36ef34Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1236d36ef34Smrg      echo "<$gnu_software_URL/m4/>"
1246d36ef34Smrg      echo "<$perl_URL>"
1256d36ef34Smrg      ;;
1266d36ef34Smrg  esac
1276d36ef34Smrg}
1286d36ef34Smrg
1296d36ef34Smrggive_advice ()
1306d36ef34Smrg{
1316d36ef34Smrg  # Normalize program name to check for.
1326d36ef34Smrg  normalized_program=`echo "$1" | sed '
1336d36ef34Smrg    s/^gnu-//; t
1346d36ef34Smrg    s/^gnu//; t
1356d36ef34Smrg    s/^g//; t'`
1366d36ef34Smrg
1376d36ef34Smrg  printf '%s\n' "'$1' is $msg."
1386d36ef34Smrg
1396d36ef34Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1406d36ef34Smrg  case $normalized_program in
1416d36ef34Smrg    autoconf*)
1426d36ef34Smrg      echo "You should only need it if you modified 'configure.ac',"
1436d36ef34Smrg      echo "or m4 files included by it."
1446d36ef34Smrg      program_details 'autoconf'
1456d36ef34Smrg      ;;
1466d36ef34Smrg    autoheader*)
1476d36ef34Smrg      echo "You should only need it if you modified 'acconfig.h' or"
1486d36ef34Smrg      echo "$configure_deps."
1496d36ef34Smrg      program_details 'autoheader'
1506d36ef34Smrg      ;;
1516d36ef34Smrg    automake*)
1526d36ef34Smrg      echo "You should only need it if you modified 'Makefile.am' or"
1536d36ef34Smrg      echo "$configure_deps."
1546d36ef34Smrg      program_details 'automake'
1556d36ef34Smrg      ;;
1566d36ef34Smrg    aclocal*)
1576d36ef34Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
1586d36ef34Smrg      echo "$configure_deps."
1596d36ef34Smrg      program_details 'aclocal'
1606d36ef34Smrg      ;;
1616d36ef34Smrg   autom4te*)
1626d36ef34Smrg      echo "You might have modified some maintainer files that require"
163da4a0041Smrg      echo "the 'autom4te' program to be rebuilt."
1646d36ef34Smrg      program_details 'autom4te'
1656d36ef34Smrg      ;;
1666d36ef34Smrg    bison*|yacc*)
1676d36ef34Smrg      echo "You should only need it if you modified a '.y' file."
1686d36ef34Smrg      echo "You may want to install the GNU Bison package:"
1696d36ef34Smrg      echo "<$gnu_software_URL/bison/>"
1706d36ef34Smrg      ;;
1716d36ef34Smrg    lex*|flex*)
1726d36ef34Smrg      echo "You should only need it if you modified a '.l' file."
1736d36ef34Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1746d36ef34Smrg      echo "<$flex_URL>"
1756d36ef34Smrg      ;;
1766d36ef34Smrg    help2man*)
1776d36ef34Smrg      echo "You should only need it if you modified a dependency" \
1786d36ef34Smrg           "of a man page."
1796d36ef34Smrg      echo "You may want to install the GNU Help2man package:"
1806d36ef34Smrg      echo "<$gnu_software_URL/help2man/>"
1816d36ef34Smrg    ;;
1826d36ef34Smrg    makeinfo*)
1836d36ef34Smrg      echo "You should only need it if you modified a '.texi' file, or"
1846d36ef34Smrg      echo "any other file indirectly affecting the aspect of the manual."
1856d36ef34Smrg      echo "You might want to install the Texinfo package:"
1866d36ef34Smrg      echo "<$gnu_software_URL/texinfo/>"
1876d36ef34Smrg      echo "The spurious makeinfo call might also be the consequence of"
1886d36ef34Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1896d36ef34Smrg      echo "want to install GNU make:"
1906d36ef34Smrg      echo "<$gnu_software_URL/make/>"
1916d36ef34Smrg      ;;
1926d36ef34Smrg    *)
1936d36ef34Smrg      echo "You might have modified some files without having the proper"
1946d36ef34Smrg      echo "tools for further handling them.  Check the 'README' file, it"
1956d36ef34Smrg      echo "often tells you about the needed prerequisites for installing"
1966d36ef34Smrg      echo "this package.  You may also peek at any GNU archive site, in"
1976d36ef34Smrg      echo "case some other package contains this missing '$1' program."
1986d36ef34Smrg      ;;
1996d36ef34Smrg  esac
2006d36ef34Smrg}
2016d36ef34Smrg
2026d36ef34Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2036d36ef34Smrg                       -e '2,$s/^/         /' >&2
2046d36ef34Smrg
2056d36ef34Smrg# Propagate the correct exit status (expected to be 127 for a program
2066d36ef34Smrg# not found, 63 for a program that failed due to version mismatch).
2076d36ef34Smrgexit $st
2081abf7346Smrg
2091abf7346Smrg# Local variables:
210a5a2a776Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2111abf7346Smrg# time-stamp-start: "scriptversion="
2121abf7346Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213a5a2a776Smrg# time-stamp-time-zone: "UTC0"
2148b6d6341Smrg# time-stamp-end: "; # UTC"
2151abf7346Smrg# End:
216