1ed029a5fSmrg#! /bin/sh
25d10e53fSmrg# Common wrapper for a few potentially missing GNU programs.
3dd519f38Smrg
45d10e53fSmrgscriptversion=2018-03-07.03; # UTC
5dd519f38Smrg
65d10e53fSmrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
75d10e53fSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8ed029a5fSmrg
9ed029a5fSmrg# This program is free software; you can redistribute it and/or modify
10ed029a5fSmrg# it under the terms of the GNU General Public License as published by
11ed029a5fSmrg# the Free Software Foundation; either version 2, or (at your option)
12ed029a5fSmrg# any later version.
13ed029a5fSmrg
14ed029a5fSmrg# This program is distributed in the hope that it will be useful,
15ed029a5fSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16ed029a5fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17ed029a5fSmrg# GNU General Public License for more details.
18ed029a5fSmrg
19ed029a5fSmrg# You should have received a copy of the GNU General Public License
205d10e53fSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21ed029a5fSmrg
22ed029a5fSmrg# As a special exception to the GNU General Public License, if you
23ed029a5fSmrg# distribute this file as part of a program that contains a
24ed029a5fSmrg# configuration script generated by Autoconf, you may include it under
25ed029a5fSmrg# the same distribution terms that you use for the rest of that program.
26ed029a5fSmrg
27ed029a5fSmrgif test $# -eq 0; then
285d10e53fSmrg  echo 1>&2 "Try '$0 --help' for more information"
29ed029a5fSmrg  exit 1
30ed029a5fSmrgfi
31ed029a5fSmrg
325d10e53fSmrgcase $1 in
33ed029a5fSmrg
345d10e53fSmrg  --is-lightweight)
355d10e53fSmrg    # Used by our autoconf macros to check whether the available missing
365d10e53fSmrg    # script is modern enough.
375d10e53fSmrg    exit 0
385d10e53fSmrg    ;;
39dd519f38Smrg
405d10e53fSmrg  --run)
415d10e53fSmrg    # Back-compat with the calling convention used by older automake.
425d10e53fSmrg    shift
435d10e53fSmrg    ;;
44ed029a5fSmrg
45ed029a5fSmrg  -h|--h|--he|--hel|--help)
46ed029a5fSmrg    echo "\
47ed029a5fSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48ed029a5fSmrg
495d10e53fSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
505d10e53fSmrgto PROGRAM being missing or too old.
51ed029a5fSmrg
52ed029a5fSmrgOptions:
53ed029a5fSmrg  -h, --help      display this help and exit
54ed029a5fSmrg  -v, --version   output version information and exit
55ed029a5fSmrg
56ed029a5fSmrgSupported PROGRAM values:
575d10e53fSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
585d10e53fSmrg  bison     yacc      flex         lex       help2man
59dd519f38Smrg
605d10e53fSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
615d10e53fSmrg'g' are ignored when checking the name.
62dd519f38Smrg
63dd519f38SmrgSend bug reports to <bug-automake@gnu.org>."
64dd519f38Smrg    exit $?
65ed029a5fSmrg    ;;
66ed029a5fSmrg
67ed029a5fSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68dd519f38Smrg    echo "missing $scriptversion (GNU Automake)"
69dd519f38Smrg    exit $?
70ed029a5fSmrg    ;;
71ed029a5fSmrg
72ed029a5fSmrg  -*)
735d10e53fSmrg    echo 1>&2 "$0: unknown '$1' option"
745d10e53fSmrg    echo 1>&2 "Try '$0 --help' for more information"
75ed029a5fSmrg    exit 1
76ed029a5fSmrg    ;;
77ed029a5fSmrg
78dd519f38Smrgesac
79dd519f38Smrg
805d10e53fSmrg# Run the given program, remember its exit status.
815d10e53fSmrg"$@"; st=$?
825d10e53fSmrg
835d10e53fSmrg# If it succeeded, we are done.
845d10e53fSmrgtest $st -eq 0 && exit 0
855d10e53fSmrg
865d10e53fSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
875d10e53fSmrg# passed; such an option is passed most likely to detect whether the
885d10e53fSmrg# program is present and works.
895d10e53fSmrgcase $2 in --version|--help) exit $st;; esac
905d10e53fSmrg
915d10e53fSmrg# Exit code 63 means version mismatch.  This often happens when the user
925d10e53fSmrg# tries to use an ancient version of a tool on a file that requires a
935d10e53fSmrg# minimum version.
945d10e53fSmrgif test $st -eq 63; then
955d10e53fSmrg  msg="probably too old"
965d10e53fSmrgelif test $st -eq 127; then
975d10e53fSmrg  # Program was missing.
985d10e53fSmrg  msg="missing on your system"
995d10e53fSmrgelse
1005d10e53fSmrg  # Program was found and executed, but failed.  Give up.
1015d10e53fSmrg  exit $st
1025d10e53fSmrgfi
103ed029a5fSmrg
1045d10e53fSmrgperl_URL=https://www.perl.org/
1055d10e53fSmrgflex_URL=https://github.com/westes/flex
1065d10e53fSmrggnu_software_URL=https://www.gnu.org/software
1075d10e53fSmrg
1085d10e53fSmrgprogram_details ()
1095d10e53fSmrg{
1105d10e53fSmrg  case $1 in
1115d10e53fSmrg    aclocal|automake)
1125d10e53fSmrg      echo "The '$1' program is part of the GNU Automake package:"
1135d10e53fSmrg      echo "<$gnu_software_URL/automake>"
1145d10e53fSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1155d10e53fSmrg      echo "<$gnu_software_URL/autoconf>"
1165d10e53fSmrg      echo "<$gnu_software_URL/m4/>"
1175d10e53fSmrg      echo "<$perl_URL>"
1185d10e53fSmrg      ;;
1195d10e53fSmrg    autoconf|autom4te|autoheader)
1205d10e53fSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
1215d10e53fSmrg      echo "<$gnu_software_URL/autoconf/>"
1225d10e53fSmrg      echo "It also requires GNU m4 and Perl in order to run:"
1235d10e53fSmrg      echo "<$gnu_software_URL/m4/>"
1245d10e53fSmrg      echo "<$perl_URL>"
1255d10e53fSmrg      ;;
1265d10e53fSmrg  esac
1275d10e53fSmrg}
1285d10e53fSmrg
1295d10e53fSmrggive_advice ()
1305d10e53fSmrg{
1315d10e53fSmrg  # Normalize program name to check for.
1325d10e53fSmrg  normalized_program=`echo "$1" | sed '
1335d10e53fSmrg    s/^gnu-//; t
1345d10e53fSmrg    s/^gnu//; t
1355d10e53fSmrg    s/^g//; t'`
1365d10e53fSmrg
1375d10e53fSmrg  printf '%s\n' "'$1' is $msg."
1385d10e53fSmrg
1395d10e53fSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1405d10e53fSmrg  case $normalized_program in
1415d10e53fSmrg    autoconf*)
1425d10e53fSmrg      echo "You should only need it if you modified 'configure.ac',"
1435d10e53fSmrg      echo "or m4 files included by it."
1445d10e53fSmrg      program_details 'autoconf'
1455d10e53fSmrg      ;;
1465d10e53fSmrg    autoheader*)
1475d10e53fSmrg      echo "You should only need it if you modified 'acconfig.h' or"
1485d10e53fSmrg      echo "$configure_deps."
1495d10e53fSmrg      program_details 'autoheader'
1505d10e53fSmrg      ;;
1515d10e53fSmrg    automake*)
1525d10e53fSmrg      echo "You should only need it if you modified 'Makefile.am' or"
1535d10e53fSmrg      echo "$configure_deps."
1545d10e53fSmrg      program_details 'automake'
1555d10e53fSmrg      ;;
1565d10e53fSmrg    aclocal*)
1575d10e53fSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
1585d10e53fSmrg      echo "$configure_deps."
1595d10e53fSmrg      program_details 'aclocal'
1605d10e53fSmrg      ;;
1615d10e53fSmrg   autom4te*)
1625d10e53fSmrg      echo "You might have modified some maintainer files that require"
1635d10e53fSmrg      echo "the 'autom4te' program to be rebuilt."
1645d10e53fSmrg      program_details 'autom4te'
1655d10e53fSmrg      ;;
1665d10e53fSmrg    bison*|yacc*)
1675d10e53fSmrg      echo "You should only need it if you modified a '.y' file."
1685d10e53fSmrg      echo "You may want to install the GNU Bison package:"
1695d10e53fSmrg      echo "<$gnu_software_URL/bison/>"
1705d10e53fSmrg      ;;
1715d10e53fSmrg    lex*|flex*)
1725d10e53fSmrg      echo "You should only need it if you modified a '.l' file."
1735d10e53fSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1745d10e53fSmrg      echo "<$flex_URL>"
1755d10e53fSmrg      ;;
1765d10e53fSmrg    help2man*)
1775d10e53fSmrg      echo "You should only need it if you modified a dependency" \
1785d10e53fSmrg           "of a man page."
1795d10e53fSmrg      echo "You may want to install the GNU Help2man package:"
1805d10e53fSmrg      echo "<$gnu_software_URL/help2man/>"
1815d10e53fSmrg    ;;
1825d10e53fSmrg    makeinfo*)
1835d10e53fSmrg      echo "You should only need it if you modified a '.texi' file, or"
1845d10e53fSmrg      echo "any other file indirectly affecting the aspect of the manual."
1855d10e53fSmrg      echo "You might want to install the Texinfo package:"
1865d10e53fSmrg      echo "<$gnu_software_URL/texinfo/>"
1875d10e53fSmrg      echo "The spurious makeinfo call might also be the consequence of"
1885d10e53fSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1895d10e53fSmrg      echo "want to install GNU make:"
1905d10e53fSmrg      echo "<$gnu_software_URL/make/>"
1915d10e53fSmrg      ;;
1925d10e53fSmrg    *)
1935d10e53fSmrg      echo "You might have modified some files without having the proper"
1945d10e53fSmrg      echo "tools for further handling them.  Check the 'README' file, it"
1955d10e53fSmrg      echo "often tells you about the needed prerequisites for installing"
1965d10e53fSmrg      echo "this package.  You may also peek at any GNU archive site, in"
1975d10e53fSmrg      echo "case some other package contains this missing '$1' program."
1985d10e53fSmrg      ;;
1995d10e53fSmrg  esac
2005d10e53fSmrg}
2015d10e53fSmrg
2025d10e53fSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2035d10e53fSmrg                       -e '2,$s/^/         /' >&2
2045d10e53fSmrg
2055d10e53fSmrg# Propagate the correct exit status (expected to be 127 for a program
2065d10e53fSmrg# not found, 63 for a program that failed due to version mismatch).
2075d10e53fSmrgexit $st
208dd519f38Smrg
209dd519f38Smrg# Local variables:
2105d10e53fSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
211dd519f38Smrg# time-stamp-start: "scriptversion="
212dd519f38Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2135d10e53fSmrg# time-stamp-time-zone: "UTC0"
214dd519f38Smrg# time-stamp-end: "; # UTC"
215dd519f38Smrg# End:
216