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