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