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