OSDN Git Service

original
[gb-231r1-is01/GB_2.3_IS01.git] / build / 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
29 # If this makefile is being read from within an inheritance,
30 # use the new values.
31 skip_definition:=
32 ifdef LOCAL_PACKAGE_OVERRIDES
33   package_overridden := $(call set-inherited-package-variables)
34   ifeq ($(strip $(package_overridden)),)
35     skip_definition := true
36   endif
37 endif
38
39 ifndef skip_definition
40
41 LOCAL_PACKAGE_NAME := $(strip $(LOCAL_PACKAGE_NAME))
42 ifeq ($(LOCAL_PACKAGE_NAME),)
43 $(error $(LOCAL_PATH): Package modules must define LOCAL_PACKAGE_NAME)
44 endif
45
46 ifneq ($(strip $(LOCAL_MODULE_SUFFIX)),)
47 $(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE_SUFFIX)
48 endif
49 LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
50
51 ifneq ($(strip $(LOCAL_MODULE)),)
52 $(error $(LOCAL_PATH): Package modules may not define LOCAL_MODULE)
53 endif
54 LOCAL_MODULE := $(LOCAL_PACKAGE_NAME)
55
56 # Android packages should use Android resources or assets.
57 ifneq (,$(LOCAL_JAVA_RESOURCE_DIRS))
58 $(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_DIRS)
59 endif
60 ifneq (,$(LOCAL_JAVA_RESOURCE_FILES))
61 $(error $(LOCAL_PATH): Package modules may not set LOCAL_JAVA_RESOURCE_FILES)
62 endif
63
64 ifeq ($(strip $(LOCAL_MANIFEST_FILE)),)
65 LOCAL_MANIFEST_FILE := AndroidManifest.xml
66 endif
67
68 ifneq ($(strip $(LOCAL_MODULE_CLASS)),)
69 $(error $(LOCAL_PATH): Package modules may not set LOCAL_MODULE_CLASS)
70 endif
71 LOCAL_MODULE_CLASS := APPS
72
73 # Package LOCAL_MODULE_TAGS default to optional
74 LOCAL_MODULE_TAGS := $(strip $(LOCAL_MODULE_TAGS))
75 ifeq ($(LOCAL_MODULE_TAGS),)
76 LOCAL_MODULE_TAGS := optional
77 endif
78
79 #$(warning $(LOCAL_PATH) $(LOCAL_PACKAGE_NAME) $(sort $(LOCAL_MODULE_TAGS)))
80
81 ifeq ($(filter tests, $(LOCAL_MODULE_TAGS)),)
82 # Force localization check if it's not tagged as tests.
83 LOCAL_AAPT_FLAGS := $(LOCAL_AAPT_FLAGS) -z
84 endif
85
86 ifeq (,$(LOCAL_ASSET_DIR))
87 LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
88 endif
89
90 ifeq (,$(LOCAL_RESOURCE_DIR))
91   LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
92 endif
93 LOCAL_RESOURCE_DIR := \
94   $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \
95     $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
96   $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \
97     $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \
98   $(LOCAL_RESOURCE_DIR)
99
100 # this is an app, so add the system libraries to the search path
101 LOCAL_AIDL_INCLUDES += $(FRAMEWORKS_BASE_JAVA_SRC_DIRS)
102
103 #$(warning Finding assets for $(LOCAL_ASSET_DIR))
104
105 all_assets := $(call find-subdir-assets,$(LOCAL_ASSET_DIR))
106 all_assets := $(addprefix $(LOCAL_ASSET_DIR)/,$(patsubst assets/%,%,$(all_assets)))
107
108 all_resources := $(strip \
109     $(foreach dir, $(LOCAL_RESOURCE_DIR), \
110       $(addprefix $(dir)/, \
111         $(patsubst res/%,%, \
112           $(call find-subdir-assets,$(dir)) \
113          ) \
114        ) \
115      ))
116
117 all_res_assets := $(strip $(all_assets) $(all_resources))
118
119 package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
120 # If no assets or resources were found, clear the directory variables so
121 # we don't try to build them.
122 ifeq (,$(all_assets))
123 LOCAL_ASSET_DIR:=
124 endif
125 ifeq (,$(all_resources))
126 LOCAL_RESOURCE_DIR:=
127 R_file_stamp :=
128 else
129 # Make sure that R_file_stamp inherits the proper PRIVATE vars.
130 # If R.stamp moves, be sure to update the framework makefile,
131 # which has intimate knowledge of its location.
132 R_file_stamp := $(package_expected_intermediates_COMMON)/src/R.stamp
133 LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
134 endif
135
136 LOCAL_BUILT_MODULE_STEM := package.apk
137
138 LOCAL_PROGUARD_ENABLED:=$(strip $(LOCAL_PROGUARD_ENABLED))
139 ifndef LOCAL_PROGUARD_ENABLED
140 ifneq ($(filter user userdebug, $(TARGET_BUILD_VARIANT)),)
141     # turn on Proguard by default for user & userdebug build
142     LOCAL_PROGUARD_ENABLED :=full
143 endif
144 endif
145 ifeq ($(LOCAL_PROGUARD_ENABLED),disabled)
146     # the package explicitly request to disable proguard.
147     LOCAL_PROGUARD_ENABLED :=
148 endif
149 proguard_options_file :=
150 ifneq ($(LOCAL_PROGUARD_ENABLED),custom)
151 ifneq ($(all_resources),)
152     proguard_options_file := $(package_expected_intermediates_COMMON)/proguard_options
153 endif # all_resources
154 endif # !custom
155 LOCAL_PROGUARD_FLAGS := $(addprefix -include ,$(proguard_options_file)) $(LOCAL_PROGUARD_FLAGS)
156
157 ifeq (true,$(WITH_DEXPREOPT))
158 ifneq (,$(LOCAL_SRC_FILES))
159 ifndef LOCAL_DEX_PREOPT
160 LOCAL_DEX_PREOPT := true
161 endif
162 endif
163 endif
164
165 # The dex files go in the package, so we don't
166 # want to install them separately for this module.
167 old_DONT_INSTALL_DEX_FILES := $(DONT_INSTALL_DEX_FILES)
168 DONT_INSTALL_DEX_FILES := true
169 #################################
170 include $(BUILD_SYSTEM)/java.mk
171 #################################
172 DONT_INSTALL_DEX_FILES := $(old_DONT_INSTALL_DEX_FILES)
173 old_DONT_INSTALL_DEX_FILES =
174
175 full_android_manifest := $(LOCAL_PATH)/$(LOCAL_MANIFEST_FILE)
176 $(LOCAL_INTERMEDIATE_TARGETS): \
177         PRIVATE_ANDROID_MANIFEST := $(full_android_manifest)
178
179 ifneq ($(all_resources),)
180
181 # Since we don't know where the real R.java file is going to end up,
182 # we need to use another file to stand in its place.  We'll just
183 # copy the generated file to src/R.stamp, which means it will
184 # have the same contents and timestamp as the actual file.
185 #
186 # At the same time, this will copy the R.java file to a central
187 # 'R' directory to make it easier to add the files to an IDE.
188 #
189 #TODO: use PRIVATE_SOURCE_INTERMEDIATES_DIR instead of
190 #      $(intermediates.COMMON)/src
191 ifneq ($(package_expected_intermediates_COMMON),$(intermediates.COMMON))
192   $(error $(LOCAL_MODULE): internal error: expected intermediates.COMMON "$(package_expected_intermediates_COMMON)" != intermediates.COMMON "$(intermediates.COMMON)")
193 endif
194
195 $(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
196                         $(intermediates.COMMON)/public_resources.xml
197 $(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
198 $(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(AAPT) | $(ACP)
199         @echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
200         @rm -f $@
201         $(create-resource-java-files)
202         $(hide) for GENERATED_MANIFEST_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
203                                         -name Manifest.java 2> /dev/null`; do \
204                 dir=`grep package $$GENERATED_MANIFEST_FILE | head -n1 | \
205                         awk '{print $$2}' | tr -d ";" | tr . /`; \
206                 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
207                 $(ACP) -fpt $$GENERATED_MANIFEST_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
208         done;
209         $(hide) for GENERATED_R_FILE in `find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) \
210                                         -name R.java 2> /dev/null`; do \
211                 dir=`grep package $$GENERATED_R_FILE | head -n1 | \
212                         awk '{print $$2}' | tr -d ";" | tr . /`; \
213                 mkdir -p $(TARGET_COMMON_OUT_ROOT)/R/$$dir; \
214                 $(ACP) -fpt $$GENERATED_R_FILE $(TARGET_COMMON_OUT_ROOT)/R/$$dir \
215                         || exit 31; \
216                 $(ACP) -fpt $$GENERATED_R_FILE $@ || exit 32; \
217         done; \
218
219 $(proguard_options_file): $(R_file_stamp)
220
221 ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
222 # Put this module's resources into a PRODUCT-agnositc package that
223 # other packages can use to build their own PRODUCT-agnostic R.java (etc.)
224 # files.
225 resource_export_package := $(intermediates.COMMON)/package-export.apk
226 $(R_file_stamp): $(resource_export_package)
227
228 # add-assets-to-package looks at PRODUCT_AAPT_CONFIG, but this target
229 # can't know anything about PRODUCT.  Clear it out just for this target.
230 $(resource_export_package): PRODUCT_AAPT_CONFIG :=
231 $(resource_export_package): $(all_res_assets) $(full_android_manifest) $(AAPT)
232         @echo "target Export Resources: $(PRIVATE_MODULE) ($@)"
233         $(create-empty-package)
234         $(add-assets-to-package)
235 endif
236
237 # Other modules should depend on the BUILT module if
238 # they want to use this module's R.java file.
239 $(LOCAL_BUILT_MODULE): $(R_file_stamp)
240
241 ifneq ($(full_classes_jar),)
242 # If full_classes_jar is non-empty, we're building sources.
243 # If we're building sources, the initial javac step (which
244 # produces full_classes_compiled_jar) needs to ensure the
245 # R.java and Manifest.java files have been generated first.
246 $(full_classes_compiled_jar): $(R_file_stamp)
247 endif
248
249 endif   # all_resources
250
251 ifeq ($(LOCAL_NO_STANDARD_LIBRARIES),true)
252 # We need to explicitly clear this var so that we don't
253 # inherit the value from whomever caused us to be built.
254 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_AAPT_INCLUDES :=
255 else
256 # Most packages should link against the resources defined by framework-res.
257 # Even if they don't have their own resources, they may use framework
258 # resources.
259 ifneq ($(filter-out current,$(LOCAL_SDK_VERSION)),)
260 # for released sdk versions, the platform resources were built into android.jar.
261 framework_res_package_export := \
262         $(HISTORICAL_SDK_VERSIONS_ROOT)/$(LOCAL_SDK_VERSION)/android.jar
263 framework_res_package_export_deps := $(framework_res_package_export)
264 else # LOCAL_SDK_VERSION
265 framework_res_package_export := \
266         $(call intermediates-dir-for,APPS,framework-res,,COMMON)/package-export.apk
267 # We can't depend directly on the export.apk file; it won't get its
268 # PRIVATE_ vars set up correctly if we do.  Instead, depend on the
269 # corresponding R.stamp file, which lists the export.apk as a dependency.
270 framework_res_package_export_deps := \
271         $(dir $(framework_res_package_export))src/R.stamp
272 endif # LOCAL_SDK_VERSION
273 $(R_file_stamp): $(framework_res_package_export_deps)
274 $(LOCAL_INTERMEDIATE_TARGETS): \
275         PRIVATE_AAPT_INCLUDES := $(framework_res_package_export)
276 endif # LOCAL_NO_STANDARD_LIBRARIES
277
278 ifneq ($(full_classes_jar),)
279 $(LOCAL_BUILT_MODULE): PRIVATE_DEX_FILE := $(built_dex)
280 $(LOCAL_BUILT_MODULE): $(built_dex)
281 endif # full_classes_jar
282
283
284 # Get the list of jni libraries to be included in the apk file.
285
286 so_suffix := $($(my_prefix)SHLIB_SUFFIX)
287
288 jni_shared_libraries := \
289     $(addprefix $($(my_prefix)OUT_INTERMEDIATE_LIBRARIES)/, \
290       $(addsuffix $(so_suffix), \
291         $(LOCAL_JNI_SHARED_LIBRARIES)))
292
293 # Pick a key to sign the package with.  If this package hasn't specified
294 # an explicit certificate, use the default.
295 # Secure release builds will have their packages signed after the fact,
296 # so it's ok for these private keys to be in the clear.
297 ifeq ($(LOCAL_CERTIFICATE),)
298     LOCAL_CERTIFICATE := testkey
299 endif
300
301 ifeq ($(LOCAL_CERTIFICATE),EXTERNAL)
302   # The special value "EXTERNAL" means that we will sign it with the
303   # default testkey, apply predexopt, but then expect the final .apk
304   # (after dexopting) to be signed by an outside tool.
305   LOCAL_CERTIFICATE := testkey
306   PACKAGES.$(LOCAL_PACKAGE_NAME).EXTERNAL_KEY := 1
307 endif
308
309 # If this is not an absolute certificate, assign it to a generic one.
310 ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
311     LOCAL_CERTIFICATE := $(SRC_TARGET_DIR)/product/security/$(LOCAL_CERTIFICATE)
312 endif
313 private_key := $(LOCAL_CERTIFICATE).pk8
314 certificate := $(LOCAL_CERTIFICATE).x509.pem
315
316 $(LOCAL_BUILT_MODULE): $(private_key) $(certificate) $(SIGNAPK_JAR)
317 $(LOCAL_BUILT_MODULE): PRIVATE_PRIVATE_KEY := $(private_key)
318 $(LOCAL_BUILT_MODULE): PRIVATE_CERTIFICATE := $(certificate)
319
320 PACKAGES.$(LOCAL_PACKAGE_NAME).PRIVATE_KEY := $(private_key)
321 PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate)
322
323 # Define the rule to build the actual package.
324 $(LOCAL_BUILT_MODULE): $(AAPT) | $(ZIPALIGN)
325 ifeq ($(LOCAL_DEX_PREOPT),true)
326 # Make sure the boot jars get dexpreopt-ed first
327 $(LOCAL_BUILT_MODULE): $(DEXPREOPT_BOOT_ODEXS) | $(DEXPREOPT) $(DEXOPT)
328 endif
329 $(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries)
330 ifneq ($(TARGET_BUILD_APPS),)
331     # Include all resources for unbundled apps.
332     $(LOCAL_BUILT_MODULE): PRODUCT_AAPT_CONFIG :=
333 endif
334 $(LOCAL_BUILT_MODULE): $(all_res_assets) $(jni_shared_libraries) $(full_android_manifest)
335         @echo "target Package: $(PRIVATE_MODULE) ($@)"
336         $(create-empty-package)
337         $(add-assets-to-package)
338 ifneq ($(jni_shared_libraries),)
339         $(add-jni-shared-libs-to-package)
340 endif
341 ifneq ($(full_classes_jar),)
342         $(add-dex-to-package)
343 endif
344         $(sign-package)
345         @# Alignment must happen after all other zip operations.
346         $(align-package)
347 ifeq ($(LOCAL_DEX_PREOPT),true)
348         $(hide) rm -f $(patsubst %.apk,%.odex,$@)
349         $(call dexpreopt-one-file,$@,$(patsubst %.apk,%.odex,$@))
350         $(call dexpreopt-remove-classes.dex,$@)
351
352 built_odex := $(basename $(LOCAL_BUILT_MODULE)).odex
353 $(built_odex): $(LOCAL_BUILT_MODULE)
354 endif
355
356 # Save information about this package
357 PACKAGES.$(LOCAL_PACKAGE_NAME).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
358 PACKAGES.$(LOCAL_PACKAGE_NAME).RESOURCE_FILES := $(all_resources)
359
360 PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
361
362 endif # skip_definition