xref: /aosp_15_r20/external/tcpdump/aclocal.m4 (revision 05b00f6010a2396e3db2409989fc67270046269f)
1*05b00f60SXin Lidnl Copyright (c) 1995, 1996, 1997, 1998
2*05b00f60SXin Lidnl	The Regents of the University of California.  All rights reserved.
3*05b00f60SXin Lidnl
4*05b00f60SXin Lidnl Redistribution and use in source and binary forms, with or without
5*05b00f60SXin Lidnl modification, are permitted provided that: (1) source code distributions
6*05b00f60SXin Lidnl retain the above copyright notice and this paragraph in its entirety, (2)
7*05b00f60SXin Lidnl distributions including binary code include the above copyright notice and
8*05b00f60SXin Lidnl this paragraph in its entirety in the documentation or other materials
9*05b00f60SXin Lidnl provided with the distribution, and (3) all advertising materials mentioning
10*05b00f60SXin Lidnl features or use of this software display the following acknowledgement:
11*05b00f60SXin Lidnl ``This product includes software developed by the University of California,
12*05b00f60SXin Lidnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13*05b00f60SXin Lidnl the University nor the names of its contributors may be used to endorse
14*05b00f60SXin Lidnl or promote products derived from this software without specific prior
15*05b00f60SXin Lidnl written permission.
16*05b00f60SXin Lidnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17*05b00f60SXin Lidnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18*05b00f60SXin Lidnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19*05b00f60SXin Lidnl
20*05b00f60SXin Lidnl LBL autoconf macros
21*05b00f60SXin Lidnl
22*05b00f60SXin Li
23*05b00f60SXin Lidnl
24*05b00f60SXin Lidnl Do whatever AC_LBL_C_INIT work is necessary before using AC_PROG_CC.
25*05b00f60SXin Lidnl
26*05b00f60SXin Lidnl It appears that newer versions of autoconf (2.64 and later) will,
27*05b00f60SXin Lidnl if you use AC_TRY_COMPILE in a macro, stick AC_PROG_CC at the
28*05b00f60SXin Lidnl beginning of the macro, even if the macro itself calls AC_PROG_CC.
29*05b00f60SXin Lidnl See the "Prerequisite Macros" and "Expanded Before Required" sections
30*05b00f60SXin Lidnl in the Autoconf documentation.
31*05b00f60SXin Lidnl
32*05b00f60SXin Lidnl This causes a steaming heap of fail in our case, as we were, in
33*05b00f60SXin Lidnl AC_LBL_C_INIT, doing the tests we now do in AC_LBL_C_INIT_BEFORE_CC,
34*05b00f60SXin Lidnl calling AC_PROG_CC, and then doing the tests we now do in
35*05b00f60SXin Lidnl AC_LBL_C_INIT.  Now, we run AC_LBL_C_INIT_BEFORE_CC, AC_PROG_CC,
36*05b00f60SXin Lidnl and AC_LBL_C_INIT at the top level.
37*05b00f60SXin Lidnl
38*05b00f60SXin LiAC_DEFUN(AC_LBL_C_INIT_BEFORE_CC,
39*05b00f60SXin Li[
40*05b00f60SXin Li    AC_BEFORE([$0], [AC_LBL_C_INIT])
41*05b00f60SXin Li    AC_BEFORE([$0], [AC_PROG_CC])
42*05b00f60SXin Li    AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
43*05b00f60SXin Li    AC_BEFORE([$0], [AC_LBL_DEVEL])
44*05b00f60SXin Li    AC_ARG_WITH(gcc, [  --without-gcc           don't use gcc])
45*05b00f60SXin Li    $1=""
46*05b00f60SXin Li    if test "${srcdir}" != "." ; then
47*05b00f60SXin Li	    $1="-I$srcdir"
48*05b00f60SXin Li    fi
49*05b00f60SXin Li    if test "${CFLAGS+set}" = set; then
50*05b00f60SXin Li	    LBL_CFLAGS="$CFLAGS"
51*05b00f60SXin Li    fi
52*05b00f60SXin Li    if test -z "$CC" ; then
53*05b00f60SXin Li	    case "$host_os" in
54*05b00f60SXin Li
55*05b00f60SXin Li	    bsdi*)
56*05b00f60SXin Li		    AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
57*05b00f60SXin Li		    if test $SHLICC2 = yes ; then
58*05b00f60SXin Li			    CC=shlicc2
59*05b00f60SXin Li			    export CC
60*05b00f60SXin Li		    fi
61*05b00f60SXin Li		    ;;
62*05b00f60SXin Li	    esac
63*05b00f60SXin Li    fi
64*05b00f60SXin Li    if test -z "$CC" -a "$with_gcc" = no ; then
65*05b00f60SXin Li	    CC=cc
66*05b00f60SXin Li	    export CC
67*05b00f60SXin Li    fi
68*05b00f60SXin Li])
69*05b00f60SXin Li
70*05b00f60SXin Lidnl
71*05b00f60SXin Lidnl Determine which compiler we're using (cc or gcc)
72*05b00f60SXin Lidnl If using gcc, determine the version number
73*05b00f60SXin Lidnl If using cc:
74*05b00f60SXin Lidnl     require that it support ansi prototypes
75*05b00f60SXin Lidnl     use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to
76*05b00f60SXin Lidnl     do that ourselves for gcc)
77*05b00f60SXin Lidnl     add -g flags, as appropriate
78*05b00f60SXin Lidnl     explicitly specify /usr/local/include
79*05b00f60SXin Lidnl
80*05b00f60SXin Lidnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler
81*05b00f60SXin Lidnl that defines __GNUC__, which means clang, for example, counts as "gcc".
82*05b00f60SXin Lidnl
83*05b00f60SXin Lidnl usage:
84*05b00f60SXin Lidnl
85*05b00f60SXin Lidnl	AC_LBL_C_INIT(copt, incls)
86*05b00f60SXin Lidnl
87*05b00f60SXin Lidnl results:
88*05b00f60SXin Lidnl
89*05b00f60SXin Lidnl	$1 (copt set)
90*05b00f60SXin Lidnl	$2 (incls set)
91*05b00f60SXin Lidnl	CC
92*05b00f60SXin Lidnl	LDFLAGS
93*05b00f60SXin Lidnl	LBL_CFLAGS
94*05b00f60SXin Lidnl
95*05b00f60SXin LiAC_DEFUN(AC_LBL_C_INIT,
96*05b00f60SXin Li[
97*05b00f60SXin Li    AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
98*05b00f60SXin Li    AC_BEFORE([$0], [AC_LBL_DEVEL])
99*05b00f60SXin Li    AC_BEFORE([$0], [AC_LBL_SHLIBS_INIT])
100*05b00f60SXin Li    if test "$GCC" = yes ; then
101*05b00f60SXin Li	    #
102*05b00f60SXin Li	    # -Werror forces warnings to be errors.
103*05b00f60SXin Li	    #
104*05b00f60SXin Li	    ac_lbl_cc_force_warning_errors=-Werror
105*05b00f60SXin Li    else
106*05b00f60SXin Li	    $2="$$2 -I/usr/local/include"
107*05b00f60SXin Li	    LDFLAGS="$LDFLAGS -L/usr/local/lib"
108*05b00f60SXin Li
109*05b00f60SXin Li	    case "$host_os" in
110*05b00f60SXin Li
111*05b00f60SXin Li	    darwin*)
112*05b00f60SXin Li		    #
113*05b00f60SXin Li		    # This is assumed either to be GCC or clang, both
114*05b00f60SXin Li		    # of which use -Werror to force warnings to be errors.
115*05b00f60SXin Li		    #
116*05b00f60SXin Li		    ac_lbl_cc_force_warning_errors=-Werror
117*05b00f60SXin Li		    ;;
118*05b00f60SXin Li
119*05b00f60SXin Li	    hpux*)
120*05b00f60SXin Li		    #
121*05b00f60SXin Li		    # HP C, which is what we presume we're using, doesn't
122*05b00f60SXin Li		    # exit with a non-zero exit status if we hand it an
123*05b00f60SXin Li		    # invalid -W flag, can't be forced to do so even with
124*05b00f60SXin Li		    # +We, and doesn't handle GCC-style -W flags, so we
125*05b00f60SXin Li		    # don't want to try using GCC-style -W flags.
126*05b00f60SXin Li		    #
127*05b00f60SXin Li		    ac_lbl_cc_dont_try_gcc_dashW=yes
128*05b00f60SXin Li		    ;;
129*05b00f60SXin Li
130*05b00f60SXin Li	    irix*)
131*05b00f60SXin Li		    #
132*05b00f60SXin Li		    # MIPS C, which is what we presume we're using, doesn't
133*05b00f60SXin Li		    # necessarily exit with a non-zero exit status if we
134*05b00f60SXin Li		    # hand it an invalid -W flag, can't be forced to do
135*05b00f60SXin Li		    # so, and doesn't handle GCC-style -W flags, so we
136*05b00f60SXin Li		    # don't want to try using GCC-style -W flags.
137*05b00f60SXin Li		    #
138*05b00f60SXin Li		    ac_lbl_cc_dont_try_gcc_dashW=yes
139*05b00f60SXin Li		    #
140*05b00f60SXin Li		    # It also, apparently, defaults to "char" being
141*05b00f60SXin Li		    # unsigned, unlike most other C implementations;
142*05b00f60SXin Li		    # I suppose we could say "signed char" whenever
143*05b00f60SXin Li		    # we want to guarantee a signed "char", but let's
144*05b00f60SXin Li		    # just force signed chars.
145*05b00f60SXin Li		    #
146*05b00f60SXin Li		    # -xansi is normally the default, but the
147*05b00f60SXin Li		    # configure script was setting it; perhaps -cckr
148*05b00f60SXin Li		    # was the default in the Old Days.  (Then again,
149*05b00f60SXin Li		    # that would probably be for backwards compatibility
150*05b00f60SXin Li		    # in the days when ANSI C was Shiny and New, i.e.
151*05b00f60SXin Li		    # 1989 and the early '90's, so maybe we can just
152*05b00f60SXin Li		    # drop support for those compilers.)
153*05b00f60SXin Li		    #
154*05b00f60SXin Li		    # -g is equivalent to -g2, which turns off
155*05b00f60SXin Li		    # optimization; we choose -g3, which generates
156*05b00f60SXin Li		    # debugging information but doesn't turn off
157*05b00f60SXin Li		    # optimization (even if the optimization would
158*05b00f60SXin Li		    # cause inaccuracies in debugging).
159*05b00f60SXin Li		    #
160*05b00f60SXin Li		    $1="$$1 -xansi -signed -g3"
161*05b00f60SXin Li		    ;;
162*05b00f60SXin Li
163*05b00f60SXin Li	    osf*)
164*05b00f60SXin Li		    #
165*05b00f60SXin Li		    # Presumed to be DEC OSF/1, Digital UNIX, or
166*05b00f60SXin Li		    # Tru64 UNIX.
167*05b00f60SXin Li		    #
168*05b00f60SXin Li		    # The DEC C compiler, which is what we presume we're
169*05b00f60SXin Li		    # using, doesn't exit with a non-zero exit status if we
170*05b00f60SXin Li		    # hand it an invalid -W flag, can't be forced to do
171*05b00f60SXin Li		    # so, and doesn't handle GCC-style -W flags, so we
172*05b00f60SXin Li		    # don't want to try using GCC-style -W flags.
173*05b00f60SXin Li		    #
174*05b00f60SXin Li		    ac_lbl_cc_dont_try_gcc_dashW=yes
175*05b00f60SXin Li		    #
176*05b00f60SXin Li		    # -g is equivalent to -g2, which turns off
177*05b00f60SXin Li		    # optimization; we choose -g3, which generates
178*05b00f60SXin Li		    # debugging information but doesn't turn off
179*05b00f60SXin Li		    # optimization (even if the optimization would
180*05b00f60SXin Li		    # cause inaccuracies in debugging).
181*05b00f60SXin Li		    #
182*05b00f60SXin Li		    $1="$$1 -g3"
183*05b00f60SXin Li		    ;;
184*05b00f60SXin Li
185*05b00f60SXin Li	    solaris*)
186*05b00f60SXin Li		    #
187*05b00f60SXin Li		    # Assumed to be Sun C, which requires -errwarn to force
188*05b00f60SXin Li		    # warnings to be treated as errors.
189*05b00f60SXin Li		    #
190*05b00f60SXin Li		    ac_lbl_cc_force_warning_errors=-errwarn
191*05b00f60SXin Li		    ;;
192*05b00f60SXin Li
193*05b00f60SXin Li	    ultrix*)
194*05b00f60SXin Li		    AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
195*05b00f60SXin Li		    AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
196*05b00f60SXin Li			AC_TRY_COMPILE(
197*05b00f60SXin Li			    [#include <sys/types.h>],
198*05b00f60SXin Li			    [struct a { int b; };
199*05b00f60SXin Li			    void c(const struct a *)],
200*05b00f60SXin Li			    ac_cv_lbl_cc_const_proto=yes,
201*05b00f60SXin Li			    ac_cv_lbl_cc_const_proto=no))
202*05b00f60SXin Li		    AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
203*05b00f60SXin Li		    if test $ac_cv_lbl_cc_const_proto = no ; then
204*05b00f60SXin Li			    AC_DEFINE(const,[],
205*05b00f60SXin Li			        [to handle Ultrix compilers that don't support const in prototypes])
206*05b00f60SXin Li		    fi
207*05b00f60SXin Li		    ;;
208*05b00f60SXin Li	    esac
209*05b00f60SXin Li	    $1="$$1 -O"
210*05b00f60SXin Li    fi
211*05b00f60SXin Li])
212*05b00f60SXin Li
213*05b00f60SXin Lidnl
214*05b00f60SXin Lidnl Check whether the compiler option specified as the second argument
215*05b00f60SXin Lidnl is supported by the compiler and, if so, add it to the macro
216*05b00f60SXin Lidnl specified as the first argument
217*05b00f60SXin Lidnl
218*05b00f60SXin LiAC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
219*05b00f60SXin Li    [
220*05b00f60SXin Li	AC_MSG_CHECKING([whether the compiler supports the $2 option])
221*05b00f60SXin Li	save_CFLAGS="$CFLAGS"
222*05b00f60SXin Li	CFLAGS="$CFLAGS $2"
223*05b00f60SXin Li	#
224*05b00f60SXin Li	# XXX - yes, this depends on the way AC_LANG_WERROR works,
225*05b00f60SXin Li	# but no mechanism is provided to turn AC_LANG_WERROR on
226*05b00f60SXin Li	# *and then turn it back off*, so that we *only* do it when
227*05b00f60SXin Li	# testing compiler options - 15 years after somebody asked
228*05b00f60SXin Li	# for it:
229*05b00f60SXin Li	#
230*05b00f60SXin Li	#     https://autoconf.gnu.narkive.com/gTAVmfKD/how-to-cancel-flags-set-by-ac-lang-werror
231*05b00f60SXin Li	#
232*05b00f60SXin Li	save_ac_c_werror_flag="$ac_c_werror_flag"
233*05b00f60SXin Li	ac_c_werror_flag=yes
234*05b00f60SXin Li	#
235*05b00f60SXin Li	# We use AC_LANG_SOURCE() so that we can control the complete
236*05b00f60SXin Li	# content of the program being compiled.  We do not, for example,
237*05b00f60SXin Li	# want the default "int main()" that AC_LANG_PROGRAM() generates,
238*05b00f60SXin Li	# as it will generate a warning with -Wold-style-definition, meaning
239*05b00f60SXin Li	# that we would treat it as not working, as the test will fail if
240*05b00f60SXin Li	# *any* error output, including a warning due to the flag we're
241*05b00f60SXin Li	# testing, is generated; see
242*05b00f60SXin Li	#
243*05b00f60SXin Li	#    https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
244*05b00f60SXin Li	#    https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
245*05b00f60SXin Li	#
246*05b00f60SXin Li	# This may, as per those two messages, be fixed in autoconf 2.70,
247*05b00f60SXin Li	# but we only require 2.64 or newer for now.
248*05b00f60SXin Li	#
249*05b00f60SXin Li	AC_COMPILE_IFELSE(
250*05b00f60SXin Li	    [AC_LANG_SOURCE([[int main(void) { return 0; }]])],
251*05b00f60SXin Li	    [
252*05b00f60SXin Li		AC_MSG_RESULT([yes])
253*05b00f60SXin Li		CFLAGS="$save_CFLAGS"
254*05b00f60SXin Li		$1="$$1 $2"
255*05b00f60SXin Li	    ],
256*05b00f60SXin Li	    [
257*05b00f60SXin Li		AC_MSG_RESULT([no])
258*05b00f60SXin Li		CFLAGS="$save_CFLAGS"
259*05b00f60SXin Li	    ])
260*05b00f60SXin Li	ac_c_werror_flag="$save_ac_c_werror_flag"
261*05b00f60SXin Li    ])
262*05b00f60SXin Li
263*05b00f60SXin Lidnl
264*05b00f60SXin Lidnl Check whether the compiler supports an option to generate
265*05b00f60SXin Lidnl Makefile-style dependency lines
266*05b00f60SXin Lidnl
267*05b00f60SXin Lidnl GCC uses -M for this.  Non-GCC compilers that support this
268*05b00f60SXin Lidnl use a variety of flags, including but not limited to -M.
269*05b00f60SXin Lidnl
270*05b00f60SXin Lidnl We test whether the flag in question is supported, as older
271*05b00f60SXin Lidnl versions of compilers might not support it.
272*05b00f60SXin Lidnl
273*05b00f60SXin Lidnl We don't try all the possible flags, just in case some flag means
274*05b00f60SXin Lidnl "generate dependencies" on one compiler but means something else
275*05b00f60SXin Lidnl on another compiler.
276*05b00f60SXin Lidnl
277*05b00f60SXin Lidnl Most compilers that support this send the output to the standard
278*05b00f60SXin Lidnl output by default.  IBM's XLC, however, supports -M but sends
279*05b00f60SXin Lidnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
280*05b00f60SXin Lidnl to work around that, so we don't bother with XLC.
281*05b00f60SXin Lidnl
282*05b00f60SXin LiAC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
283*05b00f60SXin Li    [
284*05b00f60SXin Li	AC_MSG_CHECKING([whether the compiler supports generating dependencies])
285*05b00f60SXin Li	if test "$GCC" = yes ; then
286*05b00f60SXin Li		#
287*05b00f60SXin Li		# GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
288*05b00f60SXin Li		# though it's not); we assume that, in this case, the flag
289*05b00f60SXin Li		# would be -M.
290*05b00f60SXin Li		#
291*05b00f60SXin Li		ac_lbl_dependency_flag="-M"
292*05b00f60SXin Li	else
293*05b00f60SXin Li		#
294*05b00f60SXin Li		# Not GCC or a compiler deemed to be GCC; what platform is
295*05b00f60SXin Li		# this?  (We're assuming that if the compiler isn't GCC
296*05b00f60SXin Li		# it's the compiler from the vendor of the OS; that won't
297*05b00f60SXin Li		# necessarily be true for x86 platforms, where it might be
298*05b00f60SXin Li		# the Intel C compiler.)
299*05b00f60SXin Li		#
300*05b00f60SXin Li		case "$host_os" in
301*05b00f60SXin Li
302*05b00f60SXin Li		irix*|osf*|darwin*)
303*05b00f60SXin Li			#
304*05b00f60SXin Li			# MIPS C for IRIX, DEC C, and clang all use -M.
305*05b00f60SXin Li			#
306*05b00f60SXin Li			ac_lbl_dependency_flag="-M"
307*05b00f60SXin Li			;;
308*05b00f60SXin Li
309*05b00f60SXin Li		solaris*)
310*05b00f60SXin Li			#
311*05b00f60SXin Li			# Sun C uses -xM.
312*05b00f60SXin Li			#
313*05b00f60SXin Li			ac_lbl_dependency_flag="-xM"
314*05b00f60SXin Li			;;
315*05b00f60SXin Li
316*05b00f60SXin Li		hpux*)
317*05b00f60SXin Li			#
318*05b00f60SXin Li			# HP's older C compilers don't support this.
319*05b00f60SXin Li			# HP's newer C compilers support this with
320*05b00f60SXin Li			# either +M or +Make; the older compilers
321*05b00f60SXin Li			# interpret +M as something completely
322*05b00f60SXin Li			# different, so we use +Make so we don't
323*05b00f60SXin Li			# think it works with the older compilers.
324*05b00f60SXin Li			#
325*05b00f60SXin Li			ac_lbl_dependency_flag="+Make"
326*05b00f60SXin Li			;;
327*05b00f60SXin Li
328*05b00f60SXin Li		*)
329*05b00f60SXin Li			#
330*05b00f60SXin Li			# Not one of the above; assume no support for
331*05b00f60SXin Li			# generating dependencies.
332*05b00f60SXin Li			#
333*05b00f60SXin Li			ac_lbl_dependency_flag=""
334*05b00f60SXin Li			;;
335*05b00f60SXin Li		esac
336*05b00f60SXin Li	fi
337*05b00f60SXin Li
338*05b00f60SXin Li	#
339*05b00f60SXin Li	# Is ac_lbl_dependency_flag defined and, if so, does the compiler
340*05b00f60SXin Li	# complain about it?
341*05b00f60SXin Li	#
342*05b00f60SXin Li	# Note: clang doesn't seem to exit with an error status when handed
343*05b00f60SXin Li	# an unknown non-warning error, even if you pass it
344*05b00f60SXin Li	# -Werror=unknown-warning-option.  However, it always supports
345*05b00f60SXin Li	# -M, so the fact that this test always succeeds with clang
346*05b00f60SXin Li	# isn't an issue.
347*05b00f60SXin Li	#
348*05b00f60SXin Li	if test ! -z "$ac_lbl_dependency_flag"; then
349*05b00f60SXin Li		AC_LANG_CONFTEST(
350*05b00f60SXin Li		    [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
351*05b00f60SXin Li		if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
352*05b00f60SXin Li			AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
353*05b00f60SXin Li			DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
354*05b00f60SXin Li			MKDEP='${top_srcdir}/mkdep'
355*05b00f60SXin Li		else
356*05b00f60SXin Li			AC_MSG_RESULT([no])
357*05b00f60SXin Li			#
358*05b00f60SXin Li			# We can't run mkdep, so have "make depend" do
359*05b00f60SXin Li			# nothing.
360*05b00f60SXin Li			#
361*05b00f60SXin Li			MKDEP=:
362*05b00f60SXin Li		fi
363*05b00f60SXin Li		rm -rf conftest*
364*05b00f60SXin Li	else
365*05b00f60SXin Li		AC_MSG_RESULT([no])
366*05b00f60SXin Li		#
367*05b00f60SXin Li		# We can't run mkdep, so have "make depend" do
368*05b00f60SXin Li		# nothing.
369*05b00f60SXin Li		#
370*05b00f60SXin Li		MKDEP=:
371*05b00f60SXin Li	fi
372*05b00f60SXin Li	AC_SUBST(DEPENDENCY_CFLAG)
373*05b00f60SXin Li	AC_SUBST(MKDEP)
374*05b00f60SXin Li    ])
375*05b00f60SXin Li
376*05b00f60SXin Li#
377*05b00f60SXin Li# Try compiling a sample of the type of code that appears in
378*05b00f60SXin Li# gencode.c with "inline", "__inline__", and "__inline".
379*05b00f60SXin Li#
380*05b00f60SXin Li# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
381*05b00f60SXin Li# as it just tests whether a function returning "int" can be inlined;
382*05b00f60SXin Li# at least some versions of HP's C compiler can inline that, but can't
383*05b00f60SXin Li# inline a function that returns a struct pointer.
384*05b00f60SXin Li#
385*05b00f60SXin Li# Make sure we use the V_CCOPT flags, because some of those might
386*05b00f60SXin Li# disable inlining.
387*05b00f60SXin Li#
388*05b00f60SXin LiAC_DEFUN(AC_LBL_C_INLINE,
389*05b00f60SXin Li    [AC_MSG_CHECKING(for inline)
390*05b00f60SXin Li    save_CFLAGS="$CFLAGS"
391*05b00f60SXin Li    CFLAGS="$V_CCOPT"
392*05b00f60SXin Li    AC_CACHE_VAL(ac_cv_lbl_inline, [
393*05b00f60SXin Li	ac_cv_lbl_inline=""
394*05b00f60SXin Li	ac_lbl_cc_inline=no
395*05b00f60SXin Li	for ac_lbl_inline in inline __inline__ __inline
396*05b00f60SXin Li	do
397*05b00f60SXin Li	    AC_TRY_COMPILE(
398*05b00f60SXin Li		[#define inline $ac_lbl_inline
399*05b00f60SXin Li		static inline struct iltest *foo(void);
400*05b00f60SXin Li		struct iltest {
401*05b00f60SXin Li		    int iltest1;
402*05b00f60SXin Li		    int iltest2;
403*05b00f60SXin Li		};
404*05b00f60SXin Li
405*05b00f60SXin Li		static inline struct iltest *
406*05b00f60SXin Li		foo()
407*05b00f60SXin Li		{
408*05b00f60SXin Li		    static struct iltest xxx;
409*05b00f60SXin Li
410*05b00f60SXin Li		    return &xxx;
411*05b00f60SXin Li		}],,ac_lbl_cc_inline=yes,)
412*05b00f60SXin Li	    if test "$ac_lbl_cc_inline" = yes ; then
413*05b00f60SXin Li		break;
414*05b00f60SXin Li	    fi
415*05b00f60SXin Li	done
416*05b00f60SXin Li	if test "$ac_lbl_cc_inline" = yes ; then
417*05b00f60SXin Li	    ac_cv_lbl_inline=$ac_lbl_inline
418*05b00f60SXin Li	fi])
419*05b00f60SXin Li    CFLAGS="$save_CFLAGS"
420*05b00f60SXin Li    if test ! -z "$ac_cv_lbl_inline" ; then
421*05b00f60SXin Li	AC_MSG_RESULT($ac_cv_lbl_inline)
422*05b00f60SXin Li    else
423*05b00f60SXin Li	AC_MSG_RESULT(no)
424*05b00f60SXin Li    fi
425*05b00f60SXin Li    AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
426*05b00f60SXin Li
427*05b00f60SXin Lidnl
428*05b00f60SXin Lidnl Use pfopen.c if available and pfopen() not in standard libraries
429*05b00f60SXin Lidnl Require libpcap
430*05b00f60SXin Lidnl Look for libpcap in directories under ..; those are local versions.
431*05b00f60SXin Lidnl Look for an installed libpcap if there is no local version or if
432*05b00f60SXin Lidnl the user said not to look for a local version.
433*05b00f60SXin Lidnl
434*05b00f60SXin Lidnl usage:
435*05b00f60SXin Lidnl
436*05b00f60SXin Lidnl	AC_LBL_LIBPCAP(pcapdep, incls)
437*05b00f60SXin Lidnl
438*05b00f60SXin Lidnl results:
439*05b00f60SXin Lidnl
440*05b00f60SXin Lidnl	$1 (pcapdep set)
441*05b00f60SXin Lidnl	$2 (incls appended)
442*05b00f60SXin Lidnl	LIBS
443*05b00f60SXin Lidnl	LBL_LIBS
444*05b00f60SXin Lidnl
445*05b00f60SXin LiAC_DEFUN(AC_LBL_LIBPCAP,
446*05b00f60SXin Li    [AC_REQUIRE([AC_LBL_LIBRARY_NET])
447*05b00f60SXin Li    dnl
448*05b00f60SXin Li    dnl save a copy before locating libpcap.a
449*05b00f60SXin Li    dnl
450*05b00f60SXin Li    LBL_LIBS="$LIBS"
451*05b00f60SXin Li    pfopen=/usr/examples/packetfilter/pfopen.c
452*05b00f60SXin Li    if test -f $pfopen ; then
453*05b00f60SXin Li        AC_CHECK_FUNCS(pfopen)
454*05b00f60SXin Li        if test $ac_cv_func_pfopen = "no" ; then
455*05b00f60SXin Li            AC_MSG_RESULT(Using $pfopen)
456*05b00f60SXin Li            LIBS="$LIBS $pfopen"
457*05b00f60SXin Li        fi
458*05b00f60SXin Li    fi
459*05b00f60SXin Li    libpcap=FAIL
460*05b00f60SXin Li    AC_MSG_CHECKING([whether to look for a local libpcap])
461*05b00f60SXin Li    AC_ARG_ENABLE(local-libpcap,
462*05b00f60SXin Li        AS_HELP_STRING([--disable-local-libpcap],
463*05b00f60SXin Li                       [don't look for a local libpcap @<:@default=check for a local libpcap@:>@]),,
464*05b00f60SXin Li        enableval=yes)
465*05b00f60SXin Li    case "$enableval" in
466*05b00f60SXin Li
467*05b00f60SXin Li    no)
468*05b00f60SXin Li        AC_MSG_RESULT(no)
469*05b00f60SXin Li        #
470*05b00f60SXin Li        # Don't look for a local libpcap.
471*05b00f60SXin Li        #
472*05b00f60SXin Li        using_local_libpcap=no
473*05b00f60SXin Li        ;;
474*05b00f60SXin Li
475*05b00f60SXin Li    *)
476*05b00f60SXin Li        AC_MSG_RESULT(yes)
477*05b00f60SXin Li        #
478*05b00f60SXin Li        # Look for a local pcap library.
479*05b00f60SXin Li        #
480*05b00f60SXin Li        AC_MSG_CHECKING(for local pcap library)
481*05b00f60SXin Li        lastdir=FAIL
482*05b00f60SXin Li        places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
483*05b00f60SXin Li            egrep '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
484*05b00f60SXin Li        places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
485*05b00f60SXin Li            egrep '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
486*05b00f60SXin Li        for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
487*05b00f60SXin Li            basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//' | \
488*05b00f60SXin Li                sed -e 's/-PRE-GIT$//' `
489*05b00f60SXin Li            if test $lastdir = $basedir ; then
490*05b00f60SXin Li                dnl skip alphas when an actual release is present
491*05b00f60SXin Li                continue;
492*05b00f60SXin Li            fi
493*05b00f60SXin Li            lastdir=$dir
494*05b00f60SXin Li            if test -r $dir/libpcap.a ; then
495*05b00f60SXin Li                libpcap=$dir/libpcap.a
496*05b00f60SXin Li                local_pcap_dir=$dir
497*05b00f60SXin Li                dnl continue and select the last one that exists
498*05b00f60SXin Li            fi
499*05b00f60SXin Li        done
500*05b00f60SXin Li        if test $libpcap = FAIL ; then
501*05b00f60SXin Li            #
502*05b00f60SXin Li            # We didn't find a local libpcap.
503*05b00f60SXin Li            #
504*05b00f60SXin Li            AC_MSG_RESULT(not found)
505*05b00f60SXin Li            using_local_libpcap=no;
506*05b00f60SXin Li        else
507*05b00f60SXin Li            #
508*05b00f60SXin Li            # We found a local libpcap.
509*05b00f60SXin Li            #
510*05b00f60SXin Li            AC_MSG_RESULT($libpcap)
511*05b00f60SXin Li            using_local_libpcap=yes
512*05b00f60SXin Li        fi
513*05b00f60SXin Li        ;;
514*05b00f60SXin Li    esac
515*05b00f60SXin Li
516*05b00f60SXin Li    if test $using_local_libpcap = no ; then
517*05b00f60SXin Li        #
518*05b00f60SXin Li        # We didn't find a local libpcap.
519*05b00f60SXin Li        # Look for an installed pkg-config.
520*05b00f60SXin Li        #
521*05b00f60SXin Li        AC_PATH_TOOL(PKG_CONFIG, pkg-config)
522*05b00f60SXin Li        if test -n "$PKG_CONFIG" ; then
523*05b00f60SXin Li            #
524*05b00f60SXin Li            # We have it.  Are there .pc files for libpcap?
525*05b00f60SXin Li            #
526*05b00f60SXin Li            # --exists was introduced in pkg-config 0.4.0; that
527*05b00f60SXin Li            # dates back to late 2000, so we won't worry about
528*05b00f60SXin Li            # earlier releases that lack it.
529*05b00f60SXin Li            #
530*05b00f60SXin Li            AC_MSG_CHECKING(whether there are .pc files for libpcap)
531*05b00f60SXin Li            if "$PKG_CONFIG" libpcap --exists ; then
532*05b00f60SXin Li                #
533*05b00f60SXin Li                # Yes, so we can use pkg-config to get configuration
534*05b00f60SXin Li                # information for libpcap.
535*05b00f60SXin Li                #
536*05b00f60SXin Li                AC_MSG_RESULT(yes)
537*05b00f60SXin Li                pkg_config_usable=yes
538*05b00f60SXin Li            else
539*05b00f60SXin Li                #
540*05b00f60SXin Li                # No, so we can't use pkg-config to get configuration
541*05b00f60SXin Li                # information for libpcap.
542*05b00f60SXin Li                #
543*05b00f60SXin Li                AC_MSG_RESULT(no)
544*05b00f60SXin Li                pkg_config_usable=no
545*05b00f60SXin Li            fi
546*05b00f60SXin Li        else
547*05b00f60SXin Li            #
548*05b00f60SXin Li            # We don't have it, so we obviously can't use it.
549*05b00f60SXin Li            #
550*05b00f60SXin Li            pkg_config_usable=no
551*05b00f60SXin Li        fi
552*05b00f60SXin Li        if test "$pkg_config_usable" = "yes" ; then
553*05b00f60SXin Li            #
554*05b00f60SXin Li            # Found both - use pkg-config to get the include flags for
555*05b00f60SXin Li            # libpcap and the flags to link with libpcap.
556*05b00f60SXin Li            #
557*05b00f60SXin Li            # Please read section 11.6 "Shell Substitutions"
558*05b00f60SXin Li            # in the autoconf manual before doing anything
559*05b00f60SXin Li            # to this that involves quoting.  Especially note
560*05b00f60SXin Li            # the statement "There is just no portable way to use
561*05b00f60SXin Li            # double-quoted strings inside double-quoted back-quoted
562*05b00f60SXin Li            # expressions (pfew!)."
563*05b00f60SXin Li            #
564*05b00f60SXin Li            cflags=`"$PKG_CONFIG" libpcap --cflags`
565*05b00f60SXin Li            $2="$cflags $$2"
566*05b00f60SXin Li            libpcap=`"$PKG_CONFIG" libpcap --libs`
567*05b00f60SXin Li        else
568*05b00f60SXin Li            #
569*05b00f60SXin Li            # No pkg-config
570*05b00f60SXin Li            # Look for an installed pcap-config.
571*05b00f60SXin Li            #
572*05b00f60SXin Li            AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
573*05b00f60SXin Li            if test -n "$PCAP_CONFIG" ; then
574*05b00f60SXin Li                #
575*05b00f60SXin Li                # Found - use it to get the include flags for
576*05b00f60SXin Li                # libpcap and the flags to link with libpcap.
577*05b00f60SXin Li                #
578*05b00f60SXin Li                # If this is a vendor-supplied pcap-config, which
579*05b00f60SXin Li                # we define as being "a pcap-config in /usr/bin
580*05b00f60SXin Li                # or /usr/ccs/bin" (the latter is for Solaris and
581*05b00f60SXin Li                # Sun/Oracle Studio), there are some issues.  Work
582*05b00f60SXin Li                # around them.
583*05b00f60SXin Li                #
584*05b00f60SXin Li                if test \( "$PCAP_CONFIG" = "/usr/bin/pcap-config" \) -o \
585*05b00f60SXin Li                        \( "$PCAP_CONFIG" = "/usr/ccs/bin/pcap-config" \) ; then
586*05b00f60SXin Li                    #
587*05b00f60SXin Li                    # It's vendor-supplied.
588*05b00f60SXin Li                    #
589*05b00f60SXin Li                    case "$host_os" in
590*05b00f60SXin Li
591*05b00f60SXin Li                    darwin*)
592*05b00f60SXin Li                        #
593*05b00f60SXin Li                        # This is macOS or another Darwin-based OS.
594*05b00f60SXin Li                        #
595*05b00f60SXin Li                        # That means that /usr/bin/pcap-config it
596*05b00f60SXin Li                        # may provide -I/usr/local/include with --cflags
597*05b00f60SXin Li                        # and -L/usr/local/lib with --libs, rather than
598*05b00f60SXin Li                        # pointing to the OS-supplied library and
599*05b00f60SXin Li                        # Xcode-supplied headers.  Remember that, so we
600*05b00f60SXin Li                        # ignore those values.
601*05b00f60SXin Li                        #
602*05b00f60SXin Li                        _broken_apple_pcap_config=yes
603*05b00f60SXin Li                        ;;
604*05b00f60SXin Li
605*05b00f60SXin Li                    solaris*)
606*05b00f60SXin Li                        #
607*05b00f60SXin Li                        # This is Solaris 2 or later, i.e. SunOS 5.x.
608*05b00f60SXin Li                        #
609*05b00f60SXin Li                        # At least on Solaris 11; there's /usr/bin/pcap-config,
610*05b00f60SXin Li                        # which reports -L/usr/lib with --libs, causing
611*05b00f60SXin Li                        # the 32-bit libraries to be found, and there's
612*05b00f60SXin Li                        # /usr/bin/{64bitarch}/pcap-config, where {64bitarch}
613*05b00f60SXin Li                        # is a name for the 64-bit version of the instruction
614*05b00f60SXin Li                        # set, which reports -L /usr/lib/{64bitarch}, causing
615*05b00f60SXin Li                        # the 64-bit libraries to be found.
616*05b00f60SXin Li                        #
617*05b00f60SXin Li                        # So if we're building 64-bit targets, we replace
618*05b00f60SXin Li                        # PCAP_CONFIG with /usr/bin/{64bitarch}; we get
619*05b00f60SXin Li                        # {64bitarch} as the output of "isainfo -n".
620*05b00f60SXin Li                        #
621*05b00f60SXin Li                        # Are we building 32-bit or 64-bit?  Get the
622*05b00f60SXin Li                        # size of void *, and check that.
623*05b00f60SXin Li                        #
624*05b00f60SXin Li                        AC_CHECK_SIZEOF([void *])
625*05b00f60SXin Li                        if test ac_cv_sizeof_void_p -eq 8 ; then
626*05b00f60SXin Li                            isainfo_output=`isainfo -n`
627*05b00f60SXin Li                            if test ! -z "$isainfo_output" ; then
628*05b00f60SXin Li                                #
629*05b00f60SXin Li                                # Success - change PCAP_CONFIG.
630*05b00f60SXin Li                                #
631*05b00f60SXin Li                                PCAP_CONFIG=`echo $PCAP_CONFIG | sed "s;/bin/;/bin/$isainfo_output/;"`
632*05b00f60SXin Li                            fi
633*05b00f60SXin Li                        fi
634*05b00f60SXin Li                        ;;
635*05b00f60SXin Li                    esac
636*05b00f60SXin Li                fi
637*05b00f60SXin Li                #
638*05b00f60SXin Li                # Please read section 11.6 "Shell Substitutions"
639*05b00f60SXin Li                # in the autoconf manual before doing anything
640*05b00f60SXin Li                # to this that involves quoting.  Especially note
641*05b00f60SXin Li                # the statement "There is just no portable way to use
642*05b00f60SXin Li                # double-quoted strings inside double-quoted back-quoted
643*05b00f60SXin Li                # expressions (pfew!)."
644*05b00f60SXin Li                #
645*05b00f60SXin Li                cflags=`"$PCAP_CONFIG" --cflags`
646*05b00f60SXin Li                #
647*05b00f60SXin Li                # Work around macOS (and probably other Darwin) brokenness,
648*05b00f60SXin Li                # by not adding /usr/local/include if it's from the broken
649*05b00f60SXin Li                # Apple pcap-config.
650*05b00f60SXin Li                #
651*05b00f60SXin Li                if test "$_broken_apple_pcap_config" = "yes" ; then
652*05b00f60SXin Li                    #
653*05b00f60SXin Li                    # Strip -I/usr/local/include with sed.
654*05b00f60SXin Li                    #
655*05b00f60SXin Li                    cflags=`echo $cflags | sed 's;-I/usr/local/include;;'`
656*05b00f60SXin Li                fi
657*05b00f60SXin Li                $2="$cflags $$2"
658*05b00f60SXin Li                libpcap=`"$PCAP_CONFIG" --libs`
659*05b00f60SXin Li                #
660*05b00f60SXin Li                # Work around macOS (and probably other Darwin) brokenness,
661*05b00f60SXin Li                # by not adding /usr/local/lib if it's from the broken
662*05b00f60SXin Li                # Apple pcap-config.
663*05b00f60SXin Li                #
664*05b00f60SXin Li                if test "$_broken_apple_pcap_config" = "yes" ; then
665*05b00f60SXin Li                    #
666*05b00f60SXin Li                    # Strip -L/usr/local/lib with sed.
667*05b00f60SXin Li                    #
668*05b00f60SXin Li                    libpcap=`echo $libpcap | sed 's;-L/usr/local/lib;;'`
669*05b00f60SXin Li                fi
670*05b00f60SXin Li            else
671*05b00f60SXin Li                #
672*05b00f60SXin Li                # Not found; look for an installed pcap.
673*05b00f60SXin Li                #
674*05b00f60SXin Li                AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
675*05b00f60SXin Li                if test $libpcap = FAIL ; then
676*05b00f60SXin Li                    AC_MSG_ERROR(see the INSTALL doc for more info)
677*05b00f60SXin Li                fi
678*05b00f60SXin Li                dnl
679*05b00f60SXin Li                dnl Some versions of Red Hat Linux put "pcap.h" in
680*05b00f60SXin Li                dnl "/usr/include/pcap"; had the LBL folks done so,
681*05b00f60SXin Li                dnl that would have been a good idea, but for
682*05b00f60SXin Li                dnl the Red Hat folks to do so just breaks source
683*05b00f60SXin Li                dnl compatibility with other systems.
684*05b00f60SXin Li                dnl
685*05b00f60SXin Li                dnl We work around this by assuming that, as we didn't
686*05b00f60SXin Li                dnl find a local libpcap, libpcap is in /usr/lib or
687*05b00f60SXin Li                dnl /usr/local/lib and that the corresponding header
688*05b00f60SXin Li                dnl file is under one of those directories; if we don't
689*05b00f60SXin Li                dnl find it in either of those directories, we check to
690*05b00f60SXin Li                dnl see if it's in a "pcap" subdirectory of them and,
691*05b00f60SXin Li                dnl if so, add that subdirectory to the "-I" list.
692*05b00f60SXin Li                dnl
693*05b00f60SXin Li                dnl (We now also put pcap.h in /usr/include/pcap, but we
694*05b00f60SXin Li                dnl leave behind a /usr/include/pcap.h that includes it,
695*05b00f60SXin Li                dnl so you can still just include <pcap.h>.)
696*05b00f60SXin Li                dnl
697*05b00f60SXin Li                AC_MSG_CHECKING(for extraneous pcap header directories)
698*05b00f60SXin Li                if test \( ! -r /usr/local/include/pcap.h \) -a \
699*05b00f60SXin Li                        \( ! -r /usr/include/pcap.h \); then
700*05b00f60SXin Li                    if test -r /usr/local/include/pcap/pcap.h; then
701*05b00f60SXin Li                        d="/usr/local/include/pcap"
702*05b00f60SXin Li                    elif test -r /usr/include/pcap/pcap.h; then
703*05b00f60SXin Li                        d="/usr/include/pcap"
704*05b00f60SXin Li                    fi
705*05b00f60SXin Li                fi
706*05b00f60SXin Li                if test -z "$d" ; then
707*05b00f60SXin Li                    AC_MSG_RESULT(not found)
708*05b00f60SXin Li                else
709*05b00f60SXin Li                    $2="-I$d $$2"
710*05b00f60SXin Li                    AC_MSG_RESULT(found -- -I$d added)
711*05b00f60SXin Li                fi
712*05b00f60SXin Li            fi
713*05b00f60SXin Li        fi
714*05b00f60SXin Li    else
715*05b00f60SXin Li        #
716*05b00f60SXin Li        # We found a local libpcap.  Add it to the dependencies for
717*05b00f60SXin Li        # tcpdump.
718*05b00f60SXin Li        #
719*05b00f60SXin Li        $1=$libpcap
720*05b00f60SXin Li
721*05b00f60SXin Li        #
722*05b00f60SXin Li        # Look for its pcap-config script.
723*05b00f60SXin Li        #
724*05b00f60SXin Li        AC_PATH_PROG(PCAP_CONFIG, pcap-config,, $local_pcap_dir)
725*05b00f60SXin Li
726*05b00f60SXin Li        if test -n "$PCAP_CONFIG"; then
727*05b00f60SXin Li            #
728*05b00f60SXin Li            # We don't want its --cflags or --libs output, because
729*05b00f60SXin Li            # those presume it's installed.  For the C compiler flags,
730*05b00f60SXin Li            # we add the source directory for the local libpcap, so
731*05b00f60SXin Li            # we pick up its header files.
732*05b00f60SXin Li            #
733*05b00f60SXin Li            # We do, however, want its additional libraries, as required
734*05b00f60SXin Li            # when linking statically, because it makes calls to
735*05b00f60SXin Li            # routines in those libraries, so we'll need to link with
736*05b00f60SXin Li            # them, because we'll be linking statically with it.
737*05b00f60SXin Li            #
738*05b00f60SXin Li            # If it supports --static-pcap-only. use that, as we will be
739*05b00f60SXin Li            # linking with a static libpcap but won't be linking
740*05b00f60SXin Li            # statically with any of the libraries on which it depends;
741*05b00f60SXin Li            # those libraries might not even have static versions
742*05b00f60SXin Li            # installed.
743*05b00f60SXin Li            #
744*05b00f60SXin Li            # That means we need to find out the libraries on which
745*05b00f60SXin Li            # libpcap directly depends, so we can link with them, but we
746*05b00f60SXin Li            # don't need to link with the libraries on which those
747*05b00f60SXin Li            # libraries depend as, on all UN*Xes with which I'm
748*05b00f60SXin Li            # familiar, the libraries on which a shared library depends
749*05b00f60SXin Li            # are stored in the library and are automatically loaded by
750*05b00f60SXin Li            # the run-time linker, without the executable having to be
751*05b00f60SXin Li            # linked with those libraries.  (This allows a library to be
752*05b00f60SXin Li            # changed to depend on more libraries without breaking that
753*05b00f60SXin Li            # library's ABI.)
754*05b00f60SXin Li            #
755*05b00f60SXin Li            # The only way to test for that support is to see if the
756*05b00f60SXin Li            # script contains the string "static-pcap-only"; we can't
757*05b00f60SXin Li            # try using that flag and checking for errors, as the
758*05b00f60SXin Li            # versions of the script that didn't have that flag wouldn't
759*05b00f60SXin Li            # report or return an error for an unsupported command-line
760*05b00f60SXin Li            # flag.  Those older versions provided, with --static, only
761*05b00f60SXin Li            # the libraries on which libpcap depends, not the
762*05b00f60SXin Li            # dependencies of those libraries; the versions with
763*05b00f60SXin Li            # --static-pcap-only provide all the dependencies with
764*05b00f60SXin Li            # --static, for the benefit of programs that are completely
765*05b00f60SXin Li            # statically linked, and provide only the direct
766*05b00f60SXin Li            # dependencies with --static-pcap-only.
767*05b00f60SXin Li            #
768*05b00f60SXin Li            if grep -s -q "static-pcap-only" "$PCAP_CONFIG"
769*05b00f60SXin Li            then
770*05b00f60SXin Li                static_opt="--static-pcap-only"
771*05b00f60SXin Li            else
772*05b00f60SXin Li                static_opt="--static"
773*05b00f60SXin Li            fi
774*05b00f60SXin Li            $2="-I$local_pcap_dir $$2"
775*05b00f60SXin Li            additional_libs=`"$PCAP_CONFIG" $static_opt --additional-libs`
776*05b00f60SXin Li            libpcap="$libpcap $additional_libs"
777*05b00f60SXin Li        else
778*05b00f60SXin Li            #
779*05b00f60SXin Li            # It doesn't have a pcap-config script.
780*05b00f60SXin Li            # Make sure it has a pcap.h file.
781*05b00f60SXin Li            #
782*05b00f60SXin Li            places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
783*05b00f60SXin Li                egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
784*05b00f60SXin Li            places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
785*05b00f60SXin Li                egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
786*05b00f60SXin Li            pcapH=FAIL
787*05b00f60SXin Li            if test -r $local_pcap_dir/pcap.h; then
788*05b00f60SXin Li                pcapH=$local_pcap_dir
789*05b00f60SXin Li            else
790*05b00f60SXin Li                for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
791*05b00f60SXin Li                    if test -r $dir/pcap.h ; then
792*05b00f60SXin Li                        pcapH=$dir
793*05b00f60SXin Li                    fi
794*05b00f60SXin Li                done
795*05b00f60SXin Li            fi
796*05b00f60SXin Li
797*05b00f60SXin Li            if test $pcapH = FAIL ; then
798*05b00f60SXin Li                AC_MSG_ERROR(cannot find pcap.h: see INSTALL)
799*05b00f60SXin Li            fi
800*05b00f60SXin Li
801*05b00f60SXin Li            #
802*05b00f60SXin Li            # Force the compiler to look for header files in the
803*05b00f60SXin Li            # directory containing pcap.h.
804*05b00f60SXin Li            #
805*05b00f60SXin Li            $2="-I$pcapH $$2"
806*05b00f60SXin Li        fi
807*05b00f60SXin Li    fi
808*05b00f60SXin Li
809*05b00f60SXin Li    if test -z "$PKG_CONFIG" -a -z "$PCAP_CONFIG"; then
810*05b00f60SXin Li        #
811*05b00f60SXin Li        # We don't have pkg-config or pcap-config; find out any additional
812*05b00f60SXin Li        # link flags we need.  (If we have pkg-config or pcap-config, we
813*05b00f60SXin Li        # assume it tells us what we need.)
814*05b00f60SXin Li        #
815*05b00f60SXin Li        case "$host_os" in
816*05b00f60SXin Li
817*05b00f60SXin Li        aix*)
818*05b00f60SXin Li            #
819*05b00f60SXin Li            # If libpcap is DLPI-based, we have to use /lib/pse.exp if
820*05b00f60SXin Li            # present, as we use the STREAMS routines.
821*05b00f60SXin Li            #
822*05b00f60SXin Li            # (XXX - true only if we're linking with a static libpcap?)
823*05b00f60SXin Li            #
824*05b00f60SXin Li            pseexe="/lib/pse.exp"
825*05b00f60SXin Li            AC_MSG_CHECKING(for $pseexe)
826*05b00f60SXin Li            if test -f $pseexe ; then
827*05b00f60SXin Li                AC_MSG_RESULT(yes)
828*05b00f60SXin Li                LIBS="$LIBS -I:$pseexe"
829*05b00f60SXin Li            fi
830*05b00f60SXin Li
831*05b00f60SXin Li            #
832*05b00f60SXin Li            # If libpcap is BPF-based, we need "-lodm" and "-lcfg", as
833*05b00f60SXin Li            # we use them to load the BPF module.
834*05b00f60SXin Li            #
835*05b00f60SXin Li            # (XXX - true only if we're linking with a static libpcap?)
836*05b00f60SXin Li            #
837*05b00f60SXin Li            LIBS="$LIBS -lodm -lcfg"
838*05b00f60SXin Li            ;;
839*05b00f60SXin Li
840*05b00f60SXin Li	solaris*)
841*05b00f60SXin Li            # libdlpi is needed for Solaris 11 and later.
842*05b00f60SXin Li            AC_CHECK_LIB(dlpi, dlpi_walk, LIBS="$LIBS -ldlpi" LDFLAGS="-L/lib $LDFLAGS", ,-L/lib)
843*05b00f60SXin Li            ;;
844*05b00f60SXin Li        esac
845*05b00f60SXin Li    fi
846*05b00f60SXin Li
847*05b00f60SXin Li    LIBS="$libpcap $LIBS"
848*05b00f60SXin Li
849*05b00f60SXin Li    dnl
850*05b00f60SXin Li    dnl Check for "pcap_loop()", to make sure we found a working
851*05b00f60SXin Li    dnl libpcap and have all the right other libraries with which
852*05b00f60SXin Li    dnl to link.  (Otherwise, the checks below will fail, not
853*05b00f60SXin Li    dnl because the routines are missing from the library, but
854*05b00f60SXin Li    dnl because we aren't linking properly with libpcap, and
855*05b00f60SXin Li    dnl that will cause confusing errors at build time.)
856*05b00f60SXin Li    dnl
857*05b00f60SXin Li    AC_CHECK_FUNC(pcap_loop,,
858*05b00f60SXin Li    [
859*05b00f60SXin Li        AC_MSG_ERROR(
860*05b00f60SXin Li[This is a bug, please follow the guidelines in CONTRIBUTING.md and include the
861*05b00f60SXin Liconfig.log file in your report.  If you have downloaded libpcap from
862*05b00f60SXin Litcpdump.org, and built it yourself, please also include the config.log
863*05b00f60SXin Lifile from the libpcap source directory, the Makefile from the libpcap
864*05b00f60SXin Lisource directory, and the output of the make process for libpcap, as
865*05b00f60SXin Lithis could be a problem with the libpcap that was built, and we will
866*05b00f60SXin Linot be able to determine why this is happening, and thus will not be
867*05b00f60SXin Liable to fix it, without that information, as we have not been able to
868*05b00f60SXin Lireproduce this problem ourselves.])
869*05b00f60SXin Li    ])
870*05b00f60SXin Li])
871*05b00f60SXin Li
872*05b00f60SXin Lidnl
873*05b00f60SXin Lidnl If using gcc, make sure we have ANSI ioctl definitions
874*05b00f60SXin Lidnl
875*05b00f60SXin Lidnl usage:
876*05b00f60SXin Lidnl
877*05b00f60SXin Lidnl	AC_LBL_FIXINCLUDES
878*05b00f60SXin Lidnl
879*05b00f60SXin LiAC_DEFUN(AC_LBL_FIXINCLUDES,
880*05b00f60SXin Li    [if test "$GCC" = yes ; then
881*05b00f60SXin Li	    AC_MSG_CHECKING(for ANSI ioctl definitions)
882*05b00f60SXin Li	    AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
883*05b00f60SXin Li		AC_TRY_COMPILE(
884*05b00f60SXin Li		    [/*
885*05b00f60SXin Li		     * This generates a "duplicate case value" when fixincludes
886*05b00f60SXin Li		     * has not be run.
887*05b00f60SXin Li		     */
888*05b00f60SXin Li#		include <sys/types.h>
889*05b00f60SXin Li#		include <sys/time.h>
890*05b00f60SXin Li#		include <sys/ioctl.h>
891*05b00f60SXin Li#		ifdef HAVE_SYS_IOCCOM_H
892*05b00f60SXin Li#		include <sys/ioccom.h>
893*05b00f60SXin Li#		endif],
894*05b00f60SXin Li		    [switch (0) {
895*05b00f60SXin Li		    case _IO('A', 1):;
896*05b00f60SXin Li		    case _IO('B', 1):;
897*05b00f60SXin Li		    }],
898*05b00f60SXin Li		    ac_cv_lbl_gcc_fixincludes=yes,
899*05b00f60SXin Li		    ac_cv_lbl_gcc_fixincludes=no))
900*05b00f60SXin Li	    AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
901*05b00f60SXin Li	    if test $ac_cv_lbl_gcc_fixincludes = no ; then
902*05b00f60SXin Li		    # Don't cache failure
903*05b00f60SXin Li		    unset ac_cv_lbl_gcc_fixincludes
904*05b00f60SXin Li		    AC_MSG_ERROR(see the INSTALL for more info)
905*05b00f60SXin Li	    fi
906*05b00f60SXin Li    fi])
907*05b00f60SXin Li
908*05b00f60SXin Lidnl
909*05b00f60SXin Lidnl Checks to see if union wait is used with WEXITSTATUS()
910*05b00f60SXin Lidnl
911*05b00f60SXin Lidnl usage:
912*05b00f60SXin Lidnl
913*05b00f60SXin Lidnl	AC_LBL_UNION_WAIT
914*05b00f60SXin Lidnl
915*05b00f60SXin Lidnl results:
916*05b00f60SXin Lidnl
917*05b00f60SXin Lidnl	DECLWAITSTATUS (defined)
918*05b00f60SXin Lidnl
919*05b00f60SXin LiAC_DEFUN(AC_LBL_UNION_WAIT,
920*05b00f60SXin Li    [AC_MSG_CHECKING(if union wait is used)
921*05b00f60SXin Li    AC_CACHE_VAL(ac_cv_lbl_union_wait,
922*05b00f60SXin Li	AC_TRY_COMPILE([
923*05b00f60SXin Li#	include <sys/types.h>
924*05b00f60SXin Li#	include <sys/wait.h>],
925*05b00f60SXin Li	    [int status;
926*05b00f60SXin Li	    u_int i = WEXITSTATUS(status);
927*05b00f60SXin Li	    u_int j = waitpid(0, &status, 0);],
928*05b00f60SXin Li	    ac_cv_lbl_union_wait=no,
929*05b00f60SXin Li	    ac_cv_lbl_union_wait=yes))
930*05b00f60SXin Li    AC_MSG_RESULT($ac_cv_lbl_union_wait)
931*05b00f60SXin Li    if test $ac_cv_lbl_union_wait = yes ; then
932*05b00f60SXin Li	    AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait])
933*05b00f60SXin Li    else
934*05b00f60SXin Li	    AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
935*05b00f60SXin Li    fi])
936*05b00f60SXin Li
937*05b00f60SXin Lidnl
938*05b00f60SXin Lidnl Checks to see if -R is used
939*05b00f60SXin Lidnl
940*05b00f60SXin Lidnl usage:
941*05b00f60SXin Lidnl
942*05b00f60SXin Lidnl	AC_LBL_HAVE_RUN_PATH
943*05b00f60SXin Lidnl
944*05b00f60SXin Lidnl results:
945*05b00f60SXin Lidnl
946*05b00f60SXin Lidnl	ac_cv_lbl_have_run_path (yes or no)
947*05b00f60SXin Lidnl
948*05b00f60SXin LiAC_DEFUN(AC_LBL_HAVE_RUN_PATH,
949*05b00f60SXin Li    [AC_MSG_CHECKING(for ${CC-cc} -R)
950*05b00f60SXin Li    AC_CACHE_VAL(ac_cv_lbl_have_run_path,
951*05b00f60SXin Li	[echo 'main(){}' > conftest.c
952*05b00f60SXin Li	${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
953*05b00f60SXin Li	if test ! -s conftest.out ; then
954*05b00f60SXin Li		ac_cv_lbl_have_run_path=yes
955*05b00f60SXin Li	else
956*05b00f60SXin Li		ac_cv_lbl_have_run_path=no
957*05b00f60SXin Li	fi
958*05b00f60SXin Li	rm -f -r conftest*])
959*05b00f60SXin Li    AC_MSG_RESULT($ac_cv_lbl_have_run_path)
960*05b00f60SXin Li    ])
961*05b00f60SXin Li
962*05b00f60SXin Lidnl
963*05b00f60SXin Lidnl Check whether a given format can be used to print 64-bit integers
964*05b00f60SXin Lidnl
965*05b00f60SXin LiAC_DEFUN(AC_LBL_CHECK_64BIT_FORMAT,
966*05b00f60SXin Li  [
967*05b00f60SXin Li    AC_MSG_CHECKING([whether %$1x can be used to format 64-bit integers])
968*05b00f60SXin Li    AC_RUN_IFELSE(
969*05b00f60SXin Li      [
970*05b00f60SXin Li	AC_LANG_SOURCE(
971*05b00f60SXin Li	  [[
972*05b00f60SXin Li#	    ifdef HAVE_INTTYPES_H
973*05b00f60SXin Li	    #include <inttypes.h>
974*05b00f60SXin Li#	    endif
975*05b00f60SXin Li	    #include <stdio.h>
976*05b00f60SXin Li	    #include <sys/types.h>
977*05b00f60SXin Li
978*05b00f60SXin Li	    main()
979*05b00f60SXin Li	    {
980*05b00f60SXin Li	      uint64_t t = 1;
981*05b00f60SXin Li	      char strbuf[16+1];
982*05b00f60SXin Li	      sprintf(strbuf, "%016$1x", t << 32);
983*05b00f60SXin Li	      if (strcmp(strbuf, "0000000100000000") == 0)
984*05b00f60SXin Li		exit(0);
985*05b00f60SXin Li	      else
986*05b00f60SXin Li		exit(1);
987*05b00f60SXin Li	    }
988*05b00f60SXin Li	  ]])
989*05b00f60SXin Li      ],
990*05b00f60SXin Li      [
991*05b00f60SXin Li	AC_DEFINE(PRId64, "$1d", [define if the platform doesn't define PRId64])
992*05b00f60SXin Li	AC_DEFINE(PRIo64, "$1o", [define if the platform doesn't define PRIo64])
993*05b00f60SXin Li	AC_DEFINE(PRIx64, "$1x", [define if the platform doesn't define PRIu64])
994*05b00f60SXin Li	AC_DEFINE(PRIu64, "$1u", [define if the platform doesn't define PRIx64])
995*05b00f60SXin Li	AC_MSG_RESULT(yes)
996*05b00f60SXin Li      ],
997*05b00f60SXin Li      [
998*05b00f60SXin Li	AC_MSG_RESULT(no)
999*05b00f60SXin Li	$2
1000*05b00f60SXin Li      ])
1001*05b00f60SXin Li  ])
1002*05b00f60SXin Li
1003*05b00f60SXin Lidnl
1004*05b00f60SXin Lidnl If the file .devel exists:
1005*05b00f60SXin Lidnl	Add some warning flags if the compiler supports them
1006*05b00f60SXin Lidnl	If an os prototype include exists, symlink os-proto.h to it
1007*05b00f60SXin Lidnl
1008*05b00f60SXin Lidnl usage:
1009*05b00f60SXin Lidnl
1010*05b00f60SXin Lidnl	AC_LBL_DEVEL(copt)
1011*05b00f60SXin Lidnl
1012*05b00f60SXin Lidnl results:
1013*05b00f60SXin Lidnl
1014*05b00f60SXin Lidnl	$1 (copt appended)
1015*05b00f60SXin Lidnl	HAVE_OS_PROTO_H (defined)
1016*05b00f60SXin Lidnl	os-proto.h (symlinked)
1017*05b00f60SXin Lidnl
1018*05b00f60SXin LiAC_DEFUN(AC_LBL_DEVEL,
1019*05b00f60SXin Li    [rm -f os-proto.h
1020*05b00f60SXin Li    if test "${LBL_CFLAGS+set}" = set; then
1021*05b00f60SXin Li	    $1="$$1 ${LBL_CFLAGS}"
1022*05b00f60SXin Li    fi
1023*05b00f60SXin Li    if test -f .devel ; then
1024*05b00f60SXin Li	    #
1025*05b00f60SXin Li	    # Skip all the warning option stuff on some compilers.
1026*05b00f60SXin Li	    #
1027*05b00f60SXin Li	    if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
1028*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -W)
1029*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
1030*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wassign-enum)
1031*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wcast-qual)
1032*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
1033*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
1034*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wold-style-definition)
1035*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpedantic)
1036*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
1037*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
1038*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
1039*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
1040*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
1041*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code-return)
1042*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
1043*05b00f60SXin Li		    AC_LBL_CHECK_COMPILER_OPT($1, -Wwrite-strings)
1044*05b00f60SXin Li	    fi
1045*05b00f60SXin Li	    AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
1046*05b00f60SXin Li	    #
1047*05b00f60SXin Li	    # We used to set -n32 for IRIX 6 when not using GCC (presumed
1048*05b00f60SXin Li	    # to mean that we're using MIPS C or MIPSpro C); it specified
1049*05b00f60SXin Li	    # the "new" faster 32-bit ABI, introduced in IRIX 6.2.  I'm
1050*05b00f60SXin Li	    # not sure why that would be something to do *only* with a
1051*05b00f60SXin Li	    # .devel file; why should the ABI for which we produce code
1052*05b00f60SXin Li	    # depend on .devel?
1053*05b00f60SXin Li	    #
1054*05b00f60SXin Li	    os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
1055*05b00f60SXin Li	    name="lbl/os-$os.h"
1056*05b00f60SXin Li	    if test -f $name ; then
1057*05b00f60SXin Li		    ln -s $name os-proto.h
1058*05b00f60SXin Li		    AC_DEFINE(HAVE_OS_PROTO_H, 1,
1059*05b00f60SXin Li			[if there's an os_proto.h for this platform, to use additional prototypes])
1060*05b00f60SXin Li	    else
1061*05b00f60SXin Li		    AC_MSG_WARN(can't find $name)
1062*05b00f60SXin Li	    fi
1063*05b00f60SXin Li    fi])
1064*05b00f60SXin Li
1065*05b00f60SXin Lidnl
1066*05b00f60SXin Lidnl Improved version of AC_CHECK_LIB
1067*05b00f60SXin Lidnl
1068*05b00f60SXin Lidnl Thanks to John Hawkinson ([email protected])
1069*05b00f60SXin Lidnl
1070*05b00f60SXin Lidnl usage:
1071*05b00f60SXin Lidnl
1072*05b00f60SXin Lidnl	AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
1073*05b00f60SXin Lidnl	    ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
1074*05b00f60SXin Lidnl
1075*05b00f60SXin Lidnl results:
1076*05b00f60SXin Lidnl
1077*05b00f60SXin Lidnl	LIBS
1078*05b00f60SXin Lidnl
1079*05b00f60SXin Lidnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS"
1080*05b00f60SXin Lidnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more.
1081*05b00f60SXin Lidnl We keep it around for reference purposes in case it's ever
1082*05b00f60SXin Lidnl useful in the future.
1083*05b00f60SXin Lidnl
1084*05b00f60SXin Li
1085*05b00f60SXin Lidefine(AC_LBL_CHECK_LIB,
1086*05b00f60SXin Li[AC_MSG_CHECKING([for $2 in -l$1])
1087*05b00f60SXin Lidnl Use a cache variable name containing the library, function
1088*05b00f60SXin Lidnl name, and extra libraries to link with, because the test really is
1089*05b00f60SXin Lidnl for library $1 defining function $2, when linked with potinal
1090*05b00f60SXin Lidnl library $5, not just for library $1.  Separate tests with the same
1091*05b00f60SXin Lidnl $1 and different $2's or $5's may have different results.
1092*05b00f60SXin Liac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
1093*05b00f60SXin LiAC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
1094*05b00f60SXin Li[ac_save_LIBS="$LIBS"
1095*05b00f60SXin LiLIBS="-l$1 $5 $LIBS"
1096*05b00f60SXin LiAC_TRY_LINK(dnl
1097*05b00f60SXin Liifelse([$2], [main], , dnl Avoid conflicting decl of main.
1098*05b00f60SXin Li[/* Override any gcc2 internal prototype to avoid an error.  */
1099*05b00f60SXin Li]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
1100*05b00f60SXin Liextern "C"
1101*05b00f60SXin Li#endif
1102*05b00f60SXin Li])dnl
1103*05b00f60SXin Li[/* We use char because int might match the return type of a gcc2
1104*05b00f60SXin Li    builtin and then its argument prototype would still apply.  */
1105*05b00f60SXin Lichar $2();
1106*05b00f60SXin Li]),
1107*05b00f60SXin Li	    [$2()],
1108*05b00f60SXin Li	    eval "ac_cv_lbl_lib_$ac_lib_var=yes",
1109*05b00f60SXin Li	    eval "ac_cv_lbl_lib_$ac_lib_var=no")
1110*05b00f60SXin LiLIBS="$ac_save_LIBS"
1111*05b00f60SXin Li])dnl
1112*05b00f60SXin Liif eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
1113*05b00f60SXin Li  AC_MSG_RESULT(yes)
1114*05b00f60SXin Li  ifelse([$3], ,
1115*05b00f60SXin Li[changequote(, )dnl
1116*05b00f60SXin Li  ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
1117*05b00f60SXin Li    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1118*05b00f60SXin Lichangequote([, ])dnl
1119*05b00f60SXin Li  AC_DEFINE_UNQUOTED($ac_tr_lib)
1120*05b00f60SXin Li  LIBS="-l$1 $LIBS"
1121*05b00f60SXin Li], [$3])
1122*05b00f60SXin Lielse
1123*05b00f60SXin Li  AC_MSG_RESULT(no)
1124*05b00f60SXin Liifelse([$4], , , [$4
1125*05b00f60SXin Li])dnl
1126*05b00f60SXin Lifi
1127*05b00f60SXin Li])
1128*05b00f60SXin Li
1129*05b00f60SXin Lidnl
1130*05b00f60SXin Lidnl AC_LBL_LIBRARY_NET
1131*05b00f60SXin Lidnl
1132*05b00f60SXin Lidnl This test is for network applications that need socket() and
1133*05b00f60SXin Lidnl gethostbyname() -ish functions.  Under Solaris, those applications
1134*05b00f60SXin Lidnl need to link with "-lsocket -lnsl".  Under IRIX, they need to link
1135*05b00f60SXin Lidnl with "-lnsl" but should *not* link with "-lsocket" because
1136*05b00f60SXin Lidnl libsocket.a breaks a number of things (for instance:
1137*05b00f60SXin Lidnl gethostbyname() under IRIX 5.2, and snoop sockets under most
1138*05b00f60SXin Lidnl versions of IRIX).
1139*05b00f60SXin Lidnl
1140*05b00f60SXin Lidnl Unfortunately, many application developers are not aware of this,
1141*05b00f60SXin Lidnl and mistakenly write tests that cause -lsocket to be used under
1142*05b00f60SXin Lidnl IRIX.  It is also easy to write tests that cause -lnsl to be used
1143*05b00f60SXin Lidnl under operating systems where neither are necessary (or useful),
1144*05b00f60SXin Lidnl such as SunOS 4.1.4, which uses -lnsl for TLI.
1145*05b00f60SXin Lidnl
1146*05b00f60SXin Lidnl This test exists so that every application developer does not test
1147*05b00f60SXin Lidnl this in a different, and subtly broken fashion.
1148*05b00f60SXin Li
1149*05b00f60SXin Lidnl It has been argued that this test should be broken up into two
1150*05b00f60SXin Lidnl separate tests, one for the resolver libraries, and one for the
1151*05b00f60SXin Lidnl libraries necessary for using Sockets API. Unfortunately, the two
1152*05b00f60SXin Lidnl are carefully intertwined and allowing the autoconf user to use
1153*05b00f60SXin Lidnl them independently potentially results in unfortunate ordering
1154*05b00f60SXin Lidnl dependencies -- as such, such component macros would have to
1155*05b00f60SXin Lidnl carefully use indirection and be aware if the other components were
1156*05b00f60SXin Lidnl executed. Since other autoconf macros do not go to this trouble,
1157*05b00f60SXin Lidnl and almost no applications use sockets without the resolver, this
1158*05b00f60SXin Lidnl complexity has not been implemented.
1159*05b00f60SXin Lidnl
1160*05b00f60SXin Lidnl The check for libresolv is in case you are attempting to link
1161*05b00f60SXin Lidnl statically and happen to have a libresolv.a lying around (and no
1162*05b00f60SXin Lidnl libnsl.a).
1163*05b00f60SXin Lidnl
1164*05b00f60SXin LiAC_DEFUN(AC_LBL_LIBRARY_NET, [
1165*05b00f60SXin Li    # Most operating systems have gethostbyname() in the default searched
1166*05b00f60SXin Li    # libraries (i.e. libc):
1167*05b00f60SXin Li    # Some OSes (eg. Solaris) place it in libnsl
1168*05b00f60SXin Li    # Some strange OSes (SINIX) have it in libsocket:
1169*05b00f60SXin Li    AC_SEARCH_LIBS(gethostbyname, nsl socket resolv)
1170*05b00f60SXin Li    # Unfortunately libsocket sometimes depends on libnsl and
1171*05b00f60SXin Li    # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this.
1172*05b00f60SXin Li    if test "$ac_cv_search_gethostbyname" = "no"
1173*05b00f60SXin Li    then
1174*05b00f60SXin Li	AC_CHECK_LIB(socket, gethostbyname,
1175*05b00f60SXin Li                     LIBS="-lsocket -lnsl $LIBS", , -lnsl)
1176*05b00f60SXin Li    fi
1177*05b00f60SXin Li    AC_SEARCH_LIBS(socket, socket, ,
1178*05b00f60SXin Li	AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl))
1179*05b00f60SXin Li    # DLPI needs putmsg under HPUX so test for -lstr while we're at it
1180*05b00f60SXin Li    AC_SEARCH_LIBS(putmsg, str)
1181*05b00f60SXin Li    ])
1182*05b00f60SXin Li
1183*05b00f60SXin Lidnl Copyright (c) 1999 WIDE Project. All rights reserved.
1184*05b00f60SXin Lidnl
1185*05b00f60SXin Lidnl Redistribution and use in source and binary forms, with or without
1186*05b00f60SXin Lidnl modification, are permitted provided that the following conditions
1187*05b00f60SXin Lidnl are met:
1188*05b00f60SXin Lidnl 1. Redistributions of source code must retain the above copyright
1189*05b00f60SXin Lidnl    notice, this list of conditions and the following disclaimer.
1190*05b00f60SXin Lidnl 2. Redistributions in binary form must reproduce the above copyright
1191*05b00f60SXin Lidnl    notice, this list of conditions and the following disclaimer in the
1192*05b00f60SXin Lidnl    documentation and/or other materials provided with the distribution.
1193*05b00f60SXin Lidnl 3. Neither the name of the project nor the names of its contributors
1194*05b00f60SXin Lidnl    may be used to endorse or promote products derived from this software
1195*05b00f60SXin Lidnl    without specific prior written permission.
1196*05b00f60SXin Lidnl
1197*05b00f60SXin Lidnl THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1198*05b00f60SXin Lidnl ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1199*05b00f60SXin Lidnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1200*05b00f60SXin Lidnl ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
1201*05b00f60SXin Lidnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1202*05b00f60SXin Lidnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1203*05b00f60SXin Lidnl OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1204*05b00f60SXin Lidnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1205*05b00f60SXin Lidnl LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1206*05b00f60SXin Lidnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1207*05b00f60SXin Lidnl SUCH DAMAGE.
1208*05b00f60SXin Li
1209*05b00f60SXin LiAC_DEFUN(AC_LBL_SSLEAY,
1210*05b00f60SXin Li    [
1211*05b00f60SXin Li	#
1212*05b00f60SXin Li	# Find the last component of $libdir; it's not necessarily
1213*05b00f60SXin Li	# "lib" - it might be "lib64" on, for example, x86-64
1214*05b00f60SXin Li	# Linux systems.
1215*05b00f60SXin Li	#
1216*05b00f60SXin Li	# We assume the directory in which we're looking for
1217*05b00f60SXin Li	# libcrypto has a subdirectory with that as its name.
1218*05b00f60SXin Li	#
1219*05b00f60SXin Li	tmplib=`echo "$libdir" | sed 's,.*/,,'`
1220*05b00f60SXin Li
1221*05b00f60SXin Li	#
1222*05b00f60SXin Li	# XXX - is there a better way to check if a given library is
1223*05b00f60SXin Li	# in a given directory than checking each of the possible
1224*05b00f60SXin Li	# shared library suffixes?
1225*05b00f60SXin Li	#
1226*05b00f60SXin Li	# Are there any other suffixes we need to look for?  Do we
1227*05b00f60SXin Li	# have to worry about ".so.{version}"?
1228*05b00f60SXin Li	#
1229*05b00f60SXin Li	# Or should we just look for "libcrypto.*"?
1230*05b00f60SXin Li	#
1231*05b00f60SXin Li	if test -d "$1/$tmplib" -a \( -f "$1/$tmplib/libcrypto.a" -o \
1232*05b00f60SXin Li				    -f "$1/$tmplib/libcrypto.so" -o \
1233*05b00f60SXin Li				    -f "$1/$tmplib/libcrypto.sl" -o \
1234*05b00f60SXin Li				    -f "$1/$tmplib/libcrypto.dylib" \); then
1235*05b00f60SXin Li		ac_cv_ssleay_path="$1"
1236*05b00f60SXin Li	fi
1237*05b00f60SXin Li
1238*05b00f60SXin Li	#
1239*05b00f60SXin Li	# Make sure we have the headers as well.
1240*05b00f60SXin Li	#
1241*05b00f60SXin Li	if test -d "$1/include/openssl" -a -f "$1/include/openssl/des.h"; then
1242*05b00f60SXin Li		incdir="-I$1/include"
1243*05b00f60SXin Li	fi
1244*05b00f60SXin Li])
1245