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