2017-08-06 23:05:18 +01:00
|
|
|
# On macOS, binaries refer to dynamic library dependencies using
|
2014-01-15 12:39:52 +00:00
|
|
|
# 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.
|
|
|
|
|
2015-03-24 14:59:05 +00:00
|
|
|
fixupOutputHooks+=('fixDarwinDylibNamesIn $prefix')
|
2014-09-24 15:12:49 +01:00
|
|
|
|
2014-01-15 12:39:52 +00:00
|
|
|
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"
|
2020-11-19 08:18:44 +00:00
|
|
|
int_out=$(@targetPrefix@install_name_tool -id "$fn" "${flags[@]}" "$fn" 2>&1)
|
2018-11-15 21:02:42 +00:00
|
|
|
result=$?
|
|
|
|
if [ "$result" -ne 0 ] &&
|
|
|
|
! grep "shared library stub file and can't be changed" <<< "$out"
|
|
|
|
then
|
|
|
|
echo "$int_out" >&2
|
|
|
|
exit "$result"
|
|
|
|
fi
|
2014-01-15 12:39:52 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
fixDarwinDylibNamesIn() {
|
|
|
|
local dir="$1"
|
|
|
|
fixDarwinDylibNames $(find "$dir" -name "*.dylib")
|
|
|
|
}
|