1
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
2
# serial 11 (pkg-config-0.29.1)
4
dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
5
dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
7
dnl This program is free software; you can redistribute it and/or modify
8
dnl it under the terms of the GNU General Public License as published by
9
dnl the Free Software Foundation; either version 2 of the License, or
10
dnl (at your option) any later version.
12
dnl This program is distributed in the hope that it will be useful, but
13
dnl WITHOUT ANY WARRANTY; without even the implied warranty of
14
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
dnl General Public License for more details.
17
dnl You should have received a copy of the GNU General Public License
18
dnl along with this program; if not, write to the Free Software
19
dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22
dnl As a special exception to the GNU General Public License, if you
23
dnl distribute this file as part of a program that contains a
24
dnl configuration script generated by Autoconf, you may include it under
25
dnl the same distribution terms that you use for the rest of that
28
dnl PKG_PREREQ(MIN-VERSION)
29
dnl -----------------------
32
dnl Verify that the version of the pkg-config macros are at least
33
dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
34
dnl installed version of pkg-config, this checks the developer's version
35
dnl of pkg.m4 when generating configure.
37
dnl To ensure that this macro is defined, also add:
38
dnl m4_ifndef([PKG_PREREQ],
39
dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
41
dnl See the "Since" comment for each macro you use to see what version
42
dnl of the macros you require.
43
m4_defun([PKG_PREREQ],
44
[m4_define([PKG_MACROS_VERSION], [0.29.1])
45
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
46
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
49
dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
50
dnl ----------------------------------
53
dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
54
dnl first found in the path. Checks that the version of pkg-config found
55
dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is
56
dnl used since that's the first version where most current features of
57
dnl pkg-config existed.
58
AC_DEFUN([PKG_PROG_PKG_CONFIG],
59
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
60
m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
61
m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
62
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
63
AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
64
AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
66
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
67
AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
69
if test -n "$PKG_CONFIG"; then
70
_pkg_min_version=m4_default([$1], [0.9.0])
71
AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
72
if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
79
])dnl PKG_PROG_PKG_CONFIG
81
dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
82
dnl -------------------------------------------------------------------
85
dnl Check to see whether a particular set of modules exists. Similar to
86
dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
88
dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
89
dnl only at the first occurence in configure.ac, so if the first place
90
dnl it's called might be skipped (such as if it is within an "if", you
91
dnl have to call PKG_CHECK_EXISTS manually
92
AC_DEFUN([PKG_CHECK_EXISTS],
93
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
94
if test -n "$PKG_CONFIG" && \
95
AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
101
dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
102
dnl ---------------------------------------------
103
dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
104
dnl pkg_failed based on the result.
105
m4_define([_PKG_CONFIG],
106
[if test -n "$$1"; then
108
elif test -n "$PKG_CONFIG"; then
109
PKG_CHECK_EXISTS([$3],
110
[pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
111
test "x$?" != "x0" && pkg_failed=yes ],
118
dnl _PKG_SHORT_ERRORS_SUPPORTED
119
dnl ---------------------------
120
dnl Internal check to see if pkg-config supports short errors.
121
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
122
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
123
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
124
_pkg_short_errors_supported=yes
126
_pkg_short_errors_supported=no
128
])dnl _PKG_SHORT_ERRORS_SUPPORTED
131
dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
132
dnl [ACTION-IF-NOT-FOUND])
133
dnl --------------------------------------------------------------
136
dnl Note that if there is a possibility the first call to
137
dnl PKG_CHECK_MODULES might not happen, you should be sure to include an
138
dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
139
AC_DEFUN([PKG_CHECK_MODULES],
140
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
141
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
142
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
145
AC_MSG_CHECKING([for $1])
147
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
148
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
150
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
151
and $1[]_LIBS to avoid the need to call pkg-config.
152
See the pkg-config man page for more details.])
154
if test $pkg_failed = yes; then
156
_PKG_SHORT_ERRORS_SUPPORTED
157
if test $_pkg_short_errors_supported = yes; then
158
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
160
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
162
# Put the nasty error message in config.log where it belongs
163
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
165
m4_default([$4], [AC_MSG_ERROR(
166
[Package requirements ($2) were not met:
170
Consider adjusting the PKG_CONFIG_PATH environment variable if you
171
installed software in a non-standard prefix.
175
elif test $pkg_failed = untried; then
177
m4_default([$4], [AC_MSG_FAILURE(
178
[The pkg-config script could not be found or is too old. Make sure it
179
is in your PATH or set the PKG_CONFIG environment variable to the full
184
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
187
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
188
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
192
])dnl PKG_CHECK_MODULES
195
dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
196
dnl [ACTION-IF-NOT-FOUND])
197
dnl ---------------------------------------------------------------------
200
dnl Checks for existence of MODULES and gathers its build flags with
201
dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
202
dnl and VARIABLE-PREFIX_LIBS from --libs.
204
dnl Note that if there is a possibility the first call to
205
dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to
206
dnl include an explicit call to PKG_PROG_PKG_CONFIG in your
208
AC_DEFUN([PKG_CHECK_MODULES_STATIC],
209
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
210
_save_PKG_CONFIG=$PKG_CONFIG
211
PKG_CONFIG="$PKG_CONFIG --static"
212
PKG_CHECK_MODULES($@)
213
PKG_CONFIG=$_save_PKG_CONFIG[]dnl
214
])dnl PKG_CHECK_MODULES_STATIC
217
dnl PKG_INSTALLDIR([DIRECTORY])
218
dnl -------------------------
221
dnl Substitutes the variable pkgconfigdir as the location where a module
222
dnl should install pkg-config .pc files. By default the directory is
223
dnl $libdir/pkgconfig, but the default can be changed by passing
224
dnl DIRECTORY. The user can override through the --with-pkgconfigdir
226
AC_DEFUN([PKG_INSTALLDIR],
227
[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
228
m4_pushdef([pkg_description],
229
[pkg-config installation directory @<:@]pkg_default[@:>@])
230
AC_ARG_WITH([pkgconfigdir],
231
[AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
232
[with_pkgconfigdir=]pkg_default)
233
AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
234
m4_popdef([pkg_default])
235
m4_popdef([pkg_description])
239
dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
240
dnl --------------------------------
243
dnl Substitutes the variable noarch_pkgconfigdir as the location where a
244
dnl module should install arch-independent pkg-config .pc files. By
245
dnl default the directory is $datadir/pkgconfig, but the default can be
246
dnl changed by passing DIRECTORY. The user can override through the
247
dnl --with-noarch-pkgconfigdir parameter.
248
AC_DEFUN([PKG_NOARCH_INSTALLDIR],
249
[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
250
m4_pushdef([pkg_description],
251
[pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
252
AC_ARG_WITH([noarch-pkgconfigdir],
253
[AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
254
[with_noarch_pkgconfigdir=]pkg_default)
255
AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
256
m4_popdef([pkg_default])
257
m4_popdef([pkg_description])
258
])dnl PKG_NOARCH_INSTALLDIR
261
dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
262
dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
263
dnl -------------------------------------------
266
dnl Retrieves the value of the pkg-config variable for the given module.
267
AC_DEFUN([PKG_CHECK_VAR],
268
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
269
AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
271
_PKG_CONFIG([$1], [variable="][$3]["], [$2])
272
AS_VAR_COPY([$1], [pkg_cv_][$1])
274
AS_VAR_IF([$1], [""], [$5], [$4])dnl
277
dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
278
dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
279
dnl [DESCRIPTION], [DEFAULT])
280
dnl ------------------------------------------
282
dnl Prepare a "--with-" configure option using the lowercase
283
dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and
284
dnl PKG_CHECK_MODULES in a single macro.
285
AC_DEFUN([PKG_WITH_MODULES],
287
m4_pushdef([with_arg], m4_tolower([$1]))
289
m4_pushdef([description],
290
[m4_default([$5], [build with ]with_arg[ support])])
292
m4_pushdef([def_arg], [m4_default([$6], [auto])])
293
m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
294
m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])
297
[yes],[m4_pushdef([with_without], [--without-]with_arg)],
298
[m4_pushdef([with_without],[--with-]with_arg)])
300
AC_ARG_WITH(with_arg,
301
AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
302
[AS_TR_SH([with_]with_arg)=def_arg])
304
AS_CASE([$AS_TR_SH([with_]with_arg)],
305
[yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
306
[auto],[PKG_CHECK_MODULES([$1],[$2],
307
[m4_n([def_action_if_found]) $3],
308
[m4_n([def_action_if_not_found]) $4])])
310
m4_popdef([with_arg])
311
m4_popdef([description])
314
])dnl PKG_WITH_MODULES
316
dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
317
dnl [DESCRIPTION], [DEFAULT])
318
dnl -----------------------------------------------
320
dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES
321
dnl check._[VARIABLE-PREFIX] is exported as make variable.
322
AC_DEFUN([PKG_HAVE_WITH_MODULES],
324
PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])
326
AM_CONDITIONAL([HAVE_][$1],
327
[test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
328
])dnl PKG_HAVE_WITH_MODULES
330
dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
331
dnl [DESCRIPTION], [DEFAULT])
332
dnl ------------------------------------------------------
334
dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
335
dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make
336
dnl and preprocessor variable.
337
AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],
339
PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])
341
AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
342
[AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
343
])dnl PKG_HAVE_DEFINE_WITH_MODULES