dynamic_binary.mk revision bfb52a2ec199a75e1a0e4e92148af0a6323c9f46
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
20# base_rules.make defines $(intermediates), but we need its value
21# before we include base_rules.  Make a guess, and verify that
22# it's correct once the real value is defined.
23guessed_intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX))
24
25# Define the target that is the unmodified output of the linker.
26# The basename of this target must be the same as the final output
27# binary name, because it's used to set the "soname" in the binary.
28# The includer of this file will define a rule to build this target.
29linked_module := $(guessed_intermediates)/LINKED/$(my_built_module_stem)
30
31ALL_ORIGINAL_DYNAMIC_BINARIES += $(linked_module)
32
33# Because TARGET_SYMBOL_FILTER_FILE depends on ALL_ORIGINAL_DYNAMIC_BINARIES,
34# the linked_module rules won't necessarily inherit the PRIVATE_
35# variables from LOCAL_BUILT_MODULE.  This tells binary.make to explicitly
36# define the PRIVATE_ variables for linked_module as well as for
37# LOCAL_BUILT_MODULE.
38LOCAL_INTERMEDIATE_TARGETS := $(linked_module)
39
40###################################
41include $(BUILD_SYSTEM)/binary.mk
42###################################
43
44# Make sure that our guess at the value of intermediates was correct.
45ifneq ($(intermediates),$(guessed_intermediates))
46$(error Internal error: guessed path '$(guessed_intermediates)' doesn't match '$(intermediates))
47endif
48
49###########################################################
50## Compress
51###########################################################
52compress_input := $(linked_module)
53
54ifeq ($(strip $(LOCAL_COMPRESS_MODULE_SYMBOLS)),)
55  LOCAL_COMPRESS_MODULE_SYMBOLS := $(strip $(TARGET_COMPRESS_MODULE_SYMBOLS))
56endif
57
58ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true)
59$(error Symbol compression not yet supported.)
60compress_output := $(intermediates)/COMPRESSED-$(my_built_module_stem)
61
62#TODO: write the real $(STRIPPER) rule.
63#TODO: define a rule to build TARGET_SYMBOL_FILTER_FILE, and
64#      make it depend on ALL_ORIGINAL_DYNAMIC_BINARIES.
65$(compress_output): $(compress_input) $(TARGET_SYMBOL_FILTER_FILE) | $(ACP)
66	@echo "target Compress Symbols: $(PRIVATE_MODULE) ($@)"
67	$(copy-file-to-target)
68else
69# Skip this step.
70compress_output := $(compress_input)
71endif
72
73###########################################################
74## Store a copy with symbols for symbolic debugging
75###########################################################
76ifeq ($(LOCAL_UNSTRIPPED_PATH),)
77my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
78else
79my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
80endif
81symbolic_input := $(compress_output)
82symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
83$(symbolic_output) : $(symbolic_input) | $(ACP)
84	@echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
85	$(copy-file-to-target)
86
87
88###########################################################
89## Strip
90###########################################################
91strip_input := $(symbolic_output)
92strip_output := $(LOCAL_BUILT_MODULE)
93
94my_strip_module := $(LOCAL_STRIP_MODULE)
95ifeq ($(my_strip_module),)
96  my_strip_module := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP_MODULE)
97endif
98
99$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
100$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
101$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
102ifeq ($(my_strip_module),no_debuglink)
103$(strip_output): PRIVATE_NO_DEBUGLINK := true
104else
105$(strip_output): PRIVATE_NO_DEBUGLINK :=
106endif
107
108ifneq ($(filter true no_debuglink,$(my_strip_module)),)
109# Strip the binary
110$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
111	$(transform-to-stripped)
112else ifeq ($(my_strip_module),keep_symbols)
113# Strip only the debug frames, but leave the symbol table.
114$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
115	$(transform-to-stripped-keep-symbols)
116
117# A product may be configured to strip everything in some build variants.
118# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE
119# is still with the symbols and we don't need to clean it (and relink) when
120# you switch build variant.
121ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),)
122$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \
123  $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE)
124endif
125else
126# Don't strip the binary, just copy it.  We can't skip this step
127# because a copy of the binary must appear at LOCAL_BUILT_MODULE.
128#
129# If the binary we're copying is acp or a prerequisite,
130# use cp(1) instead.
131ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
132$(strip_output): $(strip_input) | $(ACP)
133	@echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
134	$(copy-file-to-target)
135else
136$(strip_output): $(strip_input)
137	@echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
138	$(copy-file-to-target-with-cp)
139endif
140endif # my_strip_module
141
142
143$(cleantarget): PRIVATE_CLEAN_FILES += \
144    $(linked_module) \
145    $(symbolic_output) \
146    $(compress_output)
147