The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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. |
| 11 | ifdef 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)))) |
| 13 | endif |
| 14 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 15 | # The name of the target file, without any path prepended. |
Colin Cross | 5a9db90 | 2014-03-21 12:27:37 -0700 | [diff] [blame] | 16 | # This duplicates logic from base_rules.mk because we need to |
| 17 | # know its results before base_rules.mk is included. |
| 18 | include $(BUILD_SYSTEM)/configure_module_stem.mk |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 19 | |
Ying Wang | 98ae798 | 2014-12-18 14:53:52 -0800 | [diff] [blame] | 20 | intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 21 | |
| 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 Willemsen | 50e8753 | 2017-05-19 14:20:02 -0700 | [diff] [blame] | 26 | linked_module := $(intermediates)/LINKED/$(notdir $(my_installed_module_stem)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 27 | |
Colin Cross | c6d6306 | 2022-03-21 14:32:42 -0700 | [diff] [blame] | 28 | # 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 Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 30 | LOCAL_INTERMEDIATE_TARGETS := $(linked_module) |
| 31 | |
| 32 | ################################### |
Chih-Hung Hsieh | 289e8d6 | 2018-05-24 15:13:19 -0700 | [diff] [blame] | 33 | include $(BUILD_SYSTEM)/use_lld_setup.mk |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 34 | include $(BUILD_SYSTEM)/binary.mk |
| 35 | ################################### |
| 36 | |
Colin Cross | 70bfe07 | 2019-09-05 14:27:02 -0700 | [diff] [blame] | 37 | ifdef LOCAL_INJECT_BSSL_HASH |
| 38 | inject_module := $(intermediates)/INJECT_BSSL_HASH/$(notdir $(my_installed_module_stem)) |
| 39 | LOCAL_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 $@ |
| 44 | else |
| 45 | inject_module := $(linked_module) |
| 46 | endif |
| 47 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 48 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 49 | ## Store a copy with symbols for symbolic debugging |
| 50 | ########################################################### |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 51 | ifeq ($(LOCAL_UNSTRIPPED_PATH),) |
Ying Wang | b8e0185 | 2014-01-23 15:09:04 -0800 | [diff] [blame] | 52 | my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
| 53 | else |
| 54 | my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 55 | endif |
Colin Cross | 70bfe07 | 2019-09-05 14:27:02 -0700 | [diff] [blame] | 56 | symbolic_input := $(inject_module) |
Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 57 | symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) |
Colin Cross | ac7febc | 2022-04-06 01:11:20 +0000 | [diff] [blame] | 58 | $(eval $(call copy-unstripped-elf-file-with-mapping,$(symbolic_input),$(symbolic_output))) |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 59 | |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 60 | ########################################################### |
| 61 | ## Store breakpad symbols |
| 62 | ########################################################### |
| 63 | |
| 64 | ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) |
Steve Fung | dfbab49 | 2015-09-24 18:12:33 -0700 | [diff] [blame] | 65 | my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
Colin Cross | 70bfe07 | 2019-09-05 14:27:02 -0700 | [diff] [blame] | 66 | breakpad_input := $(inject_module) |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 67 | breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym |
Steve Fung | 445beae | 2017-08-30 14:58:33 -0700 | [diff] [blame] | 68 | $(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF) |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 69 | @echo "target breakpad: $(PRIVATE_MODULE) ($@)" |
| 70 | @mkdir -p $(dir $@) |
Steve Fung | 445beae | 2017-08-30 14:58:33 -0700 | [diff] [blame] | 71 | $(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 Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 77 | $(LOCAL_BUILT_MODULE) : $(breakpad_output) |
| 78 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 79 | |
| 80 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 81 | ## Strip |
| 82 | ########################################################### |
Colin Cross | db98001 | 2021-04-27 19:43:33 -0700 | [diff] [blame] | 83 | strip_input := $(inject_module) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 84 | strip_output := $(LOCAL_BUILT_MODULE) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 85 | |
Colin Cross | db98001 | 2021-04-27 19:43:33 -0700 | [diff] [blame] | 86 | # 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 Wang | 6efe88b | 2016-03-01 20:14:52 -0800 | [diff] [blame] | 91 | my_strip_module := $(firstword \ |
| 92 | $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ |
| 93 | $(LOCAL_STRIP_MODULE)) |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 94 | ifeq ($(my_strip_module),) |
Yabin Cui | 700883e | 2016-04-26 16:08:00 -0700 | [diff] [blame] | 95 | my_strip_module := mini-debug-info |
| 96 | endif |
| 97 | |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 98 | ifeq ($(my_strip_module),false) |
| 99 | my_strip_module := |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 100 | endif |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 101 | |
| 102 | my_strip_args := |
| 103 | ifeq ($(my_strip_module),mini-debug-info) |
| 104 | my_strip_args += --keep-mini-debug-info |
| 105 | else ifeq ($(my_strip_module),keep_symbols) |
| 106 | my_strip_args += --keep-symbols |
| 107 | endif |
| 108 | |
| 109 | ifeq (,$(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 Cui | 700883e | 2016-04-26 16:08:00 -0700 | [diff] [blame] | 113 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 114 | |
Yi Kong | 9e86573 | 2018-11-07 16:33:11 -0800 | [diff] [blame] | 115 | ifeq ($($(my_prefix)OS),darwin) |
| 116 | # llvm-strip does not support Darwin Mach-O yet. |
| 117 | my_strip_args += --use-gnu-strip |
Ying Wang | c1729f3 | 2014-08-20 17:12:32 -0700 | [diff] [blame] | 118 | endif |
| 119 | |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 120 | valid_strip := mini-debug-info keep_symbols true no_debuglink |
| 121 | ifneq (,$(filter-out $(valid_strip),$(my_strip_module))) |
| 122 | $(call pretty-error,Invalid strip value $(my_strip_module), only one of $(valid_strip) allowed) |
Ying Wang | d8c5ca9 | 2014-08-10 16:19:04 -0700 | [diff] [blame] | 123 | endif |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 124 | |
| 125 | ifneq (,$(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 Srbecky | bf086ed | 2021-04-30 20:01:34 +0100 | [diff] [blame] | 128 | $(strip_output): $(strip_input) $(SOONG_STRIP_PATH) $(XZ) |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 129 | @echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)" |
| 130 | CLANG_BIN=$(LLVM_PREBUILTS_PATH) \ |
| 131 | CROSS_COMPILE=$(PRIVATE_TOOLS_PREFIX) \ |
| 132 | XZ=$(XZ) \ |
David Srbecky | bf086ed | 2021-04-30 20:01:34 +0100 | [diff] [blame] | 133 | CREATE_MINIDEBUGINFO=${CREATE_MINIDEBUGINFO} \ |
Colin Cross | 3e87e83 | 2020-01-27 13:52:28 -0800 | [diff] [blame] | 134 | $(SOONG_STRIP_PATH) -i $< -o $@ -d $@.strip.d $(PRIVATE_STRIP_ARGS) |
David Srbecky | bf086ed | 2021-04-30 20:01:34 +0100 | [diff] [blame] | 135 | ifneq ($(HOST_OS),darwin) |
| 136 | $(strip_output): $(CREATE_MINIDEBUGINFO) |
| 137 | endif |
Colin Cross | 3e87e83 | 2020-01-27 13:52:28 -0800 | [diff] [blame] | 138 | $(call include-depfile,$(strip_output).strip.d,$(strip_output)) |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 139 | else |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 140 | # 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 Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 143 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" |
| 144 | $(copy-file-to-target) |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 145 | endif # my_strip_module |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 146 | |
Ying Wang | eda6ac2 | 2013-01-28 10:58:01 -0800 | [diff] [blame] | 147 | $(cleantarget): PRIVATE_CLEAN_FILES += \ |
| 148 | $(linked_module) \ |
Colin Cross | 70bfe07 | 2019-09-05 14:27:02 -0700 | [diff] [blame] | 149 | $(inject_module) \ |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 150 | $(breakpad_output) \ |
Dmitriy Ivanov | 4c2d1a6 | 2015-04-20 16:59:05 -0700 | [diff] [blame] | 151 | $(symbolic_output) \ |
| 152 | $(strip_output) |