2
2
# ylwrap - wrapper for lex/yacc invocations.
4
scriptversion=2011-08-25.18; # UTC
4
scriptversion=2012-12-21.17; # UTC
6
# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
7
# 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
6
# Copyright (C) 1996-2013 Free Software Foundation, Inc.
9
8
# Written by Tom Tromey <tromey@cygnus.com>.
76
109
input="`pwd`/$input"
112
input_rx=`get_dirname "$input" | quote_for_sed`
114
# Since DOS filename conventions don't allow two dots,
115
# the DOS version of Bison writes out y_tab.c instead of y.tab.c
116
# and y_tab.h instead of y.tab.h. Test to see if this is the case.
118
if test -f y_tab.c || test -f y_tab.h; then
122
# The parser itself, the first file, is the destination of the .y.c
123
# rule in the Makefile.
126
# A sed program to s/FROM/TO/g for all the FROM/TO so that, for
127
# instance, we rename #include "y.tab.h" into #include "parse.h"
128
# during the conversion from y.tab.c to parse.c.
131
# Also rename header guards, as Bison 2.7 for instance uses its header
132
# guard in its implementation file.
133
sed_fix_header_guards=
81
135
while test "$#" -ne 0; do
82
136
if test "$1" = "--"; then
86
pairlist="$pairlist $1"
141
# Handle y_tab.c and y_tab.h output by DOS
142
if $y_tab_nodot; then
144
"y.tab.c") from=y_tab.c;;
145
"y.tab.h") from=y_tab.h;;
151
sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;"
152
sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;"
90
155
# The program to run.
117
182
if test $ret -eq 0; then
121
# Since DOS filename conventions don't allow two dots,
122
# the DOS version of Bison writes out y_tab.c instead of y.tab.c
123
# and y_tab.h instead of y.tab.h. Test to see if this is the case.
125
if test -f y_tab.c || test -f y_tab.h; then
129
# The directory holding the input.
130
input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
131
# Quote $INPUT_DIR so we can use it in a regexp.
132
# FIXME: really we should care about more than `.' and `\'.
133
input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
135
while test "$#" -ne 0; do
137
# Handle y_tab.c and y_tab.h output by DOS
138
if test $y_tab_nodot = "yes"; then
139
if test $from = "y.tab.c"; then
142
if test $from = "y.tab.h"; then
185
to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
147
186
if test -f "$from"; then
148
187
# If $2 is an absolute path name, then just use that,
149
# otherwise prepend `../'.
151
[\\/]* | ?:[\\/]*) target="$2";;
188
# otherwise prepend '../'.
190
[\\/]* | ?:[\\/]*) target=$to;;
155
# We do not want to overwrite a header file if it hasn't
156
# changed. This avoid useless recompilations. However the
157
# parser itself (the first file) should always be updated,
158
# because it is the destination of the .y.c rule in the
159
# Makefile. Divert the output of all other files to a temporary
160
# file so we can compare them to existing versions.
161
if test $first = no; then
194
# Do not overwrite unchanged header files to avoid useless
195
# recompilations. Always update the parser itself: it is the
196
# destination of the .y.c rule in the Makefile. Divert the
197
# output of all other files to a temporary file so we can
198
# compare them to existing versions.
199
if test $from != $parser; then
162
200
realtarget="$target"
163
target="tmp-`echo $target | sed s/.*[\\/]//g`"
201
target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
165
# Edit out `#line' or `#' directives.
167
# We don't want the resulting debug information to point at
168
# an absolute srcdir; it is better for it to just mention the
169
# .y file with no path.
171
# We want to use the real output file name, not yy.lex.c for
174
# We want the include guards to be adjusted too.
175
FROM=`echo "$from" | sed \
176
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
177
-e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
178
TARGET=`echo "$2" | sed \
179
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
180
-e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
182
sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
183
-e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
185
# Check whether header files must be updated.
186
if test $first = no; then
204
# Munge "#line" or "#" directives. Don't let the resulting
205
# debug information point at an absolute srcdir. Use the real
206
# output file name, not yy.lex.c for instance. Adjust the
207
# include guards too.
209
-e "s|$input_rx|$input_sub_rx|" \
210
-e "$sed_fix_filenames" \
211
-e "$sed_fix_header_guards" \
212
"$from" >"$target" || ret=$?
214
# Check whether files must be updated.
215
if test "$from" != "$parser"; then
187
216
if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
188
echo "$2" is unchanged
217
echo "$to is unchanged"
192
221
mv -f "$target" "$realtarget"
196
# A missing file is only an error for the first file. This
197
# is a blatant hack to let us support using "yacc -d". If -d
198
# is not specified, we don't want an error when the header
200
if test $first = yes; then
225
# A missing file is only an error for the parser. This is a
226
# blatant hack to let us support using "yacc -d". If -d is not
227
# specified, don't fail when the header file is "missing".
228
if test "$from" = "$parser"; then
212
235
# Remove the directory.