🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

275 lines
10 KiB

  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. m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
  139. and $1[]_LIBS to avoid the need to call pkg-config.
  140. See the pkg-config man page for more details.])
  141. if test $pkg_failed = yes; then
  142. AC_MSG_RESULT([no])
  143. _PKG_SHORT_ERRORS_SUPPORTED
  144. if test $_pkg_short_errors_supported = yes; then
  145. $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
  146. else
  147. $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
  148. fi
  149. # Put the nasty error message in config.log where it belongs
  150. echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
  151. m4_default([$4], [AC_MSG_ERROR(
  152. [Package requirements ($2) were not met:
  153. $$1_PKG_ERRORS
  154. Consider adjusting the PKG_CONFIG_PATH environment variable if you
  155. installed software in a non-standard prefix.
  156. _PKG_TEXT])[]dnl
  157. ])
  158. elif test $pkg_failed = untried; then
  159. AC_MSG_RESULT([no])
  160. m4_default([$4], [AC_MSG_FAILURE(
  161. [The pkg-config script could not be found or is too old. Make sure it
  162. is in your PATH or set the PKG_CONFIG environment variable to the full
  163. path to pkg-config.
  164. _PKG_TEXT
  165. To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
  166. ])
  167. else
  168. $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
  169. $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
  170. AC_MSG_RESULT([yes])
  171. $3
  172. fi[]dnl
  173. ])dnl PKG_CHECK_MODULES
  174. dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
  175. dnl [ACTION-IF-NOT-FOUND])
  176. dnl ---------------------------------------------------------------------
  177. dnl Since: 0.29
  178. dnl
  179. dnl Checks for existence of MODULES and gathers its build flags with
  180. dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
  181. dnl and VARIABLE-PREFIX_LIBS from --libs.
  182. dnl
  183. dnl Note that if there is a possibility the first call to
  184. dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to
  185. dnl include an explicit call to PKG_PROG_PKG_CONFIG in your
  186. dnl configure.ac.
  187. AC_DEFUN([PKG_CHECK_MODULES_STATIC],
  188. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  189. _save_PKG_CONFIG=$PKG_CONFIG
  190. PKG_CONFIG="$PKG_CONFIG --static"
  191. PKG_CHECK_MODULES($@)
  192. PKG_CONFIG=$_save_PKG_CONFIG[]dnl
  193. ])dnl PKG_CHECK_MODULES_STATIC
  194. dnl PKG_INSTALLDIR([DIRECTORY])
  195. dnl -------------------------
  196. dnl Since: 0.27
  197. dnl
  198. dnl Substitutes the variable pkgconfigdir as the location where a module
  199. dnl should install pkg-config .pc files. By default the directory is
  200. dnl $libdir/pkgconfig, but the default can be changed by passing
  201. dnl DIRECTORY. The user can override through the --with-pkgconfigdir
  202. dnl parameter.
  203. AC_DEFUN([PKG_INSTALLDIR],
  204. [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
  205. m4_pushdef([pkg_description],
  206. [pkg-config installation directory @<:@]pkg_default[@:>@])
  207. AC_ARG_WITH([pkgconfigdir],
  208. [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
  209. [with_pkgconfigdir=]pkg_default)
  210. AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
  211. m4_popdef([pkg_default])
  212. m4_popdef([pkg_description])
  213. ])dnl PKG_INSTALLDIR
  214. dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
  215. dnl --------------------------------
  216. dnl Since: 0.27
  217. dnl
  218. dnl Substitutes the variable noarch_pkgconfigdir as the location where a
  219. dnl module should install arch-independent pkg-config .pc files. By
  220. dnl default the directory is $datadir/pkgconfig, but the default can be
  221. dnl changed by passing DIRECTORY. The user can override through the
  222. dnl --with-noarch-pkgconfigdir parameter.
  223. AC_DEFUN([PKG_NOARCH_INSTALLDIR],
  224. [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
  225. m4_pushdef([pkg_description],
  226. [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
  227. AC_ARG_WITH([noarch-pkgconfigdir],
  228. [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
  229. [with_noarch_pkgconfigdir=]pkg_default)
  230. AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
  231. m4_popdef([pkg_default])
  232. m4_popdef([pkg_description])
  233. ])dnl PKG_NOARCH_INSTALLDIR
  234. dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
  235. dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  236. dnl -------------------------------------------
  237. dnl Since: 0.28
  238. dnl
  239. dnl Retrieves the value of the pkg-config variable for the given module.
  240. AC_DEFUN([PKG_CHECK_VAR],
  241. [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
  242. AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
  243. _PKG_CONFIG([$1], [variable="][$3]["], [$2])
  244. AS_VAR_COPY([$1], [pkg_cv_][$1])
  245. AS_VAR_IF([$1], [""], [$5], [$4])dnl
  246. ])dnl PKG_CHECK_VAR