michael@0: #! /bin/sh michael@0: michael@0: # Wrapper for compilers which do not understand `-c -o'. michael@0: michael@0: # Copyright 1999, 2000 Free Software Foundation, Inc. michael@0: # Written by Tom Tromey . michael@0: # michael@0: # This program is free software; you can redistribute it and/or modify michael@0: # it under the terms of the GNU General Public License as published by michael@0: # the Free Software Foundation; either version 2, or (at your option) michael@0: # any later version. michael@0: # michael@0: # This program is distributed in the hope that it will be useful, michael@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of michael@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the michael@0: # GNU General Public License for more details. michael@0: # michael@0: # You should have received a copy of the GNU General Public License michael@0: # along with this program; if not, write to the Free Software michael@0: # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. michael@0: michael@0: # As a special exception to the GNU General Public License, if you michael@0: # distribute this file as part of a program that contains a michael@0: # configuration script generated by Autoconf, you may include it under michael@0: # the same distribution terms that you use for the rest of that program. michael@0: michael@0: # Usage: michael@0: # compile PROGRAM [ARGS]... michael@0: # `-o FOO.o' is removed from the args passed to the actual compile. michael@0: michael@0: prog=$1 michael@0: shift michael@0: michael@0: ofile= michael@0: cfile= michael@0: args= michael@0: while test $# -gt 0; do michael@0: case "$1" in michael@0: -o) michael@0: # configure might choose to run compile as `compile cc -o foo foo.c'. michael@0: # So we do something ugly here. michael@0: ofile=$2 michael@0: shift michael@0: case "$ofile" in michael@0: *.o | *.obj) michael@0: ;; michael@0: *) michael@0: args="$args -o $ofile" michael@0: ofile= michael@0: ;; michael@0: esac michael@0: ;; michael@0: *.c) michael@0: cfile=$1 michael@0: args="$args $1" michael@0: ;; michael@0: *) michael@0: args="$args $1" michael@0: ;; michael@0: esac michael@0: shift michael@0: done michael@0: michael@0: if test -z "$ofile" || test -z "$cfile"; then michael@0: # If no `-o' option was seen then we might have been invoked from a michael@0: # pattern rule where we don't need one. That is ok -- this is a michael@0: # normal compilation that the losing compiler can handle. If no michael@0: # `.c' file was seen then we are probably linking. That is also michael@0: # ok. michael@0: exec "$prog" $args michael@0: fi michael@0: michael@0: # Name of file we expect compiler to create. michael@0: cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'` michael@0: michael@0: # Create the lock directory. michael@0: # Note: use `[/.-]' here to ensure that we don't use the same name michael@0: # that we are using for the .o file. Also, base the name on the expected michael@0: # object file name, since that is what matters with a parallel build. michael@0: lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d michael@0: while true; do michael@0: if mkdir $lockdir > /dev/null 2>&1; then michael@0: break michael@0: fi michael@0: sleep 1 michael@0: done michael@0: # FIXME: race condition here if user kills between mkdir and trap. michael@0: trap "rmdir $lockdir; exit 1" 1 2 15 michael@0: michael@0: # Run the compile. michael@0: "$prog" $args michael@0: status=$? michael@0: michael@0: if test -f "$cofile"; then michael@0: mv "$cofile" "$ofile" michael@0: fi michael@0: michael@0: rmdir $lockdir michael@0: exit $status