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