Blame config/compile

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