pkg.m4 (12678B)
1 # pkg.m4 - Macros to locate and use pkg-config. -*- Autoconf -*- 2 # serial 16 (pkgconf) 3 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, see <https://www.gnu.org/licenses/>. 19 dnl 20 dnl As a special exception to the GNU General Public License, if you 21 dnl distribute this file as part of a program that contains a 22 dnl configuration script generated by Autoconf, you may include it under 23 dnl the same distribution terms that you use for the rest of that 24 dnl program. 25 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 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 64 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then 65 AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) 66 fi 67 if test -n "$PKG_CONFIG"; then 68 _pkg_min_version=m4_default([$1], [0.9.0]) 69 AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) 70 if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then 71 AC_MSG_RESULT([yes]) 72 else 73 AC_MSG_RESULT([no]) 74 PKG_CONFIG="" 75 fi 76 fi[]dnl 77 ])dnl PKG_PROG_PKG_CONFIG 78 79 dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 80 dnl ------------------------------------------------------------------- 81 dnl Since: 0.18 82 dnl 83 dnl Check to see whether a particular set of modules exists. Similar to 84 dnl PKG_CHECK_MODULES(), but does not set variables or print errors. 85 dnl 86 dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) 87 dnl only at the first occurrence in configure.ac, so if the first place 88 dnl it's called might be skipped (such as if it is within an "if", you 89 dnl have to call PKG_CHECK_EXISTS manually 90 AC_DEFUN([PKG_CHECK_EXISTS], 91 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 92 if test -n "$PKG_CONFIG" && \ 93 AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then 94 m4_default([$2], [:]) 95 m4_ifvaln([$3], [else 96 $3])dnl 97 fi]) 98 99 dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) 100 dnl --------------------------------------------- 101 dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting 102 dnl pkg_failed based on the result. 103 m4_define([_PKG_CONFIG], 104 [if test -n "$$1"; then 105 pkg_cv_[]$1="$$1" 106 elif test -n "$PKG_CONFIG"; then 107 PKG_CHECK_EXISTS([$3], 108 [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null` 109 test "x$?" != "x0" && pkg_failed=yes ], 110 [pkg_failed=yes]) 111 else 112 pkg_failed=untried 113 fi[]dnl 114 ])dnl _PKG_CONFIG 115 116 dnl _PKG_SHORT_ERRORS_SUPPORTED 117 dnl --------------------------- 118 dnl Internal check to see if pkg-config supports short errors. 119 AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], 120 [AC_REQUIRE([PKG_PROG_PKG_CONFIG]) 121 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then 122 _pkg_short_errors_supported=yes 123 else 124 _pkg_short_errors_supported=no 125 fi[]dnl 126 ])dnl _PKG_SHORT_ERRORS_SUPPORTED 127 128 129 dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], 130 dnl [ACTION-IF-NOT-FOUND]) 131 dnl -------------------------------------------------------------- 132 dnl Since: 0.4.0 133 dnl 134 dnl Note that if there is a possibility the first call to 135 dnl PKG_CHECK_MODULES might not happen, you should be sure to include an 136 dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac 137 AC_DEFUN([PKG_CHECK_MODULES], 138 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 139 AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl 140 AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl 141 142 pkg_failed=no 143 AC_MSG_CHECKING([for $2]) 144 145 _PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) 146 _PKG_CONFIG([$1][_LIBS], [libs], [$2]) 147 148 m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS 149 and $1[]_LIBS to avoid the need to call pkg-config. 150 See the pkg-config man page for more details.]) 151 152 if test $pkg_failed = yes; then 153 AC_MSG_RESULT([no]) 154 _PKG_SHORT_ERRORS_SUPPORTED 155 if test $_pkg_short_errors_supported = yes; then 156 $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1` 157 else 158 $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1` 159 fi 160 # Put the nasty error message in config.log where it belongs 161 echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD 162 163 m4_default([$4], [AC_MSG_ERROR( 164 [Package requirements ($2) were not met: 165 166 $$1_PKG_ERRORS 167 168 Consider adjusting the PKG_CONFIG_PATH environment variable if you 169 installed software in a non-standard prefix. 170 171 _PKG_TEXT])[]dnl 172 ]) 173 elif test $pkg_failed = untried; then 174 AC_MSG_RESULT([no]) 175 m4_default([$4], [AC_MSG_FAILURE( 176 [A pkg-config implementation could not be found or is too old. Make sure it 177 is in your PATH or set the PKG_CONFIG environment variable to the full 178 path to pkg-config. 179 180 _PKG_TEXT 181 182 To get a pkg-config implementation, see <http://github.com/pkgconf/pkgconf>.])[]dnl 183 ]) 184 else 185 $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS 186 $1[]_LIBS=$pkg_cv_[]$1[]_LIBS 187 AC_MSG_RESULT([yes]) 188 $3 189 fi[]dnl 190 ])dnl PKG_CHECK_MODULES 191 192 193 dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], 194 dnl [ACTION-IF-NOT-FOUND]) 195 dnl --------------------------------------------------------------------- 196 dnl Since: 0.29 197 dnl 198 dnl Checks for existence of MODULES and gathers its build flags with 199 dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags 200 dnl and VARIABLE-PREFIX_LIBS from --libs. 201 dnl 202 dnl Note that if there is a possibility the first call to 203 dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to 204 dnl include an explicit call to PKG_PROG_PKG_CONFIG in your 205 dnl configure.ac. 206 AC_DEFUN([PKG_CHECK_MODULES_STATIC], 207 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 208 _save_PKG_CONFIG=$PKG_CONFIG 209 PKG_CONFIG="$PKG_CONFIG --static" 210 PKG_CHECK_MODULES($@) 211 PKG_CONFIG=$_save_PKG_CONFIG[]dnl 212 ])dnl PKG_CHECK_MODULES_STATIC 213 214 215 dnl PKG_INSTALLDIR([DIRECTORY]) 216 dnl ------------------------- 217 dnl Since: 0.27 218 dnl 219 dnl Substitutes the variable pkgconfigdir as the location where a module 220 dnl should install pkg-config .pc files. By default the directory is 221 dnl $libdir/pkgconfig, but the default can be changed by passing 222 dnl DIRECTORY. The user can override through the --with-pkgconfigdir 223 dnl parameter. 224 AC_DEFUN([PKG_INSTALLDIR], 225 [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])]) 226 m4_pushdef([pkg_description], 227 [pkg-config installation directory @<:@]pkg_default[@:>@]) 228 AC_ARG_WITH([pkgconfigdir], 229 [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],, 230 [with_pkgconfigdir=]pkg_default) 231 AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) 232 m4_popdef([pkg_default]) 233 m4_popdef([pkg_description]) 234 ])dnl PKG_INSTALLDIR 235 236 237 dnl PKG_NOARCH_INSTALLDIR([DIRECTORY]) 238 dnl -------------------------------- 239 dnl Since: 0.27 240 dnl 241 dnl Substitutes the variable noarch_pkgconfigdir as the location where a 242 dnl module should install arch-independent pkg-config .pc files. By 243 dnl default the directory is $datadir/pkgconfig, but the default can be 244 dnl changed by passing DIRECTORY. The user can override through the 245 dnl --with-noarch-pkgconfigdir parameter. 246 AC_DEFUN([PKG_NOARCH_INSTALLDIR], 247 [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])]) 248 m4_pushdef([pkg_description], 249 [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@]) 250 AC_ARG_WITH([noarch-pkgconfigdir], 251 [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],, 252 [with_noarch_pkgconfigdir=]pkg_default) 253 AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir]) 254 m4_popdef([pkg_default]) 255 m4_popdef([pkg_description]) 256 ])dnl PKG_NOARCH_INSTALLDIR 257 258 259 dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE, 260 dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 261 dnl ------------------------------------------- 262 dnl Since: 0.28 263 dnl 264 dnl Retrieves the value of the pkg-config variable for the given module. 265 AC_DEFUN([PKG_CHECK_VAR], 266 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl 267 AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl 268 269 _PKG_CONFIG([$1], [variable="][$3]["], [$2]) 270 AS_VAR_COPY([$1], [pkg_cv_][$1]) 271 272 AS_VAR_IF([$1], [""], [$5], [$4])dnl 273 ])dnl PKG_CHECK_VAR 274 275 dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES, 276 dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND], 277 dnl [DESCRIPTION], [DEFAULT]) 278 dnl ------------------------------------------ 279 dnl 280 dnl Prepare a "--with-" configure option using the lowercase 281 dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and 282 dnl PKG_CHECK_MODULES in a single macro. 283 AC_DEFUN([PKG_WITH_MODULES], 284 [ 285 m4_pushdef([with_arg], m4_tolower([$1])) 286 287 m4_pushdef([description], 288 [m4_default([$5], [build with ]with_arg[ support])]) 289 290 m4_pushdef([def_arg], [m4_default([$6], [auto])]) 291 m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes]) 292 m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no]) 293 294 m4_case(def_arg, 295 [yes],[m4_pushdef([with_without], [--without-]with_arg)], 296 [m4_pushdef([with_without],[--with-]with_arg)]) 297 298 AC_ARG_WITH(with_arg, 299 AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),, 300 [AS_TR_SH([with_]with_arg)=def_arg]) 301 302 AS_CASE([$AS_TR_SH([with_]with_arg)], 303 [yes],[PKG_CHECK_MODULES([$1],[$2],[$3],[$4])], 304 [auto],[PKG_CHECK_MODULES([$1],[$2], 305 [m4_n([def_action_if_found]) $3], 306 [m4_n([def_action_if_not_found]) $4])]) 307 308 m4_popdef([with_arg]) 309 m4_popdef([description]) 310 m4_popdef([def_arg]) 311 312 ])dnl PKG_WITH_MODULES 313 314 dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES, 315 dnl [DESCRIPTION], [DEFAULT]) 316 dnl ----------------------------------------------- 317 dnl 318 dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES 319 dnl check._[VARIABLE-PREFIX] is exported as make variable. 320 AC_DEFUN([PKG_HAVE_WITH_MODULES], 321 [ 322 PKG_WITH_MODULES([$1],[$2],,,[$3],[$4]) 323 324 AM_CONDITIONAL([HAVE_][$1], 325 [test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"]) 326 ])dnl PKG_HAVE_WITH_MODULES 327 328 dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES, 329 dnl [DESCRIPTION], [DEFAULT]) 330 dnl ------------------------------------------------------ 331 dnl 332 dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after 333 dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make 334 dnl and preprocessor variable. 335 AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES], 336 [ 337 PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4]) 338 339 AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"], 340 [AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])]) 341 ])dnl PKG_HAVE_DEFINE_WITH_MODULES