summaryrefslogtreecommitdiffstats
path: root/gl/m4/threadlib.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/threadlib.m4')
-rw-r--r--gl/m4/threadlib.m4136
1 files changed, 80 insertions, 56 deletions
diff --git a/gl/m4/threadlib.m4 b/gl/m4/threadlib.m4
index 05cc4ffa..26bdeb58 100644
--- a/gl/m4/threadlib.m4
+++ b/gl/m4/threadlib.m4
@@ -1,5 +1,5 @@
1# threadlib.m4 serial 5 (gettext-0.18) 1# threadlib.m4 serial 10 (gettext-0.18.2)
2dnl Copyright (C) 2005-2010 Free Software Foundation, Inc. 2dnl Copyright (C) 2005-2013 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,8 +9,13 @@ 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).
@@ -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,9 +162,11 @@ 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 AC_LINK_IFELSE(
152 [pthread_mutex_lock((pthread_mutex_t*)0); 166 [AC_LANG_PROGRAM(
153 pthread_mutexattr_init((pthread_mutexattr_t*)0);], 167 [[#include <pthread.h>]],
168 [[pthread_mutex_lock((pthread_mutex_t*)0);
169 pthread_mutexattr_init((pthread_mutexattr_t*)0);]])],
154 [gl_have_pthread=yes]) 170 [gl_have_pthread=yes])
155 # Test for libpthread by looking for pthread_kill. (Not pthread_self, 171 # Test for libpthread by looking for pthread_kill. (Not pthread_self,
156 # since it is defined as a macro on OSF/1.) 172 # since it is defined as a macro on OSF/1.)
@@ -203,9 +219,13 @@ int main ()
203 gl_have_solaristhread= 219 gl_have_solaristhread=
204 gl_save_LIBS="$LIBS" 220 gl_save_LIBS="$LIBS"
205 LIBS="$LIBS -lthread" 221 LIBS="$LIBS -lthread"
206 AC_TRY_LINK([#include <thread.h> 222 AC_LINK_IFELSE(
207#include <synch.h>], 223 [AC_LANG_PROGRAM(
208 [thr_self();], 224 [[
225#include <thread.h>
226#include <synch.h>
227 ]],
228 [[thr_self();]])],
209 [gl_have_solaristhread=yes]) 229 [gl_have_solaristhread=yes])
210 LIBS="$gl_save_LIBS" 230 LIBS="$gl_save_LIBS"
211 if test -n "$gl_have_solaristhread"; then 231 if test -n "$gl_have_solaristhread"; then
@@ -230,8 +250,10 @@ int main ()
230 AC_LIB_LINKFLAGS([pth]) 250 AC_LIB_LINKFLAGS([pth])
231 gl_have_pth= 251 gl_have_pth=
232 gl_save_LIBS="$LIBS" 252 gl_save_LIBS="$LIBS"
233 LIBS="$LIBS -lpth" 253 LIBS="$LIBS $LIBPTH"
234 AC_TRY_LINK([#include <pth.h>], [pth_self();], [gl_have_pth=yes]) 254 AC_LINK_IFELSE(
255 [AC_LANG_PROGRAM([[#include <pth.h>]], [[pth_self();]])],
256 [gl_have_pth=yes])
235 LIBS="$gl_save_LIBS" 257 LIBS="$gl_save_LIBS"
236 if test -n "$gl_have_pth"; then 258 if test -n "$gl_have_pth"; then
237 gl_threads_api=pth 259 gl_threads_api=pth
@@ -254,17 +276,19 @@ int main ()
254 fi 276 fi
255 fi 277 fi
256 if test -z "$gl_have_pthread"; then 278 if test -z "$gl_have_pthread"; then
257 if test "$gl_use_threads" = yes || test "$gl_use_threads" = win32; then 279 case "$gl_use_threads" in
258 if { case "$host_os" in 280 yes | windows | win32) # The 'win32' is for backward compatibility.
259 mingw*) true;; 281 if { case "$host_os" in
260 *) false;; 282 mingw*) true;;
261 esac 283 *) false;;
262 }; then 284 esac
263 gl_threads_api=win32 285 }; then
264 AC_DEFINE([USE_WIN32_THREADS], [1], 286 gl_threads_api=windows
265 [Define if the Win32 multithreading API can be used.]) 287 AC_DEFINE([USE_WINDOWS_THREADS], [1],
266 fi 288 [Define if the native Windows multithreading API can be used.])
267 fi 289 fi
290 ;;
291 esac
268 fi 292 fi
269 fi 293 fi
270 AC_MSG_CHECKING([for multithread API to use]) 294 AC_MSG_CHECKING([for multithread API to use])
@@ -295,50 +319,50 @@ AC_DEFUN([gl_DISABLE_THREADS], [
295 319
296dnl Survey of platforms: 320dnl Survey of platforms:
297dnl 321dnl
298dnl Platform Available Compiler Supports test-lock 322dnl Platform Available Compiler Supports test-lock
299dnl flavours option weak result 323dnl flavours option weak result
300dnl --------------- --------- --------- -------- --------- 324dnl --------------- --------- --------- -------- ---------
301dnl Linux 2.4/glibc posix -lpthread Y OK 325dnl Linux 2.4/glibc posix -lpthread Y OK
302dnl 326dnl
303dnl GNU Hurd/glibc posix 327dnl GNU Hurd/glibc posix
304dnl 328dnl
305dnl FreeBSD 5.3 posix -lc_r Y 329dnl FreeBSD 5.3 posix -lc_r Y
306dnl posix -lkse ? Y 330dnl posix -lkse ? Y
307dnl posix -lpthread ? Y 331dnl posix -lpthread ? Y
308dnl posix -lthr Y 332dnl posix -lthr Y
309dnl 333dnl
310dnl FreeBSD 5.2 posix -lc_r Y 334dnl FreeBSD 5.2 posix -lc_r Y
311dnl posix -lkse Y 335dnl posix -lkse Y
312dnl posix -lthr Y 336dnl posix -lthr Y
313dnl 337dnl
314dnl FreeBSD 4.0,4.10 posix -lc_r Y OK 338dnl FreeBSD 4.0,4.10 posix -lc_r Y OK
315dnl 339dnl
316dnl NetBSD 1.6 -- 340dnl NetBSD 1.6 --
317dnl 341dnl
318dnl OpenBSD 3.4 posix -lpthread Y OK 342dnl OpenBSD 3.4 posix -lpthread Y OK
319dnl 343dnl
320dnl MacOS X 10.[123] posix -lpthread Y OK 344dnl Mac OS X 10.[123] posix -lpthread Y OK
321dnl 345dnl
322dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK 346dnl 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 347dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK
324dnl 348dnl
325dnl HP-UX 11 posix -lpthread N (cc) OK 349dnl HP-UX 11 posix -lpthread N (cc) OK
326dnl Y (gcc) 350dnl Y (gcc)
327dnl 351dnl
328dnl IRIX 6.5 posix -lpthread Y 0.5 352dnl IRIX 6.5 posix -lpthread Y 0.5
329dnl 353dnl
330dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK 354dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK
331dnl 355dnl
332dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK 356dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK
333dnl -lpthread (gcc) Y 357dnl -lpthread (gcc) Y
334dnl 358dnl
335dnl Cygwin posix -lpthread Y OK 359dnl Cygwin posix -lpthread Y OK
336dnl 360dnl
337dnl Any of the above pth -lpth 0.0 361dnl Any of the above pth -lpth 0.0
338dnl 362dnl
339dnl Mingw win32 N OK 363dnl Mingw windows N OK
340dnl 364dnl
341dnl BeOS 5 -- 365dnl BeOS 5 --
342dnl 366dnl
343dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is 367dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is
344dnl turned off: 368dnl turned off: