1## 2## Copyright (c) 2012 The WebM project authors. All Rights Reserved. 3## 4## Use of this source code is governed by a BSD-style license 5## that can be found in the LICENSE file in the root of the source 6## tree. An additional intellectual property rights grant can be found 7## in the file PATENTS. All contributing project authors may 8## be found in the AUTHORS file in the root of the source tree. 9## 10 11# Ignore this file during non-NDK builds. 12ifdef NDK_ROOT 13# 14# This file is to be used for compiling libvpx for Android using the NDK. 15# In an Android project place a libvpx checkout in the jni directory. 16# Run the configure script from the jni directory. Base libvpx 17# encoder/decoder configuration will look similar to: 18# ./libvpx/configure --target=armv7-android-gcc --disable-examples \ 19# --enable-external-build 20# 21# When targeting Android, realtime-only is enabled by default. This can 22# be overridden by adding the command line flag: 23# --disable-realtime-only 24# 25# This will create .mk files that contain variables that contain the 26# source files to compile. 27# 28# Place an Android.mk file in the jni directory that references the 29# Android.mk file in the libvpx directory: 30# LOCAL_PATH := $(call my-dir) 31# include $(CLEAR_VARS) 32# include jni/libvpx/build/make/Android.mk 33# 34# By default libvpx will use the 'cpufeatures' module from the NDK. This allows 35# the library to be built with all available optimizations (SSE2->AVX512 for 36# x86, NEON for arm, DSPr2 for mips). This can be disabled with 37# --disable-runtime-cpu-detect 38# but the resulting library *must* be run on devices supporting all of the 39# enabled extensions. They can be disabled individually with 40# --disable-{sse2, sse3, ssse3, sse4_1, avx, avx2, avx512} 41# --disable-neon[-asm] 42# --disable-{dspr2, msa} 43 44# 45# Running ndk-build will build libvpx and include it in your project. 46# 47 48CONFIG_DIR := $(LOCAL_PATH)/ 49LIBVPX_PATH := $(LOCAL_PATH)/libvpx 50ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas 51ASM_CNV_PATH := $(LOCAL_PATH)/$(ASM_CNV_PATH_LOCAL) 52ifneq ($(V),1) 53 qexec := @ 54endif 55 56# Use the makefiles generated by upstream configure to determine which files to 57# build. Also set any architecture-specific flags. 58ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) 59 include $(CONFIG_DIR)libs-armv7-android-gcc.mk 60 LOCAL_ARM_MODE := arm 61else ifeq ($(TARGET_ARCH_ABI),arm64-v8a) 62 include $(CONFIG_DIR)libs-arm64-android-gcc.mk 63 LOCAL_ARM_MODE := arm 64else ifeq ($(TARGET_ARCH_ABI),x86) 65 include $(CONFIG_DIR)libs-x86-android-gcc.mk 66else ifeq ($(TARGET_ARCH_ABI),x86_64) 67 include $(CONFIG_DIR)libs-x86_64-android-gcc.mk 68else ifeq ($(TARGET_ARCH_ABI),mips) 69 include $(CONFIG_DIR)libs-mips-android-gcc.mk 70else 71 $(error Not a supported TARGET_ARCH_ABI: $(TARGET_ARCH_ABI)) 72endif 73 74# Rule that is normally in Makefile created by libvpx 75# configure. Used to filter out source files based on configuration. 76enabled=$(filter-out $($(1)-no),$($(1)-yes)) 77 78# Override the relative path that is defined by the libvpx 79# configure process 80SRC_PATH_BARE := $(LIBVPX_PATH) 81 82# Include the list of files to be built 83include $(LIBVPX_PATH)/libs.mk 84 85# Optimise the code. May want to revisit this setting in the future. 86LOCAL_CFLAGS := -O3 87 88# For x86, include the source code in the search path so it will find files 89# like x86inc.asm and x86_abi_support.asm 90LOCAL_ASMFLAGS := -I$(LIBVPX_PATH) 91 92.PRECIOUS: %.asm.S 93$(ASM_CNV_PATH)/libvpx/%.asm.S: $(LIBVPX_PATH)/%.asm 94 $(qexec)mkdir -p $(dir $@) 95 $(qexec)$(CONFIG_DIR)$(ASM_CONVERSION) <$< > $@ 96 97# For building *_rtcd.h, which have rules in libs.mk 98TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN))) 99target := libs 100 101LOCAL_SRC_FILES += vpx_config.c 102 103# Remove duplicate entries 104CODEC_SRCS_UNIQUE = $(sort $(CODEC_SRCS)) 105 106# Pull out C files. vpx_config.c is in the immediate directory and 107# so it does not need libvpx/ prefixed like the rest of the source files. 108# The neon files with intrinsics need to have .neon appended so the proper 109# flags are applied. 110CODEC_SRCS_C = $(filter %.c, $(CODEC_SRCS_UNIQUE)) 111LOCAL_NEON_SRCS_C = $(filter %_neon.c, $(CODEC_SRCS_C)) 112LOCAL_CODEC_SRCS_C = $(filter-out vpx_config.c %_neon.c, $(CODEC_SRCS_C)) 113 114LOCAL_SRC_FILES += $(foreach file, $(LOCAL_CODEC_SRCS_C), libvpx/$(file)) 115ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) 116 LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file).neon) 117else # If there are neon sources then we are building for arm64 and do not need to specify .neon 118 LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file)) 119endif 120 121# Pull out assembly files, splitting NEON from the rest. This is 122# done to specify that the NEON assembly files use NEON assembler flags. 123# x86 assembly matches %.asm, arm matches %.asm.S 124 125# x86: 126 127CODEC_SRCS_ASM_X86 = $(filter %.asm, $(CODEC_SRCS_UNIQUE)) 128LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file)) 129 130# arm: 131CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.S, $(CODEC_SRCS_UNIQUE)) 132CODEC_SRCS_ASM_ARM = $(foreach v, \ 133 $(CODEC_SRCS_ASM_ARM_ALL), \ 134 $(if $(findstring neon,$(v)),,$(v))) 135CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.S, \ 136 $(ASM_CNV_PATH_LOCAL)/libvpx/%.S, \ 137 $(CODEC_SRCS_ASM_ARM)) 138LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS) 139 140ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) 141 ASM_INCLUDES := vpx_dsp/arm/idct_neon.asm.S 142 CODEC_SRCS_ASM_NEON = $(foreach v, \ 143 $(CODEC_SRCS_ASM_ARM_ALL),\ 144 $(if $(findstring neon,$(v)),$(v),)) 145 CODEC_SRCS_ASM_NEON := $(filter-out $(addprefix %, $(ASM_INCLUDES)), \ 146 $(CODEC_SRCS_ASM_NEON)) 147 CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.S, \ 148 $(ASM_CNV_PATH_LOCAL)/libvpx/%.S, \ 149 $(CODEC_SRCS_ASM_NEON)) 150 LOCAL_SRC_FILES += $(patsubst %.S, \ 151 %.S.neon, \ 152 $(CODEC_SRCS_ASM_NEON_ADS2GAS)) 153 154 NEON_ASM_TARGETS = $(patsubst %.S, \ 155 $(ASM_CNV_PATH)/libvpx/%.S, \ 156 $(CODEC_SRCS_ASM_NEON)) 157# add a dependency to the full path to the ads2gas output to ensure the 158# includes are converted first. 159ifneq ($(strip $(NEON_ASM_TARGETS)),) 160$(NEON_ASM_TARGETS): $(addprefix $(ASM_CNV_PATH)/libvpx/, $(ASM_INCLUDES)) 161endif 162endif 163 164LOCAL_CFLAGS += \ 165 -DHAVE_CONFIG_H=vpx_config.h \ 166 -I$(LIBVPX_PATH) \ 167 -I$(ASM_CNV_PATH) \ 168 -I$(ASM_CNV_PATH)/libvpx 169 170LOCAL_MODULE := libvpx 171LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD 172LOCAL_LICENSE_CONDITIONS := notice 173LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../../LICENSE $(LOCAL_PATH)/../../PATENTS 174 175ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes) 176 LOCAL_STATIC_LIBRARIES := cpufeatures 177endif 178 179# Add a dependency to force generation of the RTCD files. 180define rtcd_dep_template 181rtcd_dep_template_SRCS := $(addprefix $(LOCAL_PATH)/, $(LOCAL_SRC_FILES)) 182rtcd_dep_template_SRCS := $$(rtcd_dep_template_SRCS:.neon=) 183ifeq ($(CONFIG_VP8), yes) 184$$(rtcd_dep_template_SRCS): vp8_rtcd.h 185endif 186ifeq ($(CONFIG_VP9), yes) 187$$(rtcd_dep_template_SRCS): vp9_rtcd.h 188endif 189$$(rtcd_dep_template_SRCS): vpx_scale_rtcd.h 190$$(rtcd_dep_template_SRCS): vpx_dsp_rtcd.h 191 192rtcd_dep_template_CONFIG_ASM_ABIS := x86 x86_64 armeabi-v7a 193ifneq ($$(findstring $(TARGET_ARCH_ABI),$$(rtcd_dep_template_CONFIG_ASM_ABIS)),) 194$$(rtcd_dep_template_SRCS): vpx_config.asm 195endif 196endef 197 198$(eval $(call rtcd_dep_template)) 199 200.PHONY: clean 201clean: 202 @echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]" 203 $(qexec)$(RM) $(CODEC_SRCS_ASM_ADS2GAS) $(CODEC_SRCS_ASM_NEON_ADS2GAS) 204 $(qexec)$(RM) -r $(ASM_CNV_PATH) 205 $(qexec)$(RM) $(CLEAN-OBJS) 206 207ifeq ($(ENABLE_SHARED),1) 208 LOCAL_CFLAGS += -fPIC 209 include $(BUILD_SHARED_LIBRARY) 210else 211 include $(BUILD_STATIC_LIBRARY) 212endif 213 214ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes) 215$(call import-module,android/cpufeatures) 216endif 217endif # NDK_ROOT 218