1181834Sroberto#! /bin/sh
2181834Sroberto# Wrapper for compilers which do not understand `-c -o'.
3181834Sroberto
4181834Srobertoscriptversion=2005-05-14.22
5181834Sroberto
6181834Sroberto# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
7181834Sroberto# Written by Tom Tromey <tromey@cygnus.com>.
8181834Sroberto#
9181834Sroberto# This program is free software; you can redistribute it and/or modify
10181834Sroberto# it under the terms of the GNU General Public License as published by
11181834Sroberto# the Free Software Foundation; either version 2, or (at your option)
12181834Sroberto# any later version.
13181834Sroberto#
14181834Sroberto# This program is distributed in the hope that it will be useful,
15181834Sroberto# but WITHOUT ANY WARRANTY; without even the implied warranty of
16181834Sroberto# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17181834Sroberto# GNU General Public License for more details.
18181834Sroberto#
19181834Sroberto# You should have received a copy of the GNU General Public License
20181834Sroberto# along with this program; if not, write to the Free Software
21181834Sroberto# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22181834Sroberto
23181834Sroberto# As a special exception to the GNU General Public License, if you
24181834Sroberto# distribute this file as part of a program that contains a
25181834Sroberto# configuration script generated by Autoconf, you may include it under
26181834Sroberto# the same distribution terms that you use for the rest of that program.
27181834Sroberto
28181834Sroberto# This file is maintained in Automake, please report
29181834Sroberto# bugs to <bug-automake@gnu.org> or send patches to
30181834Sroberto# <automake-patches@gnu.org>.
31181834Sroberto
32181834Srobertocase $1 in
33181834Sroberto  '')
34181834Sroberto     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
35181834Sroberto     exit 1;
36181834Sroberto     ;;
37181834Sroberto  -h | --h*)
38181834Sroberto    cat <<\EOF
39181834SrobertoUsage: compile [--help] [--version] PROGRAM [ARGS]
40181834Sroberto
41181834SrobertoWrapper for compilers which do not understand `-c -o'.
42181834SrobertoRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
43181834Srobertoarguments, and rename the output as expected.
44181834Sroberto
45181834SrobertoIf you are trying to build a whole package this is not the
46181834Srobertoright script to run: please start by reading the file `INSTALL'.
47181834Sroberto
48181834SrobertoReport bugs to <bug-automake@gnu.org>.
49181834SrobertoEOF
50181834Sroberto    exit $?
51181834Sroberto    ;;
52181834Sroberto  -v | --v*)
53181834Sroberto    echo "compile $scriptversion"
54181834Sroberto    exit $?
55181834Sroberto    ;;
56181834Srobertoesac
57181834Sroberto
58181834Srobertoofile=
59181834Srobertocfile=
60181834Srobertoeat=
61181834Sroberto
62181834Srobertofor arg
63181834Srobertodo
64181834Sroberto  if test -n "$eat"; then
65181834Sroberto    eat=
66181834Sroberto  else
67181834Sroberto    case $1 in
68181834Sroberto      -o)
69181834Sroberto	# configure might choose to run compile as `compile cc -o foo foo.c'.
70181834Sroberto	# So we strip `-o arg' only if arg is an object.
71181834Sroberto	eat=1
72181834Sroberto	case $2 in
73181834Sroberto	  *.o | *.obj)
74181834Sroberto	    ofile=$2
75181834Sroberto	    ;;
76181834Sroberto	  *)
77181834Sroberto	    set x "$@" -o "$2"
78181834Sroberto	    shift
79181834Sroberto	    ;;
80181834Sroberto	esac
81181834Sroberto	;;
82181834Sroberto      *.c)
83181834Sroberto	cfile=$1
84181834Sroberto	set x "$@" "$1"
85181834Sroberto	shift
86181834Sroberto	;;
87181834Sroberto      *)
88181834Sroberto	set x "$@" "$1"
89181834Sroberto	shift
90181834Sroberto	;;
91181834Sroberto    esac
92181834Sroberto  fi
93181834Sroberto  shift
94181834Srobertodone
95181834Sroberto
96181834Srobertoif test -z "$ofile" || test -z "$cfile"; then
97181834Sroberto  # If no `-o' option was seen then we might have been invoked from a
98181834Sroberto  # pattern rule where we don't need one.  That is ok -- this is a
99181834Sroberto  # normal compilation that the losing compiler can handle.  If no
100181834Sroberto  # `.c' file was seen then we are probably linking.  That is also
101181834Sroberto  # ok.
102181834Sroberto  exec "$@"
103181834Srobertofi
104181834Sroberto
105181834Sroberto# Name of file we expect compiler to create.
106181834Srobertocofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
107181834Sroberto
108181834Sroberto# Create the lock directory.
109181834Sroberto# Note: use `[/.-]' here to ensure that we don't use the same name
110181834Sroberto# that we are using for the .o file.  Also, base the name on the expected
111181834Sroberto# object file name, since that is what matters with a parallel build.
112181834Srobertolockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
113181834Srobertowhile true; do
114181834Sroberto  if mkdir "$lockdir" >/dev/null 2>&1; then
115181834Sroberto    break
116181834Sroberto  fi
117181834Sroberto  sleep 1
118181834Srobertodone
119181834Sroberto# FIXME: race condition here if user kills between mkdir and trap.
120181834Srobertotrap "rmdir '$lockdir'; exit 1" 1 2 15
121181834Sroberto
122181834Sroberto# Run the compile.
123181834Sroberto"$@"
124181834Srobertoret=$?
125181834Sroberto
126181834Srobertoif test -f "$cofile"; then
127181834Sroberto  mv "$cofile" "$ofile"
128181834Srobertoelif test -f "${cofile}bj"; then
129181834Sroberto  mv "${cofile}bj" "$ofile"
130181834Srobertofi
131181834Sroberto
132181834Srobertormdir "$lockdir"
133181834Srobertoexit $ret
134181834Sroberto
135181834Sroberto# Local Variables:
136181834Sroberto# mode: shell-script
137181834Sroberto# sh-indentation: 2
138181834Sroberto# eval: (add-hook 'write-file-hooks 'time-stamp)
139181834Sroberto# time-stamp-start: "scriptversion="
140181834Sroberto# time-stamp-format: "%:y-%02m-%02d.%02H"
141181834Sroberto# time-stamp-end: "$"
142181834Sroberto# End:
143