blob: 5120e7ec55118cfecbd9de7c6c600ad1e89dc618 [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
Colin Cross70bfe072019-09-05 14:27:02 -070042ifdef 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
The Android Open Source Project88b60792009-03-03 19:28:42 -080053###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070054## Store a copy with symbols for symbolic debugging
55###########################################################
Ying Wangf3584962013-11-13 17:56:20 -080056ifeq ($(LOCAL_UNSTRIPPED_PATH),)
Ying Wangb8e01852014-01-23 15:09:04 -080057my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
58else
59my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
Ying Wangf3584962013-11-13 17:56:20 -080060endif
Colin Cross70bfe072019-09-05 14:27:02 -070061symbolic_input := $(inject_module)
Ying Wang966c1e02014-05-20 14:43:51 -070062symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
Dan Willemsen7f016152016-02-29 17:52:39 -080063$(symbolic_output) : $(symbolic_input)
Ying Wang374b3252011-03-14 11:44:57 -070064 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
65 $(copy-file-to-target)
66
Steve Fungcb2e67f2015-09-24 01:40:52 -070067###########################################################
68## Store breakpad symbols
69###########################################################
70
71ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
Steve Fungdfbab492015-09-24 18:12:33 -070072my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
Colin Cross70bfe072019-09-05 14:27:02 -070073breakpad_input := $(inject_module)
Steve Fungcb2e67f2015-09-24 01:40:52 -070074breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym
Steve Fung445beae2017-08-30 14:58:33 -070075$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF)
Steve Fungcb2e67f2015-09-24 01:40:52 -070076 @echo "target breakpad: $(PRIVATE_MODULE) ($@)"
77 @mkdir -p $(dir $@)
Steve Fung445beae2017-08-30 14:58:33 -070078 $(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
Steve Fungcb2e67f2015-09-24 01:40:52 -070084$(LOCAL_BUILT_MODULE) : $(breakpad_output)
85endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080086
87###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -080088## Strip
89###########################################################
Colin Crossdb980012021-04-27 19:43:33 -070090strip_input := $(inject_module)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070091strip_output := $(LOCAL_BUILT_MODULE)
The Android Open Source Project88b60792009-03-03 19:28:42 -080092
Colin Crossdb980012021-04-27 19:43:33 -070093# Use an order-only dependency to ensure the unstripped file in the symbols
94# directory is copied when the module is built, but does not force the
95# module to be rebuilt when the symbols directory is cleaned by installclean.
96$(strip_output): | $(symbolic_output)
97
Ying Wang6efe88b2016-03-01 20:14:52 -080098my_strip_module := $(firstword \
99 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
100 $(LOCAL_STRIP_MODULE))
Ying Wange1889af2014-03-16 12:43:49 -0700101ifeq ($(my_strip_module),)
Yabin Cui700883e2016-04-26 16:08:00 -0700102 my_strip_module := mini-debug-info
103endif
104
Colin Cross830eed82018-09-07 23:15:46 -0700105ifeq ($(my_strip_module),false)
106 my_strip_module :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800107endif
Colin Cross830eed82018-09-07 23:15:46 -0700108
109my_strip_args :=
110ifeq ($(my_strip_module),mini-debug-info)
111 my_strip_args += --keep-mini-debug-info
112else ifeq ($(my_strip_module),keep_symbols)
113 my_strip_args += --keep-symbols
114endif
115
116ifeq (,$(filter no_debuglink mini-debug-info,$(my_strip_module)))
117 ifneq ($(TARGET_BUILD_VARIANT),user)
118 my_strip_args += --add-gnu-debuglink
119 endif
Yabin Cui700883e2016-04-26 16:08:00 -0700120endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800121
Yi Kong9e865732018-11-07 16:33:11 -0800122ifeq ($($(my_prefix)OS),darwin)
123 # llvm-strip does not support Darwin Mach-O yet.
124 my_strip_args += --use-gnu-strip
Ying Wangc1729f32014-08-20 17:12:32 -0700125endif
126
Colin Cross830eed82018-09-07 23:15:46 -0700127valid_strip := mini-debug-info keep_symbols true no_debuglink
128ifneq (,$(filter-out $(valid_strip),$(my_strip_module)))
129 $(call pretty-error,Invalid strip value $(my_strip_module), only one of $(valid_strip) allowed)
Ying Wangd8c5ca92014-08-10 16:19:04 -0700130endif
Colin Cross830eed82018-09-07 23:15:46 -0700131
132ifneq (,$(my_strip_module))
133 $(strip_output): PRIVATE_STRIP_ARGS := $(my_strip_args)
134 $(strip_output): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX)
135 $(strip_output): $(strip_input) $(SOONG_STRIP_PATH)
136 @echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)"
137 CLANG_BIN=$(LLVM_PREBUILTS_PATH) \
138 CROSS_COMPILE=$(PRIVATE_TOOLS_PREFIX) \
139 XZ=$(XZ) \
Colin Cross3e87e832020-01-27 13:52:28 -0800140 $(SOONG_STRIP_PATH) -i $< -o $@ -d $@.strip.d $(PRIVATE_STRIP_ARGS)
141 $(call include-depfile,$(strip_output).strip.d,$(strip_output))
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700142else
Colin Cross830eed82018-09-07 23:15:46 -0700143 # 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 $(strip_output): $(strip_input)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800146 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
147 $(copy-file-to-target)
Ying Wange1889af2014-03-16 12:43:49 -0700148endif # my_strip_module
The Android Open Source Project88b60792009-03-03 19:28:42 -0800149
Ying Wangeda6ac22013-01-28 10:58:01 -0800150$(cleantarget): PRIVATE_CLEAN_FILES += \
151 $(linked_module) \
Colin Cross70bfe072019-09-05 14:27:02 -0700152 $(inject_module) \
Steve Fungcb2e67f2015-09-24 01:40:52 -0700153 $(breakpad_output) \
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -0700154 $(symbolic_output) \
155 $(strip_output)