forked from microsoft/mssql-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure_dylibs.sh
More file actions
executable file
·123 lines (101 loc) · 3.79 KB
/
configure_dylibs.sh
File metadata and controls
executable file
·123 lines (101 loc) · 3.79 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Script to configure dylib paths for macOS
# This script fixes the library paths in the ODBC driver dylibs and codesigns them
# Function to get the current architecture
get_mac_platform_architecture() {
arch=$(uname -m)
echo "$arch"
}
# Directory structure setup
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
# Get platform and configure paths
ARCH=$(get_mac_platform_architecture)
LIB_DIR="$PROJECT_DIR/libs/macos/$ARCH/lib"
LIBMSODBCSQL_PATH="$LIB_DIR/libmsodbcsql.18.dylib"
LIBODBCINST_PATH="$LIB_DIR/libodbcinst.2.dylib"
LIBLTDL_PATH="$LIB_DIR/libltdl.7.dylib"
echo "Initial configuration:"
otool -L "$LIBMSODBCSQL_PATH"
otool -L "$LIBODBCINST_PATH"
if [ -f "$LIBLTDL_PATH" ]; then
otool -L "$LIBLTDL_PATH"
fi
echo "Configuring dylibs in: $LIB_DIR"
# Check if the directories and files exist
if [ ! -d "$LIB_DIR" ]; then
echo "Error: Library directory doesn't exist: $LIB_DIR"
exit 1
fi
if [ ! -f "$LIBMSODBCSQL_PATH" ]; then
echo "Error: libmsodbcsql.18.dylib not found at: $LIBMSODBCSQL_PATH"
exit 1
fi
if [ ! -f "$LIBODBCINST_PATH" ]; then
echo "Error: libodbcinst.2.dylib not found at: $LIBODBCINST_PATH"
exit 1
fi
# Get the existing library paths which are linked to the dylibs
echo "Reading dependencies from libmsodbcsql.18.dylib..."
OTOOL_LIST=$(otool -L "$LIBMSODBCSQL_PATH")
OLD_LIBODBCINST_PATH=""
# In the otool list of libmsodbcsql_path, get the library path for libodbcinst
while IFS= read -r line; do
if [[ "$line" == *"libodbcinst"* ]]; then
OLD_LIBODBCINST_PATH=$(echo "$line" | awk '{print $1}')
break
fi
done <<< "$OTOOL_LIST"
echo "Reading dependencies from libodbcinst.2.dylib..."
OTOOL_LIST=$(otool -L "$LIBODBCINST_PATH")
OLD_LIBLTDL_PATH=""
# In the otool list of libodbcinst_path, get the library path for libltdl
while IFS= read -r line; do
if [[ "$line" == *"libltdl"* ]]; then
OLD_LIBLTDL_PATH=$(echo "$line" | awk '{print $1}')
break
fi
done <<< "$OTOOL_LIST"
# Configure the library paths if dependencies were found
if [ -n "$OLD_LIBODBCINST_PATH" ]; then
echo "Fixing libmsodbcsql.18.dylib dependency on libodbcinst.2.dylib..."
echo " Changing: $OLD_LIBODBCINST_PATH"
echo " To: @loader_path/libodbcinst.2.dylib"
install_name_tool -change "$OLD_LIBODBCINST_PATH" "@loader_path/libodbcinst.2.dylib" "$LIBMSODBCSQL_PATH"
else
echo "Warning: libodbcinst dependency not found in libmsodbcsql.18.dylib"
fi
if [ -n "$OLD_LIBLTDL_PATH" ] && [ -f "$LIBLTDL_PATH" ]; then
echo "Fixing libodbcinst.2.dylib dependency on libltdl.7.dylib..."
echo " Changing: $OLD_LIBLTDL_PATH"
echo " To: @loader_path/libltdl.7.dylib"
install_name_tool -change "$OLD_LIBLTDL_PATH" "@loader_path/libltdl.7.dylib" "$LIBODBCINST_PATH"
else
echo "Note: libltdl dependency not found or not needed"
fi
# Force codesign the dylibs
# First set the IDs of the libraries using @loader_path
echo "Setting library IDs with @loader_path..."
echo "Setting ID for libmsodbcsql.18.dylib..."
install_name_tool -id "@loader_path/libmsodbcsql.18.dylib" "$LIBMSODBCSQL_PATH"
echo "Setting ID for libodbcinst.2.dylib..."
install_name_tool -id "@loader_path/libodbcinst.2.dylib" "$LIBODBCINST_PATH"
if [ -f "$LIBLTDL_PATH" ]; then
echo "Setting ID for libltdl.7.dylib..."
install_name_tool -id "@loader_path/libltdl.7.dylib" "$LIBLTDL_PATH"
fi
echo "Codesigning libmsodbcsql.18.dylib..."
codesign -s - -f "$LIBMSODBCSQL_PATH" 2>/dev/null
echo "Codesigning libodbcinst.2.dylib..."
codesign -s - -f "$LIBODBCINST_PATH" 2>/dev/null
if [ -f "$LIBLTDL_PATH" ]; then
echo "Codesigning libltdl.7.dylib..."
codesign -s - -f "$LIBLTDL_PATH" 2>/dev/null
fi
echo "Library configuration complete!"
echo "Final configuration:"
otool -L "$LIBMSODBCSQL_PATH"
otool -L "$LIBODBCINST_PATH"
if [ -f "$LIBLTDL_PATH" ]; then
otool -L "$LIBLTDL_PATH"
fi