compile revision 4fb28925
14fb28925Smrg#! /bin/sh
24fb28925Smrg
34fb28925Smrg# Wrapper for compilers which do not understand `-c -o'.
44fb28925Smrg
54fb28925Smrg# Copyright 1999, 2000 Free Software Foundation, Inc.
64fb28925Smrg# Written by Tom Tromey <tromey@cygnus.com>.
74fb28925Smrg#
84fb28925Smrg# This program is free software; you can redistribute it and/or modify
94fb28925Smrg# it under the terms of the GNU General Public License as published by
104fb28925Smrg# the Free Software Foundation; either version 2, or (at your option)
114fb28925Smrg# any later version.
124fb28925Smrg#
134fb28925Smrg# This program is distributed in the hope that it will be useful,
144fb28925Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
154fb28925Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
164fb28925Smrg# GNU General Public License for more details.
174fb28925Smrg#
184fb28925Smrg# You should have received a copy of the GNU General Public License
194fb28925Smrg# along with this program; if not, write to the Free Software
204fb28925Smrg# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
214fb28925Smrg
224fb28925Smrg# As a special exception to the GNU General Public License, if you
234fb28925Smrg# distribute this file as part of a program that contains a
244fb28925Smrg# configuration script generated by Autoconf, you may include it under
254fb28925Smrg# the same distribution terms that you use for the rest of that program.
264fb28925Smrg
274fb28925Smrg# Usage:
284fb28925Smrg# compile PROGRAM [ARGS]...
294fb28925Smrg# `-o FOO.o' is removed from the args passed to the actual compile.
304fb28925Smrg
314fb28925Smrgprog=$1
324fb28925Smrgshift
334fb28925Smrg
344fb28925Smrgofile=
354fb28925Smrgcfile=
364fb28925Smrgargs=
374fb28925Smrgwhile test $# -gt 0; do
384fb28925Smrg   case "$1" in
394fb28925Smrg    -o)
404fb28925Smrg       # configure might choose to run compile as `compile cc -o foo foo.c'.
414fb28925Smrg       # So we do something ugly here.
424fb28925Smrg       ofile=$2
434fb28925Smrg       shift
444fb28925Smrg       case "$ofile" in
454fb28925Smrg	*.o | *.obj)
464fb28925Smrg	   ;;
474fb28925Smrg	*)
484fb28925Smrg	   args="$args -o $ofile"
494fb28925Smrg	   ofile=
504fb28925Smrg	   ;;
514fb28925Smrg       esac
524fb28925Smrg       ;;
534fb28925Smrg    *.c)
544fb28925Smrg       cfile=$1
554fb28925Smrg       args="$args $1"
564fb28925Smrg       ;;
574fb28925Smrg    *)
584fb28925Smrg       args="$args $1"
594fb28925Smrg       ;;
604fb28925Smrg   esac
614fb28925Smrg   shift
624fb28925Smrgdone
634fb28925Smrg
644fb28925Smrgif test -z "$ofile" || test -z "$cfile"; then
654fb28925Smrg   # If no `-o' option was seen then we might have been invoked from a
664fb28925Smrg   # pattern rule where we don't need one.  That is ok -- this is a
674fb28925Smrg   # normal compilation that the losing compiler can handle.  If no
684fb28925Smrg   # `.c' file was seen then we are probably linking.  That is also
694fb28925Smrg   # ok.
704fb28925Smrg   exec "$prog" $args
714fb28925Smrgfi
724fb28925Smrg
734fb28925Smrg# Name of file we expect compiler to create.
744fb28925Smrgcofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
754fb28925Smrg
764fb28925Smrg# Create the lock directory.
774fb28925Smrg# Note: use `[/.-]' here to ensure that we don't use the same name
784fb28925Smrg# that we are using for the .o file.  Also, base the name on the expected
794fb28925Smrg# object file name, since that is what matters with a parallel build.
804fb28925Smrglockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
814fb28925Smrgwhile true; do
824fb28925Smrg   if mkdir $lockdir > /dev/null 2>&1; then
834fb28925Smrg      break
844fb28925Smrg   fi
854fb28925Smrg   sleep 1
864fb28925Smrgdone
874fb28925Smrg# FIXME: race condition here if user kills between mkdir and trap.
884fb28925Smrgtrap "rmdir $lockdir; exit 1" 1 2 15
894fb28925Smrg
904fb28925Smrg# Run the compile.
914fb28925Smrg"$prog" $args
924fb28925Smrgstatus=$?
934fb28925Smrg
944fb28925Smrgif test -f "$cofile"; then
954fb28925Smrg   mv "$cofile" "$ofile"
964fb28925Smrgfi
974fb28925Smrg
984fb28925Smrgrmdir $lockdir
994fb28925Smrgexit $status
100