1943345d3Smrg#! /bin/sh
215ffece8Smrg# Common wrapper for a few potentially missing GNU programs.
3943345d3Smrg
415ffece8Smrgscriptversion=2018-03-07.03; # UTC
5943345d3Smrg
615ffece8Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
715ffece8Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8943345d3Smrg
9943345d3Smrg# This program is free software; you can redistribute it and/or modify
10943345d3Smrg# it under the terms of the GNU General Public License as published by
11943345d3Smrg# the Free Software Foundation; either version 2, or (at your option)
12943345d3Smrg# any later version.
13943345d3Smrg
14943345d3Smrg# This program is distributed in the hope that it will be useful,
15943345d3Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16943345d3Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17943345d3Smrg# GNU General Public License for more details.
18943345d3Smrg
19943345d3Smrg# You should have received a copy of the GNU General Public License
2015ffece8Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21943345d3Smrg
22943345d3Smrg# As a special exception to the GNU General Public License, if you
23943345d3Smrg# distribute this file as part of a program that contains a
24943345d3Smrg# configuration script generated by Autoconf, you may include it under
25943345d3Smrg# the same distribution terms that you use for the rest of that program.
26943345d3Smrg
27943345d3Smrgif test $# -eq 0; then
2815ffece8Smrg  echo 1>&2 "Try '$0 --help' for more information"
29943345d3Smrg  exit 1
30943345d3Smrgfi
31943345d3Smrg
3215ffece8Smrgcase $1 in
33943345d3Smrg
3415ffece8Smrg  --is-lightweight)
3515ffece8Smrg    # Used by our autoconf macros to check whether the available missing
3615ffece8Smrg    # script is modern enough.
3715ffece8Smrg    exit 0
3815ffece8Smrg    ;;
39943345d3Smrg
4015ffece8Smrg  --run)
4115ffece8Smrg    # Back-compat with the calling convention used by older automake.
4215ffece8Smrg    shift
4315ffece8Smrg    ;;
44943345d3Smrg
45943345d3Smrg  -h|--h|--he|--hel|--help)
46943345d3Smrg    echo "\
47943345d3Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48943345d3Smrg
4915ffece8SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5015ffece8Smrgto PROGRAM being missing or too old.
51943345d3Smrg
52943345d3SmrgOptions:
53943345d3Smrg  -h, --help      display this help and exit
54943345d3Smrg  -v, --version   output version information and exit
55943345d3Smrg
56943345d3SmrgSupported PROGRAM values:
5715ffece8Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5815ffece8Smrg  bison     yacc      flex         lex       help2man
59943345d3Smrg
6015ffece8SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6115ffece8Smrg'g' are ignored when checking the name.
625e695a52Smrg
63943345d3SmrgSend bug reports to <bug-automake@gnu.org>."
64943345d3Smrg    exit $?
65943345d3Smrg    ;;
66943345d3Smrg
67943345d3Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68943345d3Smrg    echo "missing $scriptversion (GNU Automake)"
69943345d3Smrg    exit $?
70943345d3Smrg    ;;
71943345d3Smrg
72943345d3Smrg  -*)
7315ffece8Smrg    echo 1>&2 "$0: unknown '$1' option"
7415ffece8Smrg    echo 1>&2 "Try '$0 --help' for more information"
75943345d3Smrg    exit 1
76943345d3Smrg    ;;
77943345d3Smrg
78943345d3Smrgesac
79943345d3Smrg
8015ffece8Smrg# Run the given program, remember its exit status.
8115ffece8Smrg"$@"; st=$?
8215ffece8Smrg
8315ffece8Smrg# If it succeeded, we are done.
8415ffece8Smrgtest $st -eq 0 && exit 0
8515ffece8Smrg
8615ffece8Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8715ffece8Smrg# passed; such an option is passed most likely to detect whether the
8815ffece8Smrg# program is present and works.
8915ffece8Smrgcase $2 in --version|--help) exit $st;; esac
9015ffece8Smrg
9115ffece8Smrg# Exit code 63 means version mismatch.  This often happens when the user
9215ffece8Smrg# tries to use an ancient version of a tool on a file that requires a
9315ffece8Smrg# minimum version.
9415ffece8Smrgif test $st -eq 63; then
9515ffece8Smrg  msg="probably too old"
9615ffece8Smrgelif test $st -eq 127; then
9715ffece8Smrg  # Program was missing.
9815ffece8Smrg  msg="missing on your system"
9915ffece8Smrgelse
10015ffece8Smrg  # Program was found and executed, but failed.  Give up.
10115ffece8Smrg  exit $st
10215ffece8Smrgfi
103943345d3Smrg
10415ffece8Smrgperl_URL=https://www.perl.org/
10515ffece8Smrgflex_URL=https://github.com/westes/flex
10615ffece8Smrggnu_software_URL=https://www.gnu.org/software
10715ffece8Smrg
10815ffece8Smrgprogram_details ()
10915ffece8Smrg{
11015ffece8Smrg  case $1 in
11115ffece8Smrg    aclocal|automake)
11215ffece8Smrg      echo "The '$1' program is part of the GNU Automake package:"
11315ffece8Smrg      echo "<$gnu_software_URL/automake>"
11415ffece8Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11515ffece8Smrg      echo "<$gnu_software_URL/autoconf>"
11615ffece8Smrg      echo "<$gnu_software_URL/m4/>"
11715ffece8Smrg      echo "<$perl_URL>"
11815ffece8Smrg      ;;
11915ffece8Smrg    autoconf|autom4te|autoheader)
12015ffece8Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12115ffece8Smrg      echo "<$gnu_software_URL/autoconf/>"
12215ffece8Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12315ffece8Smrg      echo "<$gnu_software_URL/m4/>"
12415ffece8Smrg      echo "<$perl_URL>"
12515ffece8Smrg      ;;
12615ffece8Smrg  esac
12715ffece8Smrg}
12815ffece8Smrg
12915ffece8Smrggive_advice ()
13015ffece8Smrg{
13115ffece8Smrg  # Normalize program name to check for.
13215ffece8Smrg  normalized_program=`echo "$1" | sed '
13315ffece8Smrg    s/^gnu-//; t
13415ffece8Smrg    s/^gnu//; t
13515ffece8Smrg    s/^g//; t'`
13615ffece8Smrg
13715ffece8Smrg  printf '%s\n' "'$1' is $msg."
13815ffece8Smrg
13915ffece8Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14015ffece8Smrg  case $normalized_program in
14115ffece8Smrg    autoconf*)
14215ffece8Smrg      echo "You should only need it if you modified 'configure.ac',"
14315ffece8Smrg      echo "or m4 files included by it."
14415ffece8Smrg      program_details 'autoconf'
14515ffece8Smrg      ;;
14615ffece8Smrg    autoheader*)
14715ffece8Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14815ffece8Smrg      echo "$configure_deps."
14915ffece8Smrg      program_details 'autoheader'
15015ffece8Smrg      ;;
15115ffece8Smrg    automake*)
15215ffece8Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15315ffece8Smrg      echo "$configure_deps."
15415ffece8Smrg      program_details 'automake'
15515ffece8Smrg      ;;
15615ffece8Smrg    aclocal*)
15715ffece8Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15815ffece8Smrg      echo "$configure_deps."
15915ffece8Smrg      program_details 'aclocal'
16015ffece8Smrg      ;;
16115ffece8Smrg   autom4te*)
16215ffece8Smrg      echo "You might have modified some maintainer files that require"
16315ffece8Smrg      echo "the 'autom4te' program to be rebuilt."
16415ffece8Smrg      program_details 'autom4te'
16515ffece8Smrg      ;;
16615ffece8Smrg    bison*|yacc*)
16715ffece8Smrg      echo "You should only need it if you modified a '.y' file."
16815ffece8Smrg      echo "You may want to install the GNU Bison package:"
16915ffece8Smrg      echo "<$gnu_software_URL/bison/>"
17015ffece8Smrg      ;;
17115ffece8Smrg    lex*|flex*)
17215ffece8Smrg      echo "You should only need it if you modified a '.l' file."
17315ffece8Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17415ffece8Smrg      echo "<$flex_URL>"
17515ffece8Smrg      ;;
17615ffece8Smrg    help2man*)
17715ffece8Smrg      echo "You should only need it if you modified a dependency" \
17815ffece8Smrg           "of a man page."
17915ffece8Smrg      echo "You may want to install the GNU Help2man package:"
18015ffece8Smrg      echo "<$gnu_software_URL/help2man/>"
181943345d3Smrg    ;;
18215ffece8Smrg    makeinfo*)
18315ffece8Smrg      echo "You should only need it if you modified a '.texi' file, or"
18415ffece8Smrg      echo "any other file indirectly affecting the aspect of the manual."
18515ffece8Smrg      echo "You might want to install the Texinfo package:"
18615ffece8Smrg      echo "<$gnu_software_URL/texinfo/>"
18715ffece8Smrg      echo "The spurious makeinfo call might also be the consequence of"
18815ffece8Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18915ffece8Smrg      echo "want to install GNU make:"
19015ffece8Smrg      echo "<$gnu_software_URL/make/>"
19115ffece8Smrg      ;;
19215ffece8Smrg    *)
19315ffece8Smrg      echo "You might have modified some files without having the proper"
19415ffece8Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19515ffece8Smrg      echo "often tells you about the needed prerequisites for installing"
19615ffece8Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19715ffece8Smrg      echo "case some other package contains this missing '$1' program."
19815ffece8Smrg      ;;
19915ffece8Smrg  esac
20015ffece8Smrg}
20115ffece8Smrg
20215ffece8Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20315ffece8Smrg                       -e '2,$s/^/         /' >&2
20415ffece8Smrg
20515ffece8Smrg# Propagate the correct exit status (expected to be 127 for a program
20615ffece8Smrg# not found, 63 for a program that failed due to version mismatch).
20715ffece8Smrgexit $st
208943345d3Smrg
209943345d3Smrg# Local variables:
21015ffece8Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
211943345d3Smrg# time-stamp-start: "scriptversion="
212943345d3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21315ffece8Smrg# time-stamp-time-zone: "UTC0"
2145e695a52Smrg# time-stamp-end: "; # UTC"
215943345d3Smrg# End:
216