Skip to content

eBPF-based security platform

build: find the system static archives on Fedora and RHEL hosts

Puranjay Mohanece3c773851a
diff --git a/Makefile.target-deps b/Makefile.target-deps
index 69dba49b..a668f4a6 100644
--- a/Makefile.target-deps
+++ b/Makefile.target-deps
@@ -33,7 +33,16 @@ CURL_VERSION ?= 8.18.0
TSS_VERSION ?= 4.1.3
TARGET_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null || gcc -print-multiarch)
-TARGET_SYSTEM_LIBDIR ?= /usr/lib/$(TARGET_MULTIARCH)
+
+# The multiarch directory on Debian, /usr/lib64 on Fedora and RHEL: the
+# first that holds libelf.a, else the first candidate.
+TARGET_SYSTEM_ROOT ?= /usr
+TARGET_SYSTEM_LIBDIRS := \
+ $(if $(TARGET_MULTIARCH),$(TARGET_SYSTEM_ROOT)/lib/$(TARGET_MULTIARCH)) \
+ $(TARGET_SYSTEM_ROOT)/lib64 $(TARGET_SYSTEM_ROOT)/lib
+TARGET_SYSTEM_LIBDIR ?= $(firstword \
+ $(foreach d,$(TARGET_SYSTEM_LIBDIRS),$(if $(wildcard $(d)/libelf.a),$(d))) \
+ $(TARGET_SYSTEM_LIBDIRS))
OPENSSL_PKG_CONFIG_PATH := $(TARGET_OPENSSL_PREFIX)/lib/pkgconfig
diff --git a/testing/t0045-target-system-libdir.sh b/testing/t0045-target-system-libdir.sh
new file mode 100644
index 00000000..c81de0d7
--- /dev/null
+++ b/testing/t0045-target-system-libdir.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+
+cd "$(dirname "$0")"
+. ./test-lib.sh
+
+WORK=$(mktemp -d)
+trap 'rm -rf "$WORK"' EXIT
+printf 'show:\n\t@echo $(TARGET_SYSTEM_LIBDIR)\n' >"$WORK/show.mk"
+
+libdir() {
+ multiarch=$1 root=$2
+ shift 2
+ env -u TARGET_SYSTEM_LIBDIR make -s -f ../Makefile.target-deps \
+ -f "$WORK/show.mk" show TARGET_MULTIARCH="$multiarch" \
+ TARGET_SYSTEM_ROOT="$root" "$@" 2>/dev/null
+}
+
+test_expect_success 'the system archives are found in the Debian multiarch directory' '
+ mkdir -p "$WORK/deb/lib/aarch64-linux-gnu" &&
+ : >"$WORK/deb/lib/aarch64-linux-gnu/libelf.a" &&
+ test "$(libdir aarch64-linux-gnu "$WORK/deb")" = \
+ "$WORK/deb/lib/aarch64-linux-gnu"
+'
+
+test_expect_success 'the system archives are found in lib64 where gcc has no multiarch name' '
+ mkdir -p "$WORK/rpm/lib64" &&
+ : >"$WORK/rpm/lib64/libelf.a" &&
+ test "$(libdir "" "$WORK/rpm")" = "$WORK/rpm/lib64"
+'
+
+test_expect_success 'the multiarch directory wins over lib64 and lib' '
+ mkdir -p "$WORK/all/lib/x86_64-linux-gnu" "$WORK/all/lib64" &&
+ : >"$WORK/all/lib/x86_64-linux-gnu/libelf.a" &&
+ : >"$WORK/all/lib64/libelf.a" &&
+ : >"$WORK/all/lib/libelf.a" &&
+ test "$(libdir x86_64-linux-gnu "$WORK/all")" = \
+ "$WORK/all/lib/x86_64-linux-gnu"
+'
+
+test_expect_success 'a plain lib directory is found' '
+ mkdir -p "$WORK/plain/lib" &&
+ : >"$WORK/plain/lib/libelf.a" &&
+ test "$(libdir "" "$WORK/plain")" = "$WORK/plain/lib"
+'
+
+test_expect_success 'without any archive the Debian path is reported' '
+ mkdir -p "$WORK/none" &&
+ test "$(libdir x86_64-linux-gnu "$WORK/none")" = \
+ "$WORK/none/lib/x86_64-linux-gnu"
+'
+
+test_expect_success 'an explicit TARGET_SYSTEM_LIBDIR is kept' '
+ test "$(libdir x86_64-linux-gnu "$WORK/rpm" TARGET_SYSTEM_LIBDIR=/elsewhere)" \
+ = /elsewhere
+'
+
+test_done