diff options
Diffstat (limited to 'm4/threadlib.m4')
-rw-r--r-- | m4/threadlib.m4 | 162 |
1 files changed, 102 insertions, 60 deletions
diff --git a/m4/threadlib.m4 b/m4/threadlib.m4 index 05cc4ffa..b43534ea 100644 --- a/m4/threadlib.m4 +++ b/m4/threadlib.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # threadlib.m4 serial 5 (gettext-0.18) | 1 | # threadlib.m4 serial 11 (gettext-0.18.2) |
2 | dnl Copyright (C) 2005-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2005-2016 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -9,15 +9,20 @@ dnl From Bruno Haible. | |||
9 | dnl gl_THREADLIB | 9 | dnl gl_THREADLIB |
10 | dnl ------------ | 10 | dnl ------------ |
11 | dnl Tests for a multithreading library to be used. | 11 | dnl Tests for a multithreading library to be used. |
12 | dnl If the configure.ac contains a definition of the gl_THREADLIB_DEFAULT_NO | ||
13 | dnl (it must be placed before the invocation of gl_THREADLIB_EARLY!), then the | ||
14 | dnl default is 'no', otherwise it is system dependent. In both cases, the user | ||
15 | dnl can change the choice through the options --enable-threads=choice or | ||
16 | dnl --disable-threads. | ||
12 | dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, | 17 | dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, |
13 | dnl USE_PTH_THREADS, USE_WIN32_THREADS | 18 | dnl USE_PTH_THREADS, USE_WINDOWS_THREADS |
14 | dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use | 19 | dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use |
15 | dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with | 20 | dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with |
16 | dnl libtool). | 21 | dnl libtool). |
17 | dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for | 22 | dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for |
18 | dnl programs that really need multithread functionality. The difference | 23 | dnl programs that really need multithread functionality. The difference |
19 | dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak | 24 | dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak |
20 | dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". | 25 | dnl symbols, typically LIBTHREAD is empty whereas LIBMULTITHREAD is not. |
21 | dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for | 26 | dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for |
22 | dnl multithread-safe programs. | 27 | dnl multithread-safe programs. |
23 | 28 | ||
@@ -44,10 +49,12 @@ AC_DEFUN([gl_THREADLIB_EARLY_BODY], | |||
44 | [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], | 49 | [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], |
45 | [AC_REQUIRE([AC_GNU_SOURCE])]) | 50 | [AC_REQUIRE([AC_GNU_SOURCE])]) |
46 | dnl Check for multithreading. | 51 | dnl Check for multithreading. |
47 | m4_divert_text([DEFAULTS], [gl_use_threads_default=]) | 52 | m4_ifdef([gl_THREADLIB_DEFAULT_NO], |
53 | [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])], | ||
54 | [m4_divert_text([DEFAULTS], [gl_use_threads_default=])]) | ||
48 | AC_ARG_ENABLE([threads], | 55 | AC_ARG_ENABLE([threads], |
49 | AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API]) | 56 | AC_HELP_STRING([--enable-threads={posix|solaris|pth|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [ |
50 | AC_HELP_STRING([--disable-threads], [build without multithread safety]), | 57 | AC_HELP_STRING([--disable-threads], [build without multithread safety])]), |
51 | [gl_use_threads=$enableval], | 58 | [gl_use_threads=$enableval], |
52 | [if test -n "$gl_use_threads_default"; then | 59 | [if test -n "$gl_use_threads_default"; then |
53 | gl_use_threads="$gl_use_threads_default" | 60 | gl_use_threads="$gl_use_threads_default" |
@@ -80,7 +87,7 @@ changequote([,])dnl | |||
80 | # groks <pthread.h>. cc also understands the flag -pthread, but | 87 | # groks <pthread.h>. cc also understands the flag -pthread, but |
81 | # we don't use it because 1. gcc-2.95 doesn't understand -pthread, | 88 | # we don't use it because 1. gcc-2.95 doesn't understand -pthread, |
82 | # 2. putting a flag into CPPFLAGS that has an effect on the linker | 89 | # 2. putting a flag into CPPFLAGS that has an effect on the linker |
83 | # causes the AC_TRY_LINK test below to succeed unexpectedly, | 90 | # causes the AC_LINK_IFELSE test below to succeed unexpectedly, |
84 | # leading to wrong values of LIBTHREAD and LTLIBTHREAD. | 91 | # leading to wrong values of LIBTHREAD and LTLIBTHREAD. |
85 | CPPFLAGS="$CPPFLAGS -D_REENTRANT" | 92 | CPPFLAGS="$CPPFLAGS -D_REENTRANT" |
86 | ;; | 93 | ;; |
@@ -111,18 +118,25 @@ AC_DEFUN([gl_THREADLIB_BODY], | |||
111 | [gl_cv_have_weak], | 118 | [gl_cv_have_weak], |
112 | [gl_cv_have_weak=no | 119 | [gl_cv_have_weak=no |
113 | dnl First, test whether the compiler accepts it syntactically. | 120 | dnl First, test whether the compiler accepts it syntactically. |
114 | AC_TRY_LINK([extern void xyzzy (); | 121 | AC_LINK_IFELSE( |
115 | #pragma weak xyzzy], [xyzzy();], [gl_cv_have_weak=maybe]) | 122 | [AC_LANG_PROGRAM( |
123 | [[extern void xyzzy (); | ||
124 | #pragma weak xyzzy]], | ||
125 | [[xyzzy();]])], | ||
126 | [gl_cv_have_weak=maybe]) | ||
116 | if test $gl_cv_have_weak = maybe; then | 127 | if test $gl_cv_have_weak = maybe; then |
117 | dnl Second, test whether it actually works. On Cygwin 1.7.2, with | 128 | dnl Second, test whether it actually works. On Cygwin 1.7.2, with |
118 | dnl gcc 4.3, symbols declared weak always evaluate to the address 0. | 129 | dnl gcc 4.3, symbols declared weak always evaluate to the address 0. |
119 | AC_TRY_RUN([ | 130 | AC_RUN_IFELSE( |
131 | [AC_LANG_SOURCE([[ | ||
120 | #include <stdio.h> | 132 | #include <stdio.h> |
121 | #pragma weak fputs | 133 | #pragma weak fputs |
122 | int main () | 134 | int main () |
123 | { | 135 | { |
124 | return (fputs == NULL); | 136 | return (fputs == NULL); |
125 | }], [gl_cv_have_weak=yes], [gl_cv_have_weak=no], | 137 | }]])], |
138 | [gl_cv_have_weak=yes], | ||
139 | [gl_cv_have_weak=no], | ||
126 | [dnl When cross-compiling, assume that only ELF platforms support | 140 | [dnl When cross-compiling, assume that only ELF platforms support |
127 | dnl weak symbols. | 141 | dnl weak symbols. |
128 | AC_EGREP_CPP([Extensible Linking Format], | 142 | AC_EGREP_CPP([Extensible Linking Format], |
@@ -148,13 +162,31 @@ int main () | |||
148 | # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist | 162 | # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist |
149 | # in libc. IRIX 6.5 has the first one in both libc and libpthread, but | 163 | # in libc. IRIX 6.5 has the first one in both libc and libpthread, but |
150 | # the second one only in libpthread, and lock.c needs it. | 164 | # the second one only in libpthread, and lock.c needs it. |
151 | AC_TRY_LINK([#include <pthread.h>], | 165 | # |
152 | [pthread_mutex_lock((pthread_mutex_t*)0); | 166 | # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04 |
153 | pthread_mutexattr_init((pthread_mutexattr_t*)0);], | 167 | # needs -pthread for some reason. See: |
154 | [gl_have_pthread=yes]) | 168 | # http://lists.gnu.org/archive/html/bug-gnulib/2014-09/msg00023.html |
169 | save_LIBS=$LIBS | ||
170 | for gl_pthread in '' '-pthread'; do | ||
171 | LIBS="$LIBS $gl_pthread" | ||
172 | AC_LINK_IFELSE( | ||
173 | [AC_LANG_PROGRAM( | ||
174 | [[#include <pthread.h> | ||
175 | pthread_mutex_t m; | ||
176 | pthread_mutexattr_t ma; | ||
177 | ]], | ||
178 | [[pthread_mutex_lock (&m); | ||
179 | pthread_mutexattr_init (&ma);]])], | ||
180 | [gl_have_pthread=yes | ||
181 | LIBTHREAD=$gl_pthread LTLIBTHREAD=$gl_pthread | ||
182 | LIBMULTITHREAD=$gl_pthread LTLIBMULTITHREAD=$gl_pthread]) | ||
183 | LIBS=$save_LIBS | ||
184 | test -n "$gl_have_pthread" && break | ||
185 | done | ||
186 | |||
155 | # Test for libpthread by looking for pthread_kill. (Not pthread_self, | 187 | # Test for libpthread by looking for pthread_kill. (Not pthread_self, |
156 | # since it is defined as a macro on OSF/1.) | 188 | # since it is defined as a macro on OSF/1.) |
157 | if test -n "$gl_have_pthread"; then | 189 | if test -n "$gl_have_pthread" && test -z "$LIBTHREAD"; then |
158 | # The program links fine without libpthread. But it may actually | 190 | # The program links fine without libpthread. But it may actually |
159 | # need to link with libpthread in order to create multiple threads. | 191 | # need to link with libpthread in order to create multiple threads. |
160 | AC_CHECK_LIB([pthread], [pthread_kill], | 192 | AC_CHECK_LIB([pthread], [pthread_kill], |
@@ -169,7 +201,7 @@ int main () | |||
169 | [Define if the pthread_in_use() detection is hard.]) | 201 | [Define if the pthread_in_use() detection is hard.]) |
170 | esac | 202 | esac |
171 | ]) | 203 | ]) |
172 | else | 204 | elif test -z "$gl_have_pthread"; then |
173 | # Some library is needed. Try libpthread and libc_r. | 205 | # Some library is needed. Try libpthread and libc_r. |
174 | AC_CHECK_LIB([pthread], [pthread_kill], | 206 | AC_CHECK_LIB([pthread], [pthread_kill], |
175 | [gl_have_pthread=yes | 207 | [gl_have_pthread=yes |
@@ -203,9 +235,13 @@ int main () | |||
203 | gl_have_solaristhread= | 235 | gl_have_solaristhread= |
204 | gl_save_LIBS="$LIBS" | 236 | gl_save_LIBS="$LIBS" |
205 | LIBS="$LIBS -lthread" | 237 | LIBS="$LIBS -lthread" |
206 | AC_TRY_LINK([#include <thread.h> | 238 | AC_LINK_IFELSE( |
207 | #include <synch.h>], | 239 | [AC_LANG_PROGRAM( |
208 | [thr_self();], | 240 | [[ |
241 | #include <thread.h> | ||
242 | #include <synch.h> | ||
243 | ]], | ||
244 | [[thr_self();]])], | ||
209 | [gl_have_solaristhread=yes]) | 245 | [gl_have_solaristhread=yes]) |
210 | LIBS="$gl_save_LIBS" | 246 | LIBS="$gl_save_LIBS" |
211 | if test -n "$gl_have_solaristhread"; then | 247 | if test -n "$gl_have_solaristhread"; then |
@@ -230,8 +266,10 @@ int main () | |||
230 | AC_LIB_LINKFLAGS([pth]) | 266 | AC_LIB_LINKFLAGS([pth]) |
231 | gl_have_pth= | 267 | gl_have_pth= |
232 | gl_save_LIBS="$LIBS" | 268 | gl_save_LIBS="$LIBS" |
233 | LIBS="$LIBS -lpth" | 269 | LIBS="$LIBS $LIBPTH" |
234 | AC_TRY_LINK([#include <pth.h>], [pth_self();], [gl_have_pth=yes]) | 270 | AC_LINK_IFELSE( |
271 | [AC_LANG_PROGRAM([[#include <pth.h>]], [[pth_self();]])], | ||
272 | [gl_have_pth=yes]) | ||
235 | LIBS="$gl_save_LIBS" | 273 | LIBS="$gl_save_LIBS" |
236 | if test -n "$gl_have_pth"; then | 274 | if test -n "$gl_have_pth"; then |
237 | gl_threads_api=pth | 275 | gl_threads_api=pth |
@@ -254,17 +292,19 @@ int main () | |||
254 | fi | 292 | fi |
255 | fi | 293 | fi |
256 | if test -z "$gl_have_pthread"; then | 294 | if test -z "$gl_have_pthread"; then |
257 | if test "$gl_use_threads" = yes || test "$gl_use_threads" = win32; then | 295 | case "$gl_use_threads" in |
258 | if { case "$host_os" in | 296 | yes | windows | win32) # The 'win32' is for backward compatibility. |
259 | mingw*) true;; | 297 | if { case "$host_os" in |
260 | *) false;; | 298 | mingw*) true;; |
261 | esac | 299 | *) false;; |
262 | }; then | 300 | esac |
263 | gl_threads_api=win32 | 301 | }; then |
264 | AC_DEFINE([USE_WIN32_THREADS], [1], | 302 | gl_threads_api=windows |
265 | [Define if the Win32 multithreading API can be used.]) | 303 | AC_DEFINE([USE_WINDOWS_THREADS], [1], |
266 | fi | 304 | [Define if the native Windows multithreading API can be used.]) |
267 | fi | 305 | fi |
306 | ;; | ||
307 | esac | ||
268 | fi | 308 | fi |
269 | fi | 309 | fi |
270 | AC_MSG_CHECKING([for multithread API to use]) | 310 | AC_MSG_CHECKING([for multithread API to use]) |
@@ -295,50 +335,52 @@ AC_DEFUN([gl_DISABLE_THREADS], [ | |||
295 | 335 | ||
296 | dnl Survey of platforms: | 336 | dnl Survey of platforms: |
297 | dnl | 337 | dnl |
298 | dnl Platform Available Compiler Supports test-lock | 338 | dnl Platform Available Compiler Supports test-lock |
299 | dnl flavours option weak result | 339 | dnl flavours option weak result |
300 | dnl --------------- --------- --------- -------- --------- | 340 | dnl --------------- --------- --------- -------- --------- |
301 | dnl Linux 2.4/glibc posix -lpthread Y OK | 341 | dnl Linux 2.4/glibc posix -lpthread Y OK |
342 | dnl | ||
343 | dnl GNU Hurd/glibc posix | ||
302 | dnl | 344 | dnl |
303 | dnl GNU Hurd/glibc posix | 345 | dnl Ubuntu 14.04 posix -pthread Y OK |
304 | dnl | 346 | dnl |
305 | dnl FreeBSD 5.3 posix -lc_r Y | 347 | dnl FreeBSD 5.3 posix -lc_r Y |
306 | dnl posix -lkse ? Y | 348 | dnl posix -lkse ? Y |
307 | dnl posix -lpthread ? Y | 349 | dnl posix -lpthread ? Y |
308 | dnl posix -lthr Y | 350 | dnl posix -lthr Y |
309 | dnl | 351 | dnl |
310 | dnl FreeBSD 5.2 posix -lc_r Y | 352 | dnl FreeBSD 5.2 posix -lc_r Y |
311 | dnl posix -lkse Y | 353 | dnl posix -lkse Y |
312 | dnl posix -lthr Y | 354 | dnl posix -lthr Y |
313 | dnl | 355 | dnl |
314 | dnl FreeBSD 4.0,4.10 posix -lc_r Y OK | 356 | dnl FreeBSD 4.0,4.10 posix -lc_r Y OK |
315 | dnl | 357 | dnl |
316 | dnl NetBSD 1.6 -- | 358 | dnl NetBSD 1.6 -- |
317 | dnl | 359 | dnl |
318 | dnl OpenBSD 3.4 posix -lpthread Y OK | 360 | dnl OpenBSD 3.4 posix -lpthread Y OK |
319 | dnl | 361 | dnl |
320 | dnl MacOS X 10.[123] posix -lpthread Y OK | 362 | dnl Mac OS X 10.[123] posix -lpthread Y OK |
321 | dnl | 363 | dnl |
322 | dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK | 364 | dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK |
323 | dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK | 365 | dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK |
324 | dnl | 366 | dnl |
325 | dnl HP-UX 11 posix -lpthread N (cc) OK | 367 | dnl HP-UX 11 posix -lpthread N (cc) OK |
326 | dnl Y (gcc) | 368 | dnl Y (gcc) |
327 | dnl | 369 | dnl |
328 | dnl IRIX 6.5 posix -lpthread Y 0.5 | 370 | dnl IRIX 6.5 posix -lpthread Y 0.5 |
329 | dnl | 371 | dnl |
330 | dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK | 372 | dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK |
331 | dnl | 373 | dnl |
332 | dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK | 374 | dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK |
333 | dnl -lpthread (gcc) Y | 375 | dnl -lpthread (gcc) Y |
334 | dnl | 376 | dnl |
335 | dnl Cygwin posix -lpthread Y OK | 377 | dnl Cygwin posix -lpthread Y OK |
336 | dnl | 378 | dnl |
337 | dnl Any of the above pth -lpth 0.0 | 379 | dnl Any of the above pth -lpth 0.0 |
338 | dnl | 380 | dnl |
339 | dnl Mingw win32 N OK | 381 | dnl Mingw windows N OK |
340 | dnl | 382 | dnl |
341 | dnl BeOS 5 -- | 383 | dnl BeOS 5 -- |
342 | dnl | 384 | dnl |
343 | dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is | 385 | dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is |
344 | dnl turned off: | 386 | dnl turned off: |