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