Blame m4/pkg.m4

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