xref: /netbsd-src/external/bsd/tcpdump/dist/aclocal.m4 (revision c41df9f6167ea7cd2f761f0a97783c8267cb8847)
10f74e101Schristosdnl Copyright (c) 1995, 1996, 1997, 1998
20f74e101Schristosdnl	The Regents of the University of California.  All rights reserved.
30f74e101Schristosdnl
40f74e101Schristosdnl Redistribution and use in source and binary forms, with or without
50f74e101Schristosdnl modification, are permitted provided that: (1) source code distributions
60f74e101Schristosdnl retain the above copyright notice and this paragraph in its entirety, (2)
70f74e101Schristosdnl distributions including binary code include the above copyright notice and
80f74e101Schristosdnl this paragraph in its entirety in the documentation or other materials
90f74e101Schristosdnl provided with the distribution, and (3) all advertising materials mentioning
100f74e101Schristosdnl features or use of this software display the following acknowledgement:
110f74e101Schristosdnl ``This product includes software developed by the University of California,
120f74e101Schristosdnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
130f74e101Schristosdnl the University nor the names of its contributors may be used to endorse
140f74e101Schristosdnl or promote products derived from this software without specific prior
150f74e101Schristosdnl written permission.
160f74e101Schristosdnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
170f74e101Schristosdnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
180f74e101Schristosdnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
190f74e101Schristosdnl
200f74e101Schristosdnl LBL autoconf macros
210f74e101Schristosdnl
220f74e101Schristos
230f74e101Schristosdnl
240f74e101Schristosdnl Do whatever AC_LBL_C_INIT work is necessary before using AC_PROG_CC.
250f74e101Schristosdnl
260f74e101Schristosdnl It appears that newer versions of autoconf (2.64 and later) will,
270f74e101Schristosdnl if you use AC_TRY_COMPILE in a macro, stick AC_PROG_CC at the
280f74e101Schristosdnl beginning of the macro, even if the macro itself calls AC_PROG_CC.
290f74e101Schristosdnl See the "Prerequisite Macros" and "Expanded Before Required" sections
300f74e101Schristosdnl in the Autoconf documentation.
310f74e101Schristosdnl
320f74e101Schristosdnl This causes a steaming heap of fail in our case, as we were, in
330f74e101Schristosdnl AC_LBL_C_INIT, doing the tests we now do in AC_LBL_C_INIT_BEFORE_CC,
340f74e101Schristosdnl calling AC_PROG_CC, and then doing the tests we now do in
350f74e101Schristosdnl AC_LBL_C_INIT.  Now, we run AC_LBL_C_INIT_BEFORE_CC, AC_PROG_CC,
360f74e101Schristosdnl and AC_LBL_C_INIT at the top level.
370f74e101Schristosdnl
380f74e101SchristosAC_DEFUN(AC_LBL_C_INIT_BEFORE_CC,
39026d7285Schristos[
400f74e101Schristos    AC_BEFORE([$0], [AC_LBL_C_INIT])
410f74e101Schristos    AC_BEFORE([$0], [AC_PROG_CC])
420f74e101Schristos    AC_BEFORE([$0], [AC_LBL_DEVEL])
430f74e101Schristos    AC_ARG_WITH(gcc, [  --without-gcc           don't use gcc])
44026d7285Schristos    $1=""
450f74e101Schristos    if test "${srcdir}" != "." ; then
46026d7285Schristos	    $1="-I$srcdir"
470f74e101Schristos    fi
480f74e101Schristos    if test "${CFLAGS+set}" = set; then
490f74e101Schristos	    LBL_CFLAGS="$CFLAGS"
500f74e101Schristos    fi
510f74e101Schristos    if test -z "$CC" ; then
520f74e101Schristos	    case "$host_os" in
530f74e101Schristos
540f74e101Schristos	    bsdi*)
550f74e101Schristos		    AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
560f74e101Schristos		    if test $SHLICC2 = yes ; then
570f74e101Schristos			    CC=shlicc2
580f74e101Schristos			    export CC
590f74e101Schristos		    fi
600f74e101Schristos		    ;;
610f74e101Schristos	    esac
620f74e101Schristos    fi
630f74e101Schristos    if test -z "$CC" -a "$with_gcc" = no ; then
640f74e101Schristos	    CC=cc
650f74e101Schristos	    export CC
660f74e101Schristos    fi
670f74e101Schristos])
680f74e101Schristos
690f74e101Schristosdnl
700f74e101Schristosdnl Determine which compiler we're using (cc or gcc)
710f74e101Schristosdnl If using gcc, determine the version number
72026d7285Schristosdnl If using cc:
73026d7285Schristosdnl     require that it support ansi prototypes
74026d7285Schristosdnl     use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to
75026d7285Schristosdnl     do that ourselves for gcc)
76026d7285Schristosdnl     add -g flags, as appropriate
77026d7285Schristosdnl     explicitly specify /usr/local/include
78026d7285Schristosdnl
79026d7285Schristosdnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler
80026d7285Schristosdnl that defines __GNUC__, which means clang, for example, counts as "gcc".
810f74e101Schristosdnl
820f74e101Schristosdnl usage:
830f74e101Schristosdnl
840f74e101Schristosdnl	AC_LBL_C_INIT(copt, incls)
850f74e101Schristosdnl
860f74e101Schristosdnl results:
870f74e101Schristosdnl
880f74e101Schristosdnl	$1 (copt set)
890f74e101Schristosdnl	$2 (incls set)
900f74e101Schristosdnl	CC
910f74e101Schristosdnl	LDFLAGS
920f74e101Schristosdnl	LBL_CFLAGS
930f74e101Schristosdnl
940f74e101SchristosAC_DEFUN(AC_LBL_C_INIT,
95026d7285Schristos[
960f74e101Schristos    AC_BEFORE([$0], [AC_LBL_DEVEL])
970f74e101Schristos    if test "$GCC" = yes ; then
98026d7285Schristos	    #
99026d7285Schristos	    # -Werror forces warnings to be errors.
100026d7285Schristos	    #
101026d7285Schristos	    ac_lbl_cc_force_warning_errors=-Werror
1020f74e101Schristos    else
1030f74e101Schristos	    $2="$$2 -I/usr/local/include"
1040f74e101Schristos	    LDFLAGS="$LDFLAGS -L/usr/local/lib"
1050f74e101Schristos
1060f74e101Schristos	    case "$host_os" in
1070f74e101Schristos
108026d7285Schristos	    darwin*)
109026d7285Schristos		    #
110026d7285Schristos		    # This is assumed either to be GCC or clang, both
111026d7285Schristos		    # of which use -Werror to force warnings to be errors.
112026d7285Schristos		    #
113026d7285Schristos		    ac_lbl_cc_force_warning_errors=-Werror
114026d7285Schristos		    ;;
115026d7285Schristos
116026d7285Schristos	    hpux*)
117026d7285Schristos		    #
118026d7285Schristos		    # HP C, which is what we presume we're using, doesn't
119026d7285Schristos		    # exit with a non-zero exit status if we hand it an
120026d7285Schristos		    # invalid -W flag, can't be forced to do so even with
121026d7285Schristos		    # +We, and doesn't handle GCC-style -W flags, so we
122026d7285Schristos		    # don't want to try using GCC-style -W flags.
123026d7285Schristos		    #
124026d7285Schristos		    ac_lbl_cc_dont_try_gcc_dashW=yes
125026d7285Schristos		    ;;
126026d7285Schristos
1270f74e101Schristos	    irix*)
128026d7285Schristos		    #
129026d7285Schristos		    # MIPS C, which is what we presume we're using, doesn't
130026d7285Schristos		    # necessarily exit with a non-zero exit status if we
131026d7285Schristos		    # hand it an invalid -W flag, can't be forced to do
132026d7285Schristos		    # so, and doesn't handle GCC-style -W flags, so we
133026d7285Schristos		    # don't want to try using GCC-style -W flags.
134026d7285Schristos		    #
135026d7285Schristos		    ac_lbl_cc_dont_try_gcc_dashW=yes
136026d7285Schristos		    #
137026d7285Schristos		    # It also, apparently, defaults to "char" being
138026d7285Schristos		    # unsigned, unlike most other C implementations;
139026d7285Schristos		    # I suppose we could say "signed char" whenever
140026d7285Schristos		    # we want to guarantee a signed "char", but let's
141026d7285Schristos		    # just force signed chars.
142026d7285Schristos		    #
143026d7285Schristos		    # -xansi is normally the default, but the
144026d7285Schristos		    # configure script was setting it; perhaps -cckr
145026d7285Schristos		    # was the default in the Old Days.  (Then again,
146026d7285Schristos		    # that would probably be for backwards compatibility
147026d7285Schristos		    # in the days when ANSI C was Shiny and New, i.e.
148026d7285Schristos		    # 1989 and the early '90's, so maybe we can just
149026d7285Schristos		    # drop support for those compilers.)
150026d7285Schristos		    #
151026d7285Schristos		    # -g is equivalent to -g2, which turns off
152026d7285Schristos		    # optimization; we choose -g3, which generates
153026d7285Schristos		    # debugging information but doesn't turn off
154026d7285Schristos		    # optimization (even if the optimization would
155026d7285Schristos		    # cause inaccuracies in debugging).
156026d7285Schristos		    #
157026d7285Schristos		    $1="$$1 -xansi -signed -g3"
1580f74e101Schristos		    ;;
1590f74e101Schristos
1600f74e101Schristos	    osf*)
1610f74e101Schristos		    #
1620f74e101Schristos		    # Presumed to be DEC OSF/1, Digital UNIX, or
1630f74e101Schristos		    # Tru64 UNIX.
1640f74e101Schristos		    #
165026d7285Schristos		    # The DEC C compiler, which is what we presume we're
166026d7285Schristos		    # using, doesn't exit with a non-zero exit status if we
167026d7285Schristos		    # hand it an invalid -W flag, can't be forced to do
168026d7285Schristos		    # so, and doesn't handle GCC-style -W flags, so we
169026d7285Schristos		    # don't want to try using GCC-style -W flags.
170026d7285Schristos		    #
171026d7285Schristos		    ac_lbl_cc_dont_try_gcc_dashW=yes
172026d7285Schristos		    #
173026d7285Schristos		    # -g is equivalent to -g2, which turns off
174026d7285Schristos		    # optimization; we choose -g3, which generates
175026d7285Schristos		    # debugging information but doesn't turn off
176026d7285Schristos		    # optimization (even if the optimization would
177026d7285Schristos		    # cause inaccuracies in debugging).
178026d7285Schristos		    #
179026d7285Schristos		    $1="$$1 -g3"
180026d7285Schristos		    ;;
181026d7285Schristos
182026d7285Schristos	    solaris*)
183026d7285Schristos		    #
184026d7285Schristos		    # Assumed to be Sun C, which requires -errwarn to force
185026d7285Schristos		    # warnings to be treated as errors.
186026d7285Schristos		    #
187026d7285Schristos		    ac_lbl_cc_force_warning_errors=-errwarn
1880f74e101Schristos		    ;;
1890f74e101Schristos
1900f74e101Schristos	    ultrix*)
1910f74e101Schristos		    AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
1920f74e101Schristos		    AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
1930f74e101Schristos			AC_TRY_COMPILE(
1940f74e101Schristos			    [#include <sys/types.h>],
1950f74e101Schristos			    [struct a { int b; };
1960f74e101Schristos			    void c(const struct a *)],
1970f74e101Schristos			    ac_cv_lbl_cc_const_proto=yes,
1980f74e101Schristos			    ac_cv_lbl_cc_const_proto=no))
1990f74e101Schristos		    AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
2000f74e101Schristos		    if test $ac_cv_lbl_cc_const_proto = no ; then
2010f74e101Schristos			    AC_DEFINE(const,[],
2020f74e101Schristos			        [to handle Ultrix compilers that don't support const in prototypes])
2030f74e101Schristos		    fi
2040f74e101Schristos		    ;;
2050f74e101Schristos	    esac
206026d7285Schristos	    $1="$$1 -O"
2070f74e101Schristos    fi
2080f74e101Schristos])
2090f74e101Schristos
210026d7285Schristosdnl
211*c41df9f6Schristosdnl Save the values of various variables that affect compilation and
212*c41df9f6Schristosdnl linking, and that we don't ourselves modify persistently; done
213*c41df9f6Schristosdnl before a test involving compiling or linking is done, so that we
214*c41df9f6Schristosdnl can restore those variables after the test is done.
215*c41df9f6Schristosdnl
216*c41df9f6SchristosAC_DEFUN(AC_LBL_SAVE_CHECK_STATE,
217*c41df9f6Schristos[
218*c41df9f6Schristos	save_CFLAGS="$CFLAGS"
219*c41df9f6Schristos	save_LIBS="$LIBS"
220*c41df9f6Schristos	save_LDFLAGS="$LDFLAGS"
221*c41df9f6Schristos])
222*c41df9f6Schristos
223*c41df9f6Schristosdnl
224*c41df9f6Schristosdnl Restore the values of variables saved by AC_LBL_SAVE_CHECK_STATE.
225*c41df9f6Schristosdnl
226*c41df9f6SchristosAC_DEFUN(AC_LBL_RESTORE_CHECK_STATE,
227*c41df9f6Schristos[
228*c41df9f6Schristos	CFLAGS="$save_CFLAGS"
229*c41df9f6Schristos	LIBS="$save_LIBS"
230*c41df9f6Schristos	LDFLAGS="$save_LDFLAGS"
231*c41df9f6Schristos])
232*c41df9f6Schristos
233*c41df9f6Schristosdnl
234026d7285Schristosdnl Check whether the compiler option specified as the second argument
235026d7285Schristosdnl is supported by the compiler and, if so, add it to the macro
236026d7285Schristosdnl specified as the first argument
237026d7285Schristosdnl
238026d7285SchristosAC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
239026d7285Schristos    [
240026d7285Schristos	AC_MSG_CHECKING([whether the compiler supports the $2 option])
241026d7285Schristos	save_CFLAGS="$CFLAGS"
242784088dfSchristos	CFLAGS="$CFLAGS $2"
243d881c474Schristos	#
244d881c474Schristos	# XXX - yes, this depends on the way AC_LANG_WERROR works,
245d881c474Schristos	# but no mechanism is provided to turn AC_LANG_WERROR on
246d881c474Schristos	# *and then turn it back off*, so that we *only* do it when
247d881c474Schristos	# testing compiler options - 15 years after somebody asked
248d881c474Schristos	# for it:
249d881c474Schristos	#
250d881c474Schristos	#     https://autoconf.gnu.narkive.com/gTAVmfKD/how-to-cancel-flags-set-by-ac-lang-werror
251d881c474Schristos	#
252d881c474Schristos	save_ac_c_werror_flag="$ac_c_werror_flag"
253d881c474Schristos	ac_c_werror_flag=yes
254d881c474Schristos	#
255d881c474Schristos	# We use AC_LANG_SOURCE() so that we can control the complete
256d881c474Schristos	# content of the program being compiled.  We do not, for example,
257d881c474Schristos	# want the default "int main()" that AC_LANG_PROGRAM() generates,
258d881c474Schristos	# as it will generate a warning with -Wold-style-definition, meaning
259d881c474Schristos	# that we would treat it as not working, as the test will fail if
260d881c474Schristos	# *any* error output, including a warning due to the flag we're
261d881c474Schristos	# testing, is generated; see
262d881c474Schristos	#
263d881c474Schristos	#    https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
264d881c474Schristos	#    https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
265d881c474Schristos	#
266d881c474Schristos	# This may, as per those two messages, be fixed in autoconf 2.70,
267*c41df9f6Schristos	# but we only require 2.69 or newer for now.
268d881c474Schristos	#
269d881c474Schristos	AC_COMPILE_IFELSE(
270d881c474Schristos	    [AC_LANG_SOURCE([[int main(void) { return 0; }]])],
271026d7285Schristos	    [
272026d7285Schristos		AC_MSG_RESULT([yes])
273026d7285Schristos		CFLAGS="$save_CFLAGS"
274026d7285Schristos		$1="$$1 $2"
275026d7285Schristos	    ],
276026d7285Schristos	    [
277026d7285Schristos		AC_MSG_RESULT([no])
278026d7285Schristos		CFLAGS="$save_CFLAGS"
279026d7285Schristos	    ])
280d881c474Schristos	ac_c_werror_flag="$save_ac_c_werror_flag"
281026d7285Schristos    ])
282026d7285Schristos
283026d7285Schristosdnl
284026d7285Schristosdnl Check whether the compiler supports an option to generate
285026d7285Schristosdnl Makefile-style dependency lines
286026d7285Schristosdnl
287026d7285Schristosdnl GCC uses -M for this.  Non-GCC compilers that support this
288026d7285Schristosdnl use a variety of flags, including but not limited to -M.
289026d7285Schristosdnl
290026d7285Schristosdnl We test whether the flag in question is supported, as older
291026d7285Schristosdnl versions of compilers might not support it.
292026d7285Schristosdnl
293026d7285Schristosdnl We don't try all the possible flags, just in case some flag means
294026d7285Schristosdnl "generate dependencies" on one compiler but means something else
295026d7285Schristosdnl on another compiler.
296026d7285Schristosdnl
297026d7285Schristosdnl Most compilers that support this send the output to the standard
298026d7285Schristosdnl output by default.  IBM's XLC, however, supports -M but sends
299026d7285Schristosdnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
300026d7285Schristosdnl to work around that, so we don't bother with XLC.
301026d7285Schristosdnl
302026d7285SchristosAC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
303026d7285Schristos    [
304026d7285Schristos	AC_MSG_CHECKING([whether the compiler supports generating dependencies])
305026d7285Schristos	if test "$GCC" = yes ; then
306026d7285Schristos		#
307026d7285Schristos		# GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
308026d7285Schristos		# though it's not); we assume that, in this case, the flag
309026d7285Schristos		# would be -M.
310026d7285Schristos		#
311026d7285Schristos		ac_lbl_dependency_flag="-M"
312026d7285Schristos	else
313026d7285Schristos		#
314026d7285Schristos		# Not GCC or a compiler deemed to be GCC; what platform is
315026d7285Schristos		# this?  (We're assuming that if the compiler isn't GCC
316026d7285Schristos		# it's the compiler from the vendor of the OS; that won't
317026d7285Schristos		# necessarily be true for x86 platforms, where it might be
318026d7285Schristos		# the Intel C compiler.)
319026d7285Schristos		#
320026d7285Schristos		case "$host_os" in
321026d7285Schristos
322026d7285Schristos		irix*|osf*|darwin*)
323026d7285Schristos			#
324026d7285Schristos			# MIPS C for IRIX, DEC C, and clang all use -M.
325026d7285Schristos			#
326026d7285Schristos			ac_lbl_dependency_flag="-M"
327026d7285Schristos			;;
328026d7285Schristos
329026d7285Schristos		solaris*)
330026d7285Schristos			#
331026d7285Schristos			# Sun C uses -xM.
332026d7285Schristos			#
333026d7285Schristos			ac_lbl_dependency_flag="-xM"
334026d7285Schristos			;;
335026d7285Schristos
336026d7285Schristos		hpux*)
337026d7285Schristos			#
338026d7285Schristos			# HP's older C compilers don't support this.
339026d7285Schristos			# HP's newer C compilers support this with
340026d7285Schristos			# either +M or +Make; the older compilers
341026d7285Schristos			# interpret +M as something completely
342026d7285Schristos			# different, so we use +Make so we don't
343026d7285Schristos			# think it works with the older compilers.
344026d7285Schristos			#
345026d7285Schristos			ac_lbl_dependency_flag="+Make"
346026d7285Schristos			;;
347026d7285Schristos
348026d7285Schristos		*)
349026d7285Schristos			#
350026d7285Schristos			# Not one of the above; assume no support for
351026d7285Schristos			# generating dependencies.
352026d7285Schristos			#
353026d7285Schristos			ac_lbl_dependency_flag=""
354026d7285Schristos			;;
355026d7285Schristos		esac
356026d7285Schristos	fi
357026d7285Schristos
358026d7285Schristos	#
359026d7285Schristos	# Is ac_lbl_dependency_flag defined and, if so, does the compiler
360026d7285Schristos	# complain about it?
361026d7285Schristos	#
362026d7285Schristos	# Note: clang doesn't seem to exit with an error status when handed
363026d7285Schristos	# an unknown non-warning error, even if you pass it
364026d7285Schristos	# -Werror=unknown-warning-option.  However, it always supports
365026d7285Schristos	# -M, so the fact that this test always succeeds with clang
366026d7285Schristos	# isn't an issue.
367026d7285Schristos	#
368026d7285Schristos	if test ! -z "$ac_lbl_dependency_flag"; then
369026d7285Schristos		AC_LANG_CONFTEST(
370026d7285Schristos		    [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
371d881c474Schristos		if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
372026d7285Schristos			AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
373026d7285Schristos			DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
374d881c474Schristos			MKDEP='${top_srcdir}/mkdep'
375026d7285Schristos		else
376026d7285Schristos			AC_MSG_RESULT([no])
377026d7285Schristos			#
378026d7285Schristos			# We can't run mkdep, so have "make depend" do
379026d7285Schristos			# nothing.
380026d7285Schristos			#
381026d7285Schristos			MKDEP=:
382026d7285Schristos		fi
383026d7285Schristos		rm -rf conftest*
384026d7285Schristos	else
385026d7285Schristos		AC_MSG_RESULT([no])
386026d7285Schristos		#
387026d7285Schristos		# We can't run mkdep, so have "make depend" do
388026d7285Schristos		# nothing.
389026d7285Schristos		#
390026d7285Schristos		MKDEP=:
391026d7285Schristos	fi
392026d7285Schristos	AC_SUBST(DEPENDENCY_CFLAG)
393026d7285Schristos	AC_SUBST(MKDEP)
394026d7285Schristos    ])
395026d7285Schristos
3960f74e101Schristos#
3970f74e101Schristos# Try compiling a sample of the type of code that appears in
3980f74e101Schristos# gencode.c with "inline", "__inline__", and "__inline".
3990f74e101Schristos#
4000f74e101Schristos# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
4010f74e101Schristos# as it just tests whether a function returning "int" can be inlined;
4020f74e101Schristos# at least some versions of HP's C compiler can inline that, but can't
4030f74e101Schristos# inline a function that returns a struct pointer.
4040f74e101Schristos#
4050f74e101Schristos# Make sure we use the V_CCOPT flags, because some of those might
4060f74e101Schristos# disable inlining.
4070f74e101Schristos#
4080f74e101SchristosAC_DEFUN(AC_LBL_C_INLINE,
4090f74e101Schristos    [AC_MSG_CHECKING(for inline)
4100f74e101Schristos    save_CFLAGS="$CFLAGS"
4110f74e101Schristos    CFLAGS="$V_CCOPT"
4120f74e101Schristos    AC_CACHE_VAL(ac_cv_lbl_inline, [
4130f74e101Schristos	ac_cv_lbl_inline=""
4140f74e101Schristos	ac_lbl_cc_inline=no
4150f74e101Schristos	for ac_lbl_inline in inline __inline__ __inline
4160f74e101Schristos	do
4170f74e101Schristos	    AC_TRY_COMPILE(
4180f74e101Schristos		[#define inline $ac_lbl_inline
4190f74e101Schristos		static inline struct iltest *foo(void);
4200f74e101Schristos		struct iltest {
4210f74e101Schristos		    int iltest1;
4220f74e101Schristos		    int iltest2;
4230f74e101Schristos		};
4240f74e101Schristos
4250f74e101Schristos		static inline struct iltest *
4260f74e101Schristos		foo()
4270f74e101Schristos		{
4280f74e101Schristos		    static struct iltest xxx;
4290f74e101Schristos
4300f74e101Schristos		    return &xxx;
4310f74e101Schristos		}],,ac_lbl_cc_inline=yes,)
4320f74e101Schristos	    if test "$ac_lbl_cc_inline" = yes ; then
4330f74e101Schristos		break;
4340f74e101Schristos	    fi
4350f74e101Schristos	done
4360f74e101Schristos	if test "$ac_lbl_cc_inline" = yes ; then
4370f74e101Schristos	    ac_cv_lbl_inline=$ac_lbl_inline
4380f74e101Schristos	fi])
4390f74e101Schristos    CFLAGS="$save_CFLAGS"
4400f74e101Schristos    if test ! -z "$ac_cv_lbl_inline" ; then
4410f74e101Schristos	AC_MSG_RESULT($ac_cv_lbl_inline)
4420f74e101Schristos    else
4430f74e101Schristos	AC_MSG_RESULT(no)
4440f74e101Schristos    fi
4450f74e101Schristos    AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
4460f74e101Schristos
4470f74e101Schristosdnl
4480f74e101Schristosdnl Use pfopen.c if available and pfopen() not in standard libraries
4490f74e101Schristosdnl Require libpcap
450d881c474Schristosdnl Look for libpcap in directories under ..; those are local versions.
451d881c474Schristosdnl Look for an installed libpcap if there is no local version or if
452d881c474Schristosdnl the user said not to look for a local version.
4530f74e101Schristosdnl
4540f74e101Schristosdnl usage:
4550f74e101Schristosdnl
4560f74e101Schristosdnl	AC_LBL_LIBPCAP(pcapdep, incls)
4570f74e101Schristosdnl
4580f74e101Schristosdnl results:
4590f74e101Schristosdnl
4600f74e101Schristosdnl	$1 (pcapdep set)
4610f74e101Schristosdnl	$2 (incls appended)
4620f74e101Schristosdnl	LIBS
4630f74e101Schristosdnl	LBL_LIBS
4640f74e101Schristosdnl
4650f74e101SchristosAC_DEFUN(AC_LBL_LIBPCAP,
466*c41df9f6Schristos[
467*c41df9f6Schristos    AC_REQUIRE([AC_PROG_EGREP])
468*c41df9f6Schristos    AC_REQUIRE([AC_LBL_LIBRARY_NET])
4690f74e101Schristos    dnl
4700f74e101Schristos    dnl save a copy before locating libpcap.a
4710f74e101Schristos    dnl
4720f74e101Schristos    LBL_LIBS="$LIBS"
4730f74e101Schristos    pfopen=/usr/examples/packetfilter/pfopen.c
4740f74e101Schristos    if test -f $pfopen ; then
4750f74e101Schristos        AC_CHECK_FUNCS(pfopen)
4760f74e101Schristos        if test $ac_cv_func_pfopen = "no" ; then
4770f74e101Schristos            AC_MSG_RESULT(Using $pfopen)
4780f74e101Schristos            LIBS="$LIBS $pfopen"
4790f74e101Schristos        fi
4800f74e101Schristos    fi
4810f74e101Schristos    libpcap=FAIL
482d881c474Schristos    AC_MSG_CHECKING([whether to look for a local libpcap])
483d881c474Schristos    AC_ARG_ENABLE(local-libpcap,
484d881c474Schristos        AS_HELP_STRING([--disable-local-libpcap],
485d881c474Schristos                       [don't look for a local libpcap @<:@default=check for a local libpcap@:>@]),,
486d881c474Schristos        enableval=yes)
487d881c474Schristos    case "$enableval" in
488d881c474Schristos
489d881c474Schristos    no)
490d881c474Schristos        AC_MSG_RESULT(no)
491d881c474Schristos        #
492d881c474Schristos        # Don't look for a local libpcap.
493d881c474Schristos        #
494d881c474Schristos        using_local_libpcap=no
495d881c474Schristos        ;;
496d881c474Schristos
497d881c474Schristos    *)
498d881c474Schristos        AC_MSG_RESULT(yes)
499d881c474Schristos        #
500d881c474Schristos        # Look for a local pcap library.
501d881c474Schristos        #
5023d25ea14Schristos        AC_MSG_CHECKING(for local pcap library)
5030f74e101Schristos        lastdir=FAIL
5040f74e101Schristos        places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
505*c41df9f6Schristos            $EGREP '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
506c47fd378Schristos        places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
507*c41df9f6Schristos            $EGREP '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
508c47fd378Schristos        for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
5090f74e101Schristos            basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//' | \
5100f74e101Schristos                sed -e 's/-PRE-GIT$//' `
5110f74e101Schristos            if test $lastdir = $basedir ; then
5120f74e101Schristos                dnl skip alphas when an actual release is present
5130f74e101Schristos                continue;
5140f74e101Schristos            fi
5150f74e101Schristos            lastdir=$dir
5160f74e101Schristos            if test -r $dir/libpcap.a ; then
5170f74e101Schristos                libpcap=$dir/libpcap.a
518d881c474Schristos                local_pcap_dir=$dir
5190f74e101Schristos                dnl continue and select the last one that exists
5200f74e101Schristos            fi
5210f74e101Schristos        done
5220f74e101Schristos        if test $libpcap = FAIL ; then
523d881c474Schristos            #
524d881c474Schristos            # We didn't find a local libpcap.
525d881c474Schristos            #
5260f74e101Schristos            AC_MSG_RESULT(not found)
527d881c474Schristos            using_local_libpcap=no;
528d881c474Schristos        else
529d881c474Schristos            #
530d881c474Schristos            # We found a local libpcap.
531d881c474Schristos            #
532d881c474Schristos            AC_MSG_RESULT($libpcap)
533d881c474Schristos            using_local_libpcap=yes
534d881c474Schristos        fi
535d881c474Schristos        ;;
536d881c474Schristos    esac
5370f74e101Schristos
538d881c474Schristos    if test $using_local_libpcap = no ; then
5390f74e101Schristos        #
540d881c474Schristos        # We didn't find a local libpcap.
541d881c474Schristos        # Look for an installed pkg-config.
5420f74e101Schristos        #
543d881c474Schristos        if test -n "$PKG_CONFIG" ; then
5440f74e101Schristos            #
545d881c474Schristos            # We have it.  Are there .pc files for libpcap?
546d881c474Schristos            #
547d881c474Schristos            # --exists was introduced in pkg-config 0.4.0; that
548d881c474Schristos            # dates back to late 2000, so we won't worry about
549d881c474Schristos            # earlier releases that lack it.
550d881c474Schristos            #
551d881c474Schristos            AC_MSG_CHECKING(whether there are .pc files for libpcap)
552d881c474Schristos            if "$PKG_CONFIG" libpcap --exists ; then
553d881c474Schristos                #
554d881c474Schristos                # Yes, so we can use pkg-config to get configuration
555d881c474Schristos                # information for libpcap.
556d881c474Schristos                #
557d881c474Schristos                AC_MSG_RESULT(yes)
558d881c474Schristos                pkg_config_usable=yes
559d881c474Schristos            else
560d881c474Schristos                #
561d881c474Schristos                # No, so we can't use pkg-config to get configuration
562d881c474Schristos                # information for libpcap.
563d881c474Schristos                #
564d881c474Schristos                AC_MSG_RESULT(no)
565d881c474Schristos                pkg_config_usable=no
566d881c474Schristos            fi
567d881c474Schristos        else
568d881c474Schristos            #
569d881c474Schristos            # We don't have it, so we obviously can't use it.
570d881c474Schristos            #
571d881c474Schristos            pkg_config_usable=no
572d881c474Schristos        fi
573d881c474Schristos        if test "$pkg_config_usable" = "yes" ; then
574d881c474Schristos            #
575d881c474Schristos            # Found both - use pkg-config to get the include flags for
5760f74e101Schristos            # libpcap and the flags to link with libpcap.
5770f74e101Schristos            #
5789546e36dSchristos            # Please read section 11.6 "Shell Substitutions"
5799546e36dSchristos            # in the autoconf manual before doing anything
5809546e36dSchristos            # to this that involves quoting.  Especially note
5819546e36dSchristos            # the statement "There is just no portable way to use
5829546e36dSchristos            # double-quoted strings inside double-quoted back-quoted
5839546e36dSchristos            # expressions (pfew!)."
5849546e36dSchristos            #
585d881c474Schristos            cflags=`"$PKG_CONFIG" libpcap --cflags`
5869546e36dSchristos            $2="$cflags $$2"
587d881c474Schristos            libpcap=`"$PKG_CONFIG" libpcap --libs`
5880f74e101Schristos        else
5890f74e101Schristos            #
590d881c474Schristos            # No pkg-config
591d881c474Schristos            # Look for an installed pcap-config.
592d881c474Schristos            #
593d881c474Schristos            AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
594d881c474Schristos            if test -n "$PCAP_CONFIG" ; then
595d881c474Schristos                #
596d881c474Schristos                # Found - use it to get the include flags for
597d881c474Schristos                # libpcap and the flags to link with libpcap.
598d881c474Schristos                #
599d881c474Schristos                # If this is a vendor-supplied pcap-config, which
600d881c474Schristos                # we define as being "a pcap-config in /usr/bin
601d881c474Schristos                # or /usr/ccs/bin" (the latter is for Solaris and
602d881c474Schristos                # Sun/Oracle Studio), there are some issues.  Work
603d881c474Schristos                # around them.
604d881c474Schristos                #
605d881c474Schristos                if test \( "$PCAP_CONFIG" = "/usr/bin/pcap-config" \) -o \
606d881c474Schristos                        \( "$PCAP_CONFIG" = "/usr/ccs/bin/pcap-config" \) ; then
607d881c474Schristos                    #
608d881c474Schristos                    # It's vendor-supplied.
609d881c474Schristos                    #
610d881c474Schristos                    case "$host_os" in
611d881c474Schristos
612d881c474Schristos                    darwin*)
613d881c474Schristos                        #
614d881c474Schristos                        # This is macOS or another Darwin-based OS.
615d881c474Schristos                        #
616d881c474Schristos                        # That means that /usr/bin/pcap-config it
617d881c474Schristos                        # may provide -I/usr/local/include with --cflags
618d881c474Schristos                        # and -L/usr/local/lib with --libs, rather than
619d881c474Schristos                        # pointing to the OS-supplied library and
620d881c474Schristos                        # Xcode-supplied headers.  Remember that, so we
621d881c474Schristos                        # ignore those values.
622d881c474Schristos                        #
623d881c474Schristos                        _broken_apple_pcap_config=yes
624*c41df9f6Schristos
625*c41df9f6Schristos                        #
626*c41df9f6Schristos                        # Furthermore:
627*c41df9f6Schristos                        #
628*c41df9f6Schristos                        # macOS Sonoma's libpcap includes stub versions
629*c41df9f6Schristos                        # of the remote-capture APIs.  They are exported
630*c41df9f6Schristos                        # as "weakly linked symbols".
631*c41df9f6Schristos                        #
632*c41df9f6Schristos                        # Xcode 15 offers only a macOS Sonoma SDK, which
633*c41df9f6Schristos                        # has a .tbd file for libpcap that claims it
634*c41df9f6Schristos                        # includes those APIs.  (Newer versions of macOS
635*c41df9f6Schristos                        # don't provide the system shared libraries,
636*c41df9f6Schristos                        # they only provide the dyld shared cache
637*c41df9f6Schristos                        # containing those libraries, so the OS provides
638*c41df9f6Schristos                        # SDKs that include a .tbd file to use when
639*c41df9f6Schristos                        # linking.)
640*c41df9f6Schristos                        #
641*c41df9f6Schristos                        # This means that AC_CHECK_FUNCS() will think
642*c41df9f6Schristos                        # that the remote-capture APIs are present,
643*c41df9f6Schristos                        # including pcap_open() and
644*c41df9f6Schristos                        # pcap_findalldevs_ex().
645*c41df9f6Schristos                        #
646*c41df9f6Schristos                        # However, they are *not* present in macOS
647*c41df9f6Schristos                        # Ventura and earlier, which means that building
648*c41df9f6Schristos                        # on Ventura with Xcode 15 produces executables
649*c41df9f6Schristos                        # that fail to start because one of those APIs
650*c41df9f6Schristos                        # isn't found in the system libpcap.
651*c41df9f6Schristos                        #
652*c41df9f6Schristos                        # Protecting calls to those APIs with
653*c41df9f6Schristos                        # __builtin_available() does not appear to
654*c41df9f6Schristos                        # prevent this, for some unknown reason, and it
655*c41df9f6Schristos                        # doesn't even allow the program to compile with
656*c41df9f6Schristos                        # versions of Xcode prior to Xcode 15, as the
657*c41df9f6Schristos                        # pcap.h file doesn't specify minimum OS
658*c41df9f6Schristos                        # versions for those functions.
659*c41df9f6Schristos                        #
660*c41df9f6Schristos                        # Given all that, and given that the versions of
661*c41df9f6Schristos                        # the remote-capture APIs in Sonoma are stubs
662*c41df9f6Schristos                        # that always fail, there doesn't seem to be any
663*c41df9f6Schristos                        # point in checking for pcap_open() if we're
664*c41df9f6Schristos                        # linking against the Apple libpcap.
665*c41df9f6Schristos                        #
666*c41df9f6Schristos                        # However, if we're *not* linking against the
667*c41df9f6Schristos                        # Apple libpcap, we should check for it, so that
668*c41df9f6Schristos                        # we can use it if it's present.
669*c41df9f6Schristos                        #
670*c41df9f6Schristos                        # We know this is macOS and that we're using
671*c41df9f6Schristos                        # the system-provided pcap-config to find
672*c41df9f6Schristos                        # libpcap, so we know it'll be the system
673*c41df9f6Schristos                        # libpcap, and note that we should not search
674*c41df9f6Schristos                        # for remote-capture APIs.
675*c41df9f6Schristos                        #
676*c41df9f6Schristos                        _dont_check_for_remote_apis=yes
677d881c474Schristos                        ;;
678d881c474Schristos
679d881c474Schristos                    solaris*)
680d881c474Schristos                        #
681d881c474Schristos                        # This is Solaris 2 or later, i.e. SunOS 5.x.
682d881c474Schristos                        #
683d881c474Schristos                        # At least on Solaris 11; there's /usr/bin/pcap-config,
684d881c474Schristos                        # which reports -L/usr/lib with --libs, causing
685d881c474Schristos                        # the 32-bit libraries to be found, and there's
686d881c474Schristos                        # /usr/bin/{64bitarch}/pcap-config, where {64bitarch}
687d881c474Schristos                        # is a name for the 64-bit version of the instruction
688d881c474Schristos                        # set, which reports -L /usr/lib/{64bitarch}, causing
689d881c474Schristos                        # the 64-bit libraries to be found.
690d881c474Schristos                        #
691d881c474Schristos                        # So if we're building 64-bit targets, we replace
692d881c474Schristos                        # PCAP_CONFIG with /usr/bin/{64bitarch}; we get
693d881c474Schristos                        # {64bitarch} as the output of "isainfo -n".
694d881c474Schristos                        #
695d881c474Schristos                        # Are we building 32-bit or 64-bit?  Get the
696d881c474Schristos                        # size of void *, and check that.
697d881c474Schristos                        #
698d881c474Schristos                        AC_CHECK_SIZEOF([void *])
699d881c474Schristos                        if test ac_cv_sizeof_void_p -eq 8 ; then
700d881c474Schristos                            isainfo_output=`isainfo -n`
701d881c474Schristos                            if test ! -z "$isainfo_output" ; then
702d881c474Schristos                                #
703d881c474Schristos                                # Success - change PCAP_CONFIG.
704d881c474Schristos                                #
705d881c474Schristos                                PCAP_CONFIG=`echo $PCAP_CONFIG | sed "s;/bin/;/bin/$isainfo_output/;"`
706d881c474Schristos                            fi
707d881c474Schristos                        fi
708d881c474Schristos                        ;;
709d881c474Schristos                    esac
710d881c474Schristos                fi
711d881c474Schristos                #
712d881c474Schristos                # Please read section 11.6 "Shell Substitutions"
713d881c474Schristos                # in the autoconf manual before doing anything
714d881c474Schristos                # to this that involves quoting.  Especially note
715d881c474Schristos                # the statement "There is just no portable way to use
716d881c474Schristos                # double-quoted strings inside double-quoted back-quoted
717d881c474Schristos                # expressions (pfew!)."
718d881c474Schristos                #
719d881c474Schristos                cflags=`"$PCAP_CONFIG" --cflags`
720d881c474Schristos                #
721d881c474Schristos                # Work around macOS (and probably other Darwin) brokenness,
722d881c474Schristos                # by not adding /usr/local/include if it's from the broken
723d881c474Schristos                # Apple pcap-config.
724d881c474Schristos                #
725d881c474Schristos                if test "$_broken_apple_pcap_config" = "yes" ; then
726d881c474Schristos                    #
727d881c474Schristos                    # Strip -I/usr/local/include with sed.
728d881c474Schristos                    #
729d881c474Schristos                    cflags=`echo $cflags | sed 's;-I/usr/local/include;;'`
730d881c474Schristos                fi
731d881c474Schristos                $2="$cflags $$2"
732d881c474Schristos                libpcap=`"$PCAP_CONFIG" --libs`
733d881c474Schristos                #
734d881c474Schristos                # Work around macOS (and probably other Darwin) brokenness,
735d881c474Schristos                # by not adding /usr/local/lib if it's from the broken
736d881c474Schristos                # Apple pcap-config.
737d881c474Schristos                #
738d881c474Schristos                if test "$_broken_apple_pcap_config" = "yes" ; then
739d881c474Schristos                    #
740d881c474Schristos                    # Strip -L/usr/local/lib with sed.
741d881c474Schristos                    #
742d881c474Schristos                    libpcap=`echo $libpcap | sed 's;-L/usr/local/lib;;'`
743d881c474Schristos                fi
744d881c474Schristos            else
745d881c474Schristos                #
746d881c474Schristos                # Not found; look for an installed pcap.
7470f74e101Schristos                #
7480f74e101Schristos                AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
7490f74e101Schristos                if test $libpcap = FAIL ; then
750*c41df9f6Schristos                    AC_MSG_ERROR(see the INSTALL.md file for more info)
7510f74e101Schristos                fi
7520f74e101Schristos                dnl
7530f74e101Schristos                dnl Some versions of Red Hat Linux put "pcap.h" in
7540f74e101Schristos                dnl "/usr/include/pcap"; had the LBL folks done so,
7550f74e101Schristos                dnl that would have been a good idea, but for
7560f74e101Schristos                dnl the Red Hat folks to do so just breaks source
7570f74e101Schristos                dnl compatibility with other systems.
7580f74e101Schristos                dnl
7590f74e101Schristos                dnl We work around this by assuming that, as we didn't
7600f74e101Schristos                dnl find a local libpcap, libpcap is in /usr/lib or
7610f74e101Schristos                dnl /usr/local/lib and that the corresponding header
7620f74e101Schristos                dnl file is under one of those directories; if we don't
7630f74e101Schristos                dnl find it in either of those directories, we check to
7640f74e101Schristos                dnl see if it's in a "pcap" subdirectory of them and,
7650f74e101Schristos                dnl if so, add that subdirectory to the "-I" list.
7660f74e101Schristos                dnl
7670f74e101Schristos                dnl (We now also put pcap.h in /usr/include/pcap, but we
7680f74e101Schristos                dnl leave behind a /usr/include/pcap.h that includes it,
7690f74e101Schristos                dnl so you can still just include <pcap.h>.)
7700f74e101Schristos                dnl
7710f74e101Schristos                AC_MSG_CHECKING(for extraneous pcap header directories)
7720f74e101Schristos                if test \( ! -r /usr/local/include/pcap.h \) -a \
7730f74e101Schristos                        \( ! -r /usr/include/pcap.h \); then
7740f74e101Schristos                    if test -r /usr/local/include/pcap/pcap.h; then
7750f74e101Schristos                        d="/usr/local/include/pcap"
7760f74e101Schristos                    elif test -r /usr/include/pcap/pcap.h; then
7770f74e101Schristos                        d="/usr/include/pcap"
7780f74e101Schristos                    fi
7790f74e101Schristos                fi
7800f74e101Schristos                if test -z "$d" ; then
7810f74e101Schristos                    AC_MSG_RESULT(not found)
7820f74e101Schristos                else
7830f74e101Schristos                    $2="-I$d $$2"
7840f74e101Schristos                    AC_MSG_RESULT(found -- -I$d added)
7850f74e101Schristos                fi
7860f74e101Schristos            fi
787d881c474Schristos        fi
7880f74e101Schristos    else
789d881c474Schristos        #
790d881c474Schristos        # We found a local libpcap.  Add it to the dependencies for
791d881c474Schristos        # tcpdump.
792d881c474Schristos        #
7930f74e101Schristos        $1=$libpcap
794d881c474Schristos
795d881c474Schristos        #
796d881c474Schristos        # Look for its pcap-config script.
797d881c474Schristos        #
798d881c474Schristos        AC_PATH_PROG(PCAP_CONFIG, pcap-config,, $local_pcap_dir)
799d881c474Schristos
800d881c474Schristos        if test -n "$PCAP_CONFIG"; then
801d881c474Schristos            #
802d881c474Schristos            # We don't want its --cflags or --libs output, because
803d881c474Schristos            # those presume it's installed.  For the C compiler flags,
804d881c474Schristos            # we add the source directory for the local libpcap, so
805d881c474Schristos            # we pick up its header files.
806d881c474Schristos            #
807d881c474Schristos            # We do, however, want its additional libraries, as required
808d881c474Schristos            # when linking statically, because it makes calls to
809d881c474Schristos            # routines in those libraries, so we'll need to link with
810d881c474Schristos            # them, because we'll be linking statically with it.
811d881c474Schristos            #
812d881c474Schristos            # If it supports --static-pcap-only. use that, as we will be
813d881c474Schristos            # linking with a static libpcap but won't be linking
814d881c474Schristos            # statically with any of the libraries on which it depends;
815d881c474Schristos            # those libraries might not even have static versions
816d881c474Schristos            # installed.
817d881c474Schristos            #
818d881c474Schristos            # That means we need to find out the libraries on which
819d881c474Schristos            # libpcap directly depends, so we can link with them, but we
820d881c474Schristos            # don't need to link with the libraries on which those
821d881c474Schristos            # libraries depend as, on all UN*Xes with which I'm
822d881c474Schristos            # familiar, the libraries on which a shared library depends
823d881c474Schristos            # are stored in the library and are automatically loaded by
824d881c474Schristos            # the run-time linker, without the executable having to be
825d881c474Schristos            # linked with those libraries.  (This allows a library to be
826d881c474Schristos            # changed to depend on more libraries without breaking that
827d881c474Schristos            # library's ABI.)
828d881c474Schristos            #
829d881c474Schristos            # The only way to test for that support is to see if the
830d881c474Schristos            # script contains the string "static-pcap-only"; we can't
831d881c474Schristos            # try using that flag and checking for errors, as the
832d881c474Schristos            # versions of the script that didn't have that flag wouldn't
833d881c474Schristos            # report or return an error for an unsupported command-line
834d881c474Schristos            # flag.  Those older versions provided, with --static, only
835d881c474Schristos            # the libraries on which libpcap depends, not the
836d881c474Schristos            # dependencies of those libraries; the versions with
837d881c474Schristos            # --static-pcap-only provide all the dependencies with
838d881c474Schristos            # --static, for the benefit of programs that are completely
839d881c474Schristos            # statically linked, and provide only the direct
840d881c474Schristos            # dependencies with --static-pcap-only.
841d881c474Schristos            #
842*c41df9f6Schristos            if grep "static-pcap-only" "$PCAP_CONFIG" >/dev/null 2>&1
843d881c474Schristos            then
844d881c474Schristos                static_opt="--static-pcap-only"
845d881c474Schristos            else
846d881c474Schristos                static_opt="--static"
847d881c474Schristos            fi
848d881c474Schristos            $2="-I$local_pcap_dir $$2"
849d881c474Schristos            additional_libs=`"$PCAP_CONFIG" $static_opt --additional-libs`
850d881c474Schristos            libpcap="$libpcap $additional_libs"
851d881c474Schristos        else
852d881c474Schristos            #
853d881c474Schristos            # It doesn't have a pcap-config script.
854d881c474Schristos            # Make sure it has a pcap.h file.
855d881c474Schristos            #
8560f74e101Schristos            places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
857*c41df9f6Schristos                $EGREP '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
858c47fd378Schristos            places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
859*c41df9f6Schristos                $EGREP '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
860c47fd378Schristos            pcapH=FAIL
861d881c474Schristos            if test -r $local_pcap_dir/pcap.h; then
862d881c474Schristos                pcapH=$local_pcap_dir
8630f74e101Schristos            else
864c47fd378Schristos                for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
865c47fd378Schristos                    if test -r $dir/pcap.h ; then
866c47fd378Schristos                        pcapH=$dir
8670f74e101Schristos                    fi
868c47fd378Schristos                done
869c47fd378Schristos            fi
870c47fd378Schristos
871c47fd378Schristos            if test $pcapH = FAIL ; then
872*c41df9f6Schristos                AC_MSG_ERROR(cannot find pcap.h: see the INSTALL.md file)
873c47fd378Schristos            fi
874d881c474Schristos
875d881c474Schristos            #
876d881c474Schristos            # Force the compiler to look for header files in the
877d881c474Schristos            # directory containing pcap.h.
878d881c474Schristos            #
879c47fd378Schristos            $2="-I$pcapH $$2"
8800f74e101Schristos        fi
8810f74e101Schristos    fi
882d881c474Schristos
883d881c474Schristos    if test -z "$PKG_CONFIG" -a -z "$PCAP_CONFIG"; then
8840f74e101Schristos        #
885d881c474Schristos        # We don't have pkg-config or pcap-config; find out any additional
886d881c474Schristos        # link flags we need.  (If we have pkg-config or pcap-config, we
887d881c474Schristos        # assume it tells us what we need.)
8880f74e101Schristos        #
8890f74e101Schristos        case "$host_os" in
8900f74e101Schristos
8910f74e101Schristos        aix*)
8920f74e101Schristos            #
8930f74e101Schristos            # If libpcap is DLPI-based, we have to use /lib/pse.exp if
8940f74e101Schristos            # present, as we use the STREAMS routines.
8950f74e101Schristos            #
8960f74e101Schristos            # (XXX - true only if we're linking with a static libpcap?)
8970f74e101Schristos            #
8980f74e101Schristos            pseexe="/lib/pse.exp"
8990f74e101Schristos            AC_MSG_CHECKING(for $pseexe)
9000f74e101Schristos            if test -f $pseexe ; then
9010f74e101Schristos                AC_MSG_RESULT(yes)
9020f74e101Schristos                LIBS="$LIBS -I:$pseexe"
9030f74e101Schristos            fi
9040f74e101Schristos
9050f74e101Schristos            #
9060f74e101Schristos            # If libpcap is BPF-based, we need "-lodm" and "-lcfg", as
9070f74e101Schristos            # we use them to load the BPF module.
9080f74e101Schristos            #
9090f74e101Schristos            # (XXX - true only if we're linking with a static libpcap?)
9100f74e101Schristos            #
9110f74e101Schristos            LIBS="$LIBS -lodm -lcfg"
9120f74e101Schristos            ;;
913d881c474Schristos
914d881c474Schristos	solaris*)
915d881c474Schristos            # libdlpi is needed for Solaris 11 and later.
916d881c474Schristos            AC_CHECK_LIB(dlpi, dlpi_walk, LIBS="$LIBS -ldlpi" LDFLAGS="-L/lib $LDFLAGS", ,-L/lib)
917d881c474Schristos            ;;
9180f74e101Schristos        esac
9190f74e101Schristos    fi
9200f74e101Schristos
921d881c474Schristos    LIBS="$libpcap $LIBS"
922d881c474Schristos
9230f74e101Schristos    dnl
9249546e36dSchristos    dnl Check for "pcap_loop()", to make sure we found a working
9259546e36dSchristos    dnl libpcap and have all the right other libraries with which
9269546e36dSchristos    dnl to link.  (Otherwise, the checks below will fail, not
9279546e36dSchristos    dnl because the routines are missing from the library, but
9289546e36dSchristos    dnl because we aren't linking properly with libpcap, and
9299546e36dSchristos    dnl that will cause confusing errors at build time.)
9309546e36dSchristos    dnl
9319546e36dSchristos    AC_CHECK_FUNC(pcap_loop,,
9329546e36dSchristos    [
9339546e36dSchristos        AC_MSG_ERROR(
934*c41df9f6Schristos[
935*c41df9f6Schristos1. Do you try to build a 32-bit tcpdump with a 64-bit libpcap or vice versa?
936*c41df9f6Schristos2. This is a bug, please follow the guidelines in CONTRIBUTING.md and include
937*c41df9f6Schristosthe config.log file in your report.  If you have downloaded libpcap from
9389546e36dSchristostcpdump.org, and built it yourself, please also include the config.log
9399546e36dSchristosfile from the libpcap source directory, the Makefile from the libpcap
9409546e36dSchristossource directory, and the output of the make process for libpcap, as
9419546e36dSchristosthis could be a problem with the libpcap that was built, and we will
9429546e36dSchristosnot be able to determine why this is happening, and thus will not be
9439546e36dSchristosable to fix it, without that information, as we have not been able to
9449546e36dSchristosreproduce this problem ourselves.])
9459546e36dSchristos    ])
9460f74e101Schristos])
9470f74e101Schristos
9480f74e101Schristosdnl
9490f74e101Schristosdnl Check whether a given format can be used to print 64-bit integers
9500f74e101Schristosdnl
9510f74e101SchristosAC_DEFUN(AC_LBL_CHECK_64BIT_FORMAT,
9520f74e101Schristos  [
9530f74e101Schristos    AC_MSG_CHECKING([whether %$1x can be used to format 64-bit integers])
9540f74e101Schristos    AC_RUN_IFELSE(
9550f74e101Schristos      [
9560f74e101Schristos	AC_LANG_SOURCE(
9570f74e101Schristos	  [[
9580f74e101Schristos#	    ifdef HAVE_INTTYPES_H
9590f74e101Schristos	    #include <inttypes.h>
9600f74e101Schristos#	    endif
9610f74e101Schristos	    #include <stdio.h>
9620f74e101Schristos	    #include <sys/types.h>
9630f74e101Schristos
9640f74e101Schristos	    main()
9650f74e101Schristos	    {
966c47fd378Schristos	      uint64_t t = 1;
9670f74e101Schristos	      char strbuf[16+1];
9680f74e101Schristos	      sprintf(strbuf, "%016$1x", t << 32);
9690f74e101Schristos	      if (strcmp(strbuf, "0000000100000000") == 0)
9700f74e101Schristos		exit(0);
9710f74e101Schristos	      else
9720f74e101Schristos		exit(1);
9730f74e101Schristos	    }
9740f74e101Schristos	  ]])
9750f74e101Schristos      ],
9760f74e101Schristos      [
977026d7285Schristos	AC_DEFINE(PRId64, "$1d", [define if the platform doesn't define PRId64])
978026d7285Schristos	AC_DEFINE(PRIo64, "$1o", [define if the platform doesn't define PRIo64])
979026d7285Schristos	AC_DEFINE(PRIx64, "$1x", [define if the platform doesn't define PRIu64])
980026d7285Schristos	AC_DEFINE(PRIu64, "$1u", [define if the platform doesn't define PRIx64])
9810f74e101Schristos	AC_MSG_RESULT(yes)
9820f74e101Schristos      ],
9830f74e101Schristos      [
9840f74e101Schristos	AC_MSG_RESULT(no)
9850f74e101Schristos	$2
9860f74e101Schristos      ])
9870f74e101Schristos  ])
9880f74e101Schristos
9890f74e101Schristosdnl
990026d7285Schristosdnl If the file .devel exists:
991026d7285Schristosdnl	Add some warning flags if the compiler supports them
9920f74e101Schristosdnl	If an os prototype include exists, symlink os-proto.h to it
9930f74e101Schristosdnl
9940f74e101Schristosdnl usage:
9950f74e101Schristosdnl
9960f74e101Schristosdnl	AC_LBL_DEVEL(copt)
9970f74e101Schristosdnl
9980f74e101Schristosdnl results:
9990f74e101Schristosdnl
10000f74e101Schristosdnl	$1 (copt appended)
10010f74e101Schristosdnl	HAVE_OS_PROTO_H (defined)
10020f74e101Schristosdnl	os-proto.h (symlinked)
10030f74e101Schristosdnl
10040f74e101SchristosAC_DEFUN(AC_LBL_DEVEL,
10050f74e101Schristos    [rm -f os-proto.h
10060f74e101Schristos    if test "${LBL_CFLAGS+set}" = set; then
10070f74e101Schristos	    $1="$$1 ${LBL_CFLAGS}"
10080f74e101Schristos    fi
10090f74e101Schristos    if test -f .devel ; then
1010026d7285Schristos	    #
1011026d7285Schristos	    # Skip all the warning option stuff on some compilers.
1012026d7285Schristos	    #
1013026d7285Schristos	    if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
1014026d7285Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -W)
1015d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
1016d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wassign-enum)
1017d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wcast-qual)
1018d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
1019d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
1020*c41df9f6Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wnull-pointer-subtraction)
1021d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wold-style-definition)
1022d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpedantic)
1023d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
1024d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
1025d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
1026d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
1027d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
1028*c41df9f6Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wundef)
1029d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code-return)
1030*c41df9f6Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-parameter)
1031*c41df9f6Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-variable)
1032d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
1033d881c474Schristos		    AC_LBL_CHECK_COMPILER_OPT($1, -Wwrite-strings)
10340f74e101Schristos	    fi
1035026d7285Schristos	    AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
1036026d7285Schristos	    #
1037026d7285Schristos	    # We used to set -n32 for IRIX 6 when not using GCC (presumed
1038026d7285Schristos	    # to mean that we're using MIPS C or MIPSpro C); it specified
1039026d7285Schristos	    # the "new" faster 32-bit ABI, introduced in IRIX 6.2.  I'm
1040026d7285Schristos	    # not sure why that would be something to do *only* with a
1041026d7285Schristos	    # .devel file; why should the ABI for which we produce code
1042026d7285Schristos	    # depend on .devel?
1043026d7285Schristos	    #
10440f74e101Schristos	    os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
10450f74e101Schristos	    name="lbl/os-$os.h"
10460f74e101Schristos	    if test -f $name ; then
10470f74e101Schristos		    ln -s $name os-proto.h
10480f74e101Schristos		    AC_DEFINE(HAVE_OS_PROTO_H, 1,
10490f74e101Schristos			[if there's an os_proto.h for this platform, to use additional prototypes])
10500f74e101Schristos	    else
10510f74e101Schristos		    AC_MSG_WARN(can't find $name)
10520f74e101Schristos	    fi
10530f74e101Schristos    fi])
10540f74e101Schristos
10550f74e101Schristosdnl
10560f74e101Schristosdnl Improved version of AC_CHECK_LIB
10570f74e101Schristosdnl
10580f74e101Schristosdnl Thanks to John Hawkinson (jhawk@mit.edu)
10590f74e101Schristosdnl
10600f74e101Schristosdnl usage:
10610f74e101Schristosdnl
10620f74e101Schristosdnl	AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
10630f74e101Schristosdnl	    ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
10640f74e101Schristosdnl
10650f74e101Schristosdnl results:
10660f74e101Schristosdnl
10670f74e101Schristosdnl	LIBS
10680f74e101Schristosdnl
10690f74e101Schristosdnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS"
10700f74e101Schristosdnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more.
10710f74e101Schristosdnl We keep it around for reference purposes in case it's ever
10720f74e101Schristosdnl useful in the future.
10730f74e101Schristosdnl
10740f74e101Schristos
10750f74e101Schristosdefine(AC_LBL_CHECK_LIB,
10760f74e101Schristos[AC_MSG_CHECKING([for $2 in -l$1])
10770f74e101Schristosdnl Use a cache variable name containing the library, function
10780f74e101Schristosdnl name, and extra libraries to link with, because the test really is
10790f74e101Schristosdnl for library $1 defining function $2, when linked with potinal
10800f74e101Schristosdnl library $5, not just for library $1.  Separate tests with the same
10810f74e101Schristosdnl $1 and different $2's or $5's may have different results.
10820f74e101Schristosac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
10830f74e101SchristosAC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
10840f74e101Schristos[ac_save_LIBS="$LIBS"
10850f74e101SchristosLIBS="-l$1 $5 $LIBS"
10860f74e101SchristosAC_TRY_LINK(dnl
10870f74e101Schristosifelse([$2], [main], , dnl Avoid conflicting decl of main.
10880f74e101Schristos[/* Override any gcc2 internal prototype to avoid an error.  */
10890f74e101Schristos]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
10900f74e101Schristosextern "C"
10910f74e101Schristos#endif
10920f74e101Schristos])dnl
10930f74e101Schristos[/* We use char because int might match the return type of a gcc2
10940f74e101Schristos    builtin and then its argument prototype would still apply.  */
10950f74e101Schristoschar $2();
10960f74e101Schristos]),
10970f74e101Schristos	    [$2()],
10980f74e101Schristos	    eval "ac_cv_lbl_lib_$ac_lib_var=yes",
10990f74e101Schristos	    eval "ac_cv_lbl_lib_$ac_lib_var=no")
11000f74e101SchristosLIBS="$ac_save_LIBS"
11010f74e101Schristos])dnl
11020f74e101Schristosif eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
11030f74e101Schristos  AC_MSG_RESULT(yes)
11040f74e101Schristos  ifelse([$3], ,
11050f74e101Schristos[changequote(, )dnl
11060f74e101Schristos  ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
11070f74e101Schristos    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
11080f74e101Schristoschangequote([, ])dnl
11090f74e101Schristos  AC_DEFINE_UNQUOTED($ac_tr_lib)
11100f74e101Schristos  LIBS="-l$1 $LIBS"
11110f74e101Schristos], [$3])
11120f74e101Schristoselse
11130f74e101Schristos  AC_MSG_RESULT(no)
11140f74e101Schristosifelse([$4], , , [$4
11150f74e101Schristos])dnl
11160f74e101Schristosfi
11170f74e101Schristos])
11180f74e101Schristos
11190f74e101Schristosdnl
11200f74e101Schristosdnl AC_LBL_LIBRARY_NET
11210f74e101Schristosdnl
11220f74e101Schristosdnl This test is for network applications that need socket() and
1123*c41df9f6Schristosdnl gethostbyaddr() -ish functions.  Under Solaris, those applications
11240f74e101Schristosdnl need to link with "-lsocket -lnsl".  Under IRIX, they need to link
11250f74e101Schristosdnl with "-lnsl" but should *not* link with "-lsocket" because
11260f74e101Schristosdnl libsocket.a breaks a number of things (for instance:
1127*c41df9f6Schristosdnl gethostbyaddr() under IRIX 5.2, and snoop sockets under most
11280f74e101Schristosdnl versions of IRIX).
11290f74e101Schristosdnl
11300f74e101Schristosdnl Unfortunately, many application developers are not aware of this,
11310f74e101Schristosdnl and mistakenly write tests that cause -lsocket to be used under
11320f74e101Schristosdnl IRIX.  It is also easy to write tests that cause -lnsl to be used
11330f74e101Schristosdnl under operating systems where neither are necessary (or useful),
11340f74e101Schristosdnl such as SunOS 4.1.4, which uses -lnsl for TLI.
11350f74e101Schristosdnl
11360f74e101Schristosdnl This test exists so that every application developer does not test
11370f74e101Schristosdnl this in a different, and subtly broken fashion.
11380f74e101Schristos
11390f74e101Schristosdnl It has been argued that this test should be broken up into two
1140d881c474Schristosdnl separate tests, one for the resolver libraries, and one for the
11410f74e101Schristosdnl libraries necessary for using Sockets API. Unfortunately, the two
11420f74e101Schristosdnl are carefully intertwined and allowing the autoconf user to use
1143d881c474Schristosdnl them independently potentially results in unfortunate ordering
1144d881c474Schristosdnl dependencies -- as such, such component macros would have to
11450f74e101Schristosdnl carefully use indirection and be aware if the other components were
11460f74e101Schristosdnl executed. Since other autoconf macros do not go to this trouble,
11470f74e101Schristosdnl and almost no applications use sockets without the resolver, this
11480f74e101Schristosdnl complexity has not been implemented.
11490f74e101Schristosdnl
11500f74e101Schristosdnl The check for libresolv is in case you are attempting to link
11510f74e101Schristosdnl statically and happen to have a libresolv.a lying around (and no
11520f74e101Schristosdnl libnsl.a).
11530f74e101Schristosdnl
11540f74e101SchristosAC_DEFUN(AC_LBL_LIBRARY_NET, [
1155*c41df9f6Schristos    # Most operating systems have gethostbyaddr() in the default searched
11560f74e101Schristos    # libraries (i.e. libc):
11570f74e101Schristos    # Some OSes (eg. Solaris) place it in libnsl
11580f74e101Schristos    # Some strange OSes (SINIX) have it in libsocket:
1159*c41df9f6Schristos    AC_SEARCH_LIBS(gethostbyaddr, network nsl socket resolv)
11600f74e101Schristos    # Unfortunately libsocket sometimes depends on libnsl and
11610f74e101Schristos    # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this.
1162*c41df9f6Schristos    if test "$ac_cv_search_gethostbyaddr" = "no"
11630f74e101Schristos    then
1164*c41df9f6Schristos	AC_CHECK_LIB(socket, gethostbyaddr,
11650f74e101Schristos                     LIBS="-lsocket -lnsl $LIBS", , -lnsl)
11660f74e101Schristos    fi
11670f74e101Schristos    AC_SEARCH_LIBS(socket, socket, ,
11680f74e101Schristos	AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl))
11690f74e101Schristos    # DLPI needs putmsg under HPUX so test for -lstr while we're at it
11700f74e101Schristos    AC_SEARCH_LIBS(putmsg, str)
11710f74e101Schristos    ])
11720f74e101Schristos
11730f74e101Schristosdnl Copyright (c) 1999 WIDE Project. All rights reserved.
11740f74e101Schristosdnl
11750f74e101Schristosdnl Redistribution and use in source and binary forms, with or without
11760f74e101Schristosdnl modification, are permitted provided that the following conditions
11770f74e101Schristosdnl are met:
11780f74e101Schristosdnl 1. Redistributions of source code must retain the above copyright
11790f74e101Schristosdnl    notice, this list of conditions and the following disclaimer.
11800f74e101Schristosdnl 2. Redistributions in binary form must reproduce the above copyright
11810f74e101Schristosdnl    notice, this list of conditions and the following disclaimer in the
11820f74e101Schristosdnl    documentation and/or other materials provided with the distribution.
11830f74e101Schristosdnl 3. Neither the name of the project nor the names of its contributors
11840f74e101Schristosdnl    may be used to endorse or promote products derived from this software
11850f74e101Schristosdnl    without specific prior written permission.
11860f74e101Schristosdnl
11870f74e101Schristosdnl THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
11880f74e101Schristosdnl ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
11890f74e101Schristosdnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
11900f74e101Schristosdnl ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
11910f74e101Schristosdnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
11920f74e101Schristosdnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
11930f74e101Schristosdnl OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
11940f74e101Schristosdnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
11950f74e101Schristosdnl LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
11960f74e101Schristosdnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
11970f74e101Schristosdnl SUCH DAMAGE.
11980f74e101Schristos
11990f74e101SchristosAC_DEFUN(AC_LBL_SSLEAY,
12000f74e101Schristos    [
12010f74e101Schristos	#
12020f74e101Schristos	# Find the last component of $libdir; it's not necessarily
12030f74e101Schristos	# "lib" - it might be "lib64" on, for example, x86-64
12040f74e101Schristos	# Linux systems.
12050f74e101Schristos	#
12060f74e101Schristos	# We assume the directory in which we're looking for
12070f74e101Schristos	# libcrypto has a subdirectory with that as its name.
12080f74e101Schristos	#
12090f74e101Schristos	tmplib=`echo "$libdir" | sed 's,.*/,,'`
12100f74e101Schristos
12110f74e101Schristos	#
12120f74e101Schristos	# XXX - is there a better way to check if a given library is
12130f74e101Schristos	# in a given directory than checking each of the possible
12140f74e101Schristos	# shared library suffixes?
12150f74e101Schristos	#
12160f74e101Schristos	# Are there any other suffixes we need to look for?  Do we
12170f74e101Schristos	# have to worry about ".so.{version}"?
12180f74e101Schristos	#
12190f74e101Schristos	# Or should we just look for "libcrypto.*"?
12200f74e101Schristos	#
12210f74e101Schristos	if test -d "$1/$tmplib" -a \( -f "$1/$tmplib/libcrypto.a" -o \
12220f74e101Schristos				    -f "$1/$tmplib/libcrypto.so" -o \
12230f74e101Schristos				    -f "$1/$tmplib/libcrypto.sl" -o \
12240f74e101Schristos				    -f "$1/$tmplib/libcrypto.dylib" \); then
12250f74e101Schristos		ac_cv_ssleay_path="$1"
12260f74e101Schristos	fi
12270f74e101Schristos
12280f74e101Schristos	#
12290f74e101Schristos	# Make sure we have the headers as well.
12300f74e101Schristos	#
12310f74e101Schristos	if test -d "$1/include/openssl" -a -f "$1/include/openssl/des.h"; then
12320f74e101Schristos		incdir="-I$1/include"
12330f74e101Schristos	fi
12340f74e101Schristos])
1235*c41df9f6Schristos
1236*c41df9f6Schristosm4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
1237*c41df9f6Schristosdnl pkg.m4 - Macros to locate and utilise pkg-config.   -*- Autoconf -*-
1238*c41df9f6Schristosdnl serial 11 (pkg-config-0.29)
1239*c41df9f6Schristosdnl
1240*c41df9f6Schristosdnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
1241*c41df9f6Schristosdnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
1242*c41df9f6Schristosdnl
1243*c41df9f6Schristosdnl This program is free software; you can redistribute it and/or modify
1244*c41df9f6Schristosdnl it under the terms of the GNU General Public License as published by
1245*c41df9f6Schristosdnl the Free Software Foundation; either version 2 of the License, or
1246*c41df9f6Schristosdnl (at your option) any later version.
1247*c41df9f6Schristosdnl
1248*c41df9f6Schristosdnl This program is distributed in the hope that it will be useful, but
1249*c41df9f6Schristosdnl WITHOUT ANY WARRANTY; without even the implied warranty of
1250*c41df9f6Schristosdnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1251*c41df9f6Schristosdnl General Public License for more details.
1252*c41df9f6Schristosdnl
1253*c41df9f6Schristosdnl You should have received a copy of the GNU General Public License
1254*c41df9f6Schristosdnl along with this program; if not, write to the Free Software
1255*c41df9f6Schristosdnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1256*c41df9f6Schristosdnl 02111-1307, USA.
1257*c41df9f6Schristosdnl
1258*c41df9f6Schristosdnl As a special exception to the GNU General Public License, if you
1259*c41df9f6Schristosdnl distribute this file as part of a program that contains a
1260*c41df9f6Schristosdnl configuration script generated by Autoconf, you may include it under
1261*c41df9f6Schristosdnl the same distribution terms that you use for the rest of that
1262*c41df9f6Schristosdnl program.
1263*c41df9f6Schristos
1264*c41df9f6Schristosdnl PKG_PREREQ(MIN-VERSION)
1265*c41df9f6Schristosdnl -----------------------
1266*c41df9f6Schristosdnl Since: 0.29
1267*c41df9f6Schristosdnl
1268*c41df9f6Schristosdnl Verify that the version of the pkg-config macros are at least
1269*c41df9f6Schristosdnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
1270*c41df9f6Schristosdnl installed version of pkg-config, this checks the developer's version
1271*c41df9f6Schristosdnl of pkg.m4 when generating configure.
1272*c41df9f6Schristosdnl
1273*c41df9f6Schristosdnl To ensure that this macro is defined, also add:
1274*c41df9f6Schristosdnl m4_ifndef([PKG_PREREQ],
1275*c41df9f6Schristosdnl     [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
1276*c41df9f6Schristosdnl
1277*c41df9f6Schristosdnl See the "Since" comment for each macro you use to see what version
1278*c41df9f6Schristosdnl of the macros you require.
1279*c41df9f6Schristosm4_defun([PKG_PREREQ],
1280*c41df9f6Schristos[m4_define([PKG_MACROS_VERSION], [0.29])
1281*c41df9f6Schristosm4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
1282*c41df9f6Schristos    [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
1283*c41df9f6Schristos])dnl PKG_PREREQ
1284*c41df9f6Schristos
1285*c41df9f6Schristosdnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
1286*c41df9f6Schristosdnl ----------------------------------
1287*c41df9f6Schristosdnl Since: 0.16
1288*c41df9f6Schristosdnl
1289*c41df9f6Schristosdnl Search for the pkg-config tool and set the PKG_CONFIG variable to
1290*c41df9f6Schristosdnl first found in the path. Checks that the version of pkg-config found
1291*c41df9f6Schristosdnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.17.0 is
1292*c41df9f6Schristosdnl used since that's the first version where --static was supported.
1293*c41df9f6SchristosAC_DEFUN([PKG_PROG_PKG_CONFIG],
1294*c41df9f6Schristos[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
1295*c41df9f6Schristosm4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
1296*c41df9f6Schristosm4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
1297*c41df9f6SchristosAC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
1298*c41df9f6SchristosAC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
1299*c41df9f6SchristosAC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
1300*c41df9f6Schristos
1301*c41df9f6Schristosif test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
1302*c41df9f6Schristos	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
1303*c41df9f6Schristosfi
1304*c41df9f6Schristosif test -n "$PKG_CONFIG"; then
1305*c41df9f6Schristos	_pkg_min_version=m4_default([$1], [0.17.0])
1306*c41df9f6Schristos	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
1307*c41df9f6Schristos	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
1308*c41df9f6Schristos		AC_MSG_RESULT([yes])
1309*c41df9f6Schristos	else
1310*c41df9f6Schristos		AC_MSG_RESULT([no])
1311*c41df9f6Schristos		PKG_CONFIG=""
1312*c41df9f6Schristos	fi
1313*c41df9f6Schristosfi[]dnl
1314*c41df9f6Schristos])dnl PKG_PROG_PKG_CONFIG
1315*c41df9f6Schristos
1316*c41df9f6Schristosdnl PKG_CHECK_EXISTS(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1317*c41df9f6Schristosdnl -------------------------------------------------------------------
1318*c41df9f6Schristosdnl Since: 0.18
1319*c41df9f6Schristosdnl
1320*c41df9f6Schristosdnl Check to see whether a particular module exists. Similar to
1321*c41df9f6Schristosdnl PKG_CHECK_MODULE(), but does not set variables or print errors.
1322*c41df9f6SchristosAC_DEFUN([PKG_CHECK_EXISTS],
1323*c41df9f6Schristos[
1324*c41df9f6Schristosif test -n "$PKG_CONFIG" && \
1325*c41df9f6Schristos    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
1326*c41df9f6Schristos  m4_default([$2], [:])
1327*c41df9f6Schristosm4_ifvaln([$3], [else
1328*c41df9f6Schristos  $3])dnl
1329*c41df9f6Schristosfi])
1330*c41df9f6Schristos
1331*c41df9f6Schristosdnl _PKG_CONFIG_WITH_FLAGS([VARIABLE], [FLAGS], [MODULE])
1332*c41df9f6Schristosdnl ---------------------------------------------
1333*c41df9f6Schristosdnl Internal wrapper calling pkg-config via PKG_CONFIG and, if
1334*c41df9f6Schristosdnl pkg-config fails, reporting the error and quitting.
1335*c41df9f6Schristosm4_define([_PKG_CONFIG_WITH_FLAGS],
1336*c41df9f6Schristos[if test ! -n "$$1"; then
1337*c41df9f6Schristos    $1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
1338*c41df9f6Schristos    if test "x$?" != "x0"; then
1339*c41df9f6Schristos        #
1340*c41df9f6Schristos        # That failed - report an error.
1341*c41df9f6Schristos        # Re-run the command, telling pkg-config to print an error
1342*c41df9f6Schristos        # message, capture the error message, and report it.
1343*c41df9f6Schristos        # This causes the configuration script to fail, as it means
1344*c41df9f6Schristos        # the script is almost certainly doing something wrong.
1345*c41df9f6Schristos        #
1346*c41df9f6Schristos        _PKG_SHORT_ERRORS_SUPPORTED
1347*c41df9f6Schristos	if test $_pkg_short_errors_supported = yes; then
1348*c41df9f6Schristos	    _pkg_error_string=`$PKG_CONFIG --short-errors --print-errors $2 "$3" 2>&1`
1349*c41df9f6Schristos	else
1350*c41df9f6Schristos	    _pkg_error_string=`$PKG_CONFIG --print-errors $2 "$3" 2>&1`
1351*c41df9f6Schristos	fi
1352*c41df9f6Schristos        AC_MSG_ERROR([$PKG_CONFIG $2 "$3" failed: $_pkg_error_string])
1353*c41df9f6Schristos    fi
1354*c41df9f6Schristos fi[]dnl
1355*c41df9f6Schristos])dnl _PKG_CONFIG_WITH_FLAGS
1356*c41df9f6Schristos
1357*c41df9f6Schristos
1358*c41df9f6Schristosdnl _PKG_CONFIG([VARIABLE], [FLAGS], [MODULE])
1359*c41df9f6Schristosdnl ---------------------------------------------
1360*c41df9f6Schristosdnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
1361*c41df9f6Schristosdnl pkg_failed based on the result.
1362*c41df9f6Schristosm4_define([_PKG_CONFIG],
1363*c41df9f6Schristos[if test -n "$$1"; then
1364*c41df9f6Schristos    pkg_cv_[]$1="$$1"
1365*c41df9f6Schristos elif test -n "$PKG_CONFIG"; then
1366*c41df9f6Schristos    PKG_CHECK_EXISTS([$3],
1367*c41df9f6Schristos                     [pkg_cv_[]$1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
1368*c41df9f6Schristos		      test "x$?" != "x0" && pkg_failed=yes ],
1369*c41df9f6Schristos		     [pkg_failed=yes])
1370*c41df9f6Schristos else
1371*c41df9f6Schristos    pkg_failed=untried
1372*c41df9f6Schristosfi[]dnl
1373*c41df9f6Schristos])dnl _PKG_CONFIG
1374*c41df9f6Schristos
1375*c41df9f6Schristosdnl _PKG_SHORT_ERRORS_SUPPORTED
1376*c41df9f6Schristosdnl ---------------------------
1377*c41df9f6Schristosdnl Internal check to see if pkg-config supports short errors.
1378*c41df9f6SchristosAC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
1379*c41df9f6Schristos[
1380*c41df9f6Schristosif $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
1381*c41df9f6Schristos        _pkg_short_errors_supported=yes
1382*c41df9f6Schristoselse
1383*c41df9f6Schristos        _pkg_short_errors_supported=no
1384*c41df9f6Schristosfi[]dnl
1385*c41df9f6Schristos])dnl _PKG_SHORT_ERRORS_SUPPORTED
1386*c41df9f6Schristos
1387*c41df9f6Schristos
1388*c41df9f6Schristosdnl PKG_CHECK_MODULE(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1389*c41df9f6Schristosdnl   [ACTION-IF-NOT-FOUND])
1390*c41df9f6Schristosdnl --------------------------------------------------------------
1391*c41df9f6Schristosdnl Since: 0.4.0
1392*c41df9f6SchristosAC_DEFUN([PKG_CHECK_MODULE],
1393*c41df9f6Schristos[
1394*c41df9f6SchristosAC_MSG_CHECKING([for $2 with pkg-config])
1395*c41df9f6Schristosif test -n "$PKG_CONFIG"; then
1396*c41df9f6Schristos    AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $2, overriding pkg-config])dnl
1397*c41df9f6Schristos    AC_ARG_VAR([$1][_LIBS], [linker flags for $2, overriding pkg-config])dnl
1398*c41df9f6Schristos    AC_ARG_VAR([$1][_LIBS_STATIC], [static-link linker flags for $2, overriding pkg-config])dnl
1399*c41df9f6Schristos
1400*c41df9f6Schristos    if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
1401*c41df9f6Schristos	#
1402*c41df9f6Schristos	# The package was found, so try to get its C flags and
1403*c41df9f6Schristos	# libraries.
1404*c41df9f6Schristos	#
1405*c41df9f6Schristos        AC_MSG_RESULT([found])
1406*c41df9f6Schristos	_PKG_CONFIG_WITH_FLAGS([$1][_CFLAGS], [--cflags], [$2])
1407*c41df9f6Schristos	_PKG_CONFIG_WITH_FLAGS([$1][_LIBS], [--libs], [$2])
1408*c41df9f6Schristos	_PKG_CONFIG_WITH_FLAGS([$1][_LIBS_STATIC], [--libs --static], [$2])
1409*c41df9f6Schristos        m4_default([$3], [:])
1410*c41df9f6Schristos    else
1411*c41df9f6Schristos        AC_MSG_RESULT([not found])
1412*c41df9f6Schristos        m4_default([$4], [:])
1413*c41df9f6Schristos    fi
1414*c41df9f6Schristoselse
1415*c41df9f6Schristos    # No pkg-config, so obviously not found with pkg-config.
1416*c41df9f6Schristos    AC_MSG_RESULT([pkg-config not found])
1417*c41df9f6Schristos    m4_default([$4], [:])
1418*c41df9f6Schristosfi
1419*c41df9f6Schristos])dnl PKG_CHECK_MODULE
1420*c41df9f6Schristos
1421*c41df9f6Schristos
1422*c41df9f6Schristosdnl PKG_CHECK_MODULE_STATIC(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1423*c41df9f6Schristosdnl   [ACTION-IF-NOT-FOUND])
1424*c41df9f6Schristosdnl ---------------------------------------------------------------------
1425*c41df9f6Schristosdnl Since: 0.29
1426*c41df9f6Schristosdnl
1427*c41df9f6Schristosdnl Checks for existence of MODULE and gathers its build flags with
1428*c41df9f6Schristosdnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
1429*c41df9f6Schristosdnl and VARIABLE-PREFIX_LIBS from --libs.
1430*c41df9f6SchristosAC_DEFUN([PKG_CHECK_MODULE_STATIC],
1431*c41df9f6Schristos[
1432*c41df9f6Schristos_save_PKG_CONFIG=$PKG_CONFIG
1433*c41df9f6SchristosPKG_CONFIG="$PKG_CONFIG --static"
1434*c41df9f6SchristosPKG_CHECK_MODULE($@)
1435*c41df9f6SchristosPKG_CONFIG=$_save_PKG_CONFIG[]dnl
1436*c41df9f6Schristos])dnl PKG_CHECK_MODULE_STATIC
1437*c41df9f6Schristos
1438*c41df9f6Schristos
1439*c41df9f6Schristosdnl PKG_INSTALLDIR([DIRECTORY])
1440*c41df9f6Schristosdnl -------------------------
1441*c41df9f6Schristosdnl Since: 0.27
1442*c41df9f6Schristosdnl
1443*c41df9f6Schristosdnl Substitutes the variable pkgconfigdir as the location where a module
1444*c41df9f6Schristosdnl should install pkg-config .pc files. By default the directory is
1445*c41df9f6Schristosdnl $libdir/pkgconfig, but the default can be changed by passing
1446*c41df9f6Schristosdnl DIRECTORY. The user can override through the --with-pkgconfigdir
1447*c41df9f6Schristosdnl parameter.
1448*c41df9f6SchristosAC_DEFUN([PKG_INSTALLDIR],
1449*c41df9f6Schristos[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
1450*c41df9f6Schristosm4_pushdef([pkg_description],
1451*c41df9f6Schristos    [pkg-config installation directory @<:@]pkg_default[@:>@])
1452*c41df9f6SchristosAC_ARG_WITH([pkgconfigdir],
1453*c41df9f6Schristos    [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
1454*c41df9f6Schristos    [with_pkgconfigdir=]pkg_default)
1455*c41df9f6SchristosAC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
1456*c41df9f6Schristosm4_popdef([pkg_default])
1457*c41df9f6Schristosm4_popdef([pkg_description])
1458*c41df9f6Schristos])dnl PKG_INSTALLDIR
1459*c41df9f6Schristos
1460*c41df9f6Schristos
1461*c41df9f6Schristosdnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
1462*c41df9f6Schristosdnl --------------------------------
1463*c41df9f6Schristosdnl Since: 0.27
1464*c41df9f6Schristosdnl
1465*c41df9f6Schristosdnl Substitutes the variable noarch_pkgconfigdir as the location where a
1466*c41df9f6Schristosdnl module should install arch-independent pkg-config .pc files. By
1467*c41df9f6Schristosdnl default the directory is $datadir/pkgconfig, but the default can be
1468*c41df9f6Schristosdnl changed by passing DIRECTORY. The user can override through the
1469*c41df9f6Schristosdnl --with-noarch-pkgconfigdir parameter.
1470*c41df9f6SchristosAC_DEFUN([PKG_NOARCH_INSTALLDIR],
1471*c41df9f6Schristos[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
1472*c41df9f6Schristosm4_pushdef([pkg_description],
1473*c41df9f6Schristos    [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
1474*c41df9f6SchristosAC_ARG_WITH([noarch-pkgconfigdir],
1475*c41df9f6Schristos    [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
1476*c41df9f6Schristos    [with_noarch_pkgconfigdir=]pkg_default)
1477*c41df9f6SchristosAC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
1478*c41df9f6Schristosm4_popdef([pkg_default])
1479*c41df9f6Schristosm4_popdef([pkg_description])
1480*c41df9f6Schristos])dnl PKG_NOARCH_INSTALLDIR
1481*c41df9f6Schristos
1482*c41df9f6Schristos
1483*c41df9f6Schristosdnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
1484*c41df9f6Schristosdnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1485*c41df9f6Schristosdnl -------------------------------------------
1486*c41df9f6Schristosdnl Since: 0.28
1487*c41df9f6Schristosdnl
1488*c41df9f6Schristosdnl Retrieves the value of the pkg-config variable for the given module.
1489*c41df9f6SchristosAC_DEFUN([PKG_CHECK_VAR],
1490*c41df9f6Schristos[
1491*c41df9f6SchristosAC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
1492*c41df9f6Schristos
1493*c41df9f6Schristos_PKG_CONFIG([$1], [--variable="][$3]["], [$2])
1494*c41df9f6SchristosAS_VAR_COPY([$1], [pkg_cv_][$1])
1495*c41df9f6Schristos
1496*c41df9f6SchristosAS_VAR_IF([$1], [""], [$5], [$4])dnl
1497*c41df9f6Schristos])dnl PKG_CHECK_VAR
1498