1 dnl Copyright (c) 1995, 1996, 1997, 1998
2 dnl The Regents of the University of California. All rights reserved.
4 dnl Redistribution and use in source and binary forms, with or without
5 dnl modification, are permitted provided that: (1) source code distributions
6 dnl retain the above copyright notice and this paragraph in its entirety, (2)
7 dnl distributions including binary code include the above copyright notice and
8 dnl this paragraph in its entirety in the documentation or other materials
9 dnl provided with the distribution, and (3) all advertising materials mentioning
10 dnl features or use of this software display the following acknowledgement:
11 dnl ``This product includes software developed by the University of California,
12 dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13 dnl the University nor the names of its contributors may be used to endorse
14 dnl or promote products derived from this software without specific prior
15 dnl written permission.
16 dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 dnl LBL autoconf macros
24 dnl Do whatever AC_LBL_C_INIT work is necessary before using AC_PROG_CC.
26 dnl It appears that newer versions of autoconf (2.64 and later) will,
27 dnl if you use AC_TRY_COMPILE in a macro, stick AC_PROG_CC at the
28 dnl beginning of the macro, even if the macro itself calls AC_PROG_CC.
29 dnl See the "Prerequisite Macros" and "Expanded Before Required" sections
30 dnl in the Autoconf documentation.
32 dnl This causes a steaming heap of fail in our case, as we were, in
33 dnl AC_LBL_C_INIT, doing the tests we now do in AC_LBL_C_INIT_BEFORE_CC,
34 dnl calling AC_PROG_CC, and then doing the tests we now do in
35 dnl AC_LBL_C_INIT. Now, we run AC_LBL_C_INIT_BEFORE_CC, AC_PROG_CC,
36 dnl and AC_LBL_C_INIT at the top level.
38 AC_DEFUN(AC_LBL_C_INIT_BEFORE_CC,
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])
45 if test "${srcdir}" != "." ; then
48 if test "${CFLAGS+set}" = set; then
51 if test -z "$CC" -a "$with_gcc" = no ; then
58 dnl Determine which compiler we're using (cc or gcc)
59 dnl If using gcc, determine the version number
61 dnl require that it support ansi prototypes
62 dnl use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to
63 dnl do that ourselves for gcc)
64 dnl add -g flags, as appropriate
65 dnl explicitly specify /usr/local/include
67 dnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler
68 dnl that defines __GNUC__, which means clang, for example, counts as "gcc".
72 dnl AC_LBL_C_INIT(copt, incls)
82 AC_DEFUN(AC_LBL_C_INIT,
84 AC_BEFORE([$0], [AC_LBL_DEVEL])
85 AC_BEFORE([$0], [AC_LBL_SHLIBS_INIT])
86 if test "$GCC" = yes ; then
88 # -Werror forces warnings to be errors.
90 ac_lbl_cc_force_warning_errors=-Werror
93 # Try to have the compiler default to hiding symbols,
94 # so that only symbols explicitly exported with
95 # PCAP_API will be visible outside (shared) libraries.
97 AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
99 $2="$$2 -I/usr/local/include"
100 LDFLAGS="$LDFLAGS -L/usr/local/lib"
106 # This is assumed either to be GCC or clang, both
107 # of which use -Werror to force warnings to be errors.
109 ac_lbl_cc_force_warning_errors=-Werror
112 # Try to have the compiler default to hiding symbols,
113 # so that only symbols explicitly exported with
114 # PCAP_API will be visible outside (shared) libraries.
116 AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
121 # HP C, which is what we presume we're using, doesn't
122 # exit with a non-zero exit status if we hand it an
123 # invalid -W flag, can't be forced to do so even with
124 # +We, and doesn't handle GCC-style -W flags, so we
125 # don't want to try using GCC-style -W flags.
127 ac_lbl_cc_dont_try_gcc_dashW=yes
132 # Assumed to be Sun C, which requires -errwarn to force
133 # warnings to be treated as errors.
135 ac_lbl_cc_force_warning_errors=-errwarn
138 # Try to have the compiler default to hiding symbols,
139 # so that only symbols explicitly exported with
140 # PCAP_API will be visible outside (shared) libraries.
142 AC_LBL_CHECK_COMPILER_OPT($1, -xldscope=hidden)
150 dnl Save the values of various variables that affect compilation and
151 dnl linking, and that we don't ourselves modify persistently; done
152 dnl before a test involving compiling or linking is done, so that we
153 dnl can restore those variables after the test is done.
155 AC_DEFUN(AC_LBL_SAVE_CHECK_STATE,
157 save_CFLAGS="$CFLAGS"
159 save_LDFLAGS="$LDFLAGS"
163 dnl Restore the values of variables saved by AC_LBL_SAVE_CHECK_STATE.
165 AC_DEFUN(AC_LBL_RESTORE_CHECK_STATE,
167 CFLAGS="$save_CFLAGS"
169 LDFLAGS="$save_LDFLAGS"
173 dnl Check whether the compiler option specified as the second argument
174 dnl is supported by the compiler and, if so, add it to the macro
175 dnl specified as the first argument
177 dnl If a third argument is supplied, treat it as C code to be compiled
178 dnl with the flag in question, and the "treat warnings as errors" flag
179 dnl set, and don't add the flag to the first argument if the compile
180 dnl fails; this is for warning options cause problems that can't be
181 dnl worked around. If a third argument is supplied, a fourth argument
182 dnl should also be supplied; it's a message describing what the test
183 dnl program is checking.
185 AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
187 AC_MSG_CHECKING([whether the compiler supports the $2 option])
188 save_CFLAGS="$CFLAGS"
191 # XXX - yes, this depends on the way AC_LANG_WERROR works,
192 # but no mechanism is provided to turn AC_LANG_WERROR on
193 # *and then turn it back off*, so that we *only* do it when
194 # testing compiler options - 15 years after somebody asked
197 # https://autoconf.gnu.narkive.com/gTAVmfKD/how-to-cancel-flags-set-by-ac-lang-werror
199 save_ac_c_werror_flag="$ac_c_werror_flag"
202 # We use AC_LANG_SOURCE() so that we can control the complete
203 # content of the program being compiled. We do not, for example,
204 # want the default "int main()" that AC_LANG_PROGRAM() generates,
205 # as it will generate a warning with -Wold-style-definition, meaning
206 # that we would treat it as not working, as the test will fail if
207 # *any* error output, including a warning due to the flag we're
208 # testing, is generated; see
210 # https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
211 # https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
213 # This may, as per those two messages, be fixed in autoconf 2.70,
214 # but we only require 2.69 or newer for now.
217 [AC_LANG_SOURCE([[int main(void) { return 0; }]])],
220 can_add_to_cflags=yes
222 # The compile supports this; do we have some C code for
223 # which the warning should *not* appear?
224 # We test the fourth argument because the third argument
225 # could contain quotes, breaking the test.
229 CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
230 AC_MSG_CHECKING(whether $2 $4)
232 [AC_LANG_SOURCE($3)],
247 CFLAGS="$save_CFLAGS"
248 if test x"$can_add_to_cflags" = "xyes"
255 CFLAGS="$save_CFLAGS"
257 ac_c_werror_flag="$save_ac_c_werror_flag"
261 dnl Check whether the compiler supports an option to generate
262 dnl Makefile-style dependency lines
264 dnl GCC uses -M for this. Non-GCC compilers that support this
265 dnl use a variety of flags, including but not limited to -M.
267 dnl We test whether the flag in question is supported, as older
268 dnl versions of compilers might not support it.
270 dnl We don't try all the possible flags, just in case some flag means
271 dnl "generate dependencies" on one compiler but means something else
272 dnl on another compiler.
274 dnl Most compilers that support this send the output to the standard
275 dnl output by default. IBM's XLC, however, supports -M but sends
276 dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
277 dnl to work around that, so we don't bother with XLC.
279 AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
281 AC_MSG_CHECKING([whether the compiler supports generating dependencies])
282 if test "$GCC" = yes ; then
284 # GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
285 # though it's not); we assume that, in this case, the flag
288 ac_lbl_dependency_flag="-M"
291 # Not GCC or a compiler deemed to be GCC; what platform is
292 # this? (We're assuming that if the compiler isn't GCC
293 # it's the compiler from the vendor of the OS; that won't
294 # necessarily be true for x86 platforms, where it might be
295 # the Intel C compiler.)
303 ac_lbl_dependency_flag="-M"
310 ac_lbl_dependency_flag="-xM"
315 # HP's older C compilers don't support this.
316 # HP's newer C compilers support this with
317 # either +M or +Make; the older compilers
318 # interpret +M as something completely
319 # different, so we use +Make so we don't
320 # think it works with the older compilers.
322 ac_lbl_dependency_flag="+Make"
327 # Not one of the above; assume no support for
328 # generating dependencies.
330 ac_lbl_dependency_flag=""
336 # Is ac_lbl_dependency_flag defined and, if so, does the compiler
339 # Note: clang doesn't seem to exit with an error status when handed
340 # an unknown non-warning error, even if you pass it
341 # -Werror=unknown-warning-option. However, it always supports
342 # -M, so the fact that this test always succeeds with clang
345 if test ! -z "$ac_lbl_dependency_flag"; then
347 [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
348 if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
349 AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
350 DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
351 MKDEP='${top_srcdir}/mkdep'
355 # We can't run mkdep, so have "make depend" do
358 MKDEP='${top_srcdir}/nomkdep'
364 # We can't run mkdep, so have "make depend" do
367 MKDEP='${top_srcdir}/nomkdep'
369 AC_SUBST(DEPENDENCY_CFLAG)
374 dnl Determine what options are needed to build a shared library
378 dnl AC_LBL_SHLIBS_INIT
382 dnl V_SHLIB_CCOPT (modified to build position-independent code)
387 AC_DEFUN(AC_LBL_SHLIBS_INIT,
389 if test "$GCC" = yes ; then
391 # On platforms where we build a shared library:
393 # add options to generate position-independent code,
394 # if necessary (it's the default in AIX and Darwin/macOS);
396 # define option to set the soname of the shared library,
397 # if the OS supports that;
399 # add options to specify, at link time, a directory to
400 # add to the run-time search path, if that's necessary.
403 V_SHLIB_OPT="-shared"
409 freebsd*|netbsd*|openbsd*|dragonfly*|linux*|haiku*|midipix*|gnu*)
411 # Platforms where the C compiler is GCC or accepts
412 # compatible command-line arguments, and the linker
413 # is the GNU linker or accepts compatible command-line
416 # Some instruction sets require -fPIC on some
417 # operating systems. Check for them. If you
418 # have a combination that requires it, add it
427 freebsd*|openbsd*|linux*)
433 V_SHLIB_CCOPT="$V_SHLIB_CCOPT $PIC_OPT"
434 V_SONAME_OPT="-Wl,-soname,"
438 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
440 # XXX - this assumes GCC is using the HP linker,
441 # rather than the GNU linker, and that the "+h"
442 # option is used on all HP-UX platforms, both .sl
445 V_SONAME_OPT="-Wl,+h,"
447 # By default, directories specified with -L
448 # are added to the run-time search path, so
449 # we don't add them in pcap-config.
454 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
456 # Sun/Oracle's C compiler, GCC, and GCC-compatible
457 # compilers support -Wl,{comma-separated list of options},
458 # and we use the C compiler, not ld, for all linking,
459 # including linking to produce a shared library.
461 V_SONAME_OPT="-Wl,-h,"
466 # Set the appropriate compiler flags and, on platforms
467 # where we build a shared library:
469 # add options to generate position-independent code,
470 # if necessary (it's the default in Darwin/macOS);
472 # if we generate ".so" shared libraries, define the
473 # appropriate options for building the shared library;
475 # add options to specify, at link time, a directory to
476 # add to the run-time search path, if that's necessary.
478 # Note: spaces after V_SONAME_OPT are significant; on
479 # some platforms the soname is passed with a GCC-like
480 # "-Wl,-soname,{soname}" option, with the soname part
481 # of the option, while on other platforms the C compiler
482 # driver takes it as a regular option with the soname
483 # following the option.
489 V_SHLIB_OPT="-G -bnoentry -bexpall"
492 freebsd*|netbsd*|openbsd*|dragonfly*|linux*)
494 # Platforms where the C compiler is GCC or accepts
495 # compatible command-line arguments, and the linker
496 # is the GNU linker or accepts compatible command-line
499 # XXX - does 64-bit SPARC require -fPIC?
501 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
503 V_SHLIB_OPT="-shared"
504 V_SONAME_OPT="-Wl,-soname,"
508 V_SHLIB_CCOPT="$V_SHLIB_CCOPT +z"
513 # By default, directories specified with -L
514 # are added to the run-time search path, so
515 # we don't add them in pcap-config.
520 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -Kpic"
524 # Sun/Oracle's C compiler, GCC, and GCC-compatible
525 # compilers support -Wl,{comma-separated list of options},
526 # and we use the C compiler, not ld, for all linking,
527 # including linking to produce a shared library.
529 V_SONAME_OPT="-Wl,-h,"
536 # Test whether we have __atomic_load_n() and __atomic_store_n().
538 # We use AC_LINK_IFELSE because AC_TRY_COMPILE will succeed, as the
539 # compiler will just think that those functions are undefined,
540 # and perhaps warn about that, but not fail to compile.
542 AC_DEFUN(AC_PCAP_C___ATOMICS,
544 AC_MSG_CHECKING(for __atomic_load_n)
545 AC_CACHE_VAL(ac_cv_have___atomic_load_n,
546 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
550 j = __atomic_load_n(&i, __ATOMIC_RELAXED);
552 [ac_have___atomic_load_n=yes],
553 [ac_have___atomic_load_n=no]))
554 AC_MSG_RESULT($ac_have___atomic_load_n)
555 if test $ac_have___atomic_load_n = yes ; then
556 AC_DEFINE(HAVE___ATOMIC_LOAD_N, 1,
557 [define if __atomic_load_n is supported by the compiler])
560 AC_MSG_CHECKING(for __atomic_store_n)
561 AC_CACHE_VAL(ac_cv_have___atomic_store_n,
562 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
565 __atomic_store_n(&i, 17, __ATOMIC_RELAXED);
567 [ac_have___atomic_store_n=yes],
568 [ac_have___atomic_store_n=no]))
569 AC_MSG_RESULT($ac_have___atomic_store_n)
570 if test $ac_have___atomic_store_n = yes ; then
571 AC_DEFINE(HAVE___ATOMIC_STORE_N, 1,
572 [define if __atomic_store_n is supported by the compiler])
576 dnl If the file .devel exists:
577 dnl Add some warning flags if the compiler supports them
578 dnl If an os prototype include exists, symlink os-proto.h to it
582 dnl AC_LBL_DEVEL(copt)
586 dnl $1 (copt appended)
587 dnl HAVE_OS_PROTO_H (defined)
588 dnl os-proto.h (symlinked)
590 AC_DEFUN(AC_LBL_DEVEL,
592 if test "${LBL_CFLAGS+set}" = set; then
593 $1="$$1 ${LBL_CFLAGS}"
595 if test -f .devel ; then
597 # Skip all the warning option stuff on some compilers.
599 if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
600 AC_LBL_CHECK_COMPILER_OPT($1, -W)
601 AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
602 AC_LBL_CHECK_COMPILER_OPT($1, -Wcomma)
603 # Warns about safeguards added in case the enums are
605 # AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default)
606 AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation)
607 AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral)
608 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-noreturn)
609 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
610 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
611 AC_LBL_CHECK_COMPILER_OPT($1, -Wnull-pointer-subtraction)
612 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
613 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
614 AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
615 AC_LBL_CHECK_COMPILER_OPT($1, -Wshorten-64-to-32)
616 AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
617 AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
618 AC_LBL_CHECK_COMPILER_OPT($1, -Wundef)
620 # This can cause problems with ntohs(), ntohl(),
621 # htons(), and htonl() on some platforms, such
622 # as OpenBSD 6.3 with Clang 5.0.1. I guess the
623 # problem is that the macro that ultimately does
624 # the byte-swapping involves a conditional
625 # expression that tests whether the value being
626 # swapped is a compile-time constant or not,
627 # using __builtin_constant_p(), and, depending
628 # on whether it is, does a compile-time swap or
629 # a run-time swap; perhaps the compiler always
630 # considers one of the two results of the
631 # conditional expression is never evaluated,
632 # because the conditional check is done at
633 # compile time, and thus always says "that
634 # expression is never executed".
636 # (Perhaps there should be a way of flagging
637 # an expression that you *want* evaluated at
638 # compile time, so that the compiler 1) warns
639 # if it *can't* be evaluated at compile time
640 # and 2) *doesn't* warn that the true or false
641 # branch will never be reached.)
643 AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code,
645 #include <arpa/inet.h>
648 testme(unsigned short a)
653 [generates warnings from ntohs()])
654 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-parameter)
655 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-variable)
656 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter)
657 AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
659 AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
660 AC_MSG_CHECKING([whether to use an os-proto.h header])
661 os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
663 if test -f $name ; then
664 AC_MSG_RESULT([yes, at "$name"])
665 ln -s $name os-proto.h
666 AC_DEFINE(HAVE_OS_PROTO_H, 1,
667 [if there's an os-proto.h for this platform, to use additional prototypes])
674 dnl AC_LBL_LIBRARY_NET
676 dnl Look for various networking-related libraries that we may need.
678 dnl We need getaddrinfo() to translate host names in filters to IP
679 dnl addresses. We use getaddrinfo() because we want a portable
680 dnl thread-safe way of getting information for a host name or port;
681 dnl there exist _r versions of gethostbyname() and getservbyname() on
682 dnl some platforms, but not on all platforms.
684 dnl We may also need socket() and other socket functions to support:
686 dnl Local packet capture with capture mechanisms that use sockets.
688 dnl Local capture device enumeration if a socket call is needed to
689 dnl enumerate devices or get device attributes.
691 dnl Packet capture from services that put captured packets on the
692 dnl network, such as rpcap servers.
694 dnl We may also need getnameinfo() for packet capture from services
695 dnl that put packets on the network.
697 AC_DEFUN(AC_LBL_LIBRARY_NET, [
699 # Most operating systems have getaddrinfo(), and the other routines
700 # we may need, in the default searched libraries (e.g., libc).
702 # These are: AIX, FreeBSD, Linux, macOS, NetBSD, OpenBSD, Solaris
707 AC_CHECK_FUNC(getaddrinfo,,
710 # Not found in the standard system libraries.
712 # In some versions of Solaris, we need to link with libsocket
713 # and libnsl, so check in libsocket and also link with libnsl
714 # when doing this test.
716 # These are: illumos, Solaris 9.x, 10.x, 11.x before 11.4.
718 # Linking with libsocket and libnsl will find all the routines
721 AC_CHECK_LIB(socket, getaddrinfo,
724 # OK, we found it in libsocket.
726 LIBS="-lsocket -lnsl $LIBS"
730 # Not found in libsocket; test for it in libnetwork, which
731 # is where it is in Haiku.
733 # Linking with libnetwork will find all the routines we
736 AC_CHECK_LIB(network, getaddrinfo,
739 # OK, we found it in libnetwork.
741 LIBS="-lnetwork $LIBS"
747 AC_MSG_ERROR([getaddrinfo is required, but wasn't found])
752 # We require a version of recvmsg() that conforms to the Single
753 # UNIX Specification, so that we can check whether a datagram
754 # received with recvmsg() was truncated when received due to the
755 # buffer being too small.
757 # On most systems, the version of recvmsg() in the libraries
758 # found above conforms to the SUS.
760 # On at least some versions of Solaris, it does not conform to
761 # the SUS, and we need the version in libxnet, which does
764 # Check whether libxnet exists and has a version of recvmsg();
765 # if it does, link with libxnet before we link with libsocket,
766 # to get that version.
768 # This test also links with libsocket and libnsl.
770 AC_CHECK_LIB(xnet, recvmsg,
773 # libxnet has recvmsg(); link with it as well.
780 m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
781 dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
782 dnl serial 11 (pkg-config-0.29)
784 dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
785 dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
787 dnl This program is free software; you can redistribute it and/or modify
788 dnl it under the terms of the GNU General Public License as published by
789 dnl the Free Software Foundation; either version 2 of the License, or
790 dnl (at your option) any later version.
792 dnl This program is distributed in the hope that it will be useful, but
793 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
794 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
795 dnl General Public License for more details.
797 dnl You should have received a copy of the GNU General Public License
798 dnl along with this program; if not, write to the Free Software
799 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
802 dnl As a special exception to the GNU General Public License, if you
803 dnl distribute this file as part of a program that contains a
804 dnl configuration script generated by Autoconf, you may include it under
805 dnl the same distribution terms that you use for the rest of that
808 dnl PKG_PREREQ(MIN-VERSION)
809 dnl -----------------------
812 dnl Verify that the version of the pkg-config macros are at least
813 dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
814 dnl installed version of pkg-config, this checks the developer's version
815 dnl of pkg.m4 when generating configure.
817 dnl To ensure that this macro is defined, also add:
818 dnl m4_ifndef([PKG_PREREQ],
819 dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
821 dnl See the "Since" comment for each macro you use to see what version
822 dnl of the macros you require.
823 m4_defun([PKG_PREREQ],
824 [m4_define([PKG_MACROS_VERSION], [0.29])
825 m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
826 [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
829 dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
830 dnl ----------------------------------
833 dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
834 dnl first found in the path. Checks that the version of pkg-config found
835 dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.17.0 is
836 dnl used since that's the first version where --static was supported.
837 AC_DEFUN([PKG_PROG_PKG_CONFIG],
838 [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
839 m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
840 m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
841 AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
842 AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
843 AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
845 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
846 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
848 if test -n "$PKG_CONFIG"; then
849 _pkg_min_version=m4_default([$1], [0.17.0])
850 AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
851 if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
858 ])dnl PKG_PROG_PKG_CONFIG
860 dnl PKG_CHECK_EXISTS(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
861 dnl -------------------------------------------------------------------
864 dnl Check to see whether a particular module exists. Similar to
865 dnl PKG_CHECK_MODULE(), but does not set variables or print errors.
866 AC_DEFUN([PKG_CHECK_EXISTS],
868 if test -n "$PKG_CONFIG" && \
869 AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
870 m4_default([$2], [:])
871 m4_ifvaln([$3], [else
875 dnl _PKG_CONFIG_WITH_FLAGS([VARIABLE], [FLAGS], [MODULE])
876 dnl ---------------------------------------------
877 dnl Internal wrapper calling pkg-config via PKG_CONFIG and, if
878 dnl pkg-config fails, reporting the error and quitting.
879 m4_define([_PKG_CONFIG_WITH_FLAGS],
880 [if test ! -n "$$1"; then
881 $1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
882 if test "x$?" != "x0"; then
884 # That failed - report an error.
885 # Re-run the command, telling pkg-config to print an error
886 # message, capture the error message, and report it.
887 # This causes the configuration script to fail, as it means
888 # the script is almost certainly doing something wrong.
890 _PKG_SHORT_ERRORS_SUPPORTED
891 if test $_pkg_short_errors_supported = yes; then
892 _pkg_error_string=`$PKG_CONFIG --short-errors --print-errors $2 "$3" 2>&1`
894 _pkg_error_string=`$PKG_CONFIG --print-errors $2 "$3" 2>&1`
896 AC_MSG_ERROR([$PKG_CONFIG $2 "$3" failed: $_pkg_error_string])
899 ])dnl _PKG_CONFIG_WITH_FLAGS
902 dnl _PKG_CONFIG([VARIABLE], [FLAGS], [MODULE])
903 dnl ---------------------------------------------
904 dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
905 dnl pkg_failed based on the result.
906 m4_define([_PKG_CONFIG],
907 [if test -n "$$1"; then
909 elif test -n "$PKG_CONFIG"; then
910 PKG_CHECK_EXISTS([$3],
911 [pkg_cv_[]$1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
912 test "x$?" != "x0" && pkg_failed=yes ],
919 dnl _PKG_SHORT_ERRORS_SUPPORTED
920 dnl ---------------------------
921 dnl Internal check to see if pkg-config supports short errors.
922 AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
924 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
925 _pkg_short_errors_supported=yes
927 _pkg_short_errors_supported=no
929 ])dnl _PKG_SHORT_ERRORS_SUPPORTED
932 dnl PKG_CHECK_MODULE(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
933 dnl [ACTION-IF-NOT-FOUND])
934 dnl --------------------------------------------------------------
936 AC_DEFUN([PKG_CHECK_MODULE],
938 AC_MSG_CHECKING([for $2 with pkg-config])
939 if test -n "$PKG_CONFIG"; then
940 AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $2, overriding pkg-config])dnl
941 AC_ARG_VAR([$1][_LIBS], [linker flags for $2, overriding pkg-config])dnl
942 AC_ARG_VAR([$1][_LIBS_STATIC], [static-link linker flags for $2, overriding pkg-config])dnl
944 if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
946 # The package was found, so try to get its C flags and
949 AC_MSG_RESULT([found])
950 _PKG_CONFIG_WITH_FLAGS([$1][_CFLAGS], [--cflags], [$2])
951 _PKG_CONFIG_WITH_FLAGS([$1][_LIBS], [--libs], [$2])
952 _PKG_CONFIG_WITH_FLAGS([$1][_LIBS_STATIC], [--libs --static], [$2])
953 m4_default([$3], [:])
955 AC_MSG_RESULT([not found])
956 m4_default([$4], [:])
959 # No pkg-config, so obviously not found with pkg-config.
960 AC_MSG_RESULT([pkg-config not found])
961 m4_default([$4], [:])
963 ])dnl PKG_CHECK_MODULE
966 dnl PKG_CHECK_MODULE_STATIC(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
967 dnl [ACTION-IF-NOT-FOUND])
968 dnl ---------------------------------------------------------------------
971 dnl Checks for existence of MODULE and gathers its build flags with
972 dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
973 dnl and VARIABLE-PREFIX_LIBS from --libs.
974 AC_DEFUN([PKG_CHECK_MODULE_STATIC],
976 _save_PKG_CONFIG=$PKG_CONFIG
977 PKG_CONFIG="$PKG_CONFIG --static"
979 PKG_CONFIG=$_save_PKG_CONFIG[]dnl
980 ])dnl PKG_CHECK_MODULE_STATIC
983 dnl PKG_INSTALLDIR([DIRECTORY])
984 dnl -------------------------
987 dnl Substitutes the variable pkgconfigdir as the location where a module
988 dnl should install pkg-config .pc files. By default the directory is
989 dnl $libdir/pkgconfig, but the default can be changed by passing
990 dnl DIRECTORY. The user can override through the --with-pkgconfigdir
992 AC_DEFUN([PKG_INSTALLDIR],
993 [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
994 m4_pushdef([pkg_description],
995 [pkg-config installation directory @<:@]pkg_default[@:>@])
996 AC_ARG_WITH([pkgconfigdir],
997 [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
998 [with_pkgconfigdir=]pkg_default)
999 AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
1000 m4_popdef([pkg_default])
1001 m4_popdef([pkg_description])
1002 ])dnl PKG_INSTALLDIR
1005 dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
1006 dnl --------------------------------
1009 dnl Substitutes the variable noarch_pkgconfigdir as the location where a
1010 dnl module should install arch-independent pkg-config .pc files. By
1011 dnl default the directory is $datadir/pkgconfig, but the default can be
1012 dnl changed by passing DIRECTORY. The user can override through the
1013 dnl --with-noarch-pkgconfigdir parameter.
1014 AC_DEFUN([PKG_NOARCH_INSTALLDIR],
1015 [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
1016 m4_pushdef([pkg_description],
1017 [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
1018 AC_ARG_WITH([noarch-pkgconfigdir],
1019 [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
1020 [with_noarch_pkgconfigdir=]pkg_default)
1021 AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
1022 m4_popdef([pkg_default])
1023 m4_popdef([pkg_description])
1024 ])dnl PKG_NOARCH_INSTALLDIR
1027 dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
1028 dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1029 dnl -------------------------------------------
1032 dnl Retrieves the value of the pkg-config variable for the given module.
1033 AC_DEFUN([PKG_CHECK_VAR],
1035 AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
1037 _PKG_CONFIG([$1], [--variable="][$3]["], [$2])
1038 AS_VAR_COPY([$1], [pkg_cv_][$1])
1040 AS_VAR_IF([$1], [""], [$5], [$4])dnl