175b29833Smrg#! /bin/sh
275b29833Smrg# Common wrapper for a few potentially missing GNU programs.
375b29833Smrg
475b29833Smrgscriptversion=2018-03-07.03; # UTC
575b29833Smrg
675b29833Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
775b29833Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
875b29833Smrg
975b29833Smrg# This program is free software; you can redistribute it and/or modify
1075b29833Smrg# it under the terms of the GNU General Public License as published by
1175b29833Smrg# the Free Software Foundation; either version 2, or (at your option)
1275b29833Smrg# any later version.
1375b29833Smrg
1475b29833Smrg# This program is distributed in the hope that it will be useful,
1575b29833Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1675b29833Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1775b29833Smrg# GNU General Public License for more details.
1875b29833Smrg
1975b29833Smrg# You should have received a copy of the GNU General Public License
2075b29833Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2175b29833Smrg
2275b29833Smrg# As a special exception to the GNU General Public License, if you
2375b29833Smrg# distribute this file as part of a program that contains a
2475b29833Smrg# configuration script generated by Autoconf, you may include it under
2575b29833Smrg# the same distribution terms that you use for the rest of that program.
2675b29833Smrg
2775b29833Smrgif test $# -eq 0; then
2875b29833Smrg  echo 1>&2 "Try '$0 --help' for more information"
2975b29833Smrg  exit 1
3075b29833Smrgfi
3175b29833Smrg
3275b29833Smrgcase $1 in
3375b29833Smrg
3475b29833Smrg  --is-lightweight)
3575b29833Smrg    # Used by our autoconf macros to check whether the available missing
3675b29833Smrg    # script is modern enough.
3775b29833Smrg    exit 0
3875b29833Smrg    ;;
3975b29833Smrg
4075b29833Smrg  --run)
4175b29833Smrg    # Back-compat with the calling convention used by older automake.
4275b29833Smrg    shift
4375b29833Smrg    ;;
4475b29833Smrg
4575b29833Smrg  -h|--h|--he|--hel|--help)
4675b29833Smrg    echo "\
4775b29833Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4875b29833Smrg
4975b29833SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5075b29833Smrgto PROGRAM being missing or too old.
5175b29833Smrg
5275b29833SmrgOptions:
5375b29833Smrg  -h, --help      display this help and exit
5475b29833Smrg  -v, --version   output version information and exit
5575b29833Smrg
5675b29833SmrgSupported PROGRAM values:
5775b29833Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5875b29833Smrg  bison     yacc      flex         lex       help2man
5975b29833Smrg
6075b29833SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6175b29833Smrg'g' are ignored when checking the name.
6275b29833Smrg
6375b29833SmrgSend bug reports to <bug-automake@gnu.org>."
6475b29833Smrg    exit $?
6575b29833Smrg    ;;
6675b29833Smrg
6775b29833Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6875b29833Smrg    echo "missing $scriptversion (GNU Automake)"
6975b29833Smrg    exit $?
7075b29833Smrg    ;;
7175b29833Smrg
7275b29833Smrg  -*)
7375b29833Smrg    echo 1>&2 "$0: unknown '$1' option"
7475b29833Smrg    echo 1>&2 "Try '$0 --help' for more information"
7575b29833Smrg    exit 1
7675b29833Smrg    ;;
7775b29833Smrg
7875b29833Smrgesac
7975b29833Smrg
8075b29833Smrg# Run the given program, remember its exit status.
8175b29833Smrg"$@"; st=$?
8275b29833Smrg
8375b29833Smrg# If it succeeded, we are done.
8475b29833Smrgtest $st -eq 0 && exit 0
8575b29833Smrg
8675b29833Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8775b29833Smrg# passed; such an option is passed most likely to detect whether the
8875b29833Smrg# program is present and works.
8975b29833Smrgcase $2 in --version|--help) exit $st;; esac
9075b29833Smrg
9175b29833Smrg# Exit code 63 means version mismatch.  This often happens when the user
9275b29833Smrg# tries to use an ancient version of a tool on a file that requires a
9375b29833Smrg# minimum version.
9475b29833Smrgif test $st -eq 63; then
9575b29833Smrg  msg="probably too old"
9675b29833Smrgelif test $st -eq 127; then
9775b29833Smrg  # Program was missing.
9875b29833Smrg  msg="missing on your system"
9975b29833Smrgelse
10075b29833Smrg  # Program was found and executed, but failed.  Give up.
10175b29833Smrg  exit $st
10275b29833Smrgfi
10375b29833Smrg
10475b29833Smrgperl_URL=https://www.perl.org/
10575b29833Smrgflex_URL=https://github.com/westes/flex
10675b29833Smrggnu_software_URL=https://www.gnu.org/software
10775b29833Smrg
10875b29833Smrgprogram_details ()
10975b29833Smrg{
11075b29833Smrg  case $1 in
11175b29833Smrg    aclocal|automake)
11275b29833Smrg      echo "The '$1' program is part of the GNU Automake package:"
11375b29833Smrg      echo "<$gnu_software_URL/automake>"
11475b29833Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11575b29833Smrg      echo "<$gnu_software_URL/autoconf>"
11675b29833Smrg      echo "<$gnu_software_URL/m4/>"
11775b29833Smrg      echo "<$perl_URL>"
11875b29833Smrg      ;;
11975b29833Smrg    autoconf|autom4te|autoheader)
12075b29833Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12175b29833Smrg      echo "<$gnu_software_URL/autoconf/>"
12275b29833Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12375b29833Smrg      echo "<$gnu_software_URL/m4/>"
12475b29833Smrg      echo "<$perl_URL>"
12575b29833Smrg      ;;
12675b29833Smrg  esac
12775b29833Smrg}
12875b29833Smrg
12975b29833Smrggive_advice ()
13075b29833Smrg{
13175b29833Smrg  # Normalize program name to check for.
13275b29833Smrg  normalized_program=`echo "$1" | sed '
13375b29833Smrg    s/^gnu-//; t
13475b29833Smrg    s/^gnu//; t
13575b29833Smrg    s/^g//; t'`
13675b29833Smrg
13775b29833Smrg  printf '%s\n' "'$1' is $msg."
13875b29833Smrg
13975b29833Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14075b29833Smrg  case $normalized_program in
14175b29833Smrg    autoconf*)
14275b29833Smrg      echo "You should only need it if you modified 'configure.ac',"
14375b29833Smrg      echo "or m4 files included by it."
14475b29833Smrg      program_details 'autoconf'
14575b29833Smrg      ;;
14675b29833Smrg    autoheader*)
14775b29833Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14875b29833Smrg      echo "$configure_deps."
14975b29833Smrg      program_details 'autoheader'
15075b29833Smrg      ;;
15175b29833Smrg    automake*)
15275b29833Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15375b29833Smrg      echo "$configure_deps."
15475b29833Smrg      program_details 'automake'
15575b29833Smrg      ;;
15675b29833Smrg    aclocal*)
15775b29833Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15875b29833Smrg      echo "$configure_deps."
15975b29833Smrg      program_details 'aclocal'
16075b29833Smrg      ;;
16175b29833Smrg   autom4te*)
16275b29833Smrg      echo "You might have modified some maintainer files that require"
16375b29833Smrg      echo "the 'autom4te' program to be rebuilt."
16475b29833Smrg      program_details 'autom4te'
16575b29833Smrg      ;;
16675b29833Smrg    bison*|yacc*)
16775b29833Smrg      echo "You should only need it if you modified a '.y' file."
16875b29833Smrg      echo "You may want to install the GNU Bison package:"
16975b29833Smrg      echo "<$gnu_software_URL/bison/>"
17075b29833Smrg      ;;
17175b29833Smrg    lex*|flex*)
17275b29833Smrg      echo "You should only need it if you modified a '.l' file."
17375b29833Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17475b29833Smrg      echo "<$flex_URL>"
17575b29833Smrg      ;;
17675b29833Smrg    help2man*)
17775b29833Smrg      echo "You should only need it if you modified a dependency" \
17875b29833Smrg           "of a man page."
17975b29833Smrg      echo "You may want to install the GNU Help2man package:"
18075b29833Smrg      echo "<$gnu_software_URL/help2man/>"
18175b29833Smrg    ;;
18275b29833Smrg    makeinfo*)
18375b29833Smrg      echo "You should only need it if you modified a '.texi' file, or"
18475b29833Smrg      echo "any other file indirectly affecting the aspect of the manual."
18575b29833Smrg      echo "You might want to install the Texinfo package:"
18675b29833Smrg      echo "<$gnu_software_URL/texinfo/>"
18775b29833Smrg      echo "The spurious makeinfo call might also be the consequence of"
18875b29833Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18975b29833Smrg      echo "want to install GNU make:"
19075b29833Smrg      echo "<$gnu_software_URL/make/>"
19175b29833Smrg      ;;
19275b29833Smrg    *)
19375b29833Smrg      echo "You might have modified some files without having the proper"
19475b29833Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19575b29833Smrg      echo "often tells you about the needed prerequisites for installing"
19675b29833Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19775b29833Smrg      echo "case some other package contains this missing '$1' program."
19875b29833Smrg      ;;
19975b29833Smrg  esac
20075b29833Smrg}
20175b29833Smrg
20275b29833Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20375b29833Smrg                       -e '2,$s/^/         /' >&2
20475b29833Smrg
20575b29833Smrg# Propagate the correct exit status (expected to be 127 for a program
20675b29833Smrg# not found, 63 for a program that failed due to version mismatch).
20775b29833Smrgexit $st
20875b29833Smrg
20975b29833Smrg# Local variables:
21075b29833Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
21175b29833Smrg# time-stamp-start: "scriptversion="
21275b29833Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21375b29833Smrg# time-stamp-time-zone: "UTC0"
21475b29833Smrg# time-stamp-end: "; # UTC"
21575b29833Smrg# End:
216