package.mk revision b6c1cf6de79035f58b512f4400db458c8401379a
1#
2# Copyright (C) 2008 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17###########################################################
18## Standard rules for building an application package.
19##
20## Additional inputs from base_rules.make:
21## LOCAL_PACKAGE_NAME: The name of the package; the directory
22##		will be called this.
23##
24## MODULE, MODULE_PATH, and MODULE_SUFFIX will
25## be set for you.
26###########################################################
27
28LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
29ifeq ($(LOCAL_PACKAGE_NAME),)
30$(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
31endif
32
33LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
34ifeq ($(LOCAL_MODULE_TAGS),)
35$(error $(LOCAL_PATH): Package modules must define LOCAL_MODULE_TAGS)
36endif
37
38#$(warning $(LOCAL_PATH) $(LOCAL_PACKAGE_NAME) $(sort $(LOCAL_MODULE_TAGS)))
39
40ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
41$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
42endif
43LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
44
45ifneq ($(strip $(LOCAL_MODULE)),)
46$(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE)
47endif
48LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
49
50# Android packages should use Android resources or assets.
51ifneq (,$(LOCAL_JAVA_RESOURCE_DIRS))
52$(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_DIRS)
53endif
54ifneq (,$(LOCAL_JAVA_RESOURCE_FILES))
55$(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_FILES)
56endif
57
58ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
59$(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
60endif
61LOCAL_MODULE_CLASS := APPS
62
63ifeq (,$(LOCAL_ASSET_DIR))
64LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
65endif
66
67ifeq (,$(LOCAL_RESOURCE_DIR))
68LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
69endif
70
71# this is an app, so add the system libraries to the search path
72LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
73
74#$(warning Finding assets for $(LOCAL_ASSET_DIR))
75
76all_assets := $(call find-subdir-assets,$(LOCAL_ASSET_DIR))
77all_assets := $(addprefix $(LOCAL_ASSET_DIR)/,$(patsubst assets/%,%,$(all_assets)))
78
79all_resources := $(call find-subdir-assets,$(LOCAL_RESOURCE_DIR))
80all_resources := $(addprefix $(LOCAL_RESOURCE_DIR)/,$(patsubst res/%,%,$(all_resources)))
81
82all_res_assets := $(strip $(all_assets) $(all_resources))
83
84# If no assets or resources were found, clear the directory variables so
85# we don't try to build them.
86ifeq (,$(all_assets))
87LOCAL_ASSET_DIR:=
88endif
89ifeq (,$(all_resources))
90LOCAL_RESOURCE_DIR:=
91R_file_stamp :=
92else
93# Make sure that R_file_stamp inherits the proper PRIVATE vars.
94# If R.stamp moves, be sure to update the framework makefile,
95# which has intimate knowledge of its location.
96package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
97R_file_stamp := $(package_expected_intermediates_COMMON)/src/R.stamp
98LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
99endif
100
101LOCAL_BUILT_MODULE_STEM := package.apk
102
103# The dex files go in the package, so we don't
104# want to install them separately for this module.
105old_DONT_INSTALL_DEX_FILES := $(DONT_INSTALL_DEX_FILES)
106DONT_INSTALL_DEX_FILES := true
107#################################
108include $(BUILD_SYSTEM)/java.mk
109#################################
110DONT_INSTALL_DEX_FILES := $(old_DONT_INSTALL_DEX_FILES)
111old_DONT_INSTALL_DEX_FILES =
112
113full_android_manifest := $(LOCAL_PATH)/AndroidManifest.xml
114$(LOCAL_INTERMEDIATE_TARGETS): \
115	PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
116
117ifneq ($(all_resources),)
118
119# Since we don't know where the real R.java file is going to end up,
120# we need to use another file to stand in its place.  We'll just
121# copy the generated file to src/R.stamp, which means it will
122# have the same contents and timestamp as the actual file.
123#
124# At the same time, this will copy the R.java file to a central
125# 'R' directory to make it easier to add the files to an IDE.
126#
127#TODO: use PRIVATE_SOURCE_INTERMEDIATES_DIR instead of
128#      $(intermediates.COMMON)/src
129ifneq ($(package_expected_intermediates_COMMON),$(intermediates.COMMON))
130  $(error $(LOCAL_MODULE): internal error: expected intermediates.COMMON "$(package_expected_intermediates_COMMON)" != intermediates.COMMON "$(intermediates.COMMON)")
131endif
132
133$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
134			$(intermediates.COMMON)/public_resources.xml
135$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(AAPT) | $(ACP)
136	@echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
137	@rm -f $@
138	$(create-resource-java-files)
139	$(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
140					-name Manifest.java 2> /dev/null`; do \
141		dir=`grep package $$GENERATED_MANIFEST_FILE | head -n1 | \
142			awk '{print $$2}' | tr -d ";" | tr . /`; \
143		mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
144		$(ACP) -fpt $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
145	done;
146	$(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
147					-name R.java 2> /dev/null`; do \
148		dir=`grep package $$GENERATED_R_FILE | head -n1 | \
149			awk '{print $$2}' | tr -d ";" | tr . /`; \
150		mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
151		$(ACP) -fpt $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
152			|| exit 31; \
153		$(ACP) -fpt $$GENERATED_R_FILE $@ || exit 32; \
154	done; \
155
156ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
157# Put this module's resources into a PRODUCT-agnositc package that
158# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
159# files.
160resource_export_package := $(intermediates.COMMON)/package-export.apk
161$(R_file_stamp): $(resource_export_package)
162
163# add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
164# can't know anything about PRODUCT.  Clear it out just for this target.
165$(resource_export_package): PRODUCT_AAPT_CONFIG :=
166$(resource_export_package): $(all_res_assets) $(full_android_manifest) $(AAPT)
167	@echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
168	$(create-empty-package)
169	$(add-assets-to-package)
170endif
171
172# Other modules should depend on the BUILT module if
173# they want to use this module's R.java file.
174$(LOCAL_BUILT_MODULE): $(R_file_stamp)
175
176ifneq ($(full_classes_jar),)
177$(full_classes_jar): $(R_file_stamp)
178endif
179
180endif	# all_resources
181
182ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
183# We need to explicitly clear this var so that we don't
184# inherit the value from whomever caused us to be built.
185$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
186else
187# Most packages should link against the resources defined by framework-res.
188# Even if they don't have their own resources, they may use framework
189# resources.
190framework_res_package_export := \
191	$(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
192$(LOCAL_INTERMEDIATE_TARGETS): \
193	PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
194# We can't depend directly on the export.apk file; it won't get its
195# PRIVATE_ vars set up correctly if we do.  Instead, depend on the
196# corresponding R.stamp file, which lists the export.apk as a dependency.
197framework_res_package_export_deps := \
198	$(dir $(framework_res_package_export))src/R.stamp
199$(R_file_stamp): $(framework_res_package_export_deps)
200endif
201
202ifneq ($(full_classes_jar),)
203$(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
204$(LOCAL_BUILT_MODULE): $(built_dex)
205endif # full_classes_jar
206
207
208# Get the list of jni libraries to be included in the apk file.
209
210so_suffix := $($(my_prefix)SHLIB_SUFFIX)
211
212jni_shared_libraries := \
213    $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
214      $(addsuffix $(so_suffix), \
215        $(LOCAL_JNI_SHARED_LIBRARIES)))
216
217# Pick a key to sign the package with.  If this package hasn't specified
218# an explicit certificate, use the default.
219# Secure release builds will have their packages signed after the fact,
220# so it's ok for these private keys to be in the clear.
221ifeq ($(LOCAL_CERTIFICATE),)
222    LOCAL_CERTIFICATE := testkey
223endif
224# If this is not an absolute certificate, assign it to a generic one.
225ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
226    LOCAL_CERTIFICATE := $(SRC_TARGET_DIR)/product/security/$(LOCAL_CERTIFICATE)
227endif
228private_key := $(LOCAL_CERTIFICATE).pk8
229certificate := $(LOCAL_CERTIFICATE).x509.pem
230
231$(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
232$(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
233$(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
234
235PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
236PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
237
238# Define the rule to build the actual package.
239$(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
240$(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries)
241$(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
242	@echo "target Package: $(PRIVATE_MODULE) ($@)"
243	$(create-empty-package)
244	$(add-assets-to-package)
245ifneq ($(jni_shared_libraries),)
246	$(add-jni-shared-libs-to-package)
247endif
248ifneq ($(full_classes_jar),)
249	$(add-dex-to-package)
250endif
251	$(sign-package)
252	@# Alignment must happen after all other zip operations.
253	$(align-package)
254
255# Save information about this package
256PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
257PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
258
259PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
260