blob: b0af228aecdae78cc167a29959dab1ae9908c9b5 [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))
Ying Wangc0adfb72014-02-27 14:10:53 -080029 else
Ying Wang34d5f1b2014-05-16 10:38:43 -070030 ifdef LOCAL_SRC_FILES_$(my_32_64_bit_suffix)
31 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES_$(my_32_64_bit_suffix))
32 else
33 my_prebuilt_src_file := $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
34 endif
Ying Wangc0adfb72014-02-27 14:10:53 -080035 endif
Colin Crosse18cb932014-02-13 15:04:18 -080036endif
37
Colin Crosse18cb932014-02-13 15:04:18 -080038ifeq (SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS))
39 # Put the built targets of all shared libraries in a common directory
40 # to simplify the link line.
41 OVERRIDE_BUILT_MODULE_PATH := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)
Ying Wangbfb52a22014-08-20 17:12:32 -070042 ifeq ($(LOCAL_IS_HOST_MODULE)$(LOCAL_STRIP_MODULE),)
43 # Strip but not try to add debuglink
44 LOCAL_STRIP_MODULE := no_debuglink
45 endif
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070046
47 ifeq ($(LOCAL_IS_HOST_MODULE)$(LOCAL_PACK_MODULE_RELOCATIONS),)
48 # Do not pack relocations by default
49 LOCAL_PACK_MODULE_RELOCATIONS := false
50 endif
Dan Albert52831d12015-11-12 15:27:49 -080051
52 ifeq ($(DISABLE_RELOCATION_PACKER),true)
53 LOCAL_PACK_MODULE_RELOCATIONS := false
54 endif
Colin Crosse18cb932014-02-13 15:04:18 -080055endif
56
57ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
58 prebuilt_module_is_a_library := true
59else
60 prebuilt_module_is_a_library :=
61endif
62
63# Don't install static libraries by default.
64ifndef LOCAL_UNINSTALLABLE_MODULE
65ifeq (STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS))
66 LOCAL_UNINSTALLABLE_MODULE := true
67endif
68endif
69
Ying Wangaf9757e2014-07-17 21:24:42 -070070ifeq ($(LOCAL_MODULE_CLASS),APPS)
71LOCAL_BUILT_MODULE_STEM := package.apk
72LOCAL_INSTALLED_MODULE_STEM := $(LOCAL_MODULE).apk
73endif
74
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070075ifneq ($(filter true no_debuglink,$(LOCAL_STRIP_MODULE) $(LOCAL_PACK_MODULE_RELOCATIONS)),)
Colin Crosse18cb932014-02-13 15:04:18 -080076 ifdef LOCAL_IS_HOST_MODULE
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070077 $(error Cannot strip/pack host module LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -080078 endif
79 ifeq ($(filter SHARED_LIBRARIES EXECUTABLES,$(LOCAL_MODULE_CLASS)),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070080 $(error Can strip/pack only shared libraries or executables LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -080081 endif
82 ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070083 $(error Cannot strip/pack scripts LOCAL_PATH=$(LOCAL_PATH))
Colin Crosse18cb932014-02-13 15:04:18 -080084 endif
85 include $(BUILD_SYSTEM)/dynamic_binary.mk
86 built_module := $(linked_module)
Ying Wangbfb52a22014-08-20 17:12:32 -070087
Dmitriy Ivanov64762c32015-04-24 15:33:14 -070088else # LOCAL_STRIP_MODULE and LOCAL_PACK_MODULE_RELOCATIONS not true
Colin Crosse18cb932014-02-13 15:04:18 -080089 include $(BUILD_SYSTEM)/base_rules.mk
90 built_module := $(LOCAL_BUILT_MODULE)
91
92ifdef prebuilt_module_is_a_library
93export_includes := $(intermediates)/export_includes
94$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
Colin Crossa4447e82015-09-28 16:26:00 -070095$(export_includes) : $(LOCAL_MODULE_MAKEFILE_DEP)
Colin Crosse18cb932014-02-13 15:04:18 -080096 @echo Export includes file: $< -- $@
97 $(hide) mkdir -p $(dir $@) && rm -f $@
98ifdef LOCAL_EXPORT_C_INCLUDE_DIRS
99 $(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \
100 echo "-I $$d" >> $@; \
101 done
102else
103 $(hide) touch $@
104endif
105
106$(LOCAL_BUILT_MODULE) : | $(intermediates)/export_includes
107endif # prebuilt_module_is_a_library
108
109# The real dependency will be added after all Android.mks are loaded and the install paths
110# of the shared libraries are determined.
111ifdef LOCAL_INSTALLED_MODULE
112ifdef LOCAL_SHARED_LIBRARIES
Ying Wang7c877392014-10-07 13:03:29 -0700113my_shared_libraries := $(LOCAL_SHARED_LIBRARIES)
114# Extra shared libraries introduced by LOCAL_CXX_STL.
115include $(BUILD_SYSTEM)/cxx_stl_setup.mk
Ying Wang58f462f2014-02-25 18:26:29 -0800116$(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)DEPENDENCIES_ON_SHARED_LIBRARIES += \
Ying Wang7c877392014-10-07 13:03:29 -0700117 $(my_register_name):$(LOCAL_INSTALLED_MODULE):$(subst $(space),$(comma),$(my_shared_libraries))
Colin Crosse18cb932014-02-13 15:04:18 -0800118
119# We also need the LOCAL_BUILT_MODULE dependency,
120# since we use -rpath-link which points to the built module's path.
Ying Wang7c877392014-10-07 13:03:29 -0700121my_built_shared_libraries := \
Ying Wang58f462f2014-02-25 18:26:29 -0800122 $(addprefix $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
Colin Crosse18cb932014-02-13 15:04:18 -0800123 $(addsuffix $($(my_prefix)SHLIB_SUFFIX), \
Ying Wang7c877392014-10-07 13:03:29 -0700124 $(my_shared_libraries)))
125$(LOCAL_BUILT_MODULE) : $(my_built_shared_libraries)
Colin Crosse18cb932014-02-13 15:04:18 -0800126endif
127endif
128
Ying Wang7c877392014-10-07 13:03:29 -0700129# We need to enclose the above export_includes and my_built_shared_libraries in
Ying Wangbfb52a22014-08-20 17:12:32 -0700130# "LOCAL_STRIP_MODULE not true" because otherwise the rules are defined in dynamic_binary.mk.
Colin Crosse18cb932014-02-13 15:04:18 -0800131endif # LOCAL_STRIP_MODULE not true
132
Ying Wangf0534c22014-04-15 11:12:21 -0700133ifeq ($(LOCAL_MODULE_CLASS),APPS)
Colin Crosse18cb932014-02-13 15:04:18 -0800134PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
135
Ying Wang43f7a322014-11-17 16:56:04 -0800136# Select dpi-specific source
137ifdef LOCAL_DPI_VARIANTS
Ying Wang60686582014-12-10 12:40:09 -0800138my_dpi := $(firstword $(filter $(LOCAL_DPI_VARIANTS),$(PRODUCT_AAPT_PREF_CONFIG) $(PRODUCT_AAPT_PREBUILT_DPI)))
Ying Wang43f7a322014-11-17 16:56:04 -0800139ifdef my_dpi
140ifdef LOCAL_DPI_FILE_STEM
141my_prebuilt_dpi_file_stem := $(LOCAL_DPI_FILE_STEM)
142else
143my_prebuilt_dpi_file_stem := $(LOCAL_MODULE)_%.apk
144endif
145my_prebuilt_src_file := $(dir $(my_prebuilt_src_file))$(subst %,$(my_dpi),$(my_prebuilt_dpi_file_stem))
146endif # my_dpi
147endif # LOCAL_DPI_VARIANTS
148
Ying Wang96bcad42014-04-17 13:38:04 -0700149rs_compatibility_jni_libs :=
150include $(BUILD_SYSTEM)/install_jni_libs.mk
151
Colin Crosse18cb932014-02-13 15:04:18 -0800152ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
153 # The magic string "EXTERNAL" means this package will be signed with
154 # the default dev key throughout the build process, but we expect
155 # the final package to be signed with a different key.
156 #
157 # This can be used for packages where we don't have access to the
158 # keys, but want the package to be predexopt'ed.
159 LOCAL_CERTIFICATE := $(DEFAULT_SYSTEM_DEV_CERTIFICATE)
160 PACKAGES.$(LOCAL_MODULE).EXTERNAL_KEY := 1
161
162 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
163 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
164endif
165ifeq ($(LOCAL_CERTIFICATE),)
Ying Wangf0534c22014-04-15 11:12:21 -0700166 # It is now a build error to add a prebuilt .apk without
167 # specifying a key for it.
168 $(error No LOCAL_CERTIFICATE specified for prebuilt "$(my_prebuilt_src_file)")
Colin Crosse18cb932014-02-13 15:04:18 -0800169else ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
170 # The magic string "PRESIGNED" means this package is already checked
171 # signed with its release key.
172 #
173 # By setting .CERTIFICATE but not .PRIVATE_KEY, this package will be
174 # mentioned in apkcerts.txt (with certificate set to "PRESIGNED")
175 # but the dexpreopt process will not try to re-sign the app.
176 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := PRESIGNED
177 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
178else
179 # If this is not an absolute certificate, assign it to a generic one.
180 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
181 LOCAL_CERTIFICATE := $(dir $(DEFAULT_SYSTEM_DEV_CERTIFICATE))$(LOCAL_CERTIFICATE)
182 endif
183
184 PACKAGES.$(LOCAL_MODULE).PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
185 PACKAGES.$(LOCAL_MODULE).CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
186 PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
187
188 $(built_module) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
189 $(built_module) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
190endif
191
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700192# Disable dex-preopt of prebuilts to save space, if requested.
193ifeq ($(DONT_DEXPREOPT_PREBUILTS),true)
Colin Crosse18cb932014-02-13 15:04:18 -0800194LOCAL_DEX_PREOPT := false
Andreas Gampe5e0dbe02014-10-01 22:01:16 -0700195endif
Colin Crosse18cb932014-02-13 15:04:18 -0800196
197#######################################
198# defines built_odex along with rule to install odex
199include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
200#######################################
Colin Crosse18cb932014-02-13 15:04:18 -0800201# Sign and align non-presigned .apks.
Ying Wang1fb01522015-05-01 14:02:26 -0700202
203# The embedded prebuilt jni to uncompress.
Ying Wang226eb922015-06-01 19:19:57 -0700204ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
205# For PRESIGNED apks we must uncompress every .so file:
206# even if the .so file isn't for the current TARGET_ARCH,
207# we can't strip the file.
208embedded_prebuilt_jni_libs := 'lib/*.so'
209endif
Ying Wang1fb01522015-05-01 14:02:26 -0700210ifndef embedded_prebuilt_jni_libs
211# No LOCAL_PREBUILT_JNI_LIBS, uncompress all.
212embedded_prebuilt_jni_libs := 'lib/*.so'
213endif
214$(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
215
Colin Crosse18cb932014-02-13 15:04:18 -0800216$(built_module) : $(my_prebuilt_src_file) | $(ACP) $(ZIPALIGN) $(SIGNAPK_JAR)
217 $(transform-prebuilt-to-target)
Ying Wang226eb922015-06-01 19:19:57 -0700218 $(uncompress-shared-libs)
Kenny Rootdff37552015-04-15 12:09:32 -0700219ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
220 @# Only strip out files if we can re-sign the package.
Colin Crosse18cb932014-02-13 15:04:18 -0800221ifdef LOCAL_DEX_PREOPT
Ying Wang36142f62014-05-21 16:13:33 -0700222ifneq (nostripping,$(LOCAL_DEX_PREOPT))
223 $(call dexpreopt-remove-classes.dex,$@)
224endif
Colin Crosse18cb932014-02-13 15:04:18 -0800225endif
Kenny Rootdff37552015-04-15 12:09:32 -0700226 $(sign-package)
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800227 # No need for align-package because sign-package takes care of alignment
228else
Colin Crosse18cb932014-02-13 15:04:18 -0800229 $(align-package)
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800230endif
Colin Crosse18cb932014-02-13 15:04:18 -0800231
Ying Wang36142f62014-05-21 16:13:33 -0700232###############################
233## Rule to build the odex file
234ifdef LOCAL_DEX_PREOPT
235$(built_odex) : $(my_prebuilt_src_file)
236 $(call dexpreopt-one-file,$<,$@)
237endif
238
Ying Wang00fe5872014-07-23 14:35:40 -0700239###############################
240## Install split apks.
241ifdef LOCAL_PACKAGE_SPLITS
242# LOCAL_PACKAGE_SPLITS is a list of apks to be installed.
243built_apk_splits := $(addprefix $(built_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
244installed_apk_splits := $(addprefix $(my_module_path)/,$(notdir $(LOCAL_PACKAGE_SPLITS)))
245
Alex Klyubin5b826ac2015-12-04 10:07:41 -0800246# Rules to sign the split apks.
Ying Wang00fe5872014-07-23 14:35:40 -0700247my_src_dir := $(sort $(dir $(LOCAL_PACKAGE_SPLITS)))
248ifneq (1,$(words $(my_src_dir)))
249$(error You must put all the split source apks in the same folder: $(LOCAL_PACKAGE_SPLITS))
250endif
251my_src_dir := $(LOCAL_PATH)/$(my_src_dir)
252
253$(built_apk_splits) : PRIVATE_PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
254$(built_apk_splits) : PRIVATE_CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
255$(built_apk_splits) : $(built_module_path)/%.apk : $(my_src_dir)/%.apk | $(ACP)
256 $(copy-file-to-new-target)
257 $(sign-package)
Ying Wang00fe5872014-07-23 14:35:40 -0700258
259# Rules to install the split apks.
260$(installed_apk_splits) : $(my_module_path)/%.apk : $(built_module_path)/%.apk | $(ACP)
261 @echo "Install: $@"
262 $(copy-file-to-new-target)
263
264# Register the additional built and installed files.
265ALL_MODULES.$(my_register_name).INSTALLED += $(installed_apk_splits)
266ALL_MODULES.$(my_register_name).BUILT_INSTALLED += \
267 $(foreach s,$(LOCAL_PACKAGE_SPLITS),$(built_module_path)/$(notdir $(s)):$(my_module_path)/$(notdir $(s)))
268
269# Make sure to install the splits when you run "make <module_name>".
270$(my_register_name): $(installed_apk_splits)
271
272endif # LOCAL_PACKAGE_SPLITS
273
Colin Crosse18cb932014-02-13 15:04:18 -0800274else # LOCAL_MODULE_CLASS != APPS
275ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
276$(built_module) : $(my_prebuilt_src_file)
277 $(transform-prebuilt-to-target-strip-comments)
278else
Colin Crossd6f38922015-11-16 17:43:11 -0800279ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
Colin Crosse18cb932014-02-13 15:04:18 -0800280$(built_module) : $(my_prebuilt_src_file) | $(ACP)
281 $(transform-prebuilt-to-target)
Colin Crossd6f38922015-11-16 17:43:11 -0800282else
283$(built_module) : $(my_prebuilt_src_file)
284 $(copy-file-to-target-with-cp)
285endif
Colin Crosse18cb932014-02-13 15:04:18 -0800286endif
287endif # LOCAL_MODULE_CLASS != APPS
288
289ifeq ($(LOCAL_IS_HOST_MODULE)$(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
290# for target java libraries, the LOCAL_BUILT_MODULE is in a product-specific dir,
291# while the deps should be in the common dir, so we make a copy in the common dir.
292# For nonstatic library, $(common_javalib_jar) is the dependency file,
293# while $(common_classes_jar) is used to link.
Ying Wange9dd9f22014-10-29 15:48:32 -0700294common_classes_jar := $(intermediates.COMMON)/classes.jar
295common_javalib_jar := $(intermediates.COMMON)/javalib.jar
Colin Crosse18cb932014-02-13 15:04:18 -0800296
Ying Wange9dd9f22014-10-29 15:48:32 -0700297$(common_classes_jar) $(common_javalib_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
298
299ifneq ($(filter %.aar, $(my_prebuilt_src_file)),)
300# This is .aar file, archive of classes.jar and Android resources.
301my_src_jar := $(intermediates.COMMON)/aar/classes.jar
302
303$(my_src_jar) : $(my_prebuilt_src_file)
304 $(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
305 $(hide) unzip -qo -d $(dir $@) $<
306 # Make sure the extracted classes.jar has a new timestamp.
307 $(hide) touch $@
308
309else
310# This is jar file.
311my_src_jar := $(my_prebuilt_src_file)
312endif
313$(common_classes_jar) : $(my_src_jar) | $(ACP)
Colin Crosse18cb932014-02-13 15:04:18 -0800314 $(transform-prebuilt-to-target)
315
316$(common_javalib_jar) : $(common_classes_jar) | $(ACP)
317 $(transform-prebuilt-to-target)
318
Shinichiro Hamaji89b255a2015-11-09 16:47:42 +0900319$(call define-jar-to-toc-rule, $(common_classes_jar))
320
Colin Crosse18cb932014-02-13 15:04:18 -0800321# make sure the classes.jar and javalib.jar are built before $(LOCAL_BUILT_MODULE)
322$(built_module) : $(common_javalib_jar)
323endif # TARGET JAVA_LIBRARIES
324
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200325ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
Yohann Roussel801f2c42015-03-03 17:14:09 +0100326$(intermediates.COMMON)/classes.jack : PRIVATE_JILL_FLAGS:=$(LOCAL_JILL_FLAGS)
Colin Cross7ee3b852015-09-28 18:45:23 -0700327$(intermediates.COMMON)/classes.jack : $(my_src_jar) $(LOCAL_MODULE_MAKEFILE_DEP) \
Yohann Rousselb2c55582015-07-02 12:10:17 +0200328 $(LOCAL_ADDITIONAL_DEPENDENCIES) $(JILL_JAR) $(JACK)
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200329 $(transform-jar-to-jack)
330
Shinichiro Hamajif972a4a2015-12-09 18:06:20 +0900331# Update timestamps of .toc files for prebuilts so dependents will be
332# always rebuilt.
333$(intermediates.COMMON)/classes.dex.toc: $(intermediates.COMMON)/classes.jack
334 touch $@
335
Yohann Rousselb4c49cb2014-09-08 14:45:14 +0200336endif # JAVA_LIBRARIES
337
Colin Crossa4447e82015-09-28 16:26:00 -0700338$(built_module) : $(LOCAL_MODULE_MAKEFILE_DEP) $(LOCAL_ADDITIONAL_DEPENDENCIES)
Colin Crosse18cb932014-02-13 15:04:18 -0800339
340my_prebuilt_src_file :=