missing revision bdc460c5
114c0a534Smrg#! /bin/sh
224047306Smrg# Common wrapper for a few potentially missing GNU programs.
314c0a534Smrg
4bdc460c5Smrgscriptversion=2018-03-07.03; # UTC
514c0a534Smrg
6bdc460c5Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
724047306Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
814c0a534Smrg
914c0a534Smrg# This program is free software; you can redistribute it and/or modify
1014c0a534Smrg# it under the terms of the GNU General Public License as published by
1114c0a534Smrg# the Free Software Foundation; either version 2, or (at your option)
1214c0a534Smrg# any later version.
1314c0a534Smrg
1414c0a534Smrg# This program is distributed in the hope that it will be useful,
1514c0a534Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1614c0a534Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1714c0a534Smrg# GNU General Public License for more details.
1814c0a534Smrg
1914c0a534Smrg# You should have received a copy of the GNU General Public License
20bdc460c5Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2114c0a534Smrg
2214c0a534Smrg# As a special exception to the GNU General Public License, if you
2314c0a534Smrg# distribute this file as part of a program that contains a
2414c0a534Smrg# configuration script generated by Autoconf, you may include it under
2514c0a534Smrg# the same distribution terms that you use for the rest of that program.
2614c0a534Smrg
2714c0a534Smrgif test $# -eq 0; then
2824047306Smrg  echo 1>&2 "Try '$0 --help' for more information"
2914c0a534Smrg  exit 1
3014c0a534Smrgfi
3114c0a534Smrg
3224047306Smrgcase $1 in
3314c0a534Smrg
3424047306Smrg  --is-lightweight)
3524047306Smrg    # Used by our autoconf macros to check whether the available missing
3624047306Smrg    # script is modern enough.
3724047306Smrg    exit 0
3824047306Smrg    ;;
3914c0a534Smrg
4024047306Smrg  --run)
4124047306Smrg    # Back-compat with the calling convention used by older automake.
4224047306Smrg    shift
4324047306Smrg    ;;
4414c0a534Smrg
4514c0a534Smrg  -h|--h|--he|--hel|--help)
4614c0a534Smrg    echo "\
4714c0a534Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4814c0a534Smrg
4924047306SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5024047306Smrgto PROGRAM being missing or too old.
5114c0a534Smrg
5214c0a534SmrgOptions:
5314c0a534Smrg  -h, --help      display this help and exit
5414c0a534Smrg  -v, --version   output version information and exit
5514c0a534Smrg
5614c0a534SmrgSupported PROGRAM values:
5724047306Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5824047306Smrg  bison     yacc      flex         lex       help2man
5914c0a534Smrg
6024047306SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6124047306Smrg'g' are ignored when checking the name.
62bf2eeab3Smrg
6314c0a534SmrgSend bug reports to <bug-automake@gnu.org>."
6414c0a534Smrg    exit $?
6514c0a534Smrg    ;;
6614c0a534Smrg
6714c0a534Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6814c0a534Smrg    echo "missing $scriptversion (GNU Automake)"
6914c0a534Smrg    exit $?
7014c0a534Smrg    ;;
7114c0a534Smrg
7214c0a534Smrg  -*)
7324047306Smrg    echo 1>&2 "$0: unknown '$1' option"
7424047306Smrg    echo 1>&2 "Try '$0 --help' for more information"
7514c0a534Smrg    exit 1
7614c0a534Smrg    ;;
7714c0a534Smrg
7814c0a534Smrgesac
7914c0a534Smrg
8024047306Smrg# Run the given program, remember its exit status.
8124047306Smrg"$@"; st=$?
8224047306Smrg
8324047306Smrg# If it succeeded, we are done.
8424047306Smrgtest $st -eq 0 && exit 0
8524047306Smrg
8624047306Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8724047306Smrg# passed; such an option is passed most likely to detect whether the
8824047306Smrg# program is present and works.
8924047306Smrgcase $2 in --version|--help) exit $st;; esac
9024047306Smrg
9124047306Smrg# Exit code 63 means version mismatch.  This often happens when the user
9224047306Smrg# tries to use an ancient version of a tool on a file that requires a
9324047306Smrg# minimum version.
9424047306Smrgif test $st -eq 63; then
9524047306Smrg  msg="probably too old"
9624047306Smrgelif test $st -eq 127; then
9724047306Smrg  # Program was missing.
9824047306Smrg  msg="missing on your system"
9924047306Smrgelse
10024047306Smrg  # Program was found and executed, but failed.  Give up.
10124047306Smrg  exit $st
10224047306Smrgfi
10314c0a534Smrg
104bdc460c5Smrgperl_URL=https://www.perl.org/
105bdc460c5Smrgflex_URL=https://github.com/westes/flex
106bdc460c5Smrggnu_software_URL=https://www.gnu.org/software
10724047306Smrg
10824047306Smrgprogram_details ()
10924047306Smrg{
11024047306Smrg  case $1 in
11124047306Smrg    aclocal|automake)
11224047306Smrg      echo "The '$1' program is part of the GNU Automake package:"
11324047306Smrg      echo "<$gnu_software_URL/automake>"
11424047306Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11524047306Smrg      echo "<$gnu_software_URL/autoconf>"
11624047306Smrg      echo "<$gnu_software_URL/m4/>"
11724047306Smrg      echo "<$perl_URL>"
11824047306Smrg      ;;
11924047306Smrg    autoconf|autom4te|autoheader)
12024047306Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12124047306Smrg      echo "<$gnu_software_URL/autoconf/>"
12224047306Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12324047306Smrg      echo "<$gnu_software_URL/m4/>"
12424047306Smrg      echo "<$perl_URL>"
12524047306Smrg      ;;
12624047306Smrg  esac
12724047306Smrg}
12824047306Smrg
12924047306Smrggive_advice ()
13024047306Smrg{
13124047306Smrg  # Normalize program name to check for.
13224047306Smrg  normalized_program=`echo "$1" | sed '
13324047306Smrg    s/^gnu-//; t
13424047306Smrg    s/^gnu//; t
13524047306Smrg    s/^g//; t'`
13624047306Smrg
13724047306Smrg  printf '%s\n' "'$1' is $msg."
13824047306Smrg
13924047306Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14024047306Smrg  case $normalized_program in
14124047306Smrg    autoconf*)
14224047306Smrg      echo "You should only need it if you modified 'configure.ac',"
14324047306Smrg      echo "or m4 files included by it."
14424047306Smrg      program_details 'autoconf'
14524047306Smrg      ;;
14624047306Smrg    autoheader*)
14724047306Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14824047306Smrg      echo "$configure_deps."
14924047306Smrg      program_details 'autoheader'
15024047306Smrg      ;;
15124047306Smrg    automake*)
15224047306Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15324047306Smrg      echo "$configure_deps."
15424047306Smrg      program_details 'automake'
15524047306Smrg      ;;
15624047306Smrg    aclocal*)
15724047306Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15824047306Smrg      echo "$configure_deps."
15924047306Smrg      program_details 'aclocal'
16024047306Smrg      ;;
16124047306Smrg   autom4te*)
16224047306Smrg      echo "You might have modified some maintainer files that require"
16324047306Smrg      echo "the 'autom4te' program to be rebuilt."
16424047306Smrg      program_details 'autom4te'
16524047306Smrg      ;;
16624047306Smrg    bison*|yacc*)
16724047306Smrg      echo "You should only need it if you modified a '.y' file."
16824047306Smrg      echo "You may want to install the GNU Bison package:"
16924047306Smrg      echo "<$gnu_software_URL/bison/>"
17024047306Smrg      ;;
17124047306Smrg    lex*|flex*)
17224047306Smrg      echo "You should only need it if you modified a '.l' file."
17324047306Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17424047306Smrg      echo "<$flex_URL>"
17524047306Smrg      ;;
17624047306Smrg    help2man*)
17724047306Smrg      echo "You should only need it if you modified a dependency" \
17824047306Smrg           "of a man page."
17924047306Smrg      echo "You may want to install the GNU Help2man package:"
18024047306Smrg      echo "<$gnu_software_URL/help2man/>"
18124047306Smrg    ;;
18224047306Smrg    makeinfo*)
18324047306Smrg      echo "You should only need it if you modified a '.texi' file, or"
18424047306Smrg      echo "any other file indirectly affecting the aspect of the manual."
18524047306Smrg      echo "You might want to install the Texinfo package:"
18624047306Smrg      echo "<$gnu_software_URL/texinfo/>"
18724047306Smrg      echo "The spurious makeinfo call might also be the consequence of"
18824047306Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18924047306Smrg      echo "want to install GNU make:"
19024047306Smrg      echo "<$gnu_software_URL/make/>"
19124047306Smrg      ;;
19224047306Smrg    *)
19324047306Smrg      echo "You might have modified some files without having the proper"
19424047306Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19524047306Smrg      echo "often tells you about the needed prerequisites for installing"
19624047306Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19724047306Smrg      echo "case some other package contains this missing '$1' program."
19824047306Smrg      ;;
19924047306Smrg  esac
20024047306Smrg}
20124047306Smrg
20224047306Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20324047306Smrg                       -e '2,$s/^/         /' >&2
20424047306Smrg
20524047306Smrg# Propagate the correct exit status (expected to be 127 for a program
20624047306Smrg# not found, 63 for a program that failed due to version mismatch).
20724047306Smrgexit $st
20814c0a534Smrg
20914c0a534Smrg# Local variables:
210bdc460c5Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
21114c0a534Smrg# time-stamp-start: "scriptversion="
21214c0a534Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213bdc460c5Smrg# time-stamp-time-zone: "UTC0"
214bf2eeab3Smrg# time-stamp-end: "; # UTC"
21514c0a534Smrg# End:
216