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