138b41dabSmrg#! /bin/sh
238b41dabSmrg# Common wrapper for a few potentially missing GNU programs.
338b41dabSmrg
438b41dabSmrgscriptversion=2018-03-07.03; # UTC
538b41dabSmrg
638b41dabSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
738b41dabSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
838b41dabSmrg
938b41dabSmrg# This program is free software; you can redistribute it and/or modify
1038b41dabSmrg# it under the terms of the GNU General Public License as published by
1138b41dabSmrg# the Free Software Foundation; either version 2, or (at your option)
1238b41dabSmrg# any later version.
1338b41dabSmrg
1438b41dabSmrg# This program is distributed in the hope that it will be useful,
1538b41dabSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1638b41dabSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1738b41dabSmrg# GNU General Public License for more details.
1838b41dabSmrg
1938b41dabSmrg# You should have received a copy of the GNU General Public License
2038b41dabSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2138b41dabSmrg
2238b41dabSmrg# As a special exception to the GNU General Public License, if you
2338b41dabSmrg# distribute this file as part of a program that contains a
2438b41dabSmrg# configuration script generated by Autoconf, you may include it under
2538b41dabSmrg# the same distribution terms that you use for the rest of that program.
2638b41dabSmrg
2738b41dabSmrgif test $# -eq 0; then
2838b41dabSmrg  echo 1>&2 "Try '$0 --help' for more information"
2938b41dabSmrg  exit 1
3038b41dabSmrgfi
3138b41dabSmrg
3238b41dabSmrgcase $1 in
3338b41dabSmrg
3438b41dabSmrg  --is-lightweight)
3538b41dabSmrg    # Used by our autoconf macros to check whether the available missing
3638b41dabSmrg    # script is modern enough.
3738b41dabSmrg    exit 0
3838b41dabSmrg    ;;
3938b41dabSmrg
4038b41dabSmrg  --run)
4138b41dabSmrg    # Back-compat with the calling convention used by older automake.
4238b41dabSmrg    shift
4338b41dabSmrg    ;;
4438b41dabSmrg
4538b41dabSmrg  -h|--h|--he|--hel|--help)
4638b41dabSmrg    echo "\
4738b41dabSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4838b41dabSmrg
4938b41dabSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5038b41dabSmrgto PROGRAM being missing or too old.
5138b41dabSmrg
5238b41dabSmrgOptions:
5338b41dabSmrg  -h, --help      display this help and exit
5438b41dabSmrg  -v, --version   output version information and exit
5538b41dabSmrg
5638b41dabSmrgSupported PROGRAM values:
5738b41dabSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5838b41dabSmrg  bison     yacc      flex         lex       help2man
5938b41dabSmrg
6038b41dabSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6138b41dabSmrg'g' are ignored when checking the name.
6238b41dabSmrg
6338b41dabSmrgSend bug reports to <bug-automake@gnu.org>."
6438b41dabSmrg    exit $?
6538b41dabSmrg    ;;
6638b41dabSmrg
6738b41dabSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6838b41dabSmrg    echo "missing $scriptversion (GNU Automake)"
6938b41dabSmrg    exit $?
7038b41dabSmrg    ;;
7138b41dabSmrg
7238b41dabSmrg  -*)
7338b41dabSmrg    echo 1>&2 "$0: unknown '$1' option"
7438b41dabSmrg    echo 1>&2 "Try '$0 --help' for more information"
7538b41dabSmrg    exit 1
7638b41dabSmrg    ;;
7738b41dabSmrg
7838b41dabSmrgesac
7938b41dabSmrg
8038b41dabSmrg# Run the given program, remember its exit status.
8138b41dabSmrg"$@"; st=$?
8238b41dabSmrg
8338b41dabSmrg# If it succeeded, we are done.
8438b41dabSmrgtest $st -eq 0 && exit 0
8538b41dabSmrg
8638b41dabSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
8738b41dabSmrg# passed; such an option is passed most likely to detect whether the
8838b41dabSmrg# program is present and works.
8938b41dabSmrgcase $2 in --version|--help) exit $st;; esac
9038b41dabSmrg
9138b41dabSmrg# Exit code 63 means version mismatch.  This often happens when the user
9238b41dabSmrg# tries to use an ancient version of a tool on a file that requires a
9338b41dabSmrg# minimum version.
9438b41dabSmrgif test $st -eq 63; then
9538b41dabSmrg  msg="probably too old"
9638b41dabSmrgelif test $st -eq 127; then
9738b41dabSmrg  # Program was missing.
9838b41dabSmrg  msg="missing on your system"
9938b41dabSmrgelse
10038b41dabSmrg  # Program was found and executed, but failed.  Give up.
10138b41dabSmrg  exit $st
10238b41dabSmrgfi
10338b41dabSmrg
10438b41dabSmrgperl_URL=https://www.perl.org/
10538b41dabSmrgflex_URL=https://github.com/westes/flex
10638b41dabSmrggnu_software_URL=https://www.gnu.org/software
10738b41dabSmrg
10838b41dabSmrgprogram_details ()
10938b41dabSmrg{
11038b41dabSmrg  case $1 in
11138b41dabSmrg    aclocal|automake)
11238b41dabSmrg      echo "The '$1' program is part of the GNU Automake package:"
11338b41dabSmrg      echo "<$gnu_software_URL/automake>"
11438b41dabSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11538b41dabSmrg      echo "<$gnu_software_URL/autoconf>"
11638b41dabSmrg      echo "<$gnu_software_URL/m4/>"
11738b41dabSmrg      echo "<$perl_URL>"
11838b41dabSmrg      ;;
11938b41dabSmrg    autoconf|autom4te|autoheader)
12038b41dabSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
12138b41dabSmrg      echo "<$gnu_software_URL/autoconf/>"
12238b41dabSmrg      echo "It also requires GNU m4 and Perl in order to run:"
12338b41dabSmrg      echo "<$gnu_software_URL/m4/>"
12438b41dabSmrg      echo "<$perl_URL>"
12538b41dabSmrg      ;;
12638b41dabSmrg  esac
12738b41dabSmrg}
12838b41dabSmrg
12938b41dabSmrggive_advice ()
13038b41dabSmrg{
13138b41dabSmrg  # Normalize program name to check for.
13238b41dabSmrg  normalized_program=`echo "$1" | sed '
13338b41dabSmrg    s/^gnu-//; t
13438b41dabSmrg    s/^gnu//; t
13538b41dabSmrg    s/^g//; t'`
13638b41dabSmrg
13738b41dabSmrg  printf '%s\n' "'$1' is $msg."
13838b41dabSmrg
13938b41dabSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14038b41dabSmrg  case $normalized_program in
14138b41dabSmrg    autoconf*)
14238b41dabSmrg      echo "You should only need it if you modified 'configure.ac',"
14338b41dabSmrg      echo "or m4 files included by it."
14438b41dabSmrg      program_details 'autoconf'
14538b41dabSmrg      ;;
14638b41dabSmrg    autoheader*)
14738b41dabSmrg      echo "You should only need it if you modified 'acconfig.h' or"
14838b41dabSmrg      echo "$configure_deps."
14938b41dabSmrg      program_details 'autoheader'
15038b41dabSmrg      ;;
15138b41dabSmrg    automake*)
15238b41dabSmrg      echo "You should only need it if you modified 'Makefile.am' or"
15338b41dabSmrg      echo "$configure_deps."
15438b41dabSmrg      program_details 'automake'
15538b41dabSmrg      ;;
15638b41dabSmrg    aclocal*)
15738b41dabSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
15838b41dabSmrg      echo "$configure_deps."
15938b41dabSmrg      program_details 'aclocal'
16038b41dabSmrg      ;;
16138b41dabSmrg   autom4te*)
16238b41dabSmrg      echo "You might have modified some maintainer files that require"
16338b41dabSmrg      echo "the 'autom4te' program to be rebuilt."
16438b41dabSmrg      program_details 'autom4te'
16538b41dabSmrg      ;;
16638b41dabSmrg    bison*|yacc*)
16738b41dabSmrg      echo "You should only need it if you modified a '.y' file."
16838b41dabSmrg      echo "You may want to install the GNU Bison package:"
16938b41dabSmrg      echo "<$gnu_software_URL/bison/>"
17038b41dabSmrg      ;;
17138b41dabSmrg    lex*|flex*)
17238b41dabSmrg      echo "You should only need it if you modified a '.l' file."
17338b41dabSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
17438b41dabSmrg      echo "<$flex_URL>"
17538b41dabSmrg      ;;
17638b41dabSmrg    help2man*)
17738b41dabSmrg      echo "You should only need it if you modified a dependency" \
17838b41dabSmrg           "of a man page."
17938b41dabSmrg      echo "You may want to install the GNU Help2man package:"
18038b41dabSmrg      echo "<$gnu_software_URL/help2man/>"
18138b41dabSmrg    ;;
18238b41dabSmrg    makeinfo*)
18338b41dabSmrg      echo "You should only need it if you modified a '.texi' file, or"
18438b41dabSmrg      echo "any other file indirectly affecting the aspect of the manual."
18538b41dabSmrg      echo "You might want to install the Texinfo package:"
18638b41dabSmrg      echo "<$gnu_software_URL/texinfo/>"
18738b41dabSmrg      echo "The spurious makeinfo call might also be the consequence of"
18838b41dabSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18938b41dabSmrg      echo "want to install GNU make:"
19038b41dabSmrg      echo "<$gnu_software_URL/make/>"
19138b41dabSmrg      ;;
19238b41dabSmrg    *)
19338b41dabSmrg      echo "You might have modified some files without having the proper"
19438b41dabSmrg      echo "tools for further handling them.  Check the 'README' file, it"
19538b41dabSmrg      echo "often tells you about the needed prerequisites for installing"
19638b41dabSmrg      echo "this package.  You may also peek at any GNU archive site, in"
19738b41dabSmrg      echo "case some other package contains this missing '$1' program."
19838b41dabSmrg      ;;
19938b41dabSmrg  esac
20038b41dabSmrg}
20138b41dabSmrg
20238b41dabSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20338b41dabSmrg                       -e '2,$s/^/         /' >&2
20438b41dabSmrg
20538b41dabSmrg# Propagate the correct exit status (expected to be 127 for a program
20638b41dabSmrg# not found, 63 for a program that failed due to version mismatch).
20738b41dabSmrgexit $st
20838b41dabSmrg
20938b41dabSmrg# Local variables:
21038b41dabSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
21138b41dabSmrg# time-stamp-start: "scriptversion="
21238b41dabSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21338b41dabSmrg# time-stamp-time-zone: "UTC0"
21438b41dabSmrg# time-stamp-end: "; # UTC"
21538b41dabSmrg# End:
216