Blame m4/pkg.m4

Packit 4e910c
dnl pkg.m4 - Macros to locate and utilise pkg-config.   -*- Autoconf -*-
Packit 4e910c
dnl serial 11 (pkg-config-0.29.1)
Packit 4e910c
dnl
Packit 4e910c
dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
Packit 4e910c
dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
Packit 4e910c
dnl
Packit 4e910c
dnl This program is free software; you can redistribute it and/or modify
Packit 4e910c
dnl it under the terms of the GNU General Public License as published by
Packit 4e910c
dnl the Free Software Foundation; either version 2 of the License, or
Packit 4e910c
dnl (at your option) any later version.
Packit 4e910c
dnl
Packit 4e910c
dnl This program is distributed in the hope that it will be useful, but
Packit 4e910c
dnl WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4e910c
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Packit 4e910c
dnl General Public License for more details.
Packit 4e910c
dnl
Packit 4e910c
dnl You should have received a copy of the GNU General Public License
Packit 4e910c
dnl along with this program; if not, write to the Free Software
Packit 4e910c
dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
Packit 4e910c
dnl 02111-1307, USA.
Packit 4e910c
dnl
Packit 4e910c
dnl As a special exception to the GNU General Public License, if you
Packit 4e910c
dnl distribute this file as part of a program that contains a
Packit 4e910c
dnl configuration script generated by Autoconf, you may include it under
Packit 4e910c
dnl the same distribution terms that you use for the rest of that
Packit 4e910c
dnl program.
Packit 4e910c
Packit 4e910c
dnl PKG_PREREQ(MIN-VERSION)
Packit 4e910c
dnl -----------------------
Packit 4e910c
dnl Since: 0.29
Packit 4e910c
dnl
Packit 4e910c
dnl Verify that the version of the pkg-config macros are at least
Packit 4e910c
dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
Packit 4e910c
dnl installed version of pkg-config, this checks the developer's version
Packit 4e910c
dnl of pkg.m4 when generating configure.
Packit 4e910c
dnl
Packit 4e910c
dnl To ensure that this macro is defined, also add:
Packit 4e910c
dnl m4_ifndef([PKG_PREREQ],
Packit 4e910c
dnl     [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
Packit 4e910c
dnl
Packit 4e910c
dnl See the "Since" comment for each macro you use to see what version
Packit 4e910c
dnl of the macros you require.
Packit 4e910c
m4_defun([PKG_PREREQ],
Packit 4e910c
[m4_define([PKG_MACROS_VERSION], [0.29.1])
Packit 4e910c
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
Packit 4e910c
    [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
Packit 4e910c
])dnl PKG_PREREQ
Packit 4e910c
Packit 4e910c
dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
Packit 4e910c
dnl ----------------------------------
Packit 4e910c
dnl Since: 0.16
Packit 4e910c
dnl
Packit 4e910c
dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
Packit 4e910c
dnl first found in the path. Checks that the version of pkg-config found
Packit 4e910c
dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is
Packit 4e910c
dnl used since that's the first version where most current features of
Packit 4e910c
dnl pkg-config existed.
Packit 4e910c
AC_DEFUN([PKG_PROG_PKG_CONFIG],
Packit 4e910c
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
Packit 4e910c
m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
Packit 4e910c
m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
Packit 4e910c
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
Packit 4e910c
AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
Packit 4e910c
AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
Packit 4e910c
Packit 4e910c
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
Packit 4e910c
	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
Packit 4e910c
fi
Packit 4e910c
if test -n "$PKG_CONFIG"; then
Packit 4e910c
	_pkg_min_version=m4_default([$1], [0.9.0])
Packit 4e910c
	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
Packit 4e910c
	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
Packit 4e910c
		AC_MSG_RESULT([yes])
Packit 4e910c
	else
Packit 4e910c
		AC_MSG_RESULT([no])
Packit 4e910c
		PKG_CONFIG=""
Packit 4e910c
	fi
Packit 4e910c
fi[]dnl
Packit 4e910c
])dnl PKG_PROG_PKG_CONFIG
Packit 4e910c
Packit 4e910c
dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
Packit 4e910c
dnl -------------------------------------------------------------------
Packit 4e910c
dnl Since: 0.18
Packit 4e910c
dnl
Packit 4e910c
dnl Check to see whether a particular set of modules exists. Similar to
Packit 4e910c
dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
Packit 4e910c
dnl
Packit 4e910c
dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
Packit 4e910c
dnl only at the first occurence in configure.ac, so if the first place
Packit 4e910c
dnl it's called might be skipped (such as if it is within an "if", you
Packit 4e910c
dnl have to call PKG_CHECK_EXISTS manually
Packit 4e910c
AC_DEFUN([PKG_CHECK_EXISTS],
Packit 4e910c
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
Packit 4e910c
if test -n "$PKG_CONFIG" && \
Packit 4e910c
    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
Packit 4e910c
  m4_default([$2], [:])
Packit 4e910c
m4_ifvaln([$3], [else
Packit 4e910c
  $3])dnl
Packit 4e910c
fi])
Packit 4e910c
Packit 4e910c
dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
Packit 4e910c
dnl ---------------------------------------------
Packit 4e910c
dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
Packit 4e910c
dnl pkg_failed based on the result.
Packit 4e910c
m4_define([_PKG_CONFIG],
Packit 4e910c
[if test -n "$$1"; then
Packit 4e910c
    pkg_cv_[]$1="$$1"
Packit 4e910c
 elif test -n "$PKG_CONFIG"; then
Packit 4e910c
    PKG_CHECK_EXISTS([$3],
Packit 4e910c
                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
Packit 4e910c
		      test "x$?" != "x0" && pkg_failed=yes ],
Packit 4e910c
		     [pkg_failed=yes])
Packit 4e910c
 else
Packit 4e910c
    pkg_failed=untried
Packit 4e910c
fi[]dnl
Packit 4e910c
])dnl _PKG_CONFIG
Packit 4e910c
Packit 4e910c
dnl _PKG_SHORT_ERRORS_SUPPORTED
Packit 4e910c
dnl ---------------------------
Packit 4e910c
dnl Internal check to see if pkg-config supports short errors.
Packit 4e910c
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
Packit 4e910c
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
Packit 4e910c
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
Packit 4e910c
        _pkg_short_errors_supported=yes
