xref: /aosp_15_r20/external/libwebm/infra/compile_android.sh (revision 103e46e4cd4b6efcf6001f23fa8665fb110abf8d)
1#!/bin/bash
2# Copyright (c) 2021, Google Inc. All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7#
8#   * Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10#
11#   * Redistributions in binary form must reproduce the above copyright
12#     notice, this list of conditions and the following disclaimer in
13#     the documentation and/or other materials provided with the
14#     distribution.
15#
16#   * Neither the name of Google nor the names of its contributors may
17#     be used to endorse or promote products derived from this software
18#     without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32set -e
33shopt -s inherit_errexit
34
35LIBWEBM_ROOT="$(realpath "$(dirname "$0")/..")"
36readonly LIBWEBM_ROOT
37readonly WORKSPACE=${WORKSPACE:-"$(mktemp -d)"}
38
39# shellcheck source=infra/common.sh
40source "${LIBWEBM_ROOT}/infra/common.sh"
41
42usage() {
43  cat << EOF
44Usage: $(basename "$0") APP_OPTIM APP_ABI
45Options:
46APP_OPTIM   supported build type (release, debug)
47APP_ABI     supported application binary interface compilation: (armeabi-v7a,
48            arm64-v8a, x86, x86_64)
49Environment variables:
50WORKSPACE   directory where the build is done
51EOF
52}
53
54################################################################################
55echo "Building libwebm for Android in ${WORKSPACE}"
56
57if [[ ! -d "${WORKSPACE}" ]]; then
58  log_err "${WORKSPACE} directory does not exist"
59  exit 1
60fi
61
62APP_OPTIM=${1:?"not defined.$(
63  echo
64  usage
65)"}
66APP_ABI=${2:?"Application Binary Interface not defined.$(
67  echo
68  usage
69)"}
70BUILD_DIR="${WORKSPACE}/build-${APP_OPTIM}"
71
72if ! command -v ndk-build 2> /dev/null; then
73  log_err "unable to find ndk-build in PATH"
74  exit 1
75fi
76
77make_build_dir "${BUILD_DIR}"
78ndk-build -j2 NDK_PROJECT_PATH="${BUILD_DIR}" APP_OPTIM="${APP_OPTIM}" \
79  APP_ABI="${APP_ABI}" APP_BUILD_SCRIPT="${LIBWEBM_ROOT}/Android.mk" \
80  APP_STL="c++_static"
81