2020-12-25 13:55:36 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
declare -a autoPatchelfLibs
|
2022-03-30 09:31:56 +00:00
|
|
|
declare -a extraAutoPatchelfLibs
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
gatherLibraries() {
|
|
|
|
autoPatchelfLibs+=("$1/lib")
|
|
|
|
}
|
|
|
|
|
2020-12-25 13:55:36 +00:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
# (targetOffset is referenced but not assigned.)
|
2020-04-24 23:36:52 +00:00
|
|
|
addEnvHooks "$targetOffset" gatherLibraries
|
|
|
|
|
|
|
|
# Can be used to manually add additional directories with shared object files
|
|
|
|
# to be included for the next autoPatchelf invocation.
|
|
|
|
addAutoPatchelfSearchPath() {
|
|
|
|
local -a findOpts=()
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--) shift; break;;
|
|
|
|
--no-recurse) shift; findOpts+=("-maxdepth" 1);;
|
|
|
|
--*)
|
|
|
|
echo "addAutoPatchelfSearchPath: ERROR: Invalid command line" \
|
|
|
|
"argument: $1" >&2
|
|
|
|
return 1;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
local dir=
|
|
|
|
while IFS= read -r -d '' dir; do
|
|
|
|
extraAutoPatchelfLibs+=("$dir")
|
2020-12-25 13:55:36 +00:00
|
|
|
done < <(find "$@" "${findOpts[@]}" \! -type d \
|
2022-03-30 09:31:56 +00:00
|
|
|
\( -name '*.so' -o -name '*.so.*' \) -print0 \
|
|
|
|
| sed -z 's#/[^/]*$##' \
|
|
|
|
| uniq -z
|
|
|
|
)
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
autoPatchelf() {
|
|
|
|
local norecurse=
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--) shift; break;;
|
|
|
|
--no-recurse) shift; norecurse=1;;
|
|
|
|
--*)
|
|
|
|
echo "autoPatchelf: ERROR: Invalid command line" \
|
|
|
|
"argument: $1" >&2
|
|
|
|
return 1;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
local runtimeDependenciesArray=($runtimeDependencies)
|
|
|
|
@pythonInterpreter@ @autoPatchelfScript@ \
|
|
|
|
${norecurse:+--no-recurse} \
|
|
|
|
${autoPatchelfIgnoreMissingDeps:+--ignore-missing} \
|
|
|
|
--paths "$@" \
|
|
|
|
--libs "${autoPatchelfLibs[@]}" \
|
|
|
|
"${extraAutoPatchelfLibs[@]}" \
|
|
|
|
--runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}"
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# XXX: This should ultimately use fixupOutputHooks but we currently don't have
|
|
|
|
# a way to enforce the order. If we have $runtimeDependencies set, the setup
|
|
|
|
# hook of patchelf is going to ruin everything and strip out those additional
|
|
|
|
# RPATHs.
|
|
|
|
#
|
|
|
|
# So what we do here is basically run in postFixup and emulate the same
|
|
|
|
# behaviour as fixupOutputHooks because the setup hook for patchelf is run in
|
|
|
|
# fixupOutput and the postFixup hook runs later.
|
2021-09-18 10:52:07 +00:00
|
|
|
#
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
# (Expressions don't expand in single quotes, use double quotes for that.)
|
2020-04-24 23:36:52 +00:00
|
|
|
postFixupHooks+=('
|
|
|
|
if [ -z "${dontAutoPatchelf-}" ]; then
|
|
|
|
autoPatchelf -- $(for output in $outputs; do
|
|
|
|
[ -e "${!output}" ] || continue
|
|
|
|
echo "${!output}"
|
|
|
|
done)
|
|
|
|
fi
|
|
|
|
')
|