13eed67faSmbalmer#! /bin/sh
21a9c160aSmrg# Common wrapper for a few potentially missing GNU programs.
33eed67faSmbalmer
41a9c160aSmrgscriptversion=2018-03-07.03; # UTC
53eed67faSmbalmer
6621f50c3Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
71a9c160aSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
83eed67faSmbalmer
93eed67faSmbalmer# This program is free software; you can redistribute it and/or modify
103eed67faSmbalmer# it under the terms of the GNU General Public License as published by
113eed67faSmbalmer# the Free Software Foundation; either version 2, or (at your option)
123eed67faSmbalmer# any later version.
133eed67faSmbalmer
143eed67faSmbalmer# This program is distributed in the hope that it will be useful,
153eed67faSmbalmer# but WITHOUT ANY WARRANTY; without even the implied warranty of
163eed67faSmbalmer# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
173eed67faSmbalmer# GNU General Public License for more details.
183eed67faSmbalmer
193eed67faSmbalmer# You should have received a copy of the GNU General Public License
201a9c160aSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
213eed67faSmbalmer
223eed67faSmbalmer# As a special exception to the GNU General Public License, if you
233eed67faSmbalmer# distribute this file as part of a program that contains a
243eed67faSmbalmer# configuration script generated by Autoconf, you may include it under
253eed67faSmbalmer# the same distribution terms that you use for the rest of that program.
263eed67faSmbalmer
273eed67faSmbalmerif test $# -eq 0; then
281a9c160aSmrg  echo 1>&2 "Try '$0 --help' for more information"
293eed67faSmbalmer  exit 1
303eed67faSmbalmerfi
313eed67faSmbalmer
321a9c160aSmrgcase $1 in
333eed67faSmbalmer
341a9c160aSmrg  --is-lightweight)
351a9c160aSmrg    # Used by our autoconf macros to check whether the available missing
361a9c160aSmrg    # script is modern enough.
371a9c160aSmrg    exit 0
381a9c160aSmrg    ;;
393eed67faSmbalmer
401a9c160aSmrg  --run)
411a9c160aSmrg    # Back-compat with the calling convention used by older automake.
421a9c160aSmrg    shift
431a9c160aSmrg    ;;
443eed67faSmbalmer
453eed67faSmbalmer  -h|--h|--he|--hel|--help)
463eed67faSmbalmer    echo "\
473eed67faSmbalmer$0 [OPTION]... PROGRAM [ARGUMENT]...
483eed67faSmbalmer
491a9c160aSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
501a9c160aSmrgto PROGRAM being missing or too old.
513eed67faSmbalmer
523eed67faSmbalmerOptions:
533eed67faSmbalmer  -h, --help      display this help and exit
543eed67faSmbalmer  -v, --version   output version information and exit
553eed67faSmbalmer
563eed67faSmbalmerSupported PROGRAM values:
571a9c160aSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
581a9c160aSmrg  bison     yacc      flex         lex       help2man
593eed67faSmbalmer
601a9c160aSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
611a9c160aSmrg'g' are ignored when checking the name.
62dc407927Smrg
633eed67faSmbalmerSend bug reports to <bug-automake@gnu.org>."
643eed67faSmbalmer    exit $?
653eed67faSmbalmer    ;;
663eed67faSmbalmer
673eed67faSmbalmer  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
683eed67faSmbalmer    echo "missing $scriptversion (GNU Automake)"
693eed67faSmbalmer    exit $?
703eed67faSmbalmer    ;;
713eed67faSmbalmer
723eed67faSmbalmer  -*)
731a9c160aSmrg    echo 1>&2 "$0: unknown '$1' option"
741a9c160aSmrg    echo 1>&2 "Try '$0 --help' for more information"
753eed67faSmbalmer    exit 1
763eed67faSmbalmer    ;;
773eed67faSmbalmer
783eed67faSmbalmeresac
793eed67faSmbalmer
801a9c160aSmrg# Run the given program, remember its exit status.
811a9c160aSmrg"$@"; st=$?
821a9c160aSmrg
831a9c160aSmrg# If it succeeded, we are done.
841a9c160aSmrgtest $st -eq 0 && exit 0
851a9c160aSmrg
861a9c160aSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
871a9c160aSmrg# passed; such an option is passed most likely to detect whether the
881a9c160aSmrg# program is present and works.
891a9c160aSmrgcase $2 in --version|--help) exit $st;; esac
901a9c160aSmrg
911a9c160aSmrg# Exit code 63 means version mismatch.  This often happens when the user
921a9c160aSmrg# tries to use an ancient version of a tool on a file that requires a
931a9c160aSmrg# minimum version.
941a9c160aSmrgif test $st -eq 63; then
951a9c160aSmrg  msg="probably too old"
961a9c160aSmrgelif test $st -eq 127; then
971a9c160aSmrg  # Program was missing.
981a9c160aSmrg  msg="missing on your system"
991a9c160aSmrgelse
1001a9c160aSmrg  # Program was found and executed, but failed.  Give up.
1011a9c160aSmrg  exit $st
1021a9c160aSmrgfi
1033eed67faSmbalmer
1041a9c160aSmrgperl_URL=https://www.perl.org/
1051a9c160aSmrgflex_URL=https://github.com/westes/flex
1061a9c160aSmrggnu_software_URL=https://www.gnu.org/software
1071a9c160aSmrg
1081a9c160aSmrgprogram_details ()
1091a9c160aSmrg{
1101a9c160aSmrg  case $1 in
1111a9c160aSmrg    aclocal|automake)
1121a9c160aSmrg      echo "The '$1' program is part of the GNU Automake package:"
1131a9c160aSmrg      echo "<$gnu_software_URL/automake>"
1141a9c160aSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1151a9c160aSmrg      echo "<$gnu_software_URL/autoconf>"
1161a9c160aSmrg      echo "<$gnu_software_URL/m4/>"
1171a9c160aSmrg      echo "<$perl_URL>"
1181a9c160aSmrg      ;;
1191a9c160aSmrg    autoconf|autom4te|autoheader)
1201a9c160aSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
1211a9c160aSmrg      echo "<$gnu_software_URL/autoconf/>"
1221a9c160aSmrg      echo "It also requires GNU m4 and Perl in order to run:"
1231a9c160aSmrg      echo "<$gnu_software_URL/m4/>"
1241a9c160aSmrg      echo "<$perl_URL>"
1251a9c160aSmrg      ;;
1261a9c160aSmrg  esac
1271a9c160aSmrg}
1281a9c160aSmrg
1291a9c160aSmrggive_advice ()
1301a9c160aSmrg{
1311a9c160aSmrg  # Normalize program name to check for.
1321a9c160aSmrg  normalized_program=`echo "$1" | sed '
1331a9c160aSmrg    s/^gnu-//; t
1341a9c160aSmrg    s/^gnu//; t
1351a9c160aSmrg    s/^g//; t'`
1361a9c160aSmrg
1371a9c160aSmrg  printf '%s\n' "'$1' is $msg."
1381a9c160aSmrg
1391a9c160aSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1401a9c160aSmrg  case $normalized_program in
1411a9c160aSmrg    autoconf*)
1421a9c160aSmrg      echo "You should only need it if you modified 'configure.ac',"
1431a9c160aSmrg      echo "or m4 files included by it."
1441a9c160aSmrg      program_details 'autoconf'
1451a9c160aSmrg      ;;
1461a9c160aSmrg    autoheader*)
1471a9c160aSmrg      echo "You should only need it if you modified 'acconfig.h' or"
1481a9c160aSmrg      echo "$configure_deps."
1491a9c160aSmrg      program_details 'autoheader'
1501a9c160aSmrg      ;;
1511a9c160aSmrg    automake*)
1521a9c160aSmrg      echo "You should only need it if you modified 'Makefile.am' or"
1531a9c160aSmrg      echo "$configure_deps."
1541a9c160aSmrg      program_details 'automake'
1551a9c160aSmrg      ;;
1561a9c160aSmrg    aclocal*)
1571a9c160aSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
1581a9c160aSmrg      echo "$configure_deps."
1591a9c160aSmrg      program_details 'aclocal'
1601a9c160aSmrg      ;;
1611a9c160aSmrg   autom4te*)
1621a9c160aSmrg      echo "You might have modified some maintainer files that require"
1631a9c160aSmrg      echo "the 'autom4te' program to be rebuilt."
1641a9c160aSmrg      program_details 'autom4te'
1651a9c160aSmrg      ;;
1661a9c160aSmrg    bison*|yacc*)
1671a9c160aSmrg      echo "You should only need it if you modified a '.y' file."
1681a9c160aSmrg      echo "You may want to install the GNU Bison package:"
1691a9c160aSmrg      echo "<$gnu_software_URL/bison/>"
1701a9c160aSmrg      ;;
1711a9c160aSmrg    lex*|flex*)
1721a9c160aSmrg      echo "You should only need it if you modified a '.l' file."
1731a9c160aSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1741a9c160aSmrg      echo "<$flex_URL>"
1751a9c160aSmrg      ;;
1761a9c160aSmrg    help2man*)
1771a9c160aSmrg      echo "You should only need it if you modified a dependency" \
1781a9c160aSmrg           "of a man page."
1791a9c160aSmrg      echo "You may want to install the GNU Help2man package:"
1801a9c160aSmrg      echo "<$gnu_software_URL/help2man/>"
1813eed67faSmbalmer    ;;
1821a9c160aSmrg    makeinfo*)
1831a9c160aSmrg      echo "You should only need it if you modified a '.texi' file, or"
1841a9c160aSmrg      echo "any other file indirectly affecting the aspect of the manual."
1851a9c160aSmrg      echo "You might want to install the Texinfo package:"
1861a9c160aSmrg      echo "<$gnu_software_URL/texinfo/>"
1871a9c160aSmrg      echo "The spurious makeinfo call might also be the consequence of"
1881a9c160aSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1891a9c160aSmrg      echo "want to install GNU make:"
1901a9c160aSmrg      echo "<$gnu_software_URL/make/>"
1911a9c160aSmrg      ;;
1921a9c160aSmrg    *)
1931a9c160aSmrg      echo "You might have modified some files without having the proper"
1941a9c160aSmrg      echo "tools for further handling them.  Check the 'README' file, it"
1951a9c160aSmrg      echo "often tells you about the needed prerequisites for installing"
1961a9c160aSmrg      echo "this package.  You may also peek at any GNU archive site, in"
1971a9c160aSmrg      echo "case some other package contains this missing '$1' program."
1981a9c160aSmrg      ;;
1991a9c160aSmrg  esac
2001a9c160aSmrg}
2011a9c160aSmrg
2021a9c160aSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2031a9c160aSmrg                       -e '2,$s/^/         /' >&2
2041a9c160aSmrg
2051a9c160aSmrg# Propagate the correct exit status (expected to be 127 for a program
2061a9c160aSmrg# not found, 63 for a program that failed due to version mismatch).
2071a9c160aSmrgexit $st
2083eed67faSmbalmer
2093eed67faSmbalmer# Local variables:
2101a9c160aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2113eed67faSmbalmer# time-stamp-start: "scriptversion="
2123eed67faSmbalmer# time-stamp-format: "%:y-%02m-%02d.%02H"
2131a9c160aSmrg# time-stamp-time-zone: "UTC0"
214dc407927Smrg# time-stamp-end: "; # UTC"
2153eed67faSmbalmer# End:
216