OSDN Git Service

fix archive files being created with perms 000
[android-x86/build.git] / core / Makefile
1 # Put some miscellaneous rules here
2
3 # Pick a reasonable string to use to identify files.
4 ifneq "" "$(filter eng.%,$(BUILD_NUMBER))"
5   # BUILD_NUMBER has a timestamp in it, which means that
6   # it will change every time.  Pick a stable value.
7   FILE_NAME_TAG := eng.$(USER)
8 else
9   FILE_NAME_TAG := $(BUILD_NUMBER)
10 endif
11
12 # -----------------------------------------------------------------
13 # Define rules to copy PRODUCT_COPY_FILES defined by the product.
14 # PRODUCT_COPY_FILES contains words like <source file>:<dest file>.
15 # <dest file> is relative to $(PRODUCT_OUT), so it should look like,
16 # e.g., "system/etc/file.xml".
17 $(foreach cf,$(PRODUCT_COPY_FILES), \
18   $(eval _src := $(call word-colon,1,$(cf))) \
19   $(eval _dest := $(call \
20           append-path,$(PRODUCT_OUT),$(call word-colon,2,$(cf)))) \
21   $(eval $(call copy-one-file,$(_src),$(_dest))) \
22   $(eval ALL_DEFAULT_INSTALLED_MODULES += $(_dest)) \
23  )
24
25 # -----------------------------------------------------------------
26 # docs/index.html
27 gen := $(OUT_DOCS)/index.html
28 ALL_DOCS += $(gen)
29 $(gen): frameworks/base/docs/docs-redirect-index.html
30         @mkdir -p $(dir $@)
31         @cp -f $< $@
32
33 # -----------------------------------------------------------------
34 # default.prop
35 INSTALLED_DEFAULT_PROP_TARGET := $(TARGET_ROOT_OUT)/default.prop
36 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_DEFAULT_PROP_TARGET)
37 ADDITIONAL_DEFAULT_PROPERTIES := \
38         $(call collapse-pairs, $(ADDITIONAL_DEFAULT_PROPERTIES))
39
40 $(INSTALLED_DEFAULT_PROP_TARGET):
41         @echo Target buildinfo: $@
42         @mkdir -p $(dir $@)
43         $(hide) echo "#" > $@; \
44                 echo "# ADDITIONAL_DEFAULT_PROPERTIES" >> $@; \
45                 echo "#" >> $@;
46         $(hide) $(foreach line,$(ADDITIONAL_DEFAULT_PROPERTIES), \
47                 echo "$(line)" >> $@;)
48
49 # -----------------------------------------------------------------
50 # build.prop
51 INSTALLED_BUILD_PROP_TARGET := $(TARGET_OUT)/build.prop
52 ALL_DEFAULT_INSTALLED_MODULES += $(INSTALLED_BUILD_PROP_TARGET)
53 ADDITIONAL_BUILD_PROPERTIES := \
54         $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))
55
56 # A list of arbitrary tags describing the build configuration.
57 # Force ":=" so we can use +=
58 BUILD_VERSION_TAGS := $(BUILD_VERSION_TAGS)
59 ifeq ($(TARGET_BUILD_TYPE),debug)
60   BUILD_VERSION_TAGS += debug
61 endif
62 # Apps are always signed with test keys, and may be re-signed in a post-build
63 # step.  If that happens, the "test-keys" tag will be removed by that step.
64 BUILD_VERSION_TAGS += test-keys
65 BUILD_VERSION_TAGS := $(subst $(space),$(comma),$(sort $(BUILD_VERSION_TAGS)))
66
67 # A human-readable string that descibes this build in detail.
68 build_desc := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER) $(BUILD_VERSION_TAGS)
69 $(INSTALLED_BUILD_PROP_TARGET): PRIVATE_BUILD_DESC := $(build_desc)
70
71 # The string used to uniquely identify this build;  used by the OTA server.
72 ifeq (,$(strip $(BUILD_FINGERPRINT)))
73   BUILD_FINGERPRINT := $(PRODUCT_BRAND)/$(TARGET_PRODUCT)/$(TARGET_DEVICE)/$(TARGET_BOOTLOADER_BOARD_NAME):$(PLATFORM_VERSION)/$(BUILD_ID)/$(BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)
74 endif
75 ifneq ($(words $(BUILD_FINGERPRINT)),1)
76   $(error BUILD_FINGERPRINT cannot contain spaces: "$(BUILD_FINGERPRINT)")
77 endif
78
79 # Display parameters shown under Settings -> About Phone
80 ifeq ($(TARGET_BUILD_VARIANT),user)
81   # User builds should show:
82   # release build number or branch.buld_number non-release builds
83
84   # Dev. branches should have DISPLAY_BUILD_NUMBER set
85   ifeq "true" "$(DISPLAY_BUILD_NUMBER)"
86     BUILD_DISPLAY_ID := $(BUILD_ID).$(BUILD_NUMBER)
87   else
88     BUILD_DISPLAY_ID := $(BUILD_ID)
89   endif
90 else
91   # Non-user builds should show detailed build information
92   BUILD_DISPLAY_ID := $(build_desc)
93 endif
94
95 # Selects the first locale in the list given as the argument,
96 # and splits it into language and region, which each may be
97 # empty.
98 define default-locale
99 $(subst _, , $(firstword $(1)))
100 endef
101
102 # Selects the first locale in the list given as the argument
103 # and returns the language (or the region)
104 define default-locale-language
105 $(word 2, 2, $(call default-locale, $(1)))
106 endef
107 define default-locale-region
108 $(word 3, 3, $(call default-locale, $(1)))
109 endef
110
111 BUILDINFO_SH := build/tools/buildinfo.sh
112 $(INSTALLED_BUILD_PROP_TARGET): $(BUILDINFO_SH) $(INTERNAL_BUILD_ID_MAKEFILE)
113         @echo Target buildinfo: $@
114         @mkdir -p $(dir $@)
115         $(hide) TARGET_BUILD_TYPE="$(TARGET_BUILD_VARIANT)" \
116                         TARGET_DEVICE="$(TARGET_DEVICE)" \
117                         PRODUCT_NAME="$(TARGET_PRODUCT)" \
118                         PRODUCT_BRAND="$(PRODUCT_BRAND)" \
119                         PRODUCT_DEFAULT_LANGUAGE="$(call default-locale-language,$(PRODUCT_LOCALES))" \
120                         PRODUCT_DEFAULT_REGION="$(call default-locale-region,$(PRODUCT_LOCALES))" \
121                         PRODUCT_MODEL="$(PRODUCT_MODEL)" \
122                         PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
123                         PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \
124                         BUILD_ID="$(BUILD_ID)" \
125                         BUILD_DISPLAY_ID="$(BUILD_DISPLAY_ID)" \
126                         BUILD_NUMBER="$(BUILD_NUMBER)" \
127                         PLATFORM_VERSION="$(PLATFORM_VERSION)" \
128                         PLATFORM_SDK_VERSION="$(PLATFORM_SDK_VERSION)" \
129                         PLATFORM_VERSION_CODENAME="$(PLATFORM_VERSION_CODENAME)" \
130                         BUILD_VERSION_TAGS="$(BUILD_VERSION_TAGS)" \
131                         TARGET_BOOTLOADER_BOARD_NAME="$(TARGET_BOOTLOADER_BOARD_NAME)" \
132                         BUILD_FINGERPRINT="$(BUILD_FINGERPRINT)" \
133                         TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
134                         TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \
135                 bash $(BUILDINFO_SH) > $@
136         $(hide) if [ -f $(TARGET_DEVICE_DIR)/system.prop ]; then \
137                   cat $(TARGET_DEVICE_DIR)/system.prop >> $@; \
138                 fi
139         $(if $(ADDITIONAL_BUILD_PROPERTIES), \
140                 $(hide) echo >> $@; \
141                         echo "#" >> $@; \
142                         echo "# ADDITIONAL_BUILD_PROPERTIES" >> $@; \
143                         echo "#" >> $@; )
144         $(hide) $(foreach line,$(ADDITIONAL_BUILD_PROPERTIES), \
145                 echo "$(line)" >> $@;)
146
147 build_desc :=
148
149 # -----------------------------------------------------------------
150 # sdk-build.prop
151 #
152 # There are certain things in build.prop that we don't want to
153 # ship with the sdk; remove them.
154
155 # This must be a list of entire property keys followed by
156 # "=" characters, without any internal spaces.
157 sdk_build_prop_remove := \
158         ro.build.user= \
159         ro.build.host= \
160         ro.product.brand= \
161         ro.product.manufacturer= \
162         ro.product.device=
163 # TODO: Remove this soon-to-be obsolete property
164 sdk_build_prop_remove += ro.build.product=
165 INSTALLED_SDK_BUILD_PROP_TARGET := $(PRODUCT_OUT)/sdk/sdk-build.prop
166 $(INSTALLED_SDK_BUILD_PROP_TARGET): $(INSTALLED_BUILD_PROP_TARGET)
167         @echo SDK buildinfo: $@
168         @mkdir -p $(dir $@)
169         $(hide) grep -v "$(subst $(space),\|,$(strip \
170                                 $(sdk_build_prop_remove)))" $< > $@.tmp
171         $(hide) for x in $(sdk_build_prop_remove); do \
172                                 echo "$$x"generic >> $@.tmp; done
173         $(hide) mv $@.tmp $@
174
175 # -----------------------------------------------------------------
176 # package stats
177 PACKAGE_STATS_FILE := $(PRODUCT_OUT)/package-stats.txt
178 PACKAGES_TO_STAT := \
179     $(sort $(filter $(TARGET_OUT)/% $(TARGET_OUT_DATA)/%, \
180         $(filter %.jar %.apk, $(ALL_DEFAULT_INSTALLED_MODULES))))
181 $(PACKAGE_STATS_FILE): $(PACKAGES_TO_STAT)
182         @echo Package stats: $@
183         @mkdir -p $(dir $@)
184         $(hide) rm -f $@
185         $(hide) build/tools/dump-package-stats $^ > $@
186
187 .PHONY: package-stats
188 package-stats: $(PACKAGE_STATS_FILE)
189
190 # -----------------------------------------------------------------
191 # Cert-to-package mapping.  Used by the post-build signing tools.
192 name := $(TARGET_PRODUCT)
193 ifeq ($(TARGET_BUILD_TYPE),debug)
194   name := $(name)_debug
195 endif
196 name := $(name)-apkcerts-$(FILE_NAME_TAG)
197 intermediates := \
198         $(call intermediates-dir-for,PACKAGING,apkcerts)
199 APKCERTS_FILE := $(intermediates)/$(name).txt
200 # Depending on the built packages isn't exactly right,
201 # but it should guarantee that the apkcerts file is rebuilt
202 # if any packages change which certs they're signed with.
203 all_built_packages := $(foreach p,$(PACKAGES),$(ALL_MODULES.$(p).BUILT))
204 $(APKCERTS_FILE): $(all_built_packages)
205         @echo APK certs list: $@
206         @mkdir -p $(dir $@)
207         @rm -f $@
208         $(hide) $(foreach p,$(PACKAGES),\
209           echo 'name="$(p).apk" certificate="$(PACKAGES.$(p).CERTIFICATE)" \
210                private_key="$(PACKAGES.$(p).PRIVATE_KEY)"' >> $@;)
211
212 .PHONY: apkcerts-list
213 apkcerts-list: $(APKCERTS_FILE)
214
215 # -----------------------------------------------------------------
216 # module info file
217 ifdef CREATE_MODULE_INFO_FILE
218   MODULE_INFO_FILE := $(PRODUCT_OUT)/module-info.txt
219   $(info Generating $(MODULE_INFO_FILE)...)
220   $(shell rm -f $(MODULE_INFO_FILE))
221   $(foreach m,$(ALL_MODULES), \
222     $(shell echo "NAME=\"$(m)\"" \
223         "PATH=\"$(strip $(ALL_MODULES.$(m).PATH))\"" \
224         "TAGS=\"$(strip $(filter-out _%,$(ALL_MODULES.$(m).TAGS)))\"" \
225         "BUILT=\"$(strip $(ALL_MODULES.$(m).BUILT))\"" \
226         "INSTALLED=\"$(strip $(ALL_MODULES.$(m).INSTALLED))\"" >> $(MODULE_INFO_FILE)))
227 endif
228
229 # Rules that need to be present for the simulator, even
230 # if they don't do anything.
231 .PHONY: systemimage
232 systemimage:
233
234 ifneq ($(TARGET_SIMULATOR),true)
235
236 # #################################################################
237 # Targets for boot/OS images
238 # #################################################################
239
240 # -----------------------------------------------------------------
241 # the ramdisk
242 INTERNAL_RAMDISK_FILES := $(filter $(TARGET_ROOT_OUT)/%, \
243         $(ALL_PREBUILT) \
244         $(ALL_COPIED_HEADERS) \
245         $(ALL_GENERATED_SOURCES) \
246         $(ALL_DEFAULT_INSTALLED_MODULES))
247
248 BUILT_RAMDISK_TARGET := $(PRODUCT_OUT)/ramdisk.img
249
250 # We just build this directly to the install location.
251 INSTALLED_RAMDISK_TARGET := $(BUILT_RAMDISK_TARGET)
252 $(INSTALLED_RAMDISK_TARGET): $(MKBOOTFS) $(INTERNAL_RAMDISK_FILES) | $(MINIGZIP)
253         $(call pretty,"Target ram disk: $@")
254         $(hide) $(MKBOOTFS) $(TARGET_ROOT_OUT) | $(MINIGZIP) > $@
255
256
257 ifneq ($(strip $(TARGET_NO_KERNEL)),true)
258
259 # -----------------------------------------------------------------
260 # the boot image, which is a collection of other images.
261 INTERNAL_BOOTIMAGE_ARGS := \
262         $(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
263         --kernel $(INSTALLED_KERNEL_TARGET) \
264         --ramdisk $(INSTALLED_RAMDISK_TARGET)
265
266 INTERNAL_BOOTIMAGE_FILES := $(filter-out --%,$(INTERNAL_BOOTIMAGE_ARGS))
267
268 BOARD_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE))
269 ifdef BOARD_KERNEL_CMDLINE
270   INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)"
271 endif
272
273 BOARD_KERNEL_BASE := $(strip $(BOARD_KERNEL_BASE))
274 ifdef BOARD_KERNEL_BASE
275   INTERNAL_BOOTIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
276 endif
277
278 INSTALLED_BOOTIMAGE_TARGET := $(PRODUCT_OUT)/boot.img
279
280 ifeq ($(TARGET_BOOTIMAGE_USE_EXT2),true)
281 tmp_dir_for_image := $(call intermediates-dir-for,EXECUTABLES,boot_img)/bootimg
282 INTERNAL_BOOTIMAGE_ARGS += --tmpdir $(tmp_dir_for_image)
283 INTERNAL_BOOTIMAGE_ARGS += --genext2fs $(MKEXT2IMG)
284 $(INSTALLED_BOOTIMAGE_TARGET): $(MKEXT2IMG) $(INTERNAL_BOOTIMAGE_FILES)
285         $(call pretty,"Target boot image: $@")
286         $(hide) $(MKEXT2BOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) --output $@
287
288 else # TARGET_BOOTIMAGE_USE_EXT2 != true
289
290 $(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES)
291         $(call pretty,"Target boot image: $@")
292         $(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) --output $@
293         $(hide) $(call assert-max-file-size,$@,$(BOARD_BOOTIMAGE_MAX_SIZE))
294 endif # TARGET_BOOTIMAGE_USE_EXT2
295
296 else    # TARGET_NO_KERNEL
297 # HACK: The top-level targets depend on the bootimage.  Not all targets
298 # can produce a bootimage, though, and emulator targets need the ramdisk
299 # instead.  Fake it out by calling the ramdisk the bootimage.
300 # TODO: make the emulator use bootimages, and make mkbootimg accept
301 #       kernel-less inputs.
302 INSTALLED_BOOTIMAGE_TARGET := $(INSTALLED_RAMDISK_TARGET)
303 endif
304
305 # -----------------------------------------------------------------
306 # NOTICE files
307 #
308 # This needs to be before the systemimage rules, because it adds to
309 # ALL_DEFAULT_INSTALLED_MODULES, which those use to pick which files
310 # go into the systemimage.
311
312 .PHONY: notice_files
313
314 # Create the rule to combine the files into text and html forms
315 # $(1) - Plain text output file
316 # $(2) - HTML output file
317 # $(3) - File title
318 # $(4) - Directory to use.  Notice files are all $(4)/src.  Other
319 #                directories in there will be used for scratch
320 # $(5) - Dependencies for the output files
321 #
322 # The algorithm here is that we go collect a hash for each of the notice
323 # files and write the names of the files that match that hash.  Then
324 # to generate the real files, we go print out all of the files and their
325 # hashes.
326 #
327 # These rules are fairly complex, so they depend on this makefile so if
328 # it changes, they'll run again.
329 #
330 # TODO: We could clean this up so that we just record the locations of the
331 # original notice files instead of making rules to copy them somwehere.
332 # Then we could traverse that without quite as much bash drama.
333 define combine-notice-files
334 $(1) $(2): PRIVATE_MESSAGE := $(3)
335 $(1) $(2) $(4)/hash-timestamp: PRIVATE_DIR := $(4)
336 $(4)/hash-timestamp: $(5) $(BUILD_SYSTEM)/Makefile
337         @echo Finding NOTICE files: $$@
338         $$(hide) rm -rf $$@ $$(PRIVATE_DIR)/hash
339         $$(hide) mkdir -p $$(PRIVATE_DIR)/hash
340         $$(hide) for file in $$$$(find $$(PRIVATE_DIR)/src -type f); do \
341                         hash=$$$$($(MD5SUM) $$$$file | sed -e "s/ .*//"); \
342                         hashfile=$$(PRIVATE_DIR)/hash/$$$$hash; \
343                         echo $$$$file >> $$$$hashfile; \
344                 done
345         $$(hide) touch $$@
346 $(1): $(4)/hash-timestamp
347         @echo Combining NOTICE files: $$@
348         $$(hide) mkdir -p $$(dir $$@)
349         $$(hide) echo $$(PRIVATE_MESSAGE) > $$@
350         $$(hide) find $$(PRIVATE_DIR)/hash -type f | xargs cat | sort | \
351                 sed -e "s:$$(PRIVATE_DIR)/src\(.*\)\.txt:  \1:" >> $$@
352         $$(hide) echo >> $$@
353         $$(hide) echo >> $$@
354         $$(hide) echo >> $$@
355         $$(hide) for hashfile in $$$$(find $$(PRIVATE_DIR)/hash -type f); do \
356                         echo "============================================================"\
357                                 >> $$@; \
358                         echo "Notices for file(s):" >> $$@; \
359                         cat $$$$hashfile | sort | \
360                                 sed -e "s:$$(PRIVATE_DIR)/src\(.*\)\.txt:  \1:" >> \
361                                 $$@; \
362                         echo "------------------------------------------------------------"\
363                                 >> $$@; \
364                         echo >> $$@; \
365                         orig=$$$$(head -n 1 $$$$hashfile); \
366                         cat $$$$orig >> $$@; \
367                         echo >> $$@; \
368                         echo >> $$@; \
369                         echo >> $$@; \
370                 done
371 $(2): $(4)/hash-timestamp
372         @echo Combining NOTICE files: $$@
373         $$(hide) mkdir -p $$(dir $$@)
374         $$(hide) echo "<html><head>" > $$@
375         $$(hide) echo "<style type=\"text/css\">" >> $$@
376         $$(hide) echo "body { padding: 0; font-family: sans-serif; }" >> $$@
377         $$(hide) echo ".same-license { background-color: #eeeeee; border-top: 20px solid white; padding: 10px; }" >> $$@
378         $$(hide) echo ".label { font-weight: bold; }" >> $$@
379         $$(hide) echo ".file-list { margin-left: 1em; font-color: blue; }" >> $$@
380         $$(hide) echo "</style>" >> $$@
381         $$(hide) echo "</head><body topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\">" >> $$@
382         $$(hide) echo "<table cellpading=\"0\" cellspacing=\"0\" border=\"0\">" \
383                 >> $$@
384         $$(hide) for hashfile in $$$$(find $$(PRIVATE_DIR)/hash -type f); do \
385                         cat $$$$hashfile | sort | \
386                                 sed -e "s:$$(PRIVATE_DIR)/src\(.*\)\.txt:  <a name=\"\1\"></a>:" >> \
387                                 $$@; \
388                         echo "<tr><td class=\"same-license\">" >> $$@; \
389                         echo "<div class=\"label\">Notices for file(s):</div>" >> $$@; \
390                         echo "<div class=\"file-list\">" >> $$@; \
391                         cat $$$$hashfile | sort | \
392                                 sed -e "s:$$(PRIVATE_DIR)/src\(.*\)\.txt:  \1<br/>:" >> $$@; \
393                         echo "</div><!-- file-list -->" >> $$@; \
394                         echo >> $$@; \
395                         orig=$$$$(head -n 1 $$$$hashfile); \
396                         echo "<pre class=\"license-text\">" >> $$@; \
397                         cat $$$$orig | sed -e "s/\&/\&amp;/g" | sed -e "s/</\&lt;/g" \
398                                         | sed -e "s/>/\&gt;/g" >> $$@; \
399                         echo "</pre><!-- license-text -->" >> $$@; \
400                         echo "</td></tr><!-- same-license -->" >> $$@; \
401                         echo >> $$@; \
402                         echo >> $$@; \
403                         echo >> $$@; \
404                 done
405         $$(hide) echo "</table>" >> $$@
406         $$(hide) echo "</body></html>" >> $$@
407 notice_files: $(1) $(2)
408 endef
409
410 # TODO These intermediate NOTICE.txt/NOTICE.html files should go into
411 # TARGET_OUT_NOTICE_FILES now that the notice files are gathered from
412 # the src subdirectory.
413
414 target_notice_file_txt := $(TARGET_OUT_INTERMEDIATES)/NOTICE.txt
415 target_notice_file_html := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html
416 target_notice_file_html_gz := $(TARGET_OUT_INTERMEDIATES)/NOTICE.html.gz
417 tools_notice_file_txt := $(HOST_OUT_INTERMEDIATES)/NOTICE.txt
418 tools_notice_file_html := $(HOST_OUT_INTERMEDIATES)/NOTICE.html
419
420 kernel_notice_file := $(TARGET_OUT_NOTICE_FILES)/src/kernel.txt
421
422 $(eval $(call combine-notice-files, \
423                         $(target_notice_file_txt), \
424                         $(target_notice_file_html), \
425                         "Notices for files contained in the filesystem images in this directory:", \
426                         $(TARGET_OUT_NOTICE_FILES), \
427                         $(ALL_DEFAULT_INSTALLED_MODULES) $(kernel_notice_file)))
428
429 $(eval $(call combine-notice-files, \
430                         $(tools_notice_file_txt), \
431                         $(tools_notice_file_html), \
432                         "Notices for files contained in the tools directory:", \
433                         $(HOST_OUT_NOTICE_FILES), \
434                         $(ALL_DEFAULT_INSTALLED_MODULES)))
435
436 # Install the html file at /system/etc/NOTICE.html.gz.
437 # This is not ideal, but this is very late in the game, after a lot of
438 # the module processing has already been done -- in fact, we used the
439 # fact that all that has been done to get the list of modules that we
440 # need notice files for.
441 $(target_notice_file_html_gz): $(target_notice_file_html) | $(MINIGZIP)
442         $(MINIGZIP) -9 < $< > $@
443 installed_notice_html_gz := $(TARGET_OUT)/etc/NOTICE.html.gz
444 $(installed_notice_html_gz): $(target_notice_file_html_gz) | $(ACP)
445         $(copy-file-to-target)
446
447 # if we've been run my mm, mmm, etc, don't reinstall this every time
448 ifeq ($(ONE_SHOT_MAKEFILE),)
449 ALL_DEFAULT_INSTALLED_MODULES += $(installed_notice_html_gz)
450 endif
451
452 # The kernel isn't really a module, so to get its module file in there, we
453 # make the target NOTICE files depend on this particular file too, which will
454 # then be in the right directory for the find in combine-notice-files to work.
455 $(kernel_notice_file): \
456             prebuilt/$(TARGET_PREBUILT_TAG)/kernel/LINUX_KERNEL_COPYING \
457             | $(ACP)
458         @echo Copying: $@
459         $(hide) mkdir -p $(dir $@)
460         $(hide) $(ACP) $< $@
461
462
463 # #################################################################
464 # Targets for user images
465 # #################################################################
466
467 ifeq ($(TARGET_USERIMAGES_USE_EXT2),true)
468 include external/genext2fs/Config.mk
469 INTERNAL_MKUSERFS := $(MKEXT2IMG)
470 else
471 INTERNAL_MKUSERFS := $(MKYAFFS2)
472 endif
473
474 # -----------------------------------------------------------------
475 # system yaffs image
476 #
477 # First, the "unoptimized" image, which contains .apk/.jar files
478 # that contain regular, unoptimized/unverified .dex entries.
479 #
480 systemimage_unopt_intermediates := \
481         $(call intermediates-dir-for,PACKAGING,systemimage_unopt)
482 BUILT_SYSTEMIMAGE_UNOPT := $(systemimage_unopt_intermediates)/system.img
483
484 INTERNAL_SYSTEMIMAGE_FILES := $(filter $(TARGET_OUT)/%, \
485         $(ALL_PREBUILT) \
486         $(ALL_COPIED_HEADERS) \
487         $(ALL_GENERATED_SOURCES) \
488         $(ALL_DEFAULT_INSTALLED_MODULES))
489
490 ifeq ($(TARGET_USERIMAGES_USE_EXT2),true)
491 ## generate an ext2 image
492 # $(1): output file
493 define build-systemimage-target
494     @echo "Target system fs image: $(1)"
495     $(call build-userimage-ext2-target,$(TARGET_OUT),$(1),system,)
496 endef
497
498 else # TARGET_USERIMAGES_USE_EXT2 != true
499
500 ## generate a yaffs2 image
501 # $(1): output file
502 define build-systemimage-target
503     @echo "Target system fs image: $(1)"
504     @mkdir -p $(dir $(1))
505     $(hide) $(MKYAFFS2) -f $(TARGET_OUT) $(1)
506 endef
507 endif # TARGET_USERIMAGES_USE_EXT2
508
509 $(BUILT_SYSTEMIMAGE_UNOPT): $(INTERNAL_SYSTEMIMAGE_FILES) $(INTERNAL_MKUSERFS)
510         $(call build-systemimage-target,$@)
511
512 # The installed image, which may be optimized or unoptimized.
513 #
514 INSTALLED_SYSTEMIMAGE := $(PRODUCT_OUT)/system.img
515
516 ifdef WITH_DEXPREOPT
517   ifndef DISABLE_DEXPREOPT
518     with_dexpreopt := true
519   endif
520 endif
521 ifdef with_dexpreopt
522   # This file will set BUILT_SYSTEMIMAGE and SYSTEMIMAGE_SOURCE_DIR
523   include build/tools/dexpreopt/Config.mk
524 else
525   BUILT_SYSTEMIMAGE := $(BUILT_SYSTEMIMAGE_UNOPT)
526   SYSTEMIMAGE_SOURCE_DIR := $(TARGET_OUT)
527 endif
528
529 $(INSTALLED_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE) | $(ACP)
530         @echo "Install system fs image: $@"
531         $(copy-file-to-target)
532         $(hide) $(call assert-max-file-size,$@,$(BOARD_SYSTEMIMAGE_MAX_SIZE))
533
534 systemimage: $(INSTALLED_SYSTEMIMAGE)
535
536 .PHONY: systemimage-nodeps snod
537 systemimage-nodeps snod: $(filter-out systemimage-nodeps snod,$(MAKECMDGOALS)) \
538                     | $(INTERNAL_MKUSERFS)
539         @echo "make $@: ignoring dependencies"
540         $(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE))
541         $(hide) $(call assert-max-file-size,$(INSTALLED_SYSTEMIMAGE),$(BOARD_SYSTEMIMAGE_MAX_SIZE))
542
543 #######
544 ## system tarball
545 define build-systemtarball-target
546     $(call pretty,"Target system fs tarball: $(INSTALLED_SYSTEMTARBALL_TARGET)")
547     $(MKTARBALL) $(FS_GET_STATS) \
548                 $(PRODUCT_OUT) system $(PRIVATE_SYSTEM_TAR) \
549                 $(INSTALLED_SYSTEMTARBALL_TARGET)
550 endef
551
552 system_tar := $(PRODUCT_OUT)/system.tar
553 INSTALLED_SYSTEMTARBALL_TARGET := $(system_tar).bz2
554 $(INSTALLED_SYSTEMTARBALL_TARGET): PRIVATE_SYSTEM_TAR := $(system_tar)
555 $(INSTALLED_SYSTEMTARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_SYSTEMIMAGE_FILES)
556         $(build-systemtarball-target)
557
558 .PHONY: systemtarball-nodeps
559 systemtarball-nodeps: $(FS_GET_STATS) \
560                       $(filter-out systemtarball-nodeps stnod,$(MAKECMDGOALS))
561         $(build-systemtarball-target)
562
563 .PHONY: stnod
564 stnod: systemtarball-nodeps
565
566
567 # -----------------------------------------------------------------
568 # data partition image
569 INTERNAL_USERDATAIMAGE_FILES := \
570         $(filter $(TARGET_OUT_DATA)/%,$(ALL_DEFAULT_INSTALLED_MODULES))
571
572 ifeq ($(TARGET_USERIMAGES_USE_EXT2),true)
573 ## Generate an ext2 image
574 define build-userdataimage-target
575     $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
576     @mkdir -p $(TARGET_OUT_DATA)
577     $(call build-userimage-ext2-target,$(TARGET_OUT_DATA),$(INSTALLED_USERDATAIMAGE_TARGET),userdata,)
578     $(hide) $(call assert-max-file-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_MAX_SIZE))
579 endef
580
581 else # TARGET_USERIMAGES_USE_EXT2 != true
582
583 ## Generate a yaffs2 image
584 define build-userdataimage-target
585     $(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
586     @mkdir -p $(TARGET_OUT_DATA)
587     $(hide) $(MKYAFFS2) -f $(TARGET_OUT_DATA) $(INSTALLED_USERDATAIMAGE_TARGET)
588     $(hide) $(call assert-max-file-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_MAX_SIZE))
589 endef
590 endif # TARGET_USERIMAGES_USE_EXT2
591
592 BUILT_USERDATAIMAGE_TARGET := $(PRODUCT_OUT)/userdata.img
593
594 # We just build this directly to the install location.
595 INSTALLED_USERDATAIMAGE_TARGET := $(BUILT_USERDATAIMAGE_TARGET)
596 $(INSTALLED_USERDATAIMAGE_TARGET): $(INTERNAL_MKUSERFS) \
597                                    $(INTERNAL_USERDATAIMAGE_FILES)
598         $(build-userdataimage-target)
599
600 .PHONY: userdataimage-nodeps
601 userdataimage-nodeps: $(INTERNAL_MKUSERFS)
602         $(build-userdataimage-target)
603
604 #######
605 ## data partition tarball
606 define build-userdatatarball-target
607     $(call pretty,"Target userdata fs tarball: " \
608                   "$(INSTALLED_USERDATATARBALL_TARGET)")
609     $(MKTARBALL) $(FS_GET_STATS) \
610                 $(PRODUCT_OUT) data $(PRIVATE_USERDATA_TAR) \
611                 $(INSTALLED_USERDATATARBALL_TARGET)
612 endef
613
614 userdata_tar := $(PRODUCT_OUT)/userdata.tar
615 INSTALLED_USERDATATARBALL_TARGET := $(userdata_tar).bz2
616 $(INSTALLED_USERDATATARBALL_TARGET): PRIVATE_USERDATA_TAR := $(userdata_tar)
617 $(INSTALLED_USERDATATARBALL_TARGET): $(FS_GET_STATS) $(INTERNAL_USERDATAIMAGE_FILES)
618         $(build-userdatatarball-target)
619
620 .PHONY: userdatatarball-nodeps
621 userdatatarball-nodeps: $(FS_GET_STATS)
622         $(build-userdatatarball-target)
623
624
625 # If neither TARGET_NO_KERNEL nor TARGET_NO_RECOVERY are true
626 ifeq (,$(filter true, $(TARGET_NO_KERNEL) $(TARGET_NO_RECOVERY)))
627
628 # -----------------------------------------------------------------
629 # Recovery image
630 INSTALLED_RECOVERYIMAGE_TARGET := $(PRODUCT_OUT)/recovery.img
631
632 recovery_initrc := $(call include-path-for, recovery)/etc/init.rc
633 recovery_kernel := $(INSTALLED_KERNEL_TARGET) # same as a non-recovery system
634 recovery_ramdisk := $(PRODUCT_OUT)/ramdisk-recovery.img
635 recovery_build_prop := $(INSTALLED_BUILD_PROP_TARGET)
636 recovery_binary := $(call intermediates-dir-for,EXECUTABLES,recovery)/recovery
637 recovery_resources_common := $(call include-path-for, recovery)/res
638 recovery_resources_private := $(strip $(wildcard $(TARGET_DEVICE_DIR)/recovery/res))
639 recovery_resource_deps := $(shell find $(recovery_resources_common) \
640   $(recovery_resources_private) -type f)
641
642 ifeq ($(recovery_resources_private),)
643   $(info No private recovery resources for TARGET_DEVICE $(TARGET_DEVICE))
644 endif
645
646 INTERNAL_RECOVERYIMAGE_ARGS := \
647         $(addprefix --second ,$(INSTALLED_2NDBOOTLOADER_TARGET)) \
648         --kernel $(recovery_kernel) \
649         --ramdisk $(recovery_ramdisk)
650
651 # Assumes this has already been stripped
652 ifdef BOARD_KERNEL_CMDLINE
653   INTERNAL_RECOVERYIMAGE_ARGS += --cmdline "$(BOARD_KERNEL_CMDLINE)"
654 endif
655 ifdef BOARD_KERNEL_BASE
656   INTERNAL_RECOVERYIMAGE_ARGS += --base $(BOARD_KERNEL_BASE)
657 endif
658
659 # Keys authorized to sign OTA packages this build will accept.  The
660 # build always uses test-keys for this; release packaging tools will
661 # substitute other keys for this one.
662 OTA_PUBLIC_KEYS := $(SRC_TARGET_DIR)/product/security/testkey.x509.pem
663
664 # Generate a file containing the keys that will be read by the
665 # recovery binary.
666 RECOVERY_INSTALL_OTA_KEYS := \
667         $(call intermediates-dir-for,PACKAGING,ota_keys)/keys
668 DUMPKEY_JAR := $(HOST_OUT_JAVA_LIBRARIES)/dumpkey.jar
669 $(RECOVERY_INSTALL_OTA_KEYS): PRIVATE_OTA_PUBLIC_KEYS := $(OTA_PUBLIC_KEYS)
670 $(RECOVERY_INSTALL_OTA_KEYS): $(OTA_PUBLIC_KEYS) $(DUMPKEY_JAR)
671         @echo "DumpPublicKey: $@ <= $(PRIVATE_OTA_PUBLIC_KEYS)"
672         @rm -rf $@
673         @mkdir -p $(dir $@)
674         java -jar $(DUMPKEY_JAR) $(PRIVATE_OTA_PUBLIC_KEYS) > $@
675
676 $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
677                 $(INSTALLED_RAMDISK_TARGET) \
678                 $(INSTALLED_BOOTIMAGE_TARGET) \
679                 $(recovery_binary) \
680                 $(recovery_initrc) $(recovery_kernel) \
681                 $(INSTALLED_2NDBOOTLOADER_TARGET) \
682                 $(recovery_build_prop) $(recovery_resource_deps) \
683                 $(RECOVERY_INSTALL_OTA_KEYS)
684         @echo ----- Making recovery image ------
685         rm -rf $(TARGET_RECOVERY_OUT)
686         mkdir -p $(TARGET_RECOVERY_OUT)
687         mkdir -p $(TARGET_RECOVERY_ROOT_OUT)
688         mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/etc
689         mkdir -p $(TARGET_RECOVERY_ROOT_OUT)/tmp
690         echo Copying baseline ramdisk...
691         cp -R $(TARGET_ROOT_OUT) $(TARGET_RECOVERY_OUT)
692         echo Modifying ramdisk contents...
693         cp -f $(recovery_initrc) $(TARGET_RECOVERY_ROOT_OUT)/
694         cp -f $(recovery_binary) $(TARGET_RECOVERY_ROOT_OUT)/sbin/
695         cp -rf $(recovery_resources_common) $(TARGET_RECOVERY_ROOT_OUT)/
696         $(foreach item,$(recovery_resources_private), \
697           cp -rf $(item) $(TARGET_RECOVERY_ROOT_OUT)/)
698         cp $(RECOVERY_INSTALL_OTA_KEYS) $(TARGET_RECOVERY_ROOT_OUT)/res/keys
699         cat $(INSTALLED_DEFAULT_PROP_TARGET) $(recovery_build_prop) \
700                 > $(TARGET_RECOVERY_ROOT_OUT)/default.prop
701         $(MKBOOTFS) $(TARGET_RECOVERY_ROOT_OUT) | $(MINIGZIP) > $(recovery_ramdisk)
702         $(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) --output $@
703         @echo ----- Made recovery image -------- $@
704         $(hide) $(call assert-max-file-size,$@,$(BOARD_RECOVERYIMAGE_MAX_SIZE))
705
706 else
707 INSTALLED_RECOVERYIMAGE_TARGET :=
708 endif
709
710 .PHONY: recoveryimage
711 recoveryimage: $(INSTALLED_RECOVERYIMAGE_TARGET)
712
713 # -----------------------------------------------------------------
714 # bring in the installer image generation defines if necessary
715 ifeq ($(TARGET_USE_DISKINSTALLER),true)
716 include bootable/diskinstaller/config.mk
717 endif
718
719 # -----------------------------------------------------------------
720 # OTA update package
721 name := $(TARGET_PRODUCT)
722 ifeq ($(TARGET_BUILD_TYPE),debug)
723   name := $(name)_debug
724 endif
725 name := $(name)-ota-$(FILE_NAME_TAG)
726
727 INTERNAL_OTA_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
728 INTERNAL_OTA_INTERMEDIATES_DIR := $(call intermediates-dir-for,PACKAGING,ota)
729
730 # If neither TARGET_NO_KERNEL nor TARGET_NO_RECOVERY are true
731 ifeq (,$(filter true, $(TARGET_NO_KERNEL) $(TARGET_NO_RECOVERY)))
732 INTERNAL_OTA_RECOVERYIMAGE_TARGET := $(INTERNAL_OTA_INTERMEDIATES_DIR)/system/recovery.img
733 else
734 INTERNAL_OTA_RECOVERYIMAGE_TARGET :=
735 endif
736 INTERNAL_OTA_SCRIPT_TARGET := $(INTERNAL_OTA_INTERMEDIATES_DIR)/META-INF/com/google/android/update-script
737
738 # Sign OTA packages with the test key by default.
739 # Actual product deliverables will be re-signed by hand.
740 private_key := $(SRC_TARGET_DIR)/product/security/testkey.pk8
741 certificate := $(SRC_TARGET_DIR)/product/security/testkey.x509.pem
742 $(INTERNAL_OTA_PACKAGE_TARGET): $(private_key) $(certificate) $(SIGNAPK_JAR)
743 $(INTERNAL_OTA_PACKAGE_TARGET): PRIVATE_PRIVATE_KEY := $(private_key)
744 $(INTERNAL_OTA_PACKAGE_TARGET): PRIVATE_CERTIFICATE := $(certificate)
745
746 # Depending on INSTALLED_SYSTEMIMAGE guarantees that SYSTEMIMAGE_SOURCE_DIR
747 # is up-to-date.  We use jar instead of zip so that we can use the -C
748 # switch to avoid cd-ing all over the place.
749 # TODO: Make our own jar-creation tool to avoid all these shenanigans.
750 $(INTERNAL_OTA_PACKAGE_TARGET): \
751                 $(INTERNAL_OTA_SCRIPT_TARGET) \
752                 $(INTERNAL_OTA_RECOVERYIMAGE_TARGET) \
753                 $(INSTALLED_BOOTIMAGE_TARGET) \
754                 $(INSTALLED_RADIOIMAGE_TARGET) \
755                 $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
756                 $(INSTALLED_SYSTEMIMAGE)
757         @echo "Package OTA: $@"
758         $(hide) rm -rf $@
759         $(hide) jar cf $@ \
760                 $(foreach item, \
761                         $(INSTALLED_BOOTIMAGE_TARGET) \
762                         $(INSTALLED_RADIOIMAGE_TARGET) \
763                         $(INSTALLED_ANDROID_INFO_TXT_TARGET), \
764                     -C $(dir $(item)) $(notdir $(item))) \
765                     -C $(INTERNAL_OTA_INTERMEDIATES_DIR) .
766         $(hide) find $(SYSTEMIMAGE_SOURCE_DIR) -type f -print | \
767                 sed 's|^$(dir $(SYSTEMIMAGE_SOURCE_DIR))|-C & |' | \
768                 xargs jar uf $@
769         $(hide) if jar tf $@ | egrep '.{65}' >&2; then \
770                     echo "Path too long (>64 chars) for OTA update" >&2; \
771                     exit 1; \
772                 fi
773         $(sign-package)
774
775 $(INTERNAL_OTA_SCRIPT_TARGET): \
776                 $(HOST_OUT_EXECUTABLES)/make-update-script \
777                 $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
778                 $(INSTALLED_SYSTEMIMAGE)
779         @mkdir -p $(dir $@)
780         @rm -rf $@
781         @echo "Update script: $@"
782         $(hide) TARGET_DEVICE=$(TARGET_DEVICE) \
783                 $< $(SYSTEMIMAGE_SOURCE_DIR) \
784                    $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
785                 > $@
786
787 ifneq (,$(INTERNAL_OTA_RECOVERYIMAGE_TARGET))
788 # This copy is so recovery.img can be in /system within the OTA package.
789 # That way it gets installed into the system image, which in turn installs it.
790 $(INTERNAL_OTA_RECOVERYIMAGE_TARGET): $(INSTALLED_RECOVERYIMAGE_TARGET) | $(ACP)
791         @mkdir -p $(dir $@)
792         $(hide) $(ACP) $< $@
793 endif
794
795 .PHONY: otapackage
796 otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
797
798 # Keys authorized to sign OTA packages this build will accept.  The
799 # build always uses test-keys for this; release packaging tools will
800 # substitute other keys for this one.
801 OTA_PUBLIC_KEYS := $(SRC_TARGET_DIR)/product/security/testkey.x509.pem
802
803 # Build a keystore with the authorized keys in it.
804 # java/android/android/server/checkin/UpdateVerifier.java uses this.
805 ALL_DEFAULT_INSTALLED_MODULES += $(TARGET_OUT_ETC)/security/otacerts.zip
806 $(TARGET_OUT_ETC)/security/otacerts.zip: $(OTA_PUBLIC_KEYS)
807         $(hide) rm -f $@
808         $(hide) mkdir -p $(dir $@)
809         zip -qj $@ $(OTA_PUBLIC_KEYS)
810
811 # The device does not support JKS.
812 # $(hide) for f in $(OTA_PUBLIC_KEYS); do \
813 #   echo "keytool: $@ <= $$f" && \
814 #   keytool -keystore $@ -storepass $(notdir $@) -noprompt \
815 #           -import -file $$f -alias $(notdir $$f) || exit 1; \
816 # done
817
818 # -----------------------------------------------------------------
819 # A zip of the directories that map to the target filesystem.
820 # This zip can be used to create an OTA package or filesystem image
821 # as a post-build step.
822 #
823 name := $(TARGET_PRODUCT)
824 ifeq ($(TARGET_BUILD_TYPE),debug)
825   name := $(name)_debug
826 endif
827 name := $(name)-target_files-$(FILE_NAME_TAG)
828
829 intermediates := $(call intermediates-dir-for,PACKAGING,target_files)
830 BUILT_TARGET_FILES_PACKAGE := $(intermediates)/$(name).zip
831 $(BUILT_TARGET_FILES_PACKAGE): intermediates := $(intermediates)
832 $(BUILT_TARGET_FILES_PACKAGE): \
833                 zip_root := $(intermediates)/$(name)
834
835 # $(1): Directory to copy
836 # $(2): Location to copy it to
837 # The "ls -A" is to prevent "acp s/* d" from failing if s is empty.
838 define package_files-copy-root
839   if [ -d "$(strip $(1))" -a "$$(ls -A $(1))" ]; then \
840     mkdir -p $(2) && \
841     $(ACP) -rd $(strip $(1))/* $(2); \
842   fi
843 endef
844
845 built_ota_tools := \
846         $(call intermediates-dir-for,EXECUTABLES,applypatch)/applypatch \
847         $(call intermediates-dir-for,EXECUTABLES,check_prereq)/check_prereq \
848         $(call intermediates-dir-for,EXECUTABLES,updater)/updater
849 $(BUILT_TARGET_FILES_PACKAGE): PRIVATE_OTA_TOOLS := $(built_ota_tools)
850
851 # Depending on the various images guarantees that the underlying
852 # directories are up-to-date.
853 $(BUILT_TARGET_FILES_PACKAGE): \
854                 $(INTERNAL_OTA_SCRIPT_TARGET) \
855                 $(INSTALLED_BOOTIMAGE_TARGET) \
856                 $(INSTALLED_RADIOIMAGE_TARGET) \
857                 $(INSTALLED_RECOVERYIMAGE_TARGET) \
858                 $(BUILT_SYSTEMIMAGE) \
859                 $(INSTALLED_USERDATAIMAGE_TARGET) \
860                 $(INSTALLED_ANDROID_INFO_TXT_TARGET) \
861                 $(INTERNAL_OTA_SCRIPT_TARGET) \
862                 $(built_ota_tools) \
863                 $(APKCERTS_FILE) \
864                 | $(ACP)
865         @echo "Package target files: $@"
866         $(hide) rm -rf $@ $(zip_root)
867         $(hide) mkdir -p $(dir $@) $(zip_root)
868         @# Components of the recovery image
869         $(hide) mkdir -p $(zip_root)/RECOVERY
870         $(hide) $(call package_files-copy-root, \
871                 $(TARGET_RECOVERY_ROOT_OUT),$(zip_root)/RECOVERY/RAMDISK)
872 ifdef INSTALLED_KERNEL_TARGET
873         $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/RECOVERY/kernel
874 endif
875 ifdef INSTALLED_2NDBOOTLOADER_TARGET
876         $(hide) $(ACP) \
877                 $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/RECOVERY/second
878 endif
879 ifdef BOARD_KERNEL_CMDLINE
880         $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/RECOVERY/cmdline
881 endif
882         @# Components of the boot image
883         $(hide) mkdir -p $(zip_root)/BOOT
884         $(hide) $(call package_files-copy-root, \
885                 $(TARGET_ROOT_OUT),$(zip_root)/BOOT/RAMDISK)
886 ifdef INSTALLED_KERNEL_TARGET
887         $(hide) $(ACP) $(INSTALLED_KERNEL_TARGET) $(zip_root)/BOOT/kernel
888 endif
889 ifdef INSTALLED_2NDBOOTLOADER_TARGET
890         $(hide) $(ACP) \
891                 $(INSTALLED_2NDBOOTLOADER_TARGET) $(zip_root)/BOOT/second
892 endif
893 ifdef BOARD_KERNEL_CMDLINE
894         $(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
895 endif
896 ifdef INSTALLED_RADIOIMAGE_TARGET
897         @# The radio image
898         $(hide) mkdir -p $(zip_root)/RADIO
899         $(hide) $(ACP) $(INSTALLED_RADIOIMAGE_TARGET) $(zip_root)/RADIO/image
900 endif
901         @# Contents of the system image
902         $(hide) $(call package_files-copy-root, \
903                 $(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
904         @# Contents of the data image
905         $(hide) $(call package_files-copy-root, \
906                 $(TARGET_OUT_DATA),$(zip_root)/DATA)
907         @# Extra contents of the OTA package
908         $(hide) mkdir -p $(zip_root)/OTA/bin
909         $(hide) $(call package_files-copy-root, \
910                 $(INTERNAL_OTA_INTERMEDIATES_DIR),$(zip_root)/OTA)
911         $(hide) $(ACP) $(INSTALLED_ANDROID_INFO_TXT_TARGET) $(zip_root)/OTA/
912         $(hide) $(ACP) $(PRIVATE_OTA_TOOLS) $(zip_root)/OTA/bin/
913         @# Files that don't end up in any images, but are necessary to
914         @# build them.
915         $(hide) mkdir -p $(zip_root)/META
916         $(hide) $(ACP) $(APKCERTS_FILE) $(zip_root)/META/apkcerts.txt
917         $(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
918         @# Zip everything up, preserving symlinks
919         $(hide) (cd $(zip_root) && zip -qry ../$(notdir $@) .)
920
921 target-files-package: $(BUILT_TARGET_FILES_PACKAGE)
922
923 # -----------------------------------------------------------------
924 # installed file list
925 # Depending on $(INSTALLED_SYSTEMIMAGE) ensures that it
926 # gets the DexOpt one if we're doing that.
927 INSTALLED_FILES_FILE := $(PRODUCT_OUT)/installed-files.txt
928 $(INSTALLED_FILES_FILE): $(INSTALLED_SYSTEMIMAGE)
929         @echo Installed file list: $@
930         @mkdir -p $(dir $@)
931         @rm -f $@
932         $(hide) build/tools/fileslist.py $(TARGET_OUT) $(TARGET_OUT_DATA) > $@
933
934 .PHONY: installed-file-list
935 installed-file-list: $(INSTALLED_FILES_FILE)
936 $(call dist-for-goals, sdk, $(INSTALLED_FILES_FILE))
937 $(call dist-for-goals, sdk_addon, $(INSTALLED_FILES_FILE))
938
939 # -----------------------------------------------------------------
940 # A zip of the tests that are built when running "make tests".
941 # This is very similar to BUILT_TARGET_FILES_PACKAGE, but we
942 # only grab SYSTEM and DATA, and it's called "*-tests-*.zip".
943 #
944 name := $(TARGET_PRODUCT)
945 ifeq ($(TARGET_BUILD_TYPE),debug)
946   name := $(name)_debug
947 endif
948 name := $(name)-tests-$(FILE_NAME_TAG)
949
950 intermediates := $(call intermediates-dir-for,PACKAGING,tests_zip)
951 BUILT_TESTS_ZIP_PACKAGE := $(intermediates)/$(name).zip
952 $(BUILT_TESTS_ZIP_PACKAGE): intermediates := $(intermediates)
953 $(BUILT_TESTS_ZIP_PACKAGE): zip_root := $(intermediates)/$(name)
954
955 # Depending on the images guarantees that the underlying
956 # directories are up-to-date.
957 $(BUILT_TESTS_ZIP_PACKAGE): \
958                 $(BUILT_SYSTEMIMAGE) \
959                 $(INSTALLED_USERDATAIMAGE_TARGET) \
960                 | $(ACP)
961         @echo "Package test files: $@"
962         $(hide) rm -rf $@ $(zip_root)
963         $(hide) mkdir -p $(dir $@) $(zip_root)
964         @# Some parts of the system image
965         $(hide) $(call package_files-copy-root, \
966                 $(SYSTEMIMAGE_SOURCE_DIR)/xbin,$(zip_root)/SYSTEM/xbin)
967         $(hide) $(call package_files-copy-root, \
968                 $(SYSTEMIMAGE_SOURCE_DIR)/lib,$(zip_root)/SYSTEM/lib)
969         $(hide) $(call package_files-copy-root, \
970                 $(SYSTEMIMAGE_SOURCE_DIR)/framework, \
971                 $(zip_root)/SYSTEM/framework)
972         $(hide) $(ACP) $(SYSTEMIMAGE_SOURCE_DIR)/build.prop $(zip_root)/SYSTEM
973         @# Contents of the data image
974         $(hide) $(call package_files-copy-root, \
975                 $(TARGET_OUT_DATA),$(zip_root)/DATA)
976         $(hide) (cd $(zip_root) && zip -qry ../$(notdir $@) .)
977
978 tests-zip-package: $(BUILT_TESTS_ZIP_PACKAGE)
979
980 # -----------------------------------------------------------------
981 # A zip of the symbols directory.  Keep the full paths to make it
982 # more obvious where these files came from.
983 #
984 name := $(TARGET_PRODUCT)
985 ifeq ($(TARGET_BUILD_TYPE),debug)
986   name := $(name)_debug
987 endif
988 name := $(name)-symbols-$(FILE_NAME_TAG)
989
990 SYMBOLS_ZIP := $(PRODUCT_OUT)/$(name).zip
991 $(SYMBOLS_ZIP): $(INSTALLED_SYSTEMIMAGE) $(INSTALLED_BOOTIMAGE_TARGET)
992         @echo "Package symbols: $@"
993         $(hide) rm -rf $@
994         $(hide) mkdir -p $(dir $@)
995         $(hide) zip -qr $@ $(TARGET_OUT_UNSTRIPPED)
996
997 # -----------------------------------------------------------------
998 # A zip of the Android Apps. Not keeping full path so that we don't
999 # include product names when distributing
1000 #
1001 name := $(TARGET_PRODUCT)
1002 ifeq ($(TARGET_BUILD_TYPE),debug)
1003   name := $(name)_debug
1004 endif
1005 name := $(name)-apps-$(FILE_NAME_TAG)
1006
1007 APPS_ZIP := $(PRODUCT_OUT)/$(name).zip
1008 $(APPS_ZIP): $(INSTALLED_SYSTEMIMAGE)
1009         @echo "Package apps: $@"
1010         $(hide) rm -rf $@
1011         $(hide) mkdir -p $(dir $@)
1012         $(hide) zip -qj $@ $(TARGET_OUT_APPS)/*
1013
1014 endif   # TARGET_SIMULATOR != true
1015
1016 # -----------------------------------------------------------------
1017 # dalvik something
1018 .PHONY: dalvikfiles
1019 dalvikfiles: $(INTERNAL_DALVIK_MODULES)
1020
1021 # -----------------------------------------------------------------
1022 # The update package
1023
1024 INTERNAL_UPDATE_PACKAGE_FILES += \
1025                 $(INSTALLED_BOOTIMAGE_TARGET) \
1026                 $(INSTALLED_RECOVERYIMAGE_TARGET) \
1027                 $(INSTALLED_SYSTEMIMAGE) \
1028                 $(INSTALLED_USERDATAIMAGE_TARGET) \
1029                 $(INSTALLED_ANDROID_INFO_TXT_TARGET)
1030
1031 ifneq ($(strip $(INTERNAL_UPDATE_PACKAGE_FILES)),)
1032
1033 name := $(TARGET_PRODUCT)
1034 ifeq ($(TARGET_BUILD_TYPE),debug)
1035   name := $(name)_debug
1036 endif
1037 name := $(name)-img-$(FILE_NAME_TAG)
1038
1039 INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
1040
1041 $(INTERNAL_UPDATE_PACKAGE_TARGET): $(INTERNAL_UPDATE_PACKAGE_FILES)
1042         @echo "Package: $@"
1043         $(hide) zip -qj $@ $(INTERNAL_UPDATE_PACKAGE_FILES)
1044
1045 else
1046 INTERNAL_UPDATE_PACKAGE_TARGET :=
1047 endif
1048
1049 # -----------------------------------------------------------------
1050 # The emulator package
1051
1052 ifneq ($(TARGET_SIMULATOR),true)
1053
1054 INTERNAL_EMULATOR_PACKAGE_FILES += \
1055         $(HOST_OUT_EXECUTABLES)/emulator$(HOST_EXECUTABLE_SUFFIX) \
1056         prebuilt/android-arm/kernel/kernel-qemu \
1057         $(INSTALLED_RAMDISK_TARGET) \
1058                 $(INSTALLED_SYSTEMIMAGE) \
1059                 $(INSTALLED_USERDATAIMAGE_TARGET)
1060
1061 name := $(TARGET_PRODUCT)-emulator-$(FILE_NAME_TAG)
1062
1063 INTERNAL_EMULATOR_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
1064
1065 $(INTERNAL_EMULATOR_PACKAGE_TARGET): $(INTERNAL_EMULATOR_PACKAGE_FILES)
1066         @echo "Package: $@"
1067         $(hide) zip -qj $@ $(INTERNAL_EMULATOR_PACKAGE_FILES)
1068
1069 endif
1070
1071 # -----------------------------------------------------------------
1072 # The pdk package (Platform Development Kit)
1073
1074 ifneq (,$(filter pdk,$(MAKECMDGOALS)))
1075   include development/pdk/Pdk.mk
1076 endif
1077
1078 # -----------------------------------------------------------------
1079 # The SDK
1080
1081 ifneq ($(TARGET_SIMULATOR),true)
1082
1083 # The SDK includes host-specific components, so it belongs under HOST_OUT.
1084 sdk_dir := $(HOST_OUT)/sdk
1085
1086 # Build a name that looks like:
1087 #
1088 #     linux-x86   --> android-sdk_12345_linux-x86
1089 #     darwin-x86  --> android-sdk_12345_mac-x86
1090 #     windows-x86 --> android-sdk_12345_windows
1091 #
1092 sdk_name := android-sdk_$(FILE_NAME_TAG)
1093 ifeq ($(HOST_OS),darwin)
1094   INTERNAL_SDK_HOST_OS_NAME := mac
1095 else
1096   INTERNAL_SDK_HOST_OS_NAME := $(HOST_OS)
1097 endif
1098 ifneq ($(HOST_OS),windows)
1099   INTERNAL_SDK_HOST_OS_NAME := $(INTERNAL_SDK_HOST_OS_NAME)-$(HOST_ARCH)
1100 endif
1101 sdk_name := $(sdk_name)_$(INTERNAL_SDK_HOST_OS_NAME)
1102
1103 sdk_dep_file := $(sdk_dir)/sdk_deps.mk
1104
1105 ATREE_FILES :=
1106 -include $(sdk_dep_file)
1107
1108 # if we don't have a real list, then use "everything"
1109 ifeq ($(strip $(ATREE_FILES)),)
1110 ATREE_FILES := \
1111         $(ALL_PREBUILT) \
1112         $(ALL_COPIED_HEADERS) \
1113         $(ALL_GENERATED_SOURCES) \
1114         $(ALL_DEFAULT_INSTALLED_MODULES) \
1115         $(INSTALLED_RAMDISK_TARGET) \
1116         $(ALL_DOCS) \
1117         $(ALL_SDK_FILES)
1118 endif
1119
1120 atree_dir := development/build
1121
1122 sdk_atree_files := \
1123         $(atree_dir)/sdk.exclude.atree \
1124         $(atree_dir)/sdk.atree \
1125         $(atree_dir)/sdk-$(HOST_OS)-$(HOST_ARCH).atree
1126
1127 deps := \
1128         $(target_notice_file_txt) \
1129         $(tools_notice_file_txt) \
1130         $(OUT_DOCS)/offline-sdk-timestamp \
1131         $(INTERNAL_UPDATE_PACKAGE_TARGET) \
1132         $(INSTALLED_SDK_BUILD_PROP_TARGET) \
1133         $(ATREE_FILES) \
1134         $(atree_dir)/sdk.atree \
1135         $(HOST_OUT_EXECUTABLES)/atree \
1136     $(HOST_OUT_EXECUTABLES)/line_endings
1137
1138 INTERNAL_SDK_TARGET := $(sdk_dir)/$(sdk_name).zip
1139 $(INTERNAL_SDK_TARGET): PRIVATE_NAME := $(sdk_name)
1140 $(INTERNAL_SDK_TARGET): PRIVATE_DIR := $(sdk_dir)/$(sdk_name)
1141 $(INTERNAL_SDK_TARGET): PRIVATE_DEP_FILE := $(sdk_dep_file)
1142 $(INTERNAL_SDK_TARGET): PRIVATE_INPUT_FILES := $(sdk_atree_files)
1143
1144 # Set SDK_GNU_ERROR to non-empty to fail when a GNU target is built.
1145 #
1146 #SDK_GNU_ERROR := true
1147
1148 $(INTERNAL_SDK_TARGET): $(deps)
1149         @echo "Package SDK: $@"
1150         $(hide) rm -rf $(PRIVATE_DIR) $@
1151         $(hide) for f in $(target_gnu_MODULES); do \
1152           if [ -f $$f ]; then \
1153             echo SDK: $(if $(SDK_GNU_ERROR),ERROR:,warning:) \
1154                 including GNU target $$f >&2; \
1155             FAIL=$(SDK_GNU_ERROR); \
1156           fi; \
1157         done; \
1158         if [ $$FAIL ]; then exit 1; fi
1159         $(hide) ( \
1160                 $(HOST_OUT_EXECUTABLES)/atree \
1161                 $(addprefix -f ,$(PRIVATE_INPUT_FILES)) \
1162                         -m $(PRIVATE_DEP_FILE) \
1163                         -I . \
1164                         -I $(PRODUCT_OUT) \
1165                         -I $(HOST_OUT) \
1166                         -I $(TARGET_COMMON_OUT_ROOT) \
1167                         -v "PLATFORM_NAME=android-$(PLATFORM_VERSION)" \
1168                         -o $(PRIVATE_DIR) && \
1169                 cp -f $(target_notice_file_txt) \
1170                                 $(PRIVATE_DIR)/platforms/android-$(PLATFORM_VERSION)/images/NOTICE.txt && \
1171                 cp -f $(tools_notice_file_txt) $(PRIVATE_DIR)/tools/NOTICE.txt && \
1172                 HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
1173                 development/tools/scripts/sdk_clean.sh $(PRIVATE_DIR) && \
1174                 chmod -R ug+rwX $(PRIVATE_DIR) && \
1175                 cd $(dir $@) && zip -rq $(notdir $@) $(PRIVATE_NAME) \
1176         ) || ( rm -rf $(PRIVATE_DIR) $@ && exit 44 )
1177
1178 endif # !simulator
1179
1180 # -----------------------------------------------------------------
1181 # Findbugs
1182 INTERNAL_FINDBUGS_XML_TARGET := $(PRODUCT_OUT)/findbugs.xml
1183 INTERNAL_FINDBUGS_HTML_TARGET := $(PRODUCT_OUT)/findbugs.html
1184 $(INTERNAL_FINDBUGS_XML_TARGET): $(ALL_FINDBUGS_FILES)
1185         @echo UnionBugs: $@
1186         $(hide) prebuilt/common/findbugs/bin/unionBugs $(ALL_FINDBUGS_FILES) \
1187         > $@
1188 $(INTERNAL_FINDBUGS_HTML_TARGET): $(INTERNAL_FINDBUGS_XML_TARGET)
1189         @echo ConvertXmlToText: $@
1190         $(hide) prebuilt/common/findbugs/bin/convertXmlToText -html:fancy.xsl \
1191         $(INTERNAL_FINDBUGS_XML_TARGET) > $@
1192
1193 # -----------------------------------------------------------------
1194 # Findbugs
1195
1196 # -----------------------------------------------------------------
1197 # These are some additional build tasks that need to be run.
1198 include $(sort $(wildcard $(BUILD_SYSTEM)/tasks/*.mk))