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