From 33b3ba3fc71ada906bfeb05eee937661c32b2877 Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Thu, 9 Apr 2020 12:05:16 -0700 Subject: configure.ac: Enhance compiler checks for pthreads There apparently exist some compiler ports (e.g Haiku's GCC) that do not support the ubiquitous '-pthread' compiler option. Add a check for this and only use the option if supported. Also tweak the check for the pthread library to check for the pthread_create() function. Even though libusb does not use this function, it seems to be sufficiently distinct such that the standard C library would not provide this directly if the pthread implementation resided in a separate library. Also explicitly check whether no additional library linkage is required. Signed-off-by: Chris Dickens --- configure.ac | 14 ++++++++++++-- libusb/version_nano.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 2aaa9e6..d386053 100644 --- a/configure.ac +++ b/configure.ac @@ -153,10 +153,20 @@ fi if test "x$threads" = xposix; then AC_DEFINE([THREADS_POSIX], [1], [Define to 1 if using POSIX threads.]) - AC_SUBST(THREAD_CFLAGS, [-pthread]) + dnl Some compilers do not support the '-pthread' option so check for it here + saved_CFLAGS="${CFLAGS}" + CFLAGS="-Wall -Werror -pthread" + AC_MSG_CHECKING([if $CC recognizes -pthread]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], + [AC_MSG_RESULT([yes]) + AC_SUBST(THREAD_CFLAGS, [-pthread])], + [AC_MSG_RESULT([no])]) + CFLAGS="${saved_CFLAGS}" dnl Android Linux and Darwin provide pthread functions directly in libc dnl glibc also provides some pthread functions directly, so search for a thread-specific function - AC_SEARCH_LIBS([pthread_key_create], [pthread], [AC_SUBST(THREAD_LIBS, [-lpthread])], [], []) + AC_SEARCH_LIBS([pthread_create], [pthread], + [test "x$ac_cv_search_pthread_create" != "xnone required" && AC_SUBST(THREAD_LIBS, [-lpthread])], + [], []) elif test "x$threads" = xwindows; then AC_DEFINE([THREADS_WINDOWS], [1], [Define to 1 if using Windows threads.]) else diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 07b0839..f5243a0 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11488 +#define LIBUSB_NANO 11489 -- cgit v1.2.1