config-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] config.guess: combine two heuristics to detect musl libc


From: Dmitry V. Levin
Subject: [PATCH] config.guess: combine two heuristics to detect musl libc
Date: Thu, 5 Nov 2020 08:00:00 +0000

Apparently, this is needed to correctly detect musl libc in different
versions of Alpine Linux.

According to
https://lists.gnu.org/archive/html/config-patches/2020-09/msg00002.html,
the ldd based check does not work for some old versions of the Alpine Linux,
and, according to
https://lists.gnu.org/archive/html/config-patches/2020-11/msg00002.html,
the compiler may not be available in a fresh Alpine container.

The ldd based check is essentially the same as the check that was
introduced by commit 3d00f60242f1726fc6eaa38e09435a969ee7ebe5, it is
performed iff the compiler based check could not give a definitive
answer.

Reported-by: Cheng XU <xucheng@me.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
---
 ChangeLog    |  4 ++++
 config.guess | 22 +++++++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 06a7553..8e97a97 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2020-11-05  Dmitry V. Levin  <ldv@altlinux.org>
+
+       * config.guess: Combine two heuristics to detect musl libc.
+
 2020-10-22  Rin Okuyama  <rin@netbsd.org>
 
        * config.guess (*:NetBSD:*:*): Handle aarch64eb.
diff --git a/config.guess b/config.guess
index 12dd5b4..b5456f8 100755
--- a/config.guess
+++ b/config.guess
@@ -138,9 +138,7 @@ UNAME_VERSION=`(uname -v) 2>/dev/null` || 
UNAME_VERSION=unknown
 
 case "$UNAME_SYSTEM" in
 Linux|GNU|GNU/*)
-       # If the system lacks a compiler, then just pick glibc.
-       # We could probably try harder.
-       LIBC=gnu
+       LIBC=unknown
 
        set_cc_for_build
        cat <<-EOF > "$dummy.c"
@@ -149,16 +147,30 @@ Linux|GNU|GNU/*)
        LIBC=uclibc
        #elif defined(__dietlibc__)
        LIBC=dietlibc
+       #elif defined(__GLIBC__)
+       LIBC=gnu
        #else
        #include <stdarg.h>
+       /* First heuristic to detect musl libc.  */
        #ifdef __DEFINED_va_list
        LIBC=musl
-       #else
-       LIBC=gnu
        #endif
        #endif
        EOF
        eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, 
,,g'`"
+
+       # Second heuristic to detect musl libc.
+       if [ "$LIBC" = unknown ] &&
+          command -v ldd >/dev/null &&
+          ldd --version 2>&1 | grep -q ^musl; then
+               LIBC=musl
+       fi
+
+       # If the system lacks a compiler, then just pick glibc.
+       # We could probably try harder.
+       if [ "$LIBC" = unknown ]; then
+               LIBC=gnu
+       fi
        ;;
 esac
 
-- 
ldv



reply via email to

[Prev in Thread] Current Thread [Next in Thread]