Android.mk 8.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
##
##  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
##
##  Use of this source code is governed by a BSD-style license
##  that can be found in the LICENSE file in the root of the source
##  tree. An additional intellectual property rights grant can be found
##  in the file PATENTS.  All contributing project authors may
##  be found in the AUTHORS file in the root of the source tree.
##

#
# This file is to be used for compiling libvpx for Android using the NDK.
# In an Android project place a libvpx checkout in the jni directory.
# Run the configure script from the jni directory.  Base libvpx
# encoder/decoder configuration will look similar to:
# ./libvpx/configure --target=armv7-android-gcc --disable-examples \
#                    --sdk-path=/opt/android-ndk-r6b/
#
# When targeting Android, realtime-only is enabled by default.  This can
# be overridden by adding the command line flag:
#  --disable-realtime-only
#
# This will create .mk files that contain variables that contain the
# source files to compile.
#
# Place an Android.mk file in the jni directory that references the
# Android.mk file in the libvpx directory:
# LOCAL_PATH := $(call my-dir)
# include $(CLEAR_VARS)
30
# include jni/libvpx/build/make/Android.mk
31 32 33 34 35 36
#
# There are currently two TARGET_ARCH_ABI targets for ARM.
# armeabi and armeabi-v7a.  armeabi-v7a is selected by creating an
# Application.mk in the jni directory that contains:
# APP_ABI := armeabi-v7a
#
37 38 39 40 41 42 43
# By default libvpx will detect at runtime the existance of NEON extension.
# For this we import the 'cpufeatures' module from the NDK sources.
# libvpx can also be configured without this runtime detection method.
# Configuring with --disable-runtime-cpu-detect will assume presence of NEON.
# Configuring with --disable-runtime-cpu-detect --disable-neon will remove any
# NEON dependency.

44
# To change to building armeabi, run ./libvpx/configure again, but with
45
# --target=arm5te-android-gcc and modify the Application.mk file to
46 47 48 49 50
# set APP_ABI := armeabi
#
# Running ndk-build will build libvpx and include it in your project.
#

Johann's avatar
Johann committed
51
CONFIG_DIR := $(LOCAL_PATH)/
52 53 54 55
LIBVPX_PATH := $(LOCAL_PATH)/libvpx
ASM_CNV_PATH_LOCAL := $(TARGET_ARCH_ABI)/ads2gas
ASM_CNV_PATH := $(LOCAL_PATH)/$(ASM_CNV_PATH_LOCAL)

Johann's avatar
Johann committed
56 57
# Use the makefiles generated by upstream configure to determine which files to
# build. Also set any architecture-specific flags.
58
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
Johann's avatar
Johann committed
59
  include $(CONFIG_DIR)libs-armv7-android-gcc.mk
Johann's avatar
Johann committed
60 61
  LOCAL_ARM_MODE := arm
else ifeq  ($(TARGET_ARCH_ABI),armeabi)
Johann's avatar
Johann committed
62
  include $(CONFIG_DIR)libs-armv5te-android-gcc.mk
Johann's avatar
Johann committed
63
  LOCAL_ARM_MODE := arm
64 65 66
else ifeq  ($(TARGET_ARCH_ABI),arm64-v8a)
  include $(CONFIG_DIR)libs-armv8-android-gcc.mk
  LOCAL_ARM_MODE := arm
Johann's avatar
Johann committed
67 68 69 70 71 72
else ifeq ($(TARGET_ARCH_ABI),x86)
  include $(CONFIG_DIR)libs-x86-android-gcc.mk
else ifeq ($(TARGET_ARCH_ABI),mips)
  include $(CONFIG_DIR)libs-mips-android-gcc.mk
else
  $(error Not a supported TARGET_ARCH_ABI: $(TARGET_ARCH_ABI))
73 74 75 76 77 78 79 80 81 82 83 84 85
endif

# Rule that is normally in Makefile created by libvpx
# configure.  Used to filter out source files based on configuration.
enabled=$(filter-out $($(1)-no),$($(1)-yes))

# Override the relative path that is defined by the libvpx
# configure process
SRC_PATH_BARE := $(LIBVPX_PATH)

# Include the list of files to be built
include $(LIBVPX_PATH)/libs.mk

