11f0ac6a5Smrg#! /bin/sh
26ee7d557Smrg# Common wrapper for a few potentially missing GNU and other programs.
31f0ac6a5Smrg
46ee7d557Smrgscriptversion=2024-06-07.14; # UTC
51f0ac6a5Smrg
66ee7d557Smrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
76ee7d557Smrg
86ee7d557Smrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
989c04b6cSmrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
101f0ac6a5Smrg
111f0ac6a5Smrg# This program is free software; you can redistribute it and/or modify
121f0ac6a5Smrg# it under the terms of the GNU General Public License as published by
131f0ac6a5Smrg# the Free Software Foundation; either version 2, or (at your option)
141f0ac6a5Smrg# any later version.
151f0ac6a5Smrg
161f0ac6a5Smrg# This program is distributed in the hope that it will be useful,
171f0ac6a5Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
181f0ac6a5Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
191f0ac6a5Smrg# GNU General Public License for more details.
201f0ac6a5Smrg
211f0ac6a5Smrg# You should have received a copy of the GNU General Public License
22d21ab8bcSmrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
231f0ac6a5Smrg
241f0ac6a5Smrg# As a special exception to the GNU General Public License, if you
251f0ac6a5Smrg# distribute this file as part of a program that contains a
261f0ac6a5Smrg# configuration script generated by Autoconf, you may include it under
271f0ac6a5Smrg# the same distribution terms that you use for the rest of that program.
281f0ac6a5Smrg
291f0ac6a5Smrgif test $# -eq 0; then
3089c04b6cSmrg  echo 1>&2 "Try '$0 --help' for more information"
311f0ac6a5Smrg  exit 1
321f0ac6a5Smrgfi
331f0ac6a5Smrg
3489c04b6cSmrgcase $1 in
351f0ac6a5Smrg
3689c04b6cSmrg  --is-lightweight)
3789c04b6cSmrg    # Used by our autoconf macros to check whether the available missing
3889c04b6cSmrg    # script is modern enough.
3989c04b6cSmrg    exit 0
4089c04b6cSmrg    ;;
411f0ac6a5Smrg
4289c04b6cSmrg  --run)
4389c04b6cSmrg    # Back-compat with the calling convention used by older automake.
4489c04b6cSmrg    shift
4589c04b6cSmrg    ;;
461f0ac6a5Smrg
471f0ac6a5Smrg  -h|--h|--he|--hel|--help)
481f0ac6a5Smrg    echo "\
491f0ac6a5Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
501f0ac6a5Smrg
5189c04b6cSmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
5289c04b6cSmrgto PROGRAM being missing or too old.
531f0ac6a5Smrg
541f0ac6a5SmrgOptions:
551f0ac6a5Smrg  -h, --help      display this help and exit
561f0ac6a5Smrg  -v, --version   output version information and exit
571f0ac6a5Smrg
581f0ac6a5SmrgSupported PROGRAM values:
596ee7d557Smrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
606ee7d557Smrgbison   flex     help2man lex        makeinfo perl     yacc
611f0ac6a5Smrg
6289c04b6cSmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
6389c04b6cSmrg'g' are ignored when checking the name.
64e5410a46Smrg
656ee7d557SmrgReport bugs to <bug-automake@gnu.org>.
666ee7d557SmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
676ee7d557SmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
681f0ac6a5Smrg    exit $?
691f0ac6a5Smrg    ;;
701f0ac6a5Smrg
711f0ac6a5Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
726ee7d557Smrg    echo "missing (GNU Automake) $scriptversion"
731f0ac6a5Smrg    exit $?
741f0ac6a5Smrg    ;;
751f0ac6a5Smrg
761f0ac6a5Smrg  -*)
7789c04b6cSmrg    echo 1>&2 "$0: unknown '$1' option"
7889c04b6cSmrg    echo 1>&2 "Try '$0 --help' for more information"
791f0ac6a5Smrg    exit 1
801f0ac6a5Smrg    ;;
811f0ac6a5Smrg
821f0ac6a5Smrgesac
831f0ac6a5Smrg
8489c04b6cSmrg# Run the given program, remember its exit status.
8589c04b6cSmrg"$@"; st=$?
8689c04b6cSmrg
8789c04b6cSmrg# If it succeeded, we are done.
8889c04b6cSmrgtest $st -eq 0 && exit 0
8989c04b6cSmrg
9089c04b6cSmrg# Also exit now if we it failed (or wasn't found), and '--version' was
9189c04b6cSmrg# passed; such an option is passed most likely to detect whether the
9289c04b6cSmrg# program is present and works.
9389c04b6cSmrgcase $2 in --version|--help) exit $st;; esac
9489c04b6cSmrg
9589c04b6cSmrg# Exit code 63 means version mismatch.  This often happens when the user
9689c04b6cSmrg# tries to use an ancient version of a tool on a file that requires a
9789c04b6cSmrg# minimum version.
9889c04b6cSmrgif test $st -eq 63; then
9989c04b6cSmrg  msg="probably too old"
10089c04b6cSmrgelif test $st -eq 127; then
10189c04b6cSmrg  # Program was missing.
10289c04b6cSmrg  msg="missing on your system"
10389c04b6cSmrgelse
10489c04b6cSmrg  # Program was found and executed, but failed.  Give up.
10589c04b6cSmrg  exit $st
10689c04b6cSmrgfi
1071f0ac6a5Smrg
108d21ab8bcSmrgperl_URL=https://www.perl.org/
109d21ab8bcSmrgflex_URL=https://github.com/westes/flex
110d21ab8bcSmrggnu_software_URL=https://www.gnu.org/software
11189c04b6cSmrg
11289c04b6cSmrgprogram_details ()
11389c04b6cSmrg{
11489c04b6cSmrg  case $1 in
1156ee7d557Smrg    aclocal|automake|autoreconf)
11689c04b6cSmrg      echo "The '$1' program is part of the GNU Automake package:"
11789c04b6cSmrg      echo "<$gnu_software_URL/automake>"
11889c04b6cSmrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
11989c04b6cSmrg      echo "<$gnu_software_URL/autoconf>"
12089c04b6cSmrg      echo "<$gnu_software_URL/m4/>"
12189c04b6cSmrg      echo "<$perl_URL>"
12289c04b6cSmrg      ;;
12389c04b6cSmrg    autoconf|autom4te|autoheader)
12489c04b6cSmrg      echo "The '$1' program is part of the GNU Autoconf package:"
12589c04b6cSmrg      echo "<$gnu_software_URL/autoconf/>"
12689c04b6cSmrg      echo "It also requires GNU m4 and Perl in order to run:"
12789c04b6cSmrg      echo "<$gnu_software_URL/m4/>"
12889c04b6cSmrg      echo "<$perl_URL>"
12989c04b6cSmrg      ;;
1306ee7d557Smrg    *)
1316ee7d557Smrg      :
1326ee7d557Smrg      ;;
13389c04b6cSmrg  esac
13489c04b6cSmrg}
13589c04b6cSmrg
13689c04b6cSmrggive_advice ()
13789c04b6cSmrg{
13889c04b6cSmrg  # Normalize program name to check for.
13989c04b6cSmrg  normalized_program=`echo "$1" | sed '
14089c04b6cSmrg    s/^gnu-//; t
14189c04b6cSmrg    s/^gnu//; t
14289c04b6cSmrg    s/^g//; t'`
14389c04b6cSmrg
14489c04b6cSmrg  printf '%s\n' "'$1' is $msg."
14589c04b6cSmrg
14689c04b6cSmrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1476ee7d557Smrg  autoheader_deps="'acconfig.h'"
1486ee7d557Smrg  automake_deps="'Makefile.am'"
1496ee7d557Smrg  aclocal_deps="'acinclude.m4'"
15089c04b6cSmrg  case $normalized_program in
1516ee7d557Smrg    aclocal*)
1526ee7d557Smrg      echo "You should only need it if you modified $aclocal_deps or"
1536ee7d557Smrg      echo "$configure_deps."
1546ee7d557Smrg      ;;
15589c04b6cSmrg    autoconf*)
1566ee7d557Smrg      echo "You should only need it if you modified $configure_deps."
1576ee7d557Smrg      ;;
1586ee7d557Smrg    autogen*)
1596ee7d557Smrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
1606ee7d557Smrg      echo "You may want to install the GNU AutoGen package:"
1616ee7d557Smrg      echo "<$gnu_software_URL/autogen/>"
16289c04b6cSmrg      ;;
16389c04b6cSmrg    autoheader*)
1646ee7d557Smrg      echo "You should only need it if you modified $autoheader_deps or"
16589c04b6cSmrg      echo "$configure_deps."
16689c04b6cSmrg      ;;
16789c04b6cSmrg    automake*)
1686ee7d557Smrg      echo "You should only need it if you modified $automake_deps or"
16989c04b6cSmrg      echo "$configure_deps."
17089c04b6cSmrg      ;;
1716ee7d557Smrg    autom4te*)
17289c04b6cSmrg      echo "You might have modified some maintainer files that require"
173b9867631Smrg      echo "the 'autom4te' program to be rebuilt."
1746ee7d557Smrg      ;;
1756ee7d557Smrg    autoreconf*)
1766ee7d557Smrg      echo "You should only need it if you modified $aclocal_deps or"
1776ee7d557Smrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
1786ee7d557Smrg      echo "$configure_deps."
17989c04b6cSmrg      ;;
18089c04b6cSmrg    bison*|yacc*)
18189c04b6cSmrg      echo "You should only need it if you modified a '.y' file."
18289c04b6cSmrg      echo "You may want to install the GNU Bison package:"
18389c04b6cSmrg      echo "<$gnu_software_URL/bison/>"
18489c04b6cSmrg      ;;
18589c04b6cSmrg    help2man*)
18689c04b6cSmrg      echo "You should only need it if you modified a dependency" \
18789c04b6cSmrg           "of a man page."
18889c04b6cSmrg      echo "You may want to install the GNU Help2man package:"
18989c04b6cSmrg      echo "<$gnu_software_URL/help2man/>"
19089c04b6cSmrg    ;;
1916ee7d557Smrg    lex*|flex*)
1926ee7d557Smrg      echo "You should only need it if you modified a '.l' file."
1936ee7d557Smrg      echo "You may want to install the Fast Lexical Analyzer package:"
1946ee7d557Smrg      echo "<$flex_URL>"
1956ee7d557Smrg      ;;
19689c04b6cSmrg    makeinfo*)
19789c04b6cSmrg      echo "You should only need it if you modified a '.texi' file, or"
19889c04b6cSmrg      echo "any other file indirectly affecting the aspect of the manual."
19989c04b6cSmrg      echo "You might want to install the Texinfo package:"
20089c04b6cSmrg      echo "<$gnu_software_URL/texinfo/>"
20189c04b6cSmrg      echo "The spurious makeinfo call might also be the consequence of"
20289c04b6cSmrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
20389c04b6cSmrg      echo "want to install GNU make:"
20489c04b6cSmrg      echo "<$gnu_software_URL/make/>"
20589c04b6cSmrg      ;;
2066ee7d557Smrg    perl*)
2076ee7d557Smrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
2086ee7d557Smrg      echo "  assorted other tools, or if you modified a Perl source file."
2096ee7d557Smrg      echo "You may want to install the Perl 5 language interpreter:"
2106ee7d557Smrg      echo "<$perl_URL>"
2116ee7d557Smrg      ;;
21289c04b6cSmrg    *)
21389c04b6cSmrg      echo "You might have modified some files without having the proper"
21489c04b6cSmrg      echo "tools for further handling them.  Check the 'README' file, it"
21589c04b6cSmrg      echo "often tells you about the needed prerequisites for installing"
21689c04b6cSmrg      echo "this package.  You may also peek at any GNU archive site, in"
21789c04b6cSmrg      echo "case some other package contains this missing '$1' program."
21889c04b6cSmrg      ;;
21989c04b6cSmrg  esac
2206ee7d557Smrg  program_details "$normalized_program"
22189c04b6cSmrg}
22289c04b6cSmrg
22389c04b6cSmrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
22489c04b6cSmrg                       -e '2,$s/^/         /' >&2
22589c04b6cSmrg
22689c04b6cSmrg# Propagate the correct exit status (expected to be 127 for a program
22789c04b6cSmrg# not found, 63 for a program that failed due to version mismatch).
22889c04b6cSmrgexit $st
2291f0ac6a5Smrg
2301f0ac6a5Smrg# Local variables:
231d21ab8bcSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2321f0ac6a5Smrg# time-stamp-start: "scriptversion="
2331f0ac6a5Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
234d21ab8bcSmrg# time-stamp-time-zone: "UTC0"
235e5410a46Smrg# time-stamp-end: "; # UTC"
2361f0ac6a5Smrg# End:
237