aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
committerMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
commitc4625b175f8200f643fd6e11010932ea44c78433 (patch)
treebce3f89888c8ac3991fa5569a878a9eab6801ccc /infra/libkookie/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
parent49f735974dd103039ddc4cb576bb76555164a9e7 (diff)
parentd661aa56a8843e991261510c1bb28fdc2f6975ae (diff)
Add 'infra/libkookie/' from commit 'd661aa56a8843e991261510c1bb28fdc2f6975ae'
git-subtree-dir: infra/libkookie git-subtree-mainline: 49f735974dd103039ddc4cb576bb76555164a9e7 git-subtree-split: d661aa56a8843e991261510c1bb28fdc2f6975ae
Diffstat (limited to 'infra/libkookie/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh')
-rw-r--r--infra/libkookie/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/infra/libkookie/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh b/infra/libkookie/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
new file mode 100644
index 000000000000..af2ff0cc9662
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/build-support/setup-hooks/fix-darwin-dylib-names.sh
@@ -0,0 +1,40 @@
+# On macOS, 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.
+
+fixupOutputHooks+=('fixDarwinDylibNamesIn $prefix')
+
+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"
+ int_out=$(install_name_tool -id "$fn" "${flags[@]}" "$fn" 2>&1)
+ result=$?
+ if [ "$result" -ne 0 ] &&
+ ! grep "shared library stub file and can't be changed" <<< "$out"
+ then
+ echo "$int_out" >&2
+ exit "$result"
+ fi
+ done
+}
+
+fixDarwinDylibNamesIn() {
+ local dir="$1"
+ fixDarwinDylibNames $(find "$dir" -name "*.dylib")
+}