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