Pthread detection in glib 2.2.1



Pthread detection in glib 2.2.1 doesn't work on AIX. If using the
IBM xlc_r compiler, -pthread doesn't cause the compiler to fail so the
wrong flag is selected:
  $ xlc -c -pthread a.c
  xlc: 1501-210 command option t contains an incorrect subargument
  $ echo $?
  0

  $ xlc -c -pthreads a.c
  xlc: 1501-210 command option t contains an incorrect subargument
  $ echo $?
  0

-pthreads is detected and every compile command generates the above
warning. How about a more reliable method to detech the pthread flags?
I think the first thing to do is use the default compiler options and
then start adding to $CFLAGS or $CPPFLAGS. I've started a patch below.

-- 
albert chin (china thewrittenword com)

-- snip snip
--- configure.in.orig	Sun Feb 16 20:20:14 2003
+++ configure.in	Fri Mar  7 16:16:52 2003
@@ -1287,23 +1287,22 @@
 dnl determination of G_THREAD_CFLAGS
 dnl ********************************
 
-G_THREAD_LIBS=
-G_THREAD_LIBS_EXTRA=
-G_THREAD_CFLAGS=
-
 dnl
 dnl Test program for basic POSIX threads functionality
 dnl
 m4_define([glib_thread_test],[
 #include <pthread.h> 
 int check_me = 0;
-void* func(void* data) {return check_me = 42;}
+void* func(void* data)
+ { check_me = 42;
+   return (void *)check_me;
+}
 main()
  { pthread_t t; 
    void *ret;
    pthread_create (&t, 0, func, 0);
    pthread_join (t, &ret);
-   exit (check_me != 42 || ret != 42);
+   exit (check_me != 42 || ret != (void *)42);
 }])
 
 dnl
@@ -1325,9 +1324,9 @@
     # both CPPFLAG and LIBS. 
     # One of them does for most gcc versions and some other platforms/compilers
     # too and could be considered as the canonical way to go. 
-    for flag in pthread pthreads; do
+    for flag in "" -pthread -pthreads; do
       glib_save_CFLAGS="$CFLAGS"
-      CFLAGS="$CFLAGS -$flag"
+      CFLAGS="$CFLAGS $flag"
       AC_TRY_RUN(glib_thread_test,
                  glib_flag_works=yes,
                  glib_flag_works=no,
@@ -1336,13 +1335,14 @@
                                  glib_flag_works=no)])
       CFLAGS="$glib_save_CFLAGS"
       if test $glib_flag_works = yes ; then
-         G_THREAD_CFLAGS=-$flag
-	 G_THREAD_LIBS=-$flag
+         G_THREAD_CFLAGS=$flag
+	 G_THREAD_LIBS=$flag
+	 break
       fi
     done
   fi
 
-  if test x"$G_THREAD_CFLAGS" = x; then
+  if test ${G_THREAD_CFLAGS+set} != set; then
 
     # The canonical -pthread[s] does not work. Try something different.
 
@@ -1433,7 +1433,12 @@
               *-aix*)
                 # We are not using gcc (would have set G_THREAD_LIBS) and thus 
                 # probably using the aix compiler.
-		AC_MSG_WARN($AIX_COMPILE_INFO)
+		case "$CC" in
+		cc_r|xlc_r) ;;
+		*)
+			AC_MSG_WARN($AIX_COMPILE_INFO)
+			;;
+		esac
                 ;;
               *)
                 G_THREAD_LIBS=error



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]