Home | History | Annotate | Line # | Download | only in dist
      1      1.1  christos #! /bin/sh
      2  1.1.1.2  christos # Common wrapper for a few potentially missing GNU and other programs.
      3      1.1  christos 
      4  1.1.1.2  christos scriptversion=2024-06-07.14; # UTC
      5      1.1  christos 
      6  1.1.1.2  christos # shellcheck disable=SC2006,SC2268 # we must support pre-POSIX shells
      7  1.1.1.2  christos 
      8  1.1.1.2  christos # Copyright (C) 1996-2024 Free Software Foundation, Inc.
      9      1.1  christos # Originally written by Fran,cois Pinard <pinard (at] iro.umontreal.ca>, 1996.
     10      1.1  christos 
     11      1.1  christos # This program is free software; you can redistribute it and/or modify
     12      1.1  christos # it under the terms of the GNU General Public License as published by
     13      1.1  christos # the Free Software Foundation; either version 2, or (at your option)
     14      1.1  christos # any later version.
     15      1.1  christos 
     16      1.1  christos # This program is distributed in the hope that it will be useful,
     17      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     18      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19      1.1  christos # GNU General Public License for more details.
     20      1.1  christos 
     21      1.1  christos # You should have received a copy of the GNU General Public License
     22      1.1  christos # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     23      1.1  christos 
     24      1.1  christos # As a special exception to the GNU General Public License, if you
     25      1.1  christos # distribute this file as part of a program that contains a
     26      1.1  christos # configuration script generated by Autoconf, you may include it under
     27      1.1  christos # the same distribution terms that you use for the rest of that program.
     28      1.1  christos 
     29      1.1  christos if test $# -eq 0; then
     30      1.1  christos   echo 1>&2 "Try '$0 --help' for more information"
     31      1.1  christos   exit 1
     32      1.1  christos fi
     33      1.1  christos 
     34      1.1  christos case $1 in
     35      1.1  christos 
     36      1.1  christos   --is-lightweight)
     37      1.1  christos     # Used by our autoconf macros to check whether the available missing
     38      1.1  christos     # script is modern enough.
     39      1.1  christos     exit 0
     40      1.1  christos     ;;
     41      1.1  christos 
     42      1.1  christos   --run)
     43      1.1  christos     # Back-compat with the calling convention used by older automake.
     44      1.1  christos     shift
     45      1.1  christos     ;;
     46      1.1  christos 
     47      1.1  christos   -h|--h|--he|--hel|--help)
     48      1.1  christos     echo "\
     49      1.1  christos $0 [OPTION]... PROGRAM [ARGUMENT]...
     50      1.1  christos 
     51      1.1  christos Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
     52      1.1  christos to PROGRAM being missing or too old.
     53      1.1  christos 
     54      1.1  christos Options:
     55      1.1  christos   -h, --help      display this help and exit
     56      1.1  christos   -v, --version   output version information and exit
     57      1.1  christos 
     58      1.1  christos Supported PROGRAM values:
     59  1.1.1.2  christos aclocal autoconf autogen  autoheader autom4te automake autoreconf
     60  1.1.1.2  christos bison   flex     help2man lex        makeinfo perl     yacc
     61      1.1  christos 
     62      1.1  christos Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
     63      1.1  christos 'g' are ignored when checking the name.
     64      1.1  christos 
     65  1.1.1.2  christos Report bugs to <bug-automake (at] gnu.org>.
     66  1.1.1.2  christos GNU Automake home page: <https://www.gnu.org/software/automake/>.
     67  1.1.1.2  christos General help using GNU software: <https://www.gnu.org/gethelp/>."
     68      1.1  christos     exit $?
     69      1.1  christos     ;;
     70      1.1  christos 
     71      1.1  christos   -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
     72  1.1.1.2  christos     echo "missing (GNU Automake) $scriptversion"
     73      1.1  christos     exit $?
     74      1.1  christos     ;;
     75      1.1  christos 
     76      1.1  christos   -*)
     77      1.1  christos     echo 1>&2 "$0: unknown '$1' option"
     78      1.1  christos     echo 1>&2 "Try '$0 --help' for more information"
     79      1.1  christos     exit 1
     80      1.1  christos     ;;
     81      1.1  christos 
     82      1.1  christos esac
     83      1.1  christos 
     84      1.1  christos # Run the given program, remember its exit status.
     85      1.1  christos "$@"; st=$?
     86      1.1  christos 
     87      1.1  christos # If it succeeded, we are done.
     88      1.1  christos test $st -eq 0 && exit 0
     89      1.1  christos 
     90      1.1  christos # Also exit now if we it failed (or wasn't found), and '--version' was
     91      1.1  christos # passed; such an option is passed most likely to detect whether the
     92      1.1  christos # program is present and works.
     93      1.1  christos case $2 in --version|--help) exit $st;; esac
     94      1.1  christos 
     95      1.1  christos # Exit code 63 means version mismatch.  This often happens when the user
     96      1.1  christos # tries to use an ancient version of a tool on a file that requires a
     97      1.1  christos # minimum version.
     98      1.1  christos if test $st -eq 63; then
     99      1.1  christos   msg="probably too old"
    100      1.1  christos elif test $st -eq 127; then
    101      1.1  christos   # Program was missing.
    102      1.1  christos   msg="missing on your system"
    103      1.1  christos else
    104      1.1  christos   # Program was found and executed, but failed.  Give up.
    105      1.1  christos   exit $st
    106      1.1  christos fi
    107      1.1  christos 
    108      1.1  christos perl_URL=https://www.perl.org/
    109      1.1  christos flex_URL=https://github.com/westes/flex
    110      1.1  christos gnu_software_URL=https://www.gnu.org/software
    111      1.1  christos 
    112      1.1  christos program_details ()
    113      1.1  christos {
    114      1.1  christos   case $1 in
    115  1.1.1.2  christos     aclocal|automake|autoreconf)
    116      1.1  christos       echo "The '$1' program is part of the GNU Automake package:"
    117      1.1  christos       echo "<$gnu_software_URL/automake>"
    118      1.1  christos       echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
    119      1.1  christos       echo "<$gnu_software_URL/autoconf>"
    120      1.1  christos       echo "<$gnu_software_URL/m4/>"
    121      1.1  christos       echo "<$perl_URL>"
    122      1.1  christos       ;;
    123      1.1  christos     autoconf|autom4te|autoheader)
    124      1.1  christos       echo "The '$1' program is part of the GNU Autoconf package:"
    125      1.1  christos       echo "<$gnu_software_URL/autoconf/>"
    126      1.1  christos       echo "It also requires GNU m4 and Perl in order to run:"
    127      1.1  christos       echo "<$gnu_software_URL/m4/>"
    128      1.1  christos       echo "<$perl_URL>"
    129      1.1  christos       ;;
    130  1.1.1.2  christos     *)
    131  1.1.1.2  christos       :
    132  1.1.1.2  christos       ;;
    133      1.1  christos   esac
    134      1.1  christos }
    135      1.1  christos 
    136      1.1  christos give_advice ()
    137      1.1  christos {
    138      1.1  christos   # Normalize program name to check for.
    139      1.1  christos   normalized_program=`echo "$1" | sed '
    140      1.1  christos     s/^gnu-//; t
    141      1.1  christos     s/^gnu//; t
    142      1.1  christos     s/^g//; t'`
    143      1.1  christos 
    144      1.1  christos   printf '%s\n' "'$1' is $msg."
    145      1.1  christos 
    146      1.1  christos   configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
    147  1.1.1.2  christos   autoheader_deps="'acconfig.h'"
    148  1.1.1.2  christos   automake_deps="'Makefile.am'"
    149  1.1.1.2  christos   aclocal_deps="'acinclude.m4'"
    150      1.1  christos   case $normalized_program in
    151  1.1.1.2  christos     aclocal*)
    152  1.1.1.2  christos       echo "You should only need it if you modified $aclocal_deps or"
    153  1.1.1.2  christos       echo "$configure_deps."
    154  1.1.1.2  christos       ;;
    155      1.1  christos     autoconf*)
    156  1.1.1.2  christos       echo "You should only need it if you modified $configure_deps."
    157  1.1.1.2  christos       ;;
    158  1.1.1.2  christos     autogen*)
    159  1.1.1.2  christos       echo "You should only need it if you modified a '.def' or '.tpl' file."
    160  1.1.1.2  christos       echo "You may want to install the GNU AutoGen package:"
    161  1.1.1.2  christos       echo "<$gnu_software_URL/autogen/>"
    162      1.1  christos       ;;
    163      1.1  christos     autoheader*)
    164  1.1.1.2  christos       echo "You should only need it if you modified $autoheader_deps or"
    165      1.1  christos       echo "$configure_deps."
    166      1.1  christos       ;;
    167      1.1  christos     automake*)
    168  1.1.1.2  christos       echo "You should only need it if you modified $automake_deps or"
    169      1.1  christos       echo "$configure_deps."
    170      1.1  christos       ;;
    171  1.1.1.2  christos     autom4te*)
    172      1.1  christos       echo "You might have modified some maintainer files that require"
    173      1.1  christos       echo "the 'autom4te' program to be rebuilt."
    174  1.1.1.2  christos       ;;
    175  1.1.1.2  christos     autoreconf*)
    176  1.1.1.2  christos       echo "You should only need it if you modified $aclocal_deps or"
    177  1.1.1.2  christos       echo "$automake_deps or $autoheader_deps or $automake_deps or"
    178  1.1.1.2  christos       echo "$configure_deps."
    179      1.1  christos       ;;
    180      1.1  christos     bison*|yacc*)
    181      1.1  christos       echo "You should only need it if you modified a '.y' file."
    182      1.1  christos       echo "You may want to install the GNU Bison package:"
    183      1.1  christos       echo "<$gnu_software_URL/bison/>"
    184      1.1  christos       ;;
    185      1.1  christos     help2man*)
    186      1.1  christos       echo "You should only need it if you modified a dependency" \
    187      1.1  christos            "of a man page."
    188      1.1  christos       echo "You may want to install the GNU Help2man package:"
    189      1.1  christos       echo "<$gnu_software_URL/help2man/>"
    190      1.1  christos     ;;
    191  1.1.1.2  christos     lex*|flex*)
    192  1.1.1.2  christos       echo "You should only need it if you modified a '.l' file."
    193  1.1.1.2  christos       echo "You may want to install the Fast Lexical Analyzer package:"
    194  1.1.1.2  christos       echo "<$flex_URL>"
    195  1.1.1.2  christos       ;;
    196      1.1  christos     makeinfo*)
    197      1.1  christos       echo "You should only need it if you modified a '.texi' file, or"
    198      1.1  christos       echo "any other file indirectly affecting the aspect of the manual."
    199      1.1  christos       echo "You might want to install the Texinfo package:"
    200      1.1  christos       echo "<$gnu_software_URL/texinfo/>"
    201      1.1  christos       echo "The spurious makeinfo call might also be the consequence of"
    202      1.1  christos       echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
    203      1.1  christos       echo "want to install GNU make:"
    204      1.1  christos       echo "<$gnu_software_URL/make/>"
    205      1.1  christos       ;;
    206  1.1.1.2  christos     perl*)
    207  1.1.1.2  christos       echo "You should only need it to run GNU Autoconf, GNU Automake, "
    208  1.1.1.2  christos       echo "  assorted other tools, or if you modified a Perl source file."
    209  1.1.1.2  christos       echo "You may want to install the Perl 5 language interpreter:"
    210  1.1.1.2  christos       echo "<$perl_URL>"
    211  1.1.1.2  christos       ;;
    212      1.1  christos     *)
    213      1.1  christos       echo "You might have modified some files without having the proper"
    214      1.1  christos       echo "tools for further handling them.  Check the 'README' file, it"
    215      1.1  christos       echo "often tells you about the needed prerequisites for installing"
    216      1.1  christos       echo "this package.  You may also peek at any GNU archive site, in"
    217      1.1  christos       echo "case some other package contains this missing '$1' program."
    218      1.1  christos       ;;
    219      1.1  christos   esac
    220  1.1.1.2  christos   program_details "$normalized_program"
    221      1.1  christos }
    222      1.1  christos 
    223      1.1  christos give_advice "$1" | sed -e '1s/^/WARNING: /' \
    224      1.1  christos                        -e '2,$s/^/         /' >&2
    225      1.1  christos 
    226      1.1  christos # Propagate the correct exit status (expected to be 127 for a program
    227      1.1  christos # not found, 63 for a program that failed due to version mismatch).
    228      1.1  christos exit $st
    229      1.1  christos 
    230      1.1  christos # Local variables:
    231      1.1  christos # eval: (add-hook 'before-save-hook 'time-stamp)
    232      1.1  christos # time-stamp-start: "scriptversion="
    233      1.1  christos # time-stamp-format: "%:y-%02m-%02d.%02H"
    234      1.1  christos # time-stamp-time-zone: "UTC0"
    235      1.1  christos # time-stamp-end: "; # UTC"
    236      1.1  christos # End:
    237