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