155682Smarkm#! /bin/sh
272445Sassar# Common stub for a few missing GNU programs while installing.
3142403Snectar
4233294Sstasscriptversion=2009-04-28.21; # UTC
5142403Snectar
6233294Sstas# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006,
7233294Sstas# 2008, 2009 Free Software Foundation, Inc.
872445Sassar# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
972445Sassar
1072445Sassar# This program is free software; you can redistribute it and/or modify
1172445Sassar# it under the terms of the GNU General Public License as published by
1272445Sassar# the Free Software Foundation; either version 2, or (at your option)
1372445Sassar# any later version.
1472445Sassar
1572445Sassar# This program is distributed in the hope that it will be useful,
1672445Sassar# but WITHOUT ANY WARRANTY; without even the implied warranty of
1772445Sassar# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1872445Sassar# GNU General Public License for more details.
1972445Sassar
2072445Sassar# You should have received a copy of the GNU General Public License
21233294Sstas# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2272445Sassar
23102644Snectar# As a special exception to the GNU General Public License, if you
24102644Snectar# distribute this file as part of a program that contains a
25102644Snectar# configuration script generated by Autoconf, you may include it under
26102644Snectar# the same distribution terms that you use for the rest of that program.
27102644Snectar
2872445Sassarif test $# -eq 0; then
2972445Sassar  echo 1>&2 "Try \`$0 --help' for more information"
3072445Sassar  exit 1
3172445Sassarfi
3272445Sassar
3372445Sassarrun=:
34178825Sdfrsed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
35178825Sdfrsed_minuso='s/.* -o \([^ ]*\).*/\1/p'
3672445Sassar
37102644Snectar# In the cases where this matters, `missing' is being run in the
38102644Snectar# srcdir already.
39102644Snectarif test -f configure.ac; then
40102644Snectar  configure_ac=configure.ac
41102644Snectarelse
42102644Snectar  configure_ac=configure.in
43102644Snectarfi
44102644Snectar
45142403Snectarmsg="missing on your system"
46142403Snectar
47178825Sdfrcase $1 in
4872445Sassar--run)
4972445Sassar  # Try to run requested program, and just exit if it succeeds.
5072445Sassar  run=
5172445Sassar  shift
5272445Sassar  "$@" && exit 0
53142403Snectar  # Exit code 63 means version mismatch.  This often happens
54142403Snectar  # when the user try to use an ancient version of a tool on
55142403Snectar  # a file that requires a minimum version.  In this case we
56142403Snectar  # we should proceed has if the program had been absent, or
57142403Snectar  # if --run hadn't been passed.
58142403Snectar  if test $? = 63; then
59142403Snectar    run=:
60142403Snectar    msg="probably too old"
61142403Snectar  fi
6272445Sassar  ;;
6372445Sassar
6472445Sassar  -h|--h|--he|--hel|--help)
6572445Sassar    echo "\
6672445Sassar$0 [OPTION]... PROGRAM [ARGUMENT]...
6772445Sassar
6872445SassarHandle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
6972445Sassarerror status if there is no known handling for PROGRAM.
7072445Sassar
7172445SassarOptions:
7272445Sassar  -h, --help      display this help and exit
7372445Sassar  -v, --version   output version information and exit
7472445Sassar  --run           try to run the given command, and emulate it if it fails
7572445Sassar
7672445SassarSupported PROGRAM values:
7772445Sassar  aclocal      touch file \`aclocal.m4'
7872445Sassar  autoconf     touch file \`configure'
7972445Sassar  autoheader   touch file \`config.h.in'
80178825Sdfr  autom4te     touch the output file, or create a stub one
8172445Sassar  automake     touch all \`Makefile.in' files
8272445Sassar  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
8372445Sassar  flex         create \`lex.yy.c', if possible, from existing .c
8472445Sassar  help2man     touch the output file
8572445Sassar  lex          create \`lex.yy.c', if possible, from existing .c
8672445Sassar  makeinfo     touch the output file
8772445Sassar  tar          try tar, gnutar, gtar, then tar without non-portable flags
88142403Snectar  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
89142403Snectar
90233294SstasVersion suffixes to PROGRAM as well as the prefixes \`gnu-', \`gnu', and
91233294Sstas\`g' are ignored when checking the name.
92233294Sstas
93142403SnectarSend bug reports to <bug-automake@gnu.org>."
94178825Sdfr    exit $?
9572445Sassar    ;;
9672445Sassar
9772445Sassar  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
98142403Snectar    echo "missing $scriptversion (GNU Automake)"
99178825Sdfr    exit $?
10072445Sassar    ;;
10172445Sassar
10272445Sassar  -*)
10372445Sassar    echo 1>&2 "$0: Unknown \`$1' option"
10472445Sassar    echo 1>&2 "Try \`$0 --help' for more information"
10572445Sassar    exit 1
10672445Sassar    ;;
10772445Sassar
108178825Sdfresac
109178825Sdfr
110233294Sstas# normalize program name to check for.
111233294Sstasprogram=`echo "$1" | sed '
112233294Sstas  s/^gnu-//; t
113233294Sstas  s/^gnu//; t
114233294Sstas  s/^g//; t'`
115233294Sstas
116178825Sdfr# Now exit if we have it, but it failed.  Also exit now if we
117178825Sdfr# don't have it and --version was passed (most likely to detect
118233294Sstas# the program).  This is about non-GNU programs, so use $1 not
119233294Sstas# $program.
120178825Sdfrcase $1 in
121233294Sstas  lex*|yacc*)
122178825Sdfr    # Not GNU programs, they don't have --version.
123178825Sdfr    ;;
124178825Sdfr
125233294Sstas  tar*)
126178825Sdfr    if test -n "$run"; then
127178825Sdfr       echo 1>&2 "ERROR: \`tar' requires --run"
128178825Sdfr       exit 1
129178825Sdfr    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
130178825Sdfr       exit 1
131178825Sdfr    fi
132178825Sdfr    ;;
133178825Sdfr
134178825Sdfr  *)
135102644Snectar    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
136102644Snectar       # We have it, but it failed.
137102644Snectar       exit 1
138178825Sdfr    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
139178825Sdfr       # Could not run --version or --help.  This is probably someone
140178825Sdfr       # running `$TOOL --version' or `$TOOL --help' to check whether
141178825Sdfr       # $TOOL exists and not knowing $TOOL uses missing.
142178825Sdfr       exit 1
143102644Snectar    fi
144178825Sdfr    ;;
145178825Sdfresac
146102644Snectar
147178825Sdfr# If it does not exist, or fails to run (possibly an outdated version),
148178825Sdfr# try to emulate it.
149233294Sstascase $program in
150178825Sdfr  aclocal*)
15172445Sassar    echo 1>&2 "\
152142403SnectarWARNING: \`$1' is $msg.  You should only need it if
153102644Snectar         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
15472445Sassar         to install the \`Automake' and \`Perl' packages.  Grab them from
15572445Sassar         any GNU archive site."
15672445Sassar    touch aclocal.m4
15772445Sassar    ;;
15872445Sassar
159233294Sstas  autoconf*)
16072445Sassar    echo 1>&2 "\
161142403SnectarWARNING: \`$1' is $msg.  You should only need it if
162102644Snectar         you modified \`${configure_ac}'.  You might want to install the
16372445Sassar         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
16472445Sassar         archive site."
16572445Sassar    touch configure
16672445Sassar    ;;
16772445Sassar
168233294Sstas  autoheader*)
16972445Sassar    echo 1>&2 "\
170142403SnectarWARNING: \`$1' is $msg.  You should only need it if
171102644Snectar         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
17272445Sassar         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
17372445Sassar         from any GNU archive site."
174102644Snectar    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
17572445Sassar    test -z "$files" && files="config.h"
17672445Sassar    touch_files=
17772445Sassar    for f in $files; do
178178825Sdfr      case $f in
17972445Sassar      *:*) touch_files="$touch_files "`echo "$f" |
18072445Sassar				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
18172445Sassar      *) touch_files="$touch_files $f.in";;
18272445Sassar      esac
18372445Sassar    done
18472445Sassar    touch $touch_files
18572445Sassar    ;;
18672445Sassar
187102644Snectar  automake*)
18872445Sassar    echo 1>&2 "\
189142403SnectarWARNING: \`$1' is $msg.  You should only need it if
190102644Snectar         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
19172445Sassar         You might want to install the \`Automake' and \`Perl' packages.
19272445Sassar         Grab them from any GNU archive site."
19372445Sassar    find . -type f -name Makefile.am -print |
19472445Sassar	   sed 's/\.am$/.in/' |
19572445Sassar	   while read f; do touch "$f"; done
19672445Sassar    ;;
19772445Sassar
198233294Sstas  autom4te*)
199102644Snectar    echo 1>&2 "\
200142403SnectarWARNING: \`$1' is needed, but is $msg.
201142403Snectar         You might have modified some files without having the
202102644Snectar         proper tools for further handling them.
203127808Snectar         You can get \`$1' as part of \`Autoconf' from any GNU
204102644Snectar         archive site."
205102644Snectar
206178825Sdfr    file=`echo "$*" | sed -n "$sed_output"`
207178825Sdfr    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
208102644Snectar    if test -f "$file"; then
209102644Snectar	touch $file
210102644Snectar    else
211102644Snectar	test -z "$file" || exec >$file
212102644Snectar	echo "#! /bin/sh"
213102644Snectar	echo "# Created by GNU Automake missing as a replacement of"
214102644Snectar	echo "#  $ $@"
215102644Snectar	echo "exit 0"
216102644Snectar	chmod +x $file
217102644Snectar	exit 1
218102644Snectar    fi
219102644Snectar    ;;
220102644Snectar
221233294Sstas  bison*|yacc*)
22272445Sassar    echo 1>&2 "\
223142403SnectarWARNING: \`$1' $msg.  You should only need it if
22472445Sassar         you modified a \`.y' file.  You may need the \`Bison' package
22572445Sassar         in order for those modifications to take effect.  You can get
22672445Sassar         \`Bison' from any GNU archive site."
22772445Sassar    rm -f y.tab.c y.tab.h
228178825Sdfr    if test $# -ne 1; then
22972445Sassar        eval LASTARG="\${$#}"
230178825Sdfr	case $LASTARG in
23172445Sassar	*.y)
23272445Sassar	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
233178825Sdfr	    if test -f "$SRCFILE"; then
23472445Sassar	         cp "$SRCFILE" y.tab.c
23572445Sassar	    fi
23672445Sassar	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
237178825Sdfr	    if test -f "$SRCFILE"; then
23872445Sassar	         cp "$SRCFILE" y.tab.h
23972445Sassar	    fi
24072445Sassar	  ;;
24172445Sassar	esac
24272445Sassar    fi
243178825Sdfr    if test ! -f y.tab.h; then
24472445Sassar	echo >y.tab.h
24572445Sassar    fi
246178825Sdfr    if test ! -f y.tab.c; then
24772445Sassar	echo 'main() { return 0; }' >y.tab.c
24872445Sassar    fi
24972445Sassar    ;;
25072445Sassar
251233294Sstas  lex*|flex*)
25272445Sassar    echo 1>&2 "\
253142403SnectarWARNING: \`$1' is $msg.  You should only need it if
25472445Sassar         you modified a \`.l' file.  You may need the \`Flex' package
25572445Sassar         in order for those modifications to take effect.  You can get
25672445Sassar         \`Flex' from any GNU archive site."
25772445Sassar    rm -f lex.yy.c
258178825Sdfr    if test $# -ne 1; then
25972445Sassar        eval LASTARG="\${$#}"
260178825Sdfr	case $LASTARG in
26172445Sassar	*.l)
26272445Sassar	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
263178825Sdfr	    if test -f "$SRCFILE"; then
26472445Sassar	         cp "$SRCFILE" lex.yy.c
26572445Sassar	    fi
26672445Sassar	  ;;
26772445Sassar	esac
26872445Sassar    fi
269178825Sdfr    if test ! -f lex.yy.c; then
27072445Sassar	echo 'main() { return 0; }' >lex.yy.c
27172445Sassar    fi
27272445Sassar    ;;
27372445Sassar
274233294Sstas  help2man*)
27572445Sassar    echo 1>&2 "\
276142403SnectarWARNING: \`$1' is $msg.  You should only need it if
27772445Sassar	 you modified a dependency of a manual page.  You may need the
27872445Sassar	 \`Help2man' package in order for those modifications to take
27972445Sassar	 effect.  You can get \`Help2man' from any GNU archive site."
28072445Sassar
281178825Sdfr    file=`echo "$*" | sed -n "$sed_output"`
282178825Sdfr    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
283178825Sdfr    if test -f "$file"; then
28472445Sassar	touch $file
28572445Sassar    else
28672445Sassar	test -z "$file" || exec >$file
28772445Sassar	echo ".ab help2man is required to generate this page"
288233294Sstas	exit $?
28972445Sassar    fi
29072445Sassar    ;;
29172445Sassar
292233294Sstas  makeinfo*)
29372445Sassar    echo 1>&2 "\
294142403SnectarWARNING: \`$1' is $msg.  You should only need it if
29572445Sassar         you modified a \`.texi' or \`.texinfo' file, or any other file
29672445Sassar         indirectly affecting the aspect of the manual.  The spurious
29772445Sassar         call might also be the consequence of using a buggy \`make' (AIX,
29872445Sassar         DU, IRIX).  You might want to install the \`Texinfo' package or
29972445Sassar         the \`GNU make' package.  Grab either from any GNU archive site."
300178825Sdfr    # The file to touch is that specified with -o ...
301178825Sdfr    file=`echo "$*" | sed -n "$sed_output"`
302178825Sdfr    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
30372445Sassar    if test -z "$file"; then
304178825Sdfr      # ... or it is the one specified with @setfilename ...
305178825Sdfr      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
306178825Sdfr      file=`sed -n '
307178825Sdfr	/^@setfilename/{
308178825Sdfr	  s/.* \([^ ]*\) *$/\1/
309178825Sdfr	  p
310178825Sdfr	  q
311178825Sdfr	}' $infile`
312178825Sdfr      # ... or it is derived from the source name (dir/f.texi becomes f.info)
313178825Sdfr      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
31472445Sassar    fi
315178825Sdfr    # If the file does not exist, the user really needs makeinfo;
316178825Sdfr    # let's fail without touching anything.
317178825Sdfr    test -f $file || exit 1
31872445Sassar    touch $file
31972445Sassar    ;;
32072445Sassar
321233294Sstas  tar*)
32272445Sassar    shift
32372445Sassar
32472445Sassar    # We have already tried tar in the generic part.
32572445Sassar    # Look for gnutar/gtar before invocation to avoid ugly error
32672445Sassar    # messages.
32772445Sassar    if (gnutar --version > /dev/null 2>&1); then
328127808Snectar       gnutar "$@" && exit 0
32972445Sassar    fi
33072445Sassar    if (gtar --version > /dev/null 2>&1); then
331127808Snectar       gtar "$@" && exit 0
33272445Sassar    fi
33372445Sassar    firstarg="$1"
33472445Sassar    if shift; then
335178825Sdfr	case $firstarg in
33672445Sassar	*o*)
33772445Sassar	    firstarg=`echo "$firstarg" | sed s/o//`
338127808Snectar	    tar "$firstarg" "$@" && exit 0
33972445Sassar	    ;;
34072445Sassar	esac
341178825Sdfr	case $firstarg in
34272445Sassar	*h*)
34372445Sassar	    firstarg=`echo "$firstarg" | sed s/h//`
344127808Snectar	    tar "$firstarg" "$@" && exit 0
34572445Sassar	    ;;
34672445Sassar	esac
34772445Sassar    fi
34872445Sassar
34972445Sassar    echo 1>&2 "\
35072445SassarWARNING: I can't seem to be able to run \`tar' with the given arguments.
35172445Sassar         You may want to install GNU tar or Free paxutils, or check the
35272445Sassar         command line arguments."
35372445Sassar    exit 1
35472445Sassar    ;;
35572445Sassar
35672445Sassar  *)
35772445Sassar    echo 1>&2 "\
358142403SnectarWARNING: \`$1' is needed, and is $msg.
359142403Snectar         You might have modified some files without having the
36072445Sassar         proper tools for further handling them.  Check the \`README' file,
361127808Snectar         it often tells you about the needed prerequisites for installing
36272445Sassar         this package.  You may also peek at any GNU archive site, in case
36372445Sassar         some other package would contain this missing \`$1' program."
36472445Sassar    exit 1
36572445Sassar    ;;
36672445Sassaresac
36772445Sassar
36872445Sassarexit 0
369142403Snectar
370142403Snectar# Local variables:
371142403Snectar# eval: (add-hook 'write-file-hooks 'time-stamp)
372142403Snectar# time-stamp-start: "scriptversion="
373142403Snectar# time-stamp-format: "%:y-%02m-%02d.%02H"
374233294Sstas# time-stamp-time-zone: "UTC"
375233294Sstas# time-stamp-end: "; # UTC"
376142403Snectar# End:
377