1a850946eSmrg#! /bin/sh
29511053fSmrg# Common wrapper for a few potentially missing GNU programs.
370f7c90cSmrg
4da4b5163Smrgscriptversion=2018-03-07.03; # UTC
570f7c90cSmrg
6da4b5163Smrg# Copyright (C) 1996-2021 Free Software Foundation, Inc.
79511053fSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8a850946eSmrg
9a850946eSmrg# This program is free software; you can redistribute it and/or modify
10a850946eSmrg# it under the terms of the GNU General Public License as published by
11a850946eSmrg# the Free Software Foundation; either version 2, or (at your option)
12a850946eSmrg# any later version.
13a850946eSmrg
14a850946eSmrg# This program is distributed in the hope that it will be useful,
15a850946eSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16a850946eSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a850946eSmrg# GNU General Public License for more details.
18a850946eSmrg
19a850946eSmrg# You should have received a copy of the GNU General Public License
20da4b5163Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21a850946eSmrg
22a850946eSmrg# As a special exception to the GNU General Public License, if you
23a850946eSmrg# distribute this file as part of a program that contains a
24a850946eSmrg# configuration script generated by Autoconf, you may include it under
25a850946eSmrg# the same distribution terms that you use for the rest of that program.
26a850946eSmrg
27a850946eSmrgif test $# -eq 0; then
289511053fSmrg  echo 1>&2 "Try '$0 --help' for more information"
29a850946eSmrg  exit 1
30a850946eSmrgfi
31a850946eSmrg
329511053fSmrgcase $1 in
33a850946eSmrg
349511053fSmrg  --is-lightweight)
359511053fSmrg    # Used by our autoconf macros to check whether the available missing
369511053fSmrg    # script is modern enough.
379511053fSmrg    exit 0
389511053fSmrg    ;;
3970f7c90cSmrg
409511053fSmrg  --run)
419511053fSmrg    # Back-compat with the calling convention used by older automake.
429511053fSmrg    shift
439511053fSmrg    ;;
44a850946eSmrg
45a850946eSmrg  -h|--h|--he|--hel|--help)
46a850946eSmrg    echo "\
47a850946eSmrg$0 [OPTION]... PROGRAM [ARGUMENT]...
48a850946eSmrg
499511053fSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
509511053fSmrgto PROGRAM being missing or too old.
51a850946eSmrg
52a850946eSmrgOptions:
53a850946eSmrg  -h, --help      display this help and exit
54a850946eSmrg  -v, --version   output version information and exit
55a850946eSmrg
56a850946eSmrgSupported PROGRAM values:
579511053fSmrg  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
589511053fSmrg  bison     yacc      flex         lex       help2man
5970f7c90cSmrg
609511053fSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
619511053fSmrg'g' are ignored when checking the name.
6270f7c90cSmrg
6370f7c90cSmrgSend bug reports to <bug-automake@gnu.org>."
6470f7c90cSmrg    exit $?
65a850946eSmrg    ;;
66a850946eSmrg
67a850946eSmrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6870f7c90cSmrg    echo "missing $scriptversion (GNU Automake)"
6970f7c90cSmrg    exit $?
70a850946eSmrg    ;;
71a850946eSmrg
72a850946eSmrg  -*)
739511053fSmrg    echo 1>&2 "$0: unknown '$1' option"
749511053fSmrg    echo 1>&2 "Try '$0 --help' for more information"
75a850946eSmrg    exit 1
76a850946eSmrg    ;;
77a850946eSmrg
7870f7c90cSmrgesac
7970f7c90cSmrg
809511053fSmrg# Run the given program, remember its exit status.
819511053fSmrg"$@"; st=$?
829511053fSmrg
839511053fSmrg# If it succeeded, we are done.
849511053fSmrgtest $st -eq 0 && exit 0
859511053fSmrg
869511053fSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
879511053fSmrg# passed; such an option is passed most likely to detect whether the
889511053fSmrg# program is present and works.
899511053fSmrgcase $2 in --version|--help) exit $st;; esac
909511053fSmrg
919511053fSmrg# Exit code 63 means version mismatch.  This often happens when the user
929511053fSmrg# tries to use an ancient version of a tool on a file that requires a
939511053fSmrg# minimum version.
949511053fSmrgif test $st -eq 63; then
959511053fSmrg  msg="probably too old"
969511053fSmrgelif test $st -eq 127; then
979511053fSmrg  # Program was missing.
989511053fSmrg  msg="missing on your system"
999511053fSmrgelse
1009511053fSmrg  # Program was found and executed, but failed.  Give up.
1019511053fSmrg  exit $st
1029511053fSmrgfi
103a850946eSmrg
104da4b5163Smrgperl_URL=https://www.perl.org/
105da4b5163Smrgflex_URL=https://github.com/westes/flex
106da4b5163Smrggnu_software_URL=https://www.gnu.org/software
1079511053fSmrg
1089511053fSmrgprogram_details ()
1099511053fSmrg{
1109511053fSmrg  case $1 in
1119511053fSmrg    aclocal|automake)
1129511053fSmrg      echo "The '$1' program is part of the GNU Automake package:"
1139511053fSmrg      echo "<$gnu_software_URL/automake>"
1149511053fSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1159511053fSmrg      echo "<$gnu_software_URL/autoconf>"
1169511053fSmrg      echo "<$gnu_software_URL/m4/>"
1179511053fSmrg      echo "<$perl_URL>"
1189511053fSmrg      ;;
1199511053fSmrg    autoconf|autom4te|autoheader)
1209511053fSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
1219511053fSmrg      echo "<$gnu_software_URL/autoconf/>"
1229511053fSmrg      echo "It also requires GNU m4 and Perl in order to run:"
1239511053fSmrg      echo "<$gnu_software_URL/m4/>"
1249511053fSmrg      echo "<$perl_URL>"
1259511053fSmrg      ;;
1269511053fSmrg  esac
1279511053fSmrg}
1289511053fSmrg
1299511053fSmrggive_advice ()
1309511053fSmrg{
1319511053fSmrg  # Normalize program name to check for.
1329511053fSmrg  normalized_program=`echo "$1" | sed '
1339511053fSmrg    s/^gnu-//; t
1349511053fSmrg    s/^gnu//; t
1359511053fSmrg    s/^g//; t'`
1369511053fSmrg
1379511053fSmrg  printf '%s\n' "'$1' is $msg."
1389511053fSmrg
1399511053fSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1409511053fSmrg  case $normalized_program in
1419511053fSmrg    autoconf*)
1429511053fSmrg      echo "You should only need it if you modified 'configure.ac',"
1439511053fSmrg      echo "or m4 files included by it."
1449511053fSmrg      program_details 'autoconf'
1459511053fSmrg      ;;
1469511053fSmrg    autoheader*)
1479511053fSmrg      echo "You should only need it if you modified 'acconfig.h' or"
1489511053fSmrg      echo "$configure_deps."
1499511053fSmrg      program_details 'autoheader'
1509511053fSmrg      ;;
1519511053fSmrg    automake*)
1529511053fSmrg      echo "You should only need it if you modified 'Makefile.am' or"
1539511053fSmrg      echo "$configure_deps."
1549511053fSmrg      program_details 'automake'
1559511053fSmrg      ;;
1569511053fSmrg    aclocal*)
1579511053fSmrg      echo "You should only need it if you modified 'acinclude.m4' or"
1589511053fSmrg      echo "$configure_deps."
1599511053fSmrg      program_details 'aclocal'
1609511053fSmrg      ;;
1619511053fSmrg   autom4te*)
1629511053fSmrg      echo "You might have modified some maintainer files that require"
163c44a0236Smrg      echo "the 'autom4te' program to be rebuilt."
1649511053fSmrg      program_details 'autom4te'
1659511053fSmrg      ;;
1669511053fSmrg    bison*|yacc*)
1679511053fSmrg      echo "You should only need it if you modified a '.y' file."
1689511053fSmrg      echo "You may want to install the GNU Bison package:"
1699511053fSmrg      echo "<$gnu_software_URL/bison/>"
1709511053fSmrg      ;;
1719511053fSmrg    lex*|flex*)
1729511053fSmrg      echo "You should only need it if you modified a '.l' file."
1739511053fSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1749511053fSmrg      echo "<$flex_URL>"
1759511053fSmrg      ;;
1769511053fSmrg    help2man*)
1779511053fSmrg      echo "You should only need it if you modified a dependency" \
1789511053fSmrg           "of a man page."
1799511053fSmrg      echo "You may want to install the GNU Help2man package:"
1809511053fSmrg      echo "<$gnu_software_URL/help2man/>"
1819511053fSmrg    ;;
1829511053fSmrg    makeinfo*)
1839511053fSmrg      echo "You should only need it if you modified a '.texi' file, or"
1849511053fSmrg      echo "any other file indirectly affecting the aspect of the manual."
1859511053fSmrg      echo "You might want to install the Texinfo package:"
1869511053fSmrg      echo "<$gnu_software_URL/texinfo/>"
1879511053fSmrg      echo "The spurious makeinfo call might also be the consequence of"
1889511053fSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1899511053fSmrg      echo "want to install GNU make:"
1909511053fSmrg      echo "<$gnu_software_URL/make/>"
1919511053fSmrg      ;;
1929511053fSmrg    *)
1939511053fSmrg      echo "You might have modified some files without having the proper"
1949511053fSmrg      echo "tools for further handling them.  Check the 'README' file, it"
1959511053fSmrg      echo "often tells you about the needed prerequisites for installing"
1969511053fSmrg      echo "this package.  You may also peek at any GNU archive site, in"
1979511053fSmrg      echo "case some other package contains this missing '$1' program."
1989511053fSmrg      ;;
1999511053fSmrg  esac
2009511053fSmrg}
2019511053fSmrg
2029511053fSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2039511053fSmrg                       -e '2,$s/^/         /' >&2
2049511053fSmrg
2059511053fSmrg# Propagate the correct exit status (expected to be 127 for a program
2069511053fSmrg# not found, 63 for a program that failed due to version mismatch).
2079511053fSmrgexit $st
20870f7c90cSmrg
20970f7c90cSmrg# Local variables:
210da4b5163Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
21170f7c90cSmrg# time-stamp-start: "scriptversion="
21270f7c90cSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
213da4b5163Smrg# time-stamp-time-zone: "UTC0"
21470f7c90cSmrg# time-stamp-end: "; # UTC"
21570f7c90cSmrg# End:
216