1c95b42baSmrg#! /bin/sh
2b8f63ae3Smrg# Common wrapper for a few potentially missing GNU programs.
3c95b42baSmrg
40f595aedSmrgscriptversion=2018-03-07.03; # UTC
5c95b42baSmrg
60f595aedSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7b8f63ae3Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8c95b42baSmrg
9c95b42baSmrg# This program is free software; you can redistribute it and/or modify
10c95b42baSmrg# it under the terms of the GNU General Public License as published by
11c95b42baSmrg# the Free Software Foundation; either version 2, or (at your option)
12c95b42baSmrg# any later version.
13c95b42baSmrg
14c95b42baSmrg# This program is distributed in the hope that it will be useful,
15c95b42baSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16c95b42baSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17c95b42baSmrg# GNU General Public License for more details.
18c95b42baSmrg
19c95b42baSmrg# You should have received a copy of the GNU General Public License
200f595aedSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21c95b42baSmrg
22c95b42baSmrg# As a special exception to the GNU General Public License, if you
23c95b42baSmrg# distribute this file as part of a program that contains a
24c95b42baSmrg# configuration script generated by Autoconf, you may include it under
25c95b42baSmrg# the same distribution terms that you use for the rest of that program.
26c95b42baSmrg
27c95b42baSmrgif test $# -eq 0; then
28b8f63ae3Smrg  echo 1>&2 "Try '$0 --help' for more information"
29c95b42baSmrg  exit 1
30c95b42baSmrgfi
31c95b42baSmrg
32b8f63ae3Smrgcase $1 in
33c95b42baSmrg
34b8f63ae3Smrg  --is-lightweight)
35b8f63ae3Smrg    # Used by our autoconf macros to check whether the available missing
36b8f63ae3Smrg    # script is modern enough.
37b8f63ae3Smrg    exit 0
38b8f63ae3Smrg    ;;
39c95b42baSmrg
40b8f63ae3Smrg  --run)
41b8f63ae3Smrg    # Back-compat with the calling convention used by older automake.
42b8f63ae3Smrg    shift
43b8f63ae3Smrg    ;;
44c95b42baSmrg
45c95b42baSmrg  -h|--h|--he|--hel|--help)
46c95b42baSmrg    echo "\
47c95b42baSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48c95b42baSmrg
49b8f63ae3SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50b8f63ae3Smrgto PROGRAM being missing or too old.
51c95b42baSmrg
52c95b42baSmrgOptions:
53c95b42baSmrg  -h, --help      display this help and exit
54c95b42baSmrg  -v, --version   output version information and exit
55c95b42baSmrg
56c95b42baSmrgSupported PROGRAM values:
57b8f63ae3Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58b8f63ae3Smrg  bison     yacc      flex         lex       help2man
59c95b42baSmrg
60b8f63ae3SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61b8f63ae3Smrg'g' are ignored when checking the name.
62f40e0d56Smrg
63c95b42baSmrgSend bug reports to <bug-automake@gnu.org>."
64c95b42baSmrg    exit $?
65c95b42baSmrg    ;;
66c95b42baSmrg
67c95b42baSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68c95b42baSmrg    echo "missing $scriptversion (GNU Automake)"
69c95b42baSmrg    exit $?
70c95b42baSmrg    ;;
71c95b42baSmrg
72c95b42baSmrg  -*)
73b8f63ae3Smrg    echo 1>&2 "$0: unknown '$1' option"
74b8f63ae3Smrg    echo 1>&2 "Try '$0 --help' for more information"
75c95b42baSmrg    exit 1
76c95b42baSmrg    ;;
77c95b42baSmrg
78c95b42baSmrgesac
79c95b42baSmrg
80b8f63ae3Smrg# Run the given program, remember its exit status.
81b8f63ae3Smrg"$@"; st=$?
82b8f63ae3Smrg
83b8f63ae3Smrg# If it succeeded, we are done.
84b8f63ae3Smrgtest $st -eq 0 && exit 0
85b8f63ae3Smrg
86b8f63ae3Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
87b8f63ae3Smrg# passed; such an option is passed most likely to detect whether the
88b8f63ae3Smrg# program is present and works.
89b8f63ae3Smrgcase $2 in --version|--help) exit $st;; esac
90b8f63ae3Smrg
91b8f63ae3Smrg# Exit code 63 means version mismatch.  This often happens when the user
92b8f63ae3Smrg# tries to use an ancient version of a tool on a file that requires a
93b8f63ae3Smrg# minimum version.
94b8f63ae3Smrgif test $st -eq 63; then
95b8f63ae3Smrg  msg="probably too old"
96b8f63ae3Smrgelif test $st -eq 127; then
97b8f63ae3Smrg  # Program was missing.
98b8f63ae3Smrg  msg="missing on your system"
99b8f63ae3Smrgelse
100b8f63ae3Smrg  # Program was found and executed, but failed.  Give up.
101b8f63ae3Smrg  exit $st
102b8f63ae3Smrgfi
103c95b42baSmrg
1040f595aedSmrgperl_URL=https://www.perl.org/
1050f595aedSmrgflex_URL=https://github.com/westes/flex
1060f595aedSmrggnu_software_URL=https://www.gnu.org/software
107b8f63ae3Smrg
108b8f63ae3Smrgprogram_details ()
109b8f63ae3Smrg{
110b8f63ae3Smrg  case $1 in
111b8f63ae3Smrg    aclocal|automake)
112b8f63ae3Smrg      echo "The '$1' program is part of the GNU Automake package:"
113b8f63ae3Smrg      echo "<$gnu_software_URL/automake>"
114b8f63ae3Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115b8f63ae3Smrg      echo "<$gnu_software_URL/autoconf>"
116b8f63ae3Smrg      echo "<$gnu_software_URL/m4/>"
117b8f63ae3Smrg      echo "<$perl_URL>"
118b8f63ae3Smrg      ;;
119b8f63ae3Smrg    autoconf|autom4te|autoheader)
120b8f63ae3Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
121b8f63ae3Smrg      echo "<$gnu_software_URL/autoconf/>"
122b8f63ae3Smrg      echo "It also requires GNU m4 and Perl in order to run:"
123b8f63ae3Smrg      echo "<$gnu_software_URL/m4/>"
124b8f63ae3Smrg      echo "<$perl_URL>"
125b8f63ae3Smrg      ;;
126b8f63ae3Smrg  esac
127b8f63ae3Smrg}
128b8f63ae3Smrg
129b8f63ae3Smrggive_advice ()
130b8f63ae3Smrg{
131b8f63ae3Smrg  # Normalize program name to check for.
132b8f63ae3Smrg  normalized_program=`echo "$1" | sed '
133b8f63ae3Smrg    s/^gnu-//; t
134b8f63ae3Smrg    s/^gnu//; t
135b8f63ae3Smrg    s/^g//; t'`
136b8f63ae3Smrg
137b8f63ae3Smrg  printf '%s\n' "'$1' is $msg."
138b8f63ae3Smrg
139b8f63ae3Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140b8f63ae3Smrg  case $normalized_program in
141b8f63ae3Smrg    autoconf*)
142b8f63ae3Smrg      echo "You should only need it if you modified 'configure.ac',"
143b8f63ae3Smrg      echo "or m4 files included by it."
144b8f63ae3Smrg      program_details 'autoconf'
145b8f63ae3Smrg      ;;
146b8f63ae3Smrg    autoheader*)
147b8f63ae3Smrg      echo "You should only need it if you modified 'acconfig.h' or"
148b8f63ae3Smrg      echo "$configure_deps."
149b8f63ae3Smrg      program_details 'autoheader'
150b8f63ae3Smrg      ;;
151b8f63ae3Smrg    automake*)
152b8f63ae3Smrg      echo "You should only need it if you modified 'Makefile.am' or"
153b8f63ae3Smrg      echo "$configure_deps."
154b8f63ae3Smrg      program_details 'automake'
155b8f63ae3Smrg      ;;
156b8f63ae3Smrg    aclocal*)
157b8f63ae3Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
158b8f63ae3Smrg      echo "$configure_deps."
159b8f63ae3Smrg      program_details 'aclocal'
160b8f63ae3Smrg      ;;
161b8f63ae3Smrg   autom4te*)
162b8f63ae3Smrg      echo "You might have modified some maintainer files that require"
163b8f63ae3Smrg      echo "the 'autom4te' program to be rebuilt."
164b8f63ae3Smrg      program_details 'autom4te'
165b8f63ae3Smrg      ;;
166b8f63ae3Smrg    bison*|yacc*)
167b8f63ae3Smrg      echo "You should only need it if you modified a '.y' file."
168b8f63ae3Smrg      echo "You may want to install the GNU Bison package:"
169b8f63ae3Smrg      echo "<$gnu_software_URL/bison/>"
170b8f63ae3Smrg      ;;
171b8f63ae3Smrg    lex*|flex*)
172b8f63ae3Smrg      echo "You should only need it if you modified a '.l' file."
173b8f63ae3Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
174b8f63ae3Smrg      echo "<$flex_URL>"
175b8f63ae3Smrg      ;;
176b8f63ae3Smrg    help2man*)
177b8f63ae3Smrg      echo "You should only need it if you modified a dependency" \
178b8f63ae3Smrg           "of a man page."
179b8f63ae3Smrg      echo "You may want to install the GNU Help2man package:"
180b8f63ae3Smrg      echo "<$gnu_software_URL/help2man/>"
181b8f63ae3Smrg    ;;
182b8f63ae3Smrg    makeinfo*)
183b8f63ae3Smrg      echo "You should only need it if you modified a '.texi' file, or"
184b8f63ae3Smrg      echo "any other file indirectly affecting the aspect of the manual."
185b8f63ae3Smrg      echo "You might want to install the Texinfo package:"
186b8f63ae3Smrg      echo "<$gnu_software_URL/texinfo/>"
187b8f63ae3Smrg      echo "The spurious makeinfo call might also be the consequence of"
188b8f63ae3Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189b8f63ae3Smrg      echo "want to install GNU make:"
190b8f63ae3Smrg      echo "<$gnu_software_URL/make/>"
191b8f63ae3Smrg      ;;
192b8f63ae3Smrg    *)
193b8f63ae3Smrg      echo "You might have modified some files without having the proper"
194b8f63ae3Smrg      echo "tools for further handling them.  Check the 'README' file, it"
195b8f63ae3Smrg      echo "often tells you about the needed prerequisites for installing"
196b8f63ae3Smrg      echo "this package.  You may also peek at any GNU archive site, in"
197b8f63ae3Smrg      echo "case some other package contains this missing '$1' program."
198b8f63ae3Smrg      ;;
199b8f63ae3Smrg  esac
200b8f63ae3Smrg}
201b8f63ae3Smrg
202b8f63ae3Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203b8f63ae3Smrg                       -e '2,$s/^/         /' >&2
204b8f63ae3Smrg
205b8f63ae3Smrg# Propagate the correct exit status (expected to be 127 for a program
206b8f63ae3Smrg# not found, 63 for a program that failed due to version mismatch).
207b8f63ae3Smrgexit $st
208c95b42baSmrg
209c95b42baSmrg# Local variables:
2100f595aedSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
211c95b42baSmrg# time-stamp-start: "scriptversion="
212c95b42baSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2130f595aedSmrg# time-stamp-time-zone: "UTC0"
214f40e0d56Smrg# time-stamp-end: "; # UTC"
215c95b42baSmrg# End:
216