]> git.draconx.ca Git - upkg.git/blob - m4/glib.m4
configure: Implement glib checking macro that actually links a test program.
[upkg.git] / m4 / glib.m4
1 dnl _GLIB_TRY_VERSION(min-version)
2 AC_DEFUN([_GLIB_TRY_VERSION], [dnl
3 sedhead='s/@<:@0-9@:>@@<:@0-9@:>@*/<<<&>>>/'
4 sedtail='s/.*<<<\(.*\)>>>.*/\1/;t;s/.*/0/'
5 glib_min_major=`printf   '%s' '$1' | sed -e "$sedhead"1 -e "$sedtail"`
6 glib_min_minor=`printf   '%s' '$1' | sed -e "$sedhead"2 -e "$sedtail"`
7 glib_min_release=`printf '%s' '$1' | sed -e "$sedhead"3 -e "$sedtail"`
8
9 AC_CACHE_CHECK([for glib version at least $1],
10         [glib_cv_sufficient_ver],
11         [AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
12 _GLIB_INCLUDES
13 #if !GLIB_CHECK_VERSION($glib_min_major,$glib_min_minor,$glib_min_release)
14 #  error Insufficient glib version
15 #endif
16 ], [dnl
17 _GLIB_MAIN
18 ])], [glib_cv_sufficient_ver=yes], [glib_cv_sufficient_ver=no])])
19 ])
20
21 dnl _GLIB_MODULE([module-name], [module-list])
22 AC_DEFUN([_GLIB_MODULE], [ifelse(m4_bregexp([$2], [\(^\| \)$1\( \|$\)]), [-1],
23 [], [dnl
24
25 AC_ARG_VAR([LIB]m4_toupper([$1])[_CFLAGS],
26         [C compiler flags for lib$1])
27 AC_ARG_VAR([LIB]m4_toupper([$1])[_LIBS],
28         [linker flags for lib$1])
29
30 ifelse([$1], [gobject], [dnl
31         m4_append([_GLIB_INCLUDES], [dnl
32 #include <glib-object.h>], [
33 ])
34         m4_append([_GLIB_MAIN], [dnl
35 g_type_init();
36 { GObject *obj = g_object_new(G_TYPE_OBJECT, NULL); }], [
37 ])
38 ])
39
40 if test x"$PKG_CONFIG" != x; then
41         AC_MSG_CHECKING([pkg-config database for $1-2.0])
42         _PKG_CONFIG([lib$1_cflags], [cflags], [$1-2.0])
43         _PKG_CONFIG([lib$1_libs],   [libs],   [$1-2.0])
44         if test x$pkg_failed = xyes; then
45                 errors=`$PKG_CONFIG --errors-to-stdout --print-errors lib$1`
46                 echo "$errors" >&AS_MESSAGE_LOG_FD
47
48                 AC_MSG_RESULT([no])
49         else
50                 if test x"$LIB[]m4_toupper([$1])_CFLAGS" = x; then
51                         LIB[]m4_toupper([$1])_CFLAGS=$pkg_cv_lib$1_cflags
52                 fi
53                 if test x"$LIB[]m4_toupper([$1])_LIBS" = x; then
54                         LIB[]m4_toupper([$1])_LIBS=$pkg_cv_lib$1_libs
55                 fi
56
57                 AC_MSG_RESULT([yes])
58         fi
59 fi
60
61 GLIB_CFLAGS="$GLIB_CFLAGS $LIB[]m4_toupper([$1])_CFLAGS"
62 GLIB_LIBS="$GLIB_LIBS $LIB[]m4_toupper([$1])_LIBS"
63
64 ])])
65
66 dnl CHECK_GLIB_2([min-version], [modules], [action-if-ok], [action-if-fail])
67 AC_DEFUN([CHECK_GLIB_2],
68 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
69
70 m4_define([_GLIB_INCLUDES], [#include <glib.h>])
71 m4_define([_GLIB_MAIN],     [const char *ver = glib_check_version(2,0,0);])
72
73 GLIB_CFLAGS=
74 GLIB_LIBS=
75
76 _GLIB_MODULE([glib], [glib])
77 _GLIB_MODULE([gobject], [$2])
78
79 AC_LANG_PUSH([C])
80 old_cflags=$CFLAGS
81 old_libs=$LIBS
82 CFLAGS="$GLIB_CFLAGS $CFLAGS"
83 LIBS="$GLIB_LIBS $LIBS"
84
85 _GLIB_TRY_VERSION(ifelse([$1], [], [2.0], [$1]))
86
87 CFLAGS=$old_cflags
88 LIBS=$old_libs
89 AC_LANG_POP([C])
90
91 if test x"$glib_cv_sufficient_ver" = x"yes"; then
92         AC_SUBST([GLIB_CFLAGS])
93         AC_SUBST([GLIB_LIBS])
94         ifelse([$3], [], [:], [$3])
95 else
96         ifelse([$4], [], [AC_MSG_FAILURE([dnl
97 glib version >= ifelse([$1], [], [2.0], [$1]) is required.  The latest
98 version can be obtained from ftp://ftp.gtk.org/pub/glib.
99
100 If libglib is installed but was not found by this configure script,
101 consider adjusting LIBGLIB_CFLAGS and/or LIBGLIB_LIBS as necessary.
102
103 If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH
104 if libglib is installed in a non-standard prefix.
105 ])], [$4])
106 fi
107 ])