From d91b6dac7dd7c0879b3a4a5f8f3abd82c33780b7 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sat, 17 Sep 2022 15:38:12 -0700
Subject: imx-gpu-viv: Insert libgcompat.so to DT_NEEDED section of libs

These libs are pre-compiled for glibc therefore, on musl they will need
redirecting via the gcompat stub to work at runtime.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 recipes-graphics/imx-gpu-viv/imx-gpu-viv-6.inc | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

(limited to 'recipes-graphics')

diff --git a/recipes-graphics/imx-gpu-viv/imx-gpu-viv-6.inc b/recipes-graphics/imx-gpu-viv/imx-gpu-viv-6.inc
index 4abab088..48d3ad2b 100644
--- a/recipes-graphics/imx-gpu-viv/imx-gpu-viv-6.inc
+++ b/recipes-graphics/imx-gpu-viv/imx-gpu-viv-6.inc
@@ -25,6 +25,8 @@ DEPENDS:append:mx8-nxp-bsp = " patchelf-native"
 # We depend on mesa to fill in what is missing.
 DEPENDS += "${@bb.utils.contains('DISTRO_FEATURES', 'x11', 'mesa', '', d)}"
 
+DEPENDS:append:libc-musl = " gcompat"
+
 PROVIDES += " \
     imx-gpu-viv \
     libgal-imx \
@@ -244,6 +246,24 @@ do_install () {
     chown -R root:root "${D}"
 }
 
+do_install:append:libc-musl() {
+    # libs
+    for f in `find ${D}${libdir} -name '*.so*' -type f`
+    do
+        patchelf --add-needed libgcompat.so.0 $f
+    done
+    # binaries
+    for f in `find ${D}/opt ${D}${bindir} -name '*' -type f -executable`
+    do
+        # prune scripts
+        if `patchelf --print-interpreter $f 2>&1 > /dev/null`
+        then
+            patchelf --set-interpreter ${root_prefix}`patchelf --print-interpreter $f` $f
+            patchelf --add-needed libgcompat.so.0 $f
+        fi
+    done
+}
+
 ALLOW_EMPTY:${PN} = "1"
 
 FILES:libclc-imx = "${libdir}/libCLC${SOLIBS} ${includedir}/CL/cl_viv_vx_ext.h"
-- 
cgit v1.2.3-54-g00ecf