Makefile.def: Remove reference to boehm-gc target module.
[official-gcc.git] / config / pkg.m4
blob0301d2785ad2f8e208eed3270a1ca873dbdf50cb
1 dnl pkg.m4 - Macros to locate and utilise pkg-config.   -*- Autoconf -*-
2 dnl serial 11 (pkg-config-0.29)
3 dnl
4 dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
5 dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
6 dnl
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.
11 dnl
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.
16 dnl
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
20 dnl 02111-1307, USA.
21 dnl
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
26 dnl program.
28 dnl PKG_PREREQ(MIN-VERSION)
29 dnl -----------------------
30 dnl Since: 0.29
31 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.
36 dnl
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])])
40 dnl
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])
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])])
47 ])dnl PKG_PREREQ
49 dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
50 dnl ----------------------------------
51 dnl Since: 0.16
52 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
73                 AC_MSG_RESULT([yes])
74         else
75                 AC_MSG_RESULT([no])
76                 PKG_CONFIG=""
77         fi
78 fi[]dnl
79 ])dnl PKG_PROG_PKG_CONFIG
81 dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
82 dnl -------------------------------------------------------------------
83 dnl Since: 0.18
84 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.
87 dnl
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
96   m4_default([$2], [:])
97 m4_ifvaln([$3], [else
98   $3])dnl
99 fi])
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
107     pkg_cv_[]$1="$$1"
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 ],
112                      [pkg_failed=yes])
113  else
114     pkg_failed=untried
115 fi[]dnl
116 ])dnl _PKG_CONFIG
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
125 else
126         _pkg_short_errors_supported=no
127 fi[]dnl
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 --------------------------------------------------------------
134 dnl Since: 0.4.0
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
144 pkg_failed=no
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
155         AC_MSG_RESULT([no])
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`
159         else 
160                 $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
161         fi
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:
168 $$1_PKG_ERRORS
170 Consider adjusting the PKG_CONFIG_PATH environment variable if you
171 installed software in a non-standard prefix.
173 _PKG_TEXT])[]dnl
174         ])
175 elif test $pkg_failed = untried; then
176         AC_MSG_RESULT([no])
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
180 path to pkg-config.
182 _PKG_TEXT
184 To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
185         ])
186 else
187         $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
188         $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
189         AC_MSG_RESULT([yes])
190         $3
191 fi[]dnl
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 ---------------------------------------------------------------------
198 dnl Since: 0.29
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
207 dnl configure.ac.
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 -------------------------
219 dnl Since: 0.27
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
225 dnl parameter.
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])
236 ])dnl PKG_INSTALLDIR
239 dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
240 dnl --------------------------------
241 dnl Since: 0.27
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 -------------------------------------------
264 dnl Since: 0.28
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
275 ])dnl PKG_CHECK_VAR
276 dnl pkg.m4 - Macros to locate and utilise pkg-config.   -*- Autoconf -*-
277 dnl serial 11 (pkg-config-0.29)
279 dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
280 dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
282 dnl This program is free software; you can redistribute it and/or modify
283 dnl it under the terms of the GNU General Public License as published by
284 dnl the Free Software Foundation; either version 2 of the License, or
285 dnl (at your option) any later version.
287 dnl This program is distributed in the hope that it will be useful, but
288 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
289 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
290 dnl General Public License for more details.
292 dnl You should have received a copy of the GNU General Public License
293 dnl along with this program; if not, write to the Free Software
294 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
295 dnl 02111-1307, USA.
297 dnl As a special exception to the GNU General Public License, if you
298 dnl distribute this file as part of a program that contains a
299 dnl configuration script generated by Autoconf, you may include it under
300 dnl the same distribution terms that you use for the rest of that
301 dnl program.
303 dnl PKG_PREREQ(MIN-VERSION)
304 dnl -----------------------
305 dnl Since: 0.29
307 dnl Verify that the version of the pkg-config macros are at least
308 dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
309 dnl installed version of pkg-config, this checks the developer's version
310 dnl of pkg.m4 when generating configure.
312 dnl To ensure that this macro is defined, also add:
313 dnl m4_ifndef([PKG_PREREQ],
314 dnl     [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
316 dnl See the "Since" comment for each macro you use to see what version
317 dnl of the macros you require.
318 m4_defun([PKG_PREREQ],
319 [m4_define([PKG_MACROS_VERSION], [0.29])
320 m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
321     [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
322 ])dnl PKG_PREREQ
324 dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
325 dnl ----------------------------------
326 dnl Since: 0.16
328 dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
329 dnl first found in the path. Checks that the version of pkg-config found
330 dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is
331 dnl used since that's the first version where most current features of
332 dnl pkg-config existed.
333 AC_DEFUN([PKG_PROG_PKG_CONFIG],
334 [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
335 m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
336 m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
337 AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
338 AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
339 AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
341 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
342         AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
344 if test -n "$PKG_CONFIG"; then
345         _pkg_min_version=m4_default([$1], [0.9.0])
346         AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
347         if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
348                 AC_MSG_RESULT([yes])
349         else
350                 AC_MSG_RESULT([no])
351                 PKG_CONFIG=""
352         fi
353 fi[]dnl
354 ])dnl PKG_PROG_PKG_CONFIG
356 dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
357 dnl -------------------------------------------------------------------
358 dnl Since: 0.18
360 dnl Check to see whether a particular set of modules exists. Similar to
361 dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
363 dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
364 dnl only at the first occurence in configure.ac, so if the first place
365 dnl it's called might be skipped (such as if it is within an "if", you
366 dnl have to call PKG_CHECK_EXISTS manually
367 AC_DEFUN([PKG_CHECK_EXISTS],
368 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
369 if test -n "$PKG_CONFIG" && \
370     AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
371   m4_default([$2], [:])
372 m4_ifvaln([$3], [else
373   $3])dnl
374 fi])
376 dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
377 dnl ---------------------------------------------
378 dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
379 dnl pkg_failed based on the result.
380 m4_define([_PKG_CONFIG],
381 [if test -n "$$1"; then
382     pkg_cv_[]$1="$$1"
383  elif test -n "$PKG_CONFIG"; then
384     PKG_CHECK_EXISTS([$3],
385                      [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
386                       test "x$?" != "x0" && pkg_failed=yes ],
387                      [pkg_failed=yes])
388  else
389     pkg_failed=untried
390 fi[]dnl
391 ])dnl _PKG_CONFIG
393 dnl _PKG_SHORT_ERRORS_SUPPORTED
394 dnl ---------------------------
395 dnl Internal check to see if pkg-config supports short errors.
396 AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
397 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])
398 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
399         _pkg_short_errors_supported=yes
400 else
401         _pkg_short_errors_supported=no
402 fi[]dnl
403 ])dnl _PKG_SHORT_ERRORS_SUPPORTED
406 dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
407 dnl   [ACTION-IF-NOT-FOUND])
408 dnl --------------------------------------------------------------
409 dnl Since: 0.4.0
411 dnl Note that if there is a possibility the first call to
412 dnl PKG_CHECK_MODULES might not happen, you should be sure to include an
413 dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
414 AC_DEFUN([PKG_CHECK_MODULES],
415 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
416 AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
417 AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
419 pkg_failed=no
420 AC_MSG_CHECKING([for $1])
422 _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
423 _PKG_CONFIG([$1][_LIBS], [libs], [$2])
425 m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
426 and $1[]_LIBS to avoid the need to call pkg-config.
427 See the pkg-config man page for more details.])
429 if test $pkg_failed = yes; then
430         AC_MSG_RESULT([no])
431         _PKG_SHORT_ERRORS_SUPPORTED
432         if test $_pkg_short_errors_supported = yes; then
433                 $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
434         else 
435                 $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
436         fi
437         # Put the nasty error message in config.log where it belongs
438         echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
440         m4_default([$4], [AC_MSG_ERROR(
441 [Package requirements ($2) were not met:
443 $$1_PKG_ERRORS
445 Consider adjusting the PKG_CONFIG_PATH environment variable if you
446 installed software in a non-standard prefix.
448 _PKG_TEXT])[]dnl
449         ])
450 elif test $pkg_failed = untried; then
451         AC_MSG_RESULT([no])
452         m4_default([$4], [AC_MSG_FAILURE(
453 [The pkg-config script could not be found or is too old.  Make sure it
454 is in your PATH or set the PKG_CONFIG environment variable to the full
455 path to pkg-config.
457 _PKG_TEXT
459 To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
460         ])
461 else
462         $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
463         $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
464         AC_MSG_RESULT([yes])
465         $3
466 fi[]dnl
467 ])dnl PKG_CHECK_MODULES
470 dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
471 dnl   [ACTION-IF-NOT-FOUND])
472 dnl ---------------------------------------------------------------------
473 dnl Since: 0.29
475 dnl Checks for existence of MODULES and gathers its build flags with
476 dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
477 dnl and VARIABLE-PREFIX_LIBS from --libs.
479 dnl Note that if there is a possibility the first call to
480 dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to
481 dnl include an explicit call to PKG_PROG_PKG_CONFIG in your
482 dnl configure.ac.
483 AC_DEFUN([PKG_CHECK_MODULES_STATIC],
484 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
485 _save_PKG_CONFIG=$PKG_CONFIG
486 PKG_CONFIG="$PKG_CONFIG --static"
487 PKG_CHECK_MODULES($@)
488 PKG_CONFIG=$_save_PKG_CONFIG[]dnl
489 ])dnl PKG_CHECK_MODULES_STATIC
492 dnl PKG_INSTALLDIR([DIRECTORY])
493 dnl -------------------------
494 dnl Since: 0.27
496 dnl Substitutes the variable pkgconfigdir as the location where a module
497 dnl should install pkg-config .pc files. By default the directory is
498 dnl $libdir/pkgconfig, but the default can be changed by passing
499 dnl DIRECTORY. The user can override through the --with-pkgconfigdir
500 dnl parameter.
501 AC_DEFUN([PKG_INSTALLDIR],
502 [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
503 m4_pushdef([pkg_description],
504     [pkg-config installation directory @<:@]pkg_default[@:>@])
505 AC_ARG_WITH([pkgconfigdir],
506     [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
507     [with_pkgconfigdir=]pkg_default)
508 AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
509 m4_popdef([pkg_default])
510 m4_popdef([pkg_description])
511 ])dnl PKG_INSTALLDIR
514 dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
515 dnl --------------------------------
516 dnl Since: 0.27
518 dnl Substitutes the variable noarch_pkgconfigdir as the location where a
519 dnl module should install arch-independent pkg-config .pc files. By
520 dnl default the directory is $datadir/pkgconfig, but the default can be
521 dnl changed by passing DIRECTORY. The user can override through the
522 dnl --with-noarch-pkgconfigdir parameter.
523 AC_DEFUN([PKG_NOARCH_INSTALLDIR],
524 [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
525 m4_pushdef([pkg_description],
526     [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
527 AC_ARG_WITH([noarch-pkgconfigdir],
528     [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
529     [with_noarch_pkgconfigdir=]pkg_default)
530 AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
531 m4_popdef([pkg_default])
532 m4_popdef([pkg_description])
533 ])dnl PKG_NOARCH_INSTALLDIR
536 dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
537 dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
538 dnl -------------------------------------------
539 dnl Since: 0.28
541 dnl Retrieves the value of the pkg-config variable for the given module.
542 AC_DEFUN([PKG_CHECK_VAR],
543 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
544 AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
546 _PKG_CONFIG([$1], [variable="][$3]["], [$2])
547 AS_VAR_COPY([$1], [pkg_cv_][$1])
549 AS_VAR_IF([$1], [""], [$5], [$4])dnl
550 ])dnl PKG_CHECK_VAR
551 dnl pkg.m4 - Macros to locate and utilise pkg-config.   -*- Autoconf -*-
552 dnl serial 11 (pkg-config-0.29)
554 dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
555 dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
557 dnl This program is free software; you can redistribute it and/or modify
558 dnl it under the terms of the GNU General Public License as published by
559 dnl the Free Software Foundation; either version 2 of the License, or
560 dnl (at your option) any later version.
562 dnl This program is distributed in the hope that it will be useful, but
563 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
564 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
565 dnl General Public License for more details.
567 dnl You should have received a copy of the GNU General Public License
568 dnl along with this program; if not, write to the Free Software
569 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
570 dnl 02111-1307, USA.
572 dnl As a special exception to the GNU General Public License, if you
573 dnl distribute this file as part of a program that contains a
574 dnl configuration script generated by Autoconf, you may include it under
575 dnl the same distribution terms that you use for the rest of that
576 dnl program.
578 dnl PKG_PREREQ(MIN-VERSION)
579 dnl -----------------------
580 dnl Since: 0.29
582 dnl Verify that the version of the pkg-config macros are at least
583 dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
584 dnl installed version of pkg-config, this checks the developer's version
585 dnl of pkg.m4 when generating configure.
587 dnl To ensure that this macro is defined, also add:
588 dnl m4_ifndef([PKG_PREREQ],
589 dnl     [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
591 dnl See the "Since" comment for each macro you use to see what version
592 dnl of the macros you require.
593 m4_defun([PKG_PREREQ],
594 [m4_define([PKG_MACROS_VERSION], [0.29])
595 m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
596     [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
597 ])dnl PKG_PREREQ
599 dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
600 dnl ----------------------------------
601 dnl Since: 0.16
603 dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
604 dnl first found in the path. Checks that the version of pkg-config found
605 dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is
606 dnl used since that's the first version where most current features of
607 dnl pkg-config existed.
608 AC_DEFUN([PKG_PROG_PKG_CONFIG],
609 [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
610 m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
611 m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
612 AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
613 AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
614 AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
616 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
617         AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
619 if test -n "$PKG_CONFIG"; then
620         _pkg_min_version=m4_default([$1], [0.9.0])
621         AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
622         if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
623                 AC_MSG_RESULT([yes])
624         else
625                 AC_MSG_RESULT([no])
626                 PKG_CONFIG=""
627         fi
628 fi[]dnl
629 ])dnl PKG_PROG_PKG_CONFIG
631 dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
632 dnl -------------------------------------------------------------------
633 dnl Since: 0.18
635 dnl Check to see whether a particular set of modules exists. Similar to
636 dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
638 dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
639 dnl only at the first occurence in configure.ac, so if the first place
640 dnl it's called might be skipped (such as if it is within an "if", you
641 dnl have to call PKG_CHECK_EXISTS manually
642 AC_DEFUN([PKG_CHECK_EXISTS],
643 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
644 if test -n "$PKG_CONFIG" && \
645     AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
646   m4_default([$2], [:])
647 m4_ifvaln([$3], [else
648   $3])dnl
649 fi])
651 dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
652 dnl ---------------------------------------------
653 dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
654 dnl pkg_failed based on the result.
655 m4_define([_PKG_CONFIG],
656 [if test -n "$$1"; then
657     pkg_cv_[]$1="$$1"
658  elif test -n "$PKG_CONFIG"; then
659     PKG_CHECK_EXISTS([$3],
660                      [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
661                       test "x$?" != "x0" && pkg_failed=yes ],
662                      [pkg_failed=yes])
663  else
664     pkg_failed=untried
665 fi[]dnl
666 ])dnl _PKG_CONFIG
668 dnl _PKG_SHORT_ERRORS_SUPPORTED
669 dnl ---------------------------
670 dnl Internal check to see if pkg-config supports short errors.
671 AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
672 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])
673 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
674         _pkg_short_errors_supported=yes
675 else
676         _pkg_short_errors_supported=no
677 fi[]dnl
678 ])dnl _PKG_SHORT_ERRORS_SUPPORTED
681 dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
682 dnl   [ACTION-IF-NOT-FOUND])
683 dnl --------------------------------------------------------------
684 dnl Since: 0.4.0
686 dnl Note that if there is a possibility the first call to
687 dnl PKG_CHECK_MODULES might not happen, you should be sure to include an
688 dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
689 AC_DEFUN([PKG_CHECK_MODULES],
690 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
691 AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
692 AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
694 pkg_failed=no
695 AC_MSG_CHECKING([for $1])
697 _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
698 _PKG_CONFIG([$1][_LIBS], [libs], [$2])
700 m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
701 and $1[]_LIBS to avoid the need to call pkg-config.
702 See the pkg-config man page for more details.])
704 if test $pkg_failed = yes; then
705         AC_MSG_RESULT([no])
706         _PKG_SHORT_ERRORS_SUPPORTED
707         if test $_pkg_short_errors_supported = yes; then
708                 $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
709         else 
710                 $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
711         fi
712         # Put the nasty error message in config.log where it belongs
713         echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
715         m4_default([$4], [AC_MSG_ERROR(
716 [Package requirements ($2) were not met:
718 $$1_PKG_ERRORS
720 Consider adjusting the PKG_CONFIG_PATH environment variable if you
721 installed software in a non-standard prefix.
723 _PKG_TEXT])[]dnl
724         ])
725 elif test $pkg_failed = untried; then
726         AC_MSG_RESULT([no])
727         m4_default([$4], [AC_MSG_FAILURE(
728 [The pkg-config script could not be found or is too old.  Make sure it
729 is in your PATH or set the PKG_CONFIG environment variable to the full
730 path to pkg-config.
732 _PKG_TEXT
734 To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
735         ])
736 else
737         $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
738         $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
739         AC_MSG_RESULT([yes])
740         $3
741 fi[]dnl
742 ])dnl PKG_CHECK_MODULES
745 dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
746 dnl   [ACTION-IF-NOT-FOUND])
747 dnl ---------------------------------------------------------------------
748 dnl Since: 0.29
750 dnl Checks for existence of MODULES and gathers its build flags with
751 dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
752 dnl and VARIABLE-PREFIX_LIBS from --libs.
754 dnl Note that if there is a possibility the first call to
755 dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to
756 dnl include an explicit call to PKG_PROG_PKG_CONFIG in your
757 dnl configure.ac.
758 AC_DEFUN([PKG_CHECK_MODULES_STATIC],
759 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
760 _save_PKG_CONFIG=$PKG_CONFIG
761 PKG_CONFIG="$PKG_CONFIG --static"
762 PKG_CHECK_MODULES($@)
763 PKG_CONFIG=$_save_PKG_CONFIG[]dnl
764 ])dnl PKG_CHECK_MODULES_STATIC
767 dnl PKG_INSTALLDIR([DIRECTORY])
768 dnl -------------------------
769 dnl Since: 0.27
771 dnl Substitutes the variable pkgconfigdir as the location where a module
772 dnl should install pkg-config .pc files. By default the directory is
773 dnl $libdir/pkgconfig, but the default can be changed by passing
774 dnl DIRECTORY. The user can override through the --with-pkgconfigdir
775 dnl parameter.
776 AC_DEFUN([PKG_INSTALLDIR],
777 [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
778 m4_pushdef([pkg_description],
779     [pkg-config installation directory @<:@]pkg_default[@:>@])
780 AC_ARG_WITH([pkgconfigdir],
781     [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
782     [with_pkgconfigdir=]pkg_default)
783 AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
784 m4_popdef([pkg_default])
785 m4_popdef([pkg_description])
786 ])dnl PKG_INSTALLDIR
789 dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
790 dnl --------------------------------
791 dnl Since: 0.27
793 dnl Substitutes the variable noarch_pkgconfigdir as the location where a
794 dnl module should install arch-independent pkg-config .pc files. By
795 dnl default the directory is $datadir/pkgconfig, but the default can be
796 dnl changed by passing DIRECTORY. The user can override through the
797 dnl --with-noarch-pkgconfigdir parameter.
798 AC_DEFUN([PKG_NOARCH_INSTALLDIR],
799 [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
800 m4_pushdef([pkg_description],
801     [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
802 AC_ARG_WITH([noarch-pkgconfigdir],
803     [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
804     [with_noarch_pkgconfigdir=]pkg_default)
805 AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
806 m4_popdef([pkg_default])
807 m4_popdef([pkg_description])
808 ])dnl PKG_NOARCH_INSTALLDIR
811 dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
812 dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
813 dnl -------------------------------------------
814 dnl Since: 0.28
816 dnl Retrieves the value of the pkg-config variable for the given module.
817 AC_DEFUN([PKG_CHECK_VAR],
818 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
819 AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
821 _PKG_CONFIG([$1], [variable="][$3]["], [$2])
822 AS_VAR_COPY([$1], [pkg_cv_][$1])
824 AS_VAR_IF([$1], [""], [$5], [$4])dnl
825 ])dnl PKG_CHECK_VAR