176888252Smrg#! /bin/sh
29586ba5aSmrg# Common wrapper for a few potentially missing GNU programs.
376888252Smrg
40814a2baSmrgscriptversion=2018-03-07.03; # UTC
576888252Smrg
60814a2baSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
79586ba5aSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
876888252Smrg
976888252Smrg# This program is free software; you can redistribute it and/or modify
1076888252Smrg# it under the terms of the GNU General Public License as published by
1176888252Smrg# the Free Software Foundation; either version 2, or (at your option)
1276888252Smrg# any later version.
1376888252Smrg
1476888252Smrg# This program is distributed in the hope that it will be useful,
1576888252Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1676888252Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1776888252Smrg# GNU General Public License for more details.
1876888252Smrg
1976888252Smrg# You should have received a copy of the GNU General Public License
200814a2baSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2176888252Smrg
2276888252Smrg# As a special exception to the GNU General Public License, if you
2376888252Smrg# distribute this file as part of a program that contains a
2476888252Smrg# configuration script generated by Autoconf, you may include it under
2576888252Smrg# the same distribution terms that you use for the rest of that program.
2676888252Smrg
2776888252Smrgif test $# -eq 0; then
289586ba5aSmrg  echo 1>&2 "Try '$0 --help' for more information"
2976888252Smrg  exit 1
3076888252Smrgfi
3176888252Smrg
329586ba5aSmrgcase $1 in
3376888252Smrg
349586ba5aSmrg  --is-lightweight)
359586ba5aSmrg    # Used by our autoconf macros to check whether the available missing
369586ba5aSmrg    # script is modern enough.
379586ba5aSmrg    exit 0
389586ba5aSmrg    ;;
3976888252Smrg
409586ba5aSmrg  --run)
419586ba5aSmrg    # Back-compat with the calling convention used by older automake.
429586ba5aSmrg    shift
439586ba5aSmrg    ;;
4476888252Smrg
4576888252Smrg  -h|--h|--he|--hel|--help)
4676888252Smrg    echo "\
4776888252Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4876888252Smrg
499586ba5aSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
509586ba5aSmrgto PROGRAM being missing or too old.
5176888252Smrg
5276888252SmrgOptions:
5376888252Smrg  -h, --help      display this help and exit
5476888252Smrg  -v, --version   output version information and exit
5576888252Smrg
5676888252SmrgSupported PROGRAM values:
579586ba5aSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
589586ba5aSmrg  bison     yacc      flex         lex       help2man
5976888252Smrg
609586ba5aSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
619586ba5aSmrg'g' are ignored when checking the name.
62d8556812Smrg
6376888252SmrgSend bug reports to <bug-automake@gnu.org>."
6476888252Smrg    exit $?
6576888252Smrg    ;;
6676888252Smrg
6776888252Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6876888252Smrg    echo "missing $scriptversion (GNU Automake)"
6976888252Smrg    exit $?
7076888252Smrg    ;;
7176888252Smrg
7276888252Smrg  -*)
739586ba5aSmrg    echo 1>&2 "$0: unknown '$1' option"
749586ba5aSmrg    echo 1>&2 "Try '$0 --help' for more information"
7576888252Smrg    exit 1
7676888252Smrg    ;;
7776888252Smrg
7876888252Smrgesac
7976888252Smrg
809586ba5aSmrg# Run the given program, remember its exit status.
819586ba5aSmrg"$@"; st=$?
829586ba5aSmrg
839586ba5aSmrg# If it succeeded, we are done.
849586ba5aSmrgtest $st -eq 0 && exit 0
859586ba5aSmrg
869586ba5aSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
879586ba5aSmrg# passed; such an option is passed most likely to detect whether the
889586ba5aSmrg# program is present and works.
899586ba5aSmrgcase $2 in --version|--help) exit $st;; esac
909586ba5aSmrg
919586ba5aSmrg# Exit code 63 means version mismatch.  This often happens when the user
929586ba5aSmrg# tries to use an ancient version of a tool on a file that requires a
939586ba5aSmrg# minimum version.
949586ba5aSmrgif test $st -eq 63; then
959586ba5aSmrg  msg="probably too old"
969586ba5aSmrgelif test $st -eq 127; then
979586ba5aSmrg  # Program was missing.
989586ba5aSmrg  msg="missing on your system"
999586ba5aSmrgelse
1009586ba5aSmrg  # Program was found and executed, but failed.  Give up.
1019586ba5aSmrg  exit $st
1029586ba5aSmrgfi
10376888252Smrg
1040814a2baSmrgperl_URL=https://www.perl.org/
1050814a2baSmrgflex_URL=https://github.com/westes/flex
1060814a2baSmrggnu_software_URL=https://www.gnu.org/software
1079586ba5aSmrg
1089586ba5aSmrgprogram_details ()
1099586ba5aSmrg{
1109586ba5aSmrg  case $1 in
1119586ba5aSmrg    aclocal|automake)
1129586ba5aSmrg      echo "The '$1' program is part of the GNU Automake package:"
1139586ba5aSmrg      echo "<$gnu_software_URL/automake>"
1149586ba5aSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1159586ba5aSmrg      echo "<$gnu_software_URL/autoconf>"
1169586ba5aSmrg      echo "<$gnu_software_URL/m4/>"
1179586ba5aSmrg      echo "<$perl_URL>"
1189586ba5aSmrg      ;;
1199586ba5aSmrg    autoconf|autom4te|autoheader)
1209586ba5aSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
1219586ba5aSmrg      echo "<$gnu_software_URL/autoconf/>"
1229586ba5aSmrg      echo "It also requires GNU m4 and Perl in order to run:"
1239586ba5aSmrg      echo "<$gnu_software_URL/m4/>"
1249586ba5aSmrg      echo "<$perl_URL>"
1259586ba5aSmrg      ;;
1269586ba5aSmrg  esac
1279586ba5aSmrg}
1289586ba5aSmrg
1299586ba5aSmrggive_advice ()
1309586ba5aSmrg{
1319586ba5aSmrg  # Normalize program name to check for.
1329586ba5aSmrg  normalized_program=`echo "$1" | sed '
1339586ba5aSmrg    s/^gnu-//; t
1349586ba5aSmrg    s/^gnu//; t
1359586ba5aSmrg    s/^g//; t'`
1369586ba5aSmrg
1379586ba5aSmrg  printf '%s\n' "'$1' is $msg."
1389586ba5aSmrg
1399586ba5aSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1409586ba5aSmrg  case $normalized_program in
1419586ba5aSmrg    autoconf*)
1429586ba5aSmrg      echo "You should only need it if you modified 'configure.ac',"
1439586ba5aSmrg      echo "or m4 files included by it."
1449586ba5aSmrg      program_details 'autoconf'
1459586ba5aSmrg      ;;
1469586ba5aSmrg    autoheader*)
1479586ba5aSmrg      echo "You should only need it if you modified 'acconfig.h' or"
1489586ba5aSmrg      echo "$configure_deps."
1499586ba5aSmrg      program_details 'autoheader'
1509586ba5aSmrg      ;;
1519586ba5aSmrg    automake*)
1529586ba5aSmrg      echo "You should only need it if you modified 'Makefile.am' or"
1539586ba5aSmrg      echo "$configure_deps."
1549586ba5aSmrg      program_details 'automake'
1559586ba5aSmrg      ;;
1569586ba5aSmrg    aclocal*)
1579586ba5aSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
1589586ba5aSmrg      echo "$configure_deps."
1599586ba5aSmrg      program_details 'aclocal'
1609586ba5aSmrg      ;;
1619586ba5aSmrg   autom4te*)
1629586ba5aSmrg      echo "You might have modified some maintainer files that require"
1639586ba5aSmrg      echo "the 'autom4te' program to be rebuilt."
1649586ba5aSmrg      program_details 'autom4te'
1659586ba5aSmrg      ;;
1669586ba5aSmrg    bison*|yacc*)
1679586ba5aSmrg      echo "You should only need it if you modified a '.y' file."
1689586ba5aSmrg      echo "You may want to install the GNU Bison package:"
1699586ba5aSmrg      echo "<$gnu_software_URL/bison/>"
1709586ba5aSmrg      ;;
1719586ba5aSmrg    lex*|flex*)
1729586ba5aSmrg      echo "You should only need it if you modified a '.l' file."
1739586ba5aSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1749586ba5aSmrg      echo "<$flex_URL>"
1759586ba5aSmrg      ;;
1769586ba5aSmrg    help2man*)
1779586ba5aSmrg      echo "You should only need it if you modified a dependency" \
1789586ba5aSmrg           "of a man page."
1799586ba5aSmrg      echo "You may want to install the GNU Help2man package:"
1809586ba5aSmrg      echo "<$gnu_software_URL/help2man/>"
18176888252Smrg    ;;
1829586ba5aSmrg    makeinfo*)
1839586ba5aSmrg      echo "You should only need it if you modified a '.texi' file, or"
1849586ba5aSmrg      echo "any other file indirectly affecting the aspect of the manual."
1859586ba5aSmrg      echo "You might want to install the Texinfo package:"
1869586ba5aSmrg      echo "<$gnu_software_URL/texinfo/>"
1879586ba5aSmrg      echo "The spurious makeinfo call might also be the consequence of"
1889586ba5aSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1899586ba5aSmrg      echo "want to install GNU make:"
1909586ba5aSmrg      echo "<$gnu_software_URL/make/>"
1919586ba5aSmrg      ;;
1929586ba5aSmrg    *)
1939586ba5aSmrg      echo "You might have modified some files without having the proper"
1949586ba5aSmrg      echo "tools for further handling them.  Check the 'README' file, it"
1959586ba5aSmrg      echo "often tells you about the needed prerequisites for installing"
1969586ba5aSmrg      echo "this package.  You may also peek at any GNU archive site, in"
1979586ba5aSmrg      echo "case some other package contains this missing '$1' program."
1989586ba5aSmrg      ;;
1999586ba5aSmrg  esac
2009586ba5aSmrg}
2019586ba5aSmrg
2029586ba5aSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2039586ba5aSmrg                       -e '2,$s/^/         /' >&2
2049586ba5aSmrg
2059586ba5aSmrg# Propagate the correct exit status (expected to be 127 for a program
2069586ba5aSmrg# not found, 63 for a program that failed due to version mismatch).
2079586ba5aSmrgexit $st
20876888252Smrg
20976888252Smrg# Local variables:
2100814a2baSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
21176888252Smrg# time-stamp-start: "scriptversion="
21276888252Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2130814a2baSmrg# time-stamp-time-zone: "UTC0"
214d8556812Smrg# time-stamp-end: "; # UTC"
21576888252Smrg# End:
216