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