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. 11 ifdef 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)))) 13 endif 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. 18 include $(BUILD_SYSTEM)/configure_module_stem.mk 19 20 intermediates := $(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. 26 linked_module := $(intermediates)/LINKED/$(notdir $(my_installed_module_stem)) 27 28 ALL_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. 35 LOCAL_INTERMEDIATE_TARGETS := $(linked_module) 36 37 ################################### 38 include $(BUILD_SYSTEM)/use_lld_setup.mk 39 include $(BUILD_SYSTEM)/binary.mk 40 ################################### 41 42 ########################################################### 43 ## Store a copy with symbols for symbolic debugging 44 ########################################################### 45 ifeq ($(LOCAL_UNSTRIPPED_PATH),) 46 my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 47 else 48 my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) 49 endif 50 symbolic_input := $(linked_module) 51 symbolic_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 60 ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) 61 my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 62 breakpad_input := $(linked_module) 63 breakpad_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) 74 endif 75 76 ########################################################### 77 ## Strip 78 ########################################################### 79 strip_input := $(symbolic_output) 80 strip_output := $(LOCAL_BUILT_MODULE) 81 82 my_strip_module := $(firstword \ 83 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ 84 $(LOCAL_STRIP_MODULE)) 85 ifeq ($(my_strip_module),) 86 my_strip_module := mini-debug-info 87 endif 88 89 ifeq ($(my_strip_module),false) 90 my_strip_module := 91 endif 92 93 my_strip_args := 94 ifeq ($(my_strip_module),mini-debug-info) 95 my_strip_args += --keep-mini-debug-info 96 else ifeq ($(my_strip_module),keep_symbols) 97 my_strip_args += --keep-symbols 98 endif 99 100 ifeq (,$(filter no_debuglink mini-debug-info,$(my_strip_module))) 101 ifneq ($(TARGET_BUILD_VARIANT),user) 102 my_strip_args += --add-gnu-debuglink 103 endif 104 endif 105 106 ifeq ($($(my_prefix)OS),darwin) 107 # llvm-strip does not support Darwin Mach-O yet. 108 my_strip_args += --use-gnu-strip 109 endif 110 111 valid_strip := mini-debug-info keep_symbols true no_debuglink 112 ifneq (,$(filter-out $(valid_strip),$(my_strip_module))) 113 $(call pretty-error,Invalid strip value $(my_strip_module), only one of $(valid_strip) allowed) 114 endif 115 116 ifneq (,$(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) 126 else 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) 132 endif # my_strip_module 133 134 $(cleantarget): PRIVATE_CLEAN_FILES += \ 135 $(linked_module) \ 136 $(breakpad_output) \ 137 $(symbolic_output) \ 138 $(strip_output) 139