blob: f11e723dc69d0955ec25e4ab341f21b65871e8f6 [file] [log] [blame]
Ying Wang956dccc2015-08-28 11:47:03 -07001# Common to host and target Java modules.
2
3###########################################################
4## .proto files: Compile proto files to .java
5###########################################################
6proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
7# Because names of the .java files compiled from .proto files are unknown until the
8# .proto files are compiled, we use a timestamp file as depedency.
9proto_java_sources_file_stamp :=
10ifneq ($(proto_sources),)
11proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
12
13# By putting the generated java files into $(LOCAL_INTERMEDIATE_SOURCE_DIR), they will be
14# automatically found by the java compiling function transform-java-to-classes.jar.
15proto_java_intemediate_dir := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/proto
16proto_java_sources_file_stamp := $(proto_java_intemediate_dir)/Proto.stamp
17proto_java_sources_dir := $(proto_java_intemediate_dir)/src
18
19$(proto_java_sources_file_stamp): PRIVATE_PROTO_INCLUDES := $(TOP)
20$(proto_java_sources_file_stamp): PRIVATE_PROTO_SRC_FILES := $(proto_sources_fullpath)
21$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_DIR := $(proto_java_sources_dir)
22ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
23$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javamicro_out
24else
25 ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nano)
26$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javanano_out
27 else
28$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --java_out
29 endif
30endif
31$(proto_java_sources_file_stamp): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
32$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_PARAMS := $(LOCAL_PROTO_JAVA_OUTPUT_PARAMS)
33$(proto_java_sources_file_stamp) : $(proto_sources_fullpath) $(PROTOC)
34 $(call transform-proto-to-java)
35
36#TODO: protoc should output the dependencies introduced by imports.
37endif # proto_sources
38
39#########################################
40## Java resources
41
42# Look for resource files in any specified directories.
43# Non-java and non-doc files will be picked up as resources
44# and included in the output jar file.
45java_resource_file_groups :=
46
47LOCAL_JAVA_RESOURCE_DIRS := $(strip $(LOCAL_JAVA_RESOURCE_DIRS))
48ifneq ($(LOCAL_JAVA_RESOURCE_DIRS),)
49 # This makes a list of words like
50 # <dir1>::<file1>:<file2> <dir2>::<file1> <dir3>:
51 # where each of the files is relative to the directory it's grouped with.
52 # Directories that don't contain any resource files will result in groups
53 # that end with a colon, and they are stripped out in the next step.
54 java_resource_file_groups += \
55 $(foreach dir,$(LOCAL_JAVA_RESOURCE_DIRS), \
56 $(subst $(space),:,$(strip \
57 $(LOCAL_PATH)/$(dir): \
Dan Willemsen7c3e3f82015-09-29 16:30:21 -070058 $(patsubst ./%,%,$(sort $(shell cd $(LOCAL_PATH)/$(dir) && \
Ying Wang956dccc2015-08-28 11:47:03 -070059 find . \
60 -type d -a -name ".svn" -prune -o \
61 -type f \
62 -a \! -name "*.java" \
63 -a \! -name "package.html" \
64 -a \! -name "overview.html" \
65 -a \! -name ".*.swp" \
66 -a \! -name ".DS_Store" \
67 -a \! -name "*~" \
68 -print \
Dan Willemsen7c3e3f82015-09-29 16:30:21 -070069 ))) \
Ying Wang956dccc2015-08-28 11:47:03 -070070 )) \
71 )
72 java_resource_file_groups := $(filter-out %:,$(java_resource_file_groups))
73endif # LOCAL_JAVA_RESOURCE_DIRS
74
75LOCAL_JAVA_RESOURCE_FILES := $(strip $(LOCAL_JAVA_RESOURCE_FILES))
76ifneq ($(LOCAL_JAVA_RESOURCE_FILES),)
77 java_resource_file_groups += \
78 $(foreach f,$(LOCAL_JAVA_RESOURCE_FILES), \
79 $(patsubst %/,%,$(dir $(f)))::$(notdir $(f)) \
80 )
81endif # LOCAL_JAVA_RESOURCE_FILES
82
83ifdef java_resource_file_groups
84 # The full paths to all resources, used for dependencies.
85 java_resource_sources := \
86 $(foreach group,$(java_resource_file_groups), \
87 $(addprefix $(word 1,$(subst :,$(space),$(group)))/, \
88 $(wordlist 2,9999,$(subst :,$(space),$(group))) \
89 ) \
90 )
91 # The arguments to jar that will include these files in a jar file.
92 # Quote the file name to handle special characters (such as #) correctly.
93 extra_jar_args := \
94 $(foreach group,$(java_resource_file_groups), \
95 $(addprefix -C "$(word 1,$(subst :,$(space),$(group)))" , \
96 $(foreach w, $(wordlist 2,9999,$(subst :,$(space),$(group))), "$(w)" ) \
97 ) \
98 )
99 java_resource_file_groups :=
100else
101 java_resource_sources :=
102 extra_jar_args :=
103endif # java_resource_file_groups
104
105######################################
106## PRIVATE java vars
107# LOCAL_SOURCE_FILES_ALL_GENERATED is set only if the module does not have static source files,
108# but generated source files in its LOCAL_INTERMEDIATE_SOURCE_DIR.
109# You have to set up the dependency in some other way.
110need_compile_java := $(strip $(all_java_sources)$(all_res_assets)$(java_resource_sources))$(LOCAL_STATIC_JAVA_LIBRARIES)$(filter true,$(LOCAL_SOURCE_FILES_ALL_GENERATED))
111ifdef need_compile_java
112
113full_static_java_libs := \
114 $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
115 $(call intermediates-dir-for, \
116 JAVA_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),COMMON)/javalib.jar)
117
118$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JAVA_LIBRARIES := $(full_static_java_libs)
119
120$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
121$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := $(LOCAL_ASSET_DIR)
122
123$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLASS_INTERMEDIATES_DIR := $(intermediates.COMMON)/classes
124$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_SOURCE_INTERMEDIATES_DIR := $(intermediates.COMMON)/src
125$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCES := $(all_java_sources)
126
127$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RMTYPEDEFS := $(LOCAL_RMTYPEDEFS)
128
129# full_java_libs: The list of files that should be used as the classpath.
130# Using this list as a dependency list WILL NOT WORK.
131# full_java_lib_deps: Should be specified as a prerequisite of this module
132# to guarantee that the files in full_java_libs will
133# be up-to-date.
134ifndef LOCAL_IS_HOST_MODULE
135ifeq ($(LOCAL_SDK_VERSION),)
Ying Wang4f2f1952015-11-23 14:57:26 -0800136ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
137# No bootclasspath. But we still need "" to prevent javac from using default host bootclasspath.
138my_bootclasspath := ""
139else # LOCAL_NO_STANDARD_LIBRARIES
140my_bootclasspath := $(call java-lib-files,core-libart)
141endif # LOCAL_NO_STANDARD_LIBRARIES
Ying Wang956dccc2015-08-28 11:47:03 -0700142else
143ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
144# LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
Ying Wang4f2f1952015-11-23 14:57:26 -0800145my_bootclasspath := $(call java-lib-files,android_stubs_current)
Ying Wang956dccc2015-08-28 11:47:03 -0700146else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),system_current)
Ying Wang4f2f1952015-11-23 14:57:26 -0800147my_bootclasspath := $(call java-lib-files,android_system_stubs_current)
Ying Wang956dccc2015-08-28 11:47:03 -0700148else
Ying Wang4f2f1952015-11-23 14:57:26 -0800149my_bootclasspath := $(call java-lib-files,sdk_v$(LOCAL_SDK_VERSION))
Ying Wang956dccc2015-08-28 11:47:03 -0700150endif # current or system_current
151endif # LOCAL_SDK_VERSION
Ying Wang4f2f1952015-11-23 14:57:26 -0800152$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(my_bootclasspath)
Ying Wang956dccc2015-08-28 11:47:03 -0700153
154full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
155full_java_lib_deps := $(call java-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +0900156full_java_lib_deps := $(addsuffix .toc, $(full_java_lib_deps))
Ying Wang956dccc2015-08-28 11:47:03 -0700157
158else # LOCAL_IS_HOST_MODULE
159
160ifeq ($(USE_CORE_LIB_BOOTCLASSPATH),true)
Ying Wang4f2f1952015-11-23 14:57:26 -0800161ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
162my_bootclasspath := ""
163else
164my_bootclasspath := $(call java-lib-files,core-libart-hostdex,$(LOCAL_IS_HOST_MODULE))
165endif
166$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(my_bootclasspath)
Ying Wang956dccc2015-08-28 11:47:03 -0700167
168full_shared_java_libs := $(call java-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
169full_java_lib_deps := $(call java-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE)) \
170 $(full_shared_java_libs)
171else
172$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH :=
173
174full_shared_java_libs := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/,\
175 $(addsuffix $(COMMON_JAVA_PACKAGE_SUFFIX),$(LOCAL_JAVA_LIBRARIES)))
176full_java_lib_deps := $(full_shared_java_libs)
177endif # USE_CORE_LIB_BOOTCLASSPATH
178endif # !LOCAL_IS_HOST_MODULE
179
180full_java_libs := $(full_shared_java_libs) $(full_static_java_libs) $(LOCAL_CLASSPATH)
181full_java_lib_deps := $(full_java_lib_deps) $(full_static_java_libs) $(LOCAL_CLASSPATH)
182
183ifndef LOCAL_IS_HOST_MODULE
184# This is set by packages that are linking to other packages that export
185# shared libraries, allowing them to make use of the code in the linked apk.
186apk_libraries := $(sort $(LOCAL_APK_LIBRARIES) $(LOCAL_RES_LIBRARIES))
187ifneq ($(apk_libraries),)
188 link_apk_libraries := \
189 $(foreach lib,$(apk_libraries), \
190 $(call intermediates-dir-for, \
191 APPS,$(lib),,COMMON)/classes.jar)
192
193 # link against the jar with full original names (before proguard processing).
194 full_shared_java_libs += $(link_apk_libraries)
195 full_java_libs += $(link_apk_libraries)
196 full_java_lib_deps += $(link_apk_libraries)
197endif
198
199# This is set by packages that contain instrumentation, allowing them to
200# link against the package they are instrumenting. Currently only one such
201# package is allowed.
202LOCAL_INSTRUMENTATION_FOR := $(strip $(LOCAL_INSTRUMENTATION_FOR))
203ifdef LOCAL_INSTRUMENTATION_FOR
204 ifneq ($(words $(LOCAL_INSTRUMENTATION_FOR)),1)
205 $(error \
206 $(LOCAL_PATH): Multiple LOCAL_INSTRUMENTATION_FOR members defined)
207 endif
208
209 link_instr_intermediates_dir.COMMON := $(call intermediates-dir-for, \
210 APPS,$(LOCAL_INSTRUMENTATION_FOR),,COMMON)
211 # link against the jar with full original names (before proguard processing).
212 link_instr_classes_jar := $(link_instr_intermediates_dir.COMMON)/classes.jar
213 full_java_libs += $(link_instr_classes_jar)
214 full_java_lib_deps += $(link_instr_classes_jar)
215endif # LOCAL_INSTRUMENTATION_FOR
216endif # LOCAL_IS_HOST_MODULE
217
218endif # need_compile_java
219
220# We may want to add jar manifest or jar resource files even if there is no java code at all.
221$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args)
222jar_manifest_file :=
223ifneq ($(strip $(LOCAL_JAR_MANIFEST)),)
224jar_manifest_file := $(LOCAL_PATH)/$(LOCAL_JAR_MANIFEST)
225$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST := $(jar_manifest_file)
226else
227$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAR_MANIFEST :=
228endif
229
230##########################################################
231ifndef LOCAL_IS_HOST_MODULE
232## AAPT Flags
233# aapt doesn't accept multiple --extra-packages flags.
234# We have to collapse them into a single --extra-packages flag here.
235LOCAL_AAPT_FLAGS := $(strip $(LOCAL_AAPT_FLAGS))
236ifdef LOCAL_AAPT_FLAGS
237ifeq ($(filter 0 1,$(words $(filter --extra-packages,$(LOCAL_AAPT_FLAGS)))),)
238aapt_flags := $(subst --extra-packages$(space),--extra-packages@,$(LOCAL_AAPT_FLAGS))
239aapt_flags_extra_packages := $(patsubst --extra-packages@%,%,$(filter --extra-packages@%,$(aapt_flags)))
240aapt_flags_extra_packages := $(sort $(subst :,$(space),$(aapt_flags_extra_packages)))
241LOCAL_AAPT_FLAGS := $(filter-out --extra-packages@%,$(aapt_flags)) \
242 --extra-packages $(subst $(space),:,$(aapt_flags_extra_packages))
243aapt_flags_extra_packages :=
244aapt_flags :=
245endif
246endif
247
248$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) $(PRODUCT_AAPT_FLAGS)
249$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_MANIFEST_PACKAGE_NAME := $(LOCAL_MANIFEST_PACKAGE_NAME)
250$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_MANIFEST_INSTRUMENTATION_FOR := $(LOCAL_MANIFEST_INSTRUMENTATION_FOR)
251
Ying Wang956dccc2015-08-28 11:47:03 -0700252ifdef aidl_sources
253ALL_MODULES.$(my_register_name).AIDL_FILES := $(aidl_sources)
254endif
255endif # !LOCAL_IS_HOST_MODULE
256
257$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_ALL_JAVA_LIBRARIES := $(full_java_libs)
258
259ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR := \
260 $(ALL_MODULES.$(my_register_name).INTERMEDIATE_SOURCE_DIR) $(LOCAL_INTERMEDIATE_SOURCE_DIR)
261
262###########################################################
263# JACK
264###########################################################
265ifdef LOCAL_JACK_ENABLED
266ifdef need_compile_java
267
268full_static_jack_libs := \
269 $(foreach lib,$(LOCAL_STATIC_JAVA_LIBRARIES), \
270 $(call intermediates-dir-for, \
271 JAVA_LIBRARIES,$(lib),$(LOCAL_IS_HOST_MODULE),COMMON)/classes.jack)
272
273$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_STATIC_JACK_LIBRARIES := $(full_static_jack_libs)
Ying Wang956dccc2015-08-28 11:47:03 -0700274
275ifndef LOCAL_IS_HOST_MODULE
276ifeq ($(LOCAL_SDK_VERSION),)
Ying Wang4f2f1952015-11-23 14:57:26 -0800277ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
278my_bootclasspath :=
Ying Wang956dccc2015-08-28 11:47:03 -0700279else
Ying Wang4f2f1952015-11-23 14:57:26 -0800280my_bootclasspath := $(call jack-lib-files,core-libart)
281endif
282else # LOCAL_SDK_VERSION
Ying Wang956dccc2015-08-28 11:47:03 -0700283ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),current)
284# LOCAL_SDK_VERSION is current and no TARGET_BUILD_APPS.
Ying Wang4f2f1952015-11-23 14:57:26 -0800285my_bootclasspath := $(call jack-lib-files,android_stubs_current)
Ying Wang956dccc2015-08-28 11:47:03 -0700286else ifeq ($(LOCAL_SDK_VERSION)$(TARGET_BUILD_APPS),system_current)
Ying Wang4f2f1952015-11-23 14:57:26 -0800287my_bootclasspath := $(call jack-lib-files,android_system_stubs_current)
Ying Wang956dccc2015-08-28 11:47:03 -0700288else
Ying Wang4f2f1952015-11-23 14:57:26 -0800289my_bootclasspath :=$(call jack-lib-files,sdk_v$(LOCAL_SDK_VERSION))
Ying Wang956dccc2015-08-28 11:47:03 -0700290endif # current or system_current
291endif # LOCAL_SDK_VERSION
Ying Wang4f2f1952015-11-23 14:57:26 -0800292$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES := $(my_bootclasspath)
Ying Wang956dccc2015-08-28 11:47:03 -0700293
294full_shared_jack_libs := $(call jack-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
295full_jack_lib_deps := $(call jack-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +0900296# Turn off .toc optimization for apps build as we cannot build dexdump.
297ifeq (,$(TARGET_BUILD_APPS))
298full_jack_lib_deps := $(patsubst %.jack, %.dex.toc, $(full_jack_lib_deps))
299endif
Ying Wang956dccc2015-08-28 11:47:03 -0700300
301else # LOCAL_IS_HOST_MODULE
302
303ifeq ($(USE_CORE_LIB_BOOTCLASSPATH),true)
Ying Wang4f2f1952015-11-23 14:57:26 -0800304ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
305my_bootclasspath :=
306else
307my_bootclasspath := $(call jack-lib-files,core-libart-hostdex,$(LOCAL_IS_HOST_MODULE))
308endif
309$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES := $(my_bootclasspath)
Ying Wang956dccc2015-08-28 11:47:03 -0700310full_shared_jack_libs := $(call jack-lib-files,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
311full_jack_lib_deps := $(call jack-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
312else
313$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH_JAVA_LIBRARIES :=
314full_shared_jack_libs := $(call jack-lib-deps,$(LOCAL_JAVA_LIBRARIES),$(LOCAL_IS_HOST_MODULE))
315full_jack_lib_deps := $(full_shared_jack_libs)
316endif # USE_CORE_LIB_BOOTCLASSPATH
317endif # !LOCAL_IS_HOST_MODULE
318full_jack_libs := $(full_shared_jack_libs) $(full_static_jack_libs) $(LOCAL_JACK_CLASSPATH)
319full_jack_lib_deps += $(full_static_jack_libs) $(LOCAL_JACK_CLASSPATH)
320
321ifndef LOCAL_IS_HOST_MODULE
322# This is set by packages that are linking to other packages that export
323# shared libraries, allowing them to make use of the code in the linked apk.
324ifneq ($(apk_libraries),)
325 link_apk_jack_libraries := \
326 $(foreach lib,$(apk_libraries), \
327 $(call intermediates-dir-for, \
328 APPS,$(lib),,COMMON)/classes.jack)
329
330 # link against the jar with full original names (before proguard processing).
331 full_shared_jack_libs += $(link_apk_jack_libraries)
332 full_jack_libs += $(link_apk_jack_libraries)
333 full_jack_lib_deps += $(link_apk_jack_libraries)
334endif
335
336# This is set by packages that contain instrumentation, allowing them to
337# link against the package they are instrumenting. Currently only one such
338# package is allowed.
339ifdef LOCAL_INSTRUMENTATION_FOR
340 # link against the jar with full original names (before proguard processing).
341 link_instr_classes_jack := $(link_instr_intermediates_dir.COMMON)/classes.noshrob.jack
342 full_jack_libs += $(link_instr_classes_jack)
343 full_jack_lib_deps += $(link_instr_classes_jack)
344endif # LOCAL_INSTRUMENTATION_FOR
345endif # !LOCAL_IS_HOST_MODULE
346
347# Propagate local configuration options to this target.
348$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_ALL_JACK_LIBRARIES:= $(full_jack_libs)
349$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
350
351endif # need_compile_java
352endif # LOCAL_JACK_ENABLED