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