about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-01-15 13:39:52 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-01-15 13:41:09 +0100
commit8622548160c5e29d5d2fb5d3fc942a3460a60a9c (patch)
tree3fa6983a4f76fe78f0eaa498b75fd9495d2ddfa3 /pkgs/build-support
parentabf6896aaf4611492cbccfc8c9d7b872e7ee364b (diff)
downloadnixlib-8622548160c5e29d5d2fb5d3fc942a3460a60a9c.tar
nixlib-8622548160c5e29d5d2fb5d3fc942a3460a60a9c.tar.gz
nixlib-8622548160c5e29d5d2fb5d3fc942a3460a60a9c.tar.bz2
nixlib-8622548160c5e29d5d2fb5d3fc942a3460a60a9c.tar.lz
nixlib-8622548160c5e29d5d2fb5d3fc942a3460a60a9c.tar.xz
nixlib-8622548160c5e29d5d2fb5d3fc942a3460a60a9c.tar.zst
nixlib-8622548160c5e29d5d2fb5d3fc942a3460a60a9c.zip
Add a setup hook for fixing dylib install names on Darwin
Install names need to be absolute paths, otherwise programs that link
against the dylib won't work without setting $DYLD_LIBRARY_PATH.  Most
packages do this correctly, but some (like Boost and ICU) do not.
This setup hook absolutizes all install names.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
new file mode 100644
index 000000000000..5962bf039069
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
@@ -0,0 +1,35 @@
+# On Mac OS X, binaries refer to dynamic library dependencies using
+# either relative paths (e.g. "libicudata.dylib", searched relative to
+# $DYLD_LIBRARY_PATH) or absolute paths
+# (e.g. "/nix/store/.../lib/libicudata.dylib").  In Nix, the latter is
+# preferred since it allows programs to just work.  When linking
+# against a library (e.g. "-licudata"), the linker uses the install
+# name embedded in the dylib (which can be shown using "otool -D").
+# Most packages create dylibs with absolute install names, but some do
+# not.  This setup hook fixes dylibs by setting their install names to
+# their absolute path (using "install_name_tool -id").  It also
+# rewrites references in other dylibs to absolute paths.
+
+fixDarwinDylibNames() {
+    local flags=()
+    local old_id
+
+    for fn in "$@"; do
+        flags+=(-change "$(basename "$fn")" "$fn")
+    done
+
+    for fn in "$@"; do
+        if [ -L "$fn" ]; then continue; fi
+        echo "$fn: fixing dylib"
+        install_name_tool -id "$fn" "${flags[@]}" "$fn"
+    done
+}
+
+fixDarwinDylibNamesIn() {
+    local dir="$1"
+    fixDarwinDylibNames $(find "$dir" -name "*.dylib")
+}
+
+postFixup() {
+    fixDarwinDylibNamesIn "$prefix"
+}