1af7c02bdSmrg#! /bin/sh
26c9573adSmrg# Common wrapper for a few potentially missing GNU programs.
3af7c02bdSmrg
46c9573adSmrgscriptversion=2018-03-07.03; # UTC
5af7c02bdSmrg
66c9573adSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
76c9573adSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8af7c02bdSmrg
9af7c02bdSmrg# This program is free software; you can redistribute it and/or modify
10af7c02bdSmrg# it under the terms of the GNU General Public License as published by
11af7c02bdSmrg# the Free Software Foundation; either version 2, or (at your option)
12af7c02bdSmrg# any later version.
13af7c02bdSmrg
14af7c02bdSmrg# This program is distributed in the hope that it will be useful,
15af7c02bdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16af7c02bdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17af7c02bdSmrg# GNU General Public License for more details.
18af7c02bdSmrg
19af7c02bdSmrg# You should have received a copy of the GNU General Public License
206c9573adSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21af7c02bdSmrg
22af7c02bdSmrg# As a special exception to the GNU General Public License, if you
23af7c02bdSmrg# distribute this file as part of a program that contains a
24af7c02bdSmrg# configuration script generated by Autoconf, you may include it under
25af7c02bdSmrg# the same distribution terms that you use for the rest of that program.
26af7c02bdSmrg
27af7c02bdSmrgif test $# -eq 0; then
286c9573adSmrg  echo 1>&2 "Try '$0 --help' for more information"
29af7c02bdSmrg  exit 1
30af7c02bdSmrgfi
31af7c02bdSmrg
326c9573adSmrgcase $1 in
33af7c02bdSmrg
346c9573adSmrg  --is-lightweight)
356c9573adSmrg    # Used by our autoconf macros to check whether the available missing
366c9573adSmrg    # script is modern enough.
376c9573adSmrg    exit 0
386c9573adSmrg    ;;
39af7c02bdSmrg
406c9573adSmrg  --run)
416c9573adSmrg    # Back-compat with the calling convention used by older automake.
426c9573adSmrg    shift
436c9573adSmrg    ;;
44af7c02bdSmrg
45af7c02bdSmrg  -h|--h|--he|--hel|--help)
46af7c02bdSmrg    echo "\
47af7c02bdSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48af7c02bdSmrg
496c9573adSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
506c9573adSmrgto PROGRAM being missing or too old.
51af7c02bdSmrg
52af7c02bdSmrgOptions:
53af7c02bdSmrg  -h, --help      display this help and exit
54af7c02bdSmrg  -v, --version   output version information and exit
55af7c02bdSmrg
56af7c02bdSmrgSupported PROGRAM values:
576c9573adSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
586c9573adSmrg  bison     yacc      flex         lex       help2man
59af7c02bdSmrg
606c9573adSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
616c9573adSmrg'g' are ignored when checking the name.
6281c81b28Smrg
63af7c02bdSmrgSend bug reports to <bug-automake@gnu.org>."
64af7c02bdSmrg    exit $?
65af7c02bdSmrg    ;;
66af7c02bdSmrg
67af7c02bdSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68af7c02bdSmrg    echo "missing $scriptversion (GNU Automake)"
69af7c02bdSmrg    exit $?
70af7c02bdSmrg    ;;
71af7c02bdSmrg
72af7c02bdSmrg  -*)
736c9573adSmrg    echo 1>&2 "$0: unknown '$1' option"
746c9573adSmrg    echo 1>&2 "Try '$0 --help' for more information"
75af7c02bdSmrg    exit 1
76af7c02bdSmrg    ;;
77af7c02bdSmrg
78af7c02bdSmrgesac
79af7c02bdSmrg
806c9573adSmrg# Run the given program, remember its exit status.
816c9573adSmrg"$@"; st=$?
826c9573adSmrg
836c9573adSmrg# If it succeeded, we are done.
846c9573adSmrgtest $st -eq 0 && exit 0
856c9573adSmrg
866c9573adSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
876c9573adSmrg# passed; such an option is passed most likely to detect whether the
886c9573adSmrg# program is present and works.
896c9573adSmrgcase $2 in --version|--help) exit $st;; esac
906c9573adSmrg
916c9573adSmrg# Exit code 63 means version mismatch.  This often happens when the user
926c9573adSmrg# tries to use an ancient version of a tool on a file that requires a
936c9573adSmrg# minimum version.
946c9573adSmrgif test $st -eq 63; then
956c9573adSmrg  msg="probably too old"
966c9573adSmrgelif test $st -eq 127; then
976c9573adSmrg  # Program was missing.
986c9573adSmrg  msg="missing on your system"
996c9573adSmrgelse
1006c9573adSmrg  # Program was found and executed, but failed.  Give up.
1016c9573adSmrg  exit $st
1026c9573adSmrgfi
103af7c02bdSmrg
1046c9573adSmrgperl_URL=https://www.perl.org/
1056c9573adSmrgflex_URL=https://github.com/westes/flex
1066c9573adSmrggnu_software_URL=https://www.gnu.org/software
1076c9573adSmrg
1086c9573adSmrgprogram_details ()
1096c9573adSmrg{
1106c9573adSmrg  case $1 in
1116c9573adSmrg    aclocal|automake)
1126c9573adSmrg      echo "The '$1' program is part of the GNU Automake package:"
1136c9573adSmrg      echo "<$gnu_software_URL/automake>"
1146c9573adSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1156c9573adSmrg      echo "<$gnu_software_URL/autoconf>"
1166c9573adSmrg      echo "<$gnu_software_URL/m4/>"
1176c9573adSmrg      echo "<$perl_URL>"
1186c9573adSmrg      ;;
1196c9573adSmrg    autoconf|autom4te|autoheader)
1206c9573adSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
1216c9573adSmrg      echo "<$gnu_software_URL/autoconf/>"
1226c9573adSmrg      echo "It also requires GNU m4 and Perl in order to run:"
1236c9573adSmrg      echo "<$gnu_software_URL/m4/>"
1246c9573adSmrg      echo "<$perl_URL>"
1256c9573adSmrg      ;;
1266c9573adSmrg  esac
1276c9573adSmrg}
1286c9573adSmrg
1296c9573adSmrggive_advice ()
1306c9573adSmrg{
1316c9573adSmrg  # Normalize program name to check for.
1326c9573adSmrg  normalized_program=`echo "$1" | sed '
1336c9573adSmrg    s/^gnu-//; t
1346c9573adSmrg    s/^gnu//; t
1356c9573adSmrg    s/^g//; t'`
1366c9573adSmrg
1376c9573adSmrg  printf '%s\n' "'$1' is $msg."
1386c9573adSmrg
1396c9573adSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1406c9573adSmrg  case $normalized_program in
1416c9573adSmrg    autoconf*)
1426c9573adSmrg      echo "You should only need it if you modified 'configure.ac',"
1436c9573adSmrg      echo "or m4 files included by it."
1446c9573adSmrg      program_details 'autoconf'
1456c9573adSmrg      ;;
1466c9573adSmrg    autoheader*)
1476c9573adSmrg      echo "You should only need it if you modified 'acconfig.h' or"
1486c9573adSmrg      echo "$configure_deps."
1496c9573adSmrg      program_details 'autoheader'
1506c9573adSmrg      ;;
1516c9573adSmrg    automake*)
1526c9573adSmrg      echo "You should only need it if you modified 'Makefile.am' or"
1536c9573adSmrg      echo "$configure_deps."
1546c9573adSmrg      program_details 'automake'
1556c9573adSmrg      ;;
1566c9573adSmrg    aclocal*)
1576c9573adSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
1586c9573adSmrg      echo "$configure_deps."
1596c9573adSmrg      program_details 'aclocal'
1606c9573adSmrg      ;;
1616c9573adSmrg   autom4te*)
1626c9573adSmrg      echo "You might have modified some maintainer files that require"
1636c9573adSmrg      echo "the 'autom4te' program to be rebuilt."
1646c9573adSmrg      program_details 'autom4te'
1656c9573adSmrg      ;;
1666c9573adSmrg    bison*|yacc*)
1676c9573adSmrg      echo "You should only need it if you modified a '.y' file."
1686c9573adSmrg      echo "You may want to install the GNU Bison package:"
1696c9573adSmrg      echo "<$gnu_software_URL/bison/>"
1706c9573adSmrg      ;;
1716c9573adSmrg    lex*|flex*)
1726c9573adSmrg      echo "You should only need it if you modified a '.l' file."
1736c9573adSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1746c9573adSmrg      echo "<$flex_URL>"
1756c9573adSmrg      ;;
1766c9573adSmrg    help2man*)
1776c9573adSmrg      echo "You should only need it if you modified a dependency" \
1786c9573adSmrg           "of a man page."
1796c9573adSmrg      echo "You may want to install the GNU Help2man package:"
1806c9573adSmrg      echo "<$gnu_software_URL/help2man/>"
1816c9573adSmrg    ;;
1826c9573adSmrg    makeinfo*)
1836c9573adSmrg      echo "You should only need it if you modified a '.texi' file, or"
1846c9573adSmrg      echo "any other file indirectly affecting the aspect of the manual."
1856c9573adSmrg      echo "You might want to install the Texinfo package:"
1866c9573adSmrg      echo "<$gnu_software_URL/texinfo/>"
1876c9573adSmrg      echo "The spurious makeinfo call might also be the consequence of"
1886c9573adSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1896c9573adSmrg      echo "want to install GNU make:"
1906c9573adSmrg      echo "<$gnu_software_URL/make/>"
1916c9573adSmrg      ;;
1926c9573adSmrg    *)
1936c9573adSmrg      echo "You might have modified some files without having the proper"
1946c9573adSmrg      echo "tools for further handling them.  Check the 'README' file, it"
1956c9573adSmrg      echo "often tells you about the needed prerequisites for installing"
1966c9573adSmrg      echo "this package.  You may also peek at any GNU archive site, in"
1976c9573adSmrg      echo "case some other package contains this missing '$1' program."
1986c9573adSmrg      ;;
1996c9573adSmrg  esac
2006c9573adSmrg}
2016c9573adSmrg
2026c9573adSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2036c9573adSmrg                       -e '2,$s/^/         /' >&2
2046c9573adSmrg
2056c9573adSmrg# Propagate the correct exit status (expected to be 127 for a program
2066c9573adSmrg# not found, 63 for a program that failed due to version mismatch).
2076c9573adSmrgexit $st
208af7c02bdSmrg
209af7c02bdSmrg# Local variables:
2106c9573adSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
211af7c02bdSmrg# time-stamp-start: "scriptversion="
212af7c02bdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2136c9573adSmrg# time-stamp-time-zone: "UTC0"
21481c81b28Smrg# time-stamp-end: "; # UTC"
215af7c02bdSmrg# End:
216