blob: 0d2cd7f067a06b7f4f69c5d219362f1908015eca [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
Colin Crossc6d63062022-03-21 14:32:42 -070028# This tells binary.make to explicitly define the PRIVATE_ variables for
29# linked_module as well as for LOCAL_BUILT_MODULE.
The Android Open Source Project88b60792009-03-03 19:28:42 -080030LOCAL_INTERMEDIATE_TARGETS := $(linked_module)
31
32###################################
Chih-Hung Hsieh289e8d62018-05-24 15:13:19 -070033include $(BUILD_SYSTEM)/use_lld_setup.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -080034include $(BUILD_SYSTEM)/binary.mk
35###################################
36
Colin Cross70bfe072019-09-05 14:27:02 -070037ifdef LOCAL_INJECT_BSSL_HASH
38inject_module := $(intermediates)/INJECT_BSSL_HASH/$(notdir $(my_installed_module_stem))
39LOCAL_INTERMEDIATE_TARGETS += $(inject_module)
40$(inject_module): $(SOONG_HOST_OUT)/bin/bssl_inject_hash
41$(inject_module): $(linked_module)
42 @echo "target inject BSSL hash: $(PRIVATE_MODULE) ($@)"
43 $(SOONG_HOST_OUT)/bin/bssl_inject_hash -in-object $< -o $@
44else
45inject_module := $(linked_module)
46endif
47
The Android Open Source Project88b60792009-03-03 19:28:42 -080048###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070049## Store a copy with symbols for symbolic debugging
50###########################################################
Ying Wangf3584962013-11-13 17:56:20 -080051ifeq ($(LOCAL_UNSTRIPPED_PATH),)
Ying Wangb8e01852014-01-23 15:09:04 -080052my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
53else
54my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
Ying Wangf3584962013-11-13 17:56:20 -080055endif
Colin Cross70bfe072019-09-05 14:27:02 -070056symbolic_input := $(inject_module)
Ying Wang966c1e02014-05-20 14:43:51 -070057symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
Colin Crossac7febc2022-04-06 01:11:20 +000058$(eval $(call copy-unstripped-elf-file-with-mapping,$(symbolic_input),$(symbolic_output)))
Ying Wang374b3252011-03-14 11:44:57 -070059
Steve Fungcb2e67f2015-09-24 01:40:52 -070060###########################################################
61## Store breakpad symbols
62###########################################################
63
64ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
Steve Fungdfbab492015-09-24 18:12:33 -070065my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
Colin Cross70bfe072019-09-05 14:27:02 -070066breakpad_input := $(inject_module)
Steve Fungcb2e67f2015-09-24 01:40:52 -070067breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym
Steve Fung445beae2017-08-30 14:58:33 -070068$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF)
Steve Fungcb2e67f2015-09-24 01:40:52 -070069 @echo "target breakpad: $(PRIVATE_MODULE) ($@)"
70 @mkdir -p $(dir $@)
Steve Fung445beae2017-08-30 14:58:33 -070071 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \
72 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \
73 else \
74 echo "skipped for non-elf file."; \
75 touch $@; \
76 fi
Steve Fungcb2e67f2015-09-24 01:40:52 -070077$(LOCAL_BUILT_MODULE) : $(breakpad_output)
78endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080079
80###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -080081## Strip
82###########################################################
Colin Crossdb980012021-04-27 19:43:33 -070083strip_input := $(inject_module)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070084strip_output := $(LOCAL_BUILT_MODULE)
The Android Open Source Project88b60792009-03-03 19:28:42 -080085
Colin Crossdb980012021-04-27 19:43:33 -070086# Use an order-only dependency to ensure the unstripped file in the symbols
87# directory is copied when the module is built, but does not force the
88# module to be rebuilt when the symbols directory is cleaned by installclean.
89$(strip_output): | $(symbolic_output)
90
Ying Wang6efe88b2016-03-01 20:14:52 -080091my_strip_module := $(firstword \
92 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
93 $(LOCAL_STRIP_MODULE))
Ying Wange1889af2014-03-16 12:43:49 -070094ifeq ($(my_strip_module),)
Yabin Cui700883e2016-04-26 16:08:00 -070095 my_strip_module := mini-debug-info
96endif
97
Colin Cross830eed82018-09-07 23:15:46 -070098ifeq ($(my_strip_module),false)
99 my_strip_module :=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800100endif
Colin Cross830eed82018-09-07 23:15:46 -0700101
102my_strip_args :=
103ifeq ($(my_strip_module),mini-debug-info)
104 my_strip_args += --keep-mini-debug-info
105else ifeq ($(my_strip_module),keep_symbols)
106 my_strip_args += --keep-symbols
107endif
108
109ifeq (,$(filter no_debuglink mini-debug-info,$(my_strip_module)))
110 ifneq ($(TARGET_BUILD_VARIANT),user)
111 my_strip_args += --add-gnu-debuglink
112 endif
Yabin Cui700883e2016-04-26 16:08:00 -0700113endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800114
Yi Kong9e865732018-11-07 16:33:11 -0800115ifeq ($($(my_prefix)OS),darwin)
116 # llvm-strip does not support Darwin Mach-O yet.
117 my_strip_args += --use-gnu-strip
Ying Wangc1729f32014-08-20 17:12:32 -0700118endif
119
Colin Cross830eed82018-09-07 23:15:46 -0700120valid_strip := mini-debug-info keep_symbols true no_debuglink
121ifneq (,$(filter-out $(valid_strip),$(my_strip_module)))
122 $(call pretty-error,Invalid strip value $(my_strip_module), only one of $(valid_strip) allowed)
Ying Wangd8c5ca92014-08-10 16:19:04 -0700123endif
Colin Cross830eed82018-09-07 23:15:46 -0700124
125ifneq (,$(my_strip_module))
126 $(strip_output): PRIVATE_STRIP_ARGS := $(my_strip_args)
127 $(strip_output): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX)
David Srbeckybf086ed2021-04-30 20:01:34 +0100128 $(strip_output): $(strip_input) $(SOONG_STRIP_PATH) $(XZ)
Colin Cross830eed82018-09-07 23:15:46 -0700129 @echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)"
130 CLANG_BIN=$(LLVM_PREBUILTS_PATH) \
131 CROSS_COMPILE=$(PRIVATE_TOOLS_PREFIX) \
132 XZ=$(XZ) \
David Srbeckybf086ed2021-04-30 20:01:34 +0100133 CREATE_MINIDEBUGINFO=${CREATE_MINIDEBUGINFO} \
Colin Cross3e87e832020-01-27 13:52:28 -0800134 $(SOONG_STRIP_PATH) -i $< -o $@ -d $@.strip.d $(PRIVATE_STRIP_ARGS)
David Srbeckybf086ed2021-04-30 20:01:34 +0100135 ifneq ($(HOST_OS),darwin)
136 $(strip_output): $(CREATE_MINIDEBUGINFO)
137 endif
Colin Cross3e87e832020-01-27 13:52:28 -0800138 $(call include-depfile,$(strip_output).strip.d,$(strip_output))
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700139else
Colin Cross830eed82018-09-07 23:15:46 -0700140 # Don't strip the binary, just copy it. We can't skip this step
141 # because a copy of the binary must appear at LOCAL_BUILT_MODULE.
142 $(strip_output): $(strip_input)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800143 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
144 $(copy-file-to-target)
Ying Wange1889af2014-03-16 12:43:49 -0700145endif # my_strip_module
The Android Open Source Project88b60792009-03-03 19:28:42 -0800146
Ying Wangeda6ac22013-01-28 10:58:01 -0800147$(cleantarget): PRIVATE_CLEAN_FILES += \
148 $(linked_module) \
Colin Cross70bfe072019-09-05 14:27:02 -0700149 $(inject_module) \
Steve Fungcb2e67f2015-09-24 01:40:52 -0700150 $(breakpad_output) \
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -0700151 $(symbolic_output) \
152 $(strip_output)