compile revision 1.1.1.2 1 1.1 mrg #! /bin/sh
2 1.1 mrg # Wrapper for compilers which do not understand `-c -o'.
3 1.1 mrg
4 1.1.1.2 mrg scriptversion=2010-11-15.09; # UTC
5 1.1 mrg
6 1.1.1.2 mrg # Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010 Free Software
7 1.1 mrg # Foundation, Inc.
8 1.1 mrg # Written by Tom Tromey <tromey (at] cygnus.com>.
9 1.1 mrg #
10 1.1 mrg # This program is free software; you can redistribute it and/or modify
11 1.1 mrg # it under the terms of the GNU General Public License as published by
12 1.1 mrg # the Free Software Foundation; either version 2, or (at your option)
13 1.1 mrg # any later version.
14 1.1 mrg #
15 1.1 mrg # This program is distributed in the hope that it will be useful,
16 1.1 mrg # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 1.1 mrg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 1.1 mrg # GNU General Public License for more details.
19 1.1 mrg #
20 1.1 mrg # You should have received a copy of the GNU General Public License
21 1.1 mrg # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 1.1 mrg
23 1.1 mrg # As a special exception to the GNU General Public License, if you
24 1.1 mrg # distribute this file as part of a program that contains a
25 1.1 mrg # configuration script generated by Autoconf, you may include it under
26 1.1 mrg # the same distribution terms that you use for the rest of that program.
27 1.1 mrg
28 1.1 mrg # This file is maintained in Automake, please report
29 1.1 mrg # bugs to <bug-automake (at] gnu.org> or send patches to
30 1.1 mrg # <automake-patches (at] gnu.org>.
31 1.1 mrg
32 1.1.1.2 mrg nl='
33 1.1.1.2 mrg '
34 1.1.1.2 mrg
35 1.1.1.2 mrg # We need space, tab and new line, in precisely that order. Quoting is
36 1.1.1.2 mrg # there to prevent tools from complaining about whitespace usage.
37 1.1.1.2 mrg IFS=" "" $nl"
38 1.1.1.2 mrg
39 1.1.1.2 mrg file_conv=
40 1.1.1.2 mrg
41 1.1.1.2 mrg # func_file_conv build_file lazy
42 1.1.1.2 mrg # Convert a $build file to $host form and store it in $file
43 1.1.1.2 mrg # Currently only supports Win32 hosts. If the determined conversion
44 1.1.1.2 mrg # type is listed in (the comma separated) LAZY, no conversion will
45 1.1.1.2 mrg # take place.
46 1.1.1.2 mrg func_file_conv ()
47 1.1.1.2 mrg {
48 1.1.1.2 mrg file=$1
49 1.1.1.2 mrg case $file in
50 1.1.1.2 mrg / | /[!/]*) # absolute file, and not a UNC file
51 1.1.1.2 mrg if test -z "$file_conv"; then
52 1.1.1.2 mrg # lazily determine how to convert abs files
53 1.1.1.2 mrg case `uname -s` in
54 1.1.1.2 mrg MINGW*)
55 1.1.1.2 mrg file_conv=mingw
56 1.1.1.2 mrg ;;
57 1.1.1.2 mrg CYGWIN*)
58 1.1.1.2 mrg file_conv=cygwin
59 1.1.1.2 mrg ;;
60 1.1.1.2 mrg *)
61 1.1.1.2 mrg file_conv=wine
62 1.1.1.2 mrg ;;
63 1.1.1.2 mrg esac
64 1.1.1.2 mrg fi
65 1.1.1.2 mrg case $file_conv/,$2, in
66 1.1.1.2 mrg *,$file_conv,*)
67 1.1.1.2 mrg ;;
68 1.1.1.2 mrg mingw/*)
69 1.1.1.2 mrg file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
70 1.1.1.2 mrg ;;
71 1.1.1.2 mrg cygwin/*)
72 1.1.1.2 mrg file=`cygpath -m "$file" || echo "$file"`
73 1.1.1.2 mrg ;;
74 1.1.1.2 mrg wine/*)
75 1.1.1.2 mrg file=`winepath -w "$file" || echo "$file"`
76 1.1.1.2 mrg ;;
77 1.1.1.2 mrg esac
78 1.1.1.2 mrg ;;
79 1.1.1.2 mrg esac
80 1.1.1.2 mrg }
81 1.1.1.2 mrg
82 1.1.1.2 mrg # func_cl_wrapper cl arg...
83 1.1.1.2 mrg # Adjust compile command to suit cl
84 1.1.1.2 mrg func_cl_wrapper ()
85 1.1.1.2 mrg {
86 1.1.1.2 mrg # Assume a capable shell
87 1.1.1.2 mrg lib_path=
88 1.1.1.2 mrg shared=:
89 1.1.1.2 mrg linker_opts=
90 1.1.1.2 mrg for arg
91 1.1.1.2 mrg do
92 1.1.1.2 mrg if test -n "$eat"; then
93 1.1.1.2 mrg eat=
94 1.1.1.2 mrg else
95 1.1.1.2 mrg case $1 in
96 1.1.1.2 mrg -o)
97 1.1.1.2 mrg # configure might choose to run compile as `compile cc -o foo foo.c'.
98 1.1.1.2 mrg eat=1
99 1.1.1.2 mrg case $2 in
100 1.1.1.2 mrg *.o | *.[oO][bB][jJ])
101 1.1.1.2 mrg func_file_conv "$2"
102 1.1.1.2 mrg set x "$@" -Fo"$file"
103 1.1.1.2 mrg shift
104 1.1.1.2 mrg ;;
105 1.1.1.2 mrg *)
106 1.1.1.2 mrg func_file_conv "$2"
107 1.1.1.2 mrg set x "$@" -Fe"$file"
108 1.1.1.2 mrg shift
109 1.1.1.2 mrg ;;
110 1.1.1.2 mrg esac
111 1.1.1.2 mrg ;;
112 1.1.1.2 mrg -I*)
113 1.1.1.2 mrg func_file_conv "${1#-I}" mingw
114 1.1.1.2 mrg set x "$@" -I"$file"
115 1.1.1.2 mrg shift
116 1.1.1.2 mrg ;;
117 1.1.1.2 mrg -l*)
118 1.1.1.2 mrg lib=${1#-l}
119 1.1.1.2 mrg found=no
120 1.1.1.2 mrg save_IFS=$IFS
121 1.1.1.2 mrg IFS=';'
122 1.1.1.2 mrg for dir in $lib_path $LIB
123 1.1.1.2 mrg do
124 1.1.1.2 mrg IFS=$save_IFS
125 1.1.1.2 mrg if $shared && test -f "$dir/$lib.dll.lib"; then
126 1.1.1.2 mrg found=yes
127 1.1.1.2 mrg set x "$@" "$dir/$lib.dll.lib"
128 1.1.1.2 mrg break
129 1.1.1.2 mrg fi
130 1.1.1.2 mrg if test -f "$dir/$lib.lib"; then
131 1.1.1.2 mrg found=yes
132 1.1.1.2 mrg set x "$@" "$dir/$lib.lib"
133 1.1.1.2 mrg break
134 1.1.1.2 mrg fi
135 1.1.1.2 mrg done
136 1.1.1.2 mrg IFS=$save_IFS
137 1.1.1.2 mrg
138 1.1.1.2 mrg test "$found" != yes && set x "$@" "$lib.lib"
139 1.1.1.2 mrg shift
140 1.1.1.2 mrg ;;
141 1.1.1.2 mrg -L*)
142 1.1.1.2 mrg func_file_conv "${1#-L}"
143 1.1.1.2 mrg if test -z "$lib_path"; then
144 1.1.1.2 mrg lib_path=$file
145 1.1.1.2 mrg else
146 1.1.1.2 mrg lib_path="$lib_path;$file"
147 1.1.1.2 mrg fi
148 1.1.1.2 mrg linker_opts="$linker_opts -LIBPATH:$file"
149 1.1.1.2 mrg ;;
150 1.1.1.2 mrg -static)
151 1.1.1.2 mrg shared=false
152 1.1.1.2 mrg ;;
153 1.1.1.2 mrg -Wl,*)
154 1.1.1.2 mrg arg=${1#-Wl,}
155 1.1.1.2 mrg save_ifs="$IFS"; IFS=','
156 1.1.1.2 mrg for flag in $arg; do
157 1.1.1.2 mrg IFS="$save_ifs"
158 1.1.1.2 mrg linker_opts="$linker_opts $flag"
159 1.1.1.2 mrg done
160 1.1.1.2 mrg IFS="$save_ifs"
161 1.1.1.2 mrg ;;
162 1.1.1.2 mrg -Xlinker)
163 1.1.1.2 mrg eat=1
164 1.1.1.2 mrg linker_opts="$linker_opts $2"
165 1.1.1.2 mrg ;;
166 1.1.1.2 mrg -*)
167 1.1.1.2 mrg set x "$@" "$1"
168 1.1.1.2 mrg shift
169 1.1.1.2 mrg ;;
170 1.1.1.2 mrg *.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
171 1.1.1.2 mrg func_file_conv "$1"
172 1.1.1.2 mrg set x "$@" -Tp"$file"
173 1.1.1.2 mrg shift
174 1.1.1.2 mrg ;;
175 1.1.1.2 mrg *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
176 1.1.1.2 mrg func_file_conv "$1" mingw
177 1.1.1.2 mrg set x "$@" "$file"
178 1.1.1.2 mrg shift
179 1.1.1.2 mrg ;;
180 1.1.1.2 mrg *)
181 1.1.1.2 mrg set x "$@" "$1"
182 1.1.1.2 mrg shift
183 1.1.1.2 mrg ;;
184 1.1.1.2 mrg esac
185 1.1.1.2 mrg fi
186 1.1.1.2 mrg shift
187 1.1.1.2 mrg done
188 1.1.1.2 mrg if test -n "$linker_opts"; then
189 1.1.1.2 mrg linker_opts="-link$linker_opts"
190 1.1.1.2 mrg fi
191 1.1.1.2 mrg exec "$@" $linker_opts
192 1.1.1.2 mrg exit 1
193 1.1.1.2 mrg }
194 1.1.1.2 mrg
195 1.1.1.2 mrg eat=
196 1.1.1.2 mrg
197 1.1 mrg case $1 in
198 1.1 mrg '')
199 1.1 mrg echo "$0: No command. Try \`$0 --help' for more information." 1>&2
200 1.1 mrg exit 1;
201 1.1 mrg ;;
202 1.1 mrg -h | --h*)
203 1.1 mrg cat <<\EOF
204 1.1 mrg Usage: compile [--help] [--version] PROGRAM [ARGS]
205 1.1 mrg
206 1.1 mrg Wrapper for compilers which do not understand `-c -o'.
207 1.1 mrg Remove `-o dest.o' from ARGS, run PROGRAM with the remaining
208 1.1 mrg arguments, and rename the output as expected.
209 1.1 mrg
210 1.1 mrg If you are trying to build a whole package this is not the
211 1.1 mrg right script to run: please start by reading the file `INSTALL'.
212 1.1 mrg
213 1.1 mrg Report bugs to <bug-automake (at] gnu.org>.
214 1.1 mrg EOF
215 1.1 mrg exit $?
216 1.1 mrg ;;
217 1.1 mrg -v | --v*)
218 1.1 mrg echo "compile $scriptversion"
219 1.1 mrg exit $?
220 1.1 mrg ;;
221 1.1.1.2 mrg cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
222 1.1.1.2 mrg func_cl_wrapper "$@" # Doesn't return...
223 1.1.1.2 mrg ;;
224 1.1 mrg esac
225 1.1 mrg
226 1.1 mrg ofile=
227 1.1 mrg cfile=
228 1.1 mrg
229 1.1 mrg for arg
230 1.1 mrg do
231 1.1 mrg if test -n "$eat"; then
232 1.1 mrg eat=
233 1.1 mrg else
234 1.1 mrg case $1 in
235 1.1 mrg -o)
236 1.1 mrg # configure might choose to run compile as `compile cc -o foo foo.c'.
237 1.1 mrg # So we strip `-o arg' only if arg is an object.
238 1.1 mrg eat=1
239 1.1 mrg case $2 in
240 1.1 mrg *.o | *.obj)
241 1.1 mrg ofile=$2
242 1.1 mrg ;;
243 1.1 mrg *)
244 1.1 mrg set x "$@" -o "$2"
245 1.1 mrg shift
246 1.1 mrg ;;
247 1.1 mrg esac
248 1.1 mrg ;;
249 1.1 mrg *.c)
250 1.1 mrg cfile=$1
251 1.1 mrg set x "$@" "$1"
252 1.1 mrg shift
253 1.1 mrg ;;
254 1.1 mrg *)
255 1.1 mrg set x "$@" "$1"
256 1.1 mrg shift
257 1.1 mrg ;;
258 1.1 mrg esac
259 1.1 mrg fi
260 1.1 mrg shift
261 1.1 mrg done
262 1.1 mrg
263 1.1 mrg if test -z "$ofile" || test -z "$cfile"; then
264 1.1 mrg # If no `-o' option was seen then we might have been invoked from a
265 1.1 mrg # pattern rule where we don't need one. That is ok -- this is a
266 1.1 mrg # normal compilation that the losing compiler can handle. If no
267 1.1 mrg # `.c' file was seen then we are probably linking. That is also
268 1.1 mrg # ok.
269 1.1 mrg exec "$@"
270 1.1 mrg fi
271 1.1 mrg
272 1.1 mrg # Name of file we expect compiler to create.
273 1.1 mrg cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
274 1.1 mrg
275 1.1 mrg # Create the lock directory.
276 1.1 mrg # Note: use `[/\\:.-]' here to ensure that we don't use the same name
277 1.1 mrg # that we are using for the .o file. Also, base the name on the expected
278 1.1 mrg # object file name, since that is what matters with a parallel build.
279 1.1 mrg lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
280 1.1 mrg while true; do
281 1.1 mrg if mkdir "$lockdir" >/dev/null 2>&1; then
282 1.1 mrg break
283 1.1 mrg fi
284 1.1 mrg sleep 1
285 1.1 mrg done
286 1.1 mrg # FIXME: race condition here if user kills between mkdir and trap.
287 1.1 mrg trap "rmdir '$lockdir'; exit 1" 1 2 15
288 1.1 mrg
289 1.1 mrg # Run the compile.
290 1.1 mrg "$@"
291 1.1 mrg ret=$?
292 1.1 mrg
293 1.1 mrg if test -f "$cofile"; then
294 1.1 mrg test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
295 1.1 mrg elif test -f "${cofile}bj"; then
296 1.1 mrg test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
297 1.1 mrg fi
298 1.1 mrg
299 1.1 mrg rmdir "$lockdir"
300 1.1 mrg exit $ret
301 1.1 mrg
302 1.1 mrg # Local Variables:
303 1.1 mrg # mode: shell-script
304 1.1 mrg # sh-indentation: 2
305 1.1 mrg # eval: (add-hook 'write-file-hooks 'time-stamp)
306 1.1 mrg # time-stamp-start: "scriptversion="
307 1.1 mrg # time-stamp-format: "%:y-%02m-%02d.%02H"
308 1.1 mrg # time-stamp-time-zone: "UTC"
309 1.1 mrg # time-stamp-end: "; # UTC"
310 1.1 mrg # End:
311