🏴‍☠️
Сашка ☕
Blog  Tags 
💀 🔵 🔴

💪🏻 Detect Musl

Опубликовано: 31 июля 2022 г.

Пост — чистейшая копипаста с 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]