1# shellcheck shell=bash
2# Patch all dynamically linked, ELF files with the CUDA driver (libcuda.so)
3# coming from the cuda_compat package by adding it to the RUNPATH.
4echo "Sourcing auto-add-cuda-compat-runpath-hook"
5
6addCudaCompatRunpath() {
7 local libPath
8 local origRpath
9
10 if [[ $# -eq 0 ]]; then
11 echo "addCudaCompatRunpath: no library path provided" >&2
12 exit 1
13 elif [[ $# -gt 1 ]]; then
14 echo "addCudaCompatRunpath: too many arguments" >&2
15 exit 1
16 elif [[ "$1" == "" ]]; then
17 echo "addCudaCompatRunpath: empty library path" >&2
18 exit 1
19 else
20 libPath="$1"
21 fi
22
23 origRpath="$(patchelf --print-rpath "$libPath")"
24 patchelf --set-rpath "@libcudaPath@:$origRpath" "$libPath"
25}
26
27postFixupHooks+=("autoFixElfFiles addCudaCompatRunpath")