2 # ylwrap - wrapper for lex/yacc invocations.
4 scriptversion=2012-07-13.14; # 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>.
35 */*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';;
36 # Otherwise, we want the empty string (not ".").
42 # The CPP macro used to guard inclusion of FILE.
45 printf '%s\n' "$from" \
47 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
48 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'
51 # quote_for_sed [STRING]
52 # ----------------------
53 # Return STRING (or stdin) quoted to be used as a sed pattern.
58 1) printf '%s\n' "$1";;
60 | sed -e 's|[][\\.*]|\\&|g'
65 echo "$0: No files given. Try '$0 --help' for more information." 1>&2
74 Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
76 Wrapper for lex/yacc invocations, renaming files as desired.
78 INPUT is the input file
79 OUTPUT is one file PROG generates
80 DESIRED is the file we actually want instead of OUTPUT
81 PROGRAM is program to run
82 ARGS are passed to PROG
84 Any number of OUTPUT,DESIRED pairs may be used.
86 Report bugs to <bug-automake@gnu.org>.
91 echo "ylwrap $scriptversion"
100 # We'll later need for a correct munging of "#line" directives.
101 input_sub_rx=`get_dirname "$input" | quote_for_sed`
104 # Absolute path; do nothing.
107 # Relative path. Make it absolute.
112 # Since DOS filename conventions don't allow two dots,
113 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
114 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
116 if test -f y_tab.c || test -f y_tab.h; then
120 # The parser itself, the first file, is the destination of the .y.c
121 # rule in the Makefile.
123 # The list of file to rename: FROM TO...
125 # A sed program to s/FROM/TO/g for all the FROM/TO so that, for
126 # instance, we rename #include "y.tab.h" into #include "parse.h"
127 # during the conversion from y.tab.c to parse.c.
129 while test "$#" -ne 0; do
130 if test "$1" = "--"; then
135 # Handle y_tab.c and y_tab.h output by DOS
136 if $y_tab_nodot; then
138 "y.tab.c") from=y_tab.c;;
139 "y.tab.h") from=y_tab.h;;
145 pairlist="$pairlist $from $to"
146 rename_sed="${rename_sed}s|"`quote_for_sed "$from"`"|$to|g;"
149 # The program to run.
152 # Make any relative path in $prog absolute.
154 [\\/]* | ?:[\\/]*) ;;
155 *[\\/]*) prog="`pwd`/$prog" ;;
158 # FIXME: add hostname here for parallel makes that run commands on
159 # other machines. But that might take us over the 14-char limit.
161 do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
162 trap "ret=129; $do_exit" 1
163 trap "ret=130; $do_exit" 2
164 trap "ret=141; $do_exit" 13
165 trap "ret=143; $do_exit" 15
166 mkdir $dirname || exit 1
171 0) "$prog" "$input" ;;
172 *) "$prog" "$@" "$input" ;;
176 if test $ret -eq 0; then
180 input_rx=`get_dirname "$input" | quote_for_sed`
182 while test "$#" -ne 0; do
185 if test -f "$from"; then
186 # If $2 is an absolute path name, then just use that,
187 # otherwise prepend '../'.
189 [\\/]* | ?:[\\/]*) target=$to;;
193 # Do not overwrite unchanged header files to avoid useless
194 # recompilations. Always update the parser itself: it is the
195 # destination of the .y.c rule in the Makefile. Divert the
196 # output of all other files to a temporary file so we can
197 # compare them to existing versions.
198 if test $from != $parser; then
200 target=tmp-`printf '%s\n' "$target" | sed s/.*[\\/]//g`
203 # Munge "#line" or "#" directives. Don't let the resulting
204 # debug information point at an absolute srcdir. Use the real
205 # output file name, not yy.lex.c for instance. Adjust the
206 # include guards too.
209 sed -e "/^#/!b" -e "s|$input_rx|$input_sub_rx|" -e "$rename_sed" \
210 -e "s|$FROM|$TARGET|" "$from" >"$target" || ret=$?
212 # Check whether files must be updated.
213 if test "$from" != "$parser"; then
214 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
215 echo "$to is unchanged"
219 mv -f "$target" "$realtarget"
223 # A missing file is only an error for the parser. This is a
224 # blatant hack to let us support using "yacc -d". If -d is not
225 # specified, don't fail when the header file is "missing".
226 if test "$from" = "$parser"; then
237 # Remove the directory.
246 # eval: (add-hook 'write-file-hooks 'time-stamp)
247 # time-stamp-start: "scriptversion="
248 # time-stamp-format: "%:y-%02m-%02d.%02H"
249 # time-stamp-time-zone: "UTC"
250 # time-stamp-end: "; # UTC"