]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
configure: fix pthread check with static boringssl
authorPeter Wu <peter@lekensteyn.nl>
Wed, 20 May 2020 21:36:21 +0000 (23:36 +0200)
committerPeter Wu <peter@lekensteyn.nl>
Fri, 22 May 2020 19:10:07 +0000 (21:10 +0200)
A shared boringssl/OpenSSL library requires -lcrypto only for linking.
A static build additionally requires `-ldl -lpthread`. In the latter
case `-lpthread` is added to LIBS which prevented `-pthread` from being
added to CFLAGS. Clear LIBS to fix linking failures for libtest tests.

configure.ac

index 9e1fdbebab1507b7144f45965e2d30b53fc7cd82..0c1decc7243eba6542db91a55dfd88f7807c6c63 100755 (executable)
@@ -1744,6 +1744,8 @@ if test -z "$ssl_backends" -o "x$OPT_SSL" != xno &&
        # only set this if pkg-config wasn't used
        CPPFLAGS="$CLEANCPPFLAGS -I$PREFIX_OPENSSL/include/openssl -I$PREFIX_OPENSSL/include"
      fi
+     # Linking previously failed, try extra paths from --with-ssl or pkg-config.
+     # Use a different function name to avoid reusing the earlier cached result.
      AC_CHECK_LIB(crypto, HMAC_Init_ex,[
        HAVECRYPTO="yes"
        LIBS="-lcrypto $LIBS"], [
@@ -1765,6 +1767,7 @@ if test -z "$ssl_backends" -o "x$OPT_SSL" != xno &&
        [
          AC_MSG_RESULT(no)
          dnl ok, so what about both -ldl and -lpthread?
+         dnl This may be necessary for static libraries.
 
          AC_MSG_CHECKING([OpenSSL linking with -ldl and -lpthread])
          LIBS="$CLEANLIBS -lcrypto -ldl -lpthread"
@@ -4312,9 +4315,17 @@ if test "$want_pthreads" != "no"; then
   AC_CHECK_HEADER(pthread.h,
     [ AC_DEFINE(HAVE_PTHREAD_H, 1, [if you have <pthread.h>])
       save_CFLAGS="$CFLAGS"
-
-      dnl first check for function without lib
+      dnl When statically linking against boringssl, -lpthread is added to LIBS.
+      dnl Make sure to that this does not pass the check below, we really want
+      dnl -pthread in CFLAGS as recommended for GCC. This also ensures that
+      dnl lib1541 and lib1565 tests are built with these options. Otherwise
+      dnl they fail the build since tests/libtest/Makefile.am clears LIBS.
+      save_LIBS="$LIBS"
+
+      LIBS=
+      dnl Check for libc variants without a separate pthread lib like bionic
       AC_CHECK_FUNC(pthread_create, [USE_THREADS_POSIX=1] )
+      LIBS="$save_LIBS"
 
       dnl on HPUX, life is more complicated...
       case $host in