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#                    --sdk-path=/opt/android-ndk-r6b/
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# There are currently two TARGET_ARCH_ABI targets for ARM.
33# armeabi and armeabi-v7a.  armeabi-v7a is selected by creating an
34# Application.mk in the jni directory that contains:
35# APP_ABI := armeabi-v7a
36#
37# By default libvpx will detect at runtime the existance of NEON extension.
38# For this we import the 'cpufeatures' module from the NDK sources.
39# libvpx can also be configured without this runtime detection method.
40# Configuring with --disable-runtime-cpu-detect will assume presence of NEON.
41# Configuring with --disable-runtime-cpu-detect --disable-neon \
42#     --disable-neon-asm
43# will remove any NEON dependency.
44
45# To change to building armeabi, run ./libvpx/configure again, but with
46# --target=armv6-android-gcc and modify the Application.mk file to
47# set APP_ABI := armeabi
48#
49# Running ndk-build will build libvpx and include it in your project.
50#
51
52CONFIG_DIR := $(LOCAL_PATH)/
53LIBVPX_PATH := $(LOCAL_PATH)/libvpx
54ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas
55ASM_CNV_PATH := $(LOCAL_PATH)/$(ASM_CNV_PATH_LOCAL)
56
57# Use the makefiles generated by upstream configure to determine which files to
58# build. Also set any architecture-specific flags.
59ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
60  include $(CONFIG_DIR)libs-armv7-android-gcc.mk
61  LOCAL_ARM_MODE := arm
62else ifeq  ($(TARGET_ARCH_ABI),armeabi)
63  include $(CONFIG_DIR)libs-armv6-android-gcc.mk
64  LOCAL_ARM_MODE := arm
65else ifeq  ($(TARGET_ARCH_ABI),arm64-v8a)
66  include $(CONFIG_DIR)libs-armv8-android-gcc.mk
67  LOCAL_ARM_MODE := arm
68else ifeq ($(TARGET_ARCH_ABI),x86)
69  include $(CONFIG_DIR)libs-x86-android-gcc.mk
70else ifeq ($(TARGET_ARCH_ABI),x86_64)
71  include $(CONFIG_DIR)libs-x86_64-android-gcc.mk
72else ifeq ($(TARGET_ARCH_ABI),mips)
73  include $(CONFIG_DIR)libs-mips-android-gcc.mk
74else
75  $(error Not a supported TARGET_ARCH_ABI: $(TARGET_ARCH_ABI))
76endif
77
78# Rule that is normally in Makefile created by libvpx
79# configure.  Used to filter out source files based on configuration.
80enabled=$(filter-out $($(1)-no),$($(1)-yes))
81
82# Override the relative path that is defined by the libvpx
83# configure process
84SRC_PATH_BARE := $(LIBVPX_PATH)
85
86# Include the list of files to be built
87include $(LIBVPX_PATH)/libs.mk
88
89# Optimise the code. May want to revisit this setting in the future.
90LOCAL_CFLAGS := -O3
91
92# For x86, include the source code in the search path so it will find files
93# like x86inc.asm and x86_abi_support.asm
94LOCAL_ASMFLAGS := -I$(LIBVPX_PATH)
95
96.PRECIOUS: %.asm.s
97$(ASM_CNV_PATH)/libvpx/%.asm.s: $(LIBVPX_PATH)/%.asm
98	@mkdir -p $(dir $@)
99	@$(CONFIG_DIR)$(ASM_CONVERSION) <$< > $@
100
101# For building *_rtcd.h, which have rules in libs.mk
102TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
103target := libs
104
105LOCAL_SRC_FILES += vpx_config.c
106
107# Remove duplicate entries
108CODEC_SRCS_UNIQUE = $(sort $(CODEC_SRCS))
109
110# Pull out C files.  vpx_config.c is in the immediate directory and
111# so it does not need libvpx/ prefixed like the rest of the source files.
112# The neon files with intrinsics need to have .neon appended so the proper
113# flags are applied.
114CODEC_SRCS_C = $(filter %.c, $(CODEC_SRCS_UNIQUE))
115LOCAL_NEON_SRCS_C = $(filter %_neon.c, $(CODEC_SRCS_C))
116LOCAL_CODEC_SRCS_C = $(filter-out vpx_config.c %_neon.c, $(CODEC_SRCS_C))
117
118LOCAL_SRC_FILES += $(foreach file, $(LOCAL_CODEC_SRCS_C), libvpx/$(file))
119ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
120  LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file).neon)
121else # If there are neon sources then we are building for arm64 and do not need to specify .neon
122  LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file))
123endif
124
125# Pull out assembly files, splitting NEON from the rest.  This is
126# done to specify that the NEON assembly files use NEON assembler flags.
127# x86 assembly matches %.asm, arm matches %.asm.s
128
129# x86:
130
131CODEC_SRCS_ASM_X86 = $(filter %.asm, $(CODEC_SRCS_UNIQUE))
132LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file))
133
134# arm:
135CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.s, $(CODEC_SRCS_UNIQUE))
136CODEC_SRCS_ASM_ARM = $(foreach v, \
137                     $(CODEC_SRCS_ASM_ARM_ALL), \
138                     $(if $(findstring neon,$(v)),,$(v)))
139CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.s, \
140                         $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
141                         $(CODEC_SRCS_ASM_ARM))
142LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS)
143
144ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
145  CODEC_SRCS_ASM_NEON = $(foreach v, \
146                        $(CODEC_SRCS_ASM_ARM_ALL),\
147                        $(if $(findstring neon,$(v)),$(v),))
148  CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.s, \
149                                $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
150                                $(CODEC_SRCS_ASM_NEON))
151  LOCAL_SRC_FILES += $(patsubst %.s, \
152                     %.s.neon, \
153                     $(CODEC_SRCS_ASM_NEON_ADS2GAS))
154endif
155
156LOCAL_CFLAGS += \
157    -DHAVE_CONFIG_H=vpx_config.h \
158    -I$(LIBVPX_PATH) \
159    -I$(ASM_CNV_PATH)
160
161LOCAL_MODULE := libvpx
162
163ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
164  LOCAL_STATIC_LIBRARIES := cpufeatures
165endif
166
167# Add a dependency to force generation of the RTCD files.
168define rtcd_dep_template
169rtcd_dep_template_SRCS := $(addprefix $(LOCAL_PATH)/, $(LOCAL_SRC_FILES))
170rtcd_dep_template_SRCS := $$(rtcd_dep_template_SRCS:.neon=)
171ifeq ($(CONFIG_VP8), yes)
172$$(rtcd_dep_template_SRCS): vp8_rtcd.h
173endif
174ifeq ($(CONFIG_VP9), yes)
175$$(rtcd_dep_template_SRCS): vp9_rtcd.h
176endif
177ifeq ($(CONFIG_VP10), yes)
178$$(rtcd_dep_template_SRCS): vp10_rtcd.h
179endif
180$$(rtcd_dep_template_SRCS): vpx_scale_rtcd.h
181$$(rtcd_dep_template_SRCS): vpx_dsp_rtcd.h
182
183ifneq ($(findstring $(TARGET_ARCH_ABI),x86 x86_64),)
184$$(rtcd_dep_template_SRCS): vpx_config.asm
185endif
186endef
187
188$(eval $(call rtcd_dep_template))
189
190.PHONY: clean
191clean:
192	@echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]"
193	@$(RM) $(CODEC_SRCS_ASM_ADS2GAS) $(CODEC_SRCS_ASM_NEON_ADS2GAS)
194	@$(RM) -r $(ASM_CNV_PATH)
195	@$(RM) $(CLEAN-OBJS)
196
197ifeq ($(ENABLE_SHARED),1)
198  include $(BUILD_SHARED_LIBRARY)
199else
200  include $(BUILD_STATIC_LIBRARY)
201endif
202
203ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
204$(call import-module,cpufeatures)
205endif
206