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"
68 */*|*\\*) printf '%s\n' "$1" | sed -e 's,\([\\/]\)[^\\/]*$,\1,';;
69 # Otherwise, we want the empty string (not ".").
75 # FIXME: really we should care about more than '.' and '\'.
76 sed -e 's,[\\.],\\&,g'
82 # We'll later need for a correct munging of "#line" directives.
83 input_sub_rx=`get_dirname "$input" | quote_for_sed`
86 # Absolute path; do nothing.
89 # Relative path. Make it absolute.
95 while test "$#" -ne 0; do
96 if test "$1" = "--"; then
100 pairlist="$pairlist $1"
104 # The program to run.
107 # Make any relative path in $prog absolute.
109 [\\/]* | ?:[\\/]*) ;;
110 *[\\/]*) prog="`pwd`/$prog" ;;
113 # FIXME: add hostname here for parallel makes that run commands on
114 # other machines. But that might take us over the 14-char limit.
116 do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
117 trap "ret=129; $do_exit" 1
118 trap "ret=130; $do_exit" 2
119 trap "ret=141; $do_exit" 13
120 trap "ret=143; $do_exit" 15
121 mkdir $dirname || exit 1
126 0) "$prog" "$input" ;;
127 *) "$prog" "$@" "$input" ;;
131 if test $ret -eq 0; then
135 # Since DOS filename conventions don't allow two dots,
136 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
137 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
139 if test -f y_tab.c || test -f y_tab.h; then
143 input_rx=`get_dirname "$input" | quote_for_sed`
145 while test "$#" -ne 0; do
147 # Handle y_tab.c and y_tab.h output by DOS
148 if test $y_tab_nodot = "yes"; then
149 if test $from = "y.tab.c"; then
152 if test $from = "y.tab.h"; then
157 if test -f "$from"; then
158 # If $2 is an absolute path name, then just use that,
159 # otherwise prepend '../'.
161 [\\/]* | ?:[\\/]*) target="$2";;
165 # We do not want to overwrite a header file if it hasn't
166 # changed. This avoid useless recompilations. However the
167 # parser itself (the first file) should always be updated,
168 # because it is the destination of the .y.c rule in the
169 # Makefile. Divert the output of all other files to a temporary
170 # file so we can compare them to existing versions.
171 if test $first = no; then
173 target="tmp-`echo $target | sed s/.*[\\/]//g`"
175 # Munge "#line" or "#" directives.
176 # We don't want the resulting debug information to point at
177 # an absolute srcdir.
178 # We want to use the real output file name, not yy.lex.c for
180 # We want the include guards to be adjusted too.
181 FROM=`echo "$from" | sed \
182 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
183 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
184 TARGET=`echo "$2" | sed \
185 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
186 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
188 sed -e "/^#/!b" -e "s,$input_rx,$input_sub_rx," -e "s,$from,$2," \
189 -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
191 # Check whether header files must be updated.
192 if test $first = no; then
193 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
194 echo "$2" is unchanged
198 mv -f "$target" "$realtarget"
202 # A missing file is only an error for the first file. This
203 # is a blatant hack to let us support using "yacc -d". If -d
204 # is not specified, we don't want an error when the header
206 if test $first = yes; then
218 # Remove the directory.
227 # eval: (add-hook 'write-file-hooks 'time-stamp)
228 # time-stamp-start: "scriptversion="
229 # time-stamp-format: "%:y-%02m-%02d.%02H"
230 # time-stamp-time-zone: "UTC"
231 # time-stamp-end: "; # UTC"