OSDN Git Service

Merge change 22348 into donut
[android-x86/build.git] / core / dynamic_binary.mk
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
15 LOCAL_UNSTRIPPED_PATH := $(strip $(LOCAL_UNSTRIPPED_PATH))
16 ifeq ($(LOCAL_UNSTRIPPED_PATH),)
17   LOCAL_UNSTRIPPED_PATH := $(TARGET_OUT_$(LOCAL_MODULE_CLASS)_UNSTRIPPED)
18 endif
19
20 # The name of the target file, without any path prepended.
21 # 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.
24 LOCAL_MODULE_STEM := $(strip $(LOCAL_MODULE_STEM))
25 ifeq ($(LOCAL_MODULE_STEM),)
26   LOCAL_MODULE_STEM := $(LOCAL_MODULE)
27 endif
28 LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE_STEM)$(LOCAL_MODULE_SUFFIX)
29 LOCAL_BUILT_MODULE_STEM := $(LOCAL_INSTALLED_MODULE_STEM)
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.
34 guessed_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.
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
55 # Make sure that our guess at the value of intermediates was correct.
56 ifneq ($(intermediates),$(guessed_intermediates))
57 $(error Internal error: guessed path '$(guessed_intermediates)' doesn't match '$(intermediates))
58 endif
59
60 ###########################################################
61 ## Compress
62 ###########################################################
63 compress_input := $(linked_module)
64
65 ifeq ($(strip $(LOCAL_COMPRESS_MODULE_SYMBOLS)),)
66   LOCAL_COMPRESS_MODULE_SYMBOLS := $(strip $(TARGET_COMPRESS_MODULE_SYMBOLS))
67 endif
68
69 ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true)
70 $(error Symbol compression not yet supported.)
71 compress_output := $(intermediates)/COMPRESSED-$(LOCAL_BUILT_MODULE_STEM)
72
73 #TODO: write the real $(SOSLIM) rule.
74 #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)
79 else
80 # Skip this step.
81 compress_output := $(compress_input)
82 endif
83
84
85 ###########################################################
86 ## Pre-link
87 ###########################################################
88 prelink_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.
92 prelink_output := $(LOCAL_UNSTRIPPED_PATH)/$(LOCAL_MODULE_SUBDIR)$(LOCAL_BUILT_MODULE_STEM)
93
94 ifeq ($(LOCAL_PRELINK_MODULE),true)
95 $(prelink_output): $(prelink_input) $(TARGET_PRELINKER_MAP) $(APRIORI)
96         $(transform-to-prelinked)
97 else
98 # Don't prelink the binary, just copy it.  We can't skip this step
99 # because people always expect a copy of the binary to appear
100 # in the UNSTRIPPED directory.
101 #
102 # If the binary we're copying is acp or a prerequisite,
103 # use cp(1) instead.
104 ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
105 $(prelink_output): $(prelink_input) | $(ACP)
106         @echo "target Non-prelinked: $(PRIVATE_MODULE) ($@)"
107         $(copy-file-to-target)
108 else
109 $(prelink_output): $(prelink_input)
110         @echo "target Non-prelinked: $(PRIVATE_MODULE) ($@)"
111         $(copy-file-to-target-with-cp)
112 endif
113 endif
114
115
116 ###########################################################
117 ## Strip
118 ###########################################################
119 strip_input := $(prelink_output)
120 strip_output := $(LOCAL_BUILT_MODULE)
121
122 ifeq ($(strip $(LOCAL_STRIP_MODULE)),)
123   LOCAL_STRIP_MODULE := $(strip $(TARGET_STRIP_MODULE))
124 endif
125
126 ifeq ($(LOCAL_STRIP_MODULE),true)
127 # Strip the binary
128 $(strip_output): $(strip_input) | $(SOSLIM)
129         $(transform-to-stripped)
130 else
131 # Don't strip the binary, just copy it.  We can't skip this step
132 # because a copy of the binary must appear at LOCAL_BUILT_MODULE.
133 #
134 # If the binary we're copying is acp or a prerequisite,
135 # use cp(1) instead.
136 ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
137 $(strip_output): $(strip_input) | $(ACP)
138         @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
139         $(copy-file-to-target)
140 else
141 $(strip_output): $(strip_input)
142         @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
143         $(copy-file-to-target-with-cp)
144 endif
145 endif # LOCAL_STRIP_MODULE
146
147
148 $(cleantarget): PRIVATE_CLEAN_FILES := \
149                         $(PRIVATE_CLEAN_FILES) \
150                         $(linked_module) \
151                         $(compress_output) \
152                         $(prelink_output)