2 # ylwrap - wrapper for lex/yacc invocations.
4 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002 Free Software
7 # Written by Tom Tromey <tromey@cygnus.com>.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 # As a special exception to the GNU General Public License, if you
24 # distribute this file as part of a program that contains a
25 # configuration script generated by Autoconf, you may include it under
26 # the same distribution terms that you use for the rest of that program.
29 # ylwrap INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
30 # * INPUT is the input file
31 # * OUTPUT is file PROG generates
32 # * DESIRED is file we actually want
33 # * PROGRAM is program to run
34 # * ARGS are passed to PROG
35 # Any number of OUTPUT,DESIRED pairs may be used.
42 # Absolute path; do nothing.
45 # Relative path. Make it absolute.
51 while test "$#" -ne 0; do
52 if test "$1" = "--"; then
56 pairlist
="$pairlist $1"
63 # Make any relative path in $prog absolute.
66 *[\\/]*) prog
="`pwd`/$prog" ;;
69 # FIXME: add hostname here for parallel makes that run commands on
70 # other machines. But that might take us over the 14-char limit.
72 trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
73 mkdir
$dirname ||
exit 1
79 *) $prog "$@" "$input" ;;
83 if test $status -eq 0; then
87 # Since DOS filename conventions don't allow two dots,
88 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
89 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
91 if test -f y_tab.c ||
test -f y_tab.h
; then
95 # The directory holding the input.
96 input_dir
=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
97 # Quote $INPUT_DIR so we can use it in a regexp.
98 # FIXME: really we should care about more than `.' and `\'.
99 input_rx
=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
101 while test "$#" -ne 0; do
103 # Handle y_tab.c and y_tab.h output by DOS
104 if test $y_tab_nodot = "yes"; then
105 if test $from = "y.tab.c"; then
108 if test $from = "y.tab.h"; then
113 if test -f "$from"; then
114 # If $2 is an absolute path name, then just use that,
115 # otherwise prepend `../'.
117 [\\/]* | ?
:[\\/]*) target
="$2";;
121 # Edit out `#line' or `#' directives.
123 # We don't want the resulting debug information to point at
124 # an absolute srcdir; it is better for it to just mention the
125 # .y file with no path.
127 # We want to use the real output file name, not yy.lex.c for
130 # We want the include guards to be adjusted too.
131 FROM
=`echo "$from" | sed \
132 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
133 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
134 TARGET
=`echo "$2" | sed \
135 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
136 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
137 sed "/^#/{s,$input_rx,,;s,$from,$2,;s,$FORM,$TO,;}" "$from" >"$target" ||
140 # A missing file is only an error for the first file. This
141 # is a blatant hack to let us support using "yacc -d". If -d
142 # is not specified, we don't want an error when the header
144 if test $first = yes; then
156 # Remove the directory.