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