Blame compile

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