1a99f82b8Smrg#! /bin/sh
218b08247Smrg# Common wrapper for a few potentially missing GNU programs.
32d62a77cSmrg
40c1e1135Smrgscriptversion=2018-03-07.03; # UTC
52d62a77cSmrg
60c1e1135Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
718b08247Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8a99f82b8Smrg
9a99f82b8Smrg# This program is free software; you can redistribute it and/or modify
10a99f82b8Smrg# it under the terms of the GNU General Public License as published by
11a99f82b8Smrg# the Free Software Foundation; either version 2, or (at your option)
12a99f82b8Smrg# any later version.
13a99f82b8Smrg
14a99f82b8Smrg# This program is distributed in the hope that it will be useful,
15a99f82b8Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16a99f82b8Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a99f82b8Smrg# GNU General Public License for more details.
18a99f82b8Smrg
19a99f82b8Smrg# You should have received a copy of the GNU General Public License
200c1e1135Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21a99f82b8Smrg
22a99f82b8Smrg# As a special exception to the GNU General Public License, if you
23a99f82b8Smrg# distribute this file as part of a program that contains a
24a99f82b8Smrg# configuration script generated by Autoconf, you may include it under
25a99f82b8Smrg# the same distribution terms that you use for the rest of that program.
26a99f82b8Smrg
27a99f82b8Smrgif test $# -eq 0; then
2818b08247Smrg  echo 1>&2 "Try '$0 --help' for more information"
29a99f82b8Smrg  exit 1
30a99f82b8Smrgfi
31a99f82b8Smrg
3218b08247Smrgcase $1 in
33a99f82b8Smrg
3418b08247Smrg  --is-lightweight)
3518b08247Smrg    # Used by our autoconf macros to check whether the available missing
3618b08247Smrg    # script is modern enough.
3718b08247Smrg    exit 0
3818b08247Smrg    ;;
392d62a77cSmrg
4018b08247Smrg  --run)
4118b08247Smrg    # Back-compat with the calling convention used by older automake.
4218b08247Smrg    shift
4318b08247Smrg    ;;
44a99f82b8Smrg
45a99f82b8Smrg  -h|--h|--he|--hel|--help)
46a99f82b8Smrg    echo "\
47a99f82b8Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48a99f82b8Smrg
4918b08247SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5018b08247Smrgto PROGRAM being missing or too old.
51a99f82b8Smrg
52a99f82b8SmrgOptions:
53a99f82b8Smrg  -h, --help      display this help and exit
54a99f82b8Smrg  -v, --version   output version information and exit
55a99f82b8Smrg
56a99f82b8SmrgSupported PROGRAM values:
5718b08247Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5818b08247Smrg  bison     yacc      flex         lex       help2man
592d62a77cSmrg
6018b08247SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6118b08247Smrg'g' are ignored when checking the name.
622d62a77cSmrg
632d62a77cSmrgSend bug reports to <bug-automake@gnu.org>."
642d62a77cSmrg    exit $?
65a99f82b8Smrg    ;;
66a99f82b8Smrg
67a99f82b8Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
682d62a77cSmrg    echo "missing $scriptversion (GNU Automake)"
692d62a77cSmrg    exit $?
70a99f82b8Smrg    ;;
71a99f82b8Smrg
72a99f82b8Smrg  -*)
7318b08247Smrg    echo 1>&2 "$0: unknown '$1' option"
7418b08247Smrg    echo 1>&2 "Try '$0 --help' for more information"
75a99f82b8Smrg    exit 1
76a99f82b8Smrg    ;;
77a99f82b8Smrg
782d62a77cSmrgesac
792d62a77cSmrg
8018b08247Smrg# Run the given program, remember its exit status.
8118b08247Smrg"$@"; st=$?
8218b08247Smrg
8318b08247Smrg# If it succeeded, we are done.
8418b08247Smrgtest $st -eq 0 && exit 0
8518b08247Smrg
8618b08247Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8718b08247Smrg# passed; such an option is passed most likely to detect whether the
8818b08247Smrg# program is present and works.
8918b08247Smrgcase $2 in --version|--help) exit $st;; esac
9018b08247Smrg
9118b08247Smrg# Exit code 63 means version mismatch.  This often happens when the user
9218b08247Smrg# tries to use an ancient version of a tool on a file that requires a
9318b08247Smrg# minimum version.
9418b08247Smrgif test $st -eq 63; then
9518b08247Smrg  msg="probably too old"
9618b08247Smrgelif test $st -eq 127; then
9718b08247Smrg  # Program was missing.
9818b08247Smrg  msg="missing on your system"
9918b08247Smrgelse
10018b08247Smrg  # Program was found and executed, but failed.  Give up.
10118b08247Smrg  exit $st
10218b08247Smrgfi
103a99f82b8Smrg
1040c1e1135Smrgperl_URL=https://www.perl.org/
1050c1e1135Smrgflex_URL=https://github.com/westes/flex
1060c1e1135Smrggnu_software_URL=https://www.gnu.org/software
10718b08247Smrg
10818b08247Smrgprogram_details ()
10918b08247Smrg{
11018b08247Smrg  case $1 in
11118b08247Smrg    aclocal|automake)
11218b08247Smrg      echo "The '$1' program is part of the GNU Automake package:"
11318b08247Smrg      echo "<$gnu_software_URL/automake>"
11418b08247Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11518b08247Smrg      echo "<$gnu_software_URL/autoconf>"
11618b08247Smrg      echo "<$gnu_software_URL/m4/>"
11718b08247Smrg      echo "<$perl_URL>"
11818b08247Smrg      ;;
11918b08247Smrg    autoconf|autom4te|autoheader)
12018b08247Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12118b08247Smrg      echo "<$gnu_software_URL/autoconf/>"
12218b08247Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12318b08247Smrg      echo "<$gnu_software_URL/m4/>"
12418b08247Smrg      echo "<$perl_URL>"
12518b08247Smrg      ;;
12618b08247Smrg  esac
12718b08247Smrg}
12818b08247Smrg
12918b08247Smrggive_advice ()
13018b08247Smrg{
13118b08247Smrg  # Normalize program name to check for.
13218b08247Smrg  normalized_program=`echo "$1" | sed '
13318b08247Smrg    s/^gnu-//; t
13418b08247Smrg    s/^gnu//; t
13518b08247Smrg    s/^g//; t'`
13618b08247Smrg
13718b08247Smrg  printf '%s\n' "'$1' is $msg."
13818b08247Smrg
13918b08247Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14018b08247Smrg  case $normalized_program in
14118b08247Smrg    autoconf*)
14218b08247Smrg      echo "You should only need it if you modified 'configure.ac',"
14318b08247Smrg      echo "or m4 files included by it."
14418b08247Smrg      program_details 'autoconf'
14518b08247Smrg      ;;
14618b08247Smrg    autoheader*)
14718b08247Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14818b08247Smrg      echo "$configure_deps."
14918b08247Smrg      program_details 'autoheader'
15018b08247Smrg      ;;
15118b08247Smrg    automake*)
15218b08247Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15318b08247Smrg      echo "$configure_deps."
15418b08247Smrg      program_details 'automake'
15518b08247Smrg      ;;
15618b08247Smrg    aclocal*)
15718b08247Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15818b08247Smrg      echo "$configure_deps."
15918b08247Smrg      program_details 'aclocal'
16018b08247Smrg      ;;
16118b08247Smrg   autom4te*)
16218b08247Smrg      echo "You might have modified some maintainer files that require"
16318b08247Smrg      echo "the 'autom4te' program to be rebuilt."
16418b08247Smrg      program_details 'autom4te'
16518b08247Smrg      ;;
16618b08247Smrg    bison*|yacc*)
16718b08247Smrg      echo "You should only need it if you modified a '.y' file."
16818b08247Smrg      echo "You may want to install the GNU Bison package:"
16918b08247Smrg      echo "<$gnu_software_URL/bison/>"
17018b08247Smrg      ;;
17118b08247Smrg    lex*|flex*)
17218b08247Smrg      echo "You should only need it if you modified a '.l' file."
17318b08247Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17418b08247Smrg      echo "<$flex_URL>"
17518b08247Smrg      ;;
17618b08247Smrg    help2man*)
17718b08247Smrg      echo "You should only need it if you modified a dependency" \
17818b08247Smrg           "of a man page."
17918b08247Smrg      echo "You may want to install the GNU Help2man package:"
18018b08247Smrg      echo "<$gnu_software_URL/help2man/>"
18118b08247Smrg    ;;
18218b08247Smrg    makeinfo*)
18318b08247Smrg      echo "You should only need it if you modified a '.texi' file, or"
18418b08247Smrg      echo "any other file indirectly affecting the aspect of the manual."
18518b08247Smrg      echo "You might want to install the Texinfo package:"
18618b08247Smrg      echo "<$gnu_software_URL/texinfo/>"
18718b08247Smrg      echo "The spurious makeinfo call might also be the consequence of"
18818b08247Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18918b08247Smrg      echo "want to install GNU make:"
19018b08247Smrg      echo "<$gnu_software_URL/make/>"
19118b08247Smrg      ;;
19218b08247Smrg    *)
19318b08247Smrg      echo "You might have modified some files without having the proper"
19418b08247Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19518b08247Smrg      echo "often tells you about the needed prerequisites for installing"
19618b08247Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19718b08247Smrg      echo "case some other package contains this missing '$1' program."
19818b08247Smrg      ;;
19918b08247Smrg  esac
20018b08247Smrg}
20118b08247Smrg
20218b08247Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20318b08247Smrg                       -e '2,$s/^/         /' >&2
20418b08247Smrg
20518b08247Smrg# Propagate the correct exit status (expected to be 127 for a program
20618b08247Smrg# not found, 63 for a program that failed due to version mismatch).
20718b08247Smrgexit $st
2082d62a77cSmrg
2092d62a77cSmrg# Local variables:
2100c1e1135Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2112d62a77cSmrg# time-stamp-start: "scriptversion="
2122d62a77cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2130c1e1135Smrg# time-stamp-time-zone: "UTC0"
2142d62a77cSmrg# time-stamp-end: "; # UTC"
2152d62a77cSmrg# End:
216