Improve pkg-config's configure instructure and bring it bang

Author: keybuk
Date: 2004-06-07 23:43:21 GMT
Improve pkg-config's configure instructure and bring it bang
up to date.

* pkg.m4: Complete rewrite.
(PKG_PROG_PKG_CONFIG): if PKG_CONFIG not defined, find the
pkg-config in the path or $host-pkg-config if cross-compiling,
check that is of at least version 0.9.0 or one given.
(_PKG_CONFIG): internal macro to call pkg-config.
(PKG_CHECK_MODULES): same semantics as the previous incarnation
except you can prevent pkg-config from being called by defining
xxx_CFLAGS and xxx_LIBS yourself, additionally all results are
cached.
* README, pkg-config.1: Adjust documentation to match.
This commit is contained in:
Arch Librarian 2005-07-14 13:05:59 +00:00
parent 3ab7ea98e5
commit b1584b5aaf
4 changed files with 137 additions and 72 deletions

View file

@ -1,3 +1,19 @@
2004-05-08 Scott James Remnant <scott@netsplit.com>
Improve pkg-config's configure instructure and bring it bang
up to date.
* pkg.m4: Complete rewrite.
(PKG_PROG_PKG_CONFIG): if PKG_CONFIG not defined, find the
pkg-config in the path or $host-pkg-config if cross-compiling,
check that is of at least version 0.9.0 or one given.
(_PKG_CONFIG): internal macro to call pkg-config.
(PKG_CHECK_MODULES): same semantics as the previous incarnation
except you can prevent pkg-config from being called by defining
xxx_CFLAGS and xxx_LIBS yourself, additionally all results are
cached.
* README, pkg-config.1: Adjust documentation to match.
2003-05-09 Havoc Pennington <hp@redhat.com>
* pkg.m4: improve error message a bit, from Tim Janik

16
README
View file

@ -6,20 +6,26 @@ gnome-specific but gnome.org was a convenient bug tracker).
To use pkg-config, do something like the following in your configure.in
PKG_CHECK_MODULES(GNOME, gtk > 1.2.8 gnomeui >= 1.2.0)
AC_SUBST(GNOME_CFLAGS)
AC_SUBST(GNOME_LIBS)
PKG_CHECK_MODULES([GNOME], [gtk > 1.2.8 gnomeui >= 1.2.0])
This puts the neccesary include flags to compile/link something against
libgnomeui and all its dependencies in $(GNOME_CFLAGS), and the -L/-l flags
for linking in $(GNOME_LIBS)
for linking in $(GNOME_LIBS).
Users can define the PKG_CONFIG environment variable to point at the
right one, or if they cross-compile and have a correctly named pkg-config
(eg. arm-linux-pkg-config) in their PATH that will be used in preference.
Users can also define the GNOME_CFLAGS and GNOME_LIBS environment variables
if they think they know better, pkg-config will not be called if they do
that.
The "gtk > 1.2.8" part is only neccesary if you want to specifically check
if libgtk is version 1.2.8 or higher. Otherwise, the flags for gtk
will be included automatically, since libgnomeui depends on gtk.
So you could just say:
PKG_CHECK_MODULES(GNOME, gnomeui)
PKG_CHECK_MODULES([GNOME], [gnomeui])
for any version of gnomeui.

View file

@ -252,12 +252,12 @@ files.
.SH AUTOCONF MACROS
.TP
.I "PKG_CHECK_MODULES(VARIABLEBASE,MODULELIST[,ACTION-IF-FOUND,[ACTION-IF-NOT-FOUND]])"
.I "PKG_CHECK_MODULES(VARIABLE-PREFIX,MODULES[,ACTION-IF-FOUND,[ACTION-IF-NOT-FOUND]])"
The macro PKG_CHECK_MODULES can be used in \fIconfigure.in\fP to
check whether modules exist. A typical usage would be:
.nf
PKG_CHECK_MODULES(MYSTUFF, gtk+-2.0 >= 1.3.5 libxml = 1.8.4)
PKG_CHECK_MODULES([MYSTUFF], [gtk+-2.0 >= 1.3.5 libxml = 1.8.4])
.fi
This would result in MYSTUFF_LIBS and MYSTUFF_CFLAGS substitution
@ -269,11 +269,10 @@ error messages if you specify your own ACTION-IF-NOT-FOUND.
However, it will set the variable MYSTUFF_PKG_ERRORS, which you can
use to display what went wrong.
If you want to use MYSTUFF_LIBS and MYSTUFF_CFLAGS as Makefile.am
variables (i.e. $(MYSTUFF_LIBS)) then you have to add
AC_SUBST(MYSTUFF_LIBS) to your configure.in so automake can find the
variable. You don't need to do this if you use the @MYSTUFF_LIBS@
syntax in your Makefile.am instead of $(MYSTUFF_LIBS).
.I "PKG_PROG_PKG_CONFIG([MIN-VERSION])"
Defines the PKG_CONFIG variable to the best pkg-config available,
useful if you need pkg-config but don't want to use PKG_CHECK_MODULES.
.SH METADATA FILE SYNTAX
To add a library to the set of packages \fIpkg-config\fP knows about,

164
pkg.m4
View file

@ -1,67 +1,111 @@
dnl Internal macro to check for pkg-config itself
dnl Do not call directly
AC_DEFUN([_PKG_CHECK_MODULES_FIND_PKG_CONFIG],
[
AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no])
if test "$PKG_CONFIG" = "no"; then
echo "*** The pkg-config script could not be found. Make sure it is"
echo "*** in your path, or set the PKG_CONFIG environment variable"
echo "*** to the full path to pkg-config."
echo "*** Or see http://www.freedesktop.org/software/pkgconfig/ to get pkg-config."
else
# check the pkg-config version number
PKG_CONFIG_MIN_VERSION="0.9.0"
AC_MSG_CHECKING([is pkg-config version >= $PKG_CONFIG_MIN_VERSION])
if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
PKG_CONFIG=no
echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
echo "*** See http://www.freedesktop.org/software/pkgconfig/"
fi
fi
])
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
#
# Copyright (C) 2004 Red Hat Inc.
# Written by Scott James Remnant <scott@netsplit.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
dnl PKG_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4, action-if, action-not)
dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page
dnl also defines GSTUFF_PKG_ERRORS on error
# PKG_PROG_PKG_CONFIG([MIN-VERSION])
# ----------------------------------
AC_DEFUN([PKG_PROG_PKG_CONFIG],
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
fi
if test -n "$PKG_CONFIG"; then
_pkg_min_version=m4_ifval([$1], [$1], [0.9.0])
AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
PKG_CONFIG=""
fi
fi[]dnl
])# PKG_PROG_PKG_CONFIG
# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
# ---------------------------------------------
m4_define([_PKG_CONFIG],
[if test "x$ac_cv_env_[]$1[]_set" = "xset"; then
pkg_cv_[]$1=$ac_cv_env_[]$1[]_value
elif test -n "$PKG_CONFIG"; then
if $PKG_CONFIG --exists "$3" >/dev/null 2>&1; then
pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
else
pkg_failed=yes
fi
else
pkg_failed=untried
fi[]dnl
])# _PKG_CONFIG
# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
# [ACTION-IF-NOT-FOUND])
# --------------------------------------------------------------
AC_DEFUN([PKG_CHECK_MODULES],
[
AC_REQUIRE([_PKG_CHECK_MODULES_FIND_PKG_CONFIG])dnl
succeeded=no
if test "$PKG_CONFIG" != "no" ; then
AC_MSG_CHECKING([for $2])
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1[]_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
AC_ARG_VAR([$1[]_LIBS], [linker flags for $1, overriding pkg-config])dnl
if $PKG_CONFIG --exists "$2" ; then
AC_MSG_RESULT([yes])
succeeded=yes
pkg_failed=no
AC_CACHE_CHECK([for $1[]_CFLAGS], [pkg_cv_[]$1[]_CFLAGS],
[_PKG_CONFIG([$1[]_CFLAGS], [cflags], [[$2]])])
AC_CACHE_CHECK([for $1[]_LIBS], [pkg_cv_[]$1[]_LIBS],
[_PKG_CONFIG([$1[]_LIBS], [libs], [[$2]])])
AC_MSG_CHECKING([$1_CFLAGS])
$1_CFLAGS=`$PKG_CONFIG --cflags "$2"`
AC_MSG_RESULT([$$1_CFLAGS])
if test $pkg_failed = yes; then
$1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
# Put the nasty error message in config.log where it belongs
echo "$$1[]_PKG_ERRORS" 1>&AS_MESSAGE_LOG_FD
AC_MSG_CHECKING([$1_LIBS])
$1_LIBS=`$PKG_CONFIG --libs "$2"`
AC_MSG_RESULT([$$1_LIBS])
else
$1_CFLAGS=""
$1_LIBS=""
## If we have a custom action on failure, don't print errors, but
## do set a variable so people can do so.
$1_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
ifelse([$4],, [echo $$1_PKG_ERRORS])
fi
ifelse([$4], , [AC_MSG_ERROR(dnl
[[Package requirements ($2) were not met.
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
AC_SUBST([$1_CFLAGS])
AC_SUBST([$1_LIBS])
fi
Alternatively you may set the $1_CFLAGS and $1_LIBS environment variables
to avoid the need to call pkg-config. See the pkg-config man page for
more details.]])],
[$4])
elif test $pkg_failed = untried; then
ifelse([$4], , [AC_MSG_FAILURE(dnl
[[The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config. Al
The pkg-config script could not be found or is too old.
Make sure it is in your PATH or set the PKG_CONFIG environment variable
to the full path to pkg-config.
if test $succeeded = yes; then
ifelse([$3],, [:], [$3])
else
ifelse([$4],,
[AC_MSG_ERROR([Package requirements ($2) not met; consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a nonstandard prefix. See man page for pkg-config.])],
[$4])
fi
])
Alternatively you may set the $1_CFLAGS and $1_LIBS environment variables
to avoid the need to call pkg-config. See the pkg-config man page for
more details.
To get pkg-config, see <http://www.freedesktop.org/software/pkgconfig>.]])],
[$4])
else
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
ifelse([$3], , :, [$3])
fi[]dnl
])# PKG_CHECK_MODULES