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