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