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