Skip to content

Commit

Permalink
support building custom libraries in native build scripts, fixes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
tanersener committed Dec 28, 2021
1 parent 3c77c50 commit ed8fd4b
Show file tree
Hide file tree
Showing 18 changed files with 474 additions and 109 deletions.
35 changes: 32 additions & 3 deletions android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ while [ ! $# -eq 0 ]; do
--enable-gpl)
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')

Expand Down Expand Up @@ -180,6 +188,7 @@ 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
Expand All @@ -195,13 +204,13 @@ for gpl_library in {$LIBRARY_X264,$LIBRARY_XVIDCORE,$LIBRARY_X265,$LIBRARY_LIBVI
done

echo -n -e "\nDownloading sources: "
echo -e "INFO: Downloading source code of ffmpeg and enabled external libraries.\n" 1>>"${BASEDIR}"/build.log 2>&1
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_enabled_library_sources "${ENABLED_LIBRARIES[@]}"
downloaded_library_sources "${ENABLED_LIBRARIES[@]}"

# SAVE ORIGINAL API LEVEL = NECESSARY TO BUILD 64bit ARCHITECTURES
export ORIGINAL_API=${API}
Expand Down Expand Up @@ -280,7 +289,7 @@ if [[ -n ${ANDROID_ARCHITECTURES} ]]; then

cd "${BASEDIR}"/android 1>>"${BASEDIR}"/build.log 2>&1 || exit 1

# COPY LICENSES
# COPY LIBRARY LICENSES
LICENSE_BASEDIR="${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/res/raw
rm -f "${LICENSE_BASEDIR}"/*.txt 1>>"${BASEDIR}"/build.log 2>&1 || exit 1
for library in {0..49}; do
Expand All @@ -300,6 +309,26 @@ if [[ -n ${ANDROID_ARCHITECTURES} ]]; then
fi
done

# COPY CUSTOM LIBRARY LICENSES
for custom_library_index in "${CUSTOM_LIBRARIES[@]}"; do
library_name="CUSTOM_LIBRARY_${custom_library_index}_NAME"
relative_license_path="CUSTOM_LIBRARY_${custom_library_index}_LICENSE_FILE"

destination_license_path="${LICENSE_BASEDIR}/license_${!library_name}.txt"

cp "${BASEDIR}/src/${!library_name}/${!relative_license_path}" "${destination_license_path}" 1>>"${BASEDIR}"/build.log 2>&1

RC=$?

if [[ ${RC} -ne 0 ]]; then
echo -e "DEBUG: Failed to copy the license file of custom library ${!library_name}\n" 1>>"${BASEDIR}"/build.log 2>&1
echo -e "failed\n\nSee build.log for details\n"
exit 1
fi

echo -e "DEBUG: Copied the license file of custom library ${!library_name} successfully\n" 1>>"${BASEDIR}"/build.log 2>&1
done

# COPY LIBRARY LICENSES
if [[ ${GPL_ENABLED} == "yes" ]]; then
cp "${BASEDIR}"/LICENSE.GPLv3 "${LICENSE_BASEDIR}"/license.txt 1>>"${BASEDIR}"/build.log 2>&1
Expand Down
13 changes: 11 additions & 2 deletions ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ while [ ! $# -eq 0 ]; do
--enable-gpl)
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')

Expand Down Expand Up @@ -211,6 +219,7 @@ 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
Expand All @@ -226,13 +235,13 @@ for gpl_library in {$LIBRARY_X264,$LIBRARY_XVIDCORE,$LIBRARY_X265,$LIBRARY_LIBVI
done

echo -n -e "\nDownloading sources: "
echo -e "INFO: Downloading source code of ffmpeg and enabled external libraries.\n" 1>>"${BASEDIR}"/build.log 2>&1
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_enabled_library_sources "${ENABLED_LIBRARIES[@]}"
downloaded_library_sources "${ENABLED_LIBRARIES[@]}"

# THIS WILL SAVE ARCHITECTURES TO BUILD
TARGET_ARCH_LIST=()
Expand Down
13 changes: 11 additions & 2 deletions macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ while [ ! $# -eq 0 ]; do
--enable-gpl)
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')

Expand Down Expand Up @@ -180,6 +188,7 @@ 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
Expand All @@ -195,13 +204,13 @@ for gpl_library in {$LIBRARY_X264,$LIBRARY_XVIDCORE,$LIBRARY_X265,$LIBRARY_LIBVI
done

echo -n -e "\nDownloading sources: "
echo -e "INFO: Downloading source code of ffmpeg and enabled external libraries.\n" 1>>"${BASEDIR}"/build.log 2>&1
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_enabled_library_sources "${ENABLED_LIBRARIES[@]}"
downloaded_library_sources "${ENABLED_LIBRARIES[@]}"

# THIS WILL SAVE ARCHITECTURES TO BUILD
TARGET_ARCH_LIST=()
Expand Down
30 changes: 20 additions & 10 deletions scripts/android/ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ if [ -z "${HOST_PKG_CONFIG_PATH}" ]; then
exit 1
fi

# ENABLE COMMON FUNCTIONS
source "${BASEDIR}"/scripts/function-"${FFMPEG_KIT_BUILD_TYPE}".sh 1>>"${BASEDIR}"/build.log 2>&1 || exit 1

LIB_NAME="ffmpeg"

echo -e "----------------------------------------------------------------" 1>>"${BASEDIR}"/build.log 2>&1
Expand Down Expand Up @@ -72,9 +69,9 @@ CONFIGURE_POSTFIX=""
HIGH_PRIORITY_INCLUDES=""

# SET CONFIGURE OPTIONS
for library in {1..62}; do
if [[ ${!library} -eq 1 ]]; then
ENABLED_LIBRARY=$(get_library_name $((library - 1)))
for library in {0..61}; do
if [[ ${ENABLED_LIBRARIES[$library]} -eq 1 ]]; then
ENABLED_LIBRARY=$(get_library_name ${library})

echo -e "INFO: Enabling library ${ENABLED_LIBRARY}\n" 1>>"${BASEDIR}"/build.log 2>&1

Expand Down Expand Up @@ -311,18 +308,31 @@ for library in {1..62}; do

# THE FOLLOWING LIBRARIES SHOULD BE EXPLICITLY DISABLED TO PREVENT AUTODETECT
# NOTE THAT IDS MUST BE +1 OF THE INDEX VALUE
if [[ ${library} -eq $((LIBRARY_SDL + 1)) ]]; then
if [[ ${library} -eq ${LIBRARY_SDL} ]]; then
CONFIGURE_POSTFIX+=" --disable-sdl2"
elif [[ ${library} -eq $((LIBRARY_ANDROID_ZLIB + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_ANDROID_ZLIB} ]]; then
CONFIGURE_POSTFIX+=" --disable-zlib"
elif [[ ${library} -eq $((LIBRARY_ANDROID_MEDIA_CODEC + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_ANDROID_MEDIA_CODEC} ]]; then
CONFIGURE_POSTFIX+=" --disable-mediacodec"
elif [[ ${library} -eq $((LIBRARY_OPENSSL + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_OPENSSL} ]]; then
CONFIGURE_POSTFIX+=" --disable-openssl"
fi
fi
done

# SET CONFIGURE OPTIONS FOR CUSTOM LIBRARIES
for custom_library_index in "${CUSTOM_LIBRARIES[@]}"; do
library_name="CUSTOM_LIBRARY_${custom_library_index}_NAME"
pc_file_name="CUSTOM_LIBRARY_${custom_library_index}_PACKAGE_CONFIG_FILE_NAME"
ffmpeg_flag_name="CUSTOM_LIBRARY_${custom_library_index}_FFMPEG_ENABLE_FLAG"

echo -e "INFO: Enabling custom library ${!library_name}\n" 1>>"${BASEDIR}"/build.log 2>&1

CFLAGS+=" $(pkg-config --cflags ${!pc_file_name} 2>>"${BASEDIR}"/build.log)"
LDFLAGS+=" $(pkg-config --libs --static ${!pc_file_name} 2>>"${BASEDIR}"/build.log)"
CONFIGURE_POSTFIX+=" --enable-${!ffmpeg_flag_name}"
done

export LDFLAGS+=" -L${ANDROID_NDK_ROOT}/platforms/android-${API}/arch-${TOOLCHAIN_ARCH}/usr/lib"

# LINKING WITH ANDROID LTS SUPPORT LIBRARY IS NECESSARY FOR API < 18
Expand Down
44 changes: 27 additions & 17 deletions scripts/apple/ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ if [ -z "${HOST_PKG_CONFIG_PATH}" ]; then
exit 1
fi

# ENABLE COMMON FUNCTIONS
source "${BASEDIR}"/scripts/function-"${FFMPEG_KIT_BUILD_TYPE}".sh 1>>"${BASEDIR}"/build.log 2>&1 || exit 1

LIB_NAME="ffmpeg"

echo -e "----------------------------------------------------------------" 1>>"${BASEDIR}"/build.log 2>&1
Expand Down Expand Up @@ -104,9 +101,9 @@ esac
CONFIGURE_POSTFIX=""

# SET CONFIGURE OPTIONS
for library in {1..62}; do
if [[ ${!library} -eq 1 ]]; then
ENABLED_LIBRARY=$(get_library_name $((library - 1)))
for library in {0..61}; do
if [[ ${ENABLED_LIBRARIES[$library]} -eq 1 ]]; then
ENABLED_LIBRARY=$(get_library_name ${library})

echo -e "INFO: Enabling library ${ENABLED_LIBRARY}\n" 1>>"${BASEDIR}"/build.log 2>&1

Expand Down Expand Up @@ -366,32 +363,45 @@ for library in {1..62}; do

# THE FOLLOWING LIBRARIES SHOULD BE EXPLICITLY DISABLED TO PREVENT AUTODETECT
# NOTE THAT IDS MUST BE +1 OF THE INDEX VALUE
if [[ ${library} -eq $((LIBRARY_SDL + 1)) ]]; then
if [[ ${library} -eq ${LIBRARY_SDL} ]]; then
CONFIGURE_POSTFIX+=" --disable-sdl2"
elif [[ ${library} -eq $((LIBRARY_APPLE_AUDIOTOOLBOX + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_APPLE_AUDIOTOOLBOX} ]]; then
CONFIGURE_POSTFIX+=" --disable-audiotoolbox"
elif [[ ${library} -eq $((LIBRARY_APPLE_AVFOUNDATION + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_APPLE_AVFOUNDATION} ]]; then
CONFIGURE_POSTFIX+=" --disable-avfoundation"
elif [[ ${library} -eq $((LIBRARY_APPLE_BZIP2 + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_APPLE_BZIP2} ]]; then
CONFIGURE_POSTFIX+=" --disable-bzlib"
elif [[ ${library} -eq $((LIBRARY_APPLE_COREIMAGE + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_APPLE_COREIMAGE} ]]; then
CONFIGURE_POSTFIX+=" --disable-coreimage --disable-appkit"
elif [[ ${library} -eq $((LIBRARY_APPLE_LIBICONV + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_APPLE_LIBICONV} ]]; then
CONFIGURE_POSTFIX+=" --disable-iconv"
elif [[ ${library} -eq $((LIBRARY_APPLE_OPENCL + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_APPLE_OPENCL} ]]; then
CONFIGURE_POSTFIX+=" --disable-opencl"
elif [[ ${library} -eq $((LIBRARY_APPLE_OPENGL + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_APPLE_OPENGL} ]]; then
CONFIGURE_POSTFIX+=" --disable-opengl"
elif [[ ${library} -eq $((LIBRARY_APPLE_VIDEOTOOLBOX + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_APPLE_VIDEOTOOLBOX} ]]; then
CONFIGURE_POSTFIX+=" --disable-videotoolbox"
elif [[ ${library} -eq $((LIBRARY_APPLE_ZLIB + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_APPLE_ZLIB} ]]; then
CONFIGURE_POSTFIX+=" --disable-zlib"
elif [[ ${library} -eq $((LIBRARY_OPENSSL + 1)) ]]; then
elif [[ ${library} -eq ${LIBRARY_OPENSSL} ]]; then
CONFIGURE_POSTFIX+=" --disable-openssl"
fi
fi
done

# SET CONFIGURE OPTIONS FOR CUSTOM LIBRARIES
for custom_library_index in "${CUSTOM_LIBRARIES[@]}"; do
library_name="CUSTOM_LIBRARY_${custom_library_index}_NAME"
pc_file_name="CUSTOM_LIBRARY_${custom_library_index}_PACKAGE_CONFIG_FILE_NAME"
ffmpeg_flag_name="CUSTOM_LIBRARY_${custom_library_index}_FFMPEG_ENABLE_FLAG"

echo -e "INFO: Enabling custom library ${!library_name}\n" 1>>"${BASEDIR}"/build.log 2>&1

FFMPEG_CFLAGS+=" $(pkg-config --cflags ${!pc_file_name} 2>>"${BASEDIR}"/build.log)"
FFMPEG_LDFLAGS+=" $(pkg-config --libs --static ${!pc_file_name} 2>>"${BASEDIR}"/build.log)"
CONFIGURE_POSTFIX+=" --enable-${!ffmpeg_flag_name}"
done

# ALWAYS BUILD SHARED LIBRARIES
BUILD_LIBRARY_OPTIONS="--enable-shared --disable-static --install-name-dir=@rpath"

Expand Down
1 change: 1 addition & 0 deletions scripts/function-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ under the prebuilt folder.\n"

display_help_common_libraries
display_help_gpl_libraries
display_help_custom_libraries
display_help_advanced_options " --no-archive\t\t\tdo not build Android archive [no]"
}

Expand Down
42 changes: 42 additions & 0 deletions scripts/function-apple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,27 @@ create_ffmpeg_universal_library() {
fi
done

# COPY CUSTOM LIBRARY LICENSES
for custom_library_index in "${CUSTOM_LIBRARIES[@]}"; do
library_name="CUSTOM_LIBRARY_${custom_library_index}_NAME"
library_name_uppercase=$(echo "${!library_name}" | tr '[a-z]' '[A-Z]')
relative_license_path="CUSTOM_LIBRARY_${custom_library_index}_LICENSE_FILE"

destination_license_path="${FFMPEG_UNIVERSAL_LIBRARY_DIRECTORY}/LICENSE.${library_name_uppercase}"

cp "${BASEDIR}/src/${!library_name}/${!relative_license_path}" "${destination_license_path}" 1>>"${BASEDIR}"/build.log 2>&1

RC=$?

if [[ ${RC} -ne 0 ]]; then
echo -e "DEBUG: Failed to copy the license file of custom library ${!library_name}\n" 1>>"${BASEDIR}"/build.log 2>&1
echo -e "failed\n\nSee build.log for details\n"
exit 1
fi

echo -e "DEBUG: Copied the license file of custom library ${!library_name} successfully\n" 1>>"${BASEDIR}"/build.log 2>&1
done

echo -e "DEBUG: ${LIBRARY_NAME} universal library built for $(get_apple_architecture_variant "${ARCHITECTURE_VARIANT}") platform successfully\n" 1>>"${BASEDIR}"/build.log 2>&1
}

Expand Down Expand Up @@ -407,6 +428,27 @@ create_ffmpeg_framework() {
[[ ${RC} -ne 0 ]] && exit_universal_library "${LIBRARY_NAME}"
fi
done

# COPY CUSTOM LIBRARY LICENSES
for custom_library_index in "${CUSTOM_LIBRARIES[@]}"; do
library_name="CUSTOM_LIBRARY_${custom_library_index}_NAME"
library_name_uppercase=$(echo "${!library_name}" | tr '[a-z]' '[A-Z]')
relative_license_path="CUSTOM_LIBRARY_${custom_library_index}_LICENSE_FILE"

destination_license_path="${FFMPEG_LIB_FRAMEWORK_RESOURCE_PATH}/LICENSE.${ENABLED_LIBRARY_NAME_UPPERCASE}"

cp "${BASEDIR}/src/${!library_name}/${!relative_license_path}" "${destination_license_path}" 1>>"${BASEDIR}"/build.log 2>&1

RC=$?

if [[ ${RC} -ne 0 ]]; then
echo -e "DEBUG: Failed to copy the license file of custom library ${!library_name}\n" 1>>"${BASEDIR}"/build.log 2>&1
echo -e "failed\n\nSee build.log for details\n"
exit 1
fi

echo -e "DEBUG: Copied the license file of custom library ${!library_name} successfully\n" 1>>"${BASEDIR}"/build.log 2>&1
done
fi

build_info_plist "${FFMPEG_LIB_FRAMEWORK_RESOURCE_PATH}/Info.plist" "${FFMPEG_LIB}" "com.arthenica.ffmpegkit.${CAPITAL_CASE_FFMPEG_LIB_NAME}" "${FFMPEG_LIB_VERSION}" "${FFMPEG_LIB_VERSION}" "${ARCHITECTURE_VARIANT}"
Expand Down
1 change: 1 addition & 0 deletions scripts/function-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ libraries are created under the prebuilt folder.\n"

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]"
else
Expand Down
1 change: 1 addition & 0 deletions scripts/function-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ When compilation ends, libraries are created under the prebuilt folder.\n"

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]"
else
Expand Down
1 change: 1 addition & 0 deletions scripts/function-tvos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set explicitly. When compilation ends, libraries are created under the prebuilt

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]"
else
Expand Down
Loading

0 comments on commit ed8fd4b

Please sign in to comment.