OSDN Git Service

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