Diff for /embedaddon/libiconv/srcm4/threadlib.m4 between versions 1.1 and 1.1.1.3

version 1.1, 2012/02/21 22:57:49 version 1.1.1.3, 2021/03/17 13:38:46
Line 1 Line 1
# threadlib.m4 serial 3 (gettext-0.18)# threadlib.m4 serial 16
dnl Copyright (C) 2005-2009 Free Software Foundation, Inc.dnl Copyright (C) 2005-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation  dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,  dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.  dnl with or without modifications, as long as this notice is preserved.
   
 dnl From Bruno Haible.  dnl From Bruno Haible.
   
   AC_PREREQ([2.60])
   
 dnl gl_THREADLIB  dnl gl_THREADLIB
 dnl ------------  dnl ------------
 dnl Tests for a multithreading library to be used.  dnl Tests for a multithreading library to be used.
   dnl If the configure.ac contains a definition of the gl_THREADLIB_DEFAULT_NO
   dnl (it must be placed before the invocation of gl_THREADLIB_EARLY!), then the
   dnl default is 'no', otherwise it is system dependent. In both cases, the user
   dnl can change the choice through the options --enable-threads=choice or
   dnl --disable-threads.
 dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS,  dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS,
dnl USE_PTH_THREADS, USE_WIN32_THREADSdnl USE_PTH_THREADS, USE_WINDOWS_THREADS
 dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use  dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use
 dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with  dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with
 dnl libtool).  dnl libtool).
 dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for  dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for
 dnl programs that really need multithread functionality. The difference  dnl programs that really need multithread functionality. The difference
 dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak  dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak
dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread".dnl symbols, typically LIBTHREAD is empty whereas LIBMULTITHREAD is not.
 dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for  dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for
 dnl multithread-safe programs.  dnl multithread-safe programs.
   
Line 38  AC_DEFUN([gl_THREADLIB_EARLY_BODY], Line 45  AC_DEFUN([gl_THREADLIB_EARLY_BODY],
   
   AC_REQUIRE([AC_CANONICAL_HOST])    AC_REQUIRE([AC_CANONICAL_HOST])
   dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems.    dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems.
  dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  dnl AC_GNU_SOURCE. 
  m4_ifdef([AC_USE_SYSTEM_EXTENSIONS], 
    [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], 
    [AC_REQUIRE([AC_GNU_SOURCE])]) 
   dnl Check for multithreading.    dnl Check for multithreading.
  m4_divert_text([DEFAULTS], [gl_use_threads_default=])  m4_ifdef([gl_THREADLIB_DEFAULT_NO],
     [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])],
     [m4_divert_text([DEFAULTS], [gl_use_threads_default=])])
   AC_ARG_ENABLE([threads],    AC_ARG_ENABLE([threads],
AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API])AC_HELP_STRING([--enable-threads={posix|solaris|pth|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [
AC_HELP_STRING([--disable-threads], [build without multithread safety]),AC_HELP_STRING([--disable-threads], [build without multithread safety])]),
     [gl_use_threads=$enableval],      [gl_use_threads=$enableval],
     [if test -n "$gl_use_threads_default"; then      [if test -n "$gl_use_threads_default"; then
        gl_use_threads="$gl_use_threads_default"         gl_use_threads="$gl_use_threads_default"
      else       else
   changequote(,)dnl
        case "$host_os" in         case "$host_os" in
          dnl Disable multithreading by default on OSF/1, because it interferes           dnl Disable multithreading by default on OSF/1, because it interferes
          dnl with fork()/exec(): When msgexec is linked with -lpthread, its           dnl with fork()/exec(): When msgexec is linked with -lpthread, its
          dnl child process gets an endless segmentation fault inside execvp().           dnl child process gets an endless segmentation fault inside execvp().
            dnl Disable multithreading by default on Cygwin 1.5.x, because it has
            dnl bugs that lead to endless loops or crashes. See
            dnl <https://cygwin.com/ml/cygwin/2009-08/msg00283.html>.
          osf*) gl_use_threads=no ;;           osf*) gl_use_threads=no ;;
            cygwin*)
                  case `uname -r` in
                    1.[0-5].*) gl_use_threads=no ;;
                    *)         gl_use_threads=yes ;;
                  esac
                  ;;
          *)    gl_use_threads=yes ;;           *)    gl_use_threads=yes ;;
        esac         esac
   changequote([,])dnl
      fi       fi
     ])      ])
   if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then    if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
Line 69  AC_HELP_STRING([--disable-threads], [build without mul Line 85  AC_HELP_STRING([--disable-threads], [build without mul
         # groks <pthread.h>. cc also understands the flag -pthread, but          # groks <pthread.h>. cc also understands the flag -pthread, but
         # we don't use it because 1. gcc-2.95 doesn't understand -pthread,          # we don't use it because 1. gcc-2.95 doesn't understand -pthread,
         # 2. putting a flag into CPPFLAGS that has an effect on the linker          # 2. putting a flag into CPPFLAGS that has an effect on the linker
        # causes the AC_TRY_LINK test below to succeed unexpectedly,        # causes the AC_LINK_IFELSE test below to succeed unexpectedly,
         # leading to wrong values of LIBTHREAD and LTLIBTHREAD.          # leading to wrong values of LIBTHREAD and LTLIBTHREAD.
         CPPFLAGS="$CPPFLAGS -D_REENTRANT"          CPPFLAGS="$CPPFLAGS -D_REENTRANT"
         ;;          ;;
Line 96  AC_DEFUN([gl_THREADLIB_BODY], Line 112  AC_DEFUN([gl_THREADLIB_BODY],
   LTLIBMULTITHREAD=    LTLIBMULTITHREAD=
   if test "$gl_use_threads" != no; then    if test "$gl_use_threads" != no; then
     dnl Check whether the compiler and linker support weak declarations.      dnl Check whether the compiler and linker support weak declarations.
    AC_MSG_CHECKING([whether imported symbols can be declared weak])    AC_CACHE_CHECK([whether imported symbols can be declared weak],
    gl_have_weak=no      [gl_cv_have_weak],
    AC_TRY_LINK([extern void xyzzy ();      [gl_cv_have_weak=no
#pragma weak xyzzy], [xyzzy();], [gl_have_weak=yes])       dnl First, test whether the compiler accepts it syntactically.
    AC_MSG_RESULT([$gl_have_weak])       AC_LINK_IFELSE(
          [AC_LANG_PROGRAM(
             [[extern void xyzzy ();
 #pragma weak xyzzy]],
             [[xyzzy();]])],
          [gl_cv_have_weak=maybe])
        if test $gl_cv_have_weak = maybe; then
          dnl Second, test whether it actually works. On Cygwin 1.7.2, with
          dnl gcc 4.3, symbols declared weak always evaluate to the address 0.
          AC_RUN_IFELSE(
            [AC_LANG_SOURCE([[
 #include <stdio.h>
 #pragma weak fputs
 int main ()
 {
   return (fputs == NULL);
 }]])],
            [gl_cv_have_weak=yes],
            [gl_cv_have_weak=no],
            [dnl When cross-compiling, assume that only ELF platforms support
             dnl weak symbols.
             AC_EGREP_CPP([Extensible Linking Format],
               [#ifdef __ELF__
                Extensible Linking Format
                #endif
               ],
               [gl_cv_have_weak="guessing yes"],
               [gl_cv_have_weak="guessing no"])
            ])
        fi
        dnl But when linking statically, weak symbols don't work.
        case " $LDFLAGS " in
          *" -static "*) gl_cv_have_weak=no ;;
        esac
       ])
     if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then      if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then
       # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that        # On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that
       # it groks <pthread.h>. It's added above, in gl_THREADLIB_EARLY_BODY.        # it groks <pthread.h>. It's added above, in gl_THREADLIB_EARLY_BODY.
Line 114  AC_DEFUN([gl_THREADLIB_BODY], Line 164  AC_DEFUN([gl_THREADLIB_BODY],
         # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist          # Test whether both pthread_mutex_lock and pthread_mutexattr_init exist
         # in libc. IRIX 6.5 has the first one in both libc and libpthread, but          # in libc. IRIX 6.5 has the first one in both libc and libpthread, but
         # the second one only in libpthread, and lock.c needs it.          # the second one only in libpthread, and lock.c needs it.
        AC_TRY_LINK([#include <pthread.h>],        #
          [pthread_mutex_lock((pthread_mutex_t*)0);        # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04
           pthread_mutexattr_init((pthread_mutexattr_t*)0);],        # needs -pthread for some reason.  See:
          [gl_have_pthread=yes])        # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html
         save_LIBS=$LIBS
         for gl_pthread in '' '-pthread'; do
           LIBS="$LIBS $gl_pthread"
           AC_LINK_IFELSE(
             [AC_LANG_PROGRAM(
                [[#include <pthread.h>
                  pthread_mutex_t m;
                  pthread_mutexattr_t ma;
                ]],
                [[pthread_mutex_lock (&m);
                  pthread_mutexattr_init (&ma);]])],
             [gl_have_pthread=yes
              LIBTHREAD=$gl_pthread LTLIBTHREAD=$gl_pthread
              LIBMULTITHREAD=$gl_pthread LTLIBMULTITHREAD=$gl_pthread])
           LIBS=$save_LIBS
           test -n "$gl_have_pthread" && break
         done
 
         # Test for libpthread by looking for pthread_kill. (Not pthread_self,          # Test for libpthread by looking for pthread_kill. (Not pthread_self,
         # since it is defined as a macro on OSF/1.)          # since it is defined as a macro on OSF/1.)
        if test -n "$gl_have_pthread"; then        if test -n "$gl_have_pthread" && test -z "$LIBTHREAD"; then
           # The program links fine without libpthread. But it may actually            # The program links fine without libpthread. But it may actually
           # need to link with libpthread in order to create multiple threads.            # need to link with libpthread in order to create multiple threads.
           AC_CHECK_LIB([pthread], [pthread_kill],            AC_CHECK_LIB([pthread], [pthread_kill],
Line 129  AC_DEFUN([gl_THREADLIB_BODY], Line 197  AC_DEFUN([gl_THREADLIB_BODY],
              # Therefore pthread_in_use() needs to actually try to create a               # Therefore pthread_in_use() needs to actually try to create a
              # thread: pthread_create from libc will fail, whereas               # thread: pthread_create from libc will fail, whereas
              # pthread_create will actually create a thread.               # pthread_create will actually create a thread.
                # On Solaris 10 or newer, this test is no longer needed, because
                # libc contains the fully functional pthread functions.
              case "$host_os" in               case "$host_os" in
               solaris* | hpux*)               solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*)
                  AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],                   AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1],
                    [Define if the pthread_in_use() detection is hard.])                     [Define if the pthread_in_use() detection is hard.])
              esac               esac
             ])              ])
        else        elif test -z "$gl_have_pthread"; then
           # Some library is needed. Try libpthread and libc_r.            # Some library is needed. Try libpthread and libc_r.
           AC_CHECK_LIB([pthread], [pthread_kill],            AC_CHECK_LIB([pthread], [pthread_kill],
             [gl_have_pthread=yes              [gl_have_pthread=yes
Line 154  AC_DEFUN([gl_THREADLIB_BODY], Line 224  AC_DEFUN([gl_THREADLIB_BODY],
           AC_DEFINE([USE_POSIX_THREADS], [1],            AC_DEFINE([USE_POSIX_THREADS], [1],
             [Define if the POSIX multithreading library can be used.])              [Define if the POSIX multithreading library can be used.])
           if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then            if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
            if test $gl_have_weak = yes; then            if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
               AC_DEFINE([USE_POSIX_THREADS_WEAK], [1],                AC_DEFINE([USE_POSIX_THREADS_WEAK], [1],
                 [Define if references to the POSIX multithreading library should be made weak.])                  [Define if references to the POSIX multithreading library should be made weak.])
               LIBTHREAD=                LIBTHREAD=
Line 169  AC_DEFUN([gl_THREADLIB_BODY], Line 239  AC_DEFUN([gl_THREADLIB_BODY],
         gl_have_solaristhread=          gl_have_solaristhread=
         gl_save_LIBS="$LIBS"          gl_save_LIBS="$LIBS"
         LIBS="$LIBS -lthread"          LIBS="$LIBS -lthread"
        AC_TRY_LINK([#include <thread.h>        AC_LINK_IFELSE(
#include <synch.h>],          [AC_LANG_PROGRAM(
          [thr_self();],             [[
 #include <thread.h>
 #include <synch.h>
              ]],
              [[thr_self();]])],
           [gl_have_solaristhread=yes])            [gl_have_solaristhread=yes])
         LIBS="$gl_save_LIBS"          LIBS="$gl_save_LIBS"
         if test -n "$gl_have_solaristhread"; then          if test -n "$gl_have_solaristhread"; then
Line 182  AC_DEFUN([gl_THREADLIB_BODY], Line 256  AC_DEFUN([gl_THREADLIB_BODY],
           LTLIBMULTITHREAD="$LTLIBTHREAD"            LTLIBMULTITHREAD="$LTLIBTHREAD"
           AC_DEFINE([USE_SOLARIS_THREADS], [1],            AC_DEFINE([USE_SOLARIS_THREADS], [1],
             [Define if the old Solaris multithreading library can be used.])              [Define if the old Solaris multithreading library can be used.])
          if test $gl_have_weak = yes; then          if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
             AC_DEFINE([USE_SOLARIS_THREADS_WEAK], [1],              AC_DEFINE([USE_SOLARIS_THREADS_WEAK], [1],
               [Define if references to the old Solaris multithreading library should be made weak.])                [Define if references to the old Solaris multithreading library should be made weak.])
             LIBTHREAD=              LIBTHREAD=
Line 196  AC_DEFUN([gl_THREADLIB_BODY], Line 270  AC_DEFUN([gl_THREADLIB_BODY],
       AC_LIB_LINKFLAGS([pth])        AC_LIB_LINKFLAGS([pth])
       gl_have_pth=        gl_have_pth=
       gl_save_LIBS="$LIBS"        gl_save_LIBS="$LIBS"
      LIBS="$LIBS -lpth"      LIBS="$LIBS $LIBPTH"
      AC_TRY_LINK([#include <pth.h>], [pth_self();], [gl_have_pth=yes])      AC_LINK_IFELSE(
         [AC_LANG_PROGRAM([[#include <pth.h>]], [[pth_self();]])],
         [gl_have_pth=yes])
       LIBS="$gl_save_LIBS"        LIBS="$gl_save_LIBS"
       if test -n "$gl_have_pth"; then        if test -n "$gl_have_pth"; then
         gl_threads_api=pth          gl_threads_api=pth
Line 208  AC_DEFUN([gl_THREADLIB_BODY], Line 284  AC_DEFUN([gl_THREADLIB_BODY],
         AC_DEFINE([USE_PTH_THREADS], [1],          AC_DEFINE([USE_PTH_THREADS], [1],
           [Define if the GNU Pth multithreading library can be used.])            [Define if the GNU Pth multithreading library can be used.])
         if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then          if test -n "$LIBMULTITHREAD" || test -n "$LTLIBMULTITHREAD"; then
          if test $gl_have_weak = yes; then          if case "$gl_cv_have_weak" in *yes) true;; *) false;; esac; then
             AC_DEFINE([USE_PTH_THREADS_WEAK], [1],              AC_DEFINE([USE_PTH_THREADS_WEAK], [1],
               [Define if references to the GNU Pth multithreading library should be made weak.])                [Define if references to the GNU Pth multithreading library should be made weak.])
             LIBTHREAD=              LIBTHREAD=
Line 220  AC_DEFUN([gl_THREADLIB_BODY], Line 296  AC_DEFUN([gl_THREADLIB_BODY],
       fi        fi
     fi      fi
     if test -z "$gl_have_pthread"; then      if test -z "$gl_have_pthread"; then
      if test "$gl_use_threads" = yes || test "$gl_use_threads" = win32; then      case "$gl_use_threads" in
        if { case "$host_os" in        yes | windows | win32) # The 'win32' is for backward compatibility.
               mingw*) true;;          if { case "$host_os" in
               *) false;;                 mingw*) true;;
             esac                 *) false;;
           }; then               esac
          gl_threads_api=win32             }; then
          AC_DEFINE([USE_WIN32_THREADS], [1],            gl_threads_api=windows
            [Define if the Win32 multithreading API can be used.])            AC_DEFINE([USE_WINDOWS_THREADS], [1],
        fi              [Define if the native Windows multithreading API can be used.])
      fi          fi
           ;;
       esac
     fi      fi
   fi    fi
   AC_MSG_CHECKING([for multithread API to use])    AC_MSG_CHECKING([for multithread API to use])
Line 261  AC_DEFUN([gl_DISABLE_THREADS], [ Line 339  AC_DEFUN([gl_DISABLE_THREADS], [
   
 dnl Survey of platforms:  dnl Survey of platforms:
 dnl  dnl
dnl Platform          Available   Compiler    Supports   test-lockdnl Platform           Available  Compiler    Supports   test-lock
dnl                   flavours    option      weak       resultdnl                    flavours   option      weak       result
dnl ---------------   ---------   ---------   --------   ---------dnl ---------------    ---------  ---------   --------   ---------
dnl Linux 2.4/glibc   posix       -lpthread       Y      OKdnl Linux 2.4/glibc    posix      -lpthread       Y      OK
 dnl  dnl
dnl GNU Hurd/glibc    posixdnl GNU Hurd/glibc     posix
 dnl  dnl
dnl FreeBSD 5.3       posix       -lc_r           Ydnl Ubuntu 14.04       posix      -pthread        Y      OK
dnl                   posix       -lkse ?         Y 
dnl                   posix       -lpthread ?     Y 
dnl                   posix       -lthr           Y 
 dnl  dnl
dnl FreeBSD 5.2       posix       -lc_r           Ydnl FreeBSD 5.3        posix      -lc_r           Y
dnl                   posix       -lkse           Ydnl                    posix      -lkse ?         Y
dnl                   posix       -lthr           Ydnl                    posix      -lpthread ?     Y
 dnl                    posix      -lthr           Y
 dnl  dnl
dnl FreeBSD 4.0,4.10  posix       -lc_r           Y      OKdnl FreeBSD 5.2        posix      -lc_r           Y
 dnl                    posix      -lkse           Y
 dnl                    posix      -lthr           Y
 dnl  dnl
dnl NetBSD 1.6        --dnl FreeBSD 4.0,4.10   posix      -lc_r           Y      OK
 dnl  dnl
dnl OpenBSD 3.4       posix       -lpthread       Y      OKdnl NetBSD 1.6         --
 dnl  dnl
dnl MacOS X 10.[123]  posix       -lpthread       Y      OKdnl OpenBSD 3.4        posix      -lpthread       Y      OK
 dnl  dnl
dnl Solaris 7,8,9     posix       -lpthread       Y      Sol 7,8: 0.0; Sol 9: OKdnl Mac OS X 10.[123]  posix      -lpthread       Y      OK
dnl                   solaris     -lthread        Y      Sol 7,8: 0.0; Sol 9: OK 
 dnl  dnl
dnl HP-UX 11          posix       -lpthread       N (cc) OKdnl Solaris 7,8,9      posix      -lpthread       Y      Sol 7,8: 0.0; Sol 9: OK
 dnl                    solaris    -lthread        Y      Sol 7,8: 0.0; Sol 9: OK
 dnl
 dnl HP-UX 11           posix      -lpthread       N (cc) OK
 dnl                                               Y (gcc)  dnl                                               Y (gcc)
 dnl  dnl
dnl IRIX 6.5          posix       -lpthread       Y      0.5dnl IRIX 6.5           posix      -lpthread       Y      0.5
 dnl  dnl
dnl AIX 4.3,5.1       posix       -lpthread       N      AIX 4: 0.5; AIX 5: OKdnl AIX 4.3,5.1        posix      -lpthread       N      AIX 4: 0.5; AIX 5: OK
 dnl  dnl
dnl OSF/1 4.0,5.1     posix       -pthread (cc)   N      OKdnl OSF/1 4.0,5.1      posix      -pthread (cc)   N      OK
 dnl                               -lpthread (gcc) Y  dnl                               -lpthread (gcc) Y
 dnl  dnl
dnl Cygwin            posix       -lpthread       Y      OKdnl Cygwin             posix      -lpthread       Y      OK
 dnl  dnl
dnl Any of the above  pth         -lpth                  0.0dnl Any of the above   pth        -lpth                  0.0
 dnl  dnl
dnl Mingw             win32                       N      OKdnl Mingw              windows                    N      OK
 dnl  dnl
dnl BeOS 5            --dnl BeOS 5             --
 dnl  dnl
 dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is  dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is
 dnl turned off:  dnl turned off:

Removed from v.1.1  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>