18c9fbc29Smrg#! /bin/sh
270728a38Smrg# Common wrapper for a few potentially missing GNU programs.
38c9fbc29Smrg
454cef2ddSmrgscriptversion=2018-03-07.03; # UTC
58c9fbc29Smrg
654cef2ddSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
770728a38Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
88c9fbc29Smrg
98c9fbc29Smrg# This program is free software; you can redistribute it and/or modify
108c9fbc29Smrg# it under the terms of the GNU General Public License as published by
118c9fbc29Smrg# the Free Software Foundation; either version 2, or (at your option)
128c9fbc29Smrg# any later version.
138c9fbc29Smrg
148c9fbc29Smrg# This program is distributed in the hope that it will be useful,
158c9fbc29Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
168c9fbc29Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
178c9fbc29Smrg# GNU General Public License for more details.
188c9fbc29Smrg
198c9fbc29Smrg# You should have received a copy of the GNU General Public License
2054cef2ddSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
218c9fbc29Smrg
228c9fbc29Smrg# As a special exception to the GNU General Public License, if you
238c9fbc29Smrg# distribute this file as part of a program that contains a
248c9fbc29Smrg# configuration script generated by Autoconf, you may include it under
258c9fbc29Smrg# the same distribution terms that you use for the rest of that program.
268c9fbc29Smrg
278c9fbc29Smrgif test $# -eq 0; then
2870728a38Smrg  echo 1>&2 "Try '$0 --help' for more information"
298c9fbc29Smrg  exit 1
308c9fbc29Smrgfi
318c9fbc29Smrg
3270728a38Smrgcase $1 in
338c9fbc29Smrg
3470728a38Smrg  --is-lightweight)
3570728a38Smrg    # Used by our autoconf macros to check whether the available missing
3670728a38Smrg    # script is modern enough.
3770728a38Smrg    exit 0
3870728a38Smrg    ;;
398c9fbc29Smrg
4070728a38Smrg  --run)
4170728a38Smrg    # Back-compat with the calling convention used by older automake.
4270728a38Smrg    shift
4370728a38Smrg    ;;
448c9fbc29Smrg
458c9fbc29Smrg  -h|--h|--he|--hel|--help)
468c9fbc29Smrg    echo "\
478c9fbc29Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
488c9fbc29Smrg
4970728a38SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5070728a38Smrgto PROGRAM being missing or too old.
518c9fbc29Smrg
528c9fbc29SmrgOptions:
538c9fbc29Smrg  -h, --help      display this help and exit
548c9fbc29Smrg  -v, --version   output version information and exit
558c9fbc29Smrg
568c9fbc29SmrgSupported PROGRAM values:
5770728a38Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
5870728a38Smrg  bison     yacc      flex         lex       help2man
598c9fbc29Smrg
6070728a38SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6170728a38Smrg'g' are ignored when checking the name.
624e411241Smrg
638c9fbc29SmrgSend bug reports to <bug-automake@gnu.org>."
648c9fbc29Smrg    exit $?
658c9fbc29Smrg    ;;
668c9fbc29Smrg
678c9fbc29Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
688c9fbc29Smrg    echo "missing $scriptversion (GNU Automake)"
698c9fbc29Smrg    exit $?
708c9fbc29Smrg    ;;
718c9fbc29Smrg
728c9fbc29Smrg  -*)
7370728a38Smrg    echo 1>&2 "$0: unknown '$1' option"
7470728a38Smrg    echo 1>&2 "Try '$0 --help' for more information"
758c9fbc29Smrg    exit 1
768c9fbc29Smrg    ;;
778c9fbc29Smrg
788c9fbc29Smrgesac
798c9fbc29Smrg
8070728a38Smrg# Run the given program, remember its exit status.
8170728a38Smrg"$@"; st=$?
8270728a38Smrg
8370728a38Smrg# If it succeeded, we are done.
8470728a38Smrgtest $st -eq 0 && exit 0
8570728a38Smrg
8670728a38Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
8770728a38Smrg# passed; such an option is passed most likely to detect whether the
8870728a38Smrg# program is present and works.
8970728a38Smrgcase $2 in --version|--help) exit $st;; esac
9070728a38Smrg
9170728a38Smrg# Exit code 63 means version mismatch.  This often happens when the user
9270728a38Smrg# tries to use an ancient version of a tool on a file that requires a
9370728a38Smrg# minimum version.
9470728a38Smrgif test $st -eq 63; then
9570728a38Smrg  msg="probably too old"
9670728a38Smrgelif test $st -eq 127; then
9770728a38Smrg  # Program was missing.
9870728a38Smrg  msg="missing on your system"
9970728a38Smrgelse
10070728a38Smrg  # Program was found and executed, but failed.  Give up.
10170728a38Smrg  exit $st
10270728a38Smrgfi
1038c9fbc29Smrg
10454cef2ddSmrgperl_URL=https://www.perl.org/
10554cef2ddSmrgflex_URL=https://github.com/westes/flex
10654cef2ddSmrggnu_software_URL=https://www.gnu.org/software
10770728a38Smrg
10870728a38Smrgprogram_details ()
10970728a38Smrg{
11070728a38Smrg  case $1 in
11170728a38Smrg    aclocal|automake)
11270728a38Smrg      echo "The '$1' program is part of the GNU Automake package:"
11370728a38Smrg      echo "<$gnu_software_URL/automake>"
11470728a38Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11570728a38Smrg      echo "<$gnu_software_URL/autoconf>"
11670728a38Smrg      echo "<$gnu_software_URL/m4/>"
11770728a38Smrg      echo "<$perl_URL>"
11870728a38Smrg      ;;
11970728a38Smrg    autoconf|autom4te|autoheader)
12070728a38Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
12170728a38Smrg      echo "<$gnu_software_URL/autoconf/>"
12270728a38Smrg      echo "It also requires GNU m4 and Perl in order to run:"
12370728a38Smrg      echo "<$gnu_software_URL/m4/>"
12470728a38Smrg      echo "<$perl_URL>"
12570728a38Smrg      ;;
12670728a38Smrg  esac
12770728a38Smrg}
12870728a38Smrg
12970728a38Smrggive_advice ()
13070728a38Smrg{
13170728a38Smrg  # Normalize program name to check for.
13270728a38Smrg  normalized_program=`echo "$1" | sed '
13370728a38Smrg    s/^gnu-//; t
13470728a38Smrg    s/^gnu//; t
13570728a38Smrg    s/^g//; t'`
13670728a38Smrg
13770728a38Smrg  printf '%s\n' "'$1' is $msg."
13870728a38Smrg
13970728a38Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
14070728a38Smrg  case $normalized_program in
14170728a38Smrg    autoconf*)
14270728a38Smrg      echo "You should only need it if you modified 'configure.ac',"
14370728a38Smrg      echo "or m4 files included by it."
14470728a38Smrg      program_details 'autoconf'
14570728a38Smrg      ;;
14670728a38Smrg    autoheader*)
14770728a38Smrg      echo "You should only need it if you modified 'acconfig.h' or"
14870728a38Smrg      echo "$configure_deps."
14970728a38Smrg      program_details 'autoheader'
15070728a38Smrg      ;;
15170728a38Smrg    automake*)
15270728a38Smrg      echo "You should only need it if you modified 'Makefile.am' or"
15370728a38Smrg      echo "$configure_deps."
15470728a38Smrg      program_details 'automake'
15570728a38Smrg      ;;
15670728a38Smrg    aclocal*)
15770728a38Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
15870728a38Smrg      echo "$configure_deps."
15970728a38Smrg      program_details 'aclocal'
16070728a38Smrg      ;;
16170728a38Smrg   autom4te*)
16270728a38Smrg      echo "You might have modified some maintainer files that require"
16370728a38Smrg      echo "the 'autom4te' program to be rebuilt."
16470728a38Smrg      program_details 'autom4te'
16570728a38Smrg      ;;
16670728a38Smrg    bison*|yacc*)
16770728a38Smrg      echo "You should only need it if you modified a '.y' file."
16870728a38Smrg      echo "You may want to install the GNU Bison package:"
16970728a38Smrg      echo "<$gnu_software_URL/bison/>"
17070728a38Smrg      ;;
17170728a38Smrg    lex*|flex*)
17270728a38Smrg      echo "You should only need it if you modified a '.l' file."
17370728a38Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
17470728a38Smrg      echo "<$flex_URL>"
17570728a38Smrg      ;;
17670728a38Smrg    help2man*)
17770728a38Smrg      echo "You should only need it if you modified a dependency" \
17870728a38Smrg           "of a man page."
17970728a38Smrg      echo "You may want to install the GNU Help2man package:"
18070728a38Smrg      echo "<$gnu_software_URL/help2man/>"
18170728a38Smrg    ;;
18270728a38Smrg    makeinfo*)
18370728a38Smrg      echo "You should only need it if you modified a '.texi' file, or"
18470728a38Smrg      echo "any other file indirectly affecting the aspect of the manual."
18570728a38Smrg      echo "You might want to install the Texinfo package:"
18670728a38Smrg      echo "<$gnu_software_URL/texinfo/>"
18770728a38Smrg      echo "The spurious makeinfo call might also be the consequence of"
18870728a38Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
18970728a38Smrg      echo "want to install GNU make:"
19070728a38Smrg      echo "<$gnu_software_URL/make/>"
19170728a38Smrg      ;;
19270728a38Smrg    *)
19370728a38Smrg      echo "You might have modified some files without having the proper"
19470728a38Smrg      echo "tools for further handling them.  Check the 'README' file, it"
19570728a38Smrg      echo "often tells you about the needed prerequisites for installing"
19670728a38Smrg      echo "this package.  You may also peek at any GNU archive site, in"
19770728a38Smrg      echo "case some other package contains this missing '$1' program."
19870728a38Smrg      ;;
19970728a38Smrg  esac
20070728a38Smrg}
20170728a38Smrg
20270728a38Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
20370728a38Smrg                       -e '2,$s/^/         /' >&2
20470728a38Smrg
20570728a38Smrg# Propagate the correct exit status (expected to be 127 for a program
20670728a38Smrg# not found, 63 for a program that failed due to version mismatch).
20770728a38Smrgexit $st
2088c9fbc29Smrg
2098c9fbc29Smrg# Local variables:
21054cef2ddSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2118c9fbc29Smrg# time-stamp-start: "scriptversion="
2128c9fbc29Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21354cef2ddSmrg# time-stamp-time-zone: "UTC0"
2144e411241Smrg# time-stamp-end: "; # UTC"
2158c9fbc29Smrg# End:
216