blob: b3ca4fcbd52aad379f06c6df8ae246fb26109499 [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
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 Wang4d2cc662014-01-16 12:36:34 -080023guessed_intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX))
The Android Open Source Project88b60792009-03-03 19:28:42 -080024
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.
29linked_module := $(guessed_intermediates)/LINKED/$(LOCAL_BUILT_MODULE_STEM)
30
31ALL_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.
38LOCAL_INTERMEDIATE_TARGETS := $(linked_module)
39
40###################################
41include $(BUILD_SYSTEM)/binary.mk
42###################################
43
Ying Wang4d2cc662014-01-16 12:36:34 -080044$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX)
45
The Android Open Source Project88b60792009-03-03 19:28:42 -080046# Make sure that our guess at the value of intermediates was correct.
47ifneq ($(intermediates),$(guessed_intermediates))
48$(error Internal error: guessed path '$(guessed_intermediates)' doesn't match '$(intermediates))
49endif
50
51###########################################################
52## Compress
53###########################################################
54compress_input := $(linked_module)
55
56ifeq ($(strip $(LOCAL_COMPRESS_MODULE_SYMBOLS)),)
57 LOCAL_COMPRESS_MODULE_SYMBOLS := $(strip $(TARGET_COMPRESS_MODULE_SYMBOLS))
58endif
59
60ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true)
61$(error Symbol compression not yet supported.)
62compress_output := $(intermediates)/COMPRESSED-$(LOCAL_BUILT_MODULE_STEM)
63
Bruce Beare45ac4342010-06-24 14:02:00 -070064#TODO: write the real $(STRIPPER) rule.
The Android Open Source Project88b60792009-03-03 19:28:42 -080065#TODO: define a rule to build TARGET_SYMBOL_FILTER_FILE, and
66# make it depend on ALL_ORIGINAL_DYNAMIC_BINARIES.
67$(compress_output): $(compress_input) $(TARGET_SYMBOL_FILTER_FILE) | $(ACP)
68 @echo "target Compress Symbols: $(PRIVATE_MODULE) ($@)"
69 $(copy-file-to-target)
70else
71# Skip this step.
72compress_output := $(compress_input)
73endif
74
Ying Wang374b3252011-03-14 11:44:57 -070075###########################################################
76## Store a copy with symbols for symbolic debugging
77###########################################################
Ying Wangf3584962013-11-13 17:56:20 -080078ifeq ($(LOCAL_UNSTRIPPED_PATH),)
Ying Wangb8e01852014-01-23 15:09:04 -080079my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
80else
81my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
Ying Wangf3584962013-11-13 17:56:20 -080082endif
Ying Wang374b3252011-03-14 11:44:57 -070083symbolic_input := $(compress_output)
Ying Wangb8e01852014-01-23 15:09:04 -080084symbolic_output := $(my_unstripped_path)/$(LOCAL_INSTALLED_MODULE_STEM)
Ying Wang374b3252011-03-14 11:44:57 -070085$(symbolic_output) : $(symbolic_input) | $(ACP)
86 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
87 $(copy-file-to-target)
88
The Android Open Source Project88b60792009-03-03 19:28:42 -080089
90###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -080091## Strip
92###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070093strip_input := $(symbolic_output)
The Android Open Source Project88b60792009-03-03 19:28:42 -080094strip_output := $(LOCAL_BUILT_MODULE)
95
Ying Wange1889af2014-03-16 12:43:49 -070096my_strip_module := $(LOCAL_STRIP_MODULE)
97ifeq ($(my_strip_module),)
98 my_strip_module := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP_MODULE)
The Android Open Source Project88b60792009-03-03 19:28:42 -080099endif
100
Ying Wange1889af2014-03-16 12:43:49 -0700101ifeq ($(my_strip_module),true)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800102# Strip the binary
Ying Wangb8e01852014-01-23 15:09:04 -0800103$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
104$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
105$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800106 $(transform-to-stripped)
107else
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700108ifeq ($(my_strip_module),keep_symbols)
109# Strip only the debug frames, but leave the symbol table.
110$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
111$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
112$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
113$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
114 $(transform-to-stripped-keep-symbols)
115else
The Android Open Source Project88b60792009-03-03 19:28:42 -0800116# Don't strip the binary, just copy it. We can't skip this step
117# because a copy of the binary must appear at LOCAL_BUILT_MODULE.
118#
119# If the binary we're copying is acp or a prerequisite,
120# use cp(1) instead.
121ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
122$(strip_output): $(strip_input) | $(ACP)
123 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
124 $(copy-file-to-target)
125else
126$(strip_output): $(strip_input)
127 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
128 $(copy-file-to-target-with-cp)
129endif
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700130endif
Ying Wange1889af2014-03-16 12:43:49 -0700131endif # my_strip_module
The Android Open Source Project88b60792009-03-03 19:28:42 -0800132
133
Ying Wangeda6ac22013-01-28 10:58:01 -0800134$(cleantarget): PRIVATE_CLEAN_FILES += \
135 $(linked_module) \
136 $(symbolic_output) \
137 $(compress_output)