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