150806d53Smrg#! /bin/sh
24a8d91dcSmrg# Common wrapper for a few potentially missing GNU programs.
350806d53Smrg
4e9f7eabcSmrgscriptversion=2018-03-07.03; # UTC
550806d53Smrg
6e9f7eabcSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
74a8d91dcSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
850806d53Smrg
950806d53Smrg# This program is free software; you can redistribute it and/or modify
1050806d53Smrg# it under the terms of the GNU General Public License as published by
1150806d53Smrg# the Free Software Foundation; either version 2, or (at your option)
1250806d53Smrg# any later version.
1350806d53Smrg
1450806d53Smrg# This program is distributed in the hope that it will be useful,
1550806d53Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1650806d53Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1750806d53Smrg# GNU General Public License for more details.
1850806d53Smrg
1950806d53Smrg# You should have received a copy of the GNU General Public License
20e9f7eabcSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2150806d53Smrg
2250806d53Smrg# As a special exception to the GNU General Public License, if you
2350806d53Smrg# distribute this file as part of a program that contains a
2450806d53Smrg# configuration script generated by Autoconf, you may include it under
2550806d53Smrg# the same distribution terms that you use for the rest of that program.
2650806d53Smrg
2750806d53Smrgif test $# -eq 0; then
284a8d91dcSmrg  echo 1>&2 "Try '$0 --help' for more information"
2950806d53Smrg  exit 1
3050806d53Smrgfi
3150806d53Smrg
324a8d91dcSmrgcase $1 in
3350806d53Smrg
344a8d91dcSmrg  --is-lightweight)
354a8d91dcSmrg    # Used by our autoconf macros to check whether the available missing
364a8d91dcSmrg    # script is modern enough.
374a8d91dcSmrg    exit 0
384a8d91dcSmrg    ;;
3950806d53Smrg
404a8d91dcSmrg  --run)
414a8d91dcSmrg    # Back-compat with the calling convention used by older automake.
424a8d91dcSmrg    shift
434a8d91dcSmrg    ;;
4450806d53Smrg
4550806d53Smrg  -h|--h|--he|--hel|--help)
4650806d53Smrg    echo "\
4750806d53Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4850806d53Smrg
494a8d91dcSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
504a8d91dcSmrgto PROGRAM being missing or too old.
5150806d53Smrg
5250806d53SmrgOptions:
5350806d53Smrg  -h, --help      display this help and exit
5450806d53Smrg  -v, --version   output version information and exit
5550806d53Smrg
5650806d53SmrgSupported PROGRAM values:
574a8d91dcSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
584a8d91dcSmrg  bison     yacc      flex         lex       help2man
5950806d53Smrg
604a8d91dcSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
614a8d91dcSmrg'g' are ignored when checking the name.
62a73423d7Smrg
6350806d53SmrgSend bug reports to <bug-automake@gnu.org>."
6450806d53Smrg    exit $?
6550806d53Smrg    ;;
6650806d53Smrg
6750806d53Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6850806d53Smrg    echo "missing $scriptversion (GNU Automake)"
6950806d53Smrg    exit $?
7050806d53Smrg    ;;
7150806d53Smrg
7250806d53Smrg  -*)
734a8d91dcSmrg    echo 1>&2 "$0: unknown '$1' option"
744a8d91dcSmrg    echo 1>&2 "Try '$0 --help' for more information"
7550806d53Smrg    exit 1
7650806d53Smrg    ;;
7750806d53Smrg
7850806d53Smrgesac
7950806d53Smrg
804a8d91dcSmrg# Run the given program, remember its exit status.
814a8d91dcSmrg"$@"; st=$?
824a8d91dcSmrg
834a8d91dcSmrg# If it succeeded, we are done.
844a8d91dcSmrgtest $st -eq 0 && exit 0
854a8d91dcSmrg
864a8d91dcSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
874a8d91dcSmrg# passed; such an option is passed most likely to detect whether the
884a8d91dcSmrg# program is present and works.
894a8d91dcSmrgcase $2 in --version|--help) exit $st;; esac
904a8d91dcSmrg
914a8d91dcSmrg# Exit code 63 means version mismatch.  This often happens when the user
924a8d91dcSmrg# tries to use an ancient version of a tool on a file that requires a
934a8d91dcSmrg# minimum version.
944a8d91dcSmrgif test $st -eq 63; then
954a8d91dcSmrg  msg="probably too old"
964a8d91dcSmrgelif test $st -eq 127; then
974a8d91dcSmrg  # Program was missing.
984a8d91dcSmrg  msg="missing on your system"
994a8d91dcSmrgelse
1004a8d91dcSmrg  # Program was found and executed, but failed.  Give up.
1014a8d91dcSmrg  exit $st
1024a8d91dcSmrgfi
10350806d53Smrg
104e9f7eabcSmrgperl_URL=https://www.perl.org/
105e9f7eabcSmrgflex_URL=https://github.com/westes/flex
106e9f7eabcSmrggnu_software_URL=https://www.gnu.org/software
1074a8d91dcSmrg
1084a8d91dcSmrgprogram_details ()
1094a8d91dcSmrg{
1104a8d91dcSmrg  case $1 in
1114a8d91dcSmrg    aclocal|automake)
1124a8d91dcSmrg      echo "The '$1' program is part of the GNU Automake package:"
1134a8d91dcSmrg      echo "<$gnu_software_URL/automake>"
1144a8d91dcSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1154a8d91dcSmrg      echo "<$gnu_software_URL/autoconf>"
1164a8d91dcSmrg      echo "<$gnu_software_URL/m4/>"
1174a8d91dcSmrg      echo "<$perl_URL>"
1184a8d91dcSmrg      ;;
1194a8d91dcSmrg    autoconf|autom4te|autoheader)
1204a8d91dcSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
1214a8d91dcSmrg      echo "<$gnu_software_URL/autoconf/>"
1224a8d91dcSmrg      echo "It also requires GNU m4 and Perl in order to run:"
1234a8d91dcSmrg      echo "<$gnu_software_URL/m4/>"
1244a8d91dcSmrg      echo "<$perl_URL>"
1254a8d91dcSmrg      ;;
1264a8d91dcSmrg  esac
1274a8d91dcSmrg}
1284a8d91dcSmrg
1294a8d91dcSmrggive_advice ()
1304a8d91dcSmrg{
1314a8d91dcSmrg  # Normalize program name to check for.
1324a8d91dcSmrg  normalized_program=`echo "$1" | sed '
1334a8d91dcSmrg    s/^gnu-//; t
1344a8d91dcSmrg    s/^gnu//; t
1354a8d91dcSmrg    s/^g//; t'`
1364a8d91dcSmrg
1374a8d91dcSmrg  printf '%s\n' "'$1' is $msg."
1384a8d91dcSmrg
1394a8d91dcSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1404a8d91dcSmrg  case $normalized_program in
1414a8d91dcSmrg    autoconf*)
1424a8d91dcSmrg      echo "You should only need it if you modified 'configure.ac',"
1434a8d91dcSmrg      echo "or m4 files included by it."
1444a8d91dcSmrg      program_details 'autoconf'
1454a8d91dcSmrg      ;;
1464a8d91dcSmrg    autoheader*)
1474a8d91dcSmrg      echo "You should only need it if you modified 'acconfig.h' or"
1484a8d91dcSmrg      echo "$configure_deps."
1494a8d91dcSmrg      program_details 'autoheader'
1504a8d91dcSmrg      ;;
1514a8d91dcSmrg    automake*)
1524a8d91dcSmrg      echo "You should only need it if you modified 'Makefile.am' or"
1534a8d91dcSmrg      echo "$configure_deps."
1544a8d91dcSmrg      program_details 'automake'
1554a8d91dcSmrg      ;;
1564a8d91dcSmrg    aclocal*)
1574a8d91dcSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
1584a8d91dcSmrg      echo "$configure_deps."
1594a8d91dcSmrg      program_details 'aclocal'
1604a8d91dcSmrg      ;;
1614a8d91dcSmrg   autom4te*)
1624a8d91dcSmrg      echo "You might have modified some maintainer files that require"
1634a8d91dcSmrg      echo "the 'autom4te' program to be rebuilt."
1644a8d91dcSmrg      program_details 'autom4te'
1654a8d91dcSmrg      ;;
1664a8d91dcSmrg    bison*|yacc*)
1674a8d91dcSmrg      echo "You should only need it if you modified a '.y' file."
1684a8d91dcSmrg      echo "You may want to install the GNU Bison package:"
1694a8d91dcSmrg      echo "<$gnu_software_URL/bison/>"
1704a8d91dcSmrg      ;;
1714a8d91dcSmrg    lex*|flex*)
1724a8d91dcSmrg      echo "You should only need it if you modified a '.l' file."
1734a8d91dcSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1744a8d91dcSmrg      echo "<$flex_URL>"
1754a8d91dcSmrg      ;;
1764a8d91dcSmrg    help2man*)
1774a8d91dcSmrg      echo "You should only need it if you modified a dependency" \
1784a8d91dcSmrg           "of a man page."
1794a8d91dcSmrg      echo "You may want to install the GNU Help2man package:"
1804a8d91dcSmrg      echo "<$gnu_software_URL/help2man/>"
18150806d53Smrg    ;;
1824a8d91dcSmrg    makeinfo*)
1834a8d91dcSmrg      echo "You should only need it if you modified a '.texi' file, or"
1844a8d91dcSmrg      echo "any other file indirectly affecting the aspect of the manual."
1854a8d91dcSmrg      echo "You might want to install the Texinfo package:"
1864a8d91dcSmrg      echo "<$gnu_software_URL/texinfo/>"
1874a8d91dcSmrg      echo "The spurious makeinfo call might also be the consequence of"
1884a8d91dcSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1894a8d91dcSmrg      echo "want to install GNU make:"
1904a8d91dcSmrg      echo "<$gnu_software_URL/make/>"
1914a8d91dcSmrg      ;;
1924a8d91dcSmrg    *)
1934a8d91dcSmrg      echo "You might have modified some files without having the proper"
1944a8d91dcSmrg      echo "tools for further handling them.  Check the 'README' file, it"
1954a8d91dcSmrg      echo "often tells you about the needed prerequisites for installing"
1964a8d91dcSmrg      echo "this package.  You may also peek at any GNU archive site, in"
1974a8d91dcSmrg      echo "case some other package contains this missing '$1' program."
1984a8d91dcSmrg      ;;
1994a8d91dcSmrg  esac
2004a8d91dcSmrg}
2014a8d91dcSmrg
2024a8d91dcSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2034a8d91dcSmrg                       -e '2,$s/^/         /' >&2
2044a8d91dcSmrg
2054a8d91dcSmrg# Propagate the correct exit status (expected to be 127 for a program
2064a8d91dcSmrg# not found, 63 for a program that failed due to version mismatch).
2074a8d91dcSmrgexit $st
20850806d53Smrg
20950806d53Smrg# Local variables:
210e9f7eabcSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
21150806d53Smrg# time-stamp-start: "scriptversion="
21250806d53Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213e9f7eabcSmrg# time-stamp-time-zone: "UTC0"
214a73423d7Smrg# time-stamp-end: "; # UTC"
21550806d53Smrg# End:
216