blob: 08fb176008ff40a02adb9174545372942ab98fa2 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001###########################################################
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.
11ifdef 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))))
13endif
14
The Android Open Source Project88b60792009-03-03 19:28:42 -080015# The name of the target file, without any path prepended.
Colin Cross5a9db902014-03-21 12:27:37 -070016# This duplicates logic from base_rules.mk because we need to
17# know its results before base_rules.mk is included.
18include $(BUILD_SYSTEM)/configure_module_stem.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -080019
Ying Wang98ae7982014-12-18 14:53:52 -080020intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX))
The Android Open Source Project88b60792009-03-03 19:28:42 -080021
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 Wang98ae7982014-12-18 14:53:52 -080026linked_module := $(intermediates)/LINKED/$(my_built_module_stem)
The Android Open Source Project88b60792009-03-03 19:28:42 -080027
28ALL_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.
35LOCAL_INTERMEDIATE_TARGETS := $(linked_module)
36
37###################################
38include $(BUILD_SYSTEM)/binary.mk
39###################################
40
The Android Open Source Project88b60792009-03-03 19:28:42 -080041###########################################################
42## Compress
43###########################################################
44compress_input := $(linked_module)
45
46ifeq ($(strip $(LOCAL_COMPRESS_MODULE_SYMBOLS)),)
47 LOCAL_COMPRESS_MODULE_SYMBOLS := $(strip $(TARGET_COMPRESS_MODULE_SYMBOLS))
48endif
49
50ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true)
51$(error Symbol compression not yet supported.)
Ying Wang966c1e02014-05-20 14:43:51 -070052compress_output := $(intermediates)/COMPRESSED-$(my_built_module_stem)
The Android Open Source Project88b60792009-03-03 19:28:42 -080053
Bruce Beare45ac4342010-06-24 14:02:00 -070054#TODO: write the real $(STRIPPER) rule.
The Android Open Source Project88b60792009-03-03 19:28:42 -080055#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)
60else
61# Skip this step.
62compress_output := $(compress_input)
63endif
64
Ying Wang374b3252011-03-14 11:44:57 -070065###########################################################
66## Store a copy with symbols for symbolic debugging
67###########################################################
Ying Wangf3584962013-11-13 17:56:20 -080068ifeq ($(LOCAL_UNSTRIPPED_PATH),)
Ying Wangb8e01852014-01-23 15:09:04 -080069my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
70else
71my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
Ying Wangf3584962013-11-13 17:56:20 -080072endif
Ying Wang374b3252011-03-14 11:44:57 -070073symbolic_input := $(compress_output)
Ying Wang966c1e02014-05-20 14:43:51 -070074symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
Ying Wang374b3252011-03-14 11:44:57 -070075$(symbolic_output) : $(symbolic_input) | $(ACP)
76 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
77 $(copy-file-to-target)
78
The Android Open Source Project88b60792009-03-03 19:28:42 -080079
80###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -080081## Strip
82###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070083strip_input := $(symbolic_output)
The Android Open Source Project88b60792009-03-03 19:28:42 -080084strip_output := $(LOCAL_BUILT_MODULE)
85
Ying Wange1889af2014-03-16 12:43:49 -070086my_strip_module := $(LOCAL_STRIP_MODULE)
87ifeq ($(my_strip_module),)
88 my_strip_module := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP_MODULE)
The Android Open Source Project88b60792009-03-03 19:28:42 -080089endif
90
Ying Wange1889af2014-03-16 12:43:49 -070091ifeq ($(my_strip_module),true)
The Android Open Source Project88b60792009-03-03 19:28:42 -080092# Strip the binary
Ying Wangb8e01852014-01-23 15:09:04 -080093$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
94$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
95$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
The Android Open Source Project88b60792009-03-03 19:28:42 -080096 $(transform-to-stripped)
97else
Christopher Ferrisa6e2f932014-03-18 14:50:09 -070098ifeq ($(my_strip_module),keep_symbols)
99# Strip only the debug frames, but leave the symbol table.
100$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
101$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
102$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
103$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
104 $(transform-to-stripped-keep-symbols)
Ying Wangd8c5ca92014-08-10 16:19:04 -0700105
106# A product may be configured to strip everything in some build variants.
107# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE
108# is still with the symbols and we don't need to clean it (and relink) when
109# you switch build variant.
110ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),)
111$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \
112 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE)
113endif
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700114else
The Android Open Source Project88b60792009-03-03 19:28:42 -0800115# Don't strip the binary, just copy it. We can't skip this step
116# because a copy of the binary must appear at LOCAL_BUILT_MODULE.
117#
118# If the binary we're copying is acp or a prerequisite,
119# use cp(1) instead.
120ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
121$(strip_output): $(strip_input) | $(ACP)
122 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
123 $(copy-file-to-target)
124else
125$(strip_output): $(strip_input)
126 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
127 $(copy-file-to-target-with-cp)
128endif
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700129endif
Ying Wange1889af2014-03-16 12:43:49 -0700130endif # my_strip_module
The Android Open Source Project88b60792009-03-03 19:28:42 -0800131
132
Ying Wangeda6ac22013-01-28 10:58:01 -0800133$(cleantarget): PRIVATE_CLEAN_FILES += \
134 $(linked_module) \
135 $(symbolic_output) \
136 $(compress_output)