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