linuxKernel.kernels.linux_zen: 6.11.5-zen1 -> v6.12.1-zen1; linuxKernel.kernels.linux...
[NixPkgs.git] / pkgs / build-support / setup-hooks / auto-patchelf.sh
blob541b7fc694d03f2cb9319d6758ef5d775887ffcf
1 # shellcheck shell=bash
3 declare -a autoPatchelfLibs
4 declare -a extraAutoPatchelfLibs
6 gatherLibraries() {
7 autoPatchelfLibs+=("$1/lib")
10 # shellcheck disable=SC2154
11 # (targetOffset is referenced but not assigned.)
12 addEnvHooks "$targetOffset" gatherLibraries
14 # Can be used to manually add additional directories with shared object files
15 # to be included for the next autoPatchelf invocation.
16 addAutoPatchelfSearchPath() {
17 local -a findOpts=()
19 while [ $# -gt 0 ]; do
20 case "$1" in
21 --) shift; break;;
22 --no-recurse) shift; findOpts+=("-maxdepth" 1);;
23 --*)
24 echo "addAutoPatchelfSearchPath: ERROR: Invalid command line" \
25 "argument: $1" >&2
26 return 1;;
27 *) break;;
28 esac
29 done
31 local dir=
32 while IFS= read -r -d '' dir; do
33 extraAutoPatchelfLibs+=("$dir")
34 done < <(find "$@" "${findOpts[@]}" \! -type d \
35 \( -name '*.so' -o -name '*.so.*' \) -print0 \
36 | sed -z 's#/[^/]*$##' \
37 | uniq -z
42 autoPatchelf() {
43 local norecurse=
44 while [ $# -gt 0 ]; do
45 case "$1" in
46 --) shift; break;;
47 --no-recurse) shift; norecurse=1;;
48 --*)
49 echo "autoPatchelf: ERROR: Invalid command line" \
50 "argument: $1" >&2
51 return 1;;
52 *) break;;
53 esac
54 done
56 concatTo ignoreMissingDepsArray autoPatchelfIgnoreMissingDeps
57 concatTo appendRunpathsArray appendRunpaths
58 concatTo runtimeDependenciesArray runtimeDependencies
59 concatTo patchelfFlagsArray patchelfFlags
60 concatTo autoPatchelfFlagsArray autoPatchelfFlags
62 # Check if ignoreMissingDepsArray contains "1" and if so, replace it with
63 # "*", printing a deprecation warning.
64 for dep in "${ignoreMissingDepsArray[@]}"; do
65 if [ "$dep" == "1" ]; then
66 echo "autoPatchelf: WARNING: setting 'autoPatchelfIgnoreMissingDeps" \
67 "= true;' is deprecated and will be removed in a future release." \
68 "Use 'autoPatchelfIgnoreMissingDeps = [ \"*\" ];' instead." >&2
69 ignoreMissingDepsArray=( "*" )
70 break
72 done
74 auto-patchelf \
75 ${norecurse:+--no-recurse} \
76 --ignore-missing "${ignoreMissingDepsArray[@]}" \
77 --paths "$@" \
78 --libs "${autoPatchelfLibs[@]}" \
79 "${extraAutoPatchelfLibs[@]}" \
80 --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \
81 --append-rpaths "${appendRunpathsArray[@]}" \
82 "${autoPatchelfFlagsArray[@]}" \
83 --extra-args "${patchelfFlagsArray[@]}"
86 autoPatchelfPostFixup() {
87 # XXX: This should ultimately use fixupOutputHooks but we currently don't have
88 # a way to enforce the order. If we have $runtimeDependencies set, the setup
89 # hook of patchelf is going to ruin everything and strip out those additional
90 # RPATHs.
92 # So what we do here is basically run in postFixup and emulate the same
93 # behaviour as fixupOutputHooks because the setup hook for patchelf is run in
94 # fixupOutput and the postFixup hook runs later.
95 if [[ -z "${dontAutoPatchelf-}" ]]; then
96 autoPatchelf -- $(for output in $(getAllOutputNames); do
97 [ -e "${!output}" ] || continue
98 echo "${!output}"
99 done)
103 postFixupHooks+=(autoPatchelfPostFixup)