blob: c31a07ec507216050746600760db80590dc0d78b [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
19# Not much sense to check build prebuilts
20LOCAL_DONT_CHECK_MODULE := true
21
Ying Wang34d5f1b2014-05-16 10:38:43 -070022my_32_64_bit_suffix := $(if $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)IS_64_BIT),64,32)
23
Colin Crosse18cb932014-02-13 15:04:18 -080024ifdef LOCAL_PREBUILT_MODULE_FILE
Ying Wangc0adfb72014-02-27 14:10:53 -080025 my_prebuilt_src_file := $(LOCAL_PREBUILT_MODULE_FILE)
Colin Crosse18cb932014-02-13 15:04:18 -080026else
Ying Wang6feb6d52014-04-17 10:03:35 -070027 ifdef LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)
28 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH))
Dan Willemsen5709bd52016-02-01 21:40:17 -080029 LOCAL_SRC_FILES_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) :=
Ying Wangc0adfb72014-02-27 14:10:53 -080030 else
Ying Wang34d5f1b2014-05-16 10:38:43 -070031 ifdef LOCAL_SRC_FILES_$(my_32_64_bit_suffix)
32 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES_$(my_32_64_bit_suffix))
Dan Willemsen3bb168f2016-01-19 20:07:08 -080033 LOCAL_SRC_FILES_$(my_32_64_bit_suffix) :=
Ying Wang34d5f1b2014-05-16 10:38:43 -070034 else
35 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
Dan Willemsen3bb168f2016-01-19 20:07:08 -080036 LOCAL_SRC_FILES :=
Ying Wang34d5f1b2014-05-16 10:38:43 -070037 endif
Ying Wangc0adfb72014-02-27 14:10:53 -080038 endif
Colin Crosse18cb932014-02-13 15:04:18 -080039endif
40
Ying Wangb6eb8dd2016-03-01 20:14:52 -080041my_strip_module := $(firstword \
42 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
43 $(LOCAL_STRIP_MODULE))
44my_pack_module_relocations := $(firstword \
45 $(LOCAL_PACK_MODULE_RELOCATIONS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
46 $(LOCAL_PACK_MODULE_RELOCATIONS))
47
Colin Crosse18cb932014-02-13 15:04:18 -080048ifeq (SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS))
Dan Albert4ac42312016-07-20 11:02:18 -070049 # LOCAL_COPY_TO_INTERMEDIATE_LIBRARIES indicates that this prebuilt should be
50 # installed to the common directory of libraries. This is needed for the NDK
51 # shared libraries built by soong, as we build many different versions of each
52 # library (one for each API level). Since they all have the same basename,
53 # they'd clobber each other (as well as any platform libraries by the same
54 # name).
55 ifneq ($(LOCAL_COPY_TO_INTERMEDIATE_LIBRARIES),false)
56 # Put the built targets of all shared libraries in a common directory
57 # to simplify the link line.
58 OVERRIDE_BUILT_MODULE_PATH := \
59 $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)
60 endif
Ying Wangb6eb8dd2016-03-01 20:14:52 -080061 ifeq ($(LOCAL_IS_HOST_MODULE)$(my_strip_module),)
Ying Wangbfb52a22014-08-20 17:12:32 -070062 # Strip but not try to add debuglink
Ying Wangb6eb8dd2016-03-01 20:14:52 -080063 my_strip_module := no_debuglink
Ying Wangbfb52a22014-08-20 17:12:32 -070064 endif
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070065
Ying Wangb6eb8dd2016-03-01 20:14:52 -080066 ifeq ($(LOCAL_IS_HOST_MODULE)$(my_pack_module_relocations),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070067 # Do not pack relocations by default
Ying Wangb6eb8dd2016-03-01 20:14:52 -080068 my_pack_module_relocations := false
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070069 endif
Dan Albert52831d12015-11-12 15:27:49 -080070
71 ifeq ($(DISABLE_RELOCATION_PACKER),true)
Ying Wangb6eb8dd2016-03-01 20:14:52 -080072 my_pack_module_relocations := false
Dan Albert52831d12015-11-12 15:27:49 -080073 endif
Colin Crosse18cb932014-02-13 15:04:18 -080074endif
75
76ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
77 prebuilt_module_is_a_library := true
78else
79 prebuilt_module_is_a_library :=
80endif
81
Dan Willemsenfc92fb22016-08-26 13:27:13 -070082ifeq ($(LOCAL_MODULE_MAKEFILE),$(SOONG_ANDROID_MK))
83ifeq ($(prebuilt_module_is_a_library),true)
84SOONG_ALREADY_CONV := $(SOONG_ALREADY_CONV) $(LOCAL_MODULE)
85endif
86endif
87
Colin Crosse18cb932014-02-13 15:04:18 -080088# Don't install static libraries by default.
89ifndef LOCAL_UNINSTALLABLE_MODULE
90ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS))
91 LOCAL_UNINSTALLABLE_MODULE := true
92endif
93endif
94
Ying Wang3a61eeb2016-03-11 10:32:01 -080095ifeq (JAVA_LIBRARIES,$(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS)$(filter true,$(LOCAL_UNINSTALLABLE_MODULE)))
96 prebuilt_module_is_dex_javalib := true
97else
98 prebuilt_module_is_dex_javalib :=
99endif
100
Ying Wangaf9757e2014-07-17 21:24:42 -0700101ifeq ($(LOCAL_MODULE_CLASS),APPS)
102LOCAL_BUILT_MODULE_STEM := package.apk
103LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
104endif
105
Dan Willemsen4598fbc2016-07-13 16:08:36 -0700106ifneq ($(filter true keep_symbols no_debuglink mini-debug-info,$(my_strip_module) $(my_pack_module_relocations)),)
Colin Crosse18cb932014-02-13 15:04:18 -0800107 ifdef LOCAL_IS_HOST_MODULE
Dmitriy Ivanov64762c32015-04-24 15:33:14 -0700108 $(error Cannot strip/pack host module LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -0800109 endif
Dan Willemsen7fe992c2016-03-02 13:54:51 -0800110 ifeq ($(filter SHARED_LIBRARIES EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -0700111 $(error Can strip/pack only shared libraries or executables LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -0800112 endif
113 ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -0700114 $(error Cannot strip/pack scripts LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -0800115 endif
Ying Wangb6eb8dd2016-03-01 20:14:52 -0800116 # Set the arch-specific variables to set up the strip/pack rules.
117 LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) := $(my_strip_module)
118 LOCAL_PACK_MODULE_RELOCATIONS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) := $(my_pack_module_relocations)
Colin Crosse18cb932014-02-13 15:04:18 -0800119 include $(BUILD_SYSTEM)/dynamic_binary.mk
120 built_module := $(linked_module)
Ying Wangbfb52a22014-08-20 17:12:32 -0700121
Ying Wangb6eb8dd2016-03-01 20:14:52 -0800122else # my_strip_module and my_pack_module_relocations not true
Colin Crosse18cb932014-02-13 15:04:18 -0800123 include $(BUILD_SYSTEM)/base_rules.mk
124 built_module := $(LOCAL_BUILT_MODULE)
125
126ifdef prebuilt_module_is_a_library
127export_includes := $(intermediates)/export_includes
128$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
Dan Willemsen1c6dc5b2016-01-06 14:28:36 -0800129$(export_includes) :
Colin Crosse18cb932014-02-13 15:04:18 -0800130 @echo Export includes file: $< -- $@
131 $(hide) mkdir -p $(dir $@) && rm -f $@
132ifdef LOCAL_EXPORT_C_INCLUDE_DIRS
133 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \
134 echo "-I $$d" >> $@; \
135 done
136else
137 $(hide) touch $@
138endif
139
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700140my_link_type := $(intermediates)/link_type
Dan Willemsen121e2842016-09-14 21:38:29 -0700141$(my_link_type): PRIVATE_LINK_TYPE := native:$(if $(LOCAL_SDK_VERSION),ndk,platform)
142$(eval $(call link-type-partitions,$(my_link_type)))
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700143$(my_link_type):
144 @echo Check module type: $@
145 $(hide) mkdir -p $(dir $@) && rm -f $@
Dan Willemsen121e2842016-09-14 21:38:29 -0700146 $(hide) echo "$(PRIVATE_LINK_TYPE)" >$@
Dan Willemsenb097fbe2016-06-07 14:25:14 -0700147
148$(LOCAL_BUILT_MODULE) : | $(export_includes) $(my_link_type)
Colin Crosse18cb932014-02-13 15:04:18 -0800149endif # prebuilt_module_is_a_library
150
151# The real dependency will be added after all Android.mks are loaded and the install paths
152# of the shared libraries are determined.
153ifdef LOCAL_INSTALLED_MODULE
154ifdef LOCAL_SHARED_LIBRARIES
Ying Wang7c877392014-10-07 13:03:29 -0700155my_shared_libraries := $(LOCAL_SHARED_LIBRARIES)
156# Extra shared libraries introduced by LOCAL_CXX_STL.
157include $(BUILD_SYSTEM)/cxx_stl_setup.mk
Ying Wang58f462f2014-02-25 18:26:29 -0800158$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
Ying Wang7c877392014-10-07 13:03:29 -0700159 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries))
Colin Crosse18cb932014-02-13 15:04:18 -0800160
161# We also need the LOCAL_BUILT_MODULE dependency,
162# since we use -rpath-link which points to the built module's path.
Ying Wang7c877392014-10-07 13:03:29 -0700163my_built_shared_libraries := \
Ying Wang58f462f2014-02-25 18:26:29 -0800164 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
Colin Crosse18cb932014-02-13 15:04:18 -0800165 $(addsuffix $($(my_prefix)SHLIB_SUFFIX), \
Ying Wang7c877392014-10-07 13:03:29 -0700166 $(my_shared_libraries)))
167$(LOCAL_BUILT_MODULE) : $(my_built_shared_libraries)
Colin Crosse18cb932014-02-13 15:04:18 -0800168endif
169endif
170
Ying Wang7c877392014-10-07 13:03:29 -0700171# We need to enclose the above export_includes and my_built_shared_libraries in
Ying Wangb6eb8dd2016-03-01 20:14:52 -0800172# "my_strip_module not true" because otherwise the rules are defined in dynamic_binary.mk.
173endif # my_strip_module not true
Colin Crosse18cb932014-02-13 15:04:18 -0800174
Ryan Campbell81c9d292016-09-12 13:56:50 -0700175# Coverage information is needed when static lib is a dependency of another
176# coverage-enabled module.
177ifeq (STATIC_LIBRARIES, $(LOCAL_MODULE_CLASS))
178GCNO_ARCHIVE := $(LOCAL_MODULE).gcnodir
179$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_OBJECTS :=
180$(intermediates)/$(GCNO_ARCHIVE) : PRIVATE_ALL_WHOLE_STATIC_LIBRARIES :=
181$(intermediates)/$(GCNO_ARCHIVE) :
182 $(transform-o-to-static-lib)
183endif
184
Ying Wangf0534c22014-04-15 11:12:21 -0700185ifeq ($(LOCAL_MODULE_CLASS),APPS)
Colin Crosse18cb932014-02-13 15:04:18 -0800186PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
187
Ying Wang43f7a322014-11-17 16:56:04 -0800188# Select dpi-specific source
189ifdef LOCAL_DPI_VARIANTS
Ying Wang60686582014-12-10 12:40:09 -0800190my_dpi := $(firstword $(filter $(LOCAL_DPI_VARIANTS),$(PRODUCT_AAPT_PREF_CONFIG) $(PRODUCT_AAPT_PREBUILT_DPI)))
Ying Wang43f7a322014-11-17 16:56:04 -0800191ifdef my_dpi
192ifdef LOCAL_DPI_FILE_STEM
193my_prebuilt_dpi_file_stem := $(LOCAL_DPI_FILE_STEM)
194else
195my_prebuilt_dpi_file_stem := $(LOCAL_MODULE)_%.apk
196endif
197my_prebuilt_src_file := $(dir $(my_prebuilt_src_file))$(subst %,$(my_dpi),$(my_prebuilt_dpi_file_stem))
198endif # my_dpi
199endif # LOCAL_DPI_VARIANTS
200
Ying Wang96bcad42014-04-17 13:38:04 -0700201rs_compatibility_jni_libs :=
202include $(BUILD_SYSTEM)/install_jni_libs.mk
203
Colin Crosse18cb932014-02-13 15:04:18 -0800204ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
205 # The magic string "EXTERNAL" means this package will be signed with
206 # the default dev key throughout the build process, but we expect
207 # the final package to be signed with a different key.
208 #
209 # This can be used for packages where we don't have access to the
210 # keys, but want the package to be predexopt'ed.
211 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
212 PACKAGES.$(LOCAL_MODULE).EXTERNAL_KEY := 1
213
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900214 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
Colin Crosse18cb932014-02-13 15:04:18 -0800215 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
216 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
217endif
218ifeq ($(LOCAL_CERTIFICATE),)
Ying Wangf0534c22014-04-15 11:12:21 -0700219 # It is now a build error to add a prebuilt .apk without
220 # specifying a key for it.
221 $(error No LOCAL_CERTIFICATE specified for prebuilt "$(my_prebuilt_src_file)")
Colin Crosse18cb932014-02-13 15:04:18 -0800222else ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
223 # The magic string "PRESIGNED" means this package is already checked
224 # signed with its release key.
225 #
226 # By setting .CERTIFICATE but not .PRIVATE_KEY, this package will be
227 # mentioned in apkcerts.txt (with certificate set to "PRESIGNED")
228 # but the dexpreopt process will not try to re-sign the app.
229 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := PRESIGNED
230 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
231else
232 # If this is not an absolute certificate, assign it to a generic one.
233 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
234 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
235 endif
236
237 PACKAGES.$(LOCAL_MODULE).PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
238 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
239 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
240
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900241 $(built_module) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
Colin Crosse18cb932014-02-13 15:04:18 -0800242 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
243 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
244endif
245
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700246# Disable dex-preopt of prebuilts to save space, if requested.
Ying Wang3a61eeb2016-03-11 10:32:01 -0800247ifndef LOCAL_DEX_PREOPT
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700248ifeq ($(DONT_DEXPREOPT_PREBUILTS),true)
Colin Crosse18cb932014-02-13 15:04:18 -0800249LOCAL_DEX_PREOPT := false
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700250endif
Ying Wang3a61eeb2016-03-11 10:32:01 -0800251endif
Colin Crosse18cb932014-02-13 15:04:18 -0800252
253#######################################
254# defines built_odex along with rule to install odex
255include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
256#######################################
Ying Wang3a61eeb2016-03-11 10:32:01 -0800257ifneq ($(LOCAL_REPLACE_PREBUILT_APK_INSTALLED),)
258# There is a replacement for the prebuilt .apk we can install without any processing.
Ying Wangc9a19772016-03-15 14:40:33 -0700259$(built_module) : $(LOCAL_REPLACE_PREBUILT_APK_INSTALLED)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800260 $(transform-prebuilt-to-target)
Ying Wang1fb01522015-05-01 14:02:26 -0700261
Ying Wang3a61eeb2016-03-11 10:32:01 -0800262else # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
263# Sign and align non-presigned .apks.
Ying Wang1fb01522015-05-01 14:02:26 -0700264# The embedded prebuilt jni to uncompress.
Ying Wang226eb922015-06-01 19:19:57 -0700265ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
266# For PRESIGNED apks we must uncompress every .so file:
267# even if the .so file isn't for the current TARGET_ARCH,
268# we can't strip the file.
269embedded_prebuilt_jni_libs := 'lib/*.so'
270endif
Ying Wang1fb01522015-05-01 14:02:26 -0700271ifndef embedded_prebuilt_jni_libs
272# No LOCAL_PREBUILT_JNI_LIBS, uncompress all.
273embedded_prebuilt_jni_libs := 'lib/*.so'
274endif
275$(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
276
Dan Willemsen7f016152016-02-29 17:52:39 -0800277$(built_module) : $(my_prebuilt_src_file) | $(ZIPALIGN) $(SIGNAPK_JAR) $(AAPT)
Colin Crosse18cb932014-02-13 15:04:18 -0800278 $(transform-prebuilt-to-target)
Ying Wang226eb922015-06-01 19:19:57 -0700279 $(uncompress-shared-libs)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800280ifdef LOCAL_DEX_PREOPT
281ifneq ($(BUILD_PLATFORM_ZIP),)
282 @# Keep a copy of apk with classes.dex unstripped
283 $(hide) cp -f $@ $(dir $@)package.dex.apk
284endif # BUILD_PLATFORM_ZIP
285endif # LOCAL_DEX_PREOPT
Kenny Rootdff37552015-04-15 12:09:32 -0700286ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
287 @# Only strip out files if we can re-sign the package.
Colin Crosse18cb932014-02-13 15:04:18 -0800288ifdef LOCAL_DEX_PREOPT
Ying Wang36142f62014-05-21 16:13:33 -0700289ifneq (nostripping,$(LOCAL_DEX_PREOPT))
290 $(call dexpreopt-remove-classes.dex,$@)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800291endif # LOCAL_DEX_PREOPT != nostripping
292endif # LOCAL_DEX_PREOPT
Kenny Rootdff37552015-04-15 12:09:32 -0700293 $(sign-package)
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800294 # No need for align-package because sign-package takes care of alignment
Ying Wang3a61eeb2016-03-11 10:32:01 -0800295else # LOCAL_CERTIFICATE == PRESIGNED
Colin Crosse18cb932014-02-13 15:04:18 -0800296 $(align-package)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800297endif # LOCAL_CERTIFICATE
298endif # ! LOCAL_REPLACE_PREBUILT_APK_INSTALLED
Colin Crosse18cb932014-02-13 15:04:18 -0800299
Ying Wang36142f62014-05-21 16:13:33 -0700300###############################
301## Rule to build the odex file
302ifdef LOCAL_DEX_PREOPT
303$(built_odex) : $(my_prebuilt_src_file)
304 $(call dexpreopt-one-file,$<,$@)
305endif
306
Ying Wang00fe5872014-07-23 14:35:40 -0700307###############################
308## Install split apks.
309ifdef LOCAL_PACKAGE_SPLITS
310# LOCAL_PACKAGE_SPLITS is a list of apks to be installed.
311built_apk_splits := $(addprefix $(built_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
312installed_apk_splits := $(addprefix $(my_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
313
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800314# Rules to sign the split apks.
Ying Wang00fe5872014-07-23 14:35:40 -0700315my_src_dir := $(sort $(dir $(LOCAL_PACKAGE_SPLITS)))
316ifneq (1,$(words $(my_src_dir)))
317$(error You must put all the split source apks in the same folder: $(LOCAL_PACKAGE_SPLITS))
318endif
319my_src_dir := $(LOCAL_PATH)/$(my_src_dir)
320
Shinichiro Hamaji641e61c2016-05-13 16:03:24 +0900321$(built_apk_splits) : $(LOCAL_CERTIFICATE).pk8 $(LOCAL_CERTIFICATE).x509.pem
Ying Wang00fe5872014-07-23 14:35:40 -0700322$(built_apk_splits) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
323$(built_apk_splits) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
Dan Willemsen7f016152016-02-29 17:52:39 -0800324$(built_apk_splits) : $(built_module_path)/%.apk : $(my_src_dir)/%.apk | $(AAPT)
Ying Wang00fe5872014-07-23 14:35:40 -0700325 $(copy-file-to-new-target)
326 $(sign-package)
Ying Wang00fe5872014-07-23 14:35:40 -0700327
328# Rules to install the split apks.
Dan Willemsen7f016152016-02-29 17:52:39 -0800329$(installed_apk_splits) : $(my_module_path)/%.apk : $(built_module_path)/%.apk
Ying Wang00fe5872014-07-23 14:35:40 -0700330 @echo "Install: $@"
331 $(copy-file-to-new-target)
332
333# Register the additional built and installed files.
334ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
335ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
336 $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(built_module_path)/$(notdir $(s)):$(my_module_path)/$(notdir $(s)))
337
338# Make sure to install the splits when you run "make <module_name>".
Colin Cross33886702016-09-20 16:01:28 -0700339$(my_all_targets): $(installed_apk_splits)
Ying Wang00fe5872014-07-23 14:35:40 -0700340
341endif # LOCAL_PACKAGE_SPLITS
342
Colin Crosse18cb932014-02-13 15:04:18 -0800343else # LOCAL_MODULE_CLASS != APPS
Ying Wang3a61eeb2016-03-11 10:32:01 -0800344ifeq ($(prebuilt_module_is_dex_javalib),true)
345# This is a target shared library, i.e. a jar with classes.dex.
346#######################################
347# defines built_odex along with rule to install odex
348include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
349#######################################
350ifdef LOCAL_DEX_PREOPT
351ifneq ($(dexpreopt_boot_jar_module),) # boot jar
352# boot jar's rules are defined in dex_preopt.mk
353dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar
Ying Wangc9a19772016-03-15 14:40:33 -0700354$(built_module) : $(dexpreopted_boot_jar)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800355 $(call copy-file-to-target)
Dan Willemsen08420cb2016-03-01 22:04:57 -0800356
Ying Wang3a61eeb2016-03-11 10:32:01 -0800357# For libart boot jars, we don't have .odex files.
358else # ! boot jar
359$(built_odex): PRIVATE_MODULE := $(LOCAL_MODULE)
360# Use pattern rule - we may have multiple built odex files.
361$(built_odex) : $(dir $(LOCAL_BUILT_MODULE))% : $(my_prebuilt_src_file)
362 @echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)"
363 $(call dexpreopt-one-file,$<,$@)
364
Ying Wangc9a19772016-03-15 14:40:33 -0700365$(built_module) : $(my_prebuilt_src_file)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800366 $(call copy-file-to-target)
367ifneq (nostripping,$(LOCAL_DEX_PREOPT))
368 $(call dexpreopt-remove-classes.dex,$@)
369endif
370endif # boot jar
371else # ! LOCAL_DEX_PREOPT
Ying Wangc9a19772016-03-15 14:40:33 -0700372$(built_module) : $(my_prebuilt_src_file)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800373 $(call copy-file-to-target)
374endif # LOCAL_DEX_PREOPT
375
376else # ! prebuilt_module_is_dex_javalib
Colin Crosse18cb932014-02-13 15:04:18 -0800377$(built_module) : $(my_prebuilt_src_file)
Dan Willemsen08420cb2016-03-01 22:04:57 -0800378ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
Colin Crosse18cb932014-02-13 15:04:18 -0800379 $(transform-prebuilt-to-target-strip-comments)
380else
Colin Crosse18cb932014-02-13 15:04:18 -0800381 $(transform-prebuilt-to-target)
Colin Crosse18cb932014-02-13 15:04:18 -0800382endif
Dan Willemsen7fe992c2016-03-02 13:54:51 -0800383ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
Dan Willemsen08420cb2016-03-01 22:04:57 -0800384 $(hide) chmod +x $@
385endif
Ying Wang3a61eeb2016-03-11 10:32:01 -0800386endif # ! prebuilt_module_is_dex_javalib
Colin Crosse18cb932014-02-13 15:04:18 -0800387endif # LOCAL_MODULE_CLASS != APPS
388
Ying Wang8c89b4b2016-02-22 15:54:27 -0800389ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
390my_src_jar := $(my_prebuilt_src_file)
391ifeq ($(LOCAL_IS_HOST_MODULE),)
Colin Crosse18cb932014-02-13 15:04:18 -0800392# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
393# 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 -0700394common_classes_jar := $(intermediates.COMMON)/classes.jar
395common_javalib_jar := $(intermediates.COMMON)/javalib.jar
Colin Crosse18cb932014-02-13 15:04:18 -0800396
Ying Wange9dd9f22014-10-29 15:48:32 -0700397$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
398
Dan Willemsen62dfb592016-07-08 21:33:05 -0700399my_link_type := $(intermediates.COMMON)/link_type
400ifeq ($(LOCAL_SDK_VERSION),system_current)
Dan Willemsen121e2842016-09-14 21:38:29 -0700401$(my_link_type): PRIVATE_LINK_TYPE := java:system
Dan Willemsen62dfb592016-07-08 21:33:05 -0700402else ifneq ($(LOCAL_SDK_VERSION),)
Dan Willemsen121e2842016-09-14 21:38:29 -0700403$(my_link_type): PRIVATE_LINK_TYPE := java:sdk
Dan Willemsen62dfb592016-07-08 21:33:05 -0700404else
Dan Willemsen121e2842016-09-14 21:38:29 -0700405$(my_link_type): PRIVATE_LINK_TYPE := java:platform
Dan Willemsen62dfb592016-07-08 21:33:05 -0700406endif
Dan Willemsen121e2842016-09-14 21:38:29 -0700407$(eval $(call link-type-partitions,$(my_link_type)))
Dan Willemsen62dfb592016-07-08 21:33:05 -0700408$(my_link_type):
409 @echo Check module type: $@
410 $(hide) mkdir -p $(dir $@) && rm -f $@
Dan Willemsen121e2842016-09-14 21:38:29 -0700411 $(hide) echo "$(PRIVATE_LINK_TYPE)" >$@
Dan Willemsen62dfb592016-07-08 21:33:05 -0700412$(LOCAL_BUILT_MODULE): $(my_link_type)
413
Ying Wang3a61eeb2016-03-11 10:32:01 -0800414ifeq ($(prebuilt_module_is_dex_javalib),true)
415# For prebuilt shared Java library we don't have classes.jar.
Ying Wangc9a19772016-03-15 14:40:33 -0700416$(common_javalib_jar) : $(my_src_jar)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800417 $(transform-prebuilt-to-target)
418
419else # ! prebuilt_module_is_dex_javalib
420
Ying Wangdd71c852015-12-04 13:59:18 -0800421my_src_aar := $(filter %.aar, $(my_prebuilt_src_file))
422ifneq ($(my_src_aar),)
Ying Wange9dd9f22014-10-29 15:48:32 -0700423# This is .aar file, archive of classes.jar and Android resources.
424my_src_jar := $(intermediates.COMMON)/aar/classes.jar
425
Ying Wangdd71c852015-12-04 13:59:18 -0800426$(my_src_jar) : $(my_src_aar)
Ying Wange9dd9f22014-10-29 15:48:32 -0700427 $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
428 $(hide) unzip -qo -d $(dir $@) $<
429 # Make sure the extracted classes.jar has a new timestamp.
430 $(hide) touch $@
431
Ying Wange9dd9f22014-10-29 15:48:32 -0700432endif
Ying Wang3a61eeb2016-03-11 10:32:01 -0800433
Dan Willemsen7f016152016-02-29 17:52:39 -0800434$(common_classes_jar) : $(my_src_jar)
Colin Crosse18cb932014-02-13 15:04:18 -0800435 $(transform-prebuilt-to-target)
436
Dan Willemsen7f016152016-02-29 17:52:39 -0800437$(common_javalib_jar) : $(common_classes_jar)
Colin Crosse18cb932014-02-13 15:04:18 -0800438 $(transform-prebuilt-to-target)
439
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +0900440$(call define-jar-to-toc-rule, $(common_classes_jar))
441
Ying Wange295c3d2016-02-24 14:11:55 -0800442ifdef LOCAL_USE_AAPT2
Ying Wangdd71c852015-12-04 13:59:18 -0800443ifneq ($(my_src_aar),)
Ying Wange295c3d2016-02-24 14:11:55 -0800444my_res_package := $(intermediates.COMMON)/package-res.apk
445
446# We needed only very few PRIVATE variables and aapt2.mk input variables. Reset the unnecessary ones.
447$(my_res_package): PRIVATE_AAPT2_CFLAGS :=
448$(my_res_package): PRIVATE_ANDROID_MANIFEST := $(intermediates.COMMON)/aar/AndroidManifest.xml
449$(my_res_package): PRIVATE_AAPT_INCLUDES :=
450$(my_res_package): PRIVATE_SOURCE_INTERMEDIATES_DIR :=
451$(my_res_package): PRIVATE_PROGUARD_OPTIONS_FILE :=
452$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK :=
453$(my_res_package): PRIVATE_DEFAULT_APP_TARGET_SDK :=
Adam Lesinskie758f932016-02-26 11:13:43 -0800454$(my_res_package): PRIVATE_PRODUCT_AAPT_CONFIG :=
455$(my_res_package): PRIVATE_PRODUCT_AAPT_PREF_CONFIG :=
456$(my_res_package): PRIVATE_TARGET_AAPT_CHARACTERISTICS :=
Ying Wange295c3d2016-02-24 14:11:55 -0800457
458full_android_manifest :=
459my_res_resources :=
460my_overlay_resources :=
Ying Wange295c3d2016-02-24 14:11:55 -0800461my_compiled_res_base_dir :=
462R_file_stamp :=
463proguard_options_file :=
464my_generated_res_dirs := $(intermediates.COMMON)/aar/res
465my_generated_res_dirs_deps := $(my_src_jar)
466include $(BUILD_SYSTEM)/aapt2.mk
467
468# Make sure my_res_package is created when you run mm/mmm.
469$(built_module) : $(my_res_package)
Ying Wangdd71c852015-12-04 13:59:18 -0800470endif # $(my_src_aar)
Ying Wange295c3d2016-02-24 14:11:55 -0800471endif # LOCAL_USE_AAPT2
Colin Crosse18cb932014-02-13 15:04:18 -0800472# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
473$(built_module) : $(common_javalib_jar)
Ying Wang3a61eeb2016-03-11 10:32:01 -0800474
475endif # ! prebuilt_module_is_dex_javalib
Ying Wang8c89b4b2016-02-22 15:54:27 -0800476endif # LOCAL_IS_HOST_MODULE is not set
Yohann Rousseld87cc992016-01-19 16:08:34 +0100477
Ying Wang3a61eeb2016-03-11 10:32:01 -0800478ifneq ($(prebuilt_module_is_dex_javalib),true)
Yohann Rousseld87cc992016-01-19 16:08:34 +0100479
Ying Wang8c89b4b2016-02-22 15:54:27 -0800480# We may be building classes.jack from a host jar for host dalvik Java library.
Yohann Rousseld87cc992016-01-19 16:08:34 +0100481$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_FLAGS:=$(LOCAL_JACK_FLAGS)
Yohann Roussel5960c542016-08-19 18:57:34 +0200482$(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 +0200483$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_PLUGIN_PATH := $(LOCAL_JACK_PLUGIN_PATH)
Yohann Roussel16243bd2016-09-19 17:49:03 +0200484$(intermediates.COMMON)/classes.jack : PRIVATE_JACK_PLUGIN := $(LOCAL_JACK_PLUGIN)
Yohann Roussel53b7fbb2016-08-05 17:45:10 +0200485$(intermediates.COMMON)/classes.jack : $(LOCAL_JACK_PLUGIN_PATH) $(my_src_jar) \
Shinichiro Hamaji4eaeef82016-04-07 18:56:42 +0900486 $(LOCAL_ADDITIONAL_DEPENDENCIES) $(JACK_DEFAULT_ARGS) $(JACK) \
487 | setup-jack-server
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200488 $(transform-jar-to-jack)
489
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +0900490# Update timestamps of .toc files for prebuilts so dependents will be
491# always rebuilt.
492$(intermediates.COMMON)/classes.dex.toc: $(intermediates.COMMON)/classes.jack
493 touch $@
494
Ying Wang3a61eeb2016-03-11 10:32:01 -0800495endif # ! prebuilt_module_is_dex_javalib
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200496endif # JAVA_LIBRARIES
497
Dan Willemsen1c6dc5b2016-01-06 14:28:36 -0800498$(built_module) : $(LOCAL_ADDITIONAL_DEPENDENCIES)
Colin Crosse18cb932014-02-13 15:04:18 -0800499
500my_prebuilt_src_file :=