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