blob: d57ffca9c8462de0ffc4a8a6223a7bf24cda0385 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001# 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
Ying Wang6ef046c2009-12-07 18:14:00 -080031LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES))
The Android Open Source Project88b60792009-03-03 19:28:42 -080032
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
Joe Onoratoe334d252009-07-17 15:33:40 -040041
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
Joe Onorato2daa2b32009-08-30 13:39:24 -070072full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar
Ying Wang3b2bdf12010-02-01 09:51:23 -080073full_classes_full_names_jar := $(intermediates.COMMON)/classes-full-names.jar
Joe Onorato2daa2b32009-08-30 13:39:24 -070074full_classes_proguard_jar := $(full_classes_jar)
Joe Onoratoe334d252009-07-17 15:33:40 -040075built_dex := $(intermediates.COMMON)/classes.dex
76
77LOCAL_INTERMEDIATE_TARGETS += \
78 $(full_classes_jar) \
79 $(full_classes_compiled_jar) \
80 $(full_classes_emma_jar) \
81 $(full_classes_stubs_jar) \
82 $(full_classes_jarjar_jar) \
83 $(built_dex)
84
85
86# TODO: It looks like the only thing we need from base_rules is
87# all_java_sources. See if we can get that by adding a
88# common_java.mk, and moving the include of base_rules.mk to
89# after all the declarations.
90
The Android Open Source Project88b60792009-03-03 19:28:42 -080091#######################################
92include $(BUILD_SYSTEM)/base_rules.mk
93#######################################
94
95# We use intermediates.COMMON because the classes.jar/.dex files will be
96# common even if LOCAL_BUILT_MODULE isn't.
97#
98# Override some target variables that base_rules set up for us.
99$(LOCAL_INTERMEDIATE_TARGETS): \
100 PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes
101$(LOCAL_INTERMEDIATE_TARGETS): \
102 PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/src
103
104# Since we're using intermediates.COMMON, make sure that it gets cleaned
105# properly.
106$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON)
107
108# If the module includes java code (i.e., it's not framework-res), compile it.
109full_classes_jar :=
110built_dex :=
111ifneq (,$(strip $(all_java_sources)))
112
113# If LOCAL_BUILT_MODULE_STEM wasn't overridden by our caller,
114# full_classes_jar will be the same module as LOCAL_BUILT_MODULE.
115# Otherwise, the caller will define it as a prerequisite of
116# LOCAL_BUILT_MODULE, so it will inherit the necessary PRIVATE_*
117# variable definitions.
118full_classes_jar := $(intermediates.COMMON)/classes.jar
Joe Onoratoe334d252009-07-17 15:33:40 -0400119built_dex := $(intermediates.COMMON)/classes.dex
The Android Open Source Project88b60792009-03-03 19:28:42 -0800120
Joe Onorato64d85d02009-04-09 19:31:12 -0700121# Droiddoc isn't currently able to generate stubs for modules, so we're just
122# allowing it to use the classes.jar as the "stubs" that would be use to link
123# against, for the cases where someone needs the jar to link against.
124# - Use the classes.jar instead of the handful of other intermediates that
125# we have, because it's the most processed, but still hasn't had dex run on
126# it, so it's closest to what's on the device.
127# - This extra copy, with the dependency on LOCAL_BUILT_MODULE allows the
128# PRIVATE_ vars to be preserved.
Joe Onorato64d85d02009-04-09 19:31:12 -0700129$(full_classes_stubs_jar): PRIVATE_SOURCE_FILE := $(full_classes_jar)
130$(full_classes_stubs_jar) : $(LOCAL_BUILT_MODULE) | $(ACP)
131 @echo Copying $(PRIVATE_SOURCE_FILE)
132 $(hide) $(ACP) -fp $(PRIVATE_SOURCE_FILE) $@
133ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar)
134
The Android Open Source Project88b60792009-03-03 19:28:42 -0800135# Compile the java files to a .jar file.
136# This intentionally depends on java_sources, not all_java_sources.
137# Deps for generated source files must be handled separately,
138# via deps on the target that generates the sources.
Brian Carlstromf184a0f2010-02-01 11:13:32 -0800139$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800140$(full_classes_compiled_jar): $(java_sources) $(full_java_lib_deps)
141 $(transform-java-to-classes.jar)
142
Joe Onoratoe334d252009-07-17 15:33:40 -0400143# All of the rules after full_classes_compiled_jar are very unlikely
144# to fail except for bugs in their respective tools. If you would
145# like to run these rules, add the "all" modifier goal to the make
146# command line.
147# This overwrites the value defined in base_rules.mk. That's a little
148# dirty. It's preferable to set LOCAL_CHECKED_MODULE, but this has to
149# be done after the inclusion of base_rules.mk.
150ALL_MODULES.$(LOCAL_MODULE).CHECKED := $(full_classes_compiled_jar)
151
Joe Onoratobd46b212009-03-24 19:07:34 -0700152ifneq ($(LOCAL_NO_EMMA_COMPILE),true)
153# If you instrument class files that have local variable debug information in
154# them emma does not correctly maintain the local variable table.
155# This will cause an error when you try to convert the class files for Android.
156# The workaround for this to compile the java classes with only
157# line and source debug information, not local information.
158$(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g:{lines,source}
159else
160# when emma is off, compile with the default flags, which contain full debug
161# info
162$(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g
163endif
164
The Android Open Source Project88b60792009-03-03 19:28:42 -0800165ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
166# Skip adding emma instrumentation to class files if this is a static library,
167# since it will be instrumented by the package that includes it
168LOCAL_NO_EMMA_INSTRUMENT:= true
169endif
170
171ifneq ($(LOCAL_NO_EMMA_INSTRUMENT),true)
172$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.em
173$(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir)
174# this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and
175# $(full_classes_emma_jar)
176$(full_classes_emma_jar): $(full_classes_compiled_jar)
177 $(transform-classes.jar-to-emma)
178$(PRIVATE_EMMA_COVERAGE_FILE): $(full_classes_emma_jar)
179else
180$(full_classes_emma_jar): $(full_classes_compiled_jar) | $(ACP)
Joe Onorato2daa2b32009-08-30 13:39:24 -0700181 @echo Copying: $<
The Android Open Source Project88b60792009-03-03 19:28:42 -0800182 $(copy-file-to-target)
183endif
184
Joe Onorato2daa2b32009-08-30 13:39:24 -0700185# Run jarjar if necessary, otherwise just copy the file.
The Android Open Source Project88b60792009-03-03 19:28:42 -0800186ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
187$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
Joe Onorato2daa2b32009-08-30 13:39:24 -0700188$(full_classes_jarjar_jar): $(full_classes_emma_jar) | $(JARJAR)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800189 @echo JarJar: $@
190 $(hide) $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
191else
192$(full_classes_jarjar_jar): $(full_classes_emma_jar) | $(ACP)
193 @echo Copying: $@
194 $(hide) $(ACP) $< $@
195endif
196
Ying Wang3b2bdf12010-02-01 09:51:23 -0800197# Keep a copy of the jar just before proguard processing.
198$(full_classes_full_names_jar): $(full_classes_emma_jar) | $(ACP)
199 @echo Copying: $@
200 $(hide) $(ACP) $< $@
201
Joe Onorato2daa2b32009-08-30 13:39:24 -0700202# Run proguard if necessary, otherwise just copy the file. This is the last
203# part of this step, so the output of this command is full_classes_jar.
Joe Onorato2daa2b32009-08-30 13:39:24 -0700204proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
Ying Wang3b2bdf12010-02-01 09:51:23 -0800205# Proguard doesn't like a class in both library and the jar to be processed.
206proguard_full_java_libs := $(filter-out $(full_static_java_libs),$(full_java_libs))
207proguard_flags := $(addprefix -libraryjars ,$(proguard_full_java_libs)) \
Joe Onorato2daa2b32009-08-30 13:39:24 -0700208 -include $(BUILD_SYSTEM)/proguard.flags \
209 -forceprocessing \
210 -printmapping $(proguard_dictionary)
Ying Wang3b2bdf12010-02-01 09:51:23 -0800211# If this is a test package, add proguard keep flags for tests.
212ifneq ($(strip $(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS))$(filter android.test.runner,$(LOCAL_JAVA_LIBRARIES))),)
213proguard_flags := $(proguard_flags) -include $(BUILD_SYSTEM)/proguard_tests.flags
214endif # test package
215
216LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
217ifneq ($(LOCAL_PROGUARD_ENABLED),)
218ifeq ($(LOCAL_PROGUARD_ENABLED),full)
Joe Onorato2daa2b32009-08-30 13:39:24 -0700219 # full
220else
Ying Wang3b2bdf12010-02-01 09:51:23 -0800221ifeq ($(LOCAL_PROGUARD_ENABLED),optonly)
Joe Onorato2daa2b32009-08-30 13:39:24 -0700222 # optonly
223 proguard_flags += -dontobfuscate
224else
Ying Wang3b2bdf12010-02-01 09:51:23 -0800225ifeq ($(LOCAL_PROGUARD_ENABLED),custom)
Joe Onorato2daa2b32009-08-30 13:39:24 -0700226 # custom
227else
228 $(warning while processing: $(LOCAL_MODULE))
229 $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
Ying Wang3b2bdf12010-02-01 09:51:23 -0800230endif # custom
231endif # optonly
232endif # full
233endif # LOCAL_PROGUARD_ENABLED
Joe Onorato2daa2b32009-08-30 13:39:24 -0700234
Ying Wang3b2bdf12010-02-01 09:51:23 -0800235$(full_classes_proguard_jar): PRIVATE_PROGUARD_ENABLED:=$(LOCAL_PROGUARD_ENABLED)
Joe Onorato2daa2b32009-08-30 13:39:24 -0700236$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(proguard_flags) $(LOCAL_PROGUARD_FLAGS)
Ying Wang3b2bdf12010-02-01 09:51:23 -0800237$(full_classes_proguard_jar): PRIVATE_INSTRUMENTATION_FOR:=$(strip $(LOCAL_INSTRUMENTATION_FOR))
238
239$(full_classes_proguard_jar): $(full_classes_full_names_jar) | $(ACP) $(PROGUARD)
240 $(call transform-jar-to-proguard)
241
242ALL_MODULES.$(LOCAL_MODULE).PROGUARD_ENABLED:=$(LOCAL_PROGUARD_ENABLED)
Joe Onorato2daa2b32009-08-30 13:39:24 -0700243
The Android Open Source Project88b60792009-03-03 19:28:42 -0800244# Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug
245# will work even when intermediates != intermediates.COMMON.
246$(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
247$(built_dex): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
248$(built_dex): $(full_classes_jar) $(DX)
249 $(transform-classes.jar-to-dex)
250ifneq ($(GENERATE_DEX_DEBUG),)
251 $(install-dex-debug)
252endif
253
254findbugs_xml := $(intermediates.COMMON)/findbugs.xml
255$(findbugs_xml) : PRIVATE_JAR_FILE := $(full_classes_jar)
256$(findbugs_xml) : PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \
257 $(call normalize-path-list,$(filter %.jar,\
258 $(full_java_libs)))))
259# We can't depend directly on full_classes_jar because the PRIVATE_
260# vars won't be set up correctly.
261$(findbugs_xml) : $(LOCAL_BUILT_MODULE)
262 @echo Findbugs: $@
263 $(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \
264 $(PRIVATE_AUXCLASSPATH) \
265 $(PRIVATE_JAR_FILE) \
266 > $@
267
268ALL_FINDBUGS_FILES += $(findbugs_xml)
269
270findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html
271$(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml)
272$(LOCAL_MODULE)-findbugs : $(findbugs_html)
273$(findbugs_html) : $(findbugs_xml)
274 @mkdir -p $(dir $@)
Andrew Stadlercef9ed92009-05-13 00:44:59 -0700275 @echo ConvertXmlToText: $@
276 $(hide) prebuilt/common/findbugs/bin/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \
The Android Open Source Project88b60792009-03-03 19:28:42 -0800277 > $@
278
279$(LOCAL_MODULE)-findbugs : $(findbugs_html)
280
281endif