pkg.m4 revision 423:e1830598f0b7
1139823Simp# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
275374Sbp# 
375374Sbp# Copyright �� 2004 Scott James Remnant <scott@netsplit.com>.
475374Sbp#
575374Sbp# This program is free software; you can redistribute it and/or modify
675374Sbp# it under the terms of the GNU General Public License as published by
775374Sbp# the Free Software Foundation; either version 2 of the License, or
875374Sbp# (at your option) any later version.
975374Sbp#
1075374Sbp# This program is distributed in the hope that it will be useful, but
1175374Sbp# WITHOUT ANY WARRANTY; without even the implied warranty of
1275374Sbp# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1375374Sbp# General Public License for more details.
1475374Sbp#
1575374Sbp# You should have received a copy of the GNU General Public License
1675374Sbp# along with this program; if not, write to the Free Software
1775374Sbp# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1875374Sbp#
1975374Sbp# As a special exception to the GNU General Public License, if you
2075374Sbp# distribute this file as part of a program that contains a
2175374Sbp# configuration script generated by Autoconf, you may include it under
2275374Sbp# the same distribution terms that you use for the rest of that program.
2375374Sbp
2475374Sbp# PKG_PROG_PKG_CONFIG([MIN-VERSION])
2575374Sbp# ----------------------------------
26116189SobrienAC_DEFUN([PKG_PROG_PKG_CONFIG],
27116189Sobrien[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
28116189Sobrienm4_pattern_allow([^PKG_CONFIG(_PATH)?$])
2975374SbpAC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl
3075374Sbpif test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
3175374Sbp	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
3295533Smikefi
3375374Sbpif test -n "$PKG_CONFIG"; then
3475374Sbp	_pkg_min_version=m4_default([$1], [0.9.0])
3575374Sbp	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
3675374Sbp	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
3775374Sbp		AC_MSG_RESULT([yes])
3875374Sbp	else
3975374Sbp		AC_MSG_RESULT([no])
4075374Sbp		PKG_CONFIG=""
4175374Sbp	fi
4275374Sbp		
4375374Sbpfi[]dnl
4475374Sbp])# PKG_PROG_PKG_CONFIG
4575374Sbp
4675374Sbp# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
4775374Sbp#
4875374Sbp# Check to see whether a particular set of modules exists.  Similar
4975374Sbp# to PKG_CHECK_MODULES(), but does not set variables or print errors.
5075374Sbp#
5175374Sbp#
5275374Sbp# Similar to PKG_CHECK_MODULES, make sure that the first instance of
5375374Sbp# this or PKG_CHECK_MODULES is called, or make sure to call
5475374Sbp# PKG_CHECK_EXISTS manually
5575374Sbp# --------------------------------------------------------------
5675374SbpAC_DEFUN([PKG_CHECK_EXISTS],
5775374Sbp[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
5875374Sbpif test -n "$PKG_CONFIG" && \
5975374Sbp    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
6075374Sbp  m4_ifval([$2], [$2], [:])
6175374Sbpm4_ifvaln([$3], [else
6275374Sbp  $3])dnl
6375374Sbpfi])
6475374Sbp
6575374Sbp
6675374Sbp# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
6775374Sbp# ---------------------------------------------
6875374Sbpm4_define([_PKG_CONFIG],
6975374Sbp[if test -n "$$1"; then
7075374Sbp    pkg_cv_[]$1="$$1"
7175374Sbp elif test -n "$PKG_CONFIG"; then
7275374Sbp    PKG_CHECK_EXISTS([$3],
7375374Sbp                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
7475374Sbp		     [pkg_failed=yes])
7575374Sbp else
7675374Sbp    pkg_failed=untried
7775374Sbpfi[]dnl
7875374Sbp])# _PKG_CONFIG
7975374Sbp
8075374Sbp# _PKG_SHORT_ERRORS_SUPPORTED
8175374Sbp# -----------------------------
8275374SbpAC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
8375374Sbp[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
8475374Sbpif $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
8575374Sbp        _pkg_short_errors_supported=yes
8682045Sbpelse
8775374Sbp        _pkg_short_errors_supported=no
8875374Sbpfi[]dnl
8975374Sbp])# _PKG_SHORT_ERRORS_SUPPORTED
9075374Sbp
9175374Sbp
9275374Sbp# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
9375374Sbp# [ACTION-IF-NOT-FOUND])
9475374Sbp#
9575374Sbp#
9675374Sbp# Note that if there is a possibility the first call to
9775374Sbp# PKG_CHECK_MODULES might not happen, you should be sure to include an
9875374Sbp# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
9975374Sbp#
10087192Sbp#
10175374Sbp# --------------------------------------------------------------
10275374SbpAC_DEFUN([PKG_CHECK_MODULES],
10375374Sbp[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
10487192SbpAC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
10587192SbpAC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
10675374Sbp
10775374Sbppkg_failed=no
10875374SbpAC_MSG_CHECKING([for $1])
10975374Sbp
11075374Sbp_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
11175374Sbp_PKG_CONFIG([$1][_LIBS], [libs], [$2])
11275374Sbp
11375374Sbpm4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
11475374Sbpand $1[]_LIBS to avoid the need to call pkg-config.
11575374SbpSee the pkg-config man page for more details.])
11675374Sbp
11775374Sbpif test $pkg_failed = yes; then
11875374Sbp        _PKG_SHORT_ERRORS_SUPPORTED
11975374Sbp        if test $_pkg_short_errors_supported = yes; then
12075374Sbp	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
12187192Sbp        else 
12275374Sbp	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
12375374Sbp        fi
12475374Sbp	# Put the nasty error message in config.log where it belongs
12575374Sbp	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
12675374Sbp
12775374Sbp	ifelse([$4], , [AC_MSG_ERROR(dnl
12875374Sbp[Package requirements ($2) were not met:
12975374Sbp
13075374Sbp$$1_PKG_ERRORS
13175374Sbp
13275374SbpConsider adjusting the PKG_CONFIG_PATH environment variable if you
13375374Sbpinstalled software in a non-standard prefix.
13475374Sbp
13575374Sbp_PKG_TEXT
136119376Smarcel])],
137119376Smarcel		[AC_MSG_RESULT([no])
138119376Smarcel                $4])
139119376Smarcelelif test $pkg_failed = untried; then
140119376Smarcel	ifelse([$4], , [AC_MSG_FAILURE(dnl
141119376Smarcel[The pkg-config script could not be found or is too old.  Make sure it
142119376Smarcelis in your PATH or set the PKG_CONFIG environment variable to the full
143119376Smarcelpath to pkg-config.
144119376Smarcel
145119376Smarcel_PKG_TEXT
146119376Smarcel
147119376SmarcelTo get pkg-config, see <http://pkg-config.freedesktop.org/>.])],
148119376Smarcel		[$4])
149119376Smarcelelse
150119376Smarcel	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
151119376Smarcel	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
152119376Smarcel        AC_MSG_RESULT([yes])
153119376Smarcel	ifelse([$3], , :, [$3])
154119376Smarcelfi[]dnl
155119376Smarcel])# PKG_CHECK_MODULES
156119376Smarcel