14b0ead49Smrg#! /bin/sh
226372658Smrg# Common wrapper for a few potentially missing GNU programs.
34b0ead49Smrg
4c3e29c03Smrgscriptversion=2018-03-07.03; # UTC
54b0ead49Smrg
6c3e29c03Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
726372658Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
84b0ead49Smrg
94b0ead49Smrg# This program is free software; you can redistribute it and/or modify
104b0ead49Smrg# it under the terms of the GNU General Public License as published by
114b0ead49Smrg# the Free Software Foundation; either version 2, or (at your option)
124b0ead49Smrg# any later version.
134b0ead49Smrg
144b0ead49Smrg# This program is distributed in the hope that it will be useful,
154b0ead49Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
164b0ead49Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
174b0ead49Smrg# GNU General Public License for more details.
184b0ead49Smrg
194b0ead49Smrg# You should have received a copy of the GNU General Public License
20c3e29c03Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
214b0ead49Smrg
224b0ead49Smrg# As a special exception to the GNU General Public License, if you
234b0ead49Smrg# distribute this file as part of a program that contains a
244b0ead49Smrg# configuration script generated by Autoconf, you may include it under
254b0ead49Smrg# the same distribution terms that you use for the rest of that program.
264b0ead49Smrg
274b0ead49Smrgif test $# -eq 0; then
2826372658Smrg  echo 1>&2 "Try '$0 --help' for more information"
294b0ead49Smrg  exit 1
304b0ead49Smrgfi
314b0ead49Smrg
3226372658Smrgcase $1 in
334b0ead49Smrg
3426372658Smrg  --is-lightweight)
3526372658Smrg    # Used by our autoconf macros to check whether the available missing
3626372658Smrg    # script is modern enough.
3726372658Smrg    exit 0
3826372658Smrg    ;;
394b0ead49Smrg
4026372658Smrg  --run)
4126372658Smrg    # Back-compat with the calling convention used by older automake.
4226372658Smrg    shift
4326372658Smrg    ;;
444b0ead49Smrg
454b0ead49Smrg  -h|--h|--he|--hel|--help)
464b0ead49Smrg    echo "\
474b0ead49Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
484b0ead49Smrg
4926372658SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5026372658Smrgto PROGRAM being missing or too old.
514b0ead49Smrg
524b0ead49SmrgOptions:
534b0ead49Smrg  -h, --help      display this help and exit
544b0ead49Smrg  -v, --version   output version information and exit
554b0ead49Smrg
564b0ead49SmrgSupported PROGRAM values:
5726372658Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5826372658Smrg  bison     yacc      flex         lex       help2man
594b0ead49Smrg
6026372658SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6126372658Smrg'g' are ignored when checking the name.
6252b01e16Smrg
634b0ead49SmrgSend bug reports to <bug-automake@gnu.org>."
644b0ead49Smrg    exit $?
654b0ead49Smrg    ;;
664b0ead49Smrg
674b0ead49Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
684b0ead49Smrg    echo "missing $scriptversion (GNU Automake)"
694b0ead49Smrg    exit $?
704b0ead49Smrg    ;;
714b0ead49Smrg
724b0ead49Smrg  -*)
7326372658Smrg    echo 1>&2 "$0: unknown '$1' option"
7426372658Smrg    echo 1>&2 "Try '$0 --help' for more information"
754b0ead49Smrg    exit 1
764b0ead49Smrg    ;;
774b0ead49Smrg
784b0ead49Smrgesac
794b0ead49Smrg
8026372658Smrg# Run the given program, remember its exit status.
8126372658Smrg"$@"; st=$?
8226372658Smrg
8326372658Smrg# If it succeeded, we are done.
8426372658Smrgtest $st -eq 0 && exit 0
8526372658Smrg
8626372658Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8726372658Smrg# passed; such an option is passed most likely to detect whether the
8826372658Smrg# program is present and works.
8926372658Smrgcase $2 in --version|--help) exit $st;; esac
9026372658Smrg
9126372658Smrg# Exit code 63 means version mismatch.  This often happens when the user
9226372658Smrg# tries to use an ancient version of a tool on a file that requires a
9326372658Smrg# minimum version.
9426372658Smrgif test $st -eq 63; then
9526372658Smrg  msg="probably too old"
9626372658Smrgelif test $st -eq 127; then
9726372658Smrg  # Program was missing.
9826372658Smrg  msg="missing on your system"
9926372658Smrgelse
10026372658Smrg  # Program was found and executed, but failed.  Give up.
10126372658Smrg  exit $st
10226372658Smrgfi
1034b0ead49Smrg
104c3e29c03Smrgperl_URL=https://www.perl.org/
105c3e29c03Smrgflex_URL=https://github.com/westes/flex
106c3e29c03Smrggnu_software_URL=https://www.gnu.org/software
10726372658Smrg
10826372658Smrgprogram_details ()
10926372658Smrg{
11026372658Smrg  case $1 in
11126372658Smrg    aclocal|automake)
11226372658Smrg      echo "The '$1' program is part of the GNU Automake package:"
11326372658Smrg      echo "<$gnu_software_URL/automake>"
11426372658Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11526372658Smrg      echo "<$gnu_software_URL/autoconf>"
11626372658Smrg      echo "<$gnu_software_URL/m4/>"
11726372658Smrg      echo "<$perl_URL>"
11826372658Smrg      ;;
11926372658Smrg    autoconf|autom4te|autoheader)
12026372658Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12126372658Smrg      echo "<$gnu_software_URL/autoconf/>"
12226372658Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12326372658Smrg      echo "<$gnu_software_URL/m4/>"
12426372658Smrg      echo "<$perl_URL>"
12526372658Smrg      ;;
12626372658Smrg  esac
12726372658Smrg}
12826372658Smrg
12926372658Smrggive_advice ()
13026372658Smrg{
13126372658Smrg  # Normalize program name to check for.
13226372658Smrg  normalized_program=`echo "$1" | sed '
13326372658Smrg    s/^gnu-//; t
13426372658Smrg    s/^gnu//; t
13526372658Smrg    s/^g//; t'`
13626372658Smrg
13726372658Smrg  printf '%s\n' "'$1' is $msg."
13826372658Smrg
13926372658Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14026372658Smrg  case $normalized_program in
14126372658Smrg    autoconf*)
14226372658Smrg      echo "You should only need it if you modified 'configure.ac',"
14326372658Smrg      echo "or m4 files included by it."
14426372658Smrg      program_details 'autoconf'
14526372658Smrg      ;;
14626372658Smrg    autoheader*)
14726372658Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14826372658Smrg      echo "$configure_deps."
14926372658Smrg      program_details 'autoheader'
15026372658Smrg      ;;
15126372658Smrg    automake*)
15226372658Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15326372658Smrg      echo "$configure_deps."
15426372658Smrg      program_details 'automake'
15526372658Smrg      ;;
15626372658Smrg    aclocal*)
15726372658Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15826372658Smrg      echo "$configure_deps."
15926372658Smrg      program_details 'aclocal'
16026372658Smrg      ;;
16126372658Smrg   autom4te*)
16226372658Smrg      echo "You might have modified some maintainer files that require"
16326372658Smrg      echo "the 'autom4te' program to be rebuilt."
16426372658Smrg      program_details 'autom4te'
16526372658Smrg      ;;
16626372658Smrg    bison*|yacc*)
16726372658Smrg      echo "You should only need it if you modified a '.y' file."
16826372658Smrg      echo "You may want to install the GNU Bison package:"
16926372658Smrg      echo "<$gnu_software_URL/bison/>"
17026372658Smrg      ;;
17126372658Smrg    lex*|flex*)
17226372658Smrg      echo "You should only need it if you modified a '.l' file."
17326372658Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17426372658Smrg      echo "<$flex_URL>"
17526372658Smrg      ;;
17626372658Smrg    help2man*)
17726372658Smrg      echo "You should only need it if you modified a dependency" \
17826372658Smrg           "of a man page."
17926372658Smrg      echo "You may want to install the GNU Help2man package:"
18026372658Smrg      echo "<$gnu_software_URL/help2man/>"
18126372658Smrg    ;;
18226372658Smrg    makeinfo*)
18326372658Smrg      echo "You should only need it if you modified a '.texi' file, or"
18426372658Smrg      echo "any other file indirectly affecting the aspect of the manual."
18526372658Smrg      echo "You might want to install the Texinfo package:"
18626372658Smrg      echo "<$gnu_software_URL/texinfo/>"
18726372658Smrg      echo "The spurious makeinfo call might also be the consequence of"
18826372658Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18926372658Smrg      echo "want to install GNU make:"
19026372658Smrg      echo "<$gnu_software_URL/make/>"
19126372658Smrg      ;;
19226372658Smrg    *)
19326372658Smrg      echo "You might have modified some files without having the proper"
19426372658Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19526372658Smrg      echo "often tells you about the needed prerequisites for installing"
19626372658Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19726372658Smrg      echo "case some other package contains this missing '$1' program."
19826372658Smrg      ;;
19926372658Smrg  esac
20026372658Smrg}
20126372658Smrg
20226372658Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20326372658Smrg                       -e '2,$s/^/         /' >&2
20426372658Smrg
20526372658Smrg# Propagate the correct exit status (expected to be 127 for a program
20626372658Smrg# not found, 63 for a program that failed due to version mismatch).
20726372658Smrgexit $st
2084b0ead49Smrg
2094b0ead49Smrg# Local variables:
210c3e29c03Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2114b0ead49Smrg# time-stamp-start: "scriptversion="
2124b0ead49Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213c3e29c03Smrg# time-stamp-time-zone: "UTC0"
21452b01e16Smrg# time-stamp-end: "; # UTC"
2154b0ead49Smrg# End:
216