1335e815aSmrg#! /bin/sh
20cfee914Smrg# Common wrapper for a few potentially missing GNU programs.
3f4959950Smrg
40cfee914Smrgscriptversion=2018-03-07.03; # UTC
5f4959950Smrg
60cfee914Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
70cfee914Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8335e815aSmrg
9335e815aSmrg# This program is free software; you can redistribute it and/or modify
10335e815aSmrg# it under the terms of the GNU General Public License as published by
11335e815aSmrg# the Free Software Foundation; either version 2, or (at your option)
12335e815aSmrg# any later version.
13335e815aSmrg
14335e815aSmrg# This program is distributed in the hope that it will be useful,
15335e815aSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16335e815aSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17335e815aSmrg# GNU General Public License for more details.
18335e815aSmrg
19335e815aSmrg# You should have received a copy of the GNU General Public License
200cfee914Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21335e815aSmrg
22335e815aSmrg# As a special exception to the GNU General Public License, if you
23335e815aSmrg# distribute this file as part of a program that contains a
24335e815aSmrg# configuration script generated by Autoconf, you may include it under
25335e815aSmrg# the same distribution terms that you use for the rest of that program.
26335e815aSmrg
27335e815aSmrgif test $# -eq 0; then
280cfee914Smrg  echo 1>&2 "Try '$0 --help' for more information"
29335e815aSmrg  exit 1
30335e815aSmrgfi
31335e815aSmrg
320cfee914Smrgcase $1 in
33335e815aSmrg
340cfee914Smrg  --is-lightweight)
350cfee914Smrg    # Used by our autoconf macros to check whether the available missing
360cfee914Smrg    # script is modern enough.
370cfee914Smrg    exit 0
380cfee914Smrg    ;;
39f4959950Smrg
400cfee914Smrg  --run)
410cfee914Smrg    # Back-compat with the calling convention used by older automake.
420cfee914Smrg    shift
430cfee914Smrg    ;;
44335e815aSmrg
45335e815aSmrg  -h|--h|--he|--hel|--help)
46335e815aSmrg    echo "\
47335e815aSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48335e815aSmrg
490cfee914SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
500cfee914Smrgto PROGRAM being missing or too old.
51335e815aSmrg
52335e815aSmrgOptions:
53335e815aSmrg  -h, --help      display this help and exit
54335e815aSmrg  -v, --version   output version information and exit
55335e815aSmrg
56335e815aSmrgSupported PROGRAM values:
570cfee914Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
580cfee914Smrg  bison     yacc      flex         lex       help2man
59f4959950Smrg
600cfee914SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
610cfee914Smrg'g' are ignored when checking the name.
62f4959950Smrg
63f4959950SmrgSend bug reports to <bug-automake@gnu.org>."
64f4959950Smrg    exit $?
65335e815aSmrg    ;;
66335e815aSmrg
67335e815aSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68f4959950Smrg    echo "missing $scriptversion (GNU Automake)"
69f4959950Smrg    exit $?
70335e815aSmrg    ;;
71335e815aSmrg
72335e815aSmrg  -*)
730cfee914Smrg    echo 1>&2 "$0: unknown '$1' option"
740cfee914Smrg    echo 1>&2 "Try '$0 --help' for more information"
75335e815aSmrg    exit 1
76335e815aSmrg    ;;
77335e815aSmrg
78f4959950Smrgesac
79f4959950Smrg
800cfee914Smrg# Run the given program, remember its exit status.
810cfee914Smrg"$@"; st=$?
820cfee914Smrg
830cfee914Smrg# If it succeeded, we are done.
840cfee914Smrgtest $st -eq 0 && exit 0
850cfee914Smrg
860cfee914Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
870cfee914Smrg# passed; such an option is passed most likely to detect whether the
880cfee914Smrg# program is present and works.
890cfee914Smrgcase $2 in --version|--help) exit $st;; esac
900cfee914Smrg
910cfee914Smrg# Exit code 63 means version mismatch.  This often happens when the user
920cfee914Smrg# tries to use an ancient version of a tool on a file that requires a
930cfee914Smrg# minimum version.
940cfee914Smrgif test $st -eq 63; then
950cfee914Smrg  msg="probably too old"
960cfee914Smrgelif test $st -eq 127; then
970cfee914Smrg  # Program was missing.
980cfee914Smrg  msg="missing on your system"
990cfee914Smrgelse
1000cfee914Smrg  # Program was found and executed, but failed.  Give up.
1010cfee914Smrg  exit $st
1020cfee914Smrgfi
103335e815aSmrg
1040cfee914Smrgperl_URL=https://www.perl.org/
1050cfee914Smrgflex_URL=https://github.com/westes/flex
1060cfee914Smrggnu_software_URL=https://www.gnu.org/software
1070cfee914Smrg
1080cfee914Smrgprogram_details ()
1090cfee914Smrg{
1100cfee914Smrg  case $1 in
1110cfee914Smrg    aclocal|automake)
1120cfee914Smrg      echo "The '$1' program is part of the GNU Automake package:"
1130cfee914Smrg      echo "<$gnu_software_URL/automake>"
1140cfee914Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1150cfee914Smrg      echo "<$gnu_software_URL/autoconf>"
1160cfee914Smrg      echo "<$gnu_software_URL/m4/>"
1170cfee914Smrg      echo "<$perl_URL>"
1180cfee914Smrg      ;;
1190cfee914Smrg    autoconf|autom4te|autoheader)
1200cfee914Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1210cfee914Smrg      echo "<$gnu_software_URL/autoconf/>"
1220cfee914Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1230cfee914Smrg      echo "<$gnu_software_URL/m4/>"
1240cfee914Smrg      echo "<$perl_URL>"
1250cfee914Smrg      ;;
1260cfee914Smrg  esac
1270cfee914Smrg}
1280cfee914Smrg
1290cfee914Smrggive_advice ()
1300cfee914Smrg{
1310cfee914Smrg  # Normalize program name to check for.
1320cfee914Smrg  normalized_program=`echo "$1" | sed '
1330cfee914Smrg    s/^gnu-//; t
1340cfee914Smrg    s/^gnu//; t
1350cfee914Smrg    s/^g//; t'`
1360cfee914Smrg
1370cfee914Smrg  printf '%s\n' "'$1' is $msg."
1380cfee914Smrg
1390cfee914Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1400cfee914Smrg  case $normalized_program in
1410cfee914Smrg    autoconf*)
1420cfee914Smrg      echo "You should only need it if you modified 'configure.ac',"
1430cfee914Smrg      echo "or m4 files included by it."
1440cfee914Smrg      program_details 'autoconf'
1450cfee914Smrg      ;;
1460cfee914Smrg    autoheader*)
1470cfee914Smrg      echo "You should only need it if you modified 'acconfig.h' or"
1480cfee914Smrg      echo "$configure_deps."
1490cfee914Smrg      program_details 'autoheader'
1500cfee914Smrg      ;;
1510cfee914Smrg    automake*)
1520cfee914Smrg      echo "You should only need it if you modified 'Makefile.am' or"
1530cfee914Smrg      echo "$configure_deps."
1540cfee914Smrg      program_details 'automake'
1550cfee914Smrg      ;;
1560cfee914Smrg    aclocal*)
1570cfee914Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
1580cfee914Smrg      echo "$configure_deps."
1590cfee914Smrg      program_details 'aclocal'
1600cfee914Smrg      ;;
1610cfee914Smrg   autom4te*)
1620cfee914Smrg      echo "You might have modified some maintainer files that require"
1630cfee914Smrg      echo "the 'autom4te' program to be rebuilt."
1640cfee914Smrg      program_details 'autom4te'
1650cfee914Smrg      ;;
1660cfee914Smrg    bison*|yacc*)
1670cfee914Smrg      echo "You should only need it if you modified a '.y' file."
1680cfee914Smrg      echo "You may want to install the GNU Bison package:"
1690cfee914Smrg      echo "<$gnu_software_URL/bison/>"
1700cfee914Smrg      ;;
1710cfee914Smrg    lex*|flex*)
1720cfee914Smrg      echo "You should only need it if you modified a '.l' file."
1730cfee914Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1740cfee914Smrg      echo "<$flex_URL>"
1750cfee914Smrg      ;;
1760cfee914Smrg    help2man*)
1770cfee914Smrg      echo "You should only need it if you modified a dependency" \
1780cfee914Smrg           "of a man page."
1790cfee914Smrg      echo "You may want to install the GNU Help2man package:"
1800cfee914Smrg      echo "<$gnu_software_URL/help2man/>"
1810cfee914Smrg    ;;
1820cfee914Smrg    makeinfo*)
1830cfee914Smrg      echo "You should only need it if you modified a '.texi' file, or"
1840cfee914Smrg      echo "any other file indirectly affecting the aspect of the manual."
1850cfee914Smrg      echo "You might want to install the Texinfo package:"
1860cfee914Smrg      echo "<$gnu_software_URL/texinfo/>"
1870cfee914Smrg      echo "The spurious makeinfo call might also be the consequence of"
1880cfee914Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1890cfee914Smrg      echo "want to install GNU make:"
1900cfee914Smrg      echo "<$gnu_software_URL/make/>"
1910cfee914Smrg      ;;
1920cfee914Smrg    *)
1930cfee914Smrg      echo "You might have modified some files without having the proper"
1940cfee914Smrg      echo "tools for further handling them.  Check the 'README' file, it"
1950cfee914Smrg      echo "often tells you about the needed prerequisites for installing"
1960cfee914Smrg      echo "this package.  You may also peek at any GNU archive site, in"
1970cfee914Smrg      echo "case some other package contains this missing '$1' program."
1980cfee914Smrg      ;;
1990cfee914Smrg  esac
2000cfee914Smrg}
2010cfee914Smrg
2020cfee914Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2030cfee914Smrg                       -e '2,$s/^/         /' >&2
2040cfee914Smrg
2050cfee914Smrg# Propagate the correct exit status (expected to be 127 for a program
2060cfee914Smrg# not found, 63 for a program that failed due to version mismatch).
2070cfee914Smrgexit $st
208f4959950Smrg
209f4959950Smrg# Local variables:
2100cfee914Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
211f4959950Smrg# time-stamp-start: "scriptversion="
212f4959950Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2130cfee914Smrg# time-stamp-time-zone: "UTC0"
214f4959950Smrg# time-stamp-end: "; # UTC"
215f4959950Smrg# End:
216