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