mirror of
git://f0xx.org/android_cast
synced 2026-07-29 07:58:10 +03:00
snap
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build libvpx for Android ABIs and produce libvpx.a for ANDROIDCAST_LIBVPX_LIB.
|
||||
#
|
||||
# With --enable-external-build, libvpx does not provide a libvpx.a make target;
|
||||
# this script uses the NDK (ndk-build) + generated Android.mk, as upstream intends.
|
||||
#
|
||||
# Prerequisites:
|
||||
# git submodule update --init third-party/libvpx
|
||||
# Android NDK (ndk.dir in local.properties)
|
||||
# Android NDK (ndk.dir in local.properties or ANDROID_NDK_HOME)
|
||||
#
|
||||
# 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
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
ABI="${1:-arm64-v8a}"
|
||||
@@ -37,10 +37,15 @@ fi
|
||||
if [[ -z "$NDK" && -n "${ANDROID_NDK_ROOT:-}" ]]; then
|
||||
NDK="$ANDROID_NDK_ROOT"
|
||||
fi
|
||||
NDK="${NDK%/}"
|
||||
if [[ -z "$NDK" || ! -d "$NDK" ]]; then
|
||||
echo "ERROR: Set ndk.dir in local.properties or ANDROID_NDK_HOME"
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -x "$NDK/ndk-build" ]]; then
|
||||
echo "ERROR: ndk-build not found under $NDK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$ABI" in
|
||||
arm64-v8a) VPX_TARGET=arm64-android-gcc ;;
|
||||
@@ -53,7 +58,7 @@ case "$ABI" in
|
||||
;;
|
||||
esac
|
||||
|
||||
# libvpx: include $(SRC_PATH_BARE)/foo.mk breaks when SRC_PATH_BARE has spaces.
|
||||
# libvpx Makefiles break on spaces in SRC_PATH_BARE.
|
||||
path_has_space() {
|
||||
case "$1" in
|
||||
*" "*) return 0 ;;
|
||||
@@ -82,7 +87,32 @@ echo " source: $VPX_SRC"
|
||||
echo " build: $BUILD_DIR"
|
||||
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
# Out-of-tree build fails if someone previously ran configure inside third-party/libvpx.
|
||||
if [[ -f "$VPX_SRC/vpx_config.h" ]]; then
|
||||
src_real="$(cd "$VPX_SRC" && pwd)"
|
||||
build_real="$(pwd)"
|
||||
if [[ "$src_real" != "$build_real" ]]; then
|
||||
echo "Cleaning in-tree configure artifacts from libvpx source (needed for out-of-tree build)..."
|
||||
make -C "$VPX_SRC" distclean >/dev/null 2>&1 || true
|
||||
rm -f "$VPX_SRC"/vpx_config.h "$VPX_SRC"/vpx_config.c "$VPX_SRC"/vpx_version.h \
|
||||
"$VPX_SRC"/config.mk "$VPX_SRC"/Makefile
|
||||
rm -f "$VPX_SRC"/libs-*.mk "$VPX_SRC"/vp*_rtcd.h "$VPX_SRC"/libvpx*.a 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
LIBS_MK="$BUILD_DIR/libs-${VPX_TARGET}.mk"
|
||||
need_configure=false
|
||||
if [[ ! -f Makefile ]]; then
|
||||
need_configure=true
|
||||
elif [[ ! -f "$LIBS_MK" ]] || ! grep -q "^TOOLCHAIN := ${VPX_TARGET}\$" "$BUILD_DIR/config.mk" 2>/dev/null; then
|
||||
echo "Re-configuring (stale or wrong ABI in $BUILD_DIR)..."
|
||||
make distclean >/dev/null 2>&1 || rm -f Makefile config.mk "$LIBS_MK" vpx_config.h vpx_config.c vpx_config.asm \
|
||||
vpx_version.h vp8_rtcd.h vp9_rtcd.h vpx_scale_rtcd.h vpx_dsp_rtcd.h
|
||||
need_configure=true
|
||||
fi
|
||||
|
||||
if $need_configure; then
|
||||
"$VPX_SRC/configure" \
|
||||
--target="$VPX_TARGET" \
|
||||
--disable-examples \
|
||||
@@ -107,8 +137,67 @@ if [[ ! -f Makefile ]]; then
|
||||
--disable-docs \
|
||||
--enable-external-build
|
||||
fi
|
||||
make -j"$(nproc)" libvpx.a
|
||||
cp -f libvpx.a "$OUT/libvpx.a"
|
||||
|
||||
# armeabi-v7a ndk-build runs make in ndk-app/ and needs vpx_config.asm (not required for arm64).
|
||||
make vpx_config.asm 2>/dev/null || true
|
||||
if [[ -f "$BUILD_DIR/vpx_config.asm" ]] && [[ ! -s "$BUILD_DIR/vpx_config.asm" ]]; then
|
||||
rm -f "$BUILD_DIR/vpx_config.asm"
|
||||
make vpx_config.asm
|
||||
fi
|
||||
|
||||
# RTCD headers (configure creates them; refresh if missing).
|
||||
make -j1 vp8_rtcd.h vp9_rtcd.h vpx_scale_rtcd.h vpx_dsp_rtcd.h
|
||||
|
||||
# NDK project root must not contain libvpx's top-level Makefile (ndk-build would invoke it).
|
||||
NDK_ROOT="$BUILD_DIR/ndk-app"
|
||||
JNI_DIR="$NDK_ROOT/jni"
|
||||
rm -rf "$NDK_ROOT"
|
||||
mkdir -p "$JNI_DIR"
|
||||
ln -sfn "$VPX_SRC" "$JNI_DIR/libvpx"
|
||||
|
||||
# NDK Android.mk prepends jni/ to ASM_CONVERSION; keep the configure-generated absolute path
|
||||
# in BUILD_DIR for `make vpx_config.asm`, and use a jni-only copy for ndk-build.
|
||||
LIBS_MK_NDK="$BUILD_DIR/libs-ndk-${VPX_TARGET}.mk"
|
||||
if [[ -f "$LIBS_MK" ]]; then
|
||||
cp -f "$LIBS_MK" "$LIBS_MK_NDK"
|
||||
sed -i 's|^ASM_CONVERSION=.*|ASM_CONVERSION=libvpx/build/make/ads2gas.pl|' "$LIBS_MK_NDK"
|
||||
fi
|
||||
|
||||
for f in config.mk vpx_config.c vpx_config.h vpx_config.asm vpx_version.h \
|
||||
vp8_rtcd.h vp9_rtcd.h vpx_scale_rtcd.h vpx_dsp_rtcd.h; do
|
||||
if [[ -f "$BUILD_DIR/$f" ]]; then
|
||||
ln -sfn "$BUILD_DIR/$f" "$JNI_DIR/$f"
|
||||
# ndk-build may invoke make in ndk-app/ (not jni/) for RTCD / vpx_config.asm on armeabi-v7a.
|
||||
ln -sfn "$BUILD_DIR/$f" "$NDK_ROOT/$f"
|
||||
fi
|
||||
done
|
||||
if [[ -f "$LIBS_MK_NDK" ]]; then
|
||||
ln -sfn "$LIBS_MK_NDK" "$JNI_DIR/libs-${VPX_TARGET}.mk"
|
||||
fi
|
||||
|
||||
cat > "$JNI_DIR/Application.mk" <<EOF
|
||||
APP_ABI := $ABI
|
||||
APP_PLATFORM := android-29
|
||||
APP_STL := c++_static
|
||||
EOF
|
||||
|
||||
cat > "$JNI_DIR/Android.mk" <<'EOF'
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
# configure outputs (RTCD headers, vpx_config.h) live in jni/ — not inside libvpx sources
|
||||
LOCAL_CFLAGS += -I$(LOCAL_PATH)
|
||||
include $(LOCAL_PATH)/libvpx/build/make/Android.mk
|
||||
EOF
|
||||
|
||||
"$NDK/ndk-build" -C "$NDK_ROOT" -j"$(nproc)"
|
||||
|
||||
LIBVPX_A="$NDK_ROOT/obj/local/$ABI/libvpx.a"
|
||||
if [[ ! -f "$LIBVPX_A" ]]; then
|
||||
echo "ERROR: expected $LIBVPX_A after ndk-build"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp -f "$LIBVPX_A" "$OUT/libvpx.a"
|
||||
cp -f "$OUT/libvpx.a" "$PROJECT_OUT/libvpx.a"
|
||||
|
||||
echo ""
|
||||
@@ -116,6 +205,7 @@ 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 "Build other ABIs as needed, e.g.:"
|
||||
echo " ./scripts/build-native-codecs.sh armeabi-v7a"
|
||||
echo "Then rebuild the APK (CMake picks build/native/<abi>/libvpx.a per ABI):"
|
||||
echo " ./gradlew assembleDebug"
|
||||
|
||||
Reference in New Issue
Block a user