OSDN Git Service

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