pkg.m4 10 KB

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