Android.mk 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. # This file is to be used for compiling libvpx for Android using the NDK.
  12. # In an Android project place a libvpx checkout in the jni directory.
  13. # Run the configure script from the jni directory. Base libvpx
  14. # encoder/decoder configuration will look similar to:
  15. # ./libvpx/configure --target=armv7-android-gcc --disable-examples \
  16. # --sdk-path=/opt/android-ndk-r6b/
  17. #
  18. # When targeting Android, realtime-only is enabled by default. This can
  19. # be overridden by adding the command line flag:
  20. # --disable-realtime-only
  21. #
  22. # This will create .mk files that contain variables that contain the
  23. # source files to compile.
  24. #
  25. # Place an Android.mk file in the jni directory that references the
  26. # Android.mk file in the libvpx directory:
  27. # LOCAL_PATH := $(call my-dir)
  28. # include $(CLEAR_VARS)
  29. # include jni/libvpx/build/make/Android.mk
  30. #
  31. # By default libvpx will detect at runtime the existance of NEON extension.
  32. # For this we import the 'cpufeatures' module from the NDK sources.
  33. # libvpx can also be configured without this runtime detection method.
  34. # Configuring with --disable-runtime-cpu-detect will assume presence of NEON.
  35. # Configuring with --disable-runtime-cpu-detect --disable-neon \
  36. # --disable-neon-asm
  37. # will remove any NEON dependency.
  38. #
  39. # Running ndk-build will build libvpx and include it in your project.
  40. #
  41. # Alternatively, building the examples and unit tests can be accomplished in the
  42. # following way:
  43. #
  44. # Create a standalone toolchain from the NDK:
  45. # https://developer.android.com/ndk/guides/standalone_toolchain.html
  46. #
  47. # For example - to test on arm64 devices with clang:
  48. # $NDK/build/tools/make_standalone_toolchain.py \
  49. # --arch arm64 --install-dir=/tmp/my-android-toolchain
  50. # export PATH=/tmp/my-android-toolchain/bin:$PATH
  51. # CROSS=aarch64-linux-android- CC=clang CXX=clang++ /path/to/libvpx/configure \
  52. # --target=arm64-android-gcc
  53. #
  54. # Push the resulting binaries to a device and run them:
  55. # adb push test_libvpx /data/tmp/test_libvpx
  56. # adb shell /data/tmp/test_libvpx --gtest_filter=\*Sixtap\*
  57. #
  58. # Make sure to push the test data as well and set LIBVPX_TEST_DATA
  59. CONFIG_DIR := $(LOCAL_PATH)/
  60. LIBVPX_PATH := $(LOCAL_PATH)/libvpx
  61. ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas
  62. ASM_CNV_PATH := $(LOCAL_PATH)/$(ASM_CNV_PATH_LOCAL)
  63. ifneq ($(V),1)
  64. qexec := @
  65. endif
  66. # Use the makefiles generated by upstream configure to determine which files to
  67. # build. Also set any architecture-specific flags.
  68. ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
  69. include $(CONFIG_DIR)libs-armv7-android-gcc.mk
  70. LOCAL_ARM_MODE := arm
  71. else ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
  72. include $(CONFIG_DIR)libs-arm64-android-gcc.mk
  73. LOCAL_ARM_MODE := arm
  74. else ifeq ($(TARGET_ARCH_ABI),x86)
  75. include $(CONFIG_DIR)libs-x86-android-gcc.mk
  76. else ifeq ($(TARGET_ARCH_ABI),x86_64)
  77. include $(CONFIG_DIR)libs-x86_64-android-gcc.mk
  78. else ifeq ($(TARGET_ARCH_ABI),mips)
  79. include $(CONFIG_DIR)libs-mips-android-gcc.mk
  80. else
  81. $(error Not a supported TARGET_ARCH_ABI: $(TARGET_ARCH_ABI))
  82. endif
  83. # Rule that is normally in Makefile created by libvpx
  84. # configure. Used to filter out source files based on configuration.
  85. enabled=$(filter-out $($(1)-no),$($(1)-yes))
  86. # Override the relative path that is defined by the libvpx
  87. # configure process
  88. SRC_PATH_BARE := $(LIBVPX_PATH)
  89. # Include the list of files to be built
  90. include $(LIBVPX_PATH)/libs.mk
  91. # Optimise the code. May want to revisit this setting in the future.
  92. LOCAL_CFLAGS := -O3
  93. # For x86, include the source code in the search path so it will find files
  94. # like x86inc.asm and x86_abi_support.asm
  95. LOCAL_ASMFLAGS := -I$(LIBVPX_PATH)
  96. .PRECIOUS: %.asm.S
  97. $(ASM_CNV_PATH)/libvpx/%.asm.S: $(LIBVPX_PATH)/%.asm
  98. $(qexec)mkdir -p $(dir $@)
  99. $(qexec)$(CONFIG_DIR)$(ASM_CONVERSION) <$< > $@
  100. # For building *_rtcd.h, which have rules in libs.mk
  101. TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
  102. target := libs
  103. LOCAL_SRC_FILES += vpx_config.c
  104. # Remove duplicate entries
  105. CODEC_SRCS_UNIQUE = $(sort $(CODEC_SRCS))
  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.
  110. CODEC_SRCS_C = $(filter %.c, $(CODEC_SRCS_UNIQUE))
  111. LOCAL_NEON_SRCS_C = $(filter %_neon.c, $(CODEC_SRCS_C))
  112. LOCAL_CODEC_SRCS_C = $(filter-out vpx_config.c %_neon.c, $(CODEC_SRCS_C))
  113. LOCAL_SRC_FILES += $(foreach file, $(LOCAL_CODEC_SRCS_C), libvpx/$(file))
  114. ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
  115. LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file).neon)
  116. else # 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))
  118. endif
  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. # x86:
  123. CODEC_SRCS_ASM_X86 = $(filter %.asm, $(CODEC_SRCS_UNIQUE))
  124. LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file))
  125. # arm:
  126. CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.S, $(CODEC_SRCS_UNIQUE))
  127. CODEC_SRCS_ASM_ARM = $(foreach v, \
  128. $(CODEC_SRCS_ASM_ARM_ALL), \
  129. $(if $(findstring neon,$(v)),,$(v)))
  130. CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.S, \
  131. $(ASM_CNV_PATH_LOCAL)/libvpx/%.S, \
  132. $(CODEC_SRCS_ASM_ARM))
  133. LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS)
  134. ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
  135. ASM_INCLUDES := vpx_dsp/arm/idct_neon.asm.S
  136. CODEC_SRCS_ASM_NEON = $(foreach v, \
  137. $(CODEC_SRCS_ASM_ARM_ALL),\
  138. $(if $(findstring neon,$(v)),$(v),))
  139. CODEC_SRCS_ASM_NEON := $(filter-out $(addprefix %, $(ASM_INCLUDES)), \
  140. $(CODEC_SRCS_ASM_NEON))
  141. CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.S, \
  142. $(ASM_CNV_PATH_LOCAL)/libvpx/%.S, \
  143. $(CODEC_SRCS_ASM_NEON))
  144. LOCAL_SRC_FILES += $(patsubst %.S, \
  145. %.S.neon, \
  146. $(CODEC_SRCS_ASM_NEON_ADS2GAS))
  147. NEON_ASM_TARGETS = $(patsubst %.S, \
  148. $(ASM_CNV_PATH)/libvpx/%.S, \
  149. $(CODEC_SRCS_ASM_NEON))
  150. # add a dependency to the full path to the ads2gas output to ensure the
  151. # includes are converted first.
  152. ifneq ($(strip $(NEON_ASM_TARGETS)),)
  153. $(NEON_ASM_TARGETS): $(addprefix $(ASM_CNV_PATH)/libvpx/, $(ASM_INCLUDES))
  154. endif
  155. endif
  156. LOCAL_CFLAGS += \
  157. -DHAVE_CONFIG_H=vpx_config.h \
  158. -I$(LIBVPX_PATH) \
  159. -I$(ASM_CNV_PATH) \
  160. -I$(ASM_CNV_PATH)/libvpx
  161. LOCAL_MODULE := libvpx
  162. ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
  163. LOCAL_STATIC_LIBRARIES := cpufeatures
  164. endif
  165. # Add a dependency to force generation of the RTCD files.
  166. define rtcd_dep_template
  167. rtcd_dep_template_SRCS := $(addprefix $(LOCAL_PATH)/, $(LOCAL_SRC_FILES))
  168. rtcd_dep_template_SRCS := $$(rtcd_dep_template_SRCS:.neon=)
  169. ifeq ($(CONFIG_VP8), yes)
  170. $$(rtcd_dep_template_SRCS): vp8_rtcd.h
  171. endif
  172. ifeq ($(CONFIG_VP9), yes)
  173. $$(rtcd_dep_template_SRCS): vp9_rtcd.h
  174. endif
  175. $$(rtcd_dep_template_SRCS): vpx_scale_rtcd.h
  176. $$(rtcd_dep_template_SRCS): vpx_dsp_rtcd.h
  177. rtcd_dep_template_CONFIG_ASM_ABIS := x86 x86_64 armeabi-v7a
  178. ifneq ($$(findstring $(TARGET_ARCH_ABI),$$(rtcd_dep_template_CONFIG_ASM_ABIS)),)
  179. $$(rtcd_dep_template_SRCS): vpx_config.asm
  180. endif
  181. endef
  182. $(eval $(call rtcd_dep_template))
  183. .PHONY: clean
  184. clean:
  185. @echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]"
  186. $(qexec)$(RM) $(CODEC_SRCS_ASM_ADS2GAS) $(CODEC_SRCS_ASM_NEON_ADS2GAS)
  187. $(qexec)$(RM) -r $(ASM_CNV_PATH)
  188. $(qexec)$(RM) $(CLEAN-OBJS)
  189. ifeq ($(ENABLE_SHARED),1)
  190. LOCAL_CFLAGS += -fPIC
  191. include $(BUILD_SHARED_LIBRARY)
  192. else
  193. include $(BUILD_STATIC_LIBRARY)
  194. endif
  195. ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
  196. $(call import-module,android/cpufeatures)
  197. endif