xref: /freebsd/contrib/ntp/sntp/libevent/build-aux/compile (revision f0574f5cf69e168cc4ea71ebbe5fdec9ec9a3dfe)
12b15cb3dSCy Schubert#! /bin/sh
2*f0574f5cSXin LI# Wrapper for compilers which do not understand '-c -o'.
32b15cb3dSCy Schubert
4*f0574f5cSXin LIscriptversion=2012-10-14.11; # UTC
52b15cb3dSCy Schubert
6*f0574f5cSXin LI# Copyright (C) 1999-2014 Free Software Foundation, Inc.
72b15cb3dSCy Schubert# Written by Tom Tromey <tromey@cygnus.com>.
82b15cb3dSCy Schubert#
92b15cb3dSCy Schubert# This program is free software; you can redistribute it and/or modify
102b15cb3dSCy Schubert# it under the terms of the GNU General Public License as published by
112b15cb3dSCy Schubert# the Free Software Foundation; either version 2, or (at your option)
122b15cb3dSCy Schubert# any later version.
132b15cb3dSCy Schubert#
142b15cb3dSCy Schubert# This program is distributed in the hope that it will be useful,
152b15cb3dSCy Schubert# but WITHOUT ANY WARRANTY; without even the implied warranty of
162b15cb3dSCy Schubert# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
172b15cb3dSCy Schubert# GNU General Public License for more details.
182b15cb3dSCy Schubert#
192b15cb3dSCy Schubert# You should have received a copy of the GNU General Public License
202b15cb3dSCy Schubert# along with this program.  If not, see <http://www.gnu.org/licenses/>.
212b15cb3dSCy Schubert
222b15cb3dSCy Schubert# As a special exception to the GNU General Public License, if you
232b15cb3dSCy Schubert# distribute this file as part of a program that contains a
242b15cb3dSCy Schubert# configuration script generated by Autoconf, you may include it under
252b15cb3dSCy Schubert# the same distribution terms that you use for the rest of that program.
262b15cb3dSCy Schubert
272b15cb3dSCy Schubert# This file is maintained in Automake, please report
282b15cb3dSCy Schubert# bugs to <bug-automake@gnu.org> or send patches to
292b15cb3dSCy Schubert# <automake-patches@gnu.org>.
302b15cb3dSCy Schubert
31*f0574f5cSXin LInl='
32*f0574f5cSXin LI'
33*f0574f5cSXin LI
34*f0574f5cSXin LI# We need space, tab and new line, in precisely that order.  Quoting is
35*f0574f5cSXin LI# there to prevent tools from complaining about whitespace usage.
36*f0574f5cSXin LIIFS=" ""	$nl"
37*f0574f5cSXin LI
38*f0574f5cSXin LIfile_conv=
39*f0574f5cSXin LI
40*f0574f5cSXin LI# func_file_conv build_file lazy
41*f0574f5cSXin LI# Convert a $build file to $host form and store it in $file
42*f0574f5cSXin LI# Currently only supports Windows hosts. If the determined conversion
43*f0574f5cSXin LI# type is listed in (the comma separated) LAZY, no conversion will
44*f0574f5cSXin LI# take place.
45*f0574f5cSXin LIfunc_file_conv ()
46*f0574f5cSXin LI{
47*f0574f5cSXin LI  file=$1
48*f0574f5cSXin LI  case $file in
49*f0574f5cSXin LI    / | /[!/]*) # absolute file, and not a UNC file
50*f0574f5cSXin LI      if test -z "$file_conv"; then
51*f0574f5cSXin LI	# lazily determine how to convert abs files
52*f0574f5cSXin LI	case `uname -s` in
53*f0574f5cSXin LI	  MINGW*)
54*f0574f5cSXin LI	    file_conv=mingw
55*f0574f5cSXin LI	    ;;
56*f0574f5cSXin LI	  CYGWIN*)
57*f0574f5cSXin LI	    file_conv=cygwin
58*f0574f5cSXin LI	    ;;
59*f0574f5cSXin LI	  *)
60*f0574f5cSXin LI	    file_conv=wine
61*f0574f5cSXin LI	    ;;
62*f0574f5cSXin LI	esac
63*f0574f5cSXin LI      fi
64*f0574f5cSXin LI      case $file_conv/,$2, in
65*f0574f5cSXin LI	*,$file_conv,*)
66*f0574f5cSXin LI	  ;;
67*f0574f5cSXin LI	mingw/*)
68*f0574f5cSXin LI	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
69*f0574f5cSXin LI	  ;;
70*f0574f5cSXin LI	cygwin/*)
71*f0574f5cSXin LI	  file=`cygpath -m "$file" || echo "$file"`
72*f0574f5cSXin LI	  ;;
73*f0574f5cSXin LI	wine/*)
74*f0574f5cSXin LI	  file=`winepath -w "$file" || echo "$file"`
75*f0574f5cSXin LI	  ;;
76*f0574f5cSXin LI      esac
77*f0574f5cSXin LI      ;;
78*f0574f5cSXin LI  esac
79*f0574f5cSXin LI}
80*f0574f5cSXin LI
81*f0574f5cSXin LI# func_cl_dashL linkdir
82*f0574f5cSXin LI# Make cl look for libraries in LINKDIR
83*f0574f5cSXin LIfunc_cl_dashL ()
84*f0574f5cSXin LI{
85*f0574f5cSXin LI  func_file_conv "$1"
86*f0574f5cSXin LI  if test -z "$lib_path"; then
87*f0574f5cSXin LI    lib_path=$file
88*f0574f5cSXin LI  else
89*f0574f5cSXin LI    lib_path="$lib_path;$file"
90*f0574f5cSXin LI  fi
91*f0574f5cSXin LI  linker_opts="$linker_opts -LIBPATH:$file"
92*f0574f5cSXin LI}
93*f0574f5cSXin LI
94*f0574f5cSXin LI# func_cl_dashl library
95*f0574f5cSXin LI# Do a library search-path lookup for cl
96*f0574f5cSXin LIfunc_cl_dashl ()
97*f0574f5cSXin LI{
98*f0574f5cSXin LI  lib=$1
99*f0574f5cSXin LI  found=no
100*f0574f5cSXin LI  save_IFS=$IFS
101*f0574f5cSXin LI  IFS=';'
102*f0574f5cSXin LI  for dir in $lib_path $LIB
103*f0574f5cSXin LI  do
104*f0574f5cSXin LI    IFS=$save_IFS
105*f0574f5cSXin LI    if $shared && test -f "$dir/$lib.dll.lib"; then
106*f0574f5cSXin LI      found=yes
107*f0574f5cSXin LI      lib=$dir/$lib.dll.lib
108*f0574f5cSXin LI      break
109*f0574f5cSXin LI    fi
110*f0574f5cSXin LI    if test -f "$dir/$lib.lib"; then
111*f0574f5cSXin LI      found=yes
112*f0574f5cSXin LI      lib=$dir/$lib.lib
113*f0574f5cSXin LI      break
114*f0574f5cSXin LI    fi
115*f0574f5cSXin LI    if test -f "$dir/lib$lib.a"; then
116*f0574f5cSXin LI      found=yes
117*f0574f5cSXin LI      lib=$dir/lib$lib.a
118*f0574f5cSXin LI      break
119*f0574f5cSXin LI    fi
120*f0574f5cSXin LI  done
121*f0574f5cSXin LI  IFS=$save_IFS
122*f0574f5cSXin LI
123*f0574f5cSXin LI  if test "$found" != yes; then
124*f0574f5cSXin LI    lib=$lib.lib
125*f0574f5cSXin LI  fi
126*f0574f5cSXin LI}
127*f0574f5cSXin LI
128*f0574f5cSXin LI# func_cl_wrapper cl arg...
129*f0574f5cSXin LI# Adjust compile command to suit cl
130*f0574f5cSXin LIfunc_cl_wrapper ()
131*f0574f5cSXin LI{
132*f0574f5cSXin LI  # Assume a capable shell
133*f0574f5cSXin LI  lib_path=
134*f0574f5cSXin LI  shared=:
135*f0574f5cSXin LI  linker_opts=
136*f0574f5cSXin LI  for arg
137*f0574f5cSXin LI  do
138*f0574f5cSXin LI    if test -n "$eat"; then
139*f0574f5cSXin LI      eat=
140*f0574f5cSXin LI    else
141*f0574f5cSXin LI      case $1 in
142*f0574f5cSXin LI	-o)
143*f0574f5cSXin LI	  # configure might choose to run compile as 'compile cc -o foo foo.c'.
144*f0574f5cSXin LI	  eat=1
145*f0574f5cSXin LI	  case $2 in
146*f0574f5cSXin LI	    *.o | *.[oO][bB][jJ])
147*f0574f5cSXin LI	      func_file_conv "$2"
148*f0574f5cSXin LI	      set x "$@" -Fo"$file"
149*f0574f5cSXin LI	      shift
150*f0574f5cSXin LI	      ;;
151*f0574f5cSXin LI	    *)
152*f0574f5cSXin LI	      func_file_conv "$2"
153*f0574f5cSXin LI	      set x "$@" -Fe"$file"
154*f0574f5cSXin LI	      shift
155*f0574f5cSXin LI	      ;;
156*f0574f5cSXin LI	  esac
157*f0574f5cSXin LI	  ;;
158*f0574f5cSXin LI	-I)
159*f0574f5cSXin LI	  eat=1
160*f0574f5cSXin LI	  func_file_conv "$2" mingw
161*f0574f5cSXin LI	  set x "$@" -I"$file"
162*f0574f5cSXin LI	  shift
163*f0574f5cSXin LI	  ;;
164*f0574f5cSXin LI	-I*)
165*f0574f5cSXin LI	  func_file_conv "${1#-I}" mingw
166*f0574f5cSXin LI	  set x "$@" -I"$file"
167*f0574f5cSXin LI	  shift
168*f0574f5cSXin LI	  ;;
169*f0574f5cSXin LI	-l)
170*f0574f5cSXin LI	  eat=1
171*f0574f5cSXin LI	  func_cl_dashl "$2"
172*f0574f5cSXin LI	  set x "$@" "$lib"
173*f0574f5cSXin LI	  shift
174*f0574f5cSXin LI	  ;;
175*f0574f5cSXin LI	-l*)
176*f0574f5cSXin LI	  func_cl_dashl "${1#-l}"
177*f0574f5cSXin LI	  set x "$@" "$lib"
178*f0574f5cSXin LI	  shift
179*f0574f5cSXin LI	  ;;
180*f0574f5cSXin LI	-L)
181*f0574f5cSXin LI	  eat=1
182*f0574f5cSXin LI	  func_cl_dashL "$2"
183*f0574f5cSXin LI	  ;;
184*f0574f5cSXin LI	-L*)
185*f0574f5cSXin LI	  func_cl_dashL "${1#-L}"
186*f0574f5cSXin LI	  ;;
187*f0574f5cSXin LI	-static)
188*f0574f5cSXin LI	  shared=false
189*f0574f5cSXin LI	  ;;
190*f0574f5cSXin LI	-Wl,*)
191*f0574f5cSXin LI	  arg=${1#-Wl,}
192*f0574f5cSXin LI	  save_ifs="$IFS"; IFS=','
193*f0574f5cSXin LI	  for flag in $arg; do
194*f0574f5cSXin LI	    IFS="$save_ifs"
195*f0574f5cSXin LI	    linker_opts="$linker_opts $flag"
196*f0574f5cSXin LI	  done
197*f0574f5cSXin LI	  IFS="$save_ifs"
198*f0574f5cSXin LI	  ;;
199*f0574f5cSXin LI	-Xlinker)
200*f0574f5cSXin LI	  eat=1
201*f0574f5cSXin LI	  linker_opts="$linker_opts $2"
202*f0574f5cSXin LI	  ;;
203*f0574f5cSXin LI	-*)
204*f0574f5cSXin LI	  set x "$@" "$1"
205*f0574f5cSXin LI	  shift
206*f0574f5cSXin LI	  ;;
207*f0574f5cSXin LI	*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
208*f0574f5cSXin LI	  func_file_conv "$1"
209*f0574f5cSXin LI	  set x "$@" -Tp"$file"
210*f0574f5cSXin LI	  shift
211*f0574f5cSXin LI	  ;;
212*f0574f5cSXin LI	*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
213*f0574f5cSXin LI	  func_file_conv "$1" mingw
214*f0574f5cSXin LI	  set x "$@" "$file"
215*f0574f5cSXin LI	  shift
216*f0574f5cSXin LI	  ;;
217*f0574f5cSXin LI	*)
218*f0574f5cSXin LI	  set x "$@" "$1"
219*f0574f5cSXin LI	  shift
220*f0574f5cSXin LI	  ;;
221*f0574f5cSXin LI      esac
222*f0574f5cSXin LI    fi
223*f0574f5cSXin LI    shift
224*f0574f5cSXin LI  done
225*f0574f5cSXin LI  if test -n "$linker_opts"; then
226*f0574f5cSXin LI    linker_opts="-link$linker_opts"
227*f0574f5cSXin LI  fi
228*f0574f5cSXin LI  exec "$@" $linker_opts
229*f0574f5cSXin LI  exit 1
230*f0574f5cSXin LI}
231*f0574f5cSXin LI
232*f0574f5cSXin LIeat=
233*f0574f5cSXin LI
2342b15cb3dSCy Schubertcase $1 in
2352b15cb3dSCy Schubert  '')
236*f0574f5cSXin LI     echo "$0: No command.  Try '$0 --help' for more information." 1>&2
2372b15cb3dSCy Schubert     exit 1;
2382b15cb3dSCy Schubert     ;;
2392b15cb3dSCy Schubert  -h | --h*)
2402b15cb3dSCy Schubert    cat <<\EOF
2412b15cb3dSCy SchubertUsage: compile [--help] [--version] PROGRAM [ARGS]
2422b15cb3dSCy Schubert
243*f0574f5cSXin LIWrapper for compilers which do not understand '-c -o'.
244*f0574f5cSXin LIRemove '-o dest.o' from ARGS, run PROGRAM with the remaining
2452b15cb3dSCy Schubertarguments, and rename the output as expected.
2462b15cb3dSCy Schubert
2472b15cb3dSCy SchubertIf you are trying to build a whole package this is not the
248*f0574f5cSXin LIright script to run: please start by reading the file 'INSTALL'.
2492b15cb3dSCy Schubert
2502b15cb3dSCy SchubertReport bugs to <bug-automake@gnu.org>.
2512b15cb3dSCy SchubertEOF
2522b15cb3dSCy Schubert    exit $?
2532b15cb3dSCy Schubert    ;;
2542b15cb3dSCy Schubert  -v | --v*)
2552b15cb3dSCy Schubert    echo "compile $scriptversion"
2562b15cb3dSCy Schubert    exit $?
2572b15cb3dSCy Schubert    ;;
258*f0574f5cSXin LI  cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
259*f0574f5cSXin LI    func_cl_wrapper "$@"      # Doesn't return...
260*f0574f5cSXin LI    ;;
2612b15cb3dSCy Schubertesac
2622b15cb3dSCy Schubert
2632b15cb3dSCy Schubertofile=
2642b15cb3dSCy Schubertcfile=
2652b15cb3dSCy Schubert
2662b15cb3dSCy Schubertfor arg
2672b15cb3dSCy Schubertdo
2682b15cb3dSCy Schubert  if test -n "$eat"; then
2692b15cb3dSCy Schubert    eat=
2702b15cb3dSCy Schubert  else
2712b15cb3dSCy Schubert    case $1 in
2722b15cb3dSCy Schubert      -o)
273*f0574f5cSXin LI	# configure might choose to run compile as 'compile cc -o foo foo.c'.
274*f0574f5cSXin LI	# So we strip '-o arg' only if arg is an object.
2752b15cb3dSCy Schubert	eat=1
2762b15cb3dSCy Schubert	case $2 in
2772b15cb3dSCy Schubert	  *.o | *.obj)
2782b15cb3dSCy Schubert	    ofile=$2
2792b15cb3dSCy Schubert	    ;;
2802b15cb3dSCy Schubert	  *)
2812b15cb3dSCy Schubert	    set x "$@" -o "$2"
2822b15cb3dSCy Schubert	    shift
2832b15cb3dSCy Schubert	    ;;
2842b15cb3dSCy Schubert	esac
2852b15cb3dSCy Schubert	;;
2862b15cb3dSCy Schubert      *.c)
2872b15cb3dSCy Schubert	cfile=$1
2882b15cb3dSCy Schubert	set x "$@" "$1"
2892b15cb3dSCy Schubert	shift
2902b15cb3dSCy Schubert	;;
2912b15cb3dSCy Schubert      *)
2922b15cb3dSCy Schubert	set x "$@" "$1"
2932b15cb3dSCy Schubert	shift
2942b15cb3dSCy Schubert	;;
2952b15cb3dSCy Schubert    esac
2962b15cb3dSCy Schubert  fi
2972b15cb3dSCy Schubert  shift
2982b15cb3dSCy Schubertdone
2992b15cb3dSCy Schubert
3002b15cb3dSCy Schubertif test -z "$ofile" || test -z "$cfile"; then
301*f0574f5cSXin LI  # If no '-o' option was seen then we might have been invoked from a
3022b15cb3dSCy Schubert  # pattern rule where we don't need one.  That is ok -- this is a
3032b15cb3dSCy Schubert  # normal compilation that the losing compiler can handle.  If no
304*f0574f5cSXin LI  # '.c' file was seen then we are probably linking.  That is also
3052b15cb3dSCy Schubert  # ok.
3062b15cb3dSCy Schubert  exec "$@"
3072b15cb3dSCy Schubertfi
3082b15cb3dSCy Schubert
3092b15cb3dSCy Schubert# Name of file we expect compiler to create.
3102b15cb3dSCy Schubertcofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
3112b15cb3dSCy Schubert
3122b15cb3dSCy Schubert# Create the lock directory.
313*f0574f5cSXin LI# Note: use '[/\\:.-]' here to ensure that we don't use the same name
3142b15cb3dSCy Schubert# that we are using for the .o file.  Also, base the name on the expected
3152b15cb3dSCy Schubert# object file name, since that is what matters with a parallel build.
3162b15cb3dSCy Schubertlockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
3172b15cb3dSCy Schubertwhile true; do
3182b15cb3dSCy Schubert  if mkdir "$lockdir" >/dev/null 2>&1; then
3192b15cb3dSCy Schubert    break
3202b15cb3dSCy Schubert  fi
3212b15cb3dSCy Schubert  sleep 1
3222b15cb3dSCy Schubertdone
3232b15cb3dSCy Schubert# FIXME: race condition here if user kills between mkdir and trap.
3242b15cb3dSCy Schuberttrap "rmdir '$lockdir'; exit 1" 1 2 15
3252b15cb3dSCy Schubert
3262b15cb3dSCy Schubert# Run the compile.
3272b15cb3dSCy Schubert"$@"
3282b15cb3dSCy Schubertret=$?
3292b15cb3dSCy Schubert
3302b15cb3dSCy Schubertif test -f "$cofile"; then
3312b15cb3dSCy Schubert  test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
3322b15cb3dSCy Schubertelif test -f "${cofile}bj"; then
3332b15cb3dSCy Schubert  test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
3342b15cb3dSCy Schubertfi
3352b15cb3dSCy Schubert
3362b15cb3dSCy Schubertrmdir "$lockdir"
3372b15cb3dSCy Schubertexit $ret
3382b15cb3dSCy Schubert
3392b15cb3dSCy Schubert# Local Variables:
3402b15cb3dSCy Schubert# mode: shell-script
3412b15cb3dSCy Schubert# sh-indentation: 2
3422b15cb3dSCy Schubert# eval: (add-hook 'write-file-hooks 'time-stamp)
3432b15cb3dSCy Schubert# time-stamp-start: "scriptversion="
3442b15cb3dSCy Schubert# time-stamp-format: "%:y-%02m-%02d.%02H"
3452b15cb3dSCy Schubert# time-stamp-time-zone: "UTC"
3462b15cb3dSCy Schubert# time-stamp-end: "; # UTC"
3472b15cb3dSCy Schubert# End:
348