compile revision f9c28e31
1576bbdfcSmrg#! /bin/sh
2576bbdfcSmrg# Wrapper for compilers which do not understand '-c -o'.
3576bbdfcSmrg
4f9c28e31Smrgscriptversion=2018-03-07.03; # UTC
5576bbdfcSmrg
6f9c28e31Smrg# Copyright (C) 1999-2020 Free Software Foundation, Inc.
7576bbdfcSmrg# Written by Tom Tromey <tromey@cygnus.com>.
8576bbdfcSmrg#
9576bbdfcSmrg# This program is free software; you can redistribute it and/or modify
10576bbdfcSmrg# it under the terms of the GNU General Public License as published by
11576bbdfcSmrg# the Free Software Foundation; either version 2, or (at your option)
12576bbdfcSmrg# any later version.
13576bbdfcSmrg#
14576bbdfcSmrg# This program is distributed in the hope that it will be useful,
15576bbdfcSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16576bbdfcSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17576bbdfcSmrg# GNU General Public License for more details.
18576bbdfcSmrg#
19576bbdfcSmrg# You should have received a copy of the GNU General Public License
20f9c28e31Smrg# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21576bbdfcSmrg
22576bbdfcSmrg# As a special exception to the GNU General Public License, if you
23576bbdfcSmrg# distribute this file as part of a program that contains a
24576bbdfcSmrg# configuration script generated by Autoconf, you may include it under
25576bbdfcSmrg# the same distribution terms that you use for the rest of that program.
26576bbdfcSmrg
27576bbdfcSmrg# This file is maintained in Automake, please report
28576bbdfcSmrg# bugs to <bug-automake@gnu.org> or send patches to
29576bbdfcSmrg# <automake-patches@gnu.org>.
30576bbdfcSmrg
31576bbdfcSmrgnl='
32576bbdfcSmrg'
33576bbdfcSmrg
34576bbdfcSmrg# We need space, tab and new line, in precisely that order.  Quoting is
35576bbdfcSmrg# there to prevent tools from complaining about whitespace usage.
36576bbdfcSmrgIFS=" ""	$nl"
37576bbdfcSmrg
38576bbdfcSmrgfile_conv=
39576bbdfcSmrg
40576bbdfcSmrg# func_file_conv build_file lazy
41576bbdfcSmrg# Convert a $build file to $host form and store it in $file
42576bbdfcSmrg# Currently only supports Windows hosts. If the determined conversion
43576bbdfcSmrg# type is listed in (the comma separated) LAZY, no conversion will
44576bbdfcSmrg# take place.
45576bbdfcSmrgfunc_file_conv ()
46576bbdfcSmrg{
47576bbdfcSmrg  file=$1
48576bbdfcSmrg  case $file in
49576bbdfcSmrg    / | /[!/]*) # absolute file, and not a UNC file
50576bbdfcSmrg      if test -z "$file_conv"; then
51576bbdfcSmrg	# lazily determine how to convert abs files
52576bbdfcSmrg	case `uname -s` in
53576bbdfcSmrg	  MINGW*)
54576bbdfcSmrg	    file_conv=mingw
55576bbdfcSmrg	    ;;
56f9c28e31Smrg	  CYGWIN* | MSYS*)
57576bbdfcSmrg	    file_conv=cygwin
58576bbdfcSmrg	    ;;
59576bbdfcSmrg	  *)
60576bbdfcSmrg	    file_conv=wine
61576bbdfcSmrg	    ;;
62576bbdfcSmrg	esac
63576bbdfcSmrg      fi
64576bbdfcSmrg      case $file_conv/,$2, in
65576bbdfcSmrg	*,$file_conv,*)
66576bbdfcSmrg	  ;;
67576bbdfcSmrg	mingw/*)
68576bbdfcSmrg	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
69576bbdfcSmrg	  ;;
70f9c28e31Smrg	cygwin/* | msys/*)
71576bbdfcSmrg	  file=`cygpath -m "$file" || echo "$file"`
72576bbdfcSmrg	  ;;
73576bbdfcSmrg	wine/*)
74576bbdfcSmrg	  file=`winepath -w "$file" || echo "$file"`
75576bbdfcSmrg	  ;;
76576bbdfcSmrg      esac
77576bbdfcSmrg      ;;
78576bbdfcSmrg  esac
79576bbdfcSmrg}
80576bbdfcSmrg
81576bbdfcSmrg# func_cl_dashL linkdir
82576bbdfcSmrg# Make cl look for libraries in LINKDIR
83576bbdfcSmrgfunc_cl_dashL ()
84576bbdfcSmrg{
85576bbdfcSmrg  func_file_conv "$1"
86576bbdfcSmrg  if test -z "$lib_path"; then
87576bbdfcSmrg    lib_path=$file
88576bbdfcSmrg  else
89576bbdfcSmrg    lib_path="$lib_path;$file"
90576bbdfcSmrg  fi
91576bbdfcSmrg  linker_opts="$linker_opts -LIBPATH:$file"
92576bbdfcSmrg}
93576bbdfcSmrg
94576bbdfcSmrg# func_cl_dashl library
95576bbdfcSmrg# Do a library search-path lookup for cl
96576bbdfcSmrgfunc_cl_dashl ()
97576bbdfcSmrg{
98576bbdfcSmrg  lib=$1
99576bbdfcSmrg  found=no
100576bbdfcSmrg  save_IFS=$IFS
101576bbdfcSmrg  IFS=';'
102576bbdfcSmrg  for dir in $lib_path $LIB
103576bbdfcSmrg  do
104576bbdfcSmrg    IFS=$save_IFS
105576bbdfcSmrg    if $shared && test -f "$dir/$lib.dll.lib"; then
106576bbdfcSmrg      found=yes
107576bbdfcSmrg      lib=$dir/$lib.dll.lib
108576bbdfcSmrg      break
109576bbdfcSmrg    fi
110576bbdfcSmrg    if test -f "$dir/$lib.lib"; then
111576bbdfcSmrg      found=yes
112576bbdfcSmrg      lib=$dir/$lib.lib
113576bbdfcSmrg      break
114576bbdfcSmrg    fi
115576bbdfcSmrg    if test -f "$dir/lib$lib.a"; then
116576bbdfcSmrg      found=yes
117576bbdfcSmrg      lib=$dir/lib$lib.a
118576bbdfcSmrg      break
119576bbdfcSmrg    fi
120576bbdfcSmrg  done
121576bbdfcSmrg  IFS=$save_IFS
122576bbdfcSmrg
123576bbdfcSmrg  if test "$found" != yes; then
124576bbdfcSmrg    lib=$lib.lib
125576bbdfcSmrg  fi
126576bbdfcSmrg}
127576bbdfcSmrg
128576bbdfcSmrg# func_cl_wrapper cl arg...
129576bbdfcSmrg# Adjust compile command to suit cl
130576bbdfcSmrgfunc_cl_wrapper ()
131576bbdfcSmrg{
132576bbdfcSmrg  # Assume a capable shell
133576bbdfcSmrg  lib_path=
134576bbdfcSmrg  shared=:
135576bbdfcSmrg  linker_opts=
136576bbdfcSmrg  for arg
137576bbdfcSmrg  do
138576bbdfcSmrg    if test -n "$eat"; then
139576bbdfcSmrg      eat=
140576bbdfcSmrg    else
141576bbdfcSmrg      case $1 in
142576bbdfcSmrg	-o)
143576bbdfcSmrg	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
144576bbdfcSmrg	  eat=1
145576bbdfcSmrg	  case $2 in
146576bbdfcSmrg	    *.o | *.[oO][bB][jJ])
147576bbdfcSmrg	      func_file_conv "$2"
148576bbdfcSmrg	      set x "$@" -Fo"$file"
149576bbdfcSmrg	      shift
150576bbdfcSmrg	      ;;
151576bbdfcSmrg	    *)
152576bbdfcSmrg	      func_file_conv "$2"
153576bbdfcSmrg	      set x "$@" -Fe"$file"
154576bbdfcSmrg	      shift
155576bbdfcSmrg	      ;;
156576bbdfcSmrg	  esac
157576bbdfcSmrg	  ;;
158576bbdfcSmrg	-I)
159576bbdfcSmrg	  eat=1
160576bbdfcSmrg	  func_file_conv "$2" mingw
161576bbdfcSmrg	  set x "$@" -I"$file"
162576bbdfcSmrg	  shift
163576bbdfcSmrg	  ;;
164576bbdfcSmrg	-I*)
165576bbdfcSmrg	  func_file_conv "${1#-I}" mingw
166576bbdfcSmrg	  set x "$@" -I"$file"
167576bbdfcSmrg	  shift
168576bbdfcSmrg	  ;;
169576bbdfcSmrg	-l)
170576bbdfcSmrg	  eat=1
171576bbdfcSmrg	  func_cl_dashl "$2"
172576bbdfcSmrg	  set x "$@" "$lib"
173576bbdfcSmrg	  shift
174576bbdfcSmrg	  ;;
175576bbdfcSmrg	-l*)
176576bbdfcSmrg	  func_cl_dashl "${1#-l}"
177576bbdfcSmrg	  set x "$@" "$lib"
178576bbdfcSmrg	  shift
179576bbdfcSmrg	  ;;
180576bbdfcSmrg	-L)
181576bbdfcSmrg	  eat=1
182576bbdfcSmrg	  func_cl_dashL "$2"
183576bbdfcSmrg	  ;;
184576bbdfcSmrg	-L*)
185576bbdfcSmrg	  func_cl_dashL "${1#-L}"
186576bbdfcSmrg	  ;;
187576bbdfcSmrg	-static)
188576bbdfcSmrg	  shared=false
189576bbdfcSmrg	  ;;
190576bbdfcSmrg	-Wl,*)
191576bbdfcSmrg	  arg=${1#-Wl,}
192576bbdfcSmrg	  save_ifs="$IFS"; IFS=','
193576bbdfcSmrg	  for flag in $arg; do
194576bbdfcSmrg	    IFS="$save_ifs"
195576bbdfcSmrg	    linker_opts="$linker_opts $flag"
196576bbdfcSmrg	  done
197576bbdfcSmrg	  IFS="$save_ifs"
198576bbdfcSmrg	  ;;
199576bbdfcSmrg	-Xlinker)
200576bbdfcSmrg	  eat=1
201576bbdfcSmrg	  linker_opts="$linker_opts $2"
202576bbdfcSmrg	  ;;
203576bbdfcSmrg	-*)
204576bbdfcSmrg	  set x "$@" "$1"
205576bbdfcSmrg	  shift
206576bbdfcSmrg	  ;;
207576bbdfcSmrg	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
208576bbdfcSmrg	  func_file_conv "$1"
209576bbdfcSmrg	  set x "$@" -Tp"$file"
210576bbdfcSmrg	  shift
211576bbdfcSmrg	  ;;
212576bbdfcSmrg	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
213576bbdfcSmrg	  func_file_conv "$1" mingw
214576bbdfcSmrg	  set x "$@" "$file"
215576bbdfcSmrg	  shift
216576bbdfcSmrg	  ;;
217576bbdfcSmrg	*)
218576bbdfcSmrg	  set x "$@" "$1"
219576bbdfcSmrg	  shift
220576bbdfcSmrg	  ;;
221576bbdfcSmrg      esac
222576bbdfcSmrg    fi
223576bbdfcSmrg    shift
224576bbdfcSmrg  done
225576bbdfcSmrg  if test -n "$linker_opts"; then
226576bbdfcSmrg    linker_opts="-link$linker_opts"
227576bbdfcSmrg  fi
228576bbdfcSmrg  exec "$@" $linker_opts
229576bbdfcSmrg  exit 1
230576bbdfcSmrg}
231576bbdfcSmrg
232576bbdfcSmrgeat=
233576bbdfcSmrg
234576bbdfcSmrgcase $1 in
235576bbdfcSmrg  '')
236576bbdfcSmrg     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
237576bbdfcSmrg     exit 1;
238576bbdfcSmrg     ;;
239576bbdfcSmrg  -h | --h*)
240576bbdfcSmrg    cat <<\EOF
241576bbdfcSmrgUsage: compile [--help] [--version] PROGRAM [ARGS]
242576bbdfcSmrg
243576bbdfcSmrgWrapper for compilers which do not understand '-c -o'.
244576bbdfcSmrgRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
245576bbdfcSmrgarguments, and rename the output as expected.
246576bbdfcSmrg
247576bbdfcSmrgIf you are trying to build a whole package this is not the
248576bbdfcSmrgright script to run: please start by reading the file 'INSTALL'.
249576bbdfcSmrg
250576bbdfcSmrgReport bugs to <bug-automake@gnu.org>.
251576bbdfcSmrgEOF
252576bbdfcSmrg    exit $?
253576bbdfcSmrg    ;;
254576bbdfcSmrg  -v | --v*)
255576bbdfcSmrg    echo "compile $scriptversion"
256576bbdfcSmrg    exit $?
257576bbdfcSmrg    ;;
258f9c28e31Smrg  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
259f9c28e31Smrg  icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
260576bbdfcSmrg    func_cl_wrapper "$@"      # Doesn't return...
261576bbdfcSmrg    ;;
262576bbdfcSmrgesac
263576bbdfcSmrg
264576bbdfcSmrgofile=
265576bbdfcSmrgcfile=
266576bbdfcSmrg
267576bbdfcSmrgfor arg
268576bbdfcSmrgdo
269576bbdfcSmrg  if test -n "$eat"; then
270576bbdfcSmrg    eat=
271576bbdfcSmrg  else
272576bbdfcSmrg    case $1 in
273576bbdfcSmrg      -o)
274576bbdfcSmrg	# configure might choose to run compile as 'compile cc -o foo foo.c'.
275576bbdfcSmrg	# So we strip '-o arg' only if arg is an object.
276576bbdfcSmrg	eat=1
277576bbdfcSmrg	case $2 in
278576bbdfcSmrg	  *.o | *.obj)
279576bbdfcSmrg	    ofile=$2
280576bbdfcSmrg	    ;;
281576bbdfcSmrg	  *)
282576bbdfcSmrg	    set x "$@" -o "$2"
283576bbdfcSmrg	    shift
284576bbdfcSmrg	    ;;
285576bbdfcSmrg	esac
286576bbdfcSmrg	;;
287576bbdfcSmrg      *.c)
288576bbdfcSmrg	cfile=$1
289576bbdfcSmrg	set x "$@" "$1"
290576bbdfcSmrg	shift
291576bbdfcSmrg	;;
292576bbdfcSmrg      *)
293576bbdfcSmrg	set x "$@" "$1"
294576bbdfcSmrg	shift
295576bbdfcSmrg	;;
296576bbdfcSmrg    esac
297576bbdfcSmrg  fi
298576bbdfcSmrg  shift
299576bbdfcSmrgdone
300576bbdfcSmrg
301576bbdfcSmrgif test -z "$ofile" || test -z "$cfile"; then
302576bbdfcSmrg  # If no '-o' option was seen then we might have been invoked from a
303576bbdfcSmrg  # pattern rule where we don't need one.  That is ok -- this is a
304576bbdfcSmrg  # normal compilation that the losing compiler can handle.  If no
305576bbdfcSmrg  # '.c' file was seen then we are probably linking.  That is also
306576bbdfcSmrg  # ok.
307576bbdfcSmrg  exec "$@"
308576bbdfcSmrgfi
309576bbdfcSmrg
310576bbdfcSmrg# Name of file we expect compiler to create.
311576bbdfcSmrgcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
312576bbdfcSmrg
313576bbdfcSmrg# Create the lock directory.
314576bbdfcSmrg# Note: use '[/\\:.-]' here to ensure that we don't use the same name
315576bbdfcSmrg# that we are using for the .o file.  Also, base the name on the expected
316576bbdfcSmrg# object file name, since that is what matters with a parallel build.
317576bbdfcSmrglockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
318576bbdfcSmrgwhile true; do
319576bbdfcSmrg  if mkdir "$lockdir" >/dev/null 2>&1; then
320576bbdfcSmrg    break
321576bbdfcSmrg  fi
322576bbdfcSmrg  sleep 1
323576bbdfcSmrgdone
324576bbdfcSmrg# FIXME: race condition here if user kills between mkdir and trap.
325576bbdfcSmrgtrap "rmdir '$lockdir'; exit 1" 1 2 15
326576bbdfcSmrg
327576bbdfcSmrg# Run the compile.
328576bbdfcSmrg"$@"
329576bbdfcSmrgret=$?
330576bbdfcSmrg
331576bbdfcSmrgif test -f "$cofile"; then
332576bbdfcSmrg  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
333576bbdfcSmrgelif test -f "${cofile}bj"; then
334576bbdfcSmrg  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
335576bbdfcSmrgfi
336576bbdfcSmrg
337576bbdfcSmrgrmdir "$lockdir"
338576bbdfcSmrgexit $ret
339576bbdfcSmrg
340576bbdfcSmrg# Local Variables:
341576bbdfcSmrg# mode: shell-script
342576bbdfcSmrg# sh-indentation: 2
343f9c28e31Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
344576bbdfcSmrg# time-stamp-start: "scriptversion="
345576bbdfcSmrg# time-stamp-format: "%:y-%02m-%02d.%02H"
346f9c28e31Smrg# time-stamp-time-zone: "UTC0"
347576bbdfcSmrg# time-stamp-end: "; # UTC"
348576bbdfcSmrg# End:
349