blob: a42afe9c054c9abdbfd001c1a4bb2be95a3b82f9 [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.
Dan Willemsen50e87532017-05-19 14:20:02 -070026linked_module := $(intermediates)/LINKED/$(notdir $(my_installed_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###################################
Chih-Hung Hsieh289e8d62018-05-24 15:13:19 -070038include $(BUILD_SYSTEM)/use_lld_setup.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -080039include $(BUILD_SYSTEM)/binary.mk
40###################################
41
The Android Open Source Project88b60792009-03-03 19:28:42 -080042###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070043## Store a copy with symbols for symbolic debugging
44###########################################################
Ying Wangf3584962013-11-13 17:56:20 -080045ifeq ($(LOCAL_UNSTRIPPED_PATH),)
Ying Wangb8e01852014-01-23 15:09:04 -080046my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
47else
48my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
Ying Wangf3584962013-11-13 17:56:20 -080049endif
Colin Cross979f9f92018-06-25 12:33:35 -070050symbolic_input := $(linked_module)
Ying Wang966c1e02014-05-20 14:43:51 -070051symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
Dan Willemsen7f016152016-02-29 17:52:39 -080052$(symbolic_output) : $(symbolic_input)
Ying Wang374b3252011-03-14 11:44:57 -070053 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
54 $(copy-file-to-target)
55
Steve Fungcb2e67f2015-09-24 01:40:52 -070056###########################################################
57## Store breakpad symbols
58###########################################################
59
60ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
Steve Fungdfbab492015-09-24 18:12:33 -070061my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
Colin Cross979f9f92018-06-25 12:33:35 -070062breakpad_input := $(linked_module)
Steve Fungcb2e67f2015-09-24 01:40:52 -070063breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym
Steve Fung445beae2017-08-30 14:58:33 -070064$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF)
Steve Fungcb2e67f2015-09-24 01:40:52 -070065 @echo "target breakpad: $(PRIVATE_MODULE) ($@)"
66 @mkdir -p $(dir $@)
Steve Fung445beae2017-08-30 14:58:33 -070067 $(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
Steve Fungcb2e67f2015-09-24 01:40:52 -070073$(LOCAL_BUILT_MODULE) : $(breakpad_output)
74endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080075
76###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -080077## Strip
78###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070079strip_input := $(symbolic_output)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070080strip_output := $(LOCAL_BUILT_MODULE)
The Android Open Source Project88b60792009-03-03 19:28:42 -080081
Ying Wang6efe88b2016-03-01 20:14:52 -080082my_strip_module := $(firstword \
83 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
84 $(LOCAL_STRIP_MODULE))
Ying Wange1889af2014-03-16 12:43:49 -070085ifeq ($(my_strip_module),)
Yabin Cui700883e2016-04-26 16:08:00 -070086 my_strip_module := mini-debug-info
87endif
88
Colin Cross830eed82018-09-07 23:15:46 -070089ifeq ($(my_strip_module),false)
90 my_strip_module :=
The Android Open Source Project88b60792009-03-03 19:28:42 -080091endif
Colin Cross830eed82018-09-07 23:15:46 -070092
93my_strip_args :=
94ifeq ($(my_strip_module),mini-debug-info)
95 my_strip_args += --keep-mini-debug-info
96else ifeq ($(my_strip_module),keep_symbols)
97 my_strip_args += --keep-symbols
98endif
99
100ifeq (,$(filter no_debuglink mini-debug-info,$(my_strip_module)))
101 ifneq ($(TARGET_BUILD_VARIANT),user)
102 my_strip_args += --add-gnu-debuglink
103 endif
Yabin Cui700883e2016-04-26 16:08:00 -0700104endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800105
Chih-Hung Hsieh9546d672018-06-01 14:07:52 -0700106ifeq ($(my_use_clang_lld),true)
107 # b/80093681: GNU strip and objcopy --{add,remove}-section have bug in handling
108 # GNU_RELRO segment of files lnked by clang lld; so they are replaced
109 # by llvm-strip and llvm-objcopy here.
Colin Cross830eed82018-09-07 23:15:46 -0700110 my_strip_args += --use-llvm-strip
Ying Wangc1729f32014-08-20 17:12:32 -0700111endif
112
Colin Cross830eed82018-09-07 23:15:46 -0700113valid_strip := mini-debug-info keep_symbols true no_debuglink
114ifneq (,$(filter-out $(valid_strip),$(my_strip_module)))
115 $(call pretty-error,Invalid strip value $(my_strip_module), only one of $(valid_strip) allowed)
Ying Wangd8c5ca92014-08-10 16:19:04 -0700116endif
Colin Cross830eed82018-09-07 23:15:46 -0700117
118ifneq (,$(my_strip_module))
119 $(strip_output): PRIVATE_STRIP_ARGS := $(my_strip_args)
120 $(strip_output): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX)
121 $(strip_output): $(strip_input) $(SOONG_STRIP_PATH)
122 @echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)"
123 CLANG_BIN=$(LLVM_PREBUILTS_PATH) \
124 CROSS_COMPILE=$(PRIVATE_TOOLS_PREFIX) \
125 XZ=$(XZ) \
126 $(SOONG_STRIP_PATH) -i $< -o $@ -d $@.d $(PRIVATE_STRIP_ARGS)
127 $(call include-depfile,$(strip_output).d)
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700128else
Colin Cross830eed82018-09-07 23:15:46 -0700129 # Don't strip the binary, just copy it. We can't skip this step
130 # because a copy of the binary must appear at LOCAL_BUILT_MODULE.
131 $(strip_output): $(strip_input)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800132 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
133 $(copy-file-to-target)
Ying Wange1889af2014-03-16 12:43:49 -0700134endif # my_strip_module
The Android Open Source Project88b60792009-03-03 19:28:42 -0800135
Ying Wangeda6ac22013-01-28 10:58:01 -0800136$(cleantarget): PRIVATE_CLEAN_FILES += \
137 $(linked_module) \
Steve Fungcb2e67f2015-09-24 01:40:52 -0700138 $(breakpad_output) \
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -0700139 $(symbolic_output) \
140 $(strip_output)