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$(full_classes_compiled_jar): .KATI_NINJA_POOL := $(GOMA_POOL)
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_SRCJARS := $(LOCAL_SRCJARS)
108$(full_classes_turbine_jar): \
109    $(java_source_list_file) \
110    $(java_sources_deps) \
111    $(full_java_header_libs) \
112    $(full_java_bootclasspath_libs) \
113    $(NORMALIZE_PATH) \
114    $(JAR_ARGS) \
115    $(ZIPTIME) \
116    | $(TURBINE) \
117    $(MERGE_ZIPS)
118	$(transform-java-to-header.jar)
119
120.KATI_RESTAT: $(full_classes_turbine_jar)
121
122# Run jarjar before generate classes-header.jar if necessary.
123ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
124$(full_classes_header_jarjar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
125$(full_classes_header_jarjar): $(full_classes_turbine_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
126	@echo Header JarJar: $@
127	$(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
128else
129full_classes_header_jarjar := $(full_classes_turbine_jar)
130endif
131
132$(eval $(call copy-one-file,$(full_classes_header_jarjar),$(full_classes_header_jar)))
133
134endif # TURBINE_ENABLED != false
135
136$(full_classes_combined_jar): PRIVATE_DONT_DELETE_JAR_META_INF := $(LOCAL_DONT_DELETE_JAR_META_INF)
137$(full_classes_combined_jar): $(full_classes_compiled_jar) \
138                              $(jar_manifest_file) \
139                              $(full_static_java_libs)  | $(MERGE_ZIPS)
140	$(if $(PRIVATE_JAR_MANIFEST), $(hide) sed -e "s/%BUILD_NUMBER%/$(BUILD_NUMBER_FROM_FILE)/" \
141            $(PRIVATE_JAR_MANIFEST) > $(dir $@)/manifest.mf)
142	$(MERGE_ZIPS) -j --ignore-duplicates $(if $(PRIVATE_JAR_MANIFEST),-m $(dir $@)/manifest.mf) \
143            $(if $(PRIVATE_DONT_DELETE_JAR_META_INF),,-stripDir META-INF -zipToNotStrip $<) \
144            $@ $< $(PRIVATE_STATIC_JAVA_LIBRARIES)
145
146# Run jarjar if necessary, otherwise just copy the file.
147ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
148$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
149$(full_classes_jarjar_jar): $(full_classes_combined_jar) $(LOCAL_JARJAR_RULES) | $(JARJAR)
150	@echo JarJar: $@
151	$(hide) $(JAVA) -jar $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
152else
153full_classes_jarjar_jar := $(full_classes_combined_jar)
154endif
155
156$(eval $(call copy-one-file,$(full_classes_jarjar_jar),$(full_classes_jar)))
157
158ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true)
159# No dex; all we want are the .class files with resources.
160$(LOCAL_BUILT_MODULE) : $(java_resource_sources)
161$(LOCAL_BUILT_MODULE) : $(full_classes_jar)
162	@echo "host Static Jar: $(PRIVATE_MODULE) ($@)"
163	$(copy-file-to-target)
164
165else # !LOCAL_IS_STATIC_JAVA_LIBRARY
166$(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
167$(built_dex): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
168$(built_dex): $(full_classes_jar) $(DX) $(ZIP2ZIP)
169	$(transform-classes.jar-to-dex)
170
171$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
172$(LOCAL_BUILT_MODULE): PRIVATE_SOURCE_ARCHIVE := $(full_classes_jarjar_jar)
173$(LOCAL_BUILT_MODULE): $(MERGE_ZIPS) $(SOONG_ZIP) $(ZIP2ZIP)
174$(LOCAL_BUILT_MODULE): $(built_dex) $(java_resource_sources)
175	@echo "Host Jar: $(PRIVATE_MODULE) ($@)"
176	rm -rf $@.parts
177	mkdir -p $@.parts
178	$(call create-dex-jar,$@.parts/dex.zip,$(PRIVATE_DEX_FILE))
179	$(call extract-resources-jar,$@.parts/res.zip,$(PRIVATE_SOURCE_ARCHIVE))
180	$(MERGE_ZIPS) -j $@ $@.parts/dex.zip $@.parts/res.zip
181	rm -rf $@.parts
182
183endif # !LOCAL_IS_STATIC_JAVA_LIBRARY
184
185$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEFAULT_APP_TARGET_SDK := $(call module-target-sdk-version)
186$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SDK_VERSION := $(call module-sdk-version)
187$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_MIN_SDK_VERSION := $(call codename-or-sdk-to-sdk,$(call module-min-sdk-version))
188
189USE_CORE_LIB_BOOTCLASSPATH :=
190
191endif
192