2 # ylwrap - wrapper for lex/yacc invocations.
4 scriptversion=2009-04-28.21; # UTC
6 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
7 # 2007, 2009 Free Software Foundation, Inc.
9 # Written by Tom Tromey <tromey@cygnus.com>.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # As a special exception to the GNU General Public License, if you
25 # distribute this file as part of a program that contains a
26 # configuration script generated by Autoconf, you may include it under
27 # the same distribution terms that you use for the rest of that program.
29 # This file is maintained in Automake, please report
30 # bugs to <bug-automake@gnu.org> or send patches to
31 # <automake-patches@gnu.org>.
35 echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
44 Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
46 Wrapper for lex/yacc invocations, renaming files as desired.
48 INPUT is the input file
49 OUTPUT is one file PROG generates
50 DESIRED is the file we actually want instead of OUTPUT
51 PROGRAM is program to run
52 ARGS are passed to PROG
54 Any number of OUTPUT,DESIRED pairs may be used.
56 Report bugs to <bug-automake@gnu.org>.
61 echo "ylwrap $scriptversion"
72 # Absolute path; do nothing.
75 # Relative path. Make it absolute.
81 while test "$#" -ne 0; do
82 if test "$1" = "--"; then
86 pairlist="$pairlist $1"
93 # Make any relative path in $prog absolute.
96 *[\\/]*) prog="`pwd`/$prog" ;;
99 # FIXME: add hostname here for parallel makes that run commands on
100 # other machines. But that might take us over the 14-char limit.
102 trap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
103 mkdir $dirname || exit 1
108 0) "$prog" "$input" ;;
109 *) "$prog" "$@" "$input" ;;
113 if test $ret -eq 0; then
117 # Since DOS filename conventions don't allow two dots,
118 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
119 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
121 if test -f y_tab.c || test -f y_tab.h; then
125 # The directory holding the input.
126 input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
127 # Quote $INPUT_DIR so we can use it in a regexp.
128 # FIXME: really we should care about more than `.' and `\'.
129 input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
131 while test "$#" -ne 0; do
133 # Handle y_tab.c and y_tab.h output by DOS
134 if test $y_tab_nodot = "yes"; then
135 if test $from = "y.tab.c"; then
138 if test $from = "y.tab.h"; then
143 if test -f "$from"; then
144 # If $2 is an absolute path name, then just use that,
145 # otherwise prepend `../'.
147 [\\/]* | ?:[\\/]*) target="$2";;
151 # We do not want to overwrite a header file if it hasn't
152 # changed. This avoid useless recompilations. However the
153 # parser itself (the first file) should always be updated,
154 # because it is the destination of the .y.c rule in the
155 # Makefile. Divert the output of all other files to a temporary
156 # file so we can compare them to existing versions.
157 if test $first = no; then
159 target="tmp-`echo $target | sed s/.*[\\/]//g`"
161 # Edit out `#line' or `#' directives.
163 # We don't want the resulting debug information to point at
164 # an absolute srcdir; it is better for it to just mention the
165 # .y file with no path.
167 # We want to use the real output file name, not yy.lex.c for
170 # We want the include guards to be adjusted too.
171 FROM=`echo "$from" | sed \
172 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
173 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
174 TARGET=`echo "$2" | sed \
175 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
176 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
178 sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
179 -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
181 # Check whether header files must be updated.
182 if test $first = no; then
183 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
184 echo "$2" is unchanged
188 mv -f "$target" "$realtarget"
192 # A missing file is only an error for the first file. This
193 # is a blatant hack to let us support using "yacc -d". If -d
194 # is not specified, we don't want an error when the header
196 if test $first = yes; then
208 # Remove the directory.
217 # eval: (add-hook 'write-file-hooks 'time-stamp)
218 # time-stamp-start: "scriptversion="
219 # time-stamp-format: "%:y-%02m-%02d.%02H"
220 # time-stamp-time-zone: "UTC"
221 # time-stamp-end: "; # UTC"