1f299d47fSmrg#! /bin/sh
205641e18Smrg# Common wrapper for a few potentially missing GNU programs.
3f299d47fSmrg
498d75b17Smrgscriptversion=2018-03-07.03; # UTC
5f299d47fSmrg
698d75b17Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
705641e18Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8f299d47fSmrg
9f299d47fSmrg# This program is free software; you can redistribute it and/or modify
10f299d47fSmrg# it under the terms of the GNU General Public License as published by
11f299d47fSmrg# the Free Software Foundation; either version 2, or (at your option)
12f299d47fSmrg# any later version.
13f299d47fSmrg
14f299d47fSmrg# This program is distributed in the hope that it will be useful,
15f299d47fSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16f299d47fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17f299d47fSmrg# GNU General Public License for more details.
18f299d47fSmrg
19f299d47fSmrg# You should have received a copy of the GNU General Public License
2098d75b17Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21f299d47fSmrg
22f299d47fSmrg# As a special exception to the GNU General Public License, if you
23f299d47fSmrg# distribute this file as part of a program that contains a
24f299d47fSmrg# configuration script generated by Autoconf, you may include it under
25f299d47fSmrg# the same distribution terms that you use for the rest of that program.
26f299d47fSmrg
27f299d47fSmrgif test $# -eq 0; then
2805641e18Smrg  echo 1>&2 "Try '$0 --help' for more information"
29f299d47fSmrg  exit 1
30f299d47fSmrgfi
31f299d47fSmrg
3205641e18Smrgcase $1 in
33f299d47fSmrg
3405641e18Smrg  --is-lightweight)
3505641e18Smrg    # Used by our autoconf macros to check whether the available missing
3605641e18Smrg    # script is modern enough.
3705641e18Smrg    exit 0
3805641e18Smrg    ;;
39f299d47fSmrg
4005641e18Smrg  --run)
4105641e18Smrg    # Back-compat with the calling convention used by older automake.
4205641e18Smrg    shift
4305641e18Smrg    ;;
44f299d47fSmrg
45f299d47fSmrg  -h|--h|--he|--hel|--help)
46f299d47fSmrg    echo "\
47f299d47fSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48f299d47fSmrg
4905641e18SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5005641e18Smrgto PROGRAM being missing or too old.
51f299d47fSmrg
52f299d47fSmrgOptions:
53f299d47fSmrg  -h, --help      display this help and exit
54f299d47fSmrg  -v, --version   output version information and exit
55f299d47fSmrg
56f299d47fSmrgSupported PROGRAM values:
5705641e18Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5805641e18Smrg  bison     yacc      flex         lex       help2man
59f299d47fSmrg
6005641e18SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6105641e18Smrg'g' are ignored when checking the name.
62aa98702cSmrg
63f299d47fSmrgSend bug reports to <bug-automake@gnu.org>."
64f299d47fSmrg    exit $?
65f299d47fSmrg    ;;
66f299d47fSmrg
67f299d47fSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68f299d47fSmrg    echo "missing $scriptversion (GNU Automake)"
69f299d47fSmrg    exit $?
70f299d47fSmrg    ;;
71f299d47fSmrg
72f299d47fSmrg  -*)
7305641e18Smrg    echo 1>&2 "$0: unknown '$1' option"
7405641e18Smrg    echo 1>&2 "Try '$0 --help' for more information"
75f299d47fSmrg    exit 1
76f299d47fSmrg    ;;
77f299d47fSmrg
78f299d47fSmrgesac
79f299d47fSmrg
8005641e18Smrg# Run the given program, remember its exit status.
8105641e18Smrg"$@"; st=$?
8205641e18Smrg
8305641e18Smrg# If it succeeded, we are done.
8405641e18Smrgtest $st -eq 0 && exit 0
8505641e18Smrg
8605641e18Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8705641e18Smrg# passed; such an option is passed most likely to detect whether the
8805641e18Smrg# program is present and works.
8905641e18Smrgcase $2 in --version|--help) exit $st;; esac
9005641e18Smrg
9105641e18Smrg# Exit code 63 means version mismatch.  This often happens when the user
9205641e18Smrg# tries to use an ancient version of a tool on a file that requires a
9305641e18Smrg# minimum version.
9405641e18Smrgif test $st -eq 63; then
9505641e18Smrg  msg="probably too old"
9605641e18Smrgelif test $st -eq 127; then
9705641e18Smrg  # Program was missing.
9805641e18Smrg  msg="missing on your system"
9905641e18Smrgelse
10005641e18Smrg  # Program was found and executed, but failed.  Give up.
10105641e18Smrg  exit $st
10205641e18Smrgfi
103f299d47fSmrg
10498d75b17Smrgperl_URL=https://www.perl.org/
10598d75b17Smrgflex_URL=https://github.com/westes/flex
10698d75b17Smrggnu_software_URL=https://www.gnu.org/software
10705641e18Smrg
10805641e18Smrgprogram_details ()
10905641e18Smrg{
11005641e18Smrg  case $1 in
11105641e18Smrg    aclocal|automake)
11205641e18Smrg      echo "The '$1' program is part of the GNU Automake package:"
11305641e18Smrg      echo "<$gnu_software_URL/automake>"
11405641e18Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11505641e18Smrg      echo "<$gnu_software_URL/autoconf>"
11605641e18Smrg      echo "<$gnu_software_URL/m4/>"
11705641e18Smrg      echo "<$perl_URL>"
11805641e18Smrg      ;;
11905641e18Smrg    autoconf|autom4te|autoheader)
12005641e18Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12105641e18Smrg      echo "<$gnu_software_URL/autoconf/>"
12205641e18Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12305641e18Smrg      echo "<$gnu_software_URL/m4/>"
12405641e18Smrg      echo "<$perl_URL>"
12505641e18Smrg      ;;
12605641e18Smrg  esac
12705641e18Smrg}
12805641e18Smrg
12905641e18Smrggive_advice ()
13005641e18Smrg{
13105641e18Smrg  # Normalize program name to check for.
13205641e18Smrg  normalized_program=`echo "$1" | sed '
13305641e18Smrg    s/^gnu-//; t
13405641e18Smrg    s/^gnu//; t
13505641e18Smrg    s/^g//; t'`
13605641e18Smrg
13705641e18Smrg  printf '%s\n' "'$1' is $msg."
13805641e18Smrg
13905641e18Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14005641e18Smrg  case $normalized_program in
14105641e18Smrg    autoconf*)
14205641e18Smrg      echo "You should only need it if you modified 'configure.ac',"
14305641e18Smrg      echo "or m4 files included by it."
14405641e18Smrg      program_details 'autoconf'
14505641e18Smrg      ;;
14605641e18Smrg    autoheader*)
14705641e18Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14805641e18Smrg      echo "$configure_deps."
14905641e18Smrg      program_details 'autoheader'
15005641e18Smrg      ;;
15105641e18Smrg    automake*)
15205641e18Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15305641e18Smrg      echo "$configure_deps."
15405641e18Smrg      program_details 'automake'
15505641e18Smrg      ;;
15605641e18Smrg    aclocal*)
15705641e18Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15805641e18Smrg      echo "$configure_deps."
15905641e18Smrg      program_details 'aclocal'
16005641e18Smrg      ;;
16105641e18Smrg   autom4te*)
16205641e18Smrg      echo "You might have modified some maintainer files that require"
16305641e18Smrg      echo "the 'autom4te' program to be rebuilt."
16405641e18Smrg      program_details 'autom4te'
16505641e18Smrg      ;;
16605641e18Smrg    bison*|yacc*)
16705641e18Smrg      echo "You should only need it if you modified a '.y' file."
16805641e18Smrg      echo "You may want to install the GNU Bison package:"
16905641e18Smrg      echo "<$gnu_software_URL/bison/>"
17005641e18Smrg      ;;
17105641e18Smrg    lex*|flex*)
17205641e18Smrg      echo "You should only need it if you modified a '.l' file."
17305641e18Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17405641e18Smrg      echo "<$flex_URL>"
17505641e18Smrg      ;;
17605641e18Smrg    help2man*)
17705641e18Smrg      echo "You should only need it if you modified a dependency" \
17805641e18Smrg           "of a man page."
17905641e18Smrg      echo "You may want to install the GNU Help2man package:"
18005641e18Smrg      echo "<$gnu_software_URL/help2man/>"
181f299d47fSmrg    ;;
18205641e18Smrg    makeinfo*)
18305641e18Smrg      echo "You should only need it if you modified a '.texi' file, or"
18405641e18Smrg      echo "any other file indirectly affecting the aspect of the manual."
18505641e18Smrg      echo "You might want to install the Texinfo package:"
18605641e18Smrg      echo "<$gnu_software_URL/texinfo/>"
18705641e18Smrg      echo "The spurious makeinfo call might also be the consequence of"
18805641e18Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18905641e18Smrg      echo "want to install GNU make:"
19005641e18Smrg      echo "<$gnu_software_URL/make/>"
19105641e18Smrg      ;;
19205641e18Smrg    *)
19305641e18Smrg      echo "You might have modified some files without having the proper"
19405641e18Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19505641e18Smrg      echo "often tells you about the needed prerequisites for installing"
19605641e18Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19705641e18Smrg      echo "case some other package contains this missing '$1' program."
19805641e18Smrg      ;;
19905641e18Smrg  esac
20005641e18Smrg}
20105641e18Smrg
20205641e18Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20305641e18Smrg                       -e '2,$s/^/         /' >&2
20405641e18Smrg
20505641e18Smrg# Propagate the correct exit status (expected to be 127 for a program
20605641e18Smrg# not found, 63 for a program that failed due to version mismatch).
20705641e18Smrgexit $st
208f299d47fSmrg
209f299d47fSmrg# Local variables:
21098d75b17Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
211f299d47fSmrg# time-stamp-start: "scriptversion="
212f299d47fSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21398d75b17Smrg# time-stamp-time-zone: "UTC0"
214aa98702cSmrg# time-stamp-end: "; # UTC"
215f299d47fSmrg# End:
216