1ffab5952Smrg#! /bin/sh
267e4e4deSmrg# Common wrapper for a few potentially missing GNU programs.
3ffab5952Smrg
445aa2fbfSmrgscriptversion=2018-03-07.03; # UTC
5ffab5952Smrg
6ea972ba2Smrg# Copyright (C) 1996-2020 Free Software Foundation, Inc.
767e4e4deSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8ffab5952Smrg
9ffab5952Smrg# This program is free software; you can redistribute it and/or modify
10ffab5952Smrg# it under the terms of the GNU General Public License as published by
11ffab5952Smrg# the Free Software Foundation; either version 2, or (at your option)
12ffab5952Smrg# any later version.
13ffab5952Smrg
14ffab5952Smrg# This program is distributed in the hope that it will be useful,
15ffab5952Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16ffab5952Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17ffab5952Smrg# GNU General Public License for more details.
18ffab5952Smrg
19ffab5952Smrg# You should have received a copy of the GNU General Public License
2045aa2fbfSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21ffab5952Smrg
22ffab5952Smrg# As a special exception to the GNU General Public License, if you
23ffab5952Smrg# distribute this file as part of a program that contains a
24ffab5952Smrg# configuration script generated by Autoconf, you may include it under
25ffab5952Smrg# the same distribution terms that you use for the rest of that program.
26ffab5952Smrg
27ffab5952Smrgif test $# -eq 0; then
2867e4e4deSmrg  echo 1>&2 "Try '$0 --help' for more information"
29ffab5952Smrg  exit 1
30ffab5952Smrgfi
31ffab5952Smrg
3267e4e4deSmrgcase $1 in
33ffab5952Smrg
3467e4e4deSmrg  --is-lightweight)
3567e4e4deSmrg    # Used by our autoconf macros to check whether the available missing
3667e4e4deSmrg    # script is modern enough.
3767e4e4deSmrg    exit 0
3867e4e4deSmrg    ;;
39ffab5952Smrg
4067e4e4deSmrg  --run)
4167e4e4deSmrg    # Back-compat with the calling convention used by older automake.
4267e4e4deSmrg    shift
4367e4e4deSmrg    ;;
44ffab5952Smrg
45ffab5952Smrg  -h|--h|--he|--hel|--help)
46ffab5952Smrg    echo "\
47ffab5952Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48ffab5952Smrg
4967e4e4deSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5067e4e4deSmrgto PROGRAM being missing or too old.
51ffab5952Smrg
52ffab5952SmrgOptions:
53ffab5952Smrg  -h, --help      display this help and exit
54ffab5952Smrg  -v, --version   output version information and exit
55ffab5952Smrg
56ffab5952SmrgSupported PROGRAM values:
5767e4e4deSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5867e4e4deSmrg  bison     yacc      flex         lex       help2man
59ffab5952Smrg
6067e4e4deSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6167e4e4deSmrg'g' are ignored when checking the name.
62ffab5952Smrg
63ffab5952SmrgSend bug reports to <bug-automake@gnu.org>."
64ffab5952Smrg    exit $?
65ffab5952Smrg    ;;
66ffab5952Smrg
67ffab5952Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68ffab5952Smrg    echo "missing $scriptversion (GNU Automake)"
69ffab5952Smrg    exit $?
70ffab5952Smrg    ;;
71ffab5952Smrg
72ffab5952Smrg  -*)
7367e4e4deSmrg    echo 1>&2 "$0: unknown '$1' option"
7467e4e4deSmrg    echo 1>&2 "Try '$0 --help' for more information"
75ffab5952Smrg    exit 1
76ffab5952Smrg    ;;
77ffab5952Smrg
78ffab5952Smrgesac
79ffab5952Smrg
8067e4e4deSmrg# Run the given program, remember its exit status.
8167e4e4deSmrg"$@"; st=$?
8267e4e4deSmrg
8367e4e4deSmrg# If it succeeded, we are done.
8467e4e4deSmrgtest $st -eq 0 && exit 0
8567e4e4deSmrg
8667e4e4deSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
8767e4e4deSmrg# passed; such an option is passed most likely to detect whether the
8867e4e4deSmrg# program is present and works.
8967e4e4deSmrgcase $2 in --version|--help) exit $st;; esac
9067e4e4deSmrg
9167e4e4deSmrg# Exit code 63 means version mismatch.  This often happens when the user
9267e4e4deSmrg# tries to use an ancient version of a tool on a file that requires a
9367e4e4deSmrg# minimum version.
9467e4e4deSmrgif test $st -eq 63; then
9567e4e4deSmrg  msg="probably too old"
9667e4e4deSmrgelif test $st -eq 127; then
9767e4e4deSmrg  # Program was missing.
9867e4e4deSmrg  msg="missing on your system"
9967e4e4deSmrgelse
10067e4e4deSmrg  # Program was found and executed, but failed.  Give up.
10167e4e4deSmrg  exit $st
10267e4e4deSmrgfi
103ffab5952Smrg
10445aa2fbfSmrgperl_URL=https://www.perl.org/
10545aa2fbfSmrgflex_URL=https://github.com/westes/flex
10645aa2fbfSmrggnu_software_URL=https://www.gnu.org/software
10767e4e4deSmrg
10867e4e4deSmrgprogram_details ()
10967e4e4deSmrg{
11067e4e4deSmrg  case $1 in
11167e4e4deSmrg    aclocal|automake)
11267e4e4deSmrg      echo "The '$1' program is part of the GNU Automake package:"
11367e4e4deSmrg      echo "<$gnu_software_URL/automake>"
11467e4e4deSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11567e4e4deSmrg      echo "<$gnu_software_URL/autoconf>"
11667e4e4deSmrg      echo "<$gnu_software_URL/m4/>"
11767e4e4deSmrg      echo "<$perl_URL>"
11867e4e4deSmrg      ;;
11967e4e4deSmrg    autoconf|autom4te|autoheader)
12067e4e4deSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
12167e4e4deSmrg      echo "<$gnu_software_URL/autoconf/>"
12267e4e4deSmrg      echo "It also requires GNU m4 and Perl in order to run:"
12367e4e4deSmrg      echo "<$gnu_software_URL/m4/>"
12467e4e4deSmrg      echo "<$perl_URL>"
12567e4e4deSmrg      ;;
12667e4e4deSmrg  esac
12767e4e4deSmrg}
12867e4e4deSmrg
12967e4e4deSmrggive_advice ()
13067e4e4deSmrg{
13167e4e4deSmrg  # Normalize program name to check for.
13267e4e4deSmrg  normalized_program=`echo "$1" | sed '
13367e4e4deSmrg    s/^gnu-//; t
13467e4e4deSmrg    s/^gnu//; t
13567e4e4deSmrg    s/^g//; t'`
13667e4e4deSmrg
13767e4e4deSmrg  printf '%s\n' "'$1' is $msg."
13867e4e4deSmrg
13967e4e4deSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14067e4e4deSmrg  case $normalized_program in
14167e4e4deSmrg    autoconf*)
14267e4e4deSmrg      echo "You should only need it if you modified 'configure.ac',"
14367e4e4deSmrg      echo "or m4 files included by it."
14467e4e4deSmrg      program_details 'autoconf'
14567e4e4deSmrg      ;;
14667e4e4deSmrg    autoheader*)
14767e4e4deSmrg      echo "You should only need it if you modified 'acconfig.h' or"
14867e4e4deSmrg      echo "$configure_deps."
14967e4e4deSmrg      program_details 'autoheader'
15067e4e4deSmrg      ;;
15167e4e4deSmrg    automake*)
15267e4e4deSmrg      echo "You should only need it if you modified 'Makefile.am' or"
15367e4e4deSmrg      echo "$configure_deps."
15467e4e4deSmrg      program_details 'automake'
15567e4e4deSmrg      ;;
15667e4e4deSmrg    aclocal*)
15767e4e4deSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
15867e4e4deSmrg      echo "$configure_deps."
15967e4e4deSmrg      program_details 'aclocal'
16067e4e4deSmrg      ;;
16167e4e4deSmrg   autom4te*)
16267e4e4deSmrg      echo "You might have modified some maintainer files that require"
16367e4e4deSmrg      echo "the 'autom4te' program to be rebuilt."
16467e4e4deSmrg      program_details 'autom4te'
16567e4e4deSmrg      ;;
16667e4e4deSmrg    bison*|yacc*)
16767e4e4deSmrg      echo "You should only need it if you modified a '.y' file."
16867e4e4deSmrg      echo "You may want to install the GNU Bison package:"
16967e4e4deSmrg      echo "<$gnu_software_URL/bison/>"
17067e4e4deSmrg      ;;
17167e4e4deSmrg    lex*|flex*)
17267e4e4deSmrg      echo "You should only need it if you modified a '.l' file."
17367e4e4deSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
17467e4e4deSmrg      echo "<$flex_URL>"
17567e4e4deSmrg      ;;
17667e4e4deSmrg    help2man*)
17767e4e4deSmrg      echo "You should only need it if you modified a dependency" \
17867e4e4deSmrg           "of a man page."
17967e4e4deSmrg      echo "You may want to install the GNU Help2man package:"
18067e4e4deSmrg      echo "<$gnu_software_URL/help2man/>"
181ffab5952Smrg    ;;
18267e4e4deSmrg    makeinfo*)
18367e4e4deSmrg      echo "You should only need it if you modified a '.texi' file, or"
18467e4e4deSmrg      echo "any other file indirectly affecting the aspect of the manual."
18567e4e4deSmrg      echo "You might want to install the Texinfo package:"
18667e4e4deSmrg      echo "<$gnu_software_URL/texinfo/>"
18767e4e4deSmrg      echo "The spurious makeinfo call might also be the consequence of"
18867e4e4deSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18967e4e4deSmrg      echo "want to install GNU make:"
19067e4e4deSmrg      echo "<$gnu_software_URL/make/>"
19167e4e4deSmrg      ;;
19267e4e4deSmrg    *)
19367e4e4deSmrg      echo "You might have modified some files without having the proper"
19467e4e4deSmrg      echo "tools for further handling them.  Check the 'README' file, it"
19567e4e4deSmrg      echo "often tells you about the needed prerequisites for installing"
19667e4e4deSmrg      echo "this package.  You may also peek at any GNU archive site, in"
19767e4e4deSmrg      echo "case some other package contains this missing '$1' program."
19867e4e4deSmrg      ;;
19967e4e4deSmrg  esac
20067e4e4deSmrg}
20167e4e4deSmrg
20267e4e4deSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20367e4e4deSmrg                       -e '2,$s/^/         /' >&2
20467e4e4deSmrg
20567e4e4deSmrg# Propagate the correct exit status (expected to be 127 for a program
20667e4e4deSmrg# not found, 63 for a program that failed due to version mismatch).
20767e4e4deSmrgexit $st
208ffab5952Smrg
209ffab5952Smrg# Local variables:
21045aa2fbfSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
211ffab5952Smrg# time-stamp-start: "scriptversion="
212ffab5952Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21345aa2fbfSmrg# time-stamp-time-zone: "UTC0"
214ffab5952Smrg# time-stamp-end: "; # UTC"
215ffab5952Smrg# End:
216