176404edcSAsim Jamshed#! /bin/sh
2d270d183SAsim Jamshed# Common wrapper for a few potentially missing GNU programs.
376404edcSAsim Jamshed
4d270d183SAsim Jamshedscriptversion=2013-10-28.13; # UTC
576404edcSAsim Jamshed
6d270d183SAsim Jamshed# Copyright (C) 1996-2014 Free Software Foundation, Inc.
7d270d183SAsim Jamshed# Originally written by Fran,cois Pinard <[email protected]>, 1996.
876404edcSAsim Jamshed
976404edcSAsim Jamshed# This program is free software; you can redistribute it and/or modify
1076404edcSAsim Jamshed# it under the terms of the GNU General Public License as published by
1176404edcSAsim Jamshed# the Free Software Foundation; either version 2, or (at your option)
1276404edcSAsim Jamshed# any later version.
1376404edcSAsim Jamshed
1476404edcSAsim Jamshed# This program is distributed in the hope that it will be useful,
1576404edcSAsim Jamshed# but WITHOUT ANY WARRANTY; without even the implied warranty of
1676404edcSAsim Jamshed# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1776404edcSAsim Jamshed# GNU General Public License for more details.
1876404edcSAsim Jamshed
1976404edcSAsim Jamshed# You should have received a copy of the GNU General Public License
2076404edcSAsim Jamshed# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2176404edcSAsim Jamshed
2276404edcSAsim Jamshed# As a special exception to the GNU General Public License, if you
2376404edcSAsim Jamshed# distribute this file as part of a program that contains a
2476404edcSAsim Jamshed# configuration script generated by Autoconf, you may include it under
2576404edcSAsim Jamshed# the same distribution terms that you use for the rest of that program.
2676404edcSAsim Jamshed
2776404edcSAsim Jamshedif test $# -eq 0; then
28d270d183SAsim Jamshed  echo 1>&2 "Try '$0 --help' for more information"
2976404edcSAsim Jamshed  exit 1
3076404edcSAsim Jamshedfi
3176404edcSAsim Jamshed
3276404edcSAsim Jamshedcase $1 in
33d270d183SAsim Jamshed
34d270d183SAsim Jamshed  --is-lightweight)
35d270d183SAsim Jamshed    # Used by our autoconf macros to check whether the available missing
36d270d183SAsim Jamshed    # script is modern enough.
37d270d183SAsim Jamshed    exit 0
38d270d183SAsim Jamshed    ;;
39d270d183SAsim Jamshed
4076404edcSAsim Jamshed  --run)
41d270d183SAsim Jamshed    # Back-compat with the calling convention used by older automake.
4276404edcSAsim Jamshed    shift
4376404edcSAsim Jamshed    ;;
4476404edcSAsim Jamshed
4576404edcSAsim Jamshed  -h|--h|--he|--hel|--help)
4676404edcSAsim Jamshed    echo "\
4776404edcSAsim Jamshed$0 [OPTION]... PROGRAM [ARGUMENT]...
4876404edcSAsim Jamshed
49d270d183SAsim JamshedRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50d270d183SAsim Jamshedto PROGRAM being missing or too old.
5176404edcSAsim Jamshed
5276404edcSAsim JamshedOptions:
5376404edcSAsim Jamshed  -h, --help      display this help and exit
5476404edcSAsim Jamshed  -v, --version   output version information and exit
5576404edcSAsim Jamshed
5676404edcSAsim JamshedSupported PROGRAM values:
57d270d183SAsim Jamshed  aclocal   autoconf  autoheader   autom4te  automake  makeinfo
58d270d183SAsim Jamshed  bison     yacc      flex         lex       help2man
5976404edcSAsim Jamshed
60d270d183SAsim JamshedVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61d270d183SAsim Jamshed'g' are ignored when checking the name.
6276404edcSAsim Jamshed
6376404edcSAsim JamshedSend bug reports to <[email protected]>."
6476404edcSAsim Jamshed    exit $?
6576404edcSAsim Jamshed    ;;
6676404edcSAsim Jamshed
6776404edcSAsim Jamshed  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
6876404edcSAsim Jamshed    echo "missing $scriptversion (GNU Automake)"
6976404edcSAsim Jamshed    exit $?
7076404edcSAsim Jamshed    ;;
7176404edcSAsim Jamshed
7276404edcSAsim Jamshed  -*)
73d270d183SAsim Jamshed    echo 1>&2 "$0: unknown '$1' option"
74d270d183SAsim Jamshed    echo 1>&2 "Try '$0 --help' for more information"
7576404edcSAsim Jamshed    exit 1
7676404edcSAsim Jamshed    ;;
7776404edcSAsim Jamshed
7876404edcSAsim Jamshedesac
7976404edcSAsim Jamshed
80d270d183SAsim Jamshed# Run the given program, remember its exit status.
81d270d183SAsim Jamshed"$@"; st=$?
82d270d183SAsim Jamshed
83d270d183SAsim Jamshed# If it succeeded, we are done.
84d270d183SAsim Jamshedtest $st -eq 0 && exit 0
85d270d183SAsim Jamshed
86d270d183SAsim Jamshed# Also exit now if we it failed (or wasn't found), and '--version' was
87d270d183SAsim Jamshed# passed; such an option is passed most likely to detect whether the
88d270d183SAsim Jamshed# program is present and works.
89d270d183SAsim Jamshedcase $2 in --version|--help) exit $st;; esac
90d270d183SAsim Jamshed
91d270d183SAsim Jamshed# Exit code 63 means version mismatch.  This often happens when the user
92d270d183SAsim Jamshed# tries to use an ancient version of a tool on a file that requires a
93d270d183SAsim Jamshed# minimum version.
94d270d183SAsim Jamshedif test $st -eq 63; then
95d270d183SAsim Jamshed  msg="probably too old"
96d270d183SAsim Jamshedelif test $st -eq 127; then
97d270d183SAsim Jamshed  # Program was missing.
98d270d183SAsim Jamshed  msg="missing on your system"
99d270d183SAsim Jamshedelse
100d270d183SAsim Jamshed  # Program was found and executed, but failed.  Give up.
101d270d183SAsim Jamshed  exit $st
102d270d183SAsim Jamshedfi
103d270d183SAsim Jamshed
104d270d183SAsim Jamshedperl_URL=http://www.perl.org/
105d270d183SAsim Jamshedflex_URL=http://flex.sourceforge.net/
106d270d183SAsim Jamshedgnu_software_URL=http://www.gnu.org/software
107d270d183SAsim Jamshed
108d270d183SAsim Jamshedprogram_details ()
109d270d183SAsim Jamshed{
110d270d183SAsim Jamshed  case $1 in
111d270d183SAsim Jamshed    aclocal|automake)
112d270d183SAsim Jamshed      echo "The '$1' program is part of the GNU Automake package:"
113d270d183SAsim Jamshed      echo "<$gnu_software_URL/automake>"
114d270d183SAsim Jamshed      echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115d270d183SAsim Jamshed      echo "<$gnu_software_URL/autoconf>"
116d270d183SAsim Jamshed      echo "<$gnu_software_URL/m4/>"
117d270d183SAsim Jamshed      echo "<$perl_URL>"
118d270d183SAsim Jamshed      ;;
119d270d183SAsim Jamshed    autoconf|autom4te|autoheader)
120d270d183SAsim Jamshed      echo "The '$1' program is part of the GNU Autoconf package:"
121d270d183SAsim Jamshed      echo "<$gnu_software_URL/autoconf/>"
122d270d183SAsim Jamshed      echo "It also requires GNU m4 and Perl in order to run:"
123d270d183SAsim Jamshed      echo "<$gnu_software_URL/m4/>"
124d270d183SAsim Jamshed      echo "<$perl_URL>"
125d270d183SAsim Jamshed      ;;
126d270d183SAsim Jamshed  esac
127d270d183SAsim Jamshed}
128d270d183SAsim Jamshed
129d270d183SAsim Jamshedgive_advice ()
130d270d183SAsim Jamshed{
131d270d183SAsim Jamshed  # Normalize program name to check for.
132d270d183SAsim Jamshed  normalized_program=`echo "$1" | sed '
13376404edcSAsim Jamshed    s/^gnu-//; t
13476404edcSAsim Jamshed    s/^gnu//; t
13576404edcSAsim Jamshed    s/^g//; t'`
13676404edcSAsim Jamshed
137d270d183SAsim Jamshed  printf '%s\n' "'$1' is $msg."
13876404edcSAsim Jamshed
139d270d183SAsim Jamshed  configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140d270d183SAsim Jamshed  case $normalized_program in
14176404edcSAsim Jamshed    autoconf*)
142d270d183SAsim Jamshed      echo "You should only need it if you modified 'configure.ac',"
143d270d183SAsim Jamshed      echo "or m4 files included by it."
144d270d183SAsim Jamshed      program_details 'autoconf'
14576404edcSAsim Jamshed      ;;
14676404edcSAsim Jamshed    autoheader*)
147d270d183SAsim Jamshed      echo "You should only need it if you modified 'acconfig.h' or"
148d270d183SAsim Jamshed      echo "$configure_deps."
149d270d183SAsim Jamshed      program_details 'autoheader'
15076404edcSAsim Jamshed      ;;
15176404edcSAsim Jamshed    automake*)
152d270d183SAsim Jamshed      echo "You should only need it if you modified 'Makefile.am' or"
153d270d183SAsim Jamshed      echo "$configure_deps."
154d270d183SAsim Jamshed      program_details 'automake'
15576404edcSAsim Jamshed      ;;
156d270d183SAsim Jamshed    aclocal*)
157d270d183SAsim Jamshed      echo "You should only need it if you modified 'acinclude.m4' or"
158d270d183SAsim Jamshed      echo "$configure_deps."
159d270d183SAsim Jamshed      program_details 'aclocal'
160d270d183SAsim Jamshed      ;;
16176404edcSAsim Jamshed   autom4te*)
162d270d183SAsim Jamshed      echo "You might have modified some maintainer files that require"
163d270d183SAsim Jamshed      echo "the 'autom4te' program to be rebuilt."
164d270d183SAsim Jamshed      program_details 'autom4te'
16576404edcSAsim Jamshed      ;;
16676404edcSAsim Jamshed    bison*|yacc*)
167d270d183SAsim Jamshed      echo "You should only need it if you modified a '.y' file."
168d270d183SAsim Jamshed      echo "You may want to install the GNU Bison package:"
169d270d183SAsim Jamshed      echo "<$gnu_software_URL/bison/>"
17076404edcSAsim Jamshed      ;;
17176404edcSAsim Jamshed    lex*|flex*)
172d270d183SAsim Jamshed      echo "You should only need it if you modified a '.l' file."
173d270d183SAsim Jamshed      echo "You may want to install the Fast Lexical Analyzer package:"
174d270d183SAsim Jamshed      echo "<$flex_URL>"
17576404edcSAsim Jamshed      ;;
17676404edcSAsim Jamshed    help2man*)
177d270d183SAsim Jamshed      echo "You should only need it if you modified a dependency" \
178d270d183SAsim Jamshed           "of a man page."
179d270d183SAsim Jamshed      echo "You may want to install the GNU Help2man package:"
180d270d183SAsim Jamshed      echo "<$gnu_software_URL/help2man/>"
18176404edcSAsim Jamshed    ;;
18276404edcSAsim Jamshed    makeinfo*)
183d270d183SAsim Jamshed      echo "You should only need it if you modified a '.texi' file, or"
184d270d183SAsim Jamshed      echo "any other file indirectly affecting the aspect of the manual."
185d270d183SAsim Jamshed      echo "You might want to install the Texinfo package:"
186d270d183SAsim Jamshed      echo "<$gnu_software_URL/texinfo/>"
187d270d183SAsim Jamshed      echo "The spurious makeinfo call might also be the consequence of"
188d270d183SAsim Jamshed      echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189d270d183SAsim Jamshed      echo "want to install GNU make:"
190d270d183SAsim Jamshed      echo "<$gnu_software_URL/make/>"
19176404edcSAsim Jamshed      ;;
19276404edcSAsim Jamshed    *)
193d270d183SAsim Jamshed      echo "You might have modified some files without having the proper"
194d270d183SAsim Jamshed      echo "tools for further handling them.  Check the 'README' file, it"
195d270d183SAsim Jamshed      echo "often tells you about the needed prerequisites for installing"
196d270d183SAsim Jamshed      echo "this package.  You may also peek at any GNU archive site, in"
197d270d183SAsim Jamshed      echo "case some other package contains this missing '$1' program."
19876404edcSAsim Jamshed      ;;
19976404edcSAsim Jamshed  esac
200d270d183SAsim Jamshed}
20176404edcSAsim Jamshed
202d270d183SAsim Jamshedgive_advice "$1" | sed -e '1s/^/WARNING: /' \
203d270d183SAsim Jamshed                       -e '2,$s/^/         /' >&2
204d270d183SAsim Jamshed
205d270d183SAsim Jamshed# Propagate the correct exit status (expected to be 127 for a program
206d270d183SAsim Jamshed# not found, 63 for a program that failed due to version mismatch).
207d270d183SAsim Jamshedexit $st
20876404edcSAsim Jamshed
20976404edcSAsim Jamshed# Local variables:
21076404edcSAsim Jamshed# eval: (add-hook 'write-file-hooks 'time-stamp)
21176404edcSAsim Jamshed# time-stamp-start: "scriptversion="
21276404edcSAsim Jamshed# time-stamp-format: "%:y-%02m-%02d.%02H"
21376404edcSAsim Jamshed# time-stamp-time-zone: "UTC"
21476404edcSAsim Jamshed# time-stamp-end: "; # UTC"
21576404edcSAsim Jamshed# End:
216