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