Try harder to find suitable flags for pthreads.
authorM Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
Fri, 9 Jul 2010 09:07:35 +0000 (12:07 +0300)
committerM Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
Wed, 21 Jul 2010 20:52:22 +0000 (23:52 +0300)
The flags -D_REENTRANT -lpthread work on more systems than
does -pthread unfortunately, so give that a go too.

configure.ac
pixman/Makefile.am

index 56a6e4d..b9488d9 100644 (file)
@@ -527,12 +527,12 @@ dnl Thread local storage
 support_for__thread=no
 
 AC_MSG_CHECKING(for __thread)
-AC_COMPILE_IFELSE([
+AC_LINK_IFELSE([
 #ifdef __MINGW32__
 #error MinGW has broken __thread support
 #endif
-__thread int x ;
-int main () { return 0; }
+static __thread int x ;
+int main () { x = 123; return x; }
 ], support_for__thread=yes)
 
 if test $support_for__thread = yes; then 
@@ -541,21 +541,11 @@ fi
 
 AC_MSG_RESULT($support_for__thread)
 
+dnl
 dnl posix tls
+dnl
 
-if test $support_for__thread = no; then
-
-support_for_pthread_setspecific=no
-   
-AC_MSG_CHECKING(for pthread_setspecific)
-
-save_LDFLAGS=$LDFLAGS
-
-LDFLAGS="-pthread"
-
-AC_LINK_IFELSE([
-#include <pthread.h>
-
+m4_define([pthread_test_program],[dnl
 #include <stdlib.h>
 #include <pthread.h>
 
@@ -572,7 +562,7 @@ int
 main ()
 {
     void *value = NULL;
-    
+
     if (pthread_once (&once_control, make_key) != 0)
     {
        value = NULL;
@@ -586,23 +576,50 @@ main ()
            pthread_setspecific (key, value);
        }
     }
+    return 0;
 }
-], support_for_pthread_setspecific=yes);
+])
+
+AC_DEFUN([PIXMAN_CHECK_PTHREAD],[dnl
+    if test "z$support_for_pthread_setspecific" != "zyes"; then
+       save_CFLAGS="$CFLAGS"
+       save_LDFLAGS="$LDFLAGS"
+       save_LIBS="$LIBS"
+       CFLAGS=""
+       LDFLAGS=""
+       LIBS=""
+       $1
+       AC_LINK_IFELSE([pthread_test_program],
+               [PTHREAD_CFLAGS="$CFLAGS"
+                PTHREAD_LIBS="$LIBS"
+                PTHREAD_LDFLAGS="$LDFLAGS"
+                support_for_pthread_setspecific=yes])
+       CFLAGS="$save_CFLAGS"
+       LDFLAGS="$save_LDFLAGS"
+       LIBS="$save_LIBS"
+    fi
+])
+
+if test $support_for__thread = no; then
+    support_for_pthread_setspecific=no
 
-LDFLAGS=$save_LDFLAGS
+    AC_MSG_CHECKING(for pthread_setspecific)
 
-if test $support_for_pthread_setspecific = yes; then
-   PTHREAD_LDFLAGS="-pthread"
-   AC_DEFINE([HAVE_PTHREAD_SETSPECIFIC], [], [Whether pthread_setspecific() is supported])
-fi
+    PIXMAN_CHECK_PTHREAD([CFLAGS="-D_REENTRANT"; LIBS="-lpthread"])
+    PIXMAN_CHECK_PTHREAD([CFLAGS="-pthread"; LDFLAGS="-pthread"])
 
-AC_MSG_RESULT($support_for_pthread_setspecific);
+    if test $support_for_pthread_setspecific = yes; then
+       CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+       AC_DEFINE([HAVE_PTHREAD_SETSPECIFIC], [], [Whether pthread_setspecific() is supported])
+    fi
 
+    AC_MSG_RESULT($support_for_pthread_setspecific);
 fi
 
 AC_SUBST(TOOLCHAIN_SUPPORTS__THREAD)
 AC_SUBST(HAVE_PTHREAD_SETSPECIFIC)
 AC_SUBST(PTHREAD_LDFLAGS)
+AC_SUBST(PTHREAD_LIBS)
 
 AC_OUTPUT([pixman-1.pc
            pixman-1-uninstalled.pc
index 66ad7f0..7538219 100644 (file)
@@ -1,6 +1,6 @@
 lib_LTLIBRARIES = libpixman-1.la
 libpixman_1_la_LDFLAGS = -version-info $(LT_VERSION_INFO) -no-undefined @PTHREAD_LDFLAGS@ 
-libpixman_1_la_LIBADD = @DEP_LIBS@ -lm
+libpixman_1_la_LIBADD = @PTHREAD_LIBS@ @DEP_LIBS@ -lm
 libpixman_1_la_SOURCES =                       \
        pixman.h                                \
        pixman-accessor.h                       \