compile revision 876ff6fe
1876ff6feSmrg#! /bin/sh 2876ff6feSmrg# Wrapper for compilers which do not understand `-c -o'. 3876ff6feSmrg 4876ff6feSmrgscriptversion=2005-05-14.22 5876ff6feSmrg 6876ff6feSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. 7876ff6feSmrg# Written by Tom Tromey <tromey@cygnus.com>. 8876ff6feSmrg# 9876ff6feSmrg# This program is free software; you can redistribute it and/or modify 10876ff6feSmrg# it under the terms of the GNU General Public License as published by 11876ff6feSmrg# the Free Software Foundation; either version 2, or (at your option) 12876ff6feSmrg# any later version. 13876ff6feSmrg# 14876ff6feSmrg# This program is distributed in the hope that it will be useful, 15876ff6feSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16876ff6feSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17876ff6feSmrg# GNU General Public License for more details. 18876ff6feSmrg# 19876ff6feSmrg# You should have received a copy of the GNU General Public License 20876ff6feSmrg# along with this program; if not, write to the Free Software 21876ff6feSmrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 22876ff6feSmrg 23876ff6feSmrg# As a special exception to the GNU General Public License, if you 24876ff6feSmrg# distribute this file as part of a program that contains a 25876ff6feSmrg# configuration script generated by Autoconf, you may include it under 26876ff6feSmrg# the same distribution terms that you use for the rest of that program. 27876ff6feSmrg 28876ff6feSmrg# This file is maintained in Automake, please report 29876ff6feSmrg# bugs to <bug-automake@gnu.org> or send patches to 30876ff6feSmrg# <automake-patches@gnu.org>. 31876ff6feSmrg 32876ff6feSmrgcase $1 in 33876ff6feSmrg '') 34876ff6feSmrg echo "$0: No command. Try \`$0 --help' for more information." 1>&2 35876ff6feSmrg exit 1; 36876ff6feSmrg ;; 37876ff6feSmrg -h | --h*) 38876ff6feSmrg cat <<\EOF 39876ff6feSmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 40876ff6feSmrg 41876ff6feSmrgWrapper for compilers which do not understand `-c -o'. 42876ff6feSmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining 43876ff6feSmrgarguments, and rename the output as expected. 44876ff6feSmrg 45876ff6feSmrgIf you are trying to build a whole package this is not the 46876ff6feSmrgright script to run: please start by reading the file `INSTALL'. 47876ff6feSmrg 48876ff6feSmrgReport bugs to <bug-automake@gnu.org>. 49876ff6feSmrgEOF 50876ff6feSmrg exit $? 51876ff6feSmrg ;; 52876ff6feSmrg -v | --v*) 53876ff6feSmrg echo "compile $scriptversion" 54876ff6feSmrg exit $? 55876ff6feSmrg ;; 56876ff6feSmrgesac 57876ff6feSmrg 58876ff6feSmrgofile= 59876ff6feSmrgcfile= 60876ff6feSmrgeat= 61876ff6feSmrg 62876ff6feSmrgfor arg 63876ff6feSmrgdo 64876ff6feSmrg if test -n "$eat"; then 65876ff6feSmrg eat= 66876ff6feSmrg else 67876ff6feSmrg case $1 in 68876ff6feSmrg -o) 69876ff6feSmrg # configure might choose to run compile as `compile cc -o foo foo.c'. 70876ff6feSmrg # So we strip `-o arg' only if arg is an object. 71876ff6feSmrg eat=1 72876ff6feSmrg case $2 in 73876ff6feSmrg *.o | *.obj) 74876ff6feSmrg ofile=$2 75876ff6feSmrg ;; 76876ff6feSmrg *) 77876ff6feSmrg set x "$@" -o "$2" 78876ff6feSmrg shift 79876ff6feSmrg ;; 80876ff6feSmrg esac 81876ff6feSmrg ;; 82876ff6feSmrg *.c) 83876ff6feSmrg cfile=$1 84876ff6feSmrg set x "$@" "$1" 85876ff6feSmrg shift 86876ff6feSmrg ;; 87876ff6feSmrg *) 88876ff6feSmrg set x "$@" "$1" 89876ff6feSmrg shift 90876ff6feSmrg ;; 91876ff6feSmrg esac 92876ff6feSmrg fi 93876ff6feSmrg shift 94876ff6feSmrgdone 95876ff6feSmrg 96876ff6feSmrgif test -z "$ofile" || test -z "$cfile"; then 97876ff6feSmrg # If no `-o' option was seen then we might have been invoked from a 98876ff6feSmrg # pattern rule where we don't need one. That is ok -- this is a 99876ff6feSmrg # normal compilation that the losing compiler can handle. If no 100876ff6feSmrg # `.c' file was seen then we are probably linking. That is also 101876ff6feSmrg # ok. 102876ff6feSmrg exec "$@" 103876ff6feSmrgfi 104876ff6feSmrg 105876ff6feSmrg# Name of file we expect compiler to create. 106876ff6feSmrgcofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` 107876ff6feSmrg 108876ff6feSmrg# Create the lock directory. 109876ff6feSmrg# Note: use `[/.-]' here to ensure that we don't use the same name 110876ff6feSmrg# that we are using for the .o file. Also, base the name on the expected 111876ff6feSmrg# object file name, since that is what matters with a parallel build. 112876ff6feSmrglockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d 113876ff6feSmrgwhile true; do 114876ff6feSmrg if mkdir "$lockdir" >/dev/null 2>&1; then 115876ff6feSmrg break 116876ff6feSmrg fi 117876ff6feSmrg sleep 1 118876ff6feSmrgdone 119876ff6feSmrg# FIXME: race condition here if user kills between mkdir and trap. 120876ff6feSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 121876ff6feSmrg 122876ff6feSmrg# Run the compile. 123876ff6feSmrg"$@" 124876ff6feSmrgret=$? 125876ff6feSmrg 126876ff6feSmrgif test -f "$cofile"; then 127876ff6feSmrg mv "$cofile" "$ofile" 128876ff6feSmrgelif test -f "${cofile}bj"; then 129876ff6feSmrg mv "${cofile}bj" "$ofile" 130876ff6feSmrgfi 131876ff6feSmrg 132876ff6feSmrgrmdir "$lockdir" 133876ff6feSmrgexit $ret 134876ff6feSmrg 135876ff6feSmrg# Local Variables: 136876ff6feSmrg# mode: shell-script 137876ff6feSmrg# sh-indentation: 2 138876ff6feSmrg# eval: (add-hook 'write-file-hooks 'time-stamp) 139876ff6feSmrg# time-stamp-start: "scriptversion=" 140876ff6feSmrg# time-stamp-format: "%:y-%02m-%02d.%02H" 141876ff6feSmrg# time-stamp-end: "$" 142876ff6feSmrg# End: 143