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