You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.5 KiB

  1. dnl Copyright (c) 1999, 2000 Sascha Schumann. All rights reserved.
  2. dnl
  3. dnl Redistribution and use in source and binary forms, with or without
  4. dnl modification, are permitted provided that the following conditions
  5. dnl are met:
  6. dnl
  7. dnl 1. Redistributions of source code must retain the above copyright
  8. dnl notice, this list of conditions and the following disclaimer.
  9. dnl
  10. dnl 2. Redistributions in binary form must reproduce the above copyright
  11. dnl notice, this list of conditions and the following disclaimer in
  12. dnl the documentation and/or other materials provided with the
  13. dnl distribution.
  14. dnl
  15. dnl THIS SOFTWARE IS PROVIDED BY SASCHA SCHUMANN ``AS IS'' AND ANY
  16. dnl EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. dnl PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SASCHA SCHUMANN OR
  19. dnl HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. dnl NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. dnl LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. dnl STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. dnl ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  26. dnl OF THE POSSIBILITY OF SUCH DAMAGE.
  27. dnl
  28. dnl PTHREADS_FLAGS
  29. dnl
  30. dnl Set some magic defines to achieve POSIX threads conformance
  31. dnl
  32. AC_DEFUN(PTHREADS_FLAGS,[
  33. if test -z "$host_alias" && test -n "$host"; then
  34. host_alias=$host
  35. fi
  36. if test -z "$host_alias"; then
  37. AC_MSG_ERROR(host_alias is not set. Make sure to run config.guess)
  38. fi
  39. case $host_alias in
  40. *solaris*)
  41. PTHREAD_FLAGS="-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT";;
  42. *freebsd*)
  43. PTHREAD_FLAGS="-D_REENTRANT -D_THREAD_SAFE";;
  44. *linux*)
  45. PTHREAD_FLAGS=-D_REENTRANT;;
  46. *aix*)
  47. PTHREAD_FLAGS=-D_THREAD_SAFE;;
  48. *irix*)
  49. PTHREAD_FLAGS=-D_POSIX_THREAD_SAFE_FUNCTIONS;;
  50. *hpux*)
  51. PTHREAD_FLAGS=-D_REENTRANT;;
  52. *sco*)
  53. PTHREAD_FLAGS=-D_REENTRANT;;
  54. dnl Solves sigwait() problem, creates problems with u_long etc.
  55. dnl PTHREAD_FLAGS="-D_REENTRANT -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=199506 -D_XOPEN_SOURCE_EXTENDED=1";;
  56. esac
  57. if test -n "$PTHREAD_FLAGS"; then
  58. CPPFLAGS="$CPPFLAGS $PTHREAD_FLAGS"
  59. fi
  60. ])dnl
  61. dnl
  62. dnl PTHREADS_CHECK_COMPILE
  63. dnl
  64. dnl Check whether the current setup can use POSIX threads calls
  65. dnl
  66. AC_DEFUN(PTHREADS_CHECK_COMPILE, [
  67. AC_TRY_RUN( [
  68. #include <pthread.h>
  69. #include <stddef.h>
  70. void *thread_routine(void *data) {
  71. return data;
  72. }
  73. int main() {
  74. pthread_t thd;
  75. pthread_mutexattr_t mattr;
  76. int data = 1;
  77. pthread_mutexattr_init(&mattr);
  78. return pthread_create(&thd, NULL, thread_routine, &data);
  79. } ], [
  80. pthreads_working=yes
  81. ], [
  82. pthreads_working=no
  83. ], pthreads_working=no ) ] )dnl
  84. dnl
  85. dnl PTHREADS_CHECK()
  86. dnl
  87. dnl Try to find a way to enable POSIX threads
  88. dnl
  89. dnl Magic flags
  90. dnl -kthread gcc (FreeBSD)
  91. dnl -Kthread UDK cc (UnixWare)
  92. dnl -mt WorkShop cc (Solaris)
  93. dnl -mthreads gcc (AIX)
  94. dnl -pthread gcc (Linux, FreeBSD, NetBSD, OpenBSD)
  95. dnl -pthreads gcc (Solaris)
  96. dnl -qthreaded AIX cc V5
  97. dnl -threads gcc (HP-UX)
  98. dnl
  99. AC_DEFUN(PTHREADS_CHECK,[
  100. save_CFLAGS=$CFLAGS
  101. save_LIBS=$LIBS
  102. PTHREADS_ASSIGN_VARS
  103. PTHREADS_CHECK_COMPILE
  104. LIBS=$save_LIBS
  105. CFLAGS=$save_CFLAGS
  106. AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
  107. ac_cv_pthreads_cflags=
  108. if test "$pthreads_working" != "yes"; then
  109. for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
  110. ac_save=$CFLAGS
  111. CFLAGS="$CFLAGS $flag"
  112. PTHREADS_CHECK_COMPILE
  113. CFLAGS=$ac_save
  114. if test "$pthreads_working" = "yes"; then
  115. ac_cv_pthreads_cflags=$flag
  116. break
  117. fi
  118. done
  119. fi
  120. ])
  121. AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
  122. ac_cv_pthreads_lib=
  123. if test "$pthreads_working" != "yes"; then
  124. for lib in pthread pthreads c_r; do
  125. ac_save=$LIBS
  126. LIBS="$LIBS -l$lib"
  127. PTHREADS_CHECK_COMPILE
  128. LIBS=$ac_save
  129. if test "$pthreads_working" = "yes"; then
  130. ac_cv_pthreads_lib=$lib
  131. break
  132. fi
  133. done
  134. fi
  135. ])
  136. if test "$pthreads_working" = "yes"; then
  137. threads_result="POSIX-Threads found"
  138. else
  139. threads_result="POSIX-Threads not found"
  140. fi
  141. ])dnl
  142. dnl
  143. dnl
  144. AC_DEFUN(PTHREADS_ASSIGN_VARS,[
  145. if test -n "$ac_cv_pthreads_lib"; then
  146. LIBS="$LIBS -l$ac_cv_pthreads_lib"
  147. fi
  148. if test -n "$ac_cv_pthreads_cflags"; then
  149. CFLAGS="$CFLAGS $ac_cv_pthreads_cflags"
  150. fi
  151. ])dnl