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