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