Home | History | Annotate | Download | only in make
      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 # By default libvpx will detect at runtime the existance of NEON extension.
     33 # For this we import the 'cpufeatures' module from the NDK sources.
     34 # libvpx can also be configured without this runtime detection method.
     35 # Configuring with --disable-runtime-cpu-detect will assume presence of NEON.
     36 # Configuring with --disable-runtime-cpu-detect --disable-neon \
     37 #     --disable-neon-asm
     38 # will remove any NEON dependency.
     39 
     40 #
     41 # Running ndk-build will build libvpx and include it in your project.
     42 #
     43 
     44 # Alternatively, building the examples and unit tests can be accomplished in the
     45 # following way:
     46 #
     47 # Create a standalone toolchain from the NDK:
     48 # https://developer.android.com/ndk/guides/standalone_toolchain.html
     49 #
     50 # For example - to test on arm64 devices with clang:
     51 # $NDK/build/tools/make_standalone_toolchain.py \
     52 #   --arch arm64 --install-dir=/tmp/my-android-toolchain
     53 # export PATH=/tmp/my-android-toolchain/bin:$PATH
     54 # CROSS=aarch64-linux-android- CC=clang CXX=clang++ /path/to/libvpx/configure \
     55 #   --target=arm64-android-gcc
     56 #
     57 # Push the resulting binaries to a device and run them:
     58 # adb push test_libvpx /data/tmp/test_libvpx
     59 # adb shell /data/tmp/test_libvpx --gtest_filter=\*Sixtap\*
     60 #
     61 # Make sure to push the test data as well and set LIBVPX_TEST_DATA
     62 
     63 CONFIG_DIR := $(LOCAL_PATH)/
     64 LIBVPX_PATH := $(LOCAL_PATH)/libvpx
     65 ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas
     66 ASM_CNV_PATH := $(LOCAL_PATH)/$(ASM_CNV_PATH_LOCAL)
     67 ifneq ($(V),1)
     68   qexec := @
     69 endif
     70 
     71 # Use the makefiles generated by upstream configure to determine which files to
     72 # build. Also set any architecture-specific flags.
     73 ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
     74   include $(CONFIG_DIR)libs-armv7-android-gcc.mk
     75   LOCAL_ARM_MODE := arm
     76 else ifeq  ($(TARGET_ARCH_ABI),arm64-v8a)
     77   include $(CONFIG_DIR)libs-arm64-android-gcc.mk
     78   LOCAL_ARM_MODE := arm
     79 else ifeq ($(TARGET_ARCH_ABI),x86)
     80   include $(CONFIG_DIR)libs-x86-android-gcc.mk
     81 else ifeq ($(TARGET_ARCH_ABI),x86_64)
     82   include $(CONFIG_DIR)libs-x86_64-android-gcc.mk
     83 else ifeq ($(TARGET_ARCH_ABI),mips)
     84   include $(CONFIG_DIR)libs-mips-android-gcc.mk
     85 else
     86   $(error Not a supported TARGET_ARCH_ABI: $(TARGET_ARCH_ABI))
     87 endif
     88 
     89 # Rule that is normally in Makefile created by libvpx
     90 # configure.  Used to filter out source files based on configuration.
     91 enabled=$(filter-out $($(1)-no),$($(1)-yes))
     92 
     93 # Override the relative path that is defined by the libvpx
     94 # configure process
     95 SRC_PATH_BARE := $(LIBVPX_PATH)
     96 
     97 # Include the list of files to be built
     98 include $(LIBVPX_PATH)/libs.mk
     99 
    100 # Optimise the code. May want to revisit this setting in the future.
    101 LOCAL_CFLAGS := -O3
    102 
    103 # For x86, include the source code in the search path so it will find files
    104 # like x86inc.asm and x86_abi_support.asm
    105 LOCAL_ASMFLAGS := -I$(LIBVPX_PATH)
    106 
    107 .PRECIOUS: %.asm.S
    108 $(ASM_CNV_PATH)/libvpx/%.asm.S: $(LIBVPX_PATH)/%.asm
    109 	$(qexec)mkdir -p $(dir $@)
    110 	$(qexec)$(CONFIG_DIR)$(ASM_CONVERSION) <$< > $@
    111 
    112 # For building *_rtcd.h, which have rules in libs.mk
    113 TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
    114 target := libs
    115 
    116 LOCAL_SRC_FILES += vpx_config.c
    117 
    118 # Remove duplicate entries
    119 CODEC_SRCS_UNIQUE = $(sort $(CODEC_SRCS))
    120 
    121 # Pull out C files.  vpx_config.c is in the immediate directory and
    122 # so it does not need libvpx/ prefixed like the rest of the source files.
    123 # The neon files with intrinsics need to have .neon appended so the proper
    124 # flags are applied.
    125 CODEC_SRCS_C = $(filter %.c, $(CODEC_SRCS_UNIQUE))
    126 LOCAL_NEON_SRCS_C = $(filter %_neon.c, $(CODEC_SRCS_C))
    127 LOCAL_CODEC_SRCS_C = $(filter-out vpx_config.c %_neon.c, $(CODEC_SRCS_C))
    128 
    129 LOCAL_SRC_FILES += $(foreach file, $(LOCAL_CODEC_SRCS_C), libvpx/$(file))
    130 ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
    131   LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file).neon)
    132 else # If there are neon sources then we are building for arm64 and do not need to specify .neon
    133   LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file))
    134 endif
    135 
    136 # Pull out assembly files, splitting NEON from the rest.  This is
    137 # done to specify that the NEON assembly files use NEON assembler flags.
    138 # x86 assembly matches %.asm, arm matches %.asm.S
    139 
    140 # x86:
    141 
    142 CODEC_SRCS_ASM_X86 = $(filter %.asm, $(CODEC_SRCS_UNIQUE))
    143 LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file))
    144 
    145 # arm:
    146 CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.S, $(CODEC_SRCS_UNIQUE))
    147 CODEC_SRCS_ASM_ARM = $(foreach v, \
    148                      $(CODEC_SRCS_ASM_ARM_ALL), \
    149                      $(if $(findstring neon,$(v)),,$(v)))
    150 CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.S, \
    151                          $(ASM_CNV_PATH_LOCAL)/libvpx/%.S, \
    152                          $(CODEC_SRCS_ASM_ARM))
    153 LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS)
    154 
    155 ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
    156   ASM_INCLUDES := vpx_dsp/arm/idct_neon.asm.S
    157   CODEC_SRCS_ASM_NEON = $(foreach v, \
    158                         $(CODEC_SRCS_ASM_ARM_ALL),\
    159                         $(if $(findstring neon,$(v)),$(v),))
    160   CODEC_SRCS_ASM_NEON := $(filter-out $(addprefix %, $(ASM_INCLUDES)), \
    161                          $(CODEC_SRCS_ASM_NEON))
    162   CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.S, \
    163                                 $(ASM_CNV_PATH_LOCAL)/libvpx/%.S, \
    164                                 $(CODEC_SRCS_ASM_NEON))
    165   LOCAL_SRC_FILES += $(patsubst %.S, \
    166                      %.S.neon, \
    167                      $(CODEC_SRCS_ASM_NEON_ADS2GAS))
    168 
    169   NEON_ASM_TARGETS = $(patsubst %.S, \
    170                      $(ASM_CNV_PATH)/libvpx/%.S, \
    171                      $(CODEC_SRCS_ASM_NEON))
    172 # add a dependency to the full path to the ads2gas output to ensure the
    173 # includes are converted first.
    174 ifneq ($(strip $(NEON_ASM_TARGETS)),)
    175 $(NEON_ASM_TARGETS): $(addprefix $(ASM_CNV_PATH)/libvpx/, $(ASM_INCLUDES))
    176 endif
    177 endif
    178 
    179 LOCAL_CFLAGS += \
    180     -DHAVE_CONFIG_H=vpx_config.h \
    181     -I$(LIBVPX_PATH) \
    182     -I$(ASM_CNV_PATH) \
    183     -I$(ASM_CNV_PATH)/libvpx
    184 
    185 LOCAL_MODULE := libvpx
    186 
    187 ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
    188   LOCAL_STATIC_LIBRARIES := cpufeatures
    189 endif
    190 
    191 # Add a dependency to force generation of the RTCD files.
    192 define rtcd_dep_template
    193 rtcd_dep_template_SRCS := $(addprefix $(LOCAL_PATH)/, $(LOCAL_SRC_FILES))
    194 rtcd_dep_template_SRCS := $$(rtcd_dep_template_SRCS:.neon=)
    195 ifeq ($(CONFIG_VP8), yes)
    196 $$(rtcd_dep_template_SRCS): vp8_rtcd.h
    197 endif
    198 ifeq ($(CONFIG_VP9), yes)
    199 $$(rtcd_dep_template_SRCS): vp9_rtcd.h
    200 endif
    201 $$(rtcd_dep_template_SRCS): vpx_scale_rtcd.h
    202 $$(rtcd_dep_template_SRCS): vpx_dsp_rtcd.h
    203 
    204 rtcd_dep_template_CONFIG_ASM_ABIS := x86 x86_64 armeabi-v7a
    205 ifneq ($$(findstring $(TARGET_ARCH_ABI),$$(rtcd_dep_template_CONFIG_ASM_ABIS)),)
    206 $$(rtcd_dep_template_SRCS): vpx_config.asm
    207 endif
    208 endef
    209 
    210 $(eval $(call rtcd_dep_template))
    211 
    212 .PHONY: clean
    213 clean:
    214 	@echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]"
    215 	$(qexec)$(RM) $(CODEC_SRCS_ASM_ADS2GAS) $(CODEC_SRCS_ASM_NEON_ADS2GAS)
    216 	$(qexec)$(RM) -r $(ASM_CNV_PATH)
    217 	$(qexec)$(RM) $(CLEAN-OBJS)
    218 
    219 ifeq ($(ENABLE_SHARED),1)
    220   LOCAL_CFLAGS += -fPIC
    221   include $(BUILD_SHARED_LIBRARY)
    222 else
    223   include $(BUILD_STATIC_LIBRARY)
    224 endif
    225 
    226 ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
    227 $(call import-module,android/cpufeatures)
    228 endif
    229