1 dnl Copyright (C) 2010 Vincent Torri <vtorri at univ-evry dot fr>
2 dnl That code is public domain and can be freely used or copied.
4 dnl Macro that check if several pthread library is available or not.
6 dnl Usage: EFL_CHECK_PTHREAD(want_pthread_spin[, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
7 dnl Call AC_SUBST(EFL_PTHREAD_CFLAGS)
8 dnl Call AC_SUBST(EFL_PTHREAD_LIBS)
9 dnl Define EFL_HAVE_PTHREAD
10 dnl Define EFL_HAVE_PTHREAD_SPINLOCK
12 AC_DEFUN([EFL_CHECK_PTHREAD],
17 AC_ARG_ENABLE([pthread],
18 [AC_HELP_STRING([--disable-pthread], [enable POSIX threads code @<:@default=auto@:>@])],
20 if test "x${enableval}" = "xyes" ; then
21 _efl_enable_pthread="yes"
23 _efl_enable_pthread="no"
26 [_efl_enable_pthread="auto"])
28 AC_MSG_CHECKING([whether to build POSIX threads code])
29 AC_MSG_RESULT([${_efl_enable_pthread}])
31 dnl check if the compiler supports pthreads
35 _efl_pthread_cflags=""
36 _efl_pthread_libs="-lpthreadGC2"
39 _efl_pthread_cflags="-mt"
40 _efl_pthread_libs="-mt"
43 _efl_pthread_cflags="-pthread"
44 _efl_pthread_libs="-pthread"
48 _efl_have_pthread="no"
50 if test "x${_efl_enable_pthread}" = "xyes" || test "x${_efl_enable_pthread}" = "xauto" ; then
53 CFLAGS="${CFLAGS} ${_efl_pthread_cflags}"
55 LIBS="${LIBS} ${_efl_pthread_libs}"
64 [_efl_have_pthread="yes"],
65 [_efl_have_pthread="no"])
71 AC_MSG_CHECKING([whether system support POSIX threads])
72 AC_MSG_RESULT([${_efl_have_pthread}])
73 if test "$x{_efl_enable_pthread}" = "xyes" && test "x${_efl_have_pthread}" = "xno"; then
74 AC_MSG_ERROR([pthread support requested but not found.])
79 if test "x${_efl_have_pthread}" = "xyes" ; then
80 EFL_PTHREAD_CFLAGS=${_efl_pthread_cflags}
81 EFL_PTHREAD_LIBS=${_efl_pthread_libs}
84 AC_SUBST(EFL_PTHREAD_CFLAGS)
85 AC_SUBST(EFL_PTHREAD_LIBS)
87 if test "x${_efl_have_pthread}" = "xyes" ; then
88 AC_DEFINE(EFL_HAVE_PTHREAD, 1, [Define to mention that POSIX threads are supported])
91 dnl check if the compiler supports pthreads spinlock
93 _efl_have_pthread_spinlock="no"
95 if test "x${_efl_have_pthread}" = "xyes" && test "x$1" = "xyes" ; then
98 CFLAGS="${CFLAGS} ${EFL_PTHREAD_CFLAGS}"
100 LIBS="${LIBS} ${EFL_PTHREAD_LIBS}"
106 pthread_spinlock_t lock;
108 res = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
110 [_efl_have_pthread_spinlock="yes"],
111 [_efl_have_pthread_spinlock="no"])
112 CFLAGS=${SAVE_CFLAGS}
117 AC_MSG_CHECKING([whether to build POSIX threads spinlock code])
118 AC_MSG_RESULT([${_efl_have_pthread_spinlock}])
119 if test "x${_efl_enable_pthread}" = "xyes" && test "x${_efl_have_pthread_spinlock}" = "xno" && test "x$1" = "xyes" ; then
120 AC_MSG_WARN([pthread support requested but spinlocks are not supported])
123 if test "x${_efl_have_pthread_spinlock}" = "xyes" ; then
124 AC_DEFINE(EFL_HAVE_PTHREAD_SPINLOCK, 1, [Define to mention that POSIX threads spinlocks are supported])
127 AS_IF([test "x$_efl_have_pthread" = "xyes"], [$2], [$3])
128 AS_IF([test "x$_efl_have_pthread_spinlock" = "xyes"], [$4], [$5])