compile revision 421c997b
1994689c1Smrg#! /bin/sh
2994689c1Smrg# Wrapper for compilers which do not understand `-c -o'.
3994689c1Smrg
4421c997bSmrgscriptversion=2010-11-15.09; # UTC
5994689c1Smrg
6421c997bSmrg# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010 Free Software
7994689c1Smrg# Foundation, Inc.
8994689c1Smrg# Written by Tom Tromey <tromey@cygnus.com>.
9994689c1Smrg#
10994689c1Smrg# This program is free software; you can redistribute it and/or modify
11994689c1Smrg# it under the terms of the GNU General Public License as published by
12994689c1Smrg# the Free Software Foundation; either version 2, or (at your option)
13994689c1Smrg# any later version.
14994689c1Smrg#
15994689c1Smrg# This program is distributed in the hope that it will be useful,
16994689c1Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
17994689c1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18994689c1Smrg# GNU General Public License for more details.
19994689c1Smrg#
20994689c1Smrg# You should have received a copy of the GNU General Public License
21994689c1Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22994689c1Smrg
23994689c1Smrg# As a special exception to the GNU General Public License, if you
24994689c1Smrg# distribute this file as part of a program that contains a
25994689c1Smrg# configuration script generated by Autoconf, you may include it under
26994689c1Smrg# the same distribution terms that you use for the rest of that program.
27994689c1Smrg
28994689c1Smrg# This file is maintained in Automake, please report
29994689c1Smrg# bugs to <bug-automake@gnu.org> or send patches to
30994689c1Smrg# <automake-patches@gnu.org>.
31994689c1Smrg
32421c997bSmrgnl='
33421c997bSmrg'
34421c997bSmrg
35421c997bSmrg# We need space, tab and new line, in precisely that order.  Quoting is
36421c997bSmrg# there to prevent tools from complaining about whitespace usage.
37421c997bSmrgIFS=" ""	$nl"
38421c997bSmrg
39421c997bSmrgfile_conv=
40421c997bSmrg
41421c997bSmrg# func_file_conv build_file lazy
42421c997bSmrg# Convert a $build file to $host form and store it in $file
43421c997bSmrg# Currently only supports Win32 hosts. If the determined conversion
44421c997bSmrg# type is listed in (the comma separated) LAZY, no conversion will
45421c997bSmrg# take place.
46421c997bSmrgfunc_file_conv ()
47421c997bSmrg{
48421c997bSmrg  file=$1
49421c997bSmrg  case $file in
50421c997bSmrg    / | /[!/]*) # absolute file, and not a UNC file
51421c997bSmrg      if test -z "$file_conv"; then
52421c997bSmrg	# lazily determine how to convert abs files
53421c997bSmrg	case `uname -s` in
54421c997bSmrg	  MINGW*)
55421c997bSmrg	    file_conv=mingw
56421c997bSmrg	    ;;
57421c997bSmrg	  CYGWIN*)
58421c997bSmrg	    file_conv=cygwin
59421c997bSmrg	    ;;
60421c997bSmrg	  *)
61421c997bSmrg	    file_conv=wine
62421c997bSmrg	    ;;
63421c997bSmrg	esac
64421c997bSmrg      fi
65421c997bSmrg      case $file_conv/,$2, in
66421c997bSmrg	*,$file_conv,*)
67421c997bSmrg	  ;;
68421c997bSmrg	mingw/*)
69421c997bSmrg	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
70421c997bSmrg	  ;;
71421c997bSmrg	cygwin/*)
72421c997bSmrg	  file=`cygpath -m "$file" || echo "$file"`
73421c997bSmrg	  ;;
74421c997bSmrg	wine/*)
75421c997bSmrg	  file=`winepath -w "$file" || echo "$file"`
76421c997bSmrg	  ;;
77421c997bSmrg      esac
78421c997bSmrg      ;;
79421c997bSmrg  esac
80421c997bSmrg}
81421c997bSmrg
82421c997bSmrg# func_cl_wrapper cl arg...
83421c997bSmrg# Adjust compile command to suit cl
84421c997bSmrgfunc_cl_wrapper ()
85421c997bSmrg{
86421c997bSmrg  # Assume a capable shell
87421c997bSmrg  lib_path=
88421c997bSmrg  shared=:
89421c997bSmrg  linker_opts=
90421c997bSmrg  for arg
91421c997bSmrg  do
92421c997bSmrg    if test -n "$eat"; then
93421c997bSmrg      eat=
94421c997bSmrg    else
95421c997bSmrg      case $1 in
96421c997bSmrg	-o)
97421c997bSmrg	  # configure might choose to run compile as `compile cc -o foo foo.c'.
98421c997bSmrg	  eat=1
99421c997bSmrg	  case $2 in
100421c997bSmrg	    *.o | *.[oO][bB][jJ])
101421c997bSmrg	      func_file_conv "$2"
102421c997bSmrg	      set x "$@" -Fo"$file"
103421c997bSmrg	      shift
104421c997bSmrg	      ;;
105421c997bSmrg	    *)
106421c997bSmrg	      func_file_conv "$2"
107421c997bSmrg	      set x "$@" -Fe"$file"
108421c997bSmrg	      shift
109421c997bSmrg	      ;;
110421c997bSmrg	  esac
111421c997bSmrg	  ;;
112421c997bSmrg	-I*)
113421c997bSmrg	  func_file_conv "${1#-I}" mingw
114421c997bSmrg	  set x "$@" -I"$file"
115421c997bSmrg	  shift
116421c997bSmrg	  ;;
117421c997bSmrg	-l*)
118421c997bSmrg	  lib=${1#-l}
119421c997bSmrg	  found=no
120421c997bSmrg	  save_IFS=$IFS
121421c997bSmrg	  IFS=';'
122421c997bSmrg	  for dir in $lib_path $LIB
123421c997bSmrg	  do
124421c997bSmrg	    IFS=$save_IFS
125421c997bSmrg	    if $shared && test -f "$dir/$lib.dll.lib"; then
126421c997bSmrg	      found=yes
127421c997bSmrg	      set x "$@" "$dir/$lib.dll.lib"
128421c997bSmrg	      break
129421c997bSmrg	    fi
130421c997bSmrg	    if test -f "$dir/$lib.lib"; then
131421c997bSmrg	      found=yes
132421c997bSmrg	      set x "$@" "$dir/$lib.lib"
133421c997bSmrg	      break
134421c997bSmrg	    fi
135421c997bSmrg	  done
136421c997bSmrg	  IFS=$save_IFS
137421c997bSmrg
138421c997bSmrg	  test "$found" != yes && set x "$@" "$lib.lib"
139421c997bSmrg	  shift
140421c997bSmrg	  ;;
141421c997bSmrg	-L*)
142421c997bSmrg	  func_file_conv "${1#-L}"
143421c997bSmrg	  if test -z "$lib_path"; then
144421c997bSmrg	    lib_path=$file
145421c997bSmrg	  else
146421c997bSmrg	    lib_path="$lib_path;$file"
147421c997bSmrg	  fi
148421c997bSmrg	  linker_opts="$linker_opts -LIBPATH:$file"
149421c997bSmrg	  ;;
150421c997bSmrg	-static)
151421c997bSmrg	  shared=false
152421c997bSmrg	  ;;
153421c997bSmrg	-Wl,*)
154421c997bSmrg	  arg=${1#-Wl,}
155421c997bSmrg	  save_ifs="$IFS"; IFS=','
156421c997bSmrg	  for flag in $arg; do
157421c997bSmrg	    IFS="$save_ifs"
158421c997bSmrg	    linker_opts="$linker_opts $flag"
159421c997bSmrg	  done
160421c997bSmrg	  IFS="$save_ifs"
161421c997bSmrg	  ;;
162421c997bSmrg	-Xlinker)
163421c997bSmrg	  eat=1
164421c997bSmrg	  linker_opts="$linker_opts $2"
165421c997bSmrg	  ;;
166421c997bSmrg	-*)
167421c997bSmrg	  set x "$@" "$1"
168421c997bSmrg	  shift
169421c997bSmrg	  ;;
170421c997bSmrg	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
171421c997bSmrg	  func_file_conv "$1"
172421c997bSmrg	  set x "$@" -Tp"$file"
173421c997bSmrg	  shift
174421c997bSmrg	  ;;
175421c997bSmrg	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
176421c997bSmrg	  func_file_conv "$1" mingw
177421c997bSmrg	  set x "$@" "$file"
178421c997bSmrg	  shift
179421c997bSmrg	  ;;
180421c997bSmrg	*)
181421c997bSmrg	  set x "$@" "$1"
182421c997bSmrg	  shift
183421c997bSmrg	  ;;
184421c997bSmrg      esac
185421c997bSmrg    fi
186421c997bSmrg    shift
187421c997bSmrg  done
188421c997bSmrg  if test -n "$linker_opts"; then
189421c997bSmrg    linker_opts="-link$linker_opts"
190421c997bSmrg  fi
191421c997bSmrg  exec "$@" $linker_opts
192421c997bSmrg  exit 1
193421c997bSmrg}
194421c997bSmrg
195421c997bSmrgeat=
196421c997bSmrg
197994689c1Smrgcase $1 in
198994689c1Smrg  '')
199994689c1Smrg     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
200994689c1Smrg     exit 1;
201994689c1Smrg     ;;
202994689c1Smrg  -h | --h*)
203994689c1Smrg    cat <<\EOF
204994689c1SmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
205994689c1Smrg
206994689c1SmrgWrapper for compilers which do not understand `-c -o'.
207994689c1SmrgRemove `-o dest.o' from ARGS, run PROGRAM with the remaining
208994689c1Smrgarguments, and rename the output as expected.
209994689c1Smrg
210994689c1SmrgIf you are trying to build a whole package this is not the
211994689c1Smrgright script to run: please start by reading the file `INSTALL'.
212994689c1Smrg
213994689c1SmrgReport bugs to <bug-automake@gnu.org>.
214994689c1SmrgEOF
215994689c1Smrg    exit $?
216994689c1Smrg    ;;
217994689c1Smrg  -v | --v*)
218994689c1Smrg    echo "compile $scriptversion"
219994689c1Smrg    exit $?
220994689c1Smrg    ;;
221421c997bSmrg  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
222421c997bSmrg    func_cl_wrapper "$@"      # Doesn't return...
223421c997bSmrg    ;;
224994689c1Smrgesac
225994689c1Smrg
226994689c1Smrgofile=
227994689c1Smrgcfile=
228994689c1Smrg
229994689c1Smrgfor arg
230994689c1Smrgdo
231994689c1Smrg  if test -n "$eat"; then
232994689c1Smrg    eat=
233994689c1Smrg  else
234994689c1Smrg    case $1 in
235994689c1Smrg      -o)
236994689c1Smrg	# configure might choose to run compile as `compile cc -o foo foo.c'.
237994689c1Smrg	# So we strip `-o arg' only if arg is an object.
238994689c1Smrg	eat=1
239994689c1Smrg	case $2 in
240994689c1Smrg	  *.o | *.obj)
241994689c1Smrg	    ofile=$2
242994689c1Smrg	    ;;
243994689c1Smrg	  *)
244994689c1Smrg	    set x "$@" -o "$2"
245994689c1Smrg	    shift
246994689c1Smrg	    ;;
247994689c1Smrg	esac
248994689c1Smrg	;;
249994689c1Smrg      *.c)
250994689c1Smrg	cfile=$1
251994689c1Smrg	set x "$@" "$1"
252994689c1Smrg	shift
253994689c1Smrg	;;
254994689c1Smrg      *)
255994689c1Smrg	set x "$@" "$1"
256994689c1Smrg	shift
257994689c1Smrg	;;
258994689c1Smrg    esac
259994689c1Smrg  fi
260994689c1Smrg  shift
261994689c1Smrgdone
262994689c1Smrg
263994689c1Smrgif test -z "$ofile" || test -z "$cfile"; then
264994689c1Smrg  # If no `-o' option was seen then we might have been invoked from a
265994689c1Smrg  # pattern rule where we don't need one.  That is ok -- this is a
266994689c1Smrg  # normal compilation that the losing compiler can handle.  If no
267994689c1Smrg  # `.c' file was seen then we are probably linking.  That is also
268994689c1Smrg  # ok.
269994689c1Smrg  exec "$@"
270994689c1Smrgfi
271994689c1Smrg
272994689c1Smrg# Name of file we expect compiler to create.
273994689c1Smrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
274994689c1Smrg
275994689c1Smrg# Create the lock directory.
276994689c1Smrg# Note: use `[/\\:.-]' here to ensure that we don't use the same name
277994689c1Smrg# that we are using for the .o file.  Also, base the name on the expected
278994689c1Smrg# object file name, since that is what matters with a parallel build.
279994689c1Smrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
280994689c1Smrgwhile true; do
281994689c1Smrg  if mkdir "$lockdir" >/dev/null 2>&1; then
282994689c1Smrg    break
283994689c1Smrg  fi
284994689c1Smrg  sleep 1
285994689c1Smrgdone
286994689c1Smrg# FIXME: race condition here if user kills between mkdir and trap.
287994689c1Smrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
288994689c1Smrg
289994689c1Smrg# Run the compile.
290994689c1Smrg"$@"
291994689c1Smrgret=$?
292994689c1Smrg
293994689c1Smrgif test -f "$cofile"; then
294994689c1Smrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
295994689c1Smrgelif test -f "${cofile}bj"; then
296994689c1Smrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
297994689c1Smrgfi
298994689c1Smrg
299994689c1Smrgrmdir "$lockdir"
300994689c1Smrgexit $ret
301994689c1Smrg
302994689c1Smrg# Local Variables:
303994689c1Smrg# mode: shell-script
304994689c1Smrg# sh-indentation: 2
305994689c1Smrg# eval: (add-hook 'write-file-hooks 'time-stamp)
306994689c1Smrg# time-stamp-start: "scriptversion="
307994689c1Smrg# time-stamp-format: "%:y-%02m-%02d.%02H"
308994689c1Smrg# time-stamp-time-zone: "UTC"
309994689c1Smrg# time-stamp-end: "; # UTC"
310994689c1Smrg# End:
311