summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Estienne <sebastien.estienne@gmail.com>2006-03-09 16:47:33 +0000
committerSebastien Estienne <sebastien.estienne@gmail.com>2006-03-09 16:47:33 +0000
commit65966c9895d70210b5a5ad10330a81eb3cee4b95 (patch)
treed5dde26c35241e210110ab9149ce6bce18c231e5
parent44827a94c959079400d7441f993c881e9cc71705 (diff)
* The patch was undone in svn revision 1160, adding it again and closing ticket #4
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1176 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r--common/acx_pthread.m4105
1 files changed, 105 insertions, 0 deletions
diff --git a/common/acx_pthread.m4 b/common/acx_pthread.m4
index 06af842..a96d31d 100644
--- a/common/acx_pthread.m4
+++ b/common/acx_pthread.m4
@@ -45,6 +45,10 @@ dnl @category InstalledPackages
dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
dnl @version 2005-06-15
dnl @license GPLWithACException
+dnl
+dnl Checks for GCC shared/pthread inconsistency based on work by
+dnl Marcin Owsiany <marcin@owsiany.pl>
+
AC_DEFUN([ACX_PTHREAD], [
AC_REQUIRE([AC_CANONICAL_HOST])
@@ -218,6 +222,107 @@ if test "x$acx_pthread_ok" = xyes; then
# More AIX lossage: must compile with cc_r
AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
+
+ # The next part tries to detect GCC inconsistency with -shared on some
+ # architectures and systems. The problem is that in certain
+ # configurations, when -shared is specified, GCC "forgets" to
+ # internally use various flags which are still necessary.
+
+ # First, check whether caller wants us to skip -shared checks
+ # this is useful
+ AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies])
+ if test x"$3" = x1; then
+ AC_MSG_RESULT([no])
+ else
+ AC_MSG_RESULT([yes])
+
+ # In order not to create several levels of indentation, we test
+ # the value of "$ok" until we find out the cure or run out of
+ # ideas.
+ ok="no"
+
+ #
+ # Prepare the flags
+ #
+ save_CFLAGS="$CFLAGS"
+ save_LIBS="$LIBS"
+ save_CC="$CC"
+ # Try with the flags determined by the earlier checks.
+ #
+ # -Wl,-z,defs forces link-time symbol resolution, so that the
+ # linking checks with -shared actually have any value
+ #
+ # FIXME: -fPIC is required for -shared on many architectures,
+ # so we specify it here, but the right way would probably be to
+ # properly detect whether it is actually required.
+ CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ CC="$PTHREAD_CC"
+
+ AC_MSG_CHECKING([whether -pthread is sufficient with -shared])
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [ok=yes])
+
+ if test "x$ok" = xyes; then
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ fi
+
+ #
+ # Linux gcc on some architectures such as mips/mipsel forgets
+ # about -lpthread
+ #
+ if test x"$ok" = xno; then
+ AC_MSG_CHECKING([whether -lpthread fixes that])
+ LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [ok=yes])
+
+ if test "x$ok" = xyes; then
+ AC_MSG_RESULT([yes])
+ PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
+ else
+ AC_MSG_RESULT([no])
+ fi
+ fi
+ #
+ # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
+ #
+ if test x"$ok" = xno; then
+ AC_MSG_CHECKING([whether -lc_r fixes that])
+ LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [ok=yes])
+
+ if test "x$ok" = xyes; then
+ AC_MSG_RESULT([yes])
+ PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
+ else
+ AC_MSG_RESULT([no])
+ fi
+ fi
+ if test x"$ok" = xno; then
+ # OK, we have run out of ideas
+ AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries])
+
+ # so it's not safe to assume that we may use pthreads
+ acx_pthread_ok=no
+ fi
+
+ CFLAGS="$save_CFLAGS"
+ LIBS="$save_LIBS"
+ CC="$save_CC"
+ fi
else
PTHREAD_CC="$CC"
fi