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