16
21
# You should have received a copy of the GNU General Public License
17
22
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
26
# As a special exception to the GNU General Public License, if you
21
27
# distribute this file as part of a program that contains a
22
28
# configuration script generated by Autoconf, you may include it under
23
29
# the same distribution terms that you use for the rest of that program.
26
# ylwrap INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
27
# * INPUT is the input file
28
# * OUTPUT is file PROG generates
29
# * DESIRED is file we actually want
30
# * PROGRAM is program to run
31
# * ARGS are passed to PROG
32
# Any number of OUTPUT,DESIRED pairs may be used.
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"
39
74
# Absolute path; do nothing.
42
77
# Relative path. Make it absolute.
43
78
input="`pwd`/$input"
47
# The directory holding the input.
48
input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
49
# Quote $INPUT_DIR so we can use it in a regexp.
50
# FIXME: really we should care about more than `.' and `\'.
51
input_rx=`echo "$input_dir" | sed -e 's,\\\\,\\\\\\\\,g' -e 's,\\.,\\\\.,g'`
56
83
while test "$#" -ne 0; do
57
if test "$1" = "--"; then
61
pairlist="$pairlist $1"
84
if test "$1" = "--"; then
88
pairlist="$pairlist $1"
65
92
# The program to run.
82
$prog ${1+"$@"} "$input"
85
if test $status -eq 0; then
89
# Since DOS filename conventions don't allow two dots,
90
# the DOS version of Bison writes out y_tab.c instead of y.tab.c
91
# and y_tab.h instead of y.tab.h. Test to see if this is the case.
93
if test -f y_tab.c || test -f y_tab.h; then
97
while test "$#" -ne 0; do
99
# Handle y_tab.c and y_tab.h output by DOS
100
if test $y_tab_nodot = "yes"; then
101
if test $from = "y.tab.c"; then
104
if test $from = "y.tab.h"; then
109
if test -f "$from"; then
110
# If $2 is an absolute path name, then just use that,
111
# otherwise prepend `../'.
113
[\\/]* | ?:[\\/]*) target="$2";;
117
# Edit out `#line' or `#' directives. We don't want the
118
# resulting debug information to point at an absolute srcdir;
119
# it is better for it to just mention the .y file with no
121
sed -e "/^#/ s,$input_rx,," "$from" > "$target" || status=$?
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
123
# A missing file is only an error for the first file. This
124
# is a blatant hack to let us support using "yacc -d". If -d
125
# is not specified, we don't want an error when the header
127
if test $first = yes; 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
139
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: "$"