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