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