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.
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"`
15 AC_CACHE_CHECK([for glib version at least $1],
16 [glib_cv_sufficient_ver],
17 [AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
19 #if !GLIB_CHECK_VERSION($glib_min_major,$glib_min_minor,$glib_min_release)
20 # error Insufficient glib version
24 ])], [glib_cv_sufficient_ver=yes], [glib_cv_sufficient_ver=no])])
27 dnl _GLIB_MODULE([module-name], [module-list])
28 AC_DEFUN([_GLIB_MODULE], [ifelse(m4_bregexp([$2], [\(^\| \)$1\( \|$\)]), [-1],
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])
36 ifelse([$1], [gobject], [dnl
37 m4_append([_GLIB_INCLUDES], [dnl
38 #include <glib-object.h>], [
40 m4_append([_GLIB_MAIN], [dnl
42 { GObject *obj = g_object_new(G_TYPE_OBJECT, NULL); }], [
46 ifelse([$1], [gthread], [dnl
47 m4_append([_GLIB_MAIN], [dnl
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
62 if test x"$LIB[]m4_toupper([$1])_CFLAGS" = x; then
63 LIB[]m4_toupper([$1])_CFLAGS=$pkg_cv_lib$1_cflags
65 if test x"$LIB[]m4_toupper([$1])_LIBS" = x; then
66 LIB[]m4_toupper([$1])_LIBS=$pkg_cv_lib$1_libs
73 GLIB_CFLAGS="$GLIB_CFLAGS $LIB[]m4_toupper([$1])_CFLAGS"
74 GLIB_LIBS="$GLIB_LIBS $LIB[]m4_toupper([$1])_LIBS"
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
82 m4_define([_GLIB_INCLUDES], [#include <glib.h>])
83 m4_define([_GLIB_MAIN], [const char *ver = glib_check_version(2,0,0);])
88 _GLIB_MODULE([glib], [glib])
89 _GLIB_MODULE([gobject], [$2])
90 _GLIB_MODULE([gthread], [$2])
95 CFLAGS="$GLIB_CFLAGS $CFLAGS"
96 LIBS="$GLIB_LIBS $LIBS"
98 _GLIB_TRY_VERSION(ifelse([$1], [], [2.0], [$1]))
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])
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.
113 If libglib is installed but was not found by this configure script,
114 consider adjusting LIBGLIB_CFLAGS and/or LIBGLIB_LIBS as necessary.
116 If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH
117 if libglib is installed in a non-standard prefix.