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