16ea72052Smrg#! /bin/sh
2e32e2dabSmrg# Common wrapper for a few potentially missing GNU and other programs.
3168023feSmrg
4e32e2dabSmrgscriptversion=2024-06-07.14; # UTC
5168023feSmrg
6e32e2dabSmrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
7e32e2dabSmrg
8e32e2dabSmrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
9b0c24a08Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
106ea72052Smrg
116ea72052Smrg# This program is free software; you can redistribute it and/or modify
126ea72052Smrg# it under the terms of the GNU General Public License as published by
136ea72052Smrg# the Free Software Foundation; either version 2, or (at your option)
146ea72052Smrg# any later version.
156ea72052Smrg
166ea72052Smrg# This program is distributed in the hope that it will be useful,
176ea72052Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
186ea72052Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
196ea72052Smrg# GNU General Public License for more details.
206ea72052Smrg
216ea72052Smrg# You should have received a copy of the GNU General Public License
22f3e6ffc5Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
236ea72052Smrg
246ea72052Smrg# As a special exception to the GNU General Public License, if you
256ea72052Smrg# distribute this file as part of a program that contains a
266ea72052Smrg# configuration script generated by Autoconf, you may include it under
276ea72052Smrg# the same distribution terms that you use for the rest of that program.
286ea72052Smrg
296ea72052Smrgif test $# -eq 0; then
30b0c24a08Smrg  echo 1>&2 "Try '$0 --help' for more information"
316ea72052Smrg  exit 1
326ea72052Smrgfi
336ea72052Smrg
34b0c24a08Smrgcase $1 in
356ea72052Smrg
36b0c24a08Smrg  --is-lightweight)
37b0c24a08Smrg    # Used by our autoconf macros to check whether the available missing
38b0c24a08Smrg    # script is modern enough.
39b0c24a08Smrg    exit 0
40b0c24a08Smrg    ;;
41168023feSmrg
42b0c24a08Smrg  --run)
43b0c24a08Smrg    # Back-compat with the calling convention used by older automake.
44b0c24a08Smrg    shift
45b0c24a08Smrg    ;;
466ea72052Smrg
476ea72052Smrg  -h|--h|--he|--hel|--help)
486ea72052Smrg    echo "\
496ea72052Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
506ea72052Smrg
51b0c24a08SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
52b0c24a08Smrgto PROGRAM being missing or too old.
536ea72052Smrg
546ea72052SmrgOptions:
556ea72052Smrg  -h, --help      display this help and exit
566ea72052Smrg  -v, --version   output version information and exit
576ea72052Smrg
586ea72052SmrgSupported PROGRAM values:
59e32e2dabSmrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
60e32e2dabSmrgbison   flex     help2man lex        makeinfo perl     yacc
61168023feSmrg
62b0c24a08SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
63b0c24a08Smrg'g' are ignored when checking the name.
64168023feSmrg
65e32e2dabSmrgReport bugs to <bug-automake@gnu.org>.
66e32e2dabSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
67e32e2dabSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
68168023feSmrg    exit $?
696ea72052Smrg    ;;
706ea72052Smrg
716ea72052Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
72e32e2dabSmrg    echo "missing (GNU Automake) $scriptversion"
73168023feSmrg    exit $?
746ea72052Smrg    ;;
756ea72052Smrg
766ea72052Smrg  -*)
77b0c24a08Smrg    echo 1>&2 "$0: unknown '$1' option"
78b0c24a08Smrg    echo 1>&2 "Try '$0 --help' for more information"
796ea72052Smrg    exit 1
806ea72052Smrg    ;;
816ea72052Smrg
82168023feSmrgesac
83168023feSmrg
84b0c24a08Smrg# Run the given program, remember its exit status.
85b0c24a08Smrg"$@"; st=$?
86b0c24a08Smrg
87b0c24a08Smrg# If it succeeded, we are done.
88b0c24a08Smrgtest $st -eq 0 && exit 0
89b0c24a08Smrg
90b0c24a08Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
91b0c24a08Smrg# passed; such an option is passed most likely to detect whether the
92b0c24a08Smrg# program is present and works.
93b0c24a08Smrgcase $2 in --version|--help) exit $st;; esac
94b0c24a08Smrg
95b0c24a08Smrg# Exit code 63 means version mismatch.  This often happens when the user
96b0c24a08Smrg# tries to use an ancient version of a tool on a file that requires a
97b0c24a08Smrg# minimum version.
98b0c24a08Smrgif test $st -eq 63; then
99b0c24a08Smrg  msg="probably too old"
100b0c24a08Smrgelif test $st -eq 127; then
101b0c24a08Smrg  # Program was missing.
102b0c24a08Smrg  msg="missing on your system"
103b0c24a08Smrgelse
104b0c24a08Smrg  # Program was found and executed, but failed.  Give up.
105b0c24a08Smrg  exit $st
106b0c24a08Smrgfi
1076ea72052Smrg
108f3e6ffc5Smrgperl_URL=https://www.perl.org/
109f3e6ffc5Smrgflex_URL=https://github.com/westes/flex
110f3e6ffc5Smrggnu_software_URL=https://www.gnu.org/software
111b0c24a08Smrg
112b0c24a08Smrgprogram_details ()
113b0c24a08Smrg{
114b0c24a08Smrg  case $1 in
115e32e2dabSmrg    aclocal|automake|autoreconf)
116b0c24a08Smrg      echo "The '$1' program is part of the GNU Automake package:"
117b0c24a08Smrg      echo "<$gnu_software_URL/automake>"
118b0c24a08Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
119b0c24a08Smrg      echo "<$gnu_software_URL/autoconf>"
120b0c24a08Smrg      echo "<$gnu_software_URL/m4/>"
121b0c24a08Smrg      echo "<$perl_URL>"
122b0c24a08Smrg      ;;
123b0c24a08Smrg    autoconf|autom4te|autoheader)
124b0c24a08Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
125b0c24a08Smrg      echo "<$gnu_software_URL/autoconf/>"
126b0c24a08Smrg      echo "It also requires GNU m4 and Perl in order to run:"
127b0c24a08Smrg      echo "<$gnu_software_URL/m4/>"
128b0c24a08Smrg      echo "<$perl_URL>"
129b0c24a08Smrg      ;;
130e32e2dabSmrg    *)
131e32e2dabSmrg      :
132e32e2dabSmrg      ;;
133b0c24a08Smrg  esac
134b0c24a08Smrg}
135b0c24a08Smrg
136b0c24a08Smrggive_advice ()
137b0c24a08Smrg{
138b0c24a08Smrg  # Normalize program name to check for.
139b0c24a08Smrg  normalized_program=`echo "$1" | sed '
140b0c24a08Smrg    s/^gnu-//; t
141b0c24a08Smrg    s/^gnu//; t
142b0c24a08Smrg    s/^g//; t'`
143b0c24a08Smrg
144b0c24a08Smrg  printf '%s\n' "'$1' is $msg."
145b0c24a08Smrg
146b0c24a08Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
147e32e2dabSmrg  autoheader_deps="'acconfig.h'"
148e32e2dabSmrg  automake_deps="'Makefile.am'"
149e32e2dabSmrg  aclocal_deps="'acinclude.m4'"
150b0c24a08Smrg  case $normalized_program in
151e32e2dabSmrg    aclocal*)
152e32e2dabSmrg      echo "You should only need it if you modified $aclocal_deps or"
153e32e2dabSmrg      echo "$configure_deps."
154e32e2dabSmrg      ;;
155b0c24a08Smrg    autoconf*)
156e32e2dabSmrg      echo "You should only need it if you modified $configure_deps."
157e32e2dabSmrg      ;;
158e32e2dabSmrg    autogen*)
159e32e2dabSmrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
160e32e2dabSmrg      echo "You may want to install the GNU AutoGen package:"
161e32e2dabSmrg      echo "<$gnu_software_URL/autogen/>"
162b0c24a08Smrg      ;;
163b0c24a08Smrg    autoheader*)
164e32e2dabSmrg      echo "You should only need it if you modified $autoheader_deps or"
165b0c24a08Smrg      echo "$configure_deps."
166b0c24a08Smrg      ;;
167b0c24a08Smrg    automake*)
168e32e2dabSmrg      echo "You should only need it if you modified $automake_deps or"
169b0c24a08Smrg      echo "$configure_deps."
170b0c24a08Smrg      ;;
171e32e2dabSmrg    autom4te*)
172b0c24a08Smrg      echo "You might have modified some maintainer files that require"
173b0c24a08Smrg      echo "the 'autom4te' program to be rebuilt."
174e32e2dabSmrg      ;;
175e32e2dabSmrg    autoreconf*)
176e32e2dabSmrg      echo "You should only need it if you modified $aclocal_deps or"
177e32e2dabSmrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
178e32e2dabSmrg      echo "$configure_deps."
179b0c24a08Smrg      ;;
180b0c24a08Smrg    bison*|yacc*)
181b0c24a08Smrg      echo "You should only need it if you modified a '.y' file."
182b0c24a08Smrg      echo "You may want to install the GNU Bison package:"
183b0c24a08Smrg      echo "<$gnu_software_URL/bison/>"
184b0c24a08Smrg      ;;
185b0c24a08Smrg    help2man*)
186b0c24a08Smrg      echo "You should only need it if you modified a dependency" \
187b0c24a08Smrg           "of a man page."
188b0c24a08Smrg      echo "You may want to install the GNU Help2man package:"
189b0c24a08Smrg      echo "<$gnu_software_URL/help2man/>"
190b0c24a08Smrg    ;;
191e32e2dabSmrg    lex*|flex*)
192e32e2dabSmrg      echo "You should only need it if you modified a '.l' file."
193e32e2dabSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
194e32e2dabSmrg      echo "<$flex_URL>"
195e32e2dabSmrg      ;;
196b0c24a08Smrg    makeinfo*)
197b0c24a08Smrg      echo "You should only need it if you modified a '.texi' file, or"
198b0c24a08Smrg      echo "any other file indirectly affecting the aspect of the manual."
199b0c24a08Smrg      echo "You might want to install the Texinfo package:"
200b0c24a08Smrg      echo "<$gnu_software_URL/texinfo/>"
201b0c24a08Smrg      echo "The spurious makeinfo call might also be the consequence of"
202b0c24a08Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
203b0c24a08Smrg      echo "want to install GNU make:"
204b0c24a08Smrg      echo "<$gnu_software_URL/make/>"
205b0c24a08Smrg      ;;
206e32e2dabSmrg    perl*)
207e32e2dabSmrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
208e32e2dabSmrg      echo "  assorted other tools, or if you modified a Perl source file."
209e32e2dabSmrg      echo "You may want to install the Perl 5 language interpreter:"
210e32e2dabSmrg      echo "<$perl_URL>"
211e32e2dabSmrg      ;;
212b0c24a08Smrg    *)
213b0c24a08Smrg      echo "You might have modified some files without having the proper"
214b0c24a08Smrg      echo "tools for further handling them.  Check the 'README' file, it"
215b0c24a08Smrg      echo "often tells you about the needed prerequisites for installing"
216b0c24a08Smrg      echo "this package.  You may also peek at any GNU archive site, in"
217b0c24a08Smrg      echo "case some other package contains this missing '$1' program."
218b0c24a08Smrg      ;;
219b0c24a08Smrg  esac
220e32e2dabSmrg  program_details "$normalized_program"
221b0c24a08Smrg}
222b0c24a08Smrg
223b0c24a08Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
224b0c24a08Smrg                       -e '2,$s/^/         /' >&2
225b0c24a08Smrg
226b0c24a08Smrg# Propagate the correct exit status (expected to be 127 for a program
227b0c24a08Smrg# not found, 63 for a program that failed due to version mismatch).
228b0c24a08Smrgexit $st
229168023feSmrg
230168023feSmrg# Local variables:
231f3e6ffc5Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
232168023feSmrg# time-stamp-start: "scriptversion="
233168023feSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234f3e6ffc5Smrg# time-stamp-time-zone: "UTC0"
235168023feSmrg# time-stamp-end: "; # UTC"
236168023feSmrg# End:
237