1# Rules to generate assembly.
2# Input variables:
3#   libvpx_2nd_arch
4#   libvpx_source_dir
5#   libvpx_config_dir_<arch>
6#   libvpx_codec_srcs_asm_<arch>
7#
8# Output variables:
9#   LOCAL_GENERATED_SOURCES_<arch>
10#   LOCAL_C_INCLUDES_<arch>
11#
12
13# ARM and x86 use an 'offsets' file in the assembly. It is generated by
14# tricking the compiler and generating non-functional output which is then
15# processed with grep. For ARM, this must be additionally converted from
16# RVCT (ARM's in-house compiler) format to GNU Assembler Format for gcc.
17
18# Offset files are currently used in vpx_scale for NEON and some encoder
19# functions used in both ARM and x86. These files can not be compiled and need
20# to be named accordingly to avoid auto-build rules. The encoder files are not
21# used yet but are included in the comments for future reference.
22
23libvpx_asm_offsets_intermediates := \
24    vp8/encoder/vp8_asm_enc_offsets.intermediate \
25    vpx_scale/vpx_scale_asm_offsets.intermediate \
26
27libvpx_asm_offsets_files := \
28    vp8/encoder/vp8_asm_enc_offsets.asm \
29    vpx_scale/vpx_scale_asm_offsets.asm \
30
31libvpx_intermediates := $(call local-intermediates-dir,,$(libvpx_2nd_arch))
32# Build the S files with inline assembly.
33COMPILE_TO_S := $(addprefix $(libvpx_intermediates)/, $(libvpx_asm_offsets_intermediates))
34$(COMPILE_TO_S) : PRIVATE_2ND_ARCH := $(libvpx_2nd_arch)
35$(COMPILE_TO_S) : PRIVATE_INTERMEDIATES := $(libvpx_intermediates)
36$(COMPILE_TO_S) : PRIVATE_SOURCE_DIR := $(libvpx_source_dir)
37$(COMPILE_TO_S) : PRIVATE_CONFIG_DIR := $(libvpx_config_dir_$(TARGET_$(libvpx_2nd_arch)ARCH))
38$(COMPILE_TO_S) : PRIVATE_CUSTOM_TOOL = $($(PRIVATE_2ND_ARCH)TARGET_CC) -S $(addprefix -I, $($(PRIVATE_2ND_ARCH)TARGET_C_INCLUDES)) -I $(PRIVATE_INTERMEDIATES) -I $(PRIVATE_SOURCE_DIR) -I $(PRIVATE_CONFIG_DIR) -DINLINE_ASM -o $@ $<
39$(COMPILE_TO_S) : $(libvpx_intermediates)/%.intermediate : $(libvpx_source_dir)/%.c
40	$(transform-generated-source)
41
42# Extract the offsets from the inline assembly.
43OFFSETS_GEN := $(addprefix $(libvpx_intermediates)/, $(libvpx_asm_offsets_files))
44$(OFFSETS_GEN) : PRIVATE_OFFSET_PATTERN := '^[a-zA-Z0-9_]* EQU'
45$(OFFSETS_GEN) : PRIVATE_SOURCE_DIR := $(libvpx_source_dir)
46$(OFFSETS_GEN) : PRIVATE_CUSTOM_TOOL = grep $(PRIVATE_OFFSET_PATTERN) $< | tr -d '$$\#' | perl $(PRIVATE_SOURCE_DIR)/build/make/ads2gas.pl > $@
47$(OFFSETS_GEN) : %.asm : %.intermediate
48	$(transform-generated-source)
49
50LOCAL_GENERATED_SOURCES_$(TARGET_$(libvpx_2nd_arch)ARCH) += $(OFFSETS_GEN)
51
52ifneq ($(strip $(libvpx_codec_srcs_asm_$(TARGET_$(libvpx_2nd_arch)ARCH))),)
53# This step is only required for ARM. MIPS uses intrinsics and x86 requires an
54# assembler to pre-process its assembly files.
55# The ARM assembly sources must be converted from ADS to GAS compatible format.
56VPX_GEN := $(addprefix $(libvpx_intermediates)/, $(libvpx_codec_srcs_asm_$(TARGET_$(libvpx_2nd_arch)ARCH)))
57$(VPX_GEN) : PRIVATE_SOURCE_DIR := $(libvpx_source_dir)
58$(VPX_GEN) : PRIVATE_CUSTOM_TOOL = cat $< | perl $(PRIVATE_SOURCE_DIR)/build/make/ads2gas.pl > $@
59$(VPX_GEN) : $(libvpx_intermediates)/%.s : $(libvpx_source_dir)/%
60	$(transform-generated-source)
61
62LOCAL_GENERATED_SOURCES_$(TARGET_$(libvpx_2nd_arch)ARCH) += $(VPX_GEN)
63endif
64
65LOCAL_C_INCLUDES_$(TARGET_$(libvpx_2nd_arch)ARCH) += \
66    $(libvpx_intermediates)/vp8/common \
67    $(libvpx_intermediates)/vp8/decoder \
68    $(libvpx_intermediates)/vp8/encoder \
69    $(libvpx_intermediates)/vpx_scale
70