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 42ifdef LOCAL_INJECT_BSSL_HASH 43inject_module := $(intermediates)/INJECT_BSSL_HASH/$(notdir $(my_installed_module_stem)) 44LOCAL_INTERMEDIATE_TARGETS += $(inject_module) 45$(inject_module): $(SOONG_HOST_OUT)/bin/bssl_inject_hash 46$(inject_module): $(linked_module) 47 @echo "target inject BSSL hash: $(PRIVATE_MODULE) ($@)" 48 $(SOONG_HOST_OUT)/bin/bssl_inject_hash -in-object $< -o $@ 49else 50inject_module := $(linked_module) 51endif 52 53########################################################### 54## Store a copy with symbols for symbolic debugging 55########################################################### 56ifeq ($(LOCAL_UNSTRIPPED_PATH),) 57my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 58else 59my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) 60endif 61symbolic_input := $(inject_module) 62symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) 63$(symbolic_output) : $(symbolic_input) 64 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)" 65 $(copy-file-to-target) 66 67########################################################### 68## Store breakpad symbols 69########################################################### 70 71ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) 72my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 73breakpad_input := $(inject_module) 74breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym 75$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF) 76 @echo "target breakpad: $(PRIVATE_MODULE) ($@)" 77 @mkdir -p $(dir $@) 78 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \ 79 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \ 80 else \ 81 echo "skipped for non-elf file."; \ 82 touch $@; \ 83 fi 84$(LOCAL_BUILT_MODULE) : $(breakpad_output) 85endif 86 87########################################################### 88## Strip 89########################################################### 90strip_input := $(symbolic_output) 91strip_output := $(LOCAL_BUILT_MODULE) 92 93my_strip_module := $(firstword \ 94 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ 95 $(LOCAL_STRIP_MODULE)) 96ifeq ($(my_strip_module),) 97 my_strip_module := mini-debug-info 98endif 99 100ifeq ($(my_strip_module),false) 101 my_strip_module := 102endif 103 104my_strip_args := 105ifeq ($(my_strip_module),mini-debug-info) 106 my_strip_args += --keep-mini-debug-info 107else ifeq ($(my_strip_module),keep_symbols) 108 my_strip_args += --keep-symbols 109endif 110 111ifeq (,$(filter no_debuglink mini-debug-info,$(my_strip_module))) 112 ifneq ($(TARGET_BUILD_VARIANT),user) 113 my_strip_args += --add-gnu-debuglink 114 endif 115endif 116 117ifeq ($($(my_prefix)OS),darwin) 118 # llvm-strip does not support Darwin Mach-O yet. 119 my_strip_args += --use-gnu-strip 120endif 121 122valid_strip := mini-debug-info keep_symbols true no_debuglink 123ifneq (,$(filter-out $(valid_strip),$(my_strip_module))) 124 $(call pretty-error,Invalid strip value $(my_strip_module), only one of $(valid_strip) allowed) 125endif 126 127ifneq (,$(my_strip_module)) 128 $(strip_output): PRIVATE_STRIP_ARGS := $(my_strip_args) 129 $(strip_output): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX) 130 $(strip_output): $(strip_input) $(SOONG_STRIP_PATH) 131 @echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)" 132 CLANG_BIN=$(LLVM_PREBUILTS_PATH) \ 133 CROSS_COMPILE=$(PRIVATE_TOOLS_PREFIX) \ 134 XZ=$(XZ) \ 135 $(SOONG_STRIP_PATH) -i $< -o $@ -d $@.strip.d $(PRIVATE_STRIP_ARGS) 136 $(call include-depfile,$(strip_output).strip.d,$(strip_output)) 137else 138 # Don't strip the binary, just copy it. We can't skip this step 139 # because a copy of the binary must appear at LOCAL_BUILT_MODULE. 140 $(strip_output): $(strip_input) 141 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" 142 $(copy-file-to-target) 143endif # my_strip_module 144 145$(cleantarget): PRIVATE_CLEAN_FILES += \ 146 $(linked_module) \ 147 $(inject_module) \ 148 $(breakpad_output) \ 149 $(symbolic_output) \ 150 $(strip_output) 151