14ecf19b2Smrg#! /bin/sh
2ef516338Smrg# Common wrapper for a few potentially missing GNU programs.
332034fa5Smrg
4ef516338Smrgscriptversion=2018-03-07.03; # UTC
532034fa5Smrg
6ef516338Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7ef516338Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
84ecf19b2Smrg
94ecf19b2Smrg# This program is free software; you can redistribute it and/or modify
104ecf19b2Smrg# it under the terms of the GNU General Public License as published by
114ecf19b2Smrg# the Free Software Foundation; either version 2, or (at your option)
124ecf19b2Smrg# any later version.
134ecf19b2Smrg
144ecf19b2Smrg# This program is distributed in the hope that it will be useful,
154ecf19b2Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
164ecf19b2Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
174ecf19b2Smrg# GNU General Public License for more details.
184ecf19b2Smrg
194ecf19b2Smrg# You should have received a copy of the GNU General Public License
20ef516338Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
214ecf19b2Smrg
224ecf19b2Smrg# As a special exception to the GNU General Public License, if you
234ecf19b2Smrg# distribute this file as part of a program that contains a
244ecf19b2Smrg# configuration script generated by Autoconf, you may include it under
254ecf19b2Smrg# the same distribution terms that you use for the rest of that program.
264ecf19b2Smrg
274ecf19b2Smrgif test $# -eq 0; then
28ef516338Smrg  echo 1>&2 "Try '$0 --help' for more information"
294ecf19b2Smrg  exit 1
304ecf19b2Smrgfi
314ecf19b2Smrg
32ef516338Smrgcase $1 in
334ecf19b2Smrg
34ef516338Smrg  --is-lightweight)
35ef516338Smrg    # Used by our autoconf macros to check whether the available missing
36ef516338Smrg    # script is modern enough.
37ef516338Smrg    exit 0
38ef516338Smrg    ;;
3932034fa5Smrg
40ef516338Smrg  --run)
41ef516338Smrg    # Back-compat with the calling convention used by older automake.
42ef516338Smrg    shift
43ef516338Smrg    ;;
444ecf19b2Smrg
454ecf19b2Smrg  -h|--h|--he|--hel|--help)
464ecf19b2Smrg    echo "\
474ecf19b2Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
484ecf19b2Smrg
49ef516338SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50ef516338Smrgto PROGRAM being missing or too old.
514ecf19b2Smrg
524ecf19b2SmrgOptions:
534ecf19b2Smrg  -h, --help      display this help and exit
544ecf19b2Smrg  -v, --version   output version information and exit
554ecf19b2Smrg
564ecf19b2SmrgSupported PROGRAM values:
57ef516338Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58ef516338Smrg  bison     yacc      flex         lex       help2man
5932034fa5Smrg
60ef516338SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61ef516338Smrg'g' are ignored when checking the name.
6232034fa5Smrg
6332034fa5SmrgSend bug reports to <bug-automake@gnu.org>."
6432034fa5Smrg    exit $?
654ecf19b2Smrg    ;;
664ecf19b2Smrg
674ecf19b2Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6832034fa5Smrg    echo "missing $scriptversion (GNU Automake)"
6932034fa5Smrg    exit $?
704ecf19b2Smrg    ;;
714ecf19b2Smrg
724ecf19b2Smrg  -*)
73ef516338Smrg    echo 1>&2 "$0: unknown '$1' option"
74ef516338Smrg    echo 1>&2 "Try '$0 --help' for more information"
754ecf19b2Smrg    exit 1
764ecf19b2Smrg    ;;
774ecf19b2Smrg
7832034fa5Smrgesac
7932034fa5Smrg
80ef516338Smrg# Run the given program, remember its exit status.
81ef516338Smrg"$@"; st=$?
82ef516338Smrg
83ef516338Smrg# If it succeeded, we are done.
84ef516338Smrgtest $st -eq 0 && exit 0
85ef516338Smrg
86ef516338Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
87ef516338Smrg# passed; such an option is passed most likely to detect whether the
88ef516338Smrg# program is present and works.
89ef516338Smrgcase $2 in --version|--help) exit $st;; esac
90ef516338Smrg
91ef516338Smrg# Exit code 63 means version mismatch.  This often happens when the user
92ef516338Smrg# tries to use an ancient version of a tool on a file that requires a
93ef516338Smrg# minimum version.
94ef516338Smrgif test $st -eq 63; then
95ef516338Smrg  msg="probably too old"
96ef516338Smrgelif test $st -eq 127; then
97ef516338Smrg  # Program was missing.
98ef516338Smrg  msg="missing on your system"
99ef516338Smrgelse
100ef516338Smrg  # Program was found and executed, but failed.  Give up.
101ef516338Smrg  exit $st
102ef516338Smrgfi
1034ecf19b2Smrg
104ef516338Smrgperl_URL=https://www.perl.org/
105ef516338Smrgflex_URL=https://github.com/westes/flex
106ef516338Smrggnu_software_URL=https://www.gnu.org/software
107ef516338Smrg
108ef516338Smrgprogram_details ()
109ef516338Smrg{
110ef516338Smrg  case $1 in
111ef516338Smrg    aclocal|automake)
112ef516338Smrg      echo "The '$1' program is part of the GNU Automake package:"
113ef516338Smrg      echo "<$gnu_software_URL/automake>"
114ef516338Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115ef516338Smrg      echo "<$gnu_software_URL/autoconf>"
116ef516338Smrg      echo "<$gnu_software_URL/m4/>"
117ef516338Smrg      echo "<$perl_URL>"
118ef516338Smrg      ;;
119ef516338Smrg    autoconf|autom4te|autoheader)
120ef516338Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
121ef516338Smrg      echo "<$gnu_software_URL/autoconf/>"
122ef516338Smrg      echo "It also requires GNU m4 and Perl in order to run:"
123ef516338Smrg      echo "<$gnu_software_URL/m4/>"
124ef516338Smrg      echo "<$perl_URL>"
125ef516338Smrg      ;;
126ef516338Smrg  esac
127ef516338Smrg}
128ef516338Smrg
129ef516338Smrggive_advice ()
130ef516338Smrg{
131ef516338Smrg  # Normalize program name to check for.
132ef516338Smrg  normalized_program=`echo "$1" | sed '
133ef516338Smrg    s/^gnu-//; t
134ef516338Smrg    s/^gnu//; t
135ef516338Smrg    s/^g//; t'`
136ef516338Smrg
137ef516338Smrg  printf '%s\n' "'$1' is $msg."
138ef516338Smrg
139ef516338Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140ef516338Smrg  case $normalized_program in
141ef516338Smrg    autoconf*)
142ef516338Smrg      echo "You should only need it if you modified 'configure.ac',"
143ef516338Smrg      echo "or m4 files included by it."
144ef516338Smrg      program_details 'autoconf'
145ef516338Smrg      ;;
146ef516338Smrg    autoheader*)
147ef516338Smrg      echo "You should only need it if you modified 'acconfig.h' or"
148ef516338Smrg      echo "$configure_deps."
149ef516338Smrg      program_details 'autoheader'
150ef516338Smrg      ;;
151ef516338Smrg    automake*)
152ef516338Smrg      echo "You should only need it if you modified 'Makefile.am' or"
153ef516338Smrg      echo "$configure_deps."
154ef516338Smrg      program_details 'automake'
155ef516338Smrg      ;;
156ef516338Smrg    aclocal*)
157ef516338Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
158ef516338Smrg      echo "$configure_deps."
159ef516338Smrg      program_details 'aclocal'
160ef516338Smrg      ;;
161ef516338Smrg   autom4te*)
162ef516338Smrg      echo "You might have modified some maintainer files that require"
163ef516338Smrg      echo "the 'autom4te' program to be rebuilt."
164ef516338Smrg      program_details 'autom4te'
165ef516338Smrg      ;;
166ef516338Smrg    bison*|yacc*)
167ef516338Smrg      echo "You should only need it if you modified a '.y' file."
168ef516338Smrg      echo "You may want to install the GNU Bison package:"
169ef516338Smrg      echo "<$gnu_software_URL/bison/>"
170ef516338Smrg      ;;
171ef516338Smrg    lex*|flex*)
172ef516338Smrg      echo "You should only need it if you modified a '.l' file."
173ef516338Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
174ef516338Smrg      echo "<$flex_URL>"
175ef516338Smrg      ;;
176ef516338Smrg    help2man*)
177ef516338Smrg      echo "You should only need it if you modified a dependency" \
178ef516338Smrg           "of a man page."
179ef516338Smrg      echo "You may want to install the GNU Help2man package:"
180ef516338Smrg      echo "<$gnu_software_URL/help2man/>"
181ef516338Smrg    ;;
182ef516338Smrg    makeinfo*)
183ef516338Smrg      echo "You should only need it if you modified a '.texi' file, or"
184ef516338Smrg      echo "any other file indirectly affecting the aspect of the manual."
185ef516338Smrg      echo "You might want to install the Texinfo package:"
186ef516338Smrg      echo "<$gnu_software_URL/texinfo/>"
187ef516338Smrg      echo "The spurious makeinfo call might also be the consequence of"
188ef516338Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189ef516338Smrg      echo "want to install GNU make:"
190ef516338Smrg      echo "<$gnu_software_URL/make/>"
191ef516338Smrg      ;;
192ef516338Smrg    *)
193ef516338Smrg      echo "You might have modified some files without having the proper"
194ef516338Smrg      echo "tools for further handling them.  Check the 'README' file, it"
195ef516338Smrg      echo "often tells you about the needed prerequisites for installing"
196ef516338Smrg      echo "this package.  You may also peek at any GNU archive site, in"
197ef516338Smrg      echo "case some other package contains this missing '$1' program."
198ef516338Smrg      ;;
199ef516338Smrg  esac
200ef516338Smrg}
201ef516338Smrg
202ef516338Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203ef516338Smrg                       -e '2,$s/^/         /' >&2
204ef516338Smrg
205ef516338Smrg# Propagate the correct exit status (expected to be 127 for a program
206ef516338Smrg# not found, 63 for a program that failed due to version mismatch).
207ef516338Smrgexit $st
20832034fa5Smrg
20932034fa5Smrg# Local variables:
210ef516338Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
21132034fa5Smrg# time-stamp-start: "scriptversion="
21232034fa5Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213ef516338Smrg# time-stamp-time-zone: "UTC0"
21432034fa5Smrg# time-stamp-end: "; # UTC"
21532034fa5Smrg# End:
216