blob: c04deefb1ea40388e5be743420c07e2ea1b3168d [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
15LOCAL_UNSTRIPPED_PATH := $(strip $(LOCAL_UNSTRIPPED_PATH))
16ifeq ($(LOCAL_UNSTRIPPED_PATH),)
17 LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_$(LOCAL_MODULE_CLASS)_UNSTRIPPED)
18endif
19
20# The name of the target file, without any path prepended.
Eric Fischer7bbec3a2009-03-25 16:12:29 -070021# TODO: This duplicates logic from base_rules.mk because we need to
22# know its results before base_rules.mk is included.
23# Consolidate the duplicates.
24LOCAL_MODULE_STEM := $(strip $(LOCAL_MODULE_STEM))
25ifeq ($(LOCAL_MODULE_STEM),)
26 LOCAL_MODULE_STEM := $(LOCAL_MODULE)
27endif
28LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE_STEM)$(LOCAL_MODULE_SUFFIX)
29LOCAL_BUILT_MODULE_STEM := $(LOCAL_INSTALLED_MODULE_STEM)
The Android Open Source Project88b60792009-03-03 19:28:42 -080030
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.
34guessed_intermediates := $(call local-intermediates-dir)
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.
40linked_module := $(guessed_intermediates)/LINKED/$(LOCAL_BUILT_MODULE_STEM)
41
42ALL_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.
49LOCAL_INTERMEDIATE_TARGETS := $(linked_module)
50
51###################################
52include $(BUILD_SYSTEM)/binary.mk
53###################################
54
55# Make sure that our guess at the value of intermediates was correct.
56ifneq ($(intermediates),$(guessed_intermediates))
57$(error Internal error: guessed path '$(guessed_intermediates)' doesn't match '$(intermediates))
58endif
59
60###########################################################
61## Compress
62###########################################################
63compress_input := $(linked_module)
64
65ifeq ($(strip $(LOCAL_COMPRESS_MODULE_SYMBOLS)),)
66 LOCAL_COMPRESS_MODULE_SYMBOLS := $(strip $(TARGET_COMPRESS_MODULE_SYMBOLS))
67endif
68
69ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true)
70$(error Symbol compression not yet supported.)
71compress_output := $(intermediates)/COMPRESSED-$(LOCAL_BUILT_MODULE_STEM)
72
Bruce Beare45ac4342010-06-24 14:02:00 -070073#TODO: write the real $(STRIPPER) rule.
The Android Open Source Project88b60792009-03-03 19:28:42 -080074#TODO: define a rule to build TARGET_SYMBOL_FILTER_FILE, and
75# make it depend on ALL_ORIGINAL_DYNAMIC_BINARIES.
76$(compress_output): $(compress_input) $(TARGET_SYMBOL_FILTER_FILE) | $(ACP)
77 @echo "target Compress Symbols: $(PRIVATE_MODULE) ($@)"
78 $(copy-file-to-target)
79else
80# Skip this step.
81compress_output := $(compress_input)
82endif
83
84
85###########################################################
86## Pre-link
87###########################################################
88prelink_input := $(compress_output)
89# The output of the prelink step is the binary we want to use
90# for symbolic debugging; the prelink step may move sections
91# around, so we have to use this version.
92prelink_output := $(LOCAL_UNSTRIPPED_PATH)/$(LOCAL_MODULE_SUBDIR)$(LOCAL_BUILT_MODULE_STEM)
93
Jing Yu2dcc8062009-09-21 16:31:50 -070094# Skip prelinker if it is FDO instrumentation build.
95ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),)
96ifneq ($(LOCAL_NO_FDO_SUPPORT),true)
97LOCAL_PRELINK_MODULE := false
98endif
99endif
100
The Android Open Source Project88b60792009-03-03 19:28:42 -0800101ifeq ($(LOCAL_PRELINK_MODULE),true)
102$(prelink_output): $(prelink_input) $(TARGET_PRELINKER_MAP) $(APRIORI)
103 $(transform-to-prelinked)
104else
105# Don't prelink the binary, just copy it. We can't skip this step
106# because people always expect a copy of the binary to appear
107# in the UNSTRIPPED directory.
108#
109# If the binary we're copying is acp or a prerequisite,
110# use cp(1) instead.
111ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
112$(prelink_output): $(prelink_input) | $(ACP)
113 @echo "target Non-prelinked: $(PRIVATE_MODULE) ($@)"
114 $(copy-file-to-target)
115else
116$(prelink_output): $(prelink_input)
117 @echo "target Non-prelinked: $(PRIVATE_MODULE) ($@)"
118 $(copy-file-to-target-with-cp)
119endif
120endif
121
122
123###########################################################
124## Strip
125###########################################################
126strip_input := $(prelink_output)
127strip_output := $(LOCAL_BUILT_MODULE)
128
129ifeq ($(strip $(LOCAL_STRIP_MODULE)),)
130 LOCAL_STRIP_MODULE := $(strip $(TARGET_STRIP_MODULE))
131endif
132
133ifeq ($(LOCAL_STRIP_MODULE),true)
134# Strip the binary
Bruce Beare45ac4342010-06-24 14:02:00 -0700135$(strip_output): $(strip_input) | $(TARGET_STRIP)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800136 $(transform-to-stripped)
137else
138# Don't strip the binary, just copy it. We can't skip this step
139# because a copy of the binary must appear at LOCAL_BUILT_MODULE.
140#
141# If the binary we're copying is acp or a prerequisite,
142# use cp(1) instead.
143ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
144$(strip_output): $(strip_input) | $(ACP)
145 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
146 $(copy-file-to-target)
147else
148$(strip_output): $(strip_input)
149 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
150 $(copy-file-to-target-with-cp)
151endif
152endif # LOCAL_STRIP_MODULE
153
154
155$(cleantarget): PRIVATE_CLEAN_FILES := \
156 $(PRIVATE_CLEAN_FILES) \
157 $(linked_module) \
158 $(compress_output) \
159 $(prelink_output)