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