10eb10989Smrg#! /bin/sh
2079e7944Smrg# Common wrapper for a few potentially missing GNU programs.
30eb10989Smrg
474901992Smrgscriptversion=2018-03-07.03; # UTC
50eb10989Smrg
674901992Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7079e7944Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
80eb10989Smrg
90eb10989Smrg# This program is free software; you can redistribute it and/or modify
100eb10989Smrg# it under the terms of the GNU General Public License as published by
110eb10989Smrg# the Free Software Foundation; either version 2, or (at your option)
120eb10989Smrg# any later version.
130eb10989Smrg
140eb10989Smrg# This program is distributed in the hope that it will be useful,
150eb10989Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
160eb10989Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
170eb10989Smrg# GNU General Public License for more details.
180eb10989Smrg
190eb10989Smrg# You should have received a copy of the GNU General Public License
2074901992Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
210eb10989Smrg
220eb10989Smrg# As a special exception to the GNU General Public License, if you
230eb10989Smrg# distribute this file as part of a program that contains a
240eb10989Smrg# configuration script generated by Autoconf, you may include it under
250eb10989Smrg# the same distribution terms that you use for the rest of that program.
260eb10989Smrg
270eb10989Smrgif test $# -eq 0; then
28079e7944Smrg  echo 1>&2 "Try '$0 --help' for more information"
290eb10989Smrg  exit 1
300eb10989Smrgfi
310eb10989Smrg
32079e7944Smrgcase $1 in
330eb10989Smrg
34079e7944Smrg  --is-lightweight)
35079e7944Smrg    # Used by our autoconf macros to check whether the available missing
36079e7944Smrg    # script is modern enough.
37079e7944Smrg    exit 0
38079e7944Smrg    ;;
390eb10989Smrg
40079e7944Smrg  --run)
41079e7944Smrg    # Back-compat with the calling convention used by older automake.
42079e7944Smrg    shift
43079e7944Smrg    ;;
440eb10989Smrg
450eb10989Smrg  -h|--h|--he|--hel|--help)
460eb10989Smrg    echo "\
470eb10989Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
480eb10989Smrg
49079e7944SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50079e7944Smrgto PROGRAM being missing or too old.
510eb10989Smrg
520eb10989SmrgOptions:
530eb10989Smrg  -h, --help      display this help and exit
540eb10989Smrg  -v, --version   output version information and exit
550eb10989Smrg
560eb10989SmrgSupported PROGRAM values:
57079e7944Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58079e7944Smrg  bison     yacc      flex         lex       help2man
590eb10989Smrg
60079e7944SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61079e7944Smrg'g' are ignored when checking the name.
6263165362Smrg
630eb10989SmrgSend bug reports to <bug-automake@gnu.org>."
640eb10989Smrg    exit $?
650eb10989Smrg    ;;
660eb10989Smrg
670eb10989Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
680eb10989Smrg    echo "missing $scriptversion (GNU Automake)"
690eb10989Smrg    exit $?
700eb10989Smrg    ;;
710eb10989Smrg
720eb10989Smrg  -*)
73079e7944Smrg    echo 1>&2 "$0: unknown '$1' option"
74079e7944Smrg    echo 1>&2 "Try '$0 --help' for more information"
750eb10989Smrg    exit 1
760eb10989Smrg    ;;
770eb10989Smrg
780eb10989Smrgesac
790eb10989Smrg
80079e7944Smrg# Run the given program, remember its exit status.
81079e7944Smrg"$@"; st=$?
82079e7944Smrg
83079e7944Smrg# If it succeeded, we are done.
84079e7944Smrgtest $st -eq 0 && exit 0
85079e7944Smrg
86079e7944Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
87079e7944Smrg# passed; such an option is passed most likely to detect whether the
88079e7944Smrg# program is present and works.
89079e7944Smrgcase $2 in --version|--help) exit $st;; esac
90079e7944Smrg
91079e7944Smrg# Exit code 63 means version mismatch.  This often happens when the user
92079e7944Smrg# tries to use an ancient version of a tool on a file that requires a
93079e7944Smrg# minimum version.
94079e7944Smrgif test $st -eq 63; then
95079e7944Smrg  msg="probably too old"
96079e7944Smrgelif test $st -eq 127; then
97079e7944Smrg  # Program was missing.
98079e7944Smrg  msg="missing on your system"
99079e7944Smrgelse
100079e7944Smrg  # Program was found and executed, but failed.  Give up.
101079e7944Smrg  exit $st
102079e7944Smrgfi
1030eb10989Smrg
10474901992Smrgperl_URL=https://www.perl.org/
10574901992Smrgflex_URL=https://github.com/westes/flex
10674901992Smrggnu_software_URL=https://www.gnu.org/software
107079e7944Smrg
108079e7944Smrgprogram_details ()
109079e7944Smrg{
110079e7944Smrg  case $1 in
111079e7944Smrg    aclocal|automake)
112079e7944Smrg      echo "The '$1' program is part of the GNU Automake package:"
113079e7944Smrg      echo "<$gnu_software_URL/automake>"
114079e7944Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115079e7944Smrg      echo "<$gnu_software_URL/autoconf>"
116079e7944Smrg      echo "<$gnu_software_URL/m4/>"
117079e7944Smrg      echo "<$perl_URL>"
118079e7944Smrg      ;;
119079e7944Smrg    autoconf|autom4te|autoheader)
120079e7944Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
121079e7944Smrg      echo "<$gnu_software_URL/autoconf/>"
122079e7944Smrg      echo "It also requires GNU m4 and Perl in order to run:"
123079e7944Smrg      echo "<$gnu_software_URL/m4/>"
124079e7944Smrg      echo "<$perl_URL>"
125079e7944Smrg      ;;
126079e7944Smrg  esac
127079e7944Smrg}
128079e7944Smrg
129079e7944Smrggive_advice ()
130079e7944Smrg{
131079e7944Smrg  # Normalize program name to check for.
132079e7944Smrg  normalized_program=`echo "$1" | sed '
133079e7944Smrg    s/^gnu-//; t
134079e7944Smrg    s/^gnu//; t
135079e7944Smrg    s/^g//; t'`
136079e7944Smrg
137079e7944Smrg  printf '%s\n' "'$1' is $msg."
138079e7944Smrg
139079e7944Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140079e7944Smrg  case $normalized_program in
141079e7944Smrg    autoconf*)
142079e7944Smrg      echo "You should only need it if you modified 'configure.ac',"
143079e7944Smrg      echo "or m4 files included by it."
144079e7944Smrg      program_details 'autoconf'
145079e7944Smrg      ;;
146079e7944Smrg    autoheader*)
147079e7944Smrg      echo "You should only need it if you modified 'acconfig.h' or"
148079e7944Smrg      echo "$configure_deps."
149079e7944Smrg      program_details 'autoheader'
150079e7944Smrg      ;;
151079e7944Smrg    automake*)
152079e7944Smrg      echo "You should only need it if you modified 'Makefile.am' or"
153079e7944Smrg      echo "$configure_deps."
154079e7944Smrg      program_details 'automake'
155079e7944Smrg      ;;
156079e7944Smrg    aclocal*)
157079e7944Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
158079e7944Smrg      echo "$configure_deps."
159079e7944Smrg      program_details 'aclocal'
160079e7944Smrg      ;;
161079e7944Smrg   autom4te*)
162079e7944Smrg      echo "You might have modified some maintainer files that require"
163b2f5b1dbSmrg      echo "the 'autom4te' program to be rebuilt."
164079e7944Smrg      program_details 'autom4te'
165079e7944Smrg      ;;
166079e7944Smrg    bison*|yacc*)
167079e7944Smrg      echo "You should only need it if you modified a '.y' file."
168079e7944Smrg      echo "You may want to install the GNU Bison package:"
169079e7944Smrg      echo "<$gnu_software_URL/bison/>"
170079e7944Smrg      ;;
171079e7944Smrg    lex*|flex*)
172079e7944Smrg      echo "You should only need it if you modified a '.l' file."
173079e7944Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
174079e7944Smrg      echo "<$flex_URL>"
175079e7944Smrg      ;;
176079e7944Smrg    help2man*)
177079e7944Smrg      echo "You should only need it if you modified a dependency" \
178079e7944Smrg           "of a man page."
179079e7944Smrg      echo "You may want to install the GNU Help2man package:"
180079e7944Smrg      echo "<$gnu_software_URL/help2man/>"
181079e7944Smrg    ;;
182079e7944Smrg    makeinfo*)
183079e7944Smrg      echo "You should only need it if you modified a '.texi' file, or"
184079e7944Smrg      echo "any other file indirectly affecting the aspect of the manual."
185079e7944Smrg      echo "You might want to install the Texinfo package:"
186079e7944Smrg      echo "<$gnu_software_URL/texinfo/>"
187079e7944Smrg      echo "The spurious makeinfo call might also be the consequence of"
188079e7944Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189079e7944Smrg      echo "want to install GNU make:"
190079e7944Smrg      echo "<$gnu_software_URL/make/>"
191079e7944Smrg      ;;
192079e7944Smrg    *)
193079e7944Smrg      echo "You might have modified some files without having the proper"
194079e7944Smrg      echo "tools for further handling them.  Check the 'README' file, it"
195079e7944Smrg      echo "often tells you about the needed prerequisites for installing"
196079e7944Smrg      echo "this package.  You may also peek at any GNU archive site, in"
197079e7944Smrg      echo "case some other package contains this missing '$1' program."
198079e7944Smrg      ;;
199079e7944Smrg  esac
200079e7944Smrg}
201079e7944Smrg
202079e7944Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203079e7944Smrg                       -e '2,$s/^/         /' >&2
204079e7944Smrg
205079e7944Smrg# Propagate the correct exit status (expected to be 127 for a program
206079e7944Smrg# not found, 63 for a program that failed due to version mismatch).
207079e7944Smrgexit $st
2080eb10989Smrg
2090eb10989Smrg# Local variables:
21074901992Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2110eb10989Smrg# time-stamp-start: "scriptversion="
2120eb10989Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21374901992Smrg# time-stamp-time-zone: "UTC0"
21463165362Smrg# time-stamp-end: "; # UTC"
2150eb10989Smrg# End:
216