1 |
#! /bin/sh |
#! /bin/sh |
2 |
# ylwrap - wrapper for lex/yacc invocations. |
# ylwrap - wrapper for lex/yacc invocations. |
3 |
|
|
4 |
scriptversion=2011-08-25.18; # UTC |
scriptversion=2012-07-14.08; # UTC |
5 |
|
|
6 |
# Copyright (C) 1996-2012 Free Software Foundation, Inc. |
# Copyright (C) 1996-2012 Free Software Foundation, Inc. |
7 |
# |
# |
29 |
# bugs to <bug-automake@gnu.org> or send patches to |
# bugs to <bug-automake@gnu.org> or send patches to |
30 |
# <automake-patches@gnu.org>. |
# <automake-patches@gnu.org>. |
31 |
|
|
32 |
|
get_dirname () |
33 |
|
{ |
34 |
|
case $1 in |
35 |
|
*/*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';; |
36 |
|
# Otherwise, we want the empty string (not "."). |
37 |
|
esac |
38 |
|
} |
39 |
|
|
40 |
|
# guard FILE |
41 |
|
# ---------- |
42 |
|
# The CPP macro used to guard inclusion of FILE. |
43 |
|
guard() |
44 |
|
{ |
45 |
|
printf '%s\n' "$from" \ |
46 |
|
| sed \ |
47 |
|
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ |
48 |
|
-e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' |
49 |
|
} |
50 |
|
|
51 |
|
# quote_for_sed [STRING] |
52 |
|
# ---------------------- |
53 |
|
# Return STRING (or stdin) quoted to be used as a sed pattern. |
54 |
|
quote_for_sed () |
55 |
|
{ |
56 |
|
case $# in |
57 |
|
0) cat;; |
58 |
|
1) printf '%s\n' "$1";; |
59 |
|
esac \ |
60 |
|
| sed -e 's|[][\\.*]|\\&|g' |
61 |
|
} |
62 |
|
|
63 |
case "$1" in |
case "$1" in |
64 |
'') |
'') |
65 |
echo "$0: No files given. Try '$0 --help' for more information." 1>&2 |
echo "$0: No files given. Try '$0 --help' for more information." 1>&2 |
93 |
;; |
;; |
94 |
esac |
esac |
95 |
|
|
|
get_dirname () |
|
|
{ |
|
|
case $1 in |
|
|
*/*|*\\*) printf '%s\n' "$1" | sed -e 's,\([\\/]\)[^\\/]*$,\1,';; |
|
|
# Otherwise, we want the empty string (not "."). |
|
|
esac |
|
|
} |
|
|
|
|
|
quote_for_sed () |
|
|
{ |
|
|
# FIXME: really we should care about more than '.' and '\'. |
|
|
sed -e 's,[\\.],\\&,g' |
|
|
} |
|
96 |
|
|
97 |
# The input. |
# The input. |
98 |
input="$1" |
input="$1" |
108 |
input="`pwd`/$input" |
input="`pwd`/$input" |
109 |
;; |
;; |
110 |
esac |
esac |
111 |
|
input_rx=`get_dirname "$input" | quote_for_sed` |
112 |
|
|
113 |
pairlist= |
# Since DOS filename conventions don't allow two dots, |
114 |
|
# the DOS version of Bison writes out y_tab.c instead of y.tab.c |
115 |
|
# and y_tab.h instead of y.tab.h. Test to see if this is the case. |
116 |
|
y_tab_nodot=false |
117 |
|
if test -f y_tab.c || test -f y_tab.h; then |
118 |
|
y_tab_nodot=true |
119 |
|
fi |
120 |
|
|
121 |
|
# The parser itself, the first file, is the destination of the .y.c |
122 |
|
# rule in the Makefile. |
123 |
|
parser=$1 |
124 |
|
# A sed program to s/FROM/TO/g for all the FROM/TO so that, for |
125 |
|
# instance, we rename #include "y.tab.h" into #include "parse.h" |
126 |
|
# during the conversion from y.tab.c to parse.c. |
127 |
|
rename_sed= |
128 |
while test "$#" -ne 0; do |
while test "$#" -ne 0; do |
129 |
if test "$1" = "--"; then |
if test "$1" = "--"; then |
130 |
shift |
shift |
131 |
break |
break |
132 |
fi |
fi |
133 |
pairlist="$pairlist $1" |
from=$1 |
134 |
|
# Handle y_tab.c and y_tab.h output by DOS |
135 |
|
if $y_tab_nodot; then |
136 |
|
case $from in |
137 |
|
"y.tab.c") from=y_tab.c;; |
138 |
|
"y.tab.h") from=y_tab.h;; |
139 |
|
esac |
140 |
|
fi |
141 |
|
shift |
142 |
|
to=$1 |
143 |
shift |
shift |
144 |
|
rename_sed="${rename_sed}s|"`quote_for_sed "$from"`"|$to|g;" |
145 |
done |
done |
146 |
|
|
147 |
# The program to run. |
# The program to run. |
172 |
ret=$? |
ret=$? |
173 |
|
|
174 |
if test $ret -eq 0; then |
if test $ret -eq 0; then |
175 |
set X $pairlist |
for from in * |
176 |
shift |
do |
177 |
first=yes |
to=`printf '%s\n' "$from" | sed "$rename_sed"` |
|
# Since DOS filename conventions don't allow two dots, |
|
|
# the DOS version of Bison writes out y_tab.c instead of y.tab.c |
|
|
# and y_tab.h instead of y.tab.h. Test to see if this is the case. |
|
|
y_tab_nodot="no" |
|
|
if test -f y_tab.c || test -f y_tab.h; then |
|
|
y_tab_nodot="yes" |
|
|
fi |
|
|
|
|
|
input_rx=`get_dirname "$input" | quote_for_sed` |
|
|
|
|
|
while test "$#" -ne 0; do |
|
|
from="$1" |
|
|
# Handle y_tab.c and y_tab.h output by DOS |
|
|
if test $y_tab_nodot = "yes"; then |
|
|
if test $from = "y.tab.c"; then |
|
|
from="y_tab.c" |
|
|
else |
|
|
if test $from = "y.tab.h"; then |
|
|
from="y_tab.h" |
|
|
fi |
|
|
fi |
|
|
fi |
|
178 |
if test -f "$from"; then |
if test -f "$from"; then |
179 |
# If $2 is an absolute path name, then just use that, |
# If $2 is an absolute path name, then just use that, |
180 |
# otherwise prepend '../'. |
# otherwise prepend '../'. |
181 |
case "$2" in |
case $to in |
182 |
[\\/]* | ?:[\\/]*) target="$2";; |
[\\/]* | ?:[\\/]*) target=$to;; |
183 |
*) target="../$2";; |
*) target="../$to";; |
184 |
esac |
esac |
185 |
|
|
186 |
# We do not want to overwrite a header file if it hasn't |
# Do not overwrite unchanged header files to avoid useless |
187 |
# changed. This avoid useless recompilations. However the |
# recompilations. Always update the parser itself: it is the |
188 |
# parser itself (the first file) should always be updated, |
# destination of the .y.c rule in the Makefile. Divert the |
189 |
# because it is the destination of the .y.c rule in the |
# output of all other files to a temporary file so we can |
190 |
# Makefile. Divert the output of all other files to a temporary |
# compare them to existing versions. |
191 |
# file so we can compare them to existing versions. |
if test $from != $parser; then |
|
if test $first = no; then |
|
192 |
realtarget="$target" |
realtarget="$target" |
193 |
target="tmp-`echo $target | sed s/.*[\\/]//g`" |
target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'` |
194 |
fi |
fi |
|
# Munge "#line" or "#" directives. |
|
|
# We don't want the resulting debug information to point at |
|
|
# an absolute srcdir. |
|
|
# We want to use the real output file name, not yy.lex.c for |
|
|
# instance. |
|
|
# We want the include guards to be adjusted too. |
|
|
FROM=`echo "$from" | sed \ |
|
|
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ |
|
|
-e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` |
|
|
TARGET=`echo "$2" | sed \ |
|
|
-e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ |
|
|
-e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` |
|
195 |
|
|
196 |
sed -e "/^#/!b" -e "s,$input_rx,$input_sub_rx," -e "s,$from,$2," \ |
# Munge "#line" or "#" directives. Don't let the resulting |
197 |
-e "s,$FROM,$TARGET," "$from" >"$target" || ret=$? |
# debug information point at an absolute srcdir. Use the real |
198 |
|
# output file name, not yy.lex.c for instance. Adjust the |
199 |
|
# include guards too. |
200 |
|
FROM=`guard "$from"` |
201 |
|
TARGET=`guard "$to"` |
202 |
|
sed -e "/^#/!b" -e "s|$input_rx|$input_sub_rx|" -e "$rename_sed" \ |
203 |
|
-e "s|$FROM|$TARGET|" "$from" >"$target" || ret=$? |
204 |
|
|
205 |
# Check whether header files must be updated. |
# Check whether files must be updated. |
206 |
if test $first = no; then |
if test "$from" != "$parser"; then |
207 |
if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then |
if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then |
208 |
echo "$2" is unchanged |
echo "$to is unchanged" |
209 |
rm -f "$target" |
rm -f "$target" |
210 |
else |
else |
211 |
echo updating "$2" |
echo "updating $to" |
212 |
mv -f "$target" "$realtarget" |
mv -f "$target" "$realtarget" |
213 |
fi |
fi |
214 |
fi |
fi |
215 |
else |
else |
216 |
# A missing file is only an error for the first file. This |
# A missing file is only an error for the parser. This is a |
217 |
# is a blatant hack to let us support using "yacc -d". If -d |
# blatant hack to let us support using "yacc -d". If -d is not |
218 |
# is not specified, we don't want an error when the header |
# specified, don't fail when the header file is "missing". |
219 |
# file is "missing". |
if test "$from" = "$parser"; then |
|
if test $first = yes; then |
|
220 |
ret=1 |
ret=1 |
221 |
fi |
fi |
222 |
fi |
fi |
|
shift |
|
|
shift |
|
|
first=no |
|
223 |
done |
done |
|
else |
|
|
ret=$? |
|
224 |
fi |
fi |
225 |
|
|
226 |
# Remove the directory. |
# Remove the directory. |