compile revision b1297603
1b1297603Smrg#! /bin/sh 2b1297603Smrg# Wrapper for compilers which do not understand `-c -o'. 3b1297603Smrg 4b1297603Smrgscriptversion=2005-05-14.22 5b1297603Smrg 6b1297603Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. 7b1297603Smrg# Written by Tom Tromey <tromey@cygnus.com>. 8b1297603Smrg# 9b1297603Smrg# This program is free software; you can redistribute it and/or modify 10b1297603Smrg# it under the terms of the GNU General Public License as published by 11b1297603Smrg# the Free Software Foundation; either version 2, or (at your option) 12b1297603Smrg# any later version. 13b1297603Smrg# 14b1297603Smrg# This program is distributed in the hope that it will be useful, 15b1297603Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 16b1297603Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17b1297603Smrg# GNU General Public License for more details. 18b1297603Smrg# 19b1297603Smrg# You should have received a copy of the GNU General Public License 20b1297603Smrg# along with this program; if not, write to the Free Software 21b1297603Smrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 22b1297603Smrg 23b1297603Smrg# As a special exception to the GNU General Public License, if you 24b1297603Smrg# distribute this file as part of a program that contains a 25b1297603Smrg# configuration script generated by Autoconf, you may include it under 26b1297603Smrg# the same distribution terms that you use for the rest of that program. 27b1297603Smrg 28b1297603Smrg# This file is maintained in Automake, please report 29b1297603Smrg# bugs to <bug-automake@gnu.org> or send patches to 30b1297603Smrg# <automake-patches@gnu.org>. 31b1297603Smrg 32b1297603Smrgcase $1 in 33b1297603Smrg '') 34b1297603Smrg echo "$0: No command. Try \`$0 --help' for more information." 1>&2 35b1297603Smrg exit 1; 36b1297603Smrg ;; 37b1297603Smrg -h | --h*) 38b1297603Smrg cat <<\EOF 39b1297603SmrgUsage: compile [--help] [--version] PROGRAM [ARGS] 40b1297603Smrg 41b1297603SmrgWrapper for compilers which do not understand `-c -o'. 42b1297603SmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining 43b1297603Smrgarguments, and rename the output as expected. 44b1297603Smrg 45b1297603SmrgIf you are trying to build a whole package this is not the 46b1297603Smrgright script to run: please start by reading the file `INSTALL'. 47b1297603Smrg 48b1297603SmrgReport bugs to <bug-automake@gnu.org>. 49b1297603SmrgEOF 50b1297603Smrg exit $? 51b1297603Smrg ;; 52b1297603Smrg -v | --v*) 53b1297603Smrg echo "compile $scriptversion" 54b1297603Smrg exit $? 55b1297603Smrg ;; 56b1297603Smrgesac 57b1297603Smrg 58b1297603Smrgofile= 59b1297603Smrgcfile= 60b1297603Smrgeat= 61b1297603Smrg 62b1297603Smrgfor arg 63b1297603Smrgdo 64b1297603Smrg if test -n "$eat"; then 65b1297603Smrg eat= 66b1297603Smrg else 67b1297603Smrg case $1 in 68b1297603Smrg -o) 69b1297603Smrg # configure might choose to run compile as `compile cc -o foo foo.c'. 70b1297603Smrg # So we strip `-o arg' only if arg is an object. 71b1297603Smrg eat=1 72b1297603Smrg case $2 in 73b1297603Smrg *.o | *.obj) 74b1297603Smrg ofile=$2 75b1297603Smrg ;; 76b1297603Smrg *) 77b1297603Smrg set x "$@" -o "$2" 78b1297603Smrg shift 79b1297603Smrg ;; 80b1297603Smrg esac 81b1297603Smrg ;; 82b1297603Smrg *.c) 83b1297603Smrg cfile=$1 84b1297603Smrg set x "$@" "$1" 85b1297603Smrg shift 86b1297603Smrg ;; 87b1297603Smrg *) 88b1297603Smrg set x "$@" "$1" 89b1297603Smrg shift 90b1297603Smrg ;; 91b1297603Smrg esac 92b1297603Smrg fi 93b1297603Smrg shift 94b1297603Smrgdone 95b1297603Smrg 96b1297603Smrgif test -z "$ofile" || test -z "$cfile"; then 97b1297603Smrg # If no `-o' option was seen then we might have been invoked from a 98b1297603Smrg # pattern rule where we don't need one. That is ok -- this is a 99b1297603Smrg # normal compilation that the losing compiler can handle. If no 100b1297603Smrg # `.c' file was seen then we are probably linking. That is also 101b1297603Smrg # ok. 102b1297603Smrg exec "$@" 103b1297603Smrgfi 104b1297603Smrg 105b1297603Smrg# Name of file we expect compiler to create. 106b1297603Smrgcofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` 107b1297603Smrg 108b1297603Smrg# Create the lock directory. 109b1297603Smrg# Note: use `[/.-]' here to ensure that we don't use the same name 110b1297603Smrg# that we are using for the .o file. Also, base the name on the expected 111b1297603Smrg# object file name, since that is what matters with a parallel build. 112b1297603Smrglockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d 113b1297603Smrgwhile true; do 114b1297603Smrg if mkdir "$lockdir" >/dev/null 2>&1; then 115b1297603Smrg break 116b1297603Smrg fi 117b1297603Smrg sleep 1 118b1297603Smrgdone 119b1297603Smrg# FIXME: race condition here if user kills between mkdir and trap. 120b1297603Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15 121b1297603Smrg 122b1297603Smrg# Run the compile. 123b1297603Smrg"$@" 124b1297603Smrgret=$? 125b1297603Smrg 126b1297603Smrgif test -f "$cofile"; then 127b1297603Smrg mv "$cofile" "$ofile" 128b1297603Smrgelif test -f "${cofile}bj"; then 129b1297603Smrg mv "${cofile}bj" "$ofile" 130b1297603Smrgfi 131b1297603Smrg 132b1297603Smrgrmdir "$lockdir" 133b1297603Smrgexit $ret 134b1297603Smrg 135b1297603Smrg# Local Variables: 136b1297603Smrg# mode: shell-script 137b1297603Smrg# sh-indentation: 2 138b1297603Smrg# eval: (add-hook 'write-file-hooks 'time-stamp) 139b1297603Smrg# time-stamp-start: "scriptversion=" 140b1297603Smrg# time-stamp-format: "%:y-%02m-%02d.%02H" 141b1297603Smrg# time-stamp-end: "$" 142b1297603Smrg# End: 143