pkg.m4 revision 2b490bc947dbe0094417304840bd721417a162d9
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht#
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht#
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu# This program is free software; you can redistribute it and/or modify
2643008447e30b6025f742eb6a661f38be756b1eSimon Ulbricht# it under the terms of the GNU General Public License as published by
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht# the Free Software Foundation; either version 3 of the License, or
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht# (at your option) any later version.
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht#
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht# This program is distributed in the hope that it will be useful, but
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht# WITHOUT ANY WARRANTY; without even the implied warranty of
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht# General Public License for more details.
2643008447e30b6025f742eb6a661f38be756b1eSimon Ulbricht#
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder# You should have received a copy of the GNU General Public License
2643008447e30b6025f742eb6a661f38be756b1eSimon Ulbricht# along with this program; if not, see <http://www.gnu.org/licenses/>.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht#
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht# As a special exception to the GNU General Public License, if you
d815d2b83e945875100ceca322ebd50d96714206Simon Ulbricht# distribute this file as part of a program that contains a
b0adcc203b4267d5535b430372935a5f36726db1Simon Ulbricht# configuration script generated by Autoconf, you may include it under
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht# the same distribution terms that you use for the rest of that program.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht# PKG_PROG_PKG_CONFIG([MIN-VERSION])
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht# ----------------------------------
d815d2b83e945875100ceca322ebd50d96714206Simon UlbrichtAC_DEFUN([PKG_PROG_PKG_CONFIG],
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
6150196e8d99f7161a622fdc1a872fecd378195fSimon Ulbrichtm4_pattern_allow([^PKG_CONFIG(_PATH)?$])
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtAC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maederif test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
3209c34f23fb83a86fbbdd6501db6d4bfb949a57Simon Ulbrichtfi
2643008447e30b6025f742eb6a661f38be756b1eSimon Ulbrichtif test -n "$PKG_CONFIG"; then
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht _pkg_min_version=m4_default([$1], [0.9.0])
2643008447e30b6025f742eb6a661f38be756b1eSimon Ulbricht AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht AC_MSG_RESULT([yes])
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht else
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder AC_MSG_RESULT([no])
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder PKG_CONFIG=""
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder fi
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maederfi[]dnl
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder])# PKG_PROG_PKG_CONFIG
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder#
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht# Check to see whether a particular set of modules exists. Similar
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder# to PKG_CHECK_MODULES(), but does not set variables or print errors.
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder#
9da6e0cb2ea6e43f5b09dcd2a9af5468a5d0fcf4Christian Maeder#
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht# Similar to PKG_CHECK_MODULES, make sure that the first instance of
6150196e8d99f7161a622fdc1a872fecd378195fSimon Ulbricht# this or PKG_CHECK_MODULES is called, or make sure to call
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht# PKG_CHECK_EXISTS manually
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht# --------------------------------------------------------------
65660c22133e6de16f9ece7b36ac6423014b20aaChristian MaederAC_DEFUN([PKG_CHECK_EXISTS],
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maederif test -n "$PKG_CONFIG" && \
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht m4_ifval([$2], [$2], [:])
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtm4_ifvaln([$3], [else
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht $3])dnl
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtfi])
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht# ---------------------------------------------
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtm4_define([_PKG_CONFIG],
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht[if test -n "$PKG_CONFIG"; then
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht if test -n "$$1"; then
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht pkg_cv_[]$1="$$1"
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht else
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder PKG_CHECK_EXISTS([$3],
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
d8623e217fff016f9e1759b5603fc06b29fda62cChristian Maeder [pkg_failed=yes])
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht fi
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maederelse
d8623e217fff016f9e1759b5603fc06b29fda62cChristian Maeder pkg_failed=untried
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtfi[]dnl
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder])# _PKG_CONFIG
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht# _PKG_SHORT_ERRORS_SUPPORTED
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht# -----------------------------
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon UlbrichtAC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtif $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder _pkg_short_errors_supported=yes
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtelse
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder _pkg_short_errors_supported=no
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maederfi[]dnl
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht])# _PKG_SHORT_ERRORS_SUPPORTED
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht# [ACTION-IF-NOT-FOUND])
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht#
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht#
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht# Note that if there is a possibility the first call to
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht# PKG_CHECK_MODULES might not happen, you should be sure to include an
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht#
432ac7c08e2592af0660e026051ffb052e88a100Simon Ulbricht#
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht# --------------------------------------------------------------
65660c22133e6de16f9ece7b36ac6423014b20aaChristian MaederAC_DEFUN([PKG_CHECK_MODULES],
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
a210c2e5add831cd438183c8602ed8e610922beaSimon UlbrichtAC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
a210c2e5add831cd438183c8602ed8e610922beaSimon UlbrichtAC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtpkg_failed=no
65660c22133e6de16f9ece7b36ac6423014b20aaChristian MaederAC_MSG_CHECKING([for $1])
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht_PKG_CONFIG([$1][_LIBS], [libs], [$2])
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbricht
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtm4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
e9a1a4d5820d527a6800d524ebaf29fbad6196c6Simon Ulbrichtand $1[]_LIBS to avoid the need to call pkg-config.
65660c22133e6de16f9ece7b36ac6423014b20aaChristian MaederSee the pkg-config man page for more details.])
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maederif test $pkg_failed = yes; then
6a26171b5bc5b6ec3e1b02ae30dcfb6f03d7ffefSimon Ulbricht _PKG_SHORT_ERRORS_SUPPORTED
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht if test $_pkg_short_errors_supported = yes; then
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"`
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht else
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht fi
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht # Put the nasty error message in config.log where it belongs
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht ifelse([$4], , [AC_MSG_ERROR(dnl
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht[Package requirements ($2) were not met:
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht$$1_PKG_ERRORS
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht
abea93ed557b22ea833e1524ee5ca11afc12208aSimon UlbrichtConsider adjusting the PKG_CONFIG_PATH environment variable if you
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbrichtinstalled software in a non-standard prefix.
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht_PKG_TEXT
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht])],
abea93ed557b22ea833e1524ee5ca11afc12208aSimon Ulbricht [AC_MSG_RESULT([no])
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder $4])
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maederelif test $pkg_failed = untried; then
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder ifelse([$4], , [AC_MSG_FAILURE(dnl
65660c22133e6de16f9ece7b36ac6423014b20aaChristian Maeder[The pkg-config script could not be found or is too old. Make sure it
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbrichtis in your PATH or set the PKG_CONFIG environment variable to the full
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbrichtpath to pkg-config.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht_PKG_TEXT
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon UlbrichtTo get pkg-config, see <http://www.freedesktop.org/software/pkgconfig>.])],
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht [$4])
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbrichtelse
a210c2e5add831cd438183c8602ed8e610922beaSimon Ulbricht $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht AC_MSG_RESULT([yes])
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht ifelse([$3], , :, [$3])
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtfi[]dnl
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht])# PKG_CHECK_MODULES
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht