From: Nick Bowler Date: Thu, 11 Feb 2010 00:08:25 +0000 (-0500) Subject: build: Implement a better GTK+ detection macro. X-Git-Url: http://git.draconx.ca/gitweb/liblbx.git/commitdiff_plain/7ac7ae8d08541f9d91f07bd3b7f91e9fa201b683 build: Implement a better GTK+ detection macro. 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. --- diff --git a/configure.ac b/configure.ac index f772576..d798674 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 0000000..d10b0c3 --- /dev/null +++ b/m4/gtk2.m4 @@ -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 +#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 +])