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