forked from bianster/mysqlfs
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild-macos.sh
More file actions
executable file
·239 lines (189 loc) · 4.9 KB
/
Copy pathbuild-macos.sh
File metadata and controls
executable file
·239 lines (189 loc) · 4.9 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SOURCE_DIR="$SCRIPT_DIR"
CMAKE_BIN="${CMAKE_BIN:-}"
MACOS_SDK_PATH="${MACOS_SDK_PATH:-}"
find_cmake() {
if [ -n "$CMAKE_BIN" ]; then
printf '%s\n' "$CMAKE_BIN"
return 0
fi
if command -v cmake >/dev/null 2>&1; then
command -v cmake
return 0
fi
if command -v brew >/dev/null 2>&1 && brew list --formula cmake >/dev/null 2>&1; then
printf '%s\n' "$(brew --prefix cmake)/bin/cmake"
return 0
fi
return 1
}
find_mysql_prefix() {
local formula
for formula in \
mysql@8.4 \
mysql-client@8.4 \
mysql \
mysql-client
do
if brew --prefix "$formula" >/dev/null 2>&1; then
brew --prefix "$formula"
return 0
fi
done
return 1
}
find_mysql_include_dir() {
local prefix
if [ -n "${MYSQL_INCLUDE_DIR:-}" ]; then
printf '%s\n' "$MYSQL_INCLUDE_DIR"
return 0
fi
if ! prefix="$(find_mysql_prefix)"; then
return 1
fi
if [ -f "$prefix/include/mysql/mysql.h" ]; then
printf '%s\n' "$prefix/include"
return 0
fi
return 1
}
find_mysql_library() {
local prefix
local candidate
if [ -n "${MYSQL_LIBRARY:-}" ]; then
printf '%s\n' "$MYSQL_LIBRARY"
return 0
fi
if ! prefix="$(find_mysql_prefix)"; then
return 1
fi
for candidate in \
"$prefix/lib/libmysqlclient.dylib" \
"$prefix/lib/libmysqlclient.a"
do
if [ -e "$candidate" ]; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
find_fuse_include_dir() {
local candidate
if [ -n "${FUSE_INCLUDE_DIRS:-}" ]; then
printf '%s\n' "$FUSE_INCLUDE_DIRS"
return 0
fi
for candidate in \
/usr/local/include \
/opt/homebrew/include
do
if [ -f "$candidate/fuse.h" ] || [ -f "$candidate/fuse/fuse.h" ]; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
find_fuse_library() {
local candidate
if [ -n "${FUSE_LIBRARIES:-}" ]; then
printf '%s\n' "$FUSE_LIBRARIES"
return 0
fi
for candidate in \
/usr/local/lib/libfuse.dylib \
/opt/homebrew/lib/libfuse.dylib
do
if [ -e "$candidate" ]; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
find_macos_sdk_path() {
if [ -n "$MACOS_SDK_PATH" ]; then
printf '%s\n' "$MACOS_SDK_PATH"
return 0
fi
if command -v xcrun >/dev/null 2>&1; then
xcrun --show-sdk-path
return 0
fi
return 1
}
find_libm_include_dir() {
local sdk_path
if [ -n "${LibM_INCLUDES:-}" ]; then
printf '%s\n' "$LibM_INCLUDES"
return 0
fi
if ! sdk_path="$(find_macos_sdk_path)"; then
return 1
fi
if [ -f "$sdk_path/usr/include/math.h" ]; then
printf '%s\n' "$sdk_path/usr/include"
return 0
fi
return 1
}
find_libm_library() {
local sdk_path
if [ -n "${LibM_LIBRARY:-}" ]; then
printf '%s\n' "$LibM_LIBRARY"
return 0
fi
if ! sdk_path="$(find_macos_sdk_path)"; then
return 1
fi
if [ -e "$sdk_path/usr/lib/libm.tbd" ]; then
printf '%s\n' "$sdk_path/usr/lib/libm.tbd"
return 0
fi
return 1
}
if ! command -v brew >/dev/null 2>&1; then
echo "error: Homebrew is required on macOS to locate dependencies automatically" >&2
exit 1
fi
if ! CMAKE_BIN="$(find_cmake)"; then
echo "error: cmake is required but was not found in PATH" >&2
echo "hint: install it with 'brew install cmake'" >&2
exit 1
fi
if ! MYSQL_INCLUDE_DIR="$(find_mysql_include_dir)"; then
echo "error: could not find MySQL headers; set MYSQL_INCLUDE_DIR explicitly" >&2
exit 1
fi
if ! MYSQL_LIBRARY="$(find_mysql_library)"; then
echo "error: could not find libmysqlclient; set MYSQL_LIBRARY explicitly" >&2
exit 1
fi
if ! FUSE_INCLUDE_DIRS="$(find_fuse_include_dir)"; then
echo "error: could not find macFUSE headers; set FUSE_INCLUDE_DIRS explicitly" >&2
exit 1
fi
if ! FUSE_LIBRARIES="$(find_fuse_library)"; then
echo "error: could not find libfuse.dylib; set FUSE_LIBRARIES explicitly" >&2
exit 1
fi
if ! LibM_INCLUDES="$(find_libm_include_dir)"; then
echo "error: could not find LibM headers in the active macOS SDK; set LibM_INCLUDES explicitly" >&2
exit 1
fi
if ! LibM_LIBRARY="$(find_libm_library)"; then
echo "error: could not find libm in the active macOS SDK; set LibM_LIBRARY explicitly" >&2
exit 1
fi
export MYSQLFS_BUILD_DIR="${MYSQLFS_BUILD_DIR:-$SOURCE_DIR/build-macos}"
export CMAKE_BIN
export MYSQL_INCLUDE_DIR
export MYSQL_LIBRARY
export FUSE_INCLUDE_DIRS
export FUSE_LIBRARIES
export LibM_INCLUDES
export LibM_LIBRARY
exec "$SCRIPT_DIR/build.sh" "$@"