Changeset 59310bf for automake/ylwrap
- Timestamp:
- Jul 28, 2017, 2:26:14 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 79dbb79
- Parents:
- a2e0687
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
automake/ylwrap
ra2e0687 r59310bf 2 2 # ylwrap - wrapper for lex/yacc invocations. 3 3 4 scriptversion=2011-08-25.18; # UTC 5 6 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 7 # 2007, 2009, 2010, 2011 Free Software Foundation, Inc. 4 scriptversion=2013-01-12.17; # UTC 5 6 # Copyright (C) 1996-2014 Free Software Foundation, Inc. 8 7 # 9 8 # Written by Tom Tromey <tromey@cygnus.com>. … … 31 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 64 case "$1" in 34 65 '') 35 echo "$0: No files given. Try \`$0 --help' for more information." 1>&266 echo "$0: No files given. Try '$0 --help' for more information." 1>&2 36 67 exit 1 37 68 ;; … … 66 97 67 98 # The input. 68 input= "$1"99 input=$1 69 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 105 # Absolute path; do nothing. … … 74 107 *) 75 108 # Relative path. Make it absolute. 76 input="`pwd`/$input" 77 ;; 78 esac 79 80 pairlist= 81 while test "$#" -ne 0; do 82 if test "$1" = "--"; then 109 input=`pwd`/$input 110 ;; 111 esac 112 input_rx=`get_dirname "$input" | quote_for_sed` 113 114 # Since DOS filename conventions don't allow two dots, 115 # the DOS version of Bison writes out y_tab.c instead of y.tab.c 116 # and y_tab.h instead of y.tab.h. Test to see if this is the case. 117 y_tab_nodot=false 118 if test -f y_tab.c || test -f y_tab.h; then 119 y_tab_nodot=true 120 fi 121 122 # The parser itself, the first file, is the destination of the .y.c 123 # rule in the Makefile. 124 parser=$1 125 126 # A sed program to s/FROM/TO/g for all the FROM/TO so that, for 127 # instance, we rename #include "y.tab.h" into #include "parse.h" 128 # during the conversion from y.tab.c to parse.c. 129 sed_fix_filenames= 130 131 # Also rename header guards, as Bison 2.7 for instance uses its header 132 # guard in its implementation file. 133 sed_fix_header_guards= 134 135 while test $# -ne 0; do 136 if test x"$1" = x"--"; then 83 137 shift 84 138 break 85 139 fi 86 pairlist="$pairlist $1" 140 from=$1 141 # Handle y_tab.c and y_tab.h output by DOS 142 if $y_tab_nodot; then 143 case $from in 144 "y.tab.c") from=y_tab.c;; 145 "y.tab.h") from=y_tab.h;; 146 esac 147 fi 87 148 shift 149 to=$1 150 shift 151 sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;" 152 sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;" 88 153 done 89 154 90 155 # The program to run. 91 prog= "$1"156 prog=$1 92 157 shift 93 158 # Make any relative path in $prog absolute. 94 case "$prog"in159 case $prog in 95 160 [\\/]* | ?:[\\/]*) ;; 96 *[\\/]*) prog="`pwd`/$prog" ;; 97 esac 98 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. 161 *[\\/]*) prog=`pwd`/$prog ;; 162 esac 163 101 164 dirname=ylwrap$$ 102 165 do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret' … … 116 179 117 180 if test $ret -eq 0; then 118 set X $pairlist 119 shift 120 first=yes 121 # Since DOS filename conventions don't allow two dots, 122 # the DOS version of Bison writes out y_tab.c instead of y.tab.c 123 # and y_tab.h instead of y.tab.h. Test to see if this is the case. 124 y_tab_nodot="no" 125 if test -f y_tab.c || test -f y_tab.h; then 126 y_tab_nodot="yes" 127 fi 128 129 # The directory holding the input. 130 input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'` 131 # Quote $INPUT_DIR so we can use it in a regexp. 132 # FIXME: really we should care about more than `.' and `\'. 133 input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'` 134 135 while test "$#" -ne 0; do 136 from="$1" 137 # Handle y_tab.c and y_tab.h output by DOS 138 if test $y_tab_nodot = "yes"; then 139 if test $from = "y.tab.c"; then 140 from="y_tab.c" 141 else 142 if test $from = "y.tab.h"; then 143 from="y_tab.h" 144 fi 145 fi 146 fi 181 for from in * 182 do 183 to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"` 147 184 if test -f "$from"; then 148 185 # If $2 is an absolute path name, then just use that, 149 # otherwise prepend `../'.150 case "$2"in151 [\\/]* | ?:[\\/]*) target= "$2";;152 *) target= "../$2";;186 # otherwise prepend '../'. 187 case $to in 188 [\\/]* | ?:[\\/]*) target=$to;; 189 *) target=../$to;; 153 190 esac 154 191 155 # We do not want to overwrite a header file if it hasn't 156 # changed. This avoid useless recompilations. However the 157 # parser itself (the first file) should always be updated, 158 # because it is the destination of the .y.c rule in the 159 # Makefile. Divert the output of all other files to a temporary 160 # file so we can compare them to existing versions. 161 if test $first = no; then 162 realtarget="$target" 163 target="tmp-`echo $target | sed s/.*[\\/]//g`" 192 # Do not overwrite unchanged header files to avoid useless 193 # recompilations. Always update the parser itself: it is the 194 # destination of the .y.c rule in the Makefile. Divert the 195 # output of all other files to a temporary file so we can 196 # compare them to existing versions. 197 if test $from != $parser; then 198 realtarget=$target 199 target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'` 164 200 fi 165 # Edit out `#line' or `#' directives. 166 # 167 # We don't want the resulting debug information to point at 168 # an absolute srcdir; it is better for it to just mention the 169 # .y file with no path. 170 # 171 # We want to use the real output file name, not yy.lex.c for 172 # instance. 173 # 174 # We want the include guards to be adjusted too. 175 FROM=`echo "$from" | sed \ 176 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 177 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 178 TARGET=`echo "$2" | sed \ 179 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 180 -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 181 182 sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \ 183 -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$? 184 185 # Check whether header files must be updated. 186 if test $first = no; then 201 202 # Munge "#line" or "#" directives. Don't let the resulting 203 # debug information point at an absolute srcdir. Use the real 204 # output file name, not yy.lex.c for instance. Adjust the 205 # include guards too. 206 sed -e "/^#/!b" \ 207 -e "s|$input_rx|$input_sub_rx|" \ 208 -e "$sed_fix_filenames" \ 209 -e "$sed_fix_header_guards" \ 210 "$from" >"$target" || ret=$? 211 212 # Check whether files must be updated. 213 if test "$from" != "$parser"; then 187 214 if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then 188 echo "$ 2" is unchanged215 echo "$to is unchanged" 189 216 rm -f "$target" 190 217 else 191 echo updating "$2"218 echo "updating $to" 192 219 mv -f "$target" "$realtarget" 193 220 fi 194 221 fi 195 222 else 196 # A missing file is only an error for the first file. This 197 # is a blatant hack to let us support using "yacc -d". If -d 198 # is not specified, we don't want an error when the header 199 # file is "missing". 200 if test $first = yes; then 223 # A missing file is only an error for the parser. This is a 224 # blatant hack to let us support using "yacc -d". If -d is not 225 # specified, don't fail when the header file is "missing". 226 if test "$from" = "$parser"; then 201 227 ret=1 202 228 fi 203 229 fi 204 shift205 shift206 first=no207 230 done 208 else209 ret=$?210 231 fi 211 232
Note: See TracChangeset
for help on using the changeset viewer.