Blame compile

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