1ea148d1dSmrg#! /bin/sh
2d3173433Smrg# Common wrapper for a few potentially missing GNU and other programs.
343f32c10Smrg
4d3173433Smrgscriptversion=2024-06-07.14; # UTC
543f32c10Smrg
6d3173433Smrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
7d3173433Smrg
8d3173433Smrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
96ef05171Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
1043f32c10Smrg
1143f32c10Smrg# This program is free software; you can redistribute it and/or modify
1243f32c10Smrg# it under the terms of the GNU General Public License as published by
1343f32c10Smrg# the Free Software Foundation; either version 2, or (at your option)
1443f32c10Smrg# any later version.
1543f32c10Smrg
1643f32c10Smrg# This program is distributed in the hope that it will be useful,
1743f32c10Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1843f32c10Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1943f32c10Smrg# GNU General Public License for more details.
2043f32c10Smrg
2143f32c10Smrg# You should have received a copy of the GNU General Public License
22ea148d1dSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
2343f32c10Smrg
2443f32c10Smrg# As a special exception to the GNU General Public License, if you
2543f32c10Smrg# distribute this file as part of a program that contains a
2643f32c10Smrg# configuration script generated by Autoconf, you may include it under
2743f32c10Smrg# the same distribution terms that you use for the rest of that program.
2843f32c10Smrg
2943f32c10Smrgif test $# -eq 0; then
306ef05171Smrg  echo 1>&2 "Try '$0 --help' for more information"
3143f32c10Smrg  exit 1
3243f32c10Smrgfi
3343f32c10Smrg
346ef05171Smrgcase $1 in
3543f32c10Smrg
366ef05171Smrg  --is-lightweight)
376ef05171Smrg    # Used by our autoconf macros to check whether the available missing
386ef05171Smrg    # script is modern enough.
396ef05171Smrg    exit 0
406ef05171Smrg    ;;
4143f32c10Smrg
426ef05171Smrg  --run)
436ef05171Smrg    # Back-compat with the calling convention used by older automake.
446ef05171Smrg    shift
456ef05171Smrg    ;;
4643f32c10Smrg
4743f32c10Smrg  -h|--h|--he|--hel|--help)
4843f32c10Smrg    echo "\
4943f32c10Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
5043f32c10Smrg
516ef05171SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
526ef05171Smrgto PROGRAM being missing or too old.
5343f32c10Smrg
5443f32c10SmrgOptions:
5543f32c10Smrg  -h, --help      display this help and exit
5643f32c10Smrg  -v, --version   output version information and exit
5743f32c10Smrg
5843f32c10SmrgSupported PROGRAM values:
59d3173433Smrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
60d3173433Smrgbison   flex     help2man lex        makeinfo perl     yacc
616ef05171Smrg
626ef05171SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
636ef05171Smrg'g' are ignored when checking the name.
6443f32c10Smrg
65d3173433SmrgReport bugs to <bug-automake@gnu.org>.
66d3173433SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
67d3173433SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
6843f32c10Smrg    exit $?
6943f32c10Smrg    ;;
7043f32c10Smrg
7143f32c10Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
72d3173433Smrg    echo "missing (GNU Automake) $scriptversion"
7343f32c10Smrg    exit $?
7443f32c10Smrg    ;;
7543f32c10Smrg
7643f32c10Smrg  -*)
776ef05171Smrg    echo 1>&2 "$0: unknown '$1' option"
786ef05171Smrg    echo 1>&2 "Try '$0 --help' for more information"
7943f32c10Smrg    exit 1
8043f32c10Smrg    ;;
8143f32c10Smrg
8243f32c10Smrgesac
8343f32c10Smrg
846ef05171Smrg# Run the given program, remember its exit status.
856ef05171Smrg"$@"; st=$?
866ef05171Smrg
876ef05171Smrg# If it succeeded, we are done.
886ef05171Smrgtest $st -eq 0 && exit 0
896ef05171Smrg
906ef05171Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
916ef05171Smrg# passed; such an option is passed most likely to detect whether the
926ef05171Smrg# program is present and works.
936ef05171Smrgcase $2 in --version|--help) exit $st;; esac
946ef05171Smrg
956ef05171Smrg# Exit code 63 means version mismatch.  This often happens when the user
966ef05171Smrg# tries to use an ancient version of a tool on a file that requires a
976ef05171Smrg# minimum version.
986ef05171Smrgif test $st -eq 63; then
996ef05171Smrg  msg="probably too old"
1006ef05171Smrgelif test $st -eq 127; then
1016ef05171Smrg  # Program was missing.
1026ef05171Smrg  msg="missing on your system"
1036ef05171Smrgelse
1046ef05171Smrg  # Program was found and executed, but failed.  Give up.
1056ef05171Smrg  exit $st
1066ef05171Smrgfi
10743f32c10Smrg
108ea148d1dSmrgperl_URL=https://www.perl.org/
109ea148d1dSmrgflex_URL=https://github.com/westes/flex
110ea148d1dSmrggnu_software_URL=https://www.gnu.org/software
1116ef05171Smrg
1126ef05171Smrgprogram_details ()
1136ef05171Smrg{
1146ef05171Smrg  case $1 in
115d3173433Smrg    aclocal|automake|autoreconf)
1166ef05171Smrg      echo "The '$1' program is part of the GNU Automake package:"
1176ef05171Smrg      echo "<$gnu_software_URL/automake>"
1186ef05171Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1196ef05171Smrg      echo "<$gnu_software_URL/autoconf>"
1206ef05171Smrg      echo "<$gnu_software_URL/m4/>"
1216ef05171Smrg      echo "<$perl_URL>"
1226ef05171Smrg      ;;
1236ef05171Smrg    autoconf|autom4te|autoheader)
1246ef05171Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1256ef05171Smrg      echo "<$gnu_software_URL/autoconf/>"
1266ef05171Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1276ef05171Smrg      echo "<$gnu_software_URL/m4/>"
1286ef05171Smrg      echo "<$perl_URL>"
1296ef05171Smrg      ;;
130d3173433Smrg    *)
131d3173433Smrg      :
132d3173433Smrg      ;;
1336ef05171Smrg  esac
1346ef05171Smrg}
1356ef05171Smrg
1366ef05171Smrggive_advice ()
1376ef05171Smrg{
1386ef05171Smrg  # Normalize program name to check for.
1396ef05171Smrg  normalized_program=`echo "$1" | sed '
1406ef05171Smrg    s/^gnu-//; t
1416ef05171Smrg    s/^gnu//; t
1426ef05171Smrg    s/^g//; t'`
1436ef05171Smrg
1446ef05171Smrg  printf '%s\n' "'$1' is $msg."
1456ef05171Smrg
1466ef05171Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
147d3173433Smrg  autoheader_deps="'acconfig.h'"
148d3173433Smrg  automake_deps="'Makefile.am'"
149d3173433Smrg  aclocal_deps="'acinclude.m4'"
1506ef05171Smrg  case $normalized_program in
151d3173433Smrg    aclocal*)
152d3173433Smrg      echo "You should only need it if you modified $aclocal_deps or"
153d3173433Smrg      echo "$configure_deps."
154d3173433Smrg      ;;
1556ef05171Smrg    autoconf*)
156d3173433Smrg      echo "You should only need it if you modified $configure_deps."
157d3173433Smrg      ;;
158d3173433Smrg    autogen*)
159d3173433Smrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
160d3173433Smrg      echo "You may want to install the GNU AutoGen package:"
161d3173433Smrg      echo "<$gnu_software_URL/autogen/>"
1626ef05171Smrg      ;;
1636ef05171Smrg    autoheader*)
164d3173433Smrg      echo "You should only need it if you modified $autoheader_deps or"
1656ef05171Smrg      echo "$configure_deps."
1666ef05171Smrg      ;;
1676ef05171Smrg    automake*)
168d3173433Smrg      echo "You should only need it if you modified $automake_deps or"
1696ef05171Smrg      echo "$configure_deps."
1706ef05171Smrg      ;;
171d3173433Smrg    autom4te*)
1726ef05171Smrg      echo "You might have modified some maintainer files that require"
1736ef05171Smrg      echo "the 'autom4te' program to be rebuilt."
174d3173433Smrg      ;;
175d3173433Smrg    autoreconf*)
176d3173433Smrg      echo "You should only need it if you modified $aclocal_deps or"
177d3173433Smrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
178d3173433Smrg      echo "$configure_deps."
1796ef05171Smrg      ;;
1806ef05171Smrg    bison*|yacc*)
1816ef05171Smrg      echo "You should only need it if you modified a '.y' file."
1826ef05171Smrg      echo "You may want to install the GNU Bison package:"
1836ef05171Smrg      echo "<$gnu_software_URL/bison/>"
1846ef05171Smrg      ;;
1856ef05171Smrg    help2man*)
1866ef05171Smrg      echo "You should only need it if you modified a dependency" \
1876ef05171Smrg           "of a man page."
1886ef05171Smrg      echo "You may want to install the GNU Help2man package:"
1896ef05171Smrg      echo "<$gnu_software_URL/help2man/>"
1906ef05171Smrg    ;;
191d3173433Smrg    lex*|flex*)
192d3173433Smrg      echo "You should only need it if you modified a '.l' file."
193d3173433Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
194d3173433Smrg      echo "<$flex_URL>"
195d3173433Smrg      ;;
1966ef05171Smrg    makeinfo*)
1976ef05171Smrg      echo "You should only need it if you modified a '.texi' file, or"
1986ef05171Smrg      echo "any other file indirectly affecting the aspect of the manual."
1996ef05171Smrg      echo "You might want to install the Texinfo package:"
2006ef05171Smrg      echo "<$gnu_software_URL/texinfo/>"
2016ef05171Smrg      echo "The spurious makeinfo call might also be the consequence of"
2026ef05171Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
2036ef05171Smrg      echo "want to install GNU make:"
2046ef05171Smrg      echo "<$gnu_software_URL/make/>"
2056ef05171Smrg      ;;
206d3173433Smrg    perl*)
207d3173433Smrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
208d3173433Smrg      echo "  assorted other tools, or if you modified a Perl source file."
209d3173433Smrg      echo "You may want to install the Perl 5 language interpreter:"
210d3173433Smrg      echo "<$perl_URL>"
211d3173433Smrg      ;;
2126ef05171Smrg    *)
2136ef05171Smrg      echo "You might have modified some files without having the proper"
2146ef05171Smrg      echo "tools for further handling them.  Check the 'README' file, it"
2156ef05171Smrg      echo "often tells you about the needed prerequisites for installing"
2166ef05171Smrg      echo "this package.  You may also peek at any GNU archive site, in"
2176ef05171Smrg      echo "case some other package contains this missing '$1' program."
2186ef05171Smrg      ;;
2196ef05171Smrg  esac
220d3173433Smrg  program_details "$normalized_program"
2216ef05171Smrg}
2226ef05171Smrg
2236ef05171Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2246ef05171Smrg                       -e '2,$s/^/         /' >&2
2256ef05171Smrg
2266ef05171Smrg# Propagate the correct exit status (expected to be 127 for a program
2276ef05171Smrg# not found, 63 for a program that failed due to version mismatch).
2286ef05171Smrgexit $st
22943f32c10Smrg
23043f32c10Smrg# Local variables:
231ea148d1dSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
23243f32c10Smrg# time-stamp-start: "scriptversion="
23343f32c10Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2346ef05171Smrg# time-stamp-time-zone: "UTC0"
2356ef05171Smrg# time-stamp-end: "; # UTC"
23643f32c10Smrg# End:
237