1f33d31a3Smrg#! /bin/sh
28b5ec993Smrg# Common wrapper for a few potentially missing GNU and other programs.
3f33d31a3Smrg
48b5ec993Smrgscriptversion=2024-06-07.14; # UTC
5f33d31a3Smrg
68b5ec993Smrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
78b5ec993Smrg
88b5ec993Smrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
9f33d31a3Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
10f33d31a3Smrg
11f33d31a3Smrg# This program is free software; you can redistribute it and/or modify
12f33d31a3Smrg# it under the terms of the GNU General Public License as published by
13f33d31a3Smrg# the Free Software Foundation; either version 2, or (at your option)
14f33d31a3Smrg# any later version.
15f33d31a3Smrg
16f33d31a3Smrg# This program is distributed in the hope that it will be useful,
17f33d31a3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
18f33d31a3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19f33d31a3Smrg# GNU General Public License for more details.
20f33d31a3Smrg
21f33d31a3Smrg# You should have received a copy of the GNU General Public License
229f1d9476Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
23f33d31a3Smrg
24f33d31a3Smrg# As a special exception to the GNU General Public License, if you
25f33d31a3Smrg# distribute this file as part of a program that contains a
26f33d31a3Smrg# configuration script generated by Autoconf, you may include it under
27f33d31a3Smrg# the same distribution terms that you use for the rest of that program.
28f33d31a3Smrg
29f33d31a3Smrgif test $# -eq 0; then
30f33d31a3Smrg  echo 1>&2 "Try '$0 --help' for more information"
31f33d31a3Smrg  exit 1
32f33d31a3Smrgfi
33f33d31a3Smrg
34f33d31a3Smrgcase $1 in
35f33d31a3Smrg
36f33d31a3Smrg  --is-lightweight)
37f33d31a3Smrg    # Used by our autoconf macros to check whether the available missing
38f33d31a3Smrg    # script is modern enough.
39f33d31a3Smrg    exit 0
40f33d31a3Smrg    ;;
41f33d31a3Smrg
42f33d31a3Smrg  --run)
43f33d31a3Smrg    # Back-compat with the calling convention used by older automake.
44f33d31a3Smrg    shift
45f33d31a3Smrg    ;;
46f33d31a3Smrg
47f33d31a3Smrg  -h|--h|--he|--hel|--help)
48f33d31a3Smrg    echo "\
49f33d31a3Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
50f33d31a3Smrg
51f33d31a3SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
52f33d31a3Smrgto PROGRAM being missing or too old.
53f33d31a3Smrg
54f33d31a3SmrgOptions:
55f33d31a3Smrg  -h, --help      display this help and exit
56f33d31a3Smrg  -v, --version   output version information and exit
57f33d31a3Smrg
58f33d31a3SmrgSupported PROGRAM values:
598b5ec993Smrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
608b5ec993Smrgbison   flex     help2man lex        makeinfo perl     yacc
61f33d31a3Smrg
62f33d31a3SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
63f33d31a3Smrg'g' are ignored when checking the name.
64f33d31a3Smrg
658b5ec993SmrgReport bugs to <bug-automake@gnu.org>.
668b5ec993SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
678b5ec993SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
68f33d31a3Smrg    exit $?
69f33d31a3Smrg    ;;
70f33d31a3Smrg
71f33d31a3Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
728b5ec993Smrg    echo "missing (GNU Automake) $scriptversion"
73f33d31a3Smrg    exit $?
74f33d31a3Smrg    ;;
75f33d31a3Smrg
76f33d31a3Smrg  -*)
77f33d31a3Smrg    echo 1>&2 "$0: unknown '$1' option"
78f33d31a3Smrg    echo 1>&2 "Try '$0 --help' for more information"
79f33d31a3Smrg    exit 1
80f33d31a3Smrg    ;;
81f33d31a3Smrg
82f33d31a3Smrgesac
83f33d31a3Smrg
84f33d31a3Smrg# Run the given program, remember its exit status.
85f33d31a3Smrg"$@"; st=$?
86f33d31a3Smrg
87f33d31a3Smrg# If it succeeded, we are done.
88f33d31a3Smrgtest $st -eq 0 && exit 0
89f33d31a3Smrg
90f33d31a3Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
91f33d31a3Smrg# passed; such an option is passed most likely to detect whether the
92f33d31a3Smrg# program is present and works.
93f33d31a3Smrgcase $2 in --version|--help) exit $st;; esac
94f33d31a3Smrg
95f33d31a3Smrg# Exit code 63 means version mismatch.  This often happens when the user
96f33d31a3Smrg# tries to use an ancient version of a tool on a file that requires a
97f33d31a3Smrg# minimum version.
98f33d31a3Smrgif test $st -eq 63; then
99f33d31a3Smrg  msg="probably too old"
100f33d31a3Smrgelif test $st -eq 127; then
101f33d31a3Smrg  # Program was missing.
102f33d31a3Smrg  msg="missing on your system"
103f33d31a3Smrgelse
104f33d31a3Smrg  # Program was found and executed, but failed.  Give up.
105f33d31a3Smrg  exit $st
106f33d31a3Smrgfi
107f33d31a3Smrg
1089f1d9476Smrgperl_URL=https://www.perl.org/
1099f1d9476Smrgflex_URL=https://github.com/westes/flex
1109f1d9476Smrggnu_software_URL=https://www.gnu.org/software
111f33d31a3Smrg
112f33d31a3Smrgprogram_details ()
113f33d31a3Smrg{
114f33d31a3Smrg  case $1 in
1158b5ec993Smrg    aclocal|automake|autoreconf)
116f33d31a3Smrg      echo "The '$1' program is part of the GNU Automake package:"
117f33d31a3Smrg      echo "<$gnu_software_URL/automake>"
118f33d31a3Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
119f33d31a3Smrg      echo "<$gnu_software_URL/autoconf>"
120f33d31a3Smrg      echo "<$gnu_software_URL/m4/>"
121f33d31a3Smrg      echo "<$perl_URL>"
122f33d31a3Smrg      ;;
123f33d31a3Smrg    autoconf|autom4te|autoheader)
124f33d31a3Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
125f33d31a3Smrg      echo "<$gnu_software_URL/autoconf/>"
126f33d31a3Smrg      echo "It also requires GNU m4 and Perl in order to run:"
127f33d31a3Smrg      echo "<$gnu_software_URL/m4/>"
128f33d31a3Smrg      echo "<$perl_URL>"
129f33d31a3Smrg      ;;
1308b5ec993Smrg    *)
1318b5ec993Smrg      :
1328b5ec993Smrg      ;;
133f33d31a3Smrg  esac
134f33d31a3Smrg}
135f33d31a3Smrg
136f33d31a3Smrggive_advice ()
137f33d31a3Smrg{
138f33d31a3Smrg  # Normalize program name to check for.
139f33d31a3Smrg  normalized_program=`echo "$1" | sed '
140f33d31a3Smrg    s/^gnu-//; t
141f33d31a3Smrg    s/^gnu//; t
142f33d31a3Smrg    s/^g//; t'`
143f33d31a3Smrg
144f33d31a3Smrg  printf '%s\n' "'$1' is $msg."
145f33d31a3Smrg
146f33d31a3Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1478b5ec993Smrg  autoheader_deps="'acconfig.h'"
1488b5ec993Smrg  automake_deps="'Makefile.am'"
1498b5ec993Smrg  aclocal_deps="'acinclude.m4'"
150f33d31a3Smrg  case $normalized_program in
1518b5ec993Smrg    aclocal*)
1528b5ec993Smrg      echo "You should only need it if you modified $aclocal_deps or"
1538b5ec993Smrg      echo "$configure_deps."
1548b5ec993Smrg      ;;
155f33d31a3Smrg    autoconf*)
1568b5ec993Smrg      echo "You should only need it if you modified $configure_deps."
1578b5ec993Smrg      ;;
1588b5ec993Smrg    autogen*)
1598b5ec993Smrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
1608b5ec993Smrg      echo "You may want to install the GNU AutoGen package:"
1618b5ec993Smrg      echo "<$gnu_software_URL/autogen/>"
162f33d31a3Smrg      ;;
163f33d31a3Smrg    autoheader*)
1648b5ec993Smrg      echo "You should only need it if you modified $autoheader_deps or"
165f33d31a3Smrg      echo "$configure_deps."
166f33d31a3Smrg      ;;
167f33d31a3Smrg    automake*)
1688b5ec993Smrg      echo "You should only need it if you modified $automake_deps or"
169f33d31a3Smrg      echo "$configure_deps."
170f33d31a3Smrg      ;;
1718b5ec993Smrg    autom4te*)
172f33d31a3Smrg      echo "You might have modified some maintainer files that require"
173f33d31a3Smrg      echo "the 'autom4te' program to be rebuilt."
1748b5ec993Smrg      ;;
1758b5ec993Smrg    autoreconf*)
1768b5ec993Smrg      echo "You should only need it if you modified $aclocal_deps or"
1778b5ec993Smrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
1788b5ec993Smrg      echo "$configure_deps."
179f33d31a3Smrg      ;;
180f33d31a3Smrg    bison*|yacc*)
181f33d31a3Smrg      echo "You should only need it if you modified a '.y' file."
182f33d31a3Smrg      echo "You may want to install the GNU Bison package:"
183f33d31a3Smrg      echo "<$gnu_software_URL/bison/>"
184f33d31a3Smrg      ;;
185f33d31a3Smrg    help2man*)
186f33d31a3Smrg      echo "You should only need it if you modified a dependency" \
187f33d31a3Smrg           "of a man page."
188f33d31a3Smrg      echo "You may want to install the GNU Help2man package:"
189f33d31a3Smrg      echo "<$gnu_software_URL/help2man/>"
190f33d31a3Smrg    ;;
1918b5ec993Smrg    lex*|flex*)
1928b5ec993Smrg      echo "You should only need it if you modified a '.l' file."
1938b5ec993Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1948b5ec993Smrg      echo "<$flex_URL>"
1958b5ec993Smrg      ;;
196f33d31a3Smrg    makeinfo*)
197f33d31a3Smrg      echo "You should only need it if you modified a '.texi' file, or"
198f33d31a3Smrg      echo "any other file indirectly affecting the aspect of the manual."
199f33d31a3Smrg      echo "You might want to install the Texinfo package:"
200f33d31a3Smrg      echo "<$gnu_software_URL/texinfo/>"
201f33d31a3Smrg      echo "The spurious makeinfo call might also be the consequence of"
202f33d31a3Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
203f33d31a3Smrg      echo "want to install GNU make:"
204f33d31a3Smrg      echo "<$gnu_software_URL/make/>"
205f33d31a3Smrg      ;;
2068b5ec993Smrg    perl*)
2078b5ec993Smrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
2088b5ec993Smrg      echo "  assorted other tools, or if you modified a Perl source file."
2098b5ec993Smrg      echo "You may want to install the Perl 5 language interpreter:"
2108b5ec993Smrg      echo "<$perl_URL>"
2118b5ec993Smrg      ;;
212f33d31a3Smrg    *)
213f33d31a3Smrg      echo "You might have modified some files without having the proper"
214f33d31a3Smrg      echo "tools for further handling them.  Check the 'README' file, it"
215f33d31a3Smrg      echo "often tells you about the needed prerequisites for installing"
216f33d31a3Smrg      echo "this package.  You may also peek at any GNU archive site, in"
217f33d31a3Smrg      echo "case some other package contains this missing '$1' program."
218f33d31a3Smrg      ;;
219f33d31a3Smrg  esac
2208b5ec993Smrg  program_details "$normalized_program"
221f33d31a3Smrg}
222f33d31a3Smrg
223f33d31a3Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
224f33d31a3Smrg                       -e '2,$s/^/         /' >&2
225f33d31a3Smrg
226f33d31a3Smrg# Propagate the correct exit status (expected to be 127 for a program
227f33d31a3Smrg# not found, 63 for a program that failed due to version mismatch).
228f33d31a3Smrgexit $st
229f33d31a3Smrg
230f33d31a3Smrg# Local variables:
2319f1d9476Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
232f33d31a3Smrg# time-stamp-start: "scriptversion="
233f33d31a3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2349f1d9476Smrg# time-stamp-time-zone: "UTC0"
235f33d31a3Smrg# time-stamp-end: "; # UTC"
236f33d31a3Smrg# End:
237