1# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- 2# serial 1 (pkg-config-0.24) 3# 4# Copyright © 2004 Scott James Remnant <scott@netsplit.com>. 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, but 12# WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14# General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write to the Free Software 18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19# 20# As a special exception to the GNU General Public License, if you 21# distribute this file as part of a program that contains a 22# configuration script generated by Autoconf, you may include it under 23# the same distribution terms that you use for the rest of that program. 24 25# PKG_PROG_PKG_CONFIG([MIN-VERSION]) 26# ---------------------------------- 27AC_DEFUN([PKG_PROG_PKG_CONFIG], 28[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) 29m4_pattern_allow([^PKG_CONFIG(_PATH)?$]) 30AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) 31AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) 32AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) 33 34if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then 35 AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) 36fi 37if test -n "$PKG_CONFIG"; then 38 _pkg_min_version=m4_default([$1], [0.9.0]) 39 AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) 40 if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then 41 AC_MSG_RESULT([yes]) 42 else 43 AC_MSG_RESULT([no]) 44 PKG_CONFIG="" 45 fi 46fi[]dnl 47])# PKG_PROG_PKG_CONFIG 48 49# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 50# 51# Check to see whether a particular set of modules exists. Similar 52# to PKG_CHECK_MODULES(), but does not set variables or print errors. 53# 54# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) 55# only at the first occurence in configure.ac, so if the first place 56# it's called might be skipped (such as if it is within an "if", you 57# have to call PKG_CHECK_EXISTS manually 58# -------------------------------------------------------------- 59AC_DEFUN([PKG_CHECK_EXISTS], 60[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 61if test -n "$PKG_CONFIG" && \ 62 AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then 63 m4_default([$2], [:]) 64m4_ifvaln([$3], [else 65 $3])dnl 66fi]) 67 68# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) 69# --------------------------------------------- 70m4_define([_PKG_CONFIG], 71[if test -n "$$1"; then 72 pkg_cv_[]$1="$$1" 73 elif test -n "$PKG_CONFIG"; then 74 PKG_CHECK_EXISTS([$3], 75 [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`], 76 [pkg_failed=yes]) 77 else 78 pkg_failed=untried 79fi[]dnl 80])# _PKG_CONFIG 81 82# _PKG_SHORT_ERRORS_SUPPORTED 83# ----------------------------- 84AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], 85[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) 86if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then 87 _pkg_short_errors_supported=yes 88else 89 _pkg_short_errors_supported=no 90fi[]dnl 91])# _PKG_SHORT_ERRORS_SUPPORTED 92 93 94# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], 95# [ACTION-IF-NOT-FOUND]) 96# 97# 98# Note that if there is a possibility the first call to 99# PKG_CHECK_MODULES might not happen, you should be sure to include an 100# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac 101# 102# 103# -------------------------------------------------------------- 104AC_DEFUN([PKG_CHECK_MODULES], 105[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 106AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl 107AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl 108 109pkg_failed=no 110AC_MSG_CHECKING([for $1]) 111 112_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) 113_PKG_CONFIG([$1][_LIBS], [libs], [$2]) 114 115m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS 116and $1[]_LIBS to avoid the need to call pkg-config. 117See the pkg-config man page for more details.]) 118 119if test $pkg_failed = yes; then 120 AC_MSG_RESULT([no]) 121 _PKG_SHORT_ERRORS_SUPPORTED 122 if test $_pkg_short_errors_supported = yes; then 123 $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1` 124 else 125 $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1` 126 fi 127 # Put the nasty error message in config.log where it belongs 128 echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD 129 130 m4_default([$4], [AC_MSG_ERROR( 131[Package requirements ($2) were not met: 132 133$$1_PKG_ERRORS 134 135Consider adjusting the PKG_CONFIG_PATH environment variable if you 136installed software in a non-standard prefix. 137 138_PKG_TEXT]) 139 ]) 140elif test $pkg_failed = untried; then 141 AC_MSG_RESULT([no]) 142 m4_default([$4], [AC_MSG_FAILURE( 143[The pkg-config script could not be found or is too old. Make sure it 144is in your PATH or set the PKG_CONFIG environment variable to the full 145path to pkg-config. 146 147_PKG_TEXT 148 149To get pkg-config, see <https://pkg-config.freedesktop.org/>.]) 150 ]) 151else 152 $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS 153 $1[]_LIBS=$pkg_cv_[]$1[]_LIBS 154 AC_MSG_RESULT([yes]) 155 $3 156fi[]dnl 157])# PKG_CHECK_MODULES 158