pkg.m4 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.
  27. dnl PKG_PREREQ(MIN-VERSION)
  28. dnl -----------------------
  29. dnl Since: 0.29
  30. dnl
  31. dnl Verify that the version of the pkg-config macros are at least
  32. dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
  33. dnl installed version of pkg-config, this checks the developer's version
  34. dnl of pkg.m4 when generating configure.
  35. dnl
  36. dnl To ensure that this macro is defined, also add:
  37. dnl m4_ifndef([PKG_PREREQ],
  38. dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
  39. dnl
  40. dnl See the "Since" comment for each macro you use to see what version
  41. dnl of the macros you require.
  42. m4_defun([PKG_PREREQ],
  43. [m4_define([PKG_MACROS_VERSION], [0.29])
  44. m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
  45. [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
  46. ])dnl PKG_PREREQ
  47. dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
  48. dnl ----------------------------------
  49. dnl Since: 0.16
  50. dnl
  51. dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
  52. dnl first found in the path. Checks that the version of pkg-config found
  53. dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is
  54. dnl used since that's the first version where most current features of
  55. dnl pkg-config existed.
  56. AC_DEFUN([PKG_PROG_PKG_CONFIG],
  57. [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
  58. m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
  59. m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
  60. AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
  61. AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
  62. AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
  63. if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
  64. AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
  65. fi
  66. if test -n "$PKG_CONFIG"; then
  67. _pkg_min_version=m4_default([$1], [0.9.0])
  68. AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
  69. if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
  70. AC_MSG_RESULT([yes])
  71. else
  72. AC_MSG_RESULT([no])
  73. PKG_CONFIG=""
  74. fi
  75. fi[]dnl
  76. ])dnl PKG_PROG_PKG_CONFIG
  77. dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  78. dnl -------------------------------------------------------------------
  79. dnl Since: 0.18
  80. dnl
  81. dnl Check to see whether a particular set of modules exists. Similar to
  82. dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
  83. dnl
  84. dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  85. dnl only at the first occurrence in configure.ac, so if the first place
  86. dnl it's called might be skipped (such as if it is within an "if", you
  87. dnl have to call PKG_CHECK_EXISTS manually
  88. AC_DEFUN([PKG_CHECK_EXISTS],
  89. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  90. if test -n "$PKG_CONFIG" && \
  91. AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
  92. m4_default([$2], [:])
  93. m4_ifvaln([$3], [else
  94. $3])dnl
  95. fi])
  96. dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
  97. dnl ---------------------------------------------
  98. dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
  99. dnl pkg_failed based on the result.
  100. m4_define([_PKG_CONFIG],
  101. [if test -n "$$1"; then
  102. pkg_cv_[]$1="$$1"
  103. elif test -n "$PKG_CONFIG"; then
  104. PKG_CHECK_EXISTS([$3],
  105. [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
  106. test "x$?" != "x0" && pkg_failed=yes ],
  107. [pkg_failed=yes])
  108. else
  109. pkg_failed=untried
  110. fi[]dnl
  111. ])dnl _PKG_CONFIG
  112. dnl _PKG_SHORT_ERRORS_SUPPORTED
  113. dnl ---------------------------
  114. dnl Internal check to see if pkg-config supports short errors.
  115. AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
  116. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  117. if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
  118. _pkg_short_errors_supported=yes
  119. else
  120. _pkg_short_errors_supported=no
  121. fi[]dnl
  122. ])dnl _PKG_SHORT_ERRORS_SUPPORTED
  123. dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
  124. dnl [ACTION-IF-NOT-FOUND])
  125. dnl --------------------------------------------------------------
  126. dnl Since: 0.4.0
  127. dnl
  128. dnl Note that if there is a possibility the first call to
  129. dnl PKG_CHECK_MODULES might not happen, you should be sure to include an
  130. dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
  131. AC_DEFUN([PKG_CHECK_MODULES],
  132. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  133. AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
  134. AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
  135. pkg_failed=no
  136. AC_MSG_CHECKING([for $1])
  137. _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
  138. _PKG_CONFIG([$1][_LIBS], [libs], [$2])
  139. m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
  140. and $1[]_LIBS to avoid the need to call pkg-config.
  141. See the pkg-config man page for more details.])
  142. if test $pkg_failed = yes; then
  143. AC_MSG_RESULT([no])
  144. _PKG_SHORT_ERRORS_SUPPORTED
  145. if test $_pkg_short_errors_supported = yes; then
  146. $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
  147. else
  148. $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
  149. fi
  150. # Put the nasty error message in config.log where it belongs
  151. echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
  152. m4_default([$4], [AC_MSG_ERROR(
  153. [Package requirements ($2) were not met:
  154. $$1_PKG_ERRORS
  155. Consider adjusting the PKG_CONFIG_PATH environment variable if you
  156. installed software in a non-standard prefix.
  157. _PKG_TEXT])[]dnl
  158. ])
  159. elif test $pkg_failed = untried; then
  160. AC_MSG_RESULT([no])
  161. m4_default([$4], [AC_MSG_FAILURE(
  162. [The pkg-config script could not be found or is too old. Make sure it
  163. is in your PATH or set the PKG_CONFIG environment variable to the full
  164. path to pkg-config.
  165. _PKG_TEXT
  166. To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
  167. ])
  168. else
  169. $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
  170. $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
  171. AC_MSG_RESULT([yes])
  172. $3
  173. fi[]dnl
  174. ])dnl PKG_CHECK_MODULES
  175. dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
  176. dnl [ACTION-IF-NOT-FOUND])
  177. dnl ---------------------------------------------------------------------
  178. dnl Since: 0.29
  179. dnl
  180. dnl Checks for existence of MODULES and gathers its build flags with
  181. dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
  182. dnl and VARIABLE-PREFIX_LIBS from --libs.
  183. dnl
  184. dnl Note that if there is a possibility the first call to
  185. dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to
  186. dnl include an explicit call to PKG_PROG_PKG_CONFIG in your
  187. dnl configure.ac.
  188. AC_DEFUN([PKG_CHECK_MODULES_STATIC],
  189. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  190. _save_PKG_CONFIG=$PKG_CONFIG
  191. PKG_CONFIG="$PKG_CONFIG --static"
  192. PKG_CHECK_MODULES($@)
  193. PKG_CONFIG=$_save_PKG_CONFIG[]dnl
  194. ])dnl PKG_CHECK_MODULES_STATIC
  195. dnl PKG_INSTALLDIR([DIRECTORY])
  196. dnl -------------------------
  197. dnl Since: 0.27
  198. dnl
  199. dnl Substitutes the variable pkgconfigdir as the location where a module
  200. dnl should install pkg-config .pc files. By default the directory is
  201. dnl $libdir/pkgconfig, but the default can be changed by passing
  202. dnl DIRECTORY. The user can override through the --with-pkgconfigdir
  203. dnl parameter.
  204. AC_DEFUN([PKG_INSTALLDIR],
  205. [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
  206. m4_pushdef([pkg_description],
  207. [pkg-config installation directory @<:@]pkg_default[@:>@])
  208. AC_ARG_WITH([pkgconfigdir],
  209. [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
  210. [with_pkgconfigdir=]pkg_default)
  211. AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
  212. m4_popdef([pkg_default])
  213. m4_popdef([pkg_description])
  214. ])dnl PKG_INSTALLDIR
  215. dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
  216. dnl --------------------------------
  217. dnl Since: 0.27
  218. dnl
  219. dnl Substitutes the variable noarch_pkgconfigdir as the location where a
  220. dnl module should install arch-independent pkg-config .pc files. By
  221. dnl default the directory is $datadir/pkgconfig, but the default can be
  222. dnl changed by passing DIRECTORY. The user can override through the
  223. dnl --with-noarch-pkgconfigdir parameter.
  224. AC_DEFUN([PKG_NOARCH_INSTALLDIR],
  225. [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
  226. m4_pushdef([pkg_description],
  227. [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
  228. AC_ARG_WITH([noarch-pkgconfigdir],
  229. [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
  230. [with_noarch_pkgconfigdir=]pkg_default)
  231. AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
  232. m4_popdef([pkg_default])
  233. m4_popdef([pkg_description])
  234. ])dnl PKG_NOARCH_INSTALLDIR
  235. dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
  236. dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  237. dnl -------------------------------------------
  238. dnl Since: 0.28
  239. dnl
  240. dnl Retrieves the value of the pkg-config variable for the given module.
  241. AC_DEFUN([PKG_CHECK_VAR],
  242. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  243. AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
  244. _PKG_CONFIG([$1], [variable="][$3]["], [$2])
  245. AS_VAR_COPY([$1], [pkg_cv_][$1])
  246. AS_VAR_IF([$1], [""], [$5], [$4])dnl
  247. ])dnl PKG_CHECK_VAR