xref: /netbsd-src/external/bsd/ntp/dist/sntp/libevent/build-aux/compile (revision 3e3909fe3ffe5d33a1ab87329085041d20fd552e)
18585484eSchristos#! /bin/sh
2*3e3909feSchristos# Wrapper for compilers which do not understand '-c -o'.
38585484eSchristos
4*3e3909feSchristosscriptversion=2012-10-14.11; # UTC
58585484eSchristos
6*3e3909feSchristos# Copyright (C) 1999-2014 Free Software Foundation, Inc.
78585484eSchristos# Written by Tom Tromey <tromey@cygnus.com>.
88585484eSchristos#
98585484eSchristos# This program is free software; you can redistribute it and/or modify
108585484eSchristos# it under the terms of the GNU General Public License as published by
118585484eSchristos# the Free Software Foundation; either version 2, or (at your option)
128585484eSchristos# any later version.
138585484eSchristos#
148585484eSchristos# This program is distributed in the hope that it will be useful,
158585484eSchristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
168585484eSchristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
178585484eSchristos# GNU General Public License for more details.
188585484eSchristos#
198585484eSchristos# You should have received a copy of the GNU General Public License
208585484eSchristos# along with this program.  If not, see <http://www.gnu.org/licenses/>.
218585484eSchristos
228585484eSchristos# As a special exception to the GNU General Public License, if you
238585484eSchristos# distribute this file as part of a program that contains a
248585484eSchristos# configuration script generated by Autoconf, you may include it under
258585484eSchristos# the same distribution terms that you use for the rest of that program.
268585484eSchristos
278585484eSchristos# This file is maintained in Automake, please report
288585484eSchristos# bugs to <bug-automake@gnu.org> or send patches to
298585484eSchristos# <automake-patches@gnu.org>.
308585484eSchristos
31*3e3909feSchristosnl='
32*3e3909feSchristos'
33*3e3909feSchristos
34*3e3909feSchristos# We need space, tab and new line, in precisely that order.  Quoting is
35*3e3909feSchristos# there to prevent tools from complaining about whitespace usage.
36*3e3909feSchristosIFS=" ""	$nl"
37*3e3909feSchristos
38*3e3909feSchristosfile_conv=
39*3e3909feSchristos
40*3e3909feSchristos# func_file_conv build_file lazy
41*3e3909feSchristos# Convert a $build file to $host form and store it in $file
42*3e3909feSchristos# Currently only supports Windows hosts. If the determined conversion
43*3e3909feSchristos# type is listed in (the comma separated) LAZY, no conversion will
44*3e3909feSchristos# take place.
45*3e3909feSchristosfunc_file_conv ()
46*3e3909feSchristos{
47*3e3909feSchristos  file=$1
48*3e3909feSchristos  case $file in
49*3e3909feSchristos    / | /[!/]*) # absolute file, and not a UNC file
50*3e3909feSchristos      if test -z "$file_conv"; then
51*3e3909feSchristos	# lazily determine how to convert abs files
52*3e3909feSchristos	case `uname -s` in
53*3e3909feSchristos	  MINGW*)
54*3e3909feSchristos	    file_conv=mingw
55*3e3909feSchristos	    ;;
56*3e3909feSchristos	  CYGWIN*)
57*3e3909feSchristos	    file_conv=cygwin
58*3e3909feSchristos	    ;;
59*3e3909feSchristos	  *)
60*3e3909feSchristos	    file_conv=wine
61*3e3909feSchristos	    ;;
62*3e3909feSchristos	esac
63*3e3909feSchristos      fi
64*3e3909feSchristos      case $file_conv/,$2, in
65*3e3909feSchristos	*,$file_conv,*)
66*3e3909feSchristos	  ;;
67*3e3909feSchristos	mingw/*)
68*3e3909feSchristos	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
69*3e3909feSchristos	  ;;
70*3e3909feSchristos	cygwin/*)
71*3e3909feSchristos	  file=`cygpath -m "$file" || echo "$file"`
72*3e3909feSchristos	  ;;
73*3e3909feSchristos	wine/*)
74*3e3909feSchristos	  file=`winepath -w "$file" || echo "$file"`
75*3e3909feSchristos	  ;;
76*3e3909feSchristos      esac
77*3e3909feSchristos      ;;
78*3e3909feSchristos  esac
79*3e3909feSchristos}
80*3e3909feSchristos
81*3e3909feSchristos# func_cl_dashL linkdir
82*3e3909feSchristos# Make cl look for libraries in LINKDIR
83*3e3909feSchristosfunc_cl_dashL ()
84*3e3909feSchristos{
85*3e3909feSchristos  func_file_conv "$1"
86*3e3909feSchristos  if test -z "$lib_path"; then
87*3e3909feSchristos    lib_path=$file
88*3e3909feSchristos  else
89*3e3909feSchristos    lib_path="$lib_path;$file"
90*3e3909feSchristos  fi
91*3e3909feSchristos  linker_opts="$linker_opts -LIBPATH:$file"
92*3e3909feSchristos}
93*3e3909feSchristos
94*3e3909feSchristos# func_cl_dashl library
95*3e3909feSchristos# Do a library search-path lookup for cl
96*3e3909feSchristosfunc_cl_dashl ()
97*3e3909feSchristos{
98*3e3909feSchristos  lib=$1
99*3e3909feSchristos  found=no
100*3e3909feSchristos  save_IFS=$IFS
101*3e3909feSchristos  IFS=';'
102*3e3909feSchristos  for dir in $lib_path $LIB
103*3e3909feSchristos  do
104*3e3909feSchristos    IFS=$save_IFS
105*3e3909feSchristos    if $shared && test -f "$dir/$lib.dll.lib"; then
106*3e3909feSchristos      found=yes
107*3e3909feSchristos      lib=$dir/$lib.dll.lib
108*3e3909feSchristos      break
109*3e3909feSchristos    fi
110*3e3909feSchristos    if test -f "$dir/$lib.lib"; then
111*3e3909feSchristos      found=yes
112*3e3909feSchristos      lib=$dir/$lib.lib
113*3e3909feSchristos      break
114*3e3909feSchristos    fi
115*3e3909feSchristos    if test -f "$dir/lib$lib.a"; then
116*3e3909feSchristos      found=yes
117*3e3909feSchristos      lib=$dir/lib$lib.a
118*3e3909feSchristos      break
119*3e3909feSchristos    fi
120*3e3909feSchristos  done
121*3e3909feSchristos  IFS=$save_IFS
122*3e3909feSchristos
123*3e3909feSchristos  if test "$found" != yes; then
124*3e3909feSchristos    lib=$lib.lib
125*3e3909feSchristos  fi
126*3e3909feSchristos}
127*3e3909feSchristos
128*3e3909feSchristos# func_cl_wrapper cl arg...
129*3e3909feSchristos# Adjust compile command to suit cl
130*3e3909feSchristosfunc_cl_wrapper ()
131*3e3909feSchristos{
132*3e3909feSchristos  # Assume a capable shell
133*3e3909feSchristos  lib_path=
134*3e3909feSchristos  shared=:
135*3e3909feSchristos  linker_opts=
136*3e3909feSchristos  for arg
137*3e3909feSchristos  do
138*3e3909feSchristos    if test -n "$eat"; then
139*3e3909feSchristos      eat=
140*3e3909feSchristos    else
141*3e3909feSchristos      case $1 in
142*3e3909feSchristos	-o)
143*3e3909feSchristos	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
144*3e3909feSchristos	  eat=1
145*3e3909feSchristos	  case $2 in
146*3e3909feSchristos	    *.o | *.[oO][bB][jJ])
147*3e3909feSchristos	      func_file_conv "$2"
148*3e3909feSchristos	      set x "$@" -Fo"$file"
149*3e3909feSchristos	      shift
150*3e3909feSchristos	      ;;
151*3e3909feSchristos	    *)
152*3e3909feSchristos	      func_file_conv "$2"
153*3e3909feSchristos	      set x "$@" -Fe"$file"
154*3e3909feSchristos	      shift
155*3e3909feSchristos	      ;;
156*3e3909feSchristos	  esac
157*3e3909feSchristos	  ;;
158*3e3909feSchristos	-I)
159*3e3909feSchristos	  eat=1
160*3e3909feSchristos	  func_file_conv "$2" mingw
161*3e3909feSchristos	  set x "$@" -I"$file"
162*3e3909feSchristos	  shift
163*3e3909feSchristos	  ;;
164*3e3909feSchristos	-I*)
165*3e3909feSchristos	  func_file_conv "${1#-I}" mingw
166*3e3909feSchristos	  set x "$@" -I"$file"
167*3e3909feSchristos	  shift
168*3e3909feSchristos	  ;;
169*3e3909feSchristos	-l)
170*3e3909feSchristos	  eat=1
171*3e3909feSchristos	  func_cl_dashl "$2"
172*3e3909feSchristos	  set x "$@" "$lib"
173*3e3909feSchristos	  shift
174*3e3909feSchristos	  ;;
175*3e3909feSchristos	-l*)
176*3e3909feSchristos	  func_cl_dashl "${1#-l}"
177*3e3909feSchristos	  set x "$@" "$lib"
178*3e3909feSchristos	  shift
179*3e3909feSchristos	  ;;
180*3e3909feSchristos	-L)
181*3e3909feSchristos	  eat=1
182*3e3909feSchristos	  func_cl_dashL "$2"
183*3e3909feSchristos	  ;;
184*3e3909feSchristos	-L*)
185*3e3909feSchristos	  func_cl_dashL "${1#-L}"
186*3e3909feSchristos	  ;;
187*3e3909feSchristos	-static)
188*3e3909feSchristos	  shared=false
189*3e3909feSchristos	  ;;
190*3e3909feSchristos	-Wl,*)
191*3e3909feSchristos	  arg=${1#-Wl,}
192*3e3909feSchristos	  save_ifs="$IFS"; IFS=','
193*3e3909feSchristos	  for flag in $arg; do
194*3e3909feSchristos	    IFS="$save_ifs"
195*3e3909feSchristos	    linker_opts="$linker_opts $flag"
196*3e3909feSchristos	  done
197*3e3909feSchristos	  IFS="$save_ifs"
198*3e3909feSchristos	  ;;
199*3e3909feSchristos	-Xlinker)
200*3e3909feSchristos	  eat=1
201*3e3909feSchristos	  linker_opts="$linker_opts $2"
202*3e3909feSchristos	  ;;
203*3e3909feSchristos	-*)
204*3e3909feSchristos	  set x "$@" "$1"
205*3e3909feSchristos	  shift
206*3e3909feSchristos	  ;;
207*3e3909feSchristos	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
208*3e3909feSchristos	  func_file_conv "$1"
209*3e3909feSchristos	  set x "$@" -Tp"$file"
210*3e3909feSchristos	  shift
211*3e3909feSchristos	  ;;
212*3e3909feSchristos	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
213*3e3909feSchristos	  func_file_conv "$1" mingw
214*3e3909feSchristos	  set x "$@" "$file"
215*3e3909feSchristos	  shift
216*3e3909feSchristos	  ;;
217*3e3909feSchristos	*)
218*3e3909feSchristos	  set x "$@" "$1"
219*3e3909feSchristos	  shift
220*3e3909feSchristos	  ;;
221*3e3909feSchristos      esac
222*3e3909feSchristos    fi
223*3e3909feSchristos    shift
224*3e3909feSchristos  done
225*3e3909feSchristos  if test -n "$linker_opts"; then
226*3e3909feSchristos    linker_opts="-link$linker_opts"
227*3e3909feSchristos  fi
228*3e3909feSchristos  exec "$@" $linker_opts
229*3e3909feSchristos  exit 1
230*3e3909feSchristos}
231*3e3909feSchristos
232*3e3909feSchristoseat=
233*3e3909feSchristos
2348585484eSchristoscase $1 in
2358585484eSchristos  '')
236*3e3909feSchristos     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
2378585484eSchristos     exit 1;
2388585484eSchristos     ;;
2398585484eSchristos  -h | --h*)
2408585484eSchristos    cat <<\EOF
2418585484eSchristosUsage: compile [--help] [--version] PROGRAM [ARGS]
2428585484eSchristos
243*3e3909feSchristosWrapper for compilers which do not understand '-c -o'.
244*3e3909feSchristosRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
2458585484eSchristosarguments, and rename the output as expected.
2468585484eSchristos
2478585484eSchristosIf you are trying to build a whole package this is not the
248*3e3909feSchristosright script to run: please start by reading the file 'INSTALL'.
2498585484eSchristos
2508585484eSchristosReport bugs to <bug-automake@gnu.org>.
2518585484eSchristosEOF
2528585484eSchristos    exit $?
2538585484eSchristos    ;;
2548585484eSchristos  -v | --v*)
2558585484eSchristos    echo "compile $scriptversion"
2568585484eSchristos    exit $?
2578585484eSchristos    ;;
258*3e3909feSchristos  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
259*3e3909feSchristos    func_cl_wrapper "$@"      # Doesn't return...
260*3e3909feSchristos    ;;
2618585484eSchristosesac
2628585484eSchristos
2638585484eSchristosofile=
2648585484eSchristoscfile=
2658585484eSchristos
2668585484eSchristosfor arg
2678585484eSchristosdo
2688585484eSchristos  if test -n "$eat"; then
2698585484eSchristos    eat=
2708585484eSchristos  else
2718585484eSchristos    case $1 in
2728585484eSchristos      -o)
273*3e3909feSchristos	# configure might choose to run compile as 'compile cc -o foo foo.c'.
274*3e3909feSchristos	# So we strip '-o arg' only if arg is an object.
2758585484eSchristos	eat=1
2768585484eSchristos	case $2 in
2778585484eSchristos	  *.o | *.obj)
2788585484eSchristos	    ofile=$2
2798585484eSchristos	    ;;
2808585484eSchristos	  *)
2818585484eSchristos	    set x "$@" -o "$2"
2828585484eSchristos	    shift
2838585484eSchristos	    ;;
2848585484eSchristos	esac
2858585484eSchristos	;;
2868585484eSchristos      *.c)
2878585484eSchristos	cfile=$1
2888585484eSchristos	set x "$@" "$1"
2898585484eSchristos	shift
2908585484eSchristos	;;
2918585484eSchristos      *)
2928585484eSchristos	set x "$@" "$1"
2938585484eSchristos	shift
2948585484eSchristos	;;
2958585484eSchristos    esac
2968585484eSchristos  fi
2978585484eSchristos  shift
2988585484eSchristosdone
2998585484eSchristos
3008585484eSchristosif test -z "$ofile" || test -z "$cfile"; then
301*3e3909feSchristos  # If no '-o' option was seen then we might have been invoked from a
3028585484eSchristos  # pattern rule where we don't need one.  That is ok -- this is a
3038585484eSchristos  # normal compilation that the losing compiler can handle.  If no
304*3e3909feSchristos  # '.c' file was seen then we are probably linking.  That is also
3058585484eSchristos  # ok.
3068585484eSchristos  exec "$@"
3078585484eSchristosfi
3088585484eSchristos
3098585484eSchristos# Name of file we expect compiler to create.
3108585484eSchristoscofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
3118585484eSchristos
3128585484eSchristos# Create the lock directory.
313*3e3909feSchristos# Note: use '[/\\:.-]' here to ensure that we don't use the same name
3148585484eSchristos# that we are using for the .o file.  Also, base the name on the expected
3158585484eSchristos# object file name, since that is what matters with a parallel build.
3168585484eSchristoslockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
3178585484eSchristoswhile true; do
3188585484eSchristos  if mkdir "$lockdir" >/dev/null 2>&1; then
3198585484eSchristos    break
3208585484eSchristos  fi
3218585484eSchristos  sleep 1
3228585484eSchristosdone
3238585484eSchristos# FIXME: race condition here if user kills between mkdir and trap.
3248585484eSchristostrap "rmdir '$lockdir'; exit 1" 1 2 15
3258585484eSchristos
3268585484eSchristos# Run the compile.
3278585484eSchristos"$@"
3288585484eSchristosret=$?
3298585484eSchristos
3308585484eSchristosif test -f "$cofile"; then
3318585484eSchristos  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
3328585484eSchristoselif test -f "${cofile}bj"; then
3338585484eSchristos  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
3348585484eSchristosfi
3358585484eSchristos
3368585484eSchristosrmdir "$lockdir"
3378585484eSchristosexit $ret
3388585484eSchristos
3398585484eSchristos# Local Variables:
3408585484eSchristos# mode: shell-script
3418585484eSchristos# sh-indentation: 2
3428585484eSchristos# eval: (add-hook 'write-file-hooks 'time-stamp)
3438585484eSchristos# time-stamp-start: "scriptversion="
3448585484eSchristos# time-stamp-format: "%:y-%02m-%02d.%02H"
3458585484eSchristos# time-stamp-time-zone: "UTC"
3468585484eSchristos# time-stamp-end: "; # UTC"
3478585484eSchristos# End:
348