The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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 | include $(BUILD_SYSTEM)/base_rules.mk |
| 42 | ####################################### |
| 43 | |
| 44 | # We use intermediates.COMMON because the classes.jar/.dex files will be |
| 45 | # common even if LOCAL_BUILT_MODULE isn't. |
| 46 | # |
| 47 | # Override some target variables that base_rules set up for us. |
| 48 | $(LOCAL_INTERMEDIATE_TARGETS): \ |
| 49 | PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes |
| 50 | $(LOCAL_INTERMEDIATE_TARGETS): \ |
| 51 | PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/src |
| 52 | |
| 53 | # Since we're using intermediates.COMMON, make sure that it gets cleaned |
| 54 | # properly. |
| 55 | $(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON) |
| 56 | |
| 57 | # If the module includes java code (i.e., it's not framework-res), compile it. |
| 58 | full_classes_jar := |
| 59 | built_dex := |
| 60 | ifneq (,$(strip $(all_java_sources))) |
| 61 | |
| 62 | # If LOCAL_BUILT_MODULE_STEM wasn't overridden by our caller, |
| 63 | # full_classes_jar will be the same module as LOCAL_BUILT_MODULE. |
| 64 | # Otherwise, the caller will define it as a prerequisite of |
| 65 | # LOCAL_BUILT_MODULE, so it will inherit the necessary PRIVATE_* |
| 66 | # variable definitions. |
| 67 | full_classes_jar := $(intermediates.COMMON)/classes.jar |
| 68 | |
| 69 | # Emma source code coverage |
| 70 | ifneq ($(EMMA_INSTRUMENT),true) |
| 71 | LOCAL_NO_EMMA_INSTRUMENT := true |
| 72 | LOCAL_NO_EMMA_COMPILE := true |
| 73 | endif |
| 74 | |
Joe Onorato | bd46b21 | 2009-03-24 19:07:34 -0700 | [diff] [blame] | 75 | # Choose leaf name for the compiled jar file. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 76 | ifneq ($(LOCAL_NO_EMMA_COMPILE),true) |
Joe Onorato | bd46b21 | 2009-03-24 19:07:34 -0700 | [diff] [blame] | 77 | full_classes_compiled_jar_leaf := classes-no-debug-var.jar |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 78 | else |
Joe Onorato | bd46b21 | 2009-03-24 19:07:34 -0700 | [diff] [blame] | 79 | full_classes_compiled_jar_leaf := classes-full-debug.jar |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 80 | endif |
| 81 | |
| 82 | # Compile the java files to a .jar file. |
| 83 | # This intentionally depends on java_sources, not all_java_sources. |
| 84 | # Deps for generated source files must be handled separately, |
| 85 | # via deps on the target that generates the sources. |
Joe Onorato | bd46b21 | 2009-03-24 19:07:34 -0700 | [diff] [blame] | 86 | full_classes_compiled_jar := $(intermediates.COMMON)/$(full_classes_compiled_jar_leaf) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 87 | $(full_classes_compiled_jar): $(java_sources) $(full_java_lib_deps) |
| 88 | $(transform-java-to-classes.jar) |
| 89 | |
Joe Onorato | bd46b21 | 2009-03-24 19:07:34 -0700 | [diff] [blame] | 90 | ifneq ($(LOCAL_NO_EMMA_COMPILE),true) |
| 91 | # If you instrument class files that have local variable debug information in |
| 92 | # them emma does not correctly maintain the local variable table. |
| 93 | # This will cause an error when you try to convert the class files for Android. |
| 94 | # The workaround for this to compile the java classes with only |
| 95 | # line and source debug information, not local information. |
| 96 | $(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g:{lines,source} |
| 97 | else |
| 98 | # when emma is off, compile with the default flags, which contain full debug |
| 99 | # info |
| 100 | $(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g |
| 101 | endif |
| 102 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 103 | emma_intermediates_dir := $(intermediates.COMMON)/emma_out |
Joe Onorato | bd46b21 | 2009-03-24 19:07:34 -0700 | [diff] [blame] | 104 | # the 'lib/$(full_classes_compiled_jar_leaf)' portion of this path is fixed in |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 105 | # the emma tool |
Joe Onorato | bd46b21 | 2009-03-24 19:07:34 -0700 | [diff] [blame] | 106 | full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(full_classes_compiled_jar_leaf) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 107 | |
| 108 | ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) |
| 109 | # Skip adding emma instrumentation to class files if this is a static library, |
| 110 | # since it will be instrumented by the package that includes it |
| 111 | LOCAL_NO_EMMA_INSTRUMENT:= true |
| 112 | endif |
| 113 | |
| 114 | ifneq ($(LOCAL_NO_EMMA_INSTRUMENT),true) |
| 115 | $(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.em |
| 116 | $(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir) |
| 117 | # this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and |
| 118 | # $(full_classes_emma_jar) |
| 119 | $(full_classes_emma_jar): $(full_classes_compiled_jar) |
| 120 | $(transform-classes.jar-to-emma) |
| 121 | $(PRIVATE_EMMA_COVERAGE_FILE): $(full_classes_emma_jar) |
| 122 | else |
| 123 | $(full_classes_emma_jar): $(full_classes_compiled_jar) | $(ACP) |
| 124 | @echo Copying $< |
| 125 | $(copy-file-to-target) |
| 126 | endif |
| 127 | |
| 128 | # Run jarjar if necessary, otherwise just copy the file. This is the last |
| 129 | # part of this step, so the output of this command is full_classes_jar. |
| 130 | full_classes_jarjar_jar := $(full_classes_jar) |
| 131 | ifneq ($(strip $(LOCAL_JARJAR_RULES)),) |
| 132 | $(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) |
| 133 | $(full_classes_jarjar_jar): $(full_classes_emma_jar) | jarjar |
| 134 | @echo JarJar: $@ |
| 135 | $(hide) $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@ |
| 136 | else |
| 137 | $(full_classes_jarjar_jar): $(full_classes_emma_jar) | $(ACP) |
| 138 | @echo Copying: $@ |
| 139 | $(hide) $(ACP) $< $@ |
| 140 | endif |
| 141 | |
| 142 | |
| 143 | built_dex := $(intermediates.COMMON)/classes.dex |
| 144 | |
| 145 | # Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug |
| 146 | # will work even when intermediates != intermediates.COMMON. |
| 147 | $(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON) |
| 148 | $(built_dex): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) |
| 149 | $(built_dex): $(full_classes_jar) $(DX) |
| 150 | $(transform-classes.jar-to-dex) |
| 151 | ifneq ($(GENERATE_DEX_DEBUG),) |
| 152 | $(install-dex-debug) |
| 153 | endif |
| 154 | |
| 155 | findbugs_xml := $(intermediates.COMMON)/findbugs.xml |
| 156 | $(findbugs_xml) : PRIVATE_JAR_FILE := $(full_classes_jar) |
| 157 | $(findbugs_xml) : PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \ |
| 158 | $(call normalize-path-list,$(filter %.jar,\ |
| 159 | $(full_java_libs))))) |
| 160 | # We can't depend directly on full_classes_jar because the PRIVATE_ |
| 161 | # vars won't be set up correctly. |
| 162 | $(findbugs_xml) : $(LOCAL_BUILT_MODULE) |
| 163 | @echo Findbugs: $@ |
| 164 | $(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \ |
| 165 | $(PRIVATE_AUXCLASSPATH) \ |
| 166 | $(PRIVATE_JAR_FILE) \ |
| 167 | > $@ |
| 168 | |
| 169 | ALL_FINDBUGS_FILES += $(findbugs_xml) |
| 170 | |
| 171 | findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html |
| 172 | $(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml) |
| 173 | $(LOCAL_MODULE)-findbugs : $(findbugs_html) |
| 174 | $(findbugs_html) : $(findbugs_xml) |
| 175 | @mkdir -p $(dir $@) |
| 176 | @echo UnionBugs: $@ |
| 177 | $(hide) prebuilt/common/findbugs/bin/unionBugs $(PRIVATE_XML_FILE) \ |
| 178 | | prebuilt/common/findbugs/bin/convertXmlToText -html:fancy.xsl \ |
| 179 | > $@ |
| 180 | |
| 181 | $(LOCAL_MODULE)-findbugs : $(findbugs_html) |
| 182 | |
| 183 | endif |