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