$NetBSD: patch-ak,v 1.5 2009/11/22 16:51:17 sno Exp $

--- configure.in.orig	2009-10-07 15:29:47.000000000 +0200
+++ configure.in	2009-11-22 15:18:00.124347084 +0100
@@ -835,7 +835,7 @@
 AC_MSG_RESULT($g_have_gnuc_visibility)
 AM_CONDITIONAL(HAVE_GNUC_VISIBILITY, [test x$g_have_gnuc_visibility = xyes])
 
-AC_MSG_CHECKING([whether using Sun Studio C compiler])
+AC_MSG_CHECKING([whether using Sun Studio C compiler visibilily])
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#if defined(__SUNPRO_C) || (__SUNPRO_C >= 0x550)
 #else
 # include "error: this is not Sun Studio."
@@ -1023,10 +1023,22 @@
 
 case $host in
   *-*-solaris* )
-     AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, Needed to get declarations for msg_control and msg_controllen on Solaris)
-     AC_DEFINE(_XOPEN_SOURCE,          2, Needed to get declarations for msg_control and msg_controllen on Solaris)
-     AC_DEFINE(__EXTENSIONS__,         1, Needed to get declarations for msg_control and msg_controllen on Solaris)
-     ;;
+    AC_MSG_CHECKING([whether using Sun Studio C compiler with C99])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#if defined(__STDC_VERSION__) || (__STDC_VERSION__ - 0 >= 199901L)
+#else
+# include "error: this is STD C99."
+#endif
+    ]], [[]])], [ g_have_sunstudio_c99=yes ], [ g_have_sunstudio_c99=no ])
+    AC_MSG_RESULT($g_have_sunstudio_c99)
+    if test $g_have_sunstudio_c99 = yes; then
+      AC_DEFINE(_XOPEN_SOURCE,          600, Needed to get declarations for msg_control and msg_controllen on Solaris)
+    else
+      AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, Needed to get declarations for msg_control and msg_controllen on Solaris)
+      AC_DEFINE(_XOPEN_SOURCE,          2, Needed to get declarations for msg_control and msg_controllen on Solaris)
+    fi
+
+    AC_DEFINE(__EXTENSIONS__,         1, Needed to get declarations for msg_control and msg_controllen on Solaris)
+    ;;
 esac
 
 dnl
@@ -1379,11 +1391,12 @@
   G_MODULE_LDFLAGS=
 else
   export SED
-  G_MODULE_LDFLAGS=`(./libtool --config; echo eval echo \\$export_dynamic_flag_spec) | sh`
+  G_MODULE_LDFLAGS=`(libtool --config; echo eval echo \\$export_dynamic_flag_spec) | sh`
 fi
 dnl G_MODULE_IMPL= don't reset, so cmd-line can override
 G_MODULE_NEED_USCORE=0
 G_MODULE_BROKEN_RTLD_GLOBAL=0
+G_MODULE_BROKEN_DLOPEN_NULL=0
 G_MODULE_HAVE_DLERROR=0
 dnl *** force native WIN32 shared lib loader 
 if test -z "$G_MODULE_IMPL"; then
@@ -1444,7 +1457,7 @@
 	LDFLAGS="$LDFLAGS $G_MODULE_LDFLAGS"
 dnl *** check for OSF1/5.0 RTLD_GLOBAL brokenness
 	echo "void glib_plugin_test(void) { }" > plugin.c
