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