Changeset 96fc67 in git for m4/ax_pthread.m4


Ignore:
Timestamp:
Nov 14, 2022, 11:23:41 AM (17 months ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '5b153614cbc72bfa198d75b1e9e33dab2645d9fe')
Children:
53bb34c61620c64ea3918faddfdebe69fb462864
Parents:
5416d13394a558a137ad68ab6bb7241079911448
Message:
update m4/ax_*
File:
1 edited

Legend:

Unmodified
Added
Removed
  • m4/ax_pthread.m4

    r5416d1 r96fc67  
    11# ===========================================================================
    2 #        http://www.gnu.org/software/autoconf-archive/ax_pthread.html
     2#        https://www.gnu.org/software/autoconf-archive/ax_pthread.html
    33# ===========================================================================
    44#
     
    1515#   flags/libs to be tested by setting these environment variables.)
    1616#
    17 #   Also sets PTHREAD_CC to any special C compiler that is needed for
    18 #   multi-threaded programs (defaults to the value of CC otherwise). (This
    19 #   is necessary on AIX to use the special cc_r compiler alias.)
     17#   Also sets PTHREAD_CC and PTHREAD_CXX to any special C compiler that is
     18#   needed for multi-threaded programs (defaults to the value of CC
     19#   respectively CXX otherwise). (This is necessary on e.g. AIX to use the
     20#   special cc_r/CC_r compiler alias.)
    2021#
    2122#   NOTE: You are assumed to not only compile your program with these flags,
    2223#   but also to link with them as well. For example, you might link with
    2324#   $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
     25#   $PTHREAD_CXX $CXXFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
    2426#
    2527#   If you are only building threaded programs, you may wish to use these
     
    2830#     LIBS="$PTHREAD_LIBS $LIBS"
    2931#     CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
     32#     CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
    3033#     CC="$PTHREAD_CC"
     34#     CXX="$PTHREAD_CXX"
    3135#
    3236#   In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
     
    5660#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
    5761#   Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
     62#   Copyright (c) 2019 Marc Stevens <marc.stevens@cwi.nl>
    5863#
    5964#   This program is free software: you can redistribute it and/or modify it
     
    6873#
    6974#   You should have received a copy of the GNU General Public License along
    70 #   with this program. If not, see <http://www.gnu.org/licenses/>.
     75#   with this program. If not, see <https://www.gnu.org/licenses/>.
    7176#
    7277#   As a special exception, the respective Autoconf Macro's copyright owner
     
    8388#   exception to the GPL to apply to your modified version as well.
    8489
    85 #serial 23
     90#serial 31
    8691
    8792AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
     
    105110        ax_pthread_save_LIBS="$LIBS"
    106111        AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"])
     112        AS_IF([test "x$PTHREAD_CXX" != "x"], [CXX="$PTHREAD_CXX"])
    107113        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
    108114        LIBS="$PTHREAD_LIBS $LIBS"
     
    124130# libraries is broken (non-POSIX).
    125131
    126 # Create a list of thread flags to try.  Items starting with a "-" are
    127 # C compiler flags, and other items are library names, except for "none"
    128 # which indicates that we try without any flags at all, and "pthread-config"
    129 # which is a program returning the flags for the Pth emulation library.
     132# Create a list of thread flags to try. Items with a "," contain both
     133# C compiler flags (before ",") and linker flags (after ","). Other items
     134# starting with a "-" are C compiler flags, and remaining items are
     135# library names, except for "none" which indicates that we try without
     136# any flags at all, and "pthread-config" which is a program returning
     137# the flags for the Pth emulation library.
    130138
    131139ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
     
    195203        # standard Solaris way of linking pthreads (-mt -lpthread).
    196204
    197         ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags"
     205        ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags"
    198206        ;;
    199207esac
    200 
    201 # GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC)
    202 
    203 AS_IF([test "x$GCC" = "xyes"],
    204       [ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"])
    205 
    206 # The presence of a feature test macro requesting re-entrant function
    207 # definitions is, on some systems, a strong hint that pthreads support is
    208 # correctly enabled
    209 
    210 case $host_os in
    211         darwin* | hpux* | linux* | osf* | solaris*)
    212         ax_pthread_check_macro="_REENTRANT"
    213         ;;
    214 
    215         aix*)
    216         ax_pthread_check_macro="_THREAD_SAFE"
    217         ;;
    218 
    219         *)
    220         ax_pthread_check_macro="--"
    221         ;;
    222 esac
    223 AS_IF([test "x$ax_pthread_check_macro" = "x--"],
    224       [ax_pthread_check_cond=0],
    225       [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"])
    226208
    227209# Are we compiling with Clang?
     
    243225ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
    244226
    245 ax_pthread_clang_warning=no
     227
     228# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC)
     229
     230# Note that for GCC and Clang -pthread generally implies -lpthread,
     231# except when -nostdlib is passed.
     232# This is problematic using libtool to build C++ shared libraries with pthread:
     233# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460
     234# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333
     235# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555
     236# To solve this, first try -pthread together with -lpthread for GCC
     237
     238AS_IF([test "x$GCC" = "xyes"],
     239      [ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"])
     240
     241# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first
     242
     243AS_IF([test "x$ax_pthread_clang" = "xyes"],
     244      [ax_pthread_flags="-pthread,-lpthread -pthread"])
     245
     246
     247# The presence of a feature test macro requesting re-entrant function
     248# definitions is, on some systems, a strong hint that pthreads support is
     249# correctly enabled
     250
     251case $host_os in
     252        darwin* | hpux* | linux* | osf* | solaris*)
     253        ax_pthread_check_macro="_REENTRANT"
     254        ;;
     255
     256        aix*)
     257        ax_pthread_check_macro="_THREAD_SAFE"
     258        ;;
     259
     260        *)
     261        ax_pthread_check_macro="--"
     262        ;;
     263esac
     264AS_IF([test "x$ax_pthread_check_macro" = "x--"],
     265      [ax_pthread_check_cond=0],
     266      [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"])
     267
     268
     269if test "x$ax_pthread_ok" = "xno"; then
     270for ax_pthread_try_flag in $ax_pthread_flags; do
     271
     272        case $ax_pthread_try_flag in
     273                none)
     274                AC_MSG_CHECKING([whether pthreads work without any flags])
     275                ;;
     276
     277                *,*)
     278                PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"`
     279                PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"`
     280                AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"])
     281                ;;
     282
     283                -*)
     284                AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag])
     285                PTHREAD_CFLAGS="$ax_pthread_try_flag"
     286                ;;
     287
     288                pthread-config)
     289                AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
     290                AS_IF([test "x$ax_pthread_config" = "xno"], [continue])
     291                PTHREAD_CFLAGS="`pthread-config --cflags`"
     292                PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
     293                ;;
     294
     295                *)
     296                AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag])
     297                PTHREAD_LIBS="-l$ax_pthread_try_flag"
     298                ;;
     299        esac
     300
     301        ax_pthread_save_CFLAGS="$CFLAGS"
     302        ax_pthread_save_LIBS="$LIBS"
     303        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
     304        LIBS="$PTHREAD_LIBS $LIBS"
     305
     306        # Check for various functions.  We must include pthread.h,
     307        # since some functions may be macros.  (On the Sequent, we
     308        # need a special flag -Kthread to make this header compile.)
     309        # We check for pthread_join because it is in -lpthread on IRIX
     310        # while pthread_create is in libc.  We check for pthread_attr_init
     311        # due to DEC craziness with -lpthreads.  We check for
     312        # pthread_cleanup_push because it is one of the few pthread
     313        # functions on Solaris that doesn't have a non-functional libc stub.
     314        # We try pthread_create on general principles.
     315
     316        AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
     317#                       if $ax_pthread_check_cond
     318#                        error "$ax_pthread_check_macro must be defined"
     319#                       endif
     320                        static void *some_global = NULL;
     321                        static void routine(void *a)
     322                          {
     323                             /* To avoid any unused-parameter or
     324                                unused-but-set-parameter warning.  */
     325                             some_global = a;
     326                          }
     327                        static void *start_routine(void *a) { return a; }],
     328                       [pthread_t th; pthread_attr_t attr;
     329                        pthread_create(&th, 0, start_routine, 0);
     330                        pthread_join(th, 0);
     331                        pthread_attr_init(&attr);
     332                        pthread_cleanup_push(routine, 0);
     333                        pthread_cleanup_pop(0) /* ; */])],
     334            [ax_pthread_ok=yes],
     335            [])
     336
     337        CFLAGS="$ax_pthread_save_CFLAGS"
     338        LIBS="$ax_pthread_save_LIBS"
     339
     340        AC_MSG_RESULT([$ax_pthread_ok])
     341        AS_IF([test "x$ax_pthread_ok" = "xyes"], [break])
     342
     343        PTHREAD_LIBS=""
     344        PTHREAD_CFLAGS=""
     345done
     346fi
     347
    246348
    247349# Clang needs special handling, because older versions handle the -pthread
     
    261363        # -pthread does define _REENTRANT, and while the Darwin headers
    262364        # ignore this macro, third-party headers might not.)
    263 
    264         PTHREAD_CFLAGS="-pthread"
    265         PTHREAD_LIBS=
    266 
    267         ax_pthread_ok=yes
    268365
    269366        # However, older versions of Clang make a point of warning the user
     
    295392             ax_pthread_save_ac_link="$ac_link"
    296393             ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g'
    297              ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"`
     394             ax_pthread_link_step=`AS_ECHO(["$ac_link"]) | sed "$ax_pthread_sed"`
    298395             ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)"
    299396             ax_pthread_save_CFLAGS="$CFLAGS"
     
    321418fi # $ax_pthread_clang = yes
    322419
    323 if test "x$ax_pthread_ok" = "xno"; then
    324 for ax_pthread_try_flag in $ax_pthread_flags; do
    325 
    326         case $ax_pthread_try_flag in
    327                 none)
    328                 AC_MSG_CHECKING([whether pthreads work without any flags])
    329                 ;;
    330 
    331                 -mt,pthread)
    332                 AC_MSG_CHECKING([whether pthreads work with -mt -lpthread])
    333                 PTHREAD_CFLAGS="-mt"
    334                 PTHREAD_LIBS="-lpthread"
    335                 ;;
    336 
    337                 -*)
    338                 AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag])
    339                 PTHREAD_CFLAGS="$ax_pthread_try_flag"
    340                 ;;
    341 
    342                 pthread-config)
    343                 AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
    344                 AS_IF([test "x$ax_pthread_config" = "xno"], [continue])
    345                 PTHREAD_CFLAGS="`pthread-config --cflags`"
    346                 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
    347                 ;;
    348 
    349                 *)
    350                 AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag])
    351                 PTHREAD_LIBS="-l$ax_pthread_try_flag"
    352                 ;;
    353         esac
    354 
    355         ax_pthread_save_CFLAGS="$CFLAGS"
    356         ax_pthread_save_LIBS="$LIBS"
    357         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
    358         LIBS="$PTHREAD_LIBS $LIBS"
    359 
    360         # Check for various functions.  We must include pthread.h,
    361         # since some functions may be macros.  (On the Sequent, we
    362         # need a special flag -Kthread to make this header compile.)
    363         # We check for pthread_join because it is in -lpthread on IRIX
    364         # while pthread_create is in libc.  We check for pthread_attr_init
    365         # due to DEC craziness with -lpthreads.  We check for
    366         # pthread_cleanup_push because it is one of the few pthread
    367         # functions on Solaris that doesn't have a non-functional libc stub.
    368         # We try pthread_create on general principles.
    369 
    370         AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
    371 #                       if $ax_pthread_check_cond
    372 #                        error "$ax_pthread_check_macro must be defined"
    373 #                       endif
    374                         static void routine(void *a) { a = 0; }
    375                         static void *start_routine(void *a) { return a; }],
    376                        [pthread_t th; pthread_attr_t attr;
    377                         pthread_create(&th, 0, start_routine, 0);
    378                         pthread_join(th, 0);
    379                         pthread_attr_init(&attr);
    380                         pthread_cleanup_push(routine, 0);
    381                         pthread_cleanup_pop(0) /* ; */])],
    382             [ax_pthread_ok=yes],
    383             [])
    384 
    385         CFLAGS="$ax_pthread_save_CFLAGS"
    386         LIBS="$ax_pthread_save_LIBS"
    387 
    388         AC_MSG_RESULT([$ax_pthread_ok])
    389         AS_IF([test "x$ax_pthread_ok" = "xyes"], [break])
    390 
    391         PTHREAD_LIBS=""
    392         PTHREAD_CFLAGS=""
    393 done
    394 fi
     420
    395421
    396422# Various other checks:
     
    439465            [ax_cv_PTHREAD_PRIO_INHERIT],
    440466            [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
    441                                              [[int i = PTHREAD_PRIO_INHERIT;]])],
     467                                             [[int i = PTHREAD_PRIO_INHERIT;
     468                                               return i;]])],
    442469                            [ax_cv_PTHREAD_PRIO_INHERIT=yes],
    443470                            [ax_cv_PTHREAD_PRIO_INHERIT=no])
     
    461488                     AS_CASE(["x$CC"],
    462489                         [x/*],
    463                          [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
    464                          [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
     490                         [
     491                           AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])
     492                           AS_IF([test "x${CXX}" != "x"], [AS_IF([AS_EXECUTABLE_P([${CXX}_r])],[PTHREAD_CXX="${CXX}_r"])])
     493                         ],
     494                         [
     495                           AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])
     496                           AS_IF([test "x${CXX}" != "x"], [AC_CHECK_PROGS([PTHREAD_CXX],[${CXX}_r],[$CXX])])
     497                         ]
     498                     )
     499                    ])
    465500                ;;
    466501            esac
     
    469504
    470505test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
     506test -n "$PTHREAD_CXX" || PTHREAD_CXX="$CXX"
    471507
    472508AC_SUBST([PTHREAD_LIBS])
    473509AC_SUBST([PTHREAD_CFLAGS])
    474510AC_SUBST([PTHREAD_CC])
     511AC_SUBST([PTHREAD_CXX])
    475512
    476513# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
     
    484521AC_LANG_POP
    485522])dnl AX_PTHREAD
     523
Note: See TracChangeset for help on using the changeset viewer.