ylwrap revision 60484
138889Sjdp#! /bin/sh 238889Sjdp# ylwrap - wrapper for lex/yacc invocations. 338889Sjdp# Copyright (C) 1996, 1997 Free Software Foundation, Inc. 438889Sjdp# Written by Tom Tromey <tromey@cygnus.com>. 538889Sjdp# 638889Sjdp# This program is free software; you can redistribute it and/or modify 738889Sjdp# it under the terms of the GNU General Public License as published by 838889Sjdp# the Free Software Foundation; either version 2, or (at your option) 938889Sjdp# any later version. 1038889Sjdp# 1138889Sjdp# This program is distributed in the hope that it will be useful, 1238889Sjdp# but WITHOUT ANY WARRANTY; without even the implied warranty of 1338889Sjdp# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1438889Sjdp# GNU General Public License for more details. 1538889Sjdp# 1638889Sjdp# You should have received a copy of the GNU General Public License 1738889Sjdp# along with this program; if not, write to the Free Software 1838889Sjdp# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 1938889Sjdp 2038889Sjdp# Usage: 2138889Sjdp# ylwrap PROGRAM INPUT [OUTPUT DESIRED]... -- [ARGS]... 2238889Sjdp# * PROGRAM is program to run. 2338889Sjdp# * INPUT is the input file 2438889Sjdp# * OUTPUT is file PROG generates 2538889Sjdp# * DESIRED is file we actually want 2638889Sjdp# * ARGS are passed to PROG 2738889Sjdp# Any number of OUTPUT,DESIRED pairs may be used. 2838889Sjdp 2938889Sjdp# The program to run. 3038889Sjdpprog="$1" 3138889Sjdpshift 3238889Sjdp# Make any relative path in $prog absolute. 3338889Sjdpcase "$prog" in 3460484Sobrien /* | [A-Za-z]:\\*) ;; 3538889Sjdp */*) prog="`pwd`/$prog" ;; 3638889Sjdpesac 3738889Sjdp 3838889Sjdp# The input. 3938889Sjdpinput="$1" 4038889Sjdpshift 4138889Sjdpcase "$input" in 4260484Sobrien /* | [A-Za-z]:\\*) 4338889Sjdp # Absolute path; do nothing. 4438889Sjdp ;; 4538889Sjdp *) 4638889Sjdp # Relative path. Make it absolute. Why? Because otherwise any 4738889Sjdp # debugging info in the generated file will point to the wrong 4838889Sjdp # place. This is really gross. 4938889Sjdp input="`pwd`/$input" 5038889Sjdp ;; 5138889Sjdpesac 5238889Sjdp 5360484Sobrien# We don't want to use the absolute path if the input in the current 5460484Sobrien# directory like when making a tar ball. 5560484Sobrieninput_base=`echo $input | sed -e 's|.*/||'` 5660484Sobrienif test -f $input_base && cmp $input_base $input >/dev/null 2>&1; then 5760484Sobrien input=$input_base 5860484Sobrienfi 5960484Sobrien 6038889Sjdppairlist= 6138889Sjdpwhile test "$#" -ne 0; do 6238889Sjdp if test "$1" = "--"; then 6338889Sjdp shift 6438889Sjdp break 6538889Sjdp fi 6638889Sjdp pairlist="$pairlist $1" 6738889Sjdp shift 6838889Sjdpdone 6938889Sjdp 7038889Sjdp# FIXME: add hostname here for parallel makes that run commands on 7138889Sjdp# other machines. But that might take us over the 14-char limit. 7238889Sjdpdirname=ylwrap$$ 7338889Sjdptrap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 7438889Sjdpmkdir $dirname || exit 1 7538889Sjdp 7638889Sjdpcd $dirname 7760484Sobriencase "$input" in 7860484Sobrien /* | [A-Za-z]:\\*) 7960484Sobrien # Absolute path; do nothing. 8060484Sobrien ;; 8160484Sobrien *) 8260484Sobrien # Make a symbolic link, hard link or hardcopy. 8360484Sobrien ln -s ../"$input" . > /dev/null 2>&1 || ln ../"$input" . > /dev/null 2>&1 || cp ../"$input" . 8460484Sobrien ;; 8560484Sobrienesac 8638889Sjdp$prog ${1+"$@"} "$input" 8738889Sjdpstatus=$? 8838889Sjdp 8938889Sjdpif test $status -eq 0; then 9038889Sjdp set X $pairlist 9138889Sjdp shift 9238889Sjdp first=yes 9338889Sjdp while test "$#" -ne 0; do 9438889Sjdp if test -f "$1"; then 9538889Sjdp # If $2 is an absolute path name, then just use that, 9638889Sjdp # otherwise prepend `../'. 9738889Sjdp case "$2" in 9860484Sobrien /* | [A-Za-z]:\\*) target="$2";; 9938889Sjdp *) target="../$2";; 10038889Sjdp esac 10138889Sjdp mv "$1" "$target" || status=$? 10238889Sjdp else 10338889Sjdp # A missing file is only an error for the first file. This 10438889Sjdp # is a blatant hack to let us support using "yacc -d". If -d 10538889Sjdp # is not specified, we don't want an error when the header 10638889Sjdp # file is "missing". 10738889Sjdp if test $first = yes; then 10838889Sjdp status=1 10938889Sjdp fi 11038889Sjdp fi 11138889Sjdp shift 11238889Sjdp shift 11338889Sjdp first=no 11438889Sjdp done 11538889Sjdpelse 11638889Sjdp status=$? 11738889Sjdpfi 11838889Sjdp 11938889Sjdp# Remove the directory. 12038889Sjdpcd .. 12138889Sjdprm -rf $dirname 12238889Sjdp 12338889Sjdpexit $status 124