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