1########################################################### 2## Standard rules for building any target-side binaries 3## with dynamic linkage (dynamic libraries or executables 4## that link with dynamic libraries) 5## 6## Files including this file must define a rule to build 7## the target $(linked_module). 8########################################################### 9 10# This constraint means that we can hard-code any $(TARGET_*) variables. 11ifdef LOCAL_IS_HOST_MODULE 12$(error This file should not be used to build host binaries. Included by (or near) $(lastword $(filter-out config/%,$(MAKEFILE_LIST)))) 13endif 14 15# The name of the target file, without any path prepended. 16# This duplicates logic from base_rules.mk because we need to 17# know its results before base_rules.mk is included. 18include $(BUILD_SYSTEM)/configure_module_stem.mk 19 20intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX)) 21 22# Define the target that is the unmodified output of the linker. 23# The basename of this target must be the same as the final output 24# binary name, because it's used to set the "soname" in the binary. 25# The includer of this file will define a rule to build this target. 26linked_module := $(intermediates)/LINKED/$(notdir $(my_installed_module_stem)) 27 28ALL_ORIGINAL_DYNAMIC_BINARIES += $(linked_module) 29 30# Because TARGET_SYMBOL_FILTER_FILE depends on ALL_ORIGINAL_DYNAMIC_BINARIES, 31# the linked_module rules won't necessarily inherit the PRIVATE_ 32# variables from LOCAL_BUILT_MODULE. This tells binary.make to explicitly 33# define the PRIVATE_ variables for linked_module as well as for 34# LOCAL_BUILT_MODULE. 35LOCAL_INTERMEDIATE_TARGETS := $(linked_module) 36 37################################### 38include $(BUILD_SYSTEM)/use_lld_setup.mk 39include $(BUILD_SYSTEM)/binary.mk 40################################### 41 42########################################################### 43## Store a copy with symbols for symbolic debugging 44########################################################### 45ifeq ($(LOCAL_UNSTRIPPED_PATH),) 46my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 47else 48my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) 49endif 50symbolic_input := $(linked_module) 51symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) 52$(symbolic_output) : $(symbolic_input) 53 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)" 54 $(copy-file-to-target) 55 56########################################################### 57## Store breakpad symbols 58########################################################### 59 60ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) 61my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 62breakpad_input := $(linked_module) 63breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym 64$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF) 65 @echo "target breakpad: $(PRIVATE_MODULE) ($@)" 66 @mkdir -p $(dir $@) 67 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \ 68 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \ 69 else \ 70 echo "skipped for non-elf file."; \ 71 touch $@; \ 72 fi 73$(LOCAL_BUILT_MODULE) : $(breakpad_output) 74endif 75 76########################################################### 77## Strip 78########################################################### 79strip_input := $(symbolic_output) 80strip_output := $(LOCAL_BUILT_MODULE) 81 82my_strip_module := $(firstword \ 83 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ 84 $(LOCAL_STRIP_MODULE)) 85ifeq ($(my_strip_module),) 86 my_strip_module := mini-debug-info 87endif 88 89ifeq ($(my_strip_module),false) 90 my_strip_module := 91endif 92 93my_strip_args := 94ifeq ($(my_strip_module),mini-debug-info) 95 my_strip_args += --keep-mini-debug-info 96else ifeq ($(my_strip_module),keep_symbols) 97 my_strip_args += --keep-symbols 98endif 99 100ifeq (,$(filter no_debuglink mini-debug-info,$(my_strip_module))) 101 ifneq ($(TARGET_BUILD_VARIANT),user) 102 my_strip_args += --add-gnu-debuglink 103 endif 104endif 105 106ifeq ($($(my_prefix)OS),darwin) 107 # llvm-strip does not support Darwin Mach-O yet. 108 my_strip_args += --use-gnu-strip 109endif 110 111valid_strip := mini-debug-info keep_symbols true no_debuglink 112ifneq (,$(filter-out $(valid_strip),$(my_strip_module))) 113 $(call pretty-error,Invalid strip value $(my_strip_module), only one of $(valid_strip) allowed) 114endif 115 116ifneq (,$(my_strip_module)) 117 $(strip_output): PRIVATE_STRIP_ARGS := $(my_strip_args) 118 $(strip_output): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX) 119 $(strip_output): $(strip_input) $(SOONG_STRIP_PATH) 120 @echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)" 121 CLANG_BIN=$(LLVM_PREBUILTS_PATH) \ 122 CROSS_COMPILE=$(PRIVATE_TOOLS_PREFIX) \ 123 XZ=$(XZ) \ 124 $(SOONG_STRIP_PATH) -i $< -o $@ -d $@.d $(PRIVATE_STRIP_ARGS) 125 $(call include-depfile,$(strip_output).d) 126else 127 # Don't strip the binary, just copy it. We can't skip this step 128 # because a copy of the binary must appear at LOCAL_BUILT_MODULE. 129 $(strip_output): $(strip_input) 130 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" 131 $(copy-file-to-target) 132endif # my_strip_module 133 134$(cleantarget): PRIVATE_CLEAN_FILES += \ 135 $(linked_module) \ 136 $(breakpad_output) \ 137 $(symbolic_output) \ 138 $(strip_output) 139