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