1247738Sbapt#! /bin/sh
2247738Sbapt# Common stub for a few missing GNU programs while installing.
3247738Sbapt
4247738Sbaptscriptversion=2009-04-28.21; # UTC
5247738Sbapt
6247738Sbapt# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
7247738Sbapt# 2008, 2009 Free Software Foundation, Inc.
8247738Sbapt# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
9247738Sbapt
10247738Sbapt# This program is free software; you can redistribute it and/or modify
11247738Sbapt# it under the terms of the GNU General Public License as published by
12247738Sbapt# the Free Software Foundation; either version 2, or (at your option)
13247738Sbapt# any later version.
14247738Sbapt
15247738Sbapt# This program is distributed in the hope that it will be useful,
16247738Sbapt# but WITHOUT ANY WARRANTY; without even the implied warranty of
17247738Sbapt# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18247738Sbapt# GNU General Public License for more details.
19247738Sbapt
20247738Sbapt# You should have received a copy of the GNU General Public License
21247738Sbapt# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22247738Sbapt
23247738Sbapt# As a special exception to the GNU General Public License, if you
24247738Sbapt# distribute this file as part of a program that contains a
25247738Sbapt# configuration script generated by Autoconf, you may include it under
26247738Sbapt# the same distribution terms that you use for the rest of that program.
27247738Sbapt
28247738Sbaptif test $# -eq 0; then
29247738Sbapt  echo 1>&2 "Try \`$0 --help' for more information"
30247738Sbapt  exit 1
31247738Sbaptfi
32247738Sbapt
33247738Sbaptrun=:
34247738Sbaptsed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
35247738Sbaptsed_minuso='s/.* -o \([^ ]*\).*/\1/p'
36247738Sbapt
37247738Sbapt# In the cases where this matters, `missing' is being run in the
38247738Sbapt# srcdir already.
39247738Sbaptif test -f configure.ac; then
40247738Sbapt  configure_ac=configure.ac
41247738Sbaptelse
42247738Sbapt  configure_ac=configure.in
43247738Sbaptfi
44247738Sbapt
45247738Sbaptmsg="missing on your system"
46247738Sbapt
47247738Sbaptcase $1 in
48247738Sbapt--run)
49247738Sbapt  # Try to run requested program, and just exit if it succeeds.
50247738Sbapt  run=
51247738Sbapt  shift
52247738Sbapt  "$@" && exit 0
53247738Sbapt  # Exit code 63 means version mismatch.  This often happens
54247738Sbapt  # when the user try to use an ancient version of a tool on
55247738Sbapt  # a file that requires a minimum version.  In this case we
56247738Sbapt  # we should proceed has if the program had been absent, or
57247738Sbapt  # if --run hadn't been passed.
58247738Sbapt  if test $? = 63; then
59247738Sbapt    run=:
60247738Sbapt    msg="probably too old"
61247738Sbapt  fi
62247738Sbapt  ;;
63247738Sbapt
64247738Sbapt  -h|--h|--he|--hel|--help)
65247738Sbapt    echo "\
66247738Sbapt$0 [OPTION]... PROGRAM [ARGUMENT]...
67247738Sbapt
68247738SbaptHandle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
69247738Sbapterror status if there is no known handling for PROGRAM.
70247738Sbapt
71247738SbaptOptions:
72247738Sbapt  -h, --help      display this help and exit
73247738Sbapt  -v, --version   output version information and exit
74247738Sbapt  --run           try to run the given command, and emulate it if it fails
75247738Sbapt
76247738SbaptSupported PROGRAM values:
77247738Sbapt  aclocal      touch file \`aclocal.m4'
78247738Sbapt  autoconf     touch file \`configure'
79247738Sbapt  autoheader   touch file \`config.h.in'
80247738Sbapt  autom4te     touch the output file, or create a stub one
81247738Sbapt  automake     touch all \`Makefile.in' files
82247738Sbapt  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
83247738Sbapt  flex         create \`lex.yy.c', if possible, from existing .c
84247738Sbapt  help2man     touch the output file
85247738Sbapt  lex          create \`lex.yy.c', if possible, from existing .c
86247738Sbapt  makeinfo     touch the output file
87247738Sbapt  tar          try tar, gnutar, gtar, then tar without non-portable flags
88247738Sbapt  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
89247738Sbapt
90247738SbaptVersion suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
91247738Sbapt\`g' are ignored when checking the name.
92247738Sbapt
93247738SbaptSend bug reports to <bug-automake@gnu.org>."
94247738Sbapt    exit $?
95247738Sbapt    ;;
96247738Sbapt
97247738Sbapt  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
98247738Sbapt    echo "missing $scriptversion (GNU Automake)"
99247738Sbapt    exit $?
100247738Sbapt    ;;
101247738Sbapt
102247738Sbapt  -*)
103247738Sbapt    echo 1>&2 "$0: Unknown \`$1' option"
104247738Sbapt    echo 1>&2 "Try \`$0 --help' for more information"
105247738Sbapt    exit 1
106247738Sbapt    ;;
107247738Sbapt
108247738Sbaptesac
109247738Sbapt
110247738Sbapt# normalize program name to check for.
111247738Sbaptprogram=`echo "$1" | sed '
112247738Sbapt  s/^gnu-//; t
113247738Sbapt  s/^gnu//; t
114247738Sbapt  s/^g//; t'`
115247738Sbapt
116247738Sbapt# Now exit if we have it, but it failed.  Also exit now if we
117247738Sbapt# don't have it and --version was passed (most likely to detect
118247738Sbapt# the program).  This is about non-GNU programs, so use $1 not
119247738Sbapt# $program.
120247738Sbaptcase $1 in
121247738Sbapt  lex*|yacc*)
122247738Sbapt    # Not GNU programs, they don't have --version.
123247738Sbapt    ;;
124247738Sbapt
125247738Sbapt  tar*)
126247738Sbapt    if test -n "$run"; then
127247738Sbapt       echo 1>&2 "ERROR: \`tar' requires --run"
128247738Sbapt       exit 1
129247738Sbapt    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
130247738Sbapt       exit 1
131247738Sbapt    fi
132247738Sbapt    ;;
133247738Sbapt
134247738Sbapt  *)
135247738Sbapt    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
136247738Sbapt       # We have it, but it failed.
137247738Sbapt       exit 1
138247738Sbapt    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
139247738Sbapt       # Could not run --version or --help.  This is probably someone
140247738Sbapt       # running `$TOOL --version' or `$TOOL --help' to check whether
141247738Sbapt       # $TOOL exists and not knowing $TOOL uses missing.
142247738Sbapt       exit 1
143247738Sbapt    fi
144247738Sbapt    ;;
145247738Sbaptesac
146247738Sbapt
147247738Sbapt# If it does not exist, or fails to run (possibly an outdated version),
148247738Sbapt# try to emulate it.
149247738Sbaptcase $program in
150247738Sbapt  aclocal*)
151247738Sbapt    echo 1>&2 "\
152247738SbaptWARNING: \`$1' is $msg.  You should only need it if
153247738Sbapt         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
154247738Sbapt         to install the \`Automake' and \`Perl' packages.  Grab them from
155247738Sbapt         any GNU archive site."
156247738Sbapt    touch aclocal.m4
157247738Sbapt    ;;
158247738Sbapt
159247738Sbapt  autoconf*)
160247738Sbapt    echo 1>&2 "\
161247738SbaptWARNING: \`$1' is $msg.  You should only need it if
162247738Sbapt         you modified \`${configure_ac}'.  You might want to install the
163247738Sbapt         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
164247738Sbapt         archive site."
165247738Sbapt    touch configure
166247738Sbapt    ;;
167247738Sbapt
168247738Sbapt  autoheader*)
169247738Sbapt    echo 1>&2 "\
170247738SbaptWARNING: \`$1' is $msg.  You should only need it if
171247738Sbapt         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
172247738Sbapt         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
173247738Sbapt         from any GNU archive site."
174247738Sbapt    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
175247738Sbapt    test -z "$files" && files="config.h"
176247738Sbapt    touch_files=
177247738Sbapt    for f in $files; do
178247738Sbapt      case $f in
179247738Sbapt      *:*) touch_files="$touch_files "`echo "$f" |
180247738Sbapt				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
181247738Sbapt      *) touch_files="$touch_files $f.in";;
182247738Sbapt      esac
183247738Sbapt    done
184247738Sbapt    touch $touch_files
185247738Sbapt    ;;
186247738Sbapt
187247738Sbapt  automake*)
188247738Sbapt    echo 1>&2 "\
189247738SbaptWARNING: \`$1' is $msg.  You should only need it if
190247738Sbapt         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
191247738Sbapt         You might want to install the \`Automake' and \`Perl' packages.
192247738Sbapt         Grab them from any GNU archive site."
193247738Sbapt    find . -type f -name Makefile.am -print |
194247738Sbapt	   sed 's/\.am$/.in/' |
195247738Sbapt	   while read f; do touch "$f"; done
196247738Sbapt    ;;
197247738Sbapt
198247738Sbapt  autom4te*)
199247738Sbapt    echo 1>&2 "\
200247738SbaptWARNING: \`$1' is needed, but is $msg.
201247738Sbapt         You might have modified some files without having the
202247738Sbapt         proper tools for further handling them.
203247738Sbapt         You can get \`$1' as part of \`Autoconf' from any GNU
204247738Sbapt         archive site."
205247738Sbapt
206247738Sbapt    file=`echo "$*" | sed -n "$sed_output"`
207247738Sbapt    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
208247738Sbapt    if test -f "$file"; then
209247738Sbapt	touch $file
210247738Sbapt    else
211247738Sbapt	test -z "$file" || exec >$file
212247738Sbapt	echo "#! /bin/sh"
213247738Sbapt	echo "# Created by GNU Automake missing as a replacement of"
214247738Sbapt	echo "#  $ $@"
215247738Sbapt	echo "exit 0"
216247738Sbapt	chmod +x $file
217247738Sbapt	exit 1
218247738Sbapt    fi
219247738Sbapt    ;;
220247738Sbapt
221247738Sbapt  bison*|yacc*)
222247738Sbapt    echo 1>&2 "\
223247738SbaptWARNING: \`$1' $msg.  You should only need it if
224247738Sbapt         you modified a \`.y' file.  You may need the \`Bison' package
225247738Sbapt         in order for those modifications to take effect.  You can get
226247738Sbapt         \`Bison' from any GNU archive site."
227247738Sbapt    rm -f y.tab.c y.tab.h
228247738Sbapt    if test $# -ne 1; then
229247738Sbapt        eval LASTARG="\${$#}"
230247738Sbapt	case $LASTARG in
231247738Sbapt	*.y)
232247738Sbapt	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
233247738Sbapt	    if test -f "$SRCFILE"; then
234247738Sbapt	         cp "$SRCFILE" y.tab.c
235247738Sbapt	    fi
236247738Sbapt	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
237247738Sbapt	    if test -f "$SRCFILE"; then
238247738Sbapt	         cp "$SRCFILE" y.tab.h
239247738Sbapt	    fi
240247738Sbapt	  ;;
241247738Sbapt	esac
242247738Sbapt    fi
243247738Sbapt    if test ! -f y.tab.h; then
244247738Sbapt	echo >y.tab.h
245247738Sbapt    fi
246247738Sbapt    if test ! -f y.tab.c; then
247247738Sbapt	echo 'main() { return 0; }' >y.tab.c
248247738Sbapt    fi
249247738Sbapt    ;;
250247738Sbapt
251247738Sbapt  lex*|flex*)
252247738Sbapt    echo 1>&2 "\
253247738SbaptWARNING: \`$1' is $msg.  You should only need it if
254247738Sbapt         you modified a \`.l' file.  You may need the \`Flex' package
255247738Sbapt         in order for those modifications to take effect.  You can get
256247738Sbapt         \`Flex' from any GNU archive site."
257247738Sbapt    rm -f lex.yy.c
258247738Sbapt    if test $# -ne 1; then
259247738Sbapt        eval LASTARG="\${$#}"
260247738Sbapt	case $LASTARG in
261247738Sbapt	*.l)
262247738Sbapt	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
263247738Sbapt	    if test -f "$SRCFILE"; then
264247738Sbapt	         cp "$SRCFILE" lex.yy.c
265247738Sbapt	    fi
266247738Sbapt	  ;;
267247738Sbapt	esac
268247738Sbapt    fi
269247738Sbapt    if test ! -f lex.yy.c; then
270247738Sbapt	echo 'main() { return 0; }' >lex.yy.c
271247738Sbapt    fi
272247738Sbapt    ;;
273247738Sbapt
274247738Sbapt  help2man*)
275247738Sbapt    echo 1>&2 "\
276247738SbaptWARNING: \`$1' is $msg.  You should only need it if
277247738Sbapt	 you modified a dependency of a manual page.  You may need the
278247738Sbapt	 \`Help2man' package in order for those modifications to take
279247738Sbapt	 effect.  You can get \`Help2man' from any GNU archive site."
280247738Sbapt
281247738Sbapt    file=`echo "$*" | sed -n "$sed_output"`
282247738Sbapt    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
283247738Sbapt    if test -f "$file"; then
284247738Sbapt	touch $file
285247738Sbapt    else
286247738Sbapt	test -z "$file" || exec >$file
287247738Sbapt	echo ".ab help2man is required to generate this page"
288247738Sbapt	exit $?
289247738Sbapt    fi
290247738Sbapt    ;;
291247738Sbapt
292247738Sbapt  makeinfo*)
293247738Sbapt    echo 1>&2 "\
294247738SbaptWARNING: \`$1' is $msg.  You should only need it if
295247738Sbapt         you modified a \`.texi' or \`.texinfo' file, or any other file
296247738Sbapt         indirectly affecting the aspect of the manual.  The spurious
297247738Sbapt         call might also be the consequence of using a buggy \`make' (AIX,
298247738Sbapt         DU, IRIX).  You might want to install the \`Texinfo' package or
299247738Sbapt         the \`GNU make' package.  Grab either from any GNU archive site."
300247738Sbapt    # The file to touch is that specified with -o ...
301247738Sbapt    file=`echo "$*" | sed -n "$sed_output"`
302247738Sbapt    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
303247738Sbapt    if test -z "$file"; then
304247738Sbapt      # ... or it is the one specified with @setfilename ...
305247738Sbapt      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
306247738Sbapt      file=`sed -n '
307247738Sbapt	/^@setfilename/{
308247738Sbapt	  s/.* \([^ ]*\) *$/\1/
309247738Sbapt	  p
310247738Sbapt	  q
311247738Sbapt	}' $infile`
312247738Sbapt      # ... or it is derived from the source name (dir/f.texi becomes f.info)
313247738Sbapt      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
314247738Sbapt    fi
315247738Sbapt    # If the file does not exist, the user really needs makeinfo;
316247738Sbapt    # let's fail without touching anything.
317247738Sbapt    test -f $file || exit 1
318247738Sbapt    touch $file
319247738Sbapt    ;;
320247738Sbapt
321247738Sbapt  tar*)
322247738Sbapt    shift
323247738Sbapt
324247738Sbapt    # We have already tried tar in the generic part.
325247738Sbapt    # Look for gnutar/gtar before invocation to avoid ugly error
326247738Sbapt    # messages.
327247738Sbapt    if (gnutar --version > /dev/null 2>&1); then
328247738Sbapt       gnutar "$@" && exit 0
329247738Sbapt    fi
330247738Sbapt    if (gtar --version > /dev/null 2>&1); then
331247738Sbapt       gtar "$@" && exit 0
332247738Sbapt    fi
333247738Sbapt    firstarg="$1"
334247738Sbapt    if shift; then
335247738Sbapt	case $firstarg in
336247738Sbapt	*o*)
337247738Sbapt	    firstarg=`echo "$firstarg" | sed s/o//`
338247738Sbapt	    tar "$firstarg" "$@" && exit 0
339247738Sbapt	    ;;
340247738Sbapt	esac
341247738Sbapt	case $firstarg in
342247738Sbapt	*h*)
343247738Sbapt	    firstarg=`echo "$firstarg" | sed s/h//`
344247738Sbapt	    tar "$firstarg" "$@" && exit 0
345247738Sbapt	    ;;
346247738Sbapt	esac
347247738Sbapt    fi
348247738Sbapt
349247738Sbapt    echo 1>&2 "\
350247738SbaptWARNING: I can't seem to be able to run \`tar' with the given arguments.
351247738Sbapt         You may want to install GNU tar or Free paxutils, or check the
352247738Sbapt         command line arguments."
353247738Sbapt    exit 1
354247738Sbapt    ;;
355247738Sbapt
356247738Sbapt  *)
357247738Sbapt    echo 1>&2 "\
358247738SbaptWARNING: \`$1' is needed, and is $msg.
359247738Sbapt         You might have modified some files without having the
360247738Sbapt         proper tools for further handling them.  Check the \`README' file,
361247738Sbapt         it often tells you about the needed prerequisites for installing
362247738Sbapt         this package.  You may also peek at any GNU archive site, in case
363247738Sbapt         some other package would contain this missing \`$1' program."
364247738Sbapt    exit 1
365247738Sbapt    ;;
366247738Sbaptesac
367247738Sbapt
368247738Sbaptexit 0
369247738Sbapt
370247738Sbapt# Local variables:
371247738Sbapt# eval: (add-hook 'write-file-hooks 'time-stamp)
372247738Sbapt# time-stamp-start: "scriptversion="
373247738Sbapt# time-stamp-format: "%:y-%02m-%02d.%02H"
374247738Sbapt# time-stamp-time-zone: "UTC"
375247738Sbapt# time-stamp-end: "; # UTC"
376247738Sbapt# End:
377