Blog/content/posts/2022/c/detect-musl.md
2022-12-28 00:46:21 +03:00

1.0 KiB
Raw Blame History

title date draft tags
💪🏻 Detect Musl 2022-07-31T16:00:15+03:00 false
linux
c
musl

Пост — чистейшая копипаста с SoF.

#! /bin/sh

tmpf=/tmp/musl.log

# Detect Musl C library.
libc=$(ldd /bin/ls | grep 'musl' | head -1 | cut -d ' ' -f1)
if [ -z $libc ]; then
    # This is not Musl.
    rm -f ${tmpf}
    exit 1
fi
$libc >${tmpf} 2>&1
vstr=$(cat ${tmpf} | grep "Version" | cut -d ' ' -f2)

v_major=$(echo $vstr | cut -d '.' -f1)
v_minor=$(echo $vstr | cut -d '.' -f2)
v_patch=$(echo $vstr | cut -d '.' -f3)

rm -f ${tmpf}

echo "-D__MUSL__ -D__MUSL_VER_MAJOR__=${v_major} -D__MUSL_VER_MINOR__=${v_minor} -D__MUSL_VER_PATCH__=${v_patch}"
$ ./detect-musl.sh 
  -D__MUSL__ -D__MUSL_VER_MAJOR__=1 -D__MUSL_VER_MINOR__=1 -D__MUSL_VER_PATCH__=24
$ /lib/ld-musl-x86_64.so.1
  musl libc (x86_64)
  Version 1.2.3
  Dynamic Program Loader
  Usage: /lib/ld-musl-x86_64.so.1 [options] [--] pathname [args]