155de1df9Smrg#! /bin/sh
216e5c272Smrg# Common wrapper for a few potentially missing GNU programs.
355de1df9Smrg
416e5c272Smrgscriptversion=2018-03-07.03; # UTC
555de1df9Smrg
616e5c272Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
716e5c272Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
855de1df9Smrg
955de1df9Smrg# This program is free software; you can redistribute it and/or modify
1055de1df9Smrg# it under the terms of the GNU General Public License as published by
1155de1df9Smrg# the Free Software Foundation; either version 2, or (at your option)
1255de1df9Smrg# any later version.
1355de1df9Smrg
1455de1df9Smrg# This program is distributed in the hope that it will be useful,
1555de1df9Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1655de1df9Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1755de1df9Smrg# GNU General Public License for more details.
1855de1df9Smrg
1955de1df9Smrg# You should have received a copy of the GNU General Public License
2016e5c272Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2155de1df9Smrg
2255de1df9Smrg# As a special exception to the GNU General Public License, if you
2355de1df9Smrg# distribute this file as part of a program that contains a
2455de1df9Smrg# configuration script generated by Autoconf, you may include it under
2555de1df9Smrg# the same distribution terms that you use for the rest of that program.
2655de1df9Smrg
2755de1df9Smrgif test $# -eq 0; then
2816e5c272Smrg  echo 1>&2 "Try '$0 --help' for more information"
2955de1df9Smrg  exit 1
3055de1df9Smrgfi
3155de1df9Smrg
3216e5c272Smrgcase $1 in
3355de1df9Smrg
3416e5c272Smrg  --is-lightweight)
3516e5c272Smrg    # Used by our autoconf macros to check whether the available missing
3616e5c272Smrg    # script is modern enough.
3716e5c272Smrg    exit 0
3816e5c272Smrg    ;;
3955de1df9Smrg
4016e5c272Smrg  --run)
4116e5c272Smrg    # Back-compat with the calling convention used by older automake.
4216e5c272Smrg    shift
4316e5c272Smrg    ;;
4455de1df9Smrg
4555de1df9Smrg  -h|--h|--he|--hel|--help)
4655de1df9Smrg    echo "\
4755de1df9Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4855de1df9Smrg
4916e5c272SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5016e5c272Smrgto PROGRAM being missing or too old.
5155de1df9Smrg
5255de1df9SmrgOptions:
5355de1df9Smrg  -h, --help      display this help and exit
5455de1df9Smrg  -v, --version   output version information and exit
5555de1df9Smrg
5655de1df9SmrgSupported PROGRAM values:
5716e5c272Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5816e5c272Smrg  bison     yacc      flex         lex       help2man
5955de1df9Smrg
6016e5c272SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6116e5c272Smrg'g' are ignored when checking the name.
6255de1df9Smrg
6355de1df9SmrgSend bug reports to <bug-automake@gnu.org>."
6455de1df9Smrg    exit $?
6555de1df9Smrg    ;;
6655de1df9Smrg
6755de1df9Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6855de1df9Smrg    echo "missing $scriptversion (GNU Automake)"
6955de1df9Smrg    exit $?
7055de1df9Smrg    ;;
7155de1df9Smrg
7255de1df9Smrg  -*)
7316e5c272Smrg    echo 1>&2 "$0: unknown '$1' option"
7416e5c272Smrg    echo 1>&2 "Try '$0 --help' for more information"
7555de1df9Smrg    exit 1
7655de1df9Smrg    ;;
7755de1df9Smrg
7855de1df9Smrgesac
7955de1df9Smrg
8016e5c272Smrg# Run the given program, remember its exit status.
8116e5c272Smrg"$@"; st=$?
8216e5c272Smrg
8316e5c272Smrg# If it succeeded, we are done.
8416e5c272Smrgtest $st -eq 0 && exit 0
8516e5c272Smrg
8616e5c272Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8716e5c272Smrg# passed; such an option is passed most likely to detect whether the
8816e5c272Smrg# program is present and works.
8916e5c272Smrgcase $2 in --version|--help) exit $st;; esac
9016e5c272Smrg
9116e5c272Smrg# Exit code 63 means version mismatch.  This often happens when the user
9216e5c272Smrg# tries to use an ancient version of a tool on a file that requires a
9316e5c272Smrg# minimum version.
9416e5c272Smrgif test $st -eq 63; then
9516e5c272Smrg  msg="probably too old"
9616e5c272Smrgelif test $st -eq 127; then
9716e5c272Smrg  # Program was missing.
9816e5c272Smrg  msg="missing on your system"
9916e5c272Smrgelse
10016e5c272Smrg  # Program was found and executed, but failed.  Give up.
10116e5c272Smrg  exit $st
10216e5c272Smrgfi
10355de1df9Smrg
10416e5c272Smrgperl_URL=https://www.perl.org/
10516e5c272Smrgflex_URL=https://github.com/westes/flex
10616e5c272Smrggnu_software_URL=https://www.gnu.org/software
10716e5c272Smrg
10816e5c272Smrgprogram_details ()
10916e5c272Smrg{
11016e5c272Smrg  case $1 in
11116e5c272Smrg    aclocal|automake)
11216e5c272Smrg      echo "The '$1' program is part of the GNU Automake package:"
11316e5c272Smrg      echo "<$gnu_software_URL/automake>"
11416e5c272Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11516e5c272Smrg      echo "<$gnu_software_URL/autoconf>"
11616e5c272Smrg      echo "<$gnu_software_URL/m4/>"
11716e5c272Smrg      echo "<$perl_URL>"
11816e5c272Smrg      ;;
11916e5c272Smrg    autoconf|autom4te|autoheader)
12016e5c272Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12116e5c272Smrg      echo "<$gnu_software_URL/autoconf/>"
12216e5c272Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12316e5c272Smrg      echo "<$gnu_software_URL/m4/>"
12416e5c272Smrg      echo "<$perl_URL>"
12516e5c272Smrg      ;;
12616e5c272Smrg  esac
12716e5c272Smrg}
12816e5c272Smrg
12916e5c272Smrggive_advice ()
13016e5c272Smrg{
13116e5c272Smrg  # Normalize program name to check for.
13216e5c272Smrg  normalized_program=`echo "$1" | sed '
13316e5c272Smrg    s/^gnu-//; t
13416e5c272Smrg    s/^gnu//; t
13516e5c272Smrg    s/^g//; t'`
13616e5c272Smrg
13716e5c272Smrg  printf '%s\n' "'$1' is $msg."
13816e5c272Smrg
13916e5c272Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14016e5c272Smrg  case $normalized_program in
14116e5c272Smrg    autoconf*)
14216e5c272Smrg      echo "You should only need it if you modified 'configure.ac',"
14316e5c272Smrg      echo "or m4 files included by it."
14416e5c272Smrg      program_details 'autoconf'
14516e5c272Smrg      ;;
14616e5c272Smrg    autoheader*)
14716e5c272Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14816e5c272Smrg      echo "$configure_deps."
14916e5c272Smrg      program_details 'autoheader'
15016e5c272Smrg      ;;
15116e5c272Smrg    automake*)
15216e5c272Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15316e5c272Smrg      echo "$configure_deps."
15416e5c272Smrg      program_details 'automake'
15516e5c272Smrg      ;;
15616e5c272Smrg    aclocal*)
15716e5c272Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15816e5c272Smrg      echo "$configure_deps."
15916e5c272Smrg      program_details 'aclocal'
16016e5c272Smrg      ;;
16116e5c272Smrg   autom4te*)
16216e5c272Smrg      echo "You might have modified some maintainer files that require"
16316e5c272Smrg      echo "the 'autom4te' program to be rebuilt."
16416e5c272Smrg      program_details 'autom4te'
16516e5c272Smrg      ;;
16616e5c272Smrg    bison*|yacc*)
16716e5c272Smrg      echo "You should only need it if you modified a '.y' file."
16816e5c272Smrg      echo "You may want to install the GNU Bison package:"
16916e5c272Smrg      echo "<$gnu_software_URL/bison/>"
17016e5c272Smrg      ;;
17116e5c272Smrg    lex*|flex*)
17216e5c272Smrg      echo "You should only need it if you modified a '.l' file."
17316e5c272Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17416e5c272Smrg      echo "<$flex_URL>"
17516e5c272Smrg      ;;
17616e5c272Smrg    help2man*)
17716e5c272Smrg      echo "You should only need it if you modified a dependency" \
17816e5c272Smrg           "of a man page."
17916e5c272Smrg      echo "You may want to install the GNU Help2man package:"
18016e5c272Smrg      echo "<$gnu_software_URL/help2man/>"
18116e5c272Smrg    ;;
18216e5c272Smrg    makeinfo*)
18316e5c272Smrg      echo "You should only need it if you modified a '.texi' file, or"
18416e5c272Smrg      echo "any other file indirectly affecting the aspect of the manual."
18516e5c272Smrg      echo "You might want to install the Texinfo package:"
18616e5c272Smrg      echo "<$gnu_software_URL/texinfo/>"
18716e5c272Smrg      echo "The spurious makeinfo call might also be the consequence of"
18816e5c272Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18916e5c272Smrg      echo "want to install GNU make:"
19016e5c272Smrg      echo "<$gnu_software_URL/make/>"
19116e5c272Smrg      ;;
19216e5c272Smrg    *)
19316e5c272Smrg      echo "You might have modified some files without having the proper"
19416e5c272Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19516e5c272Smrg      echo "often tells you about the needed prerequisites for installing"
19616e5c272Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19716e5c272Smrg      echo "case some other package contains this missing '$1' program."
19816e5c272Smrg      ;;
19916e5c272Smrg  esac
20016e5c272Smrg}
20116e5c272Smrg
20216e5c272Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20316e5c272Smrg                       -e '2,$s/^/         /' >&2
20416e5c272Smrg
20516e5c272Smrg# Propagate the correct exit status (expected to be 127 for a program
20616e5c272Smrg# not found, 63 for a program that failed due to version mismatch).
20716e5c272Smrgexit $st
20855de1df9Smrg
20955de1df9Smrg# Local variables:
21016e5c272Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
21155de1df9Smrg# time-stamp-start: "scriptversion="
21255de1df9Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21316e5c272Smrg# time-stamp-time-zone: "UTC0"
21455de1df9Smrg# time-stamp-end: "; # UTC"
21555de1df9Smrg# End:
216