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