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