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