compile revision 2c7c4e3d
12c7c4e3dSmrg#! /bin/sh
22c7c4e3dSmrg
32c7c4e3dSmrg# Wrapper for compilers which do not understand `-c -o'.
42c7c4e3dSmrg
52c7c4e3dSmrg# Copyright 1999, 2000 Free Software Foundation, Inc.
62c7c4e3dSmrg# Written by Tom Tromey <tromey@cygnus.com>.
72c7c4e3dSmrg#
82c7c4e3dSmrg# This program is free software; you can redistribute it and/or modify
92c7c4e3dSmrg# it under the terms of the GNU General Public License as published by
102c7c4e3dSmrg# the Free Software Foundation; either version 2, or (at your option)
112c7c4e3dSmrg# any later version.
122c7c4e3dSmrg#
132c7c4e3dSmrg# This program is distributed in the hope that it will be useful,
142c7c4e3dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
152c7c4e3dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162c7c4e3dSmrg# GNU General Public License for more details.
172c7c4e3dSmrg#
182c7c4e3dSmrg# You should have received a copy of the GNU General Public License
192c7c4e3dSmrg# along with this program; if not, write to the Free Software
202c7c4e3dSmrg# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
212c7c4e3dSmrg
222c7c4e3dSmrg# As a special exception to the GNU General Public License, if you
232c7c4e3dSmrg# distribute this file as part of a program that contains a
242c7c4e3dSmrg# configuration script generated by Autoconf, you may include it under
252c7c4e3dSmrg# the same distribution terms that you use for the rest of that program.
262c7c4e3dSmrg
272c7c4e3dSmrg# Usage:
282c7c4e3dSmrg# compile PROGRAM [ARGS]...
292c7c4e3dSmrg# `-o FOO.o' is removed from the args passed to the actual compile.
302c7c4e3dSmrg
312c7c4e3dSmrgprog=$1
322c7c4e3dSmrgshift
332c7c4e3dSmrg
342c7c4e3dSmrgofile=
352c7c4e3dSmrgcfile=
362c7c4e3dSmrgargs=
372c7c4e3dSmrgwhile test $# -gt 0; do
382c7c4e3dSmrg   case "$1" in
392c7c4e3dSmrg    -o)
402c7c4e3dSmrg       # configure might choose to run compile as `compile cc -o foo foo.c'.
412c7c4e3dSmrg       # So we do something ugly here.
422c7c4e3dSmrg       ofile=$2
432c7c4e3dSmrg       shift
442c7c4e3dSmrg       case "$ofile" in
452c7c4e3dSmrg	*.o | *.obj)
462c7c4e3dSmrg	   ;;
472c7c4e3dSmrg	*)
482c7c4e3dSmrg	   args="$args -o $ofile"
492c7c4e3dSmrg	   ofile=
502c7c4e3dSmrg	   ;;
512c7c4e3dSmrg       esac
522c7c4e3dSmrg       ;;
532c7c4e3dSmrg    *.c)
542c7c4e3dSmrg       cfile=$1
552c7c4e3dSmrg       args="$args $1"
562c7c4e3dSmrg       ;;
572c7c4e3dSmrg    *)
582c7c4e3dSmrg       args="$args $1"
592c7c4e3dSmrg       ;;
602c7c4e3dSmrg   esac
612c7c4e3dSmrg   shift
622c7c4e3dSmrgdone
632c7c4e3dSmrg
642c7c4e3dSmrgif test -z "$ofile" || test -z "$cfile"; then
652c7c4e3dSmrg   # If no `-o' option was seen then we might have been invoked from a
662c7c4e3dSmrg   # pattern rule where we don't need one.  That is ok -- this is a
672c7c4e3dSmrg   # normal compilation that the losing compiler can handle.  If no
682c7c4e3dSmrg   # `.c' file was seen then we are probably linking.  That is also
692c7c4e3dSmrg   # ok.
702c7c4e3dSmrg   exec "$prog" $args
712c7c4e3dSmrgfi
722c7c4e3dSmrg
732c7c4e3dSmrg# Name of file we expect compiler to create.
742c7c4e3dSmrgcofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
752c7c4e3dSmrg
762c7c4e3dSmrg# Create the lock directory.
772c7c4e3dSmrg# Note: use `[/.-]' here to ensure that we don't use the same name
782c7c4e3dSmrg# that we are using for the .o file.  Also, base the name on the expected
792c7c4e3dSmrg# object file name, since that is what matters with a parallel build.
802c7c4e3dSmrglockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
812c7c4e3dSmrgwhile true; do
822c7c4e3dSmrg   if mkdir $lockdir > /dev/null 2>&1; then
832c7c4e3dSmrg      break
842c7c4e3dSmrg   fi
852c7c4e3dSmrg   sleep 1
862c7c4e3dSmrgdone
872c7c4e3dSmrg# FIXME: race condition here if user kills between mkdir and trap.
882c7c4e3dSmrgtrap "rmdir $lockdir; exit 1" 1 2 15
892c7c4e3dSmrg
902c7c4e3dSmrg# Run the compile.
912c7c4e3dSmrg"$prog" $args
922c7c4e3dSmrgstatus=$?
932c7c4e3dSmrg
942c7c4e3dSmrgif test -f "$cofile"; then
952c7c4e3dSmrg   mv "$cofile" "$ofile"
962c7c4e3dSmrgfi
972c7c4e3dSmrg
982c7c4e3dSmrgrmdir $lockdir
992c7c4e3dSmrgexit $status
100