2 # ylwrap - wrapper for lex/yacc invocations.
4 scriptversion
=2005-05-14.22
6 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005
7 # Free Software Foundation, Inc.
9 # Written by Tom Tromey <tromey@cygnus.com>.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # As a special exception to the GNU General Public License, if you
27 # distribute this file as part of a program that contains a
28 # configuration script generated by Autoconf, you may include it under
29 # the same distribution terms that you use for the rest of that program.
31 # This file is maintained in Automake, please report
32 # bugs to <bug-automake@gnu.org> or send patches to
33 # <automake-patches@gnu.org>.
37 echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
46 Usage
: ylwrap
[--help|
--version] INPUT
[OUTPUT DESIRED
]...
-- PROGRAM
[ARGS
]...
48 Wrapper
for lex
/yacc invocations
, renaming files as desired.
50 INPUT is the input
file
51 OUTPUT is one
file PROG generates
52 DESIRED is the
file we actually want instead of OUTPUT
53 PROGRAM is program to run
54 ARGS are passed to PROG
56 Any number of OUTPUT
,DESIRED pairs may be used.
58 Report bugs to
<bug-automake@gnu.org
>.
63 echo "ylwrap $scriptversion"
74 # Absolute path; do nothing.
77 # Relative path. Make it absolute.
83 while test "$#" -ne 0; do
84 if test "$1" = "--"; then
88 pairlist
="$pairlist $1"
95 # Make any relative path in $prog absolute.
98 *[\\/]*) prog
="`pwd`/$prog" ;;
101 # FIXME: add hostname here for parallel makes that run commands on
102 # other machines. But that might take us over the 14-char limit.
104 trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
105 mkdir
$dirname ||
exit 1
111 *) $prog "$@" "$input" ;;
115 if test $ret -eq 0; then
119 # Since DOS filename conventions don't allow two dots,
120 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
121 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
123 if test -f y_tab.c ||
test -f y_tab.h
; then
127 # The directory holding the input.
128 input_dir
=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
129 # Quote $INPUT_DIR so we can use it in a regexp.
130 # FIXME: really we should care about more than `.' and `\'.
131 input_rx
=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
133 while test "$#" -ne 0; do
135 # Handle y_tab.c and y_tab.h output by DOS
136 if test $y_tab_nodot = "yes"; then
137 if test $from = "y.tab.c"; then
140 if test $from = "y.tab.h"; then
145 if test -f "$from"; then
146 # If $2 is an absolute path name, then just use that,
147 # otherwise prepend `../'.
149 [\\/]* | ?
:[\\/]*) target
="$2";;
153 # We do not want to overwrite a header file if it hasn't
154 # changed. This avoid useless recompilations. However the
155 # parser itself (the first file) should always be updated,
156 # because it is the destination of the .y.c rule in the
157 # Makefile. Divert the output of all other files to a temporary
158 # file so we can compare them to existing versions.
159 if test $first = no
; then
161 target
="tmp-`echo $target | sed s/.*[\\/]//g`"
163 # Edit out `#line' or `#' directives.
165 # We don't want the resulting debug information to point at
166 # an absolute srcdir; it is better for it to just mention the
167 # .y file with no path.
169 # We want to use the real output file name, not yy.lex.c for
172 # We want the include guards to be adjusted too.
173 FROM
=`echo "$from" | sed \
174 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
175 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
176 TARGET
=`echo "$2" | sed \
177 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
178 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
180 sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
181 -e "s,$FROM,$TARGET," "$from" >"$target" || ret
=$?
183 # Check whether header files must be updated.
184 if test $first = no
; then
185 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
186 echo "$2" is unchanged
190 mv -f "$target" "$realtarget"
194 # A missing file is only an error for the first file. This
195 # is a blatant hack to let us support using "yacc -d". If -d
196 # is not specified, we don't want an error when the header
198 if test $first = yes; then
210 # Remove the directory.
219 # eval: (add-hook 'write-file-hooks 'time-stamp)
220 # time-stamp-start: "scriptversion="
221 # time-stamp-format: "%:y-%02m-%02d.%02H"
222 # time-stamp-end: "$"