| 6 | # jni/prebuild/lib/<ABI>/libvpx.a |
| 7 | # jni/prebuild/lib/<ABI>/libdav1d.a |
| 8 | # jni/prebuild/lib/<ABI>/libopus.a |
| 9 | # jni/prebuild/pkgconfig/<ABI>/{vpx,dav1d}.pc |
| 10 | # source headers from jni/third_party/{libvpx,dav1d,xiph/opus,ffmpeg} |
| 11 | # generated/ABI headers overlay from jni/prebuild/include/<ABI> |
| 12 | # local patches from jni/prebuild/patches/ffmpeg/*.patch, applied to a private |
| 13 | # copy of the sources so the submodule stays a clean upstream commit |
| 14 | # |
| 15 | # Output: |
| 16 | # jni/prebuild/lib/<ABI>/libavcodec.a |
| 17 | # jni/prebuild/lib/<ABI>/libavformat.a |
| 18 | # jni/prebuild/lib/<ABI>/libavutil.a |
| 19 | # jni/prebuild/lib/<ABI>/libswscale.a |
| 20 | # jni/prebuild/lib/<ABI>/libswresample.a |
| 21 | # generated/ABI-dependent FFmpeg public headers under jni/prebuild/include/<ABI>/ |
| 22 |
| 23 | set -Eeuo pipefail |
| 24 |
| 25 | export SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-946684800}" |
| 26 | export TZ=UTC |
| 27 | export LC_ALL=C |
| 28 | export LANG=C |
| 29 | export PYTHONHASHSEED=0 |
| 30 | export ZERO_AR_DATE=1 |
| 31 | umask 022 |
| 32 |
| 33 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 34 | source "$SCRIPT_DIR/common.sh" |
| 35 |
| 36 | # The merged media build supplied its own exact flags to FFmpeg configure. |
| 37 | unset CFLAGS CXXFLAGS |
| 38 |
| 39 | require_ndk |
| 40 | require_command make |
| 41 | require_command pkg-config |
| 42 | require_command patch |
| 43 |
| 44 | PROJECT_ROOT="$JNI_DIR" |
| 45 | FFMPEG_SOURCE_DIR="${FFMPEG_SOURCE_DIR:-$JNI_DIR/third_party/ffmpeg}" |
| 46 | FFMPEG_PATCH_DIR="${FFMPEG_PATCH_DIR:-$SCRIPT_DIR/patches/ffmpeg}" |
| 47 | LIBVPX_SOURCE_DIR="${LIBVPX_SOURCE_DIR:-$JNI_DIR/third_party/libvpx}" |
| 48 | DAV1D_SOURCE_DIR="${DAV1D_SOURCE_DIR:-$JNI_DIR/third_party/dav1d}" |
| 49 | OPUS_SOURCE_DIR="${OPUS_SOURCE_DIR:-$JNI_DIR/third_party/xiph/opus}" |
| 50 | BUILD_ROOT="${FFMPEG_BUILD_ROOT:-$SCRIPT_DIR/build/ffmpeg}" |
| 51 | WORK_DIR="$BUILD_ROOT/work" |
| 52 | INSTALL_DIR="$BUILD_ROOT/install" |
| 53 |
| 54 | ENABLE_SMALL="${ENABLE_SMALL:-1}" |
| 55 | FFMPEG_OPTFLAGS="${FFMPEG_OPTFLAGS:-}" |
| 56 | FFMPEG_LIBVPX_VP8="${FFMPEG_LIBVPX_VP8:-1}" |
| 57 | FFMPEG_PARSERS="${FFMPEG_PARSERS:-1}" |
| 58 |
| 59 | UNWIND_TABLES="${UNWIND_TABLES:-0}" |
| 60 | FRAME_POINTERS="${FRAME_POINTERS:-0}" |
| 61 | FUNCTION_SECTIONS="${FUNCTION_SECTIONS:-1}" |
| 62 | ADDRSIG="${ADDRSIG:-1}" |
| 63 | HIDDEN_VISIBILITY="${HIDDEN_VISIBILITY:-0}" |
| 64 |
| 65 | FFMPEG_RUNTIME_CPUDETECT="${FFMPEG_RUNTIME_CPUDETECT:-on}" |
| 66 | FFMPEG_MMX="${FFMPEG_MMX:-auto}" |
| 67 | FFMPEG_MMXEXT="${FFMPEG_MMXEXT:-auto}" |
| 68 | FFMPEG_SSE="${FFMPEG_SSE:-auto}" |
| 69 | FFMPEG_SSE2="${FFMPEG_SSE2:-auto}" |
| 70 | FFMPEG_SSE3="${FFMPEG_SSE3:-auto}" |
| 71 | FFMPEG_SSSE3="${FFMPEG_SSSE3:-auto}" |
| 72 | FFMPEG_SSE4="${FFMPEG_SSE4:-auto}" |
| 73 | FFMPEG_SSE42="${FFMPEG_SSE42:-auto}" |
| 74 | FFMPEG_AVX="${FFMPEG_AVX:-off}" |
| 75 | FFMPEG_AVX2="${FFMPEG_AVX2:-auto}" |
| 76 | FFMPEG_AVX512="${FFMPEG_AVX512:-auto}" |
| 77 | FFMPEG_FMA3="${FFMPEG_FMA3:-auto}" |
| 78 | FFMPEG_FMA4="${FFMPEG_FMA4:-auto}" |
| 79 | FFMPEG_BMI1="${FFMPEG_BMI1:-auto}" |
| 80 | FFMPEG_BMI2="${FFMPEG_BMI2:-auto}" |
| 81 | FFMPEG_X86_64_MMX="${FFMPEG_X86_64_MMX:-off}" |
| 82 | FFMPEG_X86_64_INLINE_ASM="${FFMPEG_X86_64_INLINE_ASM:-off}" |
| 83 | FFMPEG_X86_64_X86ASM="${FFMPEG_X86_64_X86ASM:-auto}" |
| 84 | FFMPEG_X86_MMX="${FFMPEG_X86_MMX:-off}" |
| 85 | FFMPEG_X86_INLINE_ASM="${FFMPEG_X86_INLINE_ASM:-off}" |
| 86 | FFMPEG_X86_X86ASM="${FFMPEG_X86_X86ASM:-off}" |
| 87 | FFMPEG_X86_64_EXTRA_ISA_CFLAGS="${FFMPEG_X86_64_EXTRA_ISA_CFLAGS:-}" |
| 88 | FFMPEG_X86_EXTRA_ISA_CFLAGS="${FFMPEG_X86_EXTRA_ISA_CFLAGS:-}" |
| 89 |
| 90 | error() { echo "ERROR: $*" >&2; } |
| 91 |
| 92 | require_bool() { |
| 93 | local name="$1" value="$2" |
| 94 | if [[ "$value" != "0" && "$value" != "1" ]]; then |
| 95 | error "$name must be 0 or 1, got: $value" |
| 96 | exit 1 |
| 97 | fi |
| 98 | } |
| 99 |
| 100 | require_toggle() { |
| 101 | local name="$1" value="$2" |
| 102 | case "$value" in |
| 103 | auto|on|off) ;; |
| 104 | *) error "$name must be auto, on or off, got: $value"; exit 1 ;; |
| 105 | esac |
| 106 | } |
| 107 |
| 108 | # Bash 3.2 compatible; configure_args is dynamically scoped by build_ffmpeg_for_abi. |
| 109 | append_configure_toggle() { |
| 110 | local feature="$1" value="$2" |
| 111 | case "$value" in |
| 112 | auto) ;; |
| 113 | on) configure_args+=("--enable-$feature") ;; |
| 114 | off) configure_args+=("--disable-$feature") ;; |
| 115 | esac |
| 116 | } |
| 117 |
| 118 | for name in ENABLE_SMALL FFMPEG_LIBVPX_VP8 FFMPEG_PARSERS UNWIND_TABLES FRAME_POINTERS FUNCTION_SECTIONS ADDRSIG HIDDEN_VISIBILITY; do |
| 119 | require_bool "$name" "${!name}" |
| 120 | done |
| 121 | for name in \ |
| 122 | FFMPEG_RUNTIME_CPUDETECT FFMPEG_MMX FFMPEG_MMXEXT FFMPEG_SSE \ |
| 123 | FFMPEG_SSE2 FFMPEG_SSE3 FFMPEG_SSSE3 FFMPEG_SSE4 FFMPEG_SSE42 \ |
| 124 | FFMPEG_AVX FFMPEG_AVX2 FFMPEG_AVX512 FFMPEG_FMA3 FFMPEG_FMA4 \ |
| 125 | FFMPEG_BMI1 FFMPEG_BMI2 FFMPEG_X86_64_MMX FFMPEG_X86_64_INLINE_ASM \ |
| 126 | FFMPEG_X86_64_X86ASM FFMPEG_X86_MMX FFMPEG_X86_INLINE_ASM FFMPEG_X86_X86ASM |
| 127 | do |
| 128 | require_toggle "$name" "${!name}" |
| 129 | done |
| 130 |
| 131 | [[ -x "$FFMPEG_SOURCE_DIR/configure" ]] || { error "FFmpeg sources were not found in: $FFMPEG_SOURCE_DIR"; exit 1; } |
| 132 | [[ -d "$LIBVPX_SOURCE_DIR/vpx" ]] || { error "libvpx headers were not found in: $LIBVPX_SOURCE_DIR/vpx"; exit 1; } |
| 133 | [[ -f "$DAV1D_SOURCE_DIR/include/dav1d/dav1d.h" ]] || { error "dav1d headers were not found in: $DAV1D_SOURCE_DIR/include"; exit 1; } |
| 134 | [[ -f "$OPUS_SOURCE_DIR/include/opus_multistream.h" ]] || { error "Opus headers were not found in: $OPUS_SOURCE_DIR/include"; exit 1; } |
| 135 | FFMPEG_SOURCE_DIR="$(cd "$FFMPEG_SOURCE_DIR" && pwd)" |
| 136 | LIBVPX_SOURCE_DIR="$(cd "$LIBVPX_SOURCE_DIR" && pwd)" |
| 137 | DAV1D_SOURCE_DIR="$(cd "$DAV1D_SOURCE_DIR" && pwd)" |
| 138 | OPUS_SOURCE_DIR="$(cd "$OPUS_SOURCE_DIR" && pwd)" |
| 139 |
| 140 | check_x86_assembler() { |
| 141 | local abi="$1" |
| 142 | if [[ "$abi" == "x86" || "$abi" == "x86_64" ]]; then |
| 143 | if ! command -v nasm >/dev/null 2>&1 && ! command -v yasm >/dev/null 2>&1; then |
| 144 | error "NASM or Yasm is required for $abi." |
| 145 | return 1 |
| 146 | fi |
| 147 | fi |
| 148 | } |
| 149 |
| 150 | COMMON_CFLAGS_BASE="" |
| 151 | COMMON_CFLAGS_BASE+=" -ffile-prefix-map=$PROJECT_ROOT=/src" |
| 152 | COMMON_CFLAGS_BASE+=" -fdebug-prefix-map=$PROJECT_ROOT=/src" |
| 153 | COMMON_CFLAGS_BASE+=" -fmacro-prefix-map=$PROJECT_ROOT=/src" |
| 154 | COMMON_CFLAGS_BASE+=" -ffile-prefix-map=$BUILD_ROOT=/build" |
| 155 | COMMON_CFLAGS_BASE+=" -fdebug-prefix-map=$BUILD_ROOT=/build" |
| 156 | COMMON_CFLAGS_BASE+=" -fmacro-prefix-map=$BUILD_ROOT=/build" |
| 157 | COMMON_CFLAGS_BASE+=" -fdebug-compilation-dir=." |
| 158 | [[ "$FUNCTION_SECTIONS" == "1" ]] && COMMON_CFLAGS_BASE+=" -ffunction-sections -fdata-sections" |
| 159 | [[ "$HIDDEN_VISIBILITY" == "1" ]] && COMMON_CFLAGS_BASE+=" -fvisibility=hidden" |
| 160 | [[ "$UNWIND_TABLES" == "0" ]] && COMMON_CFLAGS_BASE+=" -fno-asynchronous-unwind-tables -fno-unwind-tables" |
| 161 | if [[ "$FRAME_POINTERS" == "1" ]]; then |
| 162 | COMMON_CFLAGS_BASE+=" -fno-omit-frame-pointer" |
| 163 | else |
| 164 | COMMON_CFLAGS_BASE+=" -fomit-frame-pointer" |
| 165 | fi |
| 166 | COMMON_CFLAGS_BASE+=" -g0 -fno-ident" |
| 167 | COMMON_CFLAGS_BASE="${COMMON_CFLAGS_BASE# }" |
| 168 | COMMON_CFLAGS="$COMMON_CFLAGS_BASE" |
| 169 | [[ "$ADDRSIG" == "1" ]] && COMMON_CFLAGS+=" -faddrsig" |
| 170 |
| 171 | # A patch that no longer applies fails the build: it is either merged upstream |
| 172 | # (delete it) or has to be refreshed against the new pin. |
| 173 | prepare_patched_source() { |
| 174 | local source_dir="$1" destination="$2" |
| 175 | local version patch_file patch_count=0 |
| 176 |
| 177 | version="$(git -C "$source_dir" describe --tags --always 2>/dev/null || cat "$source_dir/RELEASE")" |
| 178 | mkdir -p "$destination" |
| 179 | tar -C "$source_dir" --exclude=.git -cf - . | tar -C "$destination" -xf - |
| 180 |
| 181 | for patch_file in "$FFMPEG_PATCH_DIR"/*.patch; do |
| 182 | [[ -f "$patch_file" ]] || continue |
| 183 | echo "==> Applying $(basename "$patch_file")" |
| 184 | if ! patch -d "$destination" -p1 -N -F0 -s -i "$patch_file"; then |
| 185 | error "FFmpeg patch does not apply: $patch_file" |
| 186 | return 1 |
| 187 | fi |
| 188 | patch_count=$((patch_count + 1)) |
| 189 | done |
| 190 |
| 191 | # The copy has no .git, and version.sh would otherwise describe this repository. |
| 192 | [[ "$patch_count" == "0" ]] || version+="-tg$patch_count" |
| 193 | printf '%s\n' "$version" > "$destination/VERSION" |
| 194 | } |
| 195 |
| 196 | write_opus_pkgconfig() { |
| 197 | local abi="$1" destination_dir="$2" |
| 198 | local opus_prefix opus_headers |
| 199 | opus_prefix="$(abi_output_dir "$abi")" |
| 200 | opus_headers="$OPUS_SOURCE_DIR/include" |
| 201 | mkdir -p "$destination_dir" |
| 202 | cat > "$destination_dir/opus.pc" <<PC |
| 203 | libdir=$opus_prefix |
| 204 | includedir=$opus_headers |
| 205 | Name: Opus |
| 206 | Description: Opus IETF audio codec (prebuilt static) |
| 207 | Version: 1.6.1 |
| 208 | Libs: -L\${libdir} -lopus |
| 209 | Libs.private: -lm |
| 210 | Cflags: -I\${includedir} |
| 211 | PC |
| 212 | } |
| 213 |
| 214 | copy_generated_header_overlay() { |
| 215 | local abi="$1" prefix="$2" |
| 216 | local installed_root="$prefix/include" |
| 217 | local destination_root |
| 218 | destination_root="$(abi_include_dir "$abi")" |
| 219 |
| 220 | local installed relative source destination copied=0 |
| 221 | while IFS= read -r -d '' installed; do |
| 222 | relative="${installed#$installed_root/}" |
| 223 | source="$FFMPEG_SOURCE_DIR/$relative" |
| 224 | if [[ -f "$source" ]] && cmp -s "$source" "$installed"; then |
| 225 | continue |
| 226 | fi |
| 227 | destination="$destination_root/$relative" |
| 228 | mkdir -p "$(dirname "$destination")" |
| 229 | cp -f "$installed" "$destination" |
| 230 | chmod 0644 "$destination" |
| 231 | copied=$((copied + 1)) |
| 232 | echo "==> generated/ABI header: $destination" |
| 233 | done < <(find "$installed_root" -type f -name '*.h' -print0) |
| 234 |
| 235 | if [[ "$copied" == "0" ]]; then |
| 236 | echo "==> FFmpeg $abi: no generated/ABI-dependent public headers" |
| 237 | fi |
| 238 | } |
| 239 |
| 240 | build_ffmpeg_for_abi() { |
| 241 | local abi="$1" |
| 242 | local arch target cpu extra_cflags prefix build_dir cc cxx |
| 243 | local vpx_archive dav1d_archive opus_archive dependency_pc_dir opus_pc_dir overlay |
| 244 | local components_header enabled_av1_decoders component library destination |
| 245 | local -a configure_env=() |
| 246 | local -a configure_args=() |
| 247 | local -a required_components=() |
| 248 |
| 249 | case "$abi" in |
| 250 | arm64-v8a) |
| 251 | arch="aarch64"; target="aarch64-linux-android"; cpu="armv8-a"; extra_cflags="-march=armv8-a" |
| 252 | ;; |
| 253 | armeabi-v7a) |
| 254 | arch="arm"; target="armv7a-linux-androideabi"; cpu="armv7-a"; extra_cflags="-march=armv7-a -mfloat-abi=softfp -mfpu=neon" |
| 255 | ;; |
| 256 | x86_64) |
| 257 | arch="x86_64"; target="x86_64-linux-android"; cpu="x86-64" |
| 258 | extra_cflags="-march=x86-64${FFMPEG_X86_64_EXTRA_ISA_CFLAGS:+ $FFMPEG_X86_64_EXTRA_ISA_CFLAGS}" |
| 259 | ;; |
| 260 | x86) |
| 261 | arch="x86"; target="i686-linux-android"; cpu="i686" |
| 262 | extra_cflags="-march=i686${FFMPEG_X86_EXTRA_ISA_CFLAGS:+ $FFMPEG_X86_EXTRA_ISA_CFLAGS}" |
| 263 | ;; |
| 264 | *) error "Unsupported ABI: $abi"; return 1 ;; |
| 265 | esac |
| 266 |
| 267 | check_x86_assembler "$abi" |
| 268 |
| 269 | vpx_archive="$(abi_output_dir "$abi")/libvpx.a" |
| 270 | dav1d_archive="$(abi_output_dir "$abi")/libdav1d.a" |
| 271 | opus_archive="$(abi_output_dir "$abi")/libopus.a" |
| 272 | dependency_pc_dir="$(abi_pkgconfig_dir "$abi")" |
| 273 | overlay="$(abi_include_dir "$abi")" |
| 274 | opus_pc_dir="$WORK_DIR/opus-pkgconfig/$abi" |
| 275 |
| 276 | [[ -f "$vpx_archive" ]] || { error "Missing libvpx for $abi: $vpx_archive (run build_libvpx.sh first)"; return 1; } |
| 277 | [[ -f "$dav1d_archive" ]] || { error "Missing dav1d for $abi: $dav1d_archive (run build_dav1d.sh first)"; return 1; } |
| 278 | [[ -f "$opus_archive" ]] || { error "Missing Opus for $abi: $opus_archive (run build_opus.sh first)"; return 1; } |
| 279 | [[ -f "$dependency_pc_dir/vpx.pc" ]] || { error "Missing vpx.pc for $abi: $dependency_pc_dir/vpx.pc"; return 1; } |
| 280 | [[ -f "$dependency_pc_dir/dav1d.pc" ]] || { error "Missing dav1d.pc for $abi: $dependency_pc_dir/dav1d.pc"; return 1; } |
| 281 |
| 282 | write_opus_pkgconfig "$abi" "$opus_pc_dir" |
| 283 |
| 284 | prefix="$INSTALL_DIR/$abi" |
| 285 | build_dir="$WORK_DIR/$abi" |
| 286 | cc="$NDK_TOOLCHAIN/bin/${target}${API}-clang" |
| 287 | cxx="$NDK_TOOLCHAIN/bin/${target}${API}-clang++" |
| 288 | rm -rf "$build_dir" "$prefix" |
| 289 | mkdir -p "$build_dir" "$prefix" |
| 290 |
| 291 | configure_env=( |
| 292 | "PKG_CONFIG_PATH=$dependency_pc_dir:$opus_pc_dir${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" |
| 293 | "PKG_CONFIG_LIBDIR=$dependency_pc_dir:$opus_pc_dir" |
| 294 | "ARFLAGS=rcD" |
| 295 | ) |
| 296 |
| 297 | configure_args=( |
| 298 | --prefix="$prefix" |
| 299 | --target-os=android |
| 300 | --arch="$arch" |
| 301 | --cpu="$cpu" |
| 302 | --enable-cross-compile |
| 303 | --cc="$cc" |
| 304 | --cxx="$cxx" |
| 305 | --ar="$NDK_TOOLCHAIN/bin/llvm-ar" |
| 306 | --nm="$NDK_TOOLCHAIN/bin/llvm-nm" |
| 307 | --ranlib="$NDK_TOOLCHAIN/bin/llvm-ranlib" |
| 308 | --strip="$NDK_TOOLCHAIN/bin/llvm-strip" |
| 309 | --sysroot="$NDK_TOOLCHAIN/sysroot" |
| 310 | --enable-pic |
| 311 | --enable-static |
| 312 | --disable-shared |
| 313 | --enable-optimizations |
| 314 | --enable-pthreads |
| 315 | --disable-doc |
| 316 | --disable-debug |
| 317 | --disable-programs |
| 318 | --disable-avdevice |
| 319 | --disable-avfilter |
| 320 | --disable-network |
| 321 | --disable-autodetect |
| 322 | --disable-everything |
| 323 | --enable-avcodec |
| 324 | --enable-avformat |
| 325 | --enable-avutil |
| 326 | --enable-swscale |
| 327 | --enable-swresample |
| 328 | --enable-protocol=file |
| 329 | --enable-decoder=h264 |
| 330 | --enable-decoder=hevc |
| 331 | --enable-decoder=mpeg4 |
| 332 | --enable-decoder=mjpeg |
| 333 | --enable-decoder=gif |
| 334 | --enable-decoder=alac |
| 335 | --enable-decoder=libopus |
| 336 | --enable-decoder=mp3 |
| 337 | --enable-decoder=aac |
| 338 | --enable-decoder=flac |
| 339 | --enable-demuxer=mov |
| 340 | --enable-demuxer=gif |
| 341 | --enable-demuxer=ogg |
| 342 | --enable-demuxer=matroska |
| 343 | --enable-demuxer=mp3 |
| 344 | --enable-demuxer=aac |
| 345 | --enable-muxer=matroska |
| 346 | --enable-bsf=vp9_superframe |
| 347 | --enable-bsf=vp9_raw_reorder |
| 348 | --enable-libvpx |
| 349 | --enable-libdav1d |
| 350 | --enable-libopus |
| 351 | --enable-decoder=libdav1d |
| 352 | --enable-decoder=libvpx_vp9 |
| 353 | --enable-encoder=libvpx_vp9 |
| 354 | --pkg-config-flags=--static |
| 355 | --disable-zlib |
| 356 | "--extra-cflags=-fPIC -DANDROID $extra_cflags${COMMON_CFLAGS:+ $COMMON_CFLAGS} -I$overlay -I$LIBVPX_SOURCE_DIR -I$DAV1D_SOURCE_DIR/include -I$OPUS_SOURCE_DIR/include" |
| 357 | "--extra-ldflags=-Wl,-Bsymbolic -L$(abi_output_dir "$abi")" |
| 358 | "--extra-libs=-ldav1d -lvpx -lopus -lm -ldl" |
| 359 | ) |
| 360 |
| 361 | [[ -n "$FFMPEG_OPTFLAGS" ]] && configure_args+=("--optflags=$FFMPEG_OPTFLAGS") |
| 362 |
| 363 | if [[ "$FFMPEG_PARSERS" == "1" ]]; then |
| 364 | configure_args+=( |
| 365 | --enable-parser=h264 --enable-parser=hevc --enable-parser=mpeg4video |
| 366 | --enable-parser=mpegaudio --enable-parser=aac --enable-parser=opus |
| 367 | --enable-parser=av1 --enable-parser=gif |
| 368 | ) |
| 369 | fi |
| 370 | if [[ "$FFMPEG_LIBVPX_VP8" == "1" ]]; then |
| 371 | configure_args+=(--enable-decoder=libvpx_vp8 --enable-encoder=libvpx_vp8) |
| 372 | fi |
| 373 |
| 374 | if [[ "$abi" == "x86" || "$abi" == "x86_64" ]]; then |
| 375 | append_configure_toggle runtime-cpudetect "$FFMPEG_RUNTIME_CPUDETECT" |
| 376 | append_configure_toggle mmx "$FFMPEG_MMX" |
| 377 | append_configure_toggle mmxext "$FFMPEG_MMXEXT" |
| 378 | append_configure_toggle sse "$FFMPEG_SSE" |
| 379 | append_configure_toggle sse2 "$FFMPEG_SSE2" |
| 380 | append_configure_toggle sse3 "$FFMPEG_SSE3" |
| 381 | append_configure_toggle ssse3 "$FFMPEG_SSSE3" |
| 382 | append_configure_toggle sse4 "$FFMPEG_SSE4" |
| 383 | append_configure_toggle sse42 "$FFMPEG_SSE42" |
| 384 | append_configure_toggle avx "$FFMPEG_AVX" |
| 385 | append_configure_toggle avx2 "$FFMPEG_AVX2" |
| 386 | append_configure_toggle avx512 "$FFMPEG_AVX512" |
| 387 | append_configure_toggle fma3 "$FFMPEG_FMA3" |
| 388 | append_configure_toggle fma4 "$FFMPEG_FMA4" |
| 389 | append_configure_toggle bmi1 "$FFMPEG_BMI1" |
| 390 | append_configure_toggle bmi2 "$FFMPEG_BMI2" |
| 391 | fi |
| 392 |
| 393 | [[ "$ENABLE_SMALL" == "1" ]] && configure_args+=(--enable-small) |
| 394 | case "$abi" in |
| 395 | armeabi-v7a) configure_args+=(--enable-neon) ;; |
| 396 | x86_64) |
| 397 | append_configure_toggle mmx "$FFMPEG_X86_64_MMX" |
| 398 | append_configure_toggle inline-asm "$FFMPEG_X86_64_INLINE_ASM" |
| 399 | append_configure_toggle x86asm "$FFMPEG_X86_64_X86ASM" |
| 400 | ;; |
| 401 | x86) |
| 402 | append_configure_toggle mmx "$FFMPEG_X86_MMX" |
| 403 | append_configure_toggle inline-asm "$FFMPEG_X86_INLINE_ASM" |
| 404 | append_configure_toggle x86asm "$FFMPEG_X86_X86ASM" |
| 405 | ;; |
| 406 | esac |
| 407 |
| 408 | echo |
| 409 | echo "========== FFmpeg: $abi, API $API ==========" |
| 410 | pushd "$build_dir" >/dev/null |
| 411 | if ! env "${configure_env[@]}" "$FFMPEG_SOURCE_DIR/configure" "${configure_args[@]}"; then |
| 412 | error "FFmpeg configure failed for $abi. Log: $build_dir/ffbuild/config.log" |
| 413 | popd >/dev/null |
| 414 | return 1 |
| 415 | fi |
| 416 |
| 417 | # FFmpeg embeds the literal configure command in every library through |
| 418 | # FFMPEG_CONFIGURATION. Normalize only that diagnostic macro so Linux and |
| 419 | # macOS don't differ merely because --cc/--sysroot/--prefix contain host |
| 420 | # paths. The actual configure/compiler invocation is unchanged. |
| 421 | normalize_generated_metadata_lines "$build_dir/config.h" "#define FFMPEG_CONFIGURATION " || { |
| 422 | popd >/dev/null |
| 423 | return 1 |
| 424 | } |
| 425 |
| 426 | components_header="$build_dir/config_components.h" |
| 427 | [[ -f "$components_header" ]] || components_header="$build_dir/config.h" |
| 428 | required_components=(CONFIG_LIBDAV1D_DECODER CONFIG_LIBVPX_VP9_DECODER CONFIG_LIBVPX_VP9_ENCODER CONFIG_LIBOPUS_DECODER) |
| 429 | if [[ "$FFMPEG_LIBVPX_VP8" == "1" ]]; then |
| 430 | required_components+=(CONFIG_LIBVPX_VP8_DECODER CONFIG_LIBVPX_VP8_ENCODER) |
| 431 | fi |
| 432 | for component in "${required_components[@]}"; do |
| 433 | if ! grep -Eq "^#define[[:space:]]+$component[[:space:]]+1$" "$components_header"; then |
| 434 | error "FFmpeg component is disabled for $abi: $component" |
| 435 | popd >/dev/null |
| 436 | return 1 |
| 437 | fi |
| 438 | done |
| 439 | for component in CONFIG_VP8_DECODER CONFIG_VP9_DECODER CONFIG_AV1_DECODER; do |
| 440 | if ! grep -Eq "^#define[[:space:]]+$component[[:space:]]+0$" "$components_header"; then |
| 441 | error "Built-in FFmpeg decoder is unexpectedly enabled for $abi: $component" |
| 442 | popd >/dev/null |
| 443 | return 1 |
| 444 | fi |
| 445 | done |
| 446 | enabled_av1_decoders="$(awk '/^#define[[:space:]]+CONFIG_.*(AV1|DAV1D).*_DECODER[[:space:]]+1$/ { print $2 }' "$components_header" | LC_ALL=C sort)" |
| 447 | if [[ "$enabled_av1_decoders" != "CONFIG_LIBDAV1D_DECODER" ]]; then |
| 448 | error "Unexpected enabled AV1 decoders for $abi: ${enabled_av1_decoders:-<none>}" |
| 449 | popd >/dev/null |
| 450 | return 1 |
| 451 | fi |
| 452 |
| 453 | if ! make -j"$JOBS" 2>&1 | tee "$build_dir/build.log"; then |
| 454 | error "FFmpeg build failed for $abi. Log: $build_dir/build.log" |
| 455 | popd >/dev/null |
| 456 | return 1 |
| 457 | fi |
| 458 | if ! make install 2>&1 | tee "$build_dir/install.log"; then |
| 459 | error "FFmpeg install failed for $abi. Log: $build_dir/install.log" |
| 460 | popd >/dev/null |
| 461 | return 1 |
| 462 | fi |
| 463 | popd >/dev/null |
| 464 |
| 465 | copy_generated_header_overlay "$abi" "$prefix" |
| 466 |
| 467 | for library in libavcodec.a libavformat.a libavutil.a libswscale.a libswresample.a; do |
| 468 | [[ -f "$prefix/lib/$library" ]] || { error "Missing FFmpeg library for $abi: $prefix/lib/$library"; return 1; } |
| 469 | destination="$(abi_output_dir "$abi")/$library" |
| 470 | copy_archive "$prefix/lib/$library" "$destination" |
| 471 | echo "==> $destination" |
| 472 | done |
| 473 | } |
| 474 |
| 475 | for abi in $ABIS; do |
| 476 | overlay="$(abi_include_dir "$abi")" |
| 477 | rm -rf "$overlay/libavcodec" "$overlay/libavformat" "$overlay/libavutil" "$overlay/libswscale" "$overlay/libswresample" |
| 478 | done |
| 479 |
| 480 | print_common_config |
| 481 | echo "FFmpeg source: $FFMPEG_SOURCE_DIR" |
| 482 | echo "FFmpeg build root: $BUILD_ROOT" |
| 483 | echo "FFmpeg flags: $COMMON_CFLAGS" |
| 484 |
| 485 | rm -rf "$BUILD_ROOT" |
| 486 | mkdir -p "$WORK_DIR" "$INSTALL_DIR" |
| 487 | prepare_patched_source "$FFMPEG_SOURCE_DIR" "$WORK_DIR/source" |
| 488 | FFMPEG_SOURCE_DIR="$WORK_DIR/source" |
| 489 | for abi in $ABIS; do |
| 490 | build_ffmpeg_for_abi "$abi" |
| 491 | done |
| 492 | rm -rf "$BUILD_ROOT" |
| 493 |
| 494 | echo |
| 495 | echo "==> Removing temporary pkg-config metadata" |
| 496 | rm -rf "$PKGCONFIG_DIR" |
| 497 |
| 498 | echo |
| 499 | echo "FFmpeg static build completed." |
| 500 |