Packit 4e910c
else
Packit 4e910c
        _pkg_short_errors_supported=no
Packit 4e910c
fi[]dnl
Packit 4e910c
])dnl _PKG_SHORT_ERRORS_SUPPORTED
Packit 4e910c
Packit 4e910c
Packit 4e910c
dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
Packit 4e910c
dnl   [ACTION-IF-NOT-FOUND])
Packit 4e910c
dnl --------------------------------------------------------------
Packit 4e910c
dnl Since: 0.4.0
Packit 4e910c
dnl
Packit 4e910c
dnl Note that if there is a possibility the first call to
Packit 4e910c
dnl PKG_CHECK_MODULES might not happen, you should be sure to include an
Packit 4e910c
dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
Packit 4e910c
AC_DEFUN([PKG_CHECK_MODULES],
Packit 4e910c
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
Packit 4e910c
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
Packit 4e910c
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
Packit 4e910c
Packit 4e910c
pkg_failed=no
Packit 4e910c
AC_MSG_CHECKING([for $1])
Packit 4e910c
Packit 4e910c
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
Packit 4e910c
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
Packit 4e910c
Packit 4e910c
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
Packit 4e910c
and $1[]_LIBS to avoid the need to call pkg-config.
Packit 4e910c
See the pkg-config man page for more details.])
Packit 4e910c
Packit 4e910c
if test $pkg_failed = yes; then
Packit 4e910c
   	AC_MSG_RESULT([no])
Packit 4e910c
        _PKG_SHORT_ERRORS_SUPPORTED
Packit 4e910c
        if test $_pkg_short_errors_supported = yes; then
Packit 4e910c
	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
Packit 4e910c
        else 
Packit 4e910c
	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
Packit 4e910c
        fi
Packit 4e910c
	# Put the nasty error message in config.log where it belongs
Packit 4e910c
	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
Packit 4e910c
Packit 4e910c
	m4_default([$4], [AC_MSG_ERROR(
Packit 4e910c
[Package requirements ($2) were not met:
Packit 4e910c
Packit 4e910c
$$1_PKG_ERRORS
Packit 4e910c
Packit 4e910c
Consider adjusting the PKG_CONFIG_PATH environment variable if you
Packit 4e910c
installed software in a non-standard prefix.
Packit 4e910c
Packit 4e910c
_PKG_TEXT])[]dnl
Packit 4e910c
        ])
Packit 4e910c
elif test $pkg_failed = untried; then
Packit 4e910c
     	AC_MSG_RESULT([no])
