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