From cbd525e033eb8062c5f98e4be83fad401b44ad57 Mon Sep 17 00:00:00 2001 From: Javernaut Date: Wed, 7 Aug 2019 15:28:25 +0300 Subject: [PATCH] Structured --arch, --cc and --cross-prefix evaluating --- README.md | 4 +-- ffmpeg-android-maker.sh | 75 +++++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index c2bcd92..79167d0 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ Here is a script that downloads the source code of [FFmpeg](https://www.ffmpeg.o The actual content of all this directories depends on how the FFmpeg was configured before assembling. For my purpose I enabled only *libavcodec*, *libavformat*, *libavutil* and *libswscale*, but you can set your own configuration to make the FFmpeg you need. The version of FFmpeg here by default is **4.1.4** (but can be overridden). And the script expects to use **at least** Android NDK **r19** (*r20* also works ok). Starting with FFmpeg 4.1 and NDK r19 the whole process became much simpler. -## Supported Android architectures - +## Supported Android ABIs +a * armeabi-v7a * arm64-v8a * x86 diff --git a/ffmpeg-android-maker.sh b/ffmpeg-android-maker.sh index ab35c2f..4d7d377 100755 --- a/ffmpeg-android-maker.sh +++ b/ffmpeg-android-maker.sh @@ -96,67 +96,78 @@ function ensureSources() { esac } -# Actual magic of configuring and compiling of FFmpeg for a certain architecture. -# Supported architectures are: armeabi-v7a, arm64-v8a, x86 and x86_64 +# Actual magic of configuring and compiling of FFmpeg for a certain ABIs. +# Supported ABIs are: armeabi-v7a, arm64-v8a, x86 and x86_64 function assemble() { cd ${FFMPEG_SOURCES} - ARCH=$1 + ABI=$1 API_LEVEL=$2 TOOLCHAIN_PATH=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${HOST_TAG} SYSROOT=${TOOLCHAIN_PATH}/sysroot - CC_ANDROID_POSTFIX= EXTRA_CFLAGS= EXTRA_CONFIGURE_FLAGS= - case $ARCH in + TARGET_TRIPLE_MACHINE_BINUTILS= + TARGET_TRIPLE_MACHINE_CC= + TARGET_TRIPLE_OS="android" + + case $ABI in armeabi-v7a) - FFMPEG_ARCH_FLAG=arm - CROSS_PREFIX=arm-linux-androideabi- - CC_PREFIX=armv7a - CC_ANDROID_POSTFIX=eabi + #cc armv7a-linux-androideabi16-clang + #binutils arm -linux-androideabi -ld + TARGET_TRIPLE_MACHINE_BINUTILS=arm + TARGET_TRIPLE_MACHINE_CC=armv7a + TARGET_TRIPLE_OS=androideabi ;; - arm64-v8a) - FFMPEG_ARCH_FLAG=aarch64 - CROSS_PREFIX=aarch64-linux-android- - CC_PREFIX=aarch64 + arm64-v8a) + #cc aarch64-linux-android21-clang + #binutils aarch64-linux-android -ld + TARGET_TRIPLE_MACHINE_BINUTILS=aarch64 ;; x86) - FFMPEG_ARCH_FLAG=x86 - CROSS_PREFIX=i686-linux-android- - CC_PREFIX=i686 + #cc i686-linux-android16-clang + #binutils i686-linux-android -ld + TARGET_TRIPLE_MACHINE_BINUTILS=i686 + EXTRA_CFLAGS=-mno-stackrealign EXTRA_CONFIGURE_FLAGS=--disable-asm ;; x86_64) - FFMPEG_ARCH_FLAG=x86_64 - CROSS_PREFIX=x86_64-linux-android- - CC_PREFIX=x86_64 + #cc x86_64-linux-android21-clang + #binutils x86_64-linux-android -ld + TARGET_TRIPLE_MACHINE_BINUTILS=x86_64 + EXTRA_CONFIGURE_FLAGS=--x86asmexe=${TOOLCHAIN_PATH}/bin/yasm ;; esac - CC=${TOOLCHAIN_PATH}/bin/${CC_PREFIX}-linux-android${CC_ANDROID_POSTFIX}${API_LEVEL}-clang + # If the cc-specific variable isn't set, we fallback to binutils version + [ -z "${TARGET_TRIPLE_MACHINE_CC}" ] && TARGET_TRIPLE_MACHINE_CC=${TARGET_TRIPLE_MACHINE_BINUTILS} + + CROSS_PREFIX=${TOOLCHAIN_PATH}/bin/${TARGET_TRIPLE_MACHINE_BINUTILS}-linux-${TARGET_TRIPLE_OS}- + + CC=${TOOLCHAIN_PATH}/bin/${TARGET_TRIPLE_MACHINE_CC}-linux-${TARGET_TRIPLE_OS}${API_LEVEL}-clang DECODERS_TO_ENABLE= while IFS= read -r line; do DECODERS_TO_ENABLE="${DECODERS_TO_ENABLE} --enable-decoder=$line"; done < ${BASE_DIR}/video_decoders_list.txt ./configure \ - --prefix=${BUILD_DIR}/${ARCH} \ - --disable-doc \ + --prefix=${BUILD_DIR}/${ABI} \ --enable-cross-compile \ - --cross-prefix=${TOOLCHAIN_PATH}/bin/${CROSS_PREFIX} \ + --cross-prefix=${CROSS_PREFIX} \ + --arch=${TARGET_TRIPLE_MACHINE_BINUTILS} \ --target-os=android \ --cc=${CC} \ - --arch=${FFMPEG_ARCH_FLAG} \ --extra-cflags="-O3 -fPIC $EXTRA_CFLAGS" \ --sysroot=${SYSROOT} \ --enable-shared \ --disable-static \ - --disable-debug \ + --disable-doc \ --disable-runtime-cpudetect \ + --disable-debug \ --disable-programs \ --disable-muxers \ --disable-encoders \ @@ -177,7 +188,7 @@ function assemble() { # Saving stats about text relocation presence. # If the result file doesn't have 'TEXTREL' at all, then we are good. - ${TOOLCHAIN_PATH}/bin/${CROSS_PREFIX}readelf --dynamic ${BUILD_DIR}/${ARCH}/lib/*.so | grep 'TEXTREL\|File' >> ${STATS_DIR}/text-relocations.txt + ${CROSS_PREFIX}readelf --dynamic ${BUILD_DIR}/${ABI}/lib/*.so | grep 'TEXTREL\|File' >> ${STATS_DIR}/text-relocations.txt cd ${BASE_DIR} } @@ -194,16 +205,16 @@ function installLibs() { } function build() { - ARCH=$1 + ABI=$1 ANDROID_API=$2 - assemble ${ARCH} ${ANDROID_API} - installLibs ${ARCH} + assemble ${ABI} ${ANDROID_API} + installLibs ${ABI} } -# Placing build header files into the /bin directory -# Note, there is a only one such a folder since this headers are the same for all architectures -# May not be true for different configurations though +# Placing build header files into the /bin directory. +# Note, there is a only one such a folder since this headers are the same for all ABIs. +# May not be true for different configurations though. function installHeaders() { cd ${BUILD_DIR} cd "$(ls -1 | head -n1)"