java.mk revision efe02ce9e00b9aebde7e9b32e81780d8de8f0dbd
1# Requires: 2# LOCAL_MODULE_SUFFIX 3# LOCAL_MODULE_CLASS 4# all_res_assets 5 6ifeq ($(TARGET_BUILD_PDK),true) 7ifeq ($(TARGET_BUILD_PDK_JAVA_PLATFORM),) 8# LOCAL_SDK not defined or set to current 9ifeq ($(filter-out current,$(LOCAL_SDK_VERSION)),) 10LOCAL_SDK_VERSION := $(PDK_BUILD_SDK_VERSION) 11endif 12endif # !PDK_JAVA 13endif #PDK 14 15 16# Make sure there's something to build. 17# It's possible to build a package that doesn't contain any classes. 18ifeq (,$(strip $(LOCAL_SRC_FILES)$(all_res_assets)$(LOCAL_STATIC_JAVA_LIBRARIES))) 19$(error $(LOCAL_PATH): Target java module does not define any source or resource files) 20endif 21 22LOCAL_NO_STANDARD_LIBRARIES:=$(strip $(LOCAL_NO_STANDARD_LIBRARIES)) 23LOCAL_SDK_VERSION:=$(strip $(LOCAL_SDK_VERSION)) 24 25ifneq ($(LOCAL_SDK_VERSION),) 26 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 27 $(error $(LOCAL_PATH): Must not define both LOCAL_NO_STANDARD_LIBRARIES and LOCAL_SDK_VERSION) 28 else 29 ifeq ($(strip $(filter $(LOCAL_SDK_VERSION),$(TARGET_AVAILABLE_SDK_VERSIONS))),) 30 $(error $(LOCAL_PATH): Invalid LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)' \ 31 Choices are: $(TARGET_AVAILABLE_SDK_VERSIONS)) 32 else 33 ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current) 34 # Use android_stubs_current if LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS. 35 LOCAL_JAVA_LIBRARIES := android_stubs_current $(LOCAL_JAVA_LIBRARIES) 36 else 37 LOCAL_JAVA_LIBRARIES := sdk_v$(LOCAL_SDK_VERSION) $(LOCAL_JAVA_LIBRARIES) 38 endif 39 endif 40 endif 41else 42 ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 43 LOCAL_JAVA_LIBRARIES := core core-junit ext framework $(LOCAL_JAVA_LIBRARIES) 44 endif 45endif 46 47proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES)) 48ifneq ($(proto_sources),) 49ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro) 50 LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-2.3.0-micro 51else 52 LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-2.3.0-lite 53endif 54endif 55 56LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES)) 57 58LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM)) 59ifeq ($(LOCAL_BUILT_MODULE_STEM),) 60$(error $(LOCAL_PATH): Target java template must define LOCAL_BUILT_MODULE_STEM) 61endif 62ifneq ($(filter classes-compiled.jar classes.jar,$(LOCAL_BUILT_MODULE_STEM)),) 63$(error LOCAL_BUILT_MODULE_STEM may not be "$(LOCAL_BUILT_MODULE_STEM)") 64endif 65 66 67############################################################################## 68# Define the intermediate targets before including base_rules so they get 69# the correct environment. 70############################################################################## 71 72intermediates := $(call local-intermediates-dir) 73intermediates.COMMON := $(call local-intermediates-dir,COMMON) 74 75# Emma source code coverage 76ifneq ($(EMMA_INSTRUMENT),true) 77LOCAL_NO_EMMA_INSTRUMENT := true 78LOCAL_NO_EMMA_COMPILE := true 79endif 80 81# Choose leaf name for the compiled jar file. 82ifneq ($(LOCAL_NO_EMMA_COMPILE),true) 83full_classes_compiled_jar_leaf := classes-no-debug-var.jar 84built_dex_intermediate_leaf := classes-no-local.dex 85else 86full_classes_compiled_jar_leaf := classes-full-debug.jar 87built_dex_intermediate_leaf := classes-with-local.dex 88endif 89 90LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED)) 91ifeq ($(LOCAL_PROGUARD_ENABLED),disabled) 92LOCAL_PROGUARD_ENABLED := 93endif 94 95# By giving different file name, files can be updated correctly when switching 96# between builds with and without Proguard enabled. 97# Note that ANY intermediate targets between the proguard and 98# the final built_dex should be differently named! 99ifdef LOCAL_PROGUARD_ENABLED 100proguard_jar_leaf := proguard.classes.jar 101built_dex_intermediate_leaf := proguard.$(built_dex_intermediate_leaf) 102built_dex_leaf := proguard.classes.dex 103else 104proguard_jar_leaf := noproguard.classes.jar 105built_dex_intermediate_leaf := noproguard.$(built_dex_intermediate_leaf) 106built_dex_leaf := noproguard.classes.dex 107endif 108 109full_classes_compiled_jar := $(intermediates.COMMON)/$(full_classes_compiled_jar_leaf) 110jarjar_leaf := classes-jarjar.jar 111full_classes_jarjar_jar := $(intermediates.COMMON)/$(jarjar_leaf) 112emma_intermediates_dir := $(intermediates.COMMON)/emma_out 113# emma is hardcoded to use the leaf name of its input for the output file -- 114# only the output directory can be changed 115full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(jarjar_leaf) 116full_classes_proguard_jar := $(intermediates.COMMON)/$(proguard_jar_leaf) 117built_dex_intermediate := $(intermediates.COMMON)/$(built_dex_intermediate_leaf) 118full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar 119 120# full_classes_jar and built_dex are cleared below, and re-set if we really need them. 121full_classes_jar := $(intermediates.COMMON)/classes.jar 122built_dex := $(intermediates.COMMON)/$(built_dex_leaf) 123 124LOCAL_INTERMEDIATE_TARGETS += \ 125 $(full_classes_compiled_jar) \ 126 $(full_classes_jarjar_jar) \ 127 $(full_classes_emma_jar) \ 128 $(full_classes_jar) \ 129 $(full_classes_proguard_jar) \ 130 $(built_dex_intermediate) \ 131 $(built_dex) \ 132 $(full_classes_stubs_jar) 133 134 135LOCAL_INTERMEDIATE_SOURCE_DIR := $(intermediates.COMMON)/src 136 137############################################################### 138## .rs files: RenderScript sources to .java files and .bc files 139############################################################### 140renderscript_sources := $(filter %.rs,$(LOCAL_SRC_FILES)) 141# Because names of the java files from RenderScript are unknown until the 142# .rs file(s) are compiled, we have to depend on a timestamp file. 143RenderScript_file_stamp := 144ifneq ($(renderscript_sources),) 145renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources)) 146RenderScript_file_stamp := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/RenderScript.stamp 147renderscript_intermediate := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/renderscript 148 149renderscript_target_api := 150 151ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API)) 152renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API) 153else 154ifneq (,$(LOCAL_SDK_VERSION)) 155# Set target-api for LOCAL_SDK_VERSIONs other than current. 156ifneq (,$(filter-out current, $(LOCAL_SDK_VERSION))) 157renderscript_target_api := $(LOCAL_SDK_VERSION) 158endif 159endif # LOCAL_SDK_VERSION is set 160endif # LOCAL_RENDERSCRIPT_TARGET_API is set 161 162ifeq ($(LOCAL_RENDERSCRIPT_CC),) 163LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC) 164endif 165 166# Turn on all warnings and warnings as errors for RS compiles. 167# This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error 168renderscript_flags := -Wall -Werror 169renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS) 170 171# prepend the RenderScript system include path 172ifneq ($(filter-out current,$(LOCAL_SDK_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current,$(LOCAL_SDK_VERSION))),) 173# if a numeric LOCAL_SDK_VERSION, or current LOCAL_SDK_VERSION with TARGET_BUILD_APPS 174LOCAL_RENDERSCRIPT_INCLUDES := \ 175 $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/clang-include \ 176 $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/include \ 177 $(LOCAL_RENDERSCRIPT_INCLUDES) 178else 179LOCAL_RENDERSCRIPT_INCLUDES := \ 180 $(TOPDIR)external/clang/lib/Headers \ 181 $(TOPDIR)frameworks/rs/scriptc \ 182 $(LOCAL_RENDERSCRIPT_INCLUDES) 183endif 184 185ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),) 186LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE) 187endif 188 189$(RenderScript_file_stamp): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES) 190$(RenderScript_file_stamp): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC) 191$(RenderScript_file_stamp): PRIVATE_RS_FLAGS := $(renderscript_flags) 192$(RenderScript_file_stamp): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath) 193# By putting the generated java files into $(LOCAL_INTERMEDIATE_SOURCE_DIR), they will be 194# automatically found by the java compiling function transform-java-to-classes.jar. 195$(RenderScript_file_stamp): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate) 196$(RenderScript_file_stamp): PRIVATE_RS_TARGET_API := $(renderscript_target_api) 197$(RenderScript_file_stamp): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC) 198 $(transform-renderscripts-to-java-and-bc) 199 200# include the dependency files (.d) generated by llvm-rs-cc. 201renderscript_generated_dep_files := $(addprefix $(renderscript_intermediate)/, \ 202 $(patsubst %.rs,%.d, $(notdir $(renderscript_sources)))) 203-include $(renderscript_generated_dep_files) 204 205LOCAL_INTERMEDIATE_TARGETS += $(RenderScript_file_stamp) 206# Make sure the generated resource will be added to the apk. 207LOCAL_RESOURCE_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/renderscript/res $(LOCAL_RESOURCE_DIR) 208endif 209 210# TODO: It looks like the only thing we need from base_rules is 211# all_java_sources. See if we can get that by adding a 212# common_java.mk, and moving the include of base_rules.mk to 213# after all the declarations. 214 215####################################### 216include $(BUILD_SYSTEM)/base_rules.mk 217####################################### 218 219# We use intermediates.COMMON because the classes.jar/.dex files will be 220# common even if LOCAL_BUILT_MODULE isn't. 221# 222# Override some target variables that base_rules set up for us. 223$(LOCAL_INTERMEDIATE_TARGETS): \ 224 PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes 225$(LOCAL_INTERMEDIATE_TARGETS): \ 226 PRIVATE_SOURCE_INTERMEDIATES_DIR := $(LOCAL_INTERMEDIATE_SOURCE_DIR) 227 228# Since we're using intermediates.COMMON, make sure that it gets cleaned 229# properly. 230$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON) 231 232# If the module includes java code (i.e., it's not framework-res), compile it. 233full_classes_jar := 234built_dex := 235ifneq (,$(strip $(all_java_sources)$(full_static_java_libs))) 236 237# If LOCAL_BUILT_MODULE_STEM wasn't overridden by our caller, 238# full_classes_jar will be the same module as LOCAL_BUILT_MODULE. 239# Otherwise, the caller will define it as a prerequisite of 240# LOCAL_BUILT_MODULE, so it will inherit the necessary PRIVATE_* 241# variable definitions. 242full_classes_jar := $(intermediates.COMMON)/classes.jar 243built_dex := $(intermediates.COMMON)/$(built_dex_leaf) 244 245# Droiddoc isn't currently able to generate stubs for modules, so we're just 246# allowing it to use the classes.jar as the "stubs" that would be use to link 247# against, for the cases where someone needs the jar to link against. 248# - Use the classes.jar instead of the handful of other intermediates that 249# we have, because it's the most processed, but still hasn't had dex run on 250# it, so it's closest to what's on the device. 251# - This extra copy, with the dependency on LOCAL_BUILT_MODULE allows the 252# PRIVATE_ vars to be preserved. 253$(full_classes_stubs_jar): PRIVATE_SOURCE_FILE := $(full_classes_jar) 254$(full_classes_stubs_jar) : $(LOCAL_BUILT_MODULE) | $(ACP) 255 @echo Copying $(PRIVATE_SOURCE_FILE) 256 $(hide) $(ACP) -fp $(PRIVATE_SOURCE_FILE) $@ 257ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar) 258 259# Compile the java files to a .jar file. 260# This intentionally depends on java_sources, not all_java_sources. 261# Deps for generated source files must be handled separately, 262# via deps on the target that generates the sources. 263$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) 264$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := $(LOCAL_JAR_EXCLUDE_FILES) 265$(full_classes_compiled_jar): $(java_sources) $(java_resource_sources) $(full_java_lib_deps) $(jar_manifest_file) \ 266 $(RenderScript_file_stamp) $(proto_java_sources_file_stamp) 267 $(transform-java-to-classes.jar) 268 269# All of the rules after full_classes_compiled_jar are very unlikely 270# to fail except for bugs in their respective tools. If you would 271# like to run these rules, add the "all" modifier goal to the make 272# command line. 273# This overwrites the value defined in base_rules.mk. That's a little 274# dirty. It's preferable to set LOCAL_CHECKED_MODULE, but this has to 275# be done after the inclusion of base_rules.mk. 276ALL_MODULES.$(LOCAL_MODULE).CHECKED := $(full_classes_compiled_jar) 277 278$(full_classes_compiled_jar): PRIVATE_JAVAC_DEBUG_FLAGS := -g 279 280# Run jarjar if necessary, otherwise just copy the file. 281ifneq ($(strip $(LOCAL_JARJAR_RULES)),) 282$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) 283$(full_classes_jarjar_jar): $(full_classes_compiled_jar) | $(JARJAR) 284 @echo JarJar: $@ 285 $(hide) java -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@ 286else 287$(full_classes_jarjar_jar): $(full_classes_compiled_jar) | $(ACP) 288 @echo Copying: $@ 289 $(hide) $(ACP) -fp $< $@ 290endif 291 292ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) 293# Skip adding emma instrumentation to class files if this is a static library, 294# since it will be instrumented by the package that includes it 295LOCAL_NO_EMMA_INSTRUMENT:= true 296endif 297 298ifneq ($(LOCAL_NO_EMMA_INSTRUMENT),true) 299$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILE := $(intermediates.COMMON)/coverage.em 300$(full_classes_emma_jar): PRIVATE_EMMA_INTERMEDIATES_DIR := $(emma_intermediates_dir) 301# module level coverage filter can be defined using LOCAL_EMMA_COVERAGE_FILTER 302# in Android.mk 303ifdef LOCAL_EMMA_COVERAGE_FILTER 304$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := $(LOCAL_EMMA_COVERAGE_FILTER) 305else 306# by default, avoid applying emma instrumentation onto emma classes itself, 307# otherwise there will be exceptions thrown 308$(full_classes_emma_jar): PRIVATE_EMMA_COVERAGE_FILTER := *,-emma,-emmarun,-com.vladium.* 309endif 310# this rule will generate both $(PRIVATE_EMMA_COVERAGE_FILE) and 311# $(full_classes_emma_jar) 312$(full_classes_emma_jar): $(full_classes_jarjar_jar) | $(EMMA_JAR) 313 $(transform-classes.jar-to-emma) 314$(PRIVATE_EMMA_COVERAGE_FILE): $(full_classes_emma_jar) 315 316# tell proguard to load emma jar 317LOCAL_PROGUARD_FLAGS := $(LOCAL_PROGUARD_FLAGS) $(addprefix -libraryjars ,$(EMMA_JAR)) 318else 319$(full_classes_emma_jar): $(full_classes_jarjar_jar) | $(ACP) 320 @echo Copying: $@ 321 $(copy-file-to-target) 322endif 323 324# Keep a copy of the jar just before proguard processing. 325$(full_classes_jar): $(full_classes_emma_jar) | $(ACP) 326 @echo Copying: $@ 327 $(hide) $(ACP) -fp $< $@ 328 329# Run proguard if necessary, otherwise just copy the file. 330proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary 331# Proguard doesn't like a class in both library and the jar to be processed. 332proguard_full_java_libs := $(filter-out $(full_static_java_libs),$(full_java_libs)) 333proguard_flags := $(addprefix -libraryjars ,$(proguard_full_java_libs)) \ 334 -include $(BUILD_SYSTEM)/proguard.flags \ 335 -forceprocessing \ 336 -printmapping $(proguard_dictionary) 337# If this is a test package, add proguard keep flags for tests. 338ifneq ($(strip $(LOCAL_INSTRUMENTATION_FOR)$(filter tests,$(LOCAL_MODULE_TAGS))$(filter android.test.runner,$(LOCAL_JAVA_LIBRARIES))),) 339proguard_flags := $(proguard_flags) -include $(BUILD_SYSTEM)/proguard_tests.flags 340endif # test package 341 342ifneq ($(LOCAL_PROGUARD_ENABLED),) 343ifeq ($(LOCAL_PROGUARD_ENABLED),full) 344 # full 345else 346ifeq ($(LOCAL_PROGUARD_ENABLED),optonly) 347 # optonly 348 proguard_flags += -dontobfuscate 349else 350ifeq ($(LOCAL_PROGUARD_ENABLED),custom) 351 # custom 352else 353 $(warning while processing: $(LOCAL_MODULE)) 354 $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED)) 355endif # custom 356endif # optonly 357endif # full 358endif # LOCAL_PROGUARD_ENABLED 359 360proguard_flag_files := $(addprefix $(LOCAL_PATH)/, $(LOCAL_PROGUARD_FLAG_FILES)) 361LOCAL_PROGUARD_FLAGS += $(addprefix -include , $(proguard_flag_files)) 362 363$(full_classes_proguard_jar): PRIVATE_PROGUARD_ENABLED:=$(LOCAL_PROGUARD_ENABLED) 364$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(proguard_flags) $(LOCAL_PROGUARD_FLAGS) 365$(full_classes_proguard_jar): PRIVATE_INSTRUMENTATION_FOR:=$(strip $(LOCAL_INSTRUMENTATION_FOR)) 366$(full_classes_proguard_jar) : $(full_classes_jar) $(proguard_flag_files) | $(ACP) $(PROGUARD) 367 $(call transform-jar-to-proguard) 368 369ALL_MODULES.$(LOCAL_MODULE).PROGUARD_ENABLED:=$(LOCAL_PROGUARD_ENABLED) 370 371# Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug 372# will work even when intermediates != intermediates.COMMON. 373$(built_dex_intermediate): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON) 374$(built_dex_intermediate): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) 375# If you instrument class files that have local variable debug information in 376# them emma does not correctly maintain the local variable table. 377# This will cause an error when you try to convert the class files for Android. 378# The workaround here is to build different dex file here based on emma switch 379# then later copy into classes.dex. When emma is on, dx is run with --no-locals 380# option to remove local variable information 381ifneq ($(LOCAL_NO_EMMA_COMPILE),true) 382$(built_dex_intermediate): PRIVATE_DX_FLAGS += --no-locals 383endif 384$(built_dex_intermediate): $(full_classes_proguard_jar) $(DX) 385 $(transform-classes.jar-to-dex) 386$(built_dex): $(built_dex_intermediate) | $(ACP) 387 @echo Copying: $@ 388 $(hide) $(ACP) -fp $< $@ 389ifneq ($(GENERATE_DEX_DEBUG),) 390 $(install-dex-debug) 391endif 392 393findbugs_xml := $(intermediates.COMMON)/findbugs.xml 394$(findbugs_xml) : PRIVATE_JAR_FILE := $(full_classes_jar) 395$(findbugs_xml) : PRIVATE_AUXCLASSPATH := $(addprefix -auxclasspath ,$(strip \ 396 $(call normalize-path-list,$(filter %.jar,\ 397 $(full_java_libs))))) 398# We can't depend directly on full_classes_jar because the PRIVATE_ 399# vars won't be set up correctly. 400$(findbugs_xml) : $(LOCAL_BUILT_MODULE) 401 @echo Findbugs: $@ 402 $(hide) $(FINDBUGS) -textui -effort:min -xml:withMessages \ 403 $(PRIVATE_AUXCLASSPATH) \ 404 $(PRIVATE_JAR_FILE) \ 405 > $@ 406 407ALL_FINDBUGS_FILES += $(findbugs_xml) 408 409findbugs_html := $(PRODUCT_OUT)/findbugs/$(LOCAL_MODULE).html 410$(findbugs_html) : PRIVATE_XML_FILE := $(findbugs_xml) 411$(LOCAL_MODULE)-findbugs : $(findbugs_html) 412$(findbugs_html) : $(findbugs_xml) 413 @mkdir -p $(dir $@) 414 @echo ConvertXmlToText: $@ 415 $(hide) prebuilt/common/findbugs/bin/convertXmlToText -html:fancy.xsl $(PRIVATE_XML_FILE) \ 416 > $@ 417 418$(LOCAL_MODULE)-findbugs : $(findbugs_html) 419 420endif 421