18440cca4Smrg#! /bin/sh
204449c54Smrg# Common wrapper for a few potentially missing GNU programs.
3d1c293acSmrg
494c9ab7bSmrgscriptversion=2018-03-07.03; # UTC
5d1c293acSmrg
694c9ab7bSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
704449c54Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
88440cca4Smrg
98440cca4Smrg# This program is free software; you can redistribute it and/or modify
108440cca4Smrg# it under the terms of the GNU General Public License as published by
118440cca4Smrg# the Free Software Foundation; either version 2, or (at your option)
128440cca4Smrg# any later version.
138440cca4Smrg
148440cca4Smrg# This program is distributed in the hope that it will be useful,
158440cca4Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
168440cca4Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
178440cca4Smrg# GNU General Public License for more details.
188440cca4Smrg
198440cca4Smrg# You should have received a copy of the GNU General Public License
2094c9ab7bSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
218440cca4Smrg
228440cca4Smrg# As a special exception to the GNU General Public License, if you
238440cca4Smrg# distribute this file as part of a program that contains a
248440cca4Smrg# configuration script generated by Autoconf, you may include it under
258440cca4Smrg# the same distribution terms that you use for the rest of that program.
268440cca4Smrg
278440cca4Smrgif test $# -eq 0; then
2804449c54Smrg  echo 1>&2 "Try '$0 --help' for more information"
298440cca4Smrg  exit 1
308440cca4Smrgfi
318440cca4Smrg
3204449c54Smrgcase $1 in
338440cca4Smrg
3404449c54Smrg  --is-lightweight)
3504449c54Smrg    # Used by our autoconf macros to check whether the available missing
3604449c54Smrg    # script is modern enough.
3704449c54Smrg    exit 0
3804449c54Smrg    ;;
39d1c293acSmrg
4004449c54Smrg  --run)
4104449c54Smrg    # Back-compat with the calling convention used by older automake.
4204449c54Smrg    shift
4304449c54Smrg    ;;
448440cca4Smrg
458440cca4Smrg  -h|--h|--he|--hel|--help)
468440cca4Smrg    echo "\
478440cca4Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
488440cca4Smrg
4904449c54SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5004449c54Smrgto PROGRAM being missing or too old.
518440cca4Smrg
528440cca4SmrgOptions:
538440cca4Smrg  -h, --help      display this help and exit
548440cca4Smrg  -v, --version   output version information and exit
558440cca4Smrg
568440cca4SmrgSupported PROGRAM values:
5704449c54Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5804449c54Smrg  bison     yacc      flex         lex       help2man
59d1c293acSmrg
6004449c54SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6104449c54Smrg'g' are ignored when checking the name.
62d1c293acSmrg
63d1c293acSmrgSend bug reports to <bug-automake@gnu.org>."
64d1c293acSmrg    exit $?
658440cca4Smrg    ;;
668440cca4Smrg
678440cca4Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68d1c293acSmrg    echo "missing $scriptversion (GNU Automake)"
69d1c293acSmrg    exit $?
708440cca4Smrg    ;;
718440cca4Smrg
728440cca4Smrg  -*)
7304449c54Smrg    echo 1>&2 "$0: unknown '$1' option"
7404449c54Smrg    echo 1>&2 "Try '$0 --help' for more information"
758440cca4Smrg    exit 1
768440cca4Smrg    ;;
778440cca4Smrg
78d1c293acSmrgesac
79d1c293acSmrg
8004449c54Smrg# Run the given program, remember its exit status.
8104449c54Smrg"$@"; st=$?
8204449c54Smrg
8304449c54Smrg# If it succeeded, we are done.
8404449c54Smrgtest $st -eq 0 && exit 0
8504449c54Smrg
8604449c54Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8704449c54Smrg# passed; such an option is passed most likely to detect whether the
8804449c54Smrg# program is present and works.
8904449c54Smrgcase $2 in --version|--help) exit $st;; esac
9004449c54Smrg
9104449c54Smrg# Exit code 63 means version mismatch.  This often happens when the user
9204449c54Smrg# tries to use an ancient version of a tool on a file that requires a
9304449c54Smrg# minimum version.
9404449c54Smrgif test $st -eq 63; then
9504449c54Smrg  msg="probably too old"
9604449c54Smrgelif test $st -eq 127; then
9704449c54Smrg  # Program was missing.
9804449c54Smrg  msg="missing on your system"
9904449c54Smrgelse
10004449c54Smrg  # Program was found and executed, but failed.  Give up.
10104449c54Smrg  exit $st
10204449c54Smrgfi
1038440cca4Smrg
10494c9ab7bSmrgperl_URL=https://www.perl.org/
10594c9ab7bSmrgflex_URL=https://github.com/westes/flex
10694c9ab7bSmrggnu_software_URL=https://www.gnu.org/software
10704449c54Smrg
10804449c54Smrgprogram_details ()
10904449c54Smrg{
11004449c54Smrg  case $1 in
11104449c54Smrg    aclocal|automake)
11204449c54Smrg      echo "The '$1' program is part of the GNU Automake package:"
11304449c54Smrg      echo "<$gnu_software_URL/automake>"
11404449c54Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11504449c54Smrg      echo "<$gnu_software_URL/autoconf>"
11604449c54Smrg      echo "<$gnu_software_URL/m4/>"
11704449c54Smrg      echo "<$perl_URL>"
11804449c54Smrg      ;;
11904449c54Smrg    autoconf|autom4te|autoheader)
12004449c54Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12104449c54Smrg      echo "<$gnu_software_URL/autoconf/>"
12204449c54Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12304449c54Smrg      echo "<$gnu_software_URL/m4/>"
12404449c54Smrg      echo "<$perl_URL>"
12504449c54Smrg      ;;
12604449c54Smrg  esac
12704449c54Smrg}
12804449c54Smrg
12904449c54Smrggive_advice ()
13004449c54Smrg{
13104449c54Smrg  # Normalize program name to check for.
13204449c54Smrg  normalized_program=`echo "$1" | sed '
13304449c54Smrg    s/^gnu-//; t
13404449c54Smrg    s/^gnu//; t
13504449c54Smrg    s/^g//; t'`
13604449c54Smrg
13704449c54Smrg  printf '%s\n' "'$1' is $msg."
13804449c54Smrg
13904449c54Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14004449c54Smrg  case $normalized_program in
14104449c54Smrg    autoconf*)
14204449c54Smrg      echo "You should only need it if you modified 'configure.ac',"
14304449c54Smrg      echo "or m4 files included by it."
14404449c54Smrg      program_details 'autoconf'
14504449c54Smrg      ;;
14604449c54Smrg    autoheader*)
14704449c54Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14804449c54Smrg      echo "$configure_deps."
14904449c54Smrg      program_details 'autoheader'
15004449c54Smrg      ;;
15104449c54Smrg    automake*)
15204449c54Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15304449c54Smrg      echo "$configure_deps."
15404449c54Smrg      program_details 'automake'
15504449c54Smrg      ;;
15604449c54Smrg    aclocal*)
15704449c54Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15804449c54Smrg      echo "$configure_deps."
15904449c54Smrg      program_details 'aclocal'
16004449c54Smrg      ;;
16104449c54Smrg   autom4te*)
16204449c54Smrg      echo "You might have modified some maintainer files that require"
16304449c54Smrg      echo "the 'autom4te' program to be rebuilt."
16404449c54Smrg      program_details 'autom4te'
16504449c54Smrg      ;;
16604449c54Smrg    bison*|yacc*)
16704449c54Smrg      echo "You should only need it if you modified a '.y' file."
16804449c54Smrg      echo "You may want to install the GNU Bison package:"
16904449c54Smrg      echo "<$gnu_software_URL/bison/>"
17004449c54Smrg      ;;
17104449c54Smrg    lex*|flex*)
17204449c54Smrg      echo "You should only need it if you modified a '.l' file."
17304449c54Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17404449c54Smrg      echo "<$flex_URL>"
17504449c54Smrg      ;;
17604449c54Smrg    help2man*)
17704449c54Smrg      echo "You should only need it if you modified a dependency" \
17804449c54Smrg           "of a man page."
17904449c54Smrg      echo "You may want to install the GNU Help2man package:"
18004449c54Smrg      echo "<$gnu_software_URL/help2man/>"
18104449c54Smrg    ;;
18204449c54Smrg    makeinfo*)
18304449c54Smrg      echo "You should only need it if you modified a '.texi' file, or"
18404449c54Smrg      echo "any other file indirectly affecting the aspect of the manual."
18504449c54Smrg      echo "You might want to install the Texinfo package:"
18604449c54Smrg      echo "<$gnu_software_URL/texinfo/>"
18704449c54Smrg      echo "The spurious makeinfo call might also be the consequence of"
18804449c54Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18904449c54Smrg      echo "want to install GNU make:"
19004449c54Smrg      echo "<$gnu_software_URL/make/>"
19104449c54Smrg      ;;
19204449c54Smrg    *)
19304449c54Smrg      echo "You might have modified some files without having the proper"
19404449c54Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19504449c54Smrg      echo "often tells you about the needed prerequisites for installing"
19604449c54Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19704449c54Smrg      echo "case some other package contains this missing '$1' program."
19804449c54Smrg      ;;
19904449c54Smrg  esac
20004449c54Smrg}
20104449c54Smrg
20204449c54Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20304449c54Smrg                       -e '2,$s/^/         /' >&2
20404449c54Smrg
20504449c54Smrg# Propagate the correct exit status (expected to be 127 for a program
20604449c54Smrg# not found, 63 for a program that failed due to version mismatch).
20704449c54Smrgexit $st
208d1c293acSmrg
209d1c293acSmrg# Local variables:
21094c9ab7bSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
211d1c293acSmrg# time-stamp-start: "scriptversion="
212d1c293acSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21394c9ab7bSmrg# time-stamp-time-zone: "UTC0"
214d1c293acSmrg# time-stamp-end: "; # UTC"
215d1c293acSmrg# End:
216