summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorOrivej Desh <orivej@gmx.fr>2018-06-11 18:11:02 +0000
committerGitHub <noreply@github.com>2018-06-11 18:11:02 +0000
commitfd97db43bcb05e37f6bb77f363f1e1e239d9de53 (patch)
tree7e3eace9f6142fbbda1e9daf7bf250136767ca87 /pkgs/build-support
parent2f73a373db44d3bce716eff0b6ba49437a79c3e1 (diff)
downloadnixpkgs-fd97db43bcb05e37f6bb77f363f1e1e239d9de53.tar
nixpkgs-fd97db43bcb05e37f6bb77f363f1e1e239d9de53.tar.gz
nixpkgs-fd97db43bcb05e37f6bb77f363f1e1e239d9de53.tar.bz2
nixpkgs-fd97db43bcb05e37f6bb77f363f1e1e239d9de53.tar.lz
nixpkgs-fd97db43bcb05e37f6bb77f363f1e1e239d9de53.tar.xz
nixpkgs-fd97db43bcb05e37f6bb77f363f1e1e239d9de53.tar.zst
nixpkgs-fd97db43bcb05e37f6bb77f363f1e1e239d9de53.zip
pruneLibtoolFiles: init setup hook (#41819)
A .la file specifies linker flags to link with the library it describes. Its
"dependency_libs" field lists the libraries that this library depends upon.
This list often contains "-l" flags without corresponding "-L" flags. Many
packages in Nixpkgs deal with this in one of these ways:
- delete .la file [1]
- clear dependency_libs [2]
- add -L flags to dependency_libs [3]
- propagate dependencies [4]

Sometimes "dependency_libs" contain wrong "-L" flags pointing to the "dev"
output with headers rather than to the main output with libraries. They have to
be edited or deleted to reduce closure size [5].

Deleting .la files is often but not always safe [6].  Atomatically deleting as
many of them as possible is complex [7].  Deleting .la files that describe
shared rather than static libraries is probably safe; but clearing their
"dependency_libs" field achieves the same effect with less potential for
unintended consequences.  This is the approach that may be enabled for all
Nixpkgs.

[1] https://github.com/NixOS/nixpkgs/commit/2a79d296d3de74da77b49ca8dc9d356b1a7a1c8d
[2] https://github.com/NixOS/nixpkgs/commit/c83a53098599c49ec57823bf655ce8b45f6aea10
[3] https://github.com/NixOS/nixpkgs/commit/9e0dcf3bd9fcfeed576132b9101b866aa3cb76ff
[4] https://github.com/NixOS/nixpkgs/commit/01134e698fdfb3b61f8ab8ec3bf13e0718f63955
[5] https://github.com/NixOS/nixpkgs/commit/f6c73f1e37c735abb686d07449f349b796c54cf8
[6] https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Handling_Libtool_Archives
[7] https://github.com/gentoo/gentoo/blob/fb1f2435/eclass/ltprune.eclass
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/setup-hooks/prune-libtool-files.sh22
1 files changed, 22 insertions, 0 deletions
diff --git a/pkgs/build-support/setup-hooks/prune-libtool-files.sh b/pkgs/build-support/setup-hooks/prune-libtool-files.sh
new file mode 100644
index 00000000000..d75812e05b6
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/prune-libtool-files.sh
@@ -0,0 +1,22 @@
+# Clear dependency_libs in libtool files for shared libraries.
+
+# Shared libraries already encode their dependencies with locations.  .la
+# files do not always encode those locations, and sometimes encode the
+# locations in the wrong Nix output. .la files are not needed for shared
+# libraries, but without dependency_libs they do not hurt either.
+
+fixupOutputHooks+=(_pruneLibtoolFiles)
+
+_pruneLibtoolFiles() {
+    if [ "$dontPruneLibtoolFiles" ]; then
+       return
+    fi
+
+    # Libtool uses "dlname" and "library_names" fields for shared libraries and
+    # the "old_library" field for static libraries.  We are processing only
+    # those .la files that do not describe static libraries.
+    find "$prefix" -type f -name '*.la' \
+         -exec grep -q '^# Generated by libtool' {} \; \
+         -exec grep -q "^old_library=''" {} \; \
+         -exec sed -i {} -e "/^dependency_libs='[^']/ c dependency_libs='' #pruned" \;
+}