comparison src/fftw-3.3.8/m4/acx_pthread.m4 @ 167:bd3cc4d1df30

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 19 Nov 2019 14:52:55 +0000
parents
children
comparison
equal deleted inserted replaced
166:cbd6d7e562c7 167:bd3cc4d1df30
1 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
2 dnl @summary figure out how to build C programs using POSIX threads
3 dnl @category InstalledPackages
4 dnl
5 dnl This macro figures out how to build C programs using POSIX
6 dnl threads. It sets the PTHREAD_LIBS output variable to the threads
7 dnl library and linker flags, and the PTHREAD_CFLAGS output variable
8 dnl to any special C compiler flags that are needed. (The user can also
9 dnl force certain compiler flags/libs to be tested by setting these
10 dnl environment variables.)
11 dnl
12 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
13 dnl multi-threaded programs (defaults to the value of CC otherwise).
14 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
15 dnl
16 dnl NOTE: You are assumed to not only compile your program with these
17 dnl flags, but also link it with them as well. e.g. you should link
18 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
19 dnl
20 dnl If you are only building threads programs, you may wish to
21 dnl use these variables in your default LIBS, CFLAGS, and CC:
22 dnl
23 dnl LIBS="$PTHREAD_LIBS $LIBS"
24 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
25 dnl CC="$PTHREAD_CC"
26 dnl
27 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
28 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE
29 dnl to that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
30 dnl
31 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
32 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands
33 dnl to run it if it is not found. If ACTION-IF-FOUND is not specified,
34 dnl the default action will define HAVE_PTHREAD.
35 dnl
36 dnl Please let the authors know if this macro fails on any platform,
37 dnl or if you have any other suggestions or comments. This macro was
38 dnl based on work by SGJ on autoconf scripts for FFTW (www.fftw.org)
39 dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread
40 dnl macros posted by Alejandro Forero Cuervo to the autoconf macro
41 dnl repository. We are also grateful for the helpful feedback of
42 dnl numerous users.
43 dnl
44 dnl @version 2006-09-15
45 dnl @license GPLWithACException
46 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
47
48 AC_DEFUN([ACX_PTHREAD], [
49 AC_REQUIRE([AC_CANONICAL_HOST])
50 AC_LANG_SAVE
51 AC_LANG_C
52 acx_pthread_ok=no
53
54 # We used to check for pthread.h first, but this fails if pthread.h
55 # requires special compiler flags (e.g. on True64 or Sequent).
56 # It gets checked for in the link test anyway.
57
58 # First of all, check if the user has set any of the PTHREAD_LIBS,
59 # etcetera environment variables, and if threads linking works using
60 # them:
61 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
62 save_CFLAGS="$CFLAGS"
63 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
64 save_LIBS="$LIBS"
65 LIBS="$PTHREAD_LIBS $LIBS"
66 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
67 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
68 AC_MSG_RESULT($acx_pthread_ok)
69 if test x"$acx_pthread_ok" = xno; then
70 PTHREAD_LIBS=""
71 PTHREAD_CFLAGS=""
72 fi
73 LIBS="$save_LIBS"
74 CFLAGS="$save_CFLAGS"
75 fi
76
77 # We must check for the threads library under a number of different
78 # names; the ordering is very important because some systems
79 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
80 # libraries is broken (non-POSIX).
81
82 # Create a list of thread flags to try. Items starting with a "-" are
83 # C compiler flags, and other items are library names, except for "none"
84 # which indicates that we try without any flags at all, and "pthread-config"
85 # which is a program returning the flags for the Pth emulation library.
86
87 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mt -mthreads pthread --thread-safe pthread-config"
88
89 # The ordering *is* (sometimes) important. Some notes on the
90 # individual items follow:
91
92 # pthreads: AIX (must check this before -lpthread)
93 # none: in case threads are in libc; should be tried before -Kthread and
94 # other compiler flags to prevent continual compiler warnings
95 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
96 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
97 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
98 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
99 # -pthreads: Solaris/gcc
100 # -mthreads: Mingw32/gcc, Lynx/gcc
101 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
102 # doesn't hurt to check since this sometimes defines pthreads too;
103 # also defines -D_REENTRANT)
104 # ... -mt is also the pthreads flag for HP/aCC
105 # (where it should come before -mthreads to avoid spurious warnings)
106 # pthread: Linux, etcetera
107 # --thread-safe: KAI C++
108 # pthread-config: use pthread-config program (for GNU Pth library)
109
110 case "${host_cpu}-${host_os}" in
111 *solaris*)
112
113 # On Solaris (at least, for some versions), libc contains stubbed
114 # (non-functional) versions of the pthreads routines, so link-based
115 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
116 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
117 # a function called by this macro, so we could check for that, but
118 # who knows whether they'll stub that too in a future libc.) So,
119 # we'll just look for -pthreads and -lpthread first:
120
121 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
122 ;;
123 esac
124
125 if test x"$acx_pthread_ok" = xno; then
126 for flag in $acx_pthread_flags; do
127
128 case $flag in
129 none)
130 AC_MSG_CHECKING([whether pthreads work without any flags])
131 ;;
132
133 -*)
134 AC_MSG_CHECKING([whether pthreads work with $flag])
135 PTHREAD_CFLAGS="$flag"
136 ;;
137
138 pthread-config)
139 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
140 if test x"$acx_pthread_config" = xno; then continue; fi
141 PTHREAD_CFLAGS="`pthread-config --cflags`"
142 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
143 ;;
144
145 *)
146 AC_MSG_CHECKING([for the pthreads library -l$flag])
147 PTHREAD_LIBS="-l$flag"
148 ;;
149 esac
150
151 save_LIBS="$LIBS"
152 save_CFLAGS="$CFLAGS"
153 LIBS="$PTHREAD_LIBS $LIBS"
154 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
155
156 # Check for various functions. We must include pthread.h,
157 # since some functions may be macros. (On the Sequent, we
158 # need a special flag -Kthread to make this header compile.)
159 # We check for pthread_join because it is in -lpthread on IRIX
160 # while pthread_create is in libc. We check for pthread_attr_init
161 # due to DEC craziness with -lpthreads. We check for
162 # pthread_cleanup_push because it is one of the few pthread
163 # functions on Solaris that doesn't have a non-functional libc stub.
164 # We try pthread_create on general principles.
165 AC_TRY_LINK([#include <pthread.h>],
166 [pthread_t th; pthread_join(th, (void**) 0);
167 pthread_attr_init((pthread_attr_t*) 0);
168 pthread_cleanup_push((void(*)(void *)) 0, (void*) 0);
169 pthread_create((pthread_t*) 0, (pthread_attr_t*) 0,
170 (void*(*)(void *)) 0, (void*) 0);
171 pthread_cleanup_pop(0); ],
172 [acx_pthread_ok=yes])
173
174 LIBS="$save_LIBS"
175 CFLAGS="$save_CFLAGS"
176
177 AC_MSG_RESULT($acx_pthread_ok)
178 if test "x$acx_pthread_ok" = xyes; then
179 break;
180 fi
181
182 PTHREAD_LIBS=""
183 PTHREAD_CFLAGS=""
184 done
185 fi
186
187 # Various other checks:
188 if test "x$acx_pthread_ok" = xyes; then
189 save_LIBS="$LIBS"
190 LIBS="$PTHREAD_LIBS $LIBS"
191 save_CFLAGS="$CFLAGS"
192 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
193
194 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
195 AC_MSG_CHECKING([for joinable pthread attribute])
196 attr_name=unknown
197 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
198 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
199 [attr_name=$attr; break])
200 done
201 AC_MSG_RESULT($attr_name)
202 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
203 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
204 [Define to necessary symbol if this constant
205 uses a non-standard name on your system.])
206 fi
207
208 AC_MSG_CHECKING([if more special flags are required for pthreads])
209 flag=no
210 case "${host_cpu}-${host_os}" in
211 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
212 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
213 esac
214 AC_MSG_RESULT(${flag})
215 if test "x$flag" != xno; then
216 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
217 fi
218
219 LIBS="$save_LIBS"
220 CFLAGS="$save_CFLAGS"
221
222 # More AIX lossage: must compile with xlc_r or cc_r
223 if test x"$GCC" != xyes; then
224 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
225 else
226 PTHREAD_CC=$CC
227 fi
228 else
229 PTHREAD_CC="$CC"
230 fi
231
232 AC_SUBST(PTHREAD_LIBS)
233 AC_SUBST(PTHREAD_CFLAGS)
234 AC_SUBST(PTHREAD_CC)
235
236 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
237 if test x"$acx_pthread_ok" = xyes; then
238 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
239 :
240 else
241 acx_pthread_ok=no
242 $2
243 fi
244 AC_LANG_RESTORE
245 ])dnl ACX_PTHREAD