2 # ylwrap - wrapper for lex/yacc invocations.
4 scriptversion=2011-08-25.18; # UTC
6 # Copyright (C) 1996-2012 Free Software Foundation, Inc.
8 # Written by Tom Tromey <tromey@cygnus.com>.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
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.
28 # This file is maintained in Automake, please report
29 # bugs to <bug-automake@gnu.org> or send patches to
30 # <automake-patches@gnu.org>.
34 echo "$0: No files given. Try '$0 --help' for more information." 1>&2
43 Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
45 Wrapper for lex/yacc invocations, renaming files as desired.
47 INPUT is the input file
48 OUTPUT is one file PROG generates
49 DESIRED is the file we actually want instead of OUTPUT
50 PROGRAM is program to run
51 ARGS are passed to PROG
53 Any number of OUTPUT,DESIRED pairs may be used.
55 Report bugs to <bug-automake@gnu.org>.
60 echo "ylwrap $scriptversion"
71 # Absolute path; do nothing.
74 # Relative path. Make it absolute.
80 while test "$#" -ne 0; do
81 if test "$1" = "--"; then
85 pairlist="$pairlist $1"
92 # Make any relative path in $prog absolute.
95 *[\\/]*) prog="`pwd`/$prog" ;;
98 # FIXME: add hostname here for parallel makes that run commands on
99 # other machines. But that might take us over the 14-char limit.
101 do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
102 trap "ret=129; $do_exit" 1
103 trap "ret=130; $do_exit" 2
104 trap "ret=141; $do_exit" 13
105 trap "ret=143; $do_exit" 15
106 mkdir $dirname || exit 1
111 0) "$prog" "$input" ;;
112 *) "$prog" "$@" "$input" ;;
116 if test $ret -eq 0; then
120 # Since DOS filename conventions don't allow two dots,
121 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
122 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
124 if test -f y_tab.c || test -f y_tab.h; then
128 # The directory holding the input.
129 input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
130 # Quote $INPUT_DIR so we can use it in a regexp.
131 # FIXME: really we should care about more than '.' and '\'.
132 input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
134 while test "$#" -ne 0; do
136 # Handle y_tab.c and y_tab.h output by DOS
137 if test $y_tab_nodot = "yes"; then
138 if test $from = "y.tab.c"; then
141 if test $from = "y.tab.h"; then
146 if test -f "$from"; then
147 # If $2 is an absolute path name, then just use that,
148 # otherwise prepend '../'.
150 [\\/]* | ?:[\\/]*) target="$2";;
154 # We do not want to overwrite a header file if it hasn't
155 # changed. This avoid useless recompilations. However the
156 # parser itself (the first file) should always be updated,
157 # because it is the destination of the .y.c rule in the
158 # Makefile. Divert the output of all other files to a temporary
159 # file so we can compare them to existing versions.
160 if test $first = no; then
162 target="tmp-`echo $target | sed s/.*[\\/]//g`"
164 # Edit out '#line' or '#' directives.
166 # We don't want the resulting debug information to point at
167 # an absolute srcdir; it is better for it to just mention the
168 # .y file with no path.
170 # We want to use the real output file name, not yy.lex.c for
173 # We want the include guards to be adjusted too.
174 FROM=`echo "$from" | sed \
175 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
176 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
177 TARGET=`echo "$2" | sed \
178 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
179 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
181 sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
182 -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
184 # Check whether header files must be updated.
185 if test $first = no; then
186 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
187 echo "$2" is unchanged
191 mv -f "$target" "$realtarget"
195 # A missing file is only an error for the first file. This
196 # is a blatant hack to let us support using "yacc -d". If -d
197 # is not specified, we don't want an error when the header
199 if test $first = yes; then
211 # Remove the directory.
220 # eval: (add-hook 'write-file-hooks 'time-stamp)
221 # time-stamp-start: "scriptversion="
222 # time-stamp-format: "%:y-%02m-%02d.%02H"
223 # time-stamp-time-zone: "UTC"
224 # time-stamp-end: "; # UTC"