1d6c0b56eSmrg#! /bin/sh
2d6c0b56eSmrg# Common wrapper for a few potentially missing GNU programs.
3d6c0b56eSmrg
435d5b7c7Smrgscriptversion=2018-03-07.03; # UTC
5d6c0b56eSmrg
6e49c54bcSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7d6c0b56eSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8d6c0b56eSmrg
9d6c0b56eSmrg# This program is free software; you can redistribute it and/or modify
10d6c0b56eSmrg# it under the terms of the GNU General Public License as published by
11d6c0b56eSmrg# the Free Software Foundation; either version 2, or (at your option)
12d6c0b56eSmrg# any later version.
13d6c0b56eSmrg
14d6c0b56eSmrg# This program is distributed in the hope that it will be useful,
15d6c0b56eSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16d6c0b56eSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17d6c0b56eSmrg# GNU General Public License for more details.
18d6c0b56eSmrg
19d6c0b56eSmrg# You should have received a copy of the GNU General Public License
2035d5b7c7Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21d6c0b56eSmrg
22d6c0b56eSmrg# As a special exception to the GNU General Public License, if you
23d6c0b56eSmrg# distribute this file as part of a program that contains a
24d6c0b56eSmrg# configuration script generated by Autoconf, you may include it under
25d6c0b56eSmrg# the same distribution terms that you use for the rest of that program.
26d6c0b56eSmrg
27d6c0b56eSmrgif test $# -eq 0; then
28d6c0b56eSmrg  echo 1>&2 "Try '$0 --help' for more information"
29d6c0b56eSmrg  exit 1
30d6c0b56eSmrgfi
31d6c0b56eSmrg
32d6c0b56eSmrgcase $1 in
33d6c0b56eSmrg
34d6c0b56eSmrg  --is-lightweight)
35d6c0b56eSmrg    # Used by our autoconf macros to check whether the available missing
36d6c0b56eSmrg    # script is modern enough.
37d6c0b56eSmrg    exit 0
38d6c0b56eSmrg    ;;
39d6c0b56eSmrg
40d6c0b56eSmrg  --run)
41d6c0b56eSmrg    # Back-compat with the calling convention used by older automake.
42d6c0b56eSmrg    shift
43d6c0b56eSmrg    ;;
44d6c0b56eSmrg
45d6c0b56eSmrg  -h|--h|--he|--hel|--help)
46d6c0b56eSmrg    echo "\
47d6c0b56eSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48d6c0b56eSmrg
49d6c0b56eSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50d6c0b56eSmrgto PROGRAM being missing or too old.
51d6c0b56eSmrg
52d6c0b56eSmrgOptions:
53d6c0b56eSmrg  -h, --help      display this help and exit
54d6c0b56eSmrg  -v, --version   output version information and exit
55d6c0b56eSmrg
56d6c0b56eSmrgSupported PROGRAM values:
57d6c0b56eSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58d6c0b56eSmrg  bison     yacc      flex         lex       help2man
59d6c0b56eSmrg
60d6c0b56eSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61d6c0b56eSmrg'g' are ignored when checking the name.
62d6c0b56eSmrg
63d6c0b56eSmrgSend bug reports to <bug-automake@gnu.org>."
64d6c0b56eSmrg    exit $?
65d6c0b56eSmrg    ;;
66d6c0b56eSmrg
67d6c0b56eSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68d6c0b56eSmrg    echo "missing $scriptversion (GNU Automake)"
69d6c0b56eSmrg    exit $?
70d6c0b56eSmrg    ;;
71d6c0b56eSmrg
72d6c0b56eSmrg  -*)
73d6c0b56eSmrg    echo 1>&2 "$0: unknown '$1' option"
74d6c0b56eSmrg    echo 1>&2 "Try '$0 --help' for more information"
75d6c0b56eSmrg    exit 1
76d6c0b56eSmrg    ;;
77d6c0b56eSmrg
78d6c0b56eSmrgesac
79d6c0b56eSmrg
80d6c0b56eSmrg# Run the given program, remember its exit status.
81d6c0b56eSmrg"$@"; st=$?
82d6c0b56eSmrg
83d6c0b56eSmrg# If it succeeded, we are done.
84d6c0b56eSmrgtest $st -eq 0 && exit 0
85d6c0b56eSmrg
86d6c0b56eSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
87d6c0b56eSmrg# passed; such an option is passed most likely to detect whether the
88d6c0b56eSmrg# program is present and works.
89d6c0b56eSmrgcase $2 in --version|--help) exit $st;; esac
90d6c0b56eSmrg
91d6c0b56eSmrg# Exit code 63 means version mismatch.  This often happens when the user
92d6c0b56eSmrg# tries to use an ancient version of a tool on a file that requires a
93d6c0b56eSmrg# minimum version.
94d6c0b56eSmrgif test $st -eq 63; then
95d6c0b56eSmrg  msg="probably too old"
96d6c0b56eSmrgelif test $st -eq 127; then
97d6c0b56eSmrg  # Program was missing.
98d6c0b56eSmrg  msg="missing on your system"
99d6c0b56eSmrgelse
100d6c0b56eSmrg  # Program was found and executed, but failed.  Give up.
101d6c0b56eSmrg  exit $st
102d6c0b56eSmrgfi
103d6c0b56eSmrg
10435d5b7c7Smrgperl_URL=https://www.perl.org/
10535d5b7c7Smrgflex_URL=https://github.com/westes/flex
10635d5b7c7Smrggnu_software_URL=https://www.gnu.org/software
107d6c0b56eSmrg
108d6c0b56eSmrgprogram_details ()
109d6c0b56eSmrg{
110d6c0b56eSmrg  case $1 in
111d6c0b56eSmrg    aclocal|automake)
112d6c0b56eSmrg      echo "The '$1' program is part of the GNU Automake package:"
113d6c0b56eSmrg      echo "<$gnu_software_URL/automake>"
114d6c0b56eSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115d6c0b56eSmrg      echo "<$gnu_software_URL/autoconf>"
116d6c0b56eSmrg      echo "<$gnu_software_URL/m4/>"
117d6c0b56eSmrg      echo "<$perl_URL>"
118d6c0b56eSmrg      ;;
119d6c0b56eSmrg    autoconf|autom4te|autoheader)
120d6c0b56eSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
121d6c0b56eSmrg      echo "<$gnu_software_URL/autoconf/>"
122d6c0b56eSmrg      echo "It also requires GNU m4 and Perl in order to run:"
123d6c0b56eSmrg      echo "<$gnu_software_URL/m4/>"
124d6c0b56eSmrg      echo "<$perl_URL>"
125d6c0b56eSmrg      ;;
126d6c0b56eSmrg  esac
127d6c0b56eSmrg}
128d6c0b56eSmrg
129d6c0b56eSmrggive_advice ()
130d6c0b56eSmrg{
131d6c0b56eSmrg  # Normalize program name to check for.
132d6c0b56eSmrg  normalized_program=`echo "$1" | sed '
133d6c0b56eSmrg    s/^gnu-//; t
134d6c0b56eSmrg    s/^gnu//; t
135d6c0b56eSmrg    s/^g//; t'`
136d6c0b56eSmrg
137d6c0b56eSmrg  printf '%s\n' "'$1' is $msg."
138d6c0b56eSmrg
139d6c0b56eSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140d6c0b56eSmrg  case $normalized_program in
141d6c0b56eSmrg    autoconf*)
142d6c0b56eSmrg      echo "You should only need it if you modified 'configure.ac',"
143d6c0b56eSmrg      echo "or m4 files included by it."
144d6c0b56eSmrg      program_details 'autoconf'
145d6c0b56eSmrg      ;;
146d6c0b56eSmrg    autoheader*)
147d6c0b56eSmrg      echo "You should only need it if you modified 'acconfig.h' or"
148d6c0b56eSmrg      echo "$configure_deps."
149d6c0b56eSmrg      program_details 'autoheader'
150d6c0b56eSmrg      ;;
151d6c0b56eSmrg    automake*)
152d6c0b56eSmrg      echo "You should only need it if you modified 'Makefile.am' or"
153d6c0b56eSmrg      echo "$configure_deps."
154d6c0b56eSmrg      program_details 'automake'
155d6c0b56eSmrg      ;;
156d6c0b56eSmrg    aclocal*)
157d6c0b56eSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
158d6c0b56eSmrg      echo "$configure_deps."
159d6c0b56eSmrg      program_details 'aclocal'
160d6c0b56eSmrg      ;;
161d6c0b56eSmrg   autom4te*)
162d6c0b56eSmrg      echo "You might have modified some maintainer files that require"
163d6c0b56eSmrg      echo "the 'autom4te' program to be rebuilt."
164d6c0b56eSmrg      program_details 'autom4te'
165d6c0b56eSmrg      ;;
166d6c0b56eSmrg    bison*|yacc*)
167d6c0b56eSmrg      echo "You should only need it if you modified a '.y' file."
168d6c0b56eSmrg      echo "You may want to install the GNU Bison package:"
169d6c0b56eSmrg      echo "<$gnu_software_URL/bison/>"
170d6c0b56eSmrg      ;;
171d6c0b56eSmrg    lex*|flex*)
172d6c0b56eSmrg      echo "You should only need it if you modified a '.l' file."
173d6c0b56eSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
174d6c0b56eSmrg      echo "<$flex_URL>"
175d6c0b56eSmrg      ;;
176d6c0b56eSmrg    help2man*)
177d6c0b56eSmrg      echo "You should only need it if you modified a dependency" \
178d6c0b56eSmrg           "of a man page."
179d6c0b56eSmrg      echo "You may want to install the GNU Help2man package:"
180d6c0b56eSmrg      echo "<$gnu_software_URL/help2man/>"
181d6c0b56eSmrg    ;;
182d6c0b56eSmrg    makeinfo*)
183d6c0b56eSmrg      echo "You should only need it if you modified a '.texi' file, or"
184d6c0b56eSmrg      echo "any other file indirectly affecting the aspect of the manual."
185d6c0b56eSmrg      echo "You might want to install the Texinfo package:"
186d6c0b56eSmrg      echo "<$gnu_software_URL/texinfo/>"
187d6c0b56eSmrg      echo "The spurious makeinfo call might also be the consequence of"
188d6c0b56eSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189d6c0b56eSmrg      echo "want to install GNU make:"
190d6c0b56eSmrg      echo "<$gnu_software_URL/make/>"
191d6c0b56eSmrg      ;;
192d6c0b56eSmrg    *)
193d6c0b56eSmrg      echo "You might have modified some files without having the proper"
194d6c0b56eSmrg      echo "tools for further handling them.  Check the 'README' file, it"
195d6c0b56eSmrg      echo "often tells you about the needed prerequisites for installing"
196d6c0b56eSmrg      echo "this package.  You may also peek at any GNU archive site, in"
197d6c0b56eSmrg      echo "case some other package contains this missing '$1' program."
198d6c0b56eSmrg      ;;
199d6c0b56eSmrg  esac
200d6c0b56eSmrg}
201d6c0b56eSmrg
202d6c0b56eSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203d6c0b56eSmrg                       -e '2,$s/^/         /' >&2
204d6c0b56eSmrg
205d6c0b56eSmrg# Propagate the correct exit status (expected to be 127 for a program
206d6c0b56eSmrg# not found, 63 for a program that failed due to version mismatch).
207d6c0b56eSmrgexit $st
208d6c0b56eSmrg
209d6c0b56eSmrg# Local variables:
21035d5b7c7Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
211d6c0b56eSmrg# time-stamp-start: "scriptversion="
212d6c0b56eSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21335d5b7c7Smrg# time-stamp-time-zone: "UTC0"
214d6c0b56eSmrg# time-stamp-end: "; # UTC"
215d6c0b56eSmrg# End:
216