-	${SHELL} ./libtool --mode=compile ${CC} -shared \
+	${SHELL} libtool --mode=compile ${CC} -shared \
 		-export-dynamic -o plugin.o plugin.c 2>&1 >/dev/null
 	AC_CACHE_CHECK([for RTLD_GLOBAL brokenness],
 		glib_cv_rtldglobal_broken,[
@@ -1508,6 +1521,38 @@
 		[G_MODULE_HAVE_DLERROR=0])
 	LIBS="$LIBS_orig"
 fi
+dnl *** check for dlopen(NULL, 0) brokenness
+	AC_CACHE_CHECK([for dlopen(NULL, 0) brokenness],
+		glib_cv_dlopennull_broken,[
+		AC_TRY_RUN([
+#include <stdio.h>
+#include <dlfcn.h>
+#ifndef RTLD_GLOBAL
+#  define RTLD_GLOBAL 0
+#endif
+#ifndef RTLD_LAZY
+#  define RTLD_LAZY 0
+#endif
+int gettext;
+int main () {
+    void *handle;
+    handle = dlopen ("libm.so", RTLD_GLOBAL | RTLD_LAZY);
+    if (!handle) return 0;
+    handle = dlopen (NULL, 0);
+    if (!handle) return 0;
+    handle = dlsym (handle, "sin");
+    return handle == NULL;
+}
+		],
+		[glib_cv_dlopennull_broken=no],
+		[glib_cv_dlopennull_broken=yes],
+		[glib_cv_dlopennull_broken=no])
+	])
+	if test "x$glib_cv_dlopennull_broken" = "xyes"; then
+		G_MODULE_BROKEN_DLOPEN_NULL=1
+	else
+		G_MODULE_BROKEN_DLOPEN_NULL=0
+	fi
 dnl *** done, have we got an implementation?
 if test -z "$G_MODULE_IMPL"; then
 	G_MODULE_IMPL=0
@@ -1518,7 +1563,7 @@
 
 AC_MSG_CHECKING(for the suffix of module shared libraries)
 export SED
-shrext_cmds=`./libtool --config | grep '^shrext_cmds='`
+shrext_cmds=`libtool --config | grep '^shrext_cmds='`
 eval $shrext_cmds
 module=yes eval std_shrext=$shrext_cmds
 # chop the initial dot
@@ -1537,6 +1582,8 @@
 AC_SUBST(G_MODULE_LDFLAGS)
 AC_SUBST(G_MODULE_HAVE_DLERROR)
 AC_SUBST(G_MODULE_BROKEN_RTLD_GLOBAL)
+AC_SUBST(G_MODULE_BROKEN_DLOPEN_NULL)
+
 AC_SUBST(G_MODULE_NEED_USCORE)
 AC_SUBST(GLIB_DEBUG_FLAGS)
 
@@ -1925,22 +1972,8 @@
         G_THREAD_LIBS="-lpthread -lthread"
         ;;
       *)
-        for flag in pthread pthreads mt; do
-          glib_save_CFLAGS="$CFLAGS"
-          CFLAGS="$CFLAGS -$flag"
-          AC_TRY_RUN(glib_thread_test(0),
-                     glib_flag_works=yes,
-                     glib_flag_works=no,
-                     [AC_LINK_IFELSE(glib_thread_test(0),
-                                     glib_flag_works=yes,
-                                     glib_flag_works=no)])
-          CFLAGS="$glib_save_CFLAGS"
-          if test $glib_flag_works = yes ; then
-             G_THREAD_CFLAGS=-$flag
-	     G_THREAD_LIBS=-$flag
-	     break;
-          fi
-        done
+	G_THREAD_LIBS="${PTHREAD_LDFLAGS} ${PTHREAD_LIBS}"
+	G_THREAD_CFLAGS="${PTHREAD_CFLAGS}"
          ;;
     esac 
   fi
@@ -2336,6 +2369,10 @@
   *) 	 
     G_THREAD_LIBS_FOR_GTHREAD="$G_THREAD_LIBS" 	 
     ;;
+  *-*-netbsd*)
+    # On NetBSD, pkgsrc's libtool does the right thing.
+    G_THREAD_LIBS_FOR_GTHREAD="$G_THREAD_LIBS"
+    ;;
 esac
 
 AC_DEFINE_UNQUOTED(G_THREAD_SOURCE,"gthread-$have_threads.c",
