forked from zabbix/zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pthread.m4
167 lines (145 loc) · 4.27 KB
/
pthread.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# LIBPTHREAD_CHECK_CONFIG ([DEFAULT-ACTION])
# ----------------------------------------------------------
#
# Checks for pthread.
#
# This macro sets @LIBPTHREAD_LDFLAGS@, @LIBPTHREAD_CFLAGS@ and @LIBPTHREAD_LIBS@ to the necessary
# values.
#
# This macro is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
AC_DEFUN([LIBPTHREAD_TRY_LINK],
[
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <pthread.h>
]], [[
pthread_mutexattr_t mta;
pthread_mutex_t mutex;
pthread_mutexattr_init(&mta);
pthread_mutex_init(&mutex, &mta);
]])],[found_libpthread="yes"],[])
])dnl
AC_DEFUN([LIBPTHREAD_TRY_RUN],
[
AC_RUN_IFELSE(
[
AC_LANG_SOURCE(
#include <pthread.h>
int main()
{
pthread_mutexattr_t mta;
pthread_rwlockattr_t rwa;
pthread_mutex_t mutex;
pthread_rwlock_t rwlock;
if (0 != pthread_mutexattr_init(&mta))
return 1;
if (0 != pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_SHARED))
return 2;
if (0 != pthread_mutex_init(&mutex, &mta))
return 3;
if (0 != pthread_rwlockattr_init(&rwa))
return 4;
if (0 != pthread_rwlockattr_setpshared(&rwa, PTHREAD_PROCESS_SHARED))
return 5;
if (0 != pthread_rwlock_init(&rwlock, &rwa))
return 6;
return 0;
}
)
]
,
found_libpthread_process_shared="yes",
found_libpthread_process_shared="no",
found_libpthread_process_shared="no" dnl action-if-cross-compiling
)
])
AC_DEFUN([LIBPTHREAD_CHECK_CONFIG],
[
AC_ARG_WITH([libpthread],[
If you want to specify pthread installation directories:
AS_HELP_STRING([--with-libpthread@<:@=DIR@:>@], [use libpthread from given base install directory (DIR), default is to search through a number of common places for the libpthread files.])],
[
test "x$withval" = "xyes" && withval=/usr
LIBPTHREAD_CFLAGS="-I$withval/include"
LIBPTHREAD_LDFLAGS="-L$withval/lib"
_libpthread_dir_set="yes"
]
)
AC_ARG_WITH([libpthread-include],
AS_HELP_STRING([--with-libpthread-include@<:@=DIR@:>@],
[use libpthread include headers from given path.]
),
[
LIBPTHREAD_CFLAGS="-I$withval"
_libpthread_dir_set="yes"
]
)
AC_ARG_WITH([libpthread-lib],
AS_HELP_STRING([--with-libpthread-lib@<:@=DIR@:>@],
[use libpthread libraries from given path.]
),
[
LIBPTHREAD_LDFLAGS="-L$withval"
_libpthread_dir_set="yes"
]
)
AC_CHECK_HEADER([pthread.h],[found_libpthread=yes])
LIBPTHREAD_LIBS="-lpthread"
AC_MSG_CHECKING(for process shared libpthread support)
if test -n "$_libpthread_dir_set" -o "x$found_libpthread" = xyes; then
found_libpthread="yes"
elif test -f /usr/local/include/pthread.h; then
LIBPTHREAD_CFLAGS="-I/usr/local/include"
LIBPTHREAD_LDFLAGS="-L/usr/local/lib"
found_libpthread="yes"
elif test -f /usr/pkg/include/pthread.h; then
LIBPTHREAD_CFLAGS="-I/usr/pkg/include"
LIBPTHREAD_LDFLAGS="-L/usr/pkg/lib"
LIBPTHREAD_LDFLAGS="$LIBPTHREAD_LDFLAGS -Wl,-R/usr/pkg/lib"
found_libpthread="yes"
elif test -f /opt/csw/include/pthread.h; then
LIBPTHREAD_CFLAGS="-I/opt/csw/include"
LIBPTHREAD_LDFLAGS="-L/opt/csw/lib"
if $(echo "$CFLAGS"|grep -q -- "-m64") ; then
LIBPTHREAD_LDFLAGS="$LIBPTHREAD_LDFLAGS/64 -Wl,-R/opt/csw/lib/64"
else
LIBPTHREAD_LDFLAGS="$LIBPTHREAD_LDFLAGS -Wl,-R/opt/csw/lib"
fi
found_libpthread="yes"
else
found_libpthread="no"
AC_MSG_RESULT(no)
fi
if test "x$found_libpthread" = "xyes"; then
am_save_CFLAGS="$CFLAGS"
am_save_LDFLAGS="$LDFLAGS"
am_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $LIBPTHREAD_CFLAGS"
LDFLAGS="$LDFLAGS $LIBPTHREAD_LDFLAGS"
LIBS="$LIBS $LIBPTHREAD_LIBS"
found_libpthread="no"
found_libpthread_process_shared="no"
LIBPTHREAD_TRY_LINK([no])
LIBPTHREAD_TRY_RUN([no])
CFLAGS="$am_save_CFLAGS"
LDFLAGS="$am_save_LDFLAGS"
LIBS="$am_save_LIBS"
fi
if test "x$found_libpthread" = "xyes"; then
if test "x$found_libpthread_process_shared" = "xyes"; then
AC_DEFINE([HAVE_PTHREAD_PROCESS_SHARED], 1, [Define to 1 if you have the 'libpthread' library that supports PTHREAD_PROCESS_SHARED flag (-lpthread)])
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
else
AC_MSG_RESULT(no)
LIBPTHREAD_CFLAGS=""
LIBPTHREAD_LDFLAGS=""
LIBPTHREAD_LIBS=""
fi
AC_SUBST(LIBPTHREAD_CFLAGS)
AC_SUBST(LIBPTHREAD_LDFLAGS)
AC_SUBST(LIBPTHREAD_LIBS)
])dnl