xref: /freebsd/contrib/libpcap/aclocal.m4 (revision afdbf109c6a661a729938f68211054a0a50d38ac)
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_FIXINCLUDES])
43    AC_BEFORE([$0], [AC_LBL_DEVEL])
44    AC_ARG_WITH(gcc, [  --without-gcc           don't use gcc])
45    $1=""
46    if test "${srcdir}" != "." ; then
47	    $1="-I\$(srcdir)"
48    fi
49    if test "${CFLAGS+set}" = set; then
50	    LBL_CFLAGS="$CFLAGS"
51    fi
52    if test -z "$CC" ; then
53	    case "$host_os" in
54
55	    bsdi*)
56		    AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
57		    if test $SHLICC2 = yes ; then
58			    CC=shlicc2
59			    export CC
60		    fi
61		    ;;
62	    esac
63    fi
64    if test -z "$CC" -a "$with_gcc" = no ; then
65	    CC=cc
66	    export CC
67    fi
68])
69
70dnl
71dnl Determine which compiler we're using (cc or gcc)
72dnl If using gcc, determine the version number
73dnl If using cc:
74dnl     require that it support ansi prototypes
75dnl     use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to
76dnl     do that ourselves for gcc)
77dnl     add -g flags, as appropriate
78dnl     explicitly specify /usr/local/include
79dnl
80dnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler
81dnl that defines __GNUC__, which means clang, for example, counts as "gcc".
82dnl
83dnl usage:
84dnl
85dnl	AC_LBL_C_INIT(copt, incls)
86dnl
87dnl results:
88dnl
89dnl	$1 (copt set)
90dnl	$2 (incls set)
91dnl	CC
92dnl	LDFLAGS
93dnl	LBL_CFLAGS
94dnl
95AC_DEFUN(AC_LBL_C_INIT,
96[
97    AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
98    AC_BEFORE([$0], [AC_LBL_DEVEL])
99    AC_BEFORE([$0], [AC_LBL_SHLIBS_INIT])
100    if test "$GCC" = yes ; then
101	    #
102	    # -Werror forces warnings to be errors.
103	    #
104	    ac_lbl_cc_force_warning_errors=-Werror
105
106	    #
107	    # Try to have the compiler default to hiding symbols,
108	    # so that only symbols explicitly exported with
109	    # PCAP_API will be visible outside (shared) libraries.
110	    #
111	    AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
112    else
113	    $2="$$2 -I/usr/local/include"
114	    LDFLAGS="$LDFLAGS -L/usr/local/lib"
115
116	    case "$host_os" in
117
118	    darwin*)
119		    #
120		    # This is assumed either to be GCC or clang, both
121		    # of which use -Werror to force warnings to be errors.
122		    #
123		    ac_lbl_cc_force_warning_errors=-Werror
124
125		    #
126		    # Try to have the compiler default to hiding symbols,
127		    # so that only symbols explicitly exported with
128		    # PCAP_API will be visible outside (shared) libraries.
129		    #
130		    AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
131		    ;;
132
133	    hpux*)
134		    #
135		    # HP C, which is what we presume we're using, doesn't
136		    # exit with a non-zero exit status if we hand it an
137		    # invalid -W flag, can't be forced to do so even with
138		    # +We, and doesn't handle GCC-style -W flags, so we
139		    # don't want to try using GCC-style -W flags.
140		    #
141		    ac_lbl_cc_dont_try_gcc_dashW=yes
142		    ;;
143
144	    irix*)
145		    #
146		    # MIPS C, which is what we presume we're using, doesn't
147		    # necessarily exit with a non-zero exit status if we
148		    # hand it an invalid -W flag, can't be forced to do
149		    # so, and doesn't handle GCC-style -W flags, so we
150		    # don't want to try using GCC-style -W flags.
151		    #
152		    ac_lbl_cc_dont_try_gcc_dashW=yes
153		    #
154		    # It also, apparently, defaults to "char" being
155		    # unsigned, unlike most other C implementations;
156		    # I suppose we could say "signed char" whenever
157		    # we want to guarantee a signed "char", but let's
158		    # just force signed chars.
159		    #
160		    # -xansi is normally the default, but the
161		    # configure script was setting it; perhaps -cckr
162		    # was the default in the Old Days.  (Then again,
163		    # that would probably be for backwards compatibility
164		    # in the days when ANSI C was Shiny and New, i.e.
165		    # 1989 and the early '90's, so maybe we can just
166		    # drop support for those compilers.)
167		    #
168		    # -g is equivalent to -g2, which turns off
169		    # optimization; we choose -g3, which generates
170		    # debugging information but doesn't turn off
171		    # optimization (even if the optimization would
172		    # cause inaccuracies in debugging).
173		    #
174		    $1="$$1 -xansi -signed -g3"
175		    ;;
176
177	    osf*)
178		    #
179		    # Presumed to be DEC OSF/1, Digital UNIX, or
180		    # Tru64 UNIX.
181		    #
182		    # The DEC C compiler, which is what we presume we're
183		    # using, doesn't exit with a non-zero exit status if we
184		    # hand it an invalid -W flag, can't be forced to do
185		    # so, and doesn't handle GCC-style -W flags, so we
186		    # don't want to try using GCC-style -W flags.
187		    #
188		    ac_lbl_cc_dont_try_gcc_dashW=yes
189		    #
190		    # -g is equivalent to -g2, which turns off
191		    # optimization; we choose -g3, which generates
192		    # debugging information but doesn't turn off
193		    # optimization (even if the optimization would
194		    # cause inaccuracies in debugging).
195		    #
196		    $1="$$1 -g3"
197		    ;;
198
199	    solaris*)
200		    #
201		    # Assumed to be Sun C, which requires -errwarn to force
202		    # warnings to be treated as errors.
203		    #
204		    ac_lbl_cc_force_warning_errors=-errwarn
205
206		    #
207		    # Try to have the compiler default to hiding symbols,
208		    # so that only symbols explicitly exported with
209		    # PCAP_API will be visible outside (shared) libraries.
210		    #
211		    AC_LBL_CHECK_COMPILER_OPT($1, -xldscope=hidden)
212		    ;;
213
214	    ultrix*)
215		    AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
216		    AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
217			AC_TRY_COMPILE(
218			    [#include <sys/types.h>],
219			    [struct a { int b; };
220			    void c(const struct a *)],
221			    ac_cv_lbl_cc_const_proto=yes,
222			    ac_cv_lbl_cc_const_proto=no))
223		    AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
224		    if test $ac_cv_lbl_cc_const_proto = no ; then
225			    AC_DEFINE(const,[],
226			        [to handle Ultrix compilers that don't support const in prototypes])
227		    fi
228		    ;;
229	    esac
230	    $1="$$1 -O"
231    fi
232])
233
234dnl
235dnl Save the values of various variables that affect compilation and
236dnl linking, and that we don't ourselves modify persistently; done
237dnl before a test involving compiling or linking is done, so that we
238dnl can restore those variables after the test is done.
239dnl
240AC_DEFUN(AC_LBL_SAVE_CHECK_STATE,
241[
242	save_CFLAGS="$CFLAGS"
243	save_LIBS="$LIBS"
244	save_LDFLAGS="$LDFLAGS"
245])
246
247dnl
248dnl Restore the values of variables saved by AC_LBL_SAVE_CHECK_STATE.
249dnl
250AC_DEFUN(AC_LBL_RESTORE_CHECK_STATE,
251[
252	CFLAGS="$save_CFLAGS"
253	LIBS="$save_LIBS"
254	LDFLAGS="$save_LDFLAGS"
255])
256
257dnl
258dnl Check whether the compiler option specified as the second argument
259dnl is supported by the compiler and, if so, add it to the macro
260dnl specified as the first argument
261dnl
262dnl If a third argument is supplied, treat it as C code to be compiled
263dnl with the flag in question, and the "treat warnings as errors" flag
264dnl set, and don't add the flag to the first argument if the compile
265dnl fails; this is for warning options cause problems that can't be
266dnl worked around.  If a third argument is supplied, a fourth argument
267dnl should also be supplied; it's a message describing what the test
268dnl program is checking.
269dnl
270AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
271    [
272	AC_MSG_CHECKING([whether the compiler supports the $2 option])
273	save_CFLAGS="$CFLAGS"
274	CFLAGS="$CFLAGS $2"
275	#
276	# XXX - yes, this depends on the way AC_LANG_WERROR works,
277	# but no mechanism is provided to turn AC_LANG_WERROR on
278	# *and then turn it back off*, so that we *only* do it when
279	# testing compiler options - 15 years after somebody asked
280	# for it:
281	#
282	#     https://autoconf.gnu.narkive.com/gTAVmfKD/how-to-cancel-flags-set-by-ac-lang-werror
283	#
284	save_ac_c_werror_flag="$ac_c_werror_flag"
285	ac_c_werror_flag=yes
286	#
287	# We use AC_LANG_SOURCE() so that we can control the complete
288	# content of the program being compiled.  We do not, for example,
289	# want the default "int main()" that AC_LANG_PROGRAM() generates,
290	# as it will generate a warning with -Wold-style-definition, meaning
291	# that we would treat it as not working, as the test will fail if
292	# *any* error output, including a warning due to the flag we're
293	# testing, is generated; see
294	#
295	#    https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
296	#    https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
297	#
298	# This may, as per those two messages, be fixed in autoconf 2.70,
299	# but we only require 2.69 or newer for now.
300	#
301	AC_COMPILE_IFELSE(
302	    [AC_LANG_SOURCE([[int main(void) { return 0; }]])],
303	    [
304		AC_MSG_RESULT([yes])
305		can_add_to_cflags=yes
306		#
307		# The compile supports this; do we have some C code for
308		# which the warning should *not* appear?
309		# We test the fourth argument because the third argument
310		# could contain quotes, breaking the test.
311		#
312		if test "x$4" != "x"
313		then
314		    CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
315		    AC_MSG_CHECKING(whether $2 $4)
316		    AC_COMPILE_IFELSE(
317		      [AC_LANG_SOURCE($3)],
318		      [
319			#
320			# Not a problem.
321			#
322			AC_MSG_RESULT(no)
323		      ],
324		      [
325			#
326			# A problem.
327			#
328			AC_MSG_RESULT(yes)
329			can_add_to_cflags=no
330		      ])
331		fi
332		CFLAGS="$save_CFLAGS"
333		if test x"$can_add_to_cflags" = "xyes"
334		then
335		    $1="$$1 $2"
336		fi
337	    ],
338	    [
339		AC_MSG_RESULT([no])
340		CFLAGS="$save_CFLAGS"
341	    ])
342	ac_c_werror_flag="$save_ac_c_werror_flag"
343    ])
344
345dnl
346dnl Check whether the compiler supports an option to generate
347dnl Makefile-style dependency lines
348dnl
349dnl GCC uses -M for this.  Non-GCC compilers that support this
350dnl use a variety of flags, including but not limited to -M.
351dnl
352dnl We test whether the flag in question is supported, as older
353dnl versions of compilers might not support it.
354dnl
355dnl We don't try all the possible flags, just in case some flag means
356dnl "generate dependencies" on one compiler but means something else
357dnl on another compiler.
358dnl
359dnl Most compilers that support this send the output to the standard
360dnl output by default.  IBM's XLC, however, supports -M but sends
361dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
362dnl to work around that, so we don't bother with XLC.
363dnl
364AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
365    [
366	AC_MSG_CHECKING([whether the compiler supports generating dependencies])
367	if test "$GCC" = yes ; then
368		#
369		# GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
370		# though it's not); we assume that, in this case, the flag
371		# would be -M.
372		#
373		ac_lbl_dependency_flag="-M"
374	else
375		#
376		# Not GCC or a compiler deemed to be GCC; what platform is
377		# this?  (We're assuming that if the compiler isn't GCC
378		# it's the compiler from the vendor of the OS; that won't
379		# necessarily be true for x86 platforms, where it might be
380		# the Intel C compiler.)
381		#
382		case "$host_os" in
383
384		irix*|osf*|darwin*)
385			#
386			# MIPS C for IRIX, DEC C, and clang all use -M.
387			#
388			ac_lbl_dependency_flag="-M"
389			;;
390
391		solaris*)
392			#
393			# Sun C uses -xM.
394			#
395			ac_lbl_dependency_flag="-xM"
396			;;
397
398		hpux*)
399			#
400			# HP's older C compilers don't support this.
401			# HP's newer C compilers support this with
402			# either +M or +Make; the older compilers
403			# interpret +M as something completely
404			# different, so we use +Make so we don't
405			# think it works with the older compilers.
406			#
407			ac_lbl_dependency_flag="+Make"
408			;;
409
410		*)
411			#
412			# Not one of the above; assume no support for
413			# generating dependencies.
414			#
415			ac_lbl_dependency_flag=""
416			;;
417		esac
418	fi
419
420	#
421	# Is ac_lbl_dependency_flag defined and, if so, does the compiler
422	# complain about it?
423	#
424	# Note: clang doesn't seem to exit with an error status when handed
425	# an unknown non-warning error, even if you pass it
426	# -Werror=unknown-warning-option.  However, it always supports
427	# -M, so the fact that this test always succeeds with clang
428	# isn't an issue.
429	#
430	if test ! -z "$ac_lbl_dependency_flag"; then
431		AC_LANG_CONFTEST(
432		    [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
433		if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
434			AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
435			DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
436			MKDEP='${top_srcdir}/mkdep'
437		else
438			AC_MSG_RESULT([no])
439			#
440			# We can't run mkdep, so have "make depend" do
441			# nothing.
442			#
443			MKDEP='${top_srcdir}/nomkdep'
444		fi
445		rm -rf conftest*
446	else
447		AC_MSG_RESULT([no])
448		#
449		# We can't run mkdep, so have "make depend" do
450		# nothing.
451		#
452		MKDEP='${top_srcdir}/nomkdep'
453	fi
454	AC_SUBST(DEPENDENCY_CFLAG)
455	AC_SUBST(MKDEP)
456    ])
457
458dnl
459dnl Determine what options are needed to build a shared library
460dnl
461dnl usage:
462dnl
463dnl	AC_LBL_SHLIBS_INIT
464dnl
465dnl results:
466dnl
467dnl	V_SHLIB_CCOPT (modified to build position-independent code)
468dnl	V_SHLIB_CMD
469dnl	V_SHLIB_OPT
470dnl	V_SONAME_OPT
471dnl
472AC_DEFUN(AC_LBL_SHLIBS_INIT,
473    [AC_PREREQ(2.50)
474    if test "$GCC" = yes ; then
475	    #
476	    # On platforms where we build a shared library:
477	    #
478	    #	add options to generate position-independent code,
479	    #	if necessary (it's the default in AIX and Darwin/macOS);
480	    #
481	    #	define option to set the soname of the shared library,
482	    #	if the OS supports that;
483	    #
484	    #	add options to specify, at link time, a directory to
485	    #	add to the run-time search path, if that's necessary.
486	    #
487	    V_SHLIB_CMD="\$(CC)"
488	    V_SHLIB_OPT="-shared"
489	    case "$host_os" in
490
491	    aix*)
492		    ;;
493
494	    freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*|haiku*|midipix*)
495		    #
496		    # Platforms where the C compiler is GCC or accepts
497		    # compatible command-line arguments, and the linker
498		    # is the GNU linker or accepts compatible command-line
499		    # arguments.
500		    #
501		    # Some instruction sets require -fPIC on some
502		    # operating systems.  Check for them.  If you
503		    # have a combination that requires it, add it
504		    # here.
505		    #
506		    PIC_OPT=-fpic
507		    case "$host_cpu" in
508
509		    sparc64*)
510			case "$host_os" in
511
512			freebsd*|openbsd*|linux*)
513			    PIC_OPT=-fPIC
514			    ;;
515			esac
516			;;
517		    esac
518		    V_SHLIB_CCOPT="$V_SHLIB_CCOPT $PIC_OPT"
519		    V_SONAME_OPT="-Wl,-soname,"
520		    ;;
521
522	    hpux*)
523		    V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
524		    #
525		    # XXX - this assumes GCC is using the HP linker,
526		    # rather than the GNU linker, and that the "+h"
527		    # option is used on all HP-UX platforms, both .sl
528		    # and .so.
529		    #
530		    V_SONAME_OPT="-Wl,+h,"
531		    #
532		    # By default, directories specified with -L
533		    # are added to the run-time search path, so
534		    # we don't add them in pcap-config.
535		    #
536		    ;;
537
538	    solaris*)
539		    V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
540		    #
541		    # Sun/Oracle's C compiler, GCC, and GCC-compatible
542		    # compilers support -Wl,{comma-separated list of options},
543		    # and we use the C compiler, not ld, for all linking,
544		    # including linking to produce a shared library.
545		    #
546		    V_SONAME_OPT="-Wl,-h,"
547		    ;;
548	    esac
549    else
550	    #
551	    # Set the appropriate compiler flags and, on platforms
552	    # where we build a shared library:
553	    #
554	    #	add options to generate position-independent code,
555	    #	if necessary (it's the default in Darwin/macOS);
556	    #
557	    #	if we generate ".so" shared libraries, define the
558	    #	appropriate options for building the shared library;
559	    #
560	    #	add options to specify, at link time, a directory to
561	    #	add to the run-time search path, if that's necessary.
562	    #
563	    # Note: spaces after V_SONAME_OPT are significant; on
564	    # some platforms the soname is passed with a GCC-like
565	    # "-Wl,-soname,{soname}" option, with the soname part
566	    # of the option, while on other platforms the C compiler
567	    # driver takes it as a regular option with the soname
568	    # following the option.
569	    #
570	    case "$host_os" in
571
572	    aix*)
573		    V_SHLIB_CMD="\$(CC)"
574		    V_SHLIB_OPT="-G -bnoentry -bexpall"
575		    ;;
576
577	    freebsd*|netbsd*|openbsd*|dragonfly*|linux*)
578		    #
579		    # Platforms where the C compiler is GCC or accepts
580		    # compatible command-line arguments, and the linker
581		    # is the GNU linker or accepts compatible command-line
582		    # arguments.
583		    #
584		    # XXX - does 64-bit SPARC require -fPIC?
585		    #
586		    V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
587		    V_SHLIB_CMD="\$(CC)"
588		    V_SHLIB_OPT="-shared"
589		    V_SONAME_OPT="-Wl,-soname,"
590		    ;;
591
592	    hpux*)
593		    V_SHLIB_CCOPT="$V_SHLIB_CCOPT +z"
594		    V_SHLIB_CMD="\$(LD)"
595		    V_SHLIB_OPT="-b"
596		    V_SONAME_OPT="+h "
597		    #
598		    # By default, directories specified with -L
599		    # are added to the run-time search path, so
600		    # we don't add them in pcap-config.
601		    #
602		    ;;
603
604	    osf*)
605		    #
606		    # Presumed to be DEC OSF/1, Digital UNIX, or
607		    # Tru64 UNIX.
608		    #
609		    V_SHLIB_CMD="\$(CC)"
610		    V_SHLIB_OPT="-shared"
611		    V_SONAME_OPT="-soname "
612		    ;;
613
614	    solaris*)
615		    V_SHLIB_CCOPT="$V_SHLIB_CCOPT -Kpic"
616		    V_SHLIB_CMD="\$(CC)"
617		    V_SHLIB_OPT="-G"
618		    #
619		    # Sun/Oracle's C compiler, GCC, and GCC-compatible
620		    # compilers support -Wl,{comma-separated list of options},
621		    # and we use the C compiler, not ld, for all linking,
622		    # including linking to produce a shared library.
623		    #
624		    V_SONAME_OPT="-Wl,-h,"
625		    ;;
626	    esac
627    fi
628])
629
630#
631# Try compiling a sample of the type of code that appears in
632# gencode.c with "inline", "__inline__", and "__inline".
633#
634# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
635# as it just tests whether a function returning "int" can be inlined;
636# at least some versions of HP's C compiler can inline that, but can't
637# inline a function that returns a struct pointer.
638#
639# Make sure we use the V_CCOPT flags, because some of those might
640# disable inlining.
641#
642AC_DEFUN(AC_LBL_C_INLINE,
643    [AC_MSG_CHECKING(for inline)
644    save_CFLAGS="$CFLAGS"
645    CFLAGS="$V_CCOPT"
646    AC_CACHE_VAL(ac_cv_lbl_inline, [
647	ac_cv_lbl_inline=""
648	ac_lbl_cc_inline=no
649	for ac_lbl_inline in inline __inline__ __inline
650	do
651	    AC_TRY_COMPILE(
652		[#define inline $ac_lbl_inline
653		static inline struct iltest *foo(void);
654		struct iltest {
655		    int iltest1;
656		    int iltest2;
657		};
658
659		static inline struct iltest *
660		foo()
661		{
662		    static struct iltest xxx;
663
664		    return &xxx;
665		}],,ac_lbl_cc_inline=yes,)
666	    if test "$ac_lbl_cc_inline" = yes ; then
667		break;
668	    fi
669	done
670	if test "$ac_lbl_cc_inline" = yes ; then
671	    ac_cv_lbl_inline=$ac_lbl_inline
672	fi])
673    CFLAGS="$save_CFLAGS"
674    if test ! -z "$ac_cv_lbl_inline" ; then
675	AC_MSG_RESULT($ac_cv_lbl_inline)
676    else
677	AC_MSG_RESULT(no)
678    fi
679    AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
680
681#
682# Test whether we have __atomic_load_n() and __atomic_store_n().
683#
684# We use AC_TRY_LINK because AC_TRY_COMPILE will succeed, as the
685# compiler will just think that those functions are undefined,
686# and perhaps warn about that, but not fail to compile.
687#
688AC_DEFUN(AC_PCAP_C___ATOMICS,
689    [
690	AC_MSG_CHECKING(for __atomic_load_n)
691	AC_CACHE_VAL(ac_cv_have___atomic_load_n,
692	    AC_TRY_LINK([],
693		[
694		    int i = 17;
695		    int j;
696		    j = __atomic_load_n(&i, __ATOMIC_RELAXED);
697		],
698		ac_have___atomic_load_n=yes,
699		ac_have___atomic_load_n=no))
700	AC_MSG_RESULT($ac_have___atomic_load_n)
701	if test $ac_have___atomic_load_n = yes ; then
702	    AC_DEFINE(HAVE___ATOMIC_LOAD_N, 1,
703		[define if __atomic_load_n is supported by the compiler])
704	fi
705
706	AC_MSG_CHECKING(for __atomic_store_n)
707	AC_CACHE_VAL(ac_cv_have___atomic_store_n,
708	    AC_TRY_LINK([],
709		[
710		    int i;
711		    __atomic_store_n(&i, 17, __ATOMIC_RELAXED);
712		],
713		ac_have___atomic_store_n=yes,
714		ac_have___atomic_store_n=no))
715	AC_MSG_RESULT($ac_have___atomic_store_n)
716	if test $ac_have___atomic_store_n = yes ; then
717	    AC_DEFINE(HAVE___ATOMIC_STORE_N, 1,
718		[define if __atomic_store_n is supported by the compiler])
719	fi])
720
721dnl
722dnl If using gcc, make sure we have ANSI ioctl definitions
723dnl
724dnl usage:
725dnl
726dnl	AC_LBL_FIXINCLUDES
727dnl
728AC_DEFUN(AC_LBL_FIXINCLUDES,
729    [if test "$GCC" = yes ; then
730	    AC_MSG_CHECKING(for ANSI ioctl definitions)
731	    AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
732		AC_TRY_COMPILE(
733		    [/*
734		     * This generates a "duplicate case value" when fixincludes
735		     * has not be run.
736		     */
737#		include <sys/types.h>
738#		include <sys/time.h>
739#		include <sys/ioctl.h>
740#		ifdef HAVE_SYS_IOCCOM_H
741#		include <sys/ioccom.h>
742#		endif],
743		    [switch (0) {
744		    case _IO('A', 1):;
745		    case _IO('B', 1):;
746		    }],
747		    ac_cv_lbl_gcc_fixincludes=yes,
748		    ac_cv_lbl_gcc_fixincludes=no))
749	    AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
750	    if test $ac_cv_lbl_gcc_fixincludes = no ; then
751		    # Don't cache failure
752		    unset ac_cv_lbl_gcc_fixincludes
753		    AC_MSG_ERROR(see the INSTALL for more info)
754	    fi
755    fi])
756
757dnl
758dnl Checks to see if union wait is used with WEXITSTATUS()
759dnl
760dnl usage:
761dnl
762dnl	AC_LBL_UNION_WAIT
763dnl
764dnl results:
765dnl
766dnl	DECLWAITSTATUS (defined)
767dnl
768AC_DEFUN(AC_LBL_UNION_WAIT,
769    [AC_MSG_CHECKING(if union wait is used)
770    AC_CACHE_VAL(ac_cv_lbl_union_wait,
771	AC_TRY_COMPILE([
772#	include <sys/types.h>
773#	include <sys/wait.h>],
774	    [int status;
775	    u_int i = WEXITSTATUS(status);
776	    u_int j = waitpid(0, &status, 0);],
777	    ac_cv_lbl_union_wait=no,
778	    ac_cv_lbl_union_wait=yes))
779    AC_MSG_RESULT($ac_cv_lbl_union_wait)
780    if test $ac_cv_lbl_union_wait = yes ; then
781	    AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait])
782    else
783	    AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
784    fi])
785
786dnl
787dnl Checks to see if -R is used
788dnl
789dnl usage:
790dnl
791dnl	AC_LBL_HAVE_RUN_PATH
792dnl
793dnl results:
794dnl
795dnl	ac_cv_lbl_have_run_path (yes or no)
796dnl
797AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
798    [AC_MSG_CHECKING(for ${CC-cc} -R)
799    AC_CACHE_VAL(ac_cv_lbl_have_run_path,
800	[echo 'main(){}' > conftest.c
801	${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
802	if test ! -s conftest.out ; then
803		ac_cv_lbl_have_run_path=yes
804	else
805		ac_cv_lbl_have_run_path=no
806	fi
807	rm -f -r conftest*])
808    AC_MSG_RESULT($ac_cv_lbl_have_run_path)
809    ])
810
811dnl
812dnl If the file .devel exists:
813dnl	Add some warning flags if the compiler supports them
814dnl	If an os prototype include exists, symlink os-proto.h to it
815dnl
816dnl usage:
817dnl
818dnl	AC_LBL_DEVEL(copt)
819dnl
820dnl results:
821dnl
822dnl	$1 (copt appended)
823dnl	HAVE_OS_PROTO_H (defined)
824dnl	os-proto.h (symlinked)
825dnl
826AC_DEFUN(AC_LBL_DEVEL,
827    [rm -f os-proto.h
828    if test "${LBL_CFLAGS+set}" = set; then
829	    $1="$$1 ${LBL_CFLAGS}"
830    fi
831    if test -f .devel ; then
832	    #
833	    # Skip all the warning option stuff on some compilers.
834	    #
835	    if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
836		    AC_LBL_CHECK_COMPILER_OPT($1, -W)
837		    AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
838		    AC_LBL_CHECK_COMPILER_OPT($1, -Wcomma)
839		    # Warns about safeguards added in case the enums are
840		    # extended
841		    # AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default)
842		    AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation)
843		    AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral)
844		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-noreturn)
845		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
846		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
847		    AC_LBL_CHECK_COMPILER_OPT($1, -Wnull-pointer-subtraction)
848		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
849		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
850		    AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
851		    AC_LBL_CHECK_COMPILER_OPT($1, -Wshorten-64-to-32)
852		    AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
853		    AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
854		    AC_LBL_CHECK_COMPILER_OPT($1, -Wundef)
855		    #
856		    # This can cause problems with ntohs(), ntohl(),
857		    # htons(), and htonl() on some platforms, such
858		    # as OpenBSD 6.3 with Clang 5.0.1.  I guess the
859		    # problem is that the macro that ultimately does
860		    # the byte-swapping involves a conditional
861		    # expression that tests whether the value being
862		    # swapped is a compile-time constant or not,
863		    # using __builtin_constant_p(), and, depending
864		    # on whether it is, does a compile-time swap or
865		    # a run-time swap; perhaps the compiler always
866		    # considers one of the two results of the
867		    # conditional expression is never evaluated,
868		    # because the conditional check is done at
869		    # compile time, and thus always says "that
870		    # expression is never executed".
871		    #
872		    # (Perhaps there should be a way of flagging
873		    # an expression that you *want* evaluated at
874		    # compile time, so that the compiler 1) warns
875		    # if it *can't* be evaluated at compile time
876		    # and 2) *doesn't* warn that the true or false
877		    # branch will never be reached.)
878		    #
879		    AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code,
880		      [
881#include <arpa/inet.h>
882
883unsigned short
884testme(unsigned short a)
885{
886	return ntohs(a);
887}
888		      ],
889		      [generates warnings from ntohs()])
890		    AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-parameter)
891		    AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-variable)
892		    AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter)
893		    AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
894	    fi
895	    AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
896	    #
897	    # We used to set -n32 for IRIX 6 when not using GCC (presumed
898	    # to mean that we're using MIPS C or MIPSpro C); it specified
899	    # the "new" faster 32-bit ABI, introduced in IRIX 6.2.  I'm
900	    # not sure why that would be something to do *only* with a
901	    # .devel file; why should the ABI for which we produce code
902	    # depend on .devel?
903	    #
904	    os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
905	    name="lbl/os-$os.h"
906	    if test -f $name ; then
907		    ln -s $name os-proto.h
908		    AC_DEFINE(HAVE_OS_PROTO_H, 1,
909			[if there's an os_proto.h for this platform, to use additional prototypes])
910	    else
911		    AC_MSG_WARN(can't find $name)
912	    fi
913    fi])
914
915dnl
916dnl Improved version of AC_CHECK_LIB
917dnl
918dnl Thanks to John Hawkinson (jhawk@mit.edu)
919dnl
920dnl usage:
921dnl
922dnl	AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
923dnl	    ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
924dnl
925dnl results:
926dnl
927dnl	LIBS
928dnl
929dnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS"
930dnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more.
931dnl We keep it around for reference purposes in case it's ever
932dnl useful in the future.
933dnl
934
935define(AC_LBL_CHECK_LIB,
936[AC_MSG_CHECKING([for $2 in -l$1])
937dnl Use a cache variable name containing the library, function
938dnl name, and extra libraries to link with, because the test really is
939dnl for library $1 defining function $2, when linked with potinal
940dnl library $5, not just for library $1.  Separate tests with the same
941dnl $1 and different $2's or $5's may have different results.
942ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
943AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
944[ac_save_LIBS="$LIBS"
945LIBS="-l$1 $5 $LIBS"
946AC_TRY_LINK(dnl
947ifelse([$2], [main], , dnl Avoid conflicting decl of main.
948[/* Override any gcc2 internal prototype to avoid an error.  */
949]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
950extern "C"
951#endif
952])dnl
953[/* We use char because int might match the return type of a gcc2
954    builtin and then its argument prototype would still apply.  */
955char $2();
956]),
957	    [$2()],
958	    eval "ac_cv_lbl_lib_$ac_lib_var=yes",
959	    eval "ac_cv_lbl_lib_$ac_lib_var=no")
960LIBS="$ac_save_LIBS"
961])dnl
962if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
963  AC_MSG_RESULT(yes)
964  ifelse([$3], ,
965[changequote(, )dnl
966  ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
967    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
968changequote([, ])dnl
969  AC_DEFINE_UNQUOTED($ac_tr_lib)
970  LIBS="-l$1 $LIBS"
971], [$3])
972else
973  AC_MSG_RESULT(no)
974ifelse([$4], , , [$4
975])dnl
976fi
977])
978
979dnl
980dnl AC_LBL_LIBRARY_NET
981dnl
982dnl Look for various networking-related libraries that we may need.
983dnl
984dnl We need getaddrinfo() to translate host names in filters to IP
985dnl addresses. We use getaddrinfo() because we want a portable
986dnl thread-safe way of getting information for a host name or port;
987dnl there exist _r versions of gethostbyname() and getservbyname() on
988dnl some platforms, but not on all platforms.
989dnl
990dnl We may also need socket() and other socket functions to support:
991dnl
992dnl   Local packet capture with capture mechanisms that use sockets.
993dnl
994dnl   Local capture device enumeration if a socket call is needed to
995dnl   enumerate devices or get device attributes.
996dnl
997dnl   Packet capture from services that put captured packets on the
998dnl   network, such as rpcap servers.
999dnl
1000dnl We may also need getnameinfo() for packet capture from services
1001dnl that put packets on the network.
1002dnl
1003AC_DEFUN(AC_LBL_LIBRARY_NET, [
1004    #
1005    # Most operating systems have getaddrinfo(), and the other routines
1006    # we may need, in the default searched libraries (e.g., libc).
1007    # Check there first.
1008    #
1009    AC_CHECK_FUNC(getaddrinfo,,
1010    [
1011	#
1012	# Not found in the standard system libraries.
1013	#
1014	# In some versions of Solaris, we need to link with libsocket
1015	# and libnsl, so check in libsocket and also link with liblnsl
1016	# when doing this test.
1017	#
1018	# Linking with libsocket and libnsl will find all the routines
1019	# we need.
1020	#
1021	AC_CHECK_LIB(socket, getaddrinfo,
1022	[
1023	    #
1024	    # OK, we found it in libsocket.
1025	    #
1026	    LIBS="-lsocket -lnsl $LIBS"
1027	],
1028	[
1029	    #
1030	    # Not found in libsocket; test for it in libnetwork, which
1031	    # is where it is in Haiku.
1032	    #
1033	    # Linking with libnetwork will find all the routines we
1034	    # need.
1035	    #
1036	    AC_CHECK_LIB(network, getaddrinfo,
1037	    [
1038		#
1039		# OK, we found it in libnetwork.
1040		#
1041		LIBS="-lnetwork $LIBS"
1042	    ],
1043	    [
1044		#
1045		# We didn't find it.
1046		#
1047		AC_MSG_ERROR([getaddrinfo is required, but wasn't found])
1048	    ])
1049	], -lnsl)
1050
1051	#
1052	# We require a version of recvmsg() that conforms to the Single
1053	# UNIX Specification, so that we can check whether a datagram
1054	# received with recvmsg() was truncated when received due to the
1055	# buffer being too small.
1056	#
1057	# On most systems, the version of recvmsg() in the libraries
1058	# found above conforms to the SUS.
1059	#
1060	# On at least some versions of Solaris, it does not conform to
1061	# the SUS, and we need the version in libxnet, which does
1062	# conform.
1063	#
1064	# Check whether libxnet exists and has a version of recvmsg();
1065	# if it does, link with libxnet before we link with libsocket,
1066	# to get that version.
1067	#
1068	# This test also links with libsocket and libnsl.
1069	#
1070	AC_CHECK_LIB(xnet, recvmsg,
1071	[
1072	    #
1073	    # libxnet has recvmsg(); link with it as well.
1074	    #
1075	    LIBS="-lxnet $LIBS"
1076	], , -lsocket -lnsl)
1077    ])
1078
1079    #
1080    # DLPI needs putmsg under HP-UX, so test for -lstr while we're at it.
1081    #
1082    AC_SEARCH_LIBS(putmsg, str)
1083])
1084
1085m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
1086dnl pkg.m4 - Macros to locate and utilise pkg-config.   -*- Autoconf -*-
1087dnl serial 11 (pkg-config-0.29)
1088dnl
1089dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
1090dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
1091dnl
1092dnl This program is free software; you can redistribute it and/or modify
1093dnl it under the terms of the GNU General Public License as published by
1094dnl the Free Software Foundation; either version 2 of the License, or
1095dnl (at your option) any later version.
1096dnl
1097dnl This program is distributed in the hope that it will be useful, but
1098dnl WITHOUT ANY WARRANTY; without even the implied warranty of
1099dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1100dnl General Public License for more details.
1101dnl
1102dnl You should have received a copy of the GNU General Public License
1103dnl along with this program; if not, write to the Free Software
1104dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1105dnl 02111-1307, USA.
1106dnl
1107dnl As a special exception to the GNU General Public License, if you
1108dnl distribute this file as part of a program that contains a
1109dnl configuration script generated by Autoconf, you may include it under
1110dnl the same distribution terms that you use for the rest of that
1111dnl program.
1112
1113dnl PKG_PREREQ(MIN-VERSION)
1114dnl -----------------------
1115dnl Since: 0.29
1116dnl
1117dnl Verify that the version of the pkg-config macros are at least
1118dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
1119dnl installed version of pkg-config, this checks the developer's version
1120dnl of pkg.m4 when generating configure.
1121dnl
1122dnl To ensure that this macro is defined, also add:
1123dnl m4_ifndef([PKG_PREREQ],
1124dnl     [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
1125dnl
1126dnl See the "Since" comment for each macro you use to see what version
1127dnl of the macros you require.
1128m4_defun([PKG_PREREQ],
1129[m4_define([PKG_MACROS_VERSION], [0.29])
1130m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
1131    [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
1132])dnl PKG_PREREQ
1133
1134dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
1135dnl ----------------------------------
1136dnl Since: 0.16
1137dnl
1138dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
1139dnl first found in the path. Checks that the version of pkg-config found
1140dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.17.0 is
1141dnl used since that's the first version where --static was supported.
1142AC_DEFUN([PKG_PROG_PKG_CONFIG],
1143[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
1144m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
1145m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
1146AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
1147AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
1148AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
1149
1150if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
1151	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
1152fi
1153if test -n "$PKG_CONFIG"; then
1154	_pkg_min_version=m4_default([$1], [0.17.0])
1155	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
1156	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
1157		AC_MSG_RESULT([yes])
1158	else
1159		AC_MSG_RESULT([no])
1160		PKG_CONFIG=""
1161	fi
1162fi[]dnl
1163])dnl PKG_PROG_PKG_CONFIG
1164
1165dnl PKG_CHECK_EXISTS(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1166dnl -------------------------------------------------------------------
1167dnl Since: 0.18
1168dnl
1169dnl Check to see whether a particular module exists. Similar to
1170dnl PKG_CHECK_MODULE(), but does not set variables or print errors.
1171AC_DEFUN([PKG_CHECK_EXISTS],
1172[
1173if test -n "$PKG_CONFIG" && \
1174    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
1175  m4_default([$2], [:])
1176m4_ifvaln([$3], [else
1177  $3])dnl
1178fi])
1179
1180dnl _PKG_CONFIG_WITH_FLAGS([VARIABLE], [FLAGS], [MODULE])
1181dnl ---------------------------------------------
1182dnl Internal wrapper calling pkg-config via PKG_CONFIG and, if
1183dnl pkg-config fails, reporting the error and quitting.
1184m4_define([_PKG_CONFIG_WITH_FLAGS],
1185[if test ! -n "$$1"; then
1186    $1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
1187    if test "x$?" != "x0"; then
1188        #
1189        # That failed - report an error.
1190        # Re-run the command, telling pkg-config to print an error
1191        # message, capture the error message, and report it.
1192        # This causes the configuration script to fail, as it means
1193        # the script is almost certainly doing something wrong.
1194        #
1195        _PKG_SHORT_ERRORS_SUPPORTED
1196	if test $_pkg_short_errors_supported = yes; then
1197	    _pkg_error_string=`$PKG_CONFIG --short-errors --print-errors $2 "$3" 2>&1`
1198	else
1199	    _pkg_error_string=`$PKG_CONFIG --print-errors $2 "$3" 2>&1`
1200	fi
1201        AC_MSG_ERROR([$PKG_CONFIG $2 "$3" failed: $_pkg_error_string])
1202    fi
1203 fi[]dnl
1204])dnl _PKG_CONFIG_WITH_FLAGS
1205
1206
1207dnl _PKG_CONFIG([VARIABLE], [FLAGS], [MODULE])
1208dnl ---------------------------------------------
1209dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
1210dnl pkg_failed based on the result.
1211m4_define([_PKG_CONFIG],
1212[if test -n "$$1"; then
1213    pkg_cv_[]$1="$$1"
1214 elif test -n "$PKG_CONFIG"; then
1215    PKG_CHECK_EXISTS([$3],
1216                     [pkg_cv_[]$1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
1217		      test "x$?" != "x0" && pkg_failed=yes ],
1218		     [pkg_failed=yes])
1219 else
1220    pkg_failed=untried
1221fi[]dnl
1222])dnl _PKG_CONFIG
1223
1224dnl _PKG_SHORT_ERRORS_SUPPORTED
1225dnl ---------------------------
1226dnl Internal check to see if pkg-config supports short errors.
1227AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
1228[
1229if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
1230        _pkg_short_errors_supported=yes
1231else
1232        _pkg_short_errors_supported=no
1233fi[]dnl
1234])dnl _PKG_SHORT_ERRORS_SUPPORTED
1235
1236
1237dnl PKG_CHECK_MODULE(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1238dnl   [ACTION-IF-NOT-FOUND])
1239dnl --------------------------------------------------------------
1240dnl Since: 0.4.0
1241AC_DEFUN([PKG_CHECK_MODULE],
1242[
1243AC_MSG_CHECKING([for $2 with pkg-config])
1244if test -n "$PKG_CONFIG"; then
1245    AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $2, overriding pkg-config])dnl
1246    AC_ARG_VAR([$1][_LIBS], [linker flags for $2, overriding pkg-config])dnl
1247    AC_ARG_VAR([$1][_LIBS_STATIC], [static-link linker flags for $2, overriding pkg-config])dnl
1248
1249    if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
1250	#
1251	# The package was found, so try to get its C flags and
1252	# libraries.
1253	#
1254        AC_MSG_RESULT([found])
1255	_PKG_CONFIG_WITH_FLAGS([$1][_CFLAGS], [--cflags], [$2])
1256	_PKG_CONFIG_WITH_FLAGS([$1][_LIBS], [--libs], [$2])
1257	_PKG_CONFIG_WITH_FLAGS([$1][_LIBS_STATIC], [--libs --static], [$2])
1258        m4_default([$3], [:])
1259    else
1260        AC_MSG_RESULT([not found])
1261        m4_default([$4], [:])
1262    fi
1263else
1264    # No pkg-config, so obviously not found with pkg-config.
1265    AC_MSG_RESULT([pkg-config not found])
1266    m4_default([$4], [:])
1267fi
1268])dnl PKG_CHECK_MODULE
1269
1270
1271dnl PKG_CHECK_MODULE_STATIC(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1272dnl   [ACTION-IF-NOT-FOUND])
1273dnl ---------------------------------------------------------------------
1274dnl Since: 0.29
1275dnl
1276dnl Checks for existence of MODULE and gathers its build flags with
1277dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
1278dnl and VARIABLE-PREFIX_LIBS from --libs.
1279AC_DEFUN([PKG_CHECK_MODULE_STATIC],
1280[
1281_save_PKG_CONFIG=$PKG_CONFIG
1282PKG_CONFIG="$PKG_CONFIG --static"
1283PKG_CHECK_MODULE($@)
1284PKG_CONFIG=$_save_PKG_CONFIG[]dnl
1285])dnl PKG_CHECK_MODULE_STATIC
1286
1287
1288dnl PKG_INSTALLDIR([DIRECTORY])
1289dnl -------------------------
1290dnl Since: 0.27
1291dnl
1292dnl Substitutes the variable pkgconfigdir as the location where a module
1293dnl should install pkg-config .pc files. By default the directory is
1294dnl $libdir/pkgconfig, but the default can be changed by passing
1295dnl DIRECTORY. The user can override through the --with-pkgconfigdir
1296dnl parameter.
1297AC_DEFUN([PKG_INSTALLDIR],
1298[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
1299m4_pushdef([pkg_description],
1300    [pkg-config installation directory @<:@]pkg_default[@:>@])
1301AC_ARG_WITH([pkgconfigdir],
1302    [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
1303    [with_pkgconfigdir=]pkg_default)
1304AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
1305m4_popdef([pkg_default])
1306m4_popdef([pkg_description])
1307])dnl PKG_INSTALLDIR
1308
1309
1310dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
1311dnl --------------------------------
1312dnl Since: 0.27
1313dnl
1314dnl Substitutes the variable noarch_pkgconfigdir as the location where a
1315dnl module should install arch-independent pkg-config .pc files. By
1316dnl default the directory is $datadir/pkgconfig, but the default can be
1317dnl changed by passing DIRECTORY. The user can override through the
1318dnl --with-noarch-pkgconfigdir parameter.
1319AC_DEFUN([PKG_NOARCH_INSTALLDIR],
1320[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
1321m4_pushdef([pkg_description],
1322    [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
1323AC_ARG_WITH([noarch-pkgconfigdir],
1324    [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
1325    [with_noarch_pkgconfigdir=]pkg_default)
1326AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
1327m4_popdef([pkg_default])
1328m4_popdef([pkg_description])
1329])dnl PKG_NOARCH_INSTALLDIR
1330
1331
1332dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
1333dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1334dnl -------------------------------------------
1335dnl Since: 0.28
1336dnl
1337dnl Retrieves the value of the pkg-config variable for the given module.
1338AC_DEFUN([PKG_CHECK_VAR],
1339[
1340AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
1341
1342_PKG_CONFIG([$1], [--variable="][$3]["], [$2])
1343AS_VAR_COPY([$1], [pkg_cv_][$1])
1344
1345AS_VAR_IF([$1], [""], [$5], [$4])dnl
1346])dnl PKG_CHECK_VAR
1347