1c06b6b69Smrg#! /bin/sh
27a5ec427Smrg# Common wrapper for a few potentially missing GNU programs.
3c06b6b69Smrg
444256261Smrgscriptversion=2018-03-07.03; # UTC
5c06b6b69Smrg
644256261Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
77a5ec427Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8c06b6b69Smrg
9c06b6b69Smrg# This program is free software; you can redistribute it and/or modify
10c06b6b69Smrg# it under the terms of the GNU General Public License as published by
11c06b6b69Smrg# the Free Software Foundation; either version 2, or (at your option)
12c06b6b69Smrg# any later version.
13c06b6b69Smrg
14c06b6b69Smrg# This program is distributed in the hope that it will be useful,
15c06b6b69Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16c06b6b69Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17c06b6b69Smrg# GNU General Public License for more details.
18c06b6b69Smrg
19c06b6b69Smrg# You should have received a copy of the GNU General Public License
2044256261Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21c06b6b69Smrg
22c06b6b69Smrg# As a special exception to the GNU General Public License, if you
23c06b6b69Smrg# distribute this file as part of a program that contains a
24c06b6b69Smrg# configuration script generated by Autoconf, you may include it under
25c06b6b69Smrg# the same distribution terms that you use for the rest of that program.
26c06b6b69Smrg
27c06b6b69Smrgif test $# -eq 0; then
287a5ec427Smrg  echo 1>&2 "Try '$0 --help' for more information"
29c06b6b69Smrg  exit 1
30c06b6b69Smrgfi
31c06b6b69Smrg
327a5ec427Smrgcase $1 in
33c06b6b69Smrg
347a5ec427Smrg  --is-lightweight)
357a5ec427Smrg    # Used by our autoconf macros to check whether the available missing
367a5ec427Smrg    # script is modern enough.
377a5ec427Smrg    exit 0
387a5ec427Smrg    ;;
39c06b6b69Smrg
407a5ec427Smrg  --run)
417a5ec427Smrg    # Back-compat with the calling convention used by older automake.
427a5ec427Smrg    shift
437a5ec427Smrg    ;;
44c06b6b69Smrg
45c06b6b69Smrg  -h|--h|--he|--hel|--help)
46c06b6b69Smrg    echo "\
47c06b6b69Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48c06b6b69Smrg
497a5ec427SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
507a5ec427Smrgto PROGRAM being missing or too old.
51c06b6b69Smrg
52c06b6b69SmrgOptions:
53c06b6b69Smrg  -h, --help      display this help and exit
54c06b6b69Smrg  -v, --version   output version information and exit
55c06b6b69Smrg
56c06b6b69SmrgSupported PROGRAM values:
577a5ec427Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
587a5ec427Smrg  bison     yacc      flex         lex       help2man
59c06b6b69Smrg
607a5ec427SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
617a5ec427Smrg'g' are ignored when checking the name.
627d17d341Smrg
63c06b6b69SmrgSend bug reports to <bug-automake@gnu.org>."
64c06b6b69Smrg    exit $?
65c06b6b69Smrg    ;;
66c06b6b69Smrg
67c06b6b69Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68c06b6b69Smrg    echo "missing $scriptversion (GNU Automake)"
69c06b6b69Smrg    exit $?
70c06b6b69Smrg    ;;
71c06b6b69Smrg
72c06b6b69Smrg  -*)
737a5ec427Smrg    echo 1>&2 "$0: unknown '$1' option"
747a5ec427Smrg    echo 1>&2 "Try '$0 --help' for more information"
75c06b6b69Smrg    exit 1
76c06b6b69Smrg    ;;
77c06b6b69Smrg
78c06b6b69Smrgesac
79c06b6b69Smrg
807a5ec427Smrg# Run the given program, remember its exit status.
817a5ec427Smrg"$@"; st=$?
827a5ec427Smrg
837a5ec427Smrg# If it succeeded, we are done.
847a5ec427Smrgtest $st -eq 0 && exit 0
857a5ec427Smrg
867a5ec427Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
877a5ec427Smrg# passed; such an option is passed most likely to detect whether the
887a5ec427Smrg# program is present and works.
897a5ec427Smrgcase $2 in --version|--help) exit $st;; esac
907a5ec427Smrg
917a5ec427Smrg# Exit code 63 means version mismatch.  This often happens when the user
927a5ec427Smrg# tries to use an ancient version of a tool on a file that requires a
937a5ec427Smrg# minimum version.
947a5ec427Smrgif test $st -eq 63; then
957a5ec427Smrg  msg="probably too old"
967a5ec427Smrgelif test $st -eq 127; then
977a5ec427Smrg  # Program was missing.
987a5ec427Smrg  msg="missing on your system"
997a5ec427Smrgelse
1007a5ec427Smrg  # Program was found and executed, but failed.  Give up.
1017a5ec427Smrg  exit $st
1027a5ec427Smrgfi
103c06b6b69Smrg
10444256261Smrgperl_URL=https://www.perl.org/
10544256261Smrgflex_URL=https://github.com/westes/flex
10644256261Smrggnu_software_URL=https://www.gnu.org/software
1077a5ec427Smrg
1087a5ec427Smrgprogram_details ()
1097a5ec427Smrg{
1107a5ec427Smrg  case $1 in
1117a5ec427Smrg    aclocal|automake)
1127a5ec427Smrg      echo "The '$1' program is part of the GNU Automake package:"
1137a5ec427Smrg      echo "<$gnu_software_URL/automake>"
1147a5ec427Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1157a5ec427Smrg      echo "<$gnu_software_URL/autoconf>"
1167a5ec427Smrg      echo "<$gnu_software_URL/m4/>"
1177a5ec427Smrg      echo "<$perl_URL>"
1187a5ec427Smrg      ;;
1197a5ec427Smrg    autoconf|autom4te|autoheader)
1207a5ec427Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1217a5ec427Smrg      echo "<$gnu_software_URL/autoconf/>"
1227a5ec427Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1237a5ec427Smrg      echo "<$gnu_software_URL/m4/>"
1247a5ec427Smrg      echo "<$perl_URL>"
1257a5ec427Smrg      ;;
1267a5ec427Smrg  esac
1277a5ec427Smrg}
1287a5ec427Smrg
1297a5ec427Smrggive_advice ()
1307a5ec427Smrg{
1317a5ec427Smrg  # Normalize program name to check for.
1327a5ec427Smrg  normalized_program=`echo "$1" | sed '
1337a5ec427Smrg    s/^gnu-//; t
1347a5ec427Smrg    s/^gnu//; t
1357a5ec427Smrg    s/^g//; t'`
1367a5ec427Smrg
1377a5ec427Smrg  printf '%s\n' "'$1' is $msg."
1387a5ec427Smrg
1397a5ec427Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1407a5ec427Smrg  case $normalized_program in
1417a5ec427Smrg    autoconf*)
1427a5ec427Smrg      echo "You should only need it if you modified 'configure.ac',"
1437a5ec427Smrg      echo "or m4 files included by it."
1447a5ec427Smrg      program_details 'autoconf'
1457a5ec427Smrg      ;;
1467a5ec427Smrg    autoheader*)
1477a5ec427Smrg      echo "You should only need it if you modified 'acconfig.h' or"
1487a5ec427Smrg      echo "$configure_deps."
1497a5ec427Smrg      program_details 'autoheader'
1507a5ec427Smrg      ;;
1517a5ec427Smrg    automake*)
1527a5ec427Smrg      echo "You should only need it if you modified 'Makefile.am' or"
1537a5ec427Smrg      echo "$configure_deps."
1547a5ec427Smrg      program_details 'automake'
1557a5ec427Smrg      ;;
1567a5ec427Smrg    aclocal*)
1577a5ec427Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
1587a5ec427Smrg      echo "$configure_deps."
1597a5ec427Smrg      program_details 'aclocal'
1607a5ec427Smrg      ;;
1617a5ec427Smrg   autom4te*)
1627a5ec427Smrg      echo "You might have modified some maintainer files that require"
1637a5ec427Smrg      echo "the 'autom4te' program to be rebuilt."
1647a5ec427Smrg      program_details 'autom4te'
1657a5ec427Smrg      ;;
1667a5ec427Smrg    bison*|yacc*)
1677a5ec427Smrg      echo "You should only need it if you modified a '.y' file."
1687a5ec427Smrg      echo "You may want to install the GNU Bison package:"
1697a5ec427Smrg      echo "<$gnu_software_URL/bison/>"
1707a5ec427Smrg      ;;
1717a5ec427Smrg    lex*|flex*)
1727a5ec427Smrg      echo "You should only need it if you modified a '.l' file."
1737a5ec427Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1747a5ec427Smrg      echo "<$flex_URL>"
1757a5ec427Smrg      ;;
1767a5ec427Smrg    help2man*)
1777a5ec427Smrg      echo "You should only need it if you modified a dependency" \
1787a5ec427Smrg           "of a man page."
1797a5ec427Smrg      echo "You may want to install the GNU Help2man package:"
1807a5ec427Smrg      echo "<$gnu_software_URL/help2man/>"
181c06b6b69Smrg    ;;
1827a5ec427Smrg    makeinfo*)
1837a5ec427Smrg      echo "You should only need it if you modified a '.texi' file, or"
1847a5ec427Smrg      echo "any other file indirectly affecting the aspect of the manual."
1857a5ec427Smrg      echo "You might want to install the Texinfo package:"
1867a5ec427Smrg      echo "<$gnu_software_URL/texinfo/>"
1877a5ec427Smrg      echo "The spurious makeinfo call might also be the consequence of"
1887a5ec427Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1897a5ec427Smrg      echo "want to install GNU make:"
1907a5ec427Smrg      echo "<$gnu_software_URL/make/>"
1917a5ec427Smrg      ;;
1927a5ec427Smrg    *)
1937a5ec427Smrg      echo "You might have modified some files without having the proper"
1947a5ec427Smrg      echo "tools for further handling them.  Check the 'README' file, it"
1957a5ec427Smrg      echo "often tells you about the needed prerequisites for installing"
1967a5ec427Smrg      echo "this package.  You may also peek at any GNU archive site, in"
1977a5ec427Smrg      echo "case some other package contains this missing '$1' program."
1987a5ec427Smrg      ;;
1997a5ec427Smrg  esac
2007a5ec427Smrg}
2017a5ec427Smrg
2027a5ec427Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2037a5ec427Smrg                       -e '2,$s/^/         /' >&2
2047a5ec427Smrg
2057a5ec427Smrg# Propagate the correct exit status (expected to be 127 for a program
2067a5ec427Smrg# not found, 63 for a program that failed due to version mismatch).
2077a5ec427Smrgexit $st
208c06b6b69Smrg
209c06b6b69Smrg# Local variables:
21044256261Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
211c06b6b69Smrg# time-stamp-start: "scriptversion="
212c06b6b69Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
21344256261Smrg# time-stamp-time-zone: "UTC0"
2147d17d341Smrg# time-stamp-end: "; # UTC"
215c06b6b69Smrg# End:
216