missing revision eb323118
129459361Smrg#! /bin/sh
2eb323118Smrg# Common wrapper for a few potentially missing GNU and other programs.
329459361Smrg
4eb323118Smrgscriptversion=2024-06-07.14; # UTC
529459361Smrg
6eb323118Smrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
7eb323118Smrg
8eb323118Smrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
9fb4ebca8Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
1029459361Smrg
1129459361Smrg# This program is free software; you can redistribute it and/or modify
1229459361Smrg# it under the terms of the GNU General Public License as published by
1329459361Smrg# the Free Software Foundation; either version 2, or (at your option)
1429459361Smrg# any later version.
1529459361Smrg
1629459361Smrg# This program is distributed in the hope that it will be useful,
1729459361Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1829459361Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1929459361Smrg# GNU General Public License for more details.
2029459361Smrg
2129459361Smrg# You should have received a copy of the GNU General Public License
22e24f450bSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2329459361Smrg
2429459361Smrg# As a special exception to the GNU General Public License, if you
2529459361Smrg# distribute this file as part of a program that contains a
2629459361Smrg# configuration script generated by Autoconf, you may include it under
2729459361Smrg# the same distribution terms that you use for the rest of that program.
2829459361Smrg
2929459361Smrgif test $# -eq 0; then
30fb4ebca8Smrg  echo 1>&2 "Try '$0 --help' for more information"
3129459361Smrg  exit 1
3229459361Smrgfi
3329459361Smrg
34fb4ebca8Smrgcase $1 in
3529459361Smrg
36fb4ebca8Smrg  --is-lightweight)
37fb4ebca8Smrg    # Used by our autoconf macros to check whether the available missing
38fb4ebca8Smrg    # script is modern enough.
39fb4ebca8Smrg    exit 0
40fb4ebca8Smrg    ;;
4129459361Smrg
42fb4ebca8Smrg  --run)
43fb4ebca8Smrg    # Back-compat with the calling convention used by older automake.
44fb4ebca8Smrg    shift
45fb4ebca8Smrg    ;;
4629459361Smrg
4729459361Smrg  -h|--h|--he|--hel|--help)
4829459361Smrg    echo "\
4929459361Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
5029459361Smrg
51fb4ebca8SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
52fb4ebca8Smrgto PROGRAM being missing or too old.
5329459361Smrg
5429459361SmrgOptions:
5529459361Smrg  -h, --help      display this help and exit
5629459361Smrg  -v, --version   output version information and exit
5729459361Smrg
5829459361SmrgSupported PROGRAM values:
59eb323118Smrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
60eb323118Smrgbison   flex     help2man lex        makeinfo perl     yacc
6129459361Smrg
62fb4ebca8SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
63fb4ebca8Smrg'g' are ignored when checking the name.
6447202d7bSmrg
65eb323118SmrgReport bugs to <bug-automake@gnu.org>.
66eb323118SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
67eb323118SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
6829459361Smrg    exit $?
6929459361Smrg    ;;
7029459361Smrg
7129459361Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
72eb323118Smrg    echo "missing (GNU Automake) $scriptversion"
7329459361Smrg    exit $?
7429459361Smrg    ;;
7529459361Smrg
7629459361Smrg  -*)
77fb4ebca8Smrg    echo 1>&2 "$0: unknown '$1' option"
78fb4ebca8Smrg    echo 1>&2 "Try '$0 --help' for more information"
7929459361Smrg    exit 1
8029459361Smrg    ;;
8129459361Smrg
8229459361Smrgesac
8329459361Smrg
84fb4ebca8Smrg# Run the given program, remember its exit status.
85fb4ebca8Smrg"$@"; st=$?
86fb4ebca8Smrg
87fb4ebca8Smrg# If it succeeded, we are done.
88fb4ebca8Smrgtest $st -eq 0 && exit 0
89fb4ebca8Smrg
90fb4ebca8Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
91fb4ebca8Smrg# passed; such an option is passed most likely to detect whether the
92fb4ebca8Smrg# program is present and works.
93fb4ebca8Smrgcase $2 in --version|--help) exit $st;; esac
94fb4ebca8Smrg
95fb4ebca8Smrg# Exit code 63 means version mismatch.  This often happens when the user
96fb4ebca8Smrg# tries to use an ancient version of a tool on a file that requires a
97fb4ebca8Smrg# minimum version.
98fb4ebca8Smrgif test $st -eq 63; then
99fb4ebca8Smrg  msg="probably too old"
100fb4ebca8Smrgelif test $st -eq 127; then
101fb4ebca8Smrg  # Program was missing.
102fb4ebca8Smrg  msg="missing on your system"
103fb4ebca8Smrgelse
104fb4ebca8Smrg  # Program was found and executed, but failed.  Give up.
105fb4ebca8Smrg  exit $st
106fb4ebca8Smrgfi
10729459361Smrg
108e24f450bSmrgperl_URL=https://www.perl.org/
109e24f450bSmrgflex_URL=https://github.com/westes/flex
110e24f450bSmrggnu_software_URL=https://www.gnu.org/software
111fb4ebca8Smrg
112fb4ebca8Smrgprogram_details ()
113fb4ebca8Smrg{
114fb4ebca8Smrg  case $1 in
115eb323118Smrg    aclocal|automake|autoreconf)
116fb4ebca8Smrg      echo "The '$1' program is part of the GNU Automake package:"
117fb4ebca8Smrg      echo "<$gnu_software_URL/automake>"
118fb4ebca8Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
119fb4ebca8Smrg      echo "<$gnu_software_URL/autoconf>"
120fb4ebca8Smrg      echo "<$gnu_software_URL/m4/>"
121fb4ebca8Smrg      echo "<$perl_URL>"
122fb4ebca8Smrg      ;;
123fb4ebca8Smrg    autoconf|autom4te|autoheader)
124fb4ebca8Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
125fb4ebca8Smrg      echo "<$gnu_software_URL/autoconf/>"
126fb4ebca8Smrg      echo "It also requires GNU m4 and Perl in order to run:"
127fb4ebca8Smrg      echo "<$gnu_software_URL/m4/>"
128fb4ebca8Smrg      echo "<$perl_URL>"
129fb4ebca8Smrg      ;;
130eb323118Smrg    *)
131eb323118Smrg      :
132eb323118Smrg      ;;
133fb4ebca8Smrg  esac
134fb4ebca8Smrg}
135fb4ebca8Smrg
136fb4ebca8Smrggive_advice ()
137fb4ebca8Smrg{
138fb4ebca8Smrg  # Normalize program name to check for.
139fb4ebca8Smrg  normalized_program=`echo "$1" | sed '
140fb4ebca8Smrg    s/^gnu-//; t
141fb4ebca8Smrg    s/^gnu//; t
142fb4ebca8Smrg    s/^g//; t'`
143fb4ebca8Smrg
144fb4ebca8Smrg  printf '%s\n' "'$1' is $msg."
145fb4ebca8Smrg
146fb4ebca8Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
147eb323118Smrg  autoheader_deps="'acconfig.h'"
148eb323118Smrg  automake_deps="'Makefile.am'"
149eb323118Smrg  aclocal_deps="'acinclude.m4'"
150fb4ebca8Smrg  case $normalized_program in
151eb323118Smrg    aclocal*)
152eb323118Smrg      echo "You should only need it if you modified $aclocal_deps or"
153eb323118Smrg      echo "$configure_deps."
154eb323118Smrg      ;;
155fb4ebca8Smrg    autoconf*)
156eb323118Smrg      echo "You should only need it if you modified $configure_deps."
157eb323118Smrg      ;;
158eb323118Smrg    autogen*)
159eb323118Smrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
160eb323118Smrg      echo "You may want to install the GNU AutoGen package:"
161eb323118Smrg      echo "<$gnu_software_URL/autogen/>"
162fb4ebca8Smrg      ;;
163fb4ebca8Smrg    autoheader*)
164eb323118Smrg      echo "You should only need it if you modified $autoheader_deps or"
165fb4ebca8Smrg      echo "$configure_deps."
166fb4ebca8Smrg      ;;
167fb4ebca8Smrg    automake*)
168eb323118Smrg      echo "You should only need it if you modified $automake_deps or"
169fb4ebca8Smrg      echo "$configure_deps."
170fb4ebca8Smrg      ;;
171eb323118Smrg    autom4te*)
172fb4ebca8Smrg      echo "You might have modified some maintainer files that require"
173fb4ebca8Smrg      echo "the 'autom4te' program to be rebuilt."
174eb323118Smrg      ;;
175eb323118Smrg    autoreconf*)
176eb323118Smrg      echo "You should only need it if you modified $aclocal_deps or"
177eb323118Smrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
178eb323118Smrg      echo "$configure_deps."
179fb4ebca8Smrg      ;;
180fb4ebca8Smrg    bison*|yacc*)
181fb4ebca8Smrg      echo "You should only need it if you modified a '.y' file."
182fb4ebca8Smrg      echo "You may want to install the GNU Bison package:"
183fb4ebca8Smrg      echo "<$gnu_software_URL/bison/>"
184fb4ebca8Smrg      ;;
185fb4ebca8Smrg    help2man*)
186fb4ebca8Smrg      echo "You should only need it if you modified a dependency" \
187fb4ebca8Smrg           "of a man page."
188fb4ebca8Smrg      echo "You may want to install the GNU Help2man package:"
189fb4ebca8Smrg      echo "<$gnu_software_URL/help2man/>"
190fb4ebca8Smrg    ;;
191eb323118Smrg    lex*|flex*)
192eb323118Smrg      echo "You should only need it if you modified a '.l' file."
193eb323118Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
194eb323118Smrg      echo "<$flex_URL>"
195eb323118Smrg      ;;
196fb4ebca8Smrg    makeinfo*)
197fb4ebca8Smrg      echo "You should only need it if you modified a '.texi' file, or"
198fb4ebca8Smrg      echo "any other file indirectly affecting the aspect of the manual."
199fb4ebca8Smrg      echo "You might want to install the Texinfo package:"
200fb4ebca8Smrg      echo "<$gnu_software_URL/texinfo/>"
201fb4ebca8Smrg      echo "The spurious makeinfo call might also be the consequence of"
202fb4ebca8Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
203fb4ebca8Smrg      echo "want to install GNU make:"
204fb4ebca8Smrg      echo "<$gnu_software_URL/make/>"
205fb4ebca8Smrg      ;;
206eb323118Smrg    perl*)
207eb323118Smrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
208eb323118Smrg      echo "  assorted other tools, or if you modified a Perl source file."
209eb323118Smrg      echo "You may want to install the Perl 5 language interpreter:"
210eb323118Smrg      echo "<$perl_URL>"
211eb323118Smrg      ;;
212fb4ebca8Smrg    *)
213fb4ebca8Smrg      echo "You might have modified some files without having the proper"
214fb4ebca8Smrg      echo "tools for further handling them.  Check the 'README' file, it"
215fb4ebca8Smrg      echo "often tells you about the needed prerequisites for installing"
216fb4ebca8Smrg      echo "this package.  You may also peek at any GNU archive site, in"
217fb4ebca8Smrg      echo "case some other package contains this missing '$1' program."
218fb4ebca8Smrg      ;;
219fb4ebca8Smrg  esac
220eb323118Smrg  program_details "$normalized_program"
221fb4ebca8Smrg}
222fb4ebca8Smrg
223fb4ebca8Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
224fb4ebca8Smrg                       -e '2,$s/^/         /' >&2
225fb4ebca8Smrg
226fb4ebca8Smrg# Propagate the correct exit status (expected to be 127 for a program
227fb4ebca8Smrg# not found, 63 for a program that failed due to version mismatch).
228fb4ebca8Smrgexit $st
22929459361Smrg
23029459361Smrg# Local variables:
231e24f450bSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
23229459361Smrg# time-stamp-start: "scriptversion="
23329459361Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234fa2b3b63Smrg# time-stamp-time-zone: "UTC0"
23547202d7bSmrg# time-stamp-end: "; # UTC"
23629459361Smrg# End:
237