compile revision 010cdda0
1010cdda0Smrg#! /bin/sh 2010cdda0Smrg 3010cdda0Smrg# Wrapper for compilers which do not understand `-c -o'. 4010cdda0Smrg 5010cdda0Smrg# Copyright 1999, 2000 Free Software Foundation, Inc. 6010cdda0Smrg# Written by Tom Tromey <tromey@cygnus.com>. 7010cdda0Smrg# 8010cdda0Smrg# This program is free software; you can redistribute it and/or modify 9010cdda0Smrg# it under the terms of the GNU General Public License as published by 10010cdda0Smrg# the Free Software Foundation; either version 2, or (at your option) 11010cdda0Smrg# any later version. 12010cdda0Smrg# 13010cdda0Smrg# This program is distributed in the hope that it will be useful, 14010cdda0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 15010cdda0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16010cdda0Smrg# GNU General Public License for more details. 17010cdda0Smrg# 18010cdda0Smrg# You should have received a copy of the GNU General Public License 19010cdda0Smrg# along with this program; if not, write to the Free Software 20010cdda0Smrg# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21010cdda0Smrg 22010cdda0Smrg# As a special exception to the GNU General Public License, if you 23010cdda0Smrg# distribute this file as part of a program that contains a 24010cdda0Smrg# configuration script generated by Autoconf, you may include it under 25010cdda0Smrg# the same distribution terms that you use for the rest of that program. 26010cdda0Smrg 27010cdda0Smrg# Usage: 28010cdda0Smrg# compile PROGRAM [ARGS]... 29010cdda0Smrg# `-o FOO.o' is removed from the args passed to the actual compile. 30010cdda0Smrg 31010cdda0Smrgprog=$1 32010cdda0Smrgshift 33010cdda0Smrg 34010cdda0Smrgofile= 35010cdda0Smrgcfile= 36010cdda0Smrgargs= 37010cdda0Smrgwhile test $# -gt 0; do 38010cdda0Smrg case "$1" in 39010cdda0Smrg -o) 40010cdda0Smrg # configure might choose to run compile as `compile cc -o foo foo.c'. 41010cdda0Smrg # So we do something ugly here. 42010cdda0Smrg ofile=$2 43010cdda0Smrg shift 44010cdda0Smrg case "$ofile" in 45010cdda0Smrg *.o | *.obj) 46010cdda0Smrg ;; 47010cdda0Smrg *) 48010cdda0Smrg args="$args -o $ofile" 49010cdda0Smrg ofile= 50010cdda0Smrg ;; 51010cdda0Smrg esac 52010cdda0Smrg ;; 53010cdda0Smrg *.c) 54010cdda0Smrg cfile=$1 55010cdda0Smrg args="$args $1" 56010cdda0Smrg ;; 57010cdda0Smrg *) 58010cdda0Smrg args="$args $1" 59010cdda0Smrg ;; 60010cdda0Smrg esac 61010cdda0Smrg shift 62010cdda0Smrgdone 63010cdda0Smrg 64010cdda0Smrgif test -z "$ofile" || test -z "$cfile"; then 65010cdda0Smrg # If no `-o' option was seen then we might have been invoked from a 66010cdda0Smrg # pattern rule where we don't need one. That is ok -- this is a 67010cdda0Smrg # normal compilation that the losing compiler can handle. If no 68010cdda0Smrg # `.c' file was seen then we are probably linking. That is also 69010cdda0Smrg # ok. 70010cdda0Smrg exec "$prog" $args 71010cdda0Smrgfi 72010cdda0Smrg 73010cdda0Smrg# Name of file we expect compiler to create. 74010cdda0Smrgcofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'` 75010cdda0Smrg 76010cdda0Smrg# Create the lock directory. 77010cdda0Smrg# Note: use `[/.-]' here to ensure that we don't use the same name 78010cdda0Smrg# that we are using for the .o file. Also, base the name on the expected 79010cdda0Smrg# object file name, since that is what matters with a parallel build. 80010cdda0Smrglockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d 81010cdda0Smrgwhile true; do 82010cdda0Smrg if mkdir $lockdir > /dev/null 2>&1; then 83010cdda0Smrg break 84010cdda0Smrg fi 85010cdda0Smrg sleep 1 86010cdda0Smrgdone 87010cdda0Smrg# FIXME: race condition here if user kills between mkdir and trap. 88010cdda0Smrgtrap "rmdir $lockdir; exit 1" 1 2 15 89010cdda0Smrg 90010cdda0Smrg# Run the compile. 91010cdda0Smrg"$prog" $args 92010cdda0Smrgstatus=$? 93010cdda0Smrg 94010cdda0Smrgif test -f "$cofile"; then 95010cdda0Smrg mv "$cofile" "$ofile" 96010cdda0Smrgfi 97010cdda0Smrg 98010cdda0Smrgrmdir $lockdir 99010cdda0Smrgexit $status 100