diff options
Diffstat (limited to 'libraries/evas/m4/efl_pthread.m4')
-rw-r--r-- | libraries/evas/m4/efl_pthread.m4 | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/libraries/evas/m4/efl_pthread.m4 b/libraries/evas/m4/efl_pthread.m4 new file mode 100644 index 0000000..b90a045 --- /dev/null +++ b/libraries/evas/m4/efl_pthread.m4 | |||
@@ -0,0 +1,130 @@ | |||
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. | ||
3 | |||
4 | dnl Macro that check if several pthread library is available or not. | ||
5 | |||
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 | ||
11 | |||
12 | AC_DEFUN([EFL_CHECK_PTHREAD], | ||
13 | [ | ||
14 | |||
15 | dnl configure option | ||
16 | |||
17 | AC_ARG_ENABLE([pthread], | ||
18 | [AC_HELP_STRING([--disable-pthread], [enable POSIX threads code @<:@default=auto@:>@])], | ||
19 | [ | ||
20 | if test "x${enableval}" = "xyes" ; then | ||
21 | _efl_enable_pthread="yes" | ||
22 | else | ||
23 | _efl_enable_pthread="no" | ||
24 | fi | ||
25 | ], | ||
26 | [_efl_enable_pthread="auto"]) | ||
27 | |||
28 | AC_MSG_CHECKING([whether to build POSIX threads code]) | ||
29 | AC_MSG_RESULT([${_efl_enable_pthread}]) | ||
30 | |||
31 | dnl check if the compiler supports pthreads | ||
32 | |||
33 | case "$host_os" in | ||
34 | mingw*) | ||
35 | _efl_pthread_cflags="" | ||
36 | _efl_pthread_libs="-lpthreadGC2" | ||
37 | ;; | ||
38 | solaris*) | ||
39 | _efl_pthread_cflags="-mt" | ||
40 | _efl_pthread_libs="-mt" | ||
41 | ;; | ||
42 | *) | ||
43 | _efl_pthread_cflags="-pthread" | ||
44 | _efl_pthread_libs="-pthread" | ||
45 | ;; | ||
46 | esac | ||
47 | |||
48 | _efl_have_pthread="no" | ||
49 | |||
50 | if test "x${_efl_enable_pthread}" = "xyes" || test "x${_efl_enable_pthread}" = "xauto" ; then | ||
51 | |||
52 | SAVE_CFLAGS=${CFLAGS} | ||
53 | CFLAGS="${CFLAGS} ${_efl_pthread_cflags}" | ||
54 | SAVE_LIBS=${LIBS} | ||
55 | LIBS="${LIBS} ${_efl_pthread_libs}" | ||
56 | AC_LINK_IFELSE( | ||
57 | [AC_LANG_PROGRAM([[ | ||
58 | #include <pthread.h> | ||
59 | ]], | ||
60 | [[ | ||
61 | pthread_t id; | ||
62 | id = pthread_self(); | ||
63 | ]])], | ||
64 | [_efl_have_pthread="yes"], | ||
65 | [_efl_have_pthread="no"]) | ||
66 | CFLAGS=${SAVE_CFLAGS} | ||
67 | LIBS=${SAVE_LIBS} | ||
68 | |||
69 | fi | ||
70 | |||
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.]) | ||
75 | fi | ||
76 | |||
77 | EFL_PTHREAD_CFLAGS="" | ||
78 | EFL_PTHREAD_LIBS="" | ||
79 | if test "x${_efl_have_pthread}" = "xyes" ; then | ||
80 | EFL_PTHREAD_CFLAGS=${_efl_pthread_cflags} | ||
81 | EFL_PTHREAD_LIBS=${_efl_pthread_libs} | ||
82 | fi | ||
83 | |||
84 | AC_SUBST(EFL_PTHREAD_CFLAGS) | ||
85 | AC_SUBST(EFL_PTHREAD_LIBS) | ||
86 | |||
87 | if test "x${_efl_have_pthread}" = "xyes" ; then | ||
88 | AC_DEFINE(EFL_HAVE_PTHREAD, 1, [Define to mention that POSIX threads are supported]) | ||
89 | fi | ||
90 | |||
91 | dnl check if the compiler supports pthreads spinlock | ||
92 | |||
93 | _efl_have_pthread_spinlock="no" | ||
94 | |||
95 | if test "x${_efl_have_pthread}" = "xyes" && test "x$1" = "xyes" ; then | ||
96 | |||
97 | SAVE_CFLAGS=${CFLAGS} | ||
98 | CFLAGS="${CFLAGS} ${EFL_PTHREAD_CFLAGS}" | ||
99 | SAVE_LIBS=${LIBS} | ||
100 | LIBS="${LIBS} ${EFL_PTHREAD_LIBS}" | ||
101 | AC_LINK_IFELSE( | ||
102 | [AC_LANG_PROGRAM([[ | ||
103 | #include <pthread.h> | ||
104 | ]], | ||
105 | [[ | ||
106 | pthread_spinlock_t lock; | ||
107 | int res; | ||
108 | res = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE); | ||
109 | ]])], | ||
110 | [_efl_have_pthread_spinlock="yes"], | ||
111 | [_efl_have_pthread_spinlock="no"]) | ||
112 | CFLAGS=${SAVE_CFLAGS} | ||
113 | LIBS=${SAVE_LIBS} | ||
114 | |||
115 | fi | ||
116 | |||
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]) | ||
121 | fi | ||
122 | |||
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]) | ||
125 | fi | ||
126 | |||
127 | AS_IF([test "x$_efl_have_pthread" = "xyes"], [$2], [$3]) | ||
128 | AS_IF([test "x$_efl_have_pthread_spinlock" = "xyes"], [$4], [$5]) | ||
129 | |||
130 | ]) | ||