You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pkg.m4 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. # pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
  2. # serial 1 (pkg-config-0.24)
  3. #
  4. # Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. #
  20. # As a special exception to the GNU General Public License, if you
  21. # distribute this file as part of a program that contains a
  22. # configuration script generated by Autoconf, you may include it under
  23. # the same distribution terms that you use for the rest of that program.
  24. # PKG_PROG_PKG_CONFIG([MIN-VERSION])
  25. # ----------------------------------
  26. AC_DEFUN([PKG_PROG_PKG_CONFIG],
  27. [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
  28. m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
  29. m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
  30. AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
  31. AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
  32. AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
  33. if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
  34. AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
  35. fi
  36. if test -n "$PKG_CONFIG"; then
  37. _pkg_min_version=m4_default([$1], [0.9.0])
  38. AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
  39. if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
  40. AC_MSG_RESULT([yes])
  41. else
  42. AC_MSG_RESULT([no])
  43. PKG_CONFIG=""
  44. fi
  45. fi[]dnl
  46. ])# PKG_PROG_PKG_CONFIG
  47. # PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  48. #
  49. # Check to see whether a particular set of modules exists. Similar
  50. # to PKG_CHECK_MODULES(), but does not set variables or print errors.
  51. #
  52. # Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  53. # only at the first occurence in configure.ac, so if the first place
  54. # it's called might be skipped (such as if it is within an "if", you
  55. # have to call PKG_CHECK_EXISTS manually
  56. # --------------------------------------------------------------
  57. AC_DEFUN([PKG_CHECK_EXISTS],
  58. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  59. if test -n "$PKG_CONFIG" && \
  60. AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
  61. m4_default([$2], [:])
  62. m4_ifvaln([$3], [else
  63. $3])dnl
  64. fi])
  65. # _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
  66. # ---------------------------------------------
  67. m4_define([_PKG_CONFIG],
  68. [if test -n "$$1"; then
  69. pkg_cv_[]$1="$$1"
  70. elif test -n "$PKG_CONFIG"; then
  71. PKG_CHECK_EXISTS([$3],
  72. [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
  73. test "x$?" != "x0" && pkg_failed=yes ],
  74. [pkg_failed=yes])
  75. else
  76. pkg_failed=untried
  77. fi[]dnl
  78. ])# _PKG_CONFIG
  79. # _PKG_SHORT_ERRORS_SUPPORTED
  80. # -----------------------------
  81. AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
  82. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  83. if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
  84. _pkg_short_errors_supported=yes
  85. else
  86. _pkg_short_errors_supported=no
  87. fi[]dnl
  88. ])# _PKG_SHORT_ERRORS_SUPPORTED
  89. # PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
  90. # [ACTION-IF-NOT-FOUND])
  91. #
  92. #
  93. # Note that if there is a possibility the first call to
  94. # PKG_CHECK_MODULES might not happen, you should be sure to include an
  95. # explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
  96. #
  97. #
  98. # --------------------------------------------------------------
  99. AC_DEFUN([PKG_CHECK_MODULES],
  100. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  101. AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
  102. AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
  103. pkg_failed=no
  104. AC_MSG_CHECKING([for $1])
  105. _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
  106. _PKG_CONFIG([$1][_LIBS], [libs], [$2])
  107. m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
  108. and $1[]_LIBS to avoid the need to call pkg-config.
  109. See the pkg-config man page for more details.])
  110. if test $pkg_failed = yes; then
  111. AC_MSG_RESULT([no])
  112. _PKG_SHORT_ERRORS_SUPPORTED
  113. if test $_pkg_short_errors_supported = yes; then
  114. $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
  115. else
  116. $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
  117. fi
  118. # Put the nasty error message in config.log where it belongs
  119. echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
  120. m4_default([$4], [AC_MSG_ERROR(
  121. [Package requirements ($2) were not met:
  122. $$1_PKG_ERRORS
  123. Consider adjusting the PKG_CONFIG_PATH environment variable if you
  124. installed software in a non-standard prefix.
  125. _PKG_TEXT])[]dnl
  126. ])
  127. elif test $pkg_failed = untried; then
  128. AC_MSG_RESULT([no])
  129. m4_default([$4], [AC_MSG_FAILURE(
  130. [The pkg-config script could not be found or is too old. Make sure it
  131. is in your PATH or set the PKG_CONFIG environment variable to the full
  132. path to pkg-config.
  133. _PKG_TEXT
  134. To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
  135. ])
  136. else
  137. $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
  138. $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
  139. AC_MSG_RESULT([yes])
  140. $3
  141. fi[]dnl
  142. ])# PKG_CHECK_MODULES
  143. # PKG_INSTALLDIR(DIRECTORY)
  144. # -------------------------
  145. # Substitutes the variable pkgconfigdir as the location where a module
  146. # should install pkg-config .pc files. By default the directory is
  147. # $libdir/pkgconfig, but the default can be changed by passing
  148. # DIRECTORY. The user can override through the --with-pkgconfigdir
  149. # parameter.
  150. AC_DEFUN([PKG_INSTALLDIR],
  151. [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
  152. m4_pushdef([pkg_description],
  153. [pkg-config installation directory @<:@]pkg_default[@:>@])
  154. AC_ARG_WITH([pkgconfigdir],
  155. [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
  156. [with_pkgconfigdir=]pkg_default)
  157. AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
  158. m4_popdef([pkg_default])
  159. m4_popdef([pkg_description])
  160. ]) dnl PKG_INSTALLDIR
  161. # PKG_NOARCH_INSTALLDIR(DIRECTORY)
  162. # -------------------------
  163. # Substitutes the variable noarch_pkgconfigdir as the location where a
  164. # module should install arch-independent pkg-config .pc files. By
  165. # default the directory is $datadir/pkgconfig, but the default can be
  166. # changed by passing DIRECTORY. The user can override through the
  167. # --with-noarch-pkgconfigdir parameter.
  168. AC_DEFUN([PKG_NOARCH_INSTALLDIR],
  169. [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
  170. m4_pushdef([pkg_description],
  171. [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
  172. AC_ARG_WITH([noarch-pkgconfigdir],
  173. [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
  174. [with_noarch_pkgconfigdir=]pkg_default)
  175. AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
  176. m4_popdef([pkg_default])
  177. m4_popdef([pkg_description])
  178. ]) dnl PKG_NOARCH_INSTALLDIR
  179. # PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
  180. # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  181. # -------------------------------------------
  182. # Retrieves the value of the pkg-config variable for the given module.
  183. AC_DEFUN([PKG_CHECK_VAR],
  184. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  185. AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
  186. _PKG_CONFIG([$1], [variable="][$3]["], [$2])
  187. AS_VAR_COPY([$1], [pkg_cv_][$1])
  188. AS_VAR_IF([$1], [""], [$5], [$4])dnl
  189. ])# PKG_CHECK_VAR