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