missing revision bbfad078
197e8a2e8Smrg#! /bin/sh
2bbfad078Smrg# Common wrapper for a few potentially missing GNU and other programs.
3d7accfefSmrg
4bbfad078Smrgscriptversion=2024-06-07.14; # UTC
5d7accfefSmrg
6bbfad078Smrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
7bbfad078Smrg
8bbfad078Smrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
968af480fSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
1097e8a2e8Smrg
1197e8a2e8Smrg# This program is free software; you can redistribute it and/or modify
1297e8a2e8Smrg# it under the terms of the GNU General Public License as published by
1397e8a2e8Smrg# the Free Software Foundation; either version 2, or (at your option)
1497e8a2e8Smrg# any later version.
1597e8a2e8Smrg
1697e8a2e8Smrg# This program is distributed in the hope that it will be useful,
1797e8a2e8Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1897e8a2e8Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1997e8a2e8Smrg# GNU General Public License for more details.
2097e8a2e8Smrg
2197e8a2e8Smrg# You should have received a copy of the GNU General Public License
22219ffec0Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2397e8a2e8Smrg
2497e8a2e8Smrg# As a special exception to the GNU General Public License, if you
2597e8a2e8Smrg# distribute this file as part of a program that contains a
2697e8a2e8Smrg# configuration script generated by Autoconf, you may include it under
2797e8a2e8Smrg# the same distribution terms that you use for the rest of that program.
2897e8a2e8Smrg
2997e8a2e8Smrgif test $# -eq 0; then
3068af480fSmrg  echo 1>&2 "Try '$0 --help' for more information"
3197e8a2e8Smrg  exit 1
3297e8a2e8Smrgfi
3397e8a2e8Smrg
3468af480fSmrgcase $1 in
3597e8a2e8Smrg
3668af480fSmrg  --is-lightweight)
3768af480fSmrg    # Used by our autoconf macros to check whether the available missing
3868af480fSmrg    # script is modern enough.
3968af480fSmrg    exit 0
4068af480fSmrg    ;;
41d7accfefSmrg
4268af480fSmrg  --run)
4368af480fSmrg    # Back-compat with the calling convention used by older automake.
4468af480fSmrg    shift
4568af480fSmrg    ;;
4697e8a2e8Smrg
4797e8a2e8Smrg  -h|--h|--he|--hel|--help)
4897e8a2e8Smrg    echo "\
4997e8a2e8Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
5097e8a2e8Smrg
5168af480fSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5268af480fSmrgto PROGRAM being missing or too old.
5397e8a2e8Smrg
5497e8a2e8SmrgOptions:
5597e8a2e8Smrg  -h, --help      display this help and exit
5697e8a2e8Smrg  -v, --version   output version information and exit
5797e8a2e8Smrg
5897e8a2e8SmrgSupported PROGRAM values:
59bbfad078Smrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
60bbfad078Smrgbison   flex     help2man lex        makeinfo perl     yacc
61d7accfefSmrg
6268af480fSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6368af480fSmrg'g' are ignored when checking the name.
64d7accfefSmrg
65bbfad078SmrgReport bugs to <bug-automake@gnu.org>.
66bbfad078SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
67bbfad078SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
68d7accfefSmrg    exit $?
6997e8a2e8Smrg    ;;
7097e8a2e8Smrg
7197e8a2e8Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
72bbfad078Smrg    echo "missing (GNU Automake) $scriptversion"
73d7accfefSmrg    exit $?
7497e8a2e8Smrg    ;;
7597e8a2e8Smrg
7697e8a2e8Smrg  -*)
7768af480fSmrg    echo 1>&2 "$0: unknown '$1' option"
7868af480fSmrg    echo 1>&2 "Try '$0 --help' for more information"
7997e8a2e8Smrg    exit 1
8097e8a2e8Smrg    ;;
8197e8a2e8Smrg
82d7accfefSmrgesac
83d7accfefSmrg
8468af480fSmrg# Run the given program, remember its exit status.
8568af480fSmrg"$@"; st=$?
8668af480fSmrg
8768af480fSmrg# If it succeeded, we are done.
8868af480fSmrgtest $st -eq 0 && exit 0
8968af480fSmrg
9068af480fSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
9168af480fSmrg# passed; such an option is passed most likely to detect whether the
9268af480fSmrg# program is present and works.
9368af480fSmrgcase $2 in --version|--help) exit $st;; esac
9468af480fSmrg
9568af480fSmrg# Exit code 63 means version mismatch.  This often happens when the user
9668af480fSmrg# tries to use an ancient version of a tool on a file that requires a
9768af480fSmrg# minimum version.
9868af480fSmrgif test $st -eq 63; then
9968af480fSmrg  msg="probably too old"
10068af480fSmrgelif test $st -eq 127; then
10168af480fSmrg  # Program was missing.
10268af480fSmrg  msg="missing on your system"
10368af480fSmrgelse
10468af480fSmrg  # Program was found and executed, but failed.  Give up.
10568af480fSmrg  exit $st
10668af480fSmrgfi
10797e8a2e8Smrg
108219ffec0Smrgperl_URL=https://www.perl.org/
109219ffec0Smrgflex_URL=https://github.com/westes/flex
110219ffec0Smrggnu_software_URL=https://www.gnu.org/software
11168af480fSmrg
11268af480fSmrgprogram_details ()
11368af480fSmrg{
11468af480fSmrg  case $1 in
115bbfad078Smrg    aclocal|automake|autoreconf)
11668af480fSmrg      echo "The '$1' program is part of the GNU Automake package:"
11768af480fSmrg      echo "<$gnu_software_URL/automake>"
11868af480fSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11968af480fSmrg      echo "<$gnu_software_URL/autoconf>"
12068af480fSmrg      echo "<$gnu_software_URL/m4/>"
12168af480fSmrg      echo "<$perl_URL>"
12268af480fSmrg      ;;
12368af480fSmrg    autoconf|autom4te|autoheader)
12468af480fSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
12568af480fSmrg      echo "<$gnu_software_URL/autoconf/>"
12668af480fSmrg      echo "It also requires GNU m4 and Perl in order to run:"
12768af480fSmrg      echo "<$gnu_software_URL/m4/>"
12868af480fSmrg      echo "<$perl_URL>"
12968af480fSmrg      ;;
130bbfad078Smrg    *)
131bbfad078Smrg      :
132bbfad078Smrg      ;;
13368af480fSmrg  esac
13468af480fSmrg}
13568af480fSmrg
13668af480fSmrggive_advice ()
13768af480fSmrg{
13868af480fSmrg  # Normalize program name to check for.
13968af480fSmrg  normalized_program=`echo "$1" | sed '
14068af480fSmrg    s/^gnu-//; t
14168af480fSmrg    s/^gnu//; t
14268af480fSmrg    s/^g//; t'`
14368af480fSmrg
14468af480fSmrg  printf '%s\n' "'$1' is $msg."
14568af480fSmrg
14668af480fSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
147bbfad078Smrg  autoheader_deps="'acconfig.h'"
148bbfad078Smrg  automake_deps="'Makefile.am'"
149bbfad078Smrg  aclocal_deps="'acinclude.m4'"
15068af480fSmrg  case $normalized_program in
151bbfad078Smrg    aclocal*)
152bbfad078Smrg      echo "You should only need it if you modified $aclocal_deps or"
153bbfad078Smrg      echo "$configure_deps."
154bbfad078Smrg      ;;
15568af480fSmrg    autoconf*)
156bbfad078Smrg      echo "You should only need it if you modified $configure_deps."
157bbfad078Smrg      ;;
158bbfad078Smrg    autogen*)
159bbfad078Smrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
160bbfad078Smrg      echo "You may want to install the GNU AutoGen package:"
161bbfad078Smrg      echo "<$gnu_software_URL/autogen/>"
16268af480fSmrg      ;;
16368af480fSmrg    autoheader*)
164bbfad078Smrg      echo "You should only need it if you modified $autoheader_deps or"
16568af480fSmrg      echo "$configure_deps."
16668af480fSmrg      ;;
16768af480fSmrg    automake*)
168bbfad078Smrg      echo "You should only need it if you modified $automake_deps or"
16968af480fSmrg      echo "$configure_deps."
17068af480fSmrg      ;;
171bbfad078Smrg    autom4te*)
17268af480fSmrg      echo "You might have modified some maintainer files that require"
173219ffec0Smrg      echo "the 'autom4te' program to be rebuilt."
174bbfad078Smrg      ;;
175bbfad078Smrg    autoreconf*)
176bbfad078Smrg      echo "You should only need it if you modified $aclocal_deps or"
177bbfad078Smrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
178bbfad078Smrg      echo "$configure_deps."
17968af480fSmrg      ;;
18068af480fSmrg    bison*|yacc*)
18168af480fSmrg      echo "You should only need it if you modified a '.y' file."
18268af480fSmrg      echo "You may want to install the GNU Bison package:"
18368af480fSmrg      echo "<$gnu_software_URL/bison/>"
18468af480fSmrg      ;;
18568af480fSmrg    help2man*)
18668af480fSmrg      echo "You should only need it if you modified a dependency" \
18768af480fSmrg           "of a man page."
18868af480fSmrg      echo "You may want to install the GNU Help2man package:"
18968af480fSmrg      echo "<$gnu_software_URL/help2man/>"
19068af480fSmrg    ;;
191bbfad078Smrg    lex*|flex*)
192bbfad078Smrg      echo "You should only need it if you modified a '.l' file."
193bbfad078Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
194bbfad078Smrg      echo "<$flex_URL>"
195bbfad078Smrg      ;;
19668af480fSmrg    makeinfo*)
19768af480fSmrg      echo "You should only need it if you modified a '.texi' file, or"
19868af480fSmrg      echo "any other file indirectly affecting the aspect of the manual."
19968af480fSmrg      echo "You might want to install the Texinfo package:"
20068af480fSmrg      echo "<$gnu_software_URL/texinfo/>"
20168af480fSmrg      echo "The spurious makeinfo call might also be the consequence of"
20268af480fSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
20368af480fSmrg      echo "want to install GNU make:"
20468af480fSmrg      echo "<$gnu_software_URL/make/>"
20568af480fSmrg      ;;
206bbfad078Smrg    perl*)
207bbfad078Smrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
208bbfad078Smrg      echo "  assorted other tools, or if you modified a Perl source file."
209bbfad078Smrg      echo "You may want to install the Perl 5 language interpreter:"
210bbfad078Smrg      echo "<$perl_URL>"
211bbfad078Smrg      ;;
21268af480fSmrg    *)
21368af480fSmrg      echo "You might have modified some files without having the proper"
21468af480fSmrg      echo "tools for further handling them.  Check the 'README' file, it"
21568af480fSmrg      echo "often tells you about the needed prerequisites for installing"
21668af480fSmrg      echo "this package.  You may also peek at any GNU archive site, in"
21768af480fSmrg      echo "case some other package contains this missing '$1' program."
21868af480fSmrg      ;;
21968af480fSmrg  esac
220bbfad078Smrg  program_details "$normalized_program"
22168af480fSmrg}
22268af480fSmrg
22368af480fSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
22468af480fSmrg                       -e '2,$s/^/         /' >&2
22568af480fSmrg
22668af480fSmrg# Propagate the correct exit status (expected to be 127 for a program
22768af480fSmrg# not found, 63 for a program that failed due to version mismatch).
22868af480fSmrgexit $st
229d7accfefSmrg
230d7accfefSmrg# Local variables:
231219ffec0Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
232d7accfefSmrg# time-stamp-start: "scriptversion="
233d7accfefSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234219ffec0Smrg# time-stamp-time-zone: "UTC0"
235d7accfefSmrg# time-stamp-end: "; # UTC"
236d7accfefSmrg# End:
237