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