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