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    $(LOCAL_SRCJARS) \
77    $(LOCAL_ADDITIONAL_DEPENDENCIES)
78
79$(java_source_list_file): $(java_sources_deps)
80	$(write-java-source-list)
81
82# TODO(b/143658984): goma can't handle the --system argument to javac.
83#$(full_classes_compiled_jar): .KATI_NINJA_POOL := $(GOMA_POOL)
84$(full_classes_compiled_jar): PRIVATE_JAVA_LAYERS_FILE := $(layers_file)
85$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
86$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_FILES :=
87$(full_classes_compiled_jar): PRIVATE_JAR_PACKAGES :=
88$(full_classes_compiled_jar): PRIVATE_JAR_EXCLUDE_PACKAGES :=
89$(full_classes_compiled_jar): PRIVATE_SRCJARS := $(LOCAL_SRCJARS)
90$(full_classes_compiled_jar): PRIVATE_SRCJAR_LIST_FILE := $(intermediates.COMMON)/srcjar-list
91$(full_classes_compiled_jar): PRIVATE_SRCJAR_INTERMEDIATES_DIR := $(intermediates.COMMON)/srcjars
92$(full_classes_compiled_jar): \
93    $(java_source_list_file) \
94    $(java_sources_deps) \
95    $(full_java_header_libs) \
96    $(full_java_bootclasspath_libs) \
97    $(full_java_system_modules_deps) \
98    $(annotation_processor_deps) \
99    $(NORMALIZE_PATH) \
100    $(JAR_ARGS) \
101    $(ZIPSYNC) \
102    $(SOONG_ZIP) \
103    | $(SOONG_JAVAC_WRAPPER)
104	$(transform-host-java-to-dalvik-package)
105
106ifneq ($(TURBINE_ENABLED),false)
107
108$(full_classes_turbine_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS) $(annotation_processor_flags)
109$(full_classes_turbine_jar): PRIVATE_SRCJARS := $(LOCAL_SRCJARS)
110$(full_classes_turbine_jar): \
111    $(java_source_list_file) \
112    $(java_sources_deps) \
113    $(full_java_header_libs) \
114    $(full_java_bootclasspath_libs) \
115    $(NORMALIZE_PATH) \
116    $(JAR_ARGS) \
117    $(ZIPTIME) \
118    | $(TURBINE) \
119    $(MERGE_ZIPS)
120	$(transform-java-to-header.jar)
121
122.KATI_RESTAT: $(full_classes_turbine_jar)
123
124# Run jarjar before generate classes-header.jar if necessary.
125ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
126$(full_classes_header_jarjar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
127$(full_classes_header_jarjar): $(full_classes_turbine_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
128	@echo Header JarJar: $@
129	$(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
130else
131full_classes_header_jarjar := $(full_classes_turbine_jar)
132endif
133
134$(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar)))
135
136endif # TURBINE_ENABLED != false
137
138$(full_classes_combined_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
139$(full_classes_combined_jar): $(full_classes_compiled_jar) \
140                              $(jar_manifest_file) \
141                              $(full_static_java_libs)  | $(MERGE_ZIPS)
142	$(if $(PRIVATE_JAR_MANIFEST), $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
143            $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf)
144	$(MERGE_ZIPS) -j --ignore-duplicates $(if $(PRIVATE_JAR_MANIFEST),-m $(dir $@)/manifest.mf) \
145            $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,-stripDir META-INF -zipToNotStrip $<) \
146            $@ $< $(PRIVATE_STATIC_JAVA_LIBRARIES)
147
148# Run jarjar if necessary, otherwise just copy the file.
149ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
150$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
151$(full_classes_jarjar_jar): $(full_classes_combined_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
152	@echo JarJar: $@
153	$(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
154else
155full_classes_jarjar_jar := $(full_classes_combined_jar)
156endif
157
158$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar)))
159
160ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
161# No dex; all we want are the .class files with resources.
162$(LOCAL_BUILT_MODULE) : $(java_resource_sources)
163$(LOCAL_BUILT_MODULE) : $(full_classes_jar)
164	@echo "host Static Jar: $(PRIVATE_MODULE) ($@)"
165	$(copy-file-to-target)
166
167else # !LOCAL_IS_STATIC_JAVA_LIBRARY
168$(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
169$(built_dex): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
170$(built_dex): $(full_classes_jar) $(DX) $(ZIP2ZIP)
171	$(transform-classes.jar-to-dex)
172
173$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
174$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar)
175$(LOCAL_BUILT_MODULE): $(MERGE_ZIPS) $(SOONG_ZIP) $(ZIP2ZIP)
176$(LOCAL_BUILT_MODULE): $(built_dex) $(java_resource_sources)
177	@echo "Host Jar: $(PRIVATE_MODULE) ($@)"
178	rm -rf $@.parts
179	mkdir -p $@.parts
180	$(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
181	$(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE))
182	$(MERGE_ZIPS) -j $@ $@.parts/dex.zip $@.parts/res.zip
183	rm -rf $@.parts
184
185endif # !LOCAL_IS_STATIC_JAVA_LIBRARY
186
187$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(call module-target-sdk-version)
188$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SDK_VERSION := $(call module-sdk-version)
189$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MIN_SDK_VERSION := $(call codename-or-sdk-to-sdk,$(call module-min-sdk-version))
190
191USE_CORE_LIB_BOOTCLASSPATH :=
192
193endif
194