| 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 | ########################################################### | 
|  | 42 | ## Compress | 
|  | 43 | ########################################################### | 
|  | 44 | compress_input := $(linked_module) | 
|  | 45 |  | 
|  | 46 | ifeq ($(strip $(LOCAL_COMPRESS_MODULE_SYMBOLS)),) | 
|  | 47 | LOCAL_COMPRESS_MODULE_SYMBOLS := $(strip $(TARGET_COMPRESS_MODULE_SYMBOLS)) | 
|  | 48 | endif | 
|  | 49 |  | 
|  | 50 | ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true) | 
|  | 51 | $(error Symbol compression not yet supported.) | 
| Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 52 | compress_output := $(intermediates)/COMPRESSED-$(my_built_module_stem) | 
| The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 53 |  | 
| Bruce Beare | 45ac434 | 2010-06-24 14:02:00 -0700 | [diff] [blame] | 54 | #TODO: write the real $(STRIPPER) rule. | 
| The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 55 | #TODO: define a rule to build TARGET_SYMBOL_FILTER_FILE, and | 
|  | 56 | #      make it depend on ALL_ORIGINAL_DYNAMIC_BINARIES. | 
|  | 57 | $(compress_output): $(compress_input) $(TARGET_SYMBOL_FILTER_FILE) | $(ACP) | 
|  | 58 | @echo "target Compress Symbols: $(PRIVATE_MODULE) ($@)" | 
|  | 59 | $(copy-file-to-target) | 
|  | 60 | else | 
|  | 61 | # Skip this step. | 
|  | 62 | compress_output := $(compress_input) | 
|  | 63 | endif | 
|  | 64 |  | 
| Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 65 | ########################################################### | 
|  | 66 | ## Store a copy with symbols for symbolic debugging | 
|  | 67 | ########################################################### | 
| Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 68 | ifeq ($(LOCAL_UNSTRIPPED_PATH),) | 
| Ying Wang | b8e0185 | 2014-01-23 15:09:04 -0800 | [diff] [blame] | 69 | my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) | 
|  | 70 | else | 
|  | 71 | my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) | 
| Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 72 | endif | 
| Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 73 | symbolic_input := $(compress_output) | 
| Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 74 | symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) | 
| Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 75 | $(symbolic_output) : $(symbolic_input) | $(ACP) | 
|  | 76 | @echo "target Symbolic: $(PRIVATE_MODULE) ($@)" | 
|  | 77 | $(copy-file-to-target) | 
|  | 78 |  | 
| 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 | ########################################################### | 
| Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 83 | strip_input := $(symbolic_output) | 
| The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 84 | strip_output := $(LOCAL_BUILT_MODULE) | 
|  | 85 |  | 
| Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 86 | my_strip_module := $(LOCAL_STRIP_MODULE) | 
|  | 87 | ifeq ($(my_strip_module),) | 
|  | 88 | 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] | 89 | endif | 
|  | 90 |  | 
| Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 91 | $(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) | 
|  | 92 | $(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) | 
|  | 93 | $(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF) | 
| Ying Wang | c1729f3 | 2014-08-20 17:12:32 -0700 | [diff] [blame] | 94 | ifeq ($(my_strip_module),no_debuglink) | 
|  | 95 | $(strip_output): PRIVATE_NO_DEBUGLINK := true | 
|  | 96 | else | 
|  | 97 | $(strip_output): PRIVATE_NO_DEBUGLINK := | 
|  | 98 | endif | 
|  | 99 |  | 
|  | 100 | ifneq ($(filter true no_debuglink,$(my_strip_module)),) | 
|  | 101 | # Strip the binary | 
|  | 102 | $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) | 
|  | 103 | $(transform-to-stripped) | 
|  | 104 | else ifeq ($(my_strip_module),keep_symbols) | 
|  | 105 | # Strip only the debug frames, but leave the symbol table. | 
| Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 106 | $(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) | 
|  | 107 | $(transform-to-stripped-keep-symbols) | 
| Ying Wang | d8c5ca9 | 2014-08-10 16:19:04 -0700 | [diff] [blame] | 108 |  | 
|  | 109 | # A product may be configured to strip everything in some build variants. | 
|  | 110 | # We do the stripping as a post-install command so that LOCAL_BUILT_MODULE | 
|  | 111 | # is still with the symbols and we don't need to clean it (and relink) when | 
|  | 112 | # you switch build variant. | 
|  | 113 | ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),) | 
|  | 114 | $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \ | 
|  | 115 | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE) | 
|  | 116 | endif | 
| Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 117 | else | 
| The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 118 | # Don't strip the binary, just copy it.  We can't skip this step | 
|  | 119 | # because a copy of the binary must appear at LOCAL_BUILT_MODULE. | 
|  | 120 | # | 
|  | 121 | # If the binary we're copying is acp or a prerequisite, | 
|  | 122 | # use cp(1) instead. | 
|  | 123 | ifneq ($(LOCAL_ACP_UNAVAILABLE),true) | 
|  | 124 | $(strip_output): $(strip_input) | $(ACP) | 
|  | 125 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" | 
|  | 126 | $(copy-file-to-target) | 
|  | 127 | else | 
|  | 128 | $(strip_output): $(strip_input) | 
|  | 129 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" | 
|  | 130 | $(copy-file-to-target-with-cp) | 
|  | 131 | endif | 
| 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 |  | 
|  | 134 |  | 
| Ying Wang | eda6ac2 | 2013-01-28 10:58:01 -0800 | [diff] [blame] | 135 | $(cleantarget): PRIVATE_CLEAN_FILES += \ | 
|  | 136 | $(linked_module) \ | 
|  | 137 | $(symbolic_output) \ | 
|  | 138 | $(compress_output) |