1311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff#! /bin/sh 2311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 3311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# Wrapper for compilers which do not understand `-c -o'. 4311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 5311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# Copyright 1999, 2000 Free Software Foundation, Inc. 6311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# Written by Tom Tromey <tromey@cygnus.com>. 7311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# 8311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# This program is free software; you can redistribute it and/or modify 9311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# it under the terms of the GNU General Public License as published by 10311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# the Free Software Foundation; either version 2, or (at your option) 11311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# any later version. 12311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# 13311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# This program is distributed in the hope that it will be useful, 14311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# but WITHOUT ANY WARRANTY; without even the implied warranty of 15311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# GNU General Public License for more details. 17311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# 18311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# You should have received a copy of the GNU General Public License 19311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# along with this program; if not, write to the Free Software 20311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 22311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# As a special exception to the GNU General Public License, if you 23311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# distribute this file as part of a program that contains a 24311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# configuration script generated by Autoconf, you may include it under 25311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# the same distribution terms that you use for the rest of that program. 26311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 27311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# Usage: 28311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# compile PROGRAM [ARGS]... 29311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# `-o FOO.o' is removed from the args passed to the actual compile. 30311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 31311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffprog=$1 32311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffshift 33311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 34311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffofile= 35311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffcfile= 36311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffargs= 37311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffwhile test $# -gt 0; do 38311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff case "$1" in 39311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff -o) 40311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff # configure might choose to run compile as `compile cc -o foo foo.c'. 41311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff # So we do something ugly here. 42311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff ofile=$2 43311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff shift 44311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff case "$ofile" in 45311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff *.o | *.obj) 46311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff ;; 47311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff *) 48311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff args="$args -o $ofile" 49311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff ofile= 50311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff ;; 51311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff esac 52311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff ;; 53311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff *.c) 54311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff cfile=$1 55311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff args="$args $1" 56311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff ;; 57311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff *) 58311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff args="$args $1" 59311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff ;; 60311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff esac 61311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff shift 62311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffdone 63311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 64311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffif test -z "$ofile" || test -z "$cfile"; then 65311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff # If no `-o' option was seen then we might have been invoked from a 66311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff # pattern rule where we don't need one. That is ok -- this is a 67311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff # normal compilation that the losing compiler can handle. If no 68311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff # `.c' file was seen then we are probably linking. That is also 69311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff # ok. 70311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff exec "$prog" $args 71311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdifffi 72311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 73311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# Name of file we expect compiler to create. 74311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffcofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'` 75311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 76311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# Create the lock directory. 77311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# Note: use `[/.-]' here to ensure that we don't use the same name 78311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# that we are using for the .o file. Also, base the name on the expected 79311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# object file name, since that is what matters with a parallel build. 80311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdifflockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d 81311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffwhile true; do 82311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff if mkdir $lockdir > /dev/null 2>&1; then 83311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff break 84311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff fi 85311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff sleep 1 86311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffdone 87311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# FIXME: race condition here if user kills between mkdir and trap. 88311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdifftrap "rmdir $lockdir; exit 1" 1 2 15 89311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 90311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff# Run the compile. 91311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff"$prog" $args 92311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffstatus=$? 93311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 94311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffif test -f "$cofile"; then 95311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff mv "$cofile" "$ofile" 96311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdifffi 97311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiff 98311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffrmdir $lockdir 99311c71486f5f6074e5ba62a7f4c5397c8700b868openvcdiffexit $status 100