forked from arthenica/ffmpeg-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ios.sh
executable file
·309 lines (254 loc) · 9.33 KB
/
ios.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
#!/bin/bash
# CHECK IF XCODE IS INSTALLED
if [ ! -x "$(command -v xcrun)" ]; then
echo -e "\n(*) xcrun command not found. Please check your Xcode installation\n"
exit 1
fi
if [ ! -x "$(command -v xcodebuild)" ]; then
echo -e "\n(*) xcodebuild command not found. Please check your Xcode installation\n"
exit 1
fi
# LOAD INITIAL SETTINGS
export BASEDIR="$(pwd)"
export FFMPEG_KIT_BUILD_TYPE="ios"
source "${BASEDIR}"/scripts/variable.sh
source "${BASEDIR}"/scripts/function-${FFMPEG_KIT_BUILD_TYPE}.sh
disabled_libraries=()
# SET DEFAULTS SETTINGS
enable_default_ios_architectures
# SELECT XCODE VERSION USED FOR BUILDING
XCODE_FOR_FFMPEG_KIT=$(ls ~/.xcode.for.ffmpeg.kit.sh 2>>"${BASEDIR}"/build.log)
if [[ -f ${XCODE_FOR_FFMPEG_KIT} ]]; then
source "${XCODE_FOR_FFMPEG_KIT}" 1>>"${BASEDIR}"/build.log 2>&1
fi
# DETECT IOS SDK VERSION
export DETECTED_IOS_SDK_VERSION="$(xcrun --sdk iphoneos --show-sdk-version 2>>${BASEDIR}/build.log)"
echo -e "\nINFO: Using SDK ${DETECTED_IOS_SDK_VERSION} by Xcode provided at $(xcode-select -p)\n" 1>>"${BASEDIR}"/build.log 2>&1
echo -e "INFO: Build options: $*\n" 1>>"${BASEDIR}"/build.log 2>&1
# SET DEFAULT BUILD OPTIONS
export GPL_ENABLED="no"
DISPLAY_HELP=""
BUILD_TYPE_ID=""
BUILD_FULL=""
FFMPEG_KIT_XCF_BUILD=""
BUILD_FORCE=""
BUILD_VERSION=$(git describe --tags --always 2>>"${BASEDIR}"/build.log)
if [[ -z ${BUILD_VERSION} ]]; then
echo -e "\n(*): Can not run git commands in this folder. See build.log.\n"
exit 1
fi
# MAIN BUILDS ENABLED BY DEFAULT
enable_main_build
# PROCESS LTS BUILD OPTION FIRST AND SET BUILD TYPE: MAIN OR LTS
for argument in "$@"; do
if [[ "$argument" == "-l" ]] || [[ "$argument" == "--lts" ]]; then
enable_lts_build
BUILD_TYPE_ID+="LTS "
fi
done
# PROCESS BUILD OPTIONS
while [ ! $# -eq 0 ]; do
case $1 in
-h | --help)
DISPLAY_HELP="1"
;;
-v | --version)
display_version
exit 0
;;
--skip-*)
SKIP_LIBRARY=$(echo "$1" | sed -e 's/^--[A-Za-z]*-//g')
skip_library "${SKIP_LIBRARY}"
;;
--no-bitcode)
export NO_BITCODE="1"
;;
--no-framework)
NO_FRAMEWORK="1"
;;
--no-output-redirection)
no_output_redirection
;;
--no-workspace-cleanup-*)
NO_WORKSPACE_CLEANUP_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-[A-Za-z]*-[A-Za-z]*-//g')
no_workspace_cleanup_library "${NO_WORKSPACE_CLEANUP_LIBRARY}"
;;
-d | --debug)
enable_debug
;;
-s | --speed)
optimize_for_speed
;;
-l | --lts) ;;
-x | --xcframework)
FFMPEG_KIT_XCF_BUILD="1"
;;
-f | --force)
export BUILD_FORCE="1"
;;
--reconf-*)
CONF_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
reconf_library "${CONF_LIBRARY}"
;;
--rebuild-*)
BUILD_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
rebuild_library "${BUILD_LIBRARY}"
;;
--redownload-*)
DOWNLOAD_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
redownload_library "${DOWNLOAD_LIBRARY}"
;;
--full)
BUILD_FULL="1"
;;
--enable-gpl)
export GPL_ENABLED="yes"
;;
--enable-custom-library-*)
CUSTOM_LIBRARY_OPTION_KEY=$(echo $1 | sed -e 's/^--enable-custom-//g;s/=.*$//g')
CUSTOM_LIBRARY_OPTION_VALUE=$(echo $1 | sed -e 's/^--enable-custom-.*=//g')
echo -e "INFO: Custom library options detected: ${CUSTOM_LIBRARY_OPTION_KEY} ${CUSTOM_LIBRARY_OPTION_VALUE}\n" 1>>"${BASEDIR}"/build.log 2>&1
generate_custom_library_environment_variables "${CUSTOM_LIBRARY_OPTION_KEY}" "${CUSTOM_LIBRARY_OPTION_VALUE}"
;;
--enable-*)
ENABLED_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
enable_library "${ENABLED_LIBRARY}"
;;
--disable-lib-*)
DISABLED_LIB=$(echo $1 | sed -e 's/^--[A-Za-z]*-[A-Za-z]*-//g')
disabled_libraries+=("${DISABLED_LIB}")
;;
--disable-*)
DISABLED_ARCH=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
disable_arch "${DISABLED_ARCH}"
;;
--target=*)
TARGET=$(echo $1 | sed -e 's/^--[A-Za-z]*=//g')
export IOS_MIN_VERSION=${TARGET}
;;
--mac-catalyst-target=*)
TARGET=$(echo $1 | sed -e 's/^--[A-Za-z]*-[A-Za-z]*-[A-Za-z]*=//g')
export MAC_CATALYST_MIN_VERSION=${TARGET}
;;
*)
print_unknown_option "$1"
;;
esac
shift
done
# PROCESS FULL OPTION AS LAST OPTION
if [[ -n ${BUILD_FULL} ]]; then
for library in {0..61}; do
if [ ${GPL_ENABLED} == "yes" ]; then
enable_library "$(get_library_name "$library")" 1
else
if [[ $(is_gpl_licensed "$library") -eq 1 ]]; then
enable_library "$(get_library_name "$library")" 1
fi
fi
done
fi
# DISABLE SPECIFIED LIBRARIES
for disabled_library in ${disabled_libraries[@]}; do
set_library "${disabled_library}" 0
done
# IF HELP DISPLAYED EXIT
if [[ -n ${DISPLAY_HELP} ]]; then
display_help
exit 0
fi
# DISABLE NOT SUPPORTED ARCHITECTURES
disable_ios_architecture_not_supported_on_detected_sdk_version "${ARCH_ARMV7}"
disable_ios_architecture_not_supported_on_detected_sdk_version "${ARCH_ARMV7S}"
disable_ios_architecture_not_supported_on_detected_sdk_version "${ARCH_I386}"
disable_ios_architecture_not_supported_on_detected_sdk_version "${ARCH_ARM64E}"
disable_ios_architecture_not_supported_on_detected_sdk_version "${ARCH_X86_64_MAC_CATALYST}"
disable_ios_architecture_not_supported_on_detected_sdk_version "${ARCH_ARM64_MAC_CATALYST}"
disable_ios_architecture_not_supported_on_detected_sdk_version "${ARCH_ARM64_SIMULATOR}"
# CHECK SOME RULES FOR .framework BUNDLES
# 1. DISABLE arm64-mac-catalyst IN framework BUNDLES
if [[ ${NO_FRAMEWORK} -ne 1 ]] && [[ -z ${FFMPEG_KIT_XCF_BUILD} ]] && [[ ${ENABLED_ARCHITECTURES[${ARCH_ARM64_MAC_CATALYST}]} -eq 1 ]]; then
echo -e "INFO: Disabled arm64-mac-catalyst architecture which cannot exist in a framework bundle.\n" 1>>"${BASEDIR}"/build.log 2>&1
disable_arch "arm64-mac-catalyst"
fi
# 2. DISABLE x86-64-mac-catalyst IN framework BUNDLES
if [[ ${NO_FRAMEWORK} -ne 1 ]] && [[ -z ${FFMPEG_KIT_XCF_BUILD} ]] && [[ ${ENABLED_ARCHITECTURES[${ARCH_X86_64_MAC_CATALYST}]} -eq 1 ]]; then
echo -e "INFO: Disabled x86-64-mac-catalyst architecture which cannot exist in a framework bundle.\n" 1>>"${BASEDIR}"/build.log 2>&1
disable_arch "x86-64-mac-catalyst"
fi
# 3. DISABLE arm64-simulator WHEN arm64 IS ENABLED IN framework BUNDLES
if [[ ${NO_FRAMEWORK} -ne 1 ]] && [[ -z ${FFMPEG_KIT_XCF_BUILD} ]] && [[ ${ENABLED_ARCHITECTURES[${ARCH_ARM64}]} -eq 1 ]] && [[ ${ENABLED_ARCHITECTURES[${ARCH_ARM64_SIMULATOR}]} -eq 1 ]]; then
echo -e "INFO: Disabled arm64-simulator architecture which cannot co-exist with arm64 in the same framework bundle.\n" 1>>"${BASEDIR}"/build.log 2>&1
disable_arch "arm64-simulator"
fi
echo -e "\nBuilding ffmpeg-kit ${BUILD_TYPE_ID}shared library for iOS\n"
echo -e -n "INFO: Building ffmpeg-kit ${BUILD_VERSION} ${BUILD_TYPE_ID}for iOS: " 1>>"${BASEDIR}"/build.log 2>&1
echo -e "$(date)\n" 1>>"${BASEDIR}"/build.log 2>&1
# PRINT BUILD SUMMARY
print_enabled_architectures
print_enabled_libraries
print_reconfigure_requested_libraries
print_rebuild_requested_libraries
print_redownload_requested_libraries
print_custom_libraries
# VALIDATE GPL FLAGS
for gpl_library in {$LIBRARY_X264,$LIBRARY_XVIDCORE,$LIBRARY_X265,$LIBRARY_LIBVIDSTAB,$LIBRARY_RUBBERBAND}; do
if [[ ${ENABLED_LIBRARIES[$gpl_library]} -eq 1 ]]; then
library_name=$(get_library_name "${gpl_library}")
if [ ${GPL_ENABLED} != "yes" ]; then
echo -e "\n(*) Invalid configuration detected. GPL library ${library_name} enabled without --enable-gpl flag.\n"
echo -e "\n(*) Invalid configuration detected. GPL library ${library_name} enabled without --enable-gpl flag.\n" 1>>"${BASEDIR}"/build.log 2>&1
exit 1
fi
fi
done
echo -n -e "\nDownloading sources: "
echo -e "INFO: Downloading the source code of ffmpeg and external libraries.\n" 1>>"${BASEDIR}"/build.log 2>&1
# DOWNLOAD GNU CONFIG
download_gnu_config
# DOWNLOAD LIBRARY SOURCES
downloaded_library_sources "${ENABLED_LIBRARIES[@]}"
# THIS WILL SAVE ARCHITECTURES TO BUILD
TARGET_ARCH_LIST=()
# BUILD ENABLED LIBRARIES ON ENABLED ARCHITECTURES
for run_arch in {0..12}; do
if [[ ${ENABLED_ARCHITECTURES[$run_arch]} -eq 1 ]]; then
export ARCH=$(get_arch_name "$run_arch")
export FULL_ARCH=$(get_full_arch_name "$run_arch")
export SDK_PATH=$(get_sdk_path)
export SDK_NAME=$(get_sdk_name)
# EXECUTE MAIN BUILD SCRIPT
. "${BASEDIR}"/scripts/main-ios.sh "${ENABLED_LIBRARIES[@]}"
TARGET_ARCH_LIST+=("${FULL_ARCH}")
# CLEAR FLAGS
for library in {0..61}; do
library_name=$(get_library_name "${library}")
unset "$(echo "OK_${library_name}" | sed "s/\-/\_/g")"
unset "$(echo "DEPENDENCY_REBUILT_${library_name}" | sed "s/\-/\_/g")"
done
fi
done
echo -e -n "\n"
# DO NOT BUILD FRAMEWORKS
if [[ ${NO_FRAMEWORK} -ne 1 ]]; then
# BUILD FFMPEG-KIT
if [[ -n ${TARGET_ARCH_LIST[0]} ]]; then
# INITIALIZE TARGET FOLDERS
initialize_prebuilt_ios_folders
# PREPARE PLATFORM ARCHITECTURE STRINGS
build_apple_architecture_variant_strings
if [[ -n ${FFMPEG_KIT_XCF_BUILD} ]]; then
echo -e -n "\nCreating xcframeworks under prebuilt: "
create_universal_libraries_for_ios_xcframeworks
create_frameworks_for_ios_xcframeworks
create_ios_xcframeworks
else
echo -e -n "\nCreating frameworks under prebuilt: "
create_universal_libraries_for_ios_default_frameworks
create_ios_default_frameworks
fi
echo -e "ok\n"
fi
else
echo -e "INFO: Skipped creating iOS frameworks.\n" 1>>"${BASEDIR}"/build.log 2>&1
fi