1
0

ax_pthread.m4 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_pthread.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro figures out how to build C programs using POSIX threads. It
  12. # sets the PTHREAD_LIBS output variable to the threads library and linker
  13. # flags, and the PTHREAD_CFLAGS output variable to any special C compiler
  14. # flags that are needed. (The user can also force certain compiler
  15. # flags/libs to be tested by setting these environment variables.)
  16. #
  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.)
  21. #
  22. # NOTE: You are assumed to not only compile your program with these flags,
  23. # but also to link with them as well. For example, you might link with
  24. # $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
  25. # $PTHREAD_CXX $CXXFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
  26. #
  27. # If you are only building threaded programs, you may wish to use these
  28. # variables in your default LIBS, CFLAGS, and CC:
  29. #
  30. # LIBS="$PTHREAD_LIBS $LIBS"
  31. # CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  32. # CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
  33. # CC="$PTHREAD_CC"
  34. # CXX="$PTHREAD_CXX"
  35. #
  36. # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
  37. # has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to
  38. # that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
  39. #
  40. # Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the
  41. # PTHREAD_PRIO_INHERIT symbol is defined when compiling with
  42. # PTHREAD_CFLAGS.
  43. #
  44. # ACTION-IF-FOUND is a list of shell commands to run if a threads library
  45. # is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
  46. # is not found. If ACTION-IF-FOUND is not specified, the default action
  47. # will define HAVE_PTHREAD.
  48. #
  49. # Please let the authors know if this macro fails on any platform, or if
  50. # you have any other suggestions or comments. This macro was based on work
  51. # by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
  52. # from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
  53. # Alejandro Forero Cuervo to the autoconf macro repository. We are also
  54. # grateful for the helpful feedback of numerous users.
  55. #
  56. # Updated for Autoconf 2.68 by Daniel Richard G.
  57. #
  58. # LICENSE
  59. #
  60. # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
  61. # Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
  62. # Copyright (c) 2019 Marc Stevens <marc.stevens@cwi.nl>
  63. #
  64. # This program is free software: you can redistribute it and/or modify it
  65. # under the terms of the GNU General Public License as published by the
  66. # Free Software Foundation, either version 3 of the License, or (at your
  67. # option) any later version.
  68. #
  69. # This program is distributed in the hope that it will be useful, but
  70. # WITHOUT ANY WARRANTY; without even the implied warranty of
  71. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  72. # Public License for more details.
  73. #
  74. # You should have received a copy of the GNU General Public License along
  75. # with this program. If not, see <https://www.gnu.org/licenses/>.
  76. #
  77. # As a special exception, the respective Autoconf Macro's copyright owner
  78. # gives unlimited permission to copy, distribute and modify the configure
  79. # scripts that are the output of Autoconf when processing the Macro. You
  80. # need not follow the terms of the GNU General Public License when using
  81. # or distributing such scripts, even though portions of the text of the
  82. # Macro appear in them. The GNU General Public License (GPL) does govern
  83. # all other use of the material that constitutes the Autoconf Macro.
  84. #
  85. # This special exception to the GPL applies to versions of the Autoconf
  86. # Macro released by the Autoconf Archive. When you make and distribute a
  87. # modified version of the Autoconf Macro, you may extend this special
  88. # exception to the GPL to apply to your modified version as well.
  89. #serial 30
  90. AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
  91. AC_DEFUN([AX_PTHREAD], [
  92. AC_REQUIRE([AC_CANONICAL_TARGET])
  93. AC_REQUIRE([AC_PROG_CC])
  94. AC_REQUIRE([AC_PROG_SED])
  95. AC_LANG_PUSH([C])
  96. ax_pthread_ok=no
  97. # We used to check for pthread.h first, but this fails if pthread.h
  98. # requires special compiler flags (e.g. on Tru64 or Sequent).
  99. # It gets checked for in the link test anyway.
  100. # First of all, check if the user has set any of the PTHREAD_LIBS,
  101. # etcetera environment variables, and if threads linking works using
  102. # them:
  103. if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then
  104. ax_pthread_save_CC="$CC"
  105. ax_pthread_save_CFLAGS="$CFLAGS"
  106. ax_pthread_save_LIBS="$LIBS"
  107. AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"])
  108. AS_IF([test "x$PTHREAD_CXX" != "x"], [CXX="$PTHREAD_CXX"])
  109. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  110. LIBS="$PTHREAD_LIBS $LIBS"
  111. AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS])
  112. AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes])
  113. AC_MSG_RESULT([$ax_pthread_ok])
  114. if test "x$ax_pthread_ok" = "xno"; then
  115. PTHREAD_LIBS=""
  116. PTHREAD_CFLAGS=""
  117. fi
  118. CC="$ax_pthread_save_CC"
  119. CFLAGS="$ax_pthread_save_CFLAGS"
  120. LIBS="$ax_pthread_save_LIBS"
  121. fi
  122. # We must check for the threads library under a number of different
  123. # names; the ordering is very important because some systems
  124. # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
  125. # libraries is broken (non-POSIX).
  126. # Create a list of thread flags to try. Items with a "," contain both
  127. # C compiler flags (before ",") and linker flags (after ","). Other items
  128. # starting with a "-" are C compiler flags, and remaining items are
  129. # library names, except for "none" which indicates that we try without
  130. # any flags at all, and "pthread-config" which is a program returning
  131. # the flags for the Pth emulation library.
  132. ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
  133. # The ordering *is* (sometimes) important. Some notes on the
  134. # individual items follow:
  135. # pthreads: AIX (must check this before -lpthread)
  136. # none: in case threads are in libc; should be tried before -Kthread and
  137. # other compiler flags to prevent continual compiler warnings
  138. # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
  139. # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64
  140. # (Note: HP C rejects this with "bad form for `-t' option")
  141. # -pthreads: Solaris/gcc (Note: HP C also rejects)
  142. # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
  143. # doesn't hurt to check since this sometimes defines pthreads and
  144. # -D_REENTRANT too), HP C (must be checked before -lpthread, which
  145. # is present but should not be used directly; and before -mthreads,
  146. # because the compiler interprets this as "-mt" + "-hreads")
  147. # -mthreads: Mingw32/gcc, Lynx/gcc
  148. # pthread: Linux, etcetera
  149. # --thread-safe: KAI C++
  150. # pthread-config: use pthread-config program (for GNU Pth library)
  151. case $target_os in
  152. freebsd*)
  153. # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
  154. # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
  155. ax_pthread_flags="-kthread lthread $ax_pthread_flags"
  156. ;;
  157. hpux*)
  158. # From the cc(1) man page: "[-mt] Sets various -D flags to enable
  159. # multi-threading and also sets -lpthread."
  160. ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags"
  161. ;;
  162. openedition*)
  163. # IBM z/OS requires a feature-test macro to be defined in order to
  164. # enable POSIX threads at all, so give the user a hint if this is
  165. # not set. (We don't define these ourselves, as they can affect
  166. # other portions of the system API in unpredictable ways.)
  167. AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING],
  168. [
  169. # if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS)
  170. AX_PTHREAD_ZOS_MISSING
  171. # endif
  172. ],
  173. [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])])
  174. ;;
  175. solaris*)
  176. # On Solaris (at least, for some versions), libc contains stubbed
  177. # (non-functional) versions of the pthreads routines, so link-based
  178. # tests will erroneously succeed. (N.B.: The stubs are missing
  179. # pthread_cleanup_push, or rather a function called by this macro,
  180. # so we could check for that, but who knows whether they'll stub
  181. # that too in a future libc.) So we'll check first for the
  182. # standard Solaris way of linking pthreads (-mt -lpthread).
  183. ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags"
  184. ;;
  185. esac
  186. # Are we compiling with Clang?
  187. AC_CACHE_CHECK([whether $CC is Clang],
  188. [ax_cv_PTHREAD_CLANG],
  189. [ax_cv_PTHREAD_CLANG=no
  190. # Note that Autoconf sets GCC=yes for Clang as well as GCC
  191. if test "x$GCC" = "xyes"; then
  192. AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG],
  193. [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */
  194. # if defined(__clang__) && defined(__llvm__)
  195. AX_PTHREAD_CC_IS_CLANG
  196. # endif
  197. ],
  198. [ax_cv_PTHREAD_CLANG=yes])
  199. fi
  200. ])
  201. ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
  202. # GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC)
  203. # Note that for GCC and Clang -pthread generally implies -lpthread,
  204. # except when -nostdlib is passed.
  205. # This is problematic using libtool to build C++ shared libraries with pthread:
  206. # [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460
  207. # [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333
  208. # [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555
  209. # To solve this, first try -pthread together with -lpthread for GCC
  210. AS_IF([test "x$GCC" = "xyes"],
  211. [ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"])
  212. # Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first
  213. AS_IF([test "x$ax_pthread_clang" = "xyes"],
  214. [ax_pthread_flags="-pthread,-lpthread -pthread"])
  215. # The presence of a feature test macro requesting re-entrant function
  216. # definitions is, on some systems, a strong hint that pthreads support is
  217. # correctly enabled
  218. case $target_os in
  219. darwin* | hpux* | linux* | osf* | solaris*)
  220. ax_pthread_check_macro="_REENTRANT"
  221. ;;
  222. aix*)
  223. ax_pthread_check_macro="_THREAD_SAFE"
  224. ;;
  225. *)
  226. ax_pthread_check_macro="--"
  227. ;;
  228. esac
  229. AS_IF([test "x$ax_pthread_check_macro" = "x--"],
  230. [ax_pthread_check_cond=0],
  231. [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"])
  232. if test "x$ax_pthread_ok" = "xno"; then
  233. for ax_pthread_try_flag in $ax_pthread_flags; do
  234. case $ax_pthread_try_flag in
  235. none)
  236. AC_MSG_CHECKING([whether pthreads work without any flags])
  237. ;;
  238. *,*)
  239. PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"`
  240. PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"`
  241. AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"])
  242. ;;
  243. -*)
  244. AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag])
  245. PTHREAD_CFLAGS="$ax_pthread_try_flag"
  246. ;;
  247. pthread-config)
  248. AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
  249. AS_IF([test "x$ax_pthread_config" = "xno"], [continue])
  250. PTHREAD_CFLAGS="`pthread-config --cflags`"
  251. PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
  252. ;;
  253. *)
  254. AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag])
  255. PTHREAD_LIBS="-l$ax_pthread_try_flag"
  256. ;;
  257. esac
  258. ax_pthread_save_CFLAGS="$CFLAGS"
  259. ax_pthread_save_LIBS="$LIBS"
  260. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  261. LIBS="$PTHREAD_LIBS $LIBS"
  262. # Check for various functions. We must include pthread.h,
  263. # since some functions may be macros. (On the Sequent, we
  264. # need a special flag -Kthread to make this header compile.)
  265. # We check for pthread_join because it is in -lpthread on IRIX
  266. # while pthread_create is in libc. We check for pthread_attr_init
  267. # due to DEC craziness with -lpthreads. We check for
  268. # pthread_cleanup_push because it is one of the few pthread
  269. # functions on Solaris that doesn't have a non-functional libc stub.
  270. # We try pthread_create on general principles.
  271. AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
  272. # if $ax_pthread_check_cond
  273. # error "$ax_pthread_check_macro must be defined"
  274. # endif
  275. static void *some_global = NULL;
  276. static void routine(void *a)
  277. {
  278. /* To avoid any unused-parameter or
  279. unused-but-set-parameter warning. */
  280. some_global = a;
  281. }
  282. static void *start_routine(void *a) { return a; }],
  283. [pthread_t th; pthread_attr_t attr;
  284. pthread_create(&th, 0, start_routine, 0);
  285. pthread_join(th, 0);
  286. pthread_attr_init(&attr);
  287. pthread_cleanup_push(routine, 0);
  288. pthread_cleanup_pop(0) /* ; */])],
  289. [ax_pthread_ok=yes],
  290. [])
  291. CFLAGS="$ax_pthread_save_CFLAGS"
  292. LIBS="$ax_pthread_save_LIBS"
  293. AC_MSG_RESULT([$ax_pthread_ok])
  294. AS_IF([test "x$ax_pthread_ok" = "xyes"], [break])
  295. PTHREAD_LIBS=""
  296. PTHREAD_CFLAGS=""
  297. done
  298. fi
  299. # Clang needs special handling, because older versions handle the -pthread
  300. # option in a rather... idiosyncratic way
  301. if test "x$ax_pthread_clang" = "xyes"; then
  302. # Clang takes -pthread; it has never supported any other flag
  303. # (Note 1: This will need to be revisited if a system that Clang
  304. # supports has POSIX threads in a separate library. This tends not
  305. # to be the way of modern systems, but it's conceivable.)
  306. # (Note 2: On some systems, notably Darwin, -pthread is not needed
  307. # to get POSIX threads support; the API is always present and
  308. # active. We could reasonably leave PTHREAD_CFLAGS empty. But
  309. # -pthread does define _REENTRANT, and while the Darwin headers
  310. # ignore this macro, third-party headers might not.)
  311. # However, older versions of Clang make a point of warning the user
  312. # that, in an invocation where only linking and no compilation is
  313. # taking place, the -pthread option has no effect ("argument unused
  314. # during compilation"). They expect -pthread to be passed in only
  315. # when source code is being compiled.
  316. #
  317. # Problem is, this is at odds with the way Automake and most other
  318. # C build frameworks function, which is that the same flags used in
  319. # compilation (CFLAGS) are also used in linking. Many systems
  320. # supported by AX_PTHREAD require exactly this for POSIX threads
  321. # support, and in fact it is often not straightforward to specify a
  322. # flag that is used only in the compilation phase and not in
  323. # linking. Such a scenario is extremely rare in practice.
  324. #
  325. # Even though use of the -pthread flag in linking would only print
  326. # a warning, this can be a nuisance for well-run software projects
  327. # that build with -Werror. So if the active version of Clang has
  328. # this misfeature, we search for an option to squash it.
  329. AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread],
  330. [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG],
  331. [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown
  332. # Create an alternate version of $ac_link that compiles and
  333. # links in two steps (.c -> .o, .o -> exe) instead of one
  334. # (.c -> exe), because the warning occurs only in the second
  335. # step
  336. ax_pthread_save_ac_link="$ac_link"
  337. ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g'
  338. ax_pthread_link_step=`AS_ECHO(["$ac_link"]) | sed "$ax_pthread_sed"`
  339. ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)"
  340. ax_pthread_save_CFLAGS="$CFLAGS"
  341. for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do
  342. AS_IF([test "x$ax_pthread_try" = "xunknown"], [break])
  343. CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS"
  344. ac_link="$ax_pthread_save_ac_link"
  345. AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
  346. [ac_link="$ax_pthread_2step_ac_link"
  347. AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
  348. [break])
  349. ])
  350. done
  351. ac_link="$ax_pthread_save_ac_link"
  352. CFLAGS="$ax_pthread_save_CFLAGS"
  353. AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no])
  354. ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try"
  355. ])
  356. case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in
  357. no | unknown) ;;
  358. *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;;
  359. esac
  360. fi # $ax_pthread_clang = yes
  361. # Various other checks:
  362. if test "x$ax_pthread_ok" = "xyes"; then
  363. ax_pthread_save_CFLAGS="$CFLAGS"
  364. ax_pthread_save_LIBS="$LIBS"
  365. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  366. LIBS="$PTHREAD_LIBS $LIBS"
  367. # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
  368. AC_CACHE_CHECK([for joinable pthread attribute],
  369. [ax_cv_PTHREAD_JOINABLE_ATTR],
  370. [ax_cv_PTHREAD_JOINABLE_ATTR=unknown
  371. for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
  372. AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
  373. [int attr = $ax_pthread_attr; return attr /* ; */])],
  374. [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break],
  375. [])
  376. done
  377. ])
  378. AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \
  379. test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \
  380. test "x$ax_pthread_joinable_attr_defined" != "xyes"],
  381. [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE],
  382. [$ax_cv_PTHREAD_JOINABLE_ATTR],
  383. [Define to necessary symbol if this constant
  384. uses a non-standard name on your system.])
  385. ax_pthread_joinable_attr_defined=yes
  386. ])
  387. AC_CACHE_CHECK([whether more special flags are required for pthreads],
  388. [ax_cv_PTHREAD_SPECIAL_FLAGS],
  389. [ax_cv_PTHREAD_SPECIAL_FLAGS=no
  390. case $target_os in
  391. solaris*)
  392. ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS"
  393. ;;
  394. esac
  395. ])
  396. AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \
  397. test "x$ax_pthread_special_flags_added" != "xyes"],
  398. [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS"
  399. ax_pthread_special_flags_added=yes])
  400. AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
  401. [ax_cv_PTHREAD_PRIO_INHERIT],
  402. [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
  403. [[int i = PTHREAD_PRIO_INHERIT;
  404. return i;]])],
  405. [ax_cv_PTHREAD_PRIO_INHERIT=yes],
  406. [ax_cv_PTHREAD_PRIO_INHERIT=no])
  407. ])
  408. AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \
  409. test "x$ax_pthread_prio_inherit_defined" != "xyes"],
  410. [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.])
  411. ax_pthread_prio_inherit_defined=yes
  412. ])
  413. CFLAGS="$ax_pthread_save_CFLAGS"
  414. LIBS="$ax_pthread_save_LIBS"
  415. # More AIX lossage: compile with *_r variant
  416. if test "x$GCC" != "xyes"; then
  417. case $target_os in
  418. aix*)
  419. AS_CASE(["x/$CC"],
  420. [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
  421. [#handle absolute path differently from PATH based program lookup
  422. AS_CASE(["x$CC"],
  423. [x/*],
  424. [
  425. AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])
  426. AS_IF([test "x${CXX}" != "x"], [AS_IF([AS_EXECUTABLE_P([${CXX}_r])],[PTHREAD_CXX="${CXX}_r"])])
  427. ],
  428. [
  429. AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])
  430. AS_IF([test "x${CXX}" != "x"], [AC_CHECK_PROGS([PTHREAD_CXX],[${CXX}_r],[$CXX])])
  431. ]
  432. )
  433. ])
  434. ;;
  435. esac
  436. fi
  437. fi
  438. test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
  439. test -n "$PTHREAD_CXX" || PTHREAD_CXX="$CXX"
  440. AC_SUBST([PTHREAD_LIBS])
  441. AC_SUBST([PTHREAD_CFLAGS])
  442. AC_SUBST([PTHREAD_CC])
  443. AC_SUBST([PTHREAD_CXX])
  444. # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  445. if test "x$ax_pthread_ok" = "xyes"; then
  446. ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1])
  447. :
  448. else
  449. ax_pthread_ok=no
  450. $2
  451. fi
  452. AC_LANG_POP
  453. ])dnl AX_PTHREAD