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