From: Nick Bowler Date: Sun, 19 Jul 2009 21:08:19 +0000 (-0400) Subject: configure: Implement glib checking macro that actually links a test program. X-Git-Url: https://git.draconx.ca/gitweb/upkg.git/commitdiff_plain/b0b60305e274967d5b4502c5ce1926a1699e2d3e configure: Implement glib checking macro that actually links a test program. --- diff --git a/configure.ac b/configure.ac index 42594de..16e4c65 100644 --- a/configure.ac +++ b/configure.ac @@ -18,17 +18,8 @@ AM_CONDITIONAL([BUNDLED_LIBLTDL], [test x$LTDLDEPS != x]) gl_INIT -AC_ARG_WITH([gobject], - [AS_HELP_STRING([--with-gobject], - [build tools requiring libgobject [default=yes]] - )], - [], - [with_gobject=yes]) - -have_gobject=no -if test x$with_gobject = xyes; then -AM_PATH_GLIB_2_0(, [have_gobject=yes], [have_gobject=no], [gobject]) -fi +CHECK_GLIB_2([],[gobject], [have_gobject=yes], [have_gobject=no]) +AM_CONDITIONAL([BUILD_UPKG], [test x$have_gobject = xyes]) AC_ARG_WITH([modlib], [AS_HELP_STRING([--with-modlib], @@ -69,8 +60,6 @@ AC_MSG_RESULT([$use_modlib]) AM_CONDITIONAL([USE_LIBMODPLUG], [test x$use_modlib = xmodplug]) AM_CONDITIONAL([USE_DUMMYMOD], [test x$use_modlib = xnone]) -AM_CONDITIONAL([BUILD_UPKG], [test x$have_gobject = xyes]) - AC_CONFIG_FILES([ Makefile libltdl/Makefile diff --git a/m4/glib.m4 b/m4/glib.m4 new file mode 100644 index 0000000..261c5fd --- /dev/null +++ b/m4/glib.m4 @@ -0,0 +1,107 @@ +dnl _GLIB_TRY_VERSION(min-version) +AC_DEFUN([_GLIB_TRY_VERSION], [dnl +sedhead='s/@<:@0-9@:>@@<:@0-9@:>@*/<<<&>>>/' +sedtail='s/.*<<<\(.*\)>>>.*/\1/;t;s/.*/0/' +glib_min_major=`printf '%s' '$1' | sed -e "$sedhead"1 -e "$sedtail"` +glib_min_minor=`printf '%s' '$1' | sed -e "$sedhead"2 -e "$sedtail"` +glib_min_release=`printf '%s' '$1' | sed -e "$sedhead"3 -e "$sedtail"` + +AC_CACHE_CHECK([for glib version at least $1], + [glib_cv_sufficient_ver], + [AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl +_GLIB_INCLUDES +#if !GLIB_CHECK_VERSION($glib_min_major,$glib_min_minor,$glib_min_release) +# error Insufficient glib version +#endif +], [dnl +_GLIB_MAIN +])], [glib_cv_sufficient_ver=yes], [glib_cv_sufficient_ver=no])]) +]) + +dnl _GLIB_MODULE([module-name], [module-list]) +AC_DEFUN([_GLIB_MODULE], [ifelse(m4_bregexp([$2], [\(^\| \)$1\( \|$\)]), [-1], +[], [dnl + +AC_ARG_VAR([LIB]m4_toupper([$1])[_CFLAGS], + [C compiler flags for lib$1]) +AC_ARG_VAR([LIB]m4_toupper([$1])[_LIBS], + [linker flags for lib$1]) + +ifelse([$1], [gobject], [dnl + m4_append([_GLIB_INCLUDES], [dnl +#include ], [ +]) + m4_append([_GLIB_MAIN], [dnl +g_type_init(); +{ GObject *obj = g_object_new(G_TYPE_OBJECT, NULL); }], [ +]) +]) + +if test x"$PKG_CONFIG" != x; then + AC_MSG_CHECKING([pkg-config database for $1-2.0]) + _PKG_CONFIG([lib$1_cflags], [cflags], [$1-2.0]) + _PKG_CONFIG([lib$1_libs], [libs], [$1-2.0]) + if test x$pkg_failed = xyes; then + errors=`$PKG_CONFIG --errors-to-stdout --print-errors lib$1` + echo "$errors" >&AS_MESSAGE_LOG_FD + + AC_MSG_RESULT([no]) + else + if test x"$LIB[]m4_toupper([$1])_CFLAGS" = x; then + LIB[]m4_toupper([$1])_CFLAGS=$pkg_cv_lib$1_cflags + fi + if test x"$LIB[]m4_toupper([$1])_LIBS" = x; then + LIB[]m4_toupper([$1])_LIBS=$pkg_cv_lib$1_libs + fi + + AC_MSG_RESULT([yes]) + fi +fi + +GLIB_CFLAGS="$GLIB_CFLAGS $LIB[]m4_toupper([$1])_CFLAGS" +GLIB_LIBS="$GLIB_LIBS $LIB[]m4_toupper([$1])_LIBS" + +])]) + +dnl CHECK_GLIB_2([min-version], [modules], [action-if-ok], [action-if-fail]) +AC_DEFUN([CHECK_GLIB_2], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl + +m4_define([_GLIB_INCLUDES], [#include ]) +m4_define([_GLIB_MAIN], [const char *ver = glib_check_version(2,0,0);]) + +GLIB_CFLAGS= +GLIB_LIBS= + +_GLIB_MODULE([glib], [glib]) +_GLIB_MODULE([gobject], [$2]) + +AC_LANG_PUSH([C]) +old_cflags=$CFLAGS +old_libs=$LIBS +CFLAGS="$GLIB_CFLAGS $CFLAGS" +LIBS="$GLIB_LIBS $LIBS" + +_GLIB_TRY_VERSION(ifelse([$1], [], [2.0], [$1])) + +CFLAGS=$old_cflags +LIBS=$old_libs +AC_LANG_POP([C]) + +if test x"$glib_cv_sufficient_ver" = x"yes"; then + AC_SUBST([GLIB_CFLAGS]) + AC_SUBST([GLIB_LIBS]) + ifelse([$3], [], [:], [$3]) +else + ifelse([$4], [], [AC_MSG_FAILURE([dnl +glib version >= ifelse([$1], [], [2.0], [$1]) is required. The latest +version can be obtained from ftp://ftp.gtk.org/pub/glib. + +If libglib is installed but was not found by this configure script, +consider adjusting LIBGLIB_CFLAGS and/or LIBGLIB_LIBS as necessary. + +If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH +if libglib is installed in a non-standard prefix. +])], [$4]) +fi +])