140dd5a57Smrg#! /bin/sh
240dd5a57Smrg# Wrapper for compilers which do not understand `-c -o'.
340dd5a57Smrg
440dd5a57Smrgscriptversion=2009-10-06.20; # UTC
540dd5a57Smrg
640dd5a57Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009  Free Software
740dd5a57Smrg# Foundation, Inc.
840dd5a57Smrg# Written by Tom Tromey <tromey@cygnus.com>.
940dd5a57Smrg#
1040dd5a57Smrg# This program is free software; you can redistribute it and/or modify
1140dd5a57Smrg# it under the terms of the GNU General Public License as published by
1240dd5a57Smrg# the Free Software Foundation; either version 2, or (at your option)
1340dd5a57Smrg# any later version.
1440dd5a57Smrg#
1540dd5a57Smrg# This program is distributed in the hope that it will be useful,
1640dd5a57Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1740dd5a57Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1840dd5a57Smrg# GNU General Public License for more details.
1940dd5a57Smrg#
2040dd5a57Smrg# You should have received a copy of the GNU General Public License
2140dd5a57Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2240dd5a57Smrg
2340dd5a57Smrg# As a special exception to the GNU General Public License, if you
2440dd5a57Smrg# distribute this file as part of a program that contains a
2540dd5a57Smrg# configuration script generated by Autoconf, you may include it under
2640dd5a57Smrg# the same distribution terms that you use for the rest of that program.
2740dd5a57Smrg
2840dd5a57Smrg# This file is maintained in Automake, please report
2940dd5a57Smrg# bugs to <bug-automake@gnu.org> or send patches to
3040dd5a57Smrg# <automake-patches@gnu.org>.
3140dd5a57Smrg
3240dd5a57Smrgcase $1 in
3340dd5a57Smrg  '')
3440dd5a57Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
3540dd5a57Smrg     exit 1;
3640dd5a57Smrg     ;;
3740dd5a57Smrg  -h | --h*)
3840dd5a57Smrg    cat <<\EOF
3940dd5a57SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
4040dd5a57Smrg
4140dd5a57SmrgWrapper for compilers which do not understand `-c -o'.
4240dd5a57SmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
4340dd5a57Smrgarguments, and rename the output as expected.
4440dd5a57Smrg
4540dd5a57SmrgIf you are trying to build a whole package this is not the
4640dd5a57Smrgright script to run: please start by reading the file `INSTALL'.
4740dd5a57Smrg
4840dd5a57SmrgReport bugs to <bug-automake@gnu.org>.
4940dd5a57SmrgEOF
5040dd5a57Smrg    exit $?
5140dd5a57Smrg    ;;
5240dd5a57Smrg  -v | --v*)
5340dd5a57Smrg    echo "compile $scriptversion"
5440dd5a57Smrg    exit $?
5540dd5a57Smrg    ;;
5640dd5a57Smrgesac
5740dd5a57Smrg
5840dd5a57Smrgofile=
5940dd5a57Smrgcfile=
6040dd5a57Smrgeat=
6140dd5a57Smrg
6240dd5a57Smrgfor arg
6340dd5a57Smrgdo
6440dd5a57Smrg  if test -n "$eat"; then
6540dd5a57Smrg    eat=
6640dd5a57Smrg  else
6740dd5a57Smrg    case $1 in
6840dd5a57Smrg      -o)
6940dd5a57Smrg	# configure might choose to run compile as `compile cc -o foo foo.c'.
7040dd5a57Smrg	# So we strip `-o arg' only if arg is an object.
7140dd5a57Smrg	eat=1
7240dd5a57Smrg	case $2 in
7340dd5a57Smrg	  *.o | *.obj)
7440dd5a57Smrg	    ofile=$2
7540dd5a57Smrg	    ;;
7640dd5a57Smrg	  *)
7740dd5a57Smrg	    set x "$@" -o "$2"
7840dd5a57Smrg	    shift
7940dd5a57Smrg	    ;;
8040dd5a57Smrg	esac
8140dd5a57Smrg	;;
8240dd5a57Smrg      *.c)
8340dd5a57Smrg	cfile=$1
8440dd5a57Smrg	set x "$@" "$1"
8540dd5a57Smrg	shift
8640dd5a57Smrg	;;
8740dd5a57Smrg      *)
8840dd5a57Smrg	set x "$@" "$1"
8940dd5a57Smrg	shift
9040dd5a57Smrg	;;
9140dd5a57Smrg    esac
9240dd5a57Smrg  fi
9340dd5a57Smrg  shift
9440dd5a57Smrgdone
9540dd5a57Smrg
9640dd5a57Smrgif test -z "$ofile" || test -z "$cfile"; then
9740dd5a57Smrg  # If no `-o' option was seen then we might have been invoked from a
9840dd5a57Smrg  # pattern rule where we don't need one.  That is ok -- this is a
9940dd5a57Smrg  # normal compilation that the losing compiler can handle.  If no
10040dd5a57Smrg  # `.c' file was seen then we are probably linking.  That is also
10140dd5a57Smrg  # ok.
10240dd5a57Smrg  exec "$@"
10340dd5a57Smrgfi
10440dd5a57Smrg
10540dd5a57Smrg# Name of file we expect compiler to create.
10640dd5a57Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
10740dd5a57Smrg
10840dd5a57Smrg# Create the lock directory.
10940dd5a57Smrg# Note: use `[/\\:.-]' here to ensure that we don't use the same name
11040dd5a57Smrg# that we are using for the .o file.  Also, base the name on the expected
11140dd5a57Smrg# object file name, since that is what matters with a parallel build.
11240dd5a57Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
11340dd5a57Smrgwhile true; do
11440dd5a57Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
11540dd5a57Smrg    break
11640dd5a57Smrg  fi
11740dd5a57Smrg  sleep 1
11840dd5a57Smrgdone
11940dd5a57Smrg# FIXME: race condition here if user kills between mkdir and trap.
12040dd5a57Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
12140dd5a57Smrg
12240dd5a57Smrg# Run the compile.
12340dd5a57Smrg"$@"
12440dd5a57Smrgret=$?
12540dd5a57Smrg
12640dd5a57Smrgif test -f "$cofile"; then
12740dd5a57Smrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
12840dd5a57Smrgelif test -f "${cofile}bj"; then
12940dd5a57Smrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
13040dd5a57Smrgfi
13140dd5a57Smrg
13240dd5a57Smrgrmdir "$lockdir"
13340dd5a57Smrgexit $ret
13440dd5a57Smrg
13540dd5a57Smrg# Local Variables:
13640dd5a57Smrg# mode: shell-script
13740dd5a57Smrg# sh-indentation: 2
13840dd5a57Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
13940dd5a57Smrg# time-stamp-start: "scriptversion="
14040dd5a57Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
14140dd5a57Smrg# time-stamp-time-zone: "UTC"
14240dd5a57Smrg# time-stamp-end: "; # UTC"
14340dd5a57Smrg# End:
144