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