comparison ylwrap @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents 77e2b8dfacca
children
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 #! /bin/sh 1 #! /bin/sh
2 # ylwrap - wrapper for lex/yacc invocations. 2 # ylwrap - wrapper for lex/yacc invocations.
3 3
4 scriptversion=2009-04-28.21; # UTC 4 scriptversion=2013-01-12.17; # UTC
5 5
6 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 6 # Copyright (C) 1996-2014 Free Software Foundation, Inc.
7 # 2007, 2009 Free Software Foundation, Inc.
8 # 7 #
9 # Written by Tom Tromey <tromey@cygnus.com>. 8 # Written by Tom Tromey <tromey@cygnus.com>.
10 # 9 #
11 # This program is free software; you can redistribute it and/or modify 10 # 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 11 # it under the terms of the GNU General Public License as published by
28 27
29 # This file is maintained in Automake, please report 28 # This file is maintained in Automake, please report
30 # bugs to <bug-automake@gnu.org> or send patches to 29 # bugs to <bug-automake@gnu.org> or send patches to
31 # <automake-patches@gnu.org>. 30 # <automake-patches@gnu.org>.
32 31
32 get_dirname ()
33 {
34 case $1 in
35 */*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';;
36 # Otherwise, we want the empty string (not ".").
37 esac
38 }
39
40 # guard FILE
41 # ----------
42 # The CPP macro used to guard inclusion of FILE.
43 guard ()
44 {
45 printf '%s\n' "$1" \
46 | sed \
47 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
48 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' \
49 -e 's/__*/_/g'
50 }
51
52 # quote_for_sed [STRING]
53 # ----------------------
54 # Return STRING (or stdin) quoted to be used as a sed pattern.
55 quote_for_sed ()
56 {
57 case $# in
58 0) cat;;
59 1) printf '%s\n' "$1";;
60 esac \
61 | sed -e 's|[][\\.*]|\\&|g'
62 }
63
33 case "$1" in 64 case "$1" in
34 '') 65 '')
35 echo "$0: No files given. Try \`$0 --help' for more information." 1>&2 66 echo "$0: No files given. Try '$0 --help' for more information." 1>&2
36 exit 1 67 exit 1
37 ;; 68 ;;
38 --basedir) 69 --basedir)
39 basedir=$2 70 basedir=$2
40 shift 2 71 shift 2
63 ;; 94 ;;
64 esac 95 esac
65 96
66 97
67 # The input. 98 # The input.
68 input="$1" 99 input=$1
69 shift 100 shift
70 case "$input" in 101 # We'll later need for a correct munging of "#line" directives.
102 input_sub_rx=`get_dirname "$input" | quote_for_sed`
103 case $input in
71 [\\/]* | ?:[\\/]*) 104 [\\/]* | ?:[\\/]*)
72 # Absolute path; do nothing. 105 # Absolute path; do nothing.
73 ;; 106 ;;
74 *) 107 *)
75 # Relative path. Make it absolute. 108 # Relative path. Make it absolute.
76 input="`pwd`/$input" 109 input=`pwd`/$input
77 ;; 110 ;;
78 esac 111 esac
79 112 input_rx=`get_dirname "$input" | quote_for_sed`
80 pairlist= 113
81 while test "$#" -ne 0; do 114 # The parser itself, the first file, is the destination of the .y.c
82 if test "$1" = "--"; then 115 # rule in the Makefile.
116 parser=$1
117
118 # A sed program to s/FROM/TO/g for all the FROM/TO so that, for
119 # instance, we rename #include "y.tab.h" into #include "parse.h"
120 # during the conversion from y.tab.c to parse.c.
121 sed_fix_filenames=
122
123 # Also rename header guards, as Bison 2.7 for instance uses its header
124 # guard in its implementation file.
125 sed_fix_header_guards=
126
127 while test $# -ne 0; do
128 if test x"$1" = x"--"; then
83 shift 129 shift
84 break 130 break
85 fi 131 fi
86 pairlist="$pairlist $1" 132 from=$1
87 shift 133 shift
134 to=$1
135 shift
136 sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;"
137 sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;"
88 done 138 done
89 139
90 # The program to run. 140 # The program to run.
91 prog="$1" 141 prog=$1
92 shift 142 shift
93 # Make any relative path in $prog absolute. 143 # Make any relative path in $prog absolute.
94 case "$prog" in 144 case $prog in
95 [\\/]* | ?:[\\/]*) ;; 145 [\\/]* | ?:[\\/]*) ;;
96 *[\\/]*) prog="`pwd`/$prog" ;; 146 *[\\/]*) prog=`pwd`/$prog ;;
97 esac 147 esac
98 148
99 # FIXME: add hostname here for parallel makes that run commands on
100 # other machines. But that might take us over the 14-char limit.
101 dirname=ylwrap$$ 149 dirname=ylwrap$$
102 trap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 150 do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret'
151 trap "ret=129; $do_exit" 1
152 trap "ret=130; $do_exit" 2
153 trap "ret=141; $do_exit" 13
154 trap "ret=143; $do_exit" 15
103 mkdir $dirname || exit 1 155 mkdir $dirname || exit 1
104 156
105 cd $dirname 157 cd $dirname
106 158
107 case $# in 159 case $# in
109 *) "$prog" "$@" "$input" ;; 161 *) "$prog" "$@" "$input" ;;
110 esac 162 esac
111 ret=$? 163 ret=$?
112 164
113 if test $ret -eq 0; then 165 if test $ret -eq 0; then
114 set X $pairlist 166 for from in *
115 shift 167 do
116 first=yes 168 to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"`
117 # Since DOS filename conventions don't allow two dots,
118 # the DOS version of Bison writes out y_tab.c instead of y.tab.c
119 # and y_tab.h instead of y.tab.h. Test to see if this is the case.
120 y_tab_nodot="no"
121 if test -f y_tab.c || test -f y_tab.h; then
122 y_tab_nodot="yes"
123 fi
124
125 # The directory holding the input.
126 input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'`
127 # Quote $INPUT_DIR so we can use it in a regexp.
128 # FIXME: really we should care about more than `.' and `\'.
129 input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'`
130
131 while test "$#" -ne 0; do
132 from="$1"
133 # Handle y_tab.c and y_tab.h output by DOS
134 if test $y_tab_nodot = "yes"; then
135 if test $from = "y.tab.c"; then
136 from="y_tab.c"
137 else
138 if test $from = "y.tab.h"; then
139 from="y_tab.h"
140 fi
141 fi
142 fi
143 if test -f "$from"; then 169 if test -f "$from"; then
144 # If $2 is an absolute path name, then just use that, 170 # If $2 is an absolute path name, then just use that,
145 # otherwise prepend `../'. 171 # otherwise prepend '../'.
146 case "$2" in 172 case $to in
147 [\\/]* | ?:[\\/]*) target="$2";; 173 [\\/]* | ?:[\\/]*) target=$to;;
148 *) target="../$2";; 174 *) target=../$to;;
149 esac 175 esac
150 176
151 # We do not want to overwrite a header file if it hasn't 177 # Do not overwrite unchanged header files to avoid useless
152 # changed. This avoid useless recompilations. However the 178 # recompilations. Always update the parser itself: it is the
153 # parser itself (the first file) should always be updated, 179 # destination of the .y.c rule in the Makefile. Divert the
154 # because it is the destination of the .y.c rule in the 180 # output of all other files to a temporary file so we can
155 # Makefile. Divert the output of all other files to a temporary 181 # compare them to existing versions.
156 # file so we can compare them to existing versions. 182 if test $from != $parser; then
157 if test $first = no; then 183 realtarget=$target
158 realtarget="$target" 184 target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'`
159 target="tmp-`echo $target | sed s/.*[\\/]//g`"
160 fi 185 fi
161 # Edit out `#line' or `#' directives. 186
162 # 187 # Munge "#line" or "#" directives. Don't let the resulting
163 # We don't want the resulting debug information to point at 188 # debug information point at an absolute srcdir. Use the real
164 # an absolute srcdir; it is better for it to just mention the 189 # output file name, not yy.lex.c for instance. Adjust the
165 # .y file with no path. 190 # include guards too.
166 # 191 sed -e "/^#/!b" \
167 # We want to use the real output file name, not yy.lex.c for 192 -e "s|$input_rx|$input_sub_rx|" \
168 # instance. 193 -e "$sed_fix_filenames" \
169 # 194 -e "$sed_fix_header_guards" \
170 # We want the include guards to be adjusted too. 195 "$from" >"$target" || ret=$?
171 FROM=`echo "$from" | sed \ 196
172 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 197 # Check whether files must be updated.
173 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 198 if test "$from" != "$parser"; then
174 TARGET=`echo "$2" | sed \ 199 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
175 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 200 echo "$to is unchanged"
176 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 201 rm -f "$target"
177 202 else
178 sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \ 203 echo "updating $to"
179 -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$?
180
181 # Check whether header files must be updated.
182 if test $first = no; then
183 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
184 echo "$2" is unchanged
185 rm -f "$target"
186 else
187 echo updating "$2"
188 mv -f "$target" "$realtarget" 204 mv -f "$target" "$realtarget"
189 fi 205 fi
190 fi 206 fi
191 else 207 else
192 # A missing file is only an error for the first file. This 208 # A missing file is only an error for the parser. This is a
193 # is a blatant hack to let us support using "yacc -d". If -d 209 # blatant hack to let us support using "yacc -d". If -d is not
194 # is not specified, we don't want an error when the header 210 # specified, don't fail when the header file is "missing".
195 # file is "missing". 211 if test "$from" = "$parser"; then
196 if test $first = yes; then
197 ret=1 212 ret=1
198 fi 213 fi
199 fi 214 fi
200 shift
201 shift
202 first=no
203 done 215 done
204 else
205 ret=$?
206 fi 216 fi
207 217
208 # Remove the directory. 218 # Remove the directory.
209 cd .. 219 cd ..
210 rm -rf $dirname 220 rm -rf $dirname