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