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