Parent Directory
|
Revision Log
Revision 1 - (view) (download)
| 1 : | mark | 1 | dnl From http://www.gnu.org/software/ac-archive/Installed_Packages/acx_pthread.html |
| 2 : | dnl modified to set CPPFLAGS | ||
| 3 : | |||
| 4 : | AC_DEFUN([ACX_PTHREAD], [ | ||
| 5 : | AC_REQUIRE([AC_CANONICAL_HOST]) | ||
| 6 : | AC_LANG_SAVE | ||
| 7 : | AC_LANG_C | ||
| 8 : | acx_pthread_ok=no | ||
| 9 : | |||
| 10 : | # We used to check for pthread.h first, but this fails if pthread.h | ||
| 11 : | # requires special compiler flags (e.g. on True64 or Sequent). | ||
| 12 : | # It gets checked for in the link test anyway. | ||
| 13 : | |||
| 14 : | # First of all, check if the user has set any of the PTHREAD_LIBS, | ||
| 15 : | # etcetera environment variables, and if threads linking works using | ||
| 16 : | # them: | ||
| 17 : | if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS$PTHREAD_CPPFLAGS" != x; then | ||
| 18 : | save_CFLAGS="$CFLAGS" | ||
| 19 : | CFLAGS="$CFLAGS $PTHREAD_CFLAGS" | ||
| 20 : | save_CPPFLAGS="$CPPFLAGS" | ||
| 21 : | CPPFLAGS="$CPPFLAGS $PTHREAD_CPPFLAGS" | ||
| 22 : | save_LIBS="$LIBS" | ||
| 23 : | LIBS="$PTHREAD_LIBS $LIBS" | ||
| 24 : | AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) | ||
| 25 : | AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) | ||
| 26 : | AC_MSG_RESULT($acx_pthread_ok) | ||
| 27 : | if test x"$acx_pthread_ok" = xno; then | ||
| 28 : | PTHREAD_LIBS="" | ||
| 29 : | PTHREAD_CFLAGS="" | ||
| 30 : | fi | ||
| 31 : | LIBS="$save_LIBS" | ||
| 32 : | CFLAGS="$save_CFLAGS" | ||
| 33 : | CPPFLAGS="$save_CPPFLAGS" | ||
| 34 : | fi | ||
| 35 : | |||
| 36 : | # We must check for the threads library under a number of different | ||
| 37 : | # names; the ordering is very important because some systems | ||
| 38 : | # (e.g. DEC) have both -lpthread and -lpthreads, where one of the | ||
| 39 : | # libraries is broken (non-POSIX). | ||
| 40 : | |||
| 41 : | # Create a list of thread flags to try. Items starting with a "-" are | ||
| 42 : | # C compiler flags, and other items are library names, except for "none" | ||
| 43 : | # which indicates that we try without any flags at all. | ||
| 44 : | |||
| 45 : | acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt" | ||
| 46 : | |||
| 47 : | # The ordering *is* (sometimes) important. Some notes on the | ||
| 48 : | # individual items follow: | ||
| 49 : | |||
| 50 : | # pthreads: AIX (must check this before -lpthread) | ||
| 51 : | # none: in case threads are in libc; should be tried before -Kthread and | ||
| 52 : | # other compiler flags to prevent continual compiler warnings | ||
| 53 : | # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) | ||
| 54 : | # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) | ||
| 55 : | # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) | ||
| 56 : | # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) | ||
| 57 : | # -pthreads: Solaris/gcc | ||
| 58 : | # -mthreads: Mingw32/gcc, Lynx/gcc | ||
| 59 : | # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it | ||
| 60 : | # doesn't hurt to check since this sometimes defines pthreads too; | ||
| 61 : | # also defines -D_REENTRANT) | ||
| 62 : | # pthread: Linux, etcetera | ||
| 63 : | # --thread-safe: KAI C++ | ||
| 64 : | |||
| 65 : | case "${host_cpu}-${host_os}" in | ||
| 66 : | *solaris*) | ||
| 67 : | |||
| 68 : | # On Solaris (at least, for some versions), libc contains stubbed | ||
| 69 : | # (non-functional) versions of the pthreads routines, so link-based | ||
| 70 : | # tests will erroneously succeed. (We need to link with -pthread or | ||
| 71 : | # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather | ||
| 72 : | # a function called by this macro, so we could check for that, but | ||
| 73 : | # who knows whether they'll stub that too in a future libc.) So, | ||
| 74 : | # we'll just look for -pthreads and -lpthread first: | ||
| 75 : | |||
| 76 : | acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags" | ||
| 77 : | ;; | ||
| 78 : | esac | ||
| 79 : | |||
| 80 : | if test x"$acx_pthread_ok" = xno; then | ||
| 81 : | for flag in $acx_pthread_flags; do | ||
| 82 : | |||
| 83 : | case $flag in | ||
| 84 : | none) | ||
| 85 : | AC_MSG_CHECKING([whether pthreads work without any flags]) | ||
| 86 : | ;; | ||
| 87 : | |||
| 88 : | -*) | ||
| 89 : | AC_MSG_CHECKING([whether pthreads work with $flag]) | ||
| 90 : | PTHREAD_CFLAGS="$flag" | ||
| 91 : | PTHREAD_CPPFLAGS="$flag" | ||
| 92 : | ;; | ||
| 93 : | |||
| 94 : | *) | ||
| 95 : | AC_MSG_CHECKING([for the pthreads library -l$flag]) | ||
| 96 : | PTHREAD_LIBS="-l$flag" | ||
| 97 : | ;; | ||
| 98 : | esac | ||
| 99 : | |||
| 100 : | save_LIBS="$LIBS" | ||
| 101 : | save_CFLAGS="$CFLAGS" | ||
| 102 : | save_CPPFLAGS="$CPPFLAGS" | ||
| 103 : | LIBS="$PTHREAD_LIBS $LIBS" | ||
| 104 : | CFLAGS="$CFLAGS $PTHREAD_CFLAGS" | ||
| 105 : | CPPFLAGS="$CFLAGS $PTHREAD_CPPFLAGS" | ||
| 106 : | |||
| 107 : | # Check for various functions. We must include pthread.h, | ||
| 108 : | # since some functions may be macros. (On the Sequent, we | ||
| 109 : | # need a special flag -Kthread to make this header compile.) | ||
| 110 : | # We check for pthread_join because it is in -lpthread on IRIX | ||
| 111 : | # while pthread_create is in libc. We check for pthread_attr_init | ||
| 112 : | # due to DEC craziness with -lpthreads. We check for | ||
| 113 : | # pthread_cleanup_push because it is one of the few pthread | ||
| 114 : | # functions on Solaris that doesn't have a non-functional libc stub. | ||
| 115 : | # We try pthread_create on general principles. | ||
| 116 : | AC_TRY_LINK([#include <pthread.h>], | ||
| 117 : | [pthread_t th; pthread_join(th, 0); | ||
| 118 : | pthread_attr_init(0); pthread_cleanup_push(0, 0); | ||
| 119 : | pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], | ||
| 120 : | [acx_pthread_ok=yes]) | ||
| 121 : | |||
| 122 : | LIBS="$save_LIBS" | ||
| 123 : | CFLAGS="$save_CFLAGS" | ||
| 124 : | CPPFLAGS="$save_CPPFLAGS" | ||
| 125 : | |||
| 126 : | AC_MSG_RESULT($acx_pthread_ok) | ||
| 127 : | if test "x$acx_pthread_ok" = xyes; then | ||
| 128 : | break; | ||
| 129 : | fi | ||
| 130 : | |||
| 131 : | PTHREAD_LIBS="" | ||
| 132 : | PTHREAD_CFLAGS="" | ||
| 133 : | PTHREAD_CPPFLAGS="" | ||
| 134 : | done | ||
| 135 : | fi | ||
| 136 : | |||
| 137 : | # Various other checks: | ||
| 138 : | if test "x$acx_pthread_ok" = xyes; then | ||
| 139 : | save_LIBS="$LIBS" | ||
| 140 : | LIBS="$PTHREAD_LIBS $LIBS" | ||
| 141 : | save_CFLAGS="$CFLAGS" | ||
| 142 : | CFLAGS="$CFLAGS $PTHREAD_CFLAGS" | ||
| 143 : | save_CPPFLAGS="$CPPFLAGS" | ||
| 144 : | CPPFLAGS="$CFLAGS $PTHREAD_CPPFLAGS" | ||
| 145 : | |||
| 146 : | # Detect AIX lossage: threads are created detached by default | ||
| 147 : | # and the JOINABLE attribute has a nonstandard name (UNDETACHED). | ||
| 148 : | AC_MSG_CHECKING([for joinable pthread attribute]) | ||
| 149 : | AC_TRY_LINK([#include <pthread.h>], | ||
| 150 : | [int attr=PTHREAD_CREATE_JOINABLE;], | ||
| 151 : | ok=PTHREAD_CREATE_JOINABLE, ok=unknown) | ||
| 152 : | if test x"$ok" = xunknown; then | ||
| 153 : | AC_TRY_LINK([#include <pthread.h>], | ||
| 154 : | [int attr=PTHREAD_CREATE_UNDETACHED;], | ||
| 155 : | ok=PTHREAD_CREATE_UNDETACHED, ok=unknown) | ||
| 156 : | fi | ||
| 157 : | if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then | ||
| 158 : | AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok, | ||
| 159 : | [Define to the necessary symbol if this constant | ||
| 160 : | uses a non-standard name on your system.]) | ||
| 161 : | fi | ||
| 162 : | AC_MSG_RESULT(${ok}) | ||
| 163 : | if test x"$ok" = xunknown; then | ||
| 164 : | AC_MSG_WARN([we do not know how to create joinable pthreads]) | ||
| 165 : | fi | ||
| 166 : | |||
| 167 : | AC_MSG_CHECKING([if more special flags are required for pthreads]) | ||
| 168 : | flag=no | ||
| 169 : | case "${host_cpu}-${host_os}" in | ||
| 170 : | *-aix* | *-freebsd*) flag="-D_THREAD_SAFE";; | ||
| 171 : | # -D_REENTRANT is actually implied by -pthread in Tru64 5.1, | ||
| 172 : | # at least. | ||
| 173 : | *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; | ||
| 174 : | esac | ||
| 175 : | AC_MSG_RESULT(${flag}) | ||
| 176 : | if test "x$flag" != xno; then | ||
| 177 : | PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" | ||
| 178 : | PTHREAD_CPPFLAGS="$flag $PTHREAD_CPPFLAGS" | ||
| 179 : | fi | ||
| 180 : | |||
| 181 : | LIBS="$save_LIBS" | ||
| 182 : | CFLAGS="$save_CFLAGS" | ||
| 183 : | CPPFLAGS="$save_CPPFLAGS" | ||
| 184 : | |||
| 185 : | # More AIX lossage: must compile with cc_r | ||
| 186 : | AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, [${CC}]) | ||
| 187 : | else | ||
| 188 : | PTHREAD_CC="$CC" | ||
| 189 : | fi | ||
| 190 : | |||
| 191 : | AC_SUBST(PTHREAD_LIBS) | ||
| 192 : | AC_SUBST(PTHREAD_CFLAGS) | ||
| 193 : | AC_SUBST(PTHREAD_CPPFLAGS) | ||
| 194 : | AC_SUBST(PTHREAD_CC) | ||
| 195 : | |||
| 196 : | # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: | ||
| 197 : | if test x"$acx_pthread_ok" = xyes; then | ||
| 198 : | ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) | ||
| 199 : | : | ||
| 200 : | else | ||
| 201 : | acx_pthread_ok=no | ||
| 202 : | $2 | ||
| 203 : | fi | ||
| 204 : | AC_LANG_RESTORE | ||
| 205 : | ])dnl ACX_PTHREAD |
| Administrator | ViewVC Help |
| Powered by ViewVC 1.0.3 |