Blame compile

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