17a84e134Smrg#! /bin/sh
2c889a3bfSmrg# Common wrapper for a few potentially missing GNU programs.
37a84e134Smrg
45ec34c4cSmrgscriptversion=2018-03-07.03; # UTC
57a84e134Smrg
65b16253fSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7c889a3bfSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
87a84e134Smrg
97a84e134Smrg# This program is free software; you can redistribute it and/or modify
107a84e134Smrg# it under the terms of the GNU General Public License as published by
117a84e134Smrg# the Free Software Foundation; either version 2, or (at your option)
127a84e134Smrg# any later version.
137a84e134Smrg
147a84e134Smrg# This program is distributed in the hope that it will be useful,
157a84e134Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
167a84e134Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
177a84e134Smrg# GNU General Public License for more details.
187a84e134Smrg
197a84e134Smrg# You should have received a copy of the GNU General Public License
205ec34c4cSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
217a84e134Smrg
227a84e134Smrg# As a special exception to the GNU General Public License, if you
237a84e134Smrg# distribute this file as part of a program that contains a
247a84e134Smrg# configuration script generated by Autoconf, you may include it under
257a84e134Smrg# the same distribution terms that you use for the rest of that program.
267a84e134Smrg
277a84e134Smrgif test $# -eq 0; then
28c889a3bfSmrg  echo 1>&2 "Try '$0 --help' for more information"
297a84e134Smrg  exit 1
307a84e134Smrgfi
317a84e134Smrg
32c889a3bfSmrgcase $1 in
337a84e134Smrg
34c889a3bfSmrg  --is-lightweight)
35c889a3bfSmrg    # Used by our autoconf macros to check whether the available missing
36c889a3bfSmrg    # script is modern enough.
37c889a3bfSmrg    exit 0
38c889a3bfSmrg    ;;
397a84e134Smrg
40c889a3bfSmrg  --run)
41c889a3bfSmrg    # Back-compat with the calling convention used by older automake.
42c889a3bfSmrg    shift
43c889a3bfSmrg    ;;
447a84e134Smrg
457a84e134Smrg  -h|--h|--he|--hel|--help)
467a84e134Smrg    echo "\
477a84e134Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
487a84e134Smrg
49c889a3bfSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50c889a3bfSmrgto PROGRAM being missing or too old.
517a84e134Smrg
527a84e134SmrgOptions:
537a84e134Smrg  -h, --help      display this help and exit
547a84e134Smrg  -v, --version   output version information and exit
557a84e134Smrg
567a84e134SmrgSupported PROGRAM values:
57c889a3bfSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58c889a3bfSmrg  bison     yacc      flex         lex       help2man
597a84e134Smrg
60c889a3bfSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61c889a3bfSmrg'g' are ignored when checking the name.
62e1e1713cSmrg
637a84e134SmrgSend bug reports to <bug-automake@gnu.org>."
647a84e134Smrg    exit $?
657a84e134Smrg    ;;
667a84e134Smrg
677a84e134Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
687a84e134Smrg    echo "missing $scriptversion (GNU Automake)"
697a84e134Smrg    exit $?
707a84e134Smrg    ;;
717a84e134Smrg
727a84e134Smrg  -*)
73c889a3bfSmrg    echo 1>&2 "$0: unknown '$1' option"
74c889a3bfSmrg    echo 1>&2 "Try '$0 --help' for more information"
757a84e134Smrg    exit 1
767a84e134Smrg    ;;
777a84e134Smrg
787a84e134Smrgesac
797a84e134Smrg
80c889a3bfSmrg# Run the given program, remember its exit status.
81c889a3bfSmrg"$@"; st=$?
82c889a3bfSmrg
83c889a3bfSmrg# If it succeeded, we are done.
84c889a3bfSmrgtest $st -eq 0 && exit 0
85c889a3bfSmrg
86c889a3bfSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
87c889a3bfSmrg# passed; such an option is passed most likely to detect whether the
88c889a3bfSmrg# program is present and works.
89c889a3bfSmrgcase $2 in --version|--help) exit $st;; esac
90c889a3bfSmrg
91c889a3bfSmrg# Exit code 63 means version mismatch.  This often happens when the user
92c889a3bfSmrg# tries to use an ancient version of a tool on a file that requires a
93c889a3bfSmrg# minimum version.
94c889a3bfSmrgif test $st -eq 63; then
95c889a3bfSmrg  msg="probably too old"
96c889a3bfSmrgelif test $st -eq 127; then
97c889a3bfSmrg  # Program was missing.
98c889a3bfSmrg  msg="missing on your system"
99c889a3bfSmrgelse
100c889a3bfSmrg  # Program was found and executed, but failed.  Give up.
101c889a3bfSmrg  exit $st
102c889a3bfSmrgfi
1037a84e134Smrg
1045ec34c4cSmrgperl_URL=https://www.perl.org/
1055ec34c4cSmrgflex_URL=https://github.com/westes/flex
1065ec34c4cSmrggnu_software_URL=https://www.gnu.org/software
107c889a3bfSmrg
108c889a3bfSmrgprogram_details ()
109c889a3bfSmrg{
110c889a3bfSmrg  case $1 in
111c889a3bfSmrg    aclocal|automake)
112c889a3bfSmrg      echo "The '$1' program is part of the GNU Automake package:"
113c889a3bfSmrg      echo "<$gnu_software_URL/automake>"
114c889a3bfSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115c889a3bfSmrg      echo "<$gnu_software_URL/autoconf>"
116c889a3bfSmrg      echo "<$gnu_software_URL/m4/>"
117c889a3bfSmrg      echo "<$perl_URL>"
118c889a3bfSmrg      ;;
119c889a3bfSmrg    autoconf|autom4te|autoheader)
120c889a3bfSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
121c889a3bfSmrg      echo "<$gnu_software_URL/autoconf/>"
122c889a3bfSmrg      echo "It also requires GNU m4 and Perl in order to run:"
123c889a3bfSmrg      echo "<$gnu_software_URL/m4/>"
124c889a3bfSmrg      echo "<$perl_URL>"
125c889a3bfSmrg      ;;
126c889a3bfSmrg  esac
127c889a3bfSmrg}
128c889a3bfSmrg
129c889a3bfSmrggive_advice ()
130c889a3bfSmrg{
131c889a3bfSmrg  # Normalize program name to check for.
132c889a3bfSmrg  normalized_program=`echo "$1" | sed '
133c889a3bfSmrg    s/^gnu-//; t
134c889a3bfSmrg    s/^gnu//; t
135c889a3bfSmrg    s/^g//; t'`
136c889a3bfSmrg
137c889a3bfSmrg  printf '%s\n' "'$1' is $msg."
138c889a3bfSmrg
139c889a3bfSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140c889a3bfSmrg  case $normalized_program in
141c889a3bfSmrg    autoconf*)
142c889a3bfSmrg      echo "You should only need it if you modified 'configure.ac',"
143c889a3bfSmrg      echo "or m4 files included by it."
144c889a3bfSmrg      program_details 'autoconf'
145c889a3bfSmrg      ;;
146c889a3bfSmrg    autoheader*)
147c889a3bfSmrg      echo "You should only need it if you modified 'acconfig.h' or"
148c889a3bfSmrg      echo "$configure_deps."
149c889a3bfSmrg      program_details 'autoheader'
150c889a3bfSmrg      ;;
151c889a3bfSmrg    automake*)
152c889a3bfSmrg      echo "You should only need it if you modified 'Makefile.am' or"
153c889a3bfSmrg      echo "$configure_deps."
154c889a3bfSmrg      program_details 'automake'
155c889a3bfSmrg      ;;
156c889a3bfSmrg    aclocal*)
157c889a3bfSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
158c889a3bfSmrg      echo "$configure_deps."
159c889a3bfSmrg      program_details 'aclocal'
160c889a3bfSmrg      ;;
161c889a3bfSmrg   autom4te*)
162c889a3bfSmrg      echo "You might have modified some maintainer files that require"
163c8571806Smrg      echo "the 'autom4te' program to be rebuilt."
164c889a3bfSmrg      program_details 'autom4te'
165c889a3bfSmrg      ;;
166c889a3bfSmrg    bison*|yacc*)
167c889a3bfSmrg      echo "You should only need it if you modified a '.y' file."
168c889a3bfSmrg      echo "You may want to install the GNU Bison package:"
169c889a3bfSmrg      echo "<$gnu_software_URL/bison/>"
170c889a3bfSmrg      ;;
171c889a3bfSmrg    lex*|flex*)
172c889a3bfSmrg      echo "You should only need it if you modified a '.l' file."
173c889a3bfSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
174c889a3bfSmrg      echo "<$flex_URL>"
175c889a3bfSmrg      ;;
176c889a3bfSmrg    help2man*)
177c889a3bfSmrg      echo "You should only need it if you modified a dependency" \
178c889a3bfSmrg           "of a man page."
179c889a3bfSmrg      echo "You may want to install the GNU Help2man package:"
180c889a3bfSmrg      echo "<$gnu_software_URL/help2man/>"
181c889a3bfSmrg    ;;
182c889a3bfSmrg    makeinfo*)
183c889a3bfSmrg      echo "You should only need it if you modified a '.texi' file, or"
184c889a3bfSmrg      echo "any other file indirectly affecting the aspect of the manual."
185c889a3bfSmrg      echo "You might want to install the Texinfo package:"
186c889a3bfSmrg      echo "<$gnu_software_URL/texinfo/>"
187c889a3bfSmrg      echo "The spurious makeinfo call might also be the consequence of"
188c889a3bfSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189c889a3bfSmrg      echo "want to install GNU make:"
190c889a3bfSmrg      echo "<$gnu_software_URL/make/>"
191c889a3bfSmrg      ;;
192c889a3bfSmrg    *)
193c889a3bfSmrg      echo "You might have modified some files without having the proper"
194c889a3bfSmrg      echo "tools for further handling them.  Check the 'README' file, it"
195c889a3bfSmrg      echo "often tells you about the needed prerequisites for installing"
196c889a3bfSmrg      echo "this package.  You may also peek at any GNU archive site, in"
197c889a3bfSmrg      echo "case some other package contains this missing '$1' program."
198c889a3bfSmrg      ;;
199c889a3bfSmrg  esac
200c889a3bfSmrg}
201c889a3bfSmrg
202c889a3bfSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203c889a3bfSmrg                       -e '2,$s/^/         /' >&2
204c889a3bfSmrg
205c889a3bfSmrg# Propagate the correct exit status (expected to be 127 for a program
206c889a3bfSmrg# not found, 63 for a program that failed due to version mismatch).
207c889a3bfSmrgexit $st
2087a84e134Smrg
2097a84e134Smrg# Local variables:
2105ec34c4cSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2117a84e134Smrg# time-stamp-start: "scriptversion="
2127a84e134Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2135ec34c4cSmrg# time-stamp-time-zone: "UTC0"
214e1e1713cSmrg# time-stamp-end: "; # UTC"
2157a84e134Smrg# End:
216