package compiler and linker metadata toolkit https://www.pkgconf.org/

pkg.m4 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. # pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
  2. # serial 11 (pkg-config-0.29.1)
  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.1])
  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 $1])
  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
  247. dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
  248. dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
  249. dnl [DESCRIPTION], [DEFAULT])
  250. dnl ------------------------------------------
  251. dnl
  252. dnl Prepare a "--with-" configure option using the lowercase
  253. dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and
  254. dnl PKG_CHECK_MODULES in a single macro.
  255. AC_DEFUN([PKG_WITH_MODULES],
  256. [
  257. m4_pushdef([with_arg], m4_tolower([$1]))
  258. m4_pushdef([description],
  259. [m4_default([$5], [build with ]with_arg[ support])])
  260. m4_pushdef([def_arg], [m4_default([$6], [auto])])
  261. m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
  262. m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])
  263. m4_case(def_arg,
  264. [yes],[m4_pushdef([with_without], [--without-]with_arg)],
  265. [m4_pushdef([with_without],[--with-]with_arg)])
  266. AC_ARG_WITH(with_arg,
  267. AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
  268. [AS_TR_SH([with_]with_arg)=def_arg])
  269. AS_CASE([$AS_TR_SH([with_]with_arg)],
  270. [yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
  271. [auto],[PKG_CHECK_MODULES([$1],[$2],
  272. [m4_n([def_action_if_found]) $3],
  273. [m4_n([def_action_if_not_found]) $4])])
  274. m4_popdef([with_arg])
  275. m4_popdef([description])
  276. m4_popdef([def_arg])
  277. ])dnl PKG_WITH_MODULES
  278. dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
  279. dnl [DESCRIPTION], [DEFAULT])
  280. dnl -----------------------------------------------
  281. dnl
  282. dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES
  283. dnl check._[VARIABLE-PREFIX] is exported as make variable.
  284. AC_DEFUN([PKG_HAVE_WITH_MODULES],
  285. [
  286. PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])
  287. AM_CONDITIONAL([HAVE_][$1],
  288. [test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
  289. ])dnl PKG_HAVE_WITH_MODULES
  290. dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
  291. dnl [DESCRIPTION], [DEFAULT])
  292. dnl ------------------------------------------------------
  293. dnl
  294. dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
  295. dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make
  296. dnl and preprocessor variable.
  297. AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],
  298. [
  299. PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])
  300. AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
  301. [AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
  302. ])dnl PKG_HAVE_DEFINE_WITH_MODULES