ylwrap revision 1.1.1.1.8.2 1 1.1.1.1.8.2 tls #! /bin/sh
2 1.1.1.1.8.2 tls # ylwrap - wrapper for lex/yacc invocations.
3 1.1.1.1.8.2 tls
4 1.1.1.1.8.2 tls scriptversion=2009-04-28.21; # UTC
5 1.1.1.1.8.2 tls
6 1.1.1.1.8.2 tls # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005,
7 1.1.1.1.8.2 tls # 2007, 2009 Free Software Foundation, Inc.
8 1.1.1.1.8.2 tls #
9 1.1.1.1.8.2 tls # Written by Tom Tromey <tromey (at] cygnus.com>.
10 1.1.1.1.8.2 tls #
11 1.1.1.1.8.2 tls # This program is free software; you can redistribute it and/or modify
12 1.1.1.1.8.2 tls # it under the terms of the GNU General Public License as published by
13 1.1.1.1.8.2 tls # the Free Software Foundation; either version 2, or (at your option)
14 1.1.1.1.8.2 tls # any later version.
15 1.1.1.1.8.2 tls #
16 1.1.1.1.8.2 tls # This program is distributed in the hope that it will be useful,
17 1.1.1.1.8.2 tls # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 1.1.1.1.8.2 tls # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 1.1.1.1.8.2 tls # GNU General Public License for more details.
20 1.1.1.1.8.2 tls #
21 1.1.1.1.8.2 tls # You should have received a copy of the GNU General Public License
22 1.1.1.1.8.2 tls # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 1.1.1.1.8.2 tls
24 1.1.1.1.8.2 tls # As a special exception to the GNU General Public License, if you
25 1.1.1.1.8.2 tls # distribute this file as part of a program that contains a
26 1.1.1.1.8.2 tls # configuration script generated by Autoconf, you may include it under
27 1.1.1.1.8.2 tls # the same distribution terms that you use for the rest of that program.
28 1.1.1.1.8.2 tls
29 1.1.1.1.8.2 tls # This file is maintained in Automake, please report
30 1.1.1.1.8.2 tls # bugs to <bug-automake (at] gnu.org> or send patches to
31 1.1.1.1.8.2 tls # <automake-patches (at] gnu.org>.
32 1.1.1.1.8.2 tls
33 1.1.1.1.8.2 tls case "$1" in
34 1.1.1.1.8.2 tls '')
35 1.1.1.1.8.2 tls echo "$0: No files given. Try \`$0 --help' for more information." 1>&2
36 1.1.1.1.8.2 tls exit 1
37 1.1.1.1.8.2 tls ;;
38 1.1.1.1.8.2 tls --basedir)
39 1.1.1.1.8.2 tls basedir=$2
40 1.1.1.1.8.2 tls shift 2
41 1.1.1.1.8.2 tls ;;
42 1.1.1.1.8.2 tls -h|--h*)
43 1.1.1.1.8.2 tls cat <<\EOF
44 1.1.1.1.8.2 tls Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]...
45 1.1.1.1.8.2 tls
46 1.1.1.1.8.2 tls Wrapper for lex/yacc invocations, renaming files as desired.
47 1.1.1.1.8.2 tls
48 1.1.1.1.8.2 tls INPUT is the input file
49 1.1.1.1.8.2 tls OUTPUT is one file PROG generates
50 1.1.1.1.8.2 tls DESIRED is the file we actually want instead of OUTPUT
51 1.1.1.1.8.2 tls PROGRAM is program to run
52 1.1.1.1.8.2 tls ARGS are passed to PROG
53 1.1.1.1.8.2 tls
54 1.1.1.1.8.2 tls Any number of OUTPUT,DESIRED pairs may be used.
55 1.1.1.1.8.2 tls
56 1.1.1.1.8.2 tls Report bugs to <bug-automake (at] gnu.org>.
57 1.1.1.1.8.2 tls EOF
58 1.1.1.1.8.2 tls exit $?
59 1.1.1.1.8.2 tls ;;
60 1.1.1.1.8.2 tls -v|--v*)
61 1.1.1.1.8.2 tls echo "ylwrap $scriptversion"
62 1.1.1.1.8.2 tls exit $?
63 1.1.1.1.8.2 tls ;;
64 1.1.1.1.8.2 tls esac
65 1.1.1.1.8.2 tls
66 1.1.1.1.8.2 tls
67 1.1.1.1.8.2 tls # The input.
68 1.1.1.1.8.2 tls input="$1"
69 1.1.1.1.8.2 tls shift
70 1.1.1.1.8.2 tls case "$input" in
71 1.1.1.1.8.2 tls [\\/]* | ?:[\\/]*)
72 1.1.1.1.8.2 tls # Absolute path; do nothing.
73 1.1.1.1.8.2 tls ;;
74 1.1.1.1.8.2 tls *)
75 1.1.1.1.8.2 tls # Relative path. Make it absolute.
76 1.1.1.1.8.2 tls input="`pwd`/$input"
77 1.1.1.1.8.2 tls ;;
78 1.1.1.1.8.2 tls esac
79 1.1.1.1.8.2 tls
80 1.1.1.1.8.2 tls pairlist=
81 1.1.1.1.8.2 tls while test "$#" -ne 0; do
82 1.1.1.1.8.2 tls if test "$1" = "--"; then
83 1.1.1.1.8.2 tls shift
84 1.1.1.1.8.2 tls break
85 1.1.1.1.8.2 tls fi
86 1.1.1.1.8.2 tls pairlist="$pairlist $1"
87 1.1.1.1.8.2 tls shift
88 1.1.1.1.8.2 tls done
89 1.1.1.1.8.2 tls
90 1.1.1.1.8.2 tls # The program to run.
91 1.1.1.1.8.2 tls prog="$1"
92 1.1.1.1.8.2 tls shift
93 1.1.1.1.8.2 tls # Make any relative path in $prog absolute.
94 1.1.1.1.8.2 tls case "$prog" in
95 1.1.1.1.8.2 tls [\\/]* | ?:[\\/]*) ;;
96 1.1.1.1.8.2 tls *[\\/]*) prog="`pwd`/$prog" ;;
97 1.1.1.1.8.2 tls esac
98 1.1.1.1.8.2 tls
99 1.1.1.1.8.2 tls # FIXME: add hostname here for parallel makes that run commands on
100 1.1.1.1.8.2 tls # other machines. But that might take us over the 14-char limit.
101 1.1.1.1.8.2 tls dirname=ylwrap$$
102 1.1.1.1.8.2 tls trap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15
103 1.1.1.1.8.2 tls mkdir $dirname || exit 1
104 1.1.1.1.8.2 tls
105 1.1.1.1.8.2 tls cd $dirname
106 1.1.1.1.8.2 tls
107 1.1.1.1.8.2 tls case $# in
108 1.1.1.1.8.2 tls 0) "$prog" "$input" ;;
109 1.1.1.1.8.2 tls *) "$prog" "$@" "$input" ;;
110 1.1.1.1.8.2 tls esac
111 1.1.1.1.8.2 tls ret=$?
112 1.1.1.1.8.2 tls
113 1.1.1.1.8.2 tls if test $ret -eq 0; then
114 1.1.1.1.8.2 tls set X $pairlist
115 1.1.1.1.8.2 tls shift
116 1.1.1.1.8.2 tls first=yes
117 1.1.1.1.8.2 tls # Since DOS filename conventions don't allow two dots,
118 1.1.1.1.8.2 tls # the DOS version of Bison writes out y_tab.c instead of y.tab.c
119 1.1.1.1.8.2 tls # and y_tab.h instead of y.tab.h. Test to see if this is the case.
120 1.1.1.1.8.2 tls y_tab_nodot="no"
121 1.1.1.1.8.2 tls if test -f y_tab.c || test -f y_tab.h; then
122 1.1.1.1.8.2 tls y_tab_nodot="yes"
123 1.1.1.1.8.2 tls fi
124 1.1.1.1.8.2 tls
125 1.1.1.1.8.2 tls # The directory holding the input.
126 1.1.1.1.8.2 tls input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
127 1.1.1.1.8.2 tls # Quote $INPUT_DIR so we can use it in a regexp.
128 1.1.1.1.8.2 tls # FIXME: really we should care about more than `.' and `\'.
129 1.1.1.1.8.2 tls input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
130 1.1.1.1.8.2 tls
131 1.1.1.1.8.2 tls while test "$#" -ne 0; do
132 1.1.1.1.8.2 tls from="$1"
133 1.1.1.1.8.2 tls # Handle y_tab.c and y_tab.h output by DOS
134 1.1.1.1.8.2 tls if test $y_tab_nodot = "yes"; then
135 1.1.1.1.8.2 tls if test $from = "y.tab.c"; then
136 1.1.1.1.8.2 tls from="y_tab.c"
137 1.1.1.1.8.2 tls else
138 1.1.1.1.8.2 tls if test $from = "y.tab.h"; then
139 1.1.1.1.8.2 tls from="y_tab.h"
140 1.1.1.1.8.2 tls fi
141 1.1.1.1.8.2 tls fi
142 1.1.1.1.8.2 tls fi
143 1.1.1.1.8.2 tls if test -f "$from"; then
144 1.1.1.1.8.2 tls # If $2 is an absolute path name, then just use that,
145 1.1.1.1.8.2 tls # otherwise prepend `../'.
146 1.1.1.1.8.2 tls case "$2" in
147 1.1.1.1.8.2 tls [\\/]* | ?:[\\/]*) target="$2";;
148 1.1.1.1.8.2 tls *) target="../$2";;
149 1.1.1.1.8.2 tls esac
150 1.1.1.1.8.2 tls
151 1.1.1.1.8.2 tls # We do not want to overwrite a header file if it hasn't
152 1.1.1.1.8.2 tls # changed. This avoid useless recompilations. However the
153 1.1.1.1.8.2 tls # parser itself (the first file) should always be updated,
154 1.1.1.1.8.2 tls # because it is the destination of the .y.c rule in the
155 1.1.1.1.8.2 tls # Makefile. Divert the output of all other files to a temporary
156 1.1.1.1.8.2 tls # file so we can compare them to existing versions.
157 1.1.1.1.8.2 tls if test $first = no; then
158 1.1.1.1.8.2 tls realtarget="$target"
159 1.1.1.1.8.2 tls target="tmp-`echo $target | sed s/.*[\\/]//g`"
160 1.1.1.1.8.2 tls fi
161 1.1.1.1.8.2 tls # Edit out `#line' or `#' directives.
162 1.1.1.1.8.2 tls #
163 1.1.1.1.8.2 tls # We don't want the resulting debug information to point at
164 1.1.1.1.8.2 tls # an absolute srcdir; it is better for it to just mention the
165 1.1.1.1.8.2 tls # .y file with no path.
166 1.1.1.1.8.2 tls #
167 1.1.1.1.8.2 tls # We want to use the real output file name, not yy.lex.c for
168 1.1.1.1.8.2 tls # instance.
169 1.1.1.1.8.2 tls #
170 1.1.1.1.8.2 tls # We want the include guards to be adjusted too.
171 1.1.1.1.8.2 tls FROM=`echo "$from" | sed \
172 1.1.1.1.8.2 tls -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
173 1.1.1.1.8.2 tls -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
174 1.1.1.1.8.2 tls TARGET=`echo "$2" | sed \
175 1.1.1.1.8.2 tls -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
176 1.1.1.1.8.2 tls -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
177 1.1.1.1.8.2 tls
178 1.1.1.1.8.2 tls sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
179 1.1.1.1.8.2 tls -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
180 1.1.1.1.8.2 tls
181 1.1.1.1.8.2 tls # Check whether header files must be updated.
182 1.1.1.1.8.2 tls if test $first = no; then
183 1.1.1.1.8.2 tls if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
184 1.1.1.1.8.2 tls echo "$2" is unchanged
185 1.1.1.1.8.2 tls rm -f "$target"
186 1.1.1.1.8.2 tls else
187 1.1.1.1.8.2 tls echo updating "$2"
188 1.1.1.1.8.2 tls mv -f "$target" "$realtarget"
189 1.1.1.1.8.2 tls fi
190 1.1.1.1.8.2 tls fi
191 1.1.1.1.8.2 tls else
192 1.1.1.1.8.2 tls # A missing file is only an error for the first file. This
193 1.1.1.1.8.2 tls # is a blatant hack to let us support using "yacc -d". If -d
194 1.1.1.1.8.2 tls # is not specified, we don't want an error when the header
195 1.1.1.1.8.2 tls # file is "missing".
196 1.1.1.1.8.2 tls if test $first = yes; then
197 1.1.1.1.8.2 tls ret=1
198 1.1.1.1.8.2 tls fi
199 1.1.1.1.8.2 tls fi
200 1.1.1.1.8.2 tls shift
201 1.1.1.1.8.2 tls shift
202 1.1.1.1.8.2 tls first=no
203 1.1.1.1.8.2 tls done
204 1.1.1.1.8.2 tls else
205 1.1.1.1.8.2 tls ret=$?
206 1.1.1.1.8.2 tls fi
207 1.1.1.1.8.2 tls
208 1.1.1.1.8.2 tls # Remove the directory.
209 1.1.1.1.8.2 tls cd ..
210 1.1.1.1.8.2 tls rm -rf $dirname
211 1.1.1.1.8.2 tls
212 1.1.1.1.8.2 tls exit $ret
213 1.1.1.1.8.2 tls
214 1.1.1.1.8.2 tls # Local Variables:
215 1.1.1.1.8.2 tls # mode: shell-script
216 1.1.1.1.8.2 tls # sh-indentation: 2
217 1.1.1.1.8.2 tls # eval: (add-hook 'write-file-hooks 'time-stamp)
218 1.1.1.1.8.2 tls # time-stamp-start: "scriptversion="
219 1.1.1.1.8.2 tls # time-stamp-format: "%:y-%02m-%02d.%02H"
220 1.1.1.1.8.2 tls # time-stamp-time-zone: "UTC"
221 1.1.1.1.8.2 tls # time-stamp-end: "; # UTC"
222 1.1.1.1.8.2 tls # End:
223