11cb0ef41Sopenharmony_ci#! /bin/sh
21cb0ef41Sopenharmony_ci# Common wrapper for a few potentially missing GNU programs.
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciscriptversion=2018-03-07.03; # UTC
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci# Copyright (C) 1996-2021 Free Software Foundation, Inc.
71cb0ef41Sopenharmony_ci# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci# This program is free software; you can redistribute it and/or modify
101cb0ef41Sopenharmony_ci# it under the terms of the GNU General Public License as published by
111cb0ef41Sopenharmony_ci# the Free Software Foundation; either version 2, or (at your option)
121cb0ef41Sopenharmony_ci# any later version.
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci# This program is distributed in the hope that it will be useful,
151cb0ef41Sopenharmony_ci# but WITHOUT ANY WARRANTY; without even the implied warranty of
161cb0ef41Sopenharmony_ci# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
171cb0ef41Sopenharmony_ci# GNU General Public License for more details.
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci# You should have received a copy of the GNU General Public License
201cb0ef41Sopenharmony_ci# along with this program.  If not, see <https://www.gnu.org/licenses/>.
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci# As a special exception to the GNU General Public License, if you
231cb0ef41Sopenharmony_ci# distribute this file as part of a program that contains a
241cb0ef41Sopenharmony_ci# configuration script generated by Autoconf, you may include it under
251cb0ef41Sopenharmony_ci# the same distribution terms that you use for the rest of that program.
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciif test $# -eq 0; then
281cb0ef41Sopenharmony_ci  echo 1>&2 "Try '$0 --help' for more information"
291cb0ef41Sopenharmony_ci  exit 1
301cb0ef41Sopenharmony_cifi
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_cicase $1 in
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  --is-lightweight)
351cb0ef41Sopenharmony_ci    # Used by our autoconf macros to check whether the available missing
361cb0ef41Sopenharmony_ci    # script is modern enough.
371cb0ef41Sopenharmony_ci    exit 0
381cb0ef41Sopenharmony_ci    ;;
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  --run)
411cb0ef41Sopenharmony_ci    # Back-compat with the calling convention used by older automake.
421cb0ef41Sopenharmony_ci    shift
431cb0ef41Sopenharmony_ci    ;;
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  -h|--h|--he|--hel|--help)
461cb0ef41Sopenharmony_ci    echo "\
471cb0ef41Sopenharmony_ci$0 [OPTION]... PROGRAM [ARGUMENT]...
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ciRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
501cb0ef41Sopenharmony_cito PROGRAM being missing or too old.
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ciOptions:
531cb0ef41Sopenharmony_ci  -h, --help      display this help and exit
541cb0ef41Sopenharmony_ci  -v, --version   output version information and exit
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ciSupported PROGRAM values:
571cb0ef41Sopenharmony_ci  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
581cb0ef41Sopenharmony_ci  bison     yacc      flex         lex       help2man
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ciVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
611cb0ef41Sopenharmony_ci'g' are ignored when checking the name.
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ciSend bug reports to <bug-automake@gnu.org>."
641cb0ef41Sopenharmony_ci    exit $?
651cb0ef41Sopenharmony_ci    ;;
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
681cb0ef41Sopenharmony_ci    echo "missing $scriptversion (GNU Automake)"
691cb0ef41Sopenharmony_ci    exit $?
701cb0ef41Sopenharmony_ci    ;;
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci  -*)
731cb0ef41Sopenharmony_ci    echo 1>&2 "$0: unknown '$1' option"
741cb0ef41Sopenharmony_ci    echo 1>&2 "Try '$0 --help' for more information"
751cb0ef41Sopenharmony_ci    exit 1
761cb0ef41Sopenharmony_ci    ;;
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ciesac
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci# Run the given program, remember its exit status.
811cb0ef41Sopenharmony_ci"$@"; st=$?
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci# If it succeeded, we are done.
841cb0ef41Sopenharmony_citest $st -eq 0 && exit 0
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci# Also exit now if we it failed (or wasn't found), and '--version' was
871cb0ef41Sopenharmony_ci# passed; such an option is passed most likely to detect whether the
881cb0ef41Sopenharmony_ci# program is present and works.
891cb0ef41Sopenharmony_cicase $2 in --version|--help) exit $st;; esac
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci# Exit code 63 means version mismatch.  This often happens when the user
921cb0ef41Sopenharmony_ci# tries to use an ancient version of a tool on a file that requires a
931cb0ef41Sopenharmony_ci# minimum version.
941cb0ef41Sopenharmony_ciif test $st -eq 63; then
951cb0ef41Sopenharmony_ci  msg="probably too old"
961cb0ef41Sopenharmony_cielif test $st -eq 127; then
971cb0ef41Sopenharmony_ci  # Program was missing.
981cb0ef41Sopenharmony_ci  msg="missing on your system"
991cb0ef41Sopenharmony_cielse
1001cb0ef41Sopenharmony_ci  # Program was found and executed, but failed.  Give up.
1011cb0ef41Sopenharmony_ci  exit $st
1021cb0ef41Sopenharmony_cifi
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ciperl_URL=https://www.perl.org/
1051cb0ef41Sopenharmony_ciflex_URL=https://github.com/westes/flex
1061cb0ef41Sopenharmony_cignu_software_URL=https://www.gnu.org/software
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_ciprogram_details ()
1091cb0ef41Sopenharmony_ci{
1101cb0ef41Sopenharmony_ci  case $1 in
1111cb0ef41Sopenharmony_ci    aclocal|automake)
1121cb0ef41Sopenharmony_ci      echo "The '$1' program is part of the GNU Automake package:"
1131cb0ef41Sopenharmony_ci      echo "<$gnu_software_URL/automake>"
1141cb0ef41Sopenharmony_ci      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
1151cb0ef41Sopenharmony_ci      echo "<$gnu_software_URL/autoconf>"
1161cb0ef41Sopenharmony_ci      echo "<$gnu_software_URL/m4/>"
1171cb0ef41Sopenharmony_ci      echo "<$perl_URL>"
1181cb0ef41Sopenharmony_ci      ;;
1191cb0ef41Sopenharmony_ci    autoconf|autom4te|autoheader)
1201cb0ef41Sopenharmony_ci      echo "The '$1' program is part of the GNU Autoconf package:"
1211cb0ef41Sopenharmony_ci      echo "<$gnu_software_URL/autoconf/>"
1221cb0ef41Sopenharmony_ci      echo "It also requires GNU m4 and Perl in order to run:"
1231cb0ef41Sopenharmony_ci      echo "<$gnu_software_URL/m4/>"
1241cb0ef41Sopenharmony_ci      echo "<$perl_URL>"
1251cb0ef41Sopenharmony_ci      ;;
1261cb0ef41Sopenharmony_ci  esac
1271cb0ef41Sopenharmony_ci}
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_cigive_advice ()
1301cb0ef41Sopenharmony_ci{
1311cb0ef41Sopenharmony_ci  # Normalize program name to check for.
1321cb0ef41Sopenharmony_ci  normalized_program=`echo "$1" | sed '
1331cb0ef41Sopenharmony_ci    s/^gnu-//; t
1341cb0ef41Sopenharmony_ci    s/^gnu//; t
1351cb0ef41Sopenharmony_ci    s/^g//; t'`
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci  printf '%s\n' "'$1' is $msg."
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
1401cb0ef41Sopenharmony_ci  case $normalized_program in
1411cb0ef41Sopenharmony_ci    autoconf*)
1421cb0ef41Sopenharmony_ci      echo "You should only need it if you modified 'configure.ac',"
1431cb0ef41Sopenharmony_ci      echo "or m4 files included by it."
1441cb0ef41Sopenharmony_ci      program_details 'autoconf'
1451cb0ef41Sopenharmony_ci      ;;
1461cb0ef41Sopenharmony_ci    autoheader*)
1471cb0ef41Sopenharmony_ci      echo "You should only need it if you modified 'acconfig.h' or"
1481cb0ef41Sopenharmony_ci      echo "$configure_deps."
1491cb0ef41Sopenharmony_ci      program_details 'autoheader'
1501cb0ef41Sopenharmony_ci      ;;
1511cb0ef41Sopenharmony_ci    automake*)
1521cb0ef41Sopenharmony_ci      echo "You should only need it if you modified 'Makefile.am' or"
1531cb0ef41Sopenharmony_ci      echo "$configure_deps."
1541cb0ef41Sopenharmony_ci      program_details 'automake'
1551cb0ef41Sopenharmony_ci      ;;
1561cb0ef41Sopenharmony_ci    aclocal*)
1571cb0ef41Sopenharmony_ci      echo "You should only need it if you modified 'acinclude.m4' or"
1581cb0ef41Sopenharmony_ci      echo "$configure_deps."
1591cb0ef41Sopenharmony_ci      program_details 'aclocal'
1601cb0ef41Sopenharmony_ci      ;;
1611cb0ef41Sopenharmony_ci   autom4te*)
1621cb0ef41Sopenharmony_ci      echo "You might have modified some maintainer files that require"
1631cb0ef41Sopenharmony_ci      echo "the 'autom4te' program to be rebuilt."
1641cb0ef41Sopenharmony_ci      program_details 'autom4te'
1651cb0ef41Sopenharmony_ci      ;;
1661cb0ef41Sopenharmony_ci    bison*|yacc*)
1671cb0ef41Sopenharmony_ci      echo "You should only need it if you modified a '.y' file."
1681cb0ef41Sopenharmony_ci      echo "You may want to install the GNU Bison package:"
1691cb0ef41Sopenharmony_ci      echo "<$gnu_software_URL/bison/>"
1701cb0ef41Sopenharmony_ci      ;;
1711cb0ef41Sopenharmony_ci    lex*|flex*)
1721cb0ef41Sopenharmony_ci      echo "You should only need it if you modified a '.l' file."
1731cb0ef41Sopenharmony_ci      echo "You may want to install the Fast Lexical Analyzer package:"
1741cb0ef41Sopenharmony_ci      echo "<$flex_URL>"
1751cb0ef41Sopenharmony_ci      ;;
1761cb0ef41Sopenharmony_ci    help2man*)
1771cb0ef41Sopenharmony_ci      echo "You should only need it if you modified a dependency" \
1781cb0ef41Sopenharmony_ci           "of a man page."
1791cb0ef41Sopenharmony_ci      echo "You may want to install the GNU Help2man package:"
1801cb0ef41Sopenharmony_ci      echo "<$gnu_software_URL/help2man/>"
1811cb0ef41Sopenharmony_ci    ;;
1821cb0ef41Sopenharmony_ci    makeinfo*)
1831cb0ef41Sopenharmony_ci      echo "You should only need it if you modified a '.texi' file, or"
1841cb0ef41Sopenharmony_ci      echo "any other file indirectly affecting the aspect of the manual."
1851cb0ef41Sopenharmony_ci      echo "You might want to install the Texinfo package:"
1861cb0ef41Sopenharmony_ci      echo "<$gnu_software_URL/texinfo/>"
1871cb0ef41Sopenharmony_ci      echo "The spurious makeinfo call might also be the consequence of"
1881cb0ef41Sopenharmony_ci      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
1891cb0ef41Sopenharmony_ci      echo "want to install GNU make:"
1901cb0ef41Sopenharmony_ci      echo "<$gnu_software_URL/make/>"
1911cb0ef41Sopenharmony_ci      ;;
1921cb0ef41Sopenharmony_ci    *)
1931cb0ef41Sopenharmony_ci      echo "You might have modified some files without having the proper"
1941cb0ef41Sopenharmony_ci      echo "tools for further handling them.  Check the 'README' file, it"
1951cb0ef41Sopenharmony_ci      echo "often tells you about the needed prerequisites for installing"
1961cb0ef41Sopenharmony_ci      echo "this package.  You may also peek at any GNU archive site, in"
1971cb0ef41Sopenharmony_ci      echo "case some other package contains this missing '$1' program."
1981cb0ef41Sopenharmony_ci      ;;
1991cb0ef41Sopenharmony_ci  esac
2001cb0ef41Sopenharmony_ci}
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_cigive_advice "$1" | sed -e '1s/^/WARNING: /' \
2031cb0ef41Sopenharmony_ci                       -e '2,$s/^/         /' >&2
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ci# Propagate the correct exit status (expected to be 127 for a program
2061cb0ef41Sopenharmony_ci# not found, 63 for a program that failed due to version mismatch).
2071cb0ef41Sopenharmony_ciexit $st
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_ci# Local variables:
2101cb0ef41Sopenharmony_ci# eval: (add-hook 'before-save-hook 'time-stamp)
2111cb0ef41Sopenharmony_ci# time-stamp-start: "scriptversion="
2121cb0ef41Sopenharmony_ci# time-stamp-format: "%:y-%02m-%02d.%02H"
2131cb0ef41Sopenharmony_ci# time-stamp-time-zone: "UTC0"
2141cb0ef41Sopenharmony_ci# time-stamp-end: "; # UTC"
2151cb0ef41Sopenharmony_ci# End:
216