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