ylwrap revision 350952b9
1350952b9Smrg#! /bin/sh 2350952b9Smrg# ylwrap - wrapper for lex/yacc invocations. 3350952b9Smrg 4350952b9Smrgscriptversion=2009-04-28.21; # UTC 5350952b9Smrg 6350952b9Smrg# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 7350952b9Smrg# 2007, 2009 Free Software Foundation, Inc. 8350952b9Smrg# 9350952b9Smrg# Written by Tom Tromey <tromey@cygnus.com>. 10350952b9Smrg# 11350952b9Smrg# This program is free software; you can redistribute it and/or modify 12350952b9Smrg# it under the terms of the GNU General Public License as published by 13350952b9Smrg# the Free Software Foundation; either version 2, or (at your option) 14350952b9Smrg# any later version. 15350952b9Smrg# 16350952b9Smrg# This program is distributed in the hope that it will be useful, 17350952b9Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 18350952b9Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19350952b9Smrg# GNU General Public License for more details. 20350952b9Smrg# 21350952b9Smrg# You should have received a copy of the GNU General Public License 22350952b9Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 23350952b9Smrg 24350952b9Smrg# As a special exception to the GNU General Public License, if you 25350952b9Smrg# distribute this file as part of a program that contains a 26350952b9Smrg# configuration script generated by Autoconf, you may include it under 27350952b9Smrg# the same distribution terms that you use for the rest of that program. 28350952b9Smrg 29350952b9Smrg# This file is maintained in Automake, please report 30350952b9Smrg# bugs to <bug-automake@gnu.org> or send patches to 31350952b9Smrg# <automake-patches@gnu.org>. 32350952b9Smrg 33350952b9Smrgcase "$1" in 34350952b9Smrg '') 35350952b9Smrg echo "$0: No files given. Try \`$0 --help' for more information." 1>&2 36350952b9Smrg exit 1 37350952b9Smrg ;; 38350952b9Smrg --basedir) 39350952b9Smrg basedir=$2 40350952b9Smrg shift 2 41350952b9Smrg ;; 42350952b9Smrg -h|--h*) 43350952b9Smrg cat <<\EOF 44350952b9SmrgUsage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]... 45350952b9Smrg 46350952b9SmrgWrapper for lex/yacc invocations, renaming files as desired. 47350952b9Smrg 48350952b9Smrg INPUT is the input file 49350952b9Smrg OUTPUT is one file PROG generates 50350952b9Smrg DESIRED is the file we actually want instead of OUTPUT 51350952b9Smrg PROGRAM is program to run 52350952b9Smrg ARGS are passed to PROG 53350952b9Smrg 54350952b9SmrgAny number of OUTPUT,DESIRED pairs may be used. 55350952b9Smrg 56350952b9SmrgReport bugs to <bug-automake@gnu.org>. 57350952b9SmrgEOF 58350952b9Smrg exit $? 59350952b9Smrg ;; 60350952b9Smrg -v|--v*) 61350952b9Smrg echo "ylwrap $scriptversion" 62350952b9Smrg exit $? 63350952b9Smrg ;; 64350952b9Smrgesac 65350952b9Smrg 66350952b9Smrg 67350952b9Smrg# The input. 68350952b9Smrginput="$1" 69350952b9Smrgshift 70350952b9Smrgcase "$input" in 71350952b9Smrg [\\/]* | ?:[\\/]*) 72350952b9Smrg # Absolute path; do nothing. 73350952b9Smrg ;; 74350952b9Smrg *) 75350952b9Smrg # Relative path. Make it absolute. 76350952b9Smrg input="`pwd`/$input" 77350952b9Smrg ;; 78350952b9Smrgesac 79350952b9Smrg 80350952b9Smrgpairlist= 81350952b9Smrgwhile test "$#" -ne 0; do 82350952b9Smrg if test "$1" = "--"; then 83350952b9Smrg shift 84350952b9Smrg break 85350952b9Smrg fi 86350952b9Smrg pairlist="$pairlist $1" 87350952b9Smrg shift 88350952b9Smrgdone 89350952b9Smrg 90350952b9Smrg# The program to run. 91350952b9Smrgprog="$1" 92350952b9Smrgshift 93350952b9Smrg# Make any relative path in $prog absolute. 94350952b9Smrgcase "$prog" in 95350952b9Smrg [\\/]* | ?:[\\/]*) ;; 96350952b9Smrg *[\\/]*) prog="`pwd`/$prog" ;; 97350952b9Smrgesac 98350952b9Smrg 99350952b9Smrg# FIXME: add hostname here for parallel makes that run commands on 100350952b9Smrg# other machines. But that might take us over the 14-char limit. 101350952b9Smrgdirname=ylwrap$$ 102350952b9Smrgtrap "cd '`pwd`'; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 103350952b9Smrgmkdir $dirname || exit 1 104350952b9Smrg 105350952b9Smrgcd $dirname 106350952b9Smrg 107350952b9Smrgcase $# in 108350952b9Smrg 0) "$prog" "$input" ;; 109350952b9Smrg *) "$prog" "$@" "$input" ;; 110350952b9Smrgesac 111350952b9Smrgret=$? 112350952b9Smrg 113350952b9Smrgif test $ret -eq 0; then 114350952b9Smrg set X $pairlist 115350952b9Smrg shift 116350952b9Smrg first=yes 117350952b9Smrg # Since DOS filename conventions don't allow two dots, 118350952b9Smrg # the DOS version of Bison writes out y_tab.c instead of y.tab.c 119350952b9Smrg # and y_tab.h instead of y.tab.h. Test to see if this is the case. 120350952b9Smrg y_tab_nodot="no" 121350952b9Smrg if test -f y_tab.c || test -f y_tab.h; then 122350952b9Smrg y_tab_nodot="yes" 123350952b9Smrg fi 124350952b9Smrg 125350952b9Smrg # The directory holding the input. 126350952b9Smrg input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'` 127350952b9Smrg # Quote $INPUT_DIR so we can use it in a regexp. 128350952b9Smrg # FIXME: really we should care about more than `.' and `\'. 129350952b9Smrg input_rx=`echo "$input_dir" | sed 's,\\\\,\\\\\\\\,g;s,\\.,\\\\.,g'` 130350952b9Smrg 131350952b9Smrg while test "$#" -ne 0; do 132350952b9Smrg from="$1" 133350952b9Smrg # Handle y_tab.c and y_tab.h output by DOS 134350952b9Smrg if test $y_tab_nodot = "yes"; then 135350952b9Smrg if test $from = "y.tab.c"; then 136350952b9Smrg from="y_tab.c" 137350952b9Smrg else 138350952b9Smrg if test $from = "y.tab.h"; then 139350952b9Smrg from="y_tab.h" 140350952b9Smrg fi 141350952b9Smrg fi 142350952b9Smrg fi 143350952b9Smrg if test -f "$from"; then 144350952b9Smrg # If $2 is an absolute path name, then just use that, 145350952b9Smrg # otherwise prepend `../'. 146350952b9Smrg case "$2" in 147350952b9Smrg [\\/]* | ?:[\\/]*) target="$2";; 148350952b9Smrg *) target="../$2";; 149350952b9Smrg esac 150350952b9Smrg 151350952b9Smrg # We do not want to overwrite a header file if it hasn't 152350952b9Smrg # changed. This avoid useless recompilations. However the 153350952b9Smrg # parser itself (the first file) should always be updated, 154350952b9Smrg # because it is the destination of the .y.c rule in the 155350952b9Smrg # Makefile. Divert the output of all other files to a temporary 156350952b9Smrg # file so we can compare them to existing versions. 157350952b9Smrg if test $first = no; then 158350952b9Smrg realtarget="$target" 159350952b9Smrg target="tmp-`echo $target | sed s/.*[\\/]//g`" 160350952b9Smrg fi 161350952b9Smrg # Edit out `#line' or `#' directives. 162350952b9Smrg # 163350952b9Smrg # We don't want the resulting debug information to point at 164350952b9Smrg # an absolute srcdir; it is better for it to just mention the 165350952b9Smrg # .y file with no path. 166350952b9Smrg # 167350952b9Smrg # We want to use the real output file name, not yy.lex.c for 168350952b9Smrg # instance. 169350952b9Smrg # 170350952b9Smrg # We want the include guards to be adjusted too. 171350952b9Smrg FROM=`echo "$from" | sed \ 172350952b9Smrg -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 173350952b9Smrg -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 174350952b9Smrg TARGET=`echo "$2" | sed \ 175350952b9Smrg -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\ 176350952b9Smrg -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'` 177350952b9Smrg 178350952b9Smrg sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \ 179350952b9Smrg -e "s,$FROM,$TARGET," "$from" >"$target" || ret=$? 180350952b9Smrg 181350952b9Smrg # Check whether header files must be updated. 182350952b9Smrg if test $first = no; then 183350952b9Smrg if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then 184350952b9Smrg echo "$2" is unchanged 185350952b9Smrg rm -f "$target" 186350952b9Smrg else 187350952b9Smrg echo updating "$2" 188350952b9Smrg mv -f "$target" "$realtarget" 189350952b9Smrg fi 190350952b9Smrg fi 191350952b9Smrg else 192350952b9Smrg # A missing file is only an error for the first file. This 193350952b9Smrg # is a blatant hack to let us support using "yacc -d". If -d 194350952b9Smrg # is not specified, we don't want an error when the header 195350952b9Smrg # file is "missing". 196350952b9Smrg if test $first = yes; then 197350952b9Smrg ret=1 198350952b9Smrg fi 199350952b9Smrg fi 200350952b9Smrg shift 201350952b9Smrg shift 202350952b9Smrg first=no 203350952b9Smrg done 204350952b9Smrgelse 205350952b9Smrg ret=$? 206350952b9Smrgfi 207350952b9Smrg 208350952b9Smrg# Remove the directory. 209350952b9Smrgcd .. 210350952b9Smrgrm -rf $dirname 211350952b9Smrg 212350952b9Smrgexit $ret 213350952b9Smrg 214350952b9Smrg# Local Variables: 215350952b9Smrg# mode: shell-script 216350952b9Smrg# sh-indentation: 2 217350952b9Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 218350952b9Smrg# time-stamp-start: "scriptversion=" 219350952b9Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 220350952b9Smrg# time-stamp-time-zone: "UTC" 221350952b9Smrg# time-stamp-end: "; # UTC" 222350952b9Smrg# End: 223