joachim99@2: #! /bin/sh joachim99@2: # ylwrap - wrapper for lex/yacc invocations. joachim99@2: # Copyright 1996, 1997, 1998, 1999 Free Software Foundation, Inc. joachim99@2: # Written by Tom Tromey . joachim99@2: # joachim99@2: # This program is free software; you can redistribute it and/or modify joachim99@2: # it under the terms of the GNU General Public License as published by joachim99@2: # the Free Software Foundation; either version 2, or (at your option) joachim99@2: # any later version. joachim99@2: # joachim99@2: # This program is distributed in the hope that it will be useful, joachim99@2: # but WITHOUT ANY WARRANTY; without even the implied warranty of joachim99@2: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the joachim99@2: # GNU General Public License for more details. joachim99@2: # joachim99@2: # You should have received a copy of the GNU General Public License joachim99@2: # along with this program; if not, write to the Free Software joachim99@2: # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. joachim99@2: joachim99@2: # As a special exception to the GNU General Public License, if you joachim99@2: # distribute this file as part of a program that contains a joachim99@2: # configuration script generated by Autoconf, you may include it under joachim99@2: # the same distribution terms that you use for the rest of that program. joachim99@2: joachim99@2: # Usage: joachim99@2: # ylwrap INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]... joachim99@2: # * INPUT is the input file joachim99@2: # * OUTPUT is file PROG generates joachim99@2: # * DESIRED is file we actually want joachim99@2: # * PROGRAM is program to run joachim99@2: # * ARGS are passed to PROG joachim99@2: # Any number of OUTPUT,DESIRED pairs may be used. joachim99@2: joachim99@2: # The input. joachim99@2: input="$1" joachim99@2: shift joachim99@2: case "$input" in joachim99@2: [\\/]* | ?:[\\/]*) joachim99@2: # Absolute path; do nothing. joachim99@2: ;; joachim99@2: *) joachim99@2: # Relative path. Make it absolute. joachim99@2: input="`pwd`/$input" joachim99@2: ;; joachim99@2: esac joachim99@2: joachim99@2: # The directory holding the input. joachim99@2: input_dir=`echo "$input" | sed -e 's,\([\\/]\)[^\\/]*$,\1,'` joachim99@2: # Quote $INPUT_DIR so we can use it in a regexp. joachim99@2: # FIXME: really we should care about more than `.' and `\'. joachim99@2: input_rx=`echo "$input_dir" | sed -e 's,\\\\,\\\\\\\\,g' -e 's,\\.,\\\\.,g'` joachim99@2: joachim99@2: echo "got $input_rx" joachim99@2: joachim99@2: pairlist= joachim99@2: while test "$#" -ne 0; do joachim99@2: if test "$1" = "--"; then joachim99@2: shift joachim99@2: break joachim99@2: fi joachim99@2: pairlist="$pairlist $1" joachim99@2: shift joachim99@2: done joachim99@2: joachim99@2: # The program to run. joachim99@2: prog="$1" joachim99@2: shift joachim99@2: # Make any relative path in $prog absolute. joachim99@2: case "$prog" in joachim99@2: [\\/]* | ?:[\\/]*) ;; joachim99@2: *[\\/]*) prog="`pwd`/$prog" ;; joachim99@2: esac joachim99@2: joachim99@2: # FIXME: add hostname here for parallel makes that run commands on joachim99@2: # other machines. But that might take us over the 14-char limit. joachim99@2: dirname=ylwrap$$ joachim99@2: trap "cd `pwd`; rm -rf $dirname > /dev/null 2>&1" 1 2 3 15 joachim99@2: mkdir $dirname || exit 1 joachim99@2: joachim99@2: cd $dirname joachim99@2: joachim99@2: $prog ${1+"$@"} "$input" joachim99@2: status=$? joachim99@2: joachim99@2: if test $status -eq 0; then joachim99@2: set X $pairlist joachim99@2: shift joachim99@2: first=yes joachim99@2: # Since DOS filename conventions don't allow two dots, joachim99@2: # the DOS version of Bison writes out y_tab.c instead of y.tab.c joachim99@2: # and y_tab.h instead of y.tab.h. Test to see if this is the case. joachim99@2: y_tab_nodot="no" joachim99@2: if test -f y_tab.c || test -f y_tab.h; then joachim99@2: y_tab_nodot="yes" joachim99@2: fi joachim99@2: joachim99@2: while test "$#" -ne 0; do joachim99@2: from="$1" joachim99@2: # Handle y_tab.c and y_tab.h output by DOS joachim99@2: if test $y_tab_nodot = "yes"; then joachim99@2: if test $from = "y.tab.c"; then joachim99@2: from="y_tab.c" joachim99@2: else joachim99@2: if test $from = "y.tab.h"; then joachim99@2: from="y_tab.h" joachim99@2: fi joachim99@2: fi joachim99@2: fi joachim99@2: if test -f "$from"; then joachim99@2: # If $2 is an absolute path name, then just use that, joachim99@2: # otherwise prepend `../'. joachim99@2: case "$2" in joachim99@2: [\\/]* | ?:[\\/]*) target="$2";; joachim99@2: *) target="../$2";; joachim99@2: esac joachim99@2: joachim99@2: # Edit out `#line' or `#' directives. We don't want the joachim99@2: # resulting debug information to point at an absolute srcdir; joachim99@2: # it is better for it to just mention the .y file with no joachim99@2: # path. joachim99@2: sed -e "/^#/ s,$input_rx,," "$from" > "$target" || status=$? joachim99@2: else joachim99@2: # A missing file is only an error for the first file. This joachim99@2: # is a blatant hack to let us support using "yacc -d". If -d joachim99@2: # is not specified, we don't want an error when the header joachim99@2: # file is "missing". joachim99@2: if test $first = yes; then joachim99@2: status=1 joachim99@2: fi joachim99@2: fi joachim99@2: shift joachim99@2: shift joachim99@2: first=no joachim99@2: done joachim99@2: else joachim99@2: status=$? joachim99@2: fi joachim99@2: joachim99@2: # Remove the directory. joachim99@2: cd .. joachim99@2: rm -rf $dirname joachim99@2: joachim99@2: exit $status