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. |
Ying Wang | 98ae798 | 2014-12-18 14:53:52 -0800 | [diff] [blame] | 26 | linked_module := $(intermediates)/LINKED/$(my_built_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 | ################################### |
| 38 | include $(BUILD_SYSTEM)/binary.mk |
| 39 | ################################### |
| 40 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 41 | ########################################################### |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 42 | ## Pack relocation tables |
| 43 | ########################################################### |
| 44 | relocation_packer_input := $(linked_module) |
| 45 | relocation_packer_output := $(intermediates)/PACKED/$(my_built_module_stem) |
| 46 | |
Dan Albert | 52831d1 | 2015-11-12 15:27:49 -0800 | [diff] [blame] | 47 | my_pack_module_relocations := false |
| 48 | ifneq ($(DISABLE_RELOCATION_PACKER),true) |
Ying Wang | 6efe88b | 2016-03-01 20:14:52 -0800 | [diff] [blame^] | 49 | my_pack_module_relocations := $(firstword \ |
| 50 | $(LOCAL_PACK_MODULE_RELOCATIONS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ |
| 51 | $(LOCAL_PACK_MODULE_RELOCATIONS)) |
Dan Albert | 52831d1 | 2015-11-12 15:27:49 -0800 | [diff] [blame] | 52 | endif |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 53 | |
| 54 | ifeq ($(my_pack_module_relocations),) |
| 55 | my_pack_module_relocations := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PACK_MODULE_RELOCATIONS) |
| 56 | endif |
| 57 | |
Dmitriy Ivanov | e24b6f7 | 2015-04-29 12:13:37 -0700 | [diff] [blame] | 58 | # Do not pack relocations for executables. Because packing results in |
| 59 | # non-zero p_vaddr which causes kernel to load executables to lower |
| 60 | # address (starting at 0x8000) http://b/20665974 |
| 61 | ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 62 | my_pack_module_relocations := false |
| 63 | endif |
| 64 | |
| 65 | # TODO (dimitry): Relocation packer is not yet available for darwin |
| 66 | ifneq ($(HOST_OS),linux) |
| 67 | my_pack_module_relocations := false |
| 68 | endif |
| 69 | |
| 70 | ifeq (true,$(my_pack_module_relocations)) |
| 71 | # Pack relocations |
Dan Willemsen | 7f01615 | 2016-02-29 17:52:39 -0800 | [diff] [blame] | 72 | $(relocation_packer_output): $(relocation_packer_input) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 73 | $(pack-elf-relocations) |
| 74 | else |
Dan Willemsen | 7f01615 | 2016-02-29 17:52:39 -0800 | [diff] [blame] | 75 | $(relocation_packer_output): $(relocation_packer_input) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 76 | @echo "target Unpacked: $(PRIVATE_MODULE) ($@)" |
| 77 | $(copy-file-to-target) |
| 78 | endif |
| 79 | |
| 80 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 81 | ## Store a copy with symbols for symbolic debugging |
| 82 | ########################################################### |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 83 | ifeq ($(LOCAL_UNSTRIPPED_PATH),) |
Ying Wang | b8e0185 | 2014-01-23 15:09:04 -0800 | [diff] [blame] | 84 | my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
| 85 | else |
| 86 | my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 87 | endif |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 88 | symbolic_input := $(relocation_packer_output) |
Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 89 | symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) |
Dan Willemsen | 7f01615 | 2016-02-29 17:52:39 -0800 | [diff] [blame] | 90 | $(symbolic_output) : $(symbolic_input) |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 91 | @echo "target Symbolic: $(PRIVATE_MODULE) ($@)" |
| 92 | $(copy-file-to-target) |
| 93 | |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 94 | ########################################################### |
| 95 | ## Store breakpad symbols |
| 96 | ########################################################### |
| 97 | |
| 98 | ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) |
Steve Fung | dfbab49 | 2015-09-24 18:12:33 -0700 | [diff] [blame] | 99 | my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 100 | breakpad_input := $(relocation_packer_output) |
| 101 | breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym |
| 102 | $(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) |
| 103 | @echo "target breakpad: $(PRIVATE_MODULE) ($@)" |
| 104 | @mkdir -p $(dir $@) |
| 105 | $(hide) $(BREAKPAD_DUMP_SYMS) -c $< > $@ |
| 106 | $(LOCAL_BUILT_MODULE) : $(breakpad_output) |
| 107 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 108 | |
| 109 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 110 | ## Strip |
| 111 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 112 | strip_input := $(symbolic_output) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 113 | strip_output := $(LOCAL_BUILT_MODULE) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 114 | |
Ying Wang | 6efe88b | 2016-03-01 20:14:52 -0800 | [diff] [blame^] | 115 | my_strip_module := $(firstword \ |
| 116 | $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ |
| 117 | $(LOCAL_STRIP_MODULE)) |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 118 | ifeq ($(my_strip_module),) |
Dmitriy Ivanov | 4c2d1a6 | 2015-04-20 16:59:05 -0700 | [diff] [blame] | 119 | my_strip_module := true |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 120 | endif |
| 121 | |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 122 | $(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 123 | $(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) |
| 124 | $(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF) |
Ying Wang | c1729f3 | 2014-08-20 17:12:32 -0700 | [diff] [blame] | 125 | ifeq ($(my_strip_module),no_debuglink) |
| 126 | $(strip_output): PRIVATE_NO_DEBUGLINK := true |
| 127 | else |
| 128 | $(strip_output): PRIVATE_NO_DEBUGLINK := |
| 129 | endif |
| 130 | |
| 131 | ifneq ($(filter true no_debuglink,$(my_strip_module)),) |
| 132 | # Strip the binary |
| 133 | $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 134 | $(transform-to-stripped) |
| 135 | else ifeq ($(my_strip_module),keep_symbols) |
| 136 | # Strip only the debug frames, but leave the symbol table. |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 137 | $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 138 | $(transform-to-stripped-keep-symbols) |
Ying Wang | d8c5ca9 | 2014-08-10 16:19:04 -0700 | [diff] [blame] | 139 | |
| 140 | # A product may be configured to strip everything in some build variants. |
| 141 | # We do the stripping as a post-install command so that LOCAL_BUILT_MODULE |
| 142 | # is still with the symbols and we don't need to clean it (and relink) when |
| 143 | # you switch build variant. |
| 144 | ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),) |
| 145 | $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \ |
| 146 | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE) |
| 147 | endif |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 148 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 149 | # Don't strip the binary, just copy it. We can't skip this step |
| 150 | # because a copy of the binary must appear at LOCAL_BUILT_MODULE. |
Dan Willemsen | 7f01615 | 2016-02-29 17:52:39 -0800 | [diff] [blame] | 151 | $(strip_output): $(strip_input) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 152 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" |
| 153 | $(copy-file-to-target) |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 154 | endif # my_strip_module |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 155 | |
Ying Wang | eda6ac2 | 2013-01-28 10:58:01 -0800 | [diff] [blame] | 156 | $(cleantarget): PRIVATE_CLEAN_FILES += \ |
| 157 | $(linked_module) \ |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 158 | $(breakpad_output) \ |
Dmitriy Ivanov | 4c2d1a6 | 2015-04-20 16:59:05 -0700 | [diff] [blame] | 159 | $(symbolic_output) \ |
| 160 | $(strip_output) |