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