13e747e6dSmrg#! /bin/sh
2c2535118Smrg# Common wrapper for a few potentially missing GNU programs.
33e747e6dSmrg
46d8e82c3Smrgscriptversion=2018-03-07.03; # UTC
53e747e6dSmrg
66d8e82c3Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7c2535118Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
83e747e6dSmrg
93e747e6dSmrg# This program is free software; you can redistribute it and/or modify
103e747e6dSmrg# it under the terms of the GNU General Public License as published by
113e747e6dSmrg# the Free Software Foundation; either version 2, or (at your option)
123e747e6dSmrg# any later version.
133e747e6dSmrg
143e747e6dSmrg# This program is distributed in the hope that it will be useful,
153e747e6dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
163e747e6dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
173e747e6dSmrg# GNU General Public License for more details.
183e747e6dSmrg
193e747e6dSmrg# You should have received a copy of the GNU General Public License
206d8e82c3Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
213e747e6dSmrg
223e747e6dSmrg# As a special exception to the GNU General Public License, if you
233e747e6dSmrg# distribute this file as part of a program that contains a
243e747e6dSmrg# configuration script generated by Autoconf, you may include it under
253e747e6dSmrg# the same distribution terms that you use for the rest of that program.
263e747e6dSmrg
273e747e6dSmrgif test $# -eq 0; then
28c2535118Smrg  echo 1>&2 "Try '$0 --help' for more information"
293e747e6dSmrg  exit 1
303e747e6dSmrgfi
313e747e6dSmrg
32c2535118Smrgcase $1 in
333e747e6dSmrg
34c2535118Smrg  --is-lightweight)
35c2535118Smrg    # Used by our autoconf macros to check whether the available missing
36c2535118Smrg    # script is modern enough.
37c2535118Smrg    exit 0
38c2535118Smrg    ;;
393e747e6dSmrg
40c2535118Smrg  --run)
41c2535118Smrg    # Back-compat with the calling convention used by older automake.
42c2535118Smrg    shift
43c2535118Smrg    ;;
443e747e6dSmrg
453e747e6dSmrg  -h|--h|--he|--hel|--help)
463e747e6dSmrg    echo "\
473e747e6dSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
483e747e6dSmrg
49c2535118SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50c2535118Smrgto PROGRAM being missing or too old.
513e747e6dSmrg
523e747e6dSmrgOptions:
533e747e6dSmrg  -h, --help      display this help and exit
543e747e6dSmrg  -v, --version   output version information and exit
553e747e6dSmrg
563e747e6dSmrgSupported PROGRAM values:
57c2535118Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58c2535118Smrg  bison     yacc      flex         lex       help2man
593e747e6dSmrg
60c2535118SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61c2535118Smrg'g' are ignored when checking the name.
627a2631fcSmrg
633e747e6dSmrgSend bug reports to <bug-automake@gnu.org>."
643e747e6dSmrg    exit $?
653e747e6dSmrg    ;;
663e747e6dSmrg
673e747e6dSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
683e747e6dSmrg    echo "missing $scriptversion (GNU Automake)"
693e747e6dSmrg    exit $?
703e747e6dSmrg    ;;
713e747e6dSmrg
723e747e6dSmrg  -*)
73c2535118Smrg    echo 1>&2 "$0: unknown '$1' option"
74c2535118Smrg    echo 1>&2 "Try '$0 --help' for more information"
753e747e6dSmrg    exit 1
763e747e6dSmrg    ;;
773e747e6dSmrg
783e747e6dSmrgesac
793e747e6dSmrg
80c2535118Smrg# Run the given program, remember its exit status.
81c2535118Smrg"$@"; st=$?
82c2535118Smrg
83c2535118Smrg# If it succeeded, we are done.
84c2535118Smrgtest $st -eq 0 && exit 0
85c2535118Smrg
86c2535118Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
87c2535118Smrg# passed; such an option is passed most likely to detect whether the
88c2535118Smrg# program is present and works.
89c2535118Smrgcase $2 in --version|--help) exit $st;; esac
90c2535118Smrg
91c2535118Smrg# Exit code 63 means version mismatch.  This often happens when the user
92c2535118Smrg# tries to use an ancient version of a tool on a file that requires a
93c2535118Smrg# minimum version.
94c2535118Smrgif test $st -eq 63; then
95c2535118Smrg  msg="probably too old"
96c2535118Smrgelif test $st -eq 127; then
97c2535118Smrg  # Program was missing.
98c2535118Smrg  msg="missing on your system"
99c2535118Smrgelse
100c2535118Smrg  # Program was found and executed, but failed.  Give up.
101c2535118Smrg  exit $st
102c2535118Smrgfi
1033e747e6dSmrg
1046d8e82c3Smrgperl_URL=https://www.perl.org/
1056d8e82c3Smrgflex_URL=https://github.com/westes/flex
1066d8e82c3Smrggnu_software_URL=https://www.gnu.org/software
107c2535118Smrg
108c2535118Smrgprogram_details ()
109c2535118Smrg{
110c2535118Smrg  case $1 in
111c2535118Smrg    aclocal|automake)
112c2535118Smrg      echo "The '$1' program is part of the GNU Automake package:"
113c2535118Smrg      echo "<$gnu_software_URL/automake>"
114c2535118Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115c2535118Smrg      echo "<$gnu_software_URL/autoconf>"
116c2535118Smrg      echo "<$gnu_software_URL/m4/>"
117c2535118Smrg      echo "<$perl_URL>"
118c2535118Smrg      ;;
119c2535118Smrg    autoconf|autom4te|autoheader)
120c2535118Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
121c2535118Smrg      echo "<$gnu_software_URL/autoconf/>"
122c2535118Smrg      echo "It also requires GNU m4 and Perl in order to run:"
123c2535118Smrg      echo "<$gnu_software_URL/m4/>"
124c2535118Smrg      echo "<$perl_URL>"
125c2535118Smrg      ;;
126c2535118Smrg  esac
127c2535118Smrg}
128c2535118Smrg
129c2535118Smrggive_advice ()
130c2535118Smrg{
131c2535118Smrg  # Normalize program name to check for.
132c2535118Smrg  normalized_program=`echo "$1" | sed '
133c2535118Smrg    s/^gnu-//; t
134c2535118Smrg    s/^gnu//; t
135c2535118Smrg    s/^g//; t'`
136c2535118Smrg
137c2535118Smrg  printf '%s\n' "'$1' is $msg."
138c2535118Smrg
139c2535118Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140c2535118Smrg  case $normalized_program in
141c2535118Smrg    autoconf*)
142c2535118Smrg      echo "You should only need it if you modified 'configure.ac',"
143c2535118Smrg      echo "or m4 files included by it."
144c2535118Smrg      program_details 'autoconf'
145c2535118Smrg      ;;
146c2535118Smrg    autoheader*)
147c2535118Smrg      echo "You should only need it if you modified 'acconfig.h' or"
148c2535118Smrg      echo "$configure_deps."
149c2535118Smrg      program_details 'autoheader'
150c2535118Smrg      ;;
151c2535118Smrg    automake*)
152c2535118Smrg      echo "You should only need it if you modified 'Makefile.am' or"
153c2535118Smrg      echo "$configure_deps."
154c2535118Smrg      program_details 'automake'
155c2535118Smrg      ;;
156c2535118Smrg    aclocal*)
157c2535118Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
158c2535118Smrg      echo "$configure_deps."
159c2535118Smrg      program_details 'aclocal'
160c2535118Smrg      ;;
161c2535118Smrg   autom4te*)
162c2535118Smrg      echo "You might have modified some maintainer files that require"
1639cd34f4bSmrg      echo "the 'autom4te' program to be rebuilt."
164c2535118Smrg      program_details 'autom4te'
165c2535118Smrg      ;;
166c2535118Smrg    bison*|yacc*)
167c2535118Smrg      echo "You should only need it if you modified a '.y' file."
168c2535118Smrg      echo "You may want to install the GNU Bison package:"
169c2535118Smrg      echo "<$gnu_software_URL/bison/>"
170c2535118Smrg      ;;
171c2535118Smrg    lex*|flex*)
172c2535118Smrg      echo "You should only need it if you modified a '.l' file."
173c2535118Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
174c2535118Smrg      echo "<$flex_URL>"
175c2535118Smrg      ;;
176c2535118Smrg    help2man*)
177c2535118Smrg      echo "You should only need it if you modified a dependency" \
178c2535118Smrg           "of a man page."
179c2535118Smrg      echo "You may want to install the GNU Help2man package:"
180c2535118Smrg      echo "<$gnu_software_URL/help2man/>"
181c2535118Smrg    ;;
182c2535118Smrg    makeinfo*)
183c2535118Smrg      echo "You should only need it if you modified a '.texi' file, or"
184c2535118Smrg      echo "any other file indirectly affecting the aspect of the manual."
185c2535118Smrg      echo "You might want to install the Texinfo package:"
186c2535118Smrg      echo "<$gnu_software_URL/texinfo/>"
187c2535118Smrg      echo "The spurious makeinfo call might also be the consequence of"
188c2535118Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189c2535118Smrg      echo "want to install GNU make:"
190c2535118Smrg      echo "<$gnu_software_URL/make/>"
191c2535118Smrg      ;;
192c2535118Smrg    *)
193c2535118Smrg      echo "You might have modified some files without having the proper"
194c2535118Smrg      echo "tools for further handling them.  Check the 'README' file, it"
195c2535118Smrg      echo "often tells you about the needed prerequisites for installing"
196c2535118Smrg      echo "this package.  You may also peek at any GNU archive site, in"
197c2535118Smrg      echo "case some other package contains this missing '$1' program."
198c2535118Smrg      ;;
199c2535118Smrg  esac
200c2535118Smrg}
201c2535118Smrg
202c2535118Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203c2535118Smrg                       -e '2,$s/^/         /' >&2
204c2535118Smrg
205c2535118Smrg# Propagate the correct exit status (expected to be 127 for a program
206c2535118Smrg# not found, 63 for a program that failed due to version mismatch).
207c2535118Smrgexit $st
2083e747e6dSmrg
2093e747e6dSmrg# Local variables:
2106d8e82c3Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2113e747e6dSmrg# time-stamp-start: "scriptversion="
2123e747e6dSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2136d8e82c3Smrg# time-stamp-time-zone: "UTC0"
2147a2631fcSmrg# time-stamp-end: "; # UTC"
2153e747e6dSmrg# End:
216