| 6 |
| # That file is upstream and stays untouched. The scripts here reproduce its |
| 7 | # configuration and verification steps, split into per-component entry points |
| 8 | # (build_libvpx.sh / build_dav1d.sh / build_ffmpeg.sh) and extended with |
| 9 | # Windows MINGW64 host support. |
| 10 | # |
| 11 | # Layout produced (consumed by TMessagesProj/jni/CMakeLists.txt): |
| 12 | # jni/ffmpeg/include/ merged headers (libvpx/, dav1d/, libav*/, libsw*/) |
| 13 | # jni/ffmpeg/<ABI>/*.a static libraries |
| 14 | # jni/ffmpeg/build_android/ intermediate build + install trees |
| 15 |
| 16 | if [[ -n "${BUILD_COMMON_SOURCED:-}" ]]; then |
| 17 | return 0 |
| 18 | fi |
| 19 | BUILD_COMMON_SOURCED=1 |
| 20 |
| 21 | set -Eeuo pipefail |
| 22 |
| 23 | # Reproducible-build environment; SOURCE_DATE_EPOCH may be overridden. |
| 24 | SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-946684800}" |
| 25 | export SOURCE_DATE_EPOCH |
| 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 | error() { echo "ERROR: $*" >&2; } |
| 34 | die() { error "$*"; exit 1; } |
| 35 |
| 36 | require_bool() { |
| 37 | case "$2" in |
| 38 | 0|1) ;; |
| 39 | *) die "$1 must be 0 or 1, got: $2" ;; |
| 40 | esac |
| 41 | } |
| 42 |
| 43 | require_toggle() { |
| 44 | case "$2" in |
| 45 | auto|on|off) ;; |
| 46 | *) die "$1 must be auto, on or off, got: $2" ;; |
| 47 | esac |
| 48 | } |
| 49 |
| 50 | # usage: append_configure_toggle <array-name> <feature> <auto|on|off> |
| 51 | append_configure_toggle() { |
| 52 | local -n destination="$1" |
| 53 | case "$3" in |
| 54 | auto) ;; |
| 55 | on) destination+=("--enable-$2") ;; |
| 56 | off) destination+=("--disable-$2") ;; |
| 57 | esac |
| 58 | } |
| 59 |
| 60 | # --------------------------------------------------------------------------- |
| 61 | # Paths |
| 62 | # --------------------------------------------------------------------------- |
| 63 | THIRD_PARTY_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" |
| 64 | JNI_DIR="$(cd "$THIRD_PARTY_DIR/.." && pwd)" |
| 65 |
| 66 | LIBVPX_SOURCE_DIR="${LIBVPX_SOURCE_DIR:-$THIRD_PARTY_DIR/libvpx}" |
| 67 | DAV1D_SOURCE_DIR="${DAV1D_SOURCE_DIR:-$THIRD_PARTY_DIR/dav1d}" |
| 68 | FFMPEG_SOURCE_DIR="${FFMPEG_SOURCE_DIR:-$THIRD_PARTY_DIR/ffmpeg}" |
| 69 |
| 70 | # Final package consumed by jni/CMakeLists.txt. |
| 71 | PACKAGE_DIR="${PACKAGE_DIR:-$JNI_DIR/ffmpeg}" |
| 72 | BUILD_ROOT="${BUILD_ROOT:-$PACKAGE_DIR/build_android}" |
| 73 |
| 74 | LIBVPX_WORK_DIR="$BUILD_ROOT/work/libvpx" |
| 75 | DAV1D_WORK_DIR="$BUILD_ROOT/work/dav1d" |
| 76 | FFMPEG_WORK_DIR="$BUILD_ROOT/work/ffmpeg" |
| 77 | LIBVPX_OUTPUT_DIR="$BUILD_ROOT/libvpx" |
| 78 | DAV1D_OUTPUT_DIR="$BUILD_ROOT/dav1d" |
| 79 | FFMPEG_OUTPUT_DIR="$BUILD_ROOT/ffmpeg" |
| 80 |
| 81 | # --------------------------------------------------------------------------- |
| 82 | # Build options |
| 83 | # --------------------------------------------------------------------------- |
| 84 | NDK_VERSION="${NDK_VERSION:-27.2.12479018}" |
| 85 | API="${API:-21}" |
| 86 | # All four ABIs are built by default: the packaging step merges headers across |
| 87 | # ABIS and emits per-ABI dispatchers, so a package built from a subset would |
| 88 | # #error out when compiled for a missing ABI. |
| 89 | #ABIS="${ABIS:-arm64-v8a armeabi-v7a x86_64 x86}" |
| 90 | ABIS="${ABIS:-arm64-v8a armeabi-v7a}" |
| 91 | CLEAN="${CLEAN:-1}" |
| 92 | PACKAGE_OUTPUT="${PACKAGE_OUTPUT:-1}" |
| 93 | JOBS="${JOBS:-$(getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || echo 8)}" |
| 94 |
| 95 | # Code-generation switches shared by all three components. See the upstream |
| 96 | # reference script for the rationale behind each default. |
| 97 | UNWIND_TABLES="${UNWIND_TABLES:-0}" |
| 98 | FRAME_POINTERS="${FRAME_POINTERS:-0}" |
| 99 | FUNCTION_SECTIONS="${FUNCTION_SECTIONS:-1}" |
| 100 | ADDRSIG="${ADDRSIG:-1}" |
| 101 | LIBVPX_ADDRSIG="${LIBVPX_ADDRSIG:-0}" |
| 102 | HIDDEN_VISIBILITY="${HIDDEN_VISIBILITY:-0}" |
| 103 |
| 104 | require_bool CLEAN "$CLEAN" |
| 105 | require_bool PACKAGE_OUTPUT "$PACKAGE_OUTPUT" |
| 106 | require_bool UNWIND_TABLES "$UNWIND_TABLES" |
| 107 | require_bool FRAME_POINTERS "$FRAME_POINTERS" |
| 108 | require_bool FUNCTION_SECTIONS "$FUNCTION_SECTIONS" |
| 109 | require_bool ADDRSIG "$ADDRSIG" |
| 110 | require_bool LIBVPX_ADDRSIG "$LIBVPX_ADDRSIG" |
| 111 | require_bool HIDDEN_VISIBILITY "$HIDDEN_VISIBILITY" |
| 112 |
| 113 | # --------------------------------------------------------------------------- |
| 114 | # Host detection |
| 115 | # |
| 116 | # HOST_IS_WINDOWS=1 on MSYS2/MINGW64/Cygwin. On those hosts: |
| 117 | # - the per-API clang drivers are ${triple}${API}-clang.cmd wrappers and the |
| 118 | # binutils are llvm-*.exe; |
| 119 | # - configure scripts that hand paths to a native (non-MSYS) tool need |
| 120 | # Windows paths, so to_native_path() converts them with cygpath -m. |
| 121 | # --------------------------------------------------------------------------- |
| 122 | HOST_IS_WINDOWS=0 |
| 123 | case "$(uname -s)" in |
| 124 | Linux) |
| 125 | case "$(uname -m)" in |
| 126 | x86_64) HOST_TAG="linux-x86_64" ;; |
| 127 | aarch64|arm64) HOST_TAG="linux-aarch64" ;; |
| 128 | *) die "Unsupported Linux host architecture: $(uname -m)" ;; |
| 129 | esac |
| 130 | ;; |
| 131 | Darwin) |
| 132 | case "$(uname -m)" in |
| 133 | x86_64) HOST_TAG="darwin-x86_64" ;; |
| 134 | arm64) HOST_TAG="darwin-arm64" ;; |
| 135 | *) die "Unsupported macOS host architecture: $(uname -m)" ;; |
| 136 | esac |
| 137 | ;; |
| 138 | MINGW*|MSYS*|CYGWIN*) |
| 139 | HOST_IS_WINDOWS=1 |
| 140 | HOST_TAG="windows-x86_64" |
| 141 | ;; |
| 142 | *) die "Unsupported host: $(uname -s). Use Linux, macOS or MSYS2/MINGW64." ;; |
| 143 | esac |
| 144 |
| 145 | # Convert an MSYS/Cygwin path to a Windows path. No-op elsewhere. |
| 146 | to_native_path() { |
| 147 | if [[ "$HOST_IS_WINDOWS" == "1" ]] && command -v cygpath >/dev/null 2>&1; then |
| 148 | cygpath -m -- "$1" |
| 149 | else |
| 150 | printf '%s' "$1" |
| 151 | fi |
| 152 | } |
| 153 |
| 154 | # --------------------------------------------------------------------------- |
| 155 | # NDK / toolchain |
| 156 | # --------------------------------------------------------------------------- |
| 157 | locate_ndk() { |
| 158 | local candidate sdk_root |
| 159 |
| 160 | if [[ -n "${ANDROID_NDK_HOME:-}" && -d "$ANDROID_NDK_HOME" ]]; then |
| 161 | : |
| 162 | elif [[ -n "${NDK:-}" && -d "$NDK" ]]; then |
| 163 | ANDROID_NDK_HOME="$NDK" |
| 164 | else |
| 165 | sdk_root="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}" |
| 166 | if [[ -z "$sdk_root" ]]; then |
| 167 | for candidate in \ |
| 168 | "${HOME:-}/Android/Sdk" \ |
| 169 | "${HOME:-}/Library/Android/sdk" \ |
| 170 | "${HOME:-}/.local/lib/android/sdk" \ |
| 171 | "${LOCALAPPDATA:-}/Android/Sdk" |
| 172 | do |
| 173 | if [[ -d "$candidate/ndk/$NDK_VERSION" ]]; then |
| 174 | sdk_root="$candidate" |
| 175 | break |
| 176 | fi |
| 177 | done |
| 178 | fi |
| 179 | [[ -n "$sdk_root" ]] && ANDROID_NDK_HOME="$sdk_root/ndk/$NDK_VERSION" |
| 180 | fi |
| 181 |
| 182 | if [[ -z "${ANDROID_NDK_HOME:-}" || ! -d "$ANDROID_NDK_HOME" ]]; then |
| 183 | error "Android NDK $NDK_VERSION was not found." |
| 184 | echo "Set ANDROID_NDK_HOME, for example:" >&2 |
| 185 | echo " ANDROID_NDK_HOME=\"\$HOME/Android/Sdk/ndk/$NDK_VERSION\" $0" >&2 |
| 186 | exit 1 |
| 187 | fi |
| 188 |
| 189 | ANDROID_NDK_HOME="$(cd "$ANDROID_NDK_HOME" && pwd)" |
| 190 | export ANDROID_NDK_HOME |
| 191 |
| 192 | TOOLCHAIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG" |
| 193 | [[ -d "$TOOLCHAIN" ]] || die "LLVM toolchain was not found: $TOOLCHAIN" |
| 194 |
| 195 | # NDK r23+ ships unified llvm-* binutils only; the ${triple}-ar/ld/nm |
| 196 | # wrappers are gone. On Windows they carry a .exe suffix. |
| 197 | TOOL_SUFFIX="" |
| 198 | [[ -x "$TOOLCHAIN/bin/llvm-ar.exe" ]] && TOOL_SUFFIX=".exe" |
| 199 |
| 200 | AR_BIN="$TOOLCHAIN/bin/llvm-ar$TOOL_SUFFIX" |
| 201 | NM_BIN="$TOOLCHAIN/bin/llvm-nm$TOOL_SUFFIX" |
| 202 | STRIP_BIN="$TOOLCHAIN/bin/llvm-strip$TOOL_SUFFIX" |
| 203 | RANLIB_BIN="$TOOLCHAIN/bin/llvm-ranlib$TOOL_SUFFIX" |
| 204 | OBJCOPY_BIN="$TOOLCHAIN/bin/llvm-objcopy$TOOL_SUFFIX" |
| 205 | READELF_BIN="$TOOLCHAIN/bin/llvm-readelf$TOOL_SUFFIX" |
| 206 |
| 207 | for tool in "$AR_BIN" "$NM_BIN" "$STRIP_BIN" "$RANLIB_BIN"; do |
| 208 | [[ -x "$tool" ]] || die "Missing NDK tool: $tool" |
| 209 | done |
| 210 | } |
| 211 |
| 212 | # clang driver for an ABI triple. |
| 213 | # |
| 214 | # On Windows the NDK ships two wrappers per triple: an extension-less bash |
| 215 | # script and a ${name}.cmd batch file. Which one is usable depends on who |
| 216 | # spawns it: |
| 217 | # shell (default) - the script. Anything launched through the MSYS shell or |
| 218 | # make can run it, and libvpx's configure only appends the |
| 219 | # required `-c` to ASFLAGS when $AS matches the glob |
| 220 | # `*clang`, which the .cmd name would not. |
| 221 | # native - the .cmd. Required for tools that spawn the compiler |
| 222 | # through CreateProcess without a shell (meson/ninja). |
| 223 | clang_driver() { |
| 224 | local triple="$1" kind="${2:-clang}" flavor="${3:-shell}" base |
| 225 | base="$TOOLCHAIN/bin/${triple}${API}-${kind}" |
| 226 |
| 227 | if [[ "$HOST_IS_WINDOWS" == "1" && "$flavor" == "native" ]]; then |
| 228 | [[ -f "$base.cmd" ]] || die "clang driver was not found: $base.cmd" |
| 229 | printf '%s' "$base.cmd" |
| 230 | return 0 |
| 231 | fi |
| 232 |
| 233 | [[ -f "$base" ]] || die "clang driver was not found: $base" |
| 234 | printf '%s' "$base" |
| 235 | } |
| 236 |
| 237 | # Clang target triple for an ABI. |
| 238 | abi_triple() { |
| 239 | case "$1" in |
| 240 | arm64-v8a) printf 'aarch64-linux-android' ;; |
| 241 | armeabi-v7a) printf 'armv7a-linux-androideabi' ;; |
| 242 | x86_64) printf 'x86_64-linux-android' ;; |
| 243 | x86) printf 'i686-linux-android' ;; |
| 244 | *) die "Unsupported ABI: $1" ;; |
| 245 | esac |
| 246 | } |
| 247 |
| 248 | check_x86_assembler() { |
| 249 | case "$1" in |
| 250 | x86|x86_64) |
| 251 | if ! command -v nasm >/dev/null 2>&1 && ! command -v yasm >/dev/null 2>&1; then |
| 252 | error "NASM or Yasm is required for $1." |
| 253 | echo "Linux: sudo apt install nasm MSYS2: pacman -S nasm" >&2 |
| 254 | return 1 |
| 255 | fi |
| 256 | ;; |
| 257 | esac |
| 258 | } |
| 259 |
| 260 | # --------------------------------------------------------------------------- |
| 261 | # Shared compiler flags |
| 262 | # --------------------------------------------------------------------------- |
| 263 | build_common_cflags() { |
| 264 | local flags="" |
| 265 |
| 266 | # Strip host-specific absolute paths out of DWARF, __FILE__ and |
| 267 | # diagnostics. Windows paths must be passed in native form or clang will |
| 268 | # never match them. |
| 269 | local src_root build_root |
| 270 | src_root="$(to_native_path "$JNI_DIR")" |
| 271 | build_root="$(to_native_path "$BUILD_ROOT")" |
| 272 |
| 273 | flags+=" -ffile-prefix-map=$src_root=/src" |
| 274 | flags+=" -ffile-prefix-map=$build_root=/build" |
| 275 | flags+=" -fdebug-compilation-dir=." |
| 276 |
| 277 | [[ "$FUNCTION_SECTIONS" == "1" ]] && flags+=" -ffunction-sections -fdata-sections" |
| 278 | [[ "$HIDDEN_VISIBILITY" == "1" ]] && flags+=" -fvisibility=hidden" |
| 279 | if [[ "$UNWIND_TABLES" == "0" ]]; then |
| 280 | flags+=" -fno-asynchronous-unwind-tables -fno-unwind-tables" |
| 281 | fi |
| 282 | if [[ "$FRAME_POINTERS" == "1" ]]; then |
| 283 | flags+=" -fno-omit-frame-pointer" |
| 284 | else |
| 285 | flags+=" -fomit-frame-pointer" |
| 286 | fi |
| 287 |
| 288 | printf '%s' "${flags# }" |
| 289 | } |
| 290 |
| 291 | locate_ndk |
| 292 |
| 293 | # Both the libvpx and the FFmpeg configure scripts derive their scratch |
| 294 | # directory from TMPDIR/TEMPDIR/TMP. Under MSYS2 those often carry the Windows |
| 295 | # TEMP value, which mixes separators into every temp-file path the configure |
| 296 | # checks build. Point them at a POSIX directory we own. |
| 297 | if [[ "$HOST_IS_WINDOWS" == "1" ]]; then |
| 298 | TMPDIR="$BUILD_ROOT/tmp" |
| 299 | mkdir -p "$TMPDIR" |
| 300 | export TMPDIR |
| 301 | unset TEMPDIR |
| 302 | fi |
| 303 |
| 304 | COMMON_CFLAGS_BASE="$(build_common_cflags)" |
| 305 | COMMON_CFLAGS="$COMMON_CFLAGS_BASE" |
| 306 | LIBVPX_COMMON_CFLAGS="$COMMON_CFLAGS_BASE" |
| 307 |
| 308 | # -faddrsig emits the address-significance table that -Wl,--icf=safe needs. |
| 309 | # Clang does not enable it by default on Android. libvpx is excluded because |
| 310 | # its `%.a: %_g.a` strip rule zeroes sh_link on the table and lld then rejects |
| 311 | # it under --fatal-warnings; see build_libvpx.sh. |
| 312 | LIBVPX_SKIP_STRIP=0 |
| 313 | if [[ "$ADDRSIG" == "1" ]]; then |
| 314 | COMMON_CFLAGS+=" -faddrsig" |
| 315 | if [[ "$LIBVPX_ADDRSIG" == "1" ]]; then |
| 316 | LIBVPX_COMMON_CFLAGS+=" -faddrsig" |
| 317 | LIBVPX_SKIP_STRIP=1 |
| 318 | fi |
| 319 | fi |
| 320 |
| 321 | # --------------------------------------------------------------------------- |
| 322 | # Packaging |
| 323 | # |
| 324 | # Each component installs into $BUILD_ROOT/<component>/<ABI>/{include,lib}. |
| 325 | # Packaging merges the per-ABI include trees into $PACKAGE_DIR/include and |
| 326 | # copies the archives to $PACKAGE_DIR/<ABI>. Headers that differ between ABIs |
| 327 | # (config-dependent ones) are emitted as <name>.<abi>.h plus a dispatcher |
| 328 | # <name>.h that selects on the predefined ABI macros. |
| 329 | # --------------------------------------------------------------------------- |
| 330 | abi_identifier() { |
| 331 | case "$1" in |
| 332 | arm64-v8a) printf 'arm64_v8a' ;; |
| 333 | armeabi-v7a) printf 'armeabi_v7a' ;; |
| 334 | x86_64) printf 'x86_64' ;; |
| 335 | x86) printf 'x86' ;; |
| 336 | *) die "Unsupported ABI in abi_identifier: $1" ;; |
| 337 | esac |
| 338 | } |
| 339 |
| 340 | abi_cpp_condition() { |
| 341 | case "$1" in |
| 342 | arm64-v8a) printf 'defined(__aarch64__)' ;; |
| 343 | armeabi-v7a) printf 'defined(__arm__) && !defined(__aarch64__)' ;; |
| 344 | x86_64) printf 'defined(__x86_64__)' ;; |
| 345 | x86) printf 'defined(__i386__)' ;; |
| 346 | *) die "Unsupported ABI in abi_cpp_condition: $1" ;; |
| 347 | esac |
| 348 | } |
| 349 |
| 350 | list_relative_files() { |
| 351 | ( cd "$1" && find . -type f -print | sed 's#^\./##' | LC_ALL=C sort ) |
| 352 | } |
| 353 |
| 354 | copy_or_dispatch_header() { |
| 355 | local component="$1" relative_path="$2" source_base="$3" destination_root="$4" |
| 356 | local reference_abi="" reference_file="" abi source_file |
| 357 | local files_identical=1 |
| 358 |
| 359 | for abi in $ABIS; do |
| 360 | source_file="$source_base/$abi/include/$relative_path" |
| 361 | [[ -f "$source_file" ]] || { error "Missing $component header for $abi: $source_file"; return 1; } |
| 362 |
| 363 | if [[ -z "$reference_abi" ]]; then |
| 364 | reference_abi="$abi" |
| 365 | reference_file="$source_file" |
| 366 | elif ! cmp -s "$reference_file" "$source_file"; then |
| 367 | files_identical=0 |
| 368 | fi |
| 369 | done |
| 370 |
| 371 | local destination_file="$destination_root/$relative_path" |
| 372 | mkdir -p "$(dirname "$destination_file")" |
| 373 |
| 374 | if [[ "$files_identical" == "1" ]]; then |
| 375 | if [[ -e "$destination_file" ]] && ! cmp -s "$reference_file" "$destination_file"; then |
| 376 | error "Header collision while packaging: $relative_path" |
| 377 | return 1 |
| 378 | fi |
| 379 | cp -f "$reference_file" "$destination_file" |
| 380 | return 0 |
| 381 | fi |
| 382 |
| 383 | if [[ "$relative_path" != *.h ]]; then |
| 384 | error "$component file differs between ABIs and is not a header: $relative_path" |
| 385 | return 1 |
| 386 | fi |
| 387 |
| 388 | local destination_dir base_name stem |
| 389 | destination_dir="$(dirname "$destination_file")" |
| 390 | base_name="$(basename "$destination_file")" |
| 391 | stem="${base_name%.h}" |
| 392 |
| 393 | local abi_id |
| 394 | for abi in $ABIS; do |
| 395 | abi_id="$(abi_identifier "$abi")" |
| 396 | cp -f "$source_base/$abi/include/$relative_path" "$destination_dir/${stem}.${abi_id}.h" |
| 397 | done |
| 398 |
| 399 | local guard |
| 400 | guard="ANDROID_ABI_DISPATCH_$(printf '%s' "$relative_path" | tr '[:lower:]/.-' '[:upper:]____')" |
| 401 |
| 402 | { |
| 403 | echo "/* Auto-generated ABI dispatcher for $component. */" |
| 404 | echo "#ifndef $guard" |
| 405 | echo "#define $guard" |
| 406 | echo |
| 407 | local first=1 condition |
| 408 | for abi in $ABIS; do |
| 409 | abi_id="$(abi_identifier "$abi")" |
| 410 | condition="$(abi_cpp_condition "$abi")" |
| 411 | if [[ "$first" == "1" ]]; then |
| 412 | echo "#if $condition" |
| 413 | first=0 |
| 414 | else |
| 415 | echo "#elif $condition" |
| 416 | fi |
| 417 | echo "#include \"${stem}.${abi_id}.h\"" |
| 418 | done |
| 419 | echo "#else" |
| 420 | echo "#error Unsupported Android ABI" |
| 421 | echo "#endif" |
| 422 | echo |
| 423 | echo "#endif /* $guard */" |
| 424 | } > "$destination_file" |
| 425 |
| 426 | echo "ABI-dependent header: $component/$relative_path" |
| 427 | } |
| 428 |
| 429 | merge_component_headers() { |
| 430 | local component="$1" source_base="$2" destination_root="$3" |
| 431 | local reference_abi="" reference_manifest="" abi include_dir manifest |
| 432 |
| 433 | local manifest_dir="$BUILD_ROOT/manifests" |
| 434 | mkdir -p "$manifest_dir" |
| 435 |
| 436 | for abi in $ABIS; do |
| 437 | include_dir="$source_base/$abi/include" |
| 438 | [[ -d "$include_dir" ]] || { |
| 439 | error "Missing include directory for $component/$abi: $include_dir" |
| 440 | return 1 |
| 441 | } |
| 442 |
| 443 | manifest="$manifest_dir/${component}.${abi}.headers" |
| 444 | list_relative_files "$include_dir" > "$manifest" |
| 445 |
| 446 | if [[ -z "$reference_abi" ]]; then |
| 447 | reference_abi="$abi" |
| 448 | reference_manifest="$manifest" |
| 449 | elif ! cmp -s "$reference_manifest" "$manifest"; then |
| 450 | error "$component installs a different header set for $reference_abi and $abi." |
| 451 | diff -u "$reference_manifest" "$manifest" || true |
| 452 | return 1 |
| 453 | fi |
| 454 | done |
| 455 |
| 456 | local relative_path |
| 457 | while IFS= read -r relative_path; do |
| 458 | [[ -n "$relative_path" ]] || continue |
| 459 | copy_or_dispatch_header "$component" "$relative_path" "$source_base" "$destination_root" |
| 460 | done < "$reference_manifest" |
| 461 | } |
| 462 |
| 463 | copy_component_libraries() { |
| 464 | local component="$1" source_base="$2" destination_root="$3" |
| 465 | local abi source_lib_dir destination_lib_dir library destination_library |
| 466 |
| 467 | for abi in $ABIS; do |
| 468 | source_lib_dir="$source_base/$abi/lib" |
| 469 | destination_lib_dir="$destination_root/$abi" |
| 470 |
| 471 | [[ -d "$source_lib_dir" ]] || { |
| 472 | error "Missing library directory for $component/$abi: $source_lib_dir" |
| 473 | return 1 |
| 474 | } |
| 475 |
| 476 | mkdir -p "$destination_lib_dir" |
| 477 |
| 478 | while IFS= read -r -d '' library; do |
| 479 | destination_library="$destination_lib_dir/$(basename "$library")" |
| 480 | if [[ -e "$destination_library" ]] && ! cmp -s "$library" "$destination_library"; then |
| 481 | error "Library collision while packaging: $destination_library" |
| 482 | return 1 |
| 483 | fi |
| 484 | cp -f "$library" "$destination_library" |
| 485 | done < <(find "$source_lib_dir" -maxdepth 1 -type f \( -name '*.a' -o -name '*.so' \) -print0) |
| 486 | done |
| 487 | } |
| 488 |