-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·244 lines (230 loc) · 8.95 KB
/
build.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
#!/bin/sh -e
Help()
{
# Display Help
echo "compile libmpv."
echo "usage: build.sh [-h]"
echo "options:"
echo "p : Optional, platforms(macOS iOS tvOS iSimulator tvSimulator). Default: all"
echo "a : Optional, archs(x86_64 arm64). Default: all, please note iOS and tvOS will ignore this and always be arm64"
echo "l : Optional, libraries(openssl libpng freetype fribidi harfbuzz libass readline gmp nettle gnutls smbclient moltenvk shaderc littlecms libplacebo libdav1d libbluray ffmpeg uchardet luajit mpv)."
echo "o : Optional, optimize level, default: 2 when debug is false, 0 when debug is true"
echo "g : Optional, enable gpl, default: false"
echo "d : Optional, enable debug, default: false"
echo "h : Optional, Print this Help."
echo
}
PKG_DEFAULT_PATH=$(pkg-config --variable pc_path pkg-config)
export ROOT="$(pwd)"
export SRC="$ROOT/Vendor"
export PKG_CONFIG_LIBDIR
export LDFLAGS
export CFLAGS
export CXXFLAGS
export CPPFLAGS
export COMMON_OPTIONS
export ENVIRONMENT
export ARCH
export PLATFORM
export CMAKE_OSX_ARCHITECTURES
export SDKPATH
export BUILDDIR
export LC_CTYPE="C"
#export LC_ALL="C"
export CC="/usr/bin/clang"
#export PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/:/usr/local/opt/gnu-sed/libexec/gnubin:/opt/homebrew/bin:$PATH"
export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:/opt/homebrew/bin:$PATH"
export SCRATCH
export ARCH
export DEBUG_SWITCH
export GPL_SWITCH
export OptimizationLevel=2
# add maccatalyst
PLATFORMS="macos ios tvos isimulator tvsimulator"
LIBRARIES="openssl libpng freetype fribidi harfbuzz libass moltenvk shaderc littlecms libplacebo libdav1d libbluray ffmpeg uchardet luajit mpv"
#LIBRARIES="openssl libpng freetype fribidi harfbuzz libass readline gmp nettle gnutls smbclient shaderc littlecms libplacebo libdav1d libbluray ffmpeg uchardet luajit mpv"
#LIBRARIES="openssl libpng freetype fribidi harfbuzz libass shaderc littlecms libplacebo libdav1d libbluray ffmpeg uchardet luajit mpv"
#LIBRARIES="openssl srt libpng freetype brotli fribidi harfbuzz libass readline gmp nettle gnutls smbclient shaderc littlecms libdovi libplacebo libdav1d libbluray ffmpeg uchardet luajit mpv"
#LIBRARIES="readline gmp nettle gnutls smbclient"
while getopts ":hp:a:l:o:gd" OPTION; do
case $OPTION in
h)
Help
exit
;;
p)
PLATFORMS=$(echo "$OPTARG" | awk '{print tolower($0)}')
;;
a)
ARCHS_FILTERS=$(echo "$OPTARG" | awk '{print tolower($0)}')
;;
l)
LIBRARIES=$(echo "$OPTARG" | awk '{print tolower($0)}')
;;
o)
OptimizationLevelSetting=$(echo "$OPTARG" | awk '{print tolower($0)}')
;;
g)
GPL_SWITCH=true
;;
d)
DEBUG_SWITCH=true
;;
?)
echo "Invalid option"
exit 1
;;
esac
done
set -x
if [[ ! -z $OptimizationLevelSetting ]]; then
OptimizationLevel=$OptimizationLevelSetting
fi
if [[ ! -z $DEBUG_SWITCH ]]; then
debug_flag="-g"
buile_type="debug"
if [[ ! -z $OptimizationLevelSetting ]]; then
OptimizationLevel=0
fi
else
buile_type="release"
fi
which -s brew
if [[ $? != 0 ]]; then
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew list pkg-config || brew install pkg-config
brew list automake || brew install automake
brew list meson || brew install meson
brew list ninja || brew install ninja
brew list cmake || brew install cmake
brew list nasm || brew install nasm
brew list sdl2 || brew install sdl2
brew list gnu-sed || brew install gnu-sed
if [[ $LIBRARIES == *"moltenvk"* ]]; then
./scripts/moltenvk-build
fi
for PLATFORM in $PLATFORMS; do
#rm -rf build/scratch-$PLATFORM
if [[ "$PLATFORM" = "macos" ]]; then
MIN_VERSION="10.15"
if [[ -z $ARCHS_FILTERS ]]; then
ARCHS="x86_64 arm64"
else
ARCHS=$ARCHS_FILTERS
fi
SDK_VERSION=$(xcrun -sdk macosx --show-sdk-version)
PLATFORM_NAME="MacOS"
SDKPATH="$(xcrun -sdk macosx --show-sdk-path)"
DEPLOYMENT_TARGET="-mmacosx-version-min=$MIN_VERSION"
#DEPLOYMENT_TARGET_LDFLAG="-Wl,-macosx-version-min,$MIN_VERSION"
DEPLOYMENT_TARGET_LDFLAG=""
elif [[ "$PLATFORM" = "ios" ]]; then
MIN_VERSION="13.0"
ARCHS="arm64"
SDK_VERSION=$(xcrun -sdk iphoneos --show-sdk-version)
PLATFORM_NAME="iPhoneOS"
SDKPATH="$(xcrun -sdk iphoneos --show-sdk-path)"
DEPLOYMENT_TARGET="-mios-version-min=$MIN_VERSION"
#DEPLOYMENT_TARGET_LDFLAG="-Wl,-ios_version_min,$MIN_VERSION"
elif [[ "$PLATFORM" = "tvos" ]]; then
MIN_VERSION="13.0"
ARCHS="arm64"
SDK_VERSION=$(xcrun -sdk appletvos --show-sdk-version)
PLATFORM_NAME="AppleTVOS"
SDKPATH="$(xcrun -sdk appletvos --show-sdk-path)"
DEPLOYMENT_TARGET="-mtvos-version-min=$MIN_VERSION"
CFLAG_HAVE_FORK=" -DHAVE_FORK=0 "
#DEPLOYMENT_TARGET_LDFLAG="-Wl,-tvos_version_min,$MIN_VERSION"
elif [[ "$PLATFORM" = "isimulator" ]]; then
MIN_VERSION="13.0"
if [[ -z $ARCHS_FILTERS ]]; then
ARCHS="x86_64 arm64"
else
ARCHS=$ARCHS_FILTERS
fi
SDK_VERSION=$(xcrun -sdk iphonesimulator --show-sdk-version)
PLATFORM_NAME="iPhoneSimulator"
SDKPATH="$(xcrun -sdk iphonesimulator --show-sdk-path)"
DEPLOYMENT_TARGET="-mios-simulator-version-min=$MIN_VERSION"
#DEPLOYMENT_TARGET_LDFLAG="-Wl,-ios_simulator_version_min,$MIN_VERSION"
elif [[ "$PLATFORM" = "tvsimulator" ]]; then
MIN_VERSION="13.0"
if [[ -z $ARCHS_FILTERS ]]; then
ARCHS="x86_64 arm64"
else
ARCHS=$ARCHS_FILTERS
fi
SDK_VERSION=$(xcrun -sdk appletvsimulator --show-sdk-version)
PLATFORM_NAME="AppleTVSimulator"
SDKPATH="$(xcrun -sdk appletvsimulator --show-sdk-path)"
DEPLOYMENT_TARGET="-mtvos-simulator-version-min=$MIN_VERSION"
CFLAG_HAVE_FORK=" -DHAVE_FORK=0 "
#DEPLOYMENT_TARGET_LDFLAG="-Wl,-tvos_simulator_version_min,$MIN_VERSION"
elif [[ "$PLATFORM" = "maccatalyst" ]]; then
MIN_VERSION="13.0"
if [[ -z $ARCHS_FILTERS ]]; then
ARCHS="x86_64 arm64"
else
ARCHS=$ARCHS_FILTERS
fi
SDK_VERSION=$(xcrun -sdk macosx --show-sdk-version)
PLATFORM_NAME="AppleTVSimulator"
SDKPATH="$(xcrun -sdk macosx --show-sdk-path)"
DEPLOYMENT_TARGET="-target x86_64-apple-ios-macabi"
DEPLOYMENT_TARGET_LDFLAG=""
else
echo "illegal platform option"
exit 1
fi
SCRIPTS="$ROOT/scripts"
SCRATCH="$ROOT/build/scratch-$PLATFORM"
for ARCH in $ARCHS; do
echo "PLATFORM: $PLATFORM ARCH: $ARCH"
export HOSTFLAG="$ARCH-$PLATFORM-darwin"
if [[ $PLATFORM = "macos" ]]; then
HOSTFLAG_PLATFORM="apple"
elif [[ $PLATFORM = "ios" || $PLATFORM = "isimulator" || $PLATFORM = "maccatalyst" ]]; then
HOSTFLAG_PLATFORM="ios"
elif [[ $PLATFORM = "tvos" || $PLATFORM = "tvsimulator" ]]; then
HOSTFLAG_PLATFORM="tvos"
fi
HOSTFLAG="$ARCH-$HOSTFLAG_PLATFORM-darwin"
if [[ $ARCH = "arm64" ]]; then
if [[ "$PLATFORM" = "maccatalyst" ]]; then
DEPLOYMENT_TARGET="-target arm64-apple-ios-macabi"
fi
CMAKE_OSX_ARCHITECTURES=$ARCH
ACFLAGS="-arch $ARCH -isysroot $SDKPATH $DEPLOYMENT_TARGET"
ALDFLAGS="-arch $ARCH -isysroot $SDKPATH $DEPLOYMENT_TARGET_LDFLAG"
elif [[ $ARCH = "x86_64" ]]; then
CMAKE_OSX_ARCHITECTURES=$ARCH
ACFLAGS="-arch $ARCH -isysroot $SDKPATH $DEPLOYMENT_TARGET"
ALDFLAGS="-arch $ARCH -isysroot $SDKPATH $DEPLOYMENT_TARGET_LDFLAG "
else
echo "Unhandled architecture option"
exit 1
fi
CFLAGS="$ACFLAGS $CFLAG_HAVE_FORK $debug_flag -O$OptimizationLevel"
LDFLAGS="$ALDFLAGS"
CXXFLAGS="$CFLAGS"
CPPFLAGS="$CFLAGS"
PKG_CONFIG_LIBDIR="$SCRATCH/$ARCH/lib/pkgconfig:$PKG_DEFAULT_PATH"
mkdir -p $SCRATCH
export COMMON_OPTION_PREFIX="--prefix=$SCRATCH/$ARCH"
COMMON_OPTIONS="$COMMON_OPTION_PREFIX --enable-static \
--disable-shared --disable-dependency-tracking --with-pic --host=$HOSTFLAG --with-sysroot=$SDKPATH"
export MESON_COMMON_OPTIONS="-Dprefix=$SCRATCH/$ARCH -Dbuildtype=$buile_type -Ddefault_library=static --cross-file=$ROOT/meson/$PLATFORM-$ARCH.txt"
#export MESON_COMMON_OPTIONS="-Dprefix=$SCRATCH/$ARCH -Dbuildtype=release -Ddefault_library=static"
for LIBRARY in $LIBRARIES; do
if [[ $LIBRARY = "moltenvk" ]]; then
continue
fi
BUILDDIR=$SCRATCH/$ARCH/$LIBRARY
echo "building $LIBRARY"
rm -fr $BUILDDIR
mkdir -p $BUILDDIR && cd $_ && $SCRIPTS/$LIBRARY-build $LIBRARY
done
done
done