1#! /bin/sh
2# Common stub for a few missing GNU programs while installing.
3
4scriptversion=2005-02-08.22
5
6# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005
7#   Free Software Foundation, Inc.
8# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
9
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2, or (at your option)
13# any later version.
14
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software Foundation,
22# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
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
29if test $# -eq 0; then
30  echo 1>&2 "Try \`$0 --help' for more information"
31  exit 1
32fi
33
34run=:
35
36# In the cases where this matters, `missing' is being run in the
37# srcdir already.
38if test -f configure.ac; then
39  configure_ac=configure.ac
40else
41  configure_ac=configure.in
42fi
43
44msg="missing on your system"
45
46case "$1" in
47--run)
48  # Try to run requested program, and just exit if it succeeds.
49  run=
50  shift
51  "$@" && exit 0
52  # Exit code 63 means version mismatch.  This often happens
53  # when the user try to use an ancient version of a tool on
54  # a file that requires a minimum version.  In this case we
55  # we should proceed has if the program had been absent, or
56  # if --run hadn't been passed.
57  if test $? = 63; then
58    run=:
59    msg="probably too old"
60  fi
61  ;;
62
63  -h|--h|--he|--hel|--help)
64    echo "\
65$0 [OPTION]... PROGRAM [ARGUMENT]...
66
67Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
68error status if there is no known handling for PROGRAM.
69
70Options:
71  -h, --help      display this help and exit
72  -v, --version   output version information and exit
73  --run           try to run the given command, and emulate it if it fails
74
75Supported PROGRAM values:
76  aclocal      touch file \`aclocal.m4'
77  autoconf     touch file \`configure'
78  autoheader   touch file \`config.h.in'
79  automake     touch all \`Makefile.in' files
80  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
81  flex         create \`lex.yy.c', if possible, from existing .c
82  help2man     touch the output file
83  lex          create \`lex.yy.c', if possible, from existing .c
84  makeinfo     touch the output file
85  tar          try tar, gnutar, gtar, then tar without non-portable flags
86  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
87
88Send bug reports to <bug-automake@gnu.org>."
89    exit $?
90    ;;
91
92  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
93    echo "missing $scriptversion (GNU Automake)"
94    exit $?
95    ;;
96
97  -*)
98    echo 1>&2 "$0: Unknown \`$1' option"
99    echo 1>&2 "Try \`$0 --help' for more information"
100    exit 1
101    ;;
102
103esac
104
105# Now exit if we have it, but it failed.  Also exit now if we
106# don't have it and --version was passed (most likely to detect
107# the program).
108case "$1" in
109  lex|yacc)
110    # Not GNU programs, they don't have --version.
111    ;;
112
113  tar)
114    if test -n "$run"; then
115       echo 1>&2 "ERROR: \`tar' requires --run"
116       exit 1
117    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
118       exit 1
119    fi
120    ;;
121
122  *)
123    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
124       # We have it, but it failed.
125       exit 1
126    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
127       # Could not run --version or --help.  This is probably someone
128       # running `$TOOL --version' or `$TOOL --help' to check whether
129       # $TOOL exists and not knowing $TOOL uses missing.
130       exit 1
131    fi
132    ;;
133esac
134
135# If it does not exist, or fails to run (possibly an outdated version),
136# try to emulate it.
137case "$1" in
138  aclocal*)
139    echo 1>&2 "\
140WARNING: \`$1' is $msg.  You should only need it if
141         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
142         to install the \`Automake' and \`Perl' packages.  Grab them from
143         any GNU archive site."
144    touch aclocal.m4
145    ;;
146
147  autoconf)
148    echo 1>&2 "\
149WARNING: \`$1' is $msg.  You should only need it if
150         you modified \`${configure_ac}'.  You might want to install the
151         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
152         archive site."
153    touch configure
154    ;;
155
156  autoheader)
157    echo 1>&2 "\
158WARNING: \`$1' is $msg.  You should only need it if
159         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
160         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
161         from any GNU archive site."
162    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
163    test -z "$files" && files="config.h"
164    touch_files=
165    for f in $files; do
166      case "$f" in
167      *:*) touch_files="$touch_files "`echo "$f" |
168				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
169      *) touch_files="$touch_files $f.in";;
170      esac
171    done
172    touch $touch_files
173    ;;
174
175  automake*)
176    echo 1>&2 "\
177WARNING: \`$1' is $msg.  You should only need it if
178         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
179         You might want to install the \`Automake' and \`Perl' packages.
180         Grab them from any GNU archive site."
181    find . -type f -name Makefile.am -print |
182	   sed 's/\.am$/.in/' |
183	   while read f; do touch "$f"; done
184    ;;
185
186  autom4te)
187    echo 1>&2 "\
188WARNING: \`$1' is needed, but is $msg.
189         You might have modified some files without having the
190         proper tools for further handling them.
191         You can get \`$1' as part of \`Autoconf' from any GNU
192         archive site."
193
194    file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
195    test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'`
196    if test -f "$file"; then
197	touch $file
198    else
199	test -z "$file" || exec >$file
200	echo "#! /bin/sh"
201	echo "# Created by GNU Automake missing as a replacement of"
202	echo "#  $ $@"
203	echo "exit 0"
204	chmod +x $file
205	exit 1
206    fi
207    ;;
208
209  bison|yacc)
210    echo 1>&2 "\
211WARNING: \`$1' $msg.  You should only need it if
212         you modified a \`.y' file.  You may need the \`Bison' package
213         in order for those modifications to take effect.  You can get
214         \`Bison' from any GNU archive site."
215    rm -f y.tab.c y.tab.h
216    if [ $# -ne 1 ]; then
217        eval LASTARG="\${$#}"
218	case "$LASTARG" in
219	*.y)
220	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
221	    if [ -f "$SRCFILE" ]; then
222	         cp "$SRCFILE" y.tab.c
223	    fi
224	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
225	    if [ -f "$SRCFILE" ]; then
226	         cp "$SRCFILE" y.tab.h
227	    fi
228	  ;;
229	esac
230    fi
231    if [ ! -f y.tab.h ]; then
232	echo >y.tab.h
233    fi
234    if [ ! -f y.tab.c ]; then
235	echo 'main() { return 0; }' >y.tab.c
236    fi
237    ;;
238
239  lex|flex)
240    echo 1>&2 "\
241WARNING: \`$1' is $msg.  You should only need it if
242         you modified a \`.l' file.  You may need the \`Flex' package
243         in order for those modifications to take effect.  You can get
244         \`Flex' from any GNU archive site."
245    rm -f lex.yy.c
246    if [ $# -ne 1 ]; then
247        eval LASTARG="\${$#}"
248	case "$LASTARG" in
249	*.l)
250	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
251	    if [ -f "$SRCFILE" ]; then
252	         cp "$SRCFILE" lex.yy.c
253	    fi
254	  ;;
255	esac
256    fi
257    if [ ! -f lex.yy.c ]; then
258	echo 'main() { return 0; }' >lex.yy.c
259    fi
260    ;;
261
262  help2man)
263    echo 1>&2 "\
264WARNING: \`$1' is $msg.  You should only need it if
265	 you modified a dependency of a manual page.  You may need the
266	 \`Help2man' package in order for those modifications to take
267	 effect.  You can get \`Help2man' from any GNU archive site."
268
269    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
270    if test -z "$file"; then
271	file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
272    fi
273    if [ -f "$file" ]; then
274	touch $file
275    else
276	test -z "$file" || exec >$file
277	echo ".ab help2man is required to generate this page"
278	exit 1
279    fi
280    ;;
281
282  makeinfo)
283    echo 1>&2 "\
284WARNING: \`$1' is $msg.  You should only need it if
285         you modified a \`.texi' or \`.texinfo' file, or any other file
286         indirectly affecting the aspect of the manual.  The spurious
287         call might also be the consequence of using a buggy \`make' (AIX,
288         DU, IRIX).  You might want to install the \`Texinfo' package or
289         the \`GNU make' package.  Grab either from any GNU archive site."
290    # The file to touch is that specified with -o ...
291    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
292    if test -z "$file"; then
293      # ... or it is the one specified with @setfilename ...
294      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
295      file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $infile`
296      # ... or it is derived from the source name (dir/f.texi becomes f.info)
297      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
298    fi
299    touch $file
300    ;;
301
302  tar)
303    shift
304
305    # We have already tried tar in the generic part.
306    # Look for gnutar/gtar before invocation to avoid ugly error
307    # messages.
308    if (gnutar --version > /dev/null 2>&1); then
309       gnutar "$@" && exit 0
310    fi
311    if (gtar --version > /dev/null 2>&1); then
312       gtar "$@" && exit 0
313    fi
314    firstarg="$1"
315    if shift; then
316	case "$firstarg" in
317	*o*)
318	    firstarg=`echo "$firstarg" | sed s/o//`
319	    tar "$firstarg" "$@" && exit 0
320	    ;;
321	esac
322	case "$firstarg" in
323	*h*)
324	    firstarg=`echo "$firstarg" | sed s/h//`
325	    tar "$firstarg" "$@" && exit 0
326	    ;;
327	esac
328    fi
329
330    echo 1>&2 "\
331WARNING: I can't seem to be able to run \`tar' with the given arguments.
332         You may want to install GNU tar or Free paxutils, or check the
333         command line arguments."
334    exit 1
335    ;;
336
337  *)
338    echo 1>&2 "\
339WARNING: \`$1' is needed, and is $msg.
340         You might have modified some files without having the
341         proper tools for further handling them.  Check the \`README' file,
342         it often tells you about the needed prerequisites for installing
343         this package.  You may also peek at any GNU archive site, in case
344         some other package would contain this missing \`$1' program."
345    exit 1
346    ;;
347esac
348
349exit 0
350
351# Local variables:
352# eval: (add-hook 'write-file-hooks 'time-stamp)
353# time-stamp-start: "scriptversion="
354# time-stamp-format: "%:y-%02m-%02d.%02H"
355# time-stamp-end: "$"
356# End:
357