joachim99@14: #! /bin/sh joachim99@14: # Wrapper for compilers which do not understand `-c -o'. joachim99@14: joachim99@69: scriptversion=2005-05-14.22 joachim99@69: joachim99@69: # Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. joachim99@14: # Written by Tom Tromey . joachim99@14: # joachim99@14: # This program is free software; you can redistribute it and/or modify joachim99@14: # it under the terms of the GNU General Public License as published by joachim99@14: # the Free Software Foundation; either version 2, or (at your option) joachim99@14: # any later version. joachim99@14: # joachim99@14: # This program is distributed in the hope that it will be useful, joachim99@14: # but WITHOUT ANY WARRANTY; without even the implied warranty of joachim99@14: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the joachim99@14: # GNU General Public License for more details. joachim99@14: # joachim99@14: # You should have received a copy of the GNU General Public License joachim99@14: # along with this program; if not, write to the Free Software joachim99@69: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. joachim99@14: joachim99@14: # As a special exception to the GNU General Public License, if you joachim99@14: # distribute this file as part of a program that contains a joachim99@14: # configuration script generated by Autoconf, you may include it under joachim99@14: # the same distribution terms that you use for the rest of that program. joachim99@14: joachim99@69: # This file is maintained in Automake, please report joachim99@69: # bugs to or send patches to joachim99@69: # . joachim99@14: joachim99@69: case $1 in joachim99@69: '') joachim99@69: echo "$0: No command. Try \`$0 --help' for more information." 1>&2 joachim99@69: exit 1; joachim99@69: ;; joachim99@69: -h | --h*) joachim99@69: cat <<\EOF joachim99@69: Usage: compile [--help] [--version] PROGRAM [ARGS] joachim99@69: joachim99@69: Wrapper for compilers which do not understand `-c -o'. joachim99@69: Remove `-o dest.o' from ARGS, run PROGRAM with the remaining joachim99@69: arguments, and rename the output as expected. joachim99@69: joachim99@69: If you are trying to build a whole package this is not the joachim99@69: right script to run: please start by reading the file `INSTALL'. joachim99@69: joachim99@69: Report bugs to . joachim99@69: EOF joachim99@69: exit $? joachim99@69: ;; joachim99@69: -v | --v*) joachim99@69: echo "compile $scriptversion" joachim99@69: exit $? joachim99@69: ;; joachim99@69: esac joachim99@14: joachim99@14: ofile= joachim99@14: cfile= joachim99@69: eat= joachim99@69: joachim99@69: for arg joachim99@69: do joachim99@69: if test -n "$eat"; then joachim99@69: eat= joachim99@69: else joachim99@69: case $1 in joachim99@69: -o) joachim99@69: # configure might choose to run compile as `compile cc -o foo foo.c'. joachim99@69: # So we strip `-o arg' only if arg is an object. joachim99@69: eat=1 joachim99@69: case $2 in joachim99@69: *.o | *.obj) joachim99@69: ofile=$2 joachim99@69: ;; joachim99@69: *) joachim99@69: set x "$@" -o "$2" joachim99@69: shift joachim99@69: ;; joachim99@69: esac joachim99@69: ;; joachim99@69: *.c) joachim99@69: cfile=$1 joachim99@69: set x "$@" "$1" joachim99@69: shift joachim99@69: ;; joachim99@69: *) joachim99@69: set x "$@" "$1" joachim99@69: shift joachim99@69: ;; joachim99@69: esac joachim99@69: fi joachim99@69: shift joachim99@14: done joachim99@14: joachim99@14: if test -z "$ofile" || test -z "$cfile"; then joachim99@69: # If no `-o' option was seen then we might have been invoked from a joachim99@69: # pattern rule where we don't need one. That is ok -- this is a joachim99@69: # normal compilation that the losing compiler can handle. If no joachim99@69: # `.c' file was seen then we are probably linking. That is also joachim99@69: # ok. joachim99@69: exec "$@" joachim99@14: fi joachim99@14: joachim99@14: # Name of file we expect compiler to create. joachim99@69: cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'` joachim99@14: joachim99@14: # Create the lock directory. joachim99@14: # Note: use `[/.-]' here to ensure that we don't use the same name joachim99@14: # that we are using for the .o file. Also, base the name on the expected joachim99@14: # object file name, since that is what matters with a parallel build. joachim99@69: lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d joachim99@14: while true; do joachim99@69: if mkdir "$lockdir" >/dev/null 2>&1; then joachim99@69: break joachim99@69: fi joachim99@69: sleep 1 joachim99@14: done joachim99@14: # FIXME: race condition here if user kills between mkdir and trap. joachim99@69: trap "rmdir '$lockdir'; exit 1" 1 2 15 joachim99@14: joachim99@14: # Run the compile. joachim99@69: "$@" joachim99@69: ret=$? joachim99@14: joachim99@14: if test -f "$cofile"; then joachim99@69: mv "$cofile" "$ofile" joachim99@69: elif test -f "${cofile}bj"; then joachim99@69: mv "${cofile}bj" "$ofile" joachim99@14: fi joachim99@14: joachim99@69: rmdir "$lockdir" joachim99@69: exit $ret joachim99@69: joachim99@69: # Local Variables: joachim99@69: # mode: shell-script joachim99@69: # sh-indentation: 2 joachim99@69: # eval: (add-hook 'write-file-hooks 'time-stamp) joachim99@69: # time-stamp-start: "scriptversion=" joachim99@69: # time-stamp-format: "%:y-%02m-%02d.%02H" joachim99@69: # time-stamp-end: "$" joachim99@69: # End: