OSDN Git Service

merge from open-source master
[android-x86/build.git] / core / java.mk
1 # Requires:
2 # LOCAL_MODULE_SUFFIX
3 # LOCAL_MODULE_CLASS
4 # all_res_assets
5
6 # Make sure there's something to build.
7 # It's possible to build a package that doesn't contain any classes.
8 ifeq (,$(strip $(LOCAL_SRC_FILES)$(all_res_assets)))
9 $(error $(LOCAL_PATH): Target java module does not define any source or resource files)
10 endif
11
12 LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES))
13 LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION))
14
15 ifneq ($(LOCAL_SDK_VERSION),)
16   ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
17     $(error $(LOCAL_PATH): Must not define both LOCAL_NO_STANDARD_LIBRARIES and LOCAL_SDK_VERSION)
18   else
19     ifeq ($(strip $(filter $(LOCAL_SDK_VERSION),$(TARGET_AVAILABLE_SDK_VERSIONS))),)
20       $(error $(LOCAL_PATH): Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \
21              Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS))
22     else
23       LOCAL_JAVA_LIBRARIES := android_stubs_$(LOCAL_SDK_VERSION) $(LOCAL_JAVA_LIBRARIES) 
24     endif
25   endif
26 else
27   ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
28     LOCAL_JAVA_LIBRARIES := core ext framework $(LOCAL_JAVA_LIBRARIES)
29   endif
30 endif
31
32 LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))
33 ifeq ($(LOCAL_BUILT_MODULE_STEM),)
34 $(error $(LOCAL_PATH): Target java template must define LOCAL_BUILT_MODULE_STEM)
35 endif
36 ifneq ($(filter classes-compiled.jar classes.jar,$(LOCAL_BUILT_MODULE_STEM)),)
37 $(error LOCAL_BUILT_MODULE_STEM may not be "$(LOCAL_BUILT_MODULE_STEM)")
38 endif
39
40
41 ##############################################################################
42 # Define the intermediate targets before including base_rules so they get
43 # the correct environment.
44 ##############################################################################
45
46 intermediates := $(call local-intermediates-dir)
47 intermediates.COMMON := $(call local-intermediates-dir,COMMON)
48
49 # This is cleared below, and re-set if we really need it.
50 full_classes_jar := $(intermediates.COMMON)/classes.jar
51
52 # Emma source code coverage
53 ifneq ($(EMMA_INSTRUMENT),true)
54 LOCAL_NO_EMMA_INSTRUMENT := true
55 LOCAL_NO_EMMA_COMPILE := true
56 endif
57
58 # Choose leaf name for the compiled jar file.
59 ifneq ($(LOCAL_NO_EMMA_COMPILE),true)
60 full_classes_compiled_jar_leaf := classes-no-debug-var.jar
61 else
62 full_classes_compiled_jar_leaf := classes-full-debug.jar
63 endif
64 full_classes_compiled_jar := $(intermediates.COMMON)/$(full_classes_compiled_jar_leaf)
65
66 emma_intermediates_dir := $(intermediates.COMMON)/emma_out
67 # the 'lib/$(full_classes_compiled_jar_leaf)' portion of this path is fixed in
68 # the emma tool
69 full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(full_classes_compiled_jar_leaf)
70 full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
71 full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar
72 full_classes_proguard_jar := $(full_classes_jar)
73 built_dex := $(intermediates.COMMON)/classes.dex
74
75 LOCAL_INTERMEDIATE_TARGETS += \
76     $(full_classes_jar) \
77     $(full_classes_compiled_jar) \
78     $(full_classes_emma_jar) \
79     $(full_classes_stubs_jar) \
80     $(full_classes_jarjar_jar) \
81     $(built_dex)
82
83
84 # TODO: It looks like the only thing we need from base_rules is
85 # all_java_sources.  See if we can get that by adding a
86 # common_java.mk, and moving the include of base_rules.mk to
87 # after all the declarations.
88
89 #######################################
90 include $(BUILD_SYSTEM)/base_rules.mk
91 #######################################
92
93 # We use intermediates.COMMON because the classes.jar/.dex files will be
94 # common even if LOCAL_BUILT_MODULE isn't.
95 #
96 # Override some target variables that base_rules set up for us.
97 $(LOCAL_INTERMEDIATE_TARGETS): \
98         PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes
99 $(LOCAL_INTERMEDIATE_TARGETS): \
100         PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/src
101
102 # Since we're using intermediates.COMMON, make sure that it gets cleaned
103 # properly.
104 $(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
105
106 # If the module includes java code (i.e., it's not framework-res), compile it.
107 full_classes_jar :=
108 built_dex :=
109 ifneq (,$(strip $(all_java_sources)))
110
111 # If LOCAL_BUILT_MODULE_STEM wasn't overridden by our caller,
112 # full_classes_jar will be the same module as LOCAL_BUILT_MODULE.
113 # Otherwise, the caller will define it as a prerequisite of
114 # LOCAL_BUILT_MODULE, so it will inherit the necessary PRIVATE_*
115 # variable definitions.
116 full_classes_jar := $(intermediates.COMMON)/classes.jar
117 built_dex := $(intermediates.COMMON)/classes.dex
118
119 # Droiddoc isn't currently able to generate stubs for modules, so we're just
120 # allowing it to use the classes.jar as the "stubs" that would be use to link
121 # against, for the cases where someone needs the jar to link against.
122 # - Use the classes.jar instead of the handful of other intermediates that
123 #   we have, because it's the most processed, but still hasn't had dex run on
124 #   it, so it's closest to what's on the device.
125 # - This extra copy, with the dependency on LOCAL_BUILT_MODULE allows the
126 #   PRIVATE_ vars to be preserved.
127 $(full_classes_stubs_jar): PRIVATE_SOURCE_FILE := $(full_classes_jar)
128 $(full_classes_stubs_jar) : $(LOCAL_BUILT_MODULE) | $(ACP)
129         @echo Copying $(PRIVATE_SOURCE_FILE)
130         $(hide) $(ACP) -fp $(PRIVATE_SOURCE_FILE) $@
131 ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar)
132
133 # Compile the java files to a .jar file.
134 # This intentionally depends on java_sources, not all_java_sources.
135 # Deps for generated source files must be handled separately,
136 # via deps on the target that generates the sources.
137 $(full_classes_compiled_jar): $(java_sources) $(full_java_lib_deps)
138         $(transform-java-to-classes.jar)
139
140 # All of the rules after full_classes_compiled_jar are very unlikely
141 # to fail except for bugs in their respective tools.  If you would
142 # like to run these rules, add the "all" modifier goal to the make
143 # command line.
144 # This overwrites the value defined in base_rules.mk.  That's a little
145 # dirty.  It's preferable to set LOCAL_CHECKED_MODULE, but this has to
146 # be done after the inclusion of base_rules.mk.
147 ALL_MODULES.$(LOCAL_MODULE).CHECKED := $(full_classes_compiled_jar)
148
149 ifneq ($(LOCAL_NO_EMMA_COMPILE),true) 
150 # If you instrument class files that have local variable debug information in
151 # them emma does not correctly maintain the local variable table.
152 # This will cause an error when you try to convert the class files for Android.
153 # The workaround for this to compile the java classes with only
154 # line and source debug information, not local information.
155 $(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g:{lines,source}
156 else
157 # when emma is off, compile with the default flags, which contain full debug 
158 # info
159 $(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g
160 endif
161
162 ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
163 # Skip adding emma instrumentation to class files if this is a static library,
164 # since it will be instrumented by the package that includes it
165 LOCAL_NO_EMMA_INSTRUMENT:= true
166 endif
167
168 ifneq ($(LOCAL_NO_EMMA_INSTRUMENT),true)
169 $(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.em
170 $(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir)
171 # this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and
172 # $(full_classes_emma_jar)
173 $(full_classes_emma_jar): $(full_classes_compiled_jar)
174         $(transform-classes.jar-to-emma)
175 $(PRIVATE_EMMA_COVERAGE_FILE): $(full_classes_emma_jar)
176 else
177 $(full_classes_emma_jar): $(full_classes_compiled_jar) | $(ACP)
178         @echo Copying: $<
179         $(copy-file-to-target)
180 endif
181
182 # Run jarjar if necessary, otherwise just copy the file.
183 ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
184 $(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
185 $(full_classes_jarjar_jar): $(full_classes_emma_jar) | $(JARJAR)
186         @echo JarJar: $@
187         $(hide) $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
188 else
189 $(full_classes_jarjar_jar): $(full_classes_emma_jar) | $(ACP)
190         @echo Copying: $@
191         $(hide) $(ACP) $< $@
192 endif
193
194 # Run proguard if necessary, otherwise just copy the file.  This is the last
195 # part of this step, so the output of this command is full_classes_jar.
196 ifneq ($(strip $(LOCAL_PROGUARD_ENABLED)),)
197 proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
198 proguard_flags := $(addprefix -libraryjars ,$(full_java_libs)) \
199                   -include $(BUILD_SYSTEM)/proguard.flags \
200                   -forceprocessing \
201                   -printmapping $(proguard_dictionary)
202 ifeq ($(strip $(LOCAL_PROGUARD_ENABLED)),full)
203     # full
204 else
205 ifeq ($(strip $(LOCAL_PROGUARD_ENABLED)),optonly)
206     # optonly
207     proguard_flags += -dontobfuscate
208 else
209 ifeq ($(strip $(LOCAL_PROGUARD_ENABLED)),custom)
210     # custom
211 else
212     $(warning while processing: $(LOCAL_MODULE))
213     $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
214 endif
215 endif
216 endif
217
218 $(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(proguard_flags) $(LOCAL_PROGUARD_FLAGS)
219 $(full_classes_proguard_jar): $(full_classes_emma_jar) | $(PROGUARD)
220         @echo Proguard: $@
221         $(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS)
222 else
223 $(full_classes_proguard_jar): $(full_classes_emma_jar) | $(ACP)
224         @echo Copying: $@
225         $(hide) $(ACP) $< $@
226 endif
227
228 # Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug
229 # will work even when intermediates != intermediates.COMMON.
230 $(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
231 $(built_dex): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
232 $(built_dex): $(full_classes_jar) $(DX)
233         $(transform-classes.jar-to-dex)
234 ifneq ($(GENERATE_DEX_DEBUG),)
235         $(install-dex-debug)
236 endif
237
238 findbugs_xml := $(intermediates.COMMON)/findbugs.xml
239 $(findbugs_xml) : PRIVATE_JAR_FILE := $(full_classes_jar)
240 $(findbugs_xml) : PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
241                                                                 $(call normalize-path-list,$(filter %.jar,\
242                                                                                 $(full_java_libs)))))
243 # We can't depend directly on full_classes_jar because the PRIVATE_
244 # vars won't be set up correctly.
245 $(findbugs_xml) : $(LOCAL_BUILT_MODULE)
246         @echo Findbugs: $@
247         $(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
248                 $(PRIVATE_AUXCLASSPATH) \
249                 $(PRIVATE_JAR_FILE) \
250                 > $@
251
252 ALL_FINDBUGS_FILES += $(findbugs_xml)
253
254 findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html
255 $(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml)
256 $(LOCAL_MODULE)-findbugs : $(findbugs_html)
257 $(findbugs_html) : $(findbugs_xml)
258         @mkdir -p $(dir $@)
259         @echo ConvertXmlToText: $@
260         $(hide) prebuilt/common/findbugs/bin/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \
261         > $@
262
263 $(LOCAL_MODULE)-findbugs : $(findbugs_html)
264
265 endif