blob: 240415d767d358e38698336ef6f629857722b042 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001###########################################################
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
The Android Open Source Project88b60792009-03-03 19:28:42 -080015# The name of the target file, without any path prepended.
Colin Cross5a9db902014-03-21 12:27:37 -070016# 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
The Android Open Source Project88b60792009-03-03 19:28:42 -080019
Ying Wang98ae7982014-12-18 14:53:52 -080020intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX))
The Android Open Source Project88b60792009-03-03 19:28:42 -080021
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.
Ying Wang98ae7982014-12-18 14:53:52 -080026linked_module := $(intermediates)/LINKED/$(my_built_module_stem)
The Android Open Source Project88b60792009-03-03 19:28:42 -080027
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)/binary.mk
39###################################
40
The Android Open Source Project88b60792009-03-03 19:28:42 -080041###########################################################
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070042## Pack relocation tables
43###########################################################
44relocation_packer_input := $(linked_module)
45relocation_packer_output := $(intermediates)/PACKED/$(my_built_module_stem)
46
47my_pack_module_relocations := $(LOCAL_PACK_MODULE_RELOCATIONS)
48
49ifeq ($(my_pack_module_relocations),)
50 my_pack_module_relocations := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PACK_MODULE_RELOCATIONS)
51endif
52
Dmitriy Ivanove24b6f72015-04-29 12:13:37 -070053# Do not pack relocations for executables. Because packing results in
54# non-zero p_vaddr which causes kernel to load executables to lower
55# address (starting at 0x8000) http://b/20665974
56ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070057 my_pack_module_relocations := false
58endif
59
60# TODO (dimitry): Relocation packer is not yet available for darwin
61ifneq ($(HOST_OS),linux)
62 my_pack_module_relocations := false
63endif
64
65ifeq (true,$(my_pack_module_relocations))
66# Pack relocations
67$(relocation_packer_output): $(relocation_packer_input) | $(ACP)
68 $(pack-elf-relocations)
69else
70$(relocation_packer_output): $(relocation_packer_input) | $(ACP)
71 @echo "target Unpacked: $(PRIVATE_MODULE) ($@)"
72 $(copy-file-to-target)
73endif
74
75###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070076## Store a copy with symbols for symbolic debugging
77###########################################################
Ying Wangf3584962013-11-13 17:56:20 -080078ifeq ($(LOCAL_UNSTRIPPED_PATH),)
Ying Wangb8e01852014-01-23 15:09:04 -080079my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
80else
81my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
Ying Wangf3584962013-11-13 17:56:20 -080082endif
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070083symbolic_input := $(relocation_packer_output)
Ying Wang966c1e02014-05-20 14:43:51 -070084symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
Ying Wang374b3252011-03-14 11:44:57 -070085$(symbolic_output) : $(symbolic_input) | $(ACP)
86 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
87 $(copy-file-to-target)
88
Steve Fungcb2e67f2015-09-24 01:40:52 -070089###########################################################
90## Store breakpad symbols
91###########################################################
92
93ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
94my_breakpad_path := $(PRODUCT_OUT)/breakpad/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
95breakpad_input := $(relocation_packer_output)
96breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym
97$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS)
98 @echo "target breakpad: $(PRIVATE_MODULE) ($@)"
99 @mkdir -p $(dir $@)
100 $(hide) $(BREAKPAD_DUMP_SYMS) -c $< > $@
101$(LOCAL_BUILT_MODULE) : $(breakpad_output)
102endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800103
104###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800105## Strip
106###########################################################
Ying Wang374b3252011-03-14 11:44:57 -0700107strip_input := $(symbolic_output)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -0700108strip_output := $(LOCAL_BUILT_MODULE)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800109
Ying Wange1889af2014-03-16 12:43:49 -0700110my_strip_module := $(LOCAL_STRIP_MODULE)
111ifeq ($(my_strip_module),)
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -0700112 my_strip_module := true
The Android Open Source Project88b60792009-03-03 19:28:42 -0800113endif
114
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700115$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
116$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
117$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
Ying Wangc1729f32014-08-20 17:12:32 -0700118ifeq ($(my_strip_module),no_debuglink)
119$(strip_output): PRIVATE_NO_DEBUGLINK := true
120else
121$(strip_output): PRIVATE_NO_DEBUGLINK :=
122endif
123
124ifneq ($(filter true no_debuglink,$(my_strip_module)),)
125# Strip the binary
126$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
127 $(transform-to-stripped)
128else ifeq ($(my_strip_module),keep_symbols)
129# Strip only the debug frames, but leave the symbol table.
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700130$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
131 $(transform-to-stripped-keep-symbols)
Ying Wangd8c5ca92014-08-10 16:19:04 -0700132
133# A product may be configured to strip everything in some build variants.
134# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE
135# is still with the symbols and we don't need to clean it (and relink) when
136# you switch build variant.
137ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),)
138$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \
139 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE)
140endif
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700141else
The Android Open Source Project88b60792009-03-03 19:28:42 -0800142# Don't strip the binary, just copy it. We can't skip this step
143# because a copy of the binary must appear at LOCAL_BUILT_MODULE.
144#
145# If the binary we're copying is acp or a prerequisite,
146# use cp(1) instead.
147ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
148$(strip_output): $(strip_input) | $(ACP)
149 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
150 $(copy-file-to-target)
151else
152$(strip_output): $(strip_input)
153 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
154 $(copy-file-to-target-with-cp)
155endif
Ying Wange1889af2014-03-16 12:43:49 -0700156endif # my_strip_module
The Android Open Source Project88b60792009-03-03 19:28:42 -0800157
Ying Wangeda6ac22013-01-28 10:58:01 -0800158$(cleantarget): PRIVATE_CLEAN_FILES += \
159 $(linked_module) \
Steve Fungcb2e67f2015-09-24 01:40:52 -0700160 $(breakpad_output) \
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -0700161 $(symbolic_output) \
162 $(strip_output)