1# 2# Copyright (C) 2013 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16$(call record-module-type,HOST_DALVIK_JAVA_LIBRARY) 17 18# 19# Rules for building a host dalvik java library. These libraries 20# are meant to be used by a dalvik VM instance running on the host. 21# They will be compiled against libcore and not the host JRE. 22# 23 24ifeq ($(HOST_OS),linux) 25USE_CORE_LIB_BOOTCLASSPATH := true 26 27####################################### 28include $(BUILD_SYSTEM)/host_java_library_common.mk 29####################################### 30 31full_classes_turbine_jar := $(intermediates.COMMON)/classes-turbine.jar 32full_classes_header_jarjar := $(intermediates.COMMON)/classes-header-jarjar.jar 33full_classes_header_jar := $(intermediates.COMMON)/classes-header.jar 34full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar 35full_classes_combined_jar := $(intermediates.COMMON)/classes-combined.jar 36full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar 37full_classes_jar := $(intermediates.COMMON)/classes.jar 38built_dex := $(intermediates.COMMON)/classes.dex 39java_source_list_file := $(intermediates.COMMON)/java-source-list 40 41LOCAL_INTERMEDIATE_TARGETS += \ 42 $(full_classes_turbine_jar) \ 43 $(full_classes_compiled_jar) \ 44 $(full_classes_combined_jar) \ 45 $(full_classes_jarjar_jar) \ 46 $(full_classes_jar) \ 47 $(built_dex) \ 48 $(java_source_list_file) 49 50# See comment in java.mk 51ifndef LOCAL_CHECKED_MODULE 52ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) 53LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar) 54else 55LOCAL_CHECKED_MODULE := $(built_dex) 56endif 57endif 58 59####################################### 60include $(BUILD_SYSTEM)/base_rules.mk 61####################################### 62java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) \ 63 $(filter %.java,$(LOCAL_GENERATED_SOURCES)) 64all_java_sources := $(java_sources) 65 66include $(BUILD_SYSTEM)/java_common.mk 67 68include $(BUILD_SYSTEM)/sdk_check.mk 69 70$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON) 71 72# List of dependencies for anything that needs all java sources in place 73java_sources_deps := \ 74 $(java_sources) \ 75 $(java_resource_sources) \ 76 $(proto_java_sources_file_stamp) \ 77 $(LOCAL_SRCJARS) \ 78 $(LOCAL_ADDITIONAL_DEPENDENCIES) 79 80$(java_source_list_file): $(java_sources_deps) 81 $(write-java-source-list) 82 83$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file) 84$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags) 85$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := 86$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := 87$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := 88$(full_classes_compiled_jar): PRIVATE_SRCJARS := $(LOCAL_SRCJARS) 89$(full_classes_compiled_jar): PRIVATE_SRCJAR_LIST_FILE := $(intermediates.COMMON)/srcjar-list 90$(full_classes_compiled_jar): PRIVATE_SRCJAR_INTERMEDIATES_DIR := $(intermediates.COMMON)/srcjars 91$(full_classes_compiled_jar): \ 92 $(java_source_list_file) \ 93 $(java_sources_deps) \ 94 $(full_java_header_libs) \ 95 $(full_java_bootclasspath_libs) \ 96 $(full_java_system_modules_deps) \ 97 $(annotation_processor_deps) \ 98 $(NORMALIZE_PATH) \ 99 $(JAR_ARGS) \ 100 $(ZIPSYNC) \ 101 | $(SOONG_JAVAC_WRAPPER) 102 $(transform-host-java-to-dalvik-package) 103 104ifneq ($(TURBINE_ENABLED),false) 105 106$(full_classes_turbine_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags) 107$(full_classes_turbine_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF) 108$(full_classes_turbine_jar): PRIVATE_SRCJARS := $(LOCAL_SRCJARS) 109$(full_classes_turbine_jar): \ 110 $(java_source_list_file) \ 111 $(java_sources_deps) \ 112 $(full_java_header_libs) \ 113 $(full_java_bootclasspath_libs) \ 114 $(NORMALIZE_PATH) \ 115 $(JAR_ARGS) \ 116 $(ZIPTIME) \ 117 | $(TURBINE) \ 118 $(MERGE_ZIPS) 119 $(transform-java-to-header.jar) 120 121.KATI_RESTAT: $(full_classes_turbine_jar) 122 123# Run jarjar before generate classes-header.jar if necessary. 124ifneq ($(strip $(LOCAL_JARJAR_RULES)),) 125$(full_classes_header_jarjar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) 126$(full_classes_header_jarjar): $(full_classes_turbine_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR) 127 @echo Header JarJar: $@ 128 $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@ 129else 130full_classes_header_jarjar := $(full_classes_turbine_jar) 131endif 132 133$(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar))) 134 135endif # TURBINE_ENABLED != false 136 137$(full_classes_combined_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF) 138$(full_classes_combined_jar): $(full_classes_compiled_jar) \ 139 $(jar_manifest_file) \ 140 $(full_static_java_libs) | $(MERGE_ZIPS) 141 $(if $(PRIVATE_JAR_MANIFEST), $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \ 142 $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf) 143 $(MERGE_ZIPS) -j --ignore-duplicates $(if $(PRIVATE_JAR_MANIFEST),-m $(dir $@)/manifest.mf) \ 144 $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,-stripDir META-INF -zipToNotStrip $<) \ 145 $@ $< $(call reverse-list,$(PRIVATE_STATIC_JAVA_LIBRARIES)) 146 147# Run jarjar if necessary, otherwise just copy the file. 148ifneq ($(strip $(LOCAL_JARJAR_RULES)),) 149$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) 150$(full_classes_jarjar_jar): $(full_classes_combined_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR) 151 @echo JarJar: $@ 152 $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@ 153else 154full_classes_jarjar_jar := $(full_classes_combined_jar) 155endif 156 157$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar))) 158 159ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) 160# No dex; all we want are the .class files with resources. 161$(LOCAL_BUILT_MODULE) : $(java_resource_sources) 162$(LOCAL_BUILT_MODULE) : $(full_classes_jar) 163 @echo "host Static Jar: $(PRIVATE_MODULE) ($@)" 164 $(copy-file-to-target) 165 166else # !LOCAL_IS_STATIC_JAVA_LIBRARY 167$(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON) 168$(built_dex): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) 169$(built_dex): $(full_classes_jar) $(DX) $(ZIP2ZIP) 170 $(transform-classes.jar-to-dex) 171 172$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) 173$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar) 174$(LOCAL_BUILT_MODULE): $(MERGE_ZIPS) $(SOONG_ZIP) $(ZIP2ZIP) 175$(LOCAL_BUILT_MODULE): $(built_dex) $(java_resource_sources) 176 @echo "Host Jar: $(PRIVATE_MODULE) ($@)" 177 rm -rf $@.parts 178 mkdir -p $@.parts 179 $(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE)) 180 $(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE)) 181 $(MERGE_ZIPS) -j $@ $@.parts/dex.zip $@.parts/res.zip 182 rm -rf $@.parts 183 184endif # !LOCAL_IS_STATIC_JAVA_LIBRARY 185 186$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(call module-target-sdk-version) 187$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SDK_VERSION := $(call module-sdk-version) 188$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MIN_SDK_VERSION := $(call codename-or-sdk-to-sdk,$(call module-min-sdk-version)) 189 190USE_CORE_LIB_BOOTCLASSPATH := 191 192endif 193