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