Packit 4e910c
	m4_default([$4], [AC_MSG_FAILURE(
Packit 4e910c
[The pkg-config script could not be found or is too old.  Make sure it
Packit 4e910c
is in your PATH or set the PKG_CONFIG environment variable to the full
Packit 4e910c
path to pkg-config.
Packit 4e910c
Packit 4e910c
_PKG_TEXT
Packit 4e910c
Packit 4e910c
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
Packit 4e910c
        ])
Packit 4e910c
else
Packit 4e910c
	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
Packit 4e910c
	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
Packit 4e910c
        AC_MSG_RESULT([yes])
Packit 4e910c
	$3
Packit 4e910c
fi[]dnl
Packit 4e910c
])dnl PKG_CHECK_MODULES
Packit 4e910c
Packit 4e910c
Packit 4e910c
dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
Packit 4e910c
dnl   [ACTION-IF-NOT-FOUND])
Packit 4e910c
dnl ---------------------------------------------------------------------
Packit 4e910c
dnl Since: 0.29
Packit 4e910c
dnl
Packit 4e910c
dnl Checks for existence of MODULES and gathers its build flags with
Packit 4e910c
dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
Packit 4e910c
dnl and VARIABLE-PREFIX_LIBS from --libs.
Packit 4e910c
dnl
Packit 4e910c
dnl Note that if there is a possibility the first call to
Packit 4e910c
dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to
Packit 4e910c
dnl include an explicit call to PKG_PROG_PKG_CONFIG in your
Packit 4e910c
dnl configure.ac.
Packit 4e910c
AC_DEFUN([PKG_CHECK_MODULES_STATIC],
Packit 4e910c
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
Packit 4e910c
_save_PKG_CONFIG=$PKG_CONFIG
Packit 4e910c
PKG_CONFIG="$PKG_CONFIG --static"
Packit 4e910c
PKG_CHECK_MODULES($@)
Packit 4e910c
PKG_CONFIG=$_save_PKG_CONFIG[]dnl
Packit 4e910c
])dnl PKG_CHECK_MODULES_STATIC
Packit 4e910c
Packit 4e910c
Packit 4e910c
dnl PKG_INSTALLDIR([DIRECTORY])
Packit 4e910c
dnl -------------------------
Packit 4e910c
dnl Since: 0.27
Packit 4e910c
dnl
Packit 4e910c
dnl Substitutes the variable pkgconfigdir as the location where a module
Packit 4e910c
dnl should install pkg-config .pc files. By default the directory is
Packit 4e910c
dnl $libdir/pkgconfig, but the default can be changed by passing
Packit 4e910c
dnl DIRECTORY. The user can override through the --with-pkgconfigdir
Packit 4e910c
dnl parameter.
Packit 4e910c
AC_DEFUN([PKG_INSTALLDIR],
Packit 4e910c
[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
Packit 4e910c
m4_pushdef([pkg_description],
Packit 4e910c
    [pkg-config installation directory @<:@]pkg_default[@:>@])
Packit 4e910c
AC_ARG_WITH([pkgconfigdir],
Packit 4e910c
    [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
Packit 4e910c
    [with_pkgconfigdir=]pkg_default)
Packit 4e910c
AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
Packit 4e910c
m4_popdef([pkg_default])
Packit 4e910c
m4_popdef([pkg_description])
Packit 4e910c
])dnl PKG_INSTALLDIR
Packit 4e910c
Packit 4e910c
Packit 4e910c
dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
Packit 4e910c
dnl --------------------------------
Packit 4e910c
dnl Since: 0.27
Packit 4e910c
dnl
Packit 4e910c
dnl Substitutes the variable noarch_pkgconfigdir as the location where a
Packit 4e910c
dnl module should install arch-independent pkg-config .pc files. By
Packit 4e910c
dnl default the directory is $datadir/pkgconfig, but the default can be
Packit 4e910c
dnl changed by passing DIRECTORY. The user can override through the
Packit 4e910c
dnl --with-noarch-pkgconfigdir parameter.
Packit 4e910c
AC_DEFUN([PKG_NOARCH_INSTALLDIR],
Packit 4e910c
[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
Packit 4e910c
m4_pushdef([pkg_description],
Packit 4e910c
    [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
Packit 4e910c
AC_ARG_WITH([noarch-pkgconfigdir],
Packit 4e910c
    [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
Packit 4e910c
    [with_noarch_pkgconfigdir=]pkg_default)
Packit 4e910c
AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
Packit 4e910c
m4_popdef([pkg_default])
Packit 4e910c
m4_popdef([pkg_description])
Packit 4e910c
])dnl PKG_NOARCH_INSTALLDIR
Packit 4e910c
Packit 4e910c
Packit 4e910c
dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
Packit 4e910c
dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
Packit 4e910c
dnl -------------------------------------------
Packit 4e910c
dnl Since: 0.28
Packit 4e910c
dnl
Packit 4e910c
dnl Retrieves the value of the pkg-config variable for the given module.
Packit 4e910c
AC_DEFUN([PKG_CHECK_VAR],
Packit 4e910c
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
Packit 4e910c
AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
Packit 4e910c
Packit 4e910c
_PKG_CONFIG([$1], [variable="][$3]["], [$2])
Packit 4e910c
AS_VAR_COPY([$1], [pkg_cv_][$1])
Packit 4e910c
Packit 4e910c
AS_VAR_IF([$1], [""], [$5], [$4])dnl
Packit 4e910c
])dnl PKG_CHECK_VAR