1126a8a12Smrg#! /bin/sh
26bea0e4fSmrg# Common wrapper for a few potentially missing GNU and other programs.
3126a8a12Smrg
46bea0e4fSmrgscriptversion=2024-06-07.14; # UTC
5126a8a12Smrg
66bea0e4fSmrg# shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
76bea0e4fSmrg
86bea0e4fSmrg# Copyright (C) 1996-2024 Free Software Foundation, Inc.
90a6b08f8Smrg# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
10126a8a12Smrg
11126a8a12Smrg# This program is free software; you can redistribute it and/or modify
12126a8a12Smrg# it under the terms of the GNU General Public License as published by
13126a8a12Smrg# the Free Software Foundation; either version 2, or (at your option)
14126a8a12Smrg# any later version.
15126a8a12Smrg
16126a8a12Smrg# This program is distributed in the hope that it will be useful,
17126a8a12Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
18126a8a12Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19126a8a12Smrg# GNU General Public License for more details.
20126a8a12Smrg
21126a8a12Smrg# You should have received a copy of the GNU General Public License
223fb97780Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
23126a8a12Smrg
24126a8a12Smrg# As a special exception to the GNU General Public License, if you
25126a8a12Smrg# distribute this file as part of a program that contains a
26126a8a12Smrg# configuration script generated by Autoconf, you may include it under
27126a8a12Smrg# the same distribution terms that you use for the rest of that program.
28126a8a12Smrg
29126a8a12Smrgif test $# -eq 0; then
300a6b08f8Smrg  echo 1>&2 "Try '$0 --help' for more information"
31126a8a12Smrg  exit 1
32126a8a12Smrgfi
33126a8a12Smrg
340a6b08f8Smrgcase $1 in
35126a8a12Smrg
360a6b08f8Smrg  --is-lightweight)
370a6b08f8Smrg    # Used by our autoconf macros to check whether the available missing
380a6b08f8Smrg    # script is modern enough.
390a6b08f8Smrg    exit 0
400a6b08f8Smrg    ;;
41126a8a12Smrg
420a6b08f8Smrg  --run)
430a6b08f8Smrg    # Back-compat with the calling convention used by older automake.
440a6b08f8Smrg    shift
450a6b08f8Smrg    ;;
46126a8a12Smrg
47126a8a12Smrg  -h|--h|--he|--hel|--help)
48126a8a12Smrg    echo "\
49126a8a12Smrg$0 [OPTION]... PROGRAM [ARGUMENT]...
50126a8a12Smrg
510a6b08f8SmrgRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
520a6b08f8Smrgto PROGRAM being missing or too old.
53126a8a12Smrg
54126a8a12SmrgOptions:
55126a8a12Smrg  -h, --help      display this help and exit
56126a8a12Smrg  -v, --version   output version information and exit
57126a8a12Smrg
58126a8a12SmrgSupported PROGRAM values:
596bea0e4fSmrgaclocal autoconf autogen  autoheader autom4te automake autoreconf
606bea0e4fSmrgbison   flex     help2man lex        makeinfo perl     yacc
61126a8a12Smrg
620a6b08f8SmrgVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
630a6b08f8Smrg'g' are ignored when checking the name.
64d656433aSmrg
656bea0e4fSmrgReport bugs to <bug-automake@gnu.org>.
666bea0e4fSmrgGNU Automake home page: <https://www.gnu.org/software/automake/>.
676bea0e4fSmrgGeneral help using GNU software: <https://www.gnu.org/gethelp/>."
68126a8a12Smrg    exit $?
69126a8a12Smrg    ;;
70126a8a12Smrg
71126a8a12Smrg  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
726bea0e4fSmrg    echo "missing (GNU Automake) $scriptversion"
73126a8a12Smrg    exit $?
74126a8a12Smrg    ;;
75126a8a12Smrg
76126a8a12Smrg  -*)
770a6b08f8Smrg    echo 1>&2 "$0: unknown '$1' option"
780a6b08f8Smrg    echo 1>&2 "Try '$0 --help' for more information"
79126a8a12Smrg    exit 1
80126a8a12Smrg    ;;
81126a8a12Smrg
82126a8a12Smrgesac
83126a8a12Smrg
840a6b08f8Smrg# Run the given program, remember its exit status.
850a6b08f8Smrg"$@"; st=$?
860a6b08f8Smrg
870a6b08f8Smrg# If it succeeded, we are done.
880a6b08f8Smrgtest $st -eq 0 && exit 0
890a6b08f8Smrg
900a6b08f8Smrg# Also exit now if we it failed (or wasn't found), and '--version' was
910a6b08f8Smrg# passed; such an option is passed most likely to detect whether the
920a6b08f8Smrg# program is present and works.
930a6b08f8Smrgcase $2 in --version|--help) exit $st;; esac
940a6b08f8Smrg
950a6b08f8Smrg# Exit code 63 means version mismatch.  This often happens when the user
960a6b08f8Smrg# tries to use an ancient version of a tool on a file that requires a
970a6b08f8Smrg# minimum version.
980a6b08f8Smrgif test $st -eq 63; then
990a6b08f8Smrg  msg="probably too old"
1000a6b08f8Smrgelif test $st -eq 127; then
1010a6b08f8Smrg  # Program was missing.
1020a6b08f8Smrg  msg="missing on your system"
1030a6b08f8Smrgelse
1040a6b08f8Smrg  # Program was found and executed, but failed.  Give up.
1050a6b08f8Smrg  exit $st
1060a6b08f8Smrgfi
107126a8a12Smrg
1083fb97780Smrgperl_URL=https://www.perl.org/
1093fb97780Smrgflex_URL=https://github.com/westes/flex
1103fb97780Smrggnu_software_URL=https://www.gnu.org/software
1110a6b08f8Smrg
1120a6b08f8Smrgprogram_details ()
1130a6b08f8Smrg{
1140a6b08f8Smrg  case $1 in
1156bea0e4fSmrg    aclocal|automake|autoreconf)
1160a6b08f8Smrg      echo "The '$1' program is part of the GNU Automake package:"
1170a6b08f8Smrg      echo "<$gnu_software_URL/automake>"
1180a6b08f8Smrg      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1190a6b08f8Smrg      echo "<$gnu_software_URL/autoconf>"
1200a6b08f8Smrg      echo "<$gnu_software_URL/m4/>"
1210a6b08f8Smrg      echo "<$perl_URL>"
1220a6b08f8Smrg      ;;
1230a6b08f8Smrg    autoconf|autom4te|autoheader)
1240a6b08f8Smrg      echo "The '$1' program is part of the GNU Autoconf package:"
1250a6b08f8Smrg      echo "<$gnu_software_URL/autoconf/>"
1260a6b08f8Smrg      echo "It also requires GNU m4 and Perl in order to run:"
1270a6b08f8Smrg      echo "<$gnu_software_URL/m4/>"
1280a6b08f8Smrg      echo "<$perl_URL>"
1290a6b08f8Smrg      ;;
1306bea0e4fSmrg    *)
1316bea0e4fSmrg      :
1326bea0e4fSmrg      ;;
1330a6b08f8Smrg  esac
1340a6b08f8Smrg}
1350a6b08f8Smrg
1360a6b08f8Smrggive_advice ()
1370a6b08f8Smrg{
1380a6b08f8Smrg  # Normalize program name to check for.
1390a6b08f8Smrg  normalized_program=`echo "$1" | sed '
1400a6b08f8Smrg    s/^gnu-//; t
1410a6b08f8Smrg    s/^gnu//; t
1420a6b08f8Smrg    s/^g//; t'`
1430a6b08f8Smrg
1440a6b08f8Smrg  printf '%s\n' "'$1' is $msg."
1450a6b08f8Smrg
1460a6b08f8Smrg  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1476bea0e4fSmrg  autoheader_deps="'acconfig.h'"
1486bea0e4fSmrg  automake_deps="'Makefile.am'"
1496bea0e4fSmrg  aclocal_deps="'acinclude.m4'"
1500a6b08f8Smrg  case $normalized_program in
1516bea0e4fSmrg    aclocal*)
1526bea0e4fSmrg      echo "You should only need it if you modified $aclocal_deps or"
1536bea0e4fSmrg      echo "$configure_deps."
1546bea0e4fSmrg      ;;
1550a6b08f8Smrg    autoconf*)
1566bea0e4fSmrg      echo "You should only need it if you modified $configure_deps."
1576bea0e4fSmrg      ;;
1586bea0e4fSmrg    autogen*)
1596bea0e4fSmrg      echo "You should only need it if you modified a '.def' or '.tpl' file."
1606bea0e4fSmrg      echo "You may want to install the GNU AutoGen package:"
1616bea0e4fSmrg      echo "<$gnu_software_URL/autogen/>"
1620a6b08f8Smrg      ;;
1630a6b08f8Smrg    autoheader*)
1646bea0e4fSmrg      echo "You should only need it if you modified $autoheader_deps or"
1650a6b08f8Smrg      echo "$configure_deps."
1660a6b08f8Smrg      ;;
1670a6b08f8Smrg    automake*)
1686bea0e4fSmrg      echo "You should only need it if you modified $automake_deps or"
1690a6b08f8Smrg      echo "$configure_deps."
1700a6b08f8Smrg      ;;
1716bea0e4fSmrg    autom4te*)
1720a6b08f8Smrg      echo "You might have modified some maintainer files that require"
173300346aeSmrg      echo "the 'autom4te' program to be rebuilt."
1746bea0e4fSmrg      ;;
1756bea0e4fSmrg    autoreconf*)
1766bea0e4fSmrg      echo "You should only need it if you modified $aclocal_deps or"
1776bea0e4fSmrg      echo "$automake_deps or $autoheader_deps or $automake_deps or"
1786bea0e4fSmrg      echo "$configure_deps."
1790a6b08f8Smrg      ;;
1800a6b08f8Smrg    bison*|yacc*)
1810a6b08f8Smrg      echo "You should only need it if you modified a '.y' file."
1820a6b08f8Smrg      echo "You may want to install the GNU Bison package:"
1830a6b08f8Smrg      echo "<$gnu_software_URL/bison/>"
1840a6b08f8Smrg      ;;
1850a6b08f8Smrg    help2man*)
1860a6b08f8Smrg      echo "You should only need it if you modified a dependency" \
1870a6b08f8Smrg           "of a man page."
1880a6b08f8Smrg      echo "You may want to install the GNU Help2man package:"
1890a6b08f8Smrg      echo "<$gnu_software_URL/help2man/>"
1900a6b08f8Smrg    ;;
1916bea0e4fSmrg    lex*|flex*)
1926bea0e4fSmrg      echo "You should only need it if you modified a '.l' file."
1936bea0e4fSmrg      echo "You may want to install the Fast Lexical Analyzer package:"
1946bea0e4fSmrg      echo "<$flex_URL>"
1956bea0e4fSmrg      ;;
1960a6b08f8Smrg    makeinfo*)
1970a6b08f8Smrg      echo "You should only need it if you modified a '.texi' file, or"
1980a6b08f8Smrg      echo "any other file indirectly affecting the aspect of the manual."
1990a6b08f8Smrg      echo "You might want to install the Texinfo package:"
2000a6b08f8Smrg      echo "<$gnu_software_URL/texinfo/>"
2010a6b08f8Smrg      echo "The spurious makeinfo call might also be the consequence of"
2020a6b08f8Smrg      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
2030a6b08f8Smrg      echo "want to install GNU make:"
2040a6b08f8Smrg      echo "<$gnu_software_URL/make/>"
2050a6b08f8Smrg      ;;
2066bea0e4fSmrg    perl*)
2076bea0e4fSmrg      echo "You should only need it to run GNU Autoconf, GNU Automake, "
2086bea0e4fSmrg      echo "  assorted other tools, or if you modified a Perl source file."
2096bea0e4fSmrg      echo "You may want to install the Perl 5 language interpreter:"
2106bea0e4fSmrg      echo "<$perl_URL>"
2116bea0e4fSmrg      ;;
2120a6b08f8Smrg    *)
2130a6b08f8Smrg      echo "You might have modified some files without having the proper"
2140a6b08f8Smrg      echo "tools for further handling them.  Check the 'README' file, it"
2150a6b08f8Smrg      echo "often tells you about the needed prerequisites for installing"
2160a6b08f8Smrg      echo "this package.  You may also peek at any GNU archive site, in"
2170a6b08f8Smrg      echo "case some other package contains this missing '$1' program."
2180a6b08f8Smrg      ;;
2190a6b08f8Smrg  esac
2206bea0e4fSmrg  program_details "$normalized_program"
2210a6b08f8Smrg}
2220a6b08f8Smrg
2230a6b08f8Smrggive_advice "$1" | sed -e '1s/^/WARNING: /' \
2240a6b08f8Smrg                       -e '2,$s/^/         /' >&2
2250a6b08f8Smrg
2260a6b08f8Smrg# Propagate the correct exit status (expected to be 127 for a program
2270a6b08f8Smrg# not found, 63 for a program that failed due to version mismatch).
2280a6b08f8Smrgexit $st
229126a8a12Smrg
230126a8a12Smrg# Local variables:
2313fb97780Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
232126a8a12Smrg# time-stamp-start: "scriptversion="
233126a8a12Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
2343fb97780Smrg# time-stamp-time-zone: "UTC0"
235d656433aSmrg# time-stamp-end: "; # UTC"
236126a8a12Smrg# End:
237