$NetBSD: patch-ak,v 1.13 2012/10/06 20:44:05 prlw1 Exp $

--- configure.ac.orig	2012-09-25 07:35:55.000000000 +0000
+++ configure.ac
@@ -864,7 +864,7 @@ int main (int argc, char **argv)
 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 visibility])
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#if defined(__SUNPRO_C) || (__SUNPRO_C >= 0x550)
 #else
 # include "error: this is not Sun Studio."
@@ -1115,10 +1115,22 @@ AC_CHECK_TYPE([struct ip_mreqn], [
 
 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
@@ -1477,11 +1489,12 @@ if test x"$glib_native_win32" = xyes; th
   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
@@ -1542,13 +1555,13 @@ AS_IF([ test "$G_MODULE_IMPL" = "G_MODUL
 	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 --tag=CC ${CC} ${CFLAGS} \
+	${SHELL} libtool --mode=compile --tag=CC ${CC} ${CFLAGS} \
 		${CPPFLAGS} -c -o plugin.lo plugin.c >/dev/null 2>&1
-	${SHELL} ./libtool --mode=link --tag=CC ${CC} ${CFLAGS} \
+	${SHELL} libtool --mode=link --tag=CC ${CC} ${CFLAGS} \
 		${LDFLAGS} -module -o plugin.la -export-dynamic \
 		-shrext ".o" -avoid-version plugin.lo \
 		-rpath /dont/care >/dev/null 2>&1
-	eval `./libtool --config | grep ^objdir`
+	eval `libtool --config | grep ^objdir`
 	AC_CACHE_CHECK([for RTLD_GLOBAL brokenness],
 		glib_cv_rtldglobal_broken,[
 		AC_TRY_RUN([
@@ -1611,6 +1624,38 @@ dnl *** check for having dlerror()
 		[G_MODULE_HAVE_DLERROR=0])
 	LIBS="$LIBS_orig"
 ])
+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
@@ -1621,7 +1666,7 @@ fi
 
 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
@@ -1640,6 +1685,7 @@ AC_SUBST(G_MODULE_PLUGIN_LIBS)
 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)
 
@@ -2010,22 +2056,8 @@ AS_IF([ test x"$have_threads" = xposix],
       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([AC_LANG_SOURCE(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
 ])
@@ -2311,6 +2343,7 @@ case $host in
     ;;
   *-*-openbsd*)
     LDFLAGS="$LDFLAGS -pthread"
+    G_THREAD_LIBS_FOR_GTHREAD="$G_THREAD_LIBS"
     ;;
   *)
     G_THREAD_LIBS_FOR_GTHREAD="$G_THREAD_LIBS"