Johann's avatar
Johann committed
86
# Optimise the code. May want to revisit this setting in the future.
87 88
LOCAL_CFLAGS := -O3

Johann's avatar
Johann committed
89 90 91 92
# For x86, include the source code in the search path so it will find files
# like x86inc.asm and x86_abi_support.asm
LOCAL_ASMFLAGS := -I$(LIBVPX_PATH)

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
# -----------------------------------------------------------------------------
# Template  : asm_offsets_template
# Arguments : 1: assembly offsets file to be created
#             2: c file to base assembly offsets on
# Returns   : None
# Usage     : $(eval $(call asm_offsets_template,<asmfile>, <srcfile>
# Rationale : Create offsets at compile time using for structures that are
#             defined in c, but used in assembly functions.
# -----------------------------------------------------------------------------
define asm_offsets_template

_SRC:=$(2)
_OBJ:=$(ASM_CNV_PATH)/$$(notdir $(2)).S

_FLAGS = $$($$(my)CFLAGS) \
          $$(call get-src-file-target-cflags,$(2)) \
          $$(call host-c-includes,$$(LOCAL_C_INCLUDES) $$(CONFIG_DIR)) \
          $$(LOCAL_CFLAGS) \
          $$(NDK_APP_CFLAGS) \
          $$(call host-c-includes,$$($(my)C_INCLUDES)) \
          -DINLINE_ASM \
          -S \

_TEXT = "Compile $$(call get-src-file-text,$(2))"
_CC   = $$(TARGET_CC)

$$(eval $$(call ev-build-file))

$(1) : $$(_OBJ) $(2)
	@mkdir -p $$(dir $$@)
Johann's avatar
Johann committed
123
	@grep $(OFFSET_PATTERN) $$< | tr -d '\#' | $(CONFIG_DIR)$(ASM_CONVERSION) > $$@
124 125
endef

Johann's avatar
Johann committed
126
# Use ads2gas script to convert from RVCT format to GAS format.  This
127 128 129
#  puts the processed file under $(ASM_CNV_PATH).  Local clean rule
#  to handle removing these
ifeq ($(CONFIG_VP8_ENCODER), yes)
130
  ASM_CNV_OFFSETS_DEPEND += $(ASM_CNV_PATH)/vp8_asm_enc_offsets.asm
131
endif
132
ifeq ($(HAVE_NEON_ASM), yes)
Johann's avatar
Johann committed
133 134
  ASM_CNV_OFFSETS_DEPEND += $(ASM_CNV_PATH)/vpx_scale_asm_offsets.asm
endif
135 136 137 138

.PRECIOUS: %.asm.s
$(ASM_CNV_PATH)/libvpx/%.asm.s: $(LIBVPX_PATH)/%.asm $(ASM_CNV_OFFSETS_DEPEND)
	@mkdir -p $(dir $@)
Johann's avatar
Johann committed
139
	@$(CONFIG_DIR)$(ASM_CONVERSION) <$< > $@
140

Johann's avatar
Johann committed
141
# For building *_rtcd.h, which have rules in libs.mk
142 143
TGT_ISA:=$(word 1, $(subst -, ,$(TOOLCHAIN)))
target := libs
144 145 146 147 148 149 150 151

LOCAL_SRC_FILES += vpx_config.c

# Remove duplicate entries
CODEC_SRCS_UNIQUE = $(sort $(CODEC_SRCS))

# Pull out C files.  vpx_config.c is in the immediate directory and
# so it does not need libvpx/ prefixed like the rest of the source files.
Johann's avatar
Johann committed
152 153
# The neon files with intrinsics need to have .neon appended so the proper
# flags are applied.
154
CODEC_SRCS_C = $(filter %.c, $(CODEC_SRCS_UNIQUE))
Johann's avatar
Johann committed
155 156
LOCAL_NEON_SRCS_C = $(filter %_neon.c, $(CODEC_SRCS_C))
LOCAL_CODEC_SRCS_C = $(filter-out vpx_config.c %_neon.c, $(CODEC_SRCS_C))
157 158

LOCAL_SRC_FILES += $(foreach file, $(LOCAL_CODEC_SRCS_C), libvpx/$(file))
159 160 161 162 163
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
  LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file).neon)
else # If there are neon sources then we are building for arm64 and do not need to specify .neon
  LOCAL_SRC_FILES += $(foreach file, $(LOCAL_NEON_SRCS_C), libvpx/$(file))
