Blame compile

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