Android.mk 7.4 KB

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