2023-07-27 22:57:22 +02:00
|
|
|
# shellcheck shell=bash
|
|
|
|
# Run addOpenGLRunpath on all dynamically linked, ELF files
|
2022-04-03 11:19:04 +02:00
|
|
|
echo "Sourcing auto-add-opengl-runpath-hook"
|
|
|
|
|
2023-08-22 02:14:47 +02:00
|
|
|
elfHasDynamicSection() {
|
|
|
|
patchelf --print-rpath "$1" >& /dev/null
|
|
|
|
}
|
|
|
|
|
2023-07-27 22:57:22 +02:00
|
|
|
autoAddOpenGLRunpathPhase() (
|
|
|
|
local outputPaths
|
|
|
|
mapfile -t outputPaths < <(for o in $(getAllOutputNames); do echo "${!o}"; done)
|
|
|
|
find "${outputPaths[@]}" -type f -executable -print0 | while IFS= read -rd "" f; do
|
|
|
|
if isELF "$f"; then
|
|
|
|
# patchelf returns an error on statically linked ELF files
|
2023-08-22 02:14:47 +02:00
|
|
|
if elfHasDynamicSection "$f" ; then
|
2023-07-27 22:57:22 +02:00
|
|
|
echo "autoAddOpenGLRunpathHook: patching $f"
|
|
|
|
addOpenGLRunpath "$f"
|
2023-08-22 02:14:47 +02:00
|
|
|
elif (( "${NIX_DEBUG:-0}" >= 1 )) ; then
|
|
|
|
echo "autoAddOpenGLRunpathHook: skipping a statically-linked ELF file $f"
|
2023-07-27 22:57:22 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
)
|
2022-04-03 11:19:04 +02:00
|
|
|
|
|
|
|
if [ -z "${dontUseAutoAddOpenGLRunpath-}" ]; then
|
2023-07-27 22:57:22 +02:00
|
|
|
echo "Using autoAddOpenGLRunpathPhase"
|
|
|
|
postFixupHooks+=(autoAddOpenGLRunpathPhase)
|
2022-04-03 11:19:04 +02:00
|
|
|
fi
|