Skip to content

Commit 6bcac12

Browse files
committed
macOS lib bundle: move from Makefile to a script
Extend the script added by previous commit to one handling the entire bundling from Makefile. It is nicer having the scripting outside the Makefile, anyways, and the bundle LC_RPATH fix workaround closly relates to bundling.
1 parent 393fd8a commit 6bcac12

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

Makefile.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,8 @@ $(BUNDLE): $(TARGET) $(REFLECTOR_TARGET) @MANPAGES@ hd-rum-multi/hd-rum
582582
$(CP) hd-rum-multi/hd-rum $(BUNDLE)/Contents/MacOS/
583583
$(CP) $(srcdir)/data/template/bin/* $(BUNDLE)/Contents/MacOS
584584
$(CP) -r $(srcdir)/share/ $(BUNDLE)/Contents/share/
585-
for n in $(BUNDLE)/Contents/MacOS/*; \
586-
do echo quit \
587-
| $(DYLIBBUNDLER) $(DYLIBBUNDLER_FLAGS) -of -cd -b \
588-
-d $(BUNDLE)/Contents/libs/ -p @executable_path/../libs/ -x $$n; \
589-
done
590-
$(srcdir)/data/scripts/macos_fix_multiple_rpaths.sh $(BUNDLE)
585+
$(srcdir)/data/scripts/macos_bundle_libs.sh "$(DYLIBBUNDLER)" \
586+
"$(DYLIBBUNDLER_FLAGS)" "$(BUNDLE)"
591587
if [ -d Frameworks ]; then $(CP) -R Frameworks $(BUNDLE)/Contents/; fi
592588
if [ -n '@MANPAGES@' ]; then mkdir -p $(BUNDLE)/Contents/man/man1; \
593589
$(CP) @MANPAGES@ $(BUNDLE)/Contents/man/man1/; fi

data/scripts/macos_bundle_libs.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh -eu
2+
3+
dylibbundler=$1
4+
dylibbundler_flags=$2
5+
bundle=$3
6+
7+
rpath=@executable_path/../libs/
8+
9+
for n in "$bundle"/Contents/MacOS/*; do
10+
# shellcheck disable=SC2086 # intentional, even $dylibbundler
11+
# can have flags like 'dylibbundler -f'; obvious for _flags
12+
echo quit | $dylibbundler $dylibbundler_flags -of -cd -b \
13+
-d "$bundle/Contents/libs/" -p "$rpath" -x "$n"
14+
done
15+
16+
# Remove multiple LC_RPATH occurences of @executable_path/../libs/
17+
# as can be seen by cmd `otool -l $lib | grep -B 1 -A 2 LC_RPATH`
18+
# which seem to be refused by dyld since macOS 15.4 as can be seen
19+
# here <https://github.com/CESNET/UltraGrid/issues/436>. The multiplied
20+
# paths are caused by dylibbundler LC_RPATH replacements.
21+
22+
## output number of $rpath occurences in 'cmd LC_RPATH'
23+
num_rel_lc_rpath() {
24+
otool -l "$1" | sed -n '/LC_RPATH/,+2p' | grep -c "$rpath" || true
25+
}
26+
27+
find "$bundle" -type f -print0 |
28+
while IFS= read -r -d '' n; do
29+
count=$(num_rel_lc_rpath "$n")
30+
# remove all but at most one LC_RPATH $path occurences
31+
while [ "$count" -gt 1 ]; do
32+
install_name_tool -delete_rpath "$rpath" "$n"
33+
count=$((count - 1))
34+
done
35+
done

data/scripts/macos_fix_multiple_rpaths.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)