Blame compile

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