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