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