]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/openpam/m4/ax_pkg_config.m4
Merge bmake-20200517
[FreeBSD/FreeBSD.git] / contrib / openpam / m4 / ax_pkg_config.m4
1 dnl -*- autoconf -*-
2 dnl
3 dnl Copyright (c) 2017 The University of Oslo
4 dnl All rights reserved.
5 dnl
6 dnl Redistribution and use in source and binary forms, with or without
7 dnl modification, are permitted provided that the following conditions
8 dnl are met:
9 dnl 1. Redistributions of source code must retain the above copyright
10 dnl    notice, this list of conditions and the following disclaimer.
11 dnl 2. Redistributions in binary form must reproduce the above copyright
12 dnl    notice, this list of conditions and the following disclaimer in the
13 dnl    documentation and/or other materials provided with the distribution.
14 dnl 3. The name of the author may not be used to endorse or promote
15 dnl    products derived from this software without specific prior written
16 dnl    permission.
17 dnl
18 dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 dnl ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 dnl ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 dnl OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 dnl LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 dnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 dnl SUCH DAMAGE.
29 dnl
30
31 m4_define([AX_PKG_CONFIG_MACROS_VERSION], [0.20170404])
32
33 dnl
34 dnl AX_PROG_PKG_CONFIG([min-version])
35 dnl ---------------------------------
36 dnl
37 dnl Verify that pkgconf or pkg-config are present.
38 dnl
39 AC_DEFUN([AX_PROG_PKG_CONFIG], [
40     m4_pattern_forbid([^AX_PKG_CONFIG_[A-Z_]+$])
41     AC_ARG_VAR([PKG_CONFIG], [path to pkg-config binary])
42     AC_ARG_VAR([PKG_CONFIG_PATH], [list of directories to prepend to default search path])
43     AC_ARG_VAR([PKG_CONFIG_LIBDIR], [list of directories to search instead of default search path])
44     if test x"${PKG_CONFIG}" = x"" ; then
45         AC_PATH_PROGS([PKG_CONFIG], [pkgconf pkg-config]) >/dev/null
46     else
47         AC_PATH_PROG([PKG_CONFIG], [${PKG_CONFIG}])
48     fi
49     AC_MSG_CHECKING([for pkg-config or pkgconf])
50     if test -x "${PKG_CONFIG}" ; then
51         AC_MSG_RESULT([${PKG_CONFIG}])
52         case "${PKG_CONFIG}" in
53         *pkgconf)
54             _min_version="m4_default([$1], [1.3.0])"
55             ;;
56         *pkg-config)
57             _min_version="m4_default([$1], [0.23])"
58             ;;
59         *)
60             _min_version="9.9.error"
61             ;;
62         esac
63         AC_MSG_CHECKING([that ${PKG_CONFIG} is at least version ${_min_version}])
64         _act_version=`"${PKG_CONFIG}" --version`
65         if ! "${PKG_CONFIG}" --atleast-pkgconfig-version="${_min_version}" ; then
66             PKG_CONFIG=""
67         fi
68         AC_MSG_RESULT([${_act_version}])
69     else
70         AC_MSG_RESULT([no])
71         PKG_CONFIG=""
72     fi
73     if test x"${PKG_CONFIG}" = x"" ; then
74         AC_MSG_ERROR([pkg-config was not found or is too old])
75     fi
76     AC_ARG_WITH([pkgconfigdir],
77         AS_HELP_STRING([--with-pkgconfigdir],
78             [installation directory for .pc files @<:@LIBDIR/pkgconfig@:>@]),
79         [pkgconfigdir=$withval], [pkgconfigdir='${libdir}/pkgconfig'])
80     AC_SUBST([pkgconfigdir], [$pkgconfigdir])
81 ])
82
83 dnl
84 dnl AX_PKG_CONFIG_VAR(package-name, var-name)
85 dnl -----------------------------------------
86 dnl
87 dnl Retrieve specific pkg-config variables for the specified package.
88 dnl
89 AC_DEFUN([AX_PKG_CONFIG_VAR], [
90     AC_REQUIRE([AX_PROG_PKG_CONFIG])
91     m4_define([_p], AS_TR_SH([m4_tolower([$1])]))
92     m4_case([$2],
93         [version], [ax_pc_cv_[]_p[]_version=`"${PKG_CONFIG}" --modversion [$1]`],
94         [cflags], [ax_pc_cv_[]_p[]_cflags=`"${PKG_CONFIG}" --cflags [$1]`],
95         [libs], [ax_pc_cv_[]_p[]_libs=`"${PKG_CONFIG}" --libs [$1]`],
96         [ax_pc_cv_[]_p[]_[$2]=`"${PKG_CONFIG}" --variable=[$2] [$1]`])
97 ])
98
99 dnl
100 dnl AX_PKG_CONFIG_CHECK(package-name,
101 dnl     [action-if-found], [action-if-not-found])
102 dnl -------------------------------------------
103 dnl
104 dnl Check if the specified package is installed.  If it is, define
105 dnl HAVE_PACKAGE, PACKAGE_VERSION, PACKAGE_CFLAGS and PACKAGE_LIBS.
106 dnl The specified actions are performed in addition to the standard
107 dnl actions.
108 dnl
109 AC_DEFUN([AX_PKG_CONFIG_CHECK], [
110     AC_REQUIRE([AX_PROG_PKG_CONFIG])
111     m4_define([_P], AS_TR_SH([m4_toupper([$1])]))
112     m4_define([_p], AS_TR_SH([m4_tolower([$1])]))
113     AC_ARG_VAR(_P[_CFLAGS], [C compiler flags for $1])
114     AC_ARG_VAR(_P[_LIBS], [linker flags for $1])
115     AC_MSG_CHECKING([if $1 is installed])
116     if AC_RUN_LOG(["${PKG_CONFIG}" --exists --print-errors "$1"]) ; then
117         AC_MSG_RESULT([yes])
118         [ax_pc_cv_have_]_p=yes
119         AC_DEFINE([HAVE_]_P, [1], [Define to 1 if you have $1])
120 dnl
121         AC_MSG_CHECKING([$1 version])
122         AX_PKG_CONFIG_VAR([$1], [version])
123         AC_SUBST(_P[_VERSION], [$ax_pc_cv_]_p[_version])
124         AC_MSG_RESULT([${ax_pc_cv_]_p[_version:-unknown}])
125 dnl
126         AC_MSG_CHECKING([$1 compiler flags])
127         AX_PKG_CONFIG_VAR([$1], [cflags])
128         AC_SUBST(_P[_CFLAGS], [$ax_pc_cv_]_p[_cflags])
129         AC_MSG_RESULT([${ax_pc_cv_]_p[_cflags:-none}])
130 dnl
131         AC_MSG_CHECKING([$1 linker flags])
132         AX_PKG_CONFIG_VAR([$1], [libs])
133         AC_SUBST(_P[_LIBS], [$ax_pc_cv_]_p[_libs])
134         AC_MSG_RESULT([${ax_pc_cv_]_p[_libs:-none}])
135 dnl
136         m4_default([$2], [:])
137     else
138         AC_MSG_RESULT([no])
139         [ax_pc_cv_have_]_p=no
140         m4_default([$3], [:])
141     fi
142     m4_ifdef([AM_CONDITIONAL], [
143         AM_CONDITIONAL([HAVE_]_P, [test x"$ax_pc_cv_have_]_p[" = x"yes"])
144     ])
145 ])
146
147 dnl
148 dnl AX_PKG_CONFIG_REQUIRE(package-name)
149 dnl -----------------------------------
150 dnl
151 dnl As above, but fail if the package is not installed.
152 dnl
153 AC_DEFUN([AX_PKG_CONFIG_REQUIRE], [
154     AX_PKG_CONFIG_CHECK([$1], [], [
155         AC_MSG_ERROR([cannot proceed without $1])
156     ])
157 ])