| 6 |
| # |
| 7 | # Requires meson, ninja, python3 and pkg-config on PATH. |
| 8 |
| 9 | source "$(dirname -- "${BASH_SOURCE[0]}")/build_common.sh" |
| 10 |
| 11 | [[ -f "$DAV1D_SOURCE_DIR/meson.build" ]] || die "dav1d sources were not found in: $DAV1D_SOURCE_DIR |
| 12 | Run: git submodule update --init TMessagesProj/jni/third_party/dav1d" |
| 13 | DAV1D_SOURCE_DIR="$(cd "$DAV1D_SOURCE_DIR" && pwd)" |
| 14 |
| 15 | for tool in meson ninja python3 pkg-config; do |
| 16 | command -v "$tool" >/dev/null 2>&1 || die "Required dav1d build tool is missing: $tool" |
| 17 | done |
| 18 |
| 19 | write_dav1d_cross_file() { |
| 20 | local abi="$1" file="$2" |
| 21 | local triple cpu_family cpu extra_c_args |
| 22 |
| 23 | triple="$(abi_triple "$abi")" |
| 24 | case "$abi" in |
| 25 | armeabi-v7a) |
| 26 | cpu_family="arm" |
| 27 | cpu="armv7-a" |
| 28 | extra_c_args="'-march=armv7-a', '-mthumb', '-mfpu=neon', '-mfloat-abi=softfp'" |
| 29 | ;; |
| 30 | arm64-v8a) |
| 31 | cpu_family="aarch64" |
| 32 | cpu="armv8-a" |
| 33 | extra_c_args="'-march=armv8-a'" |
| 34 | ;; |
| 35 | x86) |
| 36 | cpu_family="x86" |
| 37 | cpu="i686" |
| 38 | extra_c_args="'-march=i686', '-msse3', '-mfpmath=sse'" |
| 39 | ;; |
| 40 | x86_64) |
| 41 | cpu_family="x86_64" |
| 42 | cpu="x86_64" |
| 43 | extra_c_args="'-march=x86-64', '-msse4.1'" |
| 44 | ;; |
| 45 | *) error "Unsupported ABI for dav1d: $abi"; return 1 ;; |
| 46 | esac |
| 47 |
| 48 | # Meson spawns the compiler directly, so the binaries must be given in the |
| 49 | # host's native form (a .cmd wrapper and Windows paths on MINGW64). |
| 50 | local cc |
| 51 | cc="$(clang_driver "$triple" clang native)" |
| 52 |
| 53 | # Meson wants a quoted list, so turn COMMON_CFLAGS into "'a', 'b'". |
| 54 | local shared_c_args="" flag |
| 55 | for flag in $COMMON_CFLAGS; do |
| 56 | shared_c_args+=", '$flag'" |
| 57 | done |
| 58 |
| 59 | cat > "$file" <<EOF |
| 60 | [binaries] |
| 61 | c = '$(to_native_path "$cc")' |
| 62 | ar = '$(to_native_path "$AR_BIN")' |
| 63 | strip = '$(to_native_path "$STRIP_BIN")' |
| 64 | ranlib = '$(to_native_path "$RANLIB_BIN")' |
| 65 | nm = '$(to_native_path "$NM_BIN")' |
| 66 | objcopy = '$(to_native_path "$OBJCOPY_BIN")' |
| 67 | pkg-config = 'pkg-config' |
| 68 |
| 69 | [host_machine] |
| 70 | system = 'android' |
| 71 | cpu_family = '$cpu_family' |
| 72 | cpu = '$cpu' |
| 73 | endian = 'little' |
| 74 |
| 75 | [properties] |
| 76 | needs_exe_wrapper = true |
| 77 |
| 78 | [built-in options] |
| 79 | c_args = [$extra_c_args, '-fPIC'$shared_c_args] |
| 80 | c_link_args = ['-Wl,--gc-sections'] |
| 81 | EOF |
| 82 | } |
| 83 |
| 84 | verify_dav1d_archive() { |
| 85 | local abi="$1" library="$2" |
| 86 |
| 87 | [[ -f "$library" ]] || { error "Missing dav1d archive for $abi: $library"; return 1; } |
| 88 |
| 89 | if ! "$NM_BIN" -g --defined-only "$library" \ |
| 90 | | awk '$NF == "dav1d_open" { found = 1 } END { exit found ? 0 : 1 }'; |
| 91 | then |
| 92 | error "dav1d_open was not found in $library" |
| 93 | return 1 |
| 94 | fi |
| 95 | } |
| 96 |
| 97 | build_dav1d_for_abi() { |
| 98 | local abi="$1" |
| 99 | check_x86_assembler "$abi" || return 1 |
| 100 |
| 101 | local prefix="$DAV1D_OUTPUT_DIR/$abi" |
| 102 | local build_dir="$DAV1D_WORK_DIR/$abi" |
| 103 | local cross_file="$DAV1D_WORK_DIR/crossfiles/$abi.ini" |
| 104 |
| 105 | if [[ "$CLEAN" == "1" ]]; then |
| 106 | rm -rf "$build_dir" "$prefix" |
| 107 | fi |
| 108 | mkdir -p "$build_dir" "$prefix" "$(dirname "$cross_file")" |
| 109 | write_dav1d_cross_file "$abi" "$cross_file" || return 1 |
| 110 |
| 111 | echo |
| 112 | echo "========== dav1d: $abi, API $API ==========" |
| 113 |
| 114 | # Meson resolves the prefix and build directory itself (it may be a native |
| 115 | # Windows Python), so hand it host-native paths. |
| 116 | if ! meson setup "$(to_native_path "$build_dir")" "$(to_native_path "$DAV1D_SOURCE_DIR")" \ |
| 117 | --cross-file "$(to_native_path "$cross_file")" \ |
| 118 | --prefix "$(to_native_path "$prefix")" \ |
| 119 | --libdir lib \ |
| 120 | --buildtype release \ |
| 121 | --default-library static \ |
| 122 | -Db_ndebug=true \ |
| 123 | -Db_lto=false \ |
| 124 | -Denable_tools=false \ |
| 125 | -Denable_examples=false \ |
| 126 | -Denable_tests=false \ |
| 127 | -Denable_docs=false \ |
| 128 | -Denable_asm=true; |
| 129 | then |
| 130 | error "dav1d configure failed for $abi." |
| 131 | return 1 |
| 132 | fi |
| 133 |
| 134 | local native_build_dir |
| 135 | native_build_dir="$(to_native_path "$build_dir")" |
| 136 |
| 137 | if ! ninja -C "$native_build_dir" -j "$JOBS" 2>&1 | tee "$build_dir/build.log"; then |
| 138 | error "dav1d build failed for $abi. Log: $build_dir/build.log" |
| 139 | return 1 |
| 140 | fi |
| 141 |
| 142 | if ! ninja -C "$native_build_dir" install 2>&1 | tee "$build_dir/install.log"; then |
| 143 | error "dav1d install failed for $abi. Log: $build_dir/install.log" |
| 144 | return 1 |
| 145 | fi |
| 146 |
| 147 | verify_dav1d_archive "$abi" "$prefix/lib/libdav1d.a" || return 1 |
| 148 | [[ -f "$prefix/include/dav1d/dav1d.h" ]] || { error "Missing dav1d headers for $abi"; return 1; } |
| 149 | [[ -f "$prefix/lib/pkgconfig/dav1d.pc" ]] || { error "Missing dav1d.pc for $abi"; return 1; } |
| 150 | } |
| 151 |
| 152 | TARGET_ABIS="${*:-$ABIS}" |
| 153 |
| 154 | mkdir -p "$DAV1D_WORK_DIR" "$DAV1D_OUTPUT_DIR" |
| 155 |
| 156 | for abi in $TARGET_ABIS; do |
| 157 | build_dav1d_for_abi "$abi" |
| 158 | done |
| 159 |
| 160 | echo |
| 161 | echo "dav1d install: $DAV1D_OUTPUT_DIR/<ABI>" |
| 162 |