compile revision 29459361
129459361Smrg#! /bin/sh
229459361Smrg# Wrapper for compilers which do not understand `-c -o'.
329459361Smrg
429459361Smrgscriptversion=2005-05-14.22
529459361Smrg
629459361Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
729459361Smrg# Written by Tom Tromey <tromey@cygnus.com>.
829459361Smrg#
929459361Smrg# This program is free software; you can redistribute it and/or modify
1029459361Smrg# it under the terms of the GNU General Public License as published by
1129459361Smrg# the Free Software Foundation; either version 2, or (at your option)
1229459361Smrg# any later version.
1329459361Smrg#
1429459361Smrg# This program is distributed in the hope that it will be useful,
1529459361Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1629459361Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1729459361Smrg# GNU General Public License for more details.
1829459361Smrg#
1929459361Smrg# You should have received a copy of the GNU General Public License
2029459361Smrg# along with this program; if not, write to the Free Software
2129459361Smrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2229459361Smrg
2329459361Smrg# As a special exception to the GNU General Public License, if you
2429459361Smrg# distribute this file as part of a program that contains a
2529459361Smrg# configuration script generated by Autoconf, you may include it under
2629459361Smrg# the same distribution terms that you use for the rest of that program.
2729459361Smrg
2829459361Smrg# This file is maintained in Automake, please report
2929459361Smrg# bugs to <bug-automake@gnu.org> or send patches to
3029459361Smrg# <automake-patches@gnu.org>.
3129459361Smrg
3229459361Smrgcase $1 in
3329459361Smrg  '')
3429459361Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
3529459361Smrg     exit 1;
3629459361Smrg     ;;
3729459361Smrg  -h | --h*)
3829459361Smrg    cat <<\EOF
3929459361SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
4029459361Smrg
4129459361SmrgWrapper for compilers which do not understand `-c -o'.
4229459361SmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
4329459361Smrgarguments, and rename the output as expected.
4429459361Smrg
4529459361SmrgIf you are trying to build a whole package this is not the
4629459361Smrgright script to run: please start by reading the file `INSTALL'.
4729459361Smrg
4829459361SmrgReport bugs to <bug-automake@gnu.org>.
4929459361SmrgEOF
5029459361Smrg    exit $?
5129459361Smrg    ;;
5229459361Smrg  -v | --v*)
5329459361Smrg    echo "compile $scriptversion"
5429459361Smrg    exit $?
5529459361Smrg    ;;
5629459361Smrgesac
5729459361Smrg
5829459361Smrgofile=
5929459361Smrgcfile=
6029459361Smrgeat=
6129459361Smrg
6229459361Smrgfor arg
6329459361Smrgdo
6429459361Smrg  if test -n "$eat"; then
6529459361Smrg    eat=
6629459361Smrg  else
6729459361Smrg    case $1 in
6829459361Smrg      -o)
6929459361Smrg	# configure might choose to run compile as `compile cc -o foo foo.c'.
7029459361Smrg	# So we strip `-o arg' only if arg is an object.
7129459361Smrg	eat=1
7229459361Smrg	case $2 in
7329459361Smrg	  *.o | *.obj)
7429459361Smrg	    ofile=$2
7529459361Smrg	    ;;
7629459361Smrg	  *)
7729459361Smrg	    set x "$@" -o "$2"
7829459361Smrg	    shift
7929459361Smrg	    ;;
8029459361Smrg	esac
8129459361Smrg	;;
8229459361Smrg      *.c)
8329459361Smrg	cfile=$1
8429459361Smrg	set x "$@" "$1"
8529459361Smrg	shift
8629459361Smrg	;;
8729459361Smrg      *)
8829459361Smrg	set x "$@" "$1"
8929459361Smrg	shift
9029459361Smrg	;;
9129459361Smrg    esac
9229459361Smrg  fi
9329459361Smrg  shift
9429459361Smrgdone
9529459361Smrg
9629459361Smrgif test -z "$ofile" || test -z "$cfile"; then
9729459361Smrg  # If no `-o' option was seen then we might have been invoked from a
9829459361Smrg  # pattern rule where we don't need one.  That is ok -- this is a
9929459361Smrg  # normal compilation that the losing compiler can handle.  If no
10029459361Smrg  # `.c' file was seen then we are probably linking.  That is also
10129459361Smrg  # ok.
10229459361Smrg  exec "$@"
10329459361Smrgfi
10429459361Smrg
10529459361Smrg# Name of file we expect compiler to create.
10629459361Smrgcofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
10729459361Smrg
10829459361Smrg# Create the lock directory.
10929459361Smrg# Note: use `[/.-]' here to ensure that we don't use the same name
11029459361Smrg# that we are using for the .o file.  Also, base the name on the expected
11129459361Smrg# object file name, since that is what matters with a parallel build.
11229459361Smrglockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
11329459361Smrgwhile true; do
11429459361Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
11529459361Smrg    break
11629459361Smrg  fi
11729459361Smrg  sleep 1
11829459361Smrgdone
11929459361Smrg# FIXME: race condition here if user kills between mkdir and trap.
12029459361Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
12129459361Smrg
12229459361Smrg# Run the compile.
12329459361Smrg"$@"
12429459361Smrgret=$?
12529459361Smrg
12629459361Smrgif test -f "$cofile"; then
12729459361Smrg  mv "$cofile" "$ofile"
12829459361Smrgelif test -f "${cofile}bj"; then
12929459361Smrg  mv "${cofile}bj" "$ofile"
13029459361Smrgfi
13129459361Smrg
13229459361Smrgrmdir "$lockdir"
13329459361Smrgexit $ret
13429459361Smrg
13529459361Smrg# Local Variables:
13629459361Smrg# mode: shell-script
13729459361Smrg# sh-indentation: 2
13829459361Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
13929459361Smrg# time-stamp-start: "scriptversion="
14029459361Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
14129459361Smrg# time-stamp-end: "$"
14229459361Smrg# End:
143