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 15LOCAL_UNSTRIPPED_PATH := $(strip $(LOCAL_UNSTRIPPED_PATH)) 16ifeq ($(LOCAL_UNSTRIPPED_PATH),) 17 ifeq ($(LOCAL_MODULE_PATH),) 18 LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_$(LOCAL_MODULE_CLASS)_UNSTRIPPED) 19 else 20 # We have to figure out the corresponding unstripped path if LOCAL_MODULE_PATH is customized. 21 LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(LOCAL_MODULE_PATH)) 22 endif 23endif 24 25# The name of the target file, without any path prepended. 26# TODO: This duplicates logic from base_rules.mk because we need to 27# know its results before base_rules.mk is included. 28# Consolidate the duplicates. 29LOCAL_MODULE_STEM := $(strip $(LOCAL_MODULE_STEM)) 30ifeq ($(LOCAL_MODULE_STEM),) 31 LOCAL_MODULE_STEM := $(LOCAL_MODULE) 32endif 33LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE_STEM)$(LOCAL_MODULE_SUFFIX) 34LOCAL_BUILT_MODULE_STEM := $(LOCAL_INSTALLED_MODULE_STEM) 35 36# base_rules.make defines $(intermediates), but we need its value 37# before we include base_rules. Make a guess, and verify that 38# it's correct once the real value is defined. 39guessed_intermediates := $(call local-intermediates-dir) 40 41# Define the target that is the unmodified output of the linker. 42# The basename of this target must be the same as the final output 43# binary name, because it's used to set the "soname" in the binary. 44# The includer of this file will define a rule to build this target. 45linked_module := $(guessed_intermediates)/LINKED/$(LOCAL_BUILT_MODULE_STEM) 46 47ALL_ORIGINAL_DYNAMIC_BINARIES += $(linked_module) 48 49# Because TARGET_SYMBOL_FILTER_FILE depends on ALL_ORIGINAL_DYNAMIC_BINARIES, 50# the linked_module rules won't necessarily inherit the PRIVATE_ 51# variables from LOCAL_BUILT_MODULE. This tells binary.make to explicitly 52# define the PRIVATE_ variables for linked_module as well as for 53# LOCAL_BUILT_MODULE. 54LOCAL_INTERMEDIATE_TARGETS := $(linked_module) 55 56################################### 57include $(BUILD_SYSTEM)/binary.mk 58################################### 59 60# Make sure that our guess at the value of intermediates was correct. 61ifneq ($(intermediates),$(guessed_intermediates)) 62$(error Internal error: guessed path '$(guessed_intermediates)' doesn't match '$(intermediates)) 63endif 64 65########################################################### 66## Compress 67########################################################### 68compress_input := $(linked_module) 69 70ifeq ($(strip $(LOCAL_COMPRESS_MODULE_SYMBOLS)),) 71 LOCAL_COMPRESS_MODULE_SYMBOLS := $(strip $(TARGET_COMPRESS_MODULE_SYMBOLS)) 72endif 73 74ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true) 75$(error Symbol compression not yet supported.) 76compress_output := $(intermediates)/COMPRESSED-$(LOCAL_BUILT_MODULE_STEM) 77 78#TODO: write the real $(SOSLIM) rule. 79#TODO: define a rule to build TARGET_SYMBOL_FILTER_FILE, and 80# make it depend on ALL_ORIGINAL_DYNAMIC_BINARIES. 81$(compress_output): $(compress_input) $(TARGET_SYMBOL_FILTER_FILE) | $(ACP) 82 @echo "target Compress Symbols: $(PRIVATE_MODULE) ($@)" 83 $(copy-file-to-target) 84else 85# Skip this step. 86compress_output := $(compress_input) 87endif 88 89 90########################################################### 91## Pre-link 92########################################################### 93prelink_input := $(compress_output) 94# The output of the prelink step is the binary we want to use 95# for symbolic debugging; the prelink step may move sections 96# around, so we have to use this version. 97prelink_output := $(LOCAL_UNSTRIPPED_PATH)/$(LOCAL_MODULE_SUBDIR)$(LOCAL_BUILT_MODULE_STEM) 98 99# Skip prelinker if it is FDO instrumentation build. 100ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),) 101ifneq ($(LOCAL_NO_FDO_SUPPORT),true) 102LOCAL_PRELINK_MODULE := false 103endif 104endif 105 106ifeq ($(LOCAL_PRELINK_MODULE),true) 107$(prelink_output): $(prelink_input) $(TARGET_PRELINKER_MAP) $(APRIORI) 108 $(transform-to-prelinked) 109else 110# Don't prelink the binary, just copy it. We can't skip this step 111# because people always expect a copy of the binary to appear 112# in the UNSTRIPPED directory. 113# 114# If the binary we're copying is acp or a prerequisite, 115# use cp(1) instead. 116ifneq ($(LOCAL_ACP_UNAVAILABLE),true) 117$(prelink_output): $(prelink_input) | $(ACP) 118 @echo "target Non-prelinked: $(PRIVATE_MODULE) ($@)" 119 $(copy-file-to-target) 120else 121$(prelink_output): $(prelink_input) 122 @echo "target Non-prelinked: $(PRIVATE_MODULE) ($@)" 123 $(copy-file-to-target-with-cp) 124endif 125endif 126 127 128########################################################### 129## Strip 130########################################################### 131strip_input := $(prelink_output) 132strip_output := $(LOCAL_BUILT_MODULE) 133 134ifeq ($(strip $(LOCAL_STRIP_MODULE)),) 135 LOCAL_STRIP_MODULE := $(strip $(TARGET_STRIP_MODULE)) 136endif 137 138ifeq ($(LOCAL_STRIP_MODULE),true) 139# Strip the binary 140$(strip_output): $(strip_input) | $(SOSLIM) 141 $(transform-to-stripped) 142else 143# Don't strip the binary, just copy it. We can't skip this step 144# because a copy of the binary must appear at LOCAL_BUILT_MODULE. 145# 146# If the binary we're copying is acp or a prerequisite, 147# use cp(1) instead. 148ifneq ($(LOCAL_ACP_UNAVAILABLE),true) 149$(strip_output): $(strip_input) | $(ACP) 150 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" 151 $(copy-file-to-target) 152else 153$(strip_output): $(strip_input) 154 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" 155 $(copy-file-to-target-with-cp) 156endif 157endif # LOCAL_STRIP_MODULE 158 159 160$(cleantarget): PRIVATE_CLEAN_FILES := \ 161 $(PRIVATE_CLEAN_FILES) \ 162 $(linked_module) \ 163 $(compress_output) \ 164 $(prelink_output) 165