Annotation of parser3/missing, revision 1.5

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

E-mail: