"Fossies" - the Fresh Open Source Software Archive

Member "amavisd-milter-1.7.2/aclocal/acx_pthread.m4" (6 Jan 2019, 13255 Bytes) of package /linux/privat/amavisd-milter-1.7.2.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 dnl http://avahi.org/log/trunk/common/acx_pthread.m4
    2 dnl cahngeset 1277
    3 dnl
    4 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
    5 dnl
    6 dnl @summary figure out how to build C programs using POSIX threads
    7 dnl
    8 dnl This macro figures out how to build C programs using POSIX threads.
    9 dnl It sets the PTHREAD_LIBS output variable to the threads library and
   10 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
   11 dnl C compiler flags that are needed. (The user can also force certain
   12 dnl compiler flags/libs to be tested by setting these environment
   13 dnl variables.)
   14 dnl
   15 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
   16 dnl multi-threaded programs (defaults to the value of CC otherwise).
   17 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
   18 dnl
   19 dnl NOTE: You are assumed to not only compile your program with these
   20 dnl flags, but also link it with them as well. e.g. you should link
   21 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
   22 dnl $LIBS
   23 dnl
   24 dnl If you are only building threads programs, you may wish to use
   25 dnl these variables in your default LIBS, CFLAGS, and CC:
   26 dnl
   27 dnl        LIBS="$PTHREAD_LIBS $LIBS"
   28 dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
   29 dnl        CC="$PTHREAD_CC"
   30 dnl
   31 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
   32 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
   33 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
   34 dnl
   35 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
   36 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
   37 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
   38 dnl default action will define HAVE_PTHREAD.
   39 dnl
   40 dnl Please let the authors know if this macro fails on any platform, or
   41 dnl if you have any other suggestions or comments. This macro was based
   42 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
   43 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
   44 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
   45 dnl We are also grateful for the helpful feedback of numerous users.
   46 dnl
   47 dnl @category InstalledPackages
   48 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
   49 dnl @version 2006-05-29
   50 dnl @license GPLWithACException
   51 dnl
   52 dnl Checks for GCC shared/pthread inconsistency based on work by
   53 dnl Marcin Owsiany <marcin@owsiany.pl>
   54 
   55 
   56 AC_DEFUN([ACX_PTHREAD], [
   57 AC_REQUIRE([AC_CANONICAL_HOST])
   58 AC_LANG_SAVE
   59 AC_LANG_C
   60 acx_pthread_ok=no
   61 
   62 # We used to check for pthread.h first, but this fails if pthread.h
   63 # requires special compiler flags (e.g. on True64 or Sequent).
   64 # It gets checked for in the link test anyway.
   65 
   66 # First of all, check if the user has set any of the PTHREAD_LIBS,
   67 # etcetera environment variables, and if threads linking works using
   68 # them:
   69 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
   70         save_CFLAGS="$CFLAGS"
   71         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
   72         save_LIBS="$LIBS"
   73         LIBS="$PTHREAD_LIBS $LIBS"
   74         AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
   75         AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
   76         AC_MSG_RESULT($acx_pthread_ok)
   77         if test x"$acx_pthread_ok" = xno; then
   78                 PTHREAD_LIBS=""
   79                 PTHREAD_CFLAGS=""
   80         fi
   81         LIBS="$save_LIBS"
   82         CFLAGS="$save_CFLAGS"
   83 fi
   84 
   85 # We must check for the threads library under a number of different
   86 # names; the ordering is very important because some systems
   87 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
   88 # libraries is broken (non-POSIX).
   89 
   90 # Create a list of thread flags to try.  Items starting with a "-" are
   91 # C compiler flags, and other items are library names, except for "none"
   92 # which indicates that we try without any flags at all, and "pthread-config"
   93 # which is a program returning the flags for the Pth emulation library.
   94 
   95 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
   96 
   97 # The ordering *is* (sometimes) important.  Some notes on the
   98 # individual items follow:
   99 
  100 # pthreads: AIX (must check this before -lpthread)
  101 # none: in case threads are in libc; should be tried before -Kthread and
  102 #       other compiler flags to prevent continual compiler warnings
  103 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
  104 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
  105 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
  106 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
  107 # -pthreads: Solaris/gcc
  108 # -mthreads: Mingw32/gcc, Lynx/gcc
  109 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
  110 #      doesn't hurt to check since this sometimes defines pthreads too;
  111 #      also defines -D_REENTRANT)
  112 #      ... -mt is also the pthreads flag for HP/aCC
  113 # pthread: Linux, etcetera
  114 # --thread-safe: KAI C++
  115 # pthread-config: use pthread-config program (for GNU Pth library)
  116 
  117 case "${host_cpu}-${host_os}" in
  118         *solaris*)
  119 
  120         # On Solaris (at least, for some versions), libc contains stubbed
  121         # (non-functional) versions of the pthreads routines, so link-based
  122         # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
  123         # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
  124         # a function called by this macro, so we could check for that, but
  125         # who knows whether they'll stub that too in a future libc.)  So,
  126         # we'll just look for -pthreads and -lpthread first:
  127 
  128         acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
  129         ;;
  130 esac
  131 
  132 if test x"$acx_pthread_ok" = xno; then
  133 for flag in $acx_pthread_flags; do
  134 
  135         case $flag in
  136                 none)
  137                 AC_MSG_CHECKING([whether pthreads work without any flags])
  138                 ;;
  139 
  140                 -*)
  141                 AC_MSG_CHECKING([whether pthreads work with $flag])
  142                 PTHREAD_CFLAGS="$flag"
  143                 ;;
  144 
  145                 pthread-config)
  146                 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
  147                 if test x"$acx_pthread_config" = xno; then continue; fi
  148                 PTHREAD_CFLAGS="`pthread-config --cflags`"
  149                 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
  150                 ;;
  151 
  152                 *)
  153                 AC_MSG_CHECKING([for the pthreads library -l$flag])
  154                 PTHREAD_LIBS="-l$flag"
  155                 ;;
  156         esac
  157 
  158         save_LIBS="$LIBS"
  159         save_CFLAGS="$CFLAGS"
  160         LIBS="$PTHREAD_LIBS $LIBS"
  161         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  162 
  163         # Check for various functions.  We must include pthread.h,
  164         # since some functions may be macros.  (On the Sequent, we
  165         # need a special flag -Kthread to make this header compile.)
  166         # We check for pthread_join because it is in -lpthread on IRIX
  167         # while pthread_create is in libc.  We check for pthread_attr_init
  168         # due to DEC craziness with -lpthreads.  We check for
  169         # pthread_cleanup_push because it is one of the few pthread
  170         # functions on Solaris that doesn't have a non-functional libc stub.
  171         # We try pthread_create on general principles.
  172         AC_TRY_LINK([#include <pthread.h>],
  173                     [pthread_t th; pthread_join(th, 0);
  174                      pthread_attr_init(0); pthread_cleanup_push(0, 0);
  175                      pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
  176                     [acx_pthread_ok=yes])
  177 
  178         LIBS="$save_LIBS"
  179         CFLAGS="$save_CFLAGS"
  180 
  181         AC_MSG_RESULT($acx_pthread_ok)
  182         if test "x$acx_pthread_ok" = xyes; then
  183                 break;
  184         fi
  185 
  186         PTHREAD_LIBS=""
  187         PTHREAD_CFLAGS=""
  188 done
  189 fi
  190 
  191 # Various other checks:
  192 if test "x$acx_pthread_ok" = xyes; then
  193         save_LIBS="$LIBS"
  194         LIBS="$PTHREAD_LIBS $LIBS"
  195         save_CFLAGS="$CFLAGS"
  196         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  197 
  198         # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
  199         AC_MSG_CHECKING([for joinable pthread attribute])
  200         attr_name=unknown
  201         for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
  202             AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
  203                         [attr_name=$attr; break])
  204         done
  205         AC_MSG_RESULT($attr_name)
  206         if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
  207             AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
  208                                [Define to necessary symbol if this constant
  209                                 uses a non-standard name on your system.])
  210         fi
  211 
  212         AC_MSG_CHECKING([if more special flags are required for pthreads])
  213         flag=no
  214         case "${host_cpu}-${host_os}" in
  215             *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
  216             *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
  217         esac
  218         AC_MSG_RESULT(${flag})
  219         if test "x$flag" != xno; then
  220             PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
  221         fi
  222 
  223         LIBS="$save_LIBS"
  224         CFLAGS="$save_CFLAGS"
  225         # More AIX lossage: must compile with xlc_r or cc_r
  226         if test x"$GCC" != xyes; then
  227           AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
  228         else
  229           PTHREAD_CC=$CC
  230         fi
  231 
  232    # The next part tries to detect GCC inconsistency with -shared on some
  233    # architectures and systems. The problem is that in certain
  234    # configurations, when -shared is specified, GCC "forgets" to
  235    # internally use various flags which are still necessary.
  236 
  237    AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies])
  238    check_inconsistencies=yes
  239    case "${host_cpu}-${host_os}" in
  240      *-darwin*) check_inconsistencies=no ;;
  241    esac
  242    if test x"$GCC" != xyes -o "x$check_inconsistencies" != xyes ; then
  243       AC_MSG_RESULT([no])
  244    else
  245       AC_MSG_RESULT([yes])
  246 
  247       # In order not to create several levels of indentation, we test
  248       # the value of "$ok" until we find out the cure or run out of
  249       # ideas.
  250       ok="no"
  251 
  252       #
  253       # Prepare the flags
  254       #
  255       save_CFLAGS="$CFLAGS"
  256       save_LIBS="$LIBS"
  257       save_CC="$CC"
  258       # Try with the flags determined by the earlier checks.
  259       #
  260       # -Wl,-z,defs forces link-time symbol resolution, so that the
  261       # linking checks with -shared actually have any value
  262       #
  263       # FIXME: -fPIC is required for -shared on many architectures,
  264       # so we specify it here, but the right way would probably be to
  265       # properly detect whether it is actually required.
  266       CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
  267       LIBS="$PTHREAD_LIBS $LIBS"
  268       CC="$PTHREAD_CC"
  269 
  270       AC_MSG_CHECKING([whether -pthread is sufficient with -shared])
  271       AC_TRY_LINK([#include <pthread.h>],
  272          [pthread_t th; pthread_join(th, 0);
  273          pthread_attr_init(0); pthread_cleanup_push(0, 0);
  274          pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
  275          [ok=yes])
  276 
  277       if test "x$ok" = xyes; then
  278          AC_MSG_RESULT([yes])
  279       else
  280          AC_MSG_RESULT([no])
  281       fi
  282 
  283       #
  284       # Linux gcc on some architectures such as mips/mipsel forgets
  285       # about -lpthread
  286       #
  287       if test x"$ok" = xno; then
  288          AC_MSG_CHECKING([whether -lpthread fixes that])
  289          LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
  290          AC_TRY_LINK([#include <pthread.h>],
  291             [pthread_t th; pthread_join(th, 0);
  292             pthread_attr_init(0); pthread_cleanup_push(0, 0);
  293             pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
  294             [ok=yes])
  295 
  296          if test "x$ok" = xyes; then
  297             AC_MSG_RESULT([yes])
  298             PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
  299          else
  300             AC_MSG_RESULT([no])
  301          fi
  302       fi
  303       #
  304       # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
  305       #
  306       if test x"$ok" = xno; then
  307          AC_MSG_CHECKING([whether -lc_r fixes that])
  308          LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
  309          AC_TRY_LINK([#include <pthread.h>],
  310              [pthread_t th; pthread_join(th, 0);
  311               pthread_attr_init(0); pthread_cleanup_push(0, 0);
  312               pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
  313              [ok=yes])
  314 
  315          if test "x$ok" = xyes; then
  316             AC_MSG_RESULT([yes])
  317             PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
  318          else
  319             AC_MSG_RESULT([no])
  320          fi
  321       fi
  322       if test x"$ok" = xno; then
  323          # OK, we have run out of ideas
  324          AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries])
  325 
  326          # so it's not safe to assume that we may use pthreads
  327          acx_pthread_ok=no
  328       fi
  329 
  330       CFLAGS="$save_CFLAGS"
  331       LIBS="$save_LIBS"
  332       CC="$save_CC"
  333    fi
  334 else
  335         PTHREAD_CC="$CC"
  336 fi
  337 
  338 AC_SUBST(PTHREAD_LIBS)
  339 AC_SUBST(PTHREAD_CFLAGS)
  340 AC_SUBST(PTHREAD_CC)
  341 
  342 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  343 if test x"$acx_pthread_ok" = xyes; then
  344         ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
  345         :
  346 else
  347         acx_pthread_ok=no
  348         $2
  349 fi
  350 AC_LANG_RESTORE
  351 ])dnl ACX_PTHREAD