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