17da8b7e3Smrg#! /bin/sh
2c3d5982aSmrg# Common wrapper for a few potentially missing GNU programs.
37da8b7e3Smrg
4e4b60806Smrgscriptversion=2018-03-07.03; # UTC
57da8b7e3Smrg
6e4b60806Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7c3d5982aSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
87da8b7e3Smrg
97da8b7e3Smrg# This program is free software; you can redistribute it and/or modify
107da8b7e3Smrg# it under the terms of the GNU General Public License as published by
117da8b7e3Smrg# the Free Software Foundation; either version 2, or (at your option)
127da8b7e3Smrg# any later version.
137da8b7e3Smrg
147da8b7e3Smrg# This program is distributed in the hope that it will be useful,
157da8b7e3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
167da8b7e3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
177da8b7e3Smrg# GNU General Public License for more details.
187da8b7e3Smrg
197da8b7e3Smrg# You should have received a copy of the GNU General Public License
20e4b60806Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
217da8b7e3Smrg
227da8b7e3Smrg# As a special exception to the GNU General Public License, if you
237da8b7e3Smrg# distribute this file as part of a program that contains a
247da8b7e3Smrg# configuration script generated by Autoconf, you may include it under
257da8b7e3Smrg# the same distribution terms that you use for the rest of that program.
267da8b7e3Smrg
277da8b7e3Smrgif test $# -eq 0; then
28c3d5982aSmrg  echo 1>&2 "Try '$0 --help' for more information"
297da8b7e3Smrg  exit 1
307da8b7e3Smrgfi
317da8b7e3Smrg
32c3d5982aSmrgcase $1 in
337da8b7e3Smrg
34c3d5982aSmrg  --is-lightweight)
35c3d5982aSmrg    # Used by our autoconf macros to check whether the available missing
36c3d5982aSmrg    # script is modern enough.
37c3d5982aSmrg    exit 0
38c3d5982aSmrg    ;;
397da8b7e3Smrg
40c3d5982aSmrg  --run)
41c3d5982aSmrg    # Back-compat with the calling convention used by older automake.
42c3d5982aSmrg    shift
43c3d5982aSmrg    ;;
447da8b7e3Smrg
457da8b7e3Smrg  -h|--h|--he|--hel|--help)
467da8b7e3Smrg    echo "\
477da8b7e3Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
487da8b7e3Smrg
49c3d5982aSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50c3d5982aSmrgto PROGRAM being missing or too old.
517da8b7e3Smrg
527da8b7e3SmrgOptions:
537da8b7e3Smrg  -h, --help      display this help and exit
547da8b7e3Smrg  -v, --version   output version information and exit
557da8b7e3Smrg
567da8b7e3SmrgSupported PROGRAM values:
57c3d5982aSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58c3d5982aSmrg  bison     yacc      flex         lex       help2man
597da8b7e3Smrg
60c3d5982aSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61c3d5982aSmrg'g' are ignored when checking the name.
62123e2cc7Smrg
637da8b7e3SmrgSend bug reports to <bug-automake@gnu.org>."
647da8b7e3Smrg    exit $?
657da8b7e3Smrg    ;;
667da8b7e3Smrg
677da8b7e3Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
687da8b7e3Smrg    echo "missing $scriptversion (GNU Automake)"
697da8b7e3Smrg    exit $?
707da8b7e3Smrg    ;;
717da8b7e3Smrg
727da8b7e3Smrg  -*)
73c3d5982aSmrg    echo 1>&2 "$0: unknown '$1' option"
74c3d5982aSmrg    echo 1>&2 "Try '$0 --help' for more information"
757da8b7e3Smrg    exit 1
767da8b7e3Smrg    ;;
777da8b7e3Smrg
787da8b7e3Smrgesac
797da8b7e3Smrg
80c3d5982aSmrg# Run the given program, remember its exit status.
81c3d5982aSmrg"$@"; st=$?
82c3d5982aSmrg
83c3d5982aSmrg# If it succeeded, we are done.
84c3d5982aSmrgtest $st -eq 0 && exit 0
85c3d5982aSmrg
86c3d5982aSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
87c3d5982aSmrg# passed; such an option is passed most likely to detect whether the
88c3d5982aSmrg# program is present and works.
89c3d5982aSmrgcase $2 in --version|--help) exit $st;; esac
90c3d5982aSmrg
91c3d5982aSmrg# Exit code 63 means version mismatch.  This often happens when the user
92c3d5982aSmrg# tries to use an ancient version of a tool on a file that requires a
93c3d5982aSmrg# minimum version.
94c3d5982aSmrgif test $st -eq 63; then
95c3d5982aSmrg  msg="probably too old"
96c3d5982aSmrgelif test $st -eq 127; then
97c3d5982aSmrg  # Program was missing.
98c3d5982aSmrg  msg="missing on your system"
99c3d5982aSmrgelse
100c3d5982aSmrg  # Program was found and executed, but failed.  Give up.
101c3d5982aSmrg  exit $st
102c3d5982aSmrgfi
1037da8b7e3Smrg
104e4b60806Smrgperl_URL=https://www.perl.org/
105e4b60806Smrgflex_URL=https://github.com/westes/flex
106e4b60806Smrggnu_software_URL=https://www.gnu.org/software
107c3d5982aSmrg
108c3d5982aSmrgprogram_details ()
109c3d5982aSmrg{
110c3d5982aSmrg  case $1 in
111c3d5982aSmrg    aclocal|automake)
112c3d5982aSmrg      echo "The '$1' program is part of the GNU Automake package:"
113c3d5982aSmrg      echo "<$gnu_software_URL/automake>"
114c3d5982aSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115c3d5982aSmrg      echo "<$gnu_software_URL/autoconf>"
116c3d5982aSmrg      echo "<$gnu_software_URL/m4/>"
117c3d5982aSmrg      echo "<$perl_URL>"
118c3d5982aSmrg      ;;
119c3d5982aSmrg    autoconf|autom4te|autoheader)
120c3d5982aSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
121c3d5982aSmrg      echo "<$gnu_software_URL/autoconf/>"
122c3d5982aSmrg      echo "It also requires GNU m4 and Perl in order to run:"
123c3d5982aSmrg      echo "<$gnu_software_URL/m4/>"
124c3d5982aSmrg      echo "<$perl_URL>"
125c3d5982aSmrg      ;;
126c3d5982aSmrg  esac
127c3d5982aSmrg}
128c3d5982aSmrg
129c3d5982aSmrggive_advice ()
130c3d5982aSmrg{
131c3d5982aSmrg  # Normalize program name to check for.
132c3d5982aSmrg  normalized_program=`echo "$1" | sed '
133c3d5982aSmrg    s/^gnu-//; t
134c3d5982aSmrg    s/^gnu//; t
135c3d5982aSmrg    s/^g//; t'`
136c3d5982aSmrg
137c3d5982aSmrg  printf '%s\n' "'$1' is $msg."
138c3d5982aSmrg
139c3d5982aSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140c3d5982aSmrg  case $normalized_program in
141c3d5982aSmrg    autoconf*)
142c3d5982aSmrg      echo "You should only need it if you modified 'configure.ac',"
143c3d5982aSmrg      echo "or m4 files included by it."
144c3d5982aSmrg      program_details 'autoconf'
145c3d5982aSmrg      ;;
146c3d5982aSmrg    autoheader*)
147c3d5982aSmrg      echo "You should only need it if you modified 'acconfig.h' or"
148c3d5982aSmrg      echo "$configure_deps."
149c3d5982aSmrg      program_details 'autoheader'
150c3d5982aSmrg      ;;
151c3d5982aSmrg    automake*)
152c3d5982aSmrg      echo "You should only need it if you modified 'Makefile.am' or"
153c3d5982aSmrg      echo "$configure_deps."
154c3d5982aSmrg      program_details 'automake'
155c3d5982aSmrg      ;;
156c3d5982aSmrg    aclocal*)
157c3d5982aSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
158c3d5982aSmrg      echo "$configure_deps."
159c3d5982aSmrg      program_details 'aclocal'
160c3d5982aSmrg      ;;
161c3d5982aSmrg   autom4te*)
162c3d5982aSmrg      echo "You might have modified some maintainer files that require"
163ff143803Smrg      echo "the 'autom4te' program to be rebuilt."
164c3d5982aSmrg      program_details 'autom4te'
165c3d5982aSmrg      ;;
166c3d5982aSmrg    bison*|yacc*)
167c3d5982aSmrg      echo "You should only need it if you modified a '.y' file."
168c3d5982aSmrg      echo "You may want to install the GNU Bison package:"
169c3d5982aSmrg      echo "<$gnu_software_URL/bison/>"
170c3d5982aSmrg      ;;
171c3d5982aSmrg    lex*|flex*)
172c3d5982aSmrg      echo "You should only need it if you modified a '.l' file."
173c3d5982aSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
174c3d5982aSmrg      echo "<$flex_URL>"
175c3d5982aSmrg      ;;
176c3d5982aSmrg    help2man*)
177c3d5982aSmrg      echo "You should only need it if you modified a dependency" \
178c3d5982aSmrg           "of a man page."
179c3d5982aSmrg      echo "You may want to install the GNU Help2man package:"
180c3d5982aSmrg      echo "<$gnu_software_URL/help2man/>"
181c3d5982aSmrg    ;;
182c3d5982aSmrg    makeinfo*)
183c3d5982aSmrg      echo "You should only need it if you modified a '.texi' file, or"
184c3d5982aSmrg      echo "any other file indirectly affecting the aspect of the manual."
185c3d5982aSmrg      echo "You might want to install the Texinfo package:"
186c3d5982aSmrg      echo "<$gnu_software_URL/texinfo/>"
187c3d5982aSmrg      echo "The spurious makeinfo call might also be the consequence of"
188c3d5982aSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189c3d5982aSmrg      echo "want to install GNU make:"
190c3d5982aSmrg      echo "<$gnu_software_URL/make/>"
191c3d5982aSmrg      ;;
192c3d5982aSmrg    *)
193c3d5982aSmrg      echo "You might have modified some files without having the proper"
194c3d5982aSmrg      echo "tools for further handling them.  Check the 'README' file, it"
195c3d5982aSmrg      echo "often tells you about the needed prerequisites for installing"
196c3d5982aSmrg      echo "this package.  You may also peek at any GNU archive site, in"
197c3d5982aSmrg      echo "case some other package contains this missing '$1' program."
198c3d5982aSmrg      ;;
199c3d5982aSmrg  esac
200c3d5982aSmrg}
201c3d5982aSmrg
202c3d5982aSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203c3d5982aSmrg                       -e '2,$s/^/         /' >&2
204c3d5982aSmrg
205c3d5982aSmrg# Propagate the correct exit status (expected to be 127 for a program
206c3d5982aSmrg# not found, 63 for a program that failed due to version mismatch).
207c3d5982aSmrgexit $st
2087da8b7e3Smrg
2097da8b7e3Smrg# Local variables:
210e4b60806Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2117da8b7e3Smrg# time-stamp-start: "scriptversion="
2127da8b7e3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213e4b60806Smrg# time-stamp-time-zone: "UTC0"
214123e2cc7Smrg# time-stamp-end: "; # UTC"
2157da8b7e3Smrg# End:
216