$NetBSD: patch-ak,v 1.21 2018/10/08 10:12:06 prlw1 Exp $

- solaris sun studio check and fix
- use pkgsrc libtool

--- configure.ac.orig	2017-06-22 13:15:19.000000000 +0000
+++ configure.ac
@@ -687,7 +687,7 @@ int main (void)
 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."
@@ -1040,10 +1040,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
@@ -1427,9 +1440,9 @@ 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
@@ -1919,22 +1965,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
 ])
