195b296d0Smrg#! /bin/sh
2eca46af7Smrg# Common wrapper for a few potentially missing GNU programs.
395b296d0Smrg
4d87a3195Smrgscriptversion=2018-03-07.03; # UTC
595b296d0Smrg
6d87a3195Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
7eca46af7Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
895b296d0Smrg
995b296d0Smrg# This program is free software; you can redistribute it and/or modify
1095b296d0Smrg# it under the terms of the GNU General Public License as published by
1195b296d0Smrg# the Free Software Foundation; either version 2, or (at your option)
1295b296d0Smrg# any later version.
1395b296d0Smrg
1495b296d0Smrg# This program is distributed in the hope that it will be useful,
1595b296d0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1695b296d0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1795b296d0Smrg# GNU General Public License for more details.
1895b296d0Smrg
1995b296d0Smrg# You should have received a copy of the GNU General Public License
20d87a3195Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2195b296d0Smrg
2295b296d0Smrg# As a special exception to the GNU General Public License, if you
2395b296d0Smrg# distribute this file as part of a program that contains a
2495b296d0Smrg# configuration script generated by Autoconf, you may include it under
2595b296d0Smrg# the same distribution terms that you use for the rest of that program.
2695b296d0Smrg
2795b296d0Smrgif test $# -eq 0; then
28eca46af7Smrg  echo 1>&2 "Try '$0 --help' for more information"
2995b296d0Smrg  exit 1
3095b296d0Smrgfi
3195b296d0Smrg
32eca46af7Smrgcase $1 in
3395b296d0Smrg
34eca46af7Smrg  --is-lightweight)
35eca46af7Smrg    # Used by our autoconf macros to check whether the available missing
36eca46af7Smrg    # script is modern enough.
37eca46af7Smrg    exit 0
38eca46af7Smrg    ;;
3995b296d0Smrg
40eca46af7Smrg  --run)
41eca46af7Smrg    # Back-compat with the calling convention used by older automake.
42eca46af7Smrg    shift
43eca46af7Smrg    ;;
4495b296d0Smrg
4595b296d0Smrg  -h|--h|--he|--hel|--help)
4695b296d0Smrg    echo "\
4795b296d0Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4895b296d0Smrg
49eca46af7SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50eca46af7Smrgto PROGRAM being missing or too old.
5195b296d0Smrg
5295b296d0SmrgOptions:
5395b296d0Smrg  -h, --help      display this help and exit
5495b296d0Smrg  -v, --version   output version information and exit
5595b296d0Smrg
5695b296d0SmrgSupported PROGRAM values:
57eca46af7Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58eca46af7Smrg  bison     yacc      flex         lex       help2man
5995b296d0Smrg
60eca46af7SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61eca46af7Smrg'g' are ignored when checking the name.
6214330f12Smrg
6395b296d0SmrgSend bug reports to <bug-automake@gnu.org>."
6495b296d0Smrg    exit $?
6595b296d0Smrg    ;;
6695b296d0Smrg
6795b296d0Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6895b296d0Smrg    echo "missing $scriptversion (GNU Automake)"
6995b296d0Smrg    exit $?
7095b296d0Smrg    ;;
7195b296d0Smrg
7295b296d0Smrg  -*)
73eca46af7Smrg    echo 1>&2 "$0: unknown '$1' option"
74eca46af7Smrg    echo 1>&2 "Try '$0 --help' for more information"
7595b296d0Smrg    exit 1
7695b296d0Smrg    ;;
7795b296d0Smrg
7895b296d0Smrgesac
7995b296d0Smrg
80eca46af7Smrg# Run the given program, remember its exit status.
81eca46af7Smrg"$@"; st=$?
82eca46af7Smrg
83eca46af7Smrg# If it succeeded, we are done.
84eca46af7Smrgtest $st -eq 0 && exit 0
85eca46af7Smrg
86eca46af7Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
87eca46af7Smrg# passed; such an option is passed most likely to detect whether the
88eca46af7Smrg# program is present and works.
89eca46af7Smrgcase $2 in --version|--help) exit $st;; esac
90eca46af7Smrg
91eca46af7Smrg# Exit code 63 means version mismatch.  This often happens when the user
92eca46af7Smrg# tries to use an ancient version of a tool on a file that requires a
93eca46af7Smrg# minimum version.
94eca46af7Smrgif test $st -eq 63; then
95eca46af7Smrg  msg="probably too old"
96eca46af7Smrgelif test $st -eq 127; then
97eca46af7Smrg  # Program was missing.
98eca46af7Smrg  msg="missing on your system"
99eca46af7Smrgelse
100eca46af7Smrg  # Program was found and executed, but failed.  Give up.
101eca46af7Smrg  exit $st
102eca46af7Smrgfi
10395b296d0Smrg
104d87a3195Smrgperl_URL=https://www.perl.org/
105d87a3195Smrgflex_URL=https://github.com/westes/flex
106d87a3195Smrggnu_software_URL=https://www.gnu.org/software
107eca46af7Smrg
108eca46af7Smrgprogram_details ()
109eca46af7Smrg{
110eca46af7Smrg  case $1 in
111eca46af7Smrg    aclocal|automake)
112eca46af7Smrg      echo "The '$1' program is part of the GNU Automake package:"
113eca46af7Smrg      echo "<$gnu_software_URL/automake>"
114eca46af7Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115eca46af7Smrg      echo "<$gnu_software_URL/autoconf>"
116eca46af7Smrg      echo "<$gnu_software_URL/m4/>"
117eca46af7Smrg      echo "<$perl_URL>"
118eca46af7Smrg      ;;
119eca46af7Smrg    autoconf|autom4te|autoheader)
120eca46af7Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
121eca46af7Smrg      echo "<$gnu_software_URL/autoconf/>"
122eca46af7Smrg      echo "It also requires GNU m4 and Perl in order to run:"
123eca46af7Smrg      echo "<$gnu_software_URL/m4/>"
124eca46af7Smrg      echo "<$perl_URL>"
125eca46af7Smrg      ;;
126eca46af7Smrg  esac
127eca46af7Smrg}
128eca46af7Smrg
129eca46af7Smrggive_advice ()
130eca46af7Smrg{
131eca46af7Smrg  # Normalize program name to check for.
132eca46af7Smrg  normalized_program=`echo "$1" | sed '
133eca46af7Smrg    s/^gnu-//; t
134eca46af7Smrg    s/^gnu//; t
135eca46af7Smrg    s/^g//; t'`
136eca46af7Smrg
137eca46af7Smrg  printf '%s\n' "'$1' is $msg."
138eca46af7Smrg
139eca46af7Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140eca46af7Smrg  case $normalized_program in
141eca46af7Smrg    autoconf*)
142eca46af7Smrg      echo "You should only need it if you modified 'configure.ac',"
143eca46af7Smrg      echo "or m4 files included by it."
144eca46af7Smrg      program_details 'autoconf'
145eca46af7Smrg      ;;
146eca46af7Smrg    autoheader*)
147eca46af7Smrg      echo "You should only need it if you modified 'acconfig.h' or"
148eca46af7Smrg      echo "$configure_deps."
149eca46af7Smrg      program_details 'autoheader'
150eca46af7Smrg      ;;
151eca46af7Smrg    automake*)
152eca46af7Smrg      echo "You should only need it if you modified 'Makefile.am' or"
153eca46af7Smrg      echo "$configure_deps."
154eca46af7Smrg      program_details 'automake'
155eca46af7Smrg      ;;
156eca46af7Smrg    aclocal*)
157eca46af7Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
158eca46af7Smrg      echo "$configure_deps."
159eca46af7Smrg      program_details 'aclocal'
160eca46af7Smrg      ;;
161eca46af7Smrg   autom4te*)
162eca46af7Smrg      echo "You might have modified some maintainer files that require"
163eca46af7Smrg      echo "the 'autom4te' program to be rebuilt."
164eca46af7Smrg      program_details 'autom4te'
165eca46af7Smrg      ;;
166eca46af7Smrg    bison*|yacc*)
167eca46af7Smrg      echo "You should only need it if you modified a '.y' file."
168eca46af7Smrg      echo "You may want to install the GNU Bison package:"
169eca46af7Smrg      echo "<$gnu_software_URL/bison/>"
170eca46af7Smrg      ;;
171eca46af7Smrg    lex*|flex*)
172eca46af7Smrg      echo "You should only need it if you modified a '.l' file."
173eca46af7Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
174eca46af7Smrg      echo "<$flex_URL>"
175eca46af7Smrg      ;;
176eca46af7Smrg    help2man*)
177eca46af7Smrg      echo "You should only need it if you modified a dependency" \
178eca46af7Smrg           "of a man page."
179eca46af7Smrg      echo "You may want to install the GNU Help2man package:"
180eca46af7Smrg      echo "<$gnu_software_URL/help2man/>"
181eca46af7Smrg    ;;
182eca46af7Smrg    makeinfo*)
183eca46af7Smrg      echo "You should only need it if you modified a '.texi' file, or"
184eca46af7Smrg      echo "any other file indirectly affecting the aspect of the manual."
185eca46af7Smrg      echo "You might want to install the Texinfo package:"
186eca46af7Smrg      echo "<$gnu_software_URL/texinfo/>"
187eca46af7Smrg      echo "The spurious makeinfo call might also be the consequence of"
188eca46af7Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189eca46af7Smrg      echo "want to install GNU make:"
190eca46af7Smrg      echo "<$gnu_software_URL/make/>"
191eca46af7Smrg      ;;
192eca46af7Smrg    *)
193eca46af7Smrg      echo "You might have modified some files without having the proper"
194eca46af7Smrg      echo "tools for further handling them.  Check the 'README' file, it"
195eca46af7Smrg      echo "often tells you about the needed prerequisites for installing"
196eca46af7Smrg      echo "this package.  You may also peek at any GNU archive site, in"
197eca46af7Smrg      echo "case some other package contains this missing '$1' program."
198eca46af7Smrg      ;;
199eca46af7Smrg  esac
200eca46af7Smrg}
201eca46af7Smrg
202eca46af7Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
203eca46af7Smrg                       -e '2,$s/^/         /' >&2
204eca46af7Smrg
205eca46af7Smrg# Propagate the correct exit status (expected to be 127 for a program
206eca46af7Smrg# not found, 63 for a program that failed due to version mismatch).
207eca46af7Smrgexit $st
20895b296d0Smrg
20995b296d0Smrg# Local variables:
210d87a3195Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
21195b296d0Smrg# time-stamp-start: "scriptversion="
21295b296d0Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213d87a3195Smrg# time-stamp-time-zone: "UTC0"
21414330f12Smrg# time-stamp-end: "; # UTC"
21595b296d0Smrg# End:
216