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