Blame compile

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