1#!/bin/bash
2
3# Copyright 2024 Google LLC
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# This script will build dav1d for the default ABI targets supported by android.
18# This script only works on linux. You must pass the path to the android NDK as
19# a parameter to this script.
20#
21# Android NDK: https://developer.android.com/ndk/downloads
22#
23# The git tag below is known to work, and will occasionally be updated. Feel
24# free to use a more recent commit.
25
26set -e
27
28if [ $# -ne 1 ]; then
29  echo "Usage: ${0} <path_to_android_ndk>"
30  exit 1
31fi
32
33if [ ! -d dav1d ]; then
34  git clone -b 1.2.1 --depth 1 https://code.videolan.org/videolan/dav1d.git
35fi
36cd dav1d
37mkdir build.android
38cd build.android
39
40# This only works on linux and mac.
41if [ "$(uname)" == "Darwin" ]; then
42  HOST_TAG="darwin"
43else
44  HOST_TAG="linux"
45fi
46android_bin="${1}/toolchains/llvm/prebuilt/${HOST_TAG}-x86_64/bin"
47
48ARCH_LIST=("arm" "aarch64" "x86" "x86_64")
49for i in "${!ARCH_LIST[@]}"; do
50  arch="${ARCH_LIST[i]}"
51  mkdir "${arch}"
52  cd "${arch}"
53  PATH=$PATH:${android_bin} meson setup --default-library=static --buildtype release \
54    --cross-file="../../package/crossfiles/${arch}-android.meson" \
55    -Denable_tools=false -Denable_tests=false ../..
56  PATH=$PATH:${android_bin} ninja -j50
57  cd ..
58done
59
60cd ../..
61