Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / libvpx / source / libvpx / build / make / Android.mk
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=arm5te-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
52 CONFIG_DIR := $(LOCAL_PATH)/
53 LIBVPX_PATH := $(LOCAL_PATH)/libvpx
54 ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas
55 ASM_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.
59 ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
60   include $(CONFIG_DIR)libs-armv7-android-gcc.mk
61   LOCAL_ARM_MODE := arm
62 else ifeq  ($(TARGET_ARCH_ABI),armeabi)
63   include $(CONFIG_DIR)libs-armv5te-android-gcc.mk
64   LOCAL_ARM_MODE := arm
65 else ifeq  ($(TARGET_ARCH_ABI),arm64-v8a)
66   include $(CONFIG_DIR)libs-armv8-android-gcc.mk
67   LOCAL_ARM_MODE := arm
68 else ifeq ($(TARGET_ARCH_ABI),x86)
69   include $(CONFIG_DIR)libs-x86-android-gcc.mk
70 else ifeq ($(TARGET_ARCH_ABI),mips)
71   include $(CONFIG_DIR)libs-mips-android-gcc.mk
72 else
73   $(error Not a supported TARGET_ARCH_ABI: $(TARGET_ARCH_ABI))
74 endif
75
76 # Rule that is normally in Makefile created by libvpx
77 # configure.  Used to filter out source files based on configuration.
78 enabled=$(filter-out $($(1)-no),$($(1)-yes))
79
80 # Override the relative path that is defined by the libvpx
81 # configure process
82 SRC_PATH_BARE := $(LIBVPX_PATH)
83
84 # Include the list of files to be built
85 include $(LIBVPX_PATH)/libs.mk
86
87 # Optimise the code. May want to revisit this setting in the future.
88 LOCAL_CFLAGS := -O3
89
90 # For x86, include the source code in the search path so it will find files
91 # like x86inc.asm and x86_abi_support.asm
92 LOCAL_ASMFLAGS := -I$(LIBVPX_PATH)
93
94 # -----------------------------------------------------------------------------
95 # Template  : asm_offsets_template
96 # Arguments : 1: assembly offsets file to be created
97 #             2: c file to base assembly offsets on
98 # Returns   : None
99 # Usage     : $(eval $(call asm_offsets_template,<asmfile>, <srcfile>
100 # Rationale : Create offsets at compile time using for structures that are
101 #             defined in c, but used in assembly functions.
102 # -----------------------------------------------------------------------------
103 define asm_offsets_template
104
105 _SRC:=$(2)
106 _OBJ:=$(ASM_CNV_PATH)/$$(notdir $(2)).S
107
108 _FLAGS = $$($$(my)CFLAGS) \
109           $$(call get-src-file-target-cflags,$(2)) \
110           $$(call host-c-includes,$$(LOCAL_C_INCLUDES) $$(CONFIG_DIR)) \
111           $$(LOCAL_CFLAGS) \
112           $$(NDK_APP_CFLAGS) \
113           $$(call host-c-includes,$$($(my)C_INCLUDES)) \
114           -DINLINE_ASM \
115           -S \
116
117 _TEXT = "Compile $$(call get-src-file-text,$(2))"
118 _CC   = $$(TARGET_CC)
119
120 $$(eval $$(call ev-build-file))
121
122 $(1) : $$(_OBJ) $(2)
123         @mkdir -p $$(dir $$@)
124         @grep $(OFFSET_PATTERN) $$< | tr -d '\#' | $(CONFIG_DIR)$(ASM_CONVERSION) > $$@
125 endef
126
127 # Use ads2gas script to convert from RVCT format to GAS format.  This
128 #  puts the processed file under $(ASM_CNV_PATH).  Local clean rule
129 #  to handle removing these
130 ifeq ($(CONFIG_VP8_ENCODER), yes)
131   ASM_CNV_OFFSETS_DEPEND += $(ASM_CNV_PATH)/vp8_asm_enc_offsets.asm
132 endif
133 ifeq ($(HAVE_NEON_ASM), yes)
134   ASM_CNV_OFFSETS_DEPEND += $(ASM_CNV_PATH)/vpx_scale_asm_offsets.asm
135 endif
136
137 .PRECIOUS: %.asm.s
138 $(ASM_CNV_PATH)/libvpx/%.asm.s: $(LIBVPX_PATH)/%.asm $(ASM_CNV_OFFSETS_DEPEND)
139         @mkdir -p $(dir $@)
140         @$(CONFIG_DIR)$(ASM_CONVERSION) <$< > $@
141
142 # For building *_rtcd.h, which have rules in libs.mk
143 TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
144 target := libs
145
146 LOCAL_SRC_FILES += vpx_config.c
147
148 # Remove duplicate entries
149 CODEC_SRCS_UNIQUE = $(sort $(CODEC_SRCS))
150
151 # Pull out C files.  vpx_config.c is in the immediate directory and
152 # so it does not need libvpx/ prefixed like the rest of the source files.
153 # The neon files with intrinsics need to have .neon appended so the proper
154 # flags are applied.
155 CODEC_SRCS_C = $(filter %.c, $(CODEC_SRCS_UNIQUE))
156 LOCAL_NEON_SRCS_C = $(filter %_neon.c, $(CODEC_SRCS_C))
157 LOCAL_CODEC_SRCS_C = $(filter-out vpx_config.c %_neon.c, $(CODEC_SRCS_C))
158
159 LOCAL_SRC_FILES += $(foreach file, $(LOCAL_CODEC_SRCS_C), libvpx/$(file))
160 ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
161   LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file).neon)
162 else # If there are neon sources then we are building for arm64 and do not need to specify .neon
163   LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file))
164 endif
165
166 # Pull out assembly files, splitting NEON from the rest.  This is
167 # done to specify that the NEON assembly files use NEON assembler flags.
168 # x86 assembly matches %.asm, arm matches %.asm.s
169
170 # x86:
171
172 CODEC_SRCS_ASM_X86 = $(filter %.asm, $(CODEC_SRCS_UNIQUE))
173 LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file))
174
175 # arm:
176 CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.s, $(CODEC_SRCS_UNIQUE))
177 CODEC_SRCS_ASM_ARM = $(foreach v, \
178                      $(CODEC_SRCS_ASM_ARM_ALL), \
179                      $(if $(findstring neon,$(v)),,$(v)))
180 CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.s, \
181                          $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
182                          $(CODEC_SRCS_ASM_ARM))
183 LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS)
184
185 ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
186   CODEC_SRCS_ASM_NEON = $(foreach v, \
187                         $(CODEC_SRCS_ASM_ARM_ALL),\
188                         $(if $(findstring neon,$(v)),$(v),))
189   CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.s, \
190                                 $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
191                                 $(CODEC_SRCS_ASM_NEON))
192   LOCAL_SRC_FILES += $(patsubst %.s, \
193                      %.s.neon, \
194                      $(CODEC_SRCS_ASM_NEON_ADS2GAS))
195 endif
196
197 LOCAL_CFLAGS += \
198     -DHAVE_CONFIG_H=vpx_config.h \
199     -I$(LIBVPX_PATH) \
200     -I$(ASM_CNV_PATH)
201
202 LOCAL_MODULE := libvpx
203
204 LOCAL_LDLIBS := -llog
205
206 ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
207   LOCAL_STATIC_LIBRARIES := cpufeatures
208 endif
209
210 # Add a dependency to force generation of the RTCD files.
211 ifeq ($(CONFIG_VP8), yes)
212 $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vp8_rtcd.h
213 endif
214 ifeq ($(CONFIG_VP9), yes)
215 $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vp9_rtcd.h
216 endif
217 $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_scale_rtcd.h
218
219 ifeq ($(TARGET_ARCH_ABI),x86)
220 $(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_config.asm
221 endif
222
223 .PHONY: clean
224 clean:
225         @echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]"
226         @$(RM) $(CODEC_SRCS_ASM_ADS2GAS) $(CODEC_SRCS_ASM_NEON_ADS2GAS)
227         @$(RM) $(patsubst %.asm, %.*, $(ASM_CNV_OFFSETS_DEPEND))
228         @$(RM) -r $(ASM_CNV_PATH)
229         @$(RM) $(CLEAN-OBJS)
230
231 include $(BUILD_SHARED_LIBRARY)
232
233 ifeq ($(HAVE_NEON), yes)
234   $(eval $(call asm_offsets_template,\
235     $(ASM_CNV_PATH)/vpx_scale_asm_offsets.asm, \
236     $(LIBVPX_PATH)/vpx_scale/vpx_scale_asm_offsets.c))
237 endif
238
239 ifeq ($(CONFIG_VP8_ENCODER), yes)
240   $(eval $(call asm_offsets_template,\
241     $(ASM_CNV_PATH)/vp8_asm_enc_offsets.asm, \
242     $(LIBVPX_PATH)/vp8/encoder/vp8_asm_enc_offsets.c))
243 endif
244
245 ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
246 $(call import-module,cpufeatures)
247 endif