compile revision 33c89af1
133c89af1Smrg#! /bin/sh
233c89af1Smrg# Wrapper for compilers which do not understand `-c -o'.
333c89af1Smrg
433c89af1Smrgscriptversion=2005-05-14.22
533c89af1Smrg
633c89af1Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
733c89af1Smrg# Written by Tom Tromey <tromey@cygnus.com>.
833c89af1Smrg#
933c89af1Smrg# This program is free software; you can redistribute it and/or modify
1033c89af1Smrg# it under the terms of the GNU General Public License as published by
1133c89af1Smrg# the Free Software Foundation; either version 2, or (at your option)
1233c89af1Smrg# any later version.
1333c89af1Smrg#
1433c89af1Smrg# This program is distributed in the hope that it will be useful,
1533c89af1Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1633c89af1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1733c89af1Smrg# GNU General Public License for more details.
1833c89af1Smrg#
1933c89af1Smrg# You should have received a copy of the GNU General Public License
2033c89af1Smrg# along with this program; if not, write to the Free Software
2133c89af1Smrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2233c89af1Smrg
2333c89af1Smrg# As a special exception to the GNU General Public License, if you
2433c89af1Smrg# distribute this file as part of a program that contains a
2533c89af1Smrg# configuration script generated by Autoconf, you may include it under
2633c89af1Smrg# the same distribution terms that you use for the rest of that program.
2733c89af1Smrg
2833c89af1Smrg# This file is maintained in Automake, please report
2933c89af1Smrg# bugs to <bug-automake@gnu.org> or send patches to
3033c89af1Smrg# <automake-patches@gnu.org>.
3133c89af1Smrg
3233c89af1Smrgcase $1 in
3333c89af1Smrg  '')
3433c89af1Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
3533c89af1Smrg     exit 1;
3633c89af1Smrg     ;;
3733c89af1Smrg  -h | --h*)
3833c89af1Smrg    cat <<\EOF
3933c89af1SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
4033c89af1Smrg
4133c89af1SmrgWrapper for compilers which do not understand `-c -o'.
4233c89af1SmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
4333c89af1Smrgarguments, and rename the output as expected.
4433c89af1Smrg
4533c89af1SmrgIf you are trying to build a whole package this is not the
4633c89af1Smrgright script to run: please start by reading the file `INSTALL'.
4733c89af1Smrg
4833c89af1SmrgReport bugs to <bug-automake@gnu.org>.
4933c89af1SmrgEOF
5033c89af1Smrg    exit $?
5133c89af1Smrg    ;;
5233c89af1Smrg  -v | --v*)
5333c89af1Smrg    echo "compile $scriptversion"
5433c89af1Smrg    exit $?
5533c89af1Smrg    ;;
5633c89af1Smrgesac
5733c89af1Smrg
5833c89af1Smrgofile=
5933c89af1Smrgcfile=
6033c89af1Smrgeat=
6133c89af1Smrg
6233c89af1Smrgfor arg
6333c89af1Smrgdo
6433c89af1Smrg  if test -n "$eat"; then
6533c89af1Smrg    eat=
6633c89af1Smrg  else
6733c89af1Smrg    case $1 in
6833c89af1Smrg      -o)
6933c89af1Smrg	# configure might choose to run compile as `compile cc -o foo foo.c'.
7033c89af1Smrg	# So we strip `-o arg' only if arg is an object.
7133c89af1Smrg	eat=1
7233c89af1Smrg	case $2 in
7333c89af1Smrg	  *.o | *.obj)
7433c89af1Smrg	    ofile=$2
7533c89af1Smrg	    ;;
7633c89af1Smrg	  *)
7733c89af1Smrg	    set x "$@" -o "$2"
7833c89af1Smrg	    shift
7933c89af1Smrg	    ;;
8033c89af1Smrg	esac
8133c89af1Smrg	;;
8233c89af1Smrg      *.c)
8333c89af1Smrg	cfile=$1
8433c89af1Smrg	set x "$@" "$1"
8533c89af1Smrg	shift
8633c89af1Smrg	;;
8733c89af1Smrg      *)
8833c89af1Smrg	set x "$@" "$1"
8933c89af1Smrg	shift
9033c89af1Smrg	;;
9133c89af1Smrg    esac
9233c89af1Smrg  fi
9333c89af1Smrg  shift
9433c89af1Smrgdone
9533c89af1Smrg
9633c89af1Smrgif test -z "$ofile" || test -z "$cfile"; then
9733c89af1Smrg  # If no `-o' option was seen then we might have been invoked from a
9833c89af1Smrg  # pattern rule where we don't need one.  That is ok -- this is a
9933c89af1Smrg  # normal compilation that the losing compiler can handle.  If no
10033c89af1Smrg  # `.c' file was seen then we are probably linking.  That is also
10133c89af1Smrg  # ok.
10233c89af1Smrg  exec "$@"
10333c89af1Smrgfi
10433c89af1Smrg
10533c89af1Smrg# Name of file we expect compiler to create.
10633c89af1Smrgcofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
10733c89af1Smrg
10833c89af1Smrg# Create the lock directory.
10933c89af1Smrg# Note: use `[/.-]' here to ensure that we don't use the same name
11033c89af1Smrg# that we are using for the .o file.  Also, base the name on the expected
11133c89af1Smrg# object file name, since that is what matters with a parallel build.
11233c89af1Smrglockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
11333c89af1Smrgwhile true; do
11433c89af1Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
11533c89af1Smrg    break
11633c89af1Smrg  fi
11733c89af1Smrg  sleep 1
11833c89af1Smrgdone
11933c89af1Smrg# FIXME: race condition here if user kills between mkdir and trap.
12033c89af1Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
12133c89af1Smrg
12233c89af1Smrg# Run the compile.
12333c89af1Smrg"$@"
12433c89af1Smrgret=$?
12533c89af1Smrg
12633c89af1Smrgif test -f "$cofile"; then
12733c89af1Smrg  mv "$cofile" "$ofile"
12833c89af1Smrgelif test -f "${cofile}bj"; then
12933c89af1Smrg  mv "${cofile}bj" "$ofile"
13033c89af1Smrgfi
13133c89af1Smrg
13233c89af1Smrgrmdir "$lockdir"
13333c89af1Smrgexit $ret
13433c89af1Smrg
13533c89af1Smrg# Local Variables:
13633c89af1Smrg# mode: shell-script
13733c89af1Smrg# sh-indentation: 2
13833c89af1Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
13933c89af1Smrg# time-stamp-start: "scriptversion="
14033c89af1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
14133c89af1Smrg# time-stamp-end: "$"
14233c89af1Smrg# End:
143