1 diff -Nur amavisd-0.1.orig/acinclude.m4 amavisd-0.1.chng/acinclude.m4
2 --- amavisd-0.1.orig/acinclude.m4 Thu Jan 1 01:00:00 1970
3 +++ amavisd-0.1.chng/acinclude.m4 Sun Jan 19 23:31:33 2003
5 +dnl Available from the GNU Autoconf Macro Archive at:
6 +dnl http://www.gnu.org/software/ac-archive/htmldoc/acx_pthread.html
8 +AC_DEFUN([ACX_PTHREAD], [
9 +AC_REQUIRE([AC_CANONICAL_HOST])
14 +# We used to check for pthread.h first, but this fails if pthread.h
15 +# requires special compiler flags (e.g. on True64 or Sequent).
16 +# It gets checked for in the link test anyway.
18 +# First of all, check if the user has set any of the PTHREAD_LIBS,
19 +# etcetera environment variables, and if threads linking works using
21 +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
22 + save_CFLAGS="$CFLAGS"
23 + CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
25 + LIBS="$PTHREAD_LIBS $LIBS"
26 + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
27 + AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
28 + AC_MSG_RESULT($acx_pthread_ok)
29 + if test x"$acx_pthread_ok" = xno; then
34 + CFLAGS="$save_CFLAGS"
37 +# We must check for the threads library under a number of different
38 +# names; the ordering is very important because some systems
39 +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
40 +# libraries is broken (non-POSIX).
42 +# Create a list of thread flags to try. Items starting with a "-" are
43 +# C compiler flags, and other items are library names, except for "none"
44 +# which indicates that we try without any flags at all.
46 +acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt"
48 +# The ordering *is* (sometimes) important. Some notes on the
49 +# individual items follow:
51 +# pthreads: AIX (must check this before -lpthread)
52 +# none: in case threads are in libc; should be tried before -Kthread and
53 +# other compiler flags to prevent continual compiler warnings
54 +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
55 +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
56 +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
57 +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
58 +# -pthreads: Solaris/gcc
59 +# -mthreads: Mingw32/gcc, Lynx/gcc
60 +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
61 +# doesn't hurt to check since this sometimes defines pthreads too;
62 +# also defines -D_REENTRANT)
63 +# pthread: Linux, etcetera
64 +# --thread-safe: KAI C++
66 +case "${host_cpu}-${host_os}" in
69 + # On Solaris (at least, for some versions), libc contains stubbed
70 + # (non-functional) versions of the pthreads routines, so link-based
71 + # tests will erroneously succeed. (We need to link with -pthread or
72 + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
73 + # a function called by this macro, so we could check for that, but
74 + # who knows whether they'll stub that too in a future libc.) So,
75 + # we'll just look for -pthreads and -lpthread first:
77 + acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
81 +if test x"$acx_pthread_ok" = xno; then
82 +for flag in $acx_pthread_flags; do
86 + AC_MSG_CHECKING([whether pthreads work without any flags])
90 + AC_MSG_CHECKING([whether pthreads work with $flag])
91 + PTHREAD_CFLAGS="$flag"
95 + AC_MSG_CHECKING([for the pthreads library -l$flag])
96 + PTHREAD_LIBS="-l$flag"
101 + save_CFLAGS="$CFLAGS"
102 + LIBS="$PTHREAD_LIBS $LIBS"
103 + CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
105 + # Check for various functions. We must include pthread.h,
106 + # since some functions may be macros. (On the Sequent, we
107 + # need a special flag -Kthread to make this header compile.)
108 + # We check for pthread_join because it is in -lpthread on IRIX
109 + # while pthread_create is in libc. We check for pthread_attr_init
110 + # due to DEC craziness with -lpthreads. We check for
111 + # pthread_cleanup_push because it is one of the few pthread
112 + # functions on Solaris that doesn't have a non-functional libc stub.
113 + # We try pthread_create on general principles.
114 + AC_TRY_LINK([#include <pthread.h>],
115 + [pthread_t th; pthread_join(th, 0);
116 + pthread_attr_init(0); pthread_cleanup_push(0, 0);
117 + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
118 + [acx_pthread_ok=yes])
121 + CFLAGS="$save_CFLAGS"
123 + AC_MSG_RESULT($acx_pthread_ok)
124 + if test "x$acx_pthread_ok" = xyes; then
133 +# Various other checks:
134 +if test "x$acx_pthread_ok" = xyes; then
136 + LIBS="$PTHREAD_LIBS $LIBS"
137 + save_CFLAGS="$CFLAGS"
138 + CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
140 + # Detect AIX lossage: threads are created detached by default
141 + # and the JOINABLE attribute has a nonstandard name (UNDETACHED).
142 + AC_MSG_CHECKING([for joinable pthread attribute])
143 + AC_TRY_LINK([#include <pthread.h>],
144 + [int attr=PTHREAD_CREATE_JOINABLE;],
145 + ok=PTHREAD_CREATE_JOINABLE, ok=unknown)
146 + if test x"$ok" = xunknown; then
147 + AC_TRY_LINK([#include <pthread.h>],
148 + [int attr=PTHREAD_CREATE_UNDETACHED;],
149 + ok=PTHREAD_CREATE_UNDETACHED, ok=unknown)
151 + if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then
152 + AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok,
153 + [Define to the necessary symbol if this constant
154 + uses a non-standard name on your system.])
156 + AC_MSG_RESULT(${ok})
157 + if test x"$ok" = xunknown; then
158 + AC_MSG_WARN([we do not know how to create joinable pthreads])
161 + AC_MSG_CHECKING([if more special flags are required for pthreads])
163 + case "${host_cpu}-${host_os}" in
164 + *-aix* | *-freebsd*) flag="-D_THREAD_SAFE";;
165 + *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
167 + AC_MSG_RESULT(${flag})
168 + if test "x$flag" != xno; then
169 + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
173 + CFLAGS="$save_CFLAGS"
175 + # More AIX lossage: must compile with cc_r
176 + AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
181 +AC_SUBST(PTHREAD_LIBS)
182 +AC_SUBST(PTHREAD_CFLAGS)
183 +AC_SUBST(PTHREAD_CC)
185 +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
186 +if test x"$acx_pthread_ok" = xyes; then
187 + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])