| 6 |
| # |
| 7 | # Runs for every ABI in $ABIS when no argument is given. See build_common.sh |
| 8 | # for the shared options (API, NDK_VERSION, CLEAN, JOBS, ...). |
| 9 |
| 10 | source "$(dirname -- "${BASH_SOURCE[0]}")/build_common.sh" |
| 11 |
| 12 | # --------------------------------------------------------------------------- |
| 13 | # Component options. Defaults reproduce the reference build in |
| 14 | # ../ffmpeg/build_ffmpeg_libvpx_dav1d_android_ndk27_merged.sh. |
| 15 | # --------------------------------------------------------------------------- |
| 16 | LIBVPX_REALTIME_ONLY="${LIBVPX_REALTIME_ONLY:-1}" |
| 17 | LIBVPX_SMALL="${LIBVPX_SMALL:-1}" |
| 18 | LIBVPX_BETTER_HW_COMPATIBILITY="${LIBVPX_BETTER_HW_COMPATIBILITY:-1}" |
| 19 | LIBVPX_WEBM_IO="${LIBVPX_WEBM_IO:-0}" |
| 20 |
| 21 | # auto = enabled for x86/x86_64, disabled for ARM. |
| 22 | LIBVPX_RUNTIME_CPU_DETECT="${LIBVPX_RUNTIME_CPU_DETECT:-auto}" |
| 23 |
| 24 | # AArch64 ISA extension kernels (dotprod / i8mm / SVE / SVE2). Off by default; |
| 25 | # turning them on trades ~150 KB for faster VP9 decode on modern SoCs. |
| 26 | LIBVPX_ARM_EXTENSIONS="${LIBVPX_ARM_EXTENSIONS:-0}" |
| 27 |
| 28 | # Decoder input size guard. Set to an empty value to remove the limit. |
| 29 | LIBVPX_SIZE_LIMIT="${LIBVPX_SIZE_LIMIT:-4096x4096}" |
| 30 |
| 31 | require_bool LIBVPX_REALTIME_ONLY "$LIBVPX_REALTIME_ONLY" |
| 32 | require_bool LIBVPX_SMALL "$LIBVPX_SMALL" |
| 33 | require_bool LIBVPX_BETTER_HW_COMPATIBILITY "$LIBVPX_BETTER_HW_COMPATIBILITY" |
| 34 | require_bool LIBVPX_WEBM_IO "$LIBVPX_WEBM_IO" |
| 35 | require_bool LIBVPX_ARM_EXTENSIONS "$LIBVPX_ARM_EXTENSIONS" |
| 36 | require_toggle LIBVPX_RUNTIME_CPU_DETECT "$LIBVPX_RUNTIME_CPU_DETECT" |
| 37 |
| 38 | [[ -f "$LIBVPX_SOURCE_DIR/configure" ]] || die "libvpx sources were not found in: $LIBVPX_SOURCE_DIR |
| 39 | Run: git submodule update --init TMessagesProj/jni/third_party/libvpx" |
| 40 | LIBVPX_SOURCE_DIR="$(cd "$LIBVPX_SOURCE_DIR" && pwd)" |
| 41 |
| 42 | # libvpx renames and removes configure toggles between releases (neon_i8mm, |
| 43 | # sve and sve2 do not exist before 1.15; neon_asm is ARM-only). Probe the |
| 44 | # option list instead of failing on an unknown flag. |
| 45 | libvpx_has_option() { |
| 46 | grep -qE "^[[:space:]]*$1[[:space:]]*$" "$LIBVPX_SOURCE_DIR/configure" |
| 47 | } |
| 48 |
| 49 | # usage: libvpx_toggle <array-name> <underscored_option> <0|1> |
| 50 | libvpx_toggle() { |
| 51 | local -n destination="$1" |
| 52 | local option="$2" enable="$3" |
| 53 | libvpx_has_option "$option" || return 0 |
| 54 | if [[ "$enable" == "1" ]]; then |
| 55 | destination+=("--enable-${option//_/-}") |
| 56 | else |
| 57 | destination+=("--disable-${option//_/-}") |
| 58 | fi |
| 59 | } |
| 60 |
| 61 | build_libvpx_for_abi() { |
| 62 | local abi="$1" |
| 63 | local target vpx_target extra_cflags |
| 64 |
| 65 | target="$(abi_triple "$abi")" |
| 66 | case "$abi" in |
| 67 | arm64-v8a) |
| 68 | vpx_target="arm64-android-gcc" |
| 69 | extra_cflags="-O3 -fPIC -march=armv8-a" |
| 70 | ;; |
| 71 | armeabi-v7a) |
| 72 | vpx_target="armv7-android-gcc" |
| 73 | extra_cflags="-O3 -fPIC -march=armv7-a -mfloat-abi=softfp -mfpu=neon" |
| 74 | ;; |
| 75 | x86_64) |
| 76 | vpx_target="x86_64-android-gcc" |
| 77 | extra_cflags="-O3 -fPIC -march=x86-64" |
| 78 | ;; |
| 79 | x86) |
| 80 | vpx_target="x86-android-gcc" |
| 81 | extra_cflags="-O3 -fPIC -march=i686 -mssse3 -mfpmath=sse" |
| 82 | ;; |
| 83 | *) error "Unsupported ABI: $abi"; return 1 ;; |
| 84 | esac |
| 85 |
| 86 | extra_cflags="$extra_cflags${LIBVPX_COMMON_CFLAGS:+ $LIBVPX_COMMON_CFLAGS}" |
| 87 |
| 88 | check_x86_assembler "$abi" || return 1 |
| 89 |
| 90 | local prefix="$LIBVPX_OUTPUT_DIR/$abi" |
| 91 | local build_dir="$LIBVPX_WORK_DIR/$abi" |
| 92 | local cc cxx |
| 93 | cc="$(clang_driver "$target" clang)" |
| 94 | cxx="$(clang_driver "$target" clang++)" |
| 95 |
| 96 | if [[ "$CLEAN" == "1" ]]; then |
| 97 | rm -rf "$build_dir" "$prefix" |
| 98 | fi |
| 99 | mkdir -p "$build_dir" "$prefix" |
| 100 |
| 101 | echo |
| 102 | echo "========== libvpx: $abi, API $API ==========" |
| 103 |
| 104 | local -a configure_env=( |
| 105 | "CC=$cc" |
| 106 | "CXX=$cxx" |
| 107 | "LD=$cc" |
| 108 | "AR=$AR_BIN" |
| 109 | "ARFLAGS=crsD" |
| 110 | "NM=$NM_BIN" |
| 111 | "STRIP=$STRIP_BIN" |
| 112 | ) |
| 113 |
| 114 | # ARM .S goes through the clang integrated assembler. x86 .asm must be |
| 115 | # handled by NASM/Yasm, which libvpx's configure detects on its own. |
| 116 | if [[ "$abi" == "arm64-v8a" || "$abi" == "armeabi-v7a" ]]; then |
| 117 | configure_env+=("AS=$cc") |
| 118 | fi |
| 119 |
| 120 | local -a vpx_args=( |
| 121 | --target="$vpx_target" |
| 122 | --prefix="$prefix" |
| 123 | --disable-shared |
| 124 | --enable-static |
| 125 | --enable-pic |
| 126 | --enable-optimizations |
| 127 | --enable-multithread |
| 128 | --disable-examples |
| 129 | --disable-tools |
| 130 | --disable-docs |
| 131 | --disable-unit-tests |
| 132 | --disable-install-bins |
| 133 | --disable-install-docs |
| 134 | --disable-debug |
| 135 | --enable-vp8 |
| 136 | --enable-vp9 |
| 137 | --enable-vp8-decoder |
| 138 | --enable-vp8-encoder |
| 139 | --enable-vp9-decoder |
| 140 | --enable-vp9-encoder |
| 141 | ) |
| 142 |
| 143 | local runtime_cpu_detect="$LIBVPX_RUNTIME_CPU_DETECT" |
| 144 | if [[ "$runtime_cpu_detect" == "auto" ]]; then |
| 145 | case "$abi" in |
| 146 | x86|x86_64) runtime_cpu_detect="on" ;; |
| 147 | *) runtime_cpu_detect="off" ;; |
| 148 | esac |
| 149 | fi |
| 150 | if [[ "$runtime_cpu_detect" == "on" ]]; then |
| 151 | vpx_args+=(--enable-runtime-cpu-detect) |
| 152 | else |
| 153 | vpx_args+=(--disable-runtime-cpu-detect) |
| 154 | fi |
| 155 |
| 156 | libvpx_toggle vpx_args realtime_only "$LIBVPX_REALTIME_ONLY" |
| 157 | libvpx_toggle vpx_args small "$LIBVPX_SMALL" |
| 158 | libvpx_toggle vpx_args better_hw_compatibility "$LIBVPX_BETTER_HW_COMPATIBILITY" |
| 159 | libvpx_toggle vpx_args webm_io "$LIBVPX_WEBM_IO" |
| 160 |
| 161 | case "$abi" in |
| 162 | armeabi-v7a) |
| 163 | libvpx_toggle vpx_args neon_asm 0 |
| 164 | ;; |
| 165 | arm64-v8a) |
| 166 | libvpx_toggle vpx_args neon_asm 0 |
| 167 | libvpx_toggle vpx_args neon_dotprod "$LIBVPX_ARM_EXTENSIONS" |
| 168 | libvpx_toggle vpx_args neon_i8mm "$LIBVPX_ARM_EXTENSIONS" |
| 169 | libvpx_toggle vpx_args sve "$LIBVPX_ARM_EXTENSIONS" |
| 170 | libvpx_toggle vpx_args sve2 "$LIBVPX_ARM_EXTENSIONS" |
| 171 | ;; |
| 172 | esac |
| 173 |
| 174 | [[ -n "$LIBVPX_SIZE_LIMIT" ]] && vpx_args+=(--size-limit="$LIBVPX_SIZE_LIMIT") |
| 175 |
| 176 | vpx_args+=( |
| 177 | --extra-cflags="$extra_cflags" |
| 178 | --log="$build_dir/config.log" |
| 179 | ) |
| 180 |
| 181 | pushd "$build_dir" >/dev/null |
| 182 |
| 183 | # AS/ASFLAGS inherited from the environment would override the per-ABI |
| 184 | # choice made above. |
| 185 | if ! env -u AS -u ASFLAGS "${configure_env[@]}" \ |
| 186 | "$LIBVPX_SOURCE_DIR/configure" "${vpx_args[@]}" |
| 187 | then |
| 188 | error "libvpx configure failed for $abi. Log: $build_dir/config.log" |
| 189 | popd >/dev/null |
| 190 | return 1 |
| 191 | fi |
| 192 |
| 193 | # `%.a: %_g.a` runs `$(STRIP) --strip-debug`, which zeroes sh_link on |
| 194 | # SHT_LLVM_ADDRSIG and makes lld reject the table under --icf=safe. |
| 195 | # Degrade the rule to a plain copy so the table stays usable. |
| 196 | if [[ "$LIBVPX_SKIP_STRIP" == "1" && -f "$build_dir/config.mk" ]]; then |
| 197 | if grep -q '^HAVE_GNU_STRIP=' "$build_dir/config.mk"; then |
| 198 | sed -i.bak 's/^HAVE_GNU_STRIP=.*/HAVE_GNU_STRIP=no/' "$build_dir/config.mk" |
| 199 | rm -f "$build_dir/config.mk.bak" |
| 200 | else |
| 201 | echo 'HAVE_GNU_STRIP=no' >> "$build_dir/config.mk" |
| 202 | fi |
| 203 | fi |
| 204 |
| 205 | if ! make -j"$JOBS" 2>&1 | tee "$build_dir/build.log"; then |
| 206 | error "libvpx build failed for $abi. Log: $build_dir/build.log" |
| 207 | popd >/dev/null |
| 208 | return 1 |
| 209 | fi |
| 210 |
| 211 | if ! make install 2>&1 | tee "$build_dir/install.log"; then |
| 212 | error "libvpx install failed for $abi. Log: $build_dir/install.log" |
| 213 | popd >/dev/null |
| 214 | return 1 |
| 215 | fi |
| 216 |
| 217 | popd >/dev/null |
| 218 |
| 219 | [[ -f "$prefix/lib/libvpx.a" ]] || { error "Missing $prefix/lib/libvpx.a"; return 1; } |
| 220 | [[ -d "$prefix/include/vpx" ]] || { error "Missing $prefix/include/vpx"; return 1; } |
| 221 | [[ -f "$prefix/lib/pkgconfig/vpx.pc" ]] || { error "Missing vpx.pc for $abi"; return 1; } |
| 222 |
| 223 | # WebRTC links directly against both VP8 and VP9 encoder/decoder interfaces. |
| 224 | local symbol |
| 225 | for symbol in \ |
| 226 | vpx_codec_vp8_cx \ |
| 227 | vpx_codec_vp8_dx \ |
| 228 | vpx_codec_vp9_cx \ |
| 229 | vpx_codec_vp9_dx |
| 230 | do |
| 231 | if ! "$NM_BIN" -g --defined-only "$prefix/lib/libvpx.a" \ |
| 232 | | grep -E "[[:space:]]${symbol}$" >/dev/null; |
| 233 | then |
| 234 | error "Missing libvpx symbol for $abi: $symbol" |
| 235 | return 1 |
| 236 | fi |
| 237 | done |
| 238 | } |
| 239 |
| 240 | TARGET_ABIS="${*:-$ABIS}" |
| 241 |
| 242 | mkdir -p "$LIBVPX_WORK_DIR" "$LIBVPX_OUTPUT_DIR" |
| 243 |
| 244 | for abi in $TARGET_ABIS; do |
| 245 | build_libvpx_for_abi "$abi" |
| 246 | done |
| 247 |
| 248 | echo |
| 249 | echo "libvpx install: $LIBVPX_OUTPUT_DIR/<ABI>" |
| 250 |