The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2008 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | # |
| 18 | # Included by config/Makefile. |
| 19 | # Defines the pieces necessary for the dexpreopt process. |
| 20 | # |
| 21 | # inputs: INSTALLED_RAMDISK_TARGET, BUILT_SYSTEMIMAGE_UNOPT |
| 22 | # outputs: BUILT_SYSTEMIMAGE, SYSTEMIMAGE_SOURCE_DIR |
| 23 | # |
| 24 | LOCAL_PATH := $(my-dir) |
| 25 | |
| 26 | # TODO: see if we can make the .odex files not be product-specific. |
| 27 | # They can't be completely common, though, because their format |
| 28 | # depends on the architecture of the target system; ARM and x86 |
| 29 | # would have different versions. |
| 30 | intermediates := \ |
| 31 | $(call intermediates-dir-for,PACKAGING,dexpreopt) |
| 32 | dexpreopt_system_dir := $(intermediates)/system |
| 33 | built_afar := $(call intermediates-dir-for,EXECUTABLES,afar)/afar |
| 34 | built_dowrapper := \ |
| 35 | $(call intermediates-dir-for,EXECUTABLES,dexopt-wrapper)/dexopt-wrapper |
| 36 | |
| 37 | # Generate a stripped-down init.rc based on the real one. |
| 38 | dexpreopt_initrc := $(intermediates)/etc/init.rc |
| 39 | geninitrc_script := $(LOCAL_PATH)/geninitrc.awk |
| 40 | $(dexpreopt_initrc): script := $(geninitrc_script) |
| 41 | $(dexpreopt_initrc): system/core/rootdir/init.rc $(geninitrc_script) |
| 42 | @echo "Dexpreopt init.rc: $@" |
| 43 | @mkdir -p $(dir $@) |
| 44 | $(hide) awk -f $(script) < $< > $@ |
| 45 | |
| 46 | BUILT_DEXPREOPT_RAMDISK := $(intermediates)/ramdisk.img |
| 47 | $(BUILT_DEXPREOPT_RAMDISK): intermediates := $(intermediates) |
| 48 | $(BUILT_DEXPREOPT_RAMDISK): dexpreopt_root_out := $(intermediates)/root |
| 49 | $(BUILT_DEXPREOPT_RAMDISK): dexpreopt_initrc := $(dexpreopt_initrc) |
| 50 | $(BUILT_DEXPREOPT_RAMDISK): built_afar := $(built_afar) |
| 51 | $(BUILT_DEXPREOPT_RAMDISK): built_dowrapper := $(built_dowrapper) |
| 52 | $(BUILT_DEXPREOPT_RAMDISK): \ |
| 53 | $(INSTALLED_RAMDISK_TARGET) \ |
| 54 | $(dexpreopt_initrc) \ |
| 55 | $(built_afar) \ |
| 56 | $(built_dowrapper) \ |
| 57 | | $(MKBOOTFS) $(ACP) |
| 58 | $(BUILT_DEXPREOPT_RAMDISK): |
| 59 | @echo "Dexpreopt ramdisk: $@" |
| 60 | $(hide) rm -f $@ |
| 61 | $(hide) rm -rf $(dexpreopt_root_out) |
| 62 | $(hide) mkdir -p $(dexpreopt_root_out) |
| 63 | $(hide) $(ACP) -rd $(TARGET_ROOT_OUT) $(intermediates) |
| 64 | $(hide) $(ACP) -f $(dexpreopt_initrc) $(dexpreopt_root_out)/ |
| 65 | $(hide) $(ACP) $(built_afar) $(dexpreopt_root_out)/sbin/ |
| 66 | $(hide) $(ACP) $(built_dowrapper) $(dexpreopt_root_out)/sbin/ |
| 67 | $(MKBOOTFS) $(dexpreopt_root_out) | gzip > $@ |
| 68 | |
| 69 | sign_dexpreopt := true |
| 70 | ifdef sign_dexpreopt |
| 71 | # Such a huge hack. We need to re-sign the .apks with the |
| 72 | # same certs that they were originally signed with. |
| 73 | dexpreopt_package_certs_file := $(intermediates)/package-certs |
| 74 | $(shell mkdir -p $(intermediates)) |
| 75 | $(shell rm -f $(dexpreopt_package_certs_file)) |
| 76 | $(foreach p,$(PACKAGES),\ |
| 77 | $(shell echo "$(p) $(PACKAGES.$(p).CERTIFICATE) $(PACKAGES.$(p).PRIVATE_KEY)" >> $(dexpreopt_package_certs_file))) |
| 78 | endif |
| 79 | |
Jean-Baptiste Queru | e6b4e5b | 2009-11-12 18:45:15 -0800 | [diff] [blame^] | 80 | # The kernel used for ARMv7 system images is different |
| 81 | ifeq ($(TARGET_ARCH_VARIANT),armv7-a) |
| 82 | BUILD_DEXPREOPT_KERNEL := prebuilt/android-arm/kernel/kernel-qemu-armv7 |
| 83 | else |
| 84 | BUILD_DEXPREOPT_KERNEL := prebuilt/android-arm/kernel/kernel-qemu |
| 85 | endif |
| 86 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 87 | # Build an optimized image from the unoptimized image |
| 88 | BUILT_DEXPREOPT_SYSTEMIMAGE := $(intermediates)/system.img |
| 89 | $(BUILT_DEXPREOPT_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE_UNOPT) |
| 90 | $(BUILT_DEXPREOPT_SYSTEMIMAGE): $(BUILT_DEXPREOPT_RAMDISK) |
| 91 | $(BUILT_DEXPREOPT_SYSTEMIMAGE): | $(DEXPREOPT) $(ACP) $(ZIPALIGN) |
| 92 | $(BUILT_DEXPREOPT_SYSTEMIMAGE): SYSTEM_DIR := $(dexpreopt_system_dir) |
| 93 | $(BUILT_DEXPREOPT_SYSTEMIMAGE): DEXPREOPT_TMP := $(intermediates)/emutmp |
| 94 | ifdef sign_dexpreopt |
| 95 | $(BUILT_DEXPREOPT_SYSTEMIMAGE): | $(SIGNAPK_JAR) |
| 96 | endif |
| 97 | $(BUILT_DEXPREOPT_SYSTEMIMAGE): |
| 98 | @rm -f $@ |
| 99 | @echo "dexpreopt: copy system to $(SYSTEM_DIR)" |
| 100 | @rm -rf $(SYSTEM_DIR) |
| 101 | @mkdir -p $(dir $(SYSTEM_DIR)) |
| 102 | $(hide) $(ACP) -rd $(TARGET_OUT) $(SYSTEM_DIR) |
| 103 | @echo "dexpreopt: optimize dex files" |
| 104 | @rm -rf $(DEXPREOPT_TMP) |
| 105 | @mkdir -p $(DEXPREOPT_TMP) |
| 106 | $(hide) \ |
| 107 | PATH=$(HOST_OUT_EXECUTABLES):$$PATH \ |
| 108 | $(DEXPREOPT) \ |
Jean-Baptiste Queru | e6b4e5b | 2009-11-12 18:45:15 -0800 | [diff] [blame^] | 109 | --kernel $(BUILD_DEXPREOPT_KERNEL) \ |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 110 | --ramdisk $(BUILT_DEXPREOPT_RAMDISK) \ |
| 111 | --image $(BUILT_SYSTEMIMAGE_UNOPT) \ |
| 112 | --system $(PRODUCT_OUT) \ |
| 113 | --tmpdir $(DEXPREOPT_TMP) \ |
| 114 | --outsystemdir $(SYSTEM_DIR) |
| 115 | ifdef sign_dexpreopt |
| 116 | @echo "dexpreopt: re-sign apk files" |
| 117 | $(hide) \ |
| 118 | export PATH=$(HOST_OUT_EXECUTABLES):$$PATH; \ |
| 119 | for apk in $(SYSTEM_DIR)/app/*.apk; do \ |
| 120 | packageName=`basename $$apk`; \ |
| 121 | packageName=`echo $$packageName | sed -e 's/.apk$$//'`; \ |
| 122 | cert=`grep "^$$packageName " $(dexpreopt_package_certs_file) | \ |
| 123 | awk '{print $$2}'`; \ |
| 124 | pkey=`grep "^$$packageName " $(dexpreopt_package_certs_file) | \ |
| 125 | awk '{print $$3}'`; \ |
| 126 | if [ "$$cert" -a "$$pkey" ]; then \ |
| 127 | echo "dexpreopt: re-sign app/"$$packageName".apk"; \ |
| 128 | tmpApk=$$apk~; \ |
| 129 | rm -f $$tmpApk; \ |
| 130 | java -jar $(SIGNAPK_JAR) $$cert $$pkey $$apk $$tmpApk || \ |
| 131 | exit 11; \ |
| 132 | mv -f $$tmpApk $$apk; \ |
| 133 | else \ |
| 134 | echo "dexpreopt: no keys for app/"$$packageName".apk"; \ |
| 135 | rm $(SYSTEM_DIR)/app/$$packageName.* && \ |
| 136 | cp $(TARGET_OUT)/app/$$packageName.apk \ |
| 137 | $(SYSTEM_DIR)/app || exit 12; \ |
| 138 | fi; \ |
| 139 | tmpApk=$$apk~; \ |
| 140 | rm -f $$tmpApk; \ |
| 141 | $(ZIPALIGN) -f 4 $$apk $$tmpApk || exit 13; \ |
| 142 | mv -f $$tmpApk $$apk; \ |
| 143 | done |
| 144 | endif |
| 145 | @echo "Dexpreopt system image: $@" |
| 146 | $(hide) $(MKYAFFS2) -f $(SYSTEM_DIR) $@ |
| 147 | |
| 148 | .PHONY: dexpreoptimage |
| 149 | dexpreoptimage: $(BUILT_DEXPREOPT_SYSTEMIMAGE) |
| 150 | |
| 151 | # Tell our caller to use the optimized systemimage |
| 152 | BUILT_SYSTEMIMAGE := $(BUILT_DEXPREOPT_SYSTEMIMAGE) |
| 153 | SYSTEMIMAGE_SOURCE_DIR := $(dexpreopt_system_dir) |