| 6 |
| # ./build_ffmpeg.sh [ABI...] |
| 7 | # PACKAGE_ONLY=1 ./build_ffmpeg.sh # skip builds, only repackage |
| 8 | # # $BUILD_ROOT/{libvpx,dav1d,ffmpeg}/<ABI> |
| 9 | # # into $PACKAGE_DIR/build_android_final. |
| 10 | # |
| 11 | # libvpx and dav1d must have been built first (build_libvpx.sh / |
| 12 | # build_dav1d.sh); their install trees under $BUILD_ROOT are located through |
| 13 | # pkg-config. |
| 14 |
| 15 | source "$(dirname -- "${BASH_SOURCE[0]}")/build_common.sh" |
| 16 |
| 17 | # --------------------------------------------------------------------------- |
| 18 | # Component options |
| 19 | # --------------------------------------------------------------------------- |
| 20 | ENABLE_SMALL="${ENABLE_SMALL:-1}" |
| 21 |
| 22 | # configure appends its own optimization flag (-Os with --enable-small, else |
| 23 | # -O3) *after* --extra-cflags, so an -O level passed there is silently |
| 24 | # overridden. --optflags is the only flag that wins. Empty = configure default. |
| 25 | FFMPEG_OPTFLAGS="${FFMPEG_OPTFLAGS:-}" |
| 26 |
| 27 | # Thin libvpxdec/libvpxenc wrappers for VP8 in addition to VP9. |
| 28 | FFMPEG_LIBVPX_VP8="${FFMPEG_LIBVPX_VP8:-1}" |
| 29 | FFMPEG_PARSERS="${FFMPEG_PARSERS:-1}" |
| 30 |
| 31 | # CPU/assembly switches. Accepted values: auto, on, off. |
| 32 | FFMPEG_RUNTIME_CPUDETECT="${FFMPEG_RUNTIME_CPUDETECT:-on}" |
| 33 | FFMPEG_MMX="${FFMPEG_MMX:-auto}" |
| 34 | FFMPEG_MMXEXT="${FFMPEG_MMXEXT:-auto}" |
| 35 | FFMPEG_SSE="${FFMPEG_SSE:-auto}" |
| 36 | FFMPEG_SSE2="${FFMPEG_SSE2:-auto}" |
| 37 | FFMPEG_SSE3="${FFMPEG_SSE3:-auto}" |
| 38 | FFMPEG_SSSE3="${FFMPEG_SSSE3:-auto}" |
| 39 | FFMPEG_SSE4="${FFMPEG_SSE4:-auto}" |
| 40 | FFMPEG_SSE42="${FFMPEG_SSE42:-auto}" |
| 41 | FFMPEG_AVX="${FFMPEG_AVX:-off}" |
| 42 | FFMPEG_AVX2="${FFMPEG_AVX2:-auto}" |
| 43 | FFMPEG_AVX512="${FFMPEG_AVX512:-auto}" |
| 44 | FFMPEG_FMA3="${FFMPEG_FMA3:-auto}" |
| 45 | FFMPEG_FMA4="${FFMPEG_FMA4:-auto}" |
| 46 | FFMPEG_BMI1="${FFMPEG_BMI1:-auto}" |
| 47 | FFMPEG_BMI2="${FFMPEG_BMI2:-auto}" |
| 48 |
| 49 | FFMPEG_X86_64_MMX="${FFMPEG_X86_64_MMX:-off}" |
| 50 | FFMPEG_X86_64_INLINE_ASM="${FFMPEG_X86_64_INLINE_ASM:-off}" |
| 51 | FFMPEG_X86_64_X86ASM="${FFMPEG_X86_64_X86ASM:-auto}" |
| 52 | FFMPEG_X86_MMX="${FFMPEG_X86_MMX:-off}" |
| 53 | FFMPEG_X86_INLINE_ASM="${FFMPEG_X86_INLINE_ASM:-off}" |
| 54 | FFMPEG_X86_X86ASM="${FFMPEG_X86_X86ASM:-off}" |
| 55 |
| 56 | FFMPEG_X86_64_EXTRA_ISA_CFLAGS="${FFMPEG_X86_64_EXTRA_ISA_CFLAGS:-}" |
| 57 | FFMPEG_X86_EXTRA_ISA_CFLAGS="${FFMPEG_X86_EXTRA_ISA_CFLAGS:-}" |
| 58 |
| 59 | require_bool ENABLE_SMALL "$ENABLE_SMALL" |
| 60 | require_bool FFMPEG_LIBVPX_VP8 "$FFMPEG_LIBVPX_VP8" |
| 61 | require_bool FFMPEG_PARSERS "$FFMPEG_PARSERS" |
| 62 | require_bool PACKAGE_ONLY "${PACKAGE_ONLY:-0}" |
| 63 |
| 64 | for toggle_name in \ |
| 65 | FFMPEG_RUNTIME_CPUDETECT FFMPEG_MMX FFMPEG_MMXEXT FFMPEG_SSE \ |
| 66 | FFMPEG_SSE2 FFMPEG_SSE3 FFMPEG_SSSE3 FFMPEG_SSE4 FFMPEG_SSE42 \ |
| 67 | FFMPEG_AVX FFMPEG_AVX2 FFMPEG_AVX512 FFMPEG_FMA3 FFMPEG_FMA4 \ |
| 68 | FFMPEG_BMI1 FFMPEG_BMI2 FFMPEG_X86_64_MMX \ |
| 69 | FFMPEG_X86_64_INLINE_ASM FFMPEG_X86_64_X86ASM FFMPEG_X86_MMX \ |
| 70 | FFMPEG_X86_INLINE_ASM FFMPEG_X86_X86ASM |
| 71 | do |
| 72 | require_toggle "$toggle_name" "${!toggle_name}" |
| 73 | done |
| 74 |
| 75 | [[ -f "$FFMPEG_SOURCE_DIR/configure" ]] || die "FFmpeg sources were not found in: $FFMPEG_SOURCE_DIR |
| 76 | Run: git submodule update --init TMessagesProj/jni/third_party/ffmpeg" |
| 77 | FFMPEG_SOURCE_DIR="$(cd "$FFMPEG_SOURCE_DIR" && pwd)" |
| 78 |
| 79 | command -v pkg-config >/dev/null 2>&1 || die "pkg-config is required to locate libvpx and dav1d." |
| 80 |
| 81 | # FFmpeg's libdav1d check is require_pkg_config with no check_lib fallback, so |
| 82 | # pkg-config has to resolve dav1d.pc (and vpx.pc). Both .pc files are collected |
| 83 | # into a single directory per ABI so PKG_CONFIG_LIBDIR never needs a path-list |
| 84 | # separator, which differs between MSYS pkg-config (':') and a native |
| 85 | # Windows pkgconf (';'). |
| 86 | # |
| 87 | # Whether that directory has to be spelled as a POSIX or a Windows path depends |
| 88 | # on which pkg-config is on PATH, so probe it instead of guessing. |
| 89 | resolve_pkgconfig_libdir() { |
| 90 | local dir="$1" candidate |
| 91 | for candidate in "$dir" "$(to_native_path "$dir")"; do |
| 92 | if PKG_CONFIG_LIBDIR="$candidate" PKG_CONFIG_PATH="" \ |
| 93 | pkg-config --exists vpx dav1d 2>/dev/null |
| 94 | then |
| 95 | printf '%s' "$candidate" |
| 96 | return 0 |
| 97 | fi |
| 98 | done |
| 99 | error "pkg-config cannot resolve vpx.pc and dav1d.pc in: $dir" |
| 100 | return 1 |
| 101 | } |
| 102 |
| 103 | build_ffmpeg_for_abi() { |
| 104 | local abi="$1" |
| 105 | local arch target cpu extra_cflags |
| 106 | local -a abi_flags=() |
| 107 |
| 108 | target="$(abi_triple "$abi")" |
| 109 | case "$abi" in |
| 110 | arm64-v8a) |
| 111 | arch="aarch64" |
| 112 | cpu="armv8-a" |
| 113 | extra_cflags="-march=armv8-a" |
| 114 | ;; |
| 115 | armeabi-v7a) |
| 116 | arch="arm" |
| 117 | cpu="armv7-a" |
| 118 | extra_cflags="-march=armv7-a -mfloat-abi=softfp -mfpu=neon" |
| 119 | abi_flags+=(--enable-neon) |
| 120 | ;; |
| 121 | x86_64) |
| 122 | arch="x86_64" |
| 123 | cpu="x86-64" |
| 124 | extra_cflags="-march=x86-64${FFMPEG_X86_64_EXTRA_ISA_CFLAGS:+ $FFMPEG_X86_64_EXTRA_ISA_CFLAGS}" |
| 125 | append_configure_toggle abi_flags mmx "$FFMPEG_X86_64_MMX" |
| 126 | append_configure_toggle abi_flags inline-asm "$FFMPEG_X86_64_INLINE_ASM" |
| 127 | append_configure_toggle abi_flags x86asm "$FFMPEG_X86_64_X86ASM" |
| 128 | ;; |
| 129 | x86) |
| 130 | arch="x86" |
| 131 | cpu="i686" |
| 132 | extra_cflags="-march=i686${FFMPEG_X86_EXTRA_ISA_CFLAGS:+ $FFMPEG_X86_EXTRA_ISA_CFLAGS}" |
| 133 | append_configure_toggle abi_flags mmx "$FFMPEG_X86_MMX" |
| 134 | append_configure_toggle abi_flags inline-asm "$FFMPEG_X86_INLINE_ASM" |
| 135 | append_configure_toggle abi_flags x86asm "$FFMPEG_X86_X86ASM" |
| 136 | ;; |
| 137 | *) error "Unsupported ABI: $abi"; return 1 ;; |
| 138 | esac |
| 139 |
| 140 | check_x86_assembler "$abi" || return 1 |
| 141 |
| 142 | local vpx_prefix="$LIBVPX_OUTPUT_DIR/$abi" |
| 143 | local dav1d_prefix="$DAV1D_OUTPUT_DIR/$abi" |
| 144 |
| 145 | [[ -f "$vpx_prefix/lib/libvpx.a" ]] || { |
| 146 | error "Missing libvpx for $abi. Run build_libvpx.sh first." |
| 147 | return 1 |
| 148 | } |
| 149 | [[ -f "$vpx_prefix/lib/pkgconfig/vpx.pc" ]] || { error "Missing vpx.pc for $abi"; return 1; } |
| 150 | [[ -f "$dav1d_prefix/lib/libdav1d.a" ]] || { |
| 151 | error "Missing dav1d for $abi. Run build_dav1d.sh first." |
| 152 | return 1 |
| 153 | } |
| 154 | [[ -f "$dav1d_prefix/lib/pkgconfig/dav1d.pc" ]] || { error "Missing dav1d.pc for $abi"; return 1; } |
| 155 |
| 156 | local prefix="$FFMPEG_OUTPUT_DIR/$abi" |
| 157 | local build_dir="$FFMPEG_WORK_DIR/$abi" |
| 158 | local cc cxx |
| 159 | cc="$(clang_driver "$target" clang)" |
| 160 | cxx="$(clang_driver "$target" clang++)" |
| 161 |
| 162 | if [[ "$CLEAN" == "1" ]]; then |
| 163 | rm -rf "$build_dir" "$prefix" |
| 164 | fi |
| 165 | mkdir -p "$build_dir" "$prefix" |
| 166 |
| 167 | local pc_dir="$build_dir/pkgconfig" |
| 168 | rm -rf "$pc_dir" |
| 169 | mkdir -p "$pc_dir" |
| 170 | cp -f "$vpx_prefix/lib/pkgconfig/vpx.pc" "$dav1d_prefix/lib/pkgconfig/dav1d.pc" "$pc_dir/" |
| 171 |
| 172 | local pkgconfig_libdir |
| 173 | pkgconfig_libdir="$(resolve_pkgconfig_libdir "$pc_dir")" || return 1 |
| 174 |
| 175 | local -a size_flags=() |
| 176 | [[ "$ENABLE_SMALL" == "1" ]] && size_flags+=(--enable-small) |
| 177 |
| 178 | local -a configure_env=( |
| 179 | "PKG_CONFIG_PATH=$pkgconfig_libdir" |
| 180 | "PKG_CONFIG_LIBDIR=$pkgconfig_libdir" |
| 181 | "ARFLAGS=rcD" |
| 182 | ) |
| 183 |
| 184 | local -a configure_args=( |
| 185 | --prefix="$prefix" |
| 186 | --target-os=android |
| 187 | --arch="$arch" |
| 188 | --cpu="$cpu" |
| 189 | --enable-cross-compile |
| 190 | --cc="$cc" |
| 191 | --cxx="$cxx" |
| 192 | --ar="$AR_BIN" |
| 193 | --nm="$NM_BIN" |
| 194 | --ranlib="$RANLIB_BIN" |
| 195 | --strip="$STRIP_BIN" |
| 196 | --sysroot="$(to_native_path "$TOOLCHAIN/sysroot")" |
| 197 |
| 198 | --enable-pic |
| 199 | --enable-static |
| 200 | --disable-shared |
| 201 | --enable-optimizations |
| 202 | --enable-pthreads |
| 203 |
| 204 | --disable-doc |
| 205 | --disable-debug |
| 206 | --disable-programs |
| 207 | --disable-avdevice |
| 208 | --disable-avfilter |
| 209 | --disable-network |
| 210 | --disable-autodetect |
| 211 | --disable-everything |
| 212 |
| 213 | --enable-avcodec |
| 214 | --enable-avformat |
| 215 | --enable-avutil |
| 216 | --enable-swscale |
| 217 | --enable-swresample |
| 218 |
| 219 | --enable-protocol=file |
| 220 |
| 221 | --enable-decoder=h264 |
| 222 | --enable-decoder=hevc |
| 223 | --enable-decoder=mpeg4 |
| 224 | --enable-decoder=mjpeg |
| 225 | --enable-decoder=gif |
| 226 | --enable-decoder=alac |
| 227 | --enable-decoder=opus |
| 228 | --enable-decoder=mp3 |
| 229 | --enable-decoder=aac |
| 230 |
| 231 | --enable-demuxer=mov |
| 232 | --enable-demuxer=gif |
| 233 | --enable-demuxer=ogg |
| 234 | --enable-demuxer=matroska |
| 235 | --enable-demuxer=mp3 |
| 236 | --enable-demuxer=aac |
| 237 |
| 238 | --enable-muxer=matroska |
| 239 |
| 240 | --enable-bsf=vp9_superframe |
| 241 | --enable-bsf=vp9_raw_reorder |
| 242 |
| 243 | --enable-libvpx |
| 244 | --enable-libdav1d |
| 245 | --enable-decoder=libdav1d |
| 246 | --enable-decoder=libvpx_vp9 |
| 247 | --enable-encoder=libvpx_vp9 |
| 248 | --pkg-config-flags=--static |
| 249 |
| 250 | # --disable-autodetect only stops probing for zlib, it does not forbid |
| 251 | # a system copy. (--disable-postproc is gone: libpostproc was removed |
| 252 | # in FFmpeg 8.0 and configure rejects the unknown option.) |
| 253 | --disable-zlib |
| 254 |
| 255 | "--extra-cflags=-fPIC -DANDROID $extra_cflags${COMMON_CFLAGS:+ $COMMON_CFLAGS} -I$(to_native_path "$vpx_prefix/include") -I$(to_native_path "$dav1d_prefix/include")" |
| 256 | "--extra-ldflags=-Wl,-Bsymbolic -L$(to_native_path "$vpx_prefix/lib") -L$(to_native_path "$dav1d_prefix/lib")" |
| 257 | # Static-only build against prebuilt libvpx.a + libdav1d.a. -ldl comes |
| 258 | # from pkg-config on some hosts but is not shipped by NDK r27; lld on |
| 259 | # Windows then deadlocks while scanning it. Keep it out, the NDK libc |
| 260 | # already exports the relevant symbols. |
| 261 | "--extra-libs=-lm" |
| 262 | ) |
| 263 |
| 264 | [[ -n "$FFMPEG_OPTFLAGS" ]] && configure_args+=("--optflags=$FFMPEG_OPTFLAGS") |
| 265 |
| 266 | if [[ "$FFMPEG_PARSERS" == "1" ]]; then |
| 267 | configure_args+=( |
| 268 | --enable-parser=h264 |
| 269 | --enable-parser=hevc |
| 270 | --enable-parser=mpeg4video |
| 271 | --enable-parser=mpegaudio |
| 272 | --enable-parser=aac |
| 273 | --enable-parser=opus |
| 274 | --enable-parser=av1 |
| 275 | ) |
| 276 | fi |
| 277 |
| 278 | if [[ "$FFMPEG_LIBVPX_VP8" == "1" ]]; then |
| 279 | configure_args+=( |
| 280 | --enable-decoder=libvpx_vp8 |
| 281 | --enable-encoder=libvpx_vp8 |
| 282 | ) |
| 283 | fi |
| 284 |
| 285 | if [[ "$abi" == "x86" || "$abi" == "x86_64" ]]; then |
| 286 | append_configure_toggle configure_args runtime-cpudetect "$FFMPEG_RUNTIME_CPUDETECT" |
| 287 | append_configure_toggle configure_args mmx "$FFMPEG_MMX" |
| 288 | append_configure_toggle configure_args mmxext "$FFMPEG_MMXEXT" |
| 289 | append_configure_toggle configure_args sse "$FFMPEG_SSE" |
| 290 | append_configure_toggle configure_args sse2 "$FFMPEG_SSE2" |
| 291 | append_configure_toggle configure_args sse3 "$FFMPEG_SSE3" |
| 292 | append_configure_toggle configure_args ssse3 "$FFMPEG_SSSE3" |
| 293 | append_configure_toggle configure_args sse4 "$FFMPEG_SSE4" |
| 294 | append_configure_toggle configure_args sse42 "$FFMPEG_SSE42" |
| 295 | append_configure_toggle configure_args avx "$FFMPEG_AVX" |
| 296 | append_configure_toggle configure_args avx2 "$FFMPEG_AVX2" |
| 297 | append_configure_toggle configure_args avx512 "$FFMPEG_AVX512" |
| 298 | append_configure_toggle configure_args fma3 "$FFMPEG_FMA3" |
| 299 | append_configure_toggle configure_args fma4 "$FFMPEG_FMA4" |
| 300 | append_configure_toggle configure_args bmi1 "$FFMPEG_BMI1" |
| 301 | append_configure_toggle configure_args bmi2 "$FFMPEG_BMI2" |
| 302 | fi |
| 303 |
| 304 | configure_args+=("${size_flags[@]}") |
| 305 | configure_args+=("${abi_flags[@]}") |
| 306 |
| 307 | echo |
| 308 | echo "========== FFmpeg: $abi, API $API ==========" |
| 309 |
| 310 | pushd "$build_dir" >/dev/null |
| 311 |
| 312 | if ! env "${configure_env[@]}" "$FFMPEG_SOURCE_DIR/configure" "${configure_args[@]}"; then |
| 313 | error "FFmpeg configure failed for $abi. Log: $build_dir/ffbuild/config.log" |
| 314 | popd >/dev/null |
| 315 | return 1 |
| 316 | fi |
| 317 |
| 318 | local components_header="$build_dir/config_components.h" |
| 319 | [[ -f "$components_header" ]] || components_header="$build_dir/config.h" |
| 320 |
| 321 | local -a required_components=( |
| 322 | CONFIG_LIBDAV1D_DECODER |
| 323 | CONFIG_LIBVPX_VP9_DECODER |
| 324 | CONFIG_LIBVPX_VP9_ENCODER |
| 325 | ) |
| 326 | if [[ "$FFMPEG_LIBVPX_VP8" == "1" ]]; then |
| 327 | required_components+=( |
| 328 | CONFIG_LIBVPX_VP8_DECODER |
| 329 | CONFIG_LIBVPX_VP8_ENCODER |
| 330 | ) |
| 331 | fi |
| 332 |
| 333 | local component |
| 334 | for component in "${required_components[@]}"; do |
| 335 | if ! grep -Eq "^#define[[:space:]]+$component[[:space:]]+1$" "$components_header"; then |
| 336 | error "FFmpeg component is disabled for $abi: $component (see $components_header and $build_dir/ffbuild/config.log)" |
| 337 | popd >/dev/null |
| 338 | return 1 |
| 339 | fi |
| 340 | done |
| 341 |
| 342 | # Keep only the specialized implementations: VP8/VP9 -> libvpx, AV1 -> dav1d. |
| 343 | for component in CONFIG_VP8_DECODER CONFIG_VP9_DECODER CONFIG_AV1_DECODER; do |
| 344 | if ! grep -Eq "^#define[[:space:]]+$component[[:space:]]+0$" "$components_header"; then |
| 345 | error "Built-in FFmpeg decoder is unexpectedly enabled for $abi: $component" |
| 346 | popd >/dev/null |
| 347 | return 1 |
| 348 | fi |
| 349 | done |
| 350 |
| 351 | local enabled_av1_decoders |
| 352 | enabled_av1_decoders="$( |
| 353 | awk '/^#define[[:space:]]+CONFIG_.*(AV1|DAV1D).*_DECODER[[:space:]]+1$/ { print $2 }' \ |
| 354 | "$components_header" | LC_ALL=C sort |
| 355 | )" |
| 356 | if [[ "$enabled_av1_decoders" != "CONFIG_LIBDAV1D_DECODER" ]]; then |
| 357 | error "Unexpected enabled AV1 decoders for $abi:" |
| 358 | printf '%s\n' "${enabled_av1_decoders:-<none>}" >&2 |
| 359 | error "Exactly CONFIG_LIBDAV1D_DECODER must be enabled." |
| 360 | popd >/dev/null |
| 361 | return 1 |
| 362 | fi |
| 363 |
| 364 | if ! make -j"$JOBS" 2>&1 | tee "$build_dir/build.log"; then |
| 365 | error "FFmpeg build failed for $abi. Log: $build_dir/build.log" |
| 366 | popd >/dev/null |
| 367 | return 1 |
| 368 | fi |
| 369 |
| 370 | if ! make install 2>&1 | tee "$build_dir/install.log"; then |
| 371 | error "FFmpeg install failed for $abi. Log: $build_dir/install.log" |
| 372 | popd >/dev/null |
| 373 | return 1 |
| 374 | fi |
| 375 |
| 376 | popd >/dev/null |
| 377 | } |
| 378 |
| 379 | # --------------------------------------------------------------------------- |
| 380 | # Packaging |
| 381 | # --------------------------------------------------------------------------- |
| 382 | package_libvpx_headers() { |
| 383 | local include_dir="$1" |
| 384 | local temporary_include="$BUILD_ROOT/libvpx_include" |
| 385 |
| 386 | rm -rf "$temporary_include" |
| 387 | mkdir -p "$temporary_include" |
| 388 |
| 389 | # libvpx installs its public headers under include/vpx. Merge them there |
| 390 | # first so the ABI comparison and dispatcher generation see the original |
| 391 | # layout. |
| 392 | merge_component_headers "libvpx" "$LIBVPX_OUTPUT_DIR" "$temporary_include" || return 1 |
| 393 |
| 394 | [[ -d "$temporary_include/vpx" ]] || { |
| 395 | error "Merged libvpx headers were not found: $temporary_include/vpx" |
| 396 | return 1 |
| 397 | } |
| 398 |
| 399 | rm -rf "$include_dir/libvpx" |
| 400 | mv "$temporary_include/vpx" "$include_dir/libvpx" |
| 401 | rm -rf "$temporary_include" |
| 402 |
| 403 | # Installed libvpx headers refer to one another as <vpx/...>, but the |
| 404 | # Telegram tree includes them as <libvpx/...>. Rewrite only those include |
| 405 | # paths in the final package; the intermediate installs stay untouched so |
| 406 | # FFmpeg's own <vpx/...> includes keep working. |
| 407 | local header |
| 408 | while IFS= read -r -d '' header; do |
| 409 | sed -i.bak \ |
| 410 | -e 's#<vpx/#<libvpx/#g' \ |
| 411 | -e 's#"vpx/#"libvpx/#g' \ |
| 412 | "$header" |
| 413 | rm -f "${header}.bak" |
| 414 | done < <(find "$include_dir/libvpx" -type f -name '*.h' -print0) |
| 415 |
| 416 | [[ -f "$include_dir/libvpx/vpx_codec.h" ]] || { |
| 417 | error "Missing packaged libvpx header: $include_dir/libvpx/vpx_codec.h" |
| 418 | return 1 |
| 419 | } |
| 420 | [[ -f "$include_dir/libvpx/vpx_decoder.h" ]] || { |
| 421 | error "Missing packaged decoder header: $include_dir/libvpx/vpx_decoder.h" |
| 422 | return 1 |
| 423 | } |
| 424 | } |
| 425 |
| 426 | report_archive_flags() { |
| 427 | [[ -x "$READELF_BIN" ]] || return 0 |
| 428 |
| 429 | echo |
| 430 | echo "========== Section report ==========" |
| 431 | echo " function-sections / addrsig enable -Wl,--gc-sections and -Wl,--icf=safe;" |
| 432 | echo " eh_frame is unwind data that survives into the linked .so." |
| 433 |
| 434 | local abi archive name sections count_text count_addrsig count_eh |
| 435 | for abi in $ABIS; do |
| 436 | for name in libavcodec libvpx libdav1d; do |
| 437 | archive="$PACKAGE_DIR/$abi/$name.a" |
| 438 | [[ -f "$archive" ]] || continue |
| 439 |
| 440 | sections="$("$READELF_BIN" --section-headers --wide "$archive" 2>/dev/null || true)" |
| 441 | count_text="$(grep -c ' \.text\.' <<<"$sections" || true)" |
| 442 | count_addrsig="$(grep -c '\.llvm_addrsig' <<<"$sections" || true)" |
| 443 | count_eh="$(grep -c ' \.eh_frame' <<<"$sections" || true)" |
| 444 |
| 445 | printf ' %-12s %-11s .text.* = %-6s .llvm_addrsig = %-6s .eh_frame = %s\n' \ |
| 446 | "$abi" "$name" "$count_text" "$count_addrsig" "$count_eh" |
| 447 | done |
| 448 | done |
| 449 | } |
| 450 |
| 451 | package_outputs() { |
| 452 | echo |
| 453 | echo "========== Packaging common include and per-ABI libraries ==========" |
| 454 |
| 455 | OUTPUT_DIR="$PACKAGE_DIR/build" |
| 456 |
| 457 | mkdir -p "$OUTPUT_DIR" |
| 458 | rm -rf "$OUTPUT_DIR/include" |
| 459 | mkdir -p "$OUTPUT_DIR/include" |
| 460 |
| 461 | local abi |
| 462 | for abi in $ABIS; do |
| 463 | rm -rf "$OUTPUT_DIR/$abi" |
| 464 | mkdir -p "$OUTPUT_DIR/$abi" |
| 465 | done |
| 466 |
| 467 | package_libvpx_headers "$OUTPUT_DIR/include" |
| 468 | copy_component_libraries "libvpx" "$LIBVPX_OUTPUT_DIR" "$OUTPUT_DIR" |
| 469 |
| 470 | merge_component_headers "dav1d" "$DAV1D_OUTPUT_DIR" "$OUTPUT_DIR/include" |
| 471 | copy_component_libraries "dav1d" "$DAV1D_OUTPUT_DIR" "$OUTPUT_DIR" |
| 472 |
| 473 | merge_component_headers "ffmpeg" "$FFMPEG_OUTPUT_DIR" "$OUTPUT_DIR/include" |
| 474 | copy_component_libraries "ffmpeg" "$FFMPEG_OUTPUT_DIR" "$OUTPUT_DIR" |
| 475 |
| 476 | echo "Package created:" |
| 477 | echo " Headers: $OUTPUT_DIR/include" |
| 478 | echo " Libraries: $OUTPUT_DIR/<ABI>" |
| 479 |
| 480 | report_archive_flags |
| 481 | } |
| 482 |
| 483 | TARGET_ABIS="${*:-$ABIS}" |
| 484 |
| 485 | mkdir -p "$FFMPEG_WORK_DIR" "$FFMPEG_OUTPUT_DIR" |
| 486 |
| 487 | if [[ "${PACKAGE_ONLY:-0}" != "1" ]]; then |
| 488 | for abi in $TARGET_ABIS; do |
| 489 | build_ffmpeg_for_abi "$abi" |
| 490 | done |
| 491 | fi |
| 492 |
| 493 | # Packaging merges headers across $ABIS, so it can only run once every ABI in |
| 494 | # that list has been built. Skip it for a partial rebuild. |
| 495 | if [[ "$PACKAGE_OUTPUT" == "1" && "$TARGET_ABIS" == "$ABIS" ]]; then |
| 496 | package_outputs |
| 497 | fi |
| 498 |
| 499 | echo |
| 500 | echo "FFmpeg install: $FFMPEG_OUTPUT_DIR/<ABI>" |
| 501 |
| 502 |