153354cdbSmrg#! /bin/sh
2ecb85c42Smrg# Common wrapper for a few potentially missing GNU programs.
353354cdbSmrg
4afb14e9bSmrgscriptversion=2018-03-07.03; # UTC
553354cdbSmrg
6afb14e9bSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7ecb85c42Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
853354cdbSmrg
953354cdbSmrg# This program is free software; you can redistribute it and/or modify
1053354cdbSmrg# it under the terms of the GNU General Public License as published by
1153354cdbSmrg# the Free Software Foundation; either version 2, or (at your option)
1253354cdbSmrg# any later version.
1353354cdbSmrg
1453354cdbSmrg# This program is distributed in the hope that it will be useful,
1553354cdbSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1653354cdbSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1753354cdbSmrg# GNU General Public License for more details.
1853354cdbSmrg
1953354cdbSmrg# You should have received a copy of the GNU General Public License
20afb14e9bSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2153354cdbSmrg
2253354cdbSmrg# As a special exception to the GNU General Public License, if you
2353354cdbSmrg# distribute this file as part of a program that contains a
2453354cdbSmrg# configuration script generated by Autoconf, you may include it under
2553354cdbSmrg# the same distribution terms that you use for the rest of that program.
2653354cdbSmrg
2753354cdbSmrgif test $# -eq 0; then
28ecb85c42Smrg  echo 1>&2 "Try '$0 --help' for more information"
2953354cdbSmrg  exit 1
3053354cdbSmrgfi
3153354cdbSmrg
32ecb85c42Smrgcase $1 in
3353354cdbSmrg
34ecb85c42Smrg  --is-lightweight)
35ecb85c42Smrg    # Used by our autoconf macros to check whether the available missing
36ecb85c42Smrg    # script is modern enough.
37ecb85c42Smrg    exit 0
38ecb85c42Smrg    ;;
3953354cdbSmrg
40ecb85c42Smrg  --run)
41ecb85c42Smrg    # Back-compat with the calling convention used by older automake.
42ecb85c42Smrg    shift
43ecb85c42Smrg    ;;
4453354cdbSmrg
4553354cdbSmrg  -h|--h|--he|--hel|--help)
4653354cdbSmrg    echo "\
4753354cdbSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4853354cdbSmrg
49ecb85c42SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50ecb85c42Smrgto PROGRAM being missing or too old.
5153354cdbSmrg
5253354cdbSmrgOptions:
5353354cdbSmrg  -h, --help      display this help and exit
5453354cdbSmrg  -v, --version   output version information and exit
5553354cdbSmrg
5653354cdbSmrgSupported PROGRAM values:
57ecb85c42Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58ecb85c42Smrg  bison     yacc      flex         lex       help2man
5953354cdbSmrg
60ecb85c42SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61ecb85c42Smrg'g' are ignored when checking the name.
6286bbecbeSmrg
6353354cdbSmrgSend bug reports to <bug-automake@gnu.org>."
6453354cdbSmrg    exit $?
6553354cdbSmrg    ;;
6653354cdbSmrg
6753354cdbSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6853354cdbSmrg    echo "missing $scriptversion (GNU Automake)"
6953354cdbSmrg    exit $?
7053354cdbSmrg    ;;
7153354cdbSmrg
7253354cdbSmrg  -*)
73ecb85c42Smrg    echo 1>&2 "$0: unknown '$1' option"
74ecb85c42Smrg    echo 1>&2 "Try '$0 --help' for more information"
7553354cdbSmrg    exit 1
7653354cdbSmrg    ;;
7753354cdbSmrg
7853354cdbSmrgesac
7953354cdbSmrg
80ecb85c42Smrg# Run the given program, remember its exit status.
81ecb85c42Smrg"$@"; st=$?
82ecb85c42Smrg
83ecb85c42Smrg# If it succeeded, we are done.
84ecb85c42Smrgtest $st -eq 0 && exit 0
85ecb85c42Smrg
86ecb85c42Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
87ecb85c42Smrg# passed; such an option is passed most likely to detect whether the
88ecb85c42Smrg# program is present and works.
89ecb85c42Smrgcase $2 in --version|--help) exit $st;; esac
90ecb85c42Smrg
91ecb85c42Smrg# Exit code 63 means version mismatch.  This often happens when the user
92ecb85c42Smrg# tries to use an ancient version of a tool on a file that requires a
93ecb85c42Smrg# minimum version.
94ecb85c42Smrgif test $st -eq 63; then
95ecb85c42Smrg  msg="probably too old"
96ecb85c42Smrgelif test $st -eq 127; then
97ecb85c42Smrg  # Program was missing.
98ecb85c42Smrg  msg="missing on your system"
99ecb85c42Smrgelse
100ecb85c42Smrg  # Program was found and executed, but failed.  Give up.
101ecb85c42Smrg  exit $st
102ecb85c42Smrgfi
10353354cdbSmrg
104afb14e9bSmrgperl_URL=https://www.perl.org/
105afb14e9bSmrgflex_URL=https://github.com/westes/flex
106afb14e9bSmrggnu_software_URL=https://www.gnu.org/software
107ecb85c42Smrg
108ecb85c42Smrgprogram_details ()
109ecb85c42Smrg{
110ecb85c42Smrg  case $1 in
111ecb85c42Smrg    aclocal|automake)
112ecb85c42Smrg      echo "The '$1' program is part of the GNU Automake package:"
113ecb85c42Smrg      echo "<$gnu_software_URL/automake>"
114ecb85c42Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115ecb85c42Smrg      echo "<$gnu_software_URL/autoconf>"
116ecb85c42Smrg      echo "<$gnu_software_URL/m4/>"
117ecb85c42Smrg      echo "<$perl_URL>"
118ecb85c42Smrg      ;;
119ecb85c42Smrg    autoconf|autom4te|autoheader)
120ecb85c42Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
121ecb85c42Smrg      echo "<$gnu_software_URL/autoconf/>"
122ecb85c42Smrg      echo "It also requires GNU m4 and Perl in order to run:"
123ecb85c42Smrg      echo "<$gnu_software_URL/m4/>"
124ecb85c42Smrg      echo "<$perl_URL>"
125ecb85c42Smrg      ;;
126ecb85c42Smrg  esac
127ecb85c42Smrg}
128ecb85c42Smrg
129ecb85c42Smrggive_advice ()
130ecb85c42Smrg{
131ecb85c42Smrg  # Normalize program name to check for.
132ecb85c42Smrg  normalized_program=`echo "$1" | sed '
133ecb85c42Smrg    s/^gnu-//; t
134ecb85c42Smrg    s/^gnu//; t
135ecb85c42Smrg    s/^g//; t'`
136ecb85c42Smrg
137ecb85c42Smrg  printf '%s\n' "'$1' is $msg."
138ecb85c42Smrg
139ecb85c42Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140ecb85c42Smrg  case $normalized_program in
141ecb85c42Smrg    autoconf*)
142ecb85c42Smrg      echo "You should only need it if you modified 'configure.ac',"
143ecb85c42Smrg      echo "or m4 files included by it."
144ecb85c42Smrg      program_details 'autoconf'
145ecb85c42Smrg      ;;
146ecb85c42Smrg    autoheader*)
147ecb85c42Smrg      echo "You should only need it if you modified 'acconfig.h' or"
148ecb85c42Smrg      echo "$configure_deps."
149ecb85c42Smrg      program_details 'autoheader'
150ecb85c42Smrg      ;;
151ecb85c42Smrg    automake*)
152ecb85c42Smrg      echo "You should only need it if you modified 'Makefile.am' or"
153ecb85c42Smrg      echo "$configure_deps."
154ecb85c42Smrg      program_details 'automake'
155ecb85c42Smrg      ;;
156ecb85c42Smrg    aclocal*)
157ecb85c42Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
158ecb85c42Smrg      echo "$configure_deps."
159ecb85c42Smrg      program_details 'aclocal'
160ecb85c42Smrg      ;;
161ecb85c42Smrg   autom4te*)
162ecb85c42Smrg      echo "You might have modified some maintainer files that require"
163ecb85c42Smrg      echo "the 'autom4te' program to be rebuilt."
164ecb85c42Smrg      program_details 'autom4te'
165ecb85c42Smrg      ;;
166ecb85c42Smrg    bison*|yacc*)
167ecb85c42Smrg      echo "You should only need it if you modified a '.y' file."
168ecb85c42Smrg      echo "You may want to install the GNU Bison package:"
169ecb85c42Smrg      echo "<$gnu_software_URL/bison/>"
170ecb85c42Smrg      ;;
171ecb85c42Smrg    lex*|flex*)
172ecb85c42Smrg      echo "You should only need it if you modified a '.l' file."
173ecb85c42Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
174ecb85c42Smrg      echo "<$flex_URL>"
175ecb85c42Smrg      ;;
176ecb85c42Smrg    help2man*)
177ecb85c42Smrg      echo "You should only need it if you modified a dependency" \
178ecb85c42Smrg           "of a man page."
179ecb85c42Smrg      echo "You may want to install the GNU Help2man package:"
180ecb85c42Smrg      echo "<$gnu_software_URL/help2man/>"
181ecb85c42Smrg    ;;
182ecb85c42Smrg    makeinfo*)
183ecb85c42Smrg      echo "You should only need it if you modified a '.texi' file, or"
184ecb85c42Smrg      echo "any other file indirectly affecting the aspect of the manual."
185ecb85c42Smrg      echo "You might want to install the Texinfo package:"
186ecb85c42Smrg      echo "<$gnu_software_URL/texinfo/>"
187ecb85c42Smrg      echo "The spurious makeinfo call might also be the consequence of"
188ecb85c42Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189ecb85c42Smrg      echo "want to install GNU make:"
190ecb85c42Smrg      echo "<$gnu_software_URL/make/>"
191ecb85c42Smrg      ;;
192ecb85c42Smrg    *)
193ecb85c42Smrg      echo "You might have modified some files without having the proper"
194ecb85c42Smrg      echo "tools for further handling them.  Check the 'README' file, it"
195ecb85c42Smrg      echo "often tells you about the needed prerequisites for installing"
196ecb85c42Smrg      echo "this package.  You may also peek at any GNU archive site, in"
197ecb85c42Smrg      echo "case some other package contains this missing '$1' program."
198ecb85c42Smrg      ;;
199ecb85c42Smrg  esac
200ecb85c42Smrg}
201ecb85c42Smrg
202ecb85c42Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203ecb85c42Smrg                       -e '2,$s/^/         /' >&2
204ecb85c42Smrg
205ecb85c42Smrg# Propagate the correct exit status (expected to be 127 for a program
206ecb85c42Smrg# not found, 63 for a program that failed due to version mismatch).
207ecb85c42Smrgexit $st
20853354cdbSmrg
20953354cdbSmrg# Local variables:
210afb14e9bSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
21153354cdbSmrg# time-stamp-start: "scriptversion="
21253354cdbSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213afb14e9bSmrg# time-stamp-time-zone: "UTC0"
21486bbecbeSmrg# time-stamp-end: "; # UTC"
21553354cdbSmrg# End:
216