OSDN Git Service

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