Skip to content

Commit 4e7e936

Browse files
shivammathurgithub-actions[bot]
authored andcommitted
Fix pthreads detection when cross-compiling
1 parent 438baf4 commit 4e7e936

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

TSRM/threads.m4

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ dnl
6666
dnl Check whether the current setup can use POSIX threads calls
6767
dnl
6868
AC_DEFUN([PTHREADS_CHECK_COMPILE], [
69-
AC_TRY_RUN( [
69+
AC_LINK_IFELSE([ AC_LANG_SOURCE([
7070
#include <pthread.h>
7171
#include <stddef.h>
7272
@@ -80,18 +80,11 @@ int main() {
8080
int data = 1;
8181
pthread_mutexattr_init(&mattr);
8282
return pthread_create(&thd, NULL, thread_routine, &data);
83-
} ], [
84-
pthreads_working=yes
83+
} ]) ], [
84+
pthreads_checked=yes
8585
], [
86-
pthreads_working=no
87-
], [
88-
dnl For cross compiling running this test is of no use. NetWare supports pthreads
89-
pthreads_working=no
90-
case $host_alias in
91-
*netware*)
92-
pthreads_working=yes
93-
esac
94-
]
86+
pthreads_checked=no
87+
]
9588
) ] )dnl
9689
dnl
9790
dnl PTHREADS_CHECK()
@@ -129,30 +122,34 @@ else
129122
CFLAGS="$CFLAGS $flag"
130123
PTHREADS_CHECK_COMPILE
131124
CFLAGS=$ac_save
132-
if test "$pthreads_working" = "yes"; then
125+
if test "$pthreads_checked" = "yes"; then
133126
ac_cv_pthreads_cflags=$flag
134127
break
135128
fi
136129
done
137130
fi
138-
fi
139-
])
131+
])
132+
133+
AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
134+
ac_cv_pthreads_lib=
135+
if test "$pthreads_working" != "yes"; then
136+
for lib in pthread pthreads c_r; do
137+
ac_save=$LIBS
138+
LIBS="$LIBS -l$lib"
139+
PTHREADS_CHECK_COMPILE
140+
LIBS=$ac_save
141+
if test "$pthreads_checked" = "yes"; then
142+
ac_cv_pthreads_lib=$lib
143+
break
144+
fi
145+
done
146+
fi
147+
])
140148
141-
AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
142-
ac_cv_pthreads_lib=
143-
if test "$pthreads_working" != "yes"; then
144-
for lib in pthread pthreads c_r; do
145-
ac_save=$LIBS
146-
LIBS="$LIBS -l$lib"
147-
PTHREADS_CHECK_COMPILE
148-
LIBS=$ac_save
149-
if test "$pthreads_working" = "yes"; then
150-
ac_cv_pthreads_lib=$lib
151-
break
152-
fi
153-
done
149+
if test "x$ac_cv_pthreads_cflags" != "x" -o "x$ac_cv_pthreads_lib" != "x"; then
150+
pthreads_working="yes"
151+
fi
154152
fi
155-
])
156153
157154
if test "$pthreads_working" = "yes"; then
158155
threads_result="POSIX-Threads found"

0 commit comments

Comments
 (0)