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