compile revision 31de2854
1f80a6dcdSmrg#! /bin/sh
2f80a6dcdSmrg
3f80a6dcdSmrg# Wrapper for compilers which do not understand `-c -o'.
4f80a6dcdSmrg
5f80a6dcdSmrg# Copyright 1999, 2000 Free Software Foundation, Inc.
6f80a6dcdSmrg# Written by Tom Tromey <tromey@cygnus.com>.
7f80a6dcdSmrg#
8f80a6dcdSmrg# This program is free software; you can redistribute it and/or modify
9f80a6dcdSmrg# it under the terms of the GNU General Public License as published by
10f80a6dcdSmrg# the Free Software Foundation; either version 2, or (at your option)
11f80a6dcdSmrg# any later version.
12f80a6dcdSmrg#
13f80a6dcdSmrg# This program is distributed in the hope that it will be useful,
14f80a6dcdSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
15f80a6dcdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16f80a6dcdSmrg# GNU General Public License for more details.
17f80a6dcdSmrg#
18f80a6dcdSmrg# You should have received a copy of the GNU General Public License
19f80a6dcdSmrg# along with this program; if not, write to the Free Software
20f80a6dcdSmrg# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21f80a6dcdSmrg
22f80a6dcdSmrg# As a special exception to the GNU General Public License, if you
23f80a6dcdSmrg# distribute this file as part of a program that contains a
24f80a6dcdSmrg# configuration script generated by Autoconf, you may include it under
25f80a6dcdSmrg# the same distribution terms that you use for the rest of that program.
26f80a6dcdSmrg
27f80a6dcdSmrg# Usage:
28f80a6dcdSmrg# compile PROGRAM [ARGS]...
29f80a6dcdSmrg# `-o FOO.o' is removed from the args passed to the actual compile.
30f80a6dcdSmrg
31f80a6dcdSmrgprog=$1
32f80a6dcdSmrgshift
33f80a6dcdSmrg
34f80a6dcdSmrgofile=
35f80a6dcdSmrgcfile=
36f80a6dcdSmrgargs=
37f80a6dcdSmrgwhile test $# -gt 0; do
38f80a6dcdSmrg   case "$1" in
39f80a6dcdSmrg    -o)
40f80a6dcdSmrg       # configure might choose to run compile as `compile cc -o foo foo.c'.
41f80a6dcdSmrg       # So we do something ugly here.
42f80a6dcdSmrg       ofile=$2
43f80a6dcdSmrg       shift
44f80a6dcdSmrg       case "$ofile" in
45f80a6dcdSmrg	*.o | *.obj)
46f80a6dcdSmrg	   ;;
47f80a6dcdSmrg	*)
48f80a6dcdSmrg	   args="$args -o $ofile"
49f80a6dcdSmrg	   ofile=
50f80a6dcdSmrg	   ;;
51f80a6dcdSmrg       esac
52f80a6dcdSmrg       ;;
53f80a6dcdSmrg    *.c)
54f80a6dcdSmrg       cfile=$1
55f80a6dcdSmrg       args="$args $1"
56f80a6dcdSmrg       ;;
57f80a6dcdSmrg    *)
58f80a6dcdSmrg       args="$args $1"
59f80a6dcdSmrg       ;;
60f80a6dcdSmrg   esac
61f80a6dcdSmrg   shift
62f80a6dcdSmrgdone
63f80a6dcdSmrg
64f80a6dcdSmrgif test -z "$ofile" || test -z "$cfile"; then
65f80a6dcdSmrg   # If no `-o' option was seen then we might have been invoked from a
66f80a6dcdSmrg   # pattern rule where we don't need one.  That is ok -- this is a
67f80a6dcdSmrg   # normal compilation that the losing compiler can handle.  If no
68f80a6dcdSmrg   # `.c' file was seen then we are probably linking.  That is also
69f80a6dcdSmrg   # ok.
70f80a6dcdSmrg   exec "$prog" $args
71f80a6dcdSmrgfi
72f80a6dcdSmrg
73f80a6dcdSmrg# Name of file we expect compiler to create.
74f80a6dcdSmrgcofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
75f80a6dcdSmrg
76f80a6dcdSmrg# Create the lock directory.
77f80a6dcdSmrg# Note: use `[/.-]' here to ensure that we don't use the same name
78f80a6dcdSmrg# that we are using for the .o file.  Also, base the name on the expected
79f80a6dcdSmrg# object file name, since that is what matters with a parallel build.
80f80a6dcdSmrglockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
81f80a6dcdSmrgwhile true; do
82f80a6dcdSmrg   if mkdir $lockdir > /dev/null 2>&1; then
83f80a6dcdSmrg      break
84f80a6dcdSmrg   fi
85f80a6dcdSmrg   sleep 1
86f80a6dcdSmrgdone
87f80a6dcdSmrg# FIXME: race condition here if user kills between mkdir and trap.
88f80a6dcdSmrgtrap "rmdir $lockdir; exit 1" 1 2 15
89f80a6dcdSmrg
90f80a6dcdSmrg# Run the compile.
91f80a6dcdSmrg"$prog" $args
92f80a6dcdSmrgstatus=$?
93f80a6dcdSmrg
94f80a6dcdSmrgif test -f "$cofile"; then
95f80a6dcdSmrg   mv "$cofile" "$ofile"
96f80a6dcdSmrgfi
97f80a6dcdSmrg
98f80a6dcdSmrgrmdir $lockdir
99f80a6dcdSmrgexit $status
100