From 281ac06e9c9e8727e5b76c6e56bf7378e9be8fa6 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Feb 2024 21:02:57 -0800 Subject: [PATCH] Adding support for visionOS (xros) build --- apple.sh | 9 + scripts/function-apple.sh | 43 +++ scripts/function-xros.sh | 542 ++++++++++++++++++++++++++++++++++++++ scripts/function.sh | 7 +- scripts/main-xros.sh | 246 +++++++++++++++++ scripts/variable.sh | 8 +- xros.sh | 285 ++++++++++++++++++++ 7 files changed, 1135 insertions(+), 5 deletions(-) create mode 100755 scripts/function-xros.sh create mode 100755 scripts/main-xros.sh create mode 100755 xros.sh diff --git a/apple.sh b/apple.sh index 38c21c8..80a0cb8 100755 --- a/apple.sh +++ b/apple.sh @@ -6,6 +6,8 @@ enable_default_architecture_variants() { ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_MAC_CATALYST]=1 ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_APPLETVOS]=1 ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_APPLETVSIMULATOR]=1 + ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_XROS]=1 + ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_XRSIMULATOR]=1 ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_MACOS]=1 } @@ -98,6 +100,12 @@ disable_arch_variant() { appletvsimulator) ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_APPLETVSIMULATOR]=0 ;; + xros) + ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_XROS]=0 + ;; + xrsimulator) + ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_XRSIMULATOR]=0 + ;; macosx) ENABLED_ARCHITECTURE_VARIANTS[ARCH_VAR_MACOS]=0 ;; @@ -136,6 +144,7 @@ fi # DETECT SDK VERSIONS DETECTED_IOS_SDK_VERSION="$(xcrun --sdk iphoneos --show-sdk-version 2>>"${BASEDIR}"/build.log)" DETECTED_TVOS_SDK_VERSION="$(xcrun --sdk appletvos --show-sdk-version 2>>"${BASEDIR}"/build.log)" +DETECTED_XROS_SDK_VERSION="$(xcrun --sdk xros --show-sdk-version 2>>"${BASEDIR}"/build.log)" DETECTED_MACOS_SDK_VERSION="$(xcrun --sdk macosx --show-sdk-version 2>>"${BASEDIR}"/build.log)" echo -e "INFO: Using iOS SDK: ${DETECTED_IOS_SDK_VERSION}, tvOS SDK: ${DETECTED_TVOS_SDK_VERSION}, macOS SDK: ${DETECTED_MACOS_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 diff --git a/scripts/function-apple.sh b/scripts/function-apple.sh index a45b8b9..12970b3 100755 --- a/scripts/function-apple.sh +++ b/scripts/function-apple.sh @@ -114,6 +114,35 @@ disable_tvos_architecture_not_supported_on_detected_sdk_version() { fi } +# +# 1. architecture index +# +disable_xros_architecture_not_supported_on_detected_sdk_version() { + local ARCH_NAME=$(get_arch_name $1) + + case ${ARCH_NAME} in + arm64-simulator) + + # INTRODUCED IN TVOS SDK 14.0 + if [[ $(compare_versions "$DETECTED_XROS_SDK_VERSION" "1.0") -ge 1 ]]; then + local SUPPORTED=1 + else + local SUPPORTED=0 + fi + ;; + *) + local SUPPORTED=1 + ;; + esac + + if [[ ${SUPPORTED} -ne 1 ]]; then + if [[ -z ${BUILD_FORCE} ]]; then + echo -e "INFO: Disabled ${ARCH_NAME} architecture which is not supported on visionOS SDK $DETECTED_XROS_SDK_VERSION\n" 1>>"${BASEDIR}"/build.log 2>&1 + disable_arch "${ARCH_NAME}" + fi + fi +} + # # 1. architecture index # @@ -160,6 +189,8 @@ build_apple_architecture_variant_strings() { export ALL_TVOS_ARCHITECTURES="$(get_apple_architectures_for_variant "${ARCH_VAR_TVOS}")" export APPLETVOS_ARCHITECTURES="$(get_apple_architectures_for_variant "${ARCH_VAR_APPLETVOS}")" export APPLETV_SIMULATOR_ARCHITECTURES="$(get_apple_architectures_for_variant "${ARCH_VAR_APPLETVSIMULATOR}")" + export XROS_ARCHITECTURES="$(get_apple_architectures_for_variant "${ARCH_VAR_XROS}")" + export XR_SIMULATOR_ARCHITECTURES="$(get_apple_architectures_for_variant "${ARCH_VAR_XRSIMULATOR}")" export MACOSX_ARCHITECTURES="$(get_apple_architectures_for_variant "${ARCH_VAR_MACOS}")" } @@ -996,6 +1027,9 @@ get_sdk_name() { tvos) echo "appletvos" ;; + xros) + echo "xros" + ;; macos) echo "macosx" ;; @@ -1009,6 +1043,9 @@ get_sdk_name() { tvos) echo "appletvsimulator" ;; + xros) + echo "xrsimulator" + ;; macos) echo "macosx" ;; @@ -1025,6 +1062,9 @@ get_sdk_name() { tvos) echo "appletvsimulator" ;; + xros) + echo "xrsimulator" + ;; esac ;; *-mac-catalyst) @@ -1096,6 +1136,9 @@ get_min_sdk_version() { tvos) echo "${TVOS_MIN_VERSION}" ;; + xros) + echo "${XROS_MIN_VERSION}" + ;; macos) echo "${MACOS_MIN_VERSION}" ;; diff --git a/scripts/function-xros.sh b/scripts/function-xros.sh new file mode 100755 index 0000000..707157a --- /dev/null +++ b/scripts/function-xros.sh @@ -0,0 +1,542 @@ +#!/bin/bash + +source "${BASEDIR}/scripts/function-apple.sh" + +prepare_inline_sed + +enable_default_xros_architectures() { + ENABLED_ARCHITECTURES[ARCH_ARM64]=1 + ENABLED_ARCHITECTURES[ARCH_X86_64]=1 + ENABLED_ARCHITECTURES[ARCH_ARM64_SIMULATOR]=1 +} + +display_help() { + COMMAND=$(echo "$0" | sed -e 's/\.\///g') + + echo -e "\n'$COMMAND' builds FFmpegKit for visionOS platform. By default three architectures (arm64, arm64-simulator \ +and x86-64) are enabled without any external libraries. Options can be used to disable architectures and/or enable \ +external libraries. Please note that GPL libraries (external libraries with GPL license) need --enable-gpl flag to be \ +set explicitly. When compilation ends, libraries are created under the prebuilt folder.\n" + echo -e "Usage: ./$COMMAND [OPTION]...\n" + echo -e "Specify environment variables as VARIABLE=VALUE to override default build options.\n" + + display_help_options " -x, --xcframework\t\tbuild xcframework bundles instead of framework bundles" " -l, --lts build lts packages to support sdk 10.0+ devices" " --target=xros sdk version\toverride minimum deployment target [11.0]" + display_help_licensing + + echo -e "Architectures:" + + echo -e " --disable-arm64\t\tdo not build arm64 architecture [yes]" + echo -e " --disable-arm64-simulator\tdo not build arm64-simulator architecture [yes]" + echo -e " --disable-x86-64\t\tdo not build x86-64 architecture [yes]\n" + + echo -e "Libraries:" + echo -e " --full\t\t\tenables all non-GPL external libraries" + echo -e " --enable-xros-audiotoolbox\tbuild with built-in Apple AudioToolbox support [no]" + echo -e " --enable-xros-bzip2\t\tbuild with built-in bzip2 support [no]" + if [[ -z ${FFMPEG_KIT_LTS_BUILD} ]]; then + echo -e " --enable-xros-videotoolbox\tbuild with built-in Apple VideoToolbox support [no]" + fi + echo -e " --enable-xros-zlib\t\tbuild with built-in zlib [no]" + echo -e " --enable-xros-libiconv\tbuild with built-in libiconv [no]" + + display_help_common_libraries + display_help_gpl_libraries + display_help_custom_libraries + if [[ -n ${FFMPEG_KIT_XCF_BUILD} ]]; then + display_help_advanced_options " --no-framework\t\tdo not build xcframework bundles [no]" " --no-bitcode\t\t\tdo not enable bitcode in bundles [no]" + else + display_help_advanced_options " --no-framework\t\tdo not build framework bundles [no]" " --no-bitcode\t\t\tdo not enable bitcode in bundles [no]" + fi +} + +enable_main_build() { + if [[ $(compare_versions "$DETECTED_XROS_SDK_VERSION" "1.0") -le 0 ]]; then + export XROS_MIN_VERSION=$DETECTED_XROS_SDK_VERSION + else + export XROS_MIN_VERSION=1.0 + fi +} + +enable_lts_build() { + export FFMPEG_KIT_LTS_BUILD="1" + + if [[ $(compare_versions "$DETECTED_XROS_SDK_VERSION" "1.0") -le 0 ]]; then + export XROS_MIN_VERSION=$DETECTED_XROS_SDK_VERSION + else + export XROS_MIN_VERSION=1.0 + fi +} + +get_common_includes() { + echo "-I${SDK_PATH}/usr/include" +} + +get_common_cflags() { + if [[ -n ${FFMPEG_KIT_LTS_BUILD} ]]; then + local LTS_BUILD_FLAG="-DFFMPEG_KIT_LTS " + fi + + local BUILD_DATE="-DFFMPEG_KIT_BUILD_DATE=$(date +%Y%m%d 2>>"${BASEDIR}"/build.log)" + if [ -z $NO_BITCODE ]; then + local BITCODE_FLAGS="-fembed-bitcode" + fi + + case ${ARCH} in + arm64) + echo "-fstrict-aliasing ${BITCODE_FLAGS} -DXROS ${LTS_BUILD_FLAG}${BUILD_DATE} -isysroot ${SDK_PATH}" + ;; + x86-64 | arm64-simulator) + echo "-fstrict-aliasing -DXROS ${LTS_BUILD_FLAG}${BUILD_DATE} -isysroot ${SDK_PATH}" + ;; + esac +} + +get_arch_specific_cflags() { + case ${ARCH} in + arm64) + echo "-arch arm64 -target $(get_target) -march=armv8-a+crc+crypto -mcpu=generic -DFFMPEG_KIT_ARM64" + ;; + arm64-simulator) + echo "-arch arm64 -target $(get_target) -march=armv8-a+crc+crypto -mcpu=generic -DFFMPEG_KIT_ARM64_SIMULATOR" + ;; + x86-64) + echo "-arch x86_64 -target $(get_target) -march=x86-64 -msse4.2 -mpopcnt -m64 -DFFMPEG_KIT_X86_64" + ;; + esac +} + +get_size_optimization_cflags() { + + local ARCH_OPTIMIZATION="" + case ${ARCH} in + arm64) + case $1 in + x264 | x265) + ARCH_OPTIMIZATION="-Oz -Wno-ignored-optimization-argument" + ;; + ffmpeg | ffmpeg-kit) + ARCH_OPTIMIZATION="-Oz -Wno-ignored-optimization-argument" + ;; + *) + ARCH_OPTIMIZATION="-Oz -Wno-ignored-optimization-argument" + ;; + esac + ;; + x86-64 | arm64-simulator) + case $1 in + x264 | ffmpeg) + ARCH_OPTIMIZATION="-O2 -Wno-ignored-optimization-argument" + ;; + x265) + ARCH_OPTIMIZATION="-O2 -Wno-ignored-optimization-argument" + ;; + *) + ARCH_OPTIMIZATION="-O2 -Wno-ignored-optimization-argument" + ;; + esac + ;; + esac + + echo "${ARCH_OPTIMIZATION}" +} + +get_size_optimization_asm_cflags() { + + local ARCH_OPTIMIZATION="" + case $1 in + jpeg | ffmpeg) + case ${ARCH} in + arm64) + ARCH_OPTIMIZATION="-Oz" + ;; + x86-64 | arm64-simulator) + ARCH_OPTIMIZATION="-O2" + ;; + esac + ;; + *) + ARCH_OPTIMIZATION=$(get_size_optimization_cflags "$1") + ;; + esac + + echo "${ARCH_OPTIMIZATION}" +} + +get_app_specific_cflags() { + + local APP_FLAGS="" + case $1 in + fontconfig) + case ${ARCH} in + arm64) + APP_FLAGS="-std=c99 -Wno-unused-function -D__IPHONE_OS_MIN_REQUIRED -D__IPHONE_VERSION_MIN_REQUIRED=30000" + ;; + *) + APP_FLAGS="-std=c99 -Wno-unused-function" + ;; + esac + ;; + ffmpeg) + APP_FLAGS="-Wno-unused-function -Wno-deprecated-declarations" + ;; + gnutls) + APP_FLAGS="-std=c99 -Wno-unused-function -D_GL_USE_STDLIB_ALLOC=1" + ;; + jpeg) + APP_FLAGS="-Wno-nullability-completeness" + ;; + kvazaar) + APP_FLAGS="-std=gnu99 -Wno-unused-function" + ;; + leptonica) + APP_FLAGS="-std=c99 -Wno-unused-function -DOS_IOS" + ;; + libwebp | xvidcore) + APP_FLAGS="-fno-common -DPIC" + ;; + ffmpeg-kit) + APP_FLAGS="-std=c99 -Wno-unused-function -Wall -Wno-deprecated-declarations -Wno-pointer-sign -Wno-switch -Wno-unused-result -Wno-unused-variable -DPIC -fobjc-arc" + ;; + sdl) + APP_FLAGS="-DPIC -Wno-unused-function -D__XROS__" + ;; + shine) + APP_FLAGS="-Wno-unused-function" + ;; + soxr | snappy) + APP_FLAGS="-std=gnu99 -Wno-unused-function -DPIC" + ;; + openh264 | x265) + APP_FLAGS="-Wno-unused-function" + ;; + *) + APP_FLAGS="-std=c99 -Wno-unused-function" + ;; + esac + + echo "${APP_FLAGS}" +} + +get_cflags() { + local ARCH_FLAGS=$(get_arch_specific_cflags) + local APP_FLAGS=$(get_app_specific_cflags "$1") + local COMMON_FLAGS=$(get_common_cflags) + if [[ -z ${FFMPEG_KIT_DEBUG} ]]; then + local OPTIMIZATION_FLAGS=$(get_size_optimization_cflags "$1") + else + local OPTIMIZATION_FLAGS="${FFMPEG_KIT_DEBUG}" + fi + local MIN_VERSION_FLAGS=$(get_min_version_cflags "$1") + local COMMON_INCLUDES=$(get_common_includes) + + echo "${ARCH_FLAGS} ${APP_FLAGS} ${COMMON_FLAGS} ${OPTIMIZATION_FLAGS} ${MIN_VERSION_FLAGS} ${COMMON_INCLUDES}" +} + +get_asmflags() { + local ARCH_FLAGS=$(get_arch_specific_cflags) + local APP_FLAGS=$(get_app_specific_cflags "$1") + local COMMON_FLAGS=$(get_common_cflags) + if [[ -z ${FFMPEG_KIT_DEBUG} ]]; then + local OPTIMIZATION_FLAGS=$(get_size_optimization_asm_cflags "$1") + else + local OPTIMIZATION_FLAGS="${FFMPEG_KIT_DEBUG}" + fi + local MIN_VERSION_FLAGS=$(get_min_version_cflags "$1") + local COMMON_INCLUDES=$(get_common_includes) + + echo "${ARCH_FLAGS} ${APP_FLAGS} ${COMMON_FLAGS} ${OPTIMIZATION_FLAGS} ${MIN_VERSION_FLAGS} ${COMMON_INCLUDES}" +} + +get_cxxflags() { + local COMMON_CFLAGS="$(get_common_cflags "$1") $(get_common_includes "$1") $(get_arch_specific_cflags) $(get_min_version_cflags "$1")" + if [[ -z ${FFMPEG_KIT_DEBUG} ]]; then + local OPTIMIZATION_FLAGS="-Oz" + else + local OPTIMIZATION_FLAGS="${FFMPEG_KIT_DEBUG}" + fi + + local BITCODE_FLAGS="" + case ${ARCH} in + arm64) + if [ -z $NO_BITCODE ]; then + local BITCODE_FLAGS="-fembed-bitcode" + fi + ;; + esac + + case $1 in + x265) + echo "-std=c++11 -fno-exceptions ${BITCODE_FLAGS} ${COMMON_CFLAGS}" + ;; + gnutls) + echo "-std=c++11 -fno-rtti ${BITCODE_FLAGS} ${COMMON_CFLAGS} ${OPTIMIZATION_FLAGS}" + ;; + libaom) + echo "-std=c++11 -fno-exceptions ${BITCODE_FLAGS} ${COMMON_CFLAGS} ${OPTIMIZATION_FLAGS}" + ;; + libilbc) + echo "-std=c++14 -fno-exceptions ${BITCODE_FLAGS} ${COMMON_CFLAGS} ${OPTIMIZATION_FLAGS}" + ;; + libwebp | xvidcore) + echo "-std=c++11 -fno-exceptions -fno-rtti ${BITCODE_FLAGS} -fno-common -DPIC ${COMMON_CFLAGS} ${OPTIMIZATION_FLAGS}" + ;; + opencore-amr) + echo "-fno-rtti ${BITCODE_FLAGS} ${COMMON_CFLAGS} ${OPTIMIZATION_FLAGS}" + ;; + rubberband) + echo "-fno-rtti ${BITCODE_FLAGS} ${COMMON_CFLAGS} ${OPTIMIZATION_FLAGS}" + ;; + srt | tesseract | zimg) + echo "-std=c++11 ${BITCODE_FLAGS} ${COMMON_CFLAGS} ${OPTIMIZATION_FLAGS}" + ;; + *) + echo "-std=c++11 -fno-exceptions -fno-rtti ${BITCODE_FLAGS} ${COMMON_CFLAGS} ${OPTIMIZATION_FLAGS}" + ;; + esac +} + +get_common_linked_libraries() { + echo "-L${SDK_PATH}/usr/lib -lc++" +} + +get_common_ldflags() { + echo "-isysroot ${SDK_PATH} $(get_min_version_cflags)" +} + +get_size_optimization_ldflags() { + case ${ARCH} in + arm64) + case $1 in + ffmpeg | ffmpeg-kit) + echo "-Oz -dead_strip" + ;; + *) + echo "-Oz -dead_strip" + ;; + esac + ;; + *) + case $1 in + ffmpeg) + echo "-O2" + ;; + *) + echo "-O2" + ;; + esac + ;; + esac +} + +get_arch_specific_ldflags() { + if [ -z $NO_BITCODE ]; then + local BITCODE_FLAGS="-fembed-bitcode" + fi + + case ${ARCH} in + arm64) + echo "-arch arm64 -march=armv8-a+crc+crypto ${BITCODE_FLAGS}" + ;; + arm64-simulator) + echo "-arch arm64 -march=armv8-a+crc+crypto" + ;; + x86-64) + echo "-arch x86_64 -march=x86-64" + ;; + esac +} + +get_ldflags() { + local ARCH_FLAGS=$(get_arch_specific_ldflags) + local LINKED_LIBRARIES=$(get_common_linked_libraries) + if [[ -z ${FFMPEG_KIT_DEBUG} ]]; then + local OPTIMIZATION_FLAGS="$(get_size_optimization_ldflags "$1")" + else + local OPTIMIZATION_FLAGS="${FFMPEG_KIT_DEBUG}" + fi + local COMMON_FLAGS=$(get_common_ldflags) + if [ -z $NO_BITCODE ]; then + local BITCODE_FLAGS="-fembed-bitcode -Wc,-fembed-bitcode" + fi + + case $1 in + ffmpeg-kit) + case ${ARCH} in + arm64) + echo "${ARCH_FLAGS} ${LINKED_LIBRARIES} ${COMMON_FLAGS} ${BITCODE_FLAGS} ${OPTIMIZATION_FLAGS}" + ;; + *) + echo "${ARCH_FLAGS} ${LINKED_LIBRARIES} ${COMMON_FLAGS} ${OPTIMIZATION_FLAGS}" + ;; + esac + ;; + *) + # NOTE THAT ffmpeg ALSO NEEDS BITCODE, IT IS ENABLED IN ffmpeg.sh + echo "${ARCH_FLAGS} ${LINKED_LIBRARIES} ${COMMON_FLAGS} ${OPTIMIZATION_FLAGS}" + ;; + esac +} + +set_toolchain_paths() { + if [ ! -f "${FFMPEG_KIT_TMPDIR}/gas-preprocessor.pl" ]; then + DOWNLOAD_RESULT=$(download "https://github.com/arthenica/gas-preprocessor/raw/v20210917/gas-preprocessor.pl" "gas-preprocessor.pl" "exit") + if [[ ${DOWNLOAD_RESULT} -ne 0 ]]; then + exit 1 + fi + (chmod +x "${FFMPEG_KIT_TMPDIR}"/gas-preprocessor.pl 1>>"${BASEDIR}"/build.log 2>&1) || return 1 + + # patch gas-preprocessor.pl against the following warning + # Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.32), passed through in regex; marked by <-- HERE in m/(?:ld|st)\d\s+({ <-- HERE \s*v(\d+)\.(\d[bhsdBHSD])\s*-\s*v(\d+)\.(\d[bhsdBHSD])\s*})/ at /Users/taner/Projects/ffmpeg-kit/.tmp/gas-preprocessor.pl line 1065. + sed -i .tmp "s/s\+({/s\+(\\\\{/g;s/s\*})/s\*\\\\})/g" "${FFMPEG_KIT_TMPDIR}"/gas-preprocessor.pl + fi + + LOCAL_GAS_PREPROCESSOR="${FFMPEG_KIT_TMPDIR}/gas-preprocessor.pl" + if [ "$1" == "x264" ]; then + LOCAL_GAS_PREPROCESSOR="${BASEDIR}/src/x264/tools/gas-preprocessor.pl" + fi + + HOST=$(get_host) + + export AR="$(xcrun --sdk "$(get_sdk_name)" -f ar 2>>"${BASEDIR}"/build.log)" + export CC="clang" + export OBJC="$(xcrun --sdk "$(get_sdk_name)" -f clang 2>>"${BASEDIR}"/build.log)" + export CXX="clang++" + + LOCAL_ASMFLAGS="$(get_asmflags "$1")" + case ${ARCH} in + arm64*) + if [ "$1" == "x265" ] || [ "$1" == "libilbc" ]; then + export AS="${LOCAL_GAS_PREPROCESSOR}" + export AS_ARGUMENTS="-arch aarch64" + export ASM_FLAGS="${LOCAL_ASMFLAGS}" + else + export AS="${LOCAL_GAS_PREPROCESSOR} -arch aarch64 -- ${CC} ${LOCAL_ASMFLAGS}" + fi + ;; + *) + export AS="${CC} ${LOCAL_ASMFLAGS}" + ;; + esac + + export LD="$(xcrun --sdk "$(get_sdk_name)" -f ld 2>>"${BASEDIR}"/build.log)" + export RANLIB="$(xcrun --sdk "$(get_sdk_name)" -f ranlib 2>>"${BASEDIR}"/build.log)" + export STRIP="$(xcrun --sdk "$(get_sdk_name)" -f strip 2>>"${BASEDIR}"/build.log)" + export NM="$(xcrun --sdk "$(get_sdk_name)" -f nm 2>>"${BASEDIR}"/build.log)" + + export INSTALL_PKG_CONFIG_DIR="${BASEDIR}/prebuilt/$(get_build_directory)/pkgconfig" + export ZLIB_PACKAGE_CONFIG_PATH="${INSTALL_PKG_CONFIG_DIR}/zlib.pc" + export BZIP2_PACKAGE_CONFIG_PATH="${INSTALL_PKG_CONFIG_DIR}/bzip2.pc" + export LIB_ICONV_PACKAGE_CONFIG_PATH="${INSTALL_PKG_CONFIG_DIR}/libiconv.pc" + export LIB_UUID_PACKAGE_CONFIG_PATH="${INSTALL_PKG_CONFIG_DIR}/uuid.pc" + + if [ ! -d "${INSTALL_PKG_CONFIG_DIR}" ]; then + mkdir -p "${INSTALL_PKG_CONFIG_DIR}" + fi + + if [ ! -f "${ZLIB_PACKAGE_CONFIG_PATH}" ]; then + create_zlib_system_package_config + fi + + if [ ! -f "${LIB_ICONV_PACKAGE_CONFIG_PATH}" ]; then + create_libiconv_system_package_config + fi + + if [ ! -f "${BZIP2_PACKAGE_CONFIG_PATH}" ]; then + create_bzip2_system_package_config + fi + + if [ ! -f "${LIB_UUID_PACKAGE_CONFIG_PATH}" ]; then + create_libuuid_system_package_config + fi +} + +initialize_prebuilt_xros_folders() { + if [[ -n ${FFMPEG_KIT_XCF_BUILD} ]]; then + + echo -e "DEBUG: Initializing universal directories and frameworks for xcf builds\n" 1>>"${BASEDIR}"/build.log 2>&1 + + if [[ $(is_apple_architecture_variant_supported "${ARCH_VAR_APPLEXROS}") -eq 1 ]]; then + initialize_folder "${BASEDIR}/.tmp/$(get_universal_library_directory "${ARCH_VAR_APPLEXROS}")" + initialize_folder "${BASEDIR}/prebuilt/$(get_framework_directory "${ARCH_VAR_APPLEXROS}")" + fi + if [[ $(is_apple_architecture_variant_supported "${ARCH_VAR_XRSIMULATOR}") -eq 1 ]]; then + initialize_folder "${BASEDIR}/.tmp/$(get_universal_library_directory "${ARCH_VAR_XRSIMULATOR}")" + initialize_folder "${BASEDIR}/prebuilt/$(get_framework_directory "${ARCH_VAR_XRSIMULATOR}")" + fi + + echo -e "DEBUG: Initializing xcframework directory at ${BASEDIR}/prebuilt/$(get_xcframework_directory)\n" 1>>"${BASEDIR}"/build.log 2>&1 + + # XCF BUILDS GENERATE XCFFRAMEWORKS + initialize_folder "${BASEDIR}/prebuilt/$(get_xcframework_directory)" + else + + echo -e "DEBUG: Initializing default universal directory at ${BASEDIR}/.tmp/$(get_universal_library_directory "${ARCH_VAR_XROS}")\n" 1>>"${BASEDIR}"/build.log 2>&1 + + # DEFAULT BUILDS GENERATE UNIVERSAL LIBRARIES AND FRAMEWORKS + initialize_folder "${BASEDIR}/.tmp/$(get_universal_library_directory "${ARCH_VAR_XROS}")" + + echo -e "DEBUG: Initializing framework directory at ${BASEDIR}/prebuilt/$(get_framework_directory "${ARCH_VAR_XROS}")\n" 1>>"${BASEDIR}"/build.log 2>&1 + + initialize_folder "${BASEDIR}/prebuilt/$(get_framework_directory "${ARCH_VAR_XROS}")" + fi +} + +# +# DEPENDS TARGET_ARCH_LIST VARIABLE +# +create_universal_libraries_for_xros_default_frameworks() { + local ROOT_UNIVERSAL_DIRECTORY_PATH="${BASEDIR}/.tmp/$(get_universal_library_directory "${ARCH_VAR_XROS}")" + + echo -e "INFO: Building universal libraries in ${ROOT_UNIVERSAL_DIRECTORY_PATH} for default frameworks using ${TARGET_ARCH_LIST[@]}\n" 1>>"${BASEDIR}"/build.log 2>&1 + + create_ffmpeg_universal_library "${ARCH_VAR_XROS}" + + create_ffmpeg_kit_universal_library "${ARCH_VAR_XROS}" + + echo -e "INFO: Universal libraries for default frameworks built successfully\n" 1>>"${BASEDIR}"/build.log 2>&1 +} + +create_xros_default_frameworks() { + echo -e "INFO: Building default frameworks\n" 1>>"${BASEDIR}"/build.log 2>&1 + + create_ffmpeg_framework "${ARCH_VAR_XROS}" + + create_ffmpeg_kit_framework "${ARCH_VAR_XROS}" + + echo -e "INFO: Default frameworks built successfully\n" 1>>"${BASEDIR}"/build.log 2>&1 +} + +create_universal_libraries_for_xros_xcframeworks() { + echo -e "INFO: Building universal libraries for xcframeworks using ${TARGET_ARCH_LIST[@]}\n" 1>>"${BASEDIR}"/build.log 2>&1 + + create_ffmpeg_universal_library "${ARCH_VAR_APPLEXROS}" + create_ffmpeg_universal_library "${ARCH_VAR_XRSIMULATOR}" + + create_ffmpeg_kit_universal_library "${ARCH_VAR_APPLEXROS}" + create_ffmpeg_kit_universal_library "${ARCH_VAR_XRSIMULATOR}" + + echo -e "INFO: Universal libraries for xcframeworks built successfully\n" 1>>"${BASEDIR}"/build.log 2>&1 +} + +create_frameworks_for_xros_xcframeworks() { + echo -e "INFO: Building frameworks for xcframeworks\n" 1>>"${BASEDIR}"/build.log 2>&1 + + create_ffmpeg_framework "${ARCH_VAR_APPLEXROS}" + create_ffmpeg_framework "${ARCH_VAR_XRSIMULATOR}" + + create_ffmpeg_kit_framework "${ARCH_VAR_APPLEXROS}" + create_ffmpeg_kit_framework "${ARCH_VAR_XRSIMULATOR}" + + echo -e "INFO: Frameworks for xcframeworks built successfully\n" 1>>"${BASEDIR}"/build.log 2>&1 +} + +create_xros_xcframeworks() { + export ARCHITECTURE_VARIANT_ARRAY=("${ARCH_VAR_APPLEXROS}" "${ARCH_VAR_XRSIMULATOR}") + echo -e "INFO: Building xcframeworks\n" 1>>"${BASEDIR}"/build.log 2>&1 + + create_ffmpeg_xcframework + + create_ffmpeg_kit_xcframework + + echo -e "INFO: xcframeworks built successfully\n" 1>>"${BASEDIR}"/build.log 2>&1 +} diff --git a/scripts/function.sh b/scripts/function.sh index 06e3565..6ec2a13 100755 --- a/scripts/function.sh +++ b/scripts/function.sh @@ -421,7 +421,7 @@ is_arch_supported_on_platform() { # IOS OR TVOS $ARCH_ARM64_SIMULATOR) - if [[ ${FFMPEG_KIT_BUILD_TYPE} == "ios" ]] || [[ ${FFMPEG_KIT_BUILD_TYPE} == "tvos" ]]; then + if [[ ${FFMPEG_KIT_BUILD_TYPE} == "ios" ]] || [[ ${FFMPEG_KIT_BUILD_TYPE} == "tvos" ]] || [[ ${FFMPEG_KIT_BUILD_TYPE} == "xros" ]]; then echo 1 else echo 0 @@ -430,7 +430,7 @@ is_arch_supported_on_platform() { # IOS, MACOS OR TVOS $ARCH_ARM64) - if [[ ${FFMPEG_KIT_BUILD_TYPE} == "ios" ]] || [[ ${FFMPEG_KIT_BUILD_TYPE} == "macos" ]] || [[ ${FFMPEG_KIT_BUILD_TYPE} == "tvos" ]]; then + if [[ ${FFMPEG_KIT_BUILD_TYPE} == "ios" ]] || [[ ${FFMPEG_KIT_BUILD_TYPE} == "macos" ]] || [[ ${FFMPEG_KIT_BUILD_TYPE} == "tvos" ]] || [[ ${FFMPEG_KIT_BUILD_TYPE} == "xros" ]]; then echo 1 else echo 0 @@ -1828,6 +1828,9 @@ get_apple_cmake_system_name() { macos) echo "Darwin" ;; + xros) + echo "visionOS" + ;; tvos) echo "tvOS" ;; diff --git a/scripts/main-xros.sh b/scripts/main-xros.sh new file mode 100755 index 0000000..be870e9 --- /dev/null +++ b/scripts/main-xros.sh @@ -0,0 +1,246 @@ +#!/bin/bash + +if [[ -z ${ARCH} ]]; then + echo -e "\n(*) ARCH not defined\n" + exit 1 +fi + +if [[ -z ${XROS_MIN_VERSION} ]]; then + echo -e "\n(*) XROS_MIN_VERSION not defined\n" + exit 1 +fi + +if [[ -z ${BASEDIR} ]]; then + echo -e "\n(*) BASEDIR not defined\n" + exit 1 +fi + +if [[ -z ${SDK_PATH} ]]; then + echo -e "\n(*) SDK_PATH not defined\n" + exit 1 +fi + +echo -e "\nBuilding ${ARCH} platform targeting visionOS SDK ${XROS_MIN_VERSION}\n" +echo -e "\nINFO: Starting new build for ${ARCH} targeting visionOS SDK ${XROS_MIN_VERSION} at $(date)\n" 1>>"${BASEDIR}"/build.log 2>&1 + +# SET BASE INSTALLATION DIRECTORY FOR THIS ARCHITECTURE +export LIB_INSTALL_BASE="${BASEDIR}/prebuilt/$(get_build_directory)" + +# CREATE PACKAGE CONFIG DIRECTORY FOR THIS ARCHITECTURE +PKG_CONFIG_DIRECTORY="${LIB_INSTALL_BASE}/pkgconfig" +if [ ! -d "${PKG_CONFIG_DIRECTORY}" ]; then + mkdir -p "${PKG_CONFIG_DIRECTORY}" || return 1 +fi + +# FILTER WHICH EXTERNAL LIBRARIES WILL BE BUILT +# NOTE THAT BUILT-IN LIBRARIES ARE FORWARDED TO FFMPEG SCRIPT WITHOUT ANY PROCESSING +enabled_library_list=() +for library in {1..50}; do + if [[ ${!library} -eq 1 ]]; then + ENABLED_LIBRARY=$(get_library_name $((library - 1))) + enabled_library_list+=(${ENABLED_LIBRARY}) + + echo -e "INFO: Enabled library ${ENABLED_LIBRARY} will be built\n" 1>>"${BASEDIR}"/build.log 2>&1 + fi +done + +# BUILD ENABLED LIBRARIES AND THEIR DEPENDENCIES +let completed=0 +while [ ${#enabled_library_list[@]} -gt $completed ]; do + for library in "${enabled_library_list[@]}"; do + let run=0 + case $library in + fontconfig) + if [[ $OK_expat -eq 1 ]] && [[ $OK_freetype -eq 1 ]]; then + run=1 + fi + ;; + freetype) + if [[ $OK_libpng -eq 1 ]]; then + run=1 + fi + ;; + gnutls) + if [[ $OK_nettle -eq 1 ]] && [[ $OK_gmp -eq 1 ]]; then + run=1 + fi + ;; + harfbuzz) + if [[ $OK_fontconfig -eq 1 ]] && [[ $OK_freetype -eq 1 ]]; then + run=1 + fi + ;; + leptonica) + if [[ $OK_giflib -eq 1 ]] && [[ $OK_jpeg -eq 1 ]] && [[ $OK_libpng -eq 1 ]] && [[ $OK_tiff -eq 1 ]] && [[ $OK_libwebp -eq 1 ]]; then + run=1 + fi + ;; + libass) + if [[ $OK_expat -eq 1 ]] && [[ $OK_freetype -eq 1 ]] && [[ $OK_fribidi -eq 1 ]] && [[ $OK_fontconfig -eq 1 ]] && [[ $OK_libpng -eq 1 ]] && [[ $OK_harfbuzz -eq 1 ]]; then + run=1 + fi + ;; + libtheora) + if [[ $OK_libvorbis -eq 1 ]] && [[ $OK_libogg -eq 1 ]]; then + run=1 + fi + ;; + libvorbis) + if [[ $OK_libogg -eq 1 ]]; then + run=1 + fi + ;; + libwebp) + if [[ $OK_giflib -eq 1 ]] && [[ $OK_jpeg -eq 1 ]] && [[ $OK_libpng -eq 1 ]] && [[ $OK_tiff -eq 1 ]]; then + run=1 + fi + ;; + nettle) + if [[ $OK_gmp -eq 1 ]]; then + run=1 + fi + ;; + rubberband) + if [[ $OK_libsndfile -eq 1 ]] && [[ $OK_libsamplerate -eq 1 ]]; then + run=1 + fi + ;; + srt) + if [[ $OK_openssl -eq 1 ]]; then + run=1 + fi + ;; + tesseract) + if [[ $OK_leptonica -eq 1 ]]; then + run=1 + fi + ;; + tiff) + if [[ $OK_jpeg -eq 1 ]]; then + run=1 + fi + ;; + twolame) + if [[ $OK_libsndfile -eq 1 ]]; then + run=1 + fi + ;; + *) + run=1 + ;; + esac + + BUILD_COMPLETED_FLAG=$(echo "OK_${library}" | sed "s/\-/\_/g") + REBUILD_FLAG=$(echo "REBUILD_${library}" | sed "s/\-/\_/g") + DEPENDENCY_REBUILT_FLAG=$(echo "DEPENDENCY_REBUILT_${library}" | sed "s/\-/\_/g") + + if [[ $run -eq 1 ]] && [[ "${!BUILD_COMPLETED_FLAG}" != "1" ]]; then + LIBRARY_IS_INSTALLED=$(library_is_installed "${LIB_INSTALL_BASE}" "${library}") + + echo -e "INFO: Flags detected for ${library}: already installed=${LIBRARY_IS_INSTALLED}, rebuild requested by user=${!REBUILD_FLAG}, will be rebuilt due to dependency update=${!DEPENDENCY_REBUILT_FLAG}\n" 1>>"${BASEDIR}"/build.log 2>&1 + + # CHECK IF BUILD IS NECESSARY OR NOT + if [[ ${LIBRARY_IS_INSTALLED} -ne 1 ]] || [[ ${!REBUILD_FLAG} -eq 1 ]] || [[ ${!DEPENDENCY_REBUILT_FLAG} -eq 1 ]]; then + echo -n "${library}: " + + "${BASEDIR}"/scripts/run-apple.sh "${library}" 1>>"${BASEDIR}"/build.log 2>&1 + + RC=$? + + # SET SOME FLAGS AFTER THE BUILD + if [ $RC -eq 0 ]; then + ((completed += 1)) + declare "$BUILD_COMPLETED_FLAG=1" + check_if_dependency_rebuilt "${library}" + echo "ok" + elif [ $RC -eq 200 ]; then + echo -e "not supported\n\nSee build.log for details\n" + exit 1 + else + echo -e "failed\n\nSee build.log for details\n" + exit 1 + fi + else + ((completed += 1)) + declare "$BUILD_COMPLETED_FLAG=1" + echo "${library}: already built" + fi + else + echo -e "INFO: Skipping $library, dependencies built=$run, already built=${!BUILD_COMPLETED_FLAG}\n" 1>>"${BASEDIR}"/build.log 2>&1 + fi + done +done + +# BUILD CUSTOM LIBRARIES +for custom_library_index in "${CUSTOM_LIBRARIES[@]}"; do + library_name="CUSTOM_LIBRARY_${custom_library_index}_NAME" + + echo -e "\nDEBUG: Custom library ${!library_name} will be built\n" 1>>"${BASEDIR}"/build.log 2>&1 + + # DEFINE SOME FLAGS TO REBUILD OPTIONS + REBUILD_FLAG=$(echo "REBUILD_${!library_name}" | sed "s/\-/\_/g") + LIBRARY_IS_INSTALLED=$(library_is_installed "${LIB_INSTALL_BASE}" "${!library_name}") + + echo -e "INFO: Flags detected for custom library ${!library_name}: already installed=${LIBRARY_IS_INSTALLED}, rebuild requested by user=${!REBUILD_FLAG}\n" 1>>"${BASEDIR}"/build.log 2>&1 + + if [[ ${LIBRARY_IS_INSTALLED} -ne 1 ]] || [[ ${!REBUILD_FLAG} -eq 1 ]]; then + + echo -n "${!library_name}: " + + "${BASEDIR}"/scripts/run-apple.sh "${!library_name}" 1>>"${BASEDIR}"/build.log 2>&1 + + RC=$? + + # SET SOME FLAGS AFTER THE BUILD + if [ $RC -eq 0 ]; then + echo "ok" + elif [ $RC -eq 200 ]; then + echo -e "not supported\n\nSee build.log for details\n" + exit 1 + else + echo -e "failed\n\nSee build.log for details\n" + exit 1 + fi + else + echo "${!library_name}: already built" + fi +done + +# SKIP TO SPEED UP THE BUILD +if [[ ${SKIP_ffmpeg} -ne 1 ]]; then + + # PREPARE PATHS & DEFINE ${INSTALL_PKG_CONFIG_DIR} + LIB_NAME="ffmpeg" + set_toolchain_paths "${LIB_NAME}" + + # SET BUILD FLAGS + HOST=$(get_host) + export CFLAGS=$(get_cflags "${LIB_NAME}") + export CXXFLAGS=$(get_cxxflags "${LIB_NAME}") + export LDFLAGS=$(get_ldflags "${LIB_NAME}") + export PKG_CONFIG_LIBDIR="${INSTALL_PKG_CONFIG_DIR}" + + cd "${BASEDIR}"/src/"${LIB_NAME}" 1>>"${BASEDIR}"/build.log 2>&1 || return 1 + + LIB_INSTALL_PREFIX="${LIB_INSTALL_BASE}/${LIB_NAME}" + + # BUILD FFMPEG + source "${BASEDIR}"/scripts/apple/ffmpeg.sh + + if [[ $? -ne 0 ]]; then + exit 1 + fi +else + echo -e "\nffmpeg: skipped" +fi + +# SKIP TO SPEED UP THE BUILD +if [[ ${SKIP_ffmpeg_kit} -ne 1 ]]; then + + # BUILD FFMPEG + . "${BASEDIR}"/scripts/apple/ffmpeg-kit.sh "$@" || return 1 +else + echo -e "\nffmpeg-kit: skipped" +fi + +echo -e "\nINFO: Completed build for ${ARCH} at $(date)\n" 1>>"${BASEDIR}"/build.log 2>&1 diff --git a/scripts/variable.sh b/scripts/variable.sh index be8c081..c671eaf 100755 --- a/scripts/variable.sh +++ b/scripts/variable.sh @@ -7,7 +7,7 @@ export FFMPEG_KIT_TMPDIR="${BASEDIR}/.tmp" ENABLED_ARCHITECTURES=(0 0 0 0 0 0 0 0 0 0 0 0 0) # ARRAY OF ENABLED ARCHITECTURE VARIANTS -ENABLED_ARCHITECTURE_VARIANTS=(0 0 0 0 0 0 0 0) +ENABLED_ARCHITECTURE_VARIANTS=(0 0 0 0 0 0 0 0 0 0) # ARRAY OF ENABLED LIBRARIES ENABLED_LIBRARIES=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) @@ -30,14 +30,14 @@ ARCH_ARM_V7A_NEON=1 # android ARCH_ARMV7=2 # ios ARCH_ARMV7S=3 # ios ARCH_ARM64_V8A=4 # android -ARCH_ARM64=5 # ios, tvos, macos +ARCH_ARM64=5 # ios, tvos, macos, xros ARCH_ARM64E=6 # ios ARCH_I386=7 # ios ARCH_X86=8 # android ARCH_X86_64=9 # android, ios, linux, macos, tvos ARCH_X86_64_MAC_CATALYST=10 # ios ARCH_ARM64_MAC_CATALYST=11 # ios -ARCH_ARM64_SIMULATOR=12 # ios +ARCH_ARM64_SIMULATOR=12 # ios, xros # ARCH VARIANT INDEXES ARCH_VAR_IOS=1 # ios @@ -48,6 +48,8 @@ ARCH_VAR_TVOS=5 # tvos ARCH_VAR_APPLETVOS=6 # tvos ARCH_VAR_APPLETVSIMULATOR=7 # tvos ARCH_VAR_MACOS=8 # macos +ARCH_VAR_XROS=9 # xros +ARCH_VAR_XRSIMULATOR=10 # xros # LIBRARY INDEXES LIBRARY_FONTCONFIG=0 diff --git a/xros.sh b/xros.sh new file mode 100755 index 0000000..ed94733 --- /dev/null +++ b/xros.sh @@ -0,0 +1,285 @@ +#!/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="xros" +source "${BASEDIR}"/scripts/variable.sh +source "${BASEDIR}"/scripts/function-${FFMPEG_KIT_BUILD_TYPE}.sh +disabled_libraries=() + +# SET DEFAULTS SETTINGS +enable_default_xros_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 XROS SDK VERSION +export DETECTED_XROS_SDK_VERSION="$(xcrun --sdk xros --show-sdk-version 2>>${BASEDIR}/build.log)" +echo -e "\nINFO: Using SDK ${DETECTED_XROS_SDK_VERSION} by Xcode provided at $(xcode-select -p)\n" 1>>"${BASEDIR}"/build.log 2>&1 +echo -e "\nINFO: 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 XROS_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_xros_architecture_not_supported_on_detected_sdk_version "${ARCH_ARM64_SIMULATOR}" + +# CHECK SOME RULES FOR .framework BUNDLES + +# 1. 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 tvOS\n" +echo -e -n "INFO: Building ffmpeg-kit ${BUILD_VERSION} ${BUILD_TYPE_ID}for tvOS: " 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-xros.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_xros_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_xros_xcframeworks + + create_frameworks_for_xros_xcframeworks + + create_xros_xcframeworks + else + echo -e -n "\nCreating frameworks under prebuilt: " + + create_universal_libraries_for_xros_default_frameworks + + create_xros_default_frameworks + fi + + echo -e "ok\n" + fi +else + echo -e "INFO: Skipped creating tvOS frameworks.\n" 1>>"${BASEDIR}"/build.log 2>&1 +fi