16df26cacSmrg#! /bin/sh
225dbecb6Smrg# Common wrapper for a few potentially missing GNU programs.
36df26cacSmrg
425dbecb6Smrgscriptversion=2018-03-07.03; # UTC
56df26cacSmrg
625dbecb6Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
725dbecb6Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
86df26cacSmrg
96df26cacSmrg# This program is free software; you can redistribute it and/or modify
106df26cacSmrg# it under the terms of the GNU General Public License as published by
116df26cacSmrg# the Free Software Foundation; either version 2, or (at your option)
126df26cacSmrg# any later version.
136df26cacSmrg
146df26cacSmrg# This program is distributed in the hope that it will be useful,
156df26cacSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
166df26cacSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
176df26cacSmrg# GNU General Public License for more details.
186df26cacSmrg
196df26cacSmrg# You should have received a copy of the GNU General Public License
2025dbecb6Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
216df26cacSmrg
226df26cacSmrg# As a special exception to the GNU General Public License, if you
236df26cacSmrg# distribute this file as part of a program that contains a
246df26cacSmrg# configuration script generated by Autoconf, you may include it under
256df26cacSmrg# the same distribution terms that you use for the rest of that program.
266df26cacSmrg
276df26cacSmrgif test $# -eq 0; then
2825dbecb6Smrg  echo 1>&2 "Try '$0 --help' for more information"
296df26cacSmrg  exit 1
306df26cacSmrgfi
316df26cacSmrg
3225dbecb6Smrgcase $1 in
336df26cacSmrg
3425dbecb6Smrg  --is-lightweight)
3525dbecb6Smrg    # Used by our autoconf macros to check whether the available missing
3625dbecb6Smrg    # script is modern enough.
3725dbecb6Smrg    exit 0
3825dbecb6Smrg    ;;
396df26cacSmrg
4025dbecb6Smrg  --run)
4125dbecb6Smrg    # Back-compat with the calling convention used by older automake.
4225dbecb6Smrg    shift
4325dbecb6Smrg    ;;
446df26cacSmrg
456df26cacSmrg  -h|--h|--he|--hel|--help)
466df26cacSmrg    echo "\
476df26cacSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
486df26cacSmrg
4925dbecb6SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5025dbecb6Smrgto PROGRAM being missing or too old.
516df26cacSmrg
526df26cacSmrgOptions:
536df26cacSmrg  -h, --help      display this help and exit
546df26cacSmrg  -v, --version   output version information and exit
556df26cacSmrg
566df26cacSmrgSupported PROGRAM values:
5725dbecb6Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5825dbecb6Smrg  bison     yacc      flex         lex       help2man
5925dbecb6Smrg
6025dbecb6SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6125dbecb6Smrg'g' are ignored when checking the name.
626df26cacSmrg
636df26cacSmrgSend bug reports to <bug-automake@gnu.org>."
646df26cacSmrg    exit $?
656df26cacSmrg    ;;
666df26cacSmrg
676df26cacSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
686df26cacSmrg    echo "missing $scriptversion (GNU Automake)"
696df26cacSmrg    exit $?
706df26cacSmrg    ;;
716df26cacSmrg
726df26cacSmrg  -*)
7325dbecb6Smrg    echo 1>&2 "$0: unknown '$1' option"
7425dbecb6Smrg    echo 1>&2 "Try '$0 --help' for more information"
756df26cacSmrg    exit 1
766df26cacSmrg    ;;
776df26cacSmrg
786df26cacSmrgesac
796df26cacSmrg
8025dbecb6Smrg# Run the given program, remember its exit status.
8125dbecb6Smrg"$@"; st=$?
8225dbecb6Smrg
8325dbecb6Smrg# If it succeeded, we are done.
8425dbecb6Smrgtest $st -eq 0 && exit 0
8525dbecb6Smrg
8625dbecb6Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8725dbecb6Smrg# passed; such an option is passed most likely to detect whether the
8825dbecb6Smrg# program is present and works.
8925dbecb6Smrgcase $2 in --version|--help) exit $st;; esac
9025dbecb6Smrg
9125dbecb6Smrg# Exit code 63 means version mismatch.  This often happens when the user
9225dbecb6Smrg# tries to use an ancient version of a tool on a file that requires a
9325dbecb6Smrg# minimum version.
9425dbecb6Smrgif test $st -eq 63; then
9525dbecb6Smrg  msg="probably too old"
9625dbecb6Smrgelif test $st -eq 127; then
9725dbecb6Smrg  # Program was missing.
9825dbecb6Smrg  msg="missing on your system"
9925dbecb6Smrgelse
10025dbecb6Smrg  # Program was found and executed, but failed.  Give up.
10125dbecb6Smrg  exit $st
10225dbecb6Smrgfi
1036df26cacSmrg
10425dbecb6Smrgperl_URL=https://www.perl.org/
10525dbecb6Smrgflex_URL=https://github.com/westes/flex
10625dbecb6Smrggnu_software_URL=https://www.gnu.org/software
10725dbecb6Smrg
10825dbecb6Smrgprogram_details ()
10925dbecb6Smrg{
11025dbecb6Smrg  case $1 in
11125dbecb6Smrg    aclocal|automake)
11225dbecb6Smrg      echo "The '$1' program is part of the GNU Automake package:"
11325dbecb6Smrg      echo "<$gnu_software_URL/automake>"
11425dbecb6Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11525dbecb6Smrg      echo "<$gnu_software_URL/autoconf>"
11625dbecb6Smrg      echo "<$gnu_software_URL/m4/>"
11725dbecb6Smrg      echo "<$perl_URL>"
11825dbecb6Smrg      ;;
11925dbecb6Smrg    autoconf|autom4te|autoheader)
12025dbecb6Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12125dbecb6Smrg      echo "<$gnu_software_URL/autoconf/>"
12225dbecb6Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12325dbecb6Smrg      echo "<$gnu_software_URL/m4/>"
12425dbecb6Smrg      echo "<$perl_URL>"
12525dbecb6Smrg      ;;
12625dbecb6Smrg  esac
12725dbecb6Smrg}
12825dbecb6Smrg
12925dbecb6Smrggive_advice ()
13025dbecb6Smrg{
13125dbecb6Smrg  # Normalize program name to check for.
13225dbecb6Smrg  normalized_program=`echo "$1" | sed '
13325dbecb6Smrg    s/^gnu-//; t
13425dbecb6Smrg    s/^gnu//; t
13525dbecb6Smrg    s/^g//; t'`
13625dbecb6Smrg
13725dbecb6Smrg  printf '%s\n' "'$1' is $msg."
13825dbecb6Smrg
13925dbecb6Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14025dbecb6Smrg  case $normalized_program in
14125dbecb6Smrg    autoconf*)
14225dbecb6Smrg      echo "You should only need it if you modified 'configure.ac',"
14325dbecb6Smrg      echo "or m4 files included by it."
14425dbecb6Smrg      program_details 'autoconf'
14525dbecb6Smrg      ;;
14625dbecb6Smrg    autoheader*)
14725dbecb6Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14825dbecb6Smrg      echo "$configure_deps."
14925dbecb6Smrg      program_details 'autoheader'
15025dbecb6Smrg      ;;
15125dbecb6Smrg    automake*)
15225dbecb6Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15325dbecb6Smrg      echo "$configure_deps."
15425dbecb6Smrg      program_details 'automake'
15525dbecb6Smrg      ;;
15625dbecb6Smrg    aclocal*)
15725dbecb6Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15825dbecb6Smrg      echo "$configure_deps."
15925dbecb6Smrg      program_details 'aclocal'
16025dbecb6Smrg      ;;
16125dbecb6Smrg   autom4te*)
16225dbecb6Smrg      echo "You might have modified some maintainer files that require"
16325dbecb6Smrg      echo "the 'autom4te' program to be rebuilt."
16425dbecb6Smrg      program_details 'autom4te'
16525dbecb6Smrg      ;;
16625dbecb6Smrg    bison*|yacc*)
16725dbecb6Smrg      echo "You should only need it if you modified a '.y' file."
16825dbecb6Smrg      echo "You may want to install the GNU Bison package:"
16925dbecb6Smrg      echo "<$gnu_software_URL/bison/>"
17025dbecb6Smrg      ;;
17125dbecb6Smrg    lex*|flex*)
17225dbecb6Smrg      echo "You should only need it if you modified a '.l' file."
17325dbecb6Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17425dbecb6Smrg      echo "<$flex_URL>"
17525dbecb6Smrg      ;;
17625dbecb6Smrg    help2man*)
17725dbecb6Smrg      echo "You should only need it if you modified a dependency" \
17825dbecb6Smrg           "of a man page."
17925dbecb6Smrg      echo "You may want to install the GNU Help2man package:"
18025dbecb6Smrg      echo "<$gnu_software_URL/help2man/>"
18125dbecb6Smrg    ;;
18225dbecb6Smrg    makeinfo*)
18325dbecb6Smrg      echo "You should only need it if you modified a '.texi' file, or"
18425dbecb6Smrg      echo "any other file indirectly affecting the aspect of the manual."
18525dbecb6Smrg      echo "You might want to install the Texinfo package:"
18625dbecb6Smrg      echo "<$gnu_software_URL/texinfo/>"
18725dbecb6Smrg      echo "The spurious makeinfo call might also be the consequence of"
18825dbecb6Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18925dbecb6Smrg      echo "want to install GNU make:"
19025dbecb6Smrg      echo "<$gnu_software_URL/make/>"
19125dbecb6Smrg      ;;
19225dbecb6Smrg    *)
19325dbecb6Smrg      echo "You might have modified some files without having the proper"
19425dbecb6Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19525dbecb6Smrg      echo "often tells you about the needed prerequisites for installing"
19625dbecb6Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19725dbecb6Smrg      echo "case some other package contains this missing '$1' program."
19825dbecb6Smrg      ;;
19925dbecb6Smrg  esac
20025dbecb6Smrg}
20125dbecb6Smrg
20225dbecb6Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20325dbecb6Smrg                       -e '2,$s/^/         /' >&2
20425dbecb6Smrg
20525dbecb6Smrg# Propagate the correct exit status (expected to be 127 for a program
20625dbecb6Smrg# not found, 63 for a program that failed due to version mismatch).
20725dbecb6Smrgexit $st
2086df26cacSmrg
2096df26cacSmrg# Local variables:
21025dbecb6Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2116df26cacSmrg# time-stamp-start: "scriptversion="
2126df26cacSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21325dbecb6Smrg# time-stamp-time-zone: "UTC0"
21425dbecb6Smrg# time-stamp-end: "; # UTC"
2156df26cacSmrg# End:
216