1a6fdc6faSmrg#! /bin/sh
2541411ceSmrg# Common wrapper for a few potentially missing GNU programs.
335d5702bSmrg
4541411ceSmrgscriptversion=2018-03-07.03; # UTC
535d5702bSmrg
6541411ceSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7541411ceSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8a6fdc6faSmrg
9a6fdc6faSmrg# This program is free software; you can redistribute it and/or modify
10a6fdc6faSmrg# it under the terms of the GNU General Public License as published by
11a6fdc6faSmrg# the Free Software Foundation; either version 2, or (at your option)
12a6fdc6faSmrg# any later version.
13a6fdc6faSmrg
14a6fdc6faSmrg# This program is distributed in the hope that it will be useful,
15a6fdc6faSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16a6fdc6faSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a6fdc6faSmrg# GNU General Public License for more details.
18a6fdc6faSmrg
19a6fdc6faSmrg# You should have received a copy of the GNU General Public License
20541411ceSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21a6fdc6faSmrg
22a6fdc6faSmrg# As a special exception to the GNU General Public License, if you
23a6fdc6faSmrg# distribute this file as part of a program that contains a
24a6fdc6faSmrg# configuration script generated by Autoconf, you may include it under
25a6fdc6faSmrg# the same distribution terms that you use for the rest of that program.
26a6fdc6faSmrg
27a6fdc6faSmrgif test $# -eq 0; then
28541411ceSmrg  echo 1>&2 "Try '$0 --help' for more information"
29a6fdc6faSmrg  exit 1
30a6fdc6faSmrgfi
31a6fdc6faSmrg
32541411ceSmrgcase $1 in
33a6fdc6faSmrg
34541411ceSmrg  --is-lightweight)
35541411ceSmrg    # Used by our autoconf macros to check whether the available missing
36541411ceSmrg    # script is modern enough.
37541411ceSmrg    exit 0
38541411ceSmrg    ;;
3935d5702bSmrg
40541411ceSmrg  --run)
41541411ceSmrg    # Back-compat with the calling convention used by older automake.
42541411ceSmrg    shift
43541411ceSmrg    ;;
44a6fdc6faSmrg
45a6fdc6faSmrg  -h|--h|--he|--hel|--help)
46a6fdc6faSmrg    echo "\
47a6fdc6faSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48a6fdc6faSmrg
49541411ceSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50541411ceSmrgto PROGRAM being missing or too old.
51a6fdc6faSmrg
52a6fdc6faSmrgOptions:
53a6fdc6faSmrg  -h, --help      display this help and exit
54a6fdc6faSmrg  -v, --version   output version information and exit
55a6fdc6faSmrg
56a6fdc6faSmrgSupported PROGRAM values:
57541411ceSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58541411ceSmrg  bison     yacc      flex         lex       help2man
5935d5702bSmrg
60541411ceSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61541411ceSmrg'g' are ignored when checking the name.
6235d5702bSmrg
6335d5702bSmrgSend bug reports to <bug-automake@gnu.org>."
6435d5702bSmrg    exit $?
65a6fdc6faSmrg    ;;
66a6fdc6faSmrg
67a6fdc6faSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6835d5702bSmrg    echo "missing $scriptversion (GNU Automake)"
6935d5702bSmrg    exit $?
70a6fdc6faSmrg    ;;
71a6fdc6faSmrg
72a6fdc6faSmrg  -*)
73541411ceSmrg    echo 1>&2 "$0: unknown '$1' option"
74541411ceSmrg    echo 1>&2 "Try '$0 --help' for more information"
75a6fdc6faSmrg    exit 1
76a6fdc6faSmrg    ;;
77a6fdc6faSmrg
7835d5702bSmrgesac
7935d5702bSmrg
80541411ceSmrg# Run the given program, remember its exit status.
81541411ceSmrg"$@"; st=$?
82541411ceSmrg
83541411ceSmrg# If it succeeded, we are done.
84541411ceSmrgtest $st -eq 0 && exit 0
85541411ceSmrg
86541411ceSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
87541411ceSmrg# passed; such an option is passed most likely to detect whether the
88541411ceSmrg# program is present and works.
89541411ceSmrgcase $2 in --version|--help) exit $st;; esac
90541411ceSmrg
91541411ceSmrg# Exit code 63 means version mismatch.  This often happens when the user
92541411ceSmrg# tries to use an ancient version of a tool on a file that requires a
93541411ceSmrg# minimum version.
94541411ceSmrgif test $st -eq 63; then
95541411ceSmrg  msg="probably too old"
96541411ceSmrgelif test $st -eq 127; then
97541411ceSmrg  # Program was missing.
98541411ceSmrg  msg="missing on your system"
99541411ceSmrgelse
100541411ceSmrg  # Program was found and executed, but failed.  Give up.
101541411ceSmrg  exit $st
102541411ceSmrgfi
103a6fdc6faSmrg
104541411ceSmrgperl_URL=https://www.perl.org/
105541411ceSmrgflex_URL=https://github.com/westes/flex
106541411ceSmrggnu_software_URL=https://www.gnu.org/software
107541411ceSmrg
108541411ceSmrgprogram_details ()
109541411ceSmrg{
110541411ceSmrg  case $1 in
111541411ceSmrg    aclocal|automake)
112541411ceSmrg      echo "The '$1' program is part of the GNU Automake package:"
113541411ceSmrg      echo "<$gnu_software_URL/automake>"
114541411ceSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115541411ceSmrg      echo "<$gnu_software_URL/autoconf>"
116541411ceSmrg      echo "<$gnu_software_URL/m4/>"
117541411ceSmrg      echo "<$perl_URL>"
118541411ceSmrg      ;;
119541411ceSmrg    autoconf|autom4te|autoheader)
120541411ceSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
121541411ceSmrg      echo "<$gnu_software_URL/autoconf/>"
122541411ceSmrg      echo "It also requires GNU m4 and Perl in order to run:"
123541411ceSmrg      echo "<$gnu_software_URL/m4/>"
124541411ceSmrg      echo "<$perl_URL>"
125541411ceSmrg      ;;
126541411ceSmrg  esac
127541411ceSmrg}
128541411ceSmrg
129541411ceSmrggive_advice ()
130541411ceSmrg{
131541411ceSmrg  # Normalize program name to check for.
132541411ceSmrg  normalized_program=`echo "$1" | sed '
133541411ceSmrg    s/^gnu-//; t
134541411ceSmrg    s/^gnu//; t
135541411ceSmrg    s/^g//; t'`
136541411ceSmrg
137541411ceSmrg  printf '%s\n' "'$1' is $msg."
138541411ceSmrg
139541411ceSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140541411ceSmrg  case $normalized_program in
141541411ceSmrg    autoconf*)
142541411ceSmrg      echo "You should only need it if you modified 'configure.ac',"
143541411ceSmrg      echo "or m4 files included by it."
144541411ceSmrg      program_details 'autoconf'
145541411ceSmrg      ;;
146541411ceSmrg    autoheader*)
147541411ceSmrg      echo "You should only need it if you modified 'acconfig.h' or"
148541411ceSmrg      echo "$configure_deps."
149541411ceSmrg      program_details 'autoheader'
150541411ceSmrg      ;;
151541411ceSmrg    automake*)
152541411ceSmrg      echo "You should only need it if you modified 'Makefile.am' or"
153541411ceSmrg      echo "$configure_deps."
154541411ceSmrg      program_details 'automake'
155541411ceSmrg      ;;
156541411ceSmrg    aclocal*)
157541411ceSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
158541411ceSmrg      echo "$configure_deps."
159541411ceSmrg      program_details 'aclocal'
160541411ceSmrg      ;;
161541411ceSmrg   autom4te*)
162541411ceSmrg      echo "You might have modified some maintainer files that require"
163541411ceSmrg      echo "the 'autom4te' program to be rebuilt."
164541411ceSmrg      program_details 'autom4te'
165541411ceSmrg      ;;
166541411ceSmrg    bison*|yacc*)
167541411ceSmrg      echo "You should only need it if you modified a '.y' file."
168541411ceSmrg      echo "You may want to install the GNU Bison package:"
169541411ceSmrg      echo "<$gnu_software_URL/bison/>"
170541411ceSmrg      ;;
171541411ceSmrg    lex*|flex*)
172541411ceSmrg      echo "You should only need it if you modified a '.l' file."
173541411ceSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
174541411ceSmrg      echo "<$flex_URL>"
175541411ceSmrg      ;;
176541411ceSmrg    help2man*)
177541411ceSmrg      echo "You should only need it if you modified a dependency" \
178541411ceSmrg           "of a man page."
179541411ceSmrg      echo "You may want to install the GNU Help2man package:"
180541411ceSmrg      echo "<$gnu_software_URL/help2man/>"
181541411ceSmrg    ;;
182541411ceSmrg    makeinfo*)
183541411ceSmrg      echo "You should only need it if you modified a '.texi' file, or"
184541411ceSmrg      echo "any other file indirectly affecting the aspect of the manual."
185541411ceSmrg      echo "You might want to install the Texinfo package:"
186541411ceSmrg      echo "<$gnu_software_URL/texinfo/>"
187541411ceSmrg      echo "The spurious makeinfo call might also be the consequence of"
188541411ceSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189541411ceSmrg      echo "want to install GNU make:"
190541411ceSmrg      echo "<$gnu_software_URL/make/>"
191541411ceSmrg      ;;
192541411ceSmrg    *)
193541411ceSmrg      echo "You might have modified some files without having the proper"
194541411ceSmrg      echo "tools for further handling them.  Check the 'README' file, it"
195541411ceSmrg      echo "often tells you about the needed prerequisites for installing"
196541411ceSmrg      echo "this package.  You may also peek at any GNU archive site, in"
197541411ceSmrg      echo "case some other package contains this missing '$1' program."
198541411ceSmrg      ;;
199541411ceSmrg  esac
200541411ceSmrg}
201541411ceSmrg
202541411ceSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203541411ceSmrg                       -e '2,$s/^/         /' >&2
204541411ceSmrg
205541411ceSmrg# Propagate the correct exit status (expected to be 127 for a program
206541411ceSmrg# not found, 63 for a program that failed due to version mismatch).
207541411ceSmrgexit $st
20835d5702bSmrg
20935d5702bSmrg# Local variables:
210541411ceSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
21135d5702bSmrg# time-stamp-start: "scriptversion="
21235d5702bSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213541411ceSmrg# time-stamp-time-zone: "UTC0"
21435d5702bSmrg# time-stamp-end: "; # UTC"
21535d5702bSmrg# End:
216