-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathbuild-package-deps-osx.sh
executable file
·404 lines (337 loc) · 13.4 KB
/
build-package-deps-osx.sh
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#!/usr/bin/env bash
set -eE
# This script builds a tar file that contains a bunch of deps that OBS needs for
# advanced functionality on OSX. Currently this tar file is pulled down off of s3
# and used in the CI build process on travis.
# Mostly this sets build flags to compile with older SDKS and make sure that
# the libs are portable.
BUILD_PACKAGES=(
"libpng 1.6.37"
"opus 1.3.1"
"ogg 68ca3841567247ac1f7850801a164f58738d8df9"
"vorbis 1.3.6"
"vpx 1.8.2"
"jansson 2.12"
"x264 origin/stable"
"mbedtls 2.16.5"
"srt 1.4.1"
"ffmpeg 4.2.2"
"luajit 2.1.0-beta3"
"freetype 2.10.1"
)
## START UTILITIES ##
hr() {
echo "───────────────────────────────────────────────────"
echo -e $1
echo "───────────────────────────────────────────────────"
}
exists()
{
command -v "$1" >/dev/null 2>&1
}
# deletes the temp directory
cleanup() {
rm -rf "${WORK_DIR}/*"
hr "Deleted contents of temp working directory ${WORK_DIR}"
}
# register the cleanup function to be called on the EXIT signal
trap cleanup EXIT
caught_error() {
hr "ERROR while building package ${1}"
exit 1
}
## END UTILITIES ##
## START DEPENDENCIES ##
for DEPENDENCY in nasm automake pkg-config; do
if ! exists ${DEPENDENCY}; then
hr "${DEPENDENCY} not found. Please install homebrew (https://brew.sh) and run './osx-install-tools.sh'."
exit 1
fi
done
## END DEPENDENCIES ##
## START ENV SETUP ##
CURDIR=$(pwd)
# the temp directory
WORK_DIR=`mktemp -d`
cd ${WORK_DIR}
DEPS_DEST=${WORK_DIR}/obsdeps
# make dest dirs
mkdir ${DEPS_DEST}
mkdir ${DEPS_DEST}/bin
mkdir ${DEPS_DEST}/include
mkdir ${DEPS_DEST}/lib
# OSX COMPAT
export MACOSX_DEPLOYMENT_TARGET=10.11
# If you need an olders SDK and Xcode won't give it to you
# https://github.com/phracker/MacOSX-SDKs
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/tmp/obsdeps/lib/pkgconfig
## END ENV SETUP ##
## START BUILD FUNCS ##
build_opus() {
OPUS_VERSION=${1}
hr "Building libopus v${OPUS_VERSION}"
# libopus
curl -L -O https://ftp.osuosl.org/pub/xiph/releases/opus/opus-${OPUS_VERSION}.tar.gz
tar -xf opus-${OPUS_VERSION}.tar.gz
cd ./opus-${OPUS_VERSION}
mkdir build
cd ./build
../configure --disable-shared --enable-static --prefix="/tmp/obsdeps"
make -j
make install
cd $WORK_DIR
}
build_ogg() {
OGG_VERSION=${1}
hr "Building libogg v${OGG_VERSION}"
# libogg
curl -L -o ogg-${OGG_VERSION}.tar.gz https://gitlab.xiph.org/xiph/ogg/-/archive/${OGG_VERSION}/ogg-${OGG_VERSION}.tar.gz
tar -xf ogg-${OGG_VERSION}.tar.gz
cd ./ogg-${OGG_VERSION}
mkdir build
./autogen.sh
cd ./build
../configure --disable-shared --enable-static --prefix="/tmp/obsdeps"
make -j
make install
cd $WORK_DIR
}
build_vorbis() {
VORBIS_VERSION=${1}
hr "Building libvorbis v${VORBIS_VERSION}"
# libvorbis
curl -L -O https://ftp.osuosl.org/pub/xiph/releases/vorbis/libvorbis-${VORBIS_VERSION}.tar.gz
tar -xf libvorbis-${VORBIS_VERSION}.tar.gz
cd ./libvorbis-${VORBIS_VERSION}
mkdir build
cd ./build
../configure --disable-shared --enable-static --prefix="/tmp/obsdeps"
make -j
make install
cd $WORK_DIR
}
build_vpx() {
VPX_VERSION=${1}
hr "Building libvpx v${VPX_VERSION}"
# libvpx
curl -L -O https://chromium.googlesource.com/webm/libvpx/+archive/v${VPX_VERSION}.tar.gz
mkdir -p ./libvpx-v${VPX_VERSION}
tar -xf v${VPX_VERSION}.tar.gz -C $PWD/libvpx-v${VPX_VERSION}
cd ./libvpx-v${VPX_VERSION}
mkdir -p build
cd ./build
../configure --disable-shared --prefix="/tmp/obsdeps" --libdir="/tmp/obsdeps/lib"
make -j
make install
cd $WORK_DIR
}
build_x264() {
X264_VERSION=${1}
hr "Building x264 ${X264_VERSION}"
# x264
git clone https://code.videolan.org/videolan/x264.git
cd ./x264
git checkout ${X264_VERSION}
mkdir build
cd ./build
../configure --extra-ldflags="-mmacosx-version-min=10.11" --enable-static --prefix="/tmp/obsdeps"
make -j
make install
../configure --extra-ldflags="-mmacosx-version-min=10.11" --enable-shared --libdir="/tmp/obsdeps/bin" --prefix="/tmp/obsdeps"
make -j
ln -f -s libx264.*.dylib libx264.dylib
find . -name \*.dylib -exec cp \{\} ${DEPS_DEST}/bin/ \;
rsync -avh --include="*/" --include="*.h" --exclude="*" ../* ${DEPS_DEST}/include/
rsync -avh --include="*/" --include="*.h" --exclude="*" ./* ${DEPS_DEST}/include/
cd $WORK_DIR
}
build_jansson() {
JANSSON_VERSION=${1}
hr "Building libjansson v${JANSSON_VERSION}"
# janson
curl -L -O http://www.digip.org/jansson/releases/jansson-${JANSSON_VERSION}.tar.gz
tar -xf jansson-${JANSSON_VERSION}.tar.gz
cd jansson-${JANSSON_VERSION}
mkdir build
cd ./build
../configure --libdir="/tmp/obsdeps/bin" --enable-shared --disable-static
make -j
find . -name \*.dylib -exec cp \{\} ${DEPS_DEST}/bin/ \;
rsync -avh --include="*/" --include="*.h" --exclude="*" ../src/* ${DEPS_DEST}/include/
rsync -avh --include="*/" --include="*.h" --exclude="*" ./src/* ${DEPS_DEST}/include/
cp ./*.h ${DEPS_DEST}/include/
cd $WORK_DIR
}
build_mbedtls() {
MBEDTLS_VERSION=${1}
hr "Building mbedtls v${MBEDTLS_VERSION}"
# mbedtls
curl -L -O https://tls.mbed.org/download/mbedtls-${MBEDTLS_VERSION}-gpl.tgz
tar -xf mbedtls-${MBEDTLS_VERSION}-gpl.tgz
cd mbedtls-${MBEDTLS_VERSION}
sed -i '.orig' 's/\/\/\#define MBEDTLS_THREADING_PTHREAD/\#define MBEDTLS_THREADING_PTHREAD/g' include/mbedtls/config.h
sed -i '.orig' 's/\/\/\#define MBEDTLS_THREADING_C/\#define MBEDTLS_THREADING_C/g' include/mbedtls/config.h
mkdir build
cd ./build
cmake -DCMAKE_INSTALL_PREFIX="/tmp/obsdeps" -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DCMAKE_FIND_FRAMEWORK=LAST -DENABLE_PROGRAMS=OFF ..
make -j
make install
find /tmp/obsdeps/lib -name libmbed\*.dylib -exec cp \{\} ${DEPS_DEST}/bin/ \;
install_name_tool -id /tmp/obsdeps/bin/libmbedtls.12.dylib ${DEPS_DEST}/bin/libmbedtls.12.dylib
install_name_tool -id /tmp/obsdeps/bin/libmbedcrypto.3.dylib ${DEPS_DEST}/bin/libmbedcrypto.3.dylib
install_name_tool -id /tmp/obsdeps/bin/libmbedx509.0.dylib ${DEPS_DEST}/bin/libmbedx509.0.dylib
install_name_tool -change libmbedtls.12.dylib /tmp/obsdeps/bin/libmbedtls.12.dylib ${DEPS_DEST}/bin/libmbedcrypto.3.dylib
install_name_tool -change libmbedx509.0.dylib /tmp/obsdeps/bin/libmbedx509.0.dylib ${DEPS_DEST}/bin/libmbedx509.0.dylib
install_name_tool -change libmbedcrypto.3.dylib /tmp/obsdeps/bin/libmbedcrypto.3.dylib ${DEPS_DEST}/bin/libmbedx509.0.dylib
install_name_tool -change libmbedtls.12.dylib /tmp/obsdeps/bin/libmbedtls.12.dylib ${DEPS_DEST}/bin/libmbedtls.12.dylib
install_name_tool -change libmbedx509.0.dylib /tmp/obsdeps/bin/libmbedx509.0.dylib ${DEPS_DEST}/bin/libmbedtls.12.dylib
install_name_tool -change libmbedcrypto.3.dylib /tmp/obsdeps/bin/libmbedcrypto.3.dylib ${DEPS_DEST}/bin/libmbedtls.12.dylib
rsync -avh --include="*/" --include="*.h" --exclude="*" ./include/mbedtls/* ${DEPS_DEST}/include/mbedtls
rsync -avh --include="*/" --include="*.h" --exclude="*" ../include/mbedtls/* ${DEPS_DEST}/include/mbedtls
if ! [ -d /tmp/obsdeps/lib/pkgconfig ]; then
mkdir -p /tmp/obsdeps/lib/pkgconfig
fi
cat <<EOF > /tmp/obsdeps/lib/pkgconfig/mbedcrypto.pc
prefix=/tmp/obsdeps
libdir=\${prefix}/lib
includedir=\${prefix}/include
Name: mbedcrypto
Description: lightweight crypto and SSL/TLS library.
Version: ${MBEDTLS_VERSION}
Libs: -L\${libdir} -lmbedcrypto
Cflags: -I\${includedir}
EOF
cat <<EOF > /tmp/obsdeps/lib/pkgconfig/mbedtls.pc
prefix=/tmp/obsdeps
libdir=\${prefix}/lib
includedir=\${prefix}/include
Name: mbedtls
Description: lightweight crypto and SSL/TLS library.
Version: ${MBEDTLS_VERSION}
Libs: -L\${libdir} -lmbedtls
Cflags: -I\${includedir}
Requires.private: mbedx509
EOF
cat <<EOF > /tmp/obsdeps/lib/pkgconfig/mbedx509.pc
prefix=/tmp/obsdeps
libdir=\${prefix}/lib
includedir=\${prefix}/include
Name: mbedx509
Description: The mbedTLS X.509 library
Version: ${MBEDTLS_VERSION}
Libs: -L\${libdir} -lmbedx509
Cflags: -I\${includedir}
Requires.private: mbedcrypto
EOF
cd $WORK_DIR
}
build_srt() {
SRT_VERSION=${1}
hr "Building libsrt v${SRT_VERSION}"
# srt
curl -L -O https://github.com/Haivision/srt/archive/v${SRT_VERSION}.tar.gz
tar -xf v${SRT_VERSION}.tar.gz
cd srt-${SRT_VERSION}
mkdir build
cd ./build
cmake -DCMAKE_INSTALL_PREFIX="/tmp/obsdeps" -DENABLE_APPS=OFF -DUSE_ENCLIB="mbedtls" -DENABLE_STATIC=ON -DENABLE_SHARED=OFF -DSSL_INCLUDE_DIRS="/tmp/obsdeps/include" -DSSL_LIBRARY_DIRS="/tmp/obsdeps/lib" -DCMAKE_FIND_FRAMEWORK=LAST ..
make -j
make install
cd $WORK_DIR
}
build_ffmpeg() {
FFMPEG_VERSION=${1}
hr "Building ffmpeg v${FFMPEG_VERSION}"
export LDFLAGS="-L/tmp/obsdeps/lib"
export CFLAGS="-I/tmp/obsdeps/include"
export LD_LIBRARY_PATH="/tmp/obsdeps/lib"
# FFMPEG
curl -L -O https://github.com/FFmpeg/FFmpeg/archive/n${FFMPEG_VERSION}.zip
unzip ./n${FFMPEG_VERSION}.zip
cd ./FFmpeg-n${FFMPEG_VERSION}
mkdir build
cd ./build
../configure --pkg-config-flags="--static" --extra-ldflags="-mmacosx-version-min=10.11" --enable-shared --disable-static --shlibdir="/tmp/obsdeps/bin" --enable-gpl --disable-doc --enable-libx264 --enable-libopus --enable-libvorbis --enable-libvpx --enable-libsrt --disable-outdev=sdl
make -j
find . -name \*.dylib -exec cp \{\} ${DEPS_DEST}/bin/ \;
rsync -avh --include="*/" --include="*.h" --exclude="*" ../* ${DEPS_DEST}/include/
rsync -avh --include="*/" --include="*.h" --exclude="*" ./* ${DEPS_DEST}/include/
install_name_tool -change libmbedcrypto.3.dylib /tmp/obsdeps/bin/libmbedcrypto.3.dylib ${DEPS_DEST}/bin/libavfilter.7.dylib
install_name_tool -change libmbedcrypto.3.dylib /tmp/obsdeps/bin/libmbedcrypto.3.dylib ${DEPS_DEST}/bin/libavdevice.58.dylib
install_name_tool -change libmbedcrypto.3.dylib /tmp/obsdeps/bin/libmbedcrypto.3.dylib ${DEPS_DEST}/bin/libavformat.58.dylib
install_name_tool -change libmbedx509.0.dylib /tmp/obsdeps/bin/libmbedx509.0.dylib ${DEPS_DEST}/bin/libavfilter.7.dylib
install_name_tool -change libmbedx509.0.dylib /tmp/obsdeps/bin/libmbedx509.0.dylib ${DEPS_DEST}/bin/libavdevice.58.dylib
install_name_tool -change libmbedx509.0.dylib /tmp/obsdeps/bin/libmbedx509.0.dylib ${DEPS_DEST}/bin/libavformat.58.dylib
install_name_tool -change libmbedtls.12.dylib /tmp/obsdeps/bin/libmbedtls.12.dylib ${DEPS_DEST}/bin/libavfilter.7.dylib
install_name_tool -change libmbedtls.12.dylib /tmp/obsdeps/bin/libmbedtls.12.dylib ${DEPS_DEST}/bin/libavdevice.58.dylib
install_name_tool -change libmbedtls.12.dylib /tmp/obsdeps/bin/libmbedtls.12.dylib ${DEPS_DEST}/bin/libavformat.58.dylib
unset LDFLAGS
unset CFLAGS
unset LD_LIBRARY_PATH
cd $WORK_DIR
}
build_luajit() {
LUAJIT_VERSION=${1}
hr "Building libluajit v${LUAJIT_VERSION}"
#luajit
curl -L -O https://luajit.org/download/LuaJIT-${LUAJIT_VERSION}.tar.gz
tar -xf LuaJIT-${LUAJIT_VERSION}.tar.gz
cd LuaJIT-${LUAJIT_VERSION}
make PREFIX=/tmp/obsdeps
make PREFIX=/tmp/obsdeps install
ln -sf luajit-${LUAJIT_VERSION} /tmp/obsdeps/bin/luajit
find /tmp/obsdeps/lib -name libluajit\*.dylib -exec cp \{\} ${DEPS_DEST}/lib/ \;
rsync -avh --include="*/" --include="*.h" --exclude="*" src/* ${DEPS_DEST}/include/
make PREFIX=/tmp/obsdeps uninstall
cd $WORK_DIR
}
build_libpng() {
LIBPNG_VERSION=${1}
hr "Building libpng v${LIBPNG_VERSION}"
curl -L -O https://downloads.sourceforge.net/project/libpng/libpng16/${LIBPNG_VERSION}/libpng-${LIBPNG_VERSION}.tar.xz
tar -xf libpng-${LIBPNG_VERSION}.tar.xz
cd libpng-${LIBPNG_VERSION}
./configure --enable-static --disable-shared --prefix="/tmp/obsdeps"
make PREFIX=/tmp/obsdeps
make PREFIX=/tmp/obsdeps install
cd $WORK_DIR
}
build_freetype() {
FREETYPE_VERSION=${1}
hr "Building libfreetype v${FREETYPE_VERSION}"
export CFLAGS="-mmacosx-version-min=10.11"
curl -L -O https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.gz
tar -xf freetype-${FREETYPE_VERSION}.tar.gz
cd freetype-${FREETYPE_VERSION}
./configure --enable-shared --disable-static --prefix="/tmp/obsdeps" --enable-freetype-config --without-harfbuzz
make PREFIX=/tmp/obsdeps
make PREFIX=/tmp/obsdeps install
find /tmp/obsdeps/lib -name libfreetype\*.dylib -exec cp \{\} ${DEPS_DEST}/lib/ \;
rsync -avh --include="*/" --include="*.h" --exclude="*" include/* ${DEPS_DEST}/include/
unset CFLAGS
cd $WORK_DIR
}
## END BUILD FUNCS ##
package_deps() {
VERSION=${1}
hr "Packaging dependencies as osx-deps-${VERSION}.tar.gz.."
tar -czf osx-deps-${VERSION}.tar.gz obsdeps
if ! [ -d "${CURDIR}/osx" ]; then
mkdir ${CURDIR}/osx
fi
cp ./osx-deps-${VERSION}.tar.gz ${CURDIR}/osx
}
BUILD_INFO="Building OBS macOS dependencies with this configuration:"
for PACKAGE in "${BUILD_PACKAGES[@]}"; do
set -- ${PACKAGE}
BUILD_INFO="${BUILD_INFO}\n${1}\t: ${2}"
done
hr "${BUILD_INFO}"
for PACKAGE in "${BUILD_PACKAGES[@]}"; do
set -- ${PACKAGE}
trap 'caught_error ${1}' ERR
FUNC_NAME="build_${1}"
${FUNC_NAME} ${2}
done
package_deps "$(date +"%Y-%m-%d")"
hr "All Done!"