18108eb18Smrg#! /bin/sh
28a355152Smrg# Common wrapper for a few potentially missing GNU programs.
31a650d1eSmrg
499c4c48aSmrgscriptversion=2018-03-07.03; # UTC
51a650d1eSmrg
699c4c48aSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
78a355152Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
88108eb18Smrg
98108eb18Smrg# This program is free software; you can redistribute it and/or modify
108108eb18Smrg# it under the terms of the GNU General Public License as published by
118108eb18Smrg# the Free Software Foundation; either version 2, or (at your option)
128108eb18Smrg# any later version.
138108eb18Smrg
148108eb18Smrg# This program is distributed in the hope that it will be useful,
158108eb18Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
168108eb18Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
178108eb18Smrg# GNU General Public License for more details.
188108eb18Smrg
198108eb18Smrg# You should have received a copy of the GNU General Public License
2099c4c48aSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
218108eb18Smrg
228108eb18Smrg# As a special exception to the GNU General Public License, if you
238108eb18Smrg# distribute this file as part of a program that contains a
248108eb18Smrg# configuration script generated by Autoconf, you may include it under
258108eb18Smrg# the same distribution terms that you use for the rest of that program.
268108eb18Smrg
278108eb18Smrgif test $# -eq 0; then
288a355152Smrg  echo 1>&2 "Try '$0 --help' for more information"
298108eb18Smrg  exit 1
308108eb18Smrgfi
318108eb18Smrg
328a355152Smrgcase $1 in
338108eb18Smrg
348a355152Smrg  --is-lightweight)
358a355152Smrg    # Used by our autoconf macros to check whether the available missing
368a355152Smrg    # script is modern enough.
378a355152Smrg    exit 0
388a355152Smrg    ;;
391a650d1eSmrg
408a355152Smrg  --run)
418a355152Smrg    # Back-compat with the calling convention used by older automake.
428a355152Smrg    shift
438a355152Smrg    ;;
448108eb18Smrg
458108eb18Smrg  -h|--h|--he|--hel|--help)
468108eb18Smrg    echo "\
478108eb18Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
488108eb18Smrg
498a355152SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
508a355152Smrgto PROGRAM being missing or too old.
518108eb18Smrg
528108eb18SmrgOptions:
538108eb18Smrg  -h, --help      display this help and exit
548108eb18Smrg  -v, --version   output version information and exit
558108eb18Smrg
568108eb18SmrgSupported PROGRAM values:
578a355152Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
588a355152Smrg  bison     yacc      flex         lex       help2man
591a650d1eSmrg
608a355152SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
618a355152Smrg'g' are ignored when checking the name.
621a650d1eSmrg
631a650d1eSmrgSend bug reports to <bug-automake@gnu.org>."
641a650d1eSmrg    exit $?
658108eb18Smrg    ;;
668108eb18Smrg
678108eb18Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
681a650d1eSmrg    echo "missing $scriptversion (GNU Automake)"
691a650d1eSmrg    exit $?
708108eb18Smrg    ;;
718108eb18Smrg
728108eb18Smrg  -*)
738a355152Smrg    echo 1>&2 "$0: unknown '$1' option"
748a355152Smrg    echo 1>&2 "Try '$0 --help' for more information"
758108eb18Smrg    exit 1
768108eb18Smrg    ;;
778108eb18Smrg
781a650d1eSmrgesac
791a650d1eSmrg
808a355152Smrg# Run the given program, remember its exit status.
818a355152Smrg"$@"; st=$?
828a355152Smrg
838a355152Smrg# If it succeeded, we are done.
848a355152Smrgtest $st -eq 0 && exit 0
858a355152Smrg
868a355152Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
878a355152Smrg# passed; such an option is passed most likely to detect whether the
888a355152Smrg# program is present and works.
898a355152Smrgcase $2 in --version|--help) exit $st;; esac
908a355152Smrg
918a355152Smrg# Exit code 63 means version mismatch.  This often happens when the user
928a355152Smrg# tries to use an ancient version of a tool on a file that requires a
938a355152Smrg# minimum version.
948a355152Smrgif test $st -eq 63; then
958a355152Smrg  msg="probably too old"
968a355152Smrgelif test $st -eq 127; then
978a355152Smrg  # Program was missing.
988a355152Smrg  msg="missing on your system"
998a355152Smrgelse
1008a355152Smrg  # Program was found and executed, but failed.  Give up.
1018a355152Smrg  exit $st
1028a355152Smrgfi
1038108eb18Smrg
10499c4c48aSmrgperl_URL=https://www.perl.org/
10599c4c48aSmrgflex_URL=https://github.com/westes/flex
10699c4c48aSmrggnu_software_URL=https://www.gnu.org/software
1078a355152Smrg
1088a355152Smrgprogram_details ()
1098a355152Smrg{
1108a355152Smrg  case $1 in
1118a355152Smrg    aclocal|automake)
1128a355152Smrg      echo "The '$1' program is part of the GNU Automake package:"
1138a355152Smrg      echo "<$gnu_software_URL/automake>"
1148a355152Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1158a355152Smrg      echo "<$gnu_software_URL/autoconf>"
1168a355152Smrg      echo "<$gnu_software_URL/m4/>"
1178a355152Smrg      echo "<$perl_URL>"
1188a355152Smrg      ;;
1198a355152Smrg    autoconf|autom4te|autoheader)
1208a355152Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1218a355152Smrg      echo "<$gnu_software_URL/autoconf/>"
1228a355152Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1238a355152Smrg      echo "<$gnu_software_URL/m4/>"
1248a355152Smrg      echo "<$perl_URL>"
1258a355152Smrg      ;;
1268a355152Smrg  esac
1278a355152Smrg}
1288a355152Smrg
1298a355152Smrggive_advice ()
1308a355152Smrg{
1318a355152Smrg  # Normalize program name to check for.
1328a355152Smrg  normalized_program=`echo "$1" | sed '
1338a355152Smrg    s/^gnu-//; t
1348a355152Smrg    s/^gnu//; t
1358a355152Smrg    s/^g//; t'`
1368a355152Smrg
1378a355152Smrg  printf '%s\n' "'$1' is $msg."
1388a355152Smrg
1398a355152Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1408a355152Smrg  case $normalized_program in
1418a355152Smrg    autoconf*)
1428a355152Smrg      echo "You should only need it if you modified 'configure.ac',"
1438a355152Smrg      echo "or m4 files included by it."
1448a355152Smrg      program_details 'autoconf'
1458a355152Smrg      ;;
1468a355152Smrg    autoheader*)
1478a355152Smrg      echo "You should only need it if you modified 'acconfig.h' or"
1488a355152Smrg      echo "$configure_deps."
1498a355152Smrg      program_details 'autoheader'
1508a355152Smrg      ;;
1518a355152Smrg    automake*)
1528a355152Smrg      echo "You should only need it if you modified 'Makefile.am' or"
1538a355152Smrg      echo "$configure_deps."
1548a355152Smrg      program_details 'automake'
1558a355152Smrg      ;;
1568a355152Smrg    aclocal*)
1578a355152Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
1588a355152Smrg      echo "$configure_deps."
1598a355152Smrg      program_details 'aclocal'
1608a355152Smrg      ;;
1618a355152Smrg   autom4te*)
1628a355152Smrg      echo "You might have modified some maintainer files that require"
1638a355152Smrg      echo "the 'autom4te' program to be rebuilt."
1648a355152Smrg      program_details 'autom4te'
1658a355152Smrg      ;;
1668a355152Smrg    bison*|yacc*)
1678a355152Smrg      echo "You should only need it if you modified a '.y' file."
1688a355152Smrg      echo "You may want to install the GNU Bison package:"
1698a355152Smrg      echo "<$gnu_software_URL/bison/>"
1708a355152Smrg      ;;
1718a355152Smrg    lex*|flex*)
1728a355152Smrg      echo "You should only need it if you modified a '.l' file."
1738a355152Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1748a355152Smrg      echo "<$flex_URL>"
1758a355152Smrg      ;;
1768a355152Smrg    help2man*)
1778a355152Smrg      echo "You should only need it if you modified a dependency" \
1788a355152Smrg           "of a man page."
1798a355152Smrg      echo "You may want to install the GNU Help2man package:"
1808a355152Smrg      echo "<$gnu_software_URL/help2man/>"
1818a355152Smrg    ;;
1828a355152Smrg    makeinfo*)
1838a355152Smrg      echo "You should only need it if you modified a '.texi' file, or"
1848a355152Smrg      echo "any other file indirectly affecting the aspect of the manual."
1858a355152Smrg      echo "You might want to install the Texinfo package:"
1868a355152Smrg      echo "<$gnu_software_URL/texinfo/>"
1878a355152Smrg      echo "The spurious makeinfo call might also be the consequence of"
1888a355152Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1898a355152Smrg      echo "want to install GNU make:"
1908a355152Smrg      echo "<$gnu_software_URL/make/>"
1918a355152Smrg      ;;
1928a355152Smrg    *)
1938a355152Smrg      echo "You might have modified some files without having the proper"
1948a355152Smrg      echo "tools for further handling them.  Check the 'README' file, it"
1958a355152Smrg      echo "often tells you about the needed prerequisites for installing"
1968a355152Smrg      echo "this package.  You may also peek at any GNU archive site, in"
1978a355152Smrg      echo "case some other package contains this missing '$1' program."
1988a355152Smrg      ;;
1998a355152Smrg  esac
2008a355152Smrg}
2018a355152Smrg
2028a355152Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2038a355152Smrg                       -e '2,$s/^/         /' >&2
2048a355152Smrg
2058a355152Smrg# Propagate the correct exit status (expected to be 127 for a program
2068a355152Smrg# not found, 63 for a program that failed due to version mismatch).
2078a355152Smrgexit $st
2081a650d1eSmrg
2091a650d1eSmrg# Local variables:
21099c4c48aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2111a650d1eSmrg# time-stamp-start: "scriptversion="
2121a650d1eSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21399c4c48aSmrg# time-stamp-time-zone: "UTC0"
2141a650d1eSmrg# time-stamp-end: "; # UTC"
2151a650d1eSmrg# End:
216