compile revision afe13c8e
1b3307321Smrg#! /bin/sh
2b3307321Smrg# Wrapper for compilers which do not understand `-c -o'.
3b3307321Smrg
4afe13c8eSmrgscriptversion=2005-05-14.22
5afe13c8eSmrg
6afe13c8eSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
7b3307321Smrg# Written by Tom Tromey <tromey@cygnus.com>.
8b3307321Smrg#
9b3307321Smrg# This program is free software; you can redistribute it and/or modify
10b3307321Smrg# it under the terms of the GNU General Public License as published by
11b3307321Smrg# the Free Software Foundation; either version 2, or (at your option)
12b3307321Smrg# any later version.
13b3307321Smrg#
14b3307321Smrg# This program is distributed in the hope that it will be useful,
15b3307321Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16b3307321Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17b3307321Smrg# GNU General Public License for more details.
18b3307321Smrg#
19b3307321Smrg# You should have received a copy of the GNU General Public License
20b3307321Smrg# along with this program; if not, write to the Free Software
21afe13c8eSmrg# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22b3307321Smrg
23b3307321Smrg# As a special exception to the GNU General Public License, if you
24b3307321Smrg# distribute this file as part of a program that contains a
25b3307321Smrg# configuration script generated by Autoconf, you may include it under
26b3307321Smrg# the same distribution terms that you use for the rest of that program.
27b3307321Smrg
28afe13c8eSmrg# This file is maintained in Automake, please report
29afe13c8eSmrg# bugs to <bug-automake@gnu.org> or send patches to
30afe13c8eSmrg# <automake-patches@gnu.org>.
31afe13c8eSmrg
32afe13c8eSmrgcase $1 in
33afe13c8eSmrg  '')
34afe13c8eSmrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
35afe13c8eSmrg     exit 1;
36afe13c8eSmrg     ;;
37afe13c8eSmrg  -h | --h*)
38afe13c8eSmrg    cat <<\EOF
39afe13c8eSmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
40afe13c8eSmrg
41afe13c8eSmrgWrapper for compilers which do not understand `-c -o'.
42afe13c8eSmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
43afe13c8eSmrgarguments, and rename the output as expected.
44b3307321Smrg
45afe13c8eSmrgIf you are trying to build a whole package this is not the
46afe13c8eSmrgright script to run: please start by reading the file `INSTALL'.
47afe13c8eSmrg
48afe13c8eSmrgReport bugs to <bug-automake@gnu.org>.
49afe13c8eSmrgEOF
50afe13c8eSmrg    exit $?
51afe13c8eSmrg    ;;
52afe13c8eSmrg  -v | --v*)
53afe13c8eSmrg    echo "compile $scriptversion"
54afe13c8eSmrg    exit $?
55afe13c8eSmrg    ;;
56afe13c8eSmrgesac
57b3307321Smrg
58b3307321Smrgofile=
59b3307321Smrgcfile=
60afe13c8eSmrgeat=
61afe13c8eSmrg
62afe13c8eSmrgfor arg
63afe13c8eSmrgdo
64afe13c8eSmrg  if test -n "$eat"; then
65afe13c8eSmrg    eat=
66afe13c8eSmrg  else
67afe13c8eSmrg    case $1 in
68afe13c8eSmrg      -o)
69afe13c8eSmrg	# configure might choose to run compile as `compile cc -o foo foo.c'.
70afe13c8eSmrg	# So we strip `-o arg' only if arg is an object.
71afe13c8eSmrg	eat=1
72afe13c8eSmrg	case $2 in
73afe13c8eSmrg	  *.o | *.obj)
74afe13c8eSmrg	    ofile=$2
75afe13c8eSmrg	    ;;
76afe13c8eSmrg	  *)
77afe13c8eSmrg	    set x "$@" -o "$2"
78afe13c8eSmrg	    shift
79afe13c8eSmrg	    ;;
80afe13c8eSmrg	esac
81afe13c8eSmrg	;;
82afe13c8eSmrg      *.c)
83afe13c8eSmrg	cfile=$1
84afe13c8eSmrg	set x "$@" "$1"
85afe13c8eSmrg	shift
86afe13c8eSmrg	;;
87afe13c8eSmrg      *)
88afe13c8eSmrg	set x "$@" "$1"
89afe13c8eSmrg	shift
90afe13c8eSmrg	;;
91afe13c8eSmrg    esac
92afe13c8eSmrg  fi
93afe13c8eSmrg  shift
94b3307321Smrgdone
95b3307321Smrg
96b3307321Smrgif test -z "$ofile" || test -z "$cfile"; then
97afe13c8eSmrg  # If no `-o' option was seen then we might have been invoked from a
98afe13c8eSmrg  # pattern rule where we don't need one.  That is ok -- this is a
99afe13c8eSmrg  # normal compilation that the losing compiler can handle.  If no
100afe13c8eSmrg  # `.c' file was seen then we are probably linking.  That is also
101afe13c8eSmrg  # ok.
102afe13c8eSmrg  exec "$@"
103b3307321Smrgfi
104b3307321Smrg
105b3307321Smrg# Name of file we expect compiler to create.
106afe13c8eSmrgcofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
107b3307321Smrg
108b3307321Smrg# Create the lock directory.
109b3307321Smrg# Note: use `[/.-]' here to ensure that we don't use the same name
110b3307321Smrg# that we are using for the .o file.  Also, base the name on the expected
111b3307321Smrg# object file name, since that is what matters with a parallel build.
112afe13c8eSmrglockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
113b3307321Smrgwhile true; do
114afe13c8eSmrg  if mkdir "$lockdir" >/dev/null 2>&1; then
115afe13c8eSmrg    break
116afe13c8eSmrg  fi
117afe13c8eSmrg  sleep 1
118b3307321Smrgdone
119b3307321Smrg# FIXME: race condition here if user kills between mkdir and trap.
120afe13c8eSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
121b3307321Smrg
122b3307321Smrg# Run the compile.
123afe13c8eSmrg"$@"
124afe13c8eSmrgret=$?
125b3307321Smrg
126b3307321Smrgif test -f "$cofile"; then
127afe13c8eSmrg  mv "$cofile" "$ofile"
128afe13c8eSmrgelif test -f "${cofile}bj"; then
129afe13c8eSmrg  mv "${cofile}bj" "$ofile"
130b3307321Smrgfi
131b3307321Smrg
132afe13c8eSmrgrmdir "$lockdir"
133afe13c8eSmrgexit $ret
134afe13c8eSmrg
135afe13c8eSmrg# Local Variables:
136afe13c8eSmrg# mode: shell-script
137afe13c8eSmrg# sh-indentation: 2
138afe13c8eSmrg# eval: (add-hook 'write-file-hooks 'time-stamp)
139afe13c8eSmrg# time-stamp-start: "scriptversion="
140afe13c8eSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
141afe13c8eSmrg# time-stamp-end: "$"
142afe13c8eSmrg# End:
143