2 # ylwrap - wrapper for lex/yacc invocations.
4 scriptversion=2010-02-06.18; # UTC
6 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
7 # 2007, 2009, 2010 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 do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
103 trap "ret=129; $do_exit" 1
104 trap "ret=130; $do_exit" 2
105 trap "ret=141; $do_exit" 13
106 trap "ret=143; $do_exit" 15
107 mkdir $dirname || exit 1
112 0) "$prog" "$input" ;;
113 *) "$prog" "$@" "$input" ;;
117 if test $ret -eq 0; then
121 # Since DOS filename conventions don't allow two dots,
122 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
123 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
125 if test -f y_tab.c || test -f y_tab.h; then
129 # The directory holding the input.
130 input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
131 # Quote $INPUT_DIR so we can use it in a regexp.
132 # FIXME: really we should care about more than `.' and `\'.
133 input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
135 while test "$#" -ne 0; do
137 # Handle y_tab.c and y_tab.h output by DOS
138 if test $y_tab_nodot = "yes"; then
139 if test $from = "y.tab.c"; then
142 if test $from = "y.tab.h"; then
147 if test -f "$from"; then
148 # If $2 is an absolute path name, then just use that,
149 # otherwise prepend `../'.
151 [\\/]* | ?:[\\/]*) target="$2";;
155 # We do not want to overwrite a header file if it hasn't
156 # changed. This avoid useless recompilations. However the
157 # parser itself (the first file) should always be updated,
158 # because it is the destination of the .y.c rule in the
159 # Makefile. Divert the output of all other files to a temporary
160 # file so we can compare them to existing versions.
161 if test $first = no; then
163 target="tmp-`echo $target | sed s/.*[\\/]//g`"
165 # Edit out `#line' or `#' directives.
167 # We don't want the resulting debug information to point at
168 # an absolute srcdir; it is better for it to just mention the
169 # .y file with no path.
171 # We want to use the real output file name, not yy.lex.c for
174 # We want the include guards to be adjusted too.
175 FROM=`echo "$from" | sed \
176 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
177 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
178 TARGET=`echo "$2" | sed \
179 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
180 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
182 sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
183 -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
185 # Check whether header files must be updated.
186 if test $first = no; then
187 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
188 echo "$2" is unchanged
192 mv -f "$target" "$realtarget"
196 # A missing file is only an error for the first file. This
197 # is a blatant hack to let us support using "yacc -d". If -d
198 # is not specified, we don't want an error when the header
200 if test $first = yes; then
212 # Remove the directory.
221 # eval: (add-hook 'write-file-hooks 'time-stamp)
222 # time-stamp-start: "scriptversion="
223 # time-stamp-format: "%:y-%02m-%02d.%02H"
224 # time-stamp-time-zone: "UTC"
225 # time-stamp-end: "; # UTC"