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)/configure_local_jack.mk 29################################# 30 31####################################### 32include $(BUILD_SYSTEM)/host_java_library_common.mk 33####################################### 34ifdef LOCAL_JACK_ENABLED 35ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) 36 # For static library, $(LOCAL_BUILT_MODULE) is $(full_classes_jack). 37 LOCAL_BUILT_MODULE_STEM := classes.jack 38endif 39endif 40 41ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true) 42 LOCAL_JAVA_LIBRARIES := core-oj-hostdex core-libart-hostdex $(LOCAL_JAVA_LIBRARIES) 43endif 44 45full_classes_compiled_jar := $(intermediates.COMMON)/classes-full-debug.jar 46full_classes_desugar_jar := $(intermediates.COMMON)/desugar.classes.jar 47full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar 48full_classes_jar := $(intermediates.COMMON)/classes.jar 49full_classes_jack := $(intermediates.COMMON)/classes.jack 50jack_check_timestamp := $(intermediates.COMMON)/jack.check.timestamp 51built_dex := $(intermediates.COMMON)/classes.dex 52 53LOCAL_INTERMEDIATE_TARGETS += \ 54 $(full_classes_compiled_jar) \ 55 $(full_classes_desugar_jar) \ 56 $(full_classes_jarjar_jar) \ 57 $(full_classes_jack) \ 58 $(full_classes_jar) \ 59 $(jack_check_timestamp) \ 60 $(built_dex) 61 62# See comment in java.mk 63ifndef LOCAL_CHECKED_MODULE 64ifdef LOCAL_JACK_ENABLED 65LOCAL_CHECKED_MODULE := $(jack_check_timestamp) 66else 67ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) 68LOCAL_CHECKED_MODULE := $(full_classes_compiled_jar) 69else 70LOCAL_CHECKED_MODULE := $(built_dex) 71endif 72endif 73endif 74 75####################################### 76include $(BUILD_SYSTEM)/base_rules.mk 77####################################### 78java_sources := $(addprefix $(LOCAL_PATH)/, $(filter %.java,$(LOCAL_SRC_FILES))) \ 79 $(filter %.java,$(LOCAL_GENERATED_SOURCES)) 80all_java_sources := $(java_sources) 81 82include $(BUILD_SYSTEM)/java_common.mk 83 84$(cleantarget): PRIVATE_CLEAN_FILES += $(intermediates.COMMON) 85 86ifndef LOCAL_JACK_ENABLED 87 88$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file) 89$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JAVACFLAGS) $(annotation_processor_flags) 90$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES := 91$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES := 92$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES := 93$(full_classes_compiled_jar): \ 94 $(java_sources) \ 95 $(java_resource_sources) \ 96 $(full_java_lib_deps) \ 97 $(jar_manifest_file) \ 98 $(proto_java_sources_file_stamp) \ 99 $(annotation_processor_deps) \ 100 $(NORMALIZE_PATH) \ 101 $(LOCAL_ADDITIONAL_DEPENDENCIES) \ 102 | $(SOONG_JAVAC_WRAPPER) 103 $(transform-host-java-to-package) 104 105my_desugaring := 106ifeq ($(LOCAL_JAVA_LANGUAGE_VERSION),1.8) 107my_desugaring := true 108$(full_classes_desugar_jar): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) 109$(full_classes_desugar_jar): $(full_classes_compiled_jar) $(DESUGAR) 110 $(desugar-classes-jar) 111endif 112 113ifndef my_desugaring 114full_classes_desugar_jar := $(full_classes_compiled_jar) 115endif 116 117# Run jarjar if necessary, otherwise just copy the file. 118ifneq ($(strip $(LOCAL_JARJAR_RULES)),) 119$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES) 120$(full_classes_jarjar_jar): $(full_classes_desugar_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR) 121 @echo JarJar: $@ 122 $(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@ 123else 124full_classes_jarjar_jar := $(full_classes_desugar_jar) 125endif 126 127$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar))) 128 129ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) 130# No dex; all we want are the .class files with resources. 131$(LOCAL_BUILT_MODULE) : $(java_resource_sources) 132$(LOCAL_BUILT_MODULE) : $(full_classes_jar) 133 @echo "host Static Jar: $(PRIVATE_MODULE) ($@)" 134 $(copy-file-to-target) 135 136else # !LOCAL_IS_STATIC_JAVA_LIBRARY 137$(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON) 138$(built_dex): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS) 139$(built_dex): $(full_classes_jar) $(DX) 140 $(transform-classes.jar-to-dex) 141 142$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) 143$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar) 144$(LOCAL_BUILT_MODULE): PRIVATE_DONT_DELETE_JAR_DIRS := $(LOCAL_DONT_DELETE_JAR_DIRS) 145$(LOCAL_BUILT_MODULE): $(built_dex) $(java_resource_sources) 146 @echo "Host Jar: $(PRIVATE_MODULE) ($@)" 147 $(call initialize-package-file,$(PRIVATE_SOURCE_ARCHIVE),$@) 148 $(add-dex-to-package) 149 150endif # !LOCAL_IS_STATIC_JAVA_LIBRARY 151 152ifneq (,$(filter-out current system_current test_current, $(LOCAL_SDK_VERSION))) 153$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(LOCAL_SDK_VERSION) 154$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SDK_VERSION := $(LOCAL_SDK_VERSION) 155else 156$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(DEFAULT_APP_TARGET_SDK) 157$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SDK_VERSION := $(PLATFORM_SDK_VERSION) 158endif 159 160else # LOCAL_JACK_ENABLED 161$(LOCAL_INTERMEDIATE_TARGETS): \ 162 PRIVATE_JACK_INTERMEDIATES_DIR := $(intermediates.COMMON)/jack-rsc 163 164ifeq ($(LOCAL_JACK_ENABLED),incremental) 165$(LOCAL_INTERMEDIATE_TARGETS): \ 166 PRIVATE_JACK_INCREMENTAL_DIR := $(intermediates.COMMON)/jack-incremental 167else 168$(LOCAL_INTERMEDIATE_TARGETS): \ 169 PRIVATE_JACK_INCREMENTAL_DIR := 170endif 171$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_FLAGS := $(GLOBAL_JAVAC_DEBUG_FLAGS) $(LOCAL_JACK_FLAGS) 172$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_VERSION := $(LOCAL_JACK_VERSION) 173$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JACK_MIN_SDK_VERSION := $(PLATFORM_JACK_MIN_SDK_VERSION) 174 175jack_all_deps := $(java_sources) $(java_resource_sources) $(full_jack_deps) \ 176 $(jar_manifest_file) $(proto_java_sources_file_stamp) \ 177 $(LOCAL_ADDITIONAL_DEPENDENCIES) $(NORMALIZE_PATH) $(JACK_DEFAULT_ARGS) $(JACK) 178 179ifneq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) 180$(built_dex): PRIVATE_CLASSES_JACK := $(full_classes_jack) 181$(built_dex): PRIVATE_JACK_PLUGIN_PATH := $(LOCAL_JACK_PLUGIN_PATH) 182$(built_dex): PRIVATE_JACK_PLUGIN := $(LOCAL_JACK_PLUGIN) 183$(built_dex): $(jack_all_deps) $(LOCAL_JACK_PLUGIN_PATH) | setup-jack-server 184 @echo Building with Jack: $@ 185 $(jack-java-to-dex) 186 187# $(full_classes_jack) is just by-product of $(built_dex). 188# The dummy command was added because, without it, make misses the fact the $(built_dex) also 189# change $(full_classes_jack). 190$(full_classes_jack): $(built_dex) 191 $(hide) touch $@ 192 193$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex) 194$(LOCAL_BUILT_MODULE): $(built_dex) $(java_resource_sources) 195 @echo "Host Jar: $(PRIVATE_MODULE) ($@)" 196 $(create-empty-package) 197 $(add-dex-to-package) 198 $(add-carried-jack-resources) 199 200else # LOCAL_IS_STATIC_JAVA_LIBRARY 201$(full_classes_jack): PRIVATE_JACK_PLUGIN_PATH := $(LOCAL_JACK_PLUGIN_PATH) 202$(full_classes_jack): PRIVATE_JACK_PLUGIN := $(LOCAL_JACK_PLUGIN) 203$(full_classes_jack): $(jack_all_deps) $(LOCAL_JACK_PLUGIN_PATH) | setup-jack-server 204 @echo Building with Jack: $@ 205 $(java-to-jack) 206 207endif # LOCAL_IS_STATIC_JAVA_LIBRARY 208 209$(jack_check_timestamp): $(jack_all_deps) | setup-jack-server 210 @echo Checking build with Jack: $@ 211 $(jack-check-java) 212endif # LOCAL_JACK_ENABLED 213 214USE_CORE_LIB_BOOTCLASSPATH := 215 216endif 217