16b526288Smrg#!/bin/sh
26b526288Smrg# Common wrapper for a few potentially missing GNU programs.
341b2f0bdSmrg
46b526288Smrgscriptversion=2016-01-11.22; # UTC
541b2f0bdSmrg
66b526288Smrg# Copyright (C) 1996-2017 Free Software Foundation, Inc.
76b526288Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
841b2f0bdSmrg
941b2f0bdSmrg# This program is free software; you can redistribute it and/or modify
1041b2f0bdSmrg# it under the terms of the GNU General Public License as published by
1141b2f0bdSmrg# the Free Software Foundation; either version 2, or (at your option)
1241b2f0bdSmrg# any later version.
1341b2f0bdSmrg
1441b2f0bdSmrg# This program is distributed in the hope that it will be useful,
1541b2f0bdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1641b2f0bdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1741b2f0bdSmrg# GNU General Public License for more details.
1841b2f0bdSmrg
1941b2f0bdSmrg# You should have received a copy of the GNU General Public License
2011245024Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2141b2f0bdSmrg
2241b2f0bdSmrg# As a special exception to the GNU General Public License, if you
2341b2f0bdSmrg# distribute this file as part of a program that contains a
2441b2f0bdSmrg# configuration script generated by Autoconf, you may include it under
2541b2f0bdSmrg# the same distribution terms that you use for the rest of that program.
2641b2f0bdSmrg
2741b2f0bdSmrgif test $# -eq 0; then
286b526288Smrg  echo 1>&2 "Try '$0 --help' for more information"
2941b2f0bdSmrg  exit 1
3041b2f0bdSmrgfi
3141b2f0bdSmrg
326b526288Smrgcase $1 in
3341b2f0bdSmrg
346b526288Smrg  --is-lightweight)
356b526288Smrg    # Used by our autoconf macros to check whether the available missing
366b526288Smrg    # script is modern enough.
376b526288Smrg    exit 0
386b526288Smrg    ;;
3941b2f0bdSmrg
406b526288Smrg  --run)
416b526288Smrg    # Back-compat with the calling convention used by older automake.
426b526288Smrg    shift
436b526288Smrg    ;;
4441b2f0bdSmrg
4541b2f0bdSmrg  -h|--h|--he|--hel|--help)
4641b2f0bdSmrg    echo "\
4741b2f0bdSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
4841b2f0bdSmrg
496b526288SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
506b526288Smrgto PROGRAM being missing or too old.
5141b2f0bdSmrg
5241b2f0bdSmrgOptions:
5341b2f0bdSmrg  -h, --help      display this help and exit
5441b2f0bdSmrg  -v, --version   output version information and exit
5541b2f0bdSmrg
5641b2f0bdSmrgSupported PROGRAM values:
576b526288Smrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
586b526288Smrg  bison     yacc      flex         lex       help2man
5941b2f0bdSmrg
606b526288SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
616b526288Smrg'g' are ignored when checking the name.
6211245024Smrg
6341b2f0bdSmrgSend bug reports to <bug-automake@gnu.org>."
6441b2f0bdSmrg    exit $?
6541b2f0bdSmrg    ;;
6641b2f0bdSmrg
6741b2f0bdSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6841b2f0bdSmrg    echo "missing $scriptversion (GNU Automake)"
6941b2f0bdSmrg    exit $?
7041b2f0bdSmrg    ;;
7141b2f0bdSmrg
7241b2f0bdSmrg  -*)
736b526288Smrg    echo 1>&2 "$0: unknown '$1' option"
746b526288Smrg    echo 1>&2 "Try '$0 --help' for more information"
7541b2f0bdSmrg    exit 1
7641b2f0bdSmrg    ;;
7741b2f0bdSmrg
7841b2f0bdSmrgesac
7941b2f0bdSmrg
806b526288Smrg# Run the given program, remember its exit status.
816b526288Smrg"$@"; st=$?
826b526288Smrg
836b526288Smrg# If it succeeded, we are done.
846b526288Smrgtest $st -eq 0 && exit 0
856b526288Smrg
866b526288Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
876b526288Smrg# passed; such an option is passed most likely to detect whether the
886b526288Smrg# program is present and works.
896b526288Smrgcase $2 in --version|--help) exit $st;; esac
906b526288Smrg
916b526288Smrg# Exit code 63 means version mismatch.  This often happens when the user
926b526288Smrg# tries to use an ancient version of a tool on a file that requires a
936b526288Smrg# minimum version.
946b526288Smrgif test $st -eq 63; then
956b526288Smrg  msg="probably too old"
966b526288Smrgelif test $st -eq 127; then
976b526288Smrg  # Program was missing.
986b526288Smrg  msg="missing on your system"
996b526288Smrgelse
1006b526288Smrg  # Program was found and executed, but failed.  Give up.
1016b526288Smrg  exit $st
1026b526288Smrgfi
10341b2f0bdSmrg
1046b526288Smrgperl_URL=http://www.perl.org/
1056b526288Smrgflex_URL=http://flex.sourceforge.net/
1066b526288Smrggnu_software_URL=http://www.gnu.org/software
1076b526288Smrg
1086b526288Smrgprogram_details ()
1096b526288Smrg{
1106b526288Smrg  case $1 in
1116b526288Smrg    aclocal|automake)
1126b526288Smrg      echo "The '$1' program is part of the GNU Automake package:"
1136b526288Smrg      echo "<$gnu_software_URL/automake>"
1146b526288Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1156b526288Smrg      echo "<$gnu_software_URL/autoconf>"
1166b526288Smrg      echo "<$gnu_software_URL/m4/>"
1176b526288Smrg      echo "<$perl_URL>"
1186b526288Smrg      ;;
1196b526288Smrg    autoconf|autom4te|autoheader)
1206b526288Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1216b526288Smrg      echo "<$gnu_software_URL/autoconf/>"
1226b526288Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1236b526288Smrg      echo "<$gnu_software_URL/m4/>"
1246b526288Smrg      echo "<$perl_URL>"
1256b526288Smrg      ;;
1266b526288Smrg  esac
1276b526288Smrg}
1286b526288Smrg
1296b526288Smrggive_advice ()
1306b526288Smrg{
1316b526288Smrg  # Normalize program name to check for.
1326b526288Smrg  normalized_program=`echo "$1" | sed '
1336b526288Smrg    s/^gnu-//; t
1346b526288Smrg    s/^gnu//; t
1356b526288Smrg    s/^g//; t'`
1366b526288Smrg
1376b526288Smrg  printf '%s\n' "'$1' is $msg."
1386b526288Smrg
1396b526288Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1406b526288Smrg  case $normalized_program in
1416b526288Smrg    autoconf*)
1426b526288Smrg      echo "You should only need it if you modified 'configure.ac',"
1436b526288Smrg      echo "or m4 files included by it."
1446b526288Smrg      program_details 'autoconf'
1456b526288Smrg      ;;
1466b526288Smrg    autoheader*)
1476b526288Smrg      echo "You should only need it if you modified 'acconfig.h' or"
1486b526288Smrg      echo "$configure_deps."
1496b526288Smrg      program_details 'autoheader'
1506b526288Smrg      ;;
1516b526288Smrg    automake*)
1526b526288Smrg      echo "You should only need it if you modified 'Makefile.am' or"
1536b526288Smrg      echo "$configure_deps."
1546b526288Smrg      program_details 'automake'
1556b526288Smrg      ;;
1566b526288Smrg    aclocal*)
1576b526288Smrg      echo "You should only need it if you modified 'acinclude.m4' or"
1586b526288Smrg      echo "$configure_deps."
1596b526288Smrg      program_details 'aclocal'
1606b526288Smrg      ;;
1616b526288Smrg   autom4te*)
1626b526288Smrg      echo "You might have modified some maintainer files that require"
1636b526288Smrg      echo "the 'autom4te' program to be rebuilt."
1646b526288Smrg      program_details 'autom4te'
1656b526288Smrg      ;;
1666b526288Smrg    bison*|yacc*)
1676b526288Smrg      echo "You should only need it if you modified a '.y' file."
1686b526288Smrg      echo "You may want to install the GNU Bison package:"
1696b526288Smrg      echo "<$gnu_software_URL/bison/>"
1706b526288Smrg      ;;
1716b526288Smrg    lex*|flex*)
1726b526288Smrg      echo "You should only need it if you modified a '.l' file."
1736b526288Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1746b526288Smrg      echo "<$flex_URL>"
1756b526288Smrg      ;;
1766b526288Smrg    help2man*)
1776b526288Smrg      echo "You should only need it if you modified a dependency" \
1786b526288Smrg           "of a man page."
1796b526288Smrg      echo "You may want to install the GNU Help2man package:"
1806b526288Smrg      echo "<$gnu_software_URL/help2man/>"
1816b526288Smrg    ;;
1826b526288Smrg    makeinfo*)
1836b526288Smrg      echo "You should only need it if you modified a '.texi' file, or"
1846b526288Smrg      echo "any other file indirectly affecting the aspect of the manual."
1856b526288Smrg      echo "You might want to install the Texinfo package:"
1866b526288Smrg      echo "<$gnu_software_URL/texinfo/>"
1876b526288Smrg      echo "The spurious makeinfo call might also be the consequence of"
1886b526288Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1896b526288Smrg      echo "want to install GNU make:"
1906b526288Smrg      echo "<$gnu_software_URL/make/>"
1916b526288Smrg      ;;
1926b526288Smrg    *)
1936b526288Smrg      echo "You might have modified some files without having the proper"
1946b526288Smrg      echo "tools for further handling them.  Check the 'README' file, it"
1956b526288Smrg      echo "often tells you about the needed prerequisites for installing"
1966b526288Smrg      echo "this package.  You may also peek at any GNU archive site, in"
1976b526288Smrg      echo "case some other package contains this missing '$1' program."
1986b526288Smrg      ;;
1996b526288Smrg  esac
2006b526288Smrg}
2016b526288Smrg
2026b526288Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2036b526288Smrg                       -e '2,$s/^/         /' >&2
2046b526288Smrg
2056b526288Smrg# Propagate the correct exit status (expected to be 127 for a program
2066b526288Smrg# not found, 63 for a program that failed due to version mismatch).
2076b526288Smrgexit $st
20841b2f0bdSmrg
20941b2f0bdSmrg# Local variables:
21041b2f0bdSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
21141b2f0bdSmrg# time-stamp-start: "scriptversion="
21241b2f0bdSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2136b526288Smrg# time-stamp-time-zone: "UTC0"
21411245024Smrg# time-stamp-end: "; # UTC"
21541b2f0bdSmrg# End:
216