compile revision 994689c1
1994689c1Smrg#! /bin/sh
2994689c1Smrg# Wrapper for compilers which do not understand `-c -o'.
3994689c1Smrg
4994689c1Smrgscriptversion=2009-10-06.20; # UTC
5994689c1Smrg
6994689c1Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009  Free Software
7994689c1Smrg# Foundation, Inc.
8994689c1Smrg# Written by Tom Tromey <tromey@cygnus.com>.
9994689c1Smrg#
10994689c1Smrg# This program is free software; you can redistribute it and/or modify
11994689c1Smrg# it under the terms of the GNU General Public License as published by
12994689c1Smrg# the Free Software Foundation; either version 2, or (at your option)
13994689c1Smrg# any later version.
14994689c1Smrg#
15994689c1Smrg# This program is distributed in the hope that it will be useful,
16994689c1Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
17994689c1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18994689c1Smrg# GNU General Public License for more details.
19994689c1Smrg#
20994689c1Smrg# You should have received a copy of the GNU General Public License
21994689c1Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22994689c1Smrg
23994689c1Smrg# As a special exception to the GNU General Public License, if you
24994689c1Smrg# distribute this file as part of a program that contains a
25994689c1Smrg# configuration script generated by Autoconf, you may include it under
26994689c1Smrg# the same distribution terms that you use for the rest of that program.
27994689c1Smrg
28994689c1Smrg# This file is maintained in Automake, please report
29994689c1Smrg# bugs to <bug-automake@gnu.org> or send patches to
30994689c1Smrg# <automake-patches@gnu.org>.
31994689c1Smrg
32994689c1Smrgcase $1 in
33994689c1Smrg  '')
34994689c1Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
35994689c1Smrg     exit 1;
36994689c1Smrg     ;;
37994689c1Smrg  -h | --h*)
38994689c1Smrg    cat <<\EOF
39994689c1SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
40994689c1Smrg
41994689c1SmrgWrapper for compilers which do not understand `-c -o'.
42994689c1SmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
43994689c1Smrgarguments, and rename the output as expected.
44994689c1Smrg
45994689c1SmrgIf you are trying to build a whole package this is not the
46994689c1Smrgright script to run: please start by reading the file `INSTALL'.
47994689c1Smrg
48994689c1SmrgReport bugs to <bug-automake@gnu.org>.
49994689c1SmrgEOF
50994689c1Smrg    exit $?
51994689c1Smrg    ;;
52994689c1Smrg  -v | --v*)
53994689c1Smrg    echo "compile $scriptversion"
54994689c1Smrg    exit $?
55994689c1Smrg    ;;
56994689c1Smrgesac
57994689c1Smrg
58994689c1Smrgofile=
59994689c1Smrgcfile=
60994689c1Smrgeat=
61994689c1Smrg
62994689c1Smrgfor arg
63994689c1Smrgdo
64994689c1Smrg  if test -n "$eat"; then
65994689c1Smrg    eat=
66994689c1Smrg  else
67994689c1Smrg    case $1 in
68994689c1Smrg      -o)
69994689c1Smrg	# configure might choose to run compile as `compile cc -o foo foo.c'.
70994689c1Smrg	# So we strip `-o arg' only if arg is an object.
71994689c1Smrg	eat=1
72994689c1Smrg	case $2 in
73994689c1Smrg	  *.o | *.obj)
74994689c1Smrg	    ofile=$2
75994689c1Smrg	    ;;
76994689c1Smrg	  *)
77994689c1Smrg	    set x "$@" -o "$2"
78994689c1Smrg	    shift
79994689c1Smrg	    ;;
80994689c1Smrg	esac
81994689c1Smrg	;;
82994689c1Smrg      *.c)
83994689c1Smrg	cfile=$1
84994689c1Smrg	set x "$@" "$1"
85994689c1Smrg	shift
86994689c1Smrg	;;
87994689c1Smrg      *)
88994689c1Smrg	set x "$@" "$1"
89994689c1Smrg	shift
90994689c1Smrg	;;
91994689c1Smrg    esac
92994689c1Smrg  fi
93994689c1Smrg  shift
94994689c1Smrgdone
95994689c1Smrg
96994689c1Smrgif test -z "$ofile" || test -z "$cfile"; then
97994689c1Smrg  # If no `-o' option was seen then we might have been invoked from a
98994689c1Smrg  # pattern rule where we don't need one.  That is ok -- this is a
99994689c1Smrg  # normal compilation that the losing compiler can handle.  If no
100994689c1Smrg  # `.c' file was seen then we are probably linking.  That is also
101994689c1Smrg  # ok.
102994689c1Smrg  exec "$@"
103994689c1Smrgfi
104994689c1Smrg
105994689c1Smrg# Name of file we expect compiler to create.
106994689c1Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
107994689c1Smrg
108994689c1Smrg# Create the lock directory.
109994689c1Smrg# Note: use `[/\\:.-]' here to ensure that we don't use the same name
110994689c1Smrg# that we are using for the .o file.  Also, base the name on the expected
111994689c1Smrg# object file name, since that is what matters with a parallel build.
112994689c1Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
113994689c1Smrgwhile true; do
114994689c1Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
115994689c1Smrg    break
116994689c1Smrg  fi
117994689c1Smrg  sleep 1
118994689c1Smrgdone
119994689c1Smrg# FIXME: race condition here if user kills between mkdir and trap.
120994689c1Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
121994689c1Smrg
122994689c1Smrg# Run the compile.
123994689c1Smrg"$@"
124994689c1Smrgret=$?
125994689c1Smrg
126994689c1Smrgif test -f "$cofile"; then
127994689c1Smrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
128994689c1Smrgelif test -f "${cofile}bj"; then
129994689c1Smrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
130994689c1Smrgfi
131994689c1Smrg
132994689c1Smrgrmdir "$lockdir"
133994689c1Smrgexit $ret
134994689c1Smrg
135994689c1Smrg# Local Variables:
136994689c1Smrg# mode: shell-script
137994689c1Smrg# sh-indentation: 2
138994689c1Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
139994689c1Smrg# time-stamp-start: "scriptversion="
140994689c1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
141994689c1Smrg# time-stamp-time-zone: "UTC"
142994689c1Smrg# time-stamp-end: "; # UTC"
143994689c1Smrg# End:
144