blob: 63fac44843ac2d28fb3f61a654db0b03d21e2f8d [file] [log] [blame]
Colin Crosse18cb932014-02-13 15:04:18 -08001###########################################################
2## Standard rules for copying files that are prebuilt
3##
4## Additional inputs from base_rules.make:
5## None.
6##
7###########################################################
8
9ifneq ($(LOCAL_PREBUILT_LIBS),)
10$(error dont use LOCAL_PREBUILT_LIBS anymore LOCAL_PATH=$(LOCAL_PATH))
11endif
12ifneq ($(LOCAL_PREBUILT_EXECUTABLES),)
13$(error dont use LOCAL_PREBUILT_EXECUTABLES anymore LOCAL_PATH=$(LOCAL_PATH))
14endif
15ifneq ($(LOCAL_PREBUILT_JAVA_LIBRARIES),)
16$(error dont use LOCAL_PREBUILT_JAVA_LIBRARIES anymore LOCAL_PATH=$(LOCAL_PATH))
17endif
18
Ying Wang34d5f1b2014-05-16 10:38:43 -070019my_32_64_bit_suffix := $(if $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)IS_64_BIT),64,32)
20
Colin Crosse18cb932014-02-13 15:04:18 -080021ifdef LOCAL_PREBUILT_MODULE_FILE
Ying Wangc0adfb72014-02-27 14:10:53 -080022 my_prebuilt_src_file := $(LOCAL_PREBUILT_MODULE_FILE)
Colin Crosse18cb932014-02-13 15:04:18 -080023else
Ying Wang6feb6d52014-04-17 10:03:35 -070024 ifdef LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
25 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
Dan Willemsen5709bd52016-02-01 21:40:17 -080026 LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) :=
Ying Wangc0adfb72014-02-27 14:10:53 -080027 else
Ying Wang34d5f1b2014-05-16 10:38:43 -070028 ifdef LOCAL_SRC_FILES_$(my_32_64_bit_suffix)
29 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES_$(my_32_64_bit_suffix))
Dan Willemsen3bb168f2016-01-19 20:07:08 -080030 LOCAL_SRC_FILES_$(my_32_64_bit_suffix) :=
Ying Wang34d5f1b2014-05-16 10:38:43 -070031 else
32 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
Dan Willemsen3bb168f2016-01-19 20:07:08 -080033 LOCAL_SRC_FILES :=
Ying Wang34d5f1b2014-05-16 10:38:43 -070034 endif
Ying Wangc0adfb72014-02-27 14:10:53 -080035 endif
Colin Crosse18cb932014-02-13 15:04:18 -080036endif
37
Colin Cross01e1b8f2016-10-27 22:10:55 +000038LOCAL_CHECKED_MODULE := $(my_prebuilt_src_file)
39
Ying Wangb6eb8dd2016-03-01 20:14:52 -080040my_strip_module := $(firstword \
41 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
42 $(LOCAL_STRIP_MODULE))
43my_pack_module_relocations := $(firstword \
44 $(LOCAL_PACK_MODULE_RELOCATIONS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
45 $(LOCAL_PACK_MODULE_RELOCATIONS))
46
Colin Crosse18cb932014-02-13 15:04:18 -080047ifeq (SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS))
Dan Albert4ac42312016-07-20 11:02:18 -070048 # LOCAL_COPY_TO_INTERMEDIATE_LIBRARIES indicates that this prebuilt should be
49 # installed to the common directory of libraries. This is needed for the NDK
50 # shared libraries built by soong, as we build many different versions of each
51 # library (one for each API level). Since they all have the same basename,
52 # they'd clobber each other (as well as any platform libraries by the same
53 # name).
54 ifneq ($(LOCAL_COPY_TO_INTERMEDIATE_LIBRARIES),false)
55 # Put the built targets of all shared libraries in a common directory
56 # to simplify the link line.
57 OVERRIDE_BUILT_MODULE_PATH := \
58 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)
59 endif
Ying Wangb6eb8dd2016-03-01 20:14:52 -080060 ifeq ($(LOCAL_IS_HOST_MODULE)$(my_strip_module),)
Ying Wangbfb52a22014-08-20 17:12:32 -070061 # Strip but not try to add debuglink
Ying Wangb6eb8dd2016-03-01 20:14:52 -080062 my_strip_module := no_debuglink
Ying Wangbfb52a22014-08-20 17:12:32 -070063 endif
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070064
Ying Wangb6eb8dd2016-03-01 20:14:52 -080065 ifeq ($(LOCAL_IS_HOST_MODULE)$(my_pack_module_relocations),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070066 # Do not pack relocations by default
Ying Wangb6eb8dd2016-03-01 20:14:52 -080067 my_pack_module_relocations := false
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070068 endif
Dan Albert52831d12015-11-12 15:27:49 -080069
70 ifeq ($(DISABLE_RELOCATION_PACKER),true)
Ying Wangb6eb8dd2016-03-01 20:14:52 -080071 my_pack_module_relocations := false
Dan Albert52831d12015-11-12 15:27:49 -080072 endif
Colin Crosse18cb932014-02-13 15:04:18 -080073endif
74
75ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
76 prebuilt_module_is_a_library := true
77else
78 prebuilt_module_is_a_library :=
79endif
80
Dan Willemsenfc92fb22016-08-26 13:27:13 -070081ifeq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
82ifeq ($(prebuilt_module_is_a_library),true)
83SOONG_ALREADY_CONV := $(SOONG_ALREADY_CONV) $(LOCAL_MODULE)
84endif
85endif
86
Colin Crosse18cb932014-02-13 15:04:18 -080087# Don't install static libraries by default.
88ifndef LOCAL_UNINSTALLABLE_MODULE
89ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS))
90 LOCAL_UNINSTALLABLE_MODULE := true
91endif
92endif
93
Ying Wang3a61eeb2016-03-11 10:32:01 -080094ifeq (JAVA_LIBRARIES,$(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS)$(filter true,$(LOCAL_UNINSTALLABLE_MODULE)))
95 prebuilt_module_is_dex_javalib := true
96else
97 prebuilt_module_is_dex_javalib :=
98endif
99
Ying Wangaf9757e2014-07-17 21:24:42 -0700100ifeq ($(LOCAL_MODULE_CLASS),APPS)
101LOCAL_BUILT_MODULE_STEM := package.apk
Dan Willemsendc1ddfc2016-08-05 17:23:33 -0700102ifndef LOCAL_INSTALLED_MODULE_STEM
Ying Wangaf9757e2014-07-17 21:24:42 -0700103LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
104endif
Dan Willemsendc1ddfc2016-08-05 17:23:33 -0700105endif
Ying Wangaf9757e2014-07-17 21:24:42 -0700106
Dan Willemsen4598fbc2016-07-13 16:08:36 -0700107ifneq ($(filter true keep_symbols no_debuglink mini-debug-info,$(my_strip_module) $(my_pack_module_relocations)),)
Colin Crosse18cb932014-02-13 15:04:18 -0800108 ifdef LOCAL_IS_HOST_MODULE
Dmitriy Ivanov64762c32015-04-24 15:33:14 -0700109 $(error Cannot strip/pack host module LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -0800110 endif
Dan Willemsen7fe992c2016-03-02 13:54:51 -0800111 ifeq ($(filter SHARED_LIBRARIES EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -0700112 $(error Can strip/pack only shared libraries or executables LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -0800113 endif
114 ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -0700115 $(error Cannot strip/pack scripts LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -0800116 endif
Ying Wangb6eb8dd2016-03-01 20:14:52 -0800117 # Set the arch-specific variables to set up the strip/pack rules.
118 LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) := $(my_strip_module)
119 LOCAL_PACK_MODULE_RELOCATIONS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) := $(my_pack_module_relocations)
Colin Crosse18cb932014-02-13 15:04:18 -0800120 include $(BUILD_SYSTEM)/dynamic_binary.mk
121 built_module := $(linked_module)
Ying Wangbfb52a22014-08-20 17:12:32 -0700122
Ying Wangb6eb8dd2016-03-01 20:14:52 -0800123else # my_strip_module and my_pack_module_relocations not true
Colin Crosse18cb932014-02-13 15:04:18 -0800124 include $(BUILD_SYSTEM)/base_rules.mk
125 built_module := $(LOCAL_BUILT_MODULE)
126
127ifdef prebuilt_module_is_a_library
128export_includes := $(intermediates)/export_includes
129$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
Dan Willemsenba6a1642016-09-29 12:08:29 -0700130$(export_includes): $(LOCAL_EXPORT_C_INCLUDE_DEPS)
Colin Crosse18cb932014-02-13 15:04:18 -0800131 @echo Export includes file: $< -- $@
132 $(hide) mkdir -p $(dir $@) && rm -f $@
133ifdef LOCAL_EXPORT_C_INCLUDE_DIRS
134 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \
135 echo "-I $$d" >> $@; \
136 done
137else
138 $(hide) touch $@
139endif
140
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700141my_link_type := $(intermediates)/link_type
Dan Willemsen121e2842016-09-14 21:38:29 -0700142$(my_link_type): PRIVATE_LINK_TYPE := native:$(if $(LOCAL_SDK_VERSION),ndk,platform)
143$(eval $(call link-type-partitions,$(my_link_type)))
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700144$(my_link_type):
145 @echo Check module type: $@
146 $(hide) mkdir -p $(dir $@) && rm -f $@
Dan Willemsen121e2842016-09-14 21:38:29 -0700147 $(hide) echo "$(PRIVATE_LINK_TYPE)" >$@
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700148
149$(LOCAL_BUILT_MODULE) : | $(export_includes) $(my_link_type)
Colin Crosse18cb932014-02-13 15:04:18 -0800150endif # prebuilt_module_is_a_library
151
152# The real dependency will be added after all Android.mks are loaded and the install paths
153# of the shared libraries are determined.
154ifdef LOCAL_INSTALLED_MODULE
155ifdef LOCAL_SHARED_LIBRARIES
Ying Wang7c877392014-10-07 13:03:29 -0700156my_shared_libraries := $(LOCAL_SHARED_LIBRARIES)
157# Extra shared libraries introduced by LOCAL_CXX_STL.
158include $(BUILD_SYSTEM)/cxx_stl_setup.mk
Ying Wang58f462f2014-02-25 18:26:29 -0800159$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
Ying Wang7c877392014-10-07 13:03:29 -0700160 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries))
Colin Crosse18cb932014-02-13 15:04:18 -0800161
162# We also need the LOCAL_BUILT_MODULE dependency,
163# since we use -rpath-link which points to the built module's path.
Ying Wang7c877392014-10-07 13:03:29 -0700164my_built_shared_libraries := \
Ying Wang58f462f2014-02-25 18:26:29 -0800165 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
Colin Crosse18cb932014-02-13 15:04:18 -0800166 $(addsuffix $($(my_prefix)SHLIB_SUFFIX), \
Ying Wang7c877392014-10-07 13:03:29 -0700167 $(my_shared_libraries)))
168$(LOCAL_BUILT_MODULE) : $(my_built_shared_libraries)
Colin Crosse18cb932014-02-13 15:04:18 -0800169endif
170endif
171
Ying Wang7c877392014-10-07 13:03:29 -0700172# We need to enclose the above export_includes and my_built_shared_libraries in
Ying Wangb6eb8dd2016-03-01 20:14:52 -0800173# "my_strip_module not true" because otherwise the rules are defined in dynamic_binary.mk.
174endif # my_strip_module not true
Colin Crosse18cb932014-02-13 15:04:18 -0800175
Dan Willemsen9f956652016-10-21 15:04:12 -0700176ifeq ($(NATIVE_COVERAGE),true)
Dan Willemsen0f909082017-02-10 00:07:17 -0800177ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE)))
178 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).gcnodir))
179 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true)
180 ifdef LOCAL_IS_HOST_MODULE
181 my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path))
182 else
183 my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
184 endif
185 my_coverage_path := $(my_coverage_path)/$(basename $(my_installed_module_stem)).gcnodir
186 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path)))
187 $(LOCAL_BUILT_MODULE): $(my_coverage_path)
188 endif
189else
Ryan Campbell81c9d292016-09-12 13:56:50 -0700190# Coverage information is needed when static lib is a dependency of another
191# coverage-enabled module.
192ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS))
193GCNO_ARCHIVE := $(LOCAL_MODULE).gcnodir
194$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS :=
195$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES :=
Dan Willemsen9f956652016-10-21 15:04:12 -0700196$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_PREFIX := $(my_prefix)
197$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX)
Ryan Campbell81c9d292016-09-12 13:56:50 -0700198$(intermediates)/$(GCNO_ARCHIVE) :
199 $(transform-o-to-static-lib)
200endif
Dan Willemsen9f956652016-10-21 15:04:12 -0700201endif
Dan Willemsen0f909082017-02-10 00:07:17 -0800202endif
Ryan Campbell81c9d292016-09-12 13:56:50 -0700203
Ying Wangf0534c22014-04-15 11:12:21 -0700204ifeq ($(LOCAL_MODULE_CLASS),APPS)
Colin Crosse18cb932014-02-13 15:04:18 -0800205PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
206
Dan Willemsen048f56d2016-06-18 20:43:51 -0700207my_extract_apk := $(strip $(LOCAL_EXTRACT_APK))
208
Ying Wang43f7a322014-11-17 16:56:04 -0800209# Select dpi-specific source
210ifdef LOCAL_DPI_VARIANTS
Ying Wang60686582014-12-10 12:40:09 -0800211my_dpi := $(firstword $(filter $(LOCAL_DPI_VARIANTS),$(PRODUCT_AAPT_PREF_CONFIG) $(PRODUCT_AAPT_PREBUILT_DPI)))
Ying Wang43f7a322014-11-17 16:56:04 -0800212ifdef my_dpi
213ifdef LOCAL_DPI_FILE_STEM
214my_prebuilt_dpi_file_stem := $(LOCAL_DPI_FILE_STEM)
215else
216my_prebuilt_dpi_file_stem := $(LOCAL_MODULE)_%.apk
217endif
218my_prebuilt_src_file := $(dir $(my_prebuilt_src_file))$(subst %,$(my_dpi),$(my_prebuilt_dpi_file_stem))
Dan Willemsen048f56d2016-06-18 20:43:51 -0700219
220ifneq ($(strip $(LOCAL_EXTRACT_DPI_APK)),)
221my_extract_apk := $(subst %,$(my_dpi),$(LOCAL_EXTRACT_DPI_APK))
222endif # LOCAL_EXTRACT_DPI_APK
Ying Wang43f7a322014-11-17 16:56:04 -0800223endif # my_dpi
224endif # LOCAL_DPI_VARIANTS
225
Dan Willemsen048f56d2016-06-18 20:43:51 -0700226ifdef my_extract_apk
227my_extracted_apk := $(intermediates)/extracted.apk
228
229$(my_extracted_apk): PRIVATE_EXTRACT := $(my_extract_apk)
230$(my_extracted_apk): $(my_prebuilt_src_file)
231 @echo Extract APK: $@
232 $(hide) mkdir -p $(dir $@) && rm -f $@
233 $(hide) unzip -p $< $(PRIVATE_EXTRACT) >$@
234
235my_prebuilt_src_file := $(my_extracted_apk)
236my_extracted_apk :=
237my_extract_apk :=
238endif
239
Ying Wang96bcad42014-04-17 13:38:04 -0700240rs_compatibility_jni_libs :=
241include $(BUILD_SYSTEM)/install_jni_libs.mk
242
Colin Crosse18cb932014-02-13 15:04:18 -0800243ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
244 # The magic string "EXTERNAL" means this package will be signed with
245 # the default dev key throughout the build process, but we expect
246 # the final package to be signed with a different key.
247 #
248 # This can be used for packages where we don't have access to the
249 # keys, but want the package to be predexopt'ed.
250 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
251 PACKAGES.$(LOCAL_MODULE).EXTERNAL_KEY := 1
252
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900253 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
Colin Crosse18cb932014-02-13 15:04:18 -0800254 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
255 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
256endif
257ifeq ($(LOCAL_CERTIFICATE),)
Ying Wangf0534c22014-04-15 11:12:21 -0700258 # It is now a build error to add a prebuilt .apk without
259 # specifying a key for it.
260 $(error No LOCAL_CERTIFICATE specified for prebuilt "$(my_prebuilt_src_file)")
Colin Crosse18cb932014-02-13 15:04:18 -0800261else ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
262 # The magic string "PRESIGNED" means this package is already checked
263 # signed with its release key.
264 #
265 # By setting .CERTIFICATE but not .PRIVATE_KEY, this package will be
266 # mentioned in apkcerts.txt (with certificate set to "PRESIGNED")
267 # but the dexpreopt process will not try to re-sign the app.
268 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := PRESIGNED
269 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
270else
271 # If this is not an absolute certificate, assign it to a generic one.
272 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
273 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
274 endif
275
276 PACKAGES.$(LOCAL_MODULE).PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
277 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
278 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
279
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900280 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
Colin Crosse18cb932014-02-13 15:04:18 -0800281 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
282 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
283endif
284
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700285# Disable dex-preopt of prebuilts to save space, if requested.
Ying Wang3a61eeb2016-03-11 10:32:01 -0800286ifndef LOCAL_DEX_PREOPT
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700287ifeq ($(DONT_DEXPREOPT_PREBUILTS),true)
Colin Crosse18cb932014-02-13 15:04:18 -0800288LOCAL_DEX_PREOPT := false
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700289endif
Ying Wang3a61eeb2016-03-11 10:32:01 -0800290endif
Colin Crosse18cb932014-02-13 15:04:18 -0800291
292#######################################
293# defines built_odex along with rule to install odex
294include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
295#######################################
Ying Wang3a61eeb2016-03-11 10:32:01 -0800296ifneq ($(LOCAL_REPLACE_PREBUILT_APK_INSTALLED),)
297# There is a replacement for the prebuilt .apk we can install without any processing.
Ying Wangc9a19772016-03-15 14:40:33 -0700298$(built_module) : $(LOCAL_REPLACE_PREBUILT_APK_INSTALLED)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800299 $(transform-prebuilt-to-target)
Ying Wang1fb01522015-05-01 14:02:26 -0700300
Ying Wang3a61eeb2016-03-11 10:32:01 -0800301else # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
302# Sign and align non-presigned .apks.
Ying Wang1fb01522015-05-01 14:02:26 -0700303# The embedded prebuilt jni to uncompress.
Ying Wang226eb922015-06-01 19:19:57 -0700304ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
305# For PRESIGNED apks we must uncompress every .so file:
306# even if the .so file isn't for the current TARGET_ARCH,
307# we can't strip the file.
308embedded_prebuilt_jni_libs := 'lib/*.so'
309endif
Ying Wang1fb01522015-05-01 14:02:26 -0700310ifndef embedded_prebuilt_jni_libs
311# No LOCAL_PREBUILT_JNI_LIBS, uncompress all.
312embedded_prebuilt_jni_libs := 'lib/*.so'
313endif
314$(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
315
Alex Klyubin1b391c02016-12-15 12:51:25 -0800316$(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(SIGNAPK_JAR)
Colin Crosse18cb932014-02-13 15:04:18 -0800317 $(transform-prebuilt-to-target)
Ying Wang226eb922015-06-01 19:19:57 -0700318 $(uncompress-shared-libs)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800319ifdef LOCAL_DEX_PREOPT
320ifneq ($(BUILD_PLATFORM_ZIP),)
321 @# Keep a copy of apk with classes.dex unstripped
322 $(hide) cp -f $@ $(dir $@)package.dex.apk
323endif # BUILD_PLATFORM_ZIP
324endif # LOCAL_DEX_PREOPT
Kenny Rootdff37552015-04-15 12:09:32 -0700325ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
326 @# Only strip out files if we can re-sign the package.
Colin Crosse18cb932014-02-13 15:04:18 -0800327ifdef LOCAL_DEX_PREOPT
Ying Wang36142f62014-05-21 16:13:33 -0700328ifneq (nostripping,$(LOCAL_DEX_PREOPT))
329 $(call dexpreopt-remove-classes.dex,$@)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800330endif # LOCAL_DEX_PREOPT != nostripping
331endif # LOCAL_DEX_PREOPT
Kenny Rootdff37552015-04-15 12:09:32 -0700332 $(sign-package)
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800333 # No need for align-package because sign-package takes care of alignment
Ying Wang3a61eeb2016-03-11 10:32:01 -0800334else # LOCAL_CERTIFICATE == PRESIGNED
Colin Crosse18cb932014-02-13 15:04:18 -0800335 $(align-package)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800336endif # LOCAL_CERTIFICATE
337endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
Colin Crosse18cb932014-02-13 15:04:18 -0800338
Ying Wang36142f62014-05-21 16:13:33 -0700339###############################
340## Rule to build the odex file
341ifdef LOCAL_DEX_PREOPT
342$(built_odex) : $(my_prebuilt_src_file)
343 $(call dexpreopt-one-file,$<,$@)
344endif
345
Ying Wang00fe5872014-07-23 14:35:40 -0700346###############################
347## Install split apks.
348ifdef LOCAL_PACKAGE_SPLITS
349# LOCAL_PACKAGE_SPLITS is a list of apks to be installed.
350built_apk_splits := $(addprefix $(built_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
351installed_apk_splits := $(addprefix $(my_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
352
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800353# Rules to sign the split apks.
Ying Wang00fe5872014-07-23 14:35:40 -0700354my_src_dir := $(sort $(dir $(LOCAL_PACKAGE_SPLITS)))
355ifneq (1,$(words $(my_src_dir)))
356$(error You must put all the split source apks in the same folder: $(LOCAL_PACKAGE_SPLITS))
357endif
358my_src_dir := $(LOCAL_PATH)/$(my_src_dir)
359
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900360$(built_apk_splits) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
Ying Wang00fe5872014-07-23 14:35:40 -0700361$(built_apk_splits) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
362$(built_apk_splits) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
Alex Klyubin1b391c02016-12-15 12:51:25 -0800363$(built_apk_splits) : $(built_module_path)/%.apk : $(my_src_dir)/%.apk
Ying Wang00fe5872014-07-23 14:35:40 -0700364 $(copy-file-to-new-target)
365 $(sign-package)
Ying Wang00fe5872014-07-23 14:35:40 -0700366
367# Rules to install the split apks.
Dan Willemsen7f016152016-02-29 17:52:39 -0800368$(installed_apk_splits) : $(my_module_path)/%.apk : $(built_module_path)/%.apk
Ying Wang00fe5872014-07-23 14:35:40 -0700369 @echo "Install: $@"
370 $(copy-file-to-new-target)
371
372# Register the additional built and installed files.
373ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
374ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
375 $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(built_module_path)/$(notdir $(s)):$(my_module_path)/$(notdir $(s)))
376
377# Make sure to install the splits when you run "make <module_name>".
Colin Cross33886702016-09-20 16:01:28 -0700378$(my_all_targets): $(installed_apk_splits)
Ying Wang00fe5872014-07-23 14:35:40 -0700379
380endif # LOCAL_PACKAGE_SPLITS
381
Colin Crosse18cb932014-02-13 15:04:18 -0800382else # LOCAL_MODULE_CLASS != APPS
Ying Wang3a61eeb2016-03-11 10:32:01 -0800383ifeq ($(prebuilt_module_is_dex_javalib),true)
384# This is a target shared library, i.e. a jar with classes.dex.
385#######################################
386# defines built_odex along with rule to install odex
387include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
388#######################################
389ifdef LOCAL_DEX_PREOPT
390ifneq ($(dexpreopt_boot_jar_module),) # boot jar
391# boot jar's rules are defined in dex_preopt.mk
392dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar
Ying Wangc9a19772016-03-15 14:40:33 -0700393$(built_module) : $(dexpreopted_boot_jar)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800394 $(call copy-file-to-target)
Dan Willemsen08420cb2016-03-01 22:04:57 -0800395
Ying Wang3a61eeb2016-03-11 10:32:01 -0800396# For libart boot jars, we don't have .odex files.
397else # ! boot jar
398$(built_odex): PRIVATE_MODULE := $(LOCAL_MODULE)
399# Use pattern rule - we may have multiple built odex files.
400$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(my_prebuilt_src_file)
401 @echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
402 $(call dexpreopt-one-file,$<,$@)
403
Ying Wangc9a19772016-03-15 14:40:33 -0700404$(built_module) : $(my_prebuilt_src_file)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800405 $(call copy-file-to-target)
406ifneq (nostripping,$(LOCAL_DEX_PREOPT))
407 $(call dexpreopt-remove-classes.dex,$@)
408endif
409endif # boot jar
410else # ! LOCAL_DEX_PREOPT
Ying Wangc9a19772016-03-15 14:40:33 -0700411$(built_module) : $(my_prebuilt_src_file)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800412 $(call copy-file-to-target)
413endif # LOCAL_DEX_PREOPT
414
415else # ! prebuilt_module_is_dex_javalib
Colin Crosse18cb932014-02-13 15:04:18 -0800416$(built_module) : $(my_prebuilt_src_file)
Dan Willemsen08420cb2016-03-01 22:04:57 -0800417ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
Colin Crosse18cb932014-02-13 15:04:18 -0800418 $(transform-prebuilt-to-target-strip-comments)
419else
Colin Crosse18cb932014-02-13 15:04:18 -0800420 $(transform-prebuilt-to-target)
Colin Crosse18cb932014-02-13 15:04:18 -0800421endif
Dan Willemsen7fe992c2016-03-02 13:54:51 -0800422ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
Dan Willemsen08420cb2016-03-01 22:04:57 -0800423 $(hide) chmod +x $@
424endif
Ying Wang3a61eeb2016-03-11 10:32:01 -0800425endif # ! prebuilt_module_is_dex_javalib
Colin Crosse18cb932014-02-13 15:04:18 -0800426endif # LOCAL_MODULE_CLASS != APPS
427
Ying Wang8c89b4b2016-02-22 15:54:27 -0800428ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
429my_src_jar := $(my_prebuilt_src_file)
Colin Cross941b6822017-03-29 13:53:29 -0700430
431ifdef LOCAL_IS_HOST_MODULE
432# for host java libraries deps should be in the common dir, so we make a copy in
433# the common dir.
434common_classes_jar := $(intermediates.COMMON)/classes.jar
435common_javalib_jar := $(intermediates.COMMON)/javalib.jar
436
437$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
438
439$(common_classes_jar) : $(my_src_jar)
440 $(transform-prebuilt-to-target)
441
442$(common_javalib_jar) : $(common_classes_jar)
443 $(transform-prebuilt-to-target)
444
445else # !LOCAL_IS_HOST_MODULE
Colin Crosse18cb932014-02-13 15:04:18 -0800446# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
447# while the deps should be in the common dir, so we make a copy in the common dir.
Ying Wange9dd9f22014-10-29 15:48:32 -0700448common_classes_jar := $(intermediates.COMMON)/classes.jar
Colin Cross950f1ef2017-04-05 15:30:42 -0700449common_classes_pre_proguard_jar := $(intermediates.COMMON)/classes-pre-proguard.jar
Ying Wange9dd9f22014-10-29 15:48:32 -0700450common_javalib_jar := $(intermediates.COMMON)/javalib.jar
Colin Crosse18cb932014-02-13 15:04:18 -0800451
Ying Wange9dd9f22014-10-29 15:48:32 -0700452$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
453
Dan Willemsen62dfb592016-07-08 21:33:05 -0700454my_link_type := $(intermediates.COMMON)/link_type
455ifeq ($(LOCAL_SDK_VERSION),system_current)
Dan Willemsen121e2842016-09-14 21:38:29 -0700456$(my_link_type): PRIVATE_LINK_TYPE := java:system
Dan Willemsen62dfb592016-07-08 21:33:05 -0700457else ifneq ($(LOCAL_SDK_VERSION),)
Dan Willemsen121e2842016-09-14 21:38:29 -0700458$(my_link_type): PRIVATE_LINK_TYPE := java:sdk
Dan Willemsen62dfb592016-07-08 21:33:05 -0700459else
Dan Willemsen121e2842016-09-14 21:38:29 -0700460$(my_link_type): PRIVATE_LINK_TYPE := java:platform
Dan Willemsen62dfb592016-07-08 21:33:05 -0700461endif
Dan Willemsen121e2842016-09-14 21:38:29 -0700462$(eval $(call link-type-partitions,$(my_link_type)))
Dan Willemsen62dfb592016-07-08 21:33:05 -0700463$(my_link_type):
464 @echo Check module type: $@
465 $(hide) mkdir -p $(dir $@) && rm -f $@
Dan Willemsen121e2842016-09-14 21:38:29 -0700466 $(hide) echo "$(PRIVATE_LINK_TYPE)" >$@
Dan Willemsen62dfb592016-07-08 21:33:05 -0700467$(LOCAL_BUILT_MODULE): $(my_link_type)
468
Ying Wang3a61eeb2016-03-11 10:32:01 -0800469ifeq ($(prebuilt_module_is_dex_javalib),true)
470# For prebuilt shared Java library we don't have classes.jar.
Ying Wangc9a19772016-03-15 14:40:33 -0700471$(common_javalib_jar) : $(my_src_jar)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800472 $(transform-prebuilt-to-target)
473
474else # ! prebuilt_module_is_dex_javalib
475
Ying Wangdd71c852015-12-04 13:59:18 -0800476my_src_aar := $(filter %.aar, $(my_prebuilt_src_file))
477ifneq ($(my_src_aar),)
Ying Wange9dd9f22014-10-29 15:48:32 -0700478# This is .aar file, archive of classes.jar and Android resources.
479my_src_jar := $(intermediates.COMMON)/aar/classes.jar
480
Ying Wangdd71c852015-12-04 13:59:18 -0800481$(my_src_jar) : $(my_src_aar)
Ying Wange9dd9f22014-10-29 15:48:32 -0700482 $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
483 $(hide) unzip -qo -d $(dir $@) $<
484 # Make sure the extracted classes.jar has a new timestamp.
485 $(hide) touch $@
486
Ying Wange9dd9f22014-10-29 15:48:32 -0700487endif
Ying Wang3a61eeb2016-03-11 10:32:01 -0800488
Dan Willemsen7f016152016-02-29 17:52:39 -0800489$(common_classes_jar) : $(my_src_jar)
Colin Crosse18cb932014-02-13 15:04:18 -0800490 $(transform-prebuilt-to-target)
491
Colin Cross950f1ef2017-04-05 15:30:42 -0700492$(common_classes_pre_proguard_jar) : $(my_src_jar)
493 $(transform-prebuilt-to-target)
494
Dan Willemsen7f016152016-02-29 17:52:39 -0800495$(common_javalib_jar) : $(common_classes_jar)
Colin Crosse18cb932014-02-13 15:04:18 -0800496 $(transform-prebuilt-to-target)
497
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +0900498$(call define-jar-to-toc-rule, $(common_classes_jar))
499
Ying Wange295c3d2016-02-24 14:11:55 -0800500ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800501ifneq ($(my_src_aar),)
Ying Wange295c3d2016-02-24 14:11:55 -0800502my_res_package := $(intermediates.COMMON)/package-res.apk
503
504# We needed only very few PRIVATE variables and aapt2.mk input variables. Reset the unnecessary ones.
505$(my_res_package): PRIVATE_AAPT2_CFLAGS :=
506$(my_res_package): PRIVATE_ANDROID_MANIFEST := $(intermediates.COMMON)/aar/AndroidManifest.xml
507$(my_res_package): PRIVATE_AAPT_INCLUDES :=
508$(my_res_package): PRIVATE_SOURCE_INTERMEDIATES_DIR :=
509$(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE :=
510$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK :=
511$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK :=
Adam Lesinskie758f932016-02-26 11:13:43 -0800512$(my_res_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
513$(my_res_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
514$(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS :=
Ying Wange295c3d2016-02-24 14:11:55 -0800515
516full_android_manifest :=
517my_res_resources :=
518my_overlay_resources :=
Ying Wange295c3d2016-02-24 14:11:55 -0800519my_compiled_res_base_dir :=
520R_file_stamp :=
521proguard_options_file :=
522my_generated_res_dirs := $(intermediates.COMMON)/aar/res
523my_generated_res_dirs_deps := $(my_src_jar)
524include $(BUILD_SYSTEM)/aapt2.mk
525
526# Make sure my_res_package is created when you run mm/mmm.
527$(built_module) : $(my_res_package)
Ying Wangdd71c852015-12-04 13:59:18 -0800528endif # $(my_src_aar)
Ying Wange295c3d2016-02-24 14:11:55 -0800529endif # LOCAL_USE_AAPT2
Colin Crosse18cb932014-02-13 15:04:18 -0800530# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
531$(built_module) : $(common_javalib_jar)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800532
533endif # ! prebuilt_module_is_dex_javalib
Ying Wang8c89b4b2016-02-22 15:54:27 -0800534endif # LOCAL_IS_HOST_MODULE is not set
Yohann Rousseld87cc992016-01-19 16:08:34 +0100535
Ying Wang3a61eeb2016-03-11 10:32:01 -0800536ifneq ($(prebuilt_module_is_dex_javalib),true)
Yohann Rousseld87cc992016-01-19 16:08:34 +0100537
Colin Cross941b6822017-03-29 13:53:29 -0700538ifdef LOCAL_JACK_ENABLED
Ying Wang8c89b4b2016-02-22 15:54:27 -0800539# We may be building classes.jack from a host jar for host dalvik Java library.
Yohann Rousseld87cc992016-01-19 16:08:34 +0100540$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_FLAGS:=$(LOCAL_JACK_FLAGS)
Yohann Roussel5960c542016-08-19 18:57:34 +0200541$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_MIN_SDK_VERSION := $(if $(strip $(LOCAL_MIN_SDK_VERSION)),$(LOCAL_MIN_SDK_VERSION),1)
Yohann Roussel53b7fbb2016-08-05 17:45:10 +0200542$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_PLUGIN_PATH := $(LOCAL_JACK_PLUGIN_PATH)
Yohann Roussel16243bd2016-09-19 17:49:03 +0200543$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_PLUGIN := $(LOCAL_JACK_PLUGIN)
Yohann Roussel53b7fbb2016-08-05 17:45:10 +0200544$(intermediates.COMMON)/classes.jack : $(LOCAL_JACK_PLUGIN_PATH) $(my_src_jar) \
Shinichiro Hamaji4eaeef82016-04-07 18:56:42 +0900545 $(LOCAL_ADDITIONAL_DEPENDENCIES) $(JACK_DEFAULT_ARGS) $(JACK) \
546 | setup-jack-server
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200547 $(transform-jar-to-jack)
548
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +0900549# Update timestamps of .toc files for prebuilts so dependents will be
550# always rebuilt.
551$(intermediates.COMMON)/classes.dex.toc: $(intermediates.COMMON)/classes.jack
552 touch $@
Colin Cross941b6822017-03-29 13:53:29 -0700553endif # LOCAL_JACK_ENABLED
Ying Wang3a61eeb2016-03-11 10:32:01 -0800554endif # ! prebuilt_module_is_dex_javalib
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200555endif # JAVA_LIBRARIES
556
Dan Willemsen1c6dc5b2016-01-06 14:28:36 -0800557$(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES)
Colin Crosse18cb932014-02-13 15:04:18 -0800558
559my_prebuilt_src_file :=