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