]> git.draconx.ca Git - liblbx.git/commitdiff
build: Implement a better GTK+ detection macro.
authorNick Bowler <nbowler@draconx.ca>
Thu, 11 Feb 2010 00:08:25 +0000 (19:08 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 11 Feb 2010 04:46:58 +0000 (23:46 -0500)
This macro uses the same ideas behind the libpng detection, does not
suffer from the POSIXLY_CORRECT nonsense, doesn't duplicate checks
for pkg-config, supports caching, and properly fails when it should.

configure.ac
m4/gtk2.m4 [new file with mode: 0644]

index f772576636ddb174cad8a84cd3087a43a24882a5..d798674e891771fc9be1c4a2f804091e486dac12 100644 (file)
@@ -36,10 +36,19 @@ DX_CHECK_LIBPNG([1.2], [have_libpng=yes])
 fi
 AM_CONDITIONAL([BUILD_LBXIMG], [test x"$have_libpng" = x"yes"])
 
-# A horrible combination of bugs makes this necessary for GTK+ detection.
-unset POSIXLY_CORRECT
-
-AM_PATH_GTK_2_0([2.16.0], [have_gtk=yes], [have_gtk=no])
+AC_ARG_ENABLE([lbxgui],
+       [AS_HELP_STRING([--enable-lbxgui],
+               [build the lbxgui tool (requires GTK+) [default=auto]])],
+       [enable_lbxgui=$enableval],
+       [enable_lbxgui=auto])
+
+have_gtk=no
+if test x"$enable_lbxgui" = x"auto"; then
+DX_CHECK_GTK2([2.16], [have_gtk=yes], [have_gtk=no])
+fi
+if test x"$enable_lbxgui" = x"yes"; then
+DX_CHECK_GTK2([2.16], [have_gtk=yes])
+fi
 AM_CONDITIONAL([BUILD_LBXGUI], [test x"$have_gtk" = x"yes"])
 
 AC_CONFIG_FILES([
diff --git a/m4/gtk2.m4 b/m4/gtk2.m4
new file mode 100644 (file)
index 0000000..d10b0c3
--- /dev/null
@@ -0,0 +1,49 @@
+dnl Copyright (C) 2010 Nick Bowler
+dnl Copying and distribution of this file, with or without modification,
+dnl are permitted in any medium without royalty provided the copyright
+dnl notice and this notice are preserved.  This file is offered as-is,
+dnl without any warranty.
+
+dnl _DX_GTK2_TEST_PROGRAM(major, minor, micro)
+AC_DEFUN([_DX_GTK2_TEST_PROGRAM], [AC_LANG_PROGRAM([dnl
+#include <gtk/gtk.h>
+#if !GTK_CHECK_VERSION( \
+       ifelse([$1], [], [2], [$1]), \
+       ifelse([$2], [], [0], [$2]), \
+       ifelse([$3], [], [0], [$3]))
+#  error Insufficient GTK version
+#endif
+], [dnl
+int argc = 0;
+char *argv[] = {NULL};
+gtk_init(&argc, &argv);
+gtk_main();
+])])
+
+dnl DX_CHECK_GTK2([min-version], [action-if-ok], [action-if-fail])
+AC_DEFUN([DX_CHECK_GTK2],
+[DX_PKG_CONFIG([gtk], [gtk+-2.0], [GTK+])
+
+DX_CHECK_LIB([gtk],
+       [for GTK+ version at least ifelse([$1], [], [2.0], [$1])],
+       [m4_apply([_DX_GTK2_TEST_PROGRAM], m4_split([$1], [\.]))], [dnl
+               [[$GTK_CFLAGS], [$GTK_LIBS]],
+               [[$pkg_cv_gtk_cflags], [$pkg_cv_gtk_libs],
+                       [test ! x"$pkg_failed" = x"yes"]],
+               ])
+
+if test x"$dx_cv_gtk_found" = x"yes"; then
+       ifelse([$2], [], [:], [$2])
+else
+       ifelse([$3], [], [AC_MSG_FAILURE([dnl
+GTK+ version at least ifelse([$1], [], [2.0], [$1]) is required.  The latest
+version can be obtained from ftp://ftk.gtk.org/.
+
+If GTK+ is installed but was not found by this configure script,
+consider adjusting GTK_CFLAGS and/or GTK_LIBS as necessary.
+
+If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH
+if GTK+ is installed in a non-standard prefix.
+])], [$3])
+fi
+])