]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
musl: split out script to setup build
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 16 Nov 2025 19:36:07 +0000 (20:36 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 17 Nov 2025 16:02:23 +0000 (17:02 +0100)
This makes it easier to set up a local build with musl:
$ tools/setup-musl-build.sh build-meson
$ ninja -C build-meson

.github/workflows/build-test-musl.sh
tools/setup-musl-build.sh [new file with mode: 0755]

index 396d8732b0ffa720f6a9358a080746c94f91630c..a2c6d8e2bb4a625e6ef526703c32770265cef115 100755 (executable)
@@ -20,73 +20,5 @@ cleanup() (
 
 trap cleanup EXIT ERR INT TERM
 
-mkdir -p "${TMPDIR}/build"
-mkdir -p "${TMPDIR}/usr/include"
-
-CFLAGS="-idirafter ${TMPDIR}/usr/include"
-
-LINKS=(
-    acl
-    archive.h
-    archive_entry.h
-    asm
-    asm-generic
-    audit-records.h
-    audit_logging.h
-    bpf
-    bzlib.h
-    curl
-    dwarf.h
-    elfutils
-    fido.h
-    gcrypt.h
-    gelf.h
-    gnutls
-    gpg-error.h
-    idn2.h
-    libaudit.h
-    libcryptsetup.h
-    libelf.h
-    libkmod.h
-    linux
-    lz4.h
-    lz4frame.h
-    lz4hc.h
-    lzma
-    lzma.h
-    microhttpd.h
-    mtd
-    openssl
-    pcre2.h
-    pwquality.h
-    qrencode.h
-    seccomp-syscalls.h
-    seccomp.h
-    security
-    selinux
-    sys/acl.h
-    sys/capability.h
-    tss2
-    xen
-    xkbcommon
-    zconf.h
-    zlib.h
-    zstd.h
-    zstd_errors.h
-)
-
-for t in "${LINKS[@]}"; do
-    [[ -e /usr/include/"$t" ]]
-    link="${TMPDIR}"/usr/include/"${t}"
-    mkdir -p "${link%/*}"
-    ln -s /usr/include/"$t" "$link"
-done
-
-env \
-    CC=musl-gcc \
-    CXX=musl-gcc \
-    CFLAGS="$CFLAGS" \
-    CXXFLAGS="$CFLAGS" \
-    meson setup --werror -Ddbus-interfaces-dir=no -Dlibc=musl "${TMPDIR}"/build
-
-ninja -v -C "${TMPDIR}"/build
+tools/setup-musl-build.sh "${TMPDIR}/build"
+ninja -v -C "${TMPDIR}/build"
diff --git a/tools/setup-musl-build.sh b/tools/setup-musl-build.sh
new file mode 100755 (executable)
index 0000000..b0fa764
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+# Usage:
+#   tools/setup-musl-build.sh <build-directory> <options…>
+# E.g.
+#   tools/setup-musl-build.sh build-musl -Dbuildtype=debugoptimized && ninja -C build-musl
+
+set -eu
+
+BUILD_DIR="${1:?}"
+shift
+
+SETUP_DIR="${BUILD_DIR}/extra"
+
+LINKS=(
+    acl
+    archive.h
+    archive_entry.h
+    asm
+    asm-generic
+    audit-records.h
+    audit_logging.h
+    bpf
+    bzlib.h
+    curl
+    dwarf.h
+    elfutils
+    fido.h
+    gcrypt.h
+    gelf.h
+    gnutls
+    gpg-error.h
+    idn2.h
+    libaudit.h
+    libcryptsetup.h
+    libelf.h
+    libkmod.h
+    linux
+    lz4.h
+    lz4frame.h
+    lz4hc.h
+    lzma
+    lzma.h
+    microhttpd.h
+    mtd
+    openssl
+    pcre2.h
+    pwquality.h
+    qrencode.h
+    seccomp-syscalls.h
+    seccomp.h
+    security
+    selinux
+    sys/acl.h
+    sys/capability.h
+    tss2
+    xen
+    xkbcommon
+    zconf.h
+    zlib.h
+    zstd.h
+    zstd_errors.h
+)
+
+for t in "${LINKS[@]}"; do
+    [[ -e /usr/include/"$t" ]]
+    link="${SETUP_DIR}/usr/include/${t}"
+    mkdir -p "${link%/*}"
+    ln -s /usr/include/"$t" "$link"
+done
+
+# Use an absolute path so that when we chdir into the build directory,
+# the path still works. This is easier than figuring out the relative path.
+[[ "${SETUP_DIR}" =~ ^/ ]] || SETUP_DIR="${PWD}/${SETUP_DIR}"
+
+CFLAGS="-idirafter ${SETUP_DIR}/usr/include"
+
+set -x
+env \
+    CC=musl-gcc \
+    CXX=musl-gcc \
+    CFLAGS="$CFLAGS" \
+    CXXFLAGS="$CFLAGS" \
+    meson setup -Ddbus-interfaces-dir=no -Dlibc=musl "${BUILD_DIR}" "${@}"