ylwrap revision 302408
1139823Simp#! /bin/sh 2133920Sandre# ylwrap - wrapper for lex/yacc invocations. 3133920Sandre# Copyright (C) 1996, 1997 Free Software Foundation, Inc. 4133920Sandre# Written by Tom Tromey <tromey@cygnus.com>. 5133920Sandre# 6133920Sandre# This program is free software; you can redistribute it and/or modify 7133920Sandre# it under the terms of the GNU General Public License as published by 8133920Sandre# the Free Software Foundation; either version 2, or (at your option) 9133920Sandre# any later version. 10133920Sandre# 11133920Sandre# This program is distributed in the hope that it will be useful, 12133920Sandre# but WITHOUT ANY WARRANTY; without even the implied warranty of 13133920Sandre# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14133920Sandre# GNU General Public License for more details. 15133920Sandre# 16133920Sandre# You should have received a copy of the GNU General Public License 17133920Sandre# along with this program; if not, write to the Free Software 18133920Sandre# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19133920Sandre 20133920Sandre# Usage: 21133920Sandre# ylwrap PROGRAM INPUT [OUTPUT DESIRED]... -- [ARGS]... 22133920Sandre# * PROGRAM is program to run. 23133920Sandre# * INPUT is the input file 24133920Sandre# * OUTPUT is file PROG generates 25133920Sandre# * DESIRED is file we actually want 26133920Sandre# * ARGS are passed to PROG 27133920Sandre# Any number of OUTPUT,DESIRED pairs may be used. 28133920Sandre 29134346Sru# The program to run. 30133920Sandreprog="$1" 31133920Sandreshift 32133920Sandre# Make any relative path in $prog absolute. 33133920Sandrecase "$prog" in 34133920Sandre /* | [A-Za-z]:\\*) ;; 35133920Sandre */*) prog="`pwd`/$prog" ;; 36134383Sandreesac 37133920Sandre 38133920Sandre# The input. 39133920Sandreinput="$1" 40133920Sandreshift 41133920Sandrecase "$input" in 42133920Sandre /* | [A-Za-z]:\\*) 43133920Sandre # Absolute path; do nothing. 44133920Sandre ;; 45133920Sandre *) 46133920Sandre # Relative path. Make it absolute. Why? Because otherwise any 47133920Sandre # debugging info in the generated file will point to the wrong 48133920Sandre # place. This is really gross. 49133920Sandre input="`pwd`/$input" 50133920Sandre ;; 51133920Sandreesac 52133920Sandre 53133920Sandre# We don't want to use the absolute path if the input in the current 54133920Sandre# directory like when making a tar ball. 55133920Sandreinput_base=`echo $input | sed -e 's|.*/||'` 56133920Sandreif test -f $input_base && cmp $input_base $input >/dev/null 2>&1; then 57133920Sandre input=$input_base 58133920Sandrefi 59133920Sandre 60133920Sandrepairlist= 61133920Sandrewhile test "$#" -ne 0; do 62141351Sglebius if test "$1" = "--"; then 63141351Sglebius shift 64133920Sandre break 65133920Sandre fi 66133920Sandre pairlist="$pairlist $1" 67133920Sandre shift 68133920Sandredone 69133920Sandre 70133920Sandre# FIXME: add hostname here for parallel makes that run commands on 71136714Sandre# other machines. But that might take us over the 14-char limit. 72136714Sandredirname=ylwrap$$ 73136714Sandretrap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 74141351Sglebiusmkdir $dirname || exit 1 75141351Sglebius 76141351Sglebiuscd $dirname 77136714Sandrecase "$input" in 78136714Sandre /* | [A-Za-z]:\\*) 79133920Sandre # Absolute path; do nothing. 80133920Sandre ;; 81133920Sandre *) 82133920Sandre # Make a symbolic link, hard link or hardcopy. 83135920Smlaier ln -s ../"$input" . > /dev/null 2>&1 || ln ../"$input" . > /dev/null 2>&1 || cp ../"$input" . 84135920Smlaier ;; 85133920Sandreesac 86133920Sandre$prog ${1+"$@"} "$input" 87141351Sglebiusstatus=$? 88133920Sandre 89133920Sandreif test $status -eq 0; then 90133920Sandre set X $pairlist 91140224Sglebius shift 92133920Sandre first=yes 93133920Sandre while test "$#" -ne 0; do 94133920Sandre if test -f "$1"; then 95133920Sandre # If $2 is an absolute path name, then just use that, 96133920Sandre # otherwise prepend `../'. 97133920Sandre case "$2" in 98134022Sandre /* | [A-Za-z]:\\*) target="$2";; 99134022Sandre *) target="../$2";; 100134022Sandre esac 101133920Sandre mv "$1" "$target" || status=$? 102133920Sandre else 103138652Sglebius # A missing file is only an error for the first file. This 104138652Sglebius # is a blatant hack to let us support using "yacc -d". If -d 105133920Sandre # is not specified, we don't want an error when the header 106133920Sandre # file is "missing". 107133920Sandre if test $first = yes; then 108133920Sandre status=1 109133920Sandre fi 110133920Sandre fi 111133920Sandre shift 112133920Sandre shift 113141351Sglebius first=no 114141351Sglebius done 115141351Sglebiuselse 116141351Sglebius status=$? 117141351Sglebiusfi 118141351Sglebius 119141351Sglebius# Remove the directory. 120141351Sglebiuscd .. 121141351Sglebiusrm -rf $dirname 122135154Sandre 123133920Sandreexit $status 124135920Smlaier