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