14a041c5bSmacallan#! /bin/sh
20a392d7eSmrg# Common wrapper for a few potentially missing GNU programs.
34a041c5bSmacallan
48fc2d0c6Smrgscriptversion=2018-03-07.03; # UTC
54a041c5bSmacallan
68fc2d0c6Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
70a392d7eSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
84a041c5bSmacallan
94a041c5bSmacallan# This program is free software; you can redistribute it and/or modify
104a041c5bSmacallan# it under the terms of the GNU General Public License as published by
114a041c5bSmacallan# the Free Software Foundation; either version 2, or (at your option)
124a041c5bSmacallan# any later version.
134a041c5bSmacallan
144a041c5bSmacallan# This program is distributed in the hope that it will be useful,
154a041c5bSmacallan# but WITHOUT ANY WARRANTY; without even the implied warranty of
164a041c5bSmacallan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
174a041c5bSmacallan# GNU General Public License for more details.
184a041c5bSmacallan
194a041c5bSmacallan# You should have received a copy of the GNU General Public License
208fc2d0c6Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
214a041c5bSmacallan
224a041c5bSmacallan# As a special exception to the GNU General Public License, if you
234a041c5bSmacallan# distribute this file as part of a program that contains a
244a041c5bSmacallan# configuration script generated by Autoconf, you may include it under
254a041c5bSmacallan# the same distribution terms that you use for the rest of that program.
264a041c5bSmacallan
274a041c5bSmacallanif test $# -eq 0; then
2854b44505Smrg  echo 1>&2 "Try '$0 --help' for more information"
294a041c5bSmacallan  exit 1
304a041c5bSmacallanfi
314a041c5bSmacallan
320a392d7eSmrgcase $1 in
334a041c5bSmacallan
340a392d7eSmrg  --is-lightweight)
350a392d7eSmrg    # Used by our autoconf macros to check whether the available missing
360a392d7eSmrg    # script is modern enough.
370a392d7eSmrg    exit 0
380a392d7eSmrg    ;;
394a041c5bSmacallan
400a392d7eSmrg  --run)
410a392d7eSmrg    # Back-compat with the calling convention used by older automake.
420a392d7eSmrg    shift
430a392d7eSmrg    ;;
444a041c5bSmacallan
454a041c5bSmacallan  -h|--h|--he|--hel|--help)
464a041c5bSmacallan    echo "\
474a041c5bSmacallan$0 [OPTION]... PROGRAM [ARGUMENT]...
484a041c5bSmacallan
490a392d7eSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
500a392d7eSmrgto PROGRAM being missing or too old.
514a041c5bSmacallan
524a041c5bSmacallanOptions:
534a041c5bSmacallan  -h, --help      display this help and exit
544a041c5bSmacallan  -v, --version   output version information and exit
554a041c5bSmacallan
564a041c5bSmacallanSupported PROGRAM values:
570a392d7eSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
580a392d7eSmrg  bison     yacc      flex         lex       help2man
5954b44505Smrg
6054b44505SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6154b44505Smrg'g' are ignored when checking the name.
624a041c5bSmacallan
634a041c5bSmacallanSend bug reports to <bug-automake@gnu.org>."
644a041c5bSmacallan    exit $?
654a041c5bSmacallan    ;;
664a041c5bSmacallan
674a041c5bSmacallan  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
684a041c5bSmacallan    echo "missing $scriptversion (GNU Automake)"
694a041c5bSmacallan    exit $?
704a041c5bSmacallan    ;;
714a041c5bSmacallan
724a041c5bSmacallan  -*)
730a392d7eSmrg    echo 1>&2 "$0: unknown '$1' option"
7454b44505Smrg    echo 1>&2 "Try '$0 --help' for more information"
754a041c5bSmacallan    exit 1
764a041c5bSmacallan    ;;
774a041c5bSmacallan
784a041c5bSmacallanesac
794a041c5bSmacallan
800a392d7eSmrg# Run the given program, remember its exit status.
810a392d7eSmrg"$@"; st=$?
820a392d7eSmrg
830a392d7eSmrg# If it succeeded, we are done.
840a392d7eSmrgtest $st -eq 0 && exit 0
850a392d7eSmrg
860a392d7eSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
870a392d7eSmrg# passed; such an option is passed most likely to detect whether the
880a392d7eSmrg# program is present and works.
890a392d7eSmrgcase $2 in --version|--help) exit $st;; esac
900a392d7eSmrg
910a392d7eSmrg# Exit code 63 means version mismatch.  This often happens when the user
920a392d7eSmrg# tries to use an ancient version of a tool on a file that requires a
930a392d7eSmrg# minimum version.
940a392d7eSmrgif test $st -eq 63; then
950a392d7eSmrg  msg="probably too old"
960a392d7eSmrgelif test $st -eq 127; then
970a392d7eSmrg  # Program was missing.
980a392d7eSmrg  msg="missing on your system"
990a392d7eSmrgelse
1000a392d7eSmrg  # Program was found and executed, but failed.  Give up.
1010a392d7eSmrg  exit $st
1020a392d7eSmrgfi
1034a041c5bSmacallan
1048fc2d0c6Smrgperl_URL=https://www.perl.org/
1058fc2d0c6Smrgflex_URL=https://github.com/westes/flex
1068fc2d0c6Smrggnu_software_URL=https://www.gnu.org/software
1070a392d7eSmrg
1080a392d7eSmrgprogram_details ()
1090a392d7eSmrg{
1100a392d7eSmrg  case $1 in
1110a392d7eSmrg    aclocal|automake)
1120a392d7eSmrg      echo "The '$1' program is part of the GNU Automake package:"
1130a392d7eSmrg      echo "<$gnu_software_URL/automake>"
1140a392d7eSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1150a392d7eSmrg      echo "<$gnu_software_URL/autoconf>"
1160a392d7eSmrg      echo "<$gnu_software_URL/m4/>"
1170a392d7eSmrg      echo "<$perl_URL>"
1180a392d7eSmrg      ;;
1190a392d7eSmrg    autoconf|autom4te|autoheader)
1200a392d7eSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
1210a392d7eSmrg      echo "<$gnu_software_URL/autoconf/>"
1220a392d7eSmrg      echo "It also requires GNU m4 and Perl in order to run:"
1230a392d7eSmrg      echo "<$gnu_software_URL/m4/>"
1240a392d7eSmrg      echo "<$perl_URL>"
1250a392d7eSmrg      ;;
1260a392d7eSmrg  esac
1270a392d7eSmrg}
1280a392d7eSmrg
1290a392d7eSmrggive_advice ()
1300a392d7eSmrg{
1310a392d7eSmrg  # Normalize program name to check for.
1320a392d7eSmrg  normalized_program=`echo "$1" | sed '
1330a392d7eSmrg    s/^gnu-//; t
1340a392d7eSmrg    s/^gnu//; t
1350a392d7eSmrg    s/^g//; t'`
1360a392d7eSmrg
1370a392d7eSmrg  printf '%s\n' "'$1' is $msg."
1380a392d7eSmrg
1390a392d7eSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1400a392d7eSmrg  case $normalized_program in
1410a392d7eSmrg    autoconf*)
1420a392d7eSmrg      echo "You should only need it if you modified 'configure.ac',"
1430a392d7eSmrg      echo "or m4 files included by it."
1440a392d7eSmrg      program_details 'autoconf'
1450a392d7eSmrg      ;;
1460a392d7eSmrg    autoheader*)
1470a392d7eSmrg      echo "You should only need it if you modified 'acconfig.h' or"
1480a392d7eSmrg      echo "$configure_deps."
1490a392d7eSmrg      program_details 'autoheader'
1500a392d7eSmrg      ;;
1510a392d7eSmrg    automake*)
1520a392d7eSmrg      echo "You should only need it if you modified 'Makefile.am' or"
1530a392d7eSmrg      echo "$configure_deps."
1540a392d7eSmrg      program_details 'automake'
1550a392d7eSmrg      ;;
1560a392d7eSmrg    aclocal*)
1570a392d7eSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
1580a392d7eSmrg      echo "$configure_deps."
1590a392d7eSmrg      program_details 'aclocal'
1600a392d7eSmrg      ;;
1610a392d7eSmrg   autom4te*)
1620a392d7eSmrg      echo "You might have modified some maintainer files that require"
1630a392d7eSmrg      echo "the 'autom4te' program to be rebuilt."
1640a392d7eSmrg      program_details 'autom4te'
1650a392d7eSmrg      ;;
1660a392d7eSmrg    bison*|yacc*)
1670a392d7eSmrg      echo "You should only need it if you modified a '.y' file."
1680a392d7eSmrg      echo "You may want to install the GNU Bison package:"
1690a392d7eSmrg      echo "<$gnu_software_URL/bison/>"
1700a392d7eSmrg      ;;
1710a392d7eSmrg    lex*|flex*)
1720a392d7eSmrg      echo "You should only need it if you modified a '.l' file."
1730a392d7eSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1740a392d7eSmrg      echo "<$flex_URL>"
1750a392d7eSmrg      ;;
1760a392d7eSmrg    help2man*)
1770a392d7eSmrg      echo "You should only need it if you modified a dependency" \
1780a392d7eSmrg           "of a man page."
1790a392d7eSmrg      echo "You may want to install the GNU Help2man package:"
1800a392d7eSmrg      echo "<$gnu_software_URL/help2man/>"
1814a041c5bSmacallan    ;;
1820a392d7eSmrg    makeinfo*)
1830a392d7eSmrg      echo "You should only need it if you modified a '.texi' file, or"
1840a392d7eSmrg      echo "any other file indirectly affecting the aspect of the manual."
1850a392d7eSmrg      echo "You might want to install the Texinfo package:"
1860a392d7eSmrg      echo "<$gnu_software_URL/texinfo/>"
1870a392d7eSmrg      echo "The spurious makeinfo call might also be the consequence of"
1880a392d7eSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1890a392d7eSmrg      echo "want to install GNU make:"
1900a392d7eSmrg      echo "<$gnu_software_URL/make/>"
1910a392d7eSmrg      ;;
1920a392d7eSmrg    *)
1930a392d7eSmrg      echo "You might have modified some files without having the proper"
1940a392d7eSmrg      echo "tools for further handling them.  Check the 'README' file, it"
1950a392d7eSmrg      echo "often tells you about the needed prerequisites for installing"
1960a392d7eSmrg      echo "this package.  You may also peek at any GNU archive site, in"
1970a392d7eSmrg      echo "case some other package contains this missing '$1' program."
1980a392d7eSmrg      ;;
1990a392d7eSmrg  esac
2000a392d7eSmrg}
2010a392d7eSmrg
2020a392d7eSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2030a392d7eSmrg                       -e '2,$s/^/         /' >&2
2040a392d7eSmrg
2050a392d7eSmrg# Propagate the correct exit status (expected to be 127 for a program
2060a392d7eSmrg# not found, 63 for a program that failed due to version mismatch).
2070a392d7eSmrgexit $st
2084a041c5bSmacallan
2094a041c5bSmacallan# Local variables:
2108fc2d0c6Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2114a041c5bSmacallan# time-stamp-start: "scriptversion="
2124a041c5bSmacallan# time-stamp-format: "%:y-%02m-%02d.%02H"
2138fc2d0c6Smrg# time-stamp-time-zone: "UTC0"
21454b44505Smrg# time-stamp-end: "; # UTC"
2154a041c5bSmacallan# End:
216