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