1692f60a7Smrg#! /bin/sh
2eaa3dbe0Smrg# Common wrapper for a few potentially missing GNU programs.
3692f60a7Smrg
4efb46889Smrgscriptversion=2018-03-07.03; # UTC
5692f60a7Smrg
6efb46889Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7eaa3dbe0Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8692f60a7Smrg
9692f60a7Smrg# This program is free software; you can redistribute it and/or modify
10692f60a7Smrg# it under the terms of the GNU General Public License as published by
11692f60a7Smrg# the Free Software Foundation; either version 2, or (at your option)
12692f60a7Smrg# any later version.
13692f60a7Smrg
14692f60a7Smrg# This program is distributed in the hope that it will be useful,
15692f60a7Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16692f60a7Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17692f60a7Smrg# GNU General Public License for more details.
18692f60a7Smrg
19692f60a7Smrg# You should have received a copy of the GNU General Public License
20efb46889Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21692f60a7Smrg
22692f60a7Smrg# As a special exception to the GNU General Public License, if you
23692f60a7Smrg# distribute this file as part of a program that contains a
24692f60a7Smrg# configuration script generated by Autoconf, you may include it under
25692f60a7Smrg# the same distribution terms that you use for the rest of that program.
26692f60a7Smrg
27692f60a7Smrgif test $# -eq 0; then
28eaa3dbe0Smrg  echo 1>&2 "Try '$0 --help' for more information"
29692f60a7Smrg  exit 1
30692f60a7Smrgfi
31692f60a7Smrg
32eaa3dbe0Smrgcase $1 in
33692f60a7Smrg
34eaa3dbe0Smrg  --is-lightweight)
35eaa3dbe0Smrg    # Used by our autoconf macros to check whether the available missing
36eaa3dbe0Smrg    # script is modern enough.
37eaa3dbe0Smrg    exit 0
38eaa3dbe0Smrg    ;;
39692f60a7Smrg
40eaa3dbe0Smrg  --run)
41eaa3dbe0Smrg    # Back-compat with the calling convention used by older automake.
42eaa3dbe0Smrg    shift
43eaa3dbe0Smrg    ;;
44692f60a7Smrg
45692f60a7Smrg  -h|--h|--he|--hel|--help)
46692f60a7Smrg    echo "\
47692f60a7Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48692f60a7Smrg
49eaa3dbe0SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50eaa3dbe0Smrgto PROGRAM being missing or too old.
51692f60a7Smrg
52692f60a7SmrgOptions:
53692f60a7Smrg  -h, --help      display this help and exit
54692f60a7Smrg  -v, --version   output version information and exit
55692f60a7Smrg
56692f60a7SmrgSupported PROGRAM values:
57eaa3dbe0Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58eaa3dbe0Smrg  bison     yacc      flex         lex       help2man
59692f60a7Smrg
60eaa3dbe0SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61eaa3dbe0Smrg'g' are ignored when checking the name.
623f6d0e1dSmrg
63692f60a7SmrgSend bug reports to <bug-automake@gnu.org>."
64692f60a7Smrg    exit $?
65692f60a7Smrg    ;;
66692f60a7Smrg
67692f60a7Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68692f60a7Smrg    echo "missing $scriptversion (GNU Automake)"
69692f60a7Smrg    exit $?
70692f60a7Smrg    ;;
71692f60a7Smrg
72692f60a7Smrg  -*)
73eaa3dbe0Smrg    echo 1>&2 "$0: unknown '$1' option"
74eaa3dbe0Smrg    echo 1>&2 "Try '$0 --help' for more information"
75692f60a7Smrg    exit 1
76692f60a7Smrg    ;;
77692f60a7Smrg
78692f60a7Smrgesac
79692f60a7Smrg
80eaa3dbe0Smrg# Run the given program, remember its exit status.
81eaa3dbe0Smrg"$@"; st=$?
82eaa3dbe0Smrg
83eaa3dbe0Smrg# If it succeeded, we are done.
84eaa3dbe0Smrgtest $st -eq 0 && exit 0
85eaa3dbe0Smrg
86eaa3dbe0Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
87eaa3dbe0Smrg# passed; such an option is passed most likely to detect whether the
88eaa3dbe0Smrg# program is present and works.
89eaa3dbe0Smrgcase $2 in --version|--help) exit $st;; esac
90eaa3dbe0Smrg
91eaa3dbe0Smrg# Exit code 63 means version mismatch.  This often happens when the user
92eaa3dbe0Smrg# tries to use an ancient version of a tool on a file that requires a
93eaa3dbe0Smrg# minimum version.
94eaa3dbe0Smrgif test $st -eq 63; then
95eaa3dbe0Smrg  msg="probably too old"
96eaa3dbe0Smrgelif test $st -eq 127; then
97eaa3dbe0Smrg  # Program was missing.
98eaa3dbe0Smrg  msg="missing on your system"
99eaa3dbe0Smrgelse
100eaa3dbe0Smrg  # Program was found and executed, but failed.  Give up.
101eaa3dbe0Smrg  exit $st
102eaa3dbe0Smrgfi
103692f60a7Smrg
104efb46889Smrgperl_URL=https://www.perl.org/
105efb46889Smrgflex_URL=https://github.com/westes/flex
106efb46889Smrggnu_software_URL=https://www.gnu.org/software
107eaa3dbe0Smrg
108eaa3dbe0Smrgprogram_details ()
109eaa3dbe0Smrg{
110eaa3dbe0Smrg  case $1 in
111eaa3dbe0Smrg    aclocal|automake)
112eaa3dbe0Smrg      echo "The '$1' program is part of the GNU Automake package:"
113eaa3dbe0Smrg      echo "<$gnu_software_URL/automake>"
114eaa3dbe0Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115eaa3dbe0Smrg      echo "<$gnu_software_URL/autoconf>"
116eaa3dbe0Smrg      echo "<$gnu_software_URL/m4/>"
117eaa3dbe0Smrg      echo "<$perl_URL>"
118eaa3dbe0Smrg      ;;
119eaa3dbe0Smrg    autoconf|autom4te|autoheader)
120eaa3dbe0Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
121eaa3dbe0Smrg      echo "<$gnu_software_URL/autoconf/>"
122eaa3dbe0Smrg      echo "It also requires GNU m4 and Perl in order to run:"
123eaa3dbe0Smrg      echo "<$gnu_software_URL/m4/>"
124eaa3dbe0Smrg      echo "<$perl_URL>"
125eaa3dbe0Smrg      ;;
126eaa3dbe0Smrg  esac
127eaa3dbe0Smrg}
128eaa3dbe0Smrg
129eaa3dbe0Smrggive_advice ()
130eaa3dbe0Smrg{
131eaa3dbe0Smrg  # Normalize program name to check for.
132eaa3dbe0Smrg  normalized_program=`echo "$1" | sed '
133eaa3dbe0Smrg    s/^gnu-//; t
134eaa3dbe0Smrg    s/^gnu//; t
135eaa3dbe0Smrg    s/^g//; t'`
136eaa3dbe0Smrg
137eaa3dbe0Smrg  printf '%s\n' "'$1' is $msg."
138eaa3dbe0Smrg
139eaa3dbe0Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140eaa3dbe0Smrg  case $normalized_program in
141eaa3dbe0Smrg    autoconf*)
142eaa3dbe0Smrg      echo "You should only need it if you modified 'configure.ac',"
143eaa3dbe0Smrg      echo "or m4 files included by it."
144eaa3dbe0Smrg      program_details 'autoconf'
145eaa3dbe0Smrg      ;;
146eaa3dbe0Smrg    autoheader*)
147eaa3dbe0Smrg      echo "You should only need it if you modified 'acconfig.h' or"
148eaa3dbe0Smrg      echo "$configure_deps."
149eaa3dbe0Smrg      program_details 'autoheader'
150eaa3dbe0Smrg      ;;
151eaa3dbe0Smrg    automake*)
152eaa3dbe0Smrg      echo "You should only need it if you modified 'Makefile.am' or"
153eaa3dbe0Smrg      echo "$configure_deps."
154eaa3dbe0Smrg      program_details 'automake'
155eaa3dbe0Smrg      ;;
156eaa3dbe0Smrg    aclocal*)
157eaa3dbe0Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
158eaa3dbe0Smrg      echo "$configure_deps."
159eaa3dbe0Smrg      program_details 'aclocal'
160eaa3dbe0Smrg      ;;
161eaa3dbe0Smrg   autom4te*)
162eaa3dbe0Smrg      echo "You might have modified some maintainer files that require"
16395903e71Smrg      echo "the 'autom4te' program to be rebuilt."
164eaa3dbe0Smrg      program_details 'autom4te'
165eaa3dbe0Smrg      ;;
166eaa3dbe0Smrg    bison*|yacc*)
167eaa3dbe0Smrg      echo "You should only need it if you modified a '.y' file."
168eaa3dbe0Smrg      echo "You may want to install the GNU Bison package:"
169eaa3dbe0Smrg      echo "<$gnu_software_URL/bison/>"
170eaa3dbe0Smrg      ;;
171eaa3dbe0Smrg    lex*|flex*)
172eaa3dbe0Smrg      echo "You should only need it if you modified a '.l' file."
173eaa3dbe0Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
174eaa3dbe0Smrg      echo "<$flex_URL>"
175eaa3dbe0Smrg      ;;
176eaa3dbe0Smrg    help2man*)
177eaa3dbe0Smrg      echo "You should only need it if you modified a dependency" \
178eaa3dbe0Smrg           "of a man page."
179eaa3dbe0Smrg      echo "You may want to install the GNU Help2man package:"
180eaa3dbe0Smrg      echo "<$gnu_software_URL/help2man/>"
181692f60a7Smrg    ;;
182eaa3dbe0Smrg    makeinfo*)
183eaa3dbe0Smrg      echo "You should only need it if you modified a '.texi' file, or"
184eaa3dbe0Smrg      echo "any other file indirectly affecting the aspect of the manual."
185eaa3dbe0Smrg      echo "You might want to install the Texinfo package:"
186eaa3dbe0Smrg      echo "<$gnu_software_URL/texinfo/>"
187eaa3dbe0Smrg      echo "The spurious makeinfo call might also be the consequence of"
188eaa3dbe0Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189eaa3dbe0Smrg      echo "want to install GNU make:"
190eaa3dbe0Smrg      echo "<$gnu_software_URL/make/>"
191eaa3dbe0Smrg      ;;
192eaa3dbe0Smrg    *)
193eaa3dbe0Smrg      echo "You might have modified some files without having the proper"
194eaa3dbe0Smrg      echo "tools for further handling them.  Check the 'README' file, it"
195eaa3dbe0Smrg      echo "often tells you about the needed prerequisites for installing"
196eaa3dbe0Smrg      echo "this package.  You may also peek at any GNU archive site, in"
197eaa3dbe0Smrg      echo "case some other package contains this missing '$1' program."
198eaa3dbe0Smrg      ;;
199eaa3dbe0Smrg  esac
200eaa3dbe0Smrg}
201eaa3dbe0Smrg
202eaa3dbe0Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203eaa3dbe0Smrg                       -e '2,$s/^/         /' >&2
204eaa3dbe0Smrg
205eaa3dbe0Smrg# Propagate the correct exit status (expected to be 127 for a program
206eaa3dbe0Smrg# not found, 63 for a program that failed due to version mismatch).
207eaa3dbe0Smrgexit $st
208692f60a7Smrg
209692f60a7Smrg# Local variables:
210efb46889Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
211692f60a7Smrg# time-stamp-start: "scriptversion="
212692f60a7Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213efb46889Smrg# time-stamp-time-zone: "UTC0"
2143f6d0e1dSmrg# time-stamp-end: "; # UTC"
215692f60a7Smrg# End:
216