aboutsummaryrefslogtreecommitdiff
path: root/m4/threadlib.m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4/threadlib.m4')
-rw-r--r--m4/threadlib.m4162
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)
2dnl Copyright (C) 2005-2010 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2016 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -9,15 +9,20 @@ dnl From Bruno Haible.
9dnl gl_THREADLIB 9dnl gl_THREADLIB
10dnl ------------ 10dnl ------------
11dnl Tests for a multithreading library to be used. 11dnl Tests for a multithreading library to be used.
12dnl If the configure.ac contains a definition of the gl_THREADLIB_DEFAULT_NO
13dnl (it must be placed before the invocation of gl_THREADLIB_EARLY!), then the
14dnl default is 'no', otherwise it is system dependent. In both cases, the user
15dnl can change the choice through the options --enable-threads=choice or
16dnl --disable-threads.
12dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, 17dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS,
13dnl USE_PTH_THREADS, USE_WIN32_THREADS 18dnl USE_PTH_THREADS, USE_WINDOWS_THREADS
14dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use 19dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use
15dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with 20dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with
16dnl libtool). 21dnl libtool).
17dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for 22dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for
18dnl programs that really need multithread functionality. The difference 23dnl programs that really need multithread functionality. The difference
19dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak 24dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak
20dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". 25dnl symbols, typically LIBTHREAD is empty whereas LIBMULTITHREAD is not.
21dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for 26dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
22dnl multithread-safe programs. 27dnl 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],
49AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API]) 56AC_HELP_STRING([--enable-threads={posix|solaris|pth|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [
50AC_HELP_STRING([--disable-threads], [build without multithread safety]), 57AC_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
122int main () 134int 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
296dnl Survey of platforms: 336dnl Survey of platforms:
297dnl 337dnl
298dnl Platform Available Compiler Supports test-lock 338dnl Platform Available Compiler Supports test-lock
299dnl flavours option weak result 339dnl flavours option weak result
300dnl --------------- --------- --------- -------- --------- 340dnl --------------- --------- --------- -------- ---------
301dnl Linux 2.4/glibc posix -lpthread Y OK 341dnl Linux 2.4/glibc posix -lpthread Y OK
342dnl
343dnl GNU Hurd/glibc posix
302dnl 344dnl
303dnl GNU Hurd/glibc posix 345dnl Ubuntu 14.04 posix -pthread Y OK
304dnl 346dnl
305dnl FreeBSD 5.3 posix -lc_r Y 347dnl FreeBSD 5.3 posix -lc_r Y
306dnl posix -lkse ? Y 348dnl posix -lkse ? Y
307dnl posix -lpthread ? Y 349dnl posix -lpthread ? Y
308dnl posix -lthr Y 350dnl posix -lthr Y
309dnl 351dnl
310dnl FreeBSD 5.2 posix -lc_r Y 352dnl FreeBSD 5.2 posix -lc_r Y
311dnl posix -lkse Y 353dnl posix -lkse Y
312dnl posix -lthr Y 354dnl posix -lthr Y
313dnl 355dnl
314dnl FreeBSD 4.0,4.10 posix -lc_r Y OK 356dnl FreeBSD 4.0,4.10 posix -lc_r Y OK
315dnl 357dnl
316dnl NetBSD 1.6 -- 358dnl NetBSD 1.6 --
317dnl 359dnl
318dnl OpenBSD 3.4 posix -lpthread Y OK 360dnl OpenBSD 3.4 posix -lpthread Y OK
319dnl 361dnl
320dnl MacOS X 10.[123] posix -lpthread Y OK 362dnl Mac OS X 10.[123] posix -lpthread Y OK
321dnl 363dnl
322dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK 364dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK
323dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK 365dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK
324dnl 366dnl
325dnl HP-UX 11 posix -lpthread N (cc) OK 367dnl HP-UX 11 posix -lpthread N (cc) OK
326dnl Y (gcc) 368dnl Y (gcc)
327dnl 369dnl
328dnl IRIX 6.5 posix -lpthread Y 0.5 370dnl IRIX 6.5 posix -lpthread Y 0.5
329dnl 371dnl
330dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK 372dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK
331dnl 373dnl
332dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK 374dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK
333dnl -lpthread (gcc) Y 375dnl -lpthread (gcc) Y
334dnl 376dnl
335dnl Cygwin posix -lpthread Y OK 377dnl Cygwin posix -lpthread Y OK
336dnl 378dnl
337dnl Any of the above pth -lpth 0.0 379dnl Any of the above pth -lpth 0.0
338dnl 380dnl
339dnl Mingw win32 N OK 381dnl Mingw windows N OK
340dnl 382dnl
341dnl BeOS 5 -- 383dnl BeOS 5 --
342dnl 384dnl
343dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is 385dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is
344dnl turned off: 386dnl turned off: