OSDN Git Service

Initial Contribution
[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 LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
22
23 # base_rules.make defines $(intermediates), but we need its value
24 # before we include base_rules.  Make a guess, and verify that
25 # it's correct once the real value is defined.
26 guessed_intermediates := $(call local-intermediates-dir)
27
28 # Define the target that is the unmodified output of the linker.
29 # The basename of this target must be the same as the final output
30 # binary name, because it's used to set the "soname" in the binary.
31 # The includer of this file will define a rule to build this target.
32 linked_module := $(guessed_intermediates)/LINKED/$(LOCAL_BUILT_MODULE_STEM)
33
34 ALL_ORIGINAL_DYNAMIC_BINARIES += $(linked_module)
35
36 # Because TARGET_SYMBOL_FILTER_FILE depends on ALL_ORIGINAL_DYNAMIC_BINARIES,
37 # the linked_module rules won't necessarily inherit the PRIVATE_
38 # variables from LOCAL_BUILT_MODULE.  This tells binary.make to explicitly
39 # define the PRIVATE_ variables for linked_module as well as for
40 # LOCAL_BUILT_MODULE.
41 LOCAL_INTERMEDIATE_TARGETS := $(linked_module)
42
43 ###################################
44 include $(BUILD_SYSTEM)/binary.mk
45 ###################################
46
47 # Make sure that our guess at the value of intermediates was correct.
48 ifneq ($(intermediates),$(guessed_intermediates))
49 $(error Internal error: guessed path '$(guessed_intermediates)' doesn't match '$(intermediates))
50 endif
51
52 ###########################################################
53 ## Compress
54 ###########################################################
55 compress_input := $(linked_module)
56
57 ifeq ($(strip $(LOCAL_COMPRESS_MODULE_SYMBOLS)),)
58   LOCAL_COMPRESS_MODULE_SYMBOLS := $(strip $(TARGET_COMPRESS_MODULE_SYMBOLS))
59 endif
60
61 ifeq ($(LOCAL_COMPRESS_MODULE_SYMBOLS),true)
62 $(error Symbol compression not yet supported.)
63 compress_output := $(intermediates)/COMPRESSED-$(LOCAL_BUILT_MODULE_STEM)
64
65 #TODO: write the real $(SOSLIM) rule.
66 #TODO: define a rule to build TARGET_SYMBOL_FILTER_FILE, and
67 #      make it depend on ALL_ORIGINAL_DYNAMIC_BINARIES.
68 $(compress_output): $(compress_input) $(TARGET_SYMBOL_FILTER_FILE) | $(ACP)
69         @echo "target Compress Symbols: $(PRIVATE_MODULE) ($@)"
70         $(copy-file-to-target)
71 else
72 # Skip this step.
73 compress_output := $(compress_input)
74 endif
75
76
77 ###########################################################
78 ## Pre-link
79 ###########################################################
80 prelink_input := $(compress_output)
81 # The output of the prelink step is the binary we want to use
82 # for symbolic debugging;  the prelink step may move sections
83 # around, so we have to use this version.
84 prelink_output := $(LOCAL_UNSTRIPPED_PATH)/$(LOCAL_MODULE_SUBDIR)$(LOCAL_BUILT_MODULE_STEM)
85
86 ifeq ($(LOCAL_PRELINK_MODULE),true)
87 $(prelink_output): $(prelink_input) $(TARGET_PRELINKER_MAP) $(APRIORI)
88         $(transform-to-prelinked)
89 else
90 # Don't prelink the binary, just copy it.  We can't skip this step
91 # because people always expect a copy of the binary to appear
92 # in the UNSTRIPPED directory.
93 #
94 # If the binary we're copying is acp or a prerequisite,
95 # use cp(1) instead.
96 ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
97 $(prelink_output): $(prelink_input) | $(ACP)
98         @echo "target Non-prelinked: $(PRIVATE_MODULE) ($@)"
99         $(copy-file-to-target)
100 else
101 $(prelink_output): $(prelink_input)
102         @echo "target Non-prelinked: $(PRIVATE_MODULE) ($@)"
103         $(copy-file-to-target-with-cp)
104 endif
105 endif
106
107
108 ###########################################################
109 ## Strip
110 ###########################################################
111 strip_input := $(prelink_output)
112 strip_output := $(LOCAL_BUILT_MODULE)
113
114 ifeq ($(strip $(LOCAL_STRIP_MODULE)),)
115   LOCAL_STRIP_MODULE := $(strip $(TARGET_STRIP_MODULE))
116 endif
117
118 ifeq ($(LOCAL_STRIP_MODULE),true)
119 # Strip the binary
120 $(strip_output): $(strip_input) | $(SOSLIM)
121         $(transform-to-stripped)
122 else
123 # Don't strip the binary, just copy it.  We can't skip this step
124 # because a copy of the binary must appear at LOCAL_BUILT_MODULE.
125 #
126 # If the binary we're copying is acp or a prerequisite,
127 # use cp(1) instead.
128 ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
129 $(strip_output): $(strip_input) | $(ACP)
130         @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
131         $(copy-file-to-target)
132 else
133 $(strip_output): $(strip_input)
134         @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
135         $(copy-file-to-target-with-cp)
136 endif
137 endif # LOCAL_STRIP_MODULE
138
139
140 $(cleantarget): PRIVATE_CLEAN_FILES := \
141                         $(PRIVATE_CLEAN_FILES) \
142                         $(linked_module) \
143                         $(compress_output) \
144                         $(prelink_output)