endif
164 165 166

# Pull out assembly files, splitting NEON from the rest.  This is
# done to specify that the NEON assembly files use NEON assembler flags.
Johann's avatar
Johann committed
167 168 169 170 171 172 173 174 175 176 177 178
# x86 assembly matches %.asm, arm matches %.asm.s

# x86:

CODEC_SRCS_ASM_X86 = $(filter %.asm, $(CODEC_SRCS_UNIQUE))
LOCAL_SRC_FILES += $(foreach file, $(CODEC_SRCS_ASM_X86), libvpx/$(file))

# arm:
CODEC_SRCS_ASM_ARM_ALL = $(filter %.asm.s, $(CODEC_SRCS_UNIQUE))
CODEC_SRCS_ASM_ARM = $(foreach v, \
                     $(CODEC_SRCS_ASM_ARM_ALL), \
                     $(if $(findstring neon,$(v)),,$(v)))
179 180
CODEC_SRCS_ASM_ADS2GAS = $(patsubst %.s, \
                         $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
Johann's avatar
Johann committed
181
                         $(CODEC_SRCS_ASM_ARM))
182 183 184 185
LOCAL_SRC_FILES += $(CODEC_SRCS_ASM_ADS2GAS)

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
  CODEC_SRCS_ASM_NEON = $(foreach v, \
Johann's avatar
Johann committed
186
                        $(CODEC_SRCS_ASM_ARM_ALL),\
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
                        $(if $(findstring neon,$(v)),$(v),))
  CODEC_SRCS_ASM_NEON_ADS2GAS = $(patsubst %.s, \
                                $(ASM_CNV_PATH_LOCAL)/libvpx/%.s, \
                                $(CODEC_SRCS_ASM_NEON))
  LOCAL_SRC_FILES += $(patsubst %.s, \
                     %.s.neon, \
                     $(CODEC_SRCS_ASM_NEON_ADS2GAS))
endif

LOCAL_CFLAGS += \
    -DHAVE_CONFIG_H=vpx_config.h \
    -I$(LIBVPX_PATH) \
    -I$(ASM_CNV_PATH)

LOCAL_MODULE := libvpx

LOCAL_LDLIBS := -llog

205 206 207
ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
  LOCAL_STATIC_LIBRARIES := cpufeatures
endif
208

Johann's avatar
Johann committed
209 210 211 212 213 214 215 216
# Add a dependency to force generation of the RTCD files.
ifeq ($(CONFIG_VP8), yes)
$(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vp8_rtcd.h
endif
ifeq ($(CONFIG_VP9), yes)
$(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vp9_rtcd.h
endif
$(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_scale_rtcd.h
217

Johann's avatar
Johann committed
218 219 220 221
ifeq ($(TARGET_ARCH_ABI),x86)
$(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_config.asm
endif

222 223 224 225 226 227
.PHONY: clean
clean:
	@echo "Clean: ads2gas files [$(TARGET_ARCH_ABI)]"
	@$(RM) $(CODEC_SRCS_ASM_ADS2GAS) $(CODEC_SRCS_ASM_NEON_ADS2GAS)
	@$(RM) $(patsubst %.asm, %.*, $(ASM_CNV_OFFSETS_DEPEND))
	@$(RM) -r $(ASM_CNV_PATH)
228
	@$(RM) $(CLEAN-OBJS)
229 230 231

include $(BUILD_SHARED_LIBRARY)

Johann's avatar
Johann committed
232
ifeq ($(HAVE_NEON), yes)
233
  $(eval $(call asm_offsets_template,\
Johann's avatar
Johann committed
234 235
    $(ASM_CNV_PATH)/vpx_scale_asm_offsets.asm, \
    $(LIBVPX_PATH)/vpx_scale/vpx_scale_asm_offsets.c))
236 237 238 239
endif

ifeq ($(CONFIG_VP8_ENCODER), yes)
  $(eval $(call asm_offsets_template,\
240 241
    $(ASM_CNV_PATH)/vp8_asm_enc_offsets.asm, \
    $(LIBVPX_PATH)/vp8/encoder/vp8_asm_enc_offsets.c))
242 243
endif

244
ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
245
$(call import-module,cpufeatures)
246
endif