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