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