190926Snectar#! /bin/sh
290926Snectar# Wrapper for compilers which do not understand `-c -o'.
390926Snectar
4233294Sstasscriptversion=2009-10-06.20; # UTC
5142403Snectar
6233294Sstas# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009  Free Software
7233294Sstas# Foundation, Inc.
890926Snectar# Written by Tom Tromey <tromey@cygnus.com>.
990926Snectar#
1090926Snectar# This program is free software; you can redistribute it and/or modify
1190926Snectar# it under the terms of the GNU General Public License as published by
1290926Snectar# the Free Software Foundation; either version 2, or (at your option)
1390926Snectar# any later version.
1490926Snectar#
1590926Snectar# This program is distributed in the hope that it will be useful,
1690926Snectar# but WITHOUT ANY WARRANTY; without even the implied warranty of
1790926Snectar# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1890926Snectar# GNU General Public License for more details.
1990926Snectar#
2090926Snectar# You should have received a copy of the GNU General Public License
21233294Sstas# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2290926Snectar
2390926Snectar# As a special exception to the GNU General Public License, if you
2490926Snectar# distribute this file as part of a program that contains a
2590926Snectar# configuration script generated by Autoconf, you may include it under
2690926Snectar# the same distribution terms that you use for the rest of that program.
2790926Snectar
28142403Snectar# This file is maintained in Automake, please report
29142403Snectar# bugs to <bug-automake@gnu.org> or send patches to
30142403Snectar# <automake-patches@gnu.org>.
3190926Snectar
32142403Snectarcase $1 in
33142403Snectar  '')
34142403Snectar     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
35142403Snectar     exit 1;
36142403Snectar     ;;
37142403Snectar  -h | --h*)
38142403Snectar    cat <<\EOF
39142403SnectarUsage: compile [--help] [--version] PROGRAM [ARGS]
40142403Snectar
41142403SnectarWrapper for compilers which do not understand `-c -o'.
42142403SnectarRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
43142403Snectararguments, and rename the output as expected.
44142403Snectar
45142403SnectarIf you are trying to build a whole package this is not the
46142403Snectarright script to run: please start by reading the file `INSTALL'.
47142403Snectar
48142403SnectarReport bugs to <bug-automake@gnu.org>.
49142403SnectarEOF
50178825Sdfr    exit $?
51142403Snectar    ;;
52142403Snectar  -v | --v*)
53142403Snectar    echo "compile $scriptversion"
54178825Sdfr    exit $?
55142403Snectar    ;;
56142403Snectaresac
57142403Snectar
5890926Snectarofile=
5990926Snectarcfile=
60178825Sdfreat=
61178825Sdfr
62178825Sdfrfor arg
63178825Sdfrdo
64178825Sdfr  if test -n "$eat"; then
65178825Sdfr    eat=
66178825Sdfr  else
67178825Sdfr    case $1 in
68178825Sdfr      -o)
69178825Sdfr	# configure might choose to run compile as `compile cc -o foo foo.c'.
70178825Sdfr	# So we strip `-o arg' only if arg is an object.
71178825Sdfr	eat=1
72178825Sdfr	case $2 in
73178825Sdfr	  *.o | *.obj)
74178825Sdfr	    ofile=$2
75178825Sdfr	    ;;
76178825Sdfr	  *)
77178825Sdfr	    set x "$@" -o "$2"
78178825Sdfr	    shift
79178825Sdfr	    ;;
80178825Sdfr	esac
81178825Sdfr	;;
82178825Sdfr      *.c)
83178825Sdfr	cfile=$1
84178825Sdfr	set x "$@" "$1"
85178825Sdfr	shift
86178825Sdfr	;;
87178825Sdfr      *)
88178825Sdfr	set x "$@" "$1"
89178825Sdfr	shift
90178825Sdfr	;;
91178825Sdfr    esac
92178825Sdfr  fi
93142403Snectar  shift
9490926Snectardone
9590926Snectar
9690926Snectarif test -z "$ofile" || test -z "$cfile"; then
97142403Snectar  # If no `-o' option was seen then we might have been invoked from a
98142403Snectar  # pattern rule where we don't need one.  That is ok -- this is a
99142403Snectar  # normal compilation that the losing compiler can handle.  If no
100142403Snectar  # `.c' file was seen then we are probably linking.  That is also
101142403Snectar  # ok.
102178825Sdfr  exec "$@"
10390926Snectarfi
10490926Snectar
10590926Snectar# Name of file we expect compiler to create.
106233294Sstascofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
10790926Snectar
10890926Snectar# Create the lock directory.
109233294Sstas# Note: use `[/\\:.-]' here to ensure that we don't use the same name
11090926Snectar# that we are using for the .o file.  Also, base the name on the expected
11190926Snectar# object file name, since that is what matters with a parallel build.
112233294Sstaslockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
11390926Snectarwhile true; do
114178825Sdfr  if mkdir "$lockdir" >/dev/null 2>&1; then
115142403Snectar    break
116142403Snectar  fi
117142403Snectar  sleep 1
11890926Snectardone
11990926Snectar# FIXME: race condition here if user kills between mkdir and trap.
120178825Sdfrtrap "rmdir '$lockdir'; exit 1" 1 2 15
12190926Snectar
12290926Snectar# Run the compile.
123178825Sdfr"$@"
124178825Sdfrret=$?
12590926Snectar
12690926Snectarif test -f "$cofile"; then
127233294Sstas  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
128178825Sdfrelif test -f "${cofile}bj"; then
129233294Sstas  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
13090926Snectarfi
13190926Snectar
132178825Sdfrrmdir "$lockdir"
133178825Sdfrexit $ret
134142403Snectar
135142403Snectar# Local Variables:
136142403Snectar# mode: shell-script
137142403Snectar# sh-indentation: 2
138142403Snectar# eval: (add-hook 'write-file-hooks 'time-stamp)
139142403Snectar# time-stamp-start: "scriptversion="
140142403Snectar# time-stamp-format: "%:y-%02m-%02d.%02H"
141233294Sstas# time-stamp-time-zone: "UTC"
142233294Sstas# time-stamp-end: "; # UTC"
143142403Snectar# End:
144