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