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