11ab64890Smrg#! /bin/sh
23b4ba46cSmrg# Common wrapper for a few potentially missing GNU and other programs.
31ab64890Smrg
43b4ba46cSmrgscriptversion=2024-06-07.14; # UTC
51ab64890Smrg
63b4ba46cSmrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
73b4ba46cSmrg
83b4ba46cSmrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
9eb411b4bSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
101ab64890Smrg
111ab64890Smrg# This program is free software; you can redistribute it and/or modify
121ab64890Smrg# it under the terms of the GNU General Public License as published by
131ab64890Smrg# the Free Software Foundation; either version 2, or (at your option)
141ab64890Smrg# any later version.
151ab64890Smrg
161ab64890Smrg# This program is distributed in the hope that it will be useful,
171ab64890Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
181ab64890Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
191ab64890Smrg# GNU General Public License for more details.
201ab64890Smrg
211ab64890Smrg# You should have received a copy of the GNU General Public License
227d2c738bSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
231ab64890Smrg
241ab64890Smrg# As a special exception to the GNU General Public License, if you
251ab64890Smrg# distribute this file as part of a program that contains a
261ab64890Smrg# configuration script generated by Autoconf, you may include it under
271ab64890Smrg# the same distribution terms that you use for the rest of that program.
281ab64890Smrg
291ab64890Smrgif test $# -eq 0; then
30eb411b4bSmrg  echo 1>&2 "Try '$0 --help' for more information"
311ab64890Smrg  exit 1
321ab64890Smrgfi
331ab64890Smrg
34eb411b4bSmrgcase $1 in
351ab64890Smrg
36eb411b4bSmrg  --is-lightweight)
37eb411b4bSmrg    # Used by our autoconf macros to check whether the available missing
38eb411b4bSmrg    # script is modern enough.
39eb411b4bSmrg    exit 0
40eb411b4bSmrg    ;;
411ab64890Smrg
42eb411b4bSmrg  --run)
43eb411b4bSmrg    # Back-compat with the calling convention used by older automake.
44eb411b4bSmrg    shift
45eb411b4bSmrg    ;;
461ab64890Smrg
471ab64890Smrg  -h|--h|--he|--hel|--help)
481ab64890Smrg    echo "\
491ab64890Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
501ab64890Smrg
51eb411b4bSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
52eb411b4bSmrgto PROGRAM being missing or too old.
531ab64890Smrg
541ab64890SmrgOptions:
551ab64890Smrg  -h, --help      display this help and exit
561ab64890Smrg  -v, --version   output version information and exit
571ab64890Smrg
581ab64890SmrgSupported PROGRAM values:
593b4ba46cSmrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
603b4ba46cSmrgbison   flex     help2man lex        makeinfo perl     yacc
611ab64890Smrg
62eb411b4bSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
63eb411b4bSmrg'g' are ignored when checking the name.
64b4ee4795Smrg
653b4ba46cSmrgReport bugs to <bug-automake@gnu.org>.
663b4ba46cSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
673b4ba46cSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
681ab64890Smrg    exit $?
691ab64890Smrg    ;;
701ab64890Smrg
711ab64890Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
723b4ba46cSmrg    echo "missing (GNU Automake) $scriptversion"
731ab64890Smrg    exit $?
741ab64890Smrg    ;;
751ab64890Smrg
761ab64890Smrg  -*)
77eb411b4bSmrg    echo 1>&2 "$0: unknown '$1' option"
78eb411b4bSmrg    echo 1>&2 "Try '$0 --help' for more information"
791ab64890Smrg    exit 1
801ab64890Smrg    ;;
811ab64890Smrg
821ab64890Smrgesac
831ab64890Smrg
84eb411b4bSmrg# Run the given program, remember its exit status.
85eb411b4bSmrg"$@"; st=$?
86eb411b4bSmrg
87eb411b4bSmrg# If it succeeded, we are done.
88eb411b4bSmrgtest $st -eq 0 && exit 0
89eb411b4bSmrg
90eb411b4bSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
91eb411b4bSmrg# passed; such an option is passed most likely to detect whether the
92eb411b4bSmrg# program is present and works.
93eb411b4bSmrgcase $2 in --version|--help) exit $st;; esac
94eb411b4bSmrg
95eb411b4bSmrg# Exit code 63 means version mismatch.  This often happens when the user
96eb411b4bSmrg# tries to use an ancient version of a tool on a file that requires a
97eb411b4bSmrg# minimum version.
98eb411b4bSmrgif test $st -eq 63; then
99eb411b4bSmrg  msg="probably too old"
100eb411b4bSmrgelif test $st -eq 127; then
101eb411b4bSmrg  # Program was missing.
102eb411b4bSmrg  msg="missing on your system"
103eb411b4bSmrgelse
104eb411b4bSmrg  # Program was found and executed, but failed.  Give up.
105eb411b4bSmrg  exit $st
106eb411b4bSmrgfi
1071ab64890Smrg
1087d2c738bSmrgperl_URL=https://www.perl.org/
1097d2c738bSmrgflex_URL=https://github.com/westes/flex
1107d2c738bSmrggnu_software_URL=https://www.gnu.org/software
111eb411b4bSmrg
112eb411b4bSmrgprogram_details ()
113eb411b4bSmrg{
114eb411b4bSmrg  case $1 in
1153b4ba46cSmrg    aclocal|automake|autoreconf)
116eb411b4bSmrg      echo "The '$1' program is part of the GNU Automake package:"
117eb411b4bSmrg      echo "<$gnu_software_URL/automake>"
118eb411b4bSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
119eb411b4bSmrg      echo "<$gnu_software_URL/autoconf>"
120eb411b4bSmrg      echo "<$gnu_software_URL/m4/>"
121eb411b4bSmrg      echo "<$perl_URL>"
122eb411b4bSmrg      ;;
123eb411b4bSmrg    autoconf|autom4te|autoheader)
124eb411b4bSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
125eb411b4bSmrg      echo "<$gnu_software_URL/autoconf/>"
126eb411b4bSmrg      echo "It also requires GNU m4 and Perl in order to run:"
127eb411b4bSmrg      echo "<$gnu_software_URL/m4/>"
128eb411b4bSmrg      echo "<$perl_URL>"
129eb411b4bSmrg      ;;
1303b4ba46cSmrg    *)
1313b4ba46cSmrg      :
1323b4ba46cSmrg      ;;
133eb411b4bSmrg  esac
134eb411b4bSmrg}
135eb411b4bSmrg
136eb411b4bSmrggive_advice ()
137eb411b4bSmrg{
138eb411b4bSmrg  # Normalize program name to check for.
139eb411b4bSmrg  normalized_program=`echo "$1" | sed '
140eb411b4bSmrg    s/^gnu-//; t
141eb411b4bSmrg    s/^gnu//; t
142eb411b4bSmrg    s/^g//; t'`
143eb411b4bSmrg
144eb411b4bSmrg  printf '%s\n' "'$1' is $msg."
145eb411b4bSmrg
146eb411b4bSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1473b4ba46cSmrg  autoheader_deps="'acconfig.h'"
1483b4ba46cSmrg  automake_deps="'Makefile.am'"
1493b4ba46cSmrg  aclocal_deps="'acinclude.m4'"
150eb411b4bSmrg  case $normalized_program in
1513b4ba46cSmrg    aclocal*)
1523b4ba46cSmrg      echo "You should only need it if you modified $aclocal_deps or"
1533b4ba46cSmrg      echo "$configure_deps."
1543b4ba46cSmrg      ;;
155eb411b4bSmrg    autoconf*)
1563b4ba46cSmrg      echo "You should only need it if you modified $configure_deps."
1573b4ba46cSmrg      ;;
1583b4ba46cSmrg    autogen*)
1593b4ba46cSmrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
1603b4ba46cSmrg      echo "You may want to install the GNU AutoGen package:"
1613b4ba46cSmrg      echo "<$gnu_software_URL/autogen/>"
162eb411b4bSmrg      ;;
163eb411b4bSmrg    autoheader*)
1643b4ba46cSmrg      echo "You should only need it if you modified $autoheader_deps or"
165eb411b4bSmrg      echo "$configure_deps."
166eb411b4bSmrg      ;;
167eb411b4bSmrg    automake*)
1683b4ba46cSmrg      echo "You should only need it if you modified $automake_deps or"
169eb411b4bSmrg      echo "$configure_deps."
170eb411b4bSmrg      ;;
1713b4ba46cSmrg    autom4te*)
172eb411b4bSmrg      echo "You might have modified some maintainer files that require"
1730f8248bfSmrg      echo "the 'autom4te' program to be rebuilt."
1743b4ba46cSmrg      ;;
1753b4ba46cSmrg    autoreconf*)
1763b4ba46cSmrg      echo "You should only need it if you modified $aclocal_deps or"
1773b4ba46cSmrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
1783b4ba46cSmrg      echo "$configure_deps."
179eb411b4bSmrg      ;;
180eb411b4bSmrg    bison*|yacc*)
181eb411b4bSmrg      echo "You should only need it if you modified a '.y' file."
182eb411b4bSmrg      echo "You may want to install the GNU Bison package:"
183eb411b4bSmrg      echo "<$gnu_software_URL/bison/>"
184eb411b4bSmrg      ;;
185eb411b4bSmrg    help2man*)
186eb411b4bSmrg      echo "You should only need it if you modified a dependency" \
187eb411b4bSmrg           "of a man page."
188eb411b4bSmrg      echo "You may want to install the GNU Help2man package:"
189eb411b4bSmrg      echo "<$gnu_software_URL/help2man/>"
190eb411b4bSmrg    ;;
1913b4ba46cSmrg    lex*|flex*)
1923b4ba46cSmrg      echo "You should only need it if you modified a '.l' file."
1933b4ba46cSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1943b4ba46cSmrg      echo "<$flex_URL>"
1953b4ba46cSmrg      ;;
196eb411b4bSmrg    makeinfo*)
197eb411b4bSmrg      echo "You should only need it if you modified a '.texi' file, or"
198eb411b4bSmrg      echo "any other file indirectly affecting the aspect of the manual."
199eb411b4bSmrg      echo "You might want to install the Texinfo package:"
200eb411b4bSmrg      echo "<$gnu_software_URL/texinfo/>"
201eb411b4bSmrg      echo "The spurious makeinfo call might also be the consequence of"
202eb411b4bSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
203eb411b4bSmrg      echo "want to install GNU make:"
204eb411b4bSmrg      echo "<$gnu_software_URL/make/>"
205eb411b4bSmrg      ;;
2063b4ba46cSmrg    perl*)
2073b4ba46cSmrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
2083b4ba46cSmrg      echo "  assorted other tools, or if you modified a Perl source file."
2093b4ba46cSmrg      echo "You may want to install the Perl 5 language interpreter:"
2103b4ba46cSmrg      echo "<$perl_URL>"
2113b4ba46cSmrg      ;;
212eb411b4bSmrg    *)
213eb411b4bSmrg      echo "You might have modified some files without having the proper"
214eb411b4bSmrg      echo "tools for further handling them.  Check the 'README' file, it"
215eb411b4bSmrg      echo "often tells you about the needed prerequisites for installing"
216eb411b4bSmrg      echo "this package.  You may also peek at any GNU archive site, in"
217eb411b4bSmrg      echo "case some other package contains this missing '$1' program."
218eb411b4bSmrg      ;;
219eb411b4bSmrg  esac
2203b4ba46cSmrg  program_details "$normalized_program"
221eb411b4bSmrg}
222eb411b4bSmrg
223eb411b4bSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
224eb411b4bSmrg                       -e '2,$s/^/         /' >&2
225eb411b4bSmrg
226eb411b4bSmrg# Propagate the correct exit status (expected to be 127 for a program
227eb411b4bSmrg# not found, 63 for a program that failed due to version mismatch).
228eb411b4bSmrgexit $st
2291ab64890Smrg
2301ab64890Smrg# Local variables:
2317d2c738bSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2321ab64890Smrg# time-stamp-start: "scriptversion="
2331ab64890Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2347d2c738bSmrg# time-stamp-time-zone: "UTC0"
235b4ee4795Smrg# time-stamp-end: "; # UTC"
2361ab64890Smrg# End:
237