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