compile revision b3eb03f3
1010cdda0Smrg#! /bin/sh
2010cdda0Smrg# Wrapper for compilers which do not understand `-c -o'.
3010cdda0Smrg
4b3eb03f3Smrgscriptversion=2009-04-28.21; # UTC
5b3eb03f3Smrg
6b3eb03f3Smrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009  Free Software
7b3eb03f3Smrg# Foundation, Inc.
8010cdda0Smrg# Written by Tom Tromey <tromey@cygnus.com>.
9010cdda0Smrg#
10010cdda0Smrg# This program is free software; you can redistribute it and/or modify
11010cdda0Smrg# it under the terms of the GNU General Public License as published by
12010cdda0Smrg# the Free Software Foundation; either version 2, or (at your option)
13010cdda0Smrg# any later version.
14010cdda0Smrg#
15010cdda0Smrg# This program is distributed in the hope that it will be useful,
16010cdda0Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
17010cdda0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18010cdda0Smrg# GNU General Public License for more details.
19010cdda0Smrg#
20010cdda0Smrg# You should have received a copy of the GNU General Public License
21b3eb03f3Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22010cdda0Smrg
23010cdda0Smrg# As a special exception to the GNU General Public License, if you
24010cdda0Smrg# distribute this file as part of a program that contains a
25010cdda0Smrg# configuration script generated by Autoconf, you may include it under
26010cdda0Smrg# the same distribution terms that you use for the rest of that program.
27010cdda0Smrg
28b3eb03f3Smrg# This file is maintained in Automake, please report
29b3eb03f3Smrg# bugs to <bug-automake@gnu.org> or send patches to
30b3eb03f3Smrg# <automake-patches@gnu.org>.
31b3eb03f3Smrg
32b3eb03f3Smrgcase $1 in
33b3eb03f3Smrg  '')
34b3eb03f3Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
35b3eb03f3Smrg     exit 1;
36b3eb03f3Smrg     ;;
37b3eb03f3Smrg  -h | --h*)
38b3eb03f3Smrg    cat <<\EOF
39b3eb03f3SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
40b3eb03f3Smrg
41b3eb03f3SmrgWrapper for compilers which do not understand `-c -o'.
42b3eb03f3SmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
43b3eb03f3Smrgarguments, and rename the output as expected.
44010cdda0Smrg
45b3eb03f3SmrgIf you are trying to build a whole package this is not the
46b3eb03f3Smrgright script to run: please start by reading the file `INSTALL'.
47b3eb03f3Smrg
48b3eb03f3SmrgReport bugs to <bug-automake@gnu.org>.
49b3eb03f3SmrgEOF
50b3eb03f3Smrg    exit $?
51b3eb03f3Smrg    ;;
52b3eb03f3Smrg  -v | --v*)
53b3eb03f3Smrg    echo "compile $scriptversion"
54b3eb03f3Smrg    exit $?
55b3eb03f3Smrg    ;;
56b3eb03f3Smrgesac
57010cdda0Smrg
58010cdda0Smrgofile=
59010cdda0Smrgcfile=
60b3eb03f3Smrgeat=
61b3eb03f3Smrg
62b3eb03f3Smrgfor arg
63b3eb03f3Smrgdo
64b3eb03f3Smrg  if test -n "$eat"; then
65b3eb03f3Smrg    eat=
66b3eb03f3Smrg  else
67b3eb03f3Smrg    case $1 in
68b3eb03f3Smrg      -o)
69b3eb03f3Smrg	# configure might choose to run compile as `compile cc -o foo foo.c'.
70b3eb03f3Smrg	# So we strip `-o arg' only if arg is an object.
71b3eb03f3Smrg	eat=1
72b3eb03f3Smrg	case $2 in
73b3eb03f3Smrg	  *.o | *.obj)
74b3eb03f3Smrg	    ofile=$2
75b3eb03f3Smrg	    ;;
76b3eb03f3Smrg	  *)
77b3eb03f3Smrg	    set x "$@" -o "$2"
78b3eb03f3Smrg	    shift
79b3eb03f3Smrg	    ;;
80b3eb03f3Smrg	esac
81b3eb03f3Smrg	;;
82b3eb03f3Smrg      *.c)
83b3eb03f3Smrg	cfile=$1
84b3eb03f3Smrg	set x "$@" "$1"
85b3eb03f3Smrg	shift
86b3eb03f3Smrg	;;
87b3eb03f3Smrg      *)
88b3eb03f3Smrg	set x "$@" "$1"
89b3eb03f3Smrg	shift
90b3eb03f3Smrg	;;
91b3eb03f3Smrg    esac
92b3eb03f3Smrg  fi
93b3eb03f3Smrg  shift
94010cdda0Smrgdone
95010cdda0Smrg
96010cdda0Smrgif test -z "$ofile" || test -z "$cfile"; then
97b3eb03f3Smrg  # If no `-o' option was seen then we might have been invoked from a
98b3eb03f3Smrg  # pattern rule where we don't need one.  That is ok -- this is a
99b3eb03f3Smrg  # normal compilation that the losing compiler can handle.  If no
100b3eb03f3Smrg  # `.c' file was seen then we are probably linking.  That is also
101b3eb03f3Smrg  # ok.
102b3eb03f3Smrg  exec "$@"
103010cdda0Smrgfi
104010cdda0Smrg
105010cdda0Smrg# Name of file we expect compiler to create.
106b3eb03f3Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
107010cdda0Smrg
108010cdda0Smrg# Create the lock directory.
109b3eb03f3Smrg# Note: use `[/\\:.-]' here to ensure that we don't use the same name
110010cdda0Smrg# that we are using for the .o file.  Also, base the name on the expected
111010cdda0Smrg# object file name, since that is what matters with a parallel build.
112b3eb03f3Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
113010cdda0Smrgwhile true; do
114b3eb03f3Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
115b3eb03f3Smrg    break
116b3eb03f3Smrg  fi
117b3eb03f3Smrg  sleep 1
118010cdda0Smrgdone
119010cdda0Smrg# FIXME: race condition here if user kills between mkdir and trap.
120b3eb03f3Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
121010cdda0Smrg
122010cdda0Smrg# Run the compile.
123b3eb03f3Smrg"$@"
124b3eb03f3Smrgret=$?
125010cdda0Smrg
126010cdda0Smrgif test -f "$cofile"; then
127b3eb03f3Smrg  mv "$cofile" "$ofile"
128b3eb03f3Smrgelif test -f "${cofile}bj"; then
129b3eb03f3Smrg  mv "${cofile}bj" "$ofile"
130010cdda0Smrgfi
131010cdda0Smrg
132b3eb03f3Smrgrmdir "$lockdir"
133b3eb03f3Smrgexit $ret
134b3eb03f3Smrg
135b3eb03f3Smrg# Local Variables:
136b3eb03f3Smrg# mode: shell-script
137b3eb03f3Smrg# sh-indentation: 2
138b3eb03f3Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
139b3eb03f3Smrg# time-stamp-start: "scriptversion="
140b3eb03f3Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
141b3eb03f3Smrg# time-stamp-time-zone: "UTC"
142b3eb03f3Smrg# time-stamp-end: "; # UTC"
143b3eb03f3Smrg# End:
144