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 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 42 | ## Store a copy with symbols for symbolic debugging |
| 43 | ########################################################### |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 44 | ifeq ($(LOCAL_UNSTRIPPED_PATH),) |
Ying Wang | b8e0185 | 2014-01-23 15:09:04 -0800 | [diff] [blame] | 45 | my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
| 46 | else |
| 47 | my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 48 | endif |
Dmitriy Ivanov | 4eb120b | 2015-04-20 12:06:37 -0700 | [diff] [blame] | 49 | symbolic_input := $(linked_module) |
Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 50 | symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 51 | $(symbolic_output) : $(symbolic_input) | $(ACP) |
| 52 | @echo "target Symbolic: $(PRIVATE_MODULE) ($@)" |
| 53 | $(copy-file-to-target) |
| 54 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 55 | |
| 56 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 57 | ## Strip |
| 58 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 59 | strip_input := $(symbolic_output) |
Dmitriy Ivanov | 4c2d1a6 | 2015-04-20 16:59:05 -0700 | [diff] [blame^] | 60 | strip_output := $(intermediates)/STRIPPED/$(my_built_module_stem) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 61 | |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 62 | my_strip_module := $(LOCAL_STRIP_MODULE) |
| 63 | ifeq ($(my_strip_module),) |
Dmitriy Ivanov | 4c2d1a6 | 2015-04-20 16:59:05 -0700 | [diff] [blame^] | 64 | my_strip_module := true |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 65 | endif |
| 66 | |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 67 | $(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 68 | $(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) |
| 69 | $(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF) |
Ying Wang | c1729f3 | 2014-08-20 17:12:32 -0700 | [diff] [blame] | 70 | ifeq ($(my_strip_module),no_debuglink) |
| 71 | $(strip_output): PRIVATE_NO_DEBUGLINK := true |
| 72 | else |
| 73 | $(strip_output): PRIVATE_NO_DEBUGLINK := |
| 74 | endif |
| 75 | |
| 76 | ifneq ($(filter true no_debuglink,$(my_strip_module)),) |
| 77 | # Strip the binary |
| 78 | $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 79 | $(transform-to-stripped) |
| 80 | else ifeq ($(my_strip_module),keep_symbols) |
| 81 | # Strip only the debug frames, but leave the symbol table. |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 82 | $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 83 | $(transform-to-stripped-keep-symbols) |
Ying Wang | d8c5ca9 | 2014-08-10 16:19:04 -0700 | [diff] [blame] | 84 | |
| 85 | # A product may be configured to strip everything in some build variants. |
| 86 | # We do the stripping as a post-install command so that LOCAL_BUILT_MODULE |
| 87 | # is still with the symbols and we don't need to clean it (and relink) when |
| 88 | # you switch build variant. |
| 89 | ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),) |
| 90 | $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \ |
| 91 | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE) |
| 92 | endif |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 93 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 94 | # Don't strip the binary, just copy it. We can't skip this step |
| 95 | # because a copy of the binary must appear at LOCAL_BUILT_MODULE. |
| 96 | # |
| 97 | # If the binary we're copying is acp or a prerequisite, |
| 98 | # use cp(1) instead. |
| 99 | ifneq ($(LOCAL_ACP_UNAVAILABLE),true) |
| 100 | $(strip_output): $(strip_input) | $(ACP) |
| 101 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" |
| 102 | $(copy-file-to-target) |
| 103 | else |
| 104 | $(strip_output): $(strip_input) |
| 105 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" |
| 106 | $(copy-file-to-target-with-cp) |
| 107 | endif |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 108 | endif # my_strip_module |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 109 | |
Dmitriy Ivanov | 4c2d1a6 | 2015-04-20 16:59:05 -0700 | [diff] [blame^] | 110 | ########################################################### |
| 111 | ## Pack relocation tables |
| 112 | ########################################################### |
| 113 | relocation_packer_input := $(strip_output) |
| 114 | relocation_packer_output := $(LOCAL_BUILT_MODULE) |
| 115 | |
| 116 | my_pack_module_relocations := $(LOCAL_PACK_MODULE_RELOCATIONS) |
| 117 | |
| 118 | ifeq ($(my_pack_module_relocations),) |
| 119 | my_pack_module_relocations := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PACK_MODULE_RELOCATIONS) |
| 120 | endif |
| 121 | |
| 122 | # Do not pack relocations for static executables. |
| 123 | ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
| 124 | my_pack_module_relocations := false |
| 125 | endif |
| 126 | |
| 127 | # TODO (dimitry): Relocation packer is not yet available for darwin |
| 128 | ifneq ($(HOST_OS),linux) |
| 129 | my_pack_module_relocations := false |
| 130 | endif |
| 131 | |
| 132 | ifeq (true,$(my_pack_module_relocations)) |
| 133 | # Pack relocations |
| 134 | $(relocation_packer_output): $(relocation_packer_input) | $(ACP) |
| 135 | $(pack-elf-relocations) |
| 136 | else |
| 137 | $(relocation_packer_output): $(relocation_packer_input) | $(ACP) |
| 138 | @echo "target Unpacked: $(PRIVATE_MODULE) ($@)" |
| 139 | $(copy-file-to-target) |
| 140 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 141 | |
Ying Wang | eda6ac2 | 2013-01-28 10:58:01 -0800 | [diff] [blame] | 142 | $(cleantarget): PRIVATE_CLEAN_FILES += \ |
| 143 | $(linked_module) \ |
Dmitriy Ivanov | 4c2d1a6 | 2015-04-20 16:59:05 -0700 | [diff] [blame^] | 144 | $(symbolic_output) \ |
| 145 | $(strip_output) |