[c5c522c] | 1 | # $Id: pthread.m4,v 1.3 2004/11/20 23:33:25 jonz Exp $ |
---|
| 2 | # Autuconf macros for checking how to compile with pthreads |
---|
| 3 | # Jonathan Zdziarski <jonathan@nuclearelephant.com> |
---|
| 4 | # |
---|
| 5 | # Public available macro: |
---|
| 6 | # DS_PTHREADS([pthreads_cppflags_out], |
---|
| 7 | # [pthreads_ldflags_out], |
---|
| 8 | # [pthreads_libs_out], |
---|
| 9 | # [additional-action-if-found], |
---|
| 10 | # [additional-action-if-not-found]) |
---|
| 11 | # |
---|
| 12 | AC_DEFUN([DS_PTHREADS], |
---|
| 13 | [ |
---|
| 14 | ds_pthreads_save_CPPFLAGS="$CPPFLAGS" |
---|
| 15 | ds_pthreads_save_LDFLAGS="$LDFLAGS" |
---|
| 16 | ds_pthreads_save_LIBS="$LIBS" |
---|
| 17 | |
---|
| 18 | ds_pthreads_CPPFLAGS="" |
---|
| 19 | ds_pthreads_LDFLAGS="" |
---|
| 20 | ds_pthreads_LIBS="" |
---|
| 21 | |
---|
| 22 | AC_MSG_CHECKING([how you like your pthreads]) |
---|
| 23 | pthreads_success="no" |
---|
| 24 | |
---|
| 25 | LIBS="$ds_pthreads_save_LIBS -pthread" |
---|
| 26 | |
---|
| 27 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
---|
| 28 | #include <pthread.h> |
---|
| 29 | #include <stdlib.h> |
---|
| 30 | |
---|
| 31 | int main() { |
---|
| 32 | |
---|
| 33 | pthread_mutex_t m; |
---|
| 34 | pthread_mutex_init(&m, NULL); |
---|
| 35 | pthread_exit(0); |
---|
| 36 | exit(EXIT_FAILURE); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | ]])], |
---|
| 40 | [ |
---|
| 41 | pthreads_success="yes" |
---|
| 42 | ds_pthreads_LIBS="-pthread" |
---|
| 43 | AC_MSG_RESULT([-pthread]) |
---|
| 44 | ], |
---|
| 45 | [ ]) |
---|
| 46 | |
---|
| 47 | if test x"$pthreads_success" = xno |
---|
| 48 | then |
---|
| 49 | LIBS="$ds_pthreads_save_LIBS -lpthread" |
---|
| 50 | |
---|
| 51 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
---|
| 52 | #include <pthread.h> |
---|
| 53 | #include <stdlib.h> |
---|
| 54 | |
---|
| 55 | int main() { |
---|
| 56 | pthread_mutex_t m; |
---|
| 57 | pthread_mutex_init(&m, NULL); |
---|
| 58 | pthread_exit(0); |
---|
| 59 | exit(EXIT_FAILURE); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | ]])], |
---|
| 63 | [ |
---|
| 64 | pthreads_success="yes" |
---|
| 65 | ds_pthreads_LIBS="-lpthread" |
---|
| 66 | AC_MSG_RESULT([-lpthread]) |
---|
| 67 | ], |
---|
| 68 | [ ]) |
---|
| 69 | fi |
---|
| 70 | |
---|
| 71 | if test x"$pthreads_success" = xno |
---|
| 72 | then |
---|
| 73 | LIBS="$ds_pthreads_save_LIBS -lpthread -mt" |
---|
| 74 | |
---|
| 75 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
---|
| 76 | #include <pthread.h> |
---|
| 77 | #include <stdlib.h> |
---|
| 78 | |
---|
| 79 | int main() { |
---|
| 80 | pthread_mutex_t m; |
---|
| 81 | pthread_mutex_init(&m, NULL); |
---|
| 82 | pthread_exit(0); |
---|
| 83 | exit(EXIT_FAILURE); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | ]])], |
---|
| 87 | [ |
---|
| 88 | pthreads_success="yes" |
---|
| 89 | ds_pthreads_LIBS="-lpthread -mt" |
---|
| 90 | AC_MSG_RESULT([-lpthread -mt]) |
---|
| 91 | ], |
---|
| 92 | [ ]) |
---|
| 93 | fi |
---|
| 94 | |
---|
| 95 | if test x"$pthreads_success" = xno |
---|
| 96 | then |
---|
| 97 | AC_MSG_RESULT([unknown]) |
---|
| 98 | AC_MSG_ERROR([Unable to determine how to compile with pthreads]) |
---|
| 99 | fi |
---|
| 100 | |
---|
| 101 | CPPFLAGS="$ds_pthreads_save_CPPFLAGS" |
---|
| 102 | LDFLAGS="$ds_pthreads_save_LDFLAGS" |
---|
| 103 | LIBS="$ds_pthreads_save_LIBS" |
---|
| 104 | |
---|
| 105 | if test x"$pthreads_success" = xyes |
---|
| 106 | then |
---|
| 107 | ifelse([$1], [], [:], [$1="$ds_pthreads_CPPFLAGS"]) |
---|
| 108 | ifelse([$2], [], [:], [$2="$ds_pthreads_LDFLAGS"]) |
---|
| 109 | ifelse([$3], [], [:], [$3="$ds_pthreads_LIBS"]) |
---|
| 110 | ifelse([$4], [], [:], [$4]) |
---|
| 111 | : |
---|
| 112 | else |
---|
| 113 | ifelse([$5], [], [:], [$5]) |
---|
| 114 | : |
---|
| 115 | fi |
---|
| 116 | ]) |
---|