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