mirror of
git://f0xx.org/android_cast
synced 2026-07-29 06:39:09 +03:00
110 lines
3.0 KiB
Bash
Executable File
110 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build libvpx for Android ABIs and produce libvpx.a for ANDROIDCAST_LIBVPX_LIB.
|
|
#
|
|
# Prerequisites:
|
|
# git submodule update --init third-party/libvpx
|
|
# Android NDK (ndk.dir in local.properties)
|
|
#
|
|
# Usage:
|
|
# ./scripts/build-native-codecs.sh arm64-v8a
|
|
# ANDROIDCAST_LIBVPX_LIB=$PWD/build/native/arm64-v8a/libvpx.a ./gradlew assembleDebug
|
|
#
|
|
# Note: libvpx Makefiles do not support spaces in paths (SRC_PATH_BARE). If the repo
|
|
# path contains spaces, this script builds under /tmp and copies libvpx.a back.
|
|
#
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
ABI="${1:-arm64-v8a}"
|
|
VPX_SRC_REAL="$ROOT/third-party/libvpx"
|
|
PROJECT_OUT="$ROOT/build/native/$ABI"
|
|
OUT="$PROJECT_OUT"
|
|
BUILD_DIR="$OUT/libvpx-build"
|
|
|
|
if [[ ! -d "$VPX_SRC_REAL" ]]; then
|
|
echo "ERROR: $VPX_SRC_REAL missing. Run:"
|
|
echo " git submodule update --init third-party/libvpx"
|
|
exit 1
|
|
fi
|
|
|
|
NDK=""
|
|
if [[ -f "$ROOT/local.properties" ]]; then
|
|
NDK="$(sed -n 's/^ndk\.dir=//p' "$ROOT/local.properties" | tr -d '\r' | head -1)"
|
|
fi
|
|
if [[ -z "$NDK" && -n "${ANDROID_NDK_HOME:-}" ]]; then
|
|
NDK="$ANDROID_NDK_HOME"
|
|
fi
|
|
if [[ -z "$NDK" && -n "${ANDROID_NDK_ROOT:-}" ]]; then
|
|
NDK="$ANDROID_NDK_ROOT"
|
|
fi
|
|
if [[ -z "$NDK" || ! -d "$NDK" ]]; then
|
|
echo "ERROR: Set ndk.dir in local.properties or ANDROID_NDK_HOME"
|
|
exit 1
|
|
fi
|
|
|
|
case "$ABI" in
|
|
arm64-v8a) VPX_TARGET=arm64-android-gcc ;;
|
|
armeabi-v7a) VPX_TARGET=armv7-android-gcc ;;
|
|
x86_64) VPX_TARGET=x86_64-android-gcc ;;
|
|
x86) VPX_TARGET=x86-android-gcc ;;
|
|
*)
|
|
echo "Unsupported ABI: $ABI"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# libvpx: include $(SRC_PATH_BARE)/foo.mk breaks when SRC_PATH_BARE has spaces.
|
|
path_has_space() {
|
|
case "$1" in
|
|
*" "*) return 0 ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
VPX_SRC="$VPX_SRC_REAL"
|
|
STAGING=""
|
|
if path_has_space "$ROOT" || path_has_space "$VPX_SRC_REAL"; then
|
|
STAGING="/tmp/androidcast-libvpx-${USER:-build}"
|
|
VPX_SRC="$STAGING/src"
|
|
BUILD_DIR="$STAGING/build/$ABI"
|
|
OUT="$STAGING/out/$ABI"
|
|
mkdir -p "$STAGING/build" "$STAGING/out"
|
|
ln -sfn "$VPX_SRC_REAL" "$VPX_SRC"
|
|
echo "Repo path contains spaces; using space-free staging under $STAGING"
|
|
fi
|
|
|
|
mkdir -p "$BUILD_DIR" "$OUT" "$PROJECT_OUT"
|
|
export ANDROID_NDK_ROOT="$NDK"
|
|
export PATH="$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
|
|
|
|
echo "Building libvpx for $ABI (target=$VPX_TARGET) ..."
|
|
echo " source: $VPX_SRC"
|
|
echo " build: $BUILD_DIR"
|
|
|
|
cd "$BUILD_DIR"
|
|
if [[ ! -f Makefile ]]; then
|
|
"$VPX_SRC/configure" \
|
|
--target="$VPX_TARGET" \
|
|
--disable-examples \
|
|
--disable-tools \
|
|
--disable-unit-tests \
|
|
--disable-webm-io \
|
|
--enable-vp8 \
|
|
--enable-vp9 \
|
|
--enable-static \
|
|
--disable-shared \
|
|
--extra-cflags="-fPIC -O2"
|
|
fi
|
|
make -j"$(nproc)" libvpx.a
|
|
cp -f libvpx.a "$OUT/libvpx.a"
|
|
cp -f "$OUT/libvpx.a" "$PROJECT_OUT/libvpx.a"
|
|
|
|
echo ""
|
|
echo "Built: $PROJECT_OUT/libvpx.a"
|
|
if [[ -n "$STAGING" ]]; then
|
|
echo "(staged under $STAGING because of spaces in repo path)"
|
|
fi
|
|
echo "Rebuild APK with:"
|
|
echo " export ANDROIDCAST_LIBVPX_LIB=$PROJECT_OUT/libvpx.a"
|
|
echo " ./gradlew assembleDebug"
|