OSDN Git Service

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