summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2020-02-13 21:07:29 +0100
committerJan Tojnar <jtojnar@gmail.com>2020-02-14 07:03:02 +0100
commit4f8a99e9e1b2b54f215f800a1a1411391da02a71 (patch)
treea435f2b3003f6a33ab60f545c283f9b1b3de2278
parentdoc/stdenv: improve autoPatchelfHook description (diff)
downloadnixpkgs-origin/apeh-anyso.tar.gz
autoPatchelfHook: Support arbitrary paths in runtimeDependenciesorigin/apeh-anysogitlab.intr/apeh-anyso
Previously, the setup hooks configuration variable only accepted packages and added lib subdirectory of those packages to rpath. That was insufficient for including shared libraries like `lib/libv4l/v4l2convert.so` so this patch allows for passing .so file paths whose parent directory will be added to rpath. The patch also makes the process more strict, failing when a package not containing lib or not a .so file is passed to avoid hard to debug failures like passing a wrong output.
-rw-r--r--doc/stdenv/stdenv.xml5
-rw-r--r--pkgs/build-support/setup-hooks/auto-patchelf.sh10
2 files changed, 13 insertions, 2 deletions
diff --git a/doc/stdenv/stdenv.xml b/doc/stdenv/stdenv.xml
index 891490edf9ad..912d194b4e24 100644
--- a/doc/stdenv/stdenv.xml
+++ b/doc/stdenv/stdenv.xml
@@ -2000,11 +2000,14 @@ addEnvHooks "$hostOffset" myBashFunction
This is a special setup hook which helps in packaging proprietary software in that it automatically tries to find missing shared library dependencies of ELF files based on the given <varname>buildInputs</varname> and <varname>nativeBuildInputs</varname>.
</para>
<para>
- You can also specify a <varname>runtimeDependencies</varname> variable which lists dependencies to be unconditionally added to <glossterm>rpath</glossterm> of all executables.
+ You can also specify a <varname>runtimeDependencies</varname> variable which lists dependencies or paths to shared libraries to be unconditionally added to <glossterm>rpath</glossterm> of all executables.
This is useful for programs that use <citerefentry>
<refentrytitle>dlopen</refentrytitle>
<manvolnum>3</manvolnum> </citerefentry> to load libraries at runtime.
</para>
+ <note>
+ <para>When you pass a library path such as <literal>${libv4l}/lib/libv4l/v4l2convert.so</literal> to <envar>runtimeDependencies</envar>, the whole <literal>${libv4l}/lib/libv4l</literal> directory is added to <glossterm>rpath</glossterm>. This enables the patched program to find all other libraries in the directory, not just the single library you chose.</para>
+ </note>
<para>
In certain situations you may want to run the main command (<command>autoPatchelf</command>) of the setup hook on a file or a set of directories instead of unconditionally patching all outputs. This can be done by setting the <varname>dontAutoPatchelf</varname> environment variable to a non-empty value.
</para>
diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh
index 52c50091d08c..744bf0df5b35 100644
--- a/pkgs/build-support/setup-hooks/auto-patchelf.sh
+++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh
@@ -106,7 +106,15 @@ autoPatchelfFile() {
patchelf --set-interpreter "$interpreter" "$toPatch"
if [ -n "$runtimeDependencies" ]; then
for dep in $runtimeDependencies; do
- rpath="$rpath${rpath:+:}$dep/lib"
+ if [[ -f "$dep" && "$dep" =~ \.so(\.[0-9]+)*$ ]]; then
+ rpath="$rpath${rpath:+:}$(dirname "$dep")"
+ elif [[ -d "$dep" && -d "$dep/lib" ]]; then
+ rpath="$rpath${rpath:+:}$dep/lib"
+ else
+ echo "autoPatchelfFile: ERROR: $dep passed to \$runtimeDependencies must be" \
+ "either a directory containing lib subdirectory or a .so file."
+ return 1
+ fi
done
fi
fi