]> git.draconx.ca Git - aspectbin.git/blob - m4/pkgvar.m4
Add an autoconf macro for dealing with pkg-config variables.
[aspectbin.git] / m4 / pkgvar.m4
1 dnl PKG_CHECK_VAR(prefix, var, desc, pkg, [action-if-ok], [action-if-fail])
2 AC_DEFUN([PKG_CHECK_VAR],
3 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
4 AC_ARG_VAR(m4_toupper([$1][_$2]), [$3, overriding pkg-config])dnl
5
6 m4_define([_PKG_VAR_TEXT], [dnl
7 Alternately, you may set the environment variable m4_toupper([$1][_$2]) to
8 avoid the need to call pkg-config.
9 See the pkg-config man page for more details.])
10
11 pkg_fail=no
12 AC_MSG_CHECKING([for $3])
13 _PKG_CONFIG([$1][_$2], [variable=$2], [$4])
14 if test -z "[$pkg_cv_$1][_$2]"; then
15         if test $pkg_failed = yes; then
16                 _PKG_SHORT_ERRORS_SUPPORTED
17                 if test $_pkg_short_errors_supported = yes; then
18                         $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$4" 2>&1`
19                 else
20                         $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$4" 2>&1`
21                 fi
22                 echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
23
24                 ifelse([$6], ,
25                         [AC_MSG_ERROR([dnl
26 Package requirements ($4) were not met:
27
28 $$1_PKG_ERRORS
29
30 Consider adjusting the PKG_CONFIG_PATH environment variable if you installed
31 software in a non-standard prefix.
32
33 _PKG_VAR_TEXT
34 ])],
35                         [AC_MSG_RESULT([unknown])
36                         $6])
37         elif test $pkg_failed = untried; then
38                 ifelse([$6], ,
39                         [AC_MSG_FAILURE([dnl
40 The pkg-config script could not be found or is too old.  Make sure it is in
41 your PATH or set the PKG_CONFIG environment variable to the full path to
42 pkg-config.
43
44 _PKG_VAR_TEXT
45
46 To get pkg-config, see <http://pkg-config.freedesktop.org/>.])],
47                         [$6])
48         else
49                 ifelse([$6], ,
50                         [AC_MSG_ERROR([dnl
51 The variable ``$2'' was not defined in the package description database for dnl
52 m4_apply([m4_car], m4_split([$4])).
53
54 Consider adjusting the PKG_CONFIG_PATH environment variable if you installed
55 software in a non-standard prefix.
56
57 _PKG_VAR_TEXT
58 ])],
59                         [AC_MSG_RESULT([unknown])
60                         $6])
61         fi
62 else
63         $1[]_$2=$pkg_cv_$1[]_$2
64         AC_MSG_RESULT([$$1][_$2])
65         ifelse([$5], , :, [$5])
66 fi
67 ])