1953daebaSmrg# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
2953daebaSmrg# serial 1 (pkg-config-0.24)
3953daebaSmrg# 
4953daebaSmrg# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
5953daebaSmrg#
6953daebaSmrg# This program is free software; you can redistribute it and/or modify
7953daebaSmrg# it under the terms of the GNU General Public License as published by
8953daebaSmrg# the Free Software Foundation; either version 2 of the License, or
9953daebaSmrg# (at your option) any later version.
10953daebaSmrg#
11953daebaSmrg# This program is distributed in the hope that it will be useful, but
12953daebaSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
13953daebaSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14953daebaSmrg# General Public License for more details.
15953daebaSmrg#
16953daebaSmrg# You should have received a copy of the GNU General Public License
17953daebaSmrg# along with this program; if not, write to the Free Software
18953daebaSmrg# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19953daebaSmrg#
20953daebaSmrg# As a special exception to the GNU General Public License, if you
21953daebaSmrg# distribute this file as part of a program that contains a
22953daebaSmrg# configuration script generated by Autoconf, you may include it under
23953daebaSmrg# the same distribution terms that you use for the rest of that program.
24953daebaSmrg
25953daebaSmrg# PKG_PROG_PKG_CONFIG([MIN-VERSION])
26953daebaSmrg# ----------------------------------
27953daebaSmrgAC_DEFUN([PKG_PROG_PKG_CONFIG],
28953daebaSmrg[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
29953daebaSmrgm4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
30953daebaSmrgm4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
31953daebaSmrgAC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
32953daebaSmrgAC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
33953daebaSmrgAC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
34953daebaSmrg
35953daebaSmrgif test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
36953daebaSmrg	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
37953daebaSmrgfi
38953daebaSmrgif test -n "$PKG_CONFIG"; then
39953daebaSmrg	_pkg_min_version=m4_default([$1], [0.9.0])
40953daebaSmrg	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
41953daebaSmrg	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
42953daebaSmrg		AC_MSG_RESULT([yes])
43953daebaSmrg	else
44953daebaSmrg		AC_MSG_RESULT([no])
45953daebaSmrg		PKG_CONFIG=""
46953daebaSmrg	fi
47953daebaSmrgfi[]dnl
48953daebaSmrg])# PKG_PROG_PKG_CONFIG
49953daebaSmrg
50953daebaSmrg# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
51953daebaSmrg#
52953daebaSmrg# Check to see whether a particular set of modules exists.  Similar
53953daebaSmrg# to PKG_CHECK_MODULES(), but does not set variables or print errors.
54953daebaSmrg#
55953daebaSmrg# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
56953daebaSmrg# only at the first occurence in configure.ac, so if the first place
57953daebaSmrg# it's called might be skipped (such as if it is within an "if", you
58953daebaSmrg# have to call PKG_CHECK_EXISTS manually
59953daebaSmrg# --------------------------------------------------------------
60953daebaSmrgAC_DEFUN([PKG_CHECK_EXISTS],
61953daebaSmrg[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
62953daebaSmrgif test -n "$PKG_CONFIG" && \
63953daebaSmrg    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
64953daebaSmrg  m4_default([$2], [:])
65953daebaSmrgm4_ifvaln([$3], [else
66953daebaSmrg  $3])dnl
67953daebaSmrgfi])
68953daebaSmrg
69953daebaSmrg# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
70953daebaSmrg# ---------------------------------------------
71953daebaSmrgm4_define([_PKG_CONFIG],
72953daebaSmrg[if test -n "$$1"; then
73953daebaSmrg    pkg_cv_[]$1="$$1"
74953daebaSmrg elif test -n "$PKG_CONFIG"; then
75953daebaSmrg    PKG_CHECK_EXISTS([$3],
76953daebaSmrg                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
77953daebaSmrg		      test "x$?" != "x0" && pkg_failed=yes ],
78953daebaSmrg		     [pkg_failed=yes])
79953daebaSmrg else
80953daebaSmrg    pkg_failed=untried
81953daebaSmrgfi[]dnl
82953daebaSmrg])# _PKG_CONFIG
83953daebaSmrg
84953daebaSmrg# _PKG_SHORT_ERRORS_SUPPORTED
85953daebaSmrg# -----------------------------
86953daebaSmrgAC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
87953daebaSmrg[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
88953daebaSmrgif $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
89953daebaSmrg        _pkg_short_errors_supported=yes
90953daebaSmrgelse
91953daebaSmrg        _pkg_short_errors_supported=no
92953daebaSmrgfi[]dnl
93953daebaSmrg])# _PKG_SHORT_ERRORS_SUPPORTED
94953daebaSmrg
95953daebaSmrg
96953daebaSmrg# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
97953daebaSmrg# [ACTION-IF-NOT-FOUND])
98953daebaSmrg#
99953daebaSmrg#
100953daebaSmrg# Note that if there is a possibility the first call to
101953daebaSmrg# PKG_CHECK_MODULES might not happen, you should be sure to include an
102953daebaSmrg# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
103953daebaSmrg#
104953daebaSmrg#
105953daebaSmrg# --------------------------------------------------------------
106953daebaSmrgAC_DEFUN([PKG_CHECK_MODULES],
107953daebaSmrg[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
108953daebaSmrgAC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
109953daebaSmrgAC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
110953daebaSmrg
111953daebaSmrgpkg_failed=no
112953daebaSmrgAC_MSG_CHECKING([for $1])
113953daebaSmrg
114953daebaSmrg_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
115953daebaSmrg_PKG_CONFIG([$1][_LIBS], [libs], [$2])
116953daebaSmrg
117953daebaSmrgm4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
118953daebaSmrgand $1[]_LIBS to avoid the need to call pkg-config.
119953daebaSmrgSee the pkg-config man page for more details.])
120953daebaSmrg
121953daebaSmrgif test $pkg_failed = yes; then
122953daebaSmrg   	AC_MSG_RESULT([no])
123953daebaSmrg        _PKG_SHORT_ERRORS_SUPPORTED
124953daebaSmrg        if test $_pkg_short_errors_supported = yes; then
125953daebaSmrg	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
126953daebaSmrg        else 
127953daebaSmrg	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
128953daebaSmrg        fi
129953daebaSmrg	# Put the nasty error message in config.log where it belongs
130953daebaSmrg	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
131953daebaSmrg
132953daebaSmrg	m4_default([$4], [AC_MSG_ERROR(
133953daebaSmrg[Package requirements ($2) were not met:
134953daebaSmrg
135953daebaSmrg$$1_PKG_ERRORS
136953daebaSmrg
137953daebaSmrgConsider adjusting the PKG_CONFIG_PATH environment variable if you
138953daebaSmrginstalled software in a non-standard prefix.
139953daebaSmrg
140953daebaSmrg_PKG_TEXT])[]dnl
141953daebaSmrg        ])
142953daebaSmrgelif test $pkg_failed = untried; then
143953daebaSmrg     	AC_MSG_RESULT([no])
144953daebaSmrg	m4_default([$4], [AC_MSG_FAILURE(
145953daebaSmrg[The pkg-config script could not be found or is too old.  Make sure it
146953daebaSmrgis in your PATH or set the PKG_CONFIG environment variable to the full
147953daebaSmrgpath to pkg-config.
148953daebaSmrg
149953daebaSmrg_PKG_TEXT
150953daebaSmrg
151953daebaSmrgTo get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
152953daebaSmrg        ])
153953daebaSmrgelse
154953daebaSmrg	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
155953daebaSmrg	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
156953daebaSmrg        AC_MSG_RESULT([yes])
157953daebaSmrg	$3
158953daebaSmrgfi[]dnl
159953daebaSmrg])# PKG_CHECK_MODULES
160953daebaSmrg
161953daebaSmrg
162953daebaSmrg# PKG_INSTALLDIR(DIRECTORY)
163953daebaSmrg# -------------------------
164953daebaSmrg# Substitutes the variable pkgconfigdir as the location where a module
165953daebaSmrg# should install pkg-config .pc files. By default the directory is
166953daebaSmrg# $libdir/pkgconfig, but the default can be changed by passing
167953daebaSmrg# DIRECTORY. The user can override through the --with-pkgconfigdir
168953daebaSmrg# parameter.
169953daebaSmrgAC_DEFUN([PKG_INSTALLDIR],
170953daebaSmrg[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
171953daebaSmrgm4_pushdef([pkg_description],
172953daebaSmrg    [pkg-config installation directory @<:@]pkg_default[@:>@])
173953daebaSmrgAC_ARG_WITH([pkgconfigdir],
174953daebaSmrg    [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
175953daebaSmrg    [with_pkgconfigdir=]pkg_default)
176953daebaSmrgAC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
177953daebaSmrgm4_popdef([pkg_default])
178953daebaSmrgm4_popdef([pkg_description])
179953daebaSmrg]) dnl PKG_INSTALLDIR
180953daebaSmrg
181953daebaSmrg
182953daebaSmrg# PKG_NOARCH_INSTALLDIR(DIRECTORY)
183953daebaSmrg# -------------------------
184953daebaSmrg# Substitutes the variable noarch_pkgconfigdir as the location where a
185953daebaSmrg# module should install arch-independent pkg-config .pc files. By
186953daebaSmrg# default the directory is $datadir/pkgconfig, but the default can be
187953daebaSmrg# changed by passing DIRECTORY. The user can override through the
188953daebaSmrg# --with-noarch-pkgconfigdir parameter.
189953daebaSmrgAC_DEFUN([PKG_NOARCH_INSTALLDIR],
190953daebaSmrg[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
191953daebaSmrgm4_pushdef([pkg_description],
192953daebaSmrg    [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
193953daebaSmrgAC_ARG_WITH([noarch-pkgconfigdir],
194953daebaSmrg    [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
195953daebaSmrg    [with_noarch_pkgconfigdir=]pkg_default)
196953daebaSmrgAC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
197953daebaSmrgm4_popdef([pkg_default])
198953daebaSmrgm4_popdef([pkg_description])
199953daebaSmrg]) dnl PKG_NOARCH_INSTALLDIR
200953daebaSmrg
201953daebaSmrg
202953daebaSmrg# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
203953daebaSmrg# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
204953daebaSmrg# -------------------------------------------
205953daebaSmrg# Retrieves the value of the pkg-config variable for the given module.
206953daebaSmrgAC_DEFUN([PKG_CHECK_VAR],
207953daebaSmrg[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
208953daebaSmrgAC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
209953daebaSmrg
210953daebaSmrg_PKG_CONFIG([$1], [variable="][$3]["], [$2])
211953daebaSmrgAS_VAR_COPY([$1], [pkg_cv_][$1])
212953daebaSmrg
213953daebaSmrgAS_VAR_IF([$1], [""], [$5], [$4])dnl
214953daebaSmrg])# PKG_CHECK_VAR
215