compile revision 14c0a534
114c0a534Smrg#! /bin/sh
214c0a534Smrg# Wrapper for compilers which do not understand `-c -o'.
314c0a534Smrg
414c0a534Smrgscriptversion=2005-05-14.22
514c0a534Smrg
614c0a534Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
714c0a534Smrg# Written by Tom Tromey <tromey@cygnus.com>.
814c0a534Smrg#
914c0a534Smrg# This program is free software; you can redistribute it and/or modify
1014c0a534Smrg# it under the terms of the GNU General Public License as published by
1114c0a534Smrg# the Free Software Foundation; either version 2, or (at your option)
1214c0a534Smrg# any later version.
1314c0a534Smrg#
1414c0a534Smrg# This program is distributed in the hope that it will be useful,
1514c0a534Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1614c0a534Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1714c0a534Smrg# GNU General Public License for more details.
1814c0a534Smrg#
1914c0a534Smrg# You should have received a copy of the GNU General Public License
2014c0a534Smrg# along with this program; if not, write to the Free Software
2114c0a534Smrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2214c0a534Smrg
2314c0a534Smrg# As a special exception to the GNU General Public License, if you
2414c0a534Smrg# distribute this file as part of a program that contains a
2514c0a534Smrg# configuration script generated by Autoconf, you may include it under
2614c0a534Smrg# the same distribution terms that you use for the rest of that program.
2714c0a534Smrg
2814c0a534Smrg# This file is maintained in Automake, please report
2914c0a534Smrg# bugs to <bug-automake@gnu.org> or send patches to
3014c0a534Smrg# <automake-patches@gnu.org>.
3114c0a534Smrg
3214c0a534Smrgcase $1 in
3314c0a534Smrg  '')
3414c0a534Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
3514c0a534Smrg     exit 1;
3614c0a534Smrg     ;;
3714c0a534Smrg  -h | --h*)
3814c0a534Smrg    cat <<\EOF
3914c0a534SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
4014c0a534Smrg
4114c0a534SmrgWrapper for compilers which do not understand `-c -o'.
4214c0a534SmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
4314c0a534Smrgarguments, and rename the output as expected.
4414c0a534Smrg
4514c0a534SmrgIf you are trying to build a whole package this is not the
4614c0a534Smrgright script to run: please start by reading the file `INSTALL'.
4714c0a534Smrg
4814c0a534SmrgReport bugs to <bug-automake@gnu.org>.
4914c0a534SmrgEOF
5014c0a534Smrg    exit $?
5114c0a534Smrg    ;;
5214c0a534Smrg  -v | --v*)
5314c0a534Smrg    echo "compile $scriptversion"
5414c0a534Smrg    exit $?
5514c0a534Smrg    ;;
5614c0a534Smrgesac
5714c0a534Smrg
5814c0a534Smrgofile=
5914c0a534Smrgcfile=
6014c0a534Smrgeat=
6114c0a534Smrg
6214c0a534Smrgfor arg
6314c0a534Smrgdo
6414c0a534Smrg  if test -n "$eat"; then
6514c0a534Smrg    eat=
6614c0a534Smrg  else
6714c0a534Smrg    case $1 in
6814c0a534Smrg      -o)
6914c0a534Smrg	# configure might choose to run compile as `compile cc -o foo foo.c'.
7014c0a534Smrg	# So we strip `-o arg' only if arg is an object.
7114c0a534Smrg	eat=1
7214c0a534Smrg	case $2 in
7314c0a534Smrg	  *.o | *.obj)
7414c0a534Smrg	    ofile=$2
7514c0a534Smrg	    ;;
7614c0a534Smrg	  *)
7714c0a534Smrg	    set x "$@" -o "$2"
7814c0a534Smrg	    shift
7914c0a534Smrg	    ;;
8014c0a534Smrg	esac
8114c0a534Smrg	;;
8214c0a534Smrg      *.c)
8314c0a534Smrg	cfile=$1
8414c0a534Smrg	set x "$@" "$1"
8514c0a534Smrg	shift
8614c0a534Smrg	;;
8714c0a534Smrg      *)
8814c0a534Smrg	set x "$@" "$1"
8914c0a534Smrg	shift
9014c0a534Smrg	;;
9114c0a534Smrg    esac
9214c0a534Smrg  fi
9314c0a534Smrg  shift
9414c0a534Smrgdone
9514c0a534Smrg
9614c0a534Smrgif test -z "$ofile" || test -z "$cfile"; then
9714c0a534Smrg  # If no `-o' option was seen then we might have been invoked from a
9814c0a534Smrg  # pattern rule where we don't need one.  That is ok -- this is a
9914c0a534Smrg  # normal compilation that the losing compiler can handle.  If no
10014c0a534Smrg  # `.c' file was seen then we are probably linking.  That is also
10114c0a534Smrg  # ok.
10214c0a534Smrg  exec "$@"
10314c0a534Smrgfi
10414c0a534Smrg
10514c0a534Smrg# Name of file we expect compiler to create.
10614c0a534Smrgcofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
10714c0a534Smrg
10814c0a534Smrg# Create the lock directory.
10914c0a534Smrg# Note: use `[/.-]' here to ensure that we don't use the same name
11014c0a534Smrg# that we are using for the .o file.  Also, base the name on the expected
11114c0a534Smrg# object file name, since that is what matters with a parallel build.
11214c0a534Smrglockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
11314c0a534Smrgwhile true; do
11414c0a534Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
11514c0a534Smrg    break
11614c0a534Smrg  fi
11714c0a534Smrg  sleep 1
11814c0a534Smrgdone
11914c0a534Smrg# FIXME: race condition here if user kills between mkdir and trap.
12014c0a534Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
12114c0a534Smrg
12214c0a534Smrg# Run the compile.
12314c0a534Smrg"$@"
12414c0a534Smrgret=$?
12514c0a534Smrg
12614c0a534Smrgif test -f "$cofile"; then
12714c0a534Smrg  mv "$cofile" "$ofile"
12814c0a534Smrgelif test -f "${cofile}bj"; then
12914c0a534Smrg  mv "${cofile}bj" "$ofile"
13014c0a534Smrgfi
13114c0a534Smrg
13214c0a534Smrgrmdir "$lockdir"
13314c0a534Smrgexit $ret
13414c0a534Smrg
13514c0a534Smrg# Local Variables:
13614c0a534Smrg# mode: shell-script
13714c0a534Smrg# sh-indentation: 2
13814c0a534Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
13914c0a534Smrg# time-stamp-start: "scriptversion="
14014c0a534Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
14114c0a534Smrg# time-stamp-end: "$"
14214c0a534Smrg# End:
143