File: fix_dylib_deps.sh

package info (click to toggle)
qlcplus 4.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 58,644 kB
  • sloc: cpp: 182,867; javascript: 7,764; xml: 2,453; ansic: 2,120; sh: 1,716; python: 634; ruby: 606; makefile: 23
file content (61 lines) | stat: -rwxr-xr-x 2,199 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash

if [ -z "$1" ]; then
    echo "Usage: $0 <source_dylib>"
    exit 1
fi

HOMEBREW_PREFIX=`brew --prefix`
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" "$FRAMEWORKS_DIR/"
        fi

        # 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