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 | |
| 20 | # base_rules.make defines $(intermediates), but we need its value |
| 21 | # before we include base_rules. Make a guess, and verify that |
| 22 | # it's correct once the real value is defined. |
Ying Wang | 4d2cc66 | 2014-01-16 12:36:34 -0800 | [diff] [blame] | 23 | guessed_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] | 24 | |
| 25 | # Define the target that is the unmodified output of the linker. |
| 26 | # The basename of this target must be the same as the final output |
| 27 | # binary name, because it's used to set the "soname" in the binary. |
| 28 | # The includer of this file will define a rule to build this target. |
Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 29 | linked_module := $(guessed_intermediates)/LINKED/$(my_built_module_stem) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 30 | |
| 31 | ALL_ORIGINAL_DYNAMIC_BINARIES += $(linked_module) |
| 32 | |
| 33 | # Because TARGET_SYMBOL_FILTER_FILE depends on ALL_ORIGINAL_DYNAMIC_BINARIES, |
| 34 | # the linked_module rules won't necessarily inherit the PRIVATE_ |
| 35 | # variables from LOCAL_BUILT_MODULE. This tells binary.make to explicitly |
| 36 | # define the PRIVATE_ variables for linked_module as well as for |
| 37 | # LOCAL_BUILT_MODULE. |
| 38 | LOCAL_INTERMEDIATE_TARGETS := $(linked_module) |
| 39 | |
| 40 | ################################### |
| 41 | include $(BUILD_SYSTEM)/binary.mk |
| 42 | ################################### |
| 43 | |
| 44 | # Make sure that our guess at the value of intermediates was correct. |
| 45 | ifneq ($(intermediates),$(guessed_intermediates)) |
| 46 | $(error Internal error: guessed path '$(guessed_intermediates)' doesn't match '$(intermediates)) |
| 47 | endif |
| 48 | |
| 49 | ########################################################### |
| 50 | ## Compress |
| 51 | ########################################################### |
| 52 | compress_input := $(linked_module) |
| 53 | |
| 54 | ifeq ($(strip $(LOCAL_COMPRESS_MODULE_SYMBOLS)),) |
| 55 | LOCAL_COMPRESS_MODULE_SYMBOLS := $(strip $(TARGET_COMPRESS_MODULE_SYMBOLS)) |
| 56 | endif |
| 57 | |
| 58 | ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true) |
| 59 | $(error Symbol compression not yet supported.) |
Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 60 | compress_output := $(intermediates)/COMPRESSED-$(my_built_module_stem) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 61 | |
Bruce Beare | 45ac434 | 2010-06-24 14:02:00 -0700 | [diff] [blame] | 62 | #TODO: write the real $(STRIPPER) rule. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 63 | #TODO: define a rule to build TARGET_SYMBOL_FILTER_FILE, and |
| 64 | # make it depend on ALL_ORIGINAL_DYNAMIC_BINARIES. |
| 65 | $(compress_output): $(compress_input) $(TARGET_SYMBOL_FILTER_FILE) | $(ACP) |
| 66 | @echo "target Compress Symbols: $(PRIVATE_MODULE) ($@)" |
| 67 | $(copy-file-to-target) |
| 68 | else |
| 69 | # Skip this step. |
| 70 | compress_output := $(compress_input) |
| 71 | endif |
| 72 | |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 73 | ########################################################### |
| 74 | ## Store a copy with symbols for symbolic debugging |
| 75 | ########################################################### |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 76 | ifeq ($(LOCAL_UNSTRIPPED_PATH),) |
Ying Wang | b8e0185 | 2014-01-23 15:09:04 -0800 | [diff] [blame] | 77 | my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
| 78 | else |
| 79 | my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 80 | endif |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 81 | symbolic_input := $(compress_output) |
Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 82 | symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 83 | $(symbolic_output) : $(symbolic_input) | $(ACP) |
| 84 | @echo "target Symbolic: $(PRIVATE_MODULE) ($@)" |
| 85 | $(copy-file-to-target) |
| 86 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 87 | |
| 88 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 89 | ## Strip |
| 90 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 91 | strip_input := $(symbolic_output) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 92 | strip_output := $(LOCAL_BUILT_MODULE) |
| 93 | |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 94 | my_strip_module := $(LOCAL_STRIP_MODULE) |
| 95 | ifeq ($(my_strip_module),) |
| 96 | my_strip_module := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP_MODULE) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 97 | endif |
| 98 | |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 99 | ifeq ($(my_strip_module),true) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 100 | # Strip the binary |
Ying Wang | b8e0185 | 2014-01-23 15:09:04 -0800 | [diff] [blame] | 101 | $(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 102 | $(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) |
| 103 | $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 104 | $(transform-to-stripped) |
| 105 | else |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 106 | ifeq ($(my_strip_module),keep_symbols) |
| 107 | # Strip only the debug frames, but leave the symbol table. |
| 108 | $(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 109 | $(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) |
| 110 | $(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF) |
| 111 | $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 112 | $(transform-to-stripped-keep-symbols) |
Ying Wang | d8c5ca9 | 2014-08-10 16:19:04 -0700 | [diff] [blame] | 113 | |
| 114 | # A product may be configured to strip everything in some build variants. |
| 115 | # We do the stripping as a post-install command so that LOCAL_BUILT_MODULE |
| 116 | # is still with the symbols and we don't need to clean it (and relink) when |
| 117 | # you switch build variant. |
| 118 | ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),) |
| 119 | $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \ |
| 120 | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE) |
| 121 | endif |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 122 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 123 | # Don't strip the binary, just copy it. We can't skip this step |
| 124 | # because a copy of the binary must appear at LOCAL_BUILT_MODULE. |
| 125 | # |
| 126 | # If the binary we're copying is acp or a prerequisite, |
| 127 | # use cp(1) instead. |
| 128 | ifneq ($(LOCAL_ACP_UNAVAILABLE),true) |
| 129 | $(strip_output): $(strip_input) | $(ACP) |
| 130 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" |
| 131 | $(copy-file-to-target) |
| 132 | else |
| 133 | $(strip_output): $(strip_input) |
| 134 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" |
| 135 | $(copy-file-to-target-with-cp) |
| 136 | endif |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 137 | endif |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 138 | endif # my_strip_module |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 139 | |
| 140 | |
Ying Wang | eda6ac2 | 2013-01-28 10:58:01 -0800 | [diff] [blame] | 141 | $(cleantarget): PRIVATE_CLEAN_FILES += \ |
| 142 | $(linked_module) \ |
| 143 | $(symbolic_output) \ |
| 144 | $(compress_output) |