From c6dd263ab1b7fb92dc323c5b17d418f0f09c3cec Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Sun, 7 May 2023 18:19:24 -0400 Subject: [PATCH] make: silence clang complaining of -pthread The clang linker doesn't need -pthread and warns of unknown command-line option. This detects clang and forgoes the -pthread flag to the linker. Change-Id: I658cd887c567a5beeeae0e6e1b6d596231894c1b Signed-off-by: Ashod Nakashian --- Makefile.am | 7 ++++++- configure.ac | 14 ++++++++++++++ test/Makefile.am | 7 ++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index a2c427e5a..a96fe521f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,7 +83,12 @@ if !ENABLE_DEBUG AM_CPPFLAGS += -DNDEBUG endif -AM_LDFLAGS = -pthread -Wl,-E -lpam $(ZLIB_LIBS) $(ZSTD_LIBS) ${PNG_LIBS} +AM_LDFLAGS = -Wl,-E -lpam $(ZLIB_LIBS) $(ZSTD_LIBS) ${PNG_LIBS} + +# Clang's linker doesn't like -pthread. +if !HAVE_CLANG +AM_LDFLAGS += -pthread +endif if ENABLE_SSL AM_LDFLAGS += ${OPENSSL_LIBS} diff --git a/configure.ac b/configure.ac index 376c9806c..71de82c46 100644 --- a/configure.ac +++ b/configure.ac @@ -1023,6 +1023,20 @@ else AC_MSG_ERROR(Compiler doesn't support C++17) fi +# Check if we have clang, rather than gcc, which +# doesn't like -pthread on the linker command-line. +AC_MSG_CHECKING([whether the compiler is clang]) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #if !defined(__clang__) + #error not clang + #endif +])], + [AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_CLANG],1,[whether the C++ compiler is clang])], + [AC_MSG_RESULT([no]) + AC_DEFINE([HAVE_CLANG],0,[whether the C++ compiler is clang])]) +AM_CONDITIONAL([HAVE_CLANG], [test "$HAVE_CLANG" = "1"]) + AS_IF([test "$ENABLE_GTKAPP" != true], [CXXFLAGS="$CXXFLAGS $CXXFLAGS_CXXSTD"]) diff --git a/test/Makefile.am b/test/Makefile.am index dd3b8a229..1b23e6dd7 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -93,7 +93,12 @@ endif noinst_LTLIBRARIES = ${all_la_unit_tests} MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy -AM_LDFLAGS = -pthread -module $(MAGIC_TO_FORCE_SHLIB_CREATION) $(ZLIB_LIBS) $(ZSTD_LIBS) ${PNG_LIBS} +AM_LDFLAGS = -module $(MAGIC_TO_FORCE_SHLIB_CREATION) $(ZLIB_LIBS) $(ZSTD_LIBS) ${PNG_LIBS} + +# Clang's linker doesn't like -pthread. +if !HAVE_CLANG +AM_LDFLAGS += -pthread +endif if ENABLE_SSL AM_LDFLAGS += ${OPENSSL_LIBS}