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