blob: 2b7a92063d0d749d93e49b27570ef8810ca76e56 [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))
Dan Willemsen9d2b3282017-04-07 20:58:43 -070082 ifeq ($(prebuilt_module_is_a_library),true)
83 SOONG_ALREADY_CONV := $(SOONG_ALREADY_CONV) $(LOCAL_MODULE)
84 endif
85
86 ifdef LOCAL_USE_VNDK
Jiyong Parka9c4c712017-07-18 13:35:27 +090087 name_without_suffix := $(patsubst %.vendor,%,$(LOCAL_MODULE))
88 ifneq ($(name_without_suffix),$(LOCAL_MODULE)
89 SPLIT_VENDOR.$(LOCAL_MODULE_CLASS).$(name_without_suffix) := 1
90 endif
91 name_without_suffix :=
Dan Willemsen9d2b3282017-04-07 20:58:43 -070092 endif
Dan Willemsenfc92fb22016-08-26 13:27:13 -070093endif
94
Colin Crosse18cb932014-02-13 15:04:18 -080095# Don't install static libraries by default.
96ifndef LOCAL_UNINSTALLABLE_MODULE
97ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS))
98 LOCAL_UNINSTALLABLE_MODULE := true
99endif
100endif
101
Ying Wang09c306c2016-03-15 16:36:29 -0700102ifeq (JAVA_LIBRARIES,$(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS)$(filter true,$(LOCAL_UNINSTALLABLE_MODULE)))
103 prebuilt_module_is_dex_javalib := true
104else
105 prebuilt_module_is_dex_javalib :=
106endif
107
Ying Wangaf9757e2014-07-17 21:24:42 -0700108ifeq ($(LOCAL_MODULE_CLASS),APPS)
109LOCAL_BUILT_MODULE_STEM := package.apk
Dan Willemsendc1ddfc2016-08-05 17:23:33 -0700110ifndef LOCAL_INSTALLED_MODULE_STEM
Ying Wangaf9757e2014-07-17 21:24:42 -0700111LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
112endif
Dan Willemsendc1ddfc2016-08-05 17:23:33 -0700113endif
Ying Wangaf9757e2014-07-17 21:24:42 -0700114
Dan Willemsen4598fbc2016-07-13 16:08:36 -0700115ifneq ($(filter true keep_symbols no_debuglink mini-debug-info,$(my_strip_module) $(my_pack_module_relocations)),)
Colin Crosse18cb932014-02-13 15:04:18 -0800116 ifdef LOCAL_IS_HOST_MODULE
Dmitriy Ivanov64762c32015-04-24 15:33:14 -0700117 $(error Cannot strip/pack host module LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -0800118 endif
Dan Willemsen7fe992c2016-03-02 13:54:51 -0800119 ifeq ($(filter SHARED_LIBRARIES EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -0700120 $(error Can strip/pack only shared libraries or executables LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -0800121 endif
122 ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -0700123 $(error Cannot strip/pack scripts LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -0800124 endif
Ying Wangb6eb8dd2016-03-01 20:14:52 -0800125 # Set the arch-specific variables to set up the strip/pack rules.
126 LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) := $(my_strip_module)
127 LOCAL_PACK_MODULE_RELOCATIONS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) := $(my_pack_module_relocations)
Colin Crosse18cb932014-02-13 15:04:18 -0800128 include $(BUILD_SYSTEM)/dynamic_binary.mk
129 built_module := $(linked_module)
Ying Wangbfb52a22014-08-20 17:12:32 -0700130
Ying Wangb6eb8dd2016-03-01 20:14:52 -0800131else # my_strip_module and my_pack_module_relocations not true
Colin Crosse18cb932014-02-13 15:04:18 -0800132 include $(BUILD_SYSTEM)/base_rules.mk
133 built_module := $(LOCAL_BUILT_MODULE)
134
135ifdef prebuilt_module_is_a_library
136export_includes := $(intermediates)/export_includes
Dan Willemsen05909fa2017-03-19 13:22:45 -0700137export_cflags := $(foreach d,$(LOCAL_EXPORT_C_INCLUDE_DIRS),-I $(d))
138# Soong exports cflags instead of include dirs, so that -isystem can be included.
139ifeq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
140export_cflags += $(LOCAL_EXPORT_CFLAGS)
141else ifdef LOCAL_EXPORT_CFLAGS
142$(call pretty-error,LOCAL_EXPORT_CFLAGS can only be used by Soong, use LOCAL_EXPORT_C_INCLUDE_DIRS instead)
143endif
144$(export_includes): PRIVATE_EXPORT_CFLAGS := $(export_cflags)
Dan Willemsenba6a1642016-09-29 12:08:29 -0700145$(export_includes): $(LOCAL_EXPORT_C_INCLUDE_DEPS)
Colin Crosse18cb932014-02-13 15:04:18 -0800146 @echo Export includes file: $< -- $@
147 $(hide) mkdir -p $(dir $@) && rm -f $@
Dan Willemsen05909fa2017-03-19 13:22:45 -0700148ifdef export_cflags
149 $(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >$@
Colin Crosse18cb932014-02-13 15:04:18 -0800150else
151 $(hide) touch $@
152endif
Dan Willemsen05909fa2017-03-19 13:22:45 -0700153export_cflags :=
Colin Crosse18cb932014-02-13 15:04:18 -0800154
Dan Willemsen9d2b3282017-04-07 20:58:43 -0700155ifdef LOCAL_SDK_VERSION
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700156my_link_type := native:ndk
Dan Willemsen9d2b3282017-04-07 20:58:43 -0700157else ifdef LOCAL_USE_VNDK
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700158my_link_type := native:vendor
Dan Willemsen9d2b3282017-04-07 20:58:43 -0700159else
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700160my_link_type := native:platform
Dan Willemsen9d2b3282017-04-07 20:58:43 -0700161endif
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700162
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700163# TODO: check dependencies of prebuilt files
164my_link_deps :=
165
166my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
167my_common :=
168include $(BUILD_SYSTEM)/link_type.mk
Colin Crosse18cb932014-02-13 15:04:18 -0800169endif # prebuilt_module_is_a_library
170
171# The real dependency will be added after all Android.mks are loaded and the install paths
172# of the shared libraries are determined.
173ifdef LOCAL_INSTALLED_MODULE
174ifdef LOCAL_SHARED_LIBRARIES
Ying Wang7c877392014-10-07 13:03:29 -0700175my_shared_libraries := $(LOCAL_SHARED_LIBRARIES)
176# Extra shared libraries introduced by LOCAL_CXX_STL.
177include $(BUILD_SYSTEM)/cxx_stl_setup.mk
Dan Willemsen9d2b3282017-04-07 20:58:43 -0700178ifdef LOCAL_USE_VNDK
Jiyong Parka9c4c712017-07-18 13:35:27 +0900179 ifneq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
Dan Willemsen9d2b3282017-04-07 20:58:43 -0700180 my_shared_libraries := $(foreach l,$(my_shared_libraries),\
181 $(if $(SPLIT_VENDOR.SHARED_LIBRARIES.$(l)),$(l).vendor,$(l)))
182 endif
183endif
Ying Wang58f462f2014-02-25 18:26:29 -0800184$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
Ying Wang7c877392014-10-07 13:03:29 -0700185 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries))
Colin Crosse18cb932014-02-13 15:04:18 -0800186
187# We also need the LOCAL_BUILT_MODULE dependency,
188# since we use -rpath-link which points to the built module's path.
Ying Wang7c877392014-10-07 13:03:29 -0700189my_built_shared_libraries := \
Ying Wang58f462f2014-02-25 18:26:29 -0800190 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
Colin Crosse18cb932014-02-13 15:04:18 -0800191 $(addsuffix $($(my_prefix)SHLIB_SUFFIX), \
Ying Wang7c877392014-10-07 13:03:29 -0700192 $(my_shared_libraries)))
193$(LOCAL_BUILT_MODULE) : $(my_built_shared_libraries)
Colin Crosse18cb932014-02-13 15:04:18 -0800194endif
195endif
196
Ying Wang7c877392014-10-07 13:03:29 -0700197# We need to enclose the above export_includes and my_built_shared_libraries in
Ying Wangb6eb8dd2016-03-01 20:14:52 -0800198# "my_strip_module not true" because otherwise the rules are defined in dynamic_binary.mk.
199endif # my_strip_module not true
Colin Crosse18cb932014-02-13 15:04:18 -0800200
Dan Willemsen9f956652016-10-21 15:04:12 -0700201ifeq ($(NATIVE_COVERAGE),true)
Dan Willemsen0f909082017-02-10 00:07:17 -0800202ifneq (,$(strip $(LOCAL_PREBUILT_COVERAGE_ARCHIVE)))
203 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(intermediates)/$(LOCAL_MODULE).gcnodir))
204 ifneq ($(LOCAL_UNINSTALLABLE_MODULE),true)
205 ifdef LOCAL_IS_HOST_MODULE
206 my_coverage_path := $($(my_prefix)OUT_COVERAGE)/$(patsubst $($(my_prefix)OUT)/%,%,$(my_module_path))
207 else
208 my_coverage_path := $(TARGET_OUT_COVERAGE)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
209 endif
210 my_coverage_path := $(my_coverage_path)/$(basename $(my_installed_module_stem)).gcnodir
211 $(eval $(call copy-one-file,$(LOCAL_PREBUILT_COVERAGE_ARCHIVE),$(my_coverage_path)))
212 $(LOCAL_BUILT_MODULE): $(my_coverage_path)
213 endif
214else
Ryan Campbell81c9d292016-09-12 13:56:50 -0700215# Coverage information is needed when static lib is a dependency of another
216# coverage-enabled module.
217ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS))
218GCNO_ARCHIVE := $(LOCAL_MODULE).gcnodir
219$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS :=
220$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES :=
Dan Willemsen9f956652016-10-21 15:04:12 -0700221$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_PREFIX := $(my_prefix)
222$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_2ND_ARCH_VAR_PREFIX := $(LOCAL_2ND_ARCH_VAR_PREFIX)
Ryan Campbell81c9d292016-09-12 13:56:50 -0700223$(intermediates)/$(GCNO_ARCHIVE) :
224 $(transform-o-to-static-lib)
225endif
Dan Willemsen9f956652016-10-21 15:04:12 -0700226endif
Dan Willemsen0f909082017-02-10 00:07:17 -0800227endif
Ryan Campbell81c9d292016-09-12 13:56:50 -0700228
Ying Wangf0534c22014-04-15 11:12:21 -0700229ifeq ($(LOCAL_MODULE_CLASS),APPS)
Colin Crosse18cb932014-02-13 15:04:18 -0800230PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
231
Dan Willemsen048f56d2016-06-18 20:43:51 -0700232my_extract_apk := $(strip $(LOCAL_EXTRACT_APK))
233
Ying Wang43f7a322014-11-17 16:56:04 -0800234# Select dpi-specific source
235ifdef LOCAL_DPI_VARIANTS
Ying Wang60686582014-12-10 12:40:09 -0800236my_dpi := $(firstword $(filter $(LOCAL_DPI_VARIANTS),$(PRODUCT_AAPT_PREF_CONFIG) $(PRODUCT_AAPT_PREBUILT_DPI)))
Ying Wang43f7a322014-11-17 16:56:04 -0800237ifdef my_dpi
238ifdef LOCAL_DPI_FILE_STEM
239my_prebuilt_dpi_file_stem := $(LOCAL_DPI_FILE_STEM)
240else
241my_prebuilt_dpi_file_stem := $(LOCAL_MODULE)_%.apk
242endif
243my_prebuilt_src_file := $(dir $(my_prebuilt_src_file))$(subst %,$(my_dpi),$(my_prebuilt_dpi_file_stem))
Dan Willemsen048f56d2016-06-18 20:43:51 -0700244
245ifneq ($(strip $(LOCAL_EXTRACT_DPI_APK)),)
246my_extract_apk := $(subst %,$(my_dpi),$(LOCAL_EXTRACT_DPI_APK))
247endif # LOCAL_EXTRACT_DPI_APK
Ying Wang43f7a322014-11-17 16:56:04 -0800248endif # my_dpi
249endif # LOCAL_DPI_VARIANTS
250
Dan Willemsen048f56d2016-06-18 20:43:51 -0700251ifdef my_extract_apk
252my_extracted_apk := $(intermediates)/extracted.apk
253
254$(my_extracted_apk): PRIVATE_EXTRACT := $(my_extract_apk)
255$(my_extracted_apk): $(my_prebuilt_src_file)
256 @echo Extract APK: $@
257 $(hide) mkdir -p $(dir $@) && rm -f $@
258 $(hide) unzip -p $< $(PRIVATE_EXTRACT) >$@
259
260my_prebuilt_src_file := $(my_extracted_apk)
261my_extracted_apk :=
262my_extract_apk :=
263endif
264
Ying Wang96bcad42014-04-17 13:38:04 -0700265rs_compatibility_jni_libs :=
266include $(BUILD_SYSTEM)/install_jni_libs.mk
267
Colin Crosse18cb932014-02-13 15:04:18 -0800268ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
269 # The magic string "EXTERNAL" means this package will be signed with
270 # the default dev key throughout the build process, but we expect
271 # the final package to be signed with a different key.
272 #
273 # This can be used for packages where we don't have access to the
274 # keys, but want the package to be predexopt'ed.
275 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
276 PACKAGES.$(LOCAL_MODULE).EXTERNAL_KEY := 1
277
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900278 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
Colin Crosse18cb932014-02-13 15:04:18 -0800279 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
280 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
281endif
282ifeq ($(LOCAL_CERTIFICATE),)
Ying Wangf0534c22014-04-15 11:12:21 -0700283 # It is now a build error to add a prebuilt .apk without
284 # specifying a key for it.
285 $(error No LOCAL_CERTIFICATE specified for prebuilt "$(my_prebuilt_src_file)")
Colin Crosse18cb932014-02-13 15:04:18 -0800286else ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
287 # The magic string "PRESIGNED" means this package is already checked
288 # signed with its release key.
289 #
290 # By setting .CERTIFICATE but not .PRIVATE_KEY, this package will be
291 # mentioned in apkcerts.txt (with certificate set to "PRESIGNED")
292 # but the dexpreopt process will not try to re-sign the app.
293 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := PRESIGNED
294 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
295else
296 # If this is not an absolute certificate, assign it to a generic one.
297 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
298 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
299 endif
300
301 PACKAGES.$(LOCAL_MODULE).PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
302 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
303 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
304
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900305 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
Colin Crosse18cb932014-02-13 15:04:18 -0800306 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
307 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
308endif
309
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700310# Disable dex-preopt of prebuilts to save space, if requested.
Ying Wang09c306c2016-03-15 16:36:29 -0700311ifndef LOCAL_DEX_PREOPT
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700312ifeq ($(DONT_DEXPREOPT_PREBUILTS),true)
Colin Crosse18cb932014-02-13 15:04:18 -0800313LOCAL_DEX_PREOPT := false
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700314endif
Ying Wang09c306c2016-03-15 16:36:29 -0700315endif
Colin Crosse18cb932014-02-13 15:04:18 -0800316
317#######################################
318# defines built_odex along with rule to install odex
319include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
320#######################################
Ying Wang09c306c2016-03-15 16:36:29 -0700321ifneq ($(LOCAL_REPLACE_PREBUILT_APK_INSTALLED),)
322# There is a replacement for the prebuilt .apk we can install without any processing.
323$(built_module) : $(LOCAL_REPLACE_PREBUILT_APK_INSTALLED)
324 $(transform-prebuilt-to-target)
Ying Wangb7d33c02016-03-15 16:28:57 -0700325
Ying Wang09c306c2016-03-15 16:36:29 -0700326else # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
327# Sign and align non-presigned .apks.
Ying Wang1fb01522015-05-01 14:02:26 -0700328# The embedded prebuilt jni to uncompress.
Ying Wang226eb922015-06-01 19:19:57 -0700329ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
330# For PRESIGNED apks we must uncompress every .so file:
331# even if the .so file isn't for the current TARGET_ARCH,
332# we can't strip the file.
333embedded_prebuilt_jni_libs := 'lib/*.so'
334endif
Ying Wang1fb01522015-05-01 14:02:26 -0700335ifndef embedded_prebuilt_jni_libs
336# No LOCAL_PREBUILT_JNI_LIBS, uncompress all.
337embedded_prebuilt_jni_libs := 'lib/*.so'
338endif
339$(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
340
Alex Klyubin1b391c02016-12-15 12:51:25 -0800341$(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(SIGNAPK_JAR)
Colin Crosse18cb932014-02-13 15:04:18 -0800342 $(transform-prebuilt-to-target)
Ying Wang226eb922015-06-01 19:19:57 -0700343 $(uncompress-shared-libs)
Nicolas Geoffrayb06c30b2017-09-19 11:51:45 +0000344ifneq (true,$(DONT_UNCOMPRESS_PRIV_APPS_DEXS))
345ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
346 $(uncompress-dexs)
Nicolas Geoffraya95fbd12017-09-19 13:10:31 +0100347else
348 ifneq (,$(filter $(PRODUCT_LOADED_BY_PRIVILEGED_MODULES), $(LOCAL_MODULE)))
349 $(uncompress-dexs)
350 endif # PRODUCT_LOADED_BY_PRIVILEGED_MODULES
Nicolas Geoffrayb06c30b2017-09-19 11:51:45 +0000351endif # LOCAL_PRIVILEGED_MODULE
352endif # DONT_UNCOMPRESS_PRIV_APPS_DEXS
Ying Wang09c306c2016-03-15 16:36:29 -0700353ifdef LOCAL_DEX_PREOPT
354ifneq ($(BUILD_PLATFORM_ZIP),)
355 @# Keep a copy of apk with classes.dex unstripped
356 $(hide) cp -f $@ $(dir $@)package.dex.apk
357endif # BUILD_PLATFORM_ZIP
358endif # LOCAL_DEX_PREOPT
Kenny Rootdff37552015-04-15 12:09:32 -0700359ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
360 @# Only strip out files if we can re-sign the package.
Colin Crosse18cb932014-02-13 15:04:18 -0800361ifdef LOCAL_DEX_PREOPT
Ying Wang36142f62014-05-21 16:13:33 -0700362ifneq (nostripping,$(LOCAL_DEX_PREOPT))
363 $(call dexpreopt-remove-classes.dex,$@)
Ying Wang09c306c2016-03-15 16:36:29 -0700364endif # LOCAL_DEX_PREOPT != nostripping
365endif # LOCAL_DEX_PREOPT
Kenny Rootdff37552015-04-15 12:09:32 -0700366 $(sign-package)
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800367 # No need for align-package because sign-package takes care of alignment
Ying Wang09c306c2016-03-15 16:36:29 -0700368else # LOCAL_CERTIFICATE == PRESIGNED
Colin Crosse18cb932014-02-13 15:04:18 -0800369 $(align-package)
Ying Wang09c306c2016-03-15 16:36:29 -0700370endif # LOCAL_CERTIFICATE
371endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
Colin Crosse18cb932014-02-13 15:04:18 -0800372
Ying Wang36142f62014-05-21 16:13:33 -0700373###############################
374## Rule to build the odex file
375ifdef LOCAL_DEX_PREOPT
376$(built_odex) : $(my_prebuilt_src_file)
377 $(call dexpreopt-one-file,$<,$@)
378endif
379
Ying Wang00fe5872014-07-23 14:35:40 -0700380###############################
381## Install split apks.
382ifdef LOCAL_PACKAGE_SPLITS
383# LOCAL_PACKAGE_SPLITS is a list of apks to be installed.
Dan Willemsenf72308a2017-05-15 23:38:04 -0700384built_apk_splits := $(addprefix $(intermediates)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
Ying Wang00fe5872014-07-23 14:35:40 -0700385installed_apk_splits := $(addprefix $(my_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
386
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800387# Rules to sign the split apks.
Ying Wang00fe5872014-07-23 14:35:40 -0700388my_src_dir := $(sort $(dir $(LOCAL_PACKAGE_SPLITS)))
389ifneq (1,$(words $(my_src_dir)))
390$(error You must put all the split source apks in the same folder: $(LOCAL_PACKAGE_SPLITS))
391endif
392my_src_dir := $(LOCAL_PATH)/$(my_src_dir)
393
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900394$(built_apk_splits) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
Ying Wang00fe5872014-07-23 14:35:40 -0700395$(built_apk_splits) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
396$(built_apk_splits) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
Dan Willemsenf72308a2017-05-15 23:38:04 -0700397$(built_apk_splits) : $(intermediates)/%.apk : $(my_src_dir)/%.apk
Ying Wang00fe5872014-07-23 14:35:40 -0700398 $(copy-file-to-new-target)
399 $(sign-package)
Ying Wang00fe5872014-07-23 14:35:40 -0700400
401# Rules to install the split apks.
Dan Willemsenf72308a2017-05-15 23:38:04 -0700402$(installed_apk_splits) : $(my_module_path)/%.apk : $(intermediates)/%.apk
Ying Wang00fe5872014-07-23 14:35:40 -0700403 @echo "Install: $@"
404 $(copy-file-to-new-target)
405
406# Register the additional built and installed files.
407ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
408ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
Dan Willemsenf72308a2017-05-15 23:38:04 -0700409 $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(intermediates)/$(notdir $(s)):$(my_module_path)/$(notdir $(s)))
Ying Wang00fe5872014-07-23 14:35:40 -0700410
411# Make sure to install the splits when you run "make <module_name>".
Colin Cross33886702016-09-20 16:01:28 -0700412$(my_all_targets): $(installed_apk_splits)
Ying Wang00fe5872014-07-23 14:35:40 -0700413
414endif # LOCAL_PACKAGE_SPLITS
415
Ying Wangda366352016-03-15 17:05:52 -0700416else ifeq ($(prebuilt_module_is_dex_javalib),true) # ! LOCAL_MODULE_CLASS != APPS
Ying Wang09c306c2016-03-15 16:36:29 -0700417# This is a target shared library, i.e. a jar with classes.dex.
418#######################################
419# defines built_odex along with rule to install odex
420include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
421#######################################
422ifdef LOCAL_DEX_PREOPT
423ifneq ($(dexpreopt_boot_jar_module),) # boot jar
424# boot jar's rules are defined in dex_preopt.mk
425dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar
426$(built_module) : $(dexpreopted_boot_jar)
427 $(call copy-file-to-target)
Dan Willemsen08420cb2016-03-01 22:04:57 -0800428
Ying Wang09c306c2016-03-15 16:36:29 -0700429# For libart boot jars, we don't have .odex files.
430else # ! boot jar
431$(built_odex): PRIVATE_MODULE := $(LOCAL_MODULE)
432# Use pattern rule - we may have multiple built odex files.
433$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(my_prebuilt_src_file)
434 @echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
435 $(call dexpreopt-one-file,$<,$@)
436
437$(built_module) : $(my_prebuilt_src_file)
438 $(call copy-file-to-target)
439ifneq (nostripping,$(LOCAL_DEX_PREOPT))
440 $(call dexpreopt-remove-classes.dex,$@)
441endif
442endif # boot jar
443else # ! LOCAL_DEX_PREOPT
444$(built_module) : $(my_prebuilt_src_file)
445 $(call copy-file-to-target)
446endif # LOCAL_DEX_PREOPT
447
448else # ! prebuilt_module_is_dex_javalib
Colin Crosse18cb932014-02-13 15:04:18 -0800449$(built_module) : $(my_prebuilt_src_file)
Dan Willemsen08420cb2016-03-01 22:04:57 -0800450ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
Colin Crosse18cb932014-02-13 15:04:18 -0800451 $(transform-prebuilt-to-target-strip-comments)
452else
Colin Crosse18cb932014-02-13 15:04:18 -0800453 $(transform-prebuilt-to-target)
Colin Crosse18cb932014-02-13 15:04:18 -0800454endif
Dan Willemsen7fe992c2016-03-02 13:54:51 -0800455ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
Dan Willemsen08420cb2016-03-01 22:04:57 -0800456 $(hide) chmod +x $@
457endif
Ying Wang09c306c2016-03-15 16:36:29 -0700458endif # ! prebuilt_module_is_dex_javalib
Colin Crosse18cb932014-02-13 15:04:18 -0800459
Ying Wang8c89b4b2016-02-22 15:54:27 -0800460ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
461my_src_jar := $(my_prebuilt_src_file)
Colin Cross941b6822017-03-29 13:53:29 -0700462
463ifdef LOCAL_IS_HOST_MODULE
464# for host java libraries deps should be in the common dir, so we make a copy in
465# the common dir.
466common_classes_jar := $(intermediates.COMMON)/classes.jar
Nan Zhangb3ec5342017-08-31 21:43:04 +0000467common_header_jar := $(intermediates.COMMON)/classes-header.jar
Colin Cross941b6822017-03-29 13:53:29 -0700468
Colin Cross96476c12017-04-06 09:56:19 -0700469$(common_classes_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
Colin Crossd2e778f2017-04-14 15:14:33 -0700470$(common_classes_jar): PRIVATE_PREFIX := $(my_prefix)
Colin Cross941b6822017-03-29 13:53:29 -0700471
472$(common_classes_jar) : $(my_src_jar)
473 $(transform-prebuilt-to-target)
474
Colin Cross7dc90432017-09-26 16:17:24 -0700475ifneq ($(TURBINE_ENABLED),false)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000476$(common_header_jar) : $(my_src_jar)
477 $(transform-prebuilt-to-target)
Colin Cross7dc90432017-09-26 16:17:24 -0700478endif
Nan Zhangb3ec5342017-08-31 21:43:04 +0000479
Colin Cross941b6822017-03-29 13:53:29 -0700480else # !LOCAL_IS_HOST_MODULE
Colin Crosse18cb932014-02-13 15:04:18 -0800481# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
482# 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 -0700483common_classes_jar := $(intermediates.COMMON)/classes.jar
Nan Zhangb3ec5342017-08-31 21:43:04 +0000484common_header_jar := $(intermediates.COMMON)/classes-header.jar
Colin Cross950f1ef2017-04-05 15:30:42 -0700485common_classes_pre_proguard_jar := $(intermediates.COMMON)/classes-pre-proguard.jar
Ying Wange9dd9f22014-10-29 15:48:32 -0700486common_javalib_jar := $(intermediates.COMMON)/javalib.jar
Colin Crosse18cb932014-02-13 15:04:18 -0800487
Colin Crossd2e778f2017-04-14 15:14:33 -0700488$(common_classes_jar) $(common_classes_pre_proguard_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
489$(common_classes_jar) $(common_classes_pre_proguard_jar) $(common_javalib_jar): PRIVATE_PREFIX := $(my_prefix)
Ying Wange9dd9f22014-10-29 15:48:32 -0700490
Dan Willemsen62dfb592016-07-08 21:33:05 -0700491ifeq ($(LOCAL_SDK_VERSION),system_current)
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700492my_link_type := java:system
Dan Willemsen62dfb592016-07-08 21:33:05 -0700493else ifneq ($(LOCAL_SDK_VERSION),)
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700494my_link_type := java:sdk
Dan Willemsen62dfb592016-07-08 21:33:05 -0700495else
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700496my_link_type := java:platform
Dan Willemsen62dfb592016-07-08 21:33:05 -0700497endif
Dan Willemsenb47d4e92017-04-08 00:31:31 -0700498
499# TODO: check dependencies of prebuilt files
500my_link_deps :=
501
502my_2nd_arch_prefix := $(LOCAL_2ND_ARCH_VAR_PREFIX)
503my_common := COMMON
504include $(BUILD_SYSTEM)/link_type.mk
Dan Willemsen62dfb592016-07-08 21:33:05 -0700505
Ying Wang09c306c2016-03-15 16:36:29 -0700506ifeq ($(prebuilt_module_is_dex_javalib),true)
507# For prebuilt shared Java library we don't have classes.jar.
508$(common_javalib_jar) : $(my_src_jar)
509 $(transform-prebuilt-to-target)
510
511else # ! prebuilt_module_is_dex_javalib
512
Ying Wangdd71c852015-12-04 13:59:18 -0800513my_src_aar := $(filter %.aar, $(my_prebuilt_src_file))
514ifneq ($(my_src_aar),)
Ying Wange9dd9f22014-10-29 15:48:32 -0700515# This is .aar file, archive of classes.jar and Android resources.
516my_src_jar := $(intermediates.COMMON)/aar/classes.jar
517
Ying Wangdd71c852015-12-04 13:59:18 -0800518$(my_src_jar) : $(my_src_aar)
Dan Willemsen7a1ad6c2017-04-27 23:10:47 -0700519 $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@) $(dir $@)/res
Ying Wange9dd9f22014-10-29 15:48:32 -0700520 $(hide) unzip -qo -d $(dir $@) $<
521 # Make sure the extracted classes.jar has a new timestamp.
522 $(hide) touch $@
523
Ying Wange9dd9f22014-10-29 15:48:32 -0700524endif
Ying Wang09c306c2016-03-15 16:36:29 -0700525
Dan Willemsen7f016152016-02-29 17:52:39 -0800526$(common_classes_jar) : $(my_src_jar)
Colin Crosse18cb932014-02-13 15:04:18 -0800527 $(transform-prebuilt-to-target)
528
Colin Cross7dc90432017-09-26 16:17:24 -0700529ifneq ($(TURBINE_ENABLED),false)
Nan Zhangb3ec5342017-08-31 21:43:04 +0000530$(common_header_jar) : $(my_src_jar)
531 $(transform-prebuilt-to-target)
Colin Cross7dc90432017-09-26 16:17:24 -0700532endif
Nan Zhangb3ec5342017-08-31 21:43:04 +0000533
Colin Cross950f1ef2017-04-05 15:30:42 -0700534$(common_classes_pre_proguard_jar) : $(my_src_jar)
535 $(transform-prebuilt-to-target)
536
Dan Willemsen7f016152016-02-29 17:52:39 -0800537$(common_javalib_jar) : $(common_classes_jar)
Colin Crosse18cb932014-02-13 15:04:18 -0800538 $(transform-prebuilt-to-target)
539
Ying Wange295c3d2016-02-24 14:11:55 -0800540ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800541ifneq ($(my_src_aar),)
Dan Willemsen470e0e12017-04-27 22:28:06 -0700542LOCAL_SDK_RES_VERSION:=$(strip $(LOCAL_SDK_RES_VERSION))
543ifeq ($(LOCAL_SDK_RES_VERSION),)
544 LOCAL_SDK_RES_VERSION:=$(LOCAL_SDK_VERSION)
545endif
546
547framework_res_package_export :=
548framework_res_package_export_deps :=
549# Please refer to package.mk
550ifneq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
551ifneq ($(filter-out current system_current test_current,$(LOCAL_SDK_RES_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current test_current,$(LOCAL_SDK_RES_VERSION))),)
552framework_res_package_export := \
553 $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_RES_VERSION)/android.jar
554framework_res_package_export_deps := $(framework_res_package_export)
555else
556framework_res_package_export := \
557 $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
558framework_res_package_export_deps := \
559 $(dir $(framework_res_package_export))src/R.stamp
560endif
561endif
562
Ying Wange295c3d2016-02-24 14:11:55 -0800563my_res_package := $(intermediates.COMMON)/package-res.apk
564
565# We needed only very few PRIVATE variables and aapt2.mk input variables. Reset the unnecessary ones.
566$(my_res_package): PRIVATE_AAPT2_CFLAGS :=
Dan Willemsen7a1ad6c2017-04-27 23:10:47 -0700567$(my_res_package): PRIVATE_AAPT_FLAGS := --static-lib --no-static-lib-packages
Ying Wange295c3d2016-02-24 14:11:55 -0800568$(my_res_package): PRIVATE_ANDROID_MANIFEST := $(intermediates.COMMON)/aar/AndroidManifest.xml
Dan Willemsen470e0e12017-04-27 22:28:06 -0700569$(my_res_package): PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
Ying Wange295c3d2016-02-24 14:11:55 -0800570$(my_res_package): PRIVATE_SOURCE_INTERMEDIATES_DIR :=
571$(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE :=
572$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK :=
573$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK :=
Adam Lesinskie758f932016-02-26 11:13:43 -0800574$(my_res_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
575$(my_res_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
576$(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS :=
Dan Willemsen470e0e12017-04-27 22:28:06 -0700577$(my_res_package) : $(framework_res_package_export_deps)
Ying Wange295c3d2016-02-24 14:11:55 -0800578
579full_android_manifest :=
580my_res_resources :=
581my_overlay_resources :=
Dan Willemsen48845252017-04-27 21:25:34 -0700582my_compiled_res_base_dir := $(intermediates.COMMON)/flat-res
Ying Wange295c3d2016-02-24 14:11:55 -0800583R_file_stamp :=
584proguard_options_file :=
585my_generated_res_dirs := $(intermediates.COMMON)/aar/res
586my_generated_res_dirs_deps := $(my_src_jar)
587include $(BUILD_SYSTEM)/aapt2.mk
588
589# Make sure my_res_package is created when you run mm/mmm.
590$(built_module) : $(my_res_package)
Ying Wangdd71c852015-12-04 13:59:18 -0800591endif # $(my_src_aar)
Ying Wange295c3d2016-02-24 14:11:55 -0800592endif # LOCAL_USE_AAPT2
Colin Crosse18cb932014-02-13 15:04:18 -0800593# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
594$(built_module) : $(common_javalib_jar)
Ying Wang09c306c2016-03-15 16:36:29 -0700595
596endif # ! prebuilt_module_is_dex_javalib
Ying Wang8c89b4b2016-02-22 15:54:27 -0800597endif # LOCAL_IS_HOST_MODULE is not set
Yohann Rousseld87cc992016-01-19 16:08:34 +0100598
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200599endif # JAVA_LIBRARIES
600
Dan Willemsen1c6dc5b2016-01-06 14:28:36 -0800601$(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES)
Colin Crosse18cb932014-02-13 15:04:18 -0800602
603my_prebuilt_src_file :=