-
Notifications
You must be signed in to change notification settings - Fork 36
/
newproject.mk
185 lines (163 loc) · 7.96 KB
/
newproject.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
OEM_TARGET_DIR := $(OUT_DIR)/oem_target_files
OEM_TARGET_ZIP := $(OUT_DIR)/oem_target_files.zip
OEM_TARGET_STD_ZIP := $(OUT_DIR)/oem_target_files.zip.std.zip
VENDOR_TARGET_ZIP := $(OUT_DIR)/vendor_target_files.zip
VENDOR_TARGET_DIR := $(OUT_DIR)/vendor_target_files
VENDOR_OTA_ZIP := $(OUT_DIR)/vendor_ota.zip
METAINF := $(VENDOR_DIR)/METAINF
TARGET_FILES_FROM_DEVICE:= $(PORT_BUILD_TOOLS)/target_files_from_device.sh
##################### newproject ########################
./PHONY: newproject
newproject: prepare-vendor prepare-vendor-boot prepare-vendor-recovery decodefile recovery_link update_file_system_config
$(hide) if [ -f $(OUT_DIR)/build-info-to-user.txt ];then \
cat $(OUT_DIR)/build-info-to-user.txt; \
fi
$(hide) echo "< newproject done"
$(hide) echo "========================================================================================"
$(hide) echo "Recommended Command:"
$(hide) echo " make vendorota -> build a vendor ota package to test whether newproject correctly."
$(hide) echo "========================================================================================"
$(OEM_TARGET_ZIP): $(PRJ_RECOVERY_FSTAB)
$(hide) echo ">> prepare vendor ..."
$(hide) echo ">>> generate vendor target files ..."
$(hide) $(TARGET_FILES_FROM_DEVICE) target
$(hide) echo "<<< generate vendor target files done"
$(OEM_TARGET_STD_ZIP): $(OEM_TARGET_ZIP)
$(hide) echo ">>> normalize the $(OEM_TARGET_ZIP) ..."
$(hide) $(OTA_NORMALIZE) --input $(OEM_TARGET_ZIP)
$(hide) echo "<<< normalize the $(OEM_TARGET_ZIP) done"
./PHONY: prepare-vendor
prepare-vendor: $(OEM_TARGET_STD_ZIP)
$(hide) rm -rf $(VENDOR_DIR)
$(hide) echo ">>> unzip $(OEM_TARGET_STD_ZIP) to $(VENDOR_DIR) ..."
$(hide) unzip -q $(OEM_TARGET_STD_ZIP) -d $(VENDOR_DIR)
$(hide) echo "<<< unzip $(OEM_TARGET_STD_ZIP) to $(VENDOR_DIR) done"
$(hide) if [ -d $(VENDOR_DIR)/SYSTEM ]; then mv $(VENDOR_DIR)/SYSTEM $(VENDOR_DIR)/system; fi
$(hide) echo "<< prepare vendor done"
$(hide) echo "* out ==> $(VENDOR_DIR)"
$(hide) echo " "
ifeq ($(PRJ_RECOVERY_FSTAB),$(wildcard $(PRJ_RECOVERY_FSTAB)))
#$(info # use $(PRJ_RECOVERY_FSTAB))
#nop
:
else
$(PRJ_RECOVERY_FSTAB): unpack-recovery
$(hide) cp $(OUT_OBJ_RECOVERY_FSTAB) $@
$(hide) rm -rf $(OUT_OBJ_RECOVERY)
$(hide) echo "* get recovery.fstab ==> $(PRJ_RECOVERY_FSTAB)"
$(hide) echo " "
endif
./PHONY: prepare-vendor-boot
prepare-vendor-boot : unpack-boot prepare-vendor
$(hide) echo ">> prepare vendor boot ..."
$(hide) rm -rf $(VENDOR_BOOT)
$(hide) if [ -d $(OUT_OBJ_BOOT) ]; then mv $(OUT_OBJ_BOOT) $(VENDOR_BOOT); fi;
$(hide) echo "<< prepare vendor boot done"
./PHONY: prepare-vendor-recovery
prepare-vendor-recovery: prepare-vendor
$(hide) echo ">> prepare vendor recovery ..."
$(hide) if [ -f $(VENDOR_SYSTEM)/build.prop ];then \
echo ">>> auto catch the recovery prop ..."; \
mkdir -p $(VENDOR_RECOVERY_RAMDISK); \
TMPPROP=$$(grep "^ro.product.device=" $(VENDOR_SYSTEM)/build.prop); \
if [ "$$TMPPROP" != "" ];then echo $$TMPPROP > $(VENDOR_RECOVERY_RAMDISK)/default.prop; fi; \
TMPPROP=$$(grep "^ro.build.product=" $(VENDOR_SYSTEM)/build.prop); \
if [ "$$TMPPROP" != "" ];then echo $$TMPPROP >> $(VENDOR_RECOVERY_RAMDISK)/default.prop; fi; \
echo "<<< auto catch the recovery prop done"; \
fi
$(hide) echo "<< prepare vendor recovery done"
################ decode files ###########################
define decode_files
$(2): ifoemvendor
$(hide) echo ">>> decode $(1) $(2) ..."
$(hide) rm -rf $(2)
$(hide) $(APKTOOL) d -t $(APKTOOL_VENDOR_TAG) $(1) -o $(2)
$(hide) echo "<<< decode $(1) $(2) done"
endef
PRJ_DECODE_APKS := $(strip framework-res)
PRJ_DECODE_JARS := $(strip $(vendor_modify_jars))
PRJ_DECODE_APKS_OUT := $(sort $(strip $(patsubst %,$(PRJ_ROOT)/%,$(PRJ_DECODE_APKS))))
PRJ_DECODE_JARS_OUT := $(sort $(strip $(patsubst %,$(PRJ_ROOT)/%.jar.out,$(PRJ_DECODE_JARS))))
$(foreach file,$(PRJ_DECODE_APKS),\
$(eval $(call decode_files, \
$(patsubst %,$(VENDOR_SYSTEM)/framework/%.apk,$(file)), \
$(patsubst %,$(PRJ_ROOT)/%,$(file)))))
$(foreach file,$(PRJ_DECODE_JARS),\
$(eval $(call decode_files, \
$(patsubst %,$(VENDOR_SYSTEM)/framework/%.jar,$(file)), \
$(patsubst %,$(PRJ_ROOT)/%.jar.out,$(file)))))
ifoemvendor: prepare-vendor
$(hide) $(call apktool_if_vendor,$(VENDOR_FRAMEWORK))
./PHONY: decodefile
decodefile: $(PRJ_DECODE_APKS_OUT) $(PRJ_DECODE_JARS_OUT)
$(hide) echo "<< decode apk and jar done"
###################### vendor ota ########################
./PHONY: vendorota oemotarom
vendorota oemotarom: $(VENDOR_OTA_ZIP)
$(hide) echo "* out ==> $(VENDOR_OTA_ZIP)"
$(VENDOR_TARGET_ZIP): $(VENDOR_RECOVERY_FSTAB)
$(hide) echo ">> build vendor target files ..."
$(hide) if [ ! -d $(OUT_DIR) ]; then mkdir -p $(OUT_DIR); fi
$(hide) rm -rf $(VENDOR_TARGET_DIR)
$(hide) cp -r $(VENDOR_DIR) $(VENDOR_TARGET_DIR)
$(hide) echo ">>> recover the link files for $(VENDOR_TARGET_DIR) ..."
$(hide) $(RECOVERY_LINK) $(VENDOR_TARGET_DIR)/META/linkinfo.txt $(VENDOR_TARGET_DIR);
$(hide) echo "<<< recover the link files for $(VENDOR_TARGET_DIR) done"
$(hide) mv $(VENDOR_TARGET_DIR)/system $(VENDOR_TARGET_DIR)/SYSTEM
$(hide) rm -rf $(VENDOR_TARGET_DIR)/BOOTABLE_IMAGES
$(hide) len=$$(grep -v "^#" $(VENDOR_RECOVERY_FSTAB) | egrep "ext|emmc|vfat|yaffs" | awk '{print NF}' | head -1); \
isNew=$$(grep -v "^#" $(VENDOR_RECOVERY_FSTAB) | egrep "ext|emmc|vfat|yaffs" | awk '{if ($$2 == "/system"){print "NEW"}}'); \
if [ "x$$len" = "x5" ] && [ "x$$isNew" = "xNEW" ]; \
then \
sed -i '/^fstab_version[ \t]*=.*/d' $(VENDOR_TARGET_DIR)/META/misc_info.txt; \
echo "fstab_version=2" >> $(VENDOR_TARGET_DIR)/META/misc_info.txt; \
else \
sed -i '/^fstab_version[ \t]*=.*/d' $(VENDOR_TARGET_DIR)/META/misc_info.txt; \
echo "fstab_version=1" >> $(VENDOR_TARGET_DIR)/META/misc_info.txt; \
fi;
$(hide) if [ x"false" = x"$(strip $(USE_ASSERTIONS_IN_UPDATER_SCRIPT))" ]; then \
echo "use_assertions=false" >> $(VENDOR_TARGET_DIR)/META/misc_info.txt; \
fi
$(hide) echo ">>> zip $(VENDOR_TARGET_ZIP) from $(VENDOR_TARGET_DIR) ..."
$(hide) cd $(VENDOR_TARGET_DIR); zip -qry $(PRJ_ROOT)/$(VENDOR_TARGET_ZIP) *; cd - > /dev/null
$(hide) echo "<<< zip $(VENDOR_TARGET_ZIP) from $(VENDOR_TARGET_DIR) done"
$(hide) echo "<< build vendor target files done"
$(VENDOR_OTA_ZIP): $(VENDOR_TARGET_ZIP)
$(hide) echo "> build vendor ota package ..."
$(hide) if [ x"$(strip $(PRODUCE_BLOCK_BASED_OTA))" = x"false" ];then \
$(TARGET_FILES_FROM_DEVICE) ota; \
else \
$(TARGET_FILES_FROM_DEVICE) ota_block; \
fi;
$(hide) echo "< build vendor ota package done"
###################### recovery link ########################
.PHONY: recovery_link
recovery_link: $(VENDOR_DIR)
$(hide) echo "> recovery vendor linkinfo ..."
$(hide) $(RECOVERY_LINK) $(VENDOR_DIR)/META/linkinfo.txt $(VENDOR_DIR);
$(hide) echo "< recovery vendor linkinfo done"
###################### update file_system ########################
.PHONY: update_file_system_config
update_file_system_config: $(VENDOR_DIR)
$(hide) echo "> update file system config info ..."
$(hide) if [ ! -d $(OUT_DIR) ]; then mkdir -p $(OUT_DIR); fi
$(hide) if [ ! -f $(OUT_DIR)/file_contexts ]; then \
if [ -f $(PRJ_BOOT_IMG_OUT)/RAMDISK/file_contexts ]; then \
cp $(PRJ_BOOT_IMG_OUT)/RAMDISK/file_contexts $(OUT_DIR)/file_contexts; \
else \
echo "get file_contexts from phone ..."; \
adb pull /file_contexts $(OUT_DIR)/file_contexts \
echo -n ""; \
fi; \
fi;
$(hide) if [ -f $(OUT_DIR)/file_contexts ]; then \
cd $(VENDOR_DIR); zip -qry $(PRJ_ROOT)/$(OUT_DIR)/vendor_system.zip system; cd - > /dev/null; \
zipinfo -1 $(OUT_DIR)/vendor_system.zip \
| $(PORT_ROOT)/build/tools/bin/fs_config -C -D $(VENDOR_SYSTEM) -S $(OUT_DIR)/file_contexts \
| sort > $(VENDOR_META)/filesystem_config.txt; \
else \
echo "ERROR: Please ensure adb can find your device or can adb pull file_contexts and then rerun this script!!"; \
echo "Maby you can get the file_contexts from phone or ota.zip and copy to devices/$(PRJ_NAME)/$(OUT_DIR)"; \
echo ""; \
fi;
$(hide) echo "< update file system config info done"