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