From 4606c71fe3bb7fd41d6e99d5e137b36039b92c55 Mon Sep 17 00:00:00 2001 From: valord577 <30427460+valord577@users.noreply.github.com> Date: Tue, 7 May 2024 22:23:51 +0800 Subject: [PATCH] add pkgs: ffmpeg (#5) --- .github/workflows/_buildx.yml | 5 +- .github/workflows/ffmpeg.yml | 33 +++++++ build.sh | 4 +- deps/ffmpeg | 2 +- env-apple.sh | 5 +- patchs/ffmpeg/01_use_custom_config.patch | 6 +- ...e.patch => 03_fix_ios_api_available.patch} | 0 patchs/ffmpeg/04_fix_some_warning.patch | 40 -------- patchs/ffmpeg/04_fix_some_warnings.patch | 52 ++++++++++ patchs/ffmpeg/05_fix_linker_xcode15.patch | 12 +++ pkg-conf.sh | 46 +++++++++ scripts/ffmpeg.sh | 96 +++++++++---------- scripts/mbedtls.sh | 2 +- 13 files changed, 203 insertions(+), 100 deletions(-) create mode 100644 .github/workflows/ffmpeg.yml rename patchs/ffmpeg/{03_fix_api_available.patch => 03_fix_ios_api_available.patch} (100%) delete mode 100644 patchs/ffmpeg/04_fix_some_warning.patch create mode 100644 patchs/ffmpeg/04_fix_some_warnings.patch create mode 100644 patchs/ffmpeg/05_fix_linker_xcode15.patch create mode 100755 pkg-conf.sh diff --git a/.github/workflows/_buildx.yml b/.github/workflows/_buildx.yml index 5d1837a..d22dbac 100644 --- a/.github/workflows/_buildx.yml +++ b/.github/workflows/_buildx.yml @@ -40,9 +40,12 @@ jobs: uses: actions/checkout@v4 with: path: ${{ env._REPO_THIS }} + fetch-depth: 0 + lfs: true - name: install required software(s) run: | - brew install ccache + brew list -l + brew install ccache nasm - name: gh action ccache restore uses: actions/cache/restore@v4 with: diff --git a/.github/workflows/ffmpeg.yml b/.github/workflows/ffmpeg.yml new file mode 100644 index 0000000..fd16e37 --- /dev/null +++ b/.github/workflows/ffmpeg.yml @@ -0,0 +1,33 @@ +name: ffmpeg +on: + push: + branches: + - main + paths: + - '.github/workflows/_buildx.yml' + - '.github/workflows/ffmpeg.yml' + - 'deps/ffmpeg' + - 'patchs/ffmpeg/**' + - 'scripts/ffmpeg.sh' + - 'build.sh' + - 'env-apple.sh' + - 'pkg-conf.sh' + pull_request: + branches: + - main + paths: + - '.github/workflows/_buildx.yml' + - '.github/workflows/ffmpeg.yml' + - 'deps/ffmpeg' + - 'patchs/ffmpeg/**' + - 'scripts/ffmpeg.sh' + - 'build.sh' + - 'env-apple.sh' + - 'pkg-conf.sh' + +jobs: + build: + secrets: inherit + uses: ./.github/workflows/_buildx.yml + with: + disable_shared: false diff --git a/build.sh b/build.sh index eb52c7d..c12e9eb 100755 --- a/build.sh +++ b/build.sh @@ -61,7 +61,7 @@ function compile() { if [ ! -e "${SUBPROJ_SRC}/.git" ]; then pushd -- "${PROJ_ROOT}" - git submodule update --init --depth 1 -- "deps/${PKG_NAME}" + git submodule update --init -f --depth ${GIT_DEPTH:-"20"} -- "deps/${PKG_NAME}" popd fi pushd -- "${SUBPROJ_SRC}" @@ -81,7 +81,7 @@ function compile() { ) } -if [ ! ${GITHUB_ACTIONS} ]; then +if [ "${GITHUB_ACTIONS}" != "true" ]; then if [ -z ${1} ]; then printf "\e[1m\e[31m%s\e[0m\n" "Please declare the modules to be compiled." exit 1 diff --git a/deps/ffmpeg b/deps/ffmpeg index 2b17a74..2eab5a1 160000 --- a/deps/ffmpeg +++ b/deps/ffmpeg @@ -1 +1 @@ -Subproject commit 2b17a74df5fbbc87cdf7a0a784e2e088ab4afd3c +Subproject commit 2eab5a1f54cd08ea8b5a2b55a805718c51b26436 diff --git a/env-apple.sh b/env-apple.sh index e1ddee0..84f847b 100755 --- a/env-apple.sh +++ b/env-apple.sh @@ -49,6 +49,5 @@ case ${TARGET_PLATFORM} in esac export SYSROOT="$(xcrun --sdk ${TARGET_PLATFORM} --show-sdk-path)" -export ECFLAGS=" -arch ${TARGET_ARCH} -m${TARGET_FLAG}-version-min=${TARGET_DEPLOYMENT}" -export ECXXFLAGS="-arch ${TARGET_ARCH} -m${TARGET_FLAG}-version-min=${TARGET_DEPLOYMENT}" -export ELDFLAGS=" -arch ${TARGET_ARCH} -m${TARGET_FLAG}-version-min=${TARGET_DEPLOYMENT}" +export ECFLAGS=" -arch ${TARGET_ARCH} -m${TARGET_FLAG}-version-min=${TARGET_DEPLOYMENT}" +export ELDFLAGS="-arch ${TARGET_ARCH} -m${TARGET_FLAG}-version-min=${TARGET_DEPLOYMENT}" diff --git a/patchs/ffmpeg/01_use_custom_config.patch b/patchs/ffmpeg/01_use_custom_config.patch index c2bbd6d..f1fe977 100644 --- a/patchs/ffmpeg/01_use_custom_config.patch +++ b/patchs/ffmpeg/01_use_custom_config.patch @@ -1,12 +1,12 @@ diff --git a/configure b/configure -index bb5e630bad..8c1e945052 100755 +index 00c3cee33f..12800dcb21 100755 --- a/configure +++ b/configure -@@ -7923,6 +7923,12 @@ enabled stripping || striptype="" +@@ -8010,6 +8010,12 @@ enabled stripping || striptype="" config_files="$TMPH ffbuild/config.mak doc/config.texi" -+if [ ${GITHUB_ACTIONS} ]; then ++if [ "${GITHUB_ACTIONS}" == "true" ]; then + FFMPEG_CONFIGURATION="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID} (${GITHUB_SHA})" +else + FFMPEG_CONFIGURATION="ffmpeg for apple - $(whoami)@$(uname -n) $(date -u '+%Y-%m-%dT%H:%M:%SZ%:z')" diff --git a/patchs/ffmpeg/03_fix_api_available.patch b/patchs/ffmpeg/03_fix_ios_api_available.patch similarity index 100% rename from patchs/ffmpeg/03_fix_api_available.patch rename to patchs/ffmpeg/03_fix_ios_api_available.patch diff --git a/patchs/ffmpeg/04_fix_some_warning.patch b/patchs/ffmpeg/04_fix_some_warning.patch deleted file mode 100644 index 79d8cb2..0000000 --- a/patchs/ffmpeg/04_fix_some_warning.patch +++ /dev/null @@ -1,40 +0,0 @@ -diff --git a/libavcodec/arm/vp8.h b/libavcodec/arm/vp8.h -index 7c59a7d63d..6f128ffebe 100644 ---- a/libavcodec/arm/vp8.h -+++ b/libavcodec/arm/vp8.h -@@ -29,7 +29,8 @@ - #define vp8_decode_block_coeffs_internal ff_decode_block_coeffs_armv6 - int ff_decode_block_coeffs_armv6(VPXRangeCoder *rc, int16_t block[16], - uint8_t probs[8][3][NUM_DCT_TOKENS-1], -- int i, uint8_t *token_prob, int16_t qmul[2]); -+ int i, const uint8_t *token_prob, -+ const int16_t qmul[2]); - #endif - - #endif /* AVCODEC_ARM_VP8_H */ -diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c -index 5456f916cf..156cd488e3 100644 ---- a/libavcodec/audiotoolboxdec.c -+++ b/libavcodec/audiotoolboxdec.c -@@ -35,7 +35,7 @@ - #include "libavutil/opt.h" - #include "libavutil/log.h" - --#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100 -+#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100 - #define kAudioFormatEnhancedAC3 'ec-3' - #endif - -diff --git a/libavcodec/pcm-dvdenc.c b/libavcodec/pcm-dvdenc.c -index a2e5cbdc2e..d9daa671a5 100644 ---- a/libavcodec/pcm-dvdenc.c -+++ b/libavcodec/pcm-dvdenc.c -@@ -35,7 +35,7 @@ typedef struct PCMDVDContext { - static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx) - { - PCMDVDContext *s = avctx->priv_data; -- int quant, freq, frame_size; -+ int quant = 0, freq, frame_size; - - switch (avctx->sample_rate) { - case 48000: diff --git a/patchs/ffmpeg/04_fix_some_warnings.patch b/patchs/ffmpeg/04_fix_some_warnings.patch new file mode 100644 index 0000000..c455808 --- /dev/null +++ b/patchs/ffmpeg/04_fix_some_warnings.patch @@ -0,0 +1,52 @@ +diff --git a/configure b/configure +index 00c3cee33f..87a8fffd32 100755 +--- a/configure ++++ b/configure +@@ -7386,7 +7386,7 @@ fi + enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel" + + # add some useful compiler flags if supported +-check_cflags -Wdeclaration-after-statement ++# check_cflags -Wdeclaration-after-statement + check_cflags -Wall + check_cflags -Wdisabled-optimization + check_cflags -Wpointer-arith +diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c +index 0f7ce8e4eb..a0fc27f76c 100644 +--- a/libavcodec/audiotoolboxdec.c ++++ b/libavcodec/audiotoolboxdec.c +@@ -36,7 +36,7 @@ + #include "libavutil/opt.h" + #include "libavutil/log.h" + +-#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101100 ++#if MAC_OS_X_VERSION_MIN_REQUIRED < 101100 + #define kAudioFormatEnhancedAC3 'ec-3' + #endif + +diff --git a/libavcodec/pcm-dvdenc.c b/libavcodec/pcm-dvdenc.c +index 1e7ee644f6..2da29a9abb 100644 +--- a/libavcodec/pcm-dvdenc.c ++++ b/libavcodec/pcm-dvdenc.c +@@ -35,7 +35,7 @@ typedef struct PCMDVDContext { + static av_cold int pcm_dvd_encode_init(AVCodecContext *avctx) + { + PCMDVDContext *s = avctx->priv_data; +- int quant, freq, frame_size; ++ int quant = 0, freq, frame_size; + + switch (avctx->sample_rate) { + case 48000: +diff --git a/libavfilter/vf_yadif_videotoolbox.m b/libavfilter/vf_yadif_videotoolbox.m +index c47d3edfb8..4ec448de1d 100644 +--- a/libavfilter/vf_yadif_videotoolbox.m ++++ b/libavfilter/vf_yadif_videotoolbox.m +@@ -172,7 +172,7 @@ static void filter(AVFilterContext *ctx, AVFrame *dst, + static av_cold void do_uninit(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), ios(8.0)) + { + YADIFVTContext *s = ctx->priv; +- YADIFContext *y = &s->yadif; ++ // YADIFContext *y = &s->yadif; + + ff_yadif_uninit(ctx); + diff --git a/patchs/ffmpeg/05_fix_linker_xcode15.patch b/patchs/ffmpeg/05_fix_linker_xcode15.patch new file mode 100644 index 0000000..4e90689 --- /dev/null +++ b/patchs/ffmpeg/05_fix_linker_xcode15.patch @@ -0,0 +1,12 @@ +diff --git a/configure b/configure +index 00c3cee33f..50964f2f30 100755 +--- a/configure ++++ b/configure +@@ -5788,6 +5788,7 @@ case $target_os in + if enabled clang; then + clang_version=$($cc -dumpversion) + test ${clang_version%%.*} -eq 11 && add_cflags -fno-stack-check ++ test ${clang_version%%.*} -eq 15 && add_ldflags -Wl,-ld_classic + fi + ;; + msys*) diff --git a/pkg-conf.sh b/pkg-conf.sh new file mode 100755 index 0000000..4a4aef4 --- /dev/null +++ b/pkg-conf.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +set -e + +export PKG_CONFIG_EXEC="pkg-config" +if command -v pkgconf >/dev/null 2>&1 ; then + export PKG_CONFIG_EXEC="pkgconf" +fi + +if [ -z "${PROJ_ROOT}" ]; then + PROJ_ROOT=$(cd "$(dirname ${BASH_SOURCE[0]})"; pwd) +fi +if [ "${GITHUB_ACTIONS}" == "true" ]; then + pushd -- "${PROJ_ROOT}"; { git lfs fetch --all --prune; }; popd +fi +export PKG_DEPS_PATH="${PROJ_ROOT}/lib" +{ rm -rf "${PKG_DEPS_PATH}"; mkdir -p "${PKG_DEPS_PATH}"; } + +function dl_pkgc() { + ( + pkg_name="${1}" + pkg_version="${2}" + pkg_type="${3}" + pkg_extra="${4}" + dl_filename="${pkg_name}_${PKG_PLATFORM}_${PKG_ARCH}_${pkg_version}_${pkg_type}.zip" + if [ -n "${pkg_extra}" ]; then + dl_filename="${pkg_name}_${PKG_PLATFORM}_${PKG_ARCH}_${pkg_version}_${pkg_type}_${pkg_extra}.zip" + fi + printf "\e[1m\e[36m%s\e[0m\n" "dl_filename='${dl_filename}'" + + pushd -- "${PROJ_ROOT}" + { + set -x + git archive --format=tar origin/packages ${pkg_name}/${pkg_version}/${dl_filename} \ + | tar -xvf - -C "${PKG_DEPS_PATH}" --strip-components=2 --no-same-owner + unzip -q "${PKG_DEPS_PATH}/${dl_filename}" -d "${PKG_DEPS_PATH}" + set +x + } + popd + ) + + export PKG_DEPS_ARGS="${PKG_DEPS_ARGS} ${5}" + if [ "${3}" == "shared" ]; then { export PKG_DEPS_SHARED="${PKG_DEPS_SHARED} ${1}"; } fi + + export PKG_DEPS_CMAKE="${PKG_DEPS_PATH}/${1};${PKG_DEPS_CMAKE}" + export PKG_CONFIG_PATH="${PKG_DEPS_PATH}/${1}/lib/pkgconfig:${PKG_CONFIG_PATH}" +} diff --git a/scripts/ffmpeg.sh b/scripts/ffmpeg.sh index dbc7403..812da4a 100755 --- a/scripts/ffmpeg.sh +++ b/scripts/ffmpeg.sh @@ -1,6 +1,14 @@ #!/usr/bin/env bash set -e +# ---------------------------- +# packages +# ---------------------------- +source "${PROJ_ROOT}/pkg-conf.sh" +dl_pkgc mbedtls '2ca6c28' static '' '--enable-mbedtls' +dl_pkgc sdl2 'fb14975' static '' '' + +printf "\e[1m\e[35m%s\e[0m\n" "${PKG_CONFIG_PATH}" # ---------------------------- # static or shared # ---------------------------- @@ -23,11 +31,11 @@ esac # ---------------------------- LIB_RELEASE=${LIB_RELEASE:-"1"} if [ "${LIB_RELEASE}" == "1" ]; then - PKG_BUILD_TYPE="--disable-debug" - PKG_INSTALL_STRIP="" + PKG_BULD_TYPE="--disable-debug --disable-logging" + PKG_INST_STRIP="" else - PKG_BUILD_TYPE="--disable-optimizations" - PKG_INSTALL_STRIP="--disable-stripping" + PKG_BULD_TYPE="--disable-optimizations --enable-extra-warnings" + PKG_INST_STRIP="--disable-stripping" fi # ---------------------------- # compile :p @@ -35,65 +43,52 @@ fi { rm -rf ${PKG_BULD_DIR}; mkdir -p "${PKG_BULD_DIR}"; } { rm -rf ${PKG_INST_DIR}; mkdir -p "${PKG_INST_DIR}"; } -function ffm_deps() { - local FFM_DEPS_NAME="${1}" - local FFM_DEPS_PATH="${PROJ_ROOT}/out/${FFM_DEPS_NAME}/${PKG_PLATFORM}/${PKG_ARCH}" - export CFLAGS="-I${FFM_DEPS_PATH}/include ${CFLAGS}" - export CXXFLAGS="-I${FFM_DEPS_PATH}/include ${CXXFLAGS}" - export LDFLAGS="-L${FFM_DEPS_PATH}/lib ${LDFLAGS}" -} -# ffm_deps "${PROJ_ROOT}/../librga/out" -# ffm_deps "${PROJ_ROOT}/../libyuv/out" - -if command -v pkgconf >/dev/null 2>&1 ; then - PKG_CONFIG_BIN="--pkg-config=pkgconf" -fi -function ffm_pkgc() { - local FFM_DEPS_NAME="${1}" - local FFM_DEPS_PATH="${PROJ_ROOT}/out/${FFM_DEPS_NAME}/${PKG_PLATFORM}/${PKG_ARCH}" - export PKG_CONFIG_PATH="${FFM_DEPS_PATH}/lib/pkgconfig:${PKG_CONFIG_PATH}" - - FF_CONFIGURE_EXTRA="${FF_CONFIGURE_EXTRA} ${2}" -} -ffm_pkgc mbedtls '--enable-mbedtls' - -case ${PKG_PLATFORM} in - "macosx") - ;; - "iphoneos" | "iphonesimulator") - FF_CONFIGURE_EXTRA="${FF_CONFIGURE_EXTRA} --disable-programs" - ;; - ?) - ;; -esac +if [ "${CLANGD_CODE_COMPLETION}" == "1" ]; then { PKG_BULD_DIR="${SUBPROJ_SRC}"; } fi pushd -- "${PKG_BULD_DIR}" CONFIGURE_COMMAND=$(cat <<- EOF ${SUBPROJ_SRC}/configure \ --prefix='${PKG_INST_DIR}' \ --cc='${CC}' --cxx='${CXX}' \ - --enable-cross-compile \ - --sysroot='${SYSROOT_PATH}' \ - --target-os=darwin --arch=${PKG_ARCH} \ - --extra-cflags='${CFLAGS_EXTRA}' \ - --extra-cxxflags='${CXXFLAGS_EXTRA}' \ - --extra-ldflags='${LDFLAGS_EXTRA}' \ - ${PKG_TYPE_FLAG} \ - ${PKG_BUILD_TYPE} \ - ${PKG_INSTALL_STRIP} \ - ${PKG_CONFIG_BIN} \ - --disable-logging \ - --disable-coreimage \ + ${PKG_TYPE_FLAG} \ + ${PKG_BULD_TYPE} \ + ${PKG_INST_STRIP} \ + --pkg-config='${PKG_CONFIG_EXEC}' \ + --extra-cflags='${ECFLAGS}' \ + --extra-cxxflags='${ECFLAGS}' \ + --extra-ldflags='${ELDFLAGS}' \ + --enable-gpl \ --enable-version3 \ --fatal-warnings \ --disable-doc \ --disable-devices \ --enable-indev=lavfi \ --enable-pic \ - --disable-symver \ - ${FF_CONFIGURE_EXTRA} + ${PKG_DEPS_ARGS} EOF ) + +case ${PKG_PLATFORM} in + "macosx" | "iphoneos" | "iphonesimulator") + CONFIGURE_COMMAND="${CONFIGURE_COMMAND} \ + --enable-cross-compile --sysroot='${SYSROOT}' \ + --target-os=darwin --arch=${PKG_ARCH} --disable-coreimage \ + --disable-libxcb --disable-xlib + " + ;; + ?) + ;; +esac +case ${PKG_PLATFORM} in + "macosx") + ;; + "iphoneos" | "iphonesimulator") + CONFIGURE_COMMAND="${CONFIGURE_COMMAND} --disable-programs" + ;; + ?) + ;; +esac + printf "\e[1m\e[36m%s\e[0m\n" "${CONFIGURE_COMMAND}" && eval ${CONFIGURE_COMMAND} popd @@ -107,6 +102,9 @@ eval ${MAKE_COMMAND} make install popd +for solib in ${PKG_DEPS_SHARED}; do + cp -a ${PKG_DEPS_PATH}/${solib}/lib/*.so "${PKG_INST_DIR}/lib" +done if command -v tree >/dev/null 2>&1 ; then tree ${PKG_INST_DIR} diff --git a/scripts/mbedtls.sh b/scripts/mbedtls.sh index 0381ccb..ad74ec7 100755 --- a/scripts/mbedtls.sh +++ b/scripts/mbedtls.sh @@ -7,7 +7,7 @@ set -e pushd -- "${SUBPROJ_SRC}" git submodule set-url -- framework ../mbedtls-framework -git submodule update --init --depth ${GIT_DEPTH:-"20"} -- framework +git submodule update --init -f --depth ${GIT_DEPTH:-"20"} -- framework popd # ---------------------------- # preset features