1a0195d5fSmrg#! /bin/sh
240a76396Smrg# Common wrapper for a few potentially missing GNU programs.
3a0195d5fSmrg
40f5b81e5Smrgscriptversion=2018-03-07.03; # UTC
5a0195d5fSmrg
60f5b81e5Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
740a76396Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8a0195d5fSmrg
9a0195d5fSmrg# This program is free software; you can redistribute it and/or modify
10a0195d5fSmrg# it under the terms of the GNU General Public License as published by
11a0195d5fSmrg# the Free Software Foundation; either version 2, or (at your option)
12a0195d5fSmrg# any later version.
13a0195d5fSmrg
14a0195d5fSmrg# This program is distributed in the hope that it will be useful,
15a0195d5fSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16a0195d5fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a0195d5fSmrg# GNU General Public License for more details.
18a0195d5fSmrg
19a0195d5fSmrg# You should have received a copy of the GNU General Public License
200f5b81e5Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21a0195d5fSmrg
22a0195d5fSmrg# As a special exception to the GNU General Public License, if you
23a0195d5fSmrg# distribute this file as part of a program that contains a
24a0195d5fSmrg# configuration script generated by Autoconf, you may include it under
25a0195d5fSmrg# the same distribution terms that you use for the rest of that program.
26a0195d5fSmrg
27a0195d5fSmrgif test $# -eq 0; then
2840a76396Smrg  echo 1>&2 "Try '$0 --help' for more information"
29a0195d5fSmrg  exit 1
30a0195d5fSmrgfi
31a0195d5fSmrg
3240a76396Smrgcase $1 in
33a0195d5fSmrg
3440a76396Smrg  --is-lightweight)
3540a76396Smrg    # Used by our autoconf macros to check whether the available missing
3640a76396Smrg    # script is modern enough.
3740a76396Smrg    exit 0
3840a76396Smrg    ;;
39a0195d5fSmrg
4040a76396Smrg  --run)
4140a76396Smrg    # Back-compat with the calling convention used by older automake.
4240a76396Smrg    shift
4340a76396Smrg    ;;
44a0195d5fSmrg
45a0195d5fSmrg  -h|--h|--he|--hel|--help)
46a0195d5fSmrg    echo "\
47a0195d5fSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48a0195d5fSmrg
4940a76396SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5040a76396Smrgto PROGRAM being missing or too old.
51a0195d5fSmrg
52a0195d5fSmrgOptions:
53a0195d5fSmrg  -h, --help      display this help and exit
54a0195d5fSmrg  -v, --version   output version information and exit
55a0195d5fSmrg
56a0195d5fSmrgSupported PROGRAM values:
5740a76396Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5840a76396Smrg  bison     yacc      flex         lex       help2man
59a0195d5fSmrg
6040a76396SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6140a76396Smrg'g' are ignored when checking the name.
626600fe5bSmrg
63a0195d5fSmrgSend bug reports to <bug-automake@gnu.org>."
64a0195d5fSmrg    exit $?
65a0195d5fSmrg    ;;
66a0195d5fSmrg
67a0195d5fSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68a0195d5fSmrg    echo "missing $scriptversion (GNU Automake)"
69a0195d5fSmrg    exit $?
70a0195d5fSmrg    ;;
71a0195d5fSmrg
72a0195d5fSmrg  -*)
7340a76396Smrg    echo 1>&2 "$0: unknown '$1' option"
7440a76396Smrg    echo 1>&2 "Try '$0 --help' for more information"
75a0195d5fSmrg    exit 1
76a0195d5fSmrg    ;;
77a0195d5fSmrg
78a0195d5fSmrgesac
79a0195d5fSmrg
8040a76396Smrg# Run the given program, remember its exit status.
8140a76396Smrg"$@"; st=$?
8240a76396Smrg
8340a76396Smrg# If it succeeded, we are done.
8440a76396Smrgtest $st -eq 0 && exit 0
8540a76396Smrg
8640a76396Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8740a76396Smrg# passed; such an option is passed most likely to detect whether the
8840a76396Smrg# program is present and works.
8940a76396Smrgcase $2 in --version|--help) exit $st;; esac
9040a76396Smrg
9140a76396Smrg# Exit code 63 means version mismatch.  This often happens when the user
9240a76396Smrg# tries to use an ancient version of a tool on a file that requires a
9340a76396Smrg# minimum version.
9440a76396Smrgif test $st -eq 63; then
9540a76396Smrg  msg="probably too old"
9640a76396Smrgelif test $st -eq 127; then
9740a76396Smrg  # Program was missing.
9840a76396Smrg  msg="missing on your system"
9940a76396Smrgelse
10040a76396Smrg  # Program was found and executed, but failed.  Give up.
10140a76396Smrg  exit $st
10240a76396Smrgfi
103a0195d5fSmrg
1040f5b81e5Smrgperl_URL=https://www.perl.org/
1050f5b81e5Smrgflex_URL=https://github.com/westes/flex
1060f5b81e5Smrggnu_software_URL=https://www.gnu.org/software
10740a76396Smrg
10840a76396Smrgprogram_details ()
10940a76396Smrg{
11040a76396Smrg  case $1 in
11140a76396Smrg    aclocal|automake)
11240a76396Smrg      echo "The '$1' program is part of the GNU Automake package:"
11340a76396Smrg      echo "<$gnu_software_URL/automake>"
11440a76396Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11540a76396Smrg      echo "<$gnu_software_URL/autoconf>"
11640a76396Smrg      echo "<$gnu_software_URL/m4/>"
11740a76396Smrg      echo "<$perl_URL>"
11840a76396Smrg      ;;
11940a76396Smrg    autoconf|autom4te|autoheader)
12040a76396Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12140a76396Smrg      echo "<$gnu_software_URL/autoconf/>"
12240a76396Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12340a76396Smrg      echo "<$gnu_software_URL/m4/>"
12440a76396Smrg      echo "<$perl_URL>"
12540a76396Smrg      ;;
12640a76396Smrg  esac
12740a76396Smrg}
12840a76396Smrg
12940a76396Smrggive_advice ()
13040a76396Smrg{
13140a76396Smrg  # Normalize program name to check for.
13240a76396Smrg  normalized_program=`echo "$1" | sed '
13340a76396Smrg    s/^gnu-//; t
13440a76396Smrg    s/^gnu//; t
13540a76396Smrg    s/^g//; t'`
13640a76396Smrg
13740a76396Smrg  printf '%s\n' "'$1' is $msg."
13840a76396Smrg
13940a76396Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14040a76396Smrg  case $normalized_program in
14140a76396Smrg    autoconf*)
14240a76396Smrg      echo "You should only need it if you modified 'configure.ac',"
14340a76396Smrg      echo "or m4 files included by it."
14440a76396Smrg      program_details 'autoconf'
14540a76396Smrg      ;;
14640a76396Smrg    autoheader*)
14740a76396Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14840a76396Smrg      echo "$configure_deps."
14940a76396Smrg      program_details 'autoheader'
15040a76396Smrg      ;;
15140a76396Smrg    automake*)
15240a76396Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15340a76396Smrg      echo "$configure_deps."
15440a76396Smrg      program_details 'automake'
15540a76396Smrg      ;;
15640a76396Smrg    aclocal*)
15740a76396Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15840a76396Smrg      echo "$configure_deps."
15940a76396Smrg      program_details 'aclocal'
16040a76396Smrg      ;;
16140a76396Smrg   autom4te*)
16240a76396Smrg      echo "You might have modified some maintainer files that require"
163feee4651Smrg      echo "the 'autom4te' program to be rebuilt."
16440a76396Smrg      program_details 'autom4te'
16540a76396Smrg      ;;
16640a76396Smrg    bison*|yacc*)
16740a76396Smrg      echo "You should only need it if you modified a '.y' file."
16840a76396Smrg      echo "You may want to install the GNU Bison package:"
16940a76396Smrg      echo "<$gnu_software_URL/bison/>"
17040a76396Smrg      ;;
17140a76396Smrg    lex*|flex*)
17240a76396Smrg      echo "You should only need it if you modified a '.l' file."
17340a76396Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17440a76396Smrg      echo "<$flex_URL>"
17540a76396Smrg      ;;
17640a76396Smrg    help2man*)
17740a76396Smrg      echo "You should only need it if you modified a dependency" \
17840a76396Smrg           "of a man page."
17940a76396Smrg      echo "You may want to install the GNU Help2man package:"
18040a76396Smrg      echo "<$gnu_software_URL/help2man/>"
18140a76396Smrg    ;;
18240a76396Smrg    makeinfo*)
18340a76396Smrg      echo "You should only need it if you modified a '.texi' file, or"
18440a76396Smrg      echo "any other file indirectly affecting the aspect of the manual."
18540a76396Smrg      echo "You might want to install the Texinfo package:"
18640a76396Smrg      echo "<$gnu_software_URL/texinfo/>"
18740a76396Smrg      echo "The spurious makeinfo call might also be the consequence of"
18840a76396Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18940a76396Smrg      echo "want to install GNU make:"
19040a76396Smrg      echo "<$gnu_software_URL/make/>"
19140a76396Smrg      ;;
19240a76396Smrg    *)
19340a76396Smrg      echo "You might have modified some files without having the proper"
19440a76396Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19540a76396Smrg      echo "often tells you about the needed prerequisites for installing"
19640a76396Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19740a76396Smrg      echo "case some other package contains this missing '$1' program."
19840a76396Smrg      ;;
19940a76396Smrg  esac
20040a76396Smrg}
20140a76396Smrg
20240a76396Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20340a76396Smrg                       -e '2,$s/^/         /' >&2
20440a76396Smrg
20540a76396Smrg# Propagate the correct exit status (expected to be 127 for a program
20640a76396Smrg# not found, 63 for a program that failed due to version mismatch).
20740a76396Smrgexit $st
208a0195d5fSmrg
209a0195d5fSmrg# Local variables:
2100f5b81e5Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
211a0195d5fSmrg# time-stamp-start: "scriptversion="
212a0195d5fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2130f5b81e5Smrg# time-stamp-time-zone: "UTC0"
2146600fe5bSmrg# time-stamp-end: "; # UTC"
215a0195d5fSmrg# End:
216