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