2020-08-05 03:26:42 +03:00
#!/bin/bash
2020-08-05 03:53:02 +03:00
# CHECK IF XCODE IS INSTALLED
if [ ! -x " $( command -v xcrun) " ] ; then
echo -e "\n(*) xcrun command not found. Please check your Xcode installation\n"
2020-08-05 03:26:42 +03:00
exit 1
fi
2021-01-09 18:24:56 +02:00
if [ ! -x " $( command -v xcodebuild) " ] ; then
echo -e "\n(*) xcodebuild command not found. Please check your Xcode installation\n"
exit 1
fi
2020-08-05 03:53:02 +03:00
# 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
# SET DEFAULTS SETTINGS
enable_default_ios_architectures
enable_main_build
2020-08-05 03:26:42 +03:00
# SELECT XCODE VERSION USED FOR BUILDING
2021-01-31 17:56:14 +02:00
XCODE_FOR_FFMPEG_KIT = $( ls ~/.xcode.for.ffmpeg.kit.sh 2>>" ${ BASEDIR } " /build.log)
2020-08-05 03:26:42 +03:00
if [ [ -f ${ XCODE_FOR_FFMPEG_KIT } ] ] ; then
source " ${ XCODE_FOR_FFMPEG_KIT } " 1>>" ${ BASEDIR } " /build.log 2>& 1
fi
2020-08-05 03:53:02 +03:00
# DETECT IOS SDK VERSION
2021-08-15 01:07:35 +03:00
DETECTED_IOS_SDK_VERSION = " $( xcrun --sdk iphoneos --show-sdk-version 2>>${ BASEDIR } /build.log) "
2021-01-31 17:56:14 +02:00
echo -e " \nINFO: Using SDK ${ DETECTED_IOS_SDK_VERSION } by Xcode provided at $( xcode-select -p) \n " 1>>" ${ BASEDIR } " /build.log 2>& 1
2020-08-05 03:53:02 +03:00
echo -e " INFO: Build options: $* \n " 1>>" ${ BASEDIR } " /build.log 2>& 1
2020-08-05 03:26:42 +03:00
2020-08-05 03:53:02 +03:00
# SET DEFAULT BUILD OPTIONS
2020-08-05 03:26:42 +03:00
GPL_ENABLED = "no"
DISPLAY_HELP = ""
BUILD_TYPE_ID = ""
BUILD_FULL = ""
FFMPEG_KIT_XCF_BUILD = ""
BUILD_FORCE = ""
2020-08-05 03:53:02 +03:00
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
# 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
2020-08-05 03:26:42 +03:00
2020-08-05 03:53:02 +03:00
# PROCESS BUILD OPTIONS
2020-08-05 03:26:42 +03:00
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 } "
; ;
2021-01-27 01:34:56 +02:00
--no-framework)
NO_FRAMEWORK = "1"
; ;
2020-08-05 03:26:42 +03:00
--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
; ;
2020-08-05 03:53:02 +03:00
-l | --lts) ; ;
2020-08-05 03:26:42 +03:00
-x | --xcframework)
FFMPEG_KIT_XCF_BUILD = "1"
; ;
-f | --force)
2020-08-05 03:53:02 +03:00
export BUILD_FORCE = "1"
2020-08-05 03:26:42 +03:00
; ;
--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 } "
; ;
2020-08-05 03:53:02 +03:00
--redownload-*)
2020-08-05 03:26:42 +03:00
DOWNLOAD_LIBRARY = $( echo $1 | sed -e 's/^--[A-Za-z]*-//g' )
redownload_library " ${ DOWNLOAD_LIBRARY } "
; ;
--full)
BUILD_FULL = "1"
; ;
--enable-gpl)
GPL_ENABLED = "yes"
; ;
--enable-*)
ENABLED_LIBRARY = $( echo $1 | sed -e 's/^--[A-Za-z]*-//g' )
enable_library " ${ ENABLED_LIBRARY } "
; ;
--disable-*)
DISABLED_ARCH = $( echo $1 | sed -e 's/^--[A-Za-z]*-//g' )
disable_arch " ${ DISABLED_ARCH } "
; ;
2021-10-09 17:14:44 +03:00
--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 }
; ;
2020-08-05 03:26:42 +03:00
*)
print_unknown_option " $1 "
; ;
esac
shift
done
2020-08-05 03:53:02 +03:00
# PROCESS FULL OPTION AS LAST OPTION
2020-08-05 03:26:42 +03:00
if [ [ -n ${ BUILD_FULL } ] ] ; then
2020-11-23 00:51:45 +02:00
for library in { 0..58} ; do
2020-08-05 03:26:42 +03:00
if [ ${ GPL_ENABLED } = = "yes" ] ; then
2020-11-23 00:51:45 +02:00
enable_library " $( get_library_name " $library " ) " 1
2020-08-05 03:26:42 +03:00
else
2020-11-23 00:51:45 +02:00
if [ [ $( is_gpl_licensed " $library " ) -eq 1 ] ] ; then
enable_library " $( get_library_name " $library " ) " 1
2020-08-05 03:26:42 +03:00
fi
fi
done
fi
2020-08-05 03:53:02 +03:00
# IF HELP DISPLAYED EXIT
if [ [ -n ${ DISPLAY_HELP } ] ] ; then
display_help
exit 0
2020-08-05 03:26:42 +03:00
fi
2020-08-05 03:53:02 +03:00
# DISABLE NOT SUPPORTED ARCHITECTURES
2020-11-23 00:51:45 +02:00
disable_ios_architecture_not_supported_on_detected_sdk_version " ${ ARCH_ARMV7 } " " ${ DETECTED_IOS_SDK_VERSION } "
disable_ios_architecture_not_supported_on_detected_sdk_version " ${ ARCH_ARMV7S } " " ${ DETECTED_IOS_SDK_VERSION } "
disable_ios_architecture_not_supported_on_detected_sdk_version " ${ ARCH_I386 } " " ${ DETECTED_IOS_SDK_VERSION } "
disable_ios_architecture_not_supported_on_detected_sdk_version " ${ ARCH_ARM64E } " " ${ DETECTED_IOS_SDK_VERSION } "
disable_ios_architecture_not_supported_on_detected_sdk_version " ${ ARCH_X86_64_MAC_CATALYST } " " ${ DETECTED_IOS_SDK_VERSION } "
disable_ios_architecture_not_supported_on_detected_sdk_version " ${ ARCH_ARM64_MAC_CATALYST } " " ${ DETECTED_IOS_SDK_VERSION } "
disable_ios_architecture_not_supported_on_detected_sdk_version " ${ ARCH_ARM64_SIMULATOR } " " ${ DETECTED_IOS_SDK_VERSION } "
2020-08-05 03:53:02 +03:00
2020-11-23 00:51:45 +02:00
# CHECK SOME RULES FOR .framework BUNDLES
# 1. DISABLE arm64-mac-catalyst WHEN arm64 IS ENABLED IN framework BUNDLES
if [ [ -z ${ FFMPEG_KIT_XCF_BUILD } ] ] && [ [ ${ ENABLED_ARCHITECTURES [ ${ ARCH_ARM64 } ] } -eq 1 ] ] && [ [ ${ ENABLED_ARCHITECTURES [ ${ ARCH_ARM64_MAC_CATALYST } ] } -eq 1 ] ] ; then
echo -e "INFO: Disabled arm64-mac-catalyst architecture which can not co-exist with arm64 in the same framework bundle.\n" 1>>" ${ BASEDIR } " /build.log 2>& 1
disable_arch "arm64-mac-catalyst"
2020-08-05 03:26:42 +03:00
fi
2020-11-23 00:51:45 +02:00
# 2. DISABLE arm64-simulator WHEN arm64 IS ENABLED IN framework BUNDLES
if [ [ -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 can not co-exist with arm64 in the same framework bundle.\n" 1>>" ${ BASEDIR } " /build.log 2>& 1
disable_arch "arm64-simulator"
fi
2021-03-02 01:04:41 +02:00
# 3. DISABLE arm64-simulator WHEN arm64-mac-catalyst IS ENABLED IN framework BUNDLES
if [ [ -z ${ FFMPEG_KIT_XCF_BUILD } ] ] && [ [ ${ ENABLED_ARCHITECTURES [ ${ ARCH_ARM64_MAC_CATALYST } ] } -eq 1 ] ] && [ [ ${ ENABLED_ARCHITECTURES [ ${ ARCH_ARM64_SIMULATOR } ] } -eq 1 ] ] ; then
echo -e "INFO: Disabled arm64-simulator architecture which can not co-exist with arm64-mac-catalyst in the same framework bundle.\n" 1>>" ${ BASEDIR } " /build.log 2>& 1
disable_arch "arm64-simulator"
fi
# 4. DISABLE x86-64-mac-catalyst WHEN x86-64 IS ENABLED IN framework BUNDLES
2020-11-23 00:51:45 +02:00
if [ [ -z ${ FFMPEG_KIT_XCF_BUILD } ] ] && [ [ ${ ENABLED_ARCHITECTURES [ ${ ARCH_X86_64 } ] } -eq 1 ] ] && [ [ ${ ENABLED_ARCHITECTURES [ ${ ARCH_X86_64_MAC_CATALYST } ] } -eq 1 ] ] ; then
echo -e "INFO: Disabled x86-64-mac-catalyst architecture which can not co-exist with x86-64 in the same framework bundle.\n" 1>>" ${ BASEDIR } " /build.log 2>& 1
disable_arch "x86-64-mac-catalyst"
2020-08-05 03:53:02 +03:00
fi
2020-08-05 03:26:42 +03:00
echo -e " \nBuilding ffmpeg-kit ${ BUILD_TYPE_ID } static library for iOS\n "
echo -e -n " INFO: Building ffmpeg-kit ${ BUILD_VERSION } ${ BUILD_TYPE_ID } for iOS: " 1>>" ${ BASEDIR } " /build.log 2>& 1
2020-08-05 03:53:02 +03:00
echo -e " $( date) \n " 1>>" ${ BASEDIR } " /build.log 2>& 1
2020-08-05 03:26:42 +03:00
# PRINT BUILD SUMMARY
print_enabled_architectures
print_enabled_libraries
print_reconfigure_requested_libraries
print_rebuild_requested_libraries
print_redownload_requested_libraries
2020-08-05 03:53:02 +03:00
# VALIDATE GPL FLAGS
2020-08-05 03:26:42 +03:00
for gpl_library in { $LIBRARY_X264 ,$LIBRARY_XVIDCORE ,$LIBRARY_X265 ,$LIBRARY_LIBVIDSTAB ,$LIBRARY_RUBBERBAND } ; do
if [ [ ${ ENABLED_LIBRARIES [ $gpl_library ] } -eq 1 ] ] ; then
2020-11-23 00:51:45 +02:00
library_name = $( get_library_name " ${ gpl_library } " )
2020-08-05 03:26:42 +03:00
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
2020-08-05 03:53:02 +03:00
echo -n -e "\nDownloading sources: "
echo -e "INFO: Downloading source code of ffmpeg and enabled external libraries.\n" 1>>" ${ BASEDIR } " /build.log 2>& 1
2020-11-23 00:51:45 +02:00
# DOWNLOAD GNU CONFIG
download_gnu_config
2020-08-05 03:53:02 +03:00
# DOWNLOAD LIBRARY SOURCES
downloaded_enabled_library_sources " ${ ENABLED_LIBRARIES [@] } "
# THIS WILL SAVE ARCHITECTURES TO BUILD
2020-08-05 03:26:42 +03:00
TARGET_ARCH_LIST = ( )
2020-08-05 03:53:02 +03:00
# BUILD ENABLED LIBRARIES ON ENABLED ARCHITECTURES
2020-11-23 00:51:45 +02:00
for run_arch in { 0..12} ; do
2020-08-05 03:26:42 +03:00
if [ [ ${ ENABLED_ARCHITECTURES [ $run_arch ] } -eq 1 ] ] ; then
2020-11-23 00:51:45 +02:00
export ARCH = $( get_arch_name " $run_arch " )
export FULL_ARCH = $( get_full_arch_name " $run_arch " )
2020-08-05 03:26:42 +03:00
export SDK_PATH = $( get_sdk_path)
export SDK_NAME = $( get_sdk_name)
2020-08-05 03:53:02 +03:00
# EXECUTE MAIN BUILD SCRIPT
2020-08-05 03:26:42 +03:00
. " ${ BASEDIR } " /scripts/main-ios.sh " ${ ENABLED_LIBRARIES [@] } "
2020-11-23 00:51:45 +02:00
TARGET_ARCH_LIST += ( " ${ FULL_ARCH } " )
2020-08-05 03:26:42 +03:00
# CLEAR FLAGS
2020-11-23 00:51:45 +02:00
for library in { 0..58} ; do
library_name = $( get_library_name " ${ library } " )
2020-08-05 03:26:42 +03:00
unset " $( echo " OK_ ${ library_name } " | sed "s/\-/\_/g" ) "
unset " $( echo " DEPENDENCY_REBUILT_ ${ library_name } " | sed "s/\-/\_/g" ) "
done
fi
done
2021-01-27 01:34:56 +02:00
echo -e -n "\n"
# DO NOT BUILD FRAMEWORKS
if [ [ ${ NO_FRAMEWORK } -ne 1 ] ] ; then
# BUILD FFMPEG-KIT
if [ [ -n ${ TARGET_ARCH_LIST [0] } ] ] ; then
2020-08-05 03:26:42 +03:00
2021-01-27 01:34:56 +02:00
# INITIALIZE TARGET FOLDERS
initialize_prebuilt_ios_folders
2020-08-05 03:26:42 +03:00
2021-01-27 01:34:56 +02:00
# PREPARE PLATFORM ARCHITECTURE STRINGS
build_apple_architecture_variant_strings
2020-08-05 03:26:42 +03:00
2021-01-27 01:34:56 +02:00
if [ [ -n ${ FFMPEG_KIT_XCF_BUILD } ] ] ; then
echo -e -n "\nCreating universal libraries and xcframeworks under prebuilt: "
2020-08-05 03:26:42 +03:00
2021-01-27 01:34:56 +02:00
create_universal_libraries_for_ios_xcframeworks
2020-08-05 03:53:02 +03:00
2021-01-27 01:34:56 +02:00
create_frameworks_for_ios_xcframeworks
2020-08-05 03:26:42 +03:00
2021-01-27 01:34:56 +02:00
create_ios_xcframeworks
else
echo -e -n "\nCreating universal libraries and frameworks under prebuilt: "
create_universal_libraries_for_ios_default_frameworks
2020-08-05 03:26:42 +03:00
2021-01-27 01:34:56 +02:00
create_ios_default_frameworks
fi
2020-08-05 03:26:42 +03:00
2021-01-27 01:34:56 +02:00
echo -e "ok\n"
2020-08-05 03:26:42 +03:00
fi
2020-11-23 00:51:45 +02:00
2021-01-27 01:34:56 +02:00
else
echo -e "INFO: Skipped creating iOS frameworks.\n" 1>>" ${ BASEDIR } " /build.log 2>& 1
2020-08-05 03:26:42 +03:00
fi