1186690Sobrien#! /bin/sh 2186690Sobrien# Wrapper for compilers which do not understand `-c -o'. 3186690Sobrien 4234449Sobrienscriptversion=2009-10-06.20; # UTC 5186690Sobrien 6234449Sobrien# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009 Free Software 7234449Sobrien# Foundation, Inc. 8186690Sobrien# Written by Tom Tromey <tromey@cygnus.com>. 9186690Sobrien# 10186690Sobrien# This program is free software; you can redistribute it and/or modify 11186690Sobrien# it under the terms of the GNU General Public License as published by 12186690Sobrien# the Free Software Foundation; either version 2, or (at your option) 13186690Sobrien# any later version. 14186690Sobrien# 15186690Sobrien# This program is distributed in the hope that it will be useful, 16186690Sobrien# but WITHOUT ANY WARRANTY; without even the implied warranty of 17186690Sobrien# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18186690Sobrien# GNU General Public License for more details. 19186690Sobrien# 20186690Sobrien# You should have received a copy of the GNU General Public License 21234449Sobrien# along with this program. If not, see <http://www.gnu.org/licenses/>. 22186690Sobrien 23186690Sobrien# As a special exception to the GNU General Public License, if you 24186690Sobrien# distribute this file as part of a program that contains a 25186690Sobrien# configuration script generated by Autoconf, you may include it under 26186690Sobrien# the same distribution terms that you use for the rest of that program. 27186690Sobrien 28186690Sobrien# This file is maintained in Automake, please report 29186690Sobrien# bugs to <bug-automake@gnu.org> or send patches to 30186690Sobrien# <automake-patches@gnu.org>. 31186690Sobrien 32186690Sobriencase $1 in 33186690Sobrien '') 34186690Sobrien echo "$0: No command. Try \`$0 --help' for more information." 1>&2 35186690Sobrien exit 1; 36186690Sobrien ;; 37186690Sobrien -h | --h*) 38186690Sobrien cat <<\EOF 39186690SobrienUsage: compile [--help] [--version] PROGRAM [ARGS] 40186690Sobrien 41186690SobrienWrapper for compilers which do not understand `-c -o'. 42186690SobrienRemove `-o dest.o' from ARGS, run PROGRAM with the remaining 43186690Sobrienarguments, and rename the output as expected. 44186690Sobrien 45186690SobrienIf you are trying to build a whole package this is not the 46186690Sobrienright script to run: please start by reading the file `INSTALL'. 47186690Sobrien 48186690SobrienReport bugs to <bug-automake@gnu.org>. 49186690SobrienEOF 50186690Sobrien exit $? 51186690Sobrien ;; 52186690Sobrien -v | --v*) 53186690Sobrien echo "compile $scriptversion" 54186690Sobrien exit $? 55186690Sobrien ;; 56186690Sobrienesac 57186690Sobrien 58186690Sobrienofile= 59186690Sobriencfile= 60186690Sobrieneat= 61186690Sobrien 62186690Sobrienfor arg 63186690Sobriendo 64186690Sobrien if test -n "$eat"; then 65186690Sobrien eat= 66186690Sobrien else 67186690Sobrien case $1 in 68186690Sobrien -o) 69186690Sobrien # configure might choose to run compile as `compile cc -o foo foo.c'. 70186690Sobrien # So we strip `-o arg' only if arg is an object. 71186690Sobrien eat=1 72186690Sobrien case $2 in 73186690Sobrien *.o | *.obj) 74186690Sobrien ofile=$2 75186690Sobrien ;; 76186690Sobrien *) 77186690Sobrien set x "$@" -o "$2" 78186690Sobrien shift 79186690Sobrien ;; 80186690Sobrien esac 81186690Sobrien ;; 82186690Sobrien *.c) 83186690Sobrien cfile=$1 84186690Sobrien set x "$@" "$1" 85186690Sobrien shift 86186690Sobrien ;; 87186690Sobrien *) 88186690Sobrien set x "$@" "$1" 89186690Sobrien shift 90186690Sobrien ;; 91186690Sobrien esac 92186690Sobrien fi 93186690Sobrien shift 94186690Sobriendone 95186690Sobrien 96186690Sobrienif test -z "$ofile" || test -z "$cfile"; then 97186690Sobrien # If no `-o' option was seen then we might have been invoked from a 98186690Sobrien # pattern rule where we don't need one. That is ok -- this is a 99186690Sobrien # normal compilation that the losing compiler can handle. If no 100186690Sobrien # `.c' file was seen then we are probably linking. That is also 101186690Sobrien # ok. 102186690Sobrien exec "$@" 103186690Sobrienfi 104186690Sobrien 105186690Sobrien# Name of file we expect compiler to create. 106234449Sobriencofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 107186690Sobrien 108186690Sobrien# Create the lock directory. 109234449Sobrien# Note: use `[/\\:.-]' here to ensure that we don't use the same name 110186690Sobrien# that we are using for the .o file. Also, base the name on the expected 111186690Sobrien# object file name, since that is what matters with a parallel build. 112234449Sobrienlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 113186690Sobrienwhile true; do 114186690Sobrien if mkdir "$lockdir" >/dev/null 2>&1; then 115186690Sobrien break 116186690Sobrien fi 117186690Sobrien sleep 1 118186690Sobriendone 119186690Sobrien# FIXME: race condition here if user kills between mkdir and trap. 120186690Sobrientrap "rmdir '$lockdir'; exit 1" 1 2 15 121186690Sobrien 122186690Sobrien# Run the compile. 123186690Sobrien"$@" 124186690Sobrienret=$? 125186690Sobrien 126186690Sobrienif test -f "$cofile"; then 127234449Sobrien test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 128186690Sobrienelif test -f "${cofile}bj"; then 129234449Sobrien test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 130186690Sobrienfi 131186690Sobrien 132186690Sobrienrmdir "$lockdir" 133186690Sobrienexit $ret 134186690Sobrien 135186690Sobrien# Local Variables: 136186690Sobrien# mode: shell-script 137186690Sobrien# sh-indentation: 2 138186690Sobrien# eval: (add-hook 'write-file-hooks 'time-stamp) 139186690Sobrien# time-stamp-start: "scriptversion=" 140186690Sobrien# time-stamp-format: "%:y-%02m-%02d.%02H" 141234449Sobrien# time-stamp-time-zone: "UTC" 142234449Sobrien# time-stamp-end: "; # UTC" 143186690Sobrien# End: 144