-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macos: improve dylib fixer to work on apple silicon
- Loading branch information
1 parent
923afa6
commit 5e19685
Showing
1 changed file
with
61 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,65 @@ | ||
echo "Processing $1..." | ||
for dep in `otool -L $1 | grep opt | cut -d ' ' -f 1` | ||
do | ||
if [[ "$dep" == *$HOMEBREW_PREFIX* ]]; then | ||
subst=${dep##*/} | ||
echo "Regular lib: $dep ($subst)" | ||
# check missing dependency | ||
if [ ! -f ~/QLC+.app/Contents/Frameworks/$subst ]; then | ||
#!/bin/bash | ||
|
||
if [ -z "$1" ]; then | ||
echo "Usage: $0 <source_dylib>" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$HOMEBREW_PREFIX" ]; then | ||
echo "HOMEBREW_PREFIX is not set. Please set it to the Homebrew installation path." | ||
exit 1 | ||
fi | ||
|
||
SRC_DYLIB="$1" | ||
FRAMEWORKS_DIR=~/QLC+.app/Contents/Frameworks | ||
|
||
echo "Processing $SRC_DYLIB... (Homebrew at $HOMEBREW_PREFIX)" | ||
|
||
# Ensure Frameworks directory exists | ||
mkdir -p "$FRAMEWORKS_DIR" | ||
|
||
# Extract the source dylib's full path from the second line of otool output | ||
dylib_full_path=$(otool -L "$SRC_DYLIB" | sed -n '2p' | awk '{print $1}') | ||
dylib_dir=$(dirname "$dylib_full_path") | ||
|
||
echo "Source dylib full path: $dylib_full_path" | ||
echo "Source dylib directory: $dylib_dir" | ||
|
||
# Process each dependency reported by otool | ||
otool -L "$SRC_DYLIB" | grep opt | awk '{print $1}' | while read -r dep; do | ||
subst=$(basename "$dep") | ||
|
||
if [[ "$dep" == *"$HOMEBREW_PREFIX"* ]]; then | ||
echo "Found Homebrew library: $dep ($subst)" | ||
|
||
# Check if the dependency is already in the target Frameworks directory | ||
if [ ! -f "$FRAMEWORKS_DIR/$subst" ]; then | ||
echo "Dependency missing: $subst. Adding it to target..." | ||
cp $dep ~/QLC+.app/Contents/Frameworks/ | ||
cp "$dep" "$FRAMEWORKS_DIR/" | ||
fi | ||
|
||
install_name_tool -change $dep @executable_path/../Frameworks/$subst $1 | ||
# Update the source dylib's reference to the dependency | ||
install_name_tool -change "$dep" "@executable_path/../Frameworks/$subst" "$SRC_DYLIB" | ||
|
||
elif [[ "$dep" == @loader_path* ]]; then | ||
echo "Found @loader_path reference: $dep ($subst)" | ||
|
||
# Resolve the actual path based on the source dylib's directory | ||
resolved_path=$(realpath "$dylib_dir/${dep#@loader_path/}") | ||
|
||
echo "Resolved path for @loader_path: $resolved_path" | ||
|
||
if [ -f "$resolved_path" ]; then | ||
# Check if the dependency is already in the target Frameworks directory | ||
if [ ! -f "$FRAMEWORKS_DIR/$subst" ]; then | ||
echo "Dependency missing: $subst. Copying resolved @loader_path dependency..." | ||
cp "$resolved_path" "$FRAMEWORKS_DIR/" | ||
fi | ||
|
||
# Update the source dylib's reference to the dependency | ||
install_name_tool -change "$dep" "@executable_path/../Frameworks/$subst" "$SRC_DYLIB" | ||
else | ||
echo "Warning: Resolved path does not exist: $resolved_path" | ||
fi | ||
fi | ||
done | ||
done |