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