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 | |
| 28 | ALL_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. |
| 35 | LOCAL_INTERMEDIATE_TARGETS := $(linked_module) |
| 36 | |
| 37 | ################################### |
Chih-Hung Hsieh | 289e8d6 | 2018-05-24 15:13:19 -0700 | [diff] [blame] | 38 | include $(BUILD_SYSTEM)/use_lld_setup.mk |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 39 | include $(BUILD_SYSTEM)/binary.mk |
| 40 | ################################### |
| 41 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 42 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 43 | ## Store a copy with symbols for symbolic debugging |
| 44 | ########################################################### |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 45 | ifeq ($(LOCAL_UNSTRIPPED_PATH),) |
Ying Wang | b8e0185 | 2014-01-23 15:09:04 -0800 | [diff] [blame] | 46 | my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
| 47 | else |
| 48 | my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 49 | endif |
Colin Cross | 979f9f9 | 2018-06-25 12:33:35 -0700 | [diff] [blame] | 50 | symbolic_input := $(linked_module) |
Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 51 | symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) |
Dan Willemsen | 7f01615 | 2016-02-29 17:52:39 -0800 | [diff] [blame] | 52 | $(symbolic_output) : $(symbolic_input) |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 53 | @echo "target Symbolic: $(PRIVATE_MODULE) ($@)" |
| 54 | $(copy-file-to-target) |
| 55 | |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 56 | ########################################################### |
| 57 | ## Store breakpad symbols |
| 58 | ########################################################### |
| 59 | |
| 60 | ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) |
Steve Fung | dfbab49 | 2015-09-24 18:12:33 -0700 | [diff] [blame] | 61 | my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
Colin Cross | 979f9f9 | 2018-06-25 12:33:35 -0700 | [diff] [blame] | 62 | breakpad_input := $(linked_module) |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 63 | breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym |
Steve Fung | 445beae | 2017-08-30 14:58:33 -0700 | [diff] [blame] | 64 | $(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF) |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 65 | @echo "target breakpad: $(PRIVATE_MODULE) ($@)" |
| 66 | @mkdir -p $(dir $@) |
Steve Fung | 445beae | 2017-08-30 14:58:33 -0700 | [diff] [blame] | 67 | $(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 Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 73 | $(LOCAL_BUILT_MODULE) : $(breakpad_output) |
| 74 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 75 | |
| 76 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 77 | ## Strip |
| 78 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 79 | strip_input := $(symbolic_output) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 80 | strip_output := $(LOCAL_BUILT_MODULE) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 81 | |
Ying Wang | 6efe88b | 2016-03-01 20:14:52 -0800 | [diff] [blame] | 82 | my_strip_module := $(firstword \ |
| 83 | $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ |
| 84 | $(LOCAL_STRIP_MODULE)) |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 85 | ifeq ($(my_strip_module),) |
Yabin Cui | 700883e | 2016-04-26 16:08:00 -0700 | [diff] [blame] | 86 | my_strip_module := mini-debug-info |
| 87 | endif |
| 88 | |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 89 | ifeq ($(my_strip_module),false) |
| 90 | my_strip_module := |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 91 | endif |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 92 | |
| 93 | my_strip_args := |
| 94 | ifeq ($(my_strip_module),mini-debug-info) |
| 95 | my_strip_args += --keep-mini-debug-info |
| 96 | else ifeq ($(my_strip_module),keep_symbols) |
| 97 | my_strip_args += --keep-symbols |
| 98 | endif |
| 99 | |
| 100 | ifeq (,$(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 Cui | 700883e | 2016-04-26 16:08:00 -0700 | [diff] [blame] | 104 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 105 | |
Yi Kong | 9e86573 | 2018-11-07 16:33:11 -0800 | [diff] [blame] | 106 | ifeq ($($(my_prefix)OS),darwin) |
| 107 | # llvm-strip does not support Darwin Mach-O yet. |
| 108 | my_strip_args += --use-gnu-strip |
Ying Wang | c1729f3 | 2014-08-20 17:12:32 -0700 | [diff] [blame] | 109 | endif |
| 110 | |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 111 | valid_strip := mini-debug-info keep_symbols true no_debuglink |
| 112 | ifneq (,$(filter-out $(valid_strip),$(my_strip_module))) |
| 113 | $(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] | 114 | endif |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 115 | |
| 116 | ifneq (,$(my_strip_module)) |
| 117 | $(strip_output): PRIVATE_STRIP_ARGS := $(my_strip_args) |
| 118 | $(strip_output): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX) |
| 119 | $(strip_output): $(strip_input) $(SOONG_STRIP_PATH) |
| 120 | @echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)" |
| 121 | CLANG_BIN=$(LLVM_PREBUILTS_PATH) \ |
| 122 | CROSS_COMPILE=$(PRIVATE_TOOLS_PREFIX) \ |
| 123 | XZ=$(XZ) \ |
| 124 | $(SOONG_STRIP_PATH) -i $< -o $@ -d $@.d $(PRIVATE_STRIP_ARGS) |
| 125 | $(call include-depfile,$(strip_output).d) |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 126 | else |
Colin Cross | 830eed8 | 2018-09-07 23:15:46 -0700 | [diff] [blame] | 127 | # Don't strip the binary, just copy it. We can't skip this step |
| 128 | # because a copy of the binary must appear at LOCAL_BUILT_MODULE. |
| 129 | $(strip_output): $(strip_input) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 130 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" |
| 131 | $(copy-file-to-target) |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 132 | endif # my_strip_module |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 133 | |
Ying Wang | eda6ac2 | 2013-01-28 10:58:01 -0800 | [diff] [blame] | 134 | $(cleantarget): PRIVATE_CLEAN_FILES += \ |
| 135 | $(linked_module) \ |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 136 | $(breakpad_output) \ |
Dmitriy Ivanov | 4c2d1a6 | 2015-04-20 16:59:05 -0700 | [diff] [blame] | 137 | $(symbolic_output) \ |
| 138 | $(strip